]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/stattext.cpp
8185ab3e26f4ad52722fd236e2084df7d457e6a6
[wxWidgets.git] / src / gtk / stattext.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: stattext.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11 #ifdef __GNUG__
12 #pragma implementation "stattext.h"
13 #endif
14
15 #include "wx/stattext.h"
16
17 #include "gdk/gdk.h"
18 #include "gtk/gtk.h"
19
20 //-----------------------------------------------------------------------------
21 // wxStaticText
22 //-----------------------------------------------------------------------------
23
24 IMPLEMENT_DYNAMIC_CLASS(wxStaticText,wxControl)
25
26 wxStaticText::wxStaticText()
27 {
28 }
29
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)
37 {
38 Create( parent, id, label, pos, size, style, name );
39 }
40
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 )
48 {
49 m_needParent = TRUE;
50
51 wxSize newSize = size;
52
53 PreCreation( parent, id, pos, size, style, name );
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
59 wxControl::SetLabel(label);
60 m_widget = gtk_label_new( m_label.mbc_str() );
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 gtk_misc_set_alignment(GTK_MISC(m_widget), 0.0, 0.0);
71
72 GtkRequisition req;
73 (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
74
75 if (newSize.x == -1) newSize.x = req.width;
76 if (newSize.y == -1) newSize.y = req.height;
77
78 SetSize( newSize.x, newSize.y );
79
80 m_parent->DoAddChild( this );
81
82 PostCreation();
83
84 SetBackgroundColour( parent->GetBackgroundColour() );
85 SetForegroundColour( parent->GetForegroundColour() );
86 SetFont( parent->GetFont() );
87
88 Show( TRUE );
89
90 return TRUE;
91 }
92
93 wxString wxStaticText::GetLabel(void) const
94 {
95 char *str = (char *) NULL;
96 gtk_label_get( GTK_LABEL(m_widget), &str );
97
98 return wxString(str);
99 }
100
101 void wxStaticText::SetLabel( const wxString &label )
102 {
103 wxControl::SetLabel(label);
104
105 gtk_label_set( GTK_LABEL(m_widget), m_label.mbc_str() );
106
107 // adjust the label size to the new label
108
109 // TODO there should be a way to prevent SetLabel() from doing it (an
110 // additional parameter?)
111 GtkRequisition req;
112 (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
113
114 SetSize( req.width, req.height );
115 }
116
117 void wxStaticText::ApplyWidgetStyle()
118 {
119 SetWidgetStyle();
120 gtk_widget_set_style( m_widget, m_widgetStyle );
121 }
122