1 //
2 // "$Id: print_panel.cxx 7913 2010-11-29 18:18:27Z greg.ercolano $"
3 //
4 // Print panel for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // Library General Public License for more details.
17 //
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 // USA.
22 //
23 // Please report all bugs and problems on the following page:
24 //
25 //     http://www.fltk.org/str.php
26 //
27 
28 //
29 // This file is "work in progress".  The main parts have been copied
30 // from fluid's print_panel{.fl|.h|.cxx} and hand-edited to produce
31 // a working version w/o global variables.  The intention is to move
32 // all static variables into an own class, and to name this class
33 // Fl_Printer_Chooser or similar...
34 //
35 // Todo:
36 //
37 //   -	Currently preferences can't be saved, and there are options that
38 //	are not yet used for printing.
39 //   -	This file can only be used as an include file in Fl_PS_Printer.cxx
40 //   -	The use of static variables should be avoided.
41 //   -	Probably much more ...
42 //
43 
44 #include "print_panel.h"
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include "../src/flstring.h"
48 #include <FL/Fl_Preferences.H>
49 #include <FL/Fl_Int_Input.H>
50 
51 static Fl_Preferences print_prefs(Fl_Preferences::USER, "fltk.org", "printers");
52 static Fl_Double_Window *print_panel=(Fl_Double_Window *)0;
53 static Fl_Group *print_panel_controls=(Fl_Group *)0;
54 static Fl_Choice *print_choice=(Fl_Choice *)0;
55 static Fl_Button *print_properties=(Fl_Button *)0;
56 static Fl_Box *print_status=(Fl_Box *)0;
57 static Fl_Round_Button *print_all=(Fl_Round_Button *)0;
58 static Fl_Round_Button *print_pages=(Fl_Round_Button *)0;
59 static Fl_Round_Button *print_selection=(Fl_Round_Button *)0;
60 static Fl_Check_Button *print_collate_button=(Fl_Check_Button *)0;
61 static Fl_Group *print_collate_group[2]={(Fl_Group *)0};
62 static Fl_Progress *print_progress=(Fl_Progress *)0;
63 static Fl_Double_Window *print_properties_panel=(Fl_Double_Window *)0;
64 static Fl_Choice *print_page_size=(Fl_Choice *)0;
65 static Fl_Int_Input *print_from=(Fl_Int_Input *)0;
66 static Fl_Int_Input *print_to=(Fl_Int_Input *)0;
67 static Fl_Spinner *print_copies=(Fl_Spinner *)0;
68 
69 static int print_start = 0;	// 1 if print_okay has been clicked
70 
cb_print_choice(Fl_Choice *,void *)71 static void cb_print_choice(Fl_Choice*, void*) {
72   print_update_status();
73 }
74 
cb_print_properties(Fl_Button *,void *)75 static void cb_print_properties(Fl_Button*, void*) {
76   print_properties_panel->show();
77 }
78 
cb_print_all(Fl_Round_Button *,void *)79 static void cb_print_all(Fl_Round_Button*, void*) {
80   print_from->deactivate();
81   print_to->deactivate();
82 }
83 
cb_print_pages(Fl_Round_Button *,void *)84 static void cb_print_pages(Fl_Round_Button*, void*) {
85   print_from->activate();
86   print_to->activate();
87 }
88 
cb_print_selection(Fl_Round_Button *,void *)89 static void cb_print_selection(Fl_Round_Button*, void*) {
90   print_from->deactivate();
91   print_to->deactivate();
92 }
93 
cb_print_copies(Fl_Spinner *,void *)94 static void cb_print_copies(Fl_Spinner*, void*) {
95   if (print_copies->value() == 1) {
96     print_collate_button->deactivate();
97     print_collate_group[0]->deactivate();
98     print_collate_group[1]->deactivate();
99   } else {
100 /*    print_collate_button->activate(); // TODO: manage collate options
101     print_collate_group[0]->activate();
102     print_collate_group[1]->activate(); */
103   };
104 }
105 
cb_print_collate_button(Fl_Check_Button *,void *)106 static void cb_print_collate_button(Fl_Check_Button*, void*) {
107   int i = print_collate_button->value() != 0;
108   print_collate_group[i]->show();
109   print_collate_group[1 - i]->hide();
110 }
111 
cb_Cancel(Fl_Button *,void *)112 static void cb_Cancel(Fl_Button*, void*) {
113   print_start = 0;
114   print_panel->hide();
115 }
116 
cb_print_properties_panel(Fl_Double_Window *,void *)117 static void cb_print_properties_panel(Fl_Double_Window*, void*) {
118   print_properties_panel->hide();
119   print_update_status();
120 }
121 
122 static Fl_Menu_Item menu_print_page_size[] = {
123  {"Letter", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
124  {"A4", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
125  {0,0,0,0,0,0,0,0,0}
126 };
127 
128 #include <FL/Fl_Pixmap.H>
129 static const char *idata_print_color[] = {
130 "24 24 17 1",
131 " \tc None",
132 ".\tc #FFFF00",
133 "+\tc #C8FF00",
134 "@\tc #00FF00",
135 "#\tc #FFC800",
136 "$\tc #FF0000",
137 "%\tc #00FFFF",
138 "&\tc #000000",
139 "*\tc #FF00FF",
140 "=\tc #00FFC8",
141 "-\tc #FF00C8",
142 ";\tc #00C800",
143 ">\tc #C80000",
144 ",\tc #0000C8",
145 "\'\tc #0000FF",
146 ")\tc #00C8FF",
147 "!\tc #C800FF",
148 "         ......         ",
149 "       ..........       ",
150 "      ............      ",
151 "     ..............     ",
152 "     ..............     ",
153 "    ................    ",
154 "    ................    ",
155 "    ................    ",
156 "    +@@@@@@+#$$$$$$#    ",
157 "   %@@@@@@@&&$$$$$$$*   ",
158 "  %%@@@@@@&&&&$$$$$$**  ",
159 " %%%=@@@@&&&&&&$$$$-*** ",
160 " %%%%@@@;&&&&&&>$$$**** ",
161 "%%%%%%@@&&&&&&&&$$******",
162 "%%%%%%%@&&&&&&&&$*******",
163 "%%%%%%%%,&&&&&&,********",
164 "%%%%%%%%\'\'\'\'\'\'\'\'********",
165 "%%%%%%%%\'\'\'\'\'\'\'\'********",
166 "%%%%%%%%\'\'\'\'\'\'\'\'********",
167 " %%%%%%%)\'\'\'\'\'\'!******* ",
168 " %%%%%%%%\'\'\'\'\'\'******** ",
169 "  %%%%%%%%\'\'\'\'********  ",
170 "   %%%%%%%%\'\'********   ",
171 "     %%%%%%  ******     "
172 };
173 static Fl_Pixmap image_print_color(idata_print_color);
174 
175 static const char *idata_print_gray[] = {
176 "24 24 17 1",
177 " \tc None",
178 ".\tc #E3E3E3",
179 "+\tc #D2D2D2",
180 "@\tc #969696",
181 "#\tc #C2C2C2",
182 "$\tc #4C4C4C",
183 "%\tc #B2B2B2",
184 "&\tc #000000",
185 "*\tc #696969",
186 "=\tc #ACACAC",
187 "-\tc #626262",
188 ";\tc #767676",
189 ">\tc #3C3C3C",
190 ",\tc #161616",
191 "\'\tc #1C1C1C",
192 ")\tc #929292",
193 "!\tc #585858",
194 "         ......         ",
195 "       ..........       ",
196 "      ............      ",
197 "     ..............     ",
198 "     ..............     ",
199 "    ................    ",
200 "    ................    ",
201 "    ................    ",
202 "    +@@@@@@+#$$$$$$#    ",
203 "   %@@@@@@@&&$$$$$$$*   ",
204 "  %%@@@@@@&&&&$$$$$$**  ",
205 " %%%=@@@@&&&&&&$$$$-*** ",
206 " %%%%@@@;&&&&&&>$$$**** ",
207 "%%%%%%@@&&&&&&&&$$******",
208 "%%%%%%%@&&&&&&&&$*******",
209 "%%%%%%%%,&&&&&&,********",
210 "%%%%%%%%\'\'\'\'\'\'\'\'********",
211 "%%%%%%%%\'\'\'\'\'\'\'\'********",
212 "%%%%%%%%\'\'\'\'\'\'\'\'********",
213 " %%%%%%%)\'\'\'\'\'\'!******* ",
214 " %%%%%%%%\'\'\'\'\'\'******** ",
215 "  %%%%%%%%\'\'\'\'********  ",
216 "   %%%%%%%%\'\'********   ",
217 "     %%%%%%  ******     "
218 };
219 static Fl_Pixmap image_print_gray(idata_print_gray);
220 
221 static Fl_Button *print_output_mode[4]={(Fl_Button *)0};
222 
cb_Save(Fl_Return_Button *,void *)223 static void cb_Save(Fl_Return_Button*, void*) {
224   print_properties_panel->hide();
225 
226   char name[1024];
227   int val;
228   const char *printer = (const char *)print_choice->menu()[print_choice->value()].user_data();
229 
230   snprintf(name, sizeof(name), "%s/page_size", printer);
231   print_prefs.set(name, print_page_size->value());
232 
233   snprintf(name, sizeof(name), "%s/output_mode", printer);
234   for (val = 0; val < 4; val ++) {
235     if (print_output_mode[val]->value()) break;
236   }
237   print_prefs.set(name, val);
238 }
239 
cb_Cancel1(Fl_Button *,void *)240 static void cb_Cancel1(Fl_Button*, void*) {
241   print_properties_panel->hide();
242   print_update_status();
243 }
244 
cb_Use(Fl_Button *,void *)245 static void cb_Use(Fl_Button*, void*) {
246   print_properties_panel->hide();
247 }
248 
make_print_panel()249 Fl_Double_Window* make_print_panel() {
250   { print_panel = new Fl_Double_Window(465, 235, Fl_Printer::dialog_title);
251     { print_panel_controls = new Fl_Group(10, 10, 447, 216);
252       { print_choice = new Fl_Choice(133, 10, 181, 25, Fl_Printer::dialog_printer);
253         print_choice->down_box(FL_BORDER_BOX);
254         print_choice->labelfont(1);
255         print_choice->callback((Fl_Callback*)cb_print_choice);
256         print_choice->when(FL_WHEN_CHANGED);
257       } // Fl_Choice* print_choice
258       { print_properties = new Fl_Button(314, 10, 115, 25, Fl_Printer::dialog_properties);
259         print_properties->callback((Fl_Callback*)cb_print_properties);
260       } // Fl_Button* print_properties
261       { print_status = new Fl_Box(0, 41, print_panel_controls->w(), 17, "printer/job status");
262         print_status->align(Fl_Align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE|FL_ALIGN_LEFT));
263       } // Fl_Box* print_status
264       { Fl_Group* o = new Fl_Group(10, 86, 227, 105, Fl_Printer::dialog_range);
265         o->box(FL_THIN_DOWN_BOX);
266         o->labelfont(1);
267         o->align(Fl_Align(FL_ALIGN_TOP_LEFT));
268         { print_all = new Fl_Round_Button(20, 96, 38, 25, Fl_Printer::dialog_all);
269           print_all->type(102);
270           print_all->down_box(FL_ROUND_DOWN_BOX);
271           print_all->value(1);
272           print_all->callback((Fl_Callback*)cb_print_all);
273         } // Fl_Round_Button* print_all
274         { print_pages = new Fl_Round_Button(20, 126, 64, 25, Fl_Printer::dialog_pages);
275           print_pages->type(102);
276           print_pages->down_box(FL_ROUND_DOWN_BOX);
277           print_pages->callback((Fl_Callback*)cb_print_pages);
278         } // Fl_Round_Button* print_pages
279         { print_selection = new Fl_Round_Button(20, 156, 82, 25, "Selection");
280           print_selection->type(102);
281           print_selection->down_box(FL_ROUND_DOWN_BOX);
282           print_selection->callback((Fl_Callback*)cb_print_selection);
283         } // Fl_Round_Button* print_selection
284         { print_from = new Fl_Int_Input(136, 126, 28, 25, Fl_Printer::dialog_from);
285           print_from->type(2);
286           print_from->textfont(4);
287           print_from->deactivate();
288         } // Fl_Int_Input* print_from
289         { print_to = new Fl_Int_Input(199, 126, 28, 25, Fl_Printer::dialog_to);
290           print_to->type(2);
291           print_to->textfont(4);
292           print_to->deactivate();
293         } // Fl_Int_Input* print_to
294         o->end();
295       } // Fl_Group* o
296       { Fl_Group* o = new Fl_Group(247, 86, 210, 105, Fl_Printer::dialog_copies);
297         o->box(FL_THIN_DOWN_BOX);
298         o->labelfont(1);
299         o->align(Fl_Align(FL_ALIGN_TOP_LEFT));
300         { print_copies = new Fl_Spinner(321, 96, 45, 25, Fl_Printer::dialog_copyNo);
301           print_copies->callback((Fl_Callback*)cb_print_copies);
302           print_copies->when(FL_WHEN_CHANGED);
303         } // Fl_Spinner* print_copies
304         { print_collate_button = new Fl_Check_Button(376, 96, 64, 25, "Collate");
305           print_collate_button->down_box(FL_DOWN_BOX);
306           print_collate_button->callback((Fl_Callback*)cb_print_collate_button);
307           print_collate_button->when(FL_WHEN_CHANGED);
308           print_collate_button->deactivate();
309         } // Fl_Check_Button* print_collate_button
310         { print_collate_group[0] = new Fl_Group(257, 131, 191, 50);
311           print_collate_group[0]->deactivate();
312           { Fl_Box* o = new Fl_Box(287, 141, 30, 40, "1");
313             o->box(FL_BORDER_BOX);
314             o->color(FL_BACKGROUND2_COLOR);
315             o->labelsize(11);
316             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
317             o->deactivate();
318           } // Fl_Box* o
319           { Fl_Box* o = new Fl_Box(272, 136, 30, 40, "1");
320             o->box(FL_BORDER_BOX);
321             o->color(FL_BACKGROUND2_COLOR);
322             o->labelsize(11);
323             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
324             o->deactivate();
325           } // Fl_Box* o
326           { Fl_Box* o = new Fl_Box(257, 131, 30, 40, "1");
327             o->box(FL_BORDER_BOX);
328             o->color(FL_BACKGROUND2_COLOR);
329             o->labelsize(11);
330             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
331             o->deactivate();
332           } // Fl_Box* o
333           { Fl_Box* o = new Fl_Box(352, 141, 30, 40, "2");
334             o->box(FL_BORDER_BOX);
335             o->color(FL_BACKGROUND2_COLOR);
336             o->labelsize(11);
337             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
338             o->deactivate();
339           } // Fl_Box* o
340           { Fl_Box* o = new Fl_Box(337, 136, 30, 40, "2");
341             o->box(FL_BORDER_BOX);
342             o->color(FL_BACKGROUND2_COLOR);
343             o->labelsize(11);
344             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
345             o->deactivate();
346           } // Fl_Box* o
347           { Fl_Box* o = new Fl_Box(322, 131, 30, 40, "2");
348             o->box(FL_BORDER_BOX);
349             o->color(FL_BACKGROUND2_COLOR);
350             o->labelsize(11);
351             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
352             o->deactivate();
353           } // Fl_Box* o
354           { Fl_Box* o = new Fl_Box(417, 141, 30, 40, "3");
355             o->box(FL_BORDER_BOX);
356             o->color(FL_BACKGROUND2_COLOR);
357             o->labelsize(11);
358             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
359             o->deactivate();
360           } // Fl_Box* o
361           { Fl_Box* o = new Fl_Box(402, 136, 30, 40, "3");
362             o->box(FL_BORDER_BOX);
363             o->color(FL_BACKGROUND2_COLOR);
364             o->labelsize(11);
365             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
366             o->deactivate();
367           } // Fl_Box* o
368           { Fl_Box* o = new Fl_Box(387, 131, 30, 40, "3");
369             o->box(FL_BORDER_BOX);
370             o->color(FL_BACKGROUND2_COLOR);
371             o->labelsize(11);
372             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
373             o->deactivate();
374           } // Fl_Box* o
375           print_collate_group[0]->end();
376         } // Fl_Group* print_collate_group[0]
377         { print_collate_group[1] = new Fl_Group(257, 131, 191, 50);
378           print_collate_group[1]->hide();
379           print_collate_group[1]->deactivate();
380           { Fl_Box* o = new Fl_Box(287, 141, 30, 40, "3");
381             o->box(FL_BORDER_BOX);
382             o->color(FL_BACKGROUND2_COLOR);
383             o->labelsize(11);
384             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
385           } // Fl_Box* o
386           { Fl_Box* o = new Fl_Box(272, 136, 30, 40, "2");
387             o->box(FL_BORDER_BOX);
388             o->color(FL_BACKGROUND2_COLOR);
389             o->labelsize(11);
390             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
391           } // Fl_Box* o
392           { Fl_Box* o = new Fl_Box(257, 131, 30, 40, "1");
393             o->box(FL_BORDER_BOX);
394             o->color(FL_BACKGROUND2_COLOR);
395             o->labelsize(11);
396             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
397           } // Fl_Box* o
398           { Fl_Box* o = new Fl_Box(352, 141, 30, 40, "3");
399             o->box(FL_BORDER_BOX);
400             o->color(FL_BACKGROUND2_COLOR);
401             o->labelsize(11);
402             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
403           } // Fl_Box* o
404           { Fl_Box* o = new Fl_Box(337, 136, 30, 40, "2");
405             o->box(FL_BORDER_BOX);
406             o->color(FL_BACKGROUND2_COLOR);
407             o->labelsize(11);
408             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
409           } // Fl_Box* o
410           { Fl_Box* o = new Fl_Box(322, 131, 30, 40, "1");
411             o->box(FL_BORDER_BOX);
412             o->color(FL_BACKGROUND2_COLOR);
413             o->labelsize(11);
414             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
415           } // Fl_Box* o
416           { Fl_Box* o = new Fl_Box(417, 141, 30, 40, "3");
417             o->box(FL_BORDER_BOX);
418             o->color(FL_BACKGROUND2_COLOR);
419             o->labelsize(11);
420             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
421           } // Fl_Box* o
422           { Fl_Box* o = new Fl_Box(402, 136, 30, 40, "2");
423             o->box(FL_BORDER_BOX);
424             o->color(FL_BACKGROUND2_COLOR);
425             o->labelsize(11);
426             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
427           } // Fl_Box* o
428           { Fl_Box* o = new Fl_Box(387, 131, 30, 40, "1");
429             o->box(FL_BORDER_BOX);
430             o->color(FL_BACKGROUND2_COLOR);
431             o->labelsize(11);
432             o->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE));
433           } // Fl_Box* o
434           print_collate_group[1]->end();
435         } // Fl_Group* print_collate_group[1]
436         o->end();
437       } // Fl_Group* o
438       { Fl_Return_Button* o = new Fl_Return_Button(279, 201, 100, 25, Fl_Printer::dialog_print_button);
439         o->callback((Fl_Callback*)print_cb);
440       } // Fl_Return_Button* o
441       { Fl_Button* o = new Fl_Button(389, 201, 68, 25, Fl_Printer::dialog_cancel_button);
442         o->callback((Fl_Callback*)cb_Cancel);
443       } // Fl_Button* o
444       print_panel_controls->end();
445     } // Fl_Group* print_panel_controls
446     { print_progress = new Fl_Progress(10, 203, 289, 21);
447       print_progress->selection_color((Fl_Color)4);
448       print_progress->hide();
449     } // Fl_Progress* print_progress
450     print_panel->set_modal();
451     print_panel->end();
452   } // Fl_Double_Window* print_panel
453   { print_properties_panel = new Fl_Double_Window(290, 130, Fl_Printer::property_title);
454     print_properties_panel->callback((Fl_Callback*)cb_print_properties_panel);
455     { print_page_size = new Fl_Choice(150, 10, 80, 25, Fl_Printer::property_pagesize);
456       print_page_size->down_box(FL_BORDER_BOX);
457       print_page_size->labelfont(FL_HELVETICA);
458       print_page_size->menu(menu_print_page_size);
459     } // Fl_Choice* print_page_size
460     { Fl_Group* o = new Fl_Group(110, 45, 170, 40, Fl_Printer::property_mode);
461       o->labelfont(FL_HELVETICA);
462       o->align(Fl_Align(FL_ALIGN_LEFT));
463       { print_output_mode[0] = new Fl_Button(110, 45, 30, 40);
464         print_output_mode[0]->type(102);
465         print_output_mode[0]->box(FL_BORDER_BOX);
466         print_output_mode[0]->down_box(FL_BORDER_BOX);
467         print_output_mode[0]->value(1);
468         print_output_mode[0]->color(FL_BACKGROUND2_COLOR);
469         print_output_mode[0]->selection_color(FL_FOREGROUND_COLOR);
470         print_output_mode[0]->image(image_print_color);
471       } // Fl_Button* print_output_mode[0]
472       { print_output_mode[1] = new Fl_Button(150, 50, 40, 30);
473         print_output_mode[1]->type(102);
474         print_output_mode[1]->box(FL_BORDER_BOX);
475         print_output_mode[1]->down_box(FL_BORDER_BOX);
476         print_output_mode[1]->color(FL_BACKGROUND2_COLOR);
477         print_output_mode[1]->selection_color(FL_FOREGROUND_COLOR);
478         print_output_mode[1]->image(image_print_color);
479       } // Fl_Button* print_output_mode[1]
480       { print_output_mode[2] = new Fl_Button(200, 45, 30, 40);
481         print_output_mode[2]->type(102);
482         print_output_mode[2]->box(FL_BORDER_BOX);
483         print_output_mode[2]->down_box(FL_BORDER_BOX);
484         print_output_mode[2]->color(FL_BACKGROUND2_COLOR);
485         print_output_mode[2]->selection_color(FL_FOREGROUND_COLOR);
486         print_output_mode[2]->image(image_print_gray);
487       } // Fl_Button* print_output_mode[2]
488       { print_output_mode[3] = new Fl_Button(240, 50, 40, 30);
489         print_output_mode[3]->type(102);
490         print_output_mode[3]->box(FL_BORDER_BOX);
491         print_output_mode[3]->down_box(FL_BORDER_BOX);
492         print_output_mode[3]->color(FL_BACKGROUND2_COLOR);
493         print_output_mode[3]->selection_color(FL_FOREGROUND_COLOR);
494         print_output_mode[3]->image(image_print_gray);
495       } // Fl_Button* print_output_mode[3]
496       o->end();
497     } // Fl_Group* o
498     { Fl_Return_Button* o = new Fl_Return_Button(93, 95, 99, 25, Fl_Printer::property_save);
499       o->callback((Fl_Callback*)cb_Save);
500     } // Fl_Return_Button* o
501     { Fl_Button* o = new Fl_Button(202, 95, 78, 25, Fl_Printer::property_cancel);
502       o->callback((Fl_Callback*)cb_Cancel1);
503     } // Fl_Button* o
504     { Fl_Button* o = new Fl_Button(10, 95, 73, 25, Fl_Printer::property_use);
505       o->callback((Fl_Callback*)cb_Use);
506     } // Fl_Button* o
507     print_properties_panel->set_modal();
508     print_properties_panel->end();
509   } // Fl_Double_Window* print_properties_panel
510   return print_properties_panel;
511 }
512 
print_cb(Fl_Return_Button *,void *)513 void print_cb(Fl_Return_Button *, void *) {
514   print_start = 1;
515   print_panel->hide();
516 }
517 
print_load()518 void print_load() {
519   FILE *lpstat;
520   char line[1024], name[1024], *nptr, qname[2048], *qptr, defname[1024];
521   int i;
522 
523   if (print_choice->size() > 1) {
524     for (i = 1; print_choice->text(i); i ++) {
525       free(print_choice->menu()[i].user_data());
526     }
527   }
528 
529   print_choice->clear();
530   print_choice->add(Fl_Printer::dialog_print_to_file, 0, 0, 0, FL_MENU_DIVIDER);
531   print_choice->value(0);
532 
533   print_start = 0;
534 
535   defname[0] = '\0';
536 
537   if ((lpstat = popen("LC_MESSAGES=C LANG=C lpstat -p -d", "r")) != NULL) {
538     while (fgets(line, sizeof(line), lpstat)) {
539       if (!strncmp(line, "printer ", 8) &&
540           sscanf(line + 8, "%s", name) == 1) {
541         for (nptr = name, qptr = qname; *nptr; *qptr++ = *nptr++) {
542           if (*nptr == '/') *qptr++ = '\\';
543         }
544         *qptr = '\0';
545 
546         print_choice->add(qname, 0, 0, (void *)strdup(name), 0);
547       } else if (!strncmp(line, "system default destination: ", 28)) {
548         if (sscanf(line + 28, "%s", defname) != 1) defname[0] = '\0';
549       }
550     }
551     pclose(lpstat);
552   }
553 
554   if (defname[0]) {
555     for (i = 1; print_choice->text(i); i ++) {
556       if (!strcmp((char *)print_choice->menu()[i].user_data(), defname)) {
557         print_choice->value(i);
558         break;
559       }
560     }
561   } else if (print_choice->size() > 2) print_choice->value(1);
562 
563   print_update_status();
564 
565 } // print_load()
566 
print_update_status()567 void print_update_status() {
568   FILE *lpstat;
569   char command[1024];
570   static char status[1024];
571   const char *printer = (const char *)print_choice->menu()[print_choice->value()].user_data();
572 
573   if (print_choice->value()) {
574     snprintf(command, sizeof(command), "lpstat -p '%s'", printer);
575     if ((lpstat = popen(command, "r")) != NULL) {
576       if (fgets(status, sizeof(status), lpstat)==0) { /* ignore */ }
577       pclose(lpstat);
578     } else strcpy(status, "printer status unavailable");
579   } else status[0] = '\0';
580 
581   print_status->label(status);
582 
583   char name[1024];
584   int val;
585 
586   snprintf(name, sizeof(name), "%s/page_size", printer);
587   print_prefs.get(name, val, 1);
588   print_page_size->value(val);
589 
590   snprintf(name, sizeof(name), "%s/output_mode", printer);
591   print_prefs.get(name, val, 0);
592   print_output_mode[val]->setonly();
593 }
594 
595 //
596 // End of "$Id: print_panel.cxx 7913 2010-11-29 18:18:27Z greg.ercolano $".
597 //
598