]>
Commit | Line | Data |
---|---|---|
27476f73 | 1 | ///////////////////////////////////////////////////////////////////////////// |
cb7d7375 | 2 | // Name: src/os2/dcprint.cpp |
27476f73 | 3 | // Purpose: wxPrinterDC class |
fb46a9a6 | 4 | // Author: David Webster |
27476f73 | 5 | // Modified by: |
fb46a9a6 | 6 | // Created: 10/14/99 |
27476f73 | 7 | // RCS-ID: $Id$ |
fb46a9a6 | 8 | // Copyright: (c) David Webster |
65571936 | 9 | // Licence: wxWindows licence |
27476f73 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
27476f73 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
fb46a9a6 | 14 | |
df91131c WS |
15 | #if wxUSE_PRINTING_ARCHITECTURE |
16 | ||
6d50343d | 17 | #include "wx/dcprint.h" |
2c24e7ad | 18 | #include "wx/os2/dcprint.h" |
6d50343d | 19 | |
fb46a9a6 DW |
20 | #define INCL_DEV |
21 | #define INCL_GPI | |
22 | #define INCL_PM | |
23 | #include<os2.h> | |
24 | ||
27476f73 | 25 | #ifndef WX_PRECOMP |
df91131c WS |
26 | #include "wx/app.h" |
27 | #include "wx/math.h" | |
28 | #include "wx/string.h" | |
e4db172a | 29 | #include "wx/log.h" |
cdccdfab | 30 | #include "wx/window.h" |
27476f73 DW |
31 | #endif |
32 | ||
27476f73 | 33 | #include "wx/os2/private.h" |
7e99520b | 34 | |
2c24e7ad | 35 | IMPLEMENT_ABSTRACT_CLASS(wxPrinterDCImpl, wxPMDCImpl) |
27476f73 | 36 | |
2c24e7ad SN |
37 | wxPrinterDCImpl::wxPrinterDCImpl( wxPrinterDC *owner, const wxPrintData& rPrintData ) : |
38 | wxPMDCImpl( owner ) | |
27476f73 | 39 | { |
e1a688e4 | 40 | m_printData = rPrintData; |
cb7d7375 | 41 | m_isInteractive = false; |
e1a688e4 | 42 | m_hDC = wxGetPrinterDC(rPrintData); |
27476f73 | 43 | m_ok = (m_hDC != 0); |
27476f73 DW |
44 | if (m_hDC) |
45 | SetMapMode(wxMM_TEXT); | |
27476f73 DW |
46 | SetBrush(*wxBLACK_BRUSH); |
47 | SetPen(*wxBLACK_PEN); | |
e1a688e4 | 48 | } // end of wxPrinterDC::wxPrinterDC |
27476f73 | 49 | |
2c24e7ad SN |
50 | wxPrinterDCImpl::wxPrinterDCImpl( wxPrinterDC *owner, WXHDC hTheDC ) : |
51 | wxPMDCImpl( owner ) | |
27476f73 | 52 | { |
cb7d7375 | 53 | m_isInteractive = false; |
e1a688e4 | 54 | m_hDC = hTheDC; |
cb7d7375 | 55 | m_ok = true; |
27476f73 DW |
56 | if (m_hDC) |
57 | { | |
27476f73 DW |
58 | SetMapMode(wxMM_TEXT); |
59 | } | |
60 | SetBrush(*wxBLACK_BRUSH); | |
61 | SetPen(*wxBLACK_PEN); | |
e1a688e4 | 62 | } // end of wxPrinterDC::wxPrinterDC |
27476f73 | 63 | |
2c24e7ad | 64 | void wxPrinterDCImpl::Init() |
27476f73 | 65 | { |
e1a688e4 DW |
66 | if (m_hDC) |
67 | { | |
68 | SetMapMode(wxMM_TEXT); | |
27476f73 | 69 | |
e1a688e4 DW |
70 | SetBrush(*wxBLACK_BRUSH); |
71 | SetPen(*wxBLACK_PEN); | |
72 | } | |
73 | } // end of wxPrinterDC::Init | |
74 | ||
2c24e7ad | 75 | bool wxPrinterDCImpl::StartDoc(const wxString& WXUNUSED(rsMessage)) |
27476f73 DW |
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 | ||
cb7d7375 | 84 | if (filename.empty()) |
27476f73 DW |
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) | |
cb7d7375 | 95 | return false; |
27476f73 DW |
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(); | |
223d09f6 | 116 | wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError); |
27476f73 DW |
117 | } |
118 | #endif | |
119 | return (ret > 0); | |
120 | */ | |
cb7d7375 | 121 | return true; |
e1a688e4 | 122 | } // end of wxPrinterDC::StartDoc |
27476f73 | 123 | |
2c24e7ad | 124 | void wxPrinterDCImpl::EndDoc() |
27476f73 DW |
125 | { |
126 | // if (m_hDC) ::EndDoc((HDC) m_hDC); | |
e1a688e4 | 127 | } // end of wxPrinterDC::EndDoc |
27476f73 | 128 | |
2c24e7ad | 129 | void wxPrinterDCImpl::StartPage() |
27476f73 DW |
130 | { |
131 | // if (m_hDC) | |
132 | // ::StartPage((HDC) m_hDC); | |
e1a688e4 | 133 | } // end of wxPrinterDC::StartPage |
27476f73 | 134 | |
2c24e7ad | 135 | void wxPrinterDCImpl::EndPage() |
27476f73 DW |
136 | { |
137 | // if (m_hDC) | |
138 | // ::EndPage((HDC) m_hDC); | |
e1a688e4 | 139 | } // end of wxPrinterDC::EndPage |
f415cab9 | 140 | |
6d52ca53 | 141 | wxRect wxPrinterDCImpl::GetPaperRect() const |
f415cab9 JS |
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 | ||
9923c37d | 149 | #if 0 |
27476f73 | 150 | // Returns default device and port names |
cb7d7375 | 151 | static bool wxGetDefaultDeviceName( wxString& rsDeviceName, wxString& rsPortName ) |
27476f73 | 152 | { |
cb7d7375 | 153 | rsDeviceName = wxEmptyString; |
27476f73 DW |
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 | ||
cb7d7375 | 182 | return false; |
27476f73 DW |
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 | } | |
6d50343d | 204 | return !deviceName.empty(); |
27476f73 | 205 | */ |
cb7d7375 | 206 | return true; |
e1a688e4 | 207 | } // end of wxGetDefaultDeviceName |
9923c37d | 208 | #endif |
27476f73 DW |
209 | |
210 | // Gets an HDC for the specified printer configuration | |
cb7d7375 | 211 | WXHDC WXDLLEXPORT wxGetPrinterDC( const wxPrintData& WXUNUSED(rPrintDataConst) ) |
27476f73 | 212 | { |
9dea36ef | 213 | HDC hDC = NULLHANDLE; |
27476f73 DW |
214 | /* |
215 | wxPrintData printData = printDataConst; | |
216 | printData.ConvertToNative(); | |
217 | ||
d3b9f782 | 218 | wxChar* driverName = NULL; |
27476f73 DW |
219 | |
220 | wxString devNameStr = printData.GetPrinterName(); | |
221 | wxChar* deviceName; | |
d3b9f782 | 222 | wxChar* portName = NULL; // Obsolete in WIN32 |
27476f73 | 223 | |
cb7d7375 | 224 | if (devNameStr.empty()) |
d3b9f782 | 225 | deviceName = NULL; |
27476f73 DW |
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 | ||
cb7d7375 | 236 | if (devNameStr.empty()) |
27476f73 DW |
237 | { |
238 | // Retrieve the default device name | |
239 | wxString portName; | |
240 | bool ret = wxGetDefaultDeviceName(devNameStr, portName); | |
241 | ||
223d09f6 | 242 | wxASSERT_MSG( ret, wxT("Could not get default device name.") ); |
27476f73 DW |
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; | |
e1a688e4 DW |
257 | } // end of wxGetPrinterDC |
258 | ||
2c24e7ad SN |
259 | void wxPrinterDCImpl::DoDrawBitmap( const wxBitmap& rBmp, |
260 | wxCoord WXUNUSED(vX), | |
261 | wxCoord WXUNUSED(vY), | |
262 | bool WXUNUSED(bUseMask)) | |
e1a688e4 | 263 | { |
9a83f860 | 264 | wxCHECK_RET( rBmp.Ok(), wxT("invalid bitmap in wxPrinterDC::DrawBitmap") ); |
e1a688e4 | 265 | |
9923c37d DW |
266 | // int nWidth = rBmp.GetWidth(); |
267 | // int nHeight = rBmp.GetHeight(); | |
e1a688e4 DW |
268 | |
269 | // TODO: | |
270 | ||
271 | } // end of wxPrinterDC::DoDrawBitmap | |
272 | ||
2c24e7ad SN |
273 | bool 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), | |
89efaf2b | 280 | wxRasterOperationMode WXUNUSED(nRop), |
2c24e7ad SN |
281 | bool WXUNUSED(bUseMask), |
282 | wxCoord WXUNUSED(xsrcMask), | |
283 | wxCoord WXUNUSED(ysrcMask) ) | |
e1a688e4 | 284 | { |
cb7d7375 | 285 | bool bSuccess = true; |
e1a688e4 DW |
286 | |
287 | // TODO: | |
288 | ||
289 | return bSuccess; | |
2c24e7ad | 290 | } // end of wxPrintDCImpl::DoBlit |
e1a688e4 | 291 | |
7e99520b | 292 | #endif //wxUSE_PRINTING_ARCHITECTURE |