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