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