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
53 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
54 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
55 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
57 #endif // wxUSE_PRINTING_ARCHITECTURE
59 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
60 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
62 // ============================================================================
64 // ============================================================================
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 wxColourData::wxColourData()
73 m_dataColour
.Set(0,0,0);
74 // m_custColours are wxNullColours initially
77 wxColourData::wxColourData(const wxColourData
& data
)
83 wxColourData::~wxColourData()
87 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
89 wxCHECK_RET( i
>= 0 && i
< NUM_CUSTOM
, _T("custom colour index out of range") );
91 m_custColours
[i
] = colour
;
94 wxColour
wxColourData::GetCustomColour(int i
)
96 wxCHECK_MSG( i
>= 0 && i
< NUM_CUSTOM
, wxColour(0,0,0),
97 _T("custom colour index out of range") );
99 return m_custColours
[i
];
102 wxColourData
& wxColourData::operator=(const wxColourData
& data
)
104 for ( int i
= 0; i
< NUM_CUSTOM
; i
++)
105 m_custColours
[i
] = data
.m_custColours
[i
];
107 m_dataColour
= data
.m_dataColour
;
108 m_chooseFull
= data
.m_chooseFull
;
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 // separator used between different fields
118 static const char wxCOL_DATA_SEP
= ',';
120 wxString
wxColourData::ToString() const
122 wxString
str(m_chooseFull
? '1' : '0');
124 for ( int i
= 0; i
< NUM_CUSTOM
; i
++ )
126 str
+= wxCOL_DATA_SEP
;
128 const wxColour
& clr
= m_custColours
[i
];
130 str
+= clr
.GetAsString(wxC2S_HTML_SYNTAX
);
136 bool wxColourData::FromString(const wxString
& str
)
139 int n
= -1; // index of the field, -1 corresponds to m_chooseFull
140 for ( wxString::const_iterator i
= str
.begin(); i
!= str
.end(); ++i
)
142 if ( *i
== wxCOL_DATA_SEP
)
147 m_chooseFull
= false;
148 else if ( token
== '1' )
150 else // only '0' and '1' are used in ToString()
153 else // custom colour
155 if ( n
== WXSIZEOF(m_custColours
) )
156 return false; // too many custom colours
158 // empty strings are used by ToString() for colours not used
160 m_custColours
[n
] = wxNullColour
;
161 else if ( !m_custColours
[n
].Set(token
) )
162 return false; // invalid colour string
168 else // continuation of the current field
177 // ----------------------------------------------------------------------------
179 // ----------------------------------------------------------------------------
181 wxFontData::wxFontData()
183 // Intialize colour to black.
184 m_fontColour
= wxNullColour
;
187 m_allowSymbols
= true;
188 m_enableEffects
= true;
192 m_encoding
= wxFONTENCODING_SYSTEM
;
195 wxFontData::~wxFontData()
201 wxFontDialogBase::~wxFontDialogBase()
205 #endif // wxUSE_FONTDLG
207 #if wxUSE_PRINTING_ARCHITECTURE
208 // ----------------------------------------------------------------------------
210 // ----------------------------------------------------------------------------
212 wxPrintData::wxPrintData()
214 m_bin
= wxPRINTBIN_DEFAULT
;
215 m_media
= wxPRINTMEDIA_DEFAULT
;
216 m_printMode
= wxPRINT_MODE_PRINTER
;
217 m_printOrientation
= wxPORTRAIT
;
218 m_printOrientationReversed
= false;
220 m_printCollate
= false;
223 m_printerName
= wxEmptyString
;
225 m_duplexMode
= wxDUPLEX_SIMPLEX
;
226 m_printQuality
= wxPRINT_QUALITY_HIGH
;
228 // we intentionally don't initialize paper id and size at all, like this
229 // the default system settings will be used for them
230 m_paperId
= wxPAPER_NONE
;
231 m_paperSize
= wxDefaultSize
;
236 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
239 wxPrintData::wxPrintData(const wxPrintData
& printData
)
247 void wxPrintData::SetPrivData( char *privData
, int len
)
251 delete [] m_privData
;
255 if (m_privDataLen
> 0)
257 m_privData
= new char[m_privDataLen
];
258 memcpy( m_privData
, privData
, m_privDataLen
);
262 wxPrintData::~wxPrintData()
264 m_nativeData
->m_ref
--;
265 if (m_nativeData
->m_ref
== 0)
269 delete [] m_privData
;
272 void wxPrintData::ConvertToNative()
274 m_nativeData
->TransferFrom( *this ) ;
277 void wxPrintData::ConvertFromNative()
279 m_nativeData
->TransferTo( *this ) ;
282 void wxPrintData::operator=(const wxPrintData
& data
)
284 m_printNoCopies
= data
.m_printNoCopies
;
285 m_printCollate
= data
.m_printCollate
;
286 m_printOrientation
= data
.m_printOrientation
;
287 m_printOrientationReversed
= data
.m_printOrientationReversed
;
288 m_printerName
= data
.m_printerName
;
289 m_colour
= data
.m_colour
;
290 m_duplexMode
= data
.m_duplexMode
;
291 m_printQuality
= data
.m_printQuality
;
292 m_paperId
= data
.m_paperId
;
293 m_paperSize
= data
.m_paperSize
;
295 m_media
= data
.m_media
;
296 m_printMode
= data
.m_printMode
;
297 m_filename
= data
.m_filename
;
299 // UnRef old m_nativeData
302 m_nativeData
->m_ref
--;
303 if (m_nativeData
->m_ref
== 0)
307 m_nativeData
= data
.GetNativeData();
308 m_nativeData
->m_ref
++;
312 delete [] m_privData
;
315 m_privDataLen
= data
.GetPrivDataLen();
316 if (m_privDataLen
> 0)
318 m_privData
= new char[m_privDataLen
];
319 memcpy( m_privData
, data
.GetPrivData(), m_privDataLen
);
323 // Is this data OK for showing the print dialog?
324 bool wxPrintData::IsOk() const
326 m_nativeData
->TransferFrom( *this );
328 return m_nativeData
->Ok();
331 // ----------------------------------------------------------------------------
333 // ----------------------------------------------------------------------------
335 wxPrintDialogData::wxPrintDialogData()
342 m_printAllPages
= false;
343 m_printCollate
= false;
344 m_printToFile
= false;
345 m_printSelection
= false;
346 m_printEnableSelection
= false;
347 m_printEnablePageNumbers
= true;
349 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
350 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
352 m_printEnableHelp
= false;
355 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
358 (*this) = dialogData
;
361 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
366 m_printMaxPage
= 9999;
368 m_printAllPages
= false;
369 m_printCollate
= false;
370 m_printToFile
= false;
371 m_printSelection
= false;
372 m_printEnableSelection
= false;
373 m_printEnablePageNumbers
= true;
374 m_printEnablePrintToFile
= true;
375 m_printEnableHelp
= false;
376 m_printData
= printData
;
379 wxPrintDialogData::~wxPrintDialogData()
383 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
385 m_printFromPage
= data
.m_printFromPage
;
386 m_printToPage
= data
.m_printToPage
;
387 m_printMinPage
= data
.m_printMinPage
;
388 m_printMaxPage
= data
.m_printMaxPage
;
389 m_printNoCopies
= data
.m_printNoCopies
;
390 m_printAllPages
= data
.m_printAllPages
;
391 m_printCollate
= data
.m_printCollate
;
392 m_printToFile
= data
.m_printToFile
;
393 m_printSelection
= data
.m_printSelection
;
394 m_printEnableSelection
= data
.m_printEnableSelection
;
395 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
396 m_printEnableHelp
= data
.m_printEnableHelp
;
397 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
398 m_printData
= data
.m_printData
;
401 void wxPrintDialogData::operator=(const wxPrintData
& data
)
406 // ----------------------------------------------------------------------------
407 // wxPageSetupDialogData
408 // ----------------------------------------------------------------------------
410 wxPageSetupDialogData::wxPageSetupDialogData()
412 m_paperSize
= wxSize(0,0);
414 CalculatePaperSizeFromId();
417 m_minMarginBottomRight
=
419 m_marginBottomRight
= wxPoint(0,0);
422 m_defaultMinMargins
= false;
423 m_enableMargins
= true;
424 m_enableOrientation
= true;
425 m_enablePaper
= true;
426 m_enablePrinter
= true;
427 m_enableHelp
= false;
428 m_getDefaultInfo
= false;
431 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
434 (*this) = dialogData
;
437 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
439 m_paperSize
= wxSize(0,0);
441 m_minMarginBottomRight
=
443 m_marginBottomRight
= wxPoint(0,0);
446 m_defaultMinMargins
= false;
447 m_enableMargins
= true;
448 m_enableOrientation
= true;
449 m_enablePaper
= true;
450 m_enablePrinter
= true;
451 m_enableHelp
= false;
452 m_getDefaultInfo
= false;
454 m_printData
= printData
;
456 // The wxPrintData paper size overrides these values, unless the size cannot
458 CalculatePaperSizeFromId();
461 wxPageSetupDialogData::~wxPageSetupDialogData()
465 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
467 m_paperSize
= data
.m_paperSize
;
468 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
469 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
470 m_marginTopLeft
= data
.m_marginTopLeft
;
471 m_marginBottomRight
= data
.m_marginBottomRight
;
472 m_defaultMinMargins
= data
.m_defaultMinMargins
;
473 m_enableMargins
= data
.m_enableMargins
;
474 m_enableOrientation
= data
.m_enableOrientation
;
475 m_enablePaper
= data
.m_enablePaper
;
476 m_enablePrinter
= data
.m_enablePrinter
;
477 m_getDefaultInfo
= data
.m_getDefaultInfo
;
478 m_enableHelp
= data
.m_enableHelp
;
480 m_printData
= data
.m_printData
;
485 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
488 CalculatePaperSizeFromId();
493 // If a corresponding paper type is found in the paper database, will set the m_printData
494 // paper size id member as well.
495 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
499 CalculateIdFromPaperSize();
502 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
503 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
505 m_printData
.SetPaperId(id
);
507 CalculatePaperSizeFromId();
510 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
512 m_printData
= printData
;
513 CalculatePaperSizeFromId();
516 // Use paper size defined in this object to set the wxPrintData
518 void wxPageSetupDialogData::CalculateIdFromPaperSize()
520 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
521 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
523 wxSize sz
= GetPaperSize();
525 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
526 if (id
!= wxPAPER_NONE
)
528 m_printData
.SetPaperId(id
);
532 // Use paper id in wxPrintData to set this object's paper size
533 void wxPageSetupDialogData::CalculatePaperSizeFromId()
535 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
536 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
538 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
540 // sz is in 10ths of a mm, while paper size is in mm
541 m_paperSize
.x
= sz
.x
/ 10;
542 m_paperSize
.y
= sz
.y
/ 10;
545 #endif // wxUSE_PRINTING_ARCHITECTURE