]> git.saurik.com Git - wxWidgets.git/blame - src/common/cmndata.cpp
Solved a bug in generic wxTreeCtrl whereby CalculatePositions was not completing
[wxWidgets.git] / src / common / cmndata.cpp
CommitLineData
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
36#ifndef __WIN32__
37#include <print.h>
38#include <commdlg.h>
39#endif
40#endif
41
42#if !USE_SHARED_LIBRARY
43IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
44IMPLEMENT_DYNAMIC_CLASS(wxPageSetupData, wxObject)
45IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
46IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
47#endif
48
49/*
50 * wxColourData
51 */
52
8bbe427f 53wxColourData::wxColourData()
c801d85f
KB
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);
8bbe427f 61}
c801d85f 62
8bbe427f 63wxColourData::~wxColourData()
c801d85f
KB
64{
65}
66
67void wxColourData::SetCustomColour(int i, wxColour& colour)
68{
69 if (i > 15 || i < 0)
70 return;
71
72 custColours[i] = colour;
73}
74
75wxColour wxColourData::GetCustomColour(int i)
76{
77 if (i > 15 || i < 0)
78 return wxColour(0,0,0);
79
80 return custColours[i];
81}
82
83void 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
8bbe427f 97wxFontData::wxFontData()
c801d85f
KB
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
8bbe427f 109wxFontData::~wxFontData()
c801d85f
KB
110{
111}
112
113void 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
8bbe427f 129wxPrintData::wxPrintData()
c801d85f 130{
2049ba38 131#ifdef __WXMSW__
c801d85f
KB
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
8bbe427f 150wxPrintData::~wxPrintData()
c801d85f 151{
2049ba38 152#ifdef __WXMSW__
c801d85f
KB
153 PRINTDLG *pd = (PRINTDLG *)printData;
154 if ( pd && pd->hDevMode )
155 GlobalFree(pd->hDevMode);
156 if ( pd )
157 delete pd;
158#endif
159}
160
2049ba38 161#ifdef __WXMSW__
8bbe427f 162void wxPrintData::ConvertToNative()
c801d85f
KB
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
c801d85f
KB
177 pd->Flags = PD_RETURNDEFAULT;
178 pd->nCopies = 1;
179
180 // Fill out the DEVMODE structure
181 // so we can use it as input in the 'real' PrintDlg
182 if (!PrintDlg(pd))
183 {
184 if ( pd->hDevMode )
185 GlobalFree(pd->hDevMode);
186 if ( pd->hDevNames )
187 GlobalFree(pd->hDevNames);
188 pd->hDevMode = NULL;
189 pd->hDevNames = NULL;
190 }
191 else
192 {
193 if ( pd->hDevNames )
194 GlobalFree(pd->hDevNames);
195 pd->hDevNames = NULL;
196 }
c801d85f
KB
197 }
198
199 if ( pd->hDevMode )
200 {
201 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
202 devMode->dmOrientation = printOrientation;
203 devMode->dmFields = DM_ORIENTATION;
204 GlobalUnlock(pd->hDevMode);
205 }
206 pd->hDC = (HDC) NULL;
207 pd->nFromPage = (UINT)printFromPage;
208 pd->nToPage = (UINT)printToPage;
209 pd->nMinPage = (UINT)printMinPage;
210 pd->nMaxPage = (UINT)printMaxPage;
211 pd->nCopies = (UINT)printNoCopies;
212
213 pd->Flags = PD_RETURNDC ;
214// pd->lStructSize = sizeof( PRINTDLG );
215 pd->lStructSize = 66 ;
8b9518ee 216 pd->hwndOwner=(HWND)NULL;
c801d85f
KB
217 pd->hDevNames=(HANDLE)NULL;
218 pd->hInstance=(HINSTANCE)NULL;
219 pd->lCustData = (LPARAM) NULL;
220 pd->lpfnPrintHook = NULL;
221 pd->lpfnSetupHook = NULL;
222 pd->lpPrintTemplateName = NULL;
223 pd->lpSetupTemplateName = NULL;
224 pd->hPrintTemplate = (HGLOBAL) NULL;
225 pd->hSetupTemplate = (HGLOBAL) NULL;
226
227 if ( printAllPages )
228 pd->Flags |= PD_ALLPAGES;
229 if ( printCollate )
230 pd->Flags |= PD_COLLATE;
231 if ( printToFile )
232 pd->Flags |= PD_PRINTTOFILE;
233 if ( !printEnablePrintToFile )
234 pd->Flags |= PD_DISABLEPRINTTOFILE;
235 if ( !printEnableSelection )
236 pd->Flags |= PD_NOSELECTION;
237 if ( !printEnablePageNumbers )
238 pd->Flags |= PD_NOPAGENUMS;
239 if ( printEnableHelp )
240 pd->Flags |= PD_SHOWHELP;
241 if ( printSetupDialog )
242 pd->Flags |= PD_PRINTSETUP;
243}
244
8bbe427f 245void wxPrintData::ConvertFromNative()
c801d85f
KB
246{
247 PRINTDLG *pd = (PRINTDLG*) printData;
248 if ( pd == NULL )
249 return;
250
251 if ( pd->hDevMode )
252 {
253 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
254 printOrientation = devMode->dmOrientation;
255 GlobalUnlock(pd->hDevMode);
256 }
257 printFromPage = pd->nFromPage ;
258 printToPage = pd->nToPage ;
259 printMinPage = pd->nMinPage ;
260 printMaxPage = pd->nMaxPage ;
261 printNoCopies = pd->nCopies ;
262
263 printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES);
264 printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE);
265 printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE);
266 printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE);
267 printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION);
268 printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS);
269 printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP);
270 printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP);
271}
272
273void wxPrintData::SetOwnerWindow(wxWindow* win)
274{
275 if ( printData == NULL )
276 ConvertToNative();
277
278 if ( printData != NULL && win != NULL)
279 {
280 PRINTDLG *pd = (PRINTDLG *) printData ;
281 pd->hwndOwner=(HWND) win->GetHWND();
282 }
283}
284#endif
285
286void wxPrintData::operator=(const wxPrintData& data)
287{
288 printFromPage = data.printFromPage;
289 printToPage = data.printToPage;
290 printMinPage = data.printMinPage;
291 printMaxPage = data.printMaxPage;
292 printNoCopies = data.printNoCopies;
293 printAllPages = data.printAllPages;
294 printCollate = data.printCollate;
295 printToFile = data.printToFile;
296 printEnableSelection = data.printEnableSelection;
297 printEnablePageNumbers = data.printEnablePageNumbers;
298 printEnableHelp = data.printEnableHelp;
299 printEnablePrintToFile = data.printEnablePrintToFile;
300 printSetupDialog = data.printSetupDialog;
301 printOrientation = data.printOrientation;
302}
303
304/*
305 * wxPageSetupData
306 */
307
8bbe427f 308wxPageSetupData::wxPageSetupData()
c801d85f
KB
309{
310#if defined(__WIN95__)
311 m_pageSetupData = NULL;
312#endif
313 m_paperSize = wxPoint(0, 0);
314 m_minMarginTopLeft = wxPoint(0, 0);
315 m_minMarginBottomRight = wxPoint(0, 0);
316 m_marginTopLeft = wxPoint(0, 0);
317 m_marginBottomRight = wxPoint(0, 0);
318 m_orientation = wxPORTRAIT;
319
320 // Flags
321 m_defaultMinMargins = FALSE;
322 m_enableMargins = TRUE;
323 m_enableOrientation = TRUE;
324 m_enablePaper = TRUE;
325 m_enablePrinter = TRUE;
326 m_enableHelp = FALSE;
327 m_getDefaultInfo = FALSE;
328}
329
8bbe427f 330wxPageSetupData::~wxPageSetupData()
c801d85f 331{
34138703 332#if defined(__WIN95__) && defined(__WXMSW__)
c801d85f
KB
333 PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData;
334 if ( pd && pd->hDevMode )
335 GlobalFree(pd->hDevMode);
336 if ( pd )
337 delete pd;
338#endif
339}
340
341void wxPageSetupData::operator=(const wxPageSetupData& data)
342{
343 m_paperSize = data.m_paperSize;
344 m_minMarginTopLeft = data.m_minMarginTopLeft;
345 m_minMarginBottomRight = data.m_minMarginBottomRight;
346 m_marginTopLeft = data.m_marginTopLeft;
347 m_marginBottomRight = data.m_marginBottomRight;
348 m_orientation = data.m_orientation;
349
350 m_defaultMinMargins = data.m_defaultMinMargins;
351 m_enableMargins = data.m_enableMargins;
352 m_enableOrientation = data.m_enableOrientation;
353 m_enablePaper = data.m_enablePaper;
354 m_enablePrinter = data.m_enablePrinter;
355 m_getDefaultInfo = data.m_getDefaultInfo;;
356 m_enableHelp = data.m_enableHelp;
357}
358
34138703 359#if defined(__WXMSW__) && defined(__WIN95__)
8bbe427f 360void wxPageSetupData::ConvertToNative()
c801d85f
KB
361{
362 PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData;
363 if ( m_pageSetupData == NULL )
364 {
365 pd = new PAGESETUPDLG;
366 pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
367 m_pageSetupData = (void *)pd;
368 }
8bbe427f 369
c801d85f
KB
370 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
371
372 if ( m_defaultMinMargins )
373 pd->Flags |= PSD_DEFAULTMINMARGINS;
374 if ( !m_enableMargins )
375 pd->Flags |= PSD_DISABLEMARGINS;
376 if ( !m_enableOrientation )
377 pd->Flags |= PSD_DISABLEORIENTATION;
378 if ( !m_enablePaper )
379 pd->Flags |= PSD_DISABLEPAPER;
380 if ( !m_enablePrinter )
381 pd->Flags |= PSD_DISABLEPRINTER;
382 if ( m_getDefaultInfo )
383 pd->Flags |= PSD_RETURNDEFAULT;
384 if ( m_enableHelp )
385 pd->Flags |= PSD_SHOWHELP;
386
387 pd->lStructSize = sizeof( PAGESETUPDLG );
c4e7c2aa 388 pd->hwndOwner=(HWND)NULL;
c801d85f
KB
389 pd->hDevNames=(HWND)NULL;
390 pd->hInstance=(HINSTANCE)NULL;
391
392 pd->ptPaperSize.x = m_paperSize.x;
393 pd->ptPaperSize.y = m_paperSize.y;
394
395 pd->rtMinMargin.left = m_minMarginTopLeft.x;
396 pd->rtMinMargin.top = m_minMarginTopLeft.y;
397 pd->rtMinMargin.right = m_minMarginBottomRight.x;
398 pd->rtMinMargin.bottom = m_minMarginBottomRight.y;
399
400 pd->rtMargin.left = m_marginTopLeft.x;
401 pd->rtMargin.top = m_marginTopLeft.y;
402 pd->rtMargin.right = m_marginBottomRight.x;
403 pd->rtMargin.bottom = m_marginBottomRight.y;
404
405 pd->lCustData = 0;
406 pd->lpfnPageSetupHook = NULL;
407 pd->lpfnPagePaintHook = NULL;
408 pd->hPageSetupTemplate = NULL;
409 pd->lpPageSetupTemplateName = NULL;
410
411 if ( pd->hDevMode )
412 {
413 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
414 memset(devMode, 0, sizeof(DEVMODE));
415 devMode->dmSize = sizeof(DEVMODE);
416 devMode->dmOrientation = m_orientation;
417 devMode->dmFields = DM_ORIENTATION;
418 GlobalUnlock(pd->hDevMode);
419 }
420}
421
8bbe427f 422void wxPageSetupData::ConvertFromNative()
c801d85f
KB
423{
424 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
425 if ( !pd )
426 return;
427
428 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
429
430 m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS);
431 m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS);
432 m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION);
433 m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER);
434 m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER);
435 m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT);
436 m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP);
437
438 m_paperSize.x = pd->ptPaperSize.x ;
439 m_paperSize.y = pd->ptPaperSize.y ;
440
441 m_minMarginTopLeft.x = pd->rtMinMargin.left ;
442 m_minMarginTopLeft.y = pd->rtMinMargin.top ;
443 m_minMarginBottomRight.x = pd->rtMinMargin.right ;
444 m_minMarginBottomRight.y = pd->rtMinMargin.bottom ;
445
446 m_marginTopLeft.x = pd->rtMargin.left ;
447 m_marginTopLeft.y = pd->rtMargin.top ;
448 m_marginBottomRight.x = pd->rtMargin.right ;
449 m_marginBottomRight.y = pd->rtMargin.bottom ;
450
451 if ( pd->hDevMode )
452 {
453 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
454 m_orientation = devMode->dmOrientation ;
455 GlobalUnlock(pd->hDevMode);
456 }
457}
458
459void wxPageSetupData::SetOwnerWindow(wxWindow* win)
460{
461 if ( m_pageSetupData == NULL )
462 ConvertToNative();
463
464 if ( m_pageSetupData != NULL && win != NULL)
465 {
466 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
467 pd->hwndOwner=(HWND) win->GetHWND();
468 }
469}
470#endif
471