1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Generic print dialogs
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "prntdlgg.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
30 #include "wx/stattext.h"
31 #include "wx/statbox.h"
32 #include "wx/button.h"
33 #include "wx/checkbox.h"
34 #include "wx/textctrl.h"
35 #include "wx/radiobox.h"
36 #include "wx/filedlg.h"
37 #include "wx/choice.h"
41 #include "wx/generic/prntdlgg.h"
44 #include "wx/generic/dcpsg.h"
47 #include "wx/printdlg.h"
49 // For print paper things
50 #include "wx/prntbase.h"
57 #if !USE_SHARED_LIBRARY
58 IMPLEMENT_CLASS(wxGenericPrintDialog
, wxDialog
)
59 IMPLEMENT_CLASS(wxGenericPrintSetupDialog
, wxDialog
)
60 IMPLEMENT_CLASS(wxGenericPageSetupDialog
, wxDialog
)
62 BEGIN_EVENT_TABLE(wxGenericPrintDialog
, wxDialog
)
63 EVT_BUTTON(wxID_OK
, wxGenericPrintDialog::OnOK
)
64 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPrintDialog::OnSetup
)
65 EVT_RADIOBOX(wxPRINTID_RANGE
, wxGenericPrintDialog::OnRange
)
68 BEGIN_EVENT_TABLE(wxGenericPageSetupDialog
, wxDialog
)
69 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPageSetupDialog::OnPrinter
)
73 extern wxPrintPaperDatabase
*wxThePrintPaperDatabase
;
76 * Generic print dialog for non-Windows printing use.
80 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
, wxPrintData
* data
):
81 wxDialog(parent
, -1, _("Print"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
|wxTAB_TRAVERSAL
)
86 (void)new wxStaticBox( this, -1, _( "Printer options" ), wxPoint( 5, 5), wxSize( 300, 60 ) );
88 printToFileCheckBox
= new wxCheckBox(this, wxPRINTID_PRINTTOFILE
, _("Print to File"), wxPoint(20, 25) );
90 setupButton
= new wxButton(this, wxPRINTID_SETUP
, _("Setup..."), wxPoint(160, 25), wxSize(100, -1));
92 wxString
*choices
= new wxString
[2];
93 choices
[0] = _("All");
94 choices
[1] = _("Pages");
96 fromText
= (wxTextCtrl
*)NULL
;
98 if(printData
.GetFromPage() != 0)
100 rangeRadioBox
= new wxRadioBox(this, wxPRINTID_RANGE
, _("Print Range"),
101 wxPoint(5, 80), wxSize(-1, -1), 2, choices
, 1, wxRA_VERTICAL
);
102 rangeRadioBox
->SetSelection(1);
105 if(printData
.GetFromPage() != 0)
107 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("From:"), wxPoint(5, 135));
109 fromText
= new wxTextCtrl(this, wxPRINTID_FROM
, "", wxPoint(45, 130), wxSize(40, -1));
111 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("To:"), wxPoint(100, 135));
113 toText
= new wxTextCtrl(this, wxPRINTID_TO
, "", wxPoint(133, 130), wxSize(40, -1));
116 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Copies:"), wxPoint(200, 135));
118 noCopiesText
= new wxTextCtrl(this, wxPRINTID_COPIES
, "", wxPoint(252, 130), wxSize(40, -1));
120 wxButton
*okButton
= new wxButton(this, wxID_OK
, _("OK"), wxPoint(40, 180), wxSize(100, -1));
121 (void) new wxButton(this, wxID_CANCEL
, _("Cancel"), wxPoint(180, 180), wxSize(100, -1));
123 okButton
->SetDefault();
124 okButton
->SetFocus();
128 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
133 int wxGenericPrintDialog::ShowModal(void)
135 if ( printData
.GetSetupDialog() )
137 wxGenericPrintSetupDialog
*genericPrintSetupDialog
=
138 new wxGenericPrintSetupDialog(GetParent(), wxThePrintSetupData
);
139 int ret
= genericPrintSetupDialog
->ShowModal();
140 if ( ret
!= wxID_CANCEL
)
142 *wxThePrintSetupData
= genericPrintSetupDialog
->printData
;
144 genericPrintSetupDialog
->Close(TRUE
);
149 return wxDialog::ShowModal();
153 wxGenericPrintDialog::~wxGenericPrintDialog(void)
157 void wxGenericPrintDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
159 TransferDataFromWindow();
161 // There are some interactions between the global setup data
162 // and the standard print dialog. The global printing 'mode'
163 // is determined by whether the user checks Print to file
165 if (printData
.GetPrintToFile())
167 wxThePrintSetupData
->SetPrinterMode(PS_FILE
);
169 wxString f
= wxFileSelector(_("PostScript file"),
170 wxPathOnly(wxThePrintSetupData
->GetPrinterFile()),
171 wxFileNameFromPath(wxThePrintSetupData
->GetPrinterFile()),
172 "ps", "*.ps", 0, this);
176 wxThePrintSetupData
->SetPrinterFile(f
);
179 wxThePrintSetupData
->SetPrinterMode(PS_PRINTER
);
184 void wxGenericPrintDialog::OnRange(wxCommandEvent
& event
)
186 if (!fromText
) return;
188 if (event
.GetInt() == 0)
190 fromText
->Enable(FALSE
);
191 toText
->Enable(FALSE
);
193 else if (event
.GetInt() == 1)
195 fromText
->Enable(TRUE
);
196 toText
->Enable(TRUE
);
200 void wxGenericPrintDialog::OnSetup(wxCommandEvent
& WXUNUSED(event
))
202 wxGenericPrintSetupDialog
*genericPrintSetupDialog
=
203 new wxGenericPrintSetupDialog(this, wxThePrintSetupData
);
204 int ret
= genericPrintSetupDialog
->ShowModal();
205 if ( ret
!= wxID_CANCEL
)
207 *wxThePrintSetupData
= genericPrintSetupDialog
->printData
;
208 printData
.SetOrientation(wxThePrintSetupData
->GetPrinterOrientation());
211 genericPrintSetupDialog
->Close(TRUE
);
214 bool wxGenericPrintDialog::TransferDataToWindow(void)
218 if(printData
.GetFromPage() != 0)
220 if (printData
.GetEnablePageNumbers())
222 fromText
->Enable(TRUE
);
223 toText
->Enable(TRUE
);
225 sprintf(buf
, "%d", printData
.GetFromPage());
226 fromText
->SetValue(buf
);
227 sprintf(buf
, "%d", printData
.GetToPage());
228 toText
->SetValue(buf
);
230 if (printData
.GetAllPages())
231 rangeRadioBox
->SetSelection(0);
233 rangeRadioBox
->SetSelection(1);
237 fromText
->Enable(FALSE
);
238 toText
->Enable(FALSE
);
239 rangeRadioBox
->SetSelection(0);
240 rangeRadioBox
->wxRadioBox::Enable(1, FALSE
);
243 sprintf(buf
, "%d", printData
.GetNoCopies());
244 noCopiesText
->SetValue(buf
);
246 printToFileCheckBox
->SetValue(printData
.GetPrintToFile());
247 printToFileCheckBox
->Enable(printData
.GetEnablePrintToFile());
251 bool wxGenericPrintDialog::TransferDataFromWindow(void)
253 if(printData
.GetFromPage() != -1)
255 if (printData
.GetEnablePageNumbers())
257 printData
.SetFromPage(atoi(fromText
->GetValue()));
258 printData
.SetToPage(atoi(toText
->GetValue()));
260 if (rangeRadioBox
->GetSelection() == 0)
261 printData
.SetAllPages(TRUE
);
263 printData
.SetAllPages(FALSE
);
266 { // continuous printing
267 printData
.SetFromPage(1);
268 printData
.SetToPage(32000);
270 printData
.SetNoCopies(atoi(noCopiesText
->GetValue()));
271 printData
.SetPrintToFile(printToFileCheckBox
->GetValue());
276 wxDC
*wxGenericPrintDialog::GetPrintDC(void)
278 return new wxPostScriptDC(wxThePrintSetupData
->GetPrinterFile(), FALSE
, (wxWindow
*) NULL
);
282 * Generic print setup dialog
285 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow
*parent
, wxPrintSetupData
* data
):
286 wxDialog(parent
, -1, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
|wxTAB_TRAVERSAL
)
291 (void) new wxStaticBox(this, wxPRINTID_STATIC
, _("Paper size"), wxPoint(10, 10), wxSize(200,60) );
295 paperTypeChoice
= CreatePaperTypeChoice(&xPos
, &yPos
);
297 wxString
*choices
= new wxString
[2];
298 choices
[0] = _("Portrait");
299 choices
[1] = _("Landscape");
301 orientationRadioBox
= new wxRadioBox(this, wxPRINTID_ORIENTATION
, _("Orientation"),
302 wxPoint(10, 80), wxSize(-1, -1), 2, choices
, 1, wxRA_VERTICAL
);
303 orientationRadioBox
->SetSelection(0);
305 (void) new wxStaticBox(this, wxPRINTID_STATIC
, _("Options"), wxPoint(10, 130), wxSize(200,50) );
307 int colourXPos
= 145;
313 colourCheckBox
= new wxCheckBox(this, wxPRINTID_PRINTCOLOUR
, _("Print in colour"), wxPoint(15, colourXPos
));
316 (void) new wxStaticBox(this, wxPRINTID_STATIC
, _("Print spooling"), wxPoint(230, 10), wxSize(200,170) );
318 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Printer command:"), wxPoint(240, 30));
320 printerCommandText
= new wxTextCtrl(this, wxPRINTID_COMMAND
, "", wxPoint(260, 55), wxSize(150, -1));
322 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Printer options:"), wxPoint(240, 110));
324 printerOptionsText
= new wxTextCtrl(this, wxPRINTID_OPTIONS
, "", wxPoint(260, 135), wxSize(150, -1));
326 wxButton
*okButton
= new wxButton(this, wxID_OK
, _("OK"), wxPoint(80, 200), wxSize(100, -1));
327 (void) new wxButton(this, wxID_CANCEL
, _("Cancel"), wxPoint(270, 200), wxSize(100, -1));
329 okButton
->SetDefault();
330 okButton
->SetFocus();
339 wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog(void)
343 bool wxGenericPrintSetupDialog::TransferDataToWindow(void)
345 if (printerCommandText
&& printData
.GetPrinterCommand())
346 printerCommandText
->SetValue(printData
.GetPrinterCommand());
347 if (printerOptionsText
&& printData
.GetPrinterOptions())
348 printerOptionsText
->SetValue(printData
.GetPrinterOptions());
350 colourCheckBox
->SetValue(printData
.GetColour());
352 if (orientationRadioBox
)
354 if (printData
.GetPrinterOrientation() == PS_PORTRAIT
)
355 orientationRadioBox
->SetSelection(0);
357 orientationRadioBox
->SetSelection(1);
362 bool wxGenericPrintSetupDialog::TransferDataFromWindow(void)
364 if (printerCommandText
)
365 printData
.SetPrinterCommand(WXSTRINGCAST printerCommandText
->GetValue());
366 if (printerOptionsText
)
367 printData
.SetPrinterOptions(WXSTRINGCAST printerOptionsText
->GetValue());
369 printData
.SetColour(colourCheckBox
->GetValue());
370 if (orientationRadioBox
)
372 int sel
= orientationRadioBox
->GetSelection();
374 printData
.SetPrinterOrientation(PS_PORTRAIT
);
376 printData
.SetPrinterOrientation(PS_LANDSCAPE
);
380 wxString
val(paperTypeChoice
->GetStringSelection());
381 if (!val
.IsNull() && val
!= "")
382 printData
.SetPaperName((char *)(const char *)val
);
384 *wxThePrintSetupData
= GetPrintData();
388 wxChoice
*wxGenericPrintSetupDialog::CreatePaperTypeChoice(int *x
, int *y
)
390 if (!wxThePrintPaperDatabase
)
392 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
393 wxThePrintPaperDatabase
->CreateDatabase();
395 int n
= wxThePrintPaperDatabase
->Number();
396 wxString
*choices
= new wxString
[n
];
399 for (i
= 0; i
< n
; i
++)
401 wxPrintPaperType
*paper
= (wxPrintPaperType
*)wxThePrintPaperDatabase
->Nth(i
)->Data();
402 choices
[i
] = paper
->pageName
;
403 if (printData
.GetPaperName() && choices
[i
] == printData
.GetPaperName())
412 wxChoice
*choice
= new wxChoice(this, wxPRINTID_PAPERSIZE
, wxPoint(*x
, *y
), wxSize(width
, -1), n
,
417 choice
->SetSelection(sel
);
424 * Generic page setup dialog
427 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent
& WXUNUSED(event
))
429 // We no longer query GetPrintMode, so we can eliminate the need
430 // to call SetPrintMode.
431 // This has the limitation that we can't explicitly call the PostScript
432 // print setup dialog from the generic Page Setup dialog under Windows,
433 // but since this choice would only happen when trying to do PostScript
434 // printing under Windows (and only in 16-bit Windows which
435 // doesn't have a Windows-specific page setup dialog) it's worth it.
438 data
.SetSetupDialog(TRUE
);
439 wxPrintDialog
*printDialog
= new wxPrintDialog(this, & data
);
440 printDialog
->ShowModal();
442 printDialog
->Destroy();
445 wxGenericPageSetupDialog::wxGenericPageSetupDialog(wxWindow
*parent
, wxPageSetupData
* data
):
446 wxDialog(parent
, -1, _("Page Setup"), wxPoint(0, 0), wxSize(600, 600), wxDIALOG_MODAL
|wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
451 int buttonWidth
= 75;
452 int buttonHeight
= 25;
461 wxButton
*okButton
= new wxButton(this, wxID_OK
, _("OK"), wxPoint(5, yPos
), wxSize(buttonWidth
, buttonHeight
));
462 (void) new wxButton(this, wxID_CANCEL
, _("Cancel"), wxPoint(buttonWidth
+ 5 + spacing
, yPos
), wxSize(buttonWidth
, buttonHeight
));
464 printerButton
= new wxButton(this, wxPRINTID_SETUP
, _("Printer..."), wxPoint(buttonWidth
*2 + 5 + 2*spacing
, yPos
), wxSize(buttonWidth
, buttonHeight
));
466 if ( !pageData
.GetEnablePrinter() )
467 printerButton
->Enable(FALSE
);
469 // if (printData.GetEnableHelp())
470 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), -1, -1, buttonWidth, buttonHeight);
472 okButton
->SetDefault();
473 okButton
->SetFocus();
482 paperTypeChoice
= CreatePaperTypeChoice(&xPos
, &yPos
);
486 wxString
*choices
= new wxString
[2];
487 choices
[0] = _("Portrait");
488 choices
[1] = _("Landscape");
489 orientationRadioBox
= new wxRadioBox(this, wxPRINTID_ORIENTATION
, _("Orientation"),
490 wxPoint(xPos
, yPos
), wxSize(-1, -1), 2, choices
, 2);
491 orientationRadioBox
->SetSelection(0);
496 int staticWidth
= 110;
504 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Left margin (mm):"), wxPoint(xPos
, yPos
));
507 marginLeftText
= new wxTextCtrl(this, wxPRINTID_LEFTMARGIN
, "", wxPoint(xPos
, yPos
), wxSize(textWidth
, -1));
508 xPos
+= textWidth
+ spacing
;
510 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Right margin (mm):"), wxPoint(xPos
, yPos
));
513 marginRightText
= new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN
, "", wxPoint(xPos
, yPos
), wxSize(textWidth
, -1));
514 xPos
+= textWidth
+ spacing
;
519 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Top margin (mm):"), wxPoint(xPos
, yPos
));
522 marginTopText
= new wxTextCtrl(this, wxPRINTID_TOPMARGIN
, "", wxPoint(xPos
, yPos
), wxSize(textWidth
, -1));
523 xPos
+= textWidth
+ spacing
;
525 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Bottom margin (mm):"), wxPoint(xPos
, yPos
));
528 marginBottomText
= new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN
, "", wxPoint(xPos
, yPos
), wxSize(textWidth
, -1));
537 wxGenericPageSetupDialog::~wxGenericPageSetupDialog(void)
541 bool wxGenericPageSetupDialog::TransferDataToWindow(void)
544 marginLeftText
->SetValue(IntToString((int) pageData
.GetMarginTopLeft().x
));
546 marginTopText
->SetValue(IntToString((int) pageData
.GetMarginTopLeft().y
));
548 marginRightText
->SetValue(IntToString((int) pageData
.GetMarginBottomRight().x
));
549 if (marginBottomText
)
550 marginBottomText
->SetValue(IntToString((int) pageData
.GetMarginBottomRight().y
));
552 if (orientationRadioBox
)
554 if (pageData
.GetOrientation() == wxPORTRAIT
)
555 orientationRadioBox
->SetSelection(0);
557 orientationRadioBox
->SetSelection(1);
562 bool wxGenericPageSetupDialog::TransferDataFromWindow(void)
564 if (marginLeftText
&& marginTopText
)
565 pageData
.SetMarginTopLeft(wxPoint(atoi((const char *)marginLeftText
->GetValue()),atoi((const char *)marginTopText
->GetValue())));
566 if (marginRightText
&& marginBottomText
)
567 pageData
.SetMarginBottomRight(wxPoint(atoi((const char *)marginRightText
->GetValue()),atoi((const char *)marginBottomText
->GetValue())));
569 if (orientationRadioBox
)
571 int sel
= orientationRadioBox
->GetSelection();
575 wxThePrintSetupData
->SetPrinterOrientation(wxPORTRAIT
);
577 pageData
.SetOrientation(wxPORTRAIT
);
582 wxThePrintSetupData
->SetPrinterOrientation(wxLANDSCAPE
);
584 pageData
.SetOrientation(wxLANDSCAPE
);
589 wxString
val(paperTypeChoice
->GetStringSelection());
590 if (!val
.IsNull() && val
!= "")
592 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType((char*) (const char *)val
);
595 pageData
.SetPaperSize(wxPoint(paper
->widthMM
, paper
->heightMM
));
603 wxChoice
*wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x
, int *y
)
605 if (!wxThePrintPaperDatabase
)
607 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
608 wxThePrintPaperDatabase
->CreateDatabase();
610 int n
= wxThePrintPaperDatabase
->Number();
611 wxString
*choices
= new wxString
[n
];
614 for (i
= 0; i
< n
; i
++)
616 wxPrintPaperType
*paper
= (wxPrintPaperType
*)wxThePrintPaperDatabase
->Nth(i
)->Data();
617 choices
[i
] = paper
->pageName
;
618 if (pageData
.GetPaperSize().x
== paper
->widthMM
&& pageData
.GetPaperSize().y
== paper
->heightMM
)
622 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Paper size"), wxPoint(*x
, *y
));
625 wxChoice
*choice
= new wxChoice(this, wxPRINTID_PAPERSIZE
, wxPoint(*x
, *y
), wxSize(300, -1), n
,
630 choice
->SetSelection(sel
);