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
;
133 wxWindowsPrintNativeData::~wxWindowsPrintNativeData()
135 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
137 GlobalFree(hDevMode
);
138 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
140 GlobalFree(hDevNames
);
143 bool wxWindowsPrintNativeData::Ok() const
145 return (m_devMode
!= NULL
) ;
148 bool wxWindowsPrintNativeData::TransferTo( wxPrintData
&data
)
150 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
151 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
158 LPDEVMODE devMode
= (LPDEVMODE
)GlobalLock(hDevMode
);
161 if (devMode
->dmFields
& DM_ORIENTATION
)
162 data
.SetOrientation( devMode
->dmOrientation
);
165 if (devMode
->dmFields
& DM_COLLATE
)
167 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
168 data
.SetCollate( true );
170 data
.SetCollate( false );
173 //// Number of copies
174 if (devMode
->dmFields
& DM_COPIES
)
175 data
.SetNoCopies( devMode
->dmCopies
);
177 if (devMode
->dmFields
& DM_DEFAULTSOURCE
)
178 data
.SetBin( (wxPrintBin
)devMode
->dmDefaultSource
);
181 if (devMode
->dmDeviceName
[0] != 0)
182 data
.SetPrinterName( devMode
->dmDeviceName
);
185 if (devMode
->dmFields
& DM_COLOR
)
187 if (devMode
->dmColor
== DMCOLOR_COLOR
)
188 data
.SetColour( true );
190 data
.SetColour( false );
193 data
.SetColour( true );
197 // We don't know size of user defined paper and some buggy drivers
198 // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
199 // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
200 // code wouldn't set m_paperSize correctly.
202 bool foundPaperSize
= false;
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) );
212 foundPaperSize
= true;
217 // Shouldn't really get here
218 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
219 data
.SetPaperId( wxPAPER_NONE
);
220 data
.SetPaperSize( wxSize(0,0) );
222 GlobalUnlock(hDevMode
);
227 if (!foundPaperSize
&& (devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
229 // DEVMODE is in tenths of a milimeter
230 data
.SetPaperId( wxPAPER_NONE
);
231 data
.SetPaperSize( wxSize(devMode
->dmPaperWidth
/ 10, devMode
->dmPaperLength
/ 10) );
235 // Shouldn't really get here
236 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
237 data
.SetPaperId( wxPAPER_NONE
);
238 data
.SetPaperSize( wxSize(0,0) );
240 GlobalUnlock(hDevMode
);
246 if (devMode
->dmFields
& DM_DUPLEX
)
248 switch (devMode
->dmDuplex
)
250 case DMDUP_HORIZONTAL
: data
.SetDuplex( wxDUPLEX_HORIZONTAL
); break;
251 case DMDUP_VERTICAL
: data
.SetDuplex( wxDUPLEX_VERTICAL
); break;
253 case DMDUP_SIMPLEX
: data
.SetDuplex( wxDUPLEX_SIMPLEX
); break;
257 data
.SetDuplex( wxDUPLEX_SIMPLEX
);
261 if (devMode
->dmFields
& DM_PRINTQUALITY
)
263 switch (devMode
->dmPrintQuality
)
265 case DMRES_MEDIUM
: data
.SetQuality( wxPRINT_QUALITY_MEDIUM
); break;
266 case DMRES_LOW
: data
.SetQuality( wxPRINT_QUALITY_LOW
); break;
267 case DMRES_DRAFT
: data
.SetQuality( wxPRINT_QUALITY_DRAFT
); break;
268 case DMRES_HIGH
: data
.SetQuality( wxPRINT_QUALITY_HIGH
); break;
271 // TODO: if the printer fills in the resolution in DPI, how
272 // will the application know if it's high, low, draft etc.??
273 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
274 data
.SetQuality( devMode
->dmPrintQuality
);
281 data
.SetQuality( wxPRINT_QUALITY_HIGH
);
283 if (devMode
->dmDriverExtra
> 0)
284 data
.SetPrivData( (char *)devMode
+devMode
->dmSize
, devMode
->dmDriverExtra
);
286 data
.SetPrivData( NULL
, 0 );
288 GlobalUnlock(hDevMode
);
293 LPDEVNAMES lpDevNames
= (LPDEVNAMES
)GlobalLock(hDevNames
);
296 // TODO: Unicode-ification
299 // port is obsolete in WIN32
300 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
302 // Get the printer name
303 wxString printerName
= (LPTSTR
)lpDevNames
+ lpDevNames
->wDeviceOffset
;
305 // Not sure if we should check for this mismatch
306 // wxASSERT_MSG( (m_printerName.empty() || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
308 if (!printerName
.empty())
309 data
.SetPrinterName( printerName
);
311 GlobalUnlock(hDevNames
);
318 bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData
&data
)
320 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
321 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
324 // Use PRINTDLG as a way of creating a DEVMODE object
327 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
332 memset(&pd
, 0, sizeof(PRINTDLG
));
334 pd
.cbStruct
= sizeof(PRINTDLG
);
336 pd
.lStructSize
= sizeof(PRINTDLG
);
340 pd
.hwndOwner
= (HWND
)NULL
;
341 pd
.hDevMode
= NULL
; // Will be created by PrintDlg
342 pd
.hDevNames
= NULL
; // Ditto
343 //pd.hInstance = (HINSTANCE) wxGetInstance();
345 pd
.Flags
= PD_RETURNDEFAULT
;
348 // Fill out the DEVMODE structure
349 // so we can use it as input in the 'real' PrintDlg
353 GlobalFree(pd
.hDevMode
);
355 GlobalFree(pd
.hDevNames
);
359 #if defined(__WXDEBUG__) && defined(__WIN32__)
360 wxString
str(wxT("Printing error: "));
361 str
+= wxGetPrintDlgError();
367 hDevMode
= pd
.hDevMode
;
368 m_devMode
= (void*)(long) hDevMode
;
371 // We'll create a new DEVNAMEs structure below.
373 GlobalFree(pd
.hDevNames
);
376 // hDevNames = pd->hDevNames;
377 // m_devNames = (void*)(long) hDevNames;
378 // pd->hDevnames = NULL;
385 LPDEVMODE devMode
= (LPDEVMODE
) GlobalLock(hDevMode
);
388 devMode
->dmOrientation
= (short)data
.GetOrientation();
391 devMode
->dmCollate
= (data
.GetCollate() ? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
392 devMode
->dmFields
|= DM_COLLATE
;
394 //// Number of copies
395 devMode
->dmCopies
= (short)data
.GetNoCopies();
396 devMode
->dmFields
|= DM_COPIES
;
399 wxString name
= data
.GetPrinterName();
402 //int len = wxMin(31, m_printerName.Len());
403 wxStrncpy((wxChar
*)devMode
->dmDeviceName
,name
.c_str(),31);
404 devMode
->dmDeviceName
[31] = wxT('\0');
408 if (data
.GetColour())
409 devMode
->dmColor
= DMCOLOR_COLOR
;
411 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
412 devMode
->dmFields
|= DM_COLOR
;
415 if (data
.GetPaperId() == wxPAPER_NONE
)
417 // DEVMODE is in tenths of a milimeter
418 devMode
->dmPaperWidth
= (short)(data
.GetPaperSize().x
* 10);
419 devMode
->dmPaperLength
= (short)(data
.GetPaperSize().y
* 10);
420 devMode
->dmPaperSize
= DMPAPER_USER
;
421 devMode
->dmFields
|= DM_PAPERWIDTH
;
422 devMode
->dmFields
|= DM_PAPERLENGTH
;
426 if (wxThePrintPaperDatabase
)
428 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType( data
.GetPaperId() );
431 devMode
->dmPaperSize
= (short)paper
->GetPlatformId();
432 devMode
->dmFields
|= DM_PAPERSIZE
;
436 // Fall back on specifying the paper size explicitly
437 devMode
->dmPaperWidth
= (short)(data
.GetPaperSize().x
* 10);
438 devMode
->dmPaperLength
= (short)(data
.GetPaperSize().y
* 10);
439 devMode
->dmPaperSize
= DMPAPER_USER
;
440 devMode
->dmFields
|= DM_PAPERWIDTH
;
441 devMode
->dmFields
|= DM_PAPERLENGTH
;
448 switch (data
.GetDuplex())
450 case wxDUPLEX_HORIZONTAL
:
451 duplex
= DMDUP_HORIZONTAL
;
453 case wxDUPLEX_VERTICAL
:
454 duplex
= DMDUP_VERTICAL
;
457 // in fact case wxDUPLEX_SIMPLEX:
458 duplex
= DMDUP_SIMPLEX
;
461 devMode
->dmDuplex
= duplex
;
462 devMode
->dmFields
|= DM_DUPLEX
;
467 switch (data
.GetQuality())
469 case wxPRINT_QUALITY_MEDIUM
:
470 quality
= DMRES_MEDIUM
;
472 case wxPRINT_QUALITY_LOW
:
475 case wxPRINT_QUALITY_DRAFT
:
476 quality
= DMRES_DRAFT
;
478 case wxPRINT_QUALITY_HIGH
:
479 quality
= DMRES_HIGH
;
482 quality
= (short)data
.GetQuality();
485 devMode
->dmPrintQuality
= quality
;
486 devMode
->dmFields
|= DM_PRINTQUALITY
;
488 if (data
.GetPrivDataLen() > 0)
490 memcpy( (char *)devMode
+devMode
->dmSize
, data
.GetPrivData(), data
.GetPrivDataLen() );
491 devMode
->dmDriverExtra
= (WXWORD
)data
.GetPrivDataLen();
494 if (data
.GetBin() != wxPRINTBIN_DEFAULT
)
496 switch (data
.GetBin())
498 case wxPRINTBIN_ONLYONE
: devMode
->dmDefaultSource
= DMBIN_ONLYONE
; break;
499 case wxPRINTBIN_LOWER
: devMode
->dmDefaultSource
= DMBIN_LOWER
; break;
500 case wxPRINTBIN_MIDDLE
: devMode
->dmDefaultSource
= DMBIN_MIDDLE
; break;
501 case wxPRINTBIN_MANUAL
: devMode
->dmDefaultSource
= DMBIN_MANUAL
; break;
502 case wxPRINTBIN_ENVELOPE
: devMode
->dmDefaultSource
= DMBIN_ENVELOPE
; break;
503 case wxPRINTBIN_ENVMANUAL
: devMode
->dmDefaultSource
= DMBIN_ENVMANUAL
; break;
504 case wxPRINTBIN_AUTO
: devMode
->dmDefaultSource
= DMBIN_AUTO
; break;
505 case wxPRINTBIN_TRACTOR
: devMode
->dmDefaultSource
= DMBIN_TRACTOR
; break;
506 case wxPRINTBIN_SMALLFMT
: devMode
->dmDefaultSource
= DMBIN_SMALLFMT
; break;
507 case wxPRINTBIN_LARGEFMT
: devMode
->dmDefaultSource
= DMBIN_LARGEFMT
; break;
508 case wxPRINTBIN_LARGECAPACITY
: devMode
->dmDefaultSource
= DMBIN_LARGECAPACITY
; break;
509 case wxPRINTBIN_CASSETTE
: devMode
->dmDefaultSource
= DMBIN_CASSETTE
; break;
510 case wxPRINTBIN_FORMSOURCE
: devMode
->dmDefaultSource
= DMBIN_FORMSOURCE
; break;
513 devMode
->dmDefaultSource
= (short)(DMBIN_USER
+ data
.GetBin() - wxPRINTBIN_USER
);
517 devMode
->dmFields
|= DM_DEFAULTSOURCE
;
520 GlobalUnlock(hDevMode
);
525 GlobalFree(hDevNames
);
528 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
529 m_devNames
= (void*) (long) wxCreateDevNames(wxEmptyString
, data
.GetPrinterName(), wxEmptyString
);
534 // ---------------------------------------------------------------------------
536 // ---------------------------------------------------------------------------
538 IMPLEMENT_CLASS(wxWindowsPrintDialog
, wxPrintDialogBase
)
540 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintDialogData
* data
)
545 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintData
* data
)
547 wxPrintDialogData data2
;
554 bool wxWindowsPrintDialog::Create(wxWindow
*p
, wxPrintDialogData
* data
)
564 m_printDialogData
= *data
;
569 wxWindowsPrintDialog::~wxWindowsPrintDialog()
571 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
572 if (pd
&& pd
->hDevMode
)
573 GlobalFree(pd
->hDevMode
);
577 if (m_destroyDC
&& m_printerDC
)
581 int wxWindowsPrintDialog::ShowModal()
583 ConvertToNative( m_printDialogData
);
585 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
588 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
589 else if (wxTheApp
->GetTopWindow())
590 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
594 bool ret
= (PrintDlg( pd
) != 0);
598 if ( ret
!= false && (pd
->hDC
) )
600 wxPrinterDC
*pdc
= new wxPrinterDC( (WXHDC
) pd
->hDC
);
602 ConvertFromNative( m_printDialogData
);
611 wxDC
*wxWindowsPrintDialog::GetPrintDC()
622 bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData
&data
)
624 wxWindowsPrintNativeData
*native_data
=
625 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
626 data
.GetPrintData().ConvertToNative();
628 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
630 // Shouldn't have been defined anywhere
635 memset( pd
, 0, sizeof(PRINTDLG
) );
636 m_printDlg
= (void*) pd
;
638 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
640 pd
->lStructSize
= 66;
642 pd
->lStructSize
= sizeof(PRINTDLG
);
644 pd
->hwndOwner
= (HWND
)NULL
;
645 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
646 pd
->hDevNames
= NULL
; // Ditto
648 pd
->Flags
= PD_RETURNDEFAULT
;
651 // Pass the devmode data to the PRINTDLG structure, since it'll
652 // be needed when PrintDlg is called.
654 GlobalFree(pd
->hDevMode
);
656 // Pass the devnames data to the PRINTDLG structure, since it'll
657 // be needed when PrintDlg is called.
659 GlobalFree(pd
->hDevNames
);
661 pd
->hDevMode
= (HGLOBAL
)(DWORD
) native_data
->GetDevMode();
662 native_data
->SetDevMode( (void*) NULL
);
664 // Shouldn't assert; we should be able to test Ok-ness at a higher level
665 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
667 pd
->hDevNames
= (HGLOBAL
)(DWORD
) native_data
->GetDevNames();
668 native_data
->SetDevNames( (void*) NULL
);
671 pd
->hDC
= (HDC
) NULL
;
672 pd
->nFromPage
= (WORD
)data
.GetFromPage();
673 pd
->nToPage
= (WORD
)data
.GetToPage();
674 pd
->nMinPage
= (WORD
)data
.GetMinPage();
675 pd
->nMaxPage
= (WORD
)data
.GetMaxPage();
676 pd
->nCopies
= (WORD
)data
.GetNoCopies();
678 pd
->Flags
= PD_RETURNDC
;
681 pd
->lStructSize
= 66;
683 pd
->lStructSize
= sizeof( PRINTDLG
);
686 pd
->hwndOwner
=(HWND
)NULL
;
687 // pd->hDevNames=(HANDLE)NULL;
688 pd
->hInstance
=(HINSTANCE
)NULL
;
689 pd
->lCustData
= (LPARAM
) NULL
;
690 pd
->lpfnPrintHook
= NULL
;
691 pd
->lpfnSetupHook
= NULL
;
692 pd
->lpPrintTemplateName
= NULL
;
693 pd
->lpSetupTemplateName
= NULL
;
694 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
695 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
697 if ( data
.GetAllPages() )
698 pd
->Flags
|= PD_ALLPAGES
;
699 if ( data
.GetSelection() )
700 pd
->Flags
|= PD_SELECTION
;
701 if ( data
.GetCollate() )
702 pd
->Flags
|= PD_COLLATE
;
703 if ( data
.GetPrintToFile() )
704 pd
->Flags
|= PD_PRINTTOFILE
;
705 if ( !data
.GetEnablePrintToFile() )
706 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
707 if ( !data
.GetEnableSelection() )
708 pd
->Flags
|= PD_NOSELECTION
;
709 if ( !data
.GetEnablePageNumbers() )
710 pd
->Flags
|= PD_NOPAGENUMS
;
711 else if ( (!data
.GetAllPages()) && (!data
.GetSelection()) && (data
.GetFromPage() != 0) && (data
.GetToPage() != 0))
712 pd
->Flags
|= PD_PAGENUMS
;
713 if ( data
.GetEnableHelp() )
714 pd
->Flags
|= PD_SHOWHELP
;
715 #if WXWIN_COMPATIBILITY_2_4
716 if ( data
.GetSetupDialog() )
717 pd
->Flags
|= PD_PRINTSETUP
;
723 bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData
&data
)
725 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
729 wxWindowsPrintNativeData
*native_data
=
730 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
732 // Pass the devmode data back to the wxPrintData structure where it really belongs.
735 if (native_data
->GetDevMode())
737 // Make sure we don't leak memory
738 GlobalFree( (HGLOBAL
)(DWORD
) native_data
->GetDevMode() );
740 native_data
->SetDevMode( (void*)(long) pd
->hDevMode
);
744 // Pass the devnames data back to the wxPrintData structure where it really belongs.
747 if (native_data
->GetDevNames())
749 // Make sure we don't leak memory
750 GlobalFree((HGLOBAL
)(DWORD
) native_data
->GetDevNames());
752 native_data
->SetDevNames((void*)(long) pd
->hDevNames
);
753 pd
->hDevNames
= NULL
;
756 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
757 // into wxWidgets form.
758 native_data
->TransferTo( data
.GetPrintData() );
760 data
.SetFromPage( pd
->nFromPage
);
761 data
.SetToPage( pd
->nToPage
);
762 data
.SetMinPage( pd
->nMinPage
);
763 data
.SetMaxPage( pd
->nMaxPage
);
764 data
.SetNoCopies( pd
->nCopies
);
766 data
.SetAllPages( (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
)) );
767 data
.SetSelection( ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
) );
768 data
.SetCollate( ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
) );
769 data
.SetPrintToFile( ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
) );
770 data
.EnablePrintToFile( ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
) );
771 data
.EnableSelection( ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
) );
772 data
.EnablePageNumbers( ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
) );
773 data
.EnableHelp( ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
) );
774 #if WXWIN_COMPATIBILITY_2_4
775 data
.SetSetupDialog( ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
) );
780 // ---------------------------------------------------------------------------
781 // wxWidnowsPageSetupDialog
782 // ---------------------------------------------------------------------------
784 IMPLEMENT_CLASS(wxWindowsPageSetupDialog
, wxPageSetupDialogBase
)
786 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog()
788 m_dialogParent
= NULL
;
792 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog(wxWindow
*p
, wxPageSetupDialogData
*data
)
797 bool wxWindowsPageSetupDialog::Create(wxWindow
*p
, wxPageSetupDialogData
*data
)
803 m_pageSetupData
= (*data
);
808 wxWindowsPageSetupDialog::~wxWindowsPageSetupDialog()
810 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageDlg
;
811 if ( pd
&& pd
->hDevMode
)
812 GlobalFree(pd
->hDevMode
);
813 if ( pd
&& pd
->hDevNames
)
814 GlobalFree(pd
->hDevNames
);
819 int wxWindowsPageSetupDialog::ShowModal()
821 ConvertToNative( m_pageSetupData
);
823 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
825 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
826 else if (wxTheApp
->GetTopWindow())
827 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
830 BOOL retVal
= PageSetupDlg( pd
) ;
834 ConvertFromNative( m_pageSetupData
);
841 bool wxWindowsPageSetupDialog::ConvertToNative( wxPageSetupDialogData
&data
)
843 wxWindowsPrintNativeData
*native_data
=
844 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
845 data
.GetPrintData().ConvertToNative();
847 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
849 // Shouldn't have been defined anywhere
853 pd
= new PAGESETUPDLG
;
855 pd
->hDevNames
= NULL
;
856 m_pageDlg
= (void *)pd
;
858 // Pass the devmode data (created in m_printData.ConvertToNative)
859 // to the PRINTDLG structure, since it'll
860 // be needed when PrintDlg is called.
864 GlobalFree(pd
->hDevMode
);
867 pd
->hDevMode
= (HGLOBAL
) native_data
->GetDevMode();
868 native_data
->SetDevMode( (void*) NULL
);
870 // Shouldn't assert; we should be able to test Ok-ness at a higher level
871 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
873 // Pass the devnames data (created in m_printData.ConvertToNative)
874 // to the PRINTDLG structure, since it'll
875 // be needed when PrintDlg is called.
879 GlobalFree(pd
->hDevNames
);
880 pd
->hDevNames
= NULL
;
882 pd
->hDevNames
= (HGLOBAL
) native_data
->GetDevNames();
883 native_data
->SetDevNames((void*) NULL
);
885 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
887 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
889 if ( data
.GetDefaultMinMargins() )
890 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
891 if ( !data
.GetEnableMargins() )
892 pd
->Flags
|= PSD_DISABLEMARGINS
;
893 if ( !data
.GetEnableOrientation() )
894 pd
->Flags
|= PSD_DISABLEORIENTATION
;
895 if ( !data
.GetEnablePaper() )
896 pd
->Flags
|= PSD_DISABLEPAPER
;
897 if ( !data
.GetEnablePrinter() )
898 pd
->Flags
|= PSD_DISABLEPRINTER
;
899 if ( data
.GetDefaultInfo() )
900 pd
->Flags
|= PSD_RETURNDEFAULT
;
901 if ( data
.GetEnableHelp() )
902 pd
->Flags
|= PSD_SHOWHELP
;
904 // We want the units to be in hundredths of a millimetre
905 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
907 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
908 pd
->hwndOwner
=(HWND
)NULL
;
909 // pd->hDevNames=(HWND)NULL;
910 pd
->hInstance
=(HINSTANCE
)NULL
;
911 // PAGESETUPDLG is in hundreds of a mm
912 pd
->ptPaperSize
.x
= data
.GetPaperSize().x
* 100;
913 pd
->ptPaperSize
.y
= data
.GetPaperSize().y
* 100;
915 pd
->rtMinMargin
.left
= data
.GetMinMarginTopLeft().x
* 100;
916 pd
->rtMinMargin
.top
= data
.GetMinMarginTopLeft().y
* 100;
917 pd
->rtMinMargin
.right
= data
.GetMinMarginBottomRight().x
* 100;
918 pd
->rtMinMargin
.bottom
= data
.GetMinMarginBottomRight().y
* 100;
920 pd
->rtMargin
.left
= data
.GetMarginTopLeft().x
* 100;
921 pd
->rtMargin
.top
= data
.GetMarginTopLeft().y
* 100;
922 pd
->rtMargin
.right
= data
.GetMarginBottomRight().x
* 100;
923 pd
->rtMargin
.bottom
= data
.GetMarginBottomRight().y
* 100;
926 pd
->lpfnPageSetupHook
= NULL
;
927 pd
->lpfnPagePaintHook
= NULL
;
928 pd
->hPageSetupTemplate
= NULL
;
929 pd
->lpPageSetupTemplateName
= NULL
;
934 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
935 memset(devMode, 0, sizeof(DEVMODE));
936 devMode->dmSize = sizeof(DEVMODE);
937 devMode->dmOrientation = m_orientation;
938 devMode->dmFields = DM_ORIENTATION;
939 GlobalUnlock(pd->hDevMode);
945 bool wxWindowsPageSetupDialog::ConvertFromNative( wxPageSetupDialogData
&data
)
947 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
951 wxWindowsPrintNativeData
*native_data
=
952 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
954 // Pass the devmode data back to the wxPrintData structure where it really belongs.
957 if (native_data
->GetDevMode())
959 // Make sure we don't leak memory
960 GlobalFree((HGLOBAL
) native_data
->GetDevMode());
962 native_data
->SetDevMode( (void*) pd
->hDevMode
);
966 // Isn't this superfluous? It's called again below.
967 // data.GetPrintData().ConvertFromNative();
969 // Pass the devnames data back to the wxPrintData structure where it really belongs.
972 if (native_data
->GetDevNames())
974 // Make sure we don't leak memory
975 GlobalFree((HGLOBAL
) native_data
->GetDevNames());
977 native_data
->SetDevNames((void*) pd
->hDevNames
);
978 pd
->hDevNames
= NULL
;
981 data
.GetPrintData().ConvertFromNative();
983 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
985 data
.SetDefaultMinMargins( ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
) );
986 data
.EnableMargins( ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
) );
987 data
.EnableOrientation( ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
) );
988 data
.EnablePaper( ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
) );
989 data
.EnablePrinter( ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
) );
990 data
.SetDefaultInfo( ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
) );
991 data
.EnableHelp( ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
) );
993 // PAGESETUPDLG is in hundreds of a mm
994 data
.SetPaperSize( wxSize(pd
->ptPaperSize
.x
/ 100, pd
->ptPaperSize
.y
/ 100) );
996 data
.SetMinMarginTopLeft( wxPoint(pd
->rtMinMargin
.left
/ 100, pd
->rtMinMargin
.top
/ 100) );
997 data
.SetMinMarginBottomRight( wxPoint(pd
->rtMinMargin
.right
/ 100, pd
->rtMinMargin
.bottom
/ 100) );
999 data
.SetMarginTopLeft( wxPoint(pd
->rtMargin
.left
/ 100, pd
->rtMargin
.top
/ 100) );
1000 data
.SetMarginBottomRight( wxPoint(pd
->rtMargin
.right
/ 100, pd
->rtMargin
.bottom
/ 100) );
1006 // wxUSE_PRINTING_ARCHITECTURE