1 /* 2 * this file is part of the oxygen gtk engine 3 * Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or(at your option ) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free 17 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 * MA 02110-1301, USA. 19 */ 20 21 #include "oxygenwidgetstatedata.h" 22 #include "../config.h" 23 24 #include <iostream> 25 26 namespace Oxygen 27 { 28 29 //_____________________________________________ connect(GtkWidget * widget)30 void WidgetStateData::connect( GtkWidget* widget ) 31 { 32 33 #if OXYGEN_DEBUG 34 std::cerr << "Oxygen::WidgetStateData::connect - " << widget << " (" << G_OBJECT_TYPE_NAME( widget ) << ")" << std::endl; 35 #endif 36 37 _target = widget; 38 _timeLine.connect( (GSourceFunc)delayedUpdate, this ); 39 } 40 41 //_____________________________________________ disconnect(GtkWidget * widget)42 void WidgetStateData::disconnect( GtkWidget* widget ) 43 { 44 #if OXYGEN_DEBUG 45 std::cerr << "Oxygen::WidgetStateData::disconnect - " << widget << " (" << G_OBJECT_TYPE_NAME( widget ) << ")" << std::endl; 46 #endif 47 48 _timeLine.disconnect(); 49 _target = 0L; 50 _state = false; 51 } 52 53 //_____________________________________________ updateState(bool state,const GdkRectangle & rect)54 bool WidgetStateData::updateState( bool state, const GdkRectangle& rect ) 55 { 56 57 // always update dirty rect 58 _dirtyRect = rect; 59 60 // check state and update 61 if( state == _state ) return false; 62 63 #if OXYGEN_DEBUG 64 std::cerr 65 << "Oxygen::WidgetStateData::updateState - " 66 << _target << " (" << ( _target ? std::string( G_OBJECT_TYPE_NAME( _target ) ) : "none" ) << ")" 67 << " state: " << state 68 << std::endl; 69 #endif 70 71 _state = state; 72 73 // change direction 74 _timeLine.setDirection( state ? TimeLine::Forward:TimeLine::Backward ); 75 76 // restart timeLine if needed 77 if( _timeLine.isConnected() && !_timeLine.isRunning() ) _timeLine.start(); 78 79 return true; 80 } 81 82 //_____________________________________________ delayedUpdate(gpointer pointer)83 gboolean WidgetStateData::delayedUpdate( gpointer pointer ) 84 { 85 86 WidgetStateData& data( *static_cast<WidgetStateData*>( pointer ) ); 87 88 #if OXYGEN_DEBUG 89 std::cerr 90 << "Oxygen::WidgetStateData::updateState - " 91 << data._target << " (" << G_OBJECT_TYPE_NAME( data._target ) << ")" 92 << " state: " << data._state 93 << " rect: " << data._dirtyRect 94 << " opacity: " << data._timeLine.value() 95 << std::endl; 96 #endif 97 98 if( data._target && gtk_widget_get_realized(data._target) ) 99 { Gtk::gtk_widget_queue_draw( data._target, &data._dirtyRect ); } 100 101 return FALSE; 102 103 } 104 105 } 106