~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/display/canvas-temporary-item.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
16
 
 
17
#include "display/canvas-temporary-item.h"
 
18
 
 
19
#include <gtk/gtkobject.h>
 
20
 
 
21
namespace Inkscape {
 
22
namespace Display {
 
23
 
 
24
/** lifetime is measured in milliseconds
 
25
 */
 
26
TemporaryItem::TemporaryItem(SPCanvasItem *item, guint lifetime, bool deselect_destroy)
 
27
    : canvasitem(item),
 
28
      timeout_id(0),
 
29
      destroy_on_deselect(deselect_destroy)
 
30
{
 
31
    if (lifetime > 0 && destroy_on_deselect) {
 
32
        g_print ("Warning: lifetime should be 0 when destroy_on_deselect is true\n");
 
33
        lifetime = 0;
 
34
    }
 
35
    // zero lifetime means stay forever, so do not add timeout event.
 
36
    if (lifetime > 0) {
 
37
        timeout_id = g_timeout_add(lifetime, &TemporaryItem::_timeout, this);
 
38
    }
 
39
}
 
40
 
 
41
TemporaryItem::~TemporaryItem()
 
42
{
 
43
    // when it has not expired yet...
 
44
    if (timeout_id) {
 
45
        g_source_remove(timeout_id);
 
46
        timeout_id = 0;
 
47
    }
 
48
 
 
49
    if (canvasitem) {
 
50
        // destroying the item automatically hides it
 
51
        gtk_object_destroy (GTK_OBJECT (canvasitem));
 
52
        canvasitem = NULL;
 
53
    }
 
54
}
 
55
 
 
56
/* static method*/
 
57
gboolean TemporaryItem::_timeout(gpointer data) {
 
58
    TemporaryItem *tempitem = reinterpret_cast<TemporaryItem *>(data);
 
59
    tempitem->timeout_id = 0;
 
60
    tempitem->signal_timeout.emit(tempitem);
 
61
    delete tempitem;
 
62
    return FALSE;
 
63
}
 
64
 
 
65
 
 
66
} //namespace Display
 
67
} /* namespace Inkscape */
 
68
 
 
69
/*
 
70
  Local Variables:
 
71
  mode:c++
 
72
  c-file-style:"stroustrup"
 
73
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
74
  indent-tabs-mode:nil
 
75
  fill-column:99
 
76
  End:
 
77
*/
 
78
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :