]>
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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "statbmp.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
24 #include "wx/statbmp.h"
28 #include "wx/msw/private.h"
30 #if !USE_SHARED_LIBRARY
31 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap
, wxControl
)
38 bool wxStaticBitmap::Create(wxWindow
*parent
, wxWindowID id
,
39 const wxBitmap
& bitmap
,
45 m_messageBitmap
= bitmap
;
47 if (parent
) parent
->AddChild(this);
49 m_backgroundColour
= parent
->GetBackgroundColour() ;
50 m_foregroundColour
= parent
->GetForegroundColour() ;
53 m_windowId
= (int)NewControlId();
62 if ( width
< 0 && bitmap
.Ok() )
63 width
= bitmap
.GetWidth();
64 if ( height
< 0 && bitmap
.Ok() )
65 height
= bitmap
.GetHeight();
67 m_windowStyle
= style
;
69 // Use an ownerdraw button to produce a static bitmap, since there's
70 // no ownerdraw static.
71 // TODO: perhaps this should be a static item, with style SS_BITMAP.
72 m_hWnd
= (WXHWND
)CreateWindow
76 BS_OWNERDRAW
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
,
78 (HWND
)parent
->GetHWND(),
84 // Subclass again for purposes of dialog editing mode
87 SetFont(* GetParent()->GetFont());
89 SetSize(x
, y
, width
, height
);
93 void wxStaticBitmap::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
95 int currentX
, currentY
;
96 GetPosition(¤tX
, ¤tY
);
100 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
102 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
105 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
107 int actualWidth
= width
;
108 int actualHeight
= height
;
113 // If we're prepared to use the existing width, then...
114 if (width
== -1 && ((sizeFlags
& wxSIZE_AUTO_WIDTH
) != wxSIZE_AUTO_WIDTH
))
116 else actualWidth
= width
;
118 // If we're prepared to use the existing height, then...
119 if (height
== -1 && ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) != wxSIZE_AUTO_HEIGHT
))
121 else actualHeight
= height
;
123 MoveWindow((HWND
) GetHWND(), x1
, y1
, actualWidth
, actualHeight
, TRUE
);
126 void wxStaticBitmap::SetBitmap(const wxBitmap
& bitmap
)
128 m_messageBitmap
= bitmap
;
135 rect
.left
= x
; rect
.top
= y
; rect
.right
= x
+ w
; rect
.bottom
= y
+ h
;
138 MoveWindow((HWND
) GetHWND(), x
, y
, bitmap
.GetWidth(), bitmap
.GetHeight(),
141 InvalidateRect((HWND
) GetParent()->GetHWND(), &rect
, TRUE
);
144 bool wxStaticBitmap::MSWOnDraw(WXDRAWITEMSTRUCT
*item
)
146 long style
= GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
148 if ((style
& 0xFF) == SS_BITMAP
)
150 // Should we call Default() here?
153 // Let default procedure draw the bitmap, which is defined
154 // in the Windows resource.
159 LPDRAWITEMSTRUCT lpDIS
= (LPDRAWITEMSTRUCT
) item
;
161 wxBitmap
* bitmap
= &m_messageBitmap
;
165 HDC hDC
= lpDIS
->hDC
;
166 HDC memDC
= ::CreateCompatibleDC(hDC
);
168 HBITMAP old
= (HBITMAP
) ::SelectObject(memDC
, (HBITMAP
) bitmap
->GetHBITMAP());
173 RECT rect
= lpDIS
->rcItem
;
175 int x
= lpDIS
->rcItem
.left
;
176 int y
= lpDIS
->rcItem
.top
;
177 int width
= lpDIS
->rcItem
.right
- x
;
178 int height
= lpDIS
->rcItem
.bottom
- y
;
180 // Centre the bitmap in the control area
181 int x1
= (int) (x
+ ((width
- bitmap
->GetWidth()) / 2));
182 int y1
= (int) (y
+ ((height
- bitmap
->GetHeight()) / 2));
184 ::BitBlt(hDC
, x1
, y1
, bitmap
->GetWidth(), bitmap
->GetHeight(), memDC
, 0, 0, SRCCOPY
);
186 ::SelectObject(memDC
, old
);
193 long wxStaticBitmap::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
195 // Ensure that static items get messages. Some controls don't like this
196 // message to be intercepted (e.g. RichEdit), hence the tests.
197 if (nMsg
== WM_NCHITTEST
)
198 return (long)HTCLIENT
;
200 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);