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