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