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
180 {
181 public:
182 int _actionCode;
183 SPObject* _target;
184 };
186 static gboolean layers_panel_activated( GtkObject */*object*/, GdkEvent * /*event*/, gpointer data )
187 {
188 if ( data )
189 {
190 LayersPanel* panel = reinterpret_cast<LayersPanel*>(data);
191 panel->setDesktop(panel->getDesktop());
192 }
194 return FALSE;
195 }
198 void LayersPanel::_styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback )
199 {
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 }
229 }
232 Gtk::MenuItem& LayersPanel::_addPopupItem( SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback, int id )
233 {
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();
275 }
277 void LayersPanel::_fireAction( unsigned int code )
278 {
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 }
294 }
296 // SP_VERB_LAYER_NEXT,
297 // SP_VERB_LAYER_PREV,
298 void LayersPanel::_takeAction( int val )
299 {
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 }
306 }
308 bool LayersPanel::_executeAction()
309 {
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_DUPLICATE:
354 {
355 _fireAction( SP_VERB_LAYER_DUPLICATE );
356 }
357 break;
358 case BUTTON_DELETE:
359 {
360 _fireAction( SP_VERB_LAYER_DELETE );
361 }
362 case BUTTON_SOLO:
363 {
364 _fireAction( SP_VERB_LAYER_SOLO );
365 }
366 break;
367 }
369 delete _pending;
370 _pending = 0;
371 }
373 return false;
374 }
376 class LayersPanel::ModelColumns : public Gtk::TreeModel::ColumnRecord
377 {
378 public:
380 ModelColumns()
381 {
382 add(_colObject);
383 add(_colVisible);
384 add(_colLocked);
385 add(_colLabel);
386 }
387 virtual ~ModelColumns() {}
389 Gtk::TreeModelColumn<SPObject*> _colObject;
390 Gtk::TreeModelColumn<Glib::ustring> _colLabel;
391 Gtk::TreeModelColumn<bool> _colVisible;
392 Gtk::TreeModelColumn<bool> _colLocked;
393 };
395 void LayersPanel::_updateLayer( SPObject *layer ) {
396 _store->foreach( sigc::bind<SPObject*>(sigc::mem_fun(*this, &LayersPanel::_checkForUpdated), layer) );
397 }
399 bool LayersPanel::_checkForUpdated(const Gtk::TreePath &/*path*/, const Gtk::TreeIter& iter, SPObject* layer)
400 {
401 bool stopGoing = false;
402 Gtk::TreeModel::Row row = *iter;
403 Glib::ustring tmp = row[_model->_colLabel];
404 if ( layer == row[_model->_colObject] )
405 {
406 row[_model->_colLabel] = layer->label() ? layer->label() : SP_OBJECT_ID(layer);
407 row[_model->_colVisible] = SP_IS_ITEM(layer) ? !SP_ITEM(layer)->isHidden() : false;
408 row[_model->_colLocked] = SP_IS_ITEM(layer) ? SP_ITEM(layer)->isLocked() : false;
410 stopGoing = true;
411 }
413 return stopGoing;
414 }
416 void LayersPanel::_selectLayer( SPObject *layer ) {
417 if ( !layer || (_desktop && _desktop->doc() && (layer == _desktop->doc()->root)) ) {
418 if ( _tree.get_selection()->count_selected_rows() != 0 ) {
419 _tree.get_selection()->unselect_all();
420 }
421 } else {
422 _store->foreach( sigc::bind<SPObject*>(sigc::mem_fun(*this, &LayersPanel::_checkForSelected), layer) );
423 }
425 _checkTreeSelection();
426 }
428 bool LayersPanel::_checkForSelected(const Gtk::TreePath &path, const Gtk::TreeIter& iter, SPObject* layer)
429 {
430 bool stopGoing = false;
432 Gtk::TreeModel::Row row = *iter;
433 if ( layer == row[_model->_colObject] )
434 {
435 _tree.expand_to_path( path );
437 Glib::RefPtr<Gtk::TreeSelection> select = _tree.get_selection();
439 select->select(iter);
441 stopGoing = true;
442 }
444 return stopGoing;
445 }
447 void LayersPanel::_layersChanged()
448 {
449 // g_message("_layersChanged()");
450 SPDocument* document = _desktop->doc();
451 SPObject* root = document->root;
452 if ( root ) {
453 _selectedConnection.block();
454 if ( _mgr && _mgr->includes( root ) ) {
455 SPObject* target = _desktop->currentLayer();
456 _store->clear();
458 #if DUMP_LAYERS
459 g_message("root:%p {%s} [%s]", root, root->id, root->label() );
460 #endif // DUMP_LAYERS
461 _addLayer( document, root, 0, target, 0 );
462 }
463 _selectedConnection.unblock();
464 }
465 }
467 void LayersPanel::_addLayer( SPDocument* doc, SPObject* layer, Gtk::TreeModel::Row* parentRow, SPObject* target, int level )
468 {
469 if ( layer && (level < _maxNestDepth) ) {
470 unsigned int counter = _mgr->childCount(layer);
471 for ( unsigned int i = 0; i < counter; i++ ) {
472 SPObject *child = _mgr->nthChildOf(layer, i);
473 if ( child ) {
474 #if DUMP_LAYERS
475 g_message(" %3d layer:%p {%s} [%s]", level, child, child->id, child->label() );
476 #endif // DUMP_LAYERS
478 Gtk::TreeModel::iterator iter = parentRow ? _store->prepend(parentRow->children()) : _store->prepend();
479 Gtk::TreeModel::Row row = *iter;
480 row[_model->_colObject] = child;
481 row[_model->_colLabel] = child->label() ? child->label() : SP_OBJECT_ID(child);
482 row[_model->_colVisible] = SP_IS_ITEM(child) ? !SP_ITEM(child)->isHidden() : false;
483 row[_model->_colLocked] = SP_IS_ITEM(child) ? SP_ITEM(child)->isLocked() : false;
485 if ( target && child == target ) {
486 _tree.expand_to_path( _store->get_path(iter) );
488 Glib::RefPtr<Gtk::TreeSelection> select = _tree.get_selection();
489 select->select(iter);
491 _checkTreeSelection();
492 }
494 _addLayer( doc, child, &row, target, level + 1 );
495 }
496 }
497 }
498 }
500 SPObject* LayersPanel::_selectedLayer()
501 {
502 SPObject* obj = 0;
504 Gtk::TreeModel::iterator iter = _tree.get_selection()->get_selected();
505 if ( iter ) {
506 Gtk::TreeModel::Row row = *iter;
507 obj = row[_model->_colObject];
508 }
510 return obj;
511 }
513 void LayersPanel::_pushTreeSelectionToCurrent()
514 {
515 SPObject* inTree = _selectedLayer();
516 // TODO hunt down the possible API abuse in getting NULL
517 if ( _desktop->currentRoot() ) {
518 if ( inTree ) {
519 SPObject* curr = _desktop->currentLayer();
520 if ( curr != inTree ) {
521 _mgr->setCurrentLayer( inTree );
522 }
523 } else {
524 _mgr->setCurrentLayer( _desktop->doc()->root );
525 }
526 }
527 }
529 void LayersPanel::_checkTreeSelection()
530 {
531 bool sensitive = false;
532 bool sensitiveNonTop = false;
533 bool sensitiveNonBottom = false;
534 if ( _tree.get_selection()->count_selected_rows() > 0 ) {
535 sensitive = true;
537 SPObject* inTree = _selectedLayer();
538 if ( inTree ) {
540 sensitiveNonTop = (Inkscape::next_layer(inTree->parent, inTree) != 0);
541 sensitiveNonBottom = (Inkscape::previous_layer(inTree->parent, inTree) != 0);
543 }
544 }
547 for ( std::vector<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) {
548 (*it)->set_sensitive( sensitive );
549 }
550 for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonTop.begin(); it != _watchingNonTop.end(); ++it ) {
551 (*it)->set_sensitive( sensitiveNonTop );
552 }
553 for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonBottom.begin(); it != _watchingNonBottom.end(); ++it ) {
554 (*it)->set_sensitive( sensitiveNonBottom );
555 }
556 }
558 void LayersPanel::_preToggle( GdkEvent const *event )
559 {
560 if ( _toggleEvent ) {
561 gdk_event_free(_toggleEvent);
562 _toggleEvent = 0;
563 }
565 if ( event && (event->type == GDK_BUTTON_PRESS) ) {
566 // Make a copy so we can keep it around.
567 _toggleEvent = gdk_event_copy(const_cast<GdkEvent*>(event));
568 }
569 }
571 void LayersPanel::_toggled( Glib::ustring const& str, int targetCol )
572 {
573 Gtk::TreeModel::Children::iterator iter = _tree.get_model()->get_iter(str);
574 Gtk::TreeModel::Row row = *iter;
576 Glib::ustring tmp = row[_model->_colLabel];
578 SPObject* obj = row[_model->_colObject];
579 SPItem* item = ( obj && SP_IS_ITEM(obj) ) ? SP_ITEM(obj) : 0;
580 if ( item ) {
581 switch ( targetCol ) {
582 case COL_VISIBLE:
583 {
584 bool newValue = !row[_model->_colVisible];
585 row[_model->_colVisible] = newValue;
586 item->setHidden( !newValue );
587 item->updateRepr();
588 sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS,
589 newValue? _("Unhide layer") : _("Hide layer"));
590 }
591 break;
593 case COL_LOCKED:
594 {
595 bool newValue = !row[_model->_colLocked];
596 row[_model->_colLocked] = newValue;
597 item->setLocked( newValue );
598 item->updateRepr();
599 sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS,
600 newValue? _("Lock layer") : _("Unlock layer"));
601 }
602 break;
603 }
604 }
605 }
607 void LayersPanel::_handleButtonEvent(GdkEventButton* evt)
608 {
609 // TODO - fix to a better is-popup function
610 if ( (evt->type == GDK_BUTTON_PRESS) && (evt->button == 3) ) {
613 {
614 Gtk::TreeModel::Path path;
615 Gtk::TreeViewColumn* col = 0;
616 int x = static_cast<int>(evt->x);
617 int y = static_cast<int>(evt->y);
618 int x2 = 0;
619 int y2 = 0;
620 if ( _tree.get_path_at_pos( x, y,
621 path, col,
622 x2, y2 ) ) {
623 _checkTreeSelection();
624 _popupMenu.popup(evt->button, evt->time);
625 }
626 }
628 }
629 }
631 void LayersPanel::_handleRowChange( Gtk::TreeModel::Path const& /*path*/, Gtk::TreeModel::iterator const& iter )
632 {
633 Gtk::TreeModel::Row row = *iter;
634 if ( row ) {
635 SPObject* obj = row[_model->_colObject];
636 if ( obj ) {
637 gchar const* oldLabel = obj->label();
638 Glib::ustring tmp = row[_model->_colLabel];
639 if ( oldLabel && oldLabel[0] && !tmp.empty() && (tmp != oldLabel) ) {
640 _mgr->renameLayer( obj, tmp.c_str() );
641 row[_model->_colLabel] = obj->label();
642 }
643 }
644 }
645 }
647 bool LayersPanel::_rowSelectFunction( Glib::RefPtr<Gtk::TreeModel> const & /*model*/, Gtk::TreeModel::Path const & /*path*/, bool currentlySelected )
648 {
649 bool val = true;
650 if ( !currentlySelected && _toggleEvent )
651 {
652 GdkEvent* event = gtk_get_current_event();
653 if ( event ) {
654 // (keep these checks separate, so we know when to call gdk_event_free()
655 if ( event->type == GDK_BUTTON_PRESS ) {
656 GdkEventButton const* target = reinterpret_cast<GdkEventButton const*>(_toggleEvent);
657 GdkEventButton const* evtb = reinterpret_cast<GdkEventButton const*>(event);
659 if ( (evtb->window == target->window)
660 && (evtb->send_event == target->send_event)
661 && (evtb->time == target->time)
662 && (evtb->state == target->state)
663 )
664 {
665 // Ooooh! It's a magic one
666 val = false;
667 }
668 }
669 gdk_event_free(event);
670 }
671 }
672 return val;
673 }
675 /**
676 * Constructor
677 */
678 LayersPanel::LayersPanel() :
679 UI::Widget::Panel("", "dialogs.layers", SP_VERB_DIALOG_LAYERS),
680 _maxNestDepth(20),
681 _mgr(0),
682 _desktop(0),
683 _model(0),
684 _pending(0),
685 _toggleEvent(0),
686 _compositeSettings(SP_VERB_DIALOG_LAYERS, "layers", UI::Widget::SimpleFilterModifier::BLEND)
687 {
688 _maxNestDepth = prefs_get_int_attribute_limited("dialogs.layers", "maxDepth", 20, 1, 1000);
690 ModelColumns *zoop = new ModelColumns();
691 _model = zoop;
693 _store = Gtk::TreeStore::create( *zoop );
695 _tree.set_model( _store );
696 _tree.set_headers_visible(false);
698 ImageToggler* eyeRenderer = manage( new ImageToggler("visible", "hidden") );
699 int visibleColNum = _tree.append_column("vis", *eyeRenderer) - 1;
700 eyeRenderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) );
701 eyeRenderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_VISIBLE) );
702 eyeRenderer->property_activatable() = true;
703 Gtk::TreeViewColumn* col = _tree.get_column(visibleColNum);
704 if ( col ) {
705 col->add_attribute( eyeRenderer->property_active(), _model->_colVisible );
706 }
708 ImageToggler * renderer = manage( new ImageToggler("width_height_lock", "lock_unlocked") );
709 int lockedColNum = _tree.append_column("lock", *renderer) - 1;
710 renderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) );
711 renderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_LOCKED) );
712 renderer->property_activatable() = true;
713 col = _tree.get_column(lockedColNum);
714 if ( col ) {
715 col->add_attribute( renderer->property_active(), _model->_colLocked );
716 }
718 int nameColNum = _tree.append_column_editable("Name", _model->_colLabel) - 1;
720 _tree.set_expander_column( *_tree.get_column(nameColNum) );
722 _compositeSettings.setSubject(&_subject);
724 _selectedConnection = _tree.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &LayersPanel::_pushTreeSelectionToCurrent) );
725 _tree.get_selection()->set_select_function( sigc::mem_fun(*this, &LayersPanel::_rowSelectFunction) );
727 _tree.get_model()->signal_row_changed().connect( sigc::mem_fun(*this, &LayersPanel::_handleRowChange) );
728 _tree.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &LayersPanel::_handleButtonEvent) );
730 _scroller.add( _tree );
731 _scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC );
733 _watching.push_back( &_compositeSettings );
735 _getContents()->pack_start( _scroller, Gtk::PACK_EXPAND_WIDGET );
737 _getContents()->pack_end(_compositeSettings, Gtk::PACK_SHRINK);
738 _getContents()->pack_end(_buttonsRow, Gtk::PACK_SHRINK);
740 SPDesktop* targetDesktop = getDesktop();
742 _buttonsRow.set_child_min_width( 16 );
744 Gtk::Button* btn = manage( new Gtk::Button() );
745 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_NEW, GTK_STOCK_ADD, _("New") );
746 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_NEW) );
747 _buttonsRow.add( *btn );
749 btn = manage( new Gtk::Button() );
750 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_TOP, GTK_STOCK_GOTO_TOP, _("Top") );
751 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_TOP) );
752 _watchingNonTop.push_back( btn );
753 _buttonsRow.add( *btn );
755 btn = manage( new Gtk::Button() );
756 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_RAISE, GTK_STOCK_GO_UP, _("Up") );
757 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_UP) );
758 _watchingNonTop.push_back( btn );
759 _buttonsRow.add( *btn );
761 btn = manage( new Gtk::Button() );
762 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_LOWER, GTK_STOCK_GO_DOWN, _("Dn") );
763 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DOWN) );
764 _watchingNonBottom.push_back( btn );
765 _buttonsRow.add( *btn );
767 btn = manage( new Gtk::Button() );
768 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_BOTTOM, GTK_STOCK_GOTO_BOTTOM, _("Bot") );
769 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_BOTTOM) );
770 _watchingNonBottom.push_back( btn );
771 _buttonsRow.add( *btn );
773 // btn = manage( new Gtk::Button("Dup") );
774 // btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DUPLICATE) );
775 // _buttonsRow.add( *btn );
777 btn = manage( new Gtk::Button() );
778 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_DELETE, GTK_STOCK_REMOVE, _("X") );
779 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DELETE) );
780 _watching.push_back( btn );
781 _buttonsRow.add( *btn );
786 // -------------------------------------------------------
787 {
788 _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RENAME, 0, "Rename", (int)BUTTON_RENAME ) );
789 _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_DUPLICATE, 0, "Duplicate", (int)BUTTON_DUPLICATE ) );
790 _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_NEW, 0, "New", (int)BUTTON_NEW ) );
791 _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_SOLO, 0, "Solo", (int)BUTTON_SOLO ) );
793 _popupMenu.items().push_back( Gtk::Menu_Helpers::SeparatorElem() );
795 _watchingNonTop.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RAISE, GTK_STOCK_GO_UP, "Up", (int)BUTTON_UP ) );
796 _watchingNonBottom.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_LOWER, GTK_STOCK_GO_DOWN, "Down", (int)BUTTON_DOWN ) );
798 _popupMenu.show_all_children();
799 }
800 // -------------------------------------------------------
804 for ( std::vector<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) {
805 (*it)->set_sensitive( false );
806 }
807 for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonTop.begin(); it != _watchingNonTop.end(); ++it ) {
808 (*it)->set_sensitive( false );
809 }
810 for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonBottom.begin(); it != _watchingNonBottom.end(); ++it ) {
811 (*it)->set_sensitive( false );
812 }
814 g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK( layers_panel_activated ), this );
815 setDesktop( targetDesktop );
817 show_all_children();
819 // restorePanelPrefs();
820 }
822 LayersPanel::~LayersPanel()
823 {
824 _compositeSettings.setSubject(NULL);
826 if ( _model )
827 {
828 delete _model;
829 }
831 if ( _toggleEvent )
832 {
833 gdk_event_free( _toggleEvent );
834 _toggleEvent = 0;
835 }
836 }
839 void LayersPanel::setDesktop( SPDesktop* desktop )
840 {
841 Panel::setDesktop(desktop);
843 if ( desktop != _desktop ) {
844 _layerChangedConnection.disconnect();
845 _layerUpdatedConnection.disconnect();
846 _changedConnection.disconnect();
847 if ( _mgr ) {
848 _mgr = 0;
849 }
850 if ( _desktop ) {
851 _desktop = 0;
852 }
854 _desktop = getDesktop();
855 if ( _desktop ) {
856 //setLabel( _desktop->doc()->name );
858 _mgr = _desktop->layer_manager;
859 if ( _mgr ) {
860 _layerChangedConnection = _mgr->connectCurrentLayerChanged( sigc::mem_fun(*this, &LayersPanel::_selectLayer) );
861 _layerUpdatedConnection = _mgr->connectLayerDetailsChanged( sigc::mem_fun(*this, &LayersPanel::_updateLayer) );
862 _changedConnection = _mgr->connectChanged( sigc::mem_fun(*this, &LayersPanel::_layersChanged) );
863 }
865 _layersChanged();
866 }
867 }
868 /*
869 GSList const *layers=sp_document_get_resource_list( _desktop->doc(), "layer" );
870 g_message( "layers list starts at %p", layers );
871 for ( GSList const *iter=layers ; iter ; iter = iter->next ) {
872 SPObject *layer=static_cast<SPObject *>(iter->data);
873 g_message(" {%s} [%s]", layer->id, layer->label() );
874 }
875 */
876 }
880 } //namespace Dialogs
881 } //namespace UI
882 } //namespace Inkscape
885 /*
886 Local Variables:
887 mode:c++
888 c-file-style:"stroustrup"
889 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
890 indent-tabs-mode:nil
891 fill-column:99
892 End:
893 */
894 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :