]>
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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "statbmp.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
19 #include "wx/window.h"
20 #include "wx/os2/private.h"
24 #include "wx/statbmp.h"
29 // ---------------------------------------------------------------------------
31 // ---------------------------------------------------------------------------
33 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap
, wxControl
)
35 static wxGDIImage
* ConvertImage(
36 const wxGDIImage
& rBitmap
39 bool bIsIcon
= rBitmap
.IsKindOf( CLASSINFO(wxIcon
) );
43 wxASSERT_MSG( wxDynamicCast(&rBitmap
, wxBitmap
),
44 _T("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(
70 , const wxGDIImage
& rBitmap
74 , const wxString
& rName
84 pParent
->AddChild(this);
87 m_windowId
= (int)NewControlId();
91 m_windowStyle
= lStyle
;
96 int nHeight
= rSize
.y
;
99 m_windowStyle
= lStyle
;
101 m_bIsIcon
= rBitmap
.IsKindOf(CLASSINFO(wxIcon
));
104 // For now we only support an ICON
106 int nWinstyle
= SS_ICON
;
108 sprintf(zId
, "#%d", rBitmap
.GetId());
109 m_hWnd
= (WXHWND
)::WinCreateWindow( pParent
->GetHWND()
112 ,nWinstyle
| WS_VISIBLE
122 vError
= ::WinGetLastError(wxGetInstance());
123 sError
= wxPMErrorToStr(vError
);
126 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create static bitmap") );
127 m_pImage
= ConvertImage(rBitmap
);
128 m_pImage
->SetHandle((WXHWND
)::WinSendMsg(m_hWnd
, SM_QUERYHANDLE
, (MPARAM
)0, (MPARAM
)0));
130 // Subclass again for purposes of dialog editing mode
133 } // end of wxStaticBitmap::Create
135 bool wxStaticBitmap::ImageIsOk() const
137 return(m_pImage
&& m_pImage
->Ok());
140 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::SetImage(
157 const wxGDIImage
& rBitmap
166 ::WinSendMsg( GetHwnd()
168 ,MPFROMHWND(rBitmap
.GetHandle())
171 m_pImage
= ConvertImage(rBitmap
);
173 GetPosition(&nX
, &nY
);
174 GetSize(&nWidth
, &nHeight
);
180 vRect
.xRight
= nX
+ nWidth
;
181 vRect
.yBottom
= nY
+ nHeight
;
183 ::WinInvalidateRect(GetHwndOf(GetParent()), &vRect
, TRUE
);
186 MRESULT
wxStaticBitmap::OS2WindowProc(
192 return wxWindow::OS2WindowProc(uMsg
, wParam
, lParam
);
193 } // end of wxStaticBitmap::OS2WindowProc