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__) && !defined(__PALMOS__)
54 #include "wx/msw/private.h"
56 #ifndef __SMARTPHONE__ /* of WinCE */
60 #if defined(__WATCOMC__) || defined(__SYMANTEC__) || defined(__SALFORDC__)
67 #include "wx/mac/private/print.h"
70 #if wxUSE_PRINTING_ARCHITECTURE
71 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
72 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
73 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
74 #endif // wxUSE_PRINTING_ARCHITECTURE
76 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
77 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
80 #define DMPAPER_USER 256
83 // ============================================================================
85 // ============================================================================
87 // ----------------------------------------------------------------------------
89 // ----------------------------------------------------------------------------
91 wxColourData::wxColourData()
94 m_dataColour
.Set(0,0,0);
95 // m_custColours are wxNullColours initially
98 wxColourData::wxColourData(const wxColourData
& data
)
104 wxColourData::~wxColourData()
108 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
110 wxCHECK_RET( (i
>= 0 && i
< 16), _T("custom colour index out of range") );
112 m_custColours
[i
] = colour
;
115 wxColour
wxColourData::GetCustomColour(int i
)
117 wxCHECK_MSG( (i
>= 0 && i
< 16), wxColour(0,0,0),
118 _T("custom colour index out of range") );
120 return m_custColours
[i
];
123 void wxColourData::operator=(const wxColourData
& data
)
126 for (i
= 0; i
< 16; i
++)
127 m_custColours
[i
] = data
.m_custColours
[i
];
129 m_dataColour
= (wxColour
&)data
.m_dataColour
;
130 m_chooseFull
= data
.m_chooseFull
;
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 wxFontData::wxFontData()
139 // Intialize colour to black.
140 m_fontColour
= wxNullColour
;
143 m_allowSymbols
= true;
144 m_enableEffects
= true;
148 m_encoding
= wxFONTENCODING_SYSTEM
;
151 wxFontData::~wxFontData()
157 wxFontDialogBase::~wxFontDialogBase()
161 #endif // wxUSE_FONTDLG
163 #if wxUSE_PRINTING_ARCHITECTURE
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 wxPrintData::wxPrintData()
171 m_nativePrintData
= wxNativePrintData::Create() ;
173 m_bin
= wxPRINTBIN_DEFAULT
;
174 m_printMode
= wxPRINT_MODE_PRINTER
;
175 m_printOrientation
= wxPORTRAIT
;
177 m_printCollate
= false;
180 m_printerName
= wxT("");
182 m_duplexMode
= wxDUPLEX_SIMPLEX
;
183 m_printQuality
= wxPRINT_QUALITY_HIGH
;
184 m_paperId
= wxPAPER_A4
;
185 m_paperSize
= wxSize(210, 297);
187 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
190 wxPrintData::wxPrintData(const wxPrintData
& printData
)
196 wxPrintData::~wxPrintData()
198 m_nativeData
->m_ref
--;
199 if (m_nativeData
->m_ref
== 0)
203 delete m_nativePrintData
;
207 void wxPrintData::ConvertToNative()
210 m_nativePrintData
->TransferFrom( this ) ;
212 m_nativeData
->TransferFrom( *this ) ;
216 void wxPrintData::ConvertFromNative()
219 m_nativePrintData
->TransferTo( this ) ;
221 m_nativeData
->TransferTo( *this ) ;
225 void wxPrintData::operator=(const wxPrintData
& data
)
227 m_printNoCopies
= data
.m_printNoCopies
;
228 m_printCollate
= data
.m_printCollate
;
229 m_printOrientation
= data
.m_printOrientation
;
230 m_printerName
= data
.m_printerName
;
231 m_colour
= data
.m_colour
;
232 m_duplexMode
= data
.m_duplexMode
;
233 m_printQuality
= data
.m_printQuality
;
234 m_paperId
= data
.m_paperId
;
235 m_paperSize
= data
.m_paperSize
;
237 m_printMode
= data
.m_printMode
;
238 m_filename
= data
.m_filename
;
240 // UnRef old m_nativeData
241 m_nativeData
->m_ref
--;
242 if (m_nativeData
->m_ref
== 0)
245 m_nativeData
= data
.GetNativeData();
246 m_nativeData
->m_ref
++;
249 m_nativePrintData
->CopyFrom( data
.m_nativePrintData
) ;
253 // Is this data OK for showing the print dialog?
254 bool wxPrintData::Ok() const
256 m_nativeData
->TransferFrom( *this );
258 return m_nativeData
->Ok();
261 #if WXWIN_COMPATIBILITY_2_4
263 #include "wx/generic/prntdlgg.h"
266 #define WXUNUSED_WITHOUT_PS(name) name
268 #define WXUNUSED_WITHOUT_PS(name) WXUNUSED(name)
271 wxString
wxPrintData::GetPrinterCommand() const
274 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
275 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterCommand();
280 wxString
wxPrintData::GetPrinterOptions() const
283 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
284 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterOptions();
289 wxString
wxPrintData::GetPreviewCommand() const
292 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
293 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPreviewCommand();
298 wxString
wxPrintData::GetFontMetricPath() const
301 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
302 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetFontMetricPath();
307 double wxPrintData::GetPrinterScaleX() const
310 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
311 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleX();
316 double wxPrintData::GetPrinterScaleY() const
319 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
320 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleY();
325 long wxPrintData::GetPrinterTranslateX() const
328 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
329 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateX();
334 long wxPrintData::GetPrinterTranslateY() const
337 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
338 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateY();
343 void wxPrintData::SetPrinterCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
346 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
347 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterCommand( command
);
351 void wxPrintData::SetPrinterOptions(const wxString
& WXUNUSED_WITHOUT_PS(options
))
354 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
355 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterOptions( options
);
359 void wxPrintData::SetPreviewCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
362 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
363 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPreviewCommand( command
);
367 void wxPrintData::SetFontMetricPath(const wxString
& WXUNUSED_WITHOUT_PS(path
))
370 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
371 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetFontMetricPath( path
);
375 void wxPrintData::SetPrinterScaleX(double WXUNUSED_WITHOUT_PS(x
))
378 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
379 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleX( x
);
383 void wxPrintData::SetPrinterScaleY(double WXUNUSED_WITHOUT_PS(y
))
386 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
387 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleY( y
);
391 void wxPrintData::SetPrinterScaling(double WXUNUSED_WITHOUT_PS(x
), double WXUNUSED_WITHOUT_PS(y
))
394 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
395 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaling( x
, y
);
399 void wxPrintData::SetPrinterTranslateX(long WXUNUSED_WITHOUT_PS(x
))
402 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
403 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateX( x
);
407 void wxPrintData::SetPrinterTranslateY(long WXUNUSED_WITHOUT_PS(y
))
410 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
411 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateY( y
);
415 void wxPrintData::SetPrinterTranslation(long WXUNUSED_WITHOUT_PS(x
), long WXUNUSED_WITHOUT_PS(y
))
418 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
419 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslation( x
, y
);
424 // ----------------------------------------------------------------------------
426 // ----------------------------------------------------------------------------
428 wxPrintDialogData::wxPrintDialogData()
435 m_printAllPages
= false;
436 m_printCollate
= false;
437 m_printToFile
= false;
438 m_printSelection
= false;
439 m_printEnableSelection
= false;
440 m_printEnablePageNumbers
= true;
442 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
443 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
445 m_printEnableHelp
= false;
446 #if WXWIN_COMPATIBILITY_2_4
447 m_printSetupDialog
= false;
451 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
454 (*this) = dialogData
;
457 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
462 m_printMaxPage
= 9999;
464 m_printAllPages
= false;
465 m_printCollate
= false;
466 m_printToFile
= false;
467 m_printSelection
= false;
468 m_printEnableSelection
= false;
469 m_printEnablePageNumbers
= true;
470 m_printEnablePrintToFile
= true;
471 m_printEnableHelp
= false;
472 #if WXWIN_COMPATIBILITY_2_4
473 m_printSetupDialog
= false;
475 m_printData
= printData
;
478 wxPrintDialogData::~wxPrintDialogData()
484 void wxPrintDialogData::ConvertToNative()
486 m_printData
.ConvertToNative();
487 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
490 void wxPrintDialogData::ConvertFromNative()
492 m_printData
.ConvertFromNative();
493 m_printData
.m_nativePrintData
->TransferTo( this ) ;
499 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
501 m_printFromPage
= data
.m_printFromPage
;
502 m_printToPage
= data
.m_printToPage
;
503 m_printMinPage
= data
.m_printMinPage
;
504 m_printMaxPage
= data
.m_printMaxPage
;
505 m_printNoCopies
= data
.m_printNoCopies
;
506 m_printAllPages
= data
.m_printAllPages
;
507 m_printCollate
= data
.m_printCollate
;
508 m_printToFile
= data
.m_printToFile
;
509 m_printSelection
= data
.m_printSelection
;
510 m_printEnableSelection
= data
.m_printEnableSelection
;
511 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
512 m_printEnableHelp
= data
.m_printEnableHelp
;
513 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
514 #if WXWIN_COMPATIBILITY_2_4
515 m_printSetupDialog
= data
.m_printSetupDialog
;
517 m_printData
= data
.m_printData
;
520 void wxPrintDialogData::operator=(const wxPrintData
& data
)
525 // ----------------------------------------------------------------------------
526 // wxPageSetupDialogData
527 // ----------------------------------------------------------------------------
529 wxPageSetupDialogData::wxPageSetupDialogData()
531 m_paperSize
= wxSize(0, 0);
533 CalculatePaperSizeFromId();
535 m_minMarginTopLeft
= wxPoint(0, 0);
536 m_minMarginBottomRight
= wxPoint(0, 0);
537 m_marginTopLeft
= wxPoint(0, 0);
538 m_marginBottomRight
= wxPoint(0, 0);
541 m_defaultMinMargins
= false;
542 m_enableMargins
= true;
543 m_enableOrientation
= true;
544 m_enablePaper
= true;
545 m_enablePrinter
= true;
546 m_enableHelp
= false;
547 m_getDefaultInfo
= false;
550 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
553 (*this) = dialogData
;
556 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
558 m_paperSize
= wxSize(0, 0);
559 m_minMarginTopLeft
= wxPoint(0, 0);
560 m_minMarginBottomRight
= wxPoint(0, 0);
561 m_marginTopLeft
= wxPoint(0, 0);
562 m_marginBottomRight
= wxPoint(0, 0);
565 m_defaultMinMargins
= false;
566 m_enableMargins
= true;
567 m_enableOrientation
= true;
568 m_enablePaper
= true;
569 m_enablePrinter
= true;
570 m_enableHelp
= false;
571 m_getDefaultInfo
= false;
573 m_printData
= printData
;
575 // The wxPrintData paper size overrides these values, unless the size cannot
577 CalculatePaperSizeFromId();
580 wxPageSetupDialogData::~wxPageSetupDialogData()
584 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
586 m_paperSize
= data
.m_paperSize
;
587 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
588 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
589 m_marginTopLeft
= data
.m_marginTopLeft
;
590 m_marginBottomRight
= data
.m_marginBottomRight
;
591 m_defaultMinMargins
= data
.m_defaultMinMargins
;
592 m_enableMargins
= data
.m_enableMargins
;
593 m_enableOrientation
= data
.m_enableOrientation
;
594 m_enablePaper
= data
.m_enablePaper
;
595 m_enablePrinter
= data
.m_enablePrinter
;
596 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
597 m_enableHelp
= data
.m_enableHelp
;
599 m_printData
= data
.m_printData
;
604 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
612 void wxPageSetupDialogData::ConvertToNative()
614 m_printData
.ConvertToNative();
615 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
618 void wxPageSetupDialogData::ConvertFromNative()
620 m_printData
.ConvertFromNative ();
621 m_paperSize
= m_printData
.GetPaperSize() ;
622 CalculateIdFromPaperSize();
623 m_printData
.m_nativePrintData
->TransferTo( this ) ;
624 // adjust minimal values
626 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
627 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
629 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
630 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
632 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
633 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
635 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
636 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
641 // If a corresponding paper type is found in the paper database, will set the m_printData
642 // paper size id member as well.
643 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
647 CalculateIdFromPaperSize();
650 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
651 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
653 m_printData
.SetPaperId(id
);
655 CalculatePaperSizeFromId();
658 // Use paper size defined in this object to set the wxPrintData
660 void wxPageSetupDialogData::CalculateIdFromPaperSize()
662 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
663 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
665 wxSize sz
= GetPaperSize();
667 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
668 if (id
!= wxPAPER_NONE
)
670 m_printData
.SetPaperId(id
);
674 // Use paper id in wxPrintData to set this object's paper size
675 void wxPageSetupDialogData::CalculatePaperSizeFromId()
677 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
678 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
680 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
682 // sz is in 10ths of a mm, while paper size is in mm
683 m_paperSize
.x
= sz
.x
/ 10;
684 m_paperSize
.y
= sz
.y
/ 10;
687 #endif // wxUSE_PRINTING_ARCHITECTURE