]>
Commit | Line | Data |
---|---|---|
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 | ||
34 | extern "C" { | |
35 | ||
36 | static void | |
37 | gtk_frame_size_allocate (GtkWidget *widget, | |
38 | GtkAllocation *allocation, | |
e4161a2a | 39 | wxStaticBox * WXUNUSED(box)) |
34a0dc61 VZ |
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 | 68 | IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl) |
c801d85f | 69 | |
4d23a4bf | 70 | wxStaticBox::wxStaticBox() |
c801d85f | 71 | { |
3f659fd6 | 72 | } |
c801d85f | 73 | |
4d23a4bf VZ |
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 ) | |
c801d85f | 81 | { |
1ecc4d80 | 82 | Create( parent, id, label, pos, size, style, name ); |
3f659fd6 | 83 | } |
c801d85f | 84 | |
4d23a4bf VZ |
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 ) | |
c801d85f | 92 | { |
4dcaf11a RR |
93 | if (!PreCreation( parent, pos, size ) || |
94 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
95 | { | |
223d09f6 | 96 | wxFAIL_MSG( wxT("wxStaticBox creation failed") ); |
e8375af8 | 97 | return false; |
4dcaf11a | 98 | } |
c801d85f | 99 | |
2e1f5012 VZ |
100 | m_widget = GTKCreateFrame(label); |
101 | wxControl::SetLabel(label); | |
904f68c7 | 102 | |
f03fc89f | 103 | m_parent->DoAddChild( this ); |
1e6feb95 | 104 | |
abdeb9e7 | 105 | PostCreation(size); |
db434467 | 106 | |
4d23a4bf VZ |
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; | |
58614078 | 115 | |
c77a6796 | 116 | if ( style & (wxALIGN_RIGHT | wxALIGN_CENTER) ) // left alignment is default |
308a5aeb | 117 | gtk_frame_set_label_align(GTK_FRAME( m_widget ), xalign, 0.5); |
0154a297 | 118 | |
34a0dc61 VZ |
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 | ||
1ecc4d80 | 124 | return TRUE; |
3f659fd6 | 125 | } |
d3904ceb | 126 | |
b2ff89d6 | 127 | void wxStaticBox::SetLabel( const wxString& label ) |
d3904ceb | 128 | { |
b2ff89d6 | 129 | wxCHECK_RET( m_widget != NULL, wxT("invalid staticbox") ); |
4d23a4bf | 130 | |
b2ff89d6 | 131 | GTKSetLabelForFrame(GTK_FRAME(m_widget), label); |
d3904ceb | 132 | } |
58614078 | 133 | |
7545e132 | 134 | void wxStaticBox::DoApplyWidgetStyle(GtkRcStyle *style) |
e3716844 | 135 | { |
2e1f5012 VZ |
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); | |
e3716844 RR |
147 | } |
148 | ||
9d522606 RD |
149 | // static |
150 | wxVisualAttributes | |
151 | wxStaticBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
152 | { | |
153 | return GetDefaultAttributesFromGTKWidget(gtk_frame_new); | |
154 | } | |
155 | ||
c1f50b06 RD |
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 | ||
1e6feb95 | 165 | #endif // wxUSE_STATBOX |