]> git.saurik.com Git - wxWidgets.git/blob - src/common/cmndata.cpp
wxADJUST_MIN definition (forgot to ci last time)
[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->dmPaperSize = DMPAPER_USER;
446 devMode->dmFields |= DM_PAPERWIDTH;
447 devMode->dmFields |= DM_PAPERLENGTH;
448 }
449 else
450 {
451 if (wxThePrintPaperDatabase)
452 {
453 wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType(m_paperId);
454 if (paper)
455 {
456 devMode->dmPaperSize = paper->GetPlatformId();
457 devMode->dmFields |= DM_PAPERSIZE;
458 }
459 }
460 }
461 #endif
462
463 //// Duplex
464
465 int duplex;
466 switch (m_duplexMode)
467 {
468 case wxDUPLEX_HORIZONTAL: {
469 duplex = DMDUP_HORIZONTAL; break;
470 }
471 case wxDUPLEX_VERTICAL: {
472 duplex = DMDUP_VERTICAL; break;
473 }
474 default:
475 case wxDUPLEX_SIMPLEX: {
476 duplex = DMDUP_SIMPLEX; break;
477 }
478 }
479 devMode->dmDuplex = duplex;
480 devMode->dmFields |= DM_DUPLEX;
481
482 //// Quality
483
484 int quality;
485 switch (m_printQuality)
486 {
487 case wxPRINT_QUALITY_MEDIUM: {
488 quality = DMRES_MEDIUM; break;
489 }
490 case wxPRINT_QUALITY_LOW: {
491 quality = DMRES_LOW; break;
492 }
493 case wxPRINT_QUALITY_DRAFT: {
494 quality = DMRES_DRAFT; break;
495 }
496 case wxPRINT_QUALITY_HIGH: {
497 quality = DMRES_HIGH; break;
498 }
499 default: {
500 quality = m_printQuality; break;
501 }
502 }
503 devMode->dmPrintQuality = quality;
504 devMode->dmFields |= DM_PRINTQUALITY;
505
506 GlobalUnlock(hDevMode);
507 }
508
509 if ( hDevNames )
510 {
511 GlobalFree(hDevNames);
512 }
513
514 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
515 m_devNames = (void*) (long) wxCreateDevNames("", m_printerName, "");
516 }
517
518 void wxPrintData::ConvertFromNative()
519 {
520 HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
521 HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
522
523 if (!hDevMode)
524 return;
525
526 if ( hDevMode )
527 {
528 LPDEVMODE devMode = (LPDEVMODE)GlobalLock(hDevMode);
529
530 #ifndef __WXWINE__
531 //// Orientation
532
533 if (devMode->dmFields & DM_ORIENTATION)
534 m_printOrientation = devMode->dmOrientation;
535 #endif
536
537 //// Collation
538
539 #ifndef __WIN16__
540 if (devMode->dmFields & DM_COLLATE)
541 {
542 if (devMode->dmCollate == DMCOLLATE_TRUE)
543 m_printCollate = TRUE;
544 else
545 m_printCollate = FALSE;
546 }
547 #endif
548
549 //// Number of copies
550
551 if (devMode->dmFields & DM_COPIES)
552 {
553 m_printNoCopies = devMode->dmCopies;
554 }
555
556 //// Printer name
557
558 if (devMode->dmDeviceName[0] != 0)
559 {
560 // TODO: make this Unicode compatible
561 char buf[32];
562 int i = 0;
563 while (devMode->dmDeviceName[i] != 0)
564 {
565 buf[i] = devMode->dmDeviceName[i];
566 i ++;
567 }
568 buf[i] = 0;
569
570 m_printerName = buf;
571 }
572
573 //// Colour
574
575 if (devMode->dmFields & DM_COLOR)
576 {
577 if (devMode->dmColor == DMCOLOR_COLOR)
578 m_colour = TRUE;
579 else
580 m_colour = FALSE;
581 }
582 else
583 m_colour = TRUE;
584
585 #ifndef __WXWINE__
586 //// Paper size
587
588 if (devMode->dmFields & DM_PAPERSIZE)
589 {
590 if (wxThePrintPaperDatabase)
591 {
592 wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize);
593 if (paper)
594 {
595 m_paperId = paper->GetId();
596 m_paperSize.x = paper->GetWidth() / 10 ;
597 m_paperSize.y = paper->GetHeight() / 10 ;
598 }
599 else
600 {
601 // Shouldn't really get here
602 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
603
604 m_paperId = wxPAPER_NONE;
605 m_paperSize.x = 0;
606 m_paperSize.y = 0;
607 }
608 }
609 else
610 {
611 // Shouldn't really get here
612 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
613
614 m_paperId = wxPAPER_NONE;
615 m_paperSize.x = 0;
616 m_paperSize.y = 0;
617 }
618 }
619 else if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH))
620 {
621 // DEVMODE is in tenths of a milimeter
622 m_paperSize.x = devMode->dmPaperWidth / 10;
623 m_paperSize.y = devMode->dmPaperLength / 10;
624 m_paperId = wxPAPER_NONE;
625 }
626 else
627 {
628 // Shouldn't really get here
629 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
630
631 m_paperSize.x = 0;
632 m_paperSize.y = 0;
633 m_paperId = wxPAPER_NONE;
634 }
635 #endif
636
637 //// Duplex
638
639 if (devMode->dmFields & DM_DUPLEX)
640 {
641 switch (devMode->dmDuplex)
642 {
643 case DMDUP_HORIZONTAL: {
644 m_duplexMode = wxDUPLEX_HORIZONTAL; break;
645 }
646 case DMDUP_VERTICAL: {
647 m_duplexMode = wxDUPLEX_VERTICAL; break;
648 }
649 default:
650 case DMDUP_SIMPLEX: {
651 m_duplexMode = wxDUPLEX_SIMPLEX; break;
652 }
653 }
654 }
655 else
656 m_duplexMode = wxDUPLEX_SIMPLEX;
657
658 //// Quality
659
660 if (devMode->dmFields & DM_PRINTQUALITY)
661 {
662 switch (devMode->dmPrintQuality)
663 {
664 case DMRES_MEDIUM: {
665 m_printQuality = wxPRINT_QUALITY_MEDIUM; break;
666 }
667 case DMRES_LOW: {
668 m_printQuality = wxPRINT_QUALITY_LOW; break;
669 }
670 case DMRES_DRAFT: {
671 m_printQuality = wxPRINT_QUALITY_DRAFT; break;
672 }
673 case DMRES_HIGH: {
674 m_printQuality = wxPRINT_QUALITY_HIGH; break;
675 }
676 default:
677 {
678 // TODO: if the printer fills in the resolution in DPI, how
679 // will the application know if it's high, low, draft etc.??
680 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
681 m_printQuality = devMode->dmPrintQuality; break;
682
683 }
684 }
685 }
686 else
687 m_printQuality = wxPRINT_QUALITY_HIGH;
688
689 GlobalUnlock(hDevMode);
690 }
691
692 if (hDevNames)
693 {
694 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(hDevNames);
695 if (lpDevNames)
696 {
697 // TODO: Unicode-ification
698
699 // Get the port name
700 // port is obsolete in WIN32
701 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
702
703 // Get the printer name
704 wxString printerName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
705
706 // Not sure if we should check for this mismatch
707 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
708
709 if (printerName != wxT(""))
710 m_printerName = printerName;
711
712 GlobalUnlock(hDevNames);
713 }
714 }
715 }
716
717 #endif
718
719 #ifdef __WXMAC__
720 void wxPrintData::ConvertToNative()
721 {
722 #ifdef TARGET_CARBON
723 #else
724 (**m_macPrintInfo).prJob.iCopies = m_printNoCopies ;
725 #endif
726 }
727
728 void wxPrintData::ConvertFromNative()
729 {
730 #ifdef TARGET_CARBON
731 #else
732 m_printNoCopies = (**m_macPrintInfo).prJob.iCopies ;
733 #endif
734 }
735 #endif
736
737 void wxPrintData::operator=(const wxPrintData& data)
738 {
739 #ifdef __WXMAC__
740 #ifdef TARGET_CARBON
741 #else
742 m_macPrintInfo = data.m_macPrintInfo ;
743 HandToHand( (Handle*) &m_macPrintInfo ) ;
744 #endif
745 #endif
746 m_printNoCopies = data.m_printNoCopies;
747 m_printCollate = data.m_printCollate;
748 m_printOrientation = data.m_printOrientation;
749 m_printerName = data.m_printerName;
750 m_colour = data.m_colour;
751 m_duplexMode = data.m_duplexMode;
752 m_printQuality = data.m_printQuality;
753 m_paperId = data.m_paperId;
754 m_paperSize = data.m_paperSize;
755
756 // PostScript-specific data
757 m_printerCommand = data.m_printerCommand;
758 m_previewCommand = data.m_previewCommand;
759 m_printerOptions = data.m_printerOptions;
760 m_filename = data.m_filename;
761 m_afmPath = data.m_afmPath;
762 m_printerScaleX = data.m_printerScaleX;
763 m_printerScaleY = data.m_printerScaleY;
764 m_printerTranslateX = data.m_printerTranslateX;
765 m_printerTranslateY = data.m_printerTranslateY;
766 m_printMode = data.m_printMode;
767 }
768
769 // For compatibility
770 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
771 void wxPrintData::operator=(const wxPrintSetupData& setupData)
772 {
773 SetPrinterCommand(setupData.GetPrinterCommand());
774 SetPreviewCommand(setupData.GetPrintPreviewCommand());
775 SetPrinterOptions(setupData.GetPrinterOptions());
776
777 long xt, yt;
778 setupData.GetPrinterTranslation(& xt, & yt);
779 SetPrinterTranslation(xt, yt);
780
781 double xs, ys;
782 setupData.GetPrinterScaling(& xs, & ys);
783 SetPrinterScaling(xs, ys);
784
785 SetOrientation(setupData.GetPrinterOrientation());
786 SetPrintMode((wxPrintMode) setupData.GetPrinterMode());
787 SetFontMetricPath(setupData.GetAFMPath());
788 if (setupData.GetPaperName() != "")
789 SetPaperId(wxThePrintPaperDatabase->ConvertNameToId(setupData.GetPaperName()));
790 SetColour(setupData.GetColour());
791 SetFilename(setupData.GetPrinterFile());
792 }
793 #endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
794
795
796 // ----------------------------------------------------------------------------
797 // Print dialog data
798 // ----------------------------------------------------------------------------
799
800 wxPrintDialogData::wxPrintDialogData()
801 {
802 #ifdef __WXMSW__
803 m_printDlgData = NULL;
804 #endif
805 m_printFromPage = 0;
806 m_printToPage = 0;
807 m_printMinPage = 0;
808 m_printMaxPage = 0;
809 m_printNoCopies = 1;
810 m_printAllPages = FALSE;
811 m_printCollate = FALSE;
812 m_printToFile = FALSE;
813 m_printSelection = FALSE;
814 m_printEnableSelection = FALSE;
815 m_printEnablePageNumbers = TRUE;
816 m_printEnablePrintToFile = TRUE;
817 m_printEnableHelp = FALSE;
818 m_printSetupDialog = FALSE;
819 }
820
821 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
822 {
823 #ifdef __WXMSW__
824 m_printDlgData = NULL;
825 #endif
826 (*this) = dialogData;
827 }
828
829 wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
830 {
831 #ifdef __WXMSW__
832 m_printDlgData = NULL;
833 #endif
834 m_printFromPage = 0;
835 m_printToPage = 0;
836 m_printMinPage = 0;
837 m_printMaxPage = 0;
838 m_printNoCopies = 1;
839 m_printAllPages = FALSE;
840 m_printCollate = FALSE;
841 m_printToFile = FALSE;
842 m_printSelection = FALSE;
843 m_printEnableSelection = FALSE;
844 m_printEnablePageNumbers = TRUE;
845 m_printEnablePrintToFile = TRUE;
846 m_printEnableHelp = FALSE;
847 m_printSetupDialog = FALSE;
848
849 m_printData = printData;
850 }
851
852 wxPrintDialogData::~wxPrintDialogData()
853 {
854 #ifdef __WXMSW__
855 PRINTDLG *pd = (PRINTDLG *) m_printDlgData;
856 if ( pd && pd->hDevMode )
857 GlobalFree(pd->hDevMode);
858 if ( pd )
859 delete pd;
860 #endif
861 }
862
863 #ifdef __WXMSW__
864 void wxPrintDialogData::ConvertToNative()
865 {
866 m_printData.ConvertToNative();
867
868 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
869
870 if (!pd)
871 {
872 pd = new PRINTDLG;
873 m_printDlgData = (void*) pd;
874
875 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
876 #ifdef __GNUWIN32__
877 pd->lStructSize = 66 ;
878 #else
879 pd->lStructSize = sizeof(PRINTDLG);
880 #endif
881 pd->hwndOwner = (HWND)NULL;
882 pd->hDevMode = NULL; // Will be created by PrintDlg
883 pd->hDevNames = NULL; // Ditto
884
885 pd->Flags = PD_RETURNDEFAULT;
886 pd->nCopies = 1;
887 }
888
889 // Pass the devmode data to the PRINTDLG structure, since it'll
890 // be needed when PrintDlg is called.
891 if (pd->hDevMode)
892 {
893 GlobalFree(pd->hDevMode);
894 }
895
896 // Pass the devnames data to the PRINTDLG structure, since it'll
897 // be needed when PrintDlg is called.
898 if (pd->hDevNames)
899 {
900 GlobalFree(pd->hDevNames);
901 }
902
903 pd->hDevMode = (HGLOBAL)(DWORD) m_printData.GetNativeData();
904
905 m_printData.SetNativeData((void*) NULL);
906
907 wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
908
909 pd->hDevNames = (HGLOBAL)(DWORD) m_printData.GetNativeDataDevNames();
910
911 m_printData.SetNativeDataDevNames((void*) NULL);
912
913 pd->hDC = (HDC) NULL;
914 pd->nFromPage = (UINT)m_printFromPage;
915 pd->nToPage = (UINT)m_printToPage;
916 pd->nMinPage = (UINT)m_printMinPage;
917 pd->nMaxPage = (UINT)m_printMaxPage;
918 pd->nCopies = (UINT)m_printNoCopies;
919
920 pd->Flags = PD_RETURNDC ;
921
922 #ifdef __GNUWIN32__
923 pd->lStructSize = 66 ;
924 #else
925 pd->lStructSize = sizeof( PRINTDLG );
926 #endif
927
928 pd->hwndOwner=(HWND)NULL;
929 // pd->hDevNames=(HANDLE)NULL;
930 pd->hInstance=(HINSTANCE)NULL;
931 pd->lCustData = (LPARAM) NULL;
932 pd->lpfnPrintHook = NULL;
933 pd->lpfnSetupHook = NULL;
934 pd->lpPrintTemplateName = NULL;
935 pd->lpSetupTemplateName = NULL;
936 pd->hPrintTemplate = (HGLOBAL) NULL;
937 pd->hSetupTemplate = (HGLOBAL) NULL;
938
939 if ( m_printAllPages )
940 pd->Flags |= PD_ALLPAGES;
941 if ( m_printAllPages )
942 pd->Flags |= PD_SELECTION;
943 if ( m_printCollate )
944 pd->Flags |= PD_COLLATE;
945 if ( m_printToFile )
946 pd->Flags |= PD_PRINTTOFILE;
947 if ( !m_printEnablePrintToFile )
948 pd->Flags |= PD_DISABLEPRINTTOFILE;
949 if ( !m_printEnableSelection )
950 pd->Flags |= PD_NOSELECTION;
951 if ( !m_printEnablePageNumbers )
952 pd->Flags |= PD_NOPAGENUMS;
953 if ( m_printEnableHelp )
954 pd->Flags |= PD_SHOWHELP;
955 if ( m_printSetupDialog )
956 pd->Flags |= PD_PRINTSETUP;
957 }
958
959 void wxPrintDialogData::ConvertFromNative()
960 {
961 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
962 if ( pd == NULL )
963 return;
964
965 // Pass the devmode data back to the wxPrintData structure where it really belongs.
966 if (pd->hDevMode)
967 {
968 if (m_printData.GetNativeData())
969 {
970 // Make sure we don't leak memory
971 GlobalFree((HGLOBAL)(DWORD) m_printData.GetNativeData());
972 }
973 m_printData.SetNativeData((void*)(long) pd->hDevMode);
974 pd->hDevMode = NULL;
975 }
976
977 // Pass the devnames data back to the wxPrintData structure where it really belongs.
978 if (pd->hDevNames)
979 {
980 if (m_printData.GetNativeDataDevNames())
981 {
982 // Make sure we don't leak memory
983 GlobalFree((HGLOBAL)(DWORD) m_printData.GetNativeDataDevNames());
984 }
985 m_printData.SetNativeDataDevNames((void*)(long) pd->hDevNames);
986 pd->hDevNames = NULL;
987 }
988
989 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
990 // into wxWindows form.
991 m_printData.ConvertFromNative();
992
993 m_printFromPage = pd->nFromPage ;
994 m_printToPage = pd->nToPage ;
995 m_printMinPage = pd->nMinPage ;
996 m_printMaxPage = pd->nMaxPage ;
997 m_printNoCopies = pd->nCopies ;
998
999 m_printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES);
1000 m_printSelection = ((pd->Flags & PD_SELECTION) == PD_SELECTION);
1001 m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE);
1002 m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE);
1003 m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE);
1004 m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION);
1005 m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS);
1006 m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP);
1007 m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP);
1008
1009 /* port is obsolete in WIN32
1010 // Get the port name
1011 if (pd->hDevNames)
1012 {
1013 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
1014 if (lpDevNames) {
1015 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
1016 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
1017 GlobalUnlock(pd->hDevNames);
1018
1019 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
1020 }
1021 }
1022 */
1023 }
1024
1025 void wxPrintDialogData::SetOwnerWindow(wxWindow* win)
1026 {
1027 if ( m_printDlgData == NULL )
1028 ConvertToNative();
1029
1030 if ( m_printDlgData != NULL && win != NULL)
1031 {
1032 PRINTDLG *pd = (PRINTDLG *) m_printDlgData ;
1033 pd->hwndOwner=(HWND) win->GetHWND();
1034 }
1035 }
1036 #endif // MSW
1037
1038 #ifdef __WXMAC__
1039 void wxPrintDialogData::ConvertToNative()
1040 {
1041 #ifdef TARGET_CARBON
1042 #else
1043 (**m_printData.m_macPrintInfo).prJob.iFstPage = m_printFromPage ;
1044 (**m_printData.m_macPrintInfo).prJob.iLstPage = m_printToPage ;
1045 m_printData.ConvertToNative() ;
1046 #endif
1047 }
1048
1049 void wxPrintDialogData::ConvertFromNative()
1050 {
1051 #ifdef TARGET_CARBON
1052 #else
1053 m_printData.ConvertFromNative() ;
1054 m_printFromPage = (**m_printData.m_macPrintInfo).prJob.iFstPage ;
1055 m_printToPage = (**m_printData.m_macPrintInfo).prJob.iLstPage ;
1056 #endif
1057 }
1058 #endif
1059
1060
1061 void wxPrintDialogData::operator=(const wxPrintDialogData& data)
1062 {
1063 m_printFromPage = data.m_printFromPage;
1064 m_printToPage = data.m_printToPage;
1065 m_printMinPage = data.m_printMinPage;
1066 m_printMaxPage = data.m_printMaxPage;
1067 m_printNoCopies = data.m_printNoCopies;
1068 m_printAllPages = data.m_printAllPages;
1069 m_printCollate = data.m_printCollate;
1070 m_printToFile = data.m_printToFile;
1071 m_printSelection = data.m_printSelection;
1072 m_printEnableSelection = data.m_printEnableSelection;
1073 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
1074 m_printEnableHelp = data.m_printEnableHelp;
1075 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
1076 m_printSetupDialog = data.m_printSetupDialog;
1077
1078 m_printData = data.m_printData;
1079 }
1080
1081 void wxPrintDialogData::operator=(const wxPrintData& data)
1082 {
1083 m_printData = data;
1084 }
1085
1086 // ----------------------------------------------------------------------------
1087 // wxPageSetupDialogData
1088 // ----------------------------------------------------------------------------
1089
1090 wxPageSetupDialogData::wxPageSetupDialogData()
1091 {
1092 #if defined(__WIN95__)
1093 m_pageSetupData = NULL;
1094 #endif
1095 m_paperSize = wxSize(0, 0);
1096
1097 CalculatePaperSizeFromId();
1098
1099 m_minMarginTopLeft = wxPoint(0, 0);
1100 m_minMarginBottomRight = wxPoint(0, 0);
1101 m_marginTopLeft = wxPoint(0, 0);
1102 m_marginBottomRight = wxPoint(0, 0);
1103
1104 // Flags
1105 m_defaultMinMargins = FALSE;
1106 m_enableMargins = TRUE;
1107 m_enableOrientation = TRUE;
1108 m_enablePaper = TRUE;
1109 m_enablePrinter = TRUE;
1110 m_enableHelp = FALSE;
1111 m_getDefaultInfo = FALSE;
1112 }
1113
1114 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
1115 {
1116 #if defined(__WIN95__)
1117 m_pageSetupData = NULL;
1118 #endif
1119 (*this) = dialogData;
1120 }
1121
1122 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
1123 {
1124 #if defined(__WIN95__)
1125 m_pageSetupData = NULL;
1126 #endif
1127 m_paperSize = wxSize(0, 0);
1128 m_minMarginTopLeft = wxPoint(0, 0);
1129 m_minMarginBottomRight = wxPoint(0, 0);
1130 m_marginTopLeft = wxPoint(0, 0);
1131 m_marginBottomRight = wxPoint(0, 0);
1132
1133 // Flags
1134 m_defaultMinMargins = FALSE;
1135 m_enableMargins = TRUE;
1136 m_enableOrientation = TRUE;
1137 m_enablePaper = TRUE;
1138 m_enablePrinter = TRUE;
1139 m_enableHelp = FALSE;
1140 m_getDefaultInfo = FALSE;
1141
1142 m_printData = printData;
1143
1144 // The wxPrintData paper size overrides these values, unless the size cannot
1145 // be found.
1146 CalculatePaperSizeFromId();
1147 }
1148
1149 wxPageSetupDialogData::~wxPageSetupDialogData()
1150 {
1151 #if defined(__WIN95__) && defined(__WXMSW__)
1152 PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData;
1153 if ( pd && pd->hDevMode )
1154 GlobalFree(pd->hDevMode);
1155 if ( pd && pd->hDevNames )
1156 GlobalFree(pd->hDevNames);
1157 if ( pd )
1158 delete pd;
1159 #endif
1160 }
1161
1162 void wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
1163 {
1164 m_paperSize = data.m_paperSize;
1165 m_minMarginTopLeft = data.m_minMarginTopLeft;
1166 m_minMarginBottomRight = data.m_minMarginBottomRight;
1167 m_marginTopLeft = data.m_marginTopLeft;
1168 m_marginBottomRight = data.m_marginBottomRight;
1169 m_defaultMinMargins = data.m_defaultMinMargins;
1170 m_enableMargins = data.m_enableMargins;
1171 m_enableOrientation = data.m_enableOrientation;
1172 m_enablePaper = data.m_enablePaper;
1173 m_enablePrinter = data.m_enablePrinter;
1174 m_getDefaultInfo = data.m_getDefaultInfo;;
1175 m_enableHelp = data.m_enableHelp;
1176
1177 m_printData = data.m_printData;
1178 }
1179
1180 void wxPageSetupDialogData::operator=(const wxPrintData& data)
1181 {
1182 m_printData = data;
1183 }
1184
1185 #if defined(__WIN95__)
1186 void wxPageSetupDialogData::ConvertToNative()
1187 {
1188 m_printData.ConvertToNative();
1189
1190 PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData;
1191
1192 if ( m_pageSetupData == NULL )
1193 {
1194 pd = new PAGESETUPDLG;
1195 pd->hDevMode = NULL;
1196 pd->hDevNames = NULL;
1197 m_pageSetupData = (void *)pd;
1198 }
1199
1200 // Pass the devmode data (created in m_printData.ConvertToNative)
1201 // to the PRINTDLG structure, since it'll
1202 // be needed when PrintDlg is called.
1203
1204 if (pd->hDevMode)
1205 {
1206 GlobalFree(pd->hDevMode);
1207 pd->hDevMode = NULL;
1208 }
1209
1210 pd->hDevMode = (HGLOBAL) m_printData.GetNativeData();
1211
1212 m_printData.SetNativeData((void*) NULL);
1213
1214 wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
1215
1216 // Pass the devnames data (created in m_printData.ConvertToNative)
1217 // to the PRINTDLG structure, since it'll
1218 // be needed when PrintDlg is called.
1219
1220 if (pd->hDevNames)
1221 {
1222 GlobalFree(pd->hDevNames);
1223 pd->hDevNames = NULL;
1224 }
1225
1226 pd->hDevNames = (HGLOBAL) m_printData.GetNativeDataDevNames();
1227
1228 m_printData.SetNativeDataDevNames((void*) NULL);
1229
1230 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1231
1232 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
1233
1234 if ( m_defaultMinMargins )
1235 pd->Flags |= PSD_DEFAULTMINMARGINS;
1236 if ( !m_enableMargins )
1237 pd->Flags |= PSD_DISABLEMARGINS;
1238 if ( !m_enableOrientation )
1239 pd->Flags |= PSD_DISABLEORIENTATION;
1240 if ( !m_enablePaper )
1241 pd->Flags |= PSD_DISABLEPAPER;
1242 if ( !m_enablePrinter )
1243 pd->Flags |= PSD_DISABLEPRINTER;
1244 if ( m_getDefaultInfo )
1245 pd->Flags |= PSD_RETURNDEFAULT;
1246 if ( m_enableHelp )
1247 pd->Flags |= PSD_SHOWHELP;
1248
1249 // We want the units to be in hundredths of a millimetre
1250 pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1251
1252 pd->lStructSize = sizeof( PAGESETUPDLG );
1253 pd->hwndOwner=(HWND)NULL;
1254 // pd->hDevNames=(HWND)NULL;
1255 pd->hInstance=(HINSTANCE)NULL;
1256 // PAGESETUPDLG is in hundreds of a mm
1257 pd->ptPaperSize.x = m_paperSize.x * 100;
1258 pd->ptPaperSize.y = m_paperSize.y * 100;
1259
1260 pd->rtMinMargin.left = m_minMarginTopLeft.x * 100;
1261 pd->rtMinMargin.top = m_minMarginTopLeft.y * 100;
1262 pd->rtMinMargin.right = m_minMarginBottomRight.x * 100;
1263 pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100;
1264
1265 pd->rtMargin.left = m_marginTopLeft.x * 100;
1266 pd->rtMargin.top = m_marginTopLeft.y * 100;
1267 pd->rtMargin.right = m_marginBottomRight.x * 100;
1268 pd->rtMargin.bottom = m_marginBottomRight.y * 100;
1269
1270 pd->lCustData = 0;
1271 pd->lpfnPageSetupHook = NULL;
1272 pd->lpfnPagePaintHook = NULL;
1273 pd->hPageSetupTemplate = NULL;
1274 pd->lpPageSetupTemplateName = NULL;
1275
1276 /*
1277 if ( pd->hDevMode )
1278 {
1279 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1280 memset(devMode, 0, sizeof(DEVMODE));
1281 devMode->dmSize = sizeof(DEVMODE);
1282 devMode->dmOrientation = m_orientation;
1283 devMode->dmFields = DM_ORIENTATION;
1284 GlobalUnlock(pd->hDevMode);
1285 }
1286 */
1287 }
1288
1289 void wxPageSetupDialogData::ConvertFromNative()
1290 {
1291 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
1292 if ( !pd )
1293 return;
1294
1295 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1296 if (pd->hDevMode)
1297 {
1298 if (m_printData.GetNativeData())
1299 {
1300 // Make sure we don't leak memory
1301 GlobalFree((HGLOBAL) m_printData.GetNativeData());
1302 }
1303 m_printData.SetNativeData((void*) pd->hDevMode);
1304 pd->hDevMode = NULL;
1305 }
1306
1307 m_printData.ConvertFromNative();
1308
1309 // Pass the devnames data back to the wxPrintData structure where it really belongs.
1310 if (pd->hDevNames)
1311 {
1312 if (m_printData.GetNativeDataDevNames())
1313 {
1314 // Make sure we don't leak memory
1315 GlobalFree((HGLOBAL) m_printData.GetNativeDataDevNames());
1316 }
1317 m_printData.SetNativeDataDevNames((void*) pd->hDevNames);
1318 pd->hDevNames = NULL;
1319 }
1320
1321 m_printData.ConvertFromNative();
1322
1323 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
1324
1325 m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS);
1326 m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS);
1327 m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION);
1328 m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER);
1329 m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER);
1330 m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT);
1331 m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP);
1332
1333 // PAGESETUPDLG is in hundreds of a mm
1334 m_paperSize.x = pd->ptPaperSize.x / 100;
1335 m_paperSize.y = pd->ptPaperSize.y / 100;
1336
1337 m_minMarginTopLeft.x = pd->rtMinMargin.left / 100;
1338 m_minMarginTopLeft.y = pd->rtMinMargin.top / 100;
1339 m_minMarginBottomRight.x = pd->rtMinMargin.right / 100;
1340 m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100;
1341
1342 m_marginTopLeft.x = pd->rtMargin.left / 100 ;
1343 m_marginTopLeft.y = pd->rtMargin.top / 100 ;
1344 m_marginBottomRight.x = pd->rtMargin.right / 100 ;
1345 m_marginBottomRight.y = pd->rtMargin.bottom / 100 ;
1346 }
1347
1348 void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win)
1349 {
1350 if ( m_pageSetupData == NULL )
1351 ConvertToNative();
1352
1353 if ( m_pageSetupData != NULL && win != NULL)
1354 {
1355 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
1356 pd->hwndOwner=(HWND) win->GetHWND();
1357 }
1358 }
1359 #endif // Win95
1360
1361 #ifdef __WXMAC__
1362 void wxPageSetupDialogData::ConvertToNative()
1363 {
1364 m_printData.ConvertToNative() ;
1365 // on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0
1366 #ifdef TARGET_CARBON
1367 #else
1368 (**m_printData.m_macPrintInfo).rPaper.left = int( ((double) m_minMarginTopLeft.x)*mm2pt ) ;
1369 (**m_printData.m_macPrintInfo).rPaper.top = int( ((double) m_minMarginTopLeft.y)*mm2pt ) ;
1370
1371 (**m_printData.m_macPrintInfo).rPaper.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x)*mm2pt ) ;
1372 (**m_printData.m_macPrintInfo).rPaper.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y)*mm2pt ) ;
1373
1374 (**m_printData.m_macPrintInfo).prInfo.rPage.left = 0 ;
1375 (**m_printData.m_macPrintInfo).prInfo.rPage.top = 0 ;
1376 (**m_printData.m_macPrintInfo).prInfo.rPage.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x - m_minMarginBottomRight.x)*mm2pt ) ;
1377 (**m_printData.m_macPrintInfo).prInfo.rPage.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y - m_minMarginBottomRight.y)*mm2pt ) ;
1378 #endif
1379 }
1380
1381 void wxPageSetupDialogData::ConvertFromNative()
1382 {
1383 m_printData.ConvertFromNative () ;
1384
1385 #ifdef TARGET_CARBON
1386 #else
1387 m_paperSize.x = ((double) (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).rPaper.left ) * pt2mm ;
1388 m_paperSize.y = ((double) (**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).rPaper.top ) * pt2mm ;
1389
1390 m_minMarginTopLeft.x = ((double) -(**m_printData.m_macPrintInfo).rPaper.left ) * pt2mm ;
1391 m_minMarginTopLeft.y = ((double) -(**m_printData.m_macPrintInfo).rPaper.top ) * pt2mm ;
1392
1393 m_minMarginBottomRight.x = ((double) (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).prInfo.rPage.right ) * pt2mm ;
1394 m_minMarginBottomRight.y = ((double)(**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).prInfo.rPage.bottom ) * pt2mm ;
1395 #endif
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 #endif
1412
1413
1414 // If a corresponding paper type is found in the paper database, will set the m_printData
1415 // paper size id member as well.
1416 void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
1417 {
1418 m_paperSize = sz;
1419
1420 CalculateIdFromPaperSize();
1421 }
1422
1423 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1424 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
1425 {
1426 m_printData.SetPaperId(id);
1427
1428 CalculatePaperSizeFromId();
1429 }
1430
1431 // Use paper size defined in this object to set the wxPrintData
1432 // paper id
1433 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1434 {
1435 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
1436 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
1437
1438 wxSize sz = GetPaperSize();
1439
1440 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
1441 if (id != wxPAPER_NONE)
1442 {
1443 m_printData.SetPaperId(id);
1444 }
1445 }
1446
1447 // Use paper id in wxPrintData to set this object's paper size
1448 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1449 {
1450 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
1451 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
1452
1453 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
1454
1455 if (sz.x != 0)
1456 {
1457 // sz is in 10ths of a mm, so multiply by 10.
1458 m_paperSize.x = sz.x * 10;
1459 m_paperSize.y = sz.y * 10;
1460 }
1461 }
1462
1463 #endif // wxUSE_PRINTING_ARCHITECTURE