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