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