From: joncruz Date: Sun, 28 May 2006 06:53:12 +0000 (+0000) Subject: clicking toggles doesn't change selected layer. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9604887a348217c2d981233696057d29be2ca63d;p=inkscape.git clicking toggles doesn't change selected layer. --- diff --git a/ChangeLog b/ChangeLog index 7b5fafb86..4eca93a67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-05-28 Jon A. Cruz + + * src/dialogs/layers-panel.h, src/dialogs/layers-panel.cpp: + + Changed clicking on visibility and locked toggles to not switch + selected layer. + Fixes bug #1495856. + 2006-05-28 Michael Wybrow * src/sp-conn-end-pair.cpp: Detach connectors from empty groups diff --git a/src/dialogs/layers-panel.cpp b/src/dialogs/layers-panel.cpp index 4af154062..2dc7c2a9e 100644 --- a/src/dialogs/layers-panel.cpp +++ b/src/dialogs/layers-panel.cpp @@ -15,6 +15,7 @@ #include #include +#include #include "inkscape.h" @@ -109,6 +110,11 @@ public: return _signal_toggled; } + sigc::signal signal_pre_toggle() + { + return _signal_pre_toggle; + } + Glib::PropertyProxy property_active() { return _property_active.get_proxy(); } Glib::PropertyProxy property_activatable() { return _property_activatable.get_proxy(); } Glib::PropertyProxy< Glib::RefPtr > property_pixbuf_on(); @@ -116,6 +122,25 @@ public: // virtual Glib::PropertyProxy_Base _property_renderable(); //override protected: + + virtual void get_size_vfunc( Gtk::Widget& widget, + const Gdk::Rectangle* cell_area, + int* x_offset, + int* y_offset, + int* width, + int* height ) const + { + Gtk::CellRendererPixbuf::get_size_vfunc( widget, cell_area, x_offset, y_offset, width, height ); + + if ( width ) { + *width += (*width) >> 1; + } + if ( height ) { + *height += (*height) >> 1; + } + } + + virtual void render_vfunc( const Glib::RefPtr& window, Gtk::Widget& widget, const Gdk::Rectangle& background_area, @@ -134,7 +159,9 @@ protected: const Gdk::Rectangle& cell_area, Gtk::CellRendererState flags) { + _signal_pre_toggle.emit(event); _signal_toggled.emit(path); + return false; } @@ -149,6 +176,7 @@ private: Glib::Property< Glib::RefPtr > _property_pixbuf_off; sigc::signal _signal_toggled; + sigc::signal _signal_pre_toggle; }; class LayersPanel::InternalUIBounce @@ -397,6 +425,7 @@ bool LayersPanel::_checkForSelected(const Gtk::TreePath &path, const Gtk::TreeIt _tree.expand_to_path( path ); Glib::RefPtr select = _tree.get_selection(); + select->select(iter); stopGoing = true; @@ -446,6 +475,7 @@ void LayersPanel::_addLayer( SPDocument* doc, SPObject* layer, Gtk::TreeModel::R Glib::RefPtr select = _tree.get_selection(); select->select(iter); + _checkTreeSelection(); } @@ -512,6 +542,19 @@ void LayersPanel::_checkTreeSelection() } } +void LayersPanel::_preToggle( GdkEvent const *event ) +{ + if ( _toggleEvent ) { + gdk_event_free(_toggleEvent); + _toggleEvent = 0; + } + + if ( event && (event->type == GDK_BUTTON_PRESS) ) { + // Make a copy so we can keep it around. + _toggleEvent = gdk_event_copy(const_cast(event)); + } +} + void LayersPanel::_toggled( Glib::ustring const& str, int targetCol ) { Gtk::TreeModel::Children::iterator iter = _tree.get_model()->get_iter(str); @@ -548,6 +591,7 @@ void LayersPanel::_toggled( Glib::ustring const& str, int targetCol ) void LayersPanel::_handleButtonEvent(GdkEventButton* evt) { + // TODO - fix to a better is-popup function if ( (evt->type == GDK_BUTTON_PRESS) && (evt->button == 3) ) { @@ -585,6 +629,34 @@ void LayersPanel::_handleRowChange( Gtk::TreeModel::Path const& path, Gtk::TreeM } } +bool LayersPanel::_rowSelectFunction( Glib::RefPtr const & model, Gtk::TreeModel::Path const & path, bool currentlySelected ) +{ + bool val = true; + if ( !currentlySelected && _toggleEvent ) + { + GdkEvent* event = gtk_get_current_event(); + if ( event ) { + // (keep these checks separate, so we know when to call gdk_event_free() + if ( event->type == GDK_BUTTON_PRESS ) { + GdkEventButton const* target = reinterpret_cast(_toggleEvent); + GdkEventButton const* evtb = reinterpret_cast(event); + + if ( (evtb->window == target->window) + && (evtb->send_event == target->send_event) + && (evtb->time == target->time) + && (evtb->state == target->state) + ) + { + // Ooooh! It's a magic one + val = false; + } + } + gdk_event_free(event); + } + } + return val; +} + /** * Constructor */ @@ -594,7 +666,8 @@ LayersPanel::LayersPanel() : _mgr(0), _desktop(0), _model(0), - _pending(0) + _pending(0), + _toggleEvent(0) { _maxNestDepth = prefs_get_int_attribute_limited("dialogs.layers", "maxDepth", 20, 1, 1000); @@ -608,6 +681,7 @@ LayersPanel::LayersPanel() : ImageToggler* eyeRenderer = manage( new ImageToggler("visible", "hidden") ); int visibleColNum = _tree.append_column("vis", *eyeRenderer) - 1; + eyeRenderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) ); eyeRenderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_VISIBLE) ); eyeRenderer->property_activatable() = true; Gtk::TreeViewColumn* col = _tree.get_column(visibleColNum); @@ -617,6 +691,7 @@ LayersPanel::LayersPanel() : ImageToggler * renderer = manage( new ImageToggler("width_height_lock", "lock_unlocked") ); int lockedColNum = _tree.append_column("lock", *renderer) - 1; + renderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) ); renderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_LOCKED) ); renderer->property_activatable() = true; col = _tree.get_column(lockedColNum); @@ -630,6 +705,7 @@ LayersPanel::LayersPanel() : _tree.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &LayersPanel::_pushTreeSelectionToCurrent) ); + _tree.get_selection()->set_select_function( sigc::mem_fun(*this, &LayersPanel::_rowSelectFunction) ); _tree.get_model()->signal_row_changed().connect( sigc::mem_fun(*this, &LayersPanel::_handleRowChange) ); _tree.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &LayersPanel::_handleButtonEvent) ); @@ -729,6 +805,12 @@ LayersPanel::~LayersPanel() { delete _model; } + + if ( _toggleEvent ) + { + gdk_event_free( _toggleEvent ); + _toggleEvent = 0; + } } diff --git a/src/dialogs/layers-panel.h b/src/dialogs/layers-panel.h index 63cff3ede..263a0105c 100644 --- a/src/dialogs/layers-panel.h +++ b/src/dialogs/layers-panel.h @@ -61,6 +61,7 @@ private: void _fireAction( unsigned int code ); Gtk::MenuItem& _addPopupItem( SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback, int id ); + void _preToggle( GdkEvent const *event ); void _toggled( Glib::ustring const& str, int targetCol ); void _handleButtonEvent(GdkEventButton* evt); @@ -72,6 +73,8 @@ private: void _takeAction( int val ); bool _executeAction(); + bool _rowSelectFunction( Glib::RefPtr const & model, Gtk::TreeModel::Path const & path, bool b ); + void _updateLayer(SPObject *layer); bool _checkForUpdated(const Gtk::TreePath &path, const Gtk::TreeIter& iter, SPObject* layer); @@ -95,6 +98,7 @@ private: SPDesktop* _desktop; ModelColumns* _model; InternalUIBounce* _pending; + GdkEvent* _toggleEvent; Glib::RefPtr _store; std::vector _watching; std::vector _watchingNonTop;