]> git.saurik.com Git - wxWidgets.git/blob - src/motif/statbox.cpp
fixed typo in library name
[wxWidgets.git] / src / motif / statbox.cpp
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 #ifdef __VMS
17 #define XtDisplay XTDISPLAY
18 #endif
19
20 #include "wx/defs.h"
21
22 #include "wx/statbox.h"
23 #include "wx/utils.h"
24
25 #ifdef __VMS__
26 #pragma message disable nosimpint
27 #endif
28 #include <Xm/Frame.h>
29 #include <Xm/Form.h>
30 #include <Xm/Label.h>
31 #include <Xm/LabelG.h>
32 #ifdef __VMS__
33 #pragma message enable nosimpint
34 #endif
35
36 #include "wx/motif/private.h"
37
38 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
39
40 BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
41 //EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
42 END_EVENT_TABLE()
43
44
45 /*
46 * Static box
47 */
48
49 wxStaticBox::wxStaticBox()
50 {
51 m_labelWidget = (WXWidget) 0;
52 }
53
54 bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
55 const wxString& label,
56 const wxPoint& pos,
57 const wxSize& size,
58 long style,
59 const wxString& name)
60 {
61 m_backgroundColour = parent->GetBackgroundColour();
62 m_foregroundColour = parent->GetForegroundColour();
63 m_font = parent->GetFont();
64
65 SetName(name);
66
67 if (parent) parent->AddChild(this);
68
69 if ( id == -1 )
70 m_windowId = (int)NewControlId();
71 else
72 m_windowId = id;
73
74 m_windowStyle = style;
75
76 Widget parentWidget = (Widget) parent->GetClientWidget();
77
78 m_mainWidget = XtVaCreateManagedWidget ("staticboxframe",
79 xmFrameWidgetClass, parentWidget,
80 XmNshadowType, XmSHADOW_IN,
81 //XmNmarginHeight, 0,
82 //XmNmarginWidth, 0,
83 NULL);
84
85 bool hasLabel = (!label.IsNull() && !label.IsEmpty()) ;
86 if (hasLabel)
87 {
88 XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
89 wxString label1(wxStripMenuCodes(label));
90 wxXmString text(label1);
91 m_labelWidget = (WXWidget) XtVaCreateManagedWidget (label1.c_str(),
92 xmLabelWidgetClass, (Widget)m_mainWidget,
93 XmNfontList, fontList,
94 XmNlabelString, text(),
95 #if (XmVersion > 1200)
96 XmNframeChildType, XmFRAME_TITLE_CHILD,
97 #else
98 XmNchildType, XmFRAME_TITLE_CHILD,
99 #endif
100 NULL);
101 }
102
103 SetCanAddEventHandler(TRUE);
104 AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y);
105 ChangeBackgroundColour();
106
107 return TRUE;
108 }
109
110 wxStaticBox::~wxStaticBox()
111 {
112 DetachWidget(m_mainWidget);
113 XtDestroyWidget((Widget) m_mainWidget);
114
115 m_mainWidget = (WXWidget) 0;
116 m_labelWidget = (WXWidget) 0;
117 }
118
119 void wxStaticBox::SetLabel(const wxString& label)
120 {
121 if (!m_labelWidget)
122 return;
123
124 if (!label.IsNull())
125 {
126 wxString label1(wxStripMenuCodes(label));
127
128 wxXmString text(label1);
129 XtVaSetValues ((Widget) m_labelWidget,
130 XmNlabelString, text(),
131 XmNlabelType, XmSTRING,
132 NULL);
133 }
134 }
135
136 wxString wxStaticBox::GetLabel() const
137 {
138 if (!m_labelWidget)
139 return wxEmptyString;
140
141 XmString text = 0;
142 char *s;
143 XtVaGetValues ((Widget) m_labelWidget,
144 XmNlabelString, &text,
145 NULL);
146
147 if (!text)
148 return wxEmptyString;
149
150 if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
151 {
152 wxString str(s);
153 XtFree (s);
154 return str;
155 }
156 else
157 {
158 return wxEmptyString;
159 }
160 }
161
162 void wxStaticBox::ChangeFont(bool keepOriginalSize)
163 {
164 wxWindow::ChangeFont(keepOriginalSize);
165 }
166
167