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 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 m_outputstream
= NULL
;
222 wxPrintData::wxPrintData(const wxPrintData
& printData
)
226 m_devMode
= (void*) NULL
;
227 m_devNames
= (void*) NULL
;
228 #elif defined( __WXMAC__ )
229 m_nativePrintData
= wxNativePrintData::Create() ;
234 wxPrintData::~wxPrintData()
237 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
239 GlobalFree(hDevMode
);
240 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
242 GlobalFree(hDevNames
);
243 #elif defined(__WXMAC__)
244 delete m_nativePrintData
;
248 #if defined(__WXMSW__) // && defined(__WIN32__)
250 #if defined(__WXDEBUG__) && defined(__WIN32__)
251 static wxString
wxGetPrintDlgError()
253 DWORD err
= CommDlgExtendedError();
254 wxString msg
= wxT("Unknown");
257 case CDERR_FINDRESFAILURE
: msg
= wxT("CDERR_FINDRESFAILURE"); break;
258 case CDERR_INITIALIZATION
: msg
= wxT("CDERR_INITIALIZATION"); break;
259 case CDERR_LOADRESFAILURE
: msg
= wxT("CDERR_LOADRESFAILURE"); break;
260 case CDERR_LOADSTRFAILURE
: msg
= wxT("CDERR_LOADSTRFAILURE"); break;
261 case CDERR_LOCKRESFAILURE
: msg
= wxT("CDERR_LOCKRESFAILURE"); break;
262 case CDERR_MEMALLOCFAILURE
: msg
= wxT("CDERR_MEMALLOCFAILURE"); break;
263 case CDERR_MEMLOCKFAILURE
: msg
= wxT("CDERR_MEMLOCKFAILURE"); break;
264 case CDERR_NOHINSTANCE
: msg
= wxT("CDERR_NOHINSTANCE"); break;
265 case CDERR_NOHOOK
: msg
= wxT("CDERR_NOHOOK"); break;
266 case CDERR_NOTEMPLATE
: msg
= wxT("CDERR_NOTEMPLATE"); break;
267 case CDERR_STRUCTSIZE
: msg
= wxT("CDERR_STRUCTSIZE"); break;
268 case PDERR_RETDEFFAILURE
: msg
= wxT("PDERR_RETDEFFAILURE"); break;
269 case PDERR_PRINTERNOTFOUND
: msg
= wxT("PDERR_PRINTERNOTFOUND"); break;
270 case PDERR_PARSEFAILURE
: msg
= wxT("PDERR_PARSEFAILURE"); break;
271 case PDERR_NODEVICES
: msg
= wxT("PDERR_NODEVICES"); break;
272 case PDERR_NODEFAULTPRN
: msg
= wxT("PDERR_NODEFAULTPRN"); break;
273 case PDERR_LOADDRVFAILURE
: msg
= wxT("PDERR_LOADDRVFAILURE"); break;
274 case PDERR_INITFAILURE
: msg
= wxT("PDERR_INITFAILURE"); break;
275 case PDERR_GETDEVMODEFAIL
: msg
= wxT("PDERR_GETDEVMODEFAIL"); break;
276 case PDERR_DNDMMISMATCH
: msg
= wxT("PDERR_DNDMMISMATCH"); break;
277 case PDERR_DEFAULTDIFFERENT
: msg
= wxT("PDERR_DEFAULTDIFFERENT"); break;
278 case PDERR_CREATEICFAILURE
: msg
= wxT("PDERR_CREATEICFAILURE"); break;
285 static HGLOBAL
wxCreateDevNames(const wxString
& driverName
, const wxString
& printerName
, const wxString
& portName
)
288 // if (!driverName.IsEmpty() && !printerName.IsEmpty() && !portName.IsEmpty())
289 if (driverName
.IsEmpty() && printerName
.IsEmpty() && portName
.IsEmpty())
294 hDev
= GlobalAlloc(GPTR
, 4*sizeof(WORD
)+
295 ( driverName
.Length() + 1 +
296 printerName
.Length() + 1 +
297 portName
.Length()+1 ) * sizeof(wxChar
) );
298 LPDEVNAMES lpDev
= (LPDEVNAMES
)GlobalLock(hDev
);
299 lpDev
->wDriverOffset
= sizeof(WORD
)*4;
300 wxStrcpy((wxChar
*)((char*)lpDev
+ lpDev
->wDriverOffset
), driverName
);
302 lpDev
->wDeviceOffset
= (WORD
)( lpDev
->wDriverOffset
+
303 sizeof(wxChar
) * ( driverName
.Length() + 1 ) );
304 wxStrcpy((wxChar
*)((char*)lpDev
+ lpDev
->wDeviceOffset
), printerName
);
306 lpDev
->wOutputOffset
= (WORD
)( lpDev
->wDeviceOffset
+
307 sizeof(wxChar
) * ( printerName
.Length() + 1 ) );
308 wxStrcpy((wxChar
*)((char*) lpDev
+ lpDev
->wOutputOffset
), portName
);
318 void wxPrintData::ConvertToNative()
320 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
321 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
324 // Use PRINTDLG as a way of creating a DEVMODE object
327 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
332 memset(&pd
, 0, sizeof(PRINTDLG
));
334 pd
.cbStruct
= sizeof(PRINTDLG
);
336 pd
.lStructSize
= sizeof(PRINTDLG
);
340 pd
.hwndOwner
= (HWND
)NULL
;
341 pd
.hDevMode
= NULL
; // Will be created by PrintDlg
342 pd
.hDevNames
= NULL
; // Ditto
343 //pd.hInstance = (HINSTANCE) wxGetInstance();
345 pd
.Flags
= PD_RETURNDEFAULT
;
348 // Fill out the DEVMODE structure
349 // so we can use it as input in the 'real' PrintDlg
353 GlobalFree(pd
.hDevMode
);
355 GlobalFree(pd
.hDevNames
);
359 #if defined(__WXDEBUG__) && defined(__WIN32__)
360 wxString
str(wxT("Printing error: "));
361 str
+= wxGetPrintDlgError();
367 hDevMode
= pd
.hDevMode
;
368 m_devMode
= (void*)(long) hDevMode
;
371 // We'll create a new DEVNAMEs structure below.
373 GlobalFree(pd
.hDevNames
);
376 // hDevNames = pd->hDevNames;
377 // m_devNames = (void*)(long) hDevNames;
378 // pd->hDevnames = NULL;
385 LPDEVMODE devMode
= (LPDEVMODE
) GlobalLock(hDevMode
);
389 devMode
->dmOrientation
= m_printOrientation
;
393 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
394 devMode
->dmFields
|= DM_COLLATE
;
396 //// Number of copies
398 devMode
->dmCopies
= m_printNoCopies
;
399 devMode
->dmFields
|= DM_COPIES
;
403 if (m_printerName
!= wxT(""))
405 //int len = wxMin(31, m_printerName.Len());
406 wxStrncpy((wxChar
*)devMode
->dmDeviceName
,m_printerName
.c_str(),31);
407 devMode
->dmDeviceName
[31] = wxT('\0');
413 devMode
->dmColor
= DMCOLOR_COLOR
;
415 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
417 devMode
->dmFields
|= DM_COLOR
;
421 if (m_paperId
== wxPAPER_NONE
)
423 // DEVMODE is in tenths of a milimeter
424 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
425 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
426 devMode
->dmPaperSize
= DMPAPER_USER
;
427 devMode
->dmFields
|= DM_PAPERWIDTH
;
428 devMode
->dmFields
|= DM_PAPERLENGTH
;
432 if (wxThePrintPaperDatabase
)
434 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
437 devMode
->dmPaperSize
= paper
->GetPlatformId();
438 devMode
->dmFields
|= DM_PAPERSIZE
;
446 switch (m_duplexMode
)
448 case wxDUPLEX_HORIZONTAL
: {
449 duplex
= DMDUP_HORIZONTAL
; break;
451 case wxDUPLEX_VERTICAL
: {
452 duplex
= DMDUP_VERTICAL
; break;
455 case wxDUPLEX_SIMPLEX
: {
456 duplex
= DMDUP_SIMPLEX
; break;
459 devMode
->dmDuplex
= duplex
;
460 devMode
->dmFields
|= DM_DUPLEX
;
465 switch (m_printQuality
)
467 case wxPRINT_QUALITY_MEDIUM
: {
468 quality
= DMRES_MEDIUM
; break;
470 case wxPRINT_QUALITY_LOW
: {
471 quality
= DMRES_LOW
; break;
473 case wxPRINT_QUALITY_DRAFT
: {
474 quality
= DMRES_DRAFT
; break;
476 case wxPRINT_QUALITY_HIGH
: {
477 quality
= DMRES_HIGH
; break;
480 quality
= m_printQuality
; break;
483 devMode
->dmPrintQuality
= quality
;
484 devMode
->dmFields
|= DM_PRINTQUALITY
;
486 GlobalUnlock(hDevMode
);
491 GlobalFree(hDevNames
);
494 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
495 m_devNames
= (void*) (long) wxCreateDevNames(wxT(""), m_printerName
, wxT(""));
498 void wxPrintData::ConvertFromNative()
500 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
501 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
508 LPDEVMODE devMode
= (LPDEVMODE
)GlobalLock(hDevMode
);
512 if (devMode
->dmFields
& DM_ORIENTATION
)
513 m_printOrientation
= devMode
->dmOrientation
;
517 if (devMode
->dmFields
& DM_COLLATE
)
519 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
520 m_printCollate
= TRUE
;
522 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 m_outputstream
= data
.m_outputstream
;
719 // PostScript-specific data
720 m_printerCommand
= data
.m_printerCommand
;
721 m_previewCommand
= data
.m_previewCommand
;
722 m_printerOptions
= data
.m_printerOptions
;
723 m_filename
= data
.m_filename
;
724 m_afmPath
= data
.m_afmPath
;
725 m_printerScaleX
= data
.m_printerScaleX
;
726 m_printerScaleY
= data
.m_printerScaleY
;
727 m_printerTranslateX
= data
.m_printerTranslateX
;
728 m_printerTranslateY
= data
.m_printerTranslateY
;
729 m_printMode
= data
.m_printMode
;
732 // Is this data OK for showing the print dialog?
733 bool wxPrintData::Ok() const
736 ((wxPrintData
*)this)->ConvertToNative();
737 return (m_devMode
!= NULL
) ;
743 // ----------------------------------------------------------------------------
745 // ----------------------------------------------------------------------------
747 wxPrintDialogData::wxPrintDialogData()
750 m_printDlgData
= NULL
;
757 m_printAllPages
= FALSE
;
758 m_printCollate
= FALSE
;
759 m_printToFile
= FALSE
;
760 m_printSelection
= FALSE
;
761 m_printEnableSelection
= FALSE
;
762 m_printEnablePageNumbers
= TRUE
;
763 m_printEnablePrintToFile
= TRUE
;
764 m_printEnableHelp
= FALSE
;
765 m_printSetupDialog
= FALSE
;
768 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
772 m_printDlgData
= NULL
;
774 (*this) = dialogData
;
777 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
780 m_printDlgData
= NULL
;
785 m_printMaxPage
= 9999;
787 m_printAllPages
= FALSE
;
788 m_printCollate
= FALSE
;
789 m_printToFile
= FALSE
;
790 m_printSelection
= FALSE
;
791 m_printEnableSelection
= FALSE
;
792 m_printEnablePageNumbers
= TRUE
;
793 m_printEnablePrintToFile
= TRUE
;
794 m_printEnableHelp
= FALSE
;
795 m_printSetupDialog
= FALSE
;
797 m_printData
= printData
;
800 wxPrintDialogData::~wxPrintDialogData()
803 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
804 if ( pd
&& pd
->hDevMode
)
805 GlobalFree(pd
->hDevMode
);
812 void wxPrintDialogData::ConvertToNative()
814 m_printData
.ConvertToNative();
816 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
821 memset( pd
, 0, sizeof(PRINTDLG
) );
822 m_printDlgData
= (void*) pd
;
824 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
826 pd
->lStructSize
= 66;
828 pd
->lStructSize
= sizeof(PRINTDLG
);
830 pd
->hwndOwner
= (HWND
)NULL
;
831 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
832 pd
->hDevNames
= NULL
; // Ditto
834 pd
->Flags
= PD_RETURNDEFAULT
;
838 // Pass the devmode data to the PRINTDLG structure, since it'll
839 // be needed when PrintDlg is called.
842 GlobalFree(pd
->hDevMode
);
845 // Pass the devnames data to the PRINTDLG structure, since it'll
846 // be needed when PrintDlg is called.
849 GlobalFree(pd
->hDevNames
);
852 pd
->hDevMode
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeData();
854 m_printData
.SetNativeData((void*) NULL
);
856 // Shouldn't assert; we should be able to test Ok-ness at a higher level
857 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
859 pd
->hDevNames
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeDataDevNames();
861 m_printData
.SetNativeDataDevNames((void*) NULL
);
863 pd
->hDC
= (HDC
) NULL
;
864 pd
->nFromPage
= (WORD
)m_printFromPage
;
865 pd
->nToPage
= (WORD
)m_printToPage
;
866 pd
->nMinPage
= (WORD
)m_printMinPage
;
867 pd
->nMaxPage
= (WORD
)m_printMaxPage
;
868 pd
->nCopies
= (WORD
)m_printNoCopies
;
870 pd
->Flags
= PD_RETURNDC
;
873 pd
->lStructSize
= 66;
875 pd
->lStructSize
= sizeof( PRINTDLG
);
878 pd
->hwndOwner
=(HWND
)NULL
;
879 // pd->hDevNames=(HANDLE)NULL;
880 pd
->hInstance
=(HINSTANCE
)NULL
;
881 pd
->lCustData
= (LPARAM
) NULL
;
882 pd
->lpfnPrintHook
= NULL
;
883 pd
->lpfnSetupHook
= NULL
;
884 pd
->lpPrintTemplateName
= NULL
;
885 pd
->lpSetupTemplateName
= NULL
;
886 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
887 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
889 if ( m_printAllPages
)
890 pd
->Flags
|= PD_ALLPAGES
;
891 if ( m_printSelection
)
892 pd
->Flags
|= PD_SELECTION
;
893 if ( m_printCollate
)
894 pd
->Flags
|= PD_COLLATE
;
896 pd
->Flags
|= PD_PRINTTOFILE
;
897 if ( !m_printEnablePrintToFile
)
898 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
899 if ( !m_printEnableSelection
)
900 pd
->Flags
|= PD_NOSELECTION
;
901 if ( !m_printEnablePageNumbers
)
902 pd
->Flags
|= PD_NOPAGENUMS
;
903 else if ( (!m_printAllPages
) && (!m_printSelection
) && (m_printFromPage
!= 0) && (m_printToPage
!= 0))
904 pd
->Flags
|= PD_PAGENUMS
;
905 if ( m_printEnableHelp
)
906 pd
->Flags
|= PD_SHOWHELP
;
907 if ( m_printSetupDialog
)
908 pd
->Flags
|= PD_PRINTSETUP
;
911 void wxPrintDialogData::ConvertFromNative()
913 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
917 // Pass the devmode data back to the wxPrintData structure where it really belongs.
920 if (m_printData
.GetNativeData())
922 // Make sure we don't leak memory
923 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeData());
925 m_printData
.SetNativeData((void*)(long) pd
->hDevMode
);
929 // Pass the devnames data back to the wxPrintData structure where it really belongs.
932 if (m_printData
.GetNativeDataDevNames())
934 // Make sure we don't leak memory
935 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeDataDevNames());
937 m_printData
.SetNativeDataDevNames((void*)(long) pd
->hDevNames
);
938 pd
->hDevNames
= NULL
;
941 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
942 // into wxWindows form.
943 m_printData
.ConvertFromNative();
945 m_printFromPage
= pd
->nFromPage
;
946 m_printToPage
= pd
->nToPage
;
947 m_printMinPage
= pd
->nMinPage
;
948 m_printMaxPage
= pd
->nMaxPage
;
949 m_printNoCopies
= pd
->nCopies
;
951 m_printAllPages
= (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
));
952 m_printSelection
= ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
);
953 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
954 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
955 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
956 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
957 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
958 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
959 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
961 /* port is obsolete in WIN32
965 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
967 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
968 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
969 GlobalUnlock(pd->hDevNames);
971 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
977 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
979 if ( m_printDlgData
== NULL
)
982 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
984 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
985 pd
->hwndOwner
=(HWND
) win
->GetHWND();
992 void wxPrintDialogData::ConvertToNative()
994 m_printData
.ConvertToNative();
995 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
998 void wxPrintDialogData::ConvertFromNative()
1000 m_printData
.ConvertFromNative();
1001 m_printData
.m_nativePrintData
->TransferTo( this ) ;
1007 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
1009 m_printFromPage
= data
.m_printFromPage
;
1010 m_printToPage
= data
.m_printToPage
;
1011 m_printMinPage
= data
.m_printMinPage
;
1012 m_printMaxPage
= data
.m_printMaxPage
;
1013 m_printNoCopies
= data
.m_printNoCopies
;
1014 m_printAllPages
= data
.m_printAllPages
;
1015 m_printCollate
= data
.m_printCollate
;
1016 m_printToFile
= data
.m_printToFile
;
1017 m_printSelection
= data
.m_printSelection
;
1018 m_printEnableSelection
= data
.m_printEnableSelection
;
1019 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
1020 m_printEnableHelp
= data
.m_printEnableHelp
;
1021 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
1022 m_printSetupDialog
= data
.m_printSetupDialog
;
1024 m_printData
= data
.m_printData
;
1027 void wxPrintDialogData::operator=(const wxPrintData
& data
)
1032 // ----------------------------------------------------------------------------
1033 // wxPageSetupDialogData
1034 // ----------------------------------------------------------------------------
1036 wxPageSetupDialogData::wxPageSetupDialogData()
1038 #if defined(__WIN95__)
1039 m_pageSetupData
= NULL
;
1041 m_paperSize
= wxSize(0, 0);
1043 CalculatePaperSizeFromId();
1045 m_minMarginTopLeft
= wxPoint(0, 0);
1046 m_minMarginBottomRight
= wxPoint(0, 0);
1047 m_marginTopLeft
= wxPoint(0, 0);
1048 m_marginBottomRight
= wxPoint(0, 0);
1051 m_defaultMinMargins
= FALSE
;
1052 m_enableMargins
= TRUE
;
1053 m_enableOrientation
= TRUE
;
1054 m_enablePaper
= TRUE
;
1055 m_enablePrinter
= TRUE
;
1056 m_enableHelp
= FALSE
;
1057 m_getDefaultInfo
= FALSE
;
1060 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
1063 #if defined(__WIN95__)
1064 m_pageSetupData
= NULL
;
1066 (*this) = dialogData
;
1069 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
1071 #if defined(__WIN95__)
1072 m_pageSetupData
= NULL
;
1074 m_paperSize
= wxSize(0, 0);
1075 m_minMarginTopLeft
= wxPoint(0, 0);
1076 m_minMarginBottomRight
= wxPoint(0, 0);
1077 m_marginTopLeft
= wxPoint(0, 0);
1078 m_marginBottomRight
= wxPoint(0, 0);
1081 m_defaultMinMargins
= FALSE
;
1082 m_enableMargins
= TRUE
;
1083 m_enableOrientation
= TRUE
;
1084 m_enablePaper
= TRUE
;
1085 m_enablePrinter
= TRUE
;
1086 m_enableHelp
= FALSE
;
1087 m_getDefaultInfo
= FALSE
;
1089 m_printData
= printData
;
1091 // The wxPrintData paper size overrides these values, unless the size cannot
1093 CalculatePaperSizeFromId();
1096 wxPageSetupDialogData::~wxPageSetupDialogData()
1098 #if defined(__WIN95__) && defined(__WXMSW__)
1099 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
1100 if ( pd
&& pd
->hDevMode
)
1101 GlobalFree(pd
->hDevMode
);
1102 if ( pd
&& pd
->hDevNames
)
1103 GlobalFree(pd
->hDevNames
);
1109 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
1111 m_paperSize
= data
.m_paperSize
;
1112 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
1113 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
1114 m_marginTopLeft
= data
.m_marginTopLeft
;
1115 m_marginBottomRight
= data
.m_marginBottomRight
;
1116 m_defaultMinMargins
= data
.m_defaultMinMargins
;
1117 m_enableMargins
= data
.m_enableMargins
;
1118 m_enableOrientation
= data
.m_enableOrientation
;
1119 m_enablePaper
= data
.m_enablePaper
;
1120 m_enablePrinter
= data
.m_enablePrinter
;
1121 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
1122 m_enableHelp
= data
.m_enableHelp
;
1124 m_printData
= data
.m_printData
;
1129 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
1136 #if defined(__WIN95__)
1137 void wxPageSetupDialogData::ConvertToNative()
1139 m_printData
.ConvertToNative();
1141 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1143 if ( m_pageSetupData
== NULL
)
1145 pd
= new PAGESETUPDLG
;
1146 pd
->hDevMode
= NULL
;
1147 pd
->hDevNames
= NULL
;
1148 m_pageSetupData
= (void *)pd
;
1151 // Pass the devmode data (created in m_printData.ConvertToNative)
1152 // to the PRINTDLG structure, since it'll
1153 // be needed when PrintDlg is called.
1157 GlobalFree(pd
->hDevMode
);
1158 pd
->hDevMode
= NULL
;
1161 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
1163 m_printData
.SetNativeData((void*) NULL
);
1165 // Shouldn't assert; we should be able to test Ok-ness at a higher level
1166 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
1168 // Pass the devnames data (created in m_printData.ConvertToNative)
1169 // to the PRINTDLG structure, since it'll
1170 // be needed when PrintDlg is called.
1174 GlobalFree(pd
->hDevNames
);
1175 pd
->hDevNames
= NULL
;
1178 pd
->hDevNames
= (HGLOBAL
) m_printData
.GetNativeDataDevNames();
1180 m_printData
.SetNativeDataDevNames((void*) NULL
);
1182 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1184 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1186 if ( m_defaultMinMargins
)
1187 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
1188 if ( !m_enableMargins
)
1189 pd
->Flags
|= PSD_DISABLEMARGINS
;
1190 if ( !m_enableOrientation
)
1191 pd
->Flags
|= PSD_DISABLEORIENTATION
;
1192 if ( !m_enablePaper
)
1193 pd
->Flags
|= PSD_DISABLEPAPER
;
1194 if ( !m_enablePrinter
)
1195 pd
->Flags
|= PSD_DISABLEPRINTER
;
1196 if ( m_getDefaultInfo
)
1197 pd
->Flags
|= PSD_RETURNDEFAULT
;
1199 pd
->Flags
|= PSD_SHOWHELP
;
1201 // We want the units to be in hundredths of a millimetre
1202 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1204 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
1205 pd
->hwndOwner
=(HWND
)NULL
;
1206 // pd->hDevNames=(HWND)NULL;
1207 pd
->hInstance
=(HINSTANCE
)NULL
;
1208 // PAGESETUPDLG is in hundreds of a mm
1209 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
1210 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
1212 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
1213 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
1214 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
1215 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
1217 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
1218 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
1219 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
1220 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
1223 pd
->lpfnPageSetupHook
= NULL
;
1224 pd
->lpfnPagePaintHook
= NULL
;
1225 pd
->hPageSetupTemplate
= NULL
;
1226 pd
->lpPageSetupTemplateName
= NULL
;
1231 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1232 memset(devMode, 0, sizeof(DEVMODE));
1233 devMode->dmSize = sizeof(DEVMODE);
1234 devMode->dmOrientation = m_orientation;
1235 devMode->dmFields = DM_ORIENTATION;
1236 GlobalUnlock(pd->hDevMode);
1241 void wxPageSetupDialogData::ConvertFromNative()
1243 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1247 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1250 if (m_printData
.GetNativeData())
1252 // Make sure we don't leak memory
1253 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1255 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1256 pd
->hDevMode
= NULL
;
1259 m_printData
.ConvertFromNative();
1261 // Pass the devnames data back to the wxPrintData structure where it really belongs.
1264 if (m_printData
.GetNativeDataDevNames())
1266 // Make sure we don't leak memory
1267 GlobalFree((HGLOBAL
) m_printData
.GetNativeDataDevNames());
1269 m_printData
.SetNativeDataDevNames((void*) pd
->hDevNames
);
1270 pd
->hDevNames
= NULL
;
1273 m_printData
.ConvertFromNative();
1275 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1277 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
1278 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
1279 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
1280 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
1281 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
1282 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
1283 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
1285 // PAGESETUPDLG is in hundreds of a mm
1286 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1287 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
1289 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
1290 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
1291 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
1292 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
1294 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100;
1295 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100;
1296 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100;
1297 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100;
1300 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1302 if ( m_pageSetupData
== NULL
)
1305 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1307 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1308 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1314 void wxPageSetupDialogData::ConvertToNative()
1316 m_printData
.ConvertToNative();
1317 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
1320 void wxPageSetupDialogData::ConvertFromNative()
1322 m_printData
.ConvertFromNative ();
1323 m_paperSize
= m_printData
.GetPaperSize() ;
1324 CalculateIdFromPaperSize();
1325 m_printData
.m_nativePrintData
->TransferTo( this ) ;
1326 // adjust minimal values
1328 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
1329 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
1331 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
1332 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
1334 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
1335 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
1337 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
1338 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
1343 // If a corresponding paper type is found in the paper database, will set the m_printData
1344 // paper size id member as well.
1345 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
1349 CalculateIdFromPaperSize();
1352 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1353 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1355 m_printData
.SetPaperId(id
);
1357 CalculatePaperSizeFromId();
1360 // Use paper size defined in this object to set the wxPrintData
1362 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1364 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1365 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
1367 wxSize sz
= GetPaperSize();
1369 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1370 if (id
!= wxPAPER_NONE
)
1372 m_printData
.SetPaperId(id
);
1376 // Use paper id in wxPrintData to set this object's paper size
1377 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1379 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1380 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
1382 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
1384 // sz is in 10ths of a mm, while paper size is in mm
1385 m_paperSize
.x
= sz
.x
/ 10;
1386 m_paperSize
.y
= sz
.y
/ 10;
1389 #endif // wxUSE_PRINTING_ARCHITECTURE