]>
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
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 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap
, wxControl
)
33 BEGIN_EVENT_TABLE(wxStaticBitmap
, wxWindow
)
34 EVT_PAINT(wxStaticBitmap::OnPaint
)
37 static wxGDIImage
* ConvertImage(
38 const wxGDIImage
& rBitmap
41 bool bIsIcon
= rBitmap
.IsKindOf( CLASSINFO(wxIcon
) );
45 wxASSERT_MSG( wxDynamicCast(&rBitmap
, wxBitmap
),
46 wxT("not an icon and not a bitmap?") );
48 const wxBitmap
& rBmp
= (const wxBitmap
&)rBitmap
;
49 wxMask
* pMask
= rBmp
.GetMask();
51 if (pMask
&& pMask
->GetMaskBitmap())
53 wxIcon
* pIcon
= new wxIcon
;
55 pIcon
->CopyFromBitmap(rBmp
);
58 return new wxBitmap(rBmp
);
61 // copying a bitmap is a cheap operation
62 return new wxIcon( (const wxIcon
&)rBitmap
);
63 } // end of ConvertImage
65 // ---------------------------------------------------------------------------
67 // ---------------------------------------------------------------------------
69 bool wxStaticBitmap::Create( wxWindow
* pParent
,
71 const wxGDIImage
& rBitmap
,
73 const wxSize
& WXUNUSED(rSize
),
75 const wxString
& rName
)
84 pParent
->AddChild(this);
87 m_windowId
= (int)NewControlId();
91 m_windowStyle
= lStyle
;
97 m_windowStyle
= lStyle
;
99 m_bIsIcon
= rBitmap
.IsKindOf(CLASSINFO(wxIcon
));
102 // For now we only support an ICON
104 int nWinstyle
= SS_ICON
;
106 m_hWnd
= (WXHWND
)::WinCreateWindow( pParent
->GetHWND()
107 ,(PSZ
)wxCanvasClassName
109 ,nWinstyle
| WS_VISIBLE
119 vError
= ::WinGetLastError(wxGetInstance());
120 sError
= wxPMErrorToStr(vError
);
123 wxCHECK_MSG( m_hWnd
, false, wxT("Failed to create static bitmap") );
124 m_pImage
= ConvertImage(rBitmap
);
125 ::WinSendMsg( m_hWnd
,
127 MPFROMHWND(rBitmap
.GetHandle()),
130 // Subclass again for purposes of dialog editing mode
132 SetSize(nX
, nY
, m_pImage
->GetWidth(), m_pImage
->GetHeight());
135 } // end of wxStaticBitmap::Create
137 bool wxStaticBitmap::ImageIsOk() const
139 return(m_pImage
&& m_pImage
->Ok());
142 void wxStaticBitmap::Free()
145 } // end of wxStaticBitmap::Free
147 wxSize
wxStaticBitmap::DoGetBestSize() const
150 // Reuse the current size (as wxWindow does) instead of using some
151 // arbitrary default size (as wxControl, our immediate base class, does)
153 return wxWindow::DoGetBestSize();
156 void wxStaticBitmap::OnPaint ( wxPaintEvent
& WXUNUSED(rEvent
) )
161 if (m_pImage
->IsKindOf(CLASSINFO(wxIcon
)))
165 pIcon
= wxDynamicCast(m_pImage
, wxIcon
);
166 pBitmap
= new wxBitmap(*pIcon
);
167 vDc
.DrawBitmap(*pBitmap
, 0, 0);
172 pBitmap
= wxDynamicCast(m_pImage
, wxBitmap
);
173 vDc
.DrawBitmap(*pBitmap
, 0, 0);
175 } // end of wxStaticBitmap::OnPaint
177 void wxStaticBitmap::SetImage( const wxGDIImage
& rBitmap
)
185 ::WinSendMsg( GetHwnd()
187 ,MPFROMHWND(rBitmap
.GetHandle())
190 m_pImage
= ConvertImage(rBitmap
);
192 GetPosition(&nX
, &nY
);
193 GetSize(&nWidth
, &nHeight
);
194 // Convert to OS/2 coordinate system
195 nY
= wxWindow::GetOS2ParentHeight(GetParent()) - nY
- nHeight
;
200 vRect
.yTop
= nY
+ nHeight
;
201 vRect
.xRight
= nX
+ nWidth
;
204 ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect
, TRUE
);
207 MRESULT
wxStaticBitmap::OS2WindowProc(
213 return wxWindow::OS2WindowProc(uMsg
, wParam
, lParam
);
214 } // end of wxStaticBitmap::OS2WindowProc