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