]> git.saurik.com Git - wxWidgets.git/blob - src/motif/stattext.cpp
Added some missing copyright lines
[wxWidgets.git] / src / motif / stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: stattext.cpp
3 // Purpose: wxStaticText
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "stattext.h"
14 #endif
15
16 #ifdef __VMS
17 #define XtDisplay XTDISPLAY
18 #endif
19
20 #include "wx/app.h"
21 #include "wx/stattext.h"
22
23 #include <stdio.h>
24
25 #ifdef __VMS__
26 #pragma message disable nosimpint
27 #endif
28 #include <Xm/Frame.h>
29 #include <Xm/Label.h>
30 #include <Xm/LabelG.h>
31 #include <Xm/PushBG.h>
32 #ifdef __VMS__
33 #pragma message enable nosimpint
34 #endif
35
36 #include "wx/motif/private.h"
37
38 IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
39
40 bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
41 const wxString& label,
42 const wxPoint& pos,
43 const wxSize& size,
44 long style,
45 const wxString& name)
46 {
47 SetName(name);
48 if (parent) parent->AddChild(this);
49
50 m_backgroundColour = parent->GetBackgroundColour();
51 m_foregroundColour = parent->GetForegroundColour();
52
53 if ( id == -1 )
54 m_windowId = (int)NewControlId();
55 else
56 m_windowId = id;
57
58 m_windowStyle = style;
59 m_font = parent->GetFont();
60
61 Widget parentWidget = (Widget) parent->GetClientWidget();
62
63 Widget borderWidget = NULL;
64
65 // Decorate the label widget if a border style is specified.
66 if (style & wxSIMPLE_BORDER)
67 {
68 borderWidget = XtVaCreateManagedWidget
69 (
70 "simpleBorder",
71 xmFrameWidgetClass, parentWidget,
72 XmNshadowType, XmSHADOW_ETCHED_IN,
73 XmNshadowThickness, 1,
74 NULL
75 );
76 } else if (style & wxSUNKEN_BORDER)
77 {
78 borderWidget = XtVaCreateManagedWidget
79 (
80 "sunkenBorder",
81 xmFrameWidgetClass, parentWidget,
82 XmNshadowType, XmSHADOW_IN,
83 NULL
84 );
85 } else if (style & wxRAISED_BORDER)
86 {
87 borderWidget = XtVaCreateManagedWidget
88 (
89 "raisedBorder",
90 xmFrameWidgetClass, parentWidget,
91 XmNshadowType, XmSHADOW_OUT,
92 NULL
93 );
94 }
95
96 #if 0 // gcc 2.95 doesn't like this apparently
97 // Use XmStringCreateLtoR(), since XmStringCreateSimple
98 // doesn't obey separators.
99 // XmString text = XmStringCreateSimple (label1);
100 wxXmString text( label1 );
101 #endif // 0
102
103 wxXmString text( label );
104
105 WXFontType fontType = m_font.GetFontType(XtDisplay(parentWidget));
106
107 m_labelWidget = XtVaCreateManagedWidget (wxConstCast(name.c_str(), char),
108 xmLabelWidgetClass,
109 borderWidget ? borderWidget : parentWidget,
110 wxFont::GetFontTag(), fontType,
111 XmNlabelString, text(),
112 XmNalignment,
113 ((style & wxALIGN_RIGHT) ? XmALIGNMENT_END :
114 ((style & wxALIGN_CENTRE) ? XmALIGNMENT_CENTER :
115 XmALIGNMENT_BEGINNING)),
116 NULL);
117
118 m_mainWidget = borderWidget ? borderWidget : m_labelWidget;
119
120 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
121
122 ChangeBackgroundColour ();
123
124 return TRUE;
125 }
126
127 void wxStaticText::ChangeFont(bool keepOriginalSize)
128 {
129 wxWindow::ChangeFont(keepOriginalSize);
130 }
131
132 void wxStaticText::ChangeBackgroundColour()
133 {
134 wxWindow::ChangeBackgroundColour();
135 }
136
137 void wxStaticText::ChangeForegroundColour()
138 {
139 wxWindow::ChangeForegroundColour();
140 }
141
142 void wxStaticText::SetLabel(const wxString& label)
143 {
144 wxString buf(wxStripMenuCodes(label));
145 wxXmString label_str(buf);
146
147 // This variable means we don't need so many casts later.
148 Widget widget = (Widget) m_labelWidget;
149
150 if (GetWindowStyle() & wxST_NO_AUTORESIZE)
151 {
152 XtUnmanageChild(widget);
153 Dimension width, height;
154 XtVaGetValues(widget, XmNwidth, &width, XmNheight, &height, NULL);
155
156 XtVaSetValues(widget,
157 XmNlabelString, label_str(),
158 XmNlabelType, XmSTRING,
159 NULL);
160 XtVaSetValues(widget,
161 XmNwidth, width,
162 XmNheight, height,
163 NULL);
164 XtManageChild(widget);
165 }
166 else
167 {
168 XtVaSetValues(widget,
169 XmNlabelString, label_str(),
170 XmNlabelType, XmSTRING,
171 NULL);
172 }
173 }
174