]>
git.saurik.com Git - wxWidgets.git/blob - src/common/cmndata.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI data
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "cmndata.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/string.h"
38 #include "wx/gdicmn.h"
39 #include "wx/cmndata.h"
41 #include "wx/prntbase.h"
42 #include "wx/printdlg.h"
45 #include "wx/fontdlg.h"
46 #endif // wxUSE_FONTDLG
48 #if wxUSE_PRINTING_ARCHITECTURE
50 #endif // wxUSE_PRINTING_ARCHITECTURE
52 #if defined(__WXMSW__) && !defined(__PALMOS__)
54 #include "wx/msw/private.h"
56 #ifndef __SMARTPHONE__ /* of WinCE */
60 #if defined(__WATCOMC__) || defined(__SYMANTEC__) || defined(__SALFORDC__)
67 #include "wx/mac/private/print.h"
70 #if wxUSE_PRINTING_ARCHITECTURE
71 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
72 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
73 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
74 #endif // wxUSE_PRINTING_ARCHITECTURE
76 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
77 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
80 #define DMPAPER_USER 256
83 // ============================================================================
85 // ============================================================================
87 // ----------------------------------------------------------------------------
89 // ----------------------------------------------------------------------------
91 wxColourData::wxColourData()
94 m_dataColour
.Set(0,0,0);
95 // m_custColours are wxNullColours initially
98 wxColourData::wxColourData(const wxColourData
& data
)
104 wxColourData::~wxColourData()
108 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
110 wxCHECK_RET( (i
>= 0 && i
< 16), _T("custom colour index out of range") );
112 m_custColours
[i
] = colour
;
115 wxColour
wxColourData::GetCustomColour(int i
)
117 wxCHECK_MSG( (i
>= 0 && i
< 16), wxColour(0,0,0),
118 _T("custom colour index out of range") );
120 return m_custColours
[i
];
123 void wxColourData::operator=(const wxColourData
& data
)
126 for (i
= 0; i
< 16; i
++)
127 m_custColours
[i
] = data
.m_custColours
[i
];
129 m_dataColour
= (wxColour
&)data
.m_dataColour
;
130 m_chooseFull
= data
.m_chooseFull
;
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 wxFontData::wxFontData()
139 // Intialize colour to black.
140 m_fontColour
= wxNullColour
;
143 m_allowSymbols
= true;
144 m_enableEffects
= true;
148 m_encoding
= wxFONTENCODING_SYSTEM
;
151 wxFontData::~wxFontData()
157 wxFontDialogBase::~wxFontDialogBase()
161 #endif // wxUSE_FONTDLG
163 #if wxUSE_PRINTING_ARCHITECTURE
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 wxPrintData::wxPrintData()
171 m_nativePrintData
= wxNativePrintData::Create() ;
173 m_bin
= wxPRINTBIN_DEFAULT
;
174 m_printMode
= wxPRINT_MODE_PRINTER
;
175 m_printOrientation
= wxPORTRAIT
;
177 m_printCollate
= false;
180 m_printerName
= wxT("");
182 m_duplexMode
= wxDUPLEX_SIMPLEX
;
183 m_printQuality
= wxPRINT_QUALITY_HIGH
;
184 m_paperId
= wxPAPER_A4
;
185 m_paperSize
= wxSize(210, 297);
187 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
190 wxPrintData::wxPrintData(const wxPrintData
& printData
)
196 wxPrintData::~wxPrintData()
198 m_nativeData
->m_ref
--;
199 if (m_nativeData
->m_ref
== 0)
203 delete m_nativePrintData
;
208 void wxPrintData::ConvertToNative()
211 m_nativePrintData
->TransferFrom( this ) ;
213 m_nativeData
->TransferFrom( *this ) ;
217 void wxPrintData::ConvertFromNative()
220 m_nativePrintData
->TransferTo( this ) ;
222 m_nativeData
->TransferTo( *this ) ;
226 void wxPrintData::operator=(const wxPrintData
& data
)
228 m_printNoCopies
= data
.m_printNoCopies
;
229 m_printCollate
= data
.m_printCollate
;
230 m_printOrientation
= data
.m_printOrientation
;
231 m_printerName
= data
.m_printerName
;
232 m_colour
= data
.m_colour
;
233 m_duplexMode
= data
.m_duplexMode
;
234 m_printQuality
= data
.m_printQuality
;
235 m_paperId
= data
.m_paperId
;
236 m_paperSize
= data
.m_paperSize
;
238 m_printMode
= data
.m_printMode
;
239 m_filename
= data
.m_filename
;
241 // UnRef old m_nativeData
242 m_nativeData
->m_ref
--;
243 if (m_nativeData
->m_ref
== 0)
246 m_nativeData
= data
.GetNativeData();
247 m_nativeData
->m_ref
++;
250 m_nativePrintData
->CopyFrom( data
.m_nativePrintData
) ;
254 // Is this data OK for showing the print dialog?
255 bool wxPrintData::Ok() const
257 m_nativeData
->TransferFrom( *this );
259 return m_nativeData
->Ok();
262 // ----------------------------------------------------------------------------
264 // ----------------------------------------------------------------------------
266 wxPrintDialogData::wxPrintDialogData()
273 m_printAllPages
= false;
274 m_printCollate
= false;
275 m_printToFile
= false;
276 m_printSelection
= false;
277 m_printEnableSelection
= false;
278 m_printEnablePageNumbers
= true;
280 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
281 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
283 m_printEnableHelp
= false;
284 #if WXWIN_COMPATIBILITY_2_4
285 m_printSetupDialog
= false;
289 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
292 (*this) = dialogData
;
295 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
300 m_printMaxPage
= 9999;
302 m_printAllPages
= false;
303 m_printCollate
= false;
304 m_printToFile
= false;
305 m_printSelection
= false;
306 m_printEnableSelection
= false;
307 m_printEnablePageNumbers
= true;
308 m_printEnablePrintToFile
= true;
309 m_printEnableHelp
= false;
310 #if WXWIN_COMPATIBILITY_2_4
311 m_printSetupDialog
= false;
313 m_printData
= printData
;
316 wxPrintDialogData::~wxPrintDialogData()
322 void wxPrintDialogData::ConvertToNative()
324 m_printData
.ConvertToNative();
325 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
328 void wxPrintDialogData::ConvertFromNative()
330 m_printData
.ConvertFromNative();
331 m_printData
.m_nativePrintData
->TransferTo( this ) ;
337 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
339 m_printFromPage
= data
.m_printFromPage
;
340 m_printToPage
= data
.m_printToPage
;
341 m_printMinPage
= data
.m_printMinPage
;
342 m_printMaxPage
= data
.m_printMaxPage
;
343 m_printNoCopies
= data
.m_printNoCopies
;
344 m_printAllPages
= data
.m_printAllPages
;
345 m_printCollate
= data
.m_printCollate
;
346 m_printToFile
= data
.m_printToFile
;
347 m_printSelection
= data
.m_printSelection
;
348 m_printEnableSelection
= data
.m_printEnableSelection
;
349 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
350 m_printEnableHelp
= data
.m_printEnableHelp
;
351 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
352 #if WXWIN_COMPATIBILITY_2_4
353 m_printSetupDialog
= data
.m_printSetupDialog
;
355 m_printData
= data
.m_printData
;
358 void wxPrintDialogData::operator=(const wxPrintData
& data
)
363 // ----------------------------------------------------------------------------
364 // wxPageSetupDialogData
365 // ----------------------------------------------------------------------------
367 wxPageSetupDialogData::wxPageSetupDialogData()
369 m_paperSize
= wxSize(0, 0);
371 CalculatePaperSizeFromId();
373 m_minMarginTopLeft
= wxPoint(0, 0);
374 m_minMarginBottomRight
= wxPoint(0, 0);
375 m_marginTopLeft
= wxPoint(0, 0);
376 m_marginBottomRight
= wxPoint(0, 0);
379 m_defaultMinMargins
= false;
380 m_enableMargins
= true;
381 m_enableOrientation
= true;
382 m_enablePaper
= true;
383 m_enablePrinter
= true;
384 m_enableHelp
= false;
385 m_getDefaultInfo
= false;
388 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
391 (*this) = dialogData
;
394 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
396 m_paperSize
= wxSize(0, 0);
397 m_minMarginTopLeft
= wxPoint(0, 0);
398 m_minMarginBottomRight
= wxPoint(0, 0);
399 m_marginTopLeft
= wxPoint(0, 0);
400 m_marginBottomRight
= wxPoint(0, 0);
403 m_defaultMinMargins
= false;
404 m_enableMargins
= true;
405 m_enableOrientation
= true;
406 m_enablePaper
= true;
407 m_enablePrinter
= true;
408 m_enableHelp
= false;
409 m_getDefaultInfo
= false;
411 m_printData
= printData
;
413 // The wxPrintData paper size overrides these values, unless the size cannot
415 CalculatePaperSizeFromId();
418 wxPageSetupDialogData::~wxPageSetupDialogData()
422 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
424 m_paperSize
= data
.m_paperSize
;
425 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
426 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
427 m_marginTopLeft
= data
.m_marginTopLeft
;
428 m_marginBottomRight
= data
.m_marginBottomRight
;
429 m_defaultMinMargins
= data
.m_defaultMinMargins
;
430 m_enableMargins
= data
.m_enableMargins
;
431 m_enableOrientation
= data
.m_enableOrientation
;
432 m_enablePaper
= data
.m_enablePaper
;
433 m_enablePrinter
= data
.m_enablePrinter
;
434 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
435 m_enableHelp
= data
.m_enableHelp
;
437 m_printData
= data
.m_printData
;
442 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
450 void wxPageSetupDialogData::ConvertToNative()
452 m_printData
.ConvertToNative();
453 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
456 void wxPageSetupDialogData::ConvertFromNative()
458 m_printData
.ConvertFromNative ();
459 m_paperSize
= m_printData
.GetPaperSize() ;
460 CalculateIdFromPaperSize();
461 m_printData
.m_nativePrintData
->TransferTo( this ) ;
462 // adjust minimal values
464 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
465 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
467 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
468 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
470 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
471 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
473 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
474 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
479 // If a corresponding paper type is found in the paper database, will set the m_printData
480 // paper size id member as well.
481 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
485 CalculateIdFromPaperSize();
488 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
489 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
491 m_printData
.SetPaperId(id
);
493 CalculatePaperSizeFromId();
496 // Use paper size defined in this object to set the wxPrintData
498 void wxPageSetupDialogData::CalculateIdFromPaperSize()
500 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
501 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
503 wxSize sz
= GetPaperSize();
505 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
506 if (id
!= wxPAPER_NONE
)
508 m_printData
.SetPaperId(id
);
512 // Use paper id in wxPrintData to set this object's paper size
513 void wxPageSetupDialogData::CalculatePaperSizeFromId()
515 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
516 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
518 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
520 // sz is in 10ths of a mm, while paper size is in mm
521 m_paperSize
.x
= sz
.x
/ 10;
522 m_paperSize
.y
= sz
.y
/ 10;
525 #endif // wxUSE_PRINTING_ARCHITECTURE