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

Добавлен новый базовый класс CParagraphContentWithContentBase, для обработки...

Добавлен новый базовый класс CParagraphContentWithContentBase, для обработки элементов параграфа, которые сами имеют подобное содержимое. Переделан класс ParaHyperlink, чтобы он наследовался от данного класса. Добавлен класс ParaField для обработки простых полей (т.е. которые идут одним элементом) в документе. Сделана подсветка полей. Сделана основа для работы с MailMerge (подмена полей и просмотр результатов). Исправлен баг с совместной работой комментариев (баг 28300).

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@60759 954022d7-b5bf-4e40-9824-e11837661b57
parent 831cd711
......@@ -1105,6 +1105,10 @@ var historyitem_Hyperlink_ToolTip = 2; // Изменяем подсказку
var historyitem_Hyperlink_AddItem = 3;
var historyitem_Hyperlink_RemoveItem = 4;
// Типы изменений в классе ParaField
var historyitem_Field_AddItem = 1;
var historyitem_Field_RemoveItem = 2;
//Типы изменений в классе CGraphicObjects
var historyitem_AddNewGraphicObject = 0;
var historyitem_RemoveGraphicObject = 1;
......@@ -1255,6 +1259,7 @@ var historyitem_type_deg_subsup = 51;
var historyitem_type_iterators = 52;
var historyitem_type_deg = 53;
var historyitem_type_ParaComment = 54;
var historyitem_type_Field = 55;
......
......@@ -1357,6 +1357,7 @@ CDrawingDocument.prototype =
this.DrawFrameTrack();
this.DrawMathTrack();
this.DrawFieldTrack();
if (this.InlineTextTrackEnabled && null != this.InlineTextTrack)
{
......
......@@ -1693,6 +1693,7 @@ function CDrawingDocument()
Track : { X : 0, Y : 0, L : 0, T : 0, R : 0, B : 0, PageIndex : 0, Type : -1 }, IsTracked : false, PageIndex : 0 };
this.MathRect = { IsActive : false, Rect : { X : 0, Y : 0, R : 0, B : 0, PageIndex : 0 }, ContentSelection : null };
this.FieldTrack = {IsActive : false, Rects : []};
this.m_oCacheManager = new CCacheManager();
......@@ -3479,6 +3480,79 @@ function CDrawingDocument()
}
}
this.DrawFieldTrack = function(overlay)
{
if (!this.FieldTrack.IsActive)
return;
overlay.Show();
for (var nIndex = 0, nCount = this.FieldTrack.Rects.length; nIndex < nCount; nIndex++)
{
var FieldRect = this.FieldTrack.Rects[nIndex];
var _page = this.m_arrPages[FieldRect.PageIndex];
var drPage = _page.drawingPage;
var dKoefX = (drPage.right - drPage.left) / _page.width_mm;
var dKoefY = (drPage.bottom - drPage.top) / _page.height_mm;
if (null == this.TextMatrix || global_MatrixTransformer.IsIdentity(this.TextMatrix))
{
var _x = (drPage.left + dKoefX * FieldRect.X0);
var _y = (drPage.top + dKoefY * FieldRect.Y0);
var _r = (drPage.left + dKoefX * FieldRect.X1);
var _b = (drPage.top + dKoefY * FieldRect.Y1);
if (_x < overlay.min_x)
overlay.min_x = _x;
if (_r > overlay.max_x)
overlay.max_x = _r;
if (_y < overlay.min_y)
overlay.min_y = _y;
if (_b > overlay.max_y)
overlay.max_y = _b;
var ctx = overlay.m_oContext;
ctx.fillStyle = "#375082";
ctx.beginPath();
this.AutoShapesTrack.AddRect(ctx, _x >> 0, _y >> 0, _r >> 0, _b >> 0);
ctx.globalAlpha = 0.2;
ctx.fill();
ctx.globalAlpha = 1;
ctx.beginPath();
}
else
{
var _arrSelect = TransformRectByMatrix(this.TextMatrix, [FieldRect.X0, FieldRect.Y0, FieldRect.X1, FieldRect.Y1], drPage.left, drPage.top, dKoefX, dKoefY);
overlay.CheckPoint(_arrSelect[0], _arrSelect[1]);
overlay.CheckPoint(_arrSelect[2], _arrSelect[3]);
overlay.CheckPoint(_arrSelect[4], _arrSelect[5]);
overlay.CheckPoint(_arrSelect[6], _arrSelect[7]);
var ctx = overlay.m_oContext;
ctx.fillStyle = "#375082";
ctx.beginPath();
ctx.moveTo(_arrSelect[0], _arrSelect[1]);
ctx.lineTo(_arrSelect[2], _arrSelect[3]);
ctx.lineTo(_arrSelect[4], _arrSelect[5]);
ctx.lineTo(_arrSelect[6], _arrSelect[7]);
ctx.closePath();
ctx.globalAlpha = 0.2;
ctx.fill();
ctx.globalAlpha = 1;
ctx.beginPath();
}
}
}
this.DrawTableTrack = function(overlay)
{
if (null == this.TableOutlineDr.TableOutline)
......@@ -4512,6 +4586,16 @@ function CDrawingDocument()
this.MathRect.Rect.PageIndex = PageIndex;
}
}
this.Update_FieldTrack = function(IsActive, aRects)
{
this.FieldTrack.IsActive = IsActive;
if (true === IsActive)
this.FieldTrack.Rects = aRects;
else
this.FieldTrack.Rects = [];
};
this.Update_ParaTab = function(Default_Tab, ParaTabs)
{
......
......@@ -3082,6 +3082,11 @@ function CEditorPage(api)
drDoc.DrawMathTrack(overlay);
}
if (drDoc.FieldTrack.IsActive)
{
drDoc.DrawFieldTrack(overlay);
}
if (drDoc.InlineTextTrackEnabled && null != drDoc.InlineTextTrack)
{
var _oldPage = drDoc.AutoShapesTrack.PageIndex;
......
......@@ -148,6 +148,7 @@ function CTableId()
case historyitem_type_CommentMark : Element = new ParaComment(); break;
case historyitem_type_ParaRun : Element = new ParaRun(); break;
case historyitem_type_Section : Element = new CSectionPr(); break;
case historyitem_type_Field : Element = new ParaField(); break;
case historyitem_type_DefaultShapeDefinition : Element = new DefaultShapeDefinition(); break;
case historyitem_type_CNvPr : Element = new CNvPr(); break;
......
......@@ -845,6 +845,8 @@ function ParaComment(Start, Id)
{
this.Id = g_oIdCounter.Get_NewId();
this.Paragraph = null;
this.Start = Start;
this.CommentId = Id;
......@@ -876,8 +878,9 @@ ParaComment.prototype =
}
},
Set_Paragraph : function()
Set_Paragraph : function(Paragraph)
{
this.Paragraph = Paragraph;
},
Is_Empty : function()
......@@ -1367,6 +1370,15 @@ ParaComment.prototype =
{
// String : CommentId
this.CommentId = Reader.GetString2();
var Comment = g_oTableId.Get_ById(this.CommentId);
if (null !== this.Paragraph && null !== Comment && Comment instanceof CComment)
{
if (true === this.Start)
Comment.Set_StartId(this.Paragraph.Get_Id());
else
Comment.Set_EndId(this.Paragraph.Get_Id());
}
break;
}
}
......
......@@ -532,6 +532,56 @@ CDocumentRecalcInfo.prototype =
}
};
function CDocumentFieldsManager()
{
this.m_aFields = [];
this.m_oMailMergeFields = {};
}
CDocumentFieldsManager.prototype.Register_Field = function(oField)
{
this.m_aFields.push(oField);
var nFieldType = oField.Get_FieldType();
if (fieldtype_MERGEFIELD === nFieldType)
{
var sName = oField.Get_Argument(0);
if (undefined !== sName)
{
if (undefined === this.m_oMailMergeFields[sName])
this.m_oMailMergeFields[sName] = [];
this.m_oMailMergeFields[sName].push(oField);
}
}
};
CDocumentFieldsManager.prototype.Update_MailMergeFields = function(Map)
{
for (var FieldName in Map)
{
if (undefined !== this.m_oMailMergeFields[FieldName])
{
for (var Index = 0, Count = this.m_oMailMergeFields[FieldName].length; Index < Count; Index++)
{
var oField = this.m_oMailMergeFields[FieldName][Index];
oField.Map_MailMerge(Map[FieldName]);
}
}
}
};
CDocumentFieldsManager.prototype.Restore_MailMergeTemplate = function()
{
for (var FieldName in this.m_oMailMergeFields)
{
for (var Index = 0, Count = this.m_oMailMergeFields[FieldName].length; Index < Count; Index++)
{
var oField = this.m_oMailMergeFields[FieldName][Index];
oField.Restore_Template();
}
}
};
function CDocument(DrawingDocument)
{
this.History = History;
......@@ -662,6 +712,14 @@ function CDocument(DrawingDocument)
// Дополнительные настройки
this.UseTextShd = true; // Использовать ли заливку текста
// Мап для рассылки
this.MailMergeMap = null;
this.MailMergeMap = [{Name : "Илья", Address : "Нижний Новгород"}, {Name : "Космонавт", Address : "Галактика"}];
this.MailMergePreview = false;
// Класс, управляющий полями
this.FieldsManager = new CDocumentFieldsManager();
// Добавляем данный класс в таблицу Id (обязательно в конце конструктора)
g_oTableId.Add( this, this.Id );
}
......@@ -678,6 +736,7 @@ function CSelectedElementsInfo()
this.m_pParagraph = null; // Параграф, в котором находится выделение
this.m_oMath = null; // Формула, в которой находится выделение
this.m_oHyperlink = null; // Гиперссылка, в которой находится выделение
this.m_oField = null; // Поле, в котором находится выделение
this.Reset = function()
{
......@@ -697,6 +756,11 @@ function CSelectedElementsInfo()
this.m_oMath = Math;
};
this.Set_Field = function(Field)
{
this.m_oField = Field;
};
this.Set_Hyperlink = function(Hyperlink)
{
this.m_oHyperlink = Hyperlink;
......@@ -712,6 +776,11 @@ function CSelectedElementsInfo()
return this.m_oMath;
};
this.Get_Field = function()
{
return this.m_oField;
};
this.Get_Hyperlink = function()
{
return this.m_oHyperlink;
......@@ -9690,6 +9759,49 @@ CDocument.prototype =
//не возвращаем true чтобы не было preventDefault
}
}
else if ( e.KeyCode == 68 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + D
{
if (false === this.Document_Is_SelectionLocked(changestype_Paragraph_Content))
{
this.Create_NewHistoryPoint();
var oField;
if (true === e.ShiftKey)
{
oField = new ParaField(fieldtype_MERGEFIELD, ["Address"], []);
var oRun = new ParaRun();
oRun.Add_ToContent(0, new ParaText("«"));
oRun.Add_ToContent(1, new ParaText("A"));
oRun.Add_ToContent(2, new ParaText("d"));
oRun.Add_ToContent(3, new ParaText("d"));
oRun.Add_ToContent(4, new ParaText("r"));
oRun.Add_ToContent(5, new ParaText("e"));
oRun.Add_ToContent(6, new ParaText("s"));
oRun.Add_ToContent(7, new ParaText("s"));
oRun.Add_ToContent(8, new ParaText("»"));
oField.Add_ToContent(0, oRun);
}
else
{
oField = new ParaField(fieldtype_MERGEFIELD, ["Name"], []);
var oRun = new ParaRun();
oRun.Add_ToContent(0, new ParaText("«"));
oRun.Add_ToContent(1, new ParaText("N"));
oRun.Add_ToContent(2, new ParaText("a"));
oRun.Add_ToContent(3, new ParaText("m"));
oRun.Add_ToContent(4, new ParaText("e"));
oRun.Add_ToContent(5, new ParaText("»"));
oField.Add_ToContent(0, oRun);
}
this.FieldsManager.Register_Field(oField);
this.Paragraph_Add(oField);
this.Document_UpdateInterfaceState();
}
bRetValue = true;
}
else if ( e.KeyCode == 69 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + E + ...
{
if ( true !== e.AltKey ) // Ctrl + E - переключение прилегания параграфа между center и left
......@@ -11882,6 +11994,15 @@ CDocument.prototype =
}
else
this.DrawingDocument.Update_MathTrack(false);
var oField = oSelectedInfo.Get_Field();
if (null !== oField)
{
var aBounds = oField.Get_Bounds();
this.DrawingDocument.Update_FieldTrack(true, aBounds);
}
else
this.DrawingDocument.Update_FieldTrack(false);
},
Document_UpdateUndoRedoState : function()
......@@ -12929,6 +13050,8 @@ CDocument.prototype =
if ( false === Pos )
continue;
Pos = Math.min(Pos, this.Content.length - 1);
this.Content.splice(Pos, 1);
if ( Pos > 0 )
......@@ -13881,7 +14004,50 @@ CDocument.prototype =
this.UseTextShd = bUse;
}
};
CDocument.prototype.Recalculate_FromStart = function(bUpdateStates)
{
var RecalculateData =
{
Inline : { Pos : 0, PageNum : 0 },
Flow : [],
HdrFtr : [],
Drawings : { All: true, Map:{} }
};
this.Reset_RecalculateCache();
this.Recalculate( false, false, RecalculateData );
if (true === bUpdateStates)
{
this.Document_UpdateInterfaceState();
this.Document_UpdateSelectionState();
}
};
CDocument.prototype.Preview_MailMergeResult = function(Index)
{
if (null === this.MailMergeMap)
return;
if (true !== this.MailMergePreview)
{
this.MailMergePreview = true;
CollaborativeEditing.m_bGlobalLock = true;
}
this.FieldsManager.Update_MailMergeFields(this.MailMergeMap[Index]);
this.Recalculate_FromStart(true);
};
CDocument.prototype.EndPreview_MailMergeResult = function()
{
if (null === this.MailMergeMap || true !== this.MailMergePreview)
return;
this.MailMergePreview = false;
CollaborativeEditing.m_bGlobalLock = false;
this.FieldsManager.Restore_MailMergeTemplate();
this.Recalculate_FromStart(true);
};
CDocument.prototype.private_StartSelectionFromCurPos = function()
{
this.private_UpdateCursorXY(true, true);
......
This diff is collapsed.
This diff is collapsed.
......@@ -2807,7 +2807,29 @@ Paragraph.prototype =
break;
}
case para_Field:
{
var ContentPos = this.Get_ParaContentPos(false, false);
var CurPos = ContentPos.Get(0);
// В поле не добавляем другое поле
if (para_Field !== this.Content[CurPos].Type)
{
// Разделяем текущий элемент (возвращается правая часть)
var NewElement = this.Content[CurPos].Split(ContentPos, 1);
if (null !== NewElement)
this.Internal_Content_Add(CurPos + 1, NewElement);
this.Internal_Content_Add(CurPos + 1, Item);
// Перемещаем кусор в конец формулы
this.CurPos.ContentPos = CurPos + 1;
this.Content[this.CurPos.ContentPos].Cursor_MoveToEndPos(false);
}
break;
}
case para_Run :
{
var ContentPos = this.Get_ParaContentPos(false, false);
......@@ -11008,13 +11030,16 @@ Paragraph.prototype =
{
var Comment = g_oTableId.Get_ById( Element.CommentId );
if ( null != Comment )
// При копировании не всегда сразу заполняется правильно CommentId
if (null != Comment && Comment instanceof CComment)
{
if ( true === Element.Start )
Comment.Set_StartId( this.Get_Id() );
else
Comment.Set_EndId( this.Get_Id() );
}
Element.Set_Paragraph(this);
}
this.Content.splice( Pos, 0, Element );
......
......@@ -51,6 +51,7 @@ var para_Math_Placeholder = 0x0032; // Плейсхолдер
var para_Math_Composition = 0x0033; // Математический объект (дробь, степень и т.п.)
var para_Math_Text = 0x0034; // Текст в формуле
var para_Math_Ampersand = 0x0035; // &
var para_Field = 0x0036; // Поле
var break_Line = 0x01;
......
This diff is collapsed.
......@@ -1529,6 +1529,12 @@ Paragraph.prototype.private_RecalculateLineAlign = function(CurLine, CurPa
PRSA.LettersSkip = PRSC.LettersSkip;
PRSA.RecalcResult = recalcresult_NextElement;
var _LineMetrics = this.Lines[CurLine].Metrics;
PRSA.Y0 = (this.Pages[CurPage].Y + this.Lines[CurLine].Y - _LineMetrics.Ascent);
PRSA.Y1 = (this.Pages[CurPage].Y + this.Lines[CurLine].Y + _LineMetrics.Descent);
if (_LineMetrics.LineGap < 0)
PRSA.Y1 += _LineMetrics.LineGap;
this.Lines[CurLine].Ranges[CurRange].XVisible = X;
if ( 0 === CurRange )
......@@ -2243,6 +2249,9 @@ function CParagraphRecalculateStateAlign()
this.Paragraph = undefined;
this.RecalcResult = 0x00;//recalcresult_NextElement;
this.Y0 = 0; // Верхняя граница строки
this.Y1 = 0; // Нижняя граница строки
this.CurPage = 0;
this.PageY = 0;
......
......@@ -1027,66 +1027,6 @@ ParaRun.prototype.Clear_SpellingMarks = function()
{
this.SpellingMarks = [];
};
//----------------------------------------------------------------------------------------------------------------------
// ParaHyperlink
//----------------------------------------------------------------------------------------------------------------------
ParaHyperlink.prototype.Restart_CheckSpelling = function()
{
for (var nIndex = 0, nCount = this.Content.length; nIndex < nCount; nIndex++)
{
this.Content[nIndex].Restart_CheckSpelling();
}
};
ParaHyperlink.prototype.Check_Spelling = function(SpellCheckerEngine, Depth)
{
this.SpellingMarks = [];
var ContentLen = this.Content.length;
for ( var Pos = 0; Pos < ContentLen; Pos++ )
{
var Item = this.Content[Pos];
SpellCheckerEngine.ContentPos.Update( Pos, Depth );
Item.Check_Spelling( SpellCheckerEngine, Depth + 1 );
}
};
ParaHyperlink.prototype.Add_SpellCheckerElement = function(Element, Start, Depth)
{
if ( true === Start )
{
//Element.ClassesS.push(this);
this.Content[Element.StartPos.Get(Depth)].Add_SpellCheckerElement(Element, Start, Depth + 1);
}
else
{
//Element.ClassesE.push(this);
this.Content[Element.EndPos.Get(Depth)].Add_SpellCheckerElement(Element, Start, Depth + 1);
}
this.SpellingMarks.push( new CParagraphSpellingMark( Element, Start, Depth ) );
};
ParaHyperlink.prototype.Remove_SpellCheckerElement = function(Element)
{
var Count = this.SpellingMarks.length;
for (var Pos = 0; Pos < Count; Pos++)
{
var SpellingMark = this.SpellingMarks[Pos];
if (Element === SpellingMark.Element)
{
this.SpellingMarks.splice(Pos, 1);
break;
}
}
};
ParaHyperlink.prototype.Clear_SpellingMarks = function()
{
this.SpellingMarks = [];
};
//----------------------------------------------------------------------------------------------------------------------
// ParaComment
//----------------------------------------------------------------------------------------------------------------------
......
......@@ -313,6 +313,7 @@
<script type="text/javascript" src="../../../../OfficeWeb/Word/Editor/ParagraphContent.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Word/Editor/ParagraphContentBase.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Word/Editor/Hyperlink.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Word/Editor/Field.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Word/Editor/Run.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Word/Editor/Math.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Word/Editor/Paragraph.js"></script>
......
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