1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/printdlg.cpp
3 // Purpose: wxPrintDialog, wxPageSetupDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 // Don't use the Windows print dialog if we're in wxUniv mode and using
28 // the PostScript architecture
29 #if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXUNIVERSAL__) || !wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
32 #include "wx/msw/wrapcdlg.h"
34 #include "wx/dcprint.h"
35 #include "wx/cmndata.h"
38 #include "wx/printdlg.h"
39 #include "wx/msw/printdlg.h"
40 #include "wx/msw/dcprint.h"
49 //----------------------------------------------------------------------------
50 // wxWindowsPrintNativeData
51 //----------------------------------------------------------------------------
54 static wxString
wxGetPrintDlgError()
56 DWORD err
= CommDlgExtendedError();
57 wxString msg
= wxT("Unknown");
60 case CDERR_FINDRESFAILURE
: msg
= wxT("CDERR_FINDRESFAILURE"); break;
61 case CDERR_INITIALIZATION
: msg
= wxT("CDERR_INITIALIZATION"); break;
62 case CDERR_LOADRESFAILURE
: msg
= wxT("CDERR_LOADRESFAILURE"); break;
63 case CDERR_LOADSTRFAILURE
: msg
= wxT("CDERR_LOADSTRFAILURE"); break;
64 case CDERR_LOCKRESFAILURE
: msg
= wxT("CDERR_LOCKRESFAILURE"); break;
65 case CDERR_MEMALLOCFAILURE
: msg
= wxT("CDERR_MEMALLOCFAILURE"); break;
66 case CDERR_MEMLOCKFAILURE
: msg
= wxT("CDERR_MEMLOCKFAILURE"); break;
67 case CDERR_NOHINSTANCE
: msg
= wxT("CDERR_NOHINSTANCE"); break;
68 case CDERR_NOHOOK
: msg
= wxT("CDERR_NOHOOK"); break;
69 case CDERR_NOTEMPLATE
: msg
= wxT("CDERR_NOTEMPLATE"); break;
70 case CDERR_STRUCTSIZE
: msg
= wxT("CDERR_STRUCTSIZE"); break;
71 case PDERR_RETDEFFAILURE
: msg
= wxT("PDERR_RETDEFFAILURE"); break;
72 case PDERR_PRINTERNOTFOUND
: msg
= wxT("PDERR_PRINTERNOTFOUND"); break;
73 case PDERR_PARSEFAILURE
: msg
= wxT("PDERR_PARSEFAILURE"); break;
74 case PDERR_NODEVICES
: msg
= wxT("PDERR_NODEVICES"); break;
75 case PDERR_NODEFAULTPRN
: msg
= wxT("PDERR_NODEFAULTPRN"); break;
76 case PDERR_LOADDRVFAILURE
: msg
= wxT("PDERR_LOADDRVFAILURE"); break;
77 case PDERR_INITFAILURE
: msg
= wxT("PDERR_INITFAILURE"); break;
78 case PDERR_GETDEVMODEFAIL
: msg
= wxT("PDERR_GETDEVMODEFAIL"); break;
79 case PDERR_DNDMMISMATCH
: msg
= wxT("PDERR_DNDMMISMATCH"); break;
80 case PDERR_DEFAULTDIFFERENT
: msg
= wxT("PDERR_DEFAULTDIFFERENT"); break;
81 case PDERR_CREATEICFAILURE
: msg
= wxT("PDERR_CREATEICFAILURE"); break;
88 static HGLOBAL
wxCreateDevNames(const wxString
& driverName
, const wxString
& printerName
, const wxString
& portName
)
91 // if (!driverName.empty() && !printerName.empty() && !portName.empty())
92 if (driverName
.empty() && printerName
.empty() && portName
.empty())
97 hDev
= GlobalAlloc(GPTR
, 4*sizeof(WORD
)+
98 ( driverName
.length() + 1 +
99 printerName
.length() + 1 +
100 portName
.length()+1 ) * sizeof(wxChar
) );
101 LPDEVNAMES lpDev
= (LPDEVNAMES
)GlobalLock(hDev
);
102 lpDev
->wDriverOffset
= sizeof(WORD
) * 4 / sizeof(wxChar
);
103 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wDriverOffset
, driverName
);
105 lpDev
->wDeviceOffset
= (WORD
)( lpDev
->wDriverOffset
+
106 driverName
.length() + 1 );
107 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wDeviceOffset
, printerName
);
109 lpDev
->wOutputOffset
= (WORD
)( lpDev
->wDeviceOffset
+
110 printerName
.length() + 1 );
111 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wOutputOffset
, portName
);
121 IMPLEMENT_CLASS(wxWindowsPrintNativeData
, wxPrintNativeDataBase
)
123 wxWindowsPrintNativeData::wxWindowsPrintNativeData()
125 m_devMode
= (void*) NULL
;
126 m_devNames
= (void*) NULL
;
127 m_customWindowsPaperId
= 0;
130 wxWindowsPrintNativeData::~wxWindowsPrintNativeData()
132 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
134 GlobalFree(hDevMode
);
135 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
137 GlobalFree(hDevNames
);
140 bool wxWindowsPrintNativeData::IsOk() const
142 return (m_devMode
!= NULL
) ;
145 bool wxWindowsPrintNativeData::TransferTo( wxPrintData
&data
)
147 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
148 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
156 LPDEVMODE devMode
= (LPDEVMODE
)GlobalLock(hDevMode
);
159 if (devMode
->dmFields
& DM_ORIENTATION
)
160 data
.SetOrientation( devMode
->dmOrientation
);
163 if (devMode
->dmFields
& DM_COLLATE
)
165 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
166 data
.SetCollate( true );
168 data
.SetCollate( false );
171 //// Number of copies
172 if (devMode
->dmFields
& DM_COPIES
)
173 data
.SetNoCopies( devMode
->dmCopies
);
176 if (devMode
->dmFields
& DM_DEFAULTSOURCE
) {
177 switch (devMode
->dmDefaultSource
) {
178 case DMBIN_ONLYONE
: data
.SetBin(wxPRINTBIN_ONLYONE
); break;
179 case DMBIN_LOWER
: data
.SetBin(wxPRINTBIN_LOWER
); break;
180 case DMBIN_MIDDLE
: data
.SetBin(wxPRINTBIN_MIDDLE
); break;
181 case DMBIN_MANUAL
: data
.SetBin(wxPRINTBIN_MANUAL
); break;
182 case DMBIN_ENVELOPE
: data
.SetBin(wxPRINTBIN_ENVELOPE
); break;
183 case DMBIN_ENVMANUAL
: data
.SetBin(wxPRINTBIN_ENVMANUAL
); break;
184 case DMBIN_AUTO
: data
.SetBin(wxPRINTBIN_AUTO
); break;
185 case DMBIN_TRACTOR
: data
.SetBin(wxPRINTBIN_TRACTOR
); break;
186 case DMBIN_SMALLFMT
: data
.SetBin(wxPRINTBIN_SMALLFMT
); break;
187 case DMBIN_LARGEFMT
: data
.SetBin(wxPRINTBIN_LARGEFMT
); break;
188 case DMBIN_LARGECAPACITY
: data
.SetBin(wxPRINTBIN_LARGECAPACITY
); break;
189 case DMBIN_CASSETTE
: data
.SetBin(wxPRINTBIN_CASSETTE
); break;
190 case DMBIN_FORMSOURCE
: data
.SetBin(wxPRINTBIN_FORMSOURCE
); break;
192 if (devMode
->dmDefaultSource
>=DMBIN_USER
) {
193 data
.SetBin((wxPrintBin
)((devMode
->dmDefaultSource
)-DMBIN_USER
+(int)wxPRINTBIN_USER
));
195 data
.SetBin(wxPRINTBIN_DEFAULT
);
200 data
.SetBin(wxPRINTBIN_DEFAULT
);
202 if (devMode
->dmFields
& DM_MEDIATYPE
)
204 wxASSERT( (int)devMode
->dmMediaType
!= wxPRINTMEDIA_DEFAULT
);
205 data
.SetMedia(devMode
->dmMediaType
);
208 if (devMode
->dmDeviceName
[0] != 0)
209 // This syntax fixes a crash when using VS 7.1
210 data
.SetPrinterName( wxString(devMode
->dmDeviceName
, CCHDEVICENAME
) );
213 if (devMode
->dmFields
& DM_COLOR
)
215 if (devMode
->dmColor
== DMCOLOR_COLOR
)
216 data
.SetColour( true );
218 data
.SetColour( false );
221 data
.SetColour( true );
225 // We don't know size of user defined paper and some buggy drivers
226 // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
227 // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
228 // code wouldn't set m_paperSize correctly.
230 bool foundPaperSize
= false;
231 if ((devMode
->dmFields
& DM_PAPERSIZE
) && (devMode
->dmPaperSize
< DMPAPER_USER
))
233 if (wxThePrintPaperDatabase
)
235 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
238 data
.SetPaperId( paper
->GetId() );
239 data
.SetPaperSize( wxSize(paper
->GetWidth() / 10,paper
->GetHeight() / 10) );
240 m_customWindowsPaperId
= 0;
241 foundPaperSize
= true;
246 // Shouldn't really get here
247 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
248 data
.SetPaperId( wxPAPER_NONE
);
249 data
.SetPaperSize( wxSize(0,0) );
250 m_customWindowsPaperId
= 0;
252 GlobalUnlock(hDevMode
);
257 if (!foundPaperSize
) {
258 if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
260 // DEVMODE is in tenths of a millimeter
261 data
.SetPaperSize( wxSize(devMode
->dmPaperWidth
/ 10, devMode
->dmPaperLength
/ 10) );
262 data
.SetPaperId( wxPAPER_NONE
);
263 m_customWindowsPaperId
= devMode
->dmPaperSize
;
267 // Often will reach this for non-standard paper sizes (sizes which
268 // wouldn't be in wxWidget's paper database). Setting
269 // m_customWindowsPaperId to devMode->dmPaperSize should be enough
270 // to get this paper size working.
271 data
.SetPaperSize( wxSize(0,0) );
272 data
.SetPaperId( wxPAPER_NONE
);
273 m_customWindowsPaperId
= devMode
->dmPaperSize
;
279 if (devMode
->dmFields
& DM_DUPLEX
)
281 switch (devMode
->dmDuplex
)
283 case DMDUP_HORIZONTAL
: data
.SetDuplex( wxDUPLEX_HORIZONTAL
); break;
284 case DMDUP_VERTICAL
: data
.SetDuplex( wxDUPLEX_VERTICAL
); break;
286 case DMDUP_SIMPLEX
: data
.SetDuplex( wxDUPLEX_SIMPLEX
); break;
290 data
.SetDuplex( wxDUPLEX_SIMPLEX
);
294 if (devMode
->dmFields
& DM_PRINTQUALITY
)
296 switch (devMode
->dmPrintQuality
)
298 case DMRES_MEDIUM
: data
.SetQuality( wxPRINT_QUALITY_MEDIUM
); break;
299 case DMRES_LOW
: data
.SetQuality( wxPRINT_QUALITY_LOW
); break;
300 case DMRES_DRAFT
: data
.SetQuality( wxPRINT_QUALITY_DRAFT
); break;
301 case DMRES_HIGH
: data
.SetQuality( wxPRINT_QUALITY_HIGH
); break;
304 // TODO: if the printer fills in the resolution in DPI, how
305 // will the application know if it's high, low, draft etc.??
306 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
307 data
.SetQuality( devMode
->dmPrintQuality
);
314 data
.SetQuality( wxPRINT_QUALITY_HIGH
);
316 if (devMode
->dmDriverExtra
> 0)
317 data
.SetPrivData( (char *)devMode
+devMode
->dmSize
, devMode
->dmDriverExtra
);
319 data
.SetPrivData( NULL
, 0 );
321 GlobalUnlock(hDevMode
);
326 LPDEVNAMES lpDevNames
= (LPDEVNAMES
)GlobalLock(hDevNames
);
329 // TODO: Unicode-ification
332 // port is obsolete in WIN32
333 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
335 // Get the printer name
336 wxString printerName
= (LPTSTR
)lpDevNames
+ lpDevNames
->wDeviceOffset
;
338 // Not sure if we should check for this mismatch
339 // wxASSERT_MSG( (m_printerName.empty() || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
341 if (!printerName
.empty())
342 data
.SetPrinterName( printerName
);
344 GlobalUnlock(hDevNames
);
351 bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData
&data
)
353 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
354 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
357 // Use PRINTDLG as a way of creating a DEVMODE object
360 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
365 memset(&pd
, 0, sizeof(PRINTDLG
));
367 pd
.cbStruct
= sizeof(PRINTDLG
);
369 pd
.lStructSize
= sizeof(PRINTDLG
);
373 pd
.hwndOwner
= (HWND
)NULL
;
374 pd
.hDevMode
= NULL
; // Will be created by PrintDlg
375 pd
.hDevNames
= NULL
; // Ditto
376 //pd.hInstance = (HINSTANCE) wxGetInstance();
378 pd
.Flags
= PD_RETURNDEFAULT
;
381 // Fill out the DEVMODE structure
382 // so we can use it as input in the 'real' PrintDlg
386 GlobalFree(pd
.hDevMode
);
388 GlobalFree(pd
.hDevNames
);
392 #if defined(__WXDEBUG__) && defined(__WIN32__)
393 wxString
str(wxT("Printing error: "));
394 str
+= wxGetPrintDlgError();
400 hDevMode
= pd
.hDevMode
;
401 m_devMode
= (void*)(long) hDevMode
;
404 // We'll create a new DEVNAMEs structure below.
406 GlobalFree(pd
.hDevNames
);
409 // hDevNames = pd->hDevNames;
410 // m_devNames = (void*)(long) hDevNames;
411 // pd->hDevnames = NULL;
418 LPDEVMODE devMode
= (LPDEVMODE
) GlobalLock(hDevMode
);
421 devMode
->dmOrientation
= (short)data
.GetOrientation();
424 devMode
->dmCollate
= (data
.GetCollate() ? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
425 devMode
->dmFields
|= DM_COLLATE
;
427 //// Number of copies
428 devMode
->dmCopies
= (short)data
.GetNoCopies();
429 devMode
->dmFields
|= DM_COPIES
;
432 wxString name
= data
.GetPrinterName();
435 //int len = wxMin(31, m_printerName.Len());
436 wxStrncpy((wxChar
*)devMode
->dmDeviceName
,name
.c_str(),31);
437 devMode
->dmDeviceName
[31] = wxT('\0');
441 if (data
.GetColour())
442 devMode
->dmColor
= DMCOLOR_COLOR
;
444 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
445 devMode
->dmFields
|= DM_COLOR
;
449 // Paper id has priority over paper size. If id is specified, then size
450 // is ignored (as it can be filled in even for standard paper sizes)
452 wxPrintPaperType
*paperType
= NULL
;
454 const wxPaperSize paperId
= data
.GetPaperId();
455 if ( paperId
!= wxPAPER_NONE
&& wxThePrintPaperDatabase
)
457 paperType
= wxThePrintPaperDatabase
->FindPaperType(paperId
);
462 devMode
->dmPaperSize
= (short)paperType
->GetPlatformId();
463 devMode
->dmFields
|= DM_PAPERSIZE
;
465 else // custom (or no) paper size
467 const wxSize paperSize
= data
.GetPaperSize();
468 if ( paperSize
!= wxDefaultSize
)
470 // Fall back on specifying the paper size explicitly
471 if(m_customWindowsPaperId
!= 0)
472 devMode
->dmPaperSize
= m_customWindowsPaperId
;
474 devMode
->dmPaperSize
= DMPAPER_USER
;
475 devMode
->dmPaperWidth
= (short)(paperSize
.x
* 10);
476 devMode
->dmPaperLength
= (short)(paperSize
.y
* 10);
477 devMode
->dmFields
|= DM_PAPERWIDTH
;
478 devMode
->dmFields
|= DM_PAPERLENGTH
;
480 //else: neither paper type nor size specified, don't fill DEVMODE
481 // at all so that the system defaults are used
486 switch (data
.GetDuplex())
488 case wxDUPLEX_HORIZONTAL
:
489 duplex
= DMDUP_HORIZONTAL
;
491 case wxDUPLEX_VERTICAL
:
492 duplex
= DMDUP_VERTICAL
;
495 // in fact case wxDUPLEX_SIMPLEX:
496 duplex
= DMDUP_SIMPLEX
;
499 devMode
->dmDuplex
= duplex
;
500 devMode
->dmFields
|= DM_DUPLEX
;
505 switch (data
.GetQuality())
507 case wxPRINT_QUALITY_MEDIUM
:
508 quality
= DMRES_MEDIUM
;
510 case wxPRINT_QUALITY_LOW
:
513 case wxPRINT_QUALITY_DRAFT
:
514 quality
= DMRES_DRAFT
;
516 case wxPRINT_QUALITY_HIGH
:
517 quality
= DMRES_HIGH
;
520 quality
= (short)data
.GetQuality();
523 devMode
->dmPrintQuality
= quality
;
524 devMode
->dmFields
|= DM_PRINTQUALITY
;
526 if (data
.GetPrivDataLen() > 0)
528 memcpy( (char *)devMode
+devMode
->dmSize
, data
.GetPrivData(), data
.GetPrivDataLen() );
529 devMode
->dmDriverExtra
= (WXWORD
)data
.GetPrivDataLen();
532 if (data
.GetBin() != wxPRINTBIN_DEFAULT
)
534 switch (data
.GetBin())
536 case wxPRINTBIN_ONLYONE
: devMode
->dmDefaultSource
= DMBIN_ONLYONE
; break;
537 case wxPRINTBIN_LOWER
: devMode
->dmDefaultSource
= DMBIN_LOWER
; break;
538 case wxPRINTBIN_MIDDLE
: devMode
->dmDefaultSource
= DMBIN_MIDDLE
; break;
539 case wxPRINTBIN_MANUAL
: devMode
->dmDefaultSource
= DMBIN_MANUAL
; break;
540 case wxPRINTBIN_ENVELOPE
: devMode
->dmDefaultSource
= DMBIN_ENVELOPE
; break;
541 case wxPRINTBIN_ENVMANUAL
: devMode
->dmDefaultSource
= DMBIN_ENVMANUAL
; break;
542 case wxPRINTBIN_AUTO
: devMode
->dmDefaultSource
= DMBIN_AUTO
; break;
543 case wxPRINTBIN_TRACTOR
: devMode
->dmDefaultSource
= DMBIN_TRACTOR
; break;
544 case wxPRINTBIN_SMALLFMT
: devMode
->dmDefaultSource
= DMBIN_SMALLFMT
; break;
545 case wxPRINTBIN_LARGEFMT
: devMode
->dmDefaultSource
= DMBIN_LARGEFMT
; break;
546 case wxPRINTBIN_LARGECAPACITY
: devMode
->dmDefaultSource
= DMBIN_LARGECAPACITY
; break;
547 case wxPRINTBIN_CASSETTE
: devMode
->dmDefaultSource
= DMBIN_CASSETTE
; break;
548 case wxPRINTBIN_FORMSOURCE
: devMode
->dmDefaultSource
= DMBIN_FORMSOURCE
; break;
551 devMode
->dmDefaultSource
= (short)(DMBIN_USER
+ data
.GetBin() - wxPRINTBIN_USER
); // 256 + data.GetBin() - 14 = 242 + data.GetBin()
555 devMode
->dmFields
|= DM_DEFAULTSOURCE
;
557 if (data
.GetMedia() != wxPRINTMEDIA_DEFAULT
)
559 devMode
->dmMediaType
= data
.GetMedia();
560 devMode
->dmFields
|= DM_MEDIATYPE
;
562 GlobalUnlock(hDevMode
);
567 GlobalFree(hDevNames
);
570 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
571 m_devNames
= (void*) (long) wxCreateDevNames(wxEmptyString
, data
.GetPrinterName(), wxEmptyString
);
576 // ---------------------------------------------------------------------------
578 // ---------------------------------------------------------------------------
580 IMPLEMENT_CLASS(wxWindowsPrintDialog
, wxPrintDialogBase
)
582 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintDialogData
* data
)
587 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintData
* data
)
589 wxPrintDialogData data2
;
596 bool wxWindowsPrintDialog::Create(wxWindow
*p
, wxPrintDialogData
* data
)
606 m_printDialogData
= *data
;
611 wxWindowsPrintDialog::~wxWindowsPrintDialog()
613 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
614 if (pd
&& pd
->hDevMode
)
615 GlobalFree(pd
->hDevMode
);
619 if (m_destroyDC
&& m_printerDC
)
623 int wxWindowsPrintDialog::ShowModal()
625 ConvertToNative( m_printDialogData
);
627 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
630 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
631 else if (wxTheApp
->GetTopWindow())
632 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
636 bool ret
= (PrintDlg( pd
) != 0);
640 if ( ret
&& (pd
->hDC
) )
642 wxPrinterDC
*pdc
= new wxPrinterDCFromHDC( (WXHDC
) pd
->hDC
);
644 ConvertFromNative( m_printDialogData
);
653 wxDC
*wxWindowsPrintDialog::GetPrintDC()
661 return (wxPrinterDC
*) NULL
;
664 bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData
&data
)
666 wxWindowsPrintNativeData
*native_data
=
667 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
668 data
.GetPrintData().ConvertToNative();
670 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
672 // Shouldn't have been defined anywhere
677 memset( pd
, 0, sizeof(PRINTDLG
) );
678 m_printDlg
= (void*) pd
;
680 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
682 pd
->lStructSize
= 66;
684 pd
->lStructSize
= sizeof(PRINTDLG
);
686 pd
->hwndOwner
= (HWND
)NULL
;
687 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
688 pd
->hDevNames
= NULL
; // Ditto
690 pd
->Flags
= PD_RETURNDEFAULT
;
693 // Pass the devmode data to the PRINTDLG structure, since it'll
694 // be needed when PrintDlg is called.
696 GlobalFree(pd
->hDevMode
);
698 // Pass the devnames data to the PRINTDLG structure, since it'll
699 // be needed when PrintDlg is called.
701 GlobalFree(pd
->hDevNames
);
703 pd
->hDevMode
= (HGLOBAL
)(DWORD
) native_data
->GetDevMode();
704 native_data
->SetDevMode( (void*) NULL
);
706 // Shouldn't assert; we should be able to test Ok-ness at a higher level
707 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
709 pd
->hDevNames
= (HGLOBAL
)(DWORD
) native_data
->GetDevNames();
710 native_data
->SetDevNames( (void*) NULL
);
713 pd
->hDC
= (HDC
) NULL
;
714 pd
->nFromPage
= (WORD
)data
.GetFromPage();
715 pd
->nToPage
= (WORD
)data
.GetToPage();
716 pd
->nMinPage
= (WORD
)data
.GetMinPage();
717 pd
->nMaxPage
= (WORD
)data
.GetMaxPage();
718 pd
->nCopies
= (WORD
)data
.GetNoCopies();
720 pd
->Flags
= PD_RETURNDC
;
723 pd
->lStructSize
= 66;
725 pd
->lStructSize
= sizeof( PRINTDLG
);
728 pd
->hwndOwner
=(HWND
)NULL
;
729 // pd->hDevNames=(HANDLE)NULL;
730 pd
->hInstance
=(HINSTANCE
)NULL
;
731 pd
->lCustData
= (LPARAM
) NULL
;
732 pd
->lpfnPrintHook
= NULL
;
733 pd
->lpfnSetupHook
= NULL
;
734 pd
->lpPrintTemplateName
= NULL
;
735 pd
->lpSetupTemplateName
= NULL
;
736 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
737 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
739 if ( data
.GetAllPages() )
740 pd
->Flags
|= PD_ALLPAGES
;
741 if ( data
.GetSelection() )
742 pd
->Flags
|= PD_SELECTION
;
743 if ( data
.GetCollate() )
744 pd
->Flags
|= PD_COLLATE
;
745 if ( data
.GetPrintToFile() )
746 pd
->Flags
|= PD_PRINTTOFILE
;
747 if ( !data
.GetEnablePrintToFile() )
748 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
749 if ( !data
.GetEnableSelection() )
750 pd
->Flags
|= PD_NOSELECTION
;
751 if ( !data
.GetEnablePageNumbers() )
752 pd
->Flags
|= PD_NOPAGENUMS
;
753 else if ( (!data
.GetAllPages()) && (!data
.GetSelection()) && (data
.GetFromPage() != 0) && (data
.GetToPage() != 0))
754 pd
->Flags
|= PD_PAGENUMS
;
755 if ( data
.GetEnableHelp() )
756 pd
->Flags
|= PD_SHOWHELP
;
761 bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData
&data
)
763 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
767 wxWindowsPrintNativeData
*native_data
=
768 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
770 // Pass the devmode data back to the wxPrintData structure where it really belongs.
773 if (native_data
->GetDevMode())
775 // Make sure we don't leak memory
776 GlobalFree( (HGLOBAL
)(DWORD
) native_data
->GetDevMode() );
778 native_data
->SetDevMode( (void*)(long) pd
->hDevMode
);
782 // Pass the devnames data back to the wxPrintData structure where it really belongs.
785 if (native_data
->GetDevNames())
787 // Make sure we don't leak memory
788 GlobalFree((HGLOBAL
)(DWORD
) native_data
->GetDevNames());
790 native_data
->SetDevNames((void*)(long) pd
->hDevNames
);
791 pd
->hDevNames
= NULL
;
794 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
795 // into wxWidgets form.
796 native_data
->TransferTo( data
.GetPrintData() );
798 data
.SetFromPage( pd
->nFromPage
);
799 data
.SetToPage( pd
->nToPage
);
800 data
.SetMinPage( pd
->nMinPage
);
801 data
.SetMaxPage( pd
->nMaxPage
);
802 data
.SetNoCopies( pd
->nCopies
);
804 data
.SetAllPages( (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
)) );
805 data
.SetSelection( ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
) );
806 data
.SetCollate( ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
) );
807 data
.SetPrintToFile( ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
) );
808 data
.EnablePrintToFile( ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
) );
809 data
.EnableSelection( ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
) );
810 data
.EnablePageNumbers( ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
) );
811 data
.EnableHelp( ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
) );
816 // ---------------------------------------------------------------------------
817 // wxWidnowsPageSetupDialog
818 // ---------------------------------------------------------------------------
820 IMPLEMENT_CLASS(wxWindowsPageSetupDialog
, wxPageSetupDialogBase
)
822 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog()
824 m_dialogParent
= NULL
;
828 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog(wxWindow
*p
, wxPageSetupDialogData
*data
)
833 bool wxWindowsPageSetupDialog::Create(wxWindow
*p
, wxPageSetupDialogData
*data
)
839 m_pageSetupData
= (*data
);
844 wxWindowsPageSetupDialog::~wxWindowsPageSetupDialog()
846 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageDlg
;
847 if ( pd
&& pd
->hDevMode
)
848 GlobalFree(pd
->hDevMode
);
849 if ( pd
&& pd
->hDevNames
)
850 GlobalFree(pd
->hDevNames
);
855 int wxWindowsPageSetupDialog::ShowModal()
857 ConvertToNative( m_pageSetupData
);
859 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
861 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
862 else if (wxTheApp
->GetTopWindow())
863 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
866 BOOL retVal
= PageSetupDlg( pd
) ;
870 ConvertFromNative( m_pageSetupData
);
877 bool wxWindowsPageSetupDialog::ConvertToNative( wxPageSetupDialogData
&data
)
879 wxWindowsPrintNativeData
*native_data
=
880 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
881 data
.GetPrintData().ConvertToNative();
883 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
885 // Shouldn't have been defined anywhere
889 pd
= new PAGESETUPDLG
;
891 pd
->hDevNames
= NULL
;
892 m_pageDlg
= (void *)pd
;
894 // Pass the devmode data (created in m_printData.ConvertToNative)
895 // to the PRINTDLG structure, since it'll
896 // be needed when PrintDlg is called.
900 GlobalFree(pd
->hDevMode
);
903 pd
->hDevMode
= (HGLOBAL
) native_data
->GetDevMode();
904 native_data
->SetDevMode( (void*) NULL
);
906 // Shouldn't assert; we should be able to test Ok-ness at a higher level
907 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
909 // Pass the devnames data (created in m_printData.ConvertToNative)
910 // to the PRINTDLG structure, since it'll
911 // be needed when PrintDlg is called.
915 GlobalFree(pd
->hDevNames
);
916 pd
->hDevNames
= NULL
;
918 pd
->hDevNames
= (HGLOBAL
) native_data
->GetDevNames();
919 native_data
->SetDevNames((void*) NULL
);
921 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
923 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
925 if ( data
.GetDefaultMinMargins() )
926 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
927 if ( !data
.GetEnableMargins() )
928 pd
->Flags
|= PSD_DISABLEMARGINS
;
929 if ( !data
.GetEnableOrientation() )
930 pd
->Flags
|= PSD_DISABLEORIENTATION
;
931 if ( !data
.GetEnablePaper() )
932 pd
->Flags
|= PSD_DISABLEPAPER
;
933 if ( !data
.GetEnablePrinter() )
934 pd
->Flags
|= PSD_DISABLEPRINTER
;
935 if ( data
.GetDefaultInfo() )
936 pd
->Flags
|= PSD_RETURNDEFAULT
;
937 if ( data
.GetEnableHelp() )
938 pd
->Flags
|= PSD_SHOWHELP
;
940 // We want the units to be in hundredths of a millimetre
941 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
943 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
944 pd
->hwndOwner
=(HWND
)NULL
;
945 // pd->hDevNames=(HWND)NULL;
946 pd
->hInstance
=(HINSTANCE
)NULL
;
947 // PAGESETUPDLG is in hundreds of a mm
948 pd
->ptPaperSize
.x
= data
.GetPaperSize().x
* 100;
949 pd
->ptPaperSize
.y
= data
.GetPaperSize().y
* 100;
951 pd
->rtMinMargin
.left
= data
.GetMinMarginTopLeft().x
* 100;
952 pd
->rtMinMargin
.top
= data
.GetMinMarginTopLeft().y
* 100;
953 pd
->rtMinMargin
.right
= data
.GetMinMarginBottomRight().x
* 100;
954 pd
->rtMinMargin
.bottom
= data
.GetMinMarginBottomRight().y
* 100;
956 pd
->rtMargin
.left
= data
.GetMarginTopLeft().x
* 100;
957 pd
->rtMargin
.top
= data
.GetMarginTopLeft().y
* 100;
958 pd
->rtMargin
.right
= data
.GetMarginBottomRight().x
* 100;
959 pd
->rtMargin
.bottom
= data
.GetMarginBottomRight().y
* 100;
962 pd
->lpfnPageSetupHook
= NULL
;
963 pd
->lpfnPagePaintHook
= NULL
;
964 pd
->hPageSetupTemplate
= NULL
;
965 pd
->lpPageSetupTemplateName
= NULL
;
970 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
971 memset(devMode, 0, sizeof(DEVMODE));
972 devMode->dmSize = sizeof(DEVMODE);
973 devMode->dmOrientation = m_orientation;
974 devMode->dmFields = DM_ORIENTATION;
975 GlobalUnlock(pd->hDevMode);
981 bool wxWindowsPageSetupDialog::ConvertFromNative( wxPageSetupDialogData
&data
)
983 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
987 wxWindowsPrintNativeData
*native_data
=
988 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
990 // Pass the devmode data back to the wxPrintData structure where it really belongs.
993 if (native_data
->GetDevMode())
995 // Make sure we don't leak memory
996 GlobalFree((HGLOBAL
) native_data
->GetDevMode());
998 native_data
->SetDevMode( (void*) pd
->hDevMode
);
1002 // Isn't this superfluous? It's called again below.
1003 // data.GetPrintData().ConvertFromNative();
1005 // Pass the devnames data back to the wxPrintData structure where it really belongs.
1008 if (native_data
->GetDevNames())
1010 // Make sure we don't leak memory
1011 GlobalFree((HGLOBAL
) native_data
->GetDevNames());
1013 native_data
->SetDevNames((void*) pd
->hDevNames
);
1014 pd
->hDevNames
= NULL
;
1017 data
.GetPrintData().ConvertFromNative();
1019 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1021 data
.SetDefaultMinMargins( ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
) );
1022 data
.EnableMargins( ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
) );
1023 data
.EnableOrientation( ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
) );
1024 data
.EnablePaper( ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
) );
1025 data
.EnablePrinter( ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
) );
1026 data
.SetDefaultInfo( ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
) );
1027 data
.EnableHelp( ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
) );
1029 // PAGESETUPDLG is in hundreds of a mm
1030 if (data
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
1031 data
.SetPaperSize( wxSize(pd
->ptPaperSize
.y
/ 100, pd
->ptPaperSize
.x
/ 100) );
1033 data
.SetPaperSize( wxSize(pd
->ptPaperSize
.x
/ 100, pd
->ptPaperSize
.y
/ 100) );
1035 data
.SetMinMarginTopLeft( wxPoint(pd
->rtMinMargin
.left
/ 100, pd
->rtMinMargin
.top
/ 100) );
1036 data
.SetMinMarginBottomRight( wxPoint(pd
->rtMinMargin
.right
/ 100, pd
->rtMinMargin
.bottom
/ 100) );
1038 data
.SetMarginTopLeft( wxPoint(pd
->rtMargin
.left
/ 100, pd
->rtMargin
.top
/ 100) );
1039 data
.SetMarginBottomRight( wxPoint(pd
->rtMargin
.right
/ 100, pd
->rtMargin
.bottom
/ 100) );
1045 // wxUSE_PRINTING_ARCHITECTURE