]>
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"
19 // constants taken from GTK sources
21 #define LABEL_SIDE_PAD 2
23 //-----------------------------------------------------------------------------
24 // "size_allocate" from m_widget
25 //-----------------------------------------------------------------------------
28 static void size_allocate(GtkWidget
* widget
, GtkAllocation
* alloc
, void*)
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
;
35 if (label_widget
->allocation
.width
> w
)
37 GtkAllocation alloc2
= label_widget
->allocation
;
39 gtk_widget_size_allocate(label_widget
, &alloc2
);
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
48 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox
, wxControl
)
50 wxStaticBox::wxStaticBox()
54 wxStaticBox::wxStaticBox( wxWindow
*parent
,
56 const wxString
&label
,
60 const wxString
& name
)
62 Create( parent
, id
, label
, pos
, size
, style
, name
);
65 bool wxStaticBox::Create( wxWindow
*parent
,
67 const wxString
& label
,
71 const wxString
& name
)
73 if (!PreCreation( parent
, pos
, size
) ||
74 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
76 wxFAIL_MSG( wxT("wxStaticBox creation failed") );
80 m_widget
= GTKCreateFrame(label
);
81 g_object_ref(m_widget
);
82 // only base SetLabel needs to be called after GTKCreateFrame
83 wxControl::SetLabel(label
);
85 m_parent
->DoAddChild( this );
89 // need to set non default alignment?
91 if ( style
& wxALIGN_CENTER
)
93 else if ( style
& wxALIGN_RIGHT
)
96 gtk_frame_set_label_align(GTK_FRAME(m_widget
), xalign
, 0.5);
98 if (gtk_check_version(2, 12, 0))
100 // for clipping label as GTK >= 2.12 does
101 g_signal_connect(m_widget
, "size_allocate",
102 G_CALLBACK(size_allocate
), NULL
);
108 void wxStaticBox::SetLabel( const wxString
& label
)
110 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid staticbox") );
112 GTKSetLabelForFrame(GTK_FRAME(m_widget
), label
);
115 void wxStaticBox::DoApplyWidgetStyle(GtkRcStyle
*style
)
117 GTKFrameApplyWidgetStyle(GTK_FRAME(m_widget
), style
);
120 bool wxStaticBox::GTKWidgetNeedsMnemonic() const
125 void wxStaticBox::GTKWidgetDoSetMnemonic(GtkWidget
* w
)
127 GTKFrameSetMnemonicWidget(GTK_FRAME(m_widget
), w
);
132 wxStaticBox::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
134 return GetDefaultAttributesFromGTKWidget(gtk_frame_new
);
138 void wxStaticBox::GetBordersForSizer(int *borderTop
, int *borderOther
) const
140 const int BORDER
= 5; // FIXME: hardcoded value
142 *borderTop
= GetLabel().empty() ? 2*BORDER
: GetCharHeight();
143 *borderOther
= BORDER
;
146 #endif // wxUSE_STATBOX