From acae310d49358ac8de885fa8692caf5e4067574c Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sun, 2 Mar 2008 13:38:15 +0000 Subject: NEW: temporary on-canvas indicators (bzr r4918) --- src/display/canvas-temporary-item.cpp | 72 +++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/display/canvas-temporary-item.cpp (limited to 'src/display/canvas-temporary-item.cpp') diff --git a/src/display/canvas-temporary-item.cpp b/src/display/canvas-temporary-item.cpp new file mode 100644 index 000000000..da6caf2c1 --- /dev/null +++ b/src/display/canvas-temporary-item.cpp @@ -0,0 +1,72 @@ +/** \file + * Provides a class that can contain active TemporaryItem's on a desktop + * When the object is deleted, it also deletes the canvasitem it contains! + * This object should be created/managed by a TemporaryItemList. + * After its lifetime, it fires the timeout signal, afterwards *it deletes itself*. + * + * (part of code inspired by message-stack.cpp) + * + * Authors: + * Johan Engelen + * + * Copyright (C) Johan Engelen 2008 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "display/canvas-temporary-item.h" + +#include + +namespace Inkscape { +namespace Display { + +/** lifetime is measured in milliseconds + */ +TemporaryItem::TemporaryItem(SPCanvasItem *item, guint lifetime) + : canvasitem(item), + timeout_id(0) +{ + if (lifetime > 0) { + timeout_id = g_timeout_add(lifetime, &TemporaryItem::_timeout, this); + } +} + +TemporaryItem::~TemporaryItem() +{ + // when it has not expired yet... + if (timeout_id) { + g_source_remove(timeout_id); + timeout_id = 0; + } + + if (canvasitem) { + // destroying the item automatically hides it + gtk_object_destroy (GTK_OBJECT (canvasitem)); + canvasitem = NULL; + } +} + +/* static method*/ +gboolean TemporaryItem::_timeout(gpointer data) { + TemporaryItem *tempitem = reinterpret_cast(data); + tempitem->timeout_id = 0; + tempitem->signal_timeout.emit(tempitem); + delete tempitem; + return FALSE; +} + + +} //namespace Display +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : -- cgit v1.2.3