]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/statbox.cpp
6ca6074e54a9fdcdcc33e99a471fa941ec08b9e9
   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" 
  23 #include "wx/window.h" 
  24 #include "wx/msw/private.h" 
  28 #include "wx/dcclient.h" 
  31 #include "wx/statbox.h" 
  33 #if !USE_SHARED_LIBRARY 
  34 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox
, wxControl
) 
  36 BEGIN_EVENT_TABLE(wxStaticBox
, wxControl
) 
  37     EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground
) 
  46 bool wxStaticBox::Create(wxWindow 
*parent
, wxWindowID id
, 
  47            const wxString
& label
, 
  55   if (parent
) parent
->AddChild(this); 
  57   SetBackgroundColour(parent
->GetBackgroundColour()) ; 
  58   SetForegroundColour(parent
->GetForegroundColour()) ; 
  61       m_windowId 
= (int)NewControlId(); 
  70   m_windowStyle 
= style
; 
  72   long msStyle 
= BS_GROUPBOX 
| WS_CHILD 
| WS_VISIBLE 
; // GROUP_FLAGS; 
  75   WXDWORD exStyle 
= Determine3DEffects(0, &want3D
) ; 
  78     CreateWindowEx(exStyle
, _T("BUTTON"), (const wxChar 
*)label
, msStyle
, 
  79                     0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, 
  80                     wxGetInstance(), NULL
); 
  84     Ctl3dSubclassCtl(wx_button
); 
  89   m_hWnd 
= (WXHWND
)wx_button
; 
  91   // Subclass again for purposes of dialog editing mode 
  92   SubclassWin(GetHWND()); 
  94   SetFont(parent
->GetFont()); 
  96   SetSize(x
, y
, width
, height
); 
  97   ShowWindow(wx_button
, SW_SHOW
); 
 102 void wxStaticBox::SetLabel(const wxString
& label
) 
 104   SetWindowText((HWND
)m_hWnd
, (const wxChar 
*)label
); 
 107 void wxStaticBox::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
) 
 109   int currentX
, currentY
; 
 110   GetPosition(¤tX
, ¤tY
); 
 117   if (x 
== -1 || (sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
)) 
 119   if (y 
== -1 || (sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
)) 
 122   AdjustForParentClientOrigin(x1
, y1
, sizeFlags
); 
 124   // If we're prepared to use the existing size, then... 
 125   if (width 
== -1 && height 
== -1 && ((sizeFlags 
& wxSIZE_AUTO
) != wxSIZE_AUTO
)) 
 136   wxGetCharSize(GetHWND(), &cx
, &cy
, & this->GetFont()); 
 138   GetTextExtent(wxGetWindowText(m_hWnd
), ¤t_width
, &cyf
, 
 139                 NULL
,NULL
, & this->GetFont()); 
 141    w1 
= current_width 
+ 3*cx
; 
 143     h1 
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cyf
); 
 145   MoveWindow((HWND
)m_hWnd
, x1
, y1
, w1
, h1
, TRUE
); 
 148 WXHBRUSH 
wxStaticBox::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
, 
 149             WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
) 
 154     HBRUSH hbrush 
= Ctl3dCtlColorEx(message
, wParam
, lParam
); 
 155     return (WXHBRUSH
) hbrush
; 
 159   if (GetParent()->GetTransparentBackground()) 
 160     SetBkMode((HDC
) pDC
, TRANSPARENT
); 
 162     SetBkMode((HDC
) pDC
, OPAQUE
); 
 164   ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); 
 165   ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); 
 167   wxBrush 
*backgroundBrush 
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
); 
 169   // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush 
 170   // has a zero usage count. 
 171 //  backgroundBrush->RealizeResource(); 
 172   return (WXHBRUSH
) backgroundBrush
->GetResourceHandle(); 
 175 // Shouldn't erase the whole window, since the static box must only paint its 
 177 void wxStaticBox::OnEraseBackground(wxEraseEvent
& event
) 
 179     // If we don't have this (call Default()), we don't paint the background properly. 
 180     // If we do have this, we seem to overwrite enclosed controls. 
 181     // Is it the WS_CLIPCHILDREN style that's causing the problems? 
 182     // Probably - without this style, the background of the window will show through, 
 183     // so the control doesn't have to paint it. The window background will always be 
 184     // painted before all other controls, therefore there are no problems with 
 185     // controls being hidden by the static box. 
 186     // So, if we could specify wxCLIP_CHILDREN in window, or not, we could optimise painting better. 
 187     // We would assume wxCLIP_CHILDREN in a frame and a scrolled window, but not in a panel. 
 188     // Is this too platform-specific?? What else can we do? Not a lot, since we have to pass 
 189     // this information from arbitrary wxWindow derivatives, and it depends on what you wish to 
 190     // do with the windows. 
 191     // Alternatively, just make sure that wxStaticBox is always at the back! There are probably 
 192     // few other circumstances where it matters about child clipping. But what about painting onto 
 193     // to panel, inside a groupbox? Doesn't appear, because the box wipes it out. 
 194   wxWindow 
*parent 
= GetParent(); 
 195   if ( parent 
&& parent
->GetHWND() && (::GetWindowLong((HWND
) parent
->GetHWND(), GWL_STYLE
) & WS_CLIPCHILDREN
) ) 
 197         // TODO: May in fact need to generate a paint event for inside this 
 198         // control's rectangle, otherwise all controls are going to be clipped - 
 200         HBRUSH hBrush 
= ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); 
 201         int mode 
= ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), MM_TEXT
); 
 205         ::GetClientRect((HWND
) GetHWND(), &rect
); 
 206         ::FillRect ((HDC
) event
.GetDC()->GetHDC(), &rect
, hBrush
); 
 207         ::DeleteObject(hBrush
); 
 208         ::SetMapMode((HDC
) event
.GetDC()->GetHDC(), mode
); 
 216 long wxStaticBox::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
) 
 218     if (nMsg 
== WM_NCHITTEST
) 
 220         int xPos 
= LOWORD(lParam
);  // horizontal position of cursor 
 221         int yPos 
= HIWORD(lParam
);  // vertical position of cursor 
 223         ScreenToClient(&xPos
, &yPos
); 
 225         // Make sure you can drag by the top of the groupbox, but let 
 226         // other (enclosed) controls get mouse events also 
 228             return (long)HTCLIENT
; 
 231     return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);