]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/statbmp.cpp
c0893d25c317534a4998249be01543f624ef5738
   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( wxWindow
*         pParent
, 
  74                              const wxGDIImage
& rBitmap
, 
  76                              const wxSize
&     WXUNUSED(rSize
), 
  78                              const wxString
&   rName 
) 
  87         pParent
->AddChild(this); 
  90         m_windowId 
= (int)NewControlId(); 
  94     m_windowStyle 
= lStyle
; 
 100     m_windowStyle 
= lStyle
; 
 102     m_bIsIcon 
= rBitmap
.IsKindOf(CLASSINFO(wxIcon
)); 
 105     // For now we only support an ICON 
 107     int                             nWinstyle 
= SS_ICON
; 
 109     m_hWnd 
= (WXHWND
)::WinCreateWindow( pParent
->GetHWND() 
 110                                        ,(PSZ
)wxCanvasClassName
 
 112                                        ,nWinstyle 
| WS_VISIBLE
 
 122         vError 
= ::WinGetLastError(wxGetInstance()); 
 123         sError 
= wxPMErrorToStr(vError
); 
 126     wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create static bitmap") ); 
 127     m_pImage 
= ConvertImage(rBitmap
); 
 128     m_pImage
->SetHandle((WXHWND
)::WinSendMsg(m_hWnd
, SM_QUERYHANDLE
, (MPARAM
)0, (MPARAM
)0)); 
 130     // Subclass again for purposes of dialog editing mode 
 132     SetSize(nX
, nY
, m_pImage
->GetWidth(), m_pImage
->GetHeight()); 
 135 } // end of wxStaticBitmap::Create 
 137 bool wxStaticBitmap::ImageIsOk() const 
 139     return(m_pImage 
&& m_pImage
->Ok()); 
 142 void wxStaticBitmap::Free() 
 147 } // end of wxStaticBitmap::Free 
 149 wxSize 
wxStaticBitmap::DoGetBestSize() const 
 152     // Reuse the current size (as wxWindow does) instead of using some 
 153     // arbitrary default size (as wxControl, our immediate base class, does) 
 155     return wxWindow::DoGetBestSize(); 
 158 void wxStaticBitmap::OnPaint ( 
 159   wxPaintEvent
&                     WXUNUSED(rEvent
) 
 165     if (m_pImage
->IsKindOf(CLASSINFO(wxIcon
))) 
 169         pIcon 
= wxDynamicCast(m_pImage
, wxIcon
); 
 170         pBitmap 
= new wxBitmap(*pIcon
); 
 171         vDc
.DrawBitmap(*pBitmap
, 0, 0); 
 176         pBitmap 
= wxDynamicCast(m_pImage
, wxBitmap
); 
 177         vDc
.DrawBitmap(*pBitmap
, 0, 0); 
 179 } // end of wxStaticBitmap::OnPaint 
 181 void wxStaticBitmap::SetImage( 
 182   const wxGDIImage
&                 rBitmap
 
 191     ::WinSendMsg( GetHwnd() 
 193                  ,MPFROMHWND(rBitmap
.GetHandle()) 
 196     m_pImage 
= ConvertImage(rBitmap
); 
 198     GetPosition(&nX
, &nY
); 
 199     GetSize(&nWidth
, &nHeight
); 
 205     vRect
.xRight  
= nX 
+ nWidth
; 
 206     vRect
.yBottom 
= nY 
+ nHeight
; 
 208     ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect
, TRUE
); 
 211 MRESULT 
wxStaticBitmap::OS2WindowProc( 
 217     return wxWindow::OS2WindowProc(uMsg
, wParam
, lParam
); 
 218 } // end of wxStaticBitmap::OS2WindowProc