]>
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 | ||
b58197f2 | 30 | wxStaticText::wxStaticText() |
c801d85f | 31 | { |
3f659fd6 | 32 | } |
c801d85f | 33 | |
b58197f2 VZ |
34 | wxStaticText::wxStaticText(wxWindow *parent, |
35 | wxWindowID id, | |
36 | const wxString &label, | |
37 | const wxPoint &pos, | |
38 | const wxSize &size, | |
39 | long style, | |
40 | const wxString &name) | |
c801d85f KB |
41 | { |
42 | Create( parent, id, label, pos, size, style, name ); | |
3f659fd6 | 43 | } |
c801d85f | 44 | |
b58197f2 VZ |
45 | bool wxStaticText::Create(wxWindow *parent, |
46 | wxWindowID id, | |
47 | const wxString &label, | |
48 | const wxPoint &pos, | |
49 | const wxSize &size, | |
50 | long style, | |
51 | const wxString &name ) | |
c801d85f | 52 | { |
a93109d5 | 53 | m_needParent = TRUE; |
b58197f2 | 54 | |
4dcaf11a RR |
55 | if (!PreCreation( parent, pos, size ) || |
56 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
57 | { | |
8ccac798 | 58 | wxFAIL_MSG( wxT("wxStaticText creation failed") ); |
185fa6bf | 59 | return FALSE; |
4dcaf11a | 60 | } |
b58197f2 | 61 | |
2ce89389 VZ |
62 | m_label = label; |
63 | m_widget = gtk_label_new( wxGTK_CONV( GTKRemoveMnemonics(label)) ); | |
3d257b8d | 64 | |
a93109d5 RR |
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); | |
1a5594b8 | 73 | |
1a5594b8 VZ |
74 | // GTK_JUSTIFY_LEFT is 0, RIGHT 1 and CENTER 2 |
75 | static const float labelAlignments[] = { 0.0, 1.0, 0.5 }; | |
76 | gtk_misc_set_alignment(GTK_MISC(m_widget), labelAlignments[justify], 0.0); | |
185fa6bf | 77 | |
a5040b80 | 78 | gtk_label_set_line_wrap( GTK_LABEL(m_widget), TRUE ); |
33720b2d | 79 | |
f03fc89f | 80 | m_parent->DoAddChild( this ); |
b58197f2 | 81 | |
abdeb9e7 | 82 | PostCreation(size); |
3d257b8d | 83 | |
a93109d5 | 84 | return TRUE; |
3f659fd6 | 85 | } |
c801d85f | 86 | |
ed58dbea | 87 | wxString wxStaticText::GetLabel() const |
c801d85f | 88 | { |
3b2e67f6 | 89 | GtkLabel *label = GTK_LABEL(m_widget); |
3b2e67f6 | 90 | wxString str = wxString( label->label ); |
b58197f2 | 91 | return wxString(str); |
3f659fd6 | 92 | } |
c801d85f KB |
93 | |
94 | void wxStaticText::SetLabel( const wxString &label ) | |
95 | { | |
2ce89389 | 96 | wxCHECK_RET( m_widget != NULL, wxT("invalid static text") ); |
8ccac798 | 97 | |
2ce89389 | 98 | GTKSetLabelForLabel(GTK_LABEL(m_widget), label); |
c0e6c051 RD |
99 | |
100 | // adjust the label size to the new label unless disabled | |
101 | if (!HasFlag(wxST_NO_AUTORESIZE)) | |
c0e6c051 | 102 | SetSize( GetBestSize() ); |
33720b2d RR |
103 | } |
104 | ||
c0e6c051 RD |
105 | bool wxStaticText::SetFont( const wxFont &font ) |
106 | { | |
107 | bool ret = wxControl::SetFont(font); | |
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 RD |
114 | } |
115 | return ret; | |
116 | } | |
58614078 | 117 | |
a5040b80 RR |
118 | void wxStaticText::DoSetSize(int x, int y, |
119 | int width, int height, | |
120 | int sizeFlags ) | |
121 | { | |
122 | wxControl::DoSetSize( x, y, width, height, sizeFlags ); | |
123 | } | |
124 | ||
33720b2d RR |
125 | wxSize wxStaticText::DoGetBestSize() const |
126 | { | |
127 | // Do not return any arbitrary default value... | |
128 | wxASSERT_MSG( m_widget, wxT("wxStaticText::DoGetBestSize called before creation") ); | |
129 | ||
088ddc4e RR |
130 | // This resets the internal GTK1 size calculation, which |
131 | // otherwise would be cashed (incorrectly) | |
a5040b80 | 132 | gtk_label_set_pattern( GTK_LABEL(m_widget), NULL ); |
088ddc4e RR |
133 | |
134 | // GetBestSize is supposed to return unwrapped size | |
135 | gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE ); | |
3d257b8d | 136 | |
33720b2d | 137 | GtkRequisition req; |
a5040b80 RR |
138 | req.width = -1; |
139 | req.height = -1; | |
2afa14f2 | 140 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) |
33720b2d RR |
141 | (m_widget, &req ); |
142 | ||
088ddc4e | 143 | gtk_label_set_line_wrap( GTK_LABEL(m_widget), TRUE ); |
3d257b8d | 144 | |
a5040b80 | 145 | return wxSize (req.width, req.height); |
33720b2d RR |
146 | } |
147 | ||
174b10af RR |
148 | bool wxStaticText::SetForegroundColour(const wxColour& colour) |
149 | { | |
150 | // First, we call the base class member | |
151 | wxControl::SetForegroundColour(colour); | |
152 | // Then, to force the color change, we set the label with the current label | |
153 | SetLabel(GetLabel()); | |
154 | return true; | |
155 | } | |
156 | ||
9d522606 RD |
157 | // static |
158 | wxVisualAttributes | |
159 | wxStaticText::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
160 | { | |
161 | return GetDefaultAttributesFromGTKWidget(gtk_label_new); | |
162 | } | |
163 | ||
1e6feb95 | 164 | #endif // wxUSE_STATTEXT |