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