Dekels tabular/textinset patches

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1305 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Vigna 2001-01-08 16:14:09 +00:00
parent 7fa7d43740
commit 12747e1af9
11 changed files with 235 additions and 81 deletions

View File

@ -1,3 +1,37 @@
2001-01-07 Dekel Tsur <dekelts@tau.ac.il>
* BufferView2.C (open_new_inset): Added 2nd argument.
(getParentText, getParentLanguage): New methods.
* src/lyxfunc.C (Dispatch): Fixed handling of LFUN_LEFT and
LFUN_INSET_TABULAR for RTL text.
* src/tabular.C (Latex): Put \R{} around RTL cells.
* src/text2.C (InsertInset): Change cursor position for highly
editable insets.
* src/frontends/xforms/FormTabularCreate.C (apply): Create the
tabular inset by calling to LyXFunc::Dispatch(LFUN_INSET_TABULAR,...)
* src/insets/insettabular.C (LocalDispatch): When dispatching
LFUN_TAB/LFUN_SHIFT_TAB, if the insettext of the old cell was
locked, then the insettext of the new cell will be locked.
(moveLeft, moveRight): Fixed for RTL tabulars.
(moveNextCell, movePrevCell): Ditto.
(isRightToLeft): New method.
* src/insets/insettext.C (LocalDispatch): Fixed handling of
non-dispatched function in the locking inset.
(Edit): If the inset is empty set the language of the current font
to the language to the surronding text (this code was moved from
LocalDispatch to allow the user to change the languaeg before
inserting text).
(moveRight, moveLeft): Fixed for RTL text.
(checkAndActivateInset): Fixed.
* src/tabular.C (OldFormatRead): Use ALL_INHERIT font as the base font.
2001-01-08 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* src/frontends/xforms/Toolbar_pimpl.C (BubbleTimerCB): translate

View File

@ -26,6 +26,7 @@ class TeXErrors;
class Buffer;
class LyXScreen;
class WorkArea;
class Language;
///
class BufferView : public noncopyable {
@ -102,6 +103,10 @@ public:
///
LyXText * getLyXText() const;
///
LyXText * getParentText(Inset * inset) const;
///
Language const * getParentLanguage(Inset * inset) const;
///
int workWidth() const;
///
UpdatableInset * theLockingInset() const;
@ -188,7 +193,7 @@ public:
bool insertInset(Inset * inset, string const & lout = string(),
bool no_table = false);
/// open and lock an updatable inset
bool open_new_inset(UpdatableInset * new_inset);
bool open_new_inset(UpdatableInset * new_inset, bool behind = false);
/** Inserts a lyx file at cursor position.
@return #false# if it fails.
*/

View File

@ -262,7 +262,7 @@ bool BufferView::insertInset(Inset * inset, string const & lout,
// Open and lock an updatable inset
bool BufferView::open_new_inset(UpdatableInset * new_inset)
bool BufferView::open_new_inset(UpdatableInset * new_inset, bool behind)
{
beforeChange();
text->FinishUndo();
@ -270,7 +270,11 @@ bool BufferView::open_new_inset(UpdatableInset * new_inset)
delete new_inset;
return false;
}
new_inset->Edit(this, 0, 0, 0);
if (behind) {
LyXFont & font = getLyXText()->real_current_font;
new_inset->Edit(this, new_inset->width(this, font), 0, 0);
} else
new_inset->Edit(this, 0, 0, 0);
return true;
}
@ -945,3 +949,23 @@ LyXText * BufferView::getLyXText() const
return text;
}
LyXText * BufferView::getParentText(Inset * inset) const
{
if (inset->owner()) {
LyXText * txt = inset->getLyXText(this);
inset = inset->owner();
while (inset && inset->getLyXText(this) == txt)
inset = inset->owner();
if (inset)
return inset->getLyXText(this);
}
return text;
}
Language const * BufferView::getParentLanguage(Inset * inset) const
{
LyXText * text = getParentText(inset);
return text->cursor.par()->GetFontSettings(buffer()->params,
text->cursor.pos()).language();
}

View File

@ -25,6 +25,7 @@
#include "Dialogs.h"
#include "LyXView.h"
#include "insets/insettabular.h"
#include "support/lstrings.h"
FormTabularCreate::FormTabularCreate(LyXView * lv, Dialogs * d)
: FormBaseBD(lv, d, _("Insert Tabular"),
@ -86,10 +87,8 @@ void FormTabularCreate::apply()
int ysize = int(fl_get_slider_value(dialog_->slider_columns) + 0.5);
int xsize = int(fl_get_slider_value(dialog_->slider_rows) + 0.5);
InsetTabular * in = new InsetTabular( *lv_->buffer(), xsize, ysize );
if (!lv_->view()->open_new_inset(in)) {
delete in;
}
string tmp = tostr(xsize) + " " + tostr(ysize);
lv_->getLyXFunc()->Dispatch(LFUN_INSET_TABULAR, tmp);
}

View File

@ -763,13 +763,10 @@ void InsetTabular::InsetKeyPress(XKeyEvent * xke)
UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
string const & arg)
{
UpdatableInset::RESULT
result;
no_selection = false;
if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
|| (result == DISPATCHED_NOUPDATE)) {
UpdatableInset::RESULT result =
UpdatableInset::LocalDispatch(bv, action, arg);
if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
resetPos(bv);
return result;
}
@ -920,19 +917,23 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
break;
case LFUN_SHIFT_TAB:
case LFUN_TAB:
{
bool lock = false;
if (the_locking_inset) {
UnlockInsetInInset(bv, the_locking_inset);
the_locking_inset = 0;
lock = true;
}
if (action == LFUN_TAB)
moveNextCell(bv);
moveNextCell(bv, lock);
else
movePrevCell(bv);
movePrevCell(bv, lock);
sel_pos_start = sel_pos_end = cursor.pos();
sel_cell_start = sel_cell_end = actcell;
if (hs)
UpdateLocal(bv, SELECTION, false);
break;
}
case LFUN_LAYOUT_TABULAR:
{
bv->owner()->getDialogs()->showTabular(this);
@ -1323,9 +1324,9 @@ void InsetTabular::resetPos(BufferView * bv) const
UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
{
if (!cellstart(cursor.pos())) {
if (tabular->IsLastCell(actcell))
bool moved = isRightToLeft(bv) ? movePrevCell(bv) : moveNextCell(bv);
if (!moved)
return FINISHED;
++actcell;
cursor.pos(0);
} else if (lock) {
if (ActivateCellInset(bv))
@ -1340,10 +1341,10 @@ UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
{
if (cellstart(cursor.pos()) && !actcell)
return FINISHED;
if (cellstart(cursor.pos())) {
--actcell;
bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
if (!moved)
return FINISHED;
cursor.pos(1);
} else if (lock) { // behind the inset
cursor.pos(0);
@ -1379,21 +1380,59 @@ UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv)
}
bool InsetTabular::moveNextCell(BufferView * bv)
bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
{
if (tabular->IsLastCell(actcell))
return false;
++actcell;
if (isRightToLeft(bv)) {
if (tabular->IsFirstCellInRow(actcell)) {
int row = tabular->row_of_cell(actcell);
if (row == tabular->rows() - 1)
return false;
actcell = tabular->GetLastCellInRow(row);
actcell = tabular->GetCellBelow(actcell);
} else {
if (!actcell)
return false;
--actcell;
}
} else {
if (tabular->IsLastCell(actcell))
return false;
++actcell;
}
if (lock) {
bool rtl = tabular->GetCellInset(actcell)->par->
isRightToLeftPar(bv->buffer()->params);
ActivateCellInset(bv, 0, 0, 0, !rtl);
}
resetPos(bv);
return true;
}
bool InsetTabular::movePrevCell(BufferView * bv)
bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
{
if (!actcell) // first cell
return false;
--actcell;
if (isRightToLeft(bv)) {
if (tabular->IsLastCellInRow(actcell)) {
int row = tabular->row_of_cell(actcell);
if (row == 0)
return false;
actcell = tabular->GetFirstCellInRow(row);
actcell = tabular->GetCellAbove(actcell);
} else {
if (tabular->IsLastCell(actcell))
return false;
++actcell;
}
} else {
if (!actcell) // first cell
return false;
--actcell;
}
if (lock) {
bool rtl = tabular->GetCellInset(actcell)->par->
isRightToLeftPar(bv->buffer()->params);
ActivateCellInset(bv, 0, 0, 0, !rtl);
}
resetPos(bv);
return true;
}
@ -1774,9 +1813,9 @@ bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
x = inset->x() + inset->width(bv, font);
y = inset->descent(bv, font);
}
inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
inset_y = cursor.y();
inset->Edit(bv, x - inset_x, y - inset_y, button);
//inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
//inset_y = cursor.y();
inset->Edit(bv, x, y, button);
if (!the_locking_inset)
return false;
UpdateLocal(bv, CELL, false);
@ -2211,3 +2250,7 @@ bool InsetTabular::cutSelection()
return true;
}
bool InsetTabular::isRightToLeft(BufferView *bv )
{
return bv->getParentLanguage(this)->RightToLeft();
}

View File

@ -206,9 +206,9 @@ private:
///
UpdatableInset::RESULT moveDown(BufferView *);
///
bool moveNextCell(BufferView *);
bool moveNextCell(BufferView *, bool lock = false);
///
bool movePrevCell(BufferView *);
bool movePrevCell(BufferView *, bool lock = false);
///
bool Delete();
///
@ -239,6 +239,8 @@ private:
bool pasteSelection(BufferView *);
///
bool cutSelection();
///
bool isRightToLeft(BufferView *);
//
// Private structures and variables

View File

@ -501,6 +501,14 @@ void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
bv->text->FinishUndo();
ShowInsetCursor(bv);
UpdateLocal(bv, FULL, false);
// If the inset is empty set the language of the current font to the
// language to the surronding text.
if (par->Last() == 0 && !par->next) {
LyXFont font(LyXFont::ALL_IGNORE);
font.setLanguage(bv->getParentLanguage(this));
SetFont(bv, font, false);
}
}
@ -747,17 +755,27 @@ InsetText::LocalDispatch(BufferView * bv,
UpdateLocal(bv, CURSOR_PAR, false);
return result;
} else if (result == FINISHED) {
bool dispatched = false;
switch (action) {
case -1:
case LFUN_UNKNOWN_ACTION:
case LFUN_BREAKPARAGRAPH:
case LFUN_BREAKLINE:
moveRightIntern(bv, false, false);
break;
case LFUN_RIGHT:
moveRight(bv, false);
if (!TEXT(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
moveRightIntern(bv, false, false);
dispatched = true;
break;
case LFUN_DOWN:
moveDown(bv);
case LFUN_LEFT:
if (TEXT(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
moveRightIntern(bv, false, false);
dispatched = true;
break;
}
the_locking_inset = 0;
return DISPATCHED;
if (dispatched)
return DISPATCHED;
}
}
HideInsetCursor(bv);
@ -785,23 +803,6 @@ InsetText::LocalDispatch(BufferView * bv,
bv->text->cursor.par()->next
#endif
);
// if an empty paragraph set the language to the surronding
// paragraph language on insertion of the first character!
if (!par->Last() && !par->next) {
LyXText * text = 0;
if (owner()) {
Inset * inset = owner();
while(inset && inset->getLyXText(bv) == TEXT(bv))
inset = inset->owner();
if (inset)
text = inset->getLyXText(bv);
}
if (!text)
text = bv->text;
LyXFont font(LyXFont::ALL_IGNORE);
font.setLanguage(text->cursor.par()->getParLanguage(bv->buffer()->params));
SetFont(bv, font, false);
}
bv->setState();
if (lyxrc.auto_region_delete) {
if (TEXT(bv)->selection){
@ -853,7 +854,7 @@ InsetText::LocalDispatch(BufferView * bv,
break;
case LFUN_LEFT:
bv->text->FinishUndo();
result= moveLeft(bv);
result = moveLeft(bv);
TEXT(bv)->ClearSelection();
TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
UpdateLocal(bv, CURSOR, false);
@ -1234,10 +1235,30 @@ void InsetText::HideInsetCursor(BufferView * bv)
UpdatableInset::RESULT
InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
{
if (TEXT(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
return moveLeftIntern(bv, false, activate_inset, selecting);
else
return moveRightIntern(bv, false, activate_inset, selecting);
}
UpdatableInset::RESULT
InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
{
if (TEXT(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
return moveRightIntern(bv, true, activate_inset, selecting);
else
return moveLeftIntern(bv, true, activate_inset, selecting);
}
UpdatableInset::RESULT
InsetText::moveRightIntern(BufferView * bv, bool behind,
bool activate_inset, bool selecting)
{
if (!cpar(bv)->next && (cpos(bv) >= cpar(bv)->Last()))
return FINISHED;
if (activate_inset && checkAndActivateInset(bv, false))
if (activate_inset && checkAndActivateInset(bv, behind))
return DISPATCHED;
TEXT(bv)->CursorRight(bv, selecting);
return DISPATCHED_NOUPDATE;
@ -1245,12 +1266,13 @@ InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
UpdatableInset::RESULT
InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
InsetText::moveLeftIntern(BufferView * bv, bool behind,
bool activate_inset, bool selecting)
{
if (!cpar(bv)->previous && (cpos(bv) <= 0))
return FINISHED;
TEXT(bv)->CursorLeft(bv, selecting);
if (activate_inset && checkAndActivateInset(bv, true))
if (activate_inset && checkAndActivateInset(bv, behind))
return DISPATCHED;
return DISPATCHED_NOUPDATE;
}
@ -1352,13 +1374,14 @@ bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
if (behind) {
x = inset->width(bv, font);
y = inset->descent(bv, font);
y = font.isRightToLeft() ? 0 : inset->descent(bv, font);
} else {
x = y = 0;
x = 0;
y = font.isRightToLeft() ? inset->descent(bv, font) : 0;
}
inset_x = cx(bv) - top_x + drawTextXOffset;
inset_y = cy(bv) + drawTextYOffset;
inset->Edit(bv, x - inset_x, y - inset_y, 0);
//inset_x = cx(bv) - top_x + drawTextXOffset;
//inset_y = cy(bv) + drawTextYOffset;
inset->Edit(bv, x, y, 0);
if (!the_locking_inset)
return false;
UpdateLocal(bv, CURSOR_PAR, false);

View File

@ -208,6 +208,15 @@ private:
UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true,
bool selecting = false);
///
UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
bool activate_inset = true,
bool selecting = false);
///
UpdatableInset::RESULT moveLeftIntern(BufferView *, bool behind,
bool activate_inset = true,
bool selecting = false);
///
UpdatableInset::RESULT moveUp(BufferView *);
///
UpdatableInset::RESULT moveDown(BufferView *);

View File

@ -637,7 +637,7 @@ string const LyXFunc::Dispatch(int ac,
(result == UpdatableInset::DISPATCHED_NOUPDATE))
return string();
else {
setMessage(N_("Text mode"));
//setMessage(N_("Text mode"));
switch (action) {
case LFUN_UNKNOWN_ACTION:
case LFUN_BREAKPARAGRAPH:
@ -1468,7 +1468,15 @@ string const LyXFunc::Dispatch(int ac,
&& tmptext->cursor.par()->GetInset(tmptext->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
Inset * tmpinset = tmptext->cursor.par()->GetInset(tmptext->cursor.pos());
setMessage(tmpinset->EditMessage());
tmpinset->Edit(owner->view(), 0, 0, 0);
int y = 0;
if (is_rtl) {
LyXFont font =
tmptext->GetFont(owner->view()->buffer(),
tmptext->cursor.par(),
tmptext->cursor.pos());
y = tmpinset->descent(owner->view(),font);
}
tmpinset->Edit(owner->view(), 0, y, 0);
break;
}
if (!is_rtl)
@ -1490,7 +1498,7 @@ string const LyXFunc::Dispatch(int ac,
LyXCursor cur = txt->cursor;
if (!is_rtl)
txt->CursorLeft(owner->view(), false);
if ((cur != txt->cursor) && // only if really moved!
if ((is_rtl || cur != txt->cursor) && // only if really moved!
txt->cursor.pos() < txt->cursor.par()->Last() &&
(txt->cursor.par()->GetChar(txt->cursor.pos()) ==
LyXParagraph::META_INSET) &&
@ -1503,11 +1511,12 @@ string const LyXFunc::Dispatch(int ac,
LyXFont font = txt->GetFont(owner->view()->buffer(),
txt->cursor.par(),
txt->cursor.pos());
int y = is_rtl ? 0
: tmpinset->descent(owner->view(),font);
tmpinset->Edit(owner->view(),
tmpinset->x() +
tmpinset->width(owner->view(),font),
tmpinset->descent(owner->view(),font),
0);
y, 0);
break;
}
if (is_rtl)
@ -2265,9 +2274,9 @@ string const LyXFunc::Dispatch(int ac,
::sscanf(argument.c_str(),"%d%d", &r, &c);
InsetTabular * new_inset =
new InsetTabular(*owner->buffer(), r, c);
if (owner->view()->insertInset(new_inset))
new_inset->Edit(owner->view(), 0, 0, 0);
else
bool rtl =
owner->view()->getLyXText()->real_current_font.isRightToLeft();
if (!owner->view()->open_new_inset(new_inset, rtl))
delete new_inset;
}
break;

View File

@ -1367,7 +1367,7 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
string tmptok;
int pos = 0;
char depth = 0;
LyXFont font(LyXFont::ALL_SANE);
LyXFont font(LyXFont::ALL_INHERIT);
font.setLanguage(owner_->BufferOwner()->GetLanguage());
while (lex.IsOK()) {
@ -2195,7 +2195,16 @@ int LyXTabular::Latex(Buffer const * buf,
if (IsPartOfMultiColumn(i,j))
continue;
ret += TeXCellPreamble(os, cell);
ret += GetCellInset(cell)->Latex(buf, os, fragile, fp);
InsetText * inset = GetCellInset(cell);
bool rtl = inset->par->isRightToLeftPar(buf->params) &&
inset->par->Last() > 0 && GetPWidth(cell).empty();
if (rtl)
os << "\\R{";
ret += inset->Latex(buf, os, fragile, fp);
if (rtl)
os << "}";
ret += TeXCellPostamble(os, cell);
if (!IsLastCellInRow(cell)) { // not last cell in row
os << "&\n";

View File

@ -2145,16 +2145,13 @@ void LyXText::InsertInset(BufferView * bview, Inset * inset)
* The character will not be inserted a
* second time */
#if 1
// if we enter a text-inset the cursor should be to the left side
// of it! This couldn't happen before as Undo was not handled inside
// If we enter a highly editable inset the cursor should be to before
// the inset. This couldn't happen before as Undo was not handled inside
// inset now after the Undo LyX tries to call inset->Edit(...) again
// and cannot do this as the cursor is behind the inset and GetInset
// does not return the inset!
if (inset->IsTextInset()) {
if (cursor.par()->isRightToLeftPar(bview->buffer()->params))
CursorRight(bview);
else
CursorLeft(bview);
if (inset->Editable() == Inset::HIGHLY_EDITABLE) {
CursorLeft(bview, true);
}
#endif
}