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
)
192 void wxPrintData::SetPrivData( char *privData
, int len
)
196 delete [] m_privData
;
200 if (m_privDataLen
> 0)
202 m_privData
= new char[m_privDataLen
];
203 memcpy( m_privData
, privData
, m_privDataLen
);
207 wxPrintData::~wxPrintData()
209 m_nativeData
->m_ref
--;
210 if (m_nativeData
->m_ref
== 0)
214 delete [] m_privData
;
217 delete m_nativePrintData
;
221 void wxPrintData::ConvertToNative()
224 m_nativePrintData
->TransferFrom( this ) ;
226 m_nativeData
->TransferFrom( *this ) ;
230 void wxPrintData::ConvertFromNative()
233 m_nativePrintData
->TransferTo( this ) ;
235 m_nativeData
->TransferTo( *this ) ;
239 void wxPrintData::operator=(const wxPrintData
& data
)
241 m_printNoCopies
= data
.m_printNoCopies
;
242 m_printCollate
= data
.m_printCollate
;
243 m_printOrientation
= data
.m_printOrientation
;
244 m_printerName
= data
.m_printerName
;
245 m_colour
= data
.m_colour
;
246 m_duplexMode
= data
.m_duplexMode
;
247 m_printQuality
= data
.m_printQuality
;
248 m_paperId
= data
.m_paperId
;
249 m_paperSize
= data
.m_paperSize
;
251 m_printMode
= data
.m_printMode
;
252 m_filename
= data
.m_filename
;
254 // UnRef old m_nativeData
257 m_nativeData
->m_ref
--;
258 if (m_nativeData
->m_ref
== 0)
262 m_nativeData
= data
.GetNativeData();
263 m_nativeData
->m_ref
++;
267 delete [] m_privData
;
270 m_privDataLen
= data
.GetPrivDataLen();
271 if (m_privDataLen
> 0)
273 m_privData
= new char[m_privDataLen
];
274 memcpy( m_privData
, data
.GetPrivData(), m_privDataLen
);
278 m_nativePrintData
->CopyFrom( data
.m_nativePrintData
) ;
282 // Is this data OK for showing the print dialog?
283 bool wxPrintData::Ok() const
285 m_nativeData
->TransferFrom( *this );
287 return m_nativeData
->Ok();
290 // What should happen here? wxPostScriptPrintNativeData is not
291 // defined unless all this is true on MSW.
292 #if WXWIN_COMPATIBILITY_2_4 && wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
294 #include "wx/generic/prntdlgg.h"
297 #define WXUNUSED_WITHOUT_PS(name) name
299 #define WXUNUSED_WITHOUT_PS(name) WXUNUSED(name)
302 wxString
wxPrintData::GetPrinterCommand() const
305 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
306 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterCommand();
308 return wxEmptyString
;
311 wxString
wxPrintData::GetPrinterOptions() const
314 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
315 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterOptions();
317 return wxEmptyString
;
320 wxString
wxPrintData::GetPreviewCommand() const
323 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
324 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPreviewCommand();
326 return wxEmptyString
;
329 wxString
wxPrintData::GetFontMetricPath() const
332 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
333 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetFontMetricPath();
335 return wxEmptyString
;
338 double wxPrintData::GetPrinterScaleX() const
341 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
342 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleX();
347 double wxPrintData::GetPrinterScaleY() const
350 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
351 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterScaleY();
356 long wxPrintData::GetPrinterTranslateX() const
359 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
360 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateX();
365 long wxPrintData::GetPrinterTranslateY() const
368 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
369 return ((wxPostScriptPrintNativeData
*)m_nativeData
)->GetPrinterTranslateY();
374 void wxPrintData::SetPrinterCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
377 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
378 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterCommand( command
);
382 void wxPrintData::SetPrinterOptions(const wxString
& WXUNUSED_WITHOUT_PS(options
))
385 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
386 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterOptions( options
);
390 void wxPrintData::SetPreviewCommand(const wxString
& WXUNUSED_WITHOUT_PS(command
))
393 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
394 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPreviewCommand( command
);
398 void wxPrintData::SetFontMetricPath(const wxString
& WXUNUSED_WITHOUT_PS(path
))
401 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
402 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetFontMetricPath( path
);
406 void wxPrintData::SetPrinterScaleX(double WXUNUSED_WITHOUT_PS(x
))
409 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
410 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleX( x
);
414 void wxPrintData::SetPrinterScaleY(double WXUNUSED_WITHOUT_PS(y
))
417 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
418 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaleY( y
);
422 void wxPrintData::SetPrinterScaling(double WXUNUSED_WITHOUT_PS(x
), double WXUNUSED_WITHOUT_PS(y
))
425 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
426 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterScaling( x
, y
);
430 void wxPrintData::SetPrinterTranslateX(long WXUNUSED_WITHOUT_PS(x
))
433 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
434 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateX( x
);
438 void wxPrintData::SetPrinterTranslateY(long WXUNUSED_WITHOUT_PS(y
))
441 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
442 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslateY( y
);
446 void wxPrintData::SetPrinterTranslation(long WXUNUSED_WITHOUT_PS(x
), long WXUNUSED_WITHOUT_PS(y
))
449 if (m_nativeData
&& wxIsKindOf(m_nativeData
,wxPostScriptPrintNativeData
))
450 ((wxPostScriptPrintNativeData
*)m_nativeData
)->SetPrinterTranslation( x
, y
);
455 // ----------------------------------------------------------------------------
457 // ----------------------------------------------------------------------------
459 wxPrintDialogData::wxPrintDialogData()
466 m_printAllPages
= false;
467 m_printCollate
= false;
468 m_printToFile
= false;
469 m_printSelection
= false;
470 m_printEnableSelection
= false;
471 m_printEnablePageNumbers
= true;
473 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
474 m_printEnablePrintToFile
= ! factory
->HasOwnPrintToFile();
476 m_printEnableHelp
= false;
477 #if WXWIN_COMPATIBILITY_2_4
478 m_printSetupDialog
= false;
482 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
485 (*this) = dialogData
;
488 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
493 m_printMaxPage
= 9999;
495 m_printAllPages
= false;
496 m_printCollate
= false;
497 m_printToFile
= false;
498 m_printSelection
= false;
499 m_printEnableSelection
= false;
500 m_printEnablePageNumbers
= true;
501 m_printEnablePrintToFile
= true;
502 m_printEnableHelp
= false;
503 #if WXWIN_COMPATIBILITY_2_4
504 m_printSetupDialog
= false;
506 m_printData
= printData
;
509 wxPrintDialogData::~wxPrintDialogData()
515 void wxPrintDialogData::ConvertToNative()
517 m_printData
.ConvertToNative();
518 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
521 void wxPrintDialogData::ConvertFromNative()
523 m_printData
.ConvertFromNative();
524 m_printData
.m_nativePrintData
->TransferTo( this ) ;
530 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
532 m_printFromPage
= data
.m_printFromPage
;
533 m_printToPage
= data
.m_printToPage
;
534 m_printMinPage
= data
.m_printMinPage
;
535 m_printMaxPage
= data
.m_printMaxPage
;
536 m_printNoCopies
= data
.m_printNoCopies
;
537 m_printAllPages
= data
.m_printAllPages
;
538 m_printCollate
= data
.m_printCollate
;
539 m_printToFile
= data
.m_printToFile
;
540 m_printSelection
= data
.m_printSelection
;
541 m_printEnableSelection
= data
.m_printEnableSelection
;
542 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
543 m_printEnableHelp
= data
.m_printEnableHelp
;
544 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
545 #if WXWIN_COMPATIBILITY_2_4
546 m_printSetupDialog
= data
.m_printSetupDialog
;
548 m_printData
= data
.m_printData
;
551 void wxPrintDialogData::operator=(const wxPrintData
& data
)
556 // ----------------------------------------------------------------------------
557 // wxPageSetupDialogData
558 // ----------------------------------------------------------------------------
560 wxPageSetupDialogData::wxPageSetupDialogData()
562 m_paperSize
= wxSize(0,0);
564 CalculatePaperSizeFromId();
567 m_minMarginBottomRight
=
569 m_marginBottomRight
= wxPoint(0,0);
572 m_defaultMinMargins
= false;
573 m_enableMargins
= true;
574 m_enableOrientation
= true;
575 m_enablePaper
= true;
576 m_enablePrinter
= true;
577 m_enableHelp
= false;
578 m_getDefaultInfo
= false;
581 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
584 (*this) = dialogData
;
587 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
589 m_paperSize
= wxSize(0,0);
591 m_minMarginBottomRight
=
593 m_marginBottomRight
= wxPoint(0,0);
596 m_defaultMinMargins
= false;
597 m_enableMargins
= true;
598 m_enableOrientation
= true;
599 m_enablePaper
= true;
600 m_enablePrinter
= true;
601 m_enableHelp
= false;
602 m_getDefaultInfo
= false;
604 m_printData
= printData
;
606 // The wxPrintData paper size overrides these values, unless the size cannot
608 CalculatePaperSizeFromId();
611 wxPageSetupDialogData::~wxPageSetupDialogData()
615 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
617 m_paperSize
= data
.m_paperSize
;
618 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
619 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
620 m_marginTopLeft
= data
.m_marginTopLeft
;
621 m_marginBottomRight
= data
.m_marginBottomRight
;
622 m_defaultMinMargins
= data
.m_defaultMinMargins
;
623 m_enableMargins
= data
.m_enableMargins
;
624 m_enableOrientation
= data
.m_enableOrientation
;
625 m_enablePaper
= data
.m_enablePaper
;
626 m_enablePrinter
= data
.m_enablePrinter
;
627 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
628 m_enableHelp
= data
.m_enableHelp
;
630 m_printData
= data
.m_printData
;
635 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
638 CalculatePaperSizeFromId();
644 void wxPageSetupDialogData::ConvertToNative()
646 m_printData
.ConvertToNative();
647 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
650 void wxPageSetupDialogData::ConvertFromNative()
652 m_printData
.ConvertFromNative ();
653 m_paperSize
= m_printData
.GetPaperSize() ;
654 CalculateIdFromPaperSize();
655 m_printData
.m_nativePrintData
->TransferTo( this ) ;
656 // adjust minimal values
658 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
659 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
661 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
662 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
664 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
665 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
667 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
668 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
673 // If a corresponding paper type is found in the paper database, will set the m_printData
674 // paper size id member as well.
675 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
679 CalculateIdFromPaperSize();
682 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
683 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
685 m_printData
.SetPaperId(id
);
687 CalculatePaperSizeFromId();
690 void wxPageSetupDialogData::SetPrintData(const wxPrintData
& printData
)
692 m_printData
= printData
;
693 CalculatePaperSizeFromId();
696 // Use paper size defined in this object to set the wxPrintData
698 void wxPageSetupDialogData::CalculateIdFromPaperSize()
700 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
701 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
703 wxSize sz
= GetPaperSize();
705 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
706 if (id
!= wxPAPER_NONE
)
708 m_printData
.SetPaperId(id
);
712 // Use paper id in wxPrintData to set this object's paper size
713 void wxPageSetupDialogData::CalculatePaperSizeFromId()
715 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
716 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
718 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
720 // sz is in 10ths of a mm, while paper size is in mm
721 m_paperSize
.x
= sz
.x
/ 10;
722 m_paperSize
.y
= sz
.y
/ 10;
725 #endif // wxUSE_PRINTING_ARCHITECTURE