]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/statbox.cpp
c88b00c999ea4df6364c76c690fc7a535cc074c2
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 #if !USE_SHARED_LIBRARY
26 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox
, wxControl
)
28 BEGIN_EVENT_TABLE(wxStaticBox
, wxControl
)
29 EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground
)
38 bool wxStaticBox::Create(wxWindow
*parent
, wxWindowID id
,
39 const wxString
& label
,
47 if (parent
) parent
->AddChild(this);
49 SetBackgroundColour(parent
->GetBackgroundColour()) ;
50 SetForegroundColour(parent
->GetForegroundColour()) ;
53 m_windowId
= (int)NewControlId();
62 m_windowStyle
= style
;
66 long msStyle = BS_GROUPBOX | WS_CHILD | WS_VISIBLE ; // GROUP_FLAGS;
69 WXDWORD exStyle = Determine3DEffects(0, &want3D) ;
72 CreateWindowEx(exStyle, wxT("BUTTON"), (const wxChar *)label, msStyle,
73 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
74 wxGetInstance(), NULL);
78 Ctl3dSubclassCtl(wx_button);
83 m_hWnd = (WXHWND)wx_button;
85 // Subclass again for purposes of dialog editing mode
86 SubclassWin(GetHWND());
88 SetFont(parent->GetFont());
90 SetSize(x, y, width, height);
91 ShowWindow(wx_button, SW_SHOW);
96 wxSize
wxStaticBox::DoGetBestSize()
99 wxGetCharSize(GetHWND(), &cx
, &cy
, &GetFont());
102 GetTextExtent(wxGetWindowText(m_hWnd
), &wBox
, &cy
);
105 int hBox
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
);
107 return wxSize(wBox
, hBox
);
110 WXHBRUSH
wxStaticBox::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
117 if (GetParent()->GetTransparentBackground())
118 SetBkMode((HDC) pDC, TRANSPARENT);
120 SetBkMode((HDC) pDC, OPAQUE);
122 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
123 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
125 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
127 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
128 // has a zero usage count.
129 // backgroundBrush->RealizeResource();
130 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
135 // Shouldn't erase the whole window, since the static box must only paint its
137 void wxStaticBox::OnEraseBackground(wxEraseEvent
& event
)
139 // If we don't have this (call Default()), we don't paint the background properly.
140 // If we do have this, we seem to overwrite enclosed controls.
141 // Is it the WS_CLIPCHILDREN style that's causing the problems?
142 // Probably - without this style, the background of the window will show through,
143 // so the control doesn't have to paint it. The window background will always be
144 // painted before all other controls, therefore there are no problems with
145 // controls being hidden by the static box.
146 // So, if we could specify wxCLIP_CHILDREN in window, or not, we could optimise painting better.
147 // We would assume wxCLIP_CHILDREN in a frame and a scrolled window, but not in a panel.
148 // Is this too platform-specific?? What else can we do? Not a lot, since we have to pass
149 // this information from arbitrary wxWindow derivatives, and it depends on what you wish to
150 // do with the windows.
151 // Alternatively, just make sure that wxStaticBox is always at the back! There are probably
152 // few other circumstances where it matters about child clipping. But what about painting onto
153 // to panel, inside a groupbox? Doesn't appear, because the box wipes it out.
154 wxWindow
*parent
= GetParent();
157 if ( parent && parent->GetHWND() && (::GetWindowLong((HWND) parent->GetHWND(), GWL_STYLE) & WS_CLIPCHILDREN) )
159 // TODO: May in fact need to generate a paint event for inside this
160 // control's rectangle, otherwise all controls are going to be clipped -
162 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
163 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
167 ::GetClientRect(GetHwnd(), &rect);
168 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
169 ::DeleteObject(hBrush);
170 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
179 MRESULT
wxStaticBox::OS2WindowProc(HWND hwnd
, 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
;
194 return wxControl::OS2WindowProc(hwnd
, nMsg
, wParam
, lParam
);