]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/statbmp.cpp
909a09c5325afee6f66e70241dba40d1dcbb3c57
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 const wxBitmap
& bmp
= (const wxBitmap
&)bitmap
;
91 wxMask
*mask
= bmp
.GetMask();
92 if ( mask
&& mask
->GetMaskBitmap() )
95 icon
->CopyFromBitmap(bmp
);
102 // create a static control with either SS_BITMAP or SS_ICON style depending
103 // on what we have here
104 const wxChar
*classname
= wxT("STATIC");
105 int winstyle
= m_isIcon
? SS_ICON
: SS_BITMAP
;
107 const wxChar
*classname
= wxT("BUTTON");
108 int winstyle
= BS_OWNERDRAW
;
111 m_hWnd
= (WXHWND
)::CreateWindow
115 winstyle
| WS_CHILD
| WS_VISIBLE
| WS_DISABLED
,
117 (HWND
)parent
->GetHWND(),
123 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create static bitmap") );
125 SetImage(icon
? icon
: &bitmap
);
126 delete icon
; // may be NULL, ok
128 // Subclass again for purposes of dialog editing mode
131 SetFont(GetParent()->GetFont());
133 SetSize(x
, y
, width
, height
);
138 bool wxStaticBitmap::ImageIsOk() const
140 return m_image
&& m_image
->Ok();
143 void wxStaticBitmap::Free()
150 wxSize
wxStaticBitmap::DoGetBestSize() const
152 // reuse the current size (as wxWindow does) instead of using some
153 // arbitrary default size (as wxControl, our immediate base class, does)
154 return wxWindow::DoGetBestSize();
157 void wxStaticBitmap::SetImage(const wxGDIImage
* image
)
161 const wxIcon
*icon
= wxDynamicCast(image
, wxIcon
);
162 m_isIcon
= icon
!= NULL
;
165 m_image
= new wxIcon(*icon
);
169 wxASSERT_MSG( wxDynamicCast(image
, wxBitmap
),
170 _T("not an icon and not a bitmap?") );
172 const wxBitmap
*bitmap
= (wxBitmap
*)image
;
174 m_image
= new wxBitmap(*bitmap
);
183 HANDLE handle
= (HANDLE
)m_image
->GetHandle();
184 ::SendMessage(GetHwnd(), STM_SETIMAGE
,
185 m_isIcon
? IMAGE_ICON
: IMAGE_BITMAP
, (LPARAM
)handle
);
190 int width
= image
->GetWidth(),
191 height
= image
->GetHeight();
192 if ( width
&& height
)
197 ::MoveWindow(GetHwnd(), x
, y
, width
, height
, FALSE
);
206 InvalidateRect(GetHwndOf(GetParent()), &rect
, TRUE
);
209 // under Win32 we use the standard static control style for this
211 bool wxStaticBitmap::MSWOnDraw(WXDRAWITEMSTRUCT
*item
)
213 LPDRAWITEMSTRUCT lpDIS
= (LPDRAWITEMSTRUCT
) item
;
215 wxCHECK_MSG( !m_isIcon
, FALSE
, _T("icons not supported in wxStaticBitmap") );
217 wxBitmap
* bitmap
= (wxBitmap
*)m_image
;
221 HDC hDC
= lpDIS
->hDC
;
222 HDC memDC
= ::CreateCompatibleDC(hDC
);
224 HBITMAP old
= (HBITMAP
) ::SelectObject(memDC
, (HBITMAP
) bitmap
->GetHBITMAP());
229 int x
= lpDIS
->rcItem
.left
;
230 int y
= lpDIS
->rcItem
.top
;
231 int width
= lpDIS
->rcItem
.right
- x
;
232 int height
= lpDIS
->rcItem
.bottom
- y
;
234 // Centre the bitmap in the control area
235 int x1
= (int) (x
+ ((width
- bitmap
->GetWidth()) / 2));
236 int y1
= (int) (y
+ ((height
- bitmap
->GetHeight()) / 2));
238 ::BitBlt(hDC
, x1
, y1
, bitmap
->GetWidth(), bitmap
->GetHeight(), memDC
, 0, 0, SRCCOPY
);
240 ::SelectObject(memDC
, old
);
248 // We need this or the control can never be moved e.g. in Dialog Editor.
249 long wxStaticBitmap::MSWWindowProc(WXUINT nMsg
,
253 // Ensure that static items get messages. Some controls don't like this
254 // message to be intercepted (e.g. RichEdit), hence the tests.
255 if ( nMsg
== WM_NCHITTEST
)
256 return (long)HTCLIENT
;
258 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);