]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/stattext.cpp
BC++ 5.x also supports _beginthreadex and _endthreadex
[wxWidgets.git] / src / gtk1 / 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 if (!PreCreation( parent, pos, size ) ||
52 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
53 {
54 wxFAIL_MSG( wxT("wxXX creation failed") );
55 return FALSE;
56 }
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
62 wxControl::SetLabel(label);
63 m_widget = gtk_label_new( m_label.mbc_str() );
64
65 wxControl::SetFont( parent->GetFont() );
66
67 GtkJustification justify;
68 if ( style & wxALIGN_CENTER )
69 justify = GTK_JUSTIFY_CENTER;
70 else if ( style & wxALIGN_RIGHT )
71 justify = GTK_JUSTIFY_RIGHT;
72 else // wxALIGN_LEFT is 0
73 justify = GTK_JUSTIFY_LEFT;
74 gtk_label_set_justify(GTK_LABEL(m_widget), justify);
75
76 // GTK_JUSTIFY_LEFT is 0, RIGHT 1 and CENTER 2
77 static const float labelAlignments[] = { 0.0, 1.0, 0.5 };
78 gtk_misc_set_alignment(GTK_MISC(m_widget), labelAlignments[justify], 0.0);
79
80 // do not move this call elsewhere
81 gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE );
82
83 SetSizeOrDefault( size );
84
85 m_parent->DoAddChild( this );
86
87 PostCreation();
88
89 SetBackgroundColour( parent->GetBackgroundColour() );
90 SetForegroundColour( parent->GetForegroundColour() );
91 Show( TRUE );
92
93 return TRUE;
94 }
95
96 wxString wxStaticText::GetLabel() const
97 {
98 char *str = (char *) NULL;
99 gtk_label_get( GTK_LABEL(m_widget), &str );
100
101 return wxString(str);
102 }
103
104 void wxStaticText::SetLabel( const wxString &label )
105 {
106 wxControl::SetLabel(label);
107
108 gtk_label_set( GTK_LABEL(m_widget), m_label.mbc_str() );
109
110 // adjust the label size to the new label unless disabled
111 if (!HasFlag(wxST_NO_AUTORESIZE))
112 SetSize( GetBestSize() );
113 }
114
115 bool wxStaticText::SetFont( const wxFont &font )
116 {
117 bool ret = wxControl::SetFont(font);
118
119 // adjust the label size to the new label unless disabled
120 if (!HasFlag(wxST_NO_AUTORESIZE))
121 SetSize( GetBestSize() );
122
123 return ret;
124 }
125
126 void wxStaticText::ApplyWidgetStyle()
127 {
128 SetWidgetStyle();
129 gtk_widget_set_style( m_widget, m_widgetStyle );
130 }
131
132 wxSize wxStaticText::DoGetBestSize() const
133 {
134 // Do not return any arbitrary default value...
135 wxASSERT_MSG( m_widget, wxT("wxStaticText::DoGetBestSize called before creation") );
136
137 // this invalidates the size request
138 gtk_label_set_line_wrap( GTK_LABEL(m_widget), TRUE );
139 gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE );
140
141 GtkRequisition req;
142 req.width = 2;
143 req.height = 2;
144 (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request )
145 (m_widget, &req );
146
147 return wxSize(req.width, req.height);
148 }
149