Code

Revert recent refactoring changes by johnce because they break the build, which canno...
[inkscape.git] / src / display / canvas-temporary-item.cpp
index 7d7f8087c04e8ef45b901fb6dbf1eb0e5dbb664a..ccef4d0cbd8f5815ad38dbc2313272c9ac38186b 100644 (file)
@@ -1,73 +1,78 @@
-/** \file\r
- * Provides a class that can contain active TemporaryItem's on a desktop\r
- * When the object is deleted, it also deletes the canvasitem it contains!\r
- * This object should be created/managed by a TemporaryItemList.\r
- * After its lifetime, it fires the timeout signal, afterwards *it deletes itself*.\r
- *\r
- * (part of code inspired by message-stack.cpp)\r
- *\r
- * Authors:\r
- *   Johan Engelen\r
- *\r
- * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>\r
- *\r
- * Released under GNU GPL, read the file 'COPYING' for more information\r
- */\r
-\r
-#include "display/canvas-temporary-item.h"\r
-\r
-#include <gtk/gtkobject.h>\r
-\r
-namespace Inkscape {\r
-namespace Display {\r
-\r
-/** lifetime is measured in milliseconds\r
- */\r
-TemporaryItem::TemporaryItem(SPCanvasItem *item, guint lifetime)\r
-    : canvasitem(item),\r
-      timeout_id(0)\r
-{\r
-    // zero lifetime means stay forever, so do not add timeout event.\r
-    if (lifetime > 0) {\r
-        timeout_id = g_timeout_add(lifetime, &TemporaryItem::_timeout, this);\r
-    }\r
-}\r
-\r
-TemporaryItem::~TemporaryItem()\r
-{\r
-    // when it has not expired yet...\r
-    if (timeout_id) {\r
-        g_source_remove(timeout_id);\r
-        timeout_id = 0;\r
-    }\r
-\r
-    if (canvasitem) {\r
-        // destroying the item automatically hides it\r
-        gtk_object_destroy (GTK_OBJECT (canvasitem));\r
-        canvasitem = NULL;\r
-    }\r
-}\r
-\r
-/* static method*/\r
-gboolean TemporaryItem::_timeout(gpointer data) {\r
-    TemporaryItem *tempitem = reinterpret_cast<TemporaryItem *>(data);\r
-    tempitem->timeout_id = 0;\r
-    tempitem->signal_timeout.emit(tempitem);\r
-    delete tempitem;\r
-    return FALSE;\r
-}\r
-\r
-\r
-} //namespace Display\r
-} /* namespace Inkscape */\r
-\r
-/*\r
-  Local Variables:\r
-  mode:c++\r
-  c-file-style:"stroustrup"\r
-  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
-  indent-tabs-mode:nil\r
-  fill-column:99\r
-  End:\r
-*/\r
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :\r
+/** \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 <j.b.c.engelen@utwente.nl>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "display/canvas-temporary-item.h"
+
+#include <gtk/gtkobject.h>
+
+namespace Inkscape {
+namespace Display {
+
+/** lifetime is measured in milliseconds
+ */
+TemporaryItem::TemporaryItem(SPCanvasItem *item, guint lifetime, bool deselect_destroy)
+    : canvasitem(item),
+      timeout_id(0),
+      destroy_on_deselect(deselect_destroy)
+{
+    if (lifetime > 0 && destroy_on_deselect) {
+        g_print ("Warning: lifetime should be 0 when destroy_on_deselect is true\n");
+        lifetime = 0;
+    }
+    // zero lifetime means stay forever, so do not add timeout event.
+    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<TemporaryItem *>(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 :