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