]> git.lyx.org Git - lyx.git/blob - src/FuncRequest.h
Avoid full metrics computation with Update:FitCursor
[lyx.git] / src / FuncRequest.h
1 // -*- C++ -*-
2 /**
3  * \file FuncRequest.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef FUNCREQUEST_H
13 #define FUNCREQUEST_H
14
15 #include "FuncCode.h"
16
17 #include "support/docstring.h"
18
19 #include "frontends/KeyModifier.h"
20 #include "frontends/mouse_state.h"
21
22
23 namespace lyx {
24
25 class LyXErr;
26
27 namespace frontend {
28         class GuiView;
29 }
30
31 /**
32  * This class encapsulates a LyX action and its argument
33  * in order to pass it around easily.
34  */
35 class FuncRequest
36 {
37 public:
38         /// Where the request came from
39         enum Origin {
40                 INTERNAL,
41                 MENU, // A menu entry
42                 TOOLBAR, // A toolbar icon
43                 KEYBOARD, // a keyboard binding
44                 COMMANDBUFFER,
45                 LYXSERVER,
46                 TOC
47         };
48
49         /// just for putting these things in std::container
50         explicit FuncRequest(Origin o = INTERNAL);
51         /// actions without extra argument
52         explicit FuncRequest(FuncCode act, Origin o = INTERNAL);
53         /// actions without extra argument
54         FuncRequest(FuncCode act, int x, int y, mouse_button::state button,
55                     KeyModifier modifier, Origin o = INTERNAL);
56         /// actions with extra argument
57         FuncRequest(FuncCode act, docstring const & arg,
58                     Origin o = INTERNAL);
59         /// actions with extra argument. FIXME: remove this
60         FuncRequest(FuncCode act, std::string const & arg,
61                     Origin o = INTERNAL);
62         /// for changing requests a bit
63         FuncRequest(FuncRequest const & cmd, docstring const & arg,
64                     Origin o = INTERNAL);
65
66         /// access the whole argument
67         docstring const & argument() const { return argument_; }
68         ///
69         FuncCode action() const { return action_ ; }
70         ///
71         void setAction(FuncCode act) { action_ = act; }
72         ///
73         Origin origin() const { return origin_; }
74         ///
75         void setOrigin(Origin o) { origin_ = o; }
76         ///
77         frontend::GuiView* view_origin() const { return view_origin_; }
78         ///
79         void setViewOrigin(frontend::GuiView* o) { view_origin_ = o; }
80         ///
81         int x() const { return x_; }
82         ///
83         int y() const { return y_; }
84         ///
85         void set_y(int y) { y_ = y; }
86         ///
87         mouse_button::state button() const { return button_; }
88         ///
89         KeyModifier modifier() const { return modifier_; }
90
91         /// argument parsing, extract argument i as std::string
92         std::string getArg(unsigned int i) const;
93         /// argument parsing, extract argument i as std::string,
94         /// eating all characters up to the end of the command line
95         std::string getLongArg(unsigned int i) const;
96
97         ///
98         static FuncRequest const unknown;
99         ///
100         static FuncRequest const noaction;
101         ///
102         static FuncRequest const prefix;
103
104         ///
105         bool allowAsync() const { return allow_async_; }
106         ///
107         void allowAsync(bool allow_async) { allow_async_ = allow_async; }
108
109 private:
110         /// the action
111         FuncCode action_ = LFUN_NOACTION;
112         /// the action's string argument
113         docstring argument_;
114         /// who initiated the action
115         Origin origin_ = INTERNAL;
116         /// to which view should be this command sent (see bug #11004)
117         /// NULL=current view
118         frontend::GuiView* view_origin_ = nullptr;
119         /// the x coordinate of a mouse press
120         int x_ = 0;
121         /// the y coordinate of a mouse press
122         int y_ = 0;
123         /// some extra information (like button number)
124         mouse_button::state button_ = mouse_button::none;
125         ///
126         KeyModifier modifier_ = NoModifier;
127         /// Commands should be run synchronously when they
128         /// are launched via "command-sequence" or "repeat" or "buffer-forall"
129         bool allow_async_ = true;
130 };
131
132
133 bool operator==(FuncRequest const & lhs, FuncRequest const & rhs);
134
135 bool operator!=(FuncRequest const & lhs, FuncRequest const & rhs);
136
137 std::ostream & operator<<(std::ostream &, FuncRequest const &);
138
139 LyXErr & operator<<(LyXErr &, FuncRequest const &);
140
141
142 } // namespace lyx
143
144 #endif // FUNCREQUEST_H