fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
  SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation)  

print_panel.cxx

Go to the documentation of this file.
00001 //
00002 // "$Id: print_panel.cxx 7913 2010-11-29 18:18:27Z greg.ercolano $"
00003 //
00004 // Print panel for the Fast Light Tool Kit (FLTK).
00005 //
00006 // Copyright 1998-2010 by Bill Spitzak and others.
00007 //
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Library General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2 of the License, or (at your option) any later version.
00012 //
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Library General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU Library General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021 // USA.
00022 //
00023 // Please report all bugs and problems on the following page:
00024 //
00025 //     http://www.fltk.org/str.php
00026 //
00027 
00028 //
00029 // This file is "work in progress".  The main parts have been copied
00030 // from fluid's print_panel{.fl|.h|.cxx} and hand-edited to produce
00031 // a working version w/o global variables.  The intention is to move
00032 // all static variables into an own class, and to name this class
00033 // Fl_Printer_Chooser or similar...
00034 //
00035 // Todo:
00036 //
00037 //   -  Currently preferences can't be saved, and there are options that
00038 //      are not yet used for printing.
00039 //   -  This file can only be used as an include file in Fl_PS_Printer.cxx
00040 //   -  The use of static variables should be avoided.
00041 //   -  Probably much more ...
00042 //
00043 
00044 #include "print_panel.h"
00045 #include <stdio.h>
00046 #include <stdlib.h>
00047 #include "../src/flstring.h"
00048 #include <FL/Fl_Preferences.H>
00049 #include <FL/Fl_Int_Input.H>
00050 
00051 static Fl_Preferences print_prefs(Fl_Preferences::USER, "fltk.org", "printers");
00052 static Fl_Double_Window *print_panel=(Fl_Double_Window *)0;
00053 static Fl_Group *print_panel_controls=(Fl_Group *)0;
00054 static Fl_Choice *print_choice=(Fl_Choice *)0;
00055 static Fl_Button *print_properties=(Fl_Button *)0;
00056 static Fl_Box *print_status=(Fl_Box *)0;
00057 static Fl_Round_Button *print_all=(Fl_Round_Button *)0;
00058 static Fl_Round_Button *print_pages=(Fl_Round_Button *)0;
00059 static Fl_Round_Button *print_selection=(Fl_Round_Button *)0;
00060 static Fl_Check_Button *print_collate_button=(Fl_Check_Button *)0;
00061 static Fl_Group *print_collate_group[2]={(Fl_Group *)0};
00062 static Fl_Progress *print_progress=(Fl_Progress *)0;
00063 static Fl_Double_Window *print_properties_panel=(Fl_Double_Window *)0;
00064 static Fl_Choice *print_page_size=(Fl_Choice *)0;
00065 static Fl_Int_Input *print_from=(Fl_Int_Input *)0;
00066 static Fl_Int_Input *print_to=(Fl_Int_Input *)0;
00067 static Fl_Spinner *print_copies=(Fl_Spinner *)0;
00068 
00069 static int print_start = 0;     // 1 if print_okay has been clicked
00070 
00071 static void cb_print_choice(Fl_Choice*, void*) {
00072   print_update_status();
00073 }
00074 
00075 static void cb_print_properties(Fl_Button*, void*) {
00076   print_properties_panel->show();
00077 }
00078 
00079 static void cb_print_all(Fl_Round_Button*, void*) {
00080   print_from->deactivate();
00081   print_to->deactivate();
00082 }
00083 
00084 static void cb_print_pages(Fl_Round_Button*, void*) {
00085   print_from->activate();
00086   print_to->activate();
00087 }
00088 
00089 static void cb_print_selection(Fl_Round_Button*, void*) {
00090   print_from->deactivate();
00091   print_to->deactivate();
00092 }
00093 
00094 static void cb_print_copies(Fl_Spinner*, void*) {
00095   if (print_copies->value() == 1) {
00096     print_collate_button->deactivate();
00097     print_collate_group[0]->deactivate();
00098     print_collate_group[1]->deactivate();
00099   } else {
00100 /*    print_collate_button->activate(); // TODO: manage collate options
00101     print_collate_group[0]->activate();
00102     print_collate_group[1]->activate(); */
00103   };
00104 }
00105 
00106 static void cb_print_collate_button(Fl_Check_Button*, void*) {
00107   int i = print_collate_button->value() != 0;
00108   print_collate_group[i]->show();
00109   print_collate_group[1 - i]->hide();
00110 }
00111 
00112 static void cb_Cancel(Fl_Button*, void*) {
00113   print_start = 0;
00114   print_panel->hide();
00115 }
00116 
00117 static void cb_print_properties_panel(Fl_Double_Window*, void*) {
00118   print_properties_panel->hide();
00119   print_update_status();
00120 }
00121 
00122 static Fl_Menu_Item menu_print_page_size[] = {
00123  {"Letter", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
00124  {"A4", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
00125  {0,0,0,0,0,0,0,0,0}
00126 };
00127 
00128 #include <FL/Fl_Pixmap.H>
00129 static const char *idata_print_color[] = {
00130 "24 24 17 1",
00131 " \tc None",
00132 ".\tc #FFFF00",
00133 "+\tc #C8FF00",
00134 "@\tc #00FF00",
00135 "#\tc #FFC800",
00136 "$\tc #FF0000",
00137 "%\tc #00FFFF",
00138 "&\tc #000000",
00139 "*\tc #FF00FF",
00140 "=\tc #00FFC8",
00141 "-\tc #FF00C8",
00142 ";\tc #00C800",
00143 ">\tc #C80000",
00144 ",\tc #0000C8",
00145 "\'\tc #0000FF",
00146 ")\tc #00C8FF",
00147 "!\tc #C800FF",
00148 "         ......         ",
00149 "       ..........       ",
00150 "      ............      ",
00151 "     ..............     ",
00152 "     ..............     ",
00153 "    ................    ",
00154 "    ................    ",
00155 "    ................    ",
00156 "    +@@@@@@+#$$$$$$#    ",
00157 "   %@@@@@@@&&$$$$$$$*   ",
00158 "  %%@@@@@@&&&&$$$$$$**  ",
00159 " %%%=@@@@&&&&&&$$$$-*** ",
00160 " %%%%@@@;&&&&&&>$$$**** ",
00161 "%%%%%%@@&&&&&&&&$$******",
00162 "%%%%%%%@&&&&&&&&$*******",
00163 "%%%%%%%%,&&&&&&,********",
00164 "%%%%%%%%\'\'\'\'\'\'\'\'********",
00165 "%%%%%%%%\'\'\'\'\'\'\'\'********",
00166 "%%%%%%%%\'\'\'\'\'\'\'\'********",
00167 " %%%%%%%)\'\'\'\'\'\'!******* ",
00168 " %%%%%%%%\'\'\'\'\'\'******** ",
00169 "  %%%%%%%%\'\'\'\'********  ",
00170 "   %%%%%%%%\'\'********   ",
00171 "     %%%%%%  ******     "
00172 };
00173 static Fl_Pixmap image_print_color(idata_print_color);
00174 
00175 static const char *idata_print_gray[] = {
00176 "24 24 17 1",
00177 " \tc None",
00178 ".\tc #E3E3E3",
00179 "+\tc #D2D2D2",
00180 "@\tc #969696",
00181 "#\tc #C2C2C2",
00182 "$\tc #4C4C4C",
00183 "%\tc #B2B2B2",
00184 "&\tc #000000",
00185 "*\tc #696969",
00186 "=\tc #ACACAC",
00187 "-\tc #626262",
00188 ";\tc #767676",
00189 ">\tc #3C3C3C",
00190 ",\tc #161616",
00191 "\'\tc #1C1C1C",
00192 ")\tc #929292",
00193 "!\tc #585858",
00194 "         ......         ",
00195 "       ..........       ",
00196 "      ............      ",
00197 "     ..............     ",
00198 "     ..............     ",
00199 "    ................    ",
00200 "    ................    ",
00201 "    ................    ",
00202 "    +@@@@@@+#$$$$$$#    ",
00203 "   %@@@@@@@&&$$$$$$$*   ",
00204 "  %%@@@@@@&&&&$$$$$$**  ",
00205 " %%%=@@@@&&&&&&$$$$-*** ",
00206 " %%%%@@@;&&&&&&>$$$**** ",
00207 "%%%%%%@@&&&&&&&&$$******",
00208 "%%%%%%%@&&&&&&&&$*******",
00209 "%%%%%%%%,&&&&&&,********",
00210 "%%%%%%%%\'\'\'\'\'\'\'\'********",
00211 "%%%%%%%%\'\'\'\'\'\'\'\'********",
00212 "%%%%%%%%\'\'\'\'\'\'\'\'********",
00213 " %%%%%%%)\'\'\'\'\'\'!******* ",
00214 " %%%%%%%%\'\'\'\'\'\'******** ",
00215 "  %%%%%%%%\'\'\'\'********  ",
00216 "   %%%%%%%%\'\'********   ",
00217 "     %%%%%%  ******     "
00218 };
00219 static Fl_Pixmap image_print_gray(idata_print_gray);
00220 
00221 static Fl_Button *print_output_mode[4]={(Fl_Button *)0};
00222 
00223 static void cb_Save(Fl_Return_Button*, void*) {
00224   print_properties_panel->hide();
00225 
00226   char name[1024];
00227   int val;
00228   const char *printer = (const char *)print_choice->menu()[print_choice->value()].user_data();
00229 
00230   snprintf(name, sizeof(name), "%s/page_size", printer);
00231   print_prefs.set(name, print_page_size->value());
00232 
00233   snprintf(name, sizeof(name), "%s/output_mode", printer);
00234   for (val = 0; val < 4; val ++) {
00235     if (print_output_mode[val]->value()) break;
00236   }
00237   print_prefs.set(name, val);
00238 }
00239 
00240 static void cb_Cancel1(Fl_Button*, void*) {
00241   print_properties_panel->hide();
00242   print_update_status();
00243 }
00244 
00245 static void cb_Use(Fl_Button*, void*) {
00246   print_properties_panel->hide();
00247 }
00248 
00249 Fl_Double_Window* make_print_panel() {
00250   { print_panel = new Fl_Double_Window(465, 235, Fl_Printer::dialog_title);
00251     { print_panel_controls = new Fl_Group(10, 10, 447, 216);
00252       { print_choice = new Fl_Choice(133, 10, 181, 25, Fl_Printer::dialog_printer);
00253         print_choice->down_box(FL_BORDER_BOX);
00254         print_choice->labelfont(1);
00255         print_choice->callback((Fl_Callback*)cb_print_choice);
00256         print_choice->when(FL_WHEN_CHANGED);
00257       } // Fl_Choice* print_choice
00258       { print_properties = new Fl_Button(314, 10, 115, 25, Fl_Printer::dialog_properties);
00259         print_properties->callback((Fl_Callback*)cb_print_properties);
00260       } // Fl_Button* print_properties
00261       { print_status = new Fl_Box(0, 41, print_panel_controls->w(), 17, "printer/job status");
00262         print_status->align(Fl_Align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE|FL_ALIGN_LEFT));
00263       } // Fl_Box* print_status
00264       { Fl_Group* o = new Fl_Group(10, 86, 227, 105, Fl_Printer::dialog_range);
00265         o->box(FL_THIN_DOWN_BOX);
00266         o->labelfont(1);
00267         o->align(Fl_Align(FL_ALIGN_TOP_LEFT));
00268         { print_all = new Fl_Round_Button(20, 96, 38, 25, Fl_Printer::dialog_all);
00269           print_all->type(102);
00270           print_all->down_box(FL_ROUND_DOWN_BOX);
00271           print_all->value(1);
00272           print_all->callback((Fl_Callback*)cb_print_all);
00273         } // Fl_Round_Button* print_all
00274         { print_pages = new Fl_Round_Button(20, 126, 64, 25, Fl_Printer::dialog_pages);
00275           print_pages->type(102);
00276           print_pages->down_box(FL_ROUND_DOWN_BOX);
00277           print_pages->callback((Fl_Callback*)cb_print_pages);
00278         } // Fl_Round_Button* print_pages
00279         { print_selection = new Fl_Round_Button(20, 156, 82, 25, "Selection");
00280           print_selection->type(102);
00281           print_selection->down_box(FL_ROUND_DOWN_BOX);
00282           print_selection->callback((Fl_Callback*)cb_print_selection);
00283         } // Fl_Round_Button* print_selection
00284         { print_from = new Fl_Int_Input(136, 126, 28, 25, Fl_Printer::dialog_from);
00285           print_from->type(2);
00286           print_from->textfont(4);
00287           print_from->deactivate();
00288         } // Fl_Int_Input* print_from
00289         { print_to = new Fl_Int_Input(199, 126, 28, 25, Fl_Printer::dialog_to);
00290           print_to->type(2);
00291           print_to->textfont(4);
00292           print_to->deactivate();
00293         } // Fl_Int_Input* print_to
00294         o->end();
00295       } // Fl_Group* o
00296       { Fl_Group* o = new Fl_Group(247, 86, 210, 105, Fl_Printer::dialog_copies);
00297         o->box(FL_THIN_DOWN_BOX);
00298         o->labelfont(1);
00299         o->align(Fl_Align(FL_ALIGN_TOP_LEFT));
00300         { print_copies = new Fl_Spinner(321, 96, 45, 25, Fl_Printer::dialog_copyNo);
00301           print_copies->callback((Fl_Callback*)cb_print_copies);
00302           print_copies->when(FL_WHEN_CHANGED);
00303         } // Fl_Spinner* print_copies
00304         { print_collate_button = new Fl_Check_Button(376, 96, 64, 25, "Collate");
00305           print_collate_button->down_box(FL_DOWN_BOX);
00306           print_collate_button->callback((Fl_Callback*)cb_print_collate_button);
00307           print_collate_button->when(FL_WHEN_CHANGED);
00308           print_collate_button->deactivate();
00309         } // Fl_Check_Button* print_collate_button
00310         { print_collate_group[0] = new Fl_Group(257, 131, 191, 50);
00311           print_collate_group[0]->deactivate();
00312           { Fl_Box* o = new Fl_Box(287, 141, 30, 40, "1");
00313             o->box(FL_BORDER_BOX);
00314             o->color(FL_BACKGROUND2_COLOR);
00315             o->labelsize(11);
00316             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00317             o->deactivate();
00318           } // Fl_Box* o
00319           { Fl_Box* o = new Fl_Box(272, 136, 30, 40, "1");
00320             o->box(FL_BORDER_BOX);
00321             o->color(FL_BACKGROUND2_COLOR);
00322             o->labelsize(11);
00323             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00324             o->deactivate();
00325           } // Fl_Box* o
00326           { Fl_Box* o = new Fl_Box(257, 131, 30, 40, "1");
00327             o->box(FL_BORDER_BOX);
00328             o->color(FL_BACKGROUND2_COLOR);
00329             o->labelsize(11);
00330             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00331             o->deactivate();
00332           } // Fl_Box* o
00333           { Fl_Box* o = new Fl_Box(352, 141, 30, 40, "2");
00334             o->box(FL_BORDER_BOX);
00335             o->color(FL_BACKGROUND2_COLOR);
00336             o->labelsize(11);
00337             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00338             o->deactivate();
00339           } // Fl_Box* o
00340           { Fl_Box* o = new Fl_Box(337, 136, 30, 40, "2");
00341             o->box(FL_BORDER_BOX);
00342             o->color(FL_BACKGROUND2_COLOR);
00343             o->labelsize(11);
00344             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00345             o->deactivate();
00346           } // Fl_Box* o
00347           { Fl_Box* o = new Fl_Box(322, 131, 30, 40, "2");
00348             o->box(FL_BORDER_BOX);
00349             o->color(FL_BACKGROUND2_COLOR);
00350             o->labelsize(11);
00351             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00352             o->deactivate();
00353           } // Fl_Box* o
00354           { Fl_Box* o = new Fl_Box(417, 141, 30, 40, "3");
00355             o->box(FL_BORDER_BOX);
00356             o->color(FL_BACKGROUND2_COLOR);
00357             o->labelsize(11);
00358             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00359             o->deactivate();
00360           } // Fl_Box* o
00361           { Fl_Box* o = new Fl_Box(402, 136, 30, 40, "3");
00362             o->box(FL_BORDER_BOX);
00363             o->color(FL_BACKGROUND2_COLOR);
00364             o->labelsize(11);
00365             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00366             o->deactivate();
00367           } // Fl_Box* o
00368           { Fl_Box* o = new Fl_Box(387, 131, 30, 40, "3");
00369             o->box(FL_BORDER_BOX);
00370             o->color(FL_BACKGROUND2_COLOR);
00371             o->labelsize(11);
00372             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00373             o->deactivate();
00374           } // Fl_Box* o
00375           print_collate_group[0]->end();
00376         } // Fl_Group* print_collate_group[0]
00377         { print_collate_group[1] = new Fl_Group(257, 131, 191, 50);
00378           print_collate_group[1]->hide();
00379           print_collate_group[1]->deactivate();
00380           { Fl_Box* o = new Fl_Box(287, 141, 30, 40, "3");
00381             o->box(FL_BORDER_BOX);
00382             o->color(FL_BACKGROUND2_COLOR);
00383             o->labelsize(11);
00384             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00385           } // Fl_Box* o
00386           { Fl_Box* o = new Fl_Box(272, 136, 30, 40, "2");
00387             o->box(FL_BORDER_BOX);
00388             o->color(FL_BACKGROUND2_COLOR);
00389             o->labelsize(11);
00390             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00391           } // Fl_Box* o
00392           { Fl_Box* o = new Fl_Box(257, 131, 30, 40, "1");
00393             o->box(FL_BORDER_BOX);
00394             o->color(FL_BACKGROUND2_COLOR);
00395             o->labelsize(11);
00396             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00397           } // Fl_Box* o
00398           { Fl_Box* o = new Fl_Box(352, 141, 30, 40, "3");
00399             o->box(FL_BORDER_BOX);
00400             o->color(FL_BACKGROUND2_COLOR);
00401             o->labelsize(11);
00402             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00403           } // Fl_Box* o
00404           { Fl_Box* o = new Fl_Box(337, 136, 30, 40, "2");
00405             o->box(FL_BORDER_BOX);
00406             o->color(FL_BACKGROUND2_COLOR);
00407             o->labelsize(11);
00408             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00409           } // Fl_Box* o
00410           { Fl_Box* o = new Fl_Box(322, 131, 30, 40, "1");
00411             o->box(FL_BORDER_BOX);
00412             o->color(FL_BACKGROUND2_COLOR);
00413             o->labelsize(11);
00414             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00415           } // Fl_Box* o
00416           { Fl_Box* o = new Fl_Box(417, 141, 30, 40, "3");
00417             o->box(FL_BORDER_BOX);
00418             o->color(FL_BACKGROUND2_COLOR);
00419             o->labelsize(11);
00420             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00421           } // Fl_Box* o
00422           { Fl_Box* o = new Fl_Box(402, 136, 30, 40, "2");
00423             o->box(FL_BORDER_BOX);
00424             o->color(FL_BACKGROUND2_COLOR);
00425             o->labelsize(11);
00426             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00427           } // Fl_Box* o
00428           { Fl_Box* o = new Fl_Box(387, 131, 30, 40, "1");
00429             o->box(FL_BORDER_BOX);
00430             o->color(FL_BACKGROUND2_COLOR);
00431             o->labelsize(11);
00432             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
00433           } // Fl_Box* o
00434           print_collate_group[1]->end();
00435         } // Fl_Group* print_collate_group[1]
00436         o->end();
00437       } // Fl_Group* o
00438       { Fl_Return_Button* o = new Fl_Return_Button(279, 201, 100, 25, Fl_Printer::dialog_print_button);
00439         o->callback((Fl_Callback*)print_cb);
00440       } // Fl_Return_Button* o
00441       { Fl_Button* o = new Fl_Button(389, 201, 68, 25, Fl_Printer::dialog_cancel_button);
00442         o->callback((Fl_Callback*)cb_Cancel);
00443       } // Fl_Button* o
00444       print_panel_controls->end();
00445     } // Fl_Group* print_panel_controls
00446     { print_progress = new Fl_Progress(10, 203, 289, 21);
00447       print_progress->selection_color((Fl_Color)4);
00448       print_progress->hide();
00449     } // Fl_Progress* print_progress
00450     print_panel->set_modal();
00451     print_panel->end();
00452   } // Fl_Double_Window* print_panel
00453   { print_properties_panel = new Fl_Double_Window(290, 130, Fl_Printer::property_title);
00454     print_properties_panel->callback((Fl_Callback*)cb_print_properties_panel);
00455     { print_page_size = new Fl_Choice(150, 10, 80, 25, Fl_Printer::property_pagesize);
00456       print_page_size->down_box(FL_BORDER_BOX);
00457       print_page_size->labelfont(FL_HELVETICA);
00458       print_page_size->menu(menu_print_page_size);
00459     } // Fl_Choice* print_page_size
00460     { Fl_Group* o = new Fl_Group(110, 45, 170, 40, Fl_Printer::property_mode);
00461       o->labelfont(FL_HELVETICA);
00462       o->align(Fl_Align(FL_ALIGN_LEFT));
00463       { print_output_mode[0] = new Fl_Button(110, 45, 30, 40);
00464         print_output_mode[0]->type(102);
00465         print_output_mode[0]->box(FL_BORDER_BOX);
00466         print_output_mode[0]->down_box(FL_BORDER_BOX);
00467         print_output_mode[0]->value(1);
00468         print_output_mode[0]->color(FL_BACKGROUND2_COLOR);
00469         print_output_mode[0]->selection_color(FL_FOREGROUND_COLOR);
00470         print_output_mode[0]->image(image_print_color);
00471       } // Fl_Button* print_output_mode[0]
00472       { print_output_mode[1] = new Fl_Button(150, 50, 40, 30);
00473         print_output_mode[1]->type(102);
00474         print_output_mode[1]->box(FL_BORDER_BOX);
00475         print_output_mode[1]->down_box(FL_BORDER_BOX);
00476         print_output_mode[1]->color(FL_BACKGROUND2_COLOR);
00477         print_output_mode[1]->selection_color(FL_FOREGROUND_COLOR);
00478         print_output_mode[1]->image(image_print_color);
00479       } // Fl_Button* print_output_mode[1]
00480       { print_output_mode[2] = new Fl_Button(200, 45, 30, 40);
00481         print_output_mode[2]->type(102);
00482         print_output_mode[2]->box(FL_BORDER_BOX);
00483         print_output_mode[2]->down_box(FL_BORDER_BOX);
00484         print_output_mode[2]->color(FL_BACKGROUND2_COLOR);
00485         print_output_mode[2]->selection_color(FL_FOREGROUND_COLOR);
00486         print_output_mode[2]->image(image_print_gray);
00487       } // Fl_Button* print_output_mode[2]
00488       { print_output_mode[3] = new Fl_Button(240, 50, 40, 30);
00489         print_output_mode[3]->type(102);
00490         print_output_mode[3]->box(FL_BORDER_BOX);
00491         print_output_mode[3]->down_box(FL_BORDER_BOX);
00492         print_output_mode[3]->color(FL_BACKGROUND2_COLOR);
00493         print_output_mode[3]->selection_color(FL_FOREGROUND_COLOR);
00494         print_output_mode[3]->image(image_print_gray);
00495       } // Fl_Button* print_output_mode[3]
00496       o->end();
00497     } // Fl_Group* o
00498     { Fl_Return_Button* o = new Fl_Return_Button(93, 95, 99, 25, Fl_Printer::property_save);
00499       o->callback((Fl_Callback*)cb_Save);
00500     } // Fl_Return_Button* o
00501     { Fl_Button* o = new Fl_Button(202, 95, 78, 25, Fl_Printer::property_cancel);
00502       o->callback((Fl_Callback*)cb_Cancel1);
00503     } // Fl_Button* o
00504     { Fl_Button* o = new Fl_Button(10, 95, 73, 25, Fl_Printer::property_use);
00505       o->callback((Fl_Callback*)cb_Use);
00506     } // Fl_Button* o
00507     print_properties_panel->set_modal();
00508     print_properties_panel->end();
00509   } // Fl_Double_Window* print_properties_panel
00510   return print_properties_panel;
00511 }
00512 
00513 void print_cb(Fl_Return_Button *, void *) {
00514   print_start = 1;
00515   print_panel->hide();
00516 }
00517 
00518 void print_load() {
00519   FILE *lpstat;
00520   char line[1024], name[1024], *nptr, qname[2048], *qptr, defname[1024];
00521   int i;
00522 
00523   if (print_choice->size() > 1) {
00524     for (i = 1; print_choice->text(i); i ++) {
00525       free(print_choice->menu()[i].user_data());
00526     }
00527   }
00528 
00529   print_choice->clear();
00530   print_choice->add(Fl_Printer::dialog_print_to_file, 0, 0, 0, FL_MENU_DIVIDER);
00531   print_choice->value(0);
00532   
00533   print_start = 0;
00534 
00535   defname[0] = '\0';
00536 
00537   if ((lpstat = popen("LC_MESSAGES=C LANG=C lpstat -p -d", "r")) != NULL) {
00538     while (fgets(line, sizeof(line), lpstat)) {
00539       if (!strncmp(line, "printer ", 8) &&
00540           sscanf(line + 8, "%s", name) == 1) {
00541         for (nptr = name, qptr = qname; *nptr; *qptr++ = *nptr++) {
00542           if (*nptr == '/') *qptr++ = '\\';
00543         }
00544         *qptr = '\0';
00545 
00546         print_choice->add(qname, 0, 0, (void *)strdup(name), 0);
00547       } else if (!strncmp(line, "system default destination: ", 28)) {
00548         if (sscanf(line + 28, "%s", defname) != 1) defname[0] = '\0';
00549       }
00550     }
00551     pclose(lpstat);
00552   }
00553 
00554   if (defname[0]) {
00555     for (i = 1; print_choice->text(i); i ++) {
00556       if (!strcmp((char *)print_choice->menu()[i].user_data(), defname)) {
00557         print_choice->value(i);
00558         break;
00559       }
00560     }
00561   } else if (print_choice->size() > 2) print_choice->value(1);
00562 
00563   print_update_status();
00564 
00565 } // print_load()
00566 
00567 void print_update_status() {
00568   FILE *lpstat;
00569   char command[1024];
00570   static char status[1024];
00571   const char *printer = (const char *)print_choice->menu()[print_choice->value()].user_data();
00572 
00573   if (print_choice->value()) {
00574     snprintf(command, sizeof(command), "lpstat -p '%s'", printer);
00575     if ((lpstat = popen(command, "r")) != NULL) {
00576       if (fgets(status, sizeof(status), lpstat)==0) { /* ignore */ }
00577       pclose(lpstat);
00578     } else strcpy(status, "printer status unavailable");
00579   } else status[0] = '\0';
00580 
00581   print_status->label(status);
00582 
00583   char name[1024];
00584   int val;
00585 
00586   snprintf(name, sizeof(name), "%s/page_size", printer);
00587   print_prefs.get(name, val, 1);
00588   print_page_size->value(val);
00589 
00590   snprintf(name, sizeof(name), "%s/output_mode", printer);
00591   print_prefs.get(name, val, 0);
00592   print_output_mode[val]->setonly();
00593 }
00594 
00595 //
00596 // End of "$Id: print_panel.cxx 7913 2010-11-29 18:18:27Z greg.ercolano $".
00597 //