1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI data
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "cmndata.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/string.h"
38 #include "wx/gdicmn.h"
39 #include "wx/cmndata.h"
43 #include "wx/fontdlg.h"
44 #endif // wxUSE_FONTDLG
46 #if wxUSE_PRINTING_ARCHITECTURE
48 #endif // wxUSE_PRINTING_ARCHITECTURE
52 #include "wx/msw/private.h"
54 #if !defined(__WIN32__)
59 #if defined(__WATCOMC__) || defined(__SYMANTEC__) || defined(__SALFORDC__)
66 #include "wx/mac/private/print.h"
69 #if wxUSE_PRINTING_ARCHITECTURE
70 IMPLEMENT_DYNAMIC_CLASS(wxPrintData
, wxObject
)
71 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData
, wxObject
)
72 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData
, wxObject
)
73 #endif // wxUSE_PRINTING_ARCHITECTURE
75 IMPLEMENT_DYNAMIC_CLASS(wxFontData
, wxObject
)
76 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
79 #define DMPAPER_USER 256
82 // ============================================================================
84 // ============================================================================
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 wxColourData::wxColourData()
93 for (i
= 0; i
< 16; i
++)
94 custColours
[i
].Set(255, 255, 255);
97 dataColour
.Set(0,0,0);
100 wxColourData::wxColourData(const wxColourData
& data
)
106 wxColourData::~wxColourData()
110 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
115 custColours
[i
] = colour
;
118 wxColour
wxColourData::GetCustomColour(int i
)
121 return wxColour(0,0,0);
123 return custColours
[i
];
126 void wxColourData::operator=(const wxColourData
& data
)
129 for (i
= 0; i
< 16; i
++)
130 custColours
[i
] = data
.custColours
[i
];
132 dataColour
= (wxColour
&)data
.dataColour
;
133 chooseFull
= data
.chooseFull
;
136 // ----------------------------------------------------------------------------
138 // ----------------------------------------------------------------------------
140 wxFontData::wxFontData()
142 // Intialize colour to black.
143 fontColour
= wxNullColour
;
147 enableEffects
= TRUE
;
151 m_encoding
= wxFONTENCODING_SYSTEM
;
154 wxFontData::~wxFontData()
160 wxFontDialogBase::~wxFontDialogBase()
164 #endif // wxUSE_FONTDLG
166 #if wxUSE_PRINTING_ARCHITECTURE
167 // ----------------------------------------------------------------------------
169 // ----------------------------------------------------------------------------
171 wxPrintData::wxPrintData()
174 m_devMode
= (void*) NULL
;
175 m_devNames
= (void*) NULL
;
176 #elif defined( __WXMAC__ )
177 m_nativePrintData
= wxNativePrintData::Create() ;
179 m_printOrientation
= wxPORTRAIT
;
181 m_printCollate
= FALSE
;
184 m_printerName
= wxT("");
186 m_duplexMode
= wxDUPLEX_SIMPLEX
;
187 m_printQuality
= wxPRINT_QUALITY_HIGH
;
188 m_paperId
= wxPAPER_A4
;
189 m_paperSize
= wxSize(210, 297);
191 // PostScript-specific data
192 m_previewCommand
= wxT("");
193 m_filename
= wxT("");
195 m_printerCommand
= wxT("print");
196 m_printerOptions
= wxT("/nonotify/queue=psqueue");
197 m_afmPath
= wxT("sys$ps_font_metrics:");
201 m_printerCommand
= wxT("print");
202 m_printerOptions
= wxT("");
203 m_afmPath
= wxT("c:\\windows\\system\\");
206 #if !defined(__VMS__) && !defined(__WXMSW__)
207 m_printerCommand
= wxT("lpr");
208 m_printerOptions
= wxT("");
212 m_printerScaleX
= 1.0;
213 m_printerScaleY
= 1.0;
214 m_printerTranslateX
= 0;
215 m_printerTranslateY
= 0;
216 m_printMode
= wxPRINT_MODE_FILE
;
219 wxPrintData::wxPrintData(const wxPrintData
& printData
)
223 m_devMode
= (void*) NULL
;
224 m_devNames
= (void*) NULL
;
225 #elif defined( __WXMAC__ )
226 m_nativePrintData
= wxNativePrintData::Create() ;
231 wxPrintData::~wxPrintData()
234 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
236 GlobalFree(hDevMode
);
237 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
239 GlobalFree(hDevNames
);
240 #elif defined(__WXMAC__)
241 delete m_nativePrintData
;
245 #if defined(__WXMSW__) // && defined(__WIN32__)
247 #if defined(__WXDEBUG__) && defined(__WIN32__)
248 static wxString
wxGetPrintDlgError()
250 DWORD err
= CommDlgExtendedError();
251 wxString msg
= wxT("Unknown");
254 case CDERR_FINDRESFAILURE
: msg
= wxT("CDERR_FINDRESFAILURE"); break;
255 case CDERR_INITIALIZATION
: msg
= wxT("CDERR_INITIALIZATION"); break;
256 case CDERR_LOADRESFAILURE
: msg
= wxT("CDERR_LOADRESFAILURE"); break;
257 case CDERR_LOADSTRFAILURE
: msg
= wxT("CDERR_LOADSTRFAILURE"); break;
258 case CDERR_LOCKRESFAILURE
: msg
= wxT("CDERR_LOCKRESFAILURE"); break;
259 case CDERR_MEMALLOCFAILURE
: msg
= wxT("CDERR_MEMALLOCFAILURE"); break;
260 case CDERR_MEMLOCKFAILURE
: msg
= wxT("CDERR_MEMLOCKFAILURE"); break;
261 case CDERR_NOHINSTANCE
: msg
= wxT("CDERR_NOHINSTANCE"); break;
262 case CDERR_NOHOOK
: msg
= wxT("CDERR_NOHOOK"); break;
263 case CDERR_NOTEMPLATE
: msg
= wxT("CDERR_NOTEMPLATE"); break;
264 case CDERR_STRUCTSIZE
: msg
= wxT("CDERR_STRUCTSIZE"); break;
265 case PDERR_RETDEFFAILURE
: msg
= wxT("PDERR_RETDEFFAILURE"); break;
266 case PDERR_PRINTERNOTFOUND
: msg
= wxT("PDERR_PRINTERNOTFOUND"); break;
267 case PDERR_PARSEFAILURE
: msg
= wxT("PDERR_PARSEFAILURE"); break;
268 case PDERR_NODEVICES
: msg
= wxT("PDERR_NODEVICES"); break;
269 case PDERR_NODEFAULTPRN
: msg
= wxT("PDERR_NODEFAULTPRN"); break;
270 case PDERR_LOADDRVFAILURE
: msg
= wxT("PDERR_LOADDRVFAILURE"); break;
271 case PDERR_INITFAILURE
: msg
= wxT("PDERR_INITFAILURE"); break;
272 case PDERR_GETDEVMODEFAIL
: msg
= wxT("PDERR_GETDEVMODEFAIL"); break;
273 case PDERR_DNDMMISMATCH
: msg
= wxT("PDERR_DNDMMISMATCH"); break;
274 case PDERR_DEFAULTDIFFERENT
: msg
= wxT("PDERR_DEFAULTDIFFERENT"); break;
275 case PDERR_CREATEICFAILURE
: msg
= wxT("PDERR_CREATEICFAILURE"); break;
282 static HGLOBAL
wxCreateDevNames(const wxString
& driverName
, const wxString
& printerName
, const wxString
& portName
)
285 // if (!driverName.IsEmpty() && !printerName.IsEmpty() && !portName.IsEmpty())
286 if (driverName
.IsEmpty() && printerName
.IsEmpty() && portName
.IsEmpty())
291 hDev
= GlobalAlloc(GPTR
, 4*sizeof(WORD
)+
292 ( driverName
.Length() + 1 +
293 printerName
.Length() + 1 +
294 portName
.Length()+1 ) * sizeof(wxChar
) );
295 LPDEVNAMES lpDev
= (LPDEVNAMES
)GlobalLock(hDev
);
296 lpDev
->wDriverOffset
= sizeof(WORD
)*4;
297 wxStrcpy((wxChar
*)((char*)lpDev
+ lpDev
->wDriverOffset
), driverName
);
299 lpDev
->wDeviceOffset
= (WORD
)( lpDev
->wDriverOffset
+
300 sizeof(wxChar
) * ( driverName
.Length() + 1 ) );
301 wxStrcpy((wxChar
*)((char*)lpDev
+ lpDev
->wDeviceOffset
), printerName
);
303 lpDev
->wOutputOffset
= (WORD
)( lpDev
->wDeviceOffset
+
304 sizeof(wxChar
) * ( printerName
.Length() + 1 ) );
305 wxStrcpy((wxChar
*)((char*) lpDev
+ lpDev
->wOutputOffset
), portName
);
315 void wxPrintData::ConvertToNative()
317 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
318 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
321 // Use PRINTDLG as a way of creating a DEVMODE object
324 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
329 memset(&pd
, 0, sizeof(PRINTDLG
));
330 pd
.lStructSize
= sizeof(PRINTDLG
);
333 pd
.hwndOwner
= (HWND
)NULL
;
334 pd
.hDevMode
= NULL
; // Will be created by PrintDlg
335 pd
.hDevNames
= NULL
; // Ditto
336 //pd.hInstance = (HINSTANCE) wxGetInstance();
338 pd
.Flags
= PD_RETURNDEFAULT
;
341 // Fill out the DEVMODE structure
342 // so we can use it as input in the 'real' PrintDlg
346 GlobalFree(pd
.hDevMode
);
348 GlobalFree(pd
.hDevNames
);
352 #if defined(__WXDEBUG__) && defined(__WIN32__)
353 wxString
str(wxT("Printing error: "));
354 str
+= wxGetPrintDlgError();
360 hDevMode
= pd
.hDevMode
;
361 m_devMode
= (void*)(long) hDevMode
;
364 // We'll create a new DEVNAMEs structure below.
366 GlobalFree(pd
.hDevNames
);
369 // hDevNames = pd->hDevNames;
370 // m_devNames = (void*)(long) hDevNames;
371 // pd->hDevnames = NULL;
378 LPDEVMODE devMode
= (LPDEVMODE
) GlobalLock(hDevMode
);
382 devMode
->dmOrientation
= m_printOrientation
;
387 devMode
->dmCollate
= (m_printCollate
? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
388 devMode
->dmFields
|= DM_COLLATE
;
391 //// Number of copies
393 devMode
->dmCopies
= m_printNoCopies
;
394 devMode
->dmFields
|= DM_COPIES
;
398 if (m_printerName
!= wxT(""))
400 //int len = wxMin(31, m_printerName.Len());
401 wxStrncpy((wxChar
*)devMode
->dmDeviceName
,m_printerName
.c_str(),31);
402 devMode
->dmDeviceName
[31] = wxT('\0');
408 devMode
->dmColor
= DMCOLOR_COLOR
;
410 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
412 devMode
->dmFields
|= DM_COLOR
;
416 if (m_paperId
== wxPAPER_NONE
)
418 // DEVMODE is in tenths of a milimeter
419 devMode
->dmPaperWidth
= m_paperSize
.x
* 10;
420 devMode
->dmPaperLength
= m_paperSize
.y
* 10;
421 devMode
->dmPaperSize
= DMPAPER_USER
;
422 devMode
->dmFields
|= DM_PAPERWIDTH
;
423 devMode
->dmFields
|= DM_PAPERLENGTH
;
427 if (wxThePrintPaperDatabase
)
429 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(m_paperId
);
432 devMode
->dmPaperSize
= paper
->GetPlatformId();
433 devMode
->dmFields
|= DM_PAPERSIZE
;
441 switch (m_duplexMode
)
443 case wxDUPLEX_HORIZONTAL
: {
444 duplex
= DMDUP_HORIZONTAL
; break;
446 case wxDUPLEX_VERTICAL
: {
447 duplex
= DMDUP_VERTICAL
; break;
450 case wxDUPLEX_SIMPLEX
: {
451 duplex
= DMDUP_SIMPLEX
; break;
454 devMode
->dmDuplex
= duplex
;
455 devMode
->dmFields
|= DM_DUPLEX
;
460 switch (m_printQuality
)
462 case wxPRINT_QUALITY_MEDIUM
: {
463 quality
= DMRES_MEDIUM
; break;
465 case wxPRINT_QUALITY_LOW
: {
466 quality
= DMRES_LOW
; break;
468 case wxPRINT_QUALITY_DRAFT
: {
469 quality
= DMRES_DRAFT
; break;
471 case wxPRINT_QUALITY_HIGH
: {
472 quality
= DMRES_HIGH
; break;
475 quality
= m_printQuality
; break;
478 devMode
->dmPrintQuality
= quality
;
479 devMode
->dmFields
|= DM_PRINTQUALITY
;
481 GlobalUnlock(hDevMode
);
486 GlobalFree(hDevNames
);
489 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
490 m_devNames
= (void*) (long) wxCreateDevNames(wxT(""), m_printerName
, wxT(""));
493 void wxPrintData::ConvertFromNative()
495 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
496 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
503 LPDEVMODE devMode
= (LPDEVMODE
)GlobalLock(hDevMode
);
507 if (devMode
->dmFields
& DM_ORIENTATION
)
508 m_printOrientation
= devMode
->dmOrientation
;
513 if (devMode
->dmFields
& DM_COLLATE
)
515 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
516 m_printCollate
= TRUE
;
518 m_printCollate
= FALSE
;
522 //// Number of copies
524 if (devMode
->dmFields
& DM_COPIES
)
526 m_printNoCopies
= devMode
->dmCopies
;
531 if (devMode
->dmDeviceName
[0] != 0)
533 m_printerName
= devMode
->dmDeviceName
;
538 if (devMode
->dmFields
& DM_COLOR
)
540 if (devMode
->dmColor
== DMCOLOR_COLOR
)
550 // We don't know size of user defined paper and some buggy drivers
551 // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
552 // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
553 // code wouldn't set m_paperSize correctly.
554 if ((devMode
->dmFields
& DM_PAPERSIZE
) && (devMode
->dmPaperSize
< DMPAPER_USER
))
556 if (wxThePrintPaperDatabase
)
558 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
561 m_paperId
= paper
->GetId();
562 m_paperSize
.x
= paper
->GetWidth() / 10;
563 m_paperSize
.y
= paper
->GetHeight() / 10;
567 // Shouldn't really get here
568 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
570 m_paperId
= wxPAPER_NONE
;
577 // Shouldn't really get here
578 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
580 m_paperId
= wxPAPER_NONE
;
585 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
587 // DEVMODE is in tenths of a milimeter
588 m_paperSize
.x
= devMode
->dmPaperWidth
/ 10;
589 m_paperSize
.y
= devMode
->dmPaperLength
/ 10;
590 m_paperId
= wxPAPER_NONE
;
594 // Shouldn't really get here
595 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
599 m_paperId
= wxPAPER_NONE
;
604 if (devMode
->dmFields
& DM_DUPLEX
)
606 switch (devMode
->dmDuplex
)
608 case DMDUP_HORIZONTAL
: {
609 m_duplexMode
= wxDUPLEX_HORIZONTAL
; break;
611 case DMDUP_VERTICAL
: {
612 m_duplexMode
= wxDUPLEX_VERTICAL
; break;
615 case DMDUP_SIMPLEX
: {
616 m_duplexMode
= wxDUPLEX_SIMPLEX
; break;
621 m_duplexMode
= wxDUPLEX_SIMPLEX
;
625 if (devMode
->dmFields
& DM_PRINTQUALITY
)
627 switch (devMode
->dmPrintQuality
)
630 m_printQuality
= wxPRINT_QUALITY_MEDIUM
; break;
633 m_printQuality
= wxPRINT_QUALITY_LOW
; break;
636 m_printQuality
= wxPRINT_QUALITY_DRAFT
; break;
639 m_printQuality
= wxPRINT_QUALITY_HIGH
; break;
643 // TODO: if the printer fills in the resolution in DPI, how
644 // will the application know if it's high, low, draft etc.??
645 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
646 m_printQuality
= devMode
->dmPrintQuality
; break;
652 m_printQuality
= wxPRINT_QUALITY_HIGH
;
654 GlobalUnlock(hDevMode
);
659 LPDEVNAMES lpDevNames
= (LPDEVNAMES
)GlobalLock(hDevNames
);
662 // TODO: Unicode-ification
665 // port is obsolete in WIN32
666 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
668 // Get the printer name
669 wxString printerName
= (LPTSTR
)lpDevNames
+ lpDevNames
->wDeviceOffset
;
671 // Not sure if we should check for this mismatch
672 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
674 if (printerName
!= wxT(""))
675 m_printerName
= printerName
;
677 GlobalUnlock(hDevNames
);
686 void wxPrintData::ConvertToNative()
688 m_nativePrintData
->TransferFrom( this ) ;
691 void wxPrintData::ConvertFromNative()
693 m_nativePrintData
->TransferTo( this ) ;
698 void wxPrintData::operator=(const wxPrintData
& data
)
701 m_nativePrintData
->CopyFrom( data
.m_nativePrintData
) ;
703 m_printNoCopies
= data
.m_printNoCopies
;
704 m_printCollate
= data
.m_printCollate
;
705 m_printOrientation
= data
.m_printOrientation
;
706 m_printerName
= data
.m_printerName
;
707 m_colour
= data
.m_colour
;
708 m_duplexMode
= data
.m_duplexMode
;
709 m_printQuality
= data
.m_printQuality
;
710 m_paperId
= data
.m_paperId
;
711 m_paperSize
= data
.m_paperSize
;
713 // PostScript-specific data
714 m_printerCommand
= data
.m_printerCommand
;
715 m_previewCommand
= data
.m_previewCommand
;
716 m_printerOptions
= data
.m_printerOptions
;
717 m_filename
= data
.m_filename
;
718 m_afmPath
= data
.m_afmPath
;
719 m_printerScaleX
= data
.m_printerScaleX
;
720 m_printerScaleY
= data
.m_printerScaleY
;
721 m_printerTranslateX
= data
.m_printerTranslateX
;
722 m_printerTranslateY
= data
.m_printerTranslateY
;
723 m_printMode
= data
.m_printMode
;
726 // Is this data OK for showing the print dialog?
727 bool wxPrintData::Ok() const
730 ((wxPrintData
*)this)->ConvertToNative();
731 return (m_devMode
!= NULL
) ;
737 // ----------------------------------------------------------------------------
739 // ----------------------------------------------------------------------------
741 wxPrintDialogData::wxPrintDialogData()
744 m_printDlgData
= NULL
;
751 m_printAllPages
= FALSE
;
752 m_printCollate
= FALSE
;
753 m_printToFile
= FALSE
;
754 m_printSelection
= FALSE
;
755 m_printEnableSelection
= FALSE
;
756 m_printEnablePageNumbers
= TRUE
;
757 m_printEnablePrintToFile
= TRUE
;
758 m_printEnableHelp
= FALSE
;
759 m_printSetupDialog
= FALSE
;
762 wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData
& dialogData
)
766 m_printDlgData
= NULL
;
768 (*this) = dialogData
;
771 wxPrintDialogData::wxPrintDialogData(const wxPrintData
& printData
)
774 m_printDlgData
= NULL
;
781 m_printAllPages
= FALSE
;
782 m_printCollate
= FALSE
;
783 m_printToFile
= FALSE
;
784 m_printSelection
= FALSE
;
785 m_printEnableSelection
= FALSE
;
786 m_printEnablePageNumbers
= TRUE
;
787 m_printEnablePrintToFile
= TRUE
;
788 m_printEnableHelp
= FALSE
;
789 m_printSetupDialog
= FALSE
;
791 m_printData
= printData
;
794 wxPrintDialogData::~wxPrintDialogData()
797 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
798 if ( pd
&& pd
->hDevMode
)
799 GlobalFree(pd
->hDevMode
);
806 void wxPrintDialogData::ConvertToNative()
808 m_printData
.ConvertToNative();
810 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
815 memset( pd
, 0, sizeof(PRINTDLG
) );
816 m_printDlgData
= (void*) pd
;
818 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
820 pd
->lStructSize
= 66;
822 pd
->lStructSize
= sizeof(PRINTDLG
);
824 pd
->hwndOwner
= (HWND
)NULL
;
825 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
826 pd
->hDevNames
= NULL
; // Ditto
828 pd
->Flags
= PD_RETURNDEFAULT
;
832 // Pass the devmode data to the PRINTDLG structure, since it'll
833 // be needed when PrintDlg is called.
836 GlobalFree(pd
->hDevMode
);
839 // Pass the devnames data to the PRINTDLG structure, since it'll
840 // be needed when PrintDlg is called.
843 GlobalFree(pd
->hDevNames
);
846 pd
->hDevMode
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeData();
848 m_printData
.SetNativeData((void*) NULL
);
850 // Shouldn't assert; we should be able to test Ok-ness at a higher level
851 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
853 pd
->hDevNames
= (HGLOBAL
)(DWORD
) m_printData
.GetNativeDataDevNames();
855 m_printData
.SetNativeDataDevNames((void*) NULL
);
857 pd
->hDC
= (HDC
) NULL
;
858 pd
->nFromPage
= (WORD
)m_printFromPage
;
859 pd
->nToPage
= (WORD
)m_printToPage
;
860 pd
->nMinPage
= (WORD
)m_printMinPage
;
861 pd
->nMaxPage
= (WORD
)m_printMaxPage
;
862 pd
->nCopies
= (WORD
)m_printNoCopies
;
864 pd
->Flags
= PD_RETURNDC
;
867 pd
->lStructSize
= 66;
869 pd
->lStructSize
= sizeof( PRINTDLG
);
872 pd
->hwndOwner
=(HWND
)NULL
;
873 // pd->hDevNames=(HANDLE)NULL;
874 pd
->hInstance
=(HINSTANCE
)NULL
;
875 pd
->lCustData
= (LPARAM
) NULL
;
876 pd
->lpfnPrintHook
= NULL
;
877 pd
->lpfnSetupHook
= NULL
;
878 pd
->lpPrintTemplateName
= NULL
;
879 pd
->lpSetupTemplateName
= NULL
;
880 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
881 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
883 if ( m_printAllPages
)
884 pd
->Flags
|= PD_ALLPAGES
;
885 if ( m_printSelection
)
886 pd
->Flags
|= PD_SELECTION
;
887 if ( m_printCollate
)
888 pd
->Flags
|= PD_COLLATE
;
890 pd
->Flags
|= PD_PRINTTOFILE
;
891 if ( !m_printEnablePrintToFile
)
892 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
893 if ( !m_printEnableSelection
)
894 pd
->Flags
|= PD_NOSELECTION
;
895 if ( !m_printEnablePageNumbers
)
896 pd
->Flags
|= PD_NOPAGENUMS
;
897 else if ( (!m_printAllPages
) && (!m_printSelection
) )
898 pd
->Flags
|= PD_PAGENUMS
;
899 if ( m_printEnableHelp
)
900 pd
->Flags
|= PD_SHOWHELP
;
901 if ( m_printSetupDialog
)
902 pd
->Flags
|= PD_PRINTSETUP
;
905 void wxPrintDialogData::ConvertFromNative()
907 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
911 // Pass the devmode data back to the wxPrintData structure where it really belongs.
914 if (m_printData
.GetNativeData())
916 // Make sure we don't leak memory
917 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeData());
919 m_printData
.SetNativeData((void*)(long) pd
->hDevMode
);
923 // Pass the devnames data back to the wxPrintData structure where it really belongs.
926 if (m_printData
.GetNativeDataDevNames())
928 // Make sure we don't leak memory
929 GlobalFree((HGLOBAL
)(DWORD
) m_printData
.GetNativeDataDevNames());
931 m_printData
.SetNativeDataDevNames((void*)(long) pd
->hDevNames
);
932 pd
->hDevNames
= NULL
;
935 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
936 // into wxWindows form.
937 m_printData
.ConvertFromNative();
939 m_printFromPage
= pd
->nFromPage
;
940 m_printToPage
= pd
->nToPage
;
941 m_printMinPage
= pd
->nMinPage
;
942 m_printMaxPage
= pd
->nMaxPage
;
943 m_printNoCopies
= pd
->nCopies
;
945 m_printAllPages
= (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
));
946 m_printSelection
= ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
);
947 m_printCollate
= ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
);
948 m_printToFile
= ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
);
949 m_printEnablePrintToFile
= ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
);
950 m_printEnableSelection
= ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
);
951 m_printEnablePageNumbers
= ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
);
952 m_printEnableHelp
= ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
);
953 m_printSetupDialog
= ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
);
955 /* port is obsolete in WIN32
959 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
961 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
962 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
963 GlobalUnlock(pd->hDevNames);
965 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
971 void wxPrintDialogData::SetOwnerWindow(wxWindow
* win
)
973 if ( m_printDlgData
== NULL
)
976 if ( m_printDlgData
!= NULL
&& win
!= NULL
)
978 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlgData
;
979 pd
->hwndOwner
=(HWND
) win
->GetHWND();
986 void wxPrintDialogData::ConvertToNative()
988 m_printData
.ConvertToNative();
989 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
992 void wxPrintDialogData::ConvertFromNative()
994 m_printData
.ConvertFromNative();
995 m_printData
.m_nativePrintData
->TransferTo( this ) ;
1001 void wxPrintDialogData::operator=(const wxPrintDialogData
& data
)
1003 m_printFromPage
= data
.m_printFromPage
;
1004 m_printToPage
= data
.m_printToPage
;
1005 m_printMinPage
= data
.m_printMinPage
;
1006 m_printMaxPage
= data
.m_printMaxPage
;
1007 m_printNoCopies
= data
.m_printNoCopies
;
1008 m_printAllPages
= data
.m_printAllPages
;
1009 m_printCollate
= data
.m_printCollate
;
1010 m_printToFile
= data
.m_printToFile
;
1011 m_printSelection
= data
.m_printSelection
;
1012 m_printEnableSelection
= data
.m_printEnableSelection
;
1013 m_printEnablePageNumbers
= data
.m_printEnablePageNumbers
;
1014 m_printEnableHelp
= data
.m_printEnableHelp
;
1015 m_printEnablePrintToFile
= data
.m_printEnablePrintToFile
;
1016 m_printSetupDialog
= data
.m_printSetupDialog
;
1018 m_printData
= data
.m_printData
;
1021 void wxPrintDialogData::operator=(const wxPrintData
& data
)
1026 // ----------------------------------------------------------------------------
1027 // wxPageSetupDialogData
1028 // ----------------------------------------------------------------------------
1030 wxPageSetupDialogData::wxPageSetupDialogData()
1032 #if defined(__WIN95__)
1033 m_pageSetupData
= NULL
;
1035 m_paperSize
= wxSize(0, 0);
1037 CalculatePaperSizeFromId();
1039 m_minMarginTopLeft
= wxPoint(0, 0);
1040 m_minMarginBottomRight
= wxPoint(0, 0);
1041 m_marginTopLeft
= wxPoint(0, 0);
1042 m_marginBottomRight
= wxPoint(0, 0);
1045 m_defaultMinMargins
= FALSE
;
1046 m_enableMargins
= TRUE
;
1047 m_enableOrientation
= TRUE
;
1048 m_enablePaper
= TRUE
;
1049 m_enablePrinter
= TRUE
;
1050 m_enableHelp
= FALSE
;
1051 m_getDefaultInfo
= FALSE
;
1054 wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData
& dialogData
)
1057 #if defined(__WIN95__)
1058 m_pageSetupData
= NULL
;
1060 (*this) = dialogData
;
1063 wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData
& printData
)
1065 #if defined(__WIN95__)
1066 m_pageSetupData
= NULL
;
1068 m_paperSize
= wxSize(0, 0);
1069 m_minMarginTopLeft
= wxPoint(0, 0);
1070 m_minMarginBottomRight
= wxPoint(0, 0);
1071 m_marginTopLeft
= wxPoint(0, 0);
1072 m_marginBottomRight
= wxPoint(0, 0);
1075 m_defaultMinMargins
= FALSE
;
1076 m_enableMargins
= TRUE
;
1077 m_enableOrientation
= TRUE
;
1078 m_enablePaper
= TRUE
;
1079 m_enablePrinter
= TRUE
;
1080 m_enableHelp
= FALSE
;
1081 m_getDefaultInfo
= FALSE
;
1083 m_printData
= printData
;
1085 // The wxPrintData paper size overrides these values, unless the size cannot
1087 CalculatePaperSizeFromId();
1090 wxPageSetupDialogData::~wxPageSetupDialogData()
1092 #if defined(__WIN95__) && defined(__WXMSW__)
1093 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageSetupData
;
1094 if ( pd
&& pd
->hDevMode
)
1095 GlobalFree(pd
->hDevMode
);
1096 if ( pd
&& pd
->hDevNames
)
1097 GlobalFree(pd
->hDevNames
);
1103 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPageSetupDialogData
& data
)
1105 m_paperSize
= data
.m_paperSize
;
1106 m_minMarginTopLeft
= data
.m_minMarginTopLeft
;
1107 m_minMarginBottomRight
= data
.m_minMarginBottomRight
;
1108 m_marginTopLeft
= data
.m_marginTopLeft
;
1109 m_marginBottomRight
= data
.m_marginBottomRight
;
1110 m_defaultMinMargins
= data
.m_defaultMinMargins
;
1111 m_enableMargins
= data
.m_enableMargins
;
1112 m_enableOrientation
= data
.m_enableOrientation
;
1113 m_enablePaper
= data
.m_enablePaper
;
1114 m_enablePrinter
= data
.m_enablePrinter
;
1115 m_getDefaultInfo
= data
.m_getDefaultInfo
;;
1116 m_enableHelp
= data
.m_enableHelp
;
1118 m_printData
= data
.m_printData
;
1123 wxPageSetupDialogData
& wxPageSetupDialogData::operator=(const wxPrintData
& data
)
1130 #if defined(__WIN95__)
1131 void wxPageSetupDialogData::ConvertToNative()
1133 m_printData
.ConvertToNative();
1135 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1137 if ( m_pageSetupData
== NULL
)
1139 pd
= new PAGESETUPDLG
;
1140 pd
->hDevMode
= NULL
;
1141 pd
->hDevNames
= NULL
;
1142 m_pageSetupData
= (void *)pd
;
1145 // Pass the devmode data (created in m_printData.ConvertToNative)
1146 // to the PRINTDLG structure, since it'll
1147 // be needed when PrintDlg is called.
1151 GlobalFree(pd
->hDevMode
);
1152 pd
->hDevMode
= NULL
;
1155 pd
->hDevMode
= (HGLOBAL
) m_printData
.GetNativeData();
1157 m_printData
.SetNativeData((void*) NULL
);
1159 // Shouldn't assert; we should be able to test Ok-ness at a higher level
1160 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
1162 // Pass the devnames data (created in m_printData.ConvertToNative)
1163 // to the PRINTDLG structure, since it'll
1164 // be needed when PrintDlg is called.
1168 GlobalFree(pd
->hDevNames
);
1169 pd
->hDevNames
= NULL
;
1172 pd
->hDevNames
= (HGLOBAL
) m_printData
.GetNativeDataDevNames();
1174 m_printData
.SetNativeDataDevNames((void*) NULL
);
1176 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
1178 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1180 if ( m_defaultMinMargins
)
1181 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
1182 if ( !m_enableMargins
)
1183 pd
->Flags
|= PSD_DISABLEMARGINS
;
1184 if ( !m_enableOrientation
)
1185 pd
->Flags
|= PSD_DISABLEORIENTATION
;
1186 if ( !m_enablePaper
)
1187 pd
->Flags
|= PSD_DISABLEPAPER
;
1188 if ( !m_enablePrinter
)
1189 pd
->Flags
|= PSD_DISABLEPRINTER
;
1190 if ( m_getDefaultInfo
)
1191 pd
->Flags
|= PSD_RETURNDEFAULT
;
1193 pd
->Flags
|= PSD_SHOWHELP
;
1195 // We want the units to be in hundredths of a millimetre
1196 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
1198 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
1199 pd
->hwndOwner
=(HWND
)NULL
;
1200 // pd->hDevNames=(HWND)NULL;
1201 pd
->hInstance
=(HINSTANCE
)NULL
;
1202 // PAGESETUPDLG is in hundreds of a mm
1203 pd
->ptPaperSize
.x
= m_paperSize
.x
* 100;
1204 pd
->ptPaperSize
.y
= m_paperSize
.y
* 100;
1206 pd
->rtMinMargin
.left
= m_minMarginTopLeft
.x
* 100;
1207 pd
->rtMinMargin
.top
= m_minMarginTopLeft
.y
* 100;
1208 pd
->rtMinMargin
.right
= m_minMarginBottomRight
.x
* 100;
1209 pd
->rtMinMargin
.bottom
= m_minMarginBottomRight
.y
* 100;
1211 pd
->rtMargin
.left
= m_marginTopLeft
.x
* 100;
1212 pd
->rtMargin
.top
= m_marginTopLeft
.y
* 100;
1213 pd
->rtMargin
.right
= m_marginBottomRight
.x
* 100;
1214 pd
->rtMargin
.bottom
= m_marginBottomRight
.y
* 100;
1217 pd
->lpfnPageSetupHook
= NULL
;
1218 pd
->lpfnPagePaintHook
= NULL
;
1219 pd
->hPageSetupTemplate
= NULL
;
1220 pd
->lpPageSetupTemplateName
= NULL
;
1225 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1226 memset(devMode, 0, sizeof(DEVMODE));
1227 devMode->dmSize = sizeof(DEVMODE);
1228 devMode->dmOrientation = m_orientation;
1229 devMode->dmFields = DM_ORIENTATION;
1230 GlobalUnlock(pd->hDevMode);
1235 void wxPageSetupDialogData::ConvertFromNative()
1237 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1241 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1244 if (m_printData
.GetNativeData())
1246 // Make sure we don't leak memory
1247 GlobalFree((HGLOBAL
) m_printData
.GetNativeData());
1249 m_printData
.SetNativeData((void*) pd
->hDevMode
);
1250 pd
->hDevMode
= NULL
;
1253 m_printData
.ConvertFromNative();
1255 // Pass the devnames data back to the wxPrintData structure where it really belongs.
1258 if (m_printData
.GetNativeDataDevNames())
1260 // Make sure we don't leak memory
1261 GlobalFree((HGLOBAL
) m_printData
.GetNativeDataDevNames());
1263 m_printData
.SetNativeDataDevNames((void*) pd
->hDevNames
);
1264 pd
->hDevNames
= NULL
;
1267 m_printData
.ConvertFromNative();
1269 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1271 m_defaultMinMargins
= ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
);
1272 m_enableMargins
= ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
);
1273 m_enableOrientation
= ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
);
1274 m_enablePaper
= ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
);
1275 m_enablePrinter
= ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
);
1276 m_getDefaultInfo
= ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
);
1277 m_enableHelp
= ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
);
1279 // PAGESETUPDLG is in hundreds of a mm
1280 m_paperSize
.x
= pd
->ptPaperSize
.x
/ 100;
1281 m_paperSize
.y
= pd
->ptPaperSize
.y
/ 100;
1283 m_minMarginTopLeft
.x
= pd
->rtMinMargin
.left
/ 100;
1284 m_minMarginTopLeft
.y
= pd
->rtMinMargin
.top
/ 100;
1285 m_minMarginBottomRight
.x
= pd
->rtMinMargin
.right
/ 100;
1286 m_minMarginBottomRight
.y
= pd
->rtMinMargin
.bottom
/ 100;
1288 m_marginTopLeft
.x
= pd
->rtMargin
.left
/ 100;
1289 m_marginTopLeft
.y
= pd
->rtMargin
.top
/ 100;
1290 m_marginBottomRight
.x
= pd
->rtMargin
.right
/ 100;
1291 m_marginBottomRight
.y
= pd
->rtMargin
.bottom
/ 100;
1294 void wxPageSetupDialogData::SetOwnerWindow(wxWindow
* win
)
1296 if ( m_pageSetupData
== NULL
)
1299 if ( m_pageSetupData
!= NULL
&& win
!= NULL
)
1301 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageSetupData
;
1302 pd
->hwndOwner
=(HWND
) win
->GetHWND();
1308 void wxPageSetupDialogData::ConvertToNative()
1310 m_printData
.ConvertToNative();
1311 m_printData
.m_nativePrintData
->TransferFrom( this ) ;
1314 void wxPageSetupDialogData::ConvertFromNative()
1316 m_printData
.ConvertFromNative ();
1317 m_paperSize
= m_printData
.GetPaperSize() ;
1318 CalculateIdFromPaperSize();
1319 m_printData
.m_nativePrintData
->TransferTo( this ) ;
1320 // adjust minimal values
1322 if ( m_marginTopLeft
.x
< m_minMarginTopLeft
.x
)
1323 m_marginTopLeft
.x
= m_minMarginTopLeft
.x
;
1325 if ( m_marginBottomRight
.x
< m_minMarginBottomRight
.x
)
1326 m_marginBottomRight
.x
= m_minMarginBottomRight
.x
;
1328 if ( m_marginTopLeft
.y
< m_minMarginTopLeft
.y
)
1329 m_marginTopLeft
.y
= m_minMarginTopLeft
.y
;
1331 if ( m_marginBottomRight
.y
< m_minMarginBottomRight
.y
)
1332 m_marginBottomRight
.y
= m_minMarginBottomRight
.y
;
1337 // If a corresponding paper type is found in the paper database, will set the m_printData
1338 // paper size id member as well.
1339 void wxPageSetupDialogData::SetPaperSize(const wxSize
& sz
)
1343 CalculateIdFromPaperSize();
1346 // Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1347 void wxPageSetupDialogData::SetPaperSize(wxPaperSize id
)
1349 m_printData
.SetPaperId(id
);
1351 CalculatePaperSizeFromId();
1354 // Use paper size defined in this object to set the wxPrintData
1356 void wxPageSetupDialogData::CalculateIdFromPaperSize()
1358 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1359 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
1361 wxSize sz
= GetPaperSize();
1363 wxPaperSize id
= wxThePrintPaperDatabase
->GetSize(wxSize(sz
.x
* 10, sz
.y
* 10));
1364 if (id
!= wxPAPER_NONE
)
1366 m_printData
.SetPaperId(id
);
1370 // Use paper id in wxPrintData to set this object's paper size
1371 void wxPageSetupDialogData::CalculatePaperSizeFromId()
1373 wxASSERT_MSG( (wxThePrintPaperDatabase
!= (wxPrintPaperDatabase
*) NULL
),
1374 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
1376 wxSize sz
= wxThePrintPaperDatabase
->GetSize(m_printData
.GetPaperId());
1378 // sz is in 10ths of a mm, while paper size is in mm
1379 m_paperSize
.x
= sz
.x
/ 10;
1380 m_paperSize
.y
= sz
.y
/ 10;
1383 #endif // wxUSE_PRINTING_ARCHITECTURE