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