]>
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 | |
b58197f2 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | ||
11 | #ifdef __GNUG__ | |
b58197f2 | 12 | #pragma implementation "stattext.h" |
c801d85f KB |
13 | #endif |
14 | ||
15 | #include "wx/stattext.h" | |
16 | ||
83624f79 RR |
17 | #include "gdk/gdk.h" |
18 | #include "gtk/gtk.h" | |
19 | ||
c801d85f KB |
20 | //----------------------------------------------------------------------------- |
21 | // wxStaticText | |
22 | //----------------------------------------------------------------------------- | |
23 | ||
24 | IMPLEMENT_DYNAMIC_CLASS(wxStaticText,wxControl) | |
25 | ||
b58197f2 | 26 | wxStaticText::wxStaticText() |
c801d85f | 27 | { |
3f659fd6 | 28 | } |
c801d85f | 29 | |
b58197f2 VZ |
30 | wxStaticText::wxStaticText(wxWindow *parent, |
31 | wxWindowID id, | |
32 | const wxString &label, | |
33 | const wxPoint &pos, | |
34 | const wxSize &size, | |
35 | long style, | |
36 | const wxString &name) | |
c801d85f KB |
37 | { |
38 | Create( parent, id, label, pos, size, style, name ); | |
3f659fd6 | 39 | } |
c801d85f | 40 | |
b58197f2 VZ |
41 | bool wxStaticText::Create(wxWindow *parent, |
42 | wxWindowID id, | |
43 | const wxString &label, | |
44 | const wxPoint &pos, | |
45 | const wxSize &size, | |
46 | long style, | |
47 | const wxString &name ) | |
c801d85f | 48 | { |
a93109d5 | 49 | m_needParent = TRUE; |
b58197f2 | 50 | |
4dcaf11a RR |
51 | if (!PreCreation( parent, pos, size ) || |
52 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
53 | { | |
e90c1d2a | 54 | wxFAIL_MSG( T("wxXX creation failed") ); |
4dcaf11a RR |
55 | return FALSE; |
56 | } | |
b58197f2 VZ |
57 | |
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 | |
a93109d5 | 62 | wxControl::SetLabel(label); |
9f15c5fe | 63 | m_widget = gtk_label_new( m_label.mbc_str() ); |
a93109d5 RR |
64 | |
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 | |
fd9811b1 | 74 | //#if GTK_MINOR_VERSION == 2 |
1a5594b8 VZ |
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); | |
fd9811b1 | 78 | //#endif // GTK 1.2.x |
ccc585e5 | 79 | |
a93109d5 RR |
80 | GtkRequisition req; |
81 | (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req ); | |
b58197f2 | 82 | |
4dcaf11a | 83 | wxSize newSize = size; |
a93109d5 RR |
84 | if (newSize.x == -1) newSize.x = req.width; |
85 | if (newSize.y == -1) newSize.y = req.height; | |
a93109d5 | 86 | SetSize( newSize.x, newSize.y ); |
b58197f2 | 87 | |
f03fc89f | 88 | m_parent->DoAddChild( this ); |
b58197f2 | 89 | |
a93109d5 | 90 | PostCreation(); |
b58197f2 | 91 | |
a93109d5 RR |
92 | SetBackgroundColour( parent->GetBackgroundColour() ); |
93 | SetForegroundColour( parent->GetForegroundColour() ); | |
a7ac4461 | 94 | SetFont( parent->GetFont() ); |
58614078 | 95 | |
a93109d5 | 96 | Show( TRUE ); |
b58197f2 | 97 | |
a93109d5 | 98 | return TRUE; |
3f659fd6 | 99 | } |
c801d85f | 100 | |
ed58dbea | 101 | wxString wxStaticText::GetLabel() const |
c801d85f | 102 | { |
a93109d5 RR |
103 | char *str = (char *) NULL; |
104 | gtk_label_get( GTK_LABEL(m_widget), &str ); | |
b58197f2 VZ |
105 | |
106 | return wxString(str); | |
3f659fd6 | 107 | } |
c801d85f KB |
108 | |
109 | void wxStaticText::SetLabel( const wxString &label ) | |
110 | { | |
a93109d5 | 111 | wxControl::SetLabel(label); |
32c77a71 | 112 | |
9f15c5fe | 113 | gtk_label_set( GTK_LABEL(m_widget), m_label.mbc_str() ); |
b58197f2 VZ |
114 | |
115 | // adjust the label size to the new label | |
116 | ||
117 | // TODO there should be a way to prevent SetLabel() from doing it (an | |
118 | // additional parameter?) | |
119 | GtkRequisition req; | |
120 | (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req ); | |
121 | ||
122 | SetSize( req.width, req.height ); | |
123 | } | |
58614078 RR |
124 | |
125 | void wxStaticText::ApplyWidgetStyle() | |
126 | { | |
a93109d5 RR |
127 | SetWidgetStyle(); |
128 | gtk_widget_set_style( m_widget, m_widgetStyle ); | |
58614078 | 129 | } |
b58197f2 | 130 |