]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/dcprint.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPrinterDC class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/string.h"
25 #include "wx/window.h"
26 #include "wx/os2/private.h"
27 #include "wx/dcprint.h"
30 IMPLEMENT_CLASS(wxPrinterDC
, wxDC
)
33 // This form is deprecated
34 wxPrinterDC::wxPrinterDC(const wxString
& driver_name
, const wxString
& device_name
, const wxString
& file
, bool interactive
, int orientation
)
38 DEVOPENSTRUC devOpen
= { (char*)device_name
.c_str()
39 ,(char*)driver_name
.c_str()
49 m_isInteractive
= interactive
;
51 if (!file
.IsNull() && file
!= wxT(""))
52 m_printData
.SetFilename(file
);
55 Implement PM's version of this
56 #if wxUSE_COMMON_DIALOGS
61 pd.lStructSize = sizeof( PRINTDLG );
62 pd.hwndOwner=(HWND) NULL;
63 pd.hDevMode=(HANDLE)NULL;
64 pd.hDevNames=(HANDLE)NULL;
65 pd.Flags=PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS;
71 pd.hInstance=(HINSTANCE)NULL;
73 if ( PrintDlg( &pd ) != 0 )
75 m_hDC = (WXHDC) pd.hDC;
84 // m_dontDelete = TRUE;
89 if ((!driver_name
.IsNull() && driver_name
!= wxT("")) &&
90 (!device_name
.IsNull() && device_name
!= wxT("")) &&
91 (!file
.IsNull() && file
!= wxT("")))
93 m_hDC
= (WXHDC
) ::DevOpenDC( hab
97 ,(PDEVOPENDATA
)&devOpen
100 m_ok
= m_hDC
? TRUE
: FALSE
;
104 wxPrintData printData
;
105 printData
.SetOrientation(orientation
);
106 m_hDC
= wxGetPrinterDC(printData
);
107 m_ok
= m_hDC
? TRUE
: FALSE
;
112 // int width = GetDeviceCaps(m_hDC, VERTRES);
113 // int height = GetDeviceCaps(m_hDC, HORZRES);
114 SetMapMode(wxMM_TEXT
);
116 SetBrush(*wxBLACK_BRUSH
);
117 SetPen(*wxBLACK_PEN
);
120 wxPrinterDC::wxPrinterDC(const wxPrintData
& printData
)
122 m_printData
= printData
;
124 m_isInteractive
= FALSE
;
126 m_hDC
= wxGetPrinterDC(printData
);
130 SetMapMode(wxMM_TEXT
);
132 SetBrush(*wxBLACK_BRUSH
);
133 SetPen(*wxBLACK_PEN
);
137 wxPrinterDC::wxPrinterDC(WXHDC theDC
)
139 m_isInteractive
= FALSE
;
145 // int width = GetDeviceCaps(m_hDC, VERTRES);
146 // int height = GetDeviceCaps(m_hDC, HORZRES);
147 SetMapMode(wxMM_TEXT
);
149 SetBrush(*wxBLACK_BRUSH
);
150 SetPen(*wxBLACK_PEN
);
153 wxPrinterDC::~wxPrinterDC(void)
157 bool wxPrinterDC::StartDoc(const wxString
& message
)
159 /* TODO: PM's implementation
161 docinfo.cbSize = sizeof(DOCINFO);
162 docinfo.lpszDocName = (const wxChar*)message;
164 wxString filename(m_printData.GetFilename());
166 if (filename.IsEmpty())
167 docinfo.lpszOutput = NULL;
169 docinfo.lpszOutput = (const wxChar *) filename;
171 #if defined(__WIN95__)
172 docinfo.lpszDatatype = NULL;
181 ::StartDoc((HDC) m_hDC, &docinfo);
184 ::StartDocW((HDC) m_hDC, &docinfo);
187 ::StartDoc((HDC) m_hDC, &docinfo);
189 ::StartDocA((HDC) m_hDC, &docinfo);
197 DWORD lastError = GetLastError();
198 wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError);
206 void wxPrinterDC::EndDoc(void)
208 // if (m_hDC) ::EndDoc((HDC) m_hDC);
211 void wxPrinterDC::StartPage(void)
214 // ::StartPage((HDC) m_hDC);
217 void wxPrinterDC::EndPage(void)
220 // ::EndPage((HDC) m_hDC);
223 // Returns default device and port names
224 static bool wxGetDefaultDeviceName(wxString
& deviceName
, wxString
& portName
)
228 LPDEVNAMES lpDevNames;
229 LPSTR lpszDriverName;
230 LPSTR lpszDeviceName;
235 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
237 pd.lStructSize = 66; // sizeof(PRINTDLG);
239 pd.lStructSize = sizeof(PRINTDLG);
242 pd.hwndOwner = (HWND)NULL;
243 pd.hDevMode = NULL; // Will be created by PrintDlg
244 pd.hDevNames = NULL; // Ditto
245 pd.Flags = PD_RETURNDEFAULT;
248 if (!PrintDlg((LPPRINTDLG)&pd))
251 GlobalFree(pd.hDevMode);
253 GlobalFree(pd.hDevNames);
260 lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
261 lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
262 lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
263 lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;
264 GlobalUnlock(pd.hDevNames);
265 GlobalFree(pd.hDevNames);
268 deviceName = lpszDeviceName;
269 portName = lpszPortName;
274 GlobalFree(pd.hDevMode);
277 return ( deviceName != wxT("") );
282 // Gets an HDC for the specified printer configuration
283 WXHDC WXDLLEXPORT
wxGetPrinterDC(const wxPrintData
& printDataConst
)
285 HDC hDC
= NULLHANDLE
;
287 wxPrintData printData = printDataConst;
288 printData.ConvertToNative();
290 wxChar* driverName = (wxChar*) NULL;
292 wxString devNameStr = printData.GetPrinterName();
294 wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32
296 if (devNameStr == wxT(""))
297 deviceName = (wxChar*) NULL;
299 deviceName = WXSTRINGCAST devNameStr;
301 LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
303 HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
306 lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
308 if (devNameStr == wxT(""))
310 // Retrieve the default device name
312 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
314 wxASSERT_MSG( ret, wxT("Could not get default device name.") );
316 deviceName = WXSTRINGCAST devNameStr;
320 HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
322 HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
325 if (hDevMode && lpDevMode)
326 GlobalUnlock(hDevMode);