]> git.saurik.com Git - wxWidgets.git/blob - src/msw/statbox.cpp
added wrapper for <commctrl.h> as well
[wxWidgets.git] / src / msw / statbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/statbox.cpp
3 // Purpose: wxStaticBox
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "statbox.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #if wxUSE_STATBOX
32
33 #ifndef WX_PRECOMP
34 #include "wx/app.h"
35 #include "wx/dcclient.h"
36 #endif
37
38 #include "wx/statbox.h"
39
40 #include "wx/msw/private.h"
41
42 // ----------------------------------------------------------------------------
43 // wxWin macros
44 // ----------------------------------------------------------------------------
45
46 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
47
48 // ============================================================================
49 // implementation
50 // ============================================================================
51
52 // ----------------------------------------------------------------------------
53 // wxStaticBox
54 // ----------------------------------------------------------------------------
55
56 bool wxStaticBox::Create(wxWindow *parent,
57 wxWindowID id,
58 const wxString& label,
59 const wxPoint& pos,
60 const wxSize& size,
61 long style,
62 const wxString& name)
63 {
64 if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
65 return FALSE;
66
67 // as wxStaticBox doesn't draw its own background, we make it transparent
68 // to force redrawing its background which could have been overwritten by
69 // the other controls inside it
70 //
71 // FIXME: I still think that it isn't the right solution because the static
72 // boxes shouldn't have to be transparent if the redrawing was done
73 // right elsewhere - who ever had to make them transparent in non
74 // wxWindows programs, after all? But for now it does fix a serious
75 // problem (try resizing the sizers test screen in the layout sample
76 // after removing WS_EX_TRANSPARENT bit) and so let's use it until
77 // we fix the real underlying problem
78 if ( !MSWCreateControl(wxT("BUTTON"), BS_GROUPBOX, pos, size, label,
79 #ifdef __WXWINCE__
80 0
81 #else
82 WS_EX_TRANSPARENT
83 #endif
84 ) )
85 return FALSE;
86
87 // to be transparent we should have the same colour as the parent as well
88 SetBackgroundColour(GetParent()->GetBackgroundColour());
89
90 return TRUE;
91 }
92
93 wxSize wxStaticBox::DoGetBestSize() const
94 {
95 int cx, cy;
96 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
97
98 int wBox;
99 GetTextExtent(wxGetWindowText(m_hWnd), &wBox, &cy);
100
101 wBox += 3*cx;
102 int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
103
104 return wxSize(wBox, hBox);
105 }
106
107 long wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
108 {
109 switch ( nMsg )
110 {
111 #ifndef __WXWINCE__
112 case WM_NCHITTEST:
113 // FIXME: this hack is specific to dialog ed, shouldn't it be
114 // somehow disabled during normal operation?
115 {
116 int xPos = LOWORD(lParam); // horizontal position of cursor
117 int yPos = HIWORD(lParam); // vertical position of cursor
118
119 ScreenToClient(&xPos, &yPos);
120
121 // Make sure you can drag by the top of the groupbox, but let
122 // other (enclosed) controls get mouse events also
123 if ( yPos < 10 )
124 return (long)HTCLIENT;
125 }
126 break;
127 #endif
128 case WM_ERASEBKGND:
129 // prevent wxControl from processing this message because it will
130 // erase the background incorrectly and there is no way for us to
131 // override this at wxWin event level (if we do process the event,
132 // we don't know how to do it properly - paint the background
133 // without painting over other controls - and if we don't,
134 // wxControl still gets it)
135 return MSWDefWindowProc(nMsg, wParam, lParam);
136 }
137
138 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
139 }
140
141 #endif // wxUSE_STATBOX