1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998
|
/********************************************************************************
* *
* P r i n t J o b D i a l o g *
* *
*********************************************************************************
* Copyright (C) 1999,2022 by Jeroen van der Zijp. All Rights Reserved. *
*********************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 3 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 Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/> *
********************************************************************************/
#include "xincs.h"
#include "fxver.h"
#include "fxdefs.h"
#include "fxmath.h"
#include "FXArray.h"
#include "FXHash.h"
#include "fxascii.h"
#include "FXMutex.h"
#include "FXElement.h"
#include "FXStream.h"
#include "FXString.h"
#include "FXIO.h"
#include "FXStat.h"
#include "FXFile.h"
#include "FXSize.h"
#include "FXPoint.h"
#include "FXRectangle.h"
#include "FXObjectList.h"
#include "FXStringDictionary.h"
#include "FXSettings.h"
#include "FXRegistry.h"
#include "FXAccelTable.h"
#include "FXEvent.h"
#include "FXWindow.h"
#include "FXDCPrint.h"
#include "FXApp.h"
#include "FXGIFIcon.h"
#include "FXRecentFiles.h"
#include "FXFrame.h"
#include "FXSeparator.h"
#include "FXLabel.h"
#include "FXTextField.h"
#include "FXButton.h"
#include "FXRadioButton.h"
#include "FXPacker.h"
#include "FXHorizontalFrame.h"
#include "FXVerticalFrame.h"
#include "FXMatrix.h"
#include "FXSpinner.h"
#include "FXGroupBox.h"
#include "FXDialogBox.h"
#include "FXScrollArea.h"
#include "FXList.h"
#include "FXListBox.h"
#include "FXComboBox.h"
#include "FXMessageBox.h"
#include "FXInputDialog.h"
#include "FXFileDialog.h"
#include "FXPrintDialog.h"
#include "icons.h"
#ifdef HAVE_CUPS_H
#include <cups/cups.h>
#include <cups/ppd.h>
#endif
/*
Notes:
- Registry paper data base is of the form:
[PAPER]
0 = "[US Letter] 612 792 72 72 72 72"
1 = "[US Legal] 612 1008 72 72 72 72"
2 = "[A3] 841.88976 1190.5512 80 80 80 80"
3 = "[A4] 595.27559 841.88976 80 80 80 80"
4 = "[A5] 420.94488 595.27559 80 80 80 80"
5 = "[B4] 730 1034 60 60 60 60"
6 = "[B5] 500 710 80 80 80 80"
7 = "[B5 Japan] 517 730 80 80 80 80"
8 = "[Half Letter] 612 397 72 72 72 72"
9 = "[Executive] 523 758 72 72 72 72"
10 = "[Tabloid/Ledger] 794 1227 72 72 72 72"
11 = "[Monarch] 280 542 10 10 10 10"
12 = "[SuperB] 843 1227 80 80 80 80"
13 = "[Envelope Commercial] 298 686 5 5 5 5"
14 = "[Envelope Monarch] 280 542 5 5 5 5"
15 = "[Envelope DL] 312 625 5 5 5 5"
16 = "[Envelope C5] 460 650 5 5 5 5"
17 = "[Euro Postcard] 298 420 5 5 5 5"
The paper media are described in terms of points, i.e. 1/72 of an inch.
The description comprises name, stock width, height, and left, right, top,
bottom margins.
- Inputs print job:
Destination Printer, or file (browse to file)
Orientation
Paper size [A4(210x297mm) B5, Letter(8.5x11in), Legal, Executive, ?...
Print all pages, or range of pages [first/last]
Page collate order [first page first, last page first, even/odd]
Number of copies
Color/gray/blackwhite
Custom paper dimensions
Standard paper dimensions:
Page size Print area Top/Bottom Sides
Letter 8.5 x 11 in 8.2 x 10.6 in 0.25 in 0.25 in
A4 210 x 297 mm 200 x 287 mm 5 mm 5 mm
Legal 8.5 x 14 in 8.2 x 13.6 in 0.2 in 0.15 in
#10 Envelope 4.13 x 9.5 in 3.8 x 9.2 in 0.16 in 0.14 in
104.8 x 241.3 mm 96.5 x 233.7 mm 4.1 mm 3.6 mm
Known paper sizes:
PAPERSIZE X" Y" X cm Y cm
-----------------------------------------------------
11x17 11" 17" 27.94 43.18
a0 33.0556" 46.7778" 83.9611 118.816
a10 1.02778" 1.45833" 2.61056 3.70417
a1 23.3889" 33.0556" 59.4078 83.9611
a2 16.5278" 23.3889" 41.9806 59.4078
a3 11.6944" 16.5278" 29.7039 41.9806
a4 8.26389" 11.6944" 20.9903 29.7039
a5 5.84722" 8.26389" 14.8519 20.9903
a6 4.125" 5.84722" 10.4775 14.8519
a7 2.91667" 4.125" 7.40833 10.4775
a8 2.05556" 2.91667" 5.22111 7.40833
a9 1.45833" 2.05556" 3.70417 5.22111
archA 9" 12" 22.86 30.48
archB 12" 18" 30.48 45.72
archC 18" 24" 45.72 60.96
archD 24" 36" 60.96 91.44
archE 36" 48" 91.44 121.92
b0 39.3889" 55.6667" 100.048 141.393
b1 27.8333" 39.3889" 70.6967 100.048
b2 19.6944" 27.8333" 50.0239 70.6967
b3 13.9167" 19.6944" 35.3483 50.0239
b4 9.84722" 13.9167" 25.0119 35.3483
b5 6.95833" 9.84722" 17.6742 25.0119
flsa 8.5" 13" 21.59 33.02
flse 8.5" 13" 21.59 33.02
halfletter 5.5" 8.5" 13.97 21.59
ledger 17" 11" 43.18 27.94
legal 8.5" 14" 21.59 35.56
letter 8.5" 11" 21.59 27.94
note 7.5" 10" 19.05 25.4
Paper Keywords and paper size in points
=======================================
Letter 612x792
LetterSmall 612x792
Tabloid 792x1224
Ledger 1224x792
Legal 612x1008
Statement 396x612
Executive 540x720
A0 2384x3371
A1 1685x2384
A2 1190x1684
A3 842x1190
A4 595x842
A4Small 595x842
A5 420x595
B4 729x1032
B5 516x729
Envelope ???x???
Folio 612x936
Quarto 610x780
10x14 720x1008
*/
using namespace FX;
/*******************************************************************************/
namespace FX {
// Furnish our own version
extern FXAPI FXint __sscanf(const FXchar* string,const FXchar* format,...);
extern FXAPI FXint __snprintf(FXchar* string,FXint length,const FXchar* format,...);
// Map
FXDEFMAP(FXPrintDialog) FXPrintDialogMap[]={
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_TO_PRINTER,FXPrintDialog::onCmdToPrinter),
FXMAPFUNC(SEL_UPDATE,FXPrintDialog::ID_TO_PRINTER,FXPrintDialog::onUpdToPrinter),
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_TO_FILE,FXPrintDialog::onCmdToFile),
FXMAPFUNC(SEL_UPDATE,FXPrintDialog::ID_TO_FILE,FXPrintDialog::onUpdToFile),
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_BROWSE_FILE,FXPrintDialog::onCmdBrowse),
FXMAPFUNC(SEL_UPDATE,FXPrintDialog::ID_BROWSE_FILE,FXPrintDialog::onUpdBrowse),
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_PROPERTIES,FXPrintDialog::onCmdProps),
FXMAPFUNC(SEL_UPDATE,FXPrintDialog::ID_PROPERTIES,FXPrintDialog::onUpdProps),
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_PORTRAIT,FXPrintDialog::onCmdPortrait),
FXMAPFUNC(SEL_UPDATE,FXPrintDialog::ID_PORTRAIT,FXPrintDialog::onUpdPortrait),
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_LANDSCAPE,FXPrintDialog::onCmdLandscape),
FXMAPFUNC(SEL_UPDATE,FXPrintDialog::ID_LANDSCAPE,FXPrintDialog::onUpdLandscape),
FXMAPFUNCS(SEL_COMMAND,FXPrintDialog::ID_PAGES_ALL,FXPrintDialog::ID_PAGES_RANGE,FXPrintDialog::onCmdPages),
FXMAPFUNCS(SEL_UPDATE,FXPrintDialog::ID_PAGES_ALL,FXPrintDialog::ID_PAGES_RANGE,FXPrintDialog::onUpdPages),
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_COLOR_PRINTER,FXPrintDialog::onCmdColor),
FXMAPFUNC(SEL_UPDATE,FXPrintDialog::ID_COLOR_PRINTER,FXPrintDialog::onUpdColor),
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_GRAY_PRINTER,FXPrintDialog::onCmdGray),
FXMAPFUNC(SEL_UPDATE,FXPrintDialog::ID_GRAY_PRINTER,FXPrintDialog::onUpdGray),
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_NUM_COPIES,FXPrintDialog::onCmdNumCopies),
FXMAPFUNC(SEL_UPDATE,FXPrintDialog::ID_NUM_COPIES,FXPrintDialog::onUpdNumCopies),
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_PAGES_FIRST,FXPrintDialog::onCmdFirstPage),
FXMAPFUNC(SEL_UPDATE,FXPrintDialog::ID_PAGES_FIRST,FXPrintDialog::onUpdFirstPage),
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_PAGES_LAST,FXPrintDialog::onCmdLastPage),
FXMAPFUNC(SEL_UPDATE,FXPrintDialog::ID_PAGES_LAST,FXPrintDialog::onUpdLastPage),
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_COLLATE_NORMAL,FXPrintDialog::onCmdCollateNormal),
FXMAPFUNC(SEL_UPDATE,FXPrintDialog::ID_COLLATE_NORMAL,FXPrintDialog::onUpdCollateNormal),
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_COLLATE_REVERSED,FXPrintDialog::onCmdCollateReversed),
FXMAPFUNC(SEL_UPDATE,FXPrintDialog::ID_COLLATE_REVERSED,FXPrintDialog::onUpdCollateReversed),
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_MEDIA,FXPrintDialog::onCmdMedia),
FXMAPFUNC(SEL_UPDATE,FXPrintDialog::ID_MEDIA,FXPrintDialog::onUpdMedia),
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_PRINTER_NAME,FXPrintDialog::onCmdPrinterName),
FXMAPFUNC(SEL_UPDATE,FXPrintDialog::ID_PRINTER_NAME,FXPrintDialog::onUpdPrinterName),
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_FILE_NAME,FXPrintDialog::onCmdFileName),
FXMAPFUNC(SEL_UPDATE,FXPrintDialog::ID_FILE_NAME,FXPrintDialog::onUpdFileName),
FXMAPFUNC(SEL_COMMAND,FXPrintDialog::ID_ACCEPT,FXPrintDialog::onCmdAccept),
};
// Object implementation
FXIMPLEMENT(FXPrintDialog,FXDialogBox,FXPrintDialogMap,ARRAYNUMBER(FXPrintDialogMap))
// Separator item
FXPrintDialog::FXPrintDialog(FXWindow* own,const FXString& caption,FXuint opts,FXint x,FXint y,FXint w,FXint h):FXDialogBox(own,caption,opts|DECOR_TITLE|DECOR_BORDER|DECOR_RESIZE,x,y,w,h,0,0,0,0,4,4){
FXchar key[20],name[100];
//const FXchar *paper;
FXVerticalFrame *contents=new FXVerticalFrame(this,LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0,10,10,10,10, 10,10);
// Close and cancel buttons
FXHorizontalFrame* buttons=new FXHorizontalFrame(contents,LAYOUT_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDTH,0,0,0,0,0,0,0,0);
new FXButton(buttons,tr("&Print"),nullptr,this,ID_ACCEPT,BUTTON_INITIAL|BUTTON_DEFAULT|FRAME_RAISED|FRAME_THICK|LAYOUT_CENTER_Y|LAYOUT_RIGHT,0,0,0,0,20,20);
new FXButton(buttons,tr("&Cancel"),nullptr,this,ID_CANCEL,BUTTON_DEFAULT|FRAME_RAISED|FRAME_THICK|LAYOUT_CENTER_Y|LAYOUT_RIGHT,0,0,0,0,20,20);
#ifdef HAVE_CUPS_H
FXLabel *label=new FXLabel(buttons,tr("Using CUPS"),nullptr,LAYOUT_CENTER_Y|LAYOUT_LEFT,0,0,0,0,0,0);
label->setTextColor(label->getShadowColor());
#endif
// Print destination
FXGroupBox *dest=new FXGroupBox(contents,tr("Print Destination"),GROUPBOX_TITLE_LEFT|FRAME_RIDGE|LAYOUT_FILL_X|LAYOUT_TOP|LAYOUT_FILL_Y,0,0,0,0, 10,10,5,5, 10,5);
sendtoprinter=new FXRadioButton(dest,tr("Pr&inter:"),this,ID_TO_PRINTER,LAYOUT_SIDE_TOP|ICON_BEFORE_TEXT);
FXHorizontalFrame* printdest=new FXHorizontalFrame(dest,LAYOUT_SIDE_TOP|LAYOUT_FILL_X,0,0,0,0, 0,0,0,0, 10,10);
printername=new FXComboBox(printdest,25,this,ID_PRINTER_NAME,COMBOBOX_NORMAL|FRAME_SUNKEN|FRAME_THICK|LAYOUT_CENTER_Y|LAYOUT_FILL_X);
printername->setNumVisible(4);
new FXButton(printdest,tr("Properties..."),nullptr,this,ID_PROPERTIES,FRAME_RAISED|FRAME_THICK|LAYOUT_CENTER_Y|LAYOUT_RIGHT|LAYOUT_FIX_WIDTH,0,0,100,0, 10,10);
new FXFrame(dest,LAYOUT_SIDE_TOP|LAYOUT_FIX_HEIGHT,0,0,0,10);
sendtofile=new FXRadioButton(dest,tr("&File:"),this,ID_TO_FILE,LAYOUT_SIDE_TOP|ICON_BEFORE_TEXT);
FXHorizontalFrame* filedest=new FXHorizontalFrame(dest,LAYOUT_SIDE_TOP|LAYOUT_FILL_X,0,0,0,0, 0,0,0,0, 10,10);
filename=new FXTextField(filedest,25,this,ID_FILE_NAME,FRAME_THICK|FRAME_SUNKEN|LAYOUT_CENTER_Y|LAYOUT_FILL_X);
new FXButton(filedest,tr("&Browse..."),nullptr,this,ID_BROWSE_FILE,FRAME_RAISED|FRAME_THICK|LAYOUT_CENTER_Y|LAYOUT_RIGHT|LAYOUT_FIX_WIDTH,0,0,100,0, 10,10);
FXHorizontalFrame* bottom=new FXHorizontalFrame(contents,LAYOUT_BOTTOM|LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0,0,0,0,0);
// Left
FXVerticalFrame *left=new FXVerticalFrame(bottom,LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0,0,0,0,0, 10,10);
// Pages
FXGroupBox *pages=new FXGroupBox(left,tr("Pages"),GROUPBOX_TITLE_LEFT|FRAME_RIDGE|LAYOUT_FILL_X|LAYOUT_TOP|LAYOUT_FILL_Y,0,0,0,0, 10,10,5,5);
printall=new FXRadioButton(pages,tr("Print &All"),this,ID_PAGES_ALL,LAYOUT_SIDE_TOP|ICON_BEFORE_TEXT);
printeven=new FXRadioButton(pages,tr("&Even Pages"),this,ID_PAGES_EVEN,LAYOUT_SIDE_TOP|ICON_BEFORE_TEXT);
printodd=new FXRadioButton(pages,tr("&Odd Pages"),this,ID_PAGES_ODD,LAYOUT_SIDE_TOP|ICON_BEFORE_TEXT);
printrange=new FXRadioButton(pages,tr("Print &Range:"),this,ID_PAGES_RANGE,LAYOUT_SIDE_TOP|ICON_BEFORE_TEXT);
FXMatrix *pagerange=new FXMatrix(pages,2,MATRIX_BY_ROWS|LAYOUT_FILL_X|LAYOUT_SIDE_TOP,0,0,0,0, 20,0,0,0);
new FXLabel(pagerange,tr("From:"),nullptr,LAYOUT_CENTER_Y|LAYOUT_RIGHT|JUSTIFY_RIGHT);
new FXLabel(pagerange,tr("To:"),nullptr,LAYOUT_CENTER_Y|LAYOUT_RIGHT|JUSTIFY_RIGHT);
firstpage=new FXSpinner(pagerange,4,this,ID_PAGES_FIRST,FRAME_THICK|FRAME_SUNKEN|LAYOUT_RIGHT);
lastpage=new FXSpinner(pagerange,4,this,ID_PAGES_LAST,FRAME_THICK|FRAME_SUNKEN|LAYOUT_RIGHT);
firstpage->setRange(1,10000000);
lastpage->setRange(1,10000000);
FXGroupBox *colors=new FXGroupBox(left,tr("Colors"),GROUPBOX_TITLE_LEFT|FRAME_RIDGE|LAYOUT_FILL_X|LAYOUT_TOP|LAYOUT_FILL_Y,0,0,0,0, 10,10,5,5);
printincolor=new FXRadioButton(colors,tr("Print in Color"),this,ID_COLOR_PRINTER,LAYOUT_SIDE_TOP|ICON_BEFORE_TEXT);
printinblacknwhite=new FXRadioButton(colors,tr("Print in Black and White"),this,ID_GRAY_PRINTER,LAYOUT_SIDE_TOP|ICON_BEFORE_TEXT);
// Right
FXVerticalFrame *right=new FXVerticalFrame(bottom,LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0,0,0,0,0, 10,10);
// Make some icons
landscapeIcon=new FXGIFIcon(getApp(),landscape);
portraitIcon=new FXGIFIcon(getApp(),portrait);
// Layout
FXGroupBox *copies=new FXGroupBox(right,tr("Copies"),GROUPBOX_TITLE_LEFT|FRAME_RIDGE|LAYOUT_FILL_X|LAYOUT_TOP|LAYOUT_FILL_Y,0,0,0,0, 10,10,5,5);
new FXLabel(copies,tr("Number of copies to print:"),nullptr,LAYOUT_CENTER_Y|LAYOUT_RIGHT|JUSTIFY_RIGHT|LAYOUT_SIDE_LEFT);
numberofcopies=new FXSpinner(copies,4,this,ID_NUM_COPIES,FRAME_THICK|FRAME_SUNKEN|LAYOUT_CENTER_Y|LAYOUT_SIDE_LEFT);
numberofcopies->setRange(1,1000);
// Collate
FXGroupBox *collate=new FXGroupBox(right,tr("Collate Order"),GROUPBOX_TITLE_LEFT|FRAME_RIDGE|LAYOUT_FILL_X|LAYOUT_TOP|LAYOUT_FILL_Y,0,0,0,0, 10,10,5,5);
firstpagefirst=new FXRadioButton(collate,tr("First Page First"),this,ID_COLLATE_NORMAL,LAYOUT_SIDE_TOP|ICON_BEFORE_TEXT);
lastpagefirst=new FXRadioButton(collate,tr("Last Page First"),this,ID_COLLATE_REVERSED,LAYOUT_SIDE_TOP|ICON_BEFORE_TEXT);
// Layout
FXGroupBox *orientation=new FXGroupBox(right,tr("Layout"),GROUPBOX_TITLE_LEFT|FRAME_RIDGE|LAYOUT_FILL_X|LAYOUT_TOP|LAYOUT_FILL_Y,0,0,0,0, 10,10,5,5);
new FXLabel(orientation,FXString::null,portraitIcon,LAYOUT_SIDE_LEFT|LAYOUT_RIGHT|JUSTIFY_CENTER_X|JUSTIFY_CENTER_Y|LAYOUT_CENTER_Y);
orientportrait=new FXRadioButton(orientation,tr("Portrait"),this,ID_PORTRAIT,LAYOUT_SIDE_LEFT|ICON_BEFORE_TEXT|JUSTIFY_CENTER_Y|LAYOUT_CENTER_Y);
orientlanscape=new FXRadioButton(orientation,tr("Landscape"),this,ID_LANDSCAPE,LAYOUT_SIDE_RIGHT|ICON_BEFORE_TEXT|JUSTIFY_CENTER_Y);
new FXLabel(orientation,FXString::null,landscapeIcon,LAYOUT_SIDE_RIGHT|LAYOUT_RIGHT|JUSTIFY_CENTER_X|JUSTIFY_CENTER_Y|LAYOUT_CENTER_Y);
// Paper
FXGroupBox *paperdims=new FXGroupBox(right,tr("Paper Size"),GROUPBOX_TITLE_LEFT|FRAME_RIDGE|LAYOUT_FILL_X|LAYOUT_TOP|LAYOUT_FILL_Y,0,0,0,0, 10,10,5,5);
media=new FXListBox(paperdims,this,ID_MEDIA,FRAME_SUNKEN|FRAME_THICK|LISTBOX_NORMAL|LAYOUT_FILL_X|LAYOUT_SIDE_TOP);
media->setNumVisible(6);
// Fill up with some defaults
sendtoprinter->setCheck(true);
printall->setCheck(true);
firstpagefirst->setCheck(true);
printinblacknwhite->setCheck(true);
orientportrait->setCheck(true);
// Initial focus on printer name
printername->setFocus();
// Make sure we have at least a couple
if(!getApp()->reg().readStringEntry("PAPER","0",nullptr)){
getApp()->reg().writeStringEntry("PAPER","0","[US Letter] 612 792 72 72 72 72");
getApp()->reg().writeStringEntry("PAPER","1","[US Legal] 612 1008 72 72 72 72");
getApp()->reg().writeStringEntry("PAPER","2","[A4] 595.27559 841.88976 80 80 80 80");
getApp()->reg().writeStringEntry("PAPER","3","[A3] 841.88976 1190.5512 80 80 80 80");
}
// List paper sizes
for(FXint i=0; ; i++){
__snprintf(key,sizeof(key),"%d",i);
if(getApp()->reg().readFormatEntry("PAPER",key,"[%[^]]] %*f %*f %*f %*f %*f %*f",name)!=1) break;
media->appendItem(name);
}
// These things are always reset
printer.firstpage=1;
printer.lastpage=1;
printer.currentpage=1;
printer.frompage=1;
printer.topage=1;
printer.numcopies=1;
// The rest initialized from registry
printer.mediasize=1;
printer.mediawidth=612.0;
printer.mediaheight=792.0;
printer.leftmargin=72.0;
printer.rightmargin=72.0;
printer.topmargin=72.0;
printer.bottommargin=72.0;
// Get media
printer.mediasize=getApp()->reg().readIntEntry("PRINTER","media",0);
// Obtain size
__snprintf(key,sizeof(key),"%d",printer.mediasize);
// Parse size
getApp()->reg().readFormatEntry("PAPER",key,"[%[^]]] %lf %lf %lf %lf %lf %lf",name,&printer.mediawidth,&printer.mediaheight,&printer.leftmargin,&printer.rightmargin,&printer.topmargin,&printer.bottommargin);
FXTRACE((100,"Media=\"%s\" w=%g h=%g lm=%g rm=%g tm=%g bm=%g\n",name,printer.mediawidth,printer.mediaheight,printer.leftmargin,printer.rightmargin,printer.topmargin,printer.bottommargin));
// Initial flags
printer.flags=0;
// Landscape or portrait
if(getApp()->reg().readIntEntry("PRINTER","landscape",false))
printer.flags|=PRINT_LANDSCAPE;
else
printer.flags&=~PRINT_LANDSCAPE;
// Print to file or printer
if(getApp()->reg().readIntEntry("PRINTER","printtofile",false))
printer.flags|=PRINT_DEST_FILE;
else
printer.flags&=~PRINT_DEST_FILE;
// Color prints
if(getApp()->reg().readIntEntry("PRINTER","color",false))
printer.flags|=PRINT_COLOR;
else
printer.flags&=~PRINT_COLOR;
// Initial name
if(printer.flags&PRINT_DEST_FILE)
printer.name=getApp()->reg().readStringEntry("PRINTER","file","output.ps");
else
printer.name=getApp()->reg().readStringEntry("PRINTER","printer","");
}
// Build a list of printers
void FXPrintDialog::create(){
FXDialogBox::create();
#ifndef WIN32
#ifdef HAVE_CUPS_H
// Use CUPS to determine list of printers
cups_dest_t *dests;
FXint num_dests;
// Obtain list of destinations
num_dests=cupsGetDests(&dests);
// Fill list of printers
for(FXint d=0; d<num_dests; d++){
printername->appendItem(dests[d].name);
if(printer.name==dests[d].name) printername->setCurrentItem(d);
}
#else
FXchar name[1000];
FILE *pc;
FXchar buf[1000];
FXuint i;
// Open printcap file, found as per registry setting
// You may have change this setting for your particular system
pc=fopen(getApp()->reg().readStringEntry("SETTINGS","printcap","/etc/printcap"),"r");
// Cannot open the printcap file
if(!pc) return;
name[0]=0;
// Parse printcap one line at a time
while(fgets(buf,1000,pc)){
// Extra info if printcap has been generated by Printtool
if(strncmp(buf,"##PRINTTOOL3##",14)==0){
if(__sscanf(buf,"%*s %*s %*s %*s %*s %*s %s",name)!=1) name[0]=0;
continue;
}
// Blank line
if(buf[0]=='#' || Ascii::isSpace(buf[0])){
continue;
}
// Snarf printer name (we read until the ':' or the '|' which separates aliases)
for(i=0; i<ARRAYNUMBER(buf)-1 && buf[i]!=0 && buf[i]!=':' && buf[i]!='|'; i++){}
buf[i]=0;
// Append human-readable info, if any
if(name[0]){
strcat(buf," (");
strcat(buf,name);
strcat(buf,")");
}
// Add printer name
if(strlen(buf)) printername->appendItem(buf);
name[0]=0;
//if(printer.name==dests[d].name) printername->setCurrentItem(d);
}
// Close the file
fclose(pc);
#endif
#else
// What operating system are we running?
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
FXuint p;
// Determine list of printers on Windows NT
if(osvi.dwPlatformId==VER_PLATFORM_WIN32_NT){
DWORD dwBytesNeeded,dwNumPrinters;
EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS,nullptr,4,nullptr,0,&dwBytesNeeded,&dwNumPrinters);
PRINTER_INFO_4 *prtinfo=(PRINTER_INFO_4*)malloc(dwBytesNeeded);
if(prtinfo){
if(EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS,nullptr,4,(LPBYTE)prtinfo,dwBytesNeeded,&dwBytesNeeded,&dwNumPrinters)){
for(p=0; p<dwNumPrinters; p++){
printername->appendItem(prtinfo[p].pPrinterName);
if(printer.name==prtinfo[p].pPrinterName) printername->setCurrentItem(p);
}
}
free(prtinfo);
}
}
// Determine list of printers on Windows 9x
else if(osvi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS){
DWORD dwBytesNeeded,dwNumPrinters;
EnumPrinters(PRINTER_ENUM_LOCAL,nullptr,5,nullptr,0,&dwBytesNeeded,&dwNumPrinters);
PRINTER_INFO_5 *prtinfo=(PRINTER_INFO_5*)malloc(dwBytesNeeded);
if(prtinfo){
if(EnumPrinters(PRINTER_ENUM_LOCAL,nullptr,5,(LPBYTE)prtinfo,dwBytesNeeded,&dwBytesNeeded,&dwNumPrinters)){
for(p=0; p<dwNumPrinters; p++){
printername->appendItem(prtinfo[p].pPrinterName);
if(printer.name==prtinfo[p].pPrinterName) printername->setCurrentItem(p);
}
}
free(prtinfo);
}
}
#endif
}
// Send to printer
long FXPrintDialog::onCmdToPrinter(FXObject*,FXSelector,void*){
getApp()->reg().writeIntEntry("PRINTER","printtofile",false);
printer.name=printername->getText();
printer.flags&=~PRINT_DEST_FILE;
FXTRACE((100,"Print to printer: %s\n",printer.name.text()));
// #ifdef HAVE_CUPS_H
// int num_dests;
// cups_dest_t *dests;
// num_dests=cupsGetDests(&dests);
// FXTRACE((1,"num_dests=%d\n",num_dests));
// for(int i=0; i<num_dests; i++){
// FXTRACE((1,"printer name=%s instance=%s default=%d\n",dests[i].name,dests[i].instance,dests[i].is_default));
// const char* ppdfilename;
// ppdfilename=cupsGetPPD(dests[i].name);
// if(ppdfilename){
// ppd_file_t* ppd;
// ppd=ppdOpenFile(ppdfilename);
// if(ppd){
// FXTRACE((1,"got ppd\n"));
// FXTRACE((1,"ppd->jcl_begin=%d\n",ppd->jcl_begin));
// FXTRACE((1,"ppd->jcl_ps=%d\n",ppd->jcl_ps));
// FXTRACE((1,"ppd->jcl_end=%d\n",ppd->jcl_end));
// FXTRACE((1,"ppd->num_fonts=%d\n",ppd->num_fonts));
// for(int f=0; f<ppd->num_fonts; f++) FXTRACE((1,"ppd->fonts[%d]=%s\n",f,ppd->fonts[f]));
// FXTRACE((1,"ppd->manufacturer=%s\n",ppd->manufacturer));
// FXTRACE((1,"ppd->modelname=%s\n",ppd->modelname));
// FXTRACE((1,"ppd->nickname=%s\n",ppd->nickname));
// FXTRACE((1,"ppd->shortnickname=%s\n",ppd->shortnickname));
// FXTRACE((1,"ppd->ttrasterizer=%s\n",ppd->ttrasterizer));
// FXTRACE((1,"ppd->product=%s\n",ppd->product));
// FXTRACE((1,"ppd->patches=%s\n",ppd->patches));
// FXTRACE((1,"ppd->lang_version=%s\n",ppd->lang_version));
// FXTRACE((1,"ppd->lang_encoding=%s\n",ppd->lang_encoding));
// FXTRACE((1,"ppd->landscape=%d\n",ppd->landscape));
// FXTRACE((1,"ppd->language_level=%d\n",ppd->language_level));
// FXTRACE((1,"ppd->model_number=%d\n",ppd->model_number));
// FXTRACE((1,"ppd->manual_copies=%d\n",ppd->manual_copies));
// FXTRACE((1,"ppd->throughput=%d\n",ppd->throughput));
// FXTRACE((1,"ppd->variable_sizes=%d\n",ppd->variable_sizes));
// FXTRACE((1,"ppd->num_sizes=%d\n",ppd->num_sizes));
// for(int s=0; s<ppd->num_sizes; s++){
// ppd_size_t *sz=&ppd->sizes[s];
// FXTRACE((1,"sz->marked=%d\n",sz->marked));
// FXTRACE((1,"sz->name=%s\n",sz->name));
// FXTRACE((1,"sz->width=%f\n",sz->width));
// FXTRACE((1,"sz->length=%f\n",sz->length));
// FXTRACE((1,"sz->top=%f\n",sz->top));
// FXTRACE((1,"sz->bottom=%f\n",sz->bottom));
// FXTRACE((1,"sz->left=%f\n",sz->left));
// FXTRACE((1,"sz->right=%f\n",sz->right));
// }
// ppdClose(ppd);
// }
// }
// }
// const char *defdest;
// defdest=cupsGetDefault();
// FXTRACE((1,"default destination=%s\n",defdest));
// #endif
return 1;
}
// Update send to printer
long FXPrintDialog::onUpdToPrinter(FXObject* sender,FXSelector,void*){
sender->handle(this,(printer.flags&PRINT_DEST_FILE)?FXSEL(SEL_COMMAND,ID_UNCHECK):FXSEL(SEL_COMMAND,ID_CHECK),nullptr);
return 1;
}
// Send to file
long FXPrintDialog::onCmdToFile(FXObject*,FXSelector,void*){
getApp()->reg().writeIntEntry("PRINTER","printtofile",true);
printer.name=filename->getText();
printer.flags|=PRINT_DEST_FILE;
FXTRACE((100,"Print to file: %s\n",printer.name.text()));
return 1;
}
// Update send to file
long FXPrintDialog::onUpdToFile(FXObject* sender,FXSelector,void*){
sender->handle(this,(printer.flags&PRINT_DEST_FILE)?FXSEL(SEL_COMMAND,ID_CHECK):FXSEL(SEL_COMMAND,ID_UNCHECK),nullptr);
return 1;
}
// Close dialog with an accept
long FXPrintDialog::onCmdAccept(FXObject* sender,FXSelector sel,void* ptr){
if(printer.flags&PRINT_DEST_FILE){
if(FXStat::exists(printer.name)){
FXuint answer=FXMessageBox::question(this,MBOX_YES_NO_CANCEL,tr("Overwrite file?"),tr("Overwrite existing file %s?"),printer.name.text());
if(answer==MBOX_CLICKED_CANCEL) return 1;
if(answer==MBOX_CLICKED_NO){
return FXDialogBox::onCmdCancel(sender,sel,ptr);
}
}
}
return FXDialogBox::onCmdAccept(sender,sel,ptr);
}
// Browse output file
long FXPrintDialog::onCmdBrowse(FXObject*,FXSelector,void*){
FXString name=getApp()->reg().readStringEntry("PRINTER","file","output.ps");
name=FXFileDialog::getSaveFilename(this,tr("Select Output File"),name,tr("All Files (*)\nPostscript Files (*.ps,*.eps)"),0);
if(name.empty()) return 1;
getApp()->reg().writeStringEntry("PRINTER","file",name.text());
if(printer.flags&PRINT_DEST_FILE){
printer.name=name;
FXTRACE((100,"Print to file: %s\n",printer.name.text()));
}
return 1;
}
// Update browse output file
long FXPrintDialog::onUpdBrowse(FXObject* sender,FXSelector,void*){
sender->handle(this,(printer.flags&PRINT_DEST_FILE)?FXSEL(SEL_COMMAND,ID_ENABLE):FXSEL(SEL_COMMAND,ID_DISABLE),nullptr);
return 1;
}
// Printer properties panel
long FXPrintDialog::onCmdProps(FXObject*,FXSelector,void*){ // FIXME this needs a dialog to add/remove printers
#ifndef WIN32
FXString command="lpr -P%s -#%d";
if(FXInputDialog::getString(command,this,tr("Printer Command"),"Specify the printer command, for example:\n\n \"lpr -P%s -#%d\" or \"lp -d%s -n%d\"\n\nThis will print \"%d\" copies to printer \"%s\".")){
getApp()->reg().writeStringEntry("PRINTER","command",command.text());
}
#else
#endif
return 1;
}
// Update printer properties panel
long FXPrintDialog::onUpdProps(FXObject* sender,FXSelector,void*){
sender->handle(this,(printer.flags&PRINT_DEST_FILE)?FXSEL(SEL_COMMAND,ID_DISABLE):FXSEL(SEL_COMMAND,ID_ENABLE),nullptr);
return 1;
}
// File name
long FXPrintDialog::onCmdFileName(FXObject*,FXSelector,void*){
FXString name=filename->getText();
getApp()->reg().writeStringEntry("PRINTER","file",name.text());
if(printer.flags&PRINT_DEST_FILE){
printer.name=name;
FXTRACE((100,"Print to file: %s\n",printer.name.text()));
}
return 1;
}
// Update File name
long FXPrintDialog::onUpdFileName(FXObject* sender,FXSelector,void*){
FXString name;
if(printer.flags&PRINT_DEST_FILE){
name=printer.name;
sender->handle(this,FXSEL(SEL_COMMAND,ID_ENABLE),nullptr);
}
else{
name=getApp()->reg().readStringEntry("PRINTER","file","output.ps");
sender->handle(this,FXSEL(SEL_COMMAND,ID_DISABLE),nullptr);
}
sender->handle(this,FXSEL(SEL_COMMAND,ID_SETSTRINGVALUE),(void*)&name);
return 1;
}
// Printer name
long FXPrintDialog::onCmdPrinterName(FXObject*,FXSelector,void*){
FXString name=printername->getText();
getApp()->reg().writeStringEntry("PRINTER","printer",name.text());
if(!(printer.flags&PRINT_DEST_FILE)){
printer.name=name;
FXTRACE((100,"Print to printer: %s\n",printer.name.text()));
//
// // If using CUPS, we list the available media types for this printer
// #ifndef WIN32
// #ifdef HAVE_CUPS_H
// const char* ppd_file;
// ppd_file_t* ppd;
// ppd_file=cupsGetPPD(printer.name.text());
// if(!ppd_file) return 1;
// ppd=ppdOpenFile(ppd_file);
// if(!ppd) return 1;
// media->clearItems();
// FXTRACE((100,"num_sizes=%d\n",ppd->num_sizes));
// for(int s=0; s<ppd->num_sizes; s++){
// FXTRACE((100,"ppd->sizes[%d].name=%s\n",s,ppd->sizes[s].name));
// media->appendItem(ppd->sizes[s].name);
// }
// ppdClose(ppd);
// #endif
// #endif
}
return 1;
}
// Update Printer name
long FXPrintDialog::onUpdPrinterName(FXObject* sender,FXSelector,void*){
FXString name;
if(printer.flags&PRINT_DEST_FILE){
name=getApp()->reg().readStringEntry("PRINTER","printer","");
sender->handle(this,FXSEL(SEL_COMMAND,ID_DISABLE),nullptr);
}
else{
name=printer.name;
sender->handle(this,FXSEL(SEL_COMMAND,ID_ENABLE),nullptr);
}
sender->handle(this,FXSEL(SEL_COMMAND,ID_SETSTRINGVALUE),(void*)&name);
return 1;
}
// Portrait
long FXPrintDialog::onCmdPortrait(FXObject*,FXSelector,void*){
getApp()->reg().writeIntEntry("PRINTER","landscape",false);
printer.flags&=~PRINT_LANDSCAPE;
return 1;
}
// Update portrait
long FXPrintDialog::onUpdPortrait(FXObject* sender,FXSelector,void*){
sender->handle(this,(printer.flags&PRINT_LANDSCAPE)?FXSEL(SEL_COMMAND,ID_UNCHECK):FXSEL(SEL_COMMAND,ID_CHECK),nullptr);
return 1;
}
// Landscape
long FXPrintDialog::onCmdLandscape(FXObject*,FXSelector,void*){
getApp()->reg().writeIntEntry("PRINTER","landscape",true);
printer.flags|=PRINT_LANDSCAPE;
return 1;
}
// Update landscape
long FXPrintDialog::onUpdLandscape(FXObject* sender,FXSelector,void*){
sender->handle(this,(printer.flags&PRINT_LANDSCAPE)?FXSEL(SEL_COMMAND,ID_CHECK):FXSEL(SEL_COMMAND,ID_UNCHECK),nullptr);
return 1;
}
// Pages
long FXPrintDialog::onCmdPages(FXObject*,FXSelector sel,void*){
FXuint sid=FXSELID(sel);
switch(sid){
case ID_PAGES_ALL:
printer.flags&=~(PRINT_PAGES_EVEN|PRINT_PAGES_ODD|PRINT_PAGES_RANGE);
printer.frompage=printer.firstpage;
printer.topage=printer.lastpage;
break;
case ID_PAGES_EVEN:
printer.flags|=PRINT_PAGES_EVEN;
printer.flags&=~(PRINT_PAGES_ODD|PRINT_PAGES_RANGE);
printer.frompage=(printer.firstpage+1)&~1; // Get even
printer.topage=printer.lastpage&~1;
break;
case ID_PAGES_ODD:
printer.flags|=PRINT_PAGES_ODD;
printer.flags&=~(PRINT_PAGES_EVEN|PRINT_PAGES_RANGE);
printer.frompage=printer.firstpage|1; // Get odd?
printer.topage=(printer.lastpage-1)|1;
break;
case ID_PAGES_RANGE:
printer.flags|=PRINT_PAGES_RANGE;
printer.flags&=~(PRINT_PAGES_EVEN|PRINT_PAGES_ODD);
printer.frompage=printer.firstpage;
printer.topage=printer.lastpage;
break;
}
if(printer.frompage>printer.lastpage) printer.frompage=printer.lastpage;
if(printer.frompage<printer.firstpage) printer.frompage=printer.firstpage;
if(printer.topage>printer.lastpage) printer.topage=printer.lastpage;
if(printer.topage<printer.firstpage) printer.topage=printer.firstpage;
return 1;
}
// Update Pages
long FXPrintDialog::onUpdPages(FXObject* sender,FXSelector sel,void*){
FXuint ch=ID_UNCHECK;
FXuint sid=FXSELID(sel);
switch(sid){
case ID_PAGES_ALL:
if(!(printer.flags&(PRINT_PAGES_EVEN|PRINT_PAGES_ODD|PRINT_PAGES_RANGE))) ch=ID_CHECK;
break;
case ID_PAGES_EVEN:
if(printer.flags&PRINT_PAGES_EVEN) ch=ID_CHECK;
break;
case ID_PAGES_ODD:
if(printer.flags&PRINT_PAGES_ODD) ch=ID_CHECK;
break;
case ID_PAGES_RANGE:
if(printer.flags&PRINT_PAGES_RANGE) ch=ID_CHECK;
break;
}
sender->handle(this,FXSEL(SEL_COMMAND,ch),nullptr);
return 1;
}
// Color
long FXPrintDialog::onCmdColor(FXObject*,FXSelector,void*){
getApp()->reg().writeIntEntry("PRINTER","color",true);
printer.flags|=PRINT_COLOR;
return 1;
}
// Update color
long FXPrintDialog::onUpdColor(FXObject* sender,FXSelector,void*){
sender->handle(this,(printer.flags&PRINT_COLOR)?FXSEL(SEL_COMMAND,ID_CHECK):FXSEL(SEL_COMMAND,ID_UNCHECK),nullptr);
return 1;
}
// Gray
long FXPrintDialog::onCmdGray(FXObject*,FXSelector,void*){
getApp()->reg().writeIntEntry("PRINTER","color",false);
printer.flags&=~PRINT_COLOR;
return 1;
}
// Update gray
long FXPrintDialog::onUpdGray(FXObject* sender,FXSelector,void*){
sender->handle(this,(printer.flags&PRINT_COLOR)?FXSEL(SEL_COMMAND,ID_UNCHECK):FXSEL(SEL_COMMAND,ID_CHECK),nullptr);
return 1;
}
// Number of copies
long FXPrintDialog::onCmdNumCopies(FXObject* sender,FXSelector,void*){
sender->handle(this,FXSEL(SEL_COMMAND,ID_GETINTVALUE),(void*)&printer.numcopies);
return 1;
}
// Update number of copies
long FXPrintDialog::onUpdNumCopies(FXObject* sender,FXSelector,void*){
sender->handle(this,FXSEL(SEL_COMMAND,ID_SETINTVALUE),(void*)&printer.numcopies);
return 1;
}
// First page
long FXPrintDialog::onCmdFirstPage(FXObject* sender,FXSelector,void*){
FXint pg;
sender->handle(this,FXSEL(SEL_COMMAND,ID_GETINTVALUE),(void*)&pg);
FXASSERT(pg>0);
if((FXuint)pg<printer.firstpage) pg=printer.firstpage;
if((FXuint)pg>printer.lastpage) pg=printer.lastpage;
printer.frompage=pg;
return 1;
}
// Update first page
long FXPrintDialog::onUpdFirstPage(FXObject* sender,FXSelector,void*){
sender->handle(this,FXSEL(SEL_COMMAND,ID_SETINTVALUE),(void*)&printer.frompage);
sender->handle(this,(printer.flags&PRINT_PAGES_RANGE)?FXSEL(SEL_COMMAND,ID_ENABLE):FXSEL(SEL_COMMAND,ID_DISABLE),nullptr);
return 1;
}
// Last page
long FXPrintDialog::onCmdLastPage(FXObject* sender,FXSelector,void*){
FXint pg;
sender->handle(this,FXSEL(SEL_COMMAND,ID_GETINTVALUE),(void*)&pg);
FXASSERT(pg>0);
if((FXuint)pg<printer.firstpage) pg=printer.firstpage;
if((FXuint)pg>printer.lastpage) pg=printer.lastpage;
printer.topage=pg;
return 1;
}
// Update last page
long FXPrintDialog::onUpdLastPage(FXObject* sender,FXSelector,void*){
sender->handle(this,FXSEL(SEL_COMMAND,ID_SETINTVALUE),(void*)&printer.topage);
sender->handle(this,(printer.flags&PRINT_PAGES_RANGE)?FXSEL(SEL_COMMAND,ID_ENABLE):FXSEL(SEL_COMMAND,ID_DISABLE),nullptr);
return 1;
}
// Collate Normal
long FXPrintDialog::onCmdCollateNormal(FXObject*,FXSelector,void*){
printer.flags&=~PRINT_COLLATE_REVERSED;
return 1;
}
// Update Collate Normal
long FXPrintDialog::onUpdCollateNormal(FXObject* sender,FXSelector,void*){
sender->handle(this,(printer.flags&PRINT_COLLATE_REVERSED)?FXSEL(SEL_COMMAND,ID_UNCHECK):FXSEL(SEL_COMMAND,ID_CHECK),nullptr);
return 1;
}
// Collate Reversed
long FXPrintDialog::onCmdCollateReversed(FXObject*,FXSelector,void*){
printer.flags|=PRINT_COLLATE_REVERSED;
return 1;
}
// Update Collate Reversed
long FXPrintDialog::onUpdCollateReversed(FXObject* sender,FXSelector,void*){
sender->handle(this,(printer.flags&PRINT_COLLATE_REVERSED)?FXSEL(SEL_COMMAND,ID_CHECK):FXSEL(SEL_COMMAND,ID_UNCHECK),nullptr);
return 1;
}
// Standard paper dimensions
long FXPrintDialog::onCmdMedia(FXObject*,FXSelector,void*){
FXchar key[20],name[100];
printer.mediasize=media->getCurrentItem();
getApp()->reg().writeIntEntry("PRINTER","media",printer.mediasize);
__snprintf(key,sizeof(key),"%d",printer.mediasize);
getApp()->reg().readFormatEntry("PAPER",key,"[%[^]]] %lf %lf %lf %lf %lf %lf",name,&printer.mediawidth,&printer.mediaheight,&printer.leftmargin,&printer.rightmargin,&printer.topmargin,&printer.bottommargin);
FXTRACE((100,"Media=\"%s\" w=%g h=%g lm=%g rm=%g tm=%g bm=%g\n",name,printer.mediawidth,printer.mediaheight,printer.leftmargin,printer.rightmargin,printer.topmargin,printer.bottommargin));
return 1;
}
// Update Standard paper dimensions
long FXPrintDialog::onUpdMedia(FXObject*,FXSelector,void*){
if((FXint)printer.mediasize<=media->getNumItems()) media->setCurrentItem(printer.mediasize);
return 1;
}
// Set printer to print to
void FXPrintDialog::setPrinter(const FXPrinter& pr){
printer=pr;
}
// Obtain printer to print to
void FXPrintDialog::getPrinter(FXPrinter& pr){
pr=printer;
}
// Save data
void FXPrintDialog::save(FXStream& store) const {
FXDialogBox::save(store);
}
// Load data
void FXPrintDialog::load(FXStream& store){
FXDialogBox::load(store);
}
// Cleanup
FXPrintDialog::~FXPrintDialog(){
delete landscapeIcon;
delete portraitIcon;
landscapeIcon=(FXIcon*)-1L;
portraitIcon=(FXIcon*)-1L;
}
}
|