]>
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 #if wxUSE_PRINTING_ARCHITECTURE
32 IMPLEMENT_CLASS(wxPrinterDC
, wxDC
)
35 // This form is deprecated
36 wxPrinterDC::wxPrinterDC(const wxString
& driver_name
, const wxString
& device_name
, const wxString
& file
, bool interactive
, int orientation
)
40 DEVOPENSTRUC devOpen
= { (char*)device_name
.c_str()
41 ,(char*)driver_name
.c_str()
51 m_isInteractive
= interactive
;
53 if (!file
.IsNull() && file
!= wxT(""))
54 m_printData
.SetFilename(file
);
57 Implement PM's version of this
58 #if wxUSE_COMMON_DIALOGS
63 pd.lStructSize = sizeof( PRINTDLG );
64 pd.hwndOwner=(HWND) NULL;
65 pd.hDevMode=(HANDLE)NULL;
66 pd.hDevNames=(HANDLE)NULL;
67 pd.Flags=PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS;
73 pd.hInstance=(HINSTANCE)NULL;
75 if ( PrintDlg( &pd ) != 0 )
77 m_hDC = (WXHDC) pd.hDC;
86 // m_dontDelete = TRUE;
91 if ((!driver_name
.IsNull() && driver_name
!= wxT("")) &&
92 (!device_name
.IsNull() && device_name
!= wxT("")) &&
93 (!file
.IsNull() && file
!= wxT("")))
95 m_hDC
= (WXHDC
) ::DevOpenDC( hab
99 ,(PDEVOPENDATA
)&devOpen
102 m_ok
= m_hDC
? TRUE
: FALSE
;
106 wxPrintData printData
;
107 printData
.SetOrientation(orientation
);
108 m_hDC
= wxGetPrinterDC(printData
);
109 m_ok
= m_hDC
? TRUE
: FALSE
;
114 // int width = GetDeviceCaps(m_hDC, VERTRES);
115 // int height = GetDeviceCaps(m_hDC, HORZRES);
116 SetMapMode(wxMM_TEXT
);
118 SetBrush(*wxBLACK_BRUSH
);
119 SetPen(*wxBLACK_PEN
);
122 wxPrinterDC::wxPrinterDC(const wxPrintData
& printData
)
124 m_printData
= printData
;
126 m_isInteractive
= FALSE
;
128 m_hDC
= wxGetPrinterDC(printData
);
132 SetMapMode(wxMM_TEXT
);
134 SetBrush(*wxBLACK_BRUSH
);
135 SetPen(*wxBLACK_PEN
);
139 wxPrinterDC::wxPrinterDC(WXHDC theDC
)
141 m_isInteractive
= FALSE
;
147 // int width = GetDeviceCaps(m_hDC, VERTRES);
148 // int height = GetDeviceCaps(m_hDC, HORZRES);
149 SetMapMode(wxMM_TEXT
);
151 SetBrush(*wxBLACK_BRUSH
);
152 SetPen(*wxBLACK_PEN
);
155 wxPrinterDC::~wxPrinterDC(void)
159 bool wxPrinterDC::StartDoc(const wxString
& message
)
161 /* TODO: PM's implementation
163 docinfo.cbSize = sizeof(DOCINFO);
164 docinfo.lpszDocName = (const wxChar*)message;
166 wxString filename(m_printData.GetFilename());
168 if (filename.IsEmpty())
169 docinfo.lpszOutput = NULL;
171 docinfo.lpszOutput = (const wxChar *) filename;
173 #if defined(__WIN95__)
174 docinfo.lpszDatatype = NULL;
183 ::StartDoc((HDC) m_hDC, &docinfo);
186 ::StartDocW((HDC) m_hDC, &docinfo);
189 ::StartDoc((HDC) m_hDC, &docinfo);
191 ::StartDocA((HDC) m_hDC, &docinfo);
199 DWORD lastError = GetLastError();
200 wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError);
208 void wxPrinterDC::EndDoc(void)
210 // if (m_hDC) ::EndDoc((HDC) m_hDC);
213 void wxPrinterDC::StartPage(void)
216 // ::StartPage((HDC) m_hDC);
219 void wxPrinterDC::EndPage(void)
222 // ::EndPage((HDC) m_hDC);
225 // Returns default device and port names
226 static bool wxGetDefaultDeviceName(wxString
& deviceName
, wxString
& portName
)
230 LPDEVNAMES lpDevNames;
231 LPSTR lpszDriverName;
232 LPSTR lpszDeviceName;
237 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
239 pd.lStructSize = 66; // sizeof(PRINTDLG);
241 pd.lStructSize = sizeof(PRINTDLG);
244 pd.hwndOwner = (HWND)NULL;
245 pd.hDevMode = NULL; // Will be created by PrintDlg
246 pd.hDevNames = NULL; // Ditto
247 pd.Flags = PD_RETURNDEFAULT;
250 if (!PrintDlg((LPPRINTDLG)&pd))
253 GlobalFree(pd.hDevMode);
255 GlobalFree(pd.hDevNames);
262 lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
263 lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
264 lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
265 lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;
266 GlobalUnlock(pd.hDevNames);
267 GlobalFree(pd.hDevNames);
270 deviceName = lpszDeviceName;
271 portName = lpszPortName;
276 GlobalFree(pd.hDevMode);
279 return ( deviceName != wxT("") );
284 // Gets an HDC for the specified printer configuration
285 WXHDC WXDLLEXPORT
wxGetPrinterDC(const wxPrintData
& printDataConst
)
287 HDC hDC
= NULLHANDLE
;
289 wxPrintData printData = printDataConst;
290 printData.ConvertToNative();
292 wxChar* driverName = (wxChar*) NULL;
294 wxString devNameStr = printData.GetPrinterName();
296 wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32
298 if (devNameStr == wxT(""))
299 deviceName = (wxChar*) NULL;
301 deviceName = WXSTRINGCAST devNameStr;
303 LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
305 HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
308 lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
310 if (devNameStr == wxT(""))
312 // Retrieve the default device name
314 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
316 wxASSERT_MSG( ret, wxT("Could not get default device name.") );
318 deviceName = WXSTRINGCAST devNameStr;
322 HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
324 HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
327 if (hDevMode && lpDevMode)
328 GlobalUnlock(hDevMode);
333 #endif //wxUSE_PRINTING_ARCHITECTURE