1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI data
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 #ifndef __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 m_dataColour
.Set(0,0,0);
93 // m_custColours are wxNullColours initially
96 wxColourData::wxColourData(const wxColourData
& data
)
102 wxColourData::~wxColourData()
106 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
108 wxCHECK_RET( (i
>= 0 && i
< 16), _T("custom colour index out of range") );
110 m_custColours
[i
] = colour
;
113 wxColour
wxColourData::GetCustomColour(int i
)
115 wxCHECK_MSG( (i
>= 0 && i
< 16), wxColour(0,0,0),
116 _T("custom colour index out of range") );
118 return m_custColours
[i
];
121 void wxColourData::operator=(const wxColourData
& data
)
124 for (i
= 0; i
< 16; i
++)
125 m_custColours
[i
] = data
.m_custColours
[i
];
127 m_dataColour
= (wxColour
&)data
.m_dataColour
;
128 m_chooseFull
= data
.m_chooseFull
;
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
135 wxFontData::wxFontData()
137 // Intialize colour to black.
138 m_fontColour
= wxNullColour
;
141 m_allowSymbols
= true;
142 m_enableEffects
= true;
146 m_encoding
= wxFONTENCODING_SYSTEM
;
149 wxFontData::~wxFontData()
155 wxFontDialogBase::~wxFontDialogBase()
159 #endif // wxUSE_FONTDLG
161 #if wxUSE_PRINTING_ARCHITECTURE
162 // ----------------------------------------------------------------------------
164 // ----------------------------------------------------------------------------
166 wxPrintData::wxPrintData()
169 m_devMode
= (void*) NULL
;
170 m_devNames
= (void*) NULL
;
171 #elif defined( __WXMAC__ )
172 m_nativePrintData
= wxNativePrintData::Create() ;
174 m_bin
= wxPRINTBIN_DEFAULT
;
175 m_printOrientation
= wxPORTRAIT
;
177 m_printCollate
= false;
180 m_printerName
= wxT("");
182 m_duplexMode
= wxDUPLEX_SIMPLEX
;
183 m_printQuality
= wxPRINT_QUALITY_HIGH
;
184 m_paperId
= wxPAPER_A4
;
185 m_paperSize
= wxSize(210, 297);
187 // PostScript-specific data
188 m_previewCommand
= wxT("");
189 m_filename
= wxT("");
191 m_printerCommand
= wxT("print");
192 m_printerOptions
= wxT("/nonotify/queue=psqueue");
193 m_afmPath
= wxT("sys$ps_font_metrics:");
197 m_printerCommand
= wxT("print");
198 m_printerOptions
= wxT("");
199 m_afmPath
= wxT("c:\\windows\\system\\");
202 #if !defined(__VMS__) && !defined(__WXMSW__)
203 m_printerCommand
= wxT("lpr");
204 m_printerOptions
= wxT("");
208 m_printerScaleX
= 1.0;
209 m_printerScaleY
= 1.0;
210 m_printerTranslateX
= 0;
211 m_printerTranslateY
= 0;
212 m_printMode
= wxPRINT_MODE_FILE
;
215 m_outputstream
= NULL
;
219 wxPrintData::wxPrintData(const wxPrintData
& printData
)
223 m_devMode
= (void*) NULL
;
224 m_devNames
= (void*) NULL
;
225 #elif defined( __WXMAC__ )
226 m_nativePrintData
= wxNativePrintData::Create() ;
231 wxPrintData::~wxPrintData()
234 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
236 GlobalFree(hDevMode
);
237 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
239 GlobalFree(hDevNames
);
240 #elif defined(__WXMAC__)
241 delete m_nativePrintData
;
245 #if defined(__WXMSW__) // && defined(__WIN32__)
247 #if defined(__WXDEBUG__) && defined(__WIN32__)
248 static wxString
wxGetPrintDlgError()
250 DWORD err
= CommDlgExtendedError();
251 wxString msg
= wxT("Unknown");
254 case CDERR_FINDRESFAILURE
: msg
= wxT("CDERR_FINDRESFAILURE"); break;
255 case CDERR_INITIALIZATION
: msg
= wxT("CDERR_INITIALIZATION"); break;
256 case CDERR_LOADRESFAILURE
: msg
= wxT("CDERR_LOADRESFAILURE"); break;
257 case CDERR_LOADSTRFAILURE
: msg
= wxT("CDERR_LOADSTRFAILURE"); break;
258 case CDERR_LOCKRESFAILURE
: msg
= wxT("CDERR_LOCKRESFAILURE"); break;
259 case CDERR_MEMALLOCFAILURE
: msg
= wxT("CDERR_MEMALLOCFAILURE"); break;
260 case CDERR_MEMLOCKFAILURE
: msg
= wxT("CDERR_MEMLOCKFAILURE"); break;
261 case CDERR_NOHINSTANCE
: msg
= wxT("CDERR_NOHINSTANCE"); break;
262 case CDERR_NOHOOK
: msg
= wxT("CDERR_NOHOOK"); break;
263 case CDERR_NOTEMPLATE
: msg
= wxT("CDERR_NOTEMPLATE"); break;
264 case CDERR_STRUCTSIZE
: msg
= wxT("CDERR_STRUCTSIZE"); break;
265 case PDERR_RETDEFFAILURE
: msg
= wxT("PDERR_RETDEFFAILURE"); break;
266 case PDERR_PRINTERNOTFOUND
: msg
= wxT("PDERR_PRINTERNOTFOUND"); break;
267 case PDERR_PARSEFAILURE
: msg
= wxT("PDERR_PARSEFAILURE"); break;
268 case PDERR_NODEVICES
: msg
= wxT("PDERR_NODEVICES"); break;
269 case PDERR_NODEFAULTPRN
: msg
= wxT("PDERR_NODEFAULTPRN"); break;
270 case PDERR_LOADDRVFAILURE
: msg
= wxT("PDERR_LOADDRVFAILURE"); break;
271 case PDERR_INITFAILURE
: msg
= wxT("PDERR_INITFAILURE"); break;
272 case PDERR_GETDEVMODEFAIL
: msg
= wxT("PDERR_GETDEVMODEFAIL"); break;
273 case PDERR_DNDMMISMATCH
: msg
= wxT("PDERR_DNDMMISMATCH"); break;
274 case PDERR_DEFAULTDIFFERENT
: msg
= wxT("PDERR_DEFAULTDIFFERENT"); break;
275 case PDERR_CREATEICFAILURE
: msg
= wxT("PDERR_CREATEICFAILURE"); break;
282 static HGLOBAL
wxCreateDevNames(const wxString
& driverName
, const wxString
& printerName
, const wxString
& portName
)
285 // if (!driverName.IsEmpty() && !printerName.IsEmpty() && !portName.IsEmpty())
286 if (driverName
.IsEmpty() && printerName
.IsEmpty() && portName
.IsEmpty())
291 hDev
= GlobalAlloc(GPTR
, 4*sizeof(WORD
)+
292 ( driverName
.Length() + 1 +
293 printerName
.Length() + 1 +
294 portName
.Length()+1 ) * sizeof(wxChar
) );
295 LPDEVNAMES lpDev
= (LPDEVNAMES
)GlobalLock(hDev
);
296 lpDev
->wDriverOffset
= sizeof(WORD
)*4;
297 wxStrcpy((wxChar
*)((char*)lpDev
+ lpDev
->wDriverOffset
), driverName
);
299 lpDev
->wDeviceOffset
= (WORD
)( lpDev
->wDriverOffset
+
300 sizeof(wxChar
) * ( driverName
.Length() + 1 ) );
301 wxStrcpy((wxChar
*)((char*)lpDev
+ lpDev
->wDeviceOffset
), printerName
);
303 lpDev
->wOutputOffset
= (WORD
)( lpDev
->wDeviceOffset
+
304 sizeof(wxChar
) * ( printerName
.Length() + 1 ) );
305 wxStrcpy((wxChar
*)((char*) lpDev
+ lpDev
->wOutputOffset
), portName
);
315 void wxPrintData::ConvertToNative()
317 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
318 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
321 // Use PRINTDLG as a way of creating a DEVMODE object
324 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
329 memset(&pd
, 0, sizeof(PRINTDLG
));
331 pd
.cbStruct
= sizeof(PRINTDLG
);
333 pd
.lStructSize
= sizeof(PRINTDLG
);
337 pd
.hwndOwner
= (HWND
)NULL
;
338 pd
.hDevMode
= NULL
; // Will be created by PrintDlg
339 pd
.hDevNames
= NULL
; // Ditto
340 //pd.hInstance = (HINSTANCE) wxGetInstance();
342 pd
.Flags
= PD_RETURNDEFAULT
;
345 // Fill out the DEVMODE structure
346 // so we can use it as input in the 'real' PrintDlg
350 GlobalFree(pd
.hDevMode
);
352 GlobalFree(pd
.hDevNames
);
356 #if defined(__WXDEBUG__) && defined(__WIN32__)
357 wxString
str(wxT("Printing error: "));
358 str
+= wxGetPrintDlgError();
364 hDevMode
= pd
.hDevMode
;
365 m_devMode
= (void*)(long) hDevMode
;
368 // We'll create a new DEVNAMEs structure below.
370 GlobalFree(pd
.hDevNames
);
373 // hDevNames = pd->hDevNames;
374 // m_devNames = (void*)(long) hDevNames;
375 // pd->hDevnames = NULL;
382 LPDEVMODE devMode
= (LPDEVMODE
) GlobalLock(hDevMode
);
386 devMode
->dmOrientation
= m_printOrientation
;
390 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
391 devMode
->dmFields
|= DM_COLLATE
;
393 //// Number of copies
395 devMode
->dmCopies
= m_printNoCopies
;
396 devMode
->dmFields
|= DM_COPIES
;
400 if (m_printerName
!= wxT(""))
402 //int len = wxMin(31, m_printerName.Len());
403 wxStrncpy((wxChar
*)devMode
->dmDeviceName
,m_printerName
.c_str(),31);
404 devMode
->dmDeviceName
[31] = wxT('\0');
410 devMode
->dmColor
= DMCOLOR_COLOR
;
412 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
414 devMode
->dmFields
|= DM_COLOR
;
418 if (m_paperId
== wxPAPER_NONE
)
420 // DEVMODE is in tenths of a milimeter
421 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
422 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
423 devMode
->dmPaperSize
= DMPAPER_USER
;
424 devMode
->dmFields
|= DM_PAPERWIDTH
;
425 devMode
->dmFields
|= DM_PAPERLENGTH
;
429 if (wxThePrintPaperDatabase
)
431 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
434 devMode
->dmPaperSize
= paper
->GetPlatformId();
435 devMode
->dmFields
|= DM_PAPERSIZE
;
443 switch (m_duplexMode
)
445 case wxDUPLEX_HORIZONTAL
: {
446 duplex
= DMDUP_HORIZONTAL
; break;
448 case wxDUPLEX_VERTICAL
: {
449 duplex
= DMDUP_VERTICAL
; break;
452 case wxDUPLEX_SIMPLEX
: {
453 duplex
= DMDUP_SIMPLEX
; break;
456 devMode
->dmDuplex
= duplex
;
457 devMode
->dmFields
|= DM_DUPLEX
;
462 switch (m_printQuality
)
464 case wxPRINT_QUALITY_MEDIUM
: {
465 quality
= DMRES_MEDIUM
; break;
467 case wxPRINT_QUALITY_LOW
: {
468 quality
= DMRES_LOW
; break;
470 case wxPRINT_QUALITY_DRAFT
: {
471 quality
= DMRES_DRAFT
; break;
473 case wxPRINT_QUALITY_HIGH
: {
474 quality
= DMRES_HIGH
; break;
477 quality
= m_printQuality
; break;
480 devMode
->dmPrintQuality
= quality
;
481 devMode
->dmFields
|= DM_PRINTQUALITY
;
483 if ( m_bin
!= wxPRINTBIN_DEFAULT
)
487 case wxPRINTBIN_ONLYONE
: devMode
->dmDefaultSource
= DMBIN_ONLYONE
; break;
488 case wxPRINTBIN_LOWER
: devMode
->dmDefaultSource
= DMBIN_LOWER
; break;
489 case wxPRINTBIN_MIDDLE
: devMode
->dmDefaultSource
= DMBIN_MIDDLE
; break;
490 case wxPRINTBIN_MANUAL
: devMode
->dmDefaultSource
= DMBIN_MANUAL
; break;
491 case wxPRINTBIN_ENVELOPE
: devMode
->dmDefaultSource
= DMBIN_ENVELOPE
; break;
492 case wxPRINTBIN_ENVMANUAL
: devMode
->dmDefaultSource
= DMBIN_ENVMANUAL
; break;
493 case wxPRINTBIN_AUTO
: devMode
->dmDefaultSource
= DMBIN_AUTO
,; break;
494 case wxPRINTBIN_TRACTOR
: devMode
->dmDefaultSource
= DMBIN_TRACTOR
; break;
495 case wxPRINTBIN_SMALLFMT
: devMode
->dmDefaultSource
= DMBIN_SMALLFMT
; break;
496 case wxPRINTBIN_LARGEFMT
: devMode
->dmDefaultSource
= DMBIN_LARGEFMT
; break;
497 case wxPRINTBIN_LARGECAPACITY
: devMode
->dmDefaultSource
= DMBIN_LARGECAPACITY
; break;
498 case wxPRINTBIN_CASSETTE
: devMode
->dmDefaultSource
= DMBIN_CASSETTE
; break;
499 case wxPRINTBIN_FORMSOURCE
: devMode
->dmDefaultSource
= DMBIN_FORMSOURCE
; break;
502 devMode
->dmDefaultSource
= DMBIN_USER
+ m_bin
- wxPRINTBIN_USER
;
506 devMode
->dmFields
|= DM_DEFAULTSOURCE
;
509 GlobalUnlock(hDevMode
);
514 GlobalFree(hDevNames
);
517 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
518 m_devNames
= (void*) (long) wxCreateDevNames(wxT(""), m_printerName
, wxT(""));
521 void wxPrintData::ConvertFromNative()
523 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
524 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
531 LPDEVMODE devMode
= (LPDEVMODE
)GlobalLock(hDevMode
);
535 if (devMode
->dmFields
& DM_ORIENTATION
)
536 m_printOrientation
= devMode
->dmOrientation
;
540 if (devMode
->dmFields
& DM_COLLATE
)
542 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
543 m_printCollate
= true;
545 m_printCollate
= false;
548 //// Number of copies
550 if (devMode
->dmFields
& DM_COPIES
)
552 m_printNoCopies
= devMode
->dmCopies
;
555 if (devMode
->dmFields
& DM_DEFAULTSOURCE
)
557 m_bin
= devMode
->dmDefaultSource
;
562 if (devMode
->dmDeviceName
[0] != 0)
564 m_printerName
= devMode
->dmDeviceName
;
569 if (devMode
->dmFields
& DM_COLOR
)
571 if (devMode
->dmColor
== DMCOLOR_COLOR
)
581 // We don't know size of user defined paper and some buggy drivers
582 // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
583 // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
584 // code wouldn't set m_paperSize correctly.
585 if ((devMode
->dmFields
& DM_PAPERSIZE
) && (devMode
->dmPaperSize
< DMPAPER_USER
))
587 if (wxThePrintPaperDatabase
)
589 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
592 m_paperId
= paper
->GetId();
593 m_paperSize
.x
= paper
->GetWidth() / 10;
594 m_paperSize
.y
= paper
->GetHeight() / 10;
598 // Shouldn't really get here
599 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
601 m_paperId
= wxPAPER_NONE
;
608 // Shouldn't really get here
609 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
611 m_paperId
= wxPAPER_NONE
;
616 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
618 // DEVMODE is in tenths of a milimeter
619 m_paperSize
.x
= devMode
->dmPaperWidth
/ 10;
620 m_paperSize
.y
= devMode
->dmPaperLength
/ 10;
621 m_paperId
= wxPAPER_NONE
;
625 // Shouldn't really get here
626 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
630 m_paperId
= wxPAPER_NONE
;
635 if (devMode
->dmFields
& DM_DUPLEX
)
637 switch (devMode
->dmDuplex
)
639 case DMDUP_HORIZONTAL
: {
640 m_duplexMode
= wxDUPLEX_HORIZONTAL
; break;
642 case DMDUP_VERTICAL
: {
643 m_duplexMode
= wxDUPLEX_VERTICAL
; break;
646 case DMDUP_SIMPLEX
: {
647 m_duplexMode
= wxDUPLEX_SIMPLEX
; break;
652 m_duplexMode
= wxDUPLEX_SIMPLEX
;
656 if (devMode
->dmFields
& DM_PRINTQUALITY
)
658 switch (devMode
->dmPrintQuality
)
661 m_printQuality
= wxPRINT_QUALITY_MEDIUM
; break;
664 m_printQuality
= wxPRINT_QUALITY_LOW
; break;
667 m_printQuality
= wxPRINT_QUALITY_DRAFT
; break;
670 m_printQuality
= wxPRINT_QUALITY_HIGH
; break;
674 // TODO: if the printer fills in the resolution in DPI, how
675 // will the application know if it's high, low, draft etc.??
676 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
677 m_printQuality
= devMode
->dmPrintQuality
; break;
683 m_printQuality
= wxPRINT_QUALITY_HIGH
;
685 GlobalUnlock(hDevMode
);
690 LPDEVNAMES lpDevNames
= (LPDEVNAMES
)GlobalLock(hDevNames
);
693 // TODO: Unicode-ification
696 // port is obsolete in WIN32
697 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
699 // Get the printer name
700 wxString printerName
= (LPTSTR
)lpDevNames
+ lpDevNames
->wDeviceOffset
;
702 // Not sure if we should check for this mismatch
703 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
705 if (printerName
!= wxT(""))
706 m_printerName
= printerName
;
708 GlobalUnlock(hDevNames
);
717 void wxPrintData::ConvertToNative()
719 m_nativePrintData
->TransferFrom( this ) ;
722 void wxPrintData::ConvertFromNative()
724 m_nativePrintData
->TransferTo( this ) ;
729 void wxPrintData::operator=(const wxPrintData
& data
)
732 m_nativePrintData
->CopyFrom( data
.m_nativePrintData
) ;
734 m_printNoCopies
= data
.m_printNoCopies
;
735 m_printCollate
= data
.m_printCollate
;
736 m_printOrientation
= data
.m_printOrientation
;
737 m_printerName
= data
.m_printerName
;
738 m_colour
= data
.m_colour
;
739 m_duplexMode
= data
.m_duplexMode
;
740 m_printQuality
= data
.m_printQuality
;
741 m_paperId
= data
.m_paperId
;
742 m_paperSize
= data
.m_paperSize
;
745 m_outputstream
= data
.m_outputstream
;
748 // PostScript-specific data
749 m_printerCommand
= data
.m_printerCommand
;
750 m_previewCommand
= data
.m_previewCommand
;
751 m_printerOptions
= data
.m_printerOptions
;
752 m_filename
= data
.m_filename
;
753 m_afmPath
= data
.m_afmPath
;
754 m_printerScaleX
= data
.m_printerScaleX
;
755 m_printerScaleY
= data
.m_printerScaleY
;
756 m_printerTranslateX
= data
.m_printerTranslateX
;
757 m_printerTranslateY
= data
.m_printerTranslateY
;
758 m_printMode
= data
.m_printMode
;
761 // Is this data OK for showing the print dialog?
762 bool wxPrintData::Ok() const
765 ((wxPrintData
*)this)->ConvertToNative();
766 return (m_devMode
!= NULL
) ;
772 // ----------------------------------------------------------------------------
774 // ----------------------------------------------------------------------------
776 wxPrintDialogData::wxPrintDialogData()
779 m_printDlgData
= NULL
;
786 m_printAllPages
= false;
787 m_printCollate
= false;
788 m_printToFile
= false;
789 m_printSelection
= false;
790 m_printEnableSelection
= false;
791 m_printEnablePageNumbers
= true;
792 m_printEnablePrintToFile
= true;
793 m_printEnableHelp
= false;
794 m_printSetupDialog
= false;
797 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
801 m_printDlgData
= NULL
;
803 (*this) = dialogData
;
806 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
809 m_printDlgData
= NULL
;
814 m_printMaxPage
= 9999;
816 m_printAllPages
= false;
817 m_printCollate
= false;
818 m_printToFile
= false;
819 m_printSelection
= false;
820 m_printEnableSelection
= false;
821 m_printEnablePageNumbers
= true;
822 m_printEnablePrintToFile
= true;
823 m_printEnableHelp
= false;
824 m_printSetupDialog
= false;
826 m_printData
= printData
;
829 wxPrintDialogData::~wxPrintDialogData()
832 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
833 if ( pd
&& pd
->hDevMode
)
834 GlobalFree(pd
->hDevMode
);
841 void wxPrintDialogData::ConvertToNative()
843 m_printData
.ConvertToNative();
845 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
850 memset( pd
, 0, sizeof(PRINTDLG
) );
851 m_printDlgData
= (void*) pd
;
853 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
855 pd
->lStructSize
= 66;
857 pd
->lStructSize
= sizeof(PRINTDLG
);
859 pd
->hwndOwner
= (HWND
)NULL
;
860 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
861 pd
->hDevNames
= NULL
; // Ditto
863 pd
->Flags
= PD_RETURNDEFAULT
;
867 // Pass the devmode data to the PRINTDLG structure, since it'll
868 // be needed when PrintDlg is called.
871 GlobalFree(pd
->hDevMode
);
874 // Pass the devnames data to the PRINTDLG structure, since it'll
875 // be needed when PrintDlg is called.
878 GlobalFree(pd
->hDevNames
);
881 pd
->hDevMode
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeData();
883 m_printData
.SetNativeData((void*) NULL
);
885 // Shouldn't assert; we should be able to test Ok-ness at a higher level
886 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
888 pd
->hDevNames
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeDataDevNames();
890 m_printData
.SetNativeDataDevNames((void*) NULL
);
892 pd
->hDC
= (HDC
) NULL
;
893 pd
->nFromPage
= (WORD
)m_printFromPage
;
894 pd
->nToPage
= (WORD
)m_printToPage
;
895 pd
->nMinPage
= (WORD
)m_printMinPage
;
896 pd
->nMaxPage
= (WORD
)m_printMaxPage
;
897 pd
->nCopies
= (WORD
)m_printNoCopies
;
899 pd
->Flags
= PD_RETURNDC
;
902 pd
->lStructSize
= 66;
904 pd
->lStructSize
= sizeof( PRINTDLG
);
907 pd
->hwndOwner
=(HWND
)NULL
;
908 // pd->hDevNames=(HANDLE)NULL;
909 pd
->hInstance
=(HINSTANCE
)NULL
;
910 pd
->lCustData
= (LPARAM
) NULL
;
911 pd
->lpfnPrintHook
= NULL
;
912 pd
->lpfnSetupHook
= NULL
;
913 pd
->lpPrintTemplateName
= NULL
;
914 pd
->lpSetupTemplateName
= NULL
;
915 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
916 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
918 if ( m_printAllPages
)
919 pd
->Flags
|= PD_ALLPAGES
;
920 if ( m_printSelection
)
921 pd
->Flags
|= PD_SELECTION
;
922 if ( m_printCollate
)
923 pd
->Flags
|= PD_COLLATE
;
925 pd
->Flags
|= PD_PRINTTOFILE
;
926 if ( !m_printEnablePrintToFile
)
927 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
928 if ( !m_printEnableSelection
)
929 pd
->Flags
|= PD_NOSELECTION
;
930 if ( !m_printEnablePageNumbers
)
931 pd
->Flags
|= PD_NOPAGENUMS
;
932 else if ( (!m_printAllPages
) && (!m_printSelection
) && (m_printFromPage
!= 0) && (m_printToPage
!= 0))
933 pd
->Flags
|= PD_PAGENUMS
;
934 if ( m_printEnableHelp
)
935 pd
->Flags
|= PD_SHOWHELP
;
936 if ( m_printSetupDialog
)
937 pd
->Flags
|= PD_PRINTSETUP
;
940 void wxPrintDialogData::ConvertFromNative()
942 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
946 // Pass the devmode data back to the wxPrintData structure where it really belongs.
949 if (m_printData
.GetNativeData())
951 // Make sure we don't leak memory
952 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeData());
954 m_printData
.SetNativeData((void*)(long) pd
->hDevMode
);
958 // Pass the devnames data back to the wxPrintData structure where it really belongs.
961 if (m_printData
.GetNativeDataDevNames())
963 // Make sure we don't leak memory
964 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeDataDevNames());
966 m_printData
.SetNativeDataDevNames((void*)(long) pd
->hDevNames
);
967 pd
->hDevNames
= NULL
;
970 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
971 // into wxWidgets form.
972 m_printData
.ConvertFromNative();
974 m_printFromPage
= pd
->nFromPage
;
975 m_printToPage
= pd
->nToPage
;
976 m_printMinPage
= pd
->nMinPage
;
977 m_printMaxPage
= pd
->nMaxPage
;
978 m_printNoCopies
= pd
->nCopies
;
980 m_printAllPages
= (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
));
981 m_printSelection
= ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
);
982 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
983 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
984 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
985 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
986 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
987 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
988 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
990 /* port is obsolete in WIN32
994 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
996 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
997 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
998 GlobalUnlock(pd->hDevNames);
1000 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
1006 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
1008 if ( m_printDlgData
== NULL
)
1011 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
1013 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
1014 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1021 void wxPrintDialogData::ConvertToNative()
1023 m_printData
.ConvertToNative();
1024 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
1027 void wxPrintDialogData::ConvertFromNative()
1029 m_printData
.ConvertFromNative();
1030 m_printData
.m_nativePrintData
->TransferTo( this ) ;
1036 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
1038 m_printFromPage
= data
.m_printFromPage
;
1039 m_printToPage
= data
.m_printToPage
;
1040 m_printMinPage
= data
.m_printMinPage
;
1041 m_printMaxPage
= data
.m_printMaxPage
;
1042 m_printNoCopies
= data
.m_printNoCopies
;
1043 m_printAllPages
= data
.m_printAllPages
;
1044 m_printCollate
= data
.m_printCollate
;
1045 m_printToFile
= data
.m_printToFile
;
1046 m_printSelection
= data
.m_printSelection
;
1047 m_printEnableSelection
= data
.m_printEnableSelection
;
1048 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
1049 m_printEnableHelp
= data
.m_printEnableHelp
;
1050 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
1051 m_printSetupDialog
= data
.m_printSetupDialog
;
1053 m_printData
= data
.m_printData
;
1056 void wxPrintDialogData::operator=(const wxPrintData
& data
)
1061 // ----------------------------------------------------------------------------
1062 // wxPageSetupDialogData
1063 // ----------------------------------------------------------------------------
1065 wxPageSetupDialogData::wxPageSetupDialogData()
1067 #if defined(__WIN95__)
1068 m_pageSetupData
= NULL
;
1070 m_paperSize
= wxSize(0, 0);
1072 CalculatePaperSizeFromId();
1074 m_minMarginTopLeft
= wxPoint(0, 0);
1075 m_minMarginBottomRight
= wxPoint(0, 0);
1076 m_marginTopLeft
= wxPoint(0, 0);
1077 m_marginBottomRight
= wxPoint(0, 0);
1080 m_defaultMinMargins
= false;
1081 m_enableMargins
= true;
1082 m_enableOrientation
= true;
1083 m_enablePaper
= true;
1084 m_enablePrinter
= true;
1085 m_enableHelp
= false;
1086 m_getDefaultInfo
= false;
1089 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
1092 #if defined(__WIN95__)
1093 m_pageSetupData
= NULL
;
1095 (*this) = dialogData
;
1098 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
1100 #if defined(__WIN95__)
1101 m_pageSetupData
= NULL
;
1103 m_paperSize
= wxSize(0, 0);
1104 m_minMarginTopLeft
= wxPoint(0, 0);
1105 m_minMarginBottomRight
= wxPoint(0, 0);
1106 m_marginTopLeft
= wxPoint(0, 0);
1107 m_marginBottomRight
= wxPoint(0, 0);
1110 m_defaultMinMargins
= false;
1111 m_enableMargins
= true;
1112 m_enableOrientation
= true;
1113 m_enablePaper
= true;
1114 m_enablePrinter
= true;
1115 m_enableHelp
= false;
1116 m_getDefaultInfo
= false;
1118 m_printData
= printData
;
1120 // The wxPrintData paper size overrides these values, unless the size cannot
1122 CalculatePaperSizeFromId();
1125 wxPageSetupDialogData::~wxPageSetupDialogData()
1127 #if defined(__WIN95__) && defined(__WXMSW__)
1128 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
1129 if ( pd
&& pd
->hDevMode
)
1130 GlobalFree(pd
->hDevMode
);
1131 if ( pd
&& pd
->hDevNames
)
1132 GlobalFree(pd
->hDevNames
);
1138 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
1140 m_paperSize
= data
.m_paperSize
;
1141 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
1142 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
1143 m_marginTopLeft
= data
.m_marginTopLeft
;
1144 m_marginBottomRight
= data
.m_marginBottomRight
;
1145 m_defaultMinMargins
= data
.m_defaultMinMargins
;
1146 m_enableMargins
= data
.m_enableMargins
;
1147 m_enableOrientation
= data
.m_enableOrientation
;
1148 m_enablePaper
= data
.m_enablePaper
;
1149 m_enablePrinter
= data
.m_enablePrinter
;
1150 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
1151 m_enableHelp
= data
.m_enableHelp
;
1153 m_printData
= data
.m_printData
;
1158 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
1165 #if defined(__WIN95__)
1166 void wxPageSetupDialogData::ConvertToNative()
1168 m_printData
.ConvertToNative();
1170 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1172 if ( m_pageSetupData
== NULL
)
1174 pd
= new PAGESETUPDLG
;
1175 pd
->hDevMode
= NULL
;
1176 pd
->hDevNames
= NULL
;
1177 m_pageSetupData
= (void *)pd
;
1180 // Pass the devmode data (created in m_printData.ConvertToNative)
1181 // to the PRINTDLG structure, since it'll
1182 // be needed when PrintDlg is called.
1186 GlobalFree(pd
->hDevMode
);
1187 pd
->hDevMode
= NULL
;
1190 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
1192 m_printData
.SetNativeData((void*) NULL
);
1194 // Shouldn't assert; we should be able to test Ok-ness at a higher level
1195 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
1197 // Pass the devnames data (created in m_printData.ConvertToNative)
1198 // to the PRINTDLG structure, since it'll
1199 // be needed when PrintDlg is called.
1203 GlobalFree(pd
->hDevNames
);
1204 pd
->hDevNames
= NULL
;
1207 pd
->hDevNames
= (HGLOBAL
) m_printData
.GetNativeDataDevNames();
1209 m_printData
.SetNativeDataDevNames((void*) NULL
);
1211 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1213 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1215 if ( m_defaultMinMargins
)
1216 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
1217 if ( !m_enableMargins
)
1218 pd
->Flags
|= PSD_DISABLEMARGINS
;
1219 if ( !m_enableOrientation
)
1220 pd
->Flags
|= PSD_DISABLEORIENTATION
;
1221 if ( !m_enablePaper
)
1222 pd
->Flags
|= PSD_DISABLEPAPER
;
1223 if ( !m_enablePrinter
)
1224 pd
->Flags
|= PSD_DISABLEPRINTER
;
1225 if ( m_getDefaultInfo
)
1226 pd
->Flags
|= PSD_RETURNDEFAULT
;
1228 pd
->Flags
|= PSD_SHOWHELP
;
1230 // We want the units to be in hundredths of a millimetre
1231 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1233 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
1234 pd
->hwndOwner
=(HWND
)NULL
;
1235 // pd->hDevNames=(HWND)NULL;
1236 pd
->hInstance
=(HINSTANCE
)NULL
;
1237 // PAGESETUPDLG is in hundreds of a mm
1238 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
1239 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
1241 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
1242 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
1243 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
1244 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
1246 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
1247 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
1248 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
1249 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
1252 pd
->lpfnPageSetupHook
= NULL
;
1253 pd
->lpfnPagePaintHook
= NULL
;
1254 pd
->hPageSetupTemplate
= NULL
;
1255 pd
->lpPageSetupTemplateName
= NULL
;
1260 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1261 memset(devMode, 0, sizeof(DEVMODE));
1262 devMode->dmSize = sizeof(DEVMODE);
1263 devMode->dmOrientation = m_orientation;
1264 devMode->dmFields = DM_ORIENTATION;
1265 GlobalUnlock(pd->hDevMode);
1270 void wxPageSetupDialogData::ConvertFromNative()
1272 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1276 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1279 if (m_printData
.GetNativeData())
1281 // Make sure we don't leak memory
1282 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1284 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1285 pd
->hDevMode
= NULL
;
1288 m_printData
.ConvertFromNative();
1290 // Pass the devnames data back to the wxPrintData structure where it really belongs.
1293 if (m_printData
.GetNativeDataDevNames())
1295 // Make sure we don't leak memory
1296 GlobalFree((HGLOBAL
) m_printData
.GetNativeDataDevNames());
1298 m_printData
.SetNativeDataDevNames((void*) pd
->hDevNames
);
1299 pd
->hDevNames
= NULL
;
1302 m_printData
.ConvertFromNative();
1304 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1306 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
1307 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
1308 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
1309 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
1310 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
1311 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
1312 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
1314 // PAGESETUPDLG is in hundreds of a mm
1315 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1316 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
1318 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
1319 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
1320 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
1321 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
1323 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100;
1324 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100;
1325 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100;
1326 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100;
1329 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1331 if ( m_pageSetupData
== NULL
)
1334 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1336 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1337 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1343 void wxPageSetupDialogData::ConvertToNative()
1345 m_printData
.ConvertToNative();
1346 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
1349 void wxPageSetupDialogData::ConvertFromNative()
1351 m_printData
.ConvertFromNative ();
1352 m_paperSize
= m_printData
.GetPaperSize() ;
1353 CalculateIdFromPaperSize();
1354 m_printData
.m_nativePrintData
->TransferTo( this ) ;
1355 // adjust minimal values
1357 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
1358 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
1360 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
1361 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
1363 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
1364 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
1366 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
1367 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
1372 // If a corresponding paper type is found in the paper database, will set the m_printData
1373 // paper size id member as well.
1374 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
1378 CalculateIdFromPaperSize();
1381 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1382 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1384 m_printData
.SetPaperId(id
);
1386 CalculatePaperSizeFromId();
1389 // Use paper size defined in this object to set the wxPrintData
1391 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1393 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1394 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
1396 wxSize sz
= GetPaperSize();
1398 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1399 if (id
!= wxPAPER_NONE
)
1401 m_printData
.SetPaperId(id
);
1405 // Use paper id in wxPrintData to set this object's paper size
1406 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1408 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1409 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
1411 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
1413 // sz is in 10ths of a mm, while paper size is in mm
1414 m_paperSize
.x
= sz
.x
/ 10;
1415 m_paperSize
.y
= sz
.y
/ 10;
1418 #endif // wxUSE_PRINTING_ARCHITECTURE