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