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"
265 wxString
wxPrintData::GetPrinterCommand() const
268 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
269 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterCommand();
274 wxString
wxPrintData::GetPrinterOptions() const
277 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
278 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterOptions();
283 wxString
wxPrintData::GetPreviewCommand() const
286 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
287 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPreviewCommand();
292 wxString
wxPrintData::GetFontMetricPath() const
295 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
296 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetFontMetricPath();
301 double wxPrintData::GetPrinterScaleX() const
304 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
305 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleX();
310 double wxPrintData::GetPrinterScaleY() const
313 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
314 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleY();
319 long wxPrintData::GetPrinterTranslateX() const
322 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
323 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateX();
328 long wxPrintData::GetPrinterTranslateY() const
331 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
332 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateY();
337 void wxPrintData::SetPrinterCommand(const wxString
& command
)
340 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
341 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterCommand( command
);
345 void wxPrintData::SetPrinterOptions(const wxString
& options
)
348 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
349 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterOptions( options
);
353 void wxPrintData::SetPreviewCommand(const wxString
& command
)
356 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
357 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPreviewCommand( command
);
361 void wxPrintData::SetFontMetricPath(const wxString
& path
)
364 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
365 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetFontMetricPath( path
);
369 void wxPrintData::SetPrinterScaleX(double x
)
372 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
373 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleX( x
);
377 void wxPrintData::SetPrinterScaleY(double y
)
380 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
381 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleY( y
);
385 void wxPrintData::SetPrinterScaling(double x
, double y
)
388 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
389 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaling( x
, y
);
393 void wxPrintData::SetPrinterTranslateX(long x
)
396 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
397 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateX( x
);
401 void wxPrintData::SetPrinterTranslateY(long y
)
404 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
405 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateY( y
);
409 void wxPrintData::SetPrinterTranslation(long x
, long y
)
412 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
413 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslation( x
, y
);
418 // ----------------------------------------------------------------------------
420 // ----------------------------------------------------------------------------
422 wxPrintDialogData::wxPrintDialogData()
429 m_printAllPages
= false;
430 m_printCollate
= false;
431 m_printToFile
= false;
432 m_printSelection
= false;
433 m_printEnableSelection
= false;
434 m_printEnablePageNumbers
= true;
436 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
437 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
439 m_printEnableHelp
= false;
440 #if WXWIN_COMPATIBILITY_2_4
441 m_printSetupDialog
= false;
445 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
448 (*this) = dialogData
;
451 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
456 m_printMaxPage
= 9999;
458 m_printAllPages
= false;
459 m_printCollate
= false;
460 m_printToFile
= false;
461 m_printSelection
= false;
462 m_printEnableSelection
= false;
463 m_printEnablePageNumbers
= true;
464 m_printEnablePrintToFile
= true;
465 m_printEnableHelp
= false;
466 #if WXWIN_COMPATIBILITY_2_4
467 m_printSetupDialog
= false;
469 m_printData
= printData
;
472 wxPrintDialogData::~wxPrintDialogData()
478 void wxPrintDialogData::ConvertToNative()
480 m_printData
.ConvertToNative();
481 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
484 void wxPrintDialogData::ConvertFromNative()
486 m_printData
.ConvertFromNative();
487 m_printData
.m_nativePrintData
->TransferTo( this ) ;
493 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
495 m_printFromPage
= data
.m_printFromPage
;
496 m_printToPage
= data
.m_printToPage
;
497 m_printMinPage
= data
.m_printMinPage
;
498 m_printMaxPage
= data
.m_printMaxPage
;
499 m_printNoCopies
= data
.m_printNoCopies
;
500 m_printAllPages
= data
.m_printAllPages
;
501 m_printCollate
= data
.m_printCollate
;
502 m_printToFile
= data
.m_printToFile
;
503 m_printSelection
= data
.m_printSelection
;
504 m_printEnableSelection
= data
.m_printEnableSelection
;
505 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
506 m_printEnableHelp
= data
.m_printEnableHelp
;
507 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
508 #if WXWIN_COMPATIBILITY_2_4
509 m_printSetupDialog
= data
.m_printSetupDialog
;
511 m_printData
= data
.m_printData
;
514 void wxPrintDialogData::operator=(const wxPrintData
& data
)
519 // ----------------------------------------------------------------------------
520 // wxPageSetupDialogData
521 // ----------------------------------------------------------------------------
523 wxPageSetupDialogData::wxPageSetupDialogData()
525 m_paperSize
= wxSize(0, 0);
527 CalculatePaperSizeFromId();
529 m_minMarginTopLeft
= wxPoint(0, 0);
530 m_minMarginBottomRight
= wxPoint(0, 0);
531 m_marginTopLeft
= wxPoint(0, 0);
532 m_marginBottomRight
= wxPoint(0, 0);
535 m_defaultMinMargins
= false;
536 m_enableMargins
= true;
537 m_enableOrientation
= true;
538 m_enablePaper
= true;
539 m_enablePrinter
= true;
540 m_enableHelp
= false;
541 m_getDefaultInfo
= false;
544 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
547 (*this) = dialogData
;
550 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
552 m_paperSize
= wxSize(0, 0);
553 m_minMarginTopLeft
= wxPoint(0, 0);
554 m_minMarginBottomRight
= wxPoint(0, 0);
555 m_marginTopLeft
= wxPoint(0, 0);
556 m_marginBottomRight
= wxPoint(0, 0);
559 m_defaultMinMargins
= false;
560 m_enableMargins
= true;
561 m_enableOrientation
= true;
562 m_enablePaper
= true;
563 m_enablePrinter
= true;
564 m_enableHelp
= false;
565 m_getDefaultInfo
= false;
567 m_printData
= printData
;
569 // The wxPrintData paper size overrides these values, unless the size cannot
571 CalculatePaperSizeFromId();
574 wxPageSetupDialogData::~wxPageSetupDialogData()
578 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
580 m_paperSize
= data
.m_paperSize
;
581 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
582 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
583 m_marginTopLeft
= data
.m_marginTopLeft
;
584 m_marginBottomRight
= data
.m_marginBottomRight
;
585 m_defaultMinMargins
= data
.m_defaultMinMargins
;
586 m_enableMargins
= data
.m_enableMargins
;
587 m_enableOrientation
= data
.m_enableOrientation
;
588 m_enablePaper
= data
.m_enablePaper
;
589 m_enablePrinter
= data
.m_enablePrinter
;
590 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
591 m_enableHelp
= data
.m_enableHelp
;
593 m_printData
= data
.m_printData
;
598 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
606 void wxPageSetupDialogData::ConvertToNative()
608 m_printData
.ConvertToNative();
609 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
612 void wxPageSetupDialogData::ConvertFromNative()
614 m_printData
.ConvertFromNative ();
615 m_paperSize
= m_printData
.GetPaperSize() ;
616 CalculateIdFromPaperSize();
617 m_printData
.m_nativePrintData
->TransferTo( this ) ;
618 // adjust minimal values
620 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
621 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
623 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
624 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
626 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
627 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
629 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
630 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
635 // If a corresponding paper type is found in the paper database, will set the m_printData
636 // paper size id member as well.
637 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
641 CalculateIdFromPaperSize();
644 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
645 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
647 m_printData
.SetPaperId(id
);
649 CalculatePaperSizeFromId();
652 // Use paper size defined in this object to set the wxPrintData
654 void wxPageSetupDialogData::CalculateIdFromPaperSize()
656 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
657 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
659 wxSize sz
= GetPaperSize();
661 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
662 if (id
!= wxPAPER_NONE
)
664 m_printData
.SetPaperId(id
);
668 // Use paper id in wxPrintData to set this object's paper size
669 void wxPageSetupDialogData::CalculatePaperSizeFromId()
671 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
672 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
674 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
676 // sz is in 10ths of a mm, while paper size is in mm
677 m_paperSize
.x
= sz
.x
/ 10;
678 m_paperSize
.y
= sz
.y
/ 10;
681 #endif // wxUSE_PRINTING_ARCHITECTURE