]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/dcprint.cpp
8367bb39403fc7c6f536c2764b39d77ceab0904e
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPrinterDC class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dcprint.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
21 #include "wx/string.h"
23 #include "wx/window.h"
24 #include "wx/os2/private.h"
25 #include "wx/dcprint.h"
28 #if !USE_SHARED_LIBRARY
29 IMPLEMENT_CLASS(wxPrinterDC
, wxDC
)
37 // This form is deprecated
38 wxPrinterDC::wxPrinterDC(const wxString
& driver_name
, const wxString
& device_name
, const wxString
& file
, bool interactive
, int orientation
)
42 DEVOPENSTRUC devOpen
= { (char*)device_name
.c_str()
43 ,(char*)driver_name
.c_str()
53 m_isInteractive
= interactive
;
55 if (!file
.IsNull() && file
!= T(""))
56 m_printData
.SetFilename(file
);
59 Implement PM's version of this
60 #if wxUSE_COMMON_DIALOGS
65 pd.lStructSize = sizeof( PRINTDLG );
66 pd.hwndOwner=(HWND) NULL;
67 pd.hDevMode=(HANDLE)NULL;
68 pd.hDevNames=(HANDLE)NULL;
69 pd.Flags=PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS;
75 pd.hInstance=(HINSTANCE)NULL;
77 if ( PrintDlg( &pd ) != 0 )
79 m_hDC = (WXHDC) pd.hDC;
88 // m_dontDelete = TRUE;
93 if ((!driver_name
.IsNull() && driver_name
!= T("")) &&
94 (!device_name
.IsNull() && device_name
!= T("")) &&
95 (!file
.IsNull() && file
!= T("")))
97 m_hDC
= (WXHDC
) ::DevOpenDC( hab
101 ,(PDEVOPENDATA
)&devOpen
104 m_ok
= m_hDC
? TRUE
: FALSE
;
108 wxPrintData printData
;
109 printData
.SetOrientation(orientation
);
110 m_hDC
= wxGetPrinterDC(printData
);
111 m_ok
= m_hDC
? TRUE
: FALSE
;
116 // int width = GetDeviceCaps(m_hDC, VERTRES);
117 // int height = GetDeviceCaps(m_hDC, HORZRES);
118 SetMapMode(wxMM_TEXT
);
120 SetBrush(*wxBLACK_BRUSH
);
121 SetPen(*wxBLACK_PEN
);
124 wxPrinterDC::wxPrinterDC(const wxPrintData
& printData
)
126 m_printData
= printData
;
128 m_isInteractive
= FALSE
;
130 m_hDC
= wxGetPrinterDC(printData
);
134 SetMapMode(wxMM_TEXT
);
136 SetBrush(*wxBLACK_BRUSH
);
137 SetPen(*wxBLACK_PEN
);
141 wxPrinterDC::wxPrinterDC(WXHDC theDC
)
143 m_isInteractive
= FALSE
;
149 // int width = GetDeviceCaps(m_hDC, VERTRES);
150 // int height = GetDeviceCaps(m_hDC, HORZRES);
151 SetMapMode(wxMM_TEXT
);
153 SetBrush(*wxBLACK_BRUSH
);
154 SetPen(*wxBLACK_PEN
);
157 wxPrinterDC::~wxPrinterDC(void)
161 bool wxPrinterDC::StartDoc(const wxString
& message
)
163 /* TODO: PM's implementation
165 docinfo.cbSize = sizeof(DOCINFO);
166 docinfo.lpszDocName = (const wxChar*)message;
168 wxString filename(m_printData.GetFilename());
170 if (filename.IsEmpty())
171 docinfo.lpszOutput = NULL;
173 docinfo.lpszOutput = (const wxChar *) filename;
175 #if defined(__WIN95__)
176 docinfo.lpszDatatype = NULL;
185 ::StartDoc((HDC) m_hDC, &docinfo);
188 ::StartDocW((HDC) m_hDC, &docinfo);
191 ::StartDoc((HDC) m_hDC, &docinfo);
193 ::StartDocA((HDC) m_hDC, &docinfo);
201 DWORD lastError = GetLastError();
202 wxLogDebug(T("wxDC::StartDoc failed with error: %d\n"), lastError);
210 void wxPrinterDC::EndDoc(void)
212 // if (m_hDC) ::EndDoc((HDC) m_hDC);
215 void wxPrinterDC::StartPage(void)
218 // ::StartPage((HDC) m_hDC);
221 void wxPrinterDC::EndPage(void)
224 // ::EndPage((HDC) m_hDC);
227 // Returns default device and port names
228 static bool wxGetDefaultDeviceName(wxString
& deviceName
, wxString
& portName
)
232 LPDEVNAMES lpDevNames;
233 LPSTR lpszDriverName;
234 LPSTR lpszDeviceName;
239 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
241 pd.lStructSize = 66; // sizeof(PRINTDLG);
243 pd.lStructSize = sizeof(PRINTDLG);
246 pd.hwndOwner = (HWND)NULL;
247 pd.hDevMode = NULL; // Will be created by PrintDlg
248 pd.hDevNames = NULL; // Ditto
249 pd.Flags = PD_RETURNDEFAULT;
252 if (!PrintDlg((LPPRINTDLG)&pd))
255 GlobalFree(pd.hDevMode);
257 GlobalFree(pd.hDevNames);
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);
272 deviceName = lpszDeviceName;
273 portName = lpszPortName;
278 GlobalFree(pd.hDevMode);
281 return ( deviceName != T("") );
286 // Gets an HDC for the specified printer configuration
287 WXHDC WXDLLEXPORT
wxGetPrinterDC(const wxPrintData
& printDataConst
)
291 wxPrintData printData = printDataConst;
292 printData.ConvertToNative();
294 wxChar* driverName = (wxChar*) NULL;
296 wxString devNameStr = printData.GetPrinterName();
298 wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32
300 if (devNameStr == T(""))
301 deviceName = (wxChar*) NULL;
303 deviceName = WXSTRINGCAST devNameStr;
305 LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
307 HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
310 lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
312 if (devNameStr == T(""))
314 // Retrieve the default device name
316 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
318 wxASSERT_MSG( ret, T("Could not get default device name.") );
320 deviceName = WXSTRINGCAST devNameStr;
324 HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
326 HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
329 if (hDevMode && lpDevMode)
330 GlobalUnlock(hDevMode);