]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
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 | |
31528cd3 | 9 | // Licence: wxWindows licence |
4bb6408c JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "stattext.h" | |
14 | #endif | |
15 | ||
bcd055ae JJ |
16 | #ifdef __VMS |
17 | #define XtDisplay XTDISPLAY | |
18 | #endif | |
19 | ||
4bb6408c JS |
20 | #include "wx/app.h" |
21 | #include "wx/stattext.h" | |
22 | ||
23 | #include <stdio.h> | |
24 | ||
338dd992 JJ |
25 | #ifdef __VMS__ |
26 | #pragma message disable nosimpint | |
27 | #endif | |
7227cefd | 28 | #include <Xm/Frame.h> |
02e8b2f9 JS |
29 | #include <Xm/Label.h> |
30 | #include <Xm/LabelG.h> | |
31 | #include <Xm/PushBG.h> | |
338dd992 JJ |
32 | #ifdef __VMS__ |
33 | #pragma message enable nosimpint | |
34 | #endif | |
02e8b2f9 | 35 | |
fe5de1ea JS |
36 | #include "wx/motif/private.h" |
37 | ||
4bb6408c | 38 | IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) |
4bb6408c JS |
39 | |
40 | bool wxStaticText::Create(wxWindow *parent, wxWindowID id, | |
41 | const wxString& label, | |
42 | const wxPoint& pos, | |
43 | const wxSize& size, | |
44 | long style, | |
45 | const wxString& name) | |
46 | { | |
a4294b78 JS |
47 | SetName(name); |
48 | if (parent) parent->AddChild(this); | |
4bb6408c | 49 | |
0d57be45 JS |
50 | m_backgroundColour = parent->GetBackgroundColour(); |
51 | m_foregroundColour = parent->GetForegroundColour(); | |
4bb6408c | 52 | |
a4294b78 | 53 | if ( id == -1 ) |
31528cd3 | 54 | m_windowId = (int)NewControlId(); |
a4294b78 | 55 | else |
31528cd3 | 56 | m_windowId = id; |
4bb6408c | 57 | |
a4294b78 | 58 | m_windowStyle = style; |
da175b2c | 59 | m_font = parent->GetFont(); |
4bb6408c | 60 | |
a4294b78 | 61 | Widget parentWidget = (Widget) parent->GetClientWidget(); |
02e8b2f9 | 62 | |
7227cefd JS |
63 | Widget borderWidget = NULL; |
64 | ||
65 | // Decorate the label widget if a border style is specified. | |
66 | if (style & wxSIMPLE_BORDER) | |
67 | { | |
68 | borderWidget = XtVaCreateManagedWidget | |
69 | ( | |
70 | "simpleBorder", | |
71 | xmFrameWidgetClass, parentWidget, | |
72 | XmNshadowType, XmSHADOW_ETCHED_IN, | |
73 | XmNshadowThickness, 1, | |
74 | NULL | |
75 | ); | |
76 | } else if (style & wxSUNKEN_BORDER) | |
77 | { | |
78 | borderWidget = XtVaCreateManagedWidget | |
79 | ( | |
80 | "sunkenBorder", | |
81 | xmFrameWidgetClass, parentWidget, | |
82 | XmNshadowType, XmSHADOW_IN, | |
83 | NULL | |
84 | ); | |
85 | } else if (style & wxRAISED_BORDER) | |
86 | { | |
87 | borderWidget = XtVaCreateManagedWidget | |
88 | ( | |
89 | "raisedBorder", | |
90 | xmFrameWidgetClass, parentWidget, | |
91 | XmNshadowType, XmSHADOW_OUT, | |
92 | NULL | |
93 | ); | |
94 | } | |
95 | ||
7a4b8f27 | 96 | #if 0 // gcc 2.95 doesn't like this apparently |
8cbd2bde JS |
97 | // Use XmStringCreateLtoR(), since XmStringCreateSimple |
98 | // doesn't obey separators. | |
99 | // XmString text = XmStringCreateSimple (label1); | |
da494b40 | 100 | wxXmString text( label1 ); |
7a4b8f27 MB |
101 | #endif // 0 |
102 | ||
da494b40 | 103 | wxXmString text( label ); |
7a4b8f27 | 104 | |
da494b40 | 105 | WXFontType fontType = m_font.GetFontType(XtDisplay(parentWidget)); |
ea57084d | 106 | |
d3a80c92 | 107 | m_labelWidget = XtVaCreateManagedWidget (wxConstCast(name.c_str(), char), |
02e8b2f9 | 108 | xmLabelWidgetClass, |
7227cefd | 109 | borderWidget ? borderWidget : parentWidget, |
da494b40 MB |
110 | wxFont::GetFontTag(), fontType, |
111 | XmNlabelString, text(), | |
02e8b2f9 JS |
112 | XmNalignment, |
113 | ((style & wxALIGN_RIGHT) ? XmALIGNMENT_END : | |
114 | ((style & wxALIGN_CENTRE) ? XmALIGNMENT_CENTER : | |
115 | XmALIGNMENT_BEGINNING)), | |
116 | NULL); | |
117 | ||
6886fcfa | 118 | m_mainWidget = borderWidget ? borderWidget : m_labelWidget; |
7227cefd | 119 | |
a4294b78 JS |
120 | SetCanAddEventHandler(TRUE); |
121 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); | |
02e8b2f9 | 122 | |
0d57be45 | 123 | ChangeBackgroundColour (); |
4bb6408c | 124 | |
a4294b78 | 125 | return TRUE; |
4bb6408c JS |
126 | } |
127 | ||
4b5f3fe6 | 128 | void wxStaticText::ChangeFont(bool keepOriginalSize) |
0d57be45 | 129 | { |
4b5f3fe6 | 130 | wxWindow::ChangeFont(keepOriginalSize); |
0d57be45 JS |
131 | } |
132 | ||
133 | void wxStaticText::ChangeBackgroundColour() | |
134 | { | |
321db4b6 | 135 | wxWindow::ChangeBackgroundColour(); |
0d57be45 JS |
136 | } |
137 | ||
138 | void wxStaticText::ChangeForegroundColour() | |
139 | { | |
321db4b6 | 140 | wxWindow::ChangeForegroundColour(); |
0d57be45 JS |
141 | } |
142 | ||
fe5de1ea JS |
143 | void wxStaticText::SetLabel(const wxString& label) |
144 | { | |
145 | wxString buf(wxStripMenuCodes(label)); | |
146 | wxXmString label_str(buf); | |
147 | ||
148 | // This variable means we don't need so many casts later. | |
149 | Widget widget = (Widget) m_labelWidget; | |
150 | ||
151 | if (GetWindowStyle() & wxST_NO_AUTORESIZE) | |
152 | { | |
153 | XtUnmanageChild(widget); | |
154 | Dimension width, height; | |
155 | XtVaGetValues(widget, XmNwidth, &width, XmNheight, &height, NULL); | |
156 | ||
157 | XtVaSetValues(widget, | |
158 | XmNlabelString, label_str(), | |
159 | XmNlabelType, XmSTRING, | |
160 | NULL); | |
161 | XtVaSetValues(widget, | |
162 | XmNwidth, width, | |
163 | XmNheight, height, | |
164 | NULL); | |
165 | XtManageChild(widget); | |
166 | } | |
167 | else | |
168 | { | |
169 | XtVaSetValues(widget, | |
170 | XmNlabelString, label_str(), | |
171 | XmNlabelType, XmSTRING, | |
172 | NULL); | |
173 | } | |
174 | } | |
175 |