]>
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 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
119 winstyle
|= WS_CLIPSIBLINGS
;
122 m_hWnd
= (WXHWND
)::CreateWindow
126 // NOT DISABLED!!! We want to move it in Dialog Editor.
127 winstyle
| WS_CHILD
| WS_VISIBLE
/* | WS_CLIPSIBLINGS */ , // | WS_DISABLED,
129 (HWND
)parent
->GetHWND(),
135 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create static bitmap") );
137 SetImage(icon
? icon
: &bitmap
);
138 delete icon
; // may be NULL, ok
140 // Subclass again for purposes of dialog editing mode
143 SetFont(GetParent()->GetFont());
145 SetSize(x
, y
, width
, height
);
150 bool wxStaticBitmap::ImageIsOk() const
152 return m_image
&& m_image
->Ok();
155 void wxStaticBitmap::Free()
162 wxSize
wxStaticBitmap::DoGetBestSize() const
164 // reuse the current size (as wxWindow does) instead of using some
165 // arbitrary default size (as wxControl, our immediate base class, does)
166 return wxWindow::DoGetBestSize();
169 void wxStaticBitmap::SetImage(const wxGDIImage
* image
)
173 const wxIcon
*icon
= wxDynamicCast(image
, wxIcon
);
174 m_isIcon
= icon
!= NULL
;
177 m_image
= new wxIcon(*icon
);
181 wxASSERT_MSG( wxDynamicCast(image
, wxBitmap
),
182 _T("not an icon and not a bitmap?") );
184 const wxBitmap
*bitmap
= (wxBitmap
*)image
;
186 m_image
= new wxBitmap(*bitmap
);
195 HANDLE handle
= (HANDLE
)m_image
->GetHandle();
196 ::SendMessage(GetHwnd(), STM_SETIMAGE
,
197 m_isIcon
? IMAGE_ICON
: IMAGE_BITMAP
, (LPARAM
)handle
);
202 int width
= image
->GetWidth(),
203 height
= image
->GetHeight();
204 if ( width
&& height
)
209 ::MoveWindow(GetHwnd(), x
, y
, width
, height
, FALSE
);
218 InvalidateRect(GetHwndOf(GetParent()), &rect
, TRUE
);
221 // under Win32 we use the standard static control style for this
223 bool wxStaticBitmap::MSWOnDraw(WXDRAWITEMSTRUCT
*item
)
225 LPDRAWITEMSTRUCT lpDIS
= (LPDRAWITEMSTRUCT
) item
;
227 wxCHECK_MSG( !m_isIcon
, FALSE
, _T("icons not supported in wxStaticBitmap") );
229 wxBitmap
* bitmap
= (wxBitmap
*)m_image
;
233 HDC hDC
= lpDIS
->hDC
;
234 HDC memDC
= ::CreateCompatibleDC(hDC
);
236 HBITMAP old
= (HBITMAP
) ::SelectObject(memDC
, (HBITMAP
) bitmap
->GetHBITMAP());
241 int x
= lpDIS
->rcItem
.left
;
242 int y
= lpDIS
->rcItem
.top
;
243 int width
= lpDIS
->rcItem
.right
- x
;
244 int height
= lpDIS
->rcItem
.bottom
- y
;
246 // Centre the bitmap in the control area
247 int x1
= (int) (x
+ ((width
- bitmap
->GetWidth()) / 2));
248 int y1
= (int) (y
+ ((height
- bitmap
->GetHeight()) / 2));
250 ::BitBlt(hDC
, x1
, y1
, bitmap
->GetWidth(), bitmap
->GetHeight(), memDC
, 0, 0, SRCCOPY
);
252 ::SelectObject(memDC
, old
);
260 // We need this or the control can never be moved e.g. in Dialog Editor.
261 long wxStaticBitmap::MSWWindowProc(WXUINT nMsg
,
265 // Ensure that static items get messages. Some controls don't like this
266 // message to be intercepted (e.g. RichEdit), hence the tests.
267 if ( nMsg
== WM_NCHITTEST
)
268 return (long)HTCLIENT
;
270 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);