]> git.saurik.com Git - wxWidgets.git/blame - src/common/cmndata.cpp
Added geometry.cpp and made it compile,
[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 74
88ac883a
VZ
75 #if wxUSE_PRINTING_ARCHITECTURE
76 IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
77 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject)
78 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject)
79 #endif // wxUSE_PRINTING_ARCHITECTURE
cd0b1709 80
8826f46f
VZ
81 IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
82 IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
c801d85f 83
51abe921 84#ifdef __WXMAC__
cd0b1709
VZ
85 #define mm2pt 2.83464566929
86 #define pt2mm 0.352777777778
87#endif // Mac
51abe921 88
8826f46f
VZ
89// ============================================================================
90// implementation
91// ============================================================================
92
93// ----------------------------------------------------------------------------
94// wxColourData
95// ----------------------------------------------------------------------------
c801d85f 96
8bbe427f 97wxColourData::wxColourData()
c801d85f 98{
7bcb11d3
JS
99 int i;
100 for (i = 0; i < 16; i++)
101 custColours[i].Set(255, 255, 255);
8826f46f 102
7bcb11d3
JS
103 chooseFull = FALSE;
104 dataColour.Set(0,0,0);
105}
c801d85f 106
7bcb11d3
JS
107wxColourData::wxColourData(const wxColourData& data)
108{
109 (*this) = data;
8bbe427f 110}
c801d85f 111
8bbe427f 112wxColourData::~wxColourData()
c801d85f
KB
113{
114}
115
116void wxColourData::SetCustomColour(int i, wxColour& colour)
117{
7bcb11d3
JS
118 if (i > 15 || i < 0)
119 return;
8826f46f 120
7bcb11d3 121 custColours[i] = colour;
c801d85f
KB
122}
123
124wxColour wxColourData::GetCustomColour(int i)
125{
7bcb11d3
JS
126 if (i > 15 || i < 0)
127 return wxColour(0,0,0);
8826f46f 128
7bcb11d3 129 return custColours[i];
c801d85f
KB
130}
131
132void wxColourData::operator=(const wxColourData& data)
133{
7bcb11d3
JS
134 int i;
135 for (i = 0; i < 16; i++)
136 custColours[i] = data.custColours[i];
8826f46f 137
7bcb11d3
JS
138 dataColour = (wxColour&)data.dataColour;
139 chooseFull = data.chooseFull;
c801d85f
KB
140}
141
8826f46f
VZ
142// ----------------------------------------------------------------------------
143// Font data
144// ----------------------------------------------------------------------------
c801d85f 145
8bbe427f 146wxFontData::wxFontData()
c801d85f 147{
7bcb11d3
JS
148 // Intialize colour to black.
149 fontColour.Set(0, 0, 0);
8826f46f 150
7bcb11d3
JS
151 showHelp = FALSE;
152 allowSymbols = TRUE;
153 enableEffects = TRUE;
154 minSize = 0;
155 maxSize = 0;
c801d85f 156
7beba2fc 157 m_encoding = wxFONTENCODING_SYSTEM;
c801d85f
KB
158}
159
8bbe427f 160wxFontData::~wxFontData()
c801d85f
KB
161{
162}
163
88ac883a 164#if wxUSE_PRINTING_ARCHITECTURE
8826f46f
VZ
165// ----------------------------------------------------------------------------
166// Print data
167// ----------------------------------------------------------------------------
c801d85f 168
8bbe427f 169wxPrintData::wxPrintData()
c801d85f 170{
2049ba38 171#ifdef __WXMSW__
7bcb11d3 172 m_devMode = NULL;
51abe921 173#elif defined( __WXMAC__ )
cd0b1709 174 m_macPrintInfo = NULL ;
c801d85f 175#endif
7bcb11d3
JS
176 m_printOrientation = wxPORTRAIT;
177 m_printNoCopies = 1;
178 m_printCollate = FALSE;
8826f46f 179
7bcb11d3
JS
180 // New, 24/3/99
181 m_printerName = "";
182 m_colour = TRUE;
183 m_duplexMode = wxDUPLEX_SIMPLEX;
184 m_printQuality = wxPRINT_QUALITY_HIGH;
185 m_paperId = wxPAPER_A4;
186 m_paperSize = wxSize(210, 297);
187
188 // PostScript-specific data
189 m_printerCommand = "";
190 m_previewCommand = "";
191 m_printerOptions = "";
192 m_filename = "";
193 m_afmPath = "";
194 m_printerScaleX = 1.0;
195 m_printerScaleY = 1.0;
196 m_printerTranslateX = 0;
197 m_printerTranslateY = 0;
198 m_printMode = wxPRINT_MODE_FILE;
199}
200
201wxPrintData::wxPrintData(const wxPrintData& printData)
202{
58abfef6
JS
203#ifdef __WXMSW__
204 m_devMode = NULL;
7c74e7fe 205#elif defined( __WXMAC__ )
cd0b1709 206 m_macPrintInfo = NULL ;
58abfef6 207#endif
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 217#elif defined(__WXMAC__)
cd0b1709
VZ
218 if ( m_macPrintInfo )
219 ::DisposeHandle( (Handle) m_macPrintInfo ) ;
c801d85f
KB
220#endif
221}
222
25889d3c 223#if defined(__WXMSW__) // && defined(__WIN32__)
7bcb11d3 224
e47c4d48 225#if defined(__WXDEBUG__) && defined(__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 {
8f177c8e 318 LPDEVMODE devMode = (LPDEVMODE) 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 {
8f177c8e 440 LPDEVMODE devMode = (LPDEVMODE)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{
cd0b1709
VZ
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 }
51abe921
SC
624}
625
626void wxPrintData::ConvertFromNative()
627{
cd0b1709
VZ
628 if ( m_macPrintInfo )
629 {
630 m_printNoCopies = (**m_macPrintInfo).prJob.iCopies ;
631 }
51abe921
SC
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;
7c74e7fe 695#elif defined( __WXMAC__ )
cd0b1709 696 m_macPrintInfo = NULL ;
7bcb11d3
JS
697#endif
698 m_printFromPage = 0;
699 m_printToPage = 0;
700 m_printMinPage = 0;
701 m_printMaxPage = 0;
702 m_printNoCopies = 1;
703 m_printAllPages = FALSE;
704 m_printCollate = FALSE;
705 m_printToFile = FALSE;
5360828d 706 m_printSelection = FALSE;
7bcb11d3
JS
707 m_printEnableSelection = FALSE;
708 m_printEnablePageNumbers = TRUE;
709 m_printEnablePrintToFile = TRUE;
710 m_printEnableHelp = FALSE;
711 m_printSetupDialog = FALSE;
712}
713
714wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
715{
7c74e7fe
SC
716#ifdef __WXMSW__
717 m_printDlgData = NULL;
718#elif defined( __WXMAC__ )
cd0b1709 719 m_macPrintInfo = NULL ;
7c74e7fe 720#endif
7bcb11d3
JS
721 (*this) = dialogData;
722}
723
724wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
725{
726#ifdef __WXMSW__
727 m_printDlgData = NULL;
51abe921 728#elif defined( __WXMAC__ )
cd0b1709 729 m_macPrintInfo = NULL ;
7bcb11d3
JS
730#endif
731 m_printFromPage = 0;
732 m_printToPage = 0;
733 m_printMinPage = 0;
734 m_printMaxPage = 0;
735 m_printNoCopies = 1;
736 m_printAllPages = FALSE;
737 m_printCollate = FALSE;
738 m_printToFile = FALSE;
5360828d 739 m_printSelection = FALSE;
7bcb11d3
JS
740 m_printEnableSelection = FALSE;
741 m_printEnablePageNumbers = TRUE;
742 m_printEnablePrintToFile = TRUE;
743 m_printEnableHelp = FALSE;
744 m_printSetupDialog = FALSE;
745
746 m_printData = printData;
747}
748
749wxPrintDialogData::~wxPrintDialogData()
750{
751#ifdef __WXMSW__
752 PRINTDLG *pd = (PRINTDLG *) m_printDlgData;
753 if ( pd && pd->hDevMode )
754 GlobalFree(pd->hDevMode);
755 if ( pd )
756 delete pd;
51abe921 757#elif defined(__WXMAC__)
cd0b1709
VZ
758 if ( m_macPrintInfo )
759 ::DisposeHandle( (Handle) m_macPrintInfo ) ;
7bcb11d3
JS
760#endif
761}
762
763#ifdef __WXMSW__
764void wxPrintDialogData::ConvertToNative()
765{
766 m_printData.ConvertToNative();
767
768 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
769
770 if (!pd)
771 {
772 pd = new PRINTDLG;
773 m_printDlgData = (void*) pd;
774
775 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
776#ifdef __GNUWIN32__
777 pd->lStructSize = 66 ;
778#else
7bcb11d3 779 pd->lStructSize = sizeof(PRINTDLG);
25889d3c 780#endif
7bcb11d3
JS
781 pd->hwndOwner = (HWND)NULL;
782 pd->hDevMode = NULL; // Will be created by PrintDlg
783 pd->hDevNames = NULL; // Ditto
784
785 pd->Flags = PD_RETURNDEFAULT;
786 pd->nCopies = 1;
787 }
788
789 // Pass the devmode data to the PRINTDLG structure, since it'll
790 // be needed when PrintDlg is called.
791 if (pd->hDevMode)
792 {
793 GlobalFree(pd->hDevMode);
794 }
795
48c12cb1 796 pd->hDevMode = (HGLOBAL)(DWORD) m_printData.GetNativeData();
7bcb11d3
JS
797
798 m_printData.SetNativeData((void*) NULL);
799
223d09f6 800 wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
7bcb11d3
JS
801
802 pd->hDC = (HDC) NULL;
803 pd->nFromPage = (UINT)m_printFromPage;
804 pd->nToPage = (UINT)m_printToPage;
805 pd->nMinPage = (UINT)m_printMinPage;
806 pd->nMaxPage = (UINT)m_printMaxPage;
807 pd->nCopies = (UINT)m_printNoCopies;
8826f46f 808
c801d85f 809 pd->Flags = PD_RETURNDC ;
7bcb11d3
JS
810
811#ifdef __GNUWIN32__
c801d85f 812 pd->lStructSize = 66 ;
7bcb11d3
JS
813#else
814 pd->lStructSize = sizeof( PRINTDLG );
815#endif
816
8b9518ee 817 pd->hwndOwner=(HWND)NULL;
c801d85f
KB
818 pd->hDevNames=(HANDLE)NULL;
819 pd->hInstance=(HINSTANCE)NULL;
820 pd->lCustData = (LPARAM) NULL;
821 pd->lpfnPrintHook = NULL;
822 pd->lpfnSetupHook = NULL;
823 pd->lpPrintTemplateName = NULL;
824 pd->lpSetupTemplateName = NULL;
825 pd->hPrintTemplate = (HGLOBAL) NULL;
826 pd->hSetupTemplate = (HGLOBAL) NULL;
8826f46f 827
7bcb11d3 828 if ( m_printAllPages )
c801d85f 829 pd->Flags |= PD_ALLPAGES;
5360828d
JS
830 if ( m_printAllPages )
831 pd->Flags |= PD_SELECTION;
7bcb11d3 832 if ( m_printCollate )
c801d85f 833 pd->Flags |= PD_COLLATE;
7bcb11d3 834 if ( m_printToFile )
c801d85f 835 pd->Flags |= PD_PRINTTOFILE;
7bcb11d3 836 if ( !m_printEnablePrintToFile )
c801d85f 837 pd->Flags |= PD_DISABLEPRINTTOFILE;
7bcb11d3
JS
838 if ( !m_printEnableSelection )
839 pd->Flags |= PD_NOSELECTION;
840 if ( !m_printEnablePageNumbers )
841 pd->Flags |= PD_NOPAGENUMS;
842 if ( m_printEnableHelp )
843 pd->Flags |= PD_SHOWHELP;
844 if ( m_printSetupDialog )
845 pd->Flags |= PD_PRINTSETUP;
c801d85f
KB
846}
847
7bcb11d3 848void wxPrintDialogData::ConvertFromNative()
c801d85f 849{
7bcb11d3 850 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
c801d85f
KB
851 if ( pd == NULL )
852 return;
853
7bcb11d3
JS
854 // Pass the devmode data back to the wxPrintData structure where it really belongs.
855 if (pd->hDevMode)
c801d85f 856 {
7bcb11d3
JS
857 if (m_printData.GetNativeData())
858 {
859 // Make sure we don't leak memory
48c12cb1 860 GlobalFree((HGLOBAL)(DWORD) m_printData.GetNativeData());
7bcb11d3 861 }
aeb50f86 862 m_printData.SetNativeData((void*)(long) pd->hDevMode);
7bcb11d3 863 pd->hDevMode = NULL;
c801d85f 864 }
c801d85f 865
7bcb11d3
JS
866 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
867 // into wxWindows form.
868 m_printData.ConvertFromNative();
869
870 m_printFromPage = pd->nFromPage ;
871 m_printToPage = pd->nToPage ;
872 m_printMinPage = pd->nMinPage ;
873 m_printMaxPage = pd->nMaxPage ;
874 m_printNoCopies = pd->nCopies ;
8826f46f 875
7bcb11d3 876 m_printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES);
5360828d 877 m_printSelection = ((pd->Flags & PD_SELECTION) == PD_SELECTION);
7bcb11d3
JS
878 m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE);
879 m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE);
880 m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE);
881 m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION);
882 m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS);
883 m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP);
884 m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP);
885
886/* port is obsolete in WIN32
887 // Get the port name
888 if (pd->hDevNames)
889 {
890 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
891 if (lpDevNames) {
892 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
893 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
894 GlobalUnlock(pd->hDevNames);
8826f46f 895
7bcb11d3
JS
896// wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
897 }
898 }
899*/
c801d85f
KB
900}
901
7bcb11d3 902void wxPrintDialogData::SetOwnerWindow(wxWindow* win)
c801d85f 903{
7bcb11d3 904 if ( m_printDlgData == NULL )
c801d85f 905 ConvertToNative();
8826f46f 906
7bcb11d3 907 if ( m_printDlgData != NULL && win != NULL)
c801d85f 908 {
7bcb11d3
JS
909 PRINTDLG *pd = (PRINTDLG *) m_printDlgData ;
910 pd->hwndOwner=(HWND) win->GetHWND();
c801d85f
KB
911 }
912}
8826f46f 913#endif // MSW
c801d85f 914
51abe921
SC
915#ifdef __WXMAC__
916void wxPrintDialogData::ConvertToNative()
917{
cd0b1709
VZ
918 if ( !m_macPrintInfo )
919 {
920 m_macPrintInfo = (THPrint) NewHandleClear( sizeof( TPrint ) ) ;
921 if ( m_macPrintInfo )
922 {
923 ::PrintDefault( m_macPrintInfo ) ;
924 // todo setup the global pagesetup ?
925 }
926 }
927 if ( m_macPrintInfo )
928 {
929 (**m_macPrintInfo).prJob.iCopies = m_printNoCopies ;
930 (**m_macPrintInfo).prJob.iFstPage = m_printFromPage ;
931 (**m_macPrintInfo).prJob.iLstPage = m_printToPage ;
932 }
51abe921
SC
933}
934
935void wxPrintDialogData::ConvertFromNative()
936{
cd0b1709
VZ
937 if ( m_macPrintInfo )
938 {
939 m_printNoCopies = (**m_macPrintInfo).prJob.iCopies ;
940 m_printFromPage = (**m_macPrintInfo).prJob.iFstPage ;
941 m_printToPage = (**m_macPrintInfo).prJob.iLstPage ;
942 }
51abe921
SC
943}
944#endif
945
946
7bcb11d3 947void wxPrintDialogData::operator=(const wxPrintDialogData& data)
c801d85f 948{
7bcb11d3
JS
949 m_printFromPage = data.m_printFromPage;
950 m_printToPage = data.m_printToPage;
951 m_printMinPage = data.m_printMinPage;
952 m_printMaxPage = data.m_printMaxPage;
953 m_printNoCopies = data.m_printNoCopies;
954 m_printAllPages = data.m_printAllPages;
955 m_printCollate = data.m_printCollate;
956 m_printToFile = data.m_printToFile;
5360828d 957 m_printSelection = data.m_printSelection;
7bcb11d3
JS
958 m_printEnableSelection = data.m_printEnableSelection;
959 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
960 m_printEnableHelp = data.m_printEnableHelp;
961 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
962 m_printSetupDialog = data.m_printSetupDialog;
963
964 m_printData = data.m_printData;
965}
966
967void wxPrintDialogData::operator=(const wxPrintData& data)
968{
969 m_printData = data;
c801d85f
KB
970}
971
8826f46f
VZ
972// ----------------------------------------------------------------------------
973// wxPageSetupDialogData
974// ----------------------------------------------------------------------------
c801d85f 975
7bcb11d3 976wxPageSetupDialogData::wxPageSetupDialogData()
c801d85f
KB
977{
978#if defined(__WIN95__)
7bcb11d3 979 m_pageSetupData = NULL;
51abe921 980#elif defined( __WXMAC__ )
cd0b1709 981 m_macPageSetupInfo = NULL ;
c801d85f 982#endif
7bcb11d3
JS
983 m_paperSize = wxSize(0, 0);
984
985 CalculatePaperSizeFromId();
986
987 m_minMarginTopLeft = wxPoint(0, 0);
988 m_minMarginBottomRight = wxPoint(0, 0);
989 m_marginTopLeft = wxPoint(0, 0);
990 m_marginBottomRight = wxPoint(0, 0);
991
992 // Flags
993 m_defaultMinMargins = FALSE;
994 m_enableMargins = TRUE;
995 m_enableOrientation = TRUE;
996 m_enablePaper = TRUE;
997 m_enablePrinter = TRUE;
998 m_enableHelp = FALSE;
999 m_getDefaultInfo = FALSE;
1000}
c801d85f 1001
7bcb11d3
JS
1002wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
1003{
7c74e7fe
SC
1004#if defined(__WIN95__)
1005 m_pageSetupData = NULL;
1006#elif defined( __WXMAC__ )
cd0b1709 1007 m_macPageSetupInfo = NULL ;
7c74e7fe 1008#endif
7bcb11d3
JS
1009 (*this) = dialogData;
1010}
1011
1012wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
1013{
1014#if defined(__WIN95__)
1015 m_pageSetupData = NULL;
51abe921 1016#elif defined( __WXMAC__ )
cd0b1709 1017 m_macPageSetupInfo = NULL ;
7bcb11d3
JS
1018#endif
1019 m_paperSize = wxSize(0, 0);
1020 m_minMarginTopLeft = wxPoint(0, 0);
1021 m_minMarginBottomRight = wxPoint(0, 0);
1022 m_marginTopLeft = wxPoint(0, 0);
1023 m_marginBottomRight = wxPoint(0, 0);
1024
1025 // Flags
1026 m_defaultMinMargins = FALSE;
1027 m_enableMargins = TRUE;
1028 m_enableOrientation = TRUE;
1029 m_enablePaper = TRUE;
1030 m_enablePrinter = TRUE;
1031 m_enableHelp = FALSE;
1032 m_getDefaultInfo = FALSE;
1033
1034 m_printData = printData;
1035
1036 // The wxPrintData paper size overrides these values, unless the size cannot
1037 // be found.
1038 CalculatePaperSizeFromId();
c801d85f
KB
1039}
1040
7bcb11d3 1041wxPageSetupDialogData::~wxPageSetupDialogData()
c801d85f 1042{
34138703 1043#if defined(__WIN95__) && defined(__WXMSW__)
c801d85f
KB
1044 PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData;
1045 if ( pd && pd->hDevMode )
1046 GlobalFree(pd->hDevMode);
1047 if ( pd )
1048 delete pd;
51abe921 1049#elif defined( __WXMAC__ )
cd0b1709
VZ
1050 if( m_macPageSetupInfo )
1051 ::DisposeHandle( (Handle) m_macPageSetupInfo ) ;
c801d85f
KB
1052#endif
1053}
1054
7bcb11d3 1055void wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
c801d85f 1056{
7bcb11d3
JS
1057 m_paperSize = data.m_paperSize;
1058 m_minMarginTopLeft = data.m_minMarginTopLeft;
1059 m_minMarginBottomRight = data.m_minMarginBottomRight;
1060 m_marginTopLeft = data.m_marginTopLeft;
1061 m_marginBottomRight = data.m_marginBottomRight;
1062 m_defaultMinMargins = data.m_defaultMinMargins;
1063 m_enableMargins = data.m_enableMargins;
1064 m_enableOrientation = data.m_enableOrientation;
1065 m_enablePaper = data.m_enablePaper;
1066 m_enablePrinter = data.m_enablePrinter;
1067 m_getDefaultInfo = data.m_getDefaultInfo;;
1068 m_enableHelp = data.m_enableHelp;
1069
1070 m_printData = data.m_printData;
1071}
c801d85f 1072
7bcb11d3
JS
1073void wxPageSetupDialogData::operator=(const wxPrintData& data)
1074{
1075 m_printData = data;
c801d85f
KB
1076}
1077
8826f46f 1078#if defined(__WIN95__)
7bcb11d3 1079void wxPageSetupDialogData::ConvertToNative()
c801d85f 1080{
7bcb11d3
JS
1081 m_printData.ConvertToNative();
1082
c801d85f 1083 PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData;
7bcb11d3 1084
c801d85f
KB
1085 if ( m_pageSetupData == NULL )
1086 {
7bcb11d3
JS
1087 pd = new PAGESETUPDLG;
1088 pd->hDevMode = NULL;
1089 m_pageSetupData = (void *)pd;
c801d85f 1090 }
8bbe427f 1091
7bcb11d3
JS
1092 // Pass the devmode data (created in m_printData.ConvertToNative)
1093 // to the PRINTDLG structure, since it'll
1094 // be needed when PrintDlg is called.
1095
1096 if (pd->hDevMode)
1097 {
1098 GlobalFree(pd->hDevMode);
1099 pd->hDevMode = NULL;
1100 }
1101
7bcb11d3
JS
1102 pd->hDevMode = (HGLOBAL) m_printData.GetNativeData();
1103
1104 m_printData.SetNativeData((void*) NULL);
1105
223d09f6 1106 wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
7bcb11d3
JS
1107
1108// pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
c801d85f 1109
7bcb11d3 1110 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
8826f46f 1111
c801d85f
KB
1112 if ( m_defaultMinMargins )
1113 pd->Flags |= PSD_DEFAULTMINMARGINS;
1114 if ( !m_enableMargins )
1115 pd->Flags |= PSD_DISABLEMARGINS;
1116 if ( !m_enableOrientation )
1117 pd->Flags |= PSD_DISABLEORIENTATION;
1118 if ( !m_enablePaper )
1119 pd->Flags |= PSD_DISABLEPAPER;
1120 if ( !m_enablePrinter )
1121 pd->Flags |= PSD_DISABLEPRINTER;
1122 if ( m_getDefaultInfo )
1123 pd->Flags |= PSD_RETURNDEFAULT;
1124 if ( m_enableHelp )
1125 pd->Flags |= PSD_SHOWHELP;
1126
7bcb11d3
JS
1127 // We want the units to be in hundredths of a millimetre
1128 pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1129
c801d85f 1130 pd->lStructSize = sizeof( PAGESETUPDLG );
c4e7c2aa 1131 pd->hwndOwner=(HWND)NULL;
c801d85f
KB
1132 pd->hDevNames=(HWND)NULL;
1133 pd->hInstance=(HINSTANCE)NULL;
8826f46f 1134
7bcb11d3
JS
1135 pd->ptPaperSize.x = m_paperSize.x * 100;
1136 pd->ptPaperSize.y = m_paperSize.y * 100;
8826f46f 1137
7bcb11d3
JS
1138 pd->rtMinMargin.left = m_minMarginTopLeft.x * 100;
1139 pd->rtMinMargin.top = m_minMarginTopLeft.y * 100;
1140 pd->rtMinMargin.right = m_minMarginBottomRight.x * 100;
1141 pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100;
8826f46f 1142
7bcb11d3
JS
1143 pd->rtMargin.left = m_marginTopLeft.x * 100;
1144 pd->rtMargin.top = m_marginTopLeft.y * 100;
1145 pd->rtMargin.right = m_marginBottomRight.x * 100;
1146 pd->rtMargin.bottom = m_marginBottomRight.y * 100;
8826f46f 1147
c801d85f
KB
1148 pd->lCustData = 0;
1149 pd->lpfnPageSetupHook = NULL;
1150 pd->lpfnPagePaintHook = NULL;
1151 pd->hPageSetupTemplate = NULL;
1152 pd->lpPageSetupTemplateName = NULL;
1153
8826f46f 1154/*
c801d85f
KB
1155 if ( pd->hDevMode )
1156 {
1157 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1158 memset(devMode, 0, sizeof(DEVMODE));
1159 devMode->dmSize = sizeof(DEVMODE);
1160 devMode->dmOrientation = m_orientation;
1161 devMode->dmFields = DM_ORIENTATION;
1162 GlobalUnlock(pd->hDevMode);
1163 }
7bcb11d3 1164*/
c801d85f
KB
1165}
1166
7bcb11d3 1167void wxPageSetupDialogData::ConvertFromNative()
c801d85f
KB
1168{
1169 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
1170 if ( !pd )
1171 return;
8826f46f 1172
7bcb11d3
JS
1173 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1174 if (pd->hDevMode)
1175 {
1176 if (m_printData.GetNativeData())
1177 {
1178 // Make sure we don't leak memory
1179 GlobalFree((HGLOBAL) m_printData.GetNativeData());
1180 }
1181 m_printData.SetNativeData((void*) pd->hDevMode);
1182 pd->hDevMode = NULL;
1183 }
c801d85f 1184
7bcb11d3 1185 m_printData.ConvertFromNative();
c801d85f 1186
7bcb11d3 1187 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
8826f46f 1188
c801d85f
KB
1189 m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS);
1190 m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS);
1191 m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION);
1192 m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER);
1193 m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER);
1194 m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT);
1195 m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP);
8826f46f 1196
7bcb11d3
JS
1197 m_paperSize.x = pd->ptPaperSize.x / 100;
1198 m_paperSize.y = pd->ptPaperSize.y / 100;
8826f46f 1199
7bcb11d3
JS
1200 m_minMarginTopLeft.x = pd->rtMinMargin.left / 100;
1201 m_minMarginTopLeft.y = pd->rtMinMargin.top / 100;
1202 m_minMarginBottomRight.x = pd->rtMinMargin.right / 100;
1203 m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100;
8826f46f 1204
7bcb11d3
JS
1205 m_marginTopLeft.x = pd->rtMargin.left / 100 ;
1206 m_marginTopLeft.y = pd->rtMargin.top / 100 ;
1207 m_marginBottomRight.x = pd->rtMargin.right / 100 ;
1208 m_marginBottomRight.y = pd->rtMargin.bottom / 100 ;
1209}
c801d85f 1210
7bcb11d3
JS
1211void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win)
1212{
1213 if ( m_pageSetupData == NULL )
1214 ConvertToNative();
8826f46f 1215
7bcb11d3
JS
1216 if ( m_pageSetupData != NULL && win != NULL)
1217 {
1218 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
1219 pd->hwndOwner=(HWND) win->GetHWND();
1220 }
1221}
8826f46f 1222#endif // Win95
c801d85f 1223
51abe921 1224#ifdef __WXMAC__
7c74e7fe 1225void wxPageSetupDialogData::ConvertToNative()
51abe921 1226{
cd0b1709
VZ
1227 if ( !m_macPageSetupInfo )
1228 {
1229 m_macPageSetupInfo = (THPrint) NewHandleClear( sizeof( TPrint ) ) ;
1230 if ( m_macPageSetupInfo )
1231 {
1232 ::PrintDefault( m_macPageSetupInfo ) ;
1233 }
1234 }
1235 if ( m_macPageSetupInfo )
1236 {
1237 // on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0
1238 (**m_macPageSetupInfo).rPaper.left = int( ((double) m_minMarginTopLeft.x)*mm2pt ) ;
1239 (**m_macPageSetupInfo).rPaper.top = int( ((double) m_minMarginTopLeft.y)*mm2pt ) ;
1240
1241 (**m_macPageSetupInfo).rPaper.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x)*mm2pt ) ;
1242 (**m_macPageSetupInfo).rPaper.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y)*mm2pt ) ;
1243
1244 (**m_macPageSetupInfo).prInfo.rPage.left = 0 ;
1245 (**m_macPageSetupInfo).prInfo.rPage.top = 0 ;
1246 (**m_macPageSetupInfo).prInfo.rPage.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x - m_minMarginBottomRight.x)*mm2pt ) ;
1247 (**m_macPageSetupInfo).prInfo.rPage.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y - m_minMarginBottomRight.y)*mm2pt ) ;
1248
1249 //TODO add custom fields in dialog for margins
1250
1251 }
51abe921
SC
1252}
1253
7c74e7fe 1254void wxPageSetupDialogData::ConvertFromNative()
51abe921 1255{
cd0b1709
VZ
1256 if ( m_macPageSetupInfo )
1257 {
1258 m_paperSize.x = ((double) (**m_macPageSetupInfo).rPaper.right - (**m_macPageSetupInfo).rPaper.left ) * pt2mm ;
1259 m_paperSize.y = ((double) (**m_macPageSetupInfo).rPaper.bottom - (**m_macPageSetupInfo).rPaper.top ) * pt2mm ;
1260
1261 m_minMarginTopLeft.x = ((double) -(**m_macPageSetupInfo).rPaper.left ) * pt2mm ;
1262 m_minMarginTopLeft.y = ((double) -(**m_macPageSetupInfo).rPaper.top ) * pt2mm ;
1263
1264 m_minMarginBottomRight.x = ((double) (**m_macPageSetupInfo).rPaper.right - (**m_macPageSetupInfo).prInfo.rPage.right ) * pt2mm ;
1265 m_minMarginBottomRight.y = ((double)(**m_macPageSetupInfo).rPaper.bottom - (**m_macPageSetupInfo).prInfo.rPage.bottom ) * pt2mm ;
1266
1267 // adjust minimal values
1268 //TODO add custom fields in dialog for margins
1269
1270 if ( m_marginTopLeft.x < m_minMarginTopLeft.x )
1271 m_marginTopLeft.x = m_minMarginTopLeft.x ;
1272
1273 if ( m_marginBottomRight.x < m_minMarginBottomRight.x )
1274 m_marginBottomRight.x = m_minMarginBottomRight.x ;
1275
1276 if ( m_marginTopLeft.y < m_minMarginTopLeft.y )
1277 m_marginTopLeft.y = m_minMarginTopLeft.y ;
1278
1279 if ( m_marginBottomRight.y < m_minMarginBottomRight.y )
1280 m_marginBottomRight.y = m_minMarginBottomRight.y ;
1281
1282 }
51abe921
SC
1283}
1284#endif
1285
1286
7bcb11d3
JS
1287// If a corresponding paper type is found in the paper database, will set the m_printData
1288// paper size id member as well.
1289void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
1290{
1291 m_paperSize = sz;
c801d85f 1292
7bcb11d3
JS
1293 CalculateIdFromPaperSize();
1294}
c801d85f 1295
7bcb11d3
JS
1296// Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1297void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
1298{
1299 m_printData.SetPaperId(id);
1300
1301 CalculatePaperSizeFromId();
c801d85f
KB
1302}
1303
7bcb11d3
JS
1304// Use paper size defined in this object to set the wxPrintData
1305// paper id
1306void wxPageSetupDialogData::CalculateIdFromPaperSize()
c801d85f 1307{
8826f46f 1308 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
223d09f6 1309 wxT("wxThePrintPaperDatabase should not be NULL. "
60df2e7d 1310 "Do not create global print dialog data objects.") );
c801d85f 1311
7bcb11d3
JS
1312 wxSize sz = GetPaperSize();
1313
1314 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
1315 if (id != wxPAPER_NONE)
c801d85f 1316 {
7bcb11d3 1317 m_printData.SetPaperId(id);
c801d85f
KB
1318 }
1319}
8826f46f 1320
7bcb11d3
JS
1321// Use paper id in wxPrintData to set this object's paper size
1322void wxPageSetupDialogData::CalculatePaperSizeFromId()
1323{
8826f46f 1324 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
223d09f6 1325 wxT("wxThePrintPaperDatabase should not be NULL. "
60df2e7d 1326 "Do not create global print dialog data objects.") );
7bcb11d3
JS
1327
1328 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
c801d85f 1329
7bcb11d3
JS
1330 if (sz.x != 0)
1331 {
1332 // sz is in 10ths of a mm, so multiply by 10.
1333 m_paperSize.x = sz.x * 10;
1334 m_paperSize.y = sz.y * 10;
1335 }
1336}
8826f46f 1337
88ac883a 1338#endif // wxUSE_PRINTING_ARCHITECTURE