File indexing completed on 2024-05-12 17:05:50
0001 /* 0002 this file is part of the oxygen gtk engine 0003 SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "oxygentabwidgetstatedata.h" 0009 #include "../oxygengtkutils.h" 0010 #include "../config.h" 0011 0012 #include <iostream> 0013 0014 namespace Oxygen 0015 { 0016 0017 //_____________________________________________ 0018 const int TabWidgetStateData::IndexInvalid = -1; 0019 0020 //_____________________________________________ 0021 void TabWidgetStateData::connect( GtkWidget* widget ) 0022 { 0023 0024 #if OXYGEN_DEBUG 0025 std::cerr << "Oxygen::TabWidgetStateData::connect - " << widget << " (" << G_OBJECT_TYPE_NAME( widget ) << ")" << std::endl; 0026 #endif 0027 0028 _target = widget; 0029 0030 // connect timeLines 0031 _current._timeLine.connect( (GSourceFunc)delayedUpdate, this ); 0032 _previous._timeLine.connect( (GSourceFunc)delayedUpdate, this ); 0033 0034 // set directions 0035 _current._timeLine.setDirection( TimeLine::Forward ); 0036 _previous._timeLine.setDirection( TimeLine::Backward ); 0037 0038 } 0039 0040 //_____________________________________________ 0041 void TabWidgetStateData::disconnect( GtkWidget* widget ) 0042 { 0043 #if OXYGEN_DEBUG 0044 std::cerr << "Oxygen::TabWidgetStateData::disconnect - " << widget << " (" << G_OBJECT_TYPE_NAME( widget ) << ")" << std::endl; 0045 #endif 0046 0047 _current._timeLine.disconnect(); 0048 _current._index = IndexInvalid; 0049 0050 _previous._timeLine.disconnect(); 0051 _previous._index = IndexInvalid; 0052 0053 _target = 0L; 0054 0055 } 0056 0057 //_____________________________________________ 0058 bool TabWidgetStateData::updateState( int index, bool state ) 0059 { 0060 if( state && index != _current._index ) 0061 { 0062 0063 // stop current animation if running 0064 if( _current._timeLine.isRunning() ) _current._timeLine.stop(); 0065 0066 // stop previous animation if running 0067 if( _current._index != IndexInvalid ) 0068 { 0069 if( _previous._timeLine.isRunning() ) _previous._timeLine.stop(); 0070 0071 // move current tab index to previous 0072 _previous._index = _current._index; 0073 _previous._timeLine.start(); 0074 } 0075 0076 // assign new index to current and start animation 0077 _current._index = index; 0078 if( _current._index != IndexInvalid ) _current._timeLine.start(); 0079 0080 return true; 0081 0082 } else if( (!state) && index == _current._index ) { 0083 0084 // stop current animation if running 0085 if( _current._timeLine.isRunning() ) _current._timeLine.stop(); 0086 0087 // stop previous animation if running 0088 if( _previous._timeLine.isRunning() ) _previous._timeLine.stop(); 0089 0090 // move current tab index to previous 0091 _previous._index = _current._index; 0092 if( _previous._index != IndexInvalid ) _previous._timeLine.start(); 0093 0094 // assign invalid index to current 0095 _current._index = IndexInvalid; 0096 0097 return true; 0098 0099 } else return false; 0100 0101 } 0102 0103 //_____________________________________________ 0104 GdkRectangle TabWidgetStateData::dirtyRect( void ) const 0105 { 0106 0107 // FIXME: it might be enough to union the rects of the current and previous tab 0108 if( GTK_IS_NOTEBOOK( _target ) ) 0109 { 0110 0111 GdkRectangle rect( Gtk::gdk_rectangle() ); 0112 Gtk::gtk_notebook_get_tabbar_rect( GTK_NOTEBOOK( _target ), &rect ); 0113 0114 #if OXYGEN_DEBUG 0115 std::cerr << "Oxygen::TabWidgetData::dirtyRect - " << rect << std::endl; 0116 #endif 0117 0118 return rect; 0119 0120 } else { 0121 0122 return Gtk::gtk_widget_get_allocation( _target ); 0123 0124 } 0125 0126 } 0127 0128 //_____________________________________________ 0129 gboolean TabWidgetStateData::delayedUpdate( gpointer pointer ) 0130 { 0131 0132 TabWidgetStateData& data( *static_cast<TabWidgetStateData*>( pointer ) ); 0133 0134 if( !data._target ) return FALSE; 0135 0136 const GdkRectangle rect( data.dirtyRect() ); 0137 Gtk::gtk_widget_queue_draw( data._target, &rect ); 0138 return FALSE; 0139 0140 } 0141 0142 }