]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "stattext.h"
15 #include "wx/stattext.h"
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 IMPLEMENT_DYNAMIC_CLASS(wxStaticText
,wxControl
)
26 wxStaticText::wxStaticText()
30 wxStaticText::wxStaticText(wxWindow
*parent
,
32 const wxString
&label
,
38 Create( parent
, id
, label
, pos
, size
, style
, name
);
41 bool wxStaticText::Create(wxWindow
*parent
,
43 const wxString
&label
,
47 const wxString
&name
)
51 if (!PreCreation( parent
, pos
, size
) ||
52 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
54 wxFAIL_MSG( T("wxXX creation failed") );
58 // notice that we call the base class version which will just remove the
59 // '&' characters from the string, but not set the label's text to it
60 // because the label is not yet created and because SetLabel() has a side
61 // effect of changing the control size which might not be desirable
62 wxControl::SetLabel(label
);
63 m_widget
= gtk_label_new( m_label
.mbc_str() );
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 //#if GTK_MINOR_VERSION == 2
75 // GTK_JUSTIFY_LEFT is 0, RIGHT 1 and CENTER 2
76 static const float labelAlignments
[] = { 0.0, 1.0, 0.5 };
77 gtk_misc_set_alignment(GTK_MISC(m_widget
), labelAlignments
[justify
], 0.0);
81 (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget
)->klass
)->size_request
) (m_widget
, &req
);
83 wxSize newSize
= size
;
84 if (newSize
.x
== -1) newSize
.x
= req
.width
;
85 if (newSize
.y
== -1) newSize
.y
= req
.height
;
86 SetSize( newSize
.x
, newSize
.y
);
88 m_parent
->DoAddChild( this );
92 SetBackgroundColour( parent
->GetBackgroundColour() );
93 SetForegroundColour( parent
->GetForegroundColour() );
94 SetFont( parent
->GetFont() );
101 wxString
wxStaticText::GetLabel() const
103 char *str
= (char *) NULL
;
104 gtk_label_get( GTK_LABEL(m_widget
), &str
);
106 return wxString(str
);
109 void wxStaticText::SetLabel( const wxString
&label
)
111 wxControl::SetLabel(label
);
113 gtk_label_set( GTK_LABEL(m_widget
), m_label
.mbc_str() );
115 // adjust the label size to the new label
117 // TODO there should be a way to prevent SetLabel() from doing it (an
118 // additional parameter?)
120 (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget
)->klass
)->size_request
) (m_widget
, &req
);
122 SetSize( req
.width
, req
.height
);
125 void wxStaticText::ApplyWidgetStyle()
128 gtk_widget_set_style( m_widget
, m_widgetStyle
);