]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/stattext.cpp
Made wxStubs compile on Unix.
[wxWidgets.git] / src / gtk / stattext.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: stattext.cpp
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11
12#ifdef __GNUG__
13#pragma implementation "stattext.h"
14#endif
15
16#include "wx/stattext.h"
17
18//-----------------------------------------------------------------------------
19// wxStaticText
20//-----------------------------------------------------------------------------
21
22IMPLEMENT_DYNAMIC_CLASS(wxStaticText,wxControl)
23
24wxStaticText::wxStaticText(void)
25{
26}
27
28wxStaticText::wxStaticText( wxWindow *parent, wxWindowID id, const wxString &label,
29 const wxPoint &pos, const wxSize &size,
30 long style, const wxString &name )
31{
32 Create( parent, id, label, pos, size, style, name );
33}
34
35bool wxStaticText::Create( wxWindow *parent, wxWindowID id, const wxString &label,
36 const wxPoint &pos, const wxSize &size,
37 long style, const wxString &name )
38{
39 m_needParent = TRUE;
40
41 wxSize newSize = size;
42
43 PreCreation( parent, id, pos, size, style, name );
44
45 wxControl::SetLabel(label);
46 m_widget = gtk_label_new( m_label );
47
48 GtkJustification justify;
49 if ( style & wxALIGN_CENTER )
50 justify = GTK_JUSTIFY_CENTER;
51 else if ( style & wxALIGN_RIGHT )
52 justify = GTK_JUSTIFY_RIGHT;
53 else // wxALIGN_LEFT is 0
54 justify = GTK_JUSTIFY_LEFT;
55 gtk_label_set_justify(GTK_LABEL(m_widget), justify);
56
57 int y = 1;
58 if (newSize.x == -1) {
59 char *s = WXSTRINGCAST m_label;
60 char *nl = strchr(s, '\n');
61 if (nl) {
62 do {
63 *nl = 0;
64 int x = gdk_string_measure( m_widget->style->font, s );
65 if (x > newSize.x) {
66 newSize.x = x;
67 }
68 *nl++ = '\n';
69 if ((nl = strchr(s = nl, '\n'))) {
70 ++y;
71 } else {
72 int x = gdk_string_measure( m_widget->style->font, s );
73 if (x > newSize.x) {
74 newSize.x = x;
75 }
76 }
77 } while (nl);
78 } else {
79 newSize.x = gdk_string_measure( m_widget->style->font, label );
80 }
81 }
82 if (newSize.y == -1) {
83 if (y == 1) {
84 newSize.y = 26;
85 } else {
86 newSize.y
87 = y * (m_widget->style->font->ascent +m_widget->style->font->descent);
88 }
89 }
90
91 SetSize( newSize.x, newSize.y );
92
93 PostCreation();
94
95 Show( TRUE );
96
97 return TRUE;
98}
99
100wxString wxStaticText::GetLabel(void) const
101{
102 char *str = (char *) NULL;
103 gtk_label_get( GTK_LABEL(m_widget), &str );
104 wxString tmp( str );
105 return tmp;
106}
107
108void wxStaticText::SetLabel( const wxString &label )
109{
110 wxControl::SetLabel(label);
111
112 gtk_label_set( GTK_LABEL(m_widget), m_label );
113}