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