]> git.saurik.com Git - wxWidgets.git/blame - src/motif/stattext.cpp
compilation fix
[wxWidgets.git] / src / motif / stattext.cpp
CommitLineData
4bb6408c
JS
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
31528cd3 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "stattext.h"
14#endif
15
bcd055ae
JJ
16#ifdef __VMS
17#define XtDisplay XTDISPLAY
18#endif
19
4bb6408c
JS
20#include "wx/app.h"
21#include "wx/stattext.h"
22
23#include <stdio.h>
24
338dd992
JJ
25#ifdef __VMS__
26#pragma message disable nosimpint
27#endif
7227cefd 28#include <Xm/Frame.h>
02e8b2f9
JS
29#include <Xm/Label.h>
30#include <Xm/LabelG.h>
31#include <Xm/PushBG.h>
338dd992
JJ
32#ifdef __VMS__
33#pragma message enable nosimpint
34#endif
02e8b2f9 35
fe5de1ea
JS
36#include "wx/motif/private.h"
37
4bb6408c 38IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
4bb6408c
JS
39
40bool 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{
a4294b78
JS
47 SetName(name);
48 if (parent) parent->AddChild(this);
4bb6408c 49
0d57be45
JS
50 m_backgroundColour = parent->GetBackgroundColour();
51 m_foregroundColour = parent->GetForegroundColour();
4bb6408c 52
a4294b78 53 if ( id == -1 )
31528cd3 54 m_windowId = (int)NewControlId();
a4294b78 55 else
31528cd3 56 m_windowId = id;
4bb6408c 57
a4294b78 58 m_windowStyle = style;
da175b2c 59 m_font = parent->GetFont();
4bb6408c 60
7a4b8f27 61#if 0 // gcc 2.95 doesn't like this apparently
a4294b78 62 char* label1 = (label.IsNull() ? "" : (char*) (const char*) label);
7a4b8f27
MB
63#endif
64
a4294b78 65 Widget parentWidget = (Widget) parent->GetClientWidget();
02e8b2f9 66
7227cefd
JS
67 Widget borderWidget = NULL;
68
69 // Decorate the label widget if a border style is specified.
70 if (style & wxSIMPLE_BORDER)
71 {
72 borderWidget = XtVaCreateManagedWidget
73 (
74 "simpleBorder",
75 xmFrameWidgetClass, parentWidget,
76 XmNshadowType, XmSHADOW_ETCHED_IN,
77 XmNshadowThickness, 1,
78 NULL
79 );
80 } else if (style & wxSUNKEN_BORDER)
81 {
82 borderWidget = XtVaCreateManagedWidget
83 (
84 "sunkenBorder",
85 xmFrameWidgetClass, parentWidget,
86 XmNshadowType, XmSHADOW_IN,
87 NULL
88 );
89 } else if (style & wxRAISED_BORDER)
90 {
91 borderWidget = XtVaCreateManagedWidget
92 (
93 "raisedBorder",
94 xmFrameWidgetClass, parentWidget,
95 XmNshadowType, XmSHADOW_OUT,
96 NULL
97 );
98 }
99
7a4b8f27 100#if 0 // gcc 2.95 doesn't like this apparently
8cbd2bde
JS
101 // Use XmStringCreateLtoR(), since XmStringCreateSimple
102 // doesn't obey separators.
103// XmString text = XmStringCreateSimple (label1);
104 XmString text = XmStringCreateLtoR (label1, XmSTRING_DEFAULT_CHARSET);
7a4b8f27
MB
105#endif // 0
106
107 XmString text = XmStringCreateLtoR ((char *)(const char*)label, XmSTRING_DEFAULT_CHARSET);
108
da175b2c 109 XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
ea57084d 110
6886fcfa 111 m_labelWidget = XtVaCreateManagedWidget ((char*) (const char*) name,
02e8b2f9 112 xmLabelWidgetClass,
7227cefd 113 borderWidget ? borderWidget : parentWidget,
ea57084d 114 XmNfontList, fontList,
02e8b2f9
JS
115 XmNlabelString, text,
116 XmNalignment,
117 ((style & wxALIGN_RIGHT) ? XmALIGNMENT_END :
118 ((style & wxALIGN_CENTRE) ? XmALIGNMENT_CENTER :
119 XmALIGNMENT_BEGINNING)),
120 NULL);
121
a4294b78 122 XmStringFree (text);
02e8b2f9 123
6886fcfa 124 m_mainWidget = borderWidget ? borderWidget : m_labelWidget;
7227cefd 125
a4294b78
JS
126 SetCanAddEventHandler(TRUE);
127 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
02e8b2f9 128
0d57be45 129 ChangeBackgroundColour ();
4bb6408c 130
a4294b78 131 return TRUE;
4bb6408c
JS
132}
133
4b5f3fe6 134void wxStaticText::ChangeFont(bool keepOriginalSize)
0d57be45 135{
4b5f3fe6 136 wxWindow::ChangeFont(keepOriginalSize);
0d57be45
JS
137}
138
139void wxStaticText::ChangeBackgroundColour()
140{
321db4b6 141 wxWindow::ChangeBackgroundColour();
0d57be45
JS
142}
143
144void wxStaticText::ChangeForegroundColour()
145{
321db4b6 146 wxWindow::ChangeForegroundColour();
0d57be45
JS
147}
148
fe5de1ea
JS
149void wxStaticText::SetLabel(const wxString& label)
150{
151 wxString buf(wxStripMenuCodes(label));
152 wxXmString label_str(buf);
153
154 // This variable means we don't need so many casts later.
155 Widget widget = (Widget) m_labelWidget;
156
157 if (GetWindowStyle() & wxST_NO_AUTORESIZE)
158 {
159 XtUnmanageChild(widget);
160 Dimension width, height;
161 XtVaGetValues(widget, XmNwidth, &width, XmNheight, &height, NULL);
162
163 XtVaSetValues(widget,
164 XmNlabelString, label_str(),
165 XmNlabelType, XmSTRING,
166 NULL);
167 XtVaSetValues(widget,
168 XmNwidth, width,
169 XmNheight, height,
170 NULL);
171 XtManageChild(widget);
172 }
173 else
174 {
175 XtVaSetValues(widget,
176 XmNlabelString, label_str(),
177 XmNlabelType, XmSTRING,
178 NULL);
179 }
180}
181