]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/statbox.cpp
Invoke default action if dclick event after <ENTER> not handled in wxListBox, added...
[wxWidgets.git] / src / gtk / statbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #include "wx/gtk/private.h"
17
18 #include "gdk/gdk.h"
19 #include "gtk/gtk.h"
20
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
34 extern "C" {
35
36 static void
37 gtk_frame_size_allocate (GtkWidget *widget,
38 GtkAllocation *allocation,
39 wxStaticBox * WXUNUSED(box))
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
64 //-----------------------------------------------------------------------------
65 // wxStaticBox
66 //-----------------------------------------------------------------------------
67
68 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
69
70 wxStaticBox::wxStaticBox()
71 {
72 }
73
74 wxStaticBox::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 )
81 {
82 Create( parent, id, label, pos, size, style, name );
83 }
84
85 bool 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 )
92 {
93 if (!PreCreation( parent, pos, size ) ||
94 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
95 {
96 wxFAIL_MSG( wxT("wxStaticBox creation failed") );
97 return false;
98 }
99
100 m_widget = GTKCreateFrame(label);
101 wxControl::SetLabel(label);
102
103 m_parent->DoAddChild( this );
104
105 PostCreation(size);
106
107 // need to set non default alignment?
108 gfloat xalign;
109 if ( style & wxALIGN_CENTER )
110 xalign = 0.5;
111 else if ( style & wxALIGN_RIGHT )
112 xalign = 1.0;
113 else // wxALIGN_LEFT
114 xalign = 0.0;
115
116 if ( style & (wxALIGN_RIGHT | wxALIGN_CENTER) ) // left alignment is default
117 gtk_frame_set_label_align(GTK_FRAME( m_widget ), xalign, 0.5);
118
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);
123
124 return TRUE;
125 }
126
127 void wxStaticBox::SetLabel( const wxString& label )
128 {
129 wxCHECK_RET( m_widget != NULL, wxT("invalid staticbox") );
130
131 GTKSetLabelForFrame(GTK_FRAME(m_widget), label);
132 }
133
134 void wxStaticBox::DoApplyWidgetStyle(GtkRcStyle *style)
135 {
136 GTKFrameApplyWidgetStyle(GTK_FRAME(m_widget), style);
137 }
138
139 bool wxStaticBox::GTKWidgetNeedsMnemonic() const
140 {
141 return true;
142 }
143
144 void wxStaticBox::GTKWidgetDoSetMnemonic(GtkWidget* w)
145 {
146 GTKFrameSetMnemonicWidget(GTK_FRAME(m_widget), w);
147 }
148
149 // static
150 wxVisualAttributes
151 wxStaticBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
152 {
153 return GetDefaultAttributesFromGTKWidget(gtk_frame_new);
154 }
155
156
157 void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const
158 {
159 const int BORDER = 5; // FIXME: hardcoded value
160
161 *borderTop = GetLabel().empty() ? 2*BORDER : GetCharHeight();
162 *borderOther = BORDER;
163 }
164
165 #endif // wxUSE_STATBOX