]>
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 XmString text
= XmStringCreateLtoR (label1
, XmSTRING_DEFAULT_CHARSET
);
107 XmString text
= XmStringCreateLtoR ((char *)(const char*)label
, XmSTRING_DEFAULT_CHARSET
);
109 XmFontList fontList
= (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(parentWidget
));
111 m_labelWidget
= XtVaCreateManagedWidget ((char*) (const char*) name
,
113 borderWidget
? borderWidget
: parentWidget
,
114 XmNfontList
, fontList
,
115 XmNlabelString
, text
,
117 ((style
& wxALIGN_RIGHT
) ? XmALIGNMENT_END
:
118 ((style
& wxALIGN_CENTRE
) ? XmALIGNMENT_CENTER
:
119 XmALIGNMENT_BEGINNING
)),
124 m_mainWidget
= borderWidget
? borderWidget
: m_labelWidget
;
126 SetCanAddEventHandler(TRUE
);
127 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
129 ChangeBackgroundColour ();
134 void wxStaticText::ChangeFont(bool keepOriginalSize
)
136 wxWindow::ChangeFont(keepOriginalSize
);
139 void wxStaticText::ChangeBackgroundColour()
141 wxWindow::ChangeBackgroundColour();
144 void wxStaticText::ChangeForegroundColour()
146 wxWindow::ChangeForegroundColour();
149 void wxStaticText::SetLabel(const wxString
& label
)
151 wxString
buf(wxStripMenuCodes(label
));
152 wxXmString
label_str(buf
);
154 // This variable means we don't need so many casts later.
155 Widget widget
= (Widget
) m_labelWidget
;
157 if (GetWindowStyle() & wxST_NO_AUTORESIZE
)
159 XtUnmanageChild(widget
);
160 Dimension width
, height
;
161 XtVaGetValues(widget
, XmNwidth
, &width
, XmNheight
, &height
, NULL
);
163 XtVaSetValues(widget
,
164 XmNlabelString
, label_str(),
165 XmNlabelType
, XmSTRING
,
167 XtVaSetValues(widget
,
171 XtManageChild(widget
);
175 XtVaSetValues(widget
,
176 XmNlabelString
, label_str(),
177 XmNlabelType
, XmSTRING
,