]> git.saurik.com Git - wxWidgets.git/blob - src/msw/statbox.cpp
wxStrdup(NULL) doesn't work
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 #if wxUSE_EXTENDED_RTTI
47 IMPLEMENT_DYNAMIC_CLASS_XTI(wxStaticBox, wxControl,"wx/statbox.h")
48
49 WX_BEGIN_PROPERTIES_TABLE(wxStaticBox)
50 WX_PROPERTY( Label,wxString, SetLabel, GetLabel, wxT("") )
51 /*
52 TODO PROPERTIES :
53 label
54 */
55 WX_END_PROPERTIES_TABLE()
56
57 WX_BEGIN_HANDLERS_TABLE(wxStaticBox)
58 WX_END_HANDLERS_TABLE()
59
60 WX_CONSTRUCTOR_6( wxStaticBox , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle )
61 #else
62 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
63 #endif
64
65 // ============================================================================
66 // implementation
67 // ============================================================================
68
69 // ----------------------------------------------------------------------------
70 // wxStaticBox
71 // ----------------------------------------------------------------------------
72
73 bool wxStaticBox::Create(wxWindow *parent,
74 wxWindowID id,
75 const wxString& label,
76 const wxPoint& pos,
77 const wxSize& size,
78 long style,
79 const wxString& name)
80 {
81 if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
82 return FALSE;
83
84 // as wxStaticBox doesn't draw its own background, we make it transparent
85 // to force redrawing its background which could have been overwritten by
86 // the other controls inside it
87 //
88 // FIXME: I still think that it isn't the right solution because the static
89 // boxes shouldn't have to be transparent if the redrawing was done
90 // right elsewhere - who ever had to make them transparent in non
91 // wxWindows programs, after all? But for now it does fix a serious
92 // problem (try resizing the sizers test screen in the layout sample
93 // after removing WS_EX_TRANSPARENT bit) and so let's use it until
94 // we fix the real underlying problem
95 if ( !MSWCreateControl(wxT("BUTTON"), BS_GROUPBOX, pos, size, label,
96 #ifdef __WXWINCE__
97 0
98 #else
99 WS_EX_TRANSPARENT
100 #endif
101 ) )
102 return FALSE;
103
104 // to be transparent we should have the same colour as the parent as well
105 SetBackgroundColour(GetParent()->GetBackgroundColour());
106
107 return TRUE;
108 }
109
110 wxSize wxStaticBox::DoGetBestSize() const
111 {
112 int cx, cy;
113 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
114
115 int wBox;
116 GetTextExtent(wxGetWindowText(m_hWnd), &wBox, &cy);
117
118 wBox += 3*cx;
119 int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
120
121 return wxSize(wBox, hBox);
122 }
123
124 long wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
125 {
126 switch ( nMsg )
127 {
128 #ifndef __WXWINCE__
129 case WM_NCHITTEST:
130 // FIXME: this hack is specific to dialog ed, shouldn't it be
131 // somehow disabled during normal operation?
132 {
133 int xPos = LOWORD(lParam); // horizontal position of cursor
134 int yPos = HIWORD(lParam); // vertical position of cursor
135
136 ScreenToClient(&xPos, &yPos);
137
138 // Make sure you can drag by the top of the groupbox, but let
139 // other (enclosed) controls get mouse events also
140 if ( yPos < 10 )
141 return (long)HTCLIENT;
142 }
143 break;
144 #endif
145 case WM_ERASEBKGND:
146 // prevent wxControl from processing this message because it will
147 // erase the background incorrectly and there is no way for us to
148 // override this at wxWin event level (if we do process the event,
149 // we don't know how to do it properly - paint the background
150 // without painting over other controls - and if we don't,
151 // wxControl still gets it)
152 return MSWDefWindowProc(nMsg, wParam, lParam);
153 }
154
155 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
156 }
157
158 #endif // wxUSE_STATBOX