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