]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/stattext.cpp
Fix assorted typos in comments and other non-code.
[wxWidgets.git] / src / gtk1 / stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/stattext.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
11
12 #if wxUSE_STATTEXT
13
14 #include "wx/stattext.h"
15 #include "wx/gtk1/private.h"
16
17 #include "gdk/gdk.h"
18 #include "gtk/gtk.h"
19
20 extern "C"
21 void wxgtk_window_size_request_callback(GtkWidget *widget,
22 GtkRequisition *requisition,
23 wxWindow *win);
24
25 //-----------------------------------------------------------------------------
26 // wxStaticText
27 //-----------------------------------------------------------------------------
28
29 wxStaticText::wxStaticText()
30 {
31 }
32
33 wxStaticText::wxStaticText(wxWindow *parent,
34 wxWindowID id,
35 const wxString &label,
36 const wxPoint &pos,
37 const wxSize &size,
38 long style,
39 const wxString &name)
40 {
41 Create( parent, id, label, pos, size, style, name );
42 }
43
44 bool wxStaticText::Create(wxWindow *parent,
45 wxWindowID id,
46 const wxString &label,
47 const wxPoint &pos,
48 const wxSize &size,
49 long style,
50 const wxString &name )
51 {
52 m_needParent = TRUE;
53
54 if (!PreCreation( parent, pos, size ) ||
55 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
56 {
57 wxFAIL_MSG( wxT("wxStaticText creation failed") );
58 return FALSE;
59 }
60
61 m_label = label;
62 m_widget = gtk_label_new( wxGTK_CONV( GTKRemoveMnemonics(label)) );
63
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);
72
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);
76
77 gtk_label_set_line_wrap( GTK_LABEL(m_widget), TRUE );
78
79 m_parent->DoAddChild( this );
80
81 PostCreation(size);
82
83 return TRUE;
84 }
85
86 wxString wxStaticText::GetLabel() const
87 {
88 GtkLabel *label = GTK_LABEL(m_widget);
89 wxString str = wxString( label->label );
90 return wxString(str);
91 }
92
93 void wxStaticText::SetLabel( const wxString &label )
94 {
95 wxCHECK_RET( m_widget != NULL, wxT("invalid static text") );
96
97 GTKSetLabelForLabel(GTK_LABEL(m_widget), label);
98
99 // adjust the label size to the new label unless disabled
100 if (!HasFlag(wxST_NO_AUTORESIZE))
101 SetSize( GetBestSize() );
102 }
103
104 bool wxStaticText::SetFont( const wxFont &font )
105 {
106 bool ret = wxControl::SetFont(font);
107
108 // adjust the label size to the new label unless disabled
109 if (!HasFlag(wxST_NO_AUTORESIZE))
110 {
111 InvalidateBestSize();
112 SetSize( GetBestSize() );
113 }
114 return ret;
115 }
116
117 void wxStaticText::DoSetSize(int x, int y,
118 int width, int height,
119 int sizeFlags )
120 {
121 wxControl::DoSetSize( x, y, width, height, sizeFlags );
122 }
123
124 wxSize wxStaticText::DoGetBestSize() const
125 {
126 // Do not return any arbitrary default value...
127 wxASSERT_MSG( m_widget, wxT("wxStaticText::DoGetBestSize called before creation") );
128
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 );
132
133 // GetBestSize is supposed to return unwrapped size
134 gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE );
135
136 GtkRequisition req;
137 req.width = -1;
138 req.height = -1;
139 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request )
140 (m_widget, &req );
141
142 gtk_label_set_line_wrap( GTK_LABEL(m_widget), TRUE );
143
144 return wxSize (req.width, req.height);
145 }
146
147 bool wxStaticText::SetForegroundColour(const wxColour& colour)
148 {
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());
153 return true;
154 }
155
156 // static
157 wxVisualAttributes
158 wxStaticText::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
159 {
160 return GetDefaultAttributesFromGTKWidget(gtk_label_new);
161 }
162
163 #endif // wxUSE_STATTEXT