]> git.saurik.com Git - wxWidgets.git/blame - src/common/cmndata.cpp
added wxDynamicLibrary::HasSymbol()
[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
8826f46f 52#ifdef __WXMSW__
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;
7bcb11d3
JS
174 m_printOrientation = wxPORTRAIT;
175 m_printNoCopies = 1;
c9d59ee7 176 m_printCollate = false;
8826f46f 177
7bcb11d3 178 // New, 24/3/99
2b5f62a0 179 m_printerName = wxT("");
c9d59ee7 180 m_colour = true;
7bcb11d3
JS
181 m_duplexMode = wxDUPLEX_SIMPLEX;
182 m_printQuality = wxPRINT_QUALITY_HIGH;
183 m_paperId = wxPAPER_A4;
184 m_paperSize = wxSize(210, 297);
185
8850cbd3 186 m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData();
7bcb11d3
JS
187}
188
189wxPrintData::wxPrintData(const wxPrintData& printData)
5e472c1f 190 : wxObject()
7bcb11d3
JS
191{
192 (*this) = printData;
c801d85f
KB
193}
194
8bbe427f 195wxPrintData::~wxPrintData()
c801d85f 196{
8850cbd3
RR
197 m_nativeData->m_ref--;
198 if (m_nativeData->m_ref == 0)
199 delete m_nativeData;
200
201#ifdef __WXMAC__
746d7582 202 delete m_nativePrintData ;
c801d85f
KB
203#endif
204}
205
7bcb11d3 206
51abe921
SC
207#ifdef __WXMAC__
208void wxPrintData::ConvertToNative()
209{
746d7582 210 m_nativePrintData->TransferFrom( this ) ;
51abe921
SC
211}
212
213void wxPrintData::ConvertFromNative()
214{
746d7582 215 m_nativePrintData->TransferTo( this ) ;
51abe921
SC
216}
217#endif
218
7bcb11d3
JS
219void wxPrintData::operator=(const wxPrintData& data)
220{
221 m_printNoCopies = data.m_printNoCopies;
222 m_printCollate = data.m_printCollate;
223 m_printOrientation = data.m_printOrientation;
224 m_printerName = data.m_printerName;
225 m_colour = data.m_colour;
226 m_duplexMode = data.m_duplexMode;
227 m_printQuality = data.m_printQuality;
228 m_paperId = data.m_paperId;
229 m_paperSize = data.m_paperSize;
60090256 230 m_bin = data.m_bin;
8850cbd3
RR
231
232 m_nativeData = data.GetNativeData();
233 m_nativeData->m_ref++;
234
235#ifdef __WXMAC__
236 m_nativePrintData->CopyFrom( data.m_nativePrintData ) ;
244e5e34 237#endif
7bcb11d3
JS
238}
239
58cf0491
JS
240// Is this data OK for showing the print dialog?
241bool wxPrintData::Ok() const
242{
fd64de59 243 m_nativeData->TransferFrom( *this );
8850cbd3
RR
244
245 return m_nativeData->Ok();
58cf0491 246}
8826f46f
VZ
247
248// ----------------------------------------------------------------------------
249// Print dialog data
250// ----------------------------------------------------------------------------
7bcb11d3
JS
251
252wxPrintDialogData::wxPrintDialogData()
253{
254#ifdef __WXMSW__
255 m_printDlgData = NULL;
256#endif
257 m_printFromPage = 0;
258 m_printToPage = 0;
259 m_printMinPage = 0;
260 m_printMaxPage = 0;
261 m_printNoCopies = 1;
c9d59ee7
WS
262 m_printAllPages = false;
263 m_printCollate = false;
264 m_printToFile = false;
265 m_printSelection = false;
266 m_printEnableSelection = false;
267 m_printEnablePageNumbers = true;
268 m_printEnablePrintToFile = true;
269 m_printEnableHelp = false;
270 m_printSetupDialog = false;
7bcb11d3
JS
271}
272
273wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
5e472c1f 274 : wxObject()
7bcb11d3 275{
7c74e7fe
SC
276#ifdef __WXMSW__
277 m_printDlgData = NULL;
7c74e7fe 278#endif
7bcb11d3
JS
279 (*this) = dialogData;
280}
281
282wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
283{
284#ifdef __WXMSW__
285 m_printDlgData = NULL;
286#endif
d2b354f9 287 m_printFromPage = 1;
7bcb11d3 288 m_printToPage = 0;
d2b354f9
JS
289 m_printMinPage = 1;
290 m_printMaxPage = 9999;
7bcb11d3 291 m_printNoCopies = 1;
c9d59ee7
WS
292 m_printAllPages = false;
293 m_printCollate = false;
294 m_printToFile = false;
295 m_printSelection = false;
296 m_printEnableSelection = false;
297 m_printEnablePageNumbers = true;
298 m_printEnablePrintToFile = true;
299 m_printEnableHelp = false;
300 m_printSetupDialog = false;
7bcb11d3
JS
301
302 m_printData = printData;
303}
304
305wxPrintDialogData::~wxPrintDialogData()
306{
307#ifdef __WXMSW__
308 PRINTDLG *pd = (PRINTDLG *) m_printDlgData;
309 if ( pd && pd->hDevMode )
310 GlobalFree(pd->hDevMode);
311 if ( pd )
312 delete pd;
313#endif
314}
315
316#ifdef __WXMSW__
317void wxPrintDialogData::ConvertToNative()
318{
8850cbd3
RR
319 wxWindowsPrintNativeData *data =
320 (wxWindowsPrintNativeData *) m_printData.GetNativeData();
fd64de59 321 data->TransferFrom( m_printData );
7bcb11d3
JS
322
323 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
324
325 if (!pd)
326 {
327 pd = new PRINTDLG;
161f4f73 328 memset( pd, 0, sizeof(PRINTDLG) );
7bcb11d3
JS
329 m_printDlgData = (void*) pd;
330
331 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
332#ifdef __GNUWIN32__
161f4f73 333 pd->lStructSize = 66;
7bcb11d3 334#else
7bcb11d3 335 pd->lStructSize = sizeof(PRINTDLG);
25889d3c 336#endif
7bcb11d3
JS
337 pd->hwndOwner = (HWND)NULL;
338 pd->hDevMode = NULL; // Will be created by PrintDlg
339 pd->hDevNames = NULL; // Ditto
340
341 pd->Flags = PD_RETURNDEFAULT;
342 pd->nCopies = 1;
343 }
344
345 // Pass the devmode data to the PRINTDLG structure, since it'll
346 // be needed when PrintDlg is called.
347 if (pd->hDevMode)
348 {
349 GlobalFree(pd->hDevMode);
350 }
351
eaeb6a3c
JS
352 // Pass the devnames data to the PRINTDLG structure, since it'll
353 // be needed when PrintDlg is called.
354 if (pd->hDevNames)
355 {
356 GlobalFree(pd->hDevNames);
357 }
358
fd64de59 359 pd->hDevMode = (HGLOBAL)(DWORD) data->GetDevMode();
7bcb11d3 360
fd64de59 361 data->SetDevMode( (void*) NULL);
7bcb11d3 362
58cf0491
JS
363 // Shouldn't assert; we should be able to test Ok-ness at a higher level
364 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
7bcb11d3 365
fd64de59 366 pd->hDevNames = (HGLOBAL)(DWORD) data->GetDevNames();
eaeb6a3c 367
fd64de59 368 data->SetDevNames( (void*) NULL);
eaeb6a3c 369
7bcb11d3 370 pd->hDC = (HDC) NULL;
33ac7e6f
KB
371 pd->nFromPage = (WORD)m_printFromPage;
372 pd->nToPage = (WORD)m_printToPage;
373 pd->nMinPage = (WORD)m_printMinPage;
374 pd->nMaxPage = (WORD)m_printMaxPage;
375 pd->nCopies = (WORD)m_printNoCopies;
8826f46f 376
161f4f73 377 pd->Flags = PD_RETURNDC;
7bcb11d3
JS
378
379#ifdef __GNUWIN32__
161f4f73 380 pd->lStructSize = 66;
7bcb11d3
JS
381#else
382 pd->lStructSize = sizeof( PRINTDLG );
383#endif
384
8b9518ee 385 pd->hwndOwner=(HWND)NULL;
eaeb6a3c 386// pd->hDevNames=(HANDLE)NULL;
c801d85f
KB
387 pd->hInstance=(HINSTANCE)NULL;
388 pd->lCustData = (LPARAM) NULL;
389 pd->lpfnPrintHook = NULL;
390 pd->lpfnSetupHook = NULL;
391 pd->lpPrintTemplateName = NULL;
392 pd->lpSetupTemplateName = NULL;
393 pd->hPrintTemplate = (HGLOBAL) NULL;
394 pd->hSetupTemplate = (HGLOBAL) NULL;
8826f46f 395
7bcb11d3 396 if ( m_printAllPages )
c801d85f 397 pd->Flags |= PD_ALLPAGES;
8084a109 398 if ( m_printSelection )
5360828d 399 pd->Flags |= PD_SELECTION;
7bcb11d3 400 if ( m_printCollate )
c801d85f 401 pd->Flags |= PD_COLLATE;
7bcb11d3 402 if ( m_printToFile )
c801d85f 403 pd->Flags |= PD_PRINTTOFILE;
7bcb11d3 404 if ( !m_printEnablePrintToFile )
c801d85f 405 pd->Flags |= PD_DISABLEPRINTTOFILE;
7bcb11d3
JS
406 if ( !m_printEnableSelection )
407 pd->Flags |= PD_NOSELECTION;
408 if ( !m_printEnablePageNumbers )
409 pd->Flags |= PD_NOPAGENUMS;
d2b354f9 410 else if ( (!m_printAllPages) && (!m_printSelection) && (m_printFromPage != 0) && (m_printToPage != 0))
40474984 411 pd->Flags |= PD_PAGENUMS;
7bcb11d3
JS
412 if ( m_printEnableHelp )
413 pd->Flags |= PD_SHOWHELP;
414 if ( m_printSetupDialog )
415 pd->Flags |= PD_PRINTSETUP;
c801d85f
KB
416}
417
7bcb11d3 418void wxPrintDialogData::ConvertFromNative()
c801d85f 419{
7bcb11d3 420 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
c801d85f
KB
421 if ( pd == NULL )
422 return;
423
8850cbd3
RR
424 wxWindowsPrintNativeData *data =
425 (wxWindowsPrintNativeData *) m_printData.GetNativeData();
426
7bcb11d3
JS
427 // Pass the devmode data back to the wxPrintData structure where it really belongs.
428 if (pd->hDevMode)
c801d85f 429 {
fd64de59 430 if (data->GetDevMode())
7bcb11d3
JS
431 {
432 // Make sure we don't leak memory
fd64de59 433 GlobalFree( (HGLOBAL)(DWORD) data->GetDevMode() );
7bcb11d3 434 }
fd64de59 435 data->SetDevMode( (void*)(long) pd->hDevMode );
7bcb11d3 436 pd->hDevMode = NULL;
c801d85f 437 }
c801d85f 438
eaeb6a3c
JS
439 // Pass the devnames data back to the wxPrintData structure where it really belongs.
440 if (pd->hDevNames)
441 {
fd64de59 442 if (data->GetDevNames())
eaeb6a3c
JS
443 {
444 // Make sure we don't leak memory
fd64de59 445 GlobalFree((HGLOBAL)(DWORD) data->GetDevNames());
eaeb6a3c 446 }
fd64de59 447 data->SetDevNames((void*)(long) pd->hDevNames);
eaeb6a3c
JS
448 pd->hDevNames = NULL;
449 }
450
7bcb11d3 451 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
77ffb593 452 // into wxWidgets form.
fd64de59 453 data->TransferTo( m_printData );
7bcb11d3 454
161f4f73
VZ
455 m_printFromPage = pd->nFromPage;
456 m_printToPage = pd->nToPage;
457 m_printMinPage = pd->nMinPage;
458 m_printMaxPage = pd->nMaxPage;
459 m_printNoCopies = pd->nCopies;
8826f46f 460
40474984 461 m_printAllPages = (((pd->Flags & PD_PAGENUMS) != PD_PAGENUMS) && ((pd->Flags & PD_SELECTION) != PD_SELECTION));
5360828d 462 m_printSelection = ((pd->Flags & PD_SELECTION) == PD_SELECTION);
7bcb11d3
JS
463 m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE);
464 m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE);
465 m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE);
466 m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION);
467 m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS);
468 m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP);
469 m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP);
470
471/* port is obsolete in WIN32
472 // Get the port name
473 if (pd->hDevNames)
474 {
475 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
476 if (lpDevNames) {
477 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
478 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
479 GlobalUnlock(pd->hDevNames);
8826f46f 480
7bcb11d3
JS
481// wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
482 }
483 }
484*/
c801d85f
KB
485}
486
7bcb11d3 487void wxPrintDialogData::SetOwnerWindow(wxWindow* win)
c801d85f 488{
7bcb11d3 489 if ( m_printDlgData == NULL )
c801d85f 490 ConvertToNative();
8826f46f 491
7bcb11d3 492 if ( m_printDlgData != NULL && win != NULL)
c801d85f 493 {
161f4f73 494 PRINTDLG *pd = (PRINTDLG *) m_printDlgData;
7bcb11d3 495 pd->hwndOwner=(HWND) win->GetHWND();
c801d85f
KB
496 }
497}
8826f46f 498#endif // MSW
c801d85f 499
51abe921 500#ifdef __WXMAC__
cfb00da4 501
51abe921
SC
502void wxPrintDialogData::ConvertToNative()
503{
cfb00da4 504 m_printData.ConvertToNative();
746d7582 505 m_printData.m_nativePrintData->TransferFrom( this ) ;
51abe921
SC
506}
507
508void wxPrintDialogData::ConvertFromNative()
509{
cfb00da4 510 m_printData.ConvertFromNative();
746d7582 511 m_printData.m_nativePrintData->TransferTo( this ) ;
51abe921 512}
cfb00da4 513
51abe921
SC
514#endif
515
516
7bcb11d3 517void wxPrintDialogData::operator=(const wxPrintDialogData& data)
c801d85f 518{
7bcb11d3
JS
519 m_printFromPage = data.m_printFromPage;
520 m_printToPage = data.m_printToPage;
521 m_printMinPage = data.m_printMinPage;
522 m_printMaxPage = data.m_printMaxPage;
523 m_printNoCopies = data.m_printNoCopies;
524 m_printAllPages = data.m_printAllPages;
525 m_printCollate = data.m_printCollate;
526 m_printToFile = data.m_printToFile;
5360828d 527 m_printSelection = data.m_printSelection;
7bcb11d3
JS
528 m_printEnableSelection = data.m_printEnableSelection;
529 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
530 m_printEnableHelp = data.m_printEnableHelp;
531 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
532 m_printSetupDialog = data.m_printSetupDialog;
533
534 m_printData = data.m_printData;
535}
536
537void wxPrintDialogData::operator=(const wxPrintData& data)
538{
539 m_printData = data;
c801d85f
KB
540}
541
8826f46f
VZ
542// ----------------------------------------------------------------------------
543// wxPageSetupDialogData
544// ----------------------------------------------------------------------------
c801d85f 545
7bcb11d3 546wxPageSetupDialogData::wxPageSetupDialogData()
c801d85f
KB
547{
548#if defined(__WIN95__)
7bcb11d3 549 m_pageSetupData = NULL;
c801d85f 550#endif
7bcb11d3
JS
551 m_paperSize = wxSize(0, 0);
552
553 CalculatePaperSizeFromId();
554
555 m_minMarginTopLeft = wxPoint(0, 0);
556 m_minMarginBottomRight = wxPoint(0, 0);
557 m_marginTopLeft = wxPoint(0, 0);
558 m_marginBottomRight = wxPoint(0, 0);
559
560 // Flags
c9d59ee7
WS
561 m_defaultMinMargins = false;
562 m_enableMargins = true;
563 m_enableOrientation = true;
564 m_enablePaper = true;
565 m_enablePrinter = true;
566 m_enableHelp = false;
567 m_getDefaultInfo = false;
7bcb11d3 568}
c801d85f 569
7bcb11d3 570wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
5e472c1f 571 : wxObject()
7bcb11d3 572{
7c74e7fe
SC
573#if defined(__WIN95__)
574 m_pageSetupData = NULL;
7c74e7fe 575#endif
7bcb11d3
JS
576 (*this) = dialogData;
577}
578
579wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
580{
581#if defined(__WIN95__)
582 m_pageSetupData = NULL;
583#endif
584 m_paperSize = wxSize(0, 0);
585 m_minMarginTopLeft = wxPoint(0, 0);
586 m_minMarginBottomRight = wxPoint(0, 0);
587 m_marginTopLeft = wxPoint(0, 0);
588 m_marginBottomRight = wxPoint(0, 0);
589
590 // Flags
c9d59ee7
WS
591 m_defaultMinMargins = false;
592 m_enableMargins = true;
593 m_enableOrientation = true;
594 m_enablePaper = true;
595 m_enablePrinter = true;
596 m_enableHelp = false;
597 m_getDefaultInfo = false;
7bcb11d3
JS
598
599 m_printData = printData;
600
601 // The wxPrintData paper size overrides these values, unless the size cannot
602 // be found.
603 CalculatePaperSizeFromId();
c801d85f
KB
604}
605
7bcb11d3 606wxPageSetupDialogData::~wxPageSetupDialogData()
c801d85f 607{
34138703 608#if defined(__WIN95__) && defined(__WXMSW__)
c801d85f
KB
609 PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData;
610 if ( pd && pd->hDevMode )
611 GlobalFree(pd->hDevMode);
eaeb6a3c
JS
612 if ( pd && pd->hDevNames )
613 GlobalFree(pd->hDevNames);
c801d85f
KB
614 if ( pd )
615 delete pd;
616#endif
617}
618
5e472c1f 619wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
c801d85f 620{
7bcb11d3
JS
621 m_paperSize = data.m_paperSize;
622 m_minMarginTopLeft = data.m_minMarginTopLeft;
623 m_minMarginBottomRight = data.m_minMarginBottomRight;
624 m_marginTopLeft = data.m_marginTopLeft;
625 m_marginBottomRight = data.m_marginBottomRight;
626 m_defaultMinMargins = data.m_defaultMinMargins;
627 m_enableMargins = data.m_enableMargins;
628 m_enableOrientation = data.m_enableOrientation;
629 m_enablePaper = data.m_enablePaper;
630 m_enablePrinter = data.m_enablePrinter;
631 m_getDefaultInfo = data.m_getDefaultInfo;;
632 m_enableHelp = data.m_enableHelp;
633
634 m_printData = data.m_printData;
5e472c1f
GD
635
636 return *this;
7bcb11d3 637}
c801d85f 638
5e472c1f 639wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data)
7bcb11d3
JS
640{
641 m_printData = data;
5e472c1f
GD
642
643 return *this;
c801d85f
KB
644}
645
8826f46f 646#if defined(__WIN95__)
7bcb11d3 647void wxPageSetupDialogData::ConvertToNative()
c801d85f 648{
8850cbd3
RR
649 wxWindowsPrintNativeData *data =
650 (wxWindowsPrintNativeData *) m_printData.GetNativeData();
fd64de59 651 data->TransferFrom( m_printData );
7bcb11d3 652
c801d85f 653 PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData;
7bcb11d3 654
c801d85f
KB
655 if ( m_pageSetupData == NULL )
656 {
7bcb11d3
JS
657 pd = new PAGESETUPDLG;
658 pd->hDevMode = NULL;
eaeb6a3c 659 pd->hDevNames = NULL;
7bcb11d3 660 m_pageSetupData = (void *)pd;
c801d85f 661 }
8bbe427f 662
7bcb11d3
JS
663 // Pass the devmode data (created in m_printData.ConvertToNative)
664 // to the PRINTDLG structure, since it'll
665 // be needed when PrintDlg is called.
666
667 if (pd->hDevMode)
668 {
669 GlobalFree(pd->hDevMode);
670 pd->hDevMode = NULL;
671 }
672
fd64de59 673 pd->hDevMode = (HGLOBAL) data->GetDevMode();
7bcb11d3 674
fd64de59 675 data->SetDevMode( (void*) NULL );
7bcb11d3 676
58cf0491
JS
677 // Shouldn't assert; we should be able to test Ok-ness at a higher level
678 //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
7bcb11d3 679
eaeb6a3c
JS
680 // Pass the devnames data (created in m_printData.ConvertToNative)
681 // to the PRINTDLG structure, since it'll
682 // be needed when PrintDlg is called.
683
684 if (pd->hDevNames)
685 {
686 GlobalFree(pd->hDevNames);
687 pd->hDevNames = NULL;
688 }
689
fd64de59 690 pd->hDevNames = (HGLOBAL) data->GetDevNames();
eaeb6a3c 691
fd64de59 692 data->SetDevNames((void*) NULL);
eaeb6a3c 693
7bcb11d3 694// pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
c801d85f 695
7bcb11d3 696 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
8826f46f 697
c801d85f
KB
698 if ( m_defaultMinMargins )
699 pd->Flags |= PSD_DEFAULTMINMARGINS;
700 if ( !m_enableMargins )
701 pd->Flags |= PSD_DISABLEMARGINS;
702 if ( !m_enableOrientation )
703 pd->Flags |= PSD_DISABLEORIENTATION;
704 if ( !m_enablePaper )
705 pd->Flags |= PSD_DISABLEPAPER;
706 if ( !m_enablePrinter )
707 pd->Flags |= PSD_DISABLEPRINTER;
708 if ( m_getDefaultInfo )
709 pd->Flags |= PSD_RETURNDEFAULT;
710 if ( m_enableHelp )
711 pd->Flags |= PSD_SHOWHELP;
712
7bcb11d3
JS
713 // We want the units to be in hundredths of a millimetre
714 pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
715
c801d85f 716 pd->lStructSize = sizeof( PAGESETUPDLG );
c4e7c2aa 717 pd->hwndOwner=(HWND)NULL;
eaeb6a3c 718// pd->hDevNames=(HWND)NULL;
c801d85f 719 pd->hInstance=(HINSTANCE)NULL;
161f4f73 720 // PAGESETUPDLG is in hundreds of a mm
7bcb11d3
JS
721 pd->ptPaperSize.x = m_paperSize.x * 100;
722 pd->ptPaperSize.y = m_paperSize.y * 100;
8826f46f 723
7bcb11d3
JS
724 pd->rtMinMargin.left = m_minMarginTopLeft.x * 100;
725 pd->rtMinMargin.top = m_minMarginTopLeft.y * 100;
726 pd->rtMinMargin.right = m_minMarginBottomRight.x * 100;
727 pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100;
8826f46f 728
7bcb11d3
JS
729 pd->rtMargin.left = m_marginTopLeft.x * 100;
730 pd->rtMargin.top = m_marginTopLeft.y * 100;
731 pd->rtMargin.right = m_marginBottomRight.x * 100;
732 pd->rtMargin.bottom = m_marginBottomRight.y * 100;
8826f46f 733
c801d85f
KB
734 pd->lCustData = 0;
735 pd->lpfnPageSetupHook = NULL;
736 pd->lpfnPagePaintHook = NULL;
737 pd->hPageSetupTemplate = NULL;
738 pd->lpPageSetupTemplateName = NULL;
739
8826f46f 740/*
c801d85f
KB
741 if ( pd->hDevMode )
742 {
743 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
744 memset(devMode, 0, sizeof(DEVMODE));
745 devMode->dmSize = sizeof(DEVMODE);
746 devMode->dmOrientation = m_orientation;
747 devMode->dmFields = DM_ORIENTATION;
748 GlobalUnlock(pd->hDevMode);
749 }
7bcb11d3 750*/
c801d85f
KB
751}
752
7bcb11d3 753void wxPageSetupDialogData::ConvertFromNative()
c801d85f 754{
161f4f73 755 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData;
c801d85f
KB
756 if ( !pd )
757 return;
8826f46f 758
8850cbd3
RR
759 wxWindowsPrintNativeData *data =
760 (wxWindowsPrintNativeData *) m_printData.GetNativeData();
761
7bcb11d3
JS
762 // Pass the devmode data back to the wxPrintData structure where it really belongs.
763 if (pd->hDevMode)
764 {
fd64de59 765 if (data->GetDevMode())
7bcb11d3
JS
766 {
767 // Make sure we don't leak memory
fd64de59 768 GlobalFree((HGLOBAL) data->GetDevMode());
7bcb11d3 769 }
fd64de59 770 data->SetDevMode( (void*) pd->hDevMode );
7bcb11d3
JS
771 pd->hDevMode = NULL;
772 }
c801d85f 773
fd64de59 774 data->TransferTo( m_printData );
c801d85f 775
eaeb6a3c
JS
776 // Pass the devnames data back to the wxPrintData structure where it really belongs.
777 if (pd->hDevNames)
778 {
fd64de59 779 if (data->GetDevNames())
eaeb6a3c
JS
780 {
781 // Make sure we don't leak memory
fd64de59 782 GlobalFree((HGLOBAL) data->GetDevNames());
eaeb6a3c 783 }
fd64de59 784 data->SetDevNames((void*) pd->hDevNames);
eaeb6a3c
JS
785 pd->hDevNames = NULL;
786 }
787
fd64de59 788 data->TransferTo( m_printData );
eaeb6a3c 789
7bcb11d3 790 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
8826f46f 791
c801d85f
KB
792 m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS);
793 m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS);
794 m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION);
795 m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER);
796 m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER);
797 m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT);
798 m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP);
8826f46f 799
161f4f73 800 // PAGESETUPDLG is in hundreds of a mm
7bcb11d3
JS
801 m_paperSize.x = pd->ptPaperSize.x / 100;
802 m_paperSize.y = pd->ptPaperSize.y / 100;
8826f46f 803
7bcb11d3
JS
804 m_minMarginTopLeft.x = pd->rtMinMargin.left / 100;
805 m_minMarginTopLeft.y = pd->rtMinMargin.top / 100;
806 m_minMarginBottomRight.x = pd->rtMinMargin.right / 100;
807 m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100;
8826f46f 808
161f4f73
VZ
809 m_marginTopLeft.x = pd->rtMargin.left / 100;
810 m_marginTopLeft.y = pd->rtMargin.top / 100;
811 m_marginBottomRight.x = pd->rtMargin.right / 100;
812 m_marginBottomRight.y = pd->rtMargin.bottom / 100;
7bcb11d3 813}
c801d85f 814
7bcb11d3
JS
815void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win)
816{
817 if ( m_pageSetupData == NULL )
818 ConvertToNative();
8826f46f 819
7bcb11d3
JS
820 if ( m_pageSetupData != NULL && win != NULL)
821 {
161f4f73 822 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData;
7bcb11d3
JS
823 pd->hwndOwner=(HWND) win->GetHWND();
824 }
825}
8826f46f 826#endif // Win95
c801d85f 827
51abe921 828#ifdef __WXMAC__
7c74e7fe 829void wxPageSetupDialogData::ConvertToNative()
51abe921 830{
161f4f73 831 m_printData.ConvertToNative();
746d7582 832 m_printData.m_nativePrintData->TransferFrom( this ) ;
51abe921
SC
833}
834
7c74e7fe 835void wxPageSetupDialogData::ConvertFromNative()
51abe921 836{
161f4f73 837 m_printData.ConvertFromNative ();
cfb00da4
SC
838 m_paperSize = m_printData.GetPaperSize() ;
839 CalculateIdFromPaperSize();
746d7582 840 m_printData.m_nativePrintData->TransferTo( this ) ;
161f4f73 841 // adjust minimal values
161f4f73
VZ
842
843 if ( m_marginTopLeft.x < m_minMarginTopLeft.x )
844 m_marginTopLeft.x = m_minMarginTopLeft.x;
845
846 if ( m_marginBottomRight.x < m_minMarginBottomRight.x )
847 m_marginBottomRight.x = m_minMarginBottomRight.x;
848
849 if ( m_marginTopLeft.y < m_minMarginTopLeft.y )
850 m_marginTopLeft.y = m_minMarginTopLeft.y;
851
852 if ( m_marginBottomRight.y < m_minMarginBottomRight.y )
853 m_marginBottomRight.y = m_minMarginBottomRight.y;
51abe921
SC
854}
855#endif
856
857
7bcb11d3
JS
858// If a corresponding paper type is found in the paper database, will set the m_printData
859// paper size id member as well.
860void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
861{
862 m_paperSize = sz;
c801d85f 863
7bcb11d3
JS
864 CalculateIdFromPaperSize();
865}
c801d85f 866
7bcb11d3
JS
867// Sets the wxPrintData id, plus the paper width/height if found in the paper database.
868void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
869{
870 m_printData.SetPaperId(id);
871
872 CalculatePaperSizeFromId();
c801d85f
KB
873}
874
7bcb11d3
JS
875// Use paper size defined in this object to set the wxPrintData
876// paper id
877void wxPageSetupDialogData::CalculateIdFromPaperSize()
c801d85f 878{
8826f46f 879 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
fbdcff4a 880 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
c801d85f 881
7bcb11d3
JS
882 wxSize sz = GetPaperSize();
883
884 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
885 if (id != wxPAPER_NONE)
c801d85f 886 {
7bcb11d3 887 m_printData.SetPaperId(id);
c801d85f
KB
888 }
889}
8826f46f 890
7bcb11d3
JS
891// Use paper id in wxPrintData to set this object's paper size
892void wxPageSetupDialogData::CalculatePaperSizeFromId()
893{
8826f46f 894 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
fbdcff4a 895 wxT("wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects.") );
7bcb11d3
JS
896
897 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
c801d85f 898
01cf2f95
VZ
899 // sz is in 10ths of a mm, while paper size is in mm
900 m_paperSize.x = sz.x / 10;
901 m_paperSize.y = sz.y / 10;
7bcb11d3 902}
8826f46f 903
88ac883a 904#endif // wxUSE_PRINTING_ARCHITECTURE