]>
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
 
  45     DEVOPENSTRUC    vDevOpen 
= { (char*)rsDeviceName
.c_str() 
  46                                 ,(char*)rsDriverName
.c_str() 
  56     m_isInteractive 
= bInteractive
; 
  58     if (!rsFile
.IsNull() && rsFile 
!= wxT("")) 
  59         m_printData
.SetFilename(rsFile
); 
  62     Implement PM's version of this 
  63 #if wxUSE_COMMON_DIALOGS 
  68         pd.lStructSize = sizeof( PRINTDLG ); 
  69         pd.hwndOwner=(HWND) NULL; 
  70         pd.hDevMode=(HANDLE)NULL; 
  71         pd.hDevNames=(HANDLE)NULL; 
  72         pd.Flags=PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS; 
  78         pd.hInstance=(HINSTANCE)NULL; 
  80         if ( PrintDlg( &pd ) != 0 ) 
  82             m_hDC = (WXHDC) pd.hDC; 
  91         //     m_dontDelete = TRUE; 
  96         if ((!rsDriverName
.IsNull() && rsDriverName 
!= wxT("")) && 
  97             (!rsDeviceName
.IsNull() && rsDeviceName 
!= wxT("")) && 
  98             (!rsFile
.IsNull() && rsFile 
!= wxT(""))) 
 100             m_hDC 
= (WXHDC
) ::DevOpenDC( vHabmain
 
 104                                         ,(PDEVOPENDATA
)&vDevOpen
 
 107             m_ok 
= m_hDC 
? TRUE
: FALSE
; 
 111             wxPrintData             vPrintData
; 
 113             vPrintData
.SetOrientation(nOrientation
); 
 114             m_hDC 
= wxGetPrinterDC(vPrintData
); 
 115             m_ok 
= m_hDC 
? TRUE
: FALSE
; 
 120             //     int width = GetDeviceCaps(m_hDC, VERTRES); 
 121             //     int height = GetDeviceCaps(m_hDC, HORZRES); 
 122             SetMapMode(wxMM_TEXT
); 
 124         SetBrush(*wxBLACK_BRUSH
); 
 125         SetPen(*wxBLACK_PEN
); 
 126 } // end of wxPrinterDC::wxPrinterDC 
 128 wxPrinterDC::wxPrinterDC( 
 129   const wxPrintData
&                rPrintData
 
 132     m_printData 
= rPrintData
; 
 133     m_isInteractive 
= FALSE
; 
 134     m_hDC 
= wxGetPrinterDC(rPrintData
); 
 137         SetMapMode(wxMM_TEXT
); 
 138     SetBrush(*wxBLACK_BRUSH
); 
 139     SetPen(*wxBLACK_PEN
); 
 140 } // end of wxPrinterDC::wxPrinterDC 
 142 wxPrinterDC::wxPrinterDC( 
 146     m_isInteractive 
= FALSE
; 
 151         SetMapMode(wxMM_TEXT
); 
 153     SetBrush(*wxBLACK_BRUSH
); 
 154     SetPen(*wxBLACK_PEN
); 
 155 } // end of wxPrinterDC::wxPrinterDC 
 157 void wxPrinterDC::Init() 
 161         SetMapMode(wxMM_TEXT
); 
 163         SetBrush(*wxBLACK_BRUSH
); 
 164         SetPen(*wxBLACK_PEN
); 
 166 } // end of wxPrinterDC::Init 
 168 bool wxPrinterDC::StartDoc( 
 169   const wxString
&                   rsMessage
 
 172 /* TODO:  PM's implementation 
 174     docinfo.cbSize = sizeof(DOCINFO); 
 175     docinfo.lpszDocName = (const wxChar*)message; 
 177     wxString filename(m_printData.GetFilename()); 
 179     if (filename.IsEmpty()) 
 180         docinfo.lpszOutput = NULL; 
 182         docinfo.lpszOutput = (const wxChar *) filename; 
 184 #if defined(__WIN95__) 
 185     docinfo.lpszDatatype = NULL; 
 194         ::StartDoc((HDC) m_hDC, &docinfo); 
 197     ::StartDocW((HDC) m_hDC, &docinfo); 
 200     ::StartDoc((HDC) m_hDC, &docinfo); 
 202     ::StartDocA((HDC) m_hDC, &docinfo); 
 210         DWORD lastError = GetLastError(); 
 211         wxLogDebug(wxT("wxDC::StartDoc failed with error: %d\n"), lastError); 
 217 } // end of wxPrinterDC::StartDoc 
 219 void wxPrinterDC::EndDoc() 
 221 //    if (m_hDC) ::EndDoc((HDC) m_hDC); 
 222 } // end of wxPrinterDC::EndDoc 
 224 void wxPrinterDC::StartPage() 
 227 //        ::StartPage((HDC) m_hDC); 
 228 } // end of wxPrinterDC::StartPage 
 230 void wxPrinterDC::EndPage() 
 233 //        ::EndPage((HDC) m_hDC); 
 234 } // end of wxPrinterDC::EndPage 
 236 // Returns default device and port names 
 237 static bool wxGetDefaultDeviceName( 
 238   wxString
&                         rsDeviceName
 
 239 , wxString
&                         rsPortName
 
 244     LPDEVNAMES  lpDevNames; 
 245     LPSTR       lpszDriverName; 
 246     LPSTR       lpszDeviceName; 
 251     // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68 
 253     pd.lStructSize    = 66; // sizeof(PRINTDLG); 
 255     pd.lStructSize    = sizeof(PRINTDLG); 
 258     pd.hwndOwner      = (HWND)NULL; 
 259     pd.hDevMode       = NULL; // Will be created by PrintDlg 
 260     pd.hDevNames      = NULL; // Ditto 
 261     pd.Flags          = PD_RETURNDEFAULT; 
 264     if (!PrintDlg((LPPRINTDLG)&pd)) 
 267             GlobalFree(pd.hDevMode); 
 269             GlobalFree(pd.hDevNames); 
 276         lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames); 
 277         lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset; 
 278         lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset; 
 279         lpszPortName   = (LPSTR)lpDevNames + lpDevNames->wOutputOffset; 
 280         GlobalUnlock(pd.hDevNames); 
 281         GlobalFree(pd.hDevNames); 
 284         deviceName = lpszDeviceName; 
 285         portName = lpszPortName; 
 290         GlobalFree(pd.hDevMode); 
 293     return ( deviceName != wxT("") ); 
 296 } // 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