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 #if defined(__WXWINCE__) && !wxUSE_SMARTPHONE
58 #if defined(__WATCOMC__) || defined(__SYMANTEC__) || defined(__SALFORDC__)
65 #include "wx/mac/private/print.h"
68 #if wxUSE_PRINTING_ARCHITECTURE
69 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
70 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
71 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
72 #endif // wxUSE_PRINTING_ARCHITECTURE
74 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
75 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
78 #define DMPAPER_USER 256
81 // ============================================================================
83 // ============================================================================
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 wxColourData::wxColourData()
92 for (i
= 0; i
< 16; i
++)
93 m_custColours
[i
].Set(255, 255, 255);
96 m_dataColour
.Set(0,0,0);
99 wxColourData::wxColourData(const wxColourData
& data
)
105 wxColourData::~wxColourData()
109 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
114 m_custColours
[i
] = colour
;
117 wxColour
wxColourData::GetCustomColour(int i
)
120 return wxColour(0,0,0);
122 return m_custColours
[i
];
125 void wxColourData::operator=(const wxColourData
& data
)
128 for (i
= 0; i
< 16; i
++)
129 m_custColours
[i
] = data
.m_custColours
[i
];
131 m_dataColour
= (wxColour
&)data
.m_dataColour
;
132 m_chooseFull
= data
.m_chooseFull
;
135 // ----------------------------------------------------------------------------
137 // ----------------------------------------------------------------------------
139 wxFontData::wxFontData()
141 // Intialize colour to black.
142 m_fontColour
= wxNullColour
;
145 m_allowSymbols
= TRUE
;
146 m_enableEffects
= TRUE
;
150 m_encoding
= wxFONTENCODING_SYSTEM
;
153 wxFontData::~wxFontData()
159 wxFontDialogBase::~wxFontDialogBase()
163 #endif // wxUSE_FONTDLG
165 #if wxUSE_PRINTING_ARCHITECTURE
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
170 wxPrintData::wxPrintData()
173 m_devMode
= (void*) NULL
;
174 m_devNames
= (void*) NULL
;
175 #elif defined( __WXMAC__ )
176 m_nativePrintData
= wxNativePrintData::Create() ;
178 m_printOrientation
= wxPORTRAIT
;
180 m_printCollate
= FALSE
;
183 m_printerName
= wxT("");
185 m_duplexMode
= wxDUPLEX_SIMPLEX
;
186 m_printQuality
= wxPRINT_QUALITY_HIGH
;
187 m_paperId
= wxPAPER_A4
;
188 m_paperSize
= wxSize(210, 297);
190 // PostScript-specific data
191 m_previewCommand
= wxT("");
192 m_filename
= wxT("");
194 m_printerCommand
= wxT("print");
195 m_printerOptions
= wxT("/nonotify/queue=psqueue");
196 m_afmPath
= wxT("sys$ps_font_metrics:");
200 m_printerCommand
= wxT("print");
201 m_printerOptions
= wxT("");
202 m_afmPath
= wxT("c:\\windows\\system\\");
205 #if !defined(__VMS__) && !defined(__WXMSW__)
206 m_printerCommand
= wxT("lpr");
207 m_printerOptions
= wxT("");
211 m_printerScaleX
= 1.0;
212 m_printerScaleY
= 1.0;
213 m_printerTranslateX
= 0;
214 m_printerTranslateY
= 0;
215 m_printMode
= wxPRINT_MODE_FILE
;
218 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
;
394 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
395 devMode
->dmFields
|= DM_COLLATE
;
398 //// Number of copies
400 devMode
->dmCopies
= m_printNoCopies
;
401 devMode
->dmFields
|= DM_COPIES
;
405 if (m_printerName
!= wxT(""))
407 //int len = wxMin(31, m_printerName.Len());
408 wxStrncpy((wxChar
*)devMode
->dmDeviceName
,m_printerName
.c_str(),31);
409 devMode
->dmDeviceName
[31] = wxT('\0');
415 devMode
->dmColor
= DMCOLOR_COLOR
;
417 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
419 devMode
->dmFields
|= DM_COLOR
;
423 if (m_paperId
== wxPAPER_NONE
)
425 // DEVMODE is in tenths of a milimeter
426 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
427 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
428 devMode
->dmPaperSize
= DMPAPER_USER
;
429 devMode
->dmFields
|= DM_PAPERWIDTH
;
430 devMode
->dmFields
|= DM_PAPERLENGTH
;
434 if (wxThePrintPaperDatabase
)
436 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
439 devMode
->dmPaperSize
= paper
->GetPlatformId();
440 devMode
->dmFields
|= DM_PAPERSIZE
;
448 switch (m_duplexMode
)
450 case wxDUPLEX_HORIZONTAL
: {
451 duplex
= DMDUP_HORIZONTAL
; break;
453 case wxDUPLEX_VERTICAL
: {
454 duplex
= DMDUP_VERTICAL
; break;
457 case wxDUPLEX_SIMPLEX
: {
458 duplex
= DMDUP_SIMPLEX
; break;
461 devMode
->dmDuplex
= duplex
;
462 devMode
->dmFields
|= DM_DUPLEX
;
467 switch (m_printQuality
)
469 case wxPRINT_QUALITY_MEDIUM
: {
470 quality
= DMRES_MEDIUM
; break;
472 case wxPRINT_QUALITY_LOW
: {
473 quality
= DMRES_LOW
; break;
475 case wxPRINT_QUALITY_DRAFT
: {
476 quality
= DMRES_DRAFT
; break;
478 case wxPRINT_QUALITY_HIGH
: {
479 quality
= DMRES_HIGH
; break;
482 quality
= m_printQuality
; break;
485 devMode
->dmPrintQuality
= quality
;
486 devMode
->dmFields
|= DM_PRINTQUALITY
;
488 GlobalUnlock(hDevMode
);
493 GlobalFree(hDevNames
);
496 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
497 m_devNames
= (void*) (long) wxCreateDevNames(wxT(""), m_printerName
, wxT(""));
500 void wxPrintData::ConvertFromNative()
502 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
503 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
510 LPDEVMODE devMode
= (LPDEVMODE
)GlobalLock(hDevMode
);
514 if (devMode
->dmFields
& DM_ORIENTATION
)
515 m_printOrientation
= devMode
->dmOrientation
;
520 if (devMode
->dmFields
& DM_COLLATE
)
522 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
523 m_printCollate
= TRUE
;
525 m_printCollate
= FALSE
;
529 //// Number of copies
531 if (devMode
->dmFields
& DM_COPIES
)
533 m_printNoCopies
= devMode
->dmCopies
;
538 if (devMode
->dmDeviceName
[0] != 0)
540 m_printerName
= devMode
->dmDeviceName
;
545 if (devMode
->dmFields
& DM_COLOR
)
547 if (devMode
->dmColor
== DMCOLOR_COLOR
)
557 // We don't know size of user defined paper and some buggy drivers
558 // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
559 // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
560 // code wouldn't set m_paperSize correctly.
561 if ((devMode
->dmFields
& DM_PAPERSIZE
) && (devMode
->dmPaperSize
< DMPAPER_USER
))
563 if (wxThePrintPaperDatabase
)
565 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
568 m_paperId
= paper
->GetId();
569 m_paperSize
.x
= paper
->GetWidth() / 10;
570 m_paperSize
.y
= paper
->GetHeight() / 10;
574 // Shouldn't really get here
575 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
577 m_paperId
= wxPAPER_NONE
;
584 // Shouldn't really get here
585 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
587 m_paperId
= wxPAPER_NONE
;
592 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
594 // DEVMODE is in tenths of a milimeter
595 m_paperSize
.x
= devMode
->dmPaperWidth
/ 10;
596 m_paperSize
.y
= devMode
->dmPaperLength
/ 10;
597 m_paperId
= wxPAPER_NONE
;
601 // Shouldn't really get here
602 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
606 m_paperId
= wxPAPER_NONE
;
611 if (devMode
->dmFields
& DM_DUPLEX
)
613 switch (devMode
->dmDuplex
)
615 case DMDUP_HORIZONTAL
: {
616 m_duplexMode
= wxDUPLEX_HORIZONTAL
; break;
618 case DMDUP_VERTICAL
: {
619 m_duplexMode
= wxDUPLEX_VERTICAL
; break;
622 case DMDUP_SIMPLEX
: {
623 m_duplexMode
= wxDUPLEX_SIMPLEX
; break;
628 m_duplexMode
= wxDUPLEX_SIMPLEX
;
632 if (devMode
->dmFields
& DM_PRINTQUALITY
)
634 switch (devMode
->dmPrintQuality
)
637 m_printQuality
= wxPRINT_QUALITY_MEDIUM
; break;
640 m_printQuality
= wxPRINT_QUALITY_LOW
; break;
643 m_printQuality
= wxPRINT_QUALITY_DRAFT
; break;
646 m_printQuality
= wxPRINT_QUALITY_HIGH
; break;
650 // TODO: if the printer fills in the resolution in DPI, how
651 // will the application know if it's high, low, draft etc.??
652 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
653 m_printQuality
= devMode
->dmPrintQuality
; break;
659 m_printQuality
= wxPRINT_QUALITY_HIGH
;
661 GlobalUnlock(hDevMode
);
666 LPDEVNAMES lpDevNames
= (LPDEVNAMES
)GlobalLock(hDevNames
);
669 // TODO: Unicode-ification
672 // port is obsolete in WIN32
673 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
675 // Get the printer name
676 wxString printerName
= (LPTSTR
)lpDevNames
+ lpDevNames
->wDeviceOffset
;
678 // Not sure if we should check for this mismatch
679 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
681 if (printerName
!= wxT(""))
682 m_printerName
= printerName
;
684 GlobalUnlock(hDevNames
);
693 void wxPrintData::ConvertToNative()
695 m_nativePrintData
->TransferFrom( this ) ;
698 void wxPrintData::ConvertFromNative()
700 m_nativePrintData
->TransferTo( this ) ;
705 void wxPrintData::operator=(const wxPrintData
& data
)
708 m_nativePrintData
->CopyFrom( data
.m_nativePrintData
) ;
710 m_printNoCopies
= data
.m_printNoCopies
;
711 m_printCollate
= data
.m_printCollate
;
712 m_printOrientation
= data
.m_printOrientation
;
713 m_printerName
= data
.m_printerName
;
714 m_colour
= data
.m_colour
;
715 m_duplexMode
= data
.m_duplexMode
;
716 m_printQuality
= data
.m_printQuality
;
717 m_paperId
= data
.m_paperId
;
718 m_paperSize
= data
.m_paperSize
;
720 m_outputstream
= data
.m_outputstream
;
723 // PostScript-specific data
724 m_printerCommand
= data
.m_printerCommand
;
725 m_previewCommand
= data
.m_previewCommand
;
726 m_printerOptions
= data
.m_printerOptions
;
727 m_filename
= data
.m_filename
;
728 m_afmPath
= data
.m_afmPath
;
729 m_printerScaleX
= data
.m_printerScaleX
;
730 m_printerScaleY
= data
.m_printerScaleY
;
731 m_printerTranslateX
= data
.m_printerTranslateX
;
732 m_printerTranslateY
= data
.m_printerTranslateY
;
733 m_printMode
= data
.m_printMode
;
736 // Is this data OK for showing the print dialog?
737 bool wxPrintData::Ok() const
740 ((wxPrintData
*)this)->ConvertToNative();
741 return (m_devMode
!= NULL
) ;
747 // ----------------------------------------------------------------------------
749 // ----------------------------------------------------------------------------
751 wxPrintDialogData::wxPrintDialogData()
754 m_printDlgData
= NULL
;
761 m_printAllPages
= FALSE
;
762 m_printCollate
= FALSE
;
763 m_printToFile
= FALSE
;
764 m_printSelection
= FALSE
;
765 m_printEnableSelection
= FALSE
;
766 m_printEnablePageNumbers
= TRUE
;
767 m_printEnablePrintToFile
= TRUE
;
768 m_printEnableHelp
= FALSE
;
769 m_printSetupDialog
= FALSE
;
772 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
776 m_printDlgData
= NULL
;
778 (*this) = dialogData
;
781 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
784 m_printDlgData
= NULL
;
789 m_printMaxPage
= 9999;
791 m_printAllPages
= FALSE
;
792 m_printCollate
= FALSE
;
793 m_printToFile
= FALSE
;
794 m_printSelection
= FALSE
;
795 m_printEnableSelection
= FALSE
;
796 m_printEnablePageNumbers
= TRUE
;
797 m_printEnablePrintToFile
= TRUE
;
798 m_printEnableHelp
= FALSE
;
799 m_printSetupDialog
= FALSE
;
801 m_printData
= printData
;
804 wxPrintDialogData::~wxPrintDialogData()
807 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
808 if ( pd
&& pd
->hDevMode
)
809 GlobalFree(pd
->hDevMode
);
816 void wxPrintDialogData::ConvertToNative()
818 m_printData
.ConvertToNative();
820 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
825 memset( pd
, 0, sizeof(PRINTDLG
) );
826 m_printDlgData
= (void*) pd
;
828 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
830 pd
->lStructSize
= 66;
832 pd
->lStructSize
= sizeof(PRINTDLG
);
834 pd
->hwndOwner
= (HWND
)NULL
;
835 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
836 pd
->hDevNames
= NULL
; // Ditto
838 pd
->Flags
= PD_RETURNDEFAULT
;
842 // Pass the devmode data to the PRINTDLG structure, since it'll
843 // be needed when PrintDlg is called.
846 GlobalFree(pd
->hDevMode
);
849 // Pass the devnames data to the PRINTDLG structure, since it'll
850 // be needed when PrintDlg is called.
853 GlobalFree(pd
->hDevNames
);
856 pd
->hDevMode
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeData();
858 m_printData
.SetNativeData((void*) NULL
);
860 // Shouldn't assert; we should be able to test Ok-ness at a higher level
861 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
863 pd
->hDevNames
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeDataDevNames();
865 m_printData
.SetNativeDataDevNames((void*) NULL
);
867 pd
->hDC
= (HDC
) NULL
;
868 pd
->nFromPage
= (WORD
)m_printFromPage
;
869 pd
->nToPage
= (WORD
)m_printToPage
;
870 pd
->nMinPage
= (WORD
)m_printMinPage
;
871 pd
->nMaxPage
= (WORD
)m_printMaxPage
;
872 pd
->nCopies
= (WORD
)m_printNoCopies
;
874 pd
->Flags
= PD_RETURNDC
;
877 pd
->lStructSize
= 66;
879 pd
->lStructSize
= sizeof( PRINTDLG
);
882 pd
->hwndOwner
=(HWND
)NULL
;
883 // pd->hDevNames=(HANDLE)NULL;
884 pd
->hInstance
=(HINSTANCE
)NULL
;
885 pd
->lCustData
= (LPARAM
) NULL
;
886 pd
->lpfnPrintHook
= NULL
;
887 pd
->lpfnSetupHook
= NULL
;
888 pd
->lpPrintTemplateName
= NULL
;
889 pd
->lpSetupTemplateName
= NULL
;
890 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
891 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
893 if ( m_printAllPages
)
894 pd
->Flags
|= PD_ALLPAGES
;
895 if ( m_printSelection
)
896 pd
->Flags
|= PD_SELECTION
;
897 if ( m_printCollate
)
898 pd
->Flags
|= PD_COLLATE
;
900 pd
->Flags
|= PD_PRINTTOFILE
;
901 if ( !m_printEnablePrintToFile
)
902 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
903 if ( !m_printEnableSelection
)
904 pd
->Flags
|= PD_NOSELECTION
;
905 if ( !m_printEnablePageNumbers
)
906 pd
->Flags
|= PD_NOPAGENUMS
;
907 else if ( (!m_printAllPages
) && (!m_printSelection
) && (m_printFromPage
!= 0) && (m_printToPage
!= 0))
908 pd
->Flags
|= PD_PAGENUMS
;
909 if ( m_printEnableHelp
)
910 pd
->Flags
|= PD_SHOWHELP
;
911 if ( m_printSetupDialog
)
912 pd
->Flags
|= PD_PRINTSETUP
;
915 void wxPrintDialogData::ConvertFromNative()
917 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
921 // Pass the devmode data back to the wxPrintData structure where it really belongs.
924 if (m_printData
.GetNativeData())
926 // Make sure we don't leak memory
927 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeData());
929 m_printData
.SetNativeData((void*)(long) pd
->hDevMode
);
933 // Pass the devnames data back to the wxPrintData structure where it really belongs.
936 if (m_printData
.GetNativeDataDevNames())
938 // Make sure we don't leak memory
939 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeDataDevNames());
941 m_printData
.SetNativeDataDevNames((void*)(long) pd
->hDevNames
);
942 pd
->hDevNames
= NULL
;
945 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
946 // into wxWindows form.
947 m_printData
.ConvertFromNative();
949 m_printFromPage
= pd
->nFromPage
;
950 m_printToPage
= pd
->nToPage
;
951 m_printMinPage
= pd
->nMinPage
;
952 m_printMaxPage
= pd
->nMaxPage
;
953 m_printNoCopies
= pd
->nCopies
;
955 m_printAllPages
= (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
));
956 m_printSelection
= ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
);
957 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
958 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
959 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
960 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
961 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
962 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
963 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
965 /* port is obsolete in WIN32
969 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
971 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
972 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
973 GlobalUnlock(pd->hDevNames);
975 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
981 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
983 if ( m_printDlgData
== NULL
)
986 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
988 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
989 pd
->hwndOwner
=(HWND
) win
->GetHWND();
996 void wxPrintDialogData::ConvertToNative()
998 m_printData
.ConvertToNative();
999 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
1002 void wxPrintDialogData::ConvertFromNative()
1004 m_printData
.ConvertFromNative();
1005 m_printData
.m_nativePrintData
->TransferTo( this ) ;
1011 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
1013 m_printFromPage
= data
.m_printFromPage
;
1014 m_printToPage
= data
.m_printToPage
;
1015 m_printMinPage
= data
.m_printMinPage
;
1016 m_printMaxPage
= data
.m_printMaxPage
;
1017 m_printNoCopies
= data
.m_printNoCopies
;
1018 m_printAllPages
= data
.m_printAllPages
;
1019 m_printCollate
= data
.m_printCollate
;
1020 m_printToFile
= data
.m_printToFile
;
1021 m_printSelection
= data
.m_printSelection
;
1022 m_printEnableSelection
= data
.m_printEnableSelection
;
1023 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
1024 m_printEnableHelp
= data
.m_printEnableHelp
;
1025 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
1026 m_printSetupDialog
= data
.m_printSetupDialog
;
1028 m_printData
= data
.m_printData
;
1031 void wxPrintDialogData::operator=(const wxPrintData
& data
)
1036 // ----------------------------------------------------------------------------
1037 // wxPageSetupDialogData
1038 // ----------------------------------------------------------------------------
1040 wxPageSetupDialogData::wxPageSetupDialogData()
1042 #if defined(__WIN95__)
1043 m_pageSetupData
= NULL
;
1045 m_paperSize
= wxSize(0, 0);
1047 CalculatePaperSizeFromId();
1049 m_minMarginTopLeft
= wxPoint(0, 0);
1050 m_minMarginBottomRight
= wxPoint(0, 0);
1051 m_marginTopLeft
= wxPoint(0, 0);
1052 m_marginBottomRight
= wxPoint(0, 0);
1055 m_defaultMinMargins
= FALSE
;
1056 m_enableMargins
= TRUE
;
1057 m_enableOrientation
= TRUE
;
1058 m_enablePaper
= TRUE
;
1059 m_enablePrinter
= TRUE
;
1060 m_enableHelp
= FALSE
;
1061 m_getDefaultInfo
= FALSE
;
1064 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
1067 #if defined(__WIN95__)
1068 m_pageSetupData
= NULL
;
1070 (*this) = dialogData
;
1073 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
1075 #if defined(__WIN95__)
1076 m_pageSetupData
= NULL
;
1078 m_paperSize
= wxSize(0, 0);
1079 m_minMarginTopLeft
= wxPoint(0, 0);
1080 m_minMarginBottomRight
= wxPoint(0, 0);
1081 m_marginTopLeft
= wxPoint(0, 0);
1082 m_marginBottomRight
= wxPoint(0, 0);
1085 m_defaultMinMargins
= FALSE
;
1086 m_enableMargins
= TRUE
;
1087 m_enableOrientation
= TRUE
;
1088 m_enablePaper
= TRUE
;
1089 m_enablePrinter
= TRUE
;
1090 m_enableHelp
= FALSE
;
1091 m_getDefaultInfo
= FALSE
;
1093 m_printData
= printData
;
1095 // The wxPrintData paper size overrides these values, unless the size cannot
1097 CalculatePaperSizeFromId();
1100 wxPageSetupDialogData::~wxPageSetupDialogData()
1102 #if defined(__WIN95__) && defined(__WXMSW__)
1103 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
1104 if ( pd
&& pd
->hDevMode
)
1105 GlobalFree(pd
->hDevMode
);
1106 if ( pd
&& pd
->hDevNames
)
1107 GlobalFree(pd
->hDevNames
);
1113 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
1115 m_paperSize
= data
.m_paperSize
;
1116 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
1117 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
1118 m_marginTopLeft
= data
.m_marginTopLeft
;
1119 m_marginBottomRight
= data
.m_marginBottomRight
;
1120 m_defaultMinMargins
= data
.m_defaultMinMargins
;
1121 m_enableMargins
= data
.m_enableMargins
;
1122 m_enableOrientation
= data
.m_enableOrientation
;
1123 m_enablePaper
= data
.m_enablePaper
;
1124 m_enablePrinter
= data
.m_enablePrinter
;
1125 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
1126 m_enableHelp
= data
.m_enableHelp
;
1128 m_printData
= data
.m_printData
;
1133 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
1140 #if defined(__WIN95__)
1141 void wxPageSetupDialogData::ConvertToNative()
1143 m_printData
.ConvertToNative();
1145 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1147 if ( m_pageSetupData
== NULL
)
1149 pd
= new PAGESETUPDLG
;
1150 pd
->hDevMode
= NULL
;
1151 pd
->hDevNames
= NULL
;
1152 m_pageSetupData
= (void *)pd
;
1155 // Pass the devmode data (created in m_printData.ConvertToNative)
1156 // to the PRINTDLG structure, since it'll
1157 // be needed when PrintDlg is called.
1161 GlobalFree(pd
->hDevMode
);
1162 pd
->hDevMode
= NULL
;
1165 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
1167 m_printData
.SetNativeData((void*) NULL
);
1169 // Shouldn't assert; we should be able to test Ok-ness at a higher level
1170 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
1172 // Pass the devnames data (created in m_printData.ConvertToNative)
1173 // to the PRINTDLG structure, since it'll
1174 // be needed when PrintDlg is called.
1178 GlobalFree(pd
->hDevNames
);
1179 pd
->hDevNames
= NULL
;
1182 pd
->hDevNames
= (HGLOBAL
) m_printData
.GetNativeDataDevNames();
1184 m_printData
.SetNativeDataDevNames((void*) NULL
);
1186 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1188 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1190 if ( m_defaultMinMargins
)
1191 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
1192 if ( !m_enableMargins
)
1193 pd
->Flags
|= PSD_DISABLEMARGINS
;
1194 if ( !m_enableOrientation
)
1195 pd
->Flags
|= PSD_DISABLEORIENTATION
;
1196 if ( !m_enablePaper
)
1197 pd
->Flags
|= PSD_DISABLEPAPER
;
1198 if ( !m_enablePrinter
)
1199 pd
->Flags
|= PSD_DISABLEPRINTER
;
1200 if ( m_getDefaultInfo
)
1201 pd
->Flags
|= PSD_RETURNDEFAULT
;
1203 pd
->Flags
|= PSD_SHOWHELP
;
1205 // We want the units to be in hundredths of a millimetre
1206 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1208 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
1209 pd
->hwndOwner
=(HWND
)NULL
;
1210 // pd->hDevNames=(HWND)NULL;
1211 pd
->hInstance
=(HINSTANCE
)NULL
;
1212 // PAGESETUPDLG is in hundreds of a mm
1213 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
1214 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
1216 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
1217 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
1218 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
1219 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
1221 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
1222 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
1223 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
1224 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
1227 pd
->lpfnPageSetupHook
= NULL
;
1228 pd
->lpfnPagePaintHook
= NULL
;
1229 pd
->hPageSetupTemplate
= NULL
;
1230 pd
->lpPageSetupTemplateName
= NULL
;
1235 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1236 memset(devMode, 0, sizeof(DEVMODE));
1237 devMode->dmSize = sizeof(DEVMODE);
1238 devMode->dmOrientation = m_orientation;
1239 devMode->dmFields = DM_ORIENTATION;
1240 GlobalUnlock(pd->hDevMode);
1245 void wxPageSetupDialogData::ConvertFromNative()
1247 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1251 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1254 if (m_printData
.GetNativeData())
1256 // Make sure we don't leak memory
1257 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1259 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1260 pd
->hDevMode
= NULL
;
1263 m_printData
.ConvertFromNative();
1265 // Pass the devnames data back to the wxPrintData structure where it really belongs.
1268 if (m_printData
.GetNativeDataDevNames())
1270 // Make sure we don't leak memory
1271 GlobalFree((HGLOBAL
) m_printData
.GetNativeDataDevNames());
1273 m_printData
.SetNativeDataDevNames((void*) pd
->hDevNames
);
1274 pd
->hDevNames
= NULL
;
1277 m_printData
.ConvertFromNative();
1279 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1281 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
1282 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
1283 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
1284 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
1285 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
1286 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
1287 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
1289 // PAGESETUPDLG is in hundreds of a mm
1290 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1291 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
1293 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
1294 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
1295 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
1296 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
1298 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100;
1299 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100;
1300 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100;
1301 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100;
1304 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1306 if ( m_pageSetupData
== NULL
)
1309 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1311 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1312 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1318 void wxPageSetupDialogData::ConvertToNative()
1320 m_printData
.ConvertToNative();
1321 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
1324 void wxPageSetupDialogData::ConvertFromNative()
1326 m_printData
.ConvertFromNative ();
1327 m_paperSize
= m_printData
.GetPaperSize() ;
1328 CalculateIdFromPaperSize();
1329 m_printData
.m_nativePrintData
->TransferTo( this ) ;
1330 // adjust minimal values
1332 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
1333 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
1335 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
1336 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
1338 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
1339 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
1341 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
1342 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
1347 // If a corresponding paper type is found in the paper database, will set the m_printData
1348 // paper size id member as well.
1349 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
1353 CalculateIdFromPaperSize();
1356 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1357 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1359 m_printData
.SetPaperId(id
);
1361 CalculatePaperSizeFromId();
1364 // Use paper size defined in this object to set the wxPrintData
1366 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1368 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1369 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
1371 wxSize sz
= GetPaperSize();
1373 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1374 if (id
!= wxPAPER_NONE
)
1376 m_printData
.SetPaperId(id
);
1380 // Use paper id in wxPrintData to set this object's paper size
1381 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1383 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1384 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
1386 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
1388 // sz is in 10ths of a mm, while paper size is in mm
1389 m_paperSize
.x
= sz
.x
/ 10;
1390 m_paperSize
.y
= sz
.y
/ 10;
1393 #endif // wxUSE_PRINTING_ARCHITECTURE