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