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
)
71 #define DMPAPER_USER 256
74 // ============================================================================
76 // ============================================================================
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 wxColourData::wxColourData()
85 m_dataColour
.Set(0,0,0);
86 // m_custColours are wxNullColours initially
89 wxColourData::wxColourData(const wxColourData
& data
)
95 wxColourData::~wxColourData()
99 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
101 wxCHECK_RET( (i
>= 0 && i
< 16), _T("custom colour index out of range") );
103 m_custColours
[i
] = colour
;
106 wxColour
wxColourData::GetCustomColour(int i
)
108 wxCHECK_MSG( (i
>= 0 && i
< 16), wxColour(0,0,0),
109 _T("custom colour index out of range") );
111 return m_custColours
[i
];
114 void wxColourData::operator=(const wxColourData
& data
)
117 for (i
= 0; i
< 16; i
++)
118 m_custColours
[i
] = data
.m_custColours
[i
];
120 m_dataColour
= (wxColour
&)data
.m_dataColour
;
121 m_chooseFull
= data
.m_chooseFull
;
124 // ----------------------------------------------------------------------------
126 // ----------------------------------------------------------------------------
128 wxFontData::wxFontData()
130 // Intialize colour to black.
131 m_fontColour
= wxNullColour
;
134 m_allowSymbols
= true;
135 m_enableEffects
= true;
139 m_encoding
= wxFONTENCODING_SYSTEM
;
142 wxFontData::~wxFontData()
148 wxFontDialogBase::~wxFontDialogBase()
152 #endif // wxUSE_FONTDLG
154 #if wxUSE_PRINTING_ARCHITECTURE
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
159 wxPrintData::wxPrintData()
161 m_bin
= wxPRINTBIN_DEFAULT
;
162 m_printMode
= wxPRINT_MODE_PRINTER
;
163 m_printOrientation
= wxPORTRAIT
;
165 m_printCollate
= false;
168 m_printerName
= wxEmptyString
;
170 m_duplexMode
= wxDUPLEX_SIMPLEX
;
171 m_printQuality
= wxPRINT_QUALITY_HIGH
;
172 m_paperId
= wxPAPER_A4
;
173 m_paperSize
= wxSize(210, 297);
178 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
181 wxPrintData::wxPrintData(const wxPrintData
& printData
)
189 void wxPrintData::SetPrivData( char *privData
, int len
)
193 delete [] m_privData
;
197 if (m_privDataLen
> 0)
199 m_privData
= new char[m_privDataLen
];
200 memcpy( m_privData
, privData
, m_privDataLen
);
204 wxPrintData::~wxPrintData()
206 m_nativeData
->m_ref
--;
207 if (m_nativeData
->m_ref
== 0)
211 delete [] m_privData
;
214 void wxPrintData::ConvertToNative()
216 m_nativeData
->TransferFrom( *this ) ;
219 void wxPrintData::ConvertFromNative()
221 m_nativeData
->TransferTo( *this ) ;
224 void wxPrintData::operator=(const wxPrintData
& data
)
226 m_printNoCopies
= data
.m_printNoCopies
;
227 m_printCollate
= data
.m_printCollate
;
228 m_printOrientation
= data
.m_printOrientation
;
229 m_printerName
= data
.m_printerName
;
230 m_colour
= data
.m_colour
;
231 m_duplexMode
= data
.m_duplexMode
;
232 m_printQuality
= data
.m_printQuality
;
233 m_paperId
= data
.m_paperId
;
234 m_paperSize
= data
.m_paperSize
;
236 m_printMode
= data
.m_printMode
;
237 m_filename
= data
.m_filename
;
239 // UnRef old m_nativeData
242 m_nativeData
->m_ref
--;
243 if (m_nativeData
->m_ref
== 0)
247 m_nativeData
= data
.GetNativeData();
248 m_nativeData
->m_ref
++;
252 delete [] m_privData
;
255 m_privDataLen
= data
.GetPrivDataLen();
256 if (m_privDataLen
> 0)
258 m_privData
= new char[m_privDataLen
];
259 memcpy( m_privData
, data
.GetPrivData(), m_privDataLen
);
263 // Is this data OK for showing the print dialog?
264 bool wxPrintData::Ok() const
266 m_nativeData
->TransferFrom( *this );
268 return m_nativeData
->Ok();
271 // What should happen here? wxPostScriptPrintNativeData is not
272 // defined unless all this is true on MSW.
273 #if WXWIN_COMPATIBILITY_2_4 && wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
275 #include "wx/generic/prntdlgg.h"
278 #define WXUNUSED_WITHOUT_PS(name) name
280 #define WXUNUSED_WITHOUT_PS(name) WXUNUSED(name)
283 wxString
wxPrintData::GetPrinterCommand() const
286 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
287 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterCommand();
289 return wxEmptyString
;
292 wxString
wxPrintData::GetPrinterOptions() const
295 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
296 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterOptions();
298 return wxEmptyString
;
301 wxString
wxPrintData::GetPreviewCommand() const
304 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
305 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPreviewCommand();
307 return wxEmptyString
;
310 wxString
wxPrintData::GetFontMetricPath() const
313 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
314 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetFontMetricPath();
316 return wxEmptyString
;
319 double wxPrintData::GetPrinterScaleX() const
322 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
323 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleX();
328 double wxPrintData::GetPrinterScaleY() const
331 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
332 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleY();
337 long wxPrintData::GetPrinterTranslateX() const
340 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
341 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateX();
346 long wxPrintData::GetPrinterTranslateY() const
349 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
350 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateY();
355 void wxPrintData::SetPrinterCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
358 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
359 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterCommand( command
);
363 void wxPrintData::SetPrinterOptions(const wxString
& WXUNUSED_WITHOUT_PS(options
))
366 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
367 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterOptions( options
);
371 void wxPrintData::SetPreviewCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
374 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
375 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPreviewCommand( command
);
379 void wxPrintData::SetFontMetricPath(const wxString
& WXUNUSED_WITHOUT_PS(path
))
382 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
383 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetFontMetricPath( path
);
387 void wxPrintData::SetPrinterScaleX(double WXUNUSED_WITHOUT_PS(x
))
390 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
391 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleX( x
);
395 void wxPrintData::SetPrinterScaleY(double WXUNUSED_WITHOUT_PS(y
))
398 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
399 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleY( y
);
403 void wxPrintData::SetPrinterScaling(double WXUNUSED_WITHOUT_PS(x
), double WXUNUSED_WITHOUT_PS(y
))
406 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
407 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaling( x
, y
);
411 void wxPrintData::SetPrinterTranslateX(long WXUNUSED_WITHOUT_PS(x
))
414 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
415 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateX( x
);
419 void wxPrintData::SetPrinterTranslateY(long WXUNUSED_WITHOUT_PS(y
))
422 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
423 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateY( y
);
427 void wxPrintData::SetPrinterTranslation(long WXUNUSED_WITHOUT_PS(x
), long WXUNUSED_WITHOUT_PS(y
))
430 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
431 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslation( x
, y
);
436 // ----------------------------------------------------------------------------
438 // ----------------------------------------------------------------------------
440 wxPrintDialogData::wxPrintDialogData()
447 m_printAllPages
= false;
448 m_printCollate
= false;
449 m_printToFile
= false;
450 m_printSelection
= false;
451 m_printEnableSelection
= false;
452 m_printEnablePageNumbers
= true;
454 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
455 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
457 m_printEnableHelp
= false;
458 #if WXWIN_COMPATIBILITY_2_4
459 m_printSetupDialog
= false;
463 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
466 (*this) = dialogData
;
469 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
474 m_printMaxPage
= 9999;
476 m_printAllPages
= false;
477 m_printCollate
= false;
478 m_printToFile
= false;
479 m_printSelection
= false;
480 m_printEnableSelection
= false;
481 m_printEnablePageNumbers
= true;
482 m_printEnablePrintToFile
= true;
483 m_printEnableHelp
= false;
484 #if WXWIN_COMPATIBILITY_2_4
485 m_printSetupDialog
= false;
487 m_printData
= printData
;
490 wxPrintDialogData::~wxPrintDialogData()
494 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
496 m_printFromPage
= data
.m_printFromPage
;
497 m_printToPage
= data
.m_printToPage
;
498 m_printMinPage
= data
.m_printMinPage
;
499 m_printMaxPage
= data
.m_printMaxPage
;
500 m_printNoCopies
= data
.m_printNoCopies
;
501 m_printAllPages
= data
.m_printAllPages
;
502 m_printCollate
= data
.m_printCollate
;
503 m_printToFile
= data
.m_printToFile
;
504 m_printSelection
= data
.m_printSelection
;
505 m_printEnableSelection
= data
.m_printEnableSelection
;
506 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
507 m_printEnableHelp
= data
.m_printEnableHelp
;
508 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
509 #if WXWIN_COMPATIBILITY_2_4
510 m_printSetupDialog
= data
.m_printSetupDialog
;
512 m_printData
= data
.m_printData
;
515 void wxPrintDialogData::operator=(const wxPrintData
& data
)
520 // ----------------------------------------------------------------------------
521 // wxPageSetupDialogData
522 // ----------------------------------------------------------------------------
524 wxPageSetupDialogData::wxPageSetupDialogData()
526 m_paperSize
= wxSize(0,0);
528 CalculatePaperSizeFromId();
531 m_minMarginBottomRight
=
533 m_marginBottomRight
= wxPoint(0,0);
536 m_defaultMinMargins
= false;
537 m_enableMargins
= true;
538 m_enableOrientation
= true;
539 m_enablePaper
= true;
540 m_enablePrinter
= true;
541 m_enableHelp
= false;
542 m_getDefaultInfo
= false;
545 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
548 (*this) = dialogData
;
551 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
553 m_paperSize
= wxSize(0,0);
555 m_minMarginBottomRight
=
557 m_marginBottomRight
= wxPoint(0,0);
560 m_defaultMinMargins
= false;
561 m_enableMargins
= true;
562 m_enableOrientation
= true;
563 m_enablePaper
= true;
564 m_enablePrinter
= true;
565 m_enableHelp
= false;
566 m_getDefaultInfo
= false;
568 m_printData
= printData
;
570 // The wxPrintData paper size overrides these values, unless the size cannot
572 CalculatePaperSizeFromId();
575 wxPageSetupDialogData::~wxPageSetupDialogData()
579 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
581 m_paperSize
= data
.m_paperSize
;
582 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
583 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
584 m_marginTopLeft
= data
.m_marginTopLeft
;
585 m_marginBottomRight
= data
.m_marginBottomRight
;
586 m_defaultMinMargins
= data
.m_defaultMinMargins
;
587 m_enableMargins
= data
.m_enableMargins
;
588 m_enableOrientation
= data
.m_enableOrientation
;
589 m_enablePaper
= data
.m_enablePaper
;
590 m_enablePrinter
= data
.m_enablePrinter
;
591 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
592 m_enableHelp
= data
.m_enableHelp
;
594 m_printData
= data
.m_printData
;
599 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
602 CalculatePaperSizeFromId();
607 // If a corresponding paper type is found in the paper database, will set the m_printData
608 // paper size id member as well.
609 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
613 CalculateIdFromPaperSize();
616 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
617 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
619 m_printData
.SetPaperId(id
);
621 CalculatePaperSizeFromId();
624 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
626 m_printData
= printData
;
627 CalculatePaperSizeFromId();
630 // Use paper size defined in this object to set the wxPrintData
632 void wxPageSetupDialogData::CalculateIdFromPaperSize()
634 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
635 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
637 wxSize sz
= GetPaperSize();
639 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
640 if (id
!= wxPAPER_NONE
)
642 m_printData
.SetPaperId(id
);
646 // Use paper id in wxPrintData to set this object's paper size
647 void wxPageSetupDialogData::CalculatePaperSizeFromId()
649 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
650 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
652 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
654 // sz is in 10ths of a mm, while paper size is in mm
655 m_paperSize
.x
= sz
.x
/ 10;
656 m_paperSize
.y
= sz
.y
/ 10;
659 #endif // wxUSE_PRINTING_ARCHITECTURE