]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/stattext.cpp
unnecessary ClipRects
[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
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
24IMPLEMENT_DYNAMIC_CLASS(wxStaticText,wxControl)
25
b58197f2 26wxStaticText::wxStaticText()
c801d85f 27{
3f659fd6 28}
c801d85f 29
b58197f2
VZ
30wxStaticText::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
41bool 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
4dcaf11a
RR
51 if (!PreCreation( parent, pos, size ) ||
52 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
53 {
223d09f6 54 wxFAIL_MSG( wxT("wxXX creation failed") );
185fa6bf 55 return FALSE;
4dcaf11a 56 }
b58197f2
VZ
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
a93109d5 62 wxControl::SetLabel(label);
9f15c5fe 63 m_widget = gtk_label_new( m_label.mbc_str() );
97d7bfb8 64
a93109d5
RR
65 GtkJustification justify;
66 if ( style & wxALIGN_CENTER )
67 justify = GTK_JUSTIFY_CENTER;
68 else if ( style & wxALIGN_RIGHT )
69 justify = GTK_JUSTIFY_RIGHT;
70 else // wxALIGN_LEFT is 0
71 justify = GTK_JUSTIFY_LEFT;
72 gtk_label_set_justify(GTK_LABEL(m_widget), justify);
1a5594b8 73
1a5594b8
VZ
74 // GTK_JUSTIFY_LEFT is 0, RIGHT 1 and CENTER 2
75 static const float labelAlignments[] = { 0.0, 1.0, 0.5 };
76 gtk_misc_set_alignment(GTK_MISC(m_widget), labelAlignments[justify], 0.0);
185fa6bf 77
33720b2d
RR
78 // do not move this call elsewhere
79 gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE );
80
f03fc89f 81 m_parent->DoAddChild( this );
b58197f2 82
a93109d5 83 PostCreation();
7e2b55cd
RR
84
85 ApplyWidgetStyle();
b58197f2 86
db434467
RR
87 wxControl::SetFont( parent->GetFont() );
88
89 wxSize size_best( DoGetBestSize() );
90 wxSize new_size( size );
91 if (new_size.x == -1)
92 new_size.x = size_best.x;
93 if (new_size.y == -1)
94 new_size.y = size_best.y;
95 if ((new_size.x != size.x) || (new_size.y != size.y))
96 SetSize( new_size.x, new_size.y );
97
a93109d5
RR
98 SetBackgroundColour( parent->GetBackgroundColour() );
99 SetForegroundColour( parent->GetForegroundColour() );
a93109d5 100 Show( TRUE );
b58197f2 101
a93109d5 102 return TRUE;
3f659fd6 103}
c801d85f 104
ed58dbea 105wxString wxStaticText::GetLabel() const
c801d85f 106{
a93109d5
RR
107 char *str = (char *) NULL;
108 gtk_label_get( GTK_LABEL(m_widget), &str );
b58197f2
VZ
109
110 return wxString(str);
3f659fd6 111}
c801d85f
KB
112
113void wxStaticText::SetLabel( const wxString &label )
114{
a93109d5 115 wxControl::SetLabel(label);
32c77a71 116
9f15c5fe 117 gtk_label_set( GTK_LABEL(m_widget), m_label.mbc_str() );
b58197f2 118
185fa6bf 119 // adjust the label size to the new label unless disabled
33720b2d 120 if (!HasFlag(wxST_NO_AUTORESIZE))
f68586e5 121 SetSize( GetBestSize() );
33720b2d
RR
122}
123
124bool wxStaticText::SetFont( const wxFont &font )
125{
126 bool ret = wxControl::SetFont(font);
127
128 // adjust the label size to the new label unless disabled
129 if (!HasFlag(wxST_NO_AUTORESIZE))
130 SetSize( GetBestSize() );
131
132 return ret;
b58197f2 133}
58614078
RR
134
135void wxStaticText::ApplyWidgetStyle()
136{
a93109d5
RR
137 SetWidgetStyle();
138 gtk_widget_set_style( m_widget, m_widgetStyle );
58614078 139}
33720b2d
RR
140
141wxSize wxStaticText::DoGetBestSize() const
142{
143 // Do not return any arbitrary default value...
144 wxASSERT_MSG( m_widget, wxT("wxStaticText::DoGetBestSize called before creation") );
145
146 // this invalidates the size request
147 gtk_label_set_line_wrap( GTK_LABEL(m_widget), TRUE );
148 gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE );
149
150 GtkRequisition req;
151 req.width = 2;
152 req.height = 2;
2afa14f2 153 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request )
33720b2d
RR
154 (m_widget, &req );
155
156 return wxSize(req.width, req.height);
157}
158