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