]> git.lyx.org Git - lyx.git/blob - src/FuncRequest.cpp
cosmetics
[lyx.git] / src / FuncRequest.cpp
1 /**
2  * \file FuncRequest.cpp
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 using std::istringstream;
21 using std::vector;
22 using std::string;
23
24
25 namespace lyx {
26
27
28 FuncRequest::FuncRequest(Origin o)
29         : action(LFUN_NOACTION), origin(o), x(0), y(0),
30           button_(mouse_button::none)
31 {}
32
33
34 FuncRequest::FuncRequest(kb_action act, Origin o)
35         : action(act), origin(o), x(0), y(0), button_(mouse_button::none)
36 {}
37
38
39 FuncRequest::FuncRequest(kb_action act, docstring const & arg, Origin o)
40         : action(act), argument_(arg), origin(o), x(0), y(0),
41           button_(mouse_button::none)
42 {}
43
44
45 FuncRequest::FuncRequest(kb_action act, string const & arg, Origin o)
46         : action(act), argument_(from_utf8(arg)), origin(o), x(0), y(0),
47           button_(mouse_button::none)
48 {}
49
50
51 FuncRequest::FuncRequest(kb_action act, int ax, int ay,
52                          mouse_button::state but, Origin o)
53         : action(act), origin(o), x(ax), y(ay), button_(but)
54 {}
55
56
57 FuncRequest::FuncRequest(FuncRequest const & cmd, docstring const & arg, Origin o)
58         : action(cmd.action), argument_(arg), origin(o),
59           x(cmd.x), y(cmd.y), button_(cmd.button_)
60 {}
61
62
63 FuncRequest::FuncRequest(FuncRequest const & cmd, string const & arg, Origin o)
64         : action(cmd.action), argument_(from_utf8(arg)), origin(o),
65           x(cmd.x), y(cmd.y), button_(cmd.button_)
66 {}
67
68
69 mouse_button::state FuncRequest::button() const
70 {
71         return button_;
72 }
73
74
75 void split(vector<string> & args, string const & str)
76 {
77         istringstream is(str);
78         while (is) {
79                 char c;
80                 string s;
81                 is >> c;
82                 if (is) {
83                         if (c == '"')
84                                 getline(is, s, '"');
85                         else {
86                                 is.putback(c);
87                                 is >> s;
88                         }
89                         args.push_back(s);
90                 }
91         }
92 }
93
94
95 string FuncRequest::getArg(unsigned int i) const
96 {
97         vector<string> args;
98         split(args, to_utf8(argument_));
99         return i < args.size() ? args[i] : string();
100 }
101
102
103 bool operator==(FuncRequest const & lhs, FuncRequest const & rhs)
104 {
105         return lhs.action == rhs.action && lhs.argument() == rhs.argument();
106 }
107
108
109 std::ostream & operator<<(std::ostream & os, FuncRequest const & cmd)
110 {
111         return os
112                 << " action: " << cmd.action
113                 << " arg: '" << to_utf8(cmd.argument()) << "'"
114                 << " x: " << cmd.x
115                 << " y: " << cmd.y;
116 }
117
118
119 } // namespace lyx