]> git.saurik.com Git - wxWidgets.git/blame - src/motif/statbox.cpp
Added dialog tabbing to wxX11.
[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
f6045f99
GD
20#include "wx/defs.h"
21
4bb6408c 22#include "wx/statbox.h"
47bc1060
JS
23#include "wx/utils.h"
24
338dd992
JJ
25#ifdef __VMS__
26#pragma message disable nosimpint
27#endif
47bc1060
JS
28#include <Xm/Frame.h>
29#include <Xm/Form.h>
30#include <Xm/Label.h>
31#include <Xm/LabelG.h>
338dd992
JJ
32#ifdef __VMS__
33#pragma message enable nosimpint
34#endif
47bc1060 35
3096bd2f 36#include "wx/motif/private.h"
4bb6408c 37
4bb6408c
JS
38IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
39
40BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
31528cd3 41//EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
4bb6408c
JS
42END_EVENT_TABLE()
43
4bb6408c
JS
44
45/*
46 * Static box
47 */
31528cd3 48
47bc1060
JS
49wxStaticBox::wxStaticBox()
50{
51 m_formWidget = (WXWidget) 0;
52 m_labelWidget = (WXWidget) 0;
53}
54
4bb6408c
JS
55bool 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{
47bc1060
JS
62 m_formWidget = (WXWidget) 0;
63 m_labelWidget = (WXWidget) 0;
0d57be45
JS
64 m_backgroundColour = parent->GetBackgroundColour();
65 m_foregroundColour = parent->GetForegroundColour();
da175b2c 66 m_font = parent->GetFont();
47bc1060 67
4bb6408c
JS
68 SetName(name);
69
70 if (parent) parent->AddChild(this);
71
72 if ( id == -1 )
31528cd3 73 m_windowId = (int)NewControlId();
4bb6408c 74 else
31528cd3 75 m_windowId = id;
4bb6408c
JS
76
77 m_windowStyle = style;
78
47bc1060
JS
79 bool hasLabel = (!label.IsNull() && !label.IsEmpty()) ;
80
81 Widget parentWidget = (Widget) parent->GetClientWidget();
82
83 Widget formWidget = XtVaCreateManagedWidget ((char*) (const char*) name,
31528cd3
VZ
84 xmFormWidgetClass, parentWidget,
85 XmNmarginHeight, 0,
86 XmNmarginWidth, 0,
87 NULL);
47bc1060
JS
88
89
90 if (hasLabel)
91 {
da175b2c 92 XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
ea57084d 93
47bc1060
JS
94 wxString label1(wxStripMenuCodes(label));
95 XmString text = XmStringCreateSimple ((char*) (const char*) label1);
96 m_labelWidget = (WXWidget) XtVaCreateManagedWidget ((char*) (const char*) label1,
31528cd3
VZ
97 xmLabelWidgetClass, formWidget,
98 XmNfontList, fontList,
99 XmNlabelString, text,
100 NULL);
47bc1060
JS
101 XmStringFree (text);
102 }
103
104 Widget frameWidget = XtVaCreateManagedWidget ("frame",
31528cd3
VZ
105 xmFrameWidgetClass, formWidget,
106 XmNshadowType, XmSHADOW_IN,
107 //XmNmarginHeight, 0,
108 //XmNmarginWidth, 0,
109 NULL);
47bc1060
JS
110
111 if (hasLabel)
112 XtVaSetValues ((Widget) m_labelWidget,
31528cd3
VZ
113 XmNtopAttachment, XmATTACH_FORM,
114 XmNleftAttachment, XmATTACH_FORM,
115 XmNrightAttachment, XmATTACH_FORM,
116 XmNalignment, XmALIGNMENT_BEGINNING,
117 NULL);
47bc1060
JS
118
119 XtVaSetValues (frameWidget,
31528cd3
VZ
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);
47bc1060 126
94b49b93
JS
127 m_mainWidget = (WXWidget) frameWidget;
128 m_formWidget = (WXWidget) formWidget;
47bc1060
JS
129
130 SetCanAddEventHandler(TRUE);
94b49b93 131 AttachWidget (parent, (WXWidget) frameWidget, (WXWidget) formWidget, pos.x, pos.y, size.x, size.y);
0d57be45 132 ChangeBackgroundColour();
47bc1060
JS
133
134 return TRUE;
4bb6408c
JS
135}
136
b412f9be
JS
137wxStaticBox::~wxStaticBox()
138{
139 DetachWidget(m_formWidget);
15d5ab67
JS
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;
b412f9be
JS
149}
150
4bb6408c
JS
151void wxStaticBox::SetLabel(const wxString& label)
152{
47bc1060
JS
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,
31528cd3
VZ
162 XmNlabelString, text,
163 XmNlabelType, XmSTRING,
164 NULL);
47bc1060
JS
165 XmStringFree (text);
166 }
167}
168
169wxString wxStaticBox::GetLabel() const
170{
171 if (!m_labelWidget)
172 return wxEmptyString;
173
174 XmString text = 0;
175 char *s;
176 XtVaGetValues ((Widget) m_labelWidget,
31528cd3
VZ
177 XmNlabelString, &text,
178 NULL);
47bc1060
JS
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 }
4bb6408c
JS
193}
194
bfc6fde4 195void wxStaticBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
4bb6408c 196{
bfc6fde4 197 wxControl::DoSetSize (x, y, width, height, sizeFlags);
47bc1060
JS
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,
31528cd3 206 NULL);
47bc1060
JS
207 if (height > -1)
208 XtVaSetValues ((Widget) m_mainWidget, XmNheight, height - yy,
31528cd3 209 NULL);
47bc1060 210 }
4bb6408c
JS
211}
212
4b5f3fe6 213void wxStaticBox::ChangeFont(bool keepOriginalSize)
0d57be45 214{
4b5f3fe6 215 wxWindow::ChangeFont(keepOriginalSize);
0d57be45
JS
216}
217
218void wxStaticBox::ChangeBackgroundColour()
219{
321db4b6 220 wxWindow::ChangeBackgroundColour();
b412f9be
JS
221 if (m_labelWidget)
222 DoChangeBackgroundColour(m_labelWidget, m_backgroundColour);
0d57be45
JS
223}
224
225void wxStaticBox::ChangeForegroundColour()
226{
321db4b6 227 wxWindow::ChangeForegroundColour();
b412f9be
JS
228 if (m_labelWidget)
229 DoChangeForegroundColour(m_labelWidget, m_foregroundColour);
0d57be45
JS
230}
231