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