]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/stattext.cpp
wxArrayEditorDialog now uses wxEditableListBox. It has also been renamed to wxPGArray...
[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
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
1e6feb95
VZ
12
13#if wxUSE_STATTEXT
14
c801d85f 15#include "wx/stattext.h"
3cbab641 16#include "wx/gtk1/private.h"
c801d85f 17
83624f79
RR
18#include "gdk/gdk.h"
19#include "gtk/gtk.h"
20
e1f448ee
VZ
21extern "C"
22void wxgtk_window_size_request_callback(GtkWidget *widget,
23 GtkRequisition *requisition,
24 wxWindow *win);
25
c801d85f
KB
26//-----------------------------------------------------------------------------
27// wxStaticText
28//-----------------------------------------------------------------------------
29
30IMPLEMENT_DYNAMIC_CLASS(wxStaticText,wxControl)
31
b58197f2 32wxStaticText::wxStaticText()
c801d85f 33{
3f659fd6 34}
c801d85f 35
b58197f2
VZ
36wxStaticText::wxStaticText(wxWindow *parent,
37 wxWindowID id,
38 const wxString &label,
39 const wxPoint &pos,
40 const wxSize &size,
41 long style,
42 const wxString &name)
c801d85f
KB
43{
44 Create( parent, id, label, pos, size, style, name );
3f659fd6 45}
c801d85f 46
b58197f2
VZ
47bool wxStaticText::Create(wxWindow *parent,
48 wxWindowID id,
49 const wxString &label,
50 const wxPoint &pos,
51 const wxSize &size,
52 long style,
53 const wxString &name )
c801d85f 54{
a93109d5 55 m_needParent = TRUE;
b58197f2 56
4dcaf11a
RR
57 if (!PreCreation( parent, pos, size ) ||
58 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
59 {
8ccac798 60 wxFAIL_MSG( wxT("wxStaticText creation failed") );
185fa6bf 61 return FALSE;
4dcaf11a 62 }
b58197f2 63
2ce89389
VZ
64 m_label = label;
65 m_widget = gtk_label_new( wxGTK_CONV( GTKRemoveMnemonics(label)) );
3d257b8d 66
a93109d5
RR
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);
1a5594b8 75
1a5594b8
VZ
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);
185fa6bf 79
a5040b80 80 gtk_label_set_line_wrap( GTK_LABEL(m_widget), TRUE );
33720b2d 81
f03fc89f 82 m_parent->DoAddChild( this );
b58197f2 83
abdeb9e7 84 PostCreation(size);
3d257b8d 85
a93109d5 86 return TRUE;
3f659fd6 87}
c801d85f 88
ed58dbea 89wxString wxStaticText::GetLabel() const
c801d85f 90{
3b2e67f6 91 GtkLabel *label = GTK_LABEL(m_widget);
3b2e67f6 92 wxString str = wxString( label->label );
b58197f2 93 return wxString(str);
3f659fd6 94}
c801d85f
KB
95
96void wxStaticText::SetLabel( const wxString &label )
97{
2ce89389 98 wxCHECK_RET( m_widget != NULL, wxT("invalid static text") );
8ccac798 99
2ce89389 100 GTKSetLabelForLabel(GTK_LABEL(m_widget), label);
c0e6c051
RD
101
102 // adjust the label size to the new label unless disabled
103 if (!HasFlag(wxST_NO_AUTORESIZE))
c0e6c051 104 SetSize( GetBestSize() );
33720b2d
RR
105}
106
c0e6c051
RD
107bool wxStaticText::SetFont( const wxFont &font )
108{
109 bool ret = wxControl::SetFont(font);
110
111 // adjust the label size to the new label unless disabled
112 if (!HasFlag(wxST_NO_AUTORESIZE))
113 {
9f884528 114 InvalidateBestSize();
c0e6c051 115 SetSize( GetBestSize() );
c0e6c051
RD
116 }
117 return ret;
118}
58614078 119
a5040b80
RR
120void wxStaticText::DoSetSize(int x, int y,
121 int width, int height,
122 int sizeFlags )
123{
124 wxControl::DoSetSize( x, y, width, height, sizeFlags );
125}
126
33720b2d
RR
127wxSize wxStaticText::DoGetBestSize() const
128{
129 // Do not return any arbitrary default value...
130 wxASSERT_MSG( m_widget, wxT("wxStaticText::DoGetBestSize called before creation") );
131
088ddc4e
RR
132 // This resets the internal GTK1 size calculation, which
133 // otherwise would be cashed (incorrectly)
a5040b80 134 gtk_label_set_pattern( GTK_LABEL(m_widget), NULL );
088ddc4e
RR
135
136 // GetBestSize is supposed to return unwrapped size
137 gtk_label_set_line_wrap( GTK_LABEL(m_widget), FALSE );
3d257b8d 138
33720b2d 139 GtkRequisition req;
a5040b80
RR
140 req.width = -1;
141 req.height = -1;
2afa14f2 142 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request )
33720b2d
RR
143 (m_widget, &req );
144
088ddc4e 145 gtk_label_set_line_wrap( GTK_LABEL(m_widget), TRUE );
3d257b8d 146
a5040b80 147 return wxSize (req.width, req.height);
33720b2d
RR
148}
149
174b10af
RR
150bool wxStaticText::SetForegroundColour(const wxColour& colour)
151{
152 // First, we call the base class member
153 wxControl::SetForegroundColour(colour);
154 // Then, to force the color change, we set the label with the current label
155 SetLabel(GetLabel());
156 return true;
157}
158
9d522606
RD
159// static
160wxVisualAttributes
161wxStaticText::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
162{
163 return GetDefaultAttributesFromGTKWidget(gtk_label_new);
164}
165
1e6feb95 166#endif // wxUSE_STATTEXT