1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/cmndata.cpp
3 // Purpose: Common GDI data
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/cmndata.h"
30 #if defined(__WXMSW__)
31 #include "wx/msw/wrapcdlg.h"
34 #include "wx/string.h"
38 #include "wx/gdicmn.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
52 #if defined(__WXMAC__)
53 #include "wx/mac/private/print.h"
56 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
57 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
58 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
60 #endif // wxUSE_PRINTING_ARCHITECTURE
62 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
63 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
65 // ============================================================================
67 // ============================================================================
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
73 wxColourData::wxColourData()
76 m_dataColour
.Set(0,0,0);
77 // m_custColours are wxNullColours initially
80 wxColourData::wxColourData(const wxColourData
& data
)
86 wxColourData::~wxColourData()
90 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
92 wxCHECK_RET( i
>= 0 && i
< NUM_CUSTOM
, _T("custom colour index out of range") );
94 m_custColours
[i
] = colour
;
97 wxColour
wxColourData::GetCustomColour(int i
)
99 wxCHECK_MSG( i
>= 0 && i
< NUM_CUSTOM
, wxColour(0,0,0),
100 _T("custom colour index out of range") );
102 return m_custColours
[i
];
105 wxColourData
& wxColourData::operator=(const wxColourData
& data
)
107 for ( int i
= 0; i
< NUM_CUSTOM
; i
++)
108 m_custColours
[i
] = data
.m_custColours
[i
];
110 m_dataColour
= data
.m_dataColour
;
111 m_chooseFull
= data
.m_chooseFull
;
116 // ----------------------------------------------------------------------------
118 // ----------------------------------------------------------------------------
120 // separator used between different fields
121 static const char wxCOL_DATA_SEP
= ',';
123 wxString
wxColourData::ToString() const
125 wxString
str(m_chooseFull
? '1' : '0');
127 for ( int i
= 0; i
< NUM_CUSTOM
; i
++ )
129 str
+= wxCOL_DATA_SEP
;
131 const wxColour
& clr
= m_custColours
[i
];
133 str
+= clr
.GetAsString(wxC2S_HTML_SYNTAX
);
139 bool wxColourData::FromString(const wxString
& str
)
142 int n
= -1; // index of the field, -1 corresponds to m_chooseFull
143 for ( wxString::const_iterator i
= str
.begin(); i
!= str
.end(); ++i
)
145 if ( *i
== wxCOL_DATA_SEP
)
150 m_chooseFull
= false;
151 else if ( token
== '1' )
153 else // only '0' and '1' are used in ToString()
156 else // custom colour
158 if ( n
== WXSIZEOF(m_custColours
) )
159 return false; // too many custom colours
161 // empty strings are used by ToString() for colours not used
163 m_custColours
[n
] = wxNullColour
;
164 else if ( !m_custColours
[n
].Set(token
) )
165 return false; // invalid colour string
171 else // continuation of the current field
180 // ----------------------------------------------------------------------------
182 // ----------------------------------------------------------------------------
184 wxFontData::wxFontData()
186 // Intialize colour to black.
187 m_fontColour
= wxNullColour
;
190 m_allowSymbols
= true;
191 m_enableEffects
= true;
195 m_encoding
= wxFONTENCODING_SYSTEM
;
198 wxFontData::~wxFontData()
204 wxFontDialogBase::~wxFontDialogBase()
208 #endif // wxUSE_FONTDLG
210 #if wxUSE_PRINTING_ARCHITECTURE
211 // ----------------------------------------------------------------------------
213 // ----------------------------------------------------------------------------
215 wxPrintData::wxPrintData()
217 m_bin
= wxPRINTBIN_DEFAULT
;
218 m_media
= wxPRINTMEDIA_DEFAULT
;
219 m_printMode
= wxPRINT_MODE_PRINTER
;
220 m_printOrientation
= wxPORTRAIT
;
221 m_printOrientationReversed
= false;
223 m_printCollate
= false;
226 m_printerName
= wxEmptyString
;
228 m_duplexMode
= wxDUPLEX_SIMPLEX
;
229 m_printQuality
= wxPRINT_QUALITY_HIGH
;
231 // we intentionally don't initialize paper id and size at all, like this
232 // the default system settings will be used for them
233 m_paperId
= wxPAPER_NONE
;
234 m_paperSize
= wxDefaultSize
;
239 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
242 wxPrintData::wxPrintData(const wxPrintData
& printData
)
250 void wxPrintData::SetPrivData( char *privData
, int len
)
254 delete [] m_privData
;
258 if (m_privDataLen
> 0)
260 m_privData
= new char[m_privDataLen
];
261 memcpy( m_privData
, privData
, m_privDataLen
);
265 wxPrintData::~wxPrintData()
267 m_nativeData
->m_ref
--;
268 if (m_nativeData
->m_ref
== 0)
272 delete [] m_privData
;
275 void wxPrintData::ConvertToNative()
277 m_nativeData
->TransferFrom( *this ) ;
280 void wxPrintData::ConvertFromNative()
282 m_nativeData
->TransferTo( *this ) ;
285 void wxPrintData::operator=(const wxPrintData
& data
)
287 m_printNoCopies
= data
.m_printNoCopies
;
288 m_printCollate
= data
.m_printCollate
;
289 m_printOrientation
= data
.m_printOrientation
;
290 m_printOrientationReversed
= data
.m_printOrientationReversed
;
291 m_printerName
= data
.m_printerName
;
292 m_colour
= data
.m_colour
;
293 m_duplexMode
= data
.m_duplexMode
;
294 m_printQuality
= data
.m_printQuality
;
295 m_paperId
= data
.m_paperId
;
296 m_paperSize
= data
.m_paperSize
;
298 m_media
= data
.m_media
;
299 m_printMode
= data
.m_printMode
;
300 m_filename
= data
.m_filename
;
302 // UnRef old m_nativeData
305 m_nativeData
->m_ref
--;
306 if (m_nativeData
->m_ref
== 0)
310 m_nativeData
= data
.GetNativeData();
311 m_nativeData
->m_ref
++;
315 delete [] m_privData
;
318 m_privDataLen
= data
.GetPrivDataLen();
319 if (m_privDataLen
> 0)
321 m_privData
= new char[m_privDataLen
];
322 memcpy( m_privData
, data
.GetPrivData(), m_privDataLen
);
326 // Is this data OK for showing the print dialog?
327 bool wxPrintData::IsOk() const
329 m_nativeData
->TransferFrom( *this );
331 return m_nativeData
->Ok();
334 // ----------------------------------------------------------------------------
336 // ----------------------------------------------------------------------------
338 wxPrintDialogData::wxPrintDialogData()
345 m_printAllPages
= false;
346 m_printCollate
= false;
347 m_printToFile
= false;
348 m_printSelection
= false;
349 m_printEnableSelection
= false;
350 m_printEnablePageNumbers
= true;
352 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
353 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
355 m_printEnableHelp
= false;
358 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
361 (*this) = dialogData
;
364 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
369 m_printMaxPage
= 9999;
371 m_printAllPages
= false;
372 m_printCollate
= false;
373 m_printToFile
= false;
374 m_printSelection
= false;
375 m_printEnableSelection
= false;
376 m_printEnablePageNumbers
= true;
377 m_printEnablePrintToFile
= true;
378 m_printEnableHelp
= false;
379 m_printData
= printData
;
382 wxPrintDialogData::~wxPrintDialogData()
386 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
388 m_printFromPage
= data
.m_printFromPage
;
389 m_printToPage
= data
.m_printToPage
;
390 m_printMinPage
= data
.m_printMinPage
;
391 m_printMaxPage
= data
.m_printMaxPage
;
392 m_printNoCopies
= data
.m_printNoCopies
;
393 m_printAllPages
= data
.m_printAllPages
;
394 m_printCollate
= data
.m_printCollate
;
395 m_printToFile
= data
.m_printToFile
;
396 m_printSelection
= data
.m_printSelection
;
397 m_printEnableSelection
= data
.m_printEnableSelection
;
398 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
399 m_printEnableHelp
= data
.m_printEnableHelp
;
400 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
401 m_printData
= data
.m_printData
;
404 void wxPrintDialogData::operator=(const wxPrintData
& data
)
409 // ----------------------------------------------------------------------------
410 // wxPageSetupDialogData
411 // ----------------------------------------------------------------------------
413 wxPageSetupDialogData::wxPageSetupDialogData()
415 m_paperSize
= wxSize(0,0);
417 CalculatePaperSizeFromId();
420 m_minMarginBottomRight
=
422 m_marginBottomRight
= wxPoint(0,0);
425 m_defaultMinMargins
= false;
426 m_enableMargins
= true;
427 m_enableOrientation
= true;
428 m_enablePaper
= true;
429 m_enablePrinter
= true;
430 m_enableHelp
= false;
431 m_getDefaultInfo
= false;
434 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
437 (*this) = dialogData
;
440 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
442 m_paperSize
= wxSize(0,0);
444 m_minMarginBottomRight
=
446 m_marginBottomRight
= wxPoint(0,0);
449 m_defaultMinMargins
= false;
450 m_enableMargins
= true;
451 m_enableOrientation
= true;
452 m_enablePaper
= true;
453 m_enablePrinter
= true;
454 m_enableHelp
= false;
455 m_getDefaultInfo
= false;
457 m_printData
= printData
;
459 // The wxPrintData paper size overrides these values, unless the size cannot
461 CalculatePaperSizeFromId();
464 wxPageSetupDialogData::~wxPageSetupDialogData()
468 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
470 m_paperSize
= data
.m_paperSize
;
471 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
472 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
473 m_marginTopLeft
= data
.m_marginTopLeft
;
474 m_marginBottomRight
= data
.m_marginBottomRight
;
475 m_defaultMinMargins
= data
.m_defaultMinMargins
;
476 m_enableMargins
= data
.m_enableMargins
;
477 m_enableOrientation
= data
.m_enableOrientation
;
478 m_enablePaper
= data
.m_enablePaper
;
479 m_enablePrinter
= data
.m_enablePrinter
;
480 m_getDefaultInfo
= data
.m_getDefaultInfo
;
481 m_enableHelp
= data
.m_enableHelp
;
483 m_printData
= data
.m_printData
;
488 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
491 CalculatePaperSizeFromId();
496 // If a corresponding paper type is found in the paper database, will set the m_printData
497 // paper size id member as well.
498 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
502 CalculateIdFromPaperSize();
505 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
506 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
508 m_printData
.SetPaperId(id
);
510 CalculatePaperSizeFromId();
513 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
515 m_printData
= printData
;
516 CalculatePaperSizeFromId();
519 // Use paper size defined in this object to set the wxPrintData
521 void wxPageSetupDialogData::CalculateIdFromPaperSize()
523 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
524 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
526 wxSize sz
= GetPaperSize();
528 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
529 if (id
!= wxPAPER_NONE
)
531 m_printData
.SetPaperId(id
);
535 // Use paper id in wxPrintData to set this object's paper size
536 void wxPageSetupDialogData::CalculatePaperSizeFromId()
538 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
539 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
541 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
543 // sz is in 10ths of a mm, while paper size is in mm
544 m_paperSize
.x
= sz
.x
/ 10;
545 m_paperSize
.y
= sz
.y
/ 10;
548 #endif // wxUSE_PRINTING_ARCHITECTURE