]> git.saurik.com Git - wxWidgets.git/blame - src/common/cmndata.cpp
fixed bug in Set(double jdn): don't test whether the date is valid before setting...
[wxWidgets.git] / src / common / cmndata.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: cmndata.cpp
3// Purpose: Common GDI data
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
55d99c7a 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
8826f46f
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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"
8850cbd3
RR
41#include "wx/prntbase.h"
42#include "wx/printdlg.h"
8826f46f 43
dbc65e27
VZ
44#if wxUSE_FONTDLG
45 #include "wx/fontdlg.h"
46#endif // wxUSE_FONTDLG
47
88ac883a
VZ
48#if wxUSE_PRINTING_ARCHITECTURE
49 #include "wx/paper.h"
88ac883a 50#endif // wxUSE_PRINTING_ARCHITECTURE
7be1f0d9 51
82ef81ed 52#if defined(__WXMSW__)
1c193821 53 #include <windowsx.h>
3096bd2f 54 #include "wx/msw/private.h"
7be1f0d9 55
0c44ec97 56 #ifndef __SMARTPHONE__ /* of WinCE */
8826f46f 57 #include <commdlg.h>
1c193821 58 #endif
8826f46f 59
2bdf7154 60 #if defined(__WATCOMC__) || defined(__SYMANTEC__) || defined(__SALFORDC__)
8826f46f
VZ
61 #include <windowsx.h>
62 #include <commdlg.h>
63 #endif
64#endif // MSW
c801d85f 65
179e085f
RN
66 #if wxUSE_PRINTING_ARCHITECTURE
67
68#if defined(__WXMAC__)
746d7582
SC
69 #include "wx/mac/private/print.h"
70#endif
71
88ac883a
VZ
72 IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
73 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject)
74 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject)
75 #endif // wxUSE_PRINTING_ARCHITECTURE
cd0b1709 76
8826f46f
VZ
77 IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
78 IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
c801d85f 79
83e72d5f
GT
80#ifndef DMPAPER_USER
81 #define DMPAPER_USER 256
82#endif
83
8826f46f
VZ
84// ============================================================================
85// implementation
86// ============================================================================
87
88// ----------------------------------------------------------------------------
89// wxColourData
90// ----------------------------------------------------------------------------
c801d85f 91
8bbe427f 92wxColourData::wxColourData()
c801d85f 93{
393c836c 94 m_chooseFull = false;
ae500232 95 m_dataColour.Set(0,0,0);
393c836c 96 // m_custColours are wxNullColours initially
7bcb11d3 97}
c801d85f 98
7bcb11d3 99wxColourData::wxColourData(const wxColourData& data)
5e472c1f 100 : wxObject()
7bcb11d3
JS
101{
102 (*this) = data;
8bbe427f 103}
c801d85f 104
8bbe427f 105wxColourData::~wxColourData()
c801d85f
KB
106{
107}
108
cebf2fec 109void wxColourData::SetCustomColour(int i, const wxColour& colour)
c801d85f 110{
393c836c 111 wxCHECK_RET( (i >= 0 && i < 16), _T("custom colour index out of range") );
8826f46f 112
ae500232 113 m_custColours[i] = colour;
c801d85f
KB
114}
115
116wxColour wxColourData::GetCustomColour(int i)
117{
393c836c
VS
118 wxCHECK_MSG( (i >= 0 && i < 16), wxColour(0,0,0),
119 _T("custom colour index out of range") );
8826f46f 120
ae500232 121 return m_custColours[i];
c801d85f
KB
122}
123
124void wxColourData::operator=(const wxColourData& data)
125{
7bcb11d3
JS
126 int i;
127 for (i = 0; i < 16; i++)
ae500232 128 m_custColours[i] = data.m_custColours[i];
8826f46f 129
ae500232
JS
130 m_dataColour = (wxColour&)data.m_dataColour;
131 m_chooseFull = data.m_chooseFull;
c801d85f
KB
132}
133
8826f46f
VZ
134// ----------------------------------------------------------------------------
135// Font data
136// ----------------------------------------------------------------------------
c801d85f 137
8bbe427f 138wxFontData::wxFontData()
c801d85f 139{
7bcb11d3 140 // Intialize colour to black.
ae500232 141 m_fontColour = wxNullColour;
8826f46f 142
c9d59ee7
WS
143 m_showHelp = false;
144 m_allowSymbols = true;
145 m_enableEffects = true;
ae500232
JS
146 m_minSize = 0;
147 m_maxSize = 0;
c801d85f 148
7beba2fc 149 m_encoding = wxFONTENCODING_SYSTEM;
c801d85f
KB
150}
151
8bbe427f 152wxFontData::~wxFontData()
c801d85f
KB
153{
154}
155
dbc65e27
VZ
156#if wxUSE_FONTDLG
157
158wxFontDialogBase::~wxFontDialogBase()
159{
160}
161
162#endif // wxUSE_FONTDLG
163
88ac883a 164#if wxUSE_PRINTING_ARCHITECTURE
8826f46f
VZ
165// ----------------------------------------------------------------------------
166// Print data
167// ----------------------------------------------------------------------------
c801d85f 168
8bbe427f 169wxPrintData::wxPrintData()
c801d85f 170{
8850cbd3 171#ifdef __WXMAC__
746d7582 172 m_nativePrintData = wxNativePrintData::Create() ;
c801d85f 173#endif
60090256 174 m_bin = wxPRINTBIN_DEFAULT;
6038ec8e 175 m_printMode = wxPRINT_MODE_PRINTER;
7bcb11d3
JS
176 m_printOrientation = wxPORTRAIT;
177 m_printNoCopies = 1;
c9d59ee7 178 m_printCollate = false;
8826f46f 179
7bcb11d3 180 // New, 24/3/99
b494c48b 181 m_printerName = wxEmptyString;
c9d59ee7 182 m_colour = true;
7bcb11d3
JS
183 m_duplexMode = wxDUPLEX_SIMPLEX;
184 m_printQuality = wxPRINT_QUALITY_HIGH;
185 m_paperId = wxPAPER_A4;
186 m_paperSize = wxSize(210, 297);
187
aa96f01c
RR
188 m_privData = NULL;
189 m_privDataLen = 0;
190
8850cbd3 191 m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData();
7bcb11d3
JS
192}
193
194wxPrintData::wxPrintData(const wxPrintData& printData)
5e472c1f 195 : wxObject()
7bcb11d3 196{
7b8a9da3 197 m_nativeData = NULL;
7bcb11d3 198 (*this) = printData;
c801d85f
KB
199}
200
aa96f01c
RR
201void wxPrintData::SetPrivData( char *privData, int len )
202{
203 if (m_privData)
204 {
205 delete [] m_privData;
206 m_privData = NULL;
207 }
208 m_privDataLen = len;
209 if (m_privDataLen > 0)
210 {
211 m_privData = new char[m_privDataLen];
212 memcpy( m_privData, privData, m_privDataLen );
213 }
214}
215
8bbe427f 216wxPrintData::~wxPrintData()
c801d85f 217{
8850cbd3 218 m_nativeData->m_ref--;
4055ed82 219 if (m_nativeData->m_ref == 0)
8850cbd3 220 delete m_nativeData;
aa96f01c
RR
221
222 if (m_privData)
223 delete [] m_privData;
4055ed82 224
8850cbd3 225#ifdef __WXMAC__
746d7582 226 delete m_nativePrintData ;
c801d85f
KB
227#endif
228}
229
51abe921
SC
230void wxPrintData::ConvertToNative()
231{
53fa663a 232#ifdef __WXMAC__
746d7582 233 m_nativePrintData->TransferFrom( this ) ;
53fa663a
RR
234#else
235 m_nativeData->TransferFrom( *this ) ;
236#endif
51abe921
SC
237}
238
239void wxPrintData::ConvertFromNative()
240{
53fa663a 241#ifdef __WXMAC__
746d7582 242 m_nativePrintData->TransferTo( this ) ;
53fa663a
RR
243#else
244 m_nativeData->TransferTo( *this ) ;
51abe921 245#endif
53fa663a 246}
51abe921 247
7bcb11d3
JS
248void wxPrintData::operator=(const wxPrintData& data)
249{
250 m_printNoCopies = data.m_printNoCopies;
251 m_printCollate = data.m_printCollate;
252 m_printOrientation = data.m_printOrientation;
253 m_printerName = data.m_printerName;
254 m_colour = data.m_colour;
255 m_duplexMode = data.m_duplexMode;
256 m_printQuality = data.m_printQuality;
257 m_paperId = data.m_paperId;
258 m_paperSize = data.m_paperSize;
60090256 259 m_bin = data.m_bin;
6038ec8e 260 m_printMode = data.m_printMode;
4055ed82 261 m_filename = data.m_filename;
aac85509 262
4055ed82 263 // UnRef old m_nativeData
7b8a9da3
RD
264 if (m_nativeData)
265 {
266 m_nativeData->m_ref--;
4055ed82 267 if (m_nativeData->m_ref == 0)
7b8a9da3
RD
268 delete m_nativeData;
269 }
aac85509 270 // Set Ref new one
8850cbd3
RR
271 m_nativeData = data.GetNativeData();
272 m_nativeData->m_ref++;
4055ed82 273
aa96f01c
RR
274 if (m_privData)
275 {
276 delete [] m_privData;
277 m_privData = NULL;
278 }
279 m_privDataLen = data.GetPrivDataLen();
280 if (m_privDataLen > 0)
281 {
282 m_privData = new char[m_privDataLen];
283 memcpy( m_privData, data.GetPrivData(), m_privDataLen );
284 }
285
8850cbd3
RR
286#ifdef __WXMAC__
287 m_nativePrintData->CopyFrom( data.m_nativePrintData ) ;
244e5e34 288#endif
7bcb11d3
JS
289}
290
58cf0491
JS
291// Is this data OK for showing the print dialog?
292bool wxPrintData::Ok() const
293{
fd64de59 294 m_nativeData->TransferFrom( *this );
8850cbd3
RR
295
296 return m_nativeData->Ok();
58cf0491 297}
8826f46f 298
72259e00
RL
299// What should happen here? wxPostScriptPrintNativeData is not
300// defined unless all this is true on MSW.
301#if WXWIN_COMPATIBILITY_2_4 && wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
0ab2de15
RR
302
303#include "wx/generic/prntdlgg.h"
304
fd864f01
WS
305#if wxUSE_POSTSCRIPT
306 #define WXUNUSED_WITHOUT_PS(name) name
307#else
308 #define WXUNUSED_WITHOUT_PS(name) WXUNUSED(name)
309#endif
310
0ab2de15
RR
311wxString wxPrintData::GetPrinterCommand() const
312{
313#if wxUSE_POSTSCRIPT
314 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
315 return ((wxPostScriptPrintNativeData*)m_nativeData)->GetPrinterCommand();
316#endif
b494c48b 317 return wxEmptyString;
0ab2de15
RR
318}
319
320wxString wxPrintData::GetPrinterOptions() const
321{
322#if wxUSE_POSTSCRIPT
323 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
324 return ((wxPostScriptPrintNativeData*)m_nativeData)->GetPrinterOptions();
325#endif
b494c48b 326 return wxEmptyString;
0ab2de15
RR
327}
328
329wxString wxPrintData::GetPreviewCommand() const
330{
331#if wxUSE_POSTSCRIPT
332 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
333 return ((wxPostScriptPrintNativeData*)m_nativeData)->GetPreviewCommand();
334#endif
b494c48b 335 return wxEmptyString;
0ab2de15
RR
336}
337
338wxString wxPrintData::GetFontMetricPath() const
339{
340#if wxUSE_POSTSCRIPT
341 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
342 return ((wxPostScriptPrintNativeData*)m_nativeData)->GetFontMetricPath();
343#endif
b494c48b 344 return wxEmptyString;
0ab2de15
RR
345}
346
347double wxPrintData::GetPrinterScaleX() const
348{
349#if wxUSE_POSTSCRIPT
350 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
351 return ((wxPostScriptPrintNativeData*)m_nativeData)->GetPrinterScaleX();
352#endif
353 return 1.0;
354}
355
356double wxPrintData::GetPrinterScaleY() const
357{
358#if wxUSE_POSTSCRIPT
359 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
360 return ((wxPostScriptPrintNativeData*)m_nativeData)->GetPrinterScaleY();
361#endif
362 return 1.0;
363}
364
365long wxPrintData::GetPrinterTranslateX() const
366{
367#if wxUSE_POSTSCRIPT
368 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
369 return ((wxPostScriptPrintNativeData*)m_nativeData)->GetPrinterTranslateX();
370#endif
371 return 0;
372}
373
374long wxPrintData::GetPrinterTranslateY() const
375{
376#if wxUSE_POSTSCRIPT
377 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
378 return ((wxPostScriptPrintNativeData*)m_nativeData)->GetPrinterTranslateY();
379#endif
380 return 0;
381}
382
fd864f01 383void wxPrintData::SetPrinterCommand(const wxString& WXUNUSED_WITHOUT_PS(command))
0ab2de15
RR
384{
385#if wxUSE_POSTSCRIPT
386 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
387 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPrinterCommand( command );
388#endif
389}
390
fd864f01 391void wxPrintData::SetPrinterOptions(const wxString& WXUNUSED_WITHOUT_PS(options))
0ab2de15
RR
392{
393#if wxUSE_POSTSCRIPT
394 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
395 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPrinterOptions( options );
396#endif
397}
398
fd864f01 399void wxPrintData::SetPreviewCommand(const wxString& WXUNUSED_WITHOUT_PS(command))
0ab2de15
RR
400{
401#if wxUSE_POSTSCRIPT
402 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
403 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPreviewCommand( command );
404#endif
405}
406
fd864f01 407void wxPrintData::SetFontMetricPath(const wxString& WXUNUSED_WITHOUT_PS(path))
0ab2de15
RR
408{
409#if wxUSE_POSTSCRIPT
410 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
411 ((wxPostScriptPrintNativeData*)m_nativeData)->SetFontMetricPath( path );
412#endif
413}
414
fd864f01 415void wxPrintData::SetPrinterScaleX(double WXUNUSED_WITHOUT_PS(x))
0ab2de15
RR
416{
417#if wxUSE_POSTSCRIPT
418 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
419 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPrinterScaleX( x );
420#endif
421}
422
fd864f01 423void wxPrintData::SetPrinterScaleY(double WXUNUSED_WITHOUT_PS(y))
0ab2de15
RR
424{
425#if wxUSE_POSTSCRIPT
426 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
427 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPrinterScaleY( y );
428#endif
429}
430
fd864f01 431void wxPrintData::SetPrinterScaling(double WXUNUSED_WITHOUT_PS(x), double WXUNUSED_WITHOUT_PS(y))
0ab2de15
RR
432{
433#if wxUSE_POSTSCRIPT
434 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
435 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPrinterScaling( x, y );
436#endif
437}
438
fd864f01 439void wxPrintData::SetPrinterTranslateX(long WXUNUSED_WITHOUT_PS(x))
0ab2de15
RR
440{
441#if wxUSE_POSTSCRIPT
442 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
443 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPrinterTranslateX( x );
444#endif
445}
446
fd864f01 447void wxPrintData::SetPrinterTranslateY(long WXUNUSED_WITHOUT_PS(y))
0ab2de15
RR
448{
449#if wxUSE_POSTSCRIPT
450 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
451 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPrinterTranslateY( y );
452#endif
453}
454
fd864f01 455void wxPrintData::SetPrinterTranslation(long WXUNUSED_WITHOUT_PS(x), long WXUNUSED_WITHOUT_PS(y))
0ab2de15
RR
456{
457#if wxUSE_POSTSCRIPT
458 if (m_nativeData && wxIsKindOf(m_nativeData,wxPostScriptPrintNativeData))
459 ((wxPostScriptPrintNativeData*)m_nativeData)->SetPrinterTranslation( x, y );
460#endif
461}
462#endif
463
8826f46f
VZ
464// ----------------------------------------------------------------------------
465// Print dialog data
466// ----------------------------------------------------------------------------
7bcb11d3
JS
467
468wxPrintDialogData::wxPrintDialogData()
469{
7bcb11d3
JS
470 m_printFromPage = 0;
471 m_printToPage = 0;
472 m_printMinPage = 0;
473 m_printMaxPage = 0;
474 m_printNoCopies = 1;
c9d59ee7
WS
475 m_printAllPages = false;
476 m_printCollate = false;
477 m_printToFile = false;
478 m_printSelection = false;
479 m_printEnableSelection = false;
480 m_printEnablePageNumbers = true;
4055ed82 481
9f1316dc
RR
482 wxPrintFactory* factory = wxPrintFactory::GetFactory();
483 m_printEnablePrintToFile = ! factory->HasOwnPrintToFile();
4055ed82 484
c9d59ee7 485 m_printEnableHelp = false;
b45dfd0a 486#if WXWIN_COMPATIBILITY_2_4
c9d59ee7 487 m_printSetupDialog = false;
b45dfd0a 488#endif
7bcb11d3
JS
489}
490
491wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
5e472c1f 492 : wxObject()
7bcb11d3
JS
493{
494 (*this) = dialogData;
495}
496
497wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
498{
d2b354f9 499 m_printFromPage = 1;
7bcb11d3 500 m_printToPage = 0;
d2b354f9
JS
501 m_printMinPage = 1;
502 m_printMaxPage = 9999;
7bcb11d3 503 m_printNoCopies = 1;
c9d59ee7
WS
504 m_printAllPages = false;
505 m_printCollate = false;
506 m_printToFile = false;
507 m_printSelection = false;
508 m_printEnableSelection = false;
509 m_printEnablePageNumbers = true;
510 m_printEnablePrintToFile = true;
511 m_printEnableHelp = false;
b45dfd0a 512#if WXWIN_COMPATIBILITY_2_4
c9d59ee7 513 m_printSetupDialog = false;
b45dfd0a 514#endif
7bcb11d3
JS
515 m_printData = printData;
516}
517
518wxPrintDialogData::~wxPrintDialogData()
519{
7bcb11d3
JS
520}
521
51abe921 522#ifdef __WXMAC__
cfb00da4 523
51abe921
SC
524void wxPrintDialogData::ConvertToNative()
525{
cfb00da4 526 m_printData.ConvertToNative();
746d7582 527 m_printData.m_nativePrintData->TransferFrom( this ) ;
51abe921
SC
528}
529
530void wxPrintDialogData::ConvertFromNative()
531{
cfb00da4 532 m_printData.ConvertFromNative();
746d7582 533 m_printData.m_nativePrintData->TransferTo( this ) ;
51abe921 534}
cfb00da4 535
51abe921
SC
536#endif
537
538
7bcb11d3 539void wxPrintDialogData::operator=(const wxPrintDialogData& data)
c801d85f 540{
7bcb11d3
JS
541 m_printFromPage = data.m_printFromPage;
542 m_printToPage = data.m_printToPage;
543 m_printMinPage = data.m_printMinPage;
544 m_printMaxPage = data.m_printMaxPage;
545 m_printNoCopies = data.m_printNoCopies;
546 m_printAllPages = data.m_printAllPages;
547 m_printCollate = data.m_printCollate;
548 m_printToFile = data.m_printToFile;
5360828d 549 m_printSelection = data.m_printSelection;
7bcb11d3
JS
550 m_printEnableSelection = data.m_printEnableSelection;
551 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
552 m_printEnableHelp = data.m_printEnableHelp;
553 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
b45dfd0a 554#if WXWIN_COMPATIBILITY_2_4
7bcb11d3 555 m_printSetupDialog = data.m_printSetupDialog;
b45dfd0a 556#endif
7bcb11d3
JS
557 m_printData = data.m_printData;
558}
559
560void wxPrintDialogData::operator=(const wxPrintData& data)
561{
562 m_printData = data;
c801d85f
KB
563}
564
8826f46f
VZ
565// ----------------------------------------------------------------------------
566// wxPageSetupDialogData
567// ----------------------------------------------------------------------------
c801d85f 568
7bcb11d3 569wxPageSetupDialogData::wxPageSetupDialogData()
c801d85f 570{
c47addef 571 m_paperSize = wxSize(0,0);
7bcb11d3
JS
572
573 CalculatePaperSizeFromId();
574
2997ca30
WS
575 m_minMarginTopLeft =
576 m_minMarginBottomRight =
577 m_marginTopLeft =
c47addef 578 m_marginBottomRight = wxPoint(0,0);
7bcb11d3
JS
579
580 // Flags
c9d59ee7
WS
581 m_defaultMinMargins = false;
582 m_enableMargins = true;
583 m_enableOrientation = true;
584 m_enablePaper = true;
585 m_enablePrinter = true;
586 m_enableHelp = false;
587 m_getDefaultInfo = false;
7bcb11d3 588}
c801d85f 589
7bcb11d3 590wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
5e472c1f 591 : wxObject()
7bcb11d3
JS
592{
593 (*this) = dialogData;
594}
595
596wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
597{
c47addef 598 m_paperSize = wxSize(0,0);
2997ca30
WS
599 m_minMarginTopLeft =
600 m_minMarginBottomRight =
601 m_marginTopLeft =
c47addef 602 m_marginBottomRight = wxPoint(0,0);
7bcb11d3
JS
603
604 // Flags
c9d59ee7
WS
605 m_defaultMinMargins = false;
606 m_enableMargins = true;
607 m_enableOrientation = true;
608 m_enablePaper = true;
609 m_enablePrinter = true;
610 m_enableHelp = false;
611 m_getDefaultInfo = false;
7bcb11d3
JS
612
613 m_printData = printData;
614
615 // The wxPrintData paper size overrides these values, unless the size cannot
616 // be found.
617 CalculatePaperSizeFromId();
c801d85f
KB
618}
619
7bcb11d3 620wxPageSetupDialogData::~wxPageSetupDialogData()
c801d85f 621{
c801d85f
KB
622}
623
5e472c1f 624wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
c801d85f 625{
7bcb11d3
JS
626 m_paperSize = data.m_paperSize;
627 m_minMarginTopLeft = data.m_minMarginTopLeft;
628 m_minMarginBottomRight = data.m_minMarginBottomRight;
629 m_marginTopLeft = data.m_marginTopLeft;
630 m_marginBottomRight = data.m_marginBottomRight;
631 m_defaultMinMargins = data.m_defaultMinMargins;
632 m_enableMargins = data.m_enableMargins;
633 m_enableOrientation = data.m_enableOrientation;
634 m_enablePaper = data.m_enablePaper;
635 m_enablePrinter = data.m_enablePrinter;
636 m_getDefaultInfo = data.m_getDefaultInfo;;
637 m_enableHelp = data.m_enableHelp;
638
639 m_printData = data.m_printData;
5e472c1f
GD
640
641 return *this;
7bcb11d3 642}
c801d85f 643
5e472c1f 644wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data)
7bcb11d3
JS
645{
646 m_printData = data;
24c5243d 647 CalculatePaperSizeFromId();
5e472c1f
GD
648
649 return *this;
c801d85f
KB
650}
651
51abe921 652#ifdef __WXMAC__
7c74e7fe 653void wxPageSetupDialogData::ConvertToNative()
51abe921 654{
161f4f73 655 m_printData.ConvertToNative();
746d7582 656 m_printData.m_nativePrintData->TransferFrom( this ) ;
51abe921
SC
657}
658
7c74e7fe 659void wxPageSetupDialogData::ConvertFromNative()
51abe921 660{
161f4f73 661 m_printData.ConvertFromNative ();
cfb00da4
SC
662 m_paperSize = m_printData.GetPaperSize() ;
663 CalculateIdFromPaperSize();
746d7582 664 m_printData.m_nativePrintData->TransferTo( this ) ;
161f4f73 665 // adjust minimal values
161f4f73
VZ
666
667 if ( m_marginTopLeft.x < m_minMarginTopLeft.x )
668 m_marginTopLeft.x = m_minMarginTopLeft.x;
669
670 if ( m_marginBottomRight.x < m_minMarginBottomRight.x )
671 m_marginBottomRight.x = m_minMarginBottomRight.x;
672
673 if ( m_marginTopLeft.y < m_minMarginTopLeft.y )
674 m_marginTopLeft.y = m_minMarginTopLeft.y;
675
676 if ( m_marginBottomRight.y < m_minMarginBottomRight.y )
677 m_marginBottomRight.y = m_minMarginBottomRight.y;
51abe921
SC
678}
679#endif
680
681
7bcb11d3
JS
682// If a corresponding paper type is found in the paper database, will set the m_printData
683// paper size id member as well.
684void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
685{
686 m_paperSize = sz;
c801d85f 687
7bcb11d3
JS
688 CalculateIdFromPaperSize();
689}
c801d85f 690
7bcb11d3
JS
691// Sets the wxPrintData id, plus the paper width/height if found in the paper database.
692void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
693{
694 m_printData.SetPaperId(id);
695
696 CalculatePaperSizeFromId();
c801d85f
KB
697}
698
24c5243d
RD
699void wxPageSetupDialogData::SetPrintData(const wxPrintData& printData)
700{
701 m_printData = printData;
b494c48b 702 CalculatePaperSizeFromId();
24c5243d
RD
703}
704
7bcb11d3
JS
705// Use paper size defined in this object to set the wxPrintData
706// paper id
707void wxPageSetupDialogData::CalculateIdFromPaperSize()
c801d85f 708{
8826f46f 709 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
fbdcff4a 710 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
c801d85f 711
7bcb11d3
JS
712 wxSize sz = GetPaperSize();
713
714 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
715 if (id != wxPAPER_NONE)
c801d85f 716 {
7bcb11d3 717 m_printData.SetPaperId(id);
c801d85f
KB
718 }
719}
8826f46f 720
7bcb11d3
JS
721// Use paper id in wxPrintData to set this object's paper size
722void wxPageSetupDialogData::CalculatePaperSizeFromId()
723{
8826f46f 724 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
fbdcff4a 725 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
7bcb11d3
JS
726
727 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
c801d85f 728
01cf2f95
VZ
729 // sz is in 10ths of a mm, while paper size is in mm
730 m_paperSize.x = sz.x / 10;
731 m_paperSize.y = sz.y / 10;
7bcb11d3 732}
8826f46f 733
88ac883a 734#endif // wxUSE_PRINTING_ARCHITECTURE