2000-02-25 12:06:15 +00:00
|
|
|
// -*- C++ -*-
|
2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetText.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.
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Vigna
|
2000-02-25 12:06:15 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2000-02-25 12:06:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INSETTEXT_H
|
|
|
|
#define INSETTEXT_H
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
#include "Inset.h"
|
2007-10-29 10:46:13 +00:00
|
|
|
|
|
|
|
#include "ColorCode.h"
|
2007-04-29 23:33:02 +00:00
|
|
|
#include "Text.h"
|
2002-08-12 00:15:19 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2008-03-15 12:22:28 +00:00
|
|
|
class CompletionList;
|
2005-07-15 22:10:25 +00:00
|
|
|
class CursorSlice;
|
2003-09-07 01:45:40 +00:00
|
|
|
class Dimension;
|
2007-04-26 08:30:11 +00:00
|
|
|
class ParagraphList;
|
2009-06-19 13:50:19 +00:00
|
|
|
class InsetCaption;
|
2007-08-30 18:03:17 +00:00
|
|
|
class InsetTabular;
|
2017-01-13 10:06:48 +00:00
|
|
|
class TocBuilder;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
/**
|
2000-09-14 17:53:12 +00:00
|
|
|
A text inset is like a TeX box to write full text
|
2002-03-21 17:09:55 +00:00
|
|
|
(including styles and other insets) in a given space.
|
2000-06-12 11:27:15 +00:00
|
|
|
*/
|
2007-04-29 13:39:47 +00:00
|
|
|
class InsetText : public Inset {
|
2000-02-25 12:06:15 +00:00
|
|
|
public:
|
2009-04-04 19:34:14 +00:00
|
|
|
enum UsePlain {
|
|
|
|
DefaultLayout,
|
|
|
|
PlainLayout
|
|
|
|
};
|
|
|
|
/// \param buffer
|
|
|
|
/// \param useplain whether to use the plain layout
|
|
|
|
/// This is needed because we cannot call the virtual function
|
|
|
|
/// usePlainLayout() from within the constructor.
|
2009-11-08 15:53:21 +00:00
|
|
|
explicit InsetText(Buffer * buffer, UsePlain type = DefaultLayout);
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
It used to be that things like InsetFlex, InsetCaption, and the like used the default layout, whatever that is---usually Standard. That gave rise to bug 2178, the solution to which is to define a new empty layout, which insets like these use instead of the default. See r22966.
So, when we have an older LyX file, it will look like this:
\begin_inset ERT
status open
\begin_layout Standard
this that
\end_layout
\end_inset
which is now invalid, because ERT uses only PlainLayout. So I had put some code into Text::readParToken, where the layout for a paragraph gets set as it is read:
if (par.forceEmptyLayout()) {
// in this case only the empty layout is allowed
layoutname = tclass.emptyLayoutName();
} else if (par.useEmptyLayout()) {
// in this case, default layout maps to empty layout
if (layoutname == tclass.defaultLayoutName())
layoutname = tclass.emptyLayoutName();
} else {
// otherwise, the empty layout maps to the default
if (layoutname == tclass.emptyLayoutName())
layoutname = tclass.defaultLayoutName();
}
This turns out not to work, because par.forceEmptyLayout() and par.useEmptyLayout() always return false here, because par.inInset() always returns a null pointer, because the paragraph's inset hasn't yet been set when Text::readParagraph() gets called from Text::read() gets called from InsetText::read(). The solution is to set the paragraph's inset when it is created, which means passing a pointer to the various read() routines along the way.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23057 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-19 02:35:07 +00:00
|
|
|
InsetText(InsetText const &);
|
2008-03-04 22:28:18 +00:00
|
|
|
///
|
2008-07-23 12:55:24 +00:00
|
|
|
void setBuffer(Buffer &);
|
2007-01-30 13:23:21 +00:00
|
|
|
|
2007-09-17 21:45:14 +00:00
|
|
|
///
|
2016-12-06 08:48:49 +00:00
|
|
|
Dimension const dimensionHelper(BufferView const &) const;
|
2007-09-17 21:45:14 +00:00
|
|
|
|
2005-09-07 10:37:05 +00:00
|
|
|
/// empty inset to empty par
|
|
|
|
void clear();
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2008-02-27 20:43:16 +00:00
|
|
|
void read(Lexer & lex);
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2008-02-27 20:43:16 +00:00
|
|
|
void write(std::ostream & os) const;
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2007-09-21 20:39:47 +00:00
|
|
|
void metrics(MetricsInfo & mi, Dimension & dim) const;
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2003-05-30 06:48:24 +00:00
|
|
|
void draw(PainterInfo & pi, int x, int y) const;
|
2017-06-08 14:47:26 +00:00
|
|
|
/// Drawing background is handled in draw
|
|
|
|
virtual void drawBackground(PainterInfo &, int, int) const {}
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2009-04-22 20:55:13 +00:00
|
|
|
bool editable() const { return true; }
|
2005-07-15 22:10:25 +00:00
|
|
|
///
|
2006-03-17 19:45:28 +00:00
|
|
|
bool canTrackChanges() const { return true; }
|
2016-05-23 09:01:29 +00:00
|
|
|
/// Rely on RowPainter to draw the cue of inline insets.
|
|
|
|
bool canPaintChange(BufferView const &) const { return allowMultiPar(); }
|
2016-05-22 21:48:28 +00:00
|
|
|
///
|
2007-11-03 18:07:41 +00:00
|
|
|
InsetText * asInsetText() { return this; }
|
2007-05-29 20:53:32 +00:00
|
|
|
///
|
2007-11-03 18:07:41 +00:00
|
|
|
InsetText const * asInsetText() const { return this; }
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2008-07-29 12:07:08 +00:00
|
|
|
Text & text() { return text_; }
|
|
|
|
Text const & text() const { return text_; }
|
|
|
|
///
|
2011-02-10 20:02:48 +00:00
|
|
|
void latex(otexstream &, OutputParams const &) const;
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2013-03-08 19:52:18 +00:00
|
|
|
int plaintext(odocstringstream & ods, OutputParams const & op,
|
|
|
|
size_t max_length = INT_MAX) const;
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2008-02-27 20:43:16 +00:00
|
|
|
int docbook(odocstream &, OutputParams const &) const;
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2009-11-19 21:05:34 +00:00
|
|
|
docstring xhtml(XHTMLStream &, OutputParams const &) const;
|
2009-11-21 22:56:42 +00:00
|
|
|
///
|
|
|
|
enum XHTMLOptions {
|
|
|
|
JustText = 0,
|
|
|
|
WriteOuterTag = 1,
|
|
|
|
WriteLabel = 2,
|
|
|
|
WriteInnerTag = 4,
|
|
|
|
WriteEverything = 7
|
|
|
|
};
|
|
|
|
///
|
|
|
|
docstring insetAsXHTML(XHTMLStream &, OutputParams const &,
|
|
|
|
XHTMLOptions) const;
|
2009-06-05 17:48:14 +00:00
|
|
|
///
|
2001-06-28 10:25:20 +00:00
|
|
|
void validate(LaTeXFeatures & features) const;
|
2012-11-24 14:46:20 +00:00
|
|
|
|
2012-12-28 10:21:24 +00:00
|
|
|
/// return the argument(s) only
|
|
|
|
void getArgs(otexstream & os, OutputParams const &, bool const post = false) const;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
/// return x,y of given position relative to the inset's baseline
|
2006-10-17 16:23:27 +00:00
|
|
|
void cursorPos(BufferView const & bv, CursorSlice const & sl,
|
|
|
|
bool boundary, int & x, int & y) const;
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2007-10-13 09:04:52 +00:00
|
|
|
InsetCode lyxCode() const { return TEXT_CODE; }
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2007-04-29 18:17:15 +00:00
|
|
|
void setText(docstring const &, Font const &, bool trackChanges);
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2004-08-14 15:55:22 +00:00
|
|
|
void setDrawFrame(bool);
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2007-10-25 12:41:02 +00:00
|
|
|
ColorCode frameColor() const;
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2007-10-25 12:41:02 +00:00
|
|
|
void setFrameColor(ColorCode);
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2007-04-29 23:33:02 +00:00
|
|
|
Text * getText(int i) const {
|
|
|
|
return (i == 0) ? const_cast<Text*>(&text_) : 0;
|
2005-07-18 12:57:08 +00:00
|
|
|
}
|
2004-03-18 13:57:20 +00:00
|
|
|
///
|
2007-04-26 14:56:30 +00:00
|
|
|
virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
|
2003-03-02 23:44:58 +00:00
|
|
|
|
2009-07-14 13:00:42 +00:00
|
|
|
///
|
|
|
|
void fixParagraphsFont();
|
|
|
|
|
2006-10-20 09:29:19 +00:00
|
|
|
/// set the change for the entire inset
|
|
|
|
void setChange(Change const & change);
|
2006-10-24 06:11:45 +00:00
|
|
|
/// accept the changes within the inset
|
2009-07-16 08:37:32 +00:00
|
|
|
void acceptChanges();
|
2006-10-24 21:38:47 +00:00
|
|
|
/// reject the changes within the inset
|
2009-07-16 08:37:32 +00:00
|
|
|
void rejectChanges();
|
2003-03-02 23:44:58 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
/// append text onto the existing text
|
2008-02-27 20:43:16 +00:00
|
|
|
void appendParagraphs(ParagraphList &);
|
2003-03-02 23:44:58 +00:00
|
|
|
|
2002-03-21 15:58:54 +00:00
|
|
|
///
|
2009-11-22 20:50:35 +00:00
|
|
|
void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
|
2002-08-02 16:39:43 +00:00
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
///
|
2008-02-11 08:20:13 +00:00
|
|
|
void edit(Cursor & cur, bool front, EntryDirection entry_from);
|
2003-11-04 12:36:59 +00:00
|
|
|
///
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset * editXY(Cursor & cur, int x, int y);
|
2003-11-04 12:36:59 +00:00
|
|
|
|
2004-02-16 11:58:51 +00:00
|
|
|
/// number of cells in this inset
|
|
|
|
size_t nargs() const { return 1; }
|
2003-03-02 23:44:58 +00:00
|
|
|
///
|
2004-03-28 22:00:22 +00:00
|
|
|
ParagraphList & paragraphs();
|
|
|
|
///
|
|
|
|
ParagraphList const & paragraphs() const;
|
2004-03-28 19:13:11 +00:00
|
|
|
///
|
2012-11-25 17:13:57 +00:00
|
|
|
bool insetAllowed(InsetCode) const;
|
2010-02-13 15:44:17 +00:00
|
|
|
///
|
|
|
|
bool allowSpellCheck() const { return getLayout().spellcheck() && !getLayout().isPassThru(); }
|
2008-03-11 15:16:58 +00:00
|
|
|
///
|
2008-03-10 12:49:02 +00:00
|
|
|
virtual bool isMacroScope() const { return false; }
|
2007-12-21 20:42:46 +00:00
|
|
|
///
|
2009-07-13 15:47:40 +00:00
|
|
|
virtual bool allowMultiPar() const { return getLayout().isMultiPar(); }
|
2009-07-14 21:14:39 +00:00
|
|
|
///
|
|
|
|
/// should paragraphs be forced to use the empty layout?
|
2015-04-04 09:59:01 +00:00
|
|
|
virtual bool forcePlainLayout(idx_type = 0) const
|
2009-07-14 21:14:39 +00:00
|
|
|
{ return getLayout().forcePlainLayout(); }
|
|
|
|
/// should the user be allowed to customize alignment, etc.?
|
2015-04-04 09:59:01 +00:00
|
|
|
virtual bool allowParagraphCustomization(idx_type = 0) const
|
2009-07-14 21:14:39 +00:00
|
|
|
{ return getLayout().allowParagraphCustomization(); }
|
2015-04-04 09:59:01 +00:00
|
|
|
/// should paragraphs be forced to use a local font language switch?
|
|
|
|
virtual bool forceLocalFontSwitch() const
|
|
|
|
{ return getLayout().forcelocalfontswitch(); }
|
2007-08-27 14:38:29 +00:00
|
|
|
|
2009-06-06 03:02:43 +00:00
|
|
|
/// Update the counters of this inset and of its contents
|
2010-03-03 22:13:45 +00:00
|
|
|
virtual void updateBuffer(ParIterator const &, UpdateType);
|
2010-12-15 01:34:04 +00:00
|
|
|
///
|
2011-04-25 12:56:09 +00:00
|
|
|
void setMacrocontextPositionRecursive(DocIterator const & pos);
|
|
|
|
///
|
2010-12-15 01:34:04 +00:00
|
|
|
void toString(odocstream &) const;
|
2008-06-03 11:12:45 +00:00
|
|
|
///
|
2015-10-04 18:38:47 +00:00
|
|
|
void forOutliner(docstring &, size_t const, bool const) const;
|
2010-12-20 21:55:09 +00:00
|
|
|
///
|
2015-09-27 06:05:00 +00:00
|
|
|
void addToToc(DocIterator const & di, bool output_active,
|
2017-01-13 10:06:48 +00:00
|
|
|
UpdateType utype, TocBackend & backend) const;
|
2007-08-30 18:03:17 +00:00
|
|
|
///
|
2008-03-05 00:21:05 +00:00
|
|
|
Inset * clone() const { return new InsetText(*this); }
|
2008-02-26 19:20:12 +00:00
|
|
|
///
|
2008-03-05 00:21:05 +00:00
|
|
|
bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
|
2006-03-17 19:45:28 +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-03-16 17:07:10 +00:00
|
|
|
bool showCompletionCursor() 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;
|
2010-04-26 00:43:08 +00:00
|
|
|
/// returns the text to be used as tooltip
|
2010-11-17 16:55:58 +00:00
|
|
|
/// \param prefix: a string that will preced the tooltip,
|
|
|
|
/// e.g., "Index: ".
|
2016-06-11 11:57:18 +00:00
|
|
|
/// \param len: length of the resulting string
|
2015-11-26 20:21:21 +00:00
|
|
|
/// NOTE This routine is kind of slow. It's fine to use it within the
|
|
|
|
/// GUI, but definitely do not try to use it in updateBuffer or anything
|
2016-06-11 11:57:18 +00:00
|
|
|
/// of that sort. (Note: unnecessary internal copies have been removed
|
|
|
|
/// since the previous note. The efficiency would have to be assessed
|
|
|
|
/// again by profiling.)
|
2010-12-22 01:29:17 +00:00
|
|
|
docstring toolTipText(docstring prefix = empty_docstring(),
|
2016-06-11 11:57:18 +00:00
|
|
|
size_t len = 400) const;
|
2008-03-14 16:35:44 +00:00
|
|
|
|
2010-11-29 23:21:52 +00:00
|
|
|
///
|
2011-10-29 14:48:55 +00:00
|
|
|
std::string contextMenu(BufferView const &, int, int) const;
|
2008-03-08 22:57:22 +00:00
|
|
|
///
|
2011-10-29 14:48:55 +00:00
|
|
|
std::string contextMenuName() const;
|
2003-10-17 18:01:15 +00:00
|
|
|
///
|
2008-03-05 00:21:05 +00:00
|
|
|
void doDispatch(Cursor & cur, FuncRequest & cmd);
|
2017-02-18 18:12:55 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
bool confirmDeletion() const { return !text().empty(); }
|
|
|
|
|
2009-06-19 13:50:19 +00:00
|
|
|
protected:
|
2014-02-24 19:36:13 +00:00
|
|
|
///
|
2015-09-27 06:05:00 +00:00
|
|
|
void iterateForToc(DocIterator const & cdit, bool output_active,
|
2017-01-13 10:06:48 +00:00
|
|
|
UpdateType utype, TocBackend & backend) const;
|
2005-07-15 22:19:49 +00:00
|
|
|
private:
|
2017-01-08 20:57:02 +00:00
|
|
|
/// Open the toc item for paragraph pit. Returns the paragraph index where
|
|
|
|
/// it should end.
|
|
|
|
pit_type openAddToTocForParagraph(pit_type pit,
|
|
|
|
DocIterator const & dit,
|
2017-01-13 10:06:48 +00:00
|
|
|
bool output_active,
|
|
|
|
TocBackend & backend) const;
|
2017-01-08 20:57:02 +00:00
|
|
|
/// Close a toc item opened in start and closed in end
|
2017-01-13 10:06:48 +00:00
|
|
|
void closeAddToTocForParagraph(pit_type start, pit_type end,
|
|
|
|
TocBackend & backend) const;
|
2003-09-16 10:01:29 +00:00
|
|
|
///
|
2004-08-14 15:55:22 +00:00
|
|
|
bool drawFrame_;
|
2007-10-29 10:46:13 +00:00
|
|
|
///
|
|
|
|
ColorCode frame_color_;
|
2003-09-16 10:01:29 +00:00
|
|
|
///
|
2016-07-18 12:34:08 +00:00
|
|
|
Text text_;
|
2000-02-25 12:06:15 +00:00
|
|
|
};
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2009-11-26 16:38:26 +00:00
|
|
|
|
|
|
|
InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2);
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
#endif
|