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
);
179 if (devMode
->dmFields
& DM_DEFAULTSOURCE
)
180 data
.SetBin( (wxPrintBin
)devMode
->dmDefaultSource
);
183 if (devMode
->dmDeviceName
[0] != 0)
184 data
.SetPrinterName( devMode
->dmDeviceName
);
187 if (devMode
->dmFields
& DM_COLOR
)
189 if (devMode
->dmColor
== DMCOLOR_COLOR
)
190 data
.SetColour( true );
192 data
.SetColour( false );
195 data
.SetColour( true );
199 // We don't know size of user defined paper and some buggy drivers
200 // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
201 // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
202 // code wouldn't set m_paperSize correctly.
204 bool foundPaperSize
= false;
205 if ((devMode
->dmFields
& DM_PAPERSIZE
) && (devMode
->dmPaperSize
< DMPAPER_USER
))
207 if (wxThePrintPaperDatabase
)
209 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
212 data
.SetPaperId( paper
->GetId() );
213 data
.SetPaperSize( wxSize(paper
->GetWidth() / 10,paper
->GetHeight() / 10) );
214 m_customWindowsPaperId
= 0;
215 foundPaperSize
= true;
220 // Shouldn't really get here
221 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
222 data
.SetPaperId( wxPAPER_NONE
);
223 data
.SetPaperSize( wxSize(0,0) );
224 m_customWindowsPaperId
= 0;
226 GlobalUnlock(hDevMode
);
231 if (!foundPaperSize
&& (devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
233 // DEVMODE is in tenths of a milimeter
234 data
.SetPaperSize( wxSize(devMode
->dmPaperWidth
/ 10, devMode
->dmPaperLength
/ 10) );
235 data
.SetPaperId( wxPAPER_NONE
);
236 m_customWindowsPaperId
= devMode
->dmPaperSize
;
240 // Often will reach this for non-standard paper sizes (sizes which
241 // wouldn't be in wxWidget's paper database). Setting
242 // m_customWindowsPaperId to devMode->dmPaperSize should be enough
243 // to get this paper size working.
244 data
.SetPaperSize( wxSize(0,0) );
245 data
.SetPaperId( wxPAPER_NONE
);
246 m_customWindowsPaperId
= devMode
->dmPaperSize
;
251 if (devMode
->dmFields
& DM_DUPLEX
)
253 switch (devMode
->dmDuplex
)
255 case DMDUP_HORIZONTAL
: data
.SetDuplex( wxDUPLEX_HORIZONTAL
); break;
256 case DMDUP_VERTICAL
: data
.SetDuplex( wxDUPLEX_VERTICAL
); break;
258 case DMDUP_SIMPLEX
: data
.SetDuplex( wxDUPLEX_SIMPLEX
); break;
262 data
.SetDuplex( wxDUPLEX_SIMPLEX
);
266 if (devMode
->dmFields
& DM_PRINTQUALITY
)
268 switch (devMode
->dmPrintQuality
)
270 case DMRES_MEDIUM
: data
.SetQuality( wxPRINT_QUALITY_MEDIUM
); break;
271 case DMRES_LOW
: data
.SetQuality( wxPRINT_QUALITY_LOW
); break;
272 case DMRES_DRAFT
: data
.SetQuality( wxPRINT_QUALITY_DRAFT
); break;
273 case DMRES_HIGH
: data
.SetQuality( wxPRINT_QUALITY_HIGH
); break;
276 // TODO: if the printer fills in the resolution in DPI, how
277 // will the application know if it's high, low, draft etc.??
278 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
279 data
.SetQuality( devMode
->dmPrintQuality
);
286 data
.SetQuality( wxPRINT_QUALITY_HIGH
);
288 if (devMode
->dmDriverExtra
> 0)
289 data
.SetPrivData( (char *)devMode
+devMode
->dmSize
, devMode
->dmDriverExtra
);
291 data
.SetPrivData( NULL
, 0 );
293 GlobalUnlock(hDevMode
);
298 LPDEVNAMES lpDevNames
= (LPDEVNAMES
)GlobalLock(hDevNames
);
301 // TODO: Unicode-ification
304 // port is obsolete in WIN32
305 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
307 // Get the printer name
308 wxString printerName
= (LPTSTR
)lpDevNames
+ lpDevNames
->wDeviceOffset
;
310 // Not sure if we should check for this mismatch
311 // wxASSERT_MSG( (m_printerName.empty() || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
313 if (!printerName
.empty())
314 data
.SetPrinterName( printerName
);
316 GlobalUnlock(hDevNames
);
323 bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData
&data
)
325 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
326 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
329 // Use PRINTDLG as a way of creating a DEVMODE object
332 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
337 memset(&pd
, 0, sizeof(PRINTDLG
));
339 pd
.cbStruct
= sizeof(PRINTDLG
);
341 pd
.lStructSize
= sizeof(PRINTDLG
);
345 pd
.hwndOwner
= (HWND
)NULL
;
346 pd
.hDevMode
= NULL
; // Will be created by PrintDlg
347 pd
.hDevNames
= NULL
; // Ditto
348 //pd.hInstance = (HINSTANCE) wxGetInstance();
350 pd
.Flags
= PD_RETURNDEFAULT
;
353 // Fill out the DEVMODE structure
354 // so we can use it as input in the 'real' PrintDlg
358 GlobalFree(pd
.hDevMode
);
360 GlobalFree(pd
.hDevNames
);
364 #if defined(__WXDEBUG__) && defined(__WIN32__)
365 wxString
str(wxT("Printing error: "));
366 str
+= wxGetPrintDlgError();
372 hDevMode
= pd
.hDevMode
;
373 m_devMode
= (void*)(long) hDevMode
;
376 // We'll create a new DEVNAMEs structure below.
378 GlobalFree(pd
.hDevNames
);
381 // hDevNames = pd->hDevNames;
382 // m_devNames = (void*)(long) hDevNames;
383 // pd->hDevnames = NULL;
390 LPDEVMODE devMode
= (LPDEVMODE
) GlobalLock(hDevMode
);
393 devMode
->dmOrientation
= (short)data
.GetOrientation();
396 devMode
->dmCollate
= (data
.GetCollate() ? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
397 devMode
->dmFields
|= DM_COLLATE
;
399 //// Number of copies
400 devMode
->dmCopies
= (short)data
.GetNoCopies();
401 devMode
->dmFields
|= DM_COPIES
;
404 wxString name
= data
.GetPrinterName();
407 //int len = wxMin(31, m_printerName.Len());
408 wxStrncpy((wxChar
*)devMode
->dmDeviceName
,name
.c_str(),31);
409 devMode
->dmDeviceName
[31] = wxT('\0');
413 if (data
.GetColour())
414 devMode
->dmColor
= DMCOLOR_COLOR
;
416 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
417 devMode
->dmFields
|= DM_COLOR
;
420 if (data
.GetPaperId() == wxPAPER_NONE
)
422 // DEVMODE is in tenths of a milimeter
423 devMode
->dmPaperWidth
= (short)(data
.GetPaperSize().x
* 10);
424 devMode
->dmPaperLength
= (short)(data
.GetPaperSize().y
* 10);
425 if(m_customWindowsPaperId
!= 0)
426 devMode
->dmPaperSize
= m_customWindowsPaperId
;
428 devMode
->dmPaperSize
= DMPAPER_USER
;
429 devMode
->dmFields
|= DM_PAPERWIDTH
;
430 devMode
->dmFields
|= DM_PAPERLENGTH
;
434 if (wxThePrintPaperDatabase
)
436 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType( data
.GetPaperId() );
439 devMode
->dmPaperSize
= (short)paper
->GetPlatformId();
440 devMode
->dmFields
|= DM_PAPERSIZE
;
444 // Fall back on specifying the paper size explicitly
445 devMode
->dmPaperWidth
= (short)(data
.GetPaperSize().x
* 10);
446 devMode
->dmPaperLength
= (short)(data
.GetPaperSize().y
* 10);
447 devMode
->dmPaperSize
= DMPAPER_USER
;
448 devMode
->dmFields
|= DM_PAPERWIDTH
;
449 devMode
->dmFields
|= DM_PAPERLENGTH
;
456 switch (data
.GetDuplex())
458 case wxDUPLEX_HORIZONTAL
:
459 duplex
= DMDUP_HORIZONTAL
;
461 case wxDUPLEX_VERTICAL
:
462 duplex
= DMDUP_VERTICAL
;
465 // in fact case wxDUPLEX_SIMPLEX:
466 duplex
= DMDUP_SIMPLEX
;
469 devMode
->dmDuplex
= duplex
;
470 devMode
->dmFields
|= DM_DUPLEX
;
475 switch (data
.GetQuality())
477 case wxPRINT_QUALITY_MEDIUM
:
478 quality
= DMRES_MEDIUM
;
480 case wxPRINT_QUALITY_LOW
:
483 case wxPRINT_QUALITY_DRAFT
:
484 quality
= DMRES_DRAFT
;
486 case wxPRINT_QUALITY_HIGH
:
487 quality
= DMRES_HIGH
;
490 quality
= (short)data
.GetQuality();
493 devMode
->dmPrintQuality
= quality
;
494 devMode
->dmFields
|= DM_PRINTQUALITY
;
496 if (data
.GetPrivDataLen() > 0)
498 memcpy( (char *)devMode
+devMode
->dmSize
, data
.GetPrivData(), data
.GetPrivDataLen() );
499 devMode
->dmDriverExtra
= (WXWORD
)data
.GetPrivDataLen();
502 if (data
.GetBin() != wxPRINTBIN_DEFAULT
)
504 switch (data
.GetBin())
506 case wxPRINTBIN_ONLYONE
: devMode
->dmDefaultSource
= DMBIN_ONLYONE
; break;
507 case wxPRINTBIN_LOWER
: devMode
->dmDefaultSource
= DMBIN_LOWER
; break;
508 case wxPRINTBIN_MIDDLE
: devMode
->dmDefaultSource
= DMBIN_MIDDLE
; break;
509 case wxPRINTBIN_MANUAL
: devMode
->dmDefaultSource
= DMBIN_MANUAL
; break;
510 case wxPRINTBIN_ENVELOPE
: devMode
->dmDefaultSource
= DMBIN_ENVELOPE
; break;
511 case wxPRINTBIN_ENVMANUAL
: devMode
->dmDefaultSource
= DMBIN_ENVMANUAL
; break;
512 case wxPRINTBIN_AUTO
: devMode
->dmDefaultSource
= DMBIN_AUTO
; break;
513 case wxPRINTBIN_TRACTOR
: devMode
->dmDefaultSource
= DMBIN_TRACTOR
; break;
514 case wxPRINTBIN_SMALLFMT
: devMode
->dmDefaultSource
= DMBIN_SMALLFMT
; break;
515 case wxPRINTBIN_LARGEFMT
: devMode
->dmDefaultSource
= DMBIN_LARGEFMT
; break;
516 case wxPRINTBIN_LARGECAPACITY
: devMode
->dmDefaultSource
= DMBIN_LARGECAPACITY
; break;
517 case wxPRINTBIN_CASSETTE
: devMode
->dmDefaultSource
= DMBIN_CASSETTE
; break;
518 case wxPRINTBIN_FORMSOURCE
: devMode
->dmDefaultSource
= DMBIN_FORMSOURCE
; break;
521 devMode
->dmDefaultSource
= (short)(DMBIN_USER
+ data
.GetBin() - wxPRINTBIN_USER
);
525 devMode
->dmFields
|= DM_DEFAULTSOURCE
;
528 GlobalUnlock(hDevMode
);
533 GlobalFree(hDevNames
);
536 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
537 m_devNames
= (void*) (long) wxCreateDevNames(wxEmptyString
, data
.GetPrinterName(), wxEmptyString
);
542 // ---------------------------------------------------------------------------
544 // ---------------------------------------------------------------------------
546 IMPLEMENT_CLASS(wxWindowsPrintDialog
, wxPrintDialogBase
)
548 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintDialogData
* data
)
553 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintData
* data
)
555 wxPrintDialogData data2
;
562 bool wxWindowsPrintDialog::Create(wxWindow
*p
, wxPrintDialogData
* data
)
572 m_printDialogData
= *data
;
577 wxWindowsPrintDialog::~wxWindowsPrintDialog()
579 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
580 if (pd
&& pd
->hDevMode
)
581 GlobalFree(pd
->hDevMode
);
585 if (m_destroyDC
&& m_printerDC
)
589 int wxWindowsPrintDialog::ShowModal()
591 ConvertToNative( m_printDialogData
);
593 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
596 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
597 else if (wxTheApp
->GetTopWindow())
598 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
602 bool ret
= (PrintDlg( pd
) != 0);
606 if ( ret
&& (pd
->hDC
) )
608 wxPrinterDC
*pdc
= new wxPrinterDC( (WXHDC
) pd
->hDC
);
610 ConvertFromNative( m_printDialogData
);
619 wxDC
*wxWindowsPrintDialog::GetPrintDC()
630 bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData
&data
)
632 wxWindowsPrintNativeData
*native_data
=
633 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
634 data
.GetPrintData().ConvertToNative();
636 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
638 // Shouldn't have been defined anywhere
643 memset( pd
, 0, sizeof(PRINTDLG
) );
644 m_printDlg
= (void*) pd
;
646 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
648 pd
->lStructSize
= 66;
650 pd
->lStructSize
= sizeof(PRINTDLG
);
652 pd
->hwndOwner
= (HWND
)NULL
;
653 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
654 pd
->hDevNames
= NULL
; // Ditto
656 pd
->Flags
= PD_RETURNDEFAULT
;
659 // Pass the devmode data to the PRINTDLG structure, since it'll
660 // be needed when PrintDlg is called.
662 GlobalFree(pd
->hDevMode
);
664 // Pass the devnames data to the PRINTDLG structure, since it'll
665 // be needed when PrintDlg is called.
667 GlobalFree(pd
->hDevNames
);
669 pd
->hDevMode
= (HGLOBAL
)(DWORD
) native_data
->GetDevMode();
670 native_data
->SetDevMode( (void*) NULL
);
672 // Shouldn't assert; we should be able to test Ok-ness at a higher level
673 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
675 pd
->hDevNames
= (HGLOBAL
)(DWORD
) native_data
->GetDevNames();
676 native_data
->SetDevNames( (void*) NULL
);
679 pd
->hDC
= (HDC
) NULL
;
680 pd
->nFromPage
= (WORD
)data
.GetFromPage();
681 pd
->nToPage
= (WORD
)data
.GetToPage();
682 pd
->nMinPage
= (WORD
)data
.GetMinPage();
683 pd
->nMaxPage
= (WORD
)data
.GetMaxPage();
684 pd
->nCopies
= (WORD
)data
.GetNoCopies();
686 pd
->Flags
= PD_RETURNDC
;
689 pd
->lStructSize
= 66;
691 pd
->lStructSize
= sizeof( PRINTDLG
);
694 pd
->hwndOwner
=(HWND
)NULL
;
695 // pd->hDevNames=(HANDLE)NULL;
696 pd
->hInstance
=(HINSTANCE
)NULL
;
697 pd
->lCustData
= (LPARAM
) NULL
;
698 pd
->lpfnPrintHook
= NULL
;
699 pd
->lpfnSetupHook
= NULL
;
700 pd
->lpPrintTemplateName
= NULL
;
701 pd
->lpSetupTemplateName
= NULL
;
702 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
703 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
705 if ( data
.GetAllPages() )
706 pd
->Flags
|= PD_ALLPAGES
;
707 if ( data
.GetSelection() )
708 pd
->Flags
|= PD_SELECTION
;
709 if ( data
.GetCollate() )
710 pd
->Flags
|= PD_COLLATE
;
711 if ( data
.GetPrintToFile() )
712 pd
->Flags
|= PD_PRINTTOFILE
;
713 if ( !data
.GetEnablePrintToFile() )
714 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
715 if ( !data
.GetEnableSelection() )
716 pd
->Flags
|= PD_NOSELECTION
;
717 if ( !data
.GetEnablePageNumbers() )
718 pd
->Flags
|= PD_NOPAGENUMS
;
719 else if ( (!data
.GetAllPages()) && (!data
.GetSelection()) && (data
.GetFromPage() != 0) && (data
.GetToPage() != 0))
720 pd
->Flags
|= PD_PAGENUMS
;
721 if ( data
.GetEnableHelp() )
722 pd
->Flags
|= PD_SHOWHELP
;
723 #if WXWIN_COMPATIBILITY_2_4
724 if ( data
.GetSetupDialog() )
725 pd
->Flags
|= PD_PRINTSETUP
;
731 bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData
&data
)
733 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
737 wxWindowsPrintNativeData
*native_data
=
738 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
740 // Pass the devmode data back to the wxPrintData structure where it really belongs.
743 if (native_data
->GetDevMode())
745 // Make sure we don't leak memory
746 GlobalFree( (HGLOBAL
)(DWORD
) native_data
->GetDevMode() );
748 native_data
->SetDevMode( (void*)(long) pd
->hDevMode
);
752 // Pass the devnames data back to the wxPrintData structure where it really belongs.
755 if (native_data
->GetDevNames())
757 // Make sure we don't leak memory
758 GlobalFree((HGLOBAL
)(DWORD
) native_data
->GetDevNames());
760 native_data
->SetDevNames((void*)(long) pd
->hDevNames
);
761 pd
->hDevNames
= NULL
;
764 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
765 // into wxWidgets form.
766 native_data
->TransferTo( data
.GetPrintData() );
768 data
.SetFromPage( pd
->nFromPage
);
769 data
.SetToPage( pd
->nToPage
);
770 data
.SetMinPage( pd
->nMinPage
);
771 data
.SetMaxPage( pd
->nMaxPage
);
772 data
.SetNoCopies( pd
->nCopies
);
774 data
.SetAllPages( (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
)) );
775 data
.SetSelection( ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
) );
776 data
.SetCollate( ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
) );
777 data
.SetPrintToFile( ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
) );
778 data
.EnablePrintToFile( ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
) );
779 data
.EnableSelection( ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
) );
780 data
.EnablePageNumbers( ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
) );
781 data
.EnableHelp( ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
) );
782 #if WXWIN_COMPATIBILITY_2_4
783 data
.SetSetupDialog( ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
) );
788 // ---------------------------------------------------------------------------
789 // wxWidnowsPageSetupDialog
790 // ---------------------------------------------------------------------------
792 IMPLEMENT_CLASS(wxWindowsPageSetupDialog
, wxPageSetupDialogBase
)
794 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog()
796 m_dialogParent
= NULL
;
800 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog(wxWindow
*p
, wxPageSetupDialogData
*data
)
805 bool wxWindowsPageSetupDialog::Create(wxWindow
*p
, wxPageSetupDialogData
*data
)
811 m_pageSetupData
= (*data
);
816 wxWindowsPageSetupDialog::~wxWindowsPageSetupDialog()
818 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageDlg
;
819 if ( pd
&& pd
->hDevMode
)
820 GlobalFree(pd
->hDevMode
);
821 if ( pd
&& pd
->hDevNames
)
822 GlobalFree(pd
->hDevNames
);
827 int wxWindowsPageSetupDialog::ShowModal()
829 ConvertToNative( m_pageSetupData
);
831 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
833 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
834 else if (wxTheApp
->GetTopWindow())
835 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
838 BOOL retVal
= PageSetupDlg( pd
) ;
842 ConvertFromNative( m_pageSetupData
);
849 bool wxWindowsPageSetupDialog::ConvertToNative( wxPageSetupDialogData
&data
)
851 wxWindowsPrintNativeData
*native_data
=
852 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
853 data
.GetPrintData().ConvertToNative();
855 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
857 // Shouldn't have been defined anywhere
861 pd
= new PAGESETUPDLG
;
863 pd
->hDevNames
= NULL
;
864 m_pageDlg
= (void *)pd
;
866 // Pass the devmode data (created in m_printData.ConvertToNative)
867 // to the PRINTDLG structure, since it'll
868 // be needed when PrintDlg is called.
872 GlobalFree(pd
->hDevMode
);
875 pd
->hDevMode
= (HGLOBAL
) native_data
->GetDevMode();
876 native_data
->SetDevMode( (void*) NULL
);
878 // Shouldn't assert; we should be able to test Ok-ness at a higher level
879 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
881 // Pass the devnames data (created in m_printData.ConvertToNative)
882 // to the PRINTDLG structure, since it'll
883 // be needed when PrintDlg is called.
887 GlobalFree(pd
->hDevNames
);
888 pd
->hDevNames
= NULL
;
890 pd
->hDevNames
= (HGLOBAL
) native_data
->GetDevNames();
891 native_data
->SetDevNames((void*) NULL
);
893 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
895 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
897 if ( data
.GetDefaultMinMargins() )
898 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
899 if ( !data
.GetEnableMargins() )
900 pd
->Flags
|= PSD_DISABLEMARGINS
;
901 if ( !data
.GetEnableOrientation() )
902 pd
->Flags
|= PSD_DISABLEORIENTATION
;
903 if ( !data
.GetEnablePaper() )
904 pd
->Flags
|= PSD_DISABLEPAPER
;
905 if ( !data
.GetEnablePrinter() )
906 pd
->Flags
|= PSD_DISABLEPRINTER
;
907 if ( data
.GetDefaultInfo() )
908 pd
->Flags
|= PSD_RETURNDEFAULT
;
909 if ( data
.GetEnableHelp() )
910 pd
->Flags
|= PSD_SHOWHELP
;
912 // We want the units to be in hundredths of a millimetre
913 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
915 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
916 pd
->hwndOwner
=(HWND
)NULL
;
917 // pd->hDevNames=(HWND)NULL;
918 pd
->hInstance
=(HINSTANCE
)NULL
;
919 // PAGESETUPDLG is in hundreds of a mm
920 pd
->ptPaperSize
.x
= data
.GetPaperSize().x
* 100;
921 pd
->ptPaperSize
.y
= data
.GetPaperSize().y
* 100;
923 pd
->rtMinMargin
.left
= data
.GetMinMarginTopLeft().x
* 100;
924 pd
->rtMinMargin
.top
= data
.GetMinMarginTopLeft().y
* 100;
925 pd
->rtMinMargin
.right
= data
.GetMinMarginBottomRight().x
* 100;
926 pd
->rtMinMargin
.bottom
= data
.GetMinMarginBottomRight().y
* 100;
928 pd
->rtMargin
.left
= data
.GetMarginTopLeft().x
* 100;
929 pd
->rtMargin
.top
= data
.GetMarginTopLeft().y
* 100;
930 pd
->rtMargin
.right
= data
.GetMarginBottomRight().x
* 100;
931 pd
->rtMargin
.bottom
= data
.GetMarginBottomRight().y
* 100;
934 pd
->lpfnPageSetupHook
= NULL
;
935 pd
->lpfnPagePaintHook
= NULL
;
936 pd
->hPageSetupTemplate
= NULL
;
937 pd
->lpPageSetupTemplateName
= NULL
;
942 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
943 memset(devMode, 0, sizeof(DEVMODE));
944 devMode->dmSize = sizeof(DEVMODE);
945 devMode->dmOrientation = m_orientation;
946 devMode->dmFields = DM_ORIENTATION;
947 GlobalUnlock(pd->hDevMode);
953 bool wxWindowsPageSetupDialog::ConvertFromNative( wxPageSetupDialogData
&data
)
955 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
959 wxWindowsPrintNativeData
*native_data
=
960 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
962 // Pass the devmode data back to the wxPrintData structure where it really belongs.
965 if (native_data
->GetDevMode())
967 // Make sure we don't leak memory
968 GlobalFree((HGLOBAL
) native_data
->GetDevMode());
970 native_data
->SetDevMode( (void*) pd
->hDevMode
);
974 // Isn't this superfluous? It's called again below.
975 // data.GetPrintData().ConvertFromNative();
977 // Pass the devnames data back to the wxPrintData structure where it really belongs.
980 if (native_data
->GetDevNames())
982 // Make sure we don't leak memory
983 GlobalFree((HGLOBAL
) native_data
->GetDevNames());
985 native_data
->SetDevNames((void*) pd
->hDevNames
);
986 pd
->hDevNames
= NULL
;
989 data
.GetPrintData().ConvertFromNative();
991 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
993 data
.SetDefaultMinMargins( ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
) );
994 data
.EnableMargins( ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
) );
995 data
.EnableOrientation( ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
) );
996 data
.EnablePaper( ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
) );
997 data
.EnablePrinter( ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
) );
998 data
.SetDefaultInfo( ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
) );
999 data
.EnableHelp( ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
) );
1001 // PAGESETUPDLG is in hundreds of a mm
1002 data
.SetPaperSize( wxSize(pd
->ptPaperSize
.x
/ 100, pd
->ptPaperSize
.y
/ 100) );
1004 data
.SetMinMarginTopLeft( wxPoint(pd
->rtMinMargin
.left
/ 100, pd
->rtMinMargin
.top
/ 100) );
1005 data
.SetMinMarginBottomRight( wxPoint(pd
->rtMinMargin
.right
/ 100, pd
->rtMinMargin
.bottom
/ 100) );
1007 data
.SetMarginTopLeft( wxPoint(pd
->rtMargin
.left
/ 100, pd
->rtMargin
.top
/ 100) );
1008 data
.SetMarginBottomRight( wxPoint(pd
->rtMargin
.right
/ 100, pd
->rtMargin
.bottom
/ 100) );
1014 // wxUSE_PRINTING_ARCHITECTURE