]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/statbmp.cpp
9a7f0985a39cc2601005a0ae7aa8877d58c3c153
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 BEGIN_EVENT_TABLE(wxStaticBitmap
, wxWindow
)
32 EVT_PAINT(wxStaticBitmap::OnPaint
)
35 static wxGDIImage
* ConvertImage(
36 const wxGDIImage
& rBitmap
39 bool bIsIcon
= rBitmap
.IsKindOf( CLASSINFO(wxIcon
) );
43 wxASSERT_MSG( wxDynamicCast(&rBitmap
, wxBitmap
),
44 wxT("not an icon and not a bitmap?") );
46 const wxBitmap
& rBmp
= (const wxBitmap
&)rBitmap
;
47 wxMask
* pMask
= rBmp
.GetMask();
49 if (pMask
&& pMask
->GetMaskBitmap())
51 wxIcon
* pIcon
= new wxIcon
;
53 pIcon
->CopyFromBitmap(rBmp
);
56 return new wxBitmap(rBmp
);
59 // copying a bitmap is a cheap operation
60 return new wxIcon( (const wxIcon
&)rBitmap
);
61 } // end of ConvertImage
63 // ---------------------------------------------------------------------------
65 // ---------------------------------------------------------------------------
67 bool wxStaticBitmap::Create( wxWindow
* pParent
,
69 const wxGDIImage
& rBitmap
,
71 const wxSize
& WXUNUSED(rSize
),
73 const wxString
& rName
)
82 pParent
->AddChild(this);
85 m_windowId
= (int)NewControlId();
89 m_windowStyle
= lStyle
;
95 m_windowStyle
= lStyle
;
97 m_bIsIcon
= rBitmap
.IsKindOf(CLASSINFO(wxIcon
));
100 // For now we only support an ICON
102 int nWinstyle
= SS_ICON
;
104 m_hWnd
= (WXHWND
)::WinCreateWindow( pParent
->GetHWND()
105 ,(PSZ
)wxCanvasClassName
107 ,nWinstyle
| WS_VISIBLE
117 vError
= ::WinGetLastError(wxGetInstance());
118 sError
= wxPMErrorToStr(vError
);
121 wxCHECK_MSG( m_hWnd
, false, wxT("Failed to create static bitmap") );
122 m_pImage
= ConvertImage(rBitmap
);
123 ::WinSendMsg( m_hWnd
,
125 MPFROMHWND(rBitmap
.GetHandle()),
128 // Subclass again for purposes of dialog editing mode
130 SetSize(nX
, nY
, m_pImage
->GetWidth(), m_pImage
->GetHeight());
133 } // end of wxStaticBitmap::Create
135 bool wxStaticBitmap::ImageIsOk() const
137 return(m_pImage
&& m_pImage
->IsOk());
140 void wxStaticBitmap::Free()
143 } // end of wxStaticBitmap::Free
145 wxSize
wxStaticBitmap::DoGetBestSize() const
148 // Reuse the current size (as wxWindow does) instead of using some
149 // arbitrary default size (as wxControl, our immediate base class, does)
151 return wxWindow::DoGetBestSize();
154 void wxStaticBitmap::OnPaint ( wxPaintEvent
& WXUNUSED(rEvent
) )
159 if (m_pImage
->IsKindOf(CLASSINFO(wxIcon
)))
163 pIcon
= wxDynamicCast(m_pImage
, wxIcon
);
164 pBitmap
= new wxBitmap(*pIcon
);
165 vDc
.DrawBitmap(*pBitmap
, 0, 0);
170 pBitmap
= wxDynamicCast(m_pImage
, wxBitmap
);
171 vDc
.DrawBitmap(*pBitmap
, 0, 0);
173 } // end of wxStaticBitmap::OnPaint
175 void wxStaticBitmap::SetImage( const wxGDIImage
& rBitmap
)
183 ::WinSendMsg( GetHwnd()
185 ,MPFROMHWND(rBitmap
.GetHandle())
188 m_pImage
= ConvertImage(rBitmap
);
190 GetPosition(&nX
, &nY
);
191 GetSize(&nWidth
, &nHeight
);
192 // Convert to OS/2 coordinate system
193 nY
= wxWindow::GetOS2ParentHeight(GetParent()) - nY
- nHeight
;
198 vRect
.yTop
= nY
+ nHeight
;
199 vRect
.xRight
= nX
+ nWidth
;
202 ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect
, TRUE
);
205 MRESULT
wxStaticBitmap::OS2WindowProc(
211 return wxWindow::OS2WindowProc(uMsg
, wParam
, lParam
);
212 } // end of wxStaticBitmap::OS2WindowProc