]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/statbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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"
16 #include "wx/gtk/private.h"
22 // ============================================================================
24 // ============================================================================
26 // constants taken from GTK sources
28 #define LABEL_SIDE_PAD 2
30 //-----------------------------------------------------------------------------
31 // "gtk_frame_size_allocate" signal
32 //-----------------------------------------------------------------------------
37 gtk_frame_size_allocate (GtkWidget
*widget
,
38 GtkAllocation
*allocation
,
39 wxStaticBox
* WXUNUSED(box
))
41 GtkFrame
*frame
= GTK_FRAME (widget
);
43 // this handler gets called _after_ the GTK+'s own signal handler; thus we
44 // need to fix only the width of the GtkLabel
45 // (everything else has already been handled by the GTK+ signal handler).
47 if (frame
->label_widget
&& GTK_WIDGET_VISIBLE (frame
->label_widget
))
49 GtkAllocation ca
= frame
->label_widget
->allocation
;
51 // we want the GtkLabel to not exceed maxWidth:
52 int maxWidth
= allocation
->width
- 2*LABEL_SIDE_PAD
- 2*LABEL_PAD
;
53 maxWidth
= wxMax(2, maxWidth
); // maxWidth must always be positive!
55 // truncate the label to the GtkFrame width...
56 ca
.width
= wxMin(ca
.width
, maxWidth
);
57 gtk_widget_size_allocate(frame
->label_widget
, &ca
);
64 //-----------------------------------------------------------------------------
66 //-----------------------------------------------------------------------------
68 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox
, wxControl
)
70 wxStaticBox::wxStaticBox()
74 wxStaticBox::wxStaticBox( wxWindow
*parent
,
76 const wxString
&label
,
80 const wxString
& name
)
82 Create( parent
, id
, label
, pos
, size
, style
, name
);
85 bool wxStaticBox::Create( wxWindow
*parent
,
87 const wxString
& label
,
91 const wxString
& name
)
93 if (!PreCreation( parent
, pos
, size
) ||
94 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
96 wxFAIL_MSG( wxT("wxStaticBox creation failed") );
100 m_widget
= GTKCreateFrame(label
);
101 wxControl::SetLabel(label
);
103 m_parent
->DoAddChild( this );
107 // need to set non default alignment?
109 if ( style
& wxALIGN_CENTER
)
111 else if ( style
& wxALIGN_RIGHT
)
116 if ( style
& (wxALIGN_RIGHT
| wxALIGN_CENTER
) ) // left alignment is default
117 gtk_frame_set_label_align(GTK_FRAME( m_widget
), xalign
, 0.5);
119 // in order to clip the label widget, we must connect to the size allocate
120 // signal of this GtkFrame after the default GTK+'s allocate size function
121 g_signal_connect_after (m_widget
, "size_allocate",
122 G_CALLBACK (gtk_frame_size_allocate
), this);
127 void wxStaticBox::SetLabel( const wxString
& label
)
129 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid staticbox") );
131 GTKSetLabelForFrame(GTK_FRAME(m_widget
), label
);
134 void wxStaticBox::DoApplyWidgetStyle(GtkRcStyle
*style
)
136 GTKFrameApplyWidgetStyle(GTK_FRAME(m_widget
), style
);
139 bool wxStaticBox::GTKWidgetNeedsMnemonic() const
144 void wxStaticBox::GTKWidgetDoSetMnemonic(GtkWidget
* w
)
146 GTKFrameSetMnemonicWidget(GTK_FRAME(m_widget
), w
);
151 wxStaticBox::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
153 return GetDefaultAttributesFromGTKWidget(gtk_frame_new
);
157 void wxStaticBox::GetBordersForSizer(int *borderTop
, int *borderOther
) const
159 const int BORDER
= 5; // FIXME: hardcoded value
161 *borderTop
= GetLabel().empty() ? 2*BORDER
: GetCharHeight();
162 *borderOther
= BORDER
;
165 #endif // wxUSE_STATBOX