]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/radiobox.cpp
Added isosurf wxGLCanvas sample, cured OnPaint bug (missing wxPaintDC object)
[wxWidgets.git] / src / gtk / radiobox.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: radiobox.cpp
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11
12#ifdef __GNUG__
13#pragma implementation "radiobox.h"
14#endif
15
16#include "wx/radiobox.h"
17#include "wx/dialog.h"
18#include "wx/frame.h"
19#include "wx/gtk/win_gtk.h"
20
66bd6b93
RR
21//-----------------------------------------------------------------------------
22// data
23//-----------------------------------------------------------------------------
24
25extern bool g_blockEventsOnDrag;
26
c801d85f
KB
27//-----------------------------------------------------------------------------
28// wxRadioBox
29//-----------------------------------------------------------------------------
30
66bd6b93 31static void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRadioBox *rb )
c801d85f 32{
66bd6b93
RR
33 if (!rb->HasVMT()) return;
34 if (g_blockEventsOnDrag) return;
35
47908e25
RR
36 if (rb->m_alreadySent)
37 {
38 rb->m_alreadySent = FALSE;
39 return;
40 }
41
42 rb->m_alreadySent = TRUE;
43
c801d85f
KB
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 );
47908e25 49 rb->GetEventHandler()->ProcessEvent(event);
6de97a3b 50}
c801d85f
KB
51
52//-----------------------------------------------------------------------------
53
54IMPLEMENT_DYNAMIC_CLASS(wxRadioBox,wxControl)
55
56wxRadioBox::wxRadioBox(void)
57{
6de97a3b 58}
c801d85f 59
debe6624
JS
60bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
61 const wxPoint &pos, const wxSize &size,
6de97a3b
RR
62 int n, const wxString choices[], int WXUNUSED(majorDim),
63 long style, const wxValidator& validator, const wxString &name )
c801d85f 64{
47908e25 65 m_alreadySent = FALSE;
c801d85f
KB
66 m_needParent = TRUE;
67
68 PreCreation( parent, id, pos, size, style, name );
69
6de97a3b
RR
70 SetValidator( validator );
71
c801d85f
KB
72 m_widget = gtk_frame_new( title );
73
74 int x = m_x+5;
75 int y = m_y+15;
76 int maxLen = 0;
77 int height = 20;
78
79// if (((m_style & wxRA_VERTICAL) == wxRA_VERTICAL) && (n > 0))
80 if (n > 0)
81 {
82 GSList *radio_button_group = NULL;
83 for (int i = 0; i < n; i++)
84 {
85 if (i) radio_button_group = gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio) );
47908e25 86
c801d85f
KB
87 m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, choices[i] ) );
88
89 if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE );
90
91 gtk_signal_connect( GTK_OBJECT(m_radio), "clicked",
92 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
93
94 gtk_myfixed_put( GTK_MYFIXED(m_parent->m_wxwindow), GTK_WIDGET(m_radio), x, y );
95
96 int tmp = 22+gdk_string_measure( GTK_WIDGET(m_radio)->style->font, choices[i] );
97 if (tmp > maxLen) maxLen = tmp;
98
99 int width = m_width-10;
100 if (size.x == -1) width = tmp;
101 gtk_widget_set_usize( GTK_WIDGET(m_radio), width, 20 );
102
103 y += 20;
104 height += 20;
105
6de97a3b
RR
106 }
107 }
c801d85f
KB
108
109 wxSize newSize = size;
110 if (newSize.x == -1) newSize.x = maxLen+10;
111 if (newSize.y == -1) newSize.y = height;
112 SetSize( newSize.x, newSize.y );
113
114 PostCreation();
115
116 Show( TRUE );
117
118 return TRUE;
6de97a3b 119}
c801d85f 120
debe6624 121bool wxRadioBox::Show( bool show )
c801d85f
KB
122{
123 wxWindow::Show( show );
124
125 GSList *item = gtk_radio_button_group( m_radio );
126 while (item)
127 {
128 GtkWidget *w = GTK_WIDGET( item->data );
129 if (show) gtk_widget_show( w ); else gtk_widget_hide( w );
130 item = item->next;
6de97a3b 131 }
c801d85f
KB
132
133 return TRUE;
6de97a3b 134}
c801d85f 135
47908e25 136int wxRadioBox::FindString( const wxString &s ) const
c801d85f 137{
47908e25
RR
138 GSList *item = gtk_radio_button_group( m_radio );
139
140 int count = g_slist_length(item)-1;
141
142 while (item)
143 {
144 GtkButton *b = GTK_BUTTON( item->data );
145 GtkLabel *l = GTK_LABEL( b->child );
146 if (s == l->label) return count;
147 count--;
148 item = item->next;
6de97a3b 149 }
47908e25
RR
150
151 return -1;
6de97a3b 152}
c801d85f 153
47908e25 154void wxRadioBox::SetSelection( int n )
c801d85f 155{
47908e25
RR
156 GSList *item = gtk_radio_button_group( m_radio );
157 item = g_slist_nth( item, g_slist_length(item)-n-1 );
158 if (!item) return;
159
160 GtkToggleButton *button = GTK_TOGGLE_BUTTON( item->data );
161
162 gtk_toggle_button_set_state( button, 1 );
6de97a3b 163}
c801d85f
KB
164
165int wxRadioBox::GetSelection(void) const
166{
167 GSList *item = gtk_radio_button_group( m_radio );
168 int count = 0;
169 while (item)
170 {
171 GtkButton *button = GTK_BUTTON( item->data );
172 if (GTK_TOGGLE_BUTTON(button)->active) return count;
173 count++;
174 item = item->next;
6de97a3b 175 }
c801d85f 176 return -1;
6de97a3b 177}
c801d85f 178
47908e25 179wxString wxRadioBox::GetString( int n ) const
c801d85f 180{
47908e25
RR
181 GSList *item = gtk_radio_button_group( m_radio );
182
183 item = g_slist_nth( item, g_slist_length(item)-n-1 );
184 if (!item) return "";
185
186 GtkToggleButton *button = GTK_TOGGLE_BUTTON( item->data );
187
188 GtkLabel *label = GTK_LABEL( GTK_BUTTON(button)->child );
189
190 return wxString( label->label );
6de97a3b 191}
c801d85f
KB
192
193wxString wxRadioBox::GetLabel(void) const
194{
195 return wxControl::GetLabel();
6de97a3b 196}
c801d85f
KB
197
198void wxRadioBox::SetLabel( const wxString& WXUNUSED(label) )
199{
a3622daa 200 wxFAIL_MSG("wxRadioBox::SetLabel not implemented.");
6de97a3b 201}
c801d85f 202
debe6624 203void wxRadioBox::SetLabel( int WXUNUSED(item), const wxString& WXUNUSED(label) )
c801d85f 204{
a3622daa 205 wxFAIL_MSG("wxRadioBox::SetLabel not implemented.");
6de97a3b 206}
c801d85f 207
debe6624 208void wxRadioBox::SetLabel( int WXUNUSED(item), wxBitmap *WXUNUSED(bitmap) )
c801d85f 209{
a3622daa 210 wxFAIL_MSG("wxRadioBox::SetLabel not implemented.");
6de97a3b 211}
c801d85f 212
debe6624 213wxString wxRadioBox::GetLabel( int WXUNUSED(item) ) const
c801d85f 214{
a3622daa 215 wxFAIL_MSG("wxRadioBox::GetLabel not implemented.");
c801d85f 216 return "";
6de97a3b 217}
c801d85f 218
debe6624 219void wxRadioBox::Enable( bool WXUNUSED(enable) )
c801d85f 220{
a3622daa 221 wxFAIL_MSG("wxRadioBox::Enable not implemented.");
6de97a3b 222}
c801d85f 223
debe6624 224void wxRadioBox::Enable( int WXUNUSED(item), bool WXUNUSED(enable) )
c801d85f 225{
a3622daa 226 wxFAIL_MSG("wxRadioBox::Enable not implemented.");
6de97a3b 227}
c801d85f 228
debe6624 229void wxRadioBox::Show( int WXUNUSED(item), bool WXUNUSED(show) )
c801d85f 230{
a3622daa 231 wxFAIL_MSG("wxRadioBox::Show not implemented.");
6de97a3b 232}
c801d85f
KB
233
234wxString wxRadioBox::GetStringSelection(void) const
235{
236 GSList *item = gtk_radio_button_group( m_radio );
237 while (item)
238 {
239 GtkButton *button = GTK_BUTTON( item->data );
240 if (GTK_TOGGLE_BUTTON(button)->active)
241 {
242 GtkLabel *label = GTK_LABEL( button->child );
243 return label->label;
6de97a3b 244 }
c801d85f 245 item = item->next;
6de97a3b 246 }
c801d85f 247 return "";
6de97a3b 248}
c801d85f 249
47908e25 250bool wxRadioBox::SetStringSelection( const wxString&s )
c801d85f 251{
47908e25
RR
252 int res = FindString( s );
253 if (res == -1) return FALSE;
254 SetSelection( res );
c801d85f 255 return TRUE;
6de97a3b 256}
c801d85f
KB
257
258int wxRadioBox::Number(void) const
259{
260 int count = 0;
261 GSList *item = gtk_radio_button_group( m_radio );
262 while (item)
263 {
264 item = item->next;
265 count++;
6de97a3b 266 }
c801d85f 267 return count;
6de97a3b 268}
c801d85f
KB
269
270int wxRadioBox::GetNumberOfRowsOrCols(void) const
271{
272 return 1;
6de97a3b 273}
c801d85f 274
debe6624 275void wxRadioBox::SetNumberOfRowsOrCols( int WXUNUSED(n) )
c801d85f 276{
a3622daa 277 wxFAIL_MSG("wxRadioBox::SetNumberOfRowsOrCols not implemented.");
6de97a3b 278}
c801d85f 279