]> git.lyx.org Git - lyx.git/blob - src/dispatchresult.h
more cursor dispatch
[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         FINISHED_POP       = FINISHED, but move the cursor out the inset
29                        (possibly more than one level)
30         UNDISPATCHED        = the action was not caught, it should be
31                         dispatched by lower level insets
32 */
33 enum dispatch_result_t {
34         NONE = 0,
35         FINISHED,
36         FINISHED_RIGHT,
37         FINISHED_UP,
38         FINISHED_DOWN
39 };
40
41
42 /** \c DispatchResult is a wrapper for dispatch_result_t.
43  *  It can be forward-declared and passed as a function argument without
44  *  having to expose insetbase.h.
45  */
46 class DispatchResult {
47 public:
48         DispatchResult()
49                 : dispatched_(false), val_(NONE) {}
50         explicit
51         DispatchResult(bool dis)
52                 : dispatched_(dis), update_(false), val_(NONE) {}
53         DispatchResult(bool dis, bool update)
54                 : dispatched_(dis), update_(update), val_(NONE) {}
55         DispatchResult(bool dis, dispatch_result_t val)
56                 : dispatched_(dis), update_(true), val_(val) {}
57         dispatch_result_t val() const { return val_; }
58         void val(dispatch_result_t drt) {
59                 val_ = drt;
60         }
61         bool dispatched() const {
62                 return dispatched_;
63         }
64         void dispatched(bool dis) {
65                 dispatched_ = dis;
66         }
67         bool update() const {
68                 return update_;
69         }
70         void update(bool up) {
71                 update_ = up;
72         }
73 private:
74         bool dispatched_;
75         bool update_;
76         dispatch_result_t val_;
77 };
78
79
80 inline
81 bool operator==(DispatchResult const & lhs, DispatchResult const & rhs)
82 {
83         return lhs.dispatched() == rhs.dispatched() && lhs.val() == rhs.val();
84 }
85
86
87 inline
88 bool operator!=(DispatchResult const & lhs, DispatchResult const & rhs)
89 {
90         return !(lhs == rhs);
91 }
92
93 #endif // DISPATCH_RESULT_H