1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI data
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
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 #include "wx/fontdlg.h"
44 #endif // wxUSE_FONTDLG
46 #if wxUSE_PRINTING_ARCHITECTURE
48 #endif // wxUSE_PRINTING_ARCHITECTURE
52 #include "wx/msw/private.h"
54 #if defined(__WXWINCE__) && !wxUSE_SMARTPHONE
58 #if defined(__WATCOMC__) || defined(__SYMANTEC__) || defined(__SALFORDC__)
65 #include "wx/mac/private/print.h"
68 #if wxUSE_PRINTING_ARCHITECTURE
69 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
70 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
71 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
72 #endif // wxUSE_PRINTING_ARCHITECTURE
74 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
75 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
78 #define DMPAPER_USER 256
81 // ============================================================================
83 // ============================================================================
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 wxColourData::wxColourData()
92 for (i
= 0; i
< 16; i
++)
93 m_custColours
[i
].Set(255, 255, 255);
96 m_dataColour
.Set(0,0,0);
99 wxColourData::wxColourData(const wxColourData
& data
)
105 wxColourData::~wxColourData()
109 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
114 m_custColours
[i
] = colour
;
117 wxColour
wxColourData::GetCustomColour(int i
)
120 return wxColour(0,0,0);
122 return m_custColours
[i
];
125 void wxColourData::operator=(const wxColourData
& data
)
128 for (i
= 0; i
< 16; i
++)
129 m_custColours
[i
] = data
.m_custColours
[i
];
131 m_dataColour
= (wxColour
&)data
.m_dataColour
;
132 m_chooseFull
= data
.m_chooseFull
;
135 // ----------------------------------------------------------------------------
137 // ----------------------------------------------------------------------------
139 wxFontData::wxFontData()
141 // Intialize colour to black.
142 m_fontColour
= wxNullColour
;
145 m_allowSymbols
= TRUE
;
146 m_enableEffects
= TRUE
;
150 m_encoding
= wxFONTENCODING_SYSTEM
;
153 wxFontData::~wxFontData()
159 wxFontDialogBase::~wxFontDialogBase()
163 #endif // wxUSE_FONTDLG
165 #if wxUSE_PRINTING_ARCHITECTURE
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
170 wxPrintData::wxPrintData()
173 m_devMode
= (void*) NULL
;
174 m_devNames
= (void*) NULL
;
175 #elif defined( __WXMAC__ )
176 m_nativePrintData
= wxNativePrintData::Create() ;
178 m_printOrientation
= wxPORTRAIT
;
180 m_printCollate
= FALSE
;
183 m_printerName
= wxT("");
185 m_duplexMode
= wxDUPLEX_SIMPLEX
;
186 m_printQuality
= wxPRINT_QUALITY_HIGH
;
187 m_paperId
= wxPAPER_A4
;
188 m_paperSize
= wxSize(210, 297);
190 // PostScript-specific data
191 m_previewCommand
= wxT("");
192 m_filename
= wxT("");
194 m_printerCommand
= wxT("print");
195 m_printerOptions
= wxT("/nonotify/queue=psqueue");
196 m_afmPath
= wxT("sys$ps_font_metrics:");
200 m_printerCommand
= wxT("print");
201 m_printerOptions
= wxT("");
202 m_afmPath
= wxT("c:\\windows\\system\\");
205 #if !defined(__VMS__) && !defined(__WXMSW__)
206 m_printerCommand
= wxT("lpr");
207 m_printerOptions
= wxT("");
211 m_printerScaleX
= 1.0;
212 m_printerScaleY
= 1.0;
213 m_printerTranslateX
= 0;
214 m_printerTranslateY
= 0;
215 m_printMode
= wxPRINT_MODE_FILE
;
218 wxPrintData::wxPrintData(const wxPrintData
& printData
)
222 m_devMode
= (void*) NULL
;
223 m_devNames
= (void*) NULL
;
224 #elif defined( __WXMAC__ )
225 m_nativePrintData
= wxNativePrintData::Create() ;
230 wxPrintData::~wxPrintData()
233 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
235 GlobalFree(hDevMode
);
236 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
238 GlobalFree(hDevNames
);
239 #elif defined(__WXMAC__)
240 delete m_nativePrintData
;
244 #if defined(__WXMSW__) // && defined(__WIN32__)
246 #if defined(__WXDEBUG__) && defined(__WIN32__)
247 static wxString
wxGetPrintDlgError()
249 DWORD err
= CommDlgExtendedError();
250 wxString msg
= wxT("Unknown");
253 case CDERR_FINDRESFAILURE
: msg
= wxT("CDERR_FINDRESFAILURE"); break;
254 case CDERR_INITIALIZATION
: msg
= wxT("CDERR_INITIALIZATION"); break;
255 case CDERR_LOADRESFAILURE
: msg
= wxT("CDERR_LOADRESFAILURE"); break;
256 case CDERR_LOADSTRFAILURE
: msg
= wxT("CDERR_LOADSTRFAILURE"); break;
257 case CDERR_LOCKRESFAILURE
: msg
= wxT("CDERR_LOCKRESFAILURE"); break;
258 case CDERR_MEMALLOCFAILURE
: msg
= wxT("CDERR_MEMALLOCFAILURE"); break;
259 case CDERR_MEMLOCKFAILURE
: msg
= wxT("CDERR_MEMLOCKFAILURE"); break;
260 case CDERR_NOHINSTANCE
: msg
= wxT("CDERR_NOHINSTANCE"); break;
261 case CDERR_NOHOOK
: msg
= wxT("CDERR_NOHOOK"); break;
262 case CDERR_NOTEMPLATE
: msg
= wxT("CDERR_NOTEMPLATE"); break;
263 case CDERR_STRUCTSIZE
: msg
= wxT("CDERR_STRUCTSIZE"); break;
264 case PDERR_RETDEFFAILURE
: msg
= wxT("PDERR_RETDEFFAILURE"); break;
265 case PDERR_PRINTERNOTFOUND
: msg
= wxT("PDERR_PRINTERNOTFOUND"); break;
266 case PDERR_PARSEFAILURE
: msg
= wxT("PDERR_PARSEFAILURE"); break;
267 case PDERR_NODEVICES
: msg
= wxT("PDERR_NODEVICES"); break;
268 case PDERR_NODEFAULTPRN
: msg
= wxT("PDERR_NODEFAULTPRN"); break;
269 case PDERR_LOADDRVFAILURE
: msg
= wxT("PDERR_LOADDRVFAILURE"); break;
270 case PDERR_INITFAILURE
: msg
= wxT("PDERR_INITFAILURE"); break;
271 case PDERR_GETDEVMODEFAIL
: msg
= wxT("PDERR_GETDEVMODEFAIL"); break;
272 case PDERR_DNDMMISMATCH
: msg
= wxT("PDERR_DNDMMISMATCH"); break;
273 case PDERR_DEFAULTDIFFERENT
: msg
= wxT("PDERR_DEFAULTDIFFERENT"); break;
274 case PDERR_CREATEICFAILURE
: msg
= wxT("PDERR_CREATEICFAILURE"); break;
281 static HGLOBAL
wxCreateDevNames(const wxString
& driverName
, const wxString
& printerName
, const wxString
& portName
)
284 // if (!driverName.IsEmpty() && !printerName.IsEmpty() && !portName.IsEmpty())
285 if (driverName
.IsEmpty() && printerName
.IsEmpty() && portName
.IsEmpty())
290 hDev
= GlobalAlloc(GPTR
, 4*sizeof(WORD
)+
291 ( driverName
.Length() + 1 +
292 printerName
.Length() + 1 +
293 portName
.Length()+1 ) * sizeof(wxChar
) );
294 LPDEVNAMES lpDev
= (LPDEVNAMES
)GlobalLock(hDev
);
295 lpDev
->wDriverOffset
= sizeof(WORD
)*4;
296 wxStrcpy((wxChar
*)((char*)lpDev
+ lpDev
->wDriverOffset
), driverName
);
298 lpDev
->wDeviceOffset
= (WORD
)( lpDev
->wDriverOffset
+
299 sizeof(wxChar
) * ( driverName
.Length() + 1 ) );
300 wxStrcpy((wxChar
*)((char*)lpDev
+ lpDev
->wDeviceOffset
), printerName
);
302 lpDev
->wOutputOffset
= (WORD
)( lpDev
->wDeviceOffset
+
303 sizeof(wxChar
) * ( printerName
.Length() + 1 ) );
304 wxStrcpy((wxChar
*)((char*) lpDev
+ lpDev
->wOutputOffset
), portName
);
314 void wxPrintData::ConvertToNative()
316 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
317 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
320 // Use PRINTDLG as a way of creating a DEVMODE object
323 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
328 memset(&pd
, 0, sizeof(PRINTDLG
));
330 pd
.cbStruct
= sizeof(PRINTDLG
);
332 pd
.lStructSize
= sizeof(PRINTDLG
);
336 pd
.hwndOwner
= (HWND
)NULL
;
337 pd
.hDevMode
= NULL
; // Will be created by PrintDlg
338 pd
.hDevNames
= NULL
; // Ditto
339 //pd.hInstance = (HINSTANCE) wxGetInstance();
341 pd
.Flags
= PD_RETURNDEFAULT
;
344 // Fill out the DEVMODE structure
345 // so we can use it as input in the 'real' PrintDlg
349 GlobalFree(pd
.hDevMode
);
351 GlobalFree(pd
.hDevNames
);
355 #if defined(__WXDEBUG__) && defined(__WIN32__)
356 wxString
str(wxT("Printing error: "));
357 str
+= wxGetPrintDlgError();
363 hDevMode
= pd
.hDevMode
;
364 m_devMode
= (void*)(long) hDevMode
;
367 // We'll create a new DEVNAMEs structure below.
369 GlobalFree(pd
.hDevNames
);
372 // hDevNames = pd->hDevNames;
373 // m_devNames = (void*)(long) hDevNames;
374 // pd->hDevnames = NULL;
381 LPDEVMODE devMode
= (LPDEVMODE
) GlobalLock(hDevMode
);
385 devMode
->dmOrientation
= m_printOrientation
;
390 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
391 devMode
->dmFields
|= DM_COLLATE
;
394 //// Number of copies
396 devMode
->dmCopies
= m_printNoCopies
;
397 devMode
->dmFields
|= DM_COPIES
;
401 if (m_printerName
!= wxT(""))
403 //int len = wxMin(31, m_printerName.Len());
404 wxStrncpy((wxChar
*)devMode
->dmDeviceName
,m_printerName
.c_str(),31);
405 devMode
->dmDeviceName
[31] = wxT('\0');
411 devMode
->dmColor
= DMCOLOR_COLOR
;
413 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
415 devMode
->dmFields
|= DM_COLOR
;
419 if (m_paperId
== wxPAPER_NONE
)
421 // DEVMODE is in tenths of a milimeter
422 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
423 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
424 devMode
->dmPaperSize
= DMPAPER_USER
;
425 devMode
->dmFields
|= DM_PAPERWIDTH
;
426 devMode
->dmFields
|= DM_PAPERLENGTH
;
430 if (wxThePrintPaperDatabase
)
432 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
435 devMode
->dmPaperSize
= paper
->GetPlatformId();
436 devMode
->dmFields
|= DM_PAPERSIZE
;
444 switch (m_duplexMode
)
446 case wxDUPLEX_HORIZONTAL
: {
447 duplex
= DMDUP_HORIZONTAL
; break;
449 case wxDUPLEX_VERTICAL
: {
450 duplex
= DMDUP_VERTICAL
; break;
453 case wxDUPLEX_SIMPLEX
: {
454 duplex
= DMDUP_SIMPLEX
; break;
457 devMode
->dmDuplex
= duplex
;
458 devMode
->dmFields
|= DM_DUPLEX
;
463 switch (m_printQuality
)
465 case wxPRINT_QUALITY_MEDIUM
: {
466 quality
= DMRES_MEDIUM
; break;
468 case wxPRINT_QUALITY_LOW
: {
469 quality
= DMRES_LOW
; break;
471 case wxPRINT_QUALITY_DRAFT
: {
472 quality
= DMRES_DRAFT
; break;
474 case wxPRINT_QUALITY_HIGH
: {
475 quality
= DMRES_HIGH
; break;
478 quality
= m_printQuality
; break;
481 devMode
->dmPrintQuality
= quality
;
482 devMode
->dmFields
|= DM_PRINTQUALITY
;
484 GlobalUnlock(hDevMode
);
489 GlobalFree(hDevNames
);
492 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
493 m_devNames
= (void*) (long) wxCreateDevNames(wxT(""), m_printerName
, wxT(""));
496 void wxPrintData::ConvertFromNative()
498 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
499 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
506 LPDEVMODE devMode
= (LPDEVMODE
)GlobalLock(hDevMode
);
510 if (devMode
->dmFields
& DM_ORIENTATION
)
511 m_printOrientation
= devMode
->dmOrientation
;
516 if (devMode
->dmFields
& DM_COLLATE
)
518 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
519 m_printCollate
= TRUE
;
521 m_printCollate
= FALSE
;
525 //// Number of copies
527 if (devMode
->dmFields
& DM_COPIES
)
529 m_printNoCopies
= devMode
->dmCopies
;
534 if (devMode
->dmDeviceName
[0] != 0)
536 m_printerName
= devMode
->dmDeviceName
;
541 if (devMode
->dmFields
& DM_COLOR
)
543 if (devMode
->dmColor
== DMCOLOR_COLOR
)
553 // We don't know size of user defined paper and some buggy drivers
554 // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
555 // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
556 // code wouldn't set m_paperSize correctly.
557 if ((devMode
->dmFields
& DM_PAPERSIZE
) && (devMode
->dmPaperSize
< DMPAPER_USER
))
559 if (wxThePrintPaperDatabase
)
561 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
564 m_paperId
= paper
->GetId();
565 m_paperSize
.x
= paper
->GetWidth() / 10;
566 m_paperSize
.y
= paper
->GetHeight() / 10;
570 // Shouldn't really get here
571 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
573 m_paperId
= wxPAPER_NONE
;
580 // Shouldn't really get here
581 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
583 m_paperId
= wxPAPER_NONE
;
588 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
590 // DEVMODE is in tenths of a milimeter
591 m_paperSize
.x
= devMode
->dmPaperWidth
/ 10;
592 m_paperSize
.y
= devMode
->dmPaperLength
/ 10;
593 m_paperId
= wxPAPER_NONE
;
597 // Shouldn't really get here
598 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
602 m_paperId
= wxPAPER_NONE
;
607 if (devMode
->dmFields
& DM_DUPLEX
)
609 switch (devMode
->dmDuplex
)
611 case DMDUP_HORIZONTAL
: {
612 m_duplexMode
= wxDUPLEX_HORIZONTAL
; break;
614 case DMDUP_VERTICAL
: {
615 m_duplexMode
= wxDUPLEX_VERTICAL
; break;
618 case DMDUP_SIMPLEX
: {
619 m_duplexMode
= wxDUPLEX_SIMPLEX
; break;
624 m_duplexMode
= wxDUPLEX_SIMPLEX
;
628 if (devMode
->dmFields
& DM_PRINTQUALITY
)
630 switch (devMode
->dmPrintQuality
)
633 m_printQuality
= wxPRINT_QUALITY_MEDIUM
; break;
636 m_printQuality
= wxPRINT_QUALITY_LOW
; break;
639 m_printQuality
= wxPRINT_QUALITY_DRAFT
; break;
642 m_printQuality
= wxPRINT_QUALITY_HIGH
; break;
646 // TODO: if the printer fills in the resolution in DPI, how
647 // will the application know if it's high, low, draft etc.??
648 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
649 m_printQuality
= devMode
->dmPrintQuality
; break;
655 m_printQuality
= wxPRINT_QUALITY_HIGH
;
657 GlobalUnlock(hDevMode
);
662 LPDEVNAMES lpDevNames
= (LPDEVNAMES
)GlobalLock(hDevNames
);
665 // TODO: Unicode-ification
668 // port is obsolete in WIN32
669 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
671 // Get the printer name
672 wxString printerName
= (LPTSTR
)lpDevNames
+ lpDevNames
->wDeviceOffset
;
674 // Not sure if we should check for this mismatch
675 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
677 if (printerName
!= wxT(""))
678 m_printerName
= printerName
;
680 GlobalUnlock(hDevNames
);
689 void wxPrintData::ConvertToNative()
691 m_nativePrintData
->TransferFrom( this ) ;
694 void wxPrintData::ConvertFromNative()
696 m_nativePrintData
->TransferTo( this ) ;
701 void wxPrintData::operator=(const wxPrintData
& data
)
704 m_nativePrintData
->CopyFrom( data
.m_nativePrintData
) ;
706 m_printNoCopies
= data
.m_printNoCopies
;
707 m_printCollate
= data
.m_printCollate
;
708 m_printOrientation
= data
.m_printOrientation
;
709 m_printerName
= data
.m_printerName
;
710 m_colour
= data
.m_colour
;
711 m_duplexMode
= data
.m_duplexMode
;
712 m_printQuality
= data
.m_printQuality
;
713 m_paperId
= data
.m_paperId
;
714 m_paperSize
= data
.m_paperSize
;
716 // PostScript-specific data
717 m_printerCommand
= data
.m_printerCommand
;
718 m_previewCommand
= data
.m_previewCommand
;
719 m_printerOptions
= data
.m_printerOptions
;
720 m_filename
= data
.m_filename
;
721 m_afmPath
= data
.m_afmPath
;
722 m_printerScaleX
= data
.m_printerScaleX
;
723 m_printerScaleY
= data
.m_printerScaleY
;
724 m_printerTranslateX
= data
.m_printerTranslateX
;
725 m_printerTranslateY
= data
.m_printerTranslateY
;
726 m_printMode
= data
.m_printMode
;
729 // Is this data OK for showing the print dialog?
730 bool wxPrintData::Ok() const
733 ((wxPrintData
*)this)->ConvertToNative();
734 return (m_devMode
!= NULL
) ;
740 // ----------------------------------------------------------------------------
742 // ----------------------------------------------------------------------------
744 wxPrintDialogData::wxPrintDialogData()
747 m_printDlgData
= NULL
;
754 m_printAllPages
= FALSE
;
755 m_printCollate
= FALSE
;
756 m_printToFile
= FALSE
;
757 m_printSelection
= FALSE
;
758 m_printEnableSelection
= FALSE
;
759 m_printEnablePageNumbers
= TRUE
;
760 m_printEnablePrintToFile
= TRUE
;
761 m_printEnableHelp
= FALSE
;
762 m_printSetupDialog
= FALSE
;
765 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
769 m_printDlgData
= NULL
;
771 (*this) = dialogData
;
774 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
777 m_printDlgData
= NULL
;
782 m_printMaxPage
= 9999;
784 m_printAllPages
= FALSE
;
785 m_printCollate
= FALSE
;
786 m_printToFile
= FALSE
;
787 m_printSelection
= FALSE
;
788 m_printEnableSelection
= FALSE
;
789 m_printEnablePageNumbers
= TRUE
;
790 m_printEnablePrintToFile
= TRUE
;
791 m_printEnableHelp
= FALSE
;
792 m_printSetupDialog
= FALSE
;
794 m_printData
= printData
;
797 wxPrintDialogData::~wxPrintDialogData()
800 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
801 if ( pd
&& pd
->hDevMode
)
802 GlobalFree(pd
->hDevMode
);
809 void wxPrintDialogData::ConvertToNative()
811 m_printData
.ConvertToNative();
813 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
818 memset( pd
, 0, sizeof(PRINTDLG
) );
819 m_printDlgData
= (void*) pd
;
821 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
823 pd
->lStructSize
= 66;
825 pd
->lStructSize
= sizeof(PRINTDLG
);
827 pd
->hwndOwner
= (HWND
)NULL
;
828 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
829 pd
->hDevNames
= NULL
; // Ditto
831 pd
->Flags
= PD_RETURNDEFAULT
;
835 // Pass the devmode data to the PRINTDLG structure, since it'll
836 // be needed when PrintDlg is called.
839 GlobalFree(pd
->hDevMode
);
842 // Pass the devnames data to the PRINTDLG structure, since it'll
843 // be needed when PrintDlg is called.
846 GlobalFree(pd
->hDevNames
);
849 pd
->hDevMode
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeData();
851 m_printData
.SetNativeData((void*) NULL
);
853 // Shouldn't assert; we should be able to test Ok-ness at a higher level
854 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
856 pd
->hDevNames
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeDataDevNames();
858 m_printData
.SetNativeDataDevNames((void*) NULL
);
860 pd
->hDC
= (HDC
) NULL
;
861 pd
->nFromPage
= (WORD
)m_printFromPage
;
862 pd
->nToPage
= (WORD
)m_printToPage
;
863 pd
->nMinPage
= (WORD
)m_printMinPage
;
864 pd
->nMaxPage
= (WORD
)m_printMaxPage
;
865 pd
->nCopies
= (WORD
)m_printNoCopies
;
867 pd
->Flags
= PD_RETURNDC
;
870 pd
->lStructSize
= 66;
872 pd
->lStructSize
= sizeof( PRINTDLG
);
875 pd
->hwndOwner
=(HWND
)NULL
;
876 // pd->hDevNames=(HANDLE)NULL;
877 pd
->hInstance
=(HINSTANCE
)NULL
;
878 pd
->lCustData
= (LPARAM
) NULL
;
879 pd
->lpfnPrintHook
= NULL
;
880 pd
->lpfnSetupHook
= NULL
;
881 pd
->lpPrintTemplateName
= NULL
;
882 pd
->lpSetupTemplateName
= NULL
;
883 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
884 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
886 if ( m_printAllPages
)
887 pd
->Flags
|= PD_ALLPAGES
;
888 if ( m_printSelection
)
889 pd
->Flags
|= PD_SELECTION
;
890 if ( m_printCollate
)
891 pd
->Flags
|= PD_COLLATE
;
893 pd
->Flags
|= PD_PRINTTOFILE
;
894 if ( !m_printEnablePrintToFile
)
895 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
896 if ( !m_printEnableSelection
)
897 pd
->Flags
|= PD_NOSELECTION
;
898 if ( !m_printEnablePageNumbers
)
899 pd
->Flags
|= PD_NOPAGENUMS
;
900 else if ( (!m_printAllPages
) && (!m_printSelection
) && (m_printFromPage
!= 0) && (m_printToPage
!= 0))
901 pd
->Flags
|= PD_PAGENUMS
;
902 if ( m_printEnableHelp
)
903 pd
->Flags
|= PD_SHOWHELP
;
904 if ( m_printSetupDialog
)
905 pd
->Flags
|= PD_PRINTSETUP
;
908 void wxPrintDialogData::ConvertFromNative()
910 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
914 // Pass the devmode data back to the wxPrintData structure where it really belongs.
917 if (m_printData
.GetNativeData())
919 // Make sure we don't leak memory
920 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeData());
922 m_printData
.SetNativeData((void*)(long) pd
->hDevMode
);
926 // Pass the devnames data back to the wxPrintData structure where it really belongs.
929 if (m_printData
.GetNativeDataDevNames())
931 // Make sure we don't leak memory
932 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeDataDevNames());
934 m_printData
.SetNativeDataDevNames((void*)(long) pd
->hDevNames
);
935 pd
->hDevNames
= NULL
;
938 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
939 // into wxWindows form.
940 m_printData
.ConvertFromNative();
942 m_printFromPage
= pd
->nFromPage
;
943 m_printToPage
= pd
->nToPage
;
944 m_printMinPage
= pd
->nMinPage
;
945 m_printMaxPage
= pd
->nMaxPage
;
946 m_printNoCopies
= pd
->nCopies
;
948 m_printAllPages
= (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
));
949 m_printSelection
= ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
);
950 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
951 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
952 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
953 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
954 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
955 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
956 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
958 /* port is obsolete in WIN32
962 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
964 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
965 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
966 GlobalUnlock(pd->hDevNames);
968 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
974 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
976 if ( m_printDlgData
== NULL
)
979 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
981 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
982 pd
->hwndOwner
=(HWND
) win
->GetHWND();
989 void wxPrintDialogData::ConvertToNative()
991 m_printData
.ConvertToNative();
992 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
995 void wxPrintDialogData::ConvertFromNative()
997 m_printData
.ConvertFromNative();
998 m_printData
.m_nativePrintData
->TransferTo( this ) ;
1004 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
1006 m_printFromPage
= data
.m_printFromPage
;
1007 m_printToPage
= data
.m_printToPage
;
1008 m_printMinPage
= data
.m_printMinPage
;
1009 m_printMaxPage
= data
.m_printMaxPage
;
1010 m_printNoCopies
= data
.m_printNoCopies
;
1011 m_printAllPages
= data
.m_printAllPages
;
1012 m_printCollate
= data
.m_printCollate
;
1013 m_printToFile
= data
.m_printToFile
;
1014 m_printSelection
= data
.m_printSelection
;
1015 m_printEnableSelection
= data
.m_printEnableSelection
;
1016 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
1017 m_printEnableHelp
= data
.m_printEnableHelp
;
1018 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
1019 m_printSetupDialog
= data
.m_printSetupDialog
;
1021 m_printData
= data
.m_printData
;
1024 void wxPrintDialogData::operator=(const wxPrintData
& data
)
1029 // ----------------------------------------------------------------------------
1030 // wxPageSetupDialogData
1031 // ----------------------------------------------------------------------------
1033 wxPageSetupDialogData::wxPageSetupDialogData()
1035 #if defined(__WIN95__)
1036 m_pageSetupData
= NULL
;
1038 m_paperSize
= wxSize(0, 0);
1040 CalculatePaperSizeFromId();
1042 m_minMarginTopLeft
= wxPoint(0, 0);
1043 m_minMarginBottomRight
= wxPoint(0, 0);
1044 m_marginTopLeft
= wxPoint(0, 0);
1045 m_marginBottomRight
= wxPoint(0, 0);
1048 m_defaultMinMargins
= FALSE
;
1049 m_enableMargins
= TRUE
;
1050 m_enableOrientation
= TRUE
;
1051 m_enablePaper
= TRUE
;
1052 m_enablePrinter
= TRUE
;
1053 m_enableHelp
= FALSE
;
1054 m_getDefaultInfo
= FALSE
;
1057 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
1060 #if defined(__WIN95__)
1061 m_pageSetupData
= NULL
;
1063 (*this) = dialogData
;
1066 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
1068 #if defined(__WIN95__)
1069 m_pageSetupData
= NULL
;
1071 m_paperSize
= wxSize(0, 0);
1072 m_minMarginTopLeft
= wxPoint(0, 0);
1073 m_minMarginBottomRight
= wxPoint(0, 0);
1074 m_marginTopLeft
= wxPoint(0, 0);
1075 m_marginBottomRight
= wxPoint(0, 0);
1078 m_defaultMinMargins
= FALSE
;
1079 m_enableMargins
= TRUE
;
1080 m_enableOrientation
= TRUE
;
1081 m_enablePaper
= TRUE
;
1082 m_enablePrinter
= TRUE
;
1083 m_enableHelp
= FALSE
;
1084 m_getDefaultInfo
= FALSE
;
1086 m_printData
= printData
;
1088 // The wxPrintData paper size overrides these values, unless the size cannot
1090 CalculatePaperSizeFromId();
1093 wxPageSetupDialogData::~wxPageSetupDialogData()
1095 #if defined(__WIN95__) && defined(__WXMSW__)
1096 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
1097 if ( pd
&& pd
->hDevMode
)
1098 GlobalFree(pd
->hDevMode
);
1099 if ( pd
&& pd
->hDevNames
)
1100 GlobalFree(pd
->hDevNames
);
1106 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
1108 m_paperSize
= data
.m_paperSize
;
1109 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
1110 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
1111 m_marginTopLeft
= data
.m_marginTopLeft
;
1112 m_marginBottomRight
= data
.m_marginBottomRight
;
1113 m_defaultMinMargins
= data
.m_defaultMinMargins
;
1114 m_enableMargins
= data
.m_enableMargins
;
1115 m_enableOrientation
= data
.m_enableOrientation
;
1116 m_enablePaper
= data
.m_enablePaper
;
1117 m_enablePrinter
= data
.m_enablePrinter
;
1118 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
1119 m_enableHelp
= data
.m_enableHelp
;
1121 m_printData
= data
.m_printData
;
1126 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
1133 #if defined(__WIN95__)
1134 void wxPageSetupDialogData::ConvertToNative()
1136 m_printData
.ConvertToNative();
1138 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1140 if ( m_pageSetupData
== NULL
)
1142 pd
= new PAGESETUPDLG
;
1143 pd
->hDevMode
= NULL
;
1144 pd
->hDevNames
= NULL
;
1145 m_pageSetupData
= (void *)pd
;
1148 // Pass the devmode data (created in m_printData.ConvertToNative)
1149 // to the PRINTDLG structure, since it'll
1150 // be needed when PrintDlg is called.
1154 GlobalFree(pd
->hDevMode
);
1155 pd
->hDevMode
= NULL
;
1158 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
1160 m_printData
.SetNativeData((void*) NULL
);
1162 // Shouldn't assert; we should be able to test Ok-ness at a higher level
1163 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
1165 // Pass the devnames data (created in m_printData.ConvertToNative)
1166 // to the PRINTDLG structure, since it'll
1167 // be needed when PrintDlg is called.
1171 GlobalFree(pd
->hDevNames
);
1172 pd
->hDevNames
= NULL
;
1175 pd
->hDevNames
= (HGLOBAL
) m_printData
.GetNativeDataDevNames();
1177 m_printData
.SetNativeDataDevNames((void*) NULL
);
1179 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1181 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1183 if ( m_defaultMinMargins
)
1184 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
1185 if ( !m_enableMargins
)
1186 pd
->Flags
|= PSD_DISABLEMARGINS
;
1187 if ( !m_enableOrientation
)
1188 pd
->Flags
|= PSD_DISABLEORIENTATION
;
1189 if ( !m_enablePaper
)
1190 pd
->Flags
|= PSD_DISABLEPAPER
;
1191 if ( !m_enablePrinter
)
1192 pd
->Flags
|= PSD_DISABLEPRINTER
;
1193 if ( m_getDefaultInfo
)
1194 pd
->Flags
|= PSD_RETURNDEFAULT
;
1196 pd
->Flags
|= PSD_SHOWHELP
;
1198 // We want the units to be in hundredths of a millimetre
1199 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1201 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
1202 pd
->hwndOwner
=(HWND
)NULL
;
1203 // pd->hDevNames=(HWND)NULL;
1204 pd
->hInstance
=(HINSTANCE
)NULL
;
1205 // PAGESETUPDLG is in hundreds of a mm
1206 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
1207 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
1209 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
1210 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
1211 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
1212 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
1214 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
1215 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
1216 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
1217 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
1220 pd
->lpfnPageSetupHook
= NULL
;
1221 pd
->lpfnPagePaintHook
= NULL
;
1222 pd
->hPageSetupTemplate
= NULL
;
1223 pd
->lpPageSetupTemplateName
= NULL
;
1228 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1229 memset(devMode, 0, sizeof(DEVMODE));
1230 devMode->dmSize = sizeof(DEVMODE);
1231 devMode->dmOrientation = m_orientation;
1232 devMode->dmFields = DM_ORIENTATION;
1233 GlobalUnlock(pd->hDevMode);
1238 void wxPageSetupDialogData::ConvertFromNative()
1240 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1244 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1247 if (m_printData
.GetNativeData())
1249 // Make sure we don't leak memory
1250 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1252 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1253 pd
->hDevMode
= NULL
;
1256 m_printData
.ConvertFromNative();
1258 // Pass the devnames data back to the wxPrintData structure where it really belongs.
1261 if (m_printData
.GetNativeDataDevNames())
1263 // Make sure we don't leak memory
1264 GlobalFree((HGLOBAL
) m_printData
.GetNativeDataDevNames());
1266 m_printData
.SetNativeDataDevNames((void*) pd
->hDevNames
);
1267 pd
->hDevNames
= NULL
;
1270 m_printData
.ConvertFromNative();
1272 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1274 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
1275 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
1276 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
1277 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
1278 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
1279 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
1280 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
1282 // PAGESETUPDLG is in hundreds of a mm
1283 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1284 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
1286 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
1287 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
1288 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
1289 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
1291 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100;
1292 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100;
1293 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100;
1294 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100;
1297 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1299 if ( m_pageSetupData
== NULL
)
1302 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1304 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1305 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1311 void wxPageSetupDialogData::ConvertToNative()
1313 m_printData
.ConvertToNative();
1314 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
1317 void wxPageSetupDialogData::ConvertFromNative()
1319 m_printData
.ConvertFromNative ();
1320 m_paperSize
= m_printData
.GetPaperSize() ;
1321 CalculateIdFromPaperSize();
1322 m_printData
.m_nativePrintData
->TransferTo( this ) ;
1323 // adjust minimal values
1325 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
1326 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
1328 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
1329 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
1331 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
1332 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
1334 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
1335 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
1340 // If a corresponding paper type is found in the paper database, will set the m_printData
1341 // paper size id member as well.
1342 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
1346 CalculateIdFromPaperSize();
1349 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1350 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1352 m_printData
.SetPaperId(id
);
1354 CalculatePaperSizeFromId();
1357 // Use paper size defined in this object to set the wxPrintData
1359 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1361 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1362 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
1364 wxSize sz
= GetPaperSize();
1366 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1367 if (id
!= wxPAPER_NONE
)
1369 m_printData
.SetPaperId(id
);
1373 // Use paper id in wxPrintData to set this object's paper size
1374 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1376 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1377 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
1379 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
1381 // sz is in 10ths of a mm, while paper size is in mm
1382 m_paperSize
.x
= sz
.x
/ 10;
1383 m_paperSize
.y
= sz
.y
/ 10;
1386 #endif // wxUSE_PRINTING_ARCHITECTURE