]>
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"
27 #include "wx/string.h"
29 #include "wx/window.h"
32 #include "wx/os2/private.h"
34 IMPLEMENT_CLASS(wxPrinterDC
, wxDC
)
37 // This form is deprecated
38 wxPrinterDC::wxPrinterDC( const wxString
& rsDriverName
,
39 const wxString
& rsDeviceName
,
40 const wxString
& rsFile
,
44 DEVOPENSTRUC vDevOpen
= { (char*)rsDeviceName
.c_str()
45 ,(char*)rsDriverName
.c_str()
55 m_isInteractive
= bInteractive
;
57 if (!rsFile
.IsNull() && !rsFile
.empty())
58 m_printData
.SetFilename(rsFile
);
61 Implement PM's version of this
62 #if wxUSE_COMMON_DIALOGS
67 pd.lStructSize = sizeof( PRINTDLG );
68 pd.hwndOwner=(HWND) NULL;
69 pd.hDevMode=(HANDLE)NULL;
70 pd.hDevNames=(HANDLE)NULL;
71 pd.Flags=PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS;
77 pd.hInstance=(HINSTANCE)NULL;
79 if ( PrintDlg( &pd ) != 0 )
81 m_hDC = (WXHDC) pd.hDC;
93 if ( !rsDriverName
.empty() &&
94 !rsDeviceName
.empty() &&
97 m_hDC
= (WXHDC
) ::DevOpenDC( vHabmain
101 ,(PDEVOPENDATA
)&vDevOpen
104 m_ok
= m_hDC
? true: false;
108 wxPrintData vPrintData
;
110 vPrintData
.SetOrientation(nOrientation
);
111 m_hDC
= wxGetPrinterDC(vPrintData
);
112 m_ok
= m_hDC
? true: false;
117 // int width = GetDeviceCaps(m_hDC, VERTRES);
118 // int height = GetDeviceCaps(m_hDC, HORZRES);
119 SetMapMode(wxMM_TEXT
);
121 SetBrush(*wxBLACK_BRUSH
);
122 SetPen(*wxBLACK_PEN
);
123 } // end of wxPrinterDC::wxPrinterDC
125 wxPrinterDC::wxPrinterDC( const wxPrintData
& rPrintData
)
127 m_printData
= rPrintData
;
128 m_isInteractive
= false;
129 m_hDC
= wxGetPrinterDC(rPrintData
);
132 SetMapMode(wxMM_TEXT
);
133 SetBrush(*wxBLACK_BRUSH
);
134 SetPen(*wxBLACK_PEN
);
135 } // end of wxPrinterDC::wxPrinterDC
137 wxPrinterDC::wxPrinterDC( WXHDC hTheDC
)
139 m_isInteractive
= false;
144 SetMapMode(wxMM_TEXT
);
146 SetBrush(*wxBLACK_BRUSH
);
147 SetPen(*wxBLACK_PEN
);
148 } // end of wxPrinterDC::wxPrinterDC
150 void wxPrinterDC::Init()
154 SetMapMode(wxMM_TEXT
);
156 SetBrush(*wxBLACK_BRUSH
);
157 SetPen(*wxBLACK_PEN
);
159 } // end of wxPrinterDC::Init
161 bool wxPrinterDC::StartDoc(const wxString
& WXUNUSED(rsMessage
))
163 /* TODO: PM's implementation
165 docinfo.cbSize = sizeof(DOCINFO);
166 docinfo.lpszDocName = (const wxChar*)message;
168 wxString filename(m_printData.GetFilename());
170 if (filename.empty())
171 docinfo.lpszOutput = NULL;
173 docinfo.lpszOutput = (const wxChar *) filename;
175 #if defined(__WIN95__)
176 docinfo.lpszDatatype = NULL;
185 ::StartDoc((HDC) m_hDC, &docinfo);
188 ::StartDocW((HDC) m_hDC, &docinfo);
191 ::StartDoc((HDC) m_hDC, &docinfo);
193 ::StartDocA((HDC) m_hDC, &docinfo);
201 DWORD lastError = GetLastError();
202 wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError);
208 } // end of wxPrinterDC::StartDoc
210 void wxPrinterDC::EndDoc()
212 // if (m_hDC) ::EndDoc((HDC) m_hDC);
213 } // end of wxPrinterDC::EndDoc
215 void wxPrinterDC::StartPage()
218 // ::StartPage((HDC) m_hDC);
219 } // end of wxPrinterDC::StartPage
221 void wxPrinterDC::EndPage()
224 // ::EndPage((HDC) m_hDC);
225 } // end of wxPrinterDC::EndPage
227 // Returns default device and port names
228 static bool wxGetDefaultDeviceName( wxString
& rsDeviceName
, wxString
& rsPortName
)
230 rsDeviceName
= wxEmptyString
;
232 LPDEVNAMES lpDevNames;
233 LPSTR lpszDriverName;
234 LPSTR lpszDeviceName;
239 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
241 pd.lStructSize = 66; // sizeof(PRINTDLG);
243 pd.lStructSize = sizeof(PRINTDLG);
246 pd.hwndOwner = (HWND)NULL;
247 pd.hDevMode = NULL; // Will be created by PrintDlg
248 pd.hDevNames = NULL; // Ditto
249 pd.Flags = PD_RETURNDEFAULT;
252 if (!PrintDlg((LPPRINTDLG)&pd))
255 GlobalFree(pd.hDevMode);
257 GlobalFree(pd.hDevNames);
264 lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
265 lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
266 lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
267 lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;
268 GlobalUnlock(pd.hDevNames);
269 GlobalFree(pd.hDevNames);
272 deviceName = lpszDeviceName;
273 portName = lpszPortName;
278 GlobalFree(pd.hDevMode);
281 return !deviceName.empty();
284 } // end of wxGetDefaultDeviceName
287 // Gets an HDC for the specified printer configuration
288 WXHDC WXDLLEXPORT
wxGetPrinterDC( const wxPrintData
& WXUNUSED(rPrintDataConst
) )
290 HDC hDC
= NULLHANDLE
;
292 wxPrintData printData = printDataConst;
293 printData.ConvertToNative();
295 wxChar* driverName = (wxChar*) NULL;
297 wxString devNameStr = printData.GetPrinterName();
299 wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32
301 if (devNameStr.empty())
302 deviceName = (wxChar*) NULL;
304 deviceName = WXSTRINGCAST devNameStr;
306 LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
308 HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
311 lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
313 if (devNameStr.empty())
315 // Retrieve the default device name
317 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
319 wxASSERT_MSG( ret, wxT("Could not get default device name.") );
321 deviceName = WXSTRINGCAST devNameStr;
325 HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
327 HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
330 if (hDevMode && lpDevMode)
331 GlobalUnlock(hDevMode);
334 } // end of wxGetPrinterDC
336 void wxPrinterDC::DoDrawBitmap( const wxBitmap
& rBmp
,
337 wxCoord
WXUNUSED(vX
),
338 wxCoord
WXUNUSED(vY
),
339 bool WXUNUSED(bUseMask
))
341 wxCHECK_RET( rBmp
.Ok(), _T("invalid bitmap in wxPrinterDC::DrawBitmap") );
343 // int nWidth = rBmp.GetWidth();
344 // int nHeight = rBmp.GetHeight();
348 } // end of wxPrinterDC::DoDrawBitmap
350 bool wxPrinterDC::DoBlit( wxCoord
WXUNUSED(vXdest
),
351 wxCoord
WXUNUSED(vYdest
),
352 wxCoord
WXUNUSED(vWidth
),
353 wxCoord
WXUNUSED(vHeight
),
354 wxDC
* WXUNUSED(pSource
),
355 wxCoord
WXUNUSED(vXsrc
),
356 wxCoord
WXUNUSED(vYsrc
),
358 bool WXUNUSED(bUseMask
),
359 wxCoord
WXUNUSED(xsrcMask
),
360 wxCoord
WXUNUSED(ysrcMask
) )
362 bool bSuccess
= true;
367 } // end of wxPrintDC::DoBlit
369 #endif //wxUSE_PRINTING_ARCHITECTURE