]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/statbmp.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxStaticBitmap 
   4 // Author:      David Webster 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "statbmp.h" 
  16 // For compilers that support precompilation, includes "wx.h". 
  17 #include "wx/wxprec.h" 
  19 #include "wx/dcclient.h" 
  20 #include "wx/window.h" 
  21 #include "wx/os2/private.h" 
  25     #include "wx/statbmp.h" 
  30 // --------------------------------------------------------------------------- 
  32 // --------------------------------------------------------------------------- 
  34 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap
, wxControl
) 
  36 BEGIN_EVENT_TABLE(wxStaticBitmap
, wxWindow
) 
  37     EVT_PAINT(wxStaticBitmap::OnPaint
) 
  40 static wxGDIImage
* ConvertImage( 
  41   const wxGDIImage
&                 rBitmap
 
  44     bool                            bIsIcon 
= rBitmap
.IsKindOf( CLASSINFO(wxIcon
) ); 
  48         wxASSERT_MSG( wxDynamicCast(&rBitmap
, wxBitmap
), 
  49                       _T("not an icon and not a bitmap?") ); 
  51         const wxBitmap
&             rBmp 
= (const wxBitmap
&)rBitmap
; 
  52         wxMask
*                     pMask 
= rBmp
.GetMask(); 
  54         if (pMask 
&& pMask
->GetMaskBitmap()) 
  56             wxIcon
*                 pIcon 
= new wxIcon
; 
  58             pIcon
->CopyFromBitmap(rBmp
); 
  61         return new wxBitmap(rBmp
); 
  64     // copying a bitmap is a cheap operation 
  65     return new wxIcon( (const wxIcon
&)rBitmap 
); 
  66 } // end of ConvertImage 
  68 // --------------------------------------------------------------------------- 
  70 // --------------------------------------------------------------------------- 
  72 bool wxStaticBitmap::Create( 
  75 , const wxGDIImage
&                 rBitmap
 
  79 , const wxString
&                   rName
 
  89         pParent
->AddChild(this); 
  92         m_windowId 
= (int)NewControlId(); 
  96     m_windowStyle 
= lStyle
; 
 102     m_windowStyle 
= lStyle
; 
 104     m_bIsIcon 
= rBitmap
.IsKindOf(CLASSINFO(wxIcon
)); 
 107     // For now we only support an ICON 
 109     int                             nWinstyle 
= SS_ICON
; 
 111     m_hWnd 
= (WXHWND
)::WinCreateWindow( pParent
->GetHWND() 
 114                                        ,nWinstyle 
| WS_VISIBLE
 
 124         vError 
= ::WinGetLastError(wxGetInstance()); 
 125         sError 
= wxPMErrorToStr(vError
); 
 128     wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create static bitmap") ); 
 129     m_pImage 
= ConvertImage(rBitmap
); 
 130     m_pImage
->SetHandle((WXHWND
)::WinSendMsg(m_hWnd
, SM_QUERYHANDLE
, (MPARAM
)0, (MPARAM
)0)); 
 132     // Subclass again for purposes of dialog editing mode 
 134     SetSize(nX
, nY
, m_pImage
->GetWidth(), m_pImage
->GetHeight()); 
 137 } // end of wxStaticBitmap::Create 
 139 bool wxStaticBitmap::ImageIsOk() const 
 141     return(m_pImage 
&& m_pImage
->Ok()); 
 144 void wxStaticBitmap::Free() 
 149 } // end of wxStaticBitmap::Free 
 151 wxSize 
wxStaticBitmap::DoGetBestSize() const 
 154     // Reuse the current size (as wxWindow does) instead of using some 
 155     // arbitrary default size (as wxControl, our immediate base class, does) 
 157     return wxWindow::DoGetBestSize(); 
 160 void wxStaticBitmap::OnPaint ( 
 161   wxPaintEvent
&                     WXUNUSED(rEvent
) 
 167     if (m_pImage
->IsKindOf(CLASSINFO(wxIcon
))) 
 171         pIcon 
= wxDynamicCast(m_pImage
, wxIcon
); 
 172         pBitmap 
= new wxBitmap(*pIcon
); 
 173         vDc
.DrawBitmap(*pBitmap
, 0, 0); 
 178         pBitmap 
= wxDynamicCast(m_pImage
, wxBitmap
); 
 179         vDc
.DrawBitmap(*pBitmap
, 0, 0); 
 181 } // end of wxStaticBitmap::OnPaint 
 183 void wxStaticBitmap::SetImage( 
 184   const wxGDIImage
&                 rBitmap
 
 193     ::WinSendMsg( GetHwnd() 
 195                  ,MPFROMHWND(rBitmap
.GetHandle()) 
 198     m_pImage 
= ConvertImage(rBitmap
); 
 200     GetPosition(&nX
, &nY
); 
 201     GetSize(&nWidth
, &nHeight
); 
 207     vRect
.xRight  
= nX 
+ nWidth
; 
 208     vRect
.yBottom 
= nY 
+ nHeight
; 
 210     ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect
, TRUE
); 
 213 MRESULT 
wxStaticBitmap::OS2WindowProc( 
 219     return wxWindow::OS2WindowProc(uMsg
, wParam
, lParam
); 
 220 } // end of wxStaticBitmap::OS2WindowProc