File indexing completed on 2024-05-12 05:34:34

0001 /*
0002     this file is part of the oxygen gtk engine
0003     SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0004     SPDX-FileCopyrightText: 2010 Ruslan Kabatsayev <b7.10110111@gmail.com>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #include "oxygenmenuitemdata.h"
0010 #include "../oxygengtkutils.h"
0011 #include "../config.h"
0012 
0013 #include <gtk/gtk.h>
0014 
0015 namespace Oxygen
0016 {
0017 
0018     //________________________________________________________________________________
0019     void MenuItemData::connect( GtkWidget* widget )
0020     {
0021         _target = widget;
0022         _parentSetId.connect( G_OBJECT(widget), "parent-set", G_CALLBACK( parentSet ), this);
0023     }
0024 
0025     //________________________________________________________________________________
0026     void MenuItemData::disconnect( GtkWidget* widget )
0027     {
0028         _target = 0L;
0029         _parentSetId.disconnect();
0030     }
0031 
0032     //_____________________________________________________
0033     void MenuItemData::parentSet( GtkWidget* widget, GtkWidget*, gpointer data )
0034     {
0035 
0036         // check type
0037         if( !GTK_IS_WIDGET( widget ) ) return;
0038 
0039         // retrieve parent window and check
0040         GdkWindow* window( gtk_widget_get_parent_window( widget ) );
0041         if( !window ) return;
0042 
0043         static_cast<const MenuItemData*>(data)->attachStyle( widget, window );
0044         return;
0045 
0046     }
0047 
0048     //_____________________________________________________
0049     void MenuItemData::attachStyle( GtkWidget* widget, GdkWindow* window ) const
0050     {
0051 
0052         // retrieve widget style and check
0053         GtkStyle* style( gtk_widget_get_style( widget ) );
0054         if( !( style && style->depth >= 0 ) ) return;
0055 
0056         // adjust depth
0057         if( style->depth == gdk_drawable_get_depth( window ) )
0058         { return; }
0059 
0060         #if OXYGEN_DEBUG
0061         std::cerr
0062             << "Oxygen::MenuItemData::attachStyle -"
0063             << " widget: " << widget << " (" <<G_OBJECT_TYPE_NAME( widget ) << ")"
0064             << " style depth: " << style->depth
0065             << " window depth: " << gdk_drawable_get_depth( window )
0066             << std::endl;
0067         #endif
0068 
0069         widget->style = gtk_style_attach( style, window );
0070 
0071         // if widget is a container, we need to do the same for its children
0072         if( !GTK_IS_CONTAINER( widget ) ) return;
0073 
0074         // get children
0075         GList* children( gtk_container_get_children( GTK_CONTAINER( widget ) ) );
0076         for( GList *child = g_list_first( children ); child; child = g_list_next( child ) )
0077         {
0078             if( !GTK_IS_WIDGET( child->data ) ) continue;
0079             attachStyle( GTK_WIDGET( child->data ), window );
0080         }
0081 
0082         if( children ) g_list_free( children );
0083 
0084     }
0085 
0086 
0087 }