]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/os2/dcprint.cpp
simplify code so it always returns the same object
[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#include "wx/dcprint.h"
18#include "wx/os2/dcprint.h"
19
20#define INCL_DEV
21#define INCL_GPI
22#define INCL_PM
23#include<os2.h>
24
25#ifndef WX_PRECOMP
26 #include "wx/app.h"
27 #include "wx/math.h"
28 #include "wx/string.h"
29 #include "wx/log.h"
30 #include "wx/window.h"
31#endif
32
33#include "wx/os2/private.h"
34
35IMPLEMENT_ABSTRACT_CLASS(wxPrinterDCImpl, wxPMDCImpl)
36
37wxPrinterDCImpl::wxPrinterDCImpl( wxPrinterDC *owner, const wxPrintData& rPrintData ) :
38 wxPMDCImpl( owner )
39{
40 m_printData = rPrintData;
41 m_isInteractive = false;
42 m_hDC = wxGetPrinterDC(rPrintData);
43 m_ok = (m_hDC != 0);
44 if (m_hDC)
45 SetMapMode(wxMM_TEXT);
46 SetBrush(*wxBLACK_BRUSH);
47 SetPen(*wxBLACK_PEN);
48} // end of wxPrinterDC::wxPrinterDC
49
50wxPrinterDCImpl::wxPrinterDCImpl( wxPrinterDC *owner, WXHDC hTheDC ) :
51 wxPMDCImpl( owner )
52{
53 m_isInteractive = false;
54 m_hDC = hTheDC;
55 m_ok = true;
56 if (m_hDC)
57 {
58 SetMapMode(wxMM_TEXT);
59 }
60 SetBrush(*wxBLACK_BRUSH);
61 SetPen(*wxBLACK_PEN);
62} // end of wxPrinterDC::wxPrinterDC
63
64void wxPrinterDCImpl::Init()
65{
66 if (m_hDC)
67 {
68 SetMapMode(wxMM_TEXT);
69
70 SetBrush(*wxBLACK_BRUSH);
71 SetPen(*wxBLACK_PEN);
72 }
73} // end of wxPrinterDC::Init
74
75bool wxPrinterDCImpl::StartDoc(const wxString& WXUNUSED(rsMessage))
76{
77/* TODO: PM's implementation
78 DOCINFO docinfo;
79 docinfo.cbSize = sizeof(DOCINFO);
80 docinfo.lpszDocName = (const wxChar*)message;
81
82 wxString filename(m_printData.GetFilename());
83
84 if (filename.empty())
85 docinfo.lpszOutput = NULL;
86 else
87 docinfo.lpszOutput = (const wxChar *) filename;
88
89#if defined(__WIN95__)
90 docinfo.lpszDatatype = NULL;
91 docinfo.fwType = 0;
92#endif
93
94 if (!m_hDC)
95 return false;
96
97 int ret =
98#ifndef __WIN32__
99 ::StartDoc((HDC) m_hDC, &docinfo);
100#else
101#ifdef UNICODE
102 ::StartDocW((HDC) m_hDC, &docinfo);
103#else
104#ifdef __TWIN32__
105 ::StartDoc((HDC) m_hDC, &docinfo);
106#else
107 ::StartDocA((HDC) m_hDC, &docinfo);
108#endif
109#endif
110#endif
111
112#ifndef __WIN16__
113 if (ret <= 0)
114 {
115 DWORD lastError = GetLastError();
116 wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError);
117 }
118#endif
119 return (ret > 0);
120*/
121 return true;
122} // end of wxPrinterDC::StartDoc
123
124void wxPrinterDCImpl::EndDoc()
125{
126// if (m_hDC) ::EndDoc((HDC) m_hDC);
127} // end of wxPrinterDC::EndDoc
128
129void wxPrinterDCImpl::StartPage()
130{
131// if (m_hDC)
132// ::StartPage((HDC) m_hDC);
133} // end of wxPrinterDC::StartPage
134
135void wxPrinterDCImpl::EndPage()
136{
137// if (m_hDC)
138// ::EndPage((HDC) m_hDC);
139} // end of wxPrinterDC::EndPage
140
141wxRect wxPrinterDCImpl::GetPaperRect() const
142{
143 // Use page rect if we can't get paper rect.
144 wxCoord w, h;
145 GetSize(&w, &h);
146 return wxRect(0, 0, w, h);
147}
148
149#if 0
150// Returns default device and port names
151static bool wxGetDefaultDeviceName( wxString& rsDeviceName, wxString& rsPortName )
152{
153 rsDeviceName = wxEmptyString;
154/*
155 LPDEVNAMES lpDevNames;
156 LPSTR lpszDriverName;
157 LPSTR lpszDeviceName;
158 LPSTR lpszPortName;
159
160 PRINTDLG pd;
161
162 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
163#ifdef __GNUWIN32__
164 pd.lStructSize = 66; // sizeof(PRINTDLG);
165#else
166 pd.lStructSize = sizeof(PRINTDLG);
167#endif
168
169 pd.hwndOwner = (HWND)NULL;
170 pd.hDevMode = NULL; // Will be created by PrintDlg
171 pd.hDevNames = NULL; // Ditto
172 pd.Flags = PD_RETURNDEFAULT;
173 pd.nCopies = 1;
174
175 if (!PrintDlg((LPPRINTDLG)&pd))
176 {
177 if ( pd.hDevMode )
178 GlobalFree(pd.hDevMode);
179 if (pd.hDevNames)
180 GlobalFree(pd.hDevNames);
181
182 return false;
183 }
184
185 if (pd.hDevNames)
186 {
187 lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
188 lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
189 lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
190 lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;
191 GlobalUnlock(pd.hDevNames);
192 GlobalFree(pd.hDevNames);
193 pd.hDevNames=NULL;
194
195 deviceName = lpszDeviceName;
196 portName = lpszPortName;
197 }
198
199 if (pd.hDevMode)
200 {
201 GlobalFree(pd.hDevMode);
202 pd.hDevMode=NULL;
203 }
204 return !deviceName.empty();
205*/
206 return true;
207} // end of wxGetDefaultDeviceName
208#endif
209
210// Gets an HDC for the specified printer configuration
211WXHDC WXDLLEXPORT wxGetPrinterDC( const wxPrintData& WXUNUSED(rPrintDataConst) )
212{
213 HDC hDC = NULLHANDLE;
214/*
215 wxPrintData printData = printDataConst;
216 printData.ConvertToNative();
217
218 wxChar* driverName = NULL;
219
220 wxString devNameStr = printData.GetPrinterName();
221 wxChar* deviceName;
222 wxChar* portName = NULL; // Obsolete in WIN32
223
224 if (devNameStr.empty())
225 deviceName = NULL;
226 else
227 deviceName = WXSTRINGCAST devNameStr;
228
229 LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
230
231 HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
232
233 if ( hDevMode )
234 lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
235
236 if (devNameStr.empty())
237 {
238 // Retrieve the default device name
239 wxString portName;
240 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
241
242 wxASSERT_MSG( ret, wxT("Could not get default device name.") );
243
244 deviceName = WXSTRINGCAST devNameStr;
245 }
246
247#ifdef __WIN32__
248 HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
249#else
250 HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
251#endif
252
253 if (hDevMode && lpDevMode)
254 GlobalUnlock(hDevMode);
255*/
256 return (WXHDC) hDC;
257} // end of wxGetPrinterDC
258
259void wxPrinterDCImpl::DoDrawBitmap( const wxBitmap& rBmp,
260 wxCoord WXUNUSED(vX),
261 wxCoord WXUNUSED(vY),
262 bool WXUNUSED(bUseMask))
263{
264 wxCHECK_RET( rBmp.IsOk(), wxT("invalid bitmap in wxPrinterDC::DrawBitmap") );
265
266// int nWidth = rBmp.GetWidth();
267// int nHeight = rBmp.GetHeight();
268
269 // TODO:
270
271} // end of wxPrinterDC::DoDrawBitmap
272
273bool wxPrinterDCImpl::DoBlit( wxCoord WXUNUSED(vXdest),
274 wxCoord WXUNUSED(vYdest),
275 wxCoord WXUNUSED(vWidth),
276 wxCoord WXUNUSED(vHeight),
277 wxDC* WXUNUSED(pSource),
278 wxCoord WXUNUSED(vXsrc),
279 wxCoord WXUNUSED(vYsrc),
280 wxRasterOperationMode WXUNUSED(nRop),
281 bool WXUNUSED(bUseMask),
282 wxCoord WXUNUSED(xsrcMask),
283 wxCoord WXUNUSED(ysrcMask) )
284{
285 bool bSuccess = true;
286
287 // TODO:
288
289 return bSuccess;
290} // end of wxPrintDCImpl::DoBlit
291
292#endif //wxUSE_PRINTING_ARCHITECTURE