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