]>
Commit | Line | Data |
---|---|---|
4bb6408c | 1 | ///////////////////////////////////////////////////////////////////////////// |
7520f3da | 2 | // Name: src/motif/stattext.cpp |
4bb6408c JS |
3 | // Purpose: wxStaticText |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
4bb6408c | 7 | // Copyright: (c) Julian Smart |
65571936 | 8 | // Licence: wxWindows licence |
4bb6408c JS |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
1248b41f MB |
11 | // For compilers that support precompilation, includes "wx.h". |
12 | #include "wx/wxprec.h" | |
13 | ||
47073128 WS |
14 | #if wxUSE_STATTEXT |
15 | ||
4bb6408c JS |
16 | #include "wx/stattext.h" |
17 | ||
338dd992 JJ |
18 | #ifdef __VMS__ |
19 | #pragma message disable nosimpint | |
20 | #endif | |
02e8b2f9 | 21 | #include <Xm/Label.h> |
338dd992 JJ |
22 | #ifdef __VMS__ |
23 | #pragma message enable nosimpint | |
24 | #endif | |
02e8b2f9 | 25 | |
fe5de1ea JS |
26 | #include "wx/motif/private.h" |
27 | ||
4bb6408c JS |
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 | { | |
9a595736 MB |
35 | if( !CreateControl( parent, id, pos, size, style, |
36 | wxDefaultValidator, name ) ) | |
37 | return false; | |
105fbe1f MB |
38 | m_labelWidget = (WXWidget) 0; |
39 | PreCreation(); | |
4bb6408c | 40 | |
a4294b78 | 41 | Widget parentWidget = (Widget) parent->GetClientWidget(); |
02e8b2f9 | 42 | |
9a595736 MB |
43 | Widget borderWidget = |
44 | (Widget) wxCreateBorderWidget( (WXWidget)parentWidget, style ); | |
ea57084d | 45 | |
73608949 | 46 | m_labelWidget = |
6991087b | 47 | XtVaCreateManagedWidget (name.mb_str(), |
73608949 MB |
48 | xmLabelWidgetClass, |
49 | borderWidget ? borderWidget : parentWidget, | |
50 | wxFont::GetFontTag(), m_font.GetFontTypeC(XtDisplay(parentWidget)), | |
73608949 MB |
51 | XmNalignment, ((style & wxALIGN_RIGHT) ? XmALIGNMENT_END : |
52 | ((style & wxALIGN_CENTRE) ? XmALIGNMENT_CENTER : | |
53 | XmALIGNMENT_BEGINNING)), | |
3fe5be6e | 54 | XmNrecomputeSize, ((style & wxST_NO_AUTORESIZE) ? TRUE : FALSE), |
73608949 | 55 | NULL); |
02e8b2f9 | 56 | |
6886fcfa | 57 | m_mainWidget = borderWidget ? borderWidget : m_labelWidget; |
7227cefd | 58 | |
105fbe1f | 59 | SetLabel(label); |
02e8b2f9 | 60 | |
105fbe1f MB |
61 | wxSize best = GetBestSize(); |
62 | if( size.x != -1 ) best.x = size.x; | |
63 | if( size.y != -1 ) best.y = size.y; | |
4bb6408c | 64 | |
105fbe1f MB |
65 | PostCreation(); |
66 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, | |
67 | pos.x, pos.y, best.x, best.y); | |
39bc0347 | 68 | |
96be256b | 69 | return true; |
4bb6408c JS |
70 | } |
71 | ||
fe5de1ea JS |
72 | void wxStaticText::SetLabel(const wxString& label) |
73 | { | |
39bc0347 VZ |
74 | m_labelOrig = label; // save original label |
75 | ||
3da9cffc VZ |
76 | // Motif does not support ellipsized labels natively |
77 | DoSetLabel(GetEllipsizedLabel()); | |
39bc0347 VZ |
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)); | |
fe5de1ea JS |
94 | |
95 | // This variable means we don't need so many casts later. | |
96 | Widget widget = (Widget) m_labelWidget; | |
97 | ||
fe5de1ea JS |
98 | XtVaSetValues(widget, |
99 | XmNlabelString, label_str(), | |
100 | XmNlabelType, XmSTRING, | |
101 | NULL); | |
fe5de1ea | 102 | } |
47073128 | 103 | |
39bc0347 VZ |
104 | /* |
105 | FIXME: UpdateLabel() should be called on size events to allow correct | |
106 | dynamic ellipsizing of the label | |
107 | */ | |
108 | ||
105fbe1f MB |
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 | ||
47073128 | 117 | #endif // wxUSE_STATTEXT |