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