]> git.saurik.com Git - wxWidgets.git/blob - src/msw/printdlg.cpp
wxCheckListBox fixes: crash/memory leak when items are dynamically
[wxWidgets.git] / src / msw / printdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: printdlg.cpp
3 // Purpose: wxPrintDialog, wxPageSetupDialog
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "printdlg.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 #endif
25
26 #include "wx/printdlg.h"
27 #include "wx/dcprint.h"
28
29 // Have to emulate page setup dialog for Win16
30 #if !defined(__WIN95__)
31 #include "wx/generic/prntdlgg.h"
32 #endif
33
34 #include <stdlib.h>
35 #include <windows.h>
36 #include <commdlg.h>
37
38 #ifndef __WIN32__
39 #include <print.h>
40 #endif
41
42 // Clash with Windows header files
43 #ifdef StartDoc
44 #undef StartDoc
45 #endif
46
47 #if !USE_SHARED_LIBRARY
48 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog)
49 IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog)
50 #endif
51
52 wxPrintDialog::wxPrintDialog(void):
53 wxDialog()
54 {
55 dialogParent = NULL;
56 printerDC = NULL;
57 destroyDC = TRUE;
58 deviceName = NULL;
59 driverName = NULL;
60 portName = NULL;
61 }
62
63 wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintData* data):
64 wxDialog()
65 {
66 Create(p, data);
67 }
68
69 bool wxPrintDialog::Create(wxWindow *p, wxPrintData* data)
70 {
71 dialogParent = p;
72 printerDC = NULL;
73 destroyDC = TRUE;
74 deviceName = NULL;
75 driverName = NULL;
76 portName = NULL;
77
78 if ( data )
79 printData = *data;
80
81 #ifdef __WXMSW__
82 printData.SetOwnerWindow(p);
83 #endif
84
85 return TRUE;
86 }
87
88 wxPrintDialog::~wxPrintDialog(void)
89 {
90 if (destroyDC && printerDC)
91 delete printerDC;
92 if (deviceName) delete[] deviceName;
93 if (driverName) delete[] driverName;
94 if (portName) delete[] portName;
95 }
96
97 int wxPrintDialog::ShowModal(void)
98 {
99 printData.ConvertToNative();
100
101 bool ret = (PrintDlg( (PRINTDLG *)printData.printData ) != 0);
102 if ( ret != FALSE && ((PRINTDLG *)printData.printData)->hDC)
103 {
104 wxPrinterDC *pdc = new wxPrinterDC((WXHDC) ((PRINTDLG *)printData.printData)->hDC);
105 printerDC = pdc;
106 printData.ConvertFromNative();
107 return wxID_OK;
108 }
109 else
110 {
111 /*
112 char buf[256];
113 DWORD exError = CommDlgExtendedError();
114 sprintf(buf, "ret = %d, ex error = %d", (int) ret, (int) exError);
115 wxMessageBox(buf);
116 */
117 return wxID_CANCEL;
118 }
119 }
120
121 wxDC *wxPrintDialog::GetPrintDC(void)
122 {
123 if (printerDC)
124 {
125 destroyDC = FALSE;
126 return printerDC;
127 }
128 else
129 return NULL;
130 }
131
132 /*
133 * wxPageSetupDialog
134 */
135
136 wxPageSetupDialog::wxPageSetupDialog(void):
137 wxDialog()
138 {
139 m_dialogParent = NULL;
140 }
141
142 wxPageSetupDialog::wxPageSetupDialog(wxWindow *p, wxPageSetupData *data):
143 wxDialog()
144 {
145 Create(p, data);
146 }
147
148 bool wxPageSetupDialog::Create(wxWindow *p, wxPageSetupData *data)
149 {
150 m_dialogParent = p;
151
152 if (data)
153 m_pageSetupData = (*data);
154
155 #if defined(__WIN95__)
156 m_pageSetupData.SetOwnerWindow(p);
157 #endif
158 return TRUE;
159 }
160
161 wxPageSetupDialog::~wxPageSetupDialog(void)
162 {
163 }
164
165 int wxPageSetupDialog::ShowModal(void)
166 {
167 #ifdef __WIN95__
168 m_pageSetupData.ConvertToNative();
169 if (PageSetupDlg( (PAGESETUPDLG *)m_pageSetupData.GetNativeData() ))
170 {
171 m_pageSetupData.ConvertFromNative();
172 return wxID_OK;
173 }
174 else
175 return wxID_CANCEL;
176 #else
177 wxGenericPageSetupDialog *genericPageSetupDialog = new wxGenericPageSetupDialog(GetParent(), & m_pageSetupData);
178 int ret = genericPageSetupDialog->ShowModal();
179 m_pageSetupData = genericPageSetupDialog->GetPageSetupData();
180 genericPageSetupDialog->Close(TRUE);
181 return ret;
182 #endif
183 }
184