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