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