Commit e4688b4e authored by Ilya.Kirillov's avatar Ilya.Kirillov Committed by Alexander.Trofimov

Полностью переделан селект и работа с курсором в формулах.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@58907 954022d7-b5bf-4e40-9824-e11837661b57
parent bbf10095
......@@ -1693,7 +1693,7 @@ ParaHyperlink.prototype.Get_EndPos = function(BehindEnd, ContentPos, Depth)
//-----------------------------------------------------------------------------------
ParaHyperlink.prototype.Set_SelectionContentPos = function(StartContentPos, EndContentPos, Depth, StartFlag, EndFlag)
{
var Selection = this.State.Selection;
var Selection = this.Selection;
var OldStartPos = Selection.StartPos;
var OldEndPos = Selection.EndPos;
......@@ -1783,7 +1783,7 @@ ParaHyperlink.prototype.Selection_Stop = function()
ParaHyperlink.prototype.Selection_Remove = function()
{
var Selection = this.State.Selection;
var Selection = this.Selection;
if ( true === Selection.Use )
{
......@@ -1814,22 +1814,22 @@ ParaHyperlink.prototype.Select_All = function(Direction)
{
var ContentLen = this.Content.length;
var Selection = this.State.Selection;
var Selection = this.Selection;
Selection.Use = true;
if ( -1 === Direction )
{
Selection.StartPos = this.Content.length - 1;
Selection.StartPos = ContentLen - 1;
Selection.EndPos = 0;
}
else
{
Selection.StartPos = 0;
Selection.EndPos = this.Content.length - 1;
Selection.EndPos = ContentLen - 1;
}
for ( var CurPos = 0; CurPos < this.Content.length; CurPos++ )
for ( var CurPos = 0; CurPos < ContentLen; CurPos++ )
{
this.Content[CurPos].Select_All( Direction );
}
......
......@@ -227,9 +227,10 @@ ParaMath.prototype.Remove = function(Direction, bOnAddText)
if (oContent.bRoot)
return false;
// Значит мы в каком-то элементе, тогда надо выделить данный элемент
var oParent = oContent.GetParent();
oParent.SetSelectAll();
oParent.SelectToParent(true);
oParent.Select_WholeElement();
oParent.Select_ToRoot();
this.bSelectionUse = true;
return true;
......@@ -255,8 +256,8 @@ ParaMath.prototype.Remove = function(Direction, bOnAddText)
}
else
{
oContent.SelectElement(nStartPos + 1);
oContent.SelectToParent(true);
oContent.Select_ElementByPos(nStartPos + 1);
oContent.Select_ToRoot();
this.bSelectionUse = true;
}
}
......@@ -280,8 +281,8 @@ ParaMath.prototype.Remove = function(Direction, bOnAddText)
}
else
{
oContent.SelectElement(nStartPos - 1);
oContent.SelectToParent(true);
oContent.Select_ElementByPos(nStartPos - 1);
oContent.Select_ToRoot();
this.bSelectionUse = true;
}
}
......@@ -305,6 +306,10 @@ ParaMath.prototype.Remove = function(Direction, bOnAddText)
oContent.Remove_FromContent(nStartPos, 1);
oContent.CurPos = nStartPos;
if (para_Math_Run === oContent.content[nStartPos].Type)
oContent.content[nStartPos].Cursor_MoveToStartPos();
oContent.Correct_Content();
oContent.Correct_ContentPos(-1); // -1, потому что нам надо встать перед элементом, а не после
......@@ -1081,12 +1086,6 @@ ParaMath.prototype.Get_Default_TPrp = function()
{
return this.DefaultTextPr;
};
ParaMath.prototype.Set_Select_ToMComp = function(Direction)
{
this.bSelectionUse = true;
this.Root.Set_Select_ToMComp(Direction);
};
//-----------------------------------------------------------------------------------
// Функции отрисовки
//-----------------------------------------------------------------------------------
......@@ -1191,18 +1190,13 @@ ParaMath.prototype.Cursor_MoveToEndPos = function(SelectFromEnd)
ParaMath.prototype.Get_ParaContentPosByXY = function(SearchPos, Depth, _CurLine, _CurRange, StepEnd, Flag) // получить логическую позицию по XY
{
// TODO: ParaMath.Get_ParaContentPosByXY
var Result = false;
var CurLine = _CurLine - this.StartLine;
var CurRange = ( 0 === CurLine ? _CurRange - this.StartRange : _CurRange ); // если находимся в нулевой строке (для текущей позиции), то CurRange мб ненулевой
var StartPos = this.protected_GetRangeStartPos(CurLine, CurRange);
var EndPos = this.protected_GetRangeEndPos(CurLine, CurRange);
// TODO: реализовать поиск по Y (для случая, когда формула занимает больше одной строки)
// Проверяем, попали ли мы в формулу
if ( EndPos >= 1 )
......@@ -1216,45 +1210,26 @@ ParaMath.prototype.Get_ParaContentPosByXY = function(SearchPos, Depth, _CurLine,
if ( D >= - 0.001 && D <= Dx + 0.001 )
{
SearchPos.DiffX = 0.001;
SearchPos.InText = true;
SearchPos.DiffX = 0.001;
SearchPos.InTextPos = SearchPos.Pos.Copy();
}
SearchPos.CurX = CurX + Dx;
}
return Result;
};
ParaMath.prototype.Get_ParaContentPos = function(bSelection, bStart, ContentPos) // получить текущую логическую позицию
{
// TODO: ParaMath.Get_ParaContentPos
this.Root.Get_ParaContentPos(bSelection, bStart, ContentPos);
return ContentPos;
};
ParaMath.prototype.Set_ParaContentPos = function(ContentPos, Depth) // выставить логическую позицию в контенте
{
// TODO: ParaMath.Set_ParaContentPos
//this.State.ContentPos = ContentPos.Get(Depth);
/*console.log("Set_ParaContentPos");
var str = "";
for(var i = 0; i < ContentPos.Data.length; i++)
{
str += ContentPos.Data[i] + " ";
}
console.log(str);*/
//console.log("Set_ParaContentPos");
this.Root.Set_ParaContentPos(ContentPos, Depth);
};
ParaMath.prototype.Get_PosByElement = function(Class, ContentPos, Depth, UseRange, Range, Line)
......@@ -1282,77 +1257,78 @@ ParaMath.prototype.Get_LastRunInRange = function(_CurLine, _CurRange)
ParaMath.prototype.Get_LeftPos = function(SearchPos, ContentPos, Depth, UseContentPos)
{
// TODO: ParaMath.Get_LeftPos
return this.Root.Get_LeftPos(SearchPos, ContentPos, Depth, UseContentPos, false);
};
ParaMath.prototype.Get_RightPos = function(SearchPos, ContentPos, Depth, UseContentPos, StepEnd)
{
// TODO: ParaMath.Get_RightPos
return this.Root.Get_RightPos(SearchPos, ContentPos, Depth, UseContentPos, StepEnd, false);
};
ParaMath.prototype.Get_WordStartPos = function(SearchPos, ContentPos, Depth, UseContentPos)
{
// TODO: ParaMath.Get_StartEndPos
this.Root.Get_WordStartPos(SearchPos, ContentPos, Depth, UseContentPos, false);
SearchPos.Found = true;
SearchPos.UpdatePos = true;
};
ParaMath.prototype.Get_WordEndPos = function(SearchPos, ContentPos, Depth, UseContentPos, StepEnd)
{
// TODO: ParaMath.Get_WordEndPos
this.Root.Get_WordEndPos(SearchPos, ContentPos, Depth, UseContentPos, StepEnd, false);
SearchPos.Found = true;
SearchPos.UpdatePos = true;
};
ParaMath.prototype.Get_EndRangePos = function(_CurLine, _CurRange, SearchPos, Depth)
{
// TODO: ParaMath.Get_EndRangePos
var CurLine = _CurLine - this.StartLine;
var CurRange = ( 0 === CurLine ? _CurRange - this.StartRange : _CurRange );
// Сделать для случая, когда формула будет занимать несколько строк
var EndPos = this.protected_GetRangeEndPos(CurLine, CurRange);
return this.Root.Get_EndRangePos(_CurLine, _CurRange, SearchPos, Depth);
if (EndPos >= 1)
{
// TODO: ParaMath.Get_EndRangePos Сделать для случая, когда формула будет занимать несколько строк
return this.Root.Get_EndPos(false, SearchPos.Pos, Depth);
}
return false;
};
ParaMath.prototype.Get_StartRangePos = function(_CurLine, _CurRange, SearchPos, Depth)
{
// TODO: ParaMath.Get_StartRangePos
var CurLine = _CurLine - this.StartLine;
var CurRange = ( 0 === CurLine ? _CurRange - this.StartRange : _CurRange );
// Сделать для случая, когда формула будет занимать несколько строк, переделать
var EndPos = this.protected_GetRangeEndPos(CurLine, CurRange);
return this.Root.Get_StartRangePos(_CurLine, _CurRange, SearchPos, Depth);
//this.Root.Get_StartPos(SearchPos.Pos, Depth);
if (EndPos >= 1)
{
// TODO: ParaMath.Get_StartRangePos Сделать для случая, когда формула будет занимать несколько строк
return this.Root.Get_StartPos(SearchPos.Pos, Depth);
}
return false;
};
ParaMath.prototype.Get_StartRangePos2 = function(_CurLine, _CurRange, ContentPos, Depth)
{
// TODO: ParaMath.Get_StartRangePos2
var CurLine = _CurLine - this.StartLine;
var CurRange = ( 0 === CurLine ? _CurRange - this.StartRange : _CurRange );
// Сделать для случая, когда формула будет занимать несколько строк, переделать
var EndPos = this.protected_GetRangeEndPos(CurLine, CurRange);
this.Root.Get_StartRangePos2(_CurLine, _CurRange, ContentPos, Depth);
if (EndPos >= 1)
{
// TODO: ParaMath.Get_StartRangePos2 Сделать для случая, когда формула будет занимать несколько строк
return this.Root.Get_StartPos(ContentPos, Depth);
}
};
return false;};
ParaMath.prototype.Get_StartPos = function(ContentPos, Depth)
{
// TODO: ParaMath.Get_StartPos
this.Root.Get_StartPos(ContentPos, Depth);
};
ParaMath.prototype.Get_EndPos = function(BehindEnd, ContentPos, Depth)
{
// TODO: ParaMath.Get_EndPos
this.Root.Get_EndPos(BehindEnd, ContentPos, Depth);
};
//-----------------------------------------------------------------------------------
......@@ -1360,35 +1336,27 @@ ParaMath.prototype.Get_EndPos = function(BehindEnd, ContentPos, Depth)
//-----------------------------------------------------------------------------------
ParaMath.prototype.Set_SelectionContentPos = function(StartContentPos, EndContentPos, Depth, StartFlag, EndFlag)
{
// TODO: ParaMath.Set_SelectionContentPos
this.Root.Set_SelectionContentPos(StartContentPos, EndContentPos, Depth, StartFlag, EndFlag);
this.bSelectionUse = true;
};
ParaMath.prototype.Selection_IsUse = function()
{
// TODO: ParaMath.Selection_IsUse
return this.bSelectionUse;
};
ParaMath.prototype.Selection_Stop = function()
{
};
ParaMath.prototype.Selection_Remove = function()
{
// TODO: ParaMath.Selection_Remove
this.bSelectionUse = false;
this.Root.Selection_Remove();
};
ParaMath.prototype.Select_All = function(Direction)
{
// TODO: ParaMath.Select_All
this.bSelectionUse = true;
this.Root.Select_All();
};
......@@ -1398,50 +1366,14 @@ ParaMath.prototype.Selection_DrawRange = function(_CurLine, _CurRange, Selection
var CurLine = _CurLine - this.StartLine;
var CurRange = ( 0 === CurLine ? _CurRange - this.StartRange : _CurRange );
var StartPos = this.protected_GetRangeStartPos(CurLine, CurRange);
var EndPos = this.protected_GetRangeEndPos(CurLine, CurRange);
if ( EndPos >= 1 )
if (EndPos >= 1)
{
if ( true === this.bSelectionUse )
if (true === this.bSelectionUse)
{
// TODO: ParaMath.Selection_Draw_Range
var result = this.GetSelectContent();
result.Content.Selection_DrawRange(_CurLine, _CurRange, SelectionDraw);
/*
var Start = result.Start,
End = result.End,
oCont = result.Content;
SelectionDraw.StartX += oCont.pos.x + oCont.WidthToElement[Start];
if(Start == End)
{
oCont.content[Start].Selection_DrawRange(_CurLine, _CurRange, SelectionDraw);
}
else
{
oCont.content[Start].Selection_DrawRange(_CurLine, _CurRange, SelectionDraw);
SelectionDraw.FindStart = false; // выставляем здесь флаг, для того чтобы правильно отрисовался селект для случая пустой ран мат. объект пустой ран
SelectionDraw.W += oCont.WidthToElement[End] - oCont.WidthToElement[Start + 1]; // startPos < endPos !
oCont.content[End].Selection_DrawRange(_CurLine, _CurRange, SelectionDraw);
}
if(!oCont.bRoot)
{
//SelectionDraw.StartY = this.Math.absPos.y + oCont.pos.y; // выставляем так, чтобы для формул с различной высотой в одной строке, всё было ok
SelectionDraw.StartY = this.Y + oCont.pos.y; // выставляем так, чтобы для формул с различной высотой в одной строке, всё было ok
SelectionDraw.H = oCont.size.height;
}*/
var oSelectedContent = this.GetSelectContent();
oSelectedContent.Content.Selection_DrawRange(_CurLine, _CurRange, SelectionDraw);
}
else
{
......@@ -1450,9 +1382,7 @@ ParaMath.prototype.Selection_DrawRange = function(_CurLine, _CurRange, Selection
SelectionDraw.StartX += this.Width;
}
}
}
};
ParaMath.prototype.Selection_IsEmpty = function(CheckEnd)
......
......@@ -12367,6 +12367,8 @@ CParagraphContentPos.prototype =
PRPos.Add( this.Data[Index] );
}
PRPos.Depth = this.Depth;
return PRPos;
},
......@@ -12669,6 +12671,7 @@ function CParagraphSearchPosXY()
this.CurX = 0;
this.CurY = 0;
this.X = 0;
this.Y = 0;
this.DiffX = 1000000; // километра для ограничения должно хватить
this.NumberingDiffX = 1000000; // километра для ограничения должно хватить
......
......@@ -644,27 +644,4 @@ CAccent.prototype.draw = function(x, y, pGraphics)
}
this.operator.draw(x, y, pGraphics);
}
CAccent.prototype.Get_ParaContentPosByXY = function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
var align = (this.size.width - this.elements[0][0].size.width - this.GapLeft - this.GapRight)/2;
SearchPos.CurX += this.GapLeft + align;
var result = this.elements[0][0].Get_ParaContentPosByXY(SearchPos, Depth+2, _CurLine, _CurRange, StepEnd);
if(result)
{
SearchPos.Pos.Update2(0, Depth);
SearchPos.Pos.Update2(0, Depth+1);
SearchPos.InTextPos.Update(0, Depth);
SearchPos.InTextPos.Update(0, Depth + 1);
}
SearchPos.CurX += this.GapRight + align;
return result;
}
\ No newline at end of file
......@@ -17,27 +17,6 @@ function CMathBase(bInside)
this.ArgSize = new CMathArgSize();
/////////////////
this.CurPos_X = 0;
this.CurPos_Y = 0;
this.SelectStart =
{
X: 0,
Y: 0,
bOutside: false
};
this.SelectEnd =
{
X: 0,
Y: 0,
bOutside: false
};
this.bSelectionUse = false;
this.nRow = 0;
this.nCol = 0;
......@@ -66,6 +45,14 @@ function CMathBase(bInside)
this.Content = [];
this.CurPos = 0;
this.Selection =
{
StartPos : 0,
EndPos : 0,
Use : false
};
return this;
}
......@@ -447,33 +434,6 @@ CMathBase.prototype =
setDistance: function()
{
},
getPosTwTarget: function()
{
var pos = this.elements[this.CurPos_X][this.CurPos_Y].getPosTwTarget();
var align = this.align(this.CurPos_X, this.CurPos_Y);
var maxWH = this.getWidthsHeights();
var Heights = maxWH.heights,
Widths = maxWH.widths;
for(var t = 0; t < this.CurPos_Y; t++)
pos.x += Widths[t];
for(var t = 0; t < this.CurPos_X; t++)
pos.y += Heights[t]; // на текущей позиции добавляем максимальную высоту строки, а не высоту элемента
var dist = this.findDistance();
pos.x += dist.w + align.x;
pos.y += dist.h + align.y;
return pos;
},
findDistance: function()
{
return {w : this.dW*this.CurPos_Y, h: this.dH*this.CurPos_X };
},
hidePlaceholder: function(flag)
{
......@@ -524,279 +484,6 @@ CMathBase.prototype =
return gaps;
},
/// Position for Paragraph
Get_ParaContentPosByXY: function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
var maxWH = this.getWidthsHeights();
var Widths = maxWH.widths;
var Heights = maxWH.heights;
var X = this.ParaMath.X + this.pos.x + this.GapLeft, // this.ParaMath.X + this.pos.x совпадает с SearchPos.CurX
Y = this.ParaMath.Y + this.pos.y;
var CurrX, CurrY,
W_CurX,
Diff = 100000000;
var W = 0, H = 0;
var rX, rY,
minR;
for(var i=0; i < this.nRow; i++)
{
for(var j=0; j < this.nCol; j++)
{
if(!this.elements[i][j].IsJustDraw())
{
/*rY = SearchPos.Y - Y - H;
rX = SearchPos.X - X - W;
R = rX*rX + rY*rY;
rrX = SearchPos.X - X - W - Widths[j];
rrY = SearchPos.Y - Y - H - Heights[i];
RR = rrX*rrX + rrY*rrY;*/
var x1 = SearchPos.X - X - W,
x2 = SearchPos.X - X - W - Widths[j],
y1 = SearchPos.Y - Y - H,
y2 = SearchPos.Y - Y - H - Heights[i];
var bInY = 0 < y1 && y2 < 0,
bInX = 0 < x1 && x2 < 0;
rX = x1*x1 < x2*x2 ? x1 : x2;
rY = y1*y1 < y2*y2 ? y1 : y2;
if(bInY && bInX)
minR = 0;
else if(!bInY && !bInX)
minR = rX*rX + rY*rY;
else if(bInY)
minR = rX*rX;
else
minR = rY*rY;
if(Diff > minR)
{
Diff = minR;
CurrX = i;
CurrY = j;
W_CurX = W;
}
}
W += Widths[j] + this.dW;
}
W = 0;
H += Heights[i] + this.dH;
}
var SearchCurX = SearchPos.CurX;
var align = this.align(CurrX, CurrY);
SearchPos.CurX += this.GapLeft + W_CurX + align.x;
/*if(SearchPos.CurX + this.GapLeft < SearchPos.X )
{
SearchPos.CurX += this.GapLeft;
for(var j = 0; j < CurrY; j++)
{
if(SearchPos.CurX + Widths[j] + this.dW > SearchPos.X)
{
if(SearchPos.CurX + Widths[j] < SearchPos.X)
SearchPos.CurX += Widths[j];
break;
}
SearchPos.CurX += Widths[j] + this.dW;
if(j == CurrY-1 && SearchPos.CurX + align.x < SearchPos.X)
SearchPos.CurX += align.x;
}
}*/
var result = this.elements[CurrX][CurrY].Get_ParaContentPosByXY(SearchPos, Depth+2, _CurLine, _CurRange, StepEnd);
if(result)
{
SearchPos.Pos.Update2(CurrX, Depth);
SearchPos.Pos.Update2(CurrY, Depth + 1);
SearchPos.InTextPos.Update(CurrX, Depth);
SearchPos.InTextPos.Update(CurrY, Depth + 1);
}
SearchPos.CurX = SearchCurX + this.size.width;
return result;
},
Get_ParaContentPos: function(bSelection, bStart, ContentPos)
{
if( bSelection )
{
var oSelect;
if(bStart)
oSelect = this.SelectStart;
else
oSelect = this.SelectEnd;
ContentPos.Add(oSelect.X);
ContentPos.Add(oSelect.Y);
if(!oSelect.bOutside && !this.elements[oSelect.X][oSelect.Y].IsJustDraw())
this.elements[oSelect.X][oSelect.Y].Get_ParaContentPos(bSelection, bStart, ContentPos);
}
else
{
ContentPos.Add(this.CurPos_X);
ContentPos.Add(this.CurPos_Y);
this.elements[this.CurPos_X][this.CurPos_Y].Get_ParaContentPos(bSelection, bStart, ContentPos);
}
},
Set_ParaContentPos: function(ContentPos, Depth)
{
var CurPos_X = ContentPos.Get(Depth);
var CurPos_Y = ContentPos.Get(Depth + 1);
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_SelectionContentPos: function(StartContentPos, EndContentPos, Depth, StartFlag, EndFlag)
{
if(StartFlag === 0)
{
this.SelectStart.X = StartContentPos.Get(Depth);
this.SelectStart.Y = StartContentPos.Get(Depth + 1);
this.SelectStart.bOutside = false;
}
else
{
this.SelectStart.bOutside = true;
}
if(EndFlag === 0)
{
this.SelectEnd.X = EndContentPos.Get(Depth);
this.SelectEnd.Y = EndContentPos.Get(Depth + 1);
this.SelectEnd.bOutside = false;
}
else /// в случае, если закончили селект на уровень выше, а нужно выставить начало селекта во внутреннем элементе мат объекта
{
this.SelectEnd.bOutside = true;
}
Depth += 2;
if(!this.SelectEnd.bOutside && !this.SelectStart.bOutside)
{
var startX = this.SelectStart.X,
startY = this.SelectStart.Y;
var endX = this.SelectEnd.X,
endY = this.SelectEnd.Y;
var bJustDraw = this.elements[this.SelectStart.X][this.SelectStart.Y].IsJustDraw();
if(startX == endX && startY == endY)
{
if(!bJustDraw)
this.elements[startX][startY].Set_SelectionContentPos(StartContentPos, EndContentPos, Depth, StartFlag, EndFlag);
else
this.elements[startX][startY].Set_SelectionContentPos(StartContentPos, null, Depth, StartFlag, -1);
}
}
this.bSelectionUse = true;
},
Selection_IsEmpty: function()
{
var result = false;
if(this.IsSelectEmpty())
result = this.elements[this.SelectStart.X][this.SelectStart.Y].Selection_IsEmpty();
return result;
},
IsSelectEmpty: function()
{
var startX = this.SelectStart.X,
startY = this.SelectStart.Y;
var endX = this.SelectEnd.X,
endY = this.SelectEnd.Y;
var bEqual = (startX == endX) && (startY == endY);
var bInsideSelect = bEqual && this.elements[startX][startY].bInside == true && !this.elements[startX][startY].IsSelectEmpty();
return (!this.SelectStart.bOutside && !this.SelectEnd.bOutside) && bEqual && !bInsideSelect;
},
Recalculate_CurPos: function(_X, Y, CurrentRun, _CurRange, _CurLine, _CurPage, UpdateCurPos, UpdateTarget, ReturnTarget)
{
return this.elements[this.CurPos_X][this.CurPos_Y].Recalculate_CurPos(_X, Y, CurrentRun, _CurRange, _CurLine, _CurPage, UpdateCurPos, UpdateTarget, ReturnTarget);
},
GetSelectContent: function()
{
var result;
if(this.bSelectionUse)
result = this.elements[this.SelectStart.X][this.SelectStart.Y].GetSelectContent();
else
result = this.elements[this.CurPos_X][this.CurPos_Y].GetSelectContent();
return result;
},
Selection_DrawRange: function(CurLine, CurPage, SelectionDraw) // первые два параметра нужны только для аналогичной функции в ParaRun
{
if(SelectionDraw.FindStart == false)
{
SelectionDraw.W += this.size.width;
}
/*else
{
SelectionDraw.StartX += this.size.width;
}*/
//SelectionDraw.FindStart = true;
},
SetRunEmptyToContent: function(bAll)
{
for(var i=0; i < this.nRow; i++)
for(var j = 0; j < this.nCol; j++)
if(!this.elements[i][j].IsJustDraw())
this.elements[i][j].SetRunEmptyToContent(bAll);
},
Selection_Remove: function()
{
var start_X = this.SelectStart.X,
start_Y = this.SelectStart.Y;
// проверка на bSelectionUse, чтобы избежать ситуации, когда селекта в этом элементе не было
if(!this.SelectStart.bOutside && this.bSelectionUse) // и нужно очистить селект у всех незаселекченных элементов контента (в тч и этом) в функции Selection_DrawRange. а стартовая и конечная позиции совпадают и в стартовой позиции находится JustDraw-элемент
this.elements[start_X][start_Y].Selection_Remove();
this.bSelectionUse = false;
},
SetGaps: function(GapsInfo)
{
this.Parent = GapsInfo.Parent;
......@@ -813,232 +500,7 @@ CMathBase.prototype =
GapsInfo.setGaps();
},
/*ApplyGaps: function()
{
this.size.width += this.GapLeft + this.GapRight;
},*/
Recalculate_Reset: function(StartRange, StartLine)
{
for(var i=0; i < this.nRow; i++)
for(var j = 0; j < this.nCol; j++)
if(this.elements[i][j].IsJustDraw() == false)
this.elements[i][j].Recalculate_Reset(StartRange, StartLine);
},
// Перемещение по стрелкам
Get_LeftPos: function(SearchPos, ContentPos, Depth, UseContentPos, EndRun)
{
var CurPos_X, CurPos_Y;
if(UseContentPos === true)
{
CurPos_X = ContentPos.Get(Depth);
CurPos_Y = ContentPos.Get(Depth + 1);
}
else if(SearchPos.ForSelection == true && this.SelectEnd.bOutside === true)
{
CurPos_X = this.SelectEnd.X;
CurPos_Y = this.SelectEnd.Y;
}
else
{
CurPos_X = this.nRow - 1;
CurPos_Y = this.nCol - 1;
}
while(CurPos_X >= 0)
{
while(CurPos_Y >= 0)
{
var bJDraw = this.elements[CurPos_X][CurPos_Y].IsJustDraw(),
usePlh = !bJDraw && UseContentPos && this.elements[CurPos_X][CurPos_Y].IsPlaceholder();
if(!bJDraw && !usePlh)
{
this.elements[CurPos_X][CurPos_Y].Get_LeftPos(SearchPos, ContentPos, Depth + 2, UseContentPos, EndRun);
SearchPos.Pos.Update(CurPos_X, Depth);
SearchPos.Pos.Update(CurPos_Y, Depth+1);
}
if(SearchPos.Found === true || SearchPos.ForSelection == true)
break;
CurPos_Y--;
UseContentPos = false;
EndRun = true;
}
if(SearchPos.Found === true)
break;
CurPos_X--;
CurPos_Y = this.nCol - 1;
}
return SearchPos.Found;
},
Get_RightPos: function(SearchPos, ContentPos, Depth, UseContentPos, StepEnd, BegRun)
{
var CurPos_X, CurPos_Y;
if(UseContentPos === true)
{
CurPos_X = ContentPos.Get(Depth);
CurPos_Y = ContentPos.Get(Depth + 1);
}
else if(SearchPos.ForSelection == true && this.SelectEnd.bOutside === true)
{
CurPos_X = this.SelectEnd.X;
CurPos_Y = this.SelectEnd.Y;
}
else
{
CurPos_X = 0;
CurPos_Y = 0;
}
while(CurPos_X < this.nRow)
{
while(CurPos_Y < this.nCol)
{
var bJDraw = this.elements[CurPos_X][CurPos_Y].IsJustDraw(),
usePlh = !bJDraw && UseContentPos && this.elements[CurPos_X][CurPos_Y].IsPlaceholder();
if(!bJDraw && !usePlh)
{
this.elements[CurPos_X][CurPos_Y].Get_RightPos(SearchPos, ContentPos, Depth + 2, UseContentPos, StepEnd, BegRun);
SearchPos.Pos.Update(CurPos_X, Depth);
SearchPos.Pos.Update(CurPos_Y, Depth+1);
}
if(SearchPos.Found === true || SearchPos.ForSelection == true)
break;
CurPos_Y++;
UseContentPos = false;
BegRun = true;
}
if(SearchPos.Found === true)
break;
CurPos_X++;
CurPos_Y = 0;
}
return SearchPos.Found;
},
Get_WordStartPos: function(SearchPos, ContentPos, Depth, UseContentPos, EndRun)
{
var CurPos_X, CurPos_Y;
if(UseContentPos === true)
{
CurPos_X = ContentPos.Get(Depth);
CurPos_Y = ContentPos.Get(Depth + 1);
}
else if(SearchPos.ForSelection == true && this.SelectEnd.bOutside === true)
{
CurPos_X = this.SelectEnd.X;
CurPos_Y = this.SelectEnd.Y;
}
else
{
CurPos_X = this.nRow - 1;
CurPos_Y = this.nCol - 1;
}
var bUseContent = UseContentPos;
while(CurPos_X >= 0)
{
while(CurPos_Y >= 0)
{
var bJDraw = this.elements[CurPos_X][CurPos_Y].IsJustDraw(),
usePlh = !bJDraw && bUseContent && this.elements[CurPos_X][CurPos_Y].IsPlaceholder();
if(!bJDraw && !usePlh)
{
this.elements[CurPos_X][CurPos_Y].Get_WordStartPos(SearchPos, ContentPos, Depth + 2, bUseContent, EndRun);
SearchPos.Pos.Update(CurPos_X, Depth);
SearchPos.Pos.Update(CurPos_Y, Depth+1);
}
if(SearchPos.Found === true)
break;
CurPos_Y--;
bUseContent = false;
EndRun = true;
}
if(SearchPos.Found === true || SearchPos.ForSelection == true)
break;
CurPos_X--;
CurPos_Y = this.nCol - 1;
}
},
Get_WordEndPos : function(SearchPos, ContentPos, Depth, UseContentPos, StepEnd, BegRun)
{
var CurPos_X, CurPos_Y;
if(UseContentPos === true)
{
CurPos_X = ContentPos.Get(Depth);
CurPos_Y = ContentPos.Get(Depth + 1);
}
else if(SearchPos.ForSelection == true && this.SelectEnd.bOutside === true)
{
CurPos_X = this.SelectEnd.X;
CurPos_Y = this.SelectEnd.Y;
}
else
{
CurPos_X = 0;
CurPos_Y = 0;
}
var bUseContent = UseContentPos;
while(CurPos_X < this.nRow)
{
while(CurPos_Y < this.nCol)
{
var bJDraw = this.elements[CurPos_X][CurPos_Y].IsJustDraw(),
usePlh = !bJDraw && bUseContent && this.elements[CurPos_X][CurPos_Y].IsPlaceholder();
if(!bJDraw && !usePlh)
{
this.elements[CurPos_X][CurPos_Y].Get_WordEndPos(SearchPos, ContentPos, Depth + 2, bUseContent, StepEnd, BegRun);
SearchPos.Pos.Update(CurPos_X, Depth);
SearchPos.Pos.Update(CurPos_Y, Depth+1);
}
if(SearchPos.Found === true)
break;
CurPos_Y++;
bUseContent = false;
BegRun = true;
}
if(SearchPos.Found === true || SearchPos.ForSelection == true)
break;
CurPos_X++;
CurPos_Y = 0;
}
},
//////////////////////////////////
IsPlaceholder: function()
{
......@@ -1048,23 +510,6 @@ CMathBase.prototype =
{
return (this.Parent.Type !== para_Math_Composition ? this : this.Parent.GetParent());
},
Copy: function(Selected)
{
var props = Common_CopyObj(this.Pr);
props.ctrPrp = this.CtrPrp.Copy();
var NewObj = new this.constructor();
NewObj.init(props);
for(var i=0; i < this.nRow; i++)
for(var j = 0; j < this.nCol; j++)
{
NewObj.elements[i][j] = this.elements[i][j].Copy(Selected);
}
return NewObj;
},
Get_TextPr: function(ContentPos, Depth)
{
var row = ContentPos.Get(Depth),
......@@ -1153,87 +598,20 @@ CMathBase.prototype =
if (null !== this.ParaMath)
this.ParaMath.SetNeedResize();
},
Set_Select_ToMComp: function(Direction)
{
this.SelectStart.X = this.SelectEnd.X = this.CurPos_X;
this.SelectStart.Y = this.SelectEnd.Y = this.CurPos_Y;
this.elements[this.CurPos_X][this.CurPos_Y].Set_Select_ToMComp(Direction);
},
SetSelectAll: function()
{
this.SelectStart.bOutside = true;
this.SelectEnd.bOutside = true;
this.bSelectionUse = true;
},
SelectToParent: function(bCorrect)
{
this.bSelectionUse = true;
this.Parent.SelectToParent(bCorrect);
},
Check_NearestPos: function(ParaNearPos, Depth)
{
var ContentNearPos = new CParagraphElementNearPos();
ContentNearPos.NearPos = ParaNearPos.NearPos;
ContentNearPos.Depth = Depth;
// CParagraphNearPos for ParaNearPos
this.NearPosArray.push( ContentNearPos );
ParaNearPos.Classes.push( this );
var CurPos_X = ParaNearPos.NearPos.ContentPos.Get(Depth),
CurPos_Y = ParaNearPos.NearPos.ContentPos.Get(Depth + 1);
this.Content[CurPos_X][CurPos_Y].Check_NearestPos( ParaNearPos, Depth + 2 );
},
Create_FontMap : function(Map)
{
var CtrPrp = this.Get_CompiledCtrPrp();
CtrPrp.Document_CreateFontMap( Map, this.ParaMath.Paragraph.Get_Theme().themeElements.fontScheme);
for(var i=0; i < this.nRow; i++)
for(var j = 0; j < this.nCol; j++)
{
if(!this.elements[i][j].IsJustDraw())
this.elements[i][j].Create_FontMap( Map );
}
},
Get_AllFontNames: function(AllFonts)
{
this.CtrPrp.Document_Get_AllFontNames( AllFonts );
}
//////////////////////////
};
for(var i=0; i < this.nRow; i++)
for(var j = 0; j < this.nCol; j++)
{
if(!this.elements[i][j].IsJustDraw())
this.elements[i][j].Get_AllFontNames(AllFonts);
}
},
Undo: function(Data)
{
Data.Undo(this);
},
Redo: function(Data)
{
Data.Redo(this);
},
Refresh_RecalcData: function()
{
if(this.ParaMath !== null)
this.ParaMath.Refresh_RecalcData(); // Refresh_RecalcData сообщает родительскому классу, что у него произошли изменения, нужно пересчитать
},
Save_Changes: function(Data, Writer)
{
WriteChanges_ToBinary(Data, Writer);
},
Load_Changes : function(Reader)
CMathBase.prototype.Recalculate_Reset = function(StartRange, StartLine)
{
for (var nPos = 0, nCount = this.Content.length; nPos < nCount; nPos++)
{
ReadChanges_FromBinary(Reader, this);
this.Content[nPos].Recalculate_Reset(StartRange, StartLine);
}
//////////////////////////
};
CMathBase.prototype.Fill_LogicalContent = function(nCount)
......@@ -1257,6 +635,8 @@ CMathBase.prototype.Copy = function()
};
CMathBase.prototype.Refresh_RecalcData = function(Data)
{
if(this.ParaMath !== null)
this.ParaMath.Refresh_RecalcData(); // Refresh_RecalcData сообщает родительскому классу, что у него произошли изменения, нужно пересчитать
};
CMathBase.prototype.Write_ToBinary2 = function( Writer )
{
......@@ -1317,7 +697,6 @@ CMathBase.prototype.setProperties = function(oProps)
this.RecalcInfo.bProps = true;
}
CMathBase.prototype.Correct_Content = function(bInnerCorrection)
{
var nCount = this.Content.length;
......@@ -1326,7 +705,157 @@ CMathBase.prototype.Correct_Content = function(bInnerCorrection)
this.Content[nIndex].Correct_Content(bInnerCorrection);
}
};
CMathBase.prototype.Undo = function(Data)
{
Data.Undo(this);
};
CMathBase.prototype.Redo = function(Data)
{
Data.Redo(this);
};
CMathBase.prototype.Save_Changes = function(Data, Writer)
{
WriteChanges_ToBinary(Data, Writer);
};
CMathBase.prototype.Load_Changes = function(Reader)
{
ReadChanges_FromBinary(Reader, this);
};
CMathBase.prototype.Get_AllFontNames = function(AllFonts)
{
this.CtrPrp.Document_Get_AllFontNames(AllFonts);
for (var nIndex = 0, nCount = this.Content.length; nIndex < nCount; nIndex++)
{
this.Content[nIndex].Get_AllFontNames(AllFonts);
}
};
CMathBase.prototype.Create_FontMap = function(Map)
{
if (null === this.ParaMath)
return;
var CtrPrp = this.Get_CompiledCtrPrp();
CtrPrp.Document_CreateFontMap(Map, this.ParaMath.Paragraph.Get_Theme().themeElements.fontScheme);
for (var nIndex = 0, nCount = this.Content.length; nIndex < nCount; nIndex++)
this.Content[nIndex].Create_FontMap(Map);
};
CMathBase.prototype.Recalculate_CurPos = function(_X, Y, CurrentRun, _CurRange, _CurLine, _CurPage, UpdateCurPos, UpdateTarget, ReturnTarget)
{
return this.Content[this.CurPos].Recalculate_CurPos(_X, Y, CurrentRun, _CurRange, _CurLine, _CurPage, UpdateCurPos, UpdateTarget, ReturnTarget);
};
CMathBase.prototype.Get_ParaContentPosByXY = function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
var nCount = this.Content.length;
if (nCount <= 0)
return false;
var aBounds = [];
for (var nIndex = 0; nIndex < nCount; nIndex++)
{
aBounds.push(this.Content[nIndex].Get_Bounds());
}
var X = SearchPos.X;
var Y = SearchPos.Y;
var dDiff = null;
var nCurIndex = 0;
var nFindIndex = 0;
while (nCurIndex < nCount)
{
var oBounds = aBounds[nCurIndex];
if (oBounds.X <= X && X <= oBounds.X + oBounds.W && oBounds.Y <= Y && Y <= oBounds.Y + oBounds.H)
{
nFindIndex = nCurIndex;
break;
}
else
{
var dCurDiffX = Math.min(Math.abs(X - oBounds.X), Math.abs(X - oBounds.X - oBounds.W));
var dCurDiffY = Math.min(Math.abs(Y - oBounds.Y), Math.abs(Y - oBounds.Y - oBounds.H));
var dCurDiff = Math.min(dCurDiffX, dCurDiffY);
if (null === dDiff || dDiff > dCurDiff)
{
dDiff = dCurDiff;
nFindIndex = nCurIndex;
}
}
nCurIndex++;
}
SearchPos.CurX = aBounds[nFindIndex].X;
SearchPos.CurY = aBounds[nFindIndex].Y;
var bResult = this.Content[nFindIndex].Get_ParaContentPosByXY(SearchPos, Depth + 1, _CurLine, _CurRange, StepEnd);
if(true === bResult)
{
SearchPos.Pos.Update2(nFindIndex, Depth);
}
return bResult;
};
CMathBase.prototype.Get_ParaContentPos = function(bSelection, bStart, ContentPos)
{
var nPos = (true !== bSelection ? this.CurPos : (false !== bStart ? this.Selection.StartPos : this.Selection.EndPos));
ContentPos.Add(nPos);
if (undefined !== this.Content[nPos])
this.Content[nPos].Get_ParaContentPos(bSelection, bStart, ContentPos);
};
CMathBase.prototype.Set_ParaContentPos = function(ContentPos, Depth)
{
this.CurPos = ContentPos.Get(Depth);
if (undefined !== this.Content[this.CurPos])
this.Content[this.CurPos].Set_ParaContentPos(ContentPos, Depth + 1);
};
CMathBase.prototype.Selection_IsEmpty = function()
{
if (true !== this.Selection.Use)
return true;
if (this.Selection.StartPos === this.Selection.EndPos)
return this.Content[this.Selection.StartPos].Selection_IsEmpty();
return false;
};
CMathBase.prototype.GetSelectContent = function()
{
var nPos = (true === this.Selection.Use ? this.Selection.StartPos : this.CurPos);
return this.Content[nPos].GetSelectContent();
};
CMathBase.prototype.Is_InnerSelection = function()
{
if (true === this.Selection.Use && this.Selection.StartPos === this.Selection.EndPos)
return true;
return false;
};
CMathBase.prototype.Select_ToRoot = function()
{
if (null !== this.Parent)
this.Parent.Select_ToRoot();
};
CMathBase.prototype.Select_WholeElement = function()
{
if (null !== this.Parent)
this.Parent.Select_Element(this);
};
CMathBase.prototype.Set_SelectionContentPos = ParaHyperlink.prototype.Set_SelectionContentPos;
CMathBase.prototype.Get_LeftPos = ParaHyperlink.prototype.Get_LeftPos;
CMathBase.prototype.Get_RightPos = ParaHyperlink.prototype.Get_RightPos;
CMathBase.prototype.Get_WordStartPos = ParaHyperlink.prototype.Get_WordStartPos;
CMathBase.prototype.Get_WordEndPos = ParaHyperlink.prototype.Get_WordEndPos;
CMathBase.prototype.Selection_Remove = ParaHyperlink.prototype.Selection_Remove;
CMathBase.prototype.Select_All = ParaHyperlink.prototype.Select_All;
function CMathBasePr()
{
......
......@@ -338,29 +338,6 @@ CBorderBox.prototype.setPosition = function(pos, PosInfo)
this.elements[0][0].setPosition(NewPos, PosInfo);
}
CBorderBox.prototype.Get_ParaContentPosByXY = function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
var alignLeft = this.Pr.hideLeft ? 0 : this.gapBrd,
alignRight = this.Pr.hideRight ? 0 : this.gapBrd;
SearchPos.CurX += this.GapLeft + alignLeft;
var result = this.elements[0][0].Get_ParaContentPosByXY(SearchPos, Depth+2, _CurLine, _CurRange, StepEnd);
if(result)
{
SearchPos.Pos.Update2(0, Depth);
SearchPos.Pos.Update2(0, Depth + 1);
SearchPos.InTextPos.Update(0, Depth);
SearchPos.InTextPos.Update(0, Depth + 1);
}
SearchPos.CurX += this.GapRight + alignRight;
return result;
}
function CMathBoxPr()
{
......
......@@ -254,8 +254,8 @@ CDegree.prototype.init = function(props)
};
CDegree.prototype.fillContent = function()
{
this.iterContent = this.Content[0];
this.baseContent = this.Content[1];
this.iterContent = this.Content[1];
this.baseContent = this.Content[0];
CDegree.superclass.fillContent.apply(this, arguments);
};
......@@ -558,8 +558,16 @@ CDegreeSubSup.prototype.init = function(props)
CDegreeSubSup.prototype.fillContent = function()
{
this.baseContent = this.Content[2];
this.iters = new CIterators(this.Content[1], this.Content[0]);
if (DEGREE_SubSup === this.Pr.type)
{
this.baseContent = this.Content[0];
this.iters = new CIterators(this.Content[2], this.Content[1]);
}
else
{
this.baseContent = this.Content[2];
this.iters = new CIterators(this.Content[1], this.Content[0]);
}
CDegreeSubSup.superclass.fillContent.apply(this, arguments);
};
......@@ -382,236 +382,6 @@ function CMathGapsInfo(oMeasure, Parent, argSize)
}
CMathGapsInfo.prototype =
{
/*old_checkGapsSign: function(oMeasure, posCurr)
{
var left = null,
right = null;
var curr = this.content[posCurr].value;
if(this.argSize < 0)
{
// выставим нулевые gaps для случая, если при копировании/вставки часть контента добавили в итератор
this.content[posCurr].gaps.left = 0;
this.content[posCurr].gaps.right = 0;
}
else
{
var EQUAL = 0x3D,
PLUS = 0x2B,
MINUS = 0x2212,
MULT = 0x2217,
LESS = 0x3C,
GREATER = 0x3E;
var t = posCurr - 1;
while( t > 0 )
{
if(this.content[t].value.typeObj == MATH_TEXT || this.content[t].value.typeObj == MATH_COMP)
{
left = this.content[t].value;
break;
}
t--;
}
t = posCurr + 1;
while( t < this.content.length )
{
if(this.content[t].value.typeObj == MATH_TEXT || this.content[t].value.typeObj == MATH_COMP)
{
right = this.content[t].value;
break;
}
t++;
}
var coeffLeft = 0,
coeffRight = 0;
var bLeft = left !== null,
bRight = right !== null;
var bLeftComp = bLeft ? left.typeObj == MATH_COMP : false,
bRightComp = bRight ? right.typeObj == MATH_COMP : false,
bLeftText = bLeft ? left.typeObj == MATH_TEXT : false,
bRightText = bRight ? right.typeObj == MATH_TEXT : false;
var currCode = curr.typeObj == MATH_TEXT ? curr.getCodeChr() : null,
leftCode = bLeftText ? left.getCodeChr() : null,
rightCode = bRightText ? right.getCodeChr() : null;
var gapLeftComp = 0,
gapRightComp = 0;
if(bLeftComp)
gapLeftComp = this.getGapsMComp(left).right;
if(bRightComp)
gapRightComp = this.getGapsMComp(right).left;
if(curr.typeObj == MATH_TEXT)
{
var bSign = false;
if(this.checkOperSign(currCode)) // plus, minus, greater, less
{
bSign = true;
if(bLeft)
{
if(this.checkZeroSign(leftCode))
coeffLeft = 0;
else if(leftCode == EQUAL)
coeffLeft = 0.26;
else
coeffLeft = 0.52;
}
if(bRight)
{
var bZero = this.checkZeroSign(rightCode);
if(rightCode == EQUAL || bZero)
coeffRight = 0;
else
coeffRight = 0.49;
}
}
else if(currCode === MULT) // multiplication
{
bSign = true;
if(bLeft)
{
var bZeroLeft = this.checkZeroSign(leftCode),
bOperLeft = this.checkOperSign(leftCode);
if(leftCode == EQUAL || bOperLeft || bZeroLeft)
coeffLeft = 0;
else if(bLeft)
coeffLeft = 0.46;
}
if(bRight)
{
var bZeroRight = this.checkZeroSign(rightCode),
bOperRight = this.checkOperSign(rightCode);
if(rightCode == EQUAL || bOperRight || bZeroRight)
coeffRight = 0;
else if(bRight)
coeffRight = 0.49;
}
}
else if(currCode === EQUAL) // equal
{
bSign = true;
if(bLeft)
{
var bZero = this.checkZeroSign(leftCode);
if(leftCode == EQUAL || bZero)
coeffLeft = 0;
else if(this.checkOperSign(leftCode))
coeffLeft = 0.35;
else
coeffLeft = 0.7;
}
if(bRight)
{
var bZero = this.checkZeroSign(rightCode);
if(rightCode == EQUAL || bZero)
coeffRight = 0;
else if(this.checkOperSign(rightCode))
coeffRight = 0.25;
else
coeffRight = 0.5;
}
}
if(bSign && bLeftComp)
coeffLeft = coeffLeft - gapLeftComp;
if(bSign && bRightComp)
coeffRight = coeffRight - gapRightComp;
coeffLeft = Math.ceil(coeffLeft*10)/10;
coeffRight = Math.ceil(coeffRight*10)/10;
}
else if(curr.typeObj == MATH_COMP)
{
var currGaps = this.getGapsMComp(curr);
if(bLeft)
{
coeffLeft = currGaps.left;
if(bLeftComp)
{
if(gapLeftComp/2 < coeffLeft)
coeffLeft = gapLeftComp/2;
}
}
if(bRight)
{
coeffRight = currGaps.right;
if(bRightComp)
{
if(coeffRight/2 > gapRightComp )
coeffRight -= gapRightComp;
else
coeffRight /=2;
}
}
}
if(bLeftText)
{
if(leftCode == 0x28 || leftCode == 0x5B || leftCode == 0x7B)
coeffLeft = 0;
}
if(bRightText)
{
if(rightCode == 0x29 || rightCode == 0x5D || rightCode == 0x7D)
coeffRight = 0;
}
var runPrp = this.getRunPrp(posCurr);
var oWPrp = runPrp.getMergedWPrp();
this.applyArgSize(oWPrp);
var gapSign = 0.1513*oWPrp.FontSize;
this.content[posCurr].gaps.left = Math.ceil(coeffLeft*gapSign*10)/10; // если ни один случай не выполнился, выставляем "нулевые" gaps (default): необходимо, если что-то удалили и объект стал первый или последним в контенте
this.content[posCurr].gaps.right = Math.ceil(coeffRight*gapSign*10)/10;
*//*if(this.bRoot)
{
if(bSign)
{
var code = this.content[posCurr].value.getCodeChr();
console.log(" " + String.fromCharCode(code));
}
else if(curr.typeObj == MATH_COMP)
{
console.log(curr.constructor.name + " :")
}
if(bSign || curr.typeObj == MATH_COMP)
{
console.log("coeff left " + coeffLeft + ", coeff right " + coeffRight );
console.log("gap left : " + this.content[posCurr].gaps.left + ", gap right : " + this.content[posCurr].gaps.right);
console.log("");
}
}*//*
}
},*/
setGaps: function()
{
if(this.argSize < 0)
......@@ -1405,14 +1175,6 @@ CMathContent.prototype =
var CurPos = ParaNearPos.NearPos.ContentPos.Get(Depth);
this.Content[CurPos].Check_NearestPos( ParaNearPos, Depth + 1 );
},
Recalculate_Reset: function(StartRange, StartLine)
{
for(var i = 0; i < this.content.length; i++)
{
//if(this.content[i].typeObj !== MATH_PLACEHOLDER)
this.content[i].Recalculate_Reset(StartRange, StartLine);
}
},
GetParent: function()
{
return this.Parent.GetParent();
......@@ -1426,125 +1188,6 @@ CMathContent.prototype =
// Поиск позиции, селект
Set_SelectionContentPos: function(StartContentPos, EndContentPos, Depth, StartFlag, EndFlag)
{
var posStart, posEnd;
switch(StartFlag)
{
case 0:
posStart = StartContentPos.Get(Depth);
break;
case 1:
posStart = 0;
break;
case -1:
posStart = this.content.length - 1;
}
switch(EndFlag)
{
case 0:
posEnd = EndContentPos.Get(Depth);
break;
case 1:
posEnd = 0;
break;
case -1:
posEnd = this.content.length - 1;
}
this.Selection.Start = posStart;
this.Selection.End = posEnd;
Depth++;
if(this.IsPlaceholder())
{
this.content[0].Set_SelectionContentPos(StartContentPos, EndContentPos, Depth, StartFlag, EndFlag);
}
else if(posStart < this.content.length)
{
if(posStart == posEnd)
{
this.content[posStart].Set_SelectionContentPos(StartContentPos, EndContentPos, Depth, StartFlag, EndFlag);
}
else
{
if(posStart > posEnd)
{
this.content[posStart].Set_SelectionContentPos(StartContentPos, null, Depth, StartFlag, 1);
this.content[posEnd].Set_SelectionContentPos(null, EndContentPos, Depth, -1, EndFlag);
}
else
{
this.content[posStart].Set_SelectionContentPos(StartContentPos, null, Depth, StartFlag, -1);
this.content[posEnd].Set_SelectionContentPos(null, EndContentPos, Depth, 1, EndFlag);
}
}
}
this.Selection.Use = true;
},
GetSelectContent: function()
{
var startPos, endPos;
if(this.Selection.Use)
{
startPos = this.Selection.Start;
endPos = this.Selection.End;
if(startPos > endPos)
{
var temp = startPos;
startPos = endPos;
endPos = temp;
}
}
else
startPos = endPos = this.CurPos;
var bEqual = startPos == endPos,
bNotSelectComp = bEqual ? this.content[startPos].Type === para_Math_Composition && this.content[startPos].IsSelectEmpty() : false;
var result;
if(bNotSelectComp)
result = this.content[startPos].GetSelectContent(); // startPos == endPos
else
result = {Content: this, Start: startPos, End: endPos};
return result;
},
Select_All: function()
{
this.Selection.Start = 0;
this.Selection.End = this.content.length - 1;
this.Selection.Use = true;
if(this.content[this.Selection.Start].Type == para_Math_Run)
this.content[this.Selection.Start].Select_All();
if(this.content[this.Selection.End].Type == para_Math_Run)
this.content[this.Selection.End].Select_All();
},
SelectElement : function(nPos)
{
this.Selection.Start = nPos;
this.Selection.End = nPos;
this.Selection.Use = true;
if(para_Math_Run === this.content[this.Selection.Start].Type)
this.content[this.Selection.Start].Select_All();
else
this.content[this.Selection.Start].SetSelectAll();
},
Correct_Selection : function()
{
if (true !== this.Selection.Use)
......@@ -1600,102 +1243,9 @@ CMathContent.prototype =
return bFirst && bEnd;
},
Selection_IsEmpty: function()
{
var startPos = this.Selection.Start,
endPos = this.Selection.End;
var result = false;
if(startPos == endPos)
result = this.content[startPos].Selection_IsEmpty();
return result;
},
SelectToParent : function(bCorrect)
{
this.Selection.Use = true;
if (true === bCorrect)
this.Correct_Selection();
if(!this.bRoot)
this.Parent.SelectToParent(false);
},
Selection_DrawRange: function(_CurLine, _CurRange, SelectionDraw)
{
var Start = this.Selection.Start,
End = this.Selection.End;
if(Start > End)
{
Start = this.Selection.End;
End = this.Selection.Start;
}
SelectionDraw.StartX += this.pos.x /*+ oCont.WidthToElement[Start]*/;
var PointsInfo = new CMathPointInfo();
PointsInfo.SetInfoPoints(this.InfoPoints);
if(this.RecalcInfo.bEqqArray)
{
if(SelectionDraw.FindStart == true)
SelectionDraw.StartX += PointsInfo.GetAlign();
else
SelectionDraw.W += PointsInfo.GetAlign();
}
var DrawSelection = false;
for(var i = 0; i < this.content.length; i++)
{
DrawSelection = i >= Start && i <= End ? true : false;
if(DrawSelection == false)
this.content[i].Selection_Remove();
else if(i > Start && i < End && this.content[i].Type == para_Math_Run) /// чтобы избежать багов, которые возникают при выходе за границы формулы (при резком движении мышки например в направлении начала формулы)
this.content[i].Select_All();
if(this.content[i].Type == para_Math_Run)
this.content[i].Selection_DrawRange(_CurLine, _CurRange, SelectionDraw, PointsInfo);
else
{
if(DrawSelection == true)
{
SelectionDraw.W += this.content[i].size.width;
SelectionDraw.FindStart = false;
}
else if(SelectionDraw.FindStart == true)
SelectionDraw.StartX += this.content[i].size.width;
}
}
if(!this.bRoot)
{
SelectionDraw.StartY = this.ParaMath.Y + this.pos.y; // выставляем так, чтобы для формул с различной высотой в одной строке, всё было ok
SelectionDraw.H = this.size.height;
}
},
///////////////////////
Get_StartPos: function(ContentPos, Depth)
{
ContentPos.Update( 0, Depth );
this.content[0].Get_StartPos(ContentPos, Depth + 1);
},
Get_EndPos: function(BehindEnd, ContentPos, Depth)
{
var len = this.content.length - 1;
ContentPos.Update(len, Depth);
if(len > 0)
this.content[len].Get_EndPos(BehindEnd, ContentPos, Depth + 1);
},
Get_Id : function()
{
return this.GetId();
......@@ -1874,103 +1424,6 @@ CMathContent.prototype =
},
/// функции для работы с курсором
Get_ParaContentPosByXY: function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
var result = false;
if(this.content.length > 0) // случай , если у нас контент не заполнен, не предусмотрен
{
var pos = 0;
var lng = this.content.length;
var PointInfo = new CMathPointInfo();
PointInfo.SetInfoPoints(this.InfoPoints);
if(this.RecalcInfo.bEqqArray)
SearchPos.CurX += PointInfo.GetAlign();
SearchPos.CurY = this.pos.y + this.ParaMath.Y + this.size.ascent;
while(pos < lng)
{
//result = this.content[pos].Get_ParaContentPosByXY(SearchPos, Depth+1, _CurLine, _CurRange, StepEnd, PointInfo);
if(this.content[pos].Type == para_Math_Composition)
{
if( this.content[pos].Get_ParaContentPosByXY(SearchPos, Depth+1, _CurLine, _CurRange, StepEnd))
{
SearchPos.InTextPos.Update(pos, Depth);
SearchPos.Pos.Update2(pos, Depth);
result = true;
}
if(SearchPos.InText == false)
{
if(this.content[pos-1].Is_Empty())
{
SearchPos.CurX -= this.content[pos].size.width;
if( this.content[pos-1].Get_ParaContentPosByXY(SearchPos, Depth+1, _CurLine, _CurRange, StepEnd))
{
SearchPos.Pos.Update2(pos-1, Depth);
result = true;
}
SearchPos.CurX += this.content[pos].size.width;
}
/*if(this.content[pos+1].Is_Empty())
{
if( this.content[pos+1].Get_ParaContentPosByXY(SearchPos, Depth+1, _CurLine, _CurRange, StepEnd))
{
SearchPos.Pos.Update2(pos, Depth);
result = true;
}
}*/
}
}
else
{
if(this.content[pos].Get_ParaContentPosByXY(SearchPos, Depth+1, _CurLine, _CurRange, StepEnd, PointInfo))
{
SearchPos.InTextPos.Update(pos, Depth);
SearchPos.Pos.Update2(pos, Depth);
result = true;
}
}
pos++;
}
}
return result;
},
Get_ParaContentPos: function(bSelection, bStart, ContentPos)
{
if( bSelection )
{
var pos = bStart ? this.Selection.Start : this.Selection.End;
ContentPos.Add(pos);
this.content[pos].Get_ParaContentPos(bSelection, bStart, ContentPos);
}
else
{
ContentPos.Add(this.CurPos);
this.content[this.CurPos].Get_ParaContentPos(bSelection, bStart, ContentPos);
}
},
Set_ParaContentPos: function(ContentPos, Depth)
{
this.CurPos = ContentPos.Get(Depth);
if(this.content.length > 0)
this.content[this.CurPos].Set_ParaContentPos(ContentPos, Depth+1);
},
Cursor_MoveToStartPos: function()
{
if(!this.Is_Empty())
......@@ -2017,33 +1470,6 @@ CMathContent.prototype =
return result;
},
Get_StartRangePos: function(CurLine, CurRange, SearchPos, Depth)
{
SearchPos.Pos.Update( 0, Depth );
return this.content[0].Get_StartRangePos(CurLine, CurRange, SearchPos, Depth + 1);
},
Get_StartRangePos2: function(CurLine, CurRange, ContentPos, Depth)
{
ContentPos.Update( 0, Depth );
this.content[0].Get_StartRangePos2(CurLine, CurRange, ContentPos, Depth + 1);
},
Get_EndRangePos: function(CurLine, CurRange, SearchPos, Depth)
{
var len = this.content.length - 1;
var result = false;
if(len >= 0)
{
SearchPos.Pos.Update(len, Depth);
result = this.content[len].Get_EndRangePos(CurLine, CurRange, SearchPos, Depth + 1);
}
return result;
},
//////////////////////////////////////
/////////////////////////
......@@ -2316,200 +1742,15 @@ CMathContent.prototype =
this.Selection.End = Pos;
}
this.private_CorrectSelectionPos();
}
},
Get_Default_TPrp: function()
{
return this.ParaMath.Get_Default_TPrp();
},
//////////////////////////////
// Перемещение по стрелкам
////////////////////
Get_LeftPos: function(SearchPos, ContentPos, Depth, UseContentPos, EndRun)
{
var CurPos = UseContentPos ? ContentPos.Get(Depth) : this.content.length-1;
while(CurPos >= 0 && SearchPos.Found == false)
{
var curType = this.content[CurPos].Type,
prevType = CurPos > 0 ? this.content[CurPos - 1].Type : null;
/*if(curType == MATH_PLACEHOLDER)
{
SearchPos.Pos.Update(0, Depth + 1);
SearchPos.Found = true;
}
else */
if(curType == para_Math_Composition)
{
var bNotshift = SearchPos.ForSelection == false,
bShiftCurrObj = (SearchPos.ForSelection == true && this.Selection.Start == CurPos);
if( bNotshift || bShiftCurrObj )
this.content[CurPos].Get_LeftPos(SearchPos, ContentPos, Depth + 1, UseContentPos, EndRun);
}
else if(EndRun)
{
SearchPos.Pos.Update(this.content[CurPos].Content.length, Depth + 1);
SearchPos.Found = true;
}
else
{
this.content[CurPos].Get_LeftPos(SearchPos, ContentPos, Depth + 1, UseContentPos);
}
SearchPos.Pos.Update(CurPos, Depth);
// если перемещаемся между контентами мат объекта, то надо выставить курсор в конец следующего контента, в конечную позицию последнего рана
EndRun = (curType == para_Math_Run && prevType == para_Math_Run) ? false : true;
CurPos--;
UseContentPos = false;
}
/// для коррекции позиции курсора в начале Run
// используется функция Correct_ContentPos в Paragraph
return SearchPos.Found;
},
Get_RightPos: function(SearchPos, ContentPos, Depth, UseContentPos, StepEnd, BegRun)
{
var CurPos = UseContentPos ? ContentPos.Get(Depth) : 0;
while(CurPos < this.content.length && SearchPos.Found == false)
{
var curType = this.content[CurPos].Type,
nextType = CurPos < this.content.length - 1 ? this.content[CurPos + 1].Type : null;
/*if(curType == MATH_PLACEHOLDER)
{
SearchPos.Pos.Update(0, Depth + 1);
SearchPos.Found = true;
}
else */
if(curType == para_Math_Composition)
{
var bNotshift = SearchPos.ForSelection == false,
bShiftCurrObj = SearchPos.ForSelection == true && this.Selection.Start == CurPos;
if( bNotshift || bShiftCurrObj )
this.content[CurPos].Get_RightPos(SearchPos, ContentPos, Depth + 1, UseContentPos, StepEnd, BegRun);
}
else if(BegRun)
{
SearchPos.Pos.Update(0, Depth + 1);
SearchPos.Found = true;
}
else
{
this.content[CurPos].Get_RightPos(SearchPos, ContentPos, Depth + 1, UseContentPos, StepEnd);
}
SearchPos.Pos.Update(CurPos, Depth);
// если перемещаемся между контентами мат объекта, то надо выставить курсор в начало следующего контента, в начальную позицию первого рана
BegRun = (curType == para_Math_Run && nextType == para_Math_Run) ? false : true;
CurPos++;
UseContentPos = false;
}
return SearchPos.Found;
},
Get_WordStartPos : function(SearchPos, ContentPos, Depth, UseContentPos, EndRun)
{
var CurPos = UseContentPos ? ContentPos.Get(Depth) : this.content.length-1;
while(CurPos >= 0 && SearchPos.Found == false)
{
var curType = this.content[CurPos].Type,
prevType = CurPos > 0 ? this.content[CurPos - 1].Type : null;
if(curType == para_Math_Composition)
{
var bNotshift = SearchPos.ForSelection == false,
bShiftCurrObj = (SearchPos.ForSelection == true && this.Selection.Start == CurPos);
if( bNotshift || bShiftCurrObj )
this.content[CurPos].Get_WordStartPos(SearchPos, ContentPos, Depth + 1, UseContentPos, EndRun);
}
else if(EndRun)
{
SearchPos.Pos.Update(this.content[CurPos].Content.length, Depth + 1);
SearchPos.Found = true;
}
else
{
this.content[CurPos].Get_WordStartPos(SearchPos, ContentPos, Depth + 1, UseContentPos);
if(SearchPos.Found == false && SearchPos.Shift == true)
{
this.content[CurPos].Get_StartPos(SearchPos.Pos, Depth + 1);
SearchPos.Found = true;
}
}
SearchPos.Pos.Update(CurPos, Depth);
// если перемещаемся между контентами мат объекта, то надо выставить курсор в конец следующего контента, в конечную позицию последнего рана
EndRun = (curType == para_Math_Run && prevType == para_Math_Run) ? false : true;
CurPos--;
UseContentPos = false;
}
},
Get_WordEndPos : function(SearchPos, ContentPos, Depth, UseContentPos, StepEnd, BegRun)
{
var CurPos = UseContentPos ? ContentPos.Get(Depth) : 0;
while(CurPos < this.content.length && SearchPos.Found == false)
{
var curType = this.content[CurPos].Type,
nextType = CurPos < this.content.length - 1 ? this.content[CurPos + 1].Type : null;
if(curType == para_Math_Composition)
{
var bNotshift = SearchPos.ForSelection == false,
bShiftCurrObj = SearchPos.ForSelection == true && this.Selection.Start == CurPos;
if( bNotshift || bShiftCurrObj )
this.content[CurPos].Get_WordEndPos(SearchPos, ContentPos, Depth + 1, UseContentPos, StepEnd, BegRun);
}
else if(BegRun)
{
SearchPos.Pos.Update(0, Depth + 1);
SearchPos.Found = true;
}
else
{
this.content[CurPos].Get_WordEndPos(SearchPos, ContentPos, Depth + 1, UseContentPos, StepEnd);
if(SearchPos.Found == false && SearchPos.Shift == true)
{
this.content[CurPos].Get_EndPos(false, SearchPos.Pos, Depth + 1);
SearchPos.Found = true;
}
}
SearchPos.Pos.Update(CurPos, Depth);
// если перемещаемся между контентами мат объекта, то надо выставить курсор в начало следующего контента, в начальную позицию первого рана
BegRun = (curType == para_Math_Run && nextType == para_Math_Run) ? false : true;
CurPos++;
UseContentPos = false;
this.private_CorrectSelectionPos();
}
},
Get_Default_TPrp: function()
{
return this.ParaMath.Get_Default_TPrp();
},
/////////////////////////
Is_Empty: function()
{
......@@ -2560,55 +1801,6 @@ CMathContent.prototype =
}
},
Selection_Remove: function()
{
var start = this.Selection.Start,
end = this.Selection.End;
var lng = this.content.length;
if(start >= 0 && start < lng && end >=0 && end < lng)
{
this.content[start].Selection_Remove();
if(start !== end)
this.content[end].Selection_Remove();
}
this.Selection.Use = false;
},
Set_Select_ToMComp: function(Direction)
{
this.Selection.Use = true;
if(this.content[this.CurPos].Type == para_Math_Run)
{
if(Direction < 0 && this.CurPos > 0 && this.content[this.CurPos - 1].Type == para_Math_Composition)
{
this.Selection.Start = this.Selection.End = this.CurPos - 1;
this.content[this.CurPos - 1].SetSelectAll();
}
else if(this.CurPos < this.content.length - 1 && this.content[this.CurPos + 1].Type == para_Math_Composition)
{
this.Selection.Start = this.Selection.End = this.CurPos + 1;
this.content[this.CurPos + 1].SetSelectAll();
}
}
else if(this.content[this.CurPos].Type == para_Math_Composition)
{
if(this.content[this.CurPos].IsPlaceholder())
{
this.Selection.Start = this.Selection.End = this.CurPos;
this.content[this.CurPos].SetSelectAll();
}
else
{
this.Selection.Start = this.Selection.End = this.CurPos;
this.content[this.CurPos].Set_Select_ToMComp(Direction);
}
}
},
getElem: function(nNum)
{
return this.content[nNum];
......@@ -4638,5 +3830,557 @@ CMathContent.prototype =
var oElem = oBox.getBase();
this.AddText(oElem, sElemText);
}
}
};
CMathContent.prototype.Recalculate_Reset = function(StartRange, StartLine)
{
for(var nPos = 0, nCount = this.content.length; nPos < nCount; nPos++)
{
this.content[nPos].Recalculate_Reset(StartRange, StartLine);
}
};
CMathContent.prototype.Get_Bounds = function()
{
var X = 0, Y = 0, W = 0, H = 0;
if (null !== this.ParaMath)
{
X = this.ParaMath.X + this.pos.x;
Y = this.ParaMath.Y + this.pos.y;
W = this.size.width;
H = this.size.height;
}
return {X : X, Y : Y, W : W, H : H};
};
CMathContent.prototype.Get_ParaContentPosByXY = function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
var nLength = this.content.length;
if (nLength <= 0)
return false;
var PointInfo = new CMathPointInfo();
PointInfo.SetInfoPoints(this.InfoPoints);
if(this.RecalcInfo.bEqqArray)
SearchPos.CurX += PointInfo.GetAlign();
var bResult = false;
for (var nPos = 0; nPos < nLength; nPos++)
{
var CurX = SearchPos.CurX;
if(true === this.content[nPos].Get_ParaContentPosByXY(SearchPos, Depth + 1, _CurLine, _CurRange, StepEnd))
{
SearchPos.Pos.Update2(nPos, Depth);
bResult = true;
}
SearchPos.CurX = CurX + this.content[nPos].size.width;
}
return bResult;
};
CMathContent.prototype.Get_ParaContentPos = function(bSelection, bStart, ContentPos)
{
var nPos = (true !== bSelection ? this.CurPos : (false !== bStart ? this.Selection.Start : this.Selection.End));
ContentPos.Add(nPos);
if (undefined !== this.content[nPos])
this.content[nPos].Get_ParaContentPos(bSelection, bStart, ContentPos);
};
CMathContent.prototype.Set_ParaContentPos = function(ContentPos, Depth)
{
this.CurPos = ContentPos.Get(Depth);
if(undefined !== this.content[this.CurPos])
{
this.content[this.CurPos].Set_ParaContentPos(ContentPos, Depth + 1);
}
};
CMathContent.prototype.Set_SelectionContentPos = function(StartContentPos, EndContentPos, Depth, StartFlag, EndFlag)
{
var OldStartPos = this.Selection.Start;
var OldEndPos = this.Selection.End;
if (OldStartPos > OldEndPos)
{
OldStartPos = this.Selection.EndPos;
OldEndPos = this.Selection.StartPos;
}
var StartPos = 0;
switch(StartFlag)
{
case 1: StartPos = 0; break;
case -1: StartPos = this.content.length - 1; break;
case 0: StartPos = StartContentPos.Get(Depth); break;
}
var EndPos = 0;
switch(EndFlag)
{
case 1: EndPos = 0; break;
case -1: EndPos = this.content.length - 1; break;
case 0: EndPos = EndContentPos.Get(Depth); break;
}
// Удалим отметки о старом селекте
if (OldStartPos < StartPos && OldStartPos < EndPos)
{
var TempLimit = Math.min(StartPos, EndPos);
for (var CurPos = OldStartPos; CurPos < TempLimit; CurPos++)
{
this.content[CurPos].Selection_Remove();
}
}
if (OldEndPos > StartPos && OldEndPos > EndPos)
{
var TempLimit = Math.max(StartPos, EndPos);
for (var CurPos = TempLimit + 1; CurPos <= OldEndPos; CurPos++)
{
this.content[CurPos].Selection_Remove();
}
}
// Выставим метки нового селекта
this.Selection.Use = true;
this.Selection.Start = StartPos;
this.Selection.End = EndPos;
if (StartPos !== EndPos)
{
this.content[StartPos].Set_SelectionContentPos(StartContentPos, null, Depth + 1, StartFlag, StartPos > EndPos ? 1 : -1);
this.content[EndPos].Set_SelectionContentPos(null, EndContentPos, Depth + 1, StartPos > EndPos ? -1 : 1, EndFlag);
var _StartPos = StartPos;
var _EndPos = EndPos;
var Direction = 1;
if ( _StartPos > _EndPos )
{
_StartPos = EndPos;
_EndPos = StartPos;
Direction = -1;
}
for (var CurPos = _StartPos + 1; CurPos < _EndPos; CurPos++)
{
this.content[CurPos].Select_All( Direction );
}
}
else
{
this.content[StartPos].Set_SelectionContentPos(StartContentPos, EndContentPos, Depth + 1, StartFlag, EndFlag);
}
};
CMathContent.prototype.Selection_IsEmpty = function()
{
if (true !== this.Selection.Use)
return true;
if (this.Selection.Start === this.Selection.End)
return this.content[this.Selection.Start].Selection_IsEmpty();
return false;
};
CMathContent.prototype.GetSelectContent = function()
{
if (false === this.Selection.Use)
{
if (para_Math_Composition === this.content[this.CurPos].Type)
return this.content[this.CurPos].GetSelectContent();
else
return {Content : this, Start : this.CurPos, End : this.CurPos};
}
else
{
var StartPos = this.Selection.Start;
var EndPos = this.Selection.End;
if (StartPos > EndPos)
{
StartPos = this.Selection.End;
EndPos = this.Selection.Start;
}
if (StartPos === EndPos && para_Math_Composition === this.content[StartPos].Type && true === this.content[StartPos].Is_InnerSelection())
return this.content[StartPos].GetSelectContent();
return {Content : this, Start : StartPos, End : EndPos};
}
};
CMathContent.prototype.Get_LeftPos = function(SearchPos, ContentPos, Depth, UseContentPos)
{
if (false === UseContentPos && para_Math_Run === this.content[this.content.length - 1].Type)
{
// При переходе в новый контент встаем в его конец
var CurPos = this.content.length - 1;
this.content[CurPos].Get_EndPos(false, SearchPos.Pos, Depth + 1);
SearchPos.Pos.Update(CurPos, Depth);
SearchPos.Found = true;
return true;
}
var CurPos = UseContentPos ? ContentPos.Get(Depth) : this.content.length - 1;
var bStepStart = false;
if (CurPos > 0 || !this.content[0].Cursor_Is_Start())
bStepStart = true;
this.content[CurPos].Get_LeftPos(SearchPos, ContentPos, Depth + 1, UseContentPos);
SearchPos.Pos.Update(CurPos, Depth);
if (true === SearchPos.Found)
return true;
CurPos--;
if (true === UseContentPos && para_Math_Composition === this.content[CurPos + 1].Type)
{
// При выходе из формулы встаем в конец рана
this.content[CurPos].Get_EndPos(false, SearchPos.Pos, Depth + 1);
SearchPos.Pos.Update(CurPos, Depth);
SearchPos.Found = true;
return true;
}
while (CurPos >= 0)
{
this.content[CurPos].Get_LeftPos(SearchPos, ContentPos, Depth + 1, false);
SearchPos.Pos.Update( CurPos, Depth );
if (true === SearchPos.Found)
return true;
CurPos--;
}
if (true === bStepStart)
{
// Перед выходом из контента встаем в его начало
this.content[0].Get_StartPos(SearchPos.Pos, Depth + 1);
SearchPos.Pos.Update(0, Depth);
SearchPos.Found = true;
return true;
}
return false;
};
CMathContent.prototype.Get_RightPos = function(SearchPos, ContentPos, Depth, UseContentPos, StepEnd)
{
if (false === UseContentPos && para_Math_Run === this.content[0].Type)
{
// При переходе в новый контент встаем в его начало
this.content[0].Get_StartPos(SearchPos.Pos, Depth + 1);
SearchPos.Pos.Update(0, Depth);
SearchPos.Found = true;
return true;
}
var CurPos = true === UseContentPos ? ContentPos.Get(Depth) : 0;
var Count = this.content.length;
var bStepEnd = false;
if (CurPos < Count - 1 || !this.content[Count - 1].Cursor_Is_End())
bStepEnd = true;
this.content[CurPos].Get_RightPos(SearchPos, ContentPos, Depth + 1, UseContentPos, StepEnd);
SearchPos.Pos.Update( CurPos, Depth );
if (true === SearchPos.Found)
return true;
CurPos++;
if (true === UseContentPos && para_Math_Composition === this.content[CurPos - 1].Type)
{
// При выходе из формулы встаем в начало рана
this.content[CurPos].Get_StartPos(SearchPos.Pos, Depth + 1);
SearchPos.Pos.Update(CurPos, Depth);
SearchPos.Found = true;
return true;
}
while (CurPos < Count)
{
this.content[CurPos].Get_RightPos(SearchPos, ContentPos, Depth + 1, false, StepEnd);
SearchPos.Pos.Update(CurPos, Depth);
if (true === SearchPos.Found)
return true;
CurPos++;
}
if (true === bStepEnd)
{
// Перед выходом из контента встаем в его конец
this.content[Count - 1].Get_EndPos(false, SearchPos.Pos, Depth + 1);
SearchPos.Pos.Update(Count - 1, Depth);
SearchPos.Found = true;
return true;
}
return false;
};
CMathContent.prototype.Get_WordStartPos = function(SearchPos, ContentPos, Depth, UseContentPos)
{
if (false === UseContentPos && para_Math_Run === this.content[this.content.length - 1].Type)
{
// При переходе в новый контент встаем в его конец
var CurPos = this.content.length - 1;
this.content[CurPos].Get_EndPos(false, SearchPos.Pos, Depth + 1);
SearchPos.Pos.Update(CurPos, Depth);
SearchPos.Found = true;
SearchPos.UpdatePos = true;
return true;
}
var CurPos = true === UseContentPos ? ContentPos.Get(Depth) : this.content.length - 1;
var bStepStart = false;
if (CurPos > 0 || !this.content[0].Cursor_Is_Start())
bStepStart = true;
this.content[CurPos].Get_WordStartPos(SearchPos, ContentPos, Depth + 1, UseContentPos);
if (true === SearchPos.UpdatePos)
SearchPos.Pos.Update( CurPos, Depth );
if (true === SearchPos.Found)
return;
CurPos--;
if (true === UseContentPos && para_Math_Composition === this.content[CurPos + 1].Type)
{
// При выходе из формулы встаем в конец рана
this.content[CurPos].Get_EndPos(false, SearchPos.Pos, Depth + 1);
SearchPos.Pos.Update(CurPos, Depth);
SearchPos.Found = true;
SearchPos.UpdatePos = true;
return true;
}
while (CurPos >= 0)
{
this.content[CurPos].Get_WordStartPos(SearchPos, ContentPos, Depth + 1, false);
if (true === SearchPos.UpdatePos)
SearchPos.Pos.Update( CurPos, Depth );
if (true === SearchPos.Found)
return;
CurPos--;
}
if (true === bStepStart)
{
// Перед выходом из контента встаем в его начало
this.content[0].Get_StartPos(SearchPos.Pos, Depth + 1);
SearchPos.Pos.Update(0, Depth);
SearchPos.Found = true;
SearchPos.UpdatePos = true;
return true;
}
};
CMathContent.prototype.Get_WordEndPos = function(SearchPos, ContentPos, Depth, UseContentPos, StepEnd)
{
if (false === UseContentPos && para_Math_Run === this.content[0].Type)
{
// При переходе в новый контент встаем в его начало
this.content[0].Get_StartPos(SearchPos.Pos, Depth + 1);
SearchPos.Pos.Update(0, Depth);
SearchPos.Found = true;
SearchPos.UpdatePos = true;
return true;
}
var CurPos = true === UseContentPos ? ContentPos.Get(Depth) : 0;
var Count = this.content.length;
var bStepEnd = false;
if (CurPos < Count - 1 || !this.content[Count - 1].Cursor_Is_End())
bStepEnd = true;
this.content[CurPos].Get_WordEndPos(SearchPos, ContentPos, Depth + 1, UseContentPos, StepEnd);
if (true === SearchPos.UpdatePos)
SearchPos.Pos.Update( CurPos, Depth);
if (true === SearchPos.Found)
return;
CurPos++;
if (true === UseContentPos && para_Math_Composition === this.content[CurPos - 1].Type)
{
// При выходе из формулы встаем в начало рана
this.content[CurPos].Get_StartPos(SearchPos.Pos, Depth + 1);
SearchPos.Pos.Update(CurPos, Depth);
SearchPos.Found = true;
SearchPos.UpdatePos = true;
return true;
}
while (CurPos < Count)
{
this.content[CurPos].Get_WordEndPos(SearchPos, ContentPos, Depth + 1, false, StepEnd);
if (true === SearchPos.UpdatePos)
SearchPos.Pos.Update(CurPos, Depth);
if (true === SearchPos.Found)
return;
CurPos++;
}
if (true === bStepEnd)
{
// Перед выходом из контента встаем в его конец
this.content[Count - 1].Get_EndPos(false, SearchPos.Pos, Depth + 1);
SearchPos.Pos.Update(Count - 1, Depth);
SearchPos.Found = true;
SearchPos.UpdatePos = true;
return true;
}
};
CMathContent.prototype.Get_StartPos = function(ContentPos, Depth)
{
ContentPos.Update(0, Depth);
this.content[0].Get_StartPos(ContentPos, Depth + 1);
};
CMathContent.prototype.Get_EndPos = function(BehindEnd, ContentPos, Depth)
{
var nLastPos = this.content.length - 1;
ContentPos.Update(nLastPos, Depth);
if(undefined !== this.content[nLastPos])
this.content[nLastPos].Get_EndPos(BehindEnd, ContentPos, Depth + 1);
};
CMathContent.prototype.Selection_Remove = function()
{
var StartPos = this.Selection.Start;
var EndPos = this.Selection.End;
if (StartPos > EndPos)
{
StartPos = this.Selection.End;
EndPos = this.Selection.Start;
}
for (var nPos = StartPos; nPos <= EndPos; nPos++)
{
this.content[nPos].Selection_Remove();
}
this.Selection.Use = false;
this.Selection.Start = 0;
this.Selection.End = 0;
};
CMathContent.prototype.Select_All = function(Direction)
{
this.Selection.Use = true;
this.Selection.Start = 0;
this.Selection.End = this.content.length - 1;
for (var nPos = 0, nCount = this.content.length; nPos < nCount; nPos++)
{
this.content[nPos].Select_All(Direction);
}
};
CMathContent.prototype.Selection_DrawRange = function(_CurLine, _CurRange, SelectionDraw)
{
var Start = this.Selection.Start;
var End = this.Selection.End;
if(Start > End)
{
Start = this.Selection.End;
End = this.Selection.Start;
}
SelectionDraw.StartX += this.pos.x;
var PointsInfo = new CMathPointInfo();
PointsInfo.SetInfoPoints(this.InfoPoints);
if(this.RecalcInfo.bEqqArray)
{
if(SelectionDraw.FindStart == true)
SelectionDraw.StartX += PointsInfo.GetAlign();
else
SelectionDraw.W += PointsInfo.GetAlign();
}
var bDrawSelection = false;
for(var nPos = 0, nCount = this.content.length; nPos < nCount; nPos++)
{
bDrawSelection = nPos >= Start && nPos <= End ? true : false;
if(para_Math_Run === this.content[nPos].Type)
this.content[nPos].Selection_DrawRange(_CurLine, _CurRange, SelectionDraw, PointsInfo);
else
{
if(true === bDrawSelection)
{
SelectionDraw.W += this.content[nPos].size.width;
SelectionDraw.FindStart = false;
}
else if(true === SelectionDraw.FindStart)
SelectionDraw.StartX += this.content[nPos].size.width;
}
}
// Выставляем высоту селекта. В верхнем контенте высота задается параграфом
if(true !== this.bRoot)
{
SelectionDraw.StartY = this.ParaMath.Y + this.pos.y;
SelectionDraw.H = this.size.height;
}
};
CMathContent.prototype.Select_ToRoot = function()
{
this.Selection.Use = true;
this.Correct_Selection();
if(!this.bRoot)
this.Parent.Select_ToRoot();
};
CMathContent.prototype.Select_ElementByPos = function(nPos)
{
this.Selection.Use = true;
this.Selection.Start = nPos;
this.Selection.End = nPos;
this.content[this.Selection.Start].Select_All();
};
CMathContent.prototype.Select_Element = function(Element)
{
var nPos = -1;
for (var nCurPos = 0, nCount = this.content.length; nCurPos < nCount; nCurPos++)
{
if (this.content[nCurPos] === Element)
{
nPos = nCurPos;
break;
}
}
if (-1 !== nPos)
{
this.Selection.Use = true;
this.Selection.Start = nPos;
this.Selection.End = nPos;
}
};
\ No newline at end of file
......@@ -749,39 +749,6 @@ CMathText.prototype =
return false;
},
////
// for Para Math
// for placeholder
Set_SelectionContentPos: function(StartContentPos, EndContentPos, Depth, StartFlag, EndFlag)
{
if(StartFlag == 0)
StartContentPos.Update2(0, Depth);
if(EndFlag == 0)
EndContentPos.Update2(1, Depth);
},
Selection_DrawRange : function(_CurLine, _CurRange, SelectionDraw)
{
SelectionDraw.W += this.size.width;
SelectionDraw.FindStart = false;
},
Get_ParaContentPos: function(bSelection, bStart, ContentPos)
{
if(bSelection)
{
var pos = bStart ? 0 : 1;
ContentPos.Add(pos);
}
else
ContentPos.Add(0);
},
Get_ParaContentPosByXY: function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
SearchPos.Pos.Update2(0, Depth);
SearchPos.Pos.bPlaceholder = true;
},
Copy: function()
{
var NewLetter = new CMathText(this.bJDraw);
......
......@@ -417,99 +417,6 @@ CMatrixBase.prototype.getRowSpace = function(spaceRow, txtPrp)
return lineGap;
};
CMatrixBase.prototype.Get_ParaContentPosByXY = function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
var maxWH = this.getWidthsHeights();
var Widths = maxWH.widths;
var Heights = maxWH.heights;
var X = this.ParaMath.X + this.pos.x + this.GapLeft, // this.ParaMath.X + this.pos.x совпадает с SearchPos.CurX
Y = this.ParaMath.Y + this.pos.y;
var CurrX, CurrY,
W_CurX,
Diff = 100000000;
var W = 0, H = 0;
var rX, rY,
minR;
for(var i=0; i < this.nRow; i++)
{
for(var j=0; j < this.nCol; j++)
{
if(!this.elements[i][j].IsJustDraw())
{
var x1 = SearchPos.X - X - W,
x2 = SearchPos.X - X - W - Widths[j],
y1 = SearchPos.Y - Y - H,
y2 = SearchPos.Y - Y - H - Heights[i];
var bInY = 0 < y1 && y2 < 0,
bInX = 0 < x1 && x2 < 0;
rX = x1*x1 < x2*x2 ? x1 : x2;
rY = y1*y1 < y2*y2 ? y1 : y2;
if(bInY && bInX)
minR = 0;
else if(!bInY && !bInX)
minR = rX*rX + rY*rY;
else if(bInY)
minR = rX*rX;
else
minR = rY*rY;
if(Diff > minR)
{
Diff = minR;
CurrX = i;
CurrY = j;
W_CurX = W;
}
}
W += Widths[j] + this.gaps.column[j];
}
W = 0;
H += Heights[i] + this.gaps.row[i];
}
var PrevSearchCurX = SearchPos.CurX;
SearchPos.CurX += this.GapLeft + W_CurX;
//var SearchCurX = SearchPos.CurX + this.GapLeft + W_CurX ;
if(this.kind === MATH_MATRIX)
{
SearchPos.CurX += this.align(CurrX, CurrY).x;
}
var result = this.elements[CurrX][CurrY].Get_ParaContentPosByXY(SearchPos, Depth+2, _CurLine, _CurRange, StepEnd);
if(result)
{
SearchPos.Pos.Update2(CurrX, Depth);
SearchPos.Pos.Update2(CurrY, Depth + 1);
SearchPos.InTextPos.Update(CurrX, Depth);
SearchPos.InTextPos.Update(CurrY, Depth + 1);
}
SearchPos.CurX = PrevSearchCurX + this.size.width;
return result;
};
function CMathMatrix(props)
{
......@@ -605,18 +512,6 @@ CMathMatrix.prototype.getMetrics = function(RPI)
return {ascents: Ascents, descents: Descents, widths: Widths}
};
CMathMatrix.prototype.findDistance = function() // для получения позиции тагета
{
var w = 0, h = 0;
//кол-во элементов gap равно кол-ву элементов в строке/столбце для удобства подсчета
for(var i = 0; i < this.CurPos_X; i++)
w += this.gaps.column[i];
for(var j = 0; j < this.CurPos_Y; j++)
h += this.gaps.row[j];
return {w : w, h: h };
}
CMathMatrix.prototype.setRowGapRule = function(rule, gap)
{
this.spaceRow.rule = rule;
......
......@@ -3700,38 +3700,6 @@ CDelimiter.prototype.setPosition = function(position, PosInfo)
content.setPosition(PosContent); // CMathContent*/
}
CDelimiter.prototype.Get_ParaContentPosByXY = function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
var begWidth = this.begOper.size.width,
sepWidth = this.sepOper.size.width,
endWidth = this.endOper.size.width;
SearchPos.CurX += begWidth + this.GapLeft;
var result;
for(var j = 0; j < this.nCol; j++)
{
if(this.elements[0][j].Get_ParaContentPosByXY(SearchPos, Depth+2, _CurLine, _CurRange, StepEnd))
{
SearchPos.Pos.Update2(0, Depth);
SearchPos.Pos.Update2(j, Depth+1);
SearchPos.InTextPos.Update(0, Depth);
SearchPos.InTextPos.Update(j, Depth + 1);
result = true;
}
if(j < this.nCol - 1)
SearchPos.CurX += sepWidth;
}
SearchPos.CurX += endWidth + this.GapRight;
return result;
}
CDelimiter.prototype.draw = function(x, y, pGraphics)
{
......@@ -3835,29 +3803,6 @@ CCharacter.prototype.setPosition = function(pos, PosInfo)
this.operator.setPosition(PosOper);
}
}
CCharacter.prototype.Get_ParaContentPosByXY = function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
var align = (this.size.width - this.elements[0][0].size.width - this.GapLeft - this.GapRight)/2;
SearchPos.CurX += this.GapLeft + align;
var result = this.elements[0][0].Get_ParaContentPosByXY(SearchPos, Depth+2, _CurLine, _CurRange, StepEnd);
if(result)
{
SearchPos.Pos.Update2(0, Depth);
SearchPos.Pos.Update2(0, Depth+1);
SearchPos.InTextPos.Update(0, Depth);
SearchPos.InTextPos.Update(0, Depth + 1);
}
SearchPos.CurX += this.GapRight + align;
return result;
}
CCharacter.prototype.draw = function(x, y, pGraphics)
{
this.elements[0][0].draw(x, y, pGraphics);
......
......@@ -425,9 +425,13 @@ CRadical.prototype.kind = MATH_RADICAL;
CRadical.prototype.init = function(props)
{
this.Fill_LogicalContent(2);
this.setProperties(props);
if (true === this.Pr.degHide)
this.Fill_LogicalContent(1);
else
this.Fill_LogicalContent(2);
this.fillContent();
}
CRadical.prototype.fillContent = function()
......@@ -622,61 +626,6 @@ CRadical.prototype.setPosition = function(pos, PosInfo)
this.RealBase.setPosition(PosBase, PosInfo);
}
}
CRadical.prototype.Get_ParaContentPosByXY = function(SearchPos, Depth, _CurLine, _CurRange, StepEnd)
{
var result = false;
if(this.Pr.type == SQUARE_RADICAL)
{
SearchPos.CurX += this.size.width - this.Base.size.width - this.GapRight;
if(this.Base.Get_ParaContentPosByXY(SearchPos, Depth+2, _CurLine, _CurRange, StepEnd))
{
SearchPos.Pos.Update2(0, Depth);
SearchPos.Pos.Update2(0, Depth + 1);
SearchPos.InTextPos.Update(0, Depth);
SearchPos.InTextPos.Update(0, Depth + 1);
result = true;
}
SearchPos.CurX += this.GapRight;
}
else
{
SearchPos.CurX += this.GapLeft;
if(this.Iterator.Get_ParaContentPosByXY(SearchPos, Depth+2, _CurLine, _CurRange, StepEnd))
{
SearchPos.Pos.Update2(0, Depth);
SearchPos.Pos.Update2(0, Depth + 1);
SearchPos.InTextPos.Update(0, Depth);
SearchPos.InTextPos.Update(0, Depth + 1);
result = true;
}
SearchPos.CurX += this.size.width - this.Iterator.size.width - this.Base.size.width - this.GapRight;
if(this.Base.Get_ParaContentPosByXY(SearchPos, Depth+2, _CurLine, _CurRange, StepEnd))
{
SearchPos.Pos.Update2(0, Depth);
SearchPos.Pos.Update2(1, Depth + 1);
SearchPos.InTextPos.Update(0, Depth);
SearchPos.InTextPos.Update(1, Depth + 1);
result = true;
}
SearchPos.CurX += this.GapRight;
}
return result;
}
CRadical.prototype.draw = function(x, y, pGraphics)
{
this.signRadical.draw(x, y, pGraphics);
......@@ -684,7 +633,10 @@ CRadical.prototype.draw = function(x, y, pGraphics)
}
CRadical.prototype.getBase = function()
{
return this.Content[1];
if (true === this.Pr.degHide)
return this.Content[0];
else
return this.Content[1];
}
CRadical.prototype.getDegree = function()
{
......
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