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