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

0001 /*
0002     oxygenwidgetexplorer.h
0003     printout widget information on button press, for debugging
0004     -------------------
0005 
0006     SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0007 
0008     Largely inspired from Qtcurve style
0009     SPDX-FileCopyrightText: 2003-2010 Craig Drummond <craig.p.drummond@gmail.com>
0010 
0011     SPDX-License-Identifier: LGPL-2.0-or-later
0012 */
0013 
0014 #include "oxygenwidgetexplorer.h"
0015 #include "config.h"
0016 
0017 #include <iostream>
0018 
0019 namespace Oxygen
0020 {
0021     //___________________________________________________________
0022     WidgetExplorer::WidgetExplorer( void ):
0023         _enabled( false ),
0024         _hooksInitialized( false )
0025     {
0026 
0027         #if OXYGEN_DEBUG
0028         std::cerr << "Oxygen::WidgetExplorer::WidgetExplorer" << std::endl;
0029         #endif
0030 
0031     }
0032 
0033 
0034     //_________________________________________________
0035     WidgetExplorer::~WidgetExplorer( void )
0036     {
0037 
0038         #if OXYGEN_DEBUG
0039         std::cerr << "Oxygen::WidgetExplorer::~WidgetExplorer" << std::endl;
0040         #endif
0041 
0042         _buttonPressHook.disconnect();
0043 
0044     }
0045 
0046     //_________________________________________________
0047     void WidgetExplorer::initializeHooks( void )
0048     {
0049         if( _hooksInitialized ) return;
0050 
0051         _buttonPressHook.connect( "button-press-event", (GSignalEmissionHook)buttonPressHook, this );
0052         _hooksInitialized = true;
0053     }
0054 
0055     //_________________________________________________
0056     void WidgetExplorer::setEnabled( bool value )
0057     { _enabled = value; }
0058 
0059     //_________________________________________________________________
0060     gboolean WidgetExplorer::buttonPressHook( GSignalInvocationHint*, guint, const GValue* params, gpointer data )
0061     {
0062 
0063         // cast data to window manager
0064         WidgetExplorer &explorer( *static_cast<WidgetExplorer*>(data) );
0065         if( !explorer._enabled ) return TRUE;
0066 
0067         // get widget from params
0068         GtkWidget* widget( GTK_WIDGET( g_value_get_object( params ) ) );
0069         if( !GTK_IS_WIDGET( widget ) ) return TRUE;
0070 
0071         std::cerr << "Oxygen::WidgetExplorer::buttonPressHook -";
0072         int row( 0 );
0073         for( GtkWidget* parent = widget; parent; parent = gtk_widget_get_parent( parent ) )
0074         {
0075 
0076             if( row ) std::cerr << " parent:";
0077             std::cerr << " " << parent<< " (" << G_OBJECT_TYPE_NAME( parent ) << ")" << std::endl;
0078             ++row;
0079         }
0080         if( row > 1 ) std::cerr << std::endl;
0081         return TRUE;
0082 
0083     }
0084 
0085 }