More Motif stuff incl. beginnings of wxToolBar
[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 #ifdef __GNUG__
13 #pragma implementation "statbox.h"
14 #endif
15
16 #include "wx/statbox.h"
17 #include "wx/utils.h"
18
19 #include <Xm/Frame.h>
20 #include <Xm/Form.h>
21 #include <Xm/Label.h>
22 #include <Xm/LabelG.h>
23
24 #include <wx/motif/private.h>
25
26 #if !USE_SHARED_LIBRARY
27 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
28
29 BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
30 EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
31 END_EVENT_TABLE()
32
33 #endif
34
35 /*
36 * Static box
37 */
38
39 wxStaticBox::wxStaticBox()
40 {
41 m_formWidget = (WXWidget) 0;
42 m_labelWidget = (WXWidget) 0;
43 }
44
45 bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
46 const wxString& label,
47 const wxPoint& pos,
48 const wxSize& size,
49 long style,
50 const wxString& name)
51 {
52 m_formWidget = (WXWidget) 0;
53 m_labelWidget = (WXWidget) 0;
54 m_backgroundColour = parent->GetBackgroundColour();
55 m_foregroundColour = parent->GetForegroundColour();
56
57 SetName(name);
58
59 if (parent) parent->AddChild(this);
60
61 if ( id == -1 )
62 m_windowId = (int)NewControlId();
63 else
64 m_windowId = id;
65
66 m_windowStyle = style;
67
68 bool hasLabel = (!label.IsNull() && !label.IsEmpty()) ;
69
70 Widget parentWidget = (Widget) parent->GetClientWidget();
71
72 Widget formWidget = XtVaCreateManagedWidget ((char*) (const char*) name,
73 xmFormWidgetClass, parentWidget,
74 XmNmarginHeight, 0,
75 XmNmarginWidth, 0,
76 NULL);
77
78
79 if (hasLabel)
80 {
81 wxString label1(wxStripMenuCodes(label));
82 XmString text = XmStringCreateSimple ((char*) (const char*) label1);
83 m_labelWidget = (WXWidget) XtVaCreateManagedWidget ((char*) (const char*) label1,
84 xmLabelWidgetClass, formWidget,
85 XmNlabelString, text,
86 NULL);
87 XmStringFree (text);
88 }
89
90 Widget frameWidget = XtVaCreateManagedWidget ("frame",
91 xmFrameWidgetClass, formWidget,
92 XmNshadowType, XmSHADOW_IN,
93 // XmNmarginHeight, 0,
94 // XmNmarginWidth, 0,
95 NULL);
96
97 if (hasLabel)
98 XtVaSetValues ((Widget) m_labelWidget,
99 XmNtopAttachment, XmATTACH_FORM,
100 XmNleftAttachment, XmATTACH_FORM,
101 XmNrightAttachment, XmATTACH_FORM,
102 XmNalignment, XmALIGNMENT_BEGINNING,
103 NULL);
104
105 XtVaSetValues (frameWidget,
106 XmNtopAttachment, hasLabel ? XmATTACH_WIDGET : XmATTACH_FORM,
107 XmNtopWidget, hasLabel ? (Widget) m_labelWidget : formWidget,
108 XmNbottomAttachment, XmATTACH_FORM,
109 XmNleftAttachment, XmATTACH_FORM,
110 XmNrightAttachment, XmATTACH_FORM,
111 NULL);
112
113 m_mainWidget = (Widget) formWidget;
114
115 SetCanAddEventHandler(TRUE);
116 AttachWidget (parent, m_mainWidget, (WXWidget) frameWidget, pos.x, pos.y, size.x, size.y);
117 ChangeBackgroundColour();
118
119 return TRUE;
120 }
121
122 void wxStaticBox::SetLabel(const wxString& label)
123 {
124 if (!m_labelWidget)
125 return;
126
127 if (!label.IsNull())
128 {
129 wxString label1(wxStripMenuCodes(label));
130
131 XmString text = XmStringCreateSimple ((char*) (const char*) label1);
132 XtVaSetValues ((Widget) m_labelWidget,
133 XmNlabelString, text,
134 XmNlabelType, XmSTRING,
135 NULL);
136 XmStringFree (text);
137 }
138 }
139
140 wxString wxStaticBox::GetLabel() const
141 {
142 if (!m_labelWidget)
143 return wxEmptyString;
144
145 XmString text = 0;
146 char *s;
147 XtVaGetValues ((Widget) m_labelWidget,
148 XmNlabelString, &text,
149 NULL);
150
151 if (!text)
152 return wxEmptyString;
153
154 if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
155 {
156 wxString str(s);
157 XtFree (s);
158 return str;
159 }
160 else
161 {
162 return wxEmptyString;
163 }
164 }
165
166 void wxStaticBox::SetSize(int x, int y, int width, int height, int sizeFlags)
167 {
168 wxControl::SetSize (x, y, width, height, sizeFlags);
169
170 if (m_labelWidget)
171 {
172 Dimension xx, yy;
173 XtVaGetValues ((Widget) m_labelWidget, XmNwidth, &xx, XmNheight, &yy, NULL);
174
175 if (width > -1)
176 XtVaSetValues ((Widget) m_mainWidget, XmNwidth, width,
177 NULL);
178 if (height > -1)
179 XtVaSetValues ((Widget) m_mainWidget, XmNheight, height - yy,
180 NULL);
181 }
182 }
183
184 void wxStaticBox::ChangeFont()
185 {
186 // TODO
187 }
188
189 void wxStaticBox::ChangeBackgroundColour()
190 {
191 // TODO
192 }
193
194 void wxStaticBox::ChangeForegroundColour()
195 {
196 // TODO
197 }
198