]> git.saurik.com Git - wxWidgets.git/blame - src/msw/printdlg.cpp
forwarding style changes to documentViews, see #14578
[wxWidgets.git] / src / msw / printdlg.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
6d50343d 2// Name: src/msw/printdlg.cpp
2bda0e17
KB
3// Purpose: wxPrintDialog, wxPageSetupDialog
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
103aec29
VZ
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
2bda0e17 20// For compilers that support precompilation, includes "wx.h".
2bda0e17
KB
21#include "wx/wxprec.h"
22
a3b46648 23#ifdef __BORLANDC__
103aec29 24 #pragma hdrstop
2bda0e17
KB
25#endif
26
12bdd77c
JS
27// Don't use the Windows print dialog if we're in wxUniv mode and using
28// the PostScript architecture
29#if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXUNIVERSAL__) || !wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
f6bcfd97
BP
30
31#ifndef WX_PRECOMP
57bd4c60 32 #include "wx/msw/wrapcdlg.h"
f6bcfd97 33 #include "wx/app.h"
6d50343d 34 #include "wx/dcprint.h"
ce5d92e1 35 #include "wx/cmndata.h"
f6bcfd97
BP
36#endif
37
2bda0e17 38#include "wx/printdlg.h"
08680429 39#include "wx/msw/printdlg.h"
888dde65 40#include "wx/msw/dcprint.h"
8850cbd3 41#include "wx/paper.h"
2bda0e17 42
2bda0e17 43#include <stdlib.h>
42e69d6b 44
7da33e04
JS
45// smart pointer like class using OpenPrinter and ClosePrinter
46class WinPrinter
47{
48public:
49 // default ctor
50 WinPrinter()
51 {
52 m_hPrinter = (HANDLE)NULL;
53 }
54
55 WinPrinter( const wxString& printerName )
56 {
57 Open( printerName );
58 }
59
60 ~WinPrinter()
61 {
62 Close();
63 }
64
65 BOOL Open( const wxString& printerName, LPPRINTER_DEFAULTS pDefault=(LPPRINTER_DEFAULTS)NULL )
66 {
67 Close();
017dc06b 68 return OpenPrinter( wxMSW_CONV_LPTSTR(printerName), &m_hPrinter, pDefault );
7da33e04
JS
69 }
70
71 BOOL Close()
72 {
73 BOOL result = TRUE;
74 if( m_hPrinter )
75 {
76 result = ClosePrinter( m_hPrinter );
77 m_hPrinter = (HANDLE)NULL;
78 }
79 return result;
80 }
81
82 operator HANDLE() { return m_hPrinter; }
83 operator bool() { return m_hPrinter != (HANDLE)NULL; }
84
85private:
86 HANDLE m_hPrinter;
87
88 wxDECLARE_NO_COPY_CLASS(WinPrinter);
89};
90
91
8850cbd3
RR
92//----------------------------------------------------------------------------
93// wxWindowsPrintNativeData
94//----------------------------------------------------------------------------
95
d021f94f
VZ
96#if wxDEBUG_LEVEL
97
8850cbd3
RR
98static wxString wxGetPrintDlgError()
99{
100 DWORD err = CommDlgExtendedError();
101 wxString msg = wxT("Unknown");
102 switch (err)
103 {
104 case CDERR_FINDRESFAILURE: msg = wxT("CDERR_FINDRESFAILURE"); break;
105 case CDERR_INITIALIZATION: msg = wxT("CDERR_INITIALIZATION"); break;
106 case CDERR_LOADRESFAILURE: msg = wxT("CDERR_LOADRESFAILURE"); break;
107 case CDERR_LOADSTRFAILURE: msg = wxT("CDERR_LOADSTRFAILURE"); break;
108 case CDERR_LOCKRESFAILURE: msg = wxT("CDERR_LOCKRESFAILURE"); break;
109 case CDERR_MEMALLOCFAILURE: msg = wxT("CDERR_MEMALLOCFAILURE"); break;
110 case CDERR_MEMLOCKFAILURE: msg = wxT("CDERR_MEMLOCKFAILURE"); break;
111 case CDERR_NOHINSTANCE: msg = wxT("CDERR_NOHINSTANCE"); break;
112 case CDERR_NOHOOK: msg = wxT("CDERR_NOHOOK"); break;
113 case CDERR_NOTEMPLATE: msg = wxT("CDERR_NOTEMPLATE"); break;
114 case CDERR_STRUCTSIZE: msg = wxT("CDERR_STRUCTSIZE"); break;
115 case PDERR_RETDEFFAILURE: msg = wxT("PDERR_RETDEFFAILURE"); break;
116 case PDERR_PRINTERNOTFOUND: msg = wxT("PDERR_PRINTERNOTFOUND"); break;
117 case PDERR_PARSEFAILURE: msg = wxT("PDERR_PARSEFAILURE"); break;
118 case PDERR_NODEVICES: msg = wxT("PDERR_NODEVICES"); break;
119 case PDERR_NODEFAULTPRN: msg = wxT("PDERR_NODEFAULTPRN"); break;
120 case PDERR_LOADDRVFAILURE: msg = wxT("PDERR_LOADDRVFAILURE"); break;
121 case PDERR_INITFAILURE: msg = wxT("PDERR_INITFAILURE"); break;
122 case PDERR_GETDEVMODEFAIL: msg = wxT("PDERR_GETDEVMODEFAIL"); break;
123 case PDERR_DNDMMISMATCH: msg = wxT("PDERR_DNDMMISMATCH"); break;
124 case PDERR_DEFAULTDIFFERENT: msg = wxT("PDERR_DEFAULTDIFFERENT"); break;
125 case PDERR_CREATEICFAILURE: msg = wxT("PDERR_CREATEICFAILURE"); break;
126 default: break;
127 }
128 return msg;
129}
8850cbd3 130
d021f94f
VZ
131#endif // wxDEBUG_LEVEL
132
133
bd84061d
VZ
134static HGLOBAL
135wxCreateDevNames(const wxString& driverName,
136 const wxString& printerName,
137 const wxString& portName)
8850cbd3
RR
138{
139 HGLOBAL hDev = NULL;
f31a4098
WS
140 // if (!driverName.empty() && !printerName.empty() && !portName.empty())
141 if (driverName.empty() && printerName.empty() && portName.empty())
8850cbd3
RR
142 {
143 }
144 else
145 {
146 hDev = GlobalAlloc(GPTR, 4*sizeof(WORD)+
6d50343d
WS
147 ( driverName.length() + 1 +
148 printerName.length() + 1 +
149 portName.length()+1 ) * sizeof(wxChar) );
8850cbd3
RR
150 LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(hDev);
151 lpDev->wDriverOffset = sizeof(WORD) * 4 / sizeof(wxChar);
152 wxStrcpy((wxChar*)lpDev + lpDev->wDriverOffset, driverName);
153
154 lpDev->wDeviceOffset = (WORD)( lpDev->wDriverOffset +
6d50343d 155 driverName.length() + 1 );
8850cbd3
RR
156 wxStrcpy((wxChar*)lpDev + lpDev->wDeviceOffset, printerName);
157
158 lpDev->wOutputOffset = (WORD)( lpDev->wDeviceOffset +
6d50343d 159 printerName.length() + 1 );
8850cbd3
RR
160 wxStrcpy((wxChar*)lpDev + lpDev->wOutputOffset, portName);
161
162 lpDev->wDefault = 0;
163
164 GlobalUnlock(hDev);
165 }
166
167 return hDev;
168}
169
170IMPLEMENT_CLASS(wxWindowsPrintNativeData, wxPrintNativeDataBase)
171
172wxWindowsPrintNativeData::wxWindowsPrintNativeData()
173{
dca0f651
VZ
174 m_devMode = NULL;
175 m_devNames = NULL;
3168b4c3 176 m_customWindowsPaperId = 0;
8850cbd3
RR
177}
178
179wxWindowsPrintNativeData::~wxWindowsPrintNativeData()
180{
dca0f651 181 if ( m_devMode )
5c33522f 182 ::GlobalFree(static_cast<HGLOBAL>(m_devMode));
dca0f651
VZ
183
184 if ( m_devNames )
5c33522f 185 ::GlobalFree(static_cast<HGLOBAL>(m_devNames));
8850cbd3
RR
186}
187
b7cacb43 188bool wxWindowsPrintNativeData::IsOk() const
8850cbd3
RR
189{
190 return (m_devMode != NULL) ;
191}
192
fd64de59 193bool wxWindowsPrintNativeData::TransferTo( wxPrintData &data )
8850cbd3 194{
6c797d8f
RD
195 if ( !m_devMode )
196 InitializeDevMode();
197
dca0f651 198 if ( !m_devMode )
8850cbd3 199 return false;
8850cbd3 200
dca0f651 201 GlobalPtrLock lockDevMode(m_devMode);
8850cbd3 202
5c33522f 203 LPDEVMODE devMode = static_cast<LPDEVMODE>(lockDevMode.Get());
8850cbd3 204
dca0f651
VZ
205 //// Orientation
206 if (devMode->dmFields & DM_ORIENTATION)
af7e24c3 207 data.SetOrientation( (wxPrintOrientation)devMode->dmOrientation );
8850cbd3 208
dca0f651
VZ
209 //// Collation
210 if (devMode->dmFields & DM_COLLATE)
211 {
212 if (devMode->dmCollate == DMCOLLATE_TRUE)
213 data.SetCollate( true );
8850cbd3 214 else
dca0f651
VZ
215 data.SetCollate( false );
216 }
217
218 //// Number of copies
219 if (devMode->dmFields & DM_COPIES)
220 data.SetNoCopies( devMode->dmCopies );
221
222 //// Bin
223 if (devMode->dmFields & DM_DEFAULTSOURCE) {
224 switch (devMode->dmDefaultSource) {
225 case DMBIN_ONLYONE : data.SetBin(wxPRINTBIN_ONLYONE ); break;
226 case DMBIN_LOWER : data.SetBin(wxPRINTBIN_LOWER ); break;
227 case DMBIN_MIDDLE : data.SetBin(wxPRINTBIN_MIDDLE ); break;
228 case DMBIN_MANUAL : data.SetBin(wxPRINTBIN_MANUAL ); break;
229 case DMBIN_ENVELOPE : data.SetBin(wxPRINTBIN_ENVELOPE ); break;
230 case DMBIN_ENVMANUAL : data.SetBin(wxPRINTBIN_ENVMANUAL ); break;
231 case DMBIN_AUTO : data.SetBin(wxPRINTBIN_AUTO ); break;
232 case DMBIN_TRACTOR : data.SetBin(wxPRINTBIN_TRACTOR ); break;
233 case DMBIN_SMALLFMT : data.SetBin(wxPRINTBIN_SMALLFMT ); break;
234 case DMBIN_LARGEFMT : data.SetBin(wxPRINTBIN_LARGEFMT ); break;
235 case DMBIN_LARGECAPACITY : data.SetBin(wxPRINTBIN_LARGECAPACITY ); break;
236 case DMBIN_CASSETTE : data.SetBin(wxPRINTBIN_CASSETTE ); break;
237 case DMBIN_FORMSOURCE : data.SetBin(wxPRINTBIN_FORMSOURCE ); break;
238 default:
bd84061d 239 if (devMode->dmDefaultSource >= DMBIN_USER)
dca0f651 240 data.SetBin((wxPrintBin)((devMode->dmDefaultSource)-DMBIN_USER+(int)wxPRINTBIN_USER));
bd84061d 241 else
dca0f651 242 data.SetBin(wxPRINTBIN_DEFAULT);
dca0f651
VZ
243 }
244 } else {
245 data.SetBin(wxPRINTBIN_DEFAULT);
246 }
247 if (devMode->dmFields & DM_MEDIATYPE)
248 {
249 wxASSERT( (int)devMode->dmMediaType != wxPRINTMEDIA_DEFAULT );
250 data.SetMedia(devMode->dmMediaType);
251 }
252 //// Printer name
253 if (devMode->dmDeviceName[0] != 0)
254 // This syntax fixes a crash when using VS 7.1
255 data.SetPrinterName( wxString(devMode->dmDeviceName, CCHDEVICENAME) );
256
257 //// Colour
258 if (devMode->dmFields & DM_COLOR)
259 {
260 if (devMode->dmColor == DMCOLOR_COLOR)
8850cbd3 261 data.SetColour( true );
dca0f651
VZ
262 else
263 data.SetColour( false );
264 }
265 else
266 data.SetColour( true );
8850cbd3 267
dca0f651 268 //// Paper size
8850cbd3 269
dca0f651
VZ
270 // We don't know size of user defined paper and some buggy drivers
271 // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
272 // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
273 // code wouldn't set m_paperSize correctly.
21c358b2 274
dca0f651
VZ
275 bool foundPaperSize = false;
276 if ((devMode->dmFields & DM_PAPERSIZE) && (devMode->dmPaperSize < DMPAPER_USER))
277 {
278 if (wxThePrintPaperDatabase)
8850cbd3 279 {
dca0f651
VZ
280 wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize);
281 if (paper)
8850cbd3 282 {
dca0f651
VZ
283 data.SetPaperId( paper->GetId() );
284 data.SetPaperSize( wxSize(paper->GetWidth() / 10,paper->GetHeight() / 10) );
3168b4c3 285 m_customWindowsPaperId = 0;
dca0f651 286 foundPaperSize = true;
8850cbd3
RR
287 }
288 }
dca0f651
VZ
289 else
290 {
291 // Shouldn't really get here
292 wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
293 data.SetPaperId( wxPAPER_NONE );
294 data.SetPaperSize( wxSize(0,0) );
295 m_customWindowsPaperId = 0;
3168b4c3 296
dca0f651 297 return false;
8850cbd3 298 }
dca0f651 299 }
8850cbd3 300
dca0f651
VZ
301 if (!foundPaperSize) {
302 if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH))
8850cbd3 303 {
dca0f651
VZ
304 // DEVMODE is in tenths of a millimeter
305 data.SetPaperSize( wxSize(devMode->dmPaperWidth / 10, devMode->dmPaperLength / 10) );
306 data.SetPaperId( wxPAPER_NONE );
307 m_customWindowsPaperId = devMode->dmPaperSize;
8850cbd3
RR
308 }
309 else
dca0f651
VZ
310 {
311 // Often will reach this for non-standard paper sizes (sizes which
312 // wouldn't be in wxWidget's paper database). Setting
313 // m_customWindowsPaperId to devMode->dmPaperSize should be enough
314 // to get this paper size working.
315 data.SetPaperSize( wxSize(0,0) );
316 data.SetPaperId( wxPAPER_NONE );
317 m_customWindowsPaperId = devMode->dmPaperSize;
318 }
319 }
8850cbd3 320
dca0f651
VZ
321 //// Duplex
322
323 if (devMode->dmFields & DM_DUPLEX)
324 {
325 switch (devMode->dmDuplex)
326 {
327 case DMDUP_HORIZONTAL: data.SetDuplex( wxDUPLEX_HORIZONTAL ); break;
328 case DMDUP_VERTICAL: data.SetDuplex( wxDUPLEX_VERTICAL ); break;
329 default:
330 case DMDUP_SIMPLEX: data.SetDuplex( wxDUPLEX_SIMPLEX ); break;
331 }
332 }
333 else
334 data.SetDuplex( wxDUPLEX_SIMPLEX );
8850cbd3 335
dca0f651
VZ
336 //// Quality
337
338 if (devMode->dmFields & DM_PRINTQUALITY)
339 {
340 switch (devMode->dmPrintQuality)
8850cbd3 341 {
dca0f651
VZ
342 case DMRES_MEDIUM: data.SetQuality( wxPRINT_QUALITY_MEDIUM ); break;
343 case DMRES_LOW: data.SetQuality( wxPRINT_QUALITY_LOW ); break;
344 case DMRES_DRAFT: data.SetQuality( wxPRINT_QUALITY_DRAFT ); break;
345 case DMRES_HIGH: data.SetQuality( wxPRINT_QUALITY_HIGH ); break;
346 default:
8850cbd3 347 {
dca0f651
VZ
348 // TODO: if the printer fills in the resolution in DPI, how
349 // will the application know if it's high, low, draft etc.??
350 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
351 data.SetQuality( devMode->dmPrintQuality );
352 break;
8850cbd3 353
8850cbd3
RR
354 }
355 }
8850cbd3 356 }
dca0f651
VZ
357 else
358 data.SetQuality( wxPRINT_QUALITY_HIGH );
359
360 if (devMode->dmDriverExtra > 0)
361 data.SetPrivData( (char *)devMode+devMode->dmSize, devMode->dmDriverExtra );
362 else
363 data.SetPrivData( NULL, 0 );
8850cbd3 364
dca0f651 365 if ( m_devNames )
8850cbd3 366 {
dca0f651 367 GlobalPtrLock lockDevNames(m_devNames);
5c33522f 368 LPDEVNAMES lpDevNames = static_cast<LPDEVNAMES>(lockDevNames.Get());
8850cbd3 369
dca0f651 370 // TODO: Unicode-ification
8850cbd3 371
dca0f651
VZ
372 // Get the port name
373 // port is obsolete in WIN32
374 // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
8850cbd3 375
dca0f651
VZ
376 // Get the printer name
377 wxString printerName = (LPTSTR)lpDevNames + lpDevNames->wDeviceOffset;
8850cbd3 378
dca0f651
VZ
379 // Not sure if we should check for this mismatch
380// wxASSERT_MSG( (m_printerName.empty() || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
8850cbd3 381
dca0f651
VZ
382 if (!printerName.empty())
383 data.SetPrinterName( printerName );
8850cbd3 384 }
f31a4098 385
8850cbd3
RR
386 return true;
387}
388
6c797d8f 389void wxWindowsPrintNativeData::InitializeDevMode(const wxString& printerName, WinPrinter* printer)
8850cbd3 390{
6c797d8f
RD
391 if (m_devMode)
392 return;
393
017dc06b 394 LPTSTR szPrinterName = wxMSW_CONV_LPTSTR(printerName);
082e5b98
JS
395
396 // From MSDN: How To Modify Printer Settings with the DocumentProperties() Function
397 // The purpose of this is to fill the DEVMODE with privdata from printer driver.
398 // If we have a printer name and OpenPrinter sucessfully returns
399 // this replaces the PrintDlg function which creates the DEVMODE filled only with data from default printer.
6c797d8f 400 if ( !m_devMode && !printerName.IsEmpty() )
082e5b98
JS
401 {
402 // Open printer
6c797d8f 403 if ( printer && printer->Open( printerName ) == TRUE )
082e5b98
JS
404 {
405 DWORD dwNeeded, dwRet;
406
407 // Step 1:
408 // Allocate a buffer of the correct size.
409 dwNeeded = DocumentProperties( NULL,
b98b75cd 410 *printer, // Handle to our printer.
082e5b98
JS
411 szPrinterName, // Name of the printer.
412 NULL, // Asking for size, so
413 NULL, // these are not used.
414 0 ); // Zero returns buffer size.
415
416 LPDEVMODE tempDevMode = static_cast<LPDEVMODE>( GlobalAlloc( GMEM_FIXED | GMEM_ZEROINIT, dwNeeded ) );
417
418 // Step 2:
419 // Get the default DevMode for the printer
420 dwRet = DocumentProperties( NULL,
b98b75cd 421 *printer,
082e5b98
JS
422 szPrinterName,
423 tempDevMode, // The address of the buffer to fill.
424 NULL, // Not using the input buffer.
425 DM_OUT_BUFFER ); // Have the output buffer filled.
426
427 if ( dwRet != IDOK )
428 {
429 // If failure, cleanup
430 GlobalFree( tempDevMode );
6c797d8f 431 printer->Close();
082e5b98
JS
432 }
433 else
434 {
6c797d8f 435 m_devMode = tempDevMode;
082e5b98
JS
436 tempDevMode = NULL;
437 }
438 }
439 }
440
dca0f651 441 if ( !m_devMode )
8850cbd3
RR
442 {
443 // Use PRINTDLG as a way of creating a DEVMODE object
444 PRINTDLG pd;
445
8850cbd3
RR
446 memset(&pd, 0, sizeof(PRINTDLG));
447#ifdef __WXWINCE__
448 pd.cbStruct = sizeof(PRINTDLG);
449#else
450 pd.lStructSize = sizeof(PRINTDLG);
8850cbd3
RR
451#endif
452
bd84061d 453 pd.hwndOwner = NULL;
8850cbd3
RR
454 pd.hDevMode = NULL; // Will be created by PrintDlg
455 pd.hDevNames = NULL; // Ditto
8850cbd3
RR
456
457 pd.Flags = PD_RETURNDEFAULT;
458 pd.nCopies = 1;
459
460 // Fill out the DEVMODE structure
461 // so we can use it as input in the 'real' PrintDlg
462 if (!PrintDlg(&pd))
463 {
464 if ( pd.hDevMode )
465 GlobalFree(pd.hDevMode);
466 if ( pd.hDevNames )
467 GlobalFree(pd.hDevNames);
468 pd.hDevMode = NULL;
469 pd.hDevNames = NULL;
470
113f4def 471#if wxDEBUG_LEVEL
4b6a582b 472 wxLogDebug(wxT("Printing error: ") + wxGetPrintDlgError());
d021f94f 473#endif // wxDEBUG_LEVEL
8850cbd3
RR
474 }
475 else
476 {
6c797d8f 477 m_devMode = pd.hDevMode;
8850cbd3
RR
478 pd.hDevMode = NULL;
479
480 // We'll create a new DEVNAMEs structure below.
481 if ( pd.hDevNames )
482 GlobalFree(pd.hDevNames);
483 pd.hDevNames = NULL;
484
485 // hDevNames = pd->hDevNames;
486 // m_devNames = (void*)(long) hDevNames;
487 // pd->hDevnames = NULL;
488
489 }
490 }
491
6c797d8f
RD
492}
493
494bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data )
495{
496 WinPrinter printer;
017dc06b 497 LPTSTR szPrinterName = wxMSW_CONV_LPTSTR(data.GetPrinterName());
6c797d8f
RD
498
499 if (!m_devMode)
500 InitializeDevMode(data.GetPrinterName(), &printer);
501
502 HGLOBAL hDevMode = static_cast<HGLOBAL>(m_devMode);
503
8850cbd3
RR
504 if ( hDevMode )
505 {
dca0f651 506 GlobalPtrLock lockDevMode(hDevMode);
5c33522f 507 DEVMODE * const devMode = static_cast<DEVMODE *>(lockDevMode.Get());
8850cbd3
RR
508
509 //// Orientation
510 devMode->dmOrientation = (short)data.GetOrientation();
511
512 //// Collation
513 devMode->dmCollate = (data.GetCollate() ? DMCOLLATE_TRUE : DMCOLLATE_FALSE);
514 devMode->dmFields |= DM_COLLATE;
515
516 //// Number of copies
517 devMode->dmCopies = (short)data.GetNoCopies();
518 devMode->dmFields |= DM_COPIES;
519
520 //// Printer name
521 wxString name = data.GetPrinterName();
f31a4098 522 if (!name.empty())
8850cbd3 523 {
47af39fb
VZ
524 // NB: the cast is needed in the ANSI build, strangely enough
525 // dmDeviceName is BYTE[] and not char[] there
e408bf52 526 wxStrlcpy(reinterpret_cast<wxChar *>(devMode->dmDeviceName),
017dc06b 527 name.t_str(),
e408bf52 528 WXSIZEOF(devMode->dmDeviceName));
8850cbd3
RR
529 }
530
531 //// Colour
532 if (data.GetColour())
533 devMode->dmColor = DMCOLOR_COLOR;
534 else
535 devMode->dmColor = DMCOLOR_MONOCHROME;
536 devMode->dmFields |= DM_COLOR;
537
538 //// Paper size
d5eaa19f
VZ
539
540 // Paper id has priority over paper size. If id is specified, then size
541 // is ignored (as it can be filled in even for standard paper sizes)
542
543 wxPrintPaperType *paperType = NULL;
544
545 const wxPaperSize paperId = data.GetPaperId();
546 if ( paperId != wxPAPER_NONE && wxThePrintPaperDatabase )
8850cbd3 547 {
d5eaa19f 548 paperType = wxThePrintPaperDatabase->FindPaperType(paperId);
8850cbd3 549 }
d5eaa19f
VZ
550
551 if ( paperType )
8850cbd3 552 {
d5eaa19f
VZ
553 devMode->dmPaperSize = (short)paperType->GetPlatformId();
554 devMode->dmFields |= DM_PAPERSIZE;
555 }
556 else // custom (or no) paper size
557 {
558 const wxSize paperSize = data.GetPaperSize();
559 if ( paperSize != wxDefaultSize )
8850cbd3 560 {
d5eaa19f
VZ
561 // Fall back on specifying the paper size explicitly
562 if(m_customWindowsPaperId != 0)
563 devMode->dmPaperSize = m_customWindowsPaperId;
21c358b2 564 else
21c358b2 565 devMode->dmPaperSize = DMPAPER_USER;
d5eaa19f
VZ
566 devMode->dmPaperWidth = (short)(paperSize.x * 10);
567 devMode->dmPaperLength = (short)(paperSize.y * 10);
568 devMode->dmFields |= DM_PAPERWIDTH;
569 devMode->dmFields |= DM_PAPERLENGTH;
3c46da42
JS
570
571 // A printer driver may or may not also want DM_PAPERSIZE to
572 // be specified. Also, if the printer driver doesn't implement the DMPAPER_USER
573 // size, then this won't work, and even if you found the correct id by
574 // enumerating the driver's paper sizes, it probably won't change the actual size,
575 // it'll just select that custom paper type with its own current setting.
576 // For a discussion on this, see http://www.codeguru.com/forum/showthread.php?threadid=458617
577 // Although m_customWindowsPaperId is intended to work around this, it's
578 // unclear how it can help you set the custom paper size programmatically.
8850cbd3 579 }
d5eaa19f
VZ
580 //else: neither paper type nor size specified, don't fill DEVMODE
581 // at all so that the system defaults are used
8850cbd3
RR
582 }
583
584 //// Duplex
585 short duplex;
586 switch (data.GetDuplex())
587 {
588 case wxDUPLEX_HORIZONTAL:
589 duplex = DMDUP_HORIZONTAL;
590 break;
591 case wxDUPLEX_VERTICAL:
592 duplex = DMDUP_VERTICAL;
593 break;
594 default:
595 // in fact case wxDUPLEX_SIMPLEX:
596 duplex = DMDUP_SIMPLEX;
597 break;
598 }
599 devMode->dmDuplex = duplex;
600 devMode->dmFields |= DM_DUPLEX;
601
602 //// Quality
603
604 short quality;
605 switch (data.GetQuality())
606 {
607 case wxPRINT_QUALITY_MEDIUM:
608 quality = DMRES_MEDIUM;
609 break;
610 case wxPRINT_QUALITY_LOW:
611 quality = DMRES_LOW;
612 break;
613 case wxPRINT_QUALITY_DRAFT:
614 quality = DMRES_DRAFT;
615 break;
616 case wxPRINT_QUALITY_HIGH:
617 quality = DMRES_HIGH;
618 break;
619 default:
620 quality = (short)data.GetQuality();
082e5b98
JS
621 devMode->dmYResolution = quality;
622 devMode->dmFields |= DM_YRESOLUTION;
8850cbd3
RR
623 break;
624 }
625 devMode->dmPrintQuality = quality;
626 devMode->dmFields |= DM_PRINTQUALITY;
4e22a1f2 627
aa96f01c
RR
628 if (data.GetPrivDataLen() > 0)
629 {
630 memcpy( (char *)devMode+devMode->dmSize, data.GetPrivData(), data.GetPrivDataLen() );
4e22a1f2 631 devMode->dmDriverExtra = (WXWORD)data.GetPrivDataLen();
aa96f01c 632 }
8850cbd3
RR
633
634 if (data.GetBin() != wxPRINTBIN_DEFAULT)
635 {
636 switch (data.GetBin())
637 {
638 case wxPRINTBIN_ONLYONE: devMode->dmDefaultSource = DMBIN_ONLYONE; break;
639 case wxPRINTBIN_LOWER: devMode->dmDefaultSource = DMBIN_LOWER; break;
640 case wxPRINTBIN_MIDDLE: devMode->dmDefaultSource = DMBIN_MIDDLE; break;
641 case wxPRINTBIN_MANUAL: devMode->dmDefaultSource = DMBIN_MANUAL; break;
642 case wxPRINTBIN_ENVELOPE: devMode->dmDefaultSource = DMBIN_ENVELOPE; break;
643 case wxPRINTBIN_ENVMANUAL: devMode->dmDefaultSource = DMBIN_ENVMANUAL; break;
644 case wxPRINTBIN_AUTO: devMode->dmDefaultSource = DMBIN_AUTO; break;
645 case wxPRINTBIN_TRACTOR: devMode->dmDefaultSource = DMBIN_TRACTOR; break;
646 case wxPRINTBIN_SMALLFMT: devMode->dmDefaultSource = DMBIN_SMALLFMT; break;
647 case wxPRINTBIN_LARGEFMT: devMode->dmDefaultSource = DMBIN_LARGEFMT; break;
648 case wxPRINTBIN_LARGECAPACITY: devMode->dmDefaultSource = DMBIN_LARGECAPACITY; break;
649 case wxPRINTBIN_CASSETTE: devMode->dmDefaultSource = DMBIN_CASSETTE; break;
650 case wxPRINTBIN_FORMSOURCE: devMode->dmDefaultSource = DMBIN_FORMSOURCE; break;
651
652 default:
fde05480 653 devMode->dmDefaultSource = (short)(DMBIN_USER + data.GetBin() - wxPRINTBIN_USER); // 256 + data.GetBin() - 14 = 242 + data.GetBin()
8850cbd3
RR
654 break;
655 }
656
657 devMode->dmFields |= DM_DEFAULTSOURCE;
658 }
781609f2
JS
659 if (data.GetMedia() != wxPRINTMEDIA_DEFAULT)
660 {
661 devMode->dmMediaType = data.GetMedia();
662 devMode->dmFields |= DM_MEDIATYPE;
663 }
082e5b98
JS
664
665 if( printer )
666 {
667 // Step 3:
668 // Merge the new settings with the old.
669 // This gives the driver an opportunity to update any private
670 // portions of the DevMode structure.
671 DocumentProperties( NULL,
672 printer,
673 szPrinterName,
674 (LPDEVMODE)hDevMode, // Reuse our buffer for output.
675 (LPDEVMODE)hDevMode, // Pass the driver our changes
676 DM_IN_BUFFER | // Commands to Merge our changes and
677 DM_OUT_BUFFER ); // write the result.
678 }
8850cbd3
RR
679 }
680
dca0f651 681 if ( m_devNames )
8850cbd3 682 {
5c33522f 683 ::GlobalFree(static_cast<HGLOBAL>(m_devNames));
8850cbd3
RR
684 }
685
686 // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
dca0f651 687 m_devNames = wxCreateDevNames(wxEmptyString, data.GetPrinterName(), wxEmptyString);
f31a4098 688
8850cbd3
RR
689 return true;
690}
f31a4098 691
103aec29
VZ
692// ---------------------------------------------------------------------------
693// wxPrintDialog
694// ---------------------------------------------------------------------------
695
c061373d 696IMPLEMENT_CLASS(wxWindowsPrintDialog, wxPrintDialogBase)
2bda0e17 697
c061373d 698wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow *p, wxPrintDialogData* data)
2bda0e17 699{
7bcb11d3 700 Create(p, data);
2bda0e17
KB
701}
702
c061373d 703wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow *p, wxPrintData* data)
103aec29
VZ
704{
705 wxPrintDialogData data2;
706 if ( data )
707 data2 = *data;
708
709 Create(p, &data2);
710}
711
c061373d 712bool wxWindowsPrintDialog::Create(wxWindow *p, wxPrintDialogData* data)
2bda0e17 713{
7bcb11d3
JS
714 m_dialogParent = p;
715 m_printerDC = NULL;
078cf5cb 716 m_destroyDC = true;
7bcb11d3 717
93c2f401
RR
718 // MSW handle
719 m_printDlg = NULL;
f31a4098 720
7bcb11d3
JS
721 if ( data )
722 m_printDialogData = *data;
103aec29 723
078cf5cb 724 return true;
2bda0e17
KB
725}
726
c061373d 727wxWindowsPrintDialog::~wxWindowsPrintDialog()
2bda0e17 728{
93c2f401
RR
729 PRINTDLG *pd = (PRINTDLG *) m_printDlg;
730 if (pd && pd->hDevMode)
731 GlobalFree(pd->hDevMode);
732 if ( pd )
733 delete pd;
734
7bcb11d3
JS
735 if (m_destroyDC && m_printerDC)
736 delete m_printerDC;
2bda0e17
KB
737}
738
c061373d 739int wxWindowsPrintDialog::ShowModal()
2bda0e17 740{
93c2f401 741 ConvertToNative( m_printDialogData );
103aec29 742
93c2f401 743 PRINTDLG *pd = (PRINTDLG*) m_printDlg;
f31a4098 744
f6bcfd97 745 if (m_dialogParent)
93c2f401 746 pd->hwndOwner = (HWND) m_dialogParent->GetHWND();
f6bcfd97 747 else if (wxTheApp->GetTopWindow())
93c2f401 748 pd->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND();
f6bcfd97 749 else
93c2f401 750 pd->hwndOwner = 0;
f6bcfd97 751
93c2f401 752 bool ret = (PrintDlg( pd ) != 0);
f6bcfd97 753
93c2f401 754 pd->hwndOwner = 0;
f6bcfd97 755
d0ee33f5 756 if ( ret && (pd->hDC) )
7bcb11d3 757 {
888dde65 758 wxPrinterDC *pdc = new wxPrinterDCFromHDC( (WXHDC) pd->hDC );
7bcb11d3 759 m_printerDC = pdc;
93c2f401 760 ConvertFromNative( m_printDialogData );
7bcb11d3
JS
761 return wxID_OK;
762 }
763 else
764 {
7bcb11d3
JS
765 return wxID_CANCEL;
766 }
2bda0e17
KB
767}
768
c061373d 769wxDC *wxWindowsPrintDialog::GetPrintDC()
2bda0e17 770{
7bcb11d3
JS
771 if (m_printerDC)
772 {
078cf5cb 773 m_destroyDC = false;
7bcb11d3
JS
774 return m_printerDC;
775 }
776 else
bd84061d 777 return NULL;
2bda0e17
KB
778}
779
93c2f401
RR
780bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData &data )
781{
782 wxWindowsPrintNativeData *native_data =
783 (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData();
784 data.GetPrintData().ConvertToNative();
f31a4098 785
93c2f401
RR
786 PRINTDLG *pd = (PRINTDLG*) m_printDlg;
787
788 // Shouldn't have been defined anywhere
789 if (pd)
790 return false;
f31a4098 791
93c2f401
RR
792 pd = new PRINTDLG;
793 memset( pd, 0, sizeof(PRINTDLG) );
794 m_printDlg = (void*) pd;
795
93c2f401 796 pd->lStructSize = sizeof(PRINTDLG);
bd84061d 797 pd->hwndOwner = NULL;
93c2f401
RR
798 pd->hDevMode = NULL; // Will be created by PrintDlg
799 pd->hDevNames = NULL; // Ditto
800
801 pd->Flags = PD_RETURNDEFAULT;
802 pd->nCopies = 1;
f31a4098 803
93c2f401
RR
804 // Pass the devmode data to the PRINTDLG structure, since it'll
805 // be needed when PrintDlg is called.
806 if (pd->hDevMode)
807 GlobalFree(pd->hDevMode);
808
809 // Pass the devnames data to the PRINTDLG structure, since it'll
810 // be needed when PrintDlg is called.
811 if (pd->hDevNames)
812 GlobalFree(pd->hDevNames);
813
5c33522f 814 pd->hDevMode = static_cast<HGLOBAL>(native_data->GetDevMode());
dca0f651 815 native_data->SetDevMode(NULL);
93c2f401
RR
816
817 // Shouldn't assert; we should be able to test Ok-ness at a higher level
818 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
819
5c33522f 820 pd->hDevNames = static_cast<HGLOBAL>(native_data->GetDevNames());
dca0f651 821 native_data->SetDevNames(NULL);
93c2f401
RR
822
823
bd84061d 824 pd->hDC = NULL;
93c2f401
RR
825 pd->nFromPage = (WORD)data.GetFromPage();
826 pd->nToPage = (WORD)data.GetToPage();
827 pd->nMinPage = (WORD)data.GetMinPage();
828 pd->nMaxPage = (WORD)data.GetMaxPage();
829 pd->nCopies = (WORD)data.GetNoCopies();
830
831 pd->Flags = PD_RETURNDC;
93c2f401 832 pd->lStructSize = sizeof( PRINTDLG );
93c2f401 833
bd84061d
VZ
834 pd->hwndOwner = NULL;
835 pd->hInstance = NULL;
312242ea 836 pd->lCustData = 0;
93c2f401
RR
837 pd->lpfnPrintHook = NULL;
838 pd->lpfnSetupHook = NULL;
839 pd->lpPrintTemplateName = NULL;
840 pd->lpSetupTemplateName = NULL;
bd84061d
VZ
841 pd->hPrintTemplate = NULL;
842 pd->hSetupTemplate = NULL;
93c2f401
RR
843
844 if ( data.GetAllPages() )
845 pd->Flags |= PD_ALLPAGES;
846 if ( data.GetSelection() )
847 pd->Flags |= PD_SELECTION;
848 if ( data.GetCollate() )
849 pd->Flags |= PD_COLLATE;
850 if ( data.GetPrintToFile() )
851 pd->Flags |= PD_PRINTTOFILE;
852 if ( !data.GetEnablePrintToFile() )
853 pd->Flags |= PD_DISABLEPRINTTOFILE;
854 if ( !data.GetEnableSelection() )
855 pd->Flags |= PD_NOSELECTION;
856 if ( !data.GetEnablePageNumbers() )
857 pd->Flags |= PD_NOPAGENUMS;
858 else if ( (!data.GetAllPages()) && (!data.GetSelection()) && (data.GetFromPage() != 0) && (data.GetToPage() != 0))
859 pd->Flags |= PD_PAGENUMS;
860 if ( data.GetEnableHelp() )
861 pd->Flags |= PD_SHOWHELP;
f31a4098 862
93c2f401
RR
863 return true;
864}
865
866bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData &data )
867{
868 PRINTDLG *pd = (PRINTDLG*) m_printDlg;
869 if ( pd == NULL )
870 return false;
871
872 wxWindowsPrintNativeData *native_data =
873 (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData();
f31a4098 874
93c2f401
RR
875 // Pass the devmode data back to the wxPrintData structure where it really belongs.
876 if (pd->hDevMode)
877 {
878 if (native_data->GetDevMode())
879 {
5c33522f 880 ::GlobalFree(static_cast<HGLOBAL>(native_data->GetDevMode()));
93c2f401 881 }
dca0f651 882 native_data->SetDevMode(pd->hDevMode);
93c2f401
RR
883 pd->hDevMode = NULL;
884 }
885
886 // Pass the devnames data back to the wxPrintData structure where it really belongs.
887 if (pd->hDevNames)
888 {
889 if (native_data->GetDevNames())
890 {
5c33522f 891 ::GlobalFree(static_cast<HGLOBAL>(native_data->GetDevNames()));
93c2f401 892 }
dca0f651 893 native_data->SetDevNames(pd->hDevNames);
93c2f401
RR
894 pd->hDevNames = NULL;
895 }
896
897 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
898 // into wxWidgets form.
899 native_data->TransferTo( data.GetPrintData() );
900
901 data.SetFromPage( pd->nFromPage );
902 data.SetToPage( pd->nToPage );
903 data.SetMinPage( pd->nMinPage );
904 data.SetMaxPage( pd->nMaxPage );
905 data.SetNoCopies( pd->nCopies );
906
907 data.SetAllPages( (((pd->Flags & PD_PAGENUMS) != PD_PAGENUMS) && ((pd->Flags & PD_SELECTION) != PD_SELECTION)) );
908 data.SetSelection( ((pd->Flags & PD_SELECTION) == PD_SELECTION) );
909 data.SetCollate( ((pd->Flags & PD_COLLATE) == PD_COLLATE) );
910 data.SetPrintToFile( ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE) );
911 data.EnablePrintToFile( ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE) );
912 data.EnableSelection( ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION) );
913 data.EnablePageNumbers( ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS) );
914 data.EnableHelp( ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP) );
c1dc9f83 915
93c2f401
RR
916 return true;
917}
918
103aec29 919// ---------------------------------------------------------------------------
08680429 920// wxWidnowsPageSetupDialog
103aec29 921// ---------------------------------------------------------------------------
2bda0e17 922
08680429 923IMPLEMENT_CLASS(wxWindowsPageSetupDialog, wxPageSetupDialogBase)
c061373d 924
08680429 925wxWindowsPageSetupDialog::wxWindowsPageSetupDialog()
2bda0e17 926{
7bcb11d3 927 m_dialogParent = NULL;
b45dfd0a 928 m_pageDlg = NULL;
2bda0e17
KB
929}
930
08680429 931wxWindowsPageSetupDialog::wxWindowsPageSetupDialog(wxWindow *p, wxPageSetupDialogData *data)
2bda0e17 932{
7bcb11d3 933 Create(p, data);
2bda0e17
KB
934}
935
08680429 936bool wxWindowsPageSetupDialog::Create(wxWindow *p, wxPageSetupDialogData *data)
2bda0e17 937{
7bcb11d3 938 m_dialogParent = p;
b45dfd0a 939 m_pageDlg = NULL;
103aec29 940
7bcb11d3
JS
941 if (data)
942 m_pageSetupData = (*data);
103aec29 943
078cf5cb 944 return true;
2bda0e17
KB
945}
946
08680429 947wxWindowsPageSetupDialog::~wxWindowsPageSetupDialog()
2bda0e17 948{
b45dfd0a
RR
949 PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageDlg;
950 if ( pd && pd->hDevMode )
951 GlobalFree(pd->hDevMode);
952 if ( pd && pd->hDevNames )
953 GlobalFree(pd->hDevNames);
954 if ( pd )
955 delete pd;
2bda0e17
KB
956}
957
08680429 958int wxWindowsPageSetupDialog::ShowModal()
2bda0e17 959{
b45dfd0a 960 ConvertToNative( m_pageSetupData );
f31a4098 961
b45dfd0a 962 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageDlg;
f6bcfd97 963 if (m_dialogParent)
b45dfd0a 964 pd->hwndOwner = (HWND) m_dialogParent->GetHWND();
f6bcfd97 965 else if (wxTheApp->GetTopWindow())
b45dfd0a 966 pd->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND();
f6bcfd97 967 else
b45dfd0a
RR
968 pd->hwndOwner = 0;
969 BOOL retVal = PageSetupDlg( pd ) ;
970 pd->hwndOwner = 0;
f6bcfd97 971 if (retVal)
2bda0e17 972 {
b45dfd0a 973 ConvertFromNative( m_pageSetupData );
7bcb11d3 974 return wxID_OK;
2bda0e17
KB
975 }
976 else
7bcb11d3 977 return wxID_CANCEL;
b45dfd0a
RR
978}
979
08680429 980bool wxWindowsPageSetupDialog::ConvertToNative( wxPageSetupDialogData &data )
b45dfd0a
RR
981{
982 wxWindowsPrintNativeData *native_data =
983 (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData();
984 data.GetPrintData().ConvertToNative();
985
986 PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageDlg;
987
988 // Shouldn't have been defined anywhere
989 if (pd)
990 return false;
f31a4098 991
b45dfd0a 992 pd = new PAGESETUPDLG;
b45dfd0a
RR
993 m_pageDlg = (void *)pd;
994
fd76344e
VZ
995 // We must not set hDevMode and hDevNames when using PSD_RETURNDEFAULT,
996 // otherwise the call to PageSetupDlg() would fail.
997 if ( data.GetDefaultInfo() )
b45dfd0a 998 {
b45dfd0a 999 pd->hDevMode = NULL;
fd76344e 1000 pd->hDevNames = NULL;
b45dfd0a 1001 }
fd76344e
VZ
1002 else
1003 {
1004 // Pass the devmode data (created in m_printData.ConvertToNative)
1005 // to the PRINTDLG structure, since it'll
1006 // be needed when PrintDlg is called.
b45dfd0a 1007
fd76344e
VZ
1008 pd->hDevMode = (HGLOBAL) native_data->GetDevMode();
1009 native_data->SetDevMode(NULL);
b45dfd0a 1010
fd76344e
VZ
1011 // Shouldn't assert; we should be able to test Ok-ness at a higher level
1012 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
b45dfd0a 1013
fd76344e
VZ
1014 // Pass the devnames data (created in m_printData.ConvertToNative)
1015 // to the PRINTDLG structure, since it'll
1016 // be needed when PrintDlg is called.
b45dfd0a 1017
fd76344e
VZ
1018 pd->hDevNames = (HGLOBAL) native_data->GetDevNames();
1019 native_data->SetDevNames(NULL);
1020 }
b45dfd0a
RR
1021
1022 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
1023
1024 if ( data.GetDefaultMinMargins() )
1025 pd->Flags |= PSD_DEFAULTMINMARGINS;
1026 if ( !data.GetEnableMargins() )
1027 pd->Flags |= PSD_DISABLEMARGINS;
1028 if ( !data.GetEnableOrientation() )
1029 pd->Flags |= PSD_DISABLEORIENTATION;
1030 if ( !data.GetEnablePaper() )
1031 pd->Flags |= PSD_DISABLEPAPER;
1032 if ( !data.GetEnablePrinter() )
1033 pd->Flags |= PSD_DISABLEPRINTER;
1034 if ( data.GetDefaultInfo() )
1035 pd->Flags |= PSD_RETURNDEFAULT;
1036 if ( data.GetEnableHelp() )
1037 pd->Flags |= PSD_SHOWHELP;
1038
1039 // We want the units to be in hundredths of a millimetre
1040 pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
1041
1042 pd->lStructSize = sizeof( PAGESETUPDLG );
bd84061d
VZ
1043 pd->hwndOwner = NULL;
1044 pd->hInstance = NULL;
b45dfd0a
RR
1045 // PAGESETUPDLG is in hundreds of a mm
1046 pd->ptPaperSize.x = data.GetPaperSize().x * 100;
1047 pd->ptPaperSize.y = data.GetPaperSize().y * 100;
1048
1049 pd->rtMinMargin.left = data.GetMinMarginTopLeft().x * 100;
1050 pd->rtMinMargin.top = data.GetMinMarginTopLeft().y * 100;
1051 pd->rtMinMargin.right = data.GetMinMarginBottomRight().x * 100;
1052 pd->rtMinMargin.bottom = data.GetMinMarginBottomRight().y * 100;
1053
1054 pd->rtMargin.left = data.GetMarginTopLeft().x * 100;
1055 pd->rtMargin.top = data.GetMarginTopLeft().y * 100;
1056 pd->rtMargin.right = data.GetMarginBottomRight().x * 100;
1057 pd->rtMargin.bottom = data.GetMarginBottomRight().y * 100;
1058
1059 pd->lCustData = 0;
1060 pd->lpfnPageSetupHook = NULL;
1061 pd->lpfnPagePaintHook = NULL;
1062 pd->hPageSetupTemplate = NULL;
1063 pd->lpPageSetupTemplateName = NULL;
1064
b45dfd0a
RR
1065 return true;
1066}
1067
08680429 1068bool wxWindowsPageSetupDialog::ConvertFromNative( wxPageSetupDialogData &data )
b45dfd0a
RR
1069{
1070 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageDlg;
1071 if ( !pd )
1072 return false;
1073
1074 wxWindowsPrintNativeData *native_data =
1075 (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData();
f31a4098 1076
b45dfd0a
RR
1077 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1078 if (pd->hDevMode)
1079 {
1080 if (native_data->GetDevMode())
1081 {
1082 // Make sure we don't leak memory
1083 GlobalFree((HGLOBAL) native_data->GetDevMode());
1084 }
1085 native_data->SetDevMode( (void*) pd->hDevMode );
1086 pd->hDevMode = NULL;
1087 }
f31a4098 1088
b45dfd0a
RR
1089 // Isn't this superfluous? It's called again below.
1090 // data.GetPrintData().ConvertFromNative();
1091
1092 // Pass the devnames data back to the wxPrintData structure where it really belongs.
1093 if (pd->hDevNames)
1094 {
1095 if (native_data->GetDevNames())
1096 {
1097 // Make sure we don't leak memory
1098 GlobalFree((HGLOBAL) native_data->GetDevNames());
1099 }
1100 native_data->SetDevNames((void*) pd->hDevNames);
1101 pd->hDevNames = NULL;
1102 }
1103
1104 data.GetPrintData().ConvertFromNative();
1105
1106 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
1107
1108 data.SetDefaultMinMargins( ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS) );
1109 data.EnableMargins( ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS) );
1110 data.EnableOrientation( ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION) );
1111 data.EnablePaper( ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER) );
1112 data.EnablePrinter( ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER) );
1113 data.SetDefaultInfo( ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT) );
1114 data.EnableHelp( ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP) );
1115
1116 // PAGESETUPDLG is in hundreds of a mm
fa4f4c58
RR
1117 if (data.GetPrintData().GetOrientation() == wxLANDSCAPE)
1118 data.SetPaperSize( wxSize(pd->ptPaperSize.y / 100, pd->ptPaperSize.x / 100) );
1119 else
1120 data.SetPaperSize( wxSize(pd->ptPaperSize.x / 100, pd->ptPaperSize.y / 100) );
b45dfd0a
RR
1121
1122 data.SetMinMarginTopLeft( wxPoint(pd->rtMinMargin.left / 100, pd->rtMinMargin.top / 100) );
1123 data.SetMinMarginBottomRight( wxPoint(pd->rtMinMargin.right / 100, pd->rtMinMargin.bottom / 100) );
1124
1125 data.SetMarginTopLeft( wxPoint(pd->rtMargin.left / 100, pd->rtMargin.top / 100) );
1126 data.SetMarginBottomRight( wxPoint(pd->rtMargin.right / 100, pd->rtMargin.bottom / 100) );
f31a4098 1127
b45dfd0a 1128 return true;
2bda0e17
KB
1129}
1130
f6bcfd97
BP
1131#endif
1132 // wxUSE_PRINTING_ARCHITECTURE