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