]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/statbox.cpp
Move Objective-C interfaces into separate header files in preparation for being able...
[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"
fab591c5 16#include "wx/gtk/private.h"
1e6feb95 17
83624f79
RR
18#include "gdk/gdk.h"
19#include "gtk/gtk.h"
20
34a0dc61
VZ
21
22// ============================================================================
23// implementation
24// ============================================================================
25
26// constants taken from GTK sources
27#define LABEL_PAD 1
28#define LABEL_SIDE_PAD 2
29
30//-----------------------------------------------------------------------------
31// "gtk_frame_size_allocate" signal
32//-----------------------------------------------------------------------------
33
34extern "C" {
35
36static void
37gtk_frame_size_allocate (GtkWidget *widget,
38 GtkAllocation *allocation,
39 wxStaticBox *p)
40{
41 GtkFrame *frame = GTK_FRAME (widget);
42
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).
46
47 if (frame->label_widget && GTK_WIDGET_VISIBLE (frame->label_widget))
48 {
49 GtkAllocation ca = frame->label_widget->allocation;
50
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!
54
55 // truncate the label to the GtkFrame width...
56 ca.width = wxMin(ca.width, maxWidth);
57 gtk_widget_size_allocate(frame->label_widget, &ca);
58 }
59}
60
61}
62
63
c801d85f
KB
64//-----------------------------------------------------------------------------
65// wxStaticBox
66//-----------------------------------------------------------------------------
67
4d23a4bf 68IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
c801d85f 69
4d23a4bf 70wxStaticBox::wxStaticBox()
c801d85f 71{
3f659fd6 72}
c801d85f 73
4d23a4bf
VZ
74wxStaticBox::wxStaticBox( wxWindow *parent,
75 wxWindowID id,
76 const wxString &label,
77 const wxPoint& pos,
78 const wxSize& size,
79 long style,
80 const wxString& name )
c801d85f 81{
1ecc4d80 82 Create( parent, id, label, pos, size, style, name );
3f659fd6 83}
c801d85f 84
4d23a4bf
VZ
85bool wxStaticBox::Create( wxWindow *parent,
86 wxWindowID id,
87 const wxString& label,
88 const wxPoint& pos,
89 const wxSize& size,
90 long style,
91 const wxString& name )
c801d85f 92{
1ecc4d80 93 m_needParent = TRUE;
904f68c7 94
4dcaf11a
RR
95 if (!PreCreation( parent, pos, size ) ||
96 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
97 {
223d09f6 98 wxFAIL_MSG( wxT("wxStaticBox creation failed") );
1e6feb95 99 return FALSE;
4dcaf11a 100 }
c801d85f 101
2e1f5012
VZ
102 m_widget = GTKCreateFrame(label);
103 wxControl::SetLabel(label);
904f68c7 104
f03fc89f 105 m_parent->DoAddChild( this );
1e6feb95 106
abdeb9e7 107 PostCreation(size);
db434467 108
4d23a4bf
VZ
109 // need to set non default alignment?
110 gfloat xalign;
111 if ( style & wxALIGN_CENTER )
112 xalign = 0.5;
113 else if ( style & wxALIGN_RIGHT )
114 xalign = 1.0;
115 else // wxALIGN_LEFT
116 xalign = 0.0;
58614078 117
c77a6796 118 if ( style & (wxALIGN_RIGHT | wxALIGN_CENTER) ) // left alignment is default
308a5aeb 119 gtk_frame_set_label_align(GTK_FRAME( m_widget ), xalign, 0.5);
0154a297 120
34a0dc61
VZ
121 // in order to clip the label widget, we must connect to the size allocate
122 // signal of this GtkFrame after the default GTK+'s allocate size function
123 g_signal_connect_after (m_widget, "size_allocate",
124 G_CALLBACK (gtk_frame_size_allocate), this);
125
1ecc4d80 126 return TRUE;
3f659fd6 127}
d3904ceb 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{
161 const int BORDER = 5; // FIXME: hardcoded value
162
163 *borderTop = GetLabel().empty() ? 2*BORDER : GetCharHeight();
164 *borderOther = BORDER;
165}
166
1e6feb95 167#endif // wxUSE_STATBOX