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()
162 m_nativePrintData
= wxNativePrintData::Create() ;
164 m_bin
= wxPRINTBIN_DEFAULT
;
165 m_printMode
= wxPRINT_MODE_PRINTER
;
166 m_printOrientation
= wxPORTRAIT
;
168 m_printCollate
= false;
171 m_printerName
= wxEmptyString
;
173 m_duplexMode
= wxDUPLEX_SIMPLEX
;
174 m_printQuality
= wxPRINT_QUALITY_HIGH
;
175 m_paperId
= wxPAPER_A4
;
176 m_paperSize
= wxSize(210, 297);
181 m_nativeData
= wxPrintFactory::GetFactory()->CreatePrintNativeData();
184 wxPrintData::wxPrintData(const wxPrintData
& printData
)
191 void wxPrintData::SetPrivData( char *privData
, int len
)
195 delete [] m_privData
;
199 if (m_privDataLen
> 0)
201 m_privData
= new char[m_privDataLen
];
202 memcpy( m_privData
, privData
, m_privDataLen
);
206 wxPrintData::~wxPrintData()
208 m_nativeData
->m_ref
--;
209 if (m_nativeData
->m_ref
== 0)
213 delete [] m_privData
;
216 delete m_nativePrintData
;
220 void wxPrintData::ConvertToNative()
223 m_nativePrintData
->TransferFrom( this ) ;
225 m_nativeData
->TransferFrom( *this ) ;
229 void wxPrintData::ConvertFromNative()
232 m_nativePrintData
->TransferTo( this ) ;
234 m_nativeData
->TransferTo( *this ) ;
238 void wxPrintData::operator=(const wxPrintData
& data
)
240 m_printNoCopies
= data
.m_printNoCopies
;
241 m_printCollate
= data
.m_printCollate
;
242 m_printOrientation
= data
.m_printOrientation
;
243 m_printerName
= data
.m_printerName
;
244 m_colour
= data
.m_colour
;
245 m_duplexMode
= data
.m_duplexMode
;
246 m_printQuality
= data
.m_printQuality
;
247 m_paperId
= data
.m_paperId
;
248 m_paperSize
= data
.m_paperSize
;
250 m_printMode
= data
.m_printMode
;
251 m_filename
= data
.m_filename
;
253 // UnRef old m_nativeData
256 m_nativeData
->m_ref
--;
257 if (m_nativeData
->m_ref
== 0)
261 m_nativeData
= data
.GetNativeData();
262 m_nativeData
->m_ref
++;
266 delete [] m_privData
;
269 m_privDataLen
= data
.GetPrivDataLen();
270 if (m_privDataLen
> 0)
272 m_privData
= new char[m_privDataLen
];
273 memcpy( m_privData
, data
.GetPrivData(), m_privDataLen
);
277 m_nativePrintData
->CopyFrom( data
.m_nativePrintData
) ;
281 // Is this data OK for showing the print dialog?
282 bool wxPrintData::Ok() const
284 m_nativeData
->TransferFrom( *this );
286 return m_nativeData
->Ok();
289 // What should happen here? wxPostScriptPrintNativeData is not
290 // defined unless all this is true on MSW.
291 #if WXWIN_COMPATIBILITY_2_4 && wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
293 #include "wx/generic/prntdlgg.h"
296 #define WXUNUSED_WITHOUT_PS(name) name
298 #define WXUNUSED_WITHOUT_PS(name) WXUNUSED(name)
301 wxString
wxPrintData::GetPrinterCommand() const
304 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
305 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterCommand();
307 return wxEmptyString
;
310 wxString
wxPrintData::GetPrinterOptions() const
313 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
314 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterOptions();
316 return wxEmptyString
;
319 wxString
wxPrintData::GetPreviewCommand() const
322 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
323 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPreviewCommand();
325 return wxEmptyString
;
328 wxString
wxPrintData::GetFontMetricPath() const
331 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
332 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetFontMetricPath();
334 return wxEmptyString
;
337 double wxPrintData::GetPrinterScaleX() const
340 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
341 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleX();
346 double wxPrintData::GetPrinterScaleY() const
349 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
350 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleY();
355 long wxPrintData::GetPrinterTranslateX() const
358 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
359 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateX();
364 long wxPrintData::GetPrinterTranslateY() const
367 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
368 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateY();
373 void wxPrintData::SetPrinterCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
376 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
377 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterCommand( command
);
381 void wxPrintData::SetPrinterOptions(const wxString
& WXUNUSED_WITHOUT_PS(options
))
384 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
385 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterOptions( options
);
389 void wxPrintData::SetPreviewCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
392 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
393 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPreviewCommand( command
);
397 void wxPrintData::SetFontMetricPath(const wxString
& WXUNUSED_WITHOUT_PS(path
))
400 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
401 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetFontMetricPath( path
);
405 void wxPrintData::SetPrinterScaleX(double WXUNUSED_WITHOUT_PS(x
))
408 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
409 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleX( x
);
413 void wxPrintData::SetPrinterScaleY(double WXUNUSED_WITHOUT_PS(y
))
416 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
417 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleY( y
);
421 void wxPrintData::SetPrinterScaling(double WXUNUSED_WITHOUT_PS(x
), double WXUNUSED_WITHOUT_PS(y
))
424 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
425 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaling( x
, y
);
429 void wxPrintData::SetPrinterTranslateX(long WXUNUSED_WITHOUT_PS(x
))
432 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
433 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateX( x
);
437 void wxPrintData::SetPrinterTranslateY(long WXUNUSED_WITHOUT_PS(y
))
440 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
441 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateY( y
);
445 void wxPrintData::SetPrinterTranslation(long WXUNUSED_WITHOUT_PS(x
), long WXUNUSED_WITHOUT_PS(y
))
448 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
449 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslation( x
, y
);
454 // ----------------------------------------------------------------------------
456 // ----------------------------------------------------------------------------
458 wxPrintDialogData::wxPrintDialogData()
465 m_printAllPages
= false;
466 m_printCollate
= false;
467 m_printToFile
= false;
468 m_printSelection
= false;
469 m_printEnableSelection
= false;
470 m_printEnablePageNumbers
= true;
472 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
473 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
475 m_printEnableHelp
= false;
476 #if WXWIN_COMPATIBILITY_2_4
477 m_printSetupDialog
= false;
481 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
484 (*this) = dialogData
;
487 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
492 m_printMaxPage
= 9999;
494 m_printAllPages
= false;
495 m_printCollate
= false;
496 m_printToFile
= false;
497 m_printSelection
= false;
498 m_printEnableSelection
= false;
499 m_printEnablePageNumbers
= true;
500 m_printEnablePrintToFile
= true;
501 m_printEnableHelp
= false;
502 #if WXWIN_COMPATIBILITY_2_4
503 m_printSetupDialog
= false;
505 m_printData
= printData
;
508 wxPrintDialogData::~wxPrintDialogData()
514 void wxPrintDialogData::ConvertToNative()
516 m_printData
.ConvertToNative();
517 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
520 void wxPrintDialogData::ConvertFromNative()
522 m_printData
.ConvertFromNative();
523 m_printData
.m_nativePrintData
->TransferTo( this ) ;
529 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
531 m_printFromPage
= data
.m_printFromPage
;
532 m_printToPage
= data
.m_printToPage
;
533 m_printMinPage
= data
.m_printMinPage
;
534 m_printMaxPage
= data
.m_printMaxPage
;
535 m_printNoCopies
= data
.m_printNoCopies
;
536 m_printAllPages
= data
.m_printAllPages
;
537 m_printCollate
= data
.m_printCollate
;
538 m_printToFile
= data
.m_printToFile
;
539 m_printSelection
= data
.m_printSelection
;
540 m_printEnableSelection
= data
.m_printEnableSelection
;
541 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
542 m_printEnableHelp
= data
.m_printEnableHelp
;
543 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
544 #if WXWIN_COMPATIBILITY_2_4
545 m_printSetupDialog
= data
.m_printSetupDialog
;
547 m_printData
= data
.m_printData
;
550 void wxPrintDialogData::operator=(const wxPrintData
& data
)
555 // ----------------------------------------------------------------------------
556 // wxPageSetupDialogData
557 // ----------------------------------------------------------------------------
559 wxPageSetupDialogData::wxPageSetupDialogData()
561 m_paperSize
= wxSize(0,0);
563 CalculatePaperSizeFromId();
566 m_minMarginBottomRight
=
568 m_marginBottomRight
= wxPoint(0,0);
571 m_defaultMinMargins
= false;
572 m_enableMargins
= true;
573 m_enableOrientation
= true;
574 m_enablePaper
= true;
575 m_enablePrinter
= true;
576 m_enableHelp
= false;
577 m_getDefaultInfo
= false;
580 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
583 (*this) = dialogData
;
586 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
588 m_paperSize
= wxSize(0,0);
590 m_minMarginBottomRight
=
592 m_marginBottomRight
= wxPoint(0,0);
595 m_defaultMinMargins
= false;
596 m_enableMargins
= true;
597 m_enableOrientation
= true;
598 m_enablePaper
= true;
599 m_enablePrinter
= true;
600 m_enableHelp
= false;
601 m_getDefaultInfo
= false;
603 m_printData
= printData
;
605 // The wxPrintData paper size overrides these values, unless the size cannot
607 CalculatePaperSizeFromId();
610 wxPageSetupDialogData::~wxPageSetupDialogData()
614 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
616 m_paperSize
= data
.m_paperSize
;
617 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
618 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
619 m_marginTopLeft
= data
.m_marginTopLeft
;
620 m_marginBottomRight
= data
.m_marginBottomRight
;
621 m_defaultMinMargins
= data
.m_defaultMinMargins
;
622 m_enableMargins
= data
.m_enableMargins
;
623 m_enableOrientation
= data
.m_enableOrientation
;
624 m_enablePaper
= data
.m_enablePaper
;
625 m_enablePrinter
= data
.m_enablePrinter
;
626 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
627 m_enableHelp
= data
.m_enableHelp
;
629 m_printData
= data
.m_printData
;
634 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
637 CalculatePaperSizeFromId();
643 void wxPageSetupDialogData::ConvertToNative()
645 m_printData
.ConvertToNative();
646 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
649 void wxPageSetupDialogData::ConvertFromNative()
651 m_printData
.ConvertFromNative ();
652 m_paperSize
= m_printData
.GetPaperSize() ;
653 CalculateIdFromPaperSize();
654 m_printData
.m_nativePrintData
->TransferTo( this ) ;
655 // adjust minimal values
657 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
658 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
660 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
661 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
663 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
664 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
666 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
667 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
672 // If a corresponding paper type is found in the paper database, will set the m_printData
673 // paper size id member as well.
674 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
678 CalculateIdFromPaperSize();
681 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
682 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
684 m_printData
.SetPaperId(id
);
686 CalculatePaperSizeFromId();
689 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
691 m_printData
= printData
;
692 CalculatePaperSizeFromId();
695 // Use paper size defined in this object to set the wxPrintData
697 void wxPageSetupDialogData::CalculateIdFromPaperSize()
699 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
700 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
702 wxSize sz
= GetPaperSize();
704 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
705 if (id
!= wxPAPER_NONE
)
707 m_printData
.SetPaperId(id
);
711 // Use paper id in wxPrintData to set this object's paper size
712 void wxPageSetupDialogData::CalculatePaperSizeFromId()
714 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
715 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
717 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
719 // sz is in 10ths of a mm, while paper size is in mm
720 m_paperSize
.x
= sz
.x
/ 10;
721 m_paperSize
.y
= sz
.y
/ 10;
724 #endif // wxUSE_PRINTING_ARCHITECTURE