core/vgui/impl/gtk/vgui_gtk_adaptor.h
Go to the documentation of this file.
00001 // This is core/vgui/impl/gtk/vgui_gtk_adaptor.h
00002 #ifndef vgui_gtk_adaptor_h_
00003 #define vgui_gtk_adaptor_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford
00010 // \date   19 Dec 99
00011 // \brief  The GTK implementation of vgui_adaptor.
00012 
00013 #ifdef __SUNPRO_CC
00014 // <string> breaks if NULL is defined to "(void*)0".
00015 # include <vcl_string.h>
00016 #endif
00017 
00018 #include <vgui/vgui_adaptor.h>
00019 #include <vgui/internals/vgui_adaptor_mixin.h>
00020 #include <vcl_map.h>
00021 #include <gtk/gtk.h>
00022 
00023 struct vgui_overlay_helper;
00024 class vgui_gtk_window;
00025 
00026 //: The GTK implementation of vgui_adaptor.
00027 class vgui_gtk_adaptor : public vgui_adaptor, public vgui_adaptor_mixin
00028 {
00029  public:
00030   typedef vgui_adaptor_mixin mixin;
00031 
00032   vgui_gtk_adaptor(vgui_gtk_window* win = 0);
00033   ~vgui_gtk_adaptor();
00034 
00035   // vgui_adaptor methods
00036   void swap_buffers();
00037   void make_current();
00038   void post_redraw();
00039   void post_overlay_redraw();
00040   void post_timer(float,int);
00041   void post_destroy();  // schedules destruction of parent vgui_window
00042 
00043   void kill_timer(int);
00044 
00045   unsigned get_width() const {return mixin::width;}
00046   unsigned get_height() const {return mixin::height;}
00047   void bind_popups(vgui_modifier m, vgui_button b)
00048   { mixin::popup_modifier = m; mixin::popup_button = b; }
00049   void get_popup_bindings(vgui_modifier &m, vgui_button &b) const
00050   { m = mixin::popup_modifier; b = mixin::popup_button; }
00051 
00052   void set_default_popup(vgui_menu);
00053   vgui_menu get_popup();
00054 
00055   void draw();
00056   void reshape();
00057 
00058   // Returns NULL if the empty constructor was used
00059   vgui_window* get_window() const;
00060 
00061   // gtk stuff
00062   GtkWidget *get_glarea_widget() { return widget; }
00063 
00064  private:
00065   // main GDK-to-vgui event dispatcher
00066   static gint handle(GtkWidget *, GdkEvent *, gpointer);
00067 
00068   // idle callbacks which service pending redraw/destroy posts
00069   static gint idle_callback_for_redraw(gpointer data);
00070   static gint idle_callback_for_destroy(gpointer data);
00071 
00072   // Flags to prevent queuing of multiple redraw/destroy callbacks
00073   bool redraw_requested;
00074   bool destroy_requested;
00075 
00076   // pointer to the gtkglarea widget
00077   GtkWidget *widget;
00078 
00079   // pointer to the window which contains this adaptor
00080   vgui_gtk_window* win_;
00081 
00082   // pointer to overlay emulation data
00083   vgui_overlay_helper *ovl_helper;
00084 
00085   //: internal struct for timer
00086   struct internal_timer{
00087     gint real_id_;
00088     void* callback_ptr_;
00089     
00090     internal_timer() : real_id_(0), callback_ptr_(0) { }
00091     internal_timer(gint id, void* p) 
00092     : real_id_(id), callback_ptr_(p) { }
00093   };
00094     
00095   // map of timers currently in use
00096   vcl_map<int, internal_timer>  timers_;
00097 
00098   // This is a place to store any menu passed in,
00099   // so that it doesn't go out of scope while the popup is on screen.
00100   static vgui_menu last_popup;
00101 
00102   // last position where mouse was seen.
00103   int last_mouse_x, last_mouse_y;
00104 };
00105 
00106 #endif // vgui_gtk_adaptor_h_