]>
Commit | Line | Data |
---|---|---|
27476f73 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dcprint.cpp | |
3 | // Purpose: wxPrinterDC class | |
fb46a9a6 | 4 | // Author: David Webster |
27476f73 | 5 | // Modified by: |
fb46a9a6 | 6 | // Created: 10/14/99 |
27476f73 | 7 | // RCS-ID: $Id$ |
fb46a9a6 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
27476f73 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
27476f73 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
fb46a9a6 DW |
14 | |
15 | #define INCL_DEV | |
16 | #define INCL_GPI | |
17 | #define INCL_PM | |
18 | #include<os2.h> | |
19 | ||
27476f73 DW |
20 | #ifndef WX_PRECOMP |
21 | #endif | |
22 | ||
23 | #include "wx/string.h" | |
24 | #include "wx/log.h" | |
25 | #include "wx/window.h" | |
26 | #include "wx/os2/private.h" | |
27 | #include "wx/dcprint.h" | |
28 | #include "math.h" | |
29 | ||
30 | #if !USE_SHARED_LIBRARY | |
31 | IMPLEMENT_CLASS(wxPrinterDC, wxDC) | |
32 | #endif | |
33 | ||
27476f73 DW |
34 | |
35 | // This form is deprecated | |
36 | wxPrinterDC::wxPrinterDC(const wxString& driver_name, const wxString& device_name, const wxString& file, bool interactive, int orientation) | |
37 | { | |
38 | LONG lType; | |
39 | HAB hab; | |
40 | DEVOPENSTRUC devOpen = { (char*)device_name.c_str() | |
41 | ,(char*)driver_name.c_str() | |
42 | ,NULL | |
43 | ,NULL | |
44 | ,NULL | |
45 | ,NULL | |
46 | ,NULL | |
47 | ,NULL | |
48 | ,NULL | |
49 | }; | |
50 | ||
51 | m_isInteractive = interactive; | |
52 | ||
223d09f6 | 53 | if (!file.IsNull() && file != wxT("")) |
27476f73 DW |
54 | m_printData.SetFilename(file); |
55 | ||
56 | /* | |
57 | Implement PM's version of this | |
58 | #if wxUSE_COMMON_DIALOGS | |
59 | if (interactive) | |
60 | { | |
61 | PRINTDLG pd; | |
62 | ||
63 | pd.lStructSize = sizeof( PRINTDLG ); | |
64 | pd.hwndOwner=(HWND) NULL; | |
65 | pd.hDevMode=(HANDLE)NULL; | |
66 | pd.hDevNames=(HANDLE)NULL; | |
67 | pd.Flags=PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS; | |
68 | pd.nFromPage=0; | |
69 | pd.nToPage=0; | |
70 | pd.nMinPage=0; | |
71 | pd.nMaxPage=0; | |
72 | pd.nCopies=1; | |
73 | pd.hInstance=(HINSTANCE)NULL; | |
74 | ||
75 | if ( PrintDlg( &pd ) != 0 ) | |
76 | { | |
77 | m_hDC = (WXHDC) pd.hDC; | |
78 | m_ok = TRUE; | |
79 | } | |
80 | else | |
81 | { | |
82 | m_ok = FALSE; | |
83 | return; | |
84 | } | |
85 | ||
86 | // m_dontDelete = TRUE; | |
87 | } | |
88 | else | |
89 | #endif | |
90 | */ | |
223d09f6 KB |
91 | if ((!driver_name.IsNull() && driver_name != wxT("")) && |
92 | (!device_name.IsNull() && device_name != wxT("")) && | |
93 | (!file.IsNull() && file != wxT(""))) | |
27476f73 DW |
94 | { |
95 | m_hDC = (WXHDC) ::DevOpenDC( hab | |
96 | ,OD_QUEUED | |
97 | ,"*" | |
98 | ,5L | |
99 | ,(PDEVOPENDATA)&devOpen | |
100 | ,NULLHANDLE | |
101 | ); | |
102 | m_ok = m_hDC ? TRUE: FALSE; | |
103 | } | |
104 | else | |
105 | { | |
106 | wxPrintData printData; | |
107 | printData.SetOrientation(orientation); | |
108 | m_hDC = wxGetPrinterDC(printData); | |
109 | m_ok = m_hDC ? TRUE: FALSE; | |
110 | } | |
111 | ||
112 | if (m_hDC) | |
113 | { | |
114 | // int width = GetDeviceCaps(m_hDC, VERTRES); | |
115 | // int height = GetDeviceCaps(m_hDC, HORZRES); | |
116 | SetMapMode(wxMM_TEXT); | |
117 | } | |
118 | SetBrush(*wxBLACK_BRUSH); | |
119 | SetPen(*wxBLACK_PEN); | |
120 | } | |
121 | ||
122 | wxPrinterDC::wxPrinterDC(const wxPrintData& printData) | |
123 | { | |
124 | m_printData = printData; | |
125 | ||
126 | m_isInteractive = FALSE; | |
127 | ||
128 | m_hDC = wxGetPrinterDC(printData); | |
129 | m_ok = (m_hDC != 0); | |
130 | ||
131 | if (m_hDC) | |
132 | SetMapMode(wxMM_TEXT); | |
133 | ||
134 | SetBrush(*wxBLACK_BRUSH); | |
135 | SetPen(*wxBLACK_PEN); | |
136 | } | |
137 | ||
138 | ||
139 | wxPrinterDC::wxPrinterDC(WXHDC theDC) | |
140 | { | |
141 | m_isInteractive = FALSE; | |
142 | ||
143 | m_hDC = theDC; | |
144 | m_ok = TRUE; | |
145 | if (m_hDC) | |
146 | { | |
147 | // int width = GetDeviceCaps(m_hDC, VERTRES); | |
148 | // int height = GetDeviceCaps(m_hDC, HORZRES); | |
149 | SetMapMode(wxMM_TEXT); | |
150 | } | |
151 | SetBrush(*wxBLACK_BRUSH); | |
152 | SetPen(*wxBLACK_PEN); | |
153 | } | |
154 | ||
155 | wxPrinterDC::~wxPrinterDC(void) | |
156 | { | |
157 | } | |
158 | ||
159 | bool wxPrinterDC::StartDoc(const wxString& message) | |
160 | { | |
161 | /* TODO: PM's implementation | |
162 | DOCINFO docinfo; | |
163 | docinfo.cbSize = sizeof(DOCINFO); | |
164 | docinfo.lpszDocName = (const wxChar*)message; | |
165 | ||
166 | wxString filename(m_printData.GetFilename()); | |
167 | ||
168 | if (filename.IsEmpty()) | |
169 | docinfo.lpszOutput = NULL; | |
170 | else | |
171 | docinfo.lpszOutput = (const wxChar *) filename; | |
172 | ||
173 | #if defined(__WIN95__) | |
174 | docinfo.lpszDatatype = NULL; | |
175 | docinfo.fwType = 0; | |
176 | #endif | |
177 | ||
178 | if (!m_hDC) | |
179 | return FALSE; | |
180 | ||
181 | int ret = | |
182 | #ifndef __WIN32__ | |
183 | ::StartDoc((HDC) m_hDC, &docinfo); | |
184 | #else | |
185 | #ifdef UNICODE | |
186 | ::StartDocW((HDC) m_hDC, &docinfo); | |
187 | #else | |
188 | #ifdef __TWIN32__ | |
189 | ::StartDoc((HDC) m_hDC, &docinfo); | |
190 | #else | |
191 | ::StartDocA((HDC) m_hDC, &docinfo); | |
192 | #endif | |
193 | #endif | |
194 | #endif | |
195 | ||
196 | #ifndef __WIN16__ | |
197 | if (ret <= 0) | |
198 | { | |
199 | DWORD lastError = GetLastError(); | |
223d09f6 | 200 | wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError); |
27476f73 DW |
201 | } |
202 | #endif | |
203 | return (ret > 0); | |
204 | */ | |
205 | return(TRUE); | |
206 | } | |
207 | ||
208 | void wxPrinterDC::EndDoc(void) | |
209 | { | |
210 | // if (m_hDC) ::EndDoc((HDC) m_hDC); | |
211 | } | |
212 | ||
213 | void wxPrinterDC::StartPage(void) | |
214 | { | |
215 | // if (m_hDC) | |
216 | // ::StartPage((HDC) m_hDC); | |
217 | } | |
218 | ||
219 | void wxPrinterDC::EndPage(void) | |
220 | { | |
221 | // if (m_hDC) | |
222 | // ::EndPage((HDC) m_hDC); | |
223 | } | |
224 | ||
225 | // Returns default device and port names | |
226 | static bool wxGetDefaultDeviceName(wxString& deviceName, wxString& portName) | |
227 | { | |
228 | deviceName = ""; | |
229 | /* | |
230 | LPDEVNAMES lpDevNames; | |
231 | LPSTR lpszDriverName; | |
232 | LPSTR lpszDeviceName; | |
233 | LPSTR lpszPortName; | |
234 | ||
235 | PRINTDLG pd; | |
236 | ||
237 | // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68 | |
238 | #ifdef __GNUWIN32__ | |
239 | pd.lStructSize = 66; // sizeof(PRINTDLG); | |
240 | #else | |
241 | pd.lStructSize = sizeof(PRINTDLG); | |
242 | #endif | |
243 | ||
244 | pd.hwndOwner = (HWND)NULL; | |
245 | pd.hDevMode = NULL; // Will be created by PrintDlg | |
246 | pd.hDevNames = NULL; // Ditto | |
247 | pd.Flags = PD_RETURNDEFAULT; | |
248 | pd.nCopies = 1; | |
249 | ||
250 | if (!PrintDlg((LPPRINTDLG)&pd)) | |
251 | { | |
252 | if ( pd.hDevMode ) | |
253 | GlobalFree(pd.hDevMode); | |
254 | if (pd.hDevNames) | |
255 | GlobalFree(pd.hDevNames); | |
256 | ||
257 | return FALSE; | |
258 | } | |
259 | ||
260 | if (pd.hDevNames) | |
261 | { | |
262 | lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames); | |
263 | lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset; | |
264 | lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset; | |
265 | lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset; | |
266 | GlobalUnlock(pd.hDevNames); | |
267 | GlobalFree(pd.hDevNames); | |
268 | pd.hDevNames=NULL; | |
269 | ||
270 | deviceName = lpszDeviceName; | |
271 | portName = lpszPortName; | |
272 | } | |
273 | ||
274 | if (pd.hDevMode) | |
275 | { | |
276 | GlobalFree(pd.hDevMode); | |
277 | pd.hDevMode=NULL; | |
278 | } | |
223d09f6 | 279 | return ( deviceName != wxT("") ); |
27476f73 DW |
280 | */ |
281 | return(TRUE); | |
282 | } | |
283 | ||
284 | // Gets an HDC for the specified printer configuration | |
285 | WXHDC WXDLLEXPORT wxGetPrinterDC(const wxPrintData& printDataConst) | |
286 | { | |
287 | HDC hDC; | |
288 | /* | |
289 | wxPrintData printData = printDataConst; | |
290 | printData.ConvertToNative(); | |
291 | ||
292 | wxChar* driverName = (wxChar*) NULL; | |
293 | ||
294 | wxString devNameStr = printData.GetPrinterName(); | |
295 | wxChar* deviceName; | |
296 | wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32 | |
297 | ||
223d09f6 | 298 | if (devNameStr == wxT("")) |
27476f73 DW |
299 | deviceName = (wxChar*) NULL; |
300 | else | |
301 | deviceName = WXSTRINGCAST devNameStr; | |
302 | ||
303 | LPDEVMODE lpDevMode = (LPDEVMODE) NULL; | |
304 | ||
305 | HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData(); | |
306 | ||
307 | if ( hDevMode ) | |
308 | lpDevMode = (DEVMODE*) GlobalLock(hDevMode); | |
309 | ||
223d09f6 | 310 | if (devNameStr == wxT("")) |
27476f73 DW |
311 | { |
312 | // Retrieve the default device name | |
313 | wxString portName; | |
314 | bool ret = wxGetDefaultDeviceName(devNameStr, portName); | |
315 | ||
223d09f6 | 316 | wxASSERT_MSG( ret, wxT("Could not get default device name.") ); |
27476f73 DW |
317 | |
318 | deviceName = WXSTRINGCAST devNameStr; | |
319 | } | |
320 | ||
321 | #ifdef __WIN32__ | |
322 | HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode); | |
323 | #else | |
324 | HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode); | |
325 | #endif | |
326 | ||
327 | if (hDevMode && lpDevMode) | |
328 | GlobalUnlock(hDevMode); | |
329 | */ | |
330 | return (WXHDC) hDC; | |
331 | } | |
332 |