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
< 16), _T("custom colour index out of range") );
94 m_custColours
[i
] = colour
;
97 wxColour
wxColourData::GetCustomColour(int i
)
99 wxCHECK_MSG( (i
>= 0 && i
< 16), wxColour(0,0,0),
100 _T("custom colour index out of range") );
102 return m_custColours
[i
];
105 void wxColourData::operator=(const wxColourData
& data
)
108 for (i
= 0; i
< 16; i
++)
109 m_custColours
[i
] = data
.m_custColours
[i
];
111 m_dataColour
= (wxColour
&)data
.m_dataColour
;
112 m_chooseFull
= data
.m_chooseFull
;
115 // ----------------------------------------------------------------------------
117 // ----------------------------------------------------------------------------
119 wxFontData::wxFontData()
121 // Intialize colour to black.
122 m_fontColour
= wxNullColour
;
125 m_allowSymbols
= true;
126 m_enableEffects
= true;
130 m_encoding
= wxFONTENCODING_SYSTEM
;
133 wxFontData::~wxFontData()
139 wxFontDialogBase::~wxFontDialogBase()
143 #endif // wxUSE_FONTDLG
145 #if wxUSE_PRINTING_ARCHITECTURE
146 // ----------------------------------------------------------------------------
148 // ----------------------------------------------------------------------------
150 wxPrintData::wxPrintData()
152 m_bin
= wxPRINTBIN_DEFAULT
;
153 m_media
= wxPRINTMEDIA_DEFAULT
;
154 m_printMode
= wxPRINT_MODE_PRINTER
;
155 m_printOrientation
= wxPORTRAIT
;
156 m_printOrientationReversed
= false;
158 m_printCollate
= false;
161 m_printerName
= wxEmptyString
;
163 m_duplexMode
= wxDUPLEX_SIMPLEX
;
164 m_printQuality
= wxPRINT_QUALITY_HIGH
;
166 // we intentionally don't initialize paper id and size at all, like this
167 // the default system settings will be used for them
168 m_paperId
= wxPAPER_NONE
;
169 m_paperSize
= wxDefaultSize
;
174 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
177 wxPrintData::wxPrintData(const wxPrintData
& printData
)
185 void wxPrintData::SetPrivData( char *privData
, int len
)
189 delete [] m_privData
;
193 if (m_privDataLen
> 0)
195 m_privData
= new char[m_privDataLen
];
196 memcpy( m_privData
, privData
, m_privDataLen
);
200 wxPrintData::~wxPrintData()
202 m_nativeData
->m_ref
--;
203 if (m_nativeData
->m_ref
== 0)
207 delete [] m_privData
;
210 void wxPrintData::ConvertToNative()
212 m_nativeData
->TransferFrom( *this ) ;
215 void wxPrintData::ConvertFromNative()
217 m_nativeData
->TransferTo( *this ) ;
220 void wxPrintData::operator=(const wxPrintData
& data
)
222 m_printNoCopies
= data
.m_printNoCopies
;
223 m_printCollate
= data
.m_printCollate
;
224 m_printOrientation
= data
.m_printOrientation
;
225 m_printOrientationReversed
= data
.m_printOrientationReversed
;
226 m_printerName
= data
.m_printerName
;
227 m_colour
= data
.m_colour
;
228 m_duplexMode
= data
.m_duplexMode
;
229 m_printQuality
= data
.m_printQuality
;
230 m_paperId
= data
.m_paperId
;
231 m_paperSize
= data
.m_paperSize
;
233 m_media
= data
.m_media
;
234 m_printMode
= data
.m_printMode
;
235 m_filename
= data
.m_filename
;
237 // UnRef old m_nativeData
240 m_nativeData
->m_ref
--;
241 if (m_nativeData
->m_ref
== 0)
245 m_nativeData
= data
.GetNativeData();
246 m_nativeData
->m_ref
++;
250 delete [] m_privData
;
253 m_privDataLen
= data
.GetPrivDataLen();
254 if (m_privDataLen
> 0)
256 m_privData
= new char[m_privDataLen
];
257 memcpy( m_privData
, data
.GetPrivData(), m_privDataLen
);
261 // Is this data OK for showing the print dialog?
262 bool wxPrintData::IsOk() const
264 m_nativeData
->TransferFrom( *this );
266 return m_nativeData
->Ok();
269 // ----------------------------------------------------------------------------
271 // ----------------------------------------------------------------------------
273 wxPrintDialogData::wxPrintDialogData()
280 m_printAllPages
= false;
281 m_printCollate
= false;
282 m_printToFile
= false;
283 m_printSelection
= false;
284 m_printEnableSelection
= false;
285 m_printEnablePageNumbers
= true;
287 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
288 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
290 m_printEnableHelp
= false;
293 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
296 (*this) = dialogData
;
299 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
304 m_printMaxPage
= 9999;
306 m_printAllPages
= false;
307 m_printCollate
= false;
308 m_printToFile
= false;
309 m_printSelection
= false;
310 m_printEnableSelection
= false;
311 m_printEnablePageNumbers
= true;
312 m_printEnablePrintToFile
= true;
313 m_printEnableHelp
= false;
314 m_printData
= printData
;
317 wxPrintDialogData::~wxPrintDialogData()
321 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
323 m_printFromPage
= data
.m_printFromPage
;
324 m_printToPage
= data
.m_printToPage
;
325 m_printMinPage
= data
.m_printMinPage
;
326 m_printMaxPage
= data
.m_printMaxPage
;
327 m_printNoCopies
= data
.m_printNoCopies
;
328 m_printAllPages
= data
.m_printAllPages
;
329 m_printCollate
= data
.m_printCollate
;
330 m_printToFile
= data
.m_printToFile
;
331 m_printSelection
= data
.m_printSelection
;
332 m_printEnableSelection
= data
.m_printEnableSelection
;
333 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
334 m_printEnableHelp
= data
.m_printEnableHelp
;
335 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
336 m_printData
= data
.m_printData
;
339 void wxPrintDialogData::operator=(const wxPrintData
& data
)
344 // ----------------------------------------------------------------------------
345 // wxPageSetupDialogData
346 // ----------------------------------------------------------------------------
348 wxPageSetupDialogData::wxPageSetupDialogData()
350 m_paperSize
= wxSize(0,0);
352 CalculatePaperSizeFromId();
355 m_minMarginBottomRight
=
357 m_marginBottomRight
= wxPoint(0,0);
360 m_defaultMinMargins
= false;
361 m_enableMargins
= true;
362 m_enableOrientation
= true;
363 m_enablePaper
= true;
364 m_enablePrinter
= true;
365 m_enableHelp
= false;
366 m_getDefaultInfo
= false;
369 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
372 (*this) = dialogData
;
375 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
377 m_paperSize
= wxSize(0,0);
379 m_minMarginBottomRight
=
381 m_marginBottomRight
= wxPoint(0,0);
384 m_defaultMinMargins
= false;
385 m_enableMargins
= true;
386 m_enableOrientation
= true;
387 m_enablePaper
= true;
388 m_enablePrinter
= true;
389 m_enableHelp
= false;
390 m_getDefaultInfo
= false;
392 m_printData
= printData
;
394 // The wxPrintData paper size overrides these values, unless the size cannot
396 CalculatePaperSizeFromId();
399 wxPageSetupDialogData::~wxPageSetupDialogData()
403 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
405 m_paperSize
= data
.m_paperSize
;
406 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
407 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
408 m_marginTopLeft
= data
.m_marginTopLeft
;
409 m_marginBottomRight
= data
.m_marginBottomRight
;
410 m_defaultMinMargins
= data
.m_defaultMinMargins
;
411 m_enableMargins
= data
.m_enableMargins
;
412 m_enableOrientation
= data
.m_enableOrientation
;
413 m_enablePaper
= data
.m_enablePaper
;
414 m_enablePrinter
= data
.m_enablePrinter
;
415 m_getDefaultInfo
= data
.m_getDefaultInfo
;
416 m_enableHelp
= data
.m_enableHelp
;
418 m_printData
= data
.m_printData
;
423 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
426 CalculatePaperSizeFromId();
431 // If a corresponding paper type is found in the paper database, will set the m_printData
432 // paper size id member as well.
433 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
437 CalculateIdFromPaperSize();
440 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
441 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
443 m_printData
.SetPaperId(id
);
445 CalculatePaperSizeFromId();
448 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
450 m_printData
= printData
;
451 CalculatePaperSizeFromId();
454 // Use paper size defined in this object to set the wxPrintData
456 void wxPageSetupDialogData::CalculateIdFromPaperSize()
458 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
459 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
461 wxSize sz
= GetPaperSize();
463 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
464 if (id
!= wxPAPER_NONE
)
466 m_printData
.SetPaperId(id
);
470 // Use paper id in wxPrintData to set this object's paper size
471 void wxPageSetupDialogData::CalculatePaperSizeFromId()
473 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
474 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
476 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
478 // sz is in 10ths of a mm, while paper size is in mm
479 m_paperSize
.x
= sz
.x
/ 10;
480 m_paperSize
.y
= sz
.y
/ 10;
483 #endif // wxUSE_PRINTING_ARCHITECTURE