]> git.saurik.com Git - wxWidgets.git/blame - src/os2/dcprint.cpp
Implement wxIsPlatform64Bit().
[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
9923c37d 226#if 0
27476f73 227// Returns default device and port names
cb7d7375 228static bool wxGetDefaultDeviceName( wxString& rsDeviceName, wxString& rsPortName )
27476f73 229{
cb7d7375 230 rsDeviceName = wxEmptyString;
27476f73
DW
231/*
232 LPDEVNAMES lpDevNames;
233 LPSTR lpszDriverName;
234 LPSTR lpszDeviceName;
235 LPSTR lpszPortName;
236
237 PRINTDLG pd;
238
239 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
240#ifdef __GNUWIN32__
241 pd.lStructSize = 66; // sizeof(PRINTDLG);
242#else
243 pd.lStructSize = sizeof(PRINTDLG);
244#endif
245
246 pd.hwndOwner = (HWND)NULL;
247 pd.hDevMode = NULL; // Will be created by PrintDlg
248 pd.hDevNames = NULL; // Ditto
249 pd.Flags = PD_RETURNDEFAULT;
250 pd.nCopies = 1;
251
252 if (!PrintDlg((LPPRINTDLG)&pd))
253 {
254 if ( pd.hDevMode )
255 GlobalFree(pd.hDevMode);
256 if (pd.hDevNames)
257 GlobalFree(pd.hDevNames);
258
cb7d7375 259 return false;
27476f73
DW
260 }
261
262 if (pd.hDevNames)
263 {
264 lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
265 lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
266 lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
267 lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;
268 GlobalUnlock(pd.hDevNames);
269 GlobalFree(pd.hDevNames);
270 pd.hDevNames=NULL;
271
272 deviceName = lpszDeviceName;
273 portName = lpszPortName;
274 }
275
276 if (pd.hDevMode)
277 {
278 GlobalFree(pd.hDevMode);
279 pd.hDevMode=NULL;
280 }
6d50343d 281 return !deviceName.empty();
27476f73 282*/
cb7d7375 283 return true;
e1a688e4 284} // end of wxGetDefaultDeviceName
9923c37d 285#endif
27476f73
DW
286
287// Gets an HDC for the specified printer configuration
cb7d7375 288WXHDC WXDLLEXPORT wxGetPrinterDC( const wxPrintData& WXUNUSED(rPrintDataConst) )
27476f73 289{
9dea36ef 290 HDC hDC = NULLHANDLE;
27476f73
DW
291/*
292 wxPrintData printData = printDataConst;
293 printData.ConvertToNative();
294
295 wxChar* driverName = (wxChar*) NULL;
296
297 wxString devNameStr = printData.GetPrinterName();
298 wxChar* deviceName;
299 wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32
300
cb7d7375 301 if (devNameStr.empty())
27476f73
DW
302 deviceName = (wxChar*) NULL;
303 else
304 deviceName = WXSTRINGCAST devNameStr;
305
306 LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
307
308 HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
309
310 if ( hDevMode )
311 lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
312
cb7d7375 313 if (devNameStr.empty())
27476f73
DW
314 {
315 // Retrieve the default device name
316 wxString portName;
317 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
318
223d09f6 319 wxASSERT_MSG( ret, wxT("Could not get default device name.") );
27476f73
DW
320
321 deviceName = WXSTRINGCAST devNameStr;
322 }
323
324#ifdef __WIN32__
325 HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
326#else
327 HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
328#endif
329
330 if (hDevMode && lpDevMode)
331 GlobalUnlock(hDevMode);
332*/
333 return (WXHDC) hDC;
e1a688e4
DW
334} // end of wxGetPrinterDC
335
cb7d7375
WS
336void wxPrinterDC::DoDrawBitmap( const wxBitmap& rBmp,
337 wxCoord WXUNUSED(vX),
338 wxCoord WXUNUSED(vY),
339 bool WXUNUSED(bUseMask))
e1a688e4
DW
340{
341 wxCHECK_RET( rBmp.Ok(), _T("invalid bitmap in wxPrinterDC::DrawBitmap") );
342
9923c37d
DW
343// int nWidth = rBmp.GetWidth();
344// int nHeight = rBmp.GetHeight();
e1a688e4
DW
345
346 // TODO:
347
348} // end of wxPrinterDC::DoDrawBitmap
349
cb7d7375
WS
350bool wxPrinterDC::DoBlit( wxCoord WXUNUSED(vXdest),
351 wxCoord WXUNUSED(vYdest),
352 wxCoord WXUNUSED(vWidth),
353 wxCoord WXUNUSED(vHeight),
354 wxDC* WXUNUSED(pSource),
355 wxCoord WXUNUSED(vXsrc),
356 wxCoord WXUNUSED(vYsrc),
357 int WXUNUSED(nRop),
358 bool WXUNUSED(bUseMask),
359 wxCoord WXUNUSED(xsrcMask),
360 wxCoord WXUNUSED(ysrcMask) )
e1a688e4 361{
cb7d7375 362 bool bSuccess = true;
e1a688e4
DW
363
364 // TODO:
365
366 return bSuccess;
367} // end of wxPrintDC::DoBlit
368
7e99520b 369#endif //wxUSE_PRINTING_ARCHITECTURE