1 // This is core/vgui/impl/gtk/vgui_gtk_adaptor.h 2 #ifndef vgui_gtk_adaptor_h_ 3 #define vgui_gtk_adaptor_h_ 4 //: 5 // \file 6 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford 7 // \date 19 Dec 99 8 // \brief The GTK implementation of vgui_adaptor. 9 10 #include <map> 11 #include <vgui/vgui_adaptor.h> 12 #include <vgui/internals/vgui_adaptor_mixin.h> 13 #ifdef _MSC_VER 14 # include <vcl_msvc_warnings.h> 15 #endif 16 #include <gtk/gtk.h> 17 18 struct vgui_overlay_helper; 19 class vgui_gtk_window; 20 21 //: The GTK implementation of vgui_adaptor. 22 class vgui_gtk_adaptor : public vgui_adaptor, public vgui_adaptor_mixin 23 { 24 public: 25 typedef vgui_adaptor_mixin mixin; 26 27 vgui_gtk_adaptor(vgui_gtk_window* win = 0); 28 ~vgui_gtk_adaptor(); 29 30 // vgui_adaptor methods 31 void swap_buffers(); 32 void make_current(); 33 void post_redraw(); 34 void post_overlay_redraw(); 35 void post_timer(float,int); 36 void post_destroy(); // schedules destruction of parent vgui_window 37 38 void kill_timer(int); 39 get_width()40 unsigned get_width() const {return mixin::width;} get_height()41 unsigned get_height() const {return mixin::height;} bind_popups(vgui_modifier m,vgui_button b)42 void bind_popups(vgui_modifier m, vgui_button b) 43 { mixin::popup_modifier = m; mixin::popup_button = b; } get_popup_bindings(vgui_modifier & m,vgui_button & b)44 void get_popup_bindings(vgui_modifier &m, vgui_button &b) const 45 { m = mixin::popup_modifier; b = mixin::popup_button; } 46 47 void set_default_popup(vgui_menu); 48 vgui_menu get_popup(); 49 50 void draw(); 51 void reshape(); 52 53 // Returns NULL if the empty constructor was used 54 vgui_window* get_window() const; 55 56 // gtk stuff get_glarea_widget()57 GtkWidget *get_glarea_widget() { return widget; } 58 59 private: 60 // main GDK-to-vgui event dispatcher 61 static gint handle(GtkWidget *, GdkEvent *, gpointer); 62 63 // idle callbacks which service pending redraw/destroy posts 64 static gint idle_callback_for_redraw(gpointer data); 65 static gint idle_callback_for_destroy(gpointer data); 66 67 // Flags to prevent queuing of multiple redraw/destroy callbacks 68 bool redraw_requested; 69 bool destroy_requested; 70 71 // pointer to the gtkglarea widget 72 GtkWidget *widget; 73 74 // pointer to the window which contains this adaptor 75 vgui_gtk_window* win_; 76 77 // pointer to overlay emulation data 78 vgui_overlay_helper *ovl_helper; 79 80 //: internal struct for timer 81 struct internal_timer{ 82 gint real_id_; 83 void* callback_ptr_; 84 internal_timerinternal_timer85 internal_timer() : real_id_(0), callback_ptr_(0) { } internal_timerinternal_timer86 internal_timer(gint id, void* p) 87 : real_id_(id), callback_ptr_(p) { } 88 }; 89 90 // map of timers currently in use 91 std::map<int, internal_timer> timers_; 92 93 // This is a place to store any menu passed in, 94 // so that it doesn't go out of scope while the popup is on screen. 95 static vgui_menu last_popup; 96 97 // last position where mouse was seen. 98 int last_mouse_x, last_mouse_y; 99 }; 100 101 #endif // vgui_gtk_adaptor_h_ 102