summaryrefslogtreecommitdiff
path: root/src/Fl_Copy_Surface.cxx
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2016-03-01 17:20:25 +0000
committerManolo Gouy <Manolo>2016-03-01 17:20:25 +0000
commit7decb3d3b226854175b99ff0173ed7136e9f2176 (patch)
tree95149f69f1c6a0a8de6acca4bc706ebad21d0566 /src/Fl_Copy_Surface.cxx
parent4af165781fbaec69533b6db933e3e46778a81797 (diff)
Rewrite the Fl_Copy_Surface class with strict separation of public API and platform-related code.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11257 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Copy_Surface.cxx')
-rw-r--r--src/Fl_Copy_Surface.cxx199
1 files changed, 31 insertions, 168 deletions
diff --git a/src/Fl_Copy_Surface.cxx b/src/Fl_Copy_Surface.cxx
index 8076325bc..c6c1a3192 100644
--- a/src/Fl_Copy_Surface.cxx
+++ b/src/Fl_Copy_Surface.cxx
@@ -18,194 +18,57 @@
#include "config_lib.h"
#include <FL/Fl_Copy_Surface.H>
-#include <FL/Fl.H>
-#ifdef FL_CFG_GFX_QUARTZ
-#include "drivers/Quartz/Fl_Quartz_Graphics_Driver.h"
-#endif
-#ifdef FL_CFG_GFX_XLIB
-#include "drivers/Xlib/Fl_Translated_Xlib_Graphics_Driver.H"
-#endif
-#ifdef FL_CFG_GFX_GDI
-#include "drivers/GDI/Fl_GDI_Graphics_Driver.H"
-#endif
-
-#if defined(__APPLE__) // PORTME: Fl_Surface_Driver - platform copy surface
+#ifdef __APPLE__
+#include <src/drivers/Quartz/Fl_Quartz_Copy_Surface.H>
#elif defined(WIN32)
+#include <src/drivers/GDI/Fl_GDI_Copy_Surface.H>
-
-#else
-
-#endif
-
-
-/** Constructor.
- \param w and \param h are the width and height of the clipboard surface
- in pixels where drawing will occur.
- */
-Fl_Copy_Surface::Fl_Copy_Surface(int w, int h) : Fl_Widget_Surface(NULL)
-{
- width = w;
- height = h;
-#ifdef __APPLE__ // PORTME: Fl_Surface_Driver - platform copy surface
- driver(new Fl_Quartz_Graphics_Driver);
- prepare_copy_pdf_and_tiff(w, h);
-#elif defined(WIN32)
- driver(new Fl_Translated_GDI_Graphics_Driver);
- oldgc = (HDC)Fl_Surface_Device::surface()->driver()->gc();
- // exact computation of factor from screen units to EnhMetaFile units (0.01 mm)
- HDC hdc = GetDC(NULL);
- int hmm = GetDeviceCaps(hdc, HORZSIZE);
- int hdots = GetDeviceCaps(hdc, HORZRES);
- int vmm = GetDeviceCaps(hdc, VERTSIZE);
- int vdots = GetDeviceCaps(hdc, VERTRES);
- ReleaseDC(NULL, hdc);
- float factorw = (100.f * hmm) / hdots;
- float factorh = (100.f * vmm) / vdots;
-
- RECT rect; rect.left = 0; rect.top = 0; rect.right = (LONG)(w * factorw); rect.bottom = (LONG)(h * factorh);
- gc = CreateEnhMetaFile (NULL, NULL, &rect, NULL);
- if (gc != NULL) {
- SetTextAlign(gc, TA_BASELINE|TA_LEFT);
- SetBkMode(gc, TRANSPARENT);
- }
-#elif defined(FL_PORTING)
-# pragma message "FL_PORTING: initialize members of Fl_Copy_Surface"
-#else // Xlib
- driver(new Fl_Translated_Xlib_Graphics_Driver());
- Fl::first_window()->make_current();
- oldwindow = fl_xid(Fl::first_window());
- xid = fl_create_offscreen(w,h);
- _ss = NULL;
- Fl_Surface_Device *present_surface = Fl_Surface_Device::surface();
- set_current();
- fl_color(FL_WHITE);
- fl_rectf(0, 0, w, h);
- present_surface->set_current();
-#endif
-}
-
-/** Destructor.
- */
-Fl_Copy_Surface::~Fl_Copy_Surface()
-{
-#ifdef __APPLE__ // PORTME: Fl_Surface_Driver - platform copy surface
- complete_copy_pdf_and_tiff();
-#elif defined(WIN32)
- if (oldgc == (HDC)Fl_Surface_Device::surface()->driver()->gc()) oldgc = NULL;
- HENHMETAFILE hmf = CloseEnhMetaFile (gc);
- if ( hmf != NULL ) {
- if ( OpenClipboard (NULL) ){
- EmptyClipboard ();
- SetClipboardData (CF_ENHMETAFILE, hmf);
- CloseClipboard ();
- }
- DeleteEnhMetaFile(hmf);
- }
- DeleteDC(gc);
- Fl_Surface_Device::surface()->driver()->gc(oldgc);
#elif defined(FL_PORTING)
-# pragma message "FL_PORTING: free resources in destructor of Fl_Copy_Surface"
-#else // Xlib
- fl_pop_clip();
- unsigned char *data = fl_read_image(NULL,0,0,width,height,0);
- fl_window = oldwindow;
- _ss->set_current();
- Fl::copy_image(data,width,height,1);
- delete[] data;
- fl_delete_offscreen(xid);
-#endif
-}
-
+# pragma message "FL_PORTING: implement class Fl_Copy_Surface::Helper for your platform"
+
+class Fl_Copy_Surface::Helper : public Fl_Widget_Surface { // model
+ friend class Fl_Copy_Surface;
+private:
+ int width;
+ int height;
+ Helper(int w, int h) : Fl_Widget_Surface(NULL) {}
+ ~Helper() {}
+ void set_current(){}
+ void translate(int x, int y) {}
+ void untranslate() {}
+ int w() {return width;}
+ int h() {return height;}
+};
-void Fl_Copy_Surface::set_current()
-{
-#if defined(__APPLE__) || defined(WIN32) // PORTME: Fl_Surface_Driver - platform copy surface
- driver()->gc(gc);
- fl_window = (Window)1;
- Fl_Surface_Device::set_current();
-#elif defined(FL_PORTING)
-# pragma message "FL_PORTING: implement Fl_Copy_Surface::set_current"
#else
- fl_window=xid;
- if (!_ss) _ss = Fl_Surface_Device::surface();
- Fl_Surface_Device::set_current();
- fl_push_no_clip();
-#endif
-}
-
-
-#if defined(__APPLE__) // PORTME: Fl_Surface_Driver - platform copy surface
-
-size_t Fl_Copy_Surface::MyPutBytes(void* info, const void* buffer, size_t count)
- {
- CFDataAppendBytes ((CFMutableDataRef) info, (const UInt8 *)buffer, count);
- return count;
-}
+#include <src/drivers/Xlib/Fl_Xlib_Copy_Surface.H>
-void Fl_Copy_Surface::init_PDF_context(int w, int h)
-{
- CGRect bounds = CGRectMake(0, 0, w, h );
- pdfdata = CFDataCreateMutable(NULL, 0);
- CGDataConsumerRef myconsumer;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
- if (&CGDataConsumerCreateWithCFData != NULL) {
- myconsumer = CGDataConsumerCreateWithCFData(pdfdata); // 10.4
- }
- else
#endif
- {
- static CGDataConsumerCallbacks callbacks = { Fl_Copy_Surface::MyPutBytes, NULL };
- myconsumer = CGDataConsumerCreate ((void*) pdfdata, &callbacks);
- }
- gc = CGPDFContextCreate (myconsumer, &bounds, NULL);
- CGDataConsumerRelease (myconsumer);
-}
-void Fl_Copy_Surface::prepare_copy_pdf_and_tiff(int w, int h)
-{
- init_PDF_context(w, h);
- if (gc == NULL) return;
- CGRect bounds = CGRectMake(0, 0, w, h );
- CGContextBeginPage (gc, &bounds);
- CGContextTranslateCTM(gc, 0, h);
- CGContextScaleCTM(gc, 1.0f, -1.0f);
- CGContextSaveGState(gc);
+Fl_Copy_Surface::Helper *Fl_Copy_Surface::newPlatformSurface(int w, int h) {
+ return new Helper(w, h);
}
-void Fl_Copy_Surface::translate(int x, int y) {
- CGContextRef gc = (CGContextRef)driver()->gc();
- CGContextRestoreGState(gc);
- CGContextSaveGState(gc);
- CGContextTranslateCTM(gc, x, y);
- CGContextSaveGState(gc);
+Fl_Copy_Surface::Fl_Copy_Surface(int w, int h) : Fl_Widget_Surface(NULL) {
+ platform_surface = newPlatformSurface(w, h);
+ driver(platform_surface->driver());
}
-void Fl_Copy_Surface::untranslate() {
- CGContextRestoreGState((CGContextRef)driver()->gc());
-}
+Fl_Copy_Surface::~Fl_Copy_Surface() { delete platform_surface; }
-#elif defined(WIN32)
+void Fl_Copy_Surface::origin(int *x, int *y) {platform_surface->origin(x, y);}
-void Fl_Copy_Surface::translate(int x, int y) {
- ((Fl_Translated_GDI_Graphics_Driver*)driver())->translate_all(x, y);
-}
+void Fl_Copy_Surface::set_current() {platform_surface->set_current();}
-void Fl_Copy_Surface::untranslate() {
- ((Fl_Translated_GDI_Graphics_Driver*)driver())->untranslate_all();
-}
+void Fl_Copy_Surface::translate(int x, int y) {platform_surface->translate(x, y);}
-#else
-void Fl_Copy_Surface::translate(int x, int y) {
- ((Fl_Translated_Xlib_Graphics_Driver*)driver())->translate_all(x, y);
-}
+void Fl_Copy_Surface::untranslate() {platform_surface->untranslate();}
-void Fl_Copy_Surface::untranslate() {
- ((Fl_Translated_Xlib_Graphics_Driver*)driver())->untranslate_all();
-}
+int Fl_Copy_Surface::w() {return platform_surface->w();}
-#endif // __APPLE__ // PORTME: Fl_Surface_Driver - platform copy surface
+int Fl_Copy_Surface::h() {return platform_surface->h();}
//
// End of "$Id$".