summaryrefslogtreecommitdiff
path: root/FL
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2014-05-23 16:47:21 +0000
committerManolo Gouy <Manolo>2014-05-23 16:47:21 +0000
commit07dd8ba328117a2599cb39dbaa9f17d4f279f923 (patch)
tree6e4976f79f015d70a9e540b6e66262219fd300a2 /FL
parent85af2efe09d6ac88bfc18f8a991ea59af9a5b24b (diff)
Added copy/paste from/to FLTK applications of graphical data.
Added Fl_Image_Surface class to draw into an Fl_Image object. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10159 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'FL')
-rw-r--r--FL/Fl.H78
-rw-r--r--FL/Fl_Copy_Surface.H135
-rw-r--r--FL/Fl_Image_Surface.H90
-rw-r--r--FL/mac.H1
4 files changed, 294 insertions, 10 deletions
diff --git a/FL/Fl.H b/FL/Fl.H
index 148bca0ee..020f38cce 100644
--- a/FL/Fl.H
+++ b/FL/Fl.H
@@ -137,6 +137,8 @@ public: // should be private!
static int e_keysym;
static char* e_text;
static int e_length;
+ static void *e_clipboard_data;
+ static const char *e_clipboard_type;
static Fl_Event_Dispatch e_dispatch;
static Fl_Widget* belowmouse_;
static Fl_Widget* pushed_;
@@ -151,7 +153,9 @@ public: // should be private!
static void reset_marked_text(); // resets marked text
static void insertion_point_location(int x, int y, int height); // sets window coordinates & height of insertion point
#endif
-#endif
+#endif // FL_DOXYGEN
+
+
/**
If true then flush() will do something.
*/
@@ -729,6 +733,16 @@ public:
you paste a nul character.
*/
static int event_length() {return e_length;}
+
+ /** During an FL_PASTE event of non-textual data, returns a pointer to the pasted data.
+ The returned data is an Fl_Image * when the result of Fl::event_clipboard_type() is Fl::clipboard_image.
+ */
+ static void *event_clipboard() { return e_clipboard_data; }
+ /** Returns the type of the pasted data during an FL_PASTE event.
+ This type can be Fl::clipboard_plain_text or Fl::clipboard_image.
+ */
+ static const char *event_clipboard_type() {return e_clipboard_type; }
+
static int compose(int &del);
static void compose_reset();
@@ -763,19 +777,39 @@ public:
/**
Copies the data pointed to by \p stuff to the selection buffer
(\p destination is 0) or
- the clipboard (\p destination is 1); \p len is the number of relevant
- bytes in \p stuff.
+ the clipboard (\p destination is 1).
+ \p len is the number of relevant bytes in \p stuff.
+ \p type is always Fl::clipboard_plain_text.
The selection buffer is used for
middle-mouse pastes and for drag-and-drop selections. The
clipboard is used for traditional copy/cut/paste operations.
+
+ \note This function is, at present, intended only to copy UTF-8 encoded textual data.
+ To copy graphical data, use the Fl_Copy_Surface class. The \p type argument may allow
+ in the future to copy other kinds of data.
*/
- static void copy(const char* stuff, int len, int destination = 0); // platform dependent
+#if FLTK_ABI_VERSION >= 10303 || defined(FL_DOXYGEN)
+ static void copy(const char* stuff, int len, int destination = 0, const char *type = Fl::clipboard_plain_text); // platform dependent
+#else
+ static void copy(const char* stuff, int len, int destination, const char *type);
+ static void copy(const char* stuff, int len, int destination = 0);
+#endif
+
+#if !(defined(__APPLE__) || defined(WIN32) || defined(FL_DOXYGEN))
+ static void copy_image(const unsigned char* data, int W, int H, int destination = 0); // platform dependent
+#endif
/**
Pastes the data from the selection buffer (\p source is 0) or the clipboard
- (\p source is 1) into \p receiver.
- Set things up so the receiver widget will be called with an FL_PASTE event some
- time in the future with the data from the specified \p source in Fl::event_text()
- and the number of characters in Fl::event_length().
+ (\p source is 1) into \p receiver. If \p source is 1,
+ the optional \p type argument indicates what type of data is requested from the clipboard
+ (at present, Fl::clipboard_plain_text - requesting text data - and
+ Fl::clipboard_image - requesting image data - are possible).
+ Set things up so the handle function of the \p receiver widget will be called with an FL_PASTE event some
+ time in the future if the clipboard does contain data of the requested type. During processing of this event,
+ and if \p type is Fl::clipboard_plain_text, the text data from the specified \p source are in Fl::event_text()
+ with UTF-8 encoding, and the number of characters in Fl::event_length();
+ if \p type is Fl::clipboard_image, Fl::event_clipboard() returns a pointer to the
+ image data, as an Fl_Image *.
The receiver
should be prepared to be called \e directly by this, or for
it to happen \e later, or possibly <i>not at all</i>. This
@@ -786,8 +820,21 @@ public:
The selection buffer is used for middle-mouse pastes and for
drag-and-drop selections. The clipboard is used for traditional
copy/cut/paste operations.
- */
- static void paste(Fl_Widget &receiver, int source /*=0*/); // platform dependent
+
+ \par Platform details for image data:
+ \li Unix/Linux platform: Image data in PNG or BMP formats are recognized. Requires linking with the fltk_images library.
+ \li MSWindows platform: Both bitmap and vectorial (Enhanced metafile) data from clipboard
+ can be pasted as image data.
+ \li Mac OS X platform: Both bitmap (TIFF) and vectorial (PDF) data from clipboard
+ can be pasted as image data.
+
+ */
+#if FLTK_ABI_VERSION >= 10303 || defined(FL_DOXYGEN)
+ static void paste(Fl_Widget &receiver, int source, const char *type = Fl::clipboard_plain_text); // platform dependent
+#else
+ static void paste(Fl_Widget &receiver, int source, const char *type);
+ static void paste(Fl_Widget &receiver, int source /*=0*/);
+#endif
/**
FLTK will call the registered callback whenever there is a change to the
selection buffer or the clipboard. The source argument indicates which
@@ -815,6 +862,17 @@ public:
buffer or the clipboard.
*/
static void remove_clipboard_notify(Fl_Clipboard_Notify_Handler h);
+ /** Returns non 0 if the clipboard contains data matching \p type.
+ \p type can be Fl::clipboard_plain_text or Fl::clipboard_image.
+ */
+ static int clipboard_contains(const char *type);
+ /** Denotes plain textual data
+ */
+ static char const * const clipboard_plain_text;
+ /** Denotes image data
+ */
+ static char const * const clipboard_image;
+
/**
Initiate a Drag And Drop operation. The selection buffer should be
filled with relevant data before calling this method. FLTK will
diff --git a/FL/Fl_Copy_Surface.H b/FL/Fl_Copy_Surface.H
new file mode 100644
index 000000000..fc116f3b5
--- /dev/null
+++ b/FL/Fl_Copy_Surface.H
@@ -0,0 +1,135 @@
+//
+// "$Id: Fl_Copy_Surface.H 9869 2013-04-09 20:11:28Z greg.ercolano $"
+//
+// Copy-to-clipboard code for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 1998-2014 by Bill Spitzak and others.
+//
+// This library is free software. Distribution and use rights are outlined in
+// the file "COPYING" which should have been included with this file. If this
+// file is missing or damaged, see the license at:
+//
+// http://www.fltk.org/COPYING.php
+//
+// Please report all bugs and problems on the following page:
+//
+// http://www.fltk.org/str.php
+//
+
+#ifndef Fl_Copy_Surface_H
+#define Fl_Copy_Surface_H
+
+#include <FL/Fl_Paged_Device.H>
+#include <FL/Fl_Printer.H>
+
+#if defined(__APPLE__)
+#include <ApplicationServices/ApplicationServices.h>
+#endif
+
+/** Supports copying of graphical data to the clipboard.
+
+ <br> After creation of an Fl_Copy_Surface object, call set_current() on it, and all subsequent graphics requests
+ will be recorded in the clipboard. It's possible to draw widgets (using Fl_Copy_Surface::draw()
+ ) or to use any of the \ref fl_drawings or the \ref fl_attributes.
+ Finally, delete the Fl_Copy_Surface object to load the clipboard with the graphical data.
+ <br> Fl_GL_Window 's can be copied to the clipboard as well.
+ <br> Usage example:
+ \code
+ Fl_Widget *g = ...; // a widget you want to copy to the clipboard
+ Fl_Copy_Surface *copy_surf = new Fl_Copy_Surface(g->w(), g->h()); // create an Fl_Copy_Surface object
+ copy_surf->set_current(); // direct graphics requests to the clipboard
+ fl_color(FL_WHITE); fl_rectf(0, 0, g->w(), g->h()); // draw a white background
+ copy_surf->draw(g); // draw the g widget in the clipboard
+ delete copy_surf; // after this, the clipboard is loaded
+ Fl_Display_Device::display_device()->set_current(); // direct graphics requests back to the display
+ \endcode
+ Platform details:
+ \li MSWindows: Transparent RGB images copy without transparency.
+ The graphical data is copied to the clipboard as an 'enhanced metafile'.
+ \li Mac OS: The graphical data is copied to the clipboard (a.k.a. pasteboard) in 2 'flavors':
+ 1) in vectorial form as PDF data; 2) in bitmap form as a TIFF image (or PICT for Mac OS 10.3).
+ Applications to which the clipboard content is pasted can use the flavor that suits them best.
+ \li X11: the graphical data is copied to the clipboard as an image in BMP format.
+*/
+class Fl_Copy_Surface : public Fl_Surface_Device {
+private:
+ int width;
+ int height;
+ Fl_Paged_Device *helper;
+#ifdef __APPLE__
+ CFMutableDataRef pdfdata;
+ CGContextRef oldgc;
+ CGContextRef gc;
+ void prepare_copy_pdf_and_tiff(int w, int h);
+ void complete_copy_pdf_and_tiff();
+ void init_PDF_context(int w, int h);
+ static size_t MyPutBytes(void* info, const void* buffer, size_t count);
+#elif defined(WIN32)
+ HDC oldgc;
+ HDC gc;
+#else // Xlib
+ Fl_Offscreen xid;
+ Window oldwindow;
+ Fl_Surface_Device *_ss;
+#endif
+public:
+ static const char *class_id;
+ const char *class_name() {return class_id;};
+ Fl_Copy_Surface(int w, int h);
+ ~Fl_Copy_Surface();
+ void set_current();
+ void draw(Fl_Widget* widget, int delta_x = 0, int delta_y = 0);
+};
+
+#if defined(__APPLE__)
+
+/* Mac class to reimplement Fl_Paged_Device::printable_rect() */
+class Fl_Quartz_Surface_ : public Fl_System_Printer {
+protected:
+ int width;
+ int height;
+public:
+ static const char *class_id;
+ const char *class_name() {return class_id;};
+ Fl_Quartz_Surface_(int w, int h);
+ virtual int printable_rect(int *w, int *h);
+ virtual ~Fl_Quartz_Surface_() {};
+};
+
+#elif defined(WIN32)
+
+/* Win class to implement translate()/untranslate() */
+class Fl_GDI_Surface_ : public Fl_Paged_Device {
+ int width;
+ int height;
+ int depth;
+ POINT origins[10];
+public:
+ static const char *class_id;
+ const char *class_name() {return class_id;};
+ Fl_GDI_Surface_();
+ virtual void translate(int x, int y);
+ virtual void untranslate();
+ virtual ~Fl_GDI_Surface_();
+};
+
+#elif !defined(FL_DOXYGEN)
+
+/* Xlib class to implement translate()/untranslate() */
+class Fl_Xlib_Surface_ : public Fl_Paged_Device {
+public:
+ static const char *class_id;
+ const char *class_name() {return class_id;};
+ Fl_Xlib_Surface_();
+ virtual void translate(int x, int y);
+ virtual void untranslate();
+ virtual ~Fl_Xlib_Surface_();
+};
+
+#endif
+
+#endif // Fl_Copy_Surface_H
+
+//
+// End of "$Id: $".
+//
diff --git a/FL/Fl_Image_Surface.H b/FL/Fl_Image_Surface.H
new file mode 100644
index 000000000..2d82238c2
--- /dev/null
+++ b/FL/Fl_Image_Surface.H
@@ -0,0 +1,90 @@
+//
+// "$Id: Fl_Image_Surface.H 9869 2013-04-09 20:11:28Z greg.ercolano $"
+//
+// Draw-to-image code for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 1998-2014 by Bill Spitzak and others.
+//
+// This library is free software. Distribution and use rights are outlined in
+// the file "COPYING" which should have been included with this file. If this
+// file is missing or damaged, see the license at:
+//
+// http://www.fltk.org/COPYING.php
+//
+// Please report all bugs and problems on the following page:
+//
+// http://www.fltk.org/str.php
+//
+
+#ifndef Fl_Image_Surface_H
+#define Fl_Image_Surface_H
+
+#include <FL/Fl_Copy_Surface.H>
+#include <FL/Fl_Image.H>
+
+
+/** Directs all graphics requests to an Fl_Image.
+
+ After creation of an Fl_Image_Surface object, call set_current() on it, and all subsequent graphics requests
+ will be recorded in the image. It's possible to draw widgets (using Fl_Image_Surface::draw())
+ or to use any of the \ref fl_drawings or the \ref fl_attributes.
+ Finally, call image() on the object to obtain a newly allocated Fl_Image object.
+ <br> Fl_GL_Window objects can be drawn in the image as well.
+
+ <br> Usage example:
+ \code
+ Fl_Widget *g = ...; // a widget you want to draw in an image
+ Fl_Image_Surface *img_surf = new Fl_Image_Surface(g->w(), g->h()); // create an Fl_Image_Surface object
+ img_surf->set_current(); // direct graphics requests to the image
+ fl_color(FL_WHITE); fl_rectf(0, 0, g->w(), g->h()); // draw a white background
+ img_surf->draw(g); // draw the g widget in the image
+ Fl_Image* image = img_surf->image(); // get the resulting image
+ delete img_surf; // delete the img_surf object
+ Fl_Display_Device::display_device()->set_current(); // direct graphics requests back to the display
+ \endcode
+*/
+class Fl_Image_Surface : public Fl_Surface_Device {
+private:
+ Fl_Offscreen offscreen;
+ int width;
+ int height;
+ Fl_Paged_Device *helper;
+#ifdef __APPLE__
+#elif defined(WIN32)
+ HDC _sgc;
+ Window _sw;
+ Fl_Surface_Device *_ss;
+ int _savedc;
+#else
+ Fl_Surface_Device *previous;
+ Window pre_window;
+ GC gc;
+#endif
+public:
+ static const char *class_id;
+ const char *class_name() {return class_id;};
+ Fl_Image_Surface(int w, int h);
+ ~Fl_Image_Surface();
+ void set_current();
+ void draw(Fl_Widget*, int delta_x = 0, int delta_y = 0);
+ Fl_Image *image();
+};
+
+#ifdef __APPLE__
+/* Mac class to implement translate()/untranslate() for a flipped bitmap graphics context */
+class Fl_Quartz_Flipped_Surface_ : public Fl_Quartz_Surface_ {
+public:
+ static const char *class_id;
+ const char *class_name() {return class_id;};
+ Fl_Quartz_Flipped_Surface_(int w, int h);
+ void translate(int x, int y);
+ void untranslate();
+ virtual ~Fl_Quartz_Flipped_Surface_() {};
+};
+#endif
+
+#endif // Fl_Image_Surface_H
+
+//
+// End of "$Id: $".
+//
diff --git a/FL/mac.H b/FL/mac.H
index 8ea1bb0ad..734786e45 100644
--- a/FL/mac.H
+++ b/FL/mac.H
@@ -145,6 +145,7 @@ public:
void set_cursor(Fl_Cursor);
static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
+ static CFDataRef CGBitmapContextToTIFF(CGContextRef c);
static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h);
static CGContextRef watch_cursor_image(void);
static CGContextRef help_cursor_image(void);