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__)
53 #include "wx/msw/wrapcdlg.h"
56 #if wxUSE_PRINTING_ARCHITECTURE
58 #if defined(__WXMAC__)
59 #include "wx/mac/private/print.h"
62 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
63 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
64 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
65 #endif // wxUSE_PRINTING_ARCHITECTURE
67 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
68 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
70 // ============================================================================
72 // ============================================================================
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 wxColourData::wxColourData()
81 m_dataColour
.Set(0,0,0);
82 // m_custColours are wxNullColours initially
85 wxColourData::wxColourData(const wxColourData
& data
)
91 wxColourData::~wxColourData()
95 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
97 wxCHECK_RET( (i
>= 0 && i
< 16), _T("custom colour index out of range") );
99 m_custColours
[i
] = colour
;
102 wxColour
wxColourData::GetCustomColour(int i
)
104 wxCHECK_MSG( (i
>= 0 && i
< 16), wxColour(0,0,0),
105 _T("custom colour index out of range") );
107 return m_custColours
[i
];
110 void wxColourData::operator=(const wxColourData
& data
)
113 for (i
= 0; i
< 16; i
++)
114 m_custColours
[i
] = data
.m_custColours
[i
];
116 m_dataColour
= (wxColour
&)data
.m_dataColour
;
117 m_chooseFull
= data
.m_chooseFull
;
120 // ----------------------------------------------------------------------------
122 // ----------------------------------------------------------------------------
124 wxFontData::wxFontData()
126 // Intialize colour to black.
127 m_fontColour
= wxNullColour
;
130 m_allowSymbols
= true;
131 m_enableEffects
= true;
135 m_encoding
= wxFONTENCODING_SYSTEM
;
138 wxFontData::~wxFontData()
144 wxFontDialogBase::~wxFontDialogBase()
148 #endif // wxUSE_FONTDLG
150 #if wxUSE_PRINTING_ARCHITECTURE
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
155 wxPrintData::wxPrintData()
157 m_bin
= wxPRINTBIN_DEFAULT
;
158 m_printMode
= wxPRINT_MODE_PRINTER
;
159 m_printOrientation
= wxPORTRAIT
;
161 m_printCollate
= false;
164 m_printerName
= wxEmptyString
;
166 m_duplexMode
= wxDUPLEX_SIMPLEX
;
167 m_printQuality
= wxPRINT_QUALITY_HIGH
;
168 m_paperId
= wxPAPER_A4
;
169 m_paperSize
= wxSize(210, 297);
174 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
177 wxPrintData::wxPrintData(const wxPrintData
& printData
)
185 void wxPrintData::SetPrivData( char *privData
, int len
)
189 delete [] m_privData
;
193 if (m_privDataLen
> 0)
195 m_privData
= new char[m_privDataLen
];
196 memcpy( m_privData
, privData
, m_privDataLen
);
200 wxPrintData::~wxPrintData()
202 m_nativeData
->m_ref
--;
203 if (m_nativeData
->m_ref
== 0)
207 delete [] m_privData
;
210 void wxPrintData::ConvertToNative()
212 m_nativeData
->TransferFrom( *this ) ;
215 void wxPrintData::ConvertFromNative()
217 m_nativeData
->TransferTo( *this ) ;
220 void wxPrintData::operator=(const wxPrintData
& data
)
222 m_printNoCopies
= data
.m_printNoCopies
;
223 m_printCollate
= data
.m_printCollate
;
224 m_printOrientation
= data
.m_printOrientation
;
225 m_printerName
= data
.m_printerName
;
226 m_colour
= data
.m_colour
;
227 m_duplexMode
= data
.m_duplexMode
;
228 m_printQuality
= data
.m_printQuality
;
229 m_paperId
= data
.m_paperId
;
230 m_paperSize
= data
.m_paperSize
;
232 m_printMode
= data
.m_printMode
;
233 m_filename
= data
.m_filename
;
235 // UnRef old m_nativeData
238 m_nativeData
->m_ref
--;
239 if (m_nativeData
->m_ref
== 0)
243 m_nativeData
= data
.GetNativeData();
244 m_nativeData
->m_ref
++;
248 delete [] m_privData
;
251 m_privDataLen
= data
.GetPrivDataLen();
252 if (m_privDataLen
> 0)
254 m_privData
= new char[m_privDataLen
];
255 memcpy( m_privData
, data
.GetPrivData(), m_privDataLen
);
259 // Is this data OK for showing the print dialog?
260 bool wxPrintData::Ok() const
262 m_nativeData
->TransferFrom( *this );
264 return m_nativeData
->Ok();
267 // What should happen here? wxPostScriptPrintNativeData is not
268 // defined unless all this is true on MSW.
269 #if WXWIN_COMPATIBILITY_2_4 && wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
271 #include "wx/generic/prntdlgg.h"
274 #define WXUNUSED_WITHOUT_PS(name) name
276 #define WXUNUSED_WITHOUT_PS(name) WXUNUSED(name)
279 wxString
wxPrintData::GetPrinterCommand() const
282 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
283 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterCommand();
285 return wxEmptyString
;
288 wxString
wxPrintData::GetPrinterOptions() const
291 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
292 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterOptions();
294 return wxEmptyString
;
297 wxString
wxPrintData::GetPreviewCommand() const
300 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
301 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPreviewCommand();
303 return wxEmptyString
;
306 wxString
wxPrintData::GetFontMetricPath() const
309 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
310 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetFontMetricPath();
312 return wxEmptyString
;
315 double wxPrintData::GetPrinterScaleX() const
318 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
319 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleX();
324 double wxPrintData::GetPrinterScaleY() const
327 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
328 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleY();
333 long wxPrintData::GetPrinterTranslateX() const
336 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
337 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateX();
342 long wxPrintData::GetPrinterTranslateY() const
345 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
346 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateY();
351 void wxPrintData::SetPrinterCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
354 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
355 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterCommand( command
);
359 void wxPrintData::SetPrinterOptions(const wxString
& WXUNUSED_WITHOUT_PS(options
))
362 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
363 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterOptions( options
);
367 void wxPrintData::SetPreviewCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
370 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
371 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPreviewCommand( command
);
375 void wxPrintData::SetFontMetricPath(const wxString
& WXUNUSED_WITHOUT_PS(path
))
378 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
379 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetFontMetricPath( path
);
383 void wxPrintData::SetPrinterScaleX(double WXUNUSED_WITHOUT_PS(x
))
386 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
387 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleX( x
);
391 void wxPrintData::SetPrinterScaleY(double WXUNUSED_WITHOUT_PS(y
))
394 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
395 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleY( y
);
399 void wxPrintData::SetPrinterScaling(double WXUNUSED_WITHOUT_PS(x
), double WXUNUSED_WITHOUT_PS(y
))
402 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
403 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaling( x
, y
);
407 void wxPrintData::SetPrinterTranslateX(long WXUNUSED_WITHOUT_PS(x
))
410 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
411 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateX( x
);
415 void wxPrintData::SetPrinterTranslateY(long WXUNUSED_WITHOUT_PS(y
))
418 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
419 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateY( y
);
423 void wxPrintData::SetPrinterTranslation(long WXUNUSED_WITHOUT_PS(x
), long WXUNUSED_WITHOUT_PS(y
))
426 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
427 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslation( x
, y
);
432 // ----------------------------------------------------------------------------
434 // ----------------------------------------------------------------------------
436 wxPrintDialogData::wxPrintDialogData()
443 m_printAllPages
= false;
444 m_printCollate
= false;
445 m_printToFile
= false;
446 m_printSelection
= false;
447 m_printEnableSelection
= false;
448 m_printEnablePageNumbers
= true;
450 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
451 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
453 m_printEnableHelp
= false;
454 #if WXWIN_COMPATIBILITY_2_4
455 m_printSetupDialog
= false;
459 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
462 (*this) = dialogData
;
465 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
470 m_printMaxPage
= 9999;
472 m_printAllPages
= false;
473 m_printCollate
= false;
474 m_printToFile
= false;
475 m_printSelection
= false;
476 m_printEnableSelection
= false;
477 m_printEnablePageNumbers
= true;
478 m_printEnablePrintToFile
= true;
479 m_printEnableHelp
= false;
480 #if WXWIN_COMPATIBILITY_2_4
481 m_printSetupDialog
= false;
483 m_printData
= printData
;
486 wxPrintDialogData::~wxPrintDialogData()
490 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
492 m_printFromPage
= data
.m_printFromPage
;
493 m_printToPage
= data
.m_printToPage
;
494 m_printMinPage
= data
.m_printMinPage
;
495 m_printMaxPage
= data
.m_printMaxPage
;
496 m_printNoCopies
= data
.m_printNoCopies
;
497 m_printAllPages
= data
.m_printAllPages
;
498 m_printCollate
= data
.m_printCollate
;
499 m_printToFile
= data
.m_printToFile
;
500 m_printSelection
= data
.m_printSelection
;
501 m_printEnableSelection
= data
.m_printEnableSelection
;
502 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
503 m_printEnableHelp
= data
.m_printEnableHelp
;
504 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
505 #if WXWIN_COMPATIBILITY_2_4
506 m_printSetupDialog
= data
.m_printSetupDialog
;
508 m_printData
= data
.m_printData
;
511 void wxPrintDialogData::operator=(const wxPrintData
& data
)
516 // ----------------------------------------------------------------------------
517 // wxPageSetupDialogData
518 // ----------------------------------------------------------------------------
520 wxPageSetupDialogData::wxPageSetupDialogData()
522 m_paperSize
= wxSize(0,0);
524 CalculatePaperSizeFromId();
527 m_minMarginBottomRight
=
529 m_marginBottomRight
= wxPoint(0,0);
532 m_defaultMinMargins
= false;
533 m_enableMargins
= true;
534 m_enableOrientation
= true;
535 m_enablePaper
= true;
536 m_enablePrinter
= true;
537 m_enableHelp
= false;
538 m_getDefaultInfo
= false;
541 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
544 (*this) = dialogData
;
547 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
549 m_paperSize
= wxSize(0,0);
551 m_minMarginBottomRight
=
553 m_marginBottomRight
= wxPoint(0,0);
556 m_defaultMinMargins
= false;
557 m_enableMargins
= true;
558 m_enableOrientation
= true;
559 m_enablePaper
= true;
560 m_enablePrinter
= true;
561 m_enableHelp
= false;
562 m_getDefaultInfo
= false;
564 m_printData
= printData
;
566 // The wxPrintData paper size overrides these values, unless the size cannot
568 CalculatePaperSizeFromId();
571 wxPageSetupDialogData::~wxPageSetupDialogData()
575 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
577 m_paperSize
= data
.m_paperSize
;
578 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
579 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
580 m_marginTopLeft
= data
.m_marginTopLeft
;
581 m_marginBottomRight
= data
.m_marginBottomRight
;
582 m_defaultMinMargins
= data
.m_defaultMinMargins
;
583 m_enableMargins
= data
.m_enableMargins
;
584 m_enableOrientation
= data
.m_enableOrientation
;
585 m_enablePaper
= data
.m_enablePaper
;
586 m_enablePrinter
= data
.m_enablePrinter
;
587 m_getDefaultInfo
= data
.m_getDefaultInfo
;
588 m_enableHelp
= data
.m_enableHelp
;
590 m_printData
= data
.m_printData
;
595 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
598 CalculatePaperSizeFromId();
603 // If a corresponding paper type is found in the paper database, will set the m_printData
604 // paper size id member as well.
605 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
609 CalculateIdFromPaperSize();
612 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
613 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
615 m_printData
.SetPaperId(id
);
617 CalculatePaperSizeFromId();
620 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
622 m_printData
= printData
;
623 CalculatePaperSizeFromId();
626 // Use paper size defined in this object to set the wxPrintData
628 void wxPageSetupDialogData::CalculateIdFromPaperSize()
630 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
631 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
633 wxSize sz
= GetPaperSize();
635 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
636 if (id
!= wxPAPER_NONE
)
638 m_printData
.SetPaperId(id
);
642 // Use paper id in wxPrintData to set this object's paper size
643 void wxPageSetupDialogData::CalculatePaperSizeFromId()
645 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
646 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
648 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
650 // sz is in 10ths of a mm, while paper size is in mm
651 m_paperSize
.x
= sz
.x
/ 10;
652 m_paperSize
.y
= sz
.y
/ 10;
655 #endif // wxUSE_PRINTING_ARCHITECTURE