]> git.saurik.com Git - wxWidgets.git/blob - src/motif/statbox.cpp
Compilation fixes for SUN CC.
[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 m_windowFont = parent->GetFont();
57
58 SetName(name);
59
60 if (parent) parent->AddChild(this);
61
62 if ( id == -1 )
63 m_windowId = (int)NewControlId();
64 else
65 m_windowId = id;
66
67 m_windowStyle = style;
68
69 bool hasLabel = (!label.IsNull() && !label.IsEmpty()) ;
70
71 Widget parentWidget = (Widget) parent->GetClientWidget();
72
73 Widget formWidget = XtVaCreateManagedWidget ((char*) (const char*) name,
74 xmFormWidgetClass, parentWidget,
75 XmNmarginHeight, 0,
76 XmNmarginWidth, 0,
77 NULL);
78
79
80 if (hasLabel)
81 {
82 XmFontList fontList = (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(parentWidget));
83
84 wxString label1(wxStripMenuCodes(label));
85 XmString text = XmStringCreateSimple ((char*) (const char*) label1);
86 m_labelWidget = (WXWidget) XtVaCreateManagedWidget ((char*) (const char*) label1,
87 xmLabelWidgetClass, formWidget,
88 XmNfontList, fontList,
89 XmNlabelString, text,
90 NULL);
91 XmStringFree (text);
92 }
93
94 Widget frameWidget = XtVaCreateManagedWidget ("frame",
95 xmFrameWidgetClass, formWidget,
96 XmNshadowType, XmSHADOW_IN,
97 // XmNmarginHeight, 0,
98 // XmNmarginWidth, 0,
99 NULL);
100
101 if (hasLabel)
102 XtVaSetValues ((Widget) m_labelWidget,
103 XmNtopAttachment, XmATTACH_FORM,
104 XmNleftAttachment, XmATTACH_FORM,
105 XmNrightAttachment, XmATTACH_FORM,
106 XmNalignment, XmALIGNMENT_BEGINNING,
107 NULL);
108
109 XtVaSetValues (frameWidget,
110 XmNtopAttachment, hasLabel ? XmATTACH_WIDGET : XmATTACH_FORM,
111 XmNtopWidget, hasLabel ? (Widget) m_labelWidget : formWidget,
112 XmNbottomAttachment, XmATTACH_FORM,
113 XmNleftAttachment, XmATTACH_FORM,
114 XmNrightAttachment, XmATTACH_FORM,
115 NULL);
116
117 m_mainWidget = (WXWidget) frameWidget;
118 m_formWidget = (WXWidget) formWidget;
119
120 SetCanAddEventHandler(TRUE);
121 AttachWidget (parent, (WXWidget) frameWidget, (WXWidget) formWidget, pos.x, pos.y, size.x, size.y);
122 ChangeBackgroundColour();
123
124 return TRUE;
125 }
126
127 void wxStaticBox::SetLabel(const wxString& label)
128 {
129 if (!m_labelWidget)
130 return;
131
132 if (!label.IsNull())
133 {
134 wxString label1(wxStripMenuCodes(label));
135
136 XmString text = XmStringCreateSimple ((char*) (const char*) label1);
137 XtVaSetValues ((Widget) m_labelWidget,
138 XmNlabelString, text,
139 XmNlabelType, XmSTRING,
140 NULL);
141 XmStringFree (text);
142 }
143 }
144
145 wxString wxStaticBox::GetLabel() const
146 {
147 if (!m_labelWidget)
148 return wxEmptyString;
149
150 XmString text = 0;
151 char *s;
152 XtVaGetValues ((Widget) m_labelWidget,
153 XmNlabelString, &text,
154 NULL);
155
156 if (!text)
157 return wxEmptyString;
158
159 if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
160 {
161 wxString str(s);
162 XtFree (s);
163 return str;
164 }
165 else
166 {
167 return wxEmptyString;
168 }
169 }
170
171 void wxStaticBox::SetSize(int x, int y, int width, int height, int sizeFlags)
172 {
173 wxControl::SetSize (x, y, width, height, sizeFlags);
174
175 if (m_labelWidget)
176 {
177 Dimension xx, yy;
178 XtVaGetValues ((Widget) m_labelWidget, XmNwidth, &xx, XmNheight, &yy, NULL);
179
180 if (width > -1)
181 XtVaSetValues ((Widget) m_mainWidget, XmNwidth, width,
182 NULL);
183 if (height > -1)
184 XtVaSetValues ((Widget) m_mainWidget, XmNheight, height - yy,
185 NULL);
186 }
187 }
188
189 void wxStaticBox::ChangeFont(bool keepOriginalSize)
190 {
191 wxWindow::ChangeFont(keepOriginalSize);
192 }
193
194 void wxStaticBox::ChangeBackgroundColour()
195 {
196 wxWindow::ChangeBackgroundColour();
197 }
198
199 void wxStaticBox::ChangeForegroundColour()
200 {
201 wxWindow::ChangeForegroundColour();
202 }
203