]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "stattext.h"
19 #include "wx/stattext.h"
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
,wxControl
)
30 wxStaticText::wxStaticText()
34 wxStaticText::wxStaticText(wxWindow
*parent
,
36 const wxString
&label
,
42 Create( parent
, id
, label
, pos
, size
, style
, name
);
45 bool wxStaticText::Create(wxWindow
*parent
,
47 const wxString
&label
,
51 const wxString
&name
)
55 if (!PreCreation( parent
, pos
, size
) ||
56 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
58 wxFAIL_MSG( wxT("wxXX creation failed") );
62 // notice that we call the base class version which will just remove the
63 // '&' characters from the string, but not set the label's text to it
64 // because the label is not yet created and because SetLabel() has a side
65 // effect of changing the control size which might not be desirable
66 wxControl::SetLabel(label
);
67 m_widget
= gtk_label_new( m_label
.mbc_str() );
69 GtkJustification justify
;
70 if ( style
& wxALIGN_CENTER
)
71 justify
= GTK_JUSTIFY_CENTER
;
72 else if ( style
& wxALIGN_RIGHT
)
73 justify
= GTK_JUSTIFY_RIGHT
;
74 else // wxALIGN_LEFT is 0
75 justify
= GTK_JUSTIFY_LEFT
;
76 gtk_label_set_justify(GTK_LABEL(m_widget
), justify
);
78 // GTK_JUSTIFY_LEFT is 0, RIGHT 1 and CENTER 2
79 static const float labelAlignments
[] = { 0.0, 1.0, 0.5 };
80 gtk_misc_set_alignment(GTK_MISC(m_widget
), labelAlignments
[justify
], 0.0);
82 // do not move this call elsewhere
83 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), FALSE
);
85 m_parent
->DoAddChild( this );
91 wxControl::SetFont( parent
->GetFont() );
93 wxSize
size_best( DoGetBestSize() );
94 wxSize
new_size( size
);
96 new_size
.x
= size_best
.x
;
98 new_size
.y
= size_best
.y
;
99 if ((new_size
.x
!= size
.x
) || (new_size
.y
!= size
.y
))
100 SetSize( new_size
.x
, new_size
.y
);
102 SetBackgroundColour( parent
->GetBackgroundColour() );
103 SetForegroundColour( parent
->GetForegroundColour() );
109 wxString
wxStaticText::GetLabel() const
111 char *str
= (char *) NULL
;
112 gtk_label_get( GTK_LABEL(m_widget
), &str
);
114 return wxString(str
);
117 void wxStaticText::SetLabel( const wxString
&label
)
119 wxControl::SetLabel(label
);
121 gtk_label_set( GTK_LABEL(m_widget
), m_label
.mbc_str() );
123 // adjust the label size to the new label unless disabled
124 if (!HasFlag(wxST_NO_AUTORESIZE
))
125 SetSize( GetBestSize() );
128 bool wxStaticText::SetFont( const wxFont
&font
)
130 bool ret
= wxControl::SetFont(font
);
132 // adjust the label size to the new label unless disabled
133 if (!HasFlag(wxST_NO_AUTORESIZE
))
134 SetSize( GetBestSize() );
139 void wxStaticText::ApplyWidgetStyle()
142 gtk_widget_set_style( m_widget
, m_widgetStyle
);
145 wxSize
wxStaticText::DoGetBestSize() const
147 // Do not return any arbitrary default value...
148 wxASSERT_MSG( m_widget
, wxT("wxStaticText::DoGetBestSize called before creation") );
150 // this invalidates the size request
151 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), TRUE
);
152 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), FALSE
);
157 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) )->size_request
)
160 return wxSize(req
.width
, req
.height
);
163 #endif // wxUSE_STATTEXT