]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: printdlg.cpp | |
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 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
103aec29 | 21 | #pragma implementation "printdlg.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
2bda0e17 KB |
25 | #include "wx/wxprec.h" |
26 | ||
a3b46648 | 27 | #ifdef __BORLANDC__ |
103aec29 | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
12bdd77c JS |
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) | |
f6bcfd97 BP |
34 | |
35 | #ifndef WX_PRECOMP | |
36 | #include "wx/app.h" | |
37 | #endif | |
38 | ||
c061373d | 39 | #include "wx/cmndata.h" |
2bda0e17 | 40 | #include "wx/printdlg.h" |
08680429 | 41 | #include "wx/msw/printdlg.h" |
2bda0e17 | 42 | #include "wx/dcprint.h" |
8850cbd3 | 43 | #include "wx/paper.h" |
2bda0e17 | 44 | |
2bda0e17 | 45 | #include <stdlib.h> |
42e69d6b | 46 | |
660296aa | 47 | #include "wx/msw/wrapcdlg.h" |
2bda0e17 KB |
48 | |
49 | #ifndef __WIN32__ | |
103aec29 | 50 | #include <print.h> |
2bda0e17 KB |
51 | #endif |
52 | ||
8850cbd3 RR |
53 | //---------------------------------------------------------------------------- |
54 | // wxWindowsPrintNativeData | |
55 | //---------------------------------------------------------------------------- | |
56 | ||
57 | #ifdef __WXDEBUG__ | |
58 | static wxString wxGetPrintDlgError() | |
59 | { | |
60 | DWORD err = CommDlgExtendedError(); | |
61 | wxString msg = wxT("Unknown"); | |
62 | switch (err) | |
63 | { | |
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; | |
86 | default: break; | |
87 | } | |
88 | return msg; | |
89 | } | |
90 | #endif | |
91 | ||
92 | static HGLOBAL wxCreateDevNames(const wxString& driverName, const wxString& printerName, const wxString& portName) | |
93 | { | |
94 | HGLOBAL hDev = NULL; | |
f31a4098 WS |
95 | // if (!driverName.empty() && !printerName.empty() && !portName.empty()) |
96 | if (driverName.empty() && printerName.empty() && portName.empty()) | |
8850cbd3 RR |
97 | { |
98 | } | |
99 | else | |
100 | { | |
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); | |
108 | ||
109 | lpDev->wDeviceOffset = (WORD)( lpDev->wDriverOffset + | |
110 | driverName.Length() + 1 ); | |
111 | wxStrcpy((wxChar*)lpDev + lpDev->wDeviceOffset, printerName); | |
112 | ||
113 | lpDev->wOutputOffset = (WORD)( lpDev->wDeviceOffset + | |
114 | printerName.Length() + 1 ); | |
115 | wxStrcpy((wxChar*)lpDev + lpDev->wOutputOffset, portName); | |
116 | ||
117 | lpDev->wDefault = 0; | |
118 | ||
119 | GlobalUnlock(hDev); | |
120 | } | |
121 | ||
122 | return hDev; | |
123 | } | |
124 | ||
125 | IMPLEMENT_CLASS(wxWindowsPrintNativeData, wxPrintNativeDataBase) | |
126 | ||
127 | wxWindowsPrintNativeData::wxWindowsPrintNativeData() | |
128 | { | |
129 | m_devMode = (void*) NULL; | |
130 | m_devNames = (void*) NULL; | |
3168b4c3 | 131 | m_customWindowsPaperId = 0; |
8850cbd3 RR |
132 | } |
133 | ||
134 | wxWindowsPrintNativeData::~wxWindowsPrintNativeData() | |
135 | { | |
136 | HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; | |
137 | if ( hDevMode ) | |
138 | GlobalFree(hDevMode); | |
139 | HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames; | |
140 | if ( hDevNames ) | |
141 | GlobalFree(hDevNames); | |
142 | } | |
143 | ||
144 | bool wxWindowsPrintNativeData::Ok() const | |
145 | { | |
146 | return (m_devMode != NULL) ; | |
147 | } | |
148 | ||
fd64de59 | 149 | bool wxWindowsPrintNativeData::TransferTo( wxPrintData &data ) |
8850cbd3 RR |
150 | { |
151 | HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; | |
152 | HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames; | |
153 | ||
154 | if (!hDevMode) | |
902725ee | 155 | { |
8850cbd3 | 156 | return false; |
902725ee WS |
157 | } |
158 | else | |
8850cbd3 RR |
159 | { |
160 | LPDEVMODE devMode = (LPDEVMODE)GlobalLock(hDevMode); | |
161 | ||
162 | //// Orientation | |
163 | if (devMode->dmFields & DM_ORIENTATION) | |
164 | data.SetOrientation( devMode->dmOrientation ); | |
165 | ||
166 | //// Collation | |
167 | if (devMode->dmFields & DM_COLLATE) | |
168 | { | |
169 | if (devMode->dmCollate == DMCOLLATE_TRUE) | |
170 | data.SetCollate( true ); | |
171 | else | |
172 | data.SetCollate( false ); | |
173 | } | |
174 | ||
175 | //// Number of copies | |
176 | if (devMode->dmFields & DM_COPIES) | |
177 | data.SetNoCopies( devMode->dmCopies ); | |
178 | ||
179 | if (devMode->dmFields & DM_DEFAULTSOURCE) | |
180 | data.SetBin( (wxPrintBin)devMode->dmDefaultSource ); | |
181 | ||
182 | //// Printer name | |
183 | if (devMode->dmDeviceName[0] != 0) | |
184 | data.SetPrinterName( devMode->dmDeviceName ); | |
185 | ||
186 | //// Colour | |
187 | if (devMode->dmFields & DM_COLOR) | |
188 | { | |
189 | if (devMode->dmColor == DMCOLOR_COLOR) | |
190 | data.SetColour( true ); | |
191 | else | |
192 | data.SetColour( false ); | |
193 | } | |
194 | else | |
195 | data.SetColour( true ); | |
196 | ||
197 | //// Paper size | |
198 | ||
199 | // We don't know size of user defined paper and some buggy drivers | |
200 | // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since | |
201 | // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this | |
202 | // code wouldn't set m_paperSize correctly. | |
21c358b2 JS |
203 | |
204 | bool foundPaperSize = false; | |
8850cbd3 RR |
205 | if ((devMode->dmFields & DM_PAPERSIZE) && (devMode->dmPaperSize < DMPAPER_USER)) |
206 | { | |
207 | if (wxThePrintPaperDatabase) | |
208 | { | |
209 | wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize); | |
210 | if (paper) | |
211 | { | |
212 | data.SetPaperId( paper->GetId() ); | |
213 | data.SetPaperSize( wxSize(paper->GetWidth() / 10,paper->GetHeight() / 10) ); | |
3168b4c3 | 214 | m_customWindowsPaperId = 0; |
21c358b2 | 215 | foundPaperSize = true; |
8850cbd3 RR |
216 | } |
217 | } | |
218 | else | |
219 | { | |
220 | // Shouldn't really get here | |
221 | wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative.")); | |
222 | data.SetPaperId( wxPAPER_NONE ); | |
c47addef | 223 | data.SetPaperSize( wxSize(0,0) ); |
3168b4c3 | 224 | m_customWindowsPaperId = 0; |
902725ee | 225 | |
21c358b2 JS |
226 | GlobalUnlock(hDevMode); |
227 | return false; | |
8850cbd3 RR |
228 | } |
229 | } | |
3168b4c3 | 230 | |
21c358b2 | 231 | if (!foundPaperSize && (devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH)) |
8850cbd3 RR |
232 | { |
233 | // DEVMODE is in tenths of a milimeter | |
8850cbd3 | 234 | data.SetPaperSize( wxSize(devMode->dmPaperWidth / 10, devMode->dmPaperLength / 10) ); |
3168b4c3 JS |
235 | data.SetPaperId( wxPAPER_NONE ); |
236 | m_customWindowsPaperId = devMode->dmPaperSize; | |
8850cbd3 RR |
237 | } |
238 | else | |
239 | { | |
3168b4c3 JS |
240 | // Often will reach this for non-standard paper sizes (sizes which |
241 | // wouldn't be in wxWidget's paper database). Setting | |
242 | // m_customWindowsPaperId to devMode->dmPaperSize should be enough | |
243 | // to get this paper size working. | |
c47addef | 244 | data.SetPaperSize( wxSize(0,0) ); |
3168b4c3 JS |
245 | data.SetPaperId( wxPAPER_NONE ); |
246 | m_customWindowsPaperId = devMode->dmPaperSize; | |
8850cbd3 RR |
247 | } |
248 | ||
249 | //// Duplex | |
250 | ||
251 | if (devMode->dmFields & DM_DUPLEX) | |
252 | { | |
253 | switch (devMode->dmDuplex) | |
254 | { | |
255 | case DMDUP_HORIZONTAL: data.SetDuplex( wxDUPLEX_HORIZONTAL ); break; | |
256 | case DMDUP_VERTICAL: data.SetDuplex( wxDUPLEX_VERTICAL ); break; | |
f31a4098 | 257 | default: |
8850cbd3 RR |
258 | case DMDUP_SIMPLEX: data.SetDuplex( wxDUPLEX_SIMPLEX ); break; |
259 | } | |
260 | } | |
261 | else | |
262 | data.SetDuplex( wxDUPLEX_SIMPLEX ); | |
263 | ||
264 | //// Quality | |
265 | ||
266 | if (devMode->dmFields & DM_PRINTQUALITY) | |
267 | { | |
268 | switch (devMode->dmPrintQuality) | |
269 | { | |
270 | case DMRES_MEDIUM: data.SetQuality( wxPRINT_QUALITY_MEDIUM ); break; | |
271 | case DMRES_LOW: data.SetQuality( wxPRINT_QUALITY_LOW ); break; | |
272 | case DMRES_DRAFT: data.SetQuality( wxPRINT_QUALITY_DRAFT ); break; | |
273 | case DMRES_HIGH: data.SetQuality( wxPRINT_QUALITY_HIGH ); break; | |
274 | default: | |
275 | { | |
276 | // TODO: if the printer fills in the resolution in DPI, how | |
277 | // will the application know if it's high, low, draft etc.?? | |
278 | // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values."); | |
279 | data.SetQuality( devMode->dmPrintQuality ); | |
280 | break; | |
281 | ||
282 | } | |
283 | } | |
284 | } | |
285 | else | |
286 | data.SetQuality( wxPRINT_QUALITY_HIGH ); | |
287 | ||
aa96f01c RR |
288 | if (devMode->dmDriverExtra > 0) |
289 | data.SetPrivData( (char *)devMode+devMode->dmSize, devMode->dmDriverExtra ); | |
290 | else | |
291 | data.SetPrivData( NULL, 0 ); | |
292 | ||
8850cbd3 RR |
293 | GlobalUnlock(hDevMode); |
294 | } | |
295 | ||
296 | if (hDevNames) | |
297 | { | |
298 | LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(hDevNames); | |
299 | if (lpDevNames) | |
300 | { | |
301 | // TODO: Unicode-ification | |
302 | ||
303 | // Get the port name | |
304 | // port is obsolete in WIN32 | |
305 | // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset); | |
306 | ||
307 | // Get the printer name | |
308 | wxString printerName = (LPTSTR)lpDevNames + lpDevNames->wDeviceOffset; | |
309 | ||
310 | // Not sure if we should check for this mismatch | |
660296aa | 311 | // wxASSERT_MSG( (m_printerName.empty() || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!"); |
8850cbd3 | 312 | |
f31a4098 | 313 | if (!printerName.empty()) |
8850cbd3 RR |
314 | data.SetPrinterName( printerName ); |
315 | ||
316 | GlobalUnlock(hDevNames); | |
317 | } | |
318 | } | |
f31a4098 | 319 | |
8850cbd3 RR |
320 | return true; |
321 | } | |
322 | ||
fd64de59 | 323 | bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data ) |
8850cbd3 RR |
324 | { |
325 | HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; | |
326 | HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames; | |
327 | if (!hDevMode) | |
328 | { | |
329 | // Use PRINTDLG as a way of creating a DEVMODE object | |
330 | PRINTDLG pd; | |
331 | ||
332 | // GNU-WIN32 has the wrong size PRINTDLG - can't work out why. | |
333 | #ifdef __GNUWIN32__ | |
334 | memset(&pd, 0, 66); | |
335 | pd.lStructSize = 66; | |
336 | #else | |
337 | memset(&pd, 0, sizeof(PRINTDLG)); | |
338 | #ifdef __WXWINCE__ | |
339 | pd.cbStruct = sizeof(PRINTDLG); | |
340 | #else | |
341 | pd.lStructSize = sizeof(PRINTDLG); | |
342 | #endif | |
343 | #endif | |
344 | ||
345 | pd.hwndOwner = (HWND)NULL; | |
346 | pd.hDevMode = NULL; // Will be created by PrintDlg | |
347 | pd.hDevNames = NULL; // Ditto | |
348 | //pd.hInstance = (HINSTANCE) wxGetInstance(); | |
349 | ||
350 | pd.Flags = PD_RETURNDEFAULT; | |
351 | pd.nCopies = 1; | |
352 | ||
353 | // Fill out the DEVMODE structure | |
354 | // so we can use it as input in the 'real' PrintDlg | |
355 | if (!PrintDlg(&pd)) | |
356 | { | |
357 | if ( pd.hDevMode ) | |
358 | GlobalFree(pd.hDevMode); | |
359 | if ( pd.hDevNames ) | |
360 | GlobalFree(pd.hDevNames); | |
361 | pd.hDevMode = NULL; | |
362 | pd.hDevNames = NULL; | |
363 | ||
364 | #if defined(__WXDEBUG__) && defined(__WIN32__) | |
365 | wxString str(wxT("Printing error: ")); | |
366 | str += wxGetPrintDlgError(); | |
367 | wxLogDebug(str); | |
368 | #endif | |
369 | } | |
370 | else | |
371 | { | |
372 | hDevMode = pd.hDevMode; | |
373 | m_devMode = (void*)(long) hDevMode; | |
374 | pd.hDevMode = NULL; | |
375 | ||
376 | // We'll create a new DEVNAMEs structure below. | |
377 | if ( pd.hDevNames ) | |
378 | GlobalFree(pd.hDevNames); | |
379 | pd.hDevNames = NULL; | |
380 | ||
381 | // hDevNames = pd->hDevNames; | |
382 | // m_devNames = (void*)(long) hDevNames; | |
383 | // pd->hDevnames = NULL; | |
384 | ||
385 | } | |
386 | } | |
387 | ||
388 | if ( hDevMode ) | |
389 | { | |
390 | LPDEVMODE devMode = (LPDEVMODE) GlobalLock(hDevMode); | |
391 | ||
392 | //// Orientation | |
393 | devMode->dmOrientation = (short)data.GetOrientation(); | |
394 | ||
395 | //// Collation | |
396 | devMode->dmCollate = (data.GetCollate() ? DMCOLLATE_TRUE : DMCOLLATE_FALSE); | |
397 | devMode->dmFields |= DM_COLLATE; | |
398 | ||
399 | //// Number of copies | |
400 | devMode->dmCopies = (short)data.GetNoCopies(); | |
401 | devMode->dmFields |= DM_COPIES; | |
402 | ||
403 | //// Printer name | |
404 | wxString name = data.GetPrinterName(); | |
f31a4098 | 405 | if (!name.empty()) |
8850cbd3 RR |
406 | { |
407 | //int len = wxMin(31, m_printerName.Len()); | |
408 | wxStrncpy((wxChar*)devMode->dmDeviceName,name.c_str(),31); | |
409 | devMode->dmDeviceName[31] = wxT('\0'); | |
410 | } | |
411 | ||
412 | //// Colour | |
413 | if (data.GetColour()) | |
414 | devMode->dmColor = DMCOLOR_COLOR; | |
415 | else | |
416 | devMode->dmColor = DMCOLOR_MONOCHROME; | |
417 | devMode->dmFields |= DM_COLOR; | |
418 | ||
419 | //// Paper size | |
420 | if (data.GetPaperId() == wxPAPER_NONE) | |
421 | { | |
422 | // DEVMODE is in tenths of a milimeter | |
423 | devMode->dmPaperWidth = (short)(data.GetPaperSize().x * 10); | |
424 | devMode->dmPaperLength = (short)(data.GetPaperSize().y * 10); | |
3168b4c3 JS |
425 | if(m_customWindowsPaperId != 0) |
426 | devMode->dmPaperSize = m_customWindowsPaperId; | |
427 | else | |
428 | devMode->dmPaperSize = DMPAPER_USER; | |
8850cbd3 RR |
429 | devMode->dmFields |= DM_PAPERWIDTH; |
430 | devMode->dmFields |= DM_PAPERLENGTH; | |
431 | } | |
432 | else | |
433 | { | |
434 | if (wxThePrintPaperDatabase) | |
435 | { | |
436 | wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType( data.GetPaperId() ); | |
437 | if (paper) | |
438 | { | |
439 | devMode->dmPaperSize = (short)paper->GetPlatformId(); | |
440 | devMode->dmFields |= DM_PAPERSIZE; | |
441 | } | |
21c358b2 JS |
442 | else |
443 | { | |
444 | // Fall back on specifying the paper size explicitly | |
445 | devMode->dmPaperWidth = (short)(data.GetPaperSize().x * 10); | |
446 | devMode->dmPaperLength = (short)(data.GetPaperSize().y * 10); | |
447 | devMode->dmPaperSize = DMPAPER_USER; | |
448 | devMode->dmFields |= DM_PAPERWIDTH; | |
449 | devMode->dmFields |= DM_PAPERLENGTH; | |
450 | } | |
8850cbd3 RR |
451 | } |
452 | } | |
453 | ||
454 | //// Duplex | |
455 | short duplex; | |
456 | switch (data.GetDuplex()) | |
457 | { | |
458 | case wxDUPLEX_HORIZONTAL: | |
459 | duplex = DMDUP_HORIZONTAL; | |
460 | break; | |
461 | case wxDUPLEX_VERTICAL: | |
462 | duplex = DMDUP_VERTICAL; | |
463 | break; | |
464 | default: | |
465 | // in fact case wxDUPLEX_SIMPLEX: | |
466 | duplex = DMDUP_SIMPLEX; | |
467 | break; | |
468 | } | |
469 | devMode->dmDuplex = duplex; | |
470 | devMode->dmFields |= DM_DUPLEX; | |
471 | ||
472 | //// Quality | |
473 | ||
474 | short quality; | |
475 | switch (data.GetQuality()) | |
476 | { | |
477 | case wxPRINT_QUALITY_MEDIUM: | |
478 | quality = DMRES_MEDIUM; | |
479 | break; | |
480 | case wxPRINT_QUALITY_LOW: | |
481 | quality = DMRES_LOW; | |
482 | break; | |
483 | case wxPRINT_QUALITY_DRAFT: | |
484 | quality = DMRES_DRAFT; | |
485 | break; | |
486 | case wxPRINT_QUALITY_HIGH: | |
487 | quality = DMRES_HIGH; | |
488 | break; | |
489 | default: | |
490 | quality = (short)data.GetQuality(); | |
491 | break; | |
492 | } | |
493 | devMode->dmPrintQuality = quality; | |
494 | devMode->dmFields |= DM_PRINTQUALITY; | |
4e22a1f2 | 495 | |
aa96f01c RR |
496 | if (data.GetPrivDataLen() > 0) |
497 | { | |
498 | memcpy( (char *)devMode+devMode->dmSize, data.GetPrivData(), data.GetPrivDataLen() ); | |
4e22a1f2 | 499 | devMode->dmDriverExtra = (WXWORD)data.GetPrivDataLen(); |
aa96f01c | 500 | } |
8850cbd3 RR |
501 | |
502 | if (data.GetBin() != wxPRINTBIN_DEFAULT) | |
503 | { | |
504 | switch (data.GetBin()) | |
505 | { | |
506 | case wxPRINTBIN_ONLYONE: devMode->dmDefaultSource = DMBIN_ONLYONE; break; | |
507 | case wxPRINTBIN_LOWER: devMode->dmDefaultSource = DMBIN_LOWER; break; | |
508 | case wxPRINTBIN_MIDDLE: devMode->dmDefaultSource = DMBIN_MIDDLE; break; | |
509 | case wxPRINTBIN_MANUAL: devMode->dmDefaultSource = DMBIN_MANUAL; break; | |
510 | case wxPRINTBIN_ENVELOPE: devMode->dmDefaultSource = DMBIN_ENVELOPE; break; | |
511 | case wxPRINTBIN_ENVMANUAL: devMode->dmDefaultSource = DMBIN_ENVMANUAL; break; | |
512 | case wxPRINTBIN_AUTO: devMode->dmDefaultSource = DMBIN_AUTO; break; | |
513 | case wxPRINTBIN_TRACTOR: devMode->dmDefaultSource = DMBIN_TRACTOR; break; | |
514 | case wxPRINTBIN_SMALLFMT: devMode->dmDefaultSource = DMBIN_SMALLFMT; break; | |
515 | case wxPRINTBIN_LARGEFMT: devMode->dmDefaultSource = DMBIN_LARGEFMT; break; | |
516 | case wxPRINTBIN_LARGECAPACITY: devMode->dmDefaultSource = DMBIN_LARGECAPACITY; break; | |
517 | case wxPRINTBIN_CASSETTE: devMode->dmDefaultSource = DMBIN_CASSETTE; break; | |
518 | case wxPRINTBIN_FORMSOURCE: devMode->dmDefaultSource = DMBIN_FORMSOURCE; break; | |
519 | ||
520 | default: | |
521 | devMode->dmDefaultSource = (short)(DMBIN_USER + data.GetBin() - wxPRINTBIN_USER); | |
522 | break; | |
523 | } | |
524 | ||
525 | devMode->dmFields |= DM_DEFAULTSOURCE; | |
526 | } | |
527 | ||
528 | GlobalUnlock(hDevMode); | |
529 | } | |
530 | ||
531 | if ( hDevNames ) | |
532 | { | |
533 | GlobalFree(hDevNames); | |
534 | } | |
535 | ||
536 | // TODO: I hope it's OK to pass some empty strings to DEVNAMES. | |
f31a4098 WS |
537 | m_devNames = (void*) (long) wxCreateDevNames(wxEmptyString, data.GetPrinterName(), wxEmptyString); |
538 | ||
8850cbd3 RR |
539 | return true; |
540 | } | |
f31a4098 | 541 | |
103aec29 VZ |
542 | // --------------------------------------------------------------------------- |
543 | // wxPrintDialog | |
544 | // --------------------------------------------------------------------------- | |
545 | ||
c061373d | 546 | IMPLEMENT_CLASS(wxWindowsPrintDialog, wxPrintDialogBase) |
2bda0e17 | 547 | |
c061373d | 548 | wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow *p, wxPrintDialogData* data) |
2bda0e17 | 549 | { |
7bcb11d3 | 550 | Create(p, data); |
2bda0e17 KB |
551 | } |
552 | ||
c061373d | 553 | wxWindowsPrintDialog::wxWindowsPrintDialog(wxWindow *p, wxPrintData* data) |
103aec29 VZ |
554 | { |
555 | wxPrintDialogData data2; | |
556 | if ( data ) | |
557 | data2 = *data; | |
558 | ||
559 | Create(p, &data2); | |
560 | } | |
561 | ||
c061373d | 562 | bool wxWindowsPrintDialog::Create(wxWindow *p, wxPrintDialogData* data) |
2bda0e17 | 563 | { |
7bcb11d3 JS |
564 | m_dialogParent = p; |
565 | m_printerDC = NULL; | |
078cf5cb | 566 | m_destroyDC = true; |
7bcb11d3 | 567 | |
93c2f401 RR |
568 | // MSW handle |
569 | m_printDlg = NULL; | |
f31a4098 | 570 | |
7bcb11d3 JS |
571 | if ( data ) |
572 | m_printDialogData = *data; | |
103aec29 | 573 | |
078cf5cb | 574 | return true; |
2bda0e17 KB |
575 | } |
576 | ||
c061373d | 577 | wxWindowsPrintDialog::~wxWindowsPrintDialog() |
2bda0e17 | 578 | { |
93c2f401 RR |
579 | PRINTDLG *pd = (PRINTDLG *) m_printDlg; |
580 | if (pd && pd->hDevMode) | |
581 | GlobalFree(pd->hDevMode); | |
582 | if ( pd ) | |
583 | delete pd; | |
584 | ||
7bcb11d3 JS |
585 | if (m_destroyDC && m_printerDC) |
586 | delete m_printerDC; | |
2bda0e17 KB |
587 | } |
588 | ||
c061373d | 589 | int wxWindowsPrintDialog::ShowModal() |
2bda0e17 | 590 | { |
93c2f401 | 591 | ConvertToNative( m_printDialogData ); |
103aec29 | 592 | |
93c2f401 | 593 | PRINTDLG *pd = (PRINTDLG*) m_printDlg; |
f31a4098 | 594 | |
f6bcfd97 | 595 | if (m_dialogParent) |
93c2f401 | 596 | pd->hwndOwner = (HWND) m_dialogParent->GetHWND(); |
f6bcfd97 | 597 | else if (wxTheApp->GetTopWindow()) |
93c2f401 | 598 | pd->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND(); |
f6bcfd97 | 599 | else |
93c2f401 | 600 | pd->hwndOwner = 0; |
f6bcfd97 | 601 | |
93c2f401 | 602 | bool ret = (PrintDlg( pd ) != 0); |
f6bcfd97 | 603 | |
93c2f401 | 604 | pd->hwndOwner = 0; |
f6bcfd97 | 605 | |
93c2f401 | 606 | if ( ret != false && (pd->hDC) ) |
7bcb11d3 | 607 | { |
93c2f401 | 608 | wxPrinterDC *pdc = new wxPrinterDC( (WXHDC) pd->hDC ); |
7bcb11d3 | 609 | m_printerDC = pdc; |
93c2f401 | 610 | ConvertFromNative( m_printDialogData ); |
7bcb11d3 JS |
611 | return wxID_OK; |
612 | } | |
613 | else | |
614 | { | |
7bcb11d3 JS |
615 | return wxID_CANCEL; |
616 | } | |
2bda0e17 KB |
617 | } |
618 | ||
c061373d | 619 | wxDC *wxWindowsPrintDialog::GetPrintDC() |
2bda0e17 | 620 | { |
7bcb11d3 JS |
621 | if (m_printerDC) |
622 | { | |
078cf5cb | 623 | m_destroyDC = false; |
7bcb11d3 JS |
624 | return m_printerDC; |
625 | } | |
626 | else | |
627 | return (wxDC*) NULL; | |
2bda0e17 KB |
628 | } |
629 | ||
93c2f401 RR |
630 | bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData &data ) |
631 | { | |
632 | wxWindowsPrintNativeData *native_data = | |
633 | (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData(); | |
634 | data.GetPrintData().ConvertToNative(); | |
f31a4098 | 635 | |
93c2f401 RR |
636 | PRINTDLG *pd = (PRINTDLG*) m_printDlg; |
637 | ||
638 | // Shouldn't have been defined anywhere | |
639 | if (pd) | |
640 | return false; | |
f31a4098 | 641 | |
93c2f401 RR |
642 | pd = new PRINTDLG; |
643 | memset( pd, 0, sizeof(PRINTDLG) ); | |
644 | m_printDlg = (void*) pd; | |
645 | ||
646 | // GNU-WIN32 has the wrong size PRINTDLG - can't work out why. | |
647 | #ifdef __GNUWIN32__ | |
648 | pd->lStructSize = 66; | |
649 | #else | |
650 | pd->lStructSize = sizeof(PRINTDLG); | |
651 | #endif | |
652 | pd->hwndOwner = (HWND)NULL; | |
653 | pd->hDevMode = NULL; // Will be created by PrintDlg | |
654 | pd->hDevNames = NULL; // Ditto | |
655 | ||
656 | pd->Flags = PD_RETURNDEFAULT; | |
657 | pd->nCopies = 1; | |
f31a4098 | 658 | |
93c2f401 RR |
659 | // Pass the devmode data to the PRINTDLG structure, since it'll |
660 | // be needed when PrintDlg is called. | |
661 | if (pd->hDevMode) | |
662 | GlobalFree(pd->hDevMode); | |
663 | ||
664 | // Pass the devnames data to the PRINTDLG structure, since it'll | |
665 | // be needed when PrintDlg is called. | |
666 | if (pd->hDevNames) | |
667 | GlobalFree(pd->hDevNames); | |
668 | ||
669 | pd->hDevMode = (HGLOBAL)(DWORD) native_data->GetDevMode(); | |
670 | native_data->SetDevMode( (void*) NULL); | |
671 | ||
672 | // Shouldn't assert; we should be able to test Ok-ness at a higher level | |
673 | //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); | |
674 | ||
675 | pd->hDevNames = (HGLOBAL)(DWORD) native_data->GetDevNames(); | |
676 | native_data->SetDevNames( (void*) NULL); | |
677 | ||
678 | ||
679 | pd->hDC = (HDC) NULL; | |
680 | pd->nFromPage = (WORD)data.GetFromPage(); | |
681 | pd->nToPage = (WORD)data.GetToPage(); | |
682 | pd->nMinPage = (WORD)data.GetMinPage(); | |
683 | pd->nMaxPage = (WORD)data.GetMaxPage(); | |
684 | pd->nCopies = (WORD)data.GetNoCopies(); | |
685 | ||
686 | pd->Flags = PD_RETURNDC; | |
687 | ||
688 | #ifdef __GNUWIN32__ | |
689 | pd->lStructSize = 66; | |
690 | #else | |
691 | pd->lStructSize = sizeof( PRINTDLG ); | |
692 | #endif | |
693 | ||
694 | pd->hwndOwner=(HWND)NULL; | |
695 | // pd->hDevNames=(HANDLE)NULL; | |
696 | pd->hInstance=(HINSTANCE)NULL; | |
697 | pd->lCustData = (LPARAM) NULL; | |
698 | pd->lpfnPrintHook = NULL; | |
699 | pd->lpfnSetupHook = NULL; | |
700 | pd->lpPrintTemplateName = NULL; | |
701 | pd->lpSetupTemplateName = NULL; | |
702 | pd->hPrintTemplate = (HGLOBAL) NULL; | |
703 | pd->hSetupTemplate = (HGLOBAL) NULL; | |
704 | ||
705 | if ( data.GetAllPages() ) | |
706 | pd->Flags |= PD_ALLPAGES; | |
707 | if ( data.GetSelection() ) | |
708 | pd->Flags |= PD_SELECTION; | |
709 | if ( data.GetCollate() ) | |
710 | pd->Flags |= PD_COLLATE; | |
711 | if ( data.GetPrintToFile() ) | |
712 | pd->Flags |= PD_PRINTTOFILE; | |
713 | if ( !data.GetEnablePrintToFile() ) | |
714 | pd->Flags |= PD_DISABLEPRINTTOFILE; | |
715 | if ( !data.GetEnableSelection() ) | |
716 | pd->Flags |= PD_NOSELECTION; | |
717 | if ( !data.GetEnablePageNumbers() ) | |
718 | pd->Flags |= PD_NOPAGENUMS; | |
719 | else if ( (!data.GetAllPages()) && (!data.GetSelection()) && (data.GetFromPage() != 0) && (data.GetToPage() != 0)) | |
720 | pd->Flags |= PD_PAGENUMS; | |
721 | if ( data.GetEnableHelp() ) | |
722 | pd->Flags |= PD_SHOWHELP; | |
b45dfd0a | 723 | #if WXWIN_COMPATIBILITY_2_4 |
93c2f401 RR |
724 | if ( data.GetSetupDialog() ) |
725 | pd->Flags |= PD_PRINTSETUP; | |
b45dfd0a | 726 | #endif |
f31a4098 | 727 | |
93c2f401 RR |
728 | return true; |
729 | } | |
730 | ||
731 | bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData &data ) | |
732 | { | |
733 | PRINTDLG *pd = (PRINTDLG*) m_printDlg; | |
734 | if ( pd == NULL ) | |
735 | return false; | |
736 | ||
737 | wxWindowsPrintNativeData *native_data = | |
738 | (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData(); | |
f31a4098 | 739 | |
93c2f401 RR |
740 | // Pass the devmode data back to the wxPrintData structure where it really belongs. |
741 | if (pd->hDevMode) | |
742 | { | |
743 | if (native_data->GetDevMode()) | |
744 | { | |
745 | // Make sure we don't leak memory | |
746 | GlobalFree( (HGLOBAL)(DWORD) native_data->GetDevMode() ); | |
747 | } | |
748 | native_data->SetDevMode( (void*)(long) pd->hDevMode ); | |
749 | pd->hDevMode = NULL; | |
750 | } | |
751 | ||
752 | // Pass the devnames data back to the wxPrintData structure where it really belongs. | |
753 | if (pd->hDevNames) | |
754 | { | |
755 | if (native_data->GetDevNames()) | |
756 | { | |
757 | // Make sure we don't leak memory | |
758 | GlobalFree((HGLOBAL)(DWORD) native_data->GetDevNames()); | |
759 | } | |
760 | native_data->SetDevNames((void*)(long) pd->hDevNames); | |
761 | pd->hDevNames = NULL; | |
762 | } | |
763 | ||
764 | // Now convert the DEVMODE object, passed down from the PRINTDLG object, | |
765 | // into wxWidgets form. | |
766 | native_data->TransferTo( data.GetPrintData() ); | |
767 | ||
768 | data.SetFromPage( pd->nFromPage ); | |
769 | data.SetToPage( pd->nToPage ); | |
770 | data.SetMinPage( pd->nMinPage ); | |
771 | data.SetMaxPage( pd->nMaxPage ); | |
772 | data.SetNoCopies( pd->nCopies ); | |
773 | ||
774 | data.SetAllPages( (((pd->Flags & PD_PAGENUMS) != PD_PAGENUMS) && ((pd->Flags & PD_SELECTION) != PD_SELECTION)) ); | |
775 | data.SetSelection( ((pd->Flags & PD_SELECTION) == PD_SELECTION) ); | |
776 | data.SetCollate( ((pd->Flags & PD_COLLATE) == PD_COLLATE) ); | |
777 | data.SetPrintToFile( ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE) ); | |
778 | data.EnablePrintToFile( ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE) ); | |
779 | data.EnableSelection( ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION) ); | |
780 | data.EnablePageNumbers( ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS) ); | |
781 | data.EnableHelp( ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP) ); | |
b45dfd0a | 782 | #if WXWIN_COMPATIBILITY_2_4 |
93c2f401 | 783 | data.SetSetupDialog( ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP) ); |
f31a4098 | 784 | #endif |
93c2f401 RR |
785 | return true; |
786 | } | |
787 | ||
103aec29 | 788 | // --------------------------------------------------------------------------- |
08680429 | 789 | // wxWidnowsPageSetupDialog |
103aec29 | 790 | // --------------------------------------------------------------------------- |
2bda0e17 | 791 | |
08680429 | 792 | IMPLEMENT_CLASS(wxWindowsPageSetupDialog, wxPageSetupDialogBase) |
c061373d | 793 | |
08680429 | 794 | wxWindowsPageSetupDialog::wxWindowsPageSetupDialog() |
2bda0e17 | 795 | { |
7bcb11d3 | 796 | m_dialogParent = NULL; |
b45dfd0a | 797 | m_pageDlg = NULL; |
2bda0e17 KB |
798 | } |
799 | ||
08680429 | 800 | wxWindowsPageSetupDialog::wxWindowsPageSetupDialog(wxWindow *p, wxPageSetupDialogData *data) |
2bda0e17 | 801 | { |
7bcb11d3 | 802 | Create(p, data); |
2bda0e17 KB |
803 | } |
804 | ||
08680429 | 805 | bool wxWindowsPageSetupDialog::Create(wxWindow *p, wxPageSetupDialogData *data) |
2bda0e17 | 806 | { |
7bcb11d3 | 807 | m_dialogParent = p; |
b45dfd0a | 808 | m_pageDlg = NULL; |
103aec29 | 809 | |
7bcb11d3 JS |
810 | if (data) |
811 | m_pageSetupData = (*data); | |
103aec29 | 812 | |
078cf5cb | 813 | return true; |
2bda0e17 KB |
814 | } |
815 | ||
08680429 | 816 | wxWindowsPageSetupDialog::~wxWindowsPageSetupDialog() |
2bda0e17 | 817 | { |
b45dfd0a RR |
818 | PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageDlg; |
819 | if ( pd && pd->hDevMode ) | |
820 | GlobalFree(pd->hDevMode); | |
821 | if ( pd && pd->hDevNames ) | |
822 | GlobalFree(pd->hDevNames); | |
823 | if ( pd ) | |
824 | delete pd; | |
2bda0e17 KB |
825 | } |
826 | ||
08680429 | 827 | int wxWindowsPageSetupDialog::ShowModal() |
2bda0e17 | 828 | { |
b45dfd0a | 829 | ConvertToNative( m_pageSetupData ); |
f31a4098 | 830 | |
b45dfd0a | 831 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageDlg; |
f6bcfd97 | 832 | if (m_dialogParent) |
b45dfd0a | 833 | pd->hwndOwner = (HWND) m_dialogParent->GetHWND(); |
f6bcfd97 | 834 | else if (wxTheApp->GetTopWindow()) |
b45dfd0a | 835 | pd->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND(); |
f6bcfd97 | 836 | else |
b45dfd0a RR |
837 | pd->hwndOwner = 0; |
838 | BOOL retVal = PageSetupDlg( pd ) ; | |
839 | pd->hwndOwner = 0; | |
f6bcfd97 | 840 | if (retVal) |
2bda0e17 | 841 | { |
b45dfd0a | 842 | ConvertFromNative( m_pageSetupData ); |
7bcb11d3 | 843 | return wxID_OK; |
2bda0e17 KB |
844 | } |
845 | else | |
7bcb11d3 | 846 | return wxID_CANCEL; |
b45dfd0a RR |
847 | } |
848 | ||
08680429 | 849 | bool wxWindowsPageSetupDialog::ConvertToNative( wxPageSetupDialogData &data ) |
b45dfd0a RR |
850 | { |
851 | wxWindowsPrintNativeData *native_data = | |
852 | (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData(); | |
853 | data.GetPrintData().ConvertToNative(); | |
854 | ||
855 | PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageDlg; | |
856 | ||
857 | // Shouldn't have been defined anywhere | |
858 | if (pd) | |
859 | return false; | |
f31a4098 | 860 | |
b45dfd0a RR |
861 | pd = new PAGESETUPDLG; |
862 | pd->hDevMode = NULL; | |
863 | pd->hDevNames = NULL; | |
864 | m_pageDlg = (void *)pd; | |
865 | ||
866 | // Pass the devmode data (created in m_printData.ConvertToNative) | |
867 | // to the PRINTDLG structure, since it'll | |
868 | // be needed when PrintDlg is called. | |
869 | ||
870 | if (pd->hDevMode) | |
871 | { | |
872 | GlobalFree(pd->hDevMode); | |
873 | pd->hDevMode = NULL; | |
874 | } | |
875 | pd->hDevMode = (HGLOBAL) native_data->GetDevMode(); | |
876 | native_data->SetDevMode( (void*) NULL ); | |
877 | ||
878 | // Shouldn't assert; we should be able to test Ok-ness at a higher level | |
879 | //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); | |
880 | ||
881 | // Pass the devnames data (created in m_printData.ConvertToNative) | |
882 | // to the PRINTDLG structure, since it'll | |
883 | // be needed when PrintDlg is called. | |
884 | ||
885 | if (pd->hDevNames) | |
886 | { | |
887 | GlobalFree(pd->hDevNames); | |
888 | pd->hDevNames = NULL; | |
889 | } | |
890 | pd->hDevNames = (HGLOBAL) native_data->GetDevNames(); | |
891 | native_data->SetDevNames((void*) NULL); | |
892 | ||
893 | // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE)); | |
894 | ||
895 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; | |
896 | ||
897 | if ( data.GetDefaultMinMargins() ) | |
898 | pd->Flags |= PSD_DEFAULTMINMARGINS; | |
899 | if ( !data.GetEnableMargins() ) | |
900 | pd->Flags |= PSD_DISABLEMARGINS; | |
901 | if ( !data.GetEnableOrientation() ) | |
902 | pd->Flags |= PSD_DISABLEORIENTATION; | |
903 | if ( !data.GetEnablePaper() ) | |
904 | pd->Flags |= PSD_DISABLEPAPER; | |
905 | if ( !data.GetEnablePrinter() ) | |
906 | pd->Flags |= PSD_DISABLEPRINTER; | |
907 | if ( data.GetDefaultInfo() ) | |
908 | pd->Flags |= PSD_RETURNDEFAULT; | |
909 | if ( data.GetEnableHelp() ) | |
910 | pd->Flags |= PSD_SHOWHELP; | |
911 | ||
912 | // We want the units to be in hundredths of a millimetre | |
913 | pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS; | |
914 | ||
915 | pd->lStructSize = sizeof( PAGESETUPDLG ); | |
916 | pd->hwndOwner=(HWND)NULL; | |
917 | // pd->hDevNames=(HWND)NULL; | |
918 | pd->hInstance=(HINSTANCE)NULL; | |
919 | // PAGESETUPDLG is in hundreds of a mm | |
920 | pd->ptPaperSize.x = data.GetPaperSize().x * 100; | |
921 | pd->ptPaperSize.y = data.GetPaperSize().y * 100; | |
922 | ||
923 | pd->rtMinMargin.left = data.GetMinMarginTopLeft().x * 100; | |
924 | pd->rtMinMargin.top = data.GetMinMarginTopLeft().y * 100; | |
925 | pd->rtMinMargin.right = data.GetMinMarginBottomRight().x * 100; | |
926 | pd->rtMinMargin.bottom = data.GetMinMarginBottomRight().y * 100; | |
927 | ||
928 | pd->rtMargin.left = data.GetMarginTopLeft().x * 100; | |
929 | pd->rtMargin.top = data.GetMarginTopLeft().y * 100; | |
930 | pd->rtMargin.right = data.GetMarginBottomRight().x * 100; | |
931 | pd->rtMargin.bottom = data.GetMarginBottomRight().y * 100; | |
932 | ||
933 | pd->lCustData = 0; | |
934 | pd->lpfnPageSetupHook = NULL; | |
935 | pd->lpfnPagePaintHook = NULL; | |
936 | pd->hPageSetupTemplate = NULL; | |
937 | pd->lpPageSetupTemplateName = NULL; | |
938 | ||
939 | /* | |
940 | if ( pd->hDevMode ) | |
941 | { | |
942 | DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode); | |
943 | memset(devMode, 0, sizeof(DEVMODE)); | |
944 | devMode->dmSize = sizeof(DEVMODE); | |
945 | devMode->dmOrientation = m_orientation; | |
946 | devMode->dmFields = DM_ORIENTATION; | |
947 | GlobalUnlock(pd->hDevMode); | |
948 | } | |
949 | */ | |
950 | return true; | |
951 | } | |
952 | ||
08680429 | 953 | bool wxWindowsPageSetupDialog::ConvertFromNative( wxPageSetupDialogData &data ) |
b45dfd0a RR |
954 | { |
955 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageDlg; | |
956 | if ( !pd ) | |
957 | return false; | |
958 | ||
959 | wxWindowsPrintNativeData *native_data = | |
960 | (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData(); | |
f31a4098 | 961 | |
b45dfd0a RR |
962 | // Pass the devmode data back to the wxPrintData structure where it really belongs. |
963 | if (pd->hDevMode) | |
964 | { | |
965 | if (native_data->GetDevMode()) | |
966 | { | |
967 | // Make sure we don't leak memory | |
968 | GlobalFree((HGLOBAL) native_data->GetDevMode()); | |
969 | } | |
970 | native_data->SetDevMode( (void*) pd->hDevMode ); | |
971 | pd->hDevMode = NULL; | |
972 | } | |
f31a4098 | 973 | |
b45dfd0a RR |
974 | // Isn't this superfluous? It's called again below. |
975 | // data.GetPrintData().ConvertFromNative(); | |
976 | ||
977 | // Pass the devnames data back to the wxPrintData structure where it really belongs. | |
978 | if (pd->hDevNames) | |
979 | { | |
980 | if (native_data->GetDevNames()) | |
981 | { | |
982 | // Make sure we don't leak memory | |
983 | GlobalFree((HGLOBAL) native_data->GetDevNames()); | |
984 | } | |
985 | native_data->SetDevNames((void*) pd->hDevNames); | |
986 | pd->hDevNames = NULL; | |
987 | } | |
988 | ||
989 | data.GetPrintData().ConvertFromNative(); | |
990 | ||
991 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; | |
992 | ||
993 | data.SetDefaultMinMargins( ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS) ); | |
994 | data.EnableMargins( ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS) ); | |
995 | data.EnableOrientation( ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION) ); | |
996 | data.EnablePaper( ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER) ); | |
997 | data.EnablePrinter( ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER) ); | |
998 | data.SetDefaultInfo( ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT) ); | |
999 | data.EnableHelp( ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP) ); | |
1000 | ||
1001 | // PAGESETUPDLG is in hundreds of a mm | |
1002 | data.SetPaperSize( wxSize(pd->ptPaperSize.x / 100, pd->ptPaperSize.y / 100) ); | |
1003 | ||
1004 | data.SetMinMarginTopLeft( wxPoint(pd->rtMinMargin.left / 100, pd->rtMinMargin.top / 100) ); | |
1005 | data.SetMinMarginBottomRight( wxPoint(pd->rtMinMargin.right / 100, pd->rtMinMargin.bottom / 100) ); | |
1006 | ||
1007 | data.SetMarginTopLeft( wxPoint(pd->rtMargin.left / 100, pd->rtMargin.top / 100) ); | |
1008 | data.SetMarginBottomRight( wxPoint(pd->rtMargin.right / 100, pd->rtMargin.bottom / 100) ); | |
f31a4098 | 1009 | |
b45dfd0a | 1010 | return true; |
2bda0e17 KB |
1011 | } |
1012 | ||
f6bcfd97 BP |
1013 | #endif |
1014 | // wxUSE_PRINTING_ARCHITECTURE |