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