]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/statbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/statbox.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
15 #include "wx/statbox.h"
16 #include "wx/gtk/private/win_gtk.h" // for wxPizza
20 // constants taken from GTK sources
22 #define LABEL_SIDE_PAD 2
24 //-----------------------------------------------------------------------------
25 // "size_allocate" from m_widget
26 //-----------------------------------------------------------------------------
29 static void size_allocate(GtkWidget
* widget
, GtkAllocation
* alloc
, void*)
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
;
38 if (label_widget
->allocation
.width
> w
)
40 GtkAllocation alloc2
= label_widget
->allocation
;
42 gtk_widget_size_allocate(label_widget
, &alloc2
);
47 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
51 wxStaticBox::wxStaticBox()
55 wxStaticBox::wxStaticBox( wxWindow
*parent
,
57 const wxString
&label
,
61 const wxString
& name
)
63 Create( parent
, id
, label
, pos
, size
, style
, name
);
66 bool wxStaticBox::Create( wxWindow
*parent
,
68 const wxString
& label
,
72 const wxString
& name
)
74 if (!PreCreation( parent
, pos
, size
) ||
75 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
77 wxFAIL_MSG( wxT("wxStaticBox creation failed") );
81 m_widget
= GTKCreateFrame(label
);
82 g_object_ref(m_widget
);
84 // only base SetLabel needs to be called after GTKCreateFrame
85 wxControl::SetLabel(label
);
87 m_parent
->DoAddChild( this );
91 // need to set non default alignment?
93 if ( style
& wxALIGN_CENTER
)
95 else if ( style
& wxALIGN_RIGHT
)
98 gtk_frame_set_label_align(GTK_FRAME(m_widget
), xalign
, 0.5);
100 if (gtk_check_version(2, 12, 0))
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
);
109 void wxStaticBox::AddChild( wxWindowBase
*child
)
113 // make this window a container of other wxWindows by instancing a wxPizza
114 // and packing it into the GtkFrame:
115 m_wxwindow
= wxPizza::New();
116 gtk_widget_show( m_wxwindow
);
117 gtk_container_add( GTK_CONTAINER (m_widget
), m_wxwindow
);
120 wxWindow::AddChild( child
);
123 void wxStaticBox::SetLabel( const wxString
& label
)
125 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid staticbox") );
127 GTKSetLabelForFrame(GTK_FRAME(m_widget
), label
);
130 void wxStaticBox::DoApplyWidgetStyle(GtkRcStyle
*style
)
132 GTKFrameApplyWidgetStyle(GTK_FRAME(m_widget
), style
);
135 bool wxStaticBox::GTKWidgetNeedsMnemonic() const
140 void wxStaticBox::GTKWidgetDoSetMnemonic(GtkWidget
* w
)
142 GTKFrameSetMnemonicWidget(GTK_FRAME(m_widget
), w
);
147 wxStaticBox::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
149 return GetDefaultAttributesFromGTKWidget(gtk_frame_new
);
153 void wxStaticBox::GetBordersForSizer(int *borderTop
, int *borderOther
) const
155 const int BORDER
= 5; // FIXME: hardcoded value
157 *borderTop
= GetLabel().empty() ? 2*BORDER
: GetCharHeight();
158 *borderOther
= BORDER
;
161 #endif // wxUSE_STATBOX