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);
188 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
191 wxPrintData::wxPrintData(const wxPrintData
& printData
)
198 wxPrintData::~wxPrintData()
200 m_nativeData
->m_ref
--;
201 if (m_nativeData
->m_ref
== 0)
205 delete m_nativePrintData
;
209 void wxPrintData::ConvertToNative()
212 m_nativePrintData
->TransferFrom( this ) ;
214 m_nativeData
->TransferFrom( *this ) ;
218 void wxPrintData::ConvertFromNative()
221 m_nativePrintData
->TransferTo( this ) ;
223 m_nativeData
->TransferTo( *this ) ;
227 void wxPrintData::operator=(const wxPrintData
& data
)
229 m_printNoCopies
= data
.m_printNoCopies
;
230 m_printCollate
= data
.m_printCollate
;
231 m_printOrientation
= data
.m_printOrientation
;
232 m_printerName
= data
.m_printerName
;
233 m_colour
= data
.m_colour
;
234 m_duplexMode
= data
.m_duplexMode
;
235 m_printQuality
= data
.m_printQuality
;
236 m_paperId
= data
.m_paperId
;
237 m_paperSize
= data
.m_paperSize
;
239 m_printMode
= data
.m_printMode
;
240 m_filename
= data
.m_filename
;
242 // UnRef old m_nativeData
245 m_nativeData
->m_ref
--;
246 if (m_nativeData
->m_ref
== 0)
250 m_nativeData
= data
.GetNativeData();
251 m_nativeData
->m_ref
++;
254 m_nativePrintData
->CopyFrom( data
.m_nativePrintData
) ;
258 // Is this data OK for showing the print dialog?
259 bool wxPrintData::Ok() const
261 m_nativeData
->TransferFrom( *this );
263 return m_nativeData
->Ok();
266 // What should happen here? wxPostScriptPrintNativeData is not
267 // defined unless all this is true on MSW.
268 #if WXWIN_COMPATIBILITY_2_4 && wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
270 #include "wx/generic/prntdlgg.h"
273 #define WXUNUSED_WITHOUT_PS(name) name
275 #define WXUNUSED_WITHOUT_PS(name) WXUNUSED(name)
278 wxString
wxPrintData::GetPrinterCommand() const
281 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
282 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterCommand();
284 return wxEmptyString
;
287 wxString
wxPrintData::GetPrinterOptions() const
290 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
291 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterOptions();
293 return wxEmptyString
;
296 wxString
wxPrintData::GetPreviewCommand() const
299 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
300 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPreviewCommand();
302 return wxEmptyString
;
305 wxString
wxPrintData::GetFontMetricPath() const
308 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
309 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetFontMetricPath();
311 return wxEmptyString
;
314 double wxPrintData::GetPrinterScaleX() const
317 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
318 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleX();
323 double wxPrintData::GetPrinterScaleY() const
326 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
327 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleY();
332 long wxPrintData::GetPrinterTranslateX() const
335 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
336 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateX();
341 long wxPrintData::GetPrinterTranslateY() const
344 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
345 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateY();
350 void wxPrintData::SetPrinterCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
353 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
354 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterCommand( command
);
358 void wxPrintData::SetPrinterOptions(const wxString
& WXUNUSED_WITHOUT_PS(options
))
361 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
362 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterOptions( options
);
366 void wxPrintData::SetPreviewCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
369 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
370 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPreviewCommand( command
);
374 void wxPrintData::SetFontMetricPath(const wxString
& WXUNUSED_WITHOUT_PS(path
))
377 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
378 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetFontMetricPath( path
);
382 void wxPrintData::SetPrinterScaleX(double WXUNUSED_WITHOUT_PS(x
))
385 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
386 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleX( x
);
390 void wxPrintData::SetPrinterScaleY(double WXUNUSED_WITHOUT_PS(y
))
393 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
394 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleY( y
);
398 void wxPrintData::SetPrinterScaling(double WXUNUSED_WITHOUT_PS(x
), double WXUNUSED_WITHOUT_PS(y
))
401 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
402 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaling( x
, y
);
406 void wxPrintData::SetPrinterTranslateX(long WXUNUSED_WITHOUT_PS(x
))
409 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
410 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateX( x
);
414 void wxPrintData::SetPrinterTranslateY(long WXUNUSED_WITHOUT_PS(y
))
417 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
418 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateY( y
);
422 void wxPrintData::SetPrinterTranslation(long WXUNUSED_WITHOUT_PS(x
), long WXUNUSED_WITHOUT_PS(y
))
425 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
426 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslation( x
, y
);
431 // ----------------------------------------------------------------------------
433 // ----------------------------------------------------------------------------
435 wxPrintDialogData::wxPrintDialogData()
442 m_printAllPages
= false;
443 m_printCollate
= false;
444 m_printToFile
= false;
445 m_printSelection
= false;
446 m_printEnableSelection
= false;
447 m_printEnablePageNumbers
= true;
449 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
450 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
452 m_printEnableHelp
= false;
453 #if WXWIN_COMPATIBILITY_2_4
454 m_printSetupDialog
= false;
458 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
461 (*this) = dialogData
;
464 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
469 m_printMaxPage
= 9999;
471 m_printAllPages
= false;
472 m_printCollate
= false;
473 m_printToFile
= false;
474 m_printSelection
= false;
475 m_printEnableSelection
= false;
476 m_printEnablePageNumbers
= true;
477 m_printEnablePrintToFile
= true;
478 m_printEnableHelp
= false;
479 #if WXWIN_COMPATIBILITY_2_4
480 m_printSetupDialog
= false;
482 m_printData
= printData
;
485 wxPrintDialogData::~wxPrintDialogData()
491 void wxPrintDialogData::ConvertToNative()
493 m_printData
.ConvertToNative();
494 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
497 void wxPrintDialogData::ConvertFromNative()
499 m_printData
.ConvertFromNative();
500 m_printData
.m_nativePrintData
->TransferTo( this ) ;
506 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
508 m_printFromPage
= data
.m_printFromPage
;
509 m_printToPage
= data
.m_printToPage
;
510 m_printMinPage
= data
.m_printMinPage
;
511 m_printMaxPage
= data
.m_printMaxPage
;
512 m_printNoCopies
= data
.m_printNoCopies
;
513 m_printAllPages
= data
.m_printAllPages
;
514 m_printCollate
= data
.m_printCollate
;
515 m_printToFile
= data
.m_printToFile
;
516 m_printSelection
= data
.m_printSelection
;
517 m_printEnableSelection
= data
.m_printEnableSelection
;
518 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
519 m_printEnableHelp
= data
.m_printEnableHelp
;
520 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
521 #if WXWIN_COMPATIBILITY_2_4
522 m_printSetupDialog
= data
.m_printSetupDialog
;
524 m_printData
= data
.m_printData
;
527 void wxPrintDialogData::operator=(const wxPrintData
& data
)
532 // ----------------------------------------------------------------------------
533 // wxPageSetupDialogData
534 // ----------------------------------------------------------------------------
536 wxPageSetupDialogData::wxPageSetupDialogData()
538 m_paperSize
= wxSize(0,0);
540 CalculatePaperSizeFromId();
543 m_minMarginBottomRight
=
545 m_marginBottomRight
= wxPoint(0,0);
548 m_defaultMinMargins
= false;
549 m_enableMargins
= true;
550 m_enableOrientation
= true;
551 m_enablePaper
= true;
552 m_enablePrinter
= true;
553 m_enableHelp
= false;
554 m_getDefaultInfo
= false;
557 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
560 (*this) = dialogData
;
563 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
565 m_paperSize
= wxSize(0,0);
567 m_minMarginBottomRight
=
569 m_marginBottomRight
= wxPoint(0,0);
572 m_defaultMinMargins
= false;
573 m_enableMargins
= true;
574 m_enableOrientation
= true;
575 m_enablePaper
= true;
576 m_enablePrinter
= true;
577 m_enableHelp
= false;
578 m_getDefaultInfo
= false;
580 m_printData
= printData
;
582 // The wxPrintData paper size overrides these values, unless the size cannot
584 CalculatePaperSizeFromId();
587 wxPageSetupDialogData::~wxPageSetupDialogData()
591 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
593 m_paperSize
= data
.m_paperSize
;
594 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
595 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
596 m_marginTopLeft
= data
.m_marginTopLeft
;
597 m_marginBottomRight
= data
.m_marginBottomRight
;
598 m_defaultMinMargins
= data
.m_defaultMinMargins
;
599 m_enableMargins
= data
.m_enableMargins
;
600 m_enableOrientation
= data
.m_enableOrientation
;
601 m_enablePaper
= data
.m_enablePaper
;
602 m_enablePrinter
= data
.m_enablePrinter
;
603 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
604 m_enableHelp
= data
.m_enableHelp
;
606 m_printData
= data
.m_printData
;
611 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
614 CalculatePaperSizeFromId();
620 void wxPageSetupDialogData::ConvertToNative()
622 m_printData
.ConvertToNative();
623 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
626 void wxPageSetupDialogData::ConvertFromNative()
628 m_printData
.ConvertFromNative ();
629 m_paperSize
= m_printData
.GetPaperSize() ;
630 CalculateIdFromPaperSize();
631 m_printData
.m_nativePrintData
->TransferTo( this ) ;
632 // adjust minimal values
634 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
635 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
637 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
638 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
640 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
641 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
643 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
644 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
649 // If a corresponding paper type is found in the paper database, will set the m_printData
650 // paper size id member as well.
651 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
655 CalculateIdFromPaperSize();
658 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
659 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
661 m_printData
.SetPaperId(id
);
663 CalculatePaperSizeFromId();
666 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
668 m_printData
= printData
;
669 CalculatePaperSizeFromId();
672 // Use paper size defined in this object to set the wxPrintData
674 void wxPageSetupDialogData::CalculateIdFromPaperSize()
676 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
677 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
679 wxSize sz
= GetPaperSize();
681 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
682 if (id
!= wxPAPER_NONE
)
684 m_printData
.SetPaperId(id
);
688 // Use paper id in wxPrintData to set this object's paper size
689 void wxPageSetupDialogData::CalculatePaperSizeFromId()
691 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
692 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
694 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
696 // sz is in 10ths of a mm, while paper size is in mm
697 m_paperSize
.x
= sz
.x
/ 10;
698 m_paperSize
.y
= sz
.y
/ 10;
701 #endif // wxUSE_PRINTING_ARCHITECTURE