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