]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/statbmp.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/os2/statbmp.cpp 
   3 // Purpose:     wxStaticBitmap 
   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 #include "wx/statbmp.h" 
  19     #include "wx/window.h" 
  20     #include "wx/dcclient.h" 
  23 #include "wx/os2/private.h" 
  27 // --------------------------------------------------------------------------- 
  29 // --------------------------------------------------------------------------- 
  31 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap
, wxControl
) 
  33 BEGIN_EVENT_TABLE(wxStaticBitmap
, wxWindow
) 
  34     EVT_PAINT(wxStaticBitmap::OnPaint
) 
  37 static wxGDIImage
* ConvertImage( 
  38   const wxGDIImage
&                 rBitmap
 
  41     bool                            bIsIcon 
= rBitmap
.IsKindOf( CLASSINFO(wxIcon
) ); 
  45         wxASSERT_MSG( wxDynamicCast(&rBitmap
, wxBitmap
), 
  46                       _T("not an icon and not a bitmap?") ); 
  48         const wxBitmap
&             rBmp 
= (const wxBitmap
&)rBitmap
; 
  49         wxMask
*                     pMask 
= rBmp
.GetMask(); 
  51         if (pMask 
&& pMask
->GetMaskBitmap()) 
  53             wxIcon
*                 pIcon 
= new wxIcon
; 
  55             pIcon
->CopyFromBitmap(rBmp
); 
  58         return new wxBitmap(rBmp
); 
  61     // copying a bitmap is a cheap operation 
  62     return new wxIcon( (const wxIcon
&)rBitmap 
); 
  63 } // end of ConvertImage 
  65 // --------------------------------------------------------------------------- 
  67 // --------------------------------------------------------------------------- 
  69 bool wxStaticBitmap::Create( wxWindow
*         pParent
, 
  71                              const wxGDIImage
& rBitmap
, 
  73                              const wxSize
&     WXUNUSED(rSize
), 
  75                              const wxString
&   rName 
) 
  84         pParent
->AddChild(this); 
  87         m_windowId 
= (int)NewControlId(); 
  91     m_windowStyle 
= lStyle
; 
  97     m_windowStyle 
= lStyle
; 
  99     m_bIsIcon 
= rBitmap
.IsKindOf(CLASSINFO(wxIcon
)); 
 102     // For now we only support an ICON 
 104     int                             nWinstyle 
= SS_ICON
; 
 106     m_hWnd 
= (WXHWND
)::WinCreateWindow( pParent
->GetHWND() 
 107                                        ,(PSZ
)wxCanvasClassName
 
 109                                        ,nWinstyle 
| WS_VISIBLE
 
 119         vError 
= ::WinGetLastError(wxGetInstance()); 
 120         sError 
= wxPMErrorToStr(vError
); 
 123     wxCHECK_MSG( m_hWnd
, false, wxT("Failed to create static bitmap") ); 
 124     m_pImage 
= ConvertImage(rBitmap
); 
 125     ::WinSendMsg(   m_hWnd
, 
 127                     MPFROMHWND(rBitmap
.GetHandle()), 
 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 ( wxPaintEvent
& WXUNUSED(rEvent
) ) 
 163     if (m_pImage
->IsKindOf(CLASSINFO(wxIcon
))) 
 167         pIcon 
= wxDynamicCast(m_pImage
, wxIcon
); 
 168         pBitmap 
= new wxBitmap(*pIcon
); 
 169         vDc
.DrawBitmap(*pBitmap
, 0, 0); 
 174         pBitmap 
= wxDynamicCast(m_pImage
, wxBitmap
); 
 175         vDc
.DrawBitmap(*pBitmap
, 0, 0); 
 177 } // end of wxStaticBitmap::OnPaint 
 179 void wxStaticBitmap::SetImage( const wxGDIImage
& rBitmap 
) 
 187     ::WinSendMsg( GetHwnd() 
 189                  ,MPFROMHWND(rBitmap
.GetHandle()) 
 192     m_pImage 
= ConvertImage(rBitmap
); 
 194     GetPosition(&nX
, &nY
); 
 195     GetSize(&nWidth
, &nHeight
); 
 196     // Convert to OS/2 coordinate system 
 197     nY 
= wxWindow::GetOS2ParentHeight(GetParent()) - nY 
- nHeight
; 
 202     vRect
.yTop    
= nY 
+ nHeight
; 
 203     vRect
.xRight  
= nX 
+ nWidth
; 
 206     ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect
, TRUE
); 
 209 MRESULT 
wxStaticBitmap::OS2WindowProc( 
 215     return wxWindow::OS2WindowProc(uMsg
, wParam
, lParam
); 
 216 } // end of wxStaticBitmap::OS2WindowProc