]> git.saurik.com Git - wxWidgets.git/blame - src/motif/stattext.cpp
Try to display '...' text on editor buttons more consistently on wxGTK. This is done...
[wxWidgets.git] / src / motif / stattext.cpp
CommitLineData
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
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
1248b41f
MB
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
47073128
WS
15#if wxUSE_STATTEXT
16
4bb6408c
JS
17#include "wx/stattext.h"
18
338dd992
JJ
19#ifdef __VMS__
20#pragma message disable nosimpint
21#endif
02e8b2f9 22#include <Xm/Label.h>
338dd992
JJ
23#ifdef __VMS__
24#pragma message enable nosimpint
25#endif
02e8b2f9 26
fe5de1ea
JS
27#include "wx/motif/private.h"
28
e933b5bc 29IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
4bb6408c
JS
30
31bool 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{
9a595736
MB
38 if( !CreateControl( parent, id, pos, size, style,
39 wxDefaultValidator, name ) )
40 return false;
105fbe1f
MB
41 m_labelWidget = (WXWidget) 0;
42 PreCreation();
4bb6408c 43
a4294b78 44 Widget parentWidget = (Widget) parent->GetClientWidget();
02e8b2f9 45
9a595736
MB
46 Widget borderWidget =
47 (Widget) wxCreateBorderWidget( (WXWidget)parentWidget, style );
ea57084d 48
73608949 49 m_labelWidget =
6991087b 50 XtVaCreateManagedWidget (name.mb_str(),
73608949
MB
51 xmLabelWidgetClass,
52 borderWidget ? borderWidget : parentWidget,
53 wxFont::GetFontTag(), m_font.GetFontTypeC(XtDisplay(parentWidget)),
73608949
MB
54 XmNalignment, ((style & wxALIGN_RIGHT) ? XmALIGNMENT_END :
55 ((style & wxALIGN_CENTRE) ? XmALIGNMENT_CENTER :
56 XmALIGNMENT_BEGINNING)),
3fe5be6e 57 XmNrecomputeSize, ((style & wxST_NO_AUTORESIZE) ? TRUE : FALSE),
73608949 58 NULL);
02e8b2f9 59
6886fcfa 60 m_mainWidget = borderWidget ? borderWidget : m_labelWidget;
7227cefd 61
105fbe1f 62 SetLabel(label);
02e8b2f9 63
105fbe1f
MB
64 wxSize best = GetBestSize();
65 if( size.x != -1 ) best.x = size.x;
66 if( size.y != -1 ) best.y = size.y;
4bb6408c 67
105fbe1f
MB
68 PostCreation();
69 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
70 pos.x, pos.y, best.x, best.y);
39bc0347 71
96be256b 72 return true;
4bb6408c
JS
73}
74
fe5de1ea
JS
75void wxStaticText::SetLabel(const wxString& label)
76{
39bc0347
VZ
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
85wxString wxStaticText::DoGetLabel() const
86{
87 XmString label = NULL;
88 XtVaGetValues((Widget)m_labelWidget, XmNlabelString, &label, NULL);
89
90 return wxXmStringToString(label);
91}
92
93void wxStaticText::DoSetLabel(const wxString& str)
94{
95 // build our own cleaned label
96 wxXmString label_str(RemoveMnemonics(str));
fe5de1ea
JS
97
98 // This variable means we don't need so many casts later.
99 Widget widget = (Widget) m_labelWidget;
100
fe5de1ea
JS
101 XtVaSetValues(widget,
102 XmNlabelString, label_str(),
103 XmNlabelType, XmSTRING,
104 NULL);
fe5de1ea 105}
47073128 106
39bc0347
VZ
107/*
108 FIXME: UpdateLabel() should be called on size events to allow correct
109 dynamic ellipsizing of the label
110*/
111
105fbe1f
MB
112wxSize wxStaticText::DoGetBestSize() const
113{
114 int w, h;
115 GetTextExtent(GetLabelText(), &w, &h, NULL, NULL, NULL);
116
117 return wxSize(w, h);
118}
119
47073128 120#endif // wxUSE_STATTEXT