]>
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
, wxWindowID id
,
45 const wxString
& label
,
53 if (parent
) parent
->AddChild(this);
55 SetBackgroundColour(parent
->GetBackgroundColour()) ;
56 SetForegroundColour(parent
->GetForegroundColour()) ;
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::DoSetSize(int x
, int y
, int width
, int height
, 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 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
122 // If we're prepared to use the existing size, then...
123 if (width
== -1 && height
== -1 && ((sizeFlags
& wxSIZE_AUTO
) != wxSIZE_AUTO
))
134 wxGetCharSize(GetHWND(), &cx
, &cy
, & this->GetFont());
136 GetTextExtent(wxGetWindowText(m_hWnd
), ¤t_width
, &cyf
,
137 NULL
,NULL
, & this->GetFont());
139 w1
= current_width
+ 3*cx
;
141 h1
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cyf
);
143 MoveWindow((HWND
)m_hWnd
, x1
, y1
, w1
, h1
, TRUE
);
146 WXHBRUSH
wxStaticBox::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
147 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
152 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
153 return (WXHBRUSH
) hbrush
;
157 if (GetParent()->GetTransparentBackground())
158 SetBkMode((HDC
) pDC
, TRANSPARENT
);
160 SetBkMode((HDC
) pDC
, OPAQUE
);
162 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
163 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
165 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
167 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
168 // has a zero usage count.
169 // backgroundBrush->RealizeResource();
170 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
173 // Shouldn't erase the whole window, since the static box must only paint its
175 void wxStaticBox::OnEraseBackground(wxEraseEvent
& event
)
177 // If we don't have this (call Default()), we don't paint the background properly.
178 // If we do have this, we seem to overwrite enclosed controls.
179 // Is it the WS_CLIPCHILDREN style that's causing the problems?
180 // Probably - without this style, the background of the window will show through,
181 // so the control doesn't have to paint it. The window background will always be
182 // painted before all other controls, therefore there are no problems with
183 // controls being hidden by the static box.
184 // So, if we could specify wxCLIP_CHILDREN in window, or not, we could optimise painting better.
185 // We would assume wxCLIP_CHILDREN in a frame and a scrolled window, but not in a panel.
186 // Is this too platform-specific?? What else can we do? Not a lot, since we have to pass
187 // this information from arbitrary wxWindow derivatives, and it depends on what you wish to
188 // do with the windows.
189 // Alternatively, just make sure that wxStaticBox is always at the back! There are probably
190 // few other circumstances where it matters about child clipping. But what about painting onto
191 // to panel, inside a groupbox? Doesn't appear, because the box wipes it out.
192 wxWindow
*parent
= GetParent();
193 if ( parent
&& parent
->GetHWND() && (::GetWindowLong((HWND
) parent
->GetHWND(), GWL_STYLE
) & WS_CLIPCHILDREN
) )
195 // TODO: May in fact need to generate a paint event for inside this
196 // control's rectangle, otherwise all controls are going to be clipped -
198 HBRUSH hBrush
= ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
199 int mode
= ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), MM_TEXT
);
203 ::GetClientRect((HWND
) GetHWND(), &rect
);
204 ::FillRect ((HDC
) event
.GetDC()->GetHDC(), &rect
, hBrush
);
205 ::DeleteObject(hBrush
);
206 ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), mode
);
212 long wxStaticBox::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
214 if (nMsg
== WM_NCHITTEST
)
216 int xPos
= LOWORD(lParam
); // horizontal position of cursor
217 int yPos
= HIWORD(lParam
); // vertical position of cursor
219 ScreenToClient(&xPos
, &yPos
);
221 // Make sure you can drag by the top of the groupbox, but let
222 // other (enclosed) controls get mouse events also
224 return (long)HTCLIENT
;
227 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);