]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/statbox.cpp
Fix bug in wxFileName::Exists("/").
[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
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>
385e8575 18#include "wx/gtk/private/gtk2-compat.h"
9dc44eff 19#include "wx/gtk/private/win_gtk.h"
34a0dc61
VZ
20
21// constants taken from GTK sources
22#define LABEL_PAD 1
23#define LABEL_SIDE_PAD 2
24
25//-----------------------------------------------------------------------------
357b1b52 26// "size_allocate" from m_widget
34a0dc61
VZ
27//-----------------------------------------------------------------------------
28
9dc44eff 29#ifndef __WXGTK3__
34a0dc61 30extern "C" {
357b1b52 31static void size_allocate(GtkWidget* widget, GtkAllocation* alloc, void*)
34a0dc61 32{
357b1b52
PC
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 -
385e8575 36 2 * gtk_widget_get_style(widget)->xthickness - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD;
03647350 37 if (w < 0)
39cdc95f
FM
38 w = 0;
39
385e8575
PC
40 GtkAllocation a;
41 gtk_widget_get_allocation(label_widget, &a);
42 if (a.width > w)
34a0dc61 43 {
385e8575
PC
44 a.width = w;
45 gtk_widget_size_allocate(label_widget, &a);
34a0dc61
VZ
46 }
47}
34a0dc61 48}
9dc44eff 49#endif
34a0dc61 50
c801d85f
KB
51//-----------------------------------------------------------------------------
52// wxStaticBox
53//-----------------------------------------------------------------------------
54
4d23a4bf 55wxStaticBox::wxStaticBox()
c801d85f 56{
3f659fd6 57}
c801d85f 58
4d23a4bf
VZ
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 )
c801d85f 66{
1ecc4d80 67 Create( parent, id, label, pos, size, style, name );
3f659fd6 68}
c801d85f 69
4d23a4bf
VZ
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 )
c801d85f 77{
4dcaf11a
RR
78 if (!PreCreation( parent, pos, size ) ||
79 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
80 {
223d09f6 81 wxFAIL_MSG( wxT("wxStaticBox creation failed") );
e8375af8 82 return false;
4dcaf11a 83 }
c801d85f 84
2e1f5012 85 m_widget = GTKCreateFrame(label);
9ff9d30c 86 g_object_ref(m_widget);
39cdc95f 87
357b1b52 88 // only base SetLabel needs to be called after GTKCreateFrame
2e1f5012 89 wxControl::SetLabel(label);
904f68c7 90
f03fc89f 91 m_parent->DoAddChild( this );
1e6feb95 92
abdeb9e7 93 PostCreation(size);
db434467 94
4d23a4bf 95 // need to set non default alignment?
357b1b52 96 gfloat xalign = 0;
4d23a4bf
VZ
97 if ( style & wxALIGN_CENTER )
98 xalign = 0.5;
99 else if ( style & wxALIGN_RIGHT )
100 xalign = 1.0;
58614078 101
357b1b52 102 gtk_frame_set_label_align(GTK_FRAME(m_widget), xalign, 0.5);
0154a297 103
9dc44eff 104#ifndef __WXGTK3__
357b1b52
PC
105 if (gtk_check_version(2, 12, 0))
106 {
39cdc95f
FM
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);
357b1b52 109 }
9dc44eff 110#endif
34a0dc61 111
357b1b52 112 return true;
3f659fd6 113}
d3904ceb 114
39cdc95f
FM
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:
65391c8f 121 m_wxwindow = wxPizza::New();
39cdc95f
FM
122 gtk_widget_show( m_wxwindow );
123 gtk_container_add( GTK_CONTAINER (m_widget), m_wxwindow );
124 }
125
126 wxWindow::AddChild( child );
127}
128
b2ff89d6 129void wxStaticBox::SetLabel( const wxString& label )
d3904ceb 130{
b2ff89d6 131 wxCHECK_RET( m_widget != NULL, wxT("invalid staticbox") );
4d23a4bf 132
b2ff89d6 133 GTKSetLabelForFrame(GTK_FRAME(m_widget), label);
d3904ceb 134}
58614078 135
7545e132 136void wxStaticBox::DoApplyWidgetStyle(GtkRcStyle *style)
e3716844 137{
2e1f5012
VZ
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);
e3716844
RR
149}
150
9d522606
RD
151// static
152wxVisualAttributes
153wxStaticBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
154{
155 return GetDefaultAttributesFromGTKWidget(gtk_frame_new);
156}
157
c1f50b06
RD
158
159void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const
160{
10da53a2 161 *borderTop = GetCharHeight();
a19d4096 162 *borderOther = GetCharWidth()/2;
c1f50b06
RD
163}
164
1e6feb95 165#endif // wxUSE_STATBOX