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