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