]> git.saurik.com Git - wxWidgets.git/blob - src/motif/statbox.cpp
extra semicolons removed
[wxWidgets.git] / src / motif / statbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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/defs.h"
20
21 #include "wx/statbox.h"
22 #include "wx/utils.h"
23
24 #ifdef __VMS__
25 #pragma message disable nosimpint
26 #endif
27 #include <Xm/Frame.h>
28 #include <Xm/Label.h>
29 #ifdef __VMS__
30 #pragma message enable nosimpint
31 #endif
32
33 #include "wx/motif/private.h"
34
35 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
36
37 BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
38 //EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
39 END_EVENT_TABLE()
40
41 // ----------------------------------------------------------------------------
42 // wxXmSizeKeeper
43 // ----------------------------------------------------------------------------
44
45 // helper class to reduce code duplication
46 class wxXmSizeKeeper
47 {
48 Dimension m_x, m_y;
49 Widget m_widget;
50 public:
51 wxXmSizeKeeper( Widget w )
52 : m_widget( w )
53 {
54 XtVaGetValues( m_widget,
55 XmNwidth, &m_x,
56 XmNheight, &m_y,
57 NULL );
58 }
59
60 void Restore()
61 {
62 int x, y;
63
64 XtVaGetValues( m_widget,
65 XmNwidth, &x,
66 XmNheight, &y,
67 NULL );
68 if( x != m_x || y != m_y )
69 XtVaSetValues( m_widget,
70 XmNwidth, m_x,
71 XmNheight, m_y,
72 NULL );
73 }
74 };
75
76 /*
77 * Static box
78 */
79
80 wxStaticBox::wxStaticBox()
81 {
82 m_labelWidget = (WXWidget) 0;
83 }
84
85 bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
86 const wxString& label,
87 const wxPoint& pos,
88 const wxSize& size,
89 long style,
90 const wxString& name)
91 {
92 if( !CreateControl( parent, id, pos, size, style,
93 wxDefaultValidator, name ) )
94 return false;
95
96 Widget parentWidget = (Widget) parent->GetClientWidget();
97
98 m_mainWidget = XtVaCreateManagedWidget ("staticboxframe",
99 xmFrameWidgetClass, parentWidget,
100 // MBN: why override default?
101 // XmNshadowType, XmSHADOW_IN,
102 NULL);
103
104 bool hasLabel = (!label.IsNull() && !label.IsEmpty()) ;
105 if (hasLabel)
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 }