]>
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
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #if wxUSE_PRINTING_ARCHITECTURE
16 #include "wx/dcprint.h"
17 #include "wx/os2/dcprint.h"
27 #include "wx/string.h"
29 #include "wx/window.h"
32 #include "wx/os2/private.h"
34 IMPLEMENT_ABSTRACT_CLASS(wxPrinterDCImpl
, wxPMDCImpl
)
36 wxPrinterDCImpl::wxPrinterDCImpl( wxPrinterDC
*owner
, const wxPrintData
& rPrintData
) :
39 m_printData
= rPrintData
;
40 m_isInteractive
= false;
41 m_hDC
= wxGetPrinterDC(rPrintData
);
44 SetMapMode(wxMM_TEXT
);
45 SetBrush(*wxBLACK_BRUSH
);
47 } // end of wxPrinterDC::wxPrinterDC
49 wxPrinterDCImpl::wxPrinterDCImpl( wxPrinterDC
*owner
, WXHDC hTheDC
) :
52 m_isInteractive
= false;
57 SetMapMode(wxMM_TEXT
);
59 SetBrush(*wxBLACK_BRUSH
);
61 } // end of wxPrinterDC::wxPrinterDC
63 void wxPrinterDCImpl::Init()
67 SetMapMode(wxMM_TEXT
);
69 SetBrush(*wxBLACK_BRUSH
);
72 } // end of wxPrinterDC::Init
74 bool wxPrinterDCImpl::StartDoc(const wxString
& WXUNUSED(rsMessage
))
76 /* TODO: PM's implementation
78 docinfo.cbSize = sizeof(DOCINFO);
79 docinfo.lpszDocName = (const wxChar*)message;
81 wxString filename(m_printData.GetFilename());
84 docinfo.lpszOutput = NULL;
86 docinfo.lpszOutput = (const wxChar *) filename;
88 docinfo.lpszDatatype = NULL;
96 ::StartDoc((HDC) m_hDC, &docinfo);
99 ::StartDocW((HDC) m_hDC, &docinfo);
102 ::StartDoc((HDC) m_hDC, &docinfo);
104 ::StartDocA((HDC) m_hDC, &docinfo);
112 DWORD lastError = GetLastError();
113 wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError);
119 } // end of wxPrinterDC::StartDoc
121 void wxPrinterDCImpl::EndDoc()
123 // if (m_hDC) ::EndDoc((HDC) m_hDC);
124 } // end of wxPrinterDC::EndDoc
126 void wxPrinterDCImpl::StartPage()
129 // ::StartPage((HDC) m_hDC);
130 } // end of wxPrinterDC::StartPage
132 void wxPrinterDCImpl::EndPage()
135 // ::EndPage((HDC) m_hDC);
136 } // end of wxPrinterDC::EndPage
138 wxRect
wxPrinterDCImpl::GetPaperRect() const
140 // Use page rect if we can't get paper rect.
143 return wxRect(0, 0, w
, h
);
147 // Returns default device and port names
148 static bool wxGetDefaultDeviceName( wxString
& rsDeviceName
, wxString
& rsPortName
)
150 rsDeviceName
= wxEmptyString
;
152 LPDEVNAMES lpDevNames;
153 LPSTR lpszDriverName;
154 LPSTR lpszDeviceName;
159 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
161 pd.lStructSize = 66; // sizeof(PRINTDLG);
163 pd.lStructSize = sizeof(PRINTDLG);
166 pd.hwndOwner = (HWND)NULL;
167 pd.hDevMode = NULL; // Will be created by PrintDlg
168 pd.hDevNames = NULL; // Ditto
169 pd.Flags = PD_RETURNDEFAULT;
172 if (!PrintDlg((LPPRINTDLG)&pd))
175 GlobalFree(pd.hDevMode);
177 GlobalFree(pd.hDevNames);
184 lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
185 lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
186 lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
187 lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;
188 GlobalUnlock(pd.hDevNames);
189 GlobalFree(pd.hDevNames);
192 deviceName = lpszDeviceName;
193 portName = lpszPortName;
198 GlobalFree(pd.hDevMode);
201 return !deviceName.empty();
204 } // end of wxGetDefaultDeviceName
207 // Gets an HDC for the specified printer configuration
208 WXHDC WXDLLEXPORT
wxGetPrinterDC( const wxPrintData
& WXUNUSED(rPrintDataConst
) )
210 HDC hDC
= NULLHANDLE
;
212 wxPrintData printData = printDataConst;
213 printData.ConvertToNative();
215 wxChar* driverName = NULL;
217 wxString devNameStr = printData.GetPrinterName();
219 wxChar* portName = NULL; // Obsolete in WIN32
221 if (devNameStr.empty())
224 deviceName = WXSTRINGCAST devNameStr;
226 LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
228 HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
231 lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
233 if (devNameStr.empty())
235 // Retrieve the default device name
237 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
239 wxASSERT_MSG( ret, wxT("Could not get default device name.") );
241 deviceName = WXSTRINGCAST devNameStr;
245 HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
247 HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
250 if (hDevMode && lpDevMode)
251 GlobalUnlock(hDevMode);
254 } // end of wxGetPrinterDC
256 void wxPrinterDCImpl::DoDrawBitmap( const wxBitmap
& rBmp
,
257 wxCoord
WXUNUSED(vX
),
258 wxCoord
WXUNUSED(vY
),
259 bool WXUNUSED(bUseMask
))
261 wxCHECK_RET( rBmp
.IsOk(), wxT("invalid bitmap in wxPrinterDC::DrawBitmap") );
263 // int nWidth = rBmp.GetWidth();
264 // int nHeight = rBmp.GetHeight();
268 } // end of wxPrinterDC::DoDrawBitmap
270 bool wxPrinterDCImpl::DoBlit( wxCoord
WXUNUSED(vXdest
),
271 wxCoord
WXUNUSED(vYdest
),
272 wxCoord
WXUNUSED(vWidth
),
273 wxCoord
WXUNUSED(vHeight
),
274 wxDC
* WXUNUSED(pSource
),
275 wxCoord
WXUNUSED(vXsrc
),
276 wxCoord
WXUNUSED(vYsrc
),
277 wxRasterOperationMode
WXUNUSED(nRop
),
278 bool WXUNUSED(bUseMask
),
279 wxCoord
WXUNUSED(xsrcMask
),
280 wxCoord
WXUNUSED(ysrcMask
) )
282 bool bSuccess
= true;
287 } // end of wxPrintDCImpl::DoBlit
289 #endif //wxUSE_PRINTING_ARCHITECTURE