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