]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/stattext.cpp
only one of SetSize()s, SetClientSize()s, GetPosition()s &c is virtual now
[wxWidgets.git] / src / gtk1 / stattext.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: stattext.cpp
3// Purpose:
4// Author: Robert Roebling
a81258be
RR
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
c801d85f
KB
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
21IMPLEMENT_DYNAMIC_CLASS(wxStaticText,wxControl)
22
23wxStaticText::wxStaticText(void)
24{
3f659fd6 25}
c801d85f
KB
26
27wxStaticText::wxStaticText( wxWindow *parent, wxWindowID id, const wxString &label,
28 const wxPoint &pos, const wxSize &size,
debe6624 29 long style, const wxString &name )
c801d85f
KB
30{
31 Create( parent, id, label, pos, size, style, name );
3f659fd6 32}
c801d85f
KB
33
34bool wxStaticText::Create( wxWindow *parent, wxWindowID id, const wxString &label,
35 const wxPoint &pos, const wxSize &size,
debe6624 36 long style, const wxString &name )
c801d85f
KB
37{
38 m_needParent = TRUE;
39
40 wxSize newSize = size;
41
42 PreCreation( parent, id, pos, size, style, name );
43
32c77a71
VZ
44 wxControl::SetLabel(label);
45 m_widget = gtk_label_new( m_label );
46
604a1783
VZ
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);
c801d85f 55
94bd2ede 56 int y = 1;
7bce6aec
RR
57 if (newSize.x == -1)
58 {
94bd2ede
RR
59 char *s = WXSTRINGCAST m_label;
60 char *nl = strchr(s, '\n');
7bce6aec
RR
61 if (nl)
62 {
63 do
64 {
94bd2ede 65 *nl = 0;
7bce6aec
RR
66 int x = gdk_string_measure( m_widget->style->font, s ) + 4;
67 if (x > newSize.x) newSize.x = x;
94bd2ede 68 *nl++ = '\n';
92976ab6
RR
69 ++y;
70 if (! (nl = strchr(s = nl, '\n')))
71 {
72
7bce6aec
RR
73 int x = gdk_string_measure( m_widget->style->font, s ) + 4;
74 if (x > newSize.x) newSize.x = x;
94bd2ede
RR
75 }
76 } while (nl);
7bce6aec
RR
77 }
78 else
79 {
80 newSize.x = gdk_string_measure( m_widget->style->font, label ) + 4;
94bd2ede
RR
81 }
82 }
7bce6aec
RR
83 if (newSize.y == -1)
84 {
85 if (y == 1)
94bd2ede 86 newSize.y = 26;
7bce6aec 87 else
92976ab6 88 newSize.y = 4 + y * (m_widget->style->font->ascent + m_widget->style->font->descent + 2);
94bd2ede
RR
89 }
90
c801d85f
KB
91 SetSize( newSize.x, newSize.y );
92
6ca41e57
RR
93 m_parent->AddChild( this );
94
95 (m_parent->m_insertCallback)( m_parent, this );
96
c801d85f
KB
97 PostCreation();
98
58614078
RR
99 SetBackgroundColour( parent->GetBackgroundColour() );
100 SetForegroundColour( parent->GetForegroundColour() );
101
c801d85f
KB
102 Show( TRUE );
103
104 return TRUE;
3f659fd6 105}
c801d85f
KB
106
107wxString wxStaticText::GetLabel(void) const
108{
c67daf87 109 char *str = (char *) NULL;
c801d85f
KB
110 gtk_label_get( GTK_LABEL(m_widget), &str );
111 wxString tmp( str );
112 return tmp;
3f659fd6 113}
c801d85f
KB
114
115void wxStaticText::SetLabel( const wxString &label )
116{
32c77a71
VZ
117 wxControl::SetLabel(label);
118
119 gtk_label_set( GTK_LABEL(m_widget), m_label );
3f659fd6 120}
58614078
RR
121
122void wxStaticText::ApplyWidgetStyle()
123{
124 SetWidgetStyle();
125 gtk_widget_set_style( m_widget, m_widgetStyle );
126}
127