I suggest to use the print support capability of 1.3 in fluid
(and also to use Fl_Native_File_Chooser). I enclose here the
patch file for that. This renders file fluid/print_panel.cxx useless.

Is this OK ?

Index: fluid/fluid.cxx
===================================================================
--- fluid/fluid.cxx     (revision 8864)
+++ fluid/fluid.cxx     (working copy)
@@ -32,6 +32,8 @@
 #include <FL/Fl_PNG_Image.H>
 #include <FL/fl_message.H>
 #include <FL/filename.H>
+#include <FL/Fl_Native_File_Chooser.H>
+#include <Fl/Fl_Printer.H>
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -42,9 +44,9 @@
 #include "alignment_panel.h"
 #include "function_panel.h"
 #include "template_panel.h"
-#if !defined(WIN32) || defined(__CYGWIN__)
+/*#if !defined(WIN32) || defined(__CYGWIN__)
 #  include "print_panel.cxx"
-#endif // !WIN32 || __CYGWIN__
+#endif // !WIN32 || __CYGWIN__*/

 #if defined(WIN32) && !defined(__CYGWIN__)
 #  include <direct.h>
@@ -187,12 +189,19 @@
 }

 void save_cb(Fl_Widget *, void *v) {
+  Fl_Native_File_Chooser fnfc;
   const char *c = filename;
   if (v || !c || !*c) {
-    fl_file_chooser_ok_label("Save");
+    /*fl_file_chooser_ok_label("Save");
     c=fl_file_chooser("Save To:", "FLUID Files (*.f[ld])", c);
     fl_file_chooser_ok_label(NULL);
-    if (!c) return;
+    if (!c) return;*/
+
+    fnfc.title("Save To:");
+    fnfc.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
+    fnfc.filter("FLUID Files\t*.f[ld]");
+    if (fnfc.show() != 0) return;
+    c = fnfc.filename();

     if (!access(c, 0)) {
       const char *basename;
@@ -461,10 +470,18 @@
   }
   const char *c;
   const char *oldfilename;
-  fl_file_chooser_ok_label("Open");
+  /*fl_file_chooser_ok_label("Open");
   c = fl_file_chooser("Open:", "FLUID Files (*.f[ld])", filename);
   fl_file_chooser_ok_label(NULL);
-  if (!c) return;
+  if (!c) return;*/
+
+  Fl_Native_File_Chooser fnfc;
+  fnfc.title("Open:");
+  fnfc.type(Fl_Native_File_Chooser::BROWSE_FILE);
+  fnfc.filter("FLUID Files\t*.f[ld]\n");
+  if (fnfc.show() != 0) return;
+  c = fnfc.filename();
+
   oldfilename = filename;
   filename    = NULL;
   set_filename(c);
@@ -921,7 +938,73 @@


 ////////////////////////////////////////////////////////////////
+void print_menu_cb(Fl_Widget *, void *) {
+  int w, h, ww, hh;
+  int frompage, topage;
+  Fl_Type      *t;                     // Current widget
+  int          num_windows;            // Number of windows
+  Fl_Window_Type *windows[1000];       // Windows to print
+  int          winpage;                // Current window page
+  Fl_Window *win;
+
+  for (t = Fl_Type::first, num_windows = 0; t; t = t->next) {
+    if (t->is_window()) {
+      windows[num_windows] = (Fl_Window_Type *)t;
+      if (!((Fl_Window*)(windows[num_windows]->o))->shown()) continue;
+      num_windows ++;
+    }
+  }
+
+  Fl_Printer myprinter;
+  if ( myprinter.start_job(num_windows, &frompage, &topage) ) return;
+  int pagecount = 0;
+  for (winpage = 0; winpage < num_windows; winpage++) {
+    float scale = 1, scale_x = 1, scale_y = 1;
+    if (winpage+1 < frompage || winpage+1 > topage) continue;
+    myprinter.start_page();
+    myprinter.printable_rect(&w, &h);
+    // Get the time and date...
+    time_t curtime = time(NULL);
+    struct tm *curdate = localtime(&curtime);
+    char date[1024];
+    strftime(date, sizeof(date), "%c", curdate);
+    fl_font(FL_HELVETICA, 12);
+    fl_color(FL_BLACK);
+    fl_draw(date, (w - (int)fl_width(date))/2, fl_height());
+    sprintf(date, "%d/%d", ++pagecount, topage-frompage+1);
+    fl_draw(date, w - (int)fl_width(date), fl_height());
+    // Get the base filename...
+    const char *basename = strrchr(filename,
+#ifdef WIN32
+                                  '\\'
+#else
+                                  '/'
+#endif
+                                  );
+    if (basename) basename ++;
+    else basename = filename;
+    sprintf(date, "%s", basename);
+    fl_draw(date, 0, fl_height());
+// print centered and scaled to fit in the page
+    win = (Fl_Window*)windows[winpage]->o;
+    ww = win->decorated_w();
+    if(ww > w) scale_x = float(w)/ww;
+    hh = win->decorated_h();
+    if(hh > h) scale_y = float(h)/hh;
+    if (scale_x < scale) scale = scale_x;
+    if (scale_y < scale) scale = scale_y;
+    if (scale < 1) {
+      myprinter.scale(scale);
+      myprinter.printable_rect(&w, &h);
+      }
+    myprinter.origin(w/2, h/2);
+    myprinter.print_window(win, -ww/2, -hh/2);
+    myprinter.end_page();
+  }
+  myprinter.end_job();
+}

+/*
 #if defined(WIN32) && !defined(__CYGWIN__)
 // Draw a shaded box...
 static void win_box(int x, int y, int w, int h) {
@@ -1619,7 +1702,7 @@
   print_panel->hide();
 }
 #endif // WIN32 && !__CYGWIN__
-
+*/
 ////////////////////////////////////////////////////////////////

 extern Fl_Menu_Item New_Menu[];

_______________________________________________
fltk-dev mailing list
fltk-dev@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to