]>
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; |
01b5396f | 233 | m_filename = data.m_filename; |
8850cbd3 RR |
234 | |
235 | m_nativeData = data.GetNativeData(); | |
236 | m_nativeData->m_ref++; | |
237 | ||
238 | #ifdef __WXMAC__ | |
239 | m_nativePrintData->CopyFrom( data.m_nativePrintData ) ; | |
244e5e34 | 240 | #endif |
7bcb11d3 JS |
241 | } |
242 | ||
58cf0491 JS |
243 | // Is this data OK for showing the print dialog? |
244 | bool wxPrintData::Ok() const | |
245 | { | |
fd64de59 | 246 | m_nativeData->TransferFrom( *this ); |
8850cbd3 RR |
247 | |
248 | return m_nativeData->Ok(); | |
58cf0491 | 249 | } |
8826f46f VZ |
250 | |
251 | // ---------------------------------------------------------------------------- | |
252 | // Print dialog data | |
253 | // ---------------------------------------------------------------------------- | |
7bcb11d3 JS |
254 | |
255 | wxPrintDialogData::wxPrintDialogData() | |
256 | { | |
257 | #ifdef __WXMSW__ | |
258 | m_printDlgData = NULL; | |
259 | #endif | |
260 | m_printFromPage = 0; | |
261 | m_printToPage = 0; | |
262 | m_printMinPage = 0; | |
263 | m_printMaxPage = 0; | |
264 | m_printNoCopies = 1; | |
c9d59ee7 WS |
265 | m_printAllPages = false; |
266 | m_printCollate = false; | |
267 | m_printToFile = false; | |
268 | m_printSelection = false; | |
269 | m_printEnableSelection = false; | |
270 | m_printEnablePageNumbers = true; | |
9f1316dc RR |
271 | |
272 | wxPrintFactory* factory = wxPrintFactory::GetFactory(); | |
273 | m_printEnablePrintToFile = ! factory->HasOwnPrintToFile(); | |
274 | ||
c9d59ee7 WS |
275 | m_printEnableHelp = false; |
276 | m_printSetupDialog = false; | |
7bcb11d3 JS |
277 | } |
278 | ||
279 | wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData) | |
5e472c1f | 280 | : wxObject() |
7bcb11d3 | 281 | { |
7c74e7fe SC |
282 | #ifdef __WXMSW__ |
283 | m_printDlgData = NULL; | |
7c74e7fe | 284 | #endif |
7bcb11d3 JS |
285 | (*this) = dialogData; |
286 | } | |
287 | ||
288 | wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData) | |
289 | { | |
290 | #ifdef __WXMSW__ | |
291 | m_printDlgData = NULL; | |
292 | #endif | |
d2b354f9 | 293 | m_printFromPage = 1; |
7bcb11d3 | 294 | m_printToPage = 0; |
d2b354f9 JS |
295 | m_printMinPage = 1; |
296 | m_printMaxPage = 9999; | |
7bcb11d3 | 297 | m_printNoCopies = 1; |
c9d59ee7 WS |
298 | m_printAllPages = false; |
299 | m_printCollate = false; | |
300 | m_printToFile = false; | |
301 | m_printSelection = false; | |
302 | m_printEnableSelection = false; | |
303 | m_printEnablePageNumbers = true; | |
304 | m_printEnablePrintToFile = true; | |
305 | m_printEnableHelp = false; | |
306 | m_printSetupDialog = false; | |
7bcb11d3 JS |
307 | |
308 | m_printData = printData; | |
309 | } | |
310 | ||
311 | wxPrintDialogData::~wxPrintDialogData() | |
312 | { | |
313 | #ifdef __WXMSW__ | |
314 | PRINTDLG *pd = (PRINTDLG *) m_printDlgData; | |
315 | if ( pd && pd->hDevMode ) | |
316 | GlobalFree(pd->hDevMode); | |
317 | if ( pd ) | |
318 | delete pd; | |
319 | #endif | |
320 | } | |
321 | ||
322 | #ifdef __WXMSW__ | |
323 | void wxPrintDialogData::ConvertToNative() | |
324 | { | |
8850cbd3 RR |
325 | wxWindowsPrintNativeData *data = |
326 | (wxWindowsPrintNativeData *) m_printData.GetNativeData(); | |
fd64de59 | 327 | data->TransferFrom( m_printData ); |
7bcb11d3 JS |
328 | |
329 | PRINTDLG *pd = (PRINTDLG*) m_printDlgData; | |
330 | ||
331 | if (!pd) | |
332 | { | |
333 | pd = new PRINTDLG; | |
161f4f73 | 334 | memset( pd, 0, sizeof(PRINTDLG) ); |
7bcb11d3 JS |
335 | m_printDlgData = (void*) pd; |
336 | ||
337 | // GNU-WIN32 has the wrong size PRINTDLG - can't work out why. | |
338 | #ifdef __GNUWIN32__ | |
161f4f73 | 339 | pd->lStructSize = 66; |
7bcb11d3 | 340 | #else |
7bcb11d3 | 341 | pd->lStructSize = sizeof(PRINTDLG); |
25889d3c | 342 | #endif |
7bcb11d3 JS |
343 | pd->hwndOwner = (HWND)NULL; |
344 | pd->hDevMode = NULL; // Will be created by PrintDlg | |
345 | pd->hDevNames = NULL; // Ditto | |
346 | ||
347 | pd->Flags = PD_RETURNDEFAULT; | |
348 | pd->nCopies = 1; | |
349 | } | |
350 | ||
351 | // Pass the devmode data to the PRINTDLG structure, since it'll | |
352 | // be needed when PrintDlg is called. | |
353 | if (pd->hDevMode) | |
354 | { | |
355 | GlobalFree(pd->hDevMode); | |
356 | } | |
357 | ||
eaeb6a3c JS |
358 | // Pass the devnames data to the PRINTDLG structure, since it'll |
359 | // be needed when PrintDlg is called. | |
360 | if (pd->hDevNames) | |
361 | { | |
362 | GlobalFree(pd->hDevNames); | |
363 | } | |
364 | ||
fd64de59 | 365 | pd->hDevMode = (HGLOBAL)(DWORD) data->GetDevMode(); |
7bcb11d3 | 366 | |
fd64de59 | 367 | data->SetDevMode( (void*) NULL); |
7bcb11d3 | 368 | |
58cf0491 JS |
369 | // Shouldn't assert; we should be able to test Ok-ness at a higher level |
370 | //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); | |
7bcb11d3 | 371 | |
fd64de59 | 372 | pd->hDevNames = (HGLOBAL)(DWORD) data->GetDevNames(); |
eaeb6a3c | 373 | |
fd64de59 | 374 | data->SetDevNames( (void*) NULL); |
eaeb6a3c | 375 | |
7bcb11d3 | 376 | pd->hDC = (HDC) NULL; |
33ac7e6f KB |
377 | pd->nFromPage = (WORD)m_printFromPage; |
378 | pd->nToPage = (WORD)m_printToPage; | |
379 | pd->nMinPage = (WORD)m_printMinPage; | |
380 | pd->nMaxPage = (WORD)m_printMaxPage; | |
381 | pd->nCopies = (WORD)m_printNoCopies; | |
8826f46f | 382 | |
161f4f73 | 383 | pd->Flags = PD_RETURNDC; |
7bcb11d3 JS |
384 | |
385 | #ifdef __GNUWIN32__ | |
161f4f73 | 386 | pd->lStructSize = 66; |
7bcb11d3 JS |
387 | #else |
388 | pd->lStructSize = sizeof( PRINTDLG ); | |
389 | #endif | |
390 | ||
8b9518ee | 391 | pd->hwndOwner=(HWND)NULL; |
eaeb6a3c | 392 | // pd->hDevNames=(HANDLE)NULL; |
c801d85f KB |
393 | pd->hInstance=(HINSTANCE)NULL; |
394 | pd->lCustData = (LPARAM) NULL; | |
395 | pd->lpfnPrintHook = NULL; | |
396 | pd->lpfnSetupHook = NULL; | |
397 | pd->lpPrintTemplateName = NULL; | |
398 | pd->lpSetupTemplateName = NULL; | |
399 | pd->hPrintTemplate = (HGLOBAL) NULL; | |
400 | pd->hSetupTemplate = (HGLOBAL) NULL; | |
8826f46f | 401 | |
7bcb11d3 | 402 | if ( m_printAllPages ) |
c801d85f | 403 | pd->Flags |= PD_ALLPAGES; |
8084a109 | 404 | if ( m_printSelection ) |
5360828d | 405 | pd->Flags |= PD_SELECTION; |
7bcb11d3 | 406 | if ( m_printCollate ) |
c801d85f | 407 | pd->Flags |= PD_COLLATE; |
7bcb11d3 | 408 | if ( m_printToFile ) |
c801d85f | 409 | pd->Flags |= PD_PRINTTOFILE; |
7bcb11d3 | 410 | if ( !m_printEnablePrintToFile ) |
c801d85f | 411 | pd->Flags |= PD_DISABLEPRINTTOFILE; |
7bcb11d3 JS |
412 | if ( !m_printEnableSelection ) |
413 | pd->Flags |= PD_NOSELECTION; | |
414 | if ( !m_printEnablePageNumbers ) | |
415 | pd->Flags |= PD_NOPAGENUMS; | |
d2b354f9 | 416 | else if ( (!m_printAllPages) && (!m_printSelection) && (m_printFromPage != 0) && (m_printToPage != 0)) |
40474984 | 417 | pd->Flags |= PD_PAGENUMS; |
7bcb11d3 JS |
418 | if ( m_printEnableHelp ) |
419 | pd->Flags |= PD_SHOWHELP; | |
420 | if ( m_printSetupDialog ) | |
421 | pd->Flags |= PD_PRINTSETUP; | |
c801d85f KB |
422 | } |
423 | ||
7bcb11d3 | 424 | void wxPrintDialogData::ConvertFromNative() |
c801d85f | 425 | { |
7bcb11d3 | 426 | PRINTDLG *pd = (PRINTDLG*) m_printDlgData; |
c801d85f KB |
427 | if ( pd == NULL ) |
428 | return; | |
429 | ||
8850cbd3 RR |
430 | wxWindowsPrintNativeData *data = |
431 | (wxWindowsPrintNativeData *) m_printData.GetNativeData(); | |
432 | ||
7bcb11d3 JS |
433 | // Pass the devmode data back to the wxPrintData structure where it really belongs. |
434 | if (pd->hDevMode) | |
c801d85f | 435 | { |
fd64de59 | 436 | if (data->GetDevMode()) |
7bcb11d3 JS |
437 | { |
438 | // Make sure we don't leak memory | |
fd64de59 | 439 | GlobalFree( (HGLOBAL)(DWORD) data->GetDevMode() ); |
7bcb11d3 | 440 | } |
fd64de59 | 441 | data->SetDevMode( (void*)(long) pd->hDevMode ); |
7bcb11d3 | 442 | pd->hDevMode = NULL; |
c801d85f | 443 | } |
c801d85f | 444 | |
eaeb6a3c JS |
445 | // Pass the devnames data back to the wxPrintData structure where it really belongs. |
446 | if (pd->hDevNames) | |
447 | { | |
fd64de59 | 448 | if (data->GetDevNames()) |
eaeb6a3c JS |
449 | { |
450 | // Make sure we don't leak memory | |
fd64de59 | 451 | GlobalFree((HGLOBAL)(DWORD) data->GetDevNames()); |
eaeb6a3c | 452 | } |
fd64de59 | 453 | data->SetDevNames((void*)(long) pd->hDevNames); |
eaeb6a3c JS |
454 | pd->hDevNames = NULL; |
455 | } | |
456 | ||
7bcb11d3 | 457 | // Now convert the DEVMODE object, passed down from the PRINTDLG object, |
77ffb593 | 458 | // into wxWidgets form. |
fd64de59 | 459 | data->TransferTo( m_printData ); |
7bcb11d3 | 460 | |
161f4f73 VZ |
461 | m_printFromPage = pd->nFromPage; |
462 | m_printToPage = pd->nToPage; | |
463 | m_printMinPage = pd->nMinPage; | |
464 | m_printMaxPage = pd->nMaxPage; | |
465 | m_printNoCopies = pd->nCopies; | |
8826f46f | 466 | |
40474984 | 467 | m_printAllPages = (((pd->Flags & PD_PAGENUMS) != PD_PAGENUMS) && ((pd->Flags & PD_SELECTION) != PD_SELECTION)); |
5360828d | 468 | m_printSelection = ((pd->Flags & PD_SELECTION) == PD_SELECTION); |
7bcb11d3 JS |
469 | m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE); |
470 | m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE); | |
471 | m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE); | |
472 | m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION); | |
473 | m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS); | |
474 | m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP); | |
475 | m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP); | |
476 | ||
477 | /* port is obsolete in WIN32 | |
478 | // Get the port name | |
479 | if (pd->hDevNames) | |
480 | { | |
481 | LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames); | |
482 | if (lpDevNames) { | |
483 | m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset); | |
484 | wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset; | |
485 | GlobalUnlock(pd->hDevNames); | |
8826f46f | 486 | |
7bcb11d3 JS |
487 | // wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!"); |
488 | } | |
489 | } | |
490 | */ | |
c801d85f KB |
491 | } |
492 | ||
7bcb11d3 | 493 | void wxPrintDialogData::SetOwnerWindow(wxWindow* win) |
c801d85f | 494 | { |
7bcb11d3 | 495 | if ( m_printDlgData == NULL ) |
c801d85f | 496 | ConvertToNative(); |
8826f46f | 497 | |
7bcb11d3 | 498 | if ( m_printDlgData != NULL && win != NULL) |
c801d85f | 499 | { |
161f4f73 | 500 | PRINTDLG *pd = (PRINTDLG *) m_printDlgData; |
7bcb11d3 | 501 | pd->hwndOwner=(HWND) win->GetHWND(); |
c801d85f KB |
502 | } |
503 | } | |
8826f46f | 504 | #endif // MSW |
c801d85f | 505 | |
51abe921 | 506 | #ifdef __WXMAC__ |
cfb00da4 | 507 | |
51abe921 SC |
508 | void wxPrintDialogData::ConvertToNative() |
509 | { | |
cfb00da4 | 510 | m_printData.ConvertToNative(); |
746d7582 | 511 | m_printData.m_nativePrintData->TransferFrom( this ) ; |
51abe921 SC |
512 | } |
513 | ||
514 | void wxPrintDialogData::ConvertFromNative() | |
515 | { | |
cfb00da4 | 516 | m_printData.ConvertFromNative(); |
746d7582 | 517 | m_printData.m_nativePrintData->TransferTo( this ) ; |
51abe921 | 518 | } |
cfb00da4 | 519 | |
51abe921 SC |
520 | #endif |
521 | ||
522 | ||
7bcb11d3 | 523 | void wxPrintDialogData::operator=(const wxPrintDialogData& data) |
c801d85f | 524 | { |
7bcb11d3 JS |
525 | m_printFromPage = data.m_printFromPage; |
526 | m_printToPage = data.m_printToPage; | |
527 | m_printMinPage = data.m_printMinPage; | |
528 | m_printMaxPage = data.m_printMaxPage; | |
529 | m_printNoCopies = data.m_printNoCopies; | |
530 | m_printAllPages = data.m_printAllPages; | |
531 | m_printCollate = data.m_printCollate; | |
532 | m_printToFile = data.m_printToFile; | |
5360828d | 533 | m_printSelection = data.m_printSelection; |
7bcb11d3 JS |
534 | m_printEnableSelection = data.m_printEnableSelection; |
535 | m_printEnablePageNumbers = data.m_printEnablePageNumbers; | |
536 | m_printEnableHelp = data.m_printEnableHelp; | |
537 | m_printEnablePrintToFile = data.m_printEnablePrintToFile; | |
538 | m_printSetupDialog = data.m_printSetupDialog; | |
539 | ||
540 | m_printData = data.m_printData; | |
541 | } | |
542 | ||
543 | void wxPrintDialogData::operator=(const wxPrintData& data) | |
544 | { | |
545 | m_printData = data; | |
c801d85f KB |
546 | } |
547 | ||
8826f46f VZ |
548 | // ---------------------------------------------------------------------------- |
549 | // wxPageSetupDialogData | |
550 | // ---------------------------------------------------------------------------- | |
c801d85f | 551 | |
7bcb11d3 | 552 | wxPageSetupDialogData::wxPageSetupDialogData() |
c801d85f KB |
553 | { |
554 | #if defined(__WIN95__) | |
7bcb11d3 | 555 | m_pageSetupData = NULL; |
c801d85f | 556 | #endif |
7bcb11d3 JS |
557 | m_paperSize = wxSize(0, 0); |
558 | ||
559 | CalculatePaperSizeFromId(); | |
560 | ||
561 | m_minMarginTopLeft = wxPoint(0, 0); | |
562 | m_minMarginBottomRight = wxPoint(0, 0); | |
563 | m_marginTopLeft = wxPoint(0, 0); | |
564 | m_marginBottomRight = wxPoint(0, 0); | |
565 | ||
566 | // Flags | |
c9d59ee7 WS |
567 | m_defaultMinMargins = false; |
568 | m_enableMargins = true; | |
569 | m_enableOrientation = true; | |
570 | m_enablePaper = true; | |
571 | m_enablePrinter = true; | |
572 | m_enableHelp = false; | |
573 | m_getDefaultInfo = false; | |
7bcb11d3 | 574 | } |
c801d85f | 575 | |
7bcb11d3 | 576 | wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData) |
5e472c1f | 577 | : wxObject() |
7bcb11d3 | 578 | { |
7c74e7fe SC |
579 | #if defined(__WIN95__) |
580 | m_pageSetupData = NULL; | |
7c74e7fe | 581 | #endif |
7bcb11d3 JS |
582 | (*this) = dialogData; |
583 | } | |
584 | ||
585 | wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData) | |
586 | { | |
587 | #if defined(__WIN95__) | |
588 | m_pageSetupData = NULL; | |
589 | #endif | |
590 | m_paperSize = wxSize(0, 0); | |
591 | m_minMarginTopLeft = wxPoint(0, 0); | |
592 | m_minMarginBottomRight = wxPoint(0, 0); | |
593 | m_marginTopLeft = wxPoint(0, 0); | |
594 | m_marginBottomRight = wxPoint(0, 0); | |
595 | ||
596 | // Flags | |
c9d59ee7 WS |
597 | m_defaultMinMargins = false; |
598 | m_enableMargins = true; | |
599 | m_enableOrientation = true; | |
600 | m_enablePaper = true; | |
601 | m_enablePrinter = true; | |
602 | m_enableHelp = false; | |
603 | m_getDefaultInfo = false; | |
7bcb11d3 JS |
604 | |
605 | m_printData = printData; | |
606 | ||
607 | // The wxPrintData paper size overrides these values, unless the size cannot | |
608 | // be found. | |
609 | CalculatePaperSizeFromId(); | |
c801d85f KB |
610 | } |
611 | ||
7bcb11d3 | 612 | wxPageSetupDialogData::~wxPageSetupDialogData() |
c801d85f | 613 | { |
34138703 | 614 | #if defined(__WIN95__) && defined(__WXMSW__) |
c801d85f KB |
615 | PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData; |
616 | if ( pd && pd->hDevMode ) | |
617 | GlobalFree(pd->hDevMode); | |
eaeb6a3c JS |
618 | if ( pd && pd->hDevNames ) |
619 | GlobalFree(pd->hDevNames); | |
c801d85f KB |
620 | if ( pd ) |
621 | delete pd; | |
622 | #endif | |
623 | } | |
624 | ||
5e472c1f | 625 | wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data) |
c801d85f | 626 | { |
7bcb11d3 JS |
627 | m_paperSize = data.m_paperSize; |
628 | m_minMarginTopLeft = data.m_minMarginTopLeft; | |
629 | m_minMarginBottomRight = data.m_minMarginBottomRight; | |
630 | m_marginTopLeft = data.m_marginTopLeft; | |
631 | m_marginBottomRight = data.m_marginBottomRight; | |
632 | m_defaultMinMargins = data.m_defaultMinMargins; | |
633 | m_enableMargins = data.m_enableMargins; | |
634 | m_enableOrientation = data.m_enableOrientation; | |
635 | m_enablePaper = data.m_enablePaper; | |
636 | m_enablePrinter = data.m_enablePrinter; | |
637 | m_getDefaultInfo = data.m_getDefaultInfo;; | |
638 | m_enableHelp = data.m_enableHelp; | |
639 | ||
640 | m_printData = data.m_printData; | |
5e472c1f GD |
641 | |
642 | return *this; | |
7bcb11d3 | 643 | } |
c801d85f | 644 | |
5e472c1f | 645 | wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data) |
7bcb11d3 JS |
646 | { |
647 | m_printData = data; | |
5e472c1f GD |
648 | |
649 | return *this; | |
c801d85f KB |
650 | } |
651 | ||
8826f46f | 652 | #if defined(__WIN95__) |
7bcb11d3 | 653 | void wxPageSetupDialogData::ConvertToNative() |
c801d85f | 654 | { |
8850cbd3 RR |
655 | wxWindowsPrintNativeData *data = |
656 | (wxWindowsPrintNativeData *) m_printData.GetNativeData(); | |
fd64de59 | 657 | data->TransferFrom( m_printData ); |
7bcb11d3 | 658 | |
c801d85f | 659 | PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData; |
7bcb11d3 | 660 | |
c801d85f KB |
661 | if ( m_pageSetupData == NULL ) |
662 | { | |
7bcb11d3 JS |
663 | pd = new PAGESETUPDLG; |
664 | pd->hDevMode = NULL; | |
eaeb6a3c | 665 | pd->hDevNames = NULL; |
7bcb11d3 | 666 | m_pageSetupData = (void *)pd; |
c801d85f | 667 | } |
8bbe427f | 668 | |
7bcb11d3 JS |
669 | // Pass the devmode data (created in m_printData.ConvertToNative) |
670 | // to the PRINTDLG structure, since it'll | |
671 | // be needed when PrintDlg is called. | |
672 | ||
673 | if (pd->hDevMode) | |
674 | { | |
675 | GlobalFree(pd->hDevMode); | |
676 | pd->hDevMode = NULL; | |
677 | } | |
678 | ||
fd64de59 | 679 | pd->hDevMode = (HGLOBAL) data->GetDevMode(); |
7bcb11d3 | 680 | |
fd64de59 | 681 | data->SetDevMode( (void*) NULL ); |
7bcb11d3 | 682 | |
58cf0491 JS |
683 | // Shouldn't assert; we should be able to test Ok-ness at a higher level |
684 | //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); | |
7bcb11d3 | 685 | |
eaeb6a3c JS |
686 | // Pass the devnames data (created in m_printData.ConvertToNative) |
687 | // to the PRINTDLG structure, since it'll | |
688 | // be needed when PrintDlg is called. | |
689 | ||
690 | if (pd->hDevNames) | |
691 | { | |
692 | GlobalFree(pd->hDevNames); | |
693 | pd->hDevNames = NULL; | |
694 | } | |
695 | ||
fd64de59 | 696 | pd->hDevNames = (HGLOBAL) data->GetDevNames(); |
eaeb6a3c | 697 | |
fd64de59 | 698 | data->SetDevNames((void*) NULL); |
eaeb6a3c | 699 | |
7bcb11d3 | 700 | // pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE)); |
c801d85f | 701 | |
7bcb11d3 | 702 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; |
8826f46f | 703 | |
c801d85f KB |
704 | if ( m_defaultMinMargins ) |
705 | pd->Flags |= PSD_DEFAULTMINMARGINS; | |
706 | if ( !m_enableMargins ) | |
707 | pd->Flags |= PSD_DISABLEMARGINS; | |
708 | if ( !m_enableOrientation ) | |
709 | pd->Flags |= PSD_DISABLEORIENTATION; | |
710 | if ( !m_enablePaper ) | |
711 | pd->Flags |= PSD_DISABLEPAPER; | |
712 | if ( !m_enablePrinter ) | |
713 | pd->Flags |= PSD_DISABLEPRINTER; | |
714 | if ( m_getDefaultInfo ) | |
715 | pd->Flags |= PSD_RETURNDEFAULT; | |
716 | if ( m_enableHelp ) | |
717 | pd->Flags |= PSD_SHOWHELP; | |
718 | ||
7bcb11d3 JS |
719 | // We want the units to be in hundredths of a millimetre |
720 | pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS; | |
721 | ||
c801d85f | 722 | pd->lStructSize = sizeof( PAGESETUPDLG ); |
c4e7c2aa | 723 | pd->hwndOwner=(HWND)NULL; |
eaeb6a3c | 724 | // pd->hDevNames=(HWND)NULL; |
c801d85f | 725 | pd->hInstance=(HINSTANCE)NULL; |
161f4f73 | 726 | // PAGESETUPDLG is in hundreds of a mm |
7bcb11d3 JS |
727 | pd->ptPaperSize.x = m_paperSize.x * 100; |
728 | pd->ptPaperSize.y = m_paperSize.y * 100; | |
8826f46f | 729 | |
7bcb11d3 JS |
730 | pd->rtMinMargin.left = m_minMarginTopLeft.x * 100; |
731 | pd->rtMinMargin.top = m_minMarginTopLeft.y * 100; | |
732 | pd->rtMinMargin.right = m_minMarginBottomRight.x * 100; | |
733 | pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100; | |
8826f46f | 734 | |
7bcb11d3 JS |
735 | pd->rtMargin.left = m_marginTopLeft.x * 100; |
736 | pd->rtMargin.top = m_marginTopLeft.y * 100; | |
737 | pd->rtMargin.right = m_marginBottomRight.x * 100; | |
738 | pd->rtMargin.bottom = m_marginBottomRight.y * 100; | |
8826f46f | 739 | |
c801d85f KB |
740 | pd->lCustData = 0; |
741 | pd->lpfnPageSetupHook = NULL; | |
742 | pd->lpfnPagePaintHook = NULL; | |
743 | pd->hPageSetupTemplate = NULL; | |
744 | pd->lpPageSetupTemplateName = NULL; | |
745 | ||
8826f46f | 746 | /* |
c801d85f KB |
747 | if ( pd->hDevMode ) |
748 | { | |
749 | DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode); | |
750 | memset(devMode, 0, sizeof(DEVMODE)); | |
751 | devMode->dmSize = sizeof(DEVMODE); | |
752 | devMode->dmOrientation = m_orientation; | |
753 | devMode->dmFields = DM_ORIENTATION; | |
754 | GlobalUnlock(pd->hDevMode); | |
755 | } | |
7bcb11d3 | 756 | */ |
c801d85f KB |
757 | } |
758 | ||
7bcb11d3 | 759 | void wxPageSetupDialogData::ConvertFromNative() |
c801d85f | 760 | { |
161f4f73 | 761 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData; |
c801d85f KB |
762 | if ( !pd ) |
763 | return; | |
8826f46f | 764 | |
8850cbd3 RR |
765 | wxWindowsPrintNativeData *data = |
766 | (wxWindowsPrintNativeData *) m_printData.GetNativeData(); | |
767 | ||
7bcb11d3 JS |
768 | // Pass the devmode data back to the wxPrintData structure where it really belongs. |
769 | if (pd->hDevMode) | |
770 | { | |
fd64de59 | 771 | if (data->GetDevMode()) |
7bcb11d3 JS |
772 | { |
773 | // Make sure we don't leak memory | |
fd64de59 | 774 | GlobalFree((HGLOBAL) data->GetDevMode()); |
7bcb11d3 | 775 | } |
fd64de59 | 776 | data->SetDevMode( (void*) pd->hDevMode ); |
7bcb11d3 JS |
777 | pd->hDevMode = NULL; |
778 | } | |
c801d85f | 779 | |
fd64de59 | 780 | data->TransferTo( m_printData ); |
c801d85f | 781 | |
eaeb6a3c JS |
782 | // Pass the devnames data back to the wxPrintData structure where it really belongs. |
783 | if (pd->hDevNames) | |
784 | { | |
fd64de59 | 785 | if (data->GetDevNames()) |
eaeb6a3c JS |
786 | { |
787 | // Make sure we don't leak memory | |
fd64de59 | 788 | GlobalFree((HGLOBAL) data->GetDevNames()); |
eaeb6a3c | 789 | } |
fd64de59 | 790 | data->SetDevNames((void*) pd->hDevNames); |
eaeb6a3c JS |
791 | pd->hDevNames = NULL; |
792 | } | |
793 | ||
fd64de59 | 794 | data->TransferTo( m_printData ); |
eaeb6a3c | 795 | |
7bcb11d3 | 796 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; |
8826f46f | 797 | |
c801d85f KB |
798 | m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS); |
799 | m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS); | |
800 | m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION); | |
801 | m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER); | |
802 | m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER); | |
803 | m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT); | |
804 | m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP); | |
8826f46f | 805 | |
161f4f73 | 806 | // PAGESETUPDLG is in hundreds of a mm |
7bcb11d3 JS |
807 | m_paperSize.x = pd->ptPaperSize.x / 100; |
808 | m_paperSize.y = pd->ptPaperSize.y / 100; | |
8826f46f | 809 | |
7bcb11d3 JS |
810 | m_minMarginTopLeft.x = pd->rtMinMargin.left / 100; |
811 | m_minMarginTopLeft.y = pd->rtMinMargin.top / 100; | |
812 | m_minMarginBottomRight.x = pd->rtMinMargin.right / 100; | |
813 | m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100; | |
8826f46f | 814 | |
161f4f73 VZ |
815 | m_marginTopLeft.x = pd->rtMargin.left / 100; |
816 | m_marginTopLeft.y = pd->rtMargin.top / 100; | |
817 | m_marginBottomRight.x = pd->rtMargin.right / 100; | |
818 | m_marginBottomRight.y = pd->rtMargin.bottom / 100; | |
7bcb11d3 | 819 | } |
c801d85f | 820 | |
7bcb11d3 JS |
821 | void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win) |
822 | { | |
823 | if ( m_pageSetupData == NULL ) | |
824 | ConvertToNative(); | |
8826f46f | 825 | |
7bcb11d3 JS |
826 | if ( m_pageSetupData != NULL && win != NULL) |
827 | { | |
161f4f73 | 828 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData; |
7bcb11d3 JS |
829 | pd->hwndOwner=(HWND) win->GetHWND(); |
830 | } | |
831 | } | |
8826f46f | 832 | #endif // Win95 |
c801d85f | 833 | |
51abe921 | 834 | #ifdef __WXMAC__ |
7c74e7fe | 835 | void wxPageSetupDialogData::ConvertToNative() |
51abe921 | 836 | { |
161f4f73 | 837 | m_printData.ConvertToNative(); |
746d7582 | 838 | m_printData.m_nativePrintData->TransferFrom( this ) ; |
51abe921 SC |
839 | } |
840 | ||
7c74e7fe | 841 | void wxPageSetupDialogData::ConvertFromNative() |
51abe921 | 842 | { |
161f4f73 | 843 | m_printData.ConvertFromNative (); |
cfb00da4 SC |
844 | m_paperSize = m_printData.GetPaperSize() ; |
845 | CalculateIdFromPaperSize(); | |
746d7582 | 846 | m_printData.m_nativePrintData->TransferTo( this ) ; |
161f4f73 | 847 | // adjust minimal values |
161f4f73 VZ |
848 | |
849 | if ( m_marginTopLeft.x < m_minMarginTopLeft.x ) | |
850 | m_marginTopLeft.x = m_minMarginTopLeft.x; | |
851 | ||
852 | if ( m_marginBottomRight.x < m_minMarginBottomRight.x ) | |
853 | m_marginBottomRight.x = m_minMarginBottomRight.x; | |
854 | ||
855 | if ( m_marginTopLeft.y < m_minMarginTopLeft.y ) | |
856 | m_marginTopLeft.y = m_minMarginTopLeft.y; | |
857 | ||
858 | if ( m_marginBottomRight.y < m_minMarginBottomRight.y ) | |
859 | m_marginBottomRight.y = m_minMarginBottomRight.y; | |
51abe921 SC |
860 | } |
861 | #endif | |
862 | ||
863 | ||
7bcb11d3 JS |
864 | // If a corresponding paper type is found in the paper database, will set the m_printData |
865 | // paper size id member as well. | |
866 | void wxPageSetupDialogData::SetPaperSize(const wxSize& sz) | |
867 | { | |
868 | m_paperSize = sz; | |
c801d85f | 869 | |
7bcb11d3 JS |
870 | CalculateIdFromPaperSize(); |
871 | } | |
c801d85f | 872 | |
7bcb11d3 JS |
873 | // Sets the wxPrintData id, plus the paper width/height if found in the paper database. |
874 | void wxPageSetupDialogData::SetPaperSize(wxPaperSize id) | |
875 | { | |
876 | m_printData.SetPaperId(id); | |
877 | ||
878 | CalculatePaperSizeFromId(); | |
c801d85f KB |
879 | } |
880 | ||
7bcb11d3 JS |
881 | // Use paper size defined in this object to set the wxPrintData |
882 | // paper id | |
883 | void wxPageSetupDialogData::CalculateIdFromPaperSize() | |
c801d85f | 884 | { |
8826f46f | 885 | wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL), |
fbdcff4a | 886 | wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") ); |
c801d85f | 887 | |
7bcb11d3 JS |
888 | wxSize sz = GetPaperSize(); |
889 | ||
890 | wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10)); | |
891 | if (id != wxPAPER_NONE) | |
c801d85f | 892 | { |
7bcb11d3 | 893 | m_printData.SetPaperId(id); |
c801d85f KB |
894 | } |
895 | } | |
8826f46f | 896 | |
7bcb11d3 JS |
897 | // Use paper id in wxPrintData to set this object's paper size |
898 | void wxPageSetupDialogData::CalculatePaperSizeFromId() | |
899 | { | |
8826f46f | 900 | wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL), |
fbdcff4a | 901 | wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") ); |
7bcb11d3 JS |
902 | |
903 | wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId()); | |
c801d85f | 904 | |
01cf2f95 VZ |
905 | // sz is in 10ths of a mm, while paper size is in mm |
906 | m_paperSize.x = sz.x / 10; | |
907 | m_paperSize.y = sz.y / 10; | |
7bcb11d3 | 908 | } |
8826f46f | 909 | |
88ac883a | 910 | #endif // wxUSE_PRINTING_ARCHITECTURE |