]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/statbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/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"
18 #include "wx/gtk/private/gtk2-compat.h"
19 #include "wx/gtk/private/win_gtk.h"
21 // constants taken from GTK sources
23 #define LABEL_SIDE_PAD 2
25 //-----------------------------------------------------------------------------
26 // "size_allocate" from m_widget
27 //-----------------------------------------------------------------------------
31 static void size_allocate(GtkWidget
* widget
, GtkAllocation
* alloc
, void*)
33 // clip label as GTK >= 2.12 does
34 GtkWidget
* label_widget
= gtk_frame_get_label_widget(GTK_FRAME(widget
));
35 int w
= alloc
->width
-
36 2 * gtk_widget_get_style(widget
)->xthickness
- 2 * LABEL_PAD
- 2 * LABEL_SIDE_PAD
;
41 gtk_widget_get_allocation(label_widget
, &a
);
45 gtk_widget_size_allocate(label_widget
, &a
);
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 wxStaticBox::wxStaticBox()
59 wxStaticBox::wxStaticBox( wxWindow
*parent
,
61 const wxString
&label
,
65 const wxString
& name
)
67 Create( parent
, id
, label
, pos
, size
, style
, name
);
70 bool wxStaticBox::Create( wxWindow
*parent
,
72 const wxString
& label
,
76 const wxString
& name
)
78 if (!PreCreation( parent
, pos
, size
) ||
79 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
81 wxFAIL_MSG( wxT("wxStaticBox creation failed") );
85 m_widget
= GTKCreateFrame(label
);
86 g_object_ref(m_widget
);
88 // only base SetLabel needs to be called after GTKCreateFrame
89 wxControl::SetLabel(label
);
91 m_parent
->DoAddChild( this );
95 // need to set non default alignment?
97 if ( style
& wxALIGN_CENTER
)
99 else if ( style
& wxALIGN_RIGHT
)
102 gtk_frame_set_label_align(GTK_FRAME(m_widget
), xalign
, 0.5);
105 if (gtk_check_version(2, 12, 0))
107 // we connect this signal to perform label-clipping as GTK >= 2.12 does
108 g_signal_connect(m_widget
, "size_allocate", G_CALLBACK(size_allocate
), NULL
);
115 void wxStaticBox::AddChild( wxWindowBase
*child
)
119 // make this window a container of other wxWindows by instancing a wxPizza
120 // and packing it into the GtkFrame:
121 m_wxwindow
= wxPizza::New();
122 gtk_widget_show( m_wxwindow
);
123 gtk_container_add( GTK_CONTAINER (m_widget
), m_wxwindow
);
126 wxWindow::AddChild( child
);
129 void wxStaticBox::SetLabel( const wxString
& label
)
131 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid staticbox") );
133 GTKSetLabelForFrame(GTK_FRAME(m_widget
), label
);
136 void wxStaticBox::DoApplyWidgetStyle(GtkRcStyle
*style
)
138 GTKFrameApplyWidgetStyle(GTK_FRAME(m_widget
), style
);
141 bool wxStaticBox::GTKWidgetNeedsMnemonic() const
146 void wxStaticBox::GTKWidgetDoSetMnemonic(GtkWidget
* w
)
148 GTKFrameSetMnemonicWidget(GTK_FRAME(m_widget
), w
);
153 wxStaticBox::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
155 return GetDefaultAttributesFromGTKWidget(gtk_frame_new
);
159 void wxStaticBox::GetBordersForSizer(int *borderTop
, int *borderOther
) const
161 *borderTop
= GetCharHeight();
162 *borderOther
= GetCharWidth()/2;
165 #endif // wxUSE_STATBOX