File indexing completed on 2024-05-12 05:34:37
0001 #ifndef oxygentreeviewdata_h 0002 #define oxygentreeviewdata_h 0003 /* 0004 * this file is part of the oxygen gtk engine 0005 * SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 0006 * SPDX-FileCopyrightText: 2010 Ruslan Kabatsayev <b7.10110111@gmail.com> 0007 * 0008 * SPDX-License-Identifier: LGPL-2.0-or-later 0009 */ 0010 #include "../oxygengtkcellinfo.h" 0011 #include "../oxygengtkutils.h" 0012 #include "oxygenhoverdata.h" 0013 #include "oxygensignal.h" 0014 0015 #include <gtk/gtk.h> 0016 #include <algorithm> 0017 0018 namespace Oxygen 0019 { 0020 class TreeViewData: public HoverData 0021 { 0022 0023 public: 0024 0025 //! constructor 0026 TreeViewData( void ): 0027 _cursor(0L), 0028 _target(0L), 0029 _fullWidth( false ), 0030 _x(-1), 0031 _y(-1), 0032 _dirty( false ) 0033 {} 0034 0035 //! destructor 0036 virtual ~TreeViewData( void ) 0037 { disconnect( _target ); } 0038 0039 //! setup connections 0040 void connect( GtkWidget* ); 0041 0042 //! disconnect 0043 void disconnect( GtkWidget* ); 0044 0045 //! set cursor 0046 void setCursor( GdkCursor* cursor ) 0047 { 0048 if( _cursor == cursor ) return; 0049 _cursor = cursor; 0050 updateColumnsCursor(); 0051 } 0052 0053 //! full width flag 0054 void setFullWidth( bool value ) 0055 { _fullWidth = value; } 0056 0057 //! true when hovered cell needs update 0058 bool isDirty( void ) const 0059 { return _dirty; } 0060 0061 //! update hovered cell using stored position 0062 void updateHoveredCell( void ); 0063 0064 //! true if cell info is hovered 0065 bool isCellHovered( const Gtk::CellInfo& cellInfo ) const 0066 { return isCellHovered( cellInfo, _fullWidth ); } 0067 0068 //! true if cell info is hovered 0069 bool isCellHovered( const Gtk::CellInfo& cellInfo, bool fullWidth ) const 0070 { return hovered() && (fullWidth || cellInfo.sameColumn( _cellInfo ) ) && cellInfo.samePath( _cellInfo ); } 0071 0072 protected: 0073 0074 //! mark as dirty 0075 /* returns true if dirty state changed */ 0076 bool setDirty( bool value ) 0077 { 0078 if( _dirty == value ) return false; 0079 _dirty = value; 0080 return true; 0081 } 0082 0083 //! set mouse over state 0084 virtual bool setHovered( GtkWidget* widget, bool value ); 0085 0086 //! update columns cursor 0087 void updateColumnsCursor( void ) const; 0088 0089 //! update hovered cell based on pointer position 0090 void updatePosition( GtkWidget*, int x, int y ); 0091 0092 //! update hovered cell based on previous pointer position 0093 void updatePosition( GtkWidget* widget ) 0094 { updatePosition( widget, _x, _y ); } 0095 0096 //! update pointer position 0097 void clearPosition( GtkWidget* = 0L ); 0098 0099 //! repaint selection 0100 void triggerRepaint( void ); 0101 0102 //! handles scrollbar value change 0103 class ScrollBarData 0104 { 0105 public: 0106 0107 //! constructor 0108 ScrollBarData( void ): 0109 _widget( 0L ) 0110 {} 0111 0112 //! destructor 0113 virtual ~ScrollBarData( void ) 0114 {} 0115 0116 //! disconnect all signals 0117 void disconnect( void ); 0118 0119 GtkWidget* _widget; 0120 Signal _destroyId; 0121 Signal _valueChangedId; 0122 }; 0123 0124 //!@name child (scrollbars) handling 0125 //@{ 0126 void registerScrollBars( GtkWidget* ); 0127 void registerChild( GtkWidget*, ScrollBarData& ); 0128 void unregisterChild( GtkWidget* ); 0129 //@} 0130 0131 //!@name static callbacks 0132 //@{ 0133 static gboolean childDestroyNotifyEvent( GtkWidget*, gpointer ); 0134 static void childValueChanged( GtkRange*, gpointer ); 0135 static void columnsChanged( GtkTreeView*, gpointer ); 0136 static gboolean motionNotifyEvent( GtkWidget*, GdkEventMotion*, gpointer ); 0137 //@} 0138 0139 private: 0140 0141 //! cursor 0142 /*! associated to columns, for resize */ 0143 GdkCursor* _cursor; 0144 0145 //! target widget 0146 GtkWidget* _target; 0147 0148 //!@name callbacks ids 0149 //@{ 0150 Signal _motionId; 0151 Signal _columnsChangedId; 0152 //@} 0153 0154 //! true if hover works on full width 0155 bool _fullWidth; 0156 0157 //! keep track of the hovered path and column 0158 Gtk::CellInfo _cellInfo; 0159 0160 /*! 0161 keep last position (window_bin coordinates) used to find 0162 hovered cell 0163 */ 0164 int _x; 0165 int _y; 0166 0167 //! true when hovered cell needs to be updated 0168 bool _dirty; 0169 0170 //! vertical scrollbar data 0171 ScrollBarData _vScrollBar; 0172 0173 //! horizontal scrollbar data 0174 ScrollBarData _hScrollBar; 0175 0176 }; 0177 0178 } 0179 0180 #endif