~inkscape.dev/inkscape/trunk

1 by mental
moving trunk for module inkscape
1
/** \file
2246 by mental
update short descriptions of MessageStack and MessageContext a little bit
2
 * Raw stack of active status messages
1 by mental
moving trunk for module inkscape
3
 */
4
5
/*
6
 * Authors:
7
 *   MenTaLguY <mental@rydia.net>
10507 by Jon A. Cruz
Cleaning up trace methods to aid fixing color inversion.
8
 *   Jon A. Cruz <jon@joncruz.org>
1 by mental
moving trunk for module inkscape
9
 *
10
 * Copyright (C) 2004 MenTaLguY
10507 by Jon A. Cruz
Cleaning up trace methods to aid fixing color inversion.
11
 * Copyright (C) 2011 Jon A. Cruz
1 by mental
moving trunk for module inkscape
12
 *
13
 * Released under GNU GPL, read the file 'COPYING' for more information
14
 */
15
16
#ifndef SEEN_INKSCAPE_MESSAGE_STACK_H
17
#define SEEN_INKSCAPE_MESSAGE_STACK_H
18
13341.1.190 by Liam P. White
Header cleanup: stop using Glib types where they aren't truly needed. Eases GThread deprecation errors.
19
#include <cstdarg>
20
#include <cstddef>
21
#include <glib.h> // G_GNUC_PRINTF is the only thing worth having from here
22
#include <glibmm/ustring.h>
1 by mental
moving trunk for module inkscape
23
#include <sigc++/sigc++.h>
13341.1.190 by Liam P. White
Header cleanup: stop using Glib types where they aren't truly needed. Eases GThread deprecation errors.
24
1 by mental
moving trunk for module inkscape
25
#include "gc-managed.h"
26
#include "gc-finalized.h"
27
#include "gc-anchored.h"
28
#include "message.h"
29
30
namespace Inkscape {
31
32
/**
33
 * A class which holds a stack of displayed messages.  
34
 *
35
 * Messages can be pushed onto the top of the stack, and removed 
36
 * from any point in the stack by their id.
37
 *
38
 * Messages may also be "flashed", meaning that they will be
39
 * automatically removed from the stack a fixed period of time
40
 * after they are pushed.
41
 *
42
 * "Flashed" warnings and errors will persist longer than normal
43
 * messages.
44
 *
45
 * There is no simple "pop" operation provided, since these
46
 * stacks are intended to be shared by many different clients;
47
 * assuming that the message you pushed is still on top is an
48
 * invalid and unsafe assumption.
49
 */
50
class MessageStack : public GC::Managed<>,
51
                     public GC::Finalized,
52
                     public GC::Anchored
53
{
54
public:
55
    MessageStack();
56
    ~MessageStack();
57
58
    /** @brief returns the type of message currently at the top of the stack */
59
    MessageType currentMessageType() {
60
        return _messages ? _messages->type : NORMAL_MESSAGE;
61
    }
62
    /** @brief returns the text of the message currently at the top of
63
      *        the stack
64
      */
13341.1.190 by Liam P. White
Header cleanup: stop using Glib types where they aren't truly needed. Eases GThread deprecation errors.
65
    char const *currentMessage() {
1 by mental
moving trunk for module inkscape
66
        return _messages ? _messages->message : NULL;
67
    }
68
69
    /** @brief connects to the "changed" signal which is emitted whenever
70
      *        the topmost message on the stack changes.
71
      */
13341.1.190 by Liam P. White
Header cleanup: stop using Glib types where they aren't truly needed. Eases GThread deprecation errors.
72
    sigc::connection connectChanged(sigc::slot<void, MessageType, char const *> slot)
1 by mental
moving trunk for module inkscape
73
    {
74
        return _changed_signal.connect(slot);
75
    }
76
77
    /** @brief pushes a message onto the stack
78
      *
79
      * @param type the message type
80
      * @param message the message text
81
      *
82
      * @return the id of the pushed message
83
      */
13341.1.190 by Liam P. White
Header cleanup: stop using Glib types where they aren't truly needed. Eases GThread deprecation errors.
84
    MessageId push(MessageType type, char const *message);
1 by mental
moving trunk for module inkscape
85
86
    /** @brief pushes a message onto the stack using printf-like formatting
87
      *
88
      * @param type the message type
89
      * @param format a printf-style format string
90
      *
91
      * @return the id of the pushed message
92
      */
13341.1.190 by Liam P. White
Header cleanup: stop using Glib types where they aren't truly needed. Eases GThread deprecation errors.
93
    MessageId pushF(MessageType type, char const *format, ...) G_GNUC_PRINTF(3,4);
1 by mental
moving trunk for module inkscape
94
95
    /** @brief pushes a message onto the stack using printf-like formatting,
96
      *        using a stdarg argument list
97
      *
98
      * @param type the message type
99
      * @param format a printf-style format string
100
      * @param args the subsequent printf-style arguments
101
      *
102
      * @return the id of the pushed message
103
      */
13341.1.190 by Liam P. White
Header cleanup: stop using Glib types where they aren't truly needed. Eases GThread deprecation errors.
104
    MessageId pushVF(MessageType type, char const *format, va_list args);
1 by mental
moving trunk for module inkscape
105
106
    /** @brief removes a message from the stack, given its id
107
      *
108
      * This method will remove a message from the stack if it has not
109
      * already been removed.  It may be removed from any part of the stack.
110
      * 
111
      * @param id the message id to remove
112
      */
113
    void cancel(MessageId id);
114
10507 by Jon A. Cruz
Cleaning up trace methods to aid fixing color inversion.
115
    /**
116
     * Temporarily pushes a message onto the stack.
117
     *
118
     * @param type the message type
119
     * @param message the message text
120
     *
121
     * @return the id of the pushed message
122
     */
13341.1.190 by Liam P. White
Header cleanup: stop using Glib types where they aren't truly needed. Eases GThread deprecation errors.
123
    MessageId flash(MessageType type, char const *message);
1 by mental
moving trunk for module inkscape
124
10507 by Jon A. Cruz
Cleaning up trace methods to aid fixing color inversion.
125
    /**
126
     * Temporarily pushes a message onto the stack.
127
     *
128
     * @param type the message type
129
     * @param message the message text
130
     *
131
     * @return the id of the pushed message
132
     */
133
    MessageId flash(MessageType type, Glib::ustring const &message);
134
135
1 by mental
moving trunk for module inkscape
136
    /** @brief temporarily pushes a message onto the stack using
137
      *        printf-like formatting
138
      *
139
      * @param type the message type
140
      * @param format a printf-style format string
141
      *
142
      * @return the id of the pushed message
143
      */
13341.1.190 by Liam P. White
Header cleanup: stop using Glib types where they aren't truly needed. Eases GThread deprecation errors.
144
    MessageId flashF(MessageType type, char const *format, ...) G_GNUC_PRINTF(3,4);
1 by mental
moving trunk for module inkscape
145
146
    /** @brief temporarily pushes a message onto the stack using
147
      *        printf-like formatting, using a stdarg argument list
148
      *
149
      * @param type the message type
150
      * @param format a printf-style format string
151
      * @param args the printf-style arguments
152
      *
153
      * @return the id of the pushed message
154
      */
13341.1.190 by Liam P. White
Header cleanup: stop using Glib types where they aren't truly needed. Eases GThread deprecation errors.
155
    MessageId flashVF(MessageType type, char const *format, va_list args);
1 by mental
moving trunk for module inkscape
156
157
private:
158
    struct Message {
159
        Message *next;
160
        MessageStack *stack;
161
        MessageId id;
162
        MessageType type;
163
        gchar *message;
164
        guint timeout_id;
165
    };
166
167
    MessageStack(MessageStack const &); // no copy
168
    void operator=(MessageStack const &); // no assign
169
170
    /// pushes a message onto the stack with an optional timeout
13341.1.190 by Liam P. White
Header cleanup: stop using Glib types where they aren't truly needed. Eases GThread deprecation errors.
171
    MessageId _push(MessageType type, unsigned int lifetime, char const *message);
1 by mental
moving trunk for module inkscape
172
173
    Message *_discard(Message *m); ///< frees a message struct and returns the next such struct in the list
174
    void _emitChanged(); ///< emits the "changed" signal
13341.1.190 by Liam P. White
Header cleanup: stop using Glib types where they aren't truly needed. Eases GThread deprecation errors.
175
    static int _timeout(void* data); ///< callback to expire flashed messages
1 by mental
moving trunk for module inkscape
176
13341.1.190 by Liam P. White
Header cleanup: stop using Glib types where they aren't truly needed. Eases GThread deprecation errors.
177
    sigc::signal<void, MessageType, char const *> _changed_signal;
1 by mental
moving trunk for module inkscape
178
    Message *_messages; ///< the stack of messages as a linked list
179
    MessageId _next_id; ///< the next message id to assign
180
};
181
182
}
183
184
#endif
185
/*
186
  Local Variables:
187
  mode:c++
188
  c-file-style:"stroustrup"
189
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
190
  indent-tabs-mode:nil
191
  fill-column:99
192
  End:
193
*/
9900 by Chris Morgan
Super duper mega (fun!) commit: replaced encoding=utf-8 with fileencoding=utf-8 in all 1074 Vim modelines.
194
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :