]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/statbox.cpp
Fix deprecating warning introduced in r72446.
[wxWidgets.git] / src / gtk / statbox.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/statbox.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#if wxUSE_STATBOX
14
15#include "wx/statbox.h"
16
17#include <gtk/gtk.h>
18#include "wx/gtk/private/gtk2-compat.h"
19#include "wx/gtk/private/win_gtk.h"
20
21// constants taken from GTK sources
22#define LABEL_PAD 1
23#define LABEL_SIDE_PAD 2
24
25//-----------------------------------------------------------------------------
26// "size_allocate" from m_widget
27//-----------------------------------------------------------------------------
28
29#ifndef __WXGTK3__
30extern "C" {
31static void size_allocate(GtkWidget* widget, GtkAllocation* alloc, void*)
32{
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;
37 if (w < 0)
38 w = 0;
39
40 GtkAllocation a;
41 gtk_widget_get_allocation(label_widget, &a);
42 if (a.width > w)
43 {
44 a.width = w;
45 gtk_widget_size_allocate(label_widget, &a);
46 }
47}
48}
49#endif
50
51//-----------------------------------------------------------------------------
52// wxStaticBox
53//-----------------------------------------------------------------------------
54
55wxStaticBox::wxStaticBox()
56{
57}
58
59wxStaticBox::wxStaticBox( wxWindow *parent,
60 wxWindowID id,
61 const wxString &label,
62 const wxPoint& pos,
63 const wxSize& size,
64 long style,
65 const wxString& name )
66{
67 Create( parent, id, label, pos, size, style, name );
68}
69
70bool wxStaticBox::Create( wxWindow *parent,
71 wxWindowID id,
72 const wxString& label,
73 const wxPoint& pos,
74 const wxSize& size,
75 long style,
76 const wxString& name )
77{
78 if (!PreCreation( parent, pos, size ) ||
79 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
80 {
81 wxFAIL_MSG( wxT("wxStaticBox creation failed") );
82 return false;
83 }
84
85 m_widget = GTKCreateFrame(label);
86 g_object_ref(m_widget);
87
88 // only base SetLabel needs to be called after GTKCreateFrame
89 wxControl::SetLabel(label);
90
91 m_parent->DoAddChild( this );
92
93 PostCreation(size);
94
95 // need to set non default alignment?
96 gfloat xalign = 0;
97 if ( style & wxALIGN_CENTER )
98 xalign = 0.5;
99 else if ( style & wxALIGN_RIGHT )
100 xalign = 1.0;
101
102 gtk_frame_set_label_align(GTK_FRAME(m_widget), xalign, 0.5);
103
104#ifndef __WXGTK3__
105 if (gtk_check_version(2, 12, 0))
106 {
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);
109 }
110#endif
111
112 return true;
113}
114
115void wxStaticBox::AddChild( wxWindowBase *child )
116{
117 if (!m_wxwindow)
118 {
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 );
124 }
125
126 wxWindow::AddChild( child );
127}
128
129void wxStaticBox::SetLabel( const wxString& label )
130{
131 wxCHECK_RET( m_widget != NULL, wxT("invalid staticbox") );
132
133 GTKSetLabelForFrame(GTK_FRAME(m_widget), label);
134}
135
136void wxStaticBox::DoApplyWidgetStyle(GtkRcStyle *style)
137{
138 GTKFrameApplyWidgetStyle(GTK_FRAME(m_widget), style);
139}
140
141bool wxStaticBox::GTKWidgetNeedsMnemonic() const
142{
143 return true;
144}
145
146void wxStaticBox::GTKWidgetDoSetMnemonic(GtkWidget* w)
147{
148 GTKFrameSetMnemonicWidget(GTK_FRAME(m_widget), w);
149}
150
151// static
152wxVisualAttributes
153wxStaticBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
154{
155 return GetDefaultAttributesFromGTKWidget(gtk_frame_new);
156}
157
158
159void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const
160{
161 *borderTop = GetCharHeight();
162 *borderOther = GetCharWidth()/2;
163}
164
165#endif // wxUSE_STATBOX