]> git.lyx.org Git - lyx.git/blob - src/funcrequest.C
gnome build removal, gtk build fix
[lyx.git] / src / funcrequest.C
1 /**
2  * \file funcrequest.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "funcrequest.h"
14
15 #include <iostream>
16 #include <sstream>
17 #include <vector>
18
19 using std::getline;
20
21 using std::istringstream;
22 using std::vector;
23 using std::string;
24
25
26 FuncRequest::FuncRequest(Origin o)
27         : action(LFUN_NOACTION), origin(o), x(0), y(0),
28           button_(mouse_button::none)
29 {}
30
31
32 FuncRequest::FuncRequest(kb_action act, Origin o)
33         : action(act), origin(o), x(0), y(0), button_(mouse_button::none)
34 {}
35
36
37 FuncRequest::FuncRequest(kb_action act, string const & arg, Origin o)
38         : action(act), argument(arg), origin(o), x(0), y(0),
39           button_(mouse_button::none)
40 {}
41
42
43 FuncRequest::FuncRequest(kb_action act, int ax, int ay,
44                          mouse_button::state but, Origin o)
45         : action(act), origin(o), x(ax), y(ay), button_(but)
46 {}
47
48
49 FuncRequest::FuncRequest(FuncRequest const & cmd, string const & arg, Origin o)
50         : action(cmd.action), argument(arg), origin(o),
51           x(cmd.x), y(cmd.y), button_(cmd.button_)
52 {}
53
54
55 mouse_button::state FuncRequest::button() const
56 {
57         return button_;
58 }
59
60
61 void split(vector<string> & args, string str)
62 {
63         istringstream is(str);
64         while (is) {
65                 char c;
66                 string s;
67                 is >> c;
68                 if (c == '"')
69                         getline(is, s, '"');
70                 else {
71                         is.putback(c);
72                         is >> s;
73                 }
74                 args.push_back(s);
75         }
76 }
77
78
79 string FuncRequest::getArg(unsigned int i) const
80 {
81         vector<string> args;
82         split(args, argument);
83         return i < args.size() ? args[i] : string();
84 }
85
86
87 bool operator==(FuncRequest const & lhs, FuncRequest const & rhs)
88 {
89         return lhs.action == rhs.action && lhs.argument == rhs.argument;
90 }
91
92
93 std::ostream & operator<<(std::ostream & os, FuncRequest const & cmd)
94 {
95         return os
96                 << " action: " << cmd.action
97                 << " arg: '" << cmd.argument << "'"
98                 << " x: " << cmd.x
99                 << " y: " << cmd.y;
100 }