#define APPNAME "Radio button"
#include <gtkfc.h>
#include <Gapplication.h>
#include <Gbutton.h>
#include <GcList.h>
#include <GstringFactory.h>
class MyWindow : public Gwindow {
private:
GcList* the_list;
Gbutton* add_button;
Gbutton* remove_button;
Gbutton* print_button;
public:
MyWindow(Gstring s):Gwindow(s)
{
SetLayout(new GboxLayout(Gcontainers::VERTICAL));
Glist* titles = new Glist();
titles->Append(new Gstring("text 1"));
titles->Append(new Gstring("text 2"));
titles->Append(new Gstring("text 3"));
the_list = new GcList(titles);
delete titles;
add_button = new Gbutton(Gstring("Add"));
remove_button = new Gbutton(Gstring("Remove"));
print_button = new Gbutton(Gstring("Print"));
}
~MyWindow()
{
Gapplication::Exit();
}
bool OnInit()
{
Insert(the_list);
Insert(add_button);
Insert(remove_button);
Insert(print_button);
return true;
}
void OnAction(Gwidget* w, GdkEvent* e)
{
if(w == add_button)
{
Glist* l = new Glist();
for(int i=0; i<3; i++)
l->Append(GstringFactory::Next());
the_list->Append(l);
delete l;
}
if(w == remove_button)
{
the_list->Remove(the_list->GetSelectedRow());
}
if(w == print_button)
{
for(int i=0; i<3; i++)
printf("%s\n", the_list->GetText(the_list->GetSelectedRow(), i).c_str());
}
}
protected:
bool OnDestroy(){
return true;
}
};
int main(int argc, char **argv)
{
Gapplication app(APPNAME, argc, argv);
Gwindow *w = new MyWindow(app.GetAppName());
app.Add(w);
w->Show();
app.Run();
return EXIT_SUCCESS;
}