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