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