1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetCommand.h
|
2002-09-25 14:26:13 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
* \author Angus Leeming
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
#ifndef INSETCOMMAND_H
|
|
|
|
#define INSETCOMMAND_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
#include "Inset.h"
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetCommandParams.h"
|
|
|
|
#include "RenderButton.h"
|
2004-01-20 14:25:24 +00:00
|
|
|
|
2000-08-01 17:33:32 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2010-10-31 01:04:03 +00:00
|
|
|
class Cursor;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// InsetCommand
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Created by Alejandro 970222
|
2008-03-27 22:26:24 +00:00
|
|
|
// Used to insert a LaTeX command automatically.
|
2000-07-27 08:55:59 +00:00
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
class InsetCommand : public Inset
|
|
|
|
{
|
1999-09-27 18:44:28 +00:00
|
|
|
public:
|
2009-11-08 16:10:34 +00:00
|
|
|
///
|
2010-10-29 00:46:21 +00:00
|
|
|
InsetCommand(Buffer *, InsetCommandParams const &);
|
2003-12-11 15:23:15 +00:00
|
|
|
///
|
2010-05-01 23:04:08 +00:00
|
|
|
InsetCommand(InsetCommand const & rhs);
|
|
|
|
///
|
2010-05-03 21:43:46 +00:00
|
|
|
virtual ~InsetCommand();
|
2010-10-25 20:20:44 +00:00
|
|
|
///
|
|
|
|
InsetCommand * asInsetCommand() { return this; }
|
|
|
|
///
|
|
|
|
InsetCommand const * asInsetCommand() const { return this; }
|
|
|
|
|
2010-10-28 16:28:57 +00:00
|
|
|
/// \return true if params are successfully read
|
2010-10-29 00:25:28 +00:00
|
|
|
static bool string2params(std::string const & data,
|
2008-03-27 22:26:24 +00:00
|
|
|
InsetCommandParams &);
|
2003-05-26 09:13:55 +00:00
|
|
|
///
|
2010-10-29 00:25:28 +00:00
|
|
|
static std::string params2string(InsetCommandParams const &);
|
2007-09-21 20:39:47 +00:00
|
|
|
///
|
2008-03-27 22:26:24 +00:00
|
|
|
InsetCommandParams const & params() const { return p_; }
|
2003-06-12 08:52:36 +00:00
|
|
|
///
|
2008-03-27 22:26:24 +00:00
|
|
|
void setParams(InsetCommandParams const &);
|
|
|
|
///
|
|
|
|
docstring const & getParam(std::string const & name) const;
|
2010-10-25 20:20:44 +00:00
|
|
|
///
|
|
|
|
void setParam(std::string const & name, docstring const & value);
|
2008-03-27 22:26:24 +00:00
|
|
|
/// FIXME Remove
|
|
|
|
docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); }
|
|
|
|
|
2010-10-27 21:35:13 +00:00
|
|
|
/// \name Public functions inherited from Inset class
|
2010-10-25 20:20:44 +00:00
|
|
|
//@{
|
2003-06-03 15:10:14 +00:00
|
|
|
///
|
2008-02-27 20:43:16 +00:00
|
|
|
void write(std::ostream & os) const { p_.write(os); }
|
2000-07-13 09:38:34 +00:00
|
|
|
///
|
2008-02-27 20:43:16 +00:00
|
|
|
void read(Lexer & lex) { p_.read(lex); }
|
2002-03-21 17:09:55 +00:00
|
|
|
///
|
2008-03-27 22:26:24 +00:00
|
|
|
void doDispatch(Cursor & cur, FuncRequest & cmd);
|
|
|
|
///
|
2008-04-27 18:03:21 +00:00
|
|
|
bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
|
2008-03-27 22:26:24 +00:00
|
|
|
///
|
|
|
|
void metrics(MetricsInfo &, Dimension &) const;
|
|
|
|
///
|
|
|
|
void draw(PainterInfo & pi, int x, int y) const;
|
|
|
|
///
|
2011-02-10 20:02:48 +00:00
|
|
|
void latex(otexstream &, OutputParams const &) const;
|
2000-03-06 02:42:40 +00:00
|
|
|
///
|
2013-03-08 19:52:18 +00:00
|
|
|
int plaintext(odocstringstream & ods, OutputParams const & op,
|
|
|
|
size_t max_length = INT_MAX) const;
|
2000-04-24 20:58:23 +00:00
|
|
|
///
|
2008-02-27 20:43:16 +00:00
|
|
|
int docbook(odocstream &, OutputParams const & runparams) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2010-10-25 20:20:44 +00:00
|
|
|
bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
|
2000-08-04 13:12:30 +00:00
|
|
|
///
|
2010-10-24 21:46:28 +00:00
|
|
|
bool clickable(int, int) const { return hasSettings(); }
|
2010-11-25 16:53:56 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/// \name Methods relaying to the InsetCommandParams p_
|
|
|
|
//@{
|
2010-10-24 20:11:40 +00:00
|
|
|
///
|
2011-10-29 14:48:55 +00:00
|
|
|
std::string contextMenuName() const;
|
2006-12-04 04:31:18 +00:00
|
|
|
///
|
2010-10-25 20:20:44 +00:00
|
|
|
bool showInsetDialog(BufferView * bv) const;
|
|
|
|
///
|
|
|
|
Dimension const dimension(BufferView const &) const
|
|
|
|
{ return button_.dimension(); }
|
|
|
|
//@}
|
|
|
|
|
|
|
|
protected:
|
2010-10-27 21:35:13 +00:00
|
|
|
/// \name Functions relaying to the InsetCommandParams
|
2010-10-25 20:20:44 +00:00
|
|
|
//@{
|
|
|
|
/// Build the complete LaTeX command
|
|
|
|
/// \see InsetCommandParams::getCommand
|
|
|
|
docstring const getCommand(OutputParams const & rp) const
|
|
|
|
{ return p_.getCommand(rp); }
|
|
|
|
/// Return the command name
|
|
|
|
/// \see InsetCommandParams::getCmdName
|
|
|
|
std::string const & getCmdName() const { return p_.getCmdName(); }
|
|
|
|
/// Set the name to \p n. This must be a known name. All parameters
|
|
|
|
/// are cleared except those that exist also in the new command.
|
|
|
|
/// What matters here is the parameter name, not position.
|
|
|
|
/// \see InsetCommandParams::setCmdName
|
|
|
|
void setCmdName(std::string const & n) { p_.setCmdName(n); }
|
|
|
|
//@}
|
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
RenderButton & button() const { return button_; }
|
|
|
|
/// This should provide the text for the button
|
|
|
|
virtual docstring screenLabel() const = 0;
|
|
|
|
|
2010-10-27 21:35:13 +00:00
|
|
|
/// \name Static public methods obligated for InsetCommand derived classes
|
2010-10-25 20:20:44 +00:00
|
|
|
//@{
|
2007-10-25 04:13:56 +00:00
|
|
|
/// Return parameter information for command cmdName.
|
|
|
|
/// Not implemented here. Must be implemented in derived class.
|
2008-02-23 22:01:02 +00:00
|
|
|
static ParamInfo const & findInfo(std::string const & cmdName);
|
2007-10-25 04:13:56 +00:00
|
|
|
/// Return default command for this inset.
|
|
|
|
/// Not implemented here. Must be implemented in derived class.
|
|
|
|
static std::string defaultCommand();
|
|
|
|
/// Whether this is a command this inset can represent.
|
|
|
|
/// Not implemented here. Must be implemented in derived class.
|
|
|
|
static bool isCompatibleCommand(std::string const & cmd);
|
2010-10-25 20:20:44 +00:00
|
|
|
//@}
|
|
|
|
|
2000-07-27 08:55:59 +00:00
|
|
|
///
|
|
|
|
InsetCommandParams p_;
|
2006-12-04 04:31:18 +00:00
|
|
|
/// changes color when mouse enters/leaves this inset
|
2010-04-30 14:47:46 +00:00
|
|
|
mutable std::map<BufferView const *, bool> mouse_hover_;
|
2007-04-29 12:32:14 +00:00
|
|
|
///
|
2003-10-10 21:08:55 +00:00
|
|
|
mutable RenderButton button_;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
2009-09-26 17:19:18 +00:00
|
|
|
/// Decode InsetCommand considering Inset name and data.
|
|
|
|
bool decodeInsetParam(std::string const & name, std::string & data,
|
|
|
|
Buffer const & buffer);
|
2003-02-25 14:51:38 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|