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 wxUSE_PRINTING_ARCHITECTURE
76 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
77 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
78 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
79 #endif // wxUSE_PRINTING_ARCHITECTURE
80 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
81 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
84 #define mm2pt 2.83464566929
85 #define pt2mm 0.352777777778
88 // ============================================================================
90 // ============================================================================
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 wxColourData::wxColourData()
99 for (i
= 0; i
< 16; i
++)
100 custColours
[i
].Set(255, 255, 255);
103 dataColour
.Set(0,0,0);
106 wxColourData::wxColourData(const wxColourData
& data
)
111 wxColourData::~wxColourData()
115 void wxColourData::SetCustomColour(int i
, wxColour
& colour
)
120 custColours
[i
] = colour
;
123 wxColour
wxColourData::GetCustomColour(int i
)
126 return wxColour(0,0,0);
128 return custColours
[i
];
131 void wxColourData::operator=(const wxColourData
& data
)
134 for (i
= 0; i
< 16; i
++)
135 custColours
[i
] = data
.custColours
[i
];
137 dataColour
= (wxColour
&)data
.dataColour
;
138 chooseFull
= data
.chooseFull
;
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
145 wxFontData::wxFontData()
147 // Intialize colour to black.
148 fontColour
.Set(0, 0, 0);
152 enableEffects
= TRUE
;
156 m_encoding
= wxFONTENCODING_SYSTEM
;
159 wxFontData::~wxFontData()
163 #if wxUSE_PRINTING_ARCHITECTURE
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 wxPrintData::wxPrintData()
172 #elif defined( __WXMAC__ )
173 m_macPrintInfo
= NULL
;
175 m_printOrientation
= wxPORTRAIT
;
177 m_printCollate
= FALSE
;
182 m_duplexMode
= wxDUPLEX_SIMPLEX
;
183 m_printQuality
= wxPRINT_QUALITY_HIGH
;
184 m_paperId
= wxPAPER_A4
;
185 m_paperSize
= wxSize(210, 297);
187 // PostScript-specific data
188 m_printerCommand
= "";
189 m_previewCommand
= "";
190 m_printerOptions
= "";
193 m_printerScaleX
= 1.0;
194 m_printerScaleY
= 1.0;
195 m_printerTranslateX
= 0;
196 m_printerTranslateY
= 0;
197 m_printMode
= wxPRINT_MODE_FILE
;
200 wxPrintData::wxPrintData(const wxPrintData
& printData
)
204 #elif defined( __WXMAC__ )
205 m_macPrintInfo
= NULL
;
210 wxPrintData::~wxPrintData()
213 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
215 GlobalFree(hDevMode
);
216 #elif defined(__WXMAC__)
217 if ( m_macPrintInfo
)
218 ::DisposeHandle( (Handle
) m_macPrintInfo
) ;
222 #if defined(__WXMSW__) // && defined(__WIN32__)
225 static wxString
wxGetPrintDlgError()
227 DWORD err
= CommDlgExtendedError();
228 wxString msg
= wxT("Unknown");
231 case CDERR_FINDRESFAILURE
: msg
= wxT("CDERR_FINDRESFAILURE"); break;
232 case CDERR_INITIALIZATION
: msg
= wxT("CDERR_INITIALIZATION"); break;
233 case CDERR_LOADRESFAILURE
: msg
= wxT("CDERR_LOADRESFAILURE"); break;
234 case CDERR_LOADSTRFAILURE
: msg
= wxT("CDERR_LOADSTRFAILURE"); break;
235 case CDERR_LOCKRESFAILURE
: msg
= wxT("CDERR_LOCKRESFAILURE"); break;
236 case CDERR_MEMALLOCFAILURE
: msg
= wxT("CDERR_MEMALLOCFAILURE"); break;
237 case CDERR_MEMLOCKFAILURE
: msg
= wxT("CDERR_MEMLOCKFAILURE"); break;
238 case CDERR_NOHINSTANCE
: msg
= wxT("CDERR_NOHINSTANCE"); break;
239 case CDERR_NOHOOK
: msg
= wxT("CDERR_NOHOOK"); break;
240 case CDERR_NOTEMPLATE
: msg
= wxT("CDERR_NOTEMPLATE"); break;
241 case CDERR_STRUCTSIZE
: msg
= wxT("CDERR_STRUCTSIZE"); break;
242 case PDERR_RETDEFFAILURE
: msg
= wxT("PDERR_RETDEFFAILURE"); break;
243 case PDERR_PRINTERNOTFOUND
: msg
= wxT("PDERR_PRINTERNOTFOUND"); break;
244 case PDERR_PARSEFAILURE
: msg
= wxT("PDERR_PARSEFAILURE"); break;
245 case PDERR_NODEVICES
: msg
= wxT("PDERR_NODEVICES"); break;
246 case PDERR_NODEFAULTPRN
: msg
= wxT("PDERR_NODEFAULTPRN"); break;
247 case PDERR_LOADDRVFAILURE
: msg
= wxT("PDERR_LOADDRVFAILURE"); break;
248 case PDERR_INITFAILURE
: msg
= wxT("PDERR_INITFAILURE"); break;
249 case PDERR_GETDEVMODEFAIL
: msg
= wxT("PDERR_GETDEVMODEFAIL"); break;
250 case PDERR_DNDMMISMATCH
: msg
= wxT("PDERR_DNDMMISMATCH"); break;
251 case PDERR_DEFAULTDIFFERENT
: msg
= wxT("PDERR_DEFAULTDIFFERENT"); break;
252 case PDERR_CREATEICFAILURE
: msg
= wxT("PDERR_CREATEICFAILURE"); break;
259 void wxPrintData::ConvertToNative()
261 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
264 // Use PRINTDLG as a way of creating a DEVMODE object
265 PRINTDLG
*pd
= new PRINTDLG
;
267 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
270 pd
->lStructSize
= 66 ;
272 memset(pd
, 0, sizeof(PRINTDLG
));
273 pd
->lStructSize
= sizeof(PRINTDLG
);
276 pd
->hwndOwner
= (HWND
)NULL
;
277 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
278 pd
->hDevNames
= NULL
; // Ditto
279 pd
->hInstance
= (HINSTANCE
) wxGetInstance();
281 pd
->Flags
= PD_RETURNDEFAULT
;
284 // Fill out the DEVMODE structure
285 // so we can use it as input in the 'real' PrintDlg
289 GlobalFree(pd
->hDevMode
);
291 GlobalFree(pd
->hDevNames
);
293 pd
->hDevNames
= NULL
;
295 #if defined(__WXDEBUG__) && defined(__WIN32__)
296 wxString
str(wxT("Printing error: "));
297 str
+= wxGetPrintDlgError();
304 GlobalFree(pd
->hDevNames
);
305 pd
->hDevNames
= NULL
;
307 hDevMode
= pd
->hDevMode
;
308 m_devMode
= (void*)(long) hDevMode
;
317 LPDEVMODE devMode
= (LPDEVMODE
) GlobalLock(hDevMode
);
322 devMode
->dmOrientation
= m_printOrientation
;
324 devMode
->dmFields
= DM_ORIENTATION
;
329 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
330 devMode
->dmFields
|= DM_COLLATE
;
333 //// Number of copies
335 devMode
->dmCopies
= m_printNoCopies
;
336 devMode
->dmFields
|= DM_COPIES
;
340 if (m_printerName
!= wxT(""))
342 // TODO: make this Unicode compatible
343 int len
= wxMin(31, m_printerName
.Len());
345 for (i
= 0; i
< len
; i
++)
346 devMode
->dmDeviceName
[i
] = m_printerName
.GetChar(i
);
347 devMode
->dmDeviceName
[i
] = 0;
353 devMode
->dmColor
= DMCOLOR_COLOR
;
355 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
357 devMode
->dmFields
|= DM_COLOR
;
362 if (m_paperId
== wxPAPER_NONE
)
364 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
365 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
366 devMode
->dmFields
|= DM_PAPERWIDTH
;
367 devMode
->dmFields
|= DM_PAPERLENGTH
;
371 if (wxThePrintPaperDatabase
)
373 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
376 devMode
->dmPaperSize
= paper
->GetPlatformId();
377 devMode
->dmFields
|= DM_PAPERSIZE
;
386 switch (m_duplexMode
)
388 case wxDUPLEX_HORIZONTAL
: {
389 duplex
= DMDUP_HORIZONTAL
; break;
391 case wxDUPLEX_VERTICAL
: {
392 duplex
= DMDUP_VERTICAL
; break;
395 case wxDUPLEX_SIMPLEX
: {
396 duplex
= DMDUP_SIMPLEX
; break;
399 devMode
->dmDuplex
= duplex
;
400 devMode
->dmFields
|= DM_DUPLEX
;
405 switch (m_printQuality
)
407 case wxPRINT_QUALITY_MEDIUM
: {
408 quality
= DMRES_MEDIUM
; break;
410 case wxPRINT_QUALITY_LOW
: {
411 quality
= DMRES_LOW
; break;
413 case wxPRINT_QUALITY_DRAFT
: {
414 quality
= DMRES_DRAFT
; break;
416 case wxPRINT_QUALITY_HIGH
: {
417 quality
= DMRES_HIGH
; break;
420 quality
= m_printQuality
; break;
423 devMode
->dmPrintQuality
= quality
;
424 devMode
->dmFields
|= DM_PRINTQUALITY
;
426 GlobalUnlock(hDevMode
);
430 void wxPrintData::ConvertFromNative()
432 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
439 LPDEVMODE devMode
= (LPDEVMODE
)GlobalLock(hDevMode
);
444 if (devMode
->dmFields
& DM_ORIENTATION
)
445 m_printOrientation
= devMode
->dmOrientation
;
451 if (devMode
->dmFields
& DM_COLLATE
)
453 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
454 m_printCollate
= TRUE
;
456 m_printCollate
= FALSE
;
460 //// Number of copies
462 if (devMode
->dmFields
& DM_COPIES
)
464 m_printNoCopies
= devMode
->dmCopies
;
469 if (devMode
->dmDeviceName
[0] != 0)
471 // TODO: make this Unicode compatible
474 while (devMode
->dmDeviceName
[i
] != 0)
476 buf
[i
] = devMode
->dmDeviceName
[i
];
486 if (devMode
->dmFields
& DM_COLOR
)
488 if (devMode
->dmColor
== DMCOLOR_COLOR
)
499 if (devMode
->dmFields
& DM_PAPERSIZE
)
501 if (wxThePrintPaperDatabase
)
503 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
506 m_paperId
= paper
->GetId();
507 m_paperSize
.x
= paper
->GetWidth() / 10 ;
508 m_paperSize
.y
= paper
->GetHeight() / 10 ;
512 // Shouldn't really get here
513 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
515 m_paperId
= wxPAPER_NONE
;
522 // Shouldn't really get here
523 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
525 m_paperId
= wxPAPER_NONE
;
530 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
532 m_paperSize
.x
= devMode
->dmPaperWidth
/ 10;
533 m_paperSize
.y
= devMode
->dmPaperLength
/ 10;
534 m_paperId
= wxPAPER_NONE
;
538 // Shouldn't really get here
539 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
543 m_paperId
= wxPAPER_NONE
;
549 if (devMode
->dmFields
& DM_DUPLEX
)
551 switch (devMode
->dmDuplex
)
553 case DMDUP_HORIZONTAL
: {
554 m_duplexMode
= wxDUPLEX_HORIZONTAL
; break;
556 case DMDUP_VERTICAL
: {
557 m_duplexMode
= wxDUPLEX_VERTICAL
; break;
560 case DMDUP_SIMPLEX
: {
561 m_duplexMode
= wxDUPLEX_SIMPLEX
; break;
566 m_duplexMode
= wxDUPLEX_SIMPLEX
;
570 if (devMode
->dmFields
& DM_PRINTQUALITY
)
572 switch (devMode
->dmPrintQuality
)
575 m_printQuality
= wxPRINT_QUALITY_MEDIUM
; break;
578 m_printQuality
= wxPRINT_QUALITY_LOW
; break;
581 m_printQuality
= wxPRINT_QUALITY_DRAFT
; break;
584 m_printQuality
= wxPRINT_QUALITY_HIGH
; break;
588 // TODO: if the printer fills in the resolution in DPI, how
589 // will the application know if it's high, low, draft etc.??
590 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
591 m_printQuality
= devMode
->dmPrintQuality
; break;
597 m_printQuality
= wxPRINT_QUALITY_HIGH
;
599 GlobalUnlock(hDevMode
);
606 void wxPrintData::ConvertToNative()
608 if ( !m_macPrintInfo
)
610 m_macPrintInfo
= (THPrint
) NewHandleClear( sizeof( TPrint
) ) ;
611 if ( m_macPrintInfo
)
613 ::PrintDefault( m_macPrintInfo
) ;
614 // todo setup the global pagesetup ?
617 if ( m_macPrintInfo
)
619 (**m_macPrintInfo
).prJob
.iCopies
= m_printNoCopies
;
620 (**m_macPrintInfo
).prJob
.iFstPage
= 0 ;
621 (**m_macPrintInfo
).prJob
.iLstPage
= 0 ;
625 void wxPrintData::ConvertFromNative()
627 if ( m_macPrintInfo
)
629 m_printNoCopies
= (**m_macPrintInfo
).prJob
.iCopies
;
634 void wxPrintData::operator=(const wxPrintData
& data
)
636 m_printNoCopies
= data
.m_printNoCopies
;
637 m_printCollate
= data
.m_printCollate
;
638 m_printOrientation
= data
.m_printOrientation
;
639 m_printerName
= data
.m_printerName
;
640 m_colour
= data
.m_colour
;
641 m_duplexMode
= data
.m_duplexMode
;
642 m_printQuality
= data
.m_printQuality
;
643 m_paperId
= data
.m_paperId
;
644 m_paperSize
= data
.m_paperSize
;
646 // PostScript-specific data
647 m_printerCommand
= data
.m_printerCommand
;
648 m_previewCommand
= data
.m_previewCommand
;
649 m_printerOptions
= data
.m_printerOptions
;
650 m_filename
= data
.m_filename
;
651 m_afmPath
= data
.m_afmPath
;
652 m_printerScaleX
= data
.m_printerScaleX
;
653 m_printerScaleY
= data
.m_printerScaleY
;
654 m_printerTranslateX
= data
.m_printerTranslateX
;
655 m_printerTranslateY
= data
.m_printerTranslateY
;
656 m_printMode
= data
.m_printMode
;
660 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
661 void wxPrintData::operator=(const wxPrintSetupData
& setupData
)
663 SetPrinterCommand(setupData
.GetPrinterCommand());
664 SetPreviewCommand(setupData
.GetPrintPreviewCommand());
665 SetPrinterOptions(setupData
.GetPrinterOptions());
668 setupData
.GetPrinterTranslation(& xt
, & yt
);
669 SetPrinterTranslation(xt
, yt
);
672 setupData
.GetPrinterScaling(& xs
, & ys
);
673 SetPrinterScaling(xs
, ys
);
675 SetOrientation(setupData
.GetPrinterOrientation());
676 SetPrintMode((wxPrintMode
) setupData
.GetPrinterMode());
677 SetFontMetricPath(setupData
.GetAFMPath());
678 if (setupData
.GetPaperName() != "")
679 SetPaperId(wxThePrintPaperDatabase
->ConvertNameToId(setupData
.GetPaperName()));
680 SetColour(setupData
.GetColour());
681 SetFilename(setupData
.GetPrinterFile());
683 #endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
686 // ----------------------------------------------------------------------------
688 // ----------------------------------------------------------------------------
690 wxPrintDialogData::wxPrintDialogData()
693 m_printDlgData
= NULL
;
694 #elif defined( __WXMAC__ )
695 m_macPrintInfo
= NULL
;
702 m_printAllPages
= FALSE
;
703 m_printCollate
= FALSE
;
704 m_printToFile
= FALSE
;
705 m_printSelection
= FALSE
;
706 m_printEnableSelection
= FALSE
;
707 m_printEnablePageNumbers
= TRUE
;
708 m_printEnablePrintToFile
= TRUE
;
709 m_printEnableHelp
= FALSE
;
710 m_printSetupDialog
= FALSE
;
713 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
716 m_printDlgData
= NULL
;
717 #elif defined( __WXMAC__ )
718 m_macPrintInfo
= NULL
;
720 (*this) = dialogData
;
723 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
726 m_printDlgData
= NULL
;
727 #elif defined( __WXMAC__ )
728 m_macPrintInfo
= NULL
;
735 m_printAllPages
= FALSE
;
736 m_printCollate
= FALSE
;
737 m_printToFile
= FALSE
;
738 m_printSelection
= FALSE
;
739 m_printEnableSelection
= FALSE
;
740 m_printEnablePageNumbers
= TRUE
;
741 m_printEnablePrintToFile
= TRUE
;
742 m_printEnableHelp
= FALSE
;
743 m_printSetupDialog
= FALSE
;
745 m_printData
= printData
;
748 wxPrintDialogData::~wxPrintDialogData()
751 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
752 if ( pd
&& pd
->hDevMode
)
753 GlobalFree(pd
->hDevMode
);
756 #elif defined(__WXMAC__)
757 if ( m_macPrintInfo
)
758 ::DisposeHandle( (Handle
) m_macPrintInfo
) ;
763 void wxPrintDialogData::ConvertToNative()
765 m_printData
.ConvertToNative();
767 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
772 m_printDlgData
= (void*) pd
;
774 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
776 pd
->lStructSize
= 66 ;
778 pd
->lStructSize
= sizeof(PRINTDLG
);
780 pd
->hwndOwner
= (HWND
)NULL
;
781 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
782 pd
->hDevNames
= NULL
; // Ditto
784 pd
->Flags
= PD_RETURNDEFAULT
;
788 // Pass the devmode data to the PRINTDLG structure, since it'll
789 // be needed when PrintDlg is called.
792 GlobalFree(pd
->hDevMode
);
795 pd
->hDevMode
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeData();
797 m_printData
.SetNativeData((void*) NULL
);
799 wxASSERT_MSG( (pd
->hDevMode
), wxT("hDevMode must be non-NULL in ConvertToNative!"));
801 pd
->hDC
= (HDC
) NULL
;
802 pd
->nFromPage
= (UINT
)m_printFromPage
;
803 pd
->nToPage
= (UINT
)m_printToPage
;
804 pd
->nMinPage
= (UINT
)m_printMinPage
;
805 pd
->nMaxPage
= (UINT
)m_printMaxPage
;
806 pd
->nCopies
= (UINT
)m_printNoCopies
;
808 pd
->Flags
= PD_RETURNDC
;
811 pd
->lStructSize
= 66 ;
813 pd
->lStructSize
= sizeof( PRINTDLG
);
816 pd
->hwndOwner
=(HWND
)NULL
;
817 pd
->hDevNames
=(HANDLE
)NULL
;
818 pd
->hInstance
=(HINSTANCE
)NULL
;
819 pd
->lCustData
= (LPARAM
) NULL
;
820 pd
->lpfnPrintHook
= NULL
;
821 pd
->lpfnSetupHook
= NULL
;
822 pd
->lpPrintTemplateName
= NULL
;
823 pd
->lpSetupTemplateName
= NULL
;
824 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
825 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
827 if ( m_printAllPages
)
828 pd
->Flags
|= PD_ALLPAGES
;
829 if ( m_printAllPages
)
830 pd
->Flags
|= PD_SELECTION
;
831 if ( m_printCollate
)
832 pd
->Flags
|= PD_COLLATE
;
834 pd
->Flags
|= PD_PRINTTOFILE
;
835 if ( !m_printEnablePrintToFile
)
836 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
837 if ( !m_printEnableSelection
)
838 pd
->Flags
|= PD_NOSELECTION
;
839 if ( !m_printEnablePageNumbers
)
840 pd
->Flags
|= PD_NOPAGENUMS
;
841 if ( m_printEnableHelp
)
842 pd
->Flags
|= PD_SHOWHELP
;
843 if ( m_printSetupDialog
)
844 pd
->Flags
|= PD_PRINTSETUP
;
847 void wxPrintDialogData::ConvertFromNative()
849 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
853 // Pass the devmode data back to the wxPrintData structure where it really belongs.
856 if (m_printData
.GetNativeData())
858 // Make sure we don't leak memory
859 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeData());
861 m_printData
.SetNativeData((void*)(long) pd
->hDevMode
);
865 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
866 // into wxWindows form.
867 m_printData
.ConvertFromNative();
869 m_printFromPage
= pd
->nFromPage
;
870 m_printToPage
= pd
->nToPage
;
871 m_printMinPage
= pd
->nMinPage
;
872 m_printMaxPage
= pd
->nMaxPage
;
873 m_printNoCopies
= pd
->nCopies
;
875 m_printAllPages
= ((pd
->Flags
& PD_ALLPAGES
) == PD_ALLPAGES
);
876 m_printSelection
= ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
);
877 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
878 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
879 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
880 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
881 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
882 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
883 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
885 /* port is obsolete in WIN32
889 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
891 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
892 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
893 GlobalUnlock(pd->hDevNames);
895 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
901 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
903 if ( m_printDlgData
== NULL
)
906 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
908 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
909 pd
->hwndOwner
=(HWND
) win
->GetHWND();
915 void wxPrintDialogData::ConvertToNative()
917 if ( !m_macPrintInfo
)
919 m_macPrintInfo
= (THPrint
) NewHandleClear( sizeof( TPrint
) ) ;
920 if ( m_macPrintInfo
)
922 ::PrintDefault( m_macPrintInfo
) ;
923 // todo setup the global pagesetup ?
926 if ( m_macPrintInfo
)
928 (**m_macPrintInfo
).prJob
.iCopies
= m_printNoCopies
;
929 (**m_macPrintInfo
).prJob
.iFstPage
= m_printFromPage
;
930 (**m_macPrintInfo
).prJob
.iLstPage
= m_printToPage
;
934 void wxPrintDialogData::ConvertFromNative()
936 if ( m_macPrintInfo
)
938 m_printNoCopies
= (**m_macPrintInfo
).prJob
.iCopies
;
939 m_printFromPage
= (**m_macPrintInfo
).prJob
.iFstPage
;
940 m_printToPage
= (**m_macPrintInfo
).prJob
.iLstPage
;
946 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
948 m_printFromPage
= data
.m_printFromPage
;
949 m_printToPage
= data
.m_printToPage
;
950 m_printMinPage
= data
.m_printMinPage
;
951 m_printMaxPage
= data
.m_printMaxPage
;
952 m_printNoCopies
= data
.m_printNoCopies
;
953 m_printAllPages
= data
.m_printAllPages
;
954 m_printCollate
= data
.m_printCollate
;
955 m_printToFile
= data
.m_printToFile
;
956 m_printSelection
= data
.m_printSelection
;
957 m_printEnableSelection
= data
.m_printEnableSelection
;
958 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
959 m_printEnableHelp
= data
.m_printEnableHelp
;
960 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
961 m_printSetupDialog
= data
.m_printSetupDialog
;
963 m_printData
= data
.m_printData
;
966 void wxPrintDialogData::operator=(const wxPrintData
& data
)
971 // ----------------------------------------------------------------------------
972 // wxPageSetupDialogData
973 // ----------------------------------------------------------------------------
975 wxPageSetupDialogData::wxPageSetupDialogData()
977 #if defined(__WIN95__)
978 m_pageSetupData
= NULL
;
979 #elif defined( __WXMAC__ )
980 m_macPageSetupInfo
= NULL
;
982 m_paperSize
= wxSize(0, 0);
984 CalculatePaperSizeFromId();
986 m_minMarginTopLeft
= wxPoint(0, 0);
987 m_minMarginBottomRight
= wxPoint(0, 0);
988 m_marginTopLeft
= wxPoint(0, 0);
989 m_marginBottomRight
= wxPoint(0, 0);
992 m_defaultMinMargins
= FALSE
;
993 m_enableMargins
= TRUE
;
994 m_enableOrientation
= TRUE
;
995 m_enablePaper
= TRUE
;
996 m_enablePrinter
= TRUE
;
997 m_enableHelp
= FALSE
;
998 m_getDefaultInfo
= FALSE
;
1001 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
1003 #if defined(__WIN95__)
1004 m_pageSetupData
= NULL
;
1005 #elif defined( __WXMAC__ )
1006 m_macPageSetupInfo
= NULL
;
1008 (*this) = dialogData
;
1011 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
1013 #if defined(__WIN95__)
1014 m_pageSetupData
= NULL
;
1015 #elif defined( __WXMAC__ )
1016 m_macPageSetupInfo
= NULL
;
1018 m_paperSize
= wxSize(0, 0);
1019 m_minMarginTopLeft
= wxPoint(0, 0);
1020 m_minMarginBottomRight
= wxPoint(0, 0);
1021 m_marginTopLeft
= wxPoint(0, 0);
1022 m_marginBottomRight
= wxPoint(0, 0);
1025 m_defaultMinMargins
= FALSE
;
1026 m_enableMargins
= TRUE
;
1027 m_enableOrientation
= TRUE
;
1028 m_enablePaper
= TRUE
;
1029 m_enablePrinter
= TRUE
;
1030 m_enableHelp
= FALSE
;
1031 m_getDefaultInfo
= FALSE
;
1033 m_printData
= printData
;
1035 // The wxPrintData paper size overrides these values, unless the size cannot
1037 CalculatePaperSizeFromId();
1040 wxPageSetupDialogData::~wxPageSetupDialogData()
1042 #if defined(__WIN95__) && defined(__WXMSW__)
1043 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
1044 if ( pd
&& pd
->hDevMode
)
1045 GlobalFree(pd
->hDevMode
);
1048 #elif defined( __WXMAC__ )
1049 if( m_macPageSetupInfo
)
1050 ::DisposeHandle( (Handle
) m_macPageSetupInfo
) ;
1054 void wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
1056 m_paperSize
= data
.m_paperSize
;
1057 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
1058 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
1059 m_marginTopLeft
= data
.m_marginTopLeft
;
1060 m_marginBottomRight
= data
.m_marginBottomRight
;
1061 m_defaultMinMargins
= data
.m_defaultMinMargins
;
1062 m_enableMargins
= data
.m_enableMargins
;
1063 m_enableOrientation
= data
.m_enableOrientation
;
1064 m_enablePaper
= data
.m_enablePaper
;
1065 m_enablePrinter
= data
.m_enablePrinter
;
1066 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
1067 m_enableHelp
= data
.m_enableHelp
;
1069 m_printData
= data
.m_printData
;
1072 void wxPageSetupDialogData::operator=(const wxPrintData
& data
)
1077 #if defined(__WIN95__)
1078 void wxPageSetupDialogData::ConvertToNative()
1080 m_printData
.ConvertToNative();
1082 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1084 if ( m_pageSetupData
== NULL
)
1086 pd
= new PAGESETUPDLG
;
1087 pd
->hDevMode
= NULL
;
1088 m_pageSetupData
= (void *)pd
;
1091 // Pass the devmode data (created in m_printData.ConvertToNative)
1092 // to the PRINTDLG structure, since it'll
1093 // be needed when PrintDlg is called.
1097 GlobalFree(pd
->hDevMode
);
1098 pd
->hDevMode
= NULL
;
1101 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
1103 m_printData
.SetNativeData((void*) NULL
);
1105 wxASSERT_MSG( (pd
->hDevMode
), wxT("hDevMode must be non-NULL in ConvertToNative!"));
1107 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1109 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1111 if ( m_defaultMinMargins
)
1112 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
1113 if ( !m_enableMargins
)
1114 pd
->Flags
|= PSD_DISABLEMARGINS
;
1115 if ( !m_enableOrientation
)
1116 pd
->Flags
|= PSD_DISABLEORIENTATION
;
1117 if ( !m_enablePaper
)
1118 pd
->Flags
|= PSD_DISABLEPAPER
;
1119 if ( !m_enablePrinter
)
1120 pd
->Flags
|= PSD_DISABLEPRINTER
;
1121 if ( m_getDefaultInfo
)
1122 pd
->Flags
|= PSD_RETURNDEFAULT
;
1124 pd
->Flags
|= PSD_SHOWHELP
;
1126 // We want the units to be in hundredths of a millimetre
1127 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1129 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
1130 pd
->hwndOwner
=(HWND
)NULL
;
1131 pd
->hDevNames
=(HWND
)NULL
;
1132 pd
->hInstance
=(HINSTANCE
)NULL
;
1134 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
1135 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
1137 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
1138 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
1139 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
1140 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
1142 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
1143 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
1144 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
1145 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
1148 pd
->lpfnPageSetupHook
= NULL
;
1149 pd
->lpfnPagePaintHook
= NULL
;
1150 pd
->hPageSetupTemplate
= NULL
;
1151 pd
->lpPageSetupTemplateName
= NULL
;
1156 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1157 memset(devMode, 0, sizeof(DEVMODE));
1158 devMode->dmSize = sizeof(DEVMODE);
1159 devMode->dmOrientation = m_orientation;
1160 devMode->dmFields = DM_ORIENTATION;
1161 GlobalUnlock(pd->hDevMode);
1166 void wxPageSetupDialogData::ConvertFromNative()
1168 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1172 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1175 if (m_printData
.GetNativeData())
1177 // Make sure we don't leak memory
1178 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1180 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1181 pd
->hDevMode
= NULL
;
1184 m_printData
.ConvertFromNative();
1186 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1188 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
1189 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
1190 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
1191 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
1192 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
1193 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
1194 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
1196 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1197 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
1199 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
1200 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
1201 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
1202 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
1204 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100 ;
1205 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100 ;
1206 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100 ;
1207 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100 ;
1210 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1212 if ( m_pageSetupData
== NULL
)
1215 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1217 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1218 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1224 void wxPageSetupDialogData::ConvertToNative()
1226 if ( !m_macPageSetupInfo
)
1228 m_macPageSetupInfo
= (THPrint
) NewHandleClear( sizeof( TPrint
) ) ;
1229 if ( m_macPageSetupInfo
)
1231 ::PrintDefault( m_macPageSetupInfo
) ;
1234 if ( m_macPageSetupInfo
)
1236 // on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0
1237 (**m_macPageSetupInfo
).rPaper
.left
= int( ((double) m_minMarginTopLeft
.x
)*mm2pt
) ;
1238 (**m_macPageSetupInfo
).rPaper
.top
= int( ((double) m_minMarginTopLeft
.y
)*mm2pt
) ;
1240 (**m_macPageSetupInfo
).rPaper
.right
= int( ((double) m_paperSize
.x
- m_minMarginTopLeft
.x
)*mm2pt
) ;
1241 (**m_macPageSetupInfo
).rPaper
.bottom
= int( ((double) m_paperSize
.y
- m_minMarginTopLeft
.y
)*mm2pt
) ;
1243 (**m_macPageSetupInfo
).prInfo
.rPage
.left
= 0 ;
1244 (**m_macPageSetupInfo
).prInfo
.rPage
.top
= 0 ;
1245 (**m_macPageSetupInfo
).prInfo
.rPage
.right
= int( ((double) m_paperSize
.x
- m_minMarginTopLeft
.x
- m_minMarginBottomRight
.x
)*mm2pt
) ;
1246 (**m_macPageSetupInfo
).prInfo
.rPage
.bottom
= int( ((double) m_paperSize
.y
- m_minMarginTopLeft
.y
- m_minMarginBottomRight
.y
)*mm2pt
) ;
1248 //TODO add custom fields in dialog for margins
1253 void wxPageSetupDialogData::ConvertFromNative()
1255 if ( m_macPageSetupInfo
)
1257 m_paperSize
.x
= ((double) (**m_macPageSetupInfo
).rPaper
.right
- (**m_macPageSetupInfo
).rPaper
.left
) * pt2mm
;
1258 m_paperSize
.y
= ((double) (**m_macPageSetupInfo
).rPaper
.bottom
- (**m_macPageSetupInfo
).rPaper
.top
) * pt2mm
;
1260 m_minMarginTopLeft
.x
= ((double) -(**m_macPageSetupInfo
).rPaper
.left
) * pt2mm
;
1261 m_minMarginTopLeft
.y
= ((double) -(**m_macPageSetupInfo
).rPaper
.top
) * pt2mm
;
1263 m_minMarginBottomRight
.x
= ((double) (**m_macPageSetupInfo
).rPaper
.right
- (**m_macPageSetupInfo
).prInfo
.rPage
.right
) * pt2mm
;
1264 m_minMarginBottomRight
.y
= ((double)(**m_macPageSetupInfo
).rPaper
.bottom
- (**m_macPageSetupInfo
).prInfo
.rPage
.bottom
) * pt2mm
;
1266 // adjust minimal values
1267 //TODO add custom fields in dialog for margins
1269 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
1270 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
1272 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
1273 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
1275 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
1276 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
1278 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
1279 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
1286 // If a corresponding paper type is found in the paper database, will set the m_printData
1287 // paper size id member as well.
1288 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
1292 CalculateIdFromPaperSize();
1295 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1296 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1298 m_printData
.SetPaperId(id
);
1300 CalculatePaperSizeFromId();
1303 // Use paper size defined in this object to set the wxPrintData
1305 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1307 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1308 wxT("wxThePrintPaperDatabase should not be NULL. "
1309 "Do not create global print dialog data objects.") );
1311 wxSize sz
= GetPaperSize();
1313 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1314 if (id
!= wxPAPER_NONE
)
1316 m_printData
.SetPaperId(id
);
1320 // Use paper id in wxPrintData to set this object's paper size
1321 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1323 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1324 wxT("wxThePrintPaperDatabase should not be NULL. "
1325 "Do not create global print dialog data objects.") );
1327 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
1331 // sz is in 10ths of a mm, so multiply by 10.
1332 m_paperSize
.x
= sz
.x
* 10;
1333 m_paperSize
.y
= sz
.y
* 10;
1337 #endif // wxUSE_PRINTING_ARCHITECTURE