Fl_Copy_Surface.H 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // "$Id: Fl_Copy_Surface.H 12125 2016-11-30 07:09:48Z manolo $"
  3. //
  4. // Copy-to-clipboard code for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2014 by Bill Spitzak and others.
  7. //
  8. // This library is free software. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. #ifndef Fl_Copy_Surface_H
  19. #define Fl_Copy_Surface_H
  20. #include <FL/Fl_Widget_Surface.H>
  21. /** Supports copying of graphical data to the clipboard.
  22. <br> After creation of an Fl_Copy_Surface object, call set_current() on it, and all subsequent graphics requests
  23. will be recorded in the clipboard. It's possible to draw widgets (using Fl_Copy_Surface::draw()
  24. ) or to use any of the \ref fl_drawings or the \ref fl_attributes.
  25. Finally, delete the Fl_Copy_Surface object to load the clipboard with the graphical data.
  26. <br> Fl_GL_Window 's can be copied to the clipboard as well.
  27. <br> Usage example:
  28. \code
  29. Fl_Widget *g = ...; // a widget you want to copy to the clipboard
  30. Fl_Copy_Surface *copy_surf = new Fl_Copy_Surface(g->w(), g->h()); // create an Fl_Copy_Surface object
  31. copy_surf->set_current(); // direct graphics requests to the clipboard
  32. fl_color(FL_WHITE); fl_rectf(0, 0, g->w(), g->h()); // draw a white background
  33. copy_surf->draw(g); // draw the g widget in the clipboard
  34. delete copy_surf; // after this, the clipboard is loaded
  35. Fl_Display_Device::display_device()->set_current(); // direct graphics requests back to the display
  36. \endcode
  37. Platform details:
  38. \li MSWindows: Transparent RGB images copy without transparency.
  39. The graphical data are copied to the clipboard as an 'enhanced metafile'.
  40. \li Mac OS: The graphical data are copied to the clipboard (a.k.a. pasteboard) in two 'flavors':
  41. 1) in vectorial form as PDF data; 2) in bitmap form as a TIFF image.
  42. Applications to which the clipboard content is pasted can use the flavor that suits them best.
  43. \li X11: the graphical data are copied to the clipboard as an image in BMP format.
  44. */
  45. class FL_EXPORT Fl_Copy_Surface : public Fl_Widget_Surface {
  46. private:
  47. class Fl_Copy_Surface_Driver *platform_surface;
  48. protected:
  49. void translate(int x, int y);
  50. void untranslate();
  51. public:
  52. Fl_Copy_Surface(int w, int h);
  53. ~Fl_Copy_Surface();
  54. void set_current();
  55. /** Returns the pixel width of the copy surface */
  56. int w();
  57. /** Returns the pixel height of the copy surface */
  58. int h();
  59. void origin(int *x, int *y);
  60. void origin(int x, int y);
  61. int printable_rect(int *w, int *h);
  62. };
  63. /** A base class describing the interface between FLTK and draw-to-clipboard operations.
  64. This class is only for internal use by the FLTK library.
  65. A supported platform should implement the virtual methods of this class
  66. in order to support drawing to the clipboard through class Fl_Copy_Surface.
  67. */
  68. class Fl_Copy_Surface_Driver : public Fl_Widget_Surface {
  69. friend class Fl_Copy_Surface;
  70. protected:
  71. int width;
  72. int height;
  73. Fl_Copy_Surface_Driver(int w, int h) : Fl_Widget_Surface(NULL), width(w), height(h) {}
  74. virtual ~Fl_Copy_Surface_Driver() {}
  75. virtual void set_current() {}
  76. virtual void translate(int x, int y) {}
  77. virtual void untranslate() {}
  78. int printable_rect(int *w, int *h) {*w = width; *h = height; return 0;}
  79. virtual Fl_RGB_Image *image() {return NULL;}
  80. /** Each platform implements this function its own way.
  81. It returns an object implementing all virtual functions
  82. of class Fl_Copy_Surface_Driver for the plaform.
  83. */
  84. static Fl_Copy_Surface_Driver *newCopySurfaceDriver(int w, int h);
  85. };
  86. #endif // Fl_Copy_Surface_H
  87. //
  88. // End of "$Id: Fl_Copy_Surface.H 12125 2016-11-30 07:09:48Z manolo $".
  89. //