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