Compilation fix for wxCStrData handling.
[wxWidgets.git] / src / os2 / dcprint.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/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 #if wxUSE_PRINTING_ARCHITECTURE
16
17 #include "wx/dcprint.h"
18
19 #define INCL_DEV
20 #define INCL_GPI
21 #define INCL_PM
22 #include<os2.h>
23
24 #ifndef WX_PRECOMP
25 #include "wx/app.h"
26 #include "wx/math.h"
27 #include "wx/string.h"
28 #include "wx/log.h"
29 #include "wx/window.h"
30 #endif
31
32 #include "wx/os2/private.h"
33
34 IMPLEMENT_CLASS(wxPrinterDC, wxDC)
35
36
37 // This form is deprecated
38 wxPrinterDC::wxPrinterDC( const wxString& rsDriverName,
39 const wxString& rsDeviceName,
40 const wxString& rsFile,
41 bool bInteractive,
42 int nOrientation )
43 {
44 DEVOPENSTRUC vDevOpen = { rsDeviceName.char_str()
45 ,rsDriverName.char_str()
46 ,NULL
47 ,NULL
48 ,NULL
49 ,NULL
50 ,NULL
51 ,NULL
52 ,NULL
53 };
54
55 m_isInteractive = bInteractive;
56
57 if (!rsFile.IsNull() && !rsFile.empty())
58 m_printData.SetFilename(rsFile);
59
60 /*
61 Implement PM's version of this
62 #if wxUSE_COMMON_DIALOGS
63 if (interactive)
64 {
65 PRINTDLG pd;
66
67 pd.lStructSize = sizeof( PRINTDLG );
68 pd.hwndOwner=(HWND) NULL;
69 pd.hDevMode=(HANDLE)NULL;
70 pd.hDevNames=(HANDLE)NULL;
71 pd.Flags=PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS;
72 pd.nFromPage=0;
73 pd.nToPage=0;
74 pd.nMinPage=0;
75 pd.nMaxPage=0;
76 pd.nCopies=1;
77 pd.hInstance=(HINSTANCE)NULL;
78
79 if ( PrintDlg( &pd ) != 0 )
80 {
81 m_hDC = (WXHDC) pd.hDC;
82 m_ok = true;
83 }
84 else
85 {
86 m_ok = false;
87 return;
88 }
89 }
90 else
91 #endif
92 */
93 if ( !rsDriverName.empty() &&
94 !rsDeviceName.empty() &&
95 !rsFile.empty() )
96 {
97 m_hDC = (WXHDC) ::DevOpenDC( vHabmain
98 ,OD_QUEUED
99 ,"*"
100 ,5L
101 ,(PDEVOPENDATA)&vDevOpen
102 ,NULLHANDLE
103 );
104 m_ok = m_hDC ? true: false;
105 }
106 else
107 {
108 wxPrintData vPrintData;
109
110 vPrintData.SetOrientation(nOrientation);
111 m_hDC = wxGetPrinterDC(vPrintData);
112 m_ok = m_hDC ? true: false;
113 }
114
115 if (m_hDC)
116 {
117 // int width = GetDeviceCaps(m_hDC, VERTRES);
118 // int height = GetDeviceCaps(m_hDC, HORZRES);
119 SetMapMode(wxMM_TEXT);
120 }
121 SetBrush(*wxBLACK_BRUSH);
122 SetPen(*wxBLACK_PEN);
123 } // end of wxPrinterDC::wxPrinterDC
124
125 wxPrinterDC::wxPrinterDC( const wxPrintData& rPrintData )
126 {
127 m_printData = rPrintData;
128 m_isInteractive = false;
129 m_hDC = wxGetPrinterDC(rPrintData);
130 m_ok = (m_hDC != 0);
131 if (m_hDC)
132 SetMapMode(wxMM_TEXT);
133 SetBrush(*wxBLACK_BRUSH);
134 SetPen(*wxBLACK_PEN);
135 } // end of wxPrinterDC::wxPrinterDC
136
137 wxPrinterDC::wxPrinterDC( WXHDC hTheDC )
138 {
139 m_isInteractive = false;
140 m_hDC = hTheDC;
141 m_ok = true;
142 if (m_hDC)
143 {
144 SetMapMode(wxMM_TEXT);
145 }
146 SetBrush(*wxBLACK_BRUSH);
147 SetPen(*wxBLACK_PEN);
148 } // end of wxPrinterDC::wxPrinterDC
149
150 void wxPrinterDC::Init()
151 {
152 if (m_hDC)
153 {
154 SetMapMode(wxMM_TEXT);
155
156 SetBrush(*wxBLACK_BRUSH);
157 SetPen(*wxBLACK_PEN);
158 }
159 } // end of wxPrinterDC::Init
160
161 bool wxPrinterDC::StartDoc(const wxString& WXUNUSED(rsMessage))
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.empty())
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(wxT("wxDC::StartDoc failed with error: %d\n"), lastError);
203 }
204 #endif
205 return (ret > 0);
206 */
207 return true;
208 } // end of wxPrinterDC::StartDoc
209
210 void wxPrinterDC::EndDoc()
211 {
212 // if (m_hDC) ::EndDoc((HDC) m_hDC);
213 } // end of wxPrinterDC::EndDoc
214
215 void wxPrinterDC::StartPage()
216 {
217 // if (m_hDC)
218 // ::StartPage((HDC) m_hDC);
219 } // end of wxPrinterDC::StartPage
220
221 void wxPrinterDC::EndPage()
222 {
223 // if (m_hDC)
224 // ::EndPage((HDC) m_hDC);
225 } // end of wxPrinterDC::EndPage
226
227 wxRect wxPrinterDC::GetPaperRect()
228 {
229 // Use page rect if we can't get paper rect.
230 wxCoord w, h;
231 GetSize(&w, &h);
232 return wxRect(0, 0, w, h);
233 }
234
235 #if 0
236 // Returns default device and port names
237 static bool wxGetDefaultDeviceName( wxString& rsDeviceName, wxString& rsPortName )
238 {
239 rsDeviceName = wxEmptyString;
240 /*
241 LPDEVNAMES lpDevNames;
242 LPSTR lpszDriverName;
243 LPSTR lpszDeviceName;
244 LPSTR lpszPortName;
245
246 PRINTDLG pd;
247
248 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
249 #ifdef __GNUWIN32__
250 pd.lStructSize = 66; // sizeof(PRINTDLG);
251 #else
252 pd.lStructSize = sizeof(PRINTDLG);
253 #endif
254
255 pd.hwndOwner = (HWND)NULL;
256 pd.hDevMode = NULL; // Will be created by PrintDlg
257 pd.hDevNames = NULL; // Ditto
258 pd.Flags = PD_RETURNDEFAULT;
259 pd.nCopies = 1;
260
261 if (!PrintDlg((LPPRINTDLG)&pd))
262 {
263 if ( pd.hDevMode )
264 GlobalFree(pd.hDevMode);
265 if (pd.hDevNames)
266 GlobalFree(pd.hDevNames);
267
268 return false;
269 }
270
271 if (pd.hDevNames)
272 {
273 lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
274 lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
275 lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
276 lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;
277 GlobalUnlock(pd.hDevNames);
278 GlobalFree(pd.hDevNames);
279 pd.hDevNames=NULL;
280
281 deviceName = lpszDeviceName;
282 portName = lpszPortName;
283 }
284
285 if (pd.hDevMode)
286 {
287 GlobalFree(pd.hDevMode);
288 pd.hDevMode=NULL;
289 }
290 return !deviceName.empty();
291 */
292 return true;
293 } // end of wxGetDefaultDeviceName
294 #endif
295
296 // Gets an HDC for the specified printer configuration
297 WXHDC WXDLLEXPORT wxGetPrinterDC( const wxPrintData& WXUNUSED(rPrintDataConst) )
298 {
299 HDC hDC = NULLHANDLE;
300 /*
301 wxPrintData printData = printDataConst;
302 printData.ConvertToNative();
303
304 wxChar* driverName = (wxChar*) NULL;
305
306 wxString devNameStr = printData.GetPrinterName();
307 wxChar* deviceName;
308 wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32
309
310 if (devNameStr.empty())
311 deviceName = (wxChar*) NULL;
312 else
313 deviceName = WXSTRINGCAST devNameStr;
314
315 LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
316
317 HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
318
319 if ( hDevMode )
320 lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
321
322 if (devNameStr.empty())
323 {
324 // Retrieve the default device name
325 wxString portName;
326 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
327
328 wxASSERT_MSG( ret, wxT("Could not get default device name.") );
329
330 deviceName = WXSTRINGCAST devNameStr;
331 }
332
333 #ifdef __WIN32__
334 HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
335 #else
336 HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
337 #endif
338
339 if (hDevMode && lpDevMode)
340 GlobalUnlock(hDevMode);
341 */
342 return (WXHDC) hDC;
343 } // end of wxGetPrinterDC
344
345 void wxPrinterDC::DoDrawBitmap( const wxBitmap& rBmp,
346 wxCoord WXUNUSED(vX),
347 wxCoord WXUNUSED(vY),
348 bool WXUNUSED(bUseMask))
349 {
350 wxCHECK_RET( rBmp.Ok(), _T("invalid bitmap in wxPrinterDC::DrawBitmap") );
351
352 // int nWidth = rBmp.GetWidth();
353 // int nHeight = rBmp.GetHeight();
354
355 // TODO:
356
357 } // end of wxPrinterDC::DoDrawBitmap
358
359 bool wxPrinterDC::DoBlit( wxCoord WXUNUSED(vXdest),
360 wxCoord WXUNUSED(vYdest),
361 wxCoord WXUNUSED(vWidth),
362 wxCoord WXUNUSED(vHeight),
363 wxDC* WXUNUSED(pSource),
364 wxCoord WXUNUSED(vXsrc),
365 wxCoord WXUNUSED(vYsrc),
366 int WXUNUSED(nRop),
367 bool WXUNUSED(bUseMask),
368 wxCoord WXUNUSED(xsrcMask),
369 wxCoord WXUNUSED(ysrcMask) )
370 {
371 bool bSuccess = true;
372
373 // TODO:
374
375 return bSuccess;
376 } // end of wxPrintDC::DoBlit
377
378 #endif //wxUSE_PRINTING_ARCHITECTURE