1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "radiobox.h"
16 #include "wx/radiobox.h"
17 #include "wx/dialog.h"
19 #include "wx/gtk/win_gtk.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 void gtk_radiobutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxRadioBox
*rb
)
27 if (rb
->m_alreadySent
)
29 rb
->m_alreadySent
= FALSE
;
33 rb
->m_alreadySent
= TRUE
;
35 wxCommandEvent
event( wxEVT_COMMAND_RADIOBOX_SELECTED
, rb
->GetId() );
36 event
.SetInt( rb
->GetSelection() );
37 wxString
tmp( rb
->GetStringSelection() );
38 event
.SetString( WXSTRINGCAST(tmp
) );
39 event
.SetEventObject( rb
);
40 rb
->GetEventHandler()->ProcessEvent(event
);
43 //-----------------------------------------------------------------------------
45 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox
,wxControl
)
47 wxRadioBox::wxRadioBox(void)
51 wxRadioBox::wxRadioBox( wxWindow
*parent
, wxWindowID id
, const wxString
& title
,
52 const wxPoint
&pos
, const wxSize
&size
,
53 int n
, const wxString choices
[],
54 int majorDim
, long style
,
55 const wxString
&name
)
57 Create( parent
, id
, title
, pos
, size
, n
, choices
, majorDim
, style
, name
);
60 bool wxRadioBox::Create( wxWindow
*parent
, wxWindowID id
, const wxString
& title
,
61 const wxPoint
&pos
, const wxSize
&size
,
62 int n
, const wxString choices
[],
63 int WXUNUSED(majorDim
), long style
,
64 const wxString
&name
)
66 m_alreadySent
= FALSE
;
69 PreCreation( parent
, id
, pos
, size
, style
, name
);
71 m_widget
= gtk_frame_new( title
);
78 // if (((m_style & wxRA_VERTICAL) == wxRA_VERTICAL) && (n > 0))
81 GSList
*radio_button_group
= NULL
;
82 for (int i
= 0; i
< n
; i
++)
84 if (i
) radio_button_group
= gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio
) );
86 m_radio
= GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group
, choices
[i
] ) );
88 if (!i
) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio
), TRUE
);
90 gtk_signal_connect( GTK_OBJECT(m_radio
), "clicked",
91 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback
), (gpointer
*)this );
93 gtk_myfixed_put( GTK_MYFIXED(m_parent
->m_wxwindow
), GTK_WIDGET(m_radio
), x
, y
);
95 int tmp
= 22+gdk_string_measure( GTK_WIDGET(m_radio
)->style
->font
, choices
[i
] );
96 if (tmp
> maxLen
) maxLen
= tmp
;
98 int width
= m_width
-10;
99 if (size
.x
== -1) width
= tmp
;
100 gtk_widget_set_usize( GTK_WIDGET(m_radio
), width
, 20 );
108 wxSize newSize
= size
;
109 if (newSize
.x
== -1) newSize
.x
= maxLen
+10;
110 if (newSize
.y
== -1) newSize
.y
= height
;
111 SetSize( newSize
.x
, newSize
.y
);
120 bool wxRadioBox::Show( bool show
)
122 wxWindow::Show( show
);
124 GSList
*item
= gtk_radio_button_group( m_radio
);
127 GtkWidget
*w
= GTK_WIDGET( item
->data
);
128 if (show
) gtk_widget_show( w
); else gtk_widget_hide( w
);
135 int wxRadioBox::FindString( const wxString
&s
) const
137 GSList
*item
= gtk_radio_button_group( m_radio
);
139 int count
= g_slist_length(item
)-1;
143 GtkButton
*b
= GTK_BUTTON( item
->data
);
144 GtkLabel
*l
= GTK_LABEL( b
->child
);
145 if (s
== l
->label
) return count
;
153 void wxRadioBox::SetSelection( int n
)
155 GSList
*item
= gtk_radio_button_group( m_radio
);
156 item
= g_slist_nth( item
, g_slist_length(item
)-n
-1 );
159 GtkToggleButton
*button
= GTK_TOGGLE_BUTTON( item
->data
);
161 gtk_toggle_button_set_state( button
, 1 );
164 int wxRadioBox::GetSelection(void) const
166 GSList
*item
= gtk_radio_button_group( m_radio
);
170 GtkButton
*button
= GTK_BUTTON( item
->data
);
171 if (GTK_TOGGLE_BUTTON(button
)->active
) return count
;
178 wxString
wxRadioBox::GetString( int n
) const
180 GSList
*item
= gtk_radio_button_group( m_radio
);
182 item
= g_slist_nth( item
, g_slist_length(item
)-n
-1 );
183 if (!item
) return "";
185 GtkToggleButton
*button
= GTK_TOGGLE_BUTTON( item
->data
);
187 GtkLabel
*label
= GTK_LABEL( GTK_BUTTON(button
)->child
);
189 return wxString( label
->label
);
192 wxString
wxRadioBox::GetLabel(void) const
194 return wxControl::GetLabel();
197 void wxRadioBox::SetLabel( const wxString
& WXUNUSED(label
) )
201 void wxRadioBox::SetLabel( int WXUNUSED(item
), const wxString
& WXUNUSED(label
) )
205 void wxRadioBox::SetLabel( int WXUNUSED(item
), wxBitmap
*WXUNUSED(bitmap
) )
209 wxString
wxRadioBox::GetLabel( int WXUNUSED(item
) ) const
214 void wxRadioBox::Enable( bool WXUNUSED(enable
) )
218 void wxRadioBox::Enable( int WXUNUSED(item
), bool WXUNUSED(enable
) )
222 void wxRadioBox::Show( int WXUNUSED(item
), bool WXUNUSED(show
) )
226 wxString
wxRadioBox::GetStringSelection(void) const
228 GSList
*item
= gtk_radio_button_group( m_radio
);
231 GtkButton
*button
= GTK_BUTTON( item
->data
);
232 if (GTK_TOGGLE_BUTTON(button
)->active
)
234 GtkLabel
*label
= GTK_LABEL( button
->child
);
242 bool wxRadioBox::SetStringSelection( const wxString
&s
)
244 int res
= FindString( s
);
245 if (res
== -1) return FALSE
;
250 int wxRadioBox::Number(void) const
253 GSList
*item
= gtk_radio_button_group( m_radio
);
262 int wxRadioBox::GetNumberOfRowsOrCols(void) const
267 void wxRadioBox::SetNumberOfRowsOrCols( int WXUNUSED(n
) )