]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/radiobox.cpp
memdc and bitmap fixes
[wxWidgets.git] / src / gtk1 / radiobox.cpp
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
21 //-----------------------------------------------------------------------------
22 // wxRadioBox
23 //-----------------------------------------------------------------------------
24
25 void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), gpointer data )
26 {
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);
34 };
35
36 //-----------------------------------------------------------------------------
37
38 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox,wxControl)
39
40 wxRadioBox::wxRadioBox(void)
41 {
42 };
43
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 )
49 {
50 Create( parent, id, title, pos, size, n, choices, majorDim, style, name );
51 };
52
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 )
58 {
59 m_needParent = TRUE;
60
61 PreCreation( parent, id, pos, size, style, name );
62
63 m_widget = gtk_frame_new( title );
64
65 int x = m_x+5;
66 int y = m_y+15;
67 int maxLen = 0;
68 int height = 20;
69
70 // if (((m_style & wxRA_VERTICAL) == wxRA_VERTICAL) && (n > 0))
71 if (n > 0)
72 {
73 GSList *radio_button_group = NULL;
74 for (int i = 0; i < n; i++)
75 {
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] ) );
78
79 if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE );
80
81 gtk_signal_connect( GTK_OBJECT(m_radio), "clicked",
82 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
83
84 gtk_myfixed_put( GTK_MYFIXED(m_parent->m_wxwindow), GTK_WIDGET(m_radio), x, y );
85
86 int tmp = 22+gdk_string_measure( GTK_WIDGET(m_radio)->style->font, choices[i] );
87 if (tmp > maxLen) maxLen = tmp;
88
89 int width = m_width-10;
90 if (size.x == -1) width = tmp;
91 gtk_widget_set_usize( GTK_WIDGET(m_radio), width, 20 );
92
93 y += 20;
94 height += 20;
95
96 };
97 };
98
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 );
103
104 PostCreation();
105
106 Show( TRUE );
107
108 return TRUE;
109 };
110
111 bool wxRadioBox::Show( bool show )
112 {
113 wxWindow::Show( show );
114
115 GSList *item = gtk_radio_button_group( m_radio );
116 while (item)
117 {
118 GtkWidget *w = GTK_WIDGET( item->data );
119 if (show) gtk_widget_show( w ); else gtk_widget_hide( w );
120 item = item->next;
121 };
122
123 return TRUE;
124 };
125
126 int wxRadioBox::FindString( const wxString& WXUNUSED(s) ) const
127 {
128 return 0;
129 };
130
131 void wxRadioBox::SetSelection( int WXUNUSED(n) )
132 {
133 };
134
135 int wxRadioBox::GetSelection(void) const
136 {
137 GSList *item = gtk_radio_button_group( m_radio );
138 int count = 0;
139 while (item)
140 {
141 GtkButton *button = GTK_BUTTON( item->data );
142 if (GTK_TOGGLE_BUTTON(button)->active) return count;
143 count++;
144 item = item->next;
145 };
146 return -1;
147 };
148
149 wxString wxRadioBox::GetString( int WXUNUSED(n) ) const
150 {
151 return "";
152 };
153
154 wxString wxRadioBox::GetLabel(void) const
155 {
156 return wxControl::GetLabel();
157 };
158
159 void wxRadioBox::SetLabel( const wxString& WXUNUSED(label) )
160 {
161 };
162
163 void wxRadioBox::SetLabel( int WXUNUSED(item), const wxString& WXUNUSED(label) )
164 {
165 };
166
167 void wxRadioBox::SetLabel( int WXUNUSED(item), wxBitmap *WXUNUSED(bitmap) )
168 {
169 };
170
171 wxString wxRadioBox::GetLabel( int WXUNUSED(item) ) const
172 {
173 return "";
174 };
175
176 void wxRadioBox::Enable( bool WXUNUSED(enable) )
177 {
178 };
179
180 void wxRadioBox::Enable( int WXUNUSED(item), bool WXUNUSED(enable) )
181 {
182 };
183
184 void wxRadioBox::Show( int WXUNUSED(item), bool WXUNUSED(show) )
185 {
186 };
187
188 wxString wxRadioBox::GetStringSelection(void) const
189 {
190 GSList *item = gtk_radio_button_group( m_radio );
191 while (item)
192 {
193 GtkButton *button = GTK_BUTTON( item->data );
194 if (GTK_TOGGLE_BUTTON(button)->active)
195 {
196 GtkLabel *label = GTK_LABEL( button->child );
197 return label->label;
198 };
199 item = item->next;
200 };
201 return "";
202 };
203
204 bool wxRadioBox::SetStringSelection( const wxString& WXUNUSED(s) )
205 {
206 return TRUE;
207 };
208
209 int wxRadioBox::Number(void) const
210 {
211 int count = 0;
212 GSList *item = gtk_radio_button_group( m_radio );
213 while (item)
214 {
215 item = item->next;
216 count++;
217 };
218 return count;
219 };
220
221 int wxRadioBox::GetNumberOfRowsOrCols(void) const
222 {
223 return 1;
224 };
225
226 void wxRadioBox::SetNumberOfRowsOrCols( int WXUNUSED(n) )
227 {
228 };
229