]>
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 // we may have either bitmap or icon: if a bitmap with mask is passed, we
84 // will transform it to an icon ourselves because otherwise the mask will
85 // be ignored by Windows
86 wxIcon
*icon
= (wxIcon
*)NULL
;
87 m_isIcon
= bitmap
.IsKindOf(CLASSINFO(wxIcon
));
90 wxASSERT_MSG( !m_isIcon
, "Icons are not supported in wxStaticBitmap under WIN16." );
96 const wxBitmap
& bmp
= (const wxBitmap
&)bitmap
;
97 wxMask
*mask
= bmp
.GetMask();
98 if ( mask
&& mask
->GetMaskBitmap() )
101 icon
->CopyFromBitmap(bmp
);
109 // create a static control with either SS_BITMAP or SS_ICON style depending
110 // on what we have here
111 const wxChar
*classname
= wxT("STATIC");
112 int winstyle
= m_isIcon
? SS_ICON
: SS_BITMAP
;
114 const wxChar
*classname
= wxT("BUTTON");
115 int winstyle
= BS_OWNERDRAW
;
118 m_hWnd
= (WXHWND
)::CreateWindow
122 // NOT DISABLED!!! We want to move it in Dialog Editor.
123 winstyle
| WS_CHILD
| WS_VISIBLE
, // | WS_DISABLED,
125 (HWND
)parent
->GetHWND(),
131 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create static bitmap") );
133 SetImage(icon
? icon
: &bitmap
);
134 delete icon
; // may be NULL, ok
136 // Subclass again for purposes of dialog editing mode
139 SetFont(GetParent()->GetFont());
141 SetSize(x
, y
, width
, height
);
146 bool wxStaticBitmap::ImageIsOk() const
148 return m_image
&& m_image
->Ok();
151 void wxStaticBitmap::Free()
158 wxSize
wxStaticBitmap::DoGetBestSize() const
160 // reuse the current size (as wxWindow does) instead of using some
161 // arbitrary default size (as wxControl, our immediate base class, does)
162 return wxWindow::DoGetBestSize();
165 void wxStaticBitmap::SetImage(const wxGDIImage
* image
)
169 const wxIcon
*icon
= wxDynamicCast(image
, wxIcon
);
170 m_isIcon
= icon
!= NULL
;
173 m_image
= new wxIcon(*icon
);
177 wxASSERT_MSG( wxDynamicCast(image
, wxBitmap
),
178 _T("not an icon and not a bitmap?") );
180 const wxBitmap
*bitmap
= (wxBitmap
*)image
;
182 m_image
= new wxBitmap(*bitmap
);
191 HANDLE handle
= (HANDLE
)m_image
->GetHandle();
192 ::SendMessage(GetHwnd(), STM_SETIMAGE
,
193 m_isIcon
? IMAGE_ICON
: IMAGE_BITMAP
, (LPARAM
)handle
);
198 int width
= image
->GetWidth(),
199 height
= image
->GetHeight();
200 if ( width
&& height
)
205 ::MoveWindow(GetHwnd(), x
, y
, width
, height
, FALSE
);
214 InvalidateRect(GetHwndOf(GetParent()), &rect
, TRUE
);
217 // under Win32 we use the standard static control style for this
219 bool wxStaticBitmap::MSWOnDraw(WXDRAWITEMSTRUCT
*item
)
221 LPDRAWITEMSTRUCT lpDIS
= (LPDRAWITEMSTRUCT
) item
;
223 wxCHECK_MSG( !m_isIcon
, FALSE
, _T("icons not supported in wxStaticBitmap") );
225 wxBitmap
* bitmap
= (wxBitmap
*)m_image
;
229 HDC hDC
= lpDIS
->hDC
;
230 HDC memDC
= ::CreateCompatibleDC(hDC
);
232 HBITMAP old
= (HBITMAP
) ::SelectObject(memDC
, (HBITMAP
) bitmap
->GetHBITMAP());
237 int x
= lpDIS
->rcItem
.left
;
238 int y
= lpDIS
->rcItem
.top
;
239 int width
= lpDIS
->rcItem
.right
- x
;
240 int height
= lpDIS
->rcItem
.bottom
- y
;
242 // Centre the bitmap in the control area
243 int x1
= (int) (x
+ ((width
- bitmap
->GetWidth()) / 2));
244 int y1
= (int) (y
+ ((height
- bitmap
->GetHeight()) / 2));
246 ::BitBlt(hDC
, x1
, y1
, bitmap
->GetWidth(), bitmap
->GetHeight(), memDC
, 0, 0, SRCCOPY
);
248 ::SelectObject(memDC
, old
);
256 // We need this or the control can never be moved e.g. in Dialog Editor.
257 long wxStaticBitmap::MSWWindowProc(WXUINT nMsg
,
261 // Ensure that static items get messages. Some controls don't like this
262 // message to be intercepted (e.g. RichEdit), hence the tests.
263 if ( nMsg
== WM_NCHITTEST
)
264 return (long)HTCLIENT
;
266 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);