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