]> git.saurik.com Git - wxWidgets.git/blame - src/common/cmndata.cpp
fix from Robert
[wxWidgets.git] / src / common / cmndata.cpp
CommitLineData
c801d85f
KB
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
8bbe427f 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
8826f46f
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
c801d85f 20#ifdef __GNUG__
8826f46f 21 #pragma implementation "cmndata.h"
c801d85f
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
8826f46f 28 #pragma hdrstop
c801d85f
KB
29#endif
30
31#ifndef WX_PRECOMP
8826f46f
VZ
32 #include <stdio.h>
33 #include "wx/string.h"
34 #include "wx/utils.h"
35 #include "wx/app.h"
c801d85f
KB
36#endif
37
38#include "wx/gdicmn.h"
39#include "wx/cmndata.h"
6776a0b2 40#include "wx/log.h"
8826f46f 41
7bcb11d3 42// For compatibility
32e768ae 43#if (defined(__WXMOTIF__) || defined(__WXGTK__) || defined(__WXPM__)) && wxUSE_POSTSCRIPT
8826f46f 44 #define wxCOMPATIBILITY_WITH_PRINTSETUPDATA 1
7bcb11d3 45#endif
c801d85f 46
88ac883a
VZ
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
7be1f0d9 54
8826f46f
VZ
55#ifdef __WXMSW__
56 #include <windows.h>
3096bd2f 57 #include "wx/msw/private.h"
7be1f0d9 58
8826f46f
VZ
59 #if !defined(__WIN32__)
60 #include <print.h>
61 #include <commdlg.h>
62 #endif // Win16
63
c455ab93
RR
64 #ifdef __WXWINE__
65 #include <cderr.h>
66 #include <commdlg.h>
67 #endif
68
8826f46f
VZ
69 #if defined(__WATCOMC__) || defined(__SC__) || defined(__SALFORDC__)
70 #include <windowsx.h>
71 #include <commdlg.h>
72 #endif
73#endif // MSW
c801d85f 74
88ac883a
VZ
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
cd0b1709 80
8826f46f
VZ
81 IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
82 IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
c801d85f 83
51abe921 84#ifdef __WXMAC__
cd0b1709
VZ
85 #define mm2pt 2.83464566929
86 #define pt2mm 0.352777777778
87#endif // Mac
51abe921 88
8826f46f
VZ
89// ============================================================================
90// implementation
91// ============================================================================
92
93// ----------------------------------------------------------------------------
94// wxColourData
95// ----------------------------------------------------------------------------
c801d85f 96
8bbe427f 97wxColourData::wxColourData()
c801d85f 98{
7bcb11d3
JS
99 int i;
100 for (i = 0; i < 16; i++)
101 custColours[i].Set(255, 255, 255);
8826f46f 102
7bcb11d3
JS
103 chooseFull = FALSE;
104 dataColour.Set(0,0,0);
105}
c801d85f 106
7bcb11d3
JS
107wxColourData::wxColourData(const wxColourData& data)
108{
109 (*this) = data;
8bbe427f 110}
c801d85f 111
8bbe427f 112wxColourData::~wxColourData()
c801d85f
KB
113{
114}
115
116void wxColourData::SetCustomColour(int i, wxColour& colour)
117{
7bcb11d3
JS
118 if (i > 15 || i < 0)
119 return;
8826f46f 120
7bcb11d3 121 custColours[i] = colour;
c801d85f
KB
122}
123
124wxColour wxColourData::GetCustomColour(int i)
125{
7bcb11d3
JS
126 if (i > 15 || i < 0)
127 return wxColour(0,0,0);
8826f46f 128
7bcb11d3 129 return custColours[i];
c801d85f
KB
130}
131
132void wxColourData::operator=(const wxColourData& data)
133{
7bcb11d3
JS
134 int i;
135 for (i = 0; i < 16; i++)
136 custColours[i] = data.custColours[i];
8826f46f 137
7bcb11d3
JS
138 dataColour = (wxColour&)data.dataColour;
139 chooseFull = data.chooseFull;
c801d85f
KB
140}
141
8826f46f
VZ
142// ----------------------------------------------------------------------------
143// Font data
144// ----------------------------------------------------------------------------
c801d85f 145
8bbe427f 146wxFontData::wxFontData()
c801d85f 147{
7bcb11d3
JS
148 // Intialize colour to black.
149 fontColour.Set(0, 0, 0);
8826f46f 150
7bcb11d3
JS
151 showHelp = FALSE;
152 allowSymbols = TRUE;
153 enableEffects = TRUE;
154 minSize = 0;
155 maxSize = 0;
c801d85f 156
7beba2fc 157 m_encoding = wxFONTENCODING_SYSTEM;
c801d85f
KB
158}
159
8bbe427f 160wxFontData::~wxFontData()
c801d85f
KB
161{
162}
163
88ac883a 164#if wxUSE_PRINTING_ARCHITECTURE
8826f46f
VZ
165// ----------------------------------------------------------------------------
166// Print data
167// ----------------------------------------------------------------------------
c801d85f 168
8bbe427f 169wxPrintData::wxPrintData()
c801d85f 170{
2049ba38 171#ifdef __WXMSW__
eaeb6a3c
JS
172 m_devMode = (void*) NULL;
173 m_devNames = (void*) NULL;
51abe921 174#elif defined( __WXMAC__ )
7d610b90
SC
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*/
c801d85f 195#endif
7bcb11d3
JS
196 m_printOrientation = wxPORTRAIT;
197 m_printNoCopies = 1;
198 m_printCollate = FALSE;
8826f46f 199
7bcb11d3
JS
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{
58abfef6 223#ifdef __WXMSW__
eaeb6a3c
JS
224 m_devMode = (void*) NULL;
225 m_devNames = (void*) NULL;
7c74e7fe 226#elif defined( __WXMAC__ )
7d610b90
SC
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 */
58abfef6 237#endif
7bcb11d3 238 (*this) = printData;
c801d85f
KB
239}
240
8bbe427f 241wxPrintData::~wxPrintData()
c801d85f 242{
2049ba38 243#ifdef __WXMSW__
48c12cb1 244 HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
eaeb6a3c 245 if ( hDevMode )
7bcb11d3 246 GlobalFree(hDevMode);
eaeb6a3c
JS
247 HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
248 if ( hDevNames )
249 GlobalFree(hDevNames);
51abe921 250#elif defined(__WXMAC__)
7d610b90
SC
251 wxASSERT( m_macPrintInfo ) ;
252// ::DisposeHandle( (Handle) m_macPrintInfo ) ;
c801d85f
KB
253#endif
254}
255
25889d3c 256#if defined(__WXMSW__) // && defined(__WIN32__)
7bcb11d3 257
e47c4d48 258#if defined(__WXDEBUG__) && defined(__WIN32__)
6aa55ce7
JS
259static wxString wxGetPrintDlgError()
260{
261 DWORD err = CommDlgExtendedError();
223d09f6 262 wxString msg = wxT("Unknown");
6aa55ce7
JS
263 switch (err)
264 {
223d09f6
KB
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;
6aa55ce7
JS
287 default: break;
288 }
289 return msg;
290}
25889d3c 291#endif
6aa55ce7 292
eaeb6a3c
JS
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
8bbe427f 323void wxPrintData::ConvertToNative()
c801d85f 324{
48c12cb1 325 HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
eaeb6a3c 326 HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
7bcb11d3 327 if (!hDevMode)
c801d85f 328 {
7bcb11d3
JS
329 // Use PRINTDLG as a way of creating a DEVMODE object
330 PRINTDLG *pd = new PRINTDLG;
8826f46f 331
c801d85f 332 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
7bcb11d3 333#ifdef __GNUWIN32__
6aa55ce7 334 memset(pd, 0, 66);
c801d85f 335 pd->lStructSize = 66 ;
7bcb11d3 336#else
7bcb11d3 337 memset(pd, 0, sizeof(PRINTDLG));
6aa55ce7 338 pd->lStructSize = sizeof(PRINTDLG);
7bcb11d3
JS
339#endif
340
c801d85f
KB
341 pd->hwndOwner = (HWND)NULL;
342 pd->hDevMode = NULL; // Will be created by PrintDlg
343 pd->hDevNames = NULL; // Ditto
6aa55ce7 344 pd->hInstance = (HINSTANCE) wxGetInstance();
8826f46f 345
c801d85f
KB
346 pd->Flags = PD_RETURNDEFAULT;
347 pd->nCopies = 1;
8826f46f 348
c801d85f
KB
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;
58a33cb4
JS
359
360#if defined(__WXDEBUG__) && defined(__WIN32__)
223d09f6 361 wxString str(wxT("Printing error: "));
6aa55ce7
JS
362 str += wxGetPrintDlgError();
363 wxLogDebug(str);
364#endif
c801d85f
KB
365 }
366 else
367 {
eaeb6a3c
JS
368 hDevMode = pd->hDevMode;
369 m_devMode = (void*)(long) hDevMode;
370 pd->hDevMode = NULL;
371
372 // We'll create a new DEVNAMEs structure below.
c801d85f
KB
373 if ( pd->hDevNames )
374 GlobalFree(pd->hDevNames);
375 pd->hDevNames = NULL;
7bcb11d3 376
eaeb6a3c
JS
377 // hDevNames = pd->hDevNames;
378 // m_devNames = (void*)(long) hDevNames;
379 // pd->hDevnames = NULL;
380
c801d85f 381 }
c801d85f 382
7bcb11d3
JS
383 delete pd;
384 }
8826f46f 385
7bcb11d3 386 if ( hDevMode )
c801d85f 387 {
8f177c8e 388 LPDEVMODE devMode = (LPDEVMODE) GlobalLock(hDevMode);
8826f46f 389
7bcb11d3 390 //// Orientation
8826f46f 391
c455ab93 392#ifndef __WXWINE__
7bcb11d3 393 devMode->dmOrientation = m_printOrientation;
c455ab93 394#endif
c801d85f 395 devMode->dmFields = DM_ORIENTATION;
8826f46f 396
7bcb11d3 397 //// Collation
8826f46f 398
25889d3c 399#ifndef __WIN16__
7bcb11d3
JS
400 devMode->dmCollate = (m_printCollate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE);
401 devMode->dmFields |= DM_COLLATE;
25889d3c 402#endif
8826f46f 403
7bcb11d3 404 //// Number of copies
8826f46f 405
7bcb11d3
JS
406 devMode->dmCopies = m_printNoCopies;
407 devMode->dmFields |= DM_COPIES;
8826f46f 408
7bcb11d3 409 //// Printer name
8826f46f 410
223d09f6 411 if (m_printerName != wxT(""))
7bcb11d3
JS
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 }
8826f46f 420
7bcb11d3 421 //// Colour
8826f46f 422
7bcb11d3
JS
423 if (m_colour)
424 devMode->dmColor = DMCOLOR_COLOR;
425 else
426 devMode->dmColor = DMCOLOR_MONOCHROME;
8826f46f 427
7bcb11d3 428 devMode->dmFields |= DM_COLOR;
8826f46f 429
c455ab93 430#ifndef __WXWINE__
7bcb11d3 431 //// Paper size
8826f46f 432
7bcb11d3
JS
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 }
c455ab93 452#endif
8826f46f 453
7bcb11d3 454 //// Duplex
8826f46f 455
7bcb11d3
JS
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;
8826f46f 472
7bcb11d3 473 //// Quality
8826f46f 474
7bcb11d3
JS
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;
8826f46f 496
7bcb11d3 497 GlobalUnlock(hDevMode);
c801d85f 498 }
eaeb6a3c
JS
499
500 if ( hDevNames )
501 {
502 GlobalFree(hDevNames);
503 }
504
505 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
f6bcfd97 506 m_devNames = (void*) (long) wxCreateDevNames("", m_printerName, "");
7bcb11d3
JS
507}
508
509void wxPrintData::ConvertFromNative()
510{
48c12cb1 511 HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
eaeb6a3c 512 HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
7bcb11d3
JS
513
514 if (!hDevMode)
515 return;
516
517 if ( hDevMode )
518 {
8f177c8e 519 LPDEVMODE devMode = (LPDEVMODE)GlobalLock(hDevMode);
8826f46f 520
c455ab93 521#ifndef __WXWINE__
7bcb11d3 522 //// Orientation
8826f46f 523
7bcb11d3
JS
524 if (devMode->dmFields & DM_ORIENTATION)
525 m_printOrientation = devMode->dmOrientation;
c455ab93 526#endif
8826f46f 527
7bcb11d3 528 //// Collation
8826f46f 529
25889d3c 530#ifndef __WIN16__
7bcb11d3
JS
531 if (devMode->dmFields & DM_COLLATE)
532 {
533 if (devMode->dmCollate == DMCOLLATE_TRUE)
534 m_printCollate = TRUE;
535 else
536 m_printCollate = FALSE;
537 }
25889d3c 538#endif
8826f46f 539
7bcb11d3 540 //// Number of copies
8826f46f 541
7bcb11d3
JS
542 if (devMode->dmFields & DM_COPIES)
543 {
544 m_printNoCopies = devMode->dmCopies;
545 }
8826f46f 546
7bcb11d3 547 //// Printer name
8826f46f 548
7bcb11d3
JS
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;
8826f46f 560
7bcb11d3
JS
561 m_printerName = buf;
562 }
8826f46f 563
7bcb11d3 564 //// Colour
8826f46f 565
7bcb11d3
JS
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;
8826f46f 575
c455ab93 576#ifndef __WXWINE__
7bcb11d3 577 //// Paper size
8826f46f 578
7bcb11d3
JS
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
223d09f6 593 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
8826f46f 594
7bcb11d3
JS
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
223d09f6 603 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
8826f46f 604
7bcb11d3
JS
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
223d09f6 619 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
8826f46f 620
7bcb11d3
JS
621 m_paperSize.x = 0;
622 m_paperSize.y = 0;
623 m_paperId = wxPAPER_NONE;
624 }
c455ab93 625#endif
8826f46f 626
7bcb11d3 627 //// Duplex
8826f46f 628
7bcb11d3
JS
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;
8826f46f 647
7bcb11d3 648 //// Quality
8826f46f 649
7bcb11d3
JS
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;
8826f46f 672
7bcb11d3
JS
673 }
674 }
675 }
676 else
677 m_printQuality = wxPRINT_QUALITY_HIGH;
8826f46f 678
7bcb11d3
JS
679 GlobalUnlock(hDevMode);
680 }
eaeb6a3c
JS
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
f6bcfd97 699 if (printerName != wxT(""))
eaeb6a3c
JS
700 m_printerName = printerName;
701
702 GlobalUnlock(hDevNames);
703 }
704 }
7bcb11d3 705}
c801d85f 706
7bcb11d3
JS
707#endif
708
51abe921
SC
709#ifdef __WXMAC__
710void wxPrintData::ConvertToNative()
711{
7d610b90 712 (**m_macPrintInfo).prJob.iCopies = m_printNoCopies ;
51abe921
SC
713}
714
715void wxPrintData::ConvertFromNative()
716{
7d610b90 717 m_printNoCopies = (**m_macPrintInfo).prJob.iCopies ;
51abe921
SC
718}
719#endif
720
7bcb11d3
JS
721void wxPrintData::operator=(const wxPrintData& data)
722{
7d610b90
SC
723#ifdef __WXMAC__
724 m_macPrintInfo = data.m_macPrintInfo ;
725 HandToHand( (Handle*) &m_macPrintInfo ) ;
726#endif
7bcb11d3
JS
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
8826f46f 751#if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
7bcb11d3
JS
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}
8826f46f 774#endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
7bcb11d3 775
8826f46f
VZ
776
777// ----------------------------------------------------------------------------
778// Print dialog data
779// ----------------------------------------------------------------------------
7bcb11d3
JS
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;
5360828d 794 m_printSelection = FALSE;
7bcb11d3
JS
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{
7c74e7fe
SC
804#ifdef __WXMSW__
805 m_printDlgData = NULL;
7c74e7fe 806#endif
7bcb11d3
JS
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;
5360828d 823 m_printSelection = FALSE;
7bcb11d3
JS
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
7bcb11d3 860 pd->lStructSize = sizeof(PRINTDLG);
25889d3c 861#endif
7bcb11d3
JS
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
eaeb6a3c
JS
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
48c12cb1 884 pd->hDevMode = (HGLOBAL)(DWORD) m_printData.GetNativeData();
7bcb11d3
JS
885
886 m_printData.SetNativeData((void*) NULL);
887
223d09f6 888 wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
7bcb11d3 889
eaeb6a3c
JS
890 pd->hDevNames = (HGLOBAL)(DWORD) m_printData.GetNativeDataDevNames();
891
892 m_printData.SetNativeDataDevNames((void*) NULL);
893
7bcb11d3
JS
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;
8826f46f 900
c801d85f 901 pd->Flags = PD_RETURNDC ;
7bcb11d3
JS
902
903#ifdef __GNUWIN32__
c801d85f 904 pd->lStructSize = 66 ;
7bcb11d3
JS
905#else
906 pd->lStructSize = sizeof( PRINTDLG );
907#endif
908
8b9518ee 909 pd->hwndOwner=(HWND)NULL;
eaeb6a3c 910// pd->hDevNames=(HANDLE)NULL;
c801d85f
KB
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;
8826f46f 919
7bcb11d3 920 if ( m_printAllPages )
c801d85f 921 pd->Flags |= PD_ALLPAGES;
5360828d
JS
922 if ( m_printAllPages )
923 pd->Flags |= PD_SELECTION;
7bcb11d3 924 if ( m_printCollate )
c801d85f 925 pd->Flags |= PD_COLLATE;
7bcb11d3 926 if ( m_printToFile )
c801d85f 927 pd->Flags |= PD_PRINTTOFILE;
7bcb11d3 928 if ( !m_printEnablePrintToFile )
c801d85f 929 pd->Flags |= PD_DISABLEPRINTTOFILE;
7bcb11d3
JS
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;
c801d85f
KB
938}
939
7bcb11d3 940void wxPrintDialogData::ConvertFromNative()
c801d85f 941{
7bcb11d3 942 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
c801d85f
KB
943 if ( pd == NULL )
944 return;
945
7bcb11d3
JS
946 // Pass the devmode data back to the wxPrintData structure where it really belongs.
947 if (pd->hDevMode)
c801d85f 948 {
7bcb11d3
JS
949 if (m_printData.GetNativeData())
950 {
951 // Make sure we don't leak memory
48c12cb1 952 GlobalFree((HGLOBAL)(DWORD) m_printData.GetNativeData());
7bcb11d3 953 }
aeb50f86 954 m_printData.SetNativeData((void*)(long) pd->hDevMode);
7bcb11d3 955 pd->hDevMode = NULL;
c801d85f 956 }
c801d85f 957
eaeb6a3c
JS
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
7bcb11d3
JS
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 ;
8826f46f 979
7bcb11d3 980 m_printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES);
5360828d 981 m_printSelection = ((pd->Flags & PD_SELECTION) == PD_SELECTION);
7bcb11d3
JS
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);
8826f46f 999
7bcb11d3
JS
1000// wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
1001 }
1002 }
1003*/
c801d85f
KB
1004}
1005
7bcb11d3 1006void wxPrintDialogData::SetOwnerWindow(wxWindow* win)
c801d85f 1007{
7bcb11d3 1008 if ( m_printDlgData == NULL )
c801d85f 1009 ConvertToNative();
8826f46f 1010
7bcb11d3 1011 if ( m_printDlgData != NULL && win != NULL)
c801d85f 1012 {
7bcb11d3
JS
1013 PRINTDLG *pd = (PRINTDLG *) m_printDlgData ;
1014 pd->hwndOwner=(HWND) win->GetHWND();
c801d85f
KB
1015 }
1016}
8826f46f 1017#endif // MSW
c801d85f 1018
51abe921
SC
1019#ifdef __WXMAC__
1020void wxPrintDialogData::ConvertToNative()
1021{
7d610b90
SC
1022 (**m_printData.m_macPrintInfo).prJob.iFstPage = m_printFromPage ;
1023 (**m_printData.m_macPrintInfo).prJob.iLstPage = m_printToPage ;
1024 m_printData.ConvertToNative() ;
51abe921
SC
1025}
1026
1027void wxPrintDialogData::ConvertFromNative()
1028{
7d610b90
SC
1029 m_printData.ConvertFromNative() ;
1030 m_printFromPage = (**m_printData.m_macPrintInfo).prJob.iFstPage ;
1031 m_printToPage = (**m_printData.m_macPrintInfo).prJob.iLstPage ;
51abe921
SC
1032}
1033#endif
1034
1035
7bcb11d3 1036void wxPrintDialogData::operator=(const wxPrintDialogData& data)
c801d85f 1037{
7bcb11d3
JS
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;
5360828d 1046 m_printSelection = data.m_printSelection;
7bcb11d3
JS
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;
c801d85f
KB
1059}
1060
8826f46f
VZ
1061// ----------------------------------------------------------------------------
1062// wxPageSetupDialogData
1063// ----------------------------------------------------------------------------
c801d85f 1064
7bcb11d3 1065wxPageSetupDialogData::wxPageSetupDialogData()
c801d85f
KB
1066{
1067#if defined(__WIN95__)
7bcb11d3 1068 m_pageSetupData = NULL;
c801d85f 1069#endif
7bcb11d3
JS
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}
c801d85f 1088
7bcb11d3
JS
1089wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
1090{
7c74e7fe
SC
1091#if defined(__WIN95__)
1092 m_pageSetupData = NULL;
7c74e7fe 1093#endif
7bcb11d3
JS
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();
c801d85f
KB
1122}
1123
7bcb11d3 1124wxPageSetupDialogData::~wxPageSetupDialogData()
c801d85f 1125{
34138703 1126#if defined(__WIN95__) && defined(__WXMSW__)
c801d85f
KB
1127 PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData;
1128 if ( pd && pd->hDevMode )
1129 GlobalFree(pd->hDevMode);
eaeb6a3c
JS
1130 if ( pd && pd->hDevNames )
1131 GlobalFree(pd->hDevNames);
c801d85f
KB
1132 if ( pd )
1133 delete pd;
1134#endif
1135}
1136
7bcb11d3 1137void wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
c801d85f 1138{
7bcb11d3
JS
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}
c801d85f 1154
7bcb11d3
JS
1155void wxPageSetupDialogData::operator=(const wxPrintData& data)
1156{
1157 m_printData = data;
c801d85f
KB
1158}
1159
8826f46f 1160#if defined(__WIN95__)
7bcb11d3 1161void wxPageSetupDialogData::ConvertToNative()
c801d85f 1162{
7bcb11d3
JS
1163 m_printData.ConvertToNative();
1164
c801d85f 1165 PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData;
7bcb11d3 1166
c801d85f
KB
1167 if ( m_pageSetupData == NULL )
1168 {
7bcb11d3
JS
1169 pd = new PAGESETUPDLG;
1170 pd->hDevMode = NULL;
eaeb6a3c 1171 pd->hDevNames = NULL;
7bcb11d3 1172 m_pageSetupData = (void *)pd;
c801d85f 1173 }
8bbe427f 1174
7bcb11d3
JS
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
7bcb11d3
JS
1185 pd->hDevMode = (HGLOBAL) m_printData.GetNativeData();
1186
1187 m_printData.SetNativeData((void*) NULL);
1188
223d09f6 1189 wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
7bcb11d3 1190
eaeb6a3c
JS
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
7bcb11d3 1205// pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
c801d85f 1206
7bcb11d3 1207 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
8826f46f 1208
c801d85f
KB
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
7bcb11d3
JS
1224 // We want the units to be in hundredths of a millimetre
1225 pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1226
c801d85f 1227 pd->lStructSize = sizeof( PAGESETUPDLG );
c4e7c2aa 1228 pd->hwndOwner=(HWND)NULL;
eaeb6a3c 1229// pd->hDevNames=(HWND)NULL;
c801d85f 1230 pd->hInstance=(HINSTANCE)NULL;
8826f46f 1231
7bcb11d3
JS
1232 pd->ptPaperSize.x = m_paperSize.x * 100;
1233 pd->ptPaperSize.y = m_paperSize.y * 100;
8826f46f 1234
7bcb11d3
JS
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;
8826f46f 1239
7bcb11d3
JS
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;
8826f46f 1244
c801d85f
KB
1245 pd->lCustData = 0;
1246 pd->lpfnPageSetupHook = NULL;
1247 pd->lpfnPagePaintHook = NULL;
1248 pd->hPageSetupTemplate = NULL;
1249 pd->lpPageSetupTemplateName = NULL;
1250
8826f46f 1251/*
c801d85f
KB
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 }
7bcb11d3 1261*/
c801d85f
KB
1262}
1263
7bcb11d3 1264void wxPageSetupDialogData::ConvertFromNative()
c801d85f
KB
1265{
1266 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
1267 if ( !pd )
1268 return;
8826f46f 1269
7bcb11d3
JS
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 }
c801d85f 1281
7bcb11d3 1282 m_printData.ConvertFromNative();
c801d85f 1283
eaeb6a3c
JS
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
7bcb11d3 1298 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
8826f46f 1299
c801d85f
KB
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);
8826f46f 1307
7bcb11d3
JS
1308 m_paperSize.x = pd->ptPaperSize.x / 100;
1309 m_paperSize.y = pd->ptPaperSize.y / 100;
8826f46f 1310
7bcb11d3
JS
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;
8826f46f 1315
7bcb11d3
JS
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}
c801d85f 1321
7bcb11d3
JS
1322void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win)
1323{
1324 if ( m_pageSetupData == NULL )
1325 ConvertToNative();
8826f46f 1326
7bcb11d3
JS
1327 if ( m_pageSetupData != NULL && win != NULL)
1328 {
1329 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
1330 pd->hwndOwner=(HWND) win->GetHWND();
1331 }
1332}
8826f46f 1333#endif // Win95
c801d85f 1334
51abe921 1335#ifdef __WXMAC__
7c74e7fe 1336void wxPageSetupDialogData::ConvertToNative()
51abe921 1337{
7d610b90
SC
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 ) ;
51abe921
SC
1350}
1351
7c74e7fe 1352void wxPageSetupDialogData::ConvertFromNative()
51abe921 1353{
7d610b90
SC
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 ;
51abe921
SC
1379}
1380#endif
1381
1382
7bcb11d3
JS
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;
c801d85f 1388
7bcb11d3
JS
1389 CalculateIdFromPaperSize();
1390}
c801d85f 1391
7bcb11d3
JS
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();
c801d85f
KB
1398}
1399
7bcb11d3
JS
1400// Use paper size defined in this object to set the wxPrintData
1401// paper id
1402void wxPageSetupDialogData::CalculateIdFromPaperSize()
c801d85f 1403{
8826f46f 1404 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
fbdcff4a 1405 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
c801d85f 1406
7bcb11d3
JS
1407 wxSize sz = GetPaperSize();
1408
1409 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
1410 if (id != wxPAPER_NONE)
c801d85f 1411 {
7bcb11d3 1412 m_printData.SetPaperId(id);
c801d85f
KB
1413 }
1414}
8826f46f 1415
7bcb11d3
JS
1416// Use paper id in wxPrintData to set this object's paper size
1417void wxPageSetupDialogData::CalculatePaperSizeFromId()
1418{
8826f46f 1419 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
fbdcff4a 1420 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
7bcb11d3
JS
1421
1422 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
c801d85f 1423
7bcb11d3
JS
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}
8826f46f 1431
88ac883a 1432#endif // wxUSE_PRINTING_ARCHITECTURE