/* * clist.cpp * dim sep 22 22:42:04 EDT 2002 * * ---------------------------------------------------------------------- * * Display a columned list with 3 columns * the add button will add generated strings in list * the remove button will remove the selection * the print button print the selection * * ---------------------------------------------------------------------- * * Compile with g++ `gtkfc-config --cflags` clist.cpp -o clist `gtkfc-config --libs` */ #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)); // initialist the title list 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) { // Add 3 strings to the columned list 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; } // Remove the selection in the columned list if(w == remove_button) { the_list->Remove(the_list->GetSelectedRow()); } // Print the selection 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; }