Code

Added the ability to toggle a layer "solo". Fixes bug #171530.
[inkscape.git] / src / dialogs / layers-panel.cpp
1 /*
2  * A simple panel for layers
3  *
4  * Authors:
5  *   Jon A. Cruz
6  *
7  * Copyright (C) 2006 Jon A. Cruz
8  *
9  * Released under GNU GPL, read the file 'COPYING' for more information
10  */
11 #ifdef HAVE_CONFIG_H
12 # include <config.h>
13 #endif
15 #include <glibmm/i18n.h>
17 #include <gtk/gtkstock.h>
18 #include <gtk/gtkmain.h>
20 #include "inkscape.h"
22 #include "layers-panel.h"
24 #include "layer-manager.h"
25 #include "layer-fns.h"
27 #include "verbs.h"
28 #include "helper/action.h"
30 #include "document.h"
31 #include "desktop.h"
32 #include "sp-object.h"
33 #include "sp-item.h"
34 #include "widgets/icon.h"
35 #include <gtkmm/widget.h>
36 #include "prefs-utils.h"
37 #include "xml/repr.h"
38 #include "svg/css-ostringstream.h"
39 #include "desktop-style.h"
41 //#define DUMP_LAYERS 1
43 namespace Inkscape {
44 namespace UI {
45 namespace Dialogs {
47 LayersPanel&
48 LayersPanel::getInstance()
49 {
50     return *new LayersPanel();
51 }
53 enum {
54     COL_VISIBLE = 1,
55     COL_LOCKED
56 };
58 enum {
59     BUTTON_NEW = 0,
60     BUTTON_RENAME,
61     BUTTON_TOP,
62     BUTTON_BOTTOM,
63     BUTTON_UP,
64     BUTTON_DOWN,
65 //    BUTTON_DUPLICATE,
66     BUTTON_DELETE,
67     BUTTON_SOLO
68 };
70 class ImageToggler : public Gtk::CellRendererPixbuf {
71 public:
72     ImageToggler( char const* on, char const* off) :
73         Glib::ObjectBase(typeid(ImageToggler)),
74         Gtk::CellRendererPixbuf(),
75         _pixOnName(on),
76         _pixOffName(off),
77         _property_active(*this, "active", false),
78         _property_activatable(*this, "activatable", true),
79         _property_pixbuf_on(*this, "pixbuf_on", Glib::RefPtr<Gdk::Pixbuf>(0)),
80         _property_pixbuf_off(*this, "pixbuf_off", Glib::RefPtr<Gdk::Pixbuf>(0))
81     {
82         property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
84         Gtk::Widget* thingie = sp_icon_get_icon(_pixOnName.c_str(), Inkscape::ICON_SIZE_DECORATION);
85         if ( thingie ) {
86             if ( SP_IS_ICON(thingie->gobj()) ) {
87                 SPIcon* icon = SP_ICON(thingie->gobj());
88                 sp_icon_fetch_pixbuf( icon );
89                 _property_pixbuf_on = Glib::wrap( icon->pb, true );
90             }
91             delete thingie;
92         }
93         thingie = sp_icon_get_icon(_pixOffName.c_str(), Inkscape::ICON_SIZE_DECORATION);
94         if ( thingie ) {
95             if ( SP_IS_ICON(thingie->gobj()) ) {
96                 SPIcon* icon = SP_ICON(thingie->gobj());
97                 sp_icon_fetch_pixbuf( icon );
98                 _property_pixbuf_off = Glib::wrap( icon->pb, true );
99             }
100             delete thingie;
101         }
102         property_pixbuf() = _property_pixbuf_off.get_value();
103     }
105     sigc::signal<void, const Glib::ustring&> signal_toggled()
106     {
107         return _signal_toggled;
108     }
110     sigc::signal<void, GdkEvent const *> signal_pre_toggle()
111     {
112         return _signal_pre_toggle;
113     }
115     Glib::PropertyProxy<bool> property_active() { return _property_active.get_proxy(); }
116     Glib::PropertyProxy<bool> property_activatable() { return _property_activatable.get_proxy(); }
117     Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> > property_pixbuf_on();
118     Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> > property_pixbuf_off();
119 //  virtual Glib::PropertyProxy_Base _property_renderable(); //override
121 protected:
123     virtual void get_size_vfunc( Gtk::Widget& widget,
124                                  const Gdk::Rectangle* cell_area,
125                                  int* x_offset,
126                                  int* y_offset,
127                                  int* width,
128                                  int* height ) const
129     {
130         Gtk::CellRendererPixbuf::get_size_vfunc( widget, cell_area, x_offset, y_offset, width, height );
132         if ( width ) {
133             *width += (*width) >> 1;
134         }
135         if ( height ) {
136             *height += (*height) >> 1;
137         }
138     }
141     virtual void render_vfunc( const Glib::RefPtr<Gdk::Drawable>& window,
142                                Gtk::Widget& widget,
143                                const Gdk::Rectangle& background_area,
144                                const Gdk::Rectangle& cell_area,
145                                const Gdk::Rectangle& expose_area,
146                                Gtk::CellRendererState flags )
147     {
148         property_pixbuf() = _property_active.get_value() ? _property_pixbuf_on : _property_pixbuf_off;
149         Gtk::CellRendererPixbuf::render_vfunc( window, widget, background_area, cell_area, expose_area, flags );
150     }
152     virtual bool activate_vfunc(GdkEvent* event,
153                                 Gtk::Widget& /*widget*/,
154                                 const Glib::ustring& path,
155                                 const Gdk::Rectangle& /*background_area*/,
156                                 const Gdk::Rectangle& /*cell_area*/,
157                                 Gtk::CellRendererState /*flags*/)
158     {
159         _signal_pre_toggle.emit(event);
160         _signal_toggled.emit(path);
162         return false;
163     }
166 private:
167     Glib::ustring _pixOnName;
168     Glib::ustring _pixOffName;
170     Glib::Property<bool> _property_active;
171     Glib::Property<bool> _property_activatable;
172     Glib::Property< Glib::RefPtr<Gdk::Pixbuf> > _property_pixbuf_on;
173     Glib::Property< Glib::RefPtr<Gdk::Pixbuf> > _property_pixbuf_off;
175     sigc::signal<void, const Glib::ustring&> _signal_toggled;
176     sigc::signal<void, GdkEvent const *> _signal_pre_toggle;
177 };
179 class LayersPanel::InternalUIBounce
181 public:
182     int _actionCode;
183     SPObject* _target;
184 };
186 static gboolean layers_panel_activated( GtkObject */*object*/, GdkEvent * /*event*/, gpointer data )
188     if ( data )
189     {
190         LayersPanel* panel = reinterpret_cast<LayersPanel*>(data);
191         panel->setDesktop(panel->getDesktop());
192     }
194     return FALSE;
198 void LayersPanel::_styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback )
200     bool set = false;
202     if ( iconName ) {
203         GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName );
204         gtk_widget_show( child );
205         btn.add( *manage(Glib::wrap(child)) );
206         set = true;
207     }
209     if ( desktop ) {
210         Verb *verb = Verb::get( code );
211         if ( verb ) {
212             SPAction *action = verb->get_action(desktop);
213             if ( !set && action && action->image ) {
214                 GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, action->image );
215                 gtk_widget_show( child );
216                 btn.add( *manage(Glib::wrap(child)) );
217                 set = true;
218             }
220             if ( action && action->tip ) {
221                 _tips.set_tip( btn, action->tip );
222             }
223         }
224     }
226     if ( !set && fallback ) {
227         btn.set_label( fallback );
228     }
232 Gtk::MenuItem& LayersPanel::_addPopupItem( SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback, int id )
234     GtkWidget* iconWidget = 0;
235     const char* label = 0;
237     if ( iconName ) {
238         iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, iconName );
239     }
241     if ( desktop ) {
242         Verb *verb = Verb::get( code );
243         if ( verb ) {
244             SPAction *action = verb->get_action(desktop);
245             if ( !iconWidget && action && action->image ) {
246                 iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, action->image );
247             }
249             if ( action ) {
250                 label = action->name;
251             }
252         }
253     }
255     if ( !label && fallback ) {
256         label = fallback;
257     }
259     Gtk::Widget* wrapped = 0;
260     if ( iconWidget ) {
261         wrapped = manage(Glib::wrap(iconWidget));
262         wrapped->show();
263     }
267     Gtk::Menu::MenuList& menulist = _popupMenu.items();
269     if ( wrapped ) {
270         menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem( label, *wrapped, sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), id)) );
271     } else {
272         menulist.push_back( Gtk::Menu_Helpers::MenuElem( label, sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), id)) );
273     }
274     return menulist.back();
277 void LayersPanel::_fireAction( unsigned int code )
279     if ( _desktop ) {
280         Verb *verb = Verb::get( code );
281         if ( verb ) {
282             SPAction *action = verb->get_action(_desktop);
283             if ( action ) {
284                 sp_action_perform( action, NULL );
285 //             } else {
286 //                 g_message("no action");
287             }
288 //         } else {
289 //             g_message("no verb for %u", code);
290         }
291 //     } else {
292 //         g_message("no active desktop");
293     }
296 //     SP_VERB_LAYER_NEXT,
297 //     SP_VERB_LAYER_PREV,
298 void LayersPanel::_takeAction( int val )
300     if ( !_pending ) {
301         _pending = new InternalUIBounce();
302         _pending->_actionCode = val;
303         _pending->_target = _selectedLayer();
304         Glib::signal_timeout().connect( sigc::mem_fun(*this, &LayersPanel::_executeAction), 0 );
305     }
308 bool LayersPanel::_executeAction()
310     // Make sure selected layer hasn't changed since the action was triggered
311     if ( _pending
312          && (
313              (_pending->_actionCode == BUTTON_NEW)
314              || !( (_desktop && _desktop->currentLayer())
315                    && (_desktop->currentLayer() != _pending->_target)
316                  )
317              )
318         ) {
319         int val = _pending->_actionCode;
320 //        SPObject* target = _pending->_target;
322         switch ( val ) {
323             case BUTTON_NEW:
324             {
325                 _fireAction( SP_VERB_LAYER_NEW );
326             }
327             break;
328             case BUTTON_RENAME:
329             {
330                 _fireAction( SP_VERB_LAYER_RENAME );
331             }
332             break;
333             case BUTTON_TOP:
334             {
335                 _fireAction( SP_VERB_LAYER_TO_TOP );
336             }
337             break;
338             case BUTTON_BOTTOM:
339             {
340                 _fireAction( SP_VERB_LAYER_TO_BOTTOM );
341             }
342             break;
343             case BUTTON_UP:
344             {
345                 _fireAction( SP_VERB_LAYER_RAISE );
346             }
347             break;
348             case BUTTON_DOWN:
349             {
350                 _fireAction( SP_VERB_LAYER_LOWER );
351             }
352             break;
353             case BUTTON_DELETE:
354             {
355                 _fireAction( SP_VERB_LAYER_DELETE );
356             }
357             case BUTTON_SOLO:
358             {
359                 _fireAction( SP_VERB_LAYER_SOLO );
360             }
361             break;
362         }
364         delete _pending;
365         _pending = 0;
366     }
368     return false;
371 class LayersPanel::ModelColumns : public Gtk::TreeModel::ColumnRecord
373 public:
375     ModelColumns()
376     {
377         add(_colObject);
378         add(_colVisible);
379         add(_colLocked);
380         add(_colLabel);
381     }
382     virtual ~ModelColumns() {}
384     Gtk::TreeModelColumn<SPObject*> _colObject;
385     Gtk::TreeModelColumn<Glib::ustring> _colLabel;
386     Gtk::TreeModelColumn<bool> _colVisible;
387     Gtk::TreeModelColumn<bool> _colLocked;
388 };
390 void LayersPanel::_updateLayer( SPObject *layer ) {
391     _store->foreach( sigc::bind<SPObject*>(sigc::mem_fun(*this, &LayersPanel::_checkForUpdated), layer) );
394 bool LayersPanel::_checkForUpdated(const Gtk::TreePath &/*path*/, const Gtk::TreeIter& iter, SPObject* layer)
396     bool stopGoing = false;
397     Gtk::TreeModel::Row row = *iter;
398     Glib::ustring tmp = row[_model->_colLabel];
399     if ( layer == row[_model->_colObject] )
400     {
401         row[_model->_colLabel] = layer->label() ? layer->label() : SP_OBJECT_ID(layer);
402         row[_model->_colVisible] = SP_IS_ITEM(layer) ? !SP_ITEM(layer)->isHidden() : false;
403         row[_model->_colLocked] = SP_IS_ITEM(layer) ? SP_ITEM(layer)->isLocked() : false;
405         stopGoing = true;
406     }
408     return stopGoing;
411 void LayersPanel::_selectLayer( SPObject *layer ) {
412     if ( !layer || (_desktop && _desktop->doc() && (layer == _desktop->doc()->root)) ) {
413         if ( _tree.get_selection()->count_selected_rows() != 0 ) {
414             _tree.get_selection()->unselect_all();
415         }
416     } else {
417         _store->foreach( sigc::bind<SPObject*>(sigc::mem_fun(*this, &LayersPanel::_checkForSelected), layer) );
418     }
420     _checkTreeSelection();
423 bool LayersPanel::_checkForSelected(const Gtk::TreePath &path, const Gtk::TreeIter& iter, SPObject* layer)
425     bool stopGoing = false;
427     Gtk::TreeModel::Row row = *iter;
428     if ( layer == row[_model->_colObject] )
429     {
430         _tree.expand_to_path( path );
432         Glib::RefPtr<Gtk::TreeSelection> select = _tree.get_selection();
434         select->select(iter);
436         stopGoing = true;
437     }
439     return stopGoing;
442 void LayersPanel::_layersChanged()
444 //    g_message("_layersChanged()");
445     SPDocument* document = _desktop->doc();
446     SPObject* root = document->root;
447     if ( root ) {
448         _selectedConnection.block();
449         if ( _mgr && _mgr->includes( root ) ) {
450             SPObject* target = _desktop->currentLayer();
451             _store->clear();
453 #if DUMP_LAYERS
454             g_message("root:%p  {%s}   [%s]", root, root->id, root->label() );
455 #endif // DUMP_LAYERS
456             _addLayer( document, root, 0, target, 0 );
457         }
458         _selectedConnection.unblock();
459     }
462 void LayersPanel::_addLayer( SPDocument* doc, SPObject* layer, Gtk::TreeModel::Row* parentRow, SPObject* target, int level )
464     if ( layer && (level < _maxNestDepth) ) {
465         unsigned int counter = _mgr->childCount(layer);
466         for ( unsigned int i = 0; i < counter; i++ ) {
467             SPObject *child = _mgr->nthChildOf(layer, i);
468             if ( child ) {
469 #if DUMP_LAYERS
470                 g_message(" %3d    layer:%p  {%s}   [%s]", level, child, child->id, child->label() );
471 #endif // DUMP_LAYERS
473                 Gtk::TreeModel::iterator iter = parentRow ? _store->prepend(parentRow->children()) : _store->prepend();
474                 Gtk::TreeModel::Row row = *iter;
475                 row[_model->_colObject] = child;
476                 row[_model->_colLabel] = child->label() ? child->label() : SP_OBJECT_ID(child);
477                 row[_model->_colVisible] = SP_IS_ITEM(child) ? !SP_ITEM(child)->isHidden() : false;
478                 row[_model->_colLocked] = SP_IS_ITEM(child) ? SP_ITEM(child)->isLocked() : false;
480                 if ( target && child == target ) {
481                     _tree.expand_to_path( _store->get_path(iter) );
483                     Glib::RefPtr<Gtk::TreeSelection> select = _tree.get_selection();
484                     select->select(iter);
486                     _checkTreeSelection();
487                 }
489                 _addLayer( doc, child, &row, target, level + 1 );
490             }
491         }
492     }
495 SPObject* LayersPanel::_selectedLayer()
497     SPObject* obj = 0;
499     Gtk::TreeModel::iterator iter = _tree.get_selection()->get_selected();
500     if ( iter ) {
501         Gtk::TreeModel::Row row = *iter;
502         obj = row[_model->_colObject];
503     }
505     return obj;
508 void LayersPanel::_pushTreeSelectionToCurrent()
510     SPObject* inTree = _selectedLayer();
511     // TODO hunt down the possible API abuse in getting NULL
512     if ( _desktop->currentRoot() ) {
513         if ( inTree ) {
514             SPObject* curr = _desktop->currentLayer();
515             if ( curr != inTree ) {
516                 _mgr->setCurrentLayer( inTree );
517             }
518         } else {
519             _mgr->setCurrentLayer( _desktop->doc()->root );
520         }
521     }
524 void LayersPanel::_checkTreeSelection()
526     bool sensitive = false;
527     bool sensitiveNonTop = false;
528     bool sensitiveNonBottom = false;
529     if ( _tree.get_selection()->count_selected_rows() > 0 ) {
530         sensitive = true;
532         SPObject* inTree = _selectedLayer();
533         if ( inTree ) {
535             sensitiveNonTop = (Inkscape::next_layer(inTree->parent, inTree) != 0);
536             sensitiveNonBottom = (Inkscape::previous_layer(inTree->parent, inTree) != 0);
538         }
539     }
542     for ( std::vector<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) {
543         (*it)->set_sensitive( sensitive );
544     }
545     for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonTop.begin(); it != _watchingNonTop.end(); ++it ) {
546         (*it)->set_sensitive( sensitiveNonTop );
547     }
548     for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonBottom.begin(); it != _watchingNonBottom.end(); ++it ) {
549         (*it)->set_sensitive( sensitiveNonBottom );
550     }
553 void LayersPanel::_preToggle( GdkEvent const *event )
555     if ( _toggleEvent ) {
556         gdk_event_free(_toggleEvent);
557         _toggleEvent = 0;
558     }
560     if ( event && (event->type == GDK_BUTTON_PRESS) ) {
561         // Make a copy so we can keep it around.
562         _toggleEvent = gdk_event_copy(const_cast<GdkEvent*>(event));
563     }
566 void LayersPanel::_toggled( Glib::ustring const& str, int targetCol )
568     Gtk::TreeModel::Children::iterator iter = _tree.get_model()->get_iter(str);
569     Gtk::TreeModel::Row row = *iter;
571     Glib::ustring tmp = row[_model->_colLabel];
573     SPObject* obj = row[_model->_colObject];
574     SPItem* item = ( obj && SP_IS_ITEM(obj) ) ? SP_ITEM(obj) : 0;
575     if ( item ) {
576         switch ( targetCol ) {
577             case COL_VISIBLE:
578             {
579                 bool newValue = !row[_model->_colVisible];
580                 row[_model->_colVisible] = newValue;
581                 item->setHidden( !newValue  );
582                 item->updateRepr();
583                 sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS,
584                                   newValue? _("Unhide layer") : _("Hide layer"));
585             }
586             break;
588             case COL_LOCKED:
589             {
590                 bool newValue = !row[_model->_colLocked];
591                 row[_model->_colLocked] = newValue;
592                 item->setLocked( newValue );
593                 item->updateRepr();
594                 sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS,
595                                   newValue? _("Lock layer") : _("Unlock layer"));
596             }
597             break;
598         }
599     }
602 void LayersPanel::_handleButtonEvent(GdkEventButton* evt)
604     // TODO - fix to a better is-popup function
605     if ( (evt->type == GDK_BUTTON_PRESS) && (evt->button == 3) ) {
608         {
609             Gtk::TreeModel::Path path;
610             Gtk::TreeViewColumn* col = 0;
611             int x = static_cast<int>(evt->x);
612             int y = static_cast<int>(evt->y);
613             int x2 = 0;
614             int y2 = 0;
615             if ( _tree.get_path_at_pos( x, y,
616                                         path, col,
617                                         x2, y2 ) ) {
618                 _checkTreeSelection();
619                 _popupMenu.popup(evt->button, evt->time);
620             }
621         }
623     }
626 void LayersPanel::_handleRowChange( Gtk::TreeModel::Path const& /*path*/, Gtk::TreeModel::iterator const& iter )
628     Gtk::TreeModel::Row row = *iter;
629     if ( row ) {
630         SPObject* obj = row[_model->_colObject];
631         if ( obj ) {
632             gchar const* oldLabel = obj->label();
633             Glib::ustring tmp = row[_model->_colLabel];
634             if ( oldLabel && oldLabel[0] && !tmp.empty() && (tmp != oldLabel) ) {
635                 _mgr->renameLayer( obj, tmp.c_str() );
636                 row[_model->_colLabel] = obj->label();
637             }
638         }
639     }
642 bool LayersPanel::_rowSelectFunction( Glib::RefPtr<Gtk::TreeModel> const & /*model*/, Gtk::TreeModel::Path const & /*path*/, bool currentlySelected )
644     bool val = true;
645     if ( !currentlySelected && _toggleEvent )
646     {
647         GdkEvent* event = gtk_get_current_event();
648         if ( event ) {
649             // (keep these checks separate, so we know when to call gdk_event_free()
650             if ( event->type == GDK_BUTTON_PRESS ) {
651                 GdkEventButton const* target = reinterpret_cast<GdkEventButton const*>(_toggleEvent);
652                 GdkEventButton const* evtb = reinterpret_cast<GdkEventButton const*>(event);
654                 if ( (evtb->window == target->window)
655                      && (evtb->send_event == target->send_event)
656                      && (evtb->time == target->time)
657                      && (evtb->state == target->state)
658                     )
659                 {
660                     // Ooooh! It's a magic one
661                     val = false;
662                 }
663             }
664             gdk_event_free(event);
665         }
666     }
667     return val;
670 /**
671  * Constructor
672  */
673 LayersPanel::LayersPanel() :
674     UI::Widget::Panel("", "dialogs.layers", SP_VERB_DIALOG_LAYERS),
675     _maxNestDepth(20),
676     _mgr(0),
677     _desktop(0),
678     _model(0),
679     _pending(0),
680     _toggleEvent(0),
681     _compositeSettings(SP_VERB_DIALOG_LAYERS, "layers", UI::Widget::SimpleFilterModifier::BLEND)
683     _maxNestDepth = prefs_get_int_attribute_limited("dialogs.layers", "maxDepth", 20, 1, 1000);
685     ModelColumns *zoop = new ModelColumns();
686     _model = zoop;
688     _store = Gtk::TreeStore::create( *zoop );
690     _tree.set_model( _store );
691     _tree.set_headers_visible(false);
693     ImageToggler* eyeRenderer = manage( new ImageToggler("visible", "hidden") );
694     int visibleColNum = _tree.append_column("vis", *eyeRenderer) - 1;
695     eyeRenderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) );
696     eyeRenderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_VISIBLE) );
697     eyeRenderer->property_activatable() = true;
698     Gtk::TreeViewColumn* col = _tree.get_column(visibleColNum);
699     if ( col ) {
700         col->add_attribute( eyeRenderer->property_active(), _model->_colVisible );
701     }
703     ImageToggler * renderer = manage( new ImageToggler("width_height_lock", "lock_unlocked") );
704     int lockedColNum = _tree.append_column("lock", *renderer) - 1;
705     renderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) );
706     renderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_LOCKED) );
707     renderer->property_activatable() = true;
708     col = _tree.get_column(lockedColNum);
709     if ( col ) {
710         col->add_attribute( renderer->property_active(), _model->_colLocked );
711     }
713     int nameColNum = _tree.append_column_editable("Name", _model->_colLabel) - 1;
715     _tree.set_expander_column( *_tree.get_column(nameColNum) );
717     _compositeSettings.setSubject(&_subject);
719     _selectedConnection = _tree.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &LayersPanel::_pushTreeSelectionToCurrent) );
720     _tree.get_selection()->set_select_function( sigc::mem_fun(*this, &LayersPanel::_rowSelectFunction) );
722     _tree.get_model()->signal_row_changed().connect( sigc::mem_fun(*this, &LayersPanel::_handleRowChange) );
723     _tree.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &LayersPanel::_handleButtonEvent) );
725     _scroller.add( _tree );
726     _scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC );
728     _watching.push_back( &_compositeSettings );
730     _getContents()->pack_start( _scroller, Gtk::PACK_EXPAND_WIDGET );
732     _getContents()->pack_end(_compositeSettings, Gtk::PACK_SHRINK);
733     _getContents()->pack_end(_buttonsRow, Gtk::PACK_SHRINK);
735     SPDesktop* targetDesktop = getDesktop();
737     _buttonsRow.set_child_min_width( 16 );
739     Gtk::Button* btn = manage( new Gtk::Button() );
740     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_NEW, GTK_STOCK_ADD, _("New") );
741     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_NEW) );
742     _buttonsRow.add( *btn );
744     btn = manage( new Gtk::Button() );
745     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_TOP, GTK_STOCK_GOTO_TOP, _("Top") );
746     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_TOP) );
747     _watchingNonTop.push_back( btn );
748     _buttonsRow.add( *btn );
750     btn = manage( new Gtk::Button() );
751     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_RAISE, GTK_STOCK_GO_UP, _("Up") );
752     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_UP) );
753     _watchingNonTop.push_back( btn );
754     _buttonsRow.add( *btn );
756     btn = manage( new Gtk::Button() );
757     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_LOWER, GTK_STOCK_GO_DOWN, _("Dn") );
758     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DOWN) );
759     _watchingNonBottom.push_back( btn );
760     _buttonsRow.add( *btn );
762     btn = manage( new Gtk::Button() );
763     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_BOTTOM, GTK_STOCK_GOTO_BOTTOM, _("Bot") );
764     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_BOTTOM) );
765     _watchingNonBottom.push_back( btn );
766     _buttonsRow.add( *btn );
768 //     btn = manage( new Gtk::Button("Dup") );
769 //     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DUPLICATE) );
770 //     _buttonsRow.add( *btn );
772     btn = manage( new Gtk::Button() );
773     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_DELETE, GTK_STOCK_REMOVE, _("X") );
774     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DELETE) );
775     _watching.push_back( btn );
776     _buttonsRow.add( *btn );
781     // -------------------------------------------------------
782     {
783         _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RENAME, 0, "Rename", (int)BUTTON_RENAME ) );
784         _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_NEW, 0, "New", (int)BUTTON_NEW ) );
785         _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_SOLO, 0, "Solo", (int)BUTTON_SOLO ) );
787          _popupMenu.items().push_back( Gtk::Menu_Helpers::SeparatorElem() );
789         _watchingNonTop.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RAISE, GTK_STOCK_GO_UP, "Up", (int)BUTTON_UP ) );
790         _watchingNonBottom.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_LOWER, GTK_STOCK_GO_DOWN, "Down", (int)BUTTON_DOWN ) );
792         _popupMenu.show_all_children();
793     }
794     // -------------------------------------------------------
798     for ( std::vector<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) {
799         (*it)->set_sensitive( false );
800     }
801     for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonTop.begin(); it != _watchingNonTop.end(); ++it ) {
802         (*it)->set_sensitive( false );
803     }
804     for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonBottom.begin(); it != _watchingNonBottom.end(); ++it ) {
805         (*it)->set_sensitive( false );
806     }
808     g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK( layers_panel_activated ), this );
809     setDesktop( targetDesktop );
811     show_all_children();
813     // restorePanelPrefs();
816 LayersPanel::~LayersPanel()
818     _compositeSettings.setSubject(NULL);
820     if ( _model )
821     {
822         delete _model;
823     }
825     if ( _toggleEvent )
826     {
827         gdk_event_free( _toggleEvent );
828         _toggleEvent = 0;
829     }
833 void LayersPanel::setDesktop( SPDesktop* desktop )
835     Panel::setDesktop(desktop);
837     if ( desktop != _desktop ) {
838         _layerChangedConnection.disconnect();
839         _layerUpdatedConnection.disconnect();
840         _changedConnection.disconnect();
841         if ( _mgr ) {
842             _mgr = 0;
843         }
844         if ( _desktop ) {
845             _desktop = 0;
846         }
848         _desktop = getDesktop();
849         if ( _desktop ) {
850             //setLabel( _desktop->doc()->name );
852             _mgr = _desktop->layer_manager;
853             if ( _mgr ) {
854                 _layerChangedConnection = _mgr->connectCurrentLayerChanged( sigc::mem_fun(*this, &LayersPanel::_selectLayer) );
855                 _layerUpdatedConnection = _mgr->connectLayerDetailsChanged( sigc::mem_fun(*this, &LayersPanel::_updateLayer) );
856                 _changedConnection = _mgr->connectChanged( sigc::mem_fun(*this, &LayersPanel::_layersChanged) );
857             }
859             _layersChanged();
860         }
861     }
862 /*
863     GSList const *layers=sp_document_get_resource_list( _desktop->doc(), "layer" );
864     g_message( "layers list starts at %p", layers );
865     for ( GSList const *iter=layers ; iter ; iter = iter->next ) {
866         SPObject *layer=static_cast<SPObject *>(iter->data);
867         g_message("  {%s}   [%s]", layer->id, layer->label() );
868     }
869 */
874 } //namespace Dialogs
875 } //namespace UI
876 } //namespace Inkscape
879 /*
880   Local Variables:
881   mode:c++
882   c-file-style:"stroustrup"
883   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
884   indent-tabs-mode:nil
885   fill-column:99
886   End:
887 */
888 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :