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