]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: 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 | #ifdef __VMS | |
16 | #define XtDisplay XTDISPLAY | |
17 | #endif | |
18 | ||
19 | #include "wx/defs.h" | |
20 | ||
21 | #if wxUSE_STATTEXT | |
22 | ||
23 | #include "wx/stattext.h" | |
24 | ||
25 | #ifdef __VMS__ | |
26 | #pragma message disable nosimpint | |
27 | #endif | |
28 | #include <Xm/Label.h> | |
29 | #ifdef __VMS__ | |
30 | #pragma message enable nosimpint | |
31 | #endif | |
32 | ||
33 | #include "wx/motif/private.h" | |
34 | ||
35 | IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) | |
36 | ||
37 | bool wxStaticText::Create(wxWindow *parent, wxWindowID id, | |
38 | const wxString& label, | |
39 | const wxPoint& pos, | |
40 | const wxSize& size, | |
41 | long style, | |
42 | const wxString& name) | |
43 | { | |
44 | if( !CreateControl( parent, id, pos, size, style, | |
45 | wxDefaultValidator, name ) ) | |
46 | return false; | |
47 | ||
48 | Widget parentWidget = (Widget) parent->GetClientWidget(); | |
49 | ||
50 | Widget borderWidget = | |
51 | (Widget) wxCreateBorderWidget( (WXWidget)parentWidget, style ); | |
52 | wxXmString text( wxStripMenuCodes( label ) ); | |
53 | ||
54 | m_labelWidget = | |
55 | XtVaCreateManagedWidget (wxConstCast(name.c_str(), char), | |
56 | xmLabelWidgetClass, | |
57 | borderWidget ? borderWidget : parentWidget, | |
58 | wxFont::GetFontTag(), m_font.GetFontTypeC(XtDisplay(parentWidget)), | |
59 | XmNlabelString, text(), | |
60 | XmNalignment, ((style & wxALIGN_RIGHT) ? XmALIGNMENT_END : | |
61 | ((style & wxALIGN_CENTRE) ? XmALIGNMENT_CENTER : | |
62 | XmALIGNMENT_BEGINNING)), | |
63 | NULL); | |
64 | ||
65 | m_mainWidget = borderWidget ? borderWidget : m_labelWidget; | |
66 | ||
67 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, | |
68 | pos.x, pos.y, size.x, size.y); | |
69 | ||
70 | ChangeBackgroundColour (); | |
71 | ||
72 | return true; | |
73 | } | |
74 | ||
75 | void wxStaticText::SetLabel(const wxString& label) | |
76 | { | |
77 | wxXmString label_str(wxStripMenuCodes(label)); | |
78 | ||
79 | // This variable means we don't need so many casts later. | |
80 | Widget widget = (Widget) m_labelWidget; | |
81 | ||
82 | if (GetWindowStyle() & wxST_NO_AUTORESIZE) | |
83 | { | |
84 | XtUnmanageChild(widget); | |
85 | Dimension width, height; | |
86 | XtVaGetValues(widget, XmNwidth, &width, XmNheight, &height, NULL); | |
87 | ||
88 | XtVaSetValues(widget, | |
89 | XmNlabelString, label_str(), | |
90 | XmNlabelType, XmSTRING, | |
91 | NULL); | |
92 | XtVaSetValues(widget, | |
93 | XmNwidth, width, | |
94 | XmNheight, height, | |
95 | NULL); | |
96 | XtManageChild(widget); | |
97 | } | |
98 | else | |
99 | { | |
100 | XtVaSetValues(widget, | |
101 | XmNlabelString, label_str(), | |
102 | XmNlabelType, XmSTRING, | |
103 | NULL); | |
104 | } | |
105 | } | |
106 | ||
107 | #endif // wxUSE_STATTEXT |