]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/radiobox.cpp
Next attempt at dynlib.cpp
[wxWidgets.git] / src / gtk1 / 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;
2b5bd7fd 169 int found = -1;
c801d85f
KB
170 while (item)
171 {
172 GtkButton *button = GTK_BUTTON( item->data );
2b5bd7fd 173 if (GTK_TOGGLE_BUTTON(button)->active) found = count;
c801d85f
KB
174 count++;
175 item = item->next;
6de97a3b 176 }
2b5bd7fd
KB
177
178 return found != -1 ? count-found-1 : -1;
6de97a3b 179}
c801d85f 180
47908e25 181wxString wxRadioBox::GetString( int n ) const
c801d85f 182{
47908e25
RR
183 GSList *item = gtk_radio_button_group( m_radio );
184
185 item = g_slist_nth( item, g_slist_length(item)-n-1 );
186 if (!item) return "";
187
188 GtkToggleButton *button = GTK_TOGGLE_BUTTON( item->data );
189
190 GtkLabel *label = GTK_LABEL( GTK_BUTTON(button)->child );
191
192 return wxString( label->label );
6de97a3b 193}
c801d85f
KB
194
195wxString wxRadioBox::GetLabel(void) const
196{
197 return wxControl::GetLabel();
6de97a3b 198}
c801d85f
KB
199
200void wxRadioBox::SetLabel( const wxString& WXUNUSED(label) )
201{
a3622daa 202 wxFAIL_MSG("wxRadioBox::SetLabel not implemented.");
6de97a3b 203}
c801d85f 204
debe6624 205void wxRadioBox::SetLabel( int WXUNUSED(item), const wxString& WXUNUSED(label) )
c801d85f 206{
a3622daa 207 wxFAIL_MSG("wxRadioBox::SetLabel not implemented.");
6de97a3b 208}
c801d85f 209
debe6624 210void wxRadioBox::SetLabel( int WXUNUSED(item), wxBitmap *WXUNUSED(bitmap) )
c801d85f 211{
a3622daa 212 wxFAIL_MSG("wxRadioBox::SetLabel not implemented.");
6de97a3b 213}
c801d85f 214
debe6624 215wxString wxRadioBox::GetLabel( int WXUNUSED(item) ) const
c801d85f 216{
a3622daa 217 wxFAIL_MSG("wxRadioBox::GetLabel not implemented.");
c801d85f 218 return "";
6de97a3b 219}
c801d85f 220
debe6624 221void wxRadioBox::Enable( bool WXUNUSED(enable) )
c801d85f 222{
a3622daa 223 wxFAIL_MSG("wxRadioBox::Enable not implemented.");
6de97a3b 224}
c801d85f 225
debe6624 226void wxRadioBox::Enable( int WXUNUSED(item), bool WXUNUSED(enable) )
c801d85f 227{
a3622daa 228 wxFAIL_MSG("wxRadioBox::Enable not implemented.");
6de97a3b 229}
c801d85f 230
debe6624 231void wxRadioBox::Show( int WXUNUSED(item), bool WXUNUSED(show) )
c801d85f 232{
a3622daa 233 wxFAIL_MSG("wxRadioBox::Show not implemented.");
6de97a3b 234}
c801d85f
KB
235
236wxString wxRadioBox::GetStringSelection(void) const
237{
238 GSList *item = gtk_radio_button_group( m_radio );
239 while (item)
240 {
241 GtkButton *button = GTK_BUTTON( item->data );
242 if (GTK_TOGGLE_BUTTON(button)->active)
243 {
244 GtkLabel *label = GTK_LABEL( button->child );
245 return label->label;
6de97a3b 246 }
c801d85f 247 item = item->next;
6de97a3b 248 }
c801d85f 249 return "";
6de97a3b 250}
c801d85f 251
47908e25 252bool wxRadioBox::SetStringSelection( const wxString&s )
c801d85f 253{
47908e25
RR
254 int res = FindString( s );
255 if (res == -1) return FALSE;
256 SetSelection( res );
c801d85f 257 return TRUE;
6de97a3b 258}
c801d85f
KB
259
260int wxRadioBox::Number(void) const
261{
262 int count = 0;
263 GSList *item = gtk_radio_button_group( m_radio );
264 while (item)
265 {
266 item = item->next;
267 count++;
6de97a3b 268 }
c801d85f 269 return count;
6de97a3b 270}
c801d85f
KB
271
272int wxRadioBox::GetNumberOfRowsOrCols(void) const
273{
274 return 1;
6de97a3b 275}
c801d85f 276
debe6624 277void wxRadioBox::SetNumberOfRowsOrCols( int WXUNUSED(n) )
c801d85f 278{
a3622daa 279 wxFAIL_MSG("wxRadioBox::SetNumberOfRowsOrCols not implemented.");
6de97a3b 280}
c801d85f 281