1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI data
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
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"
43 #if (defined(__WXMOTIF__) || defined(__WXGTK__)) && wxUSE_POSTSCRIPT
44 #define wxCOMPATIBILITY_WITH_PRINTSETUPDATA 1
47 #if wxUSE_PRINTING_ARCHITECTURE
50 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
51 #include "wx/generic/dcpsg.h"
53 #endif // wxUSE_PRINTING_ARCHITECTURE
57 #include "wx/msw/private.h"
59 #if !defined(__WIN32__)
69 #if defined(__WATCOMC__) || defined(__SC__) || defined(__SALFORDC__)
75 #if !USE_SHARED_LIBRARY
76 #if wxUSE_PRINTING_ARCHITECTURE
77 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
78 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
79 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
80 #endif // wxUSE_PRINTING_ARCHITECTURE
81 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
82 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
86 #define mm2pt 2.83464566929
87 #define pt2mm 0.352777777778
90 // ============================================================================
92 // ============================================================================
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 wxColourData::wxColourData()
101 for (i
= 0; i
< 16; i
++)
102 custColours
[i
].Set(255, 255, 255);
105 dataColour
.Set(0,0,0);
108 wxColourData::wxColourData(const wxColourData
& data
)
113 wxColourData::~wxColourData()
117 void wxColourData::SetCustomColour(int i
, wxColour
& colour
)
122 custColours
[i
] = colour
;
125 wxColour
wxColourData::GetCustomColour(int i
)
128 return wxColour(0,0,0);
130 return custColours
[i
];
133 void wxColourData::operator=(const wxColourData
& data
)
136 for (i
= 0; i
< 16; i
++)
137 custColours
[i
] = data
.custColours
[i
];
139 dataColour
= (wxColour
&)data
.dataColour
;
140 chooseFull
= data
.chooseFull
;
143 // ----------------------------------------------------------------------------
145 // ----------------------------------------------------------------------------
147 wxFontData::wxFontData()
149 // Intialize colour to black.
150 fontColour
.Set(0, 0, 0);
154 enableEffects
= TRUE
;
158 m_encoding
= wxFONTENCODING_SYSTEM
;
161 wxFontData::~wxFontData()
165 #if wxUSE_PRINTING_ARCHITECTURE
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
170 wxPrintData::wxPrintData()
174 #elif defined( __WXMAC__ )
175 m_macPrintInfo
= NULL
;
177 m_printOrientation
= wxPORTRAIT
;
179 m_printCollate
= FALSE
;
184 m_duplexMode
= wxDUPLEX_SIMPLEX
;
185 m_printQuality
= wxPRINT_QUALITY_HIGH
;
186 m_paperId
= wxPAPER_A4
;
187 m_paperSize
= wxSize(210, 297);
189 // PostScript-specific data
190 m_printerCommand
= "";
191 m_previewCommand
= "";
192 m_printerOptions
= "";
195 m_printerScaleX
= 1.0;
196 m_printerScaleY
= 1.0;
197 m_printerTranslateX
= 0;
198 m_printerTranslateY
= 0;
199 m_printMode
= wxPRINT_MODE_FILE
;
202 wxPrintData::wxPrintData(const wxPrintData
& printData
)
206 #elif defined( __WXMAC__ )
207 m_macPrintInfo
= NULL
;
212 wxPrintData::~wxPrintData()
215 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
217 GlobalFree(hDevMode
);
218 #elif defined(__WXMAC__)
219 if ( m_macPrintInfo
)
220 ::DisposeHandle( (Handle
) m_macPrintInfo
) ;
224 #if defined(__WXMSW__) // && defined(__WIN32__)
227 static wxString
wxGetPrintDlgError()
229 DWORD err
= CommDlgExtendedError();
230 wxString msg
= wxT("Unknown");
233 case CDERR_FINDRESFAILURE
: msg
= wxT("CDERR_FINDRESFAILURE"); break;
234 case CDERR_INITIALIZATION
: msg
= wxT("CDERR_INITIALIZATION"); break;
235 case CDERR_LOADRESFAILURE
: msg
= wxT("CDERR_LOADRESFAILURE"); break;
236 case CDERR_LOADSTRFAILURE
: msg
= wxT("CDERR_LOADSTRFAILURE"); break;
237 case CDERR_LOCKRESFAILURE
: msg
= wxT("CDERR_LOCKRESFAILURE"); break;
238 case CDERR_MEMALLOCFAILURE
: msg
= wxT("CDERR_MEMALLOCFAILURE"); break;
239 case CDERR_MEMLOCKFAILURE
: msg
= wxT("CDERR_MEMLOCKFAILURE"); break;
240 case CDERR_NOHINSTANCE
: msg
= wxT("CDERR_NOHINSTANCE"); break;
241 case CDERR_NOHOOK
: msg
= wxT("CDERR_NOHOOK"); break;
242 case CDERR_NOTEMPLATE
: msg
= wxT("CDERR_NOTEMPLATE"); break;
243 case CDERR_STRUCTSIZE
: msg
= wxT("CDERR_STRUCTSIZE"); break;
244 case PDERR_RETDEFFAILURE
: msg
= wxT("PDERR_RETDEFFAILURE"); break;
245 case PDERR_PRINTERNOTFOUND
: msg
= wxT("PDERR_PRINTERNOTFOUND"); break;
246 case PDERR_PARSEFAILURE
: msg
= wxT("PDERR_PARSEFAILURE"); break;
247 case PDERR_NODEVICES
: msg
= wxT("PDERR_NODEVICES"); break;
248 case PDERR_NODEFAULTPRN
: msg
= wxT("PDERR_NODEFAULTPRN"); break;
249 case PDERR_LOADDRVFAILURE
: msg
= wxT("PDERR_LOADDRVFAILURE"); break;
250 case PDERR_INITFAILURE
: msg
= wxT("PDERR_INITFAILURE"); break;
251 case PDERR_GETDEVMODEFAIL
: msg
= wxT("PDERR_GETDEVMODEFAIL"); break;
252 case PDERR_DNDMMISMATCH
: msg
= wxT("PDERR_DNDMMISMATCH"); break;
253 case PDERR_DEFAULTDIFFERENT
: msg
= wxT("PDERR_DEFAULTDIFFERENT"); break;
254 case PDERR_CREATEICFAILURE
: msg
= wxT("PDERR_CREATEICFAILURE"); break;
261 void wxPrintData::ConvertToNative()
263 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
266 // Use PRINTDLG as a way of creating a DEVMODE object
267 PRINTDLG
*pd
= new PRINTDLG
;
269 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
272 pd
->lStructSize
= 66 ;
274 memset(pd
, 0, sizeof(PRINTDLG
));
275 pd
->lStructSize
= sizeof(PRINTDLG
);
278 pd
->hwndOwner
= (HWND
)NULL
;
279 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
280 pd
->hDevNames
= NULL
; // Ditto
281 pd
->hInstance
= (HINSTANCE
) wxGetInstance();
283 pd
->Flags
= PD_RETURNDEFAULT
;
286 // Fill out the DEVMODE structure
287 // so we can use it as input in the 'real' PrintDlg
291 GlobalFree(pd
->hDevMode
);
293 GlobalFree(pd
->hDevNames
);
295 pd
->hDevNames
= NULL
;
297 #if defined(__WXDEBUG__) && defined(__WIN32__)
298 wxString
str(wxT("Printing error: "));
299 str
+= wxGetPrintDlgError();
306 GlobalFree(pd
->hDevNames
);
307 pd
->hDevNames
= NULL
;
309 hDevMode
= pd
->hDevMode
;
310 m_devMode
= (void*)(long) hDevMode
;
319 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(hDevMode
);
324 devMode
->dmOrientation
= m_printOrientation
;
326 devMode
->dmFields
= DM_ORIENTATION
;
331 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
332 devMode
->dmFields
|= DM_COLLATE
;
335 //// Number of copies
337 devMode
->dmCopies
= m_printNoCopies
;
338 devMode
->dmFields
|= DM_COPIES
;
342 if (m_printerName
!= wxT(""))
344 // TODO: make this Unicode compatible
345 int len
= wxMin(31, m_printerName
.Len());
347 for (i
= 0; i
< len
; i
++)
348 devMode
->dmDeviceName
[i
] = m_printerName
.GetChar(i
);
349 devMode
->dmDeviceName
[i
] = 0;
355 devMode
->dmColor
= DMCOLOR_COLOR
;
357 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
359 devMode
->dmFields
|= DM_COLOR
;
364 if (m_paperId
== wxPAPER_NONE
)
366 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
367 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
368 devMode
->dmFields
|= DM_PAPERWIDTH
;
369 devMode
->dmFields
|= DM_PAPERLENGTH
;
373 if (wxThePrintPaperDatabase
)
375 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
378 devMode
->dmPaperSize
= paper
->GetPlatformId();
379 devMode
->dmFields
|= DM_PAPERSIZE
;
388 switch (m_duplexMode
)
390 case wxDUPLEX_HORIZONTAL
: {
391 duplex
= DMDUP_HORIZONTAL
; break;
393 case wxDUPLEX_VERTICAL
: {
394 duplex
= DMDUP_VERTICAL
; break;
397 case wxDUPLEX_SIMPLEX
: {
398 duplex
= DMDUP_SIMPLEX
; break;
401 devMode
->dmDuplex
= duplex
;
402 devMode
->dmFields
|= DM_DUPLEX
;
407 switch (m_printQuality
)
409 case wxPRINT_QUALITY_MEDIUM
: {
410 quality
= DMRES_MEDIUM
; break;
412 case wxPRINT_QUALITY_LOW
: {
413 quality
= DMRES_LOW
; break;
415 case wxPRINT_QUALITY_DRAFT
: {
416 quality
= DMRES_DRAFT
; break;
418 case wxPRINT_QUALITY_HIGH
: {
419 quality
= DMRES_HIGH
; break;
422 quality
= m_printQuality
; break;
425 devMode
->dmPrintQuality
= quality
;
426 devMode
->dmFields
|= DM_PRINTQUALITY
;
428 GlobalUnlock(hDevMode
);
432 void wxPrintData::ConvertFromNative()
434 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
441 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(hDevMode
);
446 if (devMode
->dmFields
& DM_ORIENTATION
)
447 m_printOrientation
= devMode
->dmOrientation
;
453 if (devMode
->dmFields
& DM_COLLATE
)
455 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
456 m_printCollate
= TRUE
;
458 m_printCollate
= FALSE
;
462 //// Number of copies
464 if (devMode
->dmFields
& DM_COPIES
)
466 m_printNoCopies
= devMode
->dmCopies
;
471 if (devMode
->dmDeviceName
[0] != 0)
473 // TODO: make this Unicode compatible
476 while (devMode
->dmDeviceName
[i
] != 0)
478 buf
[i
] = devMode
->dmDeviceName
[i
];
488 if (devMode
->dmFields
& DM_COLOR
)
490 if (devMode
->dmColor
== DMCOLOR_COLOR
)
501 if (devMode
->dmFields
& DM_PAPERSIZE
)
503 if (wxThePrintPaperDatabase
)
505 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
508 m_paperId
= paper
->GetId();
509 m_paperSize
.x
= paper
->GetWidth() / 10 ;
510 m_paperSize
.y
= paper
->GetHeight() / 10 ;
514 // Shouldn't really get here
515 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
517 m_paperId
= wxPAPER_NONE
;
524 // Shouldn't really get here
525 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
527 m_paperId
= wxPAPER_NONE
;
532 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
534 m_paperSize
.x
= devMode
->dmPaperWidth
/ 10;
535 m_paperSize
.y
= devMode
->dmPaperLength
/ 10;
536 m_paperId
= wxPAPER_NONE
;
540 // Shouldn't really get here
541 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
545 m_paperId
= wxPAPER_NONE
;
551 if (devMode
->dmFields
& DM_DUPLEX
)
553 switch (devMode
->dmDuplex
)
555 case DMDUP_HORIZONTAL
: {
556 m_duplexMode
= wxDUPLEX_HORIZONTAL
; break;
558 case DMDUP_VERTICAL
: {
559 m_duplexMode
= wxDUPLEX_VERTICAL
; break;
562 case DMDUP_SIMPLEX
: {
563 m_duplexMode
= wxDUPLEX_SIMPLEX
; break;
568 m_duplexMode
= wxDUPLEX_SIMPLEX
;
572 if (devMode
->dmFields
& DM_PRINTQUALITY
)
574 switch (devMode
->dmPrintQuality
)
577 m_printQuality
= wxPRINT_QUALITY_MEDIUM
; break;
580 m_printQuality
= wxPRINT_QUALITY_LOW
; break;
583 m_printQuality
= wxPRINT_QUALITY_DRAFT
; break;
586 m_printQuality
= wxPRINT_QUALITY_HIGH
; break;
590 // TODO: if the printer fills in the resolution in DPI, how
591 // will the application know if it's high, low, draft etc.??
592 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
593 m_printQuality
= devMode
->dmPrintQuality
; break;
599 m_printQuality
= wxPRINT_QUALITY_HIGH
;
601 GlobalUnlock(hDevMode
);
608 void wxPrintData::ConvertToNative()
610 if ( !m_macPrintInfo
)
612 m_macPrintInfo
= (THPrint
) NewHandleClear( sizeof( TPrint
) ) ;
613 if ( m_macPrintInfo
)
615 ::PrintDefault( m_macPrintInfo
) ;
616 // todo setup the global pagesetup ?
619 if ( m_macPrintInfo
)
621 (**m_macPrintInfo
).prJob
.iCopies
= m_printNoCopies
;
622 (**m_macPrintInfo
).prJob
.iFstPage
= 0 ;
623 (**m_macPrintInfo
).prJob
.iLstPage
= 0 ;
627 void wxPrintData::ConvertFromNative()
629 if ( m_macPrintInfo
)
631 m_printNoCopies
= (**m_macPrintInfo
).prJob
.iCopies
;
636 void wxPrintData::operator=(const wxPrintData
& data
)
638 m_printNoCopies
= data
.m_printNoCopies
;
639 m_printCollate
= data
.m_printCollate
;
640 m_printOrientation
= data
.m_printOrientation
;
641 m_printerName
= data
.m_printerName
;
642 m_colour
= data
.m_colour
;
643 m_duplexMode
= data
.m_duplexMode
;
644 m_printQuality
= data
.m_printQuality
;
645 m_paperId
= data
.m_paperId
;
646 m_paperSize
= data
.m_paperSize
;
648 // PostScript-specific data
649 m_printerCommand
= data
.m_printerCommand
;
650 m_previewCommand
= data
.m_previewCommand
;
651 m_printerOptions
= data
.m_printerOptions
;
652 m_filename
= data
.m_filename
;
653 m_afmPath
= data
.m_afmPath
;
654 m_printerScaleX
= data
.m_printerScaleX
;
655 m_printerScaleY
= data
.m_printerScaleY
;
656 m_printerTranslateX
= data
.m_printerTranslateX
;
657 m_printerTranslateY
= data
.m_printerTranslateY
;
658 m_printMode
= data
.m_printMode
;
662 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
663 void wxPrintData::operator=(const wxPrintSetupData
& setupData
)
665 SetPrinterCommand(setupData
.GetPrinterCommand());
666 SetPreviewCommand(setupData
.GetPrintPreviewCommand());
667 SetPrinterOptions(setupData
.GetPrinterOptions());
670 setupData
.GetPrinterTranslation(& xt
, & yt
);
671 SetPrinterTranslation(xt
, yt
);
674 setupData
.GetPrinterScaling(& xs
, & ys
);
675 SetPrinterScaling(xs
, ys
);
677 SetOrientation(setupData
.GetPrinterOrientation());
678 SetPrintMode((wxPrintMode
) setupData
.GetPrinterMode());
679 SetFontMetricPath(setupData
.GetAFMPath());
680 if (setupData
.GetPaperName() != "")
681 SetPaperId(wxThePrintPaperDatabase
->ConvertNameToId(setupData
.GetPaperName()));
682 SetColour(setupData
.GetColour());
683 SetFilename(setupData
.GetPrinterFile());
685 #endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
688 // ----------------------------------------------------------------------------
690 // ----------------------------------------------------------------------------
692 wxPrintDialogData::wxPrintDialogData()
695 m_printDlgData
= NULL
;
696 #elif defined( __WXMAC__ )
697 m_macPrintInfo
= NULL
;
704 m_printAllPages
= FALSE
;
705 m_printCollate
= FALSE
;
706 m_printToFile
= FALSE
;
707 m_printSelection
= FALSE
;
708 m_printEnableSelection
= FALSE
;
709 m_printEnablePageNumbers
= TRUE
;
710 m_printEnablePrintToFile
= TRUE
;
711 m_printEnableHelp
= FALSE
;
712 m_printSetupDialog
= FALSE
;
715 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
718 m_printDlgData
= NULL
;
719 #elif defined( __WXMAC__ )
720 m_macPrintInfo
= NULL
;
722 (*this) = dialogData
;
725 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
728 m_printDlgData
= NULL
;
729 #elif defined( __WXMAC__ )
730 m_macPrintInfo
= NULL
;
737 m_printAllPages
= FALSE
;
738 m_printCollate
= FALSE
;
739 m_printToFile
= FALSE
;
740 m_printSelection
= FALSE
;
741 m_printEnableSelection
= FALSE
;
742 m_printEnablePageNumbers
= TRUE
;
743 m_printEnablePrintToFile
= TRUE
;
744 m_printEnableHelp
= FALSE
;
745 m_printSetupDialog
= FALSE
;
747 m_printData
= printData
;
750 wxPrintDialogData::~wxPrintDialogData()
753 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
754 if ( pd
&& pd
->hDevMode
)
755 GlobalFree(pd
->hDevMode
);
758 #elif defined(__WXMAC__)
759 if ( m_macPrintInfo
)
760 ::DisposeHandle( (Handle
) m_macPrintInfo
) ;
765 void wxPrintDialogData::ConvertToNative()
767 m_printData
.ConvertToNative();
769 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
774 m_printDlgData
= (void*) pd
;
776 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
778 pd
->lStructSize
= 66 ;
780 pd
->lStructSize
= sizeof(PRINTDLG
);
782 pd
->hwndOwner
= (HWND
)NULL
;
783 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
784 pd
->hDevNames
= NULL
; // Ditto
786 pd
->Flags
= PD_RETURNDEFAULT
;
790 // Pass the devmode data to the PRINTDLG structure, since it'll
791 // be needed when PrintDlg is called.
794 GlobalFree(pd
->hDevMode
);
797 pd
->hDevMode
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeData();
799 m_printData
.SetNativeData((void*) NULL
);
801 wxASSERT_MSG( (pd
->hDevMode
), wxT("hDevMode must be non-NULL in ConvertToNative!"));
803 pd
->hDC
= (HDC
) NULL
;
804 pd
->nFromPage
= (UINT
)m_printFromPage
;
805 pd
->nToPage
= (UINT
)m_printToPage
;
806 pd
->nMinPage
= (UINT
)m_printMinPage
;
807 pd
->nMaxPage
= (UINT
)m_printMaxPage
;
808 pd
->nCopies
= (UINT
)m_printNoCopies
;
810 pd
->Flags
= PD_RETURNDC
;
813 pd
->lStructSize
= 66 ;
815 pd
->lStructSize
= sizeof( PRINTDLG
);
818 pd
->hwndOwner
=(HWND
)NULL
;
819 pd
->hDevNames
=(HANDLE
)NULL
;
820 pd
->hInstance
=(HINSTANCE
)NULL
;
821 pd
->lCustData
= (LPARAM
) NULL
;
822 pd
->lpfnPrintHook
= NULL
;
823 pd
->lpfnSetupHook
= NULL
;
824 pd
->lpPrintTemplateName
= NULL
;
825 pd
->lpSetupTemplateName
= NULL
;
826 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
827 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
829 if ( m_printAllPages
)
830 pd
->Flags
|= PD_ALLPAGES
;
831 if ( m_printAllPages
)
832 pd
->Flags
|= PD_SELECTION
;
833 if ( m_printCollate
)
834 pd
->Flags
|= PD_COLLATE
;
836 pd
->Flags
|= PD_PRINTTOFILE
;
837 if ( !m_printEnablePrintToFile
)
838 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
839 if ( !m_printEnableSelection
)
840 pd
->Flags
|= PD_NOSELECTION
;
841 if ( !m_printEnablePageNumbers
)
842 pd
->Flags
|= PD_NOPAGENUMS
;
843 if ( m_printEnableHelp
)
844 pd
->Flags
|= PD_SHOWHELP
;
845 if ( m_printSetupDialog
)
846 pd
->Flags
|= PD_PRINTSETUP
;
849 void wxPrintDialogData::ConvertFromNative()
851 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
855 // Pass the devmode data back to the wxPrintData structure where it really belongs.
858 if (m_printData
.GetNativeData())
860 // Make sure we don't leak memory
861 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeData());
863 m_printData
.SetNativeData((void*)(long) pd
->hDevMode
);
867 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
868 // into wxWindows form.
869 m_printData
.ConvertFromNative();
871 m_printFromPage
= pd
->nFromPage
;
872 m_printToPage
= pd
->nToPage
;
873 m_printMinPage
= pd
->nMinPage
;
874 m_printMaxPage
= pd
->nMaxPage
;
875 m_printNoCopies
= pd
->nCopies
;
877 m_printAllPages
= ((pd
->Flags
& PD_ALLPAGES
) == PD_ALLPAGES
);
878 m_printSelection
= ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
);
879 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
880 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
881 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
882 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
883 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
884 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
885 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
887 /* port is obsolete in WIN32
891 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
893 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
894 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
895 GlobalUnlock(pd->hDevNames);
897 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
903 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
905 if ( m_printDlgData
== NULL
)
908 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
910 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
911 pd
->hwndOwner
=(HWND
) win
->GetHWND();
917 void wxPrintDialogData::ConvertToNative()
919 if ( !m_macPrintInfo
)
921 m_macPrintInfo
= (THPrint
) NewHandleClear( sizeof( TPrint
) ) ;
922 if ( m_macPrintInfo
)
924 ::PrintDefault( m_macPrintInfo
) ;
925 // todo setup the global pagesetup ?
928 if ( m_macPrintInfo
)
930 (**m_macPrintInfo
).prJob
.iCopies
= m_printNoCopies
;
931 (**m_macPrintInfo
).prJob
.iFstPage
= m_printFromPage
;
932 (**m_macPrintInfo
).prJob
.iLstPage
= m_printToPage
;
936 void wxPrintDialogData::ConvertFromNative()
938 if ( m_macPrintInfo
)
940 m_printNoCopies
= (**m_macPrintInfo
).prJob
.iCopies
;
941 m_printFromPage
= (**m_macPrintInfo
).prJob
.iFstPage
;
942 m_printToPage
= (**m_macPrintInfo
).prJob
.iLstPage
;
948 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
950 m_printFromPage
= data
.m_printFromPage
;
951 m_printToPage
= data
.m_printToPage
;
952 m_printMinPage
= data
.m_printMinPage
;
953 m_printMaxPage
= data
.m_printMaxPage
;
954 m_printNoCopies
= data
.m_printNoCopies
;
955 m_printAllPages
= data
.m_printAllPages
;
956 m_printCollate
= data
.m_printCollate
;
957 m_printToFile
= data
.m_printToFile
;
958 m_printSelection
= data
.m_printSelection
;
959 m_printEnableSelection
= data
.m_printEnableSelection
;
960 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
961 m_printEnableHelp
= data
.m_printEnableHelp
;
962 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
963 m_printSetupDialog
= data
.m_printSetupDialog
;
965 m_printData
= data
.m_printData
;
968 void wxPrintDialogData::operator=(const wxPrintData
& data
)
973 // ----------------------------------------------------------------------------
974 // wxPageSetupDialogData
975 // ----------------------------------------------------------------------------
977 wxPageSetupDialogData::wxPageSetupDialogData()
979 #if defined(__WIN95__)
980 m_pageSetupData
= NULL
;
981 #elif defined( __WXMAC__ )
982 m_macPageSetupInfo
= NULL
;
984 m_paperSize
= wxSize(0, 0);
986 CalculatePaperSizeFromId();
988 m_minMarginTopLeft
= wxPoint(0, 0);
989 m_minMarginBottomRight
= wxPoint(0, 0);
990 m_marginTopLeft
= wxPoint(0, 0);
991 m_marginBottomRight
= wxPoint(0, 0);
994 m_defaultMinMargins
= FALSE
;
995 m_enableMargins
= TRUE
;
996 m_enableOrientation
= TRUE
;
997 m_enablePaper
= TRUE
;
998 m_enablePrinter
= TRUE
;
999 m_enableHelp
= FALSE
;
1000 m_getDefaultInfo
= FALSE
;
1003 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
1005 #if defined(__WIN95__)
1006 m_pageSetupData
= NULL
;
1007 #elif defined( __WXMAC__ )
1008 m_macPageSetupInfo
= NULL
;
1010 (*this) = dialogData
;
1013 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
1015 #if defined(__WIN95__)
1016 m_pageSetupData
= NULL
;
1017 #elif defined( __WXMAC__ )
1018 m_macPageSetupInfo
= NULL
;
1020 m_paperSize
= wxSize(0, 0);
1021 m_minMarginTopLeft
= wxPoint(0, 0);
1022 m_minMarginBottomRight
= wxPoint(0, 0);
1023 m_marginTopLeft
= wxPoint(0, 0);
1024 m_marginBottomRight
= wxPoint(0, 0);
1027 m_defaultMinMargins
= FALSE
;
1028 m_enableMargins
= TRUE
;
1029 m_enableOrientation
= TRUE
;
1030 m_enablePaper
= TRUE
;
1031 m_enablePrinter
= TRUE
;
1032 m_enableHelp
= FALSE
;
1033 m_getDefaultInfo
= FALSE
;
1035 m_printData
= printData
;
1037 // The wxPrintData paper size overrides these values, unless the size cannot
1039 CalculatePaperSizeFromId();
1042 wxPageSetupDialogData::~wxPageSetupDialogData()
1044 #if defined(__WIN95__) && defined(__WXMSW__)
1045 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
1046 if ( pd
&& pd
->hDevMode
)
1047 GlobalFree(pd
->hDevMode
);
1050 #elif defined( __WXMAC__ )
1051 if( m_macPageSetupInfo
)
1052 ::DisposeHandle( (Handle
) m_macPageSetupInfo
) ;
1056 void wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
1058 m_paperSize
= data
.m_paperSize
;
1059 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
1060 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
1061 m_marginTopLeft
= data
.m_marginTopLeft
;
1062 m_marginBottomRight
= data
.m_marginBottomRight
;
1063 m_defaultMinMargins
= data
.m_defaultMinMargins
;
1064 m_enableMargins
= data
.m_enableMargins
;
1065 m_enableOrientation
= data
.m_enableOrientation
;
1066 m_enablePaper
= data
.m_enablePaper
;
1067 m_enablePrinter
= data
.m_enablePrinter
;
1068 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
1069 m_enableHelp
= data
.m_enableHelp
;
1071 m_printData
= data
.m_printData
;
1074 void wxPageSetupDialogData::operator=(const wxPrintData
& data
)
1079 #if defined(__WIN95__)
1080 void wxPageSetupDialogData::ConvertToNative()
1082 m_printData
.ConvertToNative();
1084 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1086 if ( m_pageSetupData
== NULL
)
1088 pd
= new PAGESETUPDLG
;
1089 pd
->hDevMode
= NULL
;
1090 m_pageSetupData
= (void *)pd
;
1093 // Pass the devmode data (created in m_printData.ConvertToNative)
1094 // to the PRINTDLG structure, since it'll
1095 // be needed when PrintDlg is called.
1099 GlobalFree(pd
->hDevMode
);
1100 pd
->hDevMode
= NULL
;
1103 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
1105 m_printData
.SetNativeData((void*) NULL
);
1107 wxASSERT_MSG( (pd
->hDevMode
), wxT("hDevMode must be non-NULL in ConvertToNative!"));
1109 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1111 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1113 if ( m_defaultMinMargins
)
1114 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
1115 if ( !m_enableMargins
)
1116 pd
->Flags
|= PSD_DISABLEMARGINS
;
1117 if ( !m_enableOrientation
)
1118 pd
->Flags
|= PSD_DISABLEORIENTATION
;
1119 if ( !m_enablePaper
)
1120 pd
->Flags
|= PSD_DISABLEPAPER
;
1121 if ( !m_enablePrinter
)
1122 pd
->Flags
|= PSD_DISABLEPRINTER
;
1123 if ( m_getDefaultInfo
)
1124 pd
->Flags
|= PSD_RETURNDEFAULT
;
1126 pd
->Flags
|= PSD_SHOWHELP
;
1128 // We want the units to be in hundredths of a millimetre
1129 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1131 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
1132 pd
->hwndOwner
=(HWND
)NULL
;
1133 pd
->hDevNames
=(HWND
)NULL
;
1134 pd
->hInstance
=(HINSTANCE
)NULL
;
1136 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
1137 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
1139 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
1140 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
1141 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
1142 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
1144 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
1145 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
1146 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
1147 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
1150 pd
->lpfnPageSetupHook
= NULL
;
1151 pd
->lpfnPagePaintHook
= NULL
;
1152 pd
->hPageSetupTemplate
= NULL
;
1153 pd
->lpPageSetupTemplateName
= NULL
;
1158 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1159 memset(devMode, 0, sizeof(DEVMODE));
1160 devMode->dmSize = sizeof(DEVMODE);
1161 devMode->dmOrientation = m_orientation;
1162 devMode->dmFields = DM_ORIENTATION;
1163 GlobalUnlock(pd->hDevMode);
1168 void wxPageSetupDialogData::ConvertFromNative()
1170 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1174 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1177 if (m_printData
.GetNativeData())
1179 // Make sure we don't leak memory
1180 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1182 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1183 pd
->hDevMode
= NULL
;
1186 m_printData
.ConvertFromNative();
1188 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1190 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
1191 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
1192 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
1193 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
1194 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
1195 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
1196 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
1198 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1199 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
1201 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
1202 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
1203 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
1204 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
1206 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100 ;
1207 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100 ;
1208 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100 ;
1209 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100 ;
1212 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1214 if ( m_pageSetupData
== NULL
)
1217 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1219 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1220 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1226 void wxPageSetupDialogData::ConvertToNative()
1228 if ( !m_macPageSetupInfo
)
1230 m_macPageSetupInfo
= (THPrint
) NewHandleClear( sizeof( TPrint
) ) ;
1231 if ( m_macPageSetupInfo
)
1233 ::PrintDefault( m_macPageSetupInfo
) ;
1236 if ( m_macPageSetupInfo
)
1238 // on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0
1239 (**m_macPageSetupInfo
).rPaper
.left
= int( ((double) m_minMarginTopLeft
.x
)*mm2pt
) ;
1240 (**m_macPageSetupInfo
).rPaper
.top
= int( ((double) m_minMarginTopLeft
.y
)*mm2pt
) ;
1242 (**m_macPageSetupInfo
).rPaper
.right
= int( ((double) m_paperSize
.x
- m_minMarginTopLeft
.x
)*mm2pt
) ;
1243 (**m_macPageSetupInfo
).rPaper
.bottom
= int( ((double) m_paperSize
.y
- m_minMarginTopLeft
.y
)*mm2pt
) ;
1245 (**m_macPageSetupInfo
).prInfo
.rPage
.left
= 0 ;
1246 (**m_macPageSetupInfo
).prInfo
.rPage
.top
= 0 ;
1247 (**m_macPageSetupInfo
).prInfo
.rPage
.right
= int( ((double) m_paperSize
.x
- m_minMarginTopLeft
.x
- m_minMarginBottomRight
.x
)*mm2pt
) ;
1248 (**m_macPageSetupInfo
).prInfo
.rPage
.bottom
= int( ((double) m_paperSize
.y
- m_minMarginTopLeft
.y
- m_minMarginBottomRight
.y
)*mm2pt
) ;
1250 //TODO add custom fields in dialog for margins
1255 void wxPageSetupDialogData::ConvertFromNative()
1257 if ( m_macPageSetupInfo
)
1259 m_paperSize
.x
= ((double) (**m_macPageSetupInfo
).rPaper
.right
- (**m_macPageSetupInfo
).rPaper
.left
) * pt2mm
;
1260 m_paperSize
.y
= ((double) (**m_macPageSetupInfo
).rPaper
.bottom
- (**m_macPageSetupInfo
).rPaper
.top
) * pt2mm
;
1262 m_minMarginTopLeft
.x
= ((double) -(**m_macPageSetupInfo
).rPaper
.left
) * pt2mm
;
1263 m_minMarginTopLeft
.y
= ((double) -(**m_macPageSetupInfo
).rPaper
.top
) * pt2mm
;
1265 m_minMarginBottomRight
.x
= ((double) (**m_macPageSetupInfo
).rPaper
.right
- (**m_macPageSetupInfo
).prInfo
.rPage
.right
) * pt2mm
;
1266 m_minMarginBottomRight
.y
= ((double)(**m_macPageSetupInfo
).rPaper
.bottom
- (**m_macPageSetupInfo
).prInfo
.rPage
.bottom
) * pt2mm
;
1268 // adjust minimal values
1269 //TODO add custom fields in dialog for margins
1271 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
1272 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
1274 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
1275 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
1277 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
1278 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
1280 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
1281 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
1288 // If a corresponding paper type is found in the paper database, will set the m_printData
1289 // paper size id member as well.
1290 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
1294 CalculateIdFromPaperSize();
1297 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1298 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1300 m_printData
.SetPaperId(id
);
1302 CalculatePaperSizeFromId();
1305 // Use paper size defined in this object to set the wxPrintData
1307 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1309 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1310 wxT("wxThePrintPaperDatabase should not be NULL. "
1311 "Do not create global print dialog data objects.") );
1313 wxSize sz
= GetPaperSize();
1315 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1316 if (id
!= wxPAPER_NONE
)
1318 m_printData
.SetPaperId(id
);
1322 // Use paper id in wxPrintData to set this object's paper size
1323 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1325 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1326 wxT("wxThePrintPaperDatabase should not be NULL. "
1327 "Do not create global print dialog data objects.") );
1329 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
1333 // sz is in 10ths of a mm, so multiply by 10.
1334 m_paperSize
.x
= sz
.x
* 10;
1335 m_paperSize
.y
= sz
.y
* 10;
1339 #endif // wxUSE_PRINTING_ARCHITECTURE