]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: cmndata.cpp | |
3 | // Purpose: Common GDI data | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
8bbe427f | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "cmndata.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include <stdio.h> | |
34138703 | 25 | #include "wx/string.h" |
c801d85f KB |
26 | #include "wx/utils.h" |
27 | #include "wx/app.h" | |
28 | #endif | |
29 | ||
30 | #include "wx/gdicmn.h" | |
31 | #include "wx/cmndata.h" | |
32 | ||
2049ba38 | 33 | #ifdef __WXMSW__ |
c801d85f KB |
34 | #include <windows.h> |
35 | ||
7be1f0d9 | 36 | #if !defined(__WIN32__) |
c801d85f KB |
37 | #include <print.h> |
38 | #include <commdlg.h> | |
39 | #endif | |
7be1f0d9 JS |
40 | |
41 | #if defined(__WATCOMC__) | |
42 | #include <commdlg.h> | |
43 | #endif | |
44 | ||
c801d85f KB |
45 | #endif |
46 | ||
47 | #if !USE_SHARED_LIBRARY | |
48 | IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject) | |
49 | IMPLEMENT_DYNAMIC_CLASS(wxPageSetupData, wxObject) | |
50 | IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject) | |
51 | IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject) | |
52 | #endif | |
53 | ||
54 | /* | |
55 | * wxColourData | |
56 | */ | |
57 | ||
8bbe427f | 58 | wxColourData::wxColourData() |
c801d85f KB |
59 | { |
60 | int i; | |
61 | for (i = 0; i < 16; i++) | |
62 | custColours[i].Set(255, 255, 255); | |
63 | ||
64 | chooseFull = FALSE; | |
65 | dataColour.Set(0,0,0); | |
8bbe427f | 66 | } |
c801d85f | 67 | |
8bbe427f | 68 | wxColourData::~wxColourData() |
c801d85f KB |
69 | { |
70 | } | |
71 | ||
72 | void wxColourData::SetCustomColour(int i, wxColour& colour) | |
73 | { | |
74 | if (i > 15 || i < 0) | |
75 | return; | |
76 | ||
77 | custColours[i] = colour; | |
78 | } | |
79 | ||
80 | wxColour wxColourData::GetCustomColour(int i) | |
81 | { | |
82 | if (i > 15 || i < 0) | |
83 | return wxColour(0,0,0); | |
84 | ||
85 | return custColours[i]; | |
86 | } | |
87 | ||
88 | void wxColourData::operator=(const wxColourData& data) | |
89 | { | |
90 | int i; | |
91 | for (i = 0; i < 16; i++) | |
92 | custColours[i] = data.custColours[i]; | |
93 | ||
94 | dataColour = (wxColour&)data.dataColour; | |
95 | chooseFull = data.chooseFull; | |
96 | } | |
97 | ||
98 | /* | |
99 | * Font data | |
100 | */ | |
101 | ||
8bbe427f | 102 | wxFontData::wxFontData() |
c801d85f KB |
103 | { |
104 | // Intialize colour to black. | |
105 | fontColour.Set(0, 0, 0); | |
106 | ||
107 | showHelp = FALSE; | |
108 | allowSymbols = TRUE; | |
109 | enableEffects = TRUE; | |
110 | minSize = 0; | |
111 | maxSize = 0; | |
112 | } | |
113 | ||
8bbe427f | 114 | wxFontData::~wxFontData() |
c801d85f KB |
115 | { |
116 | } | |
117 | ||
118 | void wxFontData::operator=(const wxFontData& data) | |
119 | { | |
120 | fontColour = data.fontColour; | |
121 | showHelp = data.showHelp; | |
122 | allowSymbols = data.allowSymbols; | |
123 | enableEffects = data.enableEffects; | |
124 | initialFont = data.initialFont; | |
125 | chosenFont = data.chosenFont; | |
126 | minSize = data.minSize; | |
127 | maxSize = data.maxSize; | |
128 | } | |
129 | ||
130 | /* | |
131 | * Print data | |
132 | */ | |
133 | ||
8bbe427f | 134 | wxPrintData::wxPrintData() |
c801d85f | 135 | { |
2049ba38 | 136 | #ifdef __WXMSW__ |
c801d85f KB |
137 | printData = NULL; |
138 | #endif | |
139 | printOrientation = wxPORTRAIT; | |
140 | printFromPage = 0; | |
141 | printToPage = 0; | |
142 | printMinPage = 0; | |
143 | printMaxPage = 0; | |
144 | printNoCopies = 1; | |
145 | printAllPages = FALSE; | |
146 | printCollate = FALSE; | |
147 | printToFile = FALSE; | |
148 | printEnableSelection = FALSE; | |
149 | printEnablePageNumbers = TRUE; | |
150 | printEnablePrintToFile = TRUE; | |
151 | printEnableHelp = FALSE; | |
152 | printSetupDialog = FALSE; | |
153 | } | |
154 | ||
8bbe427f | 155 | wxPrintData::~wxPrintData() |
c801d85f | 156 | { |
2049ba38 | 157 | #ifdef __WXMSW__ |
c801d85f KB |
158 | PRINTDLG *pd = (PRINTDLG *)printData; |
159 | if ( pd && pd->hDevMode ) | |
160 | GlobalFree(pd->hDevMode); | |
161 | if ( pd ) | |
162 | delete pd; | |
163 | #endif | |
164 | } | |
165 | ||
2049ba38 | 166 | #ifdef __WXMSW__ |
8bbe427f | 167 | void wxPrintData::ConvertToNative() |
c801d85f KB |
168 | { |
169 | PRINTDLG *pd = (PRINTDLG*) printData; | |
170 | if ( pd == NULL ) | |
171 | { | |
172 | pd = new PRINTDLG; | |
173 | printData = (void*) pd; | |
174 | ||
175 | // GNU-WIN32 has the wrong size PRINTDLG - can't work out why. | |
176 | // pd->lStructSize = sizeof(PRINTDLG); | |
177 | pd->lStructSize = 66 ; | |
178 | pd->hwndOwner = (HWND)NULL; | |
179 | pd->hDevMode = NULL; // Will be created by PrintDlg | |
180 | pd->hDevNames = NULL; // Ditto | |
181 | ||
c801d85f KB |
182 | pd->Flags = PD_RETURNDEFAULT; |
183 | pd->nCopies = 1; | |
184 | ||
185 | // Fill out the DEVMODE structure | |
186 | // so we can use it as input in the 'real' PrintDlg | |
187 | if (!PrintDlg(pd)) | |
188 | { | |
189 | if ( pd->hDevMode ) | |
190 | GlobalFree(pd->hDevMode); | |
191 | if ( pd->hDevNames ) | |
192 | GlobalFree(pd->hDevNames); | |
193 | pd->hDevMode = NULL; | |
194 | pd->hDevNames = NULL; | |
195 | } | |
196 | else | |
197 | { | |
198 | if ( pd->hDevNames ) | |
199 | GlobalFree(pd->hDevNames); | |
200 | pd->hDevNames = NULL; | |
201 | } | |
c801d85f KB |
202 | } |
203 | ||
204 | if ( pd->hDevMode ) | |
205 | { | |
206 | DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode); | |
207 | devMode->dmOrientation = printOrientation; | |
208 | devMode->dmFields = DM_ORIENTATION; | |
209 | GlobalUnlock(pd->hDevMode); | |
210 | } | |
211 | pd->hDC = (HDC) NULL; | |
212 | pd->nFromPage = (UINT)printFromPage; | |
213 | pd->nToPage = (UINT)printToPage; | |
214 | pd->nMinPage = (UINT)printMinPage; | |
215 | pd->nMaxPage = (UINT)printMaxPage; | |
216 | pd->nCopies = (UINT)printNoCopies; | |
217 | ||
218 | pd->Flags = PD_RETURNDC ; | |
219 | // pd->lStructSize = sizeof( PRINTDLG ); | |
220 | pd->lStructSize = 66 ; | |
8b9518ee | 221 | pd->hwndOwner=(HWND)NULL; |
c801d85f KB |
222 | pd->hDevNames=(HANDLE)NULL; |
223 | pd->hInstance=(HINSTANCE)NULL; | |
224 | pd->lCustData = (LPARAM) NULL; | |
225 | pd->lpfnPrintHook = NULL; | |
226 | pd->lpfnSetupHook = NULL; | |
227 | pd->lpPrintTemplateName = NULL; | |
228 | pd->lpSetupTemplateName = NULL; | |
229 | pd->hPrintTemplate = (HGLOBAL) NULL; | |
230 | pd->hSetupTemplate = (HGLOBAL) NULL; | |
231 | ||
232 | if ( printAllPages ) | |
233 | pd->Flags |= PD_ALLPAGES; | |
234 | if ( printCollate ) | |
235 | pd->Flags |= PD_COLLATE; | |
236 | if ( printToFile ) | |
237 | pd->Flags |= PD_PRINTTOFILE; | |
238 | if ( !printEnablePrintToFile ) | |
239 | pd->Flags |= PD_DISABLEPRINTTOFILE; | |
240 | if ( !printEnableSelection ) | |
241 | pd->Flags |= PD_NOSELECTION; | |
242 | if ( !printEnablePageNumbers ) | |
243 | pd->Flags |= PD_NOPAGENUMS; | |
244 | if ( printEnableHelp ) | |
245 | pd->Flags |= PD_SHOWHELP; | |
246 | if ( printSetupDialog ) | |
247 | pd->Flags |= PD_PRINTSETUP; | |
248 | } | |
249 | ||
8bbe427f | 250 | void wxPrintData::ConvertFromNative() |
c801d85f KB |
251 | { |
252 | PRINTDLG *pd = (PRINTDLG*) printData; | |
253 | if ( pd == NULL ) | |
254 | return; | |
255 | ||
256 | if ( pd->hDevMode ) | |
257 | { | |
258 | DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode); | |
259 | printOrientation = devMode->dmOrientation; | |
260 | GlobalUnlock(pd->hDevMode); | |
261 | } | |
262 | printFromPage = pd->nFromPage ; | |
263 | printToPage = pd->nToPage ; | |
264 | printMinPage = pd->nMinPage ; | |
265 | printMaxPage = pd->nMaxPage ; | |
266 | printNoCopies = pd->nCopies ; | |
267 | ||
268 | printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES); | |
269 | printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE); | |
270 | printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE); | |
271 | printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE); | |
272 | printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION); | |
273 | printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS); | |
274 | printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP); | |
275 | printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP); | |
276 | } | |
277 | ||
278 | void wxPrintData::SetOwnerWindow(wxWindow* win) | |
279 | { | |
280 | if ( printData == NULL ) | |
281 | ConvertToNative(); | |
282 | ||
283 | if ( printData != NULL && win != NULL) | |
284 | { | |
285 | PRINTDLG *pd = (PRINTDLG *) printData ; | |
286 | pd->hwndOwner=(HWND) win->GetHWND(); | |
287 | } | |
288 | } | |
289 | #endif | |
290 | ||
291 | void wxPrintData::operator=(const wxPrintData& data) | |
292 | { | |
293 | printFromPage = data.printFromPage; | |
294 | printToPage = data.printToPage; | |
295 | printMinPage = data.printMinPage; | |
296 | printMaxPage = data.printMaxPage; | |
297 | printNoCopies = data.printNoCopies; | |
298 | printAllPages = data.printAllPages; | |
299 | printCollate = data.printCollate; | |
300 | printToFile = data.printToFile; | |
301 | printEnableSelection = data.printEnableSelection; | |
302 | printEnablePageNumbers = data.printEnablePageNumbers; | |
303 | printEnableHelp = data.printEnableHelp; | |
304 | printEnablePrintToFile = data.printEnablePrintToFile; | |
305 | printSetupDialog = data.printSetupDialog; | |
306 | printOrientation = data.printOrientation; | |
307 | } | |
308 | ||
309 | /* | |
310 | * wxPageSetupData | |
311 | */ | |
312 | ||
8bbe427f | 313 | wxPageSetupData::wxPageSetupData() |
c801d85f KB |
314 | { |
315 | #if defined(__WIN95__) | |
316 | m_pageSetupData = NULL; | |
317 | #endif | |
318 | m_paperSize = wxPoint(0, 0); | |
319 | m_minMarginTopLeft = wxPoint(0, 0); | |
320 | m_minMarginBottomRight = wxPoint(0, 0); | |
321 | m_marginTopLeft = wxPoint(0, 0); | |
322 | m_marginBottomRight = wxPoint(0, 0); | |
323 | m_orientation = wxPORTRAIT; | |
324 | ||
325 | // Flags | |
326 | m_defaultMinMargins = FALSE; | |
327 | m_enableMargins = TRUE; | |
328 | m_enableOrientation = TRUE; | |
329 | m_enablePaper = TRUE; | |
330 | m_enablePrinter = TRUE; | |
331 | m_enableHelp = FALSE; | |
332 | m_getDefaultInfo = FALSE; | |
333 | } | |
334 | ||
8bbe427f | 335 | wxPageSetupData::~wxPageSetupData() |
c801d85f | 336 | { |
34138703 | 337 | #if defined(__WIN95__) && defined(__WXMSW__) |
c801d85f KB |
338 | PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData; |
339 | if ( pd && pd->hDevMode ) | |
340 | GlobalFree(pd->hDevMode); | |
341 | if ( pd ) | |
342 | delete pd; | |
343 | #endif | |
344 | } | |
345 | ||
346 | void wxPageSetupData::operator=(const wxPageSetupData& data) | |
347 | { | |
348 | m_paperSize = data.m_paperSize; | |
349 | m_minMarginTopLeft = data.m_minMarginTopLeft; | |
350 | m_minMarginBottomRight = data.m_minMarginBottomRight; | |
351 | m_marginTopLeft = data.m_marginTopLeft; | |
352 | m_marginBottomRight = data.m_marginBottomRight; | |
353 | m_orientation = data.m_orientation; | |
354 | ||
355 | m_defaultMinMargins = data.m_defaultMinMargins; | |
356 | m_enableMargins = data.m_enableMargins; | |
357 | m_enableOrientation = data.m_enableOrientation; | |
358 | m_enablePaper = data.m_enablePaper; | |
359 | m_enablePrinter = data.m_enablePrinter; | |
360 | m_getDefaultInfo = data.m_getDefaultInfo;; | |
361 | m_enableHelp = data.m_enableHelp; | |
362 | } | |
363 | ||
34138703 | 364 | #if defined(__WXMSW__) && defined(__WIN95__) |
8bbe427f | 365 | void wxPageSetupData::ConvertToNative() |
c801d85f KB |
366 | { |
367 | PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData; | |
368 | if ( m_pageSetupData == NULL ) | |
369 | { | |
370 | pd = new PAGESETUPDLG; | |
371 | pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE)); | |
372 | m_pageSetupData = (void *)pd; | |
373 | } | |
8bbe427f | 374 | |
c801d85f KB |
375 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; |
376 | ||
377 | if ( m_defaultMinMargins ) | |
378 | pd->Flags |= PSD_DEFAULTMINMARGINS; | |
379 | if ( !m_enableMargins ) | |
380 | pd->Flags |= PSD_DISABLEMARGINS; | |
381 | if ( !m_enableOrientation ) | |
382 | pd->Flags |= PSD_DISABLEORIENTATION; | |
383 | if ( !m_enablePaper ) | |
384 | pd->Flags |= PSD_DISABLEPAPER; | |
385 | if ( !m_enablePrinter ) | |
386 | pd->Flags |= PSD_DISABLEPRINTER; | |
387 | if ( m_getDefaultInfo ) | |
388 | pd->Flags |= PSD_RETURNDEFAULT; | |
389 | if ( m_enableHelp ) | |
390 | pd->Flags |= PSD_SHOWHELP; | |
391 | ||
392 | pd->lStructSize = sizeof( PAGESETUPDLG ); | |
c4e7c2aa | 393 | pd->hwndOwner=(HWND)NULL; |
c801d85f KB |
394 | pd->hDevNames=(HWND)NULL; |
395 | pd->hInstance=(HINSTANCE)NULL; | |
396 | ||
397 | pd->ptPaperSize.x = m_paperSize.x; | |
398 | pd->ptPaperSize.y = m_paperSize.y; | |
399 | ||
400 | pd->rtMinMargin.left = m_minMarginTopLeft.x; | |
401 | pd->rtMinMargin.top = m_minMarginTopLeft.y; | |
402 | pd->rtMinMargin.right = m_minMarginBottomRight.x; | |
403 | pd->rtMinMargin.bottom = m_minMarginBottomRight.y; | |
404 | ||
405 | pd->rtMargin.left = m_marginTopLeft.x; | |
406 | pd->rtMargin.top = m_marginTopLeft.y; | |
407 | pd->rtMargin.right = m_marginBottomRight.x; | |
408 | pd->rtMargin.bottom = m_marginBottomRight.y; | |
409 | ||
410 | pd->lCustData = 0; | |
411 | pd->lpfnPageSetupHook = NULL; | |
412 | pd->lpfnPagePaintHook = NULL; | |
413 | pd->hPageSetupTemplate = NULL; | |
414 | pd->lpPageSetupTemplateName = NULL; | |
415 | ||
416 | if ( pd->hDevMode ) | |
417 | { | |
418 | DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode); | |
419 | memset(devMode, 0, sizeof(DEVMODE)); | |
420 | devMode->dmSize = sizeof(DEVMODE); | |
421 | devMode->dmOrientation = m_orientation; | |
422 | devMode->dmFields = DM_ORIENTATION; | |
423 | GlobalUnlock(pd->hDevMode); | |
424 | } | |
425 | } | |
426 | ||
8bbe427f | 427 | void wxPageSetupData::ConvertFromNative() |
c801d85f KB |
428 | { |
429 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ; | |
430 | if ( !pd ) | |
431 | return; | |
432 | ||
433 | pd->Flags = PSD_MARGINS|PSD_MINMARGINS; | |
434 | ||
435 | m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS); | |
436 | m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS); | |
437 | m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION); | |
438 | m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER); | |
439 | m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER); | |
440 | m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT); | |
441 | m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP); | |
442 | ||
443 | m_paperSize.x = pd->ptPaperSize.x ; | |
444 | m_paperSize.y = pd->ptPaperSize.y ; | |
445 | ||
446 | m_minMarginTopLeft.x = pd->rtMinMargin.left ; | |
447 | m_minMarginTopLeft.y = pd->rtMinMargin.top ; | |
448 | m_minMarginBottomRight.x = pd->rtMinMargin.right ; | |
449 | m_minMarginBottomRight.y = pd->rtMinMargin.bottom ; | |
450 | ||
451 | m_marginTopLeft.x = pd->rtMargin.left ; | |
452 | m_marginTopLeft.y = pd->rtMargin.top ; | |
453 | m_marginBottomRight.x = pd->rtMargin.right ; | |
454 | m_marginBottomRight.y = pd->rtMargin.bottom ; | |
455 | ||
456 | if ( pd->hDevMode ) | |
457 | { | |
458 | DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode); | |
459 | m_orientation = devMode->dmOrientation ; | |
460 | GlobalUnlock(pd->hDevMode); | |
461 | } | |
462 | } | |
463 | ||
464 | void wxPageSetupData::SetOwnerWindow(wxWindow* win) | |
465 | { | |
466 | if ( m_pageSetupData == NULL ) | |
467 | ConvertToNative(); | |
468 | ||
469 | if ( m_pageSetupData != NULL && win != NULL) | |
470 | { | |
471 | PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ; | |
472 | pd->hwndOwner=(HWND) win->GetHWND(); | |
473 | } | |
474 | } | |
475 | #endif | |
476 |