]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/statbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStaticBox
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "statbox.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
24 #include "wx/dcclient.h"
28 #include "wx/statbox.h"
29 #include "wx/msw/private.h"
31 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox
, wxControl
)
34 BEGIN_EVENT_TABLE(wxStaticBox
, wxControl
)
35 EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground
)
44 bool wxStaticBox::Create(wxWindow
*parent
, const wxWindowID id
,
45 const wxString
& label
,
53 if (parent
) parent
->AddChild(this);
55 SetBackgroundColour(parent
->GetDefaultBackgroundColour()) ;
56 SetForegroundColour(parent
->GetDefaultForegroundColour()) ;
59 m_windowId
= (int)NewControlId();
68 m_windowStyle
= style
;
70 long msStyle
= BS_GROUPBOX
| WS_CHILD
| WS_VISIBLE
; // GROUP_FLAGS;
73 WXDWORD exStyle
= Determine3DEffects(0, &want3D
) ;
76 CreateWindowEx(exStyle
, "BUTTON", (const char *)label
, msStyle
,
77 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
78 wxGetInstance(), NULL
);
82 Ctl3dSubclassCtl(wx_button
);
87 m_hWnd
= (WXHWND
)wx_button
;
89 // Subclass again for purposes of dialog editing mode
90 SubclassWin(GetHWND());
92 SetFont(* parent
->GetFont());
94 SetSize(x
, y
, width
, height
);
95 ShowWindow(wx_button
, SW_SHOW
);
100 void wxStaticBox::SetLabel(const wxString
& label
)
102 SetWindowText((HWND
)m_hWnd
, (const char *)label
);
105 void wxStaticBox::SetSize(const int x
, const int y
, const int width
, const int height
, const int sizeFlags
)
107 int currentX
, currentY
;
108 GetPosition(¤tX
, ¤tY
);
115 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
117 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
120 // If we're prepared to use the existing size, then...
121 if (width
== -1 && height
== -1 && ((sizeFlags
& wxSIZE_AUTO
) != wxSIZE_AUTO
))
134 HWND button
= (HWND
)m_hWnd
;
135 wxGetCharSize(GetHWND(), &cx
, &cy
,GetFont());
137 GetWindowText(button
, buf
, 300);
138 GetTextExtent(buf
, ¤t_width
, &cyf
,NULL
,NULL
,GetFont());
140 w1
= (int)(current_width
+ 3*cx
) ;
142 h1
= (int)(cyf
*EDIT_CONTROL_FACTOR
) ;
143 MoveWindow(button
, x1
, y1
, w1
, h1
, TRUE
);
145 #if WXWIN_COMPATIBILITY
146 GetEventHandler()->OldOnSize(width
, height
);
148 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
149 event
.eventObject
= this;
150 GetEventHandler()->ProcessEvent(event
);
154 WXHBRUSH
wxStaticBox::OnCtlColor(const WXHDC pDC
, const WXHWND pWnd
, const WXUINT nCtlColor
,
155 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
160 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
161 return (WXHBRUSH
) hbrush
;
165 if (GetParent()->GetTransparentBackground())
166 SetBkMode((HDC
) pDC
, TRANSPARENT
);
168 SetBkMode((HDC
) pDC
, OPAQUE
);
170 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
171 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
173 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
175 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
176 // has a zero usage count.
177 // backgroundBrush->RealizeResource();
178 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
181 // Shouldn't erase the whole window, since the static box must only paint its
183 void wxStaticBox::OnEraseBackground(wxEraseEvent
& event
)
185 wxWindow
*parent
= GetParent();
186 if ( parent
&& parent
->GetHWND() && (::GetWindowLong((HWND
) parent
->GetHWND(), GWL_STYLE
) & WS_CLIPCHILDREN
) )
188 // TODO: May in fact need to generate a paint event for inside this
189 // control's rectangle, otherwise all controls are going to be clipped -
191 HBRUSH hBrush
= ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
192 int mode
= ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), MM_TEXT
);
196 ::GetClientRect((HWND
) GetHWND(), &rect
);
197 ::FillRect ((HDC
) event
.GetDC()->GetHDC(), &rect
, hBrush
);
198 ::DeleteObject(hBrush
);
199 ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), mode
);
205 long wxStaticBox::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
207 // TODO: somehow, this has to accept mouse clicks in user interface edit mode,
208 // but not otherwise. Only there is no longer a UI edit mode...
210 // It worked before because the message could be processed if not in UI
211 // edit mode. We have to find some way of distinguishing this.
212 // Maybe this class can have an AcceptMouseEvents(bool) function; a sort of
213 // kludge... or, we can search for an active event table entry that will
214 // intercept mouse events, and if one exists (that isn't the default),
215 // skip the code below. Too time consuming though.
216 // Perhaps it's ok to do the default thing *anyway* because the title or edge
217 // of the window may still be active!
218 if (nMsg
== WM_NCHITTEST
)
221 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);