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"
44 #if (defined(__WXMOTIF__) || defined(__WXGTK__)) && wxUSE_POSTSCRIPT
45 #define wxCOMPATIBILITY_WITH_PRINTSETUPDATA 1
48 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
49 #include "wx/generic/dcpsg.h"
54 #include <wx/msw/private.h>
56 #if !defined(__WIN32__)
61 #if defined(__WATCOMC__) || defined(__SC__) || defined(__SALFORDC__)
67 #if !USE_SHARED_LIBRARY
68 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
69 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
70 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
71 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
72 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
75 // ============================================================================
77 // ============================================================================
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
83 wxColourData::wxColourData()
86 for (i
= 0; i
< 16; i
++)
87 custColours
[i
].Set(255, 255, 255);
90 dataColour
.Set(0,0,0);
93 wxColourData::wxColourData(const wxColourData
& data
)
98 wxColourData::~wxColourData()
102 void wxColourData::SetCustomColour(int i
, wxColour
& colour
)
107 custColours
[i
] = colour
;
110 wxColour
wxColourData::GetCustomColour(int i
)
113 return wxColour(0,0,0);
115 return custColours
[i
];
118 void wxColourData::operator=(const wxColourData
& data
)
121 for (i
= 0; i
< 16; i
++)
122 custColours
[i
] = data
.custColours
[i
];
124 dataColour
= (wxColour
&)data
.dataColour
;
125 chooseFull
= data
.chooseFull
;
128 // ----------------------------------------------------------------------------
130 // ----------------------------------------------------------------------------
132 wxFontData::wxFontData()
134 // Intialize colour to black.
135 fontColour
.Set(0, 0, 0);
139 enableEffects
= TRUE
;
144 wxFontData::wxFontData(const wxFontData
& data
)
149 wxFontData::~wxFontData()
153 void wxFontData::operator=(const wxFontData
& data
)
155 fontColour
= data
.fontColour
;
156 showHelp
= data
.showHelp
;
157 allowSymbols
= data
.allowSymbols
;
158 enableEffects
= data
.enableEffects
;
159 initialFont
= data
.initialFont
;
160 chosenFont
= data
.chosenFont
;
161 minSize
= data
.minSize
;
162 maxSize
= data
.maxSize
;
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
169 wxPrintData::wxPrintData()
174 m_printOrientation
= wxPORTRAIT
;
176 m_printCollate
= FALSE
;
181 m_duplexMode
= wxDUPLEX_SIMPLEX
;
182 m_printQuality
= wxPRINT_QUALITY_HIGH
;
183 m_paperId
= wxPAPER_A4
;
184 m_paperSize
= wxSize(210, 297);
186 // PostScript-specific data
187 m_printerCommand
= "";
188 m_previewCommand
= "";
189 m_printerOptions
= "";
192 m_printerScaleX
= 1.0;
193 m_printerScaleY
= 1.0;
194 m_printerTranslateX
= 0;
195 m_printerTranslateY
= 0;
196 m_printMode
= wxPRINT_MODE_FILE
;
199 wxPrintData::wxPrintData(const wxPrintData
& printData
)
204 wxPrintData::~wxPrintData()
207 HGLOBAL hDevMode
= (HGLOBAL
) m_devMode
;
209 GlobalFree(hDevMode
);
215 static wxString
wxGetPrintDlgError()
217 DWORD err
= CommDlgExtendedError();
218 wxString msg
= "Unknown";
221 case CDERR_FINDRESFAILURE
: msg
= "CDERR_FINDRESFAILURE"; break;
222 case CDERR_INITIALIZATION
: msg
= "CDERR_INITIALIZATION"; break;
223 case CDERR_LOADRESFAILURE
: msg
= "CDERR_LOADRESFAILURE"; break;
224 case CDERR_LOADSTRFAILURE
: msg
= "CDERR_LOADSTRFAILURE"; break;
225 case CDERR_LOCKRESFAILURE
: msg
= "CDERR_LOCKRESFAILURE"; break;
226 case CDERR_MEMALLOCFAILURE
: msg
= "CDERR_MEMALLOCFAILURE"; break;
227 case CDERR_MEMLOCKFAILURE
: msg
= "CDERR_MEMLOCKFAILURE"; break;
228 case CDERR_NOHINSTANCE
: msg
= "CDERR_NOHINSTANCE"; break;
229 case CDERR_NOHOOK
: msg
= "CDERR_NOHOOK"; break;
230 case CDERR_NOTEMPLATE
: msg
= "CDERR_NOTEMPLATE"; break;
231 case CDERR_STRUCTSIZE
: msg
= "CDERR_STRUCTSIZE"; break;
232 case PDERR_RETDEFFAILURE
: msg
= "PDERR_RETDEFFAILURE"; break;
233 case PDERR_PRINTERNOTFOUND
: msg
= "PDERR_PRINTERNOTFOUND"; break;
234 case PDERR_PARSEFAILURE
: msg
= "PDERR_PARSEFAILURE"; break;
235 case PDERR_NODEVICES
: msg
= "PDERR_NODEVICES"; break;
236 case PDERR_NODEFAULTPRN
: msg
= "PDERR_NODEFAULTPRN"; break;
237 case PDERR_LOADDRVFAILURE
: msg
= "PDERR_LOADDRVFAILURE"; break;
238 case PDERR_INITFAILURE
: msg
= "PDERR_INITFAILURE"; break;
239 case PDERR_GETDEVMODEFAIL
: msg
= "PDERR_GETDEVMODEFAIL"; break;
240 case PDERR_DNDMMISMATCH
: msg
= "PDERR_DNDMMISMATCH"; break;
241 case PDERR_DEFAULTDIFFERENT
: msg
= "PDERR_DEFAULTDIFFERENT"; break;
242 case PDERR_CREATEICFAILURE
: msg
= "PDERR_CREATEICFAILURE"; break;
250 void wxPrintData::ConvertToNative()
252 HGLOBAL hDevMode
= (HGLOBAL
) m_devMode
;
255 // Use PRINTDLG as a way of creating a DEVMODE object
256 PRINTDLG
*pd
= new PRINTDLG
;
258 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
261 pd
->lStructSize
= 66 ;
263 memset(pd
, 0, sizeof(PRINTDLG
));
264 pd
->lStructSize
= sizeof(PRINTDLG
);
267 pd
->hwndOwner
= (HWND
)NULL
;
268 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
269 pd
->hDevNames
= NULL
; // Ditto
270 pd
->hInstance
= (HINSTANCE
) wxGetInstance();
272 pd
->Flags
= PD_RETURNDEFAULT
;
275 // Fill out the DEVMODE structure
276 // so we can use it as input in the 'real' PrintDlg
280 GlobalFree(pd
->hDevMode
);
282 GlobalFree(pd
->hDevNames
);
284 pd
->hDevNames
= NULL
;
286 wxString
str("Printing error: ");
287 str
+= wxGetPrintDlgError();
294 GlobalFree(pd
->hDevNames
);
295 pd
->hDevNames
= NULL
;
297 hDevMode
= pd
->hDevMode
;
298 m_devMode
= (void*) hDevMode
;
307 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(hDevMode
);
311 devMode
->dmOrientation
= m_printOrientation
;
312 devMode
->dmFields
= DM_ORIENTATION
;
316 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
317 devMode
->dmFields
|= DM_COLLATE
;
319 //// Number of copies
321 devMode
->dmCopies
= m_printNoCopies
;
322 devMode
->dmFields
|= DM_COPIES
;
326 if (m_printerName
!= "")
328 // TODO: make this Unicode compatible
329 int len
= wxMin(31, m_printerName
.Len());
331 for (i
= 0; i
< len
; i
++)
332 devMode
->dmDeviceName
[i
] = m_printerName
.GetChar(i
);
333 devMode
->dmDeviceName
[i
] = 0;
339 devMode
->dmColor
= DMCOLOR_COLOR
;
341 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
343 devMode
->dmFields
|= DM_COLOR
;
347 if (m_paperId
== wxPAPER_NONE
)
349 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
350 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
351 devMode
->dmFields
|= DM_PAPERWIDTH
;
352 devMode
->dmFields
|= DM_PAPERLENGTH
;
356 if (wxThePrintPaperDatabase
)
358 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
361 devMode
->dmPaperSize
= paper
->GetPlatformId();
362 devMode
->dmFields
|= DM_PAPERSIZE
;
370 switch (m_duplexMode
)
372 case wxDUPLEX_HORIZONTAL
: {
373 duplex
= DMDUP_HORIZONTAL
; break;
375 case wxDUPLEX_VERTICAL
: {
376 duplex
= DMDUP_VERTICAL
; break;
379 case wxDUPLEX_SIMPLEX
: {
380 duplex
= DMDUP_SIMPLEX
; break;
383 devMode
->dmDuplex
= duplex
;
384 devMode
->dmFields
|= DM_DUPLEX
;
389 switch (m_printQuality
)
391 case wxPRINT_QUALITY_MEDIUM
: {
392 quality
= DMRES_MEDIUM
; break;
394 case wxPRINT_QUALITY_LOW
: {
395 quality
= DMRES_LOW
; break;
397 case wxPRINT_QUALITY_DRAFT
: {
398 quality
= DMRES_DRAFT
; break;
400 case wxPRINT_QUALITY_HIGH
: {
401 quality
= DMRES_HIGH
; break;
404 quality
= m_printQuality
; break;
407 devMode
->dmPrintQuality
= quality
;
408 devMode
->dmFields
|= DM_PRINTQUALITY
;
410 GlobalUnlock(hDevMode
);
414 void wxPrintData::ConvertFromNative()
416 HGLOBAL hDevMode
= (HGLOBAL
) m_devMode
;
423 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(hDevMode
);
427 if (devMode
->dmFields
& DM_ORIENTATION
)
428 m_printOrientation
= devMode
->dmOrientation
;
432 if (devMode
->dmFields
& DM_COLLATE
)
434 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
435 m_printCollate
= TRUE
;
437 m_printCollate
= FALSE
;
440 //// Number of copies
442 if (devMode
->dmFields
& DM_COPIES
)
444 m_printNoCopies
= devMode
->dmCopies
;
449 if (devMode
->dmDeviceName
[0] != 0)
451 // TODO: make this Unicode compatible
454 while (devMode
->dmDeviceName
[i
] != 0)
456 buf
[i
] = devMode
->dmDeviceName
[i
];
466 if (devMode
->dmFields
& DM_COLOR
)
468 if (devMode
->dmColor
== DMCOLOR_COLOR
)
478 if (devMode
->dmFields
& DM_PAPERSIZE
)
480 if (wxThePrintPaperDatabase
)
482 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
485 m_paperId
= paper
->GetId();
486 m_paperSize
.x
= paper
->GetWidth() / 10 ;
487 m_paperSize
.y
= paper
->GetHeight() / 10 ;
491 // Shouldn't really get here
492 wxFAIL_MSG("Couldn't find paper size in paper database.");
494 m_paperId
= wxPAPER_NONE
;
501 // Shouldn't really get here
502 wxFAIL_MSG("Paper database wasn't initialized in wxPrintData::ConvertFromNative.");
504 m_paperId
= wxPAPER_NONE
;
509 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
511 m_paperSize
.x
= devMode
->dmPaperWidth
/ 10;
512 m_paperSize
.y
= devMode
->dmPaperLength
/ 10;
513 m_paperId
= wxPAPER_NONE
;
517 // Shouldn't really get here
518 wxFAIL_MSG("Couldn't find paper size from DEVMODE.");
522 m_paperId
= wxPAPER_NONE
;
528 if (devMode
->dmFields
& DM_DUPLEX
)
530 switch (devMode
->dmDuplex
)
532 case DMDUP_HORIZONTAL
: {
533 m_duplexMode
= wxDUPLEX_HORIZONTAL
; break;
535 case DMDUP_VERTICAL
: {
536 m_duplexMode
= wxDUPLEX_VERTICAL
; break;
539 case DMDUP_SIMPLEX
: {
540 m_duplexMode
= wxDUPLEX_SIMPLEX
; break;
545 m_duplexMode
= wxDUPLEX_SIMPLEX
;
549 if (devMode
->dmFields
& DM_PRINTQUALITY
)
551 switch (devMode
->dmPrintQuality
)
554 m_printQuality
= wxPRINT_QUALITY_MEDIUM
; break;
557 m_printQuality
= wxPRINT_QUALITY_LOW
; break;
560 m_printQuality
= wxPRINT_QUALITY_DRAFT
; break;
563 m_printQuality
= wxPRINT_QUALITY_HIGH
; break;
567 // TODO: if the printer fills in the resolution in DPI, how
568 // will the application know if it's high, low, draft etc.??
569 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
570 m_printQuality
= devMode
->dmPrintQuality
; break;
576 m_printQuality
= wxPRINT_QUALITY_HIGH
;
578 GlobalUnlock(hDevMode
);
584 void wxPrintData::operator=(const wxPrintData
& data
)
586 m_printNoCopies
= data
.m_printNoCopies
;
587 m_printCollate
= data
.m_printCollate
;
588 m_printOrientation
= data
.m_printOrientation
;
589 m_printerName
= data
.m_printerName
;
590 m_colour
= data
.m_colour
;
591 m_duplexMode
= data
.m_duplexMode
;
592 m_printQuality
= data
.m_printQuality
;
593 m_paperId
= data
.m_paperId
;
594 m_paperSize
= data
.m_paperSize
;
596 // PostScript-specific data
597 m_printerCommand
= data
.m_printerCommand
;
598 m_previewCommand
= data
.m_previewCommand
;
599 m_printerOptions
= data
.m_printerOptions
;
600 m_filename
= data
.m_filename
;
601 m_afmPath
= data
.m_afmPath
;
602 m_printerScaleX
= data
.m_printerScaleX
;
603 m_printerScaleY
= data
.m_printerScaleY
;
604 m_printerTranslateX
= data
.m_printerTranslateX
;
605 m_printerTranslateY
= data
.m_printerTranslateY
;
606 m_printMode
= data
.m_printMode
;
610 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
611 void wxPrintData::operator=(const wxPrintSetupData
& setupData
)
613 SetPrinterCommand(setupData
.GetPrinterCommand());
614 SetPreviewCommand(setupData
.GetPrintPreviewCommand());
615 SetPrinterOptions(setupData
.GetPrinterOptions());
618 setupData
.GetPrinterTranslation(& xt
, & yt
);
619 SetPrinterTranslation(xt
, yt
);
622 setupData
.GetPrinterScaling(& xs
, & ys
);
623 SetPrinterScaling(xs
, ys
);
625 SetOrientation(setupData
.GetPrinterOrientation());
626 SetPrintMode((wxPrintMode
) setupData
.GetPrinterMode());
627 SetFontMetricPath(setupData
.GetAFMPath());
628 if (setupData
.GetPaperName() != "")
629 SetPaperId(wxThePrintPaperDatabase
->ConvertNameToId(setupData
.GetPaperName()));
630 SetColour(setupData
.GetColour());
631 SetFilename(setupData
.GetPrinterFile());
633 #endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
636 // ----------------------------------------------------------------------------
638 // ----------------------------------------------------------------------------
640 wxPrintDialogData::wxPrintDialogData()
643 m_printDlgData
= NULL
;
650 m_printAllPages
= FALSE
;
651 m_printCollate
= FALSE
;
652 m_printToFile
= FALSE
;
653 m_printEnableSelection
= FALSE
;
654 m_printEnablePageNumbers
= TRUE
;
655 m_printEnablePrintToFile
= TRUE
;
656 m_printEnableHelp
= FALSE
;
657 m_printSetupDialog
= FALSE
;
660 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
662 (*this) = dialogData
;
665 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
668 m_printDlgData
= NULL
;
675 m_printAllPages
= FALSE
;
676 m_printCollate
= FALSE
;
677 m_printToFile
= FALSE
;
678 m_printEnableSelection
= FALSE
;
679 m_printEnablePageNumbers
= TRUE
;
680 m_printEnablePrintToFile
= TRUE
;
681 m_printEnableHelp
= FALSE
;
682 m_printSetupDialog
= FALSE
;
684 m_printData
= printData
;
687 wxPrintDialogData::~wxPrintDialogData()
690 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
691 if ( pd
&& pd
->hDevMode
)
692 GlobalFree(pd
->hDevMode
);
699 void wxPrintDialogData::ConvertToNative()
701 m_printData
.ConvertToNative();
703 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
708 m_printDlgData
= (void*) pd
;
710 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
712 pd
->lStructSize
= 66 ;
715 pd
->lStructSize
= sizeof(PRINTDLG
);
716 pd
->hwndOwner
= (HWND
)NULL
;
717 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
718 pd
->hDevNames
= NULL
; // Ditto
720 pd
->Flags
= PD_RETURNDEFAULT
;
724 // Pass the devmode data to the PRINTDLG structure, since it'll
725 // be needed when PrintDlg is called.
728 GlobalFree(pd
->hDevMode
);
731 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
733 m_printData
.SetNativeData((void*) NULL
);
735 wxASSERT_MSG( (pd
->hDevMode
), "hDevMode must be non-NULL in ConvertToNative!");
737 pd
->hDC
= (HDC
) NULL
;
738 pd
->nFromPage
= (UINT
)m_printFromPage
;
739 pd
->nToPage
= (UINT
)m_printToPage
;
740 pd
->nMinPage
= (UINT
)m_printMinPage
;
741 pd
->nMaxPage
= (UINT
)m_printMaxPage
;
742 pd
->nCopies
= (UINT
)m_printNoCopies
;
744 pd
->Flags
= PD_RETURNDC
;
747 pd
->lStructSize
= 66 ;
749 pd
->lStructSize
= sizeof( PRINTDLG
);
752 pd
->hwndOwner
=(HWND
)NULL
;
753 pd
->hDevNames
=(HANDLE
)NULL
;
754 pd
->hInstance
=(HINSTANCE
)NULL
;
755 pd
->lCustData
= (LPARAM
) NULL
;
756 pd
->lpfnPrintHook
= NULL
;
757 pd
->lpfnSetupHook
= NULL
;
758 pd
->lpPrintTemplateName
= NULL
;
759 pd
->lpSetupTemplateName
= NULL
;
760 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
761 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
763 if ( m_printAllPages
)
764 pd
->Flags
|= PD_ALLPAGES
;
765 if ( m_printCollate
)
766 pd
->Flags
|= PD_COLLATE
;
768 pd
->Flags
|= PD_PRINTTOFILE
;
769 if ( !m_printEnablePrintToFile
)
770 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
771 if ( !m_printEnableSelection
)
772 pd
->Flags
|= PD_NOSELECTION
;
773 if ( !m_printEnablePageNumbers
)
774 pd
->Flags
|= PD_NOPAGENUMS
;
775 if ( m_printEnableHelp
)
776 pd
->Flags
|= PD_SHOWHELP
;
777 if ( m_printSetupDialog
)
778 pd
->Flags
|= PD_PRINTSETUP
;
781 void wxPrintDialogData::ConvertFromNative()
783 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
787 // Pass the devmode data back to the wxPrintData structure where it really belongs.
790 if (m_printData
.GetNativeData())
792 // Make sure we don't leak memory
793 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
795 m_printData
.SetNativeData((void*) pd
->hDevMode
);
799 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
800 // into wxWindows form.
801 m_printData
.ConvertFromNative();
803 m_printFromPage
= pd
->nFromPage
;
804 m_printToPage
= pd
->nToPage
;
805 m_printMinPage
= pd
->nMinPage
;
806 m_printMaxPage
= pd
->nMaxPage
;
807 m_printNoCopies
= pd
->nCopies
;
809 m_printAllPages
= ((pd
->Flags
& PD_ALLPAGES
) == PD_ALLPAGES
);
810 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
811 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
812 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
813 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
814 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
815 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
816 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
818 /* port is obsolete in WIN32
822 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
824 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
825 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
826 GlobalUnlock(pd->hDevNames);
828 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
834 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
836 if ( m_printDlgData
== NULL
)
839 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
841 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
842 pd
->hwndOwner
=(HWND
) win
->GetHWND();
847 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
849 m_printFromPage
= data
.m_printFromPage
;
850 m_printToPage
= data
.m_printToPage
;
851 m_printMinPage
= data
.m_printMinPage
;
852 m_printMaxPage
= data
.m_printMaxPage
;
853 m_printNoCopies
= data
.m_printNoCopies
;
854 m_printAllPages
= data
.m_printAllPages
;
855 m_printCollate
= data
.m_printCollate
;
856 m_printToFile
= data
.m_printToFile
;
857 m_printEnableSelection
= data
.m_printEnableSelection
;
858 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
859 m_printEnableHelp
= data
.m_printEnableHelp
;
860 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
861 m_printSetupDialog
= data
.m_printSetupDialog
;
863 m_printData
= data
.m_printData
;
866 void wxPrintDialogData::operator=(const wxPrintData
& data
)
871 // ----------------------------------------------------------------------------
872 // wxPageSetupDialogData
873 // ----------------------------------------------------------------------------
875 wxPageSetupDialogData::wxPageSetupDialogData()
877 #if defined(__WIN95__)
878 m_pageSetupData
= NULL
;
880 m_paperSize
= wxSize(0, 0);
882 CalculatePaperSizeFromId();
884 m_minMarginTopLeft
= wxPoint(0, 0);
885 m_minMarginBottomRight
= wxPoint(0, 0);
886 m_marginTopLeft
= wxPoint(0, 0);
887 m_marginBottomRight
= wxPoint(0, 0);
890 m_defaultMinMargins
= FALSE
;
891 m_enableMargins
= TRUE
;
892 m_enableOrientation
= TRUE
;
893 m_enablePaper
= TRUE
;
894 m_enablePrinter
= TRUE
;
895 m_enableHelp
= FALSE
;
896 m_getDefaultInfo
= FALSE
;
899 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
901 (*this) = dialogData
;
904 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
906 #if defined(__WIN95__)
907 m_pageSetupData
= NULL
;
909 m_paperSize
= wxSize(0, 0);
910 m_minMarginTopLeft
= wxPoint(0, 0);
911 m_minMarginBottomRight
= wxPoint(0, 0);
912 m_marginTopLeft
= wxPoint(0, 0);
913 m_marginBottomRight
= wxPoint(0, 0);
916 m_defaultMinMargins
= FALSE
;
917 m_enableMargins
= TRUE
;
918 m_enableOrientation
= TRUE
;
919 m_enablePaper
= TRUE
;
920 m_enablePrinter
= TRUE
;
921 m_enableHelp
= FALSE
;
922 m_getDefaultInfo
= FALSE
;
924 m_printData
= printData
;
926 // The wxPrintData paper size overrides these values, unless the size cannot
928 CalculatePaperSizeFromId();
931 wxPageSetupDialogData::~wxPageSetupDialogData()
933 #if defined(__WIN95__) && defined(__WXMSW__)
934 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
935 if ( pd
&& pd
->hDevMode
)
936 GlobalFree(pd
->hDevMode
);
942 void wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
944 m_paperSize
= data
.m_paperSize
;
945 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
946 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
947 m_marginTopLeft
= data
.m_marginTopLeft
;
948 m_marginBottomRight
= data
.m_marginBottomRight
;
949 m_defaultMinMargins
= data
.m_defaultMinMargins
;
950 m_enableMargins
= data
.m_enableMargins
;
951 m_enableOrientation
= data
.m_enableOrientation
;
952 m_enablePaper
= data
.m_enablePaper
;
953 m_enablePrinter
= data
.m_enablePrinter
;
954 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
955 m_enableHelp
= data
.m_enableHelp
;
957 m_printData
= data
.m_printData
;
960 void wxPageSetupDialogData::operator=(const wxPrintData
& data
)
965 #if defined(__WIN95__)
966 void wxPageSetupDialogData::ConvertToNative()
968 m_printData
.ConvertToNative();
970 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
972 if ( m_pageSetupData
== NULL
)
974 pd
= new PAGESETUPDLG
;
976 m_pageSetupData
= (void *)pd
;
979 // Pass the devmode data (created in m_printData.ConvertToNative)
980 // to the PRINTDLG structure, since it'll
981 // be needed when PrintDlg is called.
985 GlobalFree(pd
->hDevMode
);
990 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
992 m_printData
.SetNativeData((void*) NULL
);
994 wxASSERT_MSG( (pd
->hDevMode
), "hDevMode must be non-NULL in ConvertToNative!");
996 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
998 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1000 if ( m_defaultMinMargins
)
1001 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
1002 if ( !m_enableMargins
)
1003 pd
->Flags
|= PSD_DISABLEMARGINS
;
1004 if ( !m_enableOrientation
)
1005 pd
->Flags
|= PSD_DISABLEORIENTATION
;
1006 if ( !m_enablePaper
)
1007 pd
->Flags
|= PSD_DISABLEPAPER
;
1008 if ( !m_enablePrinter
)
1009 pd
->Flags
|= PSD_DISABLEPRINTER
;
1010 if ( m_getDefaultInfo
)
1011 pd
->Flags
|= PSD_RETURNDEFAULT
;
1013 pd
->Flags
|= PSD_SHOWHELP
;
1015 // We want the units to be in hundredths of a millimetre
1016 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1018 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
1019 pd
->hwndOwner
=(HWND
)NULL
;
1020 pd
->hDevNames
=(HWND
)NULL
;
1021 pd
->hInstance
=(HINSTANCE
)NULL
;
1023 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
1024 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
1026 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
1027 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
1028 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
1029 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
1031 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
1032 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
1033 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
1034 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
1037 pd
->lpfnPageSetupHook
= NULL
;
1038 pd
->lpfnPagePaintHook
= NULL
;
1039 pd
->hPageSetupTemplate
= NULL
;
1040 pd
->lpPageSetupTemplateName
= NULL
;
1045 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1046 memset(devMode, 0, sizeof(DEVMODE));
1047 devMode->dmSize = sizeof(DEVMODE);
1048 devMode->dmOrientation = m_orientation;
1049 devMode->dmFields = DM_ORIENTATION;
1050 GlobalUnlock(pd->hDevMode);
1055 void wxPageSetupDialogData::ConvertFromNative()
1057 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1061 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1064 if (m_printData
.GetNativeData())
1066 // Make sure we don't leak memory
1067 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1069 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1070 pd
->hDevMode
= NULL
;
1073 m_printData
.ConvertFromNative();
1075 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1077 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
1078 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
1079 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
1080 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
1081 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
1082 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
1083 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
1085 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1086 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
1088 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
1089 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
1090 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
1091 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
1093 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100 ;
1094 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100 ;
1095 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100 ;
1096 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100 ;
1099 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1101 if ( m_pageSetupData
== NULL
)
1104 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1106 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1107 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1112 // If a corresponding paper type is found in the paper database, will set the m_printData
1113 // paper size id member as well.
1114 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
1118 CalculateIdFromPaperSize();
1121 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1122 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1124 m_printData
.SetPaperId(id
);
1126 CalculatePaperSizeFromId();
1129 // Use paper size defined in this object to set the wxPrintData
1131 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1133 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1134 "wxThePrintPaperDatabase should not be NULL. "
1135 "Do not create global print dialog data objects." );
1137 wxSize sz
= GetPaperSize();
1139 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1140 if (id
!= wxPAPER_NONE
)
1142 m_printData
.SetPaperId(id
);
1146 // Use paper id in wxPrintData to set this object's paper size
1147 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1149 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1150 "wxThePrintPaperDatabase should not be NULL. "
1151 "Do not create global print dialog data objects." );
1153 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
1157 // sz is in 10ths of a mm, so multiply by 10.
1158 m_paperSize
.x
= sz
.x
* 10;
1159 m_paperSize
.y
= sz
.y
* 10;