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