]> git.lyx.org Git - lyx.git/blob - src/FuncRequest.cpp
MathML for InsetMathBig.
[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 #include "LyXAction.h"
15
16 #include "support/lstrings.h"
17
18 #include <iostream>
19 #include <sstream>
20 #include <vector>
21
22 using namespace std;
23 using namespace lyx::support;
24
25 namespace lyx {
26
27 FuncRequest const FuncRequest::unknown(LFUN_UNKNOWN_ACTION);
28 FuncRequest const FuncRequest::noaction(LFUN_NOACTION);
29
30 FuncRequest::FuncRequest(Origin o)
31         : action(LFUN_NOACTION), origin(o), x(0), y(0),
32           button_(mouse_button::none)
33 {}
34
35
36 FuncRequest::FuncRequest(FuncCode act, Origin o)
37         : action(act), origin(o), x(0), y(0), button_(mouse_button::none)
38 {}
39
40
41 FuncRequest::FuncRequest(FuncCode act, docstring const & arg, Origin o)
42         : action(act), argument_(arg), origin(o), x(0), y(0),
43           button_(mouse_button::none)
44 {}
45
46
47 FuncRequest::FuncRequest(FuncCode act, string const & arg, Origin o)
48         : action(act), argument_(from_utf8(arg)), origin(o), x(0), y(0),
49           button_(mouse_button::none)
50 {}
51
52
53 FuncRequest::FuncRequest(FuncCode act, int ax, int ay,
54                          mouse_button::state but, Origin o)
55         : action(act), origin(o), x(ax), y(ay), button_(but)
56 {}
57
58
59 FuncRequest::FuncRequest(FuncRequest const & cmd, docstring const & arg, Origin o)
60         : action(cmd.action), argument_(arg), origin(o),
61           x(cmd.x), y(cmd.y), button_(cmd.button_)
62 {}
63
64
65 FuncRequest::FuncRequest(FuncRequest const & cmd, string const & arg, Origin o)
66         : action(cmd.action), argument_(from_utf8(arg)), origin(o),
67           x(cmd.x), y(cmd.y), button_(cmd.button_)
68 {}
69
70
71 mouse_button::state FuncRequest::button() const
72 {
73         return button_;
74 }
75
76
77 namespace {
78
79 void splitArg(vector<string> & args, string const & str, unsigned int max)
80 {
81         istringstream is(str);
82         while (is) {
83                 if (args.size() == max) {
84                         string s;
85                         getline(is, s);
86                         args.push_back(trim(s));
87                         return;
88                 }               
89
90                 char c;
91                 string s;
92                 is >> c;
93                 if (is) {
94                         if (c == '"')
95                                 getline(is, s, '"');
96                         else {
97                                 is.putback(c);
98                                 is >> s;
99                         }
100                         args.push_back(s);
101                 }
102         }
103 }
104
105 }
106
107 string FuncRequest::getArg(unsigned int i) const
108 {
109         vector<string> args;
110         splitArg(args, to_utf8(argument_), string::npos);
111         return i < args.size() ? args[i] : string();
112 }
113
114
115 string FuncRequest::getLongArg(unsigned int i) const
116 {
117         vector<string> args;
118         splitArg(args, to_utf8(argument_), i);
119         return i < args.size() ? args[i] : string();
120 }
121
122
123 bool operator==(FuncRequest const & lhs, FuncRequest const & rhs)
124 {
125         return lhs.action == rhs.action && lhs.argument() == rhs.argument();
126 }
127
128
129 ostream & operator<<(ostream & os, FuncRequest const & cmd)
130 {
131         return os
132                 << " action: " << cmd.action 
133                 << " [" << lyxaction.getActionName(cmd.action) << "] " 
134                 << " arg: '" << to_utf8(cmd.argument()) << "'"
135                 << " x: " << cmd.x
136                 << " y: " << cmd.y;
137 }
138
139
140 } // namespace lyx