]> git.saurik.com Git - wxWidgets.git/blame - src/common/cmndata.cpp
added wxFrame::Command()
[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
8826f46f
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
c801d85f 20#ifdef __GNUG__
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"
8826f46f 40
7bcb11d3
JS
41#include "wx/paper.h"
42
43// For compatibility
44#if (defined(__WXMOTIF__) || defined(__WXGTK__)) && wxUSE_POSTSCRIPT
8826f46f 45 #define wxCOMPATIBILITY_WITH_PRINTSETUPDATA 1
7bcb11d3 46#endif
c801d85f 47
8826f46f
VZ
48#if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
49 #include "wx/generic/dcpsg.h"
c801d85f 50#endif
7be1f0d9 51
8826f46f
VZ
52#ifdef __WXMSW__
53 #include <windows.h>
7be1f0d9 54
8826f46f
VZ
55 #if !defined(__WIN32__)
56 #include <print.h>
57 #include <commdlg.h>
58 #endif // Win16
59
60 #if defined(__WATCOMC__) || defined(__SC__) || defined(__SALFORDC__)
61 #include <windowsx.h>
62 #include <commdlg.h>
63 #endif
64#endif // MSW
c801d85f
KB
65
66#if !USE_SHARED_LIBRARY
8826f46f
VZ
67 IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
68 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject)
69 IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject)
70 IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
71 IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
c801d85f
KB
72#endif
73
8826f46f
VZ
74// ============================================================================
75// implementation
76// ============================================================================
77
78// ----------------------------------------------------------------------------
79// wxColourData
80// ----------------------------------------------------------------------------
c801d85f 81
8bbe427f 82wxColourData::wxColourData()
c801d85f 83{
7bcb11d3
JS
84 int i;
85 for (i = 0; i < 16; i++)
86 custColours[i].Set(255, 255, 255);
8826f46f 87
7bcb11d3
JS
88 chooseFull = FALSE;
89 dataColour.Set(0,0,0);
90}
c801d85f 91
7bcb11d3
JS
92wxColourData::wxColourData(const wxColourData& data)
93{
94 (*this) = data;
8bbe427f 95}
c801d85f 96
8bbe427f 97wxColourData::~wxColourData()
c801d85f
KB
98{
99}
100
101void wxColourData::SetCustomColour(int i, wxColour& colour)
102{
7bcb11d3
JS
103 if (i > 15 || i < 0)
104 return;
8826f46f 105
7bcb11d3 106 custColours[i] = colour;
c801d85f
KB
107}
108
109wxColour wxColourData::GetCustomColour(int i)
110{
7bcb11d3
JS
111 if (i > 15 || i < 0)
112 return wxColour(0,0,0);
8826f46f 113
7bcb11d3 114 return custColours[i];
c801d85f
KB
115}
116
117void wxColourData::operator=(const wxColourData& data)
118{
7bcb11d3
JS
119 int i;
120 for (i = 0; i < 16; i++)
121 custColours[i] = data.custColours[i];
8826f46f 122
7bcb11d3
JS
123 dataColour = (wxColour&)data.dataColour;
124 chooseFull = data.chooseFull;
c801d85f
KB
125}
126
8826f46f
VZ
127// ----------------------------------------------------------------------------
128// Font data
129// ----------------------------------------------------------------------------
c801d85f 130
8bbe427f 131wxFontData::wxFontData()
c801d85f 132{
7bcb11d3
JS
133 // Intialize colour to black.
134 fontColour.Set(0, 0, 0);
8826f46f 135
7bcb11d3
JS
136 showHelp = FALSE;
137 allowSymbols = TRUE;
138 enableEffects = TRUE;
139 minSize = 0;
140 maxSize = 0;
141}
c801d85f 142
7bcb11d3
JS
143wxFontData::wxFontData(const wxFontData& data)
144{
145 (*this) = data;
c801d85f
KB
146}
147
8bbe427f 148wxFontData::~wxFontData()
c801d85f
KB
149{
150}
151
152void wxFontData::operator=(const wxFontData& data)
153{
7bcb11d3
JS
154 fontColour = data.fontColour;
155 showHelp = data.showHelp;
156 allowSymbols = data.allowSymbols;
157 enableEffects = data.enableEffects;
158 initialFont = data.initialFont;
159 chosenFont = data.chosenFont;
160 minSize = data.minSize;
161 maxSize = data.maxSize;
c801d85f
KB
162}
163
8826f46f
VZ
164// ----------------------------------------------------------------------------
165// Print data
166// ----------------------------------------------------------------------------
c801d85f 167
8bbe427f 168wxPrintData::wxPrintData()
c801d85f 169{
2049ba38 170#ifdef __WXMSW__
7bcb11d3 171 m_devMode = NULL;
c801d85f 172#endif
7bcb11d3
JS
173 m_printOrientation = wxPORTRAIT;
174 m_printNoCopies = 1;
175 m_printCollate = FALSE;
8826f46f 176
7bcb11d3
JS
177 // New, 24/3/99
178 m_printerName = "";
179 m_colour = TRUE;
180 m_duplexMode = wxDUPLEX_SIMPLEX;
181 m_printQuality = wxPRINT_QUALITY_HIGH;
182 m_paperId = wxPAPER_A4;
183 m_paperSize = wxSize(210, 297);
184
185 // PostScript-specific data
186 m_printerCommand = "";
187 m_previewCommand = "";
188 m_printerOptions = "";
189 m_filename = "";
190 m_afmPath = "";
191 m_printerScaleX = 1.0;
192 m_printerScaleY = 1.0;
193 m_printerTranslateX = 0;
194 m_printerTranslateY = 0;
195 m_printMode = wxPRINT_MODE_FILE;
196}
197
198wxPrintData::wxPrintData(const wxPrintData& printData)
199{
200 (*this) = printData;
c801d85f
KB
201}
202
8bbe427f 203wxPrintData::~wxPrintData()
c801d85f 204{
2049ba38 205#ifdef __WXMSW__
7bcb11d3
JS
206 HGLOBAL hDevMode = (HGLOBAL) hDevMode;
207 if (hDevMode )
208 GlobalFree(hDevMode);
209 /*
210 PRINTDLG *pd = (PRINTDLG *) m_printData;
211 if ( pd && pd->hDevMode )
c801d85f 212 GlobalFree(pd->hDevMode);
7bcb11d3 213 if ( pd )
c801d85f 214 delete pd;
7bcb11d3 215 */
c801d85f
KB
216#endif
217}
218
2049ba38 219#ifdef __WXMSW__
7bcb11d3 220
8bbe427f 221void wxPrintData::ConvertToNative()
c801d85f 222{
7bcb11d3
JS
223 HGLOBAL hDevMode = (HGLOBAL) m_devMode;
224 if (!hDevMode)
c801d85f 225 {
7bcb11d3
JS
226 // Use PRINTDLG as a way of creating a DEVMODE object
227 PRINTDLG *pd = new PRINTDLG;
8826f46f 228
c801d85f 229 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
7bcb11d3 230#ifdef __GNUWIN32__
c801d85f 231 pd->lStructSize = 66 ;
7bcb11d3
JS
232 memset(pd, 0, sizeof(PRINTDLG));
233#else
234 pd->lStructSize = sizeof(PRINTDLG);
235 memset(pd, 0, sizeof(PRINTDLG));
236#endif
237
c801d85f
KB
238 pd->hwndOwner = (HWND)NULL;
239 pd->hDevMode = NULL; // Will be created by PrintDlg
240 pd->hDevNames = NULL; // Ditto
8826f46f 241
c801d85f
KB
242 pd->Flags = PD_RETURNDEFAULT;
243 pd->nCopies = 1;
8826f46f 244
c801d85f
KB
245 // Fill out the DEVMODE structure
246 // so we can use it as input in the 'real' PrintDlg
247 if (!PrintDlg(pd))
248 {
249 if ( pd->hDevMode )
250 GlobalFree(pd->hDevMode);
251 if ( pd->hDevNames )
252 GlobalFree(pd->hDevNames);
253 pd->hDevMode = NULL;
254 pd->hDevNames = NULL;
255 }
256 else
257 {
258 if ( pd->hDevNames )
259 GlobalFree(pd->hDevNames);
260 pd->hDevNames = NULL;
7bcb11d3
JS
261
262 hDevMode = pd->hDevMode;
263 m_devMode = (void*) hDevMode;
264 pd->hDevMode = NULL;
c801d85f 265 }
c801d85f 266
7bcb11d3
JS
267 delete pd;
268 }
8826f46f 269
7bcb11d3 270 if ( hDevMode )
c801d85f 271 {
7bcb11d3 272 DEVMODE *devMode = (DEVMODE*) GlobalLock(hDevMode);
8826f46f 273
7bcb11d3 274 //// Orientation
8826f46f 275
7bcb11d3 276 devMode->dmOrientation = m_printOrientation;
c801d85f 277 devMode->dmFields = DM_ORIENTATION;
8826f46f 278
7bcb11d3 279 //// Collation
8826f46f 280
7bcb11d3
JS
281 devMode->dmCollate = (m_printCollate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE);
282 devMode->dmFields |= DM_COLLATE;
8826f46f 283
7bcb11d3 284 //// Number of copies
8826f46f 285
7bcb11d3
JS
286 devMode->dmCopies = m_printNoCopies;
287 devMode->dmFields |= DM_COPIES;
8826f46f 288
7bcb11d3 289 //// Printer name
8826f46f 290
7bcb11d3
JS
291 if (m_printerName != "")
292 {
293 // TODO: make this Unicode compatible
294 int len = wxMin(31, m_printerName.Len());
295 int i;
296 for (i = 0; i < len; i++)
297 devMode->dmDeviceName[i] = m_printerName.GetChar(i);
298 devMode->dmDeviceName[i] = 0;
299 }
8826f46f 300
7bcb11d3 301 //// Colour
8826f46f 302
7bcb11d3
JS
303 if (m_colour)
304 devMode->dmColor = DMCOLOR_COLOR;
305 else
306 devMode->dmColor = DMCOLOR_MONOCHROME;
8826f46f 307
7bcb11d3 308 devMode->dmFields |= DM_COLOR;
8826f46f 309
7bcb11d3 310 //// Paper size
8826f46f 311
7bcb11d3
JS
312 if (m_paperId == wxPAPER_NONE)
313 {
314 devMode->dmPaperWidth = m_paperSize.x * 10;
315 devMode->dmPaperLength = m_paperSize.y * 10;
316 devMode->dmFields |= DM_PAPERWIDTH;
317 devMode->dmFields |= DM_PAPERLENGTH;
318 }
319 else
320 {
321 if (wxThePrintPaperDatabase)
322 {
323 wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType(m_paperId);
324 if (paper)
325 {
326 devMode->dmPaperSize = paper->GetPlatformId();
327 devMode->dmFields |= DM_PAPERSIZE;
328 }
329 }
330 }
8826f46f 331
7bcb11d3 332 //// Duplex
8826f46f 333
7bcb11d3
JS
334 int duplex;
335 switch (m_duplexMode)
336 {
337 case wxDUPLEX_HORIZONTAL: {
338 duplex = DMDUP_HORIZONTAL; break;
339 }
340 case wxDUPLEX_VERTICAL: {
341 duplex = DMDUP_VERTICAL; break;
342 }
343 default:
344 case wxDUPLEX_SIMPLEX: {
345 duplex = DMDUP_SIMPLEX; break;
346 }
347 }
348 devMode->dmDuplex = duplex;
349 devMode->dmFields |= DM_DUPLEX;
8826f46f 350
7bcb11d3 351 //// Quality
8826f46f 352
7bcb11d3
JS
353 int quality;
354 switch (m_printQuality)
355 {
356 case wxPRINT_QUALITY_MEDIUM: {
357 quality = DMRES_MEDIUM; break;
358 }
359 case wxPRINT_QUALITY_LOW: {
360 quality = DMRES_LOW; break;
361 }
362 case wxPRINT_QUALITY_DRAFT: {
363 quality = DMRES_DRAFT; break;
364 }
365 case wxPRINT_QUALITY_HIGH: {
366 quality = DMRES_HIGH; break;
367 }
368 default: {
369 quality = m_printQuality; break;
370 }
371 }
372 devMode->dmPrintQuality = quality;
373 devMode->dmFields |= DM_PRINTQUALITY;
8826f46f 374
7bcb11d3 375 GlobalUnlock(hDevMode);
c801d85f 376 }
7bcb11d3
JS
377}
378
379void wxPrintData::ConvertFromNative()
380{
381 HGLOBAL hDevMode = (HGLOBAL) m_devMode;
382
383 if (!hDevMode)
384 return;
385
386 if ( hDevMode )
387 {
388 DEVMODE *devMode = (DEVMODE*) GlobalLock(hDevMode);
8826f46f 389
7bcb11d3 390 //// Orientation
8826f46f 391
7bcb11d3
JS
392 if (devMode->dmFields & DM_ORIENTATION)
393 m_printOrientation = devMode->dmOrientation;
8826f46f 394
7bcb11d3 395 //// Collation
8826f46f 396
7bcb11d3
JS
397 if (devMode->dmFields & DM_COLLATE)
398 {
399 if (devMode->dmCollate == DMCOLLATE_TRUE)
400 m_printCollate = TRUE;
401 else
402 m_printCollate = FALSE;
403 }
8826f46f 404
7bcb11d3 405 //// Number of copies
8826f46f 406
7bcb11d3
JS
407 if (devMode->dmFields & DM_COPIES)
408 {
409 m_printNoCopies = devMode->dmCopies;
410 }
8826f46f 411
7bcb11d3 412 //// Printer name
8826f46f 413
7bcb11d3
JS
414 if (devMode->dmDeviceName[0] != 0)
415 {
416 // TODO: make this Unicode compatible
417 char buf[32];
418 int i = 0;
419 while (devMode->dmDeviceName[i] != 0)
420 {
421 buf[i] = devMode->dmDeviceName[i];
422 i ++;
423 }
424 buf[i] = 0;
8826f46f 425
7bcb11d3
JS
426 m_printerName = buf;
427 }
8826f46f 428
7bcb11d3 429 //// Colour
8826f46f 430
7bcb11d3
JS
431 if (devMode->dmFields & DM_COLOR)
432 {
433 if (devMode->dmColor == DMCOLOR_COLOR)
434 m_colour = TRUE;
435 else
436 m_colour = FALSE;
437 }
438 else
439 m_colour = TRUE;
8826f46f 440
7bcb11d3 441 //// Paper size
8826f46f 442
7bcb11d3
JS
443 if (devMode->dmFields & DM_PAPERSIZE)
444 {
445 if (wxThePrintPaperDatabase)
446 {
447 wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize);
448 if (paper)
449 {
450 m_paperId = paper->GetId();
451 m_paperSize.x = paper->GetWidth() / 10 ;
452 m_paperSize.y = paper->GetHeight() / 10 ;
453 }
454 else
455 {
456 // Shouldn't really get here
457 wxFAIL_MSG("Couldn't find paper size in paper database.");
8826f46f 458
7bcb11d3
JS
459 m_paperId = wxPAPER_NONE;
460 m_paperSize.x = 0;
461 m_paperSize.y = 0;
462 }
463 }
464 else
465 {
466 // Shouldn't really get here
467 wxFAIL_MSG("Paper database wasn't initialized in wxPrintData::ConvertFromNative.");
8826f46f 468
7bcb11d3
JS
469 m_paperId = wxPAPER_NONE;
470 m_paperSize.x = 0;
471 m_paperSize.y = 0;
472 }
473 }
474 else if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH))
475 {
476 m_paperSize.x = devMode->dmPaperWidth / 10;
477 m_paperSize.y = devMode->dmPaperLength / 10;
478 m_paperId = wxPAPER_NONE;
479 }
480 else
481 {
482 // Shouldn't really get here
483 wxFAIL_MSG("Couldn't find paper size from DEVMODE.");
8826f46f 484
7bcb11d3
JS
485 m_paperSize.x = 0;
486 m_paperSize.y = 0;
487 m_paperId = wxPAPER_NONE;
488 }
8826f46f
VZ
489
490
7bcb11d3 491 //// Duplex
8826f46f 492
7bcb11d3
JS
493 if (devMode->dmFields & DM_DUPLEX)
494 {
495 switch (devMode->dmDuplex)
496 {
497 case DMDUP_HORIZONTAL: {
498 m_duplexMode = wxDUPLEX_HORIZONTAL; break;
499 }
500 case DMDUP_VERTICAL: {
501 m_duplexMode = wxDUPLEX_VERTICAL; break;
502 }
503 default:
504 case DMDUP_SIMPLEX: {
505 m_duplexMode = wxDUPLEX_SIMPLEX; break;
506 }
507 }
508 }
509 else
510 m_duplexMode = wxDUPLEX_SIMPLEX;
8826f46f 511
7bcb11d3 512 //// Quality
8826f46f 513
7bcb11d3
JS
514 if (devMode->dmFields & DM_PRINTQUALITY)
515 {
516 switch (devMode->dmPrintQuality)
517 {
518 case DMRES_MEDIUM: {
519 m_printQuality = wxPRINT_QUALITY_MEDIUM; break;
520 }
521 case DMRES_LOW: {
522 m_printQuality = wxPRINT_QUALITY_LOW; break;
523 }
524 case DMRES_DRAFT: {
525 m_printQuality = wxPRINT_QUALITY_DRAFT; break;
526 }
527 case DMRES_HIGH: {
528 m_printQuality = wxPRINT_QUALITY_HIGH; break;
529 }
530 default:
531 {
532 // TODO: if the printer fills in the resolution in DPI, how
533 // will the application know if it's high, low, draft etc.??
534 // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
535 m_printQuality = devMode->dmPrintQuality; break;
8826f46f 536
7bcb11d3
JS
537 }
538 }
539 }
540 else
541 m_printQuality = wxPRINT_QUALITY_HIGH;
8826f46f 542
7bcb11d3
JS
543 GlobalUnlock(hDevMode);
544 }
545}
c801d85f 546
7bcb11d3
JS
547#endif
548
549void wxPrintData::operator=(const wxPrintData& data)
550{
551 m_printNoCopies = data.m_printNoCopies;
552 m_printCollate = data.m_printCollate;
553 m_printOrientation = data.m_printOrientation;
554 m_printerName = data.m_printerName;
555 m_colour = data.m_colour;
556 m_duplexMode = data.m_duplexMode;
557 m_printQuality = data.m_printQuality;
558 m_paperId = data.m_paperId;
559 m_paperSize = data.m_paperSize;
560
561 // PostScript-specific data
562 m_printerCommand = data.m_printerCommand;
563 m_previewCommand = data.m_previewCommand;
564 m_printerOptions = data.m_printerOptions;
565 m_filename = data.m_filename;
566 m_afmPath = data.m_afmPath;
567 m_printerScaleX = data.m_printerScaleX;
568 m_printerScaleY = data.m_printerScaleY;
569 m_printerTranslateX = data.m_printerTranslateX;
570 m_printerTranslateY = data.m_printerTranslateY;
571 m_printMode = data.m_printMode;
572}
573
574// For compatibility
8826f46f 575#if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
7bcb11d3
JS
576void wxPrintData::operator=(const wxPrintSetupData& setupData)
577{
578 SetPrinterCommand(setupData.GetPrinterCommand());
579 SetPreviewCommand(setupData.GetPrintPreviewCommand());
580 SetPrinterOptions(setupData.GetPrinterOptions());
581
582 long xt, yt;
583 setupData.GetPrinterTranslation(& xt, & yt);
584 SetPrinterTranslation(xt, yt);
585
586 double xs, ys;
587 setupData.GetPrinterScaling(& xs, & ys);
588 SetPrinterScaling(xs, ys);
589
590 SetOrientation(setupData.GetPrinterOrientation());
591 SetPrintMode((wxPrintMode) setupData.GetPrinterMode());
592 SetFontMetricPath(setupData.GetAFMPath());
593 if (setupData.GetPaperName() != "")
594 SetPaperId(wxThePrintPaperDatabase->ConvertNameToId(setupData.GetPaperName()));
595 SetColour(setupData.GetColour());
596 SetFilename(setupData.GetPrinterFile());
597}
8826f46f 598#endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
7bcb11d3 599
8826f46f
VZ
600
601// ----------------------------------------------------------------------------
602// Print dialog data
603// ----------------------------------------------------------------------------
7bcb11d3
JS
604
605wxPrintDialogData::wxPrintDialogData()
606{
607#ifdef __WXMSW__
608 m_printDlgData = NULL;
609#endif
610 m_printFromPage = 0;
611 m_printToPage = 0;
612 m_printMinPage = 0;
613 m_printMaxPage = 0;
614 m_printNoCopies = 1;
615 m_printAllPages = FALSE;
616 m_printCollate = FALSE;
617 m_printToFile = FALSE;
618 m_printEnableSelection = FALSE;
619 m_printEnablePageNumbers = TRUE;
620 m_printEnablePrintToFile = TRUE;
621 m_printEnableHelp = FALSE;
622 m_printSetupDialog = FALSE;
623}
624
625wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
626{
627 (*this) = dialogData;
628}
629
630wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
631{
632#ifdef __WXMSW__
633 m_printDlgData = NULL;
634#endif
635 m_printFromPage = 0;
636 m_printToPage = 0;
637 m_printMinPage = 0;
638 m_printMaxPage = 0;
639 m_printNoCopies = 1;
640 m_printAllPages = FALSE;
641 m_printCollate = FALSE;
642 m_printToFile = FALSE;
643 m_printEnableSelection = FALSE;
644 m_printEnablePageNumbers = TRUE;
645 m_printEnablePrintToFile = TRUE;
646 m_printEnableHelp = FALSE;
647 m_printSetupDialog = FALSE;
648
649 m_printData = printData;
650}
651
652wxPrintDialogData::~wxPrintDialogData()
653{
654#ifdef __WXMSW__
655 PRINTDLG *pd = (PRINTDLG *) m_printDlgData;
656 if ( pd && pd->hDevMode )
657 GlobalFree(pd->hDevMode);
658 if ( pd )
659 delete pd;
660#endif
661}
662
663#ifdef __WXMSW__
664void wxPrintDialogData::ConvertToNative()
665{
666 m_printData.ConvertToNative();
667
668 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
669
670 if (!pd)
671 {
672 pd = new PRINTDLG;
673 m_printDlgData = (void*) pd;
674
675 // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
676#ifdef __GNUWIN32__
677 pd->lStructSize = 66 ;
678#else
679#endif
680 pd->lStructSize = sizeof(PRINTDLG);
681 pd->hwndOwner = (HWND)NULL;
682 pd->hDevMode = NULL; // Will be created by PrintDlg
683 pd->hDevNames = NULL; // Ditto
684
685 pd->Flags = PD_RETURNDEFAULT;
686 pd->nCopies = 1;
687 }
688
689 // Pass the devmode data to the PRINTDLG structure, since it'll
690 // be needed when PrintDlg is called.
691 if (pd->hDevMode)
692 {
693 GlobalFree(pd->hDevMode);
694 }
695
696 pd->hDevMode = (HGLOBAL) m_printData.GetNativeData();
697
698 m_printData.SetNativeData((void*) NULL);
699
700 wxASSERT_MSG( (pd->hDevMode), "hDevMode must be non-NULL in ConvertToNative!");
701
702 pd->hDC = (HDC) NULL;
703 pd->nFromPage = (UINT)m_printFromPage;
704 pd->nToPage = (UINT)m_printToPage;
705 pd->nMinPage = (UINT)m_printMinPage;
706 pd->nMaxPage = (UINT)m_printMaxPage;
707 pd->nCopies = (UINT)m_printNoCopies;
8826f46f 708
c801d85f 709 pd->Flags = PD_RETURNDC ;
7bcb11d3
JS
710
711#ifdef __GNUWIN32__
c801d85f 712 pd->lStructSize = 66 ;
7bcb11d3
JS
713#else
714 pd->lStructSize = sizeof( PRINTDLG );
715#endif
716
8b9518ee 717 pd->hwndOwner=(HWND)NULL;
c801d85f
KB
718 pd->hDevNames=(HANDLE)NULL;
719 pd->hInstance=(HINSTANCE)NULL;
720 pd->lCustData = (LPARAM) NULL;
721 pd->lpfnPrintHook = NULL;
722 pd->lpfnSetupHook = NULL;
723 pd->lpPrintTemplateName = NULL;
724 pd->lpSetupTemplateName = NULL;
725 pd->hPrintTemplate = (HGLOBAL) NULL;
726 pd->hSetupTemplate = (HGLOBAL) NULL;
8826f46f 727
7bcb11d3 728 if ( m_printAllPages )
c801d85f 729 pd->Flags |= PD_ALLPAGES;
7bcb11d3 730 if ( m_printCollate )
c801d85f 731 pd->Flags |= PD_COLLATE;
7bcb11d3 732 if ( m_printToFile )
c801d85f 733 pd->Flags |= PD_PRINTTOFILE;
7bcb11d3 734 if ( !m_printEnablePrintToFile )
c801d85f 735 pd->Flags |= PD_DISABLEPRINTTOFILE;
7bcb11d3
JS
736 if ( !m_printEnableSelection )
737 pd->Flags |= PD_NOSELECTION;
738 if ( !m_printEnablePageNumbers )
739 pd->Flags |= PD_NOPAGENUMS;
740 if ( m_printEnableHelp )
741 pd->Flags |= PD_SHOWHELP;
742 if ( m_printSetupDialog )
743 pd->Flags |= PD_PRINTSETUP;
c801d85f
KB
744}
745
7bcb11d3 746void wxPrintDialogData::ConvertFromNative()
c801d85f 747{
7bcb11d3 748 PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
c801d85f
KB
749 if ( pd == NULL )
750 return;
751
7bcb11d3
JS
752 // Pass the devmode data back to the wxPrintData structure where it really belongs.
753 if (pd->hDevMode)
c801d85f 754 {
7bcb11d3
JS
755 if (m_printData.GetNativeData())
756 {
757 // Make sure we don't leak memory
758 GlobalFree((HGLOBAL) m_printData.GetNativeData());
759 }
760 m_printData.SetNativeData((void*) pd->hDevMode);
761 pd->hDevMode = NULL;
c801d85f 762 }
c801d85f 763
7bcb11d3
JS
764 // Now convert the DEVMODE object, passed down from the PRINTDLG object,
765 // into wxWindows form.
766 m_printData.ConvertFromNative();
767
768 m_printFromPage = pd->nFromPage ;
769 m_printToPage = pd->nToPage ;
770 m_printMinPage = pd->nMinPage ;
771 m_printMaxPage = pd->nMaxPage ;
772 m_printNoCopies = pd->nCopies ;
8826f46f 773
7bcb11d3
JS
774 m_printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES);
775 m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE);
776 m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE);
777 m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE);
778 m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION);
779 m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS);
780 m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP);
781 m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP);
782
783/* port is obsolete in WIN32
784 // Get the port name
785 if (pd->hDevNames)
786 {
787 LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames);
788 if (lpDevNames) {
789 m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
790 wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
791 GlobalUnlock(pd->hDevNames);
8826f46f 792
7bcb11d3
JS
793// wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
794 }
795 }
796*/
c801d85f
KB
797}
798
7bcb11d3 799void wxPrintDialogData::SetOwnerWindow(wxWindow* win)
c801d85f 800{
7bcb11d3 801 if ( m_printDlgData == NULL )
c801d85f 802 ConvertToNative();
8826f46f 803
7bcb11d3 804 if ( m_printDlgData != NULL && win != NULL)
c801d85f 805 {
7bcb11d3
JS
806 PRINTDLG *pd = (PRINTDLG *) m_printDlgData ;
807 pd->hwndOwner=(HWND) win->GetHWND();
c801d85f
KB
808 }
809}
8826f46f 810#endif // MSW
c801d85f 811
7bcb11d3 812void wxPrintDialogData::operator=(const wxPrintDialogData& data)
c801d85f 813{
7bcb11d3
JS
814 m_printFromPage = data.m_printFromPage;
815 m_printToPage = data.m_printToPage;
816 m_printMinPage = data.m_printMinPage;
817 m_printMaxPage = data.m_printMaxPage;
818 m_printNoCopies = data.m_printNoCopies;
819 m_printAllPages = data.m_printAllPages;
820 m_printCollate = data.m_printCollate;
821 m_printToFile = data.m_printToFile;
822 m_printEnableSelection = data.m_printEnableSelection;
823 m_printEnablePageNumbers = data.m_printEnablePageNumbers;
824 m_printEnableHelp = data.m_printEnableHelp;
825 m_printEnablePrintToFile = data.m_printEnablePrintToFile;
826 m_printSetupDialog = data.m_printSetupDialog;
827
828 m_printData = data.m_printData;
829}
830
831void wxPrintDialogData::operator=(const wxPrintData& data)
832{
833 m_printData = data;
c801d85f
KB
834}
835
8826f46f
VZ
836// ----------------------------------------------------------------------------
837// wxPageSetupDialogData
838// ----------------------------------------------------------------------------
c801d85f 839
7bcb11d3 840wxPageSetupDialogData::wxPageSetupDialogData()
c801d85f
KB
841{
842#if defined(__WIN95__)
7bcb11d3 843 m_pageSetupData = NULL;
c801d85f 844#endif
7bcb11d3
JS
845 m_paperSize = wxSize(0, 0);
846
847 CalculatePaperSizeFromId();
848
849 m_minMarginTopLeft = wxPoint(0, 0);
850 m_minMarginBottomRight = wxPoint(0, 0);
851 m_marginTopLeft = wxPoint(0, 0);
852 m_marginBottomRight = wxPoint(0, 0);
853
854 // Flags
855 m_defaultMinMargins = FALSE;
856 m_enableMargins = TRUE;
857 m_enableOrientation = TRUE;
858 m_enablePaper = TRUE;
859 m_enablePrinter = TRUE;
860 m_enableHelp = FALSE;
861 m_getDefaultInfo = FALSE;
862}
c801d85f 863
7bcb11d3
JS
864wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData)
865{
866 (*this) = dialogData;
867}
868
869wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData)
870{
871#if defined(__WIN95__)
872 m_pageSetupData = NULL;
873#endif
874 m_paperSize = wxSize(0, 0);
875 m_minMarginTopLeft = wxPoint(0, 0);
876 m_minMarginBottomRight = wxPoint(0, 0);
877 m_marginTopLeft = wxPoint(0, 0);
878 m_marginBottomRight = wxPoint(0, 0);
879
880 // Flags
881 m_defaultMinMargins = FALSE;
882 m_enableMargins = TRUE;
883 m_enableOrientation = TRUE;
884 m_enablePaper = TRUE;
885 m_enablePrinter = TRUE;
886 m_enableHelp = FALSE;
887 m_getDefaultInfo = FALSE;
888
889 m_printData = printData;
890
891 // The wxPrintData paper size overrides these values, unless the size cannot
892 // be found.
893 CalculatePaperSizeFromId();
c801d85f
KB
894}
895
7bcb11d3 896wxPageSetupDialogData::~wxPageSetupDialogData()
c801d85f 897{
34138703 898#if defined(__WIN95__) && defined(__WXMSW__)
c801d85f
KB
899 PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData;
900 if ( pd && pd->hDevMode )
901 GlobalFree(pd->hDevMode);
902 if ( pd )
903 delete pd;
904#endif
905}
906
7bcb11d3 907void wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data)
c801d85f 908{
7bcb11d3
JS
909 m_paperSize = data.m_paperSize;
910 m_minMarginTopLeft = data.m_minMarginTopLeft;
911 m_minMarginBottomRight = data.m_minMarginBottomRight;
912 m_marginTopLeft = data.m_marginTopLeft;
913 m_marginBottomRight = data.m_marginBottomRight;
914 m_defaultMinMargins = data.m_defaultMinMargins;
915 m_enableMargins = data.m_enableMargins;
916 m_enableOrientation = data.m_enableOrientation;
917 m_enablePaper = data.m_enablePaper;
918 m_enablePrinter = data.m_enablePrinter;
919 m_getDefaultInfo = data.m_getDefaultInfo;;
920 m_enableHelp = data.m_enableHelp;
921
922 m_printData = data.m_printData;
923}
c801d85f 924
7bcb11d3
JS
925void wxPageSetupDialogData::operator=(const wxPrintData& data)
926{
927 m_printData = data;
c801d85f
KB
928}
929
8826f46f 930#if defined(__WIN95__)
7bcb11d3 931void wxPageSetupDialogData::ConvertToNative()
c801d85f 932{
7bcb11d3
JS
933 m_printData.ConvertToNative();
934
c801d85f 935 PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData;
7bcb11d3 936
c801d85f
KB
937 if ( m_pageSetupData == NULL )
938 {
7bcb11d3
JS
939 pd = new PAGESETUPDLG;
940 pd->hDevMode = NULL;
941 m_pageSetupData = (void *)pd;
c801d85f 942 }
8bbe427f 943
7bcb11d3
JS
944 // Pass the devmode data (created in m_printData.ConvertToNative)
945 // to the PRINTDLG structure, since it'll
946 // be needed when PrintDlg is called.
947
948 if (pd->hDevMode)
949 {
950 GlobalFree(pd->hDevMode);
951 pd->hDevMode = NULL;
952 }
953
954
955 pd->hDevMode = (HGLOBAL) m_printData.GetNativeData();
956
957 m_printData.SetNativeData((void*) NULL);
958
959 wxASSERT_MSG( (pd->hDevMode), "hDevMode must be non-NULL in ConvertToNative!");
960
961// pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
c801d85f 962
7bcb11d3 963 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
8826f46f 964
c801d85f
KB
965 if ( m_defaultMinMargins )
966 pd->Flags |= PSD_DEFAULTMINMARGINS;
967 if ( !m_enableMargins )
968 pd->Flags |= PSD_DISABLEMARGINS;
969 if ( !m_enableOrientation )
970 pd->Flags |= PSD_DISABLEORIENTATION;
971 if ( !m_enablePaper )
972 pd->Flags |= PSD_DISABLEPAPER;
973 if ( !m_enablePrinter )
974 pd->Flags |= PSD_DISABLEPRINTER;
975 if ( m_getDefaultInfo )
976 pd->Flags |= PSD_RETURNDEFAULT;
977 if ( m_enableHelp )
978 pd->Flags |= PSD_SHOWHELP;
979
7bcb11d3
JS
980 // We want the units to be in hundredths of a millimetre
981 pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
982
c801d85f 983 pd->lStructSize = sizeof( PAGESETUPDLG );
c4e7c2aa 984 pd->hwndOwner=(HWND)NULL;
c801d85f
KB
985 pd->hDevNames=(HWND)NULL;
986 pd->hInstance=(HINSTANCE)NULL;
8826f46f 987
7bcb11d3
JS
988 pd->ptPaperSize.x = m_paperSize.x * 100;
989 pd->ptPaperSize.y = m_paperSize.y * 100;
8826f46f 990
7bcb11d3
JS
991 pd->rtMinMargin.left = m_minMarginTopLeft.x * 100;
992 pd->rtMinMargin.top = m_minMarginTopLeft.y * 100;
993 pd->rtMinMargin.right = m_minMarginBottomRight.x * 100;
994 pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100;
8826f46f 995
7bcb11d3
JS
996 pd->rtMargin.left = m_marginTopLeft.x * 100;
997 pd->rtMargin.top = m_marginTopLeft.y * 100;
998 pd->rtMargin.right = m_marginBottomRight.x * 100;
999 pd->rtMargin.bottom = m_marginBottomRight.y * 100;
8826f46f 1000
c801d85f
KB
1001 pd->lCustData = 0;
1002 pd->lpfnPageSetupHook = NULL;
1003 pd->lpfnPagePaintHook = NULL;
1004 pd->hPageSetupTemplate = NULL;
1005 pd->lpPageSetupTemplateName = NULL;
1006
8826f46f 1007/*
c801d85f
KB
1008 if ( pd->hDevMode )
1009 {
1010 DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode);
1011 memset(devMode, 0, sizeof(DEVMODE));
1012 devMode->dmSize = sizeof(DEVMODE);
1013 devMode->dmOrientation = m_orientation;
1014 devMode->dmFields = DM_ORIENTATION;
1015 GlobalUnlock(pd->hDevMode);
1016 }
7bcb11d3 1017*/
c801d85f
KB
1018}
1019
7bcb11d3 1020void wxPageSetupDialogData::ConvertFromNative()
c801d85f
KB
1021{
1022 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
1023 if ( !pd )
1024 return;
8826f46f 1025
7bcb11d3
JS
1026 // Pass the devmode data back to the wxPrintData structure where it really belongs.
1027 if (pd->hDevMode)
1028 {
1029 if (m_printData.GetNativeData())
1030 {
1031 // Make sure we don't leak memory
1032 GlobalFree((HGLOBAL) m_printData.GetNativeData());
1033 }
1034 m_printData.SetNativeData((void*) pd->hDevMode);
1035 pd->hDevMode = NULL;
1036 }
c801d85f 1037
7bcb11d3 1038 m_printData.ConvertFromNative();
c801d85f 1039
7bcb11d3 1040 pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
8826f46f 1041
c801d85f
KB
1042 m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS);
1043 m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS);
1044 m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION);
1045 m_enablePaper = ((pd->Flags & PSD_DISABLEPAPER) != PSD_DISABLEPAPER);
1046 m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER);
1047 m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT);
1048 m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP);
8826f46f 1049
7bcb11d3
JS
1050 m_paperSize.x = pd->ptPaperSize.x / 100;
1051 m_paperSize.y = pd->ptPaperSize.y / 100;
8826f46f 1052
7bcb11d3
JS
1053 m_minMarginTopLeft.x = pd->rtMinMargin.left / 100;
1054 m_minMarginTopLeft.y = pd->rtMinMargin.top / 100;
1055 m_minMarginBottomRight.x = pd->rtMinMargin.right / 100;
1056 m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100;
8826f46f 1057
7bcb11d3
JS
1058 m_marginTopLeft.x = pd->rtMargin.left / 100 ;
1059 m_marginTopLeft.y = pd->rtMargin.top / 100 ;
1060 m_marginBottomRight.x = pd->rtMargin.right / 100 ;
1061 m_marginBottomRight.y = pd->rtMargin.bottom / 100 ;
1062}
c801d85f 1063
7bcb11d3
JS
1064void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win)
1065{
1066 if ( m_pageSetupData == NULL )
1067 ConvertToNative();
8826f46f 1068
7bcb11d3
JS
1069 if ( m_pageSetupData != NULL && win != NULL)
1070 {
1071 PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ;
1072 pd->hwndOwner=(HWND) win->GetHWND();
1073 }
1074}
8826f46f 1075#endif // Win95
c801d85f 1076
7bcb11d3
JS
1077// If a corresponding paper type is found in the paper database, will set the m_printData
1078// paper size id member as well.
1079void wxPageSetupDialogData::SetPaperSize(const wxSize& sz)
1080{
1081 m_paperSize = sz;
c801d85f 1082
7bcb11d3
JS
1083 CalculateIdFromPaperSize();
1084}
c801d85f 1085
7bcb11d3
JS
1086// Sets the wxPrintData id, plus the paper width/height if found in the paper database.
1087void wxPageSetupDialogData::SetPaperSize(wxPaperSize id)
1088{
1089 m_printData.SetPaperId(id);
1090
1091 CalculatePaperSizeFromId();
c801d85f
KB
1092}
1093
7bcb11d3
JS
1094// Use paper size defined in this object to set the wxPrintData
1095// paper id
1096void wxPageSetupDialogData::CalculateIdFromPaperSize()
c801d85f 1097{
8826f46f
VZ
1098 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
1099 "wxThePrintPaperDatabase should not be NULL. "
1100 "Do not create global print dialog data objects." );
c801d85f 1101
7bcb11d3
JS
1102 wxSize sz = GetPaperSize();
1103
1104 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
1105 if (id != wxPAPER_NONE)
c801d85f 1106 {
7bcb11d3 1107 m_printData.SetPaperId(id);
c801d85f
KB
1108 }
1109}
8826f46f 1110
7bcb11d3
JS
1111// Use paper id in wxPrintData to set this object's paper size
1112void wxPageSetupDialogData::CalculatePaperSizeFromId()
1113{
8826f46f
VZ
1114 wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL),
1115 "wxThePrintPaperDatabase should not be NULL. "
1116 "Do not create global print dialog data objects." );
7bcb11d3
JS
1117
1118 wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId());
c801d85f 1119
7bcb11d3
JS
1120 if (sz.x != 0)
1121 {
1122 // sz is in 10ths of a mm, so multiply by 10.
1123 m_paperSize.x = sz.x * 10;
1124 m_paperSize.y = sz.y * 10;
1125 }
1126}
8826f46f 1127