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