]>
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
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #include "wx/statbmp.h"
18 #include "wx/window.h"
19 #include "wx/dcclient.h"
22 #include "wx/os2/private.h"
26 // ---------------------------------------------------------------------------
28 // ---------------------------------------------------------------------------
30 BEGIN_EVENT_TABLE(wxStaticBitmap
, wxWindow
)
31 EVT_PAINT(wxStaticBitmap::OnPaint
)
34 static wxGDIImage
* ConvertImage(
35 const wxGDIImage
& rBitmap
38 bool bIsIcon
= rBitmap
.IsKindOf( CLASSINFO(wxIcon
) );
42 wxASSERT_MSG( wxDynamicCast(&rBitmap
, wxBitmap
),
43 wxT("not an icon and not a bitmap?") );
45 const wxBitmap
& rBmp
= (const wxBitmap
&)rBitmap
;
46 wxMask
* pMask
= rBmp
.GetMask();
48 if (pMask
&& pMask
->GetMaskBitmap())
50 wxIcon
* pIcon
= new wxIcon
;
52 pIcon
->CopyFromBitmap(rBmp
);
55 return new wxBitmap(rBmp
);
58 // copying a bitmap is a cheap operation
59 return new wxIcon( (const wxIcon
&)rBitmap
);
60 } // end of ConvertImage
62 // ---------------------------------------------------------------------------
64 // ---------------------------------------------------------------------------
66 bool wxStaticBitmap::Create( wxWindow
* pParent
,
68 const wxGDIImage
& rBitmap
,
70 const wxSize
& WXUNUSED(rSize
),
72 const wxString
& rName
)
81 pParent
->AddChild(this);
84 m_windowId
= (int)NewControlId();
88 m_windowStyle
= lStyle
;
94 m_windowStyle
= lStyle
;
96 m_bIsIcon
= rBitmap
.IsKindOf(CLASSINFO(wxIcon
));
99 // For now we only support an ICON
101 int nWinstyle
= SS_ICON
;
103 m_hWnd
= (WXHWND
)::WinCreateWindow( pParent
->GetHWND()
104 ,(PSZ
)wxCanvasClassName
106 ,nWinstyle
| WS_VISIBLE
116 vError
= ::WinGetLastError(wxGetInstance());
117 sError
= wxPMErrorToStr(vError
);
120 wxCHECK_MSG( m_hWnd
, false, wxT("Failed to create static bitmap") );
121 m_pImage
= ConvertImage(rBitmap
);
122 ::WinSendMsg( m_hWnd
,
124 MPFROMHWND(rBitmap
.GetHandle()),
127 // Subclass again for purposes of dialog editing mode
129 SetSize(nX
, nY
, m_pImage
->GetWidth(), m_pImage
->GetHeight());
132 } // end of wxStaticBitmap::Create
134 bool wxStaticBitmap::ImageIsOk() const
136 return(m_pImage
&& m_pImage
->IsOk());
139 void wxStaticBitmap::Free()
142 } // end of wxStaticBitmap::Free
144 wxSize
wxStaticBitmap::DoGetBestSize() const
147 // Reuse the current size (as wxWindow does) instead of using some
148 // arbitrary default size (as wxControl, our immediate base class, does)
150 return wxWindow::DoGetBestSize();
153 void wxStaticBitmap::OnPaint ( wxPaintEvent
& WXUNUSED(rEvent
) )
158 if (m_pImage
->IsKindOf(CLASSINFO(wxIcon
)))
162 pIcon
= wxDynamicCast(m_pImage
, wxIcon
);
163 pBitmap
= new wxBitmap(*pIcon
);
164 vDc
.DrawBitmap(*pBitmap
, 0, 0);
169 pBitmap
= wxDynamicCast(m_pImage
, wxBitmap
);
170 vDc
.DrawBitmap(*pBitmap
, 0, 0);
172 } // end of wxStaticBitmap::OnPaint
174 void wxStaticBitmap::SetImage( const wxGDIImage
& rBitmap
)
182 ::WinSendMsg( GetHwnd()
184 ,MPFROMHWND(rBitmap
.GetHandle())
187 m_pImage
= ConvertImage(rBitmap
);
189 GetPosition(&nX
, &nY
);
190 GetSize(&nWidth
, &nHeight
);
191 // Convert to OS/2 coordinate system
192 nY
= wxWindow::GetOS2ParentHeight(GetParent()) - nY
- nHeight
;
197 vRect
.yTop
= nY
+ nHeight
;
198 vRect
.xRight
= nX
+ nWidth
;
201 ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect
, TRUE
);
204 MRESULT
wxStaticBitmap::OS2WindowProc(
210 return wxWindow::OS2WindowProc(uMsg
, wParam
, lParam
);
211 } // end of wxStaticBitmap::OS2WindowProc