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*.
7
* (part of code inspired by message-stack.cpp)
12
* Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
14
* Released under GNU GPL, read the file 'COPYING' for more information
17
#include "display/canvas-temporary-item.h"
19
#include <gtk/gtkobject.h>
24
/** lifetime is measured in milliseconds
26
TemporaryItem::TemporaryItem(SPCanvasItem *item, guint lifetime, bool deselect_destroy)
29
destroy_on_deselect(deselect_destroy)
31
if (lifetime > 0 && destroy_on_deselect) {
32
g_print ("Warning: lifetime should be 0 when destroy_on_deselect is true\n");
35
// zero lifetime means stay forever, so do not add timeout event.
37
timeout_id = g_timeout_add(lifetime, &TemporaryItem::_timeout, this);
41
TemporaryItem::~TemporaryItem()
43
// when it has not expired yet...
45
g_source_remove(timeout_id);
50
// destroying the item automatically hides it
51
gtk_object_destroy (GTK_OBJECT (canvasitem));
57
gboolean TemporaryItem::_timeout(gpointer data) {
58
TemporaryItem *tempitem = reinterpret_cast<TemporaryItem *>(data);
59
tempitem->timeout_id = 0;
60
tempitem->signal_timeout.emit(tempitem);
67
} /* namespace Inkscape */
72
c-file-style:"stroustrup"
73
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
78
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :