Commit 9c979e7b authored by Ilya Kirillov's avatar Ilya Kirillov

Добавлено объединение ячеек в билдер.

parent a478385d
......@@ -11216,6 +11216,12 @@ CDocument.prototype =
bUpdateSelection = false;
bRetValue = keydownresult_PreventAll;
}
else if (e.KeyCode === 113)
{
// Для теста
TEST_BUILDER();
bRetValue = keydownresult_PreventAll;
}
else if ( e.KeyCode == 121 && true === e.ShiftKey ) // Shift + F10 - контекстное меню
{
var X_abs, Y_abs, oPosition, ConvertedPos;
......
/*
*
* (c) Copyright Ascensio System Limited 2010-2016
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7  3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7  3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
/*
*
* (c) Copyright Ascensio System Limited 2010-2016
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7  3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7  3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
"use strict";
// SectPr : Настройки секци (размеры, поля)
......@@ -86,6 +86,9 @@ CSectionPr.prototype =
Copy : function(Other, CopyHdrFtr)
{
if (!Other)
return;
// Тип
this.Set_Type( Other.Type );
......
......@@ -9770,18 +9770,21 @@ CTable.prototype =
return { Grid_start : Grid_start, Grid_end : Grid_end, RowsInfo : RowsInfo, bCanMerge : bCanMerge };
},
// Объединяем заселекченные ячейки
Cell_Merge : function()
/**
* Объединяем выделенные ячейки таблицы.
* @param isClearMerge - используем или нет рассчетные данные (true - не используем, false - default value)
*/
Cell_Merge : function(isClearMerge)
{
var bApplyToInnerTable = false;
if ( false === this.Selection.Use || ( true === this.Selection.Use && table_Selection_Text === this.Selection.Type ) )
bApplyToInnerTable = this.CurCell.Content.Table_MergeCells();
if ( true === bApplyToInnerTable )
return;
return false;
if ( true != this.Selection.Use || table_Selection_Cell != this.Selection.Type || this.Selection.Data.length <= 1 )
return;
return false;
// В массиве this.Selection.Data идет список ячеек по строкам (без разрывов)
// Перед объединением мы должны проверить совпадают ли начальная и конечная колонки
......@@ -9793,7 +9796,7 @@ CTable.prototype =
var RowsInfo = Temp.RowsInfo;
if ( false === bCanMerge )
return;
return false;
// Объединяем содержимое всех ячеек в левую верхнюю ячейку. (Все выделенные
// ячейки идут у нас последовательно, начиная с левой верхней), и объединяем
......@@ -9816,13 +9819,16 @@ CTable.prototype =
}
}
// Выставим ширину результируещей ячейки
var SumW = 0;
for (var CurGridCol = Grid_start; CurGridCol <= Grid_end; CurGridCol++)
if (true !== isClearMerge)
{
SumW += this.TableGridCalc[CurGridCol];
// Выставим ширину результируещей ячейки
var SumW = 0;
for (var CurGridCol = Grid_start; CurGridCol <= Grid_end; CurGridCol++)
{
SumW += this.TableGridCalc[CurGridCol];
}
Cell_tl.Set_W(new CTableMeasurement(tblwidth_Mm, SumW));
}
Cell_tl.Set_W(new CTableMeasurement(tblwidth_Mm, SumW));
// Теперь нам надо удалить лишние ячейки и добавить ячейки с
// вертикальным объединением.
......@@ -9856,16 +9862,9 @@ CTable.prototype =
}
}
// У ряда, который содержит полученную ячейку мы выставляем минимальную высоту
// сумму высот объединенных строк.
//var Summary_VMerge = this.Internal_GetVertMergeCount( Pos_tl.Row, Grid_start, Grid_end - Grid_start + 1 );
//var Summary_Height = this.RowsInfo[Pos_tl.Row + Summary_VMerge - 1].H + this.RowsInfo[Pos_tl.Row + Summary_VMerge - 1].Y - this.RowsInfo[Pos_tl.Row].Y;
// Удаляем лишние строки
this.Internal_Check_TableRows(true);
var PageNum = 0;
for ( PageNum = 0; PageNum < this.Pages.length - 1; PageNum++ )
this.Internal_Check_TableRows(true !== isClearMerge ? true : false);
for (var PageNum = 0; PageNum < this.Pages.length - 1; PageNum++ )
{
if ( Pos_tl.Row <= this.Pages[PageNum + 1].FirstRow )
break;
......@@ -9879,9 +9878,14 @@ CTable.prototype =
this.Selection.Data = [ Pos_tl ];
this.CurCell = Cell_tl;
// Запускаем пересчет
this.Internal_Recalculate_1();
if (true !== isClearMerge)
{
// Запускаем пересчет
this.Internal_Recalculate_1();
}
return true;
},
// Разделяем текущую ячейку
......@@ -13316,6 +13320,24 @@ CTable.prototype.Is_TableFirstRowOnNewPage = function(CurRow)
return false;
};
CTable.prototype.private_UpdateCellsGrid = function()
{
for (var nCurRow = 0, nRowsCount = this.Content.length; nCurRow < nRowsCount; ++nCurRow)
{
var Row = this.Content[nCurRow];
var BeforeInfo = Row.Get_Before();
var CurGridCol = BeforeInfo.GridBefore;
for (var nCurCell = 0, nCellsCount = Row.Get_CellsCount(); nCurCell < nCellsCount; ++nCurCell)
{
var Cell = Row.Get_Cell(nCurCell);
var GridSpan = Cell.Get_GridSpan();
Cell.Set_Metrics(CurGridCol, 0, 0, 0, 0, 0, 0);
Row.Update_CellInfo(nCurCell);
CurGridCol += GridSpan;
}
}
};
//----------------------------------------------------------------------------------------------------------------------
// Класс CTableLook
//----------------------------------------------------------------------------------------------------------------------
......
......@@ -107,7 +107,9 @@
if (!nRows || nRows <= 0 || !nCols || nCols <= 0)
return null;
return new ApiTable(new CTable(private_GetDrawingDocument(), private_GetLogicDocument(), true, 0, 0, 0, 0, 0, nRows, nCols, [], false));
var oTable = new CTable(private_GetDrawingDocument(), private_GetLogicDocument(), true, 0, 0, 0, 0, 0, nRows, nCols, [], false);
oTable.private_RecalculateGridOpen();
return new ApiTable(oTable);
};
//------------------------------------------------------------------------------------------------------------------
......@@ -163,12 +165,19 @@
{
if (oElement instanceof ApiParagraph || oElement instanceof ApiTable)
{
this.Document.Internal_Content_Add(this.Document.Content.length, oElement.private_GetImpl(), true);
this.Document.Internal_Content_Add(this.Document.Content.length, oElement.private_GetImpl(), false);
return true;
}
return false;
};
/**
* Remove all elements from the current document.
*/
ApiDocument.prototype["RemoveAllElements"] = function()
{
this.Document.Content = [];
};
/**
* Get style by style name
* @param sStyleName
......@@ -583,6 +592,59 @@
return new ApiTableRow(this.Table.Content[nPos]);
};
/**
* Merge array of cells. If merge was done successfully it will reuturn merged cell, otherwise "null".
* <b>Warning</b>: The number of cells in any row and the numbers of rows in the current table may be changed.
* @param aCells
* @returns {ApiTableCell | null}
*/
ApiTable.prototype["MergeCells"] = function(aCells)
{
var oTable = this.Table;
oTable.Selection.Use = true;
oTable.Selection.Type = table_Selection_Cell;
oTable.Selection.Data = [];
for (var nPos = 0, nCount = aCells.length; nPos < nCount; ++nPos)
{
var oCell = aCells[nPos].Cell;
var oPos = {Cell : oCell.Index, Row : oCell.Row.Index};
var nResultPos = 0;
var nResultLength = oTable.Selection.Data.length;
for (nResultPos = 0; nResultPos < nResultLength; ++nResultPos)
{
var oCurPos = oTable.Selection.Data[nResultPos];
if (oCurPos.Row < oPos.Row)
{
continue;
}
else if (oCurPos.Row > oPos.Row)
{
break;
}
else
{
if (oCurPos.Cell < oPos.Cell)
continue;
else
break;
}
}
oTable.Selection.Data.splice(nResultPos, 0, oPos);
}
this.Table.private_UpdateCellsGrid();
var isMerged = this.Table.Cell_Merge(true);
oTable.Selection_Remove();
if (true === isMerged)
return new ApiTableCell(this.Table.CurCell);
return null;
};
/**
* Set table style
* @param oStyle (ApiStyle)
......@@ -769,6 +831,63 @@
{
return new ApiDocument(this.Cell.Content);
};
/**
* Set the preferred width for this cell.
* @param sType ("auto" | "twips" | "percent" | "nil")
* @param nValue
*/
ApiTableCell.prototype["SetWidth"] = function(sType, nValue)
{
var CellW = null;
if ("auto" === sType)
CellW = new CTableMeasurement(tblwidth_Auto, 0);
else if ("twips" === sType)
CellW = new CTableMeasurement(tblwidth_Mm, private_Twips2MM(nValue));
else if ("percent" === sType)
CellW = new CTableMeasurement(tblwidth_Pct, nValue);
if (CellW)
this.Cell.Set_W(CellW);
};
/**
* Specify the vertical alignment for text within the current table cell.
* @param sType ("top" | "center" | "bottom")
*/
ApiTableCell.prototype["SetVerticalAlign"] = function(sType)
{
if ("top" === sType)
this.Cell.Set_VAlign(vertalignjc_Top);
else if ("bottom" === sType)
this.Cell.Set_VAlign(vertalignjc_Bottom);
else if ("center" === sType)
this.Cell.Set_VAlign(vertalignjc_Center);
};
/**
* Specify the shading which shall be applied to the extents of the current table cell.
* @param sType ("nil" | "clear")
* @param r (0-255)
* @param g (0-255)
* @param b (0-255)
* @param isAuto (true | false)
* @constructor
*/
ApiTableCell.prototype["SetShd"] = function(sType, r, g, b, isAuto)
{
this.Cell.Set_Shd(private_GetShd(sType, r, g, b, isAuto));
};
/**
* Specify the direction of the text flow for this table cell.
* @param sType ("lrtb" || "tbrl" || "btlr") default value is "lrtb" (left-right-top-bottom)
*/
ApiTableCell.prototype["SetTextDirection"] = function(sType)
{
if ("lrtb" === sType)
this.Cell.Set_TextDirection(textdirection_LRTB);
else if ("tbrl" === sType)
this.Cell.Set_TextDirection(textdirection_TBRL);
else if ("btlr" === sType)
this.Cell.Set_TextDirection(textdirection_BTLR);
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Private area
......@@ -888,6 +1007,19 @@
return oBorder;
}
function private_GetShd(sType, r, g, b, isAuto)
{
var oShd = new CDocumentShd();
if ("nil" === sType)
oShd.Value = shd_Nil;
else if ("clear" === sType)
oShd.Value = shd_Clear;
oShd.Color.Set(r, g, b, isAuto);
return oShd;
}
ApiParagraph.prototype.private_GetImpl = function()
{
return this.Paragraph;
......@@ -1101,36 +1233,169 @@ function TEST_BUILDER()
oParagraph.AddText("new products. ");
var oTableGridStyle = oDocument.GetStyle("TableGrid");
var oTable = Api.CreateTable(2, 2);
oDocument.Push(oTable);
oTable.SetStyle(oDocument.GetStyle("TableGrid"));
oTable.SetStyle(oTableGridStyle);
oTable.SetWidth("twips", 4311);
oTable.SetTableLook(true, true, false, false, false, true);
oTable.SetTableLook(true, true, false, false, true, false);
oTable.SetTableBorderTop("single", 4, 0, 0xAF, 0xAD, 0x91);
oTable.SetTableBorderBottom("single", 4, 0, 0xAF, 0xAD, 0x91);
oTable.SetTableBorderLeft("single", 4, 0, 0xAF, 0xAD, 0x91);
oTable.SetTableBorderRight("single", 4, 0, 0xAF, 0xAD, 0x91);
oTable.SetTableBorderInsideH("single", 4, 0, 0xAF, 0xAD, 0x91);
oTable.SetTableBorderInsideV("single", 4, 0, 0xAF, 0xAD, 0x91);
var oRow1 = oTable.GetRow(0);
if (oRow1)
{
oRow1.SetHeight("atLeast", 201);
var oCell = oRow1.GetCell(0);
var oCellContent = oCell.GetContent();
var oRow = oTable.GetRow(0), oCell, oCellContent;
if (oRow)
{
oRow.SetHeight("atLeast", 201);
oCell = oRow.GetCell(0);
oCell.SetWidth("twips", 1637);
oCell.SetShd("clear", 0xff, 0x68, 0x00, false);
oCell.SetVerticalAlign("center");
oCellContent = oCell.GetContent();
oParagraph = oCellContent.GetElement(0);
oParagraph.SetJc("center");
oRun = oParagraph.AddText("2014");
oRun.SetBold(true);
oRun.SetColor(0, 0, 0, false);
oCell = oRow.GetCell(1);
oCell.SetWidth("twips", 2674);
oCell.SetShd("clear", 0xff, 0x68, 0x00, false);
oCell.SetVerticalAlign("center");
oCellContent = oCell.GetContent();
oParagraph = oCellContent.GetElement(0);
oParagraph.SetJc("center");
oRun = oParagraph.AddText("2015");
oRun.SetBold(true);
oRun.SetColor(0, 0, 0, false);
}
var oRow2 = oTable.GetRow(1);
if (oRow2)
{
oRow2.SetHeight("atLeast", 1070);
oRow = oTable.GetRow(1);
if (oRow)
{
oRow.SetHeight("atLeast", 1070);
oCell = oRow.GetCell(0);
oCell.SetWidth("twips", 1637);
oCell.SetVerticalAlign("center");
oCellContent = oCell.GetContent();
oParagraph = oCellContent.GetElement(0);
oParagraph.SetJc("center");
oParagraph.AddText("All Projects");
oParagraph.AddLineBreak();
oParagraph.AddText("Pending");
oCell = oRow.GetCell(1);
oCell.SetWidth("twips", 2674);
oCell.SetShd("clear", 0, 0, 0, true);
oCell.SetVerticalAlign("center");
oCellContent = oCell.GetContent();
oCellContent.RemoveAllElements();
var oInnerTable = Api.CreateTable(3, 3);
oCellContent.Push(oInnerTable);
oInnerTable.SetStyle(oTableGridStyle);
oInnerTable.SetWidth("twips", 2448);
oInnerTable.SetTableLook(true, true, false, false, true, false);
var oMergeCells = [];
oRow = oInnerTable.GetRow(0);
if(oRow)
{
oRow.SetHeight("atLeast", 201);
oCell = oRow.GetCell(0);
if (oCell)
{
oMergeCells.push(oCell);
}
oCell = oRow.GetCell(1);
if (oCell)
{
oCell.SetWidth("twips", 865);
oCell.SetShd("clear", 0xFF, 0xc2, 0x99, false);
oCellContent = oCell.GetContent();
oParagraph = oCellContent.GetElement(0);
oParagraph.AddText("West");
}
oCell = oRow.GetCell(2);
if (oCell)
{
oCell.SetWidth("twips", 1092);
oCell.SetShd("clear", 0xff, 0xe0, 0xcc, false);
oCellContent = oCell.GetContent();
oParagraph = oCellContent.GetElement(0);
oParagraph.AddText("Approved");
}
}
oRow = oInnerTable.GetRow(1);
if (oRow)
{
oRow.SetHeight("atLeast", 196);
oCell = oRow.GetCell(0);
if (oCell)
{
oMergeCells.push(oCell);
}
oCell = oRow.GetCell(1);
if (oCell)
{
oCell.SetWidth("twips", 865);
oCell.SetShd("clear", 0xFF, 0xc2, 0x99, false);
oCellContent = oCell.GetContent();
oParagraph = oCellContent.GetElement(0);
oParagraph.AddText("Central");
}
oCell = oRow.GetCell(2);
if (oCell)
{
oCell.SetWidth("twips", 1092);
oCell.SetShd("clear", 0xff, 0xe0, 0xcc, false);
oCellContent = oCell.GetContent();
oParagraph = oCellContent.GetElement(0);
oParagraph.AddText("Pending");
}
}
oRow = oInnerTable.GetRow(2);
if (oRow)
{
oRow.SetHeight("atLeast", 196);
oCell = oRow.GetCell(0);
if (oCell)
{
oMergeCells.push(oCell);
}
oCell = oRow.GetCell(1);
if (oCell)
{
oCell.SetWidth("twips", 865);
oCell.SetShd("clear", 0xFF, 0xc2, 0x99, false);
oCellContent = oCell.GetContent();
oParagraph = oCellContent.GetElement(0);
oParagraph.AddText("East");
}
oCell = oRow.GetCell(2);
if (oCell)
{
oCell.SetWidth("twips", 1092);
oCell.SetShd("clear", 0xff, 0xe0, 0xcc, false);
oCellContent = oCell.GetContent();
oParagraph = oCellContent.GetElement(0);
oParagraph.AddText("Approved");
}
}
var oMergedCell = oInnerTable.MergeCells(oMergeCells);
oMergedCell.SetVerticalAlign("center");
oMergedCell.SetTextDirection("btlr");
oMergedCell.SetWidth("twips", 491);
oMergedCell.SetShd("clear", 0xff, 0xa4, 0x66, false);
oCellContent = oMergedCell.GetContent();
oParagraph = oCellContent.GetElement(0);
oParagraph.SetIndLeft(113);
oParagraph.SetIndRight(113);
oParagraph.SetJc("center");
oRun = oParagraph.AddText("USA");
oRun.SetBold(true);
}
// TODO: Добавить таблицу
oParagraph = Api.CreateParagraph();
......
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