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/dcprint.h"
46 #include "wx/msw/private.h"
54 //----------------------------------------------------------------------------
55 // wxWindowsPrintNativeData
56 //----------------------------------------------------------------------------
59 static wxString
wxGetPrintDlgError()
61 DWORD err
= CommDlgExtendedError();
62 wxString msg
= wxT("Unknown");
65 case CDERR_FINDRESFAILURE
: msg
= wxT("CDERR_FINDRESFAILURE"); break;
66 case CDERR_INITIALIZATION
: msg
= wxT("CDERR_INITIALIZATION"); break;
67 case CDERR_LOADRESFAILURE
: msg
= wxT("CDERR_LOADRESFAILURE"); break;
68 case CDERR_LOADSTRFAILURE
: msg
= wxT("CDERR_LOADSTRFAILURE"); break;
69 case CDERR_LOCKRESFAILURE
: msg
= wxT("CDERR_LOCKRESFAILURE"); break;
70 case CDERR_MEMALLOCFAILURE
: msg
= wxT("CDERR_MEMALLOCFAILURE"); break;
71 case CDERR_MEMLOCKFAILURE
: msg
= wxT("CDERR_MEMLOCKFAILURE"); break;
72 case CDERR_NOHINSTANCE
: msg
= wxT("CDERR_NOHINSTANCE"); break;
73 case CDERR_NOHOOK
: msg
= wxT("CDERR_NOHOOK"); break;
74 case CDERR_NOTEMPLATE
: msg
= wxT("CDERR_NOTEMPLATE"); break;
75 case CDERR_STRUCTSIZE
: msg
= wxT("CDERR_STRUCTSIZE"); break;
76 case PDERR_RETDEFFAILURE
: msg
= wxT("PDERR_RETDEFFAILURE"); break;
77 case PDERR_PRINTERNOTFOUND
: msg
= wxT("PDERR_PRINTERNOTFOUND"); break;
78 case PDERR_PARSEFAILURE
: msg
= wxT("PDERR_PARSEFAILURE"); break;
79 case PDERR_NODEVICES
: msg
= wxT("PDERR_NODEVICES"); break;
80 case PDERR_NODEFAULTPRN
: msg
= wxT("PDERR_NODEFAULTPRN"); break;
81 case PDERR_LOADDRVFAILURE
: msg
= wxT("PDERR_LOADDRVFAILURE"); break;
82 case PDERR_INITFAILURE
: msg
= wxT("PDERR_INITFAILURE"); break;
83 case PDERR_GETDEVMODEFAIL
: msg
= wxT("PDERR_GETDEVMODEFAIL"); break;
84 case PDERR_DNDMMISMATCH
: msg
= wxT("PDERR_DNDMMISMATCH"); break;
85 case PDERR_DEFAULTDIFFERENT
: msg
= wxT("PDERR_DEFAULTDIFFERENT"); break;
86 case PDERR_CREATEICFAILURE
: msg
= wxT("PDERR_CREATEICFAILURE"); break;
93 static HGLOBAL
wxCreateDevNames(const wxString
& driverName
, const wxString
& printerName
, const wxString
& portName
)
96 // if (!driverName.IsEmpty() && !printerName.IsEmpty() && !portName.IsEmpty())
97 if (driverName
.IsEmpty() && printerName
.IsEmpty() && portName
.IsEmpty())
102 hDev
= GlobalAlloc(GPTR
, 4*sizeof(WORD
)+
103 ( driverName
.Length() + 1 +
104 printerName
.Length() + 1 +
105 portName
.Length()+1 ) * sizeof(wxChar
) );
106 LPDEVNAMES lpDev
= (LPDEVNAMES
)GlobalLock(hDev
);
107 lpDev
->wDriverOffset
= sizeof(WORD
) * 4 / sizeof(wxChar
);
108 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wDriverOffset
, driverName
);
110 lpDev
->wDeviceOffset
= (WORD
)( lpDev
->wDriverOffset
+
111 driverName
.Length() + 1 );
112 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wDeviceOffset
, printerName
);
114 lpDev
->wOutputOffset
= (WORD
)( lpDev
->wDeviceOffset
+
115 printerName
.Length() + 1 );
116 wxStrcpy((wxChar
*)lpDev
+ lpDev
->wOutputOffset
, portName
);
126 IMPLEMENT_CLASS(wxWindowsPrintNativeData
, wxPrintNativeDataBase
)
128 wxWindowsPrintNativeData::wxWindowsPrintNativeData()
130 m_devMode
= (void*) NULL
;
131 m_devNames
= (void*) NULL
;
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
;
159 LPDEVMODE devMode
= (LPDEVMODE
)GlobalLock(hDevMode
);
162 if (devMode
->dmFields
& DM_ORIENTATION
)
163 data
.SetOrientation( devMode
->dmOrientation
);
166 if (devMode
->dmFields
& DM_COLLATE
)
168 if (devMode
->dmCollate
== DMCOLLATE_TRUE
)
169 data
.SetCollate( true );
171 data
.SetCollate( false );
174 //// Number of copies
175 if (devMode
->dmFields
& DM_COPIES
)
176 data
.SetNoCopies( devMode
->dmCopies
);
178 if (devMode
->dmFields
& DM_DEFAULTSOURCE
)
179 data
.SetBin( (wxPrintBin
)devMode
->dmDefaultSource
);
182 if (devMode
->dmDeviceName
[0] != 0)
183 data
.SetPrinterName( devMode
->dmDeviceName
);
186 if (devMode
->dmFields
& DM_COLOR
)
188 if (devMode
->dmColor
== DMCOLOR_COLOR
)
189 data
.SetColour( true );
191 data
.SetColour( false );
194 data
.SetColour( true );
198 // We don't know size of user defined paper and some buggy drivers
199 // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
200 // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
201 // code wouldn't set m_paperSize correctly.
202 if ((devMode
->dmFields
& DM_PAPERSIZE
) && (devMode
->dmPaperSize
< DMPAPER_USER
))
204 if (wxThePrintPaperDatabase
)
206 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
209 data
.SetPaperId( paper
->GetId() );
210 data
.SetPaperSize( wxSize(paper
->GetWidth() / 10,paper
->GetHeight() / 10) );
214 // Shouldn't really get here
215 wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
216 data
.SetPaperId( wxPAPER_NONE
);
217 data
.SetPaperSize( wxSize(0,0) );
222 // Shouldn't really get here
223 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
224 data
.SetPaperId( wxPAPER_NONE
);
225 data
.SetPaperSize( wxSize(0,0) );
228 else if ((devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
230 // DEVMODE is in tenths of a milimeter
231 data
.SetPaperId( wxPAPER_NONE
);
232 data
.SetPaperSize( wxSize(devMode
->dmPaperWidth
/ 10, devMode
->dmPaperLength
/ 10) );
236 // Shouldn't really get here
237 wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
238 data
.SetPaperId( wxPAPER_NONE
);
239 data
.SetPaperSize( wxSize(0,0) );
244 if (devMode
->dmFields
& DM_DUPLEX
)
246 switch (devMode
->dmDuplex
)
248 case DMDUP_HORIZONTAL
: data
.SetDuplex( wxDUPLEX_HORIZONTAL
); break;
249 case DMDUP_VERTICAL
: data
.SetDuplex( wxDUPLEX_VERTICAL
); break;
251 case DMDUP_SIMPLEX
: data
.SetDuplex( wxDUPLEX_SIMPLEX
); break;
255 data
.SetDuplex( wxDUPLEX_SIMPLEX
);
259 if (devMode
->dmFields
& DM_PRINTQUALITY
)
261 switch (devMode
->dmPrintQuality
)
263 case DMRES_MEDIUM
: data
.SetQuality( wxPRINT_QUALITY_MEDIUM
); break;
264 case DMRES_LOW
: data
.SetQuality( wxPRINT_QUALITY_LOW
); break;
265 case DMRES_DRAFT
: data
.SetQuality( wxPRINT_QUALITY_DRAFT
); break;
266 case DMRES_HIGH
: data
.SetQuality( wxPRINT_QUALITY_HIGH
); break;
269 // TODO: if the printer fills in the resolution in DPI, how
270 // will the application know if it's high, low, draft etc.??
271 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
272 data
.SetQuality( devMode
->dmPrintQuality
);
279 data
.SetQuality( wxPRINT_QUALITY_HIGH
);
281 GlobalUnlock(hDevMode
);
286 LPDEVNAMES lpDevNames
= (LPDEVNAMES
)GlobalLock(hDevNames
);
289 // TODO: Unicode-ification
292 // port is obsolete in WIN32
293 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
295 // Get the printer name
296 wxString printerName
= (LPTSTR
)lpDevNames
+ lpDevNames
->wDeviceOffset
;
298 // Not sure if we should check for this mismatch
299 // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
301 if (printerName
!= wxT(""))
302 data
.SetPrinterName( printerName
);
304 GlobalUnlock(hDevNames
);
311 bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData
&data
)
313 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
314 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
317 // Use PRINTDLG as a way of creating a DEVMODE object
320 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
325 memset(&pd
, 0, sizeof(PRINTDLG
));
327 pd
.cbStruct
= sizeof(PRINTDLG
);
329 pd
.lStructSize
= sizeof(PRINTDLG
);
333 pd
.hwndOwner
= (HWND
)NULL
;
334 pd
.hDevMode
= NULL
; // Will be created by PrintDlg
335 pd
.hDevNames
= NULL
; // Ditto
336 //pd.hInstance = (HINSTANCE) wxGetInstance();
338 pd
.Flags
= PD_RETURNDEFAULT
;
341 // Fill out the DEVMODE structure
342 // so we can use it as input in the 'real' PrintDlg
346 GlobalFree(pd
.hDevMode
);
348 GlobalFree(pd
.hDevNames
);
352 #if defined(__WXDEBUG__) && defined(__WIN32__)
353 wxString
str(wxT("Printing error: "));
354 str
+= wxGetPrintDlgError();
360 hDevMode
= pd
.hDevMode
;
361 m_devMode
= (void*)(long) hDevMode
;
364 // We'll create a new DEVNAMEs structure below.
366 GlobalFree(pd
.hDevNames
);
369 // hDevNames = pd->hDevNames;
370 // m_devNames = (void*)(long) hDevNames;
371 // pd->hDevnames = NULL;
378 LPDEVMODE devMode
= (LPDEVMODE
) GlobalLock(hDevMode
);
381 devMode
->dmOrientation
= (short)data
.GetOrientation();
384 devMode
->dmCollate
= (data
.GetCollate() ? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
385 devMode
->dmFields
|= DM_COLLATE
;
387 //// Number of copies
388 devMode
->dmCopies
= (short)data
.GetNoCopies();
389 devMode
->dmFields
|= DM_COPIES
;
392 wxString name
= data
.GetPrinterName();
395 //int len = wxMin(31, m_printerName.Len());
396 wxStrncpy((wxChar
*)devMode
->dmDeviceName
,name
.c_str(),31);
397 devMode
->dmDeviceName
[31] = wxT('\0');
401 if (data
.GetColour())
402 devMode
->dmColor
= DMCOLOR_COLOR
;
404 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
405 devMode
->dmFields
|= DM_COLOR
;
408 if (data
.GetPaperId() == wxPAPER_NONE
)
410 // DEVMODE is in tenths of a milimeter
411 devMode
->dmPaperWidth
= (short)(data
.GetPaperSize().x
* 10);
412 devMode
->dmPaperLength
= (short)(data
.GetPaperSize().y
* 10);
413 devMode
->dmPaperSize
= DMPAPER_USER
;
414 devMode
->dmFields
|= DM_PAPERWIDTH
;
415 devMode
->dmFields
|= DM_PAPERLENGTH
;
419 if (wxThePrintPaperDatabase
)
421 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType( data
.GetPaperId() );
424 devMode
->dmPaperSize
= (short)paper
->GetPlatformId();
425 devMode
->dmFields
|= DM_PAPERSIZE
;
432 switch (data
.GetDuplex())
434 case wxDUPLEX_HORIZONTAL
:
435 duplex
= DMDUP_HORIZONTAL
;
437 case wxDUPLEX_VERTICAL
:
438 duplex
= DMDUP_VERTICAL
;
441 // in fact case wxDUPLEX_SIMPLEX:
442 duplex
= DMDUP_SIMPLEX
;
445 devMode
->dmDuplex
= duplex
;
446 devMode
->dmFields
|= DM_DUPLEX
;
451 switch (data
.GetQuality())
453 case wxPRINT_QUALITY_MEDIUM
:
454 quality
= DMRES_MEDIUM
;
456 case wxPRINT_QUALITY_LOW
:
459 case wxPRINT_QUALITY_DRAFT
:
460 quality
= DMRES_DRAFT
;
462 case wxPRINT_QUALITY_HIGH
:
463 quality
= DMRES_HIGH
;
466 quality
= (short)data
.GetQuality();
469 devMode
->dmPrintQuality
= quality
;
470 devMode
->dmFields
|= DM_PRINTQUALITY
;
472 if (data
.GetBin() != wxPRINTBIN_DEFAULT
)
474 switch (data
.GetBin())
476 case wxPRINTBIN_ONLYONE
: devMode
->dmDefaultSource
= DMBIN_ONLYONE
; break;
477 case wxPRINTBIN_LOWER
: devMode
->dmDefaultSource
= DMBIN_LOWER
; break;
478 case wxPRINTBIN_MIDDLE
: devMode
->dmDefaultSource
= DMBIN_MIDDLE
; break;
479 case wxPRINTBIN_MANUAL
: devMode
->dmDefaultSource
= DMBIN_MANUAL
; break;
480 case wxPRINTBIN_ENVELOPE
: devMode
->dmDefaultSource
= DMBIN_ENVELOPE
; break;
481 case wxPRINTBIN_ENVMANUAL
: devMode
->dmDefaultSource
= DMBIN_ENVMANUAL
; break;
482 case wxPRINTBIN_AUTO
: devMode
->dmDefaultSource
= DMBIN_AUTO
; break;
483 case wxPRINTBIN_TRACTOR
: devMode
->dmDefaultSource
= DMBIN_TRACTOR
; break;
484 case wxPRINTBIN_SMALLFMT
: devMode
->dmDefaultSource
= DMBIN_SMALLFMT
; break;
485 case wxPRINTBIN_LARGEFMT
: devMode
->dmDefaultSource
= DMBIN_LARGEFMT
; break;
486 case wxPRINTBIN_LARGECAPACITY
: devMode
->dmDefaultSource
= DMBIN_LARGECAPACITY
; break;
487 case wxPRINTBIN_CASSETTE
: devMode
->dmDefaultSource
= DMBIN_CASSETTE
; break;
488 case wxPRINTBIN_FORMSOURCE
: devMode
->dmDefaultSource
= DMBIN_FORMSOURCE
; break;
491 devMode
->dmDefaultSource
= (short)(DMBIN_USER
+ data
.GetBin() - wxPRINTBIN_USER
);
495 devMode
->dmFields
|= DM_DEFAULTSOURCE
;
498 GlobalUnlock(hDevMode
);
503 GlobalFree(hDevNames
);
506 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
507 m_devNames
= (void*) (long) wxCreateDevNames(wxT(""), data
.GetPrinterName(), wxT(""));
512 // ---------------------------------------------------------------------------
514 // ---------------------------------------------------------------------------
516 IMPLEMENT_CLASS(wxWindowsPrintDialog
, wxPrintDialogBase
)
518 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintDialogData
* data
)
523 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintData
* data
)
525 wxPrintDialogData data2
;
532 bool wxWindowsPrintDialog::Create(wxWindow
*p
, wxPrintDialogData
* data
)
542 m_printDialogData
= *data
;
547 wxWindowsPrintDialog::~wxWindowsPrintDialog()
549 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
550 if (pd
&& pd
->hDevMode
)
551 GlobalFree(pd
->hDevMode
);
555 if (m_destroyDC
&& m_printerDC
)
559 int wxWindowsPrintDialog::ShowModal()
561 ConvertToNative( m_printDialogData
);
563 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
566 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
567 else if (wxTheApp
->GetTopWindow())
568 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
572 bool ret
= (PrintDlg( pd
) != 0);
576 if ( ret
!= false && (pd
->hDC
) )
578 wxPrinterDC
*pdc
= new wxPrinterDC( (WXHDC
) pd
->hDC
);
580 ConvertFromNative( m_printDialogData
);
589 wxDC
*wxWindowsPrintDialog::GetPrintDC()
600 bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData
&data
)
602 wxWindowsPrintNativeData
*native_data
=
603 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
604 data
.GetPrintData().ConvertToNative();
606 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
608 // Shouldn't have been defined anywhere
613 memset( pd
, 0, sizeof(PRINTDLG
) );
614 m_printDlg
= (void*) pd
;
616 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
618 pd
->lStructSize
= 66;
620 pd
->lStructSize
= sizeof(PRINTDLG
);
622 pd
->hwndOwner
= (HWND
)NULL
;
623 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
624 pd
->hDevNames
= NULL
; // Ditto
626 pd
->Flags
= PD_RETURNDEFAULT
;
629 // Pass the devmode data to the PRINTDLG structure, since it'll
630 // be needed when PrintDlg is called.
632 GlobalFree(pd
->hDevMode
);
634 // Pass the devnames data to the PRINTDLG structure, since it'll
635 // be needed when PrintDlg is called.
637 GlobalFree(pd
->hDevNames
);
639 pd
->hDevMode
= (HGLOBAL
)(DWORD
) native_data
->GetDevMode();
640 native_data
->SetDevMode( (void*) NULL
);
642 // Shouldn't assert; we should be able to test Ok-ness at a higher level
643 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
645 pd
->hDevNames
= (HGLOBAL
)(DWORD
) native_data
->GetDevNames();
646 native_data
->SetDevNames( (void*) NULL
);
649 pd
->hDC
= (HDC
) NULL
;
650 pd
->nFromPage
= (WORD
)data
.GetFromPage();
651 pd
->nToPage
= (WORD
)data
.GetToPage();
652 pd
->nMinPage
= (WORD
)data
.GetMinPage();
653 pd
->nMaxPage
= (WORD
)data
.GetMaxPage();
654 pd
->nCopies
= (WORD
)data
.GetNoCopies();
656 pd
->Flags
= PD_RETURNDC
;
659 pd
->lStructSize
= 66;
661 pd
->lStructSize
= sizeof( PRINTDLG
);
664 pd
->hwndOwner
=(HWND
)NULL
;
665 // pd->hDevNames=(HANDLE)NULL;
666 pd
->hInstance
=(HINSTANCE
)NULL
;
667 pd
->lCustData
= (LPARAM
) NULL
;
668 pd
->lpfnPrintHook
= NULL
;
669 pd
->lpfnSetupHook
= NULL
;
670 pd
->lpPrintTemplateName
= NULL
;
671 pd
->lpSetupTemplateName
= NULL
;
672 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
673 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
675 if ( data
.GetAllPages() )
676 pd
->Flags
|= PD_ALLPAGES
;
677 if ( data
.GetSelection() )
678 pd
->Flags
|= PD_SELECTION
;
679 if ( data
.GetCollate() )
680 pd
->Flags
|= PD_COLLATE
;
681 if ( data
.GetPrintToFile() )
682 pd
->Flags
|= PD_PRINTTOFILE
;
683 if ( !data
.GetEnablePrintToFile() )
684 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
685 if ( !data
.GetEnableSelection() )
686 pd
->Flags
|= PD_NOSELECTION
;
687 if ( !data
.GetEnablePageNumbers() )
688 pd
->Flags
|= PD_NOPAGENUMS
;
689 else if ( (!data
.GetAllPages()) && (!data
.GetSelection()) && (data
.GetFromPage() != 0) && (data
.GetToPage() != 0))
690 pd
->Flags
|= PD_PAGENUMS
;
691 if ( data
.GetEnableHelp() )
692 pd
->Flags
|= PD_SHOWHELP
;
693 #if WXWIN_COMPATIBILITY_2_4
694 if ( data
.GetSetupDialog() )
695 pd
->Flags
|= PD_PRINTSETUP
;
701 bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData
&data
)
703 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
707 wxWindowsPrintNativeData
*native_data
=
708 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
710 // Pass the devmode data back to the wxPrintData structure where it really belongs.
713 if (native_data
->GetDevMode())
715 // Make sure we don't leak memory
716 GlobalFree( (HGLOBAL
)(DWORD
) native_data
->GetDevMode() );
718 native_data
->SetDevMode( (void*)(long) pd
->hDevMode
);
722 // Pass the devnames data back to the wxPrintData structure where it really belongs.
725 if (native_data
->GetDevNames())
727 // Make sure we don't leak memory
728 GlobalFree((HGLOBAL
)(DWORD
) native_data
->GetDevNames());
730 native_data
->SetDevNames((void*)(long) pd
->hDevNames
);
731 pd
->hDevNames
= NULL
;
734 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
735 // into wxWidgets form.
736 native_data
->TransferTo( data
.GetPrintData() );
738 data
.SetFromPage( pd
->nFromPage
);
739 data
.SetToPage( pd
->nToPage
);
740 data
.SetMinPage( pd
->nMinPage
);
741 data
.SetMaxPage( pd
->nMaxPage
);
742 data
.SetNoCopies( pd
->nCopies
);
744 data
.SetAllPages( (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
)) );
745 data
.SetSelection( ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
) );
746 data
.SetCollate( ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
) );
747 data
.SetPrintToFile( ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
) );
748 data
.EnablePrintToFile( ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
) );
749 data
.EnableSelection( ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
) );
750 data
.EnablePageNumbers( ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
) );
751 data
.EnableHelp( ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
) );
752 #if WXWIN_COMPATIBILITY_2_4
753 data
.SetSetupDialog( ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
) );
758 // ---------------------------------------------------------------------------
760 // ---------------------------------------------------------------------------
762 IMPLEMENT_CLASS(wxPageSetupDialog
, wxDialog
)
764 wxPageSetupDialog::wxPageSetupDialog()
766 m_dialogParent
= NULL
;
770 wxPageSetupDialog::wxPageSetupDialog(wxWindow
*p
, wxPageSetupDialogData
*data
)
775 bool wxPageSetupDialog::Create(wxWindow
*p
, wxPageSetupDialogData
*data
)
781 m_pageSetupData
= (*data
);
786 wxPageSetupDialog::~wxPageSetupDialog()
788 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageDlg
;
789 if ( pd
&& pd
->hDevMode
)
790 GlobalFree(pd
->hDevMode
);
791 if ( pd
&& pd
->hDevNames
)
792 GlobalFree(pd
->hDevNames
);
797 int wxPageSetupDialog::ShowModal()
799 ConvertToNative( m_pageSetupData
);
801 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
803 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
804 else if (wxTheApp
->GetTopWindow())
805 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
808 BOOL retVal
= PageSetupDlg( pd
) ;
812 ConvertFromNative( m_pageSetupData
);
819 bool wxPageSetupDialog::ConvertToNative( wxPageSetupDialogData
&data
)
821 wxWindowsPrintNativeData
*native_data
=
822 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
823 data
.GetPrintData().ConvertToNative();
825 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
827 // Shouldn't have been defined anywhere
831 pd
= new PAGESETUPDLG
;
833 pd
->hDevNames
= NULL
;
834 m_pageDlg
= (void *)pd
;
836 // Pass the devmode data (created in m_printData.ConvertToNative)
837 // to the PRINTDLG structure, since it'll
838 // be needed when PrintDlg is called.
842 GlobalFree(pd
->hDevMode
);
845 pd
->hDevMode
= (HGLOBAL
) native_data
->GetDevMode();
846 native_data
->SetDevMode( (void*) NULL
);
848 // Shouldn't assert; we should be able to test Ok-ness at a higher level
849 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
851 // Pass the devnames data (created in m_printData.ConvertToNative)
852 // to the PRINTDLG structure, since it'll
853 // be needed when PrintDlg is called.
857 GlobalFree(pd
->hDevNames
);
858 pd
->hDevNames
= NULL
;
860 pd
->hDevNames
= (HGLOBAL
) native_data
->GetDevNames();
861 native_data
->SetDevNames((void*) NULL
);
863 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
865 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
867 if ( data
.GetDefaultMinMargins() )
868 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
869 if ( !data
.GetEnableMargins() )
870 pd
->Flags
|= PSD_DISABLEMARGINS
;
871 if ( !data
.GetEnableOrientation() )
872 pd
->Flags
|= PSD_DISABLEORIENTATION
;
873 if ( !data
.GetEnablePaper() )
874 pd
->Flags
|= PSD_DISABLEPAPER
;
875 if ( !data
.GetEnablePrinter() )
876 pd
->Flags
|= PSD_DISABLEPRINTER
;
877 if ( data
.GetDefaultInfo() )
878 pd
->Flags
|= PSD_RETURNDEFAULT
;
879 if ( data
.GetEnableHelp() )
880 pd
->Flags
|= PSD_SHOWHELP
;
882 // We want the units to be in hundredths of a millimetre
883 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
885 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
886 pd
->hwndOwner
=(HWND
)NULL
;
887 // pd->hDevNames=(HWND)NULL;
888 pd
->hInstance
=(HINSTANCE
)NULL
;
889 // PAGESETUPDLG is in hundreds of a mm
890 pd
->ptPaperSize
.x
= data
.GetPaperSize().x
* 100;
891 pd
->ptPaperSize
.y
= data
.GetPaperSize().y
* 100;
893 pd
->rtMinMargin
.left
= data
.GetMinMarginTopLeft().x
* 100;
894 pd
->rtMinMargin
.top
= data
.GetMinMarginTopLeft().y
* 100;
895 pd
->rtMinMargin
.right
= data
.GetMinMarginBottomRight().x
* 100;
896 pd
->rtMinMargin
.bottom
= data
.GetMinMarginBottomRight().y
* 100;
898 pd
->rtMargin
.left
= data
.GetMarginTopLeft().x
* 100;
899 pd
->rtMargin
.top
= data
.GetMarginTopLeft().y
* 100;
900 pd
->rtMargin
.right
= data
.GetMarginBottomRight().x
* 100;
901 pd
->rtMargin
.bottom
= data
.GetMarginBottomRight().y
* 100;
904 pd
->lpfnPageSetupHook
= NULL
;
905 pd
->lpfnPagePaintHook
= NULL
;
906 pd
->hPageSetupTemplate
= NULL
;
907 pd
->lpPageSetupTemplateName
= NULL
;
912 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
913 memset(devMode, 0, sizeof(DEVMODE));
914 devMode->dmSize = sizeof(DEVMODE);
915 devMode->dmOrientation = m_orientation;
916 devMode->dmFields = DM_ORIENTATION;
917 GlobalUnlock(pd->hDevMode);
923 bool wxPageSetupDialog::ConvertFromNative( wxPageSetupDialogData
&data
)
925 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
929 wxWindowsPrintNativeData
*native_data
=
930 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
932 // Pass the devmode data back to the wxPrintData structure where it really belongs.
935 if (native_data
->GetDevMode())
937 // Make sure we don't leak memory
938 GlobalFree((HGLOBAL
) native_data
->GetDevMode());
940 native_data
->SetDevMode( (void*) pd
->hDevMode
);
944 // Isn't this superfluous? It's called again below.
945 // data.GetPrintData().ConvertFromNative();
947 // Pass the devnames data back to the wxPrintData structure where it really belongs.
950 if (native_data
->GetDevNames())
952 // Make sure we don't leak memory
953 GlobalFree((HGLOBAL
) native_data
->GetDevNames());
955 native_data
->SetDevNames((void*) pd
->hDevNames
);
956 pd
->hDevNames
= NULL
;
959 data
.GetPrintData().ConvertFromNative();
961 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
963 data
.SetDefaultMinMargins( ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
) );
964 data
.EnableMargins( ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
) );
965 data
.EnableOrientation( ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
) );
966 data
.EnablePaper( ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
) );
967 data
.EnablePrinter( ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
) );
968 data
.SetDefaultInfo( ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
) );
969 data
.EnableHelp( ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
) );
971 // PAGESETUPDLG is in hundreds of a mm
972 data
.SetPaperSize( wxSize(pd
->ptPaperSize
.x
/ 100, pd
->ptPaperSize
.y
/ 100) );
974 data
.SetMinMarginTopLeft( wxPoint(pd
->rtMinMargin
.left
/ 100, pd
->rtMinMargin
.top
/ 100) );
975 data
.SetMinMarginBottomRight( wxPoint(pd
->rtMinMargin
.right
/ 100, pd
->rtMinMargin
.bottom
/ 100) );
977 data
.SetMarginTopLeft( wxPoint(pd
->rtMargin
.left
/ 100, pd
->rtMargin
.top
/ 100) );
978 data
.SetMarginBottomRight( wxPoint(pd
->rtMargin
.right
/ 100, pd
->rtMargin
.bottom
/ 100) );
984 // wxUSE_PRINTING_ARCHITECTURE