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/private.h"
55 //----------------------------------------------------------------------------
56 // wxWindowsPrintNativeData
57 //----------------------------------------------------------------------------
60 static wxString
wxGetPrintDlgError()
62 DWORD err
= CommDlgExtendedError();
63 wxString msg
= wxT("Unknown");
66 case CDERR_FINDRESFAILURE
: msg
= wxT("CDERR_FINDRESFAILURE"); break;
67 case CDERR_INITIALIZATION
: msg
= wxT("CDERR_INITIALIZATION"); break;
68 case CDERR_LOADRESFAILURE
: msg
= wxT("CDERR_LOADRESFAILURE"); break;
69 case CDERR_LOADSTRFAILURE
: msg
= wxT("CDERR_LOADSTRFAILURE"); break;
70 case CDERR_LOCKRESFAILURE
: msg
= wxT("CDERR_LOCKRESFAILURE"); break;
71 case CDERR_MEMALLOCFAILURE
: msg
= wxT("CDERR_MEMALLOCFAILURE"); break;
72 case CDERR_MEMLOCKFAILURE
: msg
= wxT("CDERR_MEMLOCKFAILURE"); break;
73 case CDERR_NOHINSTANCE
: msg
= wxT("CDERR_NOHINSTANCE"); break;
74 case CDERR_NOHOOK
: msg
= wxT("CDERR_NOHOOK"); break;
75 case CDERR_NOTEMPLATE
: msg
= wxT("CDERR_NOTEMPLATE"); break;
76 case CDERR_STRUCTSIZE
: msg
= wxT("CDERR_STRUCTSIZE"); break;
77 case PDERR_RETDEFFAILURE
: msg
= wxT("PDERR_RETDEFFAILURE"); break;
78 case PDERR_PRINTERNOTFOUND
: msg
= wxT("PDERR_PRINTERNOTFOUND"); break;
79 case PDERR_PARSEFAILURE
: msg
= wxT("PDERR_PARSEFAILURE"); break;
80 case PDERR_NODEVICES
: msg
= wxT("PDERR_NODEVICES"); break;
81 case PDERR_NODEFAULTPRN
: msg
= wxT("PDERR_NODEFAULTPRN"); break;
82 case PDERR_LOADDRVFAILURE
: msg
= wxT("PDERR_LOADDRVFAILURE"); break;
83 case PDERR_INITFAILURE
: msg
= wxT("PDERR_INITFAILURE"); break;
84 case PDERR_GETDEVMODEFAIL
: msg
= wxT("PDERR_GETDEVMODEFAIL"); break;
85 case PDERR_DNDMMISMATCH
: msg
= wxT("PDERR_DNDMMISMATCH"); break;
86 case PDERR_DEFAULTDIFFERENT
: msg
= wxT("PDERR_DEFAULTDIFFERENT"); break;
87 case PDERR_CREATEICFAILURE
: msg
= wxT("PDERR_CREATEICFAILURE"); break;
94 static HGLOBAL
wxCreateDevNames(const wxString
& driverName
, const wxString
& printerName
, const wxString
& portName
)
97 // if (!driverName.empty() && !printerName.empty() && !portName.empty())
98 if (driverName
.empty() && printerName
.empty() && portName
.empty())
103 hDev
= GlobalAlloc(GPTR
, 4*sizeof(WORD
)+
104 ( driverName
.Length() + 1 +
105 printerName
.Length() + 1 +
106 portName
.Length()+1 ) * sizeof(wxChar
) );
107 LPDEVNAMES lpDev
= (LPDEVNAMES
)GlobalLock(hDev
);
108 lpDev
->wDriverOffset
= sizeof(WORD
) * 4 / sizeof(wxChar
);
109 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wDriverOffset
, driverName
);
111 lpDev
->wDeviceOffset
= (WORD
)( lpDev
->wDriverOffset
+
112 driverName
.Length() + 1 );
113 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wDeviceOffset
, printerName
);
115 lpDev
->wOutputOffset
= (WORD
)( lpDev
->wDeviceOffset
+
116 printerName
.Length() + 1 );
117 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wOutputOffset
, portName
);
127 IMPLEMENT_CLASS(wxWindowsPrintNativeData
, wxPrintNativeDataBase
)
129 wxWindowsPrintNativeData::wxWindowsPrintNativeData()
131 m_devMode
= (void*) NULL
;
132 m_devNames
= (void*) NULL
;
135 wxWindowsPrintNativeData::~wxWindowsPrintNativeData()
137 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
139 GlobalFree(hDevMode
);
140 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
142 GlobalFree(hDevNames
);
145 bool wxWindowsPrintNativeData::Ok() const
147 return (m_devMode
!= NULL
) ;
150 bool wxWindowsPrintNativeData::TransferTo( wxPrintData
&data
)
152 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
153 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.
203 if ((devMode
->dmFields
& DM_PAPERSIZE
) && (devMode
->dmPaperSize
< DMPAPER_USER
))
205 if (wxThePrintPaperDatabase
)
207 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
210 data
.SetPaperId( paper
->GetId() );
211 data
.SetPaperSize( wxSize(paper
->GetWidth() / 10,paper
->GetHeight() / 10) );
215 // Shouldn't really get here
216 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
217 data
.SetPaperId( wxPAPER_NONE
);
218 data
.SetPaperSize( wxSize(0,0) );
223 // Shouldn't really get here
224 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
225 data
.SetPaperId( wxPAPER_NONE
);
226 data
.SetPaperSize( wxSize(0,0) );
229 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
231 // DEVMODE is in tenths of a milimeter
232 data
.SetPaperId( wxPAPER_NONE
);
233 data
.SetPaperSize( wxSize(devMode
->dmPaperWidth
/ 10, devMode
->dmPaperLength
/ 10) );
237 // Shouldn't really get here
238 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
239 data
.SetPaperId( wxPAPER_NONE
);
240 data
.SetPaperSize( wxSize(0,0) );
245 if (devMode
->dmFields
& DM_DUPLEX
)
247 switch (devMode
->dmDuplex
)
249 case DMDUP_HORIZONTAL
: data
.SetDuplex( wxDUPLEX_HORIZONTAL
); break;
250 case DMDUP_VERTICAL
: data
.SetDuplex( wxDUPLEX_VERTICAL
); break;
252 case DMDUP_SIMPLEX
: data
.SetDuplex( wxDUPLEX_SIMPLEX
); break;
256 data
.SetDuplex( wxDUPLEX_SIMPLEX
);
260 if (devMode
->dmFields
& DM_PRINTQUALITY
)
262 switch (devMode
->dmPrintQuality
)
264 case DMRES_MEDIUM
: data
.SetQuality( wxPRINT_QUALITY_MEDIUM
); break;
265 case DMRES_LOW
: data
.SetQuality( wxPRINT_QUALITY_LOW
); break;
266 case DMRES_DRAFT
: data
.SetQuality( wxPRINT_QUALITY_DRAFT
); break;
267 case DMRES_HIGH
: data
.SetQuality( wxPRINT_QUALITY_HIGH
); break;
270 // TODO: if the printer fills in the resolution in DPI, how
271 // will the application know if it's high, low, draft etc.??
272 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
273 data
.SetQuality( devMode
->dmPrintQuality
);
280 data
.SetQuality( wxPRINT_QUALITY_HIGH
);
282 if (devMode
->dmDriverExtra
> 0)
283 data
.SetPrivData( (char *)devMode
+devMode
->dmSize
, devMode
->dmDriverExtra
);
285 data
.SetPrivData( NULL
, 0 );
287 GlobalUnlock(hDevMode
);
292 LPDEVNAMES lpDevNames
= (LPDEVNAMES
)GlobalLock(hDevNames
);
295 // TODO: Unicode-ification
298 // port is obsolete in WIN32
299 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
301 // Get the printer name
302 wxString printerName
= (LPTSTR
)lpDevNames
+ lpDevNames
->wDeviceOffset
;
304 // Not sure if we should check for this mismatch
305 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
307 if (!printerName
.empty())
308 data
.SetPrinterName( printerName
);
310 GlobalUnlock(hDevNames
);
317 bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData
&data
)
319 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
320 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
323 // Use PRINTDLG as a way of creating a DEVMODE object
326 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
331 memset(&pd
, 0, sizeof(PRINTDLG
));
333 pd
.cbStruct
= sizeof(PRINTDLG
);
335 pd
.lStructSize
= sizeof(PRINTDLG
);
339 pd
.hwndOwner
= (HWND
)NULL
;
340 pd
.hDevMode
= NULL
; // Will be created by PrintDlg
341 pd
.hDevNames
= NULL
; // Ditto
342 //pd.hInstance = (HINSTANCE) wxGetInstance();
344 pd
.Flags
= PD_RETURNDEFAULT
;
347 // Fill out the DEVMODE structure
348 // so we can use it as input in the 'real' PrintDlg
352 GlobalFree(pd
.hDevMode
);
354 GlobalFree(pd
.hDevNames
);
358 #if defined(__WXDEBUG__) && defined(__WIN32__)
359 wxString
str(wxT("Printing error: "));
360 str
+= wxGetPrintDlgError();
366 hDevMode
= pd
.hDevMode
;
367 m_devMode
= (void*)(long) hDevMode
;
370 // We'll create a new DEVNAMEs structure below.
372 GlobalFree(pd
.hDevNames
);
375 // hDevNames = pd->hDevNames;
376 // m_devNames = (void*)(long) hDevNames;
377 // pd->hDevnames = NULL;
384 LPDEVMODE devMode
= (LPDEVMODE
) GlobalLock(hDevMode
);
387 devMode
->dmOrientation
= (short)data
.GetOrientation();
390 devMode
->dmCollate
= (data
.GetCollate() ? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
391 devMode
->dmFields
|= DM_COLLATE
;
393 //// Number of copies
394 devMode
->dmCopies
= (short)data
.GetNoCopies();
395 devMode
->dmFields
|= DM_COPIES
;
398 wxString name
= data
.GetPrinterName();
401 //int len = wxMin(31, m_printerName.Len());
402 wxStrncpy((wxChar
*)devMode
->dmDeviceName
,name
.c_str(),31);
403 devMode
->dmDeviceName
[31] = wxT('\0');
407 if (data
.GetColour())
408 devMode
->dmColor
= DMCOLOR_COLOR
;
410 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
411 devMode
->dmFields
|= DM_COLOR
;
414 if (data
.GetPaperId() == wxPAPER_NONE
)
416 // DEVMODE is in tenths of a milimeter
417 devMode
->dmPaperWidth
= (short)(data
.GetPaperSize().x
* 10);
418 devMode
->dmPaperLength
= (short)(data
.GetPaperSize().y
* 10);
419 devMode
->dmPaperSize
= DMPAPER_USER
;
420 devMode
->dmFields
|= DM_PAPERWIDTH
;
421 devMode
->dmFields
|= DM_PAPERLENGTH
;
425 if (wxThePrintPaperDatabase
)
427 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType( data
.GetPaperId() );
430 devMode
->dmPaperSize
= (short)paper
->GetPlatformId();
431 devMode
->dmFields
|= DM_PAPERSIZE
;
438 switch (data
.GetDuplex())
440 case wxDUPLEX_HORIZONTAL
:
441 duplex
= DMDUP_HORIZONTAL
;
443 case wxDUPLEX_VERTICAL
:
444 duplex
= DMDUP_VERTICAL
;
447 // in fact case wxDUPLEX_SIMPLEX:
448 duplex
= DMDUP_SIMPLEX
;
451 devMode
->dmDuplex
= duplex
;
452 devMode
->dmFields
|= DM_DUPLEX
;
457 switch (data
.GetQuality())
459 case wxPRINT_QUALITY_MEDIUM
:
460 quality
= DMRES_MEDIUM
;
462 case wxPRINT_QUALITY_LOW
:
465 case wxPRINT_QUALITY_DRAFT
:
466 quality
= DMRES_DRAFT
;
468 case wxPRINT_QUALITY_HIGH
:
469 quality
= DMRES_HIGH
;
472 quality
= (short)data
.GetQuality();
475 devMode
->dmPrintQuality
= quality
;
476 devMode
->dmFields
|= DM_PRINTQUALITY
;
478 if (data
.GetPrivDataLen() > 0)
480 memcpy( (char *)devMode
+devMode
->dmSize
, data
.GetPrivData(), data
.GetPrivDataLen() );
481 devMode
->dmDriverExtra
= (WXWORD
)data
.GetPrivDataLen();
484 if (data
.GetBin() != wxPRINTBIN_DEFAULT
)
486 switch (data
.GetBin())
488 case wxPRINTBIN_ONLYONE
: devMode
->dmDefaultSource
= DMBIN_ONLYONE
; break;
489 case wxPRINTBIN_LOWER
: devMode
->dmDefaultSource
= DMBIN_LOWER
; break;
490 case wxPRINTBIN_MIDDLE
: devMode
->dmDefaultSource
= DMBIN_MIDDLE
; break;
491 case wxPRINTBIN_MANUAL
: devMode
->dmDefaultSource
= DMBIN_MANUAL
; break;
492 case wxPRINTBIN_ENVELOPE
: devMode
->dmDefaultSource
= DMBIN_ENVELOPE
; break;
493 case wxPRINTBIN_ENVMANUAL
: devMode
->dmDefaultSource
= DMBIN_ENVMANUAL
; break;
494 case wxPRINTBIN_AUTO
: devMode
->dmDefaultSource
= DMBIN_AUTO
; break;
495 case wxPRINTBIN_TRACTOR
: devMode
->dmDefaultSource
= DMBIN_TRACTOR
; break;
496 case wxPRINTBIN_SMALLFMT
: devMode
->dmDefaultSource
= DMBIN_SMALLFMT
; break;
497 case wxPRINTBIN_LARGEFMT
: devMode
->dmDefaultSource
= DMBIN_LARGEFMT
; break;
498 case wxPRINTBIN_LARGECAPACITY
: devMode
->dmDefaultSource
= DMBIN_LARGECAPACITY
; break;
499 case wxPRINTBIN_CASSETTE
: devMode
->dmDefaultSource
= DMBIN_CASSETTE
; break;
500 case wxPRINTBIN_FORMSOURCE
: devMode
->dmDefaultSource
= DMBIN_FORMSOURCE
; break;
503 devMode
->dmDefaultSource
= (short)(DMBIN_USER
+ data
.GetBin() - wxPRINTBIN_USER
);
507 devMode
->dmFields
|= DM_DEFAULTSOURCE
;
510 GlobalUnlock(hDevMode
);
515 GlobalFree(hDevNames
);
518 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
519 m_devNames
= (void*) (long) wxCreateDevNames(wxEmptyString
, data
.GetPrinterName(), wxEmptyString
);
524 // ---------------------------------------------------------------------------
526 // ---------------------------------------------------------------------------
528 IMPLEMENT_CLASS(wxWindowsPrintDialog
, wxPrintDialogBase
)
530 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintDialogData
* data
)
535 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintData
* data
)
537 wxPrintDialogData data2
;
544 bool wxWindowsPrintDialog::Create(wxWindow
*p
, wxPrintDialogData
* data
)
554 m_printDialogData
= *data
;
559 wxWindowsPrintDialog::~wxWindowsPrintDialog()
561 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
562 if (pd
&& pd
->hDevMode
)
563 GlobalFree(pd
->hDevMode
);
567 if (m_destroyDC
&& m_printerDC
)
571 int wxWindowsPrintDialog::ShowModal()
573 ConvertToNative( m_printDialogData
);
575 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
578 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
579 else if (wxTheApp
->GetTopWindow())
580 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
584 bool ret
= (PrintDlg( pd
) != 0);
588 if ( ret
!= false && (pd
->hDC
) )
590 wxPrinterDC
*pdc
= new wxPrinterDC( (WXHDC
) pd
->hDC
);
592 ConvertFromNative( m_printDialogData
);
601 wxDC
*wxWindowsPrintDialog::GetPrintDC()
612 bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData
&data
)
614 wxWindowsPrintNativeData
*native_data
=
615 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
616 data
.GetPrintData().ConvertToNative();
618 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
620 // Shouldn't have been defined anywhere
625 memset( pd
, 0, sizeof(PRINTDLG
) );
626 m_printDlg
= (void*) pd
;
628 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
630 pd
->lStructSize
= 66;
632 pd
->lStructSize
= sizeof(PRINTDLG
);
634 pd
->hwndOwner
= (HWND
)NULL
;
635 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
636 pd
->hDevNames
= NULL
; // Ditto
638 pd
->Flags
= PD_RETURNDEFAULT
;
641 // Pass the devmode data to the PRINTDLG structure, since it'll
642 // be needed when PrintDlg is called.
644 GlobalFree(pd
->hDevMode
);
646 // Pass the devnames data to the PRINTDLG structure, since it'll
647 // be needed when PrintDlg is called.
649 GlobalFree(pd
->hDevNames
);
651 pd
->hDevMode
= (HGLOBAL
)(DWORD
) native_data
->GetDevMode();
652 native_data
->SetDevMode( (void*) NULL
);
654 // Shouldn't assert; we should be able to test Ok-ness at a higher level
655 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
657 pd
->hDevNames
= (HGLOBAL
)(DWORD
) native_data
->GetDevNames();
658 native_data
->SetDevNames( (void*) NULL
);
661 pd
->hDC
= (HDC
) NULL
;
662 pd
->nFromPage
= (WORD
)data
.GetFromPage();
663 pd
->nToPage
= (WORD
)data
.GetToPage();
664 pd
->nMinPage
= (WORD
)data
.GetMinPage();
665 pd
->nMaxPage
= (WORD
)data
.GetMaxPage();
666 pd
->nCopies
= (WORD
)data
.GetNoCopies();
668 pd
->Flags
= PD_RETURNDC
;
671 pd
->lStructSize
= 66;
673 pd
->lStructSize
= sizeof( PRINTDLG
);
676 pd
->hwndOwner
=(HWND
)NULL
;
677 // pd->hDevNames=(HANDLE)NULL;
678 pd
->hInstance
=(HINSTANCE
)NULL
;
679 pd
->lCustData
= (LPARAM
) NULL
;
680 pd
->lpfnPrintHook
= NULL
;
681 pd
->lpfnSetupHook
= NULL
;
682 pd
->lpPrintTemplateName
= NULL
;
683 pd
->lpSetupTemplateName
= NULL
;
684 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
685 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
687 if ( data
.GetAllPages() )
688 pd
->Flags
|= PD_ALLPAGES
;
689 if ( data
.GetSelection() )
690 pd
->Flags
|= PD_SELECTION
;
691 if ( data
.GetCollate() )
692 pd
->Flags
|= PD_COLLATE
;
693 if ( data
.GetPrintToFile() )
694 pd
->Flags
|= PD_PRINTTOFILE
;
695 if ( !data
.GetEnablePrintToFile() )
696 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
697 if ( !data
.GetEnableSelection() )
698 pd
->Flags
|= PD_NOSELECTION
;
699 if ( !data
.GetEnablePageNumbers() )
700 pd
->Flags
|= PD_NOPAGENUMS
;
701 else if ( (!data
.GetAllPages()) && (!data
.GetSelection()) && (data
.GetFromPage() != 0) && (data
.GetToPage() != 0))
702 pd
->Flags
|= PD_PAGENUMS
;
703 if ( data
.GetEnableHelp() )
704 pd
->Flags
|= PD_SHOWHELP
;
705 #if WXWIN_COMPATIBILITY_2_4
706 if ( data
.GetSetupDialog() )
707 pd
->Flags
|= PD_PRINTSETUP
;
713 bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData
&data
)
715 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
719 wxWindowsPrintNativeData
*native_data
=
720 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
722 // Pass the devmode data back to the wxPrintData structure where it really belongs.
725 if (native_data
->GetDevMode())
727 // Make sure we don't leak memory
728 GlobalFree( (HGLOBAL
)(DWORD
) native_data
->GetDevMode() );
730 native_data
->SetDevMode( (void*)(long) pd
->hDevMode
);
734 // Pass the devnames data back to the wxPrintData structure where it really belongs.
737 if (native_data
->GetDevNames())
739 // Make sure we don't leak memory
740 GlobalFree((HGLOBAL
)(DWORD
) native_data
->GetDevNames());
742 native_data
->SetDevNames((void*)(long) pd
->hDevNames
);
743 pd
->hDevNames
= NULL
;
746 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
747 // into wxWidgets form.
748 native_data
->TransferTo( data
.GetPrintData() );
750 data
.SetFromPage( pd
->nFromPage
);
751 data
.SetToPage( pd
->nToPage
);
752 data
.SetMinPage( pd
->nMinPage
);
753 data
.SetMaxPage( pd
->nMaxPage
);
754 data
.SetNoCopies( pd
->nCopies
);
756 data
.SetAllPages( (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
)) );
757 data
.SetSelection( ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
) );
758 data
.SetCollate( ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
) );
759 data
.SetPrintToFile( ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
) );
760 data
.EnablePrintToFile( ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
) );
761 data
.EnableSelection( ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
) );
762 data
.EnablePageNumbers( ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
) );
763 data
.EnableHelp( ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
) );
764 #if WXWIN_COMPATIBILITY_2_4
765 data
.SetSetupDialog( ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
) );
770 // ---------------------------------------------------------------------------
771 // wxWidnowsPageSetupDialog
772 // ---------------------------------------------------------------------------
774 IMPLEMENT_CLASS(wxWindowsPageSetupDialog
, wxPageSetupDialogBase
)
776 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog()
778 m_dialogParent
= NULL
;
782 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog(wxWindow
*p
, wxPageSetupDialogData
*data
)
787 bool wxWindowsPageSetupDialog::Create(wxWindow
*p
, wxPageSetupDialogData
*data
)
793 m_pageSetupData
= (*data
);
798 wxWindowsPageSetupDialog::~wxWindowsPageSetupDialog()
800 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageDlg
;
801 if ( pd
&& pd
->hDevMode
)
802 GlobalFree(pd
->hDevMode
);
803 if ( pd
&& pd
->hDevNames
)
804 GlobalFree(pd
->hDevNames
);
809 int wxWindowsPageSetupDialog::ShowModal()
811 ConvertToNative( m_pageSetupData
);
813 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
815 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
816 else if (wxTheApp
->GetTopWindow())
817 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
820 BOOL retVal
= PageSetupDlg( pd
) ;
824 ConvertFromNative( m_pageSetupData
);
831 bool wxWindowsPageSetupDialog::ConvertToNative( wxPageSetupDialogData
&data
)
833 wxWindowsPrintNativeData
*native_data
=
834 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
835 data
.GetPrintData().ConvertToNative();
837 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
839 // Shouldn't have been defined anywhere
843 pd
= new PAGESETUPDLG
;
845 pd
->hDevNames
= NULL
;
846 m_pageDlg
= (void *)pd
;
848 // Pass the devmode data (created in m_printData.ConvertToNative)
849 // to the PRINTDLG structure, since it'll
850 // be needed when PrintDlg is called.
854 GlobalFree(pd
->hDevMode
);
857 pd
->hDevMode
= (HGLOBAL
) native_data
->GetDevMode();
858 native_data
->SetDevMode( (void*) NULL
);
860 // Shouldn't assert; we should be able to test Ok-ness at a higher level
861 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
863 // Pass the devnames data (created in m_printData.ConvertToNative)
864 // to the PRINTDLG structure, since it'll
865 // be needed when PrintDlg is called.
869 GlobalFree(pd
->hDevNames
);
870 pd
->hDevNames
= NULL
;
872 pd
->hDevNames
= (HGLOBAL
) native_data
->GetDevNames();
873 native_data
->SetDevNames((void*) NULL
);
875 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
877 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
879 if ( data
.GetDefaultMinMargins() )
880 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
881 if ( !data
.GetEnableMargins() )
882 pd
->Flags
|= PSD_DISABLEMARGINS
;
883 if ( !data
.GetEnableOrientation() )
884 pd
->Flags
|= PSD_DISABLEORIENTATION
;
885 if ( !data
.GetEnablePaper() )
886 pd
->Flags
|= PSD_DISABLEPAPER
;
887 if ( !data
.GetEnablePrinter() )
888 pd
->Flags
|= PSD_DISABLEPRINTER
;
889 if ( data
.GetDefaultInfo() )
890 pd
->Flags
|= PSD_RETURNDEFAULT
;
891 if ( data
.GetEnableHelp() )
892 pd
->Flags
|= PSD_SHOWHELP
;
894 // We want the units to be in hundredths of a millimetre
895 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
897 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
898 pd
->hwndOwner
=(HWND
)NULL
;
899 // pd->hDevNames=(HWND)NULL;
900 pd
->hInstance
=(HINSTANCE
)NULL
;
901 // PAGESETUPDLG is in hundreds of a mm
902 pd
->ptPaperSize
.x
= data
.GetPaperSize().x
* 100;
903 pd
->ptPaperSize
.y
= data
.GetPaperSize().y
* 100;
905 pd
->rtMinMargin
.left
= data
.GetMinMarginTopLeft().x
* 100;
906 pd
->rtMinMargin
.top
= data
.GetMinMarginTopLeft().y
* 100;
907 pd
->rtMinMargin
.right
= data
.GetMinMarginBottomRight().x
* 100;
908 pd
->rtMinMargin
.bottom
= data
.GetMinMarginBottomRight().y
* 100;
910 pd
->rtMargin
.left
= data
.GetMarginTopLeft().x
* 100;
911 pd
->rtMargin
.top
= data
.GetMarginTopLeft().y
* 100;
912 pd
->rtMargin
.right
= data
.GetMarginBottomRight().x
* 100;
913 pd
->rtMargin
.bottom
= data
.GetMarginBottomRight().y
* 100;
916 pd
->lpfnPageSetupHook
= NULL
;
917 pd
->lpfnPagePaintHook
= NULL
;
918 pd
->hPageSetupTemplate
= NULL
;
919 pd
->lpPageSetupTemplateName
= NULL
;
924 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
925 memset(devMode, 0, sizeof(DEVMODE));
926 devMode->dmSize = sizeof(DEVMODE);
927 devMode->dmOrientation = m_orientation;
928 devMode->dmFields = DM_ORIENTATION;
929 GlobalUnlock(pd->hDevMode);
935 bool wxWindowsPageSetupDialog::ConvertFromNative( wxPageSetupDialogData
&data
)
937 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
941 wxWindowsPrintNativeData
*native_data
=
942 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
944 // Pass the devmode data back to the wxPrintData structure where it really belongs.
947 if (native_data
->GetDevMode())
949 // Make sure we don't leak memory
950 GlobalFree((HGLOBAL
) native_data
->GetDevMode());
952 native_data
->SetDevMode( (void*) pd
->hDevMode
);
956 // Isn't this superfluous? It's called again below.
957 // data.GetPrintData().ConvertFromNative();
959 // Pass the devnames data back to the wxPrintData structure where it really belongs.
962 if (native_data
->GetDevNames())
964 // Make sure we don't leak memory
965 GlobalFree((HGLOBAL
) native_data
->GetDevNames());
967 native_data
->SetDevNames((void*) pd
->hDevNames
);
968 pd
->hDevNames
= NULL
;
971 data
.GetPrintData().ConvertFromNative();
973 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
975 data
.SetDefaultMinMargins( ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
) );
976 data
.EnableMargins( ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
) );
977 data
.EnableOrientation( ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
) );
978 data
.EnablePaper( ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
) );
979 data
.EnablePrinter( ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
) );
980 data
.SetDefaultInfo( ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
) );
981 data
.EnableHelp( ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
) );
983 // PAGESETUPDLG is in hundreds of a mm
984 data
.SetPaperSize( wxSize(pd
->ptPaperSize
.x
/ 100, pd
->ptPaperSize
.y
/ 100) );
986 data
.SetMinMarginTopLeft( wxPoint(pd
->rtMinMargin
.left
/ 100, pd
->rtMinMargin
.top
/ 100) );
987 data
.SetMinMarginBottomRight( wxPoint(pd
->rtMinMargin
.right
/ 100, pd
->rtMinMargin
.bottom
/ 100) );
989 data
.SetMarginTopLeft( wxPoint(pd
->rtMargin
.left
/ 100, pd
->rtMargin
.top
/ 100) );
990 data
.SetMarginBottomRight( wxPoint(pd
->rtMargin
.right
/ 100, pd
->rtMargin
.bottom
/ 100) );
996 // wxUSE_PRINTING_ARCHITECTURE