]>
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 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
15 #include "wx/stattext.h"
16 #include "wx/gtk1/private.h"
22 void wxgtk_window_size_request_callback(GtkWidget
*widget
,
23 GtkRequisition
*requisition
,
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
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("wxStaticText creation failed") );
63 m_widget
= gtk_label_new( wxGTK_CONV( GTKRemoveMnemonics(label
)) );
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 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), TRUE
);
80 m_parent
->DoAddChild( this );
87 wxString
wxStaticText::GetLabel() const
89 GtkLabel
*label
= GTK_LABEL(m_widget
);
90 wxString str
= wxString( label
->label
);
94 void wxStaticText::SetLabel( const wxString
&label
)
96 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid static text") );
98 GTKSetLabelForLabel(GTK_LABEL(m_widget
), label
);
100 // adjust the label size to the new label unless disabled
101 if (!HasFlag(wxST_NO_AUTORESIZE
))
102 SetSize( GetBestSize() );
105 bool wxStaticText::SetFont( const wxFont
&font
)
107 bool ret
= wxControl::SetFont(font
);
109 // adjust the label size to the new label unless disabled
110 if (!HasFlag(wxST_NO_AUTORESIZE
))
112 InvalidateBestSize();
113 SetSize( GetBestSize() );
118 void wxStaticText::DoSetSize(int x
, int y
,
119 int width
, int height
,
122 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
);
125 wxSize
wxStaticText::DoGetBestSize() const
127 // Do not return any arbitrary default value...
128 wxASSERT_MSG( m_widget
, wxT("wxStaticText::DoGetBestSize called before creation") );
130 // This resets the internal GTK1 size calculation, which
131 // otherwise would be cashed (incorrectly)
132 gtk_label_set_pattern( GTK_LABEL(m_widget
), NULL
);
134 // GetBestSize is supposed to return unwrapped size
135 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), FALSE
);
140 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) )->size_request
)
143 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), TRUE
);
145 return wxSize (req
.width
, req
.height
);
148 bool wxStaticText::SetForegroundColour(const wxColour
& colour
)
150 // First, we call the base class member
151 wxControl::SetForegroundColour(colour
);
152 // Then, to force the color change, we set the label with the current label
153 SetLabel(GetLabel());
159 wxStaticText::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
161 return GetDefaultAttributesFromGTKWidget(gtk_label_new
);
164 #endif // wxUSE_STATTEXT