]> git.lyx.org Git - lyx.git/blob - src/FuncRequest.h
Attempt to fix #8137 (arrived at r40862).
[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/mouse_state.h"
20
21
22 namespace lyx {
23
24 /**
25  * This class encapsulates a LyX action and its argument
26  * in order to pass it around easily.
27  */
28 class FuncRequest
29 {
30 public:
31         /// Where the request came from
32         enum Origin {
33                 INTERNAL,
34                 MENU, // A menu entry
35                 TOOLBAR, // A toolbar icon
36                 KEYBOARD, // a keyboard binding
37                 COMMANDBUFFER, 
38                 LYXSERVER,
39                 TOC
40         };
41
42         /// just for putting these things in std::container
43         explicit FuncRequest(Origin o = INTERNAL);
44         /// actions without extra argument
45         explicit FuncRequest(FuncCode act, Origin o = INTERNAL);
46         /// actions without extra argument
47         FuncRequest(FuncCode act, int x, int y, mouse_button::state button,
48                     Origin o = INTERNAL);
49         /// actions with extra argument
50         FuncRequest(FuncCode act, docstring const & arg,
51                     Origin o = INTERNAL);
52         /// actions with extra argument. FIXME: remove this
53         FuncRequest(FuncCode act, std::string const & arg,
54                     Origin o = INTERNAL);
55         /// for changing requests a bit
56         FuncRequest(FuncRequest const & cmd, docstring const & arg,
57                     Origin o = INTERNAL);
58         /// for changing requests a bit. FIXME: remove this
59         FuncRequest(FuncRequest const & cmd, std::string const & arg,
60                     Origin o = INTERNAL);
61
62         /// access the whole argument
63         docstring const & argument() const { return argument_; }
64         ///
65         FuncCode action() const { return action_ ; }
66         ///
67         void setAction(FuncCode act) { action_ = act; }
68         ///
69         Origin origin() const { return origin_; }
70         ///
71         void setOrigin(Origin o) { origin_ = o; }
72         ///
73         int x() const { return x_; }
74         ///
75         int y() const { return y_; }
76         ///
77         void set_y(int y) { y_ = y; }
78         /// 
79         mouse_button::state button() const { return button_; }
80
81         /// argument parsing, extract argument i as std::string
82         std::string getArg(unsigned int i) const;
83         /// argument parsing, extract argument i as std::string,
84         /// eating all characters up to the end of the command line
85         std::string getLongArg(unsigned int i) const;
86
87         /// 
88         static FuncRequest const unknown;
89         /// 
90         static FuncRequest const noaction;
91 private:
92         /// the action
93         FuncCode action_;
94         /// the action's string argument
95         docstring argument_;
96         /// who initiated the action
97         Origin origin_;
98         /// the x coordinate of a mouse press
99         int x_;
100         /// the y coordinate of a mouse press
101         int y_;
102         /// some extra information (like button number)
103         mouse_button::state button_;
104 };
105
106
107 bool operator==(FuncRequest const & lhs, FuncRequest const & rhs);
108
109 std::ostream & operator<<(std::ostream &, FuncRequest const &);
110
111
112 } // namespace lyx
113
114 #endif // FUNCREQUEST_H