1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI data
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "cmndata.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/string.h"
38 #include "wx/gdicmn.h"
39 #include "wx/cmndata.h"
43 #if (defined(__WXMOTIF__) || defined(__WXGTK__)) && wxUSE_POSTSCRIPT
44 #define wxCOMPATIBILITY_WITH_PRINTSETUPDATA 1
47 #if wxUSE_PRINTING_ARCHITECTURE
50 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
51 #include "wx/generic/dcpsg.h"
53 #endif // wxUSE_PRINTING_ARCHITECTURE
57 #include <wx/msw/private.h>
59 #if !defined(__WIN32__)
69 #if defined(__WATCOMC__) || defined(__SC__) || defined(__SALFORDC__)
75 #if !USE_SHARED_LIBRARY
76 #if wxUSE_PRINTING_ARCHITECTURE
77 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
78 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
79 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
80 #endif // wxUSE_PRINTING_ARCHITECTURE
81 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
82 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
85 // ============================================================================
87 // ============================================================================
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 wxColourData::wxColourData()
96 for (i
= 0; i
< 16; i
++)
97 custColours
[i
].Set(255, 255, 255);
100 dataColour
.Set(0,0,0);
103 wxColourData::wxColourData(const wxColourData
& data
)
108 wxColourData::~wxColourData()
112 void wxColourData::SetCustomColour(int i
, wxColour
& colour
)
117 custColours
[i
] = colour
;
120 wxColour
wxColourData::GetCustomColour(int i
)
123 return wxColour(0,0,0);
125 return custColours
[i
];
128 void wxColourData::operator=(const wxColourData
& data
)
131 for (i
= 0; i
< 16; i
++)
132 custColours
[i
] = data
.custColours
[i
];
134 dataColour
= (wxColour
&)data
.dataColour
;
135 chooseFull
= data
.chooseFull
;
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 wxFontData::wxFontData()
144 // Intialize colour to black.
145 fontColour
.Set(0, 0, 0);
149 enableEffects
= TRUE
;
154 wxFontData::wxFontData(const wxFontData
& data
)
159 wxFontData::~wxFontData()
163 void wxFontData::operator=(const wxFontData
& data
)
165 fontColour
= data
.fontColour
;
166 showHelp
= data
.showHelp
;
167 allowSymbols
= data
.allowSymbols
;
168 enableEffects
= data
.enableEffects
;
169 initialFont
= data
.initialFont
;
170 chosenFont
= data
.chosenFont
;
171 minSize
= data
.minSize
;
172 maxSize
= data
.maxSize
;
175 #if wxUSE_PRINTING_ARCHITECTURE
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
180 wxPrintData::wxPrintData()
185 m_printOrientation
= wxPORTRAIT
;
187 m_printCollate
= FALSE
;
192 m_duplexMode
= wxDUPLEX_SIMPLEX
;
193 m_printQuality
= wxPRINT_QUALITY_HIGH
;
194 m_paperId
= wxPAPER_A4
;
195 m_paperSize
= wxSize(210, 297);
197 // PostScript-specific data
198 m_printerCommand
= "";
199 m_previewCommand
= "";
200 m_printerOptions
= "";
203 m_printerScaleX
= 1.0;
204 m_printerScaleY
= 1.0;
205 m_printerTranslateX
= 0;
206 m_printerTranslateY
= 0;
207 m_printMode
= wxPRINT_MODE_FILE
;
210 wxPrintData::wxPrintData(const wxPrintData
& printData
)
219 wxPrintData::~wxPrintData()
222 HGLOBAL hDevMode
= (HGLOBAL
) m_devMode
;
224 GlobalFree(hDevMode
);
228 #if defined(__WXMSW__) && defined(__WIN32__)
230 static wxString
wxGetPrintDlgError()
232 DWORD err
= CommDlgExtendedError();
233 wxString msg
= _T("Unknown");
236 case CDERR_FINDRESFAILURE
: msg
= _T("CDERR_FINDRESFAILURE"); break;
237 case CDERR_INITIALIZATION
: msg
= _T("CDERR_INITIALIZATION"); break;
238 case CDERR_LOADRESFAILURE
: msg
= _T("CDERR_LOADRESFAILURE"); break;
239 case CDERR_LOADSTRFAILURE
: msg
= _T("CDERR_LOADSTRFAILURE"); break;
240 case CDERR_LOCKRESFAILURE
: msg
= _T("CDERR_LOCKRESFAILURE"); break;
241 case CDERR_MEMALLOCFAILURE
: msg
= _T("CDERR_MEMALLOCFAILURE"); break;
242 case CDERR_MEMLOCKFAILURE
: msg
= _T("CDERR_MEMLOCKFAILURE"); break;
243 case CDERR_NOHINSTANCE
: msg
= _T("CDERR_NOHINSTANCE"); break;
244 case CDERR_NOHOOK
: msg
= _T("CDERR_NOHOOK"); break;
245 case CDERR_NOTEMPLATE
: msg
= _T("CDERR_NOTEMPLATE"); break;
246 case CDERR_STRUCTSIZE
: msg
= _T("CDERR_STRUCTSIZE"); break;
247 case PDERR_RETDEFFAILURE
: msg
= _T("PDERR_RETDEFFAILURE"); break;
248 case PDERR_PRINTERNOTFOUND
: msg
= _T("PDERR_PRINTERNOTFOUND"); break;
249 case PDERR_PARSEFAILURE
: msg
= _T("PDERR_PARSEFAILURE"); break;
250 case PDERR_NODEVICES
: msg
= _T("PDERR_NODEVICES"); break;
251 case PDERR_NODEFAULTPRN
: msg
= _T("PDERR_NODEFAULTPRN"); break;
252 case PDERR_LOADDRVFAILURE
: msg
= _T("PDERR_LOADDRVFAILURE"); break;
253 case PDERR_INITFAILURE
: msg
= _T("PDERR_INITFAILURE"); break;
254 case PDERR_GETDEVMODEFAIL
: msg
= _T("PDERR_GETDEVMODEFAIL"); break;
255 case PDERR_DNDMMISMATCH
: msg
= _T("PDERR_DNDMMISMATCH"); break;
256 case PDERR_DEFAULTDIFFERENT
: msg
= _T("PDERR_DEFAULTDIFFERENT"); break;
257 case PDERR_CREATEICFAILURE
: msg
= _T("PDERR_CREATEICFAILURE"); break;
265 void wxPrintData::ConvertToNative()
267 HGLOBAL hDevMode
= (HGLOBAL
) m_devMode
;
270 // Use PRINTDLG as a way of creating a DEVMODE object
271 PRINTDLG
*pd
= new PRINTDLG
;
273 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
276 pd
->lStructSize
= 66 ;
278 memset(pd
, 0, sizeof(PRINTDLG
));
279 pd
->lStructSize
= sizeof(PRINTDLG
);
282 pd
->hwndOwner
= (HWND
)NULL
;
283 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
284 pd
->hDevNames
= NULL
; // Ditto
285 pd
->hInstance
= (HINSTANCE
) wxGetInstance();
287 pd
->Flags
= PD_RETURNDEFAULT
;
290 // Fill out the DEVMODE structure
291 // so we can use it as input in the 'real' PrintDlg
295 GlobalFree(pd
->hDevMode
);
297 GlobalFree(pd
->hDevNames
);
299 pd
->hDevNames
= NULL
;
301 #if defined(__WXDEBUG__) && defined(__WIN32__)
302 wxString
str(_T("Printing error: "));
303 str
+= wxGetPrintDlgError();
310 GlobalFree(pd
->hDevNames
);
311 pd
->hDevNames
= NULL
;
313 hDevMode
= pd
->hDevMode
;
314 m_devMode
= (void*) hDevMode
;
323 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(hDevMode
);
328 devMode
->dmOrientation
= m_printOrientation
;
330 devMode
->dmFields
= DM_ORIENTATION
;
334 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
335 devMode
->dmFields
|= DM_COLLATE
;
337 //// Number of copies
339 devMode
->dmCopies
= m_printNoCopies
;
340 devMode
->dmFields
|= DM_COPIES
;
344 if (m_printerName
!= _T(""))
346 // TODO: make this Unicode compatible
347 int len
= wxMin(31, m_printerName
.Len());
349 for (i
= 0; i
< len
; i
++)
350 devMode
->dmDeviceName
[i
] = m_printerName
.GetChar(i
);
351 devMode
->dmDeviceName
[i
] = 0;
357 devMode
->dmColor
= DMCOLOR_COLOR
;
359 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
361 devMode
->dmFields
|= DM_COLOR
;
366 if (m_paperId
== wxPAPER_NONE
)
368 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
369 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
370 devMode
->dmFields
|= DM_PAPERWIDTH
;
371 devMode
->dmFields
|= DM_PAPERLENGTH
;
375 if (wxThePrintPaperDatabase
)
377 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
380 devMode
->dmPaperSize
= paper
->GetPlatformId();
381 devMode
->dmFields
|= DM_PAPERSIZE
;
390 switch (m_duplexMode
)
392 case wxDUPLEX_HORIZONTAL
: {
393 duplex
= DMDUP_HORIZONTAL
; break;
395 case wxDUPLEX_VERTICAL
: {
396 duplex
= DMDUP_VERTICAL
; break;
399 case wxDUPLEX_SIMPLEX
: {
400 duplex
= DMDUP_SIMPLEX
; break;
403 devMode
->dmDuplex
= duplex
;
404 devMode
->dmFields
|= DM_DUPLEX
;
409 switch (m_printQuality
)
411 case wxPRINT_QUALITY_MEDIUM
: {
412 quality
= DMRES_MEDIUM
; break;
414 case wxPRINT_QUALITY_LOW
: {
415 quality
= DMRES_LOW
; break;
417 case wxPRINT_QUALITY_DRAFT
: {
418 quality
= DMRES_DRAFT
; break;
420 case wxPRINT_QUALITY_HIGH
: {
421 quality
= DMRES_HIGH
; break;
424 quality
= m_printQuality
; break;
427 devMode
->dmPrintQuality
= quality
;
428 devMode
->dmFields
|= DM_PRINTQUALITY
;
430 GlobalUnlock(hDevMode
);
434 void wxPrintData::ConvertFromNative()
436 HGLOBAL hDevMode
= (HGLOBAL
) m_devMode
;
443 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(hDevMode
);
448 if (devMode
->dmFields
& DM_ORIENTATION
)
449 m_printOrientation
= devMode
->dmOrientation
;
454 if (devMode
->dmFields
& DM_COLLATE
)
456 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
457 m_printCollate
= TRUE
;
459 m_printCollate
= FALSE
;
462 //// Number of copies
464 if (devMode
->dmFields
& DM_COPIES
)
466 m_printNoCopies
= devMode
->dmCopies
;
471 if (devMode
->dmDeviceName
[0] != 0)
473 // TODO: make this Unicode compatible
476 while (devMode
->dmDeviceName
[i
] != 0)
478 buf
[i
] = devMode
->dmDeviceName
[i
];
488 if (devMode
->dmFields
& DM_COLOR
)
490 if (devMode
->dmColor
== DMCOLOR_COLOR
)
501 if (devMode
->dmFields
& DM_PAPERSIZE
)
503 if (wxThePrintPaperDatabase
)
505 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
508 m_paperId
= paper
->GetId();
509 m_paperSize
.x
= paper
->GetWidth() / 10 ;
510 m_paperSize
.y
= paper
->GetHeight() / 10 ;
514 // Shouldn't really get here
515 wxFAIL_MSG(_T("Couldn't find paper size in paper database."));
517 m_paperId
= wxPAPER_NONE
;
524 // Shouldn't really get here
525 wxFAIL_MSG(_T("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
527 m_paperId
= wxPAPER_NONE
;
532 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
534 m_paperSize
.x
= devMode
->dmPaperWidth
/ 10;
535 m_paperSize
.y
= devMode
->dmPaperLength
/ 10;
536 m_paperId
= wxPAPER_NONE
;
540 // Shouldn't really get here
541 wxFAIL_MSG(_T("Couldn't find paper size from DEVMODE."));
545 m_paperId
= wxPAPER_NONE
;
551 if (devMode
->dmFields
& DM_DUPLEX
)
553 switch (devMode
->dmDuplex
)
555 case DMDUP_HORIZONTAL
: {
556 m_duplexMode
= wxDUPLEX_HORIZONTAL
; break;
558 case DMDUP_VERTICAL
: {
559 m_duplexMode
= wxDUPLEX_VERTICAL
; break;
562 case DMDUP_SIMPLEX
: {
563 m_duplexMode
= wxDUPLEX_SIMPLEX
; break;
568 m_duplexMode
= wxDUPLEX_SIMPLEX
;
572 if (devMode
->dmFields
& DM_PRINTQUALITY
)
574 switch (devMode
->dmPrintQuality
)
577 m_printQuality
= wxPRINT_QUALITY_MEDIUM
; break;
580 m_printQuality
= wxPRINT_QUALITY_LOW
; break;
583 m_printQuality
= wxPRINT_QUALITY_DRAFT
; break;
586 m_printQuality
= wxPRINT_QUALITY_HIGH
; break;
590 // TODO: if the printer fills in the resolution in DPI, how
591 // will the application know if it's high, low, draft etc.??
592 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
593 m_printQuality
= devMode
->dmPrintQuality
; break;
599 m_printQuality
= wxPRINT_QUALITY_HIGH
;
601 GlobalUnlock(hDevMode
);
607 void wxPrintData::operator=(const wxPrintData
& data
)
609 m_printNoCopies
= data
.m_printNoCopies
;
610 m_printCollate
= data
.m_printCollate
;
611 m_printOrientation
= data
.m_printOrientation
;
612 m_printerName
= data
.m_printerName
;
613 m_colour
= data
.m_colour
;
614 m_duplexMode
= data
.m_duplexMode
;
615 m_printQuality
= data
.m_printQuality
;
616 m_paperId
= data
.m_paperId
;
617 m_paperSize
= data
.m_paperSize
;
619 // PostScript-specific data
620 m_printerCommand
= data
.m_printerCommand
;
621 m_previewCommand
= data
.m_previewCommand
;
622 m_printerOptions
= data
.m_printerOptions
;
623 m_filename
= data
.m_filename
;
624 m_afmPath
= data
.m_afmPath
;
625 m_printerScaleX
= data
.m_printerScaleX
;
626 m_printerScaleY
= data
.m_printerScaleY
;
627 m_printerTranslateX
= data
.m_printerTranslateX
;
628 m_printerTranslateY
= data
.m_printerTranslateY
;
629 m_printMode
= data
.m_printMode
;
633 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
634 void wxPrintData::operator=(const wxPrintSetupData
& setupData
)
636 SetPrinterCommand(setupData
.GetPrinterCommand());
637 SetPreviewCommand(setupData
.GetPrintPreviewCommand());
638 SetPrinterOptions(setupData
.GetPrinterOptions());
641 setupData
.GetPrinterTranslation(& xt
, & yt
);
642 SetPrinterTranslation(xt
, yt
);
645 setupData
.GetPrinterScaling(& xs
, & ys
);
646 SetPrinterScaling(xs
, ys
);
648 SetOrientation(setupData
.GetPrinterOrientation());
649 SetPrintMode((wxPrintMode
) setupData
.GetPrinterMode());
650 SetFontMetricPath(setupData
.GetAFMPath());
651 if (setupData
.GetPaperName() != "")
652 SetPaperId(wxThePrintPaperDatabase
->ConvertNameToId(setupData
.GetPaperName()));
653 SetColour(setupData
.GetColour());
654 SetFilename(setupData
.GetPrinterFile());
656 #endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
659 // ----------------------------------------------------------------------------
661 // ----------------------------------------------------------------------------
663 wxPrintDialogData::wxPrintDialogData()
666 m_printDlgData
= NULL
;
673 m_printAllPages
= FALSE
;
674 m_printCollate
= FALSE
;
675 m_printToFile
= FALSE
;
676 m_printEnableSelection
= FALSE
;
677 m_printEnablePageNumbers
= TRUE
;
678 m_printEnablePrintToFile
= TRUE
;
679 m_printEnableHelp
= FALSE
;
680 m_printSetupDialog
= FALSE
;
683 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
685 (*this) = dialogData
;
688 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
691 m_printDlgData
= NULL
;
698 m_printAllPages
= FALSE
;
699 m_printCollate
= FALSE
;
700 m_printToFile
= FALSE
;
701 m_printEnableSelection
= FALSE
;
702 m_printEnablePageNumbers
= TRUE
;
703 m_printEnablePrintToFile
= TRUE
;
704 m_printEnableHelp
= FALSE
;
705 m_printSetupDialog
= FALSE
;
707 m_printData
= printData
;
710 wxPrintDialogData::~wxPrintDialogData()
713 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
714 if ( pd
&& pd
->hDevMode
)
715 GlobalFree(pd
->hDevMode
);
722 void wxPrintDialogData::ConvertToNative()
724 m_printData
.ConvertToNative();
726 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
731 m_printDlgData
= (void*) pd
;
733 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
735 pd
->lStructSize
= 66 ;
738 pd
->lStructSize
= sizeof(PRINTDLG
);
739 pd
->hwndOwner
= (HWND
)NULL
;
740 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
741 pd
->hDevNames
= NULL
; // Ditto
743 pd
->Flags
= PD_RETURNDEFAULT
;
747 // Pass the devmode data to the PRINTDLG structure, since it'll
748 // be needed when PrintDlg is called.
751 GlobalFree(pd
->hDevMode
);
754 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
756 m_printData
.SetNativeData((void*) NULL
);
758 wxASSERT_MSG( (pd
->hDevMode
), _T("hDevMode must be non-NULL in ConvertToNative!"));
760 pd
->hDC
= (HDC
) NULL
;
761 pd
->nFromPage
= (UINT
)m_printFromPage
;
762 pd
->nToPage
= (UINT
)m_printToPage
;
763 pd
->nMinPage
= (UINT
)m_printMinPage
;
764 pd
->nMaxPage
= (UINT
)m_printMaxPage
;
765 pd
->nCopies
= (UINT
)m_printNoCopies
;
767 pd
->Flags
= PD_RETURNDC
;
770 pd
->lStructSize
= 66 ;
772 pd
->lStructSize
= sizeof( PRINTDLG
);
775 pd
->hwndOwner
=(HWND
)NULL
;
776 pd
->hDevNames
=(HANDLE
)NULL
;
777 pd
->hInstance
=(HINSTANCE
)NULL
;
778 pd
->lCustData
= (LPARAM
) NULL
;
779 pd
->lpfnPrintHook
= NULL
;
780 pd
->lpfnSetupHook
= NULL
;
781 pd
->lpPrintTemplateName
= NULL
;
782 pd
->lpSetupTemplateName
= NULL
;
783 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
784 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
786 if ( m_printAllPages
)
787 pd
->Flags
|= PD_ALLPAGES
;
788 if ( m_printCollate
)
789 pd
->Flags
|= PD_COLLATE
;
791 pd
->Flags
|= PD_PRINTTOFILE
;
792 if ( !m_printEnablePrintToFile
)
793 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
794 if ( !m_printEnableSelection
)
795 pd
->Flags
|= PD_NOSELECTION
;
796 if ( !m_printEnablePageNumbers
)
797 pd
->Flags
|= PD_NOPAGENUMS
;
798 if ( m_printEnableHelp
)
799 pd
->Flags
|= PD_SHOWHELP
;
800 if ( m_printSetupDialog
)
801 pd
->Flags
|= PD_PRINTSETUP
;
804 void wxPrintDialogData::ConvertFromNative()
806 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
810 // Pass the devmode data back to the wxPrintData structure where it really belongs.
813 if (m_printData
.GetNativeData())
815 // Make sure we don't leak memory
816 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
818 m_printData
.SetNativeData((void*) pd
->hDevMode
);
822 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
823 // into wxWindows form.
824 m_printData
.ConvertFromNative();
826 m_printFromPage
= pd
->nFromPage
;
827 m_printToPage
= pd
->nToPage
;
828 m_printMinPage
= pd
->nMinPage
;
829 m_printMaxPage
= pd
->nMaxPage
;
830 m_printNoCopies
= pd
->nCopies
;
832 m_printAllPages
= ((pd
->Flags
& PD_ALLPAGES
) == PD_ALLPAGES
);
833 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
834 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
835 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
836 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
837 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
838 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
839 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
841 /* port is obsolete in WIN32
845 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
847 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
848 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
849 GlobalUnlock(pd->hDevNames);
851 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
857 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
859 if ( m_printDlgData
== NULL
)
862 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
864 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
865 pd
->hwndOwner
=(HWND
) win
->GetHWND();
870 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
872 m_printFromPage
= data
.m_printFromPage
;
873 m_printToPage
= data
.m_printToPage
;
874 m_printMinPage
= data
.m_printMinPage
;
875 m_printMaxPage
= data
.m_printMaxPage
;
876 m_printNoCopies
= data
.m_printNoCopies
;
877 m_printAllPages
= data
.m_printAllPages
;
878 m_printCollate
= data
.m_printCollate
;
879 m_printToFile
= data
.m_printToFile
;
880 m_printEnableSelection
= data
.m_printEnableSelection
;
881 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
882 m_printEnableHelp
= data
.m_printEnableHelp
;
883 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
884 m_printSetupDialog
= data
.m_printSetupDialog
;
886 m_printData
= data
.m_printData
;
889 void wxPrintDialogData::operator=(const wxPrintData
& data
)
894 // ----------------------------------------------------------------------------
895 // wxPageSetupDialogData
896 // ----------------------------------------------------------------------------
898 wxPageSetupDialogData::wxPageSetupDialogData()
900 #if defined(__WIN95__)
901 m_pageSetupData
= NULL
;
903 m_paperSize
= wxSize(0, 0);
905 CalculatePaperSizeFromId();
907 m_minMarginTopLeft
= wxPoint(0, 0);
908 m_minMarginBottomRight
= wxPoint(0, 0);
909 m_marginTopLeft
= wxPoint(0, 0);
910 m_marginBottomRight
= wxPoint(0, 0);
913 m_defaultMinMargins
= FALSE
;
914 m_enableMargins
= TRUE
;
915 m_enableOrientation
= TRUE
;
916 m_enablePaper
= TRUE
;
917 m_enablePrinter
= TRUE
;
918 m_enableHelp
= FALSE
;
919 m_getDefaultInfo
= FALSE
;
922 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
924 (*this) = dialogData
;
927 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
929 #if defined(__WIN95__)
930 m_pageSetupData
= NULL
;
932 m_paperSize
= wxSize(0, 0);
933 m_minMarginTopLeft
= wxPoint(0, 0);
934 m_minMarginBottomRight
= wxPoint(0, 0);
935 m_marginTopLeft
= wxPoint(0, 0);
936 m_marginBottomRight
= wxPoint(0, 0);
939 m_defaultMinMargins
= FALSE
;
940 m_enableMargins
= TRUE
;
941 m_enableOrientation
= TRUE
;
942 m_enablePaper
= TRUE
;
943 m_enablePrinter
= TRUE
;
944 m_enableHelp
= FALSE
;
945 m_getDefaultInfo
= FALSE
;
947 m_printData
= printData
;
949 // The wxPrintData paper size overrides these values, unless the size cannot
951 CalculatePaperSizeFromId();
954 wxPageSetupDialogData::~wxPageSetupDialogData()
956 #if defined(__WIN95__) && defined(__WXMSW__)
957 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
958 if ( pd
&& pd
->hDevMode
)
959 GlobalFree(pd
->hDevMode
);
965 void wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
967 m_paperSize
= data
.m_paperSize
;
968 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
969 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
970 m_marginTopLeft
= data
.m_marginTopLeft
;
971 m_marginBottomRight
= data
.m_marginBottomRight
;
972 m_defaultMinMargins
= data
.m_defaultMinMargins
;
973 m_enableMargins
= data
.m_enableMargins
;
974 m_enableOrientation
= data
.m_enableOrientation
;
975 m_enablePaper
= data
.m_enablePaper
;
976 m_enablePrinter
= data
.m_enablePrinter
;
977 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
978 m_enableHelp
= data
.m_enableHelp
;
980 m_printData
= data
.m_printData
;
983 void wxPageSetupDialogData::operator=(const wxPrintData
& data
)
988 #if defined(__WIN95__)
989 void wxPageSetupDialogData::ConvertToNative()
991 m_printData
.ConvertToNative();
993 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
995 if ( m_pageSetupData
== NULL
)
997 pd
= new PAGESETUPDLG
;
999 m_pageSetupData
= (void *)pd
;
1002 // Pass the devmode data (created in m_printData.ConvertToNative)
1003 // to the PRINTDLG structure, since it'll
1004 // be needed when PrintDlg is called.
1008 GlobalFree(pd
->hDevMode
);
1009 pd
->hDevMode
= NULL
;
1013 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
1015 m_printData
.SetNativeData((void*) NULL
);
1017 wxASSERT_MSG( (pd
->hDevMode
), _T("hDevMode must be non-NULL in ConvertToNative!"));
1019 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1021 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1023 if ( m_defaultMinMargins
)
1024 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
1025 if ( !m_enableMargins
)
1026 pd
->Flags
|= PSD_DISABLEMARGINS
;
1027 if ( !m_enableOrientation
)
1028 pd
->Flags
|= PSD_DISABLEORIENTATION
;
1029 if ( !m_enablePaper
)
1030 pd
->Flags
|= PSD_DISABLEPAPER
;
1031 if ( !m_enablePrinter
)
1032 pd
->Flags
|= PSD_DISABLEPRINTER
;
1033 if ( m_getDefaultInfo
)
1034 pd
->Flags
|= PSD_RETURNDEFAULT
;
1036 pd
->Flags
|= PSD_SHOWHELP
;
1038 // We want the units to be in hundredths of a millimetre
1039 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1041 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
1042 pd
->hwndOwner
=(HWND
)NULL
;
1043 pd
->hDevNames
=(HWND
)NULL
;
1044 pd
->hInstance
=(HINSTANCE
)NULL
;
1046 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
1047 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
1049 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
1050 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
1051 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
1052 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
1054 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
1055 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
1056 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
1057 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
1060 pd
->lpfnPageSetupHook
= NULL
;
1061 pd
->lpfnPagePaintHook
= NULL
;
1062 pd
->hPageSetupTemplate
= NULL
;
1063 pd
->lpPageSetupTemplateName
= NULL
;
1068 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1069 memset(devMode, 0, sizeof(DEVMODE));
1070 devMode->dmSize = sizeof(DEVMODE);
1071 devMode->dmOrientation = m_orientation;
1072 devMode->dmFields = DM_ORIENTATION;
1073 GlobalUnlock(pd->hDevMode);
1078 void wxPageSetupDialogData::ConvertFromNative()
1080 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1084 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1087 if (m_printData
.GetNativeData())
1089 // Make sure we don't leak memory
1090 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1092 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1093 pd
->hDevMode
= NULL
;
1096 m_printData
.ConvertFromNative();
1098 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1100 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
1101 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
1102 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
1103 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
1104 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
1105 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
1106 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
1108 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1109 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
1111 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
1112 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
1113 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
1114 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
1116 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100 ;
1117 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100 ;
1118 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100 ;
1119 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100 ;
1122 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1124 if ( m_pageSetupData
== NULL
)
1127 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1129 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1130 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1135 // If a corresponding paper type is found in the paper database, will set the m_printData
1136 // paper size id member as well.
1137 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
1141 CalculateIdFromPaperSize();
1144 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1145 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1147 m_printData
.SetPaperId(id
);
1149 CalculatePaperSizeFromId();
1152 // Use paper size defined in this object to set the wxPrintData
1154 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1156 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1157 _T("wxThePrintPaperDatabase should not be NULL. "
1158 "Do not create global print dialog data objects.") );
1160 wxSize sz
= GetPaperSize();
1162 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1163 if (id
!= wxPAPER_NONE
)
1165 m_printData
.SetPaperId(id
);
1169 // Use paper id in wxPrintData to set this object's paper size
1170 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1172 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1173 _T("wxThePrintPaperDatabase should not be NULL. "
1174 "Do not create global print dialog data objects.") );
1176 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
1180 // sz is in 10ths of a mm, so multiply by 10.
1181 m_paperSize
.x
= sz
.x
* 10;
1182 m_paperSize
.y
= sz
.y
* 10;
1186 #endif // wxUSE_PRINTING_ARCHITECTURE