GtkFC API Reference version 0.1.0

Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members   Examples  

askyesno.cpp

/* 
 * askyesno.cpp
 * mar sep 24 16:23:42 EDT 2002
 * ----------------------------------------------------------------------
 *
 * display a dialog box when window close.
 * The virtual void Action() is used
 * to delete the main window if the ok button
 * is pressed.
 *
 * ----------------------------------------------------------------------
 *
 * Compile with g++ `gtkfc-config --cflags` askyesno.cpp -o askyesno `gtkfc-config --libs` 
 */

#define APPNAME "Ask Yes or No"

#include <gtkfc.h>
#include <Gapplication.h>
#include <Gdialog.h>
#include <Glabel.h>

class MyWindow : public Gwindow {

public:
  MyWindow(Gstring s):Gwindow(s)
  {
    SetLayout(new GboxLayout(Gcontainers::VERTICAL));
  }

  ~MyWindow()
  { 
    Gapplication::Exit();
  }

  void OnAction(Gwidget *w, GdkEvent *e)
  {
    // the Action() method of the widgets sending events must be used
    w->Action();
  }

protected:
  bool OnDestroy(){
    /* an internal method class */
    class GyesNo : public Gdialog{
    public:
      Gwindow* w;
      GyesNo(Gstring s, Gwindow* w):Gdialog(s, true){this->w = w;}
      virtual ~GyesNo(){}
      bool OnInit()
      {
    Gdialog::OnInit();
    Insert(new Glabel(Gstring("Do you really want to exit !")));
    return true;
      }
      /* This object will delete the main window 
       * if an event occur and Result() is true */
      void Action()
      {
    if(Result()) 
      {
        GetWindowMgr()->Remove(w);
      }
    else
      {
        // the dialog is closed
        GetWindowMgr()->Remove(this);
      }
      }
    };

    // The dialog is build and displayed
    GyesNo *d = new GyesNo(Gstring("popol"), this);
    GetWindowMgr()->Add(this, d);
    d->Show();
    return false; // dont delete the window, the dialog box will do this itself
  }

};



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;
}


Copyright © 2002 Thibaut Nicolas
Last modified  lun sep 23 23:41:26 EDT 2002