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