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