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