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