2002-08-14 02:29:28 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file FuncRequest.cpp
|
2003-08-23 00:17:00 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-08-14 02:29:28 +00:00
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-23 00:17:00 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-08-14 02:29:28 +00:00
|
|
|
*/
|
|
|
|
|
2002-11-04 00:15:56 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2008-12-15 15:47:33 +00:00
|
|
|
#include "LyXAction.h"
|
2004-02-03 11:49:05 +00:00
|
|
|
|
2012-06-07 15:19:04 +00:00
|
|
|
#include "support/debug.h"
|
2009-12-02 09:39:39 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2010-01-05 15:01:32 +00:00
|
|
|
#include <climits>
|
2003-11-10 09:06:48 +00:00
|
|
|
#include <iostream>
|
2004-07-24 10:55:30 +00:00
|
|
|
#include <sstream>
|
2004-02-03 11:49:05 +00:00
|
|
|
#include <vector>
|
2003-11-10 09:06:48 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2009-12-02 09:39:39 +00:00
|
|
|
using namespace lyx::support;
|
2002-08-14 02:29:28 +00:00
|
|
|
|
2007-07-17 17:46:54 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2007-10-20 23:27:03 +00:00
|
|
|
FuncRequest const FuncRequest::unknown(LFUN_UNKNOWN_ACTION);
|
|
|
|
FuncRequest const FuncRequest::noaction(LFUN_NOACTION);
|
2007-07-17 17:46:54 +00:00
|
|
|
|
2004-11-08 10:54:29 +00:00
|
|
|
FuncRequest::FuncRequest(Origin o)
|
2010-04-12 16:00:10 +00:00
|
|
|
: action_(LFUN_NOACTION), origin_(o), x_(0), y_(0),
|
2016-06-20 19:10:14 +00:00
|
|
|
button_(mouse_button::none), modifier_(NoModifier)
|
2002-08-14 02:29:28 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2008-03-15 01:20:36 +00:00
|
|
|
FuncRequest::FuncRequest(FuncCode act, Origin o)
|
2010-04-12 16:00:10 +00:00
|
|
|
: action_(act), origin_(o), x_(0), y_(0),
|
2016-06-20 19:10:14 +00:00
|
|
|
button_(mouse_button::none), modifier_(NoModifier)
|
2002-08-14 02:29:28 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2008-03-15 01:20:36 +00:00
|
|
|
FuncRequest::FuncRequest(FuncCode act, docstring const & arg, Origin o)
|
2010-04-12 15:40:51 +00:00
|
|
|
: action_(act), argument_(arg), origin_(o), x_(0), y_(0),
|
2016-06-20 19:10:14 +00:00
|
|
|
button_(mouse_button::none), modifier_(NoModifier)
|
2006-09-01 15:41:38 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2008-03-15 01:20:36 +00:00
|
|
|
FuncRequest::FuncRequest(FuncCode act, string const & arg, Origin o)
|
2010-04-12 15:40:51 +00:00
|
|
|
: action_(act), argument_(from_utf8(arg)), origin_(o), x_(0), y_(0),
|
2016-06-20 19:10:14 +00:00
|
|
|
button_(mouse_button::none), modifier_(NoModifier)
|
2002-08-14 02:29:28 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2008-03-15 01:20:36 +00:00
|
|
|
FuncRequest::FuncRequest(FuncCode act, int ax, int ay,
|
2016-06-20 19:10:14 +00:00
|
|
|
mouse_button::state but, KeyModifier modifier, Origin o)
|
|
|
|
: action_(act), origin_(o), x_(ax), y_(ay), button_(but),
|
2016-06-27 22:54:14 +00:00
|
|
|
modifier_(modifier)
|
2002-08-14 02:29:28 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2006-09-01 15:41:38 +00:00
|
|
|
FuncRequest::FuncRequest(FuncRequest const & cmd, docstring const & arg, Origin o)
|
2010-04-12 15:40:51 +00:00
|
|
|
: action_(cmd.action()), argument_(arg), origin_(o),
|
2016-06-20 19:10:14 +00:00
|
|
|
x_(cmd.x_), y_(cmd.y_), button_(cmd.button_), modifier_(NoModifier)
|
2002-08-20 13:00:25 +00:00
|
|
|
{}
|
2002-11-04 00:15:56 +00:00
|
|
|
|
2002-08-20 13:00:25 +00:00
|
|
|
|
2009-12-02 09:39:39 +00:00
|
|
|
namespace {
|
|
|
|
|
2010-01-05 15:01:32 +00:00
|
|
|
// Extracts arguments from str into args. Arguments are delimted by
|
|
|
|
// whitespace or by double quotes.
|
2010-11-29 10:48:40 +00:00
|
|
|
// We extract at most max + 1 arguments, treating args[max] as
|
2010-01-05 15:01:32 +00:00
|
|
|
// continuing to eol.
|
2010-11-29 10:48:40 +00:00
|
|
|
void splitArg(vector<string> & args, string const & str,
|
2010-01-05 15:01:32 +00:00
|
|
|
unsigned int max = UINT_MAX)
|
2003-02-26 18:03:48 +00:00
|
|
|
{
|
2003-09-15 11:00:00 +00:00
|
|
|
istringstream is(str);
|
2003-02-26 18:03:48 +00:00
|
|
|
while (is) {
|
2009-12-02 09:39:39 +00:00
|
|
|
if (args.size() == max) {
|
|
|
|
string s;
|
|
|
|
getline(is, s);
|
|
|
|
args.push_back(trim(s));
|
|
|
|
return;
|
2010-11-29 10:48:40 +00:00
|
|
|
}
|
2009-12-02 09:39:39 +00:00
|
|
|
|
2003-02-26 18:03:48 +00:00
|
|
|
char c;
|
|
|
|
string s;
|
|
|
|
is >> c;
|
2005-07-16 17:27:16 +00:00
|
|
|
if (is) {
|
|
|
|
if (c == '"')
|
2010-01-05 15:01:32 +00:00
|
|
|
// get quote delimited argument
|
2005-07-16 17:27:16 +00:00
|
|
|
getline(is, s, '"');
|
|
|
|
else {
|
2010-01-05 15:01:32 +00:00
|
|
|
// get whitespace delimited argument
|
2005-07-16 17:27:16 +00:00
|
|
|
is.putback(c);
|
|
|
|
is >> s;
|
|
|
|
}
|
|
|
|
args.push_back(s);
|
2003-02-26 18:03:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-02 09:39:39 +00:00
|
|
|
}
|
2003-02-26 18:03:48 +00:00
|
|
|
|
2003-09-21 18:57:15 +00:00
|
|
|
string FuncRequest::getArg(unsigned int i) const
|
2003-02-26 18:03:48 +00:00
|
|
|
{
|
|
|
|
vector<string> args;
|
2010-01-05 15:01:32 +00:00
|
|
|
splitArg(args, to_utf8(argument_));
|
2009-12-02 09:39:39 +00:00
|
|
|
return i < args.size() ? args[i] : string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string FuncRequest::getLongArg(unsigned int i) const
|
|
|
|
{
|
|
|
|
vector<string> args;
|
|
|
|
splitArg(args, to_utf8(argument_), i);
|
2003-02-26 18:03:48 +00:00
|
|
|
return i < args.size() ? args[i] : string();
|
|
|
|
}
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool operator==(FuncRequest const & lhs, FuncRequest const & rhs)
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
return lhs.action() == rhs.action() && lhs.argument() == rhs.argument();
|
2003-11-10 09:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
ostream & operator<<(ostream & os, FuncRequest const & cmd)
|
2003-11-10 09:06:48 +00:00
|
|
|
{
|
|
|
|
return os
|
2012-06-07 15:19:04 +00:00
|
|
|
<< " action: " << cmd.action()
|
|
|
|
<< " [" << lyxaction.getActionName(cmd.action()) << "] "
|
2006-10-21 00:16:43 +00:00
|
|
|
<< " arg: '" << to_utf8(cmd.argument()) << "'"
|
2010-04-09 19:00:42 +00:00
|
|
|
<< " x: " << cmd.x()
|
|
|
|
<< " y: " << cmd.y();
|
2003-11-10 09:06:48 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2012-06-07 15:19:04 +00:00
|
|
|
LyXErr & operator<<(LyXErr &l, FuncRequest const &fr)
|
|
|
|
{
|
|
|
|
ostringstream oss;
|
|
|
|
oss << fr;
|
|
|
|
return l << oss.str();
|
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|