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_printMode
= wxPRINT_MODE_PRINTER
;
154 m_printOrientation
= wxPORTRAIT
;
156 m_printCollate
= false;
159 m_printerName
= wxEmptyString
;
161 m_duplexMode
= wxDUPLEX_SIMPLEX
;
162 m_printQuality
= wxPRINT_QUALITY_HIGH
;
163 m_paperId
= wxPAPER_A4
;
164 m_paperSize
= wxSize(210, 297);
169 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
172 wxPrintData::wxPrintData(const wxPrintData
& printData
)
180 void wxPrintData::SetPrivData( char *privData
, int len
)
184 delete [] m_privData
;
188 if (m_privDataLen
> 0)
190 m_privData
= new char[m_privDataLen
];
191 memcpy( m_privData
, privData
, m_privDataLen
);
195 wxPrintData::~wxPrintData()
197 m_nativeData
->m_ref
--;
198 if (m_nativeData
->m_ref
== 0)
202 delete [] m_privData
;
205 void wxPrintData::ConvertToNative()
207 m_nativeData
->TransferFrom( *this ) ;
210 void wxPrintData::ConvertFromNative()
212 m_nativeData
->TransferTo( *this ) ;
215 void wxPrintData::operator=(const wxPrintData
& data
)
217 m_printNoCopies
= data
.m_printNoCopies
;
218 m_printCollate
= data
.m_printCollate
;
219 m_printOrientation
= data
.m_printOrientation
;
220 m_printerName
= data
.m_printerName
;
221 m_colour
= data
.m_colour
;
222 m_duplexMode
= data
.m_duplexMode
;
223 m_printQuality
= data
.m_printQuality
;
224 m_paperId
= data
.m_paperId
;
225 m_paperSize
= data
.m_paperSize
;
227 m_printMode
= data
.m_printMode
;
228 m_filename
= data
.m_filename
;
230 // UnRef old m_nativeData
233 m_nativeData
->m_ref
--;
234 if (m_nativeData
->m_ref
== 0)
238 m_nativeData
= data
.GetNativeData();
239 m_nativeData
->m_ref
++;
243 delete [] m_privData
;
246 m_privDataLen
= data
.GetPrivDataLen();
247 if (m_privDataLen
> 0)
249 m_privData
= new char[m_privDataLen
];
250 memcpy( m_privData
, data
.GetPrivData(), m_privDataLen
);
254 // Is this data OK for showing the print dialog?
255 bool wxPrintData::IsOk() const
257 m_nativeData
->TransferFrom( *this );
259 return m_nativeData
->Ok();
262 // What should happen here? wxPostScriptPrintNativeData is not
263 // defined unless all this is true on MSW.
264 #if WXWIN_COMPATIBILITY_2_4 && wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
266 #include "wx/generic/prntdlgg.h"
269 #define WXUNUSED_WITHOUT_PS(name) name
271 #define WXUNUSED_WITHOUT_PS(name) WXUNUSED(name)
274 wxString
wxPrintData::GetPrinterCommand() const
277 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
278 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterCommand();
280 return wxEmptyString
;
283 wxString
wxPrintData::GetPrinterOptions() const
286 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
287 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterOptions();
289 return wxEmptyString
;
292 wxString
wxPrintData::GetPreviewCommand() const
295 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
296 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPreviewCommand();
298 return wxEmptyString
;
301 wxString
wxPrintData::GetFontMetricPath() const
304 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
305 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetFontMetricPath();
307 return wxEmptyString
;
310 double wxPrintData::GetPrinterScaleX() const
313 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
314 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleX();
319 double wxPrintData::GetPrinterScaleY() const
322 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
323 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleY();
328 long wxPrintData::GetPrinterTranslateX() const
331 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
332 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateX();
337 long wxPrintData::GetPrinterTranslateY() const
340 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
341 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateY();
346 void wxPrintData::SetPrinterCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
349 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
350 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterCommand( command
);
354 void wxPrintData::SetPrinterOptions(const wxString
& WXUNUSED_WITHOUT_PS(options
))
357 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
358 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterOptions( options
);
362 void wxPrintData::SetPreviewCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
365 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
366 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPreviewCommand( command
);
370 void wxPrintData::SetFontMetricPath(const wxString
& WXUNUSED_WITHOUT_PS(path
))
373 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
374 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetFontMetricPath( path
);
378 void wxPrintData::SetPrinterScaleX(double WXUNUSED_WITHOUT_PS(x
))
381 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
382 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleX( x
);
386 void wxPrintData::SetPrinterScaleY(double WXUNUSED_WITHOUT_PS(y
))
389 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
390 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleY( y
);
394 void wxPrintData::SetPrinterScaling(double WXUNUSED_WITHOUT_PS(x
), double WXUNUSED_WITHOUT_PS(y
))
397 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
398 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaling( x
, y
);
402 void wxPrintData::SetPrinterTranslateX(long WXUNUSED_WITHOUT_PS(x
))
405 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
406 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateX( x
);
410 void wxPrintData::SetPrinterTranslateY(long WXUNUSED_WITHOUT_PS(y
))
413 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
414 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateY( y
);
418 void wxPrintData::SetPrinterTranslation(long WXUNUSED_WITHOUT_PS(x
), long WXUNUSED_WITHOUT_PS(y
))
421 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
422 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslation( x
, y
);
427 // ----------------------------------------------------------------------------
429 // ----------------------------------------------------------------------------
431 wxPrintDialogData::wxPrintDialogData()
438 m_printAllPages
= false;
439 m_printCollate
= false;
440 m_printToFile
= false;
441 m_printSelection
= false;
442 m_printEnableSelection
= false;
443 m_printEnablePageNumbers
= true;
445 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
446 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
448 m_printEnableHelp
= false;
449 #if WXWIN_COMPATIBILITY_2_4
450 m_printSetupDialog
= false;
454 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
457 (*this) = dialogData
;
460 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
465 m_printMaxPage
= 9999;
467 m_printAllPages
= false;
468 m_printCollate
= false;
469 m_printToFile
= false;
470 m_printSelection
= false;
471 m_printEnableSelection
= false;
472 m_printEnablePageNumbers
= true;
473 m_printEnablePrintToFile
= true;
474 m_printEnableHelp
= false;
475 #if WXWIN_COMPATIBILITY_2_4
476 m_printSetupDialog
= false;
478 m_printData
= printData
;
481 wxPrintDialogData::~wxPrintDialogData()
485 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
487 m_printFromPage
= data
.m_printFromPage
;
488 m_printToPage
= data
.m_printToPage
;
489 m_printMinPage
= data
.m_printMinPage
;
490 m_printMaxPage
= data
.m_printMaxPage
;
491 m_printNoCopies
= data
.m_printNoCopies
;
492 m_printAllPages
= data
.m_printAllPages
;
493 m_printCollate
= data
.m_printCollate
;
494 m_printToFile
= data
.m_printToFile
;
495 m_printSelection
= data
.m_printSelection
;
496 m_printEnableSelection
= data
.m_printEnableSelection
;
497 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
498 m_printEnableHelp
= data
.m_printEnableHelp
;
499 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
500 #if WXWIN_COMPATIBILITY_2_4
501 m_printSetupDialog
= data
.m_printSetupDialog
;
503 m_printData
= data
.m_printData
;
506 void wxPrintDialogData::operator=(const wxPrintData
& data
)
511 // ----------------------------------------------------------------------------
512 // wxPageSetupDialogData
513 // ----------------------------------------------------------------------------
515 wxPageSetupDialogData::wxPageSetupDialogData()
517 m_paperSize
= wxSize(0,0);
519 CalculatePaperSizeFromId();
522 m_minMarginBottomRight
=
524 m_marginBottomRight
= wxPoint(0,0);
527 m_defaultMinMargins
= false;
528 m_enableMargins
= true;
529 m_enableOrientation
= true;
530 m_enablePaper
= true;
531 m_enablePrinter
= true;
532 m_enableHelp
= false;
533 m_getDefaultInfo
= false;
536 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
539 (*this) = dialogData
;
542 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
544 m_paperSize
= wxSize(0,0);
546 m_minMarginBottomRight
=
548 m_marginBottomRight
= wxPoint(0,0);
551 m_defaultMinMargins
= false;
552 m_enableMargins
= true;
553 m_enableOrientation
= true;
554 m_enablePaper
= true;
555 m_enablePrinter
= true;
556 m_enableHelp
= false;
557 m_getDefaultInfo
= false;
559 m_printData
= printData
;
561 // The wxPrintData paper size overrides these values, unless the size cannot
563 CalculatePaperSizeFromId();
566 wxPageSetupDialogData::~wxPageSetupDialogData()
570 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
572 m_paperSize
= data
.m_paperSize
;
573 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
574 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
575 m_marginTopLeft
= data
.m_marginTopLeft
;
576 m_marginBottomRight
= data
.m_marginBottomRight
;
577 m_defaultMinMargins
= data
.m_defaultMinMargins
;
578 m_enableMargins
= data
.m_enableMargins
;
579 m_enableOrientation
= data
.m_enableOrientation
;
580 m_enablePaper
= data
.m_enablePaper
;
581 m_enablePrinter
= data
.m_enablePrinter
;
582 m_getDefaultInfo
= data
.m_getDefaultInfo
;
583 m_enableHelp
= data
.m_enableHelp
;
585 m_printData
= data
.m_printData
;
590 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
593 CalculatePaperSizeFromId();
598 // If a corresponding paper type is found in the paper database, will set the m_printData
599 // paper size id member as well.
600 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
604 CalculateIdFromPaperSize();
607 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
608 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
610 m_printData
.SetPaperId(id
);
612 CalculatePaperSizeFromId();
615 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
617 m_printData
= printData
;
618 CalculatePaperSizeFromId();
621 // Use paper size defined in this object to set the wxPrintData
623 void wxPageSetupDialogData::CalculateIdFromPaperSize()
625 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
626 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
628 wxSize sz
= GetPaperSize();
630 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
631 if (id
!= wxPAPER_NONE
)
633 m_printData
.SetPaperId(id
);
637 // Use paper id in wxPrintData to set this object's paper size
638 void wxPageSetupDialogData::CalculatePaperSizeFromId()
640 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
641 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
643 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
645 // sz is in 10ths of a mm, while paper size is in mm
646 m_paperSize
.x
= sz
.x
/ 10;
647 m_paperSize
.y
= sz
.y
/ 10;
650 #endif // wxUSE_PRINTING_ARCHITECTURE