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