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