1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/cmndata.cpp
3 // Purpose: Common GDI data
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/cmndata.h"
31 #include "wx/string.h"
37 #include "wx/gdicmn.h"
38 #include "wx/prntbase.h"
39 #include "wx/printdlg.h"
42 #include "wx/fontdlg.h"
43 #endif // wxUSE_FONTDLG
45 #if wxUSE_PRINTING_ARCHITECTURE
47 #endif // wxUSE_PRINTING_ARCHITECTURE
49 #if defined(__WXMSW__)
50 #include "wx/msw/wrapcdlg.h"
53 #if wxUSE_PRINTING_ARCHITECTURE
55 #if defined(__WXMAC__)
56 #include "wx/mac/private/print.h"
59 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
60 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
61 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
62 #endif // wxUSE_PRINTING_ARCHITECTURE
64 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
65 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
67 // ============================================================================
69 // ============================================================================
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 wxColourData::wxColourData()
78 m_dataColour
.Set(0,0,0);
79 // m_custColours are wxNullColours initially
82 wxColourData::wxColourData(const wxColourData
& data
)
88 wxColourData::~wxColourData()
92 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
94 wxCHECK_RET( (i
>= 0 && i
< 16), _T("custom colour index out of range") );
96 m_custColours
[i
] = colour
;
99 wxColour
wxColourData::GetCustomColour(int i
)
101 wxCHECK_MSG( (i
>= 0 && i
< 16), wxColour(0,0,0),
102 _T("custom colour index out of range") );
104 return m_custColours
[i
];
107 void wxColourData::operator=(const wxColourData
& data
)
110 for (i
= 0; i
< 16; i
++)
111 m_custColours
[i
] = data
.m_custColours
[i
];
113 m_dataColour
= (wxColour
&)data
.m_dataColour
;
114 m_chooseFull
= data
.m_chooseFull
;
117 // ----------------------------------------------------------------------------
119 // ----------------------------------------------------------------------------
121 wxFontData::wxFontData()
123 // Intialize colour to black.
124 m_fontColour
= wxNullColour
;
127 m_allowSymbols
= true;
128 m_enableEffects
= true;
132 m_encoding
= wxFONTENCODING_SYSTEM
;
135 wxFontData::~wxFontData()
141 wxFontDialogBase::~wxFontDialogBase()
145 #endif // wxUSE_FONTDLG
147 #if wxUSE_PRINTING_ARCHITECTURE
148 // ----------------------------------------------------------------------------
150 // ----------------------------------------------------------------------------
152 wxPrintData::wxPrintData()
154 m_bin
= wxPRINTBIN_DEFAULT
;
155 m_printMode
= wxPRINT_MODE_PRINTER
;
156 m_printOrientation
= wxPORTRAIT
;
158 m_printCollate
= false;
161 m_printerName
= wxEmptyString
;
163 m_duplexMode
= wxDUPLEX_SIMPLEX
;
164 m_printQuality
= wxPRINT_QUALITY_HIGH
;
165 m_paperId
= wxPAPER_A4
;
166 m_paperSize
= wxSize(210, 297);
171 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
174 wxPrintData::wxPrintData(const wxPrintData
& printData
)
182 void wxPrintData::SetPrivData( char *privData
, int len
)
186 delete [] m_privData
;
190 if (m_privDataLen
> 0)
192 m_privData
= new char[m_privDataLen
];
193 memcpy( m_privData
, privData
, m_privDataLen
);
197 wxPrintData::~wxPrintData()
199 m_nativeData
->m_ref
--;
200 if (m_nativeData
->m_ref
== 0)
204 delete [] m_privData
;
207 void wxPrintData::ConvertToNative()
209 m_nativeData
->TransferFrom( *this ) ;
212 void wxPrintData::ConvertFromNative()
214 m_nativeData
->TransferTo( *this ) ;
217 void wxPrintData::operator=(const wxPrintData
& data
)
219 m_printNoCopies
= data
.m_printNoCopies
;
220 m_printCollate
= data
.m_printCollate
;
221 m_printOrientation
= data
.m_printOrientation
;
222 m_printerName
= data
.m_printerName
;
223 m_colour
= data
.m_colour
;
224 m_duplexMode
= data
.m_duplexMode
;
225 m_printQuality
= data
.m_printQuality
;
226 m_paperId
= data
.m_paperId
;
227 m_paperSize
= data
.m_paperSize
;
229 m_printMode
= data
.m_printMode
;
230 m_filename
= data
.m_filename
;
232 // UnRef old m_nativeData
235 m_nativeData
->m_ref
--;
236 if (m_nativeData
->m_ref
== 0)
240 m_nativeData
= data
.GetNativeData();
241 m_nativeData
->m_ref
++;
245 delete [] m_privData
;
248 m_privDataLen
= data
.GetPrivDataLen();
249 if (m_privDataLen
> 0)
251 m_privData
= new char[m_privDataLen
];
252 memcpy( m_privData
, data
.GetPrivData(), m_privDataLen
);
256 // Is this data OK for showing the print dialog?
257 bool wxPrintData::Ok() const
259 m_nativeData
->TransferFrom( *this );
261 return m_nativeData
->Ok();
264 // What should happen here? wxPostScriptPrintNativeData is not
265 // defined unless all this is true on MSW.
266 #if WXWIN_COMPATIBILITY_2_4 && wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
268 #include "wx/generic/prntdlgg.h"
271 #define WXUNUSED_WITHOUT_PS(name) name
273 #define WXUNUSED_WITHOUT_PS(name) WXUNUSED(name)
276 wxString
wxPrintData::GetPrinterCommand() const
279 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
280 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterCommand();
282 return wxEmptyString
;
285 wxString
wxPrintData::GetPrinterOptions() const
288 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
289 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterOptions();
291 return wxEmptyString
;
294 wxString
wxPrintData::GetPreviewCommand() const
297 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
298 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPreviewCommand();
300 return wxEmptyString
;
303 wxString
wxPrintData::GetFontMetricPath() const
306 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
307 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetFontMetricPath();
309 return wxEmptyString
;
312 double wxPrintData::GetPrinterScaleX() const
315 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
316 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleX();
321 double wxPrintData::GetPrinterScaleY() const
324 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
325 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleY();
330 long wxPrintData::GetPrinterTranslateX() const
333 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
334 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateX();
339 long wxPrintData::GetPrinterTranslateY() const
342 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
343 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateY();
348 void wxPrintData::SetPrinterCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
351 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
352 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterCommand( command
);
356 void wxPrintData::SetPrinterOptions(const wxString
& WXUNUSED_WITHOUT_PS(options
))
359 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
360 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterOptions( options
);
364 void wxPrintData::SetPreviewCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
367 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
368 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPreviewCommand( command
);
372 void wxPrintData::SetFontMetricPath(const wxString
& WXUNUSED_WITHOUT_PS(path
))
375 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
376 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetFontMetricPath( path
);
380 void wxPrintData::SetPrinterScaleX(double WXUNUSED_WITHOUT_PS(x
))
383 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
384 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleX( x
);
388 void wxPrintData::SetPrinterScaleY(double WXUNUSED_WITHOUT_PS(y
))
391 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
392 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleY( y
);
396 void wxPrintData::SetPrinterScaling(double WXUNUSED_WITHOUT_PS(x
), double WXUNUSED_WITHOUT_PS(y
))
399 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
400 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaling( x
, y
);
404 void wxPrintData::SetPrinterTranslateX(long WXUNUSED_WITHOUT_PS(x
))
407 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
408 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateX( x
);
412 void wxPrintData::SetPrinterTranslateY(long WXUNUSED_WITHOUT_PS(y
))
415 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
416 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateY( y
);
420 void wxPrintData::SetPrinterTranslation(long WXUNUSED_WITHOUT_PS(x
), long WXUNUSED_WITHOUT_PS(y
))
423 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
424 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslation( x
, y
);
429 // ----------------------------------------------------------------------------
431 // ----------------------------------------------------------------------------
433 wxPrintDialogData::wxPrintDialogData()
440 m_printAllPages
= false;
441 m_printCollate
= false;
442 m_printToFile
= false;
443 m_printSelection
= false;
444 m_printEnableSelection
= false;
445 m_printEnablePageNumbers
= true;
447 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
448 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
450 m_printEnableHelp
= false;
451 #if WXWIN_COMPATIBILITY_2_4
452 m_printSetupDialog
= false;
456 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
459 (*this) = dialogData
;
462 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
467 m_printMaxPage
= 9999;
469 m_printAllPages
= false;
470 m_printCollate
= false;
471 m_printToFile
= false;
472 m_printSelection
= false;
473 m_printEnableSelection
= false;
474 m_printEnablePageNumbers
= true;
475 m_printEnablePrintToFile
= true;
476 m_printEnableHelp
= false;
477 #if WXWIN_COMPATIBILITY_2_4
478 m_printSetupDialog
= false;
480 m_printData
= printData
;
483 wxPrintDialogData::~wxPrintDialogData()
487 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
489 m_printFromPage
= data
.m_printFromPage
;
490 m_printToPage
= data
.m_printToPage
;
491 m_printMinPage
= data
.m_printMinPage
;
492 m_printMaxPage
= data
.m_printMaxPage
;
493 m_printNoCopies
= data
.m_printNoCopies
;
494 m_printAllPages
= data
.m_printAllPages
;
495 m_printCollate
= data
.m_printCollate
;
496 m_printToFile
= data
.m_printToFile
;
497 m_printSelection
= data
.m_printSelection
;
498 m_printEnableSelection
= data
.m_printEnableSelection
;
499 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
500 m_printEnableHelp
= data
.m_printEnableHelp
;
501 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
502 #if WXWIN_COMPATIBILITY_2_4
503 m_printSetupDialog
= data
.m_printSetupDialog
;
505 m_printData
= data
.m_printData
;
508 void wxPrintDialogData::operator=(const wxPrintData
& data
)
513 // ----------------------------------------------------------------------------
514 // wxPageSetupDialogData
515 // ----------------------------------------------------------------------------
517 wxPageSetupDialogData::wxPageSetupDialogData()
519 m_paperSize
= wxSize(0,0);
521 CalculatePaperSizeFromId();
524 m_minMarginBottomRight
=
526 m_marginBottomRight
= wxPoint(0,0);
529 m_defaultMinMargins
= false;
530 m_enableMargins
= true;
531 m_enableOrientation
= true;
532 m_enablePaper
= true;
533 m_enablePrinter
= true;
534 m_enableHelp
= false;
535 m_getDefaultInfo
= false;
538 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
541 (*this) = dialogData
;
544 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
546 m_paperSize
= wxSize(0,0);
548 m_minMarginBottomRight
=
550 m_marginBottomRight
= wxPoint(0,0);
553 m_defaultMinMargins
= false;
554 m_enableMargins
= true;
555 m_enableOrientation
= true;
556 m_enablePaper
= true;
557 m_enablePrinter
= true;
558 m_enableHelp
= false;
559 m_getDefaultInfo
= false;
561 m_printData
= printData
;
563 // The wxPrintData paper size overrides these values, unless the size cannot
565 CalculatePaperSizeFromId();
568 wxPageSetupDialogData::~wxPageSetupDialogData()
572 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
574 m_paperSize
= data
.m_paperSize
;
575 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
576 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
577 m_marginTopLeft
= data
.m_marginTopLeft
;
578 m_marginBottomRight
= data
.m_marginBottomRight
;
579 m_defaultMinMargins
= data
.m_defaultMinMargins
;
580 m_enableMargins
= data
.m_enableMargins
;
581 m_enableOrientation
= data
.m_enableOrientation
;
582 m_enablePaper
= data
.m_enablePaper
;
583 m_enablePrinter
= data
.m_enablePrinter
;
584 m_getDefaultInfo
= data
.m_getDefaultInfo
;
585 m_enableHelp
= data
.m_enableHelp
;
587 m_printData
= data
.m_printData
;
592 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
595 CalculatePaperSizeFromId();
600 // If a corresponding paper type is found in the paper database, will set the m_printData
601 // paper size id member as well.
602 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
606 CalculateIdFromPaperSize();
609 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
610 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
612 m_printData
.SetPaperId(id
);
614 CalculatePaperSizeFromId();
617 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
619 m_printData
= printData
;
620 CalculatePaperSizeFromId();
623 // Use paper size defined in this object to set the wxPrintData
625 void wxPageSetupDialogData::CalculateIdFromPaperSize()
627 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
628 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
630 wxSize sz
= GetPaperSize();
632 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
633 if (id
!= wxPAPER_NONE
)
635 m_printData
.SetPaperId(id
);
639 // Use paper id in wxPrintData to set this object's paper size
640 void wxPageSetupDialogData::CalculatePaperSizeFromId()
642 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
643 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
645 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
647 // sz is in 10ths of a mm, while paper size is in mm
648 m_paperSize
.x
= sz
.x
/ 10;
649 m_paperSize
.y
= sz
.y
/ 10;
652 #endif // wxUSE_PRINTING_ARCHITECTURE