]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: stattext.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
a81258be RR |
5 | // Id: $Id$ |
6 | // Copyright: (c) 1998 Robert Roebling | |
65571936 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
1e6feb95 VZ |
12 | |
13 | #if wxUSE_STATTEXT | |
14 | ||
c801d85f | 15 | #include "wx/stattext.h" |
3cbab641 | 16 | #include "wx/gtk1/private.h" |
c801d85f | 17 | |
83624f79 RR |
18 | #include "gdk/gdk.h" |
19 | #include "gtk/gtk.h" | |
20 | ||
e1f448ee VZ |
21 | extern "C" |
22 | void wxgtk_window_size_request_callback(GtkWidget *widget, | |
23 | GtkRequisition *requisition, | |
24 | wxWindow *win); | |
25 | ||
c801d85f KB |
26 | //----------------------------------------------------------------------------- |
27 | // wxStaticText | |
28 | //----------------------------------------------------------------------------- | |
29 | ||
30 | IMPLEMENT_DYNAMIC_CLASS(wxStaticText,wxControl) | |
31 | ||
b58197f2 | 32 | wxStaticText::wxStaticText() |
c801d85f | 33 | { |
3f659fd6 | 34 | } |
c801d85f | 35 | |
b58197f2 VZ |
36 | wxStaticText::wxStaticText(wxWindow *parent, |
37 | wxWindowID id, | |
38 | const wxString &label, | |
39 | const wxPoint &pos, | |
40 | const wxSize &size, | |
41 | long style, | |
42 | const wxString &name) | |
c801d85f KB |
43 | { |
44 | Create( parent, id, label, pos, size, style, name ); | |
3f659fd6 | 45 | } |
c801d85f | 46 | |
b58197f2 VZ |
47 | bool wxStaticText::Create(wxWindow *parent, |
48 | wxWindowID id, | |
49 | const wxString &label, | |
50 | const wxPoint &pos, | |
51 | const wxSize &size, | |
52 | long style, | |
53 | const wxString &name ) | |
c801d85f | 54 | { |
a93109d5 | 55 | m_needParent = TRUE; |
b58197f2 | 56 | |
4dcaf11a RR |
57 | if (!PreCreation( parent, pos, size ) || |
58 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
59 | { | |
8ccac798 | 60 | wxFAIL_MSG( wxT("wxStaticText creation failed") ); |
185fa6bf | 61 | return FALSE; |
4dcaf11a | 62 | } |
b58197f2 | 63 | |
bd1a4a99 JS |
64 | // the base class version which |
65 | // will not set the label's text to it | |
b58197f2 VZ |
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 | |
bd1a4a99 | 68 | wxString label1(wxStripMenuCodes(label)); |
a93109d5 | 69 | wxControl::SetLabel(label); |
bd1a4a99 | 70 | m_widget = gtk_label_new( wxGTK_CONV( label1 ) ); |
3d257b8d | 71 | |
a93109d5 RR |
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); | |
1a5594b8 | 80 | |
1a5594b8 VZ |
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); | |
185fa6bf | 84 | |
a5040b80 | 85 | gtk_label_set_line_wrap( GTK_LABEL(m_widget), TRUE ); |
33720b2d | 86 | |
f03fc89f | 87 | m_parent->DoAddChild( this ); |
b58197f2 | 88 | |
abdeb9e7 | 89 | PostCreation(size); |
3d257b8d | 90 | |
a93109d5 | 91 | return TRUE; |
3f659fd6 | 92 | } |
c801d85f | 93 | |
ed58dbea | 94 | wxString wxStaticText::GetLabel() const |
c801d85f | 95 | { |
3b2e67f6 | 96 | GtkLabel *label = GTK_LABEL(m_widget); |
3b2e67f6 | 97 | wxString str = wxString( label->label ); |
b58197f2 | 98 | return wxString(str); |
3f659fd6 | 99 | } |
c801d85f KB |
100 | |
101 | void wxStaticText::SetLabel( const wxString &label ) | |
102 | { | |
8ccac798 VS |
103 | wxControl::SetLabel(label); |
104 | ||
bd1a4a99 JS |
105 | wxString label1(wxStripMenuCodes(label)); |
106 | ||
107 | gtk_label_set( GTK_LABEL(m_widget), wxGTK_CONV( label1 ) ); | |
c0e6c051 RD |
108 | |
109 | // adjust the label size to the new label unless disabled | |
110 | if (!HasFlag(wxST_NO_AUTORESIZE)) | |
111 | { | |
9f884528 | 112 | InvalidateBestSize(); |
c0e6c051 | 113 | SetSize( GetBestSize() ); |
c0e6c051 | 114 | } |
33720b2d RR |
115 | } |
116 | ||
c0e6c051 RD |
117 | bool wxStaticText::SetFont( const wxFont &font ) |
118 | { | |
119 | bool ret = wxControl::SetFont(font); | |
120 | ||
121 | // adjust the label size to the new label unless disabled | |
122 | if (!HasFlag(wxST_NO_AUTORESIZE)) | |
123 | { | |
9f884528 | 124 | InvalidateBestSize(); |
c0e6c051 | 125 | SetSize( GetBestSize() ); |
c0e6c051 RD |
126 | } |
127 | return ret; | |
128 | } | |
58614078 | 129 | |
a5040b80 RR |
130 | void wxStaticText::DoSetSize(int x, int y, |
131 | int width, int height, | |
132 | int sizeFlags ) | |
133 | { | |
134 | wxControl::DoSetSize( x, y, width, height, sizeFlags ); | |
135 | } | |
136 | ||
33720b2d RR |
137 | wxSize wxStaticText::DoGetBestSize() const |
138 | { | |
139 | // Do not return any arbitrary default value... | |
140 | wxASSERT_MSG( m_widget, wxT("wxStaticText::DoGetBestSize called before creation") ); | |
141 | ||
088ddc4e RR |
142 | // This resets the internal GTK1 size calculation, which |
143 | // otherwise would be cashed (incorrectly) | |
a5040b80 | 144 | gtk_label_set_pattern( GTK_LABEL(m_widget), NULL ); |
088ddc4e RR |
145 | |
146 | // GetBestSize is supposed to return unwrapped size | |
147 | gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE ); | |
3d257b8d | 148 | |
33720b2d | 149 | GtkRequisition req; |
a5040b80 RR |
150 | req.width = -1; |
151 | req.height = -1; | |
2afa14f2 | 152 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) |
33720b2d RR |
153 | (m_widget, &req ); |
154 | ||
088ddc4e | 155 | gtk_label_set_line_wrap( GTK_LABEL(m_widget), TRUE ); |
3d257b8d | 156 | |
a5040b80 | 157 | return wxSize (req.width, req.height); |
33720b2d RR |
158 | } |
159 | ||
174b10af RR |
160 | bool wxStaticText::SetForegroundColour(const wxColour& colour) |
161 | { | |
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()); | |
166 | return true; | |
167 | } | |
168 | ||
9d522606 RD |
169 | // static |
170 | wxVisualAttributes | |
171 | wxStaticText::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
172 | { | |
173 | return GetDefaultAttributesFromGTKWidget(gtk_label_new); | |
174 | } | |
175 | ||
1e6feb95 | 176 | #endif // wxUSE_STATTEXT |