Author: manolo
Date: 2010-04-19 12:44:21 -0700 (Mon, 19 Apr 2010)
New Revision: 7532
Log:
Fl_Clipboard_Writer* files renamed to Fl_Clipboard_Device*

Added:
   branches/branch-1.3-Fl_Printer/FL/Fl_Clipboard_Device.H
   branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Device.cxx
   branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Device_mac.cxx
   branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Device_win32.cxx

Copied: branches/branch-1.3-Fl_Printer/FL/Fl_Clipboard_Device.H (from rev 7531, 
branches/branch-1.3-Fl_Printer/FL/Fl_Clipboard_Writer.H)
===================================================================
--- branches/branch-1.3-Fl_Printer/FL/Fl_Clipboard_Device.H                     
        (rev 0)
+++ branches/branch-1.3-Fl_Printer/FL/Fl_Clipboard_Device.H     2010-04-19 
19:44:21 UTC (rev 7532)
@@ -0,0 +1,76 @@
+//
+// "$Id$"
+//
+// declaration of Fl_Clipboard_Device class for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 2010 by Bill Spitzak and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems to:
+//
+//     http://www.fltk.org/str.php
+//
+
+#ifndef FL_CLIPBOARD_DEVICE_H
+#define FL_CLIPBOARD_DEVICE_H
+
+#include <FL/Fl_Device.H>
+
+/**
+ \brief Sends all graphics requests to the clipboard.
+ 
+ Presently implemented for the MSWindows and Mac OS X platforms only.
+ */
+class Fl_Clipboard_Device : public Fl_Surface_Device {
+private:
+#ifdef __APPLE__
+  int width, height;
+  CFMutableDataRef pdfdata_;
+#endif
+  /** \brief the clipboard's graphics context, if there's one, NULL otherwise 
*/
+//  void *gc;
+  void traverse(Fl_Widget *widget);
+  void translate(int x, int y);
+  void untranslate(void);
+public:
+  static const char *device_type;
+#ifdef __APPLE__
+  inline void bounds(int *pwidth, int *pheight) {*pwidth = width; *pheight = 
height; }
+#endif
+  /** \brief The constructor */
+  Fl_Clipboard_Device() : Fl_Surface_Device(fl_device) {type_ = device_type;};
+  /** \brief To be called before any graphics request.
+   \param w The width in pixels of the clipboard drawing surface
+   \param h The height in pixels of the clipboard drawing surface
+   */
+  int start(int w, int h);
+  /** \brief Copies a widget to the clipboard 
+   \param widget A FLTK widget of any kind
+   \param delta_x Horizontal offset for position of the widget top-left angle.
+   \param delta_y Vertical offset for position of the widget top-left angle.
+   */
+  void copy_widget(Fl_Widget* widget, int delta_x = 0, int delta_y = 0);
+  /** \brief To be called after all graphics requests were done */
+  int stop();
+  void set_current();
+};
+
+#endif // FL_CLIPBOARD_DEVICE_H
+
+//
+// End of "$Id$".
+//

Copied: branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Device.cxx (from rev 
7531, branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Writer.cxx)
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Device.cxx                  
        (rev 0)
+++ branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Device.cxx  2010-04-19 
19:44:21 UTC (rev 7532)
@@ -0,0 +1,127 @@
+//
+// "$Id$"
+//
+// implementation of Fl_Clipboard_Writer class for the Fast Light Tool Kit 
(FLTK).
+//
+// Copyright 2010 by Bill Spitzak and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems to:
+//
+//     http://www.fltk.org/str.php
+//
+#if defined(WIN32) || defined(__APPLE__)
+
+#ifdef __APPLE__
+#include "Fl_Clipboard_Device_mac.cxx"
+#elif defined(WIN32)
+#include "Fl_Clipboard_Device_win32.cxx"
+#endif
+
+#include <FL/Fl_Printer.H>
+
+const char *Fl_Clipboard_Device::device_type = "Fl_Clipboard_Device";
+
+#if !(defined(WIN32) || defined(__APPLE__))
+// not implemented yet
+int Fl_Clipboard_Device::start(int w, int h) {}
+int Fl_Clipboard_Device::stop(void) {}
+void Fl_Clipboard_Device::translate(int x, int y) {}
+void Fl_Clipboard_Device::untranslate(void) {}
+#endif
+
+void Fl_Clipboard_Device::set_current(void)
+{
+#ifdef __APPLE__
+  fl_gc = (CGContextRef)gc;
+#elif defined(WIN32)
+  fl_gc = (HDC)gc;
+#else
+  fl_gc = (_XGC*)0;
+#endif
+  this->Fl_Surface_Device::set_current();
+}
+
+void Fl_Clipboard_Device::copy_widget(Fl_Widget* widget, int delta_x, int 
delta_y) 
+{ 
+  int new_x, new_y, is_window;
+  if ( ! widget->visible() ) return;
+  is_window = (widget->as_window() != NULL);
+  widget->damage(FL_DAMAGE_ALL);
+  // set origin to the desired top-left position of the widget
+  new_x = delta_x;
+  new_y = delta_y;
+  if (!is_window) {
+    new_x -= widget->x();
+    new_y -= widget->y();
+  }
+  if (new_x != 0 || new_y != 0) {
+    translate(new_x, new_y );
+  }
+#ifndef WIN32 // doesn't  work on WIN32. Why ?
+  // if widget is a window, clip all drawings to the window area
+  if (is_window) fl_push_clip(0, 0, widget->w(), widget->h() );
+#endif
+  // we do some trickery to recognize OpenGL windows and draw them via a plugin
+  int drawn_by_plugin = 0;
+  if (widget->as_gl_window()) {
+     Fl_Plugin_Manager pm("fltk:device");  
+     Fl_Device_Plugin *pi = 
(Fl_Device_Plugin*)pm.plugin("opengl.device.fltk.org");
+     if (pi) {
+       int height = 0;
+#ifdef __APPLE__
+       int width;
+       this->bounds(&width, &height);
+#endif
+       drawn_by_plugin = pi->print(widget, 0, 0, height);
+       }
+  }
+  if (!drawn_by_plugin) {
+    widget->draw();
+  }
+#ifndef WIN32
+  if (is_window) fl_pop_clip();
+#endif
+  // find subwindows of widget and print them
+  traverse(widget);
+  // reset origin to where it was
+  if (new_x != 0 || new_y != 0) {
+    untranslate();
+  }
+}
+
+void Fl_Clipboard_Device::traverse(Fl_Widget *widget)
+{
+  Fl_Group *g = widget->as_group();
+  if (!g) return;
+  int n = g->children();
+  for (int i = 0; i < n; i++) {
+    Fl_Widget *c = g->child(i);
+    if ( !c->visible() ) continue;
+    if ( c->as_window() ) {
+      copy_widget(c, c->x(), c->y());
+    }
+    else traverse(c);
+  }
+}
+
+#endif
+
+//
+// End of "$Id$".
+//
+

Copied: branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Device_mac.cxx (from 
rev 7531, branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Writer_mac.cxx)
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Device_mac.cxx              
                (rev 0)
+++ branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Device_mac.cxx      
2010-04-19 19:44:21 UTC (rev 7532)
@@ -0,0 +1,176 @@
+//
+// "$Id$"
+//
+// mac implementation of Fl_Clipboard_Writer class for the Fast Light Tool Kit 
(FLTK).
+//
+// Copyright 2010 by Bill Spitzak and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems to:
+//
+//     http://www.fltk.org/str.php
+//
+
+#ifdef __APPLE__
+
+#include <FL/Fl_Clipboard_Device.H>
+#include <FL/x.H>
+#include <FL/fl_draw.H>
+#include <QuickTime/ImageCompression.h>
+
+static size_t MyPutBytes (void* info, const void* buffer, size_t count)
+{
+  CFDataAppendBytes ((CFMutableDataRef) info, (const UInt8 *)buffer, count);
+  return count;
+}
+
+int Fl_Clipboard_Device::start(int w, int h)
+{
+  Fl_X::q_release_context();
+  width = w;
+  height = h;
+  //prepare to draw in pdf context
+  CGRect bounds = CGRectMake(0, 0, w, h );     
+  pdfdata_ = CFDataCreateMutable(NULL, 0);
+  CGDataConsumerRef myconsumer;
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+  if(CGDataConsumerCreateWithCFData != NULL) {
+    myconsumer = CGDataConsumerCreateWithCFData (pdfdata_);
+    }
+  else
+#endif
+    {
+    static CGDataConsumerCallbacks callbacks = { MyPutBytes, NULL };
+    myconsumer = CGDataConsumerCreate ((void*) pdfdata_, &callbacks);
+    }
+  gc = CGPDFContextCreate (myconsumer, &bounds, NULL);
+  CGDataConsumerRelease (myconsumer);
+  if (gc == NULL) return 1;
+  CGContextBeginPage ((CGContextRef)gc, NULL);
+  CGContextTranslateCTM((CGContextRef)gc, 0, h);
+  CGContextScaleCTM((CGContextRef)gc, 1.0f, -1.0f);
+  CGContextSaveGState((CGContextRef)gc);
+  fl_window = (void *)1; // TODO: something better
+  this->set_current();
+  fl_clip_region(0);
+  fl_line_style(FL_SOLID);
+  return 0;
+}
+
+int Fl_Clipboard_Device::stop(void)
+{
+  int w, h;
+  CGContextRestoreGState(fl_gc);
+  // first, write the pdf data to the clipboard
+  w = width; h = height;
+  CGContextEndPage (fl_gc);
+  CGContextRelease (fl_gc);
+  PasteboardRef clipboard = NULL;
+  PasteboardCreate (kPasteboardClipboard, &clipboard);
+  PasteboardClear(clipboard);
+  PasteboardPutItemFlavor (clipboard, (PasteboardItemID)1, 
+                          CFSTR("com.adobe.pdf"), // kUTTypePDF
+                          pdfdata_, kPasteboardFlavorNoFlags);
+    
+  // second, transform this PDF to a bitmap image and put it as PICT/tiff in 
clipboard
+  CGDataProviderRef prov = CGDataProviderCreateWithData(NULL, 
CFDataGetBytePtr(pdfdata_), CFDataGetLength(pdfdata_), NULL);
+  CGPDFDocumentRef pdfdoc = CGPDFDocumentCreateWithProvider(prov);
+  CGDataProviderRelease(prov);
+  CGColorSpaceRef space = 
CGColorSpaceCreateWithName(/*kCGColorSpaceGenericRGB*/ kCGColorSpaceUserRGB);
+  const int scale = 2;
+  w *= scale; h *= scale;
+  void *mem = malloc(w * h * sizeof(int));
+  fl_gc = CGBitmapContextCreate(mem, w, h, 8, w * 4, space, 
kCGImageAlphaPremultipliedFirst /*| kCGBitmapByteOrder32Host*/);
+  CFRelease(space);
+  if (fl_gc == NULL) { free(mem); return 1; }
+  CGRect rect = CGRectMake(0, 0, w, h);
+  CGContextSetRGBFillColor(fl_gc,  1,1,1,1);//need to clear background
+  CGContextFillRect(fl_gc, rect);
+  CGContextDrawPDFDocument(fl_gc, rect, pdfdoc, 1);
+  CGPDFDocumentRelease(pdfdoc);
+  CFRelease(pdfdata_);
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+  if(CGImageDestinationCreateWithData != NULL) {
+    CFMutableDataRef pictdata = CFDataCreateMutable(NULL, 0);
+#if __LP64__
+    CFStringRef  uti = CFSTR("public.tiff");
+#else
+    CFStringRef  uti = CFSTR("com.apple.pict");
+#endif
+    CGImageRef image = CGBitmapContextCreateImage(fl_gc);
+    CGImageDestinationRef dest = CGImageDestinationCreateWithData(pictdata, 
uti, 1, NULL);
+    CGImageDestinationAddImage(dest, image, NULL);
+    CGImageDestinationFinalize(dest);
+    CGImageRelease(image);
+    CFRelease(dest);
+#if !__LP64__
+    CFRange range = CFRangeMake(0, 512);
+    CFDataDeleteBytes(pictdata, range);// The PICT clipboard REQUIRES only the 
image data, not the header.
+#endif
+    PasteboardPutItemFlavor(clipboard, (PasteboardItemID)1, uti, pictdata, 
kPasteboardFlavorNoFlags );
+    CFRelease (pictdata);
+    }
+  else
+#endif
+  { // other way for < 10.4 that uses QuickTime:
+    GraphicsExportComponent exporter;
+    OSErr err = OpenADefaultComponent(GraphicsExporterComponentType, 
/*kQTFileTypePicture*/ 'PICT', &exporter);
+    err = GraphicsExportSetInputCGBitmapContext(exporter, fl_gc);
+    Handle dataHandle = NewHandle(0);
+    err = GraphicsExportSetOutputHandle(exporter, dataHandle);
+    unsigned long size;
+    err = GraphicsExportDoExport(exporter, &size);
+    err = CloseComponent(exporter); 
+    if(GetHandleSize(dataHandle) > 512) {
+      HLock(dataHandle);
+      // The clipboard REQUIRES only the image data, not the header.
+      CFDataRef pictdata = CFDataCreate(NULL, (const UInt8 *)*dataHandle + 
512, GetHandleSize(dataHandle) - 512);
+      HUnlock(dataHandle);
+      PasteboardPutItemFlavor(clipboard, (PasteboardItemID)1, 
+                             CFSTR("com.apple.pict"),
+                             pictdata,
+                             kPasteboardFlavorNoFlags ); 
+      CFRelease (pictdata);    
+    }
+    DisposeHandle(dataHandle);
+  }
+  CFRelease (clipboard);    
+  CGContextRelease(fl_gc);
+  fl_gc = NULL;
+  free(mem);
+  Fl_Display_Device::display_device()->set_current();
+  return 0;
+}
+
+void Fl_Clipboard_Device::translate(int x, int y)
+{
+  CGContextSaveGState(fl_gc);
+  CGContextTranslateCTM(fl_gc, x, y );
+  CGContextSaveGState(fl_gc);
+}
+
+void Fl_Clipboard_Device::untranslate(void)
+{
+  CGContextRestoreGState(fl_gc);
+  CGContextRestoreGState(fl_gc);
+}
+
+#endif // __APPLE__
+
+//
+// End of "$Id$".
+//

Copied: branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Device_win32.cxx (from 
rev 7531, branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Writer_win32.cxx)
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Device_win32.cxx            
                (rev 0)
+++ branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Device_win32.cxx    
2010-04-19 19:44:21 UTC (rev 7532)
@@ -0,0 +1,114 @@
+//
+// "$Id$"
+//
+// MSWin implementation of Fl_Clipboard_Writer class for the Fast Light Tool 
Kit (FLTK).
+//
+// Copyright 2010 by Bill Spitzak and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems to:
+//
+//     http://www.fltk.org/str.php
+//
+
+#ifdef WIN32
+
+#include <FL/Fl_Clipboard_Device.H>
+#include <FL/x.H>
+#include <FL/fl_draw.H>
+
+
+int Fl_Clipboard_Device::start(int w, int h)
+{
+  HDC oldflgc = fl_gc;
+  int factor = 32; // empirically set
+  RECT rect; rect.left = 0; rect.top = 0; rect.right=w*factor; 
rect.bottom=h*factor;
+  fl_gc = CreateEnhMetaFile (NULL, NULL, &rect, NULL);
+  if (fl_gc != NULL) {
+    SetGraphicsMode(fl_gc, GM_ADVANCED); // to allow for translations
+    SetTextAlign(fl_gc, TA_BASELINE|TA_LEFT);
+    SetBkMode(fl_gc, TRANSPARENT);
+  } 
+  else {
+    fl_gc = oldflgc;
+    return 1;
+  }
+  fl_clip_region(0);
+  fl_color(FL_BLACK);
+  fl_line_style(FL_SOLID);
+  SelectObject(fl_gc, (HGDIOBJ)(fl_current_xmap->pen));
+  gc = fl_gc;
+  this->set_current();
+  return 0;
+}
+
+int Fl_Clipboard_Device::stop(void)
+{
+  int w, h;
+  HENHMETAFILE hmf = CloseEnhMetaFile (fl_gc);
+  if ( hmf != NULL ) {
+    if ( OpenClipboard (NULL) ){
+      EmptyClipboard ();
+      SetClipboardData (CF_ENHMETAFILE, hmf);
+      CloseClipboard ();
+    }
+    DeleteEnhMetaFile(hmf);
+  }
+  DeleteDC(fl_gc);
+  Fl_Display_Device::display_device()->set_current();
+  fl_gc = NULL;
+  return 0;
+}
+
+static int translate_stack_depth = 0;
+const int translate_stack_max = 5;
+static int translate_stack_x[translate_stack_max];
+static int translate_stack_y[translate_stack_max];
+
+static void do_translate(int x, int y)
+{
+  XFORM tr;
+  tr.eM11 = tr.eM22 = 1;
+  tr.eM12 = tr.eM21 = 0;
+  tr.eDx =  x;
+  tr.eDy =  y;
+  ModifyWorldTransform(fl_gc, &tr, MWT_LEFTMULTIPLY);
+}
+
+void Fl_Clipboard_Device::translate(int x, int y)
+{
+  do_translate(x, y);
+  if (translate_stack_depth < translate_stack_max) {
+    translate_stack_x[translate_stack_depth] = x;
+    translate_stack_y[translate_stack_depth] = y;
+    translate_stack_depth++;
+  }
+}
+
+void Fl_Clipboard_Device::untranslate(void)
+{
+  if (translate_stack_depth > 0) {
+    translate_stack_depth--;
+    do_translate( - translate_stack_x[translate_stack_depth], - 
translate_stack_y[translate_stack_depth] );
+  }
+}
+
+#endif // WIN32
+
+//
+// End of "$Id$".
+//

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to