]>
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 #if !USE_SHARED_LIBRARY
46 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap
, wxControl
)
49 // ===========================================================================
51 // ===========================================================================
53 // ---------------------------------------------------------------------------
55 // ---------------------------------------------------------------------------
57 bool wxStaticBitmap::Create(wxWindow
*parent
, wxWindowID id
,
58 const wxBitmap
& 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 m_isIcon
= bitmap
.IsKindOf(CLASSINFO(wxIcon
));
88 // create a static control with either SS_BITMAP or SS_ICON style depending
89 // on what we have here
90 const wxChar
*classname
= _T("STATIC");
91 int winstyle
= m_isIcon
? SS_ICON
: SS_BITMAP
;
93 const wxChar
*classname
= _T("BUTTON");
94 int winstyle
= BS_OWNERDRAW
;
97 m_hWnd
= (WXHWND
)::CreateWindow
101 winstyle
| WS_CHILD
| WS_VISIBLE
,
103 (HWND
)parent
->GetHWND(),
109 wxCHECK_MSG( m_hWnd
, FALSE
, _T("Failed to create static bitmap") );
113 // Subclass again for purposes of dialog editing mode
116 SetFont(GetParent()->GetFont());
118 SetSize(x
, y
, width
, height
);
123 bool wxStaticBitmap::ImageIsOk() const
125 if ( m_isIcon
&& m_image
.icon
)
126 return m_image
.icon
->Ok();
127 else if ( m_image
.bitmap
)
128 return m_image
.bitmap
->Ok();
133 void wxStaticBitmap::Free()
138 delete m_image
.bitmap
;
143 void wxStaticBitmap::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
145 int currentX
, currentY
;
146 GetPosition(¤tX
, ¤tY
);
150 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
152 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
155 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
157 int actualWidth
= width
;
158 int actualHeight
= height
;
163 // If we're prepared to use the existing width, then...
164 if (width
== -1 && ((sizeFlags
& wxSIZE_AUTO_WIDTH
) != wxSIZE_AUTO_WIDTH
))
169 // If we're prepared to use the existing height, then...
170 if (height
== -1 && ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) != wxSIZE_AUTO_HEIGHT
))
173 actualHeight
= height
;
175 MoveWindow((HWND
) GetHWND(), x1
, y1
, actualWidth
, actualHeight
, TRUE
);
178 void wxStaticBitmap::SetBitmap(const wxBitmap
& bitmap
)
182 m_isIcon
= bitmap
.IsKindOf(CLASSINFO(wxIcon
));
184 m_image
.icon
= new wxIcon((const wxIcon
&)bitmap
);
186 m_image
.bitmap
= new wxBitmap(bitmap
);
194 HANDLE handle
= m_isIcon
? (HANDLE
)m_image
.icon
->GetHICON()
195 : (HANDLE
)m_image
.bitmap
->GetHBITMAP();
196 ::SendMessage((HWND
)m_hWnd
, STM_SETIMAGE
,
197 m_isIcon
? IMAGE_ICON
: IMAGE_BITMAP
, (LPARAM
)handle
);
202 int width
= bitmap
.GetWidth(),
203 height
= bitmap
.GetHeight();
204 if ( width
&& height
)
209 ::MoveWindow((HWND
)GetHWND(), x
, y
, width
, height
, FALSE
);
213 RECT rect
= { x
, y
, x
+ w
, y
+ h
};
214 InvalidateRect((HWND
)GetParent()->GetHWND(), &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 wxBitmap
* bitmap
= m_image
.bitmap
;
227 HDC hDC
= lpDIS
->hDC
;
228 HDC memDC
= ::CreateCompatibleDC(hDC
);
230 HBITMAP old
= (HBITMAP
) ::SelectObject(memDC
, (HBITMAP
) bitmap
->GetHBITMAP());
235 int x
= lpDIS
->rcItem
.left
;
236 int y
= lpDIS
->rcItem
.top
;
237 int width
= lpDIS
->rcItem
.right
- x
;
238 int height
= lpDIS
->rcItem
.bottom
- y
;
240 // Centre the bitmap in the control area
241 int x1
= (int) (x
+ ((width
- bitmap
->GetWidth()) / 2));
242 int y1
= (int) (y
+ ((height
- bitmap
->GetHeight()) / 2));
244 ::BitBlt(hDC
, x1
, y1
, bitmap
->GetWidth(), bitmap
->GetHeight(), memDC
, 0, 0, SRCCOPY
);
246 ::SelectObject(memDC
, old
);
253 long wxStaticBitmap::MSWWindowProc(WXUINT nMsg
,
257 // Ensure that static items get messages. Some controls don't like this
258 // message to be intercepted (e.g. RichEdit), hence the tests.
259 if ( nMsg
== WM_NCHITTEST
)
260 return (long)HTCLIENT
;
262 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);