]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/stattext.cpp
image handlers moved to separate headers (imagbmp.h etc.) This change is backward...
[wxWidgets.git] / src / gtk1 / stattext.cpp
... / ...
CommitLineData
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
24IMPLEMENT_DYNAMIC_CLASS(wxStaticText,wxControl)
25
26wxStaticText::wxStaticText()
27{
28}
29
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)
37{
38 Create( parent, id, label, pos, size, style, name );
39}
40
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 )
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 gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE );
66
67 SetFont( parent->GetFont() );
68
69 GtkJustification justify;
70 if ( style & wxALIGN_CENTER )
71 justify = GTK_JUSTIFY_CENTER;
72 else if ( style & wxALIGN_RIGHT )
73 justify = GTK_JUSTIFY_RIGHT;
74 else // wxALIGN_LEFT is 0
75 justify = GTK_JUSTIFY_LEFT;
76 gtk_label_set_justify(GTK_LABEL(m_widget), justify);
77
78 // GTK_JUSTIFY_LEFT is 0, RIGHT 1 and CENTER 2
79 static const float labelAlignments[] = { 0.0, 1.0, 0.5 };
80 gtk_misc_set_alignment(GTK_MISC(m_widget), labelAlignments[justify], 0.0);
81
82 SetSizeOrDefault( size );
83
84 m_parent->DoAddChild( this );
85
86 PostCreation();
87
88 SetBackgroundColour( parent->GetBackgroundColour() );
89 SetForegroundColour( parent->GetForegroundColour() );
90 Show( TRUE );
91
92 return TRUE;
93}
94
95wxString wxStaticText::GetLabel() const
96{
97 char *str = (char *) NULL;
98 gtk_label_get( GTK_LABEL(m_widget), &str );
99
100 return wxString(str);
101}
102
103void wxStaticText::SetLabel( const wxString &label )
104{
105 wxControl::SetLabel(label);
106
107 gtk_label_set( GTK_LABEL(m_widget), m_label.mbc_str() );
108
109 // adjust the label size to the new label unless disabled
110 if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
111 {
112 SetSize( GetBestSize() );
113 }
114}
115
116void wxStaticText::ApplyWidgetStyle()
117{
118 SetWidgetStyle();
119 gtk_widget_set_style( m_widget, m_widgetStyle );
120}