DC updates and an associated .Def file update
[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 #if wxUSE_PRINTING_ARCHITECTURE
31
32 IMPLEMENT_CLASS(wxPrinterDC, wxDC)
33
34
35 // This form is deprecated
36 wxPrinterDC::wxPrinterDC(
37 const wxString& rsDriverName
38 , const wxString& rsDeviceName
39 , const wxString& rsFile
40 , bool bInteractive
41 , int nOrientation
42 )
43 {
44 LONG lType = 0;
45 DEVOPENSTRUC vDevOpen = { (char*)rsDeviceName.c_str()
46 ,(char*)rsDriverName.c_str()
47 ,NULL
48 ,NULL
49 ,NULL
50 ,NULL
51 ,NULL
52 ,NULL
53 ,NULL
54 };
55
56 m_isInteractive = bInteractive;
57
58 if (!rsFile.IsNull() && rsFile != wxT(""))
59 m_printData.SetFilename(rsFile);
60
61 /*
62 Implement PM's version of this
63 #if wxUSE_COMMON_DIALOGS
64 if (interactive)
65 {
66 PRINTDLG pd;
67
68 pd.lStructSize = sizeof( PRINTDLG );
69 pd.hwndOwner=(HWND) NULL;
70 pd.hDevMode=(HANDLE)NULL;
71 pd.hDevNames=(HANDLE)NULL;
72 pd.Flags=PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS;
73 pd.nFromPage=0;
74 pd.nToPage=0;
75 pd.nMinPage=0;
76 pd.nMaxPage=0;
77 pd.nCopies=1;
78 pd.hInstance=(HINSTANCE)NULL;
79
80 if ( PrintDlg( &pd ) != 0 )
81 {
82 m_hDC = (WXHDC) pd.hDC;
83 m_ok = TRUE;
84 }
85 else
86 {
87 m_ok = FALSE;
88 return;
89 }
90
91 // m_dontDelete = TRUE;
92 }
93 else
94 #endif
95 */
96 if ((!rsDriverName.IsNull() && rsDriverName != wxT("")) &&
97 (!rsDeviceName.IsNull() && rsDeviceName != wxT("")) &&
98 (!rsFile.IsNull() && rsFile != wxT("")))
99 {
100 m_hDC = (WXHDC) ::DevOpenDC( vHabmain
101 ,OD_QUEUED
102 ,"*"
103 ,5L
104 ,(PDEVOPENDATA)&vDevOpen
105 ,NULLHANDLE
106 );
107 m_ok = m_hDC ? TRUE: FALSE;
108 }
109 else
110 {
111 wxPrintData vPrintData;
112
113 vPrintData.SetOrientation(nOrientation);
114 m_hDC = wxGetPrinterDC(vPrintData);
115 m_ok = m_hDC ? TRUE: FALSE;
116 }
117
118 if (m_hDC)
119 {
120 // int width = GetDeviceCaps(m_hDC, VERTRES);
121 // int height = GetDeviceCaps(m_hDC, HORZRES);
122 SetMapMode(wxMM_TEXT);
123 }
124 SetBrush(*wxBLACK_BRUSH);
125 SetPen(*wxBLACK_PEN);
126 } // end of wxPrinterDC::wxPrinterDC
127
128 wxPrinterDC::wxPrinterDC(
129 const wxPrintData& rPrintData
130 )
131 {
132 m_printData = rPrintData;
133 m_isInteractive = FALSE;
134 m_hDC = wxGetPrinterDC(rPrintData);
135 m_ok = (m_hDC != 0);
136 if (m_hDC)
137 SetMapMode(wxMM_TEXT);
138 SetBrush(*wxBLACK_BRUSH);
139 SetPen(*wxBLACK_PEN);
140 } // end of wxPrinterDC::wxPrinterDC
141
142 wxPrinterDC::wxPrinterDC(
143 WXHDC hTheDC
144 )
145 {
146 m_isInteractive = FALSE;
147 m_hDC = hTheDC;
148 m_ok = TRUE;
149 if (m_hDC)
150 {
151 SetMapMode(wxMM_TEXT);
152 }
153 SetBrush(*wxBLACK_BRUSH);
154 SetPen(*wxBLACK_PEN);
155 } // end of wxPrinterDC::wxPrinterDC
156
157 void wxPrinterDC::Init()
158 {
159 if (m_hDC)
160 {
161 SetMapMode(wxMM_TEXT);
162
163 SetBrush(*wxBLACK_BRUSH);
164 SetPen(*wxBLACK_PEN);
165 }
166 } // end of wxPrinterDC::Init
167
168 bool wxPrinterDC::StartDoc(
169 const wxString& rsMessage
170 )
171 {
172 /* TODO: PM's implementation
173 DOCINFO docinfo;
174 docinfo.cbSize = sizeof(DOCINFO);
175 docinfo.lpszDocName = (const wxChar*)message;
176
177 wxString filename(m_printData.GetFilename());
178
179 if (filename.IsEmpty())
180 docinfo.lpszOutput = NULL;
181 else
182 docinfo.lpszOutput = (const wxChar *) filename;
183
184 #if defined(__WIN95__)
185 docinfo.lpszDatatype = NULL;
186 docinfo.fwType = 0;
187 #endif
188
189 if (!m_hDC)
190 return FALSE;
191
192 int ret =
193 #ifndef __WIN32__
194 ::StartDoc((HDC) m_hDC, &docinfo);
195 #else
196 #ifdef UNICODE
197 ::StartDocW((HDC) m_hDC, &docinfo);
198 #else
199 #ifdef __TWIN32__
200 ::StartDoc((HDC) m_hDC, &docinfo);
201 #else
202 ::StartDocA((HDC) m_hDC, &docinfo);
203 #endif
204 #endif
205 #endif
206
207 #ifndef __WIN16__
208 if (ret <= 0)
209 {
210 DWORD lastError = GetLastError();
211 wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError);
212 }
213 #endif
214 return (ret > 0);
215 */
216 return(TRUE);
217 } // end of wxPrinterDC::StartDoc
218
219 void wxPrinterDC::EndDoc()
220 {
221 // if (m_hDC) ::EndDoc((HDC) m_hDC);
222 } // end of wxPrinterDC::EndDoc
223
224 void wxPrinterDC::StartPage()
225 {
226 // if (m_hDC)
227 // ::StartPage((HDC) m_hDC);
228 } // end of wxPrinterDC::StartPage
229
230 void wxPrinterDC::EndPage()
231 {
232 // if (m_hDC)
233 // ::EndPage((HDC) m_hDC);
234 } // end of wxPrinterDC::EndPage
235
236 // Returns default device and port names
237 static bool wxGetDefaultDeviceName(
238 wxString& rsDeviceName
239 , wxString& rsPortName
240 )
241 {
242 rsDeviceName = "";
243 /*
244 LPDEVNAMES lpDevNames;
245 LPSTR lpszDriverName;
246 LPSTR lpszDeviceName;
247 LPSTR lpszPortName;
248
249 PRINTDLG pd;
250
251 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
252 #ifdef __GNUWIN32__
253 pd.lStructSize = 66; // sizeof(PRINTDLG);
254 #else
255 pd.lStructSize = sizeof(PRINTDLG);
256 #endif
257
258 pd.hwndOwner = (HWND)NULL;
259 pd.hDevMode = NULL; // Will be created by PrintDlg
260 pd.hDevNames = NULL; // Ditto
261 pd.Flags = PD_RETURNDEFAULT;
262 pd.nCopies = 1;
263
264 if (!PrintDlg((LPPRINTDLG)&pd))
265 {
266 if ( pd.hDevMode )
267 GlobalFree(pd.hDevMode);
268 if (pd.hDevNames)
269 GlobalFree(pd.hDevNames);
270
271 return FALSE;
272 }
273
274 if (pd.hDevNames)
275 {
276 lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
277 lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
278 lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
279 lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;
280 GlobalUnlock(pd.hDevNames);
281 GlobalFree(pd.hDevNames);
282 pd.hDevNames=NULL;
283
284 deviceName = lpszDeviceName;
285 portName = lpszPortName;
286 }
287
288 if (pd.hDevMode)
289 {
290 GlobalFree(pd.hDevMode);
291 pd.hDevMode=NULL;
292 }
293 return ( deviceName != wxT("") );
294 */
295 return(TRUE);
296 } // end of wxGetDefaultDeviceName
297
298 // Gets an HDC for the specified printer configuration
299 WXHDC WXDLLEXPORT wxGetPrinterDC(
300 const wxPrintData& rPrintDataConst
301 )
302 {
303 HDC hDC = NULLHANDLE;
304 /*
305 wxPrintData printData = printDataConst;
306 printData.ConvertToNative();
307
308 wxChar* driverName = (wxChar*) NULL;
309
310 wxString devNameStr = printData.GetPrinterName();
311 wxChar* deviceName;
312 wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32
313
314 if (devNameStr == wxT(""))
315 deviceName = (wxChar*) NULL;
316 else
317 deviceName = WXSTRINGCAST devNameStr;
318
319 LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
320
321 HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
322
323 if ( hDevMode )
324 lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
325
326 if (devNameStr == wxT(""))
327 {
328 // Retrieve the default device name
329 wxString portName;
330 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
331
332 wxASSERT_MSG( ret, wxT("Could not get default device name.") );
333
334 deviceName = WXSTRINGCAST devNameStr;
335 }
336
337 #ifdef __WIN32__
338 HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
339 #else
340 HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
341 #endif
342
343 if (hDevMode && lpDevMode)
344 GlobalUnlock(hDevMode);
345 */
346 return (WXHDC) hDC;
347 } // end of wxGetPrinterDC
348
349 void wxPrinterDC::DoDrawBitmap(
350 const wxBitmap& rBmp
351 , wxCoord vX
352 , wxCoord vY
353 , bool bUseMask
354 )
355 {
356 wxCHECK_RET( rBmp.Ok(), _T("invalid bitmap in wxPrinterDC::DrawBitmap") );
357
358 int nWidth = rBmp.GetWidth();
359 int nHeight = rBmp.GetHeight();
360
361 // TODO:
362
363 } // end of wxPrinterDC::DoDrawBitmap
364
365 bool wxPrinterDC::DoBlit(
366 wxCoord vXdest
367 , wxCoord vYdest
368 , wxCoord vWidth
369 , wxCoord vHeight
370 , wxDC* pSource
371 , wxCoord vXsrc
372 , wxCoord vYsrc
373 , int nRop
374 , bool bUseMask
375 )
376 {
377 bool bSuccess = TRUE;
378
379 // TODO:
380
381 return bSuccess;
382 } // end of wxPrintDC::DoBlit
383
384
385 #endif //wxUSE_PRINTING_ARCHITECTURE