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
;
153 m_encoding
= wxFONTENCODING_SYSTEM
;
156 wxFontData::~wxFontData()
160 #if wxUSE_PRINTING_ARCHITECTURE
161 // ----------------------------------------------------------------------------
163 // ----------------------------------------------------------------------------
165 wxPrintData::wxPrintData()
170 m_printOrientation
= wxPORTRAIT
;
172 m_printCollate
= FALSE
;
177 m_duplexMode
= wxDUPLEX_SIMPLEX
;
178 m_printQuality
= wxPRINT_QUALITY_HIGH
;
179 m_paperId
= wxPAPER_A4
;
180 m_paperSize
= wxSize(210, 297);
182 // PostScript-specific data
183 m_printerCommand
= "";
184 m_previewCommand
= "";
185 m_printerOptions
= "";
188 m_printerScaleX
= 1.0;
189 m_printerScaleY
= 1.0;
190 m_printerTranslateX
= 0;
191 m_printerTranslateY
= 0;
192 m_printMode
= wxPRINT_MODE_FILE
;
195 wxPrintData::wxPrintData(const wxPrintData
& printData
)
204 wxPrintData::~wxPrintData()
207 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
209 GlobalFree(hDevMode
);
213 #if defined(__WXMSW__) // && defined(__WIN32__)
216 static wxString
wxGetPrintDlgError()
218 DWORD err
= CommDlgExtendedError();
219 wxString msg
= wxT("Unknown");
222 case CDERR_FINDRESFAILURE
: msg
= wxT("CDERR_FINDRESFAILURE"); break;
223 case CDERR_INITIALIZATION
: msg
= wxT("CDERR_INITIALIZATION"); break;
224 case CDERR_LOADRESFAILURE
: msg
= wxT("CDERR_LOADRESFAILURE"); break;
225 case CDERR_LOADSTRFAILURE
: msg
= wxT("CDERR_LOADSTRFAILURE"); break;
226 case CDERR_LOCKRESFAILURE
: msg
= wxT("CDERR_LOCKRESFAILURE"); break;
227 case CDERR_MEMALLOCFAILURE
: msg
= wxT("CDERR_MEMALLOCFAILURE"); break;
228 case CDERR_MEMLOCKFAILURE
: msg
= wxT("CDERR_MEMLOCKFAILURE"); break;
229 case CDERR_NOHINSTANCE
: msg
= wxT("CDERR_NOHINSTANCE"); break;
230 case CDERR_NOHOOK
: msg
= wxT("CDERR_NOHOOK"); break;
231 case CDERR_NOTEMPLATE
: msg
= wxT("CDERR_NOTEMPLATE"); break;
232 case CDERR_STRUCTSIZE
: msg
= wxT("CDERR_STRUCTSIZE"); break;
233 case PDERR_RETDEFFAILURE
: msg
= wxT("PDERR_RETDEFFAILURE"); break;
234 case PDERR_PRINTERNOTFOUND
: msg
= wxT("PDERR_PRINTERNOTFOUND"); break;
235 case PDERR_PARSEFAILURE
: msg
= wxT("PDERR_PARSEFAILURE"); break;
236 case PDERR_NODEVICES
: msg
= wxT("PDERR_NODEVICES"); break;
237 case PDERR_NODEFAULTPRN
: msg
= wxT("PDERR_NODEFAULTPRN"); break;
238 case PDERR_LOADDRVFAILURE
: msg
= wxT("PDERR_LOADDRVFAILURE"); break;
239 case PDERR_INITFAILURE
: msg
= wxT("PDERR_INITFAILURE"); break;
240 case PDERR_GETDEVMODEFAIL
: msg
= wxT("PDERR_GETDEVMODEFAIL"); break;
241 case PDERR_DNDMMISMATCH
: msg
= wxT("PDERR_DNDMMISMATCH"); break;
242 case PDERR_DEFAULTDIFFERENT
: msg
= wxT("PDERR_DEFAULTDIFFERENT"); break;
243 case PDERR_CREATEICFAILURE
: msg
= wxT("PDERR_CREATEICFAILURE"); break;
250 void wxPrintData::ConvertToNative()
252 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) 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 #if defined(__WXDEBUG__) && defined(__WIN32__)
287 wxString
str(wxT("Printing error: "));
288 str
+= wxGetPrintDlgError();
295 GlobalFree(pd
->hDevNames
);
296 pd
->hDevNames
= NULL
;
298 hDevMode
= pd
->hDevMode
;
299 m_devMode
= (void*)(long) hDevMode
;
308 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(hDevMode
);
313 devMode
->dmOrientation
= m_printOrientation
;
315 devMode
->dmFields
= DM_ORIENTATION
;
320 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
321 devMode
->dmFields
|= DM_COLLATE
;
324 //// Number of copies
326 devMode
->dmCopies
= m_printNoCopies
;
327 devMode
->dmFields
|= DM_COPIES
;
331 if (m_printerName
!= wxT(""))
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
;
353 if (m_paperId
== wxPAPER_NONE
)
355 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
356 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
357 devMode
->dmFields
|= DM_PAPERWIDTH
;
358 devMode
->dmFields
|= DM_PAPERLENGTH
;
362 if (wxThePrintPaperDatabase
)
364 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
367 devMode
->dmPaperSize
= paper
->GetPlatformId();
368 devMode
->dmFields
|= DM_PAPERSIZE
;
377 switch (m_duplexMode
)
379 case wxDUPLEX_HORIZONTAL
: {
380 duplex
= DMDUP_HORIZONTAL
; break;
382 case wxDUPLEX_VERTICAL
: {
383 duplex
= DMDUP_VERTICAL
; break;
386 case wxDUPLEX_SIMPLEX
: {
387 duplex
= DMDUP_SIMPLEX
; break;
390 devMode
->dmDuplex
= duplex
;
391 devMode
->dmFields
|= DM_DUPLEX
;
396 switch (m_printQuality
)
398 case wxPRINT_QUALITY_MEDIUM
: {
399 quality
= DMRES_MEDIUM
; break;
401 case wxPRINT_QUALITY_LOW
: {
402 quality
= DMRES_LOW
; break;
404 case wxPRINT_QUALITY_DRAFT
: {
405 quality
= DMRES_DRAFT
; break;
407 case wxPRINT_QUALITY_HIGH
: {
408 quality
= DMRES_HIGH
; break;
411 quality
= m_printQuality
; break;
414 devMode
->dmPrintQuality
= quality
;
415 devMode
->dmFields
|= DM_PRINTQUALITY
;
417 GlobalUnlock(hDevMode
);
421 void wxPrintData::ConvertFromNative()
423 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
430 DEVMODE
*devMode
= (DEVMODE
*) GlobalLock(hDevMode
);
435 if (devMode
->dmFields
& DM_ORIENTATION
)
436 m_printOrientation
= devMode
->dmOrientation
;
442 if (devMode
->dmFields
& DM_COLLATE
)
444 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
445 m_printCollate
= TRUE
;
447 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
)
490 if (devMode
->dmFields
& DM_PAPERSIZE
)
492 if (wxThePrintPaperDatabase
)
494 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
497 m_paperId
= paper
->GetId();
498 m_paperSize
.x
= paper
->GetWidth() / 10 ;
499 m_paperSize
.y
= paper
->GetHeight() / 10 ;
503 // Shouldn't really get here
504 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
506 m_paperId
= wxPAPER_NONE
;
513 // Shouldn't really get here
514 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
516 m_paperId
= wxPAPER_NONE
;
521 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
523 m_paperSize
.x
= devMode
->dmPaperWidth
/ 10;
524 m_paperSize
.y
= devMode
->dmPaperLength
/ 10;
525 m_paperId
= wxPAPER_NONE
;
529 // Shouldn't really get here
530 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
534 m_paperId
= wxPAPER_NONE
;
540 if (devMode
->dmFields
& DM_DUPLEX
)
542 switch (devMode
->dmDuplex
)
544 case DMDUP_HORIZONTAL
: {
545 m_duplexMode
= wxDUPLEX_HORIZONTAL
; break;
547 case DMDUP_VERTICAL
: {
548 m_duplexMode
= wxDUPLEX_VERTICAL
; break;
551 case DMDUP_SIMPLEX
: {
552 m_duplexMode
= wxDUPLEX_SIMPLEX
; break;
557 m_duplexMode
= wxDUPLEX_SIMPLEX
;
561 if (devMode
->dmFields
& DM_PRINTQUALITY
)
563 switch (devMode
->dmPrintQuality
)
566 m_printQuality
= wxPRINT_QUALITY_MEDIUM
; break;
569 m_printQuality
= wxPRINT_QUALITY_LOW
; break;
572 m_printQuality
= wxPRINT_QUALITY_DRAFT
; break;
575 m_printQuality
= wxPRINT_QUALITY_HIGH
; break;
579 // TODO: if the printer fills in the resolution in DPI, how
580 // will the application know if it's high, low, draft etc.??
581 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
582 m_printQuality
= devMode
->dmPrintQuality
; break;
588 m_printQuality
= wxPRINT_QUALITY_HIGH
;
590 GlobalUnlock(hDevMode
);
596 void wxPrintData::operator=(const wxPrintData
& data
)
598 m_printNoCopies
= data
.m_printNoCopies
;
599 m_printCollate
= data
.m_printCollate
;
600 m_printOrientation
= data
.m_printOrientation
;
601 m_printerName
= data
.m_printerName
;
602 m_colour
= data
.m_colour
;
603 m_duplexMode
= data
.m_duplexMode
;
604 m_printQuality
= data
.m_printQuality
;
605 m_paperId
= data
.m_paperId
;
606 m_paperSize
= data
.m_paperSize
;
608 // PostScript-specific data
609 m_printerCommand
= data
.m_printerCommand
;
610 m_previewCommand
= data
.m_previewCommand
;
611 m_printerOptions
= data
.m_printerOptions
;
612 m_filename
= data
.m_filename
;
613 m_afmPath
= data
.m_afmPath
;
614 m_printerScaleX
= data
.m_printerScaleX
;
615 m_printerScaleY
= data
.m_printerScaleY
;
616 m_printerTranslateX
= data
.m_printerTranslateX
;
617 m_printerTranslateY
= data
.m_printerTranslateY
;
618 m_printMode
= data
.m_printMode
;
622 #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
623 void wxPrintData::operator=(const wxPrintSetupData
& setupData
)
625 SetPrinterCommand(setupData
.GetPrinterCommand());
626 SetPreviewCommand(setupData
.GetPrintPreviewCommand());
627 SetPrinterOptions(setupData
.GetPrinterOptions());
630 setupData
.GetPrinterTranslation(& xt
, & yt
);
631 SetPrinterTranslation(xt
, yt
);
634 setupData
.GetPrinterScaling(& xs
, & ys
);
635 SetPrinterScaling(xs
, ys
);
637 SetOrientation(setupData
.GetPrinterOrientation());
638 SetPrintMode((wxPrintMode
) setupData
.GetPrinterMode());
639 SetFontMetricPath(setupData
.GetAFMPath());
640 if (setupData
.GetPaperName() != "")
641 SetPaperId(wxThePrintPaperDatabase
->ConvertNameToId(setupData
.GetPaperName()));
642 SetColour(setupData
.GetColour());
643 SetFilename(setupData
.GetPrinterFile());
645 #endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
648 // ----------------------------------------------------------------------------
650 // ----------------------------------------------------------------------------
652 wxPrintDialogData::wxPrintDialogData()
655 m_printDlgData
= NULL
;
662 m_printAllPages
= FALSE
;
663 m_printCollate
= FALSE
;
664 m_printToFile
= FALSE
;
665 m_printSelection
= FALSE
;
666 m_printEnableSelection
= FALSE
;
667 m_printEnablePageNumbers
= TRUE
;
668 m_printEnablePrintToFile
= TRUE
;
669 m_printEnableHelp
= FALSE
;
670 m_printSetupDialog
= FALSE
;
673 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
675 (*this) = dialogData
;
678 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
681 m_printDlgData
= NULL
;
688 m_printAllPages
= FALSE
;
689 m_printCollate
= FALSE
;
690 m_printToFile
= FALSE
;
691 m_printSelection
= FALSE
;
692 m_printEnableSelection
= FALSE
;
693 m_printEnablePageNumbers
= TRUE
;
694 m_printEnablePrintToFile
= TRUE
;
695 m_printEnableHelp
= FALSE
;
696 m_printSetupDialog
= FALSE
;
698 m_printData
= printData
;
701 wxPrintDialogData::~wxPrintDialogData()
704 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
705 if ( pd
&& pd
->hDevMode
)
706 GlobalFree(pd
->hDevMode
);
713 void wxPrintDialogData::ConvertToNative()
715 m_printData
.ConvertToNative();
717 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
722 m_printDlgData
= (void*) pd
;
724 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
726 pd
->lStructSize
= 66 ;
728 pd
->lStructSize
= sizeof(PRINTDLG
);
730 pd
->hwndOwner
= (HWND
)NULL
;
731 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
732 pd
->hDevNames
= NULL
; // Ditto
734 pd
->Flags
= PD_RETURNDEFAULT
;
738 // Pass the devmode data to the PRINTDLG structure, since it'll
739 // be needed when PrintDlg is called.
742 GlobalFree(pd
->hDevMode
);
745 pd
->hDevMode
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeData();
747 m_printData
.SetNativeData((void*) NULL
);
749 wxASSERT_MSG( (pd
->hDevMode
), wxT("hDevMode must be non-NULL in ConvertToNative!"));
751 pd
->hDC
= (HDC
) NULL
;
752 pd
->nFromPage
= (UINT
)m_printFromPage
;
753 pd
->nToPage
= (UINT
)m_printToPage
;
754 pd
->nMinPage
= (UINT
)m_printMinPage
;
755 pd
->nMaxPage
= (UINT
)m_printMaxPage
;
756 pd
->nCopies
= (UINT
)m_printNoCopies
;
758 pd
->Flags
= PD_RETURNDC
;
761 pd
->lStructSize
= 66 ;
763 pd
->lStructSize
= sizeof( PRINTDLG
);
766 pd
->hwndOwner
=(HWND
)NULL
;
767 pd
->hDevNames
=(HANDLE
)NULL
;
768 pd
->hInstance
=(HINSTANCE
)NULL
;
769 pd
->lCustData
= (LPARAM
) NULL
;
770 pd
->lpfnPrintHook
= NULL
;
771 pd
->lpfnSetupHook
= NULL
;
772 pd
->lpPrintTemplateName
= NULL
;
773 pd
->lpSetupTemplateName
= NULL
;
774 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
775 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
777 if ( m_printAllPages
)
778 pd
->Flags
|= PD_ALLPAGES
;
779 if ( m_printAllPages
)
780 pd
->Flags
|= PD_SELECTION
;
781 if ( m_printCollate
)
782 pd
->Flags
|= PD_COLLATE
;
784 pd
->Flags
|= PD_PRINTTOFILE
;
785 if ( !m_printEnablePrintToFile
)
786 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
787 if ( !m_printEnableSelection
)
788 pd
->Flags
|= PD_NOSELECTION
;
789 if ( !m_printEnablePageNumbers
)
790 pd
->Flags
|= PD_NOPAGENUMS
;
791 if ( m_printEnableHelp
)
792 pd
->Flags
|= PD_SHOWHELP
;
793 if ( m_printSetupDialog
)
794 pd
->Flags
|= PD_PRINTSETUP
;
797 void wxPrintDialogData::ConvertFromNative()
799 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
803 // Pass the devmode data back to the wxPrintData structure where it really belongs.
806 if (m_printData
.GetNativeData())
808 // Make sure we don't leak memory
809 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeData());
811 m_printData
.SetNativeData((void*)(long) pd
->hDevMode
);
815 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
816 // into wxWindows form.
817 m_printData
.ConvertFromNative();
819 m_printFromPage
= pd
->nFromPage
;
820 m_printToPage
= pd
->nToPage
;
821 m_printMinPage
= pd
->nMinPage
;
822 m_printMaxPage
= pd
->nMaxPage
;
823 m_printNoCopies
= pd
->nCopies
;
825 m_printAllPages
= ((pd
->Flags
& PD_ALLPAGES
) == PD_ALLPAGES
);
826 m_printSelection
= ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
);
827 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
828 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
829 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
830 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
831 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
832 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
833 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
835 /* port is obsolete in WIN32
839 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
841 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
842 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
843 GlobalUnlock(pd->hDevNames);
845 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
851 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
853 if ( m_printDlgData
== NULL
)
856 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
858 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
859 pd
->hwndOwner
=(HWND
) win
->GetHWND();
864 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
866 m_printFromPage
= data
.m_printFromPage
;
867 m_printToPage
= data
.m_printToPage
;
868 m_printMinPage
= data
.m_printMinPage
;
869 m_printMaxPage
= data
.m_printMaxPage
;
870 m_printNoCopies
= data
.m_printNoCopies
;
871 m_printAllPages
= data
.m_printAllPages
;
872 m_printCollate
= data
.m_printCollate
;
873 m_printToFile
= data
.m_printToFile
;
874 m_printSelection
= data
.m_printSelection
;
875 m_printEnableSelection
= data
.m_printEnableSelection
;
876 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
877 m_printEnableHelp
= data
.m_printEnableHelp
;
878 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
879 m_printSetupDialog
= data
.m_printSetupDialog
;
881 m_printData
= data
.m_printData
;
884 void wxPrintDialogData::operator=(const wxPrintData
& data
)
889 // ----------------------------------------------------------------------------
890 // wxPageSetupDialogData
891 // ----------------------------------------------------------------------------
893 wxPageSetupDialogData::wxPageSetupDialogData()
895 #if defined(__WIN95__)
896 m_pageSetupData
= NULL
;
898 m_paperSize
= wxSize(0, 0);
900 CalculatePaperSizeFromId();
902 m_minMarginTopLeft
= wxPoint(0, 0);
903 m_minMarginBottomRight
= wxPoint(0, 0);
904 m_marginTopLeft
= wxPoint(0, 0);
905 m_marginBottomRight
= wxPoint(0, 0);
908 m_defaultMinMargins
= FALSE
;
909 m_enableMargins
= TRUE
;
910 m_enableOrientation
= TRUE
;
911 m_enablePaper
= TRUE
;
912 m_enablePrinter
= TRUE
;
913 m_enableHelp
= FALSE
;
914 m_getDefaultInfo
= FALSE
;
917 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
919 (*this) = dialogData
;
922 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
924 #if defined(__WIN95__)
925 m_pageSetupData
= NULL
;
927 m_paperSize
= wxSize(0, 0);
928 m_minMarginTopLeft
= wxPoint(0, 0);
929 m_minMarginBottomRight
= wxPoint(0, 0);
930 m_marginTopLeft
= wxPoint(0, 0);
931 m_marginBottomRight
= wxPoint(0, 0);
934 m_defaultMinMargins
= FALSE
;
935 m_enableMargins
= TRUE
;
936 m_enableOrientation
= TRUE
;
937 m_enablePaper
= TRUE
;
938 m_enablePrinter
= TRUE
;
939 m_enableHelp
= FALSE
;
940 m_getDefaultInfo
= FALSE
;
942 m_printData
= printData
;
944 // The wxPrintData paper size overrides these values, unless the size cannot
946 CalculatePaperSizeFromId();
949 wxPageSetupDialogData::~wxPageSetupDialogData()
951 #if defined(__WIN95__) && defined(__WXMSW__)
952 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
953 if ( pd
&& pd
->hDevMode
)
954 GlobalFree(pd
->hDevMode
);
960 void wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
962 m_paperSize
= data
.m_paperSize
;
963 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
964 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
965 m_marginTopLeft
= data
.m_marginTopLeft
;
966 m_marginBottomRight
= data
.m_marginBottomRight
;
967 m_defaultMinMargins
= data
.m_defaultMinMargins
;
968 m_enableMargins
= data
.m_enableMargins
;
969 m_enableOrientation
= data
.m_enableOrientation
;
970 m_enablePaper
= data
.m_enablePaper
;
971 m_enablePrinter
= data
.m_enablePrinter
;
972 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
973 m_enableHelp
= data
.m_enableHelp
;
975 m_printData
= data
.m_printData
;
978 void wxPageSetupDialogData::operator=(const wxPrintData
& data
)
983 #if defined(__WIN95__)
984 void wxPageSetupDialogData::ConvertToNative()
986 m_printData
.ConvertToNative();
988 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
990 if ( m_pageSetupData
== NULL
)
992 pd
= new PAGESETUPDLG
;
994 m_pageSetupData
= (void *)pd
;
997 // Pass the devmode data (created in m_printData.ConvertToNative)
998 // to the PRINTDLG structure, since it'll
999 // be needed when PrintDlg is called.
1003 GlobalFree(pd
->hDevMode
);
1004 pd
->hDevMode
= NULL
;
1007 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
1009 m_printData
.SetNativeData((void*) NULL
);
1011 wxASSERT_MSG( (pd
->hDevMode
), wxT("hDevMode must be non-NULL in ConvertToNative!"));
1013 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1015 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1017 if ( m_defaultMinMargins
)
1018 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
1019 if ( !m_enableMargins
)
1020 pd
->Flags
|= PSD_DISABLEMARGINS
;
1021 if ( !m_enableOrientation
)
1022 pd
->Flags
|= PSD_DISABLEORIENTATION
;
1023 if ( !m_enablePaper
)
1024 pd
->Flags
|= PSD_DISABLEPAPER
;
1025 if ( !m_enablePrinter
)
1026 pd
->Flags
|= PSD_DISABLEPRINTER
;
1027 if ( m_getDefaultInfo
)
1028 pd
->Flags
|= PSD_RETURNDEFAULT
;
1030 pd
->Flags
|= PSD_SHOWHELP
;
1032 // We want the units to be in hundredths of a millimetre
1033 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1035 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
1036 pd
->hwndOwner
=(HWND
)NULL
;
1037 pd
->hDevNames
=(HWND
)NULL
;
1038 pd
->hInstance
=(HINSTANCE
)NULL
;
1040 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
1041 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
1043 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
1044 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
1045 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
1046 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
1048 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
1049 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
1050 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
1051 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
1054 pd
->lpfnPageSetupHook
= NULL
;
1055 pd
->lpfnPagePaintHook
= NULL
;
1056 pd
->hPageSetupTemplate
= NULL
;
1057 pd
->lpPageSetupTemplateName
= NULL
;
1062 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1063 memset(devMode, 0, sizeof(DEVMODE));
1064 devMode->dmSize = sizeof(DEVMODE);
1065 devMode->dmOrientation = m_orientation;
1066 devMode->dmFields = DM_ORIENTATION;
1067 GlobalUnlock(pd->hDevMode);
1072 void wxPageSetupDialogData::ConvertFromNative()
1074 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1078 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1081 if (m_printData
.GetNativeData())
1083 // Make sure we don't leak memory
1084 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1086 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1087 pd
->hDevMode
= NULL
;
1090 m_printData
.ConvertFromNative();
1092 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1094 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
1095 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
1096 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
1097 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
1098 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
1099 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
1100 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
1102 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1103 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
1105 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
1106 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
1107 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
1108 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
1110 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100 ;
1111 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100 ;
1112 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100 ;
1113 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100 ;
1116 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1118 if ( m_pageSetupData
== NULL
)
1121 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1123 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1124 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1129 // If a corresponding paper type is found in the paper database, will set the m_printData
1130 // paper size id member as well.
1131 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
1135 CalculateIdFromPaperSize();
1138 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1139 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1141 m_printData
.SetPaperId(id
);
1143 CalculatePaperSizeFromId();
1146 // Use paper size defined in this object to set the wxPrintData
1148 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1150 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1151 wxT("wxThePrintPaperDatabase should not be NULL. "
1152 "Do not create global print dialog data objects.") );
1154 wxSize sz
= GetPaperSize();
1156 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1157 if (id
!= wxPAPER_NONE
)
1159 m_printData
.SetPaperId(id
);
1163 // Use paper id in wxPrintData to set this object's paper size
1164 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1166 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1167 wxT("wxThePrintPaperDatabase should not be NULL. "
1168 "Do not create global print dialog data objects.") );
1170 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
1174 // sz is in 10ths of a mm, so multiply by 10.
1175 m_paperSize
.x
= sz
.x
* 10;
1176 m_paperSize
.y
= sz
.y
* 10;
1180 #endif // wxUSE_PRINTING_ARCHITECTURE