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