]> git.saurik.com Git - wxWidgets.git/blame - src/os2/dcprint.cpp
compilation fix for wxUSE_UNICODE_MSLU && !WXWIN_COMPATIBILITY_2_6 (bug 1587408)
[wxWidgets.git] / src / os2 / dcprint.cpp
CommitLineData
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
WS
17#include "wx/dcprint.h"
18
fb46a9a6
DW
19#define INCL_DEV
20#define INCL_GPI
21#define INCL_PM
22#include<os2.h>
23
27476f73 24#ifndef WX_PRECOMP
df91131c
WS
25 #include "wx/app.h"
26 #include "wx/math.h"
27 #include "wx/string.h"
e4db172a 28 #include "wx/log.h"
cdccdfab 29 #include "wx/window.h"
27476f73
DW
30#endif
31
27476f73 32#include "wx/os2/private.h"
7e99520b 33
27476f73 34IMPLEMENT_CLASS(wxPrinterDC, wxDC)
27476f73 35
27476f73
DW
36
37// This form is deprecated
cb7d7375
WS
38wxPrinterDC::wxPrinterDC( const wxString& rsDriverName,
39 const wxString& rsDeviceName,
40 const wxString& rsFile,
41 bool bInteractive,
42 int nOrientation )
27476f73 43{
e1a688e4
DW
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
cb7d7375 57 if (!rsFile.IsNull() && !rsFile.empty())
e1a688e4 58 m_printData.SetFilename(rsFile);
27476f73
DW
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;
cb7d7375 82 m_ok = true;
27476f73
DW
83 }
84 else
85 {
cb7d7375 86 m_ok = false;
27476f73
DW
87 return;
88 }
27476f73
DW
89 }
90 else
91#endif
92*/
cb7d7375
WS
93 if ( !rsDriverName.empty() &&
94 !rsDeviceName.empty() &&
95 !rsFile.empty() )
27476f73 96 {
e1a688e4 97 m_hDC = (WXHDC) ::DevOpenDC( vHabmain
27476f73
DW
98 ,OD_QUEUED
99 ,"*"
100 ,5L
e1a688e4 101 ,(PDEVOPENDATA)&vDevOpen
27476f73
DW
102 ,NULLHANDLE
103 );
cb7d7375 104 m_ok = m_hDC ? true: false;
27476f73
DW
105 }
106 else
107 {
e1a688e4
DW
108 wxPrintData vPrintData;
109
110 vPrintData.SetOrientation(nOrientation);
111 m_hDC = wxGetPrinterDC(vPrintData);
cb7d7375 112 m_ok = m_hDC ? true: false;
27476f73
DW
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);
e1a688e4 123} // end of wxPrinterDC::wxPrinterDC
27476f73 124
cb7d7375 125wxPrinterDC::wxPrinterDC( const wxPrintData& rPrintData )
27476f73 126{
e1a688e4 127 m_printData = rPrintData;
cb7d7375 128 m_isInteractive = false;
e1a688e4 129 m_hDC = wxGetPrinterDC(rPrintData);
27476f73 130 m_ok = (m_hDC != 0);
27476f73
DW
131 if (m_hDC)
132 SetMapMode(wxMM_TEXT);
27476f73
DW
133 SetBrush(*wxBLACK_BRUSH);
134 SetPen(*wxBLACK_PEN);
e1a688e4 135} // end of wxPrinterDC::wxPrinterDC
27476f73 136
cb7d7375 137wxPrinterDC::wxPrinterDC( WXHDC hTheDC )
27476f73 138{
cb7d7375 139 m_isInteractive = false;
e1a688e4 140 m_hDC = hTheDC;
cb7d7375 141 m_ok = true;
27476f73
DW
142 if (m_hDC)
143 {
27476f73
DW
144 SetMapMode(wxMM_TEXT);
145 }
146 SetBrush(*wxBLACK_BRUSH);
147 SetPen(*wxBLACK_PEN);
e1a688e4 148} // end of wxPrinterDC::wxPrinterDC
27476f73 149
e1a688e4 150void wxPrinterDC::Init()
27476f73 151{
e1a688e4
DW
152 if (m_hDC)
153 {
154 SetMapMode(wxMM_TEXT);
27476f73 155
e1a688e4
DW
156 SetBrush(*wxBLACK_BRUSH);
157 SetPen(*wxBLACK_PEN);
158 }
159} // end of wxPrinterDC::Init
160
cb7d7375 161bool wxPrinterDC::StartDoc(const wxString& WXUNUSED(rsMessage))
27476f73
DW
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
cb7d7375 170 if (filename.empty())
27476f73
DW
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)
cb7d7375 181 return false;
27476f73
DW
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();
223d09f6 202 wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError);
27476f73
DW
203 }
204#endif
205 return (ret > 0);
206*/
cb7d7375 207 return true;
e1a688e4 208} // end of wxPrinterDC::StartDoc
27476f73 209
e1a688e4 210void wxPrinterDC::EndDoc()
27476f73
DW
211{
212// if (m_hDC) ::EndDoc((HDC) m_hDC);
e1a688e4 213} // end of wxPrinterDC::EndDoc
27476f73 214
e1a688e4 215void wxPrinterDC::StartPage()
27476f73
DW
216{
217// if (m_hDC)
218// ::StartPage((HDC) m_hDC);
e1a688e4 219} // end of wxPrinterDC::StartPage
27476f73 220
e1a688e4 221void wxPrinterDC::EndPage()
27476f73
DW
222{
223// if (m_hDC)
224// ::EndPage((HDC) m_hDC);
e1a688e4 225} // end of wxPrinterDC::EndPage
f415cab9
JS
226
227wxRect wxPrinterDC::GetPaperRect()
228{
229 // Use page rect if we can't get paper rect.
230 wxCoord w, h;
231 GetSize(&w, &h);
232 return wxRect(0, 0, w, h);
233}
234
9923c37d 235#if 0
27476f73 236// Returns default device and port names
cb7d7375 237static bool wxGetDefaultDeviceName( wxString& rsDeviceName, wxString& rsPortName )
27476f73 238{
cb7d7375 239 rsDeviceName = wxEmptyString;
27476f73
DW
240/*
241 LPDEVNAMES lpDevNames;
242 LPSTR lpszDriverName;
243 LPSTR lpszDeviceName;
244 LPSTR lpszPortName;
245
246 PRINTDLG pd;
247
248 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
249#ifdef __GNUWIN32__
250 pd.lStructSize = 66; // sizeof(PRINTDLG);
251#else
252 pd.lStructSize = sizeof(PRINTDLG);
253#endif
254
255 pd.hwndOwner = (HWND)NULL;
256 pd.hDevMode = NULL; // Will be created by PrintDlg
257 pd.hDevNames = NULL; // Ditto
258 pd.Flags = PD_RETURNDEFAULT;
259 pd.nCopies = 1;
260
261 if (!PrintDlg((LPPRINTDLG)&pd))
262 {
263 if ( pd.hDevMode )
264 GlobalFree(pd.hDevMode);
265 if (pd.hDevNames)
266 GlobalFree(pd.hDevNames);
267
cb7d7375 268 return false;
27476f73
DW
269 }
270
271 if (pd.hDevNames)
272 {
273 lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
274 lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
275 lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
276 lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;
277 GlobalUnlock(pd.hDevNames);
278 GlobalFree(pd.hDevNames);
279 pd.hDevNames=NULL;
280
281 deviceName = lpszDeviceName;
282 portName = lpszPortName;
283 }
284
285 if (pd.hDevMode)
286 {
287 GlobalFree(pd.hDevMode);
288 pd.hDevMode=NULL;
289 }
6d50343d 290 return !deviceName.empty();
27476f73 291*/
cb7d7375 292 return true;
e1a688e4 293} // end of wxGetDefaultDeviceName
9923c37d 294#endif
27476f73
DW
295
296// Gets an HDC for the specified printer configuration
cb7d7375 297WXHDC WXDLLEXPORT wxGetPrinterDC( const wxPrintData& WXUNUSED(rPrintDataConst) )
27476f73 298{
9dea36ef 299 HDC hDC = NULLHANDLE;
27476f73
DW
300/*
301 wxPrintData printData = printDataConst;
302 printData.ConvertToNative();
303
304 wxChar* driverName = (wxChar*) NULL;
305
306 wxString devNameStr = printData.GetPrinterName();
307 wxChar* deviceName;
308 wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32
309
cb7d7375 310 if (devNameStr.empty())
27476f73
DW
311 deviceName = (wxChar*) NULL;
312 else
313 deviceName = WXSTRINGCAST devNameStr;
314
315 LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
316
317 HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
318
319 if ( hDevMode )
320 lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
321
cb7d7375 322 if (devNameStr.empty())
27476f73
DW
323 {
324 // Retrieve the default device name
325 wxString portName;
326 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
327
223d09f6 328 wxASSERT_MSG( ret, wxT("Could not get default device name.") );
27476f73
DW
329
330 deviceName = WXSTRINGCAST devNameStr;
331 }
332
333#ifdef __WIN32__
334 HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
335#else
336 HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
337#endif
338
339 if (hDevMode && lpDevMode)
340 GlobalUnlock(hDevMode);
341*/
342 return (WXHDC) hDC;
e1a688e4
DW
343} // end of wxGetPrinterDC
344
cb7d7375
WS
345void wxPrinterDC::DoDrawBitmap( const wxBitmap& rBmp,
346 wxCoord WXUNUSED(vX),
347 wxCoord WXUNUSED(vY),
348 bool WXUNUSED(bUseMask))
e1a688e4
DW
349{
350 wxCHECK_RET( rBmp.Ok(), _T("invalid bitmap in wxPrinterDC::DrawBitmap") );
351
9923c37d
DW
352// int nWidth = rBmp.GetWidth();
353// int nHeight = rBmp.GetHeight();
e1a688e4
DW
354
355 // TODO:
356
357} // end of wxPrinterDC::DoDrawBitmap
358
cb7d7375
WS
359bool wxPrinterDC::DoBlit( wxCoord WXUNUSED(vXdest),
360 wxCoord WXUNUSED(vYdest),
361 wxCoord WXUNUSED(vWidth),
362 wxCoord WXUNUSED(vHeight),
363 wxDC* WXUNUSED(pSource),
364 wxCoord WXUNUSED(vXsrc),
365 wxCoord WXUNUSED(vYsrc),
366 int WXUNUSED(nRop),
367 bool WXUNUSED(bUseMask),
368 wxCoord WXUNUSED(xsrcMask),
369 wxCoord WXUNUSED(ysrcMask) )
e1a688e4 370{
cb7d7375 371 bool bSuccess = true;
e1a688e4
DW
372
373 // TODO:
374
375 return bSuccess;
376} // end of wxPrintDC::DoBlit
377
7e99520b 378#endif //wxUSE_PRINTING_ARCHITECTURE