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
)
208 wxPrintData::~wxPrintData()
211 HGLOBAL hDevMode
= (HGLOBAL
) m_devMode
;
213 GlobalFree(hDevMode
);
217 #if defined(__WXMSW__) && defined(__WIN32__)
219 static wxString
wxGetPrintDlgError()
221 DWORD err
= CommDlgExtendedError();
222 wxString msg
= "Unknown";
225 case CDERR_FINDRESFAILURE
: msg
= "CDERR_FINDRESFAILURE"; break;
226 case CDERR_INITIALIZATION
: msg
= "CDERR_INITIALIZATION"; break;
227 case CDERR_LOADRESFAILURE
: msg
= "CDERR_LOADRESFAILURE"; break;
228 case CDERR_LOADSTRFAILURE
: msg
= "CDERR_LOADSTRFAILURE"; break;
229 case CDERR_LOCKRESFAILURE
: msg
= "CDERR_LOCKRESFAILURE"; break;
230 case CDERR_MEMALLOCFAILURE
: msg
= "CDERR_MEMALLOCFAILURE"; break;
231 case CDERR_MEMLOCKFAILURE
: msg
= "CDERR_MEMLOCKFAILURE"; break;
232 case CDERR_NOHINSTANCE
: msg
= "CDERR_NOHINSTANCE"; break;
233 case CDERR_NOHOOK
: msg
= "CDERR_NOHOOK"; break;
234 case CDERR_NOTEMPLATE
: msg
= "CDERR_NOTEMPLATE"; break;
235 case CDERR_STRUCTSIZE
: msg
= "CDERR_STRUCTSIZE"; break;
236 case PDERR_RETDEFFAILURE
: msg
= "PDERR_RETDEFFAILURE"; break;
237 case PDERR_PRINTERNOTFOUND
: msg
= "PDERR_PRINTERNOTFOUND"; break;
238 case PDERR_PARSEFAILURE
: msg
= "PDERR_PARSEFAILURE"; break;
239 case PDERR_NODEVICES
: msg
= "PDERR_NODEVICES"; break;
240 case PDERR_NODEFAULTPRN
: msg
= "PDERR_NODEFAULTPRN"; break;
241 case PDERR_LOADDRVFAILURE
: msg
= "PDERR_LOADDRVFAILURE"; break;
242 case PDERR_INITFAILURE
: msg
= "PDERR_INITFAILURE"; break;
243 case PDERR_GETDEVMODEFAIL
: msg
= "PDERR_GETDEVMODEFAIL"; break;
244 case PDERR_DNDMMISMATCH
: msg
= "PDERR_DNDMMISMATCH"; break;
245 case PDERR_DEFAULTDIFFERENT
: msg
= "PDERR_DEFAULTDIFFERENT"; break;
246 case PDERR_CREATEICFAILURE
: msg
= "PDERR_CREATEICFAILURE"; break;
254 void wxPrintData::ConvertToNative()
256 HGLOBAL hDevMode
= (HGLOBAL
) m_devMode
;
259 // Use PRINTDLG as a way of creating a DEVMODE object
260 PRINTDLG
*pd
= new PRINTDLG
;
262 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
265 pd
->lStructSize
= 66 ;
267 memset(pd
, 0, sizeof(PRINTDLG
));
268 pd
->lStructSize
= sizeof(PRINTDLG
);
271 pd
->hwndOwner
= (HWND
)NULL
;
272 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
273 pd
->hDevNames
= NULL
; // Ditto
274 pd
->hInstance
= (HINSTANCE
) wxGetInstance();
276 pd
->Flags
= PD_RETURNDEFAULT
;
279 // Fill out the DEVMODE structure
280 // so we can use it as input in the 'real' PrintDlg
284 GlobalFree(pd
->hDevMode
);
286 GlobalFree(pd
->hDevNames
);
288 pd
->hDevNames
= NULL
;
290 #if defined(__WXDEBUG__) && defined(__WIN32__)
291 wxString
str("Printing error: ");
292 str
+= wxGetPrintDlgError();
299 GlobalFree(pd
->hDevNames
);
300 pd
->hDevNames
= NULL
;
302 hDevMode
= pd
->hDevMode
;
303 m_devMode
= (void*) hDevMode
;
312 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(hDevMode
);
316 devMode
->dmOrientation
= m_printOrientation
;
317 devMode
->dmFields
= DM_ORIENTATION
;
321 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
322 devMode
->dmFields
|= DM_COLLATE
;
324 //// Number of copies
326 devMode
->dmCopies
= m_printNoCopies
;
327 devMode
->dmFields
|= DM_COPIES
;
331 if (m_printerName
!= "")
333 // TODO: make this Unicode compatible
334 int len
= wxMin(31, m_printerName
.Len());
336 for (i
= 0; i
< len
; i
++)
337 devMode
->dmDeviceName
[i
] = m_printerName
.GetChar(i
);
338 devMode
->dmDeviceName
[i
] = 0;
344 devMode
->dmColor
= DMCOLOR_COLOR
;
346 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
348 devMode
->dmFields
|= DM_COLOR
;
352 if (m_paperId
== wxPAPER_NONE
)
354 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
355 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
356 devMode
->dmFields
|= DM_PAPERWIDTH
;
357 devMode
->dmFields
|= DM_PAPERLENGTH
;
361 if (wxThePrintPaperDatabase
)
363 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
366 devMode
->dmPaperSize
= paper
->GetPlatformId();
367 devMode
->dmFields
|= DM_PAPERSIZE
;
375 switch (m_duplexMode
)
377 case wxDUPLEX_HORIZONTAL
: {
378 duplex
= DMDUP_HORIZONTAL
; break;
380 case wxDUPLEX_VERTICAL
: {
381 duplex
= DMDUP_VERTICAL
; break;
384 case wxDUPLEX_SIMPLEX
: {
385 duplex
= DMDUP_SIMPLEX
; break;
388 devMode
->dmDuplex
= duplex
;
389 devMode
->dmFields
|= DM_DUPLEX
;
394 switch (m_printQuality
)
396 case wxPRINT_QUALITY_MEDIUM
: {
397 quality
= DMRES_MEDIUM
; break;
399 case wxPRINT_QUALITY_LOW
: {
400 quality
= DMRES_LOW
; break;
402 case wxPRINT_QUALITY_DRAFT
: {
403 quality
= DMRES_DRAFT
; break;
405 case wxPRINT_QUALITY_HIGH
: {
406 quality
= DMRES_HIGH
; break;
409 quality
= m_printQuality
; break;
412 devMode
->dmPrintQuality
= quality
;
413 devMode
->dmFields
|= DM_PRINTQUALITY
;
415 GlobalUnlock(hDevMode
);
419 void wxPrintData::ConvertFromNative()
421 HGLOBAL hDevMode
= (HGLOBAL
) m_devMode
;
428 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(hDevMode
);
432 if (devMode
->dmFields
& DM_ORIENTATION
)
433 m_printOrientation
= devMode
->dmOrientation
;
437 if (devMode
->dmFields
& DM_COLLATE
)
439 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
440 m_printCollate
= TRUE
;
442 m_printCollate
= FALSE
;
445 //// Number of copies
447 if (devMode
->dmFields
& DM_COPIES
)
449 m_printNoCopies
= devMode
->dmCopies
;
454 if (devMode
->dmDeviceName
[0] != 0)
456 // TODO: make this Unicode compatible
459 while (devMode
->dmDeviceName
[i
] != 0)
461 buf
[i
] = devMode
->dmDeviceName
[i
];
471 if (devMode
->dmFields
& DM_COLOR
)
473 if (devMode
->dmColor
== DMCOLOR_COLOR
)
483 if (devMode
->dmFields
& DM_PAPERSIZE
)
485 if (wxThePrintPaperDatabase
)
487 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
490 m_paperId
= paper
->GetId();
491 m_paperSize
.x
= paper
->GetWidth() / 10 ;
492 m_paperSize
.y
= paper
->GetHeight() / 10 ;
496 // Shouldn't really get here
497 wxFAIL_MSG("Couldn't find paper size in paper database.");
499 m_paperId
= wxPAPER_NONE
;
506 // Shouldn't really get here
507 wxFAIL_MSG("Paper database wasn't initialized in wxPrintData::ConvertFromNative.");
509 m_paperId
= wxPAPER_NONE
;
514 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
516 m_paperSize
.x
= devMode
->dmPaperWidth
/ 10;
517 m_paperSize
.y
= devMode
->dmPaperLength
/ 10;
518 m_paperId
= wxPAPER_NONE
;
522 // Shouldn't really get here
523 wxFAIL_MSG("Couldn't find paper size from DEVMODE.");
527 m_paperId
= wxPAPER_NONE
;
533 if (devMode
->dmFields
& DM_DUPLEX
)
535 switch (devMode
->dmDuplex
)
537 case DMDUP_HORIZONTAL
: {
538 m_duplexMode
= wxDUPLEX_HORIZONTAL
; break;
540 case DMDUP_VERTICAL
: {
541 m_duplexMode
= wxDUPLEX_VERTICAL
; break;
544 case DMDUP_SIMPLEX
: {
545 m_duplexMode
= wxDUPLEX_SIMPLEX
; break;
550 m_duplexMode
= wxDUPLEX_SIMPLEX
;
554 if (devMode
->dmFields
& DM_PRINTQUALITY
)
556 switch (devMode
->dmPrintQuality
)
559 m_printQuality
= wxPRINT_QUALITY_MEDIUM
; break;
562 m_printQuality
= wxPRINT_QUALITY_LOW
; break;
565 m_printQuality
= wxPRINT_QUALITY_DRAFT
; break;
568 m_printQuality
= wxPRINT_QUALITY_HIGH
; break;
572 // TODO: if the printer fills in the resolution in DPI, how
573 // will the application know if it's high, low, draft etc.??
574 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
575 m_printQuality
= devMode
->dmPrintQuality
; break;
581 m_printQuality
= wxPRINT_QUALITY_HIGH
;
583 GlobalUnlock(hDevMode
);
589 void wxPrintData::operator=(const wxPrintData
& data
)
591 m_printNoCopies
= data
.m_printNoCopies
;
592 m_printCollate
= data
.m_printCollate
;
593 m_printOrientation
= data
.m_printOrientation
;
594 m_printerName
= data
.m_printerName
;
595 m_colour
= data
.m_colour
;
596 m_duplexMode
= data
.m_duplexMode
;
597 m_printQuality
= data
.m_printQuality
;
598 m_paperId
= data
.m_paperId
;
599 m_paperSize
= data
.m_paperSize
;
601 // PostScript-specific data
602 m_printerCommand
= data
.m_printerCommand
;
603 m_previewCommand
= data
.m_previewCommand
;
604 m_printerOptions
= data
.m_printerOptions
;
605 m_filename
= data
.m_filename
;
606 m_afmPath
= data
.m_afmPath
;
607 m_printerScaleX
= data
.m_printerScaleX
;
608 m_printerScaleY
= data
.m_printerScaleY
;
609 m_printerTranslateX
= data
.m_printerTranslateX
;
610 m_printerTranslateY
= data
.m_printerTranslateY
;
611 m_printMode
= data
.m_printMode
;
615 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
616 void wxPrintData::operator=(const wxPrintSetupData
& setupData
)
618 SetPrinterCommand(setupData
.GetPrinterCommand());
619 SetPreviewCommand(setupData
.GetPrintPreviewCommand());
620 SetPrinterOptions(setupData
.GetPrinterOptions());
623 setupData
.GetPrinterTranslation(& xt
, & yt
);
624 SetPrinterTranslation(xt
, yt
);
627 setupData
.GetPrinterScaling(& xs
, & ys
);
628 SetPrinterScaling(xs
, ys
);
630 SetOrientation(setupData
.GetPrinterOrientation());
631 SetPrintMode((wxPrintMode
) setupData
.GetPrinterMode());
632 SetFontMetricPath(setupData
.GetAFMPath());
633 if (setupData
.GetPaperName() != "")
634 SetPaperId(wxThePrintPaperDatabase
->ConvertNameToId(setupData
.GetPaperName()));
635 SetColour(setupData
.GetColour());
636 SetFilename(setupData
.GetPrinterFile());
638 #endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
641 // ----------------------------------------------------------------------------
643 // ----------------------------------------------------------------------------
645 wxPrintDialogData::wxPrintDialogData()
648 m_printDlgData
= NULL
;
655 m_printAllPages
= FALSE
;
656 m_printCollate
= FALSE
;
657 m_printToFile
= FALSE
;
658 m_printEnableSelection
= FALSE
;
659 m_printEnablePageNumbers
= TRUE
;
660 m_printEnablePrintToFile
= TRUE
;
661 m_printEnableHelp
= FALSE
;
662 m_printSetupDialog
= FALSE
;
665 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
667 (*this) = dialogData
;
670 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
673 m_printDlgData
= NULL
;
680 m_printAllPages
= FALSE
;
681 m_printCollate
= FALSE
;
682 m_printToFile
= FALSE
;
683 m_printEnableSelection
= FALSE
;
684 m_printEnablePageNumbers
= TRUE
;
685 m_printEnablePrintToFile
= TRUE
;
686 m_printEnableHelp
= FALSE
;
687 m_printSetupDialog
= FALSE
;
689 m_printData
= printData
;
692 wxPrintDialogData::~wxPrintDialogData()
695 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
696 if ( pd
&& pd
->hDevMode
)
697 GlobalFree(pd
->hDevMode
);
704 void wxPrintDialogData::ConvertToNative()
706 m_printData
.ConvertToNative();
708 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
713 m_printDlgData
= (void*) pd
;
715 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
717 pd
->lStructSize
= 66 ;
720 pd
->lStructSize
= sizeof(PRINTDLG
);
721 pd
->hwndOwner
= (HWND
)NULL
;
722 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
723 pd
->hDevNames
= NULL
; // Ditto
725 pd
->Flags
= PD_RETURNDEFAULT
;
729 // Pass the devmode data to the PRINTDLG structure, since it'll
730 // be needed when PrintDlg is called.
733 GlobalFree(pd
->hDevMode
);
736 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
738 m_printData
.SetNativeData((void*) NULL
);
740 wxASSERT_MSG( (pd
->hDevMode
), "hDevMode must be non-NULL in ConvertToNative!");
742 pd
->hDC
= (HDC
) NULL
;
743 pd
->nFromPage
= (UINT
)m_printFromPage
;
744 pd
->nToPage
= (UINT
)m_printToPage
;
745 pd
->nMinPage
= (UINT
)m_printMinPage
;
746 pd
->nMaxPage
= (UINT
)m_printMaxPage
;
747 pd
->nCopies
= (UINT
)m_printNoCopies
;
749 pd
->Flags
= PD_RETURNDC
;
752 pd
->lStructSize
= 66 ;
754 pd
->lStructSize
= sizeof( PRINTDLG
);
757 pd
->hwndOwner
=(HWND
)NULL
;
758 pd
->hDevNames
=(HANDLE
)NULL
;
759 pd
->hInstance
=(HINSTANCE
)NULL
;
760 pd
->lCustData
= (LPARAM
) NULL
;
761 pd
->lpfnPrintHook
= NULL
;
762 pd
->lpfnSetupHook
= NULL
;
763 pd
->lpPrintTemplateName
= NULL
;
764 pd
->lpSetupTemplateName
= NULL
;
765 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
766 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
768 if ( m_printAllPages
)
769 pd
->Flags
|= PD_ALLPAGES
;
770 if ( m_printCollate
)
771 pd
->Flags
|= PD_COLLATE
;
773 pd
->Flags
|= PD_PRINTTOFILE
;
774 if ( !m_printEnablePrintToFile
)
775 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
776 if ( !m_printEnableSelection
)
777 pd
->Flags
|= PD_NOSELECTION
;
778 if ( !m_printEnablePageNumbers
)
779 pd
->Flags
|= PD_NOPAGENUMS
;
780 if ( m_printEnableHelp
)
781 pd
->Flags
|= PD_SHOWHELP
;
782 if ( m_printSetupDialog
)
783 pd
->Flags
|= PD_PRINTSETUP
;
786 void wxPrintDialogData::ConvertFromNative()
788 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
792 // Pass the devmode data back to the wxPrintData structure where it really belongs.
795 if (m_printData
.GetNativeData())
797 // Make sure we don't leak memory
798 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
800 m_printData
.SetNativeData((void*) pd
->hDevMode
);
804 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
805 // into wxWindows form.
806 m_printData
.ConvertFromNative();
808 m_printFromPage
= pd
->nFromPage
;
809 m_printToPage
= pd
->nToPage
;
810 m_printMinPage
= pd
->nMinPage
;
811 m_printMaxPage
= pd
->nMaxPage
;
812 m_printNoCopies
= pd
->nCopies
;
814 m_printAllPages
= ((pd
->Flags
& PD_ALLPAGES
) == PD_ALLPAGES
);
815 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
816 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
817 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
818 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
819 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
820 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
821 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
823 /* port is obsolete in WIN32
827 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
829 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
830 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
831 GlobalUnlock(pd->hDevNames);
833 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
839 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
841 if ( m_printDlgData
== NULL
)
844 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
846 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
847 pd
->hwndOwner
=(HWND
) win
->GetHWND();
852 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
854 m_printFromPage
= data
.m_printFromPage
;
855 m_printToPage
= data
.m_printToPage
;
856 m_printMinPage
= data
.m_printMinPage
;
857 m_printMaxPage
= data
.m_printMaxPage
;
858 m_printNoCopies
= data
.m_printNoCopies
;
859 m_printAllPages
= data
.m_printAllPages
;
860 m_printCollate
= data
.m_printCollate
;
861 m_printToFile
= data
.m_printToFile
;
862 m_printEnableSelection
= data
.m_printEnableSelection
;
863 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
864 m_printEnableHelp
= data
.m_printEnableHelp
;
865 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
866 m_printSetupDialog
= data
.m_printSetupDialog
;
868 m_printData
= data
.m_printData
;
871 void wxPrintDialogData::operator=(const wxPrintData
& data
)
876 // ----------------------------------------------------------------------------
877 // wxPageSetupDialogData
878 // ----------------------------------------------------------------------------
880 wxPageSetupDialogData::wxPageSetupDialogData()
882 #if defined(__WIN95__)
883 m_pageSetupData
= NULL
;
885 m_paperSize
= wxSize(0, 0);
887 CalculatePaperSizeFromId();
889 m_minMarginTopLeft
= wxPoint(0, 0);
890 m_minMarginBottomRight
= wxPoint(0, 0);
891 m_marginTopLeft
= wxPoint(0, 0);
892 m_marginBottomRight
= wxPoint(0, 0);
895 m_defaultMinMargins
= FALSE
;
896 m_enableMargins
= TRUE
;
897 m_enableOrientation
= TRUE
;
898 m_enablePaper
= TRUE
;
899 m_enablePrinter
= TRUE
;
900 m_enableHelp
= FALSE
;
901 m_getDefaultInfo
= FALSE
;
904 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
906 (*this) = dialogData
;
909 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
911 #if defined(__WIN95__)
912 m_pageSetupData
= NULL
;
914 m_paperSize
= wxSize(0, 0);
915 m_minMarginTopLeft
= wxPoint(0, 0);
916 m_minMarginBottomRight
= wxPoint(0, 0);
917 m_marginTopLeft
= wxPoint(0, 0);
918 m_marginBottomRight
= wxPoint(0, 0);
921 m_defaultMinMargins
= FALSE
;
922 m_enableMargins
= TRUE
;
923 m_enableOrientation
= TRUE
;
924 m_enablePaper
= TRUE
;
925 m_enablePrinter
= TRUE
;
926 m_enableHelp
= FALSE
;
927 m_getDefaultInfo
= FALSE
;
929 m_printData
= printData
;
931 // The wxPrintData paper size overrides these values, unless the size cannot
933 CalculatePaperSizeFromId();
936 wxPageSetupDialogData::~wxPageSetupDialogData()
938 #if defined(__WIN95__) && defined(__WXMSW__)
939 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
940 if ( pd
&& pd
->hDevMode
)
941 GlobalFree(pd
->hDevMode
);
947 void wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
949 m_paperSize
= data
.m_paperSize
;
950 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
951 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
952 m_marginTopLeft
= data
.m_marginTopLeft
;
953 m_marginBottomRight
= data
.m_marginBottomRight
;
954 m_defaultMinMargins
= data
.m_defaultMinMargins
;
955 m_enableMargins
= data
.m_enableMargins
;
956 m_enableOrientation
= data
.m_enableOrientation
;
957 m_enablePaper
= data
.m_enablePaper
;
958 m_enablePrinter
= data
.m_enablePrinter
;
959 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
960 m_enableHelp
= data
.m_enableHelp
;
962 m_printData
= data
.m_printData
;
965 void wxPageSetupDialogData::operator=(const wxPrintData
& data
)
970 #if defined(__WIN95__)
971 void wxPageSetupDialogData::ConvertToNative()
973 m_printData
.ConvertToNative();
975 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
977 if ( m_pageSetupData
== NULL
)
979 pd
= new PAGESETUPDLG
;
981 m_pageSetupData
= (void *)pd
;
984 // Pass the devmode data (created in m_printData.ConvertToNative)
985 // to the PRINTDLG structure, since it'll
986 // be needed when PrintDlg is called.
990 GlobalFree(pd
->hDevMode
);
995 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
997 m_printData
.SetNativeData((void*) NULL
);
999 wxASSERT_MSG( (pd
->hDevMode
), "hDevMode must be non-NULL in ConvertToNative!");
1001 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1003 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1005 if ( m_defaultMinMargins
)
1006 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
1007 if ( !m_enableMargins
)
1008 pd
->Flags
|= PSD_DISABLEMARGINS
;
1009 if ( !m_enableOrientation
)
1010 pd
->Flags
|= PSD_DISABLEORIENTATION
;
1011 if ( !m_enablePaper
)
1012 pd
->Flags
|= PSD_DISABLEPAPER
;
1013 if ( !m_enablePrinter
)
1014 pd
->Flags
|= PSD_DISABLEPRINTER
;
1015 if ( m_getDefaultInfo
)
1016 pd
->Flags
|= PSD_RETURNDEFAULT
;
1018 pd
->Flags
|= PSD_SHOWHELP
;
1020 // We want the units to be in hundredths of a millimetre
1021 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1023 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
1024 pd
->hwndOwner
=(HWND
)NULL
;
1025 pd
->hDevNames
=(HWND
)NULL
;
1026 pd
->hInstance
=(HINSTANCE
)NULL
;
1028 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
1029 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
1031 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
1032 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
1033 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
1034 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
1036 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
1037 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
1038 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
1039 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
1042 pd
->lpfnPageSetupHook
= NULL
;
1043 pd
->lpfnPagePaintHook
= NULL
;
1044 pd
->hPageSetupTemplate
= NULL
;
1045 pd
->lpPageSetupTemplateName
= NULL
;
1050 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1051 memset(devMode, 0, sizeof(DEVMODE));
1052 devMode->dmSize = sizeof(DEVMODE);
1053 devMode->dmOrientation = m_orientation;
1054 devMode->dmFields = DM_ORIENTATION;
1055 GlobalUnlock(pd->hDevMode);
1060 void wxPageSetupDialogData::ConvertFromNative()
1062 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1066 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1069 if (m_printData
.GetNativeData())
1071 // Make sure we don't leak memory
1072 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1074 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1075 pd
->hDevMode
= NULL
;
1078 m_printData
.ConvertFromNative();
1080 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1082 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
1083 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
1084 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
1085 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
1086 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
1087 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
1088 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
1090 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1091 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
1093 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
1094 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
1095 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
1096 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
1098 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100 ;
1099 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100 ;
1100 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100 ;
1101 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100 ;
1104 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1106 if ( m_pageSetupData
== NULL
)
1109 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1111 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1112 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1117 // If a corresponding paper type is found in the paper database, will set the m_printData
1118 // paper size id member as well.
1119 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
1123 CalculateIdFromPaperSize();
1126 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1127 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1129 m_printData
.SetPaperId(id
);
1131 CalculatePaperSizeFromId();
1134 // Use paper size defined in this object to set the wxPrintData
1136 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1138 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1139 _T("wxThePrintPaperDatabase should not be NULL. "
1140 "Do not create global print dialog data objects.") );
1142 wxSize sz
= GetPaperSize();
1144 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1145 if (id
!= wxPAPER_NONE
)
1147 m_printData
.SetPaperId(id
);
1151 // Use paper id in wxPrintData to set this object's paper size
1152 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1154 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1155 _T("wxThePrintPaperDatabase should not be NULL. "
1156 "Do not create global print dialog data objects.") );
1158 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
1162 // sz is in 10ths of a mm, so multiply by 10.
1163 m_paperSize
.x
= sz
.x
* 10;
1164 m_paperSize
.y
= sz
.y
* 10;