/* * button.cpp * lun sep 23 23:35:56 EDT 2002 * * ---------------------------------------------------------------------- * * display a simple window with a button inside. * The button must be a variable of the class. * The OnAction method is overriden to handle the event * produced by the button click. * * ---------------------------------------------------------------------- * * Compile with g++ `gtkfc-config --cflags` button.cpp -o button `gtkfc-config --libs` */ #define APPNAME "Button test" #include <gtkfc.h> #include <Gapplication.h> #include <Gbutton.h> class MyWindow : public Gwindow { private: Gbutton* the_button; public: MyWindow(Gstring s):Gwindow(s) { the_button = new Gbutton(Gstring("Push me to print hello on stdout")); SetLayout(new GboxLayout(Gcontainers::VERTICAL)); } ~MyWindow() { // DO NOT delete the_button. it was deleted in the widget tree !!! Gapplication::Exit(); } bool OnInit() { Insert(the_button); return true; } void OnAction(Gwidget* w, GdkEvent* e) { if(w == the_button) printf("hello\n"); } 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; }