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