]> git.lyx.org Git - lyx.git/blob - src/funcrequest.C
more cursor dispatch
[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 "support/std_sstream.h"
16
17 #include <iostream>
18 #include <vector>
19
20 using std::getline;
21
22 using std::istringstream;
23 using std::vector;
24 using std::string;
25
26
27 FuncRequest::FuncRequest()
28         : action(LFUN_NOACTION), x(0), y(0), button_(mouse_button::none)
29 {}
30
31
32 FuncRequest::FuncRequest(kb_action act)
33         : action(act), x(0), y(0), button_(mouse_button::none)
34 {}
35
36
37 FuncRequest::FuncRequest(kb_action act, string const & arg)
38         : action(act), argument(arg), x(0), y(0), button_(mouse_button::none)
39 {}
40
41
42 FuncRequest::FuncRequest(kb_action act, int ax, int ay, mouse_button::state but)
43         : action(act), x(ax), y(ay), button_(but)
44 {}
45
46
47 FuncRequest::FuncRequest(FuncRequest const & cmd, string const & arg)
48         : action(cmd.action), argument(arg),
49           x(cmd.x), y(cmd.y), button_(cmd.button_)
50 {}
51
52
53 mouse_button::state FuncRequest::button() const
54 {
55         return button_;
56 }
57
58
59 void split(vector<string> & args, string str)
60 {
61         istringstream is(str);
62         while (is) {
63                 char c;
64                 string s;
65                 is >> c;
66                 if (c == '"')
67                         getline(is, s, '"');
68                 else {
69                         is.putback(c);
70                         is >> s;
71                 }
72                 args.push_back(s);
73         }
74 }
75
76
77 string FuncRequest::getArg(unsigned int i) const
78 {
79         vector<string> args;
80         split(args, argument);
81         return i < args.size() ? args[i] : string();
82 }
83
84
85 bool operator==(FuncRequest const & lhs, FuncRequest const & rhs)
86 {
87         return lhs.action == rhs.action && lhs.argument == rhs.argument;
88 }
89
90
91 std::ostream & operator<<(std::ostream & os, FuncRequest const & cmd)
92 {
93         return os
94                 << " action: " << cmd.action 
95                 << " arg: '" << cmd.argument << "'"
96                 << " x: " << cmd.x 
97                 << " y: " << cmd.y; 
98 }