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