// built temporary path to inset
InsetBase * inset = bv_->text()->editXY(cur, cmd.x, cmd.y);
lyxerr << "hit inset at tip: " << inset << endl;
- lyxerr << "created temp cursor: " << cur << endl;
+ lyxerr << "created temp cursor:\n" << cur << endl;
// Try to dispatch to an non-editable inset near this position
DispatchResult res;
if (inset)
- res = inset->dispatch(cur, cmd);
+ inset->dispatch(cur, cmd);
// Dispatch to the temp cursor.
// An inset (or LyXText) can assign this to bv->cursor()
+2004-02-16 André Pönitz <poenitz@gmx.net>
+
+ * cursor.[Ch]: use new '_void_ dispatch(...)' signature (see
+ insets/ChangeLog)
+
+ * cursor_slice.[Ch]: remove unneeded acessor function
+
+ * lyxtext.h: rename rtl() to isRTL()
+
+ * rowpainter.C:
+ * tabular.C:
+ * text.C:
+ * text2.C:
+ * text3.C: adjust
+
+
2004-02-16 Alfredo Braunstein <abraunst@lyx.org>
* rowpainter.C (paintSelection): coord fix
--p.pos;
InsetBase * inset = p.pit->getInset(p.pos);
if (inset)
- p.index = inset->numParagraphs();
+ p.index = inset->nargs();
} else {
if (p.pit == p.pl->begin()) {
if (stack_.size() == 1)
{
lyxerr << "\nLCursor::dispatch: cmd: " << cmd0 << endl << *this << endl;
FuncRequest cmd = cmd0;
+ disp_.update(true);
+ disp_.val(NONE);
for (current_ = cursor_.size() - 1; current_ >= 1; --current_) {
- DispatchResult res = inset()->dispatch(*this, cmd);
- if (res.dispatched()) {
- current_ = cursor_.size() - 1;
- return DispatchResult(true, true);
- }
+ // the inset's dispatch() is supposed to reset the update and
+ // val flags if necessary
+ inset()->dispatch(*this, cmd);
-
// "Mutate" the request for semi-handled requests that need
// additional handling in outer levels.
- switch (res.val()) {
+ switch (disp_.val()) {
+ case NONE:
+ // the inset handled the event fully
+ current_ = cursor_.size() - 1;
+ return DispatchResult(true, true);
case FINISHED:
+ // the inset handled the event partially
cmd = FuncRequest(LFUN_FINISHED_LEFT);
break;
case FINISHED_RIGHT:
break;
default:
//lyxerr << "not handled on level " << current_
- // << " val: " << res.val() << endl;
+ // << " val: " << disp_.val() << endl;
break;
}
}
BOOST_ASSERT(current_ == 0);
- DispatchResult res = bv_->text()->dispatch(*this, cmd);
+ bv_->text()->dispatch(*this, cmd);
//lyxerr << " result: " << res.val() << endl;
current_ = cursor_.size() - 1;
- return res;
+ return disp_;
}
bool LCursor::goUpDown(bool up)
{
- // Be warned: The 'logic' implemented in this function is highly fragile.
- // A distance of one pixel or a '<' vs '<=' _really_ matters.
- // So fiddle around with it only if you know what you are doing!
+ // Be warned: The 'logic' implemented in this function is highly
+ // fragile. A distance of one pixel or a '<' vs '<=' _really
+ // matters. So fiddle around with it only if you think you know
+ // what you are doing!
int xo = 0;
int yo = 0;
getPos(xo, yo);
double best_dist = 1e10;
CursorBase it = cursor_;
- it.back().pos(0);
+ it.back().pos() = 0;
CursorBase et = cursor_;
- int n = et.back().asMathInset()->cell(et.back().idx_).size();
- et.back().pos(n);
+ et.back().pos() = et.back().asMathInset()->cell(et.back().idx_).size();
for (int i = 0; ; ++i) {
int xo, yo;
CursorSlice & cur = it.back();
{
return inMathed() ? "eq:" : text()->getPossibleLabel(*this);
}
+
+
+void LCursor::notdispatched()
+{
+ disp_.dispatched(false);
+}
+
+
+void LCursor::dispatched(dispatch_result_t res)
+{
+ disp_.val(res);
+}
+
+
+void LCursor::noupdate()
+{
+ disp_.update(false);
+}
#define CURSOR_H
#include "cursor_slice.h"
+#include "dispatchresult.h"
#include <iosfwd>
#include <vector>
void replaceWord(std::string const & replacestring);
/// update our view
void update();
+ ///
+ void dispatched(dispatch_result_t res);
+ void notdispatched();
+ void noupdate();
/// output
friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);
std::vector<CursorSlice> cursor_;
/// the anchor position
std::vector<CursorSlice> anchor_;
+
+ ///
+ DispatchResult disp_;
private:
///
}
-void CursorSlice::idx(idx_type idx)
-{
- idx_ = idx;
-}
-
-
size_t CursorSlice::nargs() const
{
return inset_->nargs();
}
-void CursorSlice::par(par_type par)
-{
- par_ = par;
-}
-
-
CursorSlice::par_type CursorSlice::par() const
{
return par_;
}
-void CursorSlice::pos(pos_type pos)
-{
- pos_ = pos;
-}
-
-
CursorSlice::pos_type CursorSlice::pos() const
{
return pos_;
}
-void CursorSlice::boundary(bool boundary)
-{
- boundary_ = boundary;
-}
-
-
bool CursorSlice::boundary() const
{
return boundary_;
std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
{
- os << "inset: " << item.inset_
- << " text: " << item.text()
+ os
+// << "inset: " << item.inset_
+// << " text: " << item.text()
<< " idx: " << item.idx_
<< " par: " << item.par_
<< " pos: " << item.pos_
/// the current inset
InsetBase * inset() const { return inset_; }
- /// set the paragraph that contains this cursor
- void idx(idx_type idx);
/// return the cell this cursor is in
idx_type idx() const;
/// return the cell this cursor is in
idx_type & idx();
/// return the last cell in this inset
idx_type lastidx() const { return nargs() - 1; }
- /// set the paragraph that contains this cursor
- void par(par_type par);
/// return the paragraph this cursor is in
par_type par() const;
/// return the paragraph this cursor is in
par_type & par();
- /// set the position within the paragraph
- void pos(pos_type pos);
/// return the position within the paragraph
pos_type pos() const;
/// return the position within the paragraph
/// texted specific stuff
///
/// see comment for the member
- void boundary(bool b);
- /// see comment for the member
bool boundary() const;
/// see comment for the member
bool & boundary();
+2004-02-16 André Pönitz <poenitz@gmx.net>
+
+ * insetbase.C:
+ * insetbase.[Ch]: remove explicit 'DispatchResult' return type and
+ implicitly assume 'DispatchResult(true, true) with exception of
+ InsetBase::priv_dispatch which does the equivalent of
+ 'retrun DispatchResult(false)'
+
+ * inset*.[Ch] (priv_dispatch): adjust
+
+ * insettabular.[Ch]: remove remains of the 'update' mechanism,
+ simplify cursor moving function,
+ re-enable horizontal scrolling for large tables
+
2004-02-13 André Pönitz <poenitz@gmx.net>
* insettabular.[Ch]: some work after IU
-DispatchResult InsetBase::dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetBase::dispatch(LCursor & cur, FuncRequest const & cmd)
{
- return priv_dispatch(cur, cmd);
+ priv_dispatch(cur, cmd);
}
-DispatchResult InsetBase::priv_dispatch(LCursor &, FuncRequest const &)
+void InsetBase::priv_dispatch(LCursor & cur, FuncRequest const &)
{
- lyxerr << "InsetBase::priv_dispatch" << std::endl;
- return DispatchResult(false);
+ cur.noupdate();
+ cur.notdispatched();
}
}
-InsetBase * InsetBase::editXY(LCursor & cur, int, int)
+InsetBase * InsetBase::editXY(LCursor &, int x, int y)
{
- lyxerr << "InsetBase: edit xy" << std::endl;
+ lyxerr << "InsetBase: editXY x:" << x << " y: " << y << std::endl;
return this;
}
}
-int InsetBase::getCell(int x, int y) const
-{
- for (int i = 0, n = numParagraphs(); i < n; ++i) {
- LyXText * text = getText(i);
- //lyxerr << "### text: " << text << " i: " << i
- // << " xo: " << text->xo_ << "..." << text->xo_ + text->width
- // << " yo: " << text->yo_
- // << " yo: " << text->yo_ - text->ascent() << "..."
- // << text->yo_ + text->descent()
- // << std::endl;
- if (x >= text->xo_
- && x <= text->xo_ + text->width
- && y >= text->yo_
- && y <= text->yo_ + text->height)
- {
- lyxerr << "### found text # " << i << std::endl;
- return i;
- }
- }
- return -1;
-}
-
-
void InsetBase::markErased()
{}
virtual UpdatableInset * asUpdatableInset() { return 0; }
// the real dispatcher
- DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
+ void dispatch(LCursor & cur, FuncRequest const & cmd);
/// cursor enters
virtual void edit(LCursor & cur, bool left);
/// if this insets owns text cells (e.g. InsetText) return cell num
virtual LyXText * getText(int /*num*/) const { return 0; }
- ///
- virtual int numParagraphs() const { return 0; }
- /// returns cell covering position (x,y), -1 if none exists
- virtual int getCell(int x, int y) const;
/** Adds a LaTeX snippet to the Preview Loader for transformation
* into a bitmap image. Does not start the laoding process.
virtual void addPreview(lyx::graphics::PreviewLoader &) const {}
protected:
// the real dispatcher
- virtual
- DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
public:
/// returns LyX code associated with the inset. Used for TOC, ...)
virtual Code lyxCode() const { return NO_CODE; }
}
-DispatchResult
-InsetBibitem::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetBibitem::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
InsetCommandParams p;
InsetCommandMailer::string2params("bibitem", cmd.argument, p);
if (p.getCmdName().empty())
- return DispatchResult(true, true);
+ break;
setParams(p);
cur.bv().update();
cur.bv().fitCursor();
- return DispatchResult(true, true);
+ break;
}
default:
- return InsetCommand::priv_dispatch(cur, cmd);
+ InsetCommand::priv_dispatch(cur, cmd);
+ break;
}
}
std::string const getBibLabel() const;
protected:
///
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
int counter;
}
-DispatchResult
-InsetBibtex::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetBibtex::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
InsetCommandMailer::string2params("bibtex", cmd.argument, p);
if (!p.getCmdName().empty())
setParams(p);
- return DispatchResult(true, true);
+ break;
}
default:
- return InsetCommand::priv_dispatch(cur, cmd);
+ InsetCommand::priv_dispatch(cur, cmd);
+ break;
}
}
bool delDatabase(std::string const &);
protected:
///
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
};
#endif // INSET_BIBTEX_H
}
-DispatchResult
-InsetBox::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetBox::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
lyxerr << "InsetBox::dispatch MODIFY" << endl;
InsetBoxMailer::string2params(cmd.argument, params_);
setButtonLabel();
- return DispatchResult(true, true);
+ break;
}
case LFUN_INSET_DIALOG_UPDATE:
InsetBoxMailer(*this).updateDialog(&cur.bv());
- return DispatchResult(true);
+ break;
case LFUN_MOUSE_RELEASE:
if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
InsetBoxMailer(*this).showDialog(&cur.bv());
- return DispatchResult(true);
+ break;
}
- return InsetCollapsable::priv_dispatch(cur, cmd);
+ InsetCollapsable::priv_dispatch(cur, cmd);
+ break;
default:
- return InsetCollapsable::priv_dispatch(cur, cmd);
+ InsetCollapsable::priv_dispatch(cur, cmd);
+ break;
}
}
};
protected:
///
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
friend class InsetBoxParams;
}
-DispatchResult
-InsetBranch::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetBranch::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetBranchMailer::string2params(cmd.argument, params);
params_.branch = params.branch;
setButtonLabel();
- return DispatchResult(true, true);
+ break;
}
case LFUN_MOUSE_PRESS:
if (cmd.button() != mouse_button::button3)
- return InsetCollapsable::priv_dispatch(cur, cmd);
- return DispatchResult(false);
+ InsetCollapsable::priv_dispatch(cur, cmd);
+ else
+ cur.notdispatched();
+ break;
case LFUN_INSET_DIALOG_UPDATE:
InsetBranchMailer(*this).updateDialog(&cur.bv());
- return DispatchResult(true);
+ break;
case LFUN_MOUSE_RELEASE:
- if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
+ if (cmd.button() == mouse_button::button3 && hitButton(cmd))
InsetBranchMailer(*this).showDialog(&cur.bv());
- return DispatchResult(true);
- }
- return InsetCollapsable::priv_dispatch(cur, cmd);
+ else
+ InsetCollapsable::priv_dispatch(cur, cmd);
+ break;
default:
- return InsetCollapsable::priv_dispatch(cur, cmd);
+ InsetCollapsable::priv_dispatch(cur, cmd);
+ break;
}
}
protected:
///
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
friend class InsetBranchParams;
}
-DispatchResult
-InsetCharStyle::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetCharStyle::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
setStatus(Inlined);
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
- if (cmd.button() == mouse_button::button3) {
+ if (cmd.button() == mouse_button::button3)
has_label_ = !has_label_;
- return DispatchResult(true);
- }
- inset.dispatch(cur, cmd);
- return DispatchResult(true, true);
+ else
+ inset.dispatch(cur, cmd);
+ break;
+
default:
- return InsetCollapsable::priv_dispatch(cur, cmd);
+ InsetCollapsable::priv_dispatch(cur, cmd);
+ break;
}
}
protected:
///
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
friend class InsetCharStyleParams;
}
-DispatchResult
-InsetCollapsable::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
+void InsetCollapsable::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
{
- if (cmd.button() == mouse_button::button3) {
+ if (cmd.button() == mouse_button::button3)
showInsetDialog(&cur.bv());
- }
switch (status_) {
+
case Collapsed:
lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
setStatus(Open);
edit(cur, true);
- return DispatchResult(true, true);
+ break;
case Open: {
FuncRequest cmd1 = cmd;
if (hitButton(cmd1)) {
lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
setStatus(Collapsed);
- return DispatchResult(false, FINISHED_RIGHT);
+ cur.dispatched(FINISHED_RIGHT);
+ break;
}
lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
- return inset.dispatch(cur, cmd);
+ inset.dispatch(cur, cmd);
+ break;
}
+
case Inlined:
- return inset.dispatch(cur, cmd);
+ inset.dispatch(cur, cmd);
+ break;
}
- BOOST_ASSERT(false);
- // shut up compiler
- return DispatchResult(true, true);
}
}
-DispatchResult
-InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
//lyxerr << "\nInsetCollapsable::priv_dispatch (begin): cmd: " << cmd
// << " button y: " << button_dim.y2 << endl;
inset.dispatch(cur, cmd);
else if (status_ == Open && cmd.y > button_dim.y2)
inset.dispatch(cur, cmd);
- return DispatchResult(true, true);
+ break;
case LFUN_MOUSE_MOTION:
if (status_ == Inlined)
inset.dispatch(cur, cmd);
else if (status_ == Open && cmd.y > button_dim.y2)
inset.dispatch(cur, cmd);
- return DispatchResult(true, true);
+ break;
case LFUN_MOUSE_RELEASE:
- return lfunMouseRelease(cur, cmd);
+ lfunMouseRelease(cur, cmd);
+ break;
case LFUN_INSET_TOGGLE:
if (inset.text_.toggleInset(cur))
- return DispatchResult(true, true);
+ break;
if (status_ == Open) {
setStatus(Inlined);
- return DispatchResult(true, true);
+ break;
}
setStatus(Collapsed);
- return DispatchResult(false, FINISHED_RIGHT);
+ cur.dispatched(FINISHED_RIGHT);
+ break;
default:
- return inset.dispatch(cur, cmd);
+ inset.dispatch(cur, cmd);
+ break;
}
}
}
-int InsetCollapsable::numParagraphs() const
+size_t InsetCollapsable::nargs() const
{
- return inset.numParagraphs();
+ return inset.nargs();
}
///
void scroll(BufferView & bv, int offset) const;
///
- int numParagraphs() const;
+ size_t nargs() const;
///
LyXText * getText(int) const;
///
protected:
///
- DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
///
void dimension_collapsed(Dimension &) const;
///
private:
///
- DispatchResult lfunMouseRelease(LCursor & cur, FuncRequest const & cmd);
+ void lfunMouseRelease(LCursor & cur, FuncRequest const & cmd);
public:
///
}
-DispatchResult
-InsetCommand::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetCommand::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetCommandParams p;
InsetCommandMailer::string2params(mailer_name_, cmd.argument, p);
- if (p.getCmdName().empty())
- return DispatchResult(false);
- setParams(p);
- cur.bv().update();
- return DispatchResult(true, true);
+ if (p.getCmdName().empty()) {
+ cur.notdispatched();
+ } else {
+ setParams(p);
+ cur.bv().update();
+ }
+ break;
}
case LFUN_INSET_DIALOG_UPDATE:
InsetCommandMailer(cmd.argument, *this).updateDialog(&cur.bv());
- return DispatchResult(true, true);
+ break;
case LFUN_INSET_DIALOG_SHOW:
case LFUN_MOUSE_RELEASE: {
if (!mailer_name_.empty())
InsetCommandMailer(mailer_name_, *this).showDialog(&cur.bv());
- return DispatchResult(true);
+ break;
}
default:
- return DispatchResult(false);
+ InsetOld::priv_dispatch(cur, cmd);
+ break;
}
}
protected:
///
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
///
std::string const getCommand() const { return p_.getCommand(); }
///
///
InsetCommandParams();
///
- explicit
- InsetCommandParams(std::string const & n,
+ explicit InsetCommandParams(std::string const & n,
std::string const & c = std::string(),
std::string const & o = std::string());
///
}
-DispatchResult InsetERT::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetERT::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
//lyxerr << "\nInsetERT::priv_dispatch (begin): cmd: " << cmd << endl;
switch (cmd.action) {
InsetCollapsable::CollapseStatus st;
InsetERTMailer::string2params(cmd.argument, st);
setStatus(st);
- return DispatchResult(true, true);
+ break;
}
+ // suppress these
case LFUN_LAYOUT:
case LFUN_BOLD:
case LFUN_CODE:
case LFUN_FONT_SIZE:
case LFUN_FONT_STATE:
case LFUN_UNDERLINE:
- return DispatchResult(true);
+ break;
default:
- return InsetCollapsable::priv_dispatch(cur, cmd);
+ InsetCollapsable::priv_dispatch(cur, cmd);
+ break;
}
}
bool forceDefaultParagraphs(InsetBase const *) const { return true; }
protected:
///
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
void init();
}
-DispatchResult
-InsetExternal::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetExternal::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
InsetExternalParams p;
InsetExternalMailer::string2params(cmd.argument, buffer, p);
external::editExternal(p, buffer);
- return DispatchResult(true);
+ break;
}
case LFUN_INSET_MODIFY: {
InsetExternalMailer::string2params(cmd.argument, buffer, p);
setParams(p, buffer);
cur.bv().update();
- return DispatchResult(true, true);
+ break;
}
case LFUN_INSET_DIALOG_UPDATE:
InsetExternalMailer(*this).updateDialog(&cur.bv());
- return DispatchResult(true, true);
+ break;
case LFUN_MOUSE_RELEASE:
InsetExternalMailer(*this).showDialog(&cur.bv());
- return DispatchResult(true, true);
+ break;
default:
- return DispatchResult(false);
+ InsetOld::dispatch(cur, cmd);
}
}
protected:
///
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
/** This method is connected to the graphics loader, so we are
* informed when the image has been loaded.
}
-DispatchResult
-InsetFloat::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetFloat::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
params_.wide = params.wide;
wide(params_.wide, cur.bv().buffer()->params());
cur.bv().update();
- return DispatchResult(true, true);
+ break;
}
case LFUN_INSET_DIALOG_UPDATE: {
InsetFloatMailer(*this).updateDialog(&cur.bv());
- return DispatchResult(true, true);
+ break;
}
default:
- return InsetCollapsable::priv_dispatch(cur, cmd);
+ InsetCollapsable::priv_dispatch(cur, cmd);
+ break;
}
}
///
InsetFloatParams const & params() const { return params_; }
protected:
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
InsetFloatParams params_;
}
-DispatchResult
-InsetGraphics::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetGraphics::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
setParams(p);
cur.bv().update();
}
- return DispatchResult(true, true);
+ break;
}
case LFUN_INSET_DIALOG_UPDATE:
InsetGraphicsMailer(*this).updateDialog(&cur.bv());
- return DispatchResult(true, true);
+ break;
case LFUN_MOUSE_RELEASE:
InsetGraphicsMailer(*this).showDialog(&cur.bv());
- return DispatchResult(true, true);
+ break;
default:
- return DispatchResult(false);
+ InsetOld::priv_dispatch(cur, cmd);
+ break;
}
}
void edit(LCursor & cur, bool left);
protected:
///
- DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
friend class InsetGraphicsMailer;
}
-DispatchResult
-InsetInclude::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetInclude::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
set(p, *cur.bv().buffer());
cur.bv().update();
}
- return DispatchResult(true, true);
+ break;
}
case LFUN_INSET_DIALOG_UPDATE:
InsetIncludeMailer(*this).updateDialog(&cur.bv());
- return DispatchResult(true, true);
+ break;
case LFUN_MOUSE_RELEASE:
if (button_.box().contains(cmd.x, cmd.y))
InsetIncludeMailer(*this).showDialog(&cur.bv());
- return DispatchResult(true, true);
+ break;
case LFUN_INSET_DIALOG_SHOW:
InsetIncludeMailer(*this).showDialog(&cur.bv());
- return DispatchResult(true, true);
+ break;
default:
- return DispatchResult(false);
+ InsetOld::dispatch(cur, cmd);
+ break;
}
}
void addPreview(lyx::graphics::PreviewLoader &) const;
protected:
///
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
/// Slot receiving a signal that the preview is ready to display.
void statusChanged() const;
} // namespace anon
-DispatchResult
-InsetLabel::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetLabel::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetCommandParams p;
InsetCommandMailer::string2params("label", cmd.argument, p);
- if (p.getCmdName().empty())
- return DispatchResult(false);
+ if (p.getCmdName().empty()) {
+ cur.notdispatched();
+ break;
+ }
if (p.getContents() != params().getContents())
changeRefsIfUnique(cur.bv(), params().getContents(),
p.getContents());
setParams(p);
- return DispatchResult(true, true);
+ break;
}
default:
- return InsetCommand::priv_dispatch(cur, cmd);
+ InsetCommand::priv_dispatch(cur, cmd);
+ break;
}
}
OutputParams const &) const;
protected:
///
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
};
#endif
///
InsetLatexAccent();
///
- explicit
- InsetLatexAccent(std::string const & str);
+ explicit InsetLatexAccent(std::string const & str);
///
void metrics(MetricsInfo &, Dimension &) const;
///
}
-DispatchResult
-InsetNote::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetNote::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
- case LFUN_INSET_MODIFY: {
+ case LFUN_INSET_MODIFY:
InsetNoteMailer::string2params(cmd.argument, params_);
setButtonLabel();
cur.bv().update();
- return DispatchResult(true, true);
- }
+ break;
case LFUN_INSET_DIALOG_UPDATE:
InsetNoteMailer(*this).updateDialog(&cur.bv());
- return DispatchResult(true, true);
+ break;
case LFUN_MOUSE_RELEASE:
- if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
+ if (cmd.button() == mouse_button::button3 && hitButton(cmd))
InsetNoteMailer(*this).showDialog(&cur.bv());
- return DispatchResult(true, true);
- }
- return InsetCollapsable::priv_dispatch(cur, cmd);
+ else
+ InsetCollapsable::priv_dispatch(cur, cmd);
+ break;
default:
- return InsetCollapsable::priv_dispatch(cur, cmd);
+ InsetCollapsable::priv_dispatch(cur, cmd);
+ break;
}
}
InsetNoteParams const & params() const { return params_; }
protected:
///
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
friend class InsetNoteParams;
{}
-DispatchResult InsetRef::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetRef::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
cur.bv().owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
else
InsetCommandMailer("ref", *this).showDialog(&cur.bv());
- return DispatchResult(true, true);
+ return;
case LFUN_MOUSE_RELEASE:
- return DispatchResult(true, true);
+ return;
default:
return InsetCommand::priv_dispatch(cur, cmd);
void validate(LaTeXFeatures & features) const;
protected:
///
- DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
bool isLatex;
InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
: tabular(buf.params(), max(rows, 1), max(columns, 1)),
- buffer_(&buf), cursorx_(0), cursory_(0)
+ buffer_(&buf), cursorx_(0)
{
tabular.setOwner(this);
- in_reset_pos = 0;
}
InsetTabular::InsetTabular(InsetTabular const & tab)
: UpdatableInset(tab), tabular(tab.tabular),
- buffer_(tab.buffer_), cursorx_(0), cursory_(0)
+ buffer_(tab.buffer_), cursorx_(0)
{
tabular.setOwner(this);
- in_reset_pos = 0;
}
BOOST_ASSERT(false);
}
- calculate_dimensions_of_cells(mi);
+ for (int i = 0, cell = -1; i < tabular.rows(); ++i) {
+ int maxAsc = 0;
+ int maxDesc = 0;
+ for (int j = 0; j < tabular.columns(); ++j) {
+ if (tabular.isPartOfMultiColumn(i, j))
+ continue;
+ ++cell;
+ Dimension dim;
+ MetricsInfo m = mi;
+ m.base.textwidth =
+ tabular.column_info[j].p_width.inPixels(mi.base.textwidth);
+ tabular.getCellInset(cell).metrics(m, dim);
+ maxAsc = max(maxAsc, dim.asc);
+ maxDesc = max(maxDesc, dim.des);
+ tabular.setWidthOfCell(cell, dim.wid);
+ }
+ tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT);
+ tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT);
+ }
dim.asc = tabular.getAscentOfRow(0);
dim.des = tabular.getHeightOfTabular() - tabular.getAscentOfRow(0) + 1;
x += ADD_TO_TABULAR_WIDTH;
- int cell = 0;
+ int idx = 0;
first_visible_cell = -1;
for (int i = 0; i < tabular.rows(); ++i) {
int nx = x;
- cell = tabular.getCellNumber(i, 0);
+ idx = tabular.getCellNumber(i, 0);
if (y + tabular.getDescentOfRow(i) <= 0 &&
y - tabular.getAscentOfRow(i) < pi.pain.paperHeight())
{
if (tabular.isPartOfMultiColumn(i, j))
continue;
if (first_visible_cell < 0)
- first_visible_cell = cell;
+ first_visible_cell = idx;
if (bv->cursor().selection())
- drawCellSelection(pi, nx, y, i, j, cell);
+ drawCellSelection(pi, nx, y, i, j, idx);
- int const cx = nx + tabular.getBeginningOfTextInCell(cell);
- tabular.getCellInset(cell).draw(pi, cx, y);
- drawCellLines(pi.pain, nx, y, i, cell);
- nx += tabular.getWidthOfColumn(cell);
- ++cell;
+ int const cx = nx + tabular.getBeginningOfTextInCell(idx);
+ cell(idx).draw(pi, cx, y);
+ drawCellLines(pi.pain, nx, y, i, idx);
+ nx += tabular.getWidthOfColumn(idx);
+ ++idx;
}
// Would be nice, but for some completely unfathomable reason,
}
-void InsetTabular::updateLocal(LCursor & cur) const
-{
- cur.bv().update();
- resetPos(cur);
-}
-
-
-void InsetTabular::lfunMousePress(LCursor & cur, FuncRequest const & cmd)
-{
- if (cmd.button() == mouse_button::button3)
- return;
-
- int cell = getCell(cmd.x + xo_, cmd.y + yo_);
- cur.selection() = false;
-
- lyxerr << "# InsetTabular::lfunMousePress cell: " << cell << endl;
- if (cell == -1) {
- //cur.cursor_ = theTempCursor;
- cur.push(this);
- cur.idx() = cell;
- } else {
- setPos(cur, cmd.x, cmd.y);
- //cur.cursor_ = theTempCursor;
- cur.idx() = cell;
- }
- cur.resetAnchor();
- lyxerr << cur << endl;
-
- if (cmd.button() == mouse_button::button2)
- dispatch(cur, FuncRequest(LFUN_PASTESELECTION, "paragraph"));
-}
-
-
-void InsetTabular::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
-{
- int const actcell = getCell(cmd.x + xo_, cmd.y + yo_);
- lyxerr << "# InsetTabular::lfunMouseRelease cell: " << actcell << endl;
- if (cmd.button() == mouse_button::button3)
- InsetTabularMailer(*this).showDialog(&cur.bv());
-}
-
-
void InsetTabular::edit(LCursor & cur, bool left)
{
lyxerr << "InsetTabular::edit: " << this << endl;
InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y)
{
- lyxerr << "InsetTabular::edit: " << this << endl;
+ //lyxerr << "InsetTabular::editXY: " << this << endl;
cur.selection() = false;
cur.push(this);
return setPos(cur, x, y);
//int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell);
- //if (x > xx)
- // activateCellInset(bv, cell, x - xx, y - cursory_);
}
-void InsetTabular::lfunMouseMotion(LCursor & cur, FuncRequest const & cmd)
+void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
- int const actcell = getCell(cmd.x + xo_, cmd.y + yo_);
- cur.idx() = actcell;
- lyxerr << "# InsetTabular::lfunMouseMotion cell: " << actcell << endl;
-
- setPos(cur, cmd.x, cmd.y);
-/*
- if (!hasSelection()) {
- setSelection(actcell, actcell);
- cur.setSelection();
- } else {
- setSelection(sel_cell_start, actcell);
- tablemode = (sel_cell_start != actcell);
- }
-*/
-}
-
+ lyxerr << "# InsetTabular::dispatch: cmd: " << cmd << endl;
+ //lyxerr << " cur:\n" << cur << endl;
+ CursorSlice sl = cur.current();
-DispatchResult
-InsetTabular::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
-{
- lyxerr << "# InsetTabular::dispatch: " << cmd << endl;
-
- InsetText & cell = tabular.getCellInset(cur.idx());
-
- DispatchResult result(true, true);
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
+ // we'll pop up the table dialog on release
if (cmd.button() == mouse_button::button3)
- DispatchResult(true, true);
-
- case LFUN_MOUSE_MOTION:
- lfunMouseMotion(cur, cmd);
- return DispatchResult(true, true);
-
- case LFUN_MOUSE_RELEASE:
- lfunMouseRelease(cur, cmd);
- return DispatchResult(true, true);
-
-#if 0
- int const cell = cur.idx();
- lyxerr << "# InsetTabular::dispatch: A " << cur << endl;
- result = cell.dispatch(cur, cmd);
-
- switch (result.val()) {
- case FINISHED:
- if (movePrevCell(cur))
- result = DispatchResult(true, true);
- else
- result = DispatchResult(false, FINISHED);
+ break;
+ cur.selection() = false;
+ setPos(cur, cmd.x, cmd.y);
+ cur.resetAnchor();
+ cur.bv().cursor() = cur;
+ //if (cmd.button() == mouse_button::button2)
+ // dispatch(cur, FuncRequest(LFUN_PASTESELECTION, "paragraph"));
+ //lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
break;
- case FINISHED_RIGHT:
- if (moveNextCell(cur))
- result = DispatchResult(true, true);
- else
- result = DispatchResult(false, FINISHED_RIGHT);
+ case LFUN_MOUSE_MOTION:
+ if (cmd.button() != mouse_button::button1)
+ break;
+ setPos(cur, cmd.x, cmd.y);
+ cur.bv().cursor().cursor_ = cur.cursor_;
+ cur.bv().cursor().selection() = true;
+ //lyxerr << "# InsetTabular::MouseMotion\n" << cur.bv().cursor() << endl;
break;
- case FINISHED_UP:
- if (moveUpLock(cur))
- result = DispatchResult(true, true);
- else
- result = DispatchResult(false, FINISHED_UP);
+ case LFUN_MOUSE_RELEASE:
+ //lyxerr << "# InsetTabular::MouseRelease\n" << cur.bv().cursor() << endl;
+ if (cmd.button() == mouse_button::button3)
+ InsetTabularMailer(*this).showDialog(&cur.bv());
break;
- case FINISHED_DOWN:
- if (moveDownLock(cur))
- result = DispatchResult(true, true);
- else
- result = DispatchResult(false, FINISHED_UP);
+ case LFUN_CELL_BACKWARD:
+ movePrevCell(cur);
+ cur.selection() = false;
break;
-#endif
- case LFUN_CELL_BACKWARD:
case LFUN_CELL_FORWARD:
- if (cmd.action == LFUN_CELL_FORWARD)
- moveNextCell(cur);
- else
- movePrevCell(cur);
+ moveNextCell(cur);
cur.selection() = false;
- return result;
+ break;
case LFUN_SCROLL_INSET:
- if (!cmd.argument.empty()) {
- if (cmd.argument.find('.') != cmd.argument.npos)
- scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
- else
- scroll(cur.bv(), strToInt(cmd.argument));
- cur.update();
- return DispatchResult(true, true);
- }
+ if (cmd.argument.empty())
+ break;
+ if (cmd.argument.find('.') != cmd.argument.npos)
+ scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
+ else
+ scroll(cur.bv(), strToInt(cmd.argument));
+ cur.update();
+ break;
case LFUN_RIGHTSEL:
- case LFUN_RIGHT: {
- CursorSlice sl = cur.current();
- cell.dispatch(cur, cmd);
+ case LFUN_RIGHT:
+ cell(cur.idx()).dispatch(cur, cmd);
if (sl == cur.current())
isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur);
if (sl == cur.current())
- result = DispatchResult(true, true);
+ cur.dispatched(FINISHED_RIGHT);
break;
- }
case LFUN_LEFTSEL:
- case LFUN_LEFT: {
- CursorSlice sl = cur.current();
- cell.dispatch(cur, cmd);
+ case LFUN_LEFT:
+ cell(cur.idx()).dispatch(cur, cmd);
if (sl == cur.current())
isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
if (sl == cur.current())
- result = DispatchResult(true, true);
+ cur.dispatched(FINISHED);
break;
- }
-
-#if 0
- case LFUN_DOWNSEL: {
- int const start = hasSelection() ? sel_cell_start : cur.idx();
- int const ocell = cur.idx();
- // if we are starting a selection, only select
- // the current cell at the beginning
- if (hasSelection()) {
- moveDown(cur);
- if (ocell == sel_cell_end ||
- tabular.column_of_cell(ocell) >
-tabular.column_of_cell(cur.idx()))
- //setSelection(start, tabular.getCellBelow(sel_cell_end));
- else
- //setSelection(start, tabular.getLastCellBelow(sel_cell_end));
- } else {
- //setSelection(start, start);
- }
- break;
- }
-#endif
+ case LFUN_DOWNSEL:
case LFUN_DOWN:
- if (!moveDown(cur))
- result = DispatchResult(false, FINISHED_DOWN);
- cur.selection() = false;
- break;
-
-#if 0
- case LFUN_UPSEL: {
- int const start = hasSelection() ? sel_cell_start : cur.idx();
- int const ocell = cur.idx();
- // if we are starting a selection, only select
- // the current cell at the beginning
- if (hasSelection()) {
- moveUp(cur);
- if (ocell == sel_cell_end ||
- tabular.column_of_cell(ocell) >
-tabular.column_of_cell(cur.idx()))
- //setSelection(start, tabular.getCellAbove(sel_cell_end));
- else
- //setSelection(start, tabular.getLastCellAbove(sel_cell_end));
- } else {
- //setSelection(start, start);
- }
+ cell(cur.idx()).dispatch(cur, cmd);
+ if (sl == cur.current())
+ if (tabular.row_of_cell(cur.idx()) != tabular.rows() - 1) {
+ cur.idx() = tabular.getCellBelow(cur.idx());
+ resetPos(cur);
+ }
+ if (sl == cur.current())
+ cur.dispatched(FINISHED_DOWN);
break;
- }
-#endif
+ case LFUN_UPSEL:
case LFUN_UP:
- if (!moveUp(cur))
- result = DispatchResult(false, FINISHED_DOWN);
- cur.selection() = false;
+ cell(cur.idx()).dispatch(cur, cmd);
+ if (sl == cur.current())
+ if (tabular.row_of_cell(cur.idx()) != 0) {
+ cur.idx() = tabular.getCellAbove(cur.idx());
+ resetPos(cur);
+ }
+ if (sl == cur.current())
+ cur.dispatched(FINISHED_UP);
break;
case LFUN_NEXT: {
case LFUN_TABULAR_FEATURE:
if (!tabularFeatures(cur, cmd.argument))
- result = DispatchResult(false);
+ cur.notdispatched();
break;
// insert file functions
case LFUN_FILE_INSERT_ASCII: {
string tmpstr = getContentsOfAsciiFile(&cur.bv(), cmd.argument, false);
if (!tmpstr.empty() && !insertAsciiString(cur.bv(), tmpstr, false))
- result = DispatchResult(false);
+ cur.notdispatched();
break;
}
if (tablemode(cur))
cutSelection(cur);
else
- cell.dispatch(cur, cmd);
+ cell(cur.idx()).dispatch(cur, cmd);
break;
case LFUN_COPY:
int cols = 1;
int rows = 1;
int maxCols = 1;
- string::size_type len = clip.length();
- string::size_type p = 0;
-
- while (p < len &&
- (p = clip.find_first_of("\t\n", p)) != string::npos) {
+ size_t len = clip.length();
+ for (size_t p = 0; p < len; ++p) {
+ p = clip.find_first_of("\t\n", p);
+ if (p == string::npos)
+ break;
switch (clip[p]) {
case '\t':
++cols;
cols = 1;
break;
}
- ++p;
}
maxCols = max(cols, maxCols);
string::size_type op = 0;
int cell = 0;
int cells = paste_tabular->getNumberOfCells();
- p = 0;
cols = 0;
LyXFont font;
- while (cell < cells && p < len &&
- (p = clip.find_first_of("\t\n", p)) != string::npos) {
- if (p >= len)
+ for (size_t p = 0; cell < cells && p < len; ++p) {
+ p = clip.find_first_of("\t\n", p);
+ if (p == string::npos || p >= len)
break;
switch (clip[p]) {
case '\t':
paste_tabular->getCellInset(cell).
- setText(clip.substr(op, p-op), font);
+ setText(clip.substr(op, p - op), font);
++cols;
++cell;
break;
case '\n':
paste_tabular->getCellInset(cell).
- setText(clip.substr(op, p-op), font);
+ setText(clip.substr(op, p - op), font);
while (cols++ < maxCols)
++cell;
cols = 0;
break;
}
- ++p;
- op = p;
+ op = p + 1;
}
// check for the last cell if there is no trailing '\n'
if (cell < cells && op < len)
paste_tabular->getCellInset(cell).
- setText(clip.substr(op, len-op), font);
- } else if (!insertAsciiString(cur.bv(), clip, true))
- {
+ setText(clip.substr(op, len - op), font);
+ } else if (!insertAsciiString(cur.bv(), clip, true)) {
// so that the clipboard is used and it goes on
// to default
// and executes LFUN_PASTESELECTION in insettext!
pasteSelection(cur);
break;
}
- // fall through
-
- // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
+ cell(cur.idx()).dispatch(cur, cmd);
+ break;
default:
- // handle font changing stuff on selection before we lock the inset
- // in the default part!
- result = cell.dispatch(cur, cmd);
- // we try to activate the actual inset and put this event down to
- // the insets dispatch function.
+ // we try to handle this event in the insets dispatch function.
+ cell(cur.idx()).dispatch(cur, cmd);
break;
}
- updateLocal(cur);
InsetTabularMailer(*this).updateDialog(&cur.bv());
-
- return result;
}
}
-void InsetTabular::calculate_dimensions_of_cells(MetricsInfo & mi) const
+InsetText const & InsetTabular::cell(int idx) const
{
- for (int i = 0, cell = -1; i < tabular.rows(); ++i) {
- int maxAsc = 0;
- int maxDesc = 0;
- for (int j = 0; j < tabular.columns(); ++j) {
- if (tabular.isPartOfMultiColumn(i, j))
- continue;
- ++cell;
- Dimension dim;
- MetricsInfo m = mi;
- m.base.textwidth =
- tabular.column_info[j].p_width.inPixels(mi.base.textwidth);
- tabular.getCellInset(cell).metrics(m, dim);
- maxAsc = max(maxAsc, dim.asc);
- maxDesc = max(maxDesc, dim.des);
- tabular.setWidthOfCell(cell, dim.wid);
- }
- tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT);
- tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT);
- }
+ return tabular.getCellInset(idx);
+}
+
+
+InsetText & InsetTabular::cell(int idx)
+{
+ return tabular.getCellInset(idx);
}
void InsetTabular::getCursorPos(CursorSlice const & cur, int & x, int & y) const
{
- tabular.getCellInset(cur.idx()).getCursorPos(cur, x, y);
+ cell(cur.idx()).getCursorPos(cur, x, y);
}
InsetBase * InsetTabular::setPos(LCursor & cur, int x, int y) const
{
- cur.idx() = getCell(x, y);
- InsetBase * inset = tabular.getCellInset(cur.idx()).text_.editXY(cur, x, y);
- lyxerr << "# InsetTabular::setPos() cursor: " << cur << endl;
+ int idx_min = 0;
+ int dist_min = 1000000;
+ for (idx_type i = 0; i < nargs(); ++i) {
+ int d = getText(i)->dist(x, y);
+ if (d < dist_min) {
+ dist_min = d;
+ idx_min = i;
+ }
+ }
+ cur.idx() = idx_min;
+ InsetBase * inset = cell(cur.idx()).text_.editXY(cur, x, y);
+ //lyxerr << "# InsetTabular::setPos()\n" << cur << endl;
return inset;
}
}
-void InsetTabular::resetPos(LCursor &) const
+void InsetTabular::resetPos(LCursor & cur) const
{
-#if 0
-#ifdef WITH_WARNINGS
-#warning This should be fixed in the right manner (20011128 Jug)
-#endif
- // fast hack to fix infinite repaintings!
- if (in_reset_pos > 0)
- return;
-
BufferView & bv = cur.bv();
- int cell = 0;
int actcell = cur.idx();
int actcol = tabular.column_of_cell(actcell);
- int actrow = 0;
- cursory_ = 0;
- for (; cell < actcell && !tabular.isLastRow(cell); ++cell) {
- if (tabular.isLastCellInRow(cell)) {
- cursory_ += tabular.getDescentOfRow(actrow) +
- tabular.getAscentOfRow(actrow + 1) +
- tabular.getAdditionalHeight(actrow + 1);
- ++actrow;
- }
- }
- // we need this only from here on!!!
- ++in_reset_pos;
int const offset = ADD_TO_TABULAR_WIDTH + 2;
int new_x = getCellXPos(actcell) + offset;
int old_x = cursorx_;
tabular.getWidthOfTabular() < bv.workWidth()-20)
{
scroll(bv, 0.0F);
- updateLocal(cur);
} else if (cursorx_ - offset > 20 &&
cursorx_ - offset + tabular.getWidthOfColumn(actcell)
> bv.workWidth() - 20) {
scroll(bv, - tabular.getWidthOfColumn(actcell) - 20);
- updateLocal(cur);
} else if (cursorx_ - offset < 20) {
scroll(bv, 20 - cursorx_ + offset);
- updateLocal(cur);
} else if (scroll() && xo_ > 20 &&
xo_ + tabular.getWidthOfTabular() > bv.workWidth() - 20) {
scroll(bv, old_x - cursorx_);
- updateLocal(cur);
}
- InsetTabularMailer(*this).updateDialog(&bv);
- in_reset_pos = 0;
-#endif
-}
-
-
-bool InsetTabular::moveRight(LCursor & cur)
-{
- bool moved = isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur);
- if (!moved)
- return false;
- resetPos(cur);
- return true;
-}
-
-
-bool InsetTabular::moveLeft(LCursor & cur)
-{
- bool moved = isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
- if (!moved)
- return false;
- resetPos(cur);
- return true;
-}
-
-
-bool InsetTabular::moveLeftLock(LCursor & cur)
-{
- bool moved = isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
- if (!moved)
- return false;
- activateCellInset(cur, cur.idx(), true);
- return true;
-}
-
-bool InsetTabular::moveUp(LCursor & cur)
-{
- if (tabular.row_of_cell(cur.idx()) == 0)
- return false;
- cur.idx() = tabular.getCellAbove(cur.idx());
- resetPos(cur);
- return true;
-}
-
-
-bool InsetTabular::moveUpLock(LCursor & cur)
-{
- if (tabular.row_of_cell(cur.idx()) == 0)
- return false;
- cur.idx() = tabular.getCellAbove(cur.idx());
- resetPos(cur);
- activateCellInset(cur, cur.idx(), cur.x_target(), 0);
- return true;
-}
-
-
-bool InsetTabular::moveDown(LCursor & cur)
-{
- if (tabular.row_of_cell(cur.idx()) == tabular.rows() - 1)
- return false;
- cur.idx() = tabular.getCellBelow(cur.idx());
- resetPos(cur);
- return true;
-}
-
-
-bool InsetTabular::moveDownLock(LCursor & cur)
-{
- if (tabular.row_of_cell(cur.idx()) == tabular.rows() - 1)
- return false;
- cur.idx() = tabular.getCellBelow(cur.idx());
- resetPos(cur);
- activateCellInset(cur, cur.idx(), cur.x_target());
- return true;
+ InsetTabularMailer(*this).updateDialog(&bv);
}
-bool InsetTabular::moveNextCell(LCursor & cur)
+void InsetTabular::moveNextCell(LCursor & cur)
{
lyxerr << "InsetTabular::moveNextCell 1 cur: " << cur << endl;
if (isRightToLeft(cur)) {
if (tabular.isFirstCellInRow(cur.idx())) {
int row = tabular.row_of_cell(cur.idx());
if (row == tabular.rows() - 1)
- return false;
+ return;
cur.idx() = tabular.getLastCellInRow(row);
cur.idx() = tabular.getCellBelow(cur.idx());
} else {
if (cur.idx() == 0)
- return false;
+ return;
--cur.idx();
}
} else {
if (tabular.isLastCell(cur.idx()))
- return false;
+ return;
++cur.idx();
}
cur.par() = 0;
cur.pos() = 0;
lyxerr << "InsetTabular::moveNextCell 2 cur: " << cur << endl;
resetPos(cur);
- return true;
}
-bool InsetTabular::movePrevCell(LCursor & cur)
+void InsetTabular::movePrevCell(LCursor & cur)
{
if (isRightToLeft(cur)) {
if (tabular.isLastCellInRow(cur.idx())) {
int row = tabular.row_of_cell(cur.idx());
if (row == 0)
- return false;
+ return;
cur.idx() = tabular.getFirstCellInRow(row);
cur.idx() = tabular.getCellAbove(cur.idx());
} else {
if (tabular.isLastCell(cur.idx()))
- return false;
+ return;
++cur.idx();
}
} else {
if (cur.idx() == 0) // first cell
- return false;
+ return;
--cur.idx();
}
cur.par() = 0;
cur.pos() = 0;
resetPos(cur);
- return true;
}
break;
}
- updateLocal(cur);
InsetTabularMailer(*this).updateDialog(&bv);
}
-void InsetTabular::activateCellInset(LCursor & cur, int cell, int x, int y)
-{
- cur.idx() = cell;
- tabular.getCellInset(cell).editXY(cur, x, y);
- updateLocal(cur);
-}
-
-
-void InsetTabular::activateCellInset(LCursor & cur, int cell, bool behind)
-{
- cur.idx() = cell;
- tabular.getCellInset(cell).edit(cur, behind);
- updateLocal(cur);
-}
-
-
bool InsetTabular::showInsetDialog(BufferView * bv) const
{
InsetTabularMailer(*this).showDialog(bv);
getSelection(cur, rs, re, cs, ce);
for (int i = rs; i <= re; ++i)
for (int j = cs; j <= ce; ++j)
- tabular.getCellInset(tabular.getCellNumber(i, j)).clear(track);
+ cell(tabular.getCellNumber(i, j)).clear(track);
}
}
-int InsetTabular::numParagraphs() const
+size_t InsetTabular::nargs() const
{
return tabular.getNumberOfCells();
}
-LyXText * InsetTabular::getText(int i) const
+LyXText * InsetTabular::getText(int idx) const
{
- return i < tabular.getNumberOfCells()
- ? tabular.getCellInset(i).getText(0)
- : 0;
+ return size_t(idx) < nargs() ? cell(idx).getText(0) : 0;
}
void InsetTabular::markErased()
{
- for (int cell = 0; cell < tabular.getNumberOfCells(); ++cell)
- tabular.getCellInset(cell).markErased();
+ for (idx_type idx = 0; idx < nargs(); ++idx)
+ cell(idx).markErased();
}
}
+
+
+
string const InsetTabularMailer::name_("tabular");
InsetTabularMailer::InsetTabularMailer(InsetTabular const & inset)
*
* Full author contact details are available in file CREDITS.
*/
-// This is the rewrite of the tabular (table) support.
-
-// It will probably be a lot of work.
-// One first goal could be to make the inset read the old table format
-// and just output it again... no viewing at all.
-// When making the internal structure of tabular support I really think
-// that STL containers should be used. This will separate the container from
-// the rest of the code, which is a good thing.
+// This is the rewrite of the tabular (table) support.
// Ideally the tabular support should do as the mathed and use
// LaTeX in the .lyx file too.
-// Things to think of when desingning the new tabular support:
+// Things to think of when designing the new tabular support:
// - color support (colortbl, color)
// - decimal alignment (dcloumn)
// - custom lines (hhline)
#include "inset.h"
#include "tabular.h"
-#include "frontends/mouse_state.h"
-
-
class FuncStatus;
class LyXLex;
class Painter;
///
std::string const editMessage() const;
///
- void updateLocal(LCursor & cur) const;
- ///
bool insetAllowed(InsetOld::Code) const { return true; }
///
bool isTextInset() const { return true; }
std::string const & argument, int cell) const;
/// Appends \c list with all labels found within this inset.
void getLabelList(Buffer const &, std::vector<std::string> & list) const;
+ /// number of cells
+ size_t nargs() const;
///
- int numParagraphs() const;
+ InsetText const & cell(int) const;
+ ///
+ InsetText & cell(int);
///
LyXText * getText(int) const;
protected:
///
- DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
- ///
- void lfunMousePress(LCursor & cur, FuncRequest const & cmd);
- ///
- void lfunMouseRelease(LCursor & cur, FuncRequest const & cmd);
- ///
- void lfunMouseMotion(LCursor & cur, FuncRequest const & cmd);
- ///
- void calculate_dimensions_of_cells(MetricsInfo & mi) const;
///
void drawCellLines(Painter &, int x, int baseline,
- int row, int cell) const;
+ int row, int cell) const;
///
void drawCellSelection(PainterInfo &, int x, int baseline,
- int row, int column, int cell) const;
+ int row, int column, int cell) const;
///
InsetBase * setPos(LCursor & cur, int x, int y) const;
- ///
- bool moveRight(LCursor & cur);
- ///
- bool moveLeft(LCursor & cur);
- ///
- bool moveUp(LCursor & cur);
- ///
- bool moveDown(LCursor & cur);
///
- bool moveRightLock(LCursor & cur);
+ void moveNextCell(LCursor & cur);
///
- bool moveLeftLock(LCursor & cur);
- ///
- bool moveUpLock(LCursor & cur);
- ///
- bool moveDownLock(LCursor & cur);
-
- ///
- bool moveNextCell(LCursor & cur);
- ///
- bool movePrevCell(LCursor & cur);
-
-
+ void movePrevCell(LCursor & cur);
///
int getCellXPos(int cell) const;
///
///
void removeTabularRow();
///
- //void clearSelection() const;
- ///
- //void setSelection(int start, int end) const;
- ///
- void activateCellInset(LCursor &, int cell, int x, int y);
- ///
- void activateCellInset(LCursor &, int cell, bool behind);
- ///
bool hasPasteBuffer() const;
///
bool copySelection(LCursor & cur);
int & rs, int & re, int & cs, int & ce) const;
///
bool insertAsciiString(BufferView &, std::string const & buf, bool usePaste);
-
/// are we operating on several cells?
bool tablemode(LCursor & cur) const;
- //
- // Private structures and variables
///
Buffer const * buffer_;
///
mutable int cursorx_;
///
- mutable int cursory_;
- /// true if a set of cells are selected
- //mutable bool has_selection;
- /// the starting cell selection nr
- //mutable int sel_cell_start;
- /// the ending cell selection nr
- //mutable int sel_cell_end;
- ///
mutable int first_visible_cell;
- ///
- mutable int in_reset_pos;
};
}
-DispatchResult InsetText::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetText::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
//lyxerr << "InsetText::priv_dispatch (begin), act: "
// << cmd.action << " " << endl;
setViewCache(&cur.bv());
bool was_empty = paragraphs().begin()->empty() && paragraphs().size() == 1;
- DispatchResult result = text_.dispatch(cur, cmd);
+ text_.dispatch(cur, cmd);
// If the action has deleted all text in the inset, we need
// to change the language to the language of the surronding
}
//lyxerr << "InsetText::priv_dispatch (end)" << endl;
- return result;
}
///
InsetBase * editXY(LCursor & cur, int x, int y);
- ///
- int numParagraphs() const { return 1; }
+ /// number of cells in this inset
+ size_t nargs() const { return 1; }
///
ParagraphList & paragraphs() const;
private:
///
- DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
///
void updateLocal(LCursor &);
///
}
-DispatchResult
-InsetVSpace::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetVSpace::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetVSpaceMailer::string2params(cmd.argument, space_);
- return DispatchResult(true, true);
+ break;
}
case LFUN_MOUSE_PRESS:
InsetVSpaceMailer(*this).showDialog(&cur.bv());
- return DispatchResult(true, true);
+ break;
default:
- return InsetOld::priv_dispatch(cur, cmd);
+ InsetOld::priv_dispatch(cur, cmd);
+ break;
}
}
protected:
///
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
}
-DispatchResult
-InsetWrap::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void InsetWrap::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetWrapParams params;
InsetWrapMailer::string2params(cmd.argument, params);
-
params_.placement = params.placement;
params_.width = params.width;
-
cur.bv().update();
- return DispatchResult(true, true);
+ break;
}
case LFUN_INSET_DIALOG_UPDATE:
InsetWrapMailer(*this).updateDialog(&cur.bv());
- return DispatchResult(true, true);
+ break;
default:
- return InsetCollapsable::priv_dispatch(cur, cmd);
+ InsetCollapsable::priv_dispatch(cur, cmd);
+ break;
}
}
InsetWrapParams const & params() const { return params_; }
protected:
///
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ virtual void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
InsetWrapParams params_;
}
-/// An updatable inset could handle lyx editing commands
-DispatchResult
-UpdatableInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void UpdatableInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
- case LFUN_MOUSE_RELEASE:
- return DispatchResult(editable() == IS_EDITABLE);
+ //case LFUN_MOUSE_RELEASE:
+ // return DispatchResult(editable() == IS_EDITABLE);
case LFUN_SCROLL_INSET:
- if (!cmd.argument.empty()) {
+ if (cmd.argument.empty()) {
if (cmd.argument.find('.') != cmd.argument.npos)
scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
else
scroll(cur.bv(), strToInt(cmd.argument));
cur.bv().update();
- return DispatchResult(true, true);
}
+ break;
default:
- return DispatchResult(false);
+ InsetOld::dispatch(cur, cmd);
}
}
protected:
/// An updatable inset could handle lyx editing commands
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
/// scrolls to absolute position in bufferview-workwidth * sx units
void scroll(BufferView &, float sx) const;
/// scrolls offset pixels
void draw(PainterInfo & pi, int x, int y) const;
/// draw textselection
void drawSelection(PainterInfo & pi, int x, int y) const;
+ /// returns distance of this cell to the point given by x and y
+ // assumes valid position and size cache
+ int dist(int x, int y) const;
/// try to handle that request
DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
double spacing(Paragraph const & par) const;
/// make a suggestion for a label
std::string getPossibleLabel(LCursor & cur) const;
+ /// is this paragraph right-to-left?
+ bool isRTL(Paragraph const & par) const;
///
DispatchResult moveRight(LCursor & cur);
void charInserted();
/// set 'number' font property
void number(LCursor & cur);
- /// is the cursor paragraph right-to-left?
- bool rtl(LCursor & cur) const;
};
/// return the default height of a row in pixels, considering font zoom
+
2004-02-04 Martin Vermeer <martin.vermeer@hut.fi>
* math_nestinset.C: workaround gcc 2.95 pointer comparison bug,
}
-DispatchResult
-CommandInset::priv_dispatch(LCursor & bv, FuncRequest const & cmd)
-{
- switch (cmd.action) {
- default:
- return MathNestInset::priv_dispatch(bv, cmd);
- }
- return DispatchResult(false);
-}
-
-
void CommandInset::write(WriteStream & os) const
{
os << '\\' << name_.c_str();
#define COMMAND_INSET_H
#include "math_nestinset.h"
+
#include "insets/render_button.h"
std::string const createDialogStr(std::string const & name) const;
std::string const & commandname() const { return name_; }
-protected:
- ///
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
std::string name_;
mutable bool set_label_;
#include "BufferView.h"
#include "cursor.h"
-#include "dispatchresult.h"
#include "debug.h"
#include "funcrequest.h"
#include "gettext.h"
#include "math_streamstr.h"
#include "BufferView.h"
#include "cursor.h"
-#include "dispatchresult.h"
#include "debug.h"
#include "funcrequest.h"
#include "LColor.h"
}
-DispatchResult
-MathGridInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
//lyxerr << "*** MathGridInset: request: " << cmd << endl;
switch (cmd.action) {
// GridInsetMailer(*this).showDialog();
// return DispatchResult(true, true);
//}
- return MathNestInset::priv_dispatch(cur, cmd);
+ MathNestInset::priv_dispatch(cur, cmd);
+ return;
case LFUN_INSET_DIALOG_UPDATE:
GridInsetMailer(*this).updateDialog(&cur.bv());
- return DispatchResult(false);
+ return;
// insert file functions
case LFUN_DELETE_LINE_FORWARD:
cur.idx() = cur.lastidx();
if (cur.pos() > cur.lastpos())
cur.pos() = cur.lastpos();
- return DispatchResult(true, FINISHED);
+ return;
case LFUN_CELL_SPLIT:
////recordUndo(cur, Undo::ATOMIC);
splitCell(cur);
- return DispatchResult(true, FINISHED);
+ return;
case LFUN_BREAKLINE: {
////recordUndo(cur, Undo::INSERT);
cur.idx() = cur.lastpos();
//mathcursor->normalize();
- return DispatchResult(true, FINISHED);
+ cur.dispatched(FINISHED);
+ return;
}
case LFUN_TABULAR_FEATURE: {
copyCol(col(cur.idx()));
else if (s == "swap-column")
swapCol(col(cur.idx()));
- else
- return DispatchResult(false);
+ else {
+ cur.notdispatched();
+ return;
+ }
lyxerr << "returning DispatchResult(true, FINISHED)" << endl;
- return DispatchResult(true, FINISHED);
+ return;
}
case LFUN_PASTE: {
cur.pos() += grid.cell(0).size();
} else {
// multiple cells
- col_type const numcols = min(grid.ncols(), ncols() -
-col(cur.idx()));
- row_type const numrows = min(grid.nrows(), nrows() -
-cur.row());
+ col_type const numcols =
+ min(grid.ncols(), ncols() - col(cur.idx()));
+ row_type const numrows =
+ min(grid.nrows(), nrows() - cur.row());
for (row_type r = 0; r < numrows; ++r) {
for (col_type c = 0; c < numcols; ++c) {
idx_type i = index(r + cur.row(), c + col(cur.idx()));
for (col_type c = 0; c < grid.ncols(); ++c)
cell(i).append(grid.cell(grid.index(r, c)));
}
- return DispatchResult(true, FINISHED);
+ return;
}
default:
- return MathNestInset::priv_dispatch(cur, cmd);
+ MathNestInset::priv_dispatch(cur, cmd);
+ return;
}
}
protected:
///
- DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
/// returns x offset of cell compared to inset
int cellXOffset(idx_type idx) const;
/// returns y offset of cell compared to inset
}
-DispatchResult
-MathHullInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
//lyxerr << "*** MathHullInset: request: " << cmd << endl;
switch (cmd.action) {
- case LFUN_BREAKLINE:
- if (type_ == "simple" || type_ == "equation") {
- mutate("eqnarray");
- cur.idx() = 1;
- cur.pos() = 0;
- return DispatchResult(true, FINISHED);
- }
- return MathGridInset::priv_dispatch(cur, cmd);
-
- case LFUN_MATH_NUMBER:
- //lyxerr << "toggling all numbers" << endl;
- if (display()) {
- ////recordUndo(cur, Undo::INSERT);
- bool old = numberedType();
- if (type_ == "multline")
- numbered(nrows() - 1, !old);
- else
- for (row_type row = 0; row < nrows(); ++row)
- numbered(row, !old);
- cur.message(old ? _("No number") : _("Number"));
- }
- return DispatchResult(true, true);
-
- case LFUN_MATH_NONUMBER:
- if (display()) {
- row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
- ////recordUndo(cur, Undo::INSERT);
- bool old = numbered(r);
- cur.message(old ? _("No number") : _("Number"));
- numbered(r, !old);
- }
- return DispatchResult(true, true);
-
- case LFUN_INSERT_LABEL: {
- row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
- string old_label = label(r);
- string new_label = cmd.argument;
-
- if (new_label.empty()) {
- string const default_label =
- (lyxrc.label_init_length >= 0) ? "eq:" : "";
- pair<bool, string> const res = old_label.empty()
- ? Alert::askForText(_("Enter new label to insert:"), default_label)
- : Alert::askForText(_("Enter label:"), old_label);
- if (!res.first)
- return DispatchResult(false);
- new_label = lyx::support::trim(res.second);
- }
+ case LFUN_BREAKLINE:
+ if (type_ == "simple" || type_ == "equation") {
+ mutate("eqnarray");
+ cur.idx() = 1;
+ cur.pos() = 0;
+ //cur.dispatched(FINISHED);
+ return;
+ }
+ MathGridInset::priv_dispatch(cur, cmd);
+ return;
- //if (new_label == old_label)
- // break; // Nothing to do
+ case LFUN_MATH_NUMBER:
+ //lyxerr << "toggling all numbers" << endl;
+ if (display()) {
+ ////recordUndo(cur, Undo::INSERT);
+ bool old = numberedType();
+ if (type_ == "multline")
+ numbered(nrows() - 1, !old);
+ else
+ for (row_type row = 0; row < nrows(); ++row)
+ numbered(row, !old);
+ cur.message(old ? _("No number") : _("Number"));
+ }
+ return;
- if (!new_label.empty())
- numbered(r, true);
- label(r, new_label);
- return DispatchResult(true, true);
+ case LFUN_MATH_NONUMBER:
+ if (display()) {
+ row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
+ ////recordUndo(cur, Undo::INSERT);
+ bool old = numbered(r);
+ cur.message(old ? _("No number") : _("Number"));
+ numbered(r, !old);
}
+ return;
- case LFUN_MATH_EXTERN:
- doExtern(cur, cmd);
- return DispatchResult(true, FINISHED);
-
- case LFUN_MATH_MUTATE: {
- lyxerr << "Hull: MUTATE: " << cmd.argument << endl;
- row_type r = cur.row();
- col_type c = cur.col();
- mutate(cmd.argument);
- cur.idx() = r * ncols() + c;
- if (cur.idx() >= nargs())
- cur.idx() = nargs() - 1;
- if (cur.pos() > cur.lastpos())
- cur.pos() = cur.lastpos();
- return DispatchResult(true, FINISHED);
+ case LFUN_INSERT_LABEL: {
+ row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
+ string old_label = label(r);
+ string new_label = cmd.argument;
+
+ if (new_label.empty()) {
+ string const default_label =
+ (lyxrc.label_init_length >= 0) ? "eq:" : "";
+ pair<bool, string> const res = old_label.empty()
+ ? Alert::askForText(_("Enter new label to insert:"), default_label)
+ : Alert::askForText(_("Enter label:"), old_label);
+ new_label = lyx::support::trim(res.second);
}
- case LFUN_MATH_DISPLAY: {
- mutate(type_ == "simple" ? "equation" : "simple");
- cur.idx() = 0;
+ if (!new_label.empty())
+ numbered(r, true);
+ label(r, new_label);
+ return;
+ }
+
+ case LFUN_MATH_EXTERN:
+ doExtern(cur, cmd);
+ //cur.dispatched(FINISHED);
+ return;
+
+ case LFUN_MATH_MUTATE: {
+ lyxerr << "Hull: MUTATE: " << cmd.argument << endl;
+ row_type r = cur.row();
+ col_type c = cur.col();
+ mutate(cmd.argument);
+ cur.idx() = r * ncols() + c;
+ if (cur.idx() >= nargs())
+ cur.idx() = nargs() - 1;
+ if (cur.pos() > cur.lastpos())
cur.pos() = cur.lastpos();
- return DispatchResult(true, FINISHED);
- }
+ //cur.dispatched(FINISHED);
+ return;
+ }
+
+ case LFUN_MATH_DISPLAY: {
+ mutate(type_ == "simple" ? "equation" : "simple");
+ cur.idx() = 0;
+ cur.pos() = cur.lastpos();
+ //cur.dispatched(FINISHED);
+ return;
+ }
- default:
- return MathGridInset::priv_dispatch(cur, cmd);
+ default:
+ MathGridInset::priv_dispatch(cur, cmd);
+ return;
}
}
protected:
///
- DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
///
std::string eolString(row_type row, bool fragile) const;
}
-DispatchResult MathMBoxInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void MathMBoxInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
- return text_.dispatch(cur, cmd);
+ text_.dispatch(cur, cmd);
}
/// draw according to cached metrics
void draw(PainterInfo &, int x, int y) const;
///
- DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
///
void write(WriteStream & os) const;
}
-DispatchResult
-MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
lyxerr << "MathNestInset: request: " << cmd << std::endl;
cur.cell().insert(cur.pos(), ar);
cur.pos() += ar.size();
}
- return DispatchResult(true, true);
+ break;
/*
case LFUN_PASTE: {
size_t n = 0;
cur.macroModeClose();
//recordUndo(cur, Undo::ATOMIC);
cur.selPaste(n);
- return DispatchResult(true, true);
+ break;
}
*/
case LFUN_PASTESELECTION:
- return dispatch(cur, FuncRequest(LFUN_PASTE, cur.bv().getClipboard()));
+ dispatch(cur, FuncRequest(LFUN_PASTE, cur.bv().getClipboard()));
+ break;
case LFUN_MOUSE_PRESS:
- return lfunMousePress(cur, cmd);
+ lfunMousePress(cur, cmd);
+ break;
+
case LFUN_MOUSE_MOTION:
- return lfunMouseMotion(cur, cmd);
+ lfunMouseMotion(cur, cmd);
+ break;
+
case LFUN_MOUSE_RELEASE:
- return lfunMouseRelease(cur, cmd);
+ lfunMouseRelease(cur, cmd);
+ break;
+
case LFUN_MOUSE_DOUBLE:
case LFUN_MOUSE_TRIPLE:
//lyxerr << "Mouse double" << endl;
//lyxerr << "Mouse triple" << endl;
- return dispatch(cur, FuncRequest(LFUN_WORDSEL));
+ dispatch(cur, FuncRequest(LFUN_WORDSEL));
+ break;
+
+ case LFUN_FINISHED_LEFT:
+ cur.pop(cur.currentDepth());
+ cur.bv().cursor() = cur;
+ break;
+
+ case LFUN_FINISHED_RIGHT:
+ cur.pop(cur.currentDepth());
+ ++cur.pos();
+ cur.bv().cursor() = cur;
+ break;
+
+ case LFUN_FINISHED_UP:
+ cur.pop(cur.currentDepth());
+ //idxUpDown(cur, true);
+ cur.bv().cursor() = cur;
+ break;
+
+ case LFUN_FINISHED_DOWN:
+ cur.pop(cur.currentDepth());
+ //idxUpDown(cur, false);
+ cur.bv().cursor() = cur;
+ break;
case LFUN_RIGHTSEL:
case LFUN_RIGHT:
cur.selHandle(cmd.action == LFUN_RIGHTSEL);
- return cur.right() ?
- DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
+ if (!cur.right())
+ cur.dispatched(FINISHED_RIGHT);
+ break;
case LFUN_LEFTSEL:
case LFUN_LEFT:
cur.selHandle(cmd.action == LFUN_LEFTSEL);
- return cur.left() ?
- DispatchResult(true, true) : DispatchResult(false, FINISHED);
+ if (!cur.left())
+ cur.dispatched(FINISHED);
+ break;
case LFUN_UPSEL:
case LFUN_UP:
cur.selHandle(cmd.action == LFUN_UPSEL);
- return cur.up() ?
- DispatchResult(true, true) : DispatchResult(false, FINISHED_UP);
+ if (!cur.up())
+ cur.dispatched(FINISHED_UP);
+ break;
case LFUN_DOWNSEL:
case LFUN_DOWN:
cur.selHandle(cmd.action == LFUN_DOWNSEL);
- return cur.down() ?
- DispatchResult(true, true) : DispatchResult(false, FINISHED_DOWN);
+ if (!cur.down())
+ cur.dispatched(FINISHED_DOWN);
+ break;
case LFUN_WORDSEL:
cur.home();
cur.resetAnchor();
cur.selection() = true;
cur.end();
- return DispatchResult(true, true);
+ break;
case LFUN_UP_PARAGRAPHSEL:
case LFUN_UP_PARAGRAPH:
case LFUN_DOWN_PARAGRAPHSEL:
case LFUN_DOWN_PARAGRAPH:
- return DispatchResult(true, FINISHED);
+ break;
case LFUN_WORDLEFTSEL:
case LFUN_WORDLEFT:
cur.selHandle(cmd.action == LFUN_WORDLEFTSEL);
- return cur.home()
- ? DispatchResult(true, true) : DispatchResult(true, FINISHED);
+ if (!cur.home())
+ cur.dispatched(FINISHED);
+ break;
case LFUN_WORDRIGHTSEL:
case LFUN_WORDRIGHT:
cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL);
- return cur.end()
- ? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
+ if (!cur.end())
+ cur.dispatched(FINISHED_RIGHT);
+ break;
case LFUN_HOMESEL:
case LFUN_HOME:
cur.selHandle(cmd.action == LFUN_HOMESEL);
- return cur.home()
- ? DispatchResult(true, true) : DispatchResult(true, FINISHED);
+ if (!cur.home())
+ cur.dispatched(FINISHED_RIGHT);
+ break;
case LFUN_ENDSEL:
case LFUN_END:
cur.selHandle(cmd.action == LFUN_ENDSEL);
- return cur.end()
- ? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
+ if (!cur.end())
+ cur.dispatched(FINISHED_RIGHT);
+ break;
case LFUN_PRIORSEL:
case LFUN_PRIOR:
case LFUN_BEGINNINGBUFSEL:
case LFUN_BEGINNINGBUF:
- return DispatchResult(true, FINISHED);
+ cur.dispatched(FINISHED);
+ break;
case LFUN_NEXTSEL:
case LFUN_NEXT:
case LFUN_ENDBUFSEL:
case LFUN_ENDBUF:
- return DispatchResult(false, FINISHED_RIGHT);
+ cur.dispatched(FINISHED_RIGHT);
+ break;
case LFUN_CELL_FORWARD:
cur.inset()->idxNext(cur);
- return DispatchResult(true, true);
+ break;
case LFUN_CELL_BACKWARD:
cur.inset()->idxPrev(cur);
- return DispatchResult(true, true);
+ break;
case LFUN_DELETE_WORD_BACKWARD:
case LFUN_BACKSPACE:
//recordUndo(cur, Undo::ATOMIC);
cur.backspace();
- return DispatchResult(true, true);
+ break;
case LFUN_DELETE_WORD_FORWARD:
case LFUN_DELETE:
//recordUndo(cur, Undo::ATOMIC);
cur.erase();
- return DispatchResult(true, FINISHED);
+ cur.dispatched(FINISHED);
+ break;
case LFUN_ESCAPE:
- if (!cur.selection())
- return DispatchResult(true, true);
- cur.selClear();
- return DispatchResult(false);
+ if (cur.selection())
+ cur.selClear();
+ else
+ cur.dispatched(FINISHED);
+ break;
case LFUN_INSET_TOGGLE:
cur.lockToggle();
- return DispatchResult(true, true);
+ break;
case LFUN_SELFINSERT:
- if (!cmd.argument.empty()) {
- //recordUndo(cur, Undo::ATOMIC);
- if (cmd.argument.size() == 1) {
- if (cur.interpret(cmd.argument[0]))
- return DispatchResult(true, true);
- else
- return DispatchResult(false, FINISHED_RIGHT);
- }
+ if (cmd.argument.empty()) {
+ cur.dispatched(FINISHED_RIGHT);
+ break;
+ }
+ //recordUndo(cur, Undo::ATOMIC);
+ if (cmd.argument.size() != 1) {
cur.insert(cmd.argument);
+ break;
}
- return DispatchResult(false, FINISHED_RIGHT);
-
+ if (!cur.interpret(cmd.argument[0]))
+ cur.dispatched(FINISHED_RIGHT);
+ break;
#if 0
//
istringstream is(cmd.argument.c_str());
is >> x >> y;
cur.setScreenPos(x, y);
- return DispatchResult(true, true);
+ break;
}
case LFUN_CUT:
//recordUndo(cur, Undo::DELETE);
cur.selCut();
- return DispatchResult(true, true);
+ break;
case LFUN_COPY:
cur.selCopy();
- return DispatchResult(true, true);
-
+ break;
// Special casing for superscript in case of LyX handling
// dead-keys:
//recordUndo(cur, Undo::ATOMIC);
cur.script(true);
}
- return DispatchResult(true, true);
+ break;
case LFUN_UMLAUT:
case LFUN_ACUTE:
case LFUN_TIE:
case LFUN_OGONEK:
case LFUN_HUNG_UMLAUT:
- return DispatchResult(true, true);
+ break;
// Math fonts
case LFUN_FREEFONT_APPLY:
case LFUN_FREEFONT_UPDATE:
handleFont2(cur, cmd.argument);
- return DispatchResult(true, true);
+ break;
case LFUN_BOLD:
handleFont(cur, cmd.argument, "mathbf");
- return DispatchResult(true, true);
+ break;
case LFUN_SANS:
handleFont(cur, cmd.argument, "mathsf");
- return DispatchResult(true, true);
+ break;
case LFUN_EMPH:
handleFont(cur, cmd.argument, "mathcal");
- return DispatchResult(true, true);
+ break;
case LFUN_ROMAN:
handleFont(cur, cmd.argument, "mathrm");
- return DispatchResult(true, true);
+ break;
case LFUN_CODE:
handleFont(cur, cmd.argument, "texttt");
- return DispatchResult(true, true);
+ break;
case LFUN_FRAK:
handleFont(cur, cmd.argument, "mathfrak");
- return DispatchResult(true, true);
+ break;
case LFUN_ITAL:
handleFont(cur, cmd.argument, "mathit");
- return DispatchResult(true, true);
+ break;
case LFUN_NOUN:
handleFont(cur, cmd.argument, "mathbb");
- return DispatchResult(true, true);
+ break;
//case LFUN_FREEFONT_APPLY:
handleFont(cur, cmd.argument, "textrm");
- return DispatchResult(true, true);
+ break;
case LFUN_DEFAULT:
handleFont(cur, cmd.argument, "textnormal");
- return DispatchResult(true, true);
+ break;
case LFUN_MATH_MODE:
#if 1
handleFont(cur, cmd.argument, "textrm");
//cur.owner()->message(_("math text mode toggled"));
#endif
- return DispatchResult(true, true);
+ break;
case LFUN_MATH_SIZE:
#if 0
cur.setSize(arg);
}
#endif
- return DispatchResult(true, true);
+ break;
case LFUN_INSERT_MATRIX: {
//recordUndo(cur, Undo::ATOMIC);
v_align += 'c';
cur.niceInsert(
MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
- return DispatchResult(true, true);
+ break;
}
case LFUN_MATH_DELIM: {
rs = ')';
//recordUndo(cur, Undo::ATOMIC);
cur.handleNest(MathAtom(new MathDelimInset(ls, rs)));
- return DispatchResult(true, true);
+ break;
}
case LFUN_SPACE_INSERT:
case LFUN_MATH_SPACE:
//recordUndo(cur, Undo::ATOMIC);
cur.insert(MathAtom(new MathSpaceInset(",")));
- return DispatchResult(true, true);
+ break;
case LFUN_UNDO:
#warning look here
//cur.bv().owner()->message(_("Invalid action in math mode!"));
- return DispatchResult(true, true);
+ break;
case LFUN_INSET_ERT:
// interpret this as if a backslash was typed
//recordUndo(cur, Undo::ATOMIC);
cur.interpret('\\');
- return DispatchResult(true, true);
+ break;
// FIXME: We probably should swap parts of "math-insert" and "self-insert"
// handling such that "self-insert" works on "arbitrary stuff" too, and
case LFUN_INSERT_MATH:
//recordUndo(cur, Undo::ATOMIC);
cur.niceInsert(cmd.argument);
- return DispatchResult(true, true);
-
- case LFUN_DIALOG_SHOW:
- return DispatchResult(false);
+ break;
case LFUN_DIALOG_SHOW_NEW_INSET: {
string const & name = cmd.argument;
data = tmp.createDialogStr(name);
}
#endif
- if (data.empty())
- return DispatchResult(false);
cur.bv().owner()->getDialogs().show(name, data, 0);
- return DispatchResult(true, true);
+ break;
}
case LFUN_INSET_APPLY: {
InsetBase * base = cur.bv().owner()->getDialogs().getOpenInset(name);
if (base) {
- FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
- return base->dispatch(cur, fr);
+ base->dispatch(cur, FuncRequest(LFUN_INSET_MODIFY, cmd.argument));
+ break;
}
MathArray ar;
if (createMathInset_fromDialogStr(cmd.argument, ar)) {
cur.insert(ar);
- return DispatchResult(true, true);
+ break;
}
- return DispatchResult(false);
+ cur.notdispatched();
+ break;
}
#warning look here
case LFUN_WORD_REPLACE:
case LFUN_WORD_FIND:
- return
- searchForward(&cur.bv(), cmd.getArg(0), false, false)
- ? DispatchResult(true, true) : DispatchResult(false);
+ if (!searchForward(&cur.bv(), cmd.getArg(0), false, false))
+ cur.notdispatched();
+ break;
cur.normalize();
cur.touch();
if (remove_inset)
cur.bv().owner()->dispatch(FuncRequest(LFUN_DELETE));
}
-
- return result; // original version
+ break;
#endif
default:
- return MathDimInset::priv_dispatch(cur, cmd);
+ MathDimInset::priv_dispatch(cur, cmd);
+ break;
}
}
}
-DispatchResult
-MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
+void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
{
//lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
if (cmd.button() == mouse_button::button1) {
// try to dispatch to enclosed insets first
//cur.bv().stuffClipboard(cur.grabSelection());
- return DispatchResult(true, true);
+ return;
}
if (cmd.button() == mouse_button::button2) {
cur.setScreenPos(cmd.x, cmd.y);
cur.insert(ar);
cur.bv().update();
- return DispatchResult(true, true);
+ return;
}
if (cmd.button() == mouse_button::button3) {
// try to dispatch to enclosed insets first
cur.bv().owner()->getDialogs().show("mathpanel");
- return DispatchResult(true, true);
+ return;
}
- return DispatchResult(false);
+ cur.notdispatched();
}
-DispatchResult
-MathNestInset::lfunMousePress(LCursor & cur, FuncRequest const & cmd)
+void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest const & cmd)
{
lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
if (cmd.button() == mouse_button::button1) {
//cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
lyxerr << "lfunMousePress: setting cursor to: " << cur << endl;
cur.bv().cursor() = cur;
- return DispatchResult(true, true);
}
if (cmd.button() == mouse_button::button2) {
- return priv_dispatch(cur, FuncRequest(LFUN_PASTESELECTION));
- }
-
- if (cmd.button() == mouse_button::button3) {
- return DispatchResult(true, true);
+ priv_dispatch(cur, FuncRequest(LFUN_PASTESELECTION));
}
-
- return DispatchResult(true, true);
}
-DispatchResult
-MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest const & cmd)
+void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest const & cmd)
{
// only select with button 1
if (cmd.button() != mouse_button::button1)
- return DispatchResult(true, true);
+ return;
if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2)
- return DispatchResult(true, true);
+ return;
first_x = cmd.x;
first_y = cmd.y;
//cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
cur.bv().cursor().cursor_ = cur.cursor_;
cur.bv().cursor().selection() = true;
- return DispatchResult(true, true);
+ return;
}
protected:
///
- DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
///
void handleFont(LCursor & cur,
std::string const & arg, std::string const & font);
private:
/// lfun handler
- DispatchResult lfunMousePress(LCursor &, FuncRequest const &);
+ void lfunMousePress(LCursor &, FuncRequest const &);
///
- DispatchResult lfunMouseRelease(LCursor &, FuncRequest const &);
+ void lfunMouseRelease(LCursor &, FuncRequest const &);
///
- DispatchResult lfunMouseMotion(LCursor &, FuncRequest const &);
+ void lfunMouseMotion(LCursor &, FuncRequest const &);
protected:
/// we store the cells in a vector
}
-DispatchResult
-MathScriptInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void MathScriptInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
- lyxerr << "MathScriptInset: request: " << cmd << std::endl;
+ //lyxerr << "MathScriptInset: request: " << cmd << std::endl;
if (cmd.action == LFUN_MATH_LIMITS) {
if (!cmd.argument.empty()) {
limits_ = hasLimits() ? -1 : 1;
else
limits_ = 0;
- return DispatchResult(true, true);
+ return;
}
- return MathNestInset::priv_dispatch(cur, cmd);
+ MathNestInset::priv_dispatch(cur, cmd);
}
void infoize2(std::ostream & os) const;
protected:
///
- DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
/// returns x offset for main part
int dxx() const;
#include "BufferView.h"
#include "cursor.h"
-#include "dispatchresult.h"
#include "debug.h"
#include "funcrequest.h"
#include "math_support.h"
}
-DispatchResult RefInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
+void RefInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_INSET_MODIFY:
if (cmd.getArg(0) == "ref") {
MathArray ar;
- if (!createMathInset_fromDialogStr(cmd.argument, ar))
- return DispatchResult(false);
- *this = *ar[0].nucleus()->asRefInset();
- return DispatchResult(true, true);
+ if (createMathInset_fromDialogStr(cmd.argument, ar)) {
+ *this = *ar[0].nucleus()->asRefInset();
+ return;
+ }
}
- return DispatchResult(false);
+ cur.notdispatched();
+ return;
case LFUN_MOUSE_RELEASE:
if (cmd.button() == mouse_button::button3) {
lyxerr << "trying to goto ref" << cell(0) << endl;
cur.bv().dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
- return DispatchResult(true, true);
+ return;
}
if (cmd.button() == mouse_button::button1) {
// Eventually trigger dialog with button 3
// not 1
string const data = createDialogStr("ref");
cur.bv().owner()->getDialogs().show("ref", data, this);
- return DispatchResult(true, true);
+ return;
}
- return DispatchResult(false);
+ cur.notdispatched();
+ return;
case LFUN_MOUSE_PRESS:
case LFUN_MOUSE_MOTION:
// eat other mouse commands
- return DispatchResult(true, true);
+ return;
default:
- return CommandInset::priv_dispatch(cur, cmd);
+ CommandInset::priv_dispatch(cur, cmd);
+ return;
}
}
static std::string const & getName(int type);
protected:
///
- virtual
- DispatchResult
- priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
};
#endif
void RowPainter::paintSelection()
{
- bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
+ bool const is_rtl = text_.isRTL(*pit_);
// the current selection
LCursor const & cur = bv_.cursor();
int const ww = bv_.workWidth();
- bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
+ bool const is_rtl = text_.isRTL(*pit_);
bool const is_seq = isFirstInSequence(pit_, text_.paragraphs());
//lyxerr << "paintFirst: " << pit_->id() << " is_seq: " << is_seq << std::endl;
void RowPainter::paintLast()
{
int const ww = bv_.workWidth();
- bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
+ bool const is_rtl = text_.isRTL(*pit_);
int const endlabel = getEndLabel(pit_, text_.paragraphs());
// draw an endlabel
ret += TeXCellPreamble(os, cell);
InsetText & inset = getCellInset(cell);
- bool rtl = inset.paragraphs().begin()->isRightToLeftPar(bufferparams) &&
- !inset.paragraphs().begin()->empty() && getPWidth(cell).zero();
+ bool rtl = inset.text_.isRTL(inset.paragraphs().front())
+ && !inset.paragraphs().begin()->empty()
+ && getPWidth(cell).zero();
if (rtl)
os << "\\R{";
double fill_separator = 0;
double x = 0;
- bool const is_rtl =
- pit->isRightToLeftPar(bv()->buffer()->params());
+ bool const is_rtl = isRTL(*pit);
if (is_rtl)
x = rightMargin(*pit);
else
if (end <= row_pos)
cursor_vpos = row_pos;
else if (pos >= end)
- cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params()))
- ? row_pos : end;
+ cursor_vpos = isRTL(*pit) ? row_pos : end;
else if (pos > row_pos && pos >= end)
// Place cursor after char at (logical) position pos - 1
cursor_vpos = (bidi.level(pos - 1) % 2 == 0)
text = "thm"; // Create a correct prefix for prettyref
text += ':';
- if (layout->latextype == LATEX_PARAGRAPH ||
- lyxrc.label_init_length < 0)
+ if (layout->latextype == LATEX_PARAGRAPH || lyxrc.label_init_length < 0)
text.erase();
string par_text = pit->asString(*cur.bv().buffer(), false);
return text;
}
+
+
+int LyXText::dist(int x, int y) const
+{
+ int xx = 0;
+ int yy = 0;
+
+ if (x < xo_)
+ xx = xo_ - x;
+ else if (x > xo_ + width)
+ xx = x - xo_ - width;
+
+ if (y < yo_ - ascent())
+ yy = yo_ - ascent() - y;
+ else if (y > yo_ + descent())
+ yy = y - yo_ - descent();
+
+ return xx + yy;
+}
&& getPar(cur.selBegin())->isLineSeparator(cur.selBegin().pos())
&& (cur.selBegin().par() != cur.selEnd().par()
|| cur.selBegin().pos() < cur.selEnd().pos()))
- cur.selBegin().pos(cur.selBegin().pos() + 1);
+ ++cur.selBegin().pos();
CutAndPaste::copySelection(getPar(cur.selBegin().par()),
getPar(cur.selEnd().par()),
{
BOOST_ASSERT(par != int(paragraphs().size()));
- cur.par(par);
- cur.pos(pos);
- cur.boundary(boundary);
+ cur.par() = par;
+ cur.pos() = pos;
+ cur.boundary() = boundary;
// no rows, no fun...
if (paragraphs().begin()->rows.empty())
// None of these should happen, but we're scaredy-cats
if (pos < 0) {
lyxerr << "dont like -1" << endl;
- pos = 0;
- cur.pos(0);
BOOST_ASSERT(false);
- } else if (pos > para.size()) {
+ }
+
+ if (pos > para.size()) {
lyxerr << "dont like 1, pos: " << pos
<< " size: " << para.size()
<< " row.pos():" << row.pos()
<< " par: " << par << endl;
- pos = 0;
- cur.pos(0);
BOOST_ASSERT(false);
- } else if (pos > end) {
+ }
+
+ if (pos > end) {
lyxerr << "dont like 2 please report" << endl;
// This shouldn't happen.
- pos = end;
- cur.pos(pos);
BOOST_ASSERT(false);
- } else if (pos < row.pos()) {
+ }
+
+ if (pos < row.pos()) {
lyxerr << "dont like 3 please report pos:" << pos
<< " size: " << para.size()
<< " row.pos():" << row.pos()
<< " par: " << par << endl;
- pos = row.pos();
- cur.pos(pos);
BOOST_ASSERT(false);
}
}
// If lastrow is false, we don't need to compute
// the value of rtl.
- bool const rtl = lastrow
- ? pit->isRightToLeftPar(bv()->buffer()->params())
- : false;
+ bool const rtl = lastrow ? isRTL(*pit) : false;
if (lastrow &&
((rtl && left_side && vc == row.pos() && x < tmpx - 5) ||
(!rtl && !left_side && vc == end && x > tmpx + 5)))
DispatchResult LyXText::moveRight(LCursor & cur)
{
- if (rtl(cur))
+ if (isRTL(cur.paragraph()))
return moveLeftIntern(cur, false, true, false);
else
return moveRightIntern(cur, true, true, false);
DispatchResult LyXText::moveLeft(LCursor & cur)
{
- if (rtl(cur))
+ if (isRTL(cur.paragraph()))
return moveRightIntern(cur, true, true, false);
else
return moveLeftIntern(cur, false, true, false);
}
-bool LyXText::rtl(LCursor & cur) const
+bool LyXText::isRTL(Paragraph const & par) const
{
- return cur.paragraph().isRightToLeftPar(bv()->buffer()->params());
+ return par.isRightToLeftPar(bv()->buffer()->params());
}
case LFUN_WORDRIGHT:
if (!cur.mark())
cur.clearSelection();
- if (rtl(cur))
+ if (isRTL(cur.paragraph()))
cursorLeftOneWord(cur);
else
cursorRightOneWord(cur);
case LFUN_WORDLEFT:
if (!cur.mark())
cur.clearSelection();
- if (rtl(cur))
+ if (isRTL(cur.paragraph()))
cursorRightOneWord(cur);
else
cursorLeftOneWord(cur);
case LFUN_RIGHTSEL:
if (!cur.selection())
cur.resetAnchor();
- if (rtl(cur))
+ if (isRTL(cur.paragraph()))
cursorLeft(cur, true);
else
cursorRight(cur, true);
case LFUN_LEFTSEL:
if (!cur.selection())
cur.resetAnchor();
- if (rtl(cur))
+ if (isRTL(cur.paragraph()))
cursorRight(cur, true);
else
cursorLeft(cur, true);
case LFUN_WORDRIGHTSEL:
if (!cur.selection())
cur.resetAnchor();
- if (rtl(cur))
+ if (isRTL(cur.paragraph()))
cursorLeftOneWord(cur);
else
cursorRightOneWord(cur);
case LFUN_WORDLEFTSEL:
if (!cur.selection())
cur.resetAnchor();
- if (rtl(cur))
+ if (isRTL(cur.paragraph()))
cursorRightOneWord(cur);
else
cursorLeftOneWord(cur);
case LFUN_FINISHED_LEFT:
lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
cur.pop(cur.currentDepth());
- if (rtl(cur))
+ if (isRTL(cur.paragraph()))
cursorLeft(cur, true);
cur.bv().cursor() = cur;
break;
case LFUN_FINISHED_RIGHT:
lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
cur.pop(cur.currentDepth());
- if (!rtl(cur))
+ if (!isRTL(cur.paragraph()))
cursorRight(cur, true);
cur.bv().cursor() = cur;
break;