]> git.lyx.org Git - lyx.git/blob - src/FuncRequest.h
Amend 9f04eeae032d
[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() { 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         bool allowAsync() const { return allow_async_; }
103         ///
104         void allowAsync(bool allow_async) { allow_async_ = allow_async; }
105
106 private:
107         /// the action
108         FuncCode action_;
109         /// the action's string argument
110         docstring argument_;
111         /// who initiated the action
112         Origin origin_;
113         /// to which view should be this command sent (see bug #11004)
114         /// NULL=current view
115         frontend::GuiView* view_origin_;
116         /// the x coordinate of a mouse press
117         int x_;
118         /// the y coordinate of a mouse press
119         int y_;
120         /// some extra information (like button number)
121         mouse_button::state button_;
122         ///
123         KeyModifier modifier_;
124         /// Commands should be run synchronously when they
125         /// are launched via "command-sequence" or "repeat" or "buffer-forall"
126         bool allow_async_;
127 };
128
129
130 bool operator==(FuncRequest const & lhs, FuncRequest const & rhs);
131
132 std::ostream & operator<<(std::ostream &, FuncRequest const &);
133
134 LyXErr & operator<<(LyXErr &, FuncRequest const &);
135
136
137 } // namespace lyx
138
139 #endif // FUNCREQUEST_H