]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: cmndata.cpp | |
3 | // Purpose: Common GDI data | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
8bbe427f | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8826f46f VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
c801d85f | 20 | #ifdef __GNUG__ |
8826f46f | 21 | #pragma implementation "cmndata.h" |
c801d85f KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
8826f46f | 28 | #pragma hdrstop |
c801d85f KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
8826f46f VZ |
32 | #include <stdio.h> |
33 | #include "wx/string.h" | |
34 | #include "wx/utils.h" | |
35 | #include "wx/app.h" | |
c801d85f KB |
36 | #endif |
37 | ||
38 | #include "wx/gdicmn.h" | |
39 | #include "wx/cmndata.h" | |
6776a0b2 | 40 | #include "wx/log.h" |
8826f46f | 41 | |
7bcb11d3 JS |
42 | // For compatibility |
43 | #if (defined(__WXMOTIF__) || defined(__WXGTK__)) && wxUSE_POSTSCRIPT | |
8826f46f | 44 | #define wxCOMPATIBILITY_WITH_PRINTSETUPDATA 1 |
7bcb11d3 | 45 | #endif |
c801d85f | 46 | |
88ac883a VZ |
47 | #if wxUSE_PRINTING_ARCHITECTURE |
48 | #include "wx/paper.h" | |
49 | ||
50 | #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA | |
51 | #include "wx/generic/dcpsg.h" | |
52 | #endif | |
53 | #endif // wxUSE_PRINTING_ARCHITECTURE | |
7be1f0d9 | 54 | |
8826f46f VZ |
55 | #ifdef __WXMSW__ |
56 | #include <windows.h> | |
6aa55ce7 | 57 | #include <wx/msw/private.h> |
7be1f0d9 | 58 | |
8826f46f VZ |
59 | #if !defined(__WIN32__) |
60 | #include <print.h> | |
61 | #include <commdlg.h> | |
62 | #endif // Win16 | |
63 | ||
64 | #if defined(__WATCOMC__) || defined(__SC__) || defined(__SALFORDC__) | |
65 | #include <windowsx.h> | |
66 | #include <commdlg.h> | |
67 | #endif | |
68 | #endif // MSW | |
c801d85f KB |
69 | |
70 | #if !USE_SHARED_LIBRARY | |
88ac883a VZ |
71 | #if wxUSE_PRINTING_ARCHITECTURE |
72 | IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject) | |
73 | IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject) | |
74 | IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject) | |
75 | #endif // wxUSE_PRINTING_ARCHITECTURE | |
8826f46f VZ |
76 | IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject) |
77 | IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject) | |
c801d85f KB |
78 | #endif |
79 | ||
8826f46f VZ |
80 | // ============================================================================ |
81 | // implementation | |
82 | // ============================================================================ | |
83 | ||
84 | // ---------------------------------------------------------------------------- | |
85 | // wxColourData | |
86 | // ---------------------------------------------------------------------------- | |
c801d85f | 87 | |
8bbe427f | 88 | wxColourData::wxColourData() |
c801d85f | 89 | { |
7bcb11d3 JS |
90 | int i; |
91 | for (i = 0; i < 16; i++) | |
92 | custColours[i].Set(255, 255, 255); | |
8826f46f | 93 | |
7bcb11d3 JS |
94 | chooseFull = FALSE; |
95 | dataColour.Set(0,0,0); | |
96 | } | |
c801d85f | 97 | |
7bcb11d3 JS |
98 | wxColourData::wxColourData(const wxColourData& data) |
99 | { | |
100 | (*this) = data; | |
8bbe427f | 101 | } |
c801d85f | 102 | |
8bbe427f | 103 | wxColourData::~wxColourData() |
c801d85f KB |
104 | { |
105 | } | |
106 | ||
107 | void wxColourData::SetCustomColour(int i, wxColour& colour) | |
108 | { | |
7bcb11d3 JS |
109 | if (i > 15 || i < 0) |
110 | return; | |
8826f46f | 111 | |
7bcb11d3 | 112 | custColours[i] = colour; |
c801d85f KB |
113 | } |
114 | ||
115 | wxColour wxColourData::GetCustomColour(int i) | |
116 | { | |
7bcb11d3 JS |
117 | if (i > 15 || i < 0) |
118 | return wxColour(0,0,0); | |
8826f46f | 119 | |
7bcb11d3 | 120 | return custColours[i]; |
c801d85f KB |
121 | } |
122 | ||
123 | void wxColourData::operator=(const wxColourData& data) | |
124 | { | |
7bcb11d3 JS |
125 | int i; |
126 | for (i = 0; i < 16; i++) | |
127 | custColours[i] = data.custColours[i]; | |
8826f46f | 128 | |
7bcb11d3 JS |
129 | dataColour = (wxColour&)data.dataColour; |
130 | chooseFull = data.chooseFull; | |
c801d85f KB |
131 | } |
132 | ||
8826f46f VZ |
133 | // ---------------------------------------------------------------------------- |
134 | // Font data | |
135 | // ---------------------------------------------------------------------------- | |
c801d85f | 136 | |
8bbe427f | 137 | wxFontData::wxFontData() |
c801d85f | 138 | { |
7bcb11d3 JS |
139 | // Intialize colour to black. |
140 | fontColour.Set(0, 0, 0); | |
8826f46f | 141 | |
7bcb11d3 JS |
142 | showHelp = FALSE; |
143 | allowSymbols = TRUE; | |
144 | enableEffects = TRUE; | |
145 | minSize = 0; | |
146 | maxSize = 0; | |
147 | } | |
c801d85f | 148 | |
7bcb11d3 JS |
149 | wxFontData::wxFontData(const wxFontData& data) |
150 | { | |
151 | (*this) = data; | |
c801d85f KB |
152 | } |
153 | ||
8bbe427f | 154 | wxFontData::~wxFontData() |
c801d85f KB |
155 | { |
156 | } | |
157 | ||
158 | void wxFontData::operator=(const wxFontData& data) | |
159 | { | |
7bcb11d3 JS |
160 | fontColour = data.fontColour; |
161 | showHelp = data.showHelp; | |
162 | allowSymbols = data.allowSymbols; | |
163 | enableEffects = data.enableEffects; | |
164 | initialFont = data.initialFont; | |
165 | chosenFont = data.chosenFont; | |
166 | minSize = data.minSize; | |
167 | maxSize = data.maxSize; | |
c801d85f KB |
168 | } |
169 | ||
88ac883a | 170 | #if wxUSE_PRINTING_ARCHITECTURE |
8826f46f VZ |
171 | // ---------------------------------------------------------------------------- |
172 | // Print data | |
173 | // ---------------------------------------------------------------------------- | |
c801d85f | 174 | |
8bbe427f | 175 | wxPrintData::wxPrintData() |
c801d85f | 176 | { |
2049ba38 | 177 | #ifdef __WXMSW__ |
7bcb11d3 | 178 | m_devMode = NULL; |
c801d85f | 179 | #endif |
7bcb11d3 JS |
180 | m_printOrientation = wxPORTRAIT; |
181 | m_printNoCopies = 1; | |
182 | m_printCollate = FALSE; | |
8826f46f | 183 | |
7bcb11d3 JS |
184 | // New, 24/3/99 |
185 | m_printerName = ""; | |
186 | m_colour = TRUE; | |
187 | m_duplexMode = wxDUPLEX_SIMPLEX; | |
188 | m_printQuality = wxPRINT_QUALITY_HIGH; | |
189 | m_paperId = wxPAPER_A4; | |
190 | m_paperSize = wxSize(210, 297); | |
191 | ||
192 | // PostScript-specific data | |
193 | m_printerCommand = ""; | |
194 | m_previewCommand = ""; | |
195 | m_printerOptions = ""; | |
196 | m_filename = ""; | |
197 | m_afmPath = ""; | |
198 | m_printerScaleX = 1.0; | |
199 | m_printerScaleY = 1.0; | |
200 | m_printerTranslateX = 0; | |
201 | m_printerTranslateY = 0; | |
202 | m_printMode = wxPRINT_MODE_FILE; | |
203 | } | |
204 | ||
205 | wxPrintData::wxPrintData(const wxPrintData& printData) | |
206 | { | |
58abfef6 JS |
207 | #ifdef __WXMSW__ |
208 | m_devMode = NULL; | |
209 | #endif | |
210 | ||
7bcb11d3 | 211 | (*this) = printData; |
c801d85f KB |
212 | } |
213 | ||
8bbe427f | 214 | wxPrintData::~wxPrintData() |
c801d85f | 215 | { |
2049ba38 | 216 | #ifdef __WXMSW__ |
348675e1 | 217 | HGLOBAL hDevMode = (HGLOBAL) m_devMode; |
7bcb11d3 JS |
218 | if (hDevMode ) |
219 | GlobalFree(hDevMode); | |
c801d85f KB |
220 | #endif |
221 | } | |
222 | ||
58a33cb4 | 223 | #if defined(__WXMSW__) && defined(__WIN32__) |
7bcb11d3 | 224 | |
6aa55ce7 JS |
225 | static wxString wxGetPrintDlgError() |
226 | { | |
227 | DWORD err = CommDlgExtendedError(); | |
df0a2549 | 228 | wxString msg = _T("Unknown"); |
6aa55ce7 JS |
229 | switch (err) |
230 | { | |
df0a2549 OK |
231 | case CDERR_FINDRESFAILURE: msg = _T("CDERR_FINDRESFAILURE"); break; |
232 | case CDERR_INITIALIZATION: msg = _T("CDERR_INITIALIZATION"); break; | |
233 | case CDERR_LOADRESFAILURE: msg = _T("CDERR_LOADRESFAILURE"); break; | |
234 | case CDERR_LOADSTRFAILURE: msg = _T("CDERR_LOADSTRFAILURE"); break; | |
235 | case CDERR_LOCKRESFAILURE: msg = _T("CDERR_LOCKRESFAILURE"); break; | |
236 | case CDERR_MEMALLOCFAILURE: msg = _T("CDERR_MEMALLOCFAILURE"); break; | |
237 | case CDERR_MEMLOCKFAILURE: msg = _T("CDERR_MEMLOCKFAILURE"); break; | |
238 | case CDERR_NOHINSTANCE: msg = _T("CDERR_NOHINSTANCE"); break; | |
239 | case CDERR_NOHOOK: msg = _T("CDERR_NOHOOK"); break; | |
240 | case CDERR_NOTEMPLATE: msg = _T("CDERR_NOTEMPLATE"); break; | |
241 | case CDERR_STRUCTSIZE: msg = _T("CDERR_STRUCTSIZE"); break; | |
242 | case PDERR_RETDEFFAILURE: msg = _T("PDERR_RETDEFFAILURE"); break; | |
243 | case PDERR_PRINTERNOTFOUND: msg = _T("PDERR_PRINTERNOTFOUND"); break; | |
244 | case PDERR_PARSEFAILURE: msg = _T("PDERR_PARSEFAILURE"); break; | |
245 | case PDERR_NODEVICES: msg = _T("PDERR_NODEVICES"); break; | |
246 | case PDERR_NODEFAULTPRN: msg = _T("PDERR_NODEFAULTPRN"); break; | |
247 | case PDERR_LOADDRVFAILURE: msg = _T("PDERR_LOADDRVFAILURE"); break; | |
248 | case PDERR_INITFAILURE: msg = _T("PDERR_INITFAILURE"); break; | |
249 | case PDERR_GETDEVMODEFAIL: msg = _T("PDERR_GETDEVMODEFAIL"); break; | |
250 | case PDERR_DNDMMISMATCH: msg = _T("PDERR_DNDMMISMATCH"); break; | |
251 | case PDERR_DEFAULTDIFFERENT: msg = _T("PDERR_DEFAULTDIFFERENT"); break; | |
252 | case PDERR_CREATEICFAILURE: msg = _T("PDERR_CREATEICFAILURE"); break; | |
6aa55ce7 JS |
253 | default: break; |
254 | } | |
255 | return msg; | |
256 | } | |
257 | ||
258 | ||
259 | ||
8bbe427f | 260 | void wxPrintData::ConvertToNative() |
c801d85f | 261 | { |
7bcb11d3 JS |
262 | HGLOBAL hDevMode = (HGLOBAL) m_devMode; |
263 | if (!hDevMode) | |
c801d85f | 264 | { |
7bcb11d3 JS |
265 | // Use PRINTDLG as a way of creating a DEVMODE object |
266 | PRINTDLG *pd = new PRINTDLG; | |
8826f46f | 267 | |
c801d85f | 268 | // GNU-WIN32 has the wrong size PRINTDLG - can't work out why. |
7bcb11d3 | 269 | #ifdef __GNUWIN32__ |
6aa55ce7 | 270 | memset(pd, 0, 66); |
c801d85f | 271 | pd->lStructSize = 66 ; |
7bcb11d3 | 272 | #else |
7bcb11d3 | 273 | memset(pd, 0, sizeof(PRINTDLG)); |
6aa55ce7 | 274 | pd->lStructSize = sizeof(PRINTDLG); |
7bcb11d3 JS |
275 | #endif |
276 | ||
c801d85f KB |
277 | pd->hwndOwner = (HWND)NULL; |
278 | pd->hDevMode = NULL; // Will be created by PrintDlg | |
279 | pd->hDevNames = NULL; // Ditto | |
6aa55ce7 | 280 | pd->hInstance = (HINSTANCE) wxGetInstance(); |
8826f46f | 281 | |
c801d85f KB |
282 | pd->Flags = PD_RETURNDEFAULT; |
283 | pd->nCopies = 1; | |
8826f46f | 284 | |
c801d85f KB |
285 | // Fill out the DEVMODE structure |
286 | // so we can use it as input in the 'real' PrintDlg | |
287 | if (!PrintDlg(pd)) | |
288 | { | |
289 | if ( pd->hDevMode ) | |
290 | GlobalFree(pd->hDevMode); | |
291 | if ( pd->hDevNames ) | |
292 | GlobalFree(pd->hDevNames); | |
293 | pd->hDevMode = NULL; | |
294 | pd->hDevNames = NULL; | |
58a33cb4 JS |
295 | |
296 | #if defined(__WXDEBUG__) && defined(__WIN32__) | |
df0a2549 | 297 | wxString str(_T("Printing error: ")); |
6aa55ce7 JS |
298 | str += wxGetPrintDlgError(); |
299 | wxLogDebug(str); | |
300 | #endif | |
c801d85f KB |
301 | } |
302 | else | |
303 | { | |
304 | if ( pd->hDevNames ) | |
305 | GlobalFree(pd->hDevNames); | |
306 | pd->hDevNames = NULL; | |
7bcb11d3 JS |
307 | |
308 | hDevMode = pd->hDevMode; | |
309 | m_devMode = (void*) hDevMode; | |
310 | pd->hDevMode = NULL; | |
c801d85f | 311 | } |
c801d85f | 312 | |
7bcb11d3 JS |
313 | delete pd; |
314 | } | |
8826f46f | 315 | |
7bcb11d3 | 316 | if ( hDevMode ) |
c801d85f | 317 | { |
7bcb11d3 | 318 | DEVMODE *devMode = (DEVMODE*) GlobalLock(hDevMode); |
8826f46f | 319 | |
7bcb11d3 | 320 | //// Orientation |
8826f46f | 321 | |
7bcb11d3 | 322 | devMode->dmOrientation = m_printOrientation; |
c801d85f | 323 | devMode->dmFields = DM_ORIENTATION; |
8826f46f | 324 | |
7bcb11d3 | 325 | //// Collation |
8826f46f | 326 | |
7bcb11d3 JS |
327 | devMode->dmCollate = (m_printCollate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE); |
328 | devMode->dmFields |= DM_COLLATE; | |
8826f46f | 329 | |
7bcb11d3 | 330 | //// Number of copies |
8826f46f | 331 | |
7bcb11d3 JS |
332 | devMode->dmCopies = m_printNoCopies; |
333 | devMode->dmFields |= DM_COPIES; | |
8826f46f | 334 | |
7bcb11d3 | 335 | //// Printer name |
8826f46f | 336 | |
df0a2549 | 337 | if (m_printerName != _T("")) |
7bcb11d3 JS |
338 | { |
339 | // TODO: make this Unicode compatible | |
340 | int len = wxMin(31, m_printerName.Len()); | |
341 | int i; | |
342 | for (i = 0; i < len; i++) | |
343 | devMode->dmDeviceName[i] = m_printerName.GetChar(i); | |
344 | devMode->dmDeviceName[i] = 0; | |
345 | } | |
8826f46f | 346 | |
7bcb11d3 | 347 | //// Colour |
8826f46f | 348 | |
7bcb11d3 JS |
349 | if (m_colour) |
350 | devMode->dmColor = DMCOLOR_COLOR; | |
351 | else | |
352 | devMode->dmColor = DMCOLOR_MONOCHROME; | |
8826f46f | 353 | |
7bcb11d3 | 354 | devMode->dmFields |= DM_COLOR; |
8826f46f | 355 | |
7bcb11d3 | 356 | //// Paper size |
8826f46f | 357 | |
7bcb11d3 JS |
358 | if (m_paperId == wxPAPER_NONE) |
359 | { | |
360 | devMode->dmPaperWidth = m_paperSize.x * 10; | |
361 | devMode->dmPaperLength = m_paperSize.y * 10; | |
362 | devMode->dmFields |= DM_PAPERWIDTH; | |
363 | devMode->dmFields |= DM_PAPERLENGTH; | |
364 | } | |
365 | else | |
366 | { | |
367 | if (wxThePrintPaperDatabase) | |
368 | { | |
369 | wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType(m_paperId); | |
370 | if (paper) | |
371 | { | |
372 | devMode->dmPaperSize = paper->GetPlatformId(); | |
373 | devMode->dmFields |= DM_PAPERSIZE; | |
374 | } | |
375 | } | |
376 | } | |
8826f46f | 377 | |
7bcb11d3 | 378 | //// Duplex |
8826f46f | 379 | |
7bcb11d3 JS |
380 | int duplex; |
381 | switch (m_duplexMode) | |
382 | { | |
383 | case wxDUPLEX_HORIZONTAL: { | |
384 | duplex = DMDUP_HORIZONTAL; break; | |
385 | } | |
386 | case wxDUPLEX_VERTICAL: { | |
387 | duplex = DMDUP_VERTICAL; break; | |
388 | } | |
389 | default: | |
390 | case wxDUPLEX_SIMPLEX: { | |
391 | duplex = DMDUP_SIMPLEX; break; | |
392 | } | |
393 | } | |
394 | devMode->dmDuplex = duplex; | |
395 | devMode->dmFields |= DM_DUPLEX; | |
8826f46f | 396 | |
7bcb11d3 | 397 | //// Quality |
8826f46f | 398 | |
7bcb11d3 JS |
399 | int quality; |
400 | switch (m_printQuality) | |
401 | { | |
402 | case wxPRINT_QUALITY_MEDIUM: { | |
403 | quality = DMRES_MEDIUM; break; | |
404 | } | |
405 | case wxPRINT_QUALITY_LOW: { | |
406 | quality = DMRES_LOW; break; | |
407 | } | |
408 | case wxPRINT_QUALITY_DRAFT: { | |
409 | quality = DMRES_DRAFT; break; | |
410 | } | |
411 | case wxPRINT_QUALITY_HIGH: { | |
412 | quality = DMRES_HIGH; break; | |
413 | } | |
414 | default: { | |
415 | quality = m_printQuality; break; | |
416 | } | |
417 | } | |
418 | devMode->dmPrintQuality = quality; | |
419 | devMode->dmFields |= DM_PRINTQUALITY; | |
8826f46f | 420 | |
7bcb11d3 | 421 | GlobalUnlock(hDevMode); |
c801d85f | 422 | } |
7bcb11d3 JS |
423 | } |
424 | ||
425 | void wxPrintData::ConvertFromNative() | |
426 | { | |
427 | HGLOBAL hDevMode = (HGLOBAL) m_devMode; | |
428 | ||
429 | if (!hDevMode) | |
430 | return; | |
431 | ||
432 | if ( hDevMode ) | |
433 | { | |
434 | DEVMODE *devMode = (DEVMODE*) GlobalLock(hDevMode); | |
8826f46f | 435 | |
7bcb11d3 | 436 | //// Orientation |
8826f46f | 437 | |
7bcb11d3 JS |
438 | if (devMode->dmFields & DM_ORIENTATION) |
439 | m_printOrientation = devMode->dmOrientation; | |
8826f46f | 440 | |
7bcb11d3 | 441 | //// Collation |
8826f46f | 442 | |
7bcb11d3 JS |
443 | if (devMode->dmFields & DM_COLLATE) |
444 | { | |
445 | if (devMode->dmCollate == DMCOLLATE_TRUE) | |
446 | m_printCollate = TRUE; | |
447 | else | |
448 | m_printCollate = FALSE; | |
449 | } | |
8826f46f | 450 | |
7bcb11d3 | 451 | //// Number of copies |
8826f46f | 452 | |
7bcb11d3 JS |
453 | if (devMode->dmFields & DM_COPIES) |
454 | { | |
455 | m_printNoCopies = devMode->dmCopies; | |
456 | } | |
8826f46f | 457 | |
7bcb11d3 | 458 | //// Printer name |
8826f46f | 459 | |
7bcb11d3 JS |
460 | if (devMode->dmDeviceName[0] != 0) |
461 | { | |
462 | // TODO: make this Unicode compatible | |
463 | char buf[32]; | |
464 | int i = 0; | |
465 | while (devMode->dmDeviceName[i] != 0) | |
466 | { | |
467 | buf[i] = devMode->dmDeviceName[i]; | |
468 | i ++; | |
469 | } | |
470 | buf[i] = 0; | |
8826f46f | 471 | |
7bcb11d3 JS |
472 | m_printerName = buf; |
473 | } | |
8826f46f | 474 | |
7bcb11d3 | 475 | //// Colour |
8826f46f | 476 | |
7bcb11d3 JS |
477 | if (devMode->dmFields & DM_COLOR) |
478 | { | |
479 | if (devMode->dmColor == DMCOLOR_COLOR) | |
480 | m_colour = TRUE; | |
481 | else | |
482 | m_colour = FALSE; | |
483 | } | |
484 | else | |
485 | m_colour = TRUE; | |
8826f46f | 486 | |
7bcb11d3 | 487 | //// Paper size |
8826f46f | 488 | |
7bcb11d3 JS |
489 | if (devMode->dmFields & DM_PAPERSIZE) |
490 | { | |
491 | if (wxThePrintPaperDatabase) | |
492 | { | |
493 | wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize); | |
494 | if (paper) | |
495 | { | |
496 | m_paperId = paper->GetId(); | |
497 | m_paperSize.x = paper->GetWidth() / 10 ; | |
498 | m_paperSize.y = paper->GetHeight() / 10 ; | |
499 | } | |
500 | else | |
501 | { | |
502 | // Shouldn't really get here | |
df0a2549 | 503 | wxFAIL_MSG(_T("Couldn't find paper size in paper database.")); |
8826f46f | 504 | |
7bcb11d3 JS |
505 | m_paperId = wxPAPER_NONE; |
506 | m_paperSize.x = 0; | |
507 | m_paperSize.y = 0; | |
508 | } | |
509 | } | |
510 | else | |
511 | { | |
512 | // Shouldn't really get here | |
df0a2549 | 513 | wxFAIL_MSG(_T("Paper database wasn't initialized in wxPrintData::ConvertFromNative.")); |
8826f46f | 514 | |
7bcb11d3 JS |
515 | m_paperId = wxPAPER_NONE; |
516 | m_paperSize.x = 0; | |
517 | m_paperSize.y = 0; | |
518 | } | |
519 | } | |
520 | else if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH)) | |
521 | { | |
522 | m_paperSize.x = devMode->dmPaperWidth / 10; | |
523 | m_paperSize.y = devMode->dmPaperLength / 10; | |
524 | m_paperId = wxPAPER_NONE; | |
525 | } | |
526 | else | |
527 | { | |
528 | // Shouldn't really get here | |
df0a2549 | 529 | wxFAIL_MSG(_T("Couldn't find paper size from DEVMODE.")); |
8826f46f | 530 | |
7bcb11d3 JS |
531 | m_paperSize.x = 0; |
532 | m_paperSize.y = 0; | |
533 | m_paperId = wxPAPER_NONE; | |
534 | } | |
8826f46f VZ |
535 | |
536 | ||
7bcb11d3 | 537 | //// Duplex |
8826f46f | 538 | |
7bcb11d3 JS |
539 | if (devMode->dmFields & DM_DUPLEX) |
540 | { | |
541 | switch (devMode->dmDuplex) | |
542 | { | |
543 | case DMDUP_HORIZONTAL: { | |
544 | m_duplexMode = wxDUPLEX_HORIZONTAL; break; | |
545 | } | |
546 | case DMDUP_VERTICAL: { | |
547 | m_duplexMode = wxDUPLEX_VERTICAL; break; | |
548 | } | |
549 | default: | |
550 | case DMDUP_SIMPLEX: { | |
551 | m_duplexMode = wxDUPLEX_SIMPLEX; break; | |
552 | } | |
553 | } | |
554 | } | |
555 | else | |
556 | m_duplexMode = wxDUPLEX_SIMPLEX; | |
8826f46f | 557 | |
7bcb11d3 | 558 | //// Quality |
8826f46f | 559 | |
7bcb11d3 JS |
560 | if (devMode->dmFields & DM_PRINTQUALITY) |
561 | { | |
562 | switch (devMode->dmPrintQuality) | |
563 | { | |
564 | case DMRES_MEDIUM: { | |
565 | m_printQuality = wxPRINT_QUALITY_MEDIUM; break; | |
566 | } | |
567 | case DMRES_LOW: { | |
568 | m_printQuality = wxPRINT_QUALITY_LOW; break; | |
569 | } | |
570 | case DMRES_DRAFT: { | |
571 | m_printQuality = wxPRINT_QUALITY_DRAFT; break; | |
572 | } | |
573 | case DMRES_HIGH: { | |
574 | m_printQuality = wxPRINT_QUALITY_HIGH; break; | |
575 | } | |
576 | default: | |
577 | { | |
578 | // TODO: if the printer fills in the resolution in DPI, how | |
579 | // will the application know if it's high, low, draft etc.?? | |
580 | // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values."); | |
581 | m_printQuality = devMode->dmPrintQuality; break; | |
8826f46f | 582 | |
7bcb11d3 JS |
583 | } |
584 | } | |
585 | } | |
586 | else | |
587 | m_printQuality = wxPRINT_QUALITY_HIGH; | |
8826f46f | 588 | |
7bcb11d3 JS |
589 | GlobalUnlock(hDevMode); |
590 | } | |
591 | } | |
c801d85f | 592 | |
7bcb11d3 JS |
593 | #endif |
594 | ||
595 | void wxPrintData::operator=(const wxPrintData& data) | |
596 | { | |
597 | m_printNoCopies = data.m_printNoCopies; | |
598 | m_printCollate = data.m_printCollate; | |
599 | m_printOrientation = data.m_printOrientation; | |
600 | m_printerName = data.m_printerName; | |
601 | m_colour = data.m_colour; | |
602 | m_duplexMode = data.m_duplexMode; | |
603 | m_printQuality = data.m_printQuality; | |
604 | m_paperId = data.m_paperId; | |
605 | m_paperSize = data.m_paperSize; | |
606 | ||
607 | // PostScript-specific data | |
608 | m_printerCommand = data.m_printerCommand; | |
609 | m_previewCommand = data.m_previewCommand; | |
610 | m_printerOptions = data.m_printerOptions; | |
611 | m_filename = data.m_filename; | |
612 | m_afmPath = data.m_afmPath; | |
613 | m_printerScaleX = data.m_printerScaleX; | |
614 | m_printerScaleY = data.m_printerScaleY; | |
615 | m_printerTranslateX = data.m_printerTranslateX; | |
616 | m_printerTranslateY = data.m_printerTranslateY; | |
617 | m_printMode = data.m_printMode; | |
618 | } | |
619 | ||
620 | // For compatibility | |
8826f46f | 621 | #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA |
7bcb11d3 JS |
622 | void wxPrintData::operator=(const wxPrintSetupData& setupData) |
623 | { | |
624 | SetPrinterCommand(setupData.GetPrinterCommand()); | |
625 | SetPreviewCommand(setupData.GetPrintPreviewCommand()); | |
626 | SetPrinterOptions(setupData.GetPrinterOptions()); | |
627 | ||
628 | long xt, yt; | |
629 | setupData.GetPrinterTranslation(& xt, & yt); | |
630 | SetPrinterTranslation(xt, yt); | |
631 | ||
632 | double xs, ys; | |
633 | setupData.GetPrinterScaling(& xs, & ys); | |
634 | SetPrinterScaling(xs, ys); | |
635 | ||
636 | SetOrientation(setupData.GetPrinterOrientation()); | |
637 | SetPrintMode((wxPrintMode) setupData.GetPrinterMode()); | |
638 | SetFontMetricPath(setupData.GetAFMPath()); | |
639 | if (setupData.GetPaperName() != "") | |
640 | SetPaperId(wxThePrintPaperDatabase->ConvertNameToId(setupData.GetPaperName())); | |
641 | SetColour(setupData.GetColour()); | |
642 | SetFilename(setupData.GetPrinterFile()); | |
643 | } | |
8826f46f | 644 | #endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA |
7bcb11d3 | 645 | |
8826f46f VZ |
646 | |
647 | // ---------------------------------------------------------------------------- | |
648 | // Print dialog data | |
649 | // ---------------------------------------------------------------------------- | |
7bcb11d3 JS |
650 | |
651 | wxPrintDialogData::wxPrintDialogData() | |
652 | { | |
653 | #ifdef __WXMSW__ | |
654 | m_printDlgData = NULL; | |
655 | #endif | |
656 | m_printFromPage = 0; | |
657 | m_printToPage = 0; | |
658 | m_printMinPage = 0; | |
659 | m_printMaxPage = 0; | |
660 | m_printNoCopies = 1; | |
661 | m_printAllPages = FALSE; | |
662 | m_printCollate = FALSE; | |
663 | m_printToFile = FALSE; | |
664 | m_printEnableSelection = FALSE; | |
665 | m_printEnablePageNumbers = TRUE; | |
666 | m_printEnablePrintToFile = TRUE; | |
667 | m_printEnableHelp = FALSE; | |
668 | m_printSetupDialog = FALSE; | |
669 | } | |
670 | ||
671 | wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData) | |
672 | { | |
673 | (*this) = dialogData; | |
674 | } | |
675 | ||
676 | wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData) | |
677 | { | |
678 | #ifdef __WXMSW__ | |
679 | m_printDlgData = NULL; | |
680 | #endif | |
681 | m_printFromPage = 0; | |
682 | m_printToPage = 0; | |
683 | m_printMinPage = 0; | |
684 | m_printMaxPage = 0; | |
685 | m_printNoCopies = 1; | |
686 | m_printAllPages = FALSE; | |
687 | m_printCollate = FALSE; | |
688 | m_printToFile = FALSE; | |
689 | m_printEnableSelection = FALSE; | |
690 | m_printEnablePageNumbers = TRUE; | |
691 | m_printEnablePrintToFile = TRUE; | |
692 | m_printEnableHelp = FALSE; | |
693 | m_printSetupDialog = FALSE; | |
694 | ||
695 | m_printData = printData; | |
696 | } | |
697 | ||
698 | wxPrintDialogData::~wxPrintDialogData() | |
699 | { | |
700 | #ifdef __WXMSW__ | |
701 | PRINTDLG *pd = (PRINTDLG *) m_printDlgData; | |
702 | if ( pd && pd->hDevMode ) | |
703 | GlobalFree(pd->hDevMode); | |
704 | if ( pd ) | |
705 | delete pd; | |
706 | #endif | |
707 | } | |
708 | ||
709 | #ifdef __WXMSW__ | |
710 | void wxPrintDialogData::ConvertToNative() | |
711 | { | |
712 | m_printData.ConvertToNative(); | |
713 | ||
714 | PRINTDLG *pd = (PRINTDLG*) m_printDlgData; | |
715 | ||
716 | if (!pd) | |
717 | { | |
718 | pd = new PRINTDLG; | |
719 | m_printDlgData = (void*) pd; | |
720 | ||
721 | // GNU-WIN32 has the wrong size PRINTDLG - can't work out why. | |
722 | #ifdef __GNUWIN32__ | |
723 | pd->lStructSize = 66 ; | |
724 | #else | |
725 | #endif | |
726 | pd->lStructSize = sizeof(PRINTDLG); | |
727 | pd->hwndOwner = (HWND)NULL; | |
728 | pd->hDevMode = NULL; // Will be created by PrintDlg | |
729 | pd->hDevNames = NULL; // Ditto | |
730 | ||
731 | pd->Flags = PD_RETURNDEFAULT; | |
732 | pd->nCopies = 1; | |
733 | } | |
734 | ||
735 | // Pass the devmode data to the PRINTDLG structure, since it'll | |
736 | // be needed when PrintDlg is called. | |
737 | if (pd->hDevMode) | |
738 | { | |
739 | GlobalFree(pd->hDevMode); | |
740 | } | |
741 | ||
742 | pd->hDevMode = (HGLOBAL) m_printData.GetNativeData(); | |
743 | ||
744 | m_printData.SetNativeData((void*) NULL); | |
745 | ||
df0a2549 | 746 | wxASSERT_MSG( (pd->hDevMode), _T("hDevMode must be non-NULL in ConvertToNative!")); |
7bcb11d3 JS |
747 | |
748 | pd->hDC = (HDC) NULL; | |
749 | pd->nFromPage = (UINT)m_printFromPage; | |
750 | pd->nToPage = (UINT)m_printToPage; | |
751 | pd->nMinPage = (UINT)m_printMinPage; | |
752 | pd->nMaxPage = (UINT)m_printMaxPage; | |
753 | pd->nCopies = (UINT)m_printNoCopies; | |
8826f46f | 754 | |
c801d85f | 755 | pd->Flags = PD_RETURNDC ; |
7bcb11d3 JS |
756 | |
757 | #ifdef __GNUWIN32__ | |
c801d85f | 758 | pd->lStructSize = 66 ; |
7bcb11d3 JS |
759 | #else |
760 | pd->lStructSize = sizeof( PRINTDLG ); | |
761 | #endif | |
762 | ||
8b9518ee | 763 | pd->hwndOwner=(HWND)NULL; |
c801d85f KB |
764 | pd->hDevNames=(HANDLE)NULL; |
765 | pd->hInstance=(HINSTANCE)NULL; | |
766 | pd->lCustData = (LPARAM) NULL; | |
767 | pd->lpfnPrintHook = NULL; | |
768 | pd->lpfnSetupHook = NULL; | |
769 | pd->lpPrintTemplateName = NULL; | |
770 | pd->lpSetupTemplateName = NULL; | |
771 | pd->hPrintTemplate = (HGLOBAL) NULL; | |
772 | pd->hSetupTemplate = (HGLOBAL) NULL; | |
8826f46f | 773 | |
7bcb11d3 | 774 | if ( m_printAllPages ) |
c801d85f | 775 | pd->Flags |= PD_ALLPAGES; |
7bcb11d3 | 776 | if ( m_printCollate ) |
c801d85f | 777 | pd->Flags |= PD_COLLATE; |
7bcb11d3 | 778 | if ( m_printToFile ) |
c801d85f | 779 | pd->Flags |= PD_PRINTTOFILE; |
7bcb11d3 | 780 | if ( !m_printEnablePrintToFile ) |
c801d85f | 781 | pd->Flags |= PD_DISABLEPRINTTOFILE; |
7bcb11d3 JS |
782 | if ( !m_printEnableSelection ) |
783 | pd->Flags |= PD_NOSELECTION; | |
784 | if ( !m_printEnablePageNumbers ) | |
785 | pd->Flags |= PD_NOPAGENUMS; | |
786 | if ( m_printEnableHelp ) | |
787 | pd->Flags |= PD_SHOWHELP; | |
788 | if ( m_printSetupDialog ) | |
789 | pd->Flags |= PD_PRINTSETUP; | |
c801d85f KB |
790 | } |
791 | ||
7bcb11d3 | 792 | void wxPrintDialogData::ConvertFromNative() |
c801d85f | 793 | { |
7bcb11d3 | 794 | PRINTDLG *pd = (PRINTDLG*) m_printDlgData; |
c801d85f KB |
795 | if ( pd == NULL ) |
796 | return; | |
797 | ||
7bcb11d3 JS |
798 | // Pass the devmode data back to the wxPrintData structure where it really belongs. |
799 | if (pd->hDevMode) | |
c801d85f | 800 | { |
7bcb11d3 JS |
801 | if (m_printData.GetNativeData()) |
802 | { | |
803 | // Make sure we don't leak memory | |
804 | GlobalFree((HGLOBAL) m_printData.GetNativeData()); | |
805 | } | |
806 | m_printData.SetNativeData((void*) pd->hDevMode); | |
807 | pd->hDevMode = NULL; | |
c801d85f | 808 | } |
c801d85f | 809 | |
7bcb11d3 JS |
810 | // Now convert the DEVMODE object, passed down from the PRINTDLG object, |
811 | // into wxWindows form. | |
812 | m_printData.ConvertFromNative(); | |
813 | ||
814 | m_printFromPage = pd->nFromPage ; | |
815 | m_printToPage = pd->nToPage ; | |
816 | m_printMinPage = pd->nMinPage ; | |
817 | m_printMaxPage = pd->nMaxPage ; | |
818 | m_printNoCopies = pd->nCopies ; | |
8826f46f | 819 | |
7bcb11d3 JS |
820 | m_printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES); |
821 | m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE); | |
822 | m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE); | |
823 | m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE); | |
824 | m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION); | |
825 | m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS); | |
826 | m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP); | |
827 | m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP); | |
828 | ||
829 | /* port is obsolete in WIN32 | |
830 | // Get the port name | |
831 | if (pd->hDevNames) | |
832 | { | |
833 | LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames); | |
834 | if (lpDevNames) { | |
835 | m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset); | |
836 | wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset; | |
837 | GlobalUnlock(pd->hDevNames); | |
8826f46f | 838 | |
7bcb11d3 JS |
839 | // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!"); |
840 | } | |
841 | } | |
842 | */ | |
c801d85f KB |
843 | } |
844 | ||
7bcb11d3 | 845 | void wxPrintDialogData::SetOwnerWindow(wxWindow* win) |
c801d85f | 846 | { |
7bcb11d3 | 847 | if ( m_printDlgData == NULL ) |
c801d85f | 848 | ConvertToNative(); |
8826f46f | 849 | |
7bcb11d3 | 850 | if ( m_printDlgData != NULL && win != NULL) |
c801d85f | 851 | { |
7bcb11d3 JS |
852 | PRINTDLG *pd = (PRINTDLG *) m_printDlgData ; |
853 | pd->hwndOwner=(HWND) win->GetHWND(); | |
c801d85f KB |
854 | } |
855 | } | |
8826f46f | 856 | #endif // MSW |
c801d85f | 857 | |
7bcb11d3 | 858 | void wxPrintDialogData::operator=(const wxPrintDialogData& data) |
c801d85f | 859 | { |
7bcb11d3 JS |
860 | m_printFromPage = data.m_printFromPage; |
861 | m_printToPage = data.m_printToPage; | |
862 | m_printMinPage = data.m_printMinPage; | |
863 | m_printMaxPage = data.m_printMaxPage; | |
864 | m_printNoCopies = data.m_printNoCopies; | |
865 | m_printAllPages = data.m_printAllPages; | |
866 | m_printCollate = data.m_printCollate; | |
867 | m_printToFile = data.m_printToFile; | |
868 | m_printEnableSelection = data.m_printEnableSelection; | |
869 | m_printEnablePageNumbers = data.m_printEnablePageNumbers; | |
870 | m_printEnableHelp = data.m_printEnableHelp; | |
871 | m_printEnablePrintToFile = data.m_printEnablePrintToFile; | |
872 | m_printSetupDialog = data.m_printSetupDialog; | |
873 | ||
874 | m_printData = data.m_printData; | |
875 | } | |
876 | ||
877 | void wxPrintDialogData::operator=(const wxPrintData& data) | |
878 | { | |
879 | m_printData = data; | |
c801d85f KB |
880 | } |
881 | ||
8826f46f VZ |
882 | // ---------------------------------------------------------------------------- |
883 | // wxPageSetupDialogData | |
884 | // ---------------------------------------------------------------------------- | |
c801d85f | 885 | |
7bcb11d3 | 886 | wxPageSetupDialogData::wxPageSetupDialogData() |
c801d85f KB |
887 | { |
888 | #if defined(__WIN95__) | |
7bcb11d3 | 889 | m_pageSetupData = NULL; |
c801d85f | 890 | #endif |
7bcb11d3 JS |
891 | m_paperSize = wxSize(0, 0); |
892 | ||
893 | CalculatePaperSizeFromId(); | |
894 | ||
895 | m_minMarginTopLeft = wxPoint(0, 0); | |
896 | m_minMarginBottomRight = wxPoint(0, 0); | |
897 | m_marginTopLeft = wxPoint(0, 0); | |
898 | m_marginBottomRight = wxPoint(0, 0); | |
899 | ||
900 | // Flags | |
901 | m_defaultMinMargins = FALSE; | |
902 | m_enableMargins = TRUE; | |
903 | m_enableOrientation = TRUE; | |
904 | m_enablePaper = TRUE; | |
905 | m_enablePrinter = TRUE; | |
906 | m_enableHelp = FALSE; | |
907 | m_getDefaultInfo = FALSE; | |
908 | } | |
c801d85f | 909 | |
7bcb11d3 JS |
910 | wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData) |
911 | { | |
912 | (*this) = dialogData; | |
913 | } | |
914 | ||
915 | wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData) | |
916 | { | |
917 | #if defined(__WIN95__) | |
918 | m_pageSetupData = NULL; | |
919 | #endif | |
920 | m_paperSize = wxSize(0, 0); | |
921 | m_minMarginTopLeft = wxPoint(0, 0); | |
922 | m_minMarginBottomRight = wxPoint(0, 0); | |
923 | m_marginTopLeft = wxPoint(0, 0); | |
924 | m_marginBottomRight = wxPoint(0, 0); | |
925 | ||
926 | // Flags | |
927 | m_defaultMinMargins = FALSE; | |
928 | m_enableMargins = TRUE; | |
929 | m_enableOrientation = TRUE; | |
930 | m_enablePaper = TRUE; | |
931 | m_enablePrinter = TRUE; | |
932 | m_enableHelp = FALSE; | |
933 | m_getDefaultInfo = FALSE; | |
934 | ||
935 | m_printData = printData; | |
936 | ||
937 | // The wxPrintData paper size overrides these values, unless the size cannot | |
938 | // be found. | |
939 | CalculatePaperSizeFromId(); | |
c801d85f KB |
940 | } |
941 | ||
7bcb11d3 | 942 | wxPageSetupDialogData::~wxPageSetupDialogData() |
c801d85f | 943 | { |
34138703 | 944 | #if defined(__WIN95__) && defined(__WXMSW__) |
c801d85f KB |
945 | PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData; |
946 | if ( pd && pd->hDevMode ) | |
947 | GlobalFree(pd->hDevMode); | |
948 | if ( pd ) | |
949 | delete pd; | |
950 | #endif | |
951 | } | |
952 | ||
7bcb11d3 | 953 | void wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data) |
c801d85f | 954 | { |
7bcb11d3 JS |
955 | m_paperSize = data.m_paperSize; |
956 | m_minMarginTopLeft = data.m_minMarginTopLeft; | |
957 | m_minMarginBottomRight = data.m_minMarginBottomRight; | |
958 | m_marginTopLeft = data.m_marginTopLeft; | |
959 | m_marginBottomRight = data.m_marginBottomRight; | |
960 | m_defaultMinMargins = data.m_defaultMinMargins; | |
961 | m_enableMargins = data.m_enableMargins; | |
962 | m_enableOrientation = data.m_enableOrientation; | |
963 | m_enablePaper = data.m_enablePaper; | |
964 | m_enablePrinter = data.m_enablePrinter; | |
965 | m_getDefaultInfo = data.m_getDefaultInfo;; | |
966 | m_enableHelp = data.m_enableHelp; | |
967 | ||
968 | m_printData = data.m_printData; | |
969 | } | |
c801d85f | 970 | |
7bcb11d3 JS |
971 | void wxPageSetupDialogData::operator=(const wxPrintData& data) |
972 | { | |
973 | m_printData = data; | |
c801d85f KB |
974 | } |
975 | ||
8826f46f | 976 | #if defined(__WIN95__) |
7bcb11d3 | 977 | void wxPageSetupDialogData::ConvertToNative() |
c801d85f | 978 | { |
7bcb11d3 JS |
979 | m_printData.ConvertToNative(); |
980 | ||
c801d85f | 981 | PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData; |
7bcb11d3 | 982 | |
c801d85f KB |
983 | if ( m_pageSetupData == NULL ) |
984 | { | |
7bcb11d3 JS |
985 | pd = new PAGESETUPDLG; |
986 | pd->hDevMode = NULL; | |
987 | m_pageSetupData = (void *)pd; | |
c801d85f | 988 | } |
8bbe427f | 989 | |
7bcb11d3 JS |
990 | // Pass the devmode data (created in m_printData.ConvertToNative) |
991 | // to the PRINTDLG structure, since it'll | |
992 | // be needed when PrintDlg is called. | |
993 | ||
994 | if (pd->hDevMode) | |
995 | { | |
996 | GlobalFree(pd->hDevMode); | |
997 | pd->hDevMode = NULL; | |
998 | } | |
999 | ||
1000 | ||
1001 | pd->hDevMode = (HGLOBAL) m_printData.GetNativeData(); | |
1002 | ||
1003 | m_printData.SetNativeData((void*) NULL); | |
1004 | ||
df0a2549 | 1005 | wxASSERT_MSG( (pd->hDevMode), _T("hDevMode must be non-NULL in ConvertToNative!")); |
7bcb11d3 JS |
1006 | |
1007 | // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE)); | |
c801d85f | 1008 | |
7bcb11d3 | 1009 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; |
8826f46f | 1010 | |
c801d85f KB |
1011 | if ( m_defaultMinMargins ) |
1012 | pd->Flags |= PSD_DEFAULTMINMARGINS; | |
1013 | if ( !m_enableMargins ) | |
1014 | pd->Flags |= PSD_DISABLEMARGINS; | |
1015 | if ( !m_enableOrientation ) | |
1016 | pd->Flags |= PSD_DISABLEORIENTATION; | |
1017 | if ( !m_enablePaper ) | |
1018 | pd->Flags |= PSD_DISABLEPAPER; | |
1019 | if ( !m_enablePrinter ) | |
1020 | pd->Flags |= PSD_DISABLEPRINTER; | |
1021 | if ( m_getDefaultInfo ) | |
1022 | pd->Flags |= PSD_RETURNDEFAULT; | |
1023 | if ( m_enableHelp ) | |
1024 | pd->Flags |= PSD_SHOWHELP; | |
1025 | ||
7bcb11d3 JS |
1026 | // We want the units to be in hundredths of a millimetre |
1027 | pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS; | |
1028 | ||
c801d85f | 1029 | pd->lStructSize = sizeof( PAGESETUPDLG ); |
c4e7c2aa | 1030 | pd->hwndOwner=(HWND)NULL; |
c801d85f KB |
1031 | pd->hDevNames=(HWND)NULL; |
1032 | pd->hInstance=(HINSTANCE)NULL; | |
8826f46f | 1033 | |
7bcb11d3 JS |
1034 | pd->ptPaperSize.x = m_paperSize.x * 100; |
1035 | pd->ptPaperSize.y = m_paperSize.y * 100; | |
8826f46f | 1036 | |
7bcb11d3 JS |
1037 | pd->rtMinMargin.left = m_minMarginTopLeft.x * 100; |
1038 | pd->rtMinMargin.top = m_minMarginTopLeft.y * 100; | |
1039 | pd->rtMinMargin.right = m_minMarginBottomRight.x * 100; | |
1040 | pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100; | |
8826f46f | 1041 | |
7bcb11d3 JS |
1042 | pd->rtMargin.left = m_marginTopLeft.x * 100; |
1043 | pd->rtMargin.top = m_marginTopLeft.y * 100; | |
1044 | pd->rtMargin.right = m_marginBottomRight.x * 100; | |
1045 | pd->rtMargin.bottom = m_marginBottomRight.y * 100; | |
8826f46f | 1046 | |
c801d85f KB |
1047 | pd->lCustData = 0; |
1048 | pd->lpfnPageSetupHook = NULL; | |
1049 | pd->lpfnPagePaintHook = NULL; | |
1050 | pd->hPageSetupTemplate = NULL; | |
1051 | pd->lpPageSetupTemplateName = NULL; | |
1052 | ||
8826f46f | 1053 | /* |
c801d85f KB |
1054 | if ( pd->hDevMode ) |
1055 | { | |
1056 | DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode); | |
1057 | memset(devMode, 0, sizeof(DEVMODE)); | |
1058 | devMode->dmSize = sizeof(DEVMODE); | |
1059 | devMode->dmOrientation = m_orientation; | |
1060 | devMode->dmFields = DM_ORIENTATION; | |
1061 | GlobalUnlock(pd->hDevMode); | |
1062 | } | |
7bcb11d3 | 1063 | */ |
c801d85f KB |
1064 | } |
1065 | ||
7bcb11d3 | 1066 | void wxPageSetupDialogData::ConvertFromNative() |
c801d85f KB |
1067 | { |
1068 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ; | |
1069 | if ( !pd ) | |
1070 | return; | |
8826f46f | 1071 | |
7bcb11d3 JS |
1072 | // Pass the devmode data back to the wxPrintData structure where it really belongs. |
1073 | if (pd->hDevMode) | |
1074 | { | |
1075 | if (m_printData.GetNativeData()) | |
1076 | { | |
1077 | // Make sure we don't leak memory | |
1078 | GlobalFree((HGLOBAL) m_printData.GetNativeData()); | |
1079 | } | |
1080 | m_printData.SetNativeData((void*) pd->hDevMode); | |
1081 | pd->hDevMode = NULL; | |
1082 | } | |
c801d85f | 1083 | |
7bcb11d3 | 1084 | m_printData.ConvertFromNative(); |
c801d85f | 1085 | |
7bcb11d3 | 1086 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; |
8826f46f | 1087 | |
c801d85f KB |
1088 | m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS); |
1089 | m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS); | |
1090 | m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION); | |
1091 | m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER); | |
1092 | m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER); | |
1093 | m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT); | |
1094 | m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP); | |
8826f46f | 1095 | |
7bcb11d3 JS |
1096 | m_paperSize.x = pd->ptPaperSize.x / 100; |
1097 | m_paperSize.y = pd->ptPaperSize.y / 100; | |
8826f46f | 1098 | |
7bcb11d3 JS |
1099 | m_minMarginTopLeft.x = pd->rtMinMargin.left / 100; |
1100 | m_minMarginTopLeft.y = pd->rtMinMargin.top / 100; | |
1101 | m_minMarginBottomRight.x = pd->rtMinMargin.right / 100; | |
1102 | m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100; | |
8826f46f | 1103 | |
7bcb11d3 JS |
1104 | m_marginTopLeft.x = pd->rtMargin.left / 100 ; |
1105 | m_marginTopLeft.y = pd->rtMargin.top / 100 ; | |
1106 | m_marginBottomRight.x = pd->rtMargin.right / 100 ; | |
1107 | m_marginBottomRight.y = pd->rtMargin.bottom / 100 ; | |
1108 | } | |
c801d85f | 1109 | |
7bcb11d3 JS |
1110 | void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win) |
1111 | { | |
1112 | if ( m_pageSetupData == NULL ) | |
1113 | ConvertToNative(); | |
8826f46f | 1114 | |
7bcb11d3 JS |
1115 | if ( m_pageSetupData != NULL && win != NULL) |
1116 | { | |
1117 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ; | |
1118 | pd->hwndOwner=(HWND) win->GetHWND(); | |
1119 | } | |
1120 | } | |
8826f46f | 1121 | #endif // Win95 |
c801d85f | 1122 | |
7bcb11d3 JS |
1123 | // If a corresponding paper type is found in the paper database, will set the m_printData |
1124 | // paper size id member as well. | |
1125 | void wxPageSetupDialogData::SetPaperSize(const wxSize& sz) | |
1126 | { | |
1127 | m_paperSize = sz; | |
c801d85f | 1128 | |
7bcb11d3 JS |
1129 | CalculateIdFromPaperSize(); |
1130 | } | |
c801d85f | 1131 | |
7bcb11d3 JS |
1132 | // Sets the wxPrintData id, plus the paper width/height if found in the paper database. |
1133 | void wxPageSetupDialogData::SetPaperSize(wxPaperSize id) | |
1134 | { | |
1135 | m_printData.SetPaperId(id); | |
1136 | ||
1137 | CalculatePaperSizeFromId(); | |
c801d85f KB |
1138 | } |
1139 | ||
7bcb11d3 JS |
1140 | // Use paper size defined in this object to set the wxPrintData |
1141 | // paper id | |
1142 | void wxPageSetupDialogData::CalculateIdFromPaperSize() | |
c801d85f | 1143 | { |
8826f46f | 1144 | wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL), |
50920146 OK |
1145 | _T("wxThePrintPaperDatabase should not be NULL. " |
1146 | "Do not create global print dialog data objects.") ); | |
c801d85f | 1147 | |
7bcb11d3 JS |
1148 | wxSize sz = GetPaperSize(); |
1149 | ||
1150 | wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10)); | |
1151 | if (id != wxPAPER_NONE) | |
c801d85f | 1152 | { |
7bcb11d3 | 1153 | m_printData.SetPaperId(id); |
c801d85f KB |
1154 | } |
1155 | } | |
8826f46f | 1156 | |
7bcb11d3 JS |
1157 | // Use paper id in wxPrintData to set this object's paper size |
1158 | void wxPageSetupDialogData::CalculatePaperSizeFromId() | |
1159 | { | |
8826f46f | 1160 | wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL), |
50920146 OK |
1161 | _T("wxThePrintPaperDatabase should not be NULL. " |
1162 | "Do not create global print dialog data objects.") ); | |
7bcb11d3 JS |
1163 | |
1164 | wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId()); | |
c801d85f | 1165 | |
7bcb11d3 JS |
1166 | if (sz.x != 0) |
1167 | { | |
1168 | // sz is in 10ths of a mm, so multiply by 10. | |
1169 | m_paperSize.x = sz.x * 10; | |
1170 | m_paperSize.y = sz.y * 10; | |
1171 | } | |
1172 | } | |
8826f46f | 1173 | |
88ac883a | 1174 | #endif // wxUSE_PRINTING_ARCHITECTURE |