added support for ellipsization and markup in wxStaticText (modified patch 1629946)
[wxWidgets.git] / src / motif / stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/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 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __VMS
16 #define XtDisplay XTDISPLAY
17 #endif
18
19 #if wxUSE_STATTEXT
20
21 #include "wx/stattext.h"
22
23 #ifdef __VMS__
24 #pragma message disable nosimpint
25 #endif
26 #include <Xm/Label.h>
27 #ifdef __VMS__
28 #pragma message enable nosimpint
29 #endif
30
31 #include "wx/motif/private.h"
32
33 IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
34
35 bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
36 const wxString& label,
37 const wxPoint& pos,
38 const wxSize& size,
39 long style,
40 const wxString& name)
41 {
42 if( !CreateControl( parent, id, pos, size, style,
43 wxDefaultValidator, name ) )
44 return false;
45
46 Widget parentWidget = (Widget) parent->GetClientWidget();
47
48 Widget borderWidget =
49 (Widget) wxCreateBorderWidget( (WXWidget)parentWidget, style );
50
51 m_labelWidget =
52 XtVaCreateManagedWidget (wxConstCast(name.mb_str(), char),
53 xmLabelWidgetClass,
54 borderWidget ? borderWidget : parentWidget,
55 wxFont::GetFontTag(), m_font.GetFontTypeC(XtDisplay(parentWidget)),
56 XmNalignment, ((style & wxALIGN_RIGHT) ? XmALIGNMENT_END :
57 ((style & wxALIGN_CENTRE) ? XmALIGNMENT_CENTER :
58 XmALIGNMENT_BEGINNING)),
59 XmNrecomputeSize, ((style & wxST_NO_AUTORESIZE) ? TRUE : FALSE),
60 NULL);
61
62 m_mainWidget = borderWidget ? borderWidget : m_labelWidget;
63
64 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
65 pos.x, pos.y, size.x, size.y);
66
67 ChangeBackgroundColour ();
68
69 SetLabel(label);
70
71 return true;
72 }
73
74 void wxStaticText::SetLabel(const wxString& label)
75 {
76 m_labelOrig = label; // save original label
77
78 // Motif does not support neither ellipsize nor markup in static text:
79 DoSetLabel(GetEllipsizedLabelWithoutMarkup());
80 }
81
82 // for wxST_ELLIPSIZE_* support:
83
84 wxString wxStaticText::DoGetLabel() const
85 {
86 XmString label = NULL;
87 XtVaGetValues((Widget)m_labelWidget, XmNlabelString, &label, NULL);
88
89 return wxXmStringToString(label);
90 }
91
92 void wxStaticText::DoSetLabel(const wxString& str)
93 {
94 // build our own cleaned label
95 wxXmString label_str(RemoveMnemonics(str));
96
97 // This variable means we don't need so many casts later.
98 Widget widget = (Widget) m_labelWidget;
99
100 XtVaSetValues(widget,
101 XmNlabelString, label_str(),
102 XmNlabelType, XmSTRING,
103 NULL);
104 }
105
106 /*
107 FIXME: UpdateLabel() should be called on size events to allow correct
108 dynamic ellipsizing of the label
109 */
110
111 #endif // wxUSE_STATTEXT