]> git.saurik.com Git - wxWidgets.git/blame - src/motif/statbox.cpp
added wxUSE_TOOLBAR_SIMPLE setting, enabled wxLongLong in configure by default
[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
16#include "wx/statbox.h"
47bc1060
JS
17#include "wx/utils.h"
18
338dd992
JJ
19#ifdef __VMS__
20#pragma message disable nosimpint
21#endif
47bc1060
JS
22#include <Xm/Frame.h>
23#include <Xm/Form.h>
24#include <Xm/Label.h>
25#include <Xm/LabelG.h>
338dd992
JJ
26#ifdef __VMS__
27#pragma message enable nosimpint
28#endif
47bc1060 29
3096bd2f 30#include "wx/motif/private.h"
4bb6408c
JS
31
32#if !USE_SHARED_LIBRARY
33IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
34
35BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
31528cd3 36//EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
4bb6408c
JS
37END_EVENT_TABLE()
38
39#endif
40
41/*
42 * Static box
43 */
31528cd3 44
47bc1060
JS
45wxStaticBox::wxStaticBox()
46{
47 m_formWidget = (WXWidget) 0;
48 m_labelWidget = (WXWidget) 0;
49}
50
4bb6408c
JS
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{
47bc1060
JS
58 m_formWidget = (WXWidget) 0;
59 m_labelWidget = (WXWidget) 0;
0d57be45
JS
60 m_backgroundColour = parent->GetBackgroundColour();
61 m_foregroundColour = parent->GetForegroundColour();
da175b2c 62 m_font = parent->GetFont();
47bc1060 63
4bb6408c
JS
64 SetName(name);
65
66 if (parent) parent->AddChild(this);
67
68 if ( id == -1 )
31528cd3 69 m_windowId = (int)NewControlId();
4bb6408c 70 else
31528cd3 71 m_windowId = id;
4bb6408c
JS
72
73 m_windowStyle = style;
74
47bc1060
JS
75 bool hasLabel = (!label.IsNull() && !label.IsEmpty()) ;
76
77 Widget parentWidget = (Widget) parent->GetClientWidget();
78
79 Widget formWidget = XtVaCreateManagedWidget ((char*) (const char*) name,
31528cd3
VZ
80 xmFormWidgetClass, parentWidget,
81 XmNmarginHeight, 0,
82 XmNmarginWidth, 0,
83 NULL);
47bc1060
JS
84
85
86 if (hasLabel)
87 {
da175b2c 88 XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
ea57084d 89
47bc1060
JS
90 wxString label1(wxStripMenuCodes(label));
91 XmString text = XmStringCreateSimple ((char*) (const char*) label1);
92 m_labelWidget = (WXWidget) XtVaCreateManagedWidget ((char*) (const char*) label1,
31528cd3
VZ
93 xmLabelWidgetClass, formWidget,
94 XmNfontList, fontList,
95 XmNlabelString, text,
96 NULL);
47bc1060
JS
97 XmStringFree (text);
98 }
99
100 Widget frameWidget = XtVaCreateManagedWidget ("frame",
31528cd3
VZ
101 xmFrameWidgetClass, formWidget,
102 XmNshadowType, XmSHADOW_IN,
103 //XmNmarginHeight, 0,
104 //XmNmarginWidth, 0,
105 NULL);
47bc1060
JS
106
107 if (hasLabel)
108 XtVaSetValues ((Widget) m_labelWidget,
31528cd3
VZ
109 XmNtopAttachment, XmATTACH_FORM,
110 XmNleftAttachment, XmATTACH_FORM,
111 XmNrightAttachment, XmATTACH_FORM,
112 XmNalignment, XmALIGNMENT_BEGINNING,
113 NULL);
47bc1060
JS
114
115 XtVaSetValues (frameWidget,
31528cd3
VZ
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);
47bc1060 122
94b49b93
JS
123 m_mainWidget = (WXWidget) frameWidget;
124 m_formWidget = (WXWidget) formWidget;
47bc1060
JS
125
126 SetCanAddEventHandler(TRUE);
94b49b93 127 AttachWidget (parent, (WXWidget) frameWidget, (WXWidget) formWidget, pos.x, pos.y, size.x, size.y);
0d57be45 128 ChangeBackgroundColour();
47bc1060
JS
129
130 return TRUE;
4bb6408c
JS
131}
132
b412f9be
JS
133wxStaticBox::~wxStaticBox()
134{
135 DetachWidget(m_formWidget);
15d5ab67
JS
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;
b412f9be
JS
145}
146
4bb6408c
JS
147void wxStaticBox::SetLabel(const wxString& label)
148{
47bc1060
JS
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,
31528cd3
VZ
158 XmNlabelString, text,
159 XmNlabelType, XmSTRING,
160 NULL);
47bc1060
JS
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,
31528cd3
VZ
173 XmNlabelString, &text,
174 NULL);
47bc1060
JS
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 }
4bb6408c
JS
189}
190
bfc6fde4 191void wxStaticBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
4bb6408c 192{
bfc6fde4 193 wxControl::DoSetSize (x, y, width, height, sizeFlags);
47bc1060
JS
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,
31528cd3 202 NULL);
47bc1060
JS
203 if (height > -1)
204 XtVaSetValues ((Widget) m_mainWidget, XmNheight, height - yy,
31528cd3 205 NULL);
47bc1060 206 }
4bb6408c
JS
207}
208
4b5f3fe6 209void wxStaticBox::ChangeFont(bool keepOriginalSize)
0d57be45 210{
4b5f3fe6 211 wxWindow::ChangeFont(keepOriginalSize);
0d57be45
JS
212}
213
214void wxStaticBox::ChangeBackgroundColour()
215{
321db4b6 216 wxWindow::ChangeBackgroundColour();
b412f9be
JS
217 if (m_labelWidget)
218 DoChangeBackgroundColour(m_labelWidget, m_backgroundColour);
0d57be45
JS
219}
220
221void wxStaticBox::ChangeForegroundColour()
222{
321db4b6 223 wxWindow::ChangeForegroundColour();
b412f9be
JS
224 if (m_labelWidget)
225 DoChangeForegroundColour(m_labelWidget, m_foregroundColour);
0d57be45
JS
226}
227