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 extern bool g_blockEventsOnDrag
;
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 static void gtk_radiobutton_clicked_callback( GtkWidget
*WXUNUSED(widget
), wxRadioBox
*rb
)
33 if (!rb
->HasVMT()) return;
34 if (g_blockEventsOnDrag
) return;
36 if (rb
->m_alreadySent
)
38 rb
->m_alreadySent
= FALSE
;
42 rb
->m_alreadySent
= TRUE
;
44 wxCommandEvent
event( wxEVT_COMMAND_RADIOBOX_SELECTED
, rb
->GetId() );
45 event
.SetInt( rb
->GetSelection() );
46 wxString
tmp( rb
->GetStringSelection() );
47 event
.SetString( WXSTRINGCAST(tmp
) );
48 event
.SetEventObject( rb
);
49 rb
->GetEventHandler()->ProcessEvent(event
);
52 //-----------------------------------------------------------------------------
54 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox
,wxControl
)
56 wxRadioBox::wxRadioBox(void)
60 wxRadioBox::wxRadioBox( wxWindow
*parent
, wxWindowID id
, const wxString
& title
,
61 const wxPoint
&pos
, const wxSize
&size
,
62 int n
, const wxString choices
[],
63 int majorDim
, long style
,
64 const wxString
&name
)
66 Create( parent
, id
, title
, pos
, size
, n
, choices
, majorDim
, style
, name
);
69 bool wxRadioBox::Create( wxWindow
*parent
, wxWindowID id
, const wxString
& title
,
70 const wxPoint
&pos
, const wxSize
&size
,
71 int n
, const wxString choices
[],
72 int WXUNUSED(majorDim
), long style
,
73 const wxString
&name
)
75 m_alreadySent
= FALSE
;
78 PreCreation( parent
, id
, pos
, size
, style
, name
);
80 m_widget
= gtk_frame_new( title
);
87 // if (((m_style & wxRA_VERTICAL) == wxRA_VERTICAL) && (n > 0))
90 GSList
*radio_button_group
= NULL
;
91 for (int i
= 0; i
< n
; i
++)
93 if (i
) radio_button_group
= gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio
) );
95 m_radio
= GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group
, choices
[i
] ) );
97 if (!i
) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio
), TRUE
);
99 gtk_signal_connect( GTK_OBJECT(m_radio
), "clicked",
100 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback
), (gpointer
*)this );
102 gtk_myfixed_put( GTK_MYFIXED(m_parent
->m_wxwindow
), GTK_WIDGET(m_radio
), x
, y
);
104 int tmp
= 22+gdk_string_measure( GTK_WIDGET(m_radio
)->style
->font
, choices
[i
] );
105 if (tmp
> maxLen
) maxLen
= tmp
;
107 int width
= m_width
-10;
108 if (size
.x
== -1) width
= tmp
;
109 gtk_widget_set_usize( GTK_WIDGET(m_radio
), width
, 20 );
117 wxSize newSize
= size
;
118 if (newSize
.x
== -1) newSize
.x
= maxLen
+10;
119 if (newSize
.y
== -1) newSize
.y
= height
;
120 SetSize( newSize
.x
, newSize
.y
);
129 bool wxRadioBox::Show( bool show
)
131 wxWindow::Show( show
);
133 GSList
*item
= gtk_radio_button_group( m_radio
);
136 GtkWidget
*w
= GTK_WIDGET( item
->data
);
137 if (show
) gtk_widget_show( w
); else gtk_widget_hide( w
);
144 int wxRadioBox::FindString( const wxString
&s
) const
146 GSList
*item
= gtk_radio_button_group( m_radio
);
148 int count
= g_slist_length(item
)-1;
152 GtkButton
*b
= GTK_BUTTON( item
->data
);
153 GtkLabel
*l
= GTK_LABEL( b
->child
);
154 if (s
== l
->label
) return count
;
162 void wxRadioBox::SetSelection( int n
)
164 GSList
*item
= gtk_radio_button_group( m_radio
);
165 item
= g_slist_nth( item
, g_slist_length(item
)-n
-1 );
168 GtkToggleButton
*button
= GTK_TOGGLE_BUTTON( item
->data
);
170 gtk_toggle_button_set_state( button
, 1 );
173 int wxRadioBox::GetSelection(void) const
175 GSList
*item
= gtk_radio_button_group( m_radio
);
179 GtkButton
*button
= GTK_BUTTON( item
->data
);
180 if (GTK_TOGGLE_BUTTON(button
)->active
) return count
;
187 wxString
wxRadioBox::GetString( int n
) const
189 GSList
*item
= gtk_radio_button_group( m_radio
);
191 item
= g_slist_nth( item
, g_slist_length(item
)-n
-1 );
192 if (!item
) return "";
194 GtkToggleButton
*button
= GTK_TOGGLE_BUTTON( item
->data
);
196 GtkLabel
*label
= GTK_LABEL( GTK_BUTTON(button
)->child
);
198 return wxString( label
->label
);
201 wxString
wxRadioBox::GetLabel(void) const
203 return wxControl::GetLabel();
206 void wxRadioBox::SetLabel( const wxString
& WXUNUSED(label
) )
208 wxFAIL_MSG("wxRadioBox::SetLabel not implemented.");
211 void wxRadioBox::SetLabel( int WXUNUSED(item
), const wxString
& WXUNUSED(label
) )
213 wxFAIL_MSG("wxRadioBox::SetLabel not implemented.");
216 void wxRadioBox::SetLabel( int WXUNUSED(item
), wxBitmap
*WXUNUSED(bitmap
) )
218 wxFAIL_MSG("wxRadioBox::SetLabel not implemented.");
221 wxString
wxRadioBox::GetLabel( int WXUNUSED(item
) ) const
223 wxFAIL_MSG("wxRadioBox::GetLabel not implemented.");
227 void wxRadioBox::Enable( bool WXUNUSED(enable
) )
229 wxFAIL_MSG("wxRadioBox::Enable not implemented.");
232 void wxRadioBox::Enable( int WXUNUSED(item
), bool WXUNUSED(enable
) )
234 wxFAIL_MSG("wxRadioBox::Enable not implemented.");
237 void wxRadioBox::Show( int WXUNUSED(item
), bool WXUNUSED(show
) )
239 wxFAIL_MSG("wxRadioBox::Show not implemented.");
242 wxString
wxRadioBox::GetStringSelection(void) const
244 GSList
*item
= gtk_radio_button_group( m_radio
);
247 GtkButton
*button
= GTK_BUTTON( item
->data
);
248 if (GTK_TOGGLE_BUTTON(button
)->active
)
250 GtkLabel
*label
= GTK_LABEL( button
->child
);
258 bool wxRadioBox::SetStringSelection( const wxString
&s
)
260 int res
= FindString( s
);
261 if (res
== -1) return FALSE
;
266 int wxRadioBox::Number(void) const
269 GSList
*item
= gtk_radio_button_group( m_radio
);
278 int wxRadioBox::GetNumberOfRowsOrCols(void) const
283 void wxRadioBox::SetNumberOfRowsOrCols( int WXUNUSED(n
) )
285 wxFAIL_MSG("wxRadioBox::SetNumberOfRowsOrCols not implemented.");