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