]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/cmndata.cpp
test for timegm() added
[wxWidgets.git] / src / common / cmndata.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: cmndata.cpp
3// Purpose: Common GDI data
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
21 #pragma implementation "cmndata.h"
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28 #pragma hdrstop
29#endif
30
31#ifndef WX_PRECOMP
32 #include <stdio.h>
33 #include "wx/string.h"
34 #include "wx/utils.h"
35 #include "wx/app.h"
36#endif
37
38#include "wx/gdicmn.h"
39#include "wx/cmndata.h"
40#include "wx/log.h"
41
42// For compatibility
43#if (defined(__WXMOTIF__) || defined(__WXGTK__)) && wxUSE_POSTSCRIPT
44 #define wxCOMPATIBILITY_WITH_PRINTSETUPDATA 1
45#endif
46
47#if wxUSE_PRINTING_ARCHITECTURE
48 #include "wx/paper.h"
49
50 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
51 #include "wx/generic/dcpsg.h"
52 #endif
53#endif // wxUSE_PRINTING_ARCHITECTURE
54
55#ifdef __WXMSW__
56 #include <windows.h>
57 #include "wx/msw/private.h"
58
59 #if !defined(__WIN32__)
60 #include <print.h>
61 #include <commdlg.h>
62 #endif // Win16
63
64 #ifdef __WXWINE__
65 #include <cderr.h>
66 #include <commdlg.h>
67 #endif
68
69 #if defined(__WATCOMC__) || defined(__SC__) || defined(__SALFORDC__)
70 #include <windowsx.h>
71 #include <commdlg.h>
72 #endif
73#endif // MSW
74
75#if !USE_SHARED_LIBRARY
76 #if wxUSE_PRINTING_ARCHITECTURE
77 IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
78 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject)
79 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject)
80 #endif // wxUSE_PRINTING_ARCHITECTURE
81 IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
82 IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
83#endif
84
85#ifdef __WXMAC__
86#define mm2pt 2.83464566929
87#define pt2mm 0.352777777778
88#endif
89
90// ============================================================================
91// implementation
92// ============================================================================
93
94// ----------------------------------------------------------------------------
95// wxColourData
96// ----------------------------------------------------------------------------
97
98wxColourData::wxColourData()
99{
100 int i;
101 for (i = 0; i < 16; i++)
102 custColours[i].Set(255, 255, 255);
103
104 chooseFull = FALSE;
105 dataColour.Set(0,0,0);
106}
107
108wxColourData::wxColourData(const wxColourData& data)
109{
110 (*this) = data;
111}
112
113wxColourData::~wxColourData()
114{
115}
116
117void wxColourData::SetCustomColour(int i, wxColour& colour)
118{
119 if (i > 15 || i < 0)
120 return;
121
122 custColours[i] = colour;
123}
124
125wxColour wxColourData::GetCustomColour(int i)
126{
127 if (i > 15 || i < 0)
128 return wxColour(0,0,0);
129
130 return custColours[i];
131}
132
133void wxColourData::operator=(const wxColourData& data)
134{
135 int i;
136 for (i = 0; i < 16; i++)
137 custColours[i] = data.custColours[i];
138
139 dataColour = (wxColour&)data.dataColour;
140 chooseFull = data.chooseFull;
141}
142
143// ----------------------------------------------------------------------------
144// Font data
145// ----------------------------------------------------------------------------
146
147wxFontData::wxFontData()
148{
149 // Intialize colour to black.
150 fontColour.Set(0, 0, 0);
151
152 showHelp = FALSE;
153 allowSymbols = TRUE;
154 enableEffects = TRUE;
155 minSize = 0;
156 maxSize = 0;
157
158 m_encoding = wxFONTENCODING_SYSTEM;
159}
160
161wxFontData::~wxFontData()
162{
163}
164
165#if wxUSE_PRINTING_ARCHITECTURE
166// ----------------------------------------------------------------------------
167// Print data
168// ----------------------------------------------------------------------------
169
170wxPrintData::wxPrintData()
171{
172#ifdef __WXMSW__
173 m_devMode = NULL;
174#elif defined( __WXMAC__ )
175 m_macPrintInfo = NULL ;
176#endif
177 m_printOrientation = wxPORTRAIT;
178 m_printNoCopies = 1;
179 m_printCollate = FALSE;
180
181 // New, 24/3/99
182 m_printerName = "";
183 m_colour = TRUE;
184 m_duplexMode = wxDUPLEX_SIMPLEX;
185 m_printQuality = wxPRINT_QUALITY_HIGH;
186 m_paperId = wxPAPER_A4;
187 m_paperSize = wxSize(210, 297);
188
189 // PostScript-specific data
190 m_printerCommand = "";
191 m_previewCommand = "";
192 m_printerOptions = "";
193 m_filename = "";
194 m_afmPath = "";
195 m_printerScaleX = 1.0;
196 m_printerScaleY = 1.0;
197 m_printerTranslateX = 0;
198 m_printerTranslateY = 0;
199 m_printMode = wxPRINT_MODE_FILE;
200}
201
202wxPrintData::wxPrintData(const wxPrintData& printData)
203{
204#ifdef __WXMSW__
205 m_devMode = NULL;
206#elif defined( __WXMAC__ )
207 m_macPrintInfo = NULL ;
208#endif
209 (*this) = printData;
210}
211
212wxPrintData::~wxPrintData()
213{
214#ifdef __WXMSW__
215 HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
216 if (hDevMode )
217 GlobalFree(hDevMode);
218#elif defined(__WXMAC__)
219 if ( m_macPrintInfo )
220 ::DisposeHandle( (Handle) m_macPrintInfo ) ;
221#endif
222}
223
224#if defined(__WXMSW__) // && defined(__WIN32__)
225
226#ifdef __WIN32__
227static wxString wxGetPrintDlgError()
228{
229 DWORD err = CommDlgExtendedError();
230 wxString msg = wxT("Unknown");
231 switch (err)
232 {
233 case CDERR_FINDRESFAILURE: msg = wxT("CDERR_FINDRESFAILURE"); break;
234 case CDERR_INITIALIZATION: msg = wxT("CDERR_INITIALIZATION"); break;
235 case CDERR_LOADRESFAILURE: msg = wxT("CDERR_LOADRESFAILURE"); break;
236 case CDERR_LOADSTRFAILURE: msg = wxT("CDERR_LOADSTRFAILURE"); break;
237 case CDERR_LOCKRESFAILURE: msg = wxT("CDERR_LOCKRESFAILURE"); break;
238 case CDERR_MEMALLOCFAILURE: msg = wxT("CDERR_MEMALLOCFAILURE"); break;
239 case CDERR_MEMLOCKFAILURE: msg = wxT("CDERR_MEMLOCKFAILURE"); break;
240 case CDERR_NOHINSTANCE: msg = wxT("CDERR_NOHINSTANCE"); break;
241 case CDERR_NOHOOK: msg = wxT("CDERR_NOHOOK"); break;
242 case CDERR_NOTEMPLATE: msg = wxT("CDERR_NOTEMPLATE"); break;
243 case CDERR_STRUCTSIZE: msg = wxT("CDERR_STRUCTSIZE"); break;
244 case PDERR_RETDEFFAILURE: msg = wxT("PDERR_RETDEFFAILURE"); break;
245 case PDERR_PRINTERNOTFOUND: msg = wxT("PDERR_PRINTERNOTFOUND"); break;
246 case PDERR_PARSEFAILURE: msg = wxT("PDERR_PARSEFAILURE"); break;
247 case PDERR_NODEVICES: msg = wxT("PDERR_NODEVICES"); break;
248 case PDERR_NODEFAULTPRN: msg = wxT("PDERR_NODEFAULTPRN"); break;
249 case PDERR_LOADDRVFAILURE: msg = wxT("PDERR_LOADDRVFAILURE"); break;
250 case PDERR_INITFAILURE: msg = wxT("PDERR_INITFAILURE"); break;
251 case PDERR_GETDEVMODEFAIL: msg = wxT("PDERR_GETDEVMODEFAIL"); break;
252 case PDERR_DNDMMISMATCH: msg = wxT("PDERR_DNDMMISMATCH"); break;
253 case PDERR_DEFAULTDIFFERENT: msg = wxT("PDERR_DEFAULTDIFFERENT"); break;
254 case PDERR_CREATEICFAILURE: msg = wxT("PDERR_CREATEICFAILURE"); break;
255 default: break;
256 }
257 return msg;
258}
259#endif
260
261void wxPrintData::ConvertToNative()
262{
263 HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
264 if (!hDevMode)
265 {
266 // Use PRINTDLG as a way of creating a DEVMODE object
267 PRINTDLG *pd = new PRINTDLG;
268
269 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
270#ifdef __GNUWIN32__
271 memset(pd, 0, 66);
272 pd->lStructSize = 66 ;
273#else
274 memset(pd, 0, sizeof(PRINTDLG));
275 pd->lStructSize = sizeof(PRINTDLG);
276#endif
277
278 pd->hwndOwner = (HWND)NULL;
279 pd->hDevMode = NULL; // Will be created by PrintDlg
280 pd->hDevNames = NULL; // Ditto
281 pd->hInstance = (HINSTANCE) wxGetInstance();
282
283 pd->Flags = PD_RETURNDEFAULT;
284 pd->nCopies = 1;
285
286 // Fill out the DEVMODE structure
287 // so we can use it as input in the 'real' PrintDlg
288 if (!PrintDlg(pd))
289 {
290 if ( pd->hDevMode )
291 GlobalFree(pd->hDevMode);
292 if ( pd->hDevNames )
293 GlobalFree(pd->hDevNames);
294 pd->hDevMode = NULL;
295 pd->hDevNames = NULL;
296
297#if defined(__WXDEBUG__) && defined(__WIN32__)
298 wxString str(wxT("Printing error: "));
299 str += wxGetPrintDlgError();
300 wxLogDebug(str);
301#endif
302 }
303 else
304 {
305 if ( pd->hDevNames )
306 GlobalFree(pd->hDevNames);
307 pd->hDevNames = NULL;
308
309 hDevMode = pd->hDevMode;
310 m_devMode = (void*)(long) hDevMode;
311 pd->hDevMode = NULL;
312 }
313
314 delete pd;
315 }
316
317 if ( hDevMode )
318 {
319 DEVMODE *devMode = (DEVMODE*) GlobalLock(hDevMode);
320
321 //// Orientation
322
323#ifndef __WXWINE__
324 devMode->dmOrientation = m_printOrientation;
325#endif
326 devMode->dmFields = DM_ORIENTATION;
327
328 //// Collation
329
330#ifndef __WIN16__
331 devMode->dmCollate = (m_printCollate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE);
332 devMode->dmFields |= DM_COLLATE;
333#endif
334
335 //// Number of copies
336
337 devMode->dmCopies = m_printNoCopies;
338 devMode->dmFields |= DM_COPIES;
339
340 //// Printer name
341
342 if (m_printerName != wxT(""))
343 {
344 // TODO: make this Unicode compatible
345 int len = wxMin(31, m_printerName.Len());
346 int i;
347 for (i = 0; i < len; i++)
348 devMode->dmDeviceName[i] = m_printerName.GetChar(i);
349 devMode->dmDeviceName[i] = 0;
350 }
351
352 //// Colour
353
354 if (m_colour)
355 devMode->dmColor = DMCOLOR_COLOR;
356 else
357 devMode->dmColor = DMCOLOR_MONOCHROME;
358
359 devMode->dmFields |= DM_COLOR;
360
361#ifndef __WXWINE__
362 //// Paper size
363
364 if (m_paperId == wxPAPER_NONE)
365 {
366 devMode->dmPaperWidth = m_paperSize.x * 10;
367 devMode->dmPaperLength = m_paperSize.y * 10;
368 devMode->dmFields |= DM_PAPERWIDTH;
369 devMode->dmFields |= DM_PAPERLENGTH;
370 }
371 else
372 {
373 if (wxThePrintPaperDatabase)
374 {
375 wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType(m_paperId);
376 if (paper)
377 {
378 devMode->dmPaperSize = paper->GetPlatformId();
379 devMode->dmFields |= DM_PAPERSIZE;
380 }
381 }
382 }
383#endif
384
385 //// Duplex
386
387 int duplex;
388 switch (m_duplexMode)
389 {
390 case wxDUPLEX_HORIZONTAL: {
391 duplex = DMDUP_HORIZONTAL; break;
392 }
393 case wxDUPLEX_VERTICAL: {
394 duplex = DMDUP_VERTICAL; break;
395 }
396 default:
397 case wxDUPLEX_SIMPLEX: {
398 duplex = DMDUP_SIMPLEX; break;
399 }
400 }
401 devMode->dmDuplex = duplex;
402 devMode->dmFields |= DM_DUPLEX;
403
404 //// Quality
405
406 int quality;
407 switch (m_printQuality)
408 {
409 case wxPRINT_QUALITY_MEDIUM: {
410 quality = DMRES_MEDIUM; break;
411 }
412 case wxPRINT_QUALITY_LOW: {
413 quality = DMRES_LOW; break;
414 }
415 case wxPRINT_QUALITY_DRAFT: {
416 quality = DMRES_DRAFT; break;
417 }
418 case wxPRINT_QUALITY_HIGH: {
419 quality = DMRES_HIGH; break;
420 }
421 default: {
422 quality = m_printQuality; break;
423 }
424 }
425 devMode->dmPrintQuality = quality;
426 devMode->dmFields |= DM_PRINTQUALITY;
427
428 GlobalUnlock(hDevMode);
429 }
430}
431
432void wxPrintData::ConvertFromNative()
433{
434 HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
435
436 if (!hDevMode)
437 return;
438
439 if ( hDevMode )
440 {
441 DEVMODE *devMode = (DEVMODE*) GlobalLock(hDevMode);
442
443#ifndef __WXWINE__
444 //// Orientation
445
446 if (devMode->dmFields & DM_ORIENTATION)
447 m_printOrientation = devMode->dmOrientation;
448#endif
449
450 //// Collation
451
452#ifndef __WIN16__
453 if (devMode->dmFields & DM_COLLATE)
454 {
455 if (devMode->dmCollate == DMCOLLATE_TRUE)
456 m_printCollate = TRUE;
457 else
458 m_printCollate = FALSE;
459 }
460#endif
461
462 //// Number of copies
463
464 if (devMode->dmFields & DM_COPIES)
465 {
466 m_printNoCopies = devMode->dmCopies;
467 }
468
469 //// Printer name
470
471 if (devMode->dmDeviceName[0] != 0)
472 {
473 // TODO: make this Unicode compatible
474 char buf[32];
475 int i = 0;
476 while (devMode->dmDeviceName[i] != 0)
477 {
478 buf[i] = devMode->dmDeviceName[i];
479 i ++;
480 }
481 buf[i] = 0;
482
483 m_printerName = buf;
484 }
485
486 //// Colour
487
488 if (devMode->dmFields & DM_COLOR)
489 {
490 if (devMode->dmColor == DMCOLOR_COLOR)
491 m_colour = TRUE;
492 else
493 m_colour = FALSE;
494 }
495 else
496 m_colour = TRUE;
497
498#ifndef __WXWINE__
499 //// Paper size
500
501 if (devMode->dmFields & DM_PAPERSIZE)
502 {
503 if (wxThePrintPaperDatabase)
504 {
505 wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize);
506 if (paper)
507 {
508 m_paperId = paper->GetId();
509 m_paperSize.x = paper->GetWidth() / 10 ;
510 m_paperSize.y = paper->GetHeight() / 10 ;
511 }
512 else
513 {
514 // Shouldn't really get here
515 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
516
517 m_paperId = wxPAPER_NONE;
518 m_paperSize.x = 0;
519 m_paperSize.y = 0;
520 }
521 }
522 else
523 {
524 // Shouldn't really get here
525 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
526
527 m_paperId = wxPAPER_NONE;
528 m_paperSize.x = 0;
529 m_paperSize.y = 0;
530 }
531 }
532 else if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH))
533 {
534 m_paperSize.x = devMode->dmPaperWidth / 10;
535 m_paperSize.y = devMode->dmPaperLength / 10;
536 m_paperId = wxPAPER_NONE;
537 }
538 else
539 {
540 // Shouldn't really get here
541 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
542
543 m_paperSize.x = 0;
544 m_paperSize.y = 0;
545 m_paperId = wxPAPER_NONE;
546 }
547#endif
548
549 //// Duplex
550
551 if (devMode->dmFields & DM_DUPLEX)
552 {
553 switch (devMode->dmDuplex)
554 {
555 case DMDUP_HORIZONTAL: {
556 m_duplexMode = wxDUPLEX_HORIZONTAL; break;
557 }
558 case DMDUP_VERTICAL: {
559 m_duplexMode = wxDUPLEX_VERTICAL; break;
560 }
561 default:
562 case DMDUP_SIMPLEX: {
563 m_duplexMode = wxDUPLEX_SIMPLEX; break;
564 }
565 }
566 }
567 else
568 m_duplexMode = wxDUPLEX_SIMPLEX;
569
570 //// Quality
571
572 if (devMode->dmFields & DM_PRINTQUALITY)
573 {
574 switch (devMode->dmPrintQuality)
575 {
576 case DMRES_MEDIUM: {
577 m_printQuality = wxPRINT_QUALITY_MEDIUM; break;
578 }
579 case DMRES_LOW: {
580 m_printQuality = wxPRINT_QUALITY_LOW; break;
581 }
582 case DMRES_DRAFT: {
583 m_printQuality = wxPRINT_QUALITY_DRAFT; break;
584 }
585 case DMRES_HIGH: {
586 m_printQuality = wxPRINT_QUALITY_HIGH; break;
587 }
588 default:
589 {
590 // TODO: if the printer fills in the resolution in DPI, how
591 // will the application know if it's high, low, draft etc.??
592 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
593 m_printQuality = devMode->dmPrintQuality; break;
594
595 }
596 }
597 }
598 else
599 m_printQuality = wxPRINT_QUALITY_HIGH;
600
601 GlobalUnlock(hDevMode);
602 }
603}
604
605#endif
606
607#ifdef __WXMAC__
608void wxPrintData::ConvertToNative()
609{
610 if ( !m_macPrintInfo )
611 {
612 m_macPrintInfo = (THPrint) NewHandleClear( sizeof( TPrint ) ) ;
613 if ( m_macPrintInfo )
614 {
615 ::PrintDefault( m_macPrintInfo ) ;
616 // todo setup the global pagesetup ?
617 }
618 }
619 if ( m_macPrintInfo )
620 {
621 (**m_macPrintInfo).prJob.iCopies = m_printNoCopies ;
622 (**m_macPrintInfo).prJob.iFstPage = 0 ;
623 (**m_macPrintInfo).prJob.iLstPage = 0 ;
624 }
625}
626
627void wxPrintData::ConvertFromNative()
628{
629 if ( m_macPrintInfo )
630 {
631 m_printNoCopies = (**m_macPrintInfo).prJob.iCopies ;
632 }
633}
634#endif
635
636void wxPrintData::operator=(const wxPrintData& data)
637{
638 m_printNoCopies = data.m_printNoCopies;
639 m_printCollate = data.m_printCollate;
640 m_printOrientation = data.m_printOrientation;
641 m_printerName = data.m_printerName;
642 m_colour = data.m_colour;
643 m_duplexMode = data.m_duplexMode;
644 m_printQuality = data.m_printQuality;
645 m_paperId = data.m_paperId;
646 m_paperSize = data.m_paperSize;
647
648 // PostScript-specific data
649 m_printerCommand = data.m_printerCommand;
650 m_previewCommand = data.m_previewCommand;
651 m_printerOptions = data.m_printerOptions;
652 m_filename = data.m_filename;
653 m_afmPath = data.m_afmPath;
654 m_printerScaleX = data.m_printerScaleX;
655 m_printerScaleY = data.m_printerScaleY;
656 m_printerTranslateX = data.m_printerTranslateX;
657 m_printerTranslateY = data.m_printerTranslateY;
658 m_printMode = data.m_printMode;
659}
660
661// For compatibility
662#if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
663void wxPrintData::operator=(const wxPrintSetupData& setupData)
664{
665 SetPrinterCommand(setupData.GetPrinterCommand());
666 SetPreviewCommand(setupData.GetPrintPreviewCommand());
667 SetPrinterOptions(setupData.GetPrinterOptions());
668
669 long xt, yt;
670 setupData.GetPrinterTranslation(& xt, & yt);
671 SetPrinterTranslation(xt, yt);
672
673 double xs, ys;
674 setupData.GetPrinterScaling(& xs, & ys);
675 SetPrinterScaling(xs, ys);
676
677 SetOrientation(setupData.GetPrinterOrientation());
678 SetPrintMode((wxPrintMode) setupData.GetPrinterMode());
679 SetFontMetricPath(setupData.GetAFMPath());
680 if (setupData.GetPaperName() != "")
681 SetPaperId(wxThePrintPaperDatabase->ConvertNameToId(setupData.GetPaperName()));
682 SetColour(setupData.GetColour());
683 SetFilename(setupData.GetPrinterFile());
684}
685#endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
686
687
688// ----------------------------------------------------------------------------
689// Print dialog data
690// ----------------------------------------------------------------------------
691
692wxPrintDialogData::wxPrintDialogData()
693{
694#ifdef __WXMSW__
695 m_printDlgData = NULL;
696#elif defined( __WXMAC__ )
697 m_macPrintInfo = NULL ;
698#endif
699 m_printFromPage = 0;
700 m_printToPage = 0;
701 m_printMinPage = 0;
702 m_printMaxPage = 0;
703 m_printNoCopies = 1;
704 m_printAllPages = FALSE;
705 m_printCollate = FALSE;
706 m_printToFile = FALSE;
707 m_printSelection = FALSE;
708 m_printEnableSelection = FALSE;
709 m_printEnablePageNumbers = TRUE;
710 m_printEnablePrintToFile = TRUE;
711 m_printEnableHelp = FALSE;
712 m_printSetupDialog = FALSE;
713}
714
715wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
716{
717#ifdef __WXMSW__
718 m_printDlgData = NULL;
719#elif defined( __WXMAC__ )
720 m_macPrintInfo = NULL ;
721#endif
722 (*this) = dialogData;
723}
724
725wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
726{
727#ifdef __WXMSW__
728 m_printDlgData = NULL;
729#elif defined( __WXMAC__ )
730 m_macPrintInfo = NULL ;
731#endif
732 m_printFromPage = 0;
733 m_printToPage = 0;
734 m_printMinPage = 0;
735 m_printMaxPage = 0;
736 m_printNoCopies = 1;
737 m_printAllPages = FALSE;
738 m_printCollate = FALSE;
739 m_printToFile = FALSE;
740 m_printSelection = FALSE;
741 m_printEnableSelection = FALSE;
742 m_printEnablePageNumbers = TRUE;
743 m_printEnablePrintToFile = TRUE;
744 m_printEnableHelp = FALSE;
745 m_printSetupDialog = FALSE;
746
747 m_printData = printData;
748}
749
750wxPrintDialogData::~wxPrintDialogData()
751{
752#ifdef __WXMSW__
753 PRINTDLG *pd = (PRINTDLG *) m_printDlgData;
754 if ( pd && pd->hDevMode )
755 GlobalFree(pd->hDevMode);
756 if ( pd )
757 delete pd;
758#elif defined(__WXMAC__)
759 if ( m_macPrintInfo )
760 ::DisposeHandle( (Handle) m_macPrintInfo ) ;
761#endif
762}
763
764#ifdef __WXMSW__
765void wxPrintDialogData::ConvertToNative()
766{
767 m_printData.ConvertToNative();
768
769 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
770
771 if (!pd)
772 {
773 pd = new PRINTDLG;
774 m_printDlgData = (void*) pd;
775
776 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
777#ifdef __GNUWIN32__
778 pd->lStructSize = 66 ;
779#else
780 pd->lStructSize = sizeof(PRINTDLG);
781#endif
782 pd->hwndOwner = (HWND)NULL;
783 pd->hDevMode = NULL; // Will be created by PrintDlg
784 pd->hDevNames = NULL; // Ditto
785
786 pd->Flags = PD_RETURNDEFAULT;
787 pd->nCopies = 1;
788 }
789
790 // Pass the devmode data to the PRINTDLG structure, since it'll
791 // be needed when PrintDlg is called.
792 if (pd->hDevMode)
793 {
794 GlobalFree(pd->hDevMode);
795 }
796
797 pd->hDevMode = (HGLOBAL)(DWORD) m_printData.GetNativeData();
798
799 m_printData.SetNativeData((void*) NULL);
800
801 wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
802
803 pd->hDC = (HDC) NULL;
804 pd->nFromPage = (UINT)m_printFromPage;
805 pd->nToPage = (UINT)m_printToPage;
806 pd->nMinPage = (UINT)m_printMinPage;
807 pd->nMaxPage = (UINT)m_printMaxPage;
808 pd->nCopies = (UINT)m_printNoCopies;
809
810 pd->Flags = PD_RETURNDC ;
811
812#ifdef __GNUWIN32__
813 pd->lStructSize = 66 ;
814#else
815 pd->lStructSize = sizeof( PRINTDLG );
816#endif
817
818 pd->hwndOwner=(HWND)NULL;
819 pd->hDevNames=(HANDLE)NULL;
820 pd->hInstance=(HINSTANCE)NULL;
821 pd->lCustData = (LPARAM) NULL;
822 pd->lpfnPrintHook = NULL;
823 pd->lpfnSetupHook = NULL;
824 pd->lpPrintTemplateName = NULL;
825 pd->lpSetupTemplateName = NULL;
826 pd->hPrintTemplate = (HGLOBAL) NULL;
827 pd->hSetupTemplate = (HGLOBAL) NULL;
828
829 if ( m_printAllPages )
830 pd->Flags |= PD_ALLPAGES;
831 if ( m_printAllPages )
832 pd->Flags |= PD_SELECTION;
833 if ( m_printCollate )
834 pd->Flags |= PD_COLLATE;
835 if ( m_printToFile )
836 pd->Flags |= PD_PRINTTOFILE;
837 if ( !m_printEnablePrintToFile )
838 pd->Flags |= PD_DISABLEPRINTTOFILE;
839 if ( !m_printEnableSelection )
840 pd->Flags |= PD_NOSELECTION;
841 if ( !m_printEnablePageNumbers )
842 pd->Flags |= PD_NOPAGENUMS;
843 if ( m_printEnableHelp )
844 pd->Flags |= PD_SHOWHELP;
845 if ( m_printSetupDialog )
846 pd->Flags |= PD_PRINTSETUP;
847}
848
849void wxPrintDialogData::ConvertFromNative()
850{
851 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
852 if ( pd == NULL )
853 return;
854
855 // Pass the devmode data back to the wxPrintData structure where it really belongs.
856 if (pd->hDevMode)
857 {
858 if (m_printData.GetNativeData())
859 {
860 // Make sure we don't leak memory
861 GlobalFree((HGLOBAL)(DWORD) m_printData.GetNativeData());
862 }
863 m_printData.SetNativeData((void*)(long) pd->hDevMode);
864 pd->hDevMode = NULL;
865 }
866
867 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
868 // into wxWindows form.
869 m_printData.ConvertFromNative();
870
871 m_printFromPage = pd->nFromPage ;
872 m_printToPage = pd->nToPage ;
873 m_printMinPage = pd->nMinPage ;
874 m_printMaxPage = pd->nMaxPage ;
875 m_printNoCopies = pd->nCopies ;
876
877 m_printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES);
878 m_printSelection = ((pd->Flags & PD_SELECTION) == PD_SELECTION);
879 m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE);
880 m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE);
881 m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE);
882 m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION);
883 m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS);
884 m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP);
885 m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP);
886
887/* port is obsolete in WIN32
888 // Get the port name
889 if (pd->hDevNames)
890 {
891 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
892 if (lpDevNames) {
893 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
894 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
895 GlobalUnlock(pd->hDevNames);
896
897// wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
898 }
899 }
900*/
901}
902
903void wxPrintDialogData::SetOwnerWindow(wxWindow* win)
904{
905 if ( m_printDlgData == NULL )
906 ConvertToNative();
907
908 if ( m_printDlgData != NULL && win != NULL)
909 {
910 PRINTDLG *pd = (PRINTDLG *) m_printDlgData ;
911 pd->hwndOwner=(HWND) win->GetHWND();
912 }
913}
914#endif // MSW
915
916#ifdef __WXMAC__
917void wxPrintDialogData::ConvertToNative()
918{
919 if ( !m_macPrintInfo )
920 {
921 m_macPrintInfo = (THPrint) NewHandleClear( sizeof( TPrint ) ) ;
922 if ( m_macPrintInfo )
923 {
924 ::PrintDefault( m_macPrintInfo ) ;
925 // todo setup the global pagesetup ?
926 }
927 }
928 if ( m_macPrintInfo )
929 {
930 (**m_macPrintInfo).prJob.iCopies = m_printNoCopies ;
931 (**m_macPrintInfo).prJob.iFstPage = m_printFromPage ;
932 (**m_macPrintInfo).prJob.iLstPage = m_printToPage ;
933 }
934}
935
936void wxPrintDialogData::ConvertFromNative()
937{
938 if ( m_macPrintInfo )
939 {
940 m_printNoCopies = (**m_macPrintInfo).prJob.iCopies ;
941 m_printFromPage = (**m_macPrintInfo).prJob.iFstPage ;
942 m_printToPage = (**m_macPrintInfo).prJob.iLstPage ;
943 }
944}
945#endif
946
947
948void wxPrintDialogData::operator=(const wxPrintDialogData& data)
949{
950 m_printFromPage = data.m_printFromPage;
951 m_printToPage = data.m_printToPage;
952 m_printMinPage = data.m_printMinPage;
953 m_printMaxPage = data.m_printMaxPage;
954 m_printNoCopies = data.m_printNoCopies;
955 m_printAllPages = data.m_printAllPages;
956 m_printCollate = data.m_printCollate;
957 m_printToFile = data.m_printToFile;
958 m_printSelection = data.m_printSelection;
959 m_printEnableSelection = data.m_printEnableSelection;
960 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
961 m_printEnableHelp = data.m_printEnableHelp;
962 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
963 m_printSetupDialog = data.m_printSetupDialog;
964
965 m_printData = data.m_printData;
966}
967
968void wxPrintDialogData::operator=(const wxPrintData& data)
969{
970 m_printData = data;
971}
972
973// ----------------------------------------------------------------------------
974// wxPageSetupDialogData
975// ----------------------------------------------------------------------------
976
977wxPageSetupDialogData::wxPageSetupDialogData()
978{
979#if defined(__WIN95__)
980 m_pageSetupData = NULL;
981#elif defined( __WXMAC__ )
982 m_macPageSetupInfo = NULL ;
983#endif
984 m_paperSize = wxSize(0, 0);
985
986 CalculatePaperSizeFromId();
987
988 m_minMarginTopLeft = wxPoint(0, 0);
989 m_minMarginBottomRight = wxPoint(0, 0);
990 m_marginTopLeft = wxPoint(0, 0);
991 m_marginBottomRight = wxPoint(0, 0);
992
993 // Flags
994 m_defaultMinMargins = FALSE;
995 m_enableMargins = TRUE;
996 m_enableOrientation = TRUE;
997 m_enablePaper = TRUE;
998 m_enablePrinter = TRUE;
999 m_enableHelp = FALSE;
1000 m_getDefaultInfo = FALSE;
1001}
1002
1003wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
1004{
1005#if defined(__WIN95__)
1006 m_pageSetupData = NULL;
1007#elif defined( __WXMAC__ )
1008 m_macPageSetupInfo = NULL ;
1009#endif
1010 (*this) = dialogData;
1011}
1012
1013wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
1014{
1015#if defined(__WIN95__)
1016 m_pageSetupData = NULL;
1017#elif defined( __WXMAC__ )
1018 m_macPageSetupInfo = NULL ;
1019#endif
1020 m_paperSize = wxSize(0, 0);
1021 m_minMarginTopLeft = wxPoint(0, 0);
1022 m_minMarginBottomRight = wxPoint(0, 0);
1023 m_marginTopLeft = wxPoint(0, 0);
1024 m_marginBottomRight = wxPoint(0, 0);
1025
1026 // Flags
1027 m_defaultMinMargins = FALSE;
1028 m_enableMargins = TRUE;
1029 m_enableOrientation = TRUE;
1030 m_enablePaper = TRUE;
1031 m_enablePrinter = TRUE;
1032 m_enableHelp = FALSE;
1033 m_getDefaultInfo = FALSE;
1034
1035 m_printData = printData;
1036
1037 // The wxPrintData paper size overrides these values, unless the size cannot
1038 // be found.
1039 CalculatePaperSizeFromId();
1040}
1041
1042wxPageSetupDialogData::~wxPageSetupDialogData()
1043{
1044#if defined(__WIN95__) && defined(__WXMSW__)
1045 PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData;
1046 if ( pd && pd->hDevMode )
1047 GlobalFree(pd->hDevMode);
1048 if ( pd )
1049 delete pd;
1050#elif defined( __WXMAC__ )
1051 if( m_macPageSetupInfo )
1052 ::DisposeHandle( (Handle) m_macPageSetupInfo ) ;
1053#endif
1054}
1055
1056void wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
1057{
1058 m_paperSize = data.m_paperSize;
1059 m_minMarginTopLeft = data.m_minMarginTopLeft;
1060 m_minMarginBottomRight = data.m_minMarginBottomRight;
1061 m_marginTopLeft = data.m_marginTopLeft;
1062 m_marginBottomRight = data.m_marginBottomRight;
1063 m_defaultMinMargins = data.m_defaultMinMargins;
1064 m_enableMargins = data.m_enableMargins;
1065 m_enableOrientation = data.m_enableOrientation;
1066 m_enablePaper = data.m_enablePaper;
1067 m_enablePrinter = data.m_enablePrinter;
1068 m_getDefaultInfo = data.m_getDefaultInfo;;
1069 m_enableHelp = data.m_enableHelp;
1070
1071 m_printData = data.m_printData;
1072}
1073
1074void wxPageSetupDialogData::operator=(const wxPrintData& data)
1075{
1076 m_printData = data;
1077}
1078
1079#if defined(__WIN95__)
1080void wxPageSetupDialogData::ConvertToNative()
1081{
1082 m_printData.ConvertToNative();
1083
1084 PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData;
1085
1086 if ( m_pageSetupData == NULL )
1087 {
1088 pd = new PAGESETUPDLG;
1089 pd->hDevMode = NULL;
1090 m_pageSetupData = (void *)pd;
1091 }
1092
1093 // Pass the devmode data (created in m_printData.ConvertToNative)
1094 // to the PRINTDLG structure, since it'll
1095 // be needed when PrintDlg is called.
1096
1097 if (pd->hDevMode)
1098 {
1099 GlobalFree(pd->hDevMode);
1100 pd->hDevMode = NULL;
1101 }
1102
1103 pd->hDevMode = (HGLOBAL) m_printData.GetNativeData();
1104
1105 m_printData.SetNativeData((void*) NULL);
1106
1107 wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
1108
1109// pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1110
1111 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
1112
1113 if ( m_defaultMinMargins )
1114 pd->Flags |= PSD_DEFAULTMINMARGINS;
1115 if ( !m_enableMargins )
1116 pd->Flags |= PSD_DISABLEMARGINS;
1117 if ( !m_enableOrientation )
1118 pd->Flags |= PSD_DISABLEORIENTATION;
1119 if ( !m_enablePaper )
1120 pd->Flags |= PSD_DISABLEPAPER;
1121 if ( !m_enablePrinter )
1122 pd->Flags |= PSD_DISABLEPRINTER;
1123 if ( m_getDefaultInfo )
1124 pd->Flags |= PSD_RETURNDEFAULT;
1125 if ( m_enableHelp )
1126 pd->Flags |= PSD_SHOWHELP;
1127
1128 // We want the units to be in hundredths of a millimetre
1129 pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1130
1131 pd->lStructSize = sizeof( PAGESETUPDLG );
1132 pd->hwndOwner=(HWND)NULL;
1133 pd->hDevNames=(HWND)NULL;
1134 pd->hInstance=(HINSTANCE)NULL;
1135
1136 pd->ptPaperSize.x = m_paperSize.x * 100;
1137 pd->ptPaperSize.y = m_paperSize.y * 100;
1138
1139 pd->rtMinMargin.left = m_minMarginTopLeft.x * 100;
1140 pd->rtMinMargin.top = m_minMarginTopLeft.y * 100;
1141 pd->rtMinMargin.right = m_minMarginBottomRight.x * 100;
1142 pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100;
1143
1144 pd->rtMargin.left = m_marginTopLeft.x * 100;
1145 pd->rtMargin.top = m_marginTopLeft.y * 100;
1146 pd->rtMargin.right = m_marginBottomRight.x * 100;
1147 pd->rtMargin.bottom = m_marginBottomRight.y * 100;
1148
1149 pd->lCustData = 0;
1150 pd->lpfnPageSetupHook = NULL;
1151 pd->lpfnPagePaintHook = NULL;
1152 pd->hPageSetupTemplate = NULL;
1153 pd->lpPageSetupTemplateName = NULL;
1154
1155/*
1156 if ( pd->hDevMode )
1157 {
1158 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1159 memset(devMode, 0, sizeof(DEVMODE));
1160 devMode->dmSize = sizeof(DEVMODE);
1161 devMode->dmOrientation = m_orientation;
1162 devMode->dmFields = DM_ORIENTATION;
1163 GlobalUnlock(pd->hDevMode);
1164 }
1165*/
1166}
1167
1168void wxPageSetupDialogData::ConvertFromNative()
1169{
1170 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
1171 if ( !pd )
1172 return;
1173
1174 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1175 if (pd->hDevMode)
1176 {
1177 if (m_printData.GetNativeData())
1178 {
1179 // Make sure we don't leak memory
1180 GlobalFree((HGLOBAL) m_printData.GetNativeData());
1181 }
1182 m_printData.SetNativeData((void*) pd->hDevMode);
1183 pd->hDevMode = NULL;
1184 }
1185
1186 m_printData.ConvertFromNative();
1187
1188 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
1189
1190 m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS);
1191 m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS);
1192 m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION);
1193 m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER);
1194 m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER);
1195 m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT);
1196 m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP);
1197
1198 m_paperSize.x = pd->ptPaperSize.x / 100;
1199 m_paperSize.y = pd->ptPaperSize.y / 100;
1200
1201 m_minMarginTopLeft.x = pd->rtMinMargin.left / 100;
1202 m_minMarginTopLeft.y = pd->rtMinMargin.top / 100;
1203 m_minMarginBottomRight.x = pd->rtMinMargin.right / 100;
1204 m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100;
1205
1206 m_marginTopLeft.x = pd->rtMargin.left / 100 ;
1207 m_marginTopLeft.y = pd->rtMargin.top / 100 ;
1208 m_marginBottomRight.x = pd->rtMargin.right / 100 ;
1209 m_marginBottomRight.y = pd->rtMargin.bottom / 100 ;
1210}
1211
1212void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win)
1213{
1214 if ( m_pageSetupData == NULL )
1215 ConvertToNative();
1216
1217 if ( m_pageSetupData != NULL && win != NULL)
1218 {
1219 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
1220 pd->hwndOwner=(HWND) win->GetHWND();
1221 }
1222}
1223#endif // Win95
1224
1225#ifdef __WXMAC__
1226void wxPageSetupDialogData::ConvertToNative()
1227{
1228 if ( !m_macPageSetupInfo )
1229 {
1230 m_macPageSetupInfo = (THPrint) NewHandleClear( sizeof( TPrint ) ) ;
1231 if ( m_macPageSetupInfo )
1232 {
1233 ::PrintDefault( m_macPageSetupInfo ) ;
1234 }
1235 }
1236 if ( m_macPageSetupInfo )
1237 {
1238 // on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0
1239 (**m_macPageSetupInfo).rPaper.left = int( ((double) m_minMarginTopLeft.x)*mm2pt ) ;
1240 (**m_macPageSetupInfo).rPaper.top = int( ((double) m_minMarginTopLeft.y)*mm2pt ) ;
1241
1242 (**m_macPageSetupInfo).rPaper.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x)*mm2pt ) ;
1243 (**m_macPageSetupInfo).rPaper.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y)*mm2pt ) ;
1244
1245 (**m_macPageSetupInfo).prInfo.rPage.left = 0 ;
1246 (**m_macPageSetupInfo).prInfo.rPage.top = 0 ;
1247 (**m_macPageSetupInfo).prInfo.rPage.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x - m_minMarginBottomRight.x)*mm2pt ) ;
1248 (**m_macPageSetupInfo).prInfo.rPage.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y - m_minMarginBottomRight.y)*mm2pt ) ;
1249
1250 //TODO add custom fields in dialog for margins
1251
1252 }
1253}
1254
1255void wxPageSetupDialogData::ConvertFromNative()
1256{
1257 if ( m_macPageSetupInfo )
1258 {
1259 m_paperSize.x = ((double) (**m_macPageSetupInfo).rPaper.right - (**m_macPageSetupInfo).rPaper.left ) * pt2mm ;
1260 m_paperSize.y = ((double) (**m_macPageSetupInfo).rPaper.bottom - (**m_macPageSetupInfo).rPaper.top ) * pt2mm ;
1261
1262 m_minMarginTopLeft.x = ((double) -(**m_macPageSetupInfo).rPaper.left ) * pt2mm ;
1263 m_minMarginTopLeft.y = ((double) -(**m_macPageSetupInfo).rPaper.top ) * pt2mm ;
1264
1265 m_minMarginBottomRight.x = ((double) (**m_macPageSetupInfo).rPaper.right - (**m_macPageSetupInfo).prInfo.rPage.right ) * pt2mm ;
1266 m_minMarginBottomRight.y = ((double)(**m_macPageSetupInfo).rPaper.bottom - (**m_macPageSetupInfo).prInfo.rPage.bottom ) * pt2mm ;
1267
1268 // adjust minimal values
1269 //TODO add custom fields in dialog for margins
1270
1271 if ( m_marginTopLeft.x < m_minMarginTopLeft.x )
1272 m_marginTopLeft.x = m_minMarginTopLeft.x ;
1273
1274 if ( m_marginBottomRight.x < m_minMarginBottomRight.x )
1275 m_marginBottomRight.x = m_minMarginBottomRight.x ;
1276
1277 if ( m_marginTopLeft.y < m_minMarginTopLeft.y )
1278 m_marginTopLeft.y = m_minMarginTopLeft.y ;
1279
1280 if ( m_marginBottomRight.y < m_minMarginBottomRight.y )
1281 m_marginBottomRight.y = m_minMarginBottomRight.y ;
1282
1283 }
1284}
1285#endif
1286
1287
1288// If a corresponding paper type is found in the paper database, will set the m_printData
1289// paper size id member as well.
1290void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
1291{
1292 m_paperSize = sz;
1293
1294 CalculateIdFromPaperSize();
1295}
1296
1297// Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1298void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
1299{
1300 m_printData.SetPaperId(id);
1301
1302 CalculatePaperSizeFromId();
1303}
1304
1305// Use paper size defined in this object to set the wxPrintData
1306// paper id
1307void wxPageSetupDialogData::CalculateIdFromPaperSize()
1308{
1309 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
1310 wxT("wxThePrintPaperDatabase should not be NULL. "
1311 "Do not create global print dialog data objects.") );
1312
1313 wxSize sz = GetPaperSize();
1314
1315 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
1316 if (id != wxPAPER_NONE)
1317 {
1318 m_printData.SetPaperId(id);
1319 }
1320}
1321
1322// Use paper id in wxPrintData to set this object's paper size
1323void wxPageSetupDialogData::CalculatePaperSizeFromId()
1324{
1325 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
1326 wxT("wxThePrintPaperDatabase should not be NULL. "
1327 "Do not create global print dialog data objects.") );
1328
1329 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
1330
1331 if (sz.x != 0)
1332 {
1333 // sz is in 10ths of a mm, so multiply by 10.
1334 m_paperSize.x = sz.x * 10;
1335 m_paperSize.y = sz.y * 10;
1336 }
1337}
1338
1339#endif // wxUSE_PRINTING_ARCHITECTURE