2003-08-19 13:00:56 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
* \file InsetMathNest.h
|
2003-08-19 13:00:56 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2001-08-03 17:10:22 +00:00
|
|
|
#ifndef MATH_NESTINSET_H
|
|
|
|
#define MATH_NESTINSET_H
|
|
|
|
|
2007-04-30 10:31:51 +00:00
|
|
|
#include "InsetMath.h"
|
2003-09-07 21:25:37 +00:00
|
|
|
|
2008-03-15 00:22:54 +00:00
|
|
|
// FIXME: remove
|
|
|
|
#include "support/docstring.h"
|
2008-02-21 19:42:34 +00:00
|
|
|
|
2010-04-30 14:47:46 +00:00
|
|
|
#include <map>
|
|
|
|
|
2008-03-15 00:22:54 +00:00
|
|
|
namespace lyx {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2001-11-26 13:35:08 +00:00
|
|
|
/** Abstract base class for all math objects that contain nested items.
|
|
|
|
This is basically everything that is not a single character or a
|
2002-06-14 10:48:27 +00:00
|
|
|
single symbol.
|
2001-08-03 17:10:22 +00:00
|
|
|
*/
|
|
|
|
|
2007-04-30 10:31:51 +00:00
|
|
|
class InsetMathNest : public InsetMath {
|
2002-03-21 17:42:56 +00:00
|
|
|
public:
|
2001-11-26 13:35:08 +00:00
|
|
|
/// nestinsets have a fixed size to start with
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathNest(Buffer * buf, idx_type ncells);
|
2007-05-31 12:30:17 +00:00
|
|
|
///
|
2010-04-30 14:55:37 +00:00
|
|
|
virtual ~InsetMathNest();
|
2009-08-03 10:30:34 +00:00
|
|
|
///
|
|
|
|
void setBuffer(Buffer &);
|
2001-08-03 17:10:22 +00:00
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
/// the size is usually some sort of convex hull of the cells
|
2003-05-28 13:22:36 +00:00
|
|
|
/// hides inset::metrics() intentionally!
|
2003-03-21 14:20:48 +00:00
|
|
|
void metrics(MetricsInfo const & mi) const;
|
2002-06-14 10:48:27 +00:00
|
|
|
/// draw background if locked
|
2003-03-21 14:20:48 +00:00
|
|
|
void draw(PainterInfo & pi, int x, int y) const;
|
2002-07-26 17:23:44 +00:00
|
|
|
/// draw selection background
|
2004-02-02 17:32:56 +00:00
|
|
|
void drawSelection(PainterInfo & pi, int x, int y) const;
|
2007-01-20 00:55:24 +00:00
|
|
|
/// draw decorations.
|
|
|
|
void drawDecoration(PainterInfo & pi, int x, int y) const
|
|
|
|
{ drawMarkers(pi, x, y); }
|
2010-01-28 17:37:22 +00:00
|
|
|
///
|
2010-03-03 22:13:45 +00:00
|
|
|
void updateBuffer(ParIterator const &, UpdateType);
|
2001-10-12 12:02:49 +00:00
|
|
|
/// identifies NestInsets
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathNest * asNestInset() { return this; }
|
2002-08-08 16:08:11 +00:00
|
|
|
/// identifies NestInsets
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathNest const * asNestInset() const { return this; }
|
2002-07-16 18:22:45 +00:00
|
|
|
/// get cursor position
|
2006-10-17 16:23:27 +00:00
|
|
|
void cursorPos(BufferView const & bv, CursorSlice const & sl,
|
|
|
|
bool boundary, int & x, int & y) const;
|
2004-01-30 11:41:12 +00:00
|
|
|
///
|
2008-02-10 19:52:45 +00:00
|
|
|
void edit(Cursor & cur, bool front,
|
2008-02-11 08:20:13 +00:00
|
|
|
EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
|
2004-02-06 16:14:06 +00:00
|
|
|
///
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset * editXY(Cursor & cur, int x, int y);
|
2001-08-03 17:10:22 +00:00
|
|
|
|
2007-11-05 19:44:03 +00:00
|
|
|
/// order of movement through the cells when moving backwards
|
|
|
|
bool idxBackward(Cursor &) const;
|
|
|
|
/// order of movement through the cells when moving forward
|
|
|
|
bool idxForward(Cursor &) const;
|
2001-08-03 17:10:22 +00:00
|
|
|
|
2007-11-05 19:44:03 +00:00
|
|
|
/// move to next cell
|
2007-04-26 14:56:30 +00:00
|
|
|
bool idxNext(Cursor &) const;
|
2007-11-05 19:44:03 +00:00
|
|
|
/// move to previous cell
|
2007-04-26 14:56:30 +00:00
|
|
|
bool idxPrev(Cursor &) const;
|
2001-08-03 17:10:22 +00:00
|
|
|
|
2007-11-05 19:41:16 +00:00
|
|
|
/// target pos when we enter the inset while moving forward
|
2007-04-26 14:56:30 +00:00
|
|
|
bool idxFirst(Cursor &) const;
|
2007-11-05 19:41:16 +00:00
|
|
|
/// target pos when we enter the inset while moving backwards
|
2007-04-26 14:56:30 +00:00
|
|
|
bool idxLast(Cursor &) const;
|
2001-08-03 17:10:22 +00:00
|
|
|
|
2001-11-26 13:35:08 +00:00
|
|
|
/// number of cells currently governed by us
|
2001-09-26 16:52:34 +00:00
|
|
|
idx_type nargs() const;
|
2002-05-30 07:09:54 +00:00
|
|
|
/// access to the lock
|
|
|
|
bool lock() const;
|
|
|
|
/// access to the lock
|
|
|
|
void lock(bool);
|
2002-06-27 18:12:50 +00:00
|
|
|
/// get notification when the cursor leaves this inset
|
2008-02-22 20:45:18 +00:00
|
|
|
bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
|
2001-08-03 17:10:22 +00:00
|
|
|
|
2007-04-21 22:28:21 +00:00
|
|
|
//@{
|
2010-01-27 18:10:33 +00:00
|
|
|
/// direct access to the cell.
|
|
|
|
/// Inlined because of performance reasons.
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData & cell(idx_type i) { return cells_[i]; }
|
|
|
|
MathData const & cell(idx_type i) const { return cells_[i]; }
|
2007-04-21 22:28:21 +00:00
|
|
|
//@}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-11-26 13:35:08 +00:00
|
|
|
/// can we move into this cell (see macroarg.h)
|
2002-05-30 07:09:54 +00:00
|
|
|
bool isActive() const;
|
2001-11-26 13:35:08 +00:00
|
|
|
/// request "external features"
|
|
|
|
void validate(LaTeXFeatures & features) const;
|
|
|
|
|
|
|
|
/// replace in all cells
|
2001-11-16 09:55:37 +00:00
|
|
|
void replace(ReplaceData &);
|
2002-02-01 17:01:30 +00:00
|
|
|
/// do we contain a given pattern?
|
2007-04-26 16:05:57 +00:00
|
|
|
bool contains(MathData const &) const;
|
2002-06-18 15:44:30 +00:00
|
|
|
/// glue everything to a single cell
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData glue() const;
|
2001-08-03 17:10:22 +00:00
|
|
|
|
2001-11-26 13:35:08 +00:00
|
|
|
/// debug helper
|
|
|
|
void dump() const;
|
2001-08-03 17:10:22 +00:00
|
|
|
|
2002-08-01 15:53:46 +00:00
|
|
|
/// writes \\, name(), and args in braces and '\\lyxlock' if necessary
|
|
|
|
void write(WriteStream & os) const;
|
2002-12-01 22:59:25 +00:00
|
|
|
/// writes [, name(), and args in []
|
2002-08-01 15:53:46 +00:00
|
|
|
void normalize(NormalStream & os) const;
|
2004-04-07 18:15:29 +00:00
|
|
|
///
|
2008-02-27 20:43:16 +00:00
|
|
|
int latex(odocstream & os, OutputParams const & runparams) const;
|
2007-06-07 18:08:03 +00:00
|
|
|
///
|
2010-04-30 14:47:46 +00:00
|
|
|
bool setMouseHover(BufferView const * bv, bool mouse_hover);
|
2007-06-07 21:36:42 +00:00
|
|
|
///
|
2010-04-30 14:47:46 +00:00
|
|
|
bool mouseHovered(BufferView const * bv) const
|
|
|
|
{ return mouse_hover_[bv]; }
|
2007-05-31 12:30:17 +00:00
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
///
|
|
|
|
bool completionSupported(Cursor const &) const;
|
|
|
|
///
|
|
|
|
bool inlineCompletionSupported(Cursor const & cur) const;
|
|
|
|
///
|
|
|
|
bool automaticInlineCompletion() const;
|
|
|
|
///
|
|
|
|
bool automaticPopupCompletion() const;
|
|
|
|
///
|
2008-02-22 21:11:19 +00:00
|
|
|
CompletionList const * createCompletionList(Cursor const & cur) const;
|
2008-02-21 19:42:34 +00:00
|
|
|
///
|
|
|
|
docstring completionPrefix(Cursor const & cur) const;
|
|
|
|
///
|
|
|
|
bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
|
|
|
|
///
|
|
|
|
void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
|
2009-07-16 19:00:24 +00:00
|
|
|
///
|
|
|
|
InsetCode lyxCode() const { return MATH_NEST_CODE; }
|
2008-02-21 19:42:34 +00:00
|
|
|
|
2001-08-03 17:10:22 +00:00
|
|
|
protected:
|
2007-05-31 12:30:17 +00:00
|
|
|
///
|
|
|
|
InsetMathNest(InsetMathNest const & inset);
|
|
|
|
///
|
|
|
|
InsetMathNest & operator=(InsetMathNest const &);
|
|
|
|
|
2003-10-29 10:47:21 +00:00
|
|
|
///
|
2007-04-26 14:56:30 +00:00
|
|
|
virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
|
2004-03-18 13:57:20 +00:00
|
|
|
/// do we want to handle this event?
|
2007-04-26 14:56:30 +00:00
|
|
|
bool getStatus(Cursor & cur, FuncRequest const & cmd,
|
2004-03-18 13:57:20 +00:00
|
|
|
FuncStatus & status) const;
|
2004-01-30 11:41:12 +00:00
|
|
|
///
|
2007-04-26 14:56:30 +00:00
|
|
|
void handleFont(Cursor & cur,
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring const & arg, docstring const & font);
|
2007-04-26 14:56:30 +00:00
|
|
|
void handleFont(Cursor & cur,
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring const & arg, char const * const font);
|
2004-01-30 11:41:12 +00:00
|
|
|
///
|
2007-04-26 14:56:30 +00:00
|
|
|
void handleFont2(Cursor & cur, docstring const & arg);
|
2008-03-12 14:04:25 +00:00
|
|
|
/// Grab and erase selection and insert the InsetMathNest atom in every
|
|
|
|
/// previously selected cell, insert the grabbed former data and \c arg
|
|
|
|
/// in the first cell of the inserted atom.
|
2008-03-15 00:22:54 +00:00
|
|
|
void handleNest(Cursor & cur, MathAtom const & nest);
|
2008-03-18 10:58:35 +00:00
|
|
|
void handleNest(Cursor & cur, MathAtom const & nest, docstring const & arg);
|
2003-10-29 10:47:21 +00:00
|
|
|
|
2006-05-01 08:05:22 +00:00
|
|
|
/// interpret \p c and insert the result at the current position of
|
|
|
|
/// of \p cur. Return whether the cursor should stay in the formula.
|
2007-04-26 14:56:30 +00:00
|
|
|
bool interpretChar(Cursor & cur, char_type c);
|
2004-02-27 09:18:03 +00:00
|
|
|
///
|
2008-03-15 00:22:54 +00:00
|
|
|
bool script(Cursor & cur, bool);
|
|
|
|
bool script(Cursor & cur, bool, docstring const & save_selection);
|
2004-02-27 09:18:03 +00:00
|
|
|
|
2006-05-01 08:05:22 +00:00
|
|
|
public:
|
|
|
|
/// interpret \p str and insert the result at the current position of
|
|
|
|
/// \p cur if it is something known. Return whether \p cur was
|
|
|
|
/// inserted.
|
2007-04-26 14:56:30 +00:00
|
|
|
bool interpretString(Cursor & cur, docstring const & str);
|
2004-02-06 16:14:06 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// lfun handler
|
2007-04-26 14:56:30 +00:00
|
|
|
void lfunMousePress(Cursor &, FuncRequest &);
|
2004-02-06 16:14:06 +00:00
|
|
|
///
|
2007-04-26 14:56:30 +00:00
|
|
|
void lfunMouseRelease(Cursor &, FuncRequest &);
|
2004-02-06 16:14:06 +00:00
|
|
|
///
|
2007-04-26 14:56:30 +00:00
|
|
|
void lfunMouseMotion(Cursor &, FuncRequest &);
|
2007-11-01 11:14:14 +00:00
|
|
|
/// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
|
|
|
|
/// afterwards if found
|
|
|
|
bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
|
2008-02-10 19:57:00 +00:00
|
|
|
/// move cursor forward
|
|
|
|
bool cursorMathForward(Cursor & cur);
|
|
|
|
/// move cursor backwards
|
|
|
|
bool cursorMathBackward(Cursor & cur);
|
2004-02-06 16:14:06 +00:00
|
|
|
|
|
|
|
protected:
|
2001-11-26 13:35:08 +00:00
|
|
|
/// we store the cells in a vector
|
2007-04-26 16:05:57 +00:00
|
|
|
typedef std::vector<MathData> cells_type;
|
2001-11-26 13:35:08 +00:00
|
|
|
/// thusly:
|
2001-08-03 17:10:22 +00:00
|
|
|
cells_type cells_;
|
2002-06-14 10:48:27 +00:00
|
|
|
/// if the inset is locked, it can't be entered with the cursor
|
2002-05-30 07:09:54 +00:00
|
|
|
bool lock_;
|
2007-06-07 18:08:03 +00:00
|
|
|
///
|
2010-04-30 14:47:46 +00:00
|
|
|
mutable std::map<BufferView const *, bool> mouse_hover_;
|
|
|
|
};
|
2001-08-03 17:10:22 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|
2001-08-03 17:10:22 +00:00
|
|
|
#endif
|