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