Code

Line-end fixups
[inkscape.git] / src / display / canvas-temporary-item.cpp
1 /** \file
2  * Provides a class that can contain active TemporaryItem's on a desktop
3  * When the object is deleted, it also deletes the canvasitem it contains!
4  * This object should be created/managed by a TemporaryItemList.
5  * After its lifetime, it fires the timeout signal, afterwards *it deletes itself*.
6  *
7  * (part of code inspired by message-stack.cpp)
8  *
9  * Authors:
10  *   Johan Engelen
11  *
12  * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
13  *
14  * Released under GNU GPL, read the file 'COPYING' for more information
15  */
17 #include "display/canvas-temporary-item.h"
19 #include <gtk/gtkobject.h>
21 namespace Inkscape {
22 namespace Display {
24 /** lifetime is measured in milliseconds
25  */
26 TemporaryItem::TemporaryItem(SPCanvasItem *item, guint lifetime)
27     : canvasitem(item),
28       timeout_id(0)
29 {
30     // zero lifetime means stay forever, so do not add timeout event.
31     if (lifetime > 0) {
32         timeout_id = g_timeout_add(lifetime, &TemporaryItem::_timeout, this);
33     }
34 }
36 TemporaryItem::~TemporaryItem()
37 {
38     // when it has not expired yet...
39     if (timeout_id) {
40         g_source_remove(timeout_id);
41         timeout_id = 0;
42     }
44     if (canvasitem) {
45         // destroying the item automatically hides it
46         gtk_object_destroy (GTK_OBJECT (canvasitem));
47         canvasitem = NULL;
48     }
49 }
51 /* static method*/
52 gboolean TemporaryItem::_timeout(gpointer data) {
53     TemporaryItem *tempitem = reinterpret_cast<TemporaryItem *>(data);
54     tempitem->timeout_id = 0;
55     tempitem->signal_timeout.emit(tempitem);
56     delete tempitem;
57     return FALSE;
58 }
61 } //namespace Display
62 } /* namespace Inkscape */
64 /*
65   Local Variables:
66   mode:c++
67   c-file-style:"stroustrup"
68   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
69   indent-tabs-mode:nil
70   fill-column:99
71   End:
72 */
73 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :