Commit d9992532 authored by Anna.Pavlova's avatar Anna.Pavlova Committed by Alexander.Trofimov

курсор и селект для формулы ( для ParaMath )

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@55130 954022d7-b5bf-4e40-9824-e11837661b57
parent b567eef2
......@@ -5,13 +5,17 @@
function ParaMath(bAddMenu, bCollaborative)
{
this.Id = g_oIdCounter.Get_NewId();
this.Type = para_Math;
this.Jc = undefined;
this.Math = new CMathComposition(bCollaborative);
this.Math.Parent = this;
this.Content = this.Math.Root.content; // Root.content
this.RootComposition = this.Math.Root;
this.CurrentContent = this.RootComposition;
this.SelectContent = this.RootComposition;
this.bSelectionUse = false;
this.State = new CParaRunState(); // Положение курсора и селекта для данного run
this.Paragraph = null;
......@@ -405,7 +409,7 @@ ParaMath.prototype =
if ( true !== PRS.NewRange )
{
RangeEndPos = this.Content.length; // RangeEndPos = 1; to RangeEndPos = this.Content.length;
RangeEndPos = this.RootComposition.content.length; // RangeEndPos = 1; to RangeEndPos = this.Content.length;
// Удаляем лишние строки, оставшиеся после предыдущего пересчета в самом конце
if ( this.Lines.length > this.LinesLength )
......@@ -583,9 +587,9 @@ ParaMath.prototype =
var StartPos = this.Lines[CurLine].Ranges[CurRange].StartPos;
var EndPos = this.Lines[CurLine].Ranges[CurRange].EndPos;
if ( EndPos >= 1 )
if ( EndPos >= 1)
{
return this.Math.UpdateCursor();
return this.CurrentContent.update_Cursor(_CurPage, UpdateTarget);
}
return {X : X };
......@@ -704,7 +708,7 @@ ParaMath.prototype =
this.Math.Cursor_MoveToEndPos();
},
Get_ParaContentPosByXY : function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
Get_ParaContentPosByXY : function(SearchPos, Depth, _CurLine, _CurRange, StepEnd) // получить логическую позицию по XY
{
// TODO: ParaMath.Get_ParaContentPosByXY
......@@ -723,23 +727,38 @@ ParaMath.prototype =
var Dx = this.Math.Size.WidthVisible;
var D = SearchPos.X - SearchPos.CurX;
//var Diff = Math.abs(D) < Math.abs(D - Dx) ? Math.abs(D) : Math.abs(D - Dx);
var Diff = SearchPos.X - SearchPos.CurX;
var Diff = Math.abs(D) < Math.abs(D + Dx) ? Math.abs(D) : Math.abs(D + Dx);
//var Diff = SearchPos.X - SearchPos.CurX;
if(Math.abs(Diff) < SearchPos.DiffX + 0.001 )
{
SearchPos.DiffX = Math.abs(Diff);
this.Math.Selection_SetStart(SearchPos.X, SearchPos.Y);
this.Math.Selection_SetEnd(SearchPos.X, SearchPos.Y);
this.Math.Root.get_ParaContentPos(false, SearchPos.Pos);
var X = SearchPos.X - this.Math.absPos.x,
Y = SearchPos.Y - this.Math.absPos.y;
SearchPos.DiffX = Diff;
this.RootComposition.get_ParaContentPosByXY(SearchPos.Pos, X, Y);
//this.Math.Selection_SetStart(SearchPos.X, SearchPos.Y);
//this.Math.Selection_SetEnd(SearchPos.X, SearchPos.Y);
//this.Math.Root.get_ParaContentPos(false, SearchPos.Pos);
Result = true;
if ( Diff >= - 0.001 && Diff <= Dx + 0.001 )
if ( D >= - 0.001 && D <= Dx + 0.001 )
{
SearchPos.InText = true;
SearchPos.DiffX = 0.001; // сравниваем расстояние до ближайшего элемента
}
}
// var str = "";
// for(var i = 0; i < SearchPos.Pos.Data.length; i++)
// {
// str += SearchPos.Pos.Data[i] + ", ";
//
// }
// console.log(str);
//console.log("Pos [" + i + "] = " + SearchPos.Pos[i]);
SearchPos.CurX += Dx;
/*for(var CurPos = StartPos; CurPos < EndPos; CurPos++)
......@@ -785,24 +804,22 @@ ParaMath.prototype =
return Result;
},
Get_ParaContentPos : function(bSelection, bStart, ContentPos) // получение позиции контентов
Get_ParaContentPos : function(bSelection, bStart, ContentPos) // получить текущую логическую позицию
{
// TODO: ParaMath.Get_ParaContentPos
this.Math.Root.get_ParaContentPos(bStart, ContentPos);
this.RootComposition.get_ParaContentPos(bSelection, bStart, ContentPos);
},
Set_ParaContentPos : function(ContentPos, Depth) // выставить позицию в конетенте
Set_ParaContentPos : function(ContentPos, Depth) // выставить логическую позицию в контенте
{
// TODO: ParaMath.Set_ParaContentPos
var Pos = ContentPos.Get(Depth);
this.State.ContentPos = Pos;
this.Math.Root.set_ParaContentPos(ContentPos, Depth);
this.RootComposition.set_ParaContentPos(ContentPos, Depth);
},
Get_PosByElement : function(Class, ContentPos, Depth, UseRange, Range, Line)
{
if ( this === Class )
......@@ -868,23 +885,58 @@ ParaMath.prototype =
Set_SelectionContentPos : function(StartContentPos, EndContentPos, Depth, StartFlag, EndFlag)
{
// TODO: ParaMath.Set_SelectionContentPos
this.SelectContent = this.RootComposition;
switch (StartFlag)
{
case 1:
this.RootComposition.setLogicalPosition(1);
break;
case -1:
this.RootComposition.setLogicalPosition(this.RootComposition.length - 1);
break;
case 0:
this.RootComposition.set_StartSelectContent(StartContentPos, Depth);
break;
}
switch (EndFlag)
{
case 1:
this.RootComposition.set_SelectEndExtreme(false);
break;
case -1:
this.RootComposition.set_SelectEndExtreme(true);
break;
case 0:
var result = this.RootComposition.set_EndSelectContent(EndContentPos, Depth);
this.SelectContent = result.SelectContent;
break;
}
this.bSelectionUse = true;
},
Selection_IsUse : function()
{
// TODO: ParaMath.Selection_IsUse
return false;
return this.bSelectionUse;
},
Selection_Stop : function()
{
},
},
Selection_Remove : function()
{
// TODO: ParaMath.Selection_Remove
},
this.bSelectionUse = false;
},
Select_All : function(Direction)
{
// TODO: ParaMath.Select_All
......@@ -898,16 +950,42 @@ ParaMath.prototype =
var StartPos = this.Lines[CurLine].Ranges[CurRange].StartPos;
var EndPos = this.Lines[CurLine].Ranges[CurRange].EndPos;
if ( EndPos >= 1 )
{
if ( true === this.bSelectionUse )
{
// TODO: ParaMath.Selection_Draw_Range
if(SelectionDraw.FindStart == true)
{
if(this.SelectContent.selectUse())
{
SelectionDraw.FindStart = false;
this.SelectContent.drawSelect(SelectionDraw);
}
}
else
{
if(this.RootComposition.selectUse())
SelectionDraw.W += this.RootComposition.size.width;
}
}
else
{
if ( true === SelectionDraw.FindStart )
SelectionDraw.StartX += this.Width;
}
}
},
Selection_IsEmpty : function(CheckEnd)
{
// TODO: ParaMath.Selection_IsEmpty
return true;
return !this.SelectContent.selectUse();
},
Selection_CheckParaEnd : function()
......
......@@ -10608,7 +10608,7 @@ function Binary_oMathReader(stream)
props.init = true;
}
var oDeg = oRad.getDegree();
if (oDeg && length == 0)
if (oDeg && length == 0 && props.degHide !== true)
oDeg.fillPlaceholders();
res = this.bcr.Read1(length, function(t, l){
return oThis.ReadMathArg(t,l,oDeg);
......
......@@ -851,6 +851,58 @@ CMathBase.prototype =
return {pos: posCurs, mCoord: mouseCoord, inside_flag: inside_flag};
},
excludeJDElement: function(Cur_X, Cur_Y)
{
var pos_X = Cur_X,
pos_Y = Cur_Y;
if( this.elements[Cur_X][Cur_Y].IsJustDraw() )
{
if(this.nRow > 1)
{
if(Cur_X == 0)
pos_X = 1;
else if(Cur_X == this.nRow - 1)
pos_X = this.nRow - 2;
else
{
// пока так
pos_X = Cur_X + 1;
/* if( mCoord.y < (_h - Heights[posCurs.x]/2) )
posCurs.x--;
else
posCurs.x++;*/
}
pos_Y = Cur_Y;
}
else if(this.nCol > 1)
{
if(Cur_Y == 0)
pos_Y = 1;
else if(Cur_Y == this.nCol - 1)
pos_Y = this.nCol - 2;
else
{
// пока так
pos_Y = Cur_Y + 1;
/*if( mCoord.x < (_w - Widths[u]/2) )
posCurs.y = u - 1;
else
posCurs.y = u + 1;*/
}
}
else
return; // не самое лучшее решение, в идеале если у нас если такая ситуация получилась
// (что сомнительно, в контенте один элемент с которым ничего нельзя сделать),
// то вставать после этого элемента в контенте на уровень выше
// лучше следить за подобными ситуациями, чтобы такого не было
}
return {x: pos_X, y: pos_Y};
},
setPosition: function(pos)
{
if(this.bMObjs === true)
......@@ -1180,22 +1232,83 @@ CMathBase.prototype =
/// Position for Paragraph
get_ParaContentPosByXY: function(ContentPos, X, Y)
{
/// элементов just-draw не должно прийти
var disp = this.findDisposition({x: X, y: Y});
ContentPos.Add(disp.pos.x);
ContentPos.Add(disp.pos.y);
get_ParaContentPos: function(bStart, ContentPos)
this.elements[disp.pos.x][disp.pos.y].get_ParaContentPosByXY(ContentPos, disp.mCoord.x, disp.mCoord.y);
},
get_ParaContentPos: function(bSelection, bStart, ContentPos)
{
ContentPos.Add(this.CurPos_X);
ContentPos.Add(this.CurPos_Y);
this.elements[this.CurPos_X][this.CurPos_Y].get_ParaContentPos(bStart, ContentPos);
this.elements[this.CurPos_X][this.CurPos_Y].get_ParaContentPos(bSelection, bStart, ContentPos);
},
set_ParaContentPos: function(ContentPos, Depth)
{
this.CurPos_X = ContentPos.Get(Depth);
this.CurPos_Y = ContentPos.Get(Depth + 1);
var CurPos_X = ContentPos.Get(Depth);
var CurPos_Y = ContentPos.Get(Depth + 1);
if(!this.elements[CurPos_X][CurPos_Y].IsJustDraw())
{
var disp = this.excludeJDElement(CurPos_X, CurPos_Y);
CurPos_X = disp.x;
CurPos_Y = disp.y;
}
this.CurPos_X = CurPos_X;
this.CurPos_Y = CurPos_Y;
Depth += 2;
return this.elements[this.CurPos_X][this.CurPos_Y].set_ParaContentPos(ContentPos, Depth);
},
set_StartSelectContent: function(ContentPos, Depth)
{
var Pos_X = ContentPos.Get(Depth),
Pos_Y = ContentPos.Get(Depth+1);
Depth += 2;
this.selectPos.startX = Pos_X;
this.selectPos.startY = Pos_Y;
if(!this.elements[Pos_X][Pos_Y].IsJustDraw())
this.elements[Pos_X][Pos_Y].set_StartSelectContent(ContentPos, Depth);
},
set_EndSelectContent: function(ContentPos, Depth)
{
var state = true, SelectContent = null;
var endX = ContentPos.Get(Depth),
endY = ContentPos.Get(Depth+1),
startX = this.selectPos.startX,
startY = this.selectPos.startY;
Depth += 2;
this.elements[this.CurPos_X][this.CurPos_Y].set_ParaContentPos(ContentPos, Depth);
var bJustDraw = this.elements[endX][endY].IsJustDraw();
// пока так
if(startX == endX && startY == endY && !bJustDraw)
{
//this.CurPos_X = startX;
//this.CurPos_Y = startY;
var movement = this.elements[endX][endY].set_EndSelectContent(ContentPos, Depth);
SelectContent = movement.SelectContent;
state = movement.state;
}
else
state = false;
return {state: state, SelectContent: SelectContent};
}
//////////////////////////
......
......@@ -398,6 +398,7 @@ function CMathContent(bCollaborative)
};
///////////////////////////////
this.size =
{
width: 0,
......@@ -5450,7 +5451,7 @@ CMathContent.prototype =
editor.WordControl.m_oDrawingDocument.UpdateTargetFromPaint = false;
},
update_Cursor: function()
update_Cursor: function(CurPage, UpdateTarget)
{
var runPrp = this.getRunPrp(this.CurPos);
var oWPrp = runPrp.getMergedWPrp();
......@@ -5463,8 +5464,19 @@ CMathContent.prototype =
var X = this.pos.x + absPos.x + this.content[this.CurPos].widthToEl,
Y = this.pos.y + absPos.y + this.size.ascent - sizeCursor*0.8;
return {X: X, Y: Y, Height: sizeCursor};
var Para = this.Composition.Parent.Paragraph;
if ( null !== Para && undefined !== Para && UpdateTarget == true)
{
Para.DrawingDocument.SetTargetSize( sizeCursor );
//Para.DrawingDocument.UpdateTargetFromPaint = true;
Para.DrawingDocument.UpdateTarget( X, Y, Para.Get_StartPage_Absolute() + CurPage );
console.log("CurPos: " + this.CurPos);
console.log("x " + X + " Y " + Y);
//Para.DrawingDocument.UpdateTargetFromPaint = false;
}
return {X: X, Y: Y, Height: sizeCursor};
},
old_coordWOGaps: function( msCoord )
{
......@@ -6095,6 +6107,10 @@ CMathContent.prototype =
selectUse: function()
{
//return (this.selection.startPos !== this.selection.endPos);
//console.log("start pos "+ this.RealSelect.startPos);
//console.log("end pos " + this.RealSelect.endPos);
return this.RealSelect.startPos !== this.RealSelect.endPos;
},
setCtrPrp: function()
......@@ -6177,7 +6193,7 @@ CMathContent.prototype =
this.content[i].value.setPosition(t);
}
},
drawSelect: function()
old_drawSelect: function()
{
var start = this.RealSelect.startPos,
end = this.RealSelect.endPos;
......@@ -6207,7 +6223,10 @@ CMathContent.prototype =
Y = this.pos.y + this.Composition.absPos.y;
if( widthSelect != 0)
{
editor.WordControl.m_oLogicDocument.DrawingDocument.AddPageSelection(0, X, Y, widthSelect, heightSelect );
}
},
///// properties /////
SetDot: function(flag)
......@@ -7062,7 +7081,6 @@ CMathContent.prototype =
this.RealSelect.startPos = pos;
this.RealSelect.endPos = pos;
},
setSelect_Beginning: function(bStart)
{
......@@ -7097,7 +7115,6 @@ CMathContent.prototype =
}
/* if(this.content[this.RealSelect.startPos].value.typeObj == MATH_COMP)
console.log("Select is composition");
else
......@@ -7163,15 +7180,21 @@ CMathContent.prototype =
return flag;
},
/// Position for Paragraph
get_ParaContentPos: function(bStart, ContentPos)
get_ParaContentPosByXY: function(ContentPos, X, Y)
{
var bSelect = this.selectUse();
var pos = this.findPosition( {x: X, y: Y} );
ContentPos.Add(pos);
if(bSelect)
if(this.content[pos].value.typeObj == MATH_COMP)
{
var coord = this.getCoordElem(pos, {x: X, y: Y} );
this.content[pos].value.get_ParaContentPosByXY(ContentPos, coord.x, coord.y);
}
},
get_ParaContentPos: function(bSelection, bStart, ContentPos)
{
if( bSelection && this.RealSelect.startPos !== this.RealSelect.endPos )
{
var pos = bStart ? this.RealSelect.startPos : this.RealSelect.endPos;
ContentPos.Add(pos);
......@@ -7181,20 +7204,183 @@ CMathContent.prototype =
ContentPos.Add(this.CurPos);
if(this.content[this.CurPos].value.typeObj == MATH_COMP)
this.content[this.CurPos].value.get_ParaContentPos(bStart, ContentPos);
this.content[this.CurPos].value.get_ParaContentPos(bSelection, bStart, ContentPos);
}
},
set_ParaContentPos: function(ContentPos, Depth)
{
var Content = this;
this.CurPos = ContentPos.Get(Depth);
Depth++;
if(this.content[this.CurPos].value.typeObj == MATH_COMP)
this.content[this.CurPos].value.set_ParaContentPos(ContentPos, Depth);
Content = this.content[this.CurPos].value.set_ParaContentPos(ContentPos, Depth);
return Content;
},
set_SelectEndExtreme: function(bEnd)
{
if(bEnd === false)
{
this.LogicalSelect.end = 1;
this.RealSelect.endPos = 1;
// проверка на то, чтобы CEmpty был включен !!! когда идем из мат объекта(например из числителя) и идем наверх, выходим за пределы формулы
// если стоим в конце, то this.RealSelect.endPos равен this.content.length и соответственно, нужно сделать проверку на то, что запрашиваем у существующего объекта typeObj (!)
var start = this.RealSelect.startPos; // проверяем именно тот, который идет на отрисовку, т.к. логический мб выставлен на мат. объект
if(start < this.content.length)
{
var current = this.content[this.CurPos].value.typeObj;
var selectStart = this.content[start].value.typeObj; // only for draw select
if(current == MATH_COMP && selectStart == MATH_COMP)
{
this.RealSelect.startPos++;
}
}
}
else
{
this.LogicalSelect.end = this.content.length - 1;
this.RealSelect.endPos = this.content.length;
var start = this.RealSelect.startPos - 2,
current = this.content[this.CurPos].value.typeObj,
selectStart = start > 0 ? this.content[start].value.typeObj : null;
if(current == MATH_COMP && selectStart == MATH_COMP)
{
this.RealSelect.startPos -= 2;
}
}
},
set_StartSelectContent: function(ContentPos, Depth)
{
if(this.IsPlaceholder())
{
this.LogicalSelect.start = 1;
this.LogicalSelect.end = 2;
}
else
{
var pos = ContentPos.Get(Depth);
Depth++;
this.LogicalSelect.start = this.LogicalSelect.end = pos;
if(this.RealSelect.startPos === this.RealSelect.endPos && this.content[pos].value.typeObj === MATH_COMP)
this.content[pos].value.set_StartSelectContent(ContentPos, Depth);
}
},
set_EndSelectContent: function(ContentPos, Depth)
{
/*var msCoord = {x: x, y: y};
var posEnd = this.findPosition(msCoord),
posStart = this.LogicalSelect.start;
this.CurPos = posStart;
this.LogicalSelect.end = posEnd;*/
var state = true; // вышли / не вышли за переделы контента
// актуально для мат. объекта
var SelectContent = null;
var posEnd = ContentPos.Get(Depth),
posStart = this.LogicalSelect.start;
this.LogicalSelect.end = posEnd;
Depth++;
//селект внутри мат. объекта
if(posStart === posEnd && this.content[posEnd].value.typeObj === MATH_COMP)
{
var result = this.content[posEnd].value.set_EndSelectContent(ContentPos, Depth);
this.setStartPos_Selection(posStart-1);
if( !result.state )
{
this.setEndPos_Selection(posEnd + 1);
SelectContent = this;
}
else
SelectContent = result.SelectContent;
}
//селект элементов контента
else
{
SelectContent = this;
var direction = (posStart < posEnd) ? 1 : -1;
if( this.content[posStart].value.typeObj === MATH_COMP )
{
if( direction == 1 )
this.setStartPos_Selection( posStart - 1);
else if( direction == -1 )
this.setStartPos_Selection( posStart + 1);
}
else
this.setStartPos_Selection(posStart);
if( this.content[posEnd].value.typeObj === MATH_COMP )
{
if( direction == 1 )
this.setEndPos_Selection(posEnd + 1);
else if( direction == -1 )
this.setEndPos_Selection(posEnd - 1);
}
else
this.setEndPos_Selection(posEnd);
}
return {state: state, SelectContent: SelectContent};
},
drawSelect: function(SelectionDraw)
{
var start = this.RealSelect.startPos,
end = this.RealSelect.endPos;
if( start > end)
{
var tmp = start;
start = end;
end = tmp;
}
if(this.IsPlaceholder())
{
start = 1;
end = 2;
}
//var heightSelect = this.size.ascent + this.size.descent;
var heightSelect = this.size.height;
var widthSelect = 0;
for(var j= start; j < end ; j++)
widthSelect += this.content[j].widthToEl - this.content[j-1].widthToEl;
var startPos = start > 0 ? start-1 : start;
var X = this.pos.x + this.Composition.absPos.x + this.content[startPos].widthToEl,
Y = this.pos.y + this.Composition.absPos.y;
SelectionDraw.StartX = X;
SelectionDraw.StartY = Y;
SelectionDraw.W = widthSelect;
SelectionDraw.H = heightSelect;
},
Get_Id : function()
{
return this.GetId();
},
GetId : function()
{
return this.Id;
},
//////////////////////////
......@@ -7318,15 +7504,8 @@ CMathContent.prototype =
this.setEndPos_Selection(1);
//this.setEnd_Selection(1);
//this.selection.active = false;
},
Get_Id : function()
{
return this.GetId();
},
GetId : function()
{
return this.Id;
}
/////////////////////////////////////////////////////////////////
//// test function for me ////
......@@ -7914,6 +8093,8 @@ CMathComposition.prototype =
//this.SelectContent.selection.active = false;
this.UpdateCursor();
}*/
},
ClearSelect: function()
{
......@@ -8235,9 +8416,9 @@ CMathComposition.prototype =
History.Add(this.CurrentContent, {Type: historyitem_Math_AddItem, Items: items, Pos: Pos, PosEnd: EndPos});
},
UpdateCursor: function()
UpdateCursor: function(CurPage, UpdateTarget)
{
return this.SelectContent.update_Cursor();
return this.SelectContent.update_Cursor(CurPage, UpdateTarget);
},
Refresh_RecalcData2: function()
{
......
......@@ -232,6 +232,12 @@ CMathText.prototype =
},
Resize: function(oMeasure)
{
// смещения
// rasterOffsetX
// rasterOffsetY
var letter = this.getCode();
var metricsTxt = oMeasure.Measure2Code(letter);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment