]>
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/window.h"
20 #include "wx/os2/private.h"
24 #include "wx/statbmp.h"
29 // ---------------------------------------------------------------------------
31 // ---------------------------------------------------------------------------
33 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap
, wxControl
)
35 BEGIN_EVENT_TABLE(wxStaticBitmap
, wxWindow
)
36 EVT_PAINT(wxStaticBitmap::OnPaint
)
39 static wxGDIImage
* ConvertImage(
40 const wxGDIImage
& rBitmap
43 bool bIsIcon
= rBitmap
.IsKindOf( CLASSINFO(wxIcon
) );
47 wxASSERT_MSG( wxDynamicCast(&rBitmap
, wxBitmap
),
48 _T("not an icon and not a bitmap?") );
50 const wxBitmap
& rBmp
= (const wxBitmap
&)rBitmap
;
51 wxMask
* pMask
= rBmp
.GetMask();
53 if (pMask
&& pMask
->GetMaskBitmap())
55 wxIcon
* pIcon
= new wxIcon
;
57 pIcon
->CopyFromBitmap(rBmp
);
60 return new wxBitmap(rBmp
);
63 // copying a bitmap is a cheap operation
64 return new wxIcon( (const wxIcon
&)rBitmap
);
65 } // end of ConvertImage
67 // ---------------------------------------------------------------------------
69 // ---------------------------------------------------------------------------
71 bool wxStaticBitmap::Create(
74 , const wxGDIImage
& rBitmap
78 , const wxString
& rName
88 pParent
->AddChild(this);
91 m_windowId
= (int)NewControlId();
95 m_windowStyle
= lStyle
;
100 int nHeight
= rSize
.y
;
103 m_windowStyle
= lStyle
;
105 m_bIsIcon
= rBitmap
.IsKindOf(CLASSINFO(wxIcon
));
108 // For now we only support an ICON
110 int nWinstyle
= SS_ICON
;
112 m_hWnd
= (WXHWND
)::WinCreateWindow( pParent
->GetHWND()
115 ,nWinstyle
| WS_VISIBLE
125 vError
= ::WinGetLastError(wxGetInstance());
126 sError
= wxPMErrorToStr(vError
);
129 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create static bitmap") );
130 m_pImage
= ConvertImage(rBitmap
);
131 m_pImage
->SetHandle((WXHWND
)::WinSendMsg(m_hWnd
, SM_QUERYHANDLE
, (MPARAM
)0, (MPARAM
)0));
133 // Subclass again for purposes of dialog editing mode
135 SetSize(nX
, nY
, m_pImage
->GetWidth(), m_pImage
->GetHeight());
138 } // end of wxStaticBitmap::Create
140 bool wxStaticBitmap::ImageIsOk() const
142 return(m_pImage
&& m_pImage
->Ok());
145 void wxStaticBitmap::Free()
150 } // end of wxStaticBitmap::Free
152 wxSize
wxStaticBitmap::DoGetBestSize() const
155 // Reuse the current size (as wxWindow does) instead of using some
156 // arbitrary default size (as wxControl, our immediate base class, does)
158 return wxWindow::DoGetBestSize();
161 void wxStaticBitmap::OnPaint (
162 wxPaintEvent
& WXUNUSED(rEvent
)
169 if (m_pImage
->IsKindOf(CLASSINFO(wxIcon
)))
173 pIcon
= wxDynamicCast(m_pImage
, wxIcon
);
174 pBitmap
= new wxBitmap(*pIcon
);
175 vDc
.DrawBitmap(*pBitmap
, 0, 0);
180 pBitmap
= wxDynamicCast(m_pImage
, wxBitmap
);
181 vDc
.DrawBitmap(*pBitmap
, 0, 0);
183 } // end of wxStaticBitmap::OnPaint
185 void wxStaticBitmap::SetImage(
186 const wxGDIImage
& rBitmap
195 ::WinSendMsg( GetHwnd()
197 ,MPFROMHWND(rBitmap
.GetHandle())
200 m_pImage
= ConvertImage(rBitmap
);
202 GetPosition(&nX
, &nY
);
203 GetSize(&nWidth
, &nHeight
);
209 vRect
.xRight
= nX
+ nWidth
;
210 vRect
.yBottom
= nY
+ nHeight
;
212 ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect
, TRUE
);
215 MRESULT
wxStaticBitmap::OS2WindowProc(
221 return wxWindow::OS2WindowProc(uMsg
, wParam
, lParam
);
222 } // end of wxStaticBitmap::OS2WindowProc