]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/statbox.cpp
compilation fix for PCH-less builds
[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);
357b1b52 81 // only base SetLabel needs to be called after GTKCreateFrame
2e1f5012 82 wxControl::SetLabel(label);
904f68c7 83
f03fc89f 84 m_parent->DoAddChild( this );
1e6feb95 85
abdeb9e7 86 PostCreation(size);
db434467 87
4d23a4bf 88 // need to set non default alignment?
357b1b52 89 gfloat xalign = 0;
4d23a4bf
VZ
90 if ( style & wxALIGN_CENTER )
91 xalign = 0.5;
92 else if ( style & wxALIGN_RIGHT )
93 xalign = 1.0;
58614078 94
357b1b52 95 gtk_frame_set_label_align(GTK_FRAME(m_widget), xalign, 0.5);
0154a297 96
357b1b52
PC
97 if (gtk_check_version(2, 12, 0))
98 {
99 // for clipping label as GTK >= 2.12 does
100 g_signal_connect(m_widget, "size_allocate",
101 G_CALLBACK(size_allocate), NULL);
102 }
34a0dc61 103
357b1b52 104 return true;
3f659fd6 105}
d3904ceb 106
b2ff89d6 107void wxStaticBox::SetLabel( const wxString& label )
d3904ceb 108{
b2ff89d6 109 wxCHECK_RET( m_widget != NULL, wxT("invalid staticbox") );
4d23a4bf 110
b2ff89d6 111 GTKSetLabelForFrame(GTK_FRAME(m_widget), label);
d3904ceb 112}
58614078 113
7545e132 114void wxStaticBox::DoApplyWidgetStyle(GtkRcStyle *style)
e3716844 115{
2e1f5012
VZ
116 GTKFrameApplyWidgetStyle(GTK_FRAME(m_widget), style);
117}
118
119bool wxStaticBox::GTKWidgetNeedsMnemonic() const
120{
121 return true;
122}
123
124void wxStaticBox::GTKWidgetDoSetMnemonic(GtkWidget* w)
125{
126 GTKFrameSetMnemonicWidget(GTK_FRAME(m_widget), w);
e3716844
RR
127}
128
9d522606
RD
129// static
130wxVisualAttributes
131wxStaticBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
132{
133 return GetDefaultAttributesFromGTKWidget(gtk_frame_new);
134}
135
c1f50b06
RD
136
137void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const
138{
139 const int BORDER = 5; // FIXME: hardcoded value
140
141 *borderTop = GetLabel().empty() ? 2*BORDER : GetCharHeight();
142 *borderOther = BORDER;
143}
144
1e6feb95 145#endif // wxUSE_STATBOX