core/vgui/impl/gtk/vgui_gtk.cxx
Go to the documentation of this file.
00001 // This is core/vgui/impl/gtk/vgui_gtk.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author Philip C. Pritchett, RRG, University of Oxford
00008 // \date   16 Sep 99
00009 // \brief  See vgui_gtk.h for a description of this file.
00010 
00011 
00012 #include "vgui_gtk.h"
00013 #include <vgui/vgui_gl.h> // glFlush()
00014 #include <gtk/gtk.h>
00015 #include "vgui_gtk_window.h"
00016 #include "vgui_gtk_dialog_impl.h"
00017 
00018 static bool debug = false;
00019 
00020 vgui_gtk* vgui_gtk::instance()
00021 {
00022   static vgui_gtk* instance_ = new vgui_gtk;
00023   return instance_;
00024 }
00025 
00026 //--------------------------------------------------------------------------------
00027 //: Pure virtual function from vgui (this must be implemented).
00028 //  Returns the name of the GUI toolkit.
00029 vcl_string vgui_gtk::name() const { return "gtk"; }
00030 
00031 
00032 //--------------------------------------------------------------------------------
00033 //: Virtual function from vgui.  Initialise the implementation of vgui.
00034 void vgui_gtk::init(int &argc, char **argv)
00035 {
00036   if (debug) vcl_cerr << "vgui_gtk::init()\n";
00037   gtk_init(&argc, &argv);
00038 }
00039 
00040 
00041 //--------------------------------------------------------------------------------
00042 //: Virtual function from vgui.   Runs the event loop.
00043 void vgui_gtk::run()
00044 {
00045   if (debug) vcl_cerr << "vgui_gtk::run()\n";
00046   gtk_main();
00047 }
00048 
00049 void vgui_gtk::run_one_event()
00050 {
00051   gtk_main_iteration();
00052 }
00053 
00054 void vgui_gtk::run_till_idle()
00055 {
00056   while (gtk_events_pending()) {
00057     gtk_main_iteration();
00058     glFlush();
00059   }
00060 }
00061 
00062 void vgui_gtk::flush()
00063 {
00064   glFlush();
00065   run_till_idle();
00066 }
00067 
00068 void vgui_gtk::quit()
00069 {
00070   vcl_cerr << __FILE__ " : terminating GTK+ event loop\n";
00071   gtk_main_quit(); // capes@robots -- causes the gtk event loop to return
00072 }
00073 
00074 //--------------------------------------------------------------------------------
00075 //: Virtual function from vgui.  Creates a new window with a menubar.
00076 vgui_window* vgui_gtk::produce_window(int width, int height, const vgui_menu& menubar,
00077                                       const char* title)
00078 {
00079   return new vgui_gtk_window(width, height, menubar, title);
00080 }
00081 
00082 
00083 //--------------------------------------------------------------------------------
00084 //: Virtual function from vgui.  Creates a new window.
00085 vgui_window* vgui_gtk::produce_window(int width, int height,
00086                                       const char* title)
00087 {
00088   return new vgui_gtk_window(width, height, title);
00089 }
00090 
00091 
00092 //--------------------------------------------------------------------------------
00093 //: Virtual function from vgui.  Creates a new dialog box.
00094 vgui_dialog_impl* vgui_gtk::produce_dialog(const char* name)
00095 {
00096   return new vgui_gtk_dialog_impl(name);
00097 }