]>
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"
15 #if wxUSE_PRINTING_ARCHITECTURE
17 #include "wx/dcprint.h"
18 #include "wx/os2/dcprint.h"
28 #include "wx/string.h"
30 #include "wx/window.h"
33 #include "wx/os2/private.h"
35 IMPLEMENT_ABSTRACT_CLASS(wxPrinterDCImpl
, wxPMDCImpl
)
37 wxPrinterDCImpl::wxPrinterDCImpl( wxPrinterDC
*owner
, const wxPrintData
& rPrintData
) :
40 m_printData
= rPrintData
;
41 m_isInteractive
= false;
42 m_hDC
= wxGetPrinterDC(rPrintData
);
45 SetMapMode(wxMM_TEXT
);
46 SetBrush(*wxBLACK_BRUSH
);
48 } // end of wxPrinterDC::wxPrinterDC
50 wxPrinterDCImpl::wxPrinterDCImpl( wxPrinterDC
*owner
, WXHDC hTheDC
) :
53 m_isInteractive
= false;
58 SetMapMode(wxMM_TEXT
);
60 SetBrush(*wxBLACK_BRUSH
);
62 } // end of wxPrinterDC::wxPrinterDC
64 void wxPrinterDCImpl::Init()
68 SetMapMode(wxMM_TEXT
);
70 SetBrush(*wxBLACK_BRUSH
);
73 } // end of wxPrinterDC::Init
75 bool wxPrinterDCImpl::StartDoc(const wxString
& WXUNUSED(rsMessage
))
77 /* TODO: PM's implementation
79 docinfo.cbSize = sizeof(DOCINFO);
80 docinfo.lpszDocName = (const wxChar*)message;
82 wxString filename(m_printData.GetFilename());
85 docinfo.lpszOutput = NULL;
87 docinfo.lpszOutput = (const wxChar *) filename;
89 #if defined(__WIN95__)
90 docinfo.lpszDatatype = NULL;
99 ::StartDoc((HDC) m_hDC, &docinfo);
102 ::StartDocW((HDC) m_hDC, &docinfo);
105 ::StartDoc((HDC) m_hDC, &docinfo);
107 ::StartDocA((HDC) m_hDC, &docinfo);
115 DWORD lastError = GetLastError();
116 wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError);
122 } // end of wxPrinterDC::StartDoc
124 void wxPrinterDCImpl::EndDoc()
126 // if (m_hDC) ::EndDoc((HDC) m_hDC);
127 } // end of wxPrinterDC::EndDoc
129 void wxPrinterDCImpl::StartPage()
132 // ::StartPage((HDC) m_hDC);
133 } // end of wxPrinterDC::StartPage
135 void wxPrinterDCImpl::EndPage()
138 // ::EndPage((HDC) m_hDC);
139 } // end of wxPrinterDC::EndPage
141 wxRect
wxPrinterDCImpl::GetPaperRect() const
143 // Use page rect if we can't get paper rect.
146 return wxRect(0, 0, w
, h
);
150 // Returns default device and port names
151 static bool wxGetDefaultDeviceName( wxString
& rsDeviceName
, wxString
& rsPortName
)
153 rsDeviceName
= wxEmptyString
;
155 LPDEVNAMES lpDevNames;
156 LPSTR lpszDriverName;
157 LPSTR lpszDeviceName;
162 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
164 pd.lStructSize = 66; // sizeof(PRINTDLG);
166 pd.lStructSize = sizeof(PRINTDLG);
169 pd.hwndOwner = (HWND)NULL;
170 pd.hDevMode = NULL; // Will be created by PrintDlg
171 pd.hDevNames = NULL; // Ditto
172 pd.Flags = PD_RETURNDEFAULT;
175 if (!PrintDlg((LPPRINTDLG)&pd))
178 GlobalFree(pd.hDevMode);
180 GlobalFree(pd.hDevNames);
187 lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
188 lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
189 lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
190 lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;
191 GlobalUnlock(pd.hDevNames);
192 GlobalFree(pd.hDevNames);
195 deviceName = lpszDeviceName;
196 portName = lpszPortName;
201 GlobalFree(pd.hDevMode);
204 return !deviceName.empty();
207 } // end of wxGetDefaultDeviceName
210 // Gets an HDC for the specified printer configuration
211 WXHDC WXDLLEXPORT
wxGetPrinterDC( const wxPrintData
& WXUNUSED(rPrintDataConst
) )
213 HDC hDC
= NULLHANDLE
;
215 wxPrintData printData = printDataConst;
216 printData.ConvertToNative();
218 wxChar* driverName = (wxChar*) NULL;
220 wxString devNameStr = printData.GetPrinterName();
222 wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32
224 if (devNameStr.empty())
225 deviceName = (wxChar*) NULL;
227 deviceName = WXSTRINGCAST devNameStr;
229 LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
231 HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
234 lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
236 if (devNameStr.empty())
238 // Retrieve the default device name
240 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
242 wxASSERT_MSG( ret, wxT("Could not get default device name.") );
244 deviceName = WXSTRINGCAST devNameStr;
248 HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
250 HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
253 if (hDevMode && lpDevMode)
254 GlobalUnlock(hDevMode);
257 } // end of wxGetPrinterDC
259 void wxPrinterDCImpl::DoDrawBitmap( const wxBitmap
& rBmp
,
260 wxCoord
WXUNUSED(vX
),
261 wxCoord
WXUNUSED(vY
),
262 bool WXUNUSED(bUseMask
))
264 wxCHECK_RET( rBmp
.Ok(), _T("invalid bitmap in wxPrinterDC::DrawBitmap") );
266 // int nWidth = rBmp.GetWidth();
267 // int nHeight = rBmp.GetHeight();
271 } // end of wxPrinterDC::DoDrawBitmap
273 bool wxPrinterDCImpl::DoBlit( wxCoord
WXUNUSED(vXdest
),
274 wxCoord
WXUNUSED(vYdest
),
275 wxCoord
WXUNUSED(vWidth
),
276 wxCoord
WXUNUSED(vHeight
),
277 wxDC
* WXUNUSED(pSource
),
278 wxCoord
WXUNUSED(vXsrc
),
279 wxCoord
WXUNUSED(vYsrc
),
280 wxRasterOperationMode
WXUNUSED(nRop
),
281 bool WXUNUSED(bUseMask
),
282 wxCoord
WXUNUSED(xsrcMask
),
283 wxCoord
WXUNUSED(ysrcMask
) )
285 bool bSuccess
= true;
290 } // end of wxPrintDCImpl::DoBlit
292 #endif //wxUSE_PRINTING_ARCHITECTURE