]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/os2/dcprint.cpp
Include wx/app.h according to precompiled headers of wx/wx.h (with other minor cleaning).
[wxWidgets.git] / src / os2 / dcprint.cpp
... / ...
CommitLineData
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#define INCL_DEV
18#define INCL_GPI
19#define INCL_PM
20#include<os2.h>
21
22#include "wx/dcprint.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#endif
30
31#include "wx/window.h"
32#include "wx/os2/private.h"
33
34IMPLEMENT_CLASS(wxPrinterDC, wxDC)
35
36
37// This form is deprecated
38wxPrinterDC::wxPrinterDC( const wxString& rsDriverName,
39 const wxString& rsDeviceName,
40 const wxString& rsFile,
41 bool bInteractive,
42 int nOrientation )
43{
44 DEVOPENSTRUC vDevOpen = { (char*)rsDeviceName.c_str()
45 ,(char*)rsDriverName.c_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
125wxPrinterDC::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
137wxPrinterDC::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
150void 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
161bool 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
210void wxPrinterDC::EndDoc()
211{
212// if (m_hDC) ::EndDoc((HDC) m_hDC);
213} // end of wxPrinterDC::EndDoc
214
215void wxPrinterDC::StartPage()
216{
217// if (m_hDC)
218// ::StartPage((HDC) m_hDC);
219} // end of wxPrinterDC::StartPage
220
221void wxPrinterDC::EndPage()
222{
223// if (m_hDC)
224// ::EndPage((HDC) m_hDC);
225} // end of wxPrinterDC::EndPage
226#if 0
227// Returns default device and port names
228static bool wxGetDefaultDeviceName( wxString& rsDeviceName, wxString& rsPortName )
229{
230 rsDeviceName = wxEmptyString;
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 != wxT("") );
282*/
283 return true;
284} // end of wxGetDefaultDeviceName
285#endif
286
287// Gets an HDC for the specified printer configuration
288WXHDC WXDLLEXPORT wxGetPrinterDC( const wxPrintData& WXUNUSED(rPrintDataConst) )
289{
290 HDC hDC = NULLHANDLE;
291/*
292 wxPrintData printData = printDataConst;
293 printData.ConvertToNative();
294
295 wxChar* driverName = (wxChar*) NULL;
296
297 wxString devNameStr = printData.GetPrinterName();
298 wxChar* deviceName;
299 wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32
300
301 if (devNameStr.empty())
302 deviceName = (wxChar*) NULL;
303 else
304 deviceName = WXSTRINGCAST devNameStr;
305
306 LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
307
308 HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
309
310 if ( hDevMode )
311 lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
312
313 if (devNameStr.empty())
314 {
315 // Retrieve the default device name
316 wxString portName;
317 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
318
319 wxASSERT_MSG( ret, wxT("Could not get default device name.") );
320
321 deviceName = WXSTRINGCAST devNameStr;
322 }
323
324#ifdef __WIN32__
325 HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
326#else
327 HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
328#endif
329
330 if (hDevMode && lpDevMode)
331 GlobalUnlock(hDevMode);
332*/
333 return (WXHDC) hDC;
334} // end of wxGetPrinterDC
335
336void wxPrinterDC::DoDrawBitmap( const wxBitmap& rBmp,
337 wxCoord WXUNUSED(vX),
338 wxCoord WXUNUSED(vY),
339 bool WXUNUSED(bUseMask))
340{
341 wxCHECK_RET( rBmp.Ok(), _T("invalid bitmap in wxPrinterDC::DrawBitmap") );
342
343// int nWidth = rBmp.GetWidth();
344// int nHeight = rBmp.GetHeight();
345
346 // TODO:
347
348} // end of wxPrinterDC::DoDrawBitmap
349
350bool wxPrinterDC::DoBlit( wxCoord WXUNUSED(vXdest),
351 wxCoord WXUNUSED(vYdest),
352 wxCoord WXUNUSED(vWidth),
353 wxCoord WXUNUSED(vHeight),
354 wxDC* WXUNUSED(pSource),
355 wxCoord WXUNUSED(vXsrc),
356 wxCoord WXUNUSED(vYsrc),
357 int WXUNUSED(nRop),
358 bool WXUNUSED(bUseMask),
359 wxCoord WXUNUSED(xsrcMask),
360 wxCoord WXUNUSED(ysrcMask) )
361{
362 bool bSuccess = true;
363
364 // TODO:
365
366 return bSuccess;
367} // end of wxPrintDC::DoBlit
368
369#endif //wxUSE_PRINTING_ARCHITECTURE