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