]>
Commit | Line | Data |
---|---|---|
27476f73 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dcprint.cpp | |
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 DW |
14 | |
15 | #define INCL_DEV | |
16 | #define INCL_GPI | |
17 | #define INCL_PM | |
18 | #include<os2.h> | |
19 | ||
27476f73 | 20 | #ifndef WX_PRECOMP |
3417f661 | 21 | #include "wx/app.h" |
27476f73 DW |
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 | ||
7e99520b DW |
31 | #if wxUSE_PRINTING_ARCHITECTURE |
32 | ||
27476f73 | 33 | IMPLEMENT_CLASS(wxPrinterDC, wxDC) |
27476f73 | 34 | |
27476f73 DW |
35 | |
36 | // This form is deprecated | |
e1a688e4 DW |
37 | wxPrinterDC::wxPrinterDC( |
38 | const wxString& rsDriverName | |
39 | , const wxString& rsDeviceName | |
40 | , const wxString& rsFile | |
41 | , bool bInteractive | |
42 | , int nOrientation | |
43 | ) | |
27476f73 | 44 | { |
e1a688e4 DW |
45 | DEVOPENSTRUC vDevOpen = { (char*)rsDeviceName.c_str() |
46 | ,(char*)rsDriverName.c_str() | |
47 | ,NULL | |
48 | ,NULL | |
49 | ,NULL | |
50 | ,NULL | |
51 | ,NULL | |
52 | ,NULL | |
53 | ,NULL | |
54 | }; | |
55 | ||
56 | m_isInteractive = bInteractive; | |
57 | ||
58 | if (!rsFile.IsNull() && rsFile != wxT("")) | |
59 | m_printData.SetFilename(rsFile); | |
27476f73 DW |
60 | |
61 | /* | |
62 | Implement PM's version of this | |
63 | #if wxUSE_COMMON_DIALOGS | |
64 | if (interactive) | |
65 | { | |
66 | PRINTDLG pd; | |
67 | ||
68 | pd.lStructSize = sizeof( PRINTDLG ); | |
69 | pd.hwndOwner=(HWND) NULL; | |
70 | pd.hDevMode=(HANDLE)NULL; | |
71 | pd.hDevNames=(HANDLE)NULL; | |
72 | pd.Flags=PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS; | |
73 | pd.nFromPage=0; | |
74 | pd.nToPage=0; | |
75 | pd.nMinPage=0; | |
76 | pd.nMaxPage=0; | |
77 | pd.nCopies=1; | |
78 | pd.hInstance=(HINSTANCE)NULL; | |
79 | ||
80 | if ( PrintDlg( &pd ) != 0 ) | |
81 | { | |
82 | m_hDC = (WXHDC) pd.hDC; | |
83 | m_ok = TRUE; | |
84 | } | |
85 | else | |
86 | { | |
87 | m_ok = FALSE; | |
88 | return; | |
89 | } | |
90 | ||
91 | // m_dontDelete = TRUE; | |
92 | } | |
93 | else | |
94 | #endif | |
95 | */ | |
e1a688e4 DW |
96 | if ((!rsDriverName.IsNull() && rsDriverName != wxT("")) && |
97 | (!rsDeviceName.IsNull() && rsDeviceName != wxT("")) && | |
98 | (!rsFile.IsNull() && rsFile != wxT(""))) | |
27476f73 | 99 | { |
e1a688e4 | 100 | m_hDC = (WXHDC) ::DevOpenDC( vHabmain |
27476f73 DW |
101 | ,OD_QUEUED |
102 | ,"*" | |
103 | ,5L | |
e1a688e4 | 104 | ,(PDEVOPENDATA)&vDevOpen |
27476f73 DW |
105 | ,NULLHANDLE |
106 | ); | |
107 | m_ok = m_hDC ? TRUE: FALSE; | |
108 | } | |
109 | else | |
110 | { | |
e1a688e4 DW |
111 | wxPrintData vPrintData; |
112 | ||
113 | vPrintData.SetOrientation(nOrientation); | |
114 | m_hDC = wxGetPrinterDC(vPrintData); | |
27476f73 DW |
115 | m_ok = m_hDC ? TRUE: FALSE; |
116 | } | |
117 | ||
118 | if (m_hDC) | |
119 | { | |
120 | // int width = GetDeviceCaps(m_hDC, VERTRES); | |
121 | // int height = GetDeviceCaps(m_hDC, HORZRES); | |
122 | SetMapMode(wxMM_TEXT); | |
123 | } | |
124 | SetBrush(*wxBLACK_BRUSH); | |
125 | SetPen(*wxBLACK_PEN); | |
e1a688e4 | 126 | } // end of wxPrinterDC::wxPrinterDC |
27476f73 | 127 | |
e1a688e4 DW |
128 | wxPrinterDC::wxPrinterDC( |
129 | const wxPrintData& rPrintData | |
130 | ) | |
27476f73 | 131 | { |
e1a688e4 | 132 | m_printData = rPrintData; |
27476f73 | 133 | m_isInteractive = FALSE; |
e1a688e4 | 134 | m_hDC = wxGetPrinterDC(rPrintData); |
27476f73 | 135 | m_ok = (m_hDC != 0); |
27476f73 DW |
136 | if (m_hDC) |
137 | SetMapMode(wxMM_TEXT); | |
27476f73 DW |
138 | SetBrush(*wxBLACK_BRUSH); |
139 | SetPen(*wxBLACK_PEN); | |
e1a688e4 | 140 | } // end of wxPrinterDC::wxPrinterDC |
27476f73 | 141 | |
e1a688e4 DW |
142 | wxPrinterDC::wxPrinterDC( |
143 | WXHDC hTheDC | |
144 | ) | |
27476f73 DW |
145 | { |
146 | m_isInteractive = FALSE; | |
e1a688e4 | 147 | m_hDC = hTheDC; |
27476f73 DW |
148 | m_ok = TRUE; |
149 | if (m_hDC) | |
150 | { | |
27476f73 DW |
151 | SetMapMode(wxMM_TEXT); |
152 | } | |
153 | SetBrush(*wxBLACK_BRUSH); | |
154 | SetPen(*wxBLACK_PEN); | |
e1a688e4 | 155 | } // end of wxPrinterDC::wxPrinterDC |
27476f73 | 156 | |
e1a688e4 | 157 | void wxPrinterDC::Init() |
27476f73 | 158 | { |
e1a688e4 DW |
159 | if (m_hDC) |
160 | { | |
161 | SetMapMode(wxMM_TEXT); | |
27476f73 | 162 | |
e1a688e4 DW |
163 | SetBrush(*wxBLACK_BRUSH); |
164 | SetPen(*wxBLACK_PEN); | |
165 | } | |
166 | } // end of wxPrinterDC::Init | |
167 | ||
168 | bool wxPrinterDC::StartDoc( | |
169 | const wxString& rsMessage | |
170 | ) | |
27476f73 DW |
171 | { |
172 | /* TODO: PM's implementation | |
173 | DOCINFO docinfo; | |
174 | docinfo.cbSize = sizeof(DOCINFO); | |
175 | docinfo.lpszDocName = (const wxChar*)message; | |
176 | ||
177 | wxString filename(m_printData.GetFilename()); | |
178 | ||
179 | if (filename.IsEmpty()) | |
180 | docinfo.lpszOutput = NULL; | |
181 | else | |
182 | docinfo.lpszOutput = (const wxChar *) filename; | |
183 | ||
184 | #if defined(__WIN95__) | |
185 | docinfo.lpszDatatype = NULL; | |
186 | docinfo.fwType = 0; | |
187 | #endif | |
188 | ||
189 | if (!m_hDC) | |
190 | return FALSE; | |
191 | ||
192 | int ret = | |
193 | #ifndef __WIN32__ | |
194 | ::StartDoc((HDC) m_hDC, &docinfo); | |
195 | #else | |
196 | #ifdef UNICODE | |
197 | ::StartDocW((HDC) m_hDC, &docinfo); | |
198 | #else | |
199 | #ifdef __TWIN32__ | |
200 | ::StartDoc((HDC) m_hDC, &docinfo); | |
201 | #else | |
202 | ::StartDocA((HDC) m_hDC, &docinfo); | |
203 | #endif | |
204 | #endif | |
205 | #endif | |
206 | ||
207 | #ifndef __WIN16__ | |
208 | if (ret <= 0) | |
209 | { | |
210 | DWORD lastError = GetLastError(); | |
223d09f6 | 211 | wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError); |
27476f73 DW |
212 | } |
213 | #endif | |
214 | return (ret > 0); | |
215 | */ | |
216 | return(TRUE); | |
e1a688e4 | 217 | } // end of wxPrinterDC::StartDoc |
27476f73 | 218 | |
e1a688e4 | 219 | void wxPrinterDC::EndDoc() |
27476f73 DW |
220 | { |
221 | // if (m_hDC) ::EndDoc((HDC) m_hDC); | |
e1a688e4 | 222 | } // end of wxPrinterDC::EndDoc |
27476f73 | 223 | |
e1a688e4 | 224 | void wxPrinterDC::StartPage() |
27476f73 DW |
225 | { |
226 | // if (m_hDC) | |
227 | // ::StartPage((HDC) m_hDC); | |
e1a688e4 | 228 | } // end of wxPrinterDC::StartPage |
27476f73 | 229 | |
e1a688e4 | 230 | void wxPrinterDC::EndPage() |
27476f73 DW |
231 | { |
232 | // if (m_hDC) | |
233 | // ::EndPage((HDC) m_hDC); | |
e1a688e4 | 234 | } // end of wxPrinterDC::EndPage |
9923c37d | 235 | #if 0 |
27476f73 | 236 | // Returns default device and port names |
e1a688e4 DW |
237 | static bool wxGetDefaultDeviceName( |
238 | wxString& rsDeviceName | |
239 | , wxString& rsPortName | |
240 | ) | |
27476f73 | 241 | { |
e1a688e4 | 242 | rsDeviceName = ""; |
27476f73 DW |
243 | /* |
244 | LPDEVNAMES lpDevNames; | |
245 | LPSTR lpszDriverName; | |
246 | LPSTR lpszDeviceName; | |
247 | LPSTR lpszPortName; | |
248 | ||
249 | PRINTDLG pd; | |
250 | ||
251 | // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68 | |
252 | #ifdef __GNUWIN32__ | |
253 | pd.lStructSize = 66; // sizeof(PRINTDLG); | |
254 | #else | |
255 | pd.lStructSize = sizeof(PRINTDLG); | |
256 | #endif | |
257 | ||
258 | pd.hwndOwner = (HWND)NULL; | |
259 | pd.hDevMode = NULL; // Will be created by PrintDlg | |
260 | pd.hDevNames = NULL; // Ditto | |
261 | pd.Flags = PD_RETURNDEFAULT; | |
262 | pd.nCopies = 1; | |
263 | ||
264 | if (!PrintDlg((LPPRINTDLG)&pd)) | |
265 | { | |
266 | if ( pd.hDevMode ) | |
267 | GlobalFree(pd.hDevMode); | |
268 | if (pd.hDevNames) | |
269 | GlobalFree(pd.hDevNames); | |
270 | ||
271 | return FALSE; | |
272 | } | |
273 | ||
274 | if (pd.hDevNames) | |
275 | { | |
276 | lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames); | |
277 | lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset; | |
278 | lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset; | |
279 | lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset; | |
280 | GlobalUnlock(pd.hDevNames); | |
281 | GlobalFree(pd.hDevNames); | |
282 | pd.hDevNames=NULL; | |
283 | ||
284 | deviceName = lpszDeviceName; | |
285 | portName = lpszPortName; | |
286 | } | |
287 | ||
288 | if (pd.hDevMode) | |
289 | { | |
290 | GlobalFree(pd.hDevMode); | |
291 | pd.hDevMode=NULL; | |
292 | } | |
223d09f6 | 293 | return ( deviceName != wxT("") ); |
27476f73 DW |
294 | */ |
295 | return(TRUE); | |
e1a688e4 | 296 | } // end of wxGetDefaultDeviceName |
9923c37d | 297 | #endif |
27476f73 DW |
298 | |
299 | // Gets an HDC for the specified printer configuration | |
e1a688e4 DW |
300 | WXHDC WXDLLEXPORT wxGetPrinterDC( |
301 | const wxPrintData& rPrintDataConst | |
302 | ) | |
27476f73 | 303 | { |
9dea36ef | 304 | HDC hDC = NULLHANDLE; |
27476f73 DW |
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 | ||
223d09f6 | 315 | if (devNameStr == wxT("")) |
27476f73 DW |
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 | ||
223d09f6 | 327 | if (devNameStr == wxT("")) |
27476f73 DW |
328 | { |
329 | // Retrieve the default device name | |
330 | wxString portName; | |
331 | bool ret = wxGetDefaultDeviceName(devNameStr, portName); | |
332 | ||
223d09f6 | 333 | wxASSERT_MSG( ret, wxT("Could not get default device name.") ); |
27476f73 DW |
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; | |
e1a688e4 DW |
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 | ||
9923c37d DW |
359 | // int nWidth = rBmp.GetWidth(); |
360 | // int nHeight = rBmp.GetHeight(); | |
e1a688e4 DW |
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 | |
0cbff120 JS |
376 | , wxCoord xsrcMask |
377 | , wxCoord ysrcMask | |
e1a688e4 DW |
378 | ) |
379 | { | |
380 | bool bSuccess = TRUE; | |
381 | ||
382 | // TODO: | |
383 | ||
384 | return bSuccess; | |
385 | } // end of wxPrintDC::DoBlit | |
386 | ||
27476f73 | 387 | |
7e99520b | 388 | #endif //wxUSE_PRINTING_ARCHITECTURE |