]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/dcprint.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/dcprint.cpp
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"
25 #include "wx/string.h"
27 #include "wx/window.h"
28 #include "wx/os2/private.h"
29 #include "wx/dcprint.h"
31 #if wxUSE_PRINTING_ARCHITECTURE
33 IMPLEMENT_CLASS(wxPrinterDC
, wxDC
)
36 // This form is deprecated
37 wxPrinterDC::wxPrinterDC( const wxString
& rsDriverName
,
38 const wxString
& rsDeviceName
,
39 const wxString
& rsFile
,
43 DEVOPENSTRUC vDevOpen
= { (char*)rsDeviceName
.c_str()
44 ,(char*)rsDriverName
.c_str()
54 m_isInteractive
= bInteractive
;
56 if (!rsFile
.IsNull() && !rsFile
.empty())
57 m_printData
.SetFilename(rsFile
);
60 Implement PM's version of this
61 #if wxUSE_COMMON_DIALOGS
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;
76 pd.hInstance=(HINSTANCE)NULL;
78 if ( PrintDlg( &pd ) != 0 )
80 m_hDC = (WXHDC) pd.hDC;
92 if ( !rsDriverName
.empty() &&
93 !rsDeviceName
.empty() &&
96 m_hDC
= (WXHDC
) ::DevOpenDC( vHabmain
100 ,(PDEVOPENDATA
)&vDevOpen
103 m_ok
= m_hDC
? true: false;
107 wxPrintData vPrintData
;
109 vPrintData
.SetOrientation(nOrientation
);
110 m_hDC
= wxGetPrinterDC(vPrintData
);
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
);
122 } // end of wxPrinterDC::wxPrinterDC
124 wxPrinterDC::wxPrinterDC( const wxPrintData
& rPrintData
)
126 m_printData
= rPrintData
;
127 m_isInteractive
= false;
128 m_hDC
= wxGetPrinterDC(rPrintData
);
131 SetMapMode(wxMM_TEXT
);
132 SetBrush(*wxBLACK_BRUSH
);
133 SetPen(*wxBLACK_PEN
);
134 } // end of wxPrinterDC::wxPrinterDC
136 wxPrinterDC::wxPrinterDC( WXHDC hTheDC
)
138 m_isInteractive
= false;
143 SetMapMode(wxMM_TEXT
);
145 SetBrush(*wxBLACK_BRUSH
);
146 SetPen(*wxBLACK_PEN
);
147 } // end of wxPrinterDC::wxPrinterDC
149 void wxPrinterDC::Init()
153 SetMapMode(wxMM_TEXT
);
155 SetBrush(*wxBLACK_BRUSH
);
156 SetPen(*wxBLACK_PEN
);
158 } // end of wxPrinterDC::Init
160 bool wxPrinterDC::StartDoc(const wxString
& WXUNUSED(rsMessage
))
162 /* TODO: PM's implementation
164 docinfo.cbSize = sizeof(DOCINFO);
165 docinfo.lpszDocName = (const wxChar*)message;
167 wxString filename(m_printData.GetFilename());
169 if (filename.empty())
170 docinfo.lpszOutput = NULL;
172 docinfo.lpszOutput = (const wxChar *) filename;
174 #if defined(__WIN95__)
175 docinfo.lpszDatatype = NULL;
184 ::StartDoc((HDC) m_hDC, &docinfo);
187 ::StartDocW((HDC) m_hDC, &docinfo);
190 ::StartDoc((HDC) m_hDC, &docinfo);
192 ::StartDocA((HDC) m_hDC, &docinfo);
200 DWORD lastError = GetLastError();
201 wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError);
207 } // end of wxPrinterDC::StartDoc
209 void wxPrinterDC::EndDoc()
211 // if (m_hDC) ::EndDoc((HDC) m_hDC);
212 } // end of wxPrinterDC::EndDoc
214 void wxPrinterDC::StartPage()
217 // ::StartPage((HDC) m_hDC);
218 } // end of wxPrinterDC::StartPage
220 void wxPrinterDC::EndPage()
223 // ::EndPage((HDC) m_hDC);
224 } // end of wxPrinterDC::EndPage
226 // Returns default device and port names
227 static bool wxGetDefaultDeviceName( wxString
& rsDeviceName
, wxString
& rsPortName
)
229 rsDeviceName
= wxEmptyString
;
231 LPDEVNAMES lpDevNames;
232 LPSTR lpszDriverName;
233 LPSTR lpszDeviceName;
238 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
240 pd.lStructSize = 66; // sizeof(PRINTDLG);
242 pd.lStructSize = sizeof(PRINTDLG);
245 pd.hwndOwner = (HWND)NULL;
246 pd.hDevMode = NULL; // Will be created by PrintDlg
247 pd.hDevNames = NULL; // Ditto
248 pd.Flags = PD_RETURNDEFAULT;
251 if (!PrintDlg((LPPRINTDLG)&pd))
254 GlobalFree(pd.hDevMode);
256 GlobalFree(pd.hDevNames);
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);
271 deviceName = lpszDeviceName;
272 portName = lpszPortName;
277 GlobalFree(pd.hDevMode);
280 return ( deviceName != wxT("") );
283 } // end of wxGetDefaultDeviceName
286 // Gets an HDC for the specified printer configuration
287 WXHDC WXDLLEXPORT
wxGetPrinterDC( const wxPrintData
& WXUNUSED(rPrintDataConst
) )
289 HDC hDC
= NULLHANDLE
;
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.empty())
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.empty())
314 // Retrieve the default device name
316 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
318 wxASSERT_MSG( ret, wxT("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);
333 } // end of wxGetPrinterDC
335 void wxPrinterDC::DoDrawBitmap( const wxBitmap
& rBmp
,
336 wxCoord
WXUNUSED(vX
),
337 wxCoord
WXUNUSED(vY
),
338 bool WXUNUSED(bUseMask
))
340 wxCHECK_RET( rBmp
.Ok(), _T("invalid bitmap in wxPrinterDC::DrawBitmap") );
342 // int nWidth = rBmp.GetWidth();
343 // int nHeight = rBmp.GetHeight();
347 } // end of wxPrinterDC::DoDrawBitmap
349 bool 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
),
357 bool WXUNUSED(bUseMask
),
358 wxCoord
WXUNUSED(xsrcMask
),
359 wxCoord
WXUNUSED(ysrcMask
) )
361 bool bSuccess
= true;
366 } // end of wxPrintDC::DoBlit
368 #endif //wxUSE_PRINTING_ARCHITECTURE