-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButtons.cxx
220 lines (183 loc) · 5.52 KB
/
Buttons.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include <gtk/gtk.h>
#include "Buttons.h"
void button_clicked(GtkWidget *button, gpointer user_data)
{
CButton *b=(CButton*)user_data;
b->OnClick();
}
void radio_toggled(GtkWidget *radio, gpointer user_data)
{
CRadioGroup *rg=(CRadioGroup*)user_data;
rg->CheckSelected();
}
void checkbox_toggled(GtkWidget *checkbox, gpointer user_data)
{
CCheckGroup *rg=(CCheckGroup*)user_data;
rg->OnChange(checkbox);
}
GtkWidget *CButton::CreateButtonWidget(const char*caption)
{
return gtk_button_new_with_label (caption);
}
CButton::CButton(GtkWidget *parent,const char*caption)
{
GtkWidget *Button=CreateButtonWidget(caption);
g_signal_connect(Button, "clicked", (GCallback) button_clicked, this);
SetWidget(Button);
SetParent(parent);
}
CButton::~CButton()
{
}
void CButton::SetCaption(const char*caption)
{
gtk_button_set_label(GTK_BUTTON(GetWidget()), caption);
}
void CButton::OnClick()
{
g_print("button clicked\n");
}
//Checkbox
GtkWidget *CCheckBox::CreateButtonWidget(const char*caption)
{
return gtk_check_button_new_with_label (caption);
}
CCheckBox::CCheckBox(GtkWidget *parent,const char*caption)
:CButton(parent,caption)
{
GtkWidget *Checkbox=gtk_check_button_new_with_label (caption);
//g_signal_connect(Checkbox, "clicked", (GCallback) button_clicked, this);
SetWidget(Checkbox);
SetParent(parent);
}
CCheckBox::~CCheckBox()
{
}
bool CCheckBox::GetChecked()
{
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(GetWidget()));
}
void CCheckBox::SetChecked(bool checked)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(GetWidget()),checked);
}
//Radiogroup
CRadioGroup::CRadioGroup(GtkWidget *parent,const char*caption_of_first)
{
radiocount=0;
GtkWidget *Radiogroup=gtk_vbox_new(true,2);
gtk_widget_show(Radiogroup);
GroupMaster=gtk_radio_button_new_with_label_from_widget(NULL, caption_of_first);
gtk_container_add(GTK_CONTAINER(Radiogroup), GroupMaster);
gtk_widget_show(GroupMaster);
//gtk_widget_show(Radiogroup);
//int key=g_object_get_data (G_OBJECT(w),"ClassPointer");
g_object_set_data(G_OBJECT(Radiogroup),"ClassPointer",this);
g_object_set_data(G_OBJECT(GroupMaster),"ID",gpointer(radiocount++));
g_signal_connect(GroupMaster, "toggled", (GCallback) radio_toggled, this);
// g_print("CRadioGroup set Widget [%x]/Parent [%x]\n",int(Radiogroup),int(parent));
SetWidget(Radiogroup);
SetParent(parent);
//gtk_widget_set_size_request (Radiogroup,0,0);
}
CRadioGroup::~CRadioGroup()
{
}
int CRadioGroup::GetChecked()
{
//return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(GetWidget()));
GList *List = gtk_container_get_children (GTK_CONTAINER(GetWidget()));
int l=g_list_length(List);
GtkWidget *w;
for (int i=0; i<l;i++)
{
w = GTK_WIDGET(g_list_nth( List, i )->data);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w))) return i;
};
return -1;
}
void CRadioGroup::SetChecked(int checked)
{
//gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(GetWidget()),checked);
GtkWidget *r=GetItemFromContainer(GTK_CONTAINER(GetWidget()),checked);
if (r) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(r),true);
}
void CRadioGroup::AddRadio(const char* caption)
{
GtkWidget *radio=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(GroupMaster), caption);
gtk_container_add(GTK_CONTAINER(GetWidget()), radio);
g_object_set_data(G_OBJECT(radio),"ID",gpointer(radiocount++));
g_signal_connect(radio, "toggled", (GCallback) radio_toggled, this);
gtk_widget_show(radio);
}
void CRadioGroup::CheckSelected()
{
//g_print("Radiogroup changed [%d]\n",GetChecked());
if (selectedindex!=GetChecked())
{
selectedindex=GetChecked();
OnChange(selectedindex);
}
}
void CRadioGroup::OnChange(int selected)
{
g_print("Radiogroup changed [%d]\n",selected);
}
//Checkgroup
CCheckGroup::CCheckGroup(GtkWidget *parent,const char*caption_of_first)
{
checkcount=0;
GtkWidget *Checkgroup=gtk_vbox_new(true,2);
gtk_widget_show(Checkgroup);
g_object_set_data(G_OBJECT(Checkgroup),"ClassPointer",this);
SetWidget(Checkgroup);
AddCheckBox(caption_of_first);
// g_print("CRadioGroup set Widget [%x]/Parent [%x]\n",int(Radiogroup),int(parent));
SetParent(parent);
//gtk_widget_set_size_request (Radiogroup,0,0);
}
CCheckGroup::~CCheckGroup()
{
}
bool CCheckGroup::GetChecked(int index)
{
//return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(GetWidget()));
GList *List = gtk_container_get_children (GTK_CONTAINER(GetWidget()));
int l=g_list_length(List);
if (index >=0 && index<l)
{
GtkWidget *w;
w = GTK_WIDGET(g_list_nth( List, index )->data);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w))) return true;
}
return false;
}
void CCheckGroup::SetChecked(int index,bool checked)
{
//gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(GetWidget()),item);
GtkWidget *r=GetItemFromContainer(GTK_CONTAINER(GetWidget()),index);
if (r) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(r),checked);
}
void CCheckGroup::AddCheckBox(const char* caption)
{
GtkWidget *checkbox=gtk_check_button_new_with_label(caption);
gtk_container_add(GTK_CONTAINER(GetWidget()), checkbox);
g_object_set_data(G_OBJECT(checkbox),"ID",gpointer(checkcount++));
g_signal_connect(checkbox, "toggled", (GCallback) checkbox_toggled, this);
gtk_widget_show(checkbox);
}
/*
void CCheckGroup::CheckSelected()
{
//g_print("Radiogroup changed [%d]\n",GetChecked());
if (selectedindex!=GetChecked())
{
selectedindex=GetChecked();
OnChange();
}
}
*/
void CCheckGroup::OnChange(GtkWidget *checkbox)
{
g_print("Checkgroup changed\n");
}