]>
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 | |
a93109d5 | 51 | wxSize newSize = size; |
b58197f2 | 52 | |
a93109d5 | 53 | PreCreation( parent, id, pos, size, style, name ); |
b58197f2 VZ |
54 | |
55 | // notice that we call the base class version which will just remove the | |
56 | // '&' characters from the string, but not set the label's text to it | |
57 | // because the label is not yet created and because SetLabel() has a side | |
58 | // effect of changing the control size which might not be desirable | |
a93109d5 RR |
59 | wxControl::SetLabel(label); |
60 | m_widget = gtk_label_new( m_label ); | |
61 | ||
62 | GtkJustification justify; | |
63 | if ( style & wxALIGN_CENTER ) | |
64 | justify = GTK_JUSTIFY_CENTER; | |
65 | else if ( style & wxALIGN_RIGHT ) | |
66 | justify = GTK_JUSTIFY_RIGHT; | |
67 | else // wxALIGN_LEFT is 0 | |
68 | justify = GTK_JUSTIFY_LEFT; | |
69 | gtk_label_set_justify(GTK_LABEL(m_widget), justify); | |
70 | ||
71 | GtkRequisition req; | |
72 | (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req ); | |
b58197f2 | 73 | |
a93109d5 RR |
74 | if (newSize.x == -1) newSize.x = req.width; |
75 | if (newSize.y == -1) newSize.y = req.height; | |
b58197f2 | 76 | |
a93109d5 | 77 | SetSize( newSize.x, newSize.y ); |
b58197f2 | 78 | |
a93109d5 | 79 | m_parent->AddChild( this ); |
6ca41e57 | 80 | |
a93109d5 | 81 | (m_parent->m_insertCallback)( m_parent, this ); |
b58197f2 | 82 | |
a93109d5 | 83 | PostCreation(); |
b58197f2 | 84 | |
a93109d5 RR |
85 | SetBackgroundColour( parent->GetBackgroundColour() ); |
86 | SetForegroundColour( parent->GetForegroundColour() ); | |
a7ac4461 | 87 | SetFont( parent->GetFont() ); |
58614078 | 88 | |
a93109d5 | 89 | Show( TRUE ); |
b58197f2 | 90 | |
a93109d5 | 91 | return TRUE; |
3f659fd6 | 92 | } |
c801d85f KB |
93 | |
94 | wxString wxStaticText::GetLabel(void) const | |
95 | { | |
a93109d5 RR |
96 | char *str = (char *) NULL; |
97 | gtk_label_get( GTK_LABEL(m_widget), &str ); | |
b58197f2 VZ |
98 | |
99 | return wxString(str); | |
3f659fd6 | 100 | } |
c801d85f KB |
101 | |
102 | void wxStaticText::SetLabel( const wxString &label ) | |
103 | { | |
a93109d5 | 104 | wxControl::SetLabel(label); |
32c77a71 | 105 | |
a93109d5 | 106 | gtk_label_set( GTK_LABEL(m_widget), m_label ); |
b58197f2 VZ |
107 | |
108 | // adjust the label size to the new label | |
109 | ||
110 | // TODO there should be a way to prevent SetLabel() from doing it (an | |
111 | // additional parameter?) | |
112 | GtkRequisition req; | |
113 | (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req ); | |
114 | ||
115 | SetSize( req.width, req.height ); | |
116 | } | |
58614078 RR |
117 | |
118 | void wxStaticText::ApplyWidgetStyle() | |
119 | { | |
a93109d5 RR |
120 | SetWidgetStyle(); |
121 | gtk_widget_set_style( m_widget, m_widgetStyle ); | |
58614078 | 122 | } |
b58197f2 | 123 |