1 /* 2 * this file is part of the oxygen gtk engine 3 * Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 4 * Copyright (c) 2010 Ruslan Kabatsayev <b7.10110111@gmail.com> 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or(at your option ) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free 18 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 19 * MA 02110-1301, USA. 20 */ 21 22 #include "oxygenmenuitemdata.h" 23 #include "../oxygengtkutils.h" 24 #include "../config.h" 25 26 #include <gtk/gtk.h> 27 28 namespace Oxygen 29 { 30 31 //________________________________________________________________________________ connect(GtkWidget * widget)32 void MenuItemData::connect( GtkWidget* widget ) 33 { 34 _target = widget; 35 _parentSetId.connect( G_OBJECT(widget), "parent-set", G_CALLBACK( parentSet ), this); 36 } 37 38 //________________________________________________________________________________ disconnect(GtkWidget * widget)39 void MenuItemData::disconnect( GtkWidget* widget ) 40 { 41 _target = 0L; 42 _parentSetId.disconnect(); 43 } 44 45 //_____________________________________________________ parentSet(GtkWidget * widget,GtkWidget *,gpointer data)46 void MenuItemData::parentSet( GtkWidget* widget, GtkWidget*, gpointer data ) 47 { 48 49 // check type 50 if( !GTK_IS_WIDGET( widget ) ) return; 51 52 // retrieve parent window and check 53 GdkWindow* window( gtk_widget_get_parent_window( widget ) ); 54 if( !window ) return; 55 56 static_cast<const MenuItemData*>(data)->attachStyle( widget, window ); 57 return; 58 59 } 60 61 //_____________________________________________________ attachStyle(GtkWidget * widget,GdkWindow * window) const62 void MenuItemData::attachStyle( GtkWidget* widget, GdkWindow* window ) const 63 { 64 65 // retrieve widget style and check 66 GtkStyleContext* context( gtk_widget_get_style_context( widget ) ); 67 if( !context ) return; 68 69 #if OXYGEN_DEBUG 70 std::cerr 71 << "Oxygen::MenuItemData::attachStyle -" 72 << " widget: " << widget << " (" <<G_OBJECT_TYPE_NAME( widget ) << ")" 73 << std::endl; 74 #endif 75 76 // TODO: check whether this is needed for gtk+3, and if yes, if working 77 // This is known *not* to work for gtk+2 78 // gtk_widget_set_style( widget, gtk_style_attach( style, window ) ); 79 80 // if widget is a container, we need to do the same for its children 81 if( !GTK_IS_CONTAINER( widget ) ) return; 82 83 // get children 84 GList* children( gtk_container_get_children( GTK_CONTAINER( widget ) ) ); 85 for( GList *child = g_list_first( children ); child; child = g_list_next( child ) ) 86 { 87 if( !GTK_IS_WIDGET( child->data ) ) continue; 88 attachStyle( GTK_WIDGET( child->data ), window ); 89 } 90 91 if( children ) g_list_free( children ); 92 93 } 94 95 96 } 97