File indexing completed on 2024-05-12 17:05:48
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 "oxygenhook.h" 0010 #include "../config.h" 0011 0012 #include <cassert> 0013 #include <iostream> 0014 0015 namespace Oxygen 0016 { 0017 0018 #if OXYGEN_DEBUG 0019 static int counter( 0 ); 0020 #endif 0021 0022 //__________________________________________________________________ 0023 bool Hook::connect( const std::string& signal, GType typeId, GSignalEmissionHook hookFunction, gpointer data ) 0024 { 0025 #if DISABLE_SIGNAL_HOOKS 0026 return false; 0027 #endif 0028 // make sure that signal is not already connected 0029 assert( _signalId == 0 && _hookId == 0 ); 0030 0031 // check type id 0032 if( !g_type_class_peek( typeId ) ) 0033 { 0034 0035 #if OXYGEN_DEBUG 0036 std::cerr << "Oxygen::Hook::connect - typeId " << g_type_name(typeId) << " not yet installed" << std::endl; 0037 #endif 0038 0039 g_type_class_ref( typeId ); 0040 0041 } 0042 0043 // store signal id 0044 _signalId = g_signal_lookup( signal.c_str(), typeId ); 0045 if( !_signalId ) 0046 { 0047 0048 #if OXYGEN_DEBUG 0049 std::cerr << "Oxygen::Hook::connect - signal " << signal << " not installed." << std::endl; 0050 #endif 0051 0052 return false; 0053 0054 } 0055 0056 // store attributes and create connection 0057 _hookId = g_signal_add_emission_hook( 0058 _signalId, 0059 (GQuark)0L, 0060 hookFunction, 0061 data, 0L); 0062 0063 #if OXYGEN_DEBUG 0064 ++counter; 0065 std::cerr << "Oxygen::Hook::connect - hook: " << _hookId << " counter: " << counter << std::endl; 0066 #endif 0067 0068 return true; 0069 0070 } 0071 0072 //____________________________________________________________________ 0073 void Hook::disconnect( void ) 0074 { 0075 #if DISABLE_SIGNAL_HOOKS 0076 return; 0077 #endif 0078 0079 // disconnect signal 0080 if( _signalId > 0 && _hookId > 0 ) 0081 { 0082 0083 #if OXYGEN_DEBUG 0084 --counter; 0085 std::cerr << "Oxygen::Hook::disconnect - hook: " << _hookId << " counter: " << counter << std::endl; 0086 #endif 0087 0088 g_signal_remove_emission_hook( _signalId, _hookId ); 0089 0090 } 0091 0092 _signalId = 0; 0093 _hookId = 0; 0094 0095 } 0096 0097 }