]> git.saurik.com Git - wxWidgets.git/blame - src/motif/stattext.cpp
Add missing WXK constants for the control keys
[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
4bb6408c
JS
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{
9a595736
MB
36 if( !CreateControl( parent, id, pos, size, style,
37 wxDefaultValidator, name ) )
38 return false;
105fbe1f
MB
39 m_labelWidget = (WXWidget) 0;
40 PreCreation();
4bb6408c 41
a4294b78 42 Widget parentWidget = (Widget) parent->GetClientWidget();
02e8b2f9 43
9a595736
MB
44 Widget borderWidget =
45 (Widget) wxCreateBorderWidget( (WXWidget)parentWidget, style );
ea57084d 46
73608949 47 m_labelWidget =
6991087b 48 XtVaCreateManagedWidget (name.mb_str(),
73608949
MB
49 xmLabelWidgetClass,
50 borderWidget ? borderWidget : parentWidget,
51 wxFont::GetFontTag(), m_font.GetFontTypeC(XtDisplay(parentWidget)),
73608949
MB
52 XmNalignment, ((style & wxALIGN_RIGHT) ? XmALIGNMENT_END :
53 ((style & wxALIGN_CENTRE) ? XmALIGNMENT_CENTER :
54 XmALIGNMENT_BEGINNING)),
3fe5be6e 55 XmNrecomputeSize, ((style & wxST_NO_AUTORESIZE) ? TRUE : FALSE),
73608949 56 NULL);
02e8b2f9 57
6886fcfa 58 m_mainWidget = borderWidget ? borderWidget : m_labelWidget;
7227cefd 59
105fbe1f 60 SetLabel(label);
02e8b2f9 61
105fbe1f
MB
62 wxSize best = GetBestSize();
63 if( size.x != -1 ) best.x = size.x;
64 if( size.y != -1 ) best.y = size.y;
4bb6408c 65
105fbe1f
MB
66 PostCreation();
67 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
68 pos.x, pos.y, best.x, best.y);
39bc0347 69
96be256b 70 return true;
4bb6408c
JS
71}
72
fe5de1ea
JS
73void wxStaticText::SetLabel(const wxString& label)
74{
39bc0347
VZ
75 m_labelOrig = label; // save original label
76
3da9cffc
VZ
77 // Motif does not support ellipsized labels natively
78 DoSetLabel(GetEllipsizedLabel());
39bc0347
VZ
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));
fe5de1ea
JS
95
96 // This variable means we don't need so many casts later.
97 Widget widget = (Widget) m_labelWidget;
98
fe5de1ea
JS
99 XtVaSetValues(widget,
100 XmNlabelString, label_str(),
101 XmNlabelType, XmSTRING,
102 NULL);
fe5de1ea 103}
47073128 104
39bc0347
VZ
105/*
106 FIXME: UpdateLabel() should be called on size events to allow correct
107 dynamic ellipsizing of the label
108*/
109
105fbe1f
MB
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
47073128 118#endif // wxUSE_STATTEXT