1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPrintDialog, wxPageSetupDialog
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 "printdlg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 // Don't use the Windows print dialog if we're in wxUniv mode and using
32 // the PostScript architecture
33 #if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXUNIVERSAL__) || !wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
39 #include "wx/cmndata.h"
40 #include "wx/printdlg.h"
41 #include "wx/msw/printdlg.h"
42 #include "wx/dcprint.h"
47 #include "wx/msw/wrapcdlg.h"
53 //----------------------------------------------------------------------------
54 // wxWindowsPrintNativeData
55 //----------------------------------------------------------------------------
58 static wxString
wxGetPrintDlgError()
60 DWORD err
= CommDlgExtendedError();
61 wxString msg
= wxT("Unknown");
64 case CDERR_FINDRESFAILURE
: msg
= wxT("CDERR_FINDRESFAILURE"); break;
65 case CDERR_INITIALIZATION
: msg
= wxT("CDERR_INITIALIZATION"); break;
66 case CDERR_LOADRESFAILURE
: msg
= wxT("CDERR_LOADRESFAILURE"); break;
67 case CDERR_LOADSTRFAILURE
: msg
= wxT("CDERR_LOADSTRFAILURE"); break;
68 case CDERR_LOCKRESFAILURE
: msg
= wxT("CDERR_LOCKRESFAILURE"); break;
69 case CDERR_MEMALLOCFAILURE
: msg
= wxT("CDERR_MEMALLOCFAILURE"); break;
70 case CDERR_MEMLOCKFAILURE
: msg
= wxT("CDERR_MEMLOCKFAILURE"); break;
71 case CDERR_NOHINSTANCE
: msg
= wxT("CDERR_NOHINSTANCE"); break;
72 case CDERR_NOHOOK
: msg
= wxT("CDERR_NOHOOK"); break;
73 case CDERR_NOTEMPLATE
: msg
= wxT("CDERR_NOTEMPLATE"); break;
74 case CDERR_STRUCTSIZE
: msg
= wxT("CDERR_STRUCTSIZE"); break;
75 case PDERR_RETDEFFAILURE
: msg
= wxT("PDERR_RETDEFFAILURE"); break;
76 case PDERR_PRINTERNOTFOUND
: msg
= wxT("PDERR_PRINTERNOTFOUND"); break;
77 case PDERR_PARSEFAILURE
: msg
= wxT("PDERR_PARSEFAILURE"); break;
78 case PDERR_NODEVICES
: msg
= wxT("PDERR_NODEVICES"); break;
79 case PDERR_NODEFAULTPRN
: msg
= wxT("PDERR_NODEFAULTPRN"); break;
80 case PDERR_LOADDRVFAILURE
: msg
= wxT("PDERR_LOADDRVFAILURE"); break;
81 case PDERR_INITFAILURE
: msg
= wxT("PDERR_INITFAILURE"); break;
82 case PDERR_GETDEVMODEFAIL
: msg
= wxT("PDERR_GETDEVMODEFAIL"); break;
83 case PDERR_DNDMMISMATCH
: msg
= wxT("PDERR_DNDMMISMATCH"); break;
84 case PDERR_DEFAULTDIFFERENT
: msg
= wxT("PDERR_DEFAULTDIFFERENT"); break;
85 case PDERR_CREATEICFAILURE
: msg
= wxT("PDERR_CREATEICFAILURE"); break;
92 static HGLOBAL
wxCreateDevNames(const wxString
& driverName
, const wxString
& printerName
, const wxString
& portName
)
95 // if (!driverName.empty() && !printerName.empty() && !portName.empty())
96 if (driverName
.empty() && printerName
.empty() && portName
.empty())
101 hDev
= GlobalAlloc(GPTR
, 4*sizeof(WORD
)+
102 ( driverName
.Length() + 1 +
103 printerName
.Length() + 1 +
104 portName
.Length()+1 ) * sizeof(wxChar
) );
105 LPDEVNAMES lpDev
= (LPDEVNAMES
)GlobalLock(hDev
);
106 lpDev
->wDriverOffset
= sizeof(WORD
) * 4 / sizeof(wxChar
);
107 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wDriverOffset
, driverName
);
109 lpDev
->wDeviceOffset
= (WORD
)( lpDev
->wDriverOffset
+
110 driverName
.Length() + 1 );
111 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wDeviceOffset
, printerName
);
113 lpDev
->wOutputOffset
= (WORD
)( lpDev
->wDeviceOffset
+
114 printerName
.Length() + 1 );
115 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wOutputOffset
, portName
);
125 IMPLEMENT_CLASS(wxWindowsPrintNativeData
, wxPrintNativeDataBase
)
127 wxWindowsPrintNativeData::wxWindowsPrintNativeData()
129 m_devMode
= (void*) NULL
;
130 m_devNames
= (void*) NULL
;
131 m_customWindowsPaperId
= 0;
134 wxWindowsPrintNativeData::~wxWindowsPrintNativeData()
136 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
138 GlobalFree(hDevMode
);
139 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
141 GlobalFree(hDevNames
);
144 bool wxWindowsPrintNativeData::Ok() const
146 return (m_devMode
!= NULL
) ;
149 bool wxWindowsPrintNativeData::TransferTo( wxPrintData
&data
)
151 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
152 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
160 LPDEVMODE devMode
= (LPDEVMODE
)GlobalLock(hDevMode
);
163 if (devMode
->dmFields
& DM_ORIENTATION
)
164 data
.SetOrientation( devMode
->dmOrientation
);
167 if (devMode
->dmFields
& DM_COLLATE
)
169 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
170 data
.SetCollate( true );
172 data
.SetCollate( false );
175 //// Number of copies
176 if (devMode
->dmFields
& DM_COPIES
)
177 data
.SetNoCopies( devMode
->dmCopies
);
180 if (devMode
->dmFields
& DM_DEFAULTSOURCE
) {
181 switch (devMode
->dmDefaultSource
) {
182 case DMBIN_ONLYONE
: data
.SetBin(wxPRINTBIN_ONLYONE
); break;
183 case DMBIN_LOWER
: data
.SetBin(wxPRINTBIN_LOWER
); break;
184 case DMBIN_MIDDLE
: data
.SetBin(wxPRINTBIN_MIDDLE
); break;
185 case DMBIN_MANUAL
: data
.SetBin(wxPRINTBIN_MANUAL
); break;
186 case DMBIN_ENVELOPE
: data
.SetBin(wxPRINTBIN_ENVELOPE
); break;
187 case DMBIN_ENVMANUAL
: data
.SetBin(wxPRINTBIN_ENVMANUAL
); break;
188 case DMBIN_AUTO
: data
.SetBin(wxPRINTBIN_AUTO
); break;
189 case DMBIN_TRACTOR
: data
.SetBin(wxPRINTBIN_TRACTOR
); break;
190 case DMBIN_SMALLFMT
: data
.SetBin(wxPRINTBIN_SMALLFMT
); break;
191 case DMBIN_LARGEFMT
: data
.SetBin(wxPRINTBIN_LARGEFMT
); break;
192 case DMBIN_LARGECAPACITY
: data
.SetBin(wxPRINTBIN_LARGECAPACITY
); break;
193 case DMBIN_CASSETTE
: data
.SetBin(wxPRINTBIN_CASSETTE
); break;
194 case DMBIN_FORMSOURCE
: data
.SetBin(wxPRINTBIN_FORMSOURCE
); break;
196 if (devMode
->dmDefaultSource
>=DMBIN_USER
) {
197 data
.SetBin((wxPrintBin
)((devMode
->dmDefaultSource
)-DMBIN_USER
+(int)wxPRINTBIN_USER
));
199 data
.SetBin(wxPRINTBIN_DEFAULT
);
204 data
.SetBin(wxPRINTBIN_DEFAULT
);
208 if (devMode
->dmDeviceName
[0] != 0)
209 data
.SetPrinterName( devMode
->dmDeviceName
);
212 if (devMode
->dmFields
& DM_COLOR
)
214 if (devMode
->dmColor
== DMCOLOR_COLOR
)
215 data
.SetColour( true );
217 data
.SetColour( false );
220 data
.SetColour( true );
224 // We don't know size of user defined paper and some buggy drivers
225 // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
226 // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
227 // code wouldn't set m_paperSize correctly.
229 bool foundPaperSize
= false;
230 if ((devMode
->dmFields
& DM_PAPERSIZE
) && (devMode
->dmPaperSize
< DMPAPER_USER
))
232 if (wxThePrintPaperDatabase
)
234 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
237 data
.SetPaperId( paper
->GetId() );
238 data
.SetPaperSize( wxSize(paper
->GetWidth() / 10,paper
->GetHeight() / 10) );
239 m_customWindowsPaperId
= 0;
240 foundPaperSize
= true;
245 // Shouldn't really get here
246 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
247 data
.SetPaperId( wxPAPER_NONE
);
248 data
.SetPaperSize( wxSize(0,0) );
249 m_customWindowsPaperId
= 0;
251 GlobalUnlock(hDevMode
);
256 if (!foundPaperSize
) {
257 if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
259 // DEVMODE is in tenths of a millimeter
260 data
.SetPaperSize( wxSize(devMode
->dmPaperWidth
/ 10, devMode
->dmPaperLength
/ 10) );
261 data
.SetPaperId( wxPAPER_NONE
);
262 m_customWindowsPaperId
= devMode
->dmPaperSize
;
266 // Often will reach this for non-standard paper sizes (sizes which
267 // wouldn't be in wxWidget's paper database). Setting
268 // m_customWindowsPaperId to devMode->dmPaperSize should be enough
269 // to get this paper size working.
270 data
.SetPaperSize( wxSize(0,0) );
271 data
.SetPaperId( wxPAPER_NONE
);
272 m_customWindowsPaperId
= devMode
->dmPaperSize
;
278 if (devMode
->dmFields
& DM_DUPLEX
)
280 switch (devMode
->dmDuplex
)
282 case DMDUP_HORIZONTAL
: data
.SetDuplex( wxDUPLEX_HORIZONTAL
); break;
283 case DMDUP_VERTICAL
: data
.SetDuplex( wxDUPLEX_VERTICAL
); break;
285 case DMDUP_SIMPLEX
: data
.SetDuplex( wxDUPLEX_SIMPLEX
); break;
289 data
.SetDuplex( wxDUPLEX_SIMPLEX
);
293 if (devMode
->dmFields
& DM_PRINTQUALITY
)
295 switch (devMode
->dmPrintQuality
)
297 case DMRES_MEDIUM
: data
.SetQuality( wxPRINT_QUALITY_MEDIUM
); break;
298 case DMRES_LOW
: data
.SetQuality( wxPRINT_QUALITY_LOW
); break;
299 case DMRES_DRAFT
: data
.SetQuality( wxPRINT_QUALITY_DRAFT
); break;
300 case DMRES_HIGH
: data
.SetQuality( wxPRINT_QUALITY_HIGH
); break;
303 // TODO: if the printer fills in the resolution in DPI, how
304 // will the application know if it's high, low, draft etc.??
305 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
306 data
.SetQuality( devMode
->dmPrintQuality
);
313 data
.SetQuality( wxPRINT_QUALITY_HIGH
);
315 if (devMode
->dmDriverExtra
> 0)
316 data
.SetPrivData( (char *)devMode
+devMode
->dmSize
, devMode
->dmDriverExtra
);
318 data
.SetPrivData( NULL
, 0 );
320 GlobalUnlock(hDevMode
);
325 LPDEVNAMES lpDevNames
= (LPDEVNAMES
)GlobalLock(hDevNames
);
328 // TODO: Unicode-ification
331 // port is obsolete in WIN32
332 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
334 // Get the printer name
335 wxString printerName
= (LPTSTR
)lpDevNames
+ lpDevNames
->wDeviceOffset
;
337 // Not sure if we should check for this mismatch
338 // wxASSERT_MSG( (m_printerName.empty() || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
340 if (!printerName
.empty())
341 data
.SetPrinterName( printerName
);
343 GlobalUnlock(hDevNames
);
350 bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData
&data
)
352 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
353 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
356 // Use PRINTDLG as a way of creating a DEVMODE object
359 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
364 memset(&pd
, 0, sizeof(PRINTDLG
));
366 pd
.cbStruct
= sizeof(PRINTDLG
);
368 pd
.lStructSize
= sizeof(PRINTDLG
);
372 pd
.hwndOwner
= (HWND
)NULL
;
373 pd
.hDevMode
= NULL
; // Will be created by PrintDlg
374 pd
.hDevNames
= NULL
; // Ditto
375 //pd.hInstance = (HINSTANCE) wxGetInstance();
377 pd
.Flags
= PD_RETURNDEFAULT
;
380 // Fill out the DEVMODE structure
381 // so we can use it as input in the 'real' PrintDlg
385 GlobalFree(pd
.hDevMode
);
387 GlobalFree(pd
.hDevNames
);
391 #if defined(__WXDEBUG__) && defined(__WIN32__)
392 wxString
str(wxT("Printing error: "));
393 str
+= wxGetPrintDlgError();
399 hDevMode
= pd
.hDevMode
;
400 m_devMode
= (void*)(long) hDevMode
;
403 // We'll create a new DEVNAMEs structure below.
405 GlobalFree(pd
.hDevNames
);
408 // hDevNames = pd->hDevNames;
409 // m_devNames = (void*)(long) hDevNames;
410 // pd->hDevnames = NULL;
417 LPDEVMODE devMode
= (LPDEVMODE
) GlobalLock(hDevMode
);
420 devMode
->dmOrientation
= (short)data
.GetOrientation();
423 devMode
->dmCollate
= (data
.GetCollate() ? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
424 devMode
->dmFields
|= DM_COLLATE
;
426 //// Number of copies
427 devMode
->dmCopies
= (short)data
.GetNoCopies();
428 devMode
->dmFields
|= DM_COPIES
;
431 wxString name
= data
.GetPrinterName();
434 //int len = wxMin(31, m_printerName.Len());
435 wxStrncpy((wxChar
*)devMode
->dmDeviceName
,name
.c_str(),31);
436 devMode
->dmDeviceName
[31] = wxT('\0');
440 if (data
.GetColour())
441 devMode
->dmColor
= DMCOLOR_COLOR
;
443 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
444 devMode
->dmFields
|= DM_COLOR
;
447 if (data
.GetPaperId() == wxPAPER_NONE
)
449 // DEVMODE is in tenths of a milimeter
450 devMode
->dmPaperWidth
= (short)(data
.GetPaperSize().x
* 10);
451 devMode
->dmPaperLength
= (short)(data
.GetPaperSize().y
* 10);
452 if(m_customWindowsPaperId
!= 0)
453 devMode
->dmPaperSize
= m_customWindowsPaperId
;
455 devMode
->dmPaperSize
= DMPAPER_USER
;
456 devMode
->dmFields
|= DM_PAPERWIDTH
;
457 devMode
->dmFields
|= DM_PAPERLENGTH
;
461 if (wxThePrintPaperDatabase
)
463 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType( data
.GetPaperId() );
466 devMode
->dmPaperSize
= (short)paper
->GetPlatformId();
467 devMode
->dmFields
|= DM_PAPERSIZE
;
471 // Fall back on specifying the paper size explicitly
472 devMode
->dmPaperWidth
= (short)(data
.GetPaperSize().x
* 10);
473 devMode
->dmPaperLength
= (short)(data
.GetPaperSize().y
* 10);
474 devMode
->dmPaperSize
= DMPAPER_USER
;
475 devMode
->dmFields
|= DM_PAPERWIDTH
;
476 devMode
->dmFields
|= DM_PAPERLENGTH
;
483 switch (data
.GetDuplex())
485 case wxDUPLEX_HORIZONTAL
:
486 duplex
= DMDUP_HORIZONTAL
;
488 case wxDUPLEX_VERTICAL
:
489 duplex
= DMDUP_VERTICAL
;
492 // in fact case wxDUPLEX_SIMPLEX:
493 duplex
= DMDUP_SIMPLEX
;
496 devMode
->dmDuplex
= duplex
;
497 devMode
->dmFields
|= DM_DUPLEX
;
502 switch (data
.GetQuality())
504 case wxPRINT_QUALITY_MEDIUM
:
505 quality
= DMRES_MEDIUM
;
507 case wxPRINT_QUALITY_LOW
:
510 case wxPRINT_QUALITY_DRAFT
:
511 quality
= DMRES_DRAFT
;
513 case wxPRINT_QUALITY_HIGH
:
514 quality
= DMRES_HIGH
;
517 quality
= (short)data
.GetQuality();
520 devMode
->dmPrintQuality
= quality
;
521 devMode
->dmFields
|= DM_PRINTQUALITY
;
523 if (data
.GetPrivDataLen() > 0)
525 memcpy( (char *)devMode
+devMode
->dmSize
, data
.GetPrivData(), data
.GetPrivDataLen() );
526 devMode
->dmDriverExtra
= (WXWORD
)data
.GetPrivDataLen();
529 if (data
.GetBin() != wxPRINTBIN_DEFAULT
)
531 switch (data
.GetBin())
533 case wxPRINTBIN_ONLYONE
: devMode
->dmDefaultSource
= DMBIN_ONLYONE
; break;
534 case wxPRINTBIN_LOWER
: devMode
->dmDefaultSource
= DMBIN_LOWER
; break;
535 case wxPRINTBIN_MIDDLE
: devMode
->dmDefaultSource
= DMBIN_MIDDLE
; break;
536 case wxPRINTBIN_MANUAL
: devMode
->dmDefaultSource
= DMBIN_MANUAL
; break;
537 case wxPRINTBIN_ENVELOPE
: devMode
->dmDefaultSource
= DMBIN_ENVELOPE
; break;
538 case wxPRINTBIN_ENVMANUAL
: devMode
->dmDefaultSource
= DMBIN_ENVMANUAL
; break;
539 case wxPRINTBIN_AUTO
: devMode
->dmDefaultSource
= DMBIN_AUTO
; break;
540 case wxPRINTBIN_TRACTOR
: devMode
->dmDefaultSource
= DMBIN_TRACTOR
; break;
541 case wxPRINTBIN_SMALLFMT
: devMode
->dmDefaultSource
= DMBIN_SMALLFMT
; break;
542 case wxPRINTBIN_LARGEFMT
: devMode
->dmDefaultSource
= DMBIN_LARGEFMT
; break;
543 case wxPRINTBIN_LARGECAPACITY
: devMode
->dmDefaultSource
= DMBIN_LARGECAPACITY
; break;
544 case wxPRINTBIN_CASSETTE
: devMode
->dmDefaultSource
= DMBIN_CASSETTE
; break;
545 case wxPRINTBIN_FORMSOURCE
: devMode
->dmDefaultSource
= DMBIN_FORMSOURCE
; break;
548 devMode
->dmDefaultSource
= (short)(DMBIN_USER
+ data
.GetBin() - wxPRINTBIN_USER
); // 256 + data.GetBin() - 14 = 242 + data.GetBin()
552 devMode
->dmFields
|= DM_DEFAULTSOURCE
;
555 GlobalUnlock(hDevMode
);
560 GlobalFree(hDevNames
);
563 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
564 m_devNames
= (void*) (long) wxCreateDevNames(wxEmptyString
, data
.GetPrinterName(), wxEmptyString
);
569 // ---------------------------------------------------------------------------
571 // ---------------------------------------------------------------------------
573 IMPLEMENT_CLASS(wxWindowsPrintDialog
, wxPrintDialogBase
)
575 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintDialogData
* data
)
580 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintData
* data
)
582 wxPrintDialogData data2
;
589 bool wxWindowsPrintDialog::Create(wxWindow
*p
, wxPrintDialogData
* data
)
599 m_printDialogData
= *data
;
604 wxWindowsPrintDialog::~wxWindowsPrintDialog()
606 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
607 if (pd
&& pd
->hDevMode
)
608 GlobalFree(pd
->hDevMode
);
612 if (m_destroyDC
&& m_printerDC
)
616 int wxWindowsPrintDialog::ShowModal()
618 ConvertToNative( m_printDialogData
);
620 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
623 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
624 else if (wxTheApp
->GetTopWindow())
625 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
629 bool ret
= (PrintDlg( pd
) != 0);
633 if ( ret
&& (pd
->hDC
) )
635 wxPrinterDC
*pdc
= new wxPrinterDC( (WXHDC
) pd
->hDC
);
637 ConvertFromNative( m_printDialogData
);
646 wxDC
*wxWindowsPrintDialog::GetPrintDC()
657 bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData
&data
)
659 wxWindowsPrintNativeData
*native_data
=
660 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
661 data
.GetPrintData().ConvertToNative();
663 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
665 // Shouldn't have been defined anywhere
670 memset( pd
, 0, sizeof(PRINTDLG
) );
671 m_printDlg
= (void*) pd
;
673 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
675 pd
->lStructSize
= 66;
677 pd
->lStructSize
= sizeof(PRINTDLG
);
679 pd
->hwndOwner
= (HWND
)NULL
;
680 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
681 pd
->hDevNames
= NULL
; // Ditto
683 pd
->Flags
= PD_RETURNDEFAULT
;
686 // Pass the devmode data to the PRINTDLG structure, since it'll
687 // be needed when PrintDlg is called.
689 GlobalFree(pd
->hDevMode
);
691 // Pass the devnames data to the PRINTDLG structure, since it'll
692 // be needed when PrintDlg is called.
694 GlobalFree(pd
->hDevNames
);
696 pd
->hDevMode
= (HGLOBAL
)(DWORD
) native_data
->GetDevMode();
697 native_data
->SetDevMode( (void*) NULL
);
699 // Shouldn't assert; we should be able to test Ok-ness at a higher level
700 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
702 pd
->hDevNames
= (HGLOBAL
)(DWORD
) native_data
->GetDevNames();
703 native_data
->SetDevNames( (void*) NULL
);
706 pd
->hDC
= (HDC
) NULL
;
707 pd
->nFromPage
= (WORD
)data
.GetFromPage();
708 pd
->nToPage
= (WORD
)data
.GetToPage();
709 pd
->nMinPage
= (WORD
)data
.GetMinPage();
710 pd
->nMaxPage
= (WORD
)data
.GetMaxPage();
711 pd
->nCopies
= (WORD
)data
.GetNoCopies();
713 pd
->Flags
= PD_RETURNDC
;
716 pd
->lStructSize
= 66;
718 pd
->lStructSize
= sizeof( PRINTDLG
);
721 pd
->hwndOwner
=(HWND
)NULL
;
722 // pd->hDevNames=(HANDLE)NULL;
723 pd
->hInstance
=(HINSTANCE
)NULL
;
724 pd
->lCustData
= (LPARAM
) NULL
;
725 pd
->lpfnPrintHook
= NULL
;
726 pd
->lpfnSetupHook
= NULL
;
727 pd
->lpPrintTemplateName
= NULL
;
728 pd
->lpSetupTemplateName
= NULL
;
729 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
730 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
732 if ( data
.GetAllPages() )
733 pd
->Flags
|= PD_ALLPAGES
;
734 if ( data
.GetSelection() )
735 pd
->Flags
|= PD_SELECTION
;
736 if ( data
.GetCollate() )
737 pd
->Flags
|= PD_COLLATE
;
738 if ( data
.GetPrintToFile() )
739 pd
->Flags
|= PD_PRINTTOFILE
;
740 if ( !data
.GetEnablePrintToFile() )
741 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
742 if ( !data
.GetEnableSelection() )
743 pd
->Flags
|= PD_NOSELECTION
;
744 if ( !data
.GetEnablePageNumbers() )
745 pd
->Flags
|= PD_NOPAGENUMS
;
746 else if ( (!data
.GetAllPages()) && (!data
.GetSelection()) && (data
.GetFromPage() != 0) && (data
.GetToPage() != 0))
747 pd
->Flags
|= PD_PAGENUMS
;
748 if ( data
.GetEnableHelp() )
749 pd
->Flags
|= PD_SHOWHELP
;
750 #if WXWIN_COMPATIBILITY_2_4
751 if ( data
.GetSetupDialog() )
752 pd
->Flags
|= PD_PRINTSETUP
;
758 bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData
&data
)
760 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
764 wxWindowsPrintNativeData
*native_data
=
765 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
767 // Pass the devmode data back to the wxPrintData structure where it really belongs.
770 if (native_data
->GetDevMode())
772 // Make sure we don't leak memory
773 GlobalFree( (HGLOBAL
)(DWORD
) native_data
->GetDevMode() );
775 native_data
->SetDevMode( (void*)(long) pd
->hDevMode
);
779 // Pass the devnames data back to the wxPrintData structure where it really belongs.
782 if (native_data
->GetDevNames())
784 // Make sure we don't leak memory
785 GlobalFree((HGLOBAL
)(DWORD
) native_data
->GetDevNames());
787 native_data
->SetDevNames((void*)(long) pd
->hDevNames
);
788 pd
->hDevNames
= NULL
;
791 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
792 // into wxWidgets form.
793 native_data
->TransferTo( data
.GetPrintData() );
795 data
.SetFromPage( pd
->nFromPage
);
796 data
.SetToPage( pd
->nToPage
);
797 data
.SetMinPage( pd
->nMinPage
);
798 data
.SetMaxPage( pd
->nMaxPage
);
799 data
.SetNoCopies( pd
->nCopies
);
801 data
.SetAllPages( (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
)) );
802 data
.SetSelection( ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
) );
803 data
.SetCollate( ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
) );
804 data
.SetPrintToFile( ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
) );
805 data
.EnablePrintToFile( ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
) );
806 data
.EnableSelection( ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
) );
807 data
.EnablePageNumbers( ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
) );
808 data
.EnableHelp( ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
) );
809 #if WXWIN_COMPATIBILITY_2_4
810 data
.SetSetupDialog( ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
) );
815 // ---------------------------------------------------------------------------
816 // wxWidnowsPageSetupDialog
817 // ---------------------------------------------------------------------------
819 IMPLEMENT_CLASS(wxWindowsPageSetupDialog
, wxPageSetupDialogBase
)
821 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog()
823 m_dialogParent
= NULL
;
827 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog(wxWindow
*p
, wxPageSetupDialogData
*data
)
832 bool wxWindowsPageSetupDialog::Create(wxWindow
*p
, wxPageSetupDialogData
*data
)
838 m_pageSetupData
= (*data
);
843 wxWindowsPageSetupDialog::~wxWindowsPageSetupDialog()
845 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageDlg
;
846 if ( pd
&& pd
->hDevMode
)
847 GlobalFree(pd
->hDevMode
);
848 if ( pd
&& pd
->hDevNames
)
849 GlobalFree(pd
->hDevNames
);
854 int wxWindowsPageSetupDialog::ShowModal()
856 ConvertToNative( m_pageSetupData
);
858 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
860 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
861 else if (wxTheApp
->GetTopWindow())
862 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
865 BOOL retVal
= PageSetupDlg( pd
) ;
869 ConvertFromNative( m_pageSetupData
);
876 bool wxWindowsPageSetupDialog::ConvertToNative( wxPageSetupDialogData
&data
)
878 wxWindowsPrintNativeData
*native_data
=
879 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
880 data
.GetPrintData().ConvertToNative();
882 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
884 // Shouldn't have been defined anywhere
888 pd
= new PAGESETUPDLG
;
890 pd
->hDevNames
= NULL
;
891 m_pageDlg
= (void *)pd
;
893 // Pass the devmode data (created in m_printData.ConvertToNative)
894 // to the PRINTDLG structure, since it'll
895 // be needed when PrintDlg is called.
899 GlobalFree(pd
->hDevMode
);
902 pd
->hDevMode
= (HGLOBAL
) native_data
->GetDevMode();
903 native_data
->SetDevMode( (void*) NULL
);
905 // Shouldn't assert; we should be able to test Ok-ness at a higher level
906 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
908 // Pass the devnames data (created in m_printData.ConvertToNative)
909 // to the PRINTDLG structure, since it'll
910 // be needed when PrintDlg is called.
914 GlobalFree(pd
->hDevNames
);
915 pd
->hDevNames
= NULL
;
917 pd
->hDevNames
= (HGLOBAL
) native_data
->GetDevNames();
918 native_data
->SetDevNames((void*) NULL
);
920 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
922 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
924 if ( data
.GetDefaultMinMargins() )
925 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
926 if ( !data
.GetEnableMargins() )
927 pd
->Flags
|= PSD_DISABLEMARGINS
;
928 if ( !data
.GetEnableOrientation() )
929 pd
->Flags
|= PSD_DISABLEORIENTATION
;
930 if ( !data
.GetEnablePaper() )
931 pd
->Flags
|= PSD_DISABLEPAPER
;
932 if ( !data
.GetEnablePrinter() )
933 pd
->Flags
|= PSD_DISABLEPRINTER
;
934 if ( data
.GetDefaultInfo() )
935 pd
->Flags
|= PSD_RETURNDEFAULT
;
936 if ( data
.GetEnableHelp() )
937 pd
->Flags
|= PSD_SHOWHELP
;
939 // We want the units to be in hundredths of a millimetre
940 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
942 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
943 pd
->hwndOwner
=(HWND
)NULL
;
944 // pd->hDevNames=(HWND)NULL;
945 pd
->hInstance
=(HINSTANCE
)NULL
;
946 // PAGESETUPDLG is in hundreds of a mm
947 pd
->ptPaperSize
.x
= data
.GetPaperSize().x
* 100;
948 pd
->ptPaperSize
.y
= data
.GetPaperSize().y
* 100;
950 pd
->rtMinMargin
.left
= data
.GetMinMarginTopLeft().x
* 100;
951 pd
->rtMinMargin
.top
= data
.GetMinMarginTopLeft().y
* 100;
952 pd
->rtMinMargin
.right
= data
.GetMinMarginBottomRight().x
* 100;
953 pd
->rtMinMargin
.bottom
= data
.GetMinMarginBottomRight().y
* 100;
955 pd
->rtMargin
.left
= data
.GetMarginTopLeft().x
* 100;
956 pd
->rtMargin
.top
= data
.GetMarginTopLeft().y
* 100;
957 pd
->rtMargin
.right
= data
.GetMarginBottomRight().x
* 100;
958 pd
->rtMargin
.bottom
= data
.GetMarginBottomRight().y
* 100;
961 pd
->lpfnPageSetupHook
= NULL
;
962 pd
->lpfnPagePaintHook
= NULL
;
963 pd
->hPageSetupTemplate
= NULL
;
964 pd
->lpPageSetupTemplateName
= NULL
;
969 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
970 memset(devMode, 0, sizeof(DEVMODE));
971 devMode->dmSize = sizeof(DEVMODE);
972 devMode->dmOrientation = m_orientation;
973 devMode->dmFields = DM_ORIENTATION;
974 GlobalUnlock(pd->hDevMode);
980 bool wxWindowsPageSetupDialog::ConvertFromNative( wxPageSetupDialogData
&data
)
982 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
986 wxWindowsPrintNativeData
*native_data
=
987 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
989 // Pass the devmode data back to the wxPrintData structure where it really belongs.
992 if (native_data
->GetDevMode())
994 // Make sure we don't leak memory
995 GlobalFree((HGLOBAL
) native_data
->GetDevMode());
997 native_data
->SetDevMode( (void*) pd
->hDevMode
);
1001 // Isn't this superfluous? It's called again below.
1002 // data.GetPrintData().ConvertFromNative();
1004 // Pass the devnames data back to the wxPrintData structure where it really belongs.
1007 if (native_data
->GetDevNames())
1009 // Make sure we don't leak memory
1010 GlobalFree((HGLOBAL
) native_data
->GetDevNames());
1012 native_data
->SetDevNames((void*) pd
->hDevNames
);
1013 pd
->hDevNames
= NULL
;
1016 data
.GetPrintData().ConvertFromNative();
1018 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
1020 data
.SetDefaultMinMargins( ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
) );
1021 data
.EnableMargins( ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
) );
1022 data
.EnableOrientation( ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
) );
1023 data
.EnablePaper( ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
) );
1024 data
.EnablePrinter( ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
) );
1025 data
.SetDefaultInfo( ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
) );
1026 data
.EnableHelp( ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
) );
1028 // PAGESETUPDLG is in hundreds of a mm
1029 data
.SetPaperSize( wxSize(pd
->ptPaperSize
.x
/ 100, pd
->ptPaperSize
.y
/ 100) );
1031 data
.SetMinMarginTopLeft( wxPoint(pd
->rtMinMargin
.left
/ 100, pd
->rtMinMargin
.top
/ 100) );
1032 data
.SetMinMarginBottomRight( wxPoint(pd
->rtMinMargin
.right
/ 100, pd
->rtMinMargin
.bottom
/ 100) );
1034 data
.SetMarginTopLeft( wxPoint(pd
->rtMargin
.left
/ 100, pd
->rtMargin
.top
/ 100) );
1035 data
.SetMarginBottomRight( wxPoint(pd
->rtMargin
.right
/ 100, pd
->rtMargin
.bottom
/ 100) );
1041 // wxUSE_PRINTING_ARCHITECTURE