]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/dcprint.cpp
1e26861b14bee6da7ce694ed913bf5ef87f74e96
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 docinfo.lpszDatatype = NULL;
97 ::StartDoc((HDC) m_hDC, &docinfo);
100 ::StartDocW((HDC) m_hDC, &docinfo);
103 ::StartDoc((HDC) m_hDC, &docinfo);
105 ::StartDocA((HDC) m_hDC, &docinfo);
113 DWORD lastError = GetLastError();
114 wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError);
120 } // end of wxPrinterDC::StartDoc
122 void wxPrinterDCImpl::EndDoc()
124 // if (m_hDC) ::EndDoc((HDC) m_hDC);
125 } // end of wxPrinterDC::EndDoc
127 void wxPrinterDCImpl::StartPage()
130 // ::StartPage((HDC) m_hDC);
131 } // end of wxPrinterDC::StartPage
133 void wxPrinterDCImpl::EndPage()
136 // ::EndPage((HDC) m_hDC);
137 } // end of wxPrinterDC::EndPage
139 wxRect
wxPrinterDCImpl::GetPaperRect() const
141 // Use page rect if we can't get paper rect.
144 return wxRect(0, 0, w
, h
);
148 // Returns default device and port names
149 static bool wxGetDefaultDeviceName( wxString
& rsDeviceName
, wxString
& rsPortName
)
151 rsDeviceName
= wxEmptyString
;
153 LPDEVNAMES lpDevNames;
154 LPSTR lpszDriverName;
155 LPSTR lpszDeviceName;
160 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
162 pd.lStructSize = 66; // sizeof(PRINTDLG);
164 pd.lStructSize = sizeof(PRINTDLG);
167 pd.hwndOwner = (HWND)NULL;
168 pd.hDevMode = NULL; // Will be created by PrintDlg
169 pd.hDevNames = NULL; // Ditto
170 pd.Flags = PD_RETURNDEFAULT;
173 if (!PrintDlg((LPPRINTDLG)&pd))
176 GlobalFree(pd.hDevMode);
178 GlobalFree(pd.hDevNames);
185 lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
186 lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
187 lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
188 lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;
189 GlobalUnlock(pd.hDevNames);
190 GlobalFree(pd.hDevNames);
193 deviceName = lpszDeviceName;
194 portName = lpszPortName;
199 GlobalFree(pd.hDevMode);
202 return !deviceName.empty();
205 } // end of wxGetDefaultDeviceName
208 // Gets an HDC for the specified printer configuration
209 WXHDC WXDLLEXPORT
wxGetPrinterDC( const wxPrintData
& WXUNUSED(rPrintDataConst
) )
211 HDC hDC
= NULLHANDLE
;
213 wxPrintData printData = printDataConst;
214 printData.ConvertToNative();
216 wxChar* driverName = NULL;
218 wxString devNameStr = printData.GetPrinterName();
220 wxChar* portName = NULL; // Obsolete in WIN32
222 if (devNameStr.empty())
225 deviceName = WXSTRINGCAST devNameStr;
227 LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
229 HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
232 lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
234 if (devNameStr.empty())
236 // Retrieve the default device name
238 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
240 wxASSERT_MSG( ret, wxT("Could not get default device name.") );
242 deviceName = WXSTRINGCAST devNameStr;
246 HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
248 HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
251 if (hDevMode && lpDevMode)
252 GlobalUnlock(hDevMode);
255 } // end of wxGetPrinterDC
257 void wxPrinterDCImpl::DoDrawBitmap( const wxBitmap
& rBmp
,
258 wxCoord
WXUNUSED(vX
),
259 wxCoord
WXUNUSED(vY
),
260 bool WXUNUSED(bUseMask
))
262 wxCHECK_RET( rBmp
.IsOk(), wxT("invalid bitmap in wxPrinterDC::DrawBitmap") );
264 // int nWidth = rBmp.GetWidth();
265 // int nHeight = rBmp.GetHeight();
269 } // end of wxPrinterDC::DoDrawBitmap
271 bool wxPrinterDCImpl::DoBlit( wxCoord
WXUNUSED(vXdest
),
272 wxCoord
WXUNUSED(vYdest
),
273 wxCoord
WXUNUSED(vWidth
),
274 wxCoord
WXUNUSED(vHeight
),
275 wxDC
* WXUNUSED(pSource
),
276 wxCoord
WXUNUSED(vXsrc
),
277 wxCoord
WXUNUSED(vYsrc
),
278 wxRasterOperationMode
WXUNUSED(nRop
),
279 bool WXUNUSED(bUseMask
),
280 wxCoord
WXUNUSED(xsrcMask
),
281 wxCoord
WXUNUSED(ysrcMask
) )
283 bool bSuccess
= true;
288 } // end of wxPrintDCImpl::DoBlit
290 #endif //wxUSE_PRINTING_ARCHITECTURE