]>
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 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
15 #include "wx/dcclient.h"
16 #include "wx/window.h"
17 #include "wx/os2/private.h"
21 #include "wx/statbmp.h"
26 // ---------------------------------------------------------------------------
28 // ---------------------------------------------------------------------------
30 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap
, wxControl
)
32 BEGIN_EVENT_TABLE(wxStaticBitmap
, wxWindow
)
33 EVT_PAINT(wxStaticBitmap::OnPaint
)
36 static wxGDIImage
* ConvertImage(
37 const wxGDIImage
& rBitmap
40 bool bIsIcon
= rBitmap
.IsKindOf( CLASSINFO(wxIcon
) );
44 wxASSERT_MSG( wxDynamicCast(&rBitmap
, wxBitmap
),
45 _T("not an icon and not a bitmap?") );
47 const wxBitmap
& rBmp
= (const wxBitmap
&)rBitmap
;
48 wxMask
* pMask
= rBmp
.GetMask();
50 if (pMask
&& pMask
->GetMaskBitmap())
52 wxIcon
* pIcon
= new wxIcon
;
54 pIcon
->CopyFromBitmap(rBmp
);
57 return new wxBitmap(rBmp
);
60 // copying a bitmap is a cheap operation
61 return new wxIcon( (const wxIcon
&)rBitmap
);
62 } // end of ConvertImage
64 // ---------------------------------------------------------------------------
66 // ---------------------------------------------------------------------------
68 bool wxStaticBitmap::Create( wxWindow
* pParent
,
70 const wxGDIImage
& rBitmap
,
72 const wxSize
& WXUNUSED(rSize
),
74 const wxString
& rName
)
83 pParent
->AddChild(this);
86 m_windowId
= (int)NewControlId();
90 m_windowStyle
= lStyle
;
96 m_windowStyle
= lStyle
;
98 m_bIsIcon
= rBitmap
.IsKindOf(CLASSINFO(wxIcon
));
101 // For now we only support an ICON
103 int nWinstyle
= SS_ICON
;
105 m_hWnd
= (WXHWND
)::WinCreateWindow( pParent
->GetHWND()
106 ,(PSZ
)wxCanvasClassName
108 ,nWinstyle
| WS_VISIBLE
118 vError
= ::WinGetLastError(wxGetInstance());
119 sError
= wxPMErrorToStr(vError
);
122 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create static bitmap") );
123 m_pImage
= ConvertImage(rBitmap
);
124 ::WinSendMsg( m_hWnd
,
126 MPFROMHWND(rBitmap
.GetHandle()),
129 // Subclass again for purposes of dialog editing mode
131 SetSize(nX
, nY
, m_pImage
->GetWidth(), m_pImage
->GetHeight());
134 } // end of wxStaticBitmap::Create
136 bool wxStaticBitmap::ImageIsOk() const
138 return(m_pImage
&& m_pImage
->Ok());
141 void wxStaticBitmap::Free()
146 } // end of wxStaticBitmap::Free
148 wxSize
wxStaticBitmap::DoGetBestSize() const
151 // Reuse the current size (as wxWindow does) instead of using some
152 // arbitrary default size (as wxControl, our immediate base class, does)
154 return wxWindow::DoGetBestSize();
157 void wxStaticBitmap::OnPaint (
158 wxPaintEvent
& WXUNUSED(rEvent
)
164 if (m_pImage
->IsKindOf(CLASSINFO(wxIcon
)))
168 pIcon
= wxDynamicCast(m_pImage
, wxIcon
);
169 pBitmap
= new wxBitmap(*pIcon
);
170 vDc
.DrawBitmap(*pBitmap
, 0, 0);
175 pBitmap
= wxDynamicCast(m_pImage
, wxBitmap
);
176 vDc
.DrawBitmap(*pBitmap
, 0, 0);
178 } // end of wxStaticBitmap::OnPaint
180 void wxStaticBitmap::SetImage(
181 const wxGDIImage
& rBitmap
190 ::WinSendMsg( GetHwnd()
192 ,MPFROMHWND(rBitmap
.GetHandle())
195 m_pImage
= ConvertImage(rBitmap
);
197 GetPosition(&nX
, &nY
);
198 GetSize(&nWidth
, &nHeight
);
199 // Convert to OS/2 coordinate system
200 nY
= wxWindow::GetOS2ParentHeight(GetParent()) - nY
- nHeight
;
205 vRect
.yTop
= nY
+ nHeight
;
206 vRect
.xRight
= nX
+ nWidth
;
209 ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect
, TRUE
);
212 MRESULT
wxStaticBitmap::OS2WindowProc(
218 return wxWindow::OS2WindowProc(uMsg
, wParam
, lParam
);
219 } // end of wxStaticBitmap::OS2WindowProc