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