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__)
66 #if wxUSE_PRINTING_ARCHITECTURE
68 #if defined(__WXMAC__)
69 #include "wx/mac/private/print.h"
72 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
73 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
74 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
75 #endif // wxUSE_PRINTING_ARCHITECTURE
77 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
78 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
81 #define DMPAPER_USER 256
84 // ============================================================================
86 // ============================================================================
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 wxColourData::wxColourData()
95 m_dataColour
.Set(0,0,0);
96 // m_custColours are wxNullColours initially
99 wxColourData::wxColourData(const wxColourData
& data
)
105 wxColourData::~wxColourData()
109 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
111 wxCHECK_RET( (i
>= 0 && i
< 16), _T("custom colour index out of range") );
113 m_custColours
[i
] = colour
;
116 wxColour
wxColourData::GetCustomColour(int i
)
118 wxCHECK_MSG( (i
>= 0 && i
< 16), wxColour(0,0,0),
119 _T("custom colour index out of range") );
121 return m_custColours
[i
];
124 void wxColourData::operator=(const wxColourData
& data
)
127 for (i
= 0; i
< 16; i
++)
128 m_custColours
[i
] = data
.m_custColours
[i
];
130 m_dataColour
= (wxColour
&)data
.m_dataColour
;
131 m_chooseFull
= data
.m_chooseFull
;
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
138 wxFontData::wxFontData()
140 // Intialize colour to black.
141 m_fontColour
= wxNullColour
;
144 m_allowSymbols
= true;
145 m_enableEffects
= true;
149 m_encoding
= wxFONTENCODING_SYSTEM
;
152 wxFontData::~wxFontData()
158 wxFontDialogBase::~wxFontDialogBase()
162 #endif // wxUSE_FONTDLG
164 #if wxUSE_PRINTING_ARCHITECTURE
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
169 wxPrintData::wxPrintData()
172 m_nativePrintData
= wxNativePrintData::Create() ;
174 m_bin
= wxPRINTBIN_DEFAULT
;
175 m_printMode
= wxPRINT_MODE_PRINTER
;
176 m_printOrientation
= wxPORTRAIT
;
178 m_printCollate
= false;
181 m_printerName
= wxEmptyString
;
183 m_duplexMode
= wxDUPLEX_SIMPLEX
;
184 m_printQuality
= wxPRINT_QUALITY_HIGH
;
185 m_paperId
= wxPAPER_A4
;
186 m_paperSize
= wxSize(210, 297);
191 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
194 wxPrintData::wxPrintData(const wxPrintData
& printData
)
201 void wxPrintData::SetPrivData( char *privData
, int len
)
205 delete [] m_privData
;
209 if (m_privDataLen
> 0)
211 m_privData
= new char[m_privDataLen
];
212 memcpy( m_privData
, privData
, m_privDataLen
);
216 wxPrintData::~wxPrintData()
218 m_nativeData
->m_ref
--;
219 if (m_nativeData
->m_ref
== 0)
223 delete [] m_privData
;
226 delete m_nativePrintData
;
230 void wxPrintData::ConvertToNative()
233 m_nativePrintData
->TransferFrom( this ) ;
235 m_nativeData
->TransferFrom( *this ) ;
239 void wxPrintData::ConvertFromNative()
242 m_nativePrintData
->TransferTo( this ) ;
244 m_nativeData
->TransferTo( *this ) ;
248 void wxPrintData::operator=(const wxPrintData
& data
)
250 m_printNoCopies
= data
.m_printNoCopies
;
251 m_printCollate
= data
.m_printCollate
;
252 m_printOrientation
= data
.m_printOrientation
;
253 m_printerName
= data
.m_printerName
;
254 m_colour
= data
.m_colour
;
255 m_duplexMode
= data
.m_duplexMode
;
256 m_printQuality
= data
.m_printQuality
;
257 m_paperId
= data
.m_paperId
;
258 m_paperSize
= data
.m_paperSize
;
260 m_printMode
= data
.m_printMode
;
261 m_filename
= data
.m_filename
;
263 // UnRef old m_nativeData
266 m_nativeData
->m_ref
--;
267 if (m_nativeData
->m_ref
== 0)
271 m_nativeData
= data
.GetNativeData();
272 m_nativeData
->m_ref
++;
276 delete [] m_privData
;
279 m_privDataLen
= data
.GetPrivDataLen();
280 if (m_privDataLen
> 0)
282 m_privData
= new char[m_privDataLen
];
283 memcpy( m_privData
, data
.GetPrivData(), m_privDataLen
);
287 m_nativePrintData
->CopyFrom( data
.m_nativePrintData
) ;
291 // Is this data OK for showing the print dialog?
292 bool wxPrintData::Ok() const
294 m_nativeData
->TransferFrom( *this );
296 return m_nativeData
->Ok();
299 // What should happen here? wxPostScriptPrintNativeData is not
300 // defined unless all this is true on MSW.
301 #if WXWIN_COMPATIBILITY_2_4 && wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
303 #include "wx/generic/prntdlgg.h"
306 #define WXUNUSED_WITHOUT_PS(name) name
308 #define WXUNUSED_WITHOUT_PS(name) WXUNUSED(name)
311 wxString
wxPrintData::GetPrinterCommand() const
314 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
315 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterCommand();
317 return wxEmptyString
;
320 wxString
wxPrintData::GetPrinterOptions() const
323 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
324 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterOptions();
326 return wxEmptyString
;
329 wxString
wxPrintData::GetPreviewCommand() const
332 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
333 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPreviewCommand();
335 return wxEmptyString
;
338 wxString
wxPrintData::GetFontMetricPath() const
341 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
342 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetFontMetricPath();
344 return wxEmptyString
;
347 double wxPrintData::GetPrinterScaleX() const
350 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
351 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleX();
356 double wxPrintData::GetPrinterScaleY() const
359 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
360 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleY();
365 long wxPrintData::GetPrinterTranslateX() const
368 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
369 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateX();
374 long wxPrintData::GetPrinterTranslateY() const
377 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
378 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateY();
383 void wxPrintData::SetPrinterCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
386 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
387 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterCommand( command
);
391 void wxPrintData::SetPrinterOptions(const wxString
& WXUNUSED_WITHOUT_PS(options
))
394 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
395 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterOptions( options
);
399 void wxPrintData::SetPreviewCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
402 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
403 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPreviewCommand( command
);
407 void wxPrintData::SetFontMetricPath(const wxString
& WXUNUSED_WITHOUT_PS(path
))
410 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
411 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetFontMetricPath( path
);
415 void wxPrintData::SetPrinterScaleX(double WXUNUSED_WITHOUT_PS(x
))
418 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
419 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleX( x
);
423 void wxPrintData::SetPrinterScaleY(double WXUNUSED_WITHOUT_PS(y
))
426 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
427 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleY( y
);
431 void wxPrintData::SetPrinterScaling(double WXUNUSED_WITHOUT_PS(x
), double WXUNUSED_WITHOUT_PS(y
))
434 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
435 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaling( x
, y
);
439 void wxPrintData::SetPrinterTranslateX(long WXUNUSED_WITHOUT_PS(x
))
442 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
443 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateX( x
);
447 void wxPrintData::SetPrinterTranslateY(long WXUNUSED_WITHOUT_PS(y
))
450 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
451 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateY( y
);
455 void wxPrintData::SetPrinterTranslation(long WXUNUSED_WITHOUT_PS(x
), long WXUNUSED_WITHOUT_PS(y
))
458 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
459 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslation( x
, y
);
464 // ----------------------------------------------------------------------------
466 // ----------------------------------------------------------------------------
468 wxPrintDialogData::wxPrintDialogData()
475 m_printAllPages
= false;
476 m_printCollate
= false;
477 m_printToFile
= false;
478 m_printSelection
= false;
479 m_printEnableSelection
= false;
480 m_printEnablePageNumbers
= true;
482 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
483 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
485 m_printEnableHelp
= false;
486 #if WXWIN_COMPATIBILITY_2_4
487 m_printSetupDialog
= false;
491 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
494 (*this) = dialogData
;
497 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
502 m_printMaxPage
= 9999;
504 m_printAllPages
= false;
505 m_printCollate
= false;
506 m_printToFile
= false;
507 m_printSelection
= false;
508 m_printEnableSelection
= false;
509 m_printEnablePageNumbers
= true;
510 m_printEnablePrintToFile
= true;
511 m_printEnableHelp
= false;
512 #if WXWIN_COMPATIBILITY_2_4
513 m_printSetupDialog
= false;
515 m_printData
= printData
;
518 wxPrintDialogData::~wxPrintDialogData()
524 void wxPrintDialogData::ConvertToNative()
526 m_printData
.ConvertToNative();
527 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
530 void wxPrintDialogData::ConvertFromNative()
532 m_printData
.ConvertFromNative();
533 m_printData
.m_nativePrintData
->TransferTo( this ) ;
539 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
541 m_printFromPage
= data
.m_printFromPage
;
542 m_printToPage
= data
.m_printToPage
;
543 m_printMinPage
= data
.m_printMinPage
;
544 m_printMaxPage
= data
.m_printMaxPage
;
545 m_printNoCopies
= data
.m_printNoCopies
;
546 m_printAllPages
= data
.m_printAllPages
;
547 m_printCollate
= data
.m_printCollate
;
548 m_printToFile
= data
.m_printToFile
;
549 m_printSelection
= data
.m_printSelection
;
550 m_printEnableSelection
= data
.m_printEnableSelection
;
551 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
552 m_printEnableHelp
= data
.m_printEnableHelp
;
553 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
554 #if WXWIN_COMPATIBILITY_2_4
555 m_printSetupDialog
= data
.m_printSetupDialog
;
557 m_printData
= data
.m_printData
;
560 void wxPrintDialogData::operator=(const wxPrintData
& data
)
565 // ----------------------------------------------------------------------------
566 // wxPageSetupDialogData
567 // ----------------------------------------------------------------------------
569 wxPageSetupDialogData::wxPageSetupDialogData()
571 m_paperSize
= wxSize(0,0);
573 CalculatePaperSizeFromId();
576 m_minMarginBottomRight
=
578 m_marginBottomRight
= wxPoint(0,0);
581 m_defaultMinMargins
= false;
582 m_enableMargins
= true;
583 m_enableOrientation
= true;
584 m_enablePaper
= true;
585 m_enablePrinter
= true;
586 m_enableHelp
= false;
587 m_getDefaultInfo
= false;
590 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
593 (*this) = dialogData
;
596 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
598 m_paperSize
= wxSize(0,0);
600 m_minMarginBottomRight
=
602 m_marginBottomRight
= wxPoint(0,0);
605 m_defaultMinMargins
= false;
606 m_enableMargins
= true;
607 m_enableOrientation
= true;
608 m_enablePaper
= true;
609 m_enablePrinter
= true;
610 m_enableHelp
= false;
611 m_getDefaultInfo
= false;
613 m_printData
= printData
;
615 // The wxPrintData paper size overrides these values, unless the size cannot
617 CalculatePaperSizeFromId();
620 wxPageSetupDialogData::~wxPageSetupDialogData()
624 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
626 m_paperSize
= data
.m_paperSize
;
627 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
628 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
629 m_marginTopLeft
= data
.m_marginTopLeft
;
630 m_marginBottomRight
= data
.m_marginBottomRight
;
631 m_defaultMinMargins
= data
.m_defaultMinMargins
;
632 m_enableMargins
= data
.m_enableMargins
;
633 m_enableOrientation
= data
.m_enableOrientation
;
634 m_enablePaper
= data
.m_enablePaper
;
635 m_enablePrinter
= data
.m_enablePrinter
;
636 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
637 m_enableHelp
= data
.m_enableHelp
;
639 m_printData
= data
.m_printData
;
644 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
647 CalculatePaperSizeFromId();
653 void wxPageSetupDialogData::ConvertToNative()
655 m_printData
.ConvertToNative();
656 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
659 void wxPageSetupDialogData::ConvertFromNative()
661 m_printData
.ConvertFromNative ();
662 m_paperSize
= m_printData
.GetPaperSize() ;
663 CalculateIdFromPaperSize();
664 m_printData
.m_nativePrintData
->TransferTo( this ) ;
665 // adjust minimal values
667 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
668 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
670 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
671 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
673 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
674 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
676 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
677 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
682 // If a corresponding paper type is found in the paper database, will set the m_printData
683 // paper size id member as well.
684 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
688 CalculateIdFromPaperSize();
691 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
692 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
694 m_printData
.SetPaperId(id
);
696 CalculatePaperSizeFromId();
699 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
701 m_printData
= printData
;
702 CalculatePaperSizeFromId();
705 // Use paper size defined in this object to set the wxPrintData
707 void wxPageSetupDialogData::CalculateIdFromPaperSize()
709 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
710 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
712 wxSize sz
= GetPaperSize();
714 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
715 if (id
!= wxPAPER_NONE
)
717 m_printData
.SetPaperId(id
);
721 // Use paper id in wxPrintData to set this object's paper size
722 void wxPageSetupDialogData::CalculatePaperSizeFromId()
724 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
725 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
727 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
729 // sz is in 10ths of a mm, while paper size is in mm
730 m_paperSize
.x
= sz
.x
/ 10;
731 m_paperSize
.y
= sz
.y
/ 10;
734 #endif // wxUSE_PRINTING_ARCHITECTURE