]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/statbox.cpp
Don't use deprecated gtk_widget_ref().
[wxWidgets.git] / src / gtk / statbox.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/gtk/statbox.cpp
c801d85f
KB
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"
c801d85f 12
dcf924a3
RR
13#if wxUSE_STATBOX
14
1e6feb95 15#include "wx/statbox.h"
39cdc95f 16#include "wx/gtk/private/win_gtk.h" // for wxPizza
1e6feb95 17
357b1b52 18#include <gtk/gtk.h>
34a0dc61
VZ
19
20// constants taken from GTK sources
21#define LABEL_PAD 1
22#define LABEL_SIDE_PAD 2
23
24//-----------------------------------------------------------------------------
357b1b52 25// "size_allocate" from m_widget
34a0dc61
VZ
26//-----------------------------------------------------------------------------
27
28extern "C" {
357b1b52 29static void size_allocate(GtkWidget* widget, GtkAllocation* alloc, void*)
34a0dc61 30{
357b1b52
PC
31 // clip label as GTK >= 2.12 does
32 GtkWidget* label_widget = gtk_frame_get_label_widget(GTK_FRAME(widget));
33 int w = alloc->width -
34 2 * widget->style->xthickness - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD;
03647350 35 if (w < 0)
39cdc95f
FM
36 w = 0;
37
357b1b52 38 if (label_widget->allocation.width > w)
34a0dc61 39 {
357b1b52
PC
40 GtkAllocation alloc2 = label_widget->allocation;
41 alloc2.width = w;
42 gtk_widget_size_allocate(label_widget, &alloc2);
34a0dc61
VZ
43 }
44}
34a0dc61
VZ
45}
46
c801d85f
KB
47//-----------------------------------------------------------------------------
48// wxStaticBox
49//-----------------------------------------------------------------------------
50
4d23a4bf 51wxStaticBox::wxStaticBox()
c801d85f 52{
3f659fd6 53}
c801d85f 54
4d23a4bf
VZ
55wxStaticBox::wxStaticBox( wxWindow *parent,
56 wxWindowID id,
57 const wxString &label,
58 const wxPoint& pos,
59 const wxSize& size,
60 long style,
61 const wxString& name )
c801d85f 62{
1ecc4d80 63 Create( parent, id, label, pos, size, style, name );
3f659fd6 64}
c801d85f 65
4d23a4bf
VZ
66bool wxStaticBox::Create( wxWindow *parent,
67 wxWindowID id,
68 const wxString& label,
69 const wxPoint& pos,
70 const wxSize& size,
71 long style,
72 const wxString& name )
c801d85f 73{
4dcaf11a
RR
74 if (!PreCreation( parent, pos, size ) ||
75 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
76 {
223d09f6 77 wxFAIL_MSG( wxT("wxStaticBox creation failed") );
e8375af8 78 return false;
4dcaf11a 79 }
c801d85f 80
2e1f5012 81 m_widget = GTKCreateFrame(label);
9ff9d30c 82 g_object_ref(m_widget);
39cdc95f 83
357b1b52 84 // only base SetLabel needs to be called after GTKCreateFrame
2e1f5012 85 wxControl::SetLabel(label);
904f68c7 86
f03fc89f 87 m_parent->DoAddChild( this );
1e6feb95 88
abdeb9e7 89 PostCreation(size);
db434467 90
4d23a4bf 91 // need to set non default alignment?
357b1b52 92 gfloat xalign = 0;
4d23a4bf
VZ
93 if ( style & wxALIGN_CENTER )
94 xalign = 0.5;
95 else if ( style & wxALIGN_RIGHT )
96 xalign = 1.0;
58614078 97
357b1b52 98 gtk_frame_set_label_align(GTK_FRAME(m_widget), xalign, 0.5);
0154a297 99
357b1b52
PC
100 if (gtk_check_version(2, 12, 0))
101 {
39cdc95f
FM
102 // we connect this signal to perform label-clipping as GTK >= 2.12 does
103 g_signal_connect(m_widget, "size_allocate", G_CALLBACK(size_allocate), NULL);
357b1b52 104 }
34a0dc61 105
357b1b52 106 return true;
3f659fd6 107}
d3904ceb 108
39cdc95f
FM
109void wxStaticBox::AddChild( wxWindowBase *child )
110{
111 if (!m_wxwindow)
112 {
113 // make this window a container of other wxWindows by instancing a wxPizza
114 // and packing it into the GtkFrame:
65391c8f 115 m_wxwindow = wxPizza::New();
39cdc95f
FM
116 gtk_widget_show( m_wxwindow );
117 gtk_container_add( GTK_CONTAINER (m_widget), m_wxwindow );
118 }
119
120 wxWindow::AddChild( child );
121}
122
b2ff89d6 123void wxStaticBox::SetLabel( const wxString& label )
d3904ceb 124{
b2ff89d6 125 wxCHECK_RET( m_widget != NULL, wxT("invalid staticbox") );
4d23a4bf 126
b2ff89d6 127 GTKSetLabelForFrame(GTK_FRAME(m_widget), label);
d3904ceb 128}
58614078 129
7545e132 130void wxStaticBox::DoApplyWidgetStyle(GtkRcStyle *style)
e3716844 131{
2e1f5012
VZ
132 GTKFrameApplyWidgetStyle(GTK_FRAME(m_widget), style);
133}
134
135bool wxStaticBox::GTKWidgetNeedsMnemonic() const
136{
137 return true;
138}
139
140void wxStaticBox::GTKWidgetDoSetMnemonic(GtkWidget* w)
141{
142 GTKFrameSetMnemonicWidget(GTK_FRAME(m_widget), w);
e3716844
RR
143}
144
9d522606
RD
145// static
146wxVisualAttributes
147wxStaticBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
148{
149 return GetDefaultAttributesFromGTKWidget(gtk_frame_new);
150}
151
c1f50b06
RD
152
153void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const
154{
155 const int BORDER = 5; // FIXME: hardcoded value
156
157 *borderTop = GetLabel().empty() ? 2*BORDER : GetCharHeight();
158 *borderOther = BORDER;
159}
160
1e6feb95 161#endif // wxUSE_STATBOX