Include wx/utils.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / motif / statbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/statbox.cpp
3 // Purpose: wxStaticBox
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __VMS
16 #define XtDisplay XTDISPLAY
17 #endif
18
19 #include "wx/statbox.h"
20
21 #ifndef WX_PRECOMP
22 #include "wx/utils.h"
23 #endif
24
25 #ifdef __VMS__
26 #pragma message disable nosimpint
27 #endif
28 #include <Xm/Frame.h>
29 #include <Xm/Label.h>
30 #ifdef __VMS__
31 #pragma message enable nosimpint
32 #endif
33
34 #include "wx/motif/private.h"
35
36 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
37
38 BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
39 //EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
40 END_EVENT_TABLE()
41
42 // ----------------------------------------------------------------------------
43 // wxXmSizeKeeper
44 // ----------------------------------------------------------------------------
45
46 // helper class to reduce code duplication
47 class wxXmSizeKeeper
48 {
49 Dimension m_x, m_y;
50 Widget m_widget;
51 public:
52 wxXmSizeKeeper( Widget w )
53 : m_widget( w )
54 {
55 XtVaGetValues( m_widget,
56 XmNwidth, &m_x,
57 XmNheight, &m_y,
58 NULL );
59 }
60
61 void Restore()
62 {
63 int x, y;
64
65 XtVaGetValues( m_widget,
66 XmNwidth, &x,
67 XmNheight, &y,
68 NULL );
69 if( x != m_x || y != m_y )
70 XtVaSetValues( m_widget,
71 XmNwidth, m_x,
72 XmNheight, m_y,
73 NULL );
74 }
75 };
76
77 /*
78 * Static box
79 */
80
81 wxStaticBox::wxStaticBox()
82 {
83 m_labelWidget = (WXWidget) 0;
84 }
85
86 bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
87 const wxString& label,
88 const wxPoint& pos,
89 const wxSize& size,
90 long style,
91 const wxString& name)
92 {
93 if( !CreateControl( parent, id, pos, size, style,
94 wxDefaultValidator, name ) )
95 return false;
96
97 Widget parentWidget = (Widget) parent->GetClientWidget();
98
99 m_mainWidget = XtVaCreateManagedWidget ("staticboxframe",
100 xmFrameWidgetClass, parentWidget,
101 // MBN: why override default?
102 // XmNshadowType, XmSHADOW_IN,
103 NULL);
104
105 if (!label.empty())
106 {
107 wxString label1(wxStripMenuCodes(label));
108 wxXmString text(label1);
109 Display* dpy = XtDisplay( parentWidget );
110
111 m_labelWidget = (WXWidget) XtVaCreateManagedWidget ("staticboxlabel",
112 xmLabelWidgetClass, (Widget)m_mainWidget,
113 wxFont::GetFontTag(), m_font.GetFontTypeC(dpy),
114 XmNlabelString, text(),
115 #if wxCHECK_MOTIF_VERSION( 2, 0 )
116 XmNframeChildType, XmFRAME_TITLE_CHILD,
117 #else
118 XmNchildType, XmFRAME_TITLE_CHILD,
119 #endif
120 NULL);
121 }
122
123 AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y);
124 ChangeBackgroundColour();
125
126 return true;
127 }
128
129 wxStaticBox::~wxStaticBox()
130 {
131 DetachWidget(m_mainWidget);
132 XtDestroyWidget((Widget) m_mainWidget);
133
134 m_mainWidget = (WXWidget) 0;
135 m_labelWidget = (WXWidget) 0;
136 }
137
138 void wxStaticBox::SetLabel( const wxString& label )
139 {
140 wxXmSizeKeeper sk( (Widget)GetMainWidget() );
141
142 wxStaticBoxBase::SetLabel( label );
143
144 sk.Restore();
145 }
146
147 void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const
148 {
149 Dimension shadow, border;
150
151 XtVaGetValues( (Widget) GetMainWidget(),
152 XmNshadowThickness, &shadow,
153 XmNborderWidth, &border,
154 NULL);
155
156 *borderOther = shadow + border;
157
158 if( GetLabelWidget() )
159 {
160 XtWidgetGeometry preferred;
161 XtQueryGeometry( (Widget) GetLabelWidget(), NULL, &preferred );
162
163 *borderTop = preferred.height;
164 }
165 else
166 {
167 *borderTop = shadow;
168 }
169 }