]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStaticText
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "stattext.h"
17 #define XtDisplay XTDISPLAY
21 #include "wx/stattext.h"
26 #pragma message disable nosimpint
30 #include <Xm/LabelG.h>
31 #include <Xm/PushBG.h>
33 #pragma message enable nosimpint
36 #include "wx/motif/private.h"
38 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
40 bool wxStaticText::Create(wxWindow
*parent
, wxWindowID id
,
41 const wxString
& label
,
48 if (parent
) parent
->AddChild(this);
50 m_backgroundColour
= parent
->GetBackgroundColour();
51 m_foregroundColour
= parent
->GetForegroundColour();
54 m_windowId
= (int)NewControlId();
58 m_windowStyle
= style
;
59 m_font
= parent
->GetFont();
61 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
63 Widget borderWidget
= NULL
;
65 // Decorate the label widget if a border style is specified.
66 if (style
& wxSIMPLE_BORDER
)
68 borderWidget
= XtVaCreateManagedWidget
71 xmFrameWidgetClass
, parentWidget
,
72 XmNshadowType
, XmSHADOW_ETCHED_IN
,
73 XmNshadowThickness
, 1,
76 } else if (style
& wxSUNKEN_BORDER
)
78 borderWidget
= XtVaCreateManagedWidget
81 xmFrameWidgetClass
, parentWidget
,
82 XmNshadowType
, XmSHADOW_IN
,
85 } else if (style
& wxRAISED_BORDER
)
87 borderWidget
= XtVaCreateManagedWidget
90 xmFrameWidgetClass
, parentWidget
,
91 XmNshadowType
, XmSHADOW_OUT
,
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
);
103 wxXmString
text( label
);
105 WXFontType fontType
= m_font
.GetFontType(XtDisplay(parentWidget
));
107 m_labelWidget
= XtVaCreateManagedWidget (wxConstCast(name
.c_str(), char),
109 borderWidget
? borderWidget
: parentWidget
,
110 wxFont::GetFontTag(), fontType
,
111 XmNlabelString
, text(),
113 ((style
& wxALIGN_RIGHT
) ? XmALIGNMENT_END
:
114 ((style
& wxALIGN_CENTRE
) ? XmALIGNMENT_CENTER
:
115 XmALIGNMENT_BEGINNING
)),
118 m_mainWidget
= borderWidget
? borderWidget
: m_labelWidget
;
120 SetCanAddEventHandler(TRUE
);
121 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
123 ChangeBackgroundColour ();
128 void wxStaticText::ChangeFont(bool keepOriginalSize
)
130 wxWindow::ChangeFont(keepOriginalSize
);
133 void wxStaticText::ChangeBackgroundColour()
135 wxWindow::ChangeBackgroundColour();
138 void wxStaticText::ChangeForegroundColour()
140 wxWindow::ChangeForegroundColour();
143 void wxStaticText::SetLabel(const wxString
& label
)
145 wxString
buf(wxStripMenuCodes(label
));
146 wxXmString
label_str(buf
);
148 // This variable means we don't need so many casts later.
149 Widget widget
= (Widget
) m_labelWidget
;
151 if (GetWindowStyle() & wxST_NO_AUTORESIZE
)
153 XtUnmanageChild(widget
);
154 Dimension width
, height
;
155 XtVaGetValues(widget
, XmNwidth
, &width
, XmNheight
, &height
, NULL
);
157 XtVaSetValues(widget
,
158 XmNlabelString
, label_str(),
159 XmNlabelType
, XmSTRING
,
161 XtVaSetValues(widget
,
165 XtManageChild(widget
);
169 XtVaSetValues(widget
,
170 XmNlabelString
, label_str(),
171 XmNlabelType
, XmSTRING
,