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 {
|
|
|
|
|
2000-03-08 13:52:57 +00:00
|
|
|
class Buffer;
|
2002-03-03 20:25:07 +00:00
|
|
|
class BufferParams;
|
2003-09-07 01:45:40 +00:00
|
|
|
class BufferView;
|
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;
|
2007-08-30 18:03:17 +00:00
|
|
|
class InsetTabular;
|
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.
|
|
|
|
explicit InsetText(Buffer const & 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
|
|
|
///
|
|
|
|
Dimension const dimension(BufferView const &) const;
|
|
|
|
|
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;
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring editMessage() 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; }
|
|
|
|
///
|
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_; }
|
|
|
|
///
|
2008-02-27 20:43:16 +00:00
|
|
|
int latex(odocstream &, OutputParams const &) const;
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2008-02-27 20:43:16 +00:00
|
|
|
int plaintext(odocstream &, OutputParams const &) 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
|
|
|
///
|
2001-06-28 10:25:20 +00:00
|
|
|
void validate(LaTeXFeatures & features) 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
|
|
|
///
|
2001-06-28 10:25:20 +00:00
|
|
|
void setAutoBreakRows(bool);
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2004-12-17 16:27:12 +00:00
|
|
|
bool getAutoBreakRows() const { return text_.autoBreakRows_; }
|
2001-07-31 09:53:40 +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
|
|
|
///
|
2001-06-28 10:25:20 +00:00
|
|
|
bool showInsetDialog(BufferView *) const;
|
2001-04-04 23:00:42 +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
|
|
|
|
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
|
2007-01-23 21:53:16 +00:00
|
|
|
void acceptChanges(BufferParams const & bparams);
|
2006-10-24 21:38:47 +00:00
|
|
|
/// reject the changes within the inset
|
2007-01-23 21:53:16 +00:00
|
|
|
void rejectChanges(BufferParams const & bparams);
|
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
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
void addPreview(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
|
|
|
///
|
2007-10-13 09:04:52 +00:00
|
|
|
bool insetAllowed(InsetCode) const { return true; }
|
2004-03-31 17:58:11 +00:00
|
|
|
///
|
|
|
|
bool allowSpellCheck() const { return true; }
|
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
|
|
|
///
|
2007-10-11 10:13:45 +00:00
|
|
|
virtual bool allowMultiPar() const { return true; }
|
2007-08-27 14:38:29 +00:00
|
|
|
|
2007-08-12 21:43:58 +00:00
|
|
|
// Update the counters of this inset and of its contents
|
2008-02-27 20:43:16 +00:00
|
|
|
void updateLabels(ParIterator const &);
|
2008-06-03 11:12:45 +00:00
|
|
|
///
|
|
|
|
void addToToc(DocIterator 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;
|
2008-03-14 16:35:44 +00:00
|
|
|
|
2008-03-08 22:57:22 +00:00
|
|
|
///
|
|
|
|
virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
|
2003-10-17 18:01:15 +00:00
|
|
|
///
|
2008-03-05 00:21:05 +00:00
|
|
|
void doDispatch(Cursor & cur, FuncRequest & cmd);
|
2005-07-15 22:19:49 +00:00
|
|
|
private:
|
2008-07-29 12:07:08 +00:00
|
|
|
///
|
2009-04-04 19:34:14 +00:00
|
|
|
void initParagraphs(UsePlain type);
|
2003-10-08 14:29:16 +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
|
|
|
void setParagraphOwner();
|
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
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
mutable pit_type old_pit;
|
2003-07-10 08:00:41 +00:00
|
|
|
///
|
2007-04-29 23:33:02 +00:00
|
|
|
mutable Text text_;
|
2000-02-25 12:06:15 +00:00
|
|
|
};
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
#endif
|