1 /* 2 * this file is part of the oxygen gtk engine 3 * Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 4 * 5 * the hover data code is largely inspired from the gtk redmond engine 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or(at your option ) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 20 * MA 02110-1301, USA. 21 */ 22 23 #include "oxygenhoverdata.h" 24 #include "../oxygengtkutils.h" 25 #include "../config.h" 26 27 #include <gtk/gtk.h> 28 #include <iostream> 29 30 namespace Oxygen 31 { 32 33 //________________________________________________________________________________ connect(GtkWidget * widget)34 void HoverData::connect( GtkWidget* widget ) 35 { 36 37 #if OXYGEN_DEBUG 38 std::cerr << "Oxygen::HoverData::connect - " << widget << " (" << (widget ? G_OBJECT_TYPE_NAME( widget ):"null") << ")" << std::endl; 39 #endif 40 41 const bool enabled( gtk_widget_get_state( widget ) != GTK_STATE_INSENSITIVE ); 42 43 // on connection, needs to check whether mouse pointer is in widget or not 44 // to have the proper initial value of the hover flag 45 if( enabled ) 46 { 47 48 gint xPointer,yPointer; 49 gdk_window_get_pointer( gtk_widget_get_window( widget ), &xPointer, &yPointer, 0L); 50 const GtkAllocation allocation( Gtk::gtk_widget_get_allocation( widget ) ); 51 const GdkRectangle rect( Gtk::gdk_rectangle( 0, 0, allocation.width, allocation.height ) ); 52 setHovered( widget, Gtk::gdk_rectangle_contains( &rect, xPointer, yPointer ) ); 53 54 } else { 55 56 setHovered( widget, false ); 57 58 } 59 60 // register callbacks 61 _enterId.connect( G_OBJECT(widget), "enter-notify-event", G_CALLBACK( enterNotifyEvent ), this ); 62 _leaveId.connect( G_OBJECT(widget), "leave-notify-event", G_CALLBACK( leaveNotifyEvent ), this ); 63 } 64 65 //________________________________________________________________________________ disconnect(GtkWidget * widget)66 void HoverData::disconnect( GtkWidget* widget ) 67 { 68 #if OXYGEN_DEBUG 69 std::cerr << "Oxygen::HoverData::disconnect - " << widget << " (" << (widget ? G_OBJECT_TYPE_NAME( widget ):"null") << ")" << std::endl; 70 #endif 71 72 _enterId.disconnect(); 73 _leaveId.disconnect(); 74 } 75 76 //________________________________________________________________________________ enterNotifyEvent(GtkWidget * widget,GdkEventCrossing *,gpointer data)77 gboolean HoverData::enterNotifyEvent(GtkWidget* widget, GdkEventCrossing*, gpointer data ) 78 { 79 #if OXYGEN_DEBUG 80 std::cerr << "HoverData::enterNotifyEvent - " << widget << " (" << G_OBJECT_TYPE_NAME( widget ) << ")" << std::endl; 81 #endif 82 83 static_cast<HoverData*>( data )->setHovered( widget, true ); 84 return FALSE; 85 } 86 87 //________________________________________________________________________________ leaveNotifyEvent(GtkWidget * widget,GdkEventCrossing *,gpointer data)88 gboolean HoverData::leaveNotifyEvent( GtkWidget* widget, GdkEventCrossing*, gpointer data ) 89 { 90 #if OXYGEN_DEBUG 91 std::cerr << "Oxygen::HoverData::leaveNotifyEvent - " << widget << " (" << G_OBJECT_TYPE_NAME( widget ) << ")" << std::endl; 92 #endif 93 94 static_cast<HoverData*>( data )->setHovered( widget, false ); 95 return FALSE; 96 } 97 98 } 99