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