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_printOrientation
= wxPORTRAIT
;
176 m_printCollate
= false;
179 m_printerName
= wxT("");
181 m_duplexMode
= wxDUPLEX_SIMPLEX
;
182 m_printQuality
= wxPRINT_QUALITY_HIGH
;
183 m_paperId
= wxPAPER_A4
;
184 m_paperSize
= wxSize(210, 297);
186 // PostScript-specific data
187 m_previewCommand
= wxT("");
188 m_filename
= wxT("");
190 m_printerCommand
= wxT("print");
191 m_printerOptions
= wxT("/nonotify/queue=psqueue");
192 m_afmPath
= wxT("sys$ps_font_metrics:");
196 m_printerCommand
= wxT("print");
197 m_printerOptions
= wxT("");
198 m_afmPath
= wxT("c:\\windows\\system\\");
201 #if !defined(__VMS__) && !defined(__WXMSW__)
202 m_printerCommand
= wxT("lpr");
203 m_printerOptions
= wxT("");
207 m_printerScaleX
= 1.0;
208 m_printerScaleY
= 1.0;
209 m_printerTranslateX
= 0;
210 m_printerTranslateY
= 0;
211 m_printMode
= wxPRINT_MODE_FILE
;
214 m_outputstream
= NULL
;
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
;
389 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
390 devMode
->dmFields
|= DM_COLLATE
;
392 //// Number of copies
394 devMode
->dmCopies
= m_printNoCopies
;
395 devMode
->dmFields
|= DM_COPIES
;
399 if (m_printerName
!= wxT(""))
401 //int len = wxMin(31, m_printerName.Len());
402 wxStrncpy((wxChar
*)devMode
->dmDeviceName
,m_printerName
.c_str(),31);
403 devMode
->dmDeviceName
[31] = wxT('\0');
409 devMode
->dmColor
= DMCOLOR_COLOR
;
411 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
413 devMode
->dmFields
|= DM_COLOR
;
417 if (m_paperId
== wxPAPER_NONE
)
419 // DEVMODE is in tenths of a milimeter
420 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
421 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
422 devMode
->dmPaperSize
= DMPAPER_USER
;
423 devMode
->dmFields
|= DM_PAPERWIDTH
;
424 devMode
->dmFields
|= DM_PAPERLENGTH
;
428 if (wxThePrintPaperDatabase
)
430 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
433 devMode
->dmPaperSize
= paper
->GetPlatformId();
434 devMode
->dmFields
|= DM_PAPERSIZE
;
442 switch (m_duplexMode
)
444 case wxDUPLEX_HORIZONTAL
: {
445 duplex
= DMDUP_HORIZONTAL
; break;
447 case wxDUPLEX_VERTICAL
: {
448 duplex
= DMDUP_VERTICAL
; break;
451 case wxDUPLEX_SIMPLEX
: {
452 duplex
= DMDUP_SIMPLEX
; break;
455 devMode
->dmDuplex
= duplex
;
456 devMode
->dmFields
|= DM_DUPLEX
;
461 switch (m_printQuality
)
463 case wxPRINT_QUALITY_MEDIUM
: {
464 quality
= DMRES_MEDIUM
; break;
466 case wxPRINT_QUALITY_LOW
: {
467 quality
= DMRES_LOW
; break;
469 case wxPRINT_QUALITY_DRAFT
: {
470 quality
= DMRES_DRAFT
; break;
472 case wxPRINT_QUALITY_HIGH
: {
473 quality
= DMRES_HIGH
; break;
476 quality
= m_printQuality
; break;
479 devMode
->dmPrintQuality
= quality
;
480 devMode
->dmFields
|= DM_PRINTQUALITY
;
482 GlobalUnlock(hDevMode
);
487 GlobalFree(hDevNames
);
490 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
491 m_devNames
= (void*) (long) wxCreateDevNames(wxT(""), m_printerName
, wxT(""));
494 void wxPrintData::ConvertFromNative()
496 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
497 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
504 LPDEVMODE devMode
= (LPDEVMODE
)GlobalLock(hDevMode
);
508 if (devMode
->dmFields
& DM_ORIENTATION
)
509 m_printOrientation
= devMode
->dmOrientation
;
513 if (devMode
->dmFields
& DM_COLLATE
)
515 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
516 m_printCollate
= true;
518 m_printCollate
= false;
521 //// Number of copies
523 if (devMode
->dmFields
& DM_COPIES
)
525 m_printNoCopies
= devMode
->dmCopies
;
530 if (devMode
->dmDeviceName
[0] != 0)
532 m_printerName
= devMode
->dmDeviceName
;
537 if (devMode
->dmFields
& DM_COLOR
)
539 if (devMode
->dmColor
== DMCOLOR_COLOR
)
549 // We don't know size of user defined paper and some buggy drivers
550 // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
551 // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
552 // code wouldn't set m_paperSize correctly.
553 if ((devMode
->dmFields
& DM_PAPERSIZE
) && (devMode
->dmPaperSize
< DMPAPER_USER
))
555 if (wxThePrintPaperDatabase
)
557 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
560 m_paperId
= paper
->GetId();
561 m_paperSize
.x
= paper
->GetWidth() / 10;
562 m_paperSize
.y
= paper
->GetHeight() / 10;
566 // Shouldn't really get here
567 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
569 m_paperId
= wxPAPER_NONE
;
576 // Shouldn't really get here
577 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
579 m_paperId
= wxPAPER_NONE
;
584 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
586 // DEVMODE is in tenths of a milimeter
587 m_paperSize
.x
= devMode
->dmPaperWidth
/ 10;
588 m_paperSize
.y
= devMode
->dmPaperLength
/ 10;
589 m_paperId
= wxPAPER_NONE
;
593 // Shouldn't really get here
594 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
598 m_paperId
= wxPAPER_NONE
;
603 if (devMode
->dmFields
& DM_DUPLEX
)
605 switch (devMode
->dmDuplex
)
607 case DMDUP_HORIZONTAL
: {
608 m_duplexMode
= wxDUPLEX_HORIZONTAL
; break;
610 case DMDUP_VERTICAL
: {
611 m_duplexMode
= wxDUPLEX_VERTICAL
; break;
614 case DMDUP_SIMPLEX
: {
615 m_duplexMode
= wxDUPLEX_SIMPLEX
; break;
620 m_duplexMode
= wxDUPLEX_SIMPLEX
;
624 if (devMode
->dmFields
& DM_PRINTQUALITY
)
626 switch (devMode
->dmPrintQuality
)
629 m_printQuality
= wxPRINT_QUALITY_MEDIUM
; break;
632 m_printQuality
= wxPRINT_QUALITY_LOW
; break;
635 m_printQuality
= wxPRINT_QUALITY_DRAFT
; break;
638 m_printQuality
= wxPRINT_QUALITY_HIGH
; break;
642 // TODO: if the printer fills in the resolution in DPI, how
643 // will the application know if it's high, low, draft etc.??
644 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
645 m_printQuality
= devMode
->dmPrintQuality
; break;
651 m_printQuality
= wxPRINT_QUALITY_HIGH
;
653 GlobalUnlock(hDevMode
);
658 LPDEVNAMES lpDevNames
= (LPDEVNAMES
)GlobalLock(hDevNames
);
661 // TODO: Unicode-ification
664 // port is obsolete in WIN32
665 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
667 // Get the printer name
668 wxString printerName
= (LPTSTR
)lpDevNames
+ lpDevNames
->wDeviceOffset
;
670 // Not sure if we should check for this mismatch
671 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
673 if (printerName
!= wxT(""))
674 m_printerName
= printerName
;
676 GlobalUnlock(hDevNames
);
685 void wxPrintData::ConvertToNative()
687 m_nativePrintData
->TransferFrom( this ) ;
690 void wxPrintData::ConvertFromNative()
692 m_nativePrintData
->TransferTo( this ) ;
697 void wxPrintData::operator=(const wxPrintData
& data
)
700 m_nativePrintData
->CopyFrom( data
.m_nativePrintData
) ;
702 m_printNoCopies
= data
.m_printNoCopies
;
703 m_printCollate
= data
.m_printCollate
;
704 m_printOrientation
= data
.m_printOrientation
;
705 m_printerName
= data
.m_printerName
;
706 m_colour
= data
.m_colour
;
707 m_duplexMode
= data
.m_duplexMode
;
708 m_printQuality
= data
.m_printQuality
;
709 m_paperId
= data
.m_paperId
;
710 m_paperSize
= data
.m_paperSize
;
712 m_outputstream
= data
.m_outputstream
;
715 // PostScript-specific data
716 m_printerCommand
= data
.m_printerCommand
;
717 m_previewCommand
= data
.m_previewCommand
;
718 m_printerOptions
= data
.m_printerOptions
;
719 m_filename
= data
.m_filename
;
720 m_afmPath
= data
.m_afmPath
;
721 m_printerScaleX
= data
.m_printerScaleX
;
722 m_printerScaleY
= data
.m_printerScaleY
;
723 m_printerTranslateX
= data
.m_printerTranslateX
;
724 m_printerTranslateY
= data
.m_printerTranslateY
;
725 m_printMode
= data
.m_printMode
;
728 // Is this data OK for showing the print dialog?
729 bool wxPrintData::Ok() const
732 ((wxPrintData
*)this)->ConvertToNative();
733 return (m_devMode
!= NULL
) ;
739 // ----------------------------------------------------------------------------
741 // ----------------------------------------------------------------------------
743 wxPrintDialogData::wxPrintDialogData()
746 m_printDlgData
= NULL
;
753 m_printAllPages
= false;
754 m_printCollate
= false;
755 m_printToFile
= false;
756 m_printSelection
= false;
757 m_printEnableSelection
= false;
758 m_printEnablePageNumbers
= true;
759 m_printEnablePrintToFile
= true;
760 m_printEnableHelp
= false;
761 m_printSetupDialog
= false;
764 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
768 m_printDlgData
= NULL
;
770 (*this) = dialogData
;
773 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
776 m_printDlgData
= NULL
;
781 m_printMaxPage
= 9999;
783 m_printAllPages
= false;
784 m_printCollate
= false;
785 m_printToFile
= false;
786 m_printSelection
= false;
787 m_printEnableSelection
= false;
788 m_printEnablePageNumbers
= true;
789 m_printEnablePrintToFile
= true;
790 m_printEnableHelp
= false;
791 m_printSetupDialog
= false;
793 m_printData
= printData
;
796 wxPrintDialogData::~wxPrintDialogData()
799 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
800 if ( pd
&& pd
->hDevMode
)
801 GlobalFree(pd
->hDevMode
);
808 void wxPrintDialogData::ConvertToNative()
810 m_printData
.ConvertToNative();
812 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
817 memset( pd
, 0, sizeof(PRINTDLG
) );
818 m_printDlgData
= (void*) pd
;
820 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
822 pd
->lStructSize
= 66;
824 pd
->lStructSize
= sizeof(PRINTDLG
);
826 pd
->hwndOwner
= (HWND
)NULL
;
827 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
828 pd
->hDevNames
= NULL
; // Ditto
830 pd
->Flags
= PD_RETURNDEFAULT
;
834 // Pass the devmode data to the PRINTDLG structure, since it'll
835 // be needed when PrintDlg is called.
838 GlobalFree(pd
->hDevMode
);
841 // Pass the devnames data to the PRINTDLG structure, since it'll
842 // be needed when PrintDlg is called.
845 GlobalFree(pd
->hDevNames
);
848 pd
->hDevMode
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeData();
850 m_printData
.SetNativeData((void*) NULL
);
852 // Shouldn't assert; we should be able to test Ok-ness at a higher level
853 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
855 pd
->hDevNames
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeDataDevNames();
857 m_printData
.SetNativeDataDevNames((void*) NULL
);
859 pd
->hDC
= (HDC
) NULL
;
860 pd
->nFromPage
= (WORD
)m_printFromPage
;
861 pd
->nToPage
= (WORD
)m_printToPage
;
862 pd
->nMinPage
= (WORD
)m_printMinPage
;
863 pd
->nMaxPage
= (WORD
)m_printMaxPage
;
864 pd
->nCopies
= (WORD
)m_printNoCopies
;
866 pd
->Flags
= PD_RETURNDC
;
869 pd
->lStructSize
= 66;
871 pd
->lStructSize
= sizeof( PRINTDLG
);
874 pd
->hwndOwner
=(HWND
)NULL
;
875 // pd->hDevNames=(HANDLE)NULL;
876 pd
->hInstance
=(HINSTANCE
)NULL
;
877 pd
->lCustData
= (LPARAM
) NULL
;
878 pd
->lpfnPrintHook
= NULL
;
879 pd
->lpfnSetupHook
= NULL
;
880 pd
->lpPrintTemplateName
= NULL
;
881 pd
->lpSetupTemplateName
= NULL
;
882 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
883 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
885 if ( m_printAllPages
)
886 pd
->Flags
|= PD_ALLPAGES
;
887 if ( m_printSelection
)
888 pd
->Flags
|= PD_SELECTION
;
889 if ( m_printCollate
)
890 pd
->Flags
|= PD_COLLATE
;
892 pd
->Flags
|= PD_PRINTTOFILE
;
893 if ( !m_printEnablePrintToFile
)
894 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
895 if ( !m_printEnableSelection
)
896 pd
->Flags
|= PD_NOSELECTION
;
897 if ( !m_printEnablePageNumbers
)
898 pd
->Flags
|= PD_NOPAGENUMS
;
899 else if ( (!m_printAllPages
) && (!m_printSelection
) && (m_printFromPage
!= 0) && (m_printToPage
!= 0))
900 pd
->Flags
|= PD_PAGENUMS
;
901 if ( m_printEnableHelp
)
902 pd
->Flags
|= PD_SHOWHELP
;
903 if ( m_printSetupDialog
)
904 pd
->Flags
|= PD_PRINTSETUP
;
907 void wxPrintDialogData::ConvertFromNative()
909 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
913 // Pass the devmode data back to the wxPrintData structure where it really belongs.
916 if (m_printData
.GetNativeData())
918 // Make sure we don't leak memory
919 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeData());
921 m_printData
.SetNativeData((void*)(long) pd
->hDevMode
);
925 // Pass the devnames data back to the wxPrintData structure where it really belongs.
928 if (m_printData
.GetNativeDataDevNames())
930 // Make sure we don't leak memory
931 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeDataDevNames());
933 m_printData
.SetNativeDataDevNames((void*)(long) pd
->hDevNames
);
934 pd
->hDevNames
= NULL
;
937 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
938 // into wxWidgets form.
939 m_printData
.ConvertFromNative();
941 m_printFromPage
= pd
->nFromPage
;
942 m_printToPage
= pd
->nToPage
;
943 m_printMinPage
= pd
->nMinPage
;
944 m_printMaxPage
= pd
->nMaxPage
;
945 m_printNoCopies
= pd
->nCopies
;
947 m_printAllPages
= (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
));
948 m_printSelection
= ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
);
949 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
950 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
951 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
952 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
953 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
954 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
955 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
957 /* port is obsolete in WIN32
961 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
963 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
964 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
965 GlobalUnlock(pd->hDevNames);
967 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
973 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
975 if ( m_printDlgData
== NULL
)
978 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
980 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
981 pd
->hwndOwner
=(HWND
) win
->GetHWND();
988 void wxPrintDialogData::ConvertToNative()
990 m_printData
.ConvertToNative();
991 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
994 void wxPrintDialogData::ConvertFromNative()
996 m_printData
.ConvertFromNative();
997 m_printData
.m_nativePrintData
->TransferTo( this ) ;
1003 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
1005 m_printFromPage
= data
.m_printFromPage
;
1006 m_printToPage
= data
.m_printToPage
;
1007 m_printMinPage
= data
.m_printMinPage
;
1008 m_printMaxPage
= data
.m_printMaxPage
;
1009 m_printNoCopies
= data
.m_printNoCopies
;
1010 m_printAllPages
= data
.m_printAllPages
;
1011 m_printCollate
= data
.m_printCollate
;
1012 m_printToFile
= data
.m_printToFile
;
1013 m_printSelection
= data
.m_printSelection
;
1014 m_printEnableSelection
= data
.m_printEnableSelection
;
1015 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
1016 m_printEnableHelp
= data
.m_printEnableHelp
;
1017 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
1018 m_printSetupDialog
= data
.m_printSetupDialog
;
1020 m_printData
= data
.m_printData
;
1023 void wxPrintDialogData::operator=(const wxPrintData
& data
)
1028 // ----------------------------------------------------------------------------
1029 // wxPageSetupDialogData
1030 // ----------------------------------------------------------------------------
1032 wxPageSetupDialogData::wxPageSetupDialogData()
1034 #if defined(__WIN95__)
1035 m_pageSetupData
= NULL
;
1037 m_paperSize
= wxSize(0, 0);
1039 CalculatePaperSizeFromId();
1041 m_minMarginTopLeft
= wxPoint(0, 0);
1042 m_minMarginBottomRight
= wxPoint(0, 0);
1043 m_marginTopLeft
= wxPoint(0, 0);
1044 m_marginBottomRight
= wxPoint(0, 0);
1047 m_defaultMinMargins
= false;
1048 m_enableMargins
= true;
1049 m_enableOrientation
= true;
1050 m_enablePaper
= true;
1051 m_enablePrinter
= true;
1052 m_enableHelp
= false;
1053 m_getDefaultInfo
= false;
1056 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
1059 #if defined(__WIN95__)
1060 m_pageSetupData
= NULL
;
1062 (*this) = dialogData
;
1065 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
1067 #if defined(__WIN95__)
1068 m_pageSetupData
= NULL
;
1070 m_paperSize
= wxSize(0, 0);
1071 m_minMarginTopLeft
= wxPoint(0, 0);
1072 m_minMarginBottomRight
= wxPoint(0, 0);
1073 m_marginTopLeft
= wxPoint(0, 0);
1074 m_marginBottomRight
= wxPoint(0, 0);
1077 m_defaultMinMargins
= false;
1078 m_enableMargins
= true;
1079 m_enableOrientation
= true;
1080 m_enablePaper
= true;
1081 m_enablePrinter
= true;
1082 m_enableHelp
= false;
1083 m_getDefaultInfo
= false;
1085 m_printData
= printData
;
1087 // The wxPrintData paper size overrides these values, unless the size cannot
1089 CalculatePaperSizeFromId();
1092 wxPageSetupDialogData::~wxPageSetupDialogData()
1094 #if defined(__WIN95__) && defined(__WXMSW__)
1095 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
1096 if ( pd
&& pd
->hDevMode
)
1097 GlobalFree(pd
->hDevMode
);
1098 if ( pd
&& pd
->hDevNames
)
1099 GlobalFree(pd
->hDevNames
);
1105 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
1107 m_paperSize
= data
.m_paperSize
;
1108 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
1109 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
1110 m_marginTopLeft
= data
.m_marginTopLeft
;
1111 m_marginBottomRight
= data
.m_marginBottomRight
;
1112 m_defaultMinMargins
= data
.m_defaultMinMargins
;
1113 m_enableMargins
= data
.m_enableMargins
;
1114 m_enableOrientation
= data
.m_enableOrientation
;
1115 m_enablePaper
= data
.m_enablePaper
;
1116 m_enablePrinter
= data
.m_enablePrinter
;
1117 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
1118 m_enableHelp
= data
.m_enableHelp
;
1120 m_printData
= data
.m_printData
;
1125 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
1132 #if defined(__WIN95__)
1133 void wxPageSetupDialogData::ConvertToNative()
1135 m_printData
.ConvertToNative();
1137 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1139 if ( m_pageSetupData
== NULL
)
1141 pd
= new PAGESETUPDLG
;
1142 pd
->hDevMode
= NULL
;
1143 pd
->hDevNames
= NULL
;
1144 m_pageSetupData
= (void *)pd
;
1147 // Pass the devmode data (created in m_printData.ConvertToNative)
1148 // to the PRINTDLG structure, since it'll
1149 // be needed when PrintDlg is called.
1153 GlobalFree(pd
->hDevMode
);
1154 pd
->hDevMode
= NULL
;
1157 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
1159 m_printData
.SetNativeData((void*) NULL
);
1161 // Shouldn't assert; we should be able to test Ok-ness at a higher level
1162 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
1164 // Pass the devnames data (created in m_printData.ConvertToNative)
1165 // to the PRINTDLG structure, since it'll
1166 // be needed when PrintDlg is called.
1170 GlobalFree(pd
->hDevNames
);
1171 pd
->hDevNames
= NULL
;
1174 pd
->hDevNames
= (HGLOBAL
) m_printData
.GetNativeDataDevNames();
1176 m_printData
.SetNativeDataDevNames((void*) NULL
);
1178 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1180 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1182 if ( m_defaultMinMargins
)
1183 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
1184 if ( !m_enableMargins
)
1185 pd
->Flags
|= PSD_DISABLEMARGINS
;
1186 if ( !m_enableOrientation
)
1187 pd
->Flags
|= PSD_DISABLEORIENTATION
;
1188 if ( !m_enablePaper
)
1189 pd
->Flags
|= PSD_DISABLEPAPER
;
1190 if ( !m_enablePrinter
)
1191 pd
->Flags
|= PSD_DISABLEPRINTER
;
1192 if ( m_getDefaultInfo
)
1193 pd
->Flags
|= PSD_RETURNDEFAULT
;
1195 pd
->Flags
|= PSD_SHOWHELP
;
1197 // We want the units to be in hundredths of a millimetre
1198 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1200 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
1201 pd
->hwndOwner
=(HWND
)NULL
;
1202 // pd->hDevNames=(HWND)NULL;
1203 pd
->hInstance
=(HINSTANCE
)NULL
;
1204 // PAGESETUPDLG is in hundreds of a mm
1205 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
1206 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
1208 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
1209 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
1210 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
1211 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
1213 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
1214 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
1215 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
1216 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
1219 pd
->lpfnPageSetupHook
= NULL
;
1220 pd
->lpfnPagePaintHook
= NULL
;
1221 pd
->hPageSetupTemplate
= NULL
;
1222 pd
->lpPageSetupTemplateName
= NULL
;
1227 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1228 memset(devMode, 0, sizeof(DEVMODE));
1229 devMode->dmSize = sizeof(DEVMODE);
1230 devMode->dmOrientation = m_orientation;
1231 devMode->dmFields = DM_ORIENTATION;
1232 GlobalUnlock(pd->hDevMode);
1237 void wxPageSetupDialogData::ConvertFromNative()
1239 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1243 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1246 if (m_printData
.GetNativeData())
1248 // Make sure we don't leak memory
1249 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1251 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1252 pd
->hDevMode
= NULL
;
1255 m_printData
.ConvertFromNative();
1257 // Pass the devnames data back to the wxPrintData structure where it really belongs.
1260 if (m_printData
.GetNativeDataDevNames())
1262 // Make sure we don't leak memory
1263 GlobalFree((HGLOBAL
) m_printData
.GetNativeDataDevNames());
1265 m_printData
.SetNativeDataDevNames((void*) pd
->hDevNames
);
1266 pd
->hDevNames
= NULL
;
1269 m_printData
.ConvertFromNative();
1271 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1273 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
1274 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
1275 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
1276 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
1277 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
1278 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
1279 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
1281 // PAGESETUPDLG is in hundreds of a mm
1282 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1283 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
1285 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
1286 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
1287 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
1288 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
1290 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100;
1291 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100;
1292 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100;
1293 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100;
1296 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1298 if ( m_pageSetupData
== NULL
)
1301 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1303 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1304 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1310 void wxPageSetupDialogData::ConvertToNative()
1312 m_printData
.ConvertToNative();
1313 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
1316 void wxPageSetupDialogData::ConvertFromNative()
1318 m_printData
.ConvertFromNative ();
1319 m_paperSize
= m_printData
.GetPaperSize() ;
1320 CalculateIdFromPaperSize();
1321 m_printData
.m_nativePrintData
->TransferTo( this ) ;
1322 // adjust minimal values
1324 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
1325 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
1327 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
1328 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
1330 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
1331 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
1333 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
1334 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
1339 // If a corresponding paper type is found in the paper database, will set the m_printData
1340 // paper size id member as well.
1341 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
1345 CalculateIdFromPaperSize();
1348 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1349 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1351 m_printData
.SetPaperId(id
);
1353 CalculatePaperSizeFromId();
1356 // Use paper size defined in this object to set the wxPrintData
1358 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1360 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1361 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
1363 wxSize sz
= GetPaperSize();
1365 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1366 if (id
!= wxPAPER_NONE
)
1368 m_printData
.SetPaperId(id
);
1372 // Use paper id in wxPrintData to set this object's paper size
1373 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1375 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1376 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
1378 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
1380 // sz is in 10ths of a mm, while paper size is in mm
1381 m_paperSize
.x
= sz
.x
/ 10;
1382 m_paperSize
.y
= sz
.y
/ 10;
1385 #endif // wxUSE_PRINTING_ARCHITECTURE