]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/stattext.cpp
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
14 #include "wx/stattext.h"
15 #include "wx/gtk1/private.h"
21 void wxgtk_window_size_request_callback(GtkWidget
*widget
,
22 GtkRequisition
*requisition
,
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 wxStaticText::wxStaticText()
33 wxStaticText::wxStaticText(wxWindow
*parent
,
35 const wxString
&label
,
41 Create( parent
, id
, label
, pos
, size
, style
, name
);
44 bool wxStaticText::Create(wxWindow
*parent
,
46 const wxString
&label
,
50 const wxString
&name
)
54 if (!PreCreation( parent
, pos
, size
) ||
55 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
57 wxFAIL_MSG( wxT("wxStaticText creation failed") );
62 m_widget
= gtk_label_new( wxGTK_CONV( GTKRemoveMnemonics(label
)) );
64 GtkJustification justify
;
65 if ( style
& wxALIGN_CENTER
)
66 justify
= GTK_JUSTIFY_CENTER
;
67 else if ( style
& wxALIGN_RIGHT
)
68 justify
= GTK_JUSTIFY_RIGHT
;
69 else // wxALIGN_LEFT is 0
70 justify
= GTK_JUSTIFY_LEFT
;
71 gtk_label_set_justify(GTK_LABEL(m_widget
), justify
);
73 // GTK_JUSTIFY_LEFT is 0, RIGHT 1 and CENTER 2
74 static const float labelAlignments
[] = { 0.0, 1.0, 0.5 };
75 gtk_misc_set_alignment(GTK_MISC(m_widget
), labelAlignments
[justify
], 0.0);
77 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), TRUE
);
79 m_parent
->DoAddChild( this );
86 wxString
wxStaticText::GetLabel() const
88 GtkLabel
*label
= GTK_LABEL(m_widget
);
89 wxString str
= wxString( label
->label
);
93 void wxStaticText::SetLabel( const wxString
&label
)
95 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid static text") );
97 GTKSetLabelForLabel(GTK_LABEL(m_widget
), label
);
99 // adjust the label size to the new label unless disabled
100 if (!HasFlag(wxST_NO_AUTORESIZE
))
101 SetSize( GetBestSize() );
104 bool wxStaticText::SetFont( const wxFont
&font
)
106 bool ret
= wxControl::SetFont(font
);
108 // adjust the label size to the new label unless disabled
109 if (!HasFlag(wxST_NO_AUTORESIZE
))
111 InvalidateBestSize();
112 SetSize( GetBestSize() );
117 void wxStaticText::DoSetSize(int x
, int y
,
118 int width
, int height
,
121 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
);
124 wxSize
wxStaticText::DoGetBestSize() const
126 // Do not return any arbitrary default value...
127 wxASSERT_MSG( m_widget
, wxT("wxStaticText::DoGetBestSize called before creation") );
129 // This resets the internal GTK1 size calculation, which
130 // otherwise would be cashed (incorrectly)
131 gtk_label_set_pattern( GTK_LABEL(m_widget
), NULL
);
133 // GetBestSize is supposed to return unwrapped size
134 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), FALSE
);
139 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) )->size_request
)
142 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), TRUE
);
144 return wxSize (req
.width
, req
.height
);
147 bool wxStaticText::SetForegroundColour(const wxColour
& colour
)
149 // First, we call the base class member
150 wxControl::SetForegroundColour(colour
);
151 // Then, to force the color change, we set the label with the current label
152 SetLabel(GetLabel());
158 wxStaticText::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
160 return GetDefaultAttributesFromGTKWidget(gtk_label_new
);
163 #endif // wxUSE_STATTEXT