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__)
64 #if defined(__WATCOMC__) || defined(__SC__) || defined(__SALFORDC__)
70 #if !USE_SHARED_LIBRARY
71 #if wxUSE_PRINTING_ARCHITECTURE
72 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
73 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
74 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
75 #endif // wxUSE_PRINTING_ARCHITECTURE
76 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
77 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
80 // ============================================================================
82 // ============================================================================
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 wxColourData::wxColourData()
91 for (i
= 0; i
< 16; i
++)
92 custColours
[i
].Set(255, 255, 255);
95 dataColour
.Set(0,0,0);
98 wxColourData::wxColourData(const wxColourData
& data
)
103 wxColourData::~wxColourData()
107 void wxColourData::SetCustomColour(int i
, wxColour
& colour
)
112 custColours
[i
] = colour
;
115 wxColour
wxColourData::GetCustomColour(int i
)
118 return wxColour(0,0,0);
120 return custColours
[i
];
123 void wxColourData::operator=(const wxColourData
& data
)
126 for (i
= 0; i
< 16; i
++)
127 custColours
[i
] = data
.custColours
[i
];
129 dataColour
= (wxColour
&)data
.dataColour
;
130 chooseFull
= data
.chooseFull
;
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 wxFontData::wxFontData()
139 // Intialize colour to black.
140 fontColour
.Set(0, 0, 0);
144 enableEffects
= TRUE
;
149 wxFontData::wxFontData(const wxFontData
& data
)
154 wxFontData::~wxFontData()
158 void wxFontData::operator=(const wxFontData
& data
)
160 fontColour
= data
.fontColour
;
161 showHelp
= data
.showHelp
;
162 allowSymbols
= data
.allowSymbols
;
163 enableEffects
= data
.enableEffects
;
164 initialFont
= data
.initialFont
;
165 chosenFont
= data
.chosenFont
;
166 minSize
= data
.minSize
;
167 maxSize
= data
.maxSize
;
170 #if wxUSE_PRINTING_ARCHITECTURE
171 // ----------------------------------------------------------------------------
173 // ----------------------------------------------------------------------------
175 wxPrintData::wxPrintData()
180 m_printOrientation
= wxPORTRAIT
;
182 m_printCollate
= FALSE
;
187 m_duplexMode
= wxDUPLEX_SIMPLEX
;
188 m_printQuality
= wxPRINT_QUALITY_HIGH
;
189 m_paperId
= wxPAPER_A4
;
190 m_paperSize
= wxSize(210, 297);
192 // PostScript-specific data
193 m_printerCommand
= "";
194 m_previewCommand
= "";
195 m_printerOptions
= "";
198 m_printerScaleX
= 1.0;
199 m_printerScaleY
= 1.0;
200 m_printerTranslateX
= 0;
201 m_printerTranslateY
= 0;
202 m_printMode
= wxPRINT_MODE_FILE
;
205 wxPrintData::wxPrintData(const wxPrintData
& printData
)
214 wxPrintData::~wxPrintData()
217 HGLOBAL hDevMode
= (HGLOBAL
) m_devMode
;
219 GlobalFree(hDevMode
);
223 #if defined(__WXMSW__) && defined(__WIN32__)
225 static wxString
wxGetPrintDlgError()
227 DWORD err
= CommDlgExtendedError();
228 wxString msg
= _T("Unknown");
231 case CDERR_FINDRESFAILURE
: msg
= _T("CDERR_FINDRESFAILURE"); break;
232 case CDERR_INITIALIZATION
: msg
= _T("CDERR_INITIALIZATION"); break;
233 case CDERR_LOADRESFAILURE
: msg
= _T("CDERR_LOADRESFAILURE"); break;
234 case CDERR_LOADSTRFAILURE
: msg
= _T("CDERR_LOADSTRFAILURE"); break;
235 case CDERR_LOCKRESFAILURE
: msg
= _T("CDERR_LOCKRESFAILURE"); break;
236 case CDERR_MEMALLOCFAILURE
: msg
= _T("CDERR_MEMALLOCFAILURE"); break;
237 case CDERR_MEMLOCKFAILURE
: msg
= _T("CDERR_MEMLOCKFAILURE"); break;
238 case CDERR_NOHINSTANCE
: msg
= _T("CDERR_NOHINSTANCE"); break;
239 case CDERR_NOHOOK
: msg
= _T("CDERR_NOHOOK"); break;
240 case CDERR_NOTEMPLATE
: msg
= _T("CDERR_NOTEMPLATE"); break;
241 case CDERR_STRUCTSIZE
: msg
= _T("CDERR_STRUCTSIZE"); break;
242 case PDERR_RETDEFFAILURE
: msg
= _T("PDERR_RETDEFFAILURE"); break;
243 case PDERR_PRINTERNOTFOUND
: msg
= _T("PDERR_PRINTERNOTFOUND"); break;
244 case PDERR_PARSEFAILURE
: msg
= _T("PDERR_PARSEFAILURE"); break;
245 case PDERR_NODEVICES
: msg
= _T("PDERR_NODEVICES"); break;
246 case PDERR_NODEFAULTPRN
: msg
= _T("PDERR_NODEFAULTPRN"); break;
247 case PDERR_LOADDRVFAILURE
: msg
= _T("PDERR_LOADDRVFAILURE"); break;
248 case PDERR_INITFAILURE
: msg
= _T("PDERR_INITFAILURE"); break;
249 case PDERR_GETDEVMODEFAIL
: msg
= _T("PDERR_GETDEVMODEFAIL"); break;
250 case PDERR_DNDMMISMATCH
: msg
= _T("PDERR_DNDMMISMATCH"); break;
251 case PDERR_DEFAULTDIFFERENT
: msg
= _T("PDERR_DEFAULTDIFFERENT"); break;
252 case PDERR_CREATEICFAILURE
: msg
= _T("PDERR_CREATEICFAILURE"); break;
260 void wxPrintData::ConvertToNative()
262 HGLOBAL hDevMode
= (HGLOBAL
) 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(_T("Printing error: "));
298 str
+= wxGetPrintDlgError();
305 GlobalFree(pd
->hDevNames
);
306 pd
->hDevNames
= NULL
;
308 hDevMode
= pd
->hDevMode
;
309 m_devMode
= (void*) hDevMode
;
318 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(hDevMode
);
322 devMode
->dmOrientation
= m_printOrientation
;
323 devMode
->dmFields
= DM_ORIENTATION
;
327 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
328 devMode
->dmFields
|= DM_COLLATE
;
330 //// Number of copies
332 devMode
->dmCopies
= m_printNoCopies
;
333 devMode
->dmFields
|= DM_COPIES
;
337 if (m_printerName
!= _T(""))
339 // TODO: make this Unicode compatible
340 int len
= wxMin(31, m_printerName
.Len());
342 for (i
= 0; i
< len
; i
++)
343 devMode
->dmDeviceName
[i
] = m_printerName
.GetChar(i
);
344 devMode
->dmDeviceName
[i
] = 0;
350 devMode
->dmColor
= DMCOLOR_COLOR
;
352 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
354 devMode
->dmFields
|= DM_COLOR
;
358 if (m_paperId
== wxPAPER_NONE
)
360 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
361 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
362 devMode
->dmFields
|= DM_PAPERWIDTH
;
363 devMode
->dmFields
|= DM_PAPERLENGTH
;
367 if (wxThePrintPaperDatabase
)
369 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
372 devMode
->dmPaperSize
= paper
->GetPlatformId();
373 devMode
->dmFields
|= DM_PAPERSIZE
;
381 switch (m_duplexMode
)
383 case wxDUPLEX_HORIZONTAL
: {
384 duplex
= DMDUP_HORIZONTAL
; break;
386 case wxDUPLEX_VERTICAL
: {
387 duplex
= DMDUP_VERTICAL
; break;
390 case wxDUPLEX_SIMPLEX
: {
391 duplex
= DMDUP_SIMPLEX
; break;
394 devMode
->dmDuplex
= duplex
;
395 devMode
->dmFields
|= DM_DUPLEX
;
400 switch (m_printQuality
)
402 case wxPRINT_QUALITY_MEDIUM
: {
403 quality
= DMRES_MEDIUM
; break;
405 case wxPRINT_QUALITY_LOW
: {
406 quality
= DMRES_LOW
; break;
408 case wxPRINT_QUALITY_DRAFT
: {
409 quality
= DMRES_DRAFT
; break;
411 case wxPRINT_QUALITY_HIGH
: {
412 quality
= DMRES_HIGH
; break;
415 quality
= m_printQuality
; break;
418 devMode
->dmPrintQuality
= quality
;
419 devMode
->dmFields
|= DM_PRINTQUALITY
;
421 GlobalUnlock(hDevMode
);
425 void wxPrintData::ConvertFromNative()
427 HGLOBAL hDevMode
= (HGLOBAL
) m_devMode
;
434 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(hDevMode
);
438 if (devMode
->dmFields
& DM_ORIENTATION
)
439 m_printOrientation
= devMode
->dmOrientation
;
443 if (devMode
->dmFields
& DM_COLLATE
)
445 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
446 m_printCollate
= TRUE
;
448 m_printCollate
= FALSE
;
451 //// Number of copies
453 if (devMode
->dmFields
& DM_COPIES
)
455 m_printNoCopies
= devMode
->dmCopies
;
460 if (devMode
->dmDeviceName
[0] != 0)
462 // TODO: make this Unicode compatible
465 while (devMode
->dmDeviceName
[i
] != 0)
467 buf
[i
] = devMode
->dmDeviceName
[i
];
477 if (devMode
->dmFields
& DM_COLOR
)
479 if (devMode
->dmColor
== DMCOLOR_COLOR
)
489 if (devMode
->dmFields
& DM_PAPERSIZE
)
491 if (wxThePrintPaperDatabase
)
493 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
496 m_paperId
= paper
->GetId();
497 m_paperSize
.x
= paper
->GetWidth() / 10 ;
498 m_paperSize
.y
= paper
->GetHeight() / 10 ;
502 // Shouldn't really get here
503 wxFAIL_MSG(_T("Couldn't find paper size in paper database."));
505 m_paperId
= wxPAPER_NONE
;
512 // Shouldn't really get here
513 wxFAIL_MSG(_T("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
515 m_paperId
= wxPAPER_NONE
;
520 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
522 m_paperSize
.x
= devMode
->dmPaperWidth
/ 10;
523 m_paperSize
.y
= devMode
->dmPaperLength
/ 10;
524 m_paperId
= wxPAPER_NONE
;
528 // Shouldn't really get here
529 wxFAIL_MSG(_T("Couldn't find paper size from DEVMODE."));
533 m_paperId
= wxPAPER_NONE
;
539 if (devMode
->dmFields
& DM_DUPLEX
)
541 switch (devMode
->dmDuplex
)
543 case DMDUP_HORIZONTAL
: {
544 m_duplexMode
= wxDUPLEX_HORIZONTAL
; break;
546 case DMDUP_VERTICAL
: {
547 m_duplexMode
= wxDUPLEX_VERTICAL
; break;
550 case DMDUP_SIMPLEX
: {
551 m_duplexMode
= wxDUPLEX_SIMPLEX
; break;
556 m_duplexMode
= wxDUPLEX_SIMPLEX
;
560 if (devMode
->dmFields
& DM_PRINTQUALITY
)
562 switch (devMode
->dmPrintQuality
)
565 m_printQuality
= wxPRINT_QUALITY_MEDIUM
; break;
568 m_printQuality
= wxPRINT_QUALITY_LOW
; break;
571 m_printQuality
= wxPRINT_QUALITY_DRAFT
; break;
574 m_printQuality
= wxPRINT_QUALITY_HIGH
; break;
578 // TODO: if the printer fills in the resolution in DPI, how
579 // will the application know if it's high, low, draft etc.??
580 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
581 m_printQuality
= devMode
->dmPrintQuality
; break;
587 m_printQuality
= wxPRINT_QUALITY_HIGH
;
589 GlobalUnlock(hDevMode
);
595 void wxPrintData::operator=(const wxPrintData
& data
)
597 m_printNoCopies
= data
.m_printNoCopies
;
598 m_printCollate
= data
.m_printCollate
;
599 m_printOrientation
= data
.m_printOrientation
;
600 m_printerName
= data
.m_printerName
;
601 m_colour
= data
.m_colour
;
602 m_duplexMode
= data
.m_duplexMode
;
603 m_printQuality
= data
.m_printQuality
;
604 m_paperId
= data
.m_paperId
;
605 m_paperSize
= data
.m_paperSize
;
607 // PostScript-specific data
608 m_printerCommand
= data
.m_printerCommand
;
609 m_previewCommand
= data
.m_previewCommand
;
610 m_printerOptions
= data
.m_printerOptions
;
611 m_filename
= data
.m_filename
;
612 m_afmPath
= data
.m_afmPath
;
613 m_printerScaleX
= data
.m_printerScaleX
;
614 m_printerScaleY
= data
.m_printerScaleY
;
615 m_printerTranslateX
= data
.m_printerTranslateX
;
616 m_printerTranslateY
= data
.m_printerTranslateY
;
617 m_printMode
= data
.m_printMode
;
621 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
622 void wxPrintData::operator=(const wxPrintSetupData
& setupData
)
624 SetPrinterCommand(setupData
.GetPrinterCommand());
625 SetPreviewCommand(setupData
.GetPrintPreviewCommand());
626 SetPrinterOptions(setupData
.GetPrinterOptions());
629 setupData
.GetPrinterTranslation(& xt
, & yt
);
630 SetPrinterTranslation(xt
, yt
);
633 setupData
.GetPrinterScaling(& xs
, & ys
);
634 SetPrinterScaling(xs
, ys
);
636 SetOrientation(setupData
.GetPrinterOrientation());
637 SetPrintMode((wxPrintMode
) setupData
.GetPrinterMode());
638 SetFontMetricPath(setupData
.GetAFMPath());
639 if (setupData
.GetPaperName() != "")
640 SetPaperId(wxThePrintPaperDatabase
->ConvertNameToId(setupData
.GetPaperName()));
641 SetColour(setupData
.GetColour());
642 SetFilename(setupData
.GetPrinterFile());
644 #endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
647 // ----------------------------------------------------------------------------
649 // ----------------------------------------------------------------------------
651 wxPrintDialogData::wxPrintDialogData()
654 m_printDlgData
= NULL
;
661 m_printAllPages
= FALSE
;
662 m_printCollate
= FALSE
;
663 m_printToFile
= FALSE
;
664 m_printEnableSelection
= FALSE
;
665 m_printEnablePageNumbers
= TRUE
;
666 m_printEnablePrintToFile
= TRUE
;
667 m_printEnableHelp
= FALSE
;
668 m_printSetupDialog
= FALSE
;
671 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
673 (*this) = dialogData
;
676 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
679 m_printDlgData
= NULL
;
686 m_printAllPages
= FALSE
;
687 m_printCollate
= FALSE
;
688 m_printToFile
= FALSE
;
689 m_printEnableSelection
= FALSE
;
690 m_printEnablePageNumbers
= TRUE
;
691 m_printEnablePrintToFile
= TRUE
;
692 m_printEnableHelp
= FALSE
;
693 m_printSetupDialog
= FALSE
;
695 m_printData
= printData
;
698 wxPrintDialogData::~wxPrintDialogData()
701 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
702 if ( pd
&& pd
->hDevMode
)
703 GlobalFree(pd
->hDevMode
);
710 void wxPrintDialogData::ConvertToNative()
712 m_printData
.ConvertToNative();
714 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
719 m_printDlgData
= (void*) pd
;
721 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
723 pd
->lStructSize
= 66 ;
726 pd
->lStructSize
= sizeof(PRINTDLG
);
727 pd
->hwndOwner
= (HWND
)NULL
;
728 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
729 pd
->hDevNames
= NULL
; // Ditto
731 pd
->Flags
= PD_RETURNDEFAULT
;
735 // Pass the devmode data to the PRINTDLG structure, since it'll
736 // be needed when PrintDlg is called.
739 GlobalFree(pd
->hDevMode
);
742 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
744 m_printData
.SetNativeData((void*) NULL
);
746 wxASSERT_MSG( (pd
->hDevMode
), _T("hDevMode must be non-NULL in ConvertToNative!"));
748 pd
->hDC
= (HDC
) NULL
;
749 pd
->nFromPage
= (UINT
)m_printFromPage
;
750 pd
->nToPage
= (UINT
)m_printToPage
;
751 pd
->nMinPage
= (UINT
)m_printMinPage
;
752 pd
->nMaxPage
= (UINT
)m_printMaxPage
;
753 pd
->nCopies
= (UINT
)m_printNoCopies
;
755 pd
->Flags
= PD_RETURNDC
;
758 pd
->lStructSize
= 66 ;
760 pd
->lStructSize
= sizeof( PRINTDLG
);
763 pd
->hwndOwner
=(HWND
)NULL
;
764 pd
->hDevNames
=(HANDLE
)NULL
;
765 pd
->hInstance
=(HINSTANCE
)NULL
;
766 pd
->lCustData
= (LPARAM
) NULL
;
767 pd
->lpfnPrintHook
= NULL
;
768 pd
->lpfnSetupHook
= NULL
;
769 pd
->lpPrintTemplateName
= NULL
;
770 pd
->lpSetupTemplateName
= NULL
;
771 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
772 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
774 if ( m_printAllPages
)
775 pd
->Flags
|= PD_ALLPAGES
;
776 if ( m_printCollate
)
777 pd
->Flags
|= PD_COLLATE
;
779 pd
->Flags
|= PD_PRINTTOFILE
;
780 if ( !m_printEnablePrintToFile
)
781 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
782 if ( !m_printEnableSelection
)
783 pd
->Flags
|= PD_NOSELECTION
;
784 if ( !m_printEnablePageNumbers
)
785 pd
->Flags
|= PD_NOPAGENUMS
;
786 if ( m_printEnableHelp
)
787 pd
->Flags
|= PD_SHOWHELP
;
788 if ( m_printSetupDialog
)
789 pd
->Flags
|= PD_PRINTSETUP
;
792 void wxPrintDialogData::ConvertFromNative()
794 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
798 // Pass the devmode data back to the wxPrintData structure where it really belongs.
801 if (m_printData
.GetNativeData())
803 // Make sure we don't leak memory
804 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
806 m_printData
.SetNativeData((void*) pd
->hDevMode
);
810 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
811 // into wxWindows form.
812 m_printData
.ConvertFromNative();
814 m_printFromPage
= pd
->nFromPage
;
815 m_printToPage
= pd
->nToPage
;
816 m_printMinPage
= pd
->nMinPage
;
817 m_printMaxPage
= pd
->nMaxPage
;
818 m_printNoCopies
= pd
->nCopies
;
820 m_printAllPages
= ((pd
->Flags
& PD_ALLPAGES
) == PD_ALLPAGES
);
821 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
822 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
823 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
824 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
825 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
826 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
827 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
829 /* port is obsolete in WIN32
833 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
835 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
836 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
837 GlobalUnlock(pd->hDevNames);
839 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
845 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
847 if ( m_printDlgData
== NULL
)
850 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
852 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
853 pd
->hwndOwner
=(HWND
) win
->GetHWND();
858 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
860 m_printFromPage
= data
.m_printFromPage
;
861 m_printToPage
= data
.m_printToPage
;
862 m_printMinPage
= data
.m_printMinPage
;
863 m_printMaxPage
= data
.m_printMaxPage
;
864 m_printNoCopies
= data
.m_printNoCopies
;
865 m_printAllPages
= data
.m_printAllPages
;
866 m_printCollate
= data
.m_printCollate
;
867 m_printToFile
= data
.m_printToFile
;
868 m_printEnableSelection
= data
.m_printEnableSelection
;
869 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
870 m_printEnableHelp
= data
.m_printEnableHelp
;
871 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
872 m_printSetupDialog
= data
.m_printSetupDialog
;
874 m_printData
= data
.m_printData
;
877 void wxPrintDialogData::operator=(const wxPrintData
& data
)
882 // ----------------------------------------------------------------------------
883 // wxPageSetupDialogData
884 // ----------------------------------------------------------------------------
886 wxPageSetupDialogData::wxPageSetupDialogData()
888 #if defined(__WIN95__)
889 m_pageSetupData
= NULL
;
891 m_paperSize
= wxSize(0, 0);
893 CalculatePaperSizeFromId();
895 m_minMarginTopLeft
= wxPoint(0, 0);
896 m_minMarginBottomRight
= wxPoint(0, 0);
897 m_marginTopLeft
= wxPoint(0, 0);
898 m_marginBottomRight
= wxPoint(0, 0);
901 m_defaultMinMargins
= FALSE
;
902 m_enableMargins
= TRUE
;
903 m_enableOrientation
= TRUE
;
904 m_enablePaper
= TRUE
;
905 m_enablePrinter
= TRUE
;
906 m_enableHelp
= FALSE
;
907 m_getDefaultInfo
= FALSE
;
910 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
912 (*this) = dialogData
;
915 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
917 #if defined(__WIN95__)
918 m_pageSetupData
= NULL
;
920 m_paperSize
= wxSize(0, 0);
921 m_minMarginTopLeft
= wxPoint(0, 0);
922 m_minMarginBottomRight
= wxPoint(0, 0);
923 m_marginTopLeft
= wxPoint(0, 0);
924 m_marginBottomRight
= wxPoint(0, 0);
927 m_defaultMinMargins
= FALSE
;
928 m_enableMargins
= TRUE
;
929 m_enableOrientation
= TRUE
;
930 m_enablePaper
= TRUE
;
931 m_enablePrinter
= TRUE
;
932 m_enableHelp
= FALSE
;
933 m_getDefaultInfo
= FALSE
;
935 m_printData
= printData
;
937 // The wxPrintData paper size overrides these values, unless the size cannot
939 CalculatePaperSizeFromId();
942 wxPageSetupDialogData::~wxPageSetupDialogData()
944 #if defined(__WIN95__) && defined(__WXMSW__)
945 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
946 if ( pd
&& pd
->hDevMode
)
947 GlobalFree(pd
->hDevMode
);
953 void wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
955 m_paperSize
= data
.m_paperSize
;
956 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
957 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
958 m_marginTopLeft
= data
.m_marginTopLeft
;
959 m_marginBottomRight
= data
.m_marginBottomRight
;
960 m_defaultMinMargins
= data
.m_defaultMinMargins
;
961 m_enableMargins
= data
.m_enableMargins
;
962 m_enableOrientation
= data
.m_enableOrientation
;
963 m_enablePaper
= data
.m_enablePaper
;
964 m_enablePrinter
= data
.m_enablePrinter
;
965 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
966 m_enableHelp
= data
.m_enableHelp
;
968 m_printData
= data
.m_printData
;
971 void wxPageSetupDialogData::operator=(const wxPrintData
& data
)
976 #if defined(__WIN95__)
977 void wxPageSetupDialogData::ConvertToNative()
979 m_printData
.ConvertToNative();
981 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
983 if ( m_pageSetupData
== NULL
)
985 pd
= new PAGESETUPDLG
;
987 m_pageSetupData
= (void *)pd
;
990 // Pass the devmode data (created in m_printData.ConvertToNative)
991 // to the PRINTDLG structure, since it'll
992 // be needed when PrintDlg is called.
996 GlobalFree(pd
->hDevMode
);
1001 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
1003 m_printData
.SetNativeData((void*) NULL
);
1005 wxASSERT_MSG( (pd
->hDevMode
), _T("hDevMode must be non-NULL in ConvertToNative!"));
1007 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1009 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1011 if ( m_defaultMinMargins
)
1012 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
1013 if ( !m_enableMargins
)
1014 pd
->Flags
|= PSD_DISABLEMARGINS
;
1015 if ( !m_enableOrientation
)
1016 pd
->Flags
|= PSD_DISABLEORIENTATION
;
1017 if ( !m_enablePaper
)
1018 pd
->Flags
|= PSD_DISABLEPAPER
;
1019 if ( !m_enablePrinter
)
1020 pd
->Flags
|= PSD_DISABLEPRINTER
;
1021 if ( m_getDefaultInfo
)
1022 pd
->Flags
|= PSD_RETURNDEFAULT
;
1024 pd
->Flags
|= PSD_SHOWHELP
;
1026 // We want the units to be in hundredths of a millimetre
1027 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1029 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
1030 pd
->hwndOwner
=(HWND
)NULL
;
1031 pd
->hDevNames
=(HWND
)NULL
;
1032 pd
->hInstance
=(HINSTANCE
)NULL
;
1034 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
1035 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
1037 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
1038 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
1039 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
1040 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
1042 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
1043 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
1044 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
1045 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
1048 pd
->lpfnPageSetupHook
= NULL
;
1049 pd
->lpfnPagePaintHook
= NULL
;
1050 pd
->hPageSetupTemplate
= NULL
;
1051 pd
->lpPageSetupTemplateName
= NULL
;
1056 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1057 memset(devMode, 0, sizeof(DEVMODE));
1058 devMode->dmSize = sizeof(DEVMODE);
1059 devMode->dmOrientation = m_orientation;
1060 devMode->dmFields = DM_ORIENTATION;
1061 GlobalUnlock(pd->hDevMode);
1066 void wxPageSetupDialogData::ConvertFromNative()
1068 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1072 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1075 if (m_printData
.GetNativeData())
1077 // Make sure we don't leak memory
1078 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1080 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1081 pd
->hDevMode
= NULL
;
1084 m_printData
.ConvertFromNative();
1086 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1088 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
1089 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
1090 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
1091 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
1092 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
1093 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
1094 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
1096 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1097 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
1099 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
1100 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
1101 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
1102 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
1104 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100 ;
1105 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100 ;
1106 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100 ;
1107 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100 ;
1110 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1112 if ( m_pageSetupData
== NULL
)
1115 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1117 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1118 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1123 // If a corresponding paper type is found in the paper database, will set the m_printData
1124 // paper size id member as well.
1125 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
1129 CalculateIdFromPaperSize();
1132 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1133 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1135 m_printData
.SetPaperId(id
);
1137 CalculatePaperSizeFromId();
1140 // Use paper size defined in this object to set the wxPrintData
1142 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1144 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1145 _T("wxThePrintPaperDatabase should not be NULL. "
1146 "Do not create global print dialog data objects.") );
1148 wxSize sz
= GetPaperSize();
1150 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1151 if (id
!= wxPAPER_NONE
)
1153 m_printData
.SetPaperId(id
);
1157 // Use paper id in wxPrintData to set this object's paper size
1158 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1160 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1161 _T("wxThePrintPaperDatabase should not be NULL. "
1162 "Do not create global print dialog data objects.") );
1164 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
1168 // sz is in 10ths of a mm, so multiply by 10.
1169 m_paperSize
.x
= sz
.x
* 10;
1170 m_paperSize
.y
= sz
.y
* 10;
1174 #endif // wxUSE_PRINTING_ARCHITECTURE