]>
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 wxRect
wxPrinterDC::GetPaperRect()
229 // Use page rect if we can't get paper rect.
232 return wxRect(0, 0, w
, h
);
236 // Returns default device and port names
237 static bool wxGetDefaultDeviceName( wxString
& rsDeviceName
, wxString
& rsPortName
)
239 rsDeviceName
= wxEmptyString
;
241 LPDEVNAMES lpDevNames;
242 LPSTR lpszDriverName;
243 LPSTR lpszDeviceName;
248 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
250 pd.lStructSize = 66; // sizeof(PRINTDLG);
252 pd.lStructSize = sizeof(PRINTDLG);
255 pd.hwndOwner = (HWND)NULL;
256 pd.hDevMode = NULL; // Will be created by PrintDlg
257 pd.hDevNames = NULL; // Ditto
258 pd.Flags = PD_RETURNDEFAULT;
261 if (!PrintDlg((LPPRINTDLG)&pd))
264 GlobalFree(pd.hDevMode);
266 GlobalFree(pd.hDevNames);
273 lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
274 lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
275 lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
276 lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;
277 GlobalUnlock(pd.hDevNames);
278 GlobalFree(pd.hDevNames);
281 deviceName = lpszDeviceName;
282 portName = lpszPortName;
287 GlobalFree(pd.hDevMode);
290 return !deviceName.empty();
293 } // end of wxGetDefaultDeviceName
296 // Gets an HDC for the specified printer configuration
297 WXHDC WXDLLEXPORT
wxGetPrinterDC( const wxPrintData
& WXUNUSED(rPrintDataConst
) )
299 HDC hDC
= NULLHANDLE
;
301 wxPrintData printData = printDataConst;
302 printData.ConvertToNative();
304 wxChar* driverName = (wxChar*) NULL;
306 wxString devNameStr = printData.GetPrinterName();
308 wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32
310 if (devNameStr.empty())
311 deviceName = (wxChar*) NULL;
313 deviceName = WXSTRINGCAST devNameStr;
315 LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
317 HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
320 lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
322 if (devNameStr.empty())
324 // Retrieve the default device name
326 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
328 wxASSERT_MSG( ret, wxT("Could not get default device name.") );
330 deviceName = WXSTRINGCAST devNameStr;
334 HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
336 HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
339 if (hDevMode && lpDevMode)
340 GlobalUnlock(hDevMode);
343 } // end of wxGetPrinterDC
345 void wxPrinterDC::DoDrawBitmap( const wxBitmap
& rBmp
,
346 wxCoord
WXUNUSED(vX
),
347 wxCoord
WXUNUSED(vY
),
348 bool WXUNUSED(bUseMask
))
350 wxCHECK_RET( rBmp
.Ok(), _T("invalid bitmap in wxPrinterDC::DrawBitmap") );
352 // int nWidth = rBmp.GetWidth();
353 // int nHeight = rBmp.GetHeight();
357 } // end of wxPrinterDC::DoDrawBitmap
359 bool wxPrinterDC::DoBlit( wxCoord
WXUNUSED(vXdest
),
360 wxCoord
WXUNUSED(vYdest
),
361 wxCoord
WXUNUSED(vWidth
),
362 wxCoord
WXUNUSED(vHeight
),
363 wxDC
* WXUNUSED(pSource
),
364 wxCoord
WXUNUSED(vXsrc
),
365 wxCoord
WXUNUSED(vYsrc
),
367 bool WXUNUSED(bUseMask
),
368 wxCoord
WXUNUSED(xsrcMask
),
369 wxCoord
WXUNUSED(ysrcMask
) )
371 bool bSuccess
= true;
376 } // end of wxPrintDC::DoBlit
378 #endif //wxUSE_PRINTING_ARCHITECTURE