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/debug.h"
17 #include "support/lstrings.h"
25 using namespace lyx::support;
29 FuncRequest const FuncRequest::unknown(LFUN_UNKNOWN_ACTION);
30 FuncRequest const FuncRequest::noaction(LFUN_NOACTION);
32 FuncRequest::FuncRequest(Origin o)
33 : action_(LFUN_NOACTION), origin_(o), x_(0), y_(0),
34 button_(mouse_button::none), modifier_(NoModifier), view_origin_(0)
38 FuncRequest::FuncRequest(FuncCode act, Origin o)
39 : action_(act), origin_(o), x_(0), y_(0),
40 button_(mouse_button::none), modifier_(NoModifier), view_origin_(0)
44 FuncRequest::FuncRequest(FuncCode act, docstring const & arg, Origin o)
45 : action_(act), argument_(arg), origin_(o), x_(0), y_(0),
46 button_(mouse_button::none), modifier_(NoModifier), view_origin_(0)
50 FuncRequest::FuncRequest(FuncCode act, string const & arg, Origin o)
51 : action_(act), argument_(from_utf8(arg)), origin_(o), x_(0), y_(0),
52 button_(mouse_button::none), modifier_(NoModifier), view_origin_(0)
56 FuncRequest::FuncRequest(FuncCode act, int ax, int ay,
57 mouse_button::state but, KeyModifier modifier, Origin o)
58 : action_(act), origin_(o), x_(ax), y_(ay), button_(but),
59 modifier_(modifier), view_origin_(0)
63 FuncRequest::FuncRequest(FuncRequest const & cmd, docstring const & arg, Origin o)
64 : action_(cmd.action()), argument_(arg), origin_(o),
65 x_(cmd.x_), y_(cmd.y_), button_(cmd.button_), modifier_(NoModifier),
72 // Extracts arguments from str into args. Arguments are delimited by
73 // whitespace or by double quotes.
74 // We extract at most max + 1 arguments, treating args[max] as
76 void splitArg(vector<string> & args, string const & str,
77 unsigned int max = UINT_MAX)
79 istringstream is(str);
81 if (args.size() == max) {
84 args.push_back(trim(s));
93 // get quote delimited argument
96 // get whitespace delimited argument
107 string FuncRequest::getArg(unsigned int i) const
110 splitArg(args, to_utf8(argument_));
111 return i < args.size() ? args[i] : string();
115 string FuncRequest::getLongArg(unsigned int i) const
118 splitArg(args, to_utf8(argument_), i);
119 return i < args.size() ? args[i] : string();
123 bool operator==(FuncRequest const & lhs, FuncRequest const & rhs)
125 return lhs.action() == rhs.action() && lhs.argument() == rhs.argument();
129 ostream & operator<<(ostream & os, FuncRequest const & cmd)
132 << " action: " << cmd.action()
133 << " [" << lyxaction.getActionName(cmd.action()) << "] "
134 << " arg: '" << to_utf8(cmd.argument()) << "'"
136 << " y: " << cmd.y();
140 LyXErr & operator<<(LyXErr &l, FuncRequest const &fr)
144 return l << oss.str();