1 /////////////////////////////////////////////////////////////////////////////
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"
29 #include "wx/string.h"
34 #include "wx/gdicmn.h"
35 #include "wx/cmndata.h"
37 #include "wx/prntbase.h"
38 #include "wx/printdlg.h"
41 #include "wx/fontdlg.h"
42 #endif // wxUSE_FONTDLG
44 #if wxUSE_PRINTING_ARCHITECTURE
46 #endif // wxUSE_PRINTING_ARCHITECTURE
48 #if defined(__WXMSW__)
49 #include "wx/msw/wrapcdlg.h"
52 #if wxUSE_PRINTING_ARCHITECTURE
54 #if defined(__WXMAC__)
55 #include "wx/mac/private/print.h"
58 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
59 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
60 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
61 #endif // wxUSE_PRINTING_ARCHITECTURE
63 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
64 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
66 // ============================================================================
68 // ============================================================================
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 wxColourData::wxColourData()
77 m_dataColour
.Set(0,0,0);
78 // m_custColours are wxNullColours initially
81 wxColourData::wxColourData(const wxColourData
& data
)
87 wxColourData::~wxColourData()
91 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
93 wxCHECK_RET( (i
>= 0 && i
< 16), _T("custom colour index out of range") );
95 m_custColours
[i
] = colour
;
98 wxColour
wxColourData::GetCustomColour(int i
)
100 wxCHECK_MSG( (i
>= 0 && i
< 16), wxColour(0,0,0),
101 _T("custom colour index out of range") );
103 return m_custColours
[i
];
106 void wxColourData::operator=(const wxColourData
& data
)
109 for (i
= 0; i
< 16; i
++)
110 m_custColours
[i
] = data
.m_custColours
[i
];
112 m_dataColour
= (wxColour
&)data
.m_dataColour
;
113 m_chooseFull
= data
.m_chooseFull
;
116 // ----------------------------------------------------------------------------
118 // ----------------------------------------------------------------------------
120 wxFontData::wxFontData()
122 // Intialize colour to black.
123 m_fontColour
= wxNullColour
;
126 m_allowSymbols
= true;
127 m_enableEffects
= true;
131 m_encoding
= wxFONTENCODING_SYSTEM
;
134 wxFontData::~wxFontData()
140 wxFontDialogBase::~wxFontDialogBase()
144 #endif // wxUSE_FONTDLG
146 #if wxUSE_PRINTING_ARCHITECTURE
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 wxPrintData::wxPrintData()
153 m_bin
= wxPRINTBIN_DEFAULT
;
154 m_printMode
= wxPRINT_MODE_PRINTER
;
155 m_printOrientation
= wxPORTRAIT
;
157 m_printCollate
= false;
160 m_printerName
= wxEmptyString
;
162 m_duplexMode
= wxDUPLEX_SIMPLEX
;
163 m_printQuality
= wxPRINT_QUALITY_HIGH
;
164 m_paperId
= wxPAPER_A4
;
165 m_paperSize
= wxSize(210, 297);
170 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
173 wxPrintData::wxPrintData(const wxPrintData
& printData
)
181 void wxPrintData::SetPrivData( char *privData
, int len
)
185 delete [] m_privData
;
189 if (m_privDataLen
> 0)
191 m_privData
= new char[m_privDataLen
];
192 memcpy( m_privData
, privData
, m_privDataLen
);
196 wxPrintData::~wxPrintData()
198 m_nativeData
->m_ref
--;
199 if (m_nativeData
->m_ref
== 0)
203 delete [] m_privData
;
206 void wxPrintData::ConvertToNative()
208 m_nativeData
->TransferFrom( *this ) ;
211 void wxPrintData::ConvertFromNative()
213 m_nativeData
->TransferTo( *this ) ;
216 void wxPrintData::operator=(const wxPrintData
& data
)
218 m_printNoCopies
= data
.m_printNoCopies
;
219 m_printCollate
= data
.m_printCollate
;
220 m_printOrientation
= data
.m_printOrientation
;
221 m_printerName
= data
.m_printerName
;
222 m_colour
= data
.m_colour
;
223 m_duplexMode
= data
.m_duplexMode
;
224 m_printQuality
= data
.m_printQuality
;
225 m_paperId
= data
.m_paperId
;
226 m_paperSize
= data
.m_paperSize
;
228 m_printMode
= data
.m_printMode
;
229 m_filename
= data
.m_filename
;
231 // UnRef old m_nativeData
234 m_nativeData
->m_ref
--;
235 if (m_nativeData
->m_ref
== 0)
239 m_nativeData
= data
.GetNativeData();
240 m_nativeData
->m_ref
++;
244 delete [] m_privData
;
247 m_privDataLen
= data
.GetPrivDataLen();
248 if (m_privDataLen
> 0)
250 m_privData
= new char[m_privDataLen
];
251 memcpy( m_privData
, data
.GetPrivData(), m_privDataLen
);
255 // Is this data OK for showing the print dialog?
256 bool wxPrintData::Ok() const
258 m_nativeData
->TransferFrom( *this );
260 return m_nativeData
->Ok();
263 // What should happen here? wxPostScriptPrintNativeData is not
264 // defined unless all this is true on MSW.
265 #if WXWIN_COMPATIBILITY_2_4 && wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
267 #include "wx/generic/prntdlgg.h"
270 #define WXUNUSED_WITHOUT_PS(name) name
272 #define WXUNUSED_WITHOUT_PS(name) WXUNUSED(name)
275 wxString
wxPrintData::GetPrinterCommand() const
278 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
279 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterCommand();
281 return wxEmptyString
;
284 wxString
wxPrintData::GetPrinterOptions() const
287 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
288 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterOptions();
290 return wxEmptyString
;
293 wxString
wxPrintData::GetPreviewCommand() const
296 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
297 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPreviewCommand();
299 return wxEmptyString
;
302 wxString
wxPrintData::GetFontMetricPath() const
305 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
306 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetFontMetricPath();
308 return wxEmptyString
;
311 double wxPrintData::GetPrinterScaleX() const
314 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
315 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleX();
320 double wxPrintData::GetPrinterScaleY() const
323 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
324 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleY();
329 long wxPrintData::GetPrinterTranslateX() const
332 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
333 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateX();
338 long wxPrintData::GetPrinterTranslateY() const
341 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
342 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateY();
347 void wxPrintData::SetPrinterCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
350 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
351 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterCommand( command
);
355 void wxPrintData::SetPrinterOptions(const wxString
& WXUNUSED_WITHOUT_PS(options
))
358 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
359 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterOptions( options
);
363 void wxPrintData::SetPreviewCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
366 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
367 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPreviewCommand( command
);
371 void wxPrintData::SetFontMetricPath(const wxString
& WXUNUSED_WITHOUT_PS(path
))
374 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
375 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetFontMetricPath( path
);
379 void wxPrintData::SetPrinterScaleX(double WXUNUSED_WITHOUT_PS(x
))
382 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
383 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleX( x
);
387 void wxPrintData::SetPrinterScaleY(double WXUNUSED_WITHOUT_PS(y
))
390 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
391 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleY( y
);
395 void wxPrintData::SetPrinterScaling(double WXUNUSED_WITHOUT_PS(x
), double WXUNUSED_WITHOUT_PS(y
))
398 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
399 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaling( x
, y
);
403 void wxPrintData::SetPrinterTranslateX(long WXUNUSED_WITHOUT_PS(x
))
406 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
407 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateX( x
);
411 void wxPrintData::SetPrinterTranslateY(long WXUNUSED_WITHOUT_PS(y
))
414 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
415 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateY( y
);
419 void wxPrintData::SetPrinterTranslation(long WXUNUSED_WITHOUT_PS(x
), long WXUNUSED_WITHOUT_PS(y
))
422 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
423 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslation( x
, y
);
428 // ----------------------------------------------------------------------------
430 // ----------------------------------------------------------------------------
432 wxPrintDialogData::wxPrintDialogData()
439 m_printAllPages
= false;
440 m_printCollate
= false;
441 m_printToFile
= false;
442 m_printSelection
= false;
443 m_printEnableSelection
= false;
444 m_printEnablePageNumbers
= true;
446 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
447 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
449 m_printEnableHelp
= false;
450 #if WXWIN_COMPATIBILITY_2_4
451 m_printSetupDialog
= false;
455 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
458 (*this) = dialogData
;
461 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
466 m_printMaxPage
= 9999;
468 m_printAllPages
= false;
469 m_printCollate
= false;
470 m_printToFile
= false;
471 m_printSelection
= false;
472 m_printEnableSelection
= false;
473 m_printEnablePageNumbers
= true;
474 m_printEnablePrintToFile
= true;
475 m_printEnableHelp
= false;
476 #if WXWIN_COMPATIBILITY_2_4
477 m_printSetupDialog
= false;
479 m_printData
= printData
;
482 wxPrintDialogData::~wxPrintDialogData()
486 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
488 m_printFromPage
= data
.m_printFromPage
;
489 m_printToPage
= data
.m_printToPage
;
490 m_printMinPage
= data
.m_printMinPage
;
491 m_printMaxPage
= data
.m_printMaxPage
;
492 m_printNoCopies
= data
.m_printNoCopies
;
493 m_printAllPages
= data
.m_printAllPages
;
494 m_printCollate
= data
.m_printCollate
;
495 m_printToFile
= data
.m_printToFile
;
496 m_printSelection
= data
.m_printSelection
;
497 m_printEnableSelection
= data
.m_printEnableSelection
;
498 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
499 m_printEnableHelp
= data
.m_printEnableHelp
;
500 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
501 #if WXWIN_COMPATIBILITY_2_4
502 m_printSetupDialog
= data
.m_printSetupDialog
;
504 m_printData
= data
.m_printData
;
507 void wxPrintDialogData::operator=(const wxPrintData
& data
)
512 // ----------------------------------------------------------------------------
513 // wxPageSetupDialogData
514 // ----------------------------------------------------------------------------
516 wxPageSetupDialogData::wxPageSetupDialogData()
518 m_paperSize
= wxSize(0,0);
520 CalculatePaperSizeFromId();
523 m_minMarginBottomRight
=
525 m_marginBottomRight
= wxPoint(0,0);
528 m_defaultMinMargins
= false;
529 m_enableMargins
= true;
530 m_enableOrientation
= true;
531 m_enablePaper
= true;
532 m_enablePrinter
= true;
533 m_enableHelp
= false;
534 m_getDefaultInfo
= false;
537 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
540 (*this) = dialogData
;
543 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
545 m_paperSize
= wxSize(0,0);
547 m_minMarginBottomRight
=
549 m_marginBottomRight
= wxPoint(0,0);
552 m_defaultMinMargins
= false;
553 m_enableMargins
= true;
554 m_enableOrientation
= true;
555 m_enablePaper
= true;
556 m_enablePrinter
= true;
557 m_enableHelp
= false;
558 m_getDefaultInfo
= false;
560 m_printData
= printData
;
562 // The wxPrintData paper size overrides these values, unless the size cannot
564 CalculatePaperSizeFromId();
567 wxPageSetupDialogData::~wxPageSetupDialogData()
571 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
573 m_paperSize
= data
.m_paperSize
;
574 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
575 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
576 m_marginTopLeft
= data
.m_marginTopLeft
;
577 m_marginBottomRight
= data
.m_marginBottomRight
;
578 m_defaultMinMargins
= data
.m_defaultMinMargins
;
579 m_enableMargins
= data
.m_enableMargins
;
580 m_enableOrientation
= data
.m_enableOrientation
;
581 m_enablePaper
= data
.m_enablePaper
;
582 m_enablePrinter
= data
.m_enablePrinter
;
583 m_getDefaultInfo
= data
.m_getDefaultInfo
;
584 m_enableHelp
= data
.m_enableHelp
;
586 m_printData
= data
.m_printData
;
591 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
594 CalculatePaperSizeFromId();
599 // If a corresponding paper type is found in the paper database, will set the m_printData
600 // paper size id member as well.
601 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
605 CalculateIdFromPaperSize();
608 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
609 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
611 m_printData
.SetPaperId(id
);
613 CalculatePaperSizeFromId();
616 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
618 m_printData
= printData
;
619 CalculatePaperSizeFromId();
622 // Use paper size defined in this object to set the wxPrintData
624 void wxPageSetupDialogData::CalculateIdFromPaperSize()
626 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
627 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
629 wxSize sz
= GetPaperSize();
631 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
632 if (id
!= wxPAPER_NONE
)
634 m_printData
.SetPaperId(id
);
638 // Use paper id in wxPrintData to set this object's paper size
639 void wxPageSetupDialogData::CalculatePaperSizeFromId()
641 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
642 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
644 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
646 // sz is in 10ths of a mm, while paper size is in mm
647 m_paperSize
.x
= sz
.x
/ 10;
648 m_paperSize
.y
= sz
.y
/ 10;
651 #endif // wxUSE_PRINTING_ARCHITECTURE