1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStaticBox
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
15 #include "wx/window.h"
16 #include "wx/os2/private.h"
20 #include "wx/dcclient.h"
23 #include "wx/statbox.h"
25 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox
, wxControl
)
27 BEGIN_EVENT_TABLE(wxStaticBox
, wxControl
)
28 EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground
)
36 bool wxStaticBox::Create(wxWindow
*parent
, wxWindowID id
,
37 const wxString
& label
,
45 if (parent
) parent
->AddChild(this);
47 SetBackgroundColour(parent
->GetBackgroundColour()) ;
48 SetForegroundColour(parent
->GetForegroundColour()) ;
51 m_windowId
= (int)NewControlId();
60 m_windowStyle
= style
;
64 long msStyle = BS_GROUPBOX | WS_CHILD | WS_VISIBLE ; // GROUP_FLAGS;
67 WXDWORD exStyle = Determine3DEffects(0, &want3D) ;
70 CreateWindowEx(exStyle, wxT("BUTTON"), (const wxChar *)label, msStyle,
71 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
72 wxGetInstance(), NULL);
76 Ctl3dSubclassCtl(wx_button);
81 m_hWnd = (WXHWND)wx_button;
83 // Subclass again for purposes of dialog editing mode
84 SubclassWin(GetHWND());
86 SetFont(parent->GetFont());
88 SetSize(x, y, width, height);
89 ShowWindow(wx_button, SW_SHOW);
94 wxSize
wxStaticBox::DoGetBestSize() const
97 wxGetCharSize(GetHWND(), &cx
, &cy
, (wxFont
*)&GetFont());
100 GetTextExtent(wxGetWindowText(m_hWnd
), &wBox
, &cy
);
103 int hBox
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
);
105 return wxSize(wBox
, hBox
);
108 WXHBRUSH
wxStaticBox::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
115 if (GetParent()->GetTransparentBackground())
116 SetBkMode((HDC) pDC, TRANSPARENT);
118 SetBkMode((HDC) pDC, OPAQUE);
120 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
121 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
123 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
125 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
126 // has a zero usage count.
127 // backgroundBrush->RealizeResource();
128 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
133 // Shouldn't erase the whole window, since the static box must only paint its
135 void wxStaticBox::OnEraseBackground(wxEraseEvent
& event
)
137 // If we don't have this (call Default()), we don't paint the background properly.
138 // If we do have this, we seem to overwrite enclosed controls.
139 // Is it the WS_CLIPCHILDREN style that's causing the problems?
140 // Probably - without this style, the background of the window will show through,
141 // so the control doesn't have to paint it. The window background will always be
142 // painted before all other controls, therefore there are no problems with
143 // controls being hidden by the static box.
144 // So, if we could specify wxCLIP_CHILDREN in window, or not, we could optimise painting better.
145 // We would assume wxCLIP_CHILDREN in a frame and a scrolled window, but not in a panel.
146 // Is this too platform-specific?? What else can we do? Not a lot, since we have to pass
147 // this information from arbitrary wxWindow derivatives, and it depends on what you wish to
148 // do with the windows.
149 // Alternatively, just make sure that wxStaticBox is always at the back! There are probably
150 // few other circumstances where it matters about child clipping. But what about painting onto
151 // to panel, inside a groupbox? Doesn't appear, because the box wipes it out.
152 wxWindow
*parent
= GetParent();
155 if ( parent && parent->GetHWND() && (::GetWindowLong((HWND) parent->GetHWND(), GWL_STYLE) & WS_CLIPCHILDREN) )
157 // TODO: May in fact need to generate a paint event for inside this
158 // control's rectangle, otherwise all controls are going to be clipped -
160 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
161 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
165 ::GetClientRect(GetHwnd(), &rect);
166 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
167 ::DeleteObject(hBrush);
168 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
177 MRESULT
wxStaticBox::OS2WindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
181 if ( nMsg == WM_NCHITTEST)
183 int xPos = LOWORD(lParam); // horizontal position of cursor
184 int yPos = HIWORD(lParam); // vertical position of cursor
186 // ScreenToClient(&xPos, &yPos);
188 // Make sure you can drag by the top of the groupbox, but let
189 // other (enclosed) controls get mouse events also
191 return (long)HTCLIENT;
195 return wxControl::OS2WindowProc(nMsg
, wParam
, lParam
);