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
;
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.
203 bool foundPaperSize
= false;
204 if ((devMode
->dmFields
& DM_PAPERSIZE
) && (devMode
->dmPaperSize
< DMPAPER_USER
))
206 if (wxThePrintPaperDatabase
)
208 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperTypeByPlatformId(devMode
->dmPaperSize
);
211 data
.SetPaperId( paper
->GetId() );
212 data
.SetPaperSize( wxSize(paper
->GetWidth() / 10,paper
->GetHeight() / 10) );
213 m_customWindowsPaperId
= 0;
214 foundPaperSize
= true;
219 // Shouldn't really get here
220 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
221 data
.SetPaperId( wxPAPER_NONE
);
222 data
.SetPaperSize( wxSize(0,0) );
223 m_customWindowsPaperId
= 0;
225 GlobalUnlock(hDevMode
);
230 if (!foundPaperSize
&& (devMode
->dmFields
& DM_PAPERWIDTH
) && (devMode
->dmFields
& DM_PAPERLENGTH
))
232 // DEVMODE is in tenths of a milimeter
233 data
.SetPaperSize( wxSize(devMode
->dmPaperWidth
/ 10, devMode
->dmPaperLength
/ 10) );
234 data
.SetPaperId( wxPAPER_NONE
);
235 m_customWindowsPaperId
= devMode
->dmPaperSize
;
239 // Often will reach this for non-standard paper sizes (sizes which
240 // wouldn't be in wxWidget's paper database). Setting
241 // m_customWindowsPaperId to devMode->dmPaperSize should be enough
242 // to get this paper size working.
243 data
.SetPaperSize( wxSize(0,0) );
244 data
.SetPaperId( wxPAPER_NONE
);
245 m_customWindowsPaperId
= devMode
->dmPaperSize
;
250 if (devMode
->dmFields
& DM_DUPLEX
)
252 switch (devMode
->dmDuplex
)
254 case DMDUP_HORIZONTAL
: data
.SetDuplex( wxDUPLEX_HORIZONTAL
); break;
255 case DMDUP_VERTICAL
: data
.SetDuplex( wxDUPLEX_VERTICAL
); break;
257 case DMDUP_SIMPLEX
: data
.SetDuplex( wxDUPLEX_SIMPLEX
); break;
261 data
.SetDuplex( wxDUPLEX_SIMPLEX
);
265 if (devMode
->dmFields
& DM_PRINTQUALITY
)
267 switch (devMode
->dmPrintQuality
)
269 case DMRES_MEDIUM
: data
.SetQuality( wxPRINT_QUALITY_MEDIUM
); break;
270 case DMRES_LOW
: data
.SetQuality( wxPRINT_QUALITY_LOW
); break;
271 case DMRES_DRAFT
: data
.SetQuality( wxPRINT_QUALITY_DRAFT
); break;
272 case DMRES_HIGH
: data
.SetQuality( wxPRINT_QUALITY_HIGH
); break;
275 // TODO: if the printer fills in the resolution in DPI, how
276 // will the application know if it's high, low, draft etc.??
277 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
278 data
.SetQuality( devMode
->dmPrintQuality
);
285 data
.SetQuality( wxPRINT_QUALITY_HIGH
);
287 if (devMode
->dmDriverExtra
> 0)
288 data
.SetPrivData( (char *)devMode
+devMode
->dmSize
, devMode
->dmDriverExtra
);
290 data
.SetPrivData( NULL
, 0 );
292 GlobalUnlock(hDevMode
);
297 LPDEVNAMES lpDevNames
= (LPDEVNAMES
)GlobalLock(hDevNames
);
300 // TODO: Unicode-ification
303 // port is obsolete in WIN32
304 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
306 // Get the printer name
307 wxString printerName
= (LPTSTR
)lpDevNames
+ lpDevNames
->wDeviceOffset
;
309 // Not sure if we should check for this mismatch
310 // wxASSERT_MSG( (m_printerName.empty() || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
312 if (!printerName
.empty())
313 data
.SetPrinterName( printerName
);
315 GlobalUnlock(hDevNames
);
322 bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData
&data
)
324 HGLOBAL hDevMode
= (HGLOBAL
)(DWORD
) m_devMode
;
325 HGLOBAL hDevNames
= (HGLOBAL
)(DWORD
) m_devNames
;
328 // Use PRINTDLG as a way of creating a DEVMODE object
331 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
336 memset(&pd
, 0, sizeof(PRINTDLG
));
338 pd
.cbStruct
= sizeof(PRINTDLG
);
340 pd
.lStructSize
= sizeof(PRINTDLG
);
344 pd
.hwndOwner
= (HWND
)NULL
;
345 pd
.hDevMode
= NULL
; // Will be created by PrintDlg
346 pd
.hDevNames
= NULL
; // Ditto
347 //pd.hInstance = (HINSTANCE) wxGetInstance();
349 pd
.Flags
= PD_RETURNDEFAULT
;
352 // Fill out the DEVMODE structure
353 // so we can use it as input in the 'real' PrintDlg
357 GlobalFree(pd
.hDevMode
);
359 GlobalFree(pd
.hDevNames
);
363 #if defined(__WXDEBUG__) && defined(__WIN32__)
364 wxString
str(wxT("Printing error: "));
365 str
+= wxGetPrintDlgError();
371 hDevMode
= pd
.hDevMode
;
372 m_devMode
= (void*)(long) hDevMode
;
375 // We'll create a new DEVNAMEs structure below.
377 GlobalFree(pd
.hDevNames
);
380 // hDevNames = pd->hDevNames;
381 // m_devNames = (void*)(long) hDevNames;
382 // pd->hDevnames = NULL;
389 LPDEVMODE devMode
= (LPDEVMODE
) GlobalLock(hDevMode
);
392 devMode
->dmOrientation
= (short)data
.GetOrientation();
395 devMode
->dmCollate
= (data
.GetCollate() ? DMCOLLATE_TRUE
: DMCOLLATE_FALSE
);
396 devMode
->dmFields
|= DM_COLLATE
;
398 //// Number of copies
399 devMode
->dmCopies
= (short)data
.GetNoCopies();
400 devMode
->dmFields
|= DM_COPIES
;
403 wxString name
= data
.GetPrinterName();
406 //int len = wxMin(31, m_printerName.Len());
407 wxStrncpy((wxChar
*)devMode
->dmDeviceName
,name
.c_str(),31);
408 devMode
->dmDeviceName
[31] = wxT('\0');
412 if (data
.GetColour())
413 devMode
->dmColor
= DMCOLOR_COLOR
;
415 devMode
->dmColor
= DMCOLOR_MONOCHROME
;
416 devMode
->dmFields
|= DM_COLOR
;
419 if (data
.GetPaperId() == wxPAPER_NONE
)
421 // DEVMODE is in tenths of a milimeter
422 devMode
->dmPaperWidth
= (short)(data
.GetPaperSize().x
* 10);
423 devMode
->dmPaperLength
= (short)(data
.GetPaperSize().y
* 10);
424 if(m_customWindowsPaperId
!= 0)
425 devMode
->dmPaperSize
= m_customWindowsPaperId
;
427 devMode
->dmPaperSize
= DMPAPER_USER
;
428 devMode
->dmFields
|= DM_PAPERWIDTH
;
429 devMode
->dmFields
|= DM_PAPERLENGTH
;
433 if (wxThePrintPaperDatabase
)
435 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType( data
.GetPaperId() );
438 devMode
->dmPaperSize
= (short)paper
->GetPlatformId();
439 devMode
->dmFields
|= DM_PAPERSIZE
;
443 // Fall back on specifying the paper size explicitly
444 devMode
->dmPaperWidth
= (short)(data
.GetPaperSize().x
* 10);
445 devMode
->dmPaperLength
= (short)(data
.GetPaperSize().y
* 10);
446 devMode
->dmPaperSize
= DMPAPER_USER
;
447 devMode
->dmFields
|= DM_PAPERWIDTH
;
448 devMode
->dmFields
|= DM_PAPERLENGTH
;
455 switch (data
.GetDuplex())
457 case wxDUPLEX_HORIZONTAL
:
458 duplex
= DMDUP_HORIZONTAL
;
460 case wxDUPLEX_VERTICAL
:
461 duplex
= DMDUP_VERTICAL
;
464 // in fact case wxDUPLEX_SIMPLEX:
465 duplex
= DMDUP_SIMPLEX
;
468 devMode
->dmDuplex
= duplex
;
469 devMode
->dmFields
|= DM_DUPLEX
;
474 switch (data
.GetQuality())
476 case wxPRINT_QUALITY_MEDIUM
:
477 quality
= DMRES_MEDIUM
;
479 case wxPRINT_QUALITY_LOW
:
482 case wxPRINT_QUALITY_DRAFT
:
483 quality
= DMRES_DRAFT
;
485 case wxPRINT_QUALITY_HIGH
:
486 quality
= DMRES_HIGH
;
489 quality
= (short)data
.GetQuality();
492 devMode
->dmPrintQuality
= quality
;
493 devMode
->dmFields
|= DM_PRINTQUALITY
;
495 if (data
.GetPrivDataLen() > 0)
497 memcpy( (char *)devMode
+devMode
->dmSize
, data
.GetPrivData(), data
.GetPrivDataLen() );
498 devMode
->dmDriverExtra
= (WXWORD
)data
.GetPrivDataLen();
501 if (data
.GetBin() != wxPRINTBIN_DEFAULT
)
503 switch (data
.GetBin())
505 case wxPRINTBIN_ONLYONE
: devMode
->dmDefaultSource
= DMBIN_ONLYONE
; break;
506 case wxPRINTBIN_LOWER
: devMode
->dmDefaultSource
= DMBIN_LOWER
; break;
507 case wxPRINTBIN_MIDDLE
: devMode
->dmDefaultSource
= DMBIN_MIDDLE
; break;
508 case wxPRINTBIN_MANUAL
: devMode
->dmDefaultSource
= DMBIN_MANUAL
; break;
509 case wxPRINTBIN_ENVELOPE
: devMode
->dmDefaultSource
= DMBIN_ENVELOPE
; break;
510 case wxPRINTBIN_ENVMANUAL
: devMode
->dmDefaultSource
= DMBIN_ENVMANUAL
; break;
511 case wxPRINTBIN_AUTO
: devMode
->dmDefaultSource
= DMBIN_AUTO
; break;
512 case wxPRINTBIN_TRACTOR
: devMode
->dmDefaultSource
= DMBIN_TRACTOR
; break;
513 case wxPRINTBIN_SMALLFMT
: devMode
->dmDefaultSource
= DMBIN_SMALLFMT
; break;
514 case wxPRINTBIN_LARGEFMT
: devMode
->dmDefaultSource
= DMBIN_LARGEFMT
; break;
515 case wxPRINTBIN_LARGECAPACITY
: devMode
->dmDefaultSource
= DMBIN_LARGECAPACITY
; break;
516 case wxPRINTBIN_CASSETTE
: devMode
->dmDefaultSource
= DMBIN_CASSETTE
; break;
517 case wxPRINTBIN_FORMSOURCE
: devMode
->dmDefaultSource
= DMBIN_FORMSOURCE
; break;
520 devMode
->dmDefaultSource
= (short)(DMBIN_USER
+ data
.GetBin() - wxPRINTBIN_USER
);
524 devMode
->dmFields
|= DM_DEFAULTSOURCE
;
527 GlobalUnlock(hDevMode
);
532 GlobalFree(hDevNames
);
535 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
536 m_devNames
= (void*) (long) wxCreateDevNames(wxEmptyString
, data
.GetPrinterName(), wxEmptyString
);
541 // ---------------------------------------------------------------------------
543 // ---------------------------------------------------------------------------
545 IMPLEMENT_CLASS(wxWindowsPrintDialog
, wxPrintDialogBase
)
547 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintDialogData
* data
)
552 wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow
*p
, wxPrintData
* data
)
554 wxPrintDialogData data2
;
561 bool wxWindowsPrintDialog::Create(wxWindow
*p
, wxPrintDialogData
* data
)
571 m_printDialogData
= *data
;
576 wxWindowsPrintDialog::~wxWindowsPrintDialog()
578 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
579 if (pd
&& pd
->hDevMode
)
580 GlobalFree(pd
->hDevMode
);
584 if (m_destroyDC
&& m_printerDC
)
588 int wxWindowsPrintDialog::ShowModal()
590 ConvertToNative( m_printDialogData
);
592 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
595 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
596 else if (wxTheApp
->GetTopWindow())
597 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
601 bool ret
= (PrintDlg( pd
) != 0);
605 if ( ret
!= false && (pd
->hDC
) )
607 wxPrinterDC
*pdc
= new wxPrinterDC( (WXHDC
) pd
->hDC
);
609 ConvertFromNative( m_printDialogData
);
618 wxDC
*wxWindowsPrintDialog::GetPrintDC()
629 bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData
&data
)
631 wxWindowsPrintNativeData
*native_data
=
632 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
633 data
.GetPrintData().ConvertToNative();
635 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
637 // Shouldn't have been defined anywhere
642 memset( pd
, 0, sizeof(PRINTDLG
) );
643 m_printDlg
= (void*) pd
;
645 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
647 pd
->lStructSize
= 66;
649 pd
->lStructSize
= sizeof(PRINTDLG
);
651 pd
->hwndOwner
= (HWND
)NULL
;
652 pd
->hDevMode
= NULL
; // Will be created by PrintDlg
653 pd
->hDevNames
= NULL
; // Ditto
655 pd
->Flags
= PD_RETURNDEFAULT
;
658 // Pass the devmode data to the PRINTDLG structure, since it'll
659 // be needed when PrintDlg is called.
661 GlobalFree(pd
->hDevMode
);
663 // Pass the devnames data to the PRINTDLG structure, since it'll
664 // be needed when PrintDlg is called.
666 GlobalFree(pd
->hDevNames
);
668 pd
->hDevMode
= (HGLOBAL
)(DWORD
) native_data
->GetDevMode();
669 native_data
->SetDevMode( (void*) NULL
);
671 // Shouldn't assert; we should be able to test Ok-ness at a higher level
672 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
674 pd
->hDevNames
= (HGLOBAL
)(DWORD
) native_data
->GetDevNames();
675 native_data
->SetDevNames( (void*) NULL
);
678 pd
->hDC
= (HDC
) NULL
;
679 pd
->nFromPage
= (WORD
)data
.GetFromPage();
680 pd
->nToPage
= (WORD
)data
.GetToPage();
681 pd
->nMinPage
= (WORD
)data
.GetMinPage();
682 pd
->nMaxPage
= (WORD
)data
.GetMaxPage();
683 pd
->nCopies
= (WORD
)data
.GetNoCopies();
685 pd
->Flags
= PD_RETURNDC
;
688 pd
->lStructSize
= 66;
690 pd
->lStructSize
= sizeof( PRINTDLG
);
693 pd
->hwndOwner
=(HWND
)NULL
;
694 // pd->hDevNames=(HANDLE)NULL;
695 pd
->hInstance
=(HINSTANCE
)NULL
;
696 pd
->lCustData
= (LPARAM
) NULL
;
697 pd
->lpfnPrintHook
= NULL
;
698 pd
->lpfnSetupHook
= NULL
;
699 pd
->lpPrintTemplateName
= NULL
;
700 pd
->lpSetupTemplateName
= NULL
;
701 pd
->hPrintTemplate
= (HGLOBAL
) NULL
;
702 pd
->hSetupTemplate
= (HGLOBAL
) NULL
;
704 if ( data
.GetAllPages() )
705 pd
->Flags
|= PD_ALLPAGES
;
706 if ( data
.GetSelection() )
707 pd
->Flags
|= PD_SELECTION
;
708 if ( data
.GetCollate() )
709 pd
->Flags
|= PD_COLLATE
;
710 if ( data
.GetPrintToFile() )
711 pd
->Flags
|= PD_PRINTTOFILE
;
712 if ( !data
.GetEnablePrintToFile() )
713 pd
->Flags
|= PD_DISABLEPRINTTOFILE
;
714 if ( !data
.GetEnableSelection() )
715 pd
->Flags
|= PD_NOSELECTION
;
716 if ( !data
.GetEnablePageNumbers() )
717 pd
->Flags
|= PD_NOPAGENUMS
;
718 else if ( (!data
.GetAllPages()) && (!data
.GetSelection()) && (data
.GetFromPage() != 0) && (data
.GetToPage() != 0))
719 pd
->Flags
|= PD_PAGENUMS
;
720 if ( data
.GetEnableHelp() )
721 pd
->Flags
|= PD_SHOWHELP
;
722 #if WXWIN_COMPATIBILITY_2_4
723 if ( data
.GetSetupDialog() )
724 pd
->Flags
|= PD_PRINTSETUP
;
730 bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData
&data
)
732 PRINTDLG
*pd
= (PRINTDLG
*) m_printDlg
;
736 wxWindowsPrintNativeData
*native_data
=
737 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
739 // Pass the devmode data back to the wxPrintData structure where it really belongs.
742 if (native_data
->GetDevMode())
744 // Make sure we don't leak memory
745 GlobalFree( (HGLOBAL
)(DWORD
) native_data
->GetDevMode() );
747 native_data
->SetDevMode( (void*)(long) pd
->hDevMode
);
751 // Pass the devnames data back to the wxPrintData structure where it really belongs.
754 if (native_data
->GetDevNames())
756 // Make sure we don't leak memory
757 GlobalFree((HGLOBAL
)(DWORD
) native_data
->GetDevNames());
759 native_data
->SetDevNames((void*)(long) pd
->hDevNames
);
760 pd
->hDevNames
= NULL
;
763 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
764 // into wxWidgets form.
765 native_data
->TransferTo( data
.GetPrintData() );
767 data
.SetFromPage( pd
->nFromPage
);
768 data
.SetToPage( pd
->nToPage
);
769 data
.SetMinPage( pd
->nMinPage
);
770 data
.SetMaxPage( pd
->nMaxPage
);
771 data
.SetNoCopies( pd
->nCopies
);
773 data
.SetAllPages( (((pd
->Flags
& PD_PAGENUMS
) != PD_PAGENUMS
) && ((pd
->Flags
& PD_SELECTION
) != PD_SELECTION
)) );
774 data
.SetSelection( ((pd
->Flags
& PD_SELECTION
) == PD_SELECTION
) );
775 data
.SetCollate( ((pd
->Flags
& PD_COLLATE
) == PD_COLLATE
) );
776 data
.SetPrintToFile( ((pd
->Flags
& PD_PRINTTOFILE
) == PD_PRINTTOFILE
) );
777 data
.EnablePrintToFile( ((pd
->Flags
& PD_DISABLEPRINTTOFILE
) != PD_DISABLEPRINTTOFILE
) );
778 data
.EnableSelection( ((pd
->Flags
& PD_NOSELECTION
) != PD_NOSELECTION
) );
779 data
.EnablePageNumbers( ((pd
->Flags
& PD_NOPAGENUMS
) != PD_NOPAGENUMS
) );
780 data
.EnableHelp( ((pd
->Flags
& PD_SHOWHELP
) == PD_SHOWHELP
) );
781 #if WXWIN_COMPATIBILITY_2_4
782 data
.SetSetupDialog( ((pd
->Flags
& PD_PRINTSETUP
) == PD_PRINTSETUP
) );
787 // ---------------------------------------------------------------------------
788 // wxWidnowsPageSetupDialog
789 // ---------------------------------------------------------------------------
791 IMPLEMENT_CLASS(wxWindowsPageSetupDialog
, wxPageSetupDialogBase
)
793 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog()
795 m_dialogParent
= NULL
;
799 wxWindowsPageSetupDialog::wxWindowsPageSetupDialog(wxWindow
*p
, wxPageSetupDialogData
*data
)
804 bool wxWindowsPageSetupDialog::Create(wxWindow
*p
, wxPageSetupDialogData
*data
)
810 m_pageSetupData
= (*data
);
815 wxWindowsPageSetupDialog::~wxWindowsPageSetupDialog()
817 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*)m_pageDlg
;
818 if ( pd
&& pd
->hDevMode
)
819 GlobalFree(pd
->hDevMode
);
820 if ( pd
&& pd
->hDevNames
)
821 GlobalFree(pd
->hDevNames
);
826 int wxWindowsPageSetupDialog::ShowModal()
828 ConvertToNative( m_pageSetupData
);
830 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
832 pd
->hwndOwner
= (HWND
) m_dialogParent
->GetHWND();
833 else if (wxTheApp
->GetTopWindow())
834 pd
->hwndOwner
= (HWND
) wxTheApp
->GetTopWindow()->GetHWND();
837 BOOL retVal
= PageSetupDlg( pd
) ;
841 ConvertFromNative( m_pageSetupData
);
848 bool wxWindowsPageSetupDialog::ConvertToNative( wxPageSetupDialogData
&data
)
850 wxWindowsPrintNativeData
*native_data
=
851 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
852 data
.GetPrintData().ConvertToNative();
854 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
856 // Shouldn't have been defined anywhere
860 pd
= new PAGESETUPDLG
;
862 pd
->hDevNames
= NULL
;
863 m_pageDlg
= (void *)pd
;
865 // Pass the devmode data (created in m_printData.ConvertToNative)
866 // to the PRINTDLG structure, since it'll
867 // be needed when PrintDlg is called.
871 GlobalFree(pd
->hDevMode
);
874 pd
->hDevMode
= (HGLOBAL
) native_data
->GetDevMode();
875 native_data
->SetDevMode( (void*) NULL
);
877 // Shouldn't assert; we should be able to test Ok-ness at a higher level
878 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
880 // Pass the devnames data (created in m_printData.ConvertToNative)
881 // to the PRINTDLG structure, since it'll
882 // be needed when PrintDlg is called.
886 GlobalFree(pd
->hDevNames
);
887 pd
->hDevNames
= NULL
;
889 pd
->hDevNames
= (HGLOBAL
) native_data
->GetDevNames();
890 native_data
->SetDevNames((void*) NULL
);
892 // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
894 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
896 if ( data
.GetDefaultMinMargins() )
897 pd
->Flags
|= PSD_DEFAULTMINMARGINS
;
898 if ( !data
.GetEnableMargins() )
899 pd
->Flags
|= PSD_DISABLEMARGINS
;
900 if ( !data
.GetEnableOrientation() )
901 pd
->Flags
|= PSD_DISABLEORIENTATION
;
902 if ( !data
.GetEnablePaper() )
903 pd
->Flags
|= PSD_DISABLEPAPER
;
904 if ( !data
.GetEnablePrinter() )
905 pd
->Flags
|= PSD_DISABLEPRINTER
;
906 if ( data
.GetDefaultInfo() )
907 pd
->Flags
|= PSD_RETURNDEFAULT
;
908 if ( data
.GetEnableHelp() )
909 pd
->Flags
|= PSD_SHOWHELP
;
911 // We want the units to be in hundredths of a millimetre
912 pd
->Flags
|= PSD_INHUNDREDTHSOFMILLIMETERS
;
914 pd
->lStructSize
= sizeof( PAGESETUPDLG
);
915 pd
->hwndOwner
=(HWND
)NULL
;
916 // pd->hDevNames=(HWND)NULL;
917 pd
->hInstance
=(HINSTANCE
)NULL
;
918 // PAGESETUPDLG is in hundreds of a mm
919 pd
->ptPaperSize
.x
= data
.GetPaperSize().x
* 100;
920 pd
->ptPaperSize
.y
= data
.GetPaperSize().y
* 100;
922 pd
->rtMinMargin
.left
= data
.GetMinMarginTopLeft().x
* 100;
923 pd
->rtMinMargin
.top
= data
.GetMinMarginTopLeft().y
* 100;
924 pd
->rtMinMargin
.right
= data
.GetMinMarginBottomRight().x
* 100;
925 pd
->rtMinMargin
.bottom
= data
.GetMinMarginBottomRight().y
* 100;
927 pd
->rtMargin
.left
= data
.GetMarginTopLeft().x
* 100;
928 pd
->rtMargin
.top
= data
.GetMarginTopLeft().y
* 100;
929 pd
->rtMargin
.right
= data
.GetMarginBottomRight().x
* 100;
930 pd
->rtMargin
.bottom
= data
.GetMarginBottomRight().y
* 100;
933 pd
->lpfnPageSetupHook
= NULL
;
934 pd
->lpfnPagePaintHook
= NULL
;
935 pd
->hPageSetupTemplate
= NULL
;
936 pd
->lpPageSetupTemplateName
= NULL
;
941 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
942 memset(devMode, 0, sizeof(DEVMODE));
943 devMode->dmSize = sizeof(DEVMODE);
944 devMode->dmOrientation = m_orientation;
945 devMode->dmFields = DM_ORIENTATION;
946 GlobalUnlock(pd->hDevMode);
952 bool wxWindowsPageSetupDialog::ConvertFromNative( wxPageSetupDialogData
&data
)
954 PAGESETUPDLG
*pd
= (PAGESETUPDLG
*) m_pageDlg
;
958 wxWindowsPrintNativeData
*native_data
=
959 (wxWindowsPrintNativeData
*) data
.GetPrintData().GetNativeData();
961 // Pass the devmode data back to the wxPrintData structure where it really belongs.
964 if (native_data
->GetDevMode())
966 // Make sure we don't leak memory
967 GlobalFree((HGLOBAL
) native_data
->GetDevMode());
969 native_data
->SetDevMode( (void*) pd
->hDevMode
);
973 // Isn't this superfluous? It's called again below.
974 // data.GetPrintData().ConvertFromNative();
976 // Pass the devnames data back to the wxPrintData structure where it really belongs.
979 if (native_data
->GetDevNames())
981 // Make sure we don't leak memory
982 GlobalFree((HGLOBAL
) native_data
->GetDevNames());
984 native_data
->SetDevNames((void*) pd
->hDevNames
);
985 pd
->hDevNames
= NULL
;
988 data
.GetPrintData().ConvertFromNative();
990 pd
->Flags
= PSD_MARGINS
|PSD_MINMARGINS
;
992 data
.SetDefaultMinMargins( ((pd
->Flags
& PSD_DEFAULTMINMARGINS
) == PSD_DEFAULTMINMARGINS
) );
993 data
.EnableMargins( ((pd
->Flags
& PSD_DISABLEMARGINS
) != PSD_DISABLEMARGINS
) );
994 data
.EnableOrientation( ((pd
->Flags
& PSD_DISABLEORIENTATION
) != PSD_DISABLEORIENTATION
) );
995 data
.EnablePaper( ((pd
->Flags
& PSD_DISABLEPAPER
) != PSD_DISABLEPAPER
) );
996 data
.EnablePrinter( ((pd
->Flags
& PSD_DISABLEPRINTER
) != PSD_DISABLEPRINTER
) );
997 data
.SetDefaultInfo( ((pd
->Flags
& PSD_RETURNDEFAULT
) == PSD_RETURNDEFAULT
) );
998 data
.EnableHelp( ((pd
->Flags
& PSD_SHOWHELP
) == PSD_SHOWHELP
) );
1000 // PAGESETUPDLG is in hundreds of a mm
1001 data
.SetPaperSize( wxSize(pd
->ptPaperSize
.x
/ 100, pd
->ptPaperSize
.y
/ 100) );
1003 data
.SetMinMarginTopLeft( wxPoint(pd
->rtMinMargin
.left
/ 100, pd
->rtMinMargin
.top
/ 100) );
1004 data
.SetMinMarginBottomRight( wxPoint(pd
->rtMinMargin
.right
/ 100, pd
->rtMinMargin
.bottom
/ 100) );
1006 data
.SetMarginTopLeft( wxPoint(pd
->rtMargin
.left
/ 100, pd
->rtMargin
.top
/ 100) );
1007 data
.SetMarginBottomRight( wxPoint(pd
->rtMargin
.right
/ 100, pd
->rtMargin
.bottom
/ 100) );
1013 // wxUSE_PRINTING_ARCHITECTURE