]> git.saurik.com Git - wxWidgets.git/blame - src/motif/statbox.cpp
The Unicode handling fixes my app seemed to need.
[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
9// Licence: wxWindows licence
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
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>
4bb6408c
JS
25
26#if !USE_SHARED_LIBRARY
27IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
28
29BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
30 EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
31END_EVENT_TABLE()
32
33#endif
34
35/*
36 * Static box
37 */
38
47bc1060
JS
39wxStaticBox::wxStaticBox()
40{
41 m_formWidget = (WXWidget) 0;
42 m_labelWidget = (WXWidget) 0;
43}
44
4bb6408c
JS
45bool 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{
47bc1060
JS
52 m_formWidget = (WXWidget) 0;
53 m_labelWidget = (WXWidget) 0;
0d57be45
JS
54 m_backgroundColour = parent->GetBackgroundColour();
55 m_foregroundColour = parent->GetForegroundColour();
ea57084d 56 m_windowFont = parent->GetFont();
47bc1060 57
4bb6408c
JS
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
47bc1060
JS
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 {
ea57084d
JS
82 XmFontList fontList = (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(parentWidget));
83
47bc1060
JS
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,
ea57084d 88 XmNfontList, fontList,
47bc1060
JS
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
94b49b93
JS
117 m_mainWidget = (WXWidget) frameWidget;
118 m_formWidget = (WXWidget) formWidget;
47bc1060
JS
119
120 SetCanAddEventHandler(TRUE);
94b49b93 121 AttachWidget (parent, (WXWidget) frameWidget, (WXWidget) formWidget, pos.x, pos.y, size.x, size.y);
0d57be45 122 ChangeBackgroundColour();
47bc1060
JS
123
124 return TRUE;
4bb6408c
JS
125}
126
b412f9be
JS
127wxStaticBox::~wxStaticBox()
128{
129 DetachWidget(m_formWidget);
15d5ab67
JS
130 DetachWidget(m_mainWidget);
131 XtDestroyWidget((Widget) m_mainWidget);
132 if (m_labelWidget)
133 XtDestroyWidget((Widget) m_labelWidget);
134 XtDestroyWidget((Widget) m_formWidget);
135
136 m_mainWidget = (WXWidget) 0;
137 m_labelWidget = (WXWidget) 0;
138 m_formWidget = (WXWidget) 0;
b412f9be
JS
139}
140
4bb6408c
JS
141void wxStaticBox::SetLabel(const wxString& label)
142{
47bc1060
JS
143 if (!m_labelWidget)
144 return;
145
146 if (!label.IsNull())
147 {
148 wxString label1(wxStripMenuCodes(label));
149
150 XmString text = XmStringCreateSimple ((char*) (const char*) label1);
151 XtVaSetValues ((Widget) m_labelWidget,
152 XmNlabelString, text,
153 XmNlabelType, XmSTRING,
154 NULL);
155 XmStringFree (text);
156 }
157}
158
159wxString wxStaticBox::GetLabel() const
160{
161 if (!m_labelWidget)
162 return wxEmptyString;
163
164 XmString text = 0;
165 char *s;
166 XtVaGetValues ((Widget) m_labelWidget,
167 XmNlabelString, &text,
168 NULL);
169
170 if (!text)
171 return wxEmptyString;
172
173 if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
174 {
175 wxString str(s);
176 XtFree (s);
177 return str;
178 }
179 else
180 {
181 return wxEmptyString;
182 }
4bb6408c
JS
183}
184
bfc6fde4 185void wxStaticBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
4bb6408c 186{
bfc6fde4 187 wxControl::DoSetSize (x, y, width, height, sizeFlags);
47bc1060
JS
188
189 if (m_labelWidget)
190 {
191 Dimension xx, yy;
192 XtVaGetValues ((Widget) m_labelWidget, XmNwidth, &xx, XmNheight, &yy, NULL);
193
194 if (width > -1)
195 XtVaSetValues ((Widget) m_mainWidget, XmNwidth, width,
196 NULL);
197 if (height > -1)
198 XtVaSetValues ((Widget) m_mainWidget, XmNheight, height - yy,
199 NULL);
200 }
4bb6408c
JS
201}
202
4b5f3fe6 203void wxStaticBox::ChangeFont(bool keepOriginalSize)
0d57be45 204{
4b5f3fe6 205 wxWindow::ChangeFont(keepOriginalSize);
0d57be45
JS
206}
207
208void wxStaticBox::ChangeBackgroundColour()
209{
321db4b6 210 wxWindow::ChangeBackgroundColour();
b412f9be
JS
211 if (m_labelWidget)
212 DoChangeBackgroundColour(m_labelWidget, m_backgroundColour);
0d57be45
JS
213}
214
215void wxStaticBox::ChangeForegroundColour()
216{
321db4b6 217 wxWindow::ChangeForegroundColour();
b412f9be
JS
218 if (m_labelWidget)
219 DoChangeForegroundColour(m_labelWidget, m_foregroundColour);
0d57be45
JS
220}
221