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