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
< WXSIZEOF(m_custColours
)), _T("custom colour index out of range") );
94 m_custColours
[i
] = colour
;
97 wxColour
wxColourData::GetCustomColour(int i
)
99 wxCHECK_MSG( (i
>= 0 && i
< WXSIZEOF(m_custColours
)), wxColour(0,0,0),
100 _T("custom colour index out of range") );
102 return m_custColours
[i
];
105 void wxColourData::operator=(const wxColourData
& data
)
107 for (int i
= 0; i
< WXSIZEOF(m_custColours
); i
++)
108 m_custColours
[i
] = data
.m_custColours
[i
];
110 m_dataColour
= data
.m_dataColour
;
111 m_chooseFull
= data
.m_chooseFull
;
114 // ----------------------------------------------------------------------------
116 // ----------------------------------------------------------------------------
118 // separator used between different fields
119 static const char wxCOL_DATA_SEP
= ',';
121 wxString
wxColourData::ToString() const
123 wxString
str(m_chooseFull
? '1' : '0');
125 for ( int i
= 0; i
< WXSIZEOF(m_custColours
); i
++ )
127 str
+= wxCOL_DATA_SEP
;
129 const wxColour
& clr
= m_custColours
[i
];
131 str
+= clr
.GetAsString(wxC2S_HTML_SYNTAX
);
137 bool wxColourData::FromString(const wxString
& str
)
140 int n
= -1; // index of the field, -1 corresponds to m_chooseFull
141 for ( wxString::const_iterator i
= str
.begin(); i
!= str
.end(); ++i
)
143 if ( *i
== wxCOL_DATA_SEP
)
148 m_chooseFull
= false;
149 else if ( token
== '1' )
151 else // only '0' and '1' are used in ToString()
154 else // custom colour
156 if ( n
== WXSIZEOF(m_custColours
) )
157 return false; // too many custom colours
159 // empty strings are used by ToString() for colours not used
161 m_custColours
[n
] = wxNullColour
;
162 else if ( !m_custColours
[n
].Set(token
) )
163 return false; // invalid colour string
169 else // continuation of the current field
178 // ----------------------------------------------------------------------------
180 // ----------------------------------------------------------------------------
182 wxFontData::wxFontData()
184 // Intialize colour to black.
185 m_fontColour
= wxNullColour
;
188 m_allowSymbols
= true;
189 m_enableEffects
= true;
193 m_encoding
= wxFONTENCODING_SYSTEM
;
196 wxFontData::~wxFontData()
202 wxFontDialogBase::~wxFontDialogBase()
206 #endif // wxUSE_FONTDLG
208 #if wxUSE_PRINTING_ARCHITECTURE
209 // ----------------------------------------------------------------------------
211 // ----------------------------------------------------------------------------
213 wxPrintData::wxPrintData()
215 m_bin
= wxPRINTBIN_DEFAULT
;
216 m_media
= wxPRINTMEDIA_DEFAULT
;
217 m_printMode
= wxPRINT_MODE_PRINTER
;
218 m_printOrientation
= wxPORTRAIT
;
219 m_printOrientationReversed
= false;
221 m_printCollate
= false;
224 m_printerName
= wxEmptyString
;
226 m_duplexMode
= wxDUPLEX_SIMPLEX
;
227 m_printQuality
= wxPRINT_QUALITY_HIGH
;
229 // we intentionally don't initialize paper id and size at all, like this
230 // the default system settings will be used for them
231 m_paperId
= wxPAPER_NONE
;
232 m_paperSize
= wxDefaultSize
;
237 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
240 wxPrintData::wxPrintData(const wxPrintData
& printData
)
248 void wxPrintData::SetPrivData( char *privData
, int len
)
252 delete [] m_privData
;
256 if (m_privDataLen
> 0)
258 m_privData
= new char[m_privDataLen
];
259 memcpy( m_privData
, privData
, m_privDataLen
);
263 wxPrintData::~wxPrintData()
265 m_nativeData
->m_ref
--;
266 if (m_nativeData
->m_ref
== 0)
270 delete [] m_privData
;
273 void wxPrintData::ConvertToNative()
275 m_nativeData
->TransferFrom( *this ) ;
278 void wxPrintData::ConvertFromNative()
280 m_nativeData
->TransferTo( *this ) ;
283 void wxPrintData::operator=(const wxPrintData
& data
)
285 m_printNoCopies
= data
.m_printNoCopies
;
286 m_printCollate
= data
.m_printCollate
;
287 m_printOrientation
= data
.m_printOrientation
;
288 m_printOrientationReversed
= data
.m_printOrientationReversed
;
289 m_printerName
= data
.m_printerName
;
290 m_colour
= data
.m_colour
;
291 m_duplexMode
= data
.m_duplexMode
;
292 m_printQuality
= data
.m_printQuality
;
293 m_paperId
= data
.m_paperId
;
294 m_paperSize
= data
.m_paperSize
;
296 m_media
= data
.m_media
;
297 m_printMode
= data
.m_printMode
;
298 m_filename
= data
.m_filename
;
300 // UnRef old m_nativeData
303 m_nativeData
->m_ref
--;
304 if (m_nativeData
->m_ref
== 0)
308 m_nativeData
= data
.GetNativeData();
309 m_nativeData
->m_ref
++;
313 delete [] m_privData
;
316 m_privDataLen
= data
.GetPrivDataLen();
317 if (m_privDataLen
> 0)
319 m_privData
= new char[m_privDataLen
];
320 memcpy( m_privData
, data
.GetPrivData(), m_privDataLen
);
324 // Is this data OK for showing the print dialog?
325 bool wxPrintData::IsOk() const
327 m_nativeData
->TransferFrom( *this );
329 return m_nativeData
->Ok();
332 // ----------------------------------------------------------------------------
334 // ----------------------------------------------------------------------------
336 wxPrintDialogData::wxPrintDialogData()
343 m_printAllPages
= false;
344 m_printCollate
= false;
345 m_printToFile
= false;
346 m_printSelection
= false;
347 m_printEnableSelection
= false;
348 m_printEnablePageNumbers
= true;
350 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
351 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
353 m_printEnableHelp
= false;
356 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
359 (*this) = dialogData
;
362 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
367 m_printMaxPage
= 9999;
369 m_printAllPages
= false;
370 m_printCollate
= false;
371 m_printToFile
= false;
372 m_printSelection
= false;
373 m_printEnableSelection
= false;
374 m_printEnablePageNumbers
= true;
375 m_printEnablePrintToFile
= true;
376 m_printEnableHelp
= false;
377 m_printData
= printData
;
380 wxPrintDialogData::~wxPrintDialogData()
384 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
386 m_printFromPage
= data
.m_printFromPage
;
387 m_printToPage
= data
.m_printToPage
;
388 m_printMinPage
= data
.m_printMinPage
;
389 m_printMaxPage
= data
.m_printMaxPage
;
390 m_printNoCopies
= data
.m_printNoCopies
;
391 m_printAllPages
= data
.m_printAllPages
;
392 m_printCollate
= data
.m_printCollate
;
393 m_printToFile
= data
.m_printToFile
;
394 m_printSelection
= data
.m_printSelection
;
395 m_printEnableSelection
= data
.m_printEnableSelection
;
396 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
397 m_printEnableHelp
= data
.m_printEnableHelp
;
398 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
399 m_printData
= data
.m_printData
;
402 void wxPrintDialogData::operator=(const wxPrintData
& data
)
407 // ----------------------------------------------------------------------------
408 // wxPageSetupDialogData
409 // ----------------------------------------------------------------------------
411 wxPageSetupDialogData::wxPageSetupDialogData()
413 m_paperSize
= wxSize(0,0);
415 CalculatePaperSizeFromId();
418 m_minMarginBottomRight
=
420 m_marginBottomRight
= wxPoint(0,0);
423 m_defaultMinMargins
= false;
424 m_enableMargins
= true;
425 m_enableOrientation
= true;
426 m_enablePaper
= true;
427 m_enablePrinter
= true;
428 m_enableHelp
= false;
429 m_getDefaultInfo
= false;
432 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
435 (*this) = dialogData
;
438 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
440 m_paperSize
= wxSize(0,0);
442 m_minMarginBottomRight
=
444 m_marginBottomRight
= wxPoint(0,0);
447 m_defaultMinMargins
= false;
448 m_enableMargins
= true;
449 m_enableOrientation
= true;
450 m_enablePaper
= true;
451 m_enablePrinter
= true;
452 m_enableHelp
= false;
453 m_getDefaultInfo
= false;
455 m_printData
= printData
;
457 // The wxPrintData paper size overrides these values, unless the size cannot
459 CalculatePaperSizeFromId();
462 wxPageSetupDialogData::~wxPageSetupDialogData()
466 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
468 m_paperSize
= data
.m_paperSize
;
469 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
470 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
471 m_marginTopLeft
= data
.m_marginTopLeft
;
472 m_marginBottomRight
= data
.m_marginBottomRight
;
473 m_defaultMinMargins
= data
.m_defaultMinMargins
;
474 m_enableMargins
= data
.m_enableMargins
;
475 m_enableOrientation
= data
.m_enableOrientation
;
476 m_enablePaper
= data
.m_enablePaper
;
477 m_enablePrinter
= data
.m_enablePrinter
;
478 m_getDefaultInfo
= data
.m_getDefaultInfo
;
479 m_enableHelp
= data
.m_enableHelp
;
481 m_printData
= data
.m_printData
;
486 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
489 CalculatePaperSizeFromId();
494 // If a corresponding paper type is found in the paper database, will set the m_printData
495 // paper size id member as well.
496 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
500 CalculateIdFromPaperSize();
503 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
504 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
506 m_printData
.SetPaperId(id
);
508 CalculatePaperSizeFromId();
511 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
513 m_printData
= printData
;
514 CalculatePaperSizeFromId();
517 // Use paper size defined in this object to set the wxPrintData
519 void wxPageSetupDialogData::CalculateIdFromPaperSize()
521 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
522 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
524 wxSize sz
= GetPaperSize();
526 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
527 if (id
!= wxPAPER_NONE
)
529 m_printData
.SetPaperId(id
);
533 // Use paper id in wxPrintData to set this object's paper size
534 void wxPageSetupDialogData::CalculatePaperSizeFromId()
536 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
537 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
539 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
541 // sz is in 10ths of a mm, while paper size is in mm
542 m_paperSize
.x
= sz
.x
/ 10;
543 m_paperSize
.y
= sz
.y
/ 10;
546 #endif // wxUSE_PRINTING_ARCHITECTURE