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 : argument_(arg), action_(act), origin_(o), x_(0), y_(0),
44 button_(mouse_button::none)
48 FuncRequest::FuncRequest(FuncCode act, string const & arg, Origin o)
49 : argument_(from_utf8(arg)), action_(act), 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 : argument_(arg), action_(cmd.action()), origin_(o),
62 x_(cmd.x_), y_(cmd.y_), button_(cmd.button_)
66 FuncRequest::FuncRequest(FuncRequest const & cmd, string const & arg, Origin o)
67 : argument_(from_utf8(arg)), action_(cmd.action()), origin_(o),
68 x_(cmd.x_), y_(cmd.y_), button_(cmd.button_)
74 // Extracts arguments from str into args. Arguments are delimted by
75 // whitespace or by double quotes.
76 // We extract at most max + 1 arguments, treating args[max] as
78 void splitArg(vector<string> & args, string const & str,
79 unsigned int max = UINT_MAX)
81 istringstream is(str);
83 if (args.size() == max) {
86 args.push_back(trim(s));
95 // get quote delimited argument
98 // get whitespace delimited argument
109 string FuncRequest::getArg(unsigned int i) const
112 splitArg(args, to_utf8(argument_));
113 return i < args.size() ? args[i] : string();
117 string FuncRequest::getLongArg(unsigned int i) const
120 splitArg(args, to_utf8(argument_), i);
121 return i < args.size() ? args[i] : string();
125 bool operator==(FuncRequest const & lhs, FuncRequest const & rhs)
127 return lhs.action() == rhs.action() && lhs.argument() == rhs.argument();
131 ostream & operator<<(ostream & os, FuncRequest const & cmd)
134 << " action: " << cmd.action()
135 << " [" << lyxaction.getActionName(cmd.action()) << "] "
136 << " arg: '" << to_utf8(cmd.argument()) << "'"
138 << " y: " << cmd.y();