]>
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 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 // NOT DISABLED!!! We want to move it in Dialog Editor.
116 winstyle
| WS_CHILD
| WS_VISIBLE
, // | WS_DISABLED,
118 (HWND
)parent
->GetHWND(),
124 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create static bitmap") );
126 SetImage(icon
? icon
: &bitmap
);
127 delete icon
; // may be NULL, ok
129 // Subclass again for purposes of dialog editing mode
132 SetFont(GetParent()->GetFont());
134 SetSize(x
, y
, width
, height
);
139 bool wxStaticBitmap::ImageIsOk() const
141 return m_image
&& m_image
->Ok();
144 void wxStaticBitmap::Free()
151 wxSize
wxStaticBitmap::DoGetBestSize() const
153 // reuse the current size (as wxWindow does) instead of using some
154 // arbitrary default size (as wxControl, our immediate base class, does)
155 return wxWindow::DoGetBestSize();
158 void wxStaticBitmap::SetImage(const wxGDIImage
* image
)
162 const wxIcon
*icon
= wxDynamicCast(image
, wxIcon
);
163 m_isIcon
= icon
!= NULL
;
166 m_image
= new wxIcon(*icon
);
170 wxASSERT_MSG( wxDynamicCast(image
, wxBitmap
),
171 _T("not an icon and not a bitmap?") );
173 const wxBitmap
*bitmap
= (wxBitmap
*)image
;
175 m_image
= new wxBitmap(*bitmap
);
184 HANDLE handle
= (HANDLE
)m_image
->GetHandle();
185 ::SendMessage(GetHwnd(), STM_SETIMAGE
,
186 m_isIcon
? IMAGE_ICON
: IMAGE_BITMAP
, (LPARAM
)handle
);
191 int width
= image
->GetWidth(),
192 height
= image
->GetHeight();
193 if ( width
&& height
)
198 ::MoveWindow(GetHwnd(), x
, y
, width
, height
, FALSE
);
207 InvalidateRect(GetHwndOf(GetParent()), &rect
, TRUE
);
210 // under Win32 we use the standard static control style for this
212 bool wxStaticBitmap::MSWOnDraw(WXDRAWITEMSTRUCT
*item
)
214 LPDRAWITEMSTRUCT lpDIS
= (LPDRAWITEMSTRUCT
) item
;
216 wxCHECK_MSG( !m_isIcon
, FALSE
, _T("icons not supported in wxStaticBitmap") );
218 wxBitmap
* bitmap
= (wxBitmap
*)m_image
;
222 HDC hDC
= lpDIS
->hDC
;
223 HDC memDC
= ::CreateCompatibleDC(hDC
);
225 HBITMAP old
= (HBITMAP
) ::SelectObject(memDC
, (HBITMAP
) bitmap
->GetHBITMAP());
230 int x
= lpDIS
->rcItem
.left
;
231 int y
= lpDIS
->rcItem
.top
;
232 int width
= lpDIS
->rcItem
.right
- x
;
233 int height
= lpDIS
->rcItem
.bottom
- y
;
235 // Centre the bitmap in the control area
236 int x1
= (int) (x
+ ((width
- bitmap
->GetWidth()) / 2));
237 int y1
= (int) (y
+ ((height
- bitmap
->GetHeight()) / 2));
239 ::BitBlt(hDC
, x1
, y1
, bitmap
->GetWidth(), bitmap
->GetHeight(), memDC
, 0, 0, SRCCOPY
);
241 ::SelectObject(memDC
, old
);
249 // We need this or the control can never be moved e.g. in Dialog Editor.
250 long wxStaticBitmap::MSWWindowProc(WXUINT nMsg
,
254 // Ensure that static items get messages. Some controls don't like this
255 // message to be intercepted (e.g. RichEdit), hence the tests.
256 if ( nMsg
== WM_NCHITTEST
)
257 return (long)HTCLIENT
;
259 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);