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