]> git.lyx.org Git - lyx.git/blob - src/dispatchresult.h
5ecfb35dbbcb87adb132a1778ece31cc29133a26
[lyx.git] / src / dispatchresult.h
1 // -*- C++ -*-
2 /**
3  * \file dispatchresult.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author none
8  * \author Lars Gullik Bjønnes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef DISPATCH_RESULT_H
14 #define DISPATCH_RESULT_H
15
16 /** Dispatch result codes
17         DISPATCHED          = the inset caught the action
18         DISPATCHED_NOUPDATE = the inset caught the action and no update
19                         is needed to redraw the inset
20         FINISHED            = the inset must be unlocked as a result
21                         of the action
22         FINISHED_RIGHT      = FINISHED, but move the cursor RIGHT from
23                         the inset.
24         FINISHED_UP         = FINISHED, but move the cursor UP from
25                         the inset.
26         FINISHED_DOWN       = FINISHED, but move the cursor DOWN from
27                         the inset.
28         UNDISPATCHED        = the action was not catched, it should be
29                         dispatched by lower level insets
30 */
31 enum dispatch_result_t {
32         NONE = 0,
33         NOUPDATE,
34         FINISHED,
35         FINISHED_RIGHT,
36         FINISHED_UP,
37         FINISHED_DOWN
38 };
39
40 /** \c DispatchResult is a wrapper for dispatch_result_t.
41  *  It can be forward-declared and passed as a function argument without
42  *  having to expose insetbase.h.
43  */
44 class DispatchResult {
45 public:
46         DispatchResult()
47                 : dispatched_(false), val_(NONE) {}
48         explicit
49         DispatchResult(bool dis)
50                 : dispatched_(dis), val_(NONE) {}
51         DispatchResult(bool dis, dispatch_result_t val)
52                 : dispatched_(dis), val_(val) {}
53         dispatch_result_t val() const { return val_; }
54         bool dispatched() const {
55                 return dispatched_;
56         }
57 private:
58         bool dispatched_;
59         dispatch_result_t val_;
60 };
61
62
63 inline
64 bool operator==(DispatchResult const & lhs, DispatchResult const & rhs)
65 {
66         return lhs.dispatched() == rhs.dispatched() && lhs.val() == rhs.val();
67 }
68
69
70 inline
71 bool operator!=(DispatchResult const & lhs, DispatchResult const & rhs)
72 {
73         return !(lhs == rhs);
74 }
75
76 #endif // DISPATCH_RESULT_H