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