]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/stattext.cpp
36d2e64fd5b9d775729f0601e192274bbe14804e
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") );
64 // the base class version which
65 // will not set the label's text to it
66 // because the label is not yet created and because SetLabel() has a side
67 // effect of changing the control size which might not be desirable
68 wxString
label1(wxStripMenuCodes(label
));
69 wxControl::SetLabel(label
);
70 m_widget
= gtk_label_new( wxGTK_CONV( label1
) );
72 GtkJustification justify
;
73 if ( style
& wxALIGN_CENTER
)
74 justify
= GTK_JUSTIFY_CENTER
;
75 else if ( style
& wxALIGN_RIGHT
)
76 justify
= GTK_JUSTIFY_RIGHT
;
77 else // wxALIGN_LEFT is 0
78 justify
= GTK_JUSTIFY_LEFT
;
79 gtk_label_set_justify(GTK_LABEL(m_widget
), justify
);
81 // GTK_JUSTIFY_LEFT is 0, RIGHT 1 and CENTER 2
82 static const float labelAlignments
[] = { 0.0, 1.0, 0.5 };
83 gtk_misc_set_alignment(GTK_MISC(m_widget
), labelAlignments
[justify
], 0.0);
85 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), TRUE
);
87 m_parent
->DoAddChild( this );
94 wxString
wxStaticText::GetLabel() const
96 GtkLabel
*label
= GTK_LABEL(m_widget
);
97 wxString str
= wxString( label
->label
);
101 void wxStaticText::SetLabel( const wxString
&label
)
103 wxControl::SetLabel(label
);
105 wxString
label1(wxStripMenuCodes(label
));
107 gtk_label_set( GTK_LABEL(m_widget
), wxGTK_CONV( label1
) );
109 // adjust the label size to the new label unless disabled
110 if (!HasFlag(wxST_NO_AUTORESIZE
))
112 InvalidateBestSize();
113 SetSize( GetBestSize() );
117 bool wxStaticText::SetFont( const wxFont
&font
)
119 bool ret
= wxControl::SetFont(font
);
121 // adjust the label size to the new label unless disabled
122 if (!HasFlag(wxST_NO_AUTORESIZE
))
124 InvalidateBestSize();
125 SetSize( GetBestSize() );
130 void wxStaticText::DoSetSize(int x
, int y
,
131 int width
, int height
,
134 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
);
137 wxSize
wxStaticText::DoGetBestSize() const
139 // Do not return any arbitrary default value...
140 wxASSERT_MSG( m_widget
, wxT("wxStaticText::DoGetBestSize called before creation") );
142 // This resets the internal GTK1 size calculation, which
143 // otherwise would be cashed (incorrectly)
144 gtk_label_set_pattern( GTK_LABEL(m_widget
), NULL
);
146 // GetBestSize is supposed to return unwrapped size
147 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), FALSE
);
152 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) )->size_request
)
155 gtk_label_set_line_wrap( GTK_LABEL(m_widget
), TRUE
);
157 return wxSize (req
.width
, req
.height
);
160 bool wxStaticText::SetForegroundColour(const wxColour
& colour
)
162 // First, we call the base class member
163 wxControl::SetForegroundColour(colour
);
164 // Then, to force the color change, we set the label with the current label
165 SetLabel(GetLabel());
171 wxStaticText::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
173 return GetDefaultAttributesFromGTKWidget(gtk_label_new
);
176 #endif // wxUSE_STATTEXT