]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/stattext.cpp
1. wxNotebook::GetPageCount() returns only the number of pages actually added
[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 //-----------------------------------------------------------------------------
18 // wxStaticText
19 //-----------------------------------------------------------------------------
20
21 IMPLEMENT_DYNAMIC_CLASS(wxStaticText,wxControl)
22
23 wxStaticText::wxStaticText(void)
24 {
25 }
26
27 wxStaticText::wxStaticText( wxWindow *parent, wxWindowID id, const wxString &label,
28 const wxPoint &pos, const wxSize &size,
29 long style, const wxString &name )
30 {
31 Create( parent, id, label, pos, size, style, name );
32 }
33
34 bool wxStaticText::Create( wxWindow *parent, wxWindowID id, const wxString &label,
35 const wxPoint &pos, const wxSize &size,
36 long style, const wxString &name )
37 {
38 m_needParent = TRUE;
39
40 wxSize newSize = size;
41
42 PreCreation( parent, id, pos, size, style, name );
43
44 wxControl::SetLabel(label);
45 m_widget = gtk_label_new( m_label );
46
47 GtkJustification justify;
48 if ( style & wxALIGN_CENTER )
49 justify = GTK_JUSTIFY_CENTER;
50 else if ( style & wxALIGN_RIGHT )
51 justify = GTK_JUSTIFY_RIGHT;
52 else // wxALIGN_LEFT is 0
53 justify = GTK_JUSTIFY_LEFT;
54 gtk_label_set_justify(GTK_LABEL(m_widget), justify);
55
56 int y = 1;
57 if (newSize.x == -1)
58 {
59 char *s = WXSTRINGCAST m_label;
60 char *nl = strchr(s, '\n');
61 if (nl)
62 {
63 do
64 {
65 *nl = 0;
66 int x = gdk_string_measure( m_widget->style->font, s ) + 4;
67 if (x > newSize.x) newSize.x = x;
68 *nl++ = '\n';
69 if ((nl = strchr(s = nl, '\n')))
70 {
71 ++y;
72 }
73 else
74 {
75 int x = gdk_string_measure( m_widget->style->font, s ) + 4;
76 if (x > newSize.x) newSize.x = x;
77 }
78 } while (nl);
79 }
80 else
81 {
82 newSize.x = gdk_string_measure( m_widget->style->font, label ) + 4;
83 }
84 }
85 if (newSize.y == -1)
86 {
87 if (y == 1)
88 newSize.y = 26;
89 else
90 newSize.y = 4 + y * (m_widget->style->font->ascent + 2*m_widget->style->font->descent);
91 }
92
93 SetSize( newSize.x, newSize.y );
94
95 m_parent->AddChild( this );
96
97 (m_parent->m_insertCallback)( m_parent, this );
98
99 PostCreation();
100
101 SetBackgroundColour( parent->GetBackgroundColour() );
102 SetForegroundColour( parent->GetForegroundColour() );
103
104 Show( TRUE );
105
106 return TRUE;
107 }
108
109 wxString wxStaticText::GetLabel(void) const
110 {
111 char *str = (char *) NULL;
112 gtk_label_get( GTK_LABEL(m_widget), &str );
113 wxString tmp( str );
114 return tmp;
115 }
116
117 void wxStaticText::SetLabel( const wxString &label )
118 {
119 wxControl::SetLabel(label);
120
121 gtk_label_set( GTK_LABEL(m_widget), m_label );
122 }
123
124 void wxStaticText::ApplyWidgetStyle()
125 {
126 SetWidgetStyle();
127 gtk_widget_set_style( m_widget, m_widgetStyle );
128 }
129