core/vgui/impl/gtk2/vgui_gtk2.cxx
Go to the documentation of this file.
00001 // This is core/vgui/impl/gtk2/vgui_gtk2.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_gtk2.h for a description of this file.
00010 
00011 #include "vgui_gtk2.h"
00012 #include <vgui/vgui_gl.h> // glFlush()
00013 #include <gtk/gtk.h>
00014 #include "vgui_gtk2_window.h"
00015 #include "vgui_gtk2_dialog_impl.h"
00016 #ifdef DEBUG
00017 # include <vcl_iostream.h>
00018 #endif
00019 
00020 vgui_gtk2* vgui_gtk2::instance()
00021 {
00022   static vgui_gtk2* instance_ = new vgui_gtk2;
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_gtk2::name() const { return "gtk2"; }
00030 
00031 
00032 //--------------------------------------------------------------------------------
00033 //: Virtual function from vgui.  Initialise the implementation of vgui.
00034 void vgui_gtk2::init(int &argc, char **argv)
00035 {
00036 #ifdef DEBUG
00037   vcl_cerr << "vgui_gtk2::init()\n";
00038 #endif
00039   gtk_init(&argc, &argv);
00040 }
00041 
00042 
00043 //--------------------------------------------------------------------------------
00044 //: Virtual function from vgui.   Runs the event loop.
00045 void vgui_gtk2::run()
00046 {
00047 #ifdef DEBUG
00048   vcl_cerr << "vgui_gtk2::run()\n";
00049 #endif
00050   gtk_main();
00051 }
00052 
00053 void vgui_gtk2::run_one_event()
00054 {
00055   gtk_main_iteration();
00056 }
00057 
00058 void vgui_gtk2::run_till_idle()
00059 {
00060   while (gtk_events_pending()) {
00061     gtk_main_iteration();
00062     glFlush();
00063   }
00064 }
00065 
00066 void vgui_gtk2::flush()
00067 {
00068   glFlush();
00069   run_till_idle();
00070 }
00071 
00072 void vgui_gtk2::quit()
00073 {
00074 #ifdef DEBUG
00075   vcl_cerr << __FILE__ " : terminating GTK+ event loop\n";
00076 #endif
00077   gtk_main_quit(); // capes@robots - causes the gtk event loop to return
00078 }
00079 
00080 //--------------------------------------------------------------------------------
00081 //: Virtual function from vgui.  Creates a new window with a menubar.
00082 vgui_window* vgui_gtk2::produce_window(int width, int height, const vgui_menu& menubar,
00083                                        const char* title)
00084 {
00085   return new vgui_gtk2_window(width, height, menubar, title);
00086 }
00087 
00088 
00089 //--------------------------------------------------------------------------------
00090 //: Virtual function from vgui.  Creates a new window.
00091 vgui_window* vgui_gtk2::produce_window(int width, int height,
00092                                        const char* title)
00093 {
00094   return new vgui_gtk2_window(width, height, title);
00095 }
00096 
00097 
00098 //--------------------------------------------------------------------------------
00099 //: Virtual function from vgui.  Creates a new dialog box.
00100 vgui_dialog_impl* vgui_gtk2::produce_dialog(const char* name)
00101 {
00102   return new vgui_gtk2_dialog_impl(name);
00103 }