1 #ifndef oxygentreeviewdata_h 2 #define oxygentreeviewdata_h 3 /* 4 * this file is part of the oxygen gtk engine 5 * Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 6 * Copyright (c) 2010 Ruslan Kabatsayev <b7.10110111@gmail.com> 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or(at your option ) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free 20 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 21 * MA 02110-1301, USA. 22 */ 23 #include "../oxygengtkcellinfo.h" 24 #include "../oxygengtkutils.h" 25 #include "oxygenhoverdata.h" 26 #include "oxygensignal.h" 27 28 #include <gtk/gtk.h> 29 #include <algorithm> 30 31 namespace Oxygen 32 { 33 class TreeViewData: public HoverData 34 { 35 36 public: 37 38 //! constructor TreeViewData(void)39 TreeViewData( void ): 40 _cursor(0L), 41 _target(0L), 42 _fullWidth( false ), 43 _x(-1), 44 _y(-1), 45 _dirty( false ) 46 {} 47 48 //! destructor ~TreeViewData(void)49 virtual ~TreeViewData( void ) 50 { disconnect( _target ); } 51 52 //! setup connections 53 void connect( GtkWidget* ); 54 55 //! disconnect 56 void disconnect( GtkWidget* ); 57 58 //! set cursor setCursor(GdkCursor * cursor)59 void setCursor( GdkCursor* cursor ) 60 { 61 if( _cursor == cursor ) return; 62 _cursor = cursor; 63 updateColumnsCursor(); 64 } 65 66 //! full width flag setFullWidth(bool value)67 void setFullWidth( bool value ) 68 { _fullWidth = value; } 69 70 //! true when hovered cell needs update isDirty(void)71 bool isDirty( void ) const 72 { return _dirty; } 73 74 //! update hovered cell using stored position 75 void updateHoveredCell( void ); 76 77 //! true if cell info is hovered isCellHovered(const Gtk::CellInfo & cellInfo)78 bool isCellHovered( const Gtk::CellInfo& cellInfo ) const 79 { return isCellHovered( cellInfo, _fullWidth ); } 80 81 //! true if cell info is hovered isCellHovered(const Gtk::CellInfo & cellInfo,bool fullWidth)82 bool isCellHovered( const Gtk::CellInfo& cellInfo, bool fullWidth ) const 83 { return hovered() && (fullWidth || cellInfo.sameColumn( _cellInfo ) ) && cellInfo.samePath( _cellInfo ); } 84 85 protected: 86 87 //! mark as dirty 88 /* returns true if dirty state changed */ setDirty(bool value)89 bool setDirty( bool value ) 90 { 91 if( _dirty == value ) return false; 92 _dirty = value; 93 return true; 94 } 95 96 //! set mouse over state 97 virtual bool setHovered( GtkWidget* widget, bool value ); 98 99 //! update columns cursor 100 void updateColumnsCursor( void ) const; 101 102 //! update hovered cell based on pointer position 103 void updatePosition( GtkWidget*, int x, int y ); 104 105 //! update hovered cell based on previous pointer position updatePosition(GtkWidget * widget)106 void updatePosition( GtkWidget* widget ) 107 { updatePosition( widget, _x, _y ); } 108 109 //! update pointer position 110 void clearPosition( GtkWidget* = 0L ); 111 112 //! repaint selection 113 void triggerRepaint( void ); 114 115 //! handles scrollbar value change 116 class ScrollBarData 117 { 118 public: 119 120 //! constructor ScrollBarData(void)121 ScrollBarData( void ): 122 _widget( 0L ) 123 {} 124 125 //! destructor ~ScrollBarData(void)126 virtual ~ScrollBarData( void ) 127 {} 128 129 //! disconnect all signals 130 void disconnect( void ); 131 132 GtkWidget* _widget; 133 Signal _destroyId; 134 Signal _valueChangedId; 135 }; 136 137 //!@name child (scrollbars) handling 138 //@{ 139 void registerScrollBars( GtkWidget* ); 140 void registerChild( GtkWidget*, ScrollBarData& ); 141 void unregisterChild( GtkWidget* ); 142 //@} 143 144 //!@name static callbacks 145 //@{ 146 static gboolean childDestroyNotifyEvent( GtkWidget*, gpointer ); 147 static void childValueChanged( GtkRange*, gpointer ); 148 static void columnsChanged( GtkTreeView*, gpointer ); 149 static gboolean motionNotifyEvent( GtkWidget*, GdkEventMotion*, gpointer ); 150 //@} 151 152 private: 153 154 //! cursor 155 /*! associated to columns, for resize */ 156 GdkCursor* _cursor; 157 158 //! target widget 159 GtkWidget* _target; 160 161 //!@name callbacks ids 162 //@{ 163 Signal _motionId; 164 Signal _columnsChangedId; 165 //@} 166 167 //! true if hover works on full width 168 bool _fullWidth; 169 170 //! keep track of the hovered path and column 171 Gtk::CellInfo _cellInfo; 172 173 /*! 174 keep last position (window_bin coordinates) used to find 175 hovered cell 176 */ 177 int _x; 178 int _y; 179 180 //! true when hovered cell needs to be updated 181 bool _dirty; 182 183 //! vertical scrollbar data 184 ScrollBarData _vScrollBar; 185 186 //! horizontal scrollbar data 187 ScrollBarData _hScrollBar; 188 189 }; 190 191 } 192 193 #endif 194