]>
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 |
65571936 | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8826f46f VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
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" |
8850cbd3 RR |
41 | #include "wx/prntbase.h" |
42 | #include "wx/printdlg.h" | |
8826f46f | 43 | |
dbc65e27 VZ |
44 | #if wxUSE_FONTDLG |
45 | #include "wx/fontdlg.h" | |
46 | #endif // wxUSE_FONTDLG | |
47 | ||
88ac883a VZ |
48 | #if wxUSE_PRINTING_ARCHITECTURE |
49 | #include "wx/paper.h" | |
88ac883a | 50 | #endif // wxUSE_PRINTING_ARCHITECTURE |
7be1f0d9 | 51 | |
ffecfa5a | 52 | #if defined(__WXMSW__) && !defined(__PALMOS__) |
1c193821 | 53 | #include <windowsx.h> |
3096bd2f | 54 | #include "wx/msw/private.h" |
7be1f0d9 | 55 | |
0c44ec97 | 56 | #ifndef __SMARTPHONE__ /* of WinCE */ |
8826f46f | 57 | #include <commdlg.h> |
1c193821 | 58 | #endif |
8826f46f | 59 | |
2bdf7154 | 60 | #if defined(__WATCOMC__) || defined(__SYMANTEC__) || defined(__SALFORDC__) |
8826f46f VZ |
61 | #include <windowsx.h> |
62 | #include <commdlg.h> | |
63 | #endif | |
64 | #endif // MSW | |
c801d85f | 65 | |
746d7582 SC |
66 | #ifdef __WXMAC__ |
67 | #include "wx/mac/private/print.h" | |
68 | #endif | |
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 | |
83e72d5f GT |
79 | #ifndef DMPAPER_USER |
80 | #define DMPAPER_USER 256 | |
81 | #endif | |
82 | ||
8826f46f VZ |
83 | // ============================================================================ |
84 | // implementation | |
85 | // ============================================================================ | |
86 | ||
87 | // ---------------------------------------------------------------------------- | |
88 | // wxColourData | |
89 | // ---------------------------------------------------------------------------- | |
c801d85f | 90 | |
8bbe427f | 91 | wxColourData::wxColourData() |
c801d85f | 92 | { |
393c836c | 93 | m_chooseFull = false; |
ae500232 | 94 | m_dataColour.Set(0,0,0); |
393c836c | 95 | // m_custColours are wxNullColours initially |
7bcb11d3 | 96 | } |
c801d85f | 97 | |
7bcb11d3 | 98 | wxColourData::wxColourData(const wxColourData& data) |
5e472c1f | 99 | : wxObject() |
7bcb11d3 JS |
100 | { |
101 | (*this) = data; | |
8bbe427f | 102 | } |
c801d85f | 103 | |
8bbe427f | 104 | wxColourData::~wxColourData() |
c801d85f KB |
105 | { |
106 | } | |
107 | ||
cebf2fec | 108 | void wxColourData::SetCustomColour(int i, const wxColour& colour) |
c801d85f | 109 | { |
393c836c | 110 | wxCHECK_RET( (i >= 0 && i < 16), _T("custom colour index out of range") ); |
8826f46f | 111 | |
ae500232 | 112 | m_custColours[i] = colour; |
c801d85f KB |
113 | } |
114 | ||
115 | wxColour wxColourData::GetCustomColour(int i) | |
116 | { | |
393c836c VS |
117 | wxCHECK_MSG( (i >= 0 && i < 16), wxColour(0,0,0), |
118 | _T("custom colour index out of range") ); | |
8826f46f | 119 | |
ae500232 | 120 | return m_custColours[i]; |
c801d85f KB |
121 | } |
122 | ||
123 | void wxColourData::operator=(const wxColourData& data) | |
124 | { | |
7bcb11d3 JS |
125 | int i; |
126 | for (i = 0; i < 16; i++) | |
ae500232 | 127 | m_custColours[i] = data.m_custColours[i]; |
8826f46f | 128 | |
ae500232 JS |
129 | m_dataColour = (wxColour&)data.m_dataColour; |
130 | m_chooseFull = data.m_chooseFull; | |
c801d85f KB |
131 | } |
132 | ||
8826f46f VZ |
133 | // ---------------------------------------------------------------------------- |
134 | // Font data | |
135 | // ---------------------------------------------------------------------------- | |
c801d85f | 136 | |
8bbe427f | 137 | wxFontData::wxFontData() |
c801d85f | 138 | { |
7bcb11d3 | 139 | // Intialize colour to black. |
ae500232 | 140 | m_fontColour = wxNullColour; |
8826f46f | 141 | |
c9d59ee7 WS |
142 | m_showHelp = false; |
143 | m_allowSymbols = true; | |
144 | m_enableEffects = true; | |
ae500232 JS |
145 | m_minSize = 0; |
146 | m_maxSize = 0; | |
c801d85f | 147 | |
7beba2fc | 148 | m_encoding = wxFONTENCODING_SYSTEM; |
c801d85f KB |
149 | } |
150 | ||
8bbe427f | 151 | wxFontData::~wxFontData() |
c801d85f KB |
152 | { |
153 | } | |
154 | ||
dbc65e27 VZ |
155 | #if wxUSE_FONTDLG |
156 | ||
157 | wxFontDialogBase::~wxFontDialogBase() | |
158 | { | |
159 | } | |
160 | ||
161 | #endif // wxUSE_FONTDLG | |
162 | ||
88ac883a | 163 | #if wxUSE_PRINTING_ARCHITECTURE |
8826f46f VZ |
164 | // ---------------------------------------------------------------------------- |
165 | // Print data | |
166 | // ---------------------------------------------------------------------------- | |
c801d85f | 167 | |
8bbe427f | 168 | wxPrintData::wxPrintData() |
c801d85f | 169 | { |
8850cbd3 | 170 | #ifdef __WXMAC__ |
746d7582 | 171 | m_nativePrintData = wxNativePrintData::Create() ; |
c801d85f | 172 | #endif |
60090256 | 173 | m_bin = wxPRINTBIN_DEFAULT; |
6038ec8e | 174 | m_printMode = wxPRINT_MODE_PRINTER; |
7bcb11d3 JS |
175 | m_printOrientation = wxPORTRAIT; |
176 | m_printNoCopies = 1; | |
c9d59ee7 | 177 | m_printCollate = false; |
8826f46f | 178 | |
7bcb11d3 | 179 | // New, 24/3/99 |
2b5f62a0 | 180 | m_printerName = wxT(""); |
c9d59ee7 | 181 | m_colour = true; |
7bcb11d3 JS |
182 | m_duplexMode = wxDUPLEX_SIMPLEX; |
183 | m_printQuality = wxPRINT_QUALITY_HIGH; | |
184 | m_paperId = wxPAPER_A4; | |
185 | m_paperSize = wxSize(210, 297); | |
186 | ||
8850cbd3 | 187 | m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData(); |
7bcb11d3 JS |
188 | } |
189 | ||
190 | wxPrintData::wxPrintData(const wxPrintData& printData) | |
5e472c1f | 191 | : wxObject() |
7bcb11d3 JS |
192 | { |
193 | (*this) = printData; | |
c801d85f KB |
194 | } |
195 | ||
8bbe427f | 196 | wxPrintData::~wxPrintData() |
c801d85f | 197 | { |
8850cbd3 RR |
198 | m_nativeData->m_ref--; |
199 | if (m_nativeData->m_ref == 0) | |
200 | delete m_nativeData; | |
201 | ||
202 | #ifdef __WXMAC__ | |
746d7582 | 203 | delete m_nativePrintData ; |
c801d85f KB |
204 | #endif |
205 | } | |
206 | ||
7bcb11d3 | 207 | |
51abe921 SC |
208 | #ifdef __WXMAC__ |
209 | void wxPrintData::ConvertToNative() | |
210 | { | |
746d7582 | 211 | m_nativePrintData->TransferFrom( this ) ; |
51abe921 SC |
212 | } |
213 | ||
214 | void wxPrintData::ConvertFromNative() | |
215 | { | |
746d7582 | 216 | m_nativePrintData->TransferTo( this ) ; |
51abe921 SC |
217 | } |
218 | #endif | |
219 | ||
7bcb11d3 JS |
220 | void wxPrintData::operator=(const wxPrintData& data) |
221 | { | |
222 | m_printNoCopies = data.m_printNoCopies; | |
223 | m_printCollate = data.m_printCollate; | |
224 | m_printOrientation = data.m_printOrientation; | |
225 | m_printerName = data.m_printerName; | |
226 | m_colour = data.m_colour; | |
227 | m_duplexMode = data.m_duplexMode; | |
228 | m_printQuality = data.m_printQuality; | |
229 | m_paperId = data.m_paperId; | |
230 | m_paperSize = data.m_paperSize; | |
60090256 | 231 | m_bin = data.m_bin; |
6038ec8e | 232 | m_printMode = data.m_printMode; |
8850cbd3 RR |
233 | |
234 | m_nativeData = data.GetNativeData(); | |
235 | m_nativeData->m_ref++; | |
236 | ||
237 | #ifdef __WXMAC__ | |
238 | m_nativePrintData->CopyFrom( data.m_nativePrintData ) ; | |
244e5e34 | 239 | #endif |
7bcb11d3 JS |
240 | } |
241 | ||
58cf0491 JS |
242 | // Is this data OK for showing the print dialog? |
243 | bool wxPrintData::Ok() const | |
244 | { | |
fd64de59 | 245 | m_nativeData->TransferFrom( *this ); |
8850cbd3 RR |
246 | |
247 | return m_nativeData->Ok(); | |
58cf0491 | 248 | } |
8826f46f VZ |
249 | |
250 | // ---------------------------------------------------------------------------- | |
251 | // Print dialog data | |
252 | // ---------------------------------------------------------------------------- | |
7bcb11d3 JS |
253 | |
254 | wxPrintDialogData::wxPrintDialogData() | |
255 | { | |
256 | #ifdef __WXMSW__ | |
257 | m_printDlgData = NULL; | |
258 | #endif | |
259 | m_printFromPage = 0; | |
260 | m_printToPage = 0; | |
261 | m_printMinPage = 0; | |
262 | m_printMaxPage = 0; | |
263 | m_printNoCopies = 1; | |
c9d59ee7 WS |
264 | m_printAllPages = false; |
265 | m_printCollate = false; | |
266 | m_printToFile = false; | |
267 | m_printSelection = false; | |
268 | m_printEnableSelection = false; | |
269 | m_printEnablePageNumbers = true; | |
9f1316dc RR |
270 | |
271 | wxPrintFactory* factory = wxPrintFactory::GetFactory(); | |
272 | m_printEnablePrintToFile = ! factory->HasOwnPrintToFile(); | |
273 | ||
c9d59ee7 WS |
274 | m_printEnableHelp = false; |
275 | m_printSetupDialog = false; | |
7bcb11d3 JS |
276 | } |
277 | ||
278 | wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData) | |
5e472c1f | 279 | : wxObject() |
7bcb11d3 | 280 | { |
7c74e7fe SC |
281 | #ifdef __WXMSW__ |
282 | m_printDlgData = NULL; | |
7c74e7fe | 283 | #endif |
7bcb11d3 JS |
284 | (*this) = dialogData; |
285 | } | |
286 | ||
287 | wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData) | |
288 | { | |
289 | #ifdef __WXMSW__ | |
290 | m_printDlgData = NULL; | |
291 | #endif | |
d2b354f9 | 292 | m_printFromPage = 1; |
7bcb11d3 | 293 | m_printToPage = 0; |
d2b354f9 JS |
294 | m_printMinPage = 1; |
295 | m_printMaxPage = 9999; | |
7bcb11d3 | 296 | m_printNoCopies = 1; |
c9d59ee7 WS |
297 | m_printAllPages = false; |
298 | m_printCollate = false; | |
299 | m_printToFile = false; | |
300 | m_printSelection = false; | |
301 | m_printEnableSelection = false; | |
302 | m_printEnablePageNumbers = true; | |
303 | m_printEnablePrintToFile = true; | |
304 | m_printEnableHelp = false; | |
305 | m_printSetupDialog = false; | |
7bcb11d3 JS |
306 | |
307 | m_printData = printData; | |
308 | } | |
309 | ||
310 | wxPrintDialogData::~wxPrintDialogData() | |
311 | { | |
312 | #ifdef __WXMSW__ | |
313 | PRINTDLG *pd = (PRINTDLG *) m_printDlgData; | |
314 | if ( pd && pd->hDevMode ) | |
315 | GlobalFree(pd->hDevMode); | |
316 | if ( pd ) | |
317 | delete pd; | |
318 | #endif | |
319 | } | |
320 | ||
321 | #ifdef __WXMSW__ | |
322 | void wxPrintDialogData::ConvertToNative() | |
323 | { | |
8850cbd3 RR |
324 | wxWindowsPrintNativeData *data = |
325 | (wxWindowsPrintNativeData *) m_printData.GetNativeData(); | |
fd64de59 | 326 | data->TransferFrom( m_printData ); |
7bcb11d3 JS |
327 | |
328 | PRINTDLG *pd = (PRINTDLG*) m_printDlgData; | |
329 | ||
330 | if (!pd) | |
331 | { | |
332 | pd = new PRINTDLG; | |
161f4f73 | 333 | memset( pd, 0, sizeof(PRINTDLG) ); |
7bcb11d3 JS |
334 | m_printDlgData = (void*) pd; |
335 | ||
336 | // GNU-WIN32 has the wrong size PRINTDLG - can't work out why. | |
337 | #ifdef __GNUWIN32__ | |
161f4f73 | 338 | pd->lStructSize = 66; |
7bcb11d3 | 339 | #else |
7bcb11d3 | 340 | pd->lStructSize = sizeof(PRINTDLG); |
25889d3c | 341 | #endif |
7bcb11d3 JS |
342 | pd->hwndOwner = (HWND)NULL; |
343 | pd->hDevMode = NULL; // Will be created by PrintDlg | |
344 | pd->hDevNames = NULL; // Ditto | |
345 | ||
346 | pd->Flags = PD_RETURNDEFAULT; | |
347 | pd->nCopies = 1; | |
348 | } | |
349 | ||
350 | // Pass the devmode data to the PRINTDLG structure, since it'll | |
351 | // be needed when PrintDlg is called. | |
352 | if (pd->hDevMode) | |
353 | { | |
354 | GlobalFree(pd->hDevMode); | |
355 | } | |
356 | ||
eaeb6a3c JS |
357 | // Pass the devnames data to the PRINTDLG structure, since it'll |
358 | // be needed when PrintDlg is called. | |
359 | if (pd->hDevNames) | |
360 | { | |
361 | GlobalFree(pd->hDevNames); | |
362 | } | |
363 | ||
fd64de59 | 364 | pd->hDevMode = (HGLOBAL)(DWORD) data->GetDevMode(); |
7bcb11d3 | 365 | |
fd64de59 | 366 | data->SetDevMode( (void*) NULL); |
7bcb11d3 | 367 | |
58cf0491 JS |
368 | // Shouldn't assert; we should be able to test Ok-ness at a higher level |
369 | //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); | |
7bcb11d3 | 370 | |
fd64de59 | 371 | pd->hDevNames = (HGLOBAL)(DWORD) data->GetDevNames(); |
eaeb6a3c | 372 | |
fd64de59 | 373 | data->SetDevNames( (void*) NULL); |
eaeb6a3c | 374 | |
7bcb11d3 | 375 | pd->hDC = (HDC) NULL; |
33ac7e6f KB |
376 | pd->nFromPage = (WORD)m_printFromPage; |
377 | pd->nToPage = (WORD)m_printToPage; | |
378 | pd->nMinPage = (WORD)m_printMinPage; | |
379 | pd->nMaxPage = (WORD)m_printMaxPage; | |
380 | pd->nCopies = (WORD)m_printNoCopies; | |
8826f46f | 381 | |
161f4f73 | 382 | pd->Flags = PD_RETURNDC; |
7bcb11d3 JS |
383 | |
384 | #ifdef __GNUWIN32__ | |
161f4f73 | 385 | pd->lStructSize = 66; |
7bcb11d3 JS |
386 | #else |
387 | pd->lStructSize = sizeof( PRINTDLG ); | |
388 | #endif | |
389 | ||
8b9518ee | 390 | pd->hwndOwner=(HWND)NULL; |
eaeb6a3c | 391 | // pd->hDevNames=(HANDLE)NULL; |
c801d85f KB |
392 | pd->hInstance=(HINSTANCE)NULL; |
393 | pd->lCustData = (LPARAM) NULL; | |
394 | pd->lpfnPrintHook = NULL; | |
395 | pd->lpfnSetupHook = NULL; | |
396 | pd->lpPrintTemplateName = NULL; | |
397 | pd->lpSetupTemplateName = NULL; | |
398 | pd->hPrintTemplate = (HGLOBAL) NULL; | |
399 | pd->hSetupTemplate = (HGLOBAL) NULL; | |
8826f46f | 400 | |
7bcb11d3 | 401 | if ( m_printAllPages ) |
c801d85f | 402 | pd->Flags |= PD_ALLPAGES; |
8084a109 | 403 | if ( m_printSelection ) |
5360828d | 404 | pd->Flags |= PD_SELECTION; |
7bcb11d3 | 405 | if ( m_printCollate ) |
c801d85f | 406 | pd->Flags |= PD_COLLATE; |
7bcb11d3 | 407 | if ( m_printToFile ) |
c801d85f | 408 | pd->Flags |= PD_PRINTTOFILE; |
7bcb11d3 | 409 | if ( !m_printEnablePrintToFile ) |
c801d85f | 410 | pd->Flags |= PD_DISABLEPRINTTOFILE; |
7bcb11d3 JS |
411 | if ( !m_printEnableSelection ) |
412 | pd->Flags |= PD_NOSELECTION; | |
413 | if ( !m_printEnablePageNumbers ) | |
414 | pd->Flags |= PD_NOPAGENUMS; | |
d2b354f9 | 415 | else if ( (!m_printAllPages) && (!m_printSelection) && (m_printFromPage != 0) && (m_printToPage != 0)) |
40474984 | 416 | pd->Flags |= PD_PAGENUMS; |
7bcb11d3 JS |
417 | if ( m_printEnableHelp ) |
418 | pd->Flags |= PD_SHOWHELP; | |
419 | if ( m_printSetupDialog ) | |
420 | pd->Flags |= PD_PRINTSETUP; | |
c801d85f KB |
421 | } |
422 | ||
7bcb11d3 | 423 | void wxPrintDialogData::ConvertFromNative() |
c801d85f | 424 | { |
7bcb11d3 | 425 | PRINTDLG *pd = (PRINTDLG*) m_printDlgData; |
c801d85f KB |
426 | if ( pd == NULL ) |
427 | return; | |
428 | ||
8850cbd3 RR |
429 | wxWindowsPrintNativeData *data = |
430 | (wxWindowsPrintNativeData *) m_printData.GetNativeData(); | |
431 | ||
7bcb11d3 JS |
432 | // Pass the devmode data back to the wxPrintData structure where it really belongs. |
433 | if (pd->hDevMode) | |
c801d85f | 434 | { |
fd64de59 | 435 | if (data->GetDevMode()) |
7bcb11d3 JS |
436 | { |
437 | // Make sure we don't leak memory | |
fd64de59 | 438 | GlobalFree( (HGLOBAL)(DWORD) data->GetDevMode() ); |
7bcb11d3 | 439 | } |
fd64de59 | 440 | data->SetDevMode( (void*)(long) pd->hDevMode ); |
7bcb11d3 | 441 | pd->hDevMode = NULL; |
c801d85f | 442 | } |
c801d85f | 443 | |
eaeb6a3c JS |
444 | // Pass the devnames data back to the wxPrintData structure where it really belongs. |
445 | if (pd->hDevNames) | |
446 | { | |
fd64de59 | 447 | if (data->GetDevNames()) |
eaeb6a3c JS |
448 | { |
449 | // Make sure we don't leak memory | |
fd64de59 | 450 | GlobalFree((HGLOBAL)(DWORD) data->GetDevNames()); |
eaeb6a3c | 451 | } |
fd64de59 | 452 | data->SetDevNames((void*)(long) pd->hDevNames); |
eaeb6a3c JS |
453 | pd->hDevNames = NULL; |
454 | } | |
455 | ||
7bcb11d3 | 456 | // Now convert the DEVMODE object, passed down from the PRINTDLG object, |
77ffb593 | 457 | // into wxWidgets form. |
fd64de59 | 458 | data->TransferTo( m_printData ); |
7bcb11d3 | 459 | |
161f4f73 VZ |
460 | m_printFromPage = pd->nFromPage; |
461 | m_printToPage = pd->nToPage; | |
462 | m_printMinPage = pd->nMinPage; | |
463 | m_printMaxPage = pd->nMaxPage; | |
464 | m_printNoCopies = pd->nCopies; | |
8826f46f | 465 | |
40474984 | 466 | m_printAllPages = (((pd->Flags & PD_PAGENUMS) != PD_PAGENUMS) && ((pd->Flags & PD_SELECTION) != PD_SELECTION)); |
5360828d | 467 | m_printSelection = ((pd->Flags & PD_SELECTION) == PD_SELECTION); |
7bcb11d3 JS |
468 | m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE); |
469 | m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE); | |
470 | m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE); | |
471 | m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION); | |
472 | m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS); | |
473 | m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP); | |
474 | m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP); | |
475 | ||
476 | /* port is obsolete in WIN32 | |
477 | // Get the port name | |
478 | if (pd->hDevNames) | |
479 | { | |
480 | LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames); | |
481 | if (lpDevNames) { | |
482 | m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset); | |
483 | wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset; | |
484 | GlobalUnlock(pd->hDevNames); | |
8826f46f | 485 | |
7bcb11d3 JS |
486 | // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!"); |
487 | } | |
488 | } | |
489 | */ | |
c801d85f KB |
490 | } |
491 | ||
7bcb11d3 | 492 | void wxPrintDialogData::SetOwnerWindow(wxWindow* win) |
c801d85f | 493 | { |
7bcb11d3 | 494 | if ( m_printDlgData == NULL ) |
c801d85f | 495 | ConvertToNative(); |
8826f46f | 496 | |
7bcb11d3 | 497 | if ( m_printDlgData != NULL && win != NULL) |
c801d85f | 498 | { |
161f4f73 | 499 | PRINTDLG *pd = (PRINTDLG *) m_printDlgData; |
7bcb11d3 | 500 | pd->hwndOwner=(HWND) win->GetHWND(); |
c801d85f KB |
501 | } |
502 | } | |
8826f46f | 503 | #endif // MSW |
c801d85f | 504 | |
51abe921 | 505 | #ifdef __WXMAC__ |
cfb00da4 | 506 | |
51abe921 SC |
507 | void wxPrintDialogData::ConvertToNative() |
508 | { | |
cfb00da4 | 509 | m_printData.ConvertToNative(); |
746d7582 | 510 | m_printData.m_nativePrintData->TransferFrom( this ) ; |
51abe921 SC |
511 | } |
512 | ||
513 | void wxPrintDialogData::ConvertFromNative() | |
514 | { | |
cfb00da4 | 515 | m_printData.ConvertFromNative(); |
746d7582 | 516 | m_printData.m_nativePrintData->TransferTo( this ) ; |
51abe921 | 517 | } |
cfb00da4 | 518 | |
51abe921 SC |
519 | #endif |
520 | ||
521 | ||
7bcb11d3 | 522 | void wxPrintDialogData::operator=(const wxPrintDialogData& data) |
c801d85f | 523 | { |
7bcb11d3 JS |
524 | m_printFromPage = data.m_printFromPage; |
525 | m_printToPage = data.m_printToPage; | |
526 | m_printMinPage = data.m_printMinPage; | |
527 | m_printMaxPage = data.m_printMaxPage; | |
528 | m_printNoCopies = data.m_printNoCopies; | |
529 | m_printAllPages = data.m_printAllPages; | |
530 | m_printCollate = data.m_printCollate; | |
531 | m_printToFile = data.m_printToFile; | |
5360828d | 532 | m_printSelection = data.m_printSelection; |
7bcb11d3 JS |
533 | m_printEnableSelection = data.m_printEnableSelection; |
534 | m_printEnablePageNumbers = data.m_printEnablePageNumbers; | |
535 | m_printEnableHelp = data.m_printEnableHelp; | |
536 | m_printEnablePrintToFile = data.m_printEnablePrintToFile; | |
537 | m_printSetupDialog = data.m_printSetupDialog; | |
538 | ||
539 | m_printData = data.m_printData; | |
540 | } | |
541 | ||
542 | void wxPrintDialogData::operator=(const wxPrintData& data) | |
543 | { | |
544 | m_printData = data; | |
c801d85f KB |
545 | } |
546 | ||
8826f46f VZ |
547 | // ---------------------------------------------------------------------------- |
548 | // wxPageSetupDialogData | |
549 | // ---------------------------------------------------------------------------- | |
c801d85f | 550 | |
7bcb11d3 | 551 | wxPageSetupDialogData::wxPageSetupDialogData() |
c801d85f KB |
552 | { |
553 | #if defined(__WIN95__) | |
7bcb11d3 | 554 | m_pageSetupData = NULL; |
c801d85f | 555 | #endif |
7bcb11d3 JS |
556 | m_paperSize = wxSize(0, 0); |
557 | ||
558 | CalculatePaperSizeFromId(); | |
559 | ||
560 | m_minMarginTopLeft = wxPoint(0, 0); | |
561 | m_minMarginBottomRight = wxPoint(0, 0); | |
562 | m_marginTopLeft = wxPoint(0, 0); | |
563 | m_marginBottomRight = wxPoint(0, 0); | |
564 | ||
565 | // Flags | |
c9d59ee7 WS |
566 | m_defaultMinMargins = false; |
567 | m_enableMargins = true; | |
568 | m_enableOrientation = true; | |
569 | m_enablePaper = true; | |
570 | m_enablePrinter = true; | |
571 | m_enableHelp = false; | |
572 | m_getDefaultInfo = false; | |
7bcb11d3 | 573 | } |
c801d85f | 574 | |
7bcb11d3 | 575 | wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData) |
5e472c1f | 576 | : wxObject() |
7bcb11d3 | 577 | { |
7c74e7fe SC |
578 | #if defined(__WIN95__) |
579 | m_pageSetupData = NULL; | |
7c74e7fe | 580 | #endif |
7bcb11d3 JS |
581 | (*this) = dialogData; |
582 | } | |
583 | ||
584 | wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData) | |
585 | { | |
586 | #if defined(__WIN95__) | |
587 | m_pageSetupData = NULL; | |
588 | #endif | |
589 | m_paperSize = wxSize(0, 0); | |
590 | m_minMarginTopLeft = wxPoint(0, 0); | |
591 | m_minMarginBottomRight = wxPoint(0, 0); | |
592 | m_marginTopLeft = wxPoint(0, 0); | |
593 | m_marginBottomRight = wxPoint(0, 0); | |
594 | ||
595 | // Flags | |
c9d59ee7 WS |
596 | m_defaultMinMargins = false; |
597 | m_enableMargins = true; | |
598 | m_enableOrientation = true; | |
599 | m_enablePaper = true; | |
600 | m_enablePrinter = true; | |
601 | m_enableHelp = false; | |
602 | m_getDefaultInfo = false; | |
7bcb11d3 JS |
603 | |
604 | m_printData = printData; | |
605 | ||
606 | // The wxPrintData paper size overrides these values, unless the size cannot | |
607 | // be found. | |
608 | CalculatePaperSizeFromId(); | |
c801d85f KB |
609 | } |
610 | ||
7bcb11d3 | 611 | wxPageSetupDialogData::~wxPageSetupDialogData() |
c801d85f | 612 | { |
34138703 | 613 | #if defined(__WIN95__) && defined(__WXMSW__) |
c801d85f KB |
614 | PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData; |
615 | if ( pd && pd->hDevMode ) | |
616 | GlobalFree(pd->hDevMode); | |
eaeb6a3c JS |
617 | if ( pd && pd->hDevNames ) |
618 | GlobalFree(pd->hDevNames); | |
c801d85f KB |
619 | if ( pd ) |
620 | delete pd; | |
621 | #endif | |
622 | } | |
623 | ||
5e472c1f | 624 | wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data) |
c801d85f | 625 | { |
7bcb11d3 JS |
626 | m_paperSize = data.m_paperSize; |
627 | m_minMarginTopLeft = data.m_minMarginTopLeft; | |
628 | m_minMarginBottomRight = data.m_minMarginBottomRight; | |
629 | m_marginTopLeft = data.m_marginTopLeft; | |
630 | m_marginBottomRight = data.m_marginBottomRight; | |
631 | m_defaultMinMargins = data.m_defaultMinMargins; | |
632 | m_enableMargins = data.m_enableMargins; | |
633 | m_enableOrientation = data.m_enableOrientation; | |
634 | m_enablePaper = data.m_enablePaper; | |
635 | m_enablePrinter = data.m_enablePrinter; | |
636 | m_getDefaultInfo = data.m_getDefaultInfo;; | |
637 | m_enableHelp = data.m_enableHelp; | |
638 | ||
639 | m_printData = data.m_printData; | |
5e472c1f GD |
640 | |
641 | return *this; | |
7bcb11d3 | 642 | } |
c801d85f | 643 | |
5e472c1f | 644 | wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data) |
7bcb11d3 JS |
645 | { |
646 | m_printData = data; | |
5e472c1f GD |
647 | |
648 | return *this; | |
c801d85f KB |
649 | } |
650 | ||
8826f46f | 651 | #if defined(__WIN95__) |
7bcb11d3 | 652 | void wxPageSetupDialogData::ConvertToNative() |
c801d85f | 653 | { |
8850cbd3 RR |
654 | wxWindowsPrintNativeData *data = |
655 | (wxWindowsPrintNativeData *) m_printData.GetNativeData(); | |
fd64de59 | 656 | data->TransferFrom( m_printData ); |
7bcb11d3 | 657 | |
c801d85f | 658 | PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData; |
7bcb11d3 | 659 | |
c801d85f KB |
660 | if ( m_pageSetupData == NULL ) |
661 | { | |
7bcb11d3 JS |
662 | pd = new PAGESETUPDLG; |
663 | pd->hDevMode = NULL; | |
eaeb6a3c | 664 | pd->hDevNames = NULL; |
7bcb11d3 | 665 | m_pageSetupData = (void *)pd; |
c801d85f | 666 | } |
8bbe427f | 667 | |
7bcb11d3 JS |
668 | // Pass the devmode data (created in m_printData.ConvertToNative) |
669 | // to the PRINTDLG structure, since it'll | |
670 | // be needed when PrintDlg is called. | |
671 | ||
672 | if (pd->hDevMode) | |
673 | { | |
674 | GlobalFree(pd->hDevMode); | |
675 | pd->hDevMode = NULL; | |
676 | } | |
677 | ||
fd64de59 | 678 | pd->hDevMode = (HGLOBAL) data->GetDevMode(); |
7bcb11d3 | 679 | |
fd64de59 | 680 | data->SetDevMode( (void*) NULL ); |
7bcb11d3 | 681 | |
58cf0491 JS |
682 | // Shouldn't assert; we should be able to test Ok-ness at a higher level |
683 | //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); | |
7bcb11d3 | 684 | |
eaeb6a3c JS |
685 | // Pass the devnames data (created in m_printData.ConvertToNative) |
686 | // to the PRINTDLG structure, since it'll | |
687 | // be needed when PrintDlg is called. | |
688 | ||
689 | if (pd->hDevNames) | |
690 | { | |
691 | GlobalFree(pd->hDevNames); | |
692 | pd->hDevNames = NULL; | |
693 | } | |
694 | ||
fd64de59 | 695 | pd->hDevNames = (HGLOBAL) data->GetDevNames(); |
eaeb6a3c | 696 | |
fd64de59 | 697 | data->SetDevNames((void*) NULL); |
eaeb6a3c | 698 | |
7bcb11d3 | 699 | // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE)); |
c801d85f | 700 | |
7bcb11d3 | 701 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; |
8826f46f | 702 | |
c801d85f KB |
703 | if ( m_defaultMinMargins ) |
704 | pd->Flags |= PSD_DEFAULTMINMARGINS; | |
705 | if ( !m_enableMargins ) | |
706 | pd->Flags |= PSD_DISABLEMARGINS; | |
707 | if ( !m_enableOrientation ) | |
708 | pd->Flags |= PSD_DISABLEORIENTATION; | |
709 | if ( !m_enablePaper ) | |
710 | pd->Flags |= PSD_DISABLEPAPER; | |
711 | if ( !m_enablePrinter ) | |
712 | pd->Flags |= PSD_DISABLEPRINTER; | |
713 | if ( m_getDefaultInfo ) | |
714 | pd->Flags |= PSD_RETURNDEFAULT; | |
715 | if ( m_enableHelp ) | |
716 | pd->Flags |= PSD_SHOWHELP; | |
717 | ||
7bcb11d3 JS |
718 | // We want the units to be in hundredths of a millimetre |
719 | pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS; | |
720 | ||
c801d85f | 721 | pd->lStructSize = sizeof( PAGESETUPDLG ); |
c4e7c2aa | 722 | pd->hwndOwner=(HWND)NULL; |
eaeb6a3c | 723 | // pd->hDevNames=(HWND)NULL; |
c801d85f | 724 | pd->hInstance=(HINSTANCE)NULL; |
161f4f73 | 725 | // PAGESETUPDLG is in hundreds of a mm |
7bcb11d3 JS |
726 | pd->ptPaperSize.x = m_paperSize.x * 100; |
727 | pd->ptPaperSize.y = m_paperSize.y * 100; | |
8826f46f | 728 | |
7bcb11d3 JS |
729 | pd->rtMinMargin.left = m_minMarginTopLeft.x * 100; |
730 | pd->rtMinMargin.top = m_minMarginTopLeft.y * 100; | |
731 | pd->rtMinMargin.right = m_minMarginBottomRight.x * 100; | |
732 | pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100; | |
8826f46f | 733 | |
7bcb11d3 JS |
734 | pd->rtMargin.left = m_marginTopLeft.x * 100; |
735 | pd->rtMargin.top = m_marginTopLeft.y * 100; | |
736 | pd->rtMargin.right = m_marginBottomRight.x * 100; | |
737 | pd->rtMargin.bottom = m_marginBottomRight.y * 100; | |
8826f46f | 738 | |
c801d85f KB |
739 | pd->lCustData = 0; |
740 | pd->lpfnPageSetupHook = NULL; | |
741 | pd->lpfnPagePaintHook = NULL; | |
742 | pd->hPageSetupTemplate = NULL; | |
743 | pd->lpPageSetupTemplateName = NULL; | |
744 | ||
8826f46f | 745 | /* |
c801d85f KB |
746 | if ( pd->hDevMode ) |
747 | { | |
748 | DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode); | |
749 | memset(devMode, 0, sizeof(DEVMODE)); | |
750 | devMode->dmSize = sizeof(DEVMODE); | |
751 | devMode->dmOrientation = m_orientation; | |
752 | devMode->dmFields = DM_ORIENTATION; | |
753 | GlobalUnlock(pd->hDevMode); | |
754 | } | |
7bcb11d3 | 755 | */ |
c801d85f KB |
756 | } |
757 | ||
7bcb11d3 | 758 | void wxPageSetupDialogData::ConvertFromNative() |
c801d85f | 759 | { |
161f4f73 | 760 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData; |
c801d85f KB |
761 | if ( !pd ) |
762 | return; | |
8826f46f | 763 | |
8850cbd3 RR |
764 | wxWindowsPrintNativeData *data = |
765 | (wxWindowsPrintNativeData *) m_printData.GetNativeData(); | |
766 | ||
7bcb11d3 JS |
767 | // Pass the devmode data back to the wxPrintData structure where it really belongs. |
768 | if (pd->hDevMode) | |
769 | { | |
fd64de59 | 770 | if (data->GetDevMode()) |
7bcb11d3 JS |
771 | { |
772 | // Make sure we don't leak memory | |
fd64de59 | 773 | GlobalFree((HGLOBAL) data->GetDevMode()); |
7bcb11d3 | 774 | } |
fd64de59 | 775 | data->SetDevMode( (void*) pd->hDevMode ); |
7bcb11d3 JS |
776 | pd->hDevMode = NULL; |
777 | } | |
c801d85f | 778 | |
fd64de59 | 779 | data->TransferTo( m_printData ); |
c801d85f | 780 | |
eaeb6a3c JS |
781 | // Pass the devnames data back to the wxPrintData structure where it really belongs. |
782 | if (pd->hDevNames) | |
783 | { | |
fd64de59 | 784 | if (data->GetDevNames()) |
eaeb6a3c JS |
785 | { |
786 | // Make sure we don't leak memory | |
fd64de59 | 787 | GlobalFree((HGLOBAL) data->GetDevNames()); |
eaeb6a3c | 788 | } |
fd64de59 | 789 | data->SetDevNames((void*) pd->hDevNames); |
eaeb6a3c JS |
790 | pd->hDevNames = NULL; |
791 | } | |
792 | ||
fd64de59 | 793 | data->TransferTo( m_printData ); |
eaeb6a3c | 794 | |
7bcb11d3 | 795 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; |
8826f46f | 796 | |
c801d85f KB |
797 | m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS); |
798 | m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS); | |
799 | m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION); | |
800 | m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER); | |
801 | m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER); | |
802 | m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT); | |
803 | m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP); | |
8826f46f | 804 | |
161f4f73 | 805 | // PAGESETUPDLG is in hundreds of a mm |
7bcb11d3 JS |
806 | m_paperSize.x = pd->ptPaperSize.x / 100; |
807 | m_paperSize.y = pd->ptPaperSize.y / 100; | |
8826f46f | 808 | |
7bcb11d3 JS |
809 | m_minMarginTopLeft.x = pd->rtMinMargin.left / 100; |
810 | m_minMarginTopLeft.y = pd->rtMinMargin.top / 100; | |
811 | m_minMarginBottomRight.x = pd->rtMinMargin.right / 100; | |
812 | m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100; | |
8826f46f | 813 | |
161f4f73 VZ |
814 | m_marginTopLeft.x = pd->rtMargin.left / 100; |
815 | m_marginTopLeft.y = pd->rtMargin.top / 100; | |
816 | m_marginBottomRight.x = pd->rtMargin.right / 100; | |
817 | m_marginBottomRight.y = pd->rtMargin.bottom / 100; | |
7bcb11d3 | 818 | } |
c801d85f | 819 | |
7bcb11d3 JS |
820 | void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win) |
821 | { | |
822 | if ( m_pageSetupData == NULL ) | |
823 | ConvertToNative(); | |
8826f46f | 824 | |
7bcb11d3 JS |
825 | if ( m_pageSetupData != NULL && win != NULL) |
826 | { | |
161f4f73 | 827 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData; |
7bcb11d3 JS |
828 | pd->hwndOwner=(HWND) win->GetHWND(); |
829 | } | |
830 | } | |
8826f46f | 831 | #endif // Win95 |
c801d85f | 832 | |
51abe921 | 833 | #ifdef __WXMAC__ |
7c74e7fe | 834 | void wxPageSetupDialogData::ConvertToNative() |
51abe921 | 835 | { |
161f4f73 | 836 | m_printData.ConvertToNative(); |
746d7582 | 837 | m_printData.m_nativePrintData->TransferFrom( this ) ; |
51abe921 SC |
838 | } |
839 | ||
7c74e7fe | 840 | void wxPageSetupDialogData::ConvertFromNative() |
51abe921 | 841 | { |
161f4f73 | 842 | m_printData.ConvertFromNative (); |
cfb00da4 SC |
843 | m_paperSize = m_printData.GetPaperSize() ; |
844 | CalculateIdFromPaperSize(); | |
746d7582 | 845 | m_printData.m_nativePrintData->TransferTo( this ) ; |
161f4f73 | 846 | // adjust minimal values |
161f4f73 VZ |
847 | |
848 | if ( m_marginTopLeft.x < m_minMarginTopLeft.x ) | |
849 | m_marginTopLeft.x = m_minMarginTopLeft.x; | |
850 | ||
851 | if ( m_marginBottomRight.x < m_minMarginBottomRight.x ) | |
852 | m_marginBottomRight.x = m_minMarginBottomRight.x; | |
853 | ||
854 | if ( m_marginTopLeft.y < m_minMarginTopLeft.y ) | |
855 | m_marginTopLeft.y = m_minMarginTopLeft.y; | |
856 | ||
857 | if ( m_marginBottomRight.y < m_minMarginBottomRight.y ) | |
858 | m_marginBottomRight.y = m_minMarginBottomRight.y; | |
51abe921 SC |
859 | } |
860 | #endif | |
861 | ||
862 | ||
7bcb11d3 JS |
863 | // If a corresponding paper type is found in the paper database, will set the m_printData |
864 | // paper size id member as well. | |
865 | void wxPageSetupDialogData::SetPaperSize(const wxSize& sz) | |
866 | { | |
867 | m_paperSize = sz; | |
c801d85f | 868 | |
7bcb11d3 JS |
869 | CalculateIdFromPaperSize(); |
870 | } | |
c801d85f | 871 | |
7bcb11d3 JS |
872 | // Sets the wxPrintData id, plus the paper width/height if found in the paper database. |
873 | void wxPageSetupDialogData::SetPaperSize(wxPaperSize id) | |
874 | { | |
875 | m_printData.SetPaperId(id); | |
876 | ||
877 | CalculatePaperSizeFromId(); | |
c801d85f KB |
878 | } |
879 | ||
7bcb11d3 JS |
880 | // Use paper size defined in this object to set the wxPrintData |
881 | // paper id | |
882 | void wxPageSetupDialogData::CalculateIdFromPaperSize() | |
c801d85f | 883 | { |
8826f46f | 884 | wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL), |
fbdcff4a | 885 | wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") ); |
c801d85f | 886 | |
7bcb11d3 JS |
887 | wxSize sz = GetPaperSize(); |
888 | ||
889 | wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10)); | |
890 | if (id != wxPAPER_NONE) | |
c801d85f | 891 | { |
7bcb11d3 | 892 | m_printData.SetPaperId(id); |
c801d85f KB |
893 | } |
894 | } | |
8826f46f | 895 | |
7bcb11d3 JS |
896 | // Use paper id in wxPrintData to set this object's paper size |
897 | void wxPageSetupDialogData::CalculatePaperSizeFromId() | |
898 | { | |
8826f46f | 899 | wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL), |
fbdcff4a | 900 | wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") ); |
7bcb11d3 JS |
901 | |
902 | wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId()); | |
c801d85f | 903 | |
01cf2f95 VZ |
904 | // sz is in 10ths of a mm, while paper size is in mm |
905 | m_paperSize.x = sz.x / 10; | |
906 | m_paperSize.y = sz.y / 10; | |
7bcb11d3 | 907 | } |
8826f46f | 908 | |
88ac883a | 909 | #endif // wxUSE_PRINTING_ARCHITECTURE |