]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/statbmp.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStaticBitmap
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "statbmp.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 #include "wx/window.h"
32 #include "wx/msw/private.h"
36 #include "wx/statbmp.h"
41 // ---------------------------------------------------------------------------
43 // ---------------------------------------------------------------------------
45 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap
, wxControl
)
47 // ===========================================================================
49 // ===========================================================================
51 // ---------------------------------------------------------------------------
53 // ---------------------------------------------------------------------------
55 bool wxStaticBitmap::Create(wxWindow
*parent
, wxWindowID id
,
56 const wxGDIImage
& bitmap
,
66 parent
->AddChild(this);
68 m_backgroundColour
= parent
->GetBackgroundColour() ;
69 m_foregroundColour
= parent
->GetForegroundColour() ;
72 m_windowId
= (int)NewControlId();
81 m_windowStyle
= style
;
83 m_isIcon
= bitmap
.IsKindOf(CLASSINFO(wxIcon
));
86 // create a static control with either SS_BITMAP or SS_ICON style depending
87 // on what we have here
88 const wxChar
*classname
= wxT("STATIC");
89 int winstyle
= m_isIcon
? SS_ICON
: SS_BITMAP
;
91 const wxChar
*classname
= wxT("BUTTON");
92 int winstyle
= BS_OWNERDRAW
;
95 m_hWnd
= (WXHWND
)::CreateWindow
99 winstyle
| WS_CHILD
| WS_VISIBLE
,
101 (HWND
)parent
->GetHWND(),
107 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create static bitmap") );
111 // Subclass again for purposes of dialog editing mode
114 SetFont(GetParent()->GetFont());
116 SetSize(x
, y
, width
, height
);
121 bool wxStaticBitmap::ImageIsOk() const
123 return m_image
&& m_image
->Ok();
126 void wxStaticBitmap::Free()
133 wxSize
wxStaticBitmap::DoGetBestSize() const
135 // reuse the current size (as wxWindow does) instead of using some
136 // arbitrary default size (as wxControl, our immediate base class, does)
137 return wxWindow::DoGetBestSize();
140 void wxStaticBitmap::SetImage(const wxGDIImage
& bitmap
)
144 m_isIcon
= bitmap
.IsKindOf(CLASSINFO(wxIcon
));
146 m_image
= new wxIcon((const wxIcon
&)bitmap
);
148 m_image
= new wxBitmap((const wxBitmap
&)bitmap
);
156 HANDLE handle
= (HANDLE
)m_image
->GetHandle();
157 ::SendMessage(GetHwnd(), STM_SETIMAGE
,
158 m_isIcon
? IMAGE_ICON
: IMAGE_BITMAP
, (LPARAM
)handle
);
163 int width
= bitmap
.GetWidth(),
164 height
= bitmap
.GetHeight();
165 if ( width
&& height
)
170 ::MoveWindow(GetHwnd(), x
, y
, width
, height
, FALSE
);
179 InvalidateRect(GetHwndOf(GetParent()), &rect
, TRUE
);
182 // under Win32 we use the standard static control style for this
184 bool wxStaticBitmap::MSWOnDraw(WXDRAWITEMSTRUCT
*item
)
186 LPDRAWITEMSTRUCT lpDIS
= (LPDRAWITEMSTRUCT
) item
;
188 wxCHECK_MSG( !m_isIcon
, FALSE
, _T("icons not supported in wxStaticBitmap") );
190 wxBitmap
* bitmap
= (wxBitmap
*)m_image
;
194 HDC hDC
= lpDIS
->hDC
;
195 HDC memDC
= ::CreateCompatibleDC(hDC
);
197 HBITMAP old
= (HBITMAP
) ::SelectObject(memDC
, (HBITMAP
) bitmap
->GetHBITMAP());
202 int x
= lpDIS
->rcItem
.left
;
203 int y
= lpDIS
->rcItem
.top
;
204 int width
= lpDIS
->rcItem
.right
- x
;
205 int height
= lpDIS
->rcItem
.bottom
- y
;
207 // Centre the bitmap in the control area
208 int x1
= (int) (x
+ ((width
- bitmap
->GetWidth()) / 2));
209 int y1
= (int) (y
+ ((height
- bitmap
->GetHeight()) / 2));
211 ::BitBlt(hDC
, x1
, y1
, bitmap
->GetWidth(), bitmap
->GetHeight(), memDC
, 0, 0, SRCCOPY
);
213 ::SelectObject(memDC
, old
);
221 // We need this or the control can never be moved e.g. in Dialog Editor.
222 long wxStaticBitmap::MSWWindowProc(WXUINT nMsg
,
226 // Ensure that static items get messages. Some controls don't like this
227 // message to be intercepted (e.g. RichEdit), hence the tests.
228 if ( nMsg
== WM_NCHITTEST
)
229 return (long)HTCLIENT
;
231 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);