]>
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"
15 #include "wx/stattext.h"
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
,wxControl
)
26 wxStaticText::wxStaticText()
30 wxStaticText::wxStaticText(wxWindow
*parent
,
32 const wxString
&label
,
38 Create( parent
, id
, label
, pos
, size
, style
, name
);
41 bool wxStaticText::Create(wxWindow
*parent
,
43 const wxString
&label
,
47 const wxString
&name
)
51 if (!PreCreation( parent
, pos
, size
) ||
52 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
54 wxFAIL_MSG( wxT("wxXX creation failed") );
58 // notice that we call the base class version which will just remove the
59 // '&' characters from the string, but not set the label's text to it
60 // because the label is not yet created and because SetLabel() has a side
61 // effect of changing the control size which might not be desirable
62 wxControl::SetLabel(label
);
63 m_widget
= gtk_label_new( m_label
.mbc_str() );
65 GtkJustification justify
;
66 if ( style
& wxALIGN_CENTER
)
67 justify
= GTK_JUSTIFY_CENTER
;
68 else if ( style
& wxALIGN_RIGHT
)
69 justify
= GTK_JUSTIFY_RIGHT
;
70 else // wxALIGN_LEFT is 0
71 justify
= GTK_JUSTIFY_LEFT
;
72 gtk_label_set_justify(GTK_LABEL(m_widget
), justify
);
74 // GTK_JUSTIFY_LEFT is 0, RIGHT 1 and CENTER 2
75 static const float labelAlignments
[] = { 0.0, 1.0, 0.5 };
76 gtk_misc_set_alignment(GTK_MISC(m_widget
), labelAlignments
[justify
], 0.0);
78 // do not move this call elsewhere
79 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), FALSE
);
81 m_parent
->DoAddChild( this );
87 wxControl::SetFont( parent
->GetFont() );
89 wxSize
size_best( DoGetBestSize() );
90 wxSize
new_size( size
);
92 new_size
.x
= size_best
.x
;
94 new_size
.y
= size_best
.y
;
95 if ((new_size
.x
!= size
.x
) || (new_size
.y
!= size
.y
))
96 SetSize( new_size
.x
, new_size
.y
);
98 SetBackgroundColour( parent
->GetBackgroundColour() );
99 SetForegroundColour( parent
->GetForegroundColour() );
105 wxString
wxStaticText::GetLabel() const
107 char *str
= (char *) NULL
;
108 gtk_label_get( GTK_LABEL(m_widget
), &str
);
110 return wxString(str
);
113 void wxStaticText::SetLabel( const wxString
&label
)
115 wxControl::SetLabel(label
);
117 gtk_label_set( GTK_LABEL(m_widget
), m_label
.mbc_str() );
119 // adjust the label size to the new label unless disabled
120 if (!HasFlag(wxST_NO_AUTORESIZE
))
121 SetSize( GetBestSize() );
124 bool wxStaticText::SetFont( const wxFont
&font
)
126 bool ret
= wxControl::SetFont(font
);
128 // adjust the label size to the new label unless disabled
129 if (!HasFlag(wxST_NO_AUTORESIZE
))
130 SetSize( GetBestSize() );
135 void wxStaticText::ApplyWidgetStyle()
138 gtk_widget_set_style( m_widget
, m_widgetStyle
);
141 wxSize
wxStaticText::DoGetBestSize() const
143 // Do not return any arbitrary default value...
144 wxASSERT_MSG( m_widget
, wxT("wxStaticText::DoGetBestSize called before creation") );
146 // this invalidates the size request
147 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), TRUE
);
148 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), FALSE
);
153 (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget
)->klass
)->size_request
)
156 return wxSize(req
.width
, req
.height
);