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