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

убрала Resize, setPosition и UpdatePosition (for Edit)


git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@52813 954022d7-b5bf-4e40-9824-e11837661b57
parent 14481e06
...@@ -375,8 +375,6 @@ CControlComposition.prototype = ...@@ -375,8 +375,6 @@ CControlComposition.prototype =
CreateEquation: function(indef) CreateEquation: function(indef)
{ {
this.Content[this.CurPos].CreateEquation(indef); this.Content[this.CurPos].CreateEquation(indef);
this.Content[this.CurPos].RecalculateReverse(oMeasure);
this.Content[this.CurPos].UpdatePosition();
}, },
Paragraph_Add: function(TextPr) Paragraph_Add: function(TextPr)
{ {
...@@ -415,14 +413,6 @@ CControlComposition.prototype = ...@@ -415,14 +413,6 @@ CControlComposition.prototype =
{ {
this.Content[this.CurPos].Refresh(); this.Content[this.CurPos].Refresh();
}, },
old_Set_SelectionState: function(State)
{
this.Content[this.CurPos].Set_SelectionState(State);
},
old_Get_SelectionState: function()
{
return this.Content[this.CurPos].Get_SelectionState();
},
UpdateCursor: function() UpdateCursor: function()
{ {
this.Content[this.CurPos].UpdateCursor(); this.Content[this.CurPos].UpdateCursor();
...@@ -1268,7 +1258,7 @@ function Set_Container(dimension, path, index) ...@@ -1268,7 +1258,7 @@ function Set_Container(dimension, path, index)
document.getElementById("Container").style.display = "none"; document.getElementById("Container").style.display = "none";
// AddMathComponent -> CreateEquation // AddMathComponent -> CreateEquation
//MathControl.CreateEquation(index + _i*column + _j); //MathControl.CreateEquation(index + _i*column + _j);
MathComposition.CreateEquation(index + _i*column + _j); MathComposition.CreateEquation2(index + _i*column + _j);
editor.WordControl.m_oLogicDocument.DrawingDocument.OnRecalculatePage(0, { Width : Page_Width, Height : Page_Height, Margins : { editor.WordControl.m_oLogicDocument.DrawingDocument.OnRecalculatePage(0, { Width : Page_Width, Height : Page_Height, Margins : {
Left : X_Left_Field, Left : X_Left_Field,
Right : X_Right_Field, Right : X_Right_Field,
......
...@@ -521,10 +521,6 @@ CMathBase.prototype = ...@@ -521,10 +521,6 @@ CMathBase.prototype =
return content; return content;
}, },
drawSelect: function()
{
this.elements[this.CurPos_X][this.CurPos_Y].drawSelect();
},
cursor_MoveToStartPos: function() // home => cursor_MoveToStartPos cursor_MoveToStartPos: function() // home => cursor_MoveToStartPos
{ {
this.CurPos_X = 0; this.CurPos_X = 0;
...@@ -873,11 +869,11 @@ CMathBase.prototype = ...@@ -873,11 +869,11 @@ CMathBase.prototype =
this.size = {width: _width, height: _height, center: _center}; this.size = {width: _width, height: _height, center: _center};
}, },
RecalculateReverse: function(oMeasure) /*RecalculateReverse: function(oMeasure)
{ {
this.recalculateSize(); this.recalculateSize();
this.Parent.RecalculateReverse(oMeasure); this.Parent.RecalculateReverse(oMeasure);
}, },*/
Resize: function(oMeasure) Resize: function(oMeasure)
{ {
for(var i=0; i < this.nRow; i++) for(var i=0; i < this.nRow; i++)
......
...@@ -1332,7 +1332,7 @@ CDocument.prototype = ...@@ -1332,7 +1332,7 @@ CDocument.prototype =
this.Document_UpdateRulersState(); this.Document_UpdateRulersState();
//** //**
//MathControl.UpdateCursor(); //MathControl.UpdateCursor();
MathComposition.UpdateCursor(); MathComposition.UpdateCursor2();
//this.RecalculateCurPos(); //this.RecalculateCurPos();
//** //**
//this.RecalculateCurPos(); //this.RecalculateCurPos();
......
...@@ -7,8 +7,6 @@ function CFraction() ...@@ -7,8 +7,6 @@ function CFraction()
extend(CFraction, CMathBase); extend(CFraction, CMathBase);
CFraction.prototype.init = function(props) CFraction.prototype.init = function(props)
{ {
if (props.type == undefined)
props.type = BAR_FRACTION;
var bValid = typeof(props.type) !== "undefined" && props.type !== null; var bValid = typeof(props.type) !== "undefined" && props.type !== null;
if(bValid) if(bValid)
...@@ -576,7 +574,7 @@ old_CBarFraction.prototype.setSimple = function(flag) ...@@ -576,7 +574,7 @@ old_CBarFraction.prototype.setSimple = function(flag)
else else
this.setReduct(1); this.setReduct(1);
this./**/Resize(); this.Resize();
} }
////////// //////////
......
...@@ -4412,20 +4412,7 @@ CMathContent.prototype = ...@@ -4412,20 +4412,7 @@ CMathContent.prototype =
this.update_widthContent(); /// !!!! this.update_widthContent(); /// !!!!
}, },
RecalculateReverse: function(oMeasure)
{
// for add component, set Txt Properties
var start = this.rInterval.startPos,
end = this.rInterval.endPos;
for(var i = start; i < end; i++)
this.content[i].value.Resize(oMeasure);
this.rInterval.startPos = this.rInterval.endPos = this.CurPos;
this.recalculateSize();
if(! this.bRoot )
this.Parent.RecalculateReverse(oMeasure);
},
Resize: function(oMeasure) // пересчитываем всю формулу Resize: function(oMeasure) // пересчитываем всю формулу
{ {
var bItalic = true; var bItalic = true;
...@@ -4437,7 +4424,7 @@ CMathContent.prototype = ...@@ -4437,7 +4424,7 @@ CMathContent.prototype =
if(type == MATH_TEXT) if(type == MATH_TEXT)
{ {
this.content[i].value.setMText(bItalic); this.content[i].value.setMText(bItalic);
this.content[i].value.resize(oMeasure); this.content[i].value.Resize(oMeasure);
} }
else if(type == MATH_COMP) else if(type == MATH_COMP)
{ {
...@@ -4468,7 +4455,7 @@ CMathContent.prototype = ...@@ -4468,7 +4455,7 @@ CMathContent.prototype =
txtPrp.Italic = false; txtPrp.Italic = false;
g_oTextMeasurer.SetFont(txtPrp); g_oTextMeasurer.SetFont(txtPrp);
this.content[i].value.resize(oMeasure); this.content[i].value.Resize(oMeasure);
} }
} }
} }
...@@ -5079,44 +5066,6 @@ CMathContent.prototype = ...@@ -5079,44 +5066,6 @@ CMathContent.prototype =
this.drawSelect(); this.drawSelect();
} }
}, },
//TODO
//переделать
old_drawSelect: function()
{
var start = this.selection.startPos;
var end = this.selection.endPos ;
if( start > end)
{
var tmp = start;
start = end;
end = tmp;
}
var widthSelect = 0;
try
{
for(var j = start; j < end ; j++)
widthSelect += this.content[j].widthToEl - this.content[j-1].widthToEl;
}
catch(e)
{
//console.log("Don't work update_widthContent");
console.log("Don't work drawSelect");
}
if( widthSelect != 0)
{
editor.WordControl.m_oLogicDocument.DrawingDocument.SelectClear(); // "обнуляем" логический селект
editor.WordControl.m_oLogicDocument.DrawingDocument.SelectEnabled(true); // select
/// ...Selectenabled(false) deselect, убираем слой
//editor.WordControl.m_oLogicDocument.DrawingDocument.TargetEnd();
//editor.WordControl.m_oLogicDocument.DrawingDocument.AddPageSelection(0,this.pos.x + this.content[start-1].widthToEl, this.pos.y, widthSelect, heightSelect );
editor.WordControl.m_oLogicDocument.DrawingDocument.SelectShow();
//editor.WordControl.m_oLogicDocument.DrawingDocument.TargetStart();
}
},
IsPlaceholder: function() IsPlaceholder: function()
{ {
var flag = false; var flag = false;
...@@ -5168,7 +5117,7 @@ CMathContent.prototype = ...@@ -5168,7 +5117,7 @@ CMathContent.prototype =
this.content[i].value.setPosition(t); this.content[i].value.setPosition(t);
} }
}, },
drawSelect2: function() drawSelect: function()
{ {
var start = this.RealSelect.startPos, var start = this.RealSelect.startPos,
end = this.RealSelect.endPos; end = this.RealSelect.endPos;
...@@ -6061,6 +6010,26 @@ CMathContent.prototype = ...@@ -6061,6 +6010,26 @@ CMathContent.prototype =
//this.selection.active = false; //this.selection.active = false;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
//// test function for me ////
/*RecalculateReverse: function(oMeasure)
{
// for add component, set Txt Properties
var start = this.rInterval.startPos,
end = this.rInterval.endPos;
for(var i = start; i < end; i++)
this.content[i].value.Resize(oMeasure);
this.rInterval.startPos = this.rInterval.endPos = this.CurPos;
this.recalculateSize();
if(! this.bRoot )
this.Parent.RecalculateReverse(oMeasure);
},*/
//////////////* end of test functions *//////////////////
} }
//todo //todo
//разобраться с gaps //разобраться с gaps
...@@ -6093,222 +6062,297 @@ CMathComposition.prototype = ...@@ -6093,222 +6062,297 @@ CMathComposition.prototype =
// сделать глобальную булевскую переменную для того, чтобы запоминать нужен пересчет контента или нет // сделать глобальную булевскую переменную для того, чтобы запоминать нужен пересчет контента или нет
// необходима тк на backspace может не быть реального удаления переменных, а только селект // необходима тк на backspace может не быть реального удаления переменных, а только селект
Init: function() //// test function for me ////
TestSetPosition: function()
{ {
// TODO this.Root.setPosition(this.posCompos);
// переделать gaps
//var g_Unif = 6*g_dKoef_pix_to_mm;
var g_Unif = 0;
var gps = new dist(g_Unif, g_Unif, g_Unif, g_Unif);
this.Root = new CMathContent();
this.Root.g_mContext = gps;
this.Root.setComposition(this);
//this.SetTestRunPrp();
//this.Root.setTxtPrp(this.TxtPrp);
this.CurrentContent = this.Root;
this.SelectContent = this.Root;
this.Root.relate(-1); // корень
}, },
/*SetTestRunPrp: function() TestSetFontAllSymbols: function(font)
{
var runPrp = new CTextPr();
runPrp.Merge(this.DefaultTxtPrp);
this.Root.addRunPrp(runPrp);
},*/
GetTxtPrp: function()
{ {
return this.DefaultTxtPrp; this.Root.setFont(font);
}, },
//TODO CheckTarget: function()
// переделать Draw (для режима редактирования передавать координату для отрисовки формулы) !!
// position вычислить естественно до того, как придет Draw, чтобы не пришлось пересчитывать при изменении в тексте документа
Draw_2: function(pGraphics)
{
if(this.Root.content.length > 1)
{ {
var w_Box = this.Root.size.width; var bSelect = this.SelectContent.selectUse(),
var h_Box = this.Root.size.height; bTarget = this.SelectContent.IsPlaceholder(),
bHideTgt = this.SelectContent.plhHide;
pGraphics.p_color(224, 238, 224, 255); // "p_color" for stroke
// "b_color1" for fill
//context.b_color1(224, 238, 230, 255);
pGraphics.drawHorLine(0, this.pos.y, this.pos.x, this.pos.x + w_Box, 0.2);
pGraphics.drawHorLine(0, this.pos.y + h_Box, this.pos.x, this.pos.x + w_Box, 0.2);
pGraphics.drawVerLine(0,this.pos.x, this.pos.y, this.pos.y + h_Box, 0.2 );
pGraphics.drawVerLine(0,this.pos.x + w_Box, this.pos.y, this.pos.y + h_Box, 0.2 );
}
this.Root.draw(pGraphics); if(bTarget)
},
Draw: function(x, y, pGraphics)
{ {
if(this.Root.content.length > 1) if(!bHideTgt)
{ {
this.pos = {x: x, y: y - this.Root.size.center}; this.SelectContent.tgtSelect();
this.Root.setPosition({x: x, y: y - this.Root.size.center}); this.HideCursor();
this.Root.draw(pGraphics);
//this.UpdateCursor();
} }
}, else
GetFirstPrp: function()
{ {
return this.Root.getFirstPrp(); this.SelectContent.setPositionHideTgt();
this.ShowCursor();
}
}
else if(bSelect)
this.HideCursor();
else
{
this.ShowCursor();
}
this.CurrentContent.update_Cursor();
}, },
Cursor_MoveLeft: function() Cursor_MoveRight_2: function()
{ {
var move = this.SelectContent.cursor_moveLeft(); this.ClearSelect();
var move = this.SelectContent.cursor_moveRight();
//передаем состояние, т.к. можем выйти за пределы формулы
if(move.state) if(move.state)
{ {
// SelectContent == CurrentContent
this.SelectContent = move.SelectContent; this.SelectContent = move.SelectContent;
this.CurrentContent = move.CurrContent; this.CurrentContent = move.CurrContent;
this.CheckTarget();
} }
return move.state; return move.state;
}, },
Cursor_MoveRight: function() Cursor_MoveLeft_2: function()
{ {
var move = this.SelectContent.cursor_moveRight(); this.ClearSelect();
var move = this.SelectContent.cursor_moveLeft();
//передаем состояние, т.к. можем выйти за пределы формулы
if(move.state) if(move.state)
{ {
this.SelectContent = move.SelectContent; this.SelectContent = move.SelectContent;
this.CurrentContent = move.CurrContent; this.CurrentContent = move.CurrContent;
this.CheckTarget();
} }
return move.state; return move.state;
}, },
Cursor_MoveUp: function() Cursor_MoveUp_2: function()
{ {
//TODO !!! //TODO !!!
//сделать как в Cursor_MoveLeft/Right //сделать как в Cursor_MoveLeft/Right
// в зависимости от пришедшего флага выставлять/не выставлять контент // в зависимости от пришедшего флага выставлять/не выставлять контент
this.ClearSelect();
var move = this.SelectContent.cursor_moveUp(); var move = this.SelectContent.cursor_moveUp();
this.CurrentContent = move.CurrContent; this.CurrentContent = move.CurrContent;
this.SelectContent = move.SelectContent; this.SelectContent = move.SelectContent;
return move.state; this.CheckTarget();
},
Cursor_MoveDown: function()
{
var move = this.SelectContent.cursor_moveDown();
this.CurrentContent = move.CurrContent;
this.SelectContent = move.SelectContent;
return move.state; return move.state;
}, },
Cursor_MoveToStartPos: function() OnKeyDown: function(e)
{ {
this.Root.cursor_MoveToStartPos(); //стрелка вверх
this.CurrentContent = this.SelectContent = this.Root; if(e.KeyCode==38)
},
Cursor_MoveToEndPos: function()
{ {
this.Root.cursor_MoveToEndPos(); this.Cursor_MoveUp_2();
this.CurrentContent = this.SelectContent = this.Root;
},
getSize: function() return true;
}
//стрелка вниз
else if(e.KeyCode==40)
{ {
/*return this.Root.size;*/ this.Cursor_MoveDown_2();
// return true;
var sh = 0.2487852283770651*g_oTextMeasurer.GetHeight(); }
// //стрелка влево
var size = if(e.KeyCode==37)
{ {
Width: this.Root.size.width, this.Cursor_MoveLeft_2();
WidthVisible: this.Root.size.width,
Height: this.Root.size.height,
Ascent: this.Root.size.center + sh,
Descent: this.Root.size.height - this.Root.size.center
};
return size; return true;
}, }
Remove: function(order, bOnAdd) //стрелка вправо
else if(e.KeyCode==39)
{ {
////* History *///// this.Cursor_MoveRight_2();
History.Create_NewPoint();
/*var start = this.SelectContent.selection.startPos,
end = this.SelectContent.selection.endPos;*/
var start = this.SelectContent.RealSelect.startPos,
end = this.SelectContent.RealSelect.endPos;
var Pos;
if(start !== end)
Pos = start < end ? start: end;
else if(order == 1)
Pos = this.SelectContent.CurPos;
else
Pos = this.SelectContent.CurPos + 1;
/////////////////////////// return true;
}
//backspace
else if(e.KeyCode==8)
{
try
{
if(this.Remove_2(1))
{
//this.UpdatePosition();
editor.WordControl.m_oLogicDocument.DrawingDocument.OnRecalculatePage(0, editor.WordControl.m_oLogicDocument.Pages[0]);
}
}
catch(e)
{
var removeMComp = true; }
if(bOnAdd) return true;
{
this.SelectContent.removeAreaSelect();
} }
else //delete
else if ( e.KeyCode == 46)
{ {
var result = this.SelectContent.remove(order); if(this.Remove_2(-1))
{
var bRoot = this.SelectContent.bRoot === true, //this.UpdatePosition();
bToUpper = result.state.bBegin || result.state.bEnd; // наверх нужно ли прокидовать editor.WordControl.m_oLogicDocument.DrawingDocument.OnRecalculatePage(0, editor.WordControl.m_oLogicDocument.Pages[0]);
}
}
if( result.state.bDelete ) if(e.CtrlKey == true && e.KeyCode == 81)
History.Add(this.CurrentContent, {Type: historyitem_Math_RemoveItem, Items: result.items, Pos: Pos}); {
simulatorMComposition(this, MATH_READ);
return false;
}
return false;
},
OnKeyPress: function(e)
{
var code = e.CharCode;
this.CurrentContent = result.CurrContent; //
this.SelectContent = result.SelectContent; /*if(code == 42)
this.CurrentContent.setPlaceholderAfterRemove(); // чтобы не выставлялся тагет при вставке, когда заселекчен весь контент и мы добавляем, например, другой мат элемент code = 8727;
else if(code == 45)
code = 8722;
removeMComp = !(bRoot && bToUpper); // посылаем false, если в начале + backspace или в конце + delete else if(code == 37)
code = 0x222B;
else if(code==94)
code = 0x2211;
if(code == 0x0068)
code = 0x210E;*/
/*else if(code > 0x0040 && code < 0x005B)
code = code + 0x1D3F3;
else if(code > 0x0060 && code < 0x007b)
code = code + 0x1D3ED;*/
if(code>=0x0020 )
{
editor.WordControl.m_oLogicDocument.DrawingDocument.OnRecalculatePage(0, editor.WordControl.m_oLogicDocument.Pages[0]);
this.AddLetter_2(code);
return true;
} }
return removeMComp;
return false;
}, },
OnMouseDown: function(x,y)
{
var coord = this.GetCoordComp(x,y);
UpdatePosition: function() if( this.IsRect(coord.x, coord.y) )
this.MouseDown(coord.x, coord.y);
},
OnMouseMove: function(x,y)
{ {
this.Root.setPosition(this.pos); var coord = this.GetCoordComp(x,y);
if( this.IsRect(coord.x, coord.y) )
this.MouseMove(coord.x, coord.y);
}, },
SetPosition: function(pos) OnMouseUp: function()
{ {
this.pos = pos; this.MouseUp();
this.Root.setPosition(this.pos);
}, },
RecalculateReverse: function(oMeasure) // for edit MouseDown: function(mouseX, mouseY)
{ {
this.SelectContent.RecalculateReverse(oMeasure); this.ClearSelect();
this.CurrentContent = this.SelectContent = this.Root.mouseDown({x: mouseX, y: mouseY}, -1);
this.TEST_SELECT_ACTIVE = true;
this.CheckTarget();
}, },
Resize: function(oMeasure) MouseMove: function(mouseX, mouseY)
{
if(this.TEST_SELECT_ACTIVE)
{
this.ClearSelect();
var movement = this.Root.mouseMove({x: mouseX, y: mouseY});
this.SelectContent = movement.SelectContent;
this.CheckTarget();
}
},
MouseUp: function()
{
this.TEST_SELECT_ACTIVE = false;
},
Remove_2: function(order)
{
if(TEST)
{
History.Create_NewPoint();
/*var start = this.SelectContent.selection.startPos,
end = this.SelectContent.selection.endPos;*/
var start = this.SelectContent.RealSelect.startPos,
end = this.SelectContent.RealSelect.endPos;
var Pos;
if(start !== end)
Pos = start < end ? start: end;
else if(order == 1)
Pos = this.SelectContent.CurPos;
else
Pos = this.SelectContent.CurPos + 1;
}
this.ClearSelect();
var result = this.SelectContent.remove(order);
this.CurrentContent = result.CurrContent;
this.SelectContent = result.SelectContent;
this.CurrentContent.setPlaceholderAfterRemove(); // чтобы не выставлялся тагет при вставке, когда заселекчен весь контент и мы добавляем, например, другой мат элемент
if( result.state.bDelete )
{
if(TEST)
{
History.Add(this.CurrentContent, {Type: historyitem_Math_RemoveItem, Items: result.items, Pos: Pos});
}
// временно
//this.CurrentContent.RecalculateReverse();
this.Resize(g_oTextMeasurer);
this.UpdatePosition();
}
this.CheckTarget();
return result.state.bDelete;
},
RecalculateComposition_2: function(oMeasure)
{ {
//this.SetReferenceComposition();
this.Root.Resize(oMeasure); this.Root.Resize(oMeasure);
this.Root.setPosition(this.pos);
this.UpdateCursor();
}, },
AddLetter: function(code) AddLetter_2: function(code)
{ {
if(TEST) if(TEST)
{ {
History.Create_NewPoint(); History.Create_NewPoint();
} }
//this.ClearSelect(); this.ClearSelect();
//this.SelectContent.removeAreaSelect(); this.SelectContent.removeAreaSelect();
/*if(this.Root.IsEmpty()) /*if(this.Root.IsEmpty())
...@@ -6340,63 +6384,41 @@ CMathComposition.prototype = ...@@ -6340,63 +6384,41 @@ CMathComposition.prototype =
}, },
CreateEquation2: function(indef) CreateEquation2: function(indef)
{ {
if(TEST) this.CreateEquation(indef);
{
History.Create_NewPoint();
}
//this.ClearSelect();
//this.SelectContent.removeAreaSelect();
if(TEST)
var Pos = this.SelectContent.CurPos + 1;
var items = this.SelectContent.createEquation(indef);
///
// временно // временно
//this.RecalculateReverse(); //this.RecalculateReverse();
//this.Root.Resize(); //this.Root.Resize();
this.Resize(g_oTextMeasurer); this.Resize(g_oTextMeasurer);
this.UpdatePosition(); this.UpdatePosition();
/// },
UpdateCursor2: function()
if(TEST)
{ {
//var Pos = this.SelectContent.CurPos - 1, //this.CurrentContent.update_Cursor();
var EndPos = this.SelectContent.CurPos + 1; this.SelectContent.update_Cursor();
History.Add(this.CurrentContent, {Type: historyitem_Math_AddItem, Items: items, Pos: Pos, PosEnd: EndPos}); if( this.SelectContent.selectUse())
} this.HideCursor();
else
this.CurrentContent = this.SelectContent;
this.CurrentContent.update_Cursor();
this.ShowCursor(); this.ShowCursor();
}, },
Get_SelectionState : function() HideCursor: function()
{ {
var State = new Object(); editor.WordControl.m_oLogicDocument.DrawingDocument.TargetEnd();
},
var stackCurrent = new Array(); ShowCursor: function()
this.CurrentContent.getStackPositions( stackCurrent );
State.Current =
{ {
stack: stackCurrent //узнать зачем обе функции вызывать
}; editor.WordControl.m_oLogicDocument.DrawingDocument.TargetStart();
editor.WordControl.m_oLogicDocument.DrawingDocument.TargetShow();
var stackSelect = new Array(); },
this.SelectContent.getStackPositions( stackSelect ); old_SetTxtPrp: function(txtPrp)
State.Select =
{ {
StartSelect: this.SelectContent.RealSelect.startPos - 1, this.SelectContent.changeTxtPrp(txtPrp, false);
EndSelect: this.SelectContent.RealSelect.endPos - 1, //this.SelectContent.setTxtPrp(txtPrp, false);
stack: stackSelect this.Resize();
}; this.UpdatePosition();
this.UpdateCursor();
return State;
}, },
Set_SelectionState : function(State) Set_SelectionState_2 : function(State)
{ {
this.ClearSelect(); this.ClearSelect();
// временно // временно
...@@ -6426,7 +6448,6 @@ CMathComposition.prototype = ...@@ -6426,7 +6448,6 @@ CMathComposition.prototype =
this.UpdateCursor(); this.UpdateCursor();
}*/ }*/
}, },
ClearSelect: function() ClearSelect: function()
{ {
if(this.SelectContent.selectUse()) if(this.SelectContent.selectUse())
...@@ -6435,264 +6456,198 @@ CMathComposition.prototype = ...@@ -6435,264 +6456,198 @@ CMathComposition.prototype =
editor.WordControl.m_oLogicDocument.DrawingDocument.SelectEnabled(false); editor.WordControl.m_oLogicDocument.DrawingDocument.SelectEnabled(false);
} }
}, },
old_SetTxtPrp: function(txtPrp) Draw_2: function(pGraphics)
{ {
this.SelectContent.changeTxtPrp(txtPrp, false); if(this.Root.content.length > 1)
//this.SelectContent.setTxtPrp(txtPrp, false);
this.Resize();
this.UpdatePosition();
this.UpdateCursor();
},
UpdateCursor: function()
{ {
//this.CurrentContent.update_Cursor(); var w_Box = this.Root.size.width;
this.SelectContent.update_Cursor(); var h_Box = this.Root.size.height;
/*if( this.SelectContent.selection.startPos !== this.SelectContent.selection.endPos)
this.HideCursor(); pGraphics.p_color(224, 238, 224, 255); // "p_color" for stroke
else // "b_color1" for fill
this.ShowCursor();*/ //context.b_color1(224, 238, 230, 255);
pGraphics.drawHorLine(0, this.pos.y, this.pos.x, this.pos.x + w_Box, 0.2);
pGraphics.drawHorLine(0, this.pos.y + h_Box, this.pos.x, this.pos.x + w_Box, 0.2);
pGraphics.drawVerLine(0,this.pos.x, this.pos.y, this.pos.y + h_Box, 0.2 );
pGraphics.drawVerLine(0,this.pos.x + w_Box, this.pos.y, this.pos.y + h_Box, 0.2 );
}
this.Root.draw(pGraphics);
}, },
/*GetPrpSelectContent: function() UpdatePosition: function()
{ {
return this.SelectContent.getSelectTPrp(true); this.Root.setPosition(this.pos);
},*/ },
SetPosition: function(pos)
//// test function ////
TestSetPosition: function()
{ {
this.Root.setPosition(this.posCompos); this.pos = pos;
this.Root.setPosition(this.pos);
}, },
TestSetFontAllSymbols: function(font) IsRect: function(x, y)
{ {
this.Root.setFont(font); var size = this.Root.size;
return ( x > 0 && x < size.width && y > 0 && y < size.height);
}, },
CheckTarget: function() GetCoordComp: function(x, y)
{ {
var bSelect = this.SelectContent.selectUse(), var _x = x - this.pos.x;
bTarget = this.SelectContent.IsPlaceholder(), var _y = y - this.pos.y;
bHideTgt = this.SelectContent.plhHide;
if(bTarget) return {x: _x, y: _y};
{ },
if(!bHideTgt) Resize: function(oMeasure)
{ {
this.SelectContent.tgtSelect(); this.Root.Resize(oMeasure);
this.HideCursor();
}
else
{
this.SelectContent.setPositionHideTgt();
this.ShowCursor();
}
}
else if(bSelect)
this.HideCursor();
else
{
this.ShowCursor();
}
this.CurrentContent.update_Cursor();
}, },
Cursor_MoveRight_2: function() test_for_edit: function()
{ {
this.ClearSelect(); var props =
var move = this.SelectContent.cursor_moveRight();
//передаем состояние, т.к. можем выйти за пределы формулы
if(move.state)
{ {
// SelectContent == CurrentContent type: BAR_FRACTION
this.SelectContent = move.SelectContent; };
this.CurrentContent = move.CurrContent; var fract = new CFraction();
this.CheckTarget(); addToContent_ForRead(this.Root, fract, props);
}
return move.state; fract.getNumerator().addTxt("a");
fract.getDenominator().addTxt("b");
}, },
Cursor_MoveLeft_2: function() test_for_edit_2: function()
{ {
this.ClearSelect(); simulatorMComposition(this, MATH_EDIT);
var move = this.SelectContent.cursor_moveLeft(); },
/*RecalculateReverse: function(oMeasure) // for edit
if(move.state)
{ {
this.SelectContent = move.SelectContent; this.SelectContent.RecalculateReverse(oMeasure);
this.CurrentContent = move.CurrContent; },*/
//////////////* end of test functions *//////////////////
this.CheckTarget();
}
return move.state; Init: function()
},
Cursor_MoveUp_2: function()
{ {
//TODO !!! // TODO
//сделать как в Cursor_MoveLeft/Right // переделать gaps
// в зависимости от пришедшего флага выставлять/не выставлять контент //var g_Unif = 6*g_dKoef_pix_to_mm;
this.ClearSelect(); var g_Unif = 0;
var move = this.SelectContent.cursor_moveUp(); var gps = new dist(g_Unif, g_Unif, g_Unif, g_Unif);
this.CurrentContent = move.CurrContent; this.Root = new CMathContent();
this.SelectContent = move.SelectContent; this.Root.g_mContext = gps;
this.Root.setComposition(this);
//this.SetTestRunPrp();
//this.Root.setTxtPrp(this.TxtPrp);
this.CheckTarget(); this.CurrentContent = this.Root;
this.SelectContent = this.Root;
return move.state; this.Root.relate(-1); // корень
}, },
OnKeyDown: function(e) /*SetTestRunPrp: function()
{
//стрелка вверх
if(e.KeyCode==38)
{ {
this.Cursor_MoveUp_2(); var runPrp = new CTextPr();
runPrp.Merge(this.DefaultTxtPrp);
return true; this.Root.addRunPrp(runPrp);
} },*/
//стрелка вниз GetTxtPrp: function()
else if(e.KeyCode==40)
{ {
this.Cursor_MoveDown_2(); return this.DefaultTxtPrp;
},
return true; //TODO
} // position вычислить естественно до того, как придет Draw, чтобы не пришлось пересчитывать при изменении в тексте документа
//стрелка влево Draw: function(x, y, pGraphics)
if(e.KeyCode==37)
{ {
this.Cursor_MoveLeft_2(); if(this.Root.content.length > 1)
return true;
}
//стрелка вправо
else if(e.KeyCode==39)
{ {
this.Cursor_MoveRight_2(); this.pos = {x: x, y: y - this.Root.size.center};
this.Root.setPosition({x: x, y: y - this.Root.size.center});
return true; this.Root.draw(pGraphics);
} }
//backspace },
else if(e.KeyCode==8) GetFirstPrp: function()
{
try
{ {
if(this.Remove_2(1)) return this.Root.getFirstPrp();
},
Cursor_MoveLeft: function()
{ {
//this.UpdatePosition(); var move = this.SelectContent.cursor_moveLeft();
editor.WordControl.m_oLogicDocument.DrawingDocument.OnRecalculatePage(0, editor.WordControl.m_oLogicDocument.Pages[0]);
} if(move.state)
}
catch(e)
{ {
this.SelectContent = move.SelectContent;
this.CurrentContent = move.CurrContent;
} }
return true; return move.state;
} },
//delete Cursor_MoveRight: function()
else if ( e.KeyCode == 46)
{
if(this.Remove_2(-1))
{ {
//this.UpdatePosition(); var move = this.SelectContent.cursor_moveRight();
editor.WordControl.m_oLogicDocument.DrawingDocument.OnRecalculatePage(0, editor.WordControl.m_oLogicDocument.Pages[0]);
}
}
if(e.CtrlKey == true && e.KeyCode == 81) //передаем состояние, т.к. можем выйти за пределы формулы
if(move.state)
{ {
simulatorMComposition(this, MATH_READ); this.SelectContent = move.SelectContent;
return false; this.CurrentContent = move.CurrContent;
} }
return false; return move.state;
}, },
OnKeyPress: function(e) Cursor_MoveUp: function()
{
var code = e.CharCode;
//
/*if(code == 42)
code = 8727;
else if(code == 45)
code = 8722;
else if(code == 37)
code = 0x222B;
else if(code==94)
code = 0x2211;
if(code == 0x0068)
code = 0x210E;*/
/*else if(code > 0x0040 && code < 0x005B)
code = code + 0x1D3F3;
else if(code > 0x0060 && code < 0x007b)
code = code + 0x1D3ED;*/
if(code>=0x0020 )
{ {
editor.WordControl.m_oLogicDocument.DrawingDocument.OnRecalculatePage(0, editor.WordControl.m_oLogicDocument.Pages[0]); //TODO !!!
this.AddLetter(code); //сделать как в Cursor_MoveLeft/Right
// в зависимости от пришедшего флага выставлять/не выставлять контент
return true; var move = this.SelectContent.cursor_moveUp();
}
this.CurrentContent = move.CurrContent;
this.SelectContent = move.SelectContent;
return false; return move.state;
}, },
OnMouseDown: function(x,y) Cursor_MoveDown: function()
{ {
var coord = this.GetCoordComp(x,y); var move = this.SelectContent.cursor_moveDown();
if( this.IsRect(coord.x, coord.y) ) this.CurrentContent = move.CurrContent;
this.MouseDown(coord.x, coord.y); this.SelectContent = move.SelectContent;
},
OnMouseMove: function(x,y)
{
var coord = this.GetCoordComp(x,y);
if( this.IsRect(coord.x, coord.y) ) return move.state;
this.MouseMove(coord.x, coord.y);
}, },
OnMouseUp: function() Cursor_MoveToStartPos: function()
{ {
this.MouseUp(); this.Root.cursor_MoveToStartPos();
this.CurrentContent = this.SelectContent = this.Root;
}, },
MouseDown: function(mouseX, mouseY) Cursor_MoveToEndPos: function()
{ {
this.ClearSelect(); this.Root.cursor_MoveToEndPos();
this.CurrentContent = this.SelectContent = this.Root.mouseDown({x: mouseX, y: mouseY}, -1); this.CurrentContent = this.SelectContent = this.Root;
this.TEST_SELECT_ACTIVE = true;
this.CheckTarget();
}, },
MouseMove: function(mouseX, mouseY) getSize: function()
{
if(this.TEST_SELECT_ACTIVE)
{ {
this.ClearSelect(); /*return this.Root.size;*/
var movement = this.Root.mouseMove({x: mouseX, y: mouseY});
this.SelectContent = movement.SelectContent;
this.CheckTarget(); //
} var sh = 0.2487852283770651*g_oTextMeasurer.GetHeight();
}, //
MouseUp: function() var size =
{ {
this.TEST_SELECT_ACTIVE = false; Width: this.Root.size.width,
WidthVisible: this.Root.size.width,
Height: this.Root.size.height,
Ascent: this.Root.size.center + sh,
Descent: this.Root.size.height - this.Root.size.center
};
return size;
}, },
Remove_2: function(order) Remove: function(order, bOnAdd)
{
if(TEST)
{ {
////* History */////
History.Create_NewPoint(); History.Create_NewPoint();
/*var start = this.SelectContent.selection.startPos,
end = this.SelectContent.selection.endPos;*/
var start = this.SelectContent.RealSelect.startPos, var start = this.SelectContent.RealSelect.startPos,
end = this.SelectContent.RealSelect.endPos; end = this.SelectContent.RealSelect.endPos;
var Pos; var Pos;
...@@ -6703,103 +6658,73 @@ CMathComposition.prototype = ...@@ -6703,103 +6658,73 @@ CMathComposition.prototype =
Pos = this.SelectContent.CurPos; Pos = this.SelectContent.CurPos;
else else
Pos = this.SelectContent.CurPos + 1; Pos = this.SelectContent.CurPos + 1;
}
this.ClearSelect(); ///////////////////////////
var removeMComp = true;
if(bOnAdd)
{
this.SelectContent.removeAreaSelect();
}
else
{
var result = this.SelectContent.remove(order); var result = this.SelectContent.remove(order);
this.CurrentContent = result.CurrContent;
this.SelectContent = result.SelectContent;
this.CurrentContent.setPlaceholderAfterRemove(); // чтобы не выставлялся тагет при вставке, когда заселекчен весь контент и мы добавляем, например, другой мат элемент var bRoot = this.SelectContent.bRoot === true,
bToUpper = result.state.bBegin || result.state.bEnd; // наверх нужно ли прокидовать
if( result.state.bDelete ) if( result.state.bDelete )
{
if(TEST)
{
History.Add(this.CurrentContent, {Type: historyitem_Math_RemoveItem, Items: result.items, Pos: Pos}); History.Add(this.CurrentContent, {Type: historyitem_Math_RemoveItem, Items: result.items, Pos: Pos});
}
// временно
//this.CurrentContent.RecalculateReverse();
this.Resize(g_oTextMeasurer);
this.UpdatePosition();
}
this.CheckTarget(); this.CurrentContent = result.CurrContent;
this.SelectContent = result.SelectContent;
this.CurrentContent.setPlaceholderAfterRemove(); // чтобы не выставлялся тагет при вставке, когда заселекчен весь контент и мы добавляем, например, другой мат элемент
removeMComp = !(bRoot && bToUpper); // посылаем false, если в начале + backspace или в конце + delete
}
return result.state.bDelete; return removeMComp;
}, },
RecalculateComposition_2: function(oMeasure) AddLetter: function(code)
{ {
//this.SetReferenceComposition(); History.Create_NewPoint();
this.Root.Resize(oMeasure); var items = this.SelectContent.addLetter(code);
this.Root.setPosition(this.pos); this.CurrentContent = this.SelectContent;
this.UpdateCursor();
},
////
////// /////// ///
HideCursor: function()
{
editor.WordControl.m_oLogicDocument.DrawingDocument.TargetEnd();
},
ShowCursor: function()
{
//узнать зачем обе функции вызывать
editor.WordControl.m_oLogicDocument.DrawingDocument.TargetStart();
editor.WordControl.m_oLogicDocument.DrawingDocument.TargetShow();
},
//////// var Pos = this.SelectContent.CurPos,
EndPos = this.SelectContent.CurPos + 1;
DrawSelect2: function() History.Add(this.CurrentContent, {Type: historyitem_Math_AddItem, Items: items, Pos: Pos, PosEnd: EndPos});
{
this.SelectContent.drawSelect2();
},
Refresh_RecalcData2: function()
{
this.Parent.Refresh_RecalcData2();
}, },
//test CreateEquation: function(indef)
// из MathControl
IsRect: function(x, y)
{ {
var size = this.Root.size; History.Create_NewPoint();
return ( x > 0 && x < size.width && y > 0 && y < size.height);
var Pos = this.SelectContent.CurPos + 1;
var items = this.SelectContent.createEquation(indef);
this.CurrentContent = this.SelectContent;
var EndPos = this.SelectContent.CurPos + 1;
History.Add(this.CurrentContent, {Type: historyitem_Math_AddItem, Items: items, Pos: Pos, PosEnd: EndPos});
}, },
GetCoordComp: function(x, y) UpdateCursor: function()
{ {
var _x = x - this.pos.x; this.SelectContent.update_Cursor();
var _y = y - this.pos.y;
return {x: _x, y: _y};
}, },
CreateEquation: function(indef) Refresh_RecalcData2: function()
{ {
this.CreateEquation2(indef); this.Parent.Refresh_RecalcData2();
// временно
//this.RecalculateReverse();
//this.Root.Resize();
this.Resize(g_oTextMeasurer);
this.UpdatePosition();
}, },
RecalculateComposition: function(oMeasure, TextPr) // textPrp в тестовом режиме, просто отрисуем с ними формулу RecalculateComposition: function(oMeasure, TextPr) // textPrp в тестовом режиме, просто отрисуем с ними формулу
{ {
////* test *////
/*var textPrp = new TextPr();
this.DefaultTxtPrp.FontSize = 11;
textPrp.Marge(this.DefaultTxtPrp);
textPrp.Merge(TextPr);
this.DefaultTxtPrp = textPrp;*/
///////////////////////
this.Root.Resize(oMeasure); // пересчитываем всю формулу this.Root.Resize(oMeasure); // пересчитываем всю формулу
var width = this.Root.size.width, var width = this.Root.size.width,
...@@ -6807,37 +6732,12 @@ CMathComposition.prototype = ...@@ -6807,37 +6732,12 @@ CMathComposition.prototype =
return {Width: width, Height: height, WidthVisible: width }; return {Width: width, Height: height, WidthVisible: width };
}, },
SetReferenceComposition: function()
{
this.Root.setReferenceComposition(this);
},
//////// For edit ////////
test_for_edit: function()
{
var props =
{
type: BAR_FRACTION
};
var fract = new CFraction();
addToContent_ForRead(this.Root, fract, props);
fract.getNumerator().addTxt("a");
fract.getDenominator().addTxt("b");
},
test_for_edit_2: function()
{
simulatorMComposition(this, MATH_EDIT);
},
Selection_SetStart: function(X, Y, PageNum) Selection_SetStart: function(X, Y, PageNum)
{ {
var x = X - this.pos.x, var x = X - this.pos.x,
y = Y - this.pos.y; y = Y - this.pos.y;
this.Root.selection_Start(x, y); this.Root.selection_Start(x, y);
//this.SelectContent = result.SelectContent; // если SetEnd придет раньше
}, },
Selection_SetEnd: function(X, Y, PageNum, MouseEvent) Selection_SetEnd: function(X, Y, PageNum, MouseEvent)
{ {
...@@ -6849,7 +6749,7 @@ CMathComposition.prototype = ...@@ -6849,7 +6749,7 @@ CMathComposition.prototype =
}, },
Selection_Draw: function() Selection_Draw: function()
{ {
this.SelectContent.drawSelect2(); this.SelectContent.drawSelect();
}, },
Selection_Beginning: function(bStart) // если приходит bStart = false, то это означает Selection_SetEnd (конец селекта в начале контента) Selection_Beginning: function(bStart) // если приходит bStart = false, то это означает Selection_SetEnd (конец селекта в начале контента)
{ {
...@@ -6875,7 +6775,41 @@ CMathComposition.prototype = ...@@ -6875,7 +6775,41 @@ CMathComposition.prototype =
Is_Empty: function() Is_Empty: function()
{ {
return this.Root.IsEmpty(); return this.Root.IsEmpty();
},
///////// for Undo/Redo ////////
Get_SelectionState : function()
{
var State = new Object();
var stackCurrent = new Array();
this.CurrentContent.getStackPositions( stackCurrent );
State.Current =
{
stack: stackCurrent
};
var stackSelect = new Array();
this.SelectContent.getStackPositions( stackSelect );
State.Select =
{
StartSelect: this.SelectContent.RealSelect.startPos - 1,
EndSelect: this.SelectContent.RealSelect.endPos - 1,
stack: stackSelect
};
return State;
},
Set_SelectionState : function(State)
{
var stackSelect = Common_CopyObj(State.Select.stack),
stackCurrent = Common_CopyObj(State.Current.stack);
this.SelectContent = this.Root.getContent( stackSelect, false );
this.CurrentContent = this.Root.getContent( stackCurrent, true );
} }
/////////////////////////////////////////
} }
......
...@@ -184,7 +184,7 @@ CMathText.prototype = ...@@ -184,7 +184,7 @@ CMathText.prototype =
this.size = {width: _width, widthG: widthG, height: _height, center: _center, ascent: _ascent, descent: _descent}; this.size = {width: _width, widthG: widthG, height: _height, center: _center, ascent: _ascent, descent: _descent};
}, },
resize: function(oMeasure) Resize: function(oMeasure)
{ {
var letter = this.getCode(); var letter = this.getCode();
...@@ -341,10 +341,6 @@ CMathText.prototype = ...@@ -341,10 +341,6 @@ CMathText.prototype =
this.size.center = this.size.center*(this.transform.sy + this.transform.shy);*/ this.size.center = this.size.center*(this.transform.sy + this.transform.shy);*/
}, },
Resize: function(oMeasure)
{
this.resize(oMeasure);
},
IsJustDraw: function() IsJustDraw: function()
{ {
return this.bJDraw; return this.bJDraw;
......
...@@ -2533,14 +2533,14 @@ COperator.prototype.getProps = function(props, defaultProps) ...@@ -2533,14 +2533,14 @@ COperator.prototype.getProps = function(props, defaultProps)
this.defaultType = defaultProps.type; this.defaultType = defaultProps.type;
var bDelimiter = this.type == OPER_DELIMITER || this.type == OPER_SEPARATOR, var bDelimiter = this.type == OPER_DELIMITER || this.type == OPER_SEPARATOR,
bType = typeof(props.type)!=="undefined" && props.type !== null, bNotType = typeof(props.type)=="undefined" || props.type == null,
bEmptyStr = typeof(chr) === "string" && chr.length == 0, bEmptyStr = typeof(chr) === "string" && chr.length == 0,
bCode = typeof(chr) === "string" && chr.length > 0; bCode = typeof(chr) === "string" && chr.length > 0;
var code = bCode ? chr.charCodeAt(0) : null; var code = bCode ? chr.charCodeAt(0) : null;
var bDPrpDelim = bDelimiter && !bType && bEmptyStr, var bDPrpDelim = bDelimiter && bNotType && bEmptyStr,
bDPrpOther = !bDelimiter && !bType && !bCode; bDPrpOther = !bDelimiter && bNotType && !bCode;
if(bDPrpDelim || bDPrpOther) if(bDPrpDelim || bDPrpOther)
{ {
...@@ -2722,15 +2722,6 @@ CDelimiter.prototype.init = function(props) ...@@ -2722,15 +2722,6 @@ CDelimiter.prototype.init = function(props)
else if(props.grow == false || props.grow == 0) else if(props.grow == false || props.grow == 0)
this.grow = false; this.grow = false;
if(props.begChr == undefined)
props.begChrType = PARENTHESIS_LEFT;
if(props.endChr == undefined)
props.endChrType = PARENTHESIS_RIGHT;
if(props.endChr == undefined && props.column >1)
props.sepChrType = DELIMITER_LINE;
var begPrp = var begPrp =
{ {
chr: props.begChr, chr: props.begChr,
...@@ -3253,7 +3244,7 @@ CGroupCharacter.prototype.init = function(props) ...@@ -3253,7 +3244,7 @@ CGroupCharacter.prototype.init = function(props)
/*this.setOperator(new COperator(glyph));*/ /*this.setOperator(new COperator(glyph));*/
if(this.operator.IsArrow()) if(this.operator.IsArrow())
this.setReduct(DEGR_REDUCT); /// заменить впоследствии на более подходящую функцию this.setReduct(DEGR_REDUCT);
} }
CGroupCharacter.prototype.getCenter = function() CGroupCharacter.prototype.getCenter = function()
{ {
......
...@@ -18,7 +18,7 @@ function simulatorMComposition( MComposition, ttype) ...@@ -18,7 +18,7 @@ function simulatorMComposition( MComposition, ttype)
props = props =
{ {
type: BAR_FRACTION //type: BAR_FRACTION
}; };
var fract = new CFraction(); var fract = new CFraction();
addToContent_ForRead(accent.getBase(), fract, props); addToContent_ForRead(accent.getBase(), fract, props);
...@@ -52,10 +52,13 @@ function simulatorMComposition( MComposition, ttype) ...@@ -52,10 +52,13 @@ function simulatorMComposition( MComposition, ttype)
props = props =
{ {
begChrType: PARENTHESIS_LEFT, begChr: "",
endChr: "",
sepChr: "",
//begChrType: PARENTHESIS_LEFT,
//endChrType: PARENTHESIS_RIGHT, //endChrType: PARENTHESIS_RIGHT,
endChr: ")", //endChr: ")",
sepChrType: DELIMITER_LINE, //sepChrType: DELIMITER_LINE,
column: 2 column: 2
}; };
...@@ -230,7 +233,7 @@ function simulatorMComposition( MComposition, ttype) ...@@ -230,7 +233,7 @@ function simulatorMComposition( MComposition, ttype)
lastElem.addTxt("w"); lastElem.addTxt("w");
var oper = new CGroupCharacter(); /*var oper = new CGroupCharacter();
props = props =
{ {
chrType: DOUBLE_ARROW_LR, chrType: DOUBLE_ARROW_LR,
...@@ -239,7 +242,7 @@ function simulatorMComposition( MComposition, ttype) ...@@ -239,7 +242,7 @@ function simulatorMComposition( MComposition, ttype)
addToContent_ForRead(lastElem, oper, props); addToContent_ForRead(lastElem, oper, props);
oper.getBase().addTxt("a"); oper.getBase().addTxt("a");*/
lastElem.addTxt("y"); lastElem.addTxt("y");
......
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