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