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),
39 button_(mouse_button::none)
43 FuncRequest::FuncRequest(FuncCode act, docstring const & arg, Origin o)
44 : action_(act), argument_(arg), origin_(o), x_(0), y_(0),
45 button_(mouse_button::none)
49 FuncRequest::FuncRequest(FuncCode act, string const & arg, Origin o)
50 : action_(act), argument_(from_utf8(arg)), origin_(o), x_(0), y_(0),
51 button_(mouse_button::none)
55 FuncRequest::FuncRequest(FuncCode act, int ax, int ay,
56 mouse_button::state but, Origin o)
57 : action_(act), origin_(o), x_(ax), y_(ay), button_(but)
61 FuncRequest::FuncRequest(FuncRequest const & cmd, docstring const & arg, Origin o)
62 : action_(cmd.action()), argument_(arg), origin_(o),
63 x_(cmd.x_), y_(cmd.y_), button_(cmd.button_)
67 FuncRequest::FuncRequest(FuncRequest const & cmd, string const & arg, Origin o)
68 : action_(cmd.action()), argument_(from_utf8(arg)), origin_(o),
69 x_(cmd.x_), y_(cmd.y_), button_(cmd.button_)
75 // Extracts arguments from str into args. Arguments are delimted by
76 // whitespace or by double quotes.
77 // We extract at most max + 1 arguments, treating args[max] as
79 void splitArg(vector<string> & args, string const & str,
80 unsigned int max = UINT_MAX)
82 istringstream is(str);
84 if (args.size() == max) {
87 args.push_back(trim(s));
96 // get quote delimited argument
99 // get whitespace delimited argument
110 string FuncRequest::getArg(unsigned int i) const
113 splitArg(args, to_utf8(argument_));
114 return i < args.size() ? args[i] : string();
118 string FuncRequest::getLongArg(unsigned int i) const
121 splitArg(args, to_utf8(argument_), i);
122 return i < args.size() ? args[i] : string();
126 bool operator==(FuncRequest const & lhs, FuncRequest const & rhs)
128 return lhs.action() == rhs.action() && lhs.argument() == rhs.argument();
132 ostream & operator<<(ostream & os, FuncRequest const & cmd)
135 << " action: " << cmd.action()
136 << " [" << lyxaction.getActionName(cmd.action()) << "] "
137 << " arg: '" << to_utf8(cmd.argument()) << "'"
139 << " y: " << cmd.y();