]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/statbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/statbox.cpp
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
14 #include "wx/statbox.h"
17 #include "wx/gtk/private/gtk2-compat.h"
18 #include "wx/gtk/private/win_gtk.h"
20 // constants taken from GTK sources
22 #define LABEL_SIDE_PAD 2
24 //-----------------------------------------------------------------------------
25 // "size_allocate" from m_widget
26 //-----------------------------------------------------------------------------
30 static void size_allocate(GtkWidget
* widget
, GtkAllocation
* alloc
, void*)
32 // clip label as GTK >= 2.12 does
33 GtkWidget
* label_widget
= gtk_frame_get_label_widget(GTK_FRAME(widget
));
34 int w
= alloc
->width
-
35 2 * gtk_widget_get_style(widget
)->xthickness
- 2 * LABEL_PAD
- 2 * LABEL_SIDE_PAD
;
40 gtk_widget_get_allocation(label_widget
, &a
);
44 gtk_widget_size_allocate(label_widget
, &a
);
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 wxStaticBox::wxStaticBox()
58 wxStaticBox::wxStaticBox( wxWindow
*parent
,
60 const wxString
&label
,
64 const wxString
& name
)
66 Create( parent
, id
, label
, pos
, size
, style
, name
);
69 bool wxStaticBox::Create( wxWindow
*parent
,
71 const wxString
& label
,
75 const wxString
& name
)
77 if (!PreCreation( parent
, pos
, size
) ||
78 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
80 wxFAIL_MSG( wxT("wxStaticBox creation failed") );
84 m_widget
= GTKCreateFrame(label
);
85 g_object_ref(m_widget
);
87 // only base SetLabel needs to be called after GTKCreateFrame
88 wxControl::SetLabel(label
);
90 m_parent
->DoAddChild( this );
94 // need to set non default alignment?
96 if ( style
& wxALIGN_CENTER
)
98 else if ( style
& wxALIGN_RIGHT
)
101 gtk_frame_set_label_align(GTK_FRAME(m_widget
), xalign
, 0.5);
104 if (gtk_check_version(2, 12, 0))
106 // we connect this signal to perform label-clipping as GTK >= 2.12 does
107 g_signal_connect(m_widget
, "size_allocate", G_CALLBACK(size_allocate
), NULL
);
111 m_container
.DisableSelfFocus();
116 void wxStaticBox::AddChild( wxWindowBase
*child
)
120 // make this window a container of other wxWindows by instancing a wxPizza
121 // and packing it into the GtkFrame:
122 m_wxwindow
= wxPizza::New();
123 gtk_widget_show( m_wxwindow
);
124 gtk_container_add( GTK_CONTAINER (m_widget
), m_wxwindow
);
127 wxStaticBoxBase::AddChild(child
);
130 void wxStaticBox::SetLabel( const wxString
& label
)
132 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid staticbox") );
134 GTKSetLabelForFrame(GTK_FRAME(m_widget
), label
);
137 void wxStaticBox::DoApplyWidgetStyle(GtkRcStyle
*style
)
139 GTKFrameApplyWidgetStyle(GTK_FRAME(m_widget
), style
);
142 bool wxStaticBox::GTKWidgetNeedsMnemonic() const
147 void wxStaticBox::GTKWidgetDoSetMnemonic(GtkWidget
* w
)
149 GTKFrameSetMnemonicWidget(GTK_FRAME(m_widget
), w
);
154 wxStaticBox::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
156 return GetDefaultAttributesFromGTKWidget(gtk_frame_new(""));
159 void wxStaticBox::GetBordersForSizer(int *borderTop
, int *borderOther
) const
161 *borderTop
= GetCharHeight();
162 *borderOther
= GetCharWidth()/2;
165 #endif // wxUSE_STATBOX