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         GtkStyle* style( gtk_widget_get_style( widget ) );
67         if( !( style && style->depth >= 0 ) ) return;
68 
69         // adjust depth
70         if( style->depth == gdk_drawable_get_depth( window ) )
71         { return; }
72 
73         #if OXYGEN_DEBUG
74         std::cerr
75             << "Oxygen::MenuItemData::attachStyle -"
76             << " widget: " << widget << " (" <<G_OBJECT_TYPE_NAME( widget ) << ")"
77             << " style depth: " << style->depth
78             << " window depth: " << gdk_drawable_get_depth( window )
79             << std::endl;
80         #endif
81 
82         widget->style = gtk_style_attach( style, window );
83 
84         // if widget is a container, we need to do the same for its children
85         if( !GTK_IS_CONTAINER( widget ) ) return;
86 
87         // get children
88         GList* children( gtk_container_get_children( GTK_CONTAINER( widget ) ) );
89         for( GList *child = g_list_first( children ); child; child = g_list_next( child ) )
90         {
91             if( !GTK_IS_WIDGET( child->data ) ) continue;
92             attachStyle( GTK_WIDGET( child->data ), window );
93         }
94 
95         if( children ) g_list_free( children );
96 
97     }
98 
99 
100 }
101