]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
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 | #define IN_WX_MAIN_CPP | |
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #if defined(__BORLANDC__) | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #ifndef WX_PRECOMP | |
25 | #endif | |
26 | ||
27 | #include "wx/printdlg.h" | |
28 | #include "wx/dcprint.h" | |
29 | ||
30 | // Have to emulate page setup dialog for Win16 | |
31 | #if !defined(__WIN95__) | |
32 | #include "wx/generic/prntdlgg.h" | |
33 | #endif | |
34 | ||
35 | #include <stdlib.h> | |
36 | #include <windows.h> | |
37 | #include <commdlg.h> | |
38 | ||
39 | #ifndef __WIN32__ | |
40 | #include <print.h> | |
41 | #endif | |
42 | ||
43 | // Clash with Windows header files | |
44 | #ifdef StartDoc | |
45 | #undef StartDoc | |
46 | #endif | |
47 | ||
48 | #if !USE_SHARED_LIBRARY | |
49 | IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog) | |
50 | IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog) | |
51 | #endif | |
52 | ||
53 | wxPrintDialog::wxPrintDialog(void): | |
54 | wxDialog() | |
55 | { | |
56 | dialogParent = NULL; | |
57 | printerDC = NULL; | |
58 | destroyDC = TRUE; | |
59 | deviceName = NULL; | |
60 | driverName = NULL; | |
61 | portName = NULL; | |
62 | } | |
63 | ||
64 | wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintData* data): | |
65 | wxDialog() | |
66 | { | |
67 | Create(p, data); | |
68 | } | |
69 | ||
70 | bool wxPrintDialog::Create(wxWindow *p, wxPrintData* data) | |
71 | { | |
72 | dialogParent = p; | |
73 | printerDC = NULL; | |
74 | destroyDC = TRUE; | |
75 | deviceName = NULL; | |
76 | driverName = NULL; | |
77 | portName = NULL; | |
78 | ||
79 | if ( data ) | |
80 | printData = *data; | |
81 | ||
82 | #ifdef __WINDOWS__ | |
83 | printData.SetOwnerWindow(p); | |
84 | #endif | |
85 | ||
86 | return TRUE; | |
87 | } | |
88 | ||
89 | wxPrintDialog::~wxPrintDialog(void) | |
90 | { | |
91 | if (destroyDC && printerDC) | |
92 | delete printerDC; | |
93 | if (deviceName) delete[] deviceName; | |
94 | if (driverName) delete[] driverName; | |
95 | if (portName) delete[] portName; | |
96 | } | |
97 | ||
98 | int wxPrintDialog::ShowModal(void) | |
99 | { | |
100 | printData.ConvertToNative(); | |
101 | ||
102 | bool ret = (PrintDlg( (PRINTDLG *)printData.printData ) != 0); | |
103 | if ( ret != FALSE && ((PRINTDLG *)printData.printData)->hDC) | |
104 | { | |
105 | wxPrinterDC *pdc = new wxPrinterDC((WXHDC) ((PRINTDLG *)printData.printData)->hDC); | |
106 | printerDC = pdc; | |
107 | printData.ConvertFromNative(); | |
108 | return wxID_OK; | |
109 | } | |
110 | else | |
111 | { | |
112 | /* | |
113 | char buf[256]; | |
114 | DWORD exError = CommDlgExtendedError(); | |
115 | sprintf(buf, "ret = %d, ex error = %d", (int) ret, (int) exError); | |
116 | wxMessageBox(buf); | |
117 | */ | |
118 | return wxID_CANCEL; | |
119 | } | |
120 | } | |
121 | ||
122 | wxDC *wxPrintDialog::GetPrintDC(void) | |
123 | { | |
124 | if (printerDC) | |
125 | { | |
126 | destroyDC = FALSE; | |
127 | return printerDC; | |
128 | } | |
129 | else | |
130 | return NULL; | |
131 | } | |
132 | ||
133 | /* | |
134 | * wxPageSetupDialog | |
135 | */ | |
136 | ||
137 | wxPageSetupDialog::wxPageSetupDialog(void): | |
138 | wxDialog() | |
139 | { | |
140 | m_dialogParent = NULL; | |
141 | } | |
142 | ||
143 | wxPageSetupDialog::wxPageSetupDialog(wxWindow *p, wxPageSetupData *data): | |
144 | wxDialog() | |
145 | { | |
146 | Create(p, data); | |
147 | } | |
148 | ||
149 | bool wxPageSetupDialog::Create(wxWindow *p, wxPageSetupData *data) | |
150 | { | |
151 | m_dialogParent = p; | |
152 | ||
153 | if (data) | |
154 | m_pageSetupData = (*data); | |
155 | ||
156 | #if defined(__WIN95__) | |
157 | m_pageSetupData.SetOwnerWindow(p); | |
158 | #endif | |
159 | return TRUE; | |
160 | } | |
161 | ||
162 | wxPageSetupDialog::~wxPageSetupDialog(void) | |
163 | { | |
164 | } | |
165 | ||
166 | int wxPageSetupDialog::ShowModal(void) | |
167 | { | |
168 | #ifdef __WIN95__ | |
169 | m_pageSetupData.ConvertToNative(); | |
170 | if (PageSetupDlg( (PAGESETUPDLG *)m_pageSetupData.GetNativeData() )) | |
171 | { | |
172 | m_pageSetupData.ConvertFromNative(); | |
173 | return wxID_OK; | |
174 | } | |
175 | else | |
176 | return wxID_CANCEL; | |
177 | #else | |
178 | wxGenericPageSetupDialog *genericPageSetupDialog = new wxGenericPageSetupDialog(GetParent(), & m_pageSetupData); | |
179 | int ret = genericPageSetupDialog->ShowModal(); | |
180 | m_pageSetupData = genericPageSetupDialog->GetPageSetupData(); | |
181 | genericPageSetupDialog->Close(TRUE); | |
182 | return ret; | |
183 | #endif | |
184 | } | |
185 |