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