Code

Node tool: fix Tab and Shift+Tab
[inkscape.git] / src / display / canvas-temporary-item-list.cpp
1 /** \file
2  * Provides a class that can contain active TemporaryItem's on a desktop
3  * Code inspired by message-stack.cpp
4  *
5  * Authors:
6  *   Johan Engelen
7  *
8  * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
9  *
10  * Released under GNU GPL, read the file 'COPYING' for more information
11  */
13 #include "display/canvas-temporary-item-list.h"
15 #include "display/canvas-temporary-item.h"
17 namespace Inkscape {
18 namespace Display {
20 TemporaryItemList::TemporaryItemList(SPDesktop *desktop)
21     : desktop(desktop)
22 {
24 }
26 TemporaryItemList::~TemporaryItemList()
27 {
28     // delete all items in list so the timeouts are removed
29     for ( std::list<TemporaryItem*>::iterator it = itemlist.begin(); it != itemlist.end(); ++it ) {
30         TemporaryItem * tempitem = *it;
31         delete tempitem;
32     }
33     itemlist.clear();
34 }
36 /* Note that TemporaryItem or TemporaryItemList is responsible for deletion and such, so this return pointer can safely be ignored. */
37 TemporaryItem *
38 TemporaryItemList::add_item(SPCanvasItem *item, guint lifetime)
39 {
40     // beware of strange things happening due to very short timeouts
41     TemporaryItem * tempitem = new TemporaryItem(item, lifetime);
42     itemlist.push_back(tempitem);
43     tempitem->signal_timeout.connect( sigc::mem_fun(*this, &TemporaryItemList::_item_timeout) );
44     return tempitem;
45 }
47 void
48 TemporaryItemList::delete_item( TemporaryItem * tempitem )
49 {
50     // check if the item is in the list, if so, delete it. (in other words, don't wait for the item to delete itself)
51     bool in_list = false;
52     for ( std::list<TemporaryItem*>::iterator it = itemlist.begin(); it != itemlist.end(); ++it ) {
53         if ( *it == tempitem ) {
54             in_list = true;
55             break;
56         }
57     }
58     if (in_list) {
59         itemlist.remove(tempitem);
60         delete tempitem;
61     }
62 }
64 void
65 TemporaryItemList::_item_timeout(TemporaryItem * tempitem)
66 {
67     itemlist.remove(tempitem);
68     // no need to delete the item, it does that itself after signal_timeout.emit() completes
69 }
71 } //namespace Display
72 } /* namespace Inkscape */
74 /*
75   Local Variables:
76   mode:c++
77   c-file-style:"stroustrup"
78   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
79   indent-tabs-mode:nil
80   fill-column:99
81   End:
82 */
83 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :