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