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