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