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/tokenzr.h"
42 #include "wx/prntbase.h"
43 #include "wx/printdlg.h"
46 #include "wx/fontdlg.h"
47 #endif // wxUSE_FONTDLG
49 #if wxUSE_PRINTING_ARCHITECTURE
54 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
55 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
56 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
58 #endif // wxUSE_PRINTING_ARCHITECTURE
60 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
61 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
63 // ============================================================================
65 // ============================================================================
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 wxColourData::wxColourData()
74 m_dataColour
.Set(0,0,0);
75 // m_custColours are wxNullColours initially
78 wxColourData::wxColourData(const wxColourData
& data
)
84 wxColourData::~wxColourData()
88 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
90 wxCHECK_RET( i
>= 0 && i
< NUM_CUSTOM
, wxT("custom colour index out of range") );
92 m_custColours
[i
] = colour
;
95 wxColour
wxColourData::GetCustomColour(int i
) const
97 wxCHECK_MSG( i
>= 0 && i
< NUM_CUSTOM
, wxColour(0,0,0),
98 wxT("custom colour index out of range") );
100 return m_custColours
[i
];
103 wxColourData
& wxColourData::operator=(const wxColourData
& data
)
105 for ( int i
= 0; i
< NUM_CUSTOM
; i
++)
106 m_custColours
[i
] = data
.m_custColours
[i
];
108 m_dataColour
= data
.m_dataColour
;
109 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
< NUM_CUSTOM
; 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
)
139 wxStringTokenizer
tokenizer(str
, wxCOL_DATA_SEP
);
140 wxString token
= tokenizer
.GetNextToken();
141 m_chooseFull
= token
== '1';
142 bool success
= m_chooseFull
|| token
== '0';
143 for (int i
= 0; success
&& i
< NUM_CUSTOM
; i
++)
145 token
= tokenizer
.GetNextToken();
147 m_custColours
[i
] = wxNullColour
;
149 success
= m_custColours
[i
].Set(token
);
154 // ----------------------------------------------------------------------------
156 // ----------------------------------------------------------------------------
158 wxFontData::wxFontData()
160 // Intialize colour to black.
161 m_fontColour
= wxNullColour
;
164 m_allowSymbols
= true;
165 m_enableEffects
= true;
169 m_encoding
= wxFONTENCODING_SYSTEM
;
172 wxFontData::~wxFontData()
178 wxFontDialogBase::~wxFontDialogBase()
182 #endif // wxUSE_FONTDLG
184 #if wxUSE_PRINTING_ARCHITECTURE
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
189 wxPrintData::wxPrintData()
191 m_bin
= wxPRINTBIN_DEFAULT
;
192 m_media
= wxPRINTMEDIA_DEFAULT
;
193 m_printMode
= wxPRINT_MODE_PRINTER
;
194 m_printOrientation
= wxPORTRAIT
;
195 m_printOrientationReversed
= false;
197 m_printCollate
= false;
200 m_printerName
= wxEmptyString
;
202 m_duplexMode
= wxDUPLEX_SIMPLEX
;
203 m_printQuality
= wxPRINT_QUALITY_HIGH
;
205 // we intentionally don't initialize paper id and size at all, like this
206 // the default system settings will be used for them
207 m_paperId
= wxPAPER_NONE
;
208 m_paperSize
= wxDefaultSize
;
213 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
216 wxPrintData::wxPrintData(const wxPrintData
& printData
)
224 void wxPrintData::SetPrivData( char *privData
, int len
)
226 wxDELETEA(m_privData
);
228 if (m_privDataLen
> 0)
230 m_privData
= new char[m_privDataLen
];
231 memcpy( m_privData
, privData
, m_privDataLen
);
235 wxPrintData::~wxPrintData()
237 m_nativeData
->m_ref
--;
238 if (m_nativeData
->m_ref
== 0)
242 delete [] m_privData
;
245 void wxPrintData::ConvertToNative()
247 m_nativeData
->TransferFrom( *this ) ;
250 void wxPrintData::ConvertFromNative()
252 m_nativeData
->TransferTo( *this ) ;
255 wxPrintData
& wxPrintData::operator=(const wxPrintData
& data
)
260 m_printNoCopies
= data
.m_printNoCopies
;
261 m_printCollate
= data
.m_printCollate
;
262 m_printOrientation
= data
.m_printOrientation
;
263 m_printOrientationReversed
= data
.m_printOrientationReversed
;
264 m_printerName
= data
.m_printerName
;
265 m_colour
= data
.m_colour
;
266 m_duplexMode
= data
.m_duplexMode
;
267 m_printQuality
= data
.m_printQuality
;
268 m_paperId
= data
.m_paperId
;
269 m_paperSize
= data
.m_paperSize
;
271 m_media
= data
.m_media
;
272 m_printMode
= data
.m_printMode
;
273 m_filename
= data
.m_filename
;
275 // UnRef old m_nativeData
278 m_nativeData
->m_ref
--;
279 if (m_nativeData
->m_ref
== 0)
283 m_nativeData
= data
.GetNativeData();
284 m_nativeData
->m_ref
++;
286 wxDELETEA(m_privData
);
287 m_privDataLen
= data
.GetPrivDataLen();
288 if (m_privDataLen
> 0)
290 m_privData
= new char[m_privDataLen
];
291 memcpy( m_privData
, data
.GetPrivData(), m_privDataLen
);
297 // Is this data OK for showing the print dialog?
298 bool wxPrintData::IsOk() const
300 m_nativeData
->TransferFrom( *this );
302 return m_nativeData
->Ok();
305 // ----------------------------------------------------------------------------
307 // ----------------------------------------------------------------------------
309 wxPrintDialogData::wxPrintDialogData()
316 m_printAllPages
= false;
317 m_printCollate
= false;
318 m_printToFile
= false;
319 m_printSelection
= false;
320 m_printEnableSelection
= false;
321 m_printEnablePageNumbers
= true;
323 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
324 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
326 m_printEnableHelp
= false;
329 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
332 (*this) = dialogData
;
335 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
340 m_printMaxPage
= 9999;
342 // On Mac the Print dialog always defaults to "All Pages"
344 m_printAllPages
= true;
346 m_printAllPages
= false;
348 m_printCollate
= false;
349 m_printToFile
= false;
350 m_printSelection
= false;
351 m_printEnableSelection
= false;
352 m_printEnablePageNumbers
= true;
353 m_printEnablePrintToFile
= true;
354 m_printEnableHelp
= false;
355 m_printData
= printData
;
358 wxPrintDialogData::~wxPrintDialogData()
362 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
364 m_printFromPage
= data
.m_printFromPage
;
365 m_printToPage
= data
.m_printToPage
;
366 m_printMinPage
= data
.m_printMinPage
;
367 m_printMaxPage
= data
.m_printMaxPage
;
368 m_printNoCopies
= data
.m_printNoCopies
;
369 m_printAllPages
= data
.m_printAllPages
;
370 m_printCollate
= data
.m_printCollate
;
371 m_printToFile
= data
.m_printToFile
;
372 m_printSelection
= data
.m_printSelection
;
373 m_printEnableSelection
= data
.m_printEnableSelection
;
374 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
375 m_printEnableHelp
= data
.m_printEnableHelp
;
376 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
377 m_printData
= data
.m_printData
;
380 void wxPrintDialogData::operator=(const wxPrintData
& data
)
385 // ----------------------------------------------------------------------------
386 // wxPageSetupDialogData
387 // ----------------------------------------------------------------------------
389 wxPageSetupDialogData::wxPageSetupDialogData()
391 m_paperSize
= wxSize(0,0);
393 CalculatePaperSizeFromId();
396 m_minMarginBottomRight
=
398 m_marginBottomRight
= wxPoint(0,0);
401 m_defaultMinMargins
= false;
402 m_enableMargins
= true;
403 m_enableOrientation
= true;
404 m_enablePaper
= true;
405 m_enablePrinter
= true;
406 m_enableHelp
= false;
407 m_getDefaultInfo
= false;
410 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
413 (*this) = dialogData
;
416 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
418 m_paperSize
= wxSize(0,0);
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;
433 m_printData
= printData
;
435 // The wxPrintData paper size overrides these values, unless the size cannot
437 CalculatePaperSizeFromId();
440 wxPageSetupDialogData::~wxPageSetupDialogData()
444 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
446 m_paperSize
= data
.m_paperSize
;
447 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
448 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
449 m_marginTopLeft
= data
.m_marginTopLeft
;
450 m_marginBottomRight
= data
.m_marginBottomRight
;
451 m_defaultMinMargins
= data
.m_defaultMinMargins
;
452 m_enableMargins
= data
.m_enableMargins
;
453 m_enableOrientation
= data
.m_enableOrientation
;
454 m_enablePaper
= data
.m_enablePaper
;
455 m_enablePrinter
= data
.m_enablePrinter
;
456 m_getDefaultInfo
= data
.m_getDefaultInfo
;
457 m_enableHelp
= data
.m_enableHelp
;
459 m_printData
= data
.m_printData
;
464 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
467 CalculatePaperSizeFromId();
472 // If a corresponding paper type is found in the paper database, will set the m_printData
473 // paper size id member as well.
474 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
478 CalculateIdFromPaperSize();
481 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
482 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
484 m_printData
.SetPaperId(id
);
486 CalculatePaperSizeFromId();
489 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
491 m_printData
= printData
;
492 CalculatePaperSizeFromId();
495 // Use paper size defined in this object to set the wxPrintData
497 void wxPageSetupDialogData::CalculateIdFromPaperSize()
499 wxASSERT_MSG( (wxThePrintPaperDatabase
!= NULL
),
500 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
502 wxSize sz
= GetPaperSize();
504 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
505 if (id
!= wxPAPER_NONE
)
507 m_printData
.SetPaperId(id
);
511 // Use paper id in wxPrintData to set this object's paper size
512 void wxPageSetupDialogData::CalculatePaperSizeFromId()
514 wxASSERT_MSG( (wxThePrintPaperDatabase
!= NULL
),
515 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
517 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
519 if (sz
!= wxSize(0, 0))
521 // sz is in 10ths of a mm, while paper size is in mm
522 m_paperSize
.x
= sz
.x
/ 10;
523 m_paperSize
.y
= sz
.y
/ 10;
527 #endif // wxUSE_PRINTING_ARCHITECTURE