1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/statbox.cpp
3 // Purpose: wxStaticBox
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "statbox.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
35 #include "wx/dcclient.h"
38 #include "wx/statbox.h"
40 #include "wx/msw/private.h"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 #if wxUSE_EXTENDED_RTTI
47 WX_DEFINE_FLAGS( wxStaticBoxStyle
)
49 WX_BEGIN_FLAGS( wxStaticBoxStyle
)
50 // new style border flags, we put them first to
51 // use them for streaming out
52 WX_FLAGS_MEMBER(wxBORDER_SIMPLE
)
53 WX_FLAGS_MEMBER(wxBORDER_SUNKEN
)
54 WX_FLAGS_MEMBER(wxBORDER_DOUBLE
)
55 WX_FLAGS_MEMBER(wxBORDER_RAISED
)
56 WX_FLAGS_MEMBER(wxBORDER_STATIC
)
57 WX_FLAGS_MEMBER(wxBORDER_NONE
)
59 // old style border flags
60 WX_FLAGS_MEMBER(wxSIMPLE_BORDER
)
61 WX_FLAGS_MEMBER(wxSUNKEN_BORDER
)
62 WX_FLAGS_MEMBER(wxDOUBLE_BORDER
)
63 WX_FLAGS_MEMBER(wxRAISED_BORDER
)
64 WX_FLAGS_MEMBER(wxSTATIC_BORDER
)
65 WX_FLAGS_MEMBER(wxNO_BORDER
)
67 // standard window styles
68 WX_FLAGS_MEMBER(wxTAB_TRAVERSAL
)
69 WX_FLAGS_MEMBER(wxCLIP_CHILDREN
)
70 WX_FLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
71 WX_FLAGS_MEMBER(wxWANTS_CHARS
)
72 WX_FLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE
)
73 WX_FLAGS_MEMBER(wxALWAYS_SHOW_SB
)
74 WX_FLAGS_MEMBER(wxVSCROLL
)
75 WX_FLAGS_MEMBER(wxHSCROLL
)
77 WX_END_FLAGS( wxStaticBoxStyle
)
79 IMPLEMENT_DYNAMIC_CLASS_XTI(wxStaticBox
, wxControl
,"wx/statbox.h")
81 WX_BEGIN_PROPERTIES_TABLE(wxStaticBox
)
82 WX_PROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxEmptyString
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
83 WX_PROPERTY_FLAGS( WindowStyle
, wxStaticBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
88 WX_END_PROPERTIES_TABLE()
90 WX_BEGIN_HANDLERS_TABLE(wxStaticBox
)
91 WX_END_HANDLERS_TABLE()
93 WX_CONSTRUCTOR_6( wxStaticBox
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Label
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
95 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox
, wxControl
)
98 // ============================================================================
100 // ============================================================================
102 // ----------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
106 bool wxStaticBox::Create(wxWindow
*parent
,
108 const wxString
& label
,
112 const wxString
& name
)
114 if ( !CreateControl(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
117 // as wxStaticBox doesn't draw its own background, we make it transparent
118 // to force redrawing its background which could have been overwritten by
119 // the other controls inside it
121 // FIXME: I still think that it isn't the right solution because the static
122 // boxes shouldn't have to be transparent if the redrawing was done
123 // right elsewhere - who ever had to make them transparent in non
124 // wxWindows programs, after all? But for now it does fix a serious
125 // problem (try resizing the sizers test screen in the layout sample
126 // after removing WS_EX_TRANSPARENT bit) and so let's use it until
127 // we fix the real underlying problem
128 if ( !MSWCreateControl(wxT("BUTTON"), BS_GROUPBOX
, pos
, size
, label
,
137 // to be transparent we should have the same colour as the parent as well
138 SetBackgroundColour(GetParent()->GetBackgroundColour());
143 wxSize
wxStaticBox::DoGetBestSize() const
146 wxGetCharSize(GetHWND(), &cx
, &cy
, &GetFont());
149 GetTextExtent(wxGetWindowText(m_hWnd
), &wBox
, &cy
);
152 int hBox
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
);
154 return wxSize(wBox
, hBox
);
157 long wxStaticBox::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
163 // FIXME: this hack is specific to dialog ed, shouldn't it be
164 // somehow disabled during normal operation?
166 int xPos
= LOWORD(lParam
); // horizontal position of cursor
167 int yPos
= HIWORD(lParam
); // vertical position of cursor
169 ScreenToClient(&xPos
, &yPos
);
171 // Make sure you can drag by the top of the groupbox, but let
172 // other (enclosed) controls get mouse events also
174 return (long)HTCLIENT
;
179 // prevent wxControl from processing this message because it will
180 // erase the background incorrectly and there is no way for us to
181 // override this at wxWin event level (if we do process the event,
182 // we don't know how to do it properly - paint the background
183 // without painting over other controls - and if we don't,
184 // wxControl still gets it)
185 return MSWDefWindowProc(nMsg
, wParam
, lParam
);
188 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
191 #endif // wxUSE_STATBOX