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