]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/dcprint.cpp
1 /////////////////////////////////////////////////////////////////////////////
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"
24 #include "wx/string.h"
26 #include "wx/window.h"
27 #include "wx/os2/private.h"
28 #include "wx/dcprint.h"
31 #if wxUSE_PRINTING_ARCHITECTURE
33 IMPLEMENT_CLASS(wxPrinterDC
, wxDC
)
36 // This form is deprecated
37 wxPrinterDC::wxPrinterDC(
38 const wxString
& rsDriverName
39 , const wxString
& rsDeviceName
40 , const wxString
& rsFile
46 DEVOPENSTRUC vDevOpen
= { (char*)rsDeviceName
.c_str()
47 ,(char*)rsDriverName
.c_str()
57 m_isInteractive
= bInteractive
;
59 if (!rsFile
.IsNull() && rsFile
!= wxT(""))
60 m_printData
.SetFilename(rsFile
);
63 Implement PM's version of this
64 #if wxUSE_COMMON_DIALOGS
69 pd.lStructSize = sizeof( PRINTDLG );
70 pd.hwndOwner=(HWND) NULL;
71 pd.hDevMode=(HANDLE)NULL;
72 pd.hDevNames=(HANDLE)NULL;
73 pd.Flags=PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS;
79 pd.hInstance=(HINSTANCE)NULL;
81 if ( PrintDlg( &pd ) != 0 )
83 m_hDC = (WXHDC) pd.hDC;
92 // m_dontDelete = TRUE;
97 if ((!rsDriverName
.IsNull() && rsDriverName
!= wxT("")) &&
98 (!rsDeviceName
.IsNull() && rsDeviceName
!= wxT("")) &&
99 (!rsFile
.IsNull() && rsFile
!= wxT("")))
101 m_hDC
= (WXHDC
) ::DevOpenDC( vHabmain
105 ,(PDEVOPENDATA
)&vDevOpen
108 m_ok
= m_hDC
? TRUE
: FALSE
;
112 wxPrintData vPrintData
;
114 vPrintData
.SetOrientation(nOrientation
);
115 m_hDC
= wxGetPrinterDC(vPrintData
);
116 m_ok
= m_hDC
? TRUE
: FALSE
;
121 // int width = GetDeviceCaps(m_hDC, VERTRES);
122 // int height = GetDeviceCaps(m_hDC, HORZRES);
123 SetMapMode(wxMM_TEXT
);
125 SetBrush(*wxBLACK_BRUSH
);
126 SetPen(*wxBLACK_PEN
);
127 } // end of wxPrinterDC::wxPrinterDC
129 wxPrinterDC::wxPrinterDC(
130 const wxPrintData
& rPrintData
133 m_printData
= rPrintData
;
134 m_isInteractive
= FALSE
;
135 m_hDC
= wxGetPrinterDC(rPrintData
);
138 SetMapMode(wxMM_TEXT
);
139 SetBrush(*wxBLACK_BRUSH
);
140 SetPen(*wxBLACK_PEN
);
141 } // end of wxPrinterDC::wxPrinterDC
143 wxPrinterDC::wxPrinterDC(
147 m_isInteractive
= FALSE
;
152 SetMapMode(wxMM_TEXT
);
154 SetBrush(*wxBLACK_BRUSH
);
155 SetPen(*wxBLACK_PEN
);
156 } // end of wxPrinterDC::wxPrinterDC
158 void wxPrinterDC::Init()
162 SetMapMode(wxMM_TEXT
);
164 SetBrush(*wxBLACK_BRUSH
);
165 SetPen(*wxBLACK_PEN
);
167 } // end of wxPrinterDC::Init
169 bool wxPrinterDC::StartDoc(
170 const wxString
& rsMessage
173 /* TODO: PM's implementation
175 docinfo.cbSize = sizeof(DOCINFO);
176 docinfo.lpszDocName = (const wxChar*)message;
178 wxString filename(m_printData.GetFilename());
180 if (filename.IsEmpty())
181 docinfo.lpszOutput = NULL;
183 docinfo.lpszOutput = (const wxChar *) filename;
185 #if defined(__WIN95__)
186 docinfo.lpszDatatype = NULL;
195 ::StartDoc((HDC) m_hDC, &docinfo);
198 ::StartDocW((HDC) m_hDC, &docinfo);
201 ::StartDoc((HDC) m_hDC, &docinfo);
203 ::StartDocA((HDC) m_hDC, &docinfo);
211 DWORD lastError = GetLastError();
212 wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError);
218 } // end of wxPrinterDC::StartDoc
220 void wxPrinterDC::EndDoc()
222 // if (m_hDC) ::EndDoc((HDC) m_hDC);
223 } // end of wxPrinterDC::EndDoc
225 void wxPrinterDC::StartPage()
228 // ::StartPage((HDC) m_hDC);
229 } // end of wxPrinterDC::StartPage
231 void wxPrinterDC::EndPage()
234 // ::EndPage((HDC) m_hDC);
235 } // end of wxPrinterDC::EndPage
237 // Returns default device and port names
238 static bool wxGetDefaultDeviceName(
239 wxString
& rsDeviceName
240 , wxString
& rsPortName
245 LPDEVNAMES lpDevNames;
246 LPSTR lpszDriverName;
247 LPSTR lpszDeviceName;
252 // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68
254 pd.lStructSize = 66; // sizeof(PRINTDLG);
256 pd.lStructSize = sizeof(PRINTDLG);
259 pd.hwndOwner = (HWND)NULL;
260 pd.hDevMode = NULL; // Will be created by PrintDlg
261 pd.hDevNames = NULL; // Ditto
262 pd.Flags = PD_RETURNDEFAULT;
265 if (!PrintDlg((LPPRINTDLG)&pd))
268 GlobalFree(pd.hDevMode);
270 GlobalFree(pd.hDevNames);
277 lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
278 lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset;
279 lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
280 lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset;
281 GlobalUnlock(pd.hDevNames);
282 GlobalFree(pd.hDevNames);
285 deviceName = lpszDeviceName;
286 portName = lpszPortName;
291 GlobalFree(pd.hDevMode);
294 return ( deviceName != wxT("") );
297 } // end of wxGetDefaultDeviceName
299 // Gets an HDC for the specified printer configuration
300 WXHDC WXDLLEXPORT
wxGetPrinterDC(
301 const wxPrintData
& rPrintDataConst
304 HDC hDC
= NULLHANDLE
;
306 wxPrintData printData = printDataConst;
307 printData.ConvertToNative();
309 wxChar* driverName = (wxChar*) NULL;
311 wxString devNameStr = printData.GetPrinterName();
313 wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32
315 if (devNameStr == wxT(""))
316 deviceName = (wxChar*) NULL;
318 deviceName = WXSTRINGCAST devNameStr;
320 LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
322 HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
325 lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
327 if (devNameStr == wxT(""))
329 // Retrieve the default device name
331 bool ret = wxGetDefaultDeviceName(devNameStr, portName);
333 wxASSERT_MSG( ret, wxT("Could not get default device name.") );
335 deviceName = WXSTRINGCAST devNameStr;
339 HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
341 HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
344 if (hDevMode && lpDevMode)
345 GlobalUnlock(hDevMode);
348 } // end of wxGetPrinterDC
350 void wxPrinterDC::DoDrawBitmap(
357 wxCHECK_RET( rBmp
.Ok(), _T("invalid bitmap in wxPrinterDC::DrawBitmap") );
359 int nWidth
= rBmp
.GetWidth();
360 int nHeight
= rBmp
.GetHeight();
364 } // end of wxPrinterDC::DoDrawBitmap
366 bool wxPrinterDC::DoBlit(
380 bool bSuccess
= TRUE
;
385 } // end of wxPrintDC::DoBlit
388 #endif //wxUSE_PRINTING_ARCHITECTURE