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