]>
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"
33 #include "wx/window.h"
34 #include "wx/msw/private.h"
38 #include "wx/statbmp.h"
43 // ---------------------------------------------------------------------------
45 // ---------------------------------------------------------------------------
47 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap
, wxControl
)
49 // ===========================================================================
51 // ===========================================================================
53 // ---------------------------------------------------------------------------
55 // ---------------------------------------------------------------------------
57 bool wxStaticBitmap::Create(wxWindow
*parent
, wxWindowID id
,
58 const wxGDIImage
& bitmap
,
68 parent
->AddChild(this);
70 m_backgroundColour
= parent
->GetBackgroundColour() ;
71 m_foregroundColour
= parent
->GetForegroundColour() ;
74 m_windowId
= (int)NewControlId();
83 m_windowStyle
= style
;
85 // we may have either bitmap or icon: if a bitmap with mask is passed, we
86 // will transform it to an icon ourselves because otherwise the mask will
87 // be ignored by Windows
88 wxIcon
*icon
= (wxIcon
*)NULL
;
89 m_isIcon
= bitmap
.IsKindOf(CLASSINFO(wxIcon
));
92 wxASSERT_MSG( !m_isIcon
, "Icons are not supported in wxStaticBitmap under WIN16." );
98 const wxBitmap
& bmp
= (const wxBitmap
&)bitmap
;
99 wxMask
*mask
= bmp
.GetMask();
100 if ( mask
&& mask
->GetMaskBitmap() )
103 icon
->CopyFromBitmap(bmp
);
111 // create a static control with either SS_BITMAP or SS_ICON style depending
112 // on what we have here
113 const wxChar
*classname
= wxT("STATIC");
114 int winstyle
= m_isIcon
? SS_ICON
: SS_BITMAP
;
116 const wxChar
*classname
= wxT("BUTTON");
117 int winstyle
= BS_OWNERDRAW
;
120 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
121 winstyle
|= WS_CLIPSIBLINGS
;
124 m_hWnd
= (WXHWND
)::CreateWindow
128 // NOT DISABLED!!! We want to move it in Dialog Editor.
129 winstyle
| WS_CHILD
| WS_VISIBLE
/* | WS_CLIPSIBLINGS */ , // | WS_DISABLED,
131 (HWND
)parent
->GetHWND(),
137 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create static bitmap") );
139 SetImage(icon
? icon
: &bitmap
);
140 delete icon
; // may be NULL, ok
142 // Subclass again for purposes of dialog editing mode
145 SetFont(GetParent()->GetFont());
147 SetSize(x
, y
, width
, height
);
152 bool wxStaticBitmap::ImageIsOk() const
154 return m_image
&& m_image
->Ok();
157 void wxStaticBitmap::Free()
164 wxSize
wxStaticBitmap::DoGetBestSize() const
166 // reuse the current size (as wxWindow does) instead of using some
167 // arbitrary default size (as wxControl, our immediate base class, does)
168 return wxWindow::DoGetBestSize();
171 void wxStaticBitmap::SetImage(const wxGDIImage
* image
)
175 const wxIcon
*icon
= wxDynamicCast(image
, wxIcon
);
176 m_isIcon
= icon
!= NULL
;
179 m_image
= new wxIcon(*icon
);
183 wxASSERT_MSG( wxDynamicCast(image
, wxBitmap
),
184 _T("not an icon and not a bitmap?") );
186 const wxBitmap
*bitmap
= (wxBitmap
*)image
;
188 m_image
= new wxBitmap(*bitmap
);
197 HANDLE handle
= (HANDLE
)m_image
->GetHandle();
198 ::SendMessage(GetHwnd(), STM_SETIMAGE
,
199 m_isIcon
? IMAGE_ICON
: IMAGE_BITMAP
, (LPARAM
)handle
);
204 int width
= image
->GetWidth(),
205 height
= image
->GetHeight();
206 if ( width
&& height
)
211 ::MoveWindow(GetHwnd(), x
, y
, width
, height
, FALSE
);
220 InvalidateRect(GetHwndOf(GetParent()), &rect
, TRUE
);
223 // under Win32 we use the standard static control style for this
225 bool wxStaticBitmap::MSWOnDraw(WXDRAWITEMSTRUCT
*item
)
227 LPDRAWITEMSTRUCT lpDIS
= (LPDRAWITEMSTRUCT
) item
;
229 wxCHECK_MSG( !m_isIcon
, FALSE
, _T("icons not supported in wxStaticBitmap") );
231 wxBitmap
* bitmap
= (wxBitmap
*)m_image
;
235 HDC hDC
= lpDIS
->hDC
;
236 HDC memDC
= ::CreateCompatibleDC(hDC
);
238 HBITMAP old
= (HBITMAP
) ::SelectObject(memDC
, (HBITMAP
) bitmap
->GetHBITMAP());
243 int x
= lpDIS
->rcItem
.left
;
244 int y
= lpDIS
->rcItem
.top
;
245 int width
= lpDIS
->rcItem
.right
- x
;
246 int height
= lpDIS
->rcItem
.bottom
- y
;
248 // Centre the bitmap in the control area
249 int x1
= (int) (x
+ ((width
- bitmap
->GetWidth()) / 2));
250 int y1
= (int) (y
+ ((height
- bitmap
->GetHeight()) / 2));
252 ::BitBlt(hDC
, x1
, y1
, bitmap
->GetWidth(), bitmap
->GetHeight(), memDC
, 0, 0, SRCCOPY
);
254 ::SelectObject(memDC
, old
);
262 // We need this or the control can never be moved e.g. in Dialog Editor.
263 long wxStaticBitmap::MSWWindowProc(WXUINT nMsg
,
267 // Ensure that static items get messages. Some controls don't like this
268 // message to be intercepted (e.g. RichEdit), hence the tests.
269 if ( nMsg
== WM_NCHITTEST
)
270 return (long)HTCLIENT
;
272 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
275 #endif // wxUSE_STATBMP