]> git.saurik.com Git - wxWidgets.git/blame - src/common/cmndata.cpp
correcting allocated buffer size
[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$
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 91wxColourData::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 98wxColourData::wxColourData(const wxColourData& data)
5e472c1f 99 : wxObject()
7bcb11d3
JS
100{
101 (*this) = data;
8bbe427f 102}
c801d85f 103
8bbe427f 104wxColourData::~wxColourData()
c801d85f
KB
105{
106}
107
cebf2fec 108void 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
115wxColour 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
123void 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 137wxFontData::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 151wxFontData::~wxFontData()
c801d85f
KB
152{
153}
154
dbc65e27
VZ
155#if wxUSE_FONTDLG
156
157wxFontDialogBase::~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 168wxPrintData::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
190wxPrintData::wxPrintData(const wxPrintData& printData)
5e472c1f 191 : wxObject()
7bcb11d3
JS
192{
193 (*this) = printData;
c801d85f
KB
194}
195
8bbe427f 196wxPrintData::~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
208void wxPrintData::ConvertToNative()
209{
53fa663a 210#ifdef __WXMAC__
746d7582 211 m_nativePrintData->TransferFrom( this ) ;
53fa663a
RR
212#else
213 m_nativeData->TransferFrom( *this ) ;
214#endif
51abe921
SC
215}
216
217void wxPrintData::ConvertFromNative()
218{
53fa663a 219#ifdef __WXMAC__
746d7582 220 m_nativePrintData->TransferTo( this ) ;
53fa663a
RR
221#else
222 m_nativeData->TransferTo( *this ) ;
51abe921 223#endif
53fa663a 224}
51abe921 225
7bcb11d3
JS
226void wxPrintData::operator=(const wxPrintData& data)
227{
228 m_printNoCopies = data.m_printNoCopies;
229 m_printCollate = data.m_printCollate;
230 m_printOrientation = data.m_printOrientation;
231 m_printerName = data.m_printerName;
232 m_colour = data.m_colour;
233 m_duplexMode = data.m_duplexMode;
234 m_printQuality = data.m_printQuality;
235 m_paperId = data.m_paperId;
236 m_paperSize = data.m_paperSize;
60090256 237 m_bin = data.m_bin;
6038ec8e 238 m_printMode = data.m_printMode;
01b5396f 239 m_filename = data.m_filename;
8850cbd3
RR
240
241 m_nativeData = data.GetNativeData();
242 m_nativeData->m_ref++;
243
244#ifdef __WXMAC__
245 m_nativePrintData->CopyFrom( data.m_nativePrintData ) ;
244e5e34 246#endif
7bcb11d3
JS
247}
248
58cf0491
JS
249// Is this data OK for showing the print dialog?
250bool wxPrintData::Ok() const
251{
fd64de59 252 m_nativeData->TransferFrom( *this );
8850cbd3
RR
253
254 return m_nativeData->Ok();
58cf0491 255}
8826f46f
VZ
256
257// ----------------------------------------------------------------------------
258// Print dialog data
259// ----------------------------------------------------------------------------
7bcb11d3
JS
260
261wxPrintDialogData::wxPrintDialogData()
262{
7bcb11d3
JS
263 m_printFromPage = 0;
264 m_printToPage = 0;
265 m_printMinPage = 0;
266 m_printMaxPage = 0;
267 m_printNoCopies = 1;
c9d59ee7
WS
268 m_printAllPages = false;
269 m_printCollate = false;
270 m_printToFile = false;
271 m_printSelection = false;
272 m_printEnableSelection = false;
273 m_printEnablePageNumbers = true;
9f1316dc
RR
274
275 wxPrintFactory* factory = wxPrintFactory::GetFactory();
276 m_printEnablePrintToFile = ! factory->HasOwnPrintToFile();
277
c9d59ee7 278 m_printEnableHelp = false;
b45dfd0a 279#if WXWIN_COMPATIBILITY_2_4
c9d59ee7 280 m_printSetupDialog = false;
b45dfd0a 281#endif
7bcb11d3
JS
282}
283
284wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
5e472c1f 285 : wxObject()
7bcb11d3
JS
286{
287 (*this) = dialogData;
288}
289
290wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
291{
d2b354f9 292 m_printFromPage = 1;
7bcb11d3 293 m_printToPage = 0;
d2b354f9
JS
294 m_printMinPage = 1;
295 m_printMaxPage = 9999;
7bcb11d3 296 m_printNoCopies = 1;
c9d59ee7
WS
297 m_printAllPages = false;
298 m_printCollate = false;
299 m_printToFile = false;
300 m_printSelection = false;
301 m_printEnableSelection = false;
302 m_printEnablePageNumbers = true;
303 m_printEnablePrintToFile = true;
304 m_printEnableHelp = false;
b45dfd0a 305#if WXWIN_COMPATIBILITY_2_4
c9d59ee7 306 m_printSetupDialog = false;
b45dfd0a 307#endif
7bcb11d3
JS
308 m_printData = printData;
309}
310
311wxPrintDialogData::~wxPrintDialogData()
312{
7bcb11d3
JS
313}
314
51abe921 315#ifdef __WXMAC__
cfb00da4 316
51abe921
SC
317void wxPrintDialogData::ConvertToNative()
318{
cfb00da4 319 m_printData.ConvertToNative();
746d7582 320 m_printData.m_nativePrintData->TransferFrom( this ) ;
51abe921
SC
321}
322
323void wxPrintDialogData::ConvertFromNative()
324{
cfb00da4 325 m_printData.ConvertFromNative();
746d7582 326 m_printData.m_nativePrintData->TransferTo( this ) ;
51abe921 327}
cfb00da4 328
51abe921
SC
329#endif
330
331
7bcb11d3 332void wxPrintDialogData::operator=(const wxPrintDialogData& data)
c801d85f 333{
7bcb11d3
JS
334 m_printFromPage = data.m_printFromPage;
335 m_printToPage = data.m_printToPage;
336 m_printMinPage = data.m_printMinPage;
337 m_printMaxPage = data.m_printMaxPage;
338 m_printNoCopies = data.m_printNoCopies;
339 m_printAllPages = data.m_printAllPages;
340 m_printCollate = data.m_printCollate;
341 m_printToFile = data.m_printToFile;
5360828d 342 m_printSelection = data.m_printSelection;
7bcb11d3
JS
343 m_printEnableSelection = data.m_printEnableSelection;
344 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
345 m_printEnableHelp = data.m_printEnableHelp;
346 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
b45dfd0a 347#if WXWIN_COMPATIBILITY_2_4
7bcb11d3 348 m_printSetupDialog = data.m_printSetupDialog;
b45dfd0a 349#endif
7bcb11d3
JS
350 m_printData = data.m_printData;
351}
352
353void wxPrintDialogData::operator=(const wxPrintData& data)
354{
355 m_printData = data;
c801d85f
KB
356}
357
8826f46f
VZ
358// ----------------------------------------------------------------------------
359// wxPageSetupDialogData
360// ----------------------------------------------------------------------------
c801d85f 361
7bcb11d3 362wxPageSetupDialogData::wxPageSetupDialogData()
c801d85f 363{
7bcb11d3
JS
364 m_paperSize = wxSize(0, 0);
365
366 CalculatePaperSizeFromId();
367
368 m_minMarginTopLeft = wxPoint(0, 0);
369 m_minMarginBottomRight = wxPoint(0, 0);
370 m_marginTopLeft = wxPoint(0, 0);
371 m_marginBottomRight = wxPoint(0, 0);
372
373 // Flags
c9d59ee7
WS
374 m_defaultMinMargins = false;
375 m_enableMargins = true;
376 m_enableOrientation = true;
377 m_enablePaper = true;
378 m_enablePrinter = true;
379 m_enableHelp = false;
380 m_getDefaultInfo = false;
7bcb11d3 381}
c801d85f 382
7bcb11d3 383wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
5e472c1f 384 : wxObject()
7bcb11d3
JS
385{
386 (*this) = dialogData;
387}
388
389wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
390{
7bcb11d3
JS
391 m_paperSize = wxSize(0, 0);
392 m_minMarginTopLeft = wxPoint(0, 0);
393 m_minMarginBottomRight = wxPoint(0, 0);
394 m_marginTopLeft = wxPoint(0, 0);
395 m_marginBottomRight = wxPoint(0, 0);
396
397 // Flags
c9d59ee7
WS
398 m_defaultMinMargins = false;
399 m_enableMargins = true;
400 m_enableOrientation = true;
401 m_enablePaper = true;
402 m_enablePrinter = true;
403 m_enableHelp = false;
404 m_getDefaultInfo = false;
7bcb11d3
JS
405
406 m_printData = printData;
407
408 // The wxPrintData paper size overrides these values, unless the size cannot
409 // be found.
410 CalculatePaperSizeFromId();
c801d85f
KB
411}
412
7bcb11d3 413wxPageSetupDialogData::~wxPageSetupDialogData()
c801d85f 414{
c801d85f
KB
415}
416
5e472c1f 417wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
c801d85f 418{
7bcb11d3
JS
419 m_paperSize = data.m_paperSize;
420 m_minMarginTopLeft = data.m_minMarginTopLeft;
421 m_minMarginBottomRight = data.m_minMarginBottomRight;
422 m_marginTopLeft = data.m_marginTopLeft;
423 m_marginBottomRight = data.m_marginBottomRight;
424 m_defaultMinMargins = data.m_defaultMinMargins;
425 m_enableMargins = data.m_enableMargins;
426 m_enableOrientation = data.m_enableOrientation;
427 m_enablePaper = data.m_enablePaper;
428 m_enablePrinter = data.m_enablePrinter;
429 m_getDefaultInfo = data.m_getDefaultInfo;;
430 m_enableHelp = data.m_enableHelp;
431
432 m_printData = data.m_printData;
5e472c1f
GD
433
434 return *this;
7bcb11d3 435}
c801d85f 436
5e472c1f 437wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data)
7bcb11d3
JS
438{
439 m_printData = data;
5e472c1f
GD
440
441 return *this;
c801d85f
KB
442}
443
51abe921 444#ifdef __WXMAC__
7c74e7fe 445void wxPageSetupDialogData::ConvertToNative()
51abe921 446{
161f4f73 447 m_printData.ConvertToNative();
746d7582 448 m_printData.m_nativePrintData->TransferFrom( this ) ;
51abe921
SC
449}
450
7c74e7fe 451void wxPageSetupDialogData::ConvertFromNative()
51abe921 452{
161f4f73 453 m_printData.ConvertFromNative ();
cfb00da4
SC
454 m_paperSize = m_printData.GetPaperSize() ;
455 CalculateIdFromPaperSize();
746d7582 456 m_printData.m_nativePrintData->TransferTo( this ) ;
161f4f73 457 // adjust minimal values
161f4f73
VZ
458
459 if ( m_marginTopLeft.x < m_minMarginTopLeft.x )
460 m_marginTopLeft.x = m_minMarginTopLeft.x;
461
462 if ( m_marginBottomRight.x < m_minMarginBottomRight.x )
463 m_marginBottomRight.x = m_minMarginBottomRight.x;
464
465 if ( m_marginTopLeft.y < m_minMarginTopLeft.y )
466 m_marginTopLeft.y = m_minMarginTopLeft.y;
467
468 if ( m_marginBottomRight.y < m_minMarginBottomRight.y )
469 m_marginBottomRight.y = m_minMarginBottomRight.y;
51abe921
SC
470}
471#endif
472
473
7bcb11d3
JS
474// If a corresponding paper type is found in the paper database, will set the m_printData
475// paper size id member as well.
476void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
477{
478 m_paperSize = sz;
c801d85f 479
7bcb11d3
JS
480 CalculateIdFromPaperSize();
481}
c801d85f 482
7bcb11d3
JS
483// Sets the wxPrintData id, plus the paper width/height if found in the paper database.
484void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
485{
486 m_printData.SetPaperId(id);
487
488 CalculatePaperSizeFromId();
c801d85f
KB
489}
490
7bcb11d3
JS
491// Use paper size defined in this object to set the wxPrintData
492// paper id
493void wxPageSetupDialogData::CalculateIdFromPaperSize()
c801d85f 494{
8826f46f 495 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
fbdcff4a 496 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
c801d85f 497
7bcb11d3
JS
498 wxSize sz = GetPaperSize();
499
500 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
501 if (id != wxPAPER_NONE)
c801d85f 502 {
7bcb11d3 503 m_printData.SetPaperId(id);
c801d85f
KB
504 }
505}
8826f46f 506
7bcb11d3
JS
507// Use paper id in wxPrintData to set this object's paper size
508void wxPageSetupDialogData::CalculatePaperSizeFromId()
509{
8826f46f 510 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
fbdcff4a 511 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
7bcb11d3
JS
512
513 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
c801d85f 514
01cf2f95
VZ
515 // sz is in 10ths of a mm, while paper size is in mm
516 m_paperSize.x = sz.x / 10;
517 m_paperSize.y = sz.y / 10;
7bcb11d3 518}
8826f46f 519
88ac883a 520#endif // wxUSE_PRINTING_ARCHITECTURE