]> git.saurik.com Git - wxWidgets.git/blob - src/os2/dcprint.cpp
Test commit
[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 #define INCL_DEV
16 #define INCL_GPI
17 #define INCL_PM
18 #include<os2.h>
19
20 #ifndef WX_PRECOMP
21 #include "wx/app.h"
22 #include "wx/math.h"
23 #endif
24
25 #include "wx/string.h"
26 #include "wx/log.h"
27 #include "wx/window.h"
28 #include "wx/os2/private.h"
29 #include "wx/dcprint.h"
30
31 #if wxUSE_PRINTING_ARCHITECTURE
32
33 IMPLEMENT_CLASS(wxPrinterDC, wxDC)
34
35
36 // This form is deprecated
37 wxPrinterDC::wxPrinterDC( const wxString& rsDriverName,
38 const wxString& rsDeviceName,
39 const wxString& rsFile,
40 bool bInteractive,
41 int nOrientation )
42 {
43 DEVOPENSTRUC vDevOpen = { (char*)rsDeviceName.c_str()
44 ,(char*)rsDriverName.c_str()
45 ,NULL
46 ,NULL
47 ,NULL
48 ,NULL
49 ,NULL
50 ,NULL
51 ,NULL
52 };
53
54 m_isInteractive = bInteractive;
55
56 if (!rsFile.IsNull() && !rsFile.empty())
57 m_printData.SetFilename(rsFile);
58
59 /*
60 Implement PM's version of this
61 #if wxUSE_COMMON_DIALOGS
62 if (interactive)
63 {
64 PRINTDLG pd;
65
66 pd.lStructSize = sizeof( PRINTDLG );
67 pd.hwndOwner=(HWND) NULL;
68 pd.hDevMode=(HANDLE)NULL;
69 pd.hDevNames=(HANDLE)NULL;
70 pd.Flags=PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS;
71 pd.nFromPage=0;
72 pd.nToPage=0;
73 pd.nMinPage=0;
74 pd.nMaxPage=0;
75 pd.nCopies=1;
76 pd.hInstance=(HINSTANCE)NULL;
77
78 if ( PrintDlg( &pd ) != 0 )
79 {
80 m_hDC = (WXHDC) pd.hDC;
81 m_ok = true;
82 }
83 else
84 {
85 m_ok = false;
86 return;
87 }
88 }
89 else
90 #endif
91 */
92 if ( !rsDriverName.empty() &&
93 !rsDeviceName.empty() &&
94 !rsFile.empty() )
95 {
96 m_hDC = (WXHDC) ::DevOpenDC( vHabmain
97 ,OD_QUEUED
98 ,"*"
99 ,5L
100 ,(PDEVOPENDATA)&vDevOpen
101 ,NULLHANDLE
102 );
103 m_ok = m_hDC ? true: false;
104 }
105 else
106 {
107 wxPrintData vPrintData;
108
109 vPrintData.SetOrientation(nOrientation);
110 m_hDC = wxGetPrinterDC(vPrintData);
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 } // end of wxPrinterDC::wxPrinterDC
123
124 wxPrinterDC::wxPrinterDC( const wxPrintData& rPrintData )
125 {
126 m_printData = rPrintData;
127 m_isInteractive = false;
128 m_hDC = wxGetPrinterDC(rPrintData);
129 m_ok = (m_hDC != 0);
130 if (m_hDC)
131 SetMapMode(wxMM_TEXT);
132 SetBrush(*wxBLACK_BRUSH);
133 SetPen(*wxBLACK_PEN);
134 } // end of wxPrinterDC::wxPrinterDC
135
136 wxPrinterDC::wxPrinterDC( WXHDC hTheDC )
137 {
138 m_isInteractive = false;
139 m_hDC = hTheDC;
140 m_ok = true;
141 if (m_hDC)
142 {
143 SetMapMode(wxMM_TEXT);
144 }
145 SetBrush(*wxBLACK_BRUSH);
146 SetPen(*wxBLACK_PEN);
147 } // end of wxPrinterDC::wxPrinterDC
148
149 void wxPrinterDC::Init()
150 {
151 if (m_hDC)
152 {
153 SetMapMode(wxMM_TEXT);
154
155 SetBrush(*wxBLACK_BRUSH);
156 SetPen(*wxBLACK_PEN);
157 }
158 } // end of wxPrinterDC::Init
159
160 bool wxPrinterDC::StartDoc(const wxString& WXUNUSED(rsMessage))
161 {
162 /* TODO: PM's implementation
163 DOCINFO docinfo;
164 docinfo.cbSize = sizeof(DOCINFO);
165 docinfo.lpszDocName = (const wxChar*)message;
166
167 wxString filename(m_printData.GetFilename());
168
169 if (filename.empty())
170 docinfo.lpszOutput = NULL;
171 else
172 docinfo.lpszOutput = (const wxChar *) filename;
173
174 #if defined(__WIN95__)
175 docinfo.lpszDatatype = NULL;
176 docinfo.fwType = 0;
177 #endif
178
179 if (!m_hDC)
180 return false;
181
182 int ret =
183 #ifndef __WIN32__
184 ::StartDoc((HDC) m_hDC, &docinfo);
185 #else
186 #ifdef UNICODE
187 ::StartDocW((HDC) m_hDC, &docinfo);
188 #else
189 #ifdef __TWIN32__
190 ::StartDoc((HDC) m_hDC, &docinfo);
191 #else
192 ::StartDocA((HDC) m_hDC, &docinfo);
193 #endif
194 #endif
195 #endif
196
197 #ifndef __WIN16__
198 if (ret <= 0)
199 {
200 DWORD lastError = GetLastError();
201 wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError);
202 }
203 #endif
204 return (ret > 0);
205 */
206 return true;
207 } // end of wxPrinterDC::StartDoc
208
209 void wxPrinterDC::EndDoc()
210 {
211 // if (m_hDC) ::EndDoc((HDC) m_hDC);
212 } // end of wxPrinterDC::EndDoc
213
214 void wxPrinterDC::StartPage()
215 {
216 // if (m_hDC)
217 // ::StartPage((HDC) m_hDC);
218 } // end of wxPrinterDC::StartPage
219
220 void wxPrinterDC::EndPage()
221 {
222 // if (m_hDC)
223 // ::EndPage((HDC) m_hDC);
224 } // end of wxPrinterDC::EndPage
225 #if 0
226 // Returns default device and port names
227 static bool wxGetDefaultDeviceName( wxString& rsDeviceName, wxString& rsPortName )
228 {
229 rsDeviceName = wxEmptyString;
230 /*
231 LPDEVNAMES lpDevNames;
232 LPSTR lpszDriverName;
233 LPSTR lpszDeviceName;
234 LPSTR lpszPortName;
235
236 PRINTDLG pd;
237
238 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
239 #ifdef __GNUWIN32__
240 pd.lStructSize = 66; // sizeof(PRINTDLG);
241 #else
242 pd.lStructSize = sizeof(PRINTDLG);
243 #endif
244
245 pd.hwndOwner = (HWND)NULL;
246 pd.hDevMode = NULL; // Will be created by PrintDlg
247 pd.hDevNames = NULL; // Ditto
248 pd.Flags = PD_RETURNDEFAULT;
249 pd.nCopies = 1;
250
251 if (!PrintDlg((LPPRINTDLG)&pd))
252 {
253 if ( pd.hDevMode )
254 GlobalFree(pd.hDevMode);
255 if (pd.hDevNames)
256 GlobalFree(pd.hDevNames);
257
258 return false;
259 }
260
261 if (pd.hDevNames)
262 {
263 lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
264 lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
265 lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
266 lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;
267 GlobalUnlock(pd.hDevNames);
268 GlobalFree(pd.hDevNames);
269 pd.hDevNames=NULL;
270
271 deviceName = lpszDeviceName;
272 portName = lpszPortName;
273 }
274
275 if (pd.hDevMode)
276 {
277 GlobalFree(pd.hDevMode);
278 pd.hDevMode=NULL;
279 }
280 return ( deviceName != wxT("") );
281 */
282 return true;
283 } // end of wxGetDefaultDeviceName
284 #endif
285
286 // Gets an HDC for the specified printer configuration
287 WXHDC WXDLLEXPORT wxGetPrinterDC( const wxPrintData& WXUNUSED(rPrintDataConst) )
288 {
289 HDC hDC = NULLHANDLE;
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.empty())
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.empty())
313 {
314 // Retrieve the default device name
315 wxString portName;
316 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
317
318 wxASSERT_MSG( ret, wxT("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 } // end of wxGetPrinterDC
334
335 void wxPrinterDC::DoDrawBitmap( const wxBitmap& rBmp,
336 wxCoord WXUNUSED(vX),
337 wxCoord WXUNUSED(vY),
338 bool WXUNUSED(bUseMask))
339 {
340 wxCHECK_RET( rBmp.Ok(), _T("invalid bitmap in wxPrinterDC::DrawBitmap") );
341
342 // int nWidth = rBmp.GetWidth();
343 // int nHeight = rBmp.GetHeight();
344
345 // TODO:
346
347 } // end of wxPrinterDC::DoDrawBitmap
348
349 bool wxPrinterDC::DoBlit( wxCoord WXUNUSED(vXdest),
350 wxCoord WXUNUSED(vYdest),
351 wxCoord WXUNUSED(vWidth),
352 wxCoord WXUNUSED(vHeight),
353 wxDC* WXUNUSED(pSource),
354 wxCoord WXUNUSED(vXsrc),
355 wxCoord WXUNUSED(vYsrc),
356 int WXUNUSED(nRop),
357 bool WXUNUSED(bUseMask),
358 wxCoord WXUNUSED(xsrcMask),
359 wxCoord WXUNUSED(ysrcMask) )
360 {
361 bool bSuccess = true;
362
363 // TODO:
364
365 return bSuccess;
366 } // end of wxPrintDC::DoBlit
367
368 #endif //wxUSE_PRINTING_ARCHITECTURE