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
), gpointer data
)
27 wxRadioBox
*rb
= (wxRadioBox
*)data
;
28 wxCommandEvent
event( wxEVT_COMMAND_RADIOBOX_SELECTED
, rb
->GetId() );
29 event
.SetInt( rb
->GetSelection() );
30 wxString
tmp( rb
->GetStringSelection() );
31 event
.SetString( WXSTRINGCAST(tmp
) );
32 event
.SetEventObject( rb
);
33 rb
->ProcessEvent(event
);
36 //-----------------------------------------------------------------------------
38 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox
,wxControl
)
40 wxRadioBox::wxRadioBox(void)
44 wxRadioBox::wxRadioBox( wxWindow
*parent
, wxWindowID id
, const wxString
& title
,
45 const wxPoint
&pos
, const wxSize
&size
,
46 int n
, const wxString choices
[],
47 int majorDim
, long style
,
48 const wxString
&name
)
50 Create( parent
, id
, title
, pos
, size
, n
, choices
, majorDim
, style
, name
);
53 bool wxRadioBox::Create( wxWindow
*parent
, wxWindowID id
, const wxString
& title
,
54 const wxPoint
&pos
, const wxSize
&size
,
55 int n
, const wxString choices
[],
56 int WXUNUSED(majorDim
), long style
,
57 const wxString
&name
)
61 PreCreation( parent
, id
, pos
, size
, style
, name
);
63 m_widget
= gtk_frame_new( title
);
70 // if (((m_style & wxRA_VERTICAL) == wxRA_VERTICAL) && (n > 0))
73 GSList
*radio_button_group
= NULL
;
74 for (int i
= 0; i
< n
; i
++)
76 if (i
) radio_button_group
= gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio
) );
77 m_radio
= GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group
, choices
[i
] ) );
79 if (!i
) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio
), TRUE
);
81 gtk_signal_connect( GTK_OBJECT(m_radio
), "clicked",
82 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback
), (gpointer
*)this );
84 gtk_myfixed_put( GTK_MYFIXED(m_parent
->m_wxwindow
), GTK_WIDGET(m_radio
), x
, y
);
86 int tmp
= 22+gdk_string_measure( GTK_WIDGET(m_radio
)->style
->font
, choices
[i
] );
87 if (tmp
> maxLen
) maxLen
= tmp
;
89 int width
= m_width
-10;
90 if (size
.x
== -1) width
= tmp
;
91 gtk_widget_set_usize( GTK_WIDGET(m_radio
), width
, 20 );
99 wxSize newSize
= size
;
100 if (newSize
.x
== -1) newSize
.x
= maxLen
+10;
101 if (newSize
.y
== -1) newSize
.y
= height
;
102 SetSize( newSize
.x
, newSize
.y
);
111 bool wxRadioBox::Show( bool show
)
113 wxWindow::Show( show
);
115 GSList
*item
= gtk_radio_button_group( m_radio
);
118 GtkWidget
*w
= GTK_WIDGET( item
->data
);
119 if (show
) gtk_widget_show( w
); else gtk_widget_hide( w
);
126 int wxRadioBox::FindString( const wxString
& WXUNUSED(s
) ) const
131 void wxRadioBox::SetSelection( int WXUNUSED(n
) )
135 int wxRadioBox::GetSelection(void) const
137 GSList
*item
= gtk_radio_button_group( m_radio
);
141 GtkButton
*button
= GTK_BUTTON( item
->data
);
142 if (GTK_TOGGLE_BUTTON(button
)->active
) return count
;
149 wxString
wxRadioBox::GetString( int WXUNUSED(n
) ) const
154 wxString
wxRadioBox::GetLabel(void) const
156 return wxControl::GetLabel();
159 void wxRadioBox::SetLabel( const wxString
& WXUNUSED(label
) )
163 void wxRadioBox::SetLabel( int WXUNUSED(item
), const wxString
& WXUNUSED(label
) )
167 void wxRadioBox::SetLabel( int WXUNUSED(item
), wxBitmap
*WXUNUSED(bitmap
) )
171 wxString
wxRadioBox::GetLabel( int WXUNUSED(item
) ) const
176 void wxRadioBox::Enable( bool WXUNUSED(enable
) )
180 void wxRadioBox::Enable( int WXUNUSED(item
), bool WXUNUSED(enable
) )
184 void wxRadioBox::Show( int WXUNUSED(item
), bool WXUNUSED(show
) )
188 wxString
wxRadioBox::GetStringSelection(void) const
190 GSList
*item
= gtk_radio_button_group( m_radio
);
193 GtkButton
*button
= GTK_BUTTON( item
->data
);
194 if (GTK_TOGGLE_BUTTON(button
)->active
)
196 GtkLabel
*label
= GTK_LABEL( button
->child
);
204 bool wxRadioBox::SetStringSelection( const wxString
& WXUNUSED(s
) )
209 int wxRadioBox::Number(void) const
212 GSList
*item
= gtk_radio_button_group( m_radio
);
221 int wxRadioBox::GetNumberOfRowsOrCols(void) const
226 void wxRadioBox::SetNumberOfRowsOrCols( int WXUNUSED(n
) )