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