]> git.saurik.com Git - wxWidgets.git/blame - src/common/cmndata.cpp
virtualized m_row/col height/widths arrays
[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__
eaeb6a3c
JS
172 m_devMode = (void*) NULL;
173 m_devNames = (void*) NULL;
51abe921 174#elif defined( __WXMAC__ )
cd0b1709 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 204#ifdef __WXMSW__
eaeb6a3c
JS
205 m_devMode = (void*) NULL;
206 m_devNames = (void*) NULL;
7c74e7fe 207#elif defined( __WXMAC__ )
cd0b1709 208 m_macPrintInfo = NULL ;
58abfef6 209#endif
7bcb11d3 210 (*this) = printData;
c801d85f
KB
211}
212
8bbe427f 213wxPrintData::~wxPrintData()
c801d85f 214{
2049ba38 215#ifdef __WXMSW__
48c12cb1 216 HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
eaeb6a3c 217 if ( hDevMode )
7bcb11d3 218 GlobalFree(hDevMode);
eaeb6a3c
JS
219 HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
220 if ( hDevNames )
221 GlobalFree(hDevNames);
51abe921 222#elif defined(__WXMAC__)
cd0b1709
VZ
223 if ( m_macPrintInfo )
224 ::DisposeHandle( (Handle) m_macPrintInfo ) ;
c801d85f
KB
225#endif
226}
227
25889d3c 228#if defined(__WXMSW__) // && defined(__WIN32__)
7bcb11d3 229
e47c4d48 230#if defined(__WXDEBUG__) && defined(__WIN32__)
6aa55ce7
JS
231static wxString wxGetPrintDlgError()
232{
233 DWORD err = CommDlgExtendedError();
223d09f6 234 wxString msg = wxT("Unknown");
6aa55ce7
JS
235 switch (err)
236 {
223d09f6
KB
237 case CDERR_FINDRESFAILURE: msg = wxT("CDERR_FINDRESFAILURE"); break;
238 case CDERR_INITIALIZATION: msg = wxT("CDERR_INITIALIZATION"); break;
239 case CDERR_LOADRESFAILURE: msg = wxT("CDERR_LOADRESFAILURE"); break;
240 case CDERR_LOADSTRFAILURE: msg = wxT("CDERR_LOADSTRFAILURE"); break;
241 case CDERR_LOCKRESFAILURE: msg = wxT("CDERR_LOCKRESFAILURE"); break;
242 case CDERR_MEMALLOCFAILURE: msg = wxT("CDERR_MEMALLOCFAILURE"); break;
243 case CDERR_MEMLOCKFAILURE: msg = wxT("CDERR_MEMLOCKFAILURE"); break;
244 case CDERR_NOHINSTANCE: msg = wxT("CDERR_NOHINSTANCE"); break;
245 case CDERR_NOHOOK: msg = wxT("CDERR_NOHOOK"); break;
246 case CDERR_NOTEMPLATE: msg = wxT("CDERR_NOTEMPLATE"); break;
247 case CDERR_STRUCTSIZE: msg = wxT("CDERR_STRUCTSIZE"); break;
248 case PDERR_RETDEFFAILURE: msg = wxT("PDERR_RETDEFFAILURE"); break;
249 case PDERR_PRINTERNOTFOUND: msg = wxT("PDERR_PRINTERNOTFOUND"); break;
250 case PDERR_PARSEFAILURE: msg = wxT("PDERR_PARSEFAILURE"); break;
251 case PDERR_NODEVICES: msg = wxT("PDERR_NODEVICES"); break;
252 case PDERR_NODEFAULTPRN: msg = wxT("PDERR_NODEFAULTPRN"); break;
253 case PDERR_LOADDRVFAILURE: msg = wxT("PDERR_LOADDRVFAILURE"); break;
254 case PDERR_INITFAILURE: msg = wxT("PDERR_INITFAILURE"); break;
255 case PDERR_GETDEVMODEFAIL: msg = wxT("PDERR_GETDEVMODEFAIL"); break;
256 case PDERR_DNDMMISMATCH: msg = wxT("PDERR_DNDMMISMATCH"); break;
257 case PDERR_DEFAULTDIFFERENT: msg = wxT("PDERR_DEFAULTDIFFERENT"); break;
258 case PDERR_CREATEICFAILURE: msg = wxT("PDERR_CREATEICFAILURE"); break;
6aa55ce7
JS
259 default: break;
260 }
261 return msg;
262}
25889d3c 263#endif
6aa55ce7 264
eaeb6a3c
JS
265static HGLOBAL wxCreateDevNames(const wxString& driverName, const wxString& printerName, const wxString& portName)
266{
267 HGLOBAL hDev = NULL;
268 // if (!driverName.IsEmpty() && !printerName.IsEmpty() && !portName.IsEmpty())
269 if (driverName.IsEmpty() && printerName.IsEmpty() && portName.IsEmpty())
270 {
271 }
272 else
273 {
274 hDev = GlobalAlloc(GPTR, 4*sizeof(WORD)+
275 driverName.Length() + 1 +
276 printerName.Length() + 1 +
277 portName.Length()+1);
278 LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(hDev);
279 lpDev->wDriverOffset = sizeof(WORD)*4;
280 wxStrcpy((wxChar*)lpDev + lpDev->wDriverOffset, driverName);
281
282 lpDev->wDeviceOffset = (WORD)(lpDev->wDriverOffset + driverName.Length()+1);
283 wxStrcpy((wxChar*)lpDev + lpDev->wDeviceOffset, printerName);
284
285 lpDev->wOutputOffset = (WORD)(lpDev->wDeviceOffset + printerName.Length()+1);
286 wxStrcpy((wxChar*)lpDev + lpDev->wOutputOffset, portName);
287
288 lpDev->wDefault = 0;
289
290 GlobalUnlock(hDev);
291 }
292 return hDev;
293}
294
8bbe427f 295void wxPrintData::ConvertToNative()
c801d85f 296{
48c12cb1 297 HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
eaeb6a3c 298 HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
7bcb11d3 299 if (!hDevMode)
c801d85f 300 {
7bcb11d3
JS
301 // Use PRINTDLG as a way of creating a DEVMODE object
302 PRINTDLG *pd = new PRINTDLG;
8826f46f 303
c801d85f 304 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
7bcb11d3 305#ifdef __GNUWIN32__
6aa55ce7 306 memset(pd, 0, 66);
c801d85f 307 pd->lStructSize = 66 ;
7bcb11d3 308#else
7bcb11d3 309 memset(pd, 0, sizeof(PRINTDLG));
6aa55ce7 310 pd->lStructSize = sizeof(PRINTDLG);
7bcb11d3
JS
311#endif
312
c801d85f
KB
313 pd->hwndOwner = (HWND)NULL;
314 pd->hDevMode = NULL; // Will be created by PrintDlg
315 pd->hDevNames = NULL; // Ditto
6aa55ce7 316 pd->hInstance = (HINSTANCE) wxGetInstance();
8826f46f 317
c801d85f
KB
318 pd->Flags = PD_RETURNDEFAULT;
319 pd->nCopies = 1;
8826f46f 320
c801d85f
KB
321 // Fill out the DEVMODE structure
322 // so we can use it as input in the 'real' PrintDlg
323 if (!PrintDlg(pd))
324 {
325 if ( pd->hDevMode )
326 GlobalFree(pd->hDevMode);
327 if ( pd->hDevNames )
328 GlobalFree(pd->hDevNames);
329 pd->hDevMode = NULL;
330 pd->hDevNames = NULL;
58a33cb4
JS
331
332#if defined(__WXDEBUG__) && defined(__WIN32__)
223d09f6 333 wxString str(wxT("Printing error: "));
6aa55ce7
JS
334 str += wxGetPrintDlgError();
335 wxLogDebug(str);
336#endif
c801d85f
KB
337 }
338 else
339 {
eaeb6a3c
JS
340 hDevMode = pd->hDevMode;
341 m_devMode = (void*)(long) hDevMode;
342 pd->hDevMode = NULL;
343
344 // We'll create a new DEVNAMEs structure below.
c801d85f
KB
345 if ( pd->hDevNames )
346 GlobalFree(pd->hDevNames);
347 pd->hDevNames = NULL;
7bcb11d3 348
eaeb6a3c
JS
349 // hDevNames = pd->hDevNames;
350 // m_devNames = (void*)(long) hDevNames;
351 // pd->hDevnames = NULL;
352
c801d85f 353 }
c801d85f 354
7bcb11d3
JS
355 delete pd;
356 }
8826f46f 357
7bcb11d3 358 if ( hDevMode )
c801d85f 359 {
8f177c8e 360 LPDEVMODE devMode = (LPDEVMODE) GlobalLock(hDevMode);
8826f46f 361
7bcb11d3 362 //// Orientation
8826f46f 363
c455ab93 364#ifndef __WXWINE__
7bcb11d3 365 devMode->dmOrientation = m_printOrientation;
c455ab93 366#endif
c801d85f 367 devMode->dmFields = DM_ORIENTATION;
8826f46f 368
7bcb11d3 369 //// Collation
8826f46f 370
25889d3c 371#ifndef __WIN16__
7bcb11d3
JS
372 devMode->dmCollate = (m_printCollate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE);
373 devMode->dmFields |= DM_COLLATE;
25889d3c 374#endif
8826f46f 375
7bcb11d3 376 //// Number of copies
8826f46f 377
7bcb11d3
JS
378 devMode->dmCopies = m_printNoCopies;
379 devMode->dmFields |= DM_COPIES;
8826f46f 380
7bcb11d3 381 //// Printer name
8826f46f 382
223d09f6 383 if (m_printerName != wxT(""))
7bcb11d3
JS
384 {
385 // TODO: make this Unicode compatible
386 int len = wxMin(31, m_printerName.Len());
387 int i;
388 for (i = 0; i < len; i++)
389 devMode->dmDeviceName[i] = m_printerName.GetChar(i);
390 devMode->dmDeviceName[i] = 0;
391 }
8826f46f 392
7bcb11d3 393 //// Colour
8826f46f 394
7bcb11d3
JS
395 if (m_colour)
396 devMode->dmColor = DMCOLOR_COLOR;
397 else
398 devMode->dmColor = DMCOLOR_MONOCHROME;
8826f46f 399
7bcb11d3 400 devMode->dmFields |= DM_COLOR;
8826f46f 401
c455ab93 402#ifndef __WXWINE__
7bcb11d3 403 //// Paper size
8826f46f 404
7bcb11d3
JS
405 if (m_paperId == wxPAPER_NONE)
406 {
407 devMode->dmPaperWidth = m_paperSize.x * 10;
408 devMode->dmPaperLength = m_paperSize.y * 10;
409 devMode->dmFields |= DM_PAPERWIDTH;
410 devMode->dmFields |= DM_PAPERLENGTH;
411 }
412 else
413 {
414 if (wxThePrintPaperDatabase)
415 {
416 wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType(m_paperId);
417 if (paper)
418 {
419 devMode->dmPaperSize = paper->GetPlatformId();
420 devMode->dmFields |= DM_PAPERSIZE;
421 }
422 }
423 }
c455ab93 424#endif
8826f46f 425
7bcb11d3 426 //// Duplex
8826f46f 427
7bcb11d3
JS
428 int duplex;
429 switch (m_duplexMode)
430 {
431 case wxDUPLEX_HORIZONTAL: {
432 duplex = DMDUP_HORIZONTAL; break;
433 }
434 case wxDUPLEX_VERTICAL: {
435 duplex = DMDUP_VERTICAL; break;
436 }
437 default:
438 case wxDUPLEX_SIMPLEX: {
439 duplex = DMDUP_SIMPLEX; break;
440 }
441 }
442 devMode->dmDuplex = duplex;
443 devMode->dmFields |= DM_DUPLEX;
8826f46f 444
7bcb11d3 445 //// Quality
8826f46f 446
7bcb11d3
JS
447 int quality;
448 switch (m_printQuality)
449 {
450 case wxPRINT_QUALITY_MEDIUM: {
451 quality = DMRES_MEDIUM; break;
452 }
453 case wxPRINT_QUALITY_LOW: {
454 quality = DMRES_LOW; break;
455 }
456 case wxPRINT_QUALITY_DRAFT: {
457 quality = DMRES_DRAFT; break;
458 }
459 case wxPRINT_QUALITY_HIGH: {
460 quality = DMRES_HIGH; break;
461 }
462 default: {
463 quality = m_printQuality; break;
464 }
465 }
466 devMode->dmPrintQuality = quality;
467 devMode->dmFields |= DM_PRINTQUALITY;
8826f46f 468
7bcb11d3 469 GlobalUnlock(hDevMode);
c801d85f 470 }
eaeb6a3c
JS
471
472 if ( hDevNames )
473 {
474 GlobalFree(hDevNames);
475 }
476
477 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
478 hDevNames = wxCreateDevNames("", m_printerName, "");
7bcb11d3
JS
479}
480
481void wxPrintData::ConvertFromNative()
482{
48c12cb1 483 HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
eaeb6a3c 484 HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
7bcb11d3
JS
485
486 if (!hDevMode)
487 return;
488
489 if ( hDevMode )
490 {
8f177c8e 491 LPDEVMODE devMode = (LPDEVMODE)GlobalLock(hDevMode);
8826f46f 492
c455ab93 493#ifndef __WXWINE__
7bcb11d3 494 //// Orientation
8826f46f 495
7bcb11d3
JS
496 if (devMode->dmFields & DM_ORIENTATION)
497 m_printOrientation = devMode->dmOrientation;
c455ab93 498#endif
8826f46f 499
7bcb11d3 500 //// Collation
8826f46f 501
25889d3c 502#ifndef __WIN16__
7bcb11d3
JS
503 if (devMode->dmFields & DM_COLLATE)
504 {
505 if (devMode->dmCollate == DMCOLLATE_TRUE)
506 m_printCollate = TRUE;
507 else
508 m_printCollate = FALSE;
509 }
25889d3c 510#endif
8826f46f 511
7bcb11d3 512 //// Number of copies
8826f46f 513
7bcb11d3
JS
514 if (devMode->dmFields & DM_COPIES)
515 {
516 m_printNoCopies = devMode->dmCopies;
517 }
8826f46f 518
7bcb11d3 519 //// Printer name
8826f46f 520
7bcb11d3
JS
521 if (devMode->dmDeviceName[0] != 0)
522 {
523 // TODO: make this Unicode compatible
524 char buf[32];
525 int i = 0;
526 while (devMode->dmDeviceName[i] != 0)
527 {
528 buf[i] = devMode->dmDeviceName[i];
529 i ++;
530 }
531 buf[i] = 0;
8826f46f 532
7bcb11d3
JS
533 m_printerName = buf;
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
c455ab93 548#ifndef __WXWINE__
7bcb11d3 549 //// Paper size
8826f46f 550
7bcb11d3
JS
551 if (devMode->dmFields & DM_PAPERSIZE)
552 {
553 if (wxThePrintPaperDatabase)
554 {
555 wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize);
556 if (paper)
557 {
558 m_paperId = paper->GetId();
559 m_paperSize.x = paper->GetWidth() / 10 ;
560 m_paperSize.y = paper->GetHeight() / 10 ;
561 }
562 else
563 {
564 // Shouldn't really get here
223d09f6 565 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
8826f46f 566
7bcb11d3
JS
567 m_paperId = wxPAPER_NONE;
568 m_paperSize.x = 0;
569 m_paperSize.y = 0;
570 }
571 }
572 else
573 {
574 // Shouldn't really get here
223d09f6 575 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
8826f46f 576
7bcb11d3
JS
577 m_paperId = wxPAPER_NONE;
578 m_paperSize.x = 0;
579 m_paperSize.y = 0;
580 }
581 }
582 else if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH))
583 {
584 m_paperSize.x = devMode->dmPaperWidth / 10;
585 m_paperSize.y = devMode->dmPaperLength / 10;
586 m_paperId = wxPAPER_NONE;
587 }
588 else
589 {
590 // Shouldn't really get here
223d09f6 591 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
8826f46f 592
7bcb11d3
JS
593 m_paperSize.x = 0;
594 m_paperSize.y = 0;
595 m_paperId = wxPAPER_NONE;
596 }
c455ab93 597#endif
8826f46f 598
7bcb11d3 599 //// Duplex
8826f46f 600
7bcb11d3
JS
601 if (devMode->dmFields & DM_DUPLEX)
602 {
603 switch (devMode->dmDuplex)
604 {
605 case DMDUP_HORIZONTAL: {
606 m_duplexMode = wxDUPLEX_HORIZONTAL; break;
607 }
608 case DMDUP_VERTICAL: {
609 m_duplexMode = wxDUPLEX_VERTICAL; break;
610 }
611 default:
612 case DMDUP_SIMPLEX: {
613 m_duplexMode = wxDUPLEX_SIMPLEX; break;
614 }
615 }
616 }
617 else
618 m_duplexMode = wxDUPLEX_SIMPLEX;
8826f46f 619
7bcb11d3 620 //// Quality
8826f46f 621
7bcb11d3
JS
622 if (devMode->dmFields & DM_PRINTQUALITY)
623 {
624 switch (devMode->dmPrintQuality)
625 {
626 case DMRES_MEDIUM: {
627 m_printQuality = wxPRINT_QUALITY_MEDIUM; break;
628 }
629 case DMRES_LOW: {
630 m_printQuality = wxPRINT_QUALITY_LOW; break;
631 }
632 case DMRES_DRAFT: {
633 m_printQuality = wxPRINT_QUALITY_DRAFT; break;
634 }
635 case DMRES_HIGH: {
636 m_printQuality = wxPRINT_QUALITY_HIGH; break;
637 }
638 default:
639 {
640 // TODO: if the printer fills in the resolution in DPI, how
641 // will the application know if it's high, low, draft etc.??
642 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
643 m_printQuality = devMode->dmPrintQuality; break;
8826f46f 644
7bcb11d3
JS
645 }
646 }
647 }
648 else
649 m_printQuality = wxPRINT_QUALITY_HIGH;
8826f46f 650
7bcb11d3
JS
651 GlobalUnlock(hDevMode);
652 }
eaeb6a3c
JS
653
654 if (hDevNames)
655 {
656 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(hDevNames);
657 if (lpDevNames)
658 {
659 // TODO: Unicode-ification
660
661 // Get the port name
662 // port is obsolete in WIN32
663 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
664
665 // Get the printer name
666 wxString printerName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
667
668 // Not sure if we should check for this mismatch
669// wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
670
671 if (printerName != "")
672 m_printerName = printerName;
673
674 GlobalUnlock(hDevNames);
675 }
676 }
7bcb11d3 677}
c801d85f 678
7bcb11d3
JS
679#endif
680
51abe921
SC
681#ifdef __WXMAC__
682void wxPrintData::ConvertToNative()
683{
cd0b1709
VZ
684 if ( !m_macPrintInfo )
685 {
686 m_macPrintInfo = (THPrint) NewHandleClear( sizeof( TPrint ) ) ;
687 if ( m_macPrintInfo )
688 {
689 ::PrintDefault( m_macPrintInfo ) ;
690 // todo setup the global pagesetup ?
691 }
692 }
693 if ( m_macPrintInfo )
694 {
695 (**m_macPrintInfo).prJob.iCopies = m_printNoCopies ;
696 (**m_macPrintInfo).prJob.iFstPage = 0 ;
697 (**m_macPrintInfo).prJob.iLstPage = 0 ;
698 }
51abe921
SC
699}
700
701void wxPrintData::ConvertFromNative()
702{
cd0b1709
VZ
703 if ( m_macPrintInfo )
704 {
705 m_printNoCopies = (**m_macPrintInfo).prJob.iCopies ;
706 }
51abe921
SC
707}
708#endif
709
7bcb11d3
JS
710void wxPrintData::operator=(const wxPrintData& data)
711{
712 m_printNoCopies = data.m_printNoCopies;
713 m_printCollate = data.m_printCollate;
714 m_printOrientation = data.m_printOrientation;
715 m_printerName = data.m_printerName;
716 m_colour = data.m_colour;
717 m_duplexMode = data.m_duplexMode;
718 m_printQuality = data.m_printQuality;
719 m_paperId = data.m_paperId;
720 m_paperSize = data.m_paperSize;
721
722 // PostScript-specific data
723 m_printerCommand = data.m_printerCommand;
724 m_previewCommand = data.m_previewCommand;
725 m_printerOptions = data.m_printerOptions;
726 m_filename = data.m_filename;
727 m_afmPath = data.m_afmPath;
728 m_printerScaleX = data.m_printerScaleX;
729 m_printerScaleY = data.m_printerScaleY;
730 m_printerTranslateX = data.m_printerTranslateX;
731 m_printerTranslateY = data.m_printerTranslateY;
732 m_printMode = data.m_printMode;
733}
734
735// For compatibility
8826f46f 736#if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
7bcb11d3
JS
737void wxPrintData::operator=(const wxPrintSetupData& setupData)
738{
739 SetPrinterCommand(setupData.GetPrinterCommand());
740 SetPreviewCommand(setupData.GetPrintPreviewCommand());
741 SetPrinterOptions(setupData.GetPrinterOptions());
742
743 long xt, yt;
744 setupData.GetPrinterTranslation(& xt, & yt);
745 SetPrinterTranslation(xt, yt);
746
747 double xs, ys;
748 setupData.GetPrinterScaling(& xs, & ys);
749 SetPrinterScaling(xs, ys);
750
751 SetOrientation(setupData.GetPrinterOrientation());
752 SetPrintMode((wxPrintMode) setupData.GetPrinterMode());
753 SetFontMetricPath(setupData.GetAFMPath());
754 if (setupData.GetPaperName() != "")
755 SetPaperId(wxThePrintPaperDatabase->ConvertNameToId(setupData.GetPaperName()));
756 SetColour(setupData.GetColour());
757 SetFilename(setupData.GetPrinterFile());
758}
8826f46f 759#endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
7bcb11d3 760
8826f46f
VZ
761
762// ----------------------------------------------------------------------------
763// Print dialog data
764// ----------------------------------------------------------------------------
7bcb11d3
JS
765
766wxPrintDialogData::wxPrintDialogData()
767{
768#ifdef __WXMSW__
769 m_printDlgData = NULL;
7c74e7fe 770#elif defined( __WXMAC__ )
cd0b1709 771 m_macPrintInfo = NULL ;
7bcb11d3
JS
772#endif
773 m_printFromPage = 0;
774 m_printToPage = 0;
775 m_printMinPage = 0;
776 m_printMaxPage = 0;
777 m_printNoCopies = 1;
778 m_printAllPages = FALSE;
779 m_printCollate = FALSE;
780 m_printToFile = FALSE;
5360828d 781 m_printSelection = FALSE;
7bcb11d3
JS
782 m_printEnableSelection = FALSE;
783 m_printEnablePageNumbers = TRUE;
784 m_printEnablePrintToFile = TRUE;
785 m_printEnableHelp = FALSE;
786 m_printSetupDialog = FALSE;
787}
788
789wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
790{
7c74e7fe
SC
791#ifdef __WXMSW__
792 m_printDlgData = NULL;
793#elif defined( __WXMAC__ )
cd0b1709 794 m_macPrintInfo = NULL ;
7c74e7fe 795#endif
7bcb11d3
JS
796 (*this) = dialogData;
797}
798
799wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
800{
801#ifdef __WXMSW__
802 m_printDlgData = NULL;
51abe921 803#elif defined( __WXMAC__ )
cd0b1709 804 m_macPrintInfo = NULL ;
7bcb11d3
JS
805#endif
806 m_printFromPage = 0;
807 m_printToPage = 0;
808 m_printMinPage = 0;
809 m_printMaxPage = 0;
810 m_printNoCopies = 1;
811 m_printAllPages = FALSE;
812 m_printCollate = FALSE;
813 m_printToFile = FALSE;
5360828d 814 m_printSelection = FALSE;
7bcb11d3
JS
815 m_printEnableSelection = FALSE;
816 m_printEnablePageNumbers = TRUE;
817 m_printEnablePrintToFile = TRUE;
818 m_printEnableHelp = FALSE;
819 m_printSetupDialog = FALSE;
820
821 m_printData = printData;
822}
823
824wxPrintDialogData::~wxPrintDialogData()
825{
826#ifdef __WXMSW__
827 PRINTDLG *pd = (PRINTDLG *) m_printDlgData;
828 if ( pd && pd->hDevMode )
829 GlobalFree(pd->hDevMode);
830 if ( pd )
831 delete pd;
51abe921 832#elif defined(__WXMAC__)
cd0b1709
VZ
833 if ( m_macPrintInfo )
834 ::DisposeHandle( (Handle) m_macPrintInfo ) ;
7bcb11d3
JS
835#endif
836}
837
838#ifdef __WXMSW__
839void wxPrintDialogData::ConvertToNative()
840{
841 m_printData.ConvertToNative();
842
843 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
844
845 if (!pd)
846 {
847 pd = new PRINTDLG;
848 m_printDlgData = (void*) pd;
849
850 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
851#ifdef __GNUWIN32__
852 pd->lStructSize = 66 ;
853#else
7bcb11d3 854 pd->lStructSize = sizeof(PRINTDLG);
25889d3c 855#endif
7bcb11d3
JS
856 pd->hwndOwner = (HWND)NULL;
857 pd->hDevMode = NULL; // Will be created by PrintDlg
858 pd->hDevNames = NULL; // Ditto
859
860 pd->Flags = PD_RETURNDEFAULT;
861 pd->nCopies = 1;
862 }
863
864 // Pass the devmode data to the PRINTDLG structure, since it'll
865 // be needed when PrintDlg is called.
866 if (pd->hDevMode)
867 {
868 GlobalFree(pd->hDevMode);
869 }
870
eaeb6a3c
JS
871 // Pass the devnames data to the PRINTDLG structure, since it'll
872 // be needed when PrintDlg is called.
873 if (pd->hDevNames)
874 {
875 GlobalFree(pd->hDevNames);
876 }
877
48c12cb1 878 pd->hDevMode = (HGLOBAL)(DWORD) m_printData.GetNativeData();
7bcb11d3
JS
879
880 m_printData.SetNativeData((void*) NULL);
881
223d09f6 882 wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
7bcb11d3 883
eaeb6a3c
JS
884 pd->hDevNames = (HGLOBAL)(DWORD) m_printData.GetNativeDataDevNames();
885
886 m_printData.SetNativeDataDevNames((void*) NULL);
887
7bcb11d3
JS
888 pd->hDC = (HDC) NULL;
889 pd->nFromPage = (UINT)m_printFromPage;
890 pd->nToPage = (UINT)m_printToPage;
891 pd->nMinPage = (UINT)m_printMinPage;
892 pd->nMaxPage = (UINT)m_printMaxPage;
893 pd->nCopies = (UINT)m_printNoCopies;
8826f46f 894
c801d85f 895 pd->Flags = PD_RETURNDC ;
7bcb11d3
JS
896
897#ifdef __GNUWIN32__
c801d85f 898 pd->lStructSize = 66 ;
7bcb11d3
JS
899#else
900 pd->lStructSize = sizeof( PRINTDLG );
901#endif
902
8b9518ee 903 pd->hwndOwner=(HWND)NULL;
eaeb6a3c 904// pd->hDevNames=(HANDLE)NULL;
c801d85f
KB
905 pd->hInstance=(HINSTANCE)NULL;
906 pd->lCustData = (LPARAM) NULL;
907 pd->lpfnPrintHook = NULL;
908 pd->lpfnSetupHook = NULL;
909 pd->lpPrintTemplateName = NULL;
910 pd->lpSetupTemplateName = NULL;
911 pd->hPrintTemplate = (HGLOBAL) NULL;
912 pd->hSetupTemplate = (HGLOBAL) NULL;
8826f46f 913
7bcb11d3 914 if ( m_printAllPages )
c801d85f 915 pd->Flags |= PD_ALLPAGES;
5360828d
JS
916 if ( m_printAllPages )
917 pd->Flags |= PD_SELECTION;
7bcb11d3 918 if ( m_printCollate )
c801d85f 919 pd->Flags |= PD_COLLATE;
7bcb11d3 920 if ( m_printToFile )
c801d85f 921 pd->Flags |= PD_PRINTTOFILE;
7bcb11d3 922 if ( !m_printEnablePrintToFile )
c801d85f 923 pd->Flags |= PD_DISABLEPRINTTOFILE;
7bcb11d3
JS
924 if ( !m_printEnableSelection )
925 pd->Flags |= PD_NOSELECTION;
926 if ( !m_printEnablePageNumbers )
927 pd->Flags |= PD_NOPAGENUMS;
928 if ( m_printEnableHelp )
929 pd->Flags |= PD_SHOWHELP;
930 if ( m_printSetupDialog )
931 pd->Flags |= PD_PRINTSETUP;
c801d85f
KB
932}
933
7bcb11d3 934void wxPrintDialogData::ConvertFromNative()
c801d85f 935{
7bcb11d3 936 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
c801d85f
KB
937 if ( pd == NULL )
938 return;
939
7bcb11d3
JS
940 // Pass the devmode data back to the wxPrintData structure where it really belongs.
941 if (pd->hDevMode)
c801d85f 942 {
7bcb11d3
JS
943 if (m_printData.GetNativeData())
944 {
945 // Make sure we don't leak memory
48c12cb1 946 GlobalFree((HGLOBAL)(DWORD) m_printData.GetNativeData());
7bcb11d3 947 }
aeb50f86 948 m_printData.SetNativeData((void*)(long) pd->hDevMode);
7bcb11d3 949 pd->hDevMode = NULL;
c801d85f 950 }
c801d85f 951
eaeb6a3c
JS
952 // Pass the devnames data back to the wxPrintData structure where it really belongs.
953 if (pd->hDevNames)
954 {
955 if (m_printData.GetNativeDataDevNames())
956 {
957 // Make sure we don't leak memory
958 GlobalFree((HGLOBAL)(DWORD) m_printData.GetNativeDataDevNames());
959 }
960 m_printData.SetNativeDataDevNames((void*)(long) pd->hDevNames);
961 pd->hDevNames = NULL;
962 }
963
7bcb11d3
JS
964 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
965 // into wxWindows form.
966 m_printData.ConvertFromNative();
967
968 m_printFromPage = pd->nFromPage ;
969 m_printToPage = pd->nToPage ;
970 m_printMinPage = pd->nMinPage ;
971 m_printMaxPage = pd->nMaxPage ;
972 m_printNoCopies = pd->nCopies ;
8826f46f 973
7bcb11d3 974 m_printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES);
5360828d 975 m_printSelection = ((pd->Flags & PD_SELECTION) == PD_SELECTION);
7bcb11d3
JS
976 m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE);
977 m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE);
978 m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE);
979 m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION);
980 m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS);
981 m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP);
982 m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP);
983
984/* port is obsolete in WIN32
985 // Get the port name
986 if (pd->hDevNames)
987 {
988 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
989 if (lpDevNames) {
990 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
991 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
992 GlobalUnlock(pd->hDevNames);
8826f46f 993
7bcb11d3
JS
994// wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
995 }
996 }
997*/
c801d85f
KB
998}
999
7bcb11d3 1000void wxPrintDialogData::SetOwnerWindow(wxWindow* win)
c801d85f 1001{
7bcb11d3 1002 if ( m_printDlgData == NULL )
c801d85f 1003 ConvertToNative();
8826f46f 1004
7bcb11d3 1005 if ( m_printDlgData != NULL && win != NULL)
c801d85f 1006 {
7bcb11d3
JS
1007 PRINTDLG *pd = (PRINTDLG *) m_printDlgData ;
1008 pd->hwndOwner=(HWND) win->GetHWND();
c801d85f
KB
1009 }
1010}
8826f46f 1011#endif // MSW
c801d85f 1012
51abe921
SC
1013#ifdef __WXMAC__
1014void wxPrintDialogData::ConvertToNative()
1015{
cd0b1709
VZ
1016 if ( !m_macPrintInfo )
1017 {
1018 m_macPrintInfo = (THPrint) NewHandleClear( sizeof( TPrint ) ) ;
1019 if ( m_macPrintInfo )
1020 {
1021 ::PrintDefault( m_macPrintInfo ) ;
1022 // todo setup the global pagesetup ?
1023 }
1024 }
1025 if ( m_macPrintInfo )
1026 {
1027 (**m_macPrintInfo).prJob.iCopies = m_printNoCopies ;
1028 (**m_macPrintInfo).prJob.iFstPage = m_printFromPage ;
1029 (**m_macPrintInfo).prJob.iLstPage = m_printToPage ;
1030 }
51abe921
SC
1031}
1032
1033void wxPrintDialogData::ConvertFromNative()
1034{
cd0b1709
VZ
1035 if ( m_macPrintInfo )
1036 {
1037 m_printNoCopies = (**m_macPrintInfo).prJob.iCopies ;
1038 m_printFromPage = (**m_macPrintInfo).prJob.iFstPage ;
1039 m_printToPage = (**m_macPrintInfo).prJob.iLstPage ;
1040 }
51abe921
SC
1041}
1042#endif
1043
1044
7bcb11d3 1045void wxPrintDialogData::operator=(const wxPrintDialogData& data)
c801d85f 1046{
7bcb11d3
JS
1047 m_printFromPage = data.m_printFromPage;
1048 m_printToPage = data.m_printToPage;
1049 m_printMinPage = data.m_printMinPage;
1050 m_printMaxPage = data.m_printMaxPage;
1051 m_printNoCopies = data.m_printNoCopies;
1052 m_printAllPages = data.m_printAllPages;
1053 m_printCollate = data.m_printCollate;
1054 m_printToFile = data.m_printToFile;
5360828d 1055 m_printSelection = data.m_printSelection;
7bcb11d3
JS
1056 m_printEnableSelection = data.m_printEnableSelection;
1057 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
1058 m_printEnableHelp = data.m_printEnableHelp;
1059 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
1060 m_printSetupDialog = data.m_printSetupDialog;
1061
1062 m_printData = data.m_printData;
1063}
1064
1065void wxPrintDialogData::operator=(const wxPrintData& data)
1066{
1067 m_printData = data;
c801d85f
KB
1068}
1069
8826f46f
VZ
1070// ----------------------------------------------------------------------------
1071// wxPageSetupDialogData
1072// ----------------------------------------------------------------------------
c801d85f 1073
7bcb11d3 1074wxPageSetupDialogData::wxPageSetupDialogData()
c801d85f
KB
1075{
1076#if defined(__WIN95__)
7bcb11d3 1077 m_pageSetupData = NULL;
51abe921 1078#elif defined( __WXMAC__ )
cd0b1709 1079 m_macPageSetupInfo = NULL ;
c801d85f 1080#endif
7bcb11d3
JS
1081 m_paperSize = wxSize(0, 0);
1082
1083 CalculatePaperSizeFromId();
1084
1085 m_minMarginTopLeft = wxPoint(0, 0);
1086 m_minMarginBottomRight = wxPoint(0, 0);
1087 m_marginTopLeft = wxPoint(0, 0);
1088 m_marginBottomRight = wxPoint(0, 0);
1089
1090 // Flags
1091 m_defaultMinMargins = FALSE;
1092 m_enableMargins = TRUE;
1093 m_enableOrientation = TRUE;
1094 m_enablePaper = TRUE;
1095 m_enablePrinter = TRUE;
1096 m_enableHelp = FALSE;
1097 m_getDefaultInfo = FALSE;
1098}
c801d85f 1099
7bcb11d3
JS
1100wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
1101{
7c74e7fe
SC
1102#if defined(__WIN95__)
1103 m_pageSetupData = NULL;
1104#elif defined( __WXMAC__ )
cd0b1709 1105 m_macPageSetupInfo = NULL ;
7c74e7fe 1106#endif
7bcb11d3
JS
1107 (*this) = dialogData;
1108}
1109
1110wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
1111{
1112#if defined(__WIN95__)
1113 m_pageSetupData = NULL;
51abe921 1114#elif defined( __WXMAC__ )
cd0b1709 1115 m_macPageSetupInfo = NULL ;
7bcb11d3
JS
1116#endif
1117 m_paperSize = wxSize(0, 0);
1118 m_minMarginTopLeft = wxPoint(0, 0);
1119 m_minMarginBottomRight = wxPoint(0, 0);
1120 m_marginTopLeft = wxPoint(0, 0);
1121 m_marginBottomRight = wxPoint(0, 0);
1122
1123 // Flags
1124 m_defaultMinMargins = FALSE;
1125 m_enableMargins = TRUE;
1126 m_enableOrientation = TRUE;
1127 m_enablePaper = TRUE;
1128 m_enablePrinter = TRUE;
1129 m_enableHelp = FALSE;
1130 m_getDefaultInfo = FALSE;
1131
1132 m_printData = printData;
1133
1134 // The wxPrintData paper size overrides these values, unless the size cannot
1135 // be found.
1136 CalculatePaperSizeFromId();
c801d85f
KB
1137}
1138
7bcb11d3 1139wxPageSetupDialogData::~wxPageSetupDialogData()
c801d85f 1140{
34138703 1141#if defined(__WIN95__) && defined(__WXMSW__)
c801d85f
KB
1142 PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData;
1143 if ( pd && pd->hDevMode )
1144 GlobalFree(pd->hDevMode);
eaeb6a3c
JS
1145 if ( pd && pd->hDevNames )
1146 GlobalFree(pd->hDevNames);
c801d85f
KB
1147 if ( pd )
1148 delete pd;
51abe921 1149#elif defined( __WXMAC__ )
cd0b1709
VZ
1150 if( m_macPageSetupInfo )
1151 ::DisposeHandle( (Handle) m_macPageSetupInfo ) ;
c801d85f
KB
1152#endif
1153}
1154
7bcb11d3 1155void wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
c801d85f 1156{
7bcb11d3
JS
1157 m_paperSize = data.m_paperSize;
1158 m_minMarginTopLeft = data.m_minMarginTopLeft;
1159 m_minMarginBottomRight = data.m_minMarginBottomRight;
1160 m_marginTopLeft = data.m_marginTopLeft;
1161 m_marginBottomRight = data.m_marginBottomRight;
1162 m_defaultMinMargins = data.m_defaultMinMargins;
1163 m_enableMargins = data.m_enableMargins;
1164 m_enableOrientation = data.m_enableOrientation;
1165 m_enablePaper = data.m_enablePaper;
1166 m_enablePrinter = data.m_enablePrinter;
1167 m_getDefaultInfo = data.m_getDefaultInfo;;
1168 m_enableHelp = data.m_enableHelp;
1169
1170 m_printData = data.m_printData;
1171}
c801d85f 1172
7bcb11d3
JS
1173void wxPageSetupDialogData::operator=(const wxPrintData& data)
1174{
1175 m_printData = data;
c801d85f
KB
1176}
1177
8826f46f 1178#if defined(__WIN95__)
7bcb11d3 1179void wxPageSetupDialogData::ConvertToNative()
c801d85f 1180{
7bcb11d3
JS
1181 m_printData.ConvertToNative();
1182
c801d85f 1183 PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData;
7bcb11d3 1184
c801d85f
KB
1185 if ( m_pageSetupData == NULL )
1186 {
7bcb11d3
JS
1187 pd = new PAGESETUPDLG;
1188 pd->hDevMode = NULL;
eaeb6a3c 1189 pd->hDevNames = NULL;
7bcb11d3 1190 m_pageSetupData = (void *)pd;
c801d85f 1191 }
8bbe427f 1192
7bcb11d3
JS
1193 // Pass the devmode data (created in m_printData.ConvertToNative)
1194 // to the PRINTDLG structure, since it'll
1195 // be needed when PrintDlg is called.
1196
1197 if (pd->hDevMode)
1198 {
1199 GlobalFree(pd->hDevMode);
1200 pd->hDevMode = NULL;
1201 }
1202
7bcb11d3
JS
1203 pd->hDevMode = (HGLOBAL) m_printData.GetNativeData();
1204
1205 m_printData.SetNativeData((void*) NULL);
1206
223d09f6 1207 wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
7bcb11d3 1208
eaeb6a3c
JS
1209 // Pass the devnames data (created in m_printData.ConvertToNative)
1210 // to the PRINTDLG structure, since it'll
1211 // be needed when PrintDlg is called.
1212
1213 if (pd->hDevNames)
1214 {
1215 GlobalFree(pd->hDevNames);
1216 pd->hDevNames = NULL;
1217 }
1218
1219 pd->hDevNames = (HGLOBAL) m_printData.GetNativeDataDevNames();
1220
1221 m_printData.SetNativeDataDevNames((void*) NULL);
1222
7bcb11d3 1223// pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
c801d85f 1224
7bcb11d3 1225 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
8826f46f 1226
c801d85f
KB
1227 if ( m_defaultMinMargins )
1228 pd->Flags |= PSD_DEFAULTMINMARGINS;
1229 if ( !m_enableMargins )
1230 pd->Flags |= PSD_DISABLEMARGINS;
1231 if ( !m_enableOrientation )
1232 pd->Flags |= PSD_DISABLEORIENTATION;
1233 if ( !m_enablePaper )
1234 pd->Flags |= PSD_DISABLEPAPER;
1235 if ( !m_enablePrinter )
1236 pd->Flags |= PSD_DISABLEPRINTER;
1237 if ( m_getDefaultInfo )
1238 pd->Flags |= PSD_RETURNDEFAULT;
1239 if ( m_enableHelp )
1240 pd->Flags |= PSD_SHOWHELP;
1241
7bcb11d3
JS
1242 // We want the units to be in hundredths of a millimetre
1243 pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1244
c801d85f 1245 pd->lStructSize = sizeof( PAGESETUPDLG );
c4e7c2aa 1246 pd->hwndOwner=(HWND)NULL;
eaeb6a3c 1247// pd->hDevNames=(HWND)NULL;
c801d85f 1248 pd->hInstance=(HINSTANCE)NULL;
8826f46f 1249
7bcb11d3
JS
1250 pd->ptPaperSize.x = m_paperSize.x * 100;
1251 pd->ptPaperSize.y = m_paperSize.y * 100;
8826f46f 1252
7bcb11d3
JS
1253 pd->rtMinMargin.left = m_minMarginTopLeft.x * 100;
1254 pd->rtMinMargin.top = m_minMarginTopLeft.y * 100;
1255 pd->rtMinMargin.right = m_minMarginBottomRight.x * 100;
1256 pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100;
8826f46f 1257
7bcb11d3
JS
1258 pd->rtMargin.left = m_marginTopLeft.x * 100;
1259 pd->rtMargin.top = m_marginTopLeft.y * 100;
1260 pd->rtMargin.right = m_marginBottomRight.x * 100;
1261 pd->rtMargin.bottom = m_marginBottomRight.y * 100;
8826f46f 1262
c801d85f
KB
1263 pd->lCustData = 0;
1264 pd->lpfnPageSetupHook = NULL;
1265 pd->lpfnPagePaintHook = NULL;
1266 pd->hPageSetupTemplate = NULL;
1267 pd->lpPageSetupTemplateName = NULL;
1268
8826f46f 1269/*
c801d85f
KB
1270 if ( pd->hDevMode )
1271 {
1272 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1273 memset(devMode, 0, sizeof(DEVMODE));
1274 devMode->dmSize = sizeof(DEVMODE);
1275 devMode->dmOrientation = m_orientation;
1276 devMode->dmFields = DM_ORIENTATION;
1277 GlobalUnlock(pd->hDevMode);
1278 }
7bcb11d3 1279*/
c801d85f
KB
1280}
1281
7bcb11d3 1282void wxPageSetupDialogData::ConvertFromNative()
c801d85f
KB
1283{
1284 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
1285 if ( !pd )
1286 return;
8826f46f 1287
7bcb11d3
JS
1288 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1289 if (pd->hDevMode)
1290 {
1291 if (m_printData.GetNativeData())
1292 {
1293 // Make sure we don't leak memory
1294 GlobalFree((HGLOBAL) m_printData.GetNativeData());
1295 }
1296 m_printData.SetNativeData((void*) pd->hDevMode);
1297 pd->hDevMode = NULL;
1298 }
c801d85f 1299
7bcb11d3 1300 m_printData.ConvertFromNative();
c801d85f 1301
eaeb6a3c
JS
1302 // Pass the devnames data back to the wxPrintData structure where it really belongs.
1303 if (pd->hDevNames)
1304 {
1305 if (m_printData.GetNativeDataDevNames())
1306 {
1307 // Make sure we don't leak memory
1308 GlobalFree((HGLOBAL) m_printData.GetNativeDataDevNames());
1309 }
1310 m_printData.SetNativeDataDevNames((void*) pd->hDevNames);
1311 pd->hDevNames = NULL;
1312 }
1313
1314 m_printData.ConvertFromNative();
1315
7bcb11d3 1316 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
8826f46f 1317
c801d85f
KB
1318 m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS);
1319 m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS);
1320 m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION);
1321 m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER);
1322 m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER);
1323 m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT);
1324 m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP);
8826f46f 1325
7bcb11d3
JS
1326 m_paperSize.x = pd->ptPaperSize.x / 100;
1327 m_paperSize.y = pd->ptPaperSize.y / 100;
8826f46f 1328
7bcb11d3
JS
1329 m_minMarginTopLeft.x = pd->rtMinMargin.left / 100;
1330 m_minMarginTopLeft.y = pd->rtMinMargin.top / 100;
1331 m_minMarginBottomRight.x = pd->rtMinMargin.right / 100;
1332 m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100;
8826f46f 1333
7bcb11d3
JS
1334 m_marginTopLeft.x = pd->rtMargin.left / 100 ;
1335 m_marginTopLeft.y = pd->rtMargin.top / 100 ;
1336 m_marginBottomRight.x = pd->rtMargin.right / 100 ;
1337 m_marginBottomRight.y = pd->rtMargin.bottom / 100 ;
1338}
c801d85f 1339
7bcb11d3
JS
1340void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win)
1341{
1342 if ( m_pageSetupData == NULL )
1343 ConvertToNative();
8826f46f 1344
7bcb11d3
JS
1345 if ( m_pageSetupData != NULL && win != NULL)
1346 {
1347 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
1348 pd->hwndOwner=(HWND) win->GetHWND();
1349 }
1350}
8826f46f 1351#endif // Win95
c801d85f 1352
51abe921 1353#ifdef __WXMAC__
7c74e7fe 1354void wxPageSetupDialogData::ConvertToNative()
51abe921 1355{
cd0b1709
VZ
1356 if ( !m_macPageSetupInfo )
1357 {
1358 m_macPageSetupInfo = (THPrint) NewHandleClear( sizeof( TPrint ) ) ;
1359 if ( m_macPageSetupInfo )
1360 {
1361 ::PrintDefault( m_macPageSetupInfo ) ;
1362 }
1363 }
1364 if ( m_macPageSetupInfo )
1365 {
1366 // on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0
1367 (**m_macPageSetupInfo).rPaper.left = int( ((double) m_minMarginTopLeft.x)*mm2pt ) ;
1368 (**m_macPageSetupInfo).rPaper.top = int( ((double) m_minMarginTopLeft.y)*mm2pt ) ;
1369
1370 (**m_macPageSetupInfo).rPaper.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x)*mm2pt ) ;
1371 (**m_macPageSetupInfo).rPaper.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y)*mm2pt ) ;
1372
1373 (**m_macPageSetupInfo).prInfo.rPage.left = 0 ;
1374 (**m_macPageSetupInfo).prInfo.rPage.top = 0 ;
1375 (**m_macPageSetupInfo).prInfo.rPage.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x - m_minMarginBottomRight.x)*mm2pt ) ;
1376 (**m_macPageSetupInfo).prInfo.rPage.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y - m_minMarginBottomRight.y)*mm2pt ) ;
1377
1378 //TODO add custom fields in dialog for margins
1379
1380 }
51abe921
SC
1381}
1382
7c74e7fe 1383void wxPageSetupDialogData::ConvertFromNative()
51abe921 1384{
cd0b1709
VZ
1385 if ( m_macPageSetupInfo )
1386 {
1387 m_paperSize.x = ((double) (**m_macPageSetupInfo).rPaper.right - (**m_macPageSetupInfo).rPaper.left ) * pt2mm ;
1388 m_paperSize.y = ((double) (**m_macPageSetupInfo).rPaper.bottom - (**m_macPageSetupInfo).rPaper.top ) * pt2mm ;
1389
1390 m_minMarginTopLeft.x = ((double) -(**m_macPageSetupInfo).rPaper.left ) * pt2mm ;
1391 m_minMarginTopLeft.y = ((double) -(**m_macPageSetupInfo).rPaper.top ) * pt2mm ;
1392
1393 m_minMarginBottomRight.x = ((double) (**m_macPageSetupInfo).rPaper.right - (**m_macPageSetupInfo).prInfo.rPage.right ) * pt2mm ;
1394 m_minMarginBottomRight.y = ((double)(**m_macPageSetupInfo).rPaper.bottom - (**m_macPageSetupInfo).prInfo.rPage.bottom ) * pt2mm ;
1395
1396 // adjust minimal values
1397 //TODO add custom fields in dialog for margins
1398
1399 if ( m_marginTopLeft.x < m_minMarginTopLeft.x )
1400 m_marginTopLeft.x = m_minMarginTopLeft.x ;
1401
1402 if ( m_marginBottomRight.x < m_minMarginBottomRight.x )
1403 m_marginBottomRight.x = m_minMarginBottomRight.x ;
1404
1405 if ( m_marginTopLeft.y < m_minMarginTopLeft.y )
1406 m_marginTopLeft.y = m_minMarginTopLeft.y ;
1407
1408 if ( m_marginBottomRight.y < m_minMarginBottomRight.y )
1409 m_marginBottomRight.y = m_minMarginBottomRight.y ;
1410
1411 }
51abe921
SC
1412}
1413#endif
1414
1415
7bcb11d3
JS
1416// If a corresponding paper type is found in the paper database, will set the m_printData
1417// paper size id member as well.
1418void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
1419{
1420 m_paperSize = sz;
c801d85f 1421
7bcb11d3
JS
1422 CalculateIdFromPaperSize();
1423}
c801d85f 1424
7bcb11d3
JS
1425// Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1426void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
1427{
1428 m_printData.SetPaperId(id);
1429
1430 CalculatePaperSizeFromId();
c801d85f
KB
1431}
1432
7bcb11d3
JS
1433// Use paper size defined in this object to set the wxPrintData
1434// paper id
1435void wxPageSetupDialogData::CalculateIdFromPaperSize()
c801d85f 1436{
8826f46f 1437 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
223d09f6 1438 wxT("wxThePrintPaperDatabase should not be NULL. "
60df2e7d 1439 "Do not create global print dialog data objects.") );
c801d85f 1440
7bcb11d3
JS
1441 wxSize sz = GetPaperSize();
1442
1443 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
1444 if (id != wxPAPER_NONE)
c801d85f 1445 {
7bcb11d3 1446 m_printData.SetPaperId(id);
c801d85f
KB
1447 }
1448}
8826f46f 1449
7bcb11d3
JS
1450// Use paper id in wxPrintData to set this object's paper size
1451void wxPageSetupDialogData::CalculatePaperSizeFromId()
1452{
8826f46f 1453 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
223d09f6 1454 wxT("wxThePrintPaperDatabase should not be NULL. "
60df2e7d 1455 "Do not create global print dialog data objects.") );
7bcb11d3
JS
1456
1457 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
c801d85f 1458
7bcb11d3
JS
1459 if (sz.x != 0)
1460 {
1461 // sz is in 10ths of a mm, so multiply by 10.
1462 m_paperSize.x = sz.x * 10;
1463 m_paperSize.y = sz.y * 10;
1464 }
1465}
8826f46f 1466
88ac883a 1467#endif // wxUSE_PRINTING_ARCHITECTURE