]> git.lyx.org Git - lyx.git/blob - src/funcrequest.C
Helge's infamous brackets bug
[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 const & str)
62 {
63         istringstream is(str);
64         while (is) {
65                 char c;
66                 string s;
67                 is >> c;
68                 if (is) {
69                         if (c == '"')
70                                 getline(is, s, '"');
71                         else {
72                                 is.putback(c);
73                                 is >> s;
74                         }
75                         args.push_back(s);
76                 }
77         }
78 }
79
80
81 string FuncRequest::getArg(unsigned int i) const
82 {
83         vector<string> args;
84         split(args, argument);
85         return i < args.size() ? args[i] : string();
86 }
87
88
89 bool operator==(FuncRequest const & lhs, FuncRequest const & rhs)
90 {
91         return lhs.action == rhs.action && lhs.argument == rhs.argument;
92 }
93
94
95 std::ostream & operator<<(std::ostream & os, FuncRequest const & cmd)
96 {
97         return os
98                 << " action: " << cmd.action
99                 << " arg: '" << cmd.argument << "'"
100                 << " x: " << cmd.x
101                 << " y: " << cmd.y;
102 }