]>
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"
32 #include "wx/statbmp.h"
36 #include "wx/msw/private.h"
38 // ---------------------------------------------------------------------------
40 // ---------------------------------------------------------------------------
42 #if !USE_SHARED_LIBRARY
43 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap
, wxControl
)
46 // ===========================================================================
48 // ===========================================================================
50 // ---------------------------------------------------------------------------
52 // ---------------------------------------------------------------------------
54 bool wxStaticBitmap::Create(wxWindow
*parent
, wxWindowID id
,
55 const wxBitmap
& bitmap
,
65 parent
->AddChild(this);
67 m_backgroundColour
= parent
->GetBackgroundColour() ;
68 m_foregroundColour
= parent
->GetForegroundColour() ;
71 m_windowId
= (int)NewControlId();
80 m_windowStyle
= style
;
82 m_isIcon
= bitmap
.IsKindOf(CLASSINFO(wxIcon
));
85 // create a static control with either SS_BITMAP or SS_ICON style depending
86 // on what we have here
87 const char *classname
= "STATIC";
88 int winstyle
= m_isIcon
? SS_ICON
: SS_BITMAP
;
90 const char *classname
= "BUTTON";
91 int winstyle
= BS_OWNERDRAWN
;
94 m_hWnd
= (WXHWND
)::CreateWindow
98 winstyle
| WS_CHILD
| WS_VISIBLE
,
100 (HWND
)parent
->GetHWND(),
106 wxCHECK_MSG( m_hWnd
, FALSE
, "Failed to create static bitmap" );
110 // Subclass again for purposes of dialog editing mode
113 SetFont(GetParent()->GetFont());
115 SetSize(x
, y
, width
, height
);
120 bool wxStaticBitmap::ImageIsOk() const
122 if ( m_isIcon
&& m_image
.icon
)
123 return m_image
.icon
->Ok();
124 else if ( m_image
.bitmap
)
125 return m_image
.bitmap
->Ok();
130 void wxStaticBitmap::Free()
135 delete m_image
.bitmap
;
140 void wxStaticBitmap::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
142 int currentX
, currentY
;
143 GetPosition(¤tX
, ¤tY
);
147 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
149 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
152 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
154 int actualWidth
= width
;
155 int actualHeight
= height
;
160 // If we're prepared to use the existing width, then...
161 if (width
== -1 && ((sizeFlags
& wxSIZE_AUTO_WIDTH
) != wxSIZE_AUTO_WIDTH
))
166 // If we're prepared to use the existing height, then...
167 if (height
== -1 && ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) != wxSIZE_AUTO_HEIGHT
))
170 actualHeight
= height
;
172 MoveWindow((HWND
) GetHWND(), x1
, y1
, actualWidth
, actualHeight
, TRUE
);
175 void wxStaticBitmap::SetBitmap(const wxBitmap
& bitmap
)
179 m_isIcon
= bitmap
.IsKindOf(CLASSINFO(wxIcon
));
181 m_image
.icon
= new wxIcon((const wxIcon
&)bitmap
);
183 m_image
.bitmap
= new wxBitmap(bitmap
);
189 RECT rect
= { x
, y
, x
+ w
, y
+ h
};
192 HANDLE handle
= m_isIcon
? (HANDLE
)m_image
.icon
->GetHICON()
193 : (HANDLE
)m_image
.bitmap
->GetHBITMAP();
194 ::SendMessage((HWND
)m_hWnd
, STM_SETIMAGE
,
195 m_isIcon
? IMAGE_ICON
: IMAGE_BITMAP
, (LPARAM
)handle
);
200 int width
= bitmap
.GetWidth(),
201 height
= bitmap
.GetHeight();
202 if ( width
&& height
)
204 ::MoveWindow((HWND
)GetHWND(), x
, y
, width
, height
, FALSE
);
208 InvalidateRect((HWND
)GetParent()->GetHWND(), &rect
, TRUE
);
211 // under Win32 we use the standard static control style for this
213 bool wxStaticBitmap::MSWOnDraw(WXDRAWITEMSTRUCT
*item
)
215 LPDRAWITEMSTRUCT lpDIS
= (LPDRAWITEMSTRUCT
) item
;
217 wxBitmap
* bitmap
= m_image
.bitmap
;
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
);
247 long wxStaticBitmap::MSWWindowProc(WXUINT nMsg
,
251 // Ensure that static items get messages. Some controls don't like this
252 // message to be intercepted (e.g. RichEdit), hence the tests.
253 if ( nMsg
== WM_NCHITTEST
)
254 return (long)HTCLIENT
;
256 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);