]> git.saurik.com Git - wxWidgets.git/blame - src/os2/dcprint.cpp
Test the commit announcement bot some more by fixing more gtk signal callback handler...
[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
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"
463c4d71 22#include "wx/math.h"
27476f73
DW
23#endif
24
25#include "wx/string.h"
26#include "wx/log.h"
27#include "wx/window.h"
28#include "wx/os2/private.h"
29#include "wx/dcprint.h"
27476f73 30
7e99520b
DW
31#if wxUSE_PRINTING_ARCHITECTURE
32
27476f73 33IMPLEMENT_CLASS(wxPrinterDC, wxDC)
27476f73 34
27476f73
DW
35
36// This form is deprecated
cb7d7375
WS
37wxPrinterDC::wxPrinterDC( const wxString& rsDriverName,
38 const wxString& rsDeviceName,
39 const wxString& rsFile,
40 bool bInteractive,
41 int nOrientation )
27476f73 42{
e1a688e4
DW
43 DEVOPENSTRUC vDevOpen = { (char*)rsDeviceName.c_str()
44 ,(char*)rsDriverName.c_str()
45 ,NULL
46 ,NULL
47 ,NULL
48 ,NULL
49 ,NULL
50 ,NULL
51 ,NULL
52 };
53
54 m_isInteractive = bInteractive;
55
cb7d7375 56 if (!rsFile.IsNull() && !rsFile.empty())
e1a688e4 57 m_printData.SetFilename(rsFile);
27476f73
DW
58
59/*
60 Implement PM's version of this
61#if wxUSE_COMMON_DIALOGS
62 if (interactive)
63 {
64 PRINTDLG pd;
65
66 pd.lStructSize = sizeof( PRINTDLG );
67 pd.hwndOwner=(HWND) NULL;
68 pd.hDevMode=(HANDLE)NULL;
69 pd.hDevNames=(HANDLE)NULL;
70 pd.Flags=PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS;
71 pd.nFromPage=0;
72 pd.nToPage=0;
73 pd.nMinPage=0;
74 pd.nMaxPage=0;
75 pd.nCopies=1;
76 pd.hInstance=(HINSTANCE)NULL;
77
78 if ( PrintDlg( &pd ) != 0 )
79 {
80 m_hDC = (WXHDC) pd.hDC;
cb7d7375 81 m_ok = true;
27476f73
DW
82 }
83 else
84 {
cb7d7375 85 m_ok = false;
27476f73
DW
86 return;
87 }
27476f73
DW
88 }
89 else
90#endif
91*/
cb7d7375
WS
92 if ( !rsDriverName.empty() &&
93 !rsDeviceName.empty() &&
94 !rsFile.empty() )
27476f73 95 {
e1a688e4 96 m_hDC = (WXHDC) ::DevOpenDC( vHabmain
27476f73
DW
97 ,OD_QUEUED
98 ,"*"
99 ,5L
e1a688e4 100 ,(PDEVOPENDATA)&vDevOpen
27476f73
DW
101 ,NULLHANDLE
102 );
cb7d7375 103 m_ok = m_hDC ? true: false;
27476f73
DW
104 }
105 else
106 {
e1a688e4
DW
107 wxPrintData vPrintData;
108
109 vPrintData.SetOrientation(nOrientation);
110 m_hDC = wxGetPrinterDC(vPrintData);
cb7d7375 111 m_ok = m_hDC ? true: false;
27476f73
DW
112 }
113
114 if (m_hDC)
115 {
116 // int width = GetDeviceCaps(m_hDC, VERTRES);
117 // int height = GetDeviceCaps(m_hDC, HORZRES);
118 SetMapMode(wxMM_TEXT);
119 }
120 SetBrush(*wxBLACK_BRUSH);
121 SetPen(*wxBLACK_PEN);
e1a688e4 122} // end of wxPrinterDC::wxPrinterDC
27476f73 123
cb7d7375 124wxPrinterDC::wxPrinterDC( const wxPrintData& rPrintData )
27476f73 125{
e1a688e4 126 m_printData = rPrintData;
cb7d7375 127 m_isInteractive = false;
e1a688e4 128 m_hDC = wxGetPrinterDC(rPrintData);
27476f73 129 m_ok = (m_hDC != 0);
27476f73
DW
130 if (m_hDC)
131 SetMapMode(wxMM_TEXT);
27476f73
DW
132 SetBrush(*wxBLACK_BRUSH);
133 SetPen(*wxBLACK_PEN);
e1a688e4 134} // end of wxPrinterDC::wxPrinterDC
27476f73 135
cb7d7375 136wxPrinterDC::wxPrinterDC( WXHDC hTheDC )
27476f73 137{
cb7d7375 138 m_isInteractive = false;
e1a688e4 139 m_hDC = hTheDC;
cb7d7375 140 m_ok = true;
27476f73
DW
141 if (m_hDC)
142 {
27476f73
DW
143 SetMapMode(wxMM_TEXT);
144 }
145 SetBrush(*wxBLACK_BRUSH);
146 SetPen(*wxBLACK_PEN);
e1a688e4 147} // end of wxPrinterDC::wxPrinterDC
27476f73 148
e1a688e4 149void wxPrinterDC::Init()
27476f73 150{
e1a688e4
DW
151 if (m_hDC)
152 {
153 SetMapMode(wxMM_TEXT);
27476f73 154
e1a688e4
DW
155 SetBrush(*wxBLACK_BRUSH);
156 SetPen(*wxBLACK_PEN);
157 }
158} // end of wxPrinterDC::Init
159
cb7d7375 160bool wxPrinterDC::StartDoc(const wxString& WXUNUSED(rsMessage))
27476f73
DW
161{
162/* TODO: PM's implementation
163 DOCINFO docinfo;
164 docinfo.cbSize = sizeof(DOCINFO);
165 docinfo.lpszDocName = (const wxChar*)message;
166
167 wxString filename(m_printData.GetFilename());
168
cb7d7375 169 if (filename.empty())
27476f73
DW
170 docinfo.lpszOutput = NULL;
171 else
172 docinfo.lpszOutput = (const wxChar *) filename;
173
174#if defined(__WIN95__)
175 docinfo.lpszDatatype = NULL;
176 docinfo.fwType = 0;
177#endif
178
179 if (!m_hDC)
cb7d7375 180 return false;
27476f73
DW
181
182 int ret =
183#ifndef __WIN32__
184 ::StartDoc((HDC) m_hDC, &docinfo);
185#else
186#ifdef UNICODE
187 ::StartDocW((HDC) m_hDC, &docinfo);
188#else
189#ifdef __TWIN32__
190 ::StartDoc((HDC) m_hDC, &docinfo);
191#else
192 ::StartDocA((HDC) m_hDC, &docinfo);
193#endif
194#endif
195#endif
196
197#ifndef __WIN16__
198 if (ret <= 0)
199 {
200 DWORD lastError = GetLastError();
223d09f6 201 wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError);
27476f73
DW
202 }
203#endif
204 return (ret > 0);
205*/
cb7d7375 206 return true;
e1a688e4 207} // end of wxPrinterDC::StartDoc
27476f73 208
e1a688e4 209void wxPrinterDC::EndDoc()
27476f73
DW
210{
211// if (m_hDC) ::EndDoc((HDC) m_hDC);
e1a688e4 212} // end of wxPrinterDC::EndDoc
27476f73 213
e1a688e4 214void wxPrinterDC::StartPage()
27476f73
DW
215{
216// if (m_hDC)
217// ::StartPage((HDC) m_hDC);
e1a688e4 218} // end of wxPrinterDC::StartPage
27476f73 219
e1a688e4 220void wxPrinterDC::EndPage()
27476f73
DW
221{
222// if (m_hDC)
223// ::EndPage((HDC) m_hDC);
e1a688e4 224} // end of wxPrinterDC::EndPage
9923c37d 225#if 0
27476f73 226// Returns default device and port names
cb7d7375 227static bool wxGetDefaultDeviceName( wxString& rsDeviceName, wxString& rsPortName )
27476f73 228{
cb7d7375 229 rsDeviceName = wxEmptyString;
27476f73
DW
230/*
231 LPDEVNAMES lpDevNames;
232 LPSTR lpszDriverName;
233 LPSTR lpszDeviceName;
234 LPSTR lpszPortName;
235
236 PRINTDLG pd;
237
238 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
239#ifdef __GNUWIN32__
240 pd.lStructSize = 66; // sizeof(PRINTDLG);
241#else
242 pd.lStructSize = sizeof(PRINTDLG);
243#endif
244
245 pd.hwndOwner = (HWND)NULL;
246 pd.hDevMode = NULL; // Will be created by PrintDlg
247 pd.hDevNames = NULL; // Ditto
248 pd.Flags = PD_RETURNDEFAULT;
249 pd.nCopies = 1;
250
251 if (!PrintDlg((LPPRINTDLG)&pd))
252 {
253 if ( pd.hDevMode )
254 GlobalFree(pd.hDevMode);
255 if (pd.hDevNames)
256 GlobalFree(pd.hDevNames);
257
cb7d7375 258 return false;
27476f73
DW
259 }
260
261 if (pd.hDevNames)
262 {
263 lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
264 lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
265 lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
266 lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;
267 GlobalUnlock(pd.hDevNames);
268 GlobalFree(pd.hDevNames);
269 pd.hDevNames=NULL;
270
271 deviceName = lpszDeviceName;
272 portName = lpszPortName;
273 }
274
275 if (pd.hDevMode)
276 {
277 GlobalFree(pd.hDevMode);
278 pd.hDevMode=NULL;
279 }
223d09f6 280 return ( deviceName != wxT("") );
27476f73 281*/
cb7d7375 282 return true;
e1a688e4 283} // end of wxGetDefaultDeviceName
9923c37d 284#endif
27476f73
DW
285
286// Gets an HDC for the specified printer configuration
cb7d7375 287WXHDC WXDLLEXPORT wxGetPrinterDC( const wxPrintData& WXUNUSED(rPrintDataConst) )
27476f73 288{
9dea36ef 289 HDC hDC = NULLHANDLE;
27476f73
DW
290/*
291 wxPrintData printData = printDataConst;
292 printData.ConvertToNative();
293
294 wxChar* driverName = (wxChar*) NULL;
295
296 wxString devNameStr = printData.GetPrinterName();
297 wxChar* deviceName;
298 wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32
299
cb7d7375 300 if (devNameStr.empty())
27476f73
DW
301 deviceName = (wxChar*) NULL;
302 else
303 deviceName = WXSTRINGCAST devNameStr;
304
305 LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
306
307 HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
308
309 if ( hDevMode )
310 lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
311
cb7d7375 312 if (devNameStr.empty())
27476f73
DW
313 {
314 // Retrieve the default device name
315 wxString portName;
316 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
317
223d09f6 318 wxASSERT_MSG( ret, wxT("Could not get default device name.") );
27476f73
DW
319
320 deviceName = WXSTRINGCAST devNameStr;
321 }
322
323#ifdef __WIN32__
324 HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
325#else
326 HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
327#endif
328
329 if (hDevMode && lpDevMode)
330 GlobalUnlock(hDevMode);
331*/
332 return (WXHDC) hDC;
e1a688e4
DW
333} // end of wxGetPrinterDC
334
cb7d7375
WS
335void wxPrinterDC::DoDrawBitmap( const wxBitmap& rBmp,
336 wxCoord WXUNUSED(vX),
337 wxCoord WXUNUSED(vY),
338 bool WXUNUSED(bUseMask))
e1a688e4
DW
339{
340 wxCHECK_RET( rBmp.Ok(), _T("invalid bitmap in wxPrinterDC::DrawBitmap") );
341
9923c37d
DW
342// int nWidth = rBmp.GetWidth();
343// int nHeight = rBmp.GetHeight();
e1a688e4
DW
344
345 // TODO:
346
347} // end of wxPrinterDC::DoDrawBitmap
348
cb7d7375
WS
349bool wxPrinterDC::DoBlit( wxCoord WXUNUSED(vXdest),
350 wxCoord WXUNUSED(vYdest),
351 wxCoord WXUNUSED(vWidth),
352 wxCoord WXUNUSED(vHeight),
353 wxDC* WXUNUSED(pSource),
354 wxCoord WXUNUSED(vXsrc),
355 wxCoord WXUNUSED(vYsrc),
356 int WXUNUSED(nRop),
357 bool WXUNUSED(bUseMask),
358 wxCoord WXUNUSED(xsrcMask),
359 wxCoord WXUNUSED(ysrcMask) )
e1a688e4 360{
cb7d7375 361 bool bSuccess = true;
e1a688e4
DW
362
363 // TODO:
364
365 return bSuccess;
366} // end of wxPrintDC::DoBlit
367
7e99520b 368#endif //wxUSE_PRINTING_ARCHITECTURE