]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/statbmp.cpp
3d18ef8976cdd22aafde66f297ebb28a910c5ffa
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
;
100 int nWidth
= rSize
.x
;
101 int nHeight
= rSize
.y
;
104 m_windowStyle
= lStyle
;
106 m_bIsIcon
= rBitmap
.IsKindOf(CLASSINFO(wxIcon
));
109 // For now we only support an ICON
111 int nWinstyle
= SS_ICON
;
113 m_hWnd
= (WXHWND
)::WinCreateWindow( pParent
->GetHWND()
116 ,nWinstyle
| WS_VISIBLE
126 vError
= ::WinGetLastError(wxGetInstance());
127 sError
= wxPMErrorToStr(vError
);
130 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create static bitmap") );
131 m_pImage
= ConvertImage(rBitmap
);
132 m_pImage
->SetHandle((WXHWND
)::WinSendMsg(m_hWnd
, SM_QUERYHANDLE
, (MPARAM
)0, (MPARAM
)0));
134 // Subclass again for purposes of dialog editing mode
136 SetSize(nX
, nY
, m_pImage
->GetWidth(), m_pImage
->GetHeight());
139 } // end of wxStaticBitmap::Create
141 bool wxStaticBitmap::ImageIsOk() const
143 return(m_pImage
&& m_pImage
->Ok());
146 void wxStaticBitmap::Free()
151 } // end of wxStaticBitmap::Free
153 wxSize
wxStaticBitmap::DoGetBestSize() const
156 // Reuse the current size (as wxWindow does) instead of using some
157 // arbitrary default size (as wxControl, our immediate base class, does)
159 return wxWindow::DoGetBestSize();
162 void wxStaticBitmap::OnPaint (
163 wxPaintEvent
& WXUNUSED(rEvent
)
170 if (m_pImage
->IsKindOf(CLASSINFO(wxIcon
)))
174 pIcon
= wxDynamicCast(m_pImage
, wxIcon
);
175 pBitmap
= new wxBitmap(*pIcon
);
176 vDc
.DrawBitmap(*pBitmap
, 0, 0);
181 pBitmap
= wxDynamicCast(m_pImage
, wxBitmap
);
182 vDc
.DrawBitmap(*pBitmap
, 0, 0);
184 } // end of wxStaticBitmap::OnPaint
186 void wxStaticBitmap::SetImage(
187 const wxGDIImage
& rBitmap
196 ::WinSendMsg( GetHwnd()
198 ,MPFROMHWND(rBitmap
.GetHandle())
201 m_pImage
= ConvertImage(rBitmap
);
203 GetPosition(&nX
, &nY
);
204 GetSize(&nWidth
, &nHeight
);
210 vRect
.xRight
= nX
+ nWidth
;
211 vRect
.yBottom
= nY
+ nHeight
;
213 ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect
, TRUE
);
216 MRESULT
wxStaticBitmap::OS2WindowProc(
222 return wxWindow::OS2WindowProc(uMsg
, wParam
, lParam
);
223 } // end of wxStaticBitmap::OS2WindowProc