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
81 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
82 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
85 #define mm2pt 2.83464566929
86 #define pt2mm 0.352777777778
89 // ============================================================================
91 // ============================================================================
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 wxColourData::wxColourData()
100 for (i
= 0; i
< 16; i
++)
101 custColours
[i
].Set(255, 255, 255);
104 dataColour
.Set(0,0,0);
107 wxColourData::wxColourData(const wxColourData
& data
)
112 wxColourData::~wxColourData()
116 void wxColourData::SetCustomColour(int i
, wxColour
& colour
)
121 custColours
[i
] = colour
;
124 wxColour
wxColourData::GetCustomColour(int i
)
127 return wxColour(0,0,0);
129 return custColours
[i
];
132 void wxColourData::operator=(const wxColourData
& data
)
135 for (i
= 0; i
< 16; i
++)
136 custColours
[i
] = data
.custColours
[i
];
138 dataColour
= (wxColour
&)data
.dataColour
;
139 chooseFull
= data
.chooseFull
;
142 // ----------------------------------------------------------------------------
144 // ----------------------------------------------------------------------------
146 wxFontData::wxFontData()
148 // Intialize colour to black.
149 fontColour
.Set(0, 0, 0);
153 enableEffects
= TRUE
;
157 m_encoding
= wxFONTENCODING_SYSTEM
;
160 wxFontData::~wxFontData()
164 #if wxUSE_PRINTING_ARCHITECTURE
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
169 wxPrintData::wxPrintData()
173 #elif defined( __WXMAC__ )
174 m_macPrintInfo
= NULL
;
176 m_printOrientation
= wxPORTRAIT
;
178 m_printCollate
= FALSE
;
183 m_duplexMode
= wxDUPLEX_SIMPLEX
;
184 m_printQuality
= wxPRINT_QUALITY_HIGH
;
185 m_paperId
= wxPAPER_A4
;
186 m_paperSize
= wxSize(210, 297);
188 // PostScript-specific data
189 m_printerCommand
= "";
190 m_previewCommand
= "";
191 m_printerOptions
= "";
194 m_printerScaleX
= 1.0;
195 m_printerScaleY
= 1.0;
196 m_printerTranslateX
= 0;
197 m_printerTranslateY
= 0;
198 m_printMode
= wxPRINT_MODE_FILE
;
201 wxPrintData::wxPrintData(const wxPrintData
& printData
)
205 #elif defined( __WXMAC__ )
206 m_macPrintInfo
= NULL
;
211 wxPrintData::~wxPrintData()
214 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
216 GlobalFree(hDevMode
);
217 #elif defined(__WXMAC__)
218 if ( m_macPrintInfo
)
219 ::DisposeHandle( (Handle
) m_macPrintInfo
) ;
223 #if defined(__WXMSW__) // && defined(__WIN32__)
226 static wxString
wxGetPrintDlgError()
228 DWORD err
= CommDlgExtendedError();
229 wxString msg
= wxT("Unknown");
232 case CDERR_FINDRESFAILURE
: msg
= wxT("CDERR_FINDRESFAILURE"); break;
233 case CDERR_INITIALIZATION
: msg
= wxT("CDERR_INITIALIZATION"); break;
234 case CDERR_LOADRESFAILURE
: msg
= wxT("CDERR_LOADRESFAILURE"); break;
235 case CDERR_LOADSTRFAILURE
: msg
= wxT("CDERR_LOADSTRFAILURE"); break;
236 case CDERR_LOCKRESFAILURE
: msg
= wxT("CDERR_LOCKRESFAILURE"); break;
237 case CDERR_MEMALLOCFAILURE
: msg
= wxT("CDERR_MEMALLOCFAILURE"); break;
238 case CDERR_MEMLOCKFAILURE
: msg
= wxT("CDERR_MEMLOCKFAILURE"); break;
239 case CDERR_NOHINSTANCE
: msg
= wxT("CDERR_NOHINSTANCE"); break;
240 case CDERR_NOHOOK
: msg
= wxT("CDERR_NOHOOK"); break;
241 case CDERR_NOTEMPLATE
: msg
= wxT("CDERR_NOTEMPLATE"); break;
242 case CDERR_STRUCTSIZE
: msg
= wxT("CDERR_STRUCTSIZE"); break;
243 case PDERR_RETDEFFAILURE
: msg
= wxT("PDERR_RETDEFFAILURE"); break;
244 case PDERR_PRINTERNOTFOUND
: msg
= wxT("PDERR_PRINTERNOTFOUND"); break;
245 case PDERR_PARSEFAILURE
: msg
= wxT("PDERR_PARSEFAILURE"); break;
246 case PDERR_NODEVICES
: msg
= wxT("PDERR_NODEVICES"); break;
247 case PDERR_NODEFAULTPRN
: msg
= wxT("PDERR_NODEFAULTPRN"); break;
248 case PDERR_LOADDRVFAILURE
: msg
= wxT("PDERR_LOADDRVFAILURE"); break;
249 case PDERR_INITFAILURE
: msg
= wxT("PDERR_INITFAILURE"); break;
250 case PDERR_GETDEVMODEFAIL
: msg
= wxT("PDERR_GETDEVMODEFAIL"); break;
251 case PDERR_DNDMMISMATCH
: msg
= wxT("PDERR_DNDMMISMATCH"); break;
252 case PDERR_DEFAULTDIFFERENT
: msg
= wxT("PDERR_DEFAULTDIFFERENT"); break;
253 case PDERR_CREATEICFAILURE
: msg
= wxT("PDERR_CREATEICFAILURE"); break;
260 void wxPrintData::ConvertToNative()
262 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
265 // Use PRINTDLG as a way of creating a DEVMODE object
266 PRINTDLG
*pd
= new PRINTDLG
;
268 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
271 pd
->lStructSize
= 66 ;
273 memset(pd
, 0, sizeof(PRINTDLG
));
274 pd
->lStructSize
= sizeof(PRINTDLG
);
277 pd
->hwndOwner
= (HWND
)NULL
;
278 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
279 pd
->hDevNames
= NULL
; // Ditto
280 pd
->hInstance
= (HINSTANCE
) wxGetInstance();
282 pd
->Flags
= PD_RETURNDEFAULT
;
285 // Fill out the DEVMODE structure
286 // so we can use it as input in the 'real' PrintDlg
290 GlobalFree(pd
->hDevMode
);
292 GlobalFree(pd
->hDevNames
);
294 pd
->hDevNames
= NULL
;
296 #if defined(__WXDEBUG__) && defined(__WIN32__)
297 wxString
str(wxT("Printing error: "));
298 str
+= wxGetPrintDlgError();
305 GlobalFree(pd
->hDevNames
);
306 pd
->hDevNames
= NULL
;
308 hDevMode
= pd
->hDevMode
;
309 m_devMode
= (void*)(long) hDevMode
;
318 LPDEVMODE devMode
= (LPDEVMODE
) GlobalLock(hDevMode
);
323 devMode
->dmOrientation
= m_printOrientation
;
325 devMode
->dmFields
= DM_ORIENTATION
;
330 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
331 devMode
->dmFields
|= DM_COLLATE
;
334 //// Number of copies
336 devMode
->dmCopies
= m_printNoCopies
;
337 devMode
->dmFields
|= DM_COPIES
;
341 if (m_printerName
!= wxT(""))
343 // TODO: make this Unicode compatible
344 int len
= wxMin(31, m_printerName
.Len());
346 for (i
= 0; i
< len
; i
++)
347 devMode
->dmDeviceName
[i
] = m_printerName
.GetChar(i
);
348 devMode
->dmDeviceName
[i
] = 0;
354 devMode
->dmColor
= DMCOLOR_COLOR
;
356 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
358 devMode
->dmFields
|= DM_COLOR
;
363 if (m_paperId
== wxPAPER_NONE
)
365 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
366 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
367 devMode
->dmFields
|= DM_PAPERWIDTH
;
368 devMode
->dmFields
|= DM_PAPERLENGTH
;
372 if (wxThePrintPaperDatabase
)
374 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
377 devMode
->dmPaperSize
= paper
->GetPlatformId();
378 devMode
->dmFields
|= DM_PAPERSIZE
;
387 switch (m_duplexMode
)
389 case wxDUPLEX_HORIZONTAL
: {
390 duplex
= DMDUP_HORIZONTAL
; break;
392 case wxDUPLEX_VERTICAL
: {
393 duplex
= DMDUP_VERTICAL
; break;
396 case wxDUPLEX_SIMPLEX
: {
397 duplex
= DMDUP_SIMPLEX
; break;
400 devMode
->dmDuplex
= duplex
;
401 devMode
->dmFields
|= DM_DUPLEX
;
406 switch (m_printQuality
)
408 case wxPRINT_QUALITY_MEDIUM
: {
409 quality
= DMRES_MEDIUM
; break;
411 case wxPRINT_QUALITY_LOW
: {
412 quality
= DMRES_LOW
; break;
414 case wxPRINT_QUALITY_DRAFT
: {
415 quality
= DMRES_DRAFT
; break;
417 case wxPRINT_QUALITY_HIGH
: {
418 quality
= DMRES_HIGH
; break;
421 quality
= m_printQuality
; break;
424 devMode
->dmPrintQuality
= quality
;
425 devMode
->dmFields
|= DM_PRINTQUALITY
;
427 GlobalUnlock(hDevMode
);
431 void wxPrintData::ConvertFromNative()
433 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
440 LPDEVMODE devMode
= (LPDEVMODE
)GlobalLock(hDevMode
);
445 if (devMode
->dmFields
& DM_ORIENTATION
)
446 m_printOrientation
= devMode
->dmOrientation
;
452 if (devMode
->dmFields
& DM_COLLATE
)
454 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
455 m_printCollate
= TRUE
;
457 m_printCollate
= FALSE
;
461 //// Number of copies
463 if (devMode
->dmFields
& DM_COPIES
)
465 m_printNoCopies
= devMode
->dmCopies
;
470 if (devMode
->dmDeviceName
[0] != 0)
472 // TODO: make this Unicode compatible
475 while (devMode
->dmDeviceName
[i
] != 0)
477 buf
[i
] = devMode
->dmDeviceName
[i
];
487 if (devMode
->dmFields
& DM_COLOR
)
489 if (devMode
->dmColor
== DMCOLOR_COLOR
)
500 if (devMode
->dmFields
& DM_PAPERSIZE
)
502 if (wxThePrintPaperDatabase
)
504 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
507 m_paperId
= paper
->GetId();
508 m_paperSize
.x
= paper
->GetWidth() / 10 ;
509 m_paperSize
.y
= paper
->GetHeight() / 10 ;
513 // Shouldn't really get here
514 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
516 m_paperId
= wxPAPER_NONE
;
523 // Shouldn't really get here
524 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
526 m_paperId
= wxPAPER_NONE
;
531 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
533 m_paperSize
.x
= devMode
->dmPaperWidth
/ 10;
534 m_paperSize
.y
= devMode
->dmPaperLength
/ 10;
535 m_paperId
= wxPAPER_NONE
;
539 // Shouldn't really get here
540 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
544 m_paperId
= wxPAPER_NONE
;
550 if (devMode
->dmFields
& DM_DUPLEX
)
552 switch (devMode
->dmDuplex
)
554 case DMDUP_HORIZONTAL
: {
555 m_duplexMode
= wxDUPLEX_HORIZONTAL
; break;
557 case DMDUP_VERTICAL
: {
558 m_duplexMode
= wxDUPLEX_VERTICAL
; break;
561 case DMDUP_SIMPLEX
: {
562 m_duplexMode
= wxDUPLEX_SIMPLEX
; break;
567 m_duplexMode
= wxDUPLEX_SIMPLEX
;
571 if (devMode
->dmFields
& DM_PRINTQUALITY
)
573 switch (devMode
->dmPrintQuality
)
576 m_printQuality
= wxPRINT_QUALITY_MEDIUM
; break;
579 m_printQuality
= wxPRINT_QUALITY_LOW
; break;
582 m_printQuality
= wxPRINT_QUALITY_DRAFT
; break;
585 m_printQuality
= wxPRINT_QUALITY_HIGH
; break;
589 // TODO: if the printer fills in the resolution in DPI, how
590 // will the application know if it's high, low, draft etc.??
591 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
592 m_printQuality
= devMode
->dmPrintQuality
; break;
598 m_printQuality
= wxPRINT_QUALITY_HIGH
;
600 GlobalUnlock(hDevMode
);
607 void wxPrintData::ConvertToNative()
609 if ( !m_macPrintInfo
)
611 m_macPrintInfo
= (THPrint
) NewHandleClear( sizeof( TPrint
) ) ;
612 if ( m_macPrintInfo
)
614 ::PrintDefault( m_macPrintInfo
) ;
615 // todo setup the global pagesetup ?
618 if ( m_macPrintInfo
)
620 (**m_macPrintInfo
).prJob
.iCopies
= m_printNoCopies
;
621 (**m_macPrintInfo
).prJob
.iFstPage
= 0 ;
622 (**m_macPrintInfo
).prJob
.iLstPage
= 0 ;
626 void wxPrintData::ConvertFromNative()
628 if ( m_macPrintInfo
)
630 m_printNoCopies
= (**m_macPrintInfo
).prJob
.iCopies
;
635 void wxPrintData::operator=(const wxPrintData
& data
)
637 m_printNoCopies
= data
.m_printNoCopies
;
638 m_printCollate
= data
.m_printCollate
;
639 m_printOrientation
= data
.m_printOrientation
;
640 m_printerName
= data
.m_printerName
;
641 m_colour
= data
.m_colour
;
642 m_duplexMode
= data
.m_duplexMode
;
643 m_printQuality
= data
.m_printQuality
;
644 m_paperId
= data
.m_paperId
;
645 m_paperSize
= data
.m_paperSize
;
647 // PostScript-specific data
648 m_printerCommand
= data
.m_printerCommand
;
649 m_previewCommand
= data
.m_previewCommand
;
650 m_printerOptions
= data
.m_printerOptions
;
651 m_filename
= data
.m_filename
;
652 m_afmPath
= data
.m_afmPath
;
653 m_printerScaleX
= data
.m_printerScaleX
;
654 m_printerScaleY
= data
.m_printerScaleY
;
655 m_printerTranslateX
= data
.m_printerTranslateX
;
656 m_printerTranslateY
= data
.m_printerTranslateY
;
657 m_printMode
= data
.m_printMode
;
661 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
662 void wxPrintData::operator=(const wxPrintSetupData
& setupData
)
664 SetPrinterCommand(setupData
.GetPrinterCommand());
665 SetPreviewCommand(setupData
.GetPrintPreviewCommand());
666 SetPrinterOptions(setupData
.GetPrinterOptions());
669 setupData
.GetPrinterTranslation(& xt
, & yt
);
670 SetPrinterTranslation(xt
, yt
);
673 setupData
.GetPrinterScaling(& xs
, & ys
);
674 SetPrinterScaling(xs
, ys
);
676 SetOrientation(setupData
.GetPrinterOrientation());
677 SetPrintMode((wxPrintMode
) setupData
.GetPrinterMode());
678 SetFontMetricPath(setupData
.GetAFMPath());
679 if (setupData
.GetPaperName() != "")
680 SetPaperId(wxThePrintPaperDatabase
->ConvertNameToId(setupData
.GetPaperName()));
681 SetColour(setupData
.GetColour());
682 SetFilename(setupData
.GetPrinterFile());
684 #endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
687 // ----------------------------------------------------------------------------
689 // ----------------------------------------------------------------------------
691 wxPrintDialogData::wxPrintDialogData()
694 m_printDlgData
= NULL
;
695 #elif defined( __WXMAC__ )
696 m_macPrintInfo
= NULL
;
703 m_printAllPages
= FALSE
;
704 m_printCollate
= FALSE
;
705 m_printToFile
= FALSE
;
706 m_printSelection
= FALSE
;
707 m_printEnableSelection
= FALSE
;
708 m_printEnablePageNumbers
= TRUE
;
709 m_printEnablePrintToFile
= TRUE
;
710 m_printEnableHelp
= FALSE
;
711 m_printSetupDialog
= FALSE
;
714 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
717 m_printDlgData
= NULL
;
718 #elif defined( __WXMAC__ )
719 m_macPrintInfo
= NULL
;
721 (*this) = dialogData
;
724 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
727 m_printDlgData
= NULL
;
728 #elif defined( __WXMAC__ )
729 m_macPrintInfo
= NULL
;
736 m_printAllPages
= FALSE
;
737 m_printCollate
= FALSE
;
738 m_printToFile
= FALSE
;
739 m_printSelection
= FALSE
;
740 m_printEnableSelection
= FALSE
;
741 m_printEnablePageNumbers
= TRUE
;
742 m_printEnablePrintToFile
= TRUE
;
743 m_printEnableHelp
= FALSE
;
744 m_printSetupDialog
= FALSE
;
746 m_printData
= printData
;
749 wxPrintDialogData::~wxPrintDialogData()
752 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
753 if ( pd
&& pd
->hDevMode
)
754 GlobalFree(pd
->hDevMode
);
757 #elif defined(__WXMAC__)
758 if ( m_macPrintInfo
)
759 ::DisposeHandle( (Handle
) m_macPrintInfo
) ;
764 void wxPrintDialogData::ConvertToNative()
766 m_printData
.ConvertToNative();
768 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
773 m_printDlgData
= (void*) pd
;
775 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
777 pd
->lStructSize
= 66 ;
779 pd
->lStructSize
= sizeof(PRINTDLG
);
781 pd
->hwndOwner
= (HWND
)NULL
;
782 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
783 pd
->hDevNames
= NULL
; // Ditto
785 pd
->Flags
= PD_RETURNDEFAULT
;
789 // Pass the devmode data to the PRINTDLG structure, since it'll
790 // be needed when PrintDlg is called.
793 GlobalFree(pd
->hDevMode
);
796 pd
->hDevMode
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeData();
798 m_printData
.SetNativeData((void*) NULL
);
800 wxASSERT_MSG( (pd
->hDevMode
), wxT("hDevMode must be non-NULL in ConvertToNative!"));
802 pd
->hDC
= (HDC
) NULL
;
803 pd
->nFromPage
= (UINT
)m_printFromPage
;
804 pd
->nToPage
= (UINT
)m_printToPage
;
805 pd
->nMinPage
= (UINT
)m_printMinPage
;
806 pd
->nMaxPage
= (UINT
)m_printMaxPage
;
807 pd
->nCopies
= (UINT
)m_printNoCopies
;
809 pd
->Flags
= PD_RETURNDC
;
812 pd
->lStructSize
= 66 ;
814 pd
->lStructSize
= sizeof( PRINTDLG
);
817 pd
->hwndOwner
=(HWND
)NULL
;
818 pd
->hDevNames
=(HANDLE
)NULL
;
819 pd
->hInstance
=(HINSTANCE
)NULL
;
820 pd
->lCustData
= (LPARAM
) NULL
;
821 pd
->lpfnPrintHook
= NULL
;
822 pd
->lpfnSetupHook
= NULL
;
823 pd
->lpPrintTemplateName
= NULL
;
824 pd
->lpSetupTemplateName
= NULL
;
825 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
826 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
828 if ( m_printAllPages
)
829 pd
->Flags
|= PD_ALLPAGES
;
830 if ( m_printAllPages
)
831 pd
->Flags
|= PD_SELECTION
;
832 if ( m_printCollate
)
833 pd
->Flags
|= PD_COLLATE
;
835 pd
->Flags
|= PD_PRINTTOFILE
;
836 if ( !m_printEnablePrintToFile
)
837 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
838 if ( !m_printEnableSelection
)
839 pd
->Flags
|= PD_NOSELECTION
;
840 if ( !m_printEnablePageNumbers
)
841 pd
->Flags
|= PD_NOPAGENUMS
;
842 if ( m_printEnableHelp
)
843 pd
->Flags
|= PD_SHOWHELP
;
844 if ( m_printSetupDialog
)
845 pd
->Flags
|= PD_PRINTSETUP
;
848 void wxPrintDialogData::ConvertFromNative()
850 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
854 // Pass the devmode data back to the wxPrintData structure where it really belongs.
857 if (m_printData
.GetNativeData())
859 // Make sure we don't leak memory
860 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeData());
862 m_printData
.SetNativeData((void*)(long) pd
->hDevMode
);
866 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
867 // into wxWindows form.
868 m_printData
.ConvertFromNative();
870 m_printFromPage
= pd
->nFromPage
;
871 m_printToPage
= pd
->nToPage
;
872 m_printMinPage
= pd
->nMinPage
;
873 m_printMaxPage
= pd
->nMaxPage
;
874 m_printNoCopies
= pd
->nCopies
;
876 m_printAllPages
= ((pd
->Flags
& PD_ALLPAGES
) == PD_ALLPAGES
);
877 m_printSelection
= ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
);
878 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
879 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
880 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
881 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
882 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
883 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
884 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
886 /* port is obsolete in WIN32
890 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
892 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
893 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
894 GlobalUnlock(pd->hDevNames);
896 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
902 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
904 if ( m_printDlgData
== NULL
)
907 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
909 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
910 pd
->hwndOwner
=(HWND
) win
->GetHWND();
916 void wxPrintDialogData::ConvertToNative()
918 if ( !m_macPrintInfo
)
920 m_macPrintInfo
= (THPrint
) NewHandleClear( sizeof( TPrint
) ) ;
921 if ( m_macPrintInfo
)
923 ::PrintDefault( m_macPrintInfo
) ;
924 // todo setup the global pagesetup ?
927 if ( m_macPrintInfo
)
929 (**m_macPrintInfo
).prJob
.iCopies
= m_printNoCopies
;
930 (**m_macPrintInfo
).prJob
.iFstPage
= m_printFromPage
;
931 (**m_macPrintInfo
).prJob
.iLstPage
= m_printToPage
;
935 void wxPrintDialogData::ConvertFromNative()
937 if ( m_macPrintInfo
)
939 m_printNoCopies
= (**m_macPrintInfo
).prJob
.iCopies
;
940 m_printFromPage
= (**m_macPrintInfo
).prJob
.iFstPage
;
941 m_printToPage
= (**m_macPrintInfo
).prJob
.iLstPage
;
947 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
949 m_printFromPage
= data
.m_printFromPage
;
950 m_printToPage
= data
.m_printToPage
;
951 m_printMinPage
= data
.m_printMinPage
;
952 m_printMaxPage
= data
.m_printMaxPage
;
953 m_printNoCopies
= data
.m_printNoCopies
;
954 m_printAllPages
= data
.m_printAllPages
;
955 m_printCollate
= data
.m_printCollate
;
956 m_printToFile
= data
.m_printToFile
;
957 m_printSelection
= data
.m_printSelection
;
958 m_printEnableSelection
= data
.m_printEnableSelection
;
959 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
960 m_printEnableHelp
= data
.m_printEnableHelp
;
961 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
962 m_printSetupDialog
= data
.m_printSetupDialog
;
964 m_printData
= data
.m_printData
;
967 void wxPrintDialogData::operator=(const wxPrintData
& data
)
972 // ----------------------------------------------------------------------------
973 // wxPageSetupDialogData
974 // ----------------------------------------------------------------------------
976 wxPageSetupDialogData::wxPageSetupDialogData()
978 #if defined(__WIN95__)
979 m_pageSetupData
= NULL
;
980 #elif defined( __WXMAC__ )
981 m_macPageSetupInfo
= NULL
;
983 m_paperSize
= wxSize(0, 0);
985 CalculatePaperSizeFromId();
987 m_minMarginTopLeft
= wxPoint(0, 0);
988 m_minMarginBottomRight
= wxPoint(0, 0);
989 m_marginTopLeft
= wxPoint(0, 0);
990 m_marginBottomRight
= wxPoint(0, 0);
993 m_defaultMinMargins
= FALSE
;
994 m_enableMargins
= TRUE
;
995 m_enableOrientation
= TRUE
;
996 m_enablePaper
= TRUE
;
997 m_enablePrinter
= TRUE
;
998 m_enableHelp
= FALSE
;
999 m_getDefaultInfo
= FALSE
;
1002 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
1004 #if defined(__WIN95__)
1005 m_pageSetupData
= NULL
;
1006 #elif defined( __WXMAC__ )
1007 m_macPageSetupInfo
= NULL
;
1009 (*this) = dialogData
;
1012 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
1014 #if defined(__WIN95__)
1015 m_pageSetupData
= NULL
;
1016 #elif defined( __WXMAC__ )
1017 m_macPageSetupInfo
= NULL
;
1019 m_paperSize
= wxSize(0, 0);
1020 m_minMarginTopLeft
= wxPoint(0, 0);
1021 m_minMarginBottomRight
= wxPoint(0, 0);
1022 m_marginTopLeft
= wxPoint(0, 0);
1023 m_marginBottomRight
= wxPoint(0, 0);
1026 m_defaultMinMargins
= FALSE
;
1027 m_enableMargins
= TRUE
;
1028 m_enableOrientation
= TRUE
;
1029 m_enablePaper
= TRUE
;
1030 m_enablePrinter
= TRUE
;
1031 m_enableHelp
= FALSE
;
1032 m_getDefaultInfo
= FALSE
;
1034 m_printData
= printData
;
1036 // The wxPrintData paper size overrides these values, unless the size cannot
1038 CalculatePaperSizeFromId();
1041 wxPageSetupDialogData::~wxPageSetupDialogData()
1043 #if defined(__WIN95__) && defined(__WXMSW__)
1044 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
1045 if ( pd
&& pd
->hDevMode
)
1046 GlobalFree(pd
->hDevMode
);
1049 #elif defined( __WXMAC__ )
1050 if( m_macPageSetupInfo
)
1051 ::DisposeHandle( (Handle
) m_macPageSetupInfo
) ;
1055 void wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
1057 m_paperSize
= data
.m_paperSize
;
1058 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
1059 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
1060 m_marginTopLeft
= data
.m_marginTopLeft
;
1061 m_marginBottomRight
= data
.m_marginBottomRight
;
1062 m_defaultMinMargins
= data
.m_defaultMinMargins
;
1063 m_enableMargins
= data
.m_enableMargins
;
1064 m_enableOrientation
= data
.m_enableOrientation
;
1065 m_enablePaper
= data
.m_enablePaper
;
1066 m_enablePrinter
= data
.m_enablePrinter
;
1067 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
1068 m_enableHelp
= data
.m_enableHelp
;
1070 m_printData
= data
.m_printData
;
1073 void wxPageSetupDialogData::operator=(const wxPrintData
& data
)
1078 #if defined(__WIN95__)
1079 void wxPageSetupDialogData::ConvertToNative()
1081 m_printData
.ConvertToNative();
1083 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1085 if ( m_pageSetupData
== NULL
)
1087 pd
= new PAGESETUPDLG
;
1088 pd
->hDevMode
= NULL
;
1089 m_pageSetupData
= (void *)pd
;
1092 // Pass the devmode data (created in m_printData.ConvertToNative)
1093 // to the PRINTDLG structure, since it'll
1094 // be needed when PrintDlg is called.
1098 GlobalFree(pd
->hDevMode
);
1099 pd
->hDevMode
= NULL
;
1102 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
1104 m_printData
.SetNativeData((void*) NULL
);
1106 wxASSERT_MSG( (pd
->hDevMode
), wxT("hDevMode must be non-NULL in ConvertToNative!"));
1108 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1110 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1112 if ( m_defaultMinMargins
)
1113 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
1114 if ( !m_enableMargins
)
1115 pd
->Flags
|= PSD_DISABLEMARGINS
;
1116 if ( !m_enableOrientation
)
1117 pd
->Flags
|= PSD_DISABLEORIENTATION
;
1118 if ( !m_enablePaper
)
1119 pd
->Flags
|= PSD_DISABLEPAPER
;
1120 if ( !m_enablePrinter
)
1121 pd
->Flags
|= PSD_DISABLEPRINTER
;
1122 if ( m_getDefaultInfo
)
1123 pd
->Flags
|= PSD_RETURNDEFAULT
;
1125 pd
->Flags
|= PSD_SHOWHELP
;
1127 // We want the units to be in hundredths of a millimetre
1128 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1130 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
1131 pd
->hwndOwner
=(HWND
)NULL
;
1132 pd
->hDevNames
=(HWND
)NULL
;
1133 pd
->hInstance
=(HINSTANCE
)NULL
;
1135 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
1136 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
1138 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
1139 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
1140 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
1141 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
1143 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
1144 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
1145 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
1146 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
1149 pd
->lpfnPageSetupHook
= NULL
;
1150 pd
->lpfnPagePaintHook
= NULL
;
1151 pd
->hPageSetupTemplate
= NULL
;
1152 pd
->lpPageSetupTemplateName
= NULL
;
1157 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1158 memset(devMode, 0, sizeof(DEVMODE));
1159 devMode->dmSize = sizeof(DEVMODE);
1160 devMode->dmOrientation = m_orientation;
1161 devMode->dmFields = DM_ORIENTATION;
1162 GlobalUnlock(pd->hDevMode);
1167 void wxPageSetupDialogData::ConvertFromNative()
1169 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1173 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1176 if (m_printData
.GetNativeData())
1178 // Make sure we don't leak memory
1179 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1181 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1182 pd
->hDevMode
= NULL
;
1185 m_printData
.ConvertFromNative();
1187 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1189 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
1190 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
1191 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
1192 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
1193 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
1194 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
1195 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
1197 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1198 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
1200 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
1201 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
1202 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
1203 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
1205 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100 ;
1206 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100 ;
1207 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100 ;
1208 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100 ;
1211 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1213 if ( m_pageSetupData
== NULL
)
1216 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1218 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1219 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1225 void wxPageSetupDialogData::ConvertToNative()
1227 if ( !m_macPageSetupInfo
)
1229 m_macPageSetupInfo
= (THPrint
) NewHandleClear( sizeof( TPrint
) ) ;
1230 if ( m_macPageSetupInfo
)
1232 ::PrintDefault( m_macPageSetupInfo
) ;
1235 if ( m_macPageSetupInfo
)
1237 // on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0
1238 (**m_macPageSetupInfo
).rPaper
.left
= int( ((double) m_minMarginTopLeft
.x
)*mm2pt
) ;
1239 (**m_macPageSetupInfo
).rPaper
.top
= int( ((double) m_minMarginTopLeft
.y
)*mm2pt
) ;
1241 (**m_macPageSetupInfo
).rPaper
.right
= int( ((double) m_paperSize
.x
- m_minMarginTopLeft
.x
)*mm2pt
) ;
1242 (**m_macPageSetupInfo
).rPaper
.bottom
= int( ((double) m_paperSize
.y
- m_minMarginTopLeft
.y
)*mm2pt
) ;
1244 (**m_macPageSetupInfo
).prInfo
.rPage
.left
= 0 ;
1245 (**m_macPageSetupInfo
).prInfo
.rPage
.top
= 0 ;
1246 (**m_macPageSetupInfo
).prInfo
.rPage
.right
= int( ((double) m_paperSize
.x
- m_minMarginTopLeft
.x
- m_minMarginBottomRight
.x
)*mm2pt
) ;
1247 (**m_macPageSetupInfo
).prInfo
.rPage
.bottom
= int( ((double) m_paperSize
.y
- m_minMarginTopLeft
.y
- m_minMarginBottomRight
.y
)*mm2pt
) ;
1249 //TODO add custom fields in dialog for margins
1254 void wxPageSetupDialogData::ConvertFromNative()
1256 if ( m_macPageSetupInfo
)
1258 m_paperSize
.x
= ((double) (**m_macPageSetupInfo
).rPaper
.right
- (**m_macPageSetupInfo
).rPaper
.left
) * pt2mm
;
1259 m_paperSize
.y
= ((double) (**m_macPageSetupInfo
).rPaper
.bottom
- (**m_macPageSetupInfo
).rPaper
.top
) * pt2mm
;
1261 m_minMarginTopLeft
.x
= ((double) -(**m_macPageSetupInfo
).rPaper
.left
) * pt2mm
;
1262 m_minMarginTopLeft
.y
= ((double) -(**m_macPageSetupInfo
).rPaper
.top
) * pt2mm
;
1264 m_minMarginBottomRight
.x
= ((double) (**m_macPageSetupInfo
).rPaper
.right
- (**m_macPageSetupInfo
).prInfo
.rPage
.right
) * pt2mm
;
1265 m_minMarginBottomRight
.y
= ((double)(**m_macPageSetupInfo
).rPaper
.bottom
- (**m_macPageSetupInfo
).prInfo
.rPage
.bottom
) * pt2mm
;
1267 // adjust minimal values
1268 //TODO add custom fields in dialog for margins
1270 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
1271 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
1273 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
1274 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
1276 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
1277 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
1279 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
1280 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
1287 // If a corresponding paper type is found in the paper database, will set the m_printData
1288 // paper size id member as well.
1289 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
1293 CalculateIdFromPaperSize();
1296 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1297 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1299 m_printData
.SetPaperId(id
);
1301 CalculatePaperSizeFromId();
1304 // Use paper size defined in this object to set the wxPrintData
1306 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1308 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1309 wxT("wxThePrintPaperDatabase should not be NULL. "
1310 "Do not create global print dialog data objects.") );
1312 wxSize sz
= GetPaperSize();
1314 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1315 if (id
!= wxPAPER_NONE
)
1317 m_printData
.SetPaperId(id
);
1321 // Use paper id in wxPrintData to set this object's paper size
1322 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1324 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1325 wxT("wxThePrintPaperDatabase should not be NULL. "
1326 "Do not create global print dialog data objects.") );
1328 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
1332 // sz is in 10ths of a mm, so multiply by 10.
1333 m_paperSize
.x
= sz
.x
* 10;
1334 m_paperSize
.y
= sz
.y
* 10;
1338 #endif // wxUSE_PRINTING_ARCHITECTURE