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