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