2000-03-08 13:52:57 +00:00
|
|
|
// -*- C++ -*-
|
2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2017-10-16 08:12:21 +00:00
|
|
|
* \file InsetCollapsible.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
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
* \author Alejandro Aguilar Sierra
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Vigna
|
|
|
|
* \author Lars Gullik Bjønnes
|
2000-03-08 13:52:57 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2000-03-08 13:52:57 +00:00
|
|
|
*/
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
#ifndef INSETCOLLAPSIBLE_H
|
|
|
|
#define INSETCOLLAPSIBLE_H
|
2000-03-08 13:52:57 +00:00
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetText.h"
|
2003-09-07 01:45:40 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Box.h"
|
2010-10-31 01:04:03 +00:00
|
|
|
|
2020-12-02 20:34:28 +00:00
|
|
|
#include "support/unique_ptr.h"
|
|
|
|
|
2010-10-31 01:04:03 +00:00
|
|
|
#include <map>
|
2000-03-08 13:52:57 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2004-01-13 14:13:51 +00:00
|
|
|
class CursorSlice;
|
2007-08-13 12:13:17 +00:00
|
|
|
class InsetLayout;
|
2000-03-08 13:52:57 +00:00
|
|
|
|
2020-12-02 20:34:28 +00:00
|
|
|
enum class InsetDecoration : int;
|
|
|
|
|
2018-10-04 17:36:01 +00:00
|
|
|
namespace support { class TempFile; }
|
|
|
|
|
2017-10-16 08:12:21 +00:00
|
|
|
/** A collapsible text inset
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2000-03-08 13:52:57 +00:00
|
|
|
*/
|
2017-10-16 08:12:21 +00:00
|
|
|
class InsetCollapsible : public InsetText {
|
2000-03-08 13:52:57 +00:00
|
|
|
public:
|
2009-04-04 19:34:14 +00:00
|
|
|
///
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible(Buffer *, InsetText::UsePlain = InsetText::PlainLayout);
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible(InsetCollapsible const & rhs);
|
2008-02-22 02:32:52 +00:00
|
|
|
///
|
2019-09-15 22:43:35 +00:00
|
|
|
InsetCollapsible & operator=(InsetCollapsible const &);
|
2018-10-04 17:36:01 +00:00
|
|
|
///
|
2017-10-16 08:12:21 +00:00
|
|
|
virtual ~InsetCollapsible();
|
2010-04-30 14:55:37 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
InsetCollapsible * asInsetCollapsible() override { return this; }
|
2008-02-22 02:32:52 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
InsetCollapsible const * asInsetCollapsible() const override { return this; }
|
2008-02-22 02:32:52 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
docstring toolTip(BufferView const & bv, int x, int y) const override;
|
2008-02-22 02:32:52 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
docstring layoutName() const override { return from_ascii("Collapsible"); }
|
2007-08-13 12:13:17 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void read(Lexer &) override;
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void write(std::ostream &) const override;
|
2020-01-15 10:12:47 +00:00
|
|
|
|
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
int topOffset(BufferView const * bv) const override;
|
2020-01-15 10:12:47 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
int bottomOffset(BufferView const * bv) const override;
|
2020-01-15 10:12:47 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void metrics(MetricsInfo &, Dimension &) const override;
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void draw(PainterInfo & pi, int x, int y) const override;
|
2017-06-08 14:47:26 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void drawBackground(PainterInfo &, int, int) const override {}
|
2007-09-17 21:48:25 +00:00
|
|
|
|
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,
|
2020-10-01 07:42:11 +00:00
|
|
|
bool boundary, int & x, int & y) const override;
|
2003-07-30 14:43:14 +00:00
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
docstring const getNewLabel(docstring const & l) const;
|
2003-12-01 14:51:52 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
bool editable() const override;
|
2009-04-22 20:55:13 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
bool hasSettings() const override { return true; }
|
2016-02-03 09:37:29 +00:00
|
|
|
/// Returns true if coordinates are over the inset's button.
|
|
|
|
/// Always returns false when the inset does not have a
|
|
|
|
/// button.
|
2020-10-01 07:42:11 +00:00
|
|
|
bool clickable(BufferView const & bv, int x, int y) const override;
|
2003-11-10 11:26:33 +00:00
|
|
|
/// can we go further down on mouse click?
|
2020-10-01 07:42:11 +00:00
|
|
|
bool descendable(BufferView const & bv) const override;
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
void setLabel(docstring const & l);
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2015-11-22 22:48:24 +00:00
|
|
|
docstring getLabel() const;
|
|
|
|
///
|
2004-02-13 11:05:29 +00:00
|
|
|
virtual void setButtonLabel() {}
|
2004-04-03 08:37:12 +00:00
|
|
|
///
|
2009-07-14 16:01:07 +00:00
|
|
|
virtual docstring const buttonLabel(BufferView const &) const;
|
2009-02-25 22:35:41 +00:00
|
|
|
///
|
2016-02-03 09:42:01 +00:00
|
|
|
bool isOpen(BufferView const & bv) const
|
2009-02-21 16:27:00 +00:00
|
|
|
{ return geometry(bv) != ButtonOnly; }
|
2003-12-02 07:15:42 +00:00
|
|
|
///
|
2009-11-02 05:03:09 +00:00
|
|
|
enum CollapseStatus {
|
|
|
|
Collapsed,
|
|
|
|
Open
|
|
|
|
};
|
|
|
|
///
|
|
|
|
virtual void setStatus(Cursor & cur, CollapseStatus st);
|
|
|
|
///
|
2009-02-21 16:27:00 +00:00
|
|
|
CollapseStatus status(BufferView const & bv) const;
|
2016-02-03 09:42:01 +00:00
|
|
|
/** Of the old CollapseStatus we only keep the values
|
2007-08-16 16:36:50 +00:00
|
|
|
* Open and Collapsed.
|
|
|
|
* We define a list of possible inset decoration
|
|
|
|
* styles, and a list of possible (concrete, visual)
|
|
|
|
* inset geometries. Relationships between them
|
|
|
|
* (geometries in body of table):
|
|
|
|
*
|
|
|
|
* \ CollapseStatus:
|
|
|
|
* Decoration: \ Open Collapsed
|
|
|
|
* -------------+-------------------------------
|
|
|
|
* Classic | *) TopButton, <--x) ButtonOnly
|
|
|
|
* | LeftButton
|
2008-02-05 23:29:15 +00:00
|
|
|
* Minimalistic | NoButton ButtonOnly
|
2007-08-16 16:36:50 +00:00
|
|
|
* Conglomerate | SubLabel Corners
|
|
|
|
* ---------------------------------------------
|
|
|
|
* *) toggled by openinlined_
|
2009-02-27 00:04:28 +00:00
|
|
|
* x) toggled by auto_open_
|
2007-08-16 16:36:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/// Default looks
|
2020-12-02 20:34:28 +00:00
|
|
|
virtual InsetDecoration decoration() const;
|
2007-08-16 16:36:50 +00:00
|
|
|
///
|
|
|
|
enum Geometry {
|
|
|
|
TopButton,
|
|
|
|
ButtonOnly,
|
|
|
|
NoButton,
|
|
|
|
LeftButton,
|
|
|
|
SubLabel,
|
|
|
|
Corners
|
|
|
|
};
|
|
|
|
/// Returns the geometry based on CollapseStatus
|
2009-02-27 00:04:28 +00:00
|
|
|
/// (status_), auto_open_[BufferView] and openinlined_,
|
|
|
|
/// and of course decoration().
|
2009-02-21 16:27:00 +00:00
|
|
|
Geometry geometry(BufferView const & bv) const;
|
2005-04-22 08:57:22 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
bool canPaintChange(BufferView const & bv) const override;
|
2016-05-22 21:48:28 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const override;
|
2003-10-17 18:01:15 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
bool setMouseHover(BufferView const * bv, bool mouse_hover) const override;
|
2007-08-20 19:02:38 +00:00
|
|
|
///
|
2020-12-02 20:34:28 +00:00
|
|
|
ColorCode backgroundColor(PainterInfo const &) const override;
|
2008-02-22 02:32:52 +00:00
|
|
|
///
|
2020-12-02 20:34:28 +00:00
|
|
|
ColorCode labelColor() const override;
|
2009-06-05 18:57:53 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
InsetCode lyxCode() const override { return COLLAPSIBLE_CODE; }
|
2005-07-14 17:30:24 +00:00
|
|
|
|
Fix bug 4037 and related problems. The patch has been cleaned up a bit
from the one posted to the list.
The basic idea has two parts. First, we hard code an "empty layout"
(called PlainLayout, for want of a better name) in TextClass and read it
before doing anything else. It can therefore be customized by classes,
if they want---say, to make it left-aligned. Second, InsetText's are
divided into three types: (i) normal ones, that use the "default" layout
defined by the text class; (ii) highly restrictive ones, such as ERT and
(not quite an inset) table cells, which demand the empty layout; (iii)
middling ones, which default to an empty layout and use the empty layout
in place of the default. (This is so we don't get the same problem we
had with ERT in e.g. footnotes.) The type of inset is signaled by new
methods InsetText::forceEmptyLayout() and InsetText::useEmptyLayout().
(The latter might better be called: useEmptyLayoutInsteadOfDefault(),
but that's silly.) The old InsetText::forceDefaultParagraphs() has been
split into these, plus a new method InsetText::allowParagraphCustomization().
A lot of the changes just adapt to this change.
The other big change is in GuiToolbar: We want to show LyXDefault and
the "default" layout only when they're active.
There are a handful of places where I'm not entirely sure whether we
should be using forceEmptyLayout or !allowParagraphCustomization() or
both. The InsetCaption is one of these. These places, and some others,
are marked with FIXMEs, so I'd appreciate it if people would search
through the patch and let me know whether these need changing. If they
don't, the FIXMEs can be deleted.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22966 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-12 17:31:07 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
bool usePlainLayout() const override { return true; }
|
2008-03-08 22:57:22 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
std::string contextMenu(BufferView const & bv, int x, int y) const override;
|
2010-11-29 21:27:25 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
std::string contextMenuName() const override;
|
2017-01-09 12:28:48 +00:00
|
|
|
///
|
|
|
|
void addToToc(DocIterator const & dit, bool output_active,
|
2020-10-01 07:42:11 +00:00
|
|
|
UpdateType utype, TocBackend & backend) const override;
|
2017-01-09 12:28:48 +00:00
|
|
|
|
2005-07-14 17:30:24 +00:00
|
|
|
protected:
|
2001-04-02 14:02:58 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void doDispatch(Cursor & cur, FuncRequest & cmd) override;
|
2004-03-18 13:57:20 +00:00
|
|
|
///
|
2016-02-03 09:42:01 +00:00
|
|
|
void edit(Cursor & cur, bool front,
|
2020-10-01 07:42:11 +00:00
|
|
|
EntryDirection entry_from = ENTRY_DIRECTION_IGNORE) override;
|
2003-11-04 12:36:59 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
Inset * editXY(Cursor & cur, int x, int y) override;
|
2005-05-06 20:00:31 +00:00
|
|
|
///
|
2008-10-26 02:25:57 +00:00
|
|
|
mutable CollapseStatus status_;
|
2018-10-04 21:56:14 +00:00
|
|
|
///
|
|
|
|
unique_ptr<support::TempFile> tempfile_;
|
2004-01-30 11:41:12 +00:00
|
|
|
private:
|
2007-11-07 21:57:19 +00:00
|
|
|
///
|
2009-02-25 22:35:41 +00:00
|
|
|
Dimension dimensionCollapsed(BufferView const & bv) const;
|
2007-11-03 00:35:07 +00:00
|
|
|
///
|
|
|
|
docstring labelstring_;
|
2016-02-03 09:37:29 +00:00
|
|
|
|
2016-04-19 13:45:08 +00:00
|
|
|
// These variables depend of the view in which the inset is displayed
|
|
|
|
struct View
|
|
|
|
{
|
|
|
|
/// The dimension of the inset button
|
|
|
|
Box button_dim_;
|
|
|
|
/// a substatus of the Open status, determined automatically in metrics
|
|
|
|
bool openinlined_;
|
|
|
|
/// the inset will automatically open when the cursor is inside. This is
|
2017-07-05 12:31:28 +00:00
|
|
|
/// dependent on the bufferview, compare with InsetMathMacro::editing_.
|
2016-04-19 13:45:08 +00:00
|
|
|
bool auto_open_;
|
|
|
|
/// changes color when mouse enters/leaves this inset
|
|
|
|
bool mouse_hover_;
|
|
|
|
};
|
2016-02-03 09:37:29 +00:00
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
///
|
2016-04-19 13:45:08 +00:00
|
|
|
mutable std::map<BufferView const *, View> view_;
|
2000-03-08 13:52:57 +00:00
|
|
|
};
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|
|
|
|
|
2000-03-08 13:52:57 +00:00
|
|
|
#endif
|