2 * \file FuncRequest.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "FuncRequest.h"
14 #include "LyXAction.h"
16 #include "support/lstrings.h"
24 using namespace lyx::support;
28 FuncRequest const FuncRequest::unknown(LFUN_UNKNOWN_ACTION);
29 FuncRequest const FuncRequest::noaction(LFUN_NOACTION);
31 FuncRequest::FuncRequest(Origin o)
32 : action(LFUN_NOACTION), origin(o), x(0), y(0),
33 button_(mouse_button::none)
37 FuncRequest::FuncRequest(FuncCode act, Origin o)
38 : action(act), origin(o), x(0), y(0), button_(mouse_button::none)
42 FuncRequest::FuncRequest(FuncCode act, docstring const & arg, Origin o)
43 : action(act), argument_(arg), origin(o), x(0), y(0),
44 button_(mouse_button::none)
48 FuncRequest::FuncRequest(FuncCode act, string const & arg, Origin o)
49 : action(act), argument_(from_utf8(arg)), origin(o), x(0), y(0),
50 button_(mouse_button::none)
54 FuncRequest::FuncRequest(FuncCode act, int ax, int ay,
55 mouse_button::state but, Origin o)
56 : action(act), origin(o), x(ax), y(ay), button_(but)
60 FuncRequest::FuncRequest(FuncRequest const & cmd, docstring const & arg, Origin o)
61 : action(cmd.action), argument_(arg), origin(o),
62 x(cmd.x), y(cmd.y), button_(cmd.button_)
66 FuncRequest::FuncRequest(FuncRequest const & cmd, string const & arg, Origin o)
67 : action(cmd.action), argument_(from_utf8(arg)), origin(o),
68 x(cmd.x), y(cmd.y), button_(cmd.button_)
72 mouse_button::state FuncRequest::button() const
80 // Extracts arguments from str into args. Arguments are delimted by
81 // whitespace or by double quotes.
82 // We extract at most max + 1 arguments, treating args[max] as
84 void splitArg(vector<string> & args, string const & str,
85 unsigned int max = UINT_MAX)
87 istringstream is(str);
89 if (args.size() == max) {
92 args.push_back(trim(s));
101 // get quote delimited argument
104 // get whitespace delimited argument
115 string FuncRequest::getArg(unsigned int i) const
118 splitArg(args, to_utf8(argument_));
119 return i < args.size() ? args[i] : string();
123 string FuncRequest::getLongArg(unsigned int i) const
126 splitArg(args, to_utf8(argument_), i);
127 return i < args.size() ? args[i] : string();
131 bool operator==(FuncRequest const & lhs, FuncRequest const & rhs)
133 return lhs.action == rhs.action && lhs.argument() == rhs.argument();
137 ostream & operator<<(ostream & os, FuncRequest const & cmd)
140 << " action: " << cmd.action
141 << " [" << lyxaction.getActionName(cmd.action) << "] "
142 << " arg: '" << to_utf8(cmd.argument()) << "'"