]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStaticText
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "stattext.h"
17 #define XtDisplay XTDISPLAY
21 #include "wx/stattext.h"
26 #pragma message disable nosimpint
30 #include <Xm/LabelG.h>
31 #include <Xm/PushBG.h>
33 #pragma message enable nosimpint
36 #include "wx/motif/private.h"
38 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
, wxControl
)
40 bool wxStaticText::Create(wxWindow
*parent
, wxWindowID id
,
41 const wxString
& label
,
48 if (parent
) parent
->AddChild(this);
50 m_backgroundColour
= parent
->GetBackgroundColour();
51 m_foregroundColour
= parent
->GetForegroundColour();
54 m_windowId
= (int)NewControlId();
58 m_windowStyle
= style
;
59 m_font
= parent
->GetFont();
61 #if 0 // gcc 2.95 doesn't like this apparently
62 char* label1
= (label
.IsNull() ? "" : (char*) (const char*) label
);
65 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
67 Widget borderWidget
= NULL
;
69 // Decorate the label widget if a border style is specified.
70 if (style
& wxSIMPLE_BORDER
)
72 borderWidget
= XtVaCreateManagedWidget
75 xmFrameWidgetClass
, parentWidget
,
76 XmNshadowType
, XmSHADOW_ETCHED_IN
,
77 XmNshadowThickness
, 1,
80 } else if (style
& wxSUNKEN_BORDER
)
82 borderWidget
= XtVaCreateManagedWidget
85 xmFrameWidgetClass
, parentWidget
,
86 XmNshadowType
, XmSHADOW_IN
,
89 } else if (style
& wxRAISED_BORDER
)
91 borderWidget
= XtVaCreateManagedWidget
94 xmFrameWidgetClass
, parentWidget
,
95 XmNshadowType
, XmSHADOW_OUT
,
100 #if 0 // gcc 2.95 doesn't like this apparently
101 // Use XmStringCreateLtoR(), since XmStringCreateSimple
102 // doesn't obey separators.
103 // XmString text = XmStringCreateSimple (label1);
104 wxXmString
text( label1
);
107 wxXmString
text( label
);
109 WXFontType fontType
= m_font
.GetFontType(XtDisplay(parentWidget
));
111 m_labelWidget
= XtVaCreateManagedWidget ((char*) (const char*) name
,
113 borderWidget
? borderWidget
: parentWidget
,
114 wxFont::GetFontTag(), fontType
,
115 XmNlabelString
, text(),
117 ((style
& wxALIGN_RIGHT
) ? XmALIGNMENT_END
:
118 ((style
& wxALIGN_CENTRE
) ? XmALIGNMENT_CENTER
:
119 XmALIGNMENT_BEGINNING
)),
122 m_mainWidget
= borderWidget
? borderWidget
: m_labelWidget
;
124 SetCanAddEventHandler(TRUE
);
125 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
127 ChangeBackgroundColour ();
132 void wxStaticText::ChangeFont(bool keepOriginalSize
)
134 wxWindow::ChangeFont(keepOriginalSize
);
137 void wxStaticText::ChangeBackgroundColour()
139 wxWindow::ChangeBackgroundColour();
142 void wxStaticText::ChangeForegroundColour()
144 wxWindow::ChangeForegroundColour();
147 void wxStaticText::SetLabel(const wxString
& label
)
149 wxString
buf(wxStripMenuCodes(label
));
150 wxXmString
label_str(buf
);
152 // This variable means we don't need so many casts later.
153 Widget widget
= (Widget
) m_labelWidget
;
155 if (GetWindowStyle() & wxST_NO_AUTORESIZE
)
157 XtUnmanageChild(widget
);
158 Dimension width
, height
;
159 XtVaGetValues(widget
, XmNwidth
, &width
, XmNheight
, &height
, NULL
);
161 XtVaSetValues(widget
,
162 XmNlabelString
, label_str(),
163 XmNlabelType
, XmSTRING
,
165 XtVaSetValues(widget
,
169 XtManageChild(widget
);
173 XtVaSetValues(widget
,
174 XmNlabelString
, label_str(),
175 XmNlabelType
, XmSTRING
,