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