]>
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 m_nativeData
= data
.GetNativeData();
242 m_nativeData
->m_ref
++;
245 m_nativePrintData
->CopyFrom( data
.m_nativePrintData
) ;
249 // Is this data OK for showing the print dialog?
250 bool wxPrintData::Ok() const
252 m_nativeData
->TransferFrom( *this );
254 return m_nativeData
->Ok();
257 // ----------------------------------------------------------------------------
259 // ----------------------------------------------------------------------------
261 wxPrintDialogData::wxPrintDialogData()
268 m_printAllPages
= false;
269 m_printCollate
= false;
270 m_printToFile
= false;
271 m_printSelection
= false;
272 m_printEnableSelection
= false;
273 m_printEnablePageNumbers
= true;
275 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
276 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
278 m_printEnableHelp
= false;
279 #if WXWIN_COMPATIBILITY_2_4
280 m_printSetupDialog
= false;
284 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
287 (*this) = dialogData
;
290 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
295 m_printMaxPage
= 9999;
297 m_printAllPages
= false;
298 m_printCollate
= false;
299 m_printToFile
= false;
300 m_printSelection
= false;
301 m_printEnableSelection
= false;
302 m_printEnablePageNumbers
= true;
303 m_printEnablePrintToFile
= true;
304 m_printEnableHelp
= false;
305 #if WXWIN_COMPATIBILITY_2_4
306 m_printSetupDialog
= false;
308 m_printData
= printData
;
311 wxPrintDialogData::~wxPrintDialogData()
317 void wxPrintDialogData::ConvertToNative()
319 m_printData
.ConvertToNative();
320 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
323 void wxPrintDialogData::ConvertFromNative()
325 m_printData
.ConvertFromNative();
326 m_printData
.m_nativePrintData
->TransferTo( this ) ;
332 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
334 m_printFromPage
= data
.m_printFromPage
;
335 m_printToPage
= data
.m_printToPage
;
336 m_printMinPage
= data
.m_printMinPage
;
337 m_printMaxPage
= data
.m_printMaxPage
;
338 m_printNoCopies
= data
.m_printNoCopies
;
339 m_printAllPages
= data
.m_printAllPages
;
340 m_printCollate
= data
.m_printCollate
;
341 m_printToFile
= data
.m_printToFile
;
342 m_printSelection
= data
.m_printSelection
;
343 m_printEnableSelection
= data
.m_printEnableSelection
;
344 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
345 m_printEnableHelp
= data
.m_printEnableHelp
;
346 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
347 #if WXWIN_COMPATIBILITY_2_4
348 m_printSetupDialog
= data
.m_printSetupDialog
;
350 m_printData
= data
.m_printData
;
353 void wxPrintDialogData::operator=(const wxPrintData
& data
)
358 // ----------------------------------------------------------------------------
359 // wxPageSetupDialogData
360 // ----------------------------------------------------------------------------
362 wxPageSetupDialogData::wxPageSetupDialogData()
364 m_paperSize
= wxSize(0, 0);
366 CalculatePaperSizeFromId();
368 m_minMarginTopLeft
= wxPoint(0, 0);
369 m_minMarginBottomRight
= wxPoint(0, 0);
370 m_marginTopLeft
= wxPoint(0, 0);
371 m_marginBottomRight
= wxPoint(0, 0);
374 m_defaultMinMargins
= false;
375 m_enableMargins
= true;
376 m_enableOrientation
= true;
377 m_enablePaper
= true;
378 m_enablePrinter
= true;
379 m_enableHelp
= false;
380 m_getDefaultInfo
= false;
383 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
386 (*this) = dialogData
;
389 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
391 m_paperSize
= wxSize(0, 0);
392 m_minMarginTopLeft
= wxPoint(0, 0);
393 m_minMarginBottomRight
= wxPoint(0, 0);
394 m_marginTopLeft
= wxPoint(0, 0);
395 m_marginBottomRight
= wxPoint(0, 0);
398 m_defaultMinMargins
= false;
399 m_enableMargins
= true;
400 m_enableOrientation
= true;
401 m_enablePaper
= true;
402 m_enablePrinter
= true;
403 m_enableHelp
= false;
404 m_getDefaultInfo
= false;
406 m_printData
= printData
;
408 // The wxPrintData paper size overrides these values, unless the size cannot
410 CalculatePaperSizeFromId();
413 wxPageSetupDialogData::~wxPageSetupDialogData()
417 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
419 m_paperSize
= data
.m_paperSize
;
420 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
421 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
422 m_marginTopLeft
= data
.m_marginTopLeft
;
423 m_marginBottomRight
= data
.m_marginBottomRight
;
424 m_defaultMinMargins
= data
.m_defaultMinMargins
;
425 m_enableMargins
= data
.m_enableMargins
;
426 m_enableOrientation
= data
.m_enableOrientation
;
427 m_enablePaper
= data
.m_enablePaper
;
428 m_enablePrinter
= data
.m_enablePrinter
;
429 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
430 m_enableHelp
= data
.m_enableHelp
;
432 m_printData
= data
.m_printData
;
437 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
445 void wxPageSetupDialogData::ConvertToNative()
447 m_printData
.ConvertToNative();
448 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
451 void wxPageSetupDialogData::ConvertFromNative()
453 m_printData
.ConvertFromNative ();
454 m_paperSize
= m_printData
.GetPaperSize() ;
455 CalculateIdFromPaperSize();
456 m_printData
.m_nativePrintData
->TransferTo( this ) ;
457 // adjust minimal values
459 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
460 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
462 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
463 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
465 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
466 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
468 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
469 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
474 // If a corresponding paper type is found in the paper database, will set the m_printData
475 // paper size id member as well.
476 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
480 CalculateIdFromPaperSize();
483 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
484 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
486 m_printData
.SetPaperId(id
);
488 CalculatePaperSizeFromId();
491 // Use paper size defined in this object to set the wxPrintData
493 void wxPageSetupDialogData::CalculateIdFromPaperSize()
495 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
496 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
498 wxSize sz
= GetPaperSize();
500 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
501 if (id
!= wxPAPER_NONE
)
503 m_printData
.SetPaperId(id
);
507 // Use paper id in wxPrintData to set this object's paper size
508 void wxPageSetupDialogData::CalculatePaperSizeFromId()
510 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
511 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
513 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
515 // sz is in 10ths of a mm, while paper size is in mm
516 m_paperSize
.x
= sz
.x
/ 10;
517 m_paperSize
.y
= sz
.y
/ 10;
520 #endif // wxUSE_PRINTING_ARCHITECTURE