mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-09-20 15:01:58 +00:00
split inset -> inset + updatableinset
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6212 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b99a5acc7f
commit
5246fc5583
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#include "insets/insetcommand.h" // ChangeRefs
|
#include "insets/insetcommand.h" // ChangeRefs
|
||||||
#include "insets/inseterror.h"
|
#include "insets/inseterror.h"
|
||||||
|
#include "insets/updatableinset.h"
|
||||||
|
|
||||||
#include "support/FileInfo.h"
|
#include "support/FileInfo.h"
|
||||||
#include "support/filetools.h"
|
#include "support/filetools.h"
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include "InsetList.h"
|
#include "InsetList.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#include "insets/inset.h"
|
#include "insets/updatableinset.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -19,7 +19,8 @@ struct MatchIt {
|
|||||||
/// used by lower_bound and upper_bound
|
/// used by lower_bound and upper_bound
|
||||||
inline
|
inline
|
||||||
int operator()(InsetList::InsetTable const & a,
|
int operator()(InsetList::InsetTable const & a,
|
||||||
InsetList::InsetTable const & b) const {
|
InsetList::InsetTable const & b) const
|
||||||
|
{
|
||||||
return a.pos < b.pos;
|
return a.pos < b.pos;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "bufferview_funcs.h"
|
#include "bufferview_funcs.h"
|
||||||
#include "frontends/LyXView.h"
|
|
||||||
#include "BufferView.h"
|
#include "BufferView.h"
|
||||||
#include "paragraph.h"
|
#include "paragraph.h"
|
||||||
#include "lyxfont.h"
|
#include "lyxfont.h"
|
||||||
@ -24,10 +23,13 @@
|
|||||||
#include "author.h"
|
#include "author.h"
|
||||||
#include "changes.h"
|
#include "changes.h"
|
||||||
|
|
||||||
|
#include "frontends/LyXView.h"
|
||||||
#include "frontends/Alert.h"
|
#include "frontends/Alert.h"
|
||||||
|
|
||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
|
|
||||||
|
#include "insets/updatableinset.h"
|
||||||
|
|
||||||
#include "BoostFormat.h"
|
#include "BoostFormat.h"
|
||||||
|
|
||||||
void emph(BufferView * bv)
|
void emph(BufferView * bv)
|
||||||
@ -143,11 +145,11 @@ void fontSize(BufferView * bv, string const & size)
|
|||||||
// Returns the current font and depth as a message.
|
// Returns the current font and depth as a message.
|
||||||
string const currentState(BufferView * bv)
|
string const currentState(BufferView * bv)
|
||||||
{
|
{
|
||||||
ostringstream state;
|
|
||||||
|
|
||||||
if (!bv->available())
|
if (!bv->available())
|
||||||
return string();
|
return string();
|
||||||
|
|
||||||
|
ostringstream state;
|
||||||
|
|
||||||
LyXText * text = bv->getLyXText();
|
LyXText * text = bv->getLyXText();
|
||||||
Buffer * buffer = bv->buffer();
|
Buffer * buffer = bv->buffer();
|
||||||
LyXCursor const & c(text->cursor);
|
LyXCursor const & c(text->cursor);
|
||||||
|
@ -84,7 +84,9 @@ libinsets_la_SOURCES = \
|
|||||||
insettoc.C \
|
insettoc.C \
|
||||||
insettoc.h \
|
insettoc.h \
|
||||||
inseturl.C \
|
inseturl.C \
|
||||||
inseturl.h
|
inseturl.h \
|
||||||
|
updatableinset.C \
|
||||||
|
updatableinset.h
|
||||||
# insetlist.C \
|
# insetlist.C \
|
||||||
# insetlist.h \
|
# insetlist.h \
|
||||||
# insetsection.h \
|
# insetsection.h \
|
||||||
|
@ -17,18 +17,14 @@
|
|||||||
#include "inset.h"
|
#include "inset.h"
|
||||||
|
|
||||||
#include "BufferView.h"
|
#include "BufferView.h"
|
||||||
#include "debug.h"
|
|
||||||
#include "funcrequest.h"
|
#include "funcrequest.h"
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
#include "lyxcursor.h"
|
|
||||||
#include "lyxfont.h"
|
#include "lyxfont.h"
|
||||||
#include "lyxtext.h"
|
#include "lyxtext.h"
|
||||||
#include "WordLangTuple.h"
|
|
||||||
|
|
||||||
#include "frontends/Painter.h"
|
#include "frontends/Painter.h"
|
||||||
#include "frontends/mouse_state.h"
|
#include "frontends/mouse_state.h"
|
||||||
|
|
||||||
#include "support/lstrings.h"
|
|
||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
|
|
||||||
using std::endl;
|
using std::endl;
|
||||||
@ -161,214 +157,3 @@ int Inset::latexTextWidth(BufferView * bv) const
|
|||||||
return bv->workWidth();
|
return bv->workWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
// some stuff for inset locking
|
|
||||||
|
|
||||||
UpdatableInset::UpdatableInset()
|
|
||||||
: Inset(), cursor_visible_(false), block_drawing_(false)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
UpdatableInset::UpdatableInset(UpdatableInset const & in, bool same_id)
|
|
||||||
: Inset(in, same_id), cursor_visible_(false), block_drawing_(false)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
void UpdatableInset::insetUnlock(BufferView *)
|
|
||||||
{
|
|
||||||
lyxerr[Debug::INFO] << "Inset Unlock" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// An updatable inset is highly editable by definition
|
|
||||||
Inset::EDITABLE UpdatableInset::editable() const
|
|
||||||
{
|
|
||||||
return HIGHLY_EDITABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void UpdatableInset::toggleInsetCursor(BufferView *)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
void UpdatableInset::showInsetCursor(BufferView *, bool)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
void UpdatableInset::hideInsetCursor(BufferView *)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
void UpdatableInset::fitInsetCursor(BufferView *) const
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
void UpdatableInset::edit(BufferView *, int, int, mouse_button::state)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
void UpdatableInset::edit(BufferView *, bool)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
void UpdatableInset::draw(BufferView *, LyXFont const &,
|
|
||||||
int /* baseline */, float & x,
|
|
||||||
bool/*cleared*/) const
|
|
||||||
{
|
|
||||||
x += float(scx);
|
|
||||||
// ATTENTION: don't do the following here!!!
|
|
||||||
// top_x = int(x);
|
|
||||||
// top_baseline = baseline;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void UpdatableInset::scroll(BufferView * bv, float s) const
|
|
||||||
{
|
|
||||||
LyXFont font;
|
|
||||||
|
|
||||||
if (!s) {
|
|
||||||
scx = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int const workW = bv->workWidth();
|
|
||||||
int const tmp_top_x = top_x - scx;
|
|
||||||
|
|
||||||
if (tmp_top_x > 0 &&
|
|
||||||
(tmp_top_x + width(bv, font)) < workW)
|
|
||||||
return;
|
|
||||||
if (s > 0 && top_x > 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
|
|
||||||
//int const save_scx = scx;
|
|
||||||
|
|
||||||
scx = int(s * workW / 2);
|
|
||||||
// if (!display())
|
|
||||||
// scx += 20;
|
|
||||||
|
|
||||||
if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
|
|
||||||
scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
|
|
||||||
}
|
|
||||||
|
|
||||||
// bv->updateInset(const_cast<UpdatableInset *>(this), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdatableInset::scroll(BufferView * bv, int offset) const
|
|
||||||
{
|
|
||||||
if (offset > 0) {
|
|
||||||
if (!scx && top_x >= 20)
|
|
||||||
return;
|
|
||||||
if ((top_x + offset) > 20)
|
|
||||||
scx = 0;
|
|
||||||
// scx += offset - (top_x - scx + offset - 20);
|
|
||||||
else
|
|
||||||
scx += offset;
|
|
||||||
} else {
|
|
||||||
LyXFont const font;
|
|
||||||
if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
|
|
||||||
return;
|
|
||||||
if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
|
|
||||||
scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
|
|
||||||
} else {
|
|
||||||
scx += offset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// bv->updateInset(const_cast<UpdatableInset *>(this), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// An updatable inset could handle lyx editing commands
|
|
||||||
Inset::RESULT UpdatableInset::localDispatch(FuncRequest const & ev)
|
|
||||||
{
|
|
||||||
if (ev.action == LFUN_MOUSE_RELEASE)
|
|
||||||
return (editable() == IS_EDITABLE) ? DISPATCHED : UNDISPATCHED;
|
|
||||||
|
|
||||||
if (!ev.argument.empty() && ev.action == LFUN_SCROLL_INSET) {
|
|
||||||
if (ev.argument.find('.') != ev.argument.npos) {
|
|
||||||
float const xx = static_cast<float>(strToDbl(ev.argument));
|
|
||||||
scroll(ev.view(), xx);
|
|
||||||
} else {
|
|
||||||
int const xx = strToInt(ev.argument);
|
|
||||||
scroll(ev.view(), xx);
|
|
||||||
}
|
|
||||||
ev.view()->updateInset(this, false);
|
|
||||||
|
|
||||||
return DISPATCHED;
|
|
||||||
}
|
|
||||||
return UNDISPATCHED;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
|
|
||||||
{
|
|
||||||
int w;
|
|
||||||
if (owner()) {
|
|
||||||
w = static_cast<UpdatableInset*>
|
|
||||||
(owner())->getMaxWidth(bv, this);
|
|
||||||
} else {
|
|
||||||
w = bv->text->workWidth(bv, const_cast<UpdatableInset *>(this));
|
|
||||||
}
|
|
||||||
if (w < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
// check for margins left/right and extra right margin "const 5"
|
|
||||||
if ((w - ((2 * TEXT_TO_INSET_OFFSET) + 5)) >= 0)
|
|
||||||
w -= (2 * TEXT_TO_INSET_OFFSET) + 5;
|
|
||||||
if (topx_set && owner()) {
|
|
||||||
w -= top_x;
|
|
||||||
w += owner()->x();
|
|
||||||
} else if (owner()) {
|
|
||||||
// this is needed as otherwise we might have a too large inset if
|
|
||||||
// its top_x afterwards changes to LeftMargin so we try to put at
|
|
||||||
// least the default margin as top_x
|
|
||||||
w -= 20;
|
|
||||||
}
|
|
||||||
if (w < 10) {
|
|
||||||
w = 10;
|
|
||||||
}
|
|
||||||
return w;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
LyXCursor const & Inset::cursor(BufferView * bv) const
|
|
||||||
{
|
|
||||||
if (owner())
|
|
||||||
return owner()->getLyXText(bv, false)->cursor;
|
|
||||||
return bv->text->cursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
WordLangTuple const
|
|
||||||
UpdatableInset::selectNextWordToSpellcheck(BufferView *bv, float & value) const
|
|
||||||
{
|
|
||||||
// we have to unlock ourself in this function by default!
|
|
||||||
bv->unlockInset(const_cast<UpdatableInset *>(this));
|
|
||||||
value = 0;
|
|
||||||
return WordLangTuple();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool UpdatableInset::nextChange(BufferView * bv, lyx::pos_type &)
|
|
||||||
{
|
|
||||||
// we have to unlock ourself in this function by default!
|
|
||||||
bv->unlockInset(const_cast<UpdatableInset *>(this));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool UpdatableInset::searchForward(BufferView * bv, string const &,
|
|
||||||
bool, bool)
|
|
||||||
{
|
|
||||||
// we have to unlock ourself in this function by default!
|
|
||||||
bv->unlockInset(const_cast<UpdatableInset *>(this));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool UpdatableInset::searchBackward(BufferView * bv, string const &,
|
|
||||||
bool, bool)
|
|
||||||
{
|
|
||||||
// we have to unlock ourself in this function by default!
|
|
||||||
bv->unlockInset(const_cast<UpdatableInset *>(this));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
@ -378,158 +378,6 @@ bool Inset::checkInsertChar(LyXFont &)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updatable Insets. These insets can be locked and receive
|
|
||||||
// directly user interaction. Currently used only for mathed.
|
|
||||||
// Note that all pure methods from Inset class are pure here too.
|
|
||||||
// [Alejandro 080596]
|
|
||||||
|
|
||||||
/** Extracted from Matthias notes:
|
|
||||||
*
|
|
||||||
* An inset can simple call LockInset in it's edit call and *ONLY*
|
|
||||||
* in it's edit call.
|
|
||||||
*
|
|
||||||
* Unlocking is either done by LyX or the inset itself with a
|
|
||||||
* UnlockInset-call
|
|
||||||
*
|
|
||||||
* During the lock, all button and keyboard events will be modified
|
|
||||||
* and send to the inset through the following inset-features. Note that
|
|
||||||
* Inset::insetUnlock will be called from inside UnlockInset. It is meant
|
|
||||||
* to contain the code for restoring the menus and things like this.
|
|
||||||
*
|
|
||||||
* If a inset wishes any redraw and/or update it just has to call
|
|
||||||
* updateInset(this).
|
|
||||||
*
|
|
||||||
* It's is completly irrelevant, where the inset is. UpdateInset will
|
|
||||||
* find it in any paragraph in any buffer.
|
|
||||||
* Of course the_locking_inset and the insets in the current paragraph/buffer
|
|
||||||
* are checked first, so no performance problem should occur.
|
|
||||||
*/
|
|
||||||
class UpdatableInset : public Inset {
|
|
||||||
public:
|
|
||||||
///
|
|
||||||
UpdatableInset();
|
|
||||||
///
|
|
||||||
UpdatableInset(UpdatableInset const & in, bool same_id = false);
|
|
||||||
|
|
||||||
/// check if the font of the char we want inserting is correct
|
|
||||||
/// and modify it if it is not.
|
|
||||||
virtual bool checkInsertChar(LyXFont &);
|
|
||||||
///
|
|
||||||
virtual EDITABLE editable() const;
|
|
||||||
|
|
||||||
///
|
|
||||||
virtual void toggleInsetCursor(BufferView *);
|
|
||||||
///
|
|
||||||
virtual void showInsetCursor(BufferView *, bool show = true);
|
|
||||||
///
|
|
||||||
virtual void hideInsetCursor(BufferView *);
|
|
||||||
///
|
|
||||||
virtual void fitInsetCursor(BufferView *) const;
|
|
||||||
///
|
|
||||||
virtual void getCursorPos(BufferView *, int &, int &) const {}
|
|
||||||
///
|
|
||||||
virtual void insetUnlock(BufferView *);
|
|
||||||
///
|
|
||||||
virtual void edit(BufferView *, int x, int y, mouse_button::state button);
|
|
||||||
///
|
|
||||||
virtual void edit(BufferView *, bool front = true);
|
|
||||||
///
|
|
||||||
virtual void draw(BufferView *, LyXFont const &,
|
|
||||||
int baseline, float & x, bool cleared) const;
|
|
||||||
///
|
|
||||||
virtual bool insertInset(BufferView *, Inset *) { return false; }
|
|
||||||
///
|
|
||||||
virtual UpdatableInset * getLockingInset() const {
|
|
||||||
return const_cast<UpdatableInset *>(this);
|
|
||||||
}
|
|
||||||
///
|
|
||||||
virtual UpdatableInset * getFirstLockingInsetOfType(Inset::Code c)
|
|
||||||
{ return (c == lyxCode()) ? this : 0; }
|
|
||||||
///
|
|
||||||
virtual int insetInInsetY() const { return 0; }
|
|
||||||
///
|
|
||||||
virtual bool updateInsetInInset(BufferView *, Inset *)
|
|
||||||
{ return false; }
|
|
||||||
///
|
|
||||||
virtual bool lockInsetInInset(BufferView *, UpdatableInset *)
|
|
||||||
{ return false; }
|
|
||||||
///
|
|
||||||
virtual bool unlockInsetInInset(BufferView *, UpdatableInset *,
|
|
||||||
bool /*lr*/ = false)
|
|
||||||
{ return false; }
|
|
||||||
/// An updatable inset could handle lyx editing commands
|
|
||||||
virtual RESULT localDispatch(FuncRequest const & cmd);
|
|
||||||
///
|
|
||||||
bool isCursorVisible() const { return cursor_visible_; }
|
|
||||||
///
|
|
||||||
virtual int getMaxWidth(BufferView * bv, UpdatableInset const *) const;
|
|
||||||
///
|
|
||||||
int scroll(bool recursive = true) const {
|
|
||||||
// We need this method to not clobber the real method in Inset
|
|
||||||
return Inset::scroll(recursive);
|
|
||||||
}
|
|
||||||
///
|
|
||||||
virtual bool showInsetDialog(BufferView *) const { return false; }
|
|
||||||
///
|
|
||||||
virtual void nodraw(bool b) const {
|
|
||||||
block_drawing_ = b;
|
|
||||||
}
|
|
||||||
///
|
|
||||||
virtual bool nodraw() const {
|
|
||||||
return block_drawing_;
|
|
||||||
}
|
|
||||||
///
|
|
||||||
// needed for spellchecking text
|
|
||||||
///
|
|
||||||
virtual bool allowSpellcheck() const { return false; }
|
|
||||||
///
|
|
||||||
virtual WordLangTuple const
|
|
||||||
selectNextWordToSpellcheck(BufferView *, float & value) const;
|
|
||||||
///
|
|
||||||
virtual void selectSelectedWord(BufferView *) {}
|
|
||||||
///
|
|
||||||
virtual void toggleSelection(BufferView *, bool /*kill_selection*/) {}
|
|
||||||
|
|
||||||
/// find the next change in the inset
|
|
||||||
virtual bool nextChange(BufferView * bv, lyx::pos_type & length);
|
|
||||||
|
|
||||||
///
|
|
||||||
// needed for search/replace functionality
|
|
||||||
///
|
|
||||||
virtual bool searchForward(BufferView *, string const &,
|
|
||||||
bool = true, bool = false);
|
|
||||||
///
|
|
||||||
virtual bool searchBackward(BufferView *, string const &,
|
|
||||||
bool = true, bool = false);
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
///
|
|
||||||
void toggleCursorVisible() const {
|
|
||||||
cursor_visible_ = !cursor_visible_;
|
|
||||||
}
|
|
||||||
///
|
|
||||||
void setCursorVisible(bool b) const {
|
|
||||||
cursor_visible_ = b;
|
|
||||||
}
|
|
||||||
/// scrolls to absolute position in bufferview-workwidth * sx units
|
|
||||||
void scroll(BufferView *, float sx) const;
|
|
||||||
/// scrolls offset pixels
|
|
||||||
void scroll(BufferView *, int offset) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
///
|
|
||||||
mutable bool cursor_visible_;
|
|
||||||
///
|
|
||||||
mutable bool block_drawing_;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline
|
|
||||||
bool UpdatableInset::checkInsertChar(LyXFont &)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns true if pointer argument is valid
|
* returns true if pointer argument is valid
|
||||||
* and points to an editable inset
|
* and points to an editable inset
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#define INSETTEXT_H
|
#define INSETTEXT_H
|
||||||
|
|
||||||
|
|
||||||
#include "inset.h"
|
#include "updatableinset.h"
|
||||||
#include "LString.h"
|
#include "LString.h"
|
||||||
#include "LColor.h"
|
#include "LColor.h"
|
||||||
#include "ParagraphList.h"
|
#include "ParagraphList.h"
|
||||||
|
222
src/insets/updatableinset.C
Normal file
222
src/insets/updatableinset.C
Normal file
@ -0,0 +1,222 @@
|
|||||||
|
|
||||||
|
#include "updatableinset.h"
|
||||||
|
#include "BufferView.h"
|
||||||
|
#include "funcrequest.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "lyxfont.h"
|
||||||
|
#include "WordLangTuple.h"
|
||||||
|
#include "lyxtext.h"
|
||||||
|
#include "support/lstrings.h"
|
||||||
|
|
||||||
|
|
||||||
|
// some stuff for inset locking
|
||||||
|
|
||||||
|
UpdatableInset::UpdatableInset()
|
||||||
|
: Inset(), cursor_visible_(false), block_drawing_(false)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
UpdatableInset::UpdatableInset(UpdatableInset const & in, bool same_id)
|
||||||
|
: Inset(in, same_id), cursor_visible_(false), block_drawing_(false)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
void UpdatableInset::insetUnlock(BufferView *)
|
||||||
|
{
|
||||||
|
lyxerr[Debug::INFO] << "Inset Unlock" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// An updatable inset is highly editable by definition
|
||||||
|
Inset::EDITABLE UpdatableInset::editable() const
|
||||||
|
{
|
||||||
|
return HIGHLY_EDITABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void UpdatableInset::toggleInsetCursor(BufferView *)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
void UpdatableInset::showInsetCursor(BufferView *, bool)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
void UpdatableInset::hideInsetCursor(BufferView *)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
void UpdatableInset::fitInsetCursor(BufferView *) const
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
void UpdatableInset::edit(BufferView *, int, int, mouse_button::state)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
void UpdatableInset::edit(BufferView *, bool)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
void UpdatableInset::draw(BufferView *, LyXFont const &,
|
||||||
|
int /* baseline */, float & x,
|
||||||
|
bool/*cleared*/) const
|
||||||
|
{
|
||||||
|
x += float(scx);
|
||||||
|
// ATTENTION: don't do the following here!!!
|
||||||
|
// top_x = int(x);
|
||||||
|
// top_baseline = baseline;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void UpdatableInset::scroll(BufferView * bv, float s) const
|
||||||
|
{
|
||||||
|
LyXFont font;
|
||||||
|
|
||||||
|
if (!s) {
|
||||||
|
scx = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int const workW = bv->workWidth();
|
||||||
|
int const tmp_top_x = top_x - scx;
|
||||||
|
|
||||||
|
if (tmp_top_x > 0 &&
|
||||||
|
(tmp_top_x + width(bv, font)) < workW)
|
||||||
|
return;
|
||||||
|
if (s > 0 && top_x > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
|
||||||
|
//int const save_scx = scx;
|
||||||
|
|
||||||
|
scx = int(s * workW / 2);
|
||||||
|
// if (!display())
|
||||||
|
// scx += 20;
|
||||||
|
|
||||||
|
if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
|
||||||
|
scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
|
||||||
|
}
|
||||||
|
|
||||||
|
// bv->updateInset(const_cast<UpdatableInset *>(this), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdatableInset::scroll(BufferView * bv, int offset) const
|
||||||
|
{
|
||||||
|
if (offset > 0) {
|
||||||
|
if (!scx && top_x >= 20)
|
||||||
|
return;
|
||||||
|
if ((top_x + offset) > 20)
|
||||||
|
scx = 0;
|
||||||
|
// scx += offset - (top_x - scx + offset - 20);
|
||||||
|
else
|
||||||
|
scx += offset;
|
||||||
|
} else {
|
||||||
|
LyXFont const font;
|
||||||
|
if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
|
||||||
|
return;
|
||||||
|
if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
|
||||||
|
scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
|
||||||
|
} else {
|
||||||
|
scx += offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// bv->updateInset(const_cast<UpdatableInset *>(this), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// An updatable inset could handle lyx editing commands
|
||||||
|
Inset::RESULT UpdatableInset::localDispatch(FuncRequest const & ev)
|
||||||
|
{
|
||||||
|
if (ev.action == LFUN_MOUSE_RELEASE)
|
||||||
|
return (editable() == IS_EDITABLE) ? DISPATCHED : UNDISPATCHED;
|
||||||
|
|
||||||
|
if (!ev.argument.empty() && ev.action == LFUN_SCROLL_INSET) {
|
||||||
|
if (ev.argument.find('.') != ev.argument.npos) {
|
||||||
|
float const xx = static_cast<float>(strToDbl(ev.argument));
|
||||||
|
scroll(ev.view(), xx);
|
||||||
|
} else {
|
||||||
|
int const xx = strToInt(ev.argument);
|
||||||
|
scroll(ev.view(), xx);
|
||||||
|
}
|
||||||
|
ev.view()->updateInset(this, false);
|
||||||
|
|
||||||
|
return DISPATCHED;
|
||||||
|
}
|
||||||
|
return UNDISPATCHED;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
|
||||||
|
{
|
||||||
|
int w;
|
||||||
|
if (owner()) {
|
||||||
|
w = static_cast<UpdatableInset*>
|
||||||
|
(owner())->getMaxWidth(bv, this);
|
||||||
|
} else {
|
||||||
|
w = bv->text->workWidth(bv, const_cast<UpdatableInset *>(this));
|
||||||
|
}
|
||||||
|
if (w < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// check for margins left/right and extra right margin "const 5"
|
||||||
|
if ((w - ((2 * TEXT_TO_INSET_OFFSET) + 5)) >= 0)
|
||||||
|
w -= (2 * TEXT_TO_INSET_OFFSET) + 5;
|
||||||
|
if (topx_set && owner()) {
|
||||||
|
w -= top_x;
|
||||||
|
w += owner()->x();
|
||||||
|
} else if (owner()) {
|
||||||
|
// this is needed as otherwise we might have a too large inset if
|
||||||
|
// its top_x afterwards changes to LeftMargin so we try to put at
|
||||||
|
// least the default margin as top_x
|
||||||
|
w -= 20;
|
||||||
|
}
|
||||||
|
if (w < 10) {
|
||||||
|
w = 10;
|
||||||
|
}
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LyXCursor const & Inset::cursor(BufferView * bv) const
|
||||||
|
{
|
||||||
|
if (owner())
|
||||||
|
return owner()->getLyXText(bv, false)->cursor;
|
||||||
|
return bv->text->cursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WordLangTuple const
|
||||||
|
UpdatableInset::selectNextWordToSpellcheck(BufferView *bv, float & value) const
|
||||||
|
{
|
||||||
|
// we have to unlock ourself in this function by default!
|
||||||
|
bv->unlockInset(const_cast<UpdatableInset *>(this));
|
||||||
|
value = 0;
|
||||||
|
return WordLangTuple();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool UpdatableInset::nextChange(BufferView * bv, lyx::pos_type &)
|
||||||
|
{
|
||||||
|
// we have to unlock ourself in this function by default!
|
||||||
|
bv->unlockInset(const_cast<UpdatableInset *>(this));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool UpdatableInset::searchForward(BufferView * bv, string const &,
|
||||||
|
bool, bool)
|
||||||
|
{
|
||||||
|
// we have to unlock ourself in this function by default!
|
||||||
|
bv->unlockInset(const_cast<UpdatableInset *>(this));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool UpdatableInset::searchBackward(BufferView * bv, string const &,
|
||||||
|
bool, bool)
|
||||||
|
{
|
||||||
|
// we have to unlock ourself in this function by default!
|
||||||
|
bv->unlockInset(const_cast<UpdatableInset *>(this));
|
||||||
|
return false;
|
||||||
|
}
|
178
src/insets/updatableinset.h
Normal file
178
src/insets/updatableinset.h
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
// -*- C++ -*-
|
||||||
|
/**
|
||||||
|
* \file insetupdatable.h
|
||||||
|
* This file is part of LyX, the document processor.
|
||||||
|
* Licence details can be found in the file COPYING.
|
||||||
|
*
|
||||||
|
* \author Alejandro Aguilar Sierra
|
||||||
|
* \author Jürgen Vigna
|
||||||
|
* \author Lars Gullik Bjønnes
|
||||||
|
* \author Matthias Ettrich
|
||||||
|
*
|
||||||
|
* Full author contact details are available in file CREDITS
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef UPDATABLEINSET_H
|
||||||
|
#define UPDATABLEINSET_H
|
||||||
|
|
||||||
|
// Updatable Insets. These insets can be locked and receive
|
||||||
|
// directly user interaction. Currently used only for mathed.
|
||||||
|
// Note that all pure methods from Inset class are pure here too.
|
||||||
|
// [Alejandro 080596]
|
||||||
|
|
||||||
|
#include "inset.h"
|
||||||
|
|
||||||
|
|
||||||
|
/** Extracted from Matthias notes:
|
||||||
|
*
|
||||||
|
* An inset can simple call LockInset in it's edit call and *ONLY*
|
||||||
|
* in it's edit call.
|
||||||
|
*
|
||||||
|
* Unlocking is either done by LyX or the inset itself with a
|
||||||
|
* UnlockInset-call
|
||||||
|
*
|
||||||
|
* During the lock, all button and keyboard events will be modified
|
||||||
|
* and send to the inset through the following inset-features. Note that
|
||||||
|
* Inset::insetUnlock will be called from inside UnlockInset. It is meant
|
||||||
|
* to contain the code for restoring the menus and things like this.
|
||||||
|
*
|
||||||
|
* If a inset wishes any redraw and/or update it just has to call
|
||||||
|
* updateInset(this).
|
||||||
|
*
|
||||||
|
* It's is completly irrelevant, where the inset is. UpdateInset will
|
||||||
|
* find it in any paragraph in any buffer.
|
||||||
|
* Of course the_locking_inset and the insets in the current paragraph/buffer
|
||||||
|
* are checked first, so no performance problem should occur.
|
||||||
|
*/
|
||||||
|
class UpdatableInset : public Inset {
|
||||||
|
public:
|
||||||
|
///
|
||||||
|
UpdatableInset();
|
||||||
|
///
|
||||||
|
UpdatableInset(UpdatableInset const & in, bool same_id = false);
|
||||||
|
|
||||||
|
/// check if the font of the char we want inserting is correct
|
||||||
|
/// and modify it if it is not.
|
||||||
|
virtual bool checkInsertChar(LyXFont &);
|
||||||
|
///
|
||||||
|
virtual EDITABLE editable() const;
|
||||||
|
|
||||||
|
///
|
||||||
|
virtual void toggleInsetCursor(BufferView *);
|
||||||
|
///
|
||||||
|
virtual void showInsetCursor(BufferView *, bool show = true);
|
||||||
|
///
|
||||||
|
virtual void hideInsetCursor(BufferView *);
|
||||||
|
///
|
||||||
|
virtual void fitInsetCursor(BufferView *) const;
|
||||||
|
///
|
||||||
|
virtual void getCursorPos(BufferView *, int &, int &) const {}
|
||||||
|
///
|
||||||
|
virtual void insetUnlock(BufferView *);
|
||||||
|
///
|
||||||
|
virtual void edit(BufferView *, int x, int y, mouse_button::state button);
|
||||||
|
///
|
||||||
|
virtual void edit(BufferView *, bool front = true);
|
||||||
|
///
|
||||||
|
virtual void draw(BufferView *, LyXFont const &,
|
||||||
|
int baseline, float & x, bool cleared) const;
|
||||||
|
///
|
||||||
|
virtual bool insertInset(BufferView *, Inset *) { return false; }
|
||||||
|
///
|
||||||
|
virtual UpdatableInset * getLockingInset() const {
|
||||||
|
return const_cast<UpdatableInset *>(this);
|
||||||
|
}
|
||||||
|
///
|
||||||
|
virtual UpdatableInset * getFirstLockingInsetOfType(Inset::Code c)
|
||||||
|
{ return (c == lyxCode()) ? this : 0; }
|
||||||
|
///
|
||||||
|
virtual int insetInInsetY() const { return 0; }
|
||||||
|
///
|
||||||
|
virtual bool updateInsetInInset(BufferView *, Inset *)
|
||||||
|
{ return false; }
|
||||||
|
///
|
||||||
|
virtual bool lockInsetInInset(BufferView *, UpdatableInset *)
|
||||||
|
{ return false; }
|
||||||
|
///
|
||||||
|
virtual bool unlockInsetInInset(BufferView *, UpdatableInset *,
|
||||||
|
bool /*lr*/ = false)
|
||||||
|
{ return false; }
|
||||||
|
/// An updatable inset could handle lyx editing commands
|
||||||
|
virtual RESULT localDispatch(FuncRequest const & cmd);
|
||||||
|
///
|
||||||
|
bool isCursorVisible() const { return cursor_visible_; }
|
||||||
|
///
|
||||||
|
virtual int getMaxWidth(BufferView * bv, UpdatableInset const *) const;
|
||||||
|
///
|
||||||
|
int scroll(bool recursive = true) const {
|
||||||
|
// We need this method to not clobber the real method in Inset
|
||||||
|
return Inset::scroll(recursive);
|
||||||
|
}
|
||||||
|
///
|
||||||
|
virtual bool showInsetDialog(BufferView *) const { return false; }
|
||||||
|
///
|
||||||
|
virtual void nodraw(bool b) const {
|
||||||
|
block_drawing_ = b;
|
||||||
|
}
|
||||||
|
///
|
||||||
|
virtual bool nodraw() const {
|
||||||
|
return block_drawing_;
|
||||||
|
}
|
||||||
|
///
|
||||||
|
// needed for spellchecking text
|
||||||
|
///
|
||||||
|
virtual bool allowSpellcheck() const { return false; }
|
||||||
|
///
|
||||||
|
virtual WordLangTuple const
|
||||||
|
selectNextWordToSpellcheck(BufferView *, float & value) const;
|
||||||
|
///
|
||||||
|
virtual void selectSelectedWord(BufferView *) {}
|
||||||
|
///
|
||||||
|
virtual void toggleSelection(BufferView *, bool /*kill_selection*/) {}
|
||||||
|
|
||||||
|
/// find the next change in the inset
|
||||||
|
virtual bool nextChange(BufferView * bv, lyx::pos_type & length);
|
||||||
|
|
||||||
|
///
|
||||||
|
// needed for search/replace functionality
|
||||||
|
///
|
||||||
|
virtual bool searchForward(BufferView *, string const &,
|
||||||
|
bool = true, bool = false);
|
||||||
|
///
|
||||||
|
virtual bool searchBackward(BufferView *, string const &,
|
||||||
|
bool = true, bool = false);
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
BufferView * view() const;
|
||||||
|
///
|
||||||
|
void setView(BufferView * bv) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
///
|
||||||
|
void toggleCursorVisible() const {
|
||||||
|
cursor_visible_ = !cursor_visible_;
|
||||||
|
}
|
||||||
|
///
|
||||||
|
void setCursorVisible(bool b) const {
|
||||||
|
cursor_visible_ = b;
|
||||||
|
}
|
||||||
|
/// scrolls to absolute position in bufferview-workwidth * sx units
|
||||||
|
void scroll(BufferView *, float sx) const;
|
||||||
|
/// scrolls offset pixels
|
||||||
|
void scroll(BufferView *, int offset) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
///
|
||||||
|
mutable bool cursor_visible_;
|
||||||
|
///
|
||||||
|
mutable bool block_drawing_;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool UpdatableInset::checkInsertChar(LyXFont &)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -14,7 +14,7 @@
|
|||||||
#define INSET_FORMULABASE_H
|
#define INSET_FORMULABASE_H
|
||||||
|
|
||||||
|
|
||||||
#include "insets/inset.h"
|
#include "insets/updatableinset.h"
|
||||||
#include "frontends/mouse_state.h"
|
#include "frontends/mouse_state.h"
|
||||||
#include "lyxfont.h"
|
#include "lyxfont.h"
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#include "lyxtext.h"
|
#include "lyxtext.h"
|
||||||
#include "BufferView.h"
|
#include "BufferView.h"
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "insets/inset.h"
|
#include "insets/updatableinset.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "support/LAssert.h"
|
#include "support/LAssert.h"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user