]>
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 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
,wxControl
)
32 wxStaticText::wxStaticText()
36 wxStaticText::wxStaticText(wxWindow
*parent
,
38 const wxString
&label
,
44 Create( parent
, id
, label
, pos
, size
, style
, name
);
47 bool wxStaticText::Create(wxWindow
*parent
,
49 const wxString
&label
,
53 const wxString
&name
)
57 if (!PreCreation( parent
, pos
, size
) ||
58 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
60 wxFAIL_MSG( wxT("wxStaticText creation failed") );
65 m_widget
= gtk_label_new( wxGTK_CONV( GTKRemoveMnemonics(label
)) );
67 GtkJustification justify
;
68 if ( style
& wxALIGN_CENTER
)
69 justify
= GTK_JUSTIFY_CENTER
;
70 else if ( style
& wxALIGN_RIGHT
)
71 justify
= GTK_JUSTIFY_RIGHT
;
72 else // wxALIGN_LEFT is 0
73 justify
= GTK_JUSTIFY_LEFT
;
74 gtk_label_set_justify(GTK_LABEL(m_widget
), justify
);
76 // GTK_JUSTIFY_LEFT is 0, RIGHT 1 and CENTER 2
77 static const float labelAlignments
[] = { 0.0, 1.0, 0.5 };
78 gtk_misc_set_alignment(GTK_MISC(m_widget
), labelAlignments
[justify
], 0.0);
80 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), TRUE
);
82 m_parent
->DoAddChild( this );
89 wxString
wxStaticText::GetLabel() const
91 GtkLabel
*label
= GTK_LABEL(m_widget
);
92 wxString str
= wxString( label
->label
);
96 void wxStaticText::SetLabel( const wxString
&label
)
98 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid static text") );
100 GTKSetLabelForLabel(GTK_LABEL(m_widget
), label
);
102 // adjust the label size to the new label unless disabled
103 if (!HasFlag(wxST_NO_AUTORESIZE
))
104 SetSize( GetBestSize() );
107 bool wxStaticText::SetFont( const wxFont
&font
)
109 bool ret
= wxControl::SetFont(font
);
111 // adjust the label size to the new label unless disabled
112 if (!HasFlag(wxST_NO_AUTORESIZE
))
114 InvalidateBestSize();
115 SetSize( GetBestSize() );
120 void wxStaticText::DoSetSize(int x
, int y
,
121 int width
, int height
,
124 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
);
127 wxSize
wxStaticText::DoGetBestSize() const
129 // Do not return any arbitrary default value...
130 wxASSERT_MSG( m_widget
, wxT("wxStaticText::DoGetBestSize called before creation") );
132 // This resets the internal GTK1 size calculation, which
133 // otherwise would be cashed (incorrectly)
134 gtk_label_set_pattern( GTK_LABEL(m_widget
), NULL
);
136 // GetBestSize is supposed to return unwrapped size
137 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), FALSE
);
142 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) )->size_request
)
145 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), TRUE
);
147 return wxSize (req
.width
, req
.height
);
150 bool wxStaticText::SetForegroundColour(const wxColour
& colour
)
152 // First, we call the base class member
153 wxControl::SetForegroundColour(colour
);
154 // Then, to force the color change, we set the label with the current label
155 SetLabel(GetLabel());
161 wxStaticText::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
163 return GetDefaultAttributesFromGTKWidget(gtk_label_new
);
166 #endif // wxUSE_STATTEXT