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