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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "cmndata.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/string.h"
38 #include "wx/gdicmn.h"
39 #include "wx/cmndata.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
50 #endif // wxUSE_PRINTING_ARCHITECTURE
52 #if defined(__WXMSW__)
54 #include "wx/msw/private.h"
56 #ifndef __SMARTPHONE__ /* of WinCE */
60 #if defined(__WATCOMC__) || defined(__SYMANTEC__) || defined(__SALFORDC__)
67 #include "wx/mac/private/print.h"
70 #if wxUSE_PRINTING_ARCHITECTURE
71 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
72 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
73 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
74 #endif // wxUSE_PRINTING_ARCHITECTURE
76 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
77 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
80 #define DMPAPER_USER 256
83 // ============================================================================
85 // ============================================================================
87 // ----------------------------------------------------------------------------
89 // ----------------------------------------------------------------------------
91 wxColourData::wxColourData()
94 m_dataColour
.Set(0,0,0);
95 // m_custColours are wxNullColours initially
98 wxColourData::wxColourData(const wxColourData
& data
)
104 wxColourData::~wxColourData()
108 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
110 wxCHECK_RET( (i
>= 0 && i
< 16), _T("custom colour index out of range") );
112 m_custColours
[i
] = colour
;
115 wxColour
wxColourData::GetCustomColour(int i
)
117 wxCHECK_MSG( (i
>= 0 && i
< 16), wxColour(0,0,0),
118 _T("custom colour index out of range") );
120 return m_custColours
[i
];
123 void wxColourData::operator=(const wxColourData
& data
)
126 for (i
= 0; i
< 16; i
++)
127 m_custColours
[i
] = data
.m_custColours
[i
];
129 m_dataColour
= (wxColour
&)data
.m_dataColour
;
130 m_chooseFull
= data
.m_chooseFull
;
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 wxFontData::wxFontData()
139 // Intialize colour to black.
140 m_fontColour
= wxNullColour
;
143 m_allowSymbols
= true;
144 m_enableEffects
= true;
148 m_encoding
= wxFONTENCODING_SYSTEM
;
151 wxFontData::~wxFontData()
157 wxFontDialogBase::~wxFontDialogBase()
161 #endif // wxUSE_FONTDLG
163 #if wxUSE_PRINTING_ARCHITECTURE
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 wxPrintData::wxPrintData()
171 m_nativePrintData
= wxNativePrintData::Create() ;
173 m_bin
= wxPRINTBIN_DEFAULT
;
174 m_printMode
= wxPRINT_MODE_PRINTER
;
175 m_printOrientation
= wxPORTRAIT
;
177 m_printCollate
= false;
180 m_printerName
= wxEmptyString
;
182 m_duplexMode
= wxDUPLEX_SIMPLEX
;
183 m_printQuality
= wxPRINT_QUALITY_HIGH
;
184 m_paperId
= wxPAPER_A4
;
185 m_paperSize
= wxSize(210, 297);
187 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
190 wxPrintData::wxPrintData(const wxPrintData
& printData
)
197 wxPrintData::~wxPrintData()
199 m_nativeData
->m_ref
--;
200 if (m_nativeData
->m_ref
== 0)
204 delete m_nativePrintData
;
208 void wxPrintData::ConvertToNative()
211 m_nativePrintData
->TransferFrom( this ) ;
213 m_nativeData
->TransferFrom( *this ) ;
217 void wxPrintData::ConvertFromNative()
220 m_nativePrintData
->TransferTo( this ) ;
222 m_nativeData
->TransferTo( *this ) ;
226 void wxPrintData::operator=(const wxPrintData
& data
)
228 m_printNoCopies
= data
.m_printNoCopies
;
229 m_printCollate
= data
.m_printCollate
;
230 m_printOrientation
= data
.m_printOrientation
;
231 m_printerName
= data
.m_printerName
;
232 m_colour
= data
.m_colour
;
233 m_duplexMode
= data
.m_duplexMode
;
234 m_printQuality
= data
.m_printQuality
;
235 m_paperId
= data
.m_paperId
;
236 m_paperSize
= data
.m_paperSize
;
238 m_printMode
= data
.m_printMode
;
239 m_filename
= data
.m_filename
;
241 // UnRef old m_nativeData
244 m_nativeData
->m_ref
--;
245 if (m_nativeData
->m_ref
== 0)
249 m_nativeData
= data
.GetNativeData();
250 m_nativeData
->m_ref
++;
253 m_nativePrintData
->CopyFrom( data
.m_nativePrintData
) ;
257 // Is this data OK for showing the print dialog?
258 bool wxPrintData::Ok() const
260 m_nativeData
->TransferFrom( *this );
262 return m_nativeData
->Ok();
265 // What should happen here? wxPostScriptPrintNativeData is not
266 // defined unless all this is true on MSW.
267 #if WXWIN_COMPATIBILITY_2_4 && wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
269 #include "wx/generic/prntdlgg.h"
272 #define WXUNUSED_WITHOUT_PS(name) name
274 #define WXUNUSED_WITHOUT_PS(name) WXUNUSED(name)
277 wxString
wxPrintData::GetPrinterCommand() const
280 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
281 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterCommand();
283 return wxEmptyString
;
286 wxString
wxPrintData::GetPrinterOptions() const
289 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
290 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterOptions();
292 return wxEmptyString
;
295 wxString
wxPrintData::GetPreviewCommand() const
298 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
299 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPreviewCommand();
301 return wxEmptyString
;
304 wxString
wxPrintData::GetFontMetricPath() const
307 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
308 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetFontMetricPath();
310 return wxEmptyString
;
313 double wxPrintData::GetPrinterScaleX() const
316 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
317 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleX();
322 double wxPrintData::GetPrinterScaleY() const
325 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
326 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleY();
331 long wxPrintData::GetPrinterTranslateX() const
334 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
335 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateX();
340 long wxPrintData::GetPrinterTranslateY() const
343 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
344 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateY();
349 void wxPrintData::SetPrinterCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
352 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
353 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterCommand( command
);
357 void wxPrintData::SetPrinterOptions(const wxString
& WXUNUSED_WITHOUT_PS(options
))
360 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
361 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterOptions( options
);
365 void wxPrintData::SetPreviewCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
368 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
369 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPreviewCommand( command
);
373 void wxPrintData::SetFontMetricPath(const wxString
& WXUNUSED_WITHOUT_PS(path
))
376 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
377 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetFontMetricPath( path
);
381 void wxPrintData::SetPrinterScaleX(double WXUNUSED_WITHOUT_PS(x
))
384 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
385 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleX( x
);
389 void wxPrintData::SetPrinterScaleY(double WXUNUSED_WITHOUT_PS(y
))
392 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
393 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleY( y
);
397 void wxPrintData::SetPrinterScaling(double WXUNUSED_WITHOUT_PS(x
), double WXUNUSED_WITHOUT_PS(y
))
400 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
401 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaling( x
, y
);
405 void wxPrintData::SetPrinterTranslateX(long WXUNUSED_WITHOUT_PS(x
))
408 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
409 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateX( x
);
413 void wxPrintData::SetPrinterTranslateY(long WXUNUSED_WITHOUT_PS(y
))
416 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
417 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateY( y
);
421 void wxPrintData::SetPrinterTranslation(long WXUNUSED_WITHOUT_PS(x
), long WXUNUSED_WITHOUT_PS(y
))
424 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
425 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslation( x
, y
);
430 // ----------------------------------------------------------------------------
432 // ----------------------------------------------------------------------------
434 wxPrintDialogData::wxPrintDialogData()
441 m_printAllPages
= false;
442 m_printCollate
= false;
443 m_printToFile
= false;
444 m_printSelection
= false;
445 m_printEnableSelection
= false;
446 m_printEnablePageNumbers
= true;
448 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
449 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
451 m_printEnableHelp
= false;
452 #if WXWIN_COMPATIBILITY_2_4
453 m_printSetupDialog
= false;
457 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
460 (*this) = dialogData
;
463 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
468 m_printMaxPage
= 9999;
470 m_printAllPages
= false;
471 m_printCollate
= false;
472 m_printToFile
= false;
473 m_printSelection
= false;
474 m_printEnableSelection
= false;
475 m_printEnablePageNumbers
= true;
476 m_printEnablePrintToFile
= true;
477 m_printEnableHelp
= false;
478 #if WXWIN_COMPATIBILITY_2_4
479 m_printSetupDialog
= false;
481 m_printData
= printData
;
484 wxPrintDialogData::~wxPrintDialogData()
490 void wxPrintDialogData::ConvertToNative()
492 m_printData
.ConvertToNative();
493 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
496 void wxPrintDialogData::ConvertFromNative()
498 m_printData
.ConvertFromNative();
499 m_printData
.m_nativePrintData
->TransferTo( this ) ;
505 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
507 m_printFromPage
= data
.m_printFromPage
;
508 m_printToPage
= data
.m_printToPage
;
509 m_printMinPage
= data
.m_printMinPage
;
510 m_printMaxPage
= data
.m_printMaxPage
;
511 m_printNoCopies
= data
.m_printNoCopies
;
512 m_printAllPages
= data
.m_printAllPages
;
513 m_printCollate
= data
.m_printCollate
;
514 m_printToFile
= data
.m_printToFile
;
515 m_printSelection
= data
.m_printSelection
;
516 m_printEnableSelection
= data
.m_printEnableSelection
;
517 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
518 m_printEnableHelp
= data
.m_printEnableHelp
;
519 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
520 #if WXWIN_COMPATIBILITY_2_4
521 m_printSetupDialog
= data
.m_printSetupDialog
;
523 m_printData
= data
.m_printData
;
526 void wxPrintDialogData::operator=(const wxPrintData
& data
)
531 // ----------------------------------------------------------------------------
532 // wxPageSetupDialogData
533 // ----------------------------------------------------------------------------
535 wxPageSetupDialogData::wxPageSetupDialogData()
537 m_paperSize
= wxSize();
539 CalculatePaperSizeFromId();
542 m_minMarginBottomRight
=
544 m_marginBottomRight
= wxPoint();
547 m_defaultMinMargins
= false;
548 m_enableMargins
= true;
549 m_enableOrientation
= true;
550 m_enablePaper
= true;
551 m_enablePrinter
= true;
552 m_enableHelp
= false;
553 m_getDefaultInfo
= false;
556 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
559 (*this) = dialogData
;
562 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
564 m_paperSize
= wxSize();
566 m_minMarginBottomRight
=
568 m_marginBottomRight
= wxPoint();
571 m_defaultMinMargins
= false;
572 m_enableMargins
= true;
573 m_enableOrientation
= true;
574 m_enablePaper
= true;
575 m_enablePrinter
= true;
576 m_enableHelp
= false;
577 m_getDefaultInfo
= false;
579 m_printData
= printData
;
581 // The wxPrintData paper size overrides these values, unless the size cannot
583 CalculatePaperSizeFromId();
586 wxPageSetupDialogData::~wxPageSetupDialogData()
590 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
592 m_paperSize
= data
.m_paperSize
;
593 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
594 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
595 m_marginTopLeft
= data
.m_marginTopLeft
;
596 m_marginBottomRight
= data
.m_marginBottomRight
;
597 m_defaultMinMargins
= data
.m_defaultMinMargins
;
598 m_enableMargins
= data
.m_enableMargins
;
599 m_enableOrientation
= data
.m_enableOrientation
;
600 m_enablePaper
= data
.m_enablePaper
;
601 m_enablePrinter
= data
.m_enablePrinter
;
602 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
603 m_enableHelp
= data
.m_enableHelp
;
605 m_printData
= data
.m_printData
;
610 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
613 CalculatePaperSizeFromId();
619 void wxPageSetupDialogData::ConvertToNative()
621 m_printData
.ConvertToNative();
622 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
625 void wxPageSetupDialogData::ConvertFromNative()
627 m_printData
.ConvertFromNative ();
628 m_paperSize
= m_printData
.GetPaperSize() ;
629 CalculateIdFromPaperSize();
630 m_printData
.m_nativePrintData
->TransferTo( this ) ;
631 // adjust minimal values
633 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
634 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
636 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
637 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
639 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
640 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
642 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
643 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
648 // If a corresponding paper type is found in the paper database, will set the m_printData
649 // paper size id member as well.
650 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
654 CalculateIdFromPaperSize();
657 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
658 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
660 m_printData
.SetPaperId(id
);
662 CalculatePaperSizeFromId();
665 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
667 m_printData
= printData
;
668 CalculatePaperSizeFromId();
671 // Use paper size defined in this object to set the wxPrintData
673 void wxPageSetupDialogData::CalculateIdFromPaperSize()
675 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
676 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
678 wxSize sz
= GetPaperSize();
680 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
681 if (id
!= wxPAPER_NONE
)
683 m_printData
.SetPaperId(id
);
687 // Use paper id in wxPrintData to set this object's paper size
688 void wxPageSetupDialogData::CalculatePaperSizeFromId()
690 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
691 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
693 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
695 // sz is in 10ths of a mm, while paper size is in mm
696 m_paperSize
.x
= sz
.x
/ 10;
697 m_paperSize
.y
= sz
.y
/ 10;
700 #endif // wxUSE_PRINTING_ARCHITECTURE