]>
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"
20 #include "wx/gtk/private.h"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
,wxControl
)
31 wxStaticText::wxStaticText()
35 wxStaticText::wxStaticText(wxWindow
*parent
,
37 const wxString
&label
,
43 Create( parent
, id
, label
, pos
, size
, style
, name
);
46 bool wxStaticText::Create(wxWindow
*parent
,
48 const wxString
&label
,
52 const wxString
&name
)
56 if (!PreCreation( parent
, pos
, size
) ||
57 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
59 wxFAIL_MSG( wxT("wxXX creation failed") );
63 // notice that we call the base class version which will just remove the
64 // '&' characters from the string, but not set the label's text to it
65 // because the label is not yet created and because SetLabel() has a side
66 // effect of changing the control size which might not be desirable
67 wxControl::SetLabel(label
);
68 m_widget
= gtk_label_new( m_label
.mbc_str() );
70 GtkJustification justify
;
71 if ( style
& wxALIGN_CENTER
)
72 justify
= GTK_JUSTIFY_CENTER
;
73 else if ( style
& wxALIGN_RIGHT
)
74 justify
= GTK_JUSTIFY_RIGHT
;
75 else // wxALIGN_LEFT is 0
76 justify
= GTK_JUSTIFY_LEFT
;
77 gtk_label_set_justify(GTK_LABEL(m_widget
), justify
);
79 // GTK_JUSTIFY_LEFT is 0, RIGHT 1 and CENTER 2
80 static const float labelAlignments
[] = { 0.0, 1.0, 0.5 };
81 gtk_misc_set_alignment(GTK_MISC(m_widget
), labelAlignments
[justify
], 0.0);
83 // do not move this call elsewhere
84 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), FALSE
);
86 m_parent
->DoAddChild( this );
92 wxControl::SetFont( parent
->GetFont() );
94 wxSize
size_best( DoGetBestSize() );
95 wxSize
new_size( size
);
97 new_size
.x
= size_best
.x
;
99 new_size
.y
= size_best
.y
;
100 if ((new_size
.x
!= size
.x
) || (new_size
.y
!= size
.y
))
101 SetSize( new_size
.x
, new_size
.y
);
103 SetBackgroundColour( parent
->GetBackgroundColour() );
104 SetForegroundColour( parent
->GetForegroundColour() );
110 wxString
wxStaticText::GetLabel() const
112 char *str
= (char *) NULL
;
113 gtk_label_get( GTK_LABEL(m_widget
), &str
);
115 return wxString(str
);
118 void wxStaticText::SetLabel( const wxString
&label
)
120 wxControl::SetLabel(label
);
122 gtk_label_set( GTK_LABEL(m_widget
), m_label
.mbc_str() );
124 // adjust the label size to the new label unless disabled
125 if (!HasFlag(wxST_NO_AUTORESIZE
))
126 SetSize( GetBestSize() );
129 bool wxStaticText::SetFont( const wxFont
&font
)
131 bool ret
= wxControl::SetFont(font
);
133 // adjust the label size to the new label unless disabled
134 if (!HasFlag(wxST_NO_AUTORESIZE
))
135 SetSize( GetBestSize() );
140 void wxStaticText::ApplyWidgetStyle()
143 gtk_widget_set_style( m_widget
, m_widgetStyle
);
146 wxSize
wxStaticText::DoGetBestSize() const
148 // Do not return any arbitrary default value...
149 wxASSERT_MSG( m_widget
, wxT("wxStaticText::DoGetBestSize called before creation") );
151 // this invalidates the size request
152 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), TRUE
);
153 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), FALSE
);
158 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) )->size_request
)
161 return wxSize(req
.width
, req
.height
);
164 #endif // wxUSE_STATTEXT