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"
45 #if (defined(__WXMOTIF__) || defined(__WXGTK__)) && wxUSE_POSTSCRIPT
46 #define wxCOMPATIBILITY_WITH_PRINTSETUPDATA 1
49 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
50 #include "wx/generic/dcpsg.h"
55 #include <wx/msw/private.h>
57 #if !defined(__WIN32__)
62 #if defined(__WATCOMC__) || defined(__SC__) || defined(__SALFORDC__)
68 #if !USE_SHARED_LIBRARY
69 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
70 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
71 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
72 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
73 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
76 // ============================================================================
78 // ============================================================================
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 wxColourData::wxColourData()
87 for (i
= 0; i
< 16; i
++)
88 custColours
[i
].Set(255, 255, 255);
91 dataColour
.Set(0,0,0);
94 wxColourData::wxColourData(const wxColourData
& data
)
99 wxColourData::~wxColourData()
103 void wxColourData::SetCustomColour(int i
, wxColour
& colour
)
108 custColours
[i
] = colour
;
111 wxColour
wxColourData::GetCustomColour(int i
)
114 return wxColour(0,0,0);
116 return custColours
[i
];
119 void wxColourData::operator=(const wxColourData
& data
)
122 for (i
= 0; i
< 16; i
++)
123 custColours
[i
] = data
.custColours
[i
];
125 dataColour
= (wxColour
&)data
.dataColour
;
126 chooseFull
= data
.chooseFull
;
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
133 wxFontData::wxFontData()
135 // Intialize colour to black.
136 fontColour
.Set(0, 0, 0);
140 enableEffects
= TRUE
;
145 wxFontData::wxFontData(const wxFontData
& data
)
150 wxFontData::~wxFontData()
154 void wxFontData::operator=(const wxFontData
& data
)
156 fontColour
= data
.fontColour
;
157 showHelp
= data
.showHelp
;
158 allowSymbols
= data
.allowSymbols
;
159 enableEffects
= data
.enableEffects
;
160 initialFont
= data
.initialFont
;
161 chosenFont
= data
.chosenFont
;
162 minSize
= data
.minSize
;
163 maxSize
= data
.maxSize
;
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
170 wxPrintData::wxPrintData()
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
)
209 wxPrintData::~wxPrintData()
212 HGLOBAL hDevMode
= (HGLOBAL
) m_devMode
;
214 GlobalFree(hDevMode
);
218 #if defined(__WXMSW__) && defined(__WIN32__)
220 static wxString
wxGetPrintDlgError()
222 DWORD err
= CommDlgExtendedError();
223 wxString msg
= _T("Unknown");
226 case CDERR_FINDRESFAILURE
: msg
= _T("CDERR_FINDRESFAILURE"); break;
227 case CDERR_INITIALIZATION
: msg
= _T("CDERR_INITIALIZATION"); break;
228 case CDERR_LOADRESFAILURE
: msg
= _T("CDERR_LOADRESFAILURE"); break;
229 case CDERR_LOADSTRFAILURE
: msg
= _T("CDERR_LOADSTRFAILURE"); break;
230 case CDERR_LOCKRESFAILURE
: msg
= _T("CDERR_LOCKRESFAILURE"); break;
231 case CDERR_MEMALLOCFAILURE
: msg
= _T("CDERR_MEMALLOCFAILURE"); break;
232 case CDERR_MEMLOCKFAILURE
: msg
= _T("CDERR_MEMLOCKFAILURE"); break;
233 case CDERR_NOHINSTANCE
: msg
= _T("CDERR_NOHINSTANCE"); break;
234 case CDERR_NOHOOK
: msg
= _T("CDERR_NOHOOK"); break;
235 case CDERR_NOTEMPLATE
: msg
= _T("CDERR_NOTEMPLATE"); break;
236 case CDERR_STRUCTSIZE
: msg
= _T("CDERR_STRUCTSIZE"); break;
237 case PDERR_RETDEFFAILURE
: msg
= _T("PDERR_RETDEFFAILURE"); break;
238 case PDERR_PRINTERNOTFOUND
: msg
= _T("PDERR_PRINTERNOTFOUND"); break;
239 case PDERR_PARSEFAILURE
: msg
= _T("PDERR_PARSEFAILURE"); break;
240 case PDERR_NODEVICES
: msg
= _T("PDERR_NODEVICES"); break;
241 case PDERR_NODEFAULTPRN
: msg
= _T("PDERR_NODEFAULTPRN"); break;
242 case PDERR_LOADDRVFAILURE
: msg
= _T("PDERR_LOADDRVFAILURE"); break;
243 case PDERR_INITFAILURE
: msg
= _T("PDERR_INITFAILURE"); break;
244 case PDERR_GETDEVMODEFAIL
: msg
= _T("PDERR_GETDEVMODEFAIL"); break;
245 case PDERR_DNDMMISMATCH
: msg
= _T("PDERR_DNDMMISMATCH"); break;
246 case PDERR_DEFAULTDIFFERENT
: msg
= _T("PDERR_DEFAULTDIFFERENT"); break;
247 case PDERR_CREATEICFAILURE
: msg
= _T("PDERR_CREATEICFAILURE"); break;
255 void wxPrintData::ConvertToNative()
257 HGLOBAL hDevMode
= (HGLOBAL
) m_devMode
;
260 // Use PRINTDLG as a way of creating a DEVMODE object
261 PRINTDLG
*pd
= new PRINTDLG
;
263 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
266 pd
->lStructSize
= 66 ;
268 memset(pd
, 0, sizeof(PRINTDLG
));
269 pd
->lStructSize
= sizeof(PRINTDLG
);
272 pd
->hwndOwner
= (HWND
)NULL
;
273 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
274 pd
->hDevNames
= NULL
; // Ditto
275 pd
->hInstance
= (HINSTANCE
) wxGetInstance();
277 pd
->Flags
= PD_RETURNDEFAULT
;
280 // Fill out the DEVMODE structure
281 // so we can use it as input in the 'real' PrintDlg
285 GlobalFree(pd
->hDevMode
);
287 GlobalFree(pd
->hDevNames
);
289 pd
->hDevNames
= NULL
;
291 #if defined(__WXDEBUG__) && defined(__WIN32__)
292 wxString
str(_T("Printing error: "));
293 str
+= wxGetPrintDlgError();
300 GlobalFree(pd
->hDevNames
);
301 pd
->hDevNames
= NULL
;
303 hDevMode
= pd
->hDevMode
;
304 m_devMode
= (void*) hDevMode
;
313 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(hDevMode
);
317 devMode
->dmOrientation
= m_printOrientation
;
318 devMode
->dmFields
= DM_ORIENTATION
;
322 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
323 devMode
->dmFields
|= DM_COLLATE
;
325 //// Number of copies
327 devMode
->dmCopies
= m_printNoCopies
;
328 devMode
->dmFields
|= DM_COPIES
;
332 if (m_printerName
!= _T(""))
334 // TODO: make this Unicode compatible
335 int len
= wxMin(31, m_printerName
.Len());
337 for (i
= 0; i
< len
; i
++)
338 devMode
->dmDeviceName
[i
] = m_printerName
.GetChar(i
);
339 devMode
->dmDeviceName
[i
] = 0;
345 devMode
->dmColor
= DMCOLOR_COLOR
;
347 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
349 devMode
->dmFields
|= DM_COLOR
;
353 if (m_paperId
== wxPAPER_NONE
)
355 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
356 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
357 devMode
->dmFields
|= DM_PAPERWIDTH
;
358 devMode
->dmFields
|= DM_PAPERLENGTH
;
362 if (wxThePrintPaperDatabase
)
364 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
367 devMode
->dmPaperSize
= paper
->GetPlatformId();
368 devMode
->dmFields
|= DM_PAPERSIZE
;
376 switch (m_duplexMode
)
378 case wxDUPLEX_HORIZONTAL
: {
379 duplex
= DMDUP_HORIZONTAL
; break;
381 case wxDUPLEX_VERTICAL
: {
382 duplex
= DMDUP_VERTICAL
; break;
385 case wxDUPLEX_SIMPLEX
: {
386 duplex
= DMDUP_SIMPLEX
; break;
389 devMode
->dmDuplex
= duplex
;
390 devMode
->dmFields
|= DM_DUPLEX
;
395 switch (m_printQuality
)
397 case wxPRINT_QUALITY_MEDIUM
: {
398 quality
= DMRES_MEDIUM
; break;
400 case wxPRINT_QUALITY_LOW
: {
401 quality
= DMRES_LOW
; break;
403 case wxPRINT_QUALITY_DRAFT
: {
404 quality
= DMRES_DRAFT
; break;
406 case wxPRINT_QUALITY_HIGH
: {
407 quality
= DMRES_HIGH
; break;
410 quality
= m_printQuality
; break;
413 devMode
->dmPrintQuality
= quality
;
414 devMode
->dmFields
|= DM_PRINTQUALITY
;
416 GlobalUnlock(hDevMode
);
420 void wxPrintData::ConvertFromNative()
422 HGLOBAL hDevMode
= (HGLOBAL
) m_devMode
;
429 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(hDevMode
);
433 if (devMode
->dmFields
& DM_ORIENTATION
)
434 m_printOrientation
= devMode
->dmOrientation
;
438 if (devMode
->dmFields
& DM_COLLATE
)
440 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
441 m_printCollate
= TRUE
;
443 m_printCollate
= FALSE
;
446 //// Number of copies
448 if (devMode
->dmFields
& DM_COPIES
)
450 m_printNoCopies
= devMode
->dmCopies
;
455 if (devMode
->dmDeviceName
[0] != 0)
457 // TODO: make this Unicode compatible
460 while (devMode
->dmDeviceName
[i
] != 0)
462 buf
[i
] = devMode
->dmDeviceName
[i
];
472 if (devMode
->dmFields
& DM_COLOR
)
474 if (devMode
->dmColor
== DMCOLOR_COLOR
)
484 if (devMode
->dmFields
& DM_PAPERSIZE
)
486 if (wxThePrintPaperDatabase
)
488 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
491 m_paperId
= paper
->GetId();
492 m_paperSize
.x
= paper
->GetWidth() / 10 ;
493 m_paperSize
.y
= paper
->GetHeight() / 10 ;
497 // Shouldn't really get here
498 wxFAIL_MSG(_T("Couldn't find paper size in paper database."));
500 m_paperId
= wxPAPER_NONE
;
507 // Shouldn't really get here
508 wxFAIL_MSG(_T("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
510 m_paperId
= wxPAPER_NONE
;
515 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
517 m_paperSize
.x
= devMode
->dmPaperWidth
/ 10;
518 m_paperSize
.y
= devMode
->dmPaperLength
/ 10;
519 m_paperId
= wxPAPER_NONE
;
523 // Shouldn't really get here
524 wxFAIL_MSG(_T("Couldn't find paper size from DEVMODE."));
528 m_paperId
= wxPAPER_NONE
;
534 if (devMode
->dmFields
& DM_DUPLEX
)
536 switch (devMode
->dmDuplex
)
538 case DMDUP_HORIZONTAL
: {
539 m_duplexMode
= wxDUPLEX_HORIZONTAL
; break;
541 case DMDUP_VERTICAL
: {
542 m_duplexMode
= wxDUPLEX_VERTICAL
; break;
545 case DMDUP_SIMPLEX
: {
546 m_duplexMode
= wxDUPLEX_SIMPLEX
; break;
551 m_duplexMode
= wxDUPLEX_SIMPLEX
;
555 if (devMode
->dmFields
& DM_PRINTQUALITY
)
557 switch (devMode
->dmPrintQuality
)
560 m_printQuality
= wxPRINT_QUALITY_MEDIUM
; break;
563 m_printQuality
= wxPRINT_QUALITY_LOW
; break;
566 m_printQuality
= wxPRINT_QUALITY_DRAFT
; break;
569 m_printQuality
= wxPRINT_QUALITY_HIGH
; break;
573 // TODO: if the printer fills in the resolution in DPI, how
574 // will the application know if it's high, low, draft etc.??
575 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
576 m_printQuality
= devMode
->dmPrintQuality
; break;
582 m_printQuality
= wxPRINT_QUALITY_HIGH
;
584 GlobalUnlock(hDevMode
);
590 void wxPrintData::operator=(const wxPrintData
& data
)
592 m_printNoCopies
= data
.m_printNoCopies
;
593 m_printCollate
= data
.m_printCollate
;
594 m_printOrientation
= data
.m_printOrientation
;
595 m_printerName
= data
.m_printerName
;
596 m_colour
= data
.m_colour
;
597 m_duplexMode
= data
.m_duplexMode
;
598 m_printQuality
= data
.m_printQuality
;
599 m_paperId
= data
.m_paperId
;
600 m_paperSize
= data
.m_paperSize
;
602 // PostScript-specific data
603 m_printerCommand
= data
.m_printerCommand
;
604 m_previewCommand
= data
.m_previewCommand
;
605 m_printerOptions
= data
.m_printerOptions
;
606 m_filename
= data
.m_filename
;
607 m_afmPath
= data
.m_afmPath
;
608 m_printerScaleX
= data
.m_printerScaleX
;
609 m_printerScaleY
= data
.m_printerScaleY
;
610 m_printerTranslateX
= data
.m_printerTranslateX
;
611 m_printerTranslateY
= data
.m_printerTranslateY
;
612 m_printMode
= data
.m_printMode
;
616 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
617 void wxPrintData::operator=(const wxPrintSetupData
& setupData
)
619 SetPrinterCommand(setupData
.GetPrinterCommand());
620 SetPreviewCommand(setupData
.GetPrintPreviewCommand());
621 SetPrinterOptions(setupData
.GetPrinterOptions());
624 setupData
.GetPrinterTranslation(& xt
, & yt
);
625 SetPrinterTranslation(xt
, yt
);
628 setupData
.GetPrinterScaling(& xs
, & ys
);
629 SetPrinterScaling(xs
, ys
);
631 SetOrientation(setupData
.GetPrinterOrientation());
632 SetPrintMode((wxPrintMode
) setupData
.GetPrinterMode());
633 SetFontMetricPath(setupData
.GetAFMPath());
634 if (setupData
.GetPaperName() != "")
635 SetPaperId(wxThePrintPaperDatabase
->ConvertNameToId(setupData
.GetPaperName()));
636 SetColour(setupData
.GetColour());
637 SetFilename(setupData
.GetPrinterFile());
639 #endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
642 // ----------------------------------------------------------------------------
644 // ----------------------------------------------------------------------------
646 wxPrintDialogData::wxPrintDialogData()
649 m_printDlgData
= NULL
;
656 m_printAllPages
= FALSE
;
657 m_printCollate
= FALSE
;
658 m_printToFile
= FALSE
;
659 m_printEnableSelection
= FALSE
;
660 m_printEnablePageNumbers
= TRUE
;
661 m_printEnablePrintToFile
= TRUE
;
662 m_printEnableHelp
= FALSE
;
663 m_printSetupDialog
= FALSE
;
666 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
668 (*this) = dialogData
;
671 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
674 m_printDlgData
= NULL
;
681 m_printAllPages
= FALSE
;
682 m_printCollate
= FALSE
;
683 m_printToFile
= FALSE
;
684 m_printEnableSelection
= FALSE
;
685 m_printEnablePageNumbers
= TRUE
;
686 m_printEnablePrintToFile
= TRUE
;
687 m_printEnableHelp
= FALSE
;
688 m_printSetupDialog
= FALSE
;
690 m_printData
= printData
;
693 wxPrintDialogData::~wxPrintDialogData()
696 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
697 if ( pd
&& pd
->hDevMode
)
698 GlobalFree(pd
->hDevMode
);
705 void wxPrintDialogData::ConvertToNative()
707 m_printData
.ConvertToNative();
709 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
714 m_printDlgData
= (void*) pd
;
716 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
718 pd
->lStructSize
= 66 ;
721 pd
->lStructSize
= sizeof(PRINTDLG
);
722 pd
->hwndOwner
= (HWND
)NULL
;
723 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
724 pd
->hDevNames
= NULL
; // Ditto
726 pd
->Flags
= PD_RETURNDEFAULT
;
730 // Pass the devmode data to the PRINTDLG structure, since it'll
731 // be needed when PrintDlg is called.
734 GlobalFree(pd
->hDevMode
);
737 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
739 m_printData
.SetNativeData((void*) NULL
);
741 wxASSERT_MSG( (pd
->hDevMode
), _T("hDevMode must be non-NULL in ConvertToNative!"));
743 pd
->hDC
= (HDC
) NULL
;
744 pd
->nFromPage
= (UINT
)m_printFromPage
;
745 pd
->nToPage
= (UINT
)m_printToPage
;
746 pd
->nMinPage
= (UINT
)m_printMinPage
;
747 pd
->nMaxPage
= (UINT
)m_printMaxPage
;
748 pd
->nCopies
= (UINT
)m_printNoCopies
;
750 pd
->Flags
= PD_RETURNDC
;
753 pd
->lStructSize
= 66 ;
755 pd
->lStructSize
= sizeof( PRINTDLG
);
758 pd
->hwndOwner
=(HWND
)NULL
;
759 pd
->hDevNames
=(HANDLE
)NULL
;
760 pd
->hInstance
=(HINSTANCE
)NULL
;
761 pd
->lCustData
= (LPARAM
) NULL
;
762 pd
->lpfnPrintHook
= NULL
;
763 pd
->lpfnSetupHook
= NULL
;
764 pd
->lpPrintTemplateName
= NULL
;
765 pd
->lpSetupTemplateName
= NULL
;
766 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
767 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
769 if ( m_printAllPages
)
770 pd
->Flags
|= PD_ALLPAGES
;
771 if ( m_printCollate
)
772 pd
->Flags
|= PD_COLLATE
;
774 pd
->Flags
|= PD_PRINTTOFILE
;
775 if ( !m_printEnablePrintToFile
)
776 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
777 if ( !m_printEnableSelection
)
778 pd
->Flags
|= PD_NOSELECTION
;
779 if ( !m_printEnablePageNumbers
)
780 pd
->Flags
|= PD_NOPAGENUMS
;
781 if ( m_printEnableHelp
)
782 pd
->Flags
|= PD_SHOWHELP
;
783 if ( m_printSetupDialog
)
784 pd
->Flags
|= PD_PRINTSETUP
;
787 void wxPrintDialogData::ConvertFromNative()
789 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
793 // Pass the devmode data back to the wxPrintData structure where it really belongs.
796 if (m_printData
.GetNativeData())
798 // Make sure we don't leak memory
799 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
801 m_printData
.SetNativeData((void*) pd
->hDevMode
);
805 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
806 // into wxWindows form.
807 m_printData
.ConvertFromNative();
809 m_printFromPage
= pd
->nFromPage
;
810 m_printToPage
= pd
->nToPage
;
811 m_printMinPage
= pd
->nMinPage
;
812 m_printMaxPage
= pd
->nMaxPage
;
813 m_printNoCopies
= pd
->nCopies
;
815 m_printAllPages
= ((pd
->Flags
& PD_ALLPAGES
) == PD_ALLPAGES
);
816 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
817 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
818 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
819 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
820 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
821 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
822 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
824 /* port is obsolete in WIN32
828 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
830 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
831 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
832 GlobalUnlock(pd->hDevNames);
834 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
840 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
842 if ( m_printDlgData
== NULL
)
845 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
847 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
848 pd
->hwndOwner
=(HWND
) win
->GetHWND();
853 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
855 m_printFromPage
= data
.m_printFromPage
;
856 m_printToPage
= data
.m_printToPage
;
857 m_printMinPage
= data
.m_printMinPage
;
858 m_printMaxPage
= data
.m_printMaxPage
;
859 m_printNoCopies
= data
.m_printNoCopies
;
860 m_printAllPages
= data
.m_printAllPages
;
861 m_printCollate
= data
.m_printCollate
;
862 m_printToFile
= data
.m_printToFile
;
863 m_printEnableSelection
= data
.m_printEnableSelection
;
864 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
865 m_printEnableHelp
= data
.m_printEnableHelp
;
866 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
867 m_printSetupDialog
= data
.m_printSetupDialog
;
869 m_printData
= data
.m_printData
;
872 void wxPrintDialogData::operator=(const wxPrintData
& data
)
877 // ----------------------------------------------------------------------------
878 // wxPageSetupDialogData
879 // ----------------------------------------------------------------------------
881 wxPageSetupDialogData::wxPageSetupDialogData()
883 #if defined(__WIN95__)
884 m_pageSetupData
= NULL
;
886 m_paperSize
= wxSize(0, 0);
888 CalculatePaperSizeFromId();
890 m_minMarginTopLeft
= wxPoint(0, 0);
891 m_minMarginBottomRight
= wxPoint(0, 0);
892 m_marginTopLeft
= wxPoint(0, 0);
893 m_marginBottomRight
= wxPoint(0, 0);
896 m_defaultMinMargins
= FALSE
;
897 m_enableMargins
= TRUE
;
898 m_enableOrientation
= TRUE
;
899 m_enablePaper
= TRUE
;
900 m_enablePrinter
= TRUE
;
901 m_enableHelp
= FALSE
;
902 m_getDefaultInfo
= FALSE
;
905 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
907 (*this) = dialogData
;
910 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
912 #if defined(__WIN95__)
913 m_pageSetupData
= NULL
;
915 m_paperSize
= wxSize(0, 0);
916 m_minMarginTopLeft
= wxPoint(0, 0);
917 m_minMarginBottomRight
= wxPoint(0, 0);
918 m_marginTopLeft
= wxPoint(0, 0);
919 m_marginBottomRight
= wxPoint(0, 0);
922 m_defaultMinMargins
= FALSE
;
923 m_enableMargins
= TRUE
;
924 m_enableOrientation
= TRUE
;
925 m_enablePaper
= TRUE
;
926 m_enablePrinter
= TRUE
;
927 m_enableHelp
= FALSE
;
928 m_getDefaultInfo
= FALSE
;
930 m_printData
= printData
;
932 // The wxPrintData paper size overrides these values, unless the size cannot
934 CalculatePaperSizeFromId();
937 wxPageSetupDialogData::~wxPageSetupDialogData()
939 #if defined(__WIN95__) && defined(__WXMSW__)
940 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
941 if ( pd
&& pd
->hDevMode
)
942 GlobalFree(pd
->hDevMode
);
948 void wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
950 m_paperSize
= data
.m_paperSize
;
951 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
952 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
953 m_marginTopLeft
= data
.m_marginTopLeft
;
954 m_marginBottomRight
= data
.m_marginBottomRight
;
955 m_defaultMinMargins
= data
.m_defaultMinMargins
;
956 m_enableMargins
= data
.m_enableMargins
;
957 m_enableOrientation
= data
.m_enableOrientation
;
958 m_enablePaper
= data
.m_enablePaper
;
959 m_enablePrinter
= data
.m_enablePrinter
;
960 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
961 m_enableHelp
= data
.m_enableHelp
;
963 m_printData
= data
.m_printData
;
966 void wxPageSetupDialogData::operator=(const wxPrintData
& data
)
971 #if defined(__WIN95__)
972 void wxPageSetupDialogData::ConvertToNative()
974 m_printData
.ConvertToNative();
976 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
978 if ( m_pageSetupData
== NULL
)
980 pd
= new PAGESETUPDLG
;
982 m_pageSetupData
= (void *)pd
;
985 // Pass the devmode data (created in m_printData.ConvertToNative)
986 // to the PRINTDLG structure, since it'll
987 // be needed when PrintDlg is called.
991 GlobalFree(pd
->hDevMode
);
996 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
998 m_printData
.SetNativeData((void*) NULL
);
1000 wxASSERT_MSG( (pd
->hDevMode
), _T("hDevMode must be non-NULL in ConvertToNative!"));
1002 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1004 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1006 if ( m_defaultMinMargins
)
1007 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
1008 if ( !m_enableMargins
)
1009 pd
->Flags
|= PSD_DISABLEMARGINS
;
1010 if ( !m_enableOrientation
)
1011 pd
->Flags
|= PSD_DISABLEORIENTATION
;
1012 if ( !m_enablePaper
)
1013 pd
->Flags
|= PSD_DISABLEPAPER
;
1014 if ( !m_enablePrinter
)
1015 pd
->Flags
|= PSD_DISABLEPRINTER
;
1016 if ( m_getDefaultInfo
)
1017 pd
->Flags
|= PSD_RETURNDEFAULT
;
1019 pd
->Flags
|= PSD_SHOWHELP
;
1021 // We want the units to be in hundredths of a millimetre
1022 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1024 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
1025 pd
->hwndOwner
=(HWND
)NULL
;
1026 pd
->hDevNames
=(HWND
)NULL
;
1027 pd
->hInstance
=(HINSTANCE
)NULL
;
1029 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
1030 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
1032 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
1033 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
1034 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
1035 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
1037 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
1038 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
1039 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
1040 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
1043 pd
->lpfnPageSetupHook
= NULL
;
1044 pd
->lpfnPagePaintHook
= NULL
;
1045 pd
->hPageSetupTemplate
= NULL
;
1046 pd
->lpPageSetupTemplateName
= NULL
;
1051 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1052 memset(devMode, 0, sizeof(DEVMODE));
1053 devMode->dmSize = sizeof(DEVMODE);
1054 devMode->dmOrientation = m_orientation;
1055 devMode->dmFields = DM_ORIENTATION;
1056 GlobalUnlock(pd->hDevMode);
1061 void wxPageSetupDialogData::ConvertFromNative()
1063 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1067 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1070 if (m_printData
.GetNativeData())
1072 // Make sure we don't leak memory
1073 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1075 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1076 pd
->hDevMode
= NULL
;
1079 m_printData
.ConvertFromNative();
1081 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1083 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
1084 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
1085 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
1086 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
1087 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
1088 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
1089 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
1091 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1092 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
1094 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
1095 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
1096 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
1097 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
1099 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100 ;
1100 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100 ;
1101 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100 ;
1102 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100 ;
1105 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1107 if ( m_pageSetupData
== NULL
)
1110 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1112 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1113 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1118 // If a corresponding paper type is found in the paper database, will set the m_printData
1119 // paper size id member as well.
1120 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
1124 CalculateIdFromPaperSize();
1127 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1128 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1130 m_printData
.SetPaperId(id
);
1132 CalculatePaperSizeFromId();
1135 // Use paper size defined in this object to set the wxPrintData
1137 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1139 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1140 _T("wxThePrintPaperDatabase should not be NULL. "
1141 "Do not create global print dialog data objects.") );
1143 wxSize sz
= GetPaperSize();
1145 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1146 if (id
!= wxPAPER_NONE
)
1148 m_printData
.SetPaperId(id
);
1152 // Use paper id in wxPrintData to set this object's paper size
1153 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1155 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1156 _T("wxThePrintPaperDatabase should not be NULL. "
1157 "Do not create global print dialog data objects.") );
1159 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
1163 // sz is in 10ths of a mm, so multiply by 10.
1164 m_paperSize
.x
= sz
.x
* 10;
1165 m_paperSize
.y
= sz
.y
* 10;