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

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

parent a478385d
...@@ -11216,6 +11216,12 @@ CDocument.prototype = ...@@ -11216,6 +11216,12 @@ CDocument.prototype =
bUpdateSelection = false; bUpdateSelection = false;
bRetValue = keydownresult_PreventAll; bRetValue = keydownresult_PreventAll;
} }
else if (e.KeyCode === 113)
{
// Для теста
TEST_BUILDER();
bRetValue = keydownresult_PreventAll;
}
else if ( e.KeyCode == 121 && true === e.ShiftKey ) // Shift + F10 - контекстное меню else if ( e.KeyCode == 121 && true === e.ShiftKey ) // Shift + F10 - контекстное меню
{ {
var X_abs, Y_abs, oPosition, ConvertedPos; var X_abs, Y_abs, oPosition, ConvertedPos;
......
...@@ -86,6 +86,9 @@ CSectionPr.prototype = ...@@ -86,6 +86,9 @@ CSectionPr.prototype =
Copy : function(Other, CopyHdrFtr) Copy : function(Other, CopyHdrFtr)
{ {
if (!Other)
return;
// Тип // Тип
this.Set_Type( Other.Type ); this.Set_Type( Other.Type );
......
...@@ -9770,18 +9770,21 @@ CTable.prototype = ...@@ -9770,18 +9770,21 @@ CTable.prototype =
return { Grid_start : Grid_start, Grid_end : Grid_end, RowsInfo : RowsInfo, bCanMerge : bCanMerge }; 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; var bApplyToInnerTable = false;
if ( false === this.Selection.Use || ( true === this.Selection.Use && table_Selection_Text === this.Selection.Type ) ) if ( false === this.Selection.Use || ( true === this.Selection.Use && table_Selection_Text === this.Selection.Type ) )
bApplyToInnerTable = this.CurCell.Content.Table_MergeCells(); bApplyToInnerTable = this.CurCell.Content.Table_MergeCells();
if ( true === bApplyToInnerTable ) if ( true === bApplyToInnerTable )
return; return false;
if ( true != this.Selection.Use || table_Selection_Cell != this.Selection.Type || this.Selection.Data.length <= 1 ) if ( true != this.Selection.Use || table_Selection_Cell != this.Selection.Type || this.Selection.Data.length <= 1 )
return; return false;
// В массиве this.Selection.Data идет список ячеек по строкам (без разрывов) // В массиве this.Selection.Data идет список ячеек по строкам (без разрывов)
// Перед объединением мы должны проверить совпадают ли начальная и конечная колонки // Перед объединением мы должны проверить совпадают ли начальная и конечная колонки
...@@ -9793,7 +9796,7 @@ CTable.prototype = ...@@ -9793,7 +9796,7 @@ CTable.prototype =
var RowsInfo = Temp.RowsInfo; var RowsInfo = Temp.RowsInfo;
if ( false === bCanMerge ) if ( false === bCanMerge )
return; return false;
// Объединяем содержимое всех ячеек в левую верхнюю ячейку. (Все выделенные // Объединяем содержимое всех ячеек в левую верхнюю ячейку. (Все выделенные
// ячейки идут у нас последовательно, начиная с левой верхней), и объединяем // ячейки идут у нас последовательно, начиная с левой верхней), и объединяем
...@@ -9816,6 +9819,8 @@ CTable.prototype = ...@@ -9816,6 +9819,8 @@ CTable.prototype =
} }
} }
if (true !== isClearMerge)
{
// Выставим ширину результируещей ячейки // Выставим ширину результируещей ячейки
var SumW = 0; var SumW = 0;
for (var CurGridCol = Grid_start; CurGridCol <= Grid_end; CurGridCol++) for (var CurGridCol = Grid_start; CurGridCol <= Grid_end; CurGridCol++)
...@@ -9823,6 +9828,7 @@ CTable.prototype = ...@@ -9823,6 +9828,7 @@ CTable.prototype =
SumW += this.TableGridCalc[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 = ...@@ -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); this.Internal_Check_TableRows(true !== isClearMerge ? true : false);
for (var PageNum = 0; PageNum < this.Pages.length - 1; PageNum++ )
var PageNum = 0;
for ( PageNum = 0; PageNum < this.Pages.length - 1; PageNum++ )
{ {
if ( Pos_tl.Row <= this.Pages[PageNum + 1].FirstRow ) if ( Pos_tl.Row <= this.Pages[PageNum + 1].FirstRow )
break; break;
...@@ -9880,8 +9879,13 @@ CTable.prototype = ...@@ -9880,8 +9879,13 @@ CTable.prototype =
this.CurCell = Cell_tl; this.CurCell = Cell_tl;
if (true !== isClearMerge)
{
// Запускаем пересчет // Запускаем пересчет
this.Internal_Recalculate_1(); this.Internal_Recalculate_1();
}
return true;
}, },
// Разделяем текущую ячейку // Разделяем текущую ячейку
...@@ -13316,6 +13320,24 @@ CTable.prototype.Is_TableFirstRowOnNewPage = function(CurRow) ...@@ -13316,6 +13320,24 @@ CTable.prototype.Is_TableFirstRowOnNewPage = function(CurRow)
return false; 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 // Класс CTableLook
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
......
...@@ -107,7 +107,9 @@ ...@@ -107,7 +107,9 @@
if (!nRows || nRows <= 0 || !nCols || nCols <= 0) if (!nRows || nRows <= 0 || !nCols || nCols <= 0)
return null; 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 @@ ...@@ -163,12 +165,19 @@
{ {
if (oElement instanceof ApiParagraph || oElement instanceof ApiTable) 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 true;
} }
return false; return false;
}; };
/**
* Remove all elements from the current document.
*/
ApiDocument.prototype["RemoveAllElements"] = function()
{
this.Document.Content = [];
};
/** /**
* Get style by style name * Get style by style name
* @param sStyleName * @param sStyleName
...@@ -583,6 +592,59 @@ ...@@ -583,6 +592,59 @@
return new ApiTableRow(this.Table.Content[nPos]); 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 * Set table style
* @param oStyle (ApiStyle) * @param oStyle (ApiStyle)
...@@ -769,6 +831,63 @@ ...@@ -769,6 +831,63 @@
{ {
return new ApiDocument(this.Cell.Content); 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 // Private area
...@@ -888,6 +1007,19 @@ ...@@ -888,6 +1007,19 @@
return oBorder; 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() ApiParagraph.prototype.private_GetImpl = function()
{ {
return this.Paragraph; return this.Paragraph;
...@@ -1101,36 +1233,169 @@ function TEST_BUILDER() ...@@ -1101,36 +1233,169 @@ function TEST_BUILDER()
oParagraph.AddText("new products. "); oParagraph.AddText("new products. ");
var oTableGridStyle = oDocument.GetStyle("TableGrid");
var oTable = Api.CreateTable(2, 2); var oTable = Api.CreateTable(2, 2);
oDocument.Push(oTable); oDocument.Push(oTable);
oTable.SetStyle(oDocument.GetStyle("TableGrid")); oTable.SetStyle(oTableGridStyle);
oTable.SetWidth("twips", 4311); 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.SetTableBorderTop("single", 4, 0, 0xAF, 0xAD, 0x91);
oTable.SetTableBorderBottom("single", 4, 0, 0xAF, 0xAD, 0x91); oTable.SetTableBorderBottom("single", 4, 0, 0xAF, 0xAD, 0x91);
oTable.SetTableBorderLeft("single", 4, 0, 0xAF, 0xAD, 0x91); oTable.SetTableBorderLeft("single", 4, 0, 0xAF, 0xAD, 0x91);
oTable.SetTableBorderRight("single", 4, 0, 0xAF, 0xAD, 0x91); oTable.SetTableBorderRight("single", 4, 0, 0xAF, 0xAD, 0x91);
oTable.SetTableBorderInsideH("single", 4, 0, 0xAF, 0xAD, 0x91); oTable.SetTableBorderInsideH("single", 4, 0, 0xAF, 0xAD, 0x91);
oTable.SetTableBorderInsideV("single", 4, 0, 0xAF, 0xAD, 0x91); oTable.SetTableBorderInsideV("single", 4, 0, 0xAF, 0xAD, 0x91);
var oRow1 = oTable.GetRow(0); var oRow = oTable.GetRow(0), oCell, oCellContent;
if (oRow1) if (oRow)
{ {
oRow1.SetHeight("atLeast", 201); oRow.SetHeight("atLeast", 201);
var oCell = oRow1.GetCell(0); oCell = oRow.GetCell(0);
var oCellContent = oCell.GetContent(); oCell.SetWidth("twips", 1637);
oCell.SetShd("clear", 0xff, 0x68, 0x00, false);
oCell.SetVerticalAlign("center");
oCellContent = oCell.GetContent();
oParagraph = oCellContent.GetElement(0); oParagraph = oCellContent.GetElement(0);
oParagraph.SetJc("center"); oParagraph.SetJc("center");
oRun = oParagraph.AddText("2014"); oRun = oParagraph.AddText("2014");
oRun.SetBold(true); oRun.SetBold(true);
oRun.SetColor(0, 0, 0, false); 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);
}
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");
} }
var oRow2 = oTable.GetRow(1); }
if (oRow2) 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)
{ {
oRow2.SetHeight("atLeast", 1070); 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(); 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