]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/motif/statbox.cpp
Improved selection mode handling in wxGrid::SelectBlock
[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#include "wx/statbox.h"
17#include "wx/utils.h"
18
19#ifdef __VMS__
20#pragma message disable nosimpint
21#endif
22#include <Xm/Frame.h>
23#include <Xm/Form.h>
24#include <Xm/Label.h>
25#include <Xm/LabelG.h>
26#ifdef __VMS__
27#pragma message enable nosimpint
28#endif
29
30#include "wx/motif/private.h"
31
32IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
33
34BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
35//EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
36END_EVENT_TABLE()
37
38
39/*
40 * Static box
41 */
42
43wxStaticBox::wxStaticBox()
44{
45 m_formWidget = (WXWidget) 0;
46 m_labelWidget = (WXWidget) 0;
47}
48
49bool 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{
56 m_formWidget = (WXWidget) 0;
57 m_labelWidget = (WXWidget) 0;
58 m_backgroundColour = parent->GetBackgroundColour();
59 m_foregroundColour = parent->GetForegroundColour();
60 m_font = parent->GetFont();
61
62 SetName(name);
63
64 if (parent) parent->AddChild(this);
65
66 if ( id == -1 )
67 m_windowId = (int)NewControlId();
68 else
69 m_windowId = id;
70
71 m_windowStyle = style;
72
73 bool hasLabel = (!label.IsNull() && !label.IsEmpty()) ;
74
75 Widget parentWidget = (Widget) parent->GetClientWidget();
76
77 Widget formWidget = XtVaCreateManagedWidget ((char*) (const char*) name,
78 xmFormWidgetClass, parentWidget,
79 XmNmarginHeight, 0,
80 XmNmarginWidth, 0,
81 NULL);
82
83
84 if (hasLabel)
85 {
86 XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
87
88 wxString label1(wxStripMenuCodes(label));
89 XmString text = XmStringCreateSimple ((char*) (const char*) label1);
90 m_labelWidget = (WXWidget) XtVaCreateManagedWidget ((char*) (const char*) label1,
91 xmLabelWidgetClass, formWidget,
92 XmNfontList, fontList,
93 XmNlabelString, text,
94 NULL);
95 XmStringFree (text);
96 }
97
98 Widget frameWidget = XtVaCreateManagedWidget ("frame",
99 xmFrameWidgetClass, formWidget,
100 XmNshadowType, XmSHADOW_IN,
101 //XmNmarginHeight, 0,
102 //XmNmarginWidth, 0,
103 NULL);
104
105 if (hasLabel)
106 XtVaSetValues ((Widget) m_labelWidget,
107 XmNtopAttachment, XmATTACH_FORM,
108 XmNleftAttachment, XmATTACH_FORM,
109 XmNrightAttachment, XmATTACH_FORM,
110 XmNalignment, XmALIGNMENT_BEGINNING,
111 NULL);
112
113 XtVaSetValues (frameWidget,
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);
120
121 m_mainWidget = (WXWidget) frameWidget;
122 m_formWidget = (WXWidget) formWidget;
123
124 SetCanAddEventHandler(TRUE);
125 AttachWidget (parent, (WXWidget) frameWidget, (WXWidget) formWidget, pos.x, pos.y, size.x, size.y);
126 ChangeBackgroundColour();
127
128 return TRUE;
129}
130
131wxStaticBox::~wxStaticBox()
132{
133 DetachWidget(m_formWidget);
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;
143}
144
145void wxStaticBox::SetLabel(const wxString& label)
146{
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,
156 XmNlabelString, text,
157 XmNlabelType, XmSTRING,
158 NULL);
159 XmStringFree (text);
160 }
161}
162
163wxString wxStaticBox::GetLabel() const
164{
165 if (!m_labelWidget)
166 return wxEmptyString;
167
168 XmString text = 0;
169 char *s;
170 XtVaGetValues ((Widget) m_labelWidget,
171 XmNlabelString, &text,
172 NULL);
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 }
187}
188
189void wxStaticBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
190{
191 wxControl::DoSetSize (x, y, width, height, sizeFlags);
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,
200 NULL);
201 if (height > -1)
202 XtVaSetValues ((Widget) m_mainWidget, XmNheight, height - yy,
203 NULL);
204 }
205}
206
207void wxStaticBox::ChangeFont(bool keepOriginalSize)
208{
209 wxWindow::ChangeFont(keepOriginalSize);
210}
211
212void wxStaticBox::ChangeBackgroundColour()
213{
214 wxWindow::ChangeBackgroundColour();
215 if (m_labelWidget)
216 DoChangeBackgroundColour(m_labelWidget, m_backgroundColour);
217}
218
219void wxStaticBox::ChangeForegroundColour()
220{
221 wxWindow::ChangeForegroundColour();
222 if (m_labelWidget)
223 DoChangeForegroundColour(m_labelWidget, m_foregroundColour);
224}
225