4 // FLUID print panel for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
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.
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.
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
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 // generated by Fast Light User Interface Designer (fluid) version 1.0300
30 #include "print_panel.h"
33 #include "../src/flstring.h"
34 #include <FL/Fl_Preferences.H>
35 extern Fl_Preferences fluid_prefs
;
37 Fl_Double_Window
*print_panel
=(Fl_Double_Window
*)0;
39 Fl_Group
*print_panel_controls
=(Fl_Group
*)0;
41 Fl_Choice
*print_choice
=(Fl_Choice
*)0;
43 static void cb_print_choice(Fl_Choice
*, void*) {
44 print_update_status();
47 Fl_Button
*print_properties
=(Fl_Button
*)0;
49 static void cb_print_properties(Fl_Button
*, void*) {
50 print_properties_panel
->show();
53 Fl_Box
*print_status
=(Fl_Box
*)0;
55 Fl_Round_Button
*print_all
=(Fl_Round_Button
*)0;
57 static void cb_print_all(Fl_Round_Button
*, void*) {
58 print_from
->deactivate();
59 print_to
->deactivate();
62 Fl_Round_Button
*print_pages
=(Fl_Round_Button
*)0;
64 static void cb_print_pages(Fl_Round_Button
*, void*) {
65 print_from
->activate();
69 Fl_Round_Button
*print_selection
=(Fl_Round_Button
*)0;
71 static void cb_print_selection(Fl_Round_Button
*, void*) {
72 print_from
->deactivate();
73 print_to
->deactivate();
76 Fl_Int_Input
*print_from
=(Fl_Int_Input
*)0;
78 Fl_Int_Input
*print_to
=(Fl_Int_Input
*)0;
80 Fl_Spinner
*print_copies
=(Fl_Spinner
*)0;
82 static void cb_print_copies(Fl_Spinner
*, void*) {
83 if (print_copies
->value() == 1) {
84 print_collate_button
->deactivate();
85 print_collate_group
[0]->deactivate();
86 print_collate_group
[1]->deactivate();
88 print_collate_button
->activate();
89 print_collate_group
[0]->activate();
90 print_collate_group
[1]->activate();
94 Fl_Check_Button
*print_collate_button
=(Fl_Check_Button
*)0;
96 static void cb_print_collate_button(Fl_Check_Button
*, void*) {
97 int i
= print_collate_button
->value() != 0;
98 print_collate_group
[i
]->show();
99 print_collate_group
[1 - i
]->hide();
102 Fl_Group
*print_collate_group
[2]={(Fl_Group
*)0};
104 static void cb_Cancel(Fl_Button
*, void*) {
108 Fl_Progress
*print_progress
=(Fl_Progress
*)0;
110 Fl_Double_Window
*print_properties_panel
=(Fl_Double_Window
*)0;
112 static void cb_print_properties_panel(Fl_Double_Window
*, void*) {
113 print_properties_panel
->hide();
114 print_update_status();
117 Fl_Choice
*print_page_size
=(Fl_Choice
*)0;
119 Fl_Menu_Item menu_print_page_size
[] = {
120 {"Letter", 0, 0, 0, 0, FL_NORMAL_LABEL
, 0, 14, 0},
121 {"A4", 0, 0, 0, 0, FL_NORMAL_LABEL
, 0, 14, 0},
125 #include <FL/Fl_Pixmap.H>
126 static const char *idata_print_color
[] = {
150 " ................ ",
151 " ................ ",
152 " ................ ",
153 " +@@@@@@+#$$$$$$# ",
154 " %@@@@@@@&&$$$$$$$* ",
155 " %%@@@@@@&&&&$$$$$$** ",
156 " %%%=@@@@&&&&&&$$$$-*** ",
157 " %%%%@@@;&&&&&&>$$$**** ",
158 "%%%%%%@@&&&&&&&&$$******",
159 "%%%%%%%@&&&&&&&&$*******",
160 "%%%%%%%%,&&&&&&,********",
161 "%%%%%%%%\'\'\'\'\'\'\'\'********",
162 "%%%%%%%%\'\'\'\'\'\'\'\'********",
163 "%%%%%%%%\'\'\'\'\'\'\'\'********",
164 " %%%%%%%)\'\'\'\'\'\'!******* ",
165 " %%%%%%%%\'\'\'\'\'\'******** ",
166 " %%%%%%%%\'\'\'\'******** ",
167 " %%%%%%%%\'\'******** ",
170 static Fl_Pixmap
image_print_color(idata_print_color
);
172 static const char *idata_print_gray
[] = {
196 " ................ ",
197 " ................ ",
198 " ................ ",
199 " +@@@@@@+#$$$$$$# ",
200 " %@@@@@@@&&$$$$$$$* ",
201 " %%@@@@@@&&&&$$$$$$** ",
202 " %%%=@@@@&&&&&&$$$$-*** ",
203 " %%%%@@@;&&&&&&>$$$**** ",
204 "%%%%%%@@&&&&&&&&$$******",
205 "%%%%%%%@&&&&&&&&$*******",
206 "%%%%%%%%,&&&&&&,********",
207 "%%%%%%%%\'\'\'\'\'\'\'\'********",
208 "%%%%%%%%\'\'\'\'\'\'\'\'********",
209 "%%%%%%%%\'\'\'\'\'\'\'\'********",
210 " %%%%%%%)\'\'\'\'\'\'!******* ",
211 " %%%%%%%%\'\'\'\'\'\'******** ",
212 " %%%%%%%%\'\'\'\'******** ",
213 " %%%%%%%%\'\'******** ",
216 static Fl_Pixmap
image_print_gray(idata_print_gray
);
218 Fl_Button
*print_output_mode
[4]={(Fl_Button
*)0};
220 static void cb_Save(Fl_Return_Button
*, void*) {
221 print_properties_panel
->hide();
225 const char *printer
= (const char *)print_choice
->menu()[print_choice
->value()].user_data();
227 snprintf(name
, sizeof(name
), "%s/page_size", printer
);
228 fluid_prefs
.set(name
, print_page_size
->value());
230 snprintf(name
, sizeof(name
), "%s/output_mode", printer
);
231 for (val
= 0; val
< 4; val
++) {
232 if (print_output_mode
[val
]->value()) break;
234 fluid_prefs
.set(name
, val
);
237 static void cb_Cancel1(Fl_Button
*, void*) {
238 print_properties_panel
->hide();
239 print_update_status();
242 static void cb_Use(Fl_Button
*, void*) {
243 print_properties_panel
->hide();
246 Fl_Double_Window
* make_print_panel() {
247 { print_panel
= new Fl_Double_Window(465, 235, "Print");
248 { print_panel_controls
= new Fl_Group(10, 10, 447, 216);
249 { print_choice
= new Fl_Choice(113, 10, 181, 25, "Printer:");
250 print_choice
->down_box(FL_BORDER_BOX
);
251 print_choice
->labelfont(1);
252 print_choice
->callback((Fl_Callback
*)cb_print_choice
);
253 print_choice
->when(FL_WHEN_CHANGED
);
254 } // Fl_Choice* print_choice
255 { print_properties
= new Fl_Button(294, 10, 105, 25, "Properties...");
256 print_properties
->callback((Fl_Callback
*)cb_print_properties
);
257 } // Fl_Button* print_properties
258 { print_status
= new Fl_Box(111, 41, 288, 17, "printer/job status");
259 print_status
->align(Fl_Align(68|FL_ALIGN_INSIDE
));
260 } // Fl_Box* print_status
261 { Fl_Group
* o
= new Fl_Group(10, 86, 227, 105, "Print Range");
262 o
->box(FL_THIN_DOWN_BOX
);
264 o
->align(Fl_Align(FL_ALIGN_TOP_LEFT
));
265 { print_all
= new Fl_Round_Button(20, 96, 38, 25, "All");
266 print_all
->type(102);
267 print_all
->down_box(FL_ROUND_DOWN_BOX
);
269 print_all
->callback((Fl_Callback
*)cb_print_all
);
270 } // Fl_Round_Button* print_all
271 { print_pages
= new Fl_Round_Button(20, 126, 64, 25, "Pages");
272 print_pages
->type(102);
273 print_pages
->down_box(FL_ROUND_DOWN_BOX
);
274 print_pages
->callback((Fl_Callback
*)cb_print_pages
);
275 } // Fl_Round_Button* print_pages
276 { print_selection
= new Fl_Round_Button(20, 156, 82, 25, "Selection");
277 print_selection
->type(102);
278 print_selection
->down_box(FL_ROUND_DOWN_BOX
);
279 print_selection
->callback((Fl_Callback
*)cb_print_selection
);
280 } // Fl_Round_Button* print_selection
281 { print_from
= new Fl_Int_Input(136, 126, 28, 25, "From:");
283 print_from
->textfont(4);
284 print_from
->deactivate();
285 } // Fl_Int_Input* print_from
286 { print_to
= new Fl_Int_Input(199, 126, 28, 25, "To:");
288 print_to
->textfont(4);
289 print_to
->deactivate();
290 } // Fl_Int_Input* print_to
293 { Fl_Group
* o
= new Fl_Group(247, 86, 210, 105, "Copies");
294 o
->box(FL_THIN_DOWN_BOX
);
296 o
->align(Fl_Align(FL_ALIGN_TOP_LEFT
));
297 { print_copies
= new Fl_Spinner(321, 96, 45, 25, "# Copies:");
298 print_copies
->callback((Fl_Callback
*)cb_print_copies
);
299 print_copies
->when(FL_WHEN_CHANGED
);
300 } // Fl_Spinner* print_copies
301 { print_collate_button
= new Fl_Check_Button(376, 96, 64, 25, "Collate");
302 print_collate_button
->down_box(FL_DOWN_BOX
);
303 print_collate_button
->callback((Fl_Callback
*)cb_print_collate_button
);
304 print_collate_button
->when(FL_WHEN_CHANGED
);
305 print_collate_button
->deactivate();
306 } // Fl_Check_Button* print_collate_button
307 { print_collate_group
[0] = new Fl_Group(257, 131, 191, 50);
308 print_collate_group
[0]->deactivate();
309 { Fl_Box
* o
= new Fl_Box(287, 141, 30, 40, "1");
310 o
->box(FL_BORDER_BOX
);
311 o
->color(FL_BACKGROUND2_COLOR
);
313 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
316 { Fl_Box
* o
= new Fl_Box(272, 136, 30, 40, "1");
317 o
->box(FL_BORDER_BOX
);
318 o
->color(FL_BACKGROUND2_COLOR
);
320 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
323 { Fl_Box
* o
= new Fl_Box(257, 131, 30, 40, "1");
324 o
->box(FL_BORDER_BOX
);
325 o
->color(FL_BACKGROUND2_COLOR
);
327 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
330 { Fl_Box
* o
= new Fl_Box(352, 141, 30, 40, "2");
331 o
->box(FL_BORDER_BOX
);
332 o
->color(FL_BACKGROUND2_COLOR
);
334 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
337 { Fl_Box
* o
= new Fl_Box(337, 136, 30, 40, "2");
338 o
->box(FL_BORDER_BOX
);
339 o
->color(FL_BACKGROUND2_COLOR
);
341 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
344 { Fl_Box
* o
= new Fl_Box(322, 131, 30, 40, "2");
345 o
->box(FL_BORDER_BOX
);
346 o
->color(FL_BACKGROUND2_COLOR
);
348 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
351 { Fl_Box
* o
= new Fl_Box(417, 141, 30, 40, "3");
352 o
->box(FL_BORDER_BOX
);
353 o
->color(FL_BACKGROUND2_COLOR
);
355 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
358 { Fl_Box
* o
= new Fl_Box(402, 136, 30, 40, "3");
359 o
->box(FL_BORDER_BOX
);
360 o
->color(FL_BACKGROUND2_COLOR
);
362 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
365 { Fl_Box
* o
= new Fl_Box(387, 131, 30, 40, "3");
366 o
->box(FL_BORDER_BOX
);
367 o
->color(FL_BACKGROUND2_COLOR
);
369 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
372 print_collate_group
[0]->end();
373 } // Fl_Group* print_collate_group[0]
374 { print_collate_group
[1] = new Fl_Group(257, 131, 191, 50);
375 print_collate_group
[1]->hide();
376 print_collate_group
[1]->deactivate();
377 { Fl_Box
* o
= new Fl_Box(287, 141, 30, 40, "3");
378 o
->box(FL_BORDER_BOX
);
379 o
->color(FL_BACKGROUND2_COLOR
);
381 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
383 { Fl_Box
* o
= new Fl_Box(272, 136, 30, 40, "2");
384 o
->box(FL_BORDER_BOX
);
385 o
->color(FL_BACKGROUND2_COLOR
);
387 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
389 { Fl_Box
* o
= new Fl_Box(257, 131, 30, 40, "1");
390 o
->box(FL_BORDER_BOX
);
391 o
->color(FL_BACKGROUND2_COLOR
);
393 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
395 { Fl_Box
* o
= new Fl_Box(352, 141, 30, 40, "3");
396 o
->box(FL_BORDER_BOX
);
397 o
->color(FL_BACKGROUND2_COLOR
);
399 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
401 { Fl_Box
* o
= new Fl_Box(337, 136, 30, 40, "2");
402 o
->box(FL_BORDER_BOX
);
403 o
->color(FL_BACKGROUND2_COLOR
);
405 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
407 { Fl_Box
* o
= new Fl_Box(322, 131, 30, 40, "1");
408 o
->box(FL_BORDER_BOX
);
409 o
->color(FL_BACKGROUND2_COLOR
);
411 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
413 { Fl_Box
* o
= new Fl_Box(417, 141, 30, 40, "3");
414 o
->box(FL_BORDER_BOX
);
415 o
->color(FL_BACKGROUND2_COLOR
);
417 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
419 { Fl_Box
* o
= new Fl_Box(402, 136, 30, 40, "2");
420 o
->box(FL_BORDER_BOX
);
421 o
->color(FL_BACKGROUND2_COLOR
);
423 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
425 { Fl_Box
* o
= new Fl_Box(387, 131, 30, 40, "1");
426 o
->box(FL_BORDER_BOX
);
427 o
->color(FL_BACKGROUND2_COLOR
);
429 o
->align(Fl_Align(FL_ALIGN_BOTTOM_RIGHT
|FL_ALIGN_INSIDE
));
431 print_collate_group
[1]->end();
432 } // Fl_Group* print_collate_group[1]
435 { Fl_Return_Button
* o
= new Fl_Return_Button(309, 201, 70, 25, "Print");
436 o
->callback((Fl_Callback
*)print_cb
);
437 } // Fl_Return_Button* o
438 { Fl_Button
* o
= new Fl_Button(389, 201, 68, 25, "Cancel");
439 o
->callback((Fl_Callback
*)cb_Cancel
);
441 print_panel_controls
->end();
442 } // Fl_Group* print_panel_controls
443 { print_progress
= new Fl_Progress(10, 203, 289, 21);
444 print_progress
->selection_color((Fl_Color
)4);
445 print_progress
->hide();
446 } // Fl_Progress* print_progress
447 print_panel
->set_modal();
449 } // Fl_Double_Window* print_panel
450 { print_properties_panel
= new Fl_Double_Window(290, 130, "Printer Properties");
451 print_properties_panel
->callback((Fl_Callback
*)cb_print_properties_panel
);
452 { print_page_size
= new Fl_Choice(110, 10, 80, 25, "Page Size:");
453 print_page_size
->down_box(FL_BORDER_BOX
);
454 print_page_size
->labelfont(1);
455 print_page_size
->menu(menu_print_page_size
);
456 } // Fl_Choice* print_page_size
457 { Fl_Group
* o
= new Fl_Group(110, 45, 170, 40, "Output Mode:");
459 o
->align(Fl_Align(FL_ALIGN_LEFT
));
460 { print_output_mode
[0] = new Fl_Button(110, 45, 30, 40);
461 print_output_mode
[0]->type(102);
462 print_output_mode
[0]->box(FL_BORDER_BOX
);
463 print_output_mode
[0]->down_box(FL_BORDER_BOX
);
464 print_output_mode
[0]->value(1);
465 print_output_mode
[0]->color(FL_BACKGROUND2_COLOR
);
466 print_output_mode
[0]->selection_color(FL_FOREGROUND_COLOR
);
467 print_output_mode
[0]->image(image_print_color
);
468 } // Fl_Button* print_output_mode[0]
469 { print_output_mode
[1] = new Fl_Button(150, 50, 40, 30);
470 print_output_mode
[1]->type(102);
471 print_output_mode
[1]->box(FL_BORDER_BOX
);
472 print_output_mode
[1]->down_box(FL_BORDER_BOX
);
473 print_output_mode
[1]->color(FL_BACKGROUND2_COLOR
);
474 print_output_mode
[1]->selection_color(FL_FOREGROUND_COLOR
);
475 print_output_mode
[1]->image(image_print_color
);
476 } // Fl_Button* print_output_mode[1]
477 { print_output_mode
[2] = new Fl_Button(200, 45, 30, 40);
478 print_output_mode
[2]->type(102);
479 print_output_mode
[2]->box(FL_BORDER_BOX
);
480 print_output_mode
[2]->down_box(FL_BORDER_BOX
);
481 print_output_mode
[2]->color(FL_BACKGROUND2_COLOR
);
482 print_output_mode
[2]->selection_color(FL_FOREGROUND_COLOR
);
483 print_output_mode
[2]->image(image_print_gray
);
484 } // Fl_Button* print_output_mode[2]
485 { print_output_mode
[3] = new Fl_Button(240, 50, 40, 30);
486 print_output_mode
[3]->type(102);
487 print_output_mode
[3]->box(FL_BORDER_BOX
);
488 print_output_mode
[3]->down_box(FL_BORDER_BOX
);
489 print_output_mode
[3]->color(FL_BACKGROUND2_COLOR
);
490 print_output_mode
[3]->selection_color(FL_FOREGROUND_COLOR
);
491 print_output_mode
[3]->image(image_print_gray
);
492 } // Fl_Button* print_output_mode[3]
495 { Fl_Return_Button
* o
= new Fl_Return_Button(123, 95, 79, 25, "Save");
496 o
->callback((Fl_Callback
*)cb_Save
);
497 } // Fl_Return_Button* o
498 { Fl_Button
* o
= new Fl_Button(212, 95, 68, 25, "Cancel");
499 o
->callback((Fl_Callback
*)cb_Cancel1
);
501 { Fl_Button
* o
= new Fl_Button(60, 95, 53, 25, "Use");
502 o
->callback((Fl_Callback
*)cb_Use
);
504 print_properties_panel
->set_modal();
505 print_properties_panel
->end();
506 } // Fl_Double_Window* print_properties_panel
507 return print_properties_panel
;
509 void print_cb(Fl_Return_Button
*, void *);
513 char line
[1024], name
[1024], *nptr
, qname
[2048], *qptr
, defname
[1024];
516 if (print_choice
->size() > 1) {
517 for (i
= 1; print_choice
->text(i
); i
++) {
518 free(print_choice
->menu()[i
].user_data());
522 print_choice
->clear();
523 print_choice
->add("Print To File", 0, 0, 0, FL_MENU_DIVIDER
);
524 print_choice
->value(0);
528 if ((lpstat
= popen("LC_MESSAGES=C LANG=C lpstat -p -d", "r")) != NULL
) {
529 while (fgets(line
, sizeof(line
), lpstat
)) {
530 if (!strncmp(line
, "printer ", 8) &&
531 sscanf(line
+ 8, "%s", name
) == 1) {
532 for (nptr
= name
, qptr
= qname
; *nptr
; *qptr
++ = *nptr
++) {
533 if (*nptr
== '/') *qptr
++ = '\\';
537 print_choice
->add(qname
, 0, 0, (void *)strdup(name
), 0);
538 } else if (!strncmp(line
, "system default destination: ", 28)) {
539 if (sscanf(line
+ 28, "%s", defname
) != 1) defname
[0] = '\0';
546 for (i
= 1; print_choice
->text(i
); i
++) {
547 if (!strcmp((char *)print_choice
->menu()[i
].user_data(), defname
)) {
548 print_choice
->value(i
);
552 } else if (print_choice
->size() > 2) print_choice
->value(1);
555 print_update_status();
558 void print_update_status() {
561 static char status
[1024];
562 const char *printer
= (const char *)print_choice
->menu()[print_choice
->value()].user_data();
564 if (print_choice
->value()) {
565 snprintf(command
, sizeof(command
), "lpstat -p '%s'", printer
);
566 if ((lpstat
= popen(command
, "r")) != NULL
) {
567 if (fgets(status
, sizeof(status
), lpstat
)==0) { /* ignore */ }
569 } else strcpy(status
, "printer status unavailable");
570 } else status
[0] = '\0';
572 print_status
->label(status
);
577 snprintf(name
, sizeof(name
), "%s/page_size", printer
);
578 fluid_prefs
.get(name
, val
, 0);
579 print_page_size
->value(val
);
581 snprintf(name
, sizeof(name
), "%s/output_mode", printer
);
582 fluid_prefs
.get(name
, val
, 0);
583 print_output_mode
[val
]->setonly();