]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/motif/statbox.cpp
fixed parsing of comments before root node
[wxWidgets.git] / src / motif / statbox.cpp
... / ...
CommitLineData
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/statbox.h"
21#include "wx/utils.h"
22
23#ifdef __VMS__
24#pragma message disable nosimpint
25#endif
26#include <Xm/Frame.h>
27#include <Xm/Form.h>
28#include <Xm/Label.h>
29#include <Xm/LabelG.h>
30#ifdef __VMS__
31#pragma message enable nosimpint
32#endif
33
34#include "wx/motif/private.h"
35
36IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
37
38BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
39//EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
40END_EVENT_TABLE()
41
42
43/*
44 * Static box
45 */
46
47wxStaticBox::wxStaticBox()
48{
49 m_formWidget = (WXWidget) 0;
50 m_labelWidget = (WXWidget) 0;
51}
52
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{
60 m_formWidget = (WXWidget) 0;
61 m_labelWidget = (WXWidget) 0;
62 m_backgroundColour = parent->GetBackgroundColour();
63 m_foregroundColour = parent->GetForegroundColour();
64 m_font = parent->GetFont();
65
66 SetName(name);
67
68 if (parent) parent->AddChild(this);
69
70 if ( id == -1 )
71 m_windowId = (int)NewControlId();
72 else
73 m_windowId = id;
74
75 m_windowStyle = style;
76
77 bool hasLabel = (!label.IsNull() && !label.IsEmpty()) ;
78
79 Widget parentWidget = (Widget) parent->GetClientWidget();
80
81 Widget formWidget = XtVaCreateManagedWidget ((char*) (const char*) name,
82 xmFormWidgetClass, parentWidget,
83 XmNmarginHeight, 0,
84 XmNmarginWidth, 0,
85 NULL);
86
87
88 if (hasLabel)
89 {
90 XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
91
92 wxString label1(wxStripMenuCodes(label));
93 XmString text = XmStringCreateSimple ((char*) (const char*) label1);
94 m_labelWidget = (WXWidget) XtVaCreateManagedWidget ((char*) (const char*) label1,
95 xmLabelWidgetClass, formWidget,
96 XmNfontList, fontList,
97 XmNlabelString, text,
98 NULL);
99 XmStringFree (text);
100 }
101
102 Widget frameWidget = XtVaCreateManagedWidget ("frame",
103 xmFrameWidgetClass, formWidget,
104 XmNshadowType, XmSHADOW_IN,
105 //XmNmarginHeight, 0,
106 //XmNmarginWidth, 0,
107 NULL);
108
109 if (hasLabel)
110 XtVaSetValues ((Widget) m_labelWidget,
111 XmNtopAttachment, XmATTACH_FORM,
112 XmNleftAttachment, XmATTACH_FORM,
113 XmNrightAttachment, XmATTACH_FORM,
114 XmNalignment, XmALIGNMENT_BEGINNING,
115 NULL);
116
117 XtVaSetValues (frameWidget,
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);
124
125 m_mainWidget = (WXWidget) frameWidget;
126 m_formWidget = (WXWidget) formWidget;
127
128 SetCanAddEventHandler(TRUE);
129 AttachWidget (parent, (WXWidget) frameWidget, (WXWidget) formWidget, pos.x, pos.y, size.x, size.y);
130 ChangeBackgroundColour();
131
132 return TRUE;
133}
134
135wxStaticBox::~wxStaticBox()
136{
137 DetachWidget(m_formWidget);
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;
147}
148
149void wxStaticBox::SetLabel(const wxString& label)
150{
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,
160 XmNlabelString, text,
161 XmNlabelType, XmSTRING,
162 NULL);
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,
175 XmNlabelString, &text,
176 NULL);
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 }
191}
192
193void wxStaticBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
194{
195 wxControl::DoSetSize (x, y, width, height, sizeFlags);
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,
204 NULL);
205 if (height > -1)
206 XtVaSetValues ((Widget) m_mainWidget, XmNheight, height - yy,
207 NULL);
208 }
209}
210
211void wxStaticBox::ChangeFont(bool keepOriginalSize)
212{
213 wxWindow::ChangeFont(keepOriginalSize);
214}
215
216void wxStaticBox::ChangeBackgroundColour()
217{
218 wxWindow::ChangeBackgroundColour();
219 if (m_labelWidget)
220 DoChangeBackgroundColour(m_labelWidget, m_backgroundColour);
221}
222
223void wxStaticBox::ChangeForegroundColour()
224{
225 wxWindow::ChangeForegroundColour();
226 if (m_labelWidget)
227 DoChangeForegroundColour(m_labelWidget, m_foregroundColour);
228}
229