diff --git a/cell/api.js b/cell/api.js index 5f27c4ff0c..1a09fe10ad 100644 --- a/cell/api.js +++ b/cell/api.js @@ -5813,9 +5813,22 @@ var editor; return oWorksheet.getActiveCellCoord(useUpRightMerge); } } - }; + // Получить координаты активной ячейки + spreadsheet_api.prototype.asc_getActiveCell = function() { + var oWorksheet = this.wb.getWorksheet(); + if(oWorksheet){ + if(oWorksheet.isSelectOnShape){ + return null; + } + else{ + return oWorksheet.getActiveCell(); + } + } + + }; + // Получить координаты для каких-либо действий (для общей схемы) spreadsheet_api.prototype.asc_getAnchorPosition = function() { return this.asc_getActiveCellCoord(); @@ -5886,7 +5899,11 @@ var editor; }; spreadsheet_api.prototype.asc_setCellBold = function(isBold) { - var ws = this.wb.getWorksheet(); + if (this.collaborativeEditing.getGlobalLock() || !this.canEdit()) { + return; + } + + let ws = this.wb.getWorksheet(); if (ws.objectRender.selectedGraphicObjectsExists() && ws.objectRender.controller.setCellBold) { ws.objectRender.controller.setCellBold(isBold); } else { @@ -5896,7 +5913,11 @@ var editor; }; spreadsheet_api.prototype.asc_setCellItalic = function(isItalic) { - var ws = this.wb.getWorksheet(); + if (this.collaborativeEditing.getGlobalLock() || !this.canEdit()) { + return; + } + + let ws = this.wb.getWorksheet(); if (ws.objectRender.selectedGraphicObjectsExists() && ws.objectRender.controller.setCellItalic) { ws.objectRender.controller.setCellItalic(isItalic); } else { @@ -5906,7 +5927,11 @@ var editor; }; spreadsheet_api.prototype.asc_setCellUnderline = function(isUnderline) { - var ws = this.wb.getWorksheet(); + if (this.collaborativeEditing.getGlobalLock() || !this.canEdit()) { + return; + } + + let ws = this.wb.getWorksheet(); if (ws.objectRender.selectedGraphicObjectsExists() && ws.objectRender.controller.setCellUnderline) { ws.objectRender.controller.setCellUnderline(isUnderline); } else { @@ -5916,7 +5941,11 @@ var editor; }; spreadsheet_api.prototype.asc_setCellStrikeout = function(isStrikeout) { - var ws = this.wb.getWorksheet(); + if (this.collaborativeEditing.getGlobalLock() || !this.canEdit()) { + return; + } + + let ws = this.wb.getWorksheet(); if (ws.objectRender.selectedGraphicObjectsExists() && ws.objectRender.controller.setCellStrikeout) { ws.objectRender.controller.setCellStrikeout(isStrikeout); } else { @@ -5926,7 +5955,11 @@ var editor; }; spreadsheet_api.prototype.asc_setCellSubscript = function(isSubscript) { - var ws = this.wb.getWorksheet(); + if (this.collaborativeEditing.getGlobalLock() || !this.canEdit()) { + return; + } + + let ws = this.wb.getWorksheet(); if (ws.objectRender.selectedGraphicObjectsExists() && ws.objectRender.controller.setCellSubscript) { ws.objectRender.controller.setCellSubscript(isSubscript); } else { @@ -5936,7 +5969,11 @@ var editor; }; spreadsheet_api.prototype.asc_setCellSuperscript = function(isSuperscript) { - var ws = this.wb.getWorksheet(); + if (this.collaborativeEditing.getGlobalLock() || !this.canEdit()) { + return; + } + + let ws = this.wb.getWorksheet(); if (ws.objectRender.selectedGraphicObjectsExists() && ws.objectRender.controller.setCellSuperscript) { ws.objectRender.controller.setCellSuperscript(isSuperscript); } else { @@ -5946,7 +5983,11 @@ var editor; }; spreadsheet_api.prototype.asc_setCellAlign = function(align) { - var ws = this.wb.getWorksheet(); + if (this.collaborativeEditing.getGlobalLock() || !this.canEdit()) { + return; + } + + let ws = this.wb.getWorksheet(); if (ws.objectRender.selectedGraphicObjectsExists() && ws.objectRender.controller.setCellAlign) { ws.objectRender.controller.setCellAlign(align); } else { @@ -5956,7 +5997,11 @@ var editor; }; spreadsheet_api.prototype.asc_setCellVertAlign = function(align) { - var ws = this.wb.getWorksheet(); + if (this.collaborativeEditing.getGlobalLock() || !this.canEdit()) { + return; + } + + let ws = this.wb.getWorksheet(); if (ws.objectRender.selectedGraphicObjectsExists() && ws.objectRender.controller.setCellVertAlign) { ws.objectRender.controller.setCellVertAlign(align); } else { @@ -8775,6 +8820,70 @@ var editor; return res == null ? AscCommonExcel.ESheetViewType.normal : res; }; + spreadsheet_api.prototype.asc_InsertPageBreak = function() { + if (this.collaborativeEditing.getGlobalLock() || !this.canEdit()) { + return; + } + let wb = this.wb; + if (!wb) { + return; + } + var ws = this.wb.getWorksheet(); + return ws && ws.insertPageBreak(); + }; + + spreadsheet_api.prototype.asc_RemovePageBreak = function() { + if (this.collaborativeEditing.getGlobalLock() || !this.canEdit()) { + return; + } + let wb = this.wb; + if (!wb) { + return; + } + var ws = this.wb.getWorksheet(); + return ws.removePageBreak(); + }; + + spreadsheet_api.prototype.asc_ResetAllPageBreaks = function() { + if (this.collaborativeEditing.getGlobalLock() || !this.canEdit()) { + return; + } + let wb = this.wb; + if (!wb) { + return; + } + var ws = this.wb.getWorksheet(); + return ws.resetAllPageBreaks(); + }; + + spreadsheet_api.prototype.asc_GetPageBreaksDisableType = function (index) { + if (!this.wbModel) { + return; + } + let sheetIndex = (undefined !== index && null !== index) ? index : this.wbModel.getActive(); + let ws = this.wbModel.getWorksheet(sheetIndex); + let res = Asc.c_oAscPageBreaksDisableType.none; + if (ws) { + let isPageBreaks = ws && ((ws.colBreaks && ws.colBreaks.getCount()) || (ws.rowBreaks && ws.rowBreaks.getCount())); + let activeCell = ws.selectionRange && ws.selectionRange.activeCell; + let isFirstActiveCell = activeCell && activeCell.col === 0 && activeCell.row === 0; + + if (isFirstActiveCell && !isPageBreaks) { + //disable all + res = Asc.c_oAscPageBreaksDisableType.all; + } else if (isFirstActiveCell && isPageBreaks) { + //disable insert/remove + res = Asc.c_oAscPageBreaksDisableType.insertRemove; + } else if (!isFirstActiveCell && !isPageBreaks) { + //disable reset + res = Asc.c_oAscPageBreaksDisableType.reset; + } + } + + return res; + }; + + /* * Export * ----------------------------------------------------------------------------- @@ -9340,6 +9449,11 @@ var editor; prot["asc_ChangeTextCase"] = prot.asc_ChangeTextCase; + prot["asc_InsertPageBreak"] = prot.asc_InsertPageBreak; + prot["asc_RemovePageBreak"] = prot.asc_RemovePageBreak; + prot["asc_ResetAllPageBreaks"] = prot.asc_ResetAllPageBreaks; + prot["asc_GetPageBreaksDisableType"]= prot.asc_GetPageBreaksDisableType; + diff --git a/cell/apiDefines.js b/cell/apiDefines.js index e03a5aa286..dbb574f2a7 100644 --- a/cell/apiDefines.js +++ b/cell/apiDefines.js @@ -571,7 +571,15 @@ var c_oAscPopUpSelectorType = { path: 2 }; - //----------------------------------------------------------export---------------------------------------------------- + var c_oAscPageBreaksDisableType = { + none: 0, + all: 1, + insertRemove: 2, + reset: 3 + }; + + + //----------------------------------------------------------export---------------------------------------------------- window['AscCommonExcel'] = window['AscCommonExcel'] || {}; window['AscCommonExcel'].c_oAscDrawDepOptions = c_oAscDrawDepOptions; window['AscCommonExcel'].c_oAscScrollType = c_oAscScrollType; @@ -965,5 +973,12 @@ var c_oAscPopUpSelectorType = { prot['link'] = prot.link; prot['path'] = prot.path; + window['Asc']['c_oAscPageBreaksDisableType'] = window['Asc'].c_oAscPageBreaksDisableType = c_oAscPageBreaksDisableType; + prot = c_oAscPageBreaksDisableType; + prot['none'] = prot.none; + prot['all'] = prot.all; + prot['insertRemove'] = prot.insertRemove; + prot['reset'] = prot.reset; + })(window); diff --git a/cell/model/History.js b/cell/model/History.js index b134081dc9..3a1dfc1a04 100644 --- a/cell/model/History.js +++ b/cell/model/History.js @@ -116,6 +116,8 @@ function (window, undefined) { window['AscCH'].historyitem_Worksheet_SetShowFormulas = 62; + window['AscCH'].historyitem_Worksheet_ChangeRowColBreaks = 63; + window['AscCH'].historyitem_RowCol_Fontname = 1; window['AscCH'].historyitem_RowCol_Fontsize = 2; window['AscCH'].historyitem_RowCol_Fontcolor = 3; diff --git a/cell/model/Serialize.js b/cell/model/Serialize.js index a8004bb99b..b121e26ca9 100644 --- a/cell/model/Serialize.js +++ b/cell/model/Serialize.js @@ -8244,18 +8244,17 @@ res = this.bcr.Read1(length, function(t, l) { return oThis.ReadHeaderFooter(t, l, oWorksheet.headerFooter); }); - // Disable HeaderFooter opening to prevent file corruption - // } else if (c_oSerWorksheetsTypes.RowBreaks === type) { - // oWorksheet.rowBreaks = {count: null, manualBreakCount: null, breaks: []}; - // res = this.bcr.Read1(length, function (t, l) { - // return oThis.ReadRowColBreaks(t, l, oWorksheet.rowBreaks); - // }); - // } else if (c_oSerWorksheetsTypes.ColBreaks === type) { - // oWorksheet.colBreaks = {count: null, manualBreakCount: null, breaks: []}; - // res = this.bcr.Read1(length, function (t, l) { - // return oThis.ReadRowColBreaks(t, l, oWorksheet.colBreaks); - // }); - // } else if (c_oSerWorksheetsTypes.LegacyDrawingHF === type) { + } else if (c_oSerWorksheetsTypes.RowBreaks === type) { + oWorksheet.rowBreaks = new AscCommonExcel.CRowColBreaks(); + res = this.bcr.Read1(length, function (t, l) { + return oThis.ReadRowColBreaks(t, l, oWorksheet.rowBreaks); + }); + } else if (c_oSerWorksheetsTypes.ColBreaks === type) { + oWorksheet.colBreaks = new AscCommonExcel.CRowColBreaks(); + res = this.bcr.Read1(length, function (t, l) { + return oThis.ReadRowColBreaks(t, l, oWorksheet.colBreaks); + }); + //} else if (c_oSerWorksheetsTypes.LegacyDrawingHF === type) { // oWorksheet.legacyDrawingHF = { // drawings: [], cfe: null, cff: null, cfo: null, che: null, chf: null, cho: null, lfe: null, // lff: null, lfo: null, lhe: null, lhf: null, lho: null, rfe: null, rff: null, rfo: null, rhe: null, @@ -9895,34 +9894,43 @@ return res; }; this.ReadRowColBreaks = function (type, length, breaks) { - var oThis = this; - var res = c_oSerConstants.ReadOk; + let oThis = this; + let res = c_oSerConstants.ReadOk; + let val; if (c_oSer_RowColBreaks.Count === type) { - breaks.count = this.stream.GetLong(); + val = this.stream.GetLong(); + breaks.setCount(val); } else if (c_oSer_RowColBreaks.ManualBreakCount === type) { - breaks.manualBreakCount = this.stream.GetLong(); + val = this.stream.GetLong(); + breaks.setManualBreakCount(val); } else if (c_oSer_RowColBreaks.Break === type) { - var brk = {id: null, man: null, max: null, min: null, pt: null}; + var brk = new AscCommonExcel.CBreak(); res = this.bcr.Read1(length, function(t, l) { return oThis.ReadRowColBreak(t, l, brk); }); - breaks.breaks.push(brk); + breaks.pushBreak(brk); } else res = c_oSerConstants.ReadUnknown; return res; }; this.ReadRowColBreak = function (type, length, brk) { - var res = c_oSerConstants.ReadOk; + let res = c_oSerConstants.ReadOk; + let val; if (c_oSer_RowColBreaks.Id === type) { - brk.id = this.stream.GetLong(); + val = this.stream.GetLong(); + brk.setId(val); } else if (c_oSer_RowColBreaks.Man === type) { - brk.man = this.stream.GetBool(); + val = this.stream.GetBool(); + brk.setMan(val); } else if (c_oSer_RowColBreaks.Max === type) { - brk.max = this.stream.GetLong(); + val = this.stream.GetLong(); + brk.setMax(val); } else if (c_oSer_RowColBreaks.Min === type) { - brk.min = this.stream.GetLong(); + val = this.stream.GetLong(); + brk.setMin(val); } else if (c_oSer_RowColBreaks.Pt === type) { - brk.pt = this.stream.GetBool(); + val = this.stream.GetBool(); + brk.setPt(val); } else res = c_oSerConstants.ReadUnknown; return res; diff --git a/cell/model/UndoRedo.js b/cell/model/UndoRedo.js index f30619cc7d..5ff6a0ba0e 100644 --- a/cell/model/UndoRedo.js +++ b/cell/model/UndoRedo.js @@ -454,6 +454,8 @@ function (window, undefined) { this.externalReference = 170; + this.RowColBreaks = 175; + this.Create = function (nType) { switch (nType) { case this.ValueMultiTextElem: @@ -837,16 +839,12 @@ function (window, undefined) { switch (nType) { case this.Properties.from: return this.from; - break; case this.Properties.to: return this.to; - break; case this.Properties.copyRange: return this.copyRange; - break; case this.Properties.sheetIdTo: return this.sheetIdTo; - break; } return null; }; @@ -886,13 +884,10 @@ function (window, undefined) { switch (nType) { case this.Properties.from: return this.from; - break; case this.Properties.to: return this.to; - break; case this.Properties.hyperlink: return this.hyperlink; - break; } return null; }; @@ -930,10 +925,8 @@ function (window, undefined) { switch (nType) { case this.Properties.index: return this.index; - break; case this.Properties.oNewVal: return this.oNewVal; - break; } return null; }; @@ -995,22 +988,16 @@ function (window, undefined) { switch (nType) { case this.Properties.width: return this.width; - break; case this.Properties.hd: return this.hd; - break; case this.Properties.CustomWidth: return this.CustomWidth; - break; case this.Properties.BestFit: return this.BestFit; - break; case this.Properties.OutlineLevel: return this.OutlineLevel; - break; case this.Properties.Collapsed: return this.Collapsed; - break; } return null; }; @@ -1074,19 +1061,14 @@ function (window, undefined) { switch (nType) { case this.Properties.h: return this.h; - break; case this.Properties.hd: return this.hd; - break; case this.Properties.CustomHeight: return this.CustomHeight; - break; case this.Properties.OutlineLevel: return this.OutlineLevel; - break; case this.Properties.Collapsed: return this.Collapsed; - break; } return null; }; @@ -1137,16 +1119,12 @@ function (window, undefined) { switch (nType) { case this.Properties.c1: return this.c1; - break; case this.Properties.r1: return this.r1; - break; case this.Properties.c2: return this.c2; - break; case this.Properties.r2: return this.r2; - break; } return null; }; @@ -1229,13 +1207,10 @@ function (window, undefined) { switch (nType) { case this.Properties.bbox: return this.bbox; - break; case this.Properties.places: return this.places; - break; case this.Properties.sortByRow: return this.sortByRow; - break; } return null; }; @@ -1288,13 +1263,10 @@ function (window, undefined) { switch (nType) { case this.Properties.pivot: return this.pivot; - break; case this.Properties.from: return this.from; - break; case this.Properties.to: return this.to; - break; } return null; }; @@ -1340,16 +1312,12 @@ function (window, undefined) { switch (nType) { case this.Properties.pivot: return this.pivot; - break; case this.Properties.index: return this.index; - break; case this.Properties.from: return this.from; - break; case this.Properties.to: return this.to; - break; } return null; }; @@ -1452,10 +1420,8 @@ function (window, undefined) { switch (nType) { case this.Properties.from: return this.from; - break; case this.Properties.to: return this.to; - break; } return null; }; @@ -1557,10 +1523,8 @@ function (window, undefined) { switch (nType) { case this.Properties.sheetId: return this.sheetId; - break; case this.Properties.sheet: return this.sheet; - break; } return null; }; @@ -1596,19 +1560,14 @@ function (window, undefined) { switch (nType) { case this.Properties.name: return this.name; - break; case this.Properties.ref: return this.ref; - break; case this.Properties.sheetId: return this.sheetId; - break; case this.Properties.type: return this.type; - break; case this.Properties.isXLNM: return this.isXLNM; - break; } return null; }; @@ -1857,7 +1816,7 @@ function (window, undefined) { tableCustomFunc: [] }; - var table = new AscCommonExcel.TablePart(); + table = new AscCommonExcel.TablePart(); var res = oBinaryTableReader.bcr.Read1(dstLen, function (t, l) { return oBinaryTableReader.ReadTable(t, l, table); }); @@ -1928,10 +1887,8 @@ function (window, undefined) { switch (nType) { case this.Properties.range: return new UndoRedoData_BBox(this.range); - break; case this.Properties.formula: return this.formula; - break; } return null; @@ -1966,7 +1923,6 @@ function (window, undefined) { switch (nType) { case this.Properties.elem: return this.elem; - break; } return null; }; @@ -1998,16 +1954,12 @@ function (window, undefined) { switch (nType) { case this.Properties.from: return this.from; - break; case this.Properties.to: return this.to; - break; case this.Properties.bFilter: return this.bFilter; - break; case this.Properties.tableName: return this.tableName; - break; } return null; }; @@ -2047,13 +1999,10 @@ function (window, undefined) { switch (nType) { case this.Properties.name: return this.name; - break; case this.Properties.from: return this.from; - break; case this.Properties.to: return this.to; - break; } return null; }; @@ -2090,13 +2039,10 @@ function (window, undefined) { switch (nType) { case this.Properties.id: return this.id; - break; case this.Properties.from: return this.from; - break; case this.Properties.to: return this.to; - break; } return null; }; @@ -2144,13 +2090,10 @@ function (window, undefined) { switch (nType) { case this.Properties.id: return this.id; - break; case this.Properties.from: return this.from; - break; case this.Properties.to: return this.to; - break; } return null; }; @@ -2187,13 +2130,10 @@ function (window, undefined) { switch (nType) { case this.Properties.id: return this.id; - break; case this.Properties.from: return this.from; - break; case this.Properties.to: return this.to; - break; } return null; }; @@ -2301,6 +2241,64 @@ function (window, undefined) { } }; + function UndoRedoData_RowColBreaks(id, min, max, man, pt, byCol) { + this.id = id; + this.min = min; + this.max = max; + this.man = man; + this.pt = pt; + this.byCol = byCol; + } + + UndoRedoData_RowColBreaks.prototype.Properties = { + id: 0, min: 1, max: 2, man: 3, pt: 4, byCol: 5 + }; + UndoRedoData_RowColBreaks.prototype.getType = function () { + return UndoRedoDataTypes.RowColBreaks; + }; + UndoRedoData_RowColBreaks.prototype.getProperties = function () { + return this.Properties; + }; + UndoRedoData_RowColBreaks.prototype.getProperty = function (nType) { + switch (nType) { + case this.Properties.id: + return this.id; + case this.Properties.min: + return this.min; + case this.Properties.max: + return this.max; + case this.Properties.man: + return this.man; + case this.Properties.pt: + return this.pt; + case this.Properties.byCol: + return this.byCol; + } + return null; + }; + UndoRedoData_RowColBreaks.prototype.setProperty = function (nType, value) { + switch (nType) { + case this.Properties.id: + this.id = value; + break; + case this.Properties.min: + this.min = value; + break; + case this.Properties.max: + this.min = value; + break; + case this.Properties.man: + this.min = value; + break; + case this.Properties.pt: + this.pt = value; + break; + case this.Properties.byCol: + this.byCol = value; + break; + } + }; + //для применения изменений var UndoRedoClassTypes = new function () { this.aTypes = []; @@ -3379,6 +3377,26 @@ function (window, undefined) { if (window["NATIVE_EDITOR_ENJINE"] || !wb.oApi.isDocumentLoadComplete || !wb.bCollaborativeChanges) { ws.setSheetViewType(bUndo ? Data.from : Data.to); } + } else if (AscCH.historyitem_Worksheet_ChangeRowColBreaks === Type) { + let from, to, min, max, man, pt, byCol; + if (bUndo) { + from = Data.to && Data.to.id; + to = Data.from && Data.from.id; + min = Data.from && Data.from.min; + max = Data.from && Data.from.max; + man = Data.from && Data.from.man; + pt = Data.from && Data.from.pt; + byCol = (Data.from && Data.from.byCol) || (Data.to && Data.to.byCol); + } else { + from = Data.from && Data.from.id; + to = Data.to && Data.to.id; + min = Data.to && Data.to.min; + max = Data.to && Data.to.max; + man = Data.to && Data.to.man; + pt = Data.to && Data.to.pt; + byCol = (Data.from && Data.from.byCol) || (Data.to && Data.to.byCol); + } + ws._changeRowColBreaks(from, to, min, max, man, pt, byCol); } }; UndoRedoWoorksheet.prototype.forwardTransformationIsAffect = function (Type) { @@ -4950,6 +4968,7 @@ function (window, undefined) { window['AscCommonExcel'].UndoRedoData_CF = UndoRedoData_CF; window['AscCommonExcel'].UndoRedoData_ProtectedRange = UndoRedoData_ProtectedRange; window['AscCommonExcel'].UndoRedoData_UserProtectedRange = UndoRedoData_UserProtectedRange; + window['AscCommonExcel'].UndoRedoData_RowColBreaks = UndoRedoData_RowColBreaks; window['AscCommonExcel'].UndoRedoWorkbook = UndoRedoWorkbook; window['AscCommonExcel'].UndoRedoCell = UndoRedoCell; window['AscCommonExcel'].UndoRedoWoorksheet = UndoRedoWoorksheet; diff --git a/cell/model/Workbook.js b/cell/model/Workbook.js index 1f6907de68..152be47ac9 100644 --- a/cell/model/Workbook.js +++ b/cell/model/Workbook.js @@ -11835,7 +11835,118 @@ return printProps.getJson(this); }; + Worksheet.prototype.changeRowColBreaks = function (from, to, range, byCol, addToHistory) { + let min = null; + let max = byCol ? gc_nMaxCol0 : gc_nMaxRow0; + let man = true, pt = null; + + let printArea = this.workbook.getDefinesNames("Print_Area", this.getId()); + if (printArea && range) { + if (byCol) { + min = range.r1; + max = range.r2; + } else { + min = range.c1; + max = range.c2; + } + } + + this._changeRowColBreaks(from, to, min, max, man, pt, byCol, addToHistory); + }; + + Worksheet.prototype._changeRowColBreaks = function (from, to, min, max, man, pt, byCol, addToHistory) { + let t = this; + let rowColBreaks = !byCol ? t.rowBreaks : t.colBreaks; + + let checkInit = function () { + if (!byCol) { + if (!t.rowBreaks) { + t.rowBreaks = new AscCommonExcel.CRowColBreaks(); + rowColBreaks = t.rowBreaks; + } + } else { + if (!t.colBreaks) { + t.colBreaks = new AscCommonExcel.CRowColBreaks(); + rowColBreaks = t.colBreaks; + } + } + }; + + let isChanged = false; + let oFromBreak = rowColBreaks && rowColBreaks.getBreak(from, min, max); + if (oFromBreak) { + if (to) { + //change + checkInit(); + isChanged = rowColBreaks.changeBreak(from, to, min, max, true); + } else { + //delete + isChanged = rowColBreaks && rowColBreaks.removeBreak(from, min, max); + } + } else if (to) { + //add + checkInit(); + isChanged = rowColBreaks.addBreak(to, min, max, true, null) + } + + if (isChanged && addToHistory) { + let fromData = oFromBreak && new AscCommonExcel.UndoRedoData_RowColBreaks(from, oFromBreak.min, oFromBreak.max, oFromBreak.man, oFromBreak.pt, byCol); + let toData = new AscCommonExcel.UndoRedoData_RowColBreaks(to, min, max, man, pt, byCol); + + History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ChangeRowColBreaks, this.getId(), + null, new AscCommonExcel.UndoRedoData_FromTo(fromData, toData)); + } + + this.workbook.handlers.trigger("onChangePageSetupProps", this.getId()); + }; + + Worksheet.prototype.resetAllPageBreaks = function () { + let t = this; + + let doRemoveBreaks = function(_breaks, byCol) { + if (!_breaks) { + return; + } + let aBreaks = _breaks.getBreaks(); + for (let i = 0; i < aBreaks.length; i++) { + let fromData = new AscCommonExcel.UndoRedoData_RowColBreaks(aBreaks[i].id, aBreaks[i].min, aBreaks[i].max, aBreaks[i].man, aBreaks[i].pt, byCol); + if (_breaks.removeBreak(aBreaks[i].id)) { + History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ChangeRowColBreaks, t.getId(), + null, new AscCommonExcel.UndoRedoData_FromTo(fromData, null)); + i--; + } + } + }; + + if (this.rowBreaks) { + doRemoveBreaks(this.rowBreaks); + } + if (this.colBreaks) { + doRemoveBreaks(this.colBreaks, true); + } + this.workbook.handlers.trigger("onChangePageSetupProps", this.getId()); + }; + Worksheet.prototype.getPrintAreaRangeByRowCol = function (row, col) { + let printArea = this.workbook.getDefinesNames("Print_Area", this.getId()); + let t = this; + + if (printArea) { + let ranges; + AscCommonExcel.executeInR1C1Mode(false, function () { + ranges = AscCommonExcel.getRangeByRef(printArea.ref, t, true, true) + }); + if (ranges) { + for (let i = 0; i < ranges.length; i++) { + if (ranges[i].bbox.contains(col, row)) { + return ranges[i].bbox; + } + } + } + } + + return null; + }; Worksheet.prototype.addCellWatch = function (ref, addToHistory) { for (var i = 0; i < this.aCellWatches.length; i++) { diff --git a/cell/model/WorkbookElems.js b/cell/model/WorkbookElems.js index 8f22fbd57f..872dc02e89 100644 --- a/cell/model/WorkbookElems.js +++ b/cell/model/WorkbookElems.js @@ -13710,6 +13710,22 @@ QueryTableField.prototype.clone = function() { this.init(); }; + CHeaderFooter.prototype.isEmpty = function () { + if (this.alignWithMargins === null && + this.differentFirst === null && + this.differentOddEven === null && + this.scaleWithDoc === null && + this.evenFooter === null && + this.evenHeader === null && + this.firstFooter === null && + this.firstHeader === null && + this.oddFooter === null && + this.oddHeader === null) { + return true; + } + return false; + }; + function CHeaderFooterData(str) { this.str = str; @@ -15508,6 +15524,215 @@ QueryTableField.prototype.clone = function() { } }; + function CRowColBreaks(/*ws*/) { + this.count = null; + this.manualBreakCount = null; + this.breaks = []; + + return this; + } + CRowColBreaks.prototype.clone = function () { + var res = new CRowColBreaks(); + res.count = this.count; + res.manualBreakCount = this.count; + + for (let i = 0 ; i < this.breaks.length; i++) { + res.breaks.push(this.breaks[i].clone()); + } + + return res; + }; + CRowColBreaks.prototype.setCount = function (val) { + this.count = val; + }; + CRowColBreaks.prototype.setManualBreakCount = function (val) { + this.manualBreakCount = val; + }; + CRowColBreaks.prototype.pushBreak = function (val) { + this.breaks.push(val); + }; + CRowColBreaks.prototype.getCount = function () { + return this.count; + }; + CRowColBreaks.prototype.getManualBreakCount = function () { + return this.manualBreakCount; + }; + CRowColBreaks.prototype.getBreaks = function () { + return this.breaks; + }; + CRowColBreaks.prototype.isBreak = function (index, opt_min, opt_max) { + if (this.count > 0) { + for (let i = 0; i < this.breaks.length; i++) { + if (this.breaks[i].isBreak(index, opt_min, opt_max)) { + return true; + } + } + } + return false; + }; + CRowColBreaks.prototype.forEach = function (callback) { + for (var i = 0, l = this.breaks.length; i < l; ++i) { + if (callback(this.breaks[i], i)) { + break; + } + } + }; + CRowColBreaks.prototype.containsBreak = function (id, min, max) { + let res = false; + this.forEach(function (breaksElem) { + if (breaksElem.id === id) { + res = true; + return true; + } + }); + return res; + }; + CRowColBreaks.prototype.getBreak = function (id) { + let res = null; + this.forEach(function (breaksElem) { + if (breaksElem.id === id) { + res = breaksElem; + return true; + } + }); + return res; + }; + + CRowColBreaks.prototype.changeBreak = function (idFrom, idTo, min, max, man, pt) { + let breakElem = this.getBreak(idFrom); + if (breakElem) { + return breakElem.set(idTo, min, max, man, pt); + } + }; + + CRowColBreaks.prototype.addBreak = function (id, min, max, man, pt) { + if (!id) { + return false; + } + let newBreak = new CBreak(); + newBreak.set(id, min, max, man, pt); + return this._addBreak(newBreak); + }; + + CRowColBreaks.prototype._addBreak = function (newBreak) { + this.breaks.push(newBreak); + if (this.manualBreakCount === null) { + this.manualBreakCount = 0; + } + if (this.count === null) { + this.count = 0; + } + this.manualBreakCount++; + this.count++; + return true; + }; + + CRowColBreaks.prototype.removeBreak = function (id, min, max) { + let isDeleted = false; + for (let i = 0; i < this.breaks.length; i++) { + if (this.breaks[i].isBreak(id, min, max)) { + this.breaks.splice(i, 1); + isDeleted = true; + this.manualBreakCount--; + this.count--; + break; + } + } + return isDeleted; + }; + + + function CBreak(/*ws*/) { + this.id = null; + this.min = null; + this.max = null; + + this.man = null; + this.pt = null; + + return this; + } + CBreak.prototype.clone = function () { + var res = new CBreak(); + res.id = this.id; + + res.min = this.min; + res.max = this.max; + + res.man = this.man; + res.pt = this.pt; + + return res; + }; + CBreak.prototype.setId = function (val) { + this.id = val; + }; + CBreak.prototype.setMan = function (val) { + this.man = val; + }; + CBreak.prototype.setMax = function (val) { + this.max = val; + }; + CBreak.prototype.setMin = function (val) { + this.min = val; + }; + CBreak.prototype.setPt = function (val) { + this.pt = val; + }; + CBreak.prototype.getId = function () { + return this.id; + }; + CBreak.prototype.getMan = function () { + return this.man; + }; + CBreak.prototype.getMax = function () { + return this.max; + }; + CBreak.prototype.getMin = function () { + return this.min; + }; + CBreak.prototype.getPt = function () { + return this.pt; + }; + CBreak.prototype.isBreak = function (index, opt_min, opt_max) { + let res = this.id === index; + if (res) { + if (opt_min != null && opt_max != null) { + if (this.min == null && this.max == null) { + res = false; + } else { + if (this.min > opt_max || this.max < opt_min) { + res = false; + } + } + } + } + return res; + }; + CBreak.prototype.set = function (id, min, max, man, pt) { + let isChanged = false; + if (id !== this.getId()) { + this.setId(id); + isChanged = true; + } + if (min !== this.getMin()) { + this.setMin(min); + isChanged = true; + } + if (max !== this.getMax()) { + this.setMax(max); + isChanged = true; + } + if (man !== this.getMan()) { + this.setMan(man); + isChanged = true; + } + if (pt !== this.getPt()) { + this.setPt(pt); + isChanged = true; + } + return isChanged ? this : null; + }; @@ -15982,5 +16207,8 @@ QueryTableField.prototype.clone = function() { prot["asc_getValue"] = prot.asc_getValue; prot["asc_getFormula"] = prot.asc_getFormula; + window["AscCommonExcel"].CRowColBreaks = CRowColBreaks; + window["AscCommonExcel"].CBreak = CBreak; + })(window); diff --git a/cell/view/EventsController.js b/cell/view/EventsController.js index 72c48799f2..9d8e2dd9c9 100644 --- a/cell/view/EventsController.js +++ b/cell/view/EventsController.js @@ -1839,7 +1839,7 @@ if (this.isMoveResizeRange) { this.isMoveResizeRange = false; - this._moveResizeRangeHandleDone(this.targetInfo && this.targetInfo.isPageBreakPreview); + this._moveResizeRangeHandleDone(this.targetInfo && this.targetInfo.pageBreakSelectionType); return true; } // Режим установки закреплённых областей diff --git a/cell/view/WorkbookView.js b/cell/view/WorkbookView.js index 7c5360406d..1711020ed7 100644 --- a/cell/view/WorkbookView.js +++ b/cell/view/WorkbookView.js @@ -1743,7 +1743,7 @@ if (this.Api.isEditVisibleAreaOleEditor && target.isOleRange) { d = ws.changeSelectionMoveResizeVisibleAreaHandle(x, y, target); - } else if (target.isPageBreakPreview) { + } else if (target.pageBreakSelectionType) { d = ws.changePageBreakPreviewAreaHandle(x, y, target); } else { d = ws.changeSelectionMoveResizeRangeHandle(x, y, target, this.cellEditor); diff --git a/cell/view/WorksheetView.js b/cell/view/WorksheetView.js index 39ea71c216..5ebd392784 100644 --- a/cell/view/WorksheetView.js +++ b/cell/view/WorksheetView.js @@ -2101,7 +2101,7 @@ }; // ----- Drawing for print ----- - WorksheetView.prototype._calcPagesPrint = function(range, pageOptions, indexWorksheet, arrPages, printScale, adjustPrint) { + WorksheetView.prototype._calcPagesPrint = function(range, pageOptions, indexWorksheet, arrPages, printScale, adjustPrint, bPrintArea) { if (0 > range.r2 || 0 > range.c2) { // Ничего нет return; @@ -2121,8 +2121,8 @@ //vector_koef /= AscCommon.AscBrowser.retinaPixelRatio; } - var isOnlyFirstPage = adjustPrint && adjustPrint.isOnlyFirstPage; - var pageMargins, pageSetup, pageGridLines, pageHeadings; + let isOnlyFirstPage = adjustPrint && adjustPrint.isOnlyFirstPage; + let pageMargins, pageSetup, pageGridLines, pageHeadings; if (pageOptions) { pageMargins = pageOptions.asc_getPageMargins(); pageSetup = pageOptions.asc_getPageSetup(); @@ -2130,9 +2130,9 @@ pageHeadings = pageOptions.asc_getHeadings(); } - var bFitToWidth = false; - var bFitToHeight = false; - var pageWidth, pageHeight, pageOrientation, scale; + let bFitToWidth = false; + let bFitToHeight = false; + let pageWidth, pageHeight, pageOrientation, scale; if (pageSetup instanceof asc_CPageSetup) { pageWidth = pageSetup.asc_getWidth(); pageHeight = pageSetup.asc_getHeight(); @@ -2145,11 +2145,11 @@ scale = printScale / 100; } else { //scale пока всегда берём из модели - var pageSetupModel = this.model.PagePrintOptions ? this.model.PagePrintOptions.pageSetup : null; + let pageSetupModel = this.model.PagePrintOptions ? this.model.PagePrintOptions.pageSetup : null; scale = pageSetupModel ? pageSetupModel.asc_getScale() / 100 : 1; } - var pageLeftField, pageRightField, pageTopField, pageBottomField; + let pageLeftField, pageRightField, pageTopField, pageBottomField; if (pageMargins) { pageLeftField = Math.max(pageMargins.asc_getLeft(), c_oAscPrintDefaultSettings.MinPageLeftField); pageRightField = Math.max(pageMargins.asc_getRight(), c_oAscPrintDefaultSettings.MinPageRightField); @@ -2157,17 +2157,17 @@ pageBottomField = Math.max(pageMargins.asc_getBottom(), c_oAscPrintDefaultSettings.MinPageBottomField); } - var t = this; - var _getColumnWidth = function (index) { - var defaultWidth = t._getWidthForPrint(index); + let t = this; + let _getColumnWidth = function (index) { + let defaultWidth = t._getWidthForPrint(index); if (defaultWidth) { return defaultWidth; } return t._getColumnWidth(index); }; - var _getRowHeight = function (index) { - var defaultHeight = t._getHeightForPrint(index); + let _getRowHeight = function (index) { + let defaultHeight = t._getHeightForPrint(index); if (defaultHeight) { return defaultHeight; } @@ -2206,17 +2206,17 @@ } if (Asc.c_oAscPageOrientation.PageLandscape === pageOrientation) { - var tmp = pageWidth; + let tmp = pageWidth; pageWidth = pageHeight; pageHeight = tmp; } - var pageWidthWithFields = pageWidth - pageLeftField - pageRightField; - var pageHeightWithFields = pageHeight - pageTopField - pageBottomField; - var leftFieldInPx = pageLeftField / vector_koef + 1; - var topFieldInPx = pageTopField / vector_koef + 1; + let pageWidthWithFields = pageWidth - pageLeftField - pageRightField; + let pageHeightWithFields = pageHeight - pageTopField - pageBottomField; + let leftFieldInPx = pageLeftField / vector_koef + 1; + let topFieldInPx = pageTopField / vector_koef + 1; - var startPrintPreview = this.workbook.printPreviewState && this.workbook.printPreviewState.isStart(); + let startPrintPreview = this.workbook.printPreviewState && this.workbook.printPreviewState.isStart(); let _retinaPixelRatio = this.getRetinaPixelRatio(); if (pageHeadings) { @@ -2226,15 +2226,15 @@ } //TODO при сравнении резальтатов рассчета страниц в зависимости от scale - LO выдаёт похожие результаты, MS - другие. Необходимо пересмотреть! - var pageWidthWithFieldsHeadings = ((pageWidth - pageRightField) / vector_koef - leftFieldInPx); - var pageHeightWithFieldsHeadings = ((pageHeight - pageBottomField) / vector_koef - topFieldInPx); + let pageWidthWithFieldsHeadings = ((pageWidth - pageRightField) / vector_koef - leftFieldInPx); + let pageHeightWithFieldsHeadings = ((pageHeight - pageBottomField) / vector_koef - topFieldInPx); //PRINT TITLES - var tCol1, tCol2, tRow1, tRow2; + let tCol1, tCol2, tRow1, tRow2; //первостепенно ориентируемся что в этих настройках - var printTitlesHeight = pageOptions.printTitlesHeight; - var printTitlesWidth = pageOptions.printTitlesWidth; - var _titleRange; + let printTitlesHeight = pageOptions.printTitlesHeight; + let printTitlesWidth = pageOptions.printTitlesWidth; + let _titleRange; if (null !== printTitlesHeight) { AscCommonExcel.executeInR1C1Mode(AscCommonExcel.g_R1C1Mode, function () { _titleRange = AscCommonExcel.g_oRangeCache.getAscRange(printTitlesHeight); @@ -2260,17 +2260,17 @@ } } - //var titleWidth = 0, titleHeight = 0; + //let titleWidth = 0, titleHeight = 0; if (!printTitlesHeight || !printTitlesWidth) { - var printTitles = this.model.workbook.getDefinesNames("Print_Titles", this.model.getId()); + let printTitles = this.model.workbook.getDefinesNames("Print_Titles", this.model.getId()); if(printTitles) { - var printTitleRefs; + let printTitleRefs; AscCommonExcel.executeInR1C1Mode(false, function () { printTitleRefs = AscCommonExcel.getRangeByRef(printTitles.ref, t.model, true, true) }); if(printTitleRefs && printTitleRefs.length) { - for(var i = 0; i < printTitleRefs.length; i++) { - var bbox = printTitleRefs[i].bbox; + for(let i = 0; i < printTitleRefs.length; i++) { + let bbox = printTitleRefs[i].bbox; if(bbox) { if(c_oAscSelectionType.RangeCol === bbox.getType() && null == printTitlesWidth) { tCol1 = bbox.c1; @@ -2285,32 +2285,32 @@ } } - var currentColIndex = range.c1; - var currentWidth = 0; - var currentRowIndex = range.r1; - var currentHeight = 0; - var isCalcColumnsWidth = true; + let currentColIndex = range.c1; + let currentWidth = 0; + let currentRowIndex = range.r1; + let currentHeight = 0; + let isCalcColumnsWidth = true; - var currentHeightReal = 0; - var currentWidthReal = 0; + let currentHeightReal = 0; + let currentWidthReal = 0; - var bIsAddOffset = false; - var nCountOffset = 0; - var nCountPages = 0; + let bIsAddOffset = false; + let nCountOffset = 0; + let nCountPages = 0; - var curTitleWidth = 0, curTitleHeight = 0; - var addedTitleHeight = 0, addedTitleWidth = 0; + let curTitleWidth = 0, curTitleHeight = 0; + let addedTitleHeight = 0, addedTitleWidth = 0; - var startTitleArrRow = []; + let startTitleArrRow = []; - var j; - var baseTitleHeight = 0; + let j; + let baseTitleHeight = 0; if (tRow1 < currentRowIndex) { for (j = tRow1; j < Math.min(currentRowIndex, tRow2 + 1); j++) { baseTitleHeight += _getRowHeight(j) * scale; } } - var baseTitleWidth = 0; + let baseTitleWidth = 0; if (tCol1 < currentColIndex) { for (j = tCol1; j < Math.min(currentColIndex, tCol2 + 1); j++) { baseTitleWidth += _getColumnWidth(j) * scale; @@ -2322,9 +2322,10 @@ break; } - var newPagePrint = new asc_CPagePrint(); + let newPagePrint = new asc_CPagePrint(); - var colIndex = currentColIndex, rowIndex = currentRowIndex, pageRange; + let colIndex = currentColIndex, rowIndex = currentRowIndex, pageRange; + let rowBreak = false, colBreak = false; newPagePrint.indexWorksheet = indexWorksheet; @@ -2356,12 +2357,13 @@ newPagePrint.titleHeight = curTitleHeight; for (rowIndex = currentRowIndex; rowIndex <= range.r2; ++rowIndex) { - var currentRowHeight = _getRowHeight(rowIndex) * scale; - var currentRowHeightReal = (t._getRowHeight(rowIndex)/this.getRetinaPixelRatio()) *scale; - if (currentHeight + currentRowHeight + curTitleHeight > pageHeightWithFieldsHeadings && rowIndex !== currentRowIndex) { + let currentRowHeight = _getRowHeight(rowIndex) * scale; + let currentRowHeightReal = (t._getRowHeight(rowIndex)/this.getRetinaPixelRatio()) *scale; + rowBreak = !bFitToHeight && rowIndex !== currentRowIndex && t.model.rowBreaks && t.model.rowBreaks.isBreak(rowIndex, bPrintArea && range.c1, bPrintArea && range.c2); + if ((currentHeight + currentRowHeight + curTitleHeight > pageHeightWithFieldsHeadings + && rowIndex !== currentRowIndex) || rowBreak) { // Закончили рисовать страницу curTitleHeight = addedTitleHeight; - rowIndex = rowIndex; break; } if (isCalcColumnsWidth) { @@ -2378,17 +2380,18 @@ newPagePrint.titleWidth = curTitleWidth; for (colIndex = currentColIndex; colIndex <= range.c2; ++colIndex) { - var currentColWidth = _getColumnWidth(colIndex) * scale; - var currentRowWidthReal = (t._getColumnWidth(colIndex)/this.getRetinaPixelRatio()) *scale; + let currentColWidth = _getColumnWidth(colIndex) * scale; + let currentRowWidthReal = (t._getColumnWidth(colIndex)/this.getRetinaPixelRatio()) *scale; if (bIsAddOffset) { newPagePrint.startOffset = ++nCountOffset; newPagePrint.startOffsetPx = (pageWidthWithFieldsHeadings * newPagePrint.startOffset); currentColWidth -= newPagePrint.startOffsetPx; } - if (currentWidth + currentColWidth + curTitleWidth > pageWidthWithFieldsHeadings && colIndex !== currentColIndex) { + colBreak = !bFitToWidth && colIndex !== currentColIndex && t.model.colBreaks && t.model.colBreaks.isBreak(colIndex, bPrintArea && range.r1, bPrintArea && range.r2); + if ((currentWidth + currentColWidth + curTitleWidth > pageWidthWithFieldsHeadings + && colIndex !== currentColIndex) || colBreak) { curTitleWidth = addedTitleWidth; - colIndex = colIndex; break; } @@ -2656,7 +2659,7 @@ } let _startPages = arrPages.length; - this._calcPagesPrint(range, pageOptions, indexWorksheet, arrPages, tempPrintScale, adjustPrint); + this._calcPagesPrint(range, pageOptions, indexWorksheet, arrPages, tempPrintScale, adjustPrint, true); if(arrRanges) { arrRanges.push({range: range, start: _startPages, end: arrPages.length}); @@ -4833,15 +4836,20 @@ return; } - let oPrintPages = this.pagesModeData; + const t = this; + + const printArea = this.model.workbook.getDefinesNames("Print_Area", this.model.getId()); + const oPrintPages = this.pagesModeData; + const printPages = oPrintPages && oPrintPages.printPages; + const color = new CColor(0, 0, 208); + const printRanges = this._getPageBreakPreviewRanges(oPrintPages); + const lineType = AscCommonExcel.selectionLineType.ResizeRange; + const dashLineType = AscCommonExcel.selectionLineType.Dash | lineType; + const widthLine = 3; + let allPagesRange; //рисуем страницы - let printPages = oPrintPages && oPrintPages.printPages; if(printPages && printPages.length) { - let color = new CColor(0, 0, 208); - let printRanges = this._getPageBreakPreviewRanges(oPrintPages); - let lineType = AscCommonExcel.selectionLineType.ResizeRange; - let dashLineType = AscCommonExcel.selectionLineType.Dash | lineType; for (let i = 0; i < printRanges.length; i++) { let oPrintRange = printRanges[i]; allPagesRange = oPrintRange.range; @@ -4852,6 +4860,41 @@ } this._drawElements(this._drawSelectionElement, allPagesRange, lineType, color, true); } + + //draw pages break + let pageOptions = this.model.PagePrintOptions; + let pageSetup = pageOptions && pageOptions.asc_getPageSetup(); + let bFitToWidth = pageSetup && pageSetup.asc_getFitToWidth(); + let bFitToHeight = pageSetup && pageSetup.asc_getFitToHeight(); + + let doDrawBreaks = function (_break, _byCol) { + if (!printArea) { + t._drawElements(t._drawLineBetweenRowCol, _byCol && _break.id, !_byCol && _break.id, color, allPagesRange, widthLine); + return; + } + if (_break.min === null && _break.max === null) { + return; + } + + for (let i = 0; i < printRanges.length; i++) { + //if intersection with range between min/max -> draw line + let printRange = printRanges[i].range; + if (_break.isBreak(_break.id, _byCol ? printRange.r1 : printRange.c1, _byCol ? printRange.r2 : printRange.c2)) { + t._drawElements(t._drawLineBetweenRowCol, _byCol && _break.id, !_byCol && _break.id, color, printRange, widthLine); + } + } + }; + + if (this.model.colBreaks && !bFitToWidth) { + this.model.colBreaks.forEach(function (colBreak) { + doDrawBreaks(colBreak, true); + }); + } + if (this.model.rowBreaks && !bFitToHeight) { + this.model.rowBreaks.forEach(function (rowBreak) { + doDrawBreaks(rowBreak); + }); + } } }; @@ -6302,14 +6345,22 @@ let col = args[0]; let row = args[1]; let strokeColor = args[2]; + let range = args[3]; + let widthLine = args[4] != null ? args[4] : 2; let ctx = this.overlayCtx; + if (range) { + visibleRange = range.intersection(visibleRange); + } + if (!visibleRange) { + return; + } + let fHorLine, fVerLine; fHorLine = ctx.lineHorPrevPx; fVerLine = ctx.lineVerPrevPx; - let widthLine = 2; if (AscBrowser.retinaPixelRatio === 2) { widthLine = AscCommon.AscBrowser.convertToRetinaValue(widthLine, true); @@ -8726,18 +8777,41 @@ let oPrintPages = this.isPageBreakPreview(true) && this.pagesModeData; let res = null; let _range = null; + let pageBreakSelectionType = null;//1 - outer range, 2 - inner if (oPrintPages) { let printRanges = this._getPageBreakPreviewRanges(oPrintPages); + //hit in all pages area if (printRanges) { for (let i = 0; i < printRanges.length; i++) { res = this._hitInRange(printRanges[i].range, AscCommonExcel.selectionLineType.Resize, vr, x, y, offsetX, offsetY, true); if (res) { _range = printRanges[i].range.clone(); + pageBreakSelectionType = 1; break; } } } + //hit inside pages lines + if (!res) { + let printPages = this.pagesModeData.printPages; + if (printPages) { + for (let i = 0; i < printPages.length; i++) { + res = this._hitInRange(printPages[i].page.pageRange, + AscCommonExcel.selectionLineType.Resize, vr, x, y, offsetX, offsetY, true); + if (res) { + for (let j = 0; j < printRanges.length; j++) { + if (printPages[i].page.pageRange.intersection(printRanges[j].range)) { + _range = printRanges[j].range.clone(); + pageBreakSelectionType = 2; + break; + } + } + break; + } + } + } + } } return res ? { cursor: res.cursor, @@ -8745,7 +8819,7 @@ col: res.col, row: res.row, range: _range, - isPageBreakPreview: true + pageBreakSelectionType: pageBreakSelectionType } : null; }; @@ -10716,8 +10790,12 @@ WorksheetView.prototype._drawPageBreakPreviewSelectionRange = function () { var range = this.pageBreakPreviewSelectionRange; - this._drawElements(this._drawSelectionElement, range, AscCommonExcel.selectionLineType.ResizeRange, - this.settings.activeCellBorderColor); + if (this.pageBreakPreviewSelectionRange.pageBreakSelectionType === 2) { + this._drawElements(this._drawLineBetweenRowCol, range.colByX, range.rowByY, this.settings.activeCellBorderColor, range, 2); + } else { + this._drawElements(this._drawSelectionElement, range, AscCommonExcel.selectionLineType.ResizeRange, + this.settings.activeCellBorderColor); + } }; WorksheetView.prototype.changeVisibleAreaStartPoint = function (x, y, isCtrl, isRelative) { @@ -12252,93 +12330,87 @@ }; WorksheetView.prototype.changePageBreakPreviewAreaHandle = function (x, y, targetInfo) { - if (!targetInfo || !targetInfo.range) { + if (!targetInfo) { return; } var _range = targetInfo.range; this.pageBreakPreviewSelectionRange = _range; + this.pageBreakPreviewSelectionRange.pageBreakSelectionType = targetInfo.pageBreakSelectionType; if (null === this.startCellMoveResizeRange) { - return this._startResizePageBreakPreviewRangeHandle(x, y, targetInfo, _range); - } - return this._endResizePageBreakPreviewRangeHandle(x, y, targetInfo, _range).delta; - }; + this.startCellMoveResizeRange = _range.clone(true); - - WorksheetView.prototype._startResizePageBreakPreviewRangeHandle = function (x, y, targetInfo, range) { - var ar = range.clone(); - - // Колонка по X и строка по Y - var colByX = this._findColUnderCursor(x, /*canReturnNull*/false, false).col; - var rowByY = this._findRowUnderCursor(y, /*canReturnNull*/false, false).row; - - if ((targetInfo.cursor === kCurNEResize || targetInfo.cursor === kCurSEResize)) { - this.startCellMoveResizeRange = ar.clone(true); - } else { - this.startCellMoveResizeRange = ar.clone(true); - if (colByX < ar.c1) { - colByX = ar.c1; - } else if (colByX > ar.c2) { - colByX = ar.c2; - } - if (rowByY < ar.r1) { - rowByY = ar.r1; - } else if (rowByY > ar.r2) { - rowByY = ar.r2; + if (targetInfo.pageBreakSelectionType === 2) { + if (targetInfo.cursor === kCurEWResize) { + this.startCellMoveResizeRange.colByX = targetInfo.col + 1; + } else { + this.startCellMoveResizeRange.rowByY = targetInfo.row + 1; + } } + + return; } - return null; + return this._endResizePageBreakPreviewRangeHandle(x, y, targetInfo, _range).delta; }; WorksheetView.prototype._endResizePageBreakPreviewRangeHandle = function (x, y, targetInfo, range) { var d = new AscCommon.CellBase(0, 0); var colByX = this._findColUnderCursor(x, /*canReturnNull*/false, false).col; var rowByY = this._findRowUnderCursor(y, /*canReturnNull*/false, false).row; - var type = this.startCellMoveResizeRange.getType(); var ar = range.clone(); - this.overlayCtx.clear(); - if (targetInfo.cursor === kCurEWResize) { - if (this.startCellMoveResizeRange.c1 === targetInfo.col) { - //left border - ar.c1 = Math.min(colByX, this.startCellMoveResizeRange.c2); - } else if (this.startCellMoveResizeRange.c2 === targetInfo.col) { - //right border - ar.c2 = Math.max(colByX, this.startCellMoveResizeRange.c1); - } - } else if (targetInfo.cursor === kCurNSResize) { - if (this.startCellMoveResizeRange.r1 === targetInfo.row) { - //top border - ar.r1 = Math.min(rowByY, this.startCellMoveResizeRange.r2); - } else if (this.startCellMoveResizeRange.r2 === targetInfo.row) { - //bottom border - ar.r2 = Math.max(rowByY, this.startCellMoveResizeRange.r1); - } - } else if (targetInfo.cursor === kCurSEResize) { - //left up / right down - if (this.startCellMoveResizeRange.r1 === targetInfo.row) { - //right down - ar.c2 = Math.max(colByX, this.startCellMoveResizeRange.c1); - ar.r2 = Math.max(rowByY, this.startCellMoveResizeRange.r1); - } else if (this.startCellMoveResizeRange.r2 === targetInfo.row) { - //left up - ar.r1 = Math.min(rowByY, this.startCellMoveResizeRange.r2); - ar.c1 = Math.min(colByX, this.startCellMoveResizeRange.c2); - } - } else if (targetInfo.cursor === kCurNEResize) { - //right up / left down - if (this.startCellMoveResizeRange.r1 === targetInfo.row) { - //left down - ar.r2 = Math.max(rowByY, this.startCellMoveResizeRange.r1); - ar.c1 = Math.min(colByX, this.startCellMoveResizeRange.c2); - - } else if (this.startCellMoveResizeRange.r2 === targetInfo.row) { - //right up - ar.r1 = Math.min(rowByY, this.startCellMoveResizeRange.r2); - ar.c2 = Math.max(colByX, this.startCellMoveResizeRange.c1); + if (targetInfo.pageBreakSelectionType === 2) { + if (targetInfo.cursor === kCurEWResize) { + range.colByX = colByX; + ar.colByX = colByX; + } else { + range.rowByY = rowByY; + ar.rowByY = rowByY; } + } else { + if (targetInfo.cursor === kCurEWResize) { + if (this.startCellMoveResizeRange.c1 === targetInfo.col) { + //left border + ar.c1 = Math.min(colByX, this.startCellMoveResizeRange.c2); + } else if (this.startCellMoveResizeRange.c2 === targetInfo.col) { + //right border + ar.c2 = Math.max(colByX, this.startCellMoveResizeRange.c1); + } + } else if (targetInfo.cursor === kCurNSResize) { + if (this.startCellMoveResizeRange.r1 === targetInfo.row) { + //top border + ar.r1 = Math.min(rowByY, this.startCellMoveResizeRange.r2); + } else if (this.startCellMoveResizeRange.r2 === targetInfo.row) { + //bottom border + ar.r2 = Math.max(rowByY, this.startCellMoveResizeRange.r1); + } + } else if (targetInfo.cursor === kCurSEResize) { + //left up / right down + if (this.startCellMoveResizeRange.r1 === targetInfo.row) { + //right down + ar.c2 = Math.max(colByX, this.startCellMoveResizeRange.c1); + ar.r2 = Math.max(rowByY, this.startCellMoveResizeRange.r1); + } else if (this.startCellMoveResizeRange.r2 === targetInfo.row) { + //left up + ar.r1 = Math.min(rowByY, this.startCellMoveResizeRange.r2); + ar.c1 = Math.min(colByX, this.startCellMoveResizeRange.c2); + } + } else if (targetInfo.cursor === kCurNEResize) { + //right up / left down + if (this.startCellMoveResizeRange.r1 === targetInfo.row) { + //left down + ar.r2 = Math.max(rowByY, this.startCellMoveResizeRange.r1); + ar.c1 = Math.min(colByX, this.startCellMoveResizeRange.c2); + + } else if (this.startCellMoveResizeRange.r2 === targetInfo.row) { + //right up + ar.r1 = Math.min(rowByY, this.startCellMoveResizeRange.r2); + ar.c2 = Math.max(colByX, this.startCellMoveResizeRange.c1); + } + } + ar = range.assign2(ar.clone(true)); } if (y <= this.cellsTop + 2) { @@ -12353,7 +12425,7 @@ d.col = 1; } - type = this.startCellMoveResizeRange.getType(); + let type = this.startCellMoveResizeRange.getType(); if (type === c_oAscSelectionType.RangeRow) { d.col = 0; } else if (type === c_oAscSelectionType.RangeCol) { @@ -12362,24 +12434,24 @@ d.col = 0; d.row = 0; } - ar = range.assign2(ar.clone(true)); + this._drawSelection(); return {range: ar, delta: d}; }; WorksheetView.prototype.changeSelectionMoveResizeRangeHandle = function (x, y, targetInfo, editor) { - // Возвращаемый результат - if (!targetInfo) { - return null; - } + // Возвращаемый результат + if (!targetInfo) { + return null; + } - if (this.getFormulaEditMode()) { - editor.cleanSelectRange(); - } + if (this.getFormulaEditMode()) { + editor.cleanSelectRange(); + } - var index = targetInfo.indexFormulaRange; - var initialRange = this.oOtherRanges.ranges[index]; + var index = targetInfo.indexFormulaRange; + var initialRange = this.oOtherRanges.ranges[index]; if (null === this.startCellMoveResizeRange) { return this._startMoveResizeRangeHandle(x, y, targetInfo, initialRange); @@ -12567,12 +12639,26 @@ WorksheetView.prototype.applyResizePageBreakPreviewRangeHandle = function () { let fromRange = this.startCellMoveResizeRange; let toRange = this.pageBreakPreviewSelectionRange; - if (!this.getFormulaEditMode() && !fromRange.isEqual(toRange)) { - var printArea = this.model.workbook.getDefinesNames("Print_Area", this.model.getId()); - if(printArea && printArea.sheetId === this.model.getId()) { - this.changePrintArea(Asc.c_oAscChangePrintAreaType.change, [toRange], [fromRange]) - } else { - this.changePrintArea(Asc.c_oAscChangePrintAreaType.set, [toRange]); + if (!this.getFormulaEditMode()) { + if (this.pageBreakPreviewSelectionRange.pageBreakSelectionType === 2) { + //change page breaks + if (toRange.colByX) { + if (toRange.colByX !== fromRange.colByX) { + this.changeRowColBreaks(fromRange.colByX, toRange.colByX, fromRange, true, true) + } + } else { + if (toRange.rowByY !== fromRange.rowByY) { + this.changeRowColBreaks(fromRange.rowByY, toRange.rowByY, fromRange, null, true) + } + } + } else if (!fromRange.isEqual(toRange)) { + //change all area + var printArea = this.model.workbook.getDefinesNames("Print_Area", this.model.getId()); + if(printArea && printArea.sheetId === this.model.getId()) { + this.changePrintArea(Asc.c_oAscChangePrintAreaType.change, [toRange], [fromRange]) + } else { + this.changePrintArea(Asc.c_oAscChangePrintAreaType.set, [toRange]); + } } } @@ -21345,6 +21431,142 @@ return res; }; + WorksheetView.prototype.changeRowColBreaks = function (from, to, range, byCol, opt_handle_move) { + var t = this; + + if (from === -1 || to === -1) { + return; + } + + var onChangeCallback = function (isSuccess) { + if (false === isSuccess) { + return; + } + + History.Create_NewPoint(); + History.StartTransaction(); + + //remove all breaks on path(from->to) + if (opt_handle_move) { + let reverse = from > to; + let firstIndex = !reverse ? from : to; + let lastIndex = !reverse ? to : from; + + for (let i = firstIndex; i <= lastIndex; i++) { + if (i === from) { + continue; + } + + t.model.changeRowColBreaks(i, null, range, byCol, true); + } + } + + t.model.changeRowColBreaks(from, to, range, byCol, true); + t.changeViewPrintLines(true); + + if(t.viewPrintLines) { + t.updateSelection(); + } + window["Asc"]["editor"]._onUpdateLayoutMenu(t.model.Id); + + History.EndTransaction(); + }; + + //do lock print settings + this._isLockedLayoutOptions(onChangeCallback); + }; + + WorksheetView.prototype.insertPageBreak = function () { + let t = this; + + //TODO check need change?(if added already by col and row) + + let onChangeCallback = function (isSuccess) { + if (false === isSuccess) { + return; + } + + History.Create_NewPoint(); + History.StartTransaction(); + + let activeCell = t.model.getSelection().activeCell; + let range = t.model.getPrintAreaRangeByRowCol(activeCell.row, activeCell.col); + + t.model.changeRowColBreaks(null, activeCell.row, range, null, true); + t.model.changeRowColBreaks(null, activeCell.col, range, true, true); + + t.changeViewPrintLines(true); + + if(t.viewPrintLines) { + t.updateSelection(); + } + window["Asc"]["editor"]._onUpdateLayoutMenu(t.model.Id); + + History.EndTransaction(); + }; + + //do lock print settings + this._isLockedLayoutOptions(onChangeCallback); + }; + + WorksheetView.prototype.removePageBreak = function () { + let t = this; + + let onChangeCallback = function (isSuccess) { + if (false === isSuccess) { + return; + } + + History.Create_NewPoint(); + History.StartTransaction(); + + let activeCell = t.model.getSelection().activeCell; + let range = t.model.getPrintAreaRangeByRowCol(activeCell.row, activeCell.col); + + t.model.changeRowColBreaks(activeCell.row, null, range, null, true); + t.model.changeRowColBreaks(activeCell.col, null, range, true, true); + + t.changeViewPrintLines(true); + + if(t.viewPrintLines) { + t.updateSelection(); + } + window["Asc"]["editor"]._onUpdateLayoutMenu(t.model.Id); + + History.EndTransaction(); + }; + + //do lock print settings + this._isLockedLayoutOptions(onChangeCallback); + }; + + WorksheetView.prototype.resetAllPageBreaks = function () { + let t = this; + + let onChangeCallback = function (isSuccess) { + if (false === isSuccess) { + return; + } + + History.Create_NewPoint(); + History.StartTransaction(); + + t.model.resetAllPageBreaks(); + + t.changeViewPrintLines(true); + + if(t.viewPrintLines) { + t.updateSelection(); + } + window["Asc"]["editor"]._onUpdateLayoutMenu(t.model.Id); + + History.EndTransaction(); + }; + + //do lock print settings + this._isLockedLayoutOptions(onChangeCallback); + }; + WorksheetView.prototype.changePrintTitles = function (cols, rows) { var t = this; diff --git a/tests/cell/spreadsheet-calculation/PrintTests.js b/tests/cell/spreadsheet-calculation/PrintTests.js index cee5b88afc..12a4ccbb1f 100644 --- a/tests/cell/spreadsheet-calculation/PrintTests.js +++ b/tests/cell/spreadsheet-calculation/PrintTests.js @@ -45,7 +45,33 @@ $(function() { AscCommon.baseEditorsApi.prototype._onEndLoadSdk.call(this); }; Asc.spreadsheet_api.prototype.initGlobalObjects = function(wbModel) { + AscCommonExcel.g_oUndoRedoCell = new AscCommonExcel.UndoRedoCell(wbModel); + AscCommonExcel.g_oUndoRedoWorksheet = new AscCommonExcel.UndoRedoWoorksheet(wbModel); + AscCommonExcel.g_oUndoRedoWorkbook = new AscCommonExcel.UndoRedoWorkbook(wbModel); + AscCommonExcel.g_oUndoRedoCol = new AscCommonExcel.UndoRedoRowCol(wbModel, false); + AscCommonExcel.g_oUndoRedoRow = new AscCommonExcel.UndoRedoRowCol(wbModel, true); + AscCommonExcel.g_oUndoRedoComment = new AscCommonExcel.UndoRedoComment(wbModel); + AscCommonExcel.g_oUndoRedoAutoFilters = new AscCommonExcel.UndoRedoAutoFilters(wbModel); + AscCommonExcel.g_oUndoRedoSparklines = new AscCommonExcel.UndoRedoSparklines(wbModel); AscCommonExcel.g_DefNameWorksheet = new AscCommonExcel.Worksheet(wbModel, -1); + AscCommonExcel.g_oUndoRedoSharedFormula = new AscCommonExcel.UndoRedoSharedFormula(wbModel); + AscCommonExcel.g_oUndoRedoLayout = new AscCommonExcel.UndoRedoRedoLayout(wbModel); + AscCommonExcel.g_oUndoRedoHeaderFooter = new AscCommonExcel.UndoRedoHeaderFooter(wbModel); + AscCommonExcel.g_oUndoRedoArrayFormula = new AscCommonExcel.UndoRedoArrayFormula(wbModel); + AscCommonExcel.g_oUndoRedoSortState = new AscCommonExcel.UndoRedoSortState(wbModel); + AscCommonExcel.g_oUndoRedoSlicer = new AscCommonExcel.UndoRedoSlicer(wbModel); + AscCommonExcel.g_oUndoRedoPivotTables = new AscCommonExcel.UndoRedoPivotTables(wbModel); + AscCommonExcel.g_oUndoRedoPivotFields = new AscCommonExcel.UndoRedoPivotFields(wbModel); + AscCommonExcel.g_oUndoRedoCF = new AscCommonExcel.UndoRedoCF(wbModel); + AscCommonExcel.g_oUndoRedoProtectedRange = new AscCommonExcel.UndoRedoProtectedRange(wbModel); + AscCommonExcel.g_oUndoRedoProtectedSheet = new AscCommonExcel.UndoRedoProtectedSheet(wbModel); + AscCommonExcel.g_oUndoRedoProtectedWorkbook = new AscCommonExcel.UndoRedoProtectedWorkbook(wbModel); + AscCommonExcel.g_oUndoRedoNamedSheetViews = new AscCommonExcel.UndoRedoNamedSheetViews(wbModel); + AscCommonExcel.g_oUndoRedoUserProtectedRange = new AscCommonExcel.UndoRedoUserProtectedRange(wbModel); + + History.init(wbModel); + }; + Asc.spreadsheet_api.prototype._onUpdateDocumentCanSave = function() { }; AscCommonExcel.WorkbookView.prototype._onWSSelectionChanged = function() { }; @@ -60,8 +86,6 @@ $(function() { }; AscCommonExcel.WorksheetView.prototype._autoFitColumnsWidth = function() { }; - AscCommonExcel.WorksheetView.prototype.setSelection = function() { - }; AscCommonExcel.WorksheetView.prototype.draw = function() { }; AscCommonExcel.WorksheetView.prototype._prepareDrawingObjects = function() { @@ -93,7 +117,8 @@ $(function() { startTests(); }; - AscCommon.CHistory.prototype.Create_NewPoint = function() { + AscCommon.CHistory.prototype.UndoRedoEnd = function () { + this.TurnOn(); }; var api = new Asc.spreadsheet_api({ @@ -116,7 +141,7 @@ $(function() { function comparePrintPageSettings (assert, obj1, obj2, desc) { for (let i in obj1) { if (obj1.hasOwnProperty(i)) { - if (i === "pageRange") { + if (typeof(obj1[i]) === "object" && (i === "pageRange" || i === "titleRowRange" || i === "titleColRange")) { for (let j in obj1[i]) { if (obj1[i].hasOwnProperty(j)) { assert.strictEqual(obj1[i][j], obj2[i][j], desc + j); @@ -134,9 +159,15 @@ $(function() { wsView.changeWorksheet("update", {reinitRanges: true}); } + function undoAll() { + while(AscCommon.History.Index !== -1) { + AscCommon.History.Undo(); + } + } + let wb, ws, wsView; function testPrintFileSettings() { - QUnit.test("Test: open print settings ", function(assert ) { + QUnit.test("Test: open print settings ", function (assert) { let printPagesData = api.wb.calcPagesPrint(new Asc.asc_CAdjustPrint()); assert.strictEqual(printPagesData.arrPages.length, 1, "Compare pages length 1"); let page = printPagesData.arrPages[0]; @@ -350,6 +381,1011 @@ $(function() { }; comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings changes without scale page4: "); + + undoAll(); + updateView(); + + printPagesData = api.wb.calcPagesPrint(new Asc.asc_CAdjustPrint()); + assert.strictEqual(printPagesData.arrPages.length, 1, "Compare pages length 1"); + page = printPagesData.arrPages[0]; + referenceObj = { + indexWorksheet: 0, + leftFieldInPx: 38.79527559055118, + pageClipRectHeight: 700.7800000000003, + pageClipRectLeft: 37.79527559055118, + pageClipRectTop: 37.79527559055118, + pageClipRectWidth: 796.2399999999999, + pageGridLines: false, + pageHeadings: false, + pageHeight: 210, + pageWidth: 297, + scale: 0.74, + startOffset: 0, + startOffsetPx: 0, + titleColRange: null, + titleHeight: 0, + titleRowRange: null, + titleWidth: 0, + topFieldInPx: 38.79527559055118, + pageRange: { + c1: 0, + c2: 18, + r1: 0, + r2: 57, + refType1: 3, + refType2: 3 + } + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings 1:"); + AscCommon.History.Clear(); + }); + } + + function testPageBreaksSimple() { + QUnit.test("Test: page break settings ", function (assert) { + //change active cell and add page break + //C5 + wsView.setSelection(new Asc.Range(2, 4, 2, 4)); + api.asc_InsertPageBreak(); + + let printPagesData = api.wb.calcPagesPrint(new Asc.asc_CAdjustPrint()); + assert.strictEqual(printPagesData.arrPages.length, 1, "Compare pages length 1"); + let page = printPagesData.arrPages[0]; + let referenceObj = { + indexWorksheet: 0, + leftFieldInPx: 38.79527559055118, + pageClipRectHeight: 700.7800000000003, + pageClipRectLeft: 37.79527559055118, + pageClipRectTop: 37.79527559055118, + pageClipRectWidth: 796.2399999999999, + pageGridLines: false, + pageHeadings: false, + pageHeight: 210, + pageWidth: 297, + scale: 0.74, + startOffset: 0, + startOffsetPx: 0, + titleColRange: null, + titleHeight: 0, + titleRowRange: null, + titleWidth: 0, + topFieldInPx: 38.79527559055118, + pageRange: { + c1: 0, + c2: 18, + r1: 0, + r2: 57, + refType1: 3, + refType2: 3 + } + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings 1:"); + wsView._changeFitToPage(0, 0); + updateView(); + + + printPagesData = api.wb.calcPagesPrint(new Asc.asc_CAdjustPrint()); + assert.strictEqual(printPagesData.arrPages.length, 4, "Compare pages length 2"); + + page = printPagesData.arrPages[0]; + + referenceObj = { + indexWorksheet:0, + leftFieldInPx:38.79527559055118, + pageClipRectHeight:43.66, + pageClipRectLeft:37.79527559055118, + pageClipRectTop:37.79527559055118, + pageClipRectWidth:67.34, + pageGridLines:false, + pageHeadings:false, + pageHeight:210, + pageWidth:297, + scale:0.74, + startOffset:0, + startOffsetPx:0, + titleColRange:null, + titleHeight:0, + titleRowRange:null, + titleWidth:0, + topFieldInPx:38.79527559055118, + pageRange: { + c1: 0, + c2: 1, + r1: 0, + r2: 3, + refType1: 3, + refType2: 3 + } + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings changes with scale page1: "); + + page = printPagesData.arrPages[1]; + + referenceObj = { + indexWorksheet:0, + leftFieldInPx:38.79527559055118, + pageClipRectHeight:43.66, + pageClipRectLeft:37.79527559055118, + pageClipRectTop:37.79527559055118, + pageClipRectWidth:728.9, + pageGridLines:false, + pageHeadings:false, + pageHeight:210, + pageWidth:297, + scale:0.74, + startOffset:0, + startOffsetPx:0, + titleColRange:null, + titleHeight:0, + titleRowRange:null, + titleWidth:0, + topFieldInPx:38.79527559055118, + pageRange: { + c1: 2, + c2: 18, + r1: 0, + r2: 3, + refType1: 3, + refType2: 3 + } + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings changes with scale page2: "); + + + page = printPagesData.arrPages[2]; + + referenceObj = { + indexWorksheet:0, + leftFieldInPx:38.79527559055118, + pageClipRectHeight:657.1200000000002, + pageClipRectLeft:37.79527559055118, + pageClipRectTop:37.79527559055118, + pageClipRectWidth:67.34, + pageGridLines:false, + pageHeadings:false, + pageHeight:210, + pageWidth:297, + scale:0.74, + startOffset:0, + startOffsetPx:0, + titleColRange:null, + titleHeight:0, + titleRowRange:null, + titleWidth:0, + topFieldInPx:38.79527559055118, + pageRange: { + c1: 0, + c2: 1, + r1: 4, + r2: 57, + refType1: 3, + refType2: 3 + } + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings changes with scale page3: "); + + page = printPagesData.arrPages[3]; + + referenceObj = { + indexWorksheet:0, + leftFieldInPx:38.79527559055118, + pageClipRectHeight:657.1200000000002, + pageClipRectLeft:37.79527559055118, + pageClipRectTop:37.79527559055118, + pageClipRectWidth:728.9, + pageGridLines:false, + pageHeadings:false, + pageHeight:210, + pageWidth:297, + scale:0.74, + startOffset:0, + startOffsetPx:0, + titleColRange:null, + titleHeight:0, + titleRowRange:null, + titleWidth:0, + topFieldInPx:38.79527559055118, + pageRange: { + c1: 2, + c2: 18, + r1: 4, + r2: 57, + refType1: 3, + refType2: 3 + } + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings changes with scale page4: "); + + api.asc_SetPrintScale(null, null, 100); + + updateView(); + + printPagesData = api.wb.calcPagesPrint(new Asc.asc_CAdjustPrint()); + assert.strictEqual(printPagesData.arrPages.length, 6, "Compare pages length 2"); + + page = printPagesData.arrPages[0]; + + referenceObj = { + indexWorksheet:0, + leftFieldInPx:38.79527559055118, + pageClipRectHeight:59, + pageClipRectLeft:37.79527559055118, + pageClipRectTop:37.79527559055118, + pageClipRectWidth:91, + pageGridLines:false, + pageHeadings:false, + pageHeight:210, + pageWidth:297, + scale:1, + startOffset:0, + startOffsetPx:0, + titleColRange:null, + titleHeight:0, + titleRowRange:null, + titleWidth:0, + topFieldInPx:38.79527559055118, + pageRange: { + c1: 0, + c2: 1, + r1: 0, + r2: 3, + refType1: 3, + refType2: 3 + } + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings changes without scale page1: "); + + page = printPagesData.arrPages[1]; + + referenceObj = { + indexWorksheet:0, + leftFieldInPx:38.79527559055118, + pageClipRectHeight:59, + pageClipRectLeft:37.79527559055118, + pageClipRectTop:37.79527559055118, + pageClipRectWidth:985, + pageGridLines:false, + pageHeadings:false, + pageHeight:210, + pageWidth:297, + scale:1, + startOffset:0, + startOffsetPx:0, + titleColRange:null, + titleHeight:0, + titleRowRange:null, + titleWidth:0, + topFieldInPx:38.79527559055118, + pageRange: { + c1: 2, + c2: 18, + r1: 0, + r2: 3, + refType1: 3, + refType2: 3 + } + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings changes without scale page2: "); + + page = printPagesData.arrPages[2]; + + referenceObj = { + indexWorksheet:0, + leftFieldInPx:38.79527559055118, + pageClipRectHeight:705, + pageClipRectLeft:37.79527559055118, + pageClipRectTop:37.79527559055118, + pageClipRectWidth:91, + pageGridLines:false, + pageHeadings:false, + pageHeight:210, + pageWidth:297, + scale:1, + startOffset:0, + startOffsetPx:0, + titleColRange:null, + titleHeight:0, + titleRowRange:null, + titleWidth:0, + topFieldInPx:38.79527559055118, + pageRange: { + c1: 0, + c2: 1, + r1: 4, + r2: 48, + refType1: 3, + refType2: 3 + } + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings changes without scale page3: "); + + page = printPagesData.arrPages[3]; + + referenceObj = { + indexWorksheet:0, + leftFieldInPx:38.79527559055118, + pageClipRectHeight:705, + pageClipRectLeft:37.79527559055118, + pageClipRectTop:37.79527559055118, + pageClipRectWidth:985, + pageGridLines:false, + pageHeadings:false, + pageHeight:210, + pageWidth:297, + scale:1, + startOffset:0, + startOffsetPx:0, + titleColRange:null, + titleHeight:0, + titleRowRange:null, + titleWidth:0, + topFieldInPx:38.79527559055118, + pageRange: { + c1: 2, + c2: 18, + r1: 4, + r2: 48, + refType1: 3, + refType2: 3 + } + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings changes without scale page4: "); + + page = printPagesData.arrPages[4]; + + referenceObj = { + indexWorksheet:0, + leftFieldInPx:38.79527559055118, + pageClipRectHeight:183, + pageClipRectLeft:37.79527559055118, + pageClipRectTop:37.79527559055118, + pageClipRectWidth:91, + pageGridLines:false, + pageHeadings:false, + pageHeight:210, + pageWidth:297, + scale:1, + startOffset:0, + startOffsetPx:0, + titleColRange:null, + titleHeight:0, + titleRowRange:null, + titleWidth:0, + topFieldInPx:38.79527559055118, + pageRange: { + c1: 0, + c2: 1, + r1: 49, + r2: 57, + refType1: 3, + refType2: 3 + } + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings changes without scale page5: "); + + page = printPagesData.arrPages[5]; + + referenceObj = { + indexWorksheet:0, + leftFieldInPx:38.79527559055118, + pageClipRectHeight:183, + pageClipRectLeft:37.79527559055118, + pageClipRectTop:37.79527559055118, + pageClipRectWidth:985, + pageGridLines:false, + pageHeadings:false, + pageHeight:210, + pageWidth:297, + scale:1, + startOffset:0, + startOffsetPx:0, + titleColRange:null, + titleHeight:0, + titleRowRange:null, + titleWidth:0, + topFieldInPx:38.79527559055118, + pageRange: { + c1: 2, + c2: 18, + r1: 49, + r2: 57, + refType1: 3, + refType2: 3 + } + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings changes without scale page6: "); + + undoAll(); + updateView(); + + printPagesData = api.wb.calcPagesPrint(new Asc.asc_CAdjustPrint()); + assert.strictEqual(printPagesData.arrPages.length, 1, "Compare pages length 6 after undo"); + page = printPagesData.arrPages[0]; + referenceObj = { + indexWorksheet: 0, + leftFieldInPx: 38.79527559055118, + pageClipRectHeight: 700.7800000000003, + pageClipRectLeft: 37.79527559055118, + pageClipRectTop: 37.79527559055118, + pageClipRectWidth: 796.2399999999999, + pageGridLines: false, + pageHeadings: false, + pageHeight: 210, + pageWidth: 297, + scale: 0.74, + startOffset: 0, + startOffsetPx: 0, + titleColRange: null, + titleHeight: 0, + titleRowRange: null, + titleWidth: 0, + topFieldInPx: 38.79527559055118, + pageRange: { + c1: 0, + c2: 18, + r1: 0, + r2: 57, + refType1: 3, + refType2: 3 + } + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings after undo:"); + AscCommon.History.Clear(); + }); + } + + function testPageBreaksAndTitles() { + QUnit.test("Test: page break and titles settings ", function (assert) { + api.asc_SetPrintScale(null, null, 100); + api.asc_changePrintTitles("$A:$D", "$1:$5", 0); + wsView.setSelection(new Asc.Range(1, 3, 1, 3)); + api.asc_InsertPageBreak(); + + let printPagesData = api.wb.calcPagesPrint(new Asc.asc_CAdjustPrint()); + assert.strictEqual(printPagesData.arrPages.length, 9, "Compare pages length with print titles"); + + let page = printPagesData.arrPages[0]; + + let referenceObj = { + "pageWidth": 297, + "pageHeight": 210, + "pageClipRectLeft": 37.79527559055118, + "pageClipRectTop": 37.79527559055118, + "pageClipRectWidth": 21, + "pageClipRectHeight": 45, + "pageRange": {"c1": 0, "r1": 0, "c2": 0, "r2": 2, "refType1": 3, "refType2": 3}, + "leftFieldInPx": 38.79527559055118, + "topFieldInPx": 38.79527559055118, + "pageGridLines": false, + "pageHeadings": false, + "indexWorksheet": 0, + "startOffset": 0, + "startOffsetPx": 0, + "scale": 1, + "titleRowRange": null, + "titleColRange": null, + "titleWidth": 0, + "titleHeight": 0 + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings with titles 1:"); + + page = printPagesData.arrPages[1]; + + referenceObj = { + "pageWidth": 297, + "pageHeight": 210, + "pageClipRectLeft": 37.79527559055118, + "pageClipRectTop": 37.79527559055118, + "pageClipRectWidth": 966, + "pageClipRectHeight": 45, + "pageRange": {"c1": 1, "r1": 0, "c2": 16, "r2": 2, "refType1": 3, "refType2": 3}, + "leftFieldInPx": 38.79527559055118, + "topFieldInPx": 38.79527559055118, + "pageGridLines": false, + "pageHeadings": false, + "indexWorksheet": 0, + "startOffset": 0, + "startOffsetPx": 0, + "scale": 1, + "titleRowRange": null, + "titleColRange": {"c1": 0, "r1": 0, "c2": 0, "r2": 2, "refType1": 3, "refType2": 3}, + "titleWidth": 21, + "titleHeight": 0 + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings with titles 2:"); + + page = printPagesData.arrPages[2]; + + referenceObj = { + "pageWidth": 297, + "pageHeight": 210, + "pageClipRectLeft": 37.79527559055118, + "pageClipRectTop": 37.79527559055118, + "pageClipRectWidth": 89, + "pageClipRectHeight": 45, + "pageRange": {"c1": 17, "r1": 0, "c2": 18, "r2": 2, "refType1": 3, "refType2": 3}, + "leftFieldInPx": 38.79527559055118, + "topFieldInPx": 38.79527559055118, + "pageGridLines": false, + "pageHeadings": false, + "indexWorksheet": 0, + "startOffset": 0, + "startOffsetPx": 0, + "scale": 1, + "titleRowRange": null, + "titleColRange": {"c1": 0, "r1": 0, "c2": 3, "r2": 2, "refType1": 3, "refType2": 3}, + "titleWidth": 177, + "titleHeight": 0 + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings with titles 3:"); + + page = printPagesData.arrPages[3]; + + referenceObj = { + "pageWidth": 297, + "pageHeight": 210, + "pageClipRectLeft": 37.79527559055118, + "pageClipRectTop": 37.79527559055118, + "pageClipRectWidth": 21, + "pageClipRectHeight": 662, + "pageRange": {"c1": 0, "r1": 3, "c2": 0, "r2": 45, "refType1": 3, "refType2": 3}, + "leftFieldInPx": 38.79527559055118, + "topFieldInPx": 38.79527559055118, + "pageGridLines": false, + "pageHeadings": false, + "indexWorksheet": 0, + "startOffset": 0, + "startOffsetPx": 0, + "scale": 1, + "titleRowRange": {"c1": 0, "r1": 0, "c2": 0, "r2": 2, "refType1": 3, "refType2": 3}, + "titleColRange": null, + "titleWidth": 0, + "titleHeight": 45 + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings with titles 4:"); + + page = printPagesData.arrPages[4]; + + referenceObj = { + "pageWidth": 297, + "pageHeight": 210, + "pageClipRectLeft": 37.79527559055118, + "pageClipRectTop": 37.79527559055118, + "pageClipRectWidth": 966, + "pageClipRectHeight": 662, + "pageRange": {"c1": 1, "r1": 3, "c2": 16, "r2": 45, "refType1": 3, "refType2": 3}, + "leftFieldInPx": 38.79527559055118, + "topFieldInPx": 38.79527559055118, + "pageGridLines": false, + "pageHeadings": false, + "indexWorksheet": 0, + "startOffset": 0, + "startOffsetPx": 0, + "scale": 1, + "titleRowRange": {"c1": 1, "r1": 0, "c2": 16, "r2": 2, "refType1": 3, "refType2": 3}, + "titleColRange": {"c1": 0, "r1": 3, "c2": 0, "r2": 45, "refType1": 3, "refType2": 3}, + "titleWidth": 21, + "titleHeight": 45 + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings with titles 5:"); + + page = printPagesData.arrPages[5]; + + referenceObj = { + "pageWidth": 297, + "pageHeight": 210, + "pageClipRectLeft": 37.79527559055118, + "pageClipRectTop": 37.79527559055118, + "pageClipRectWidth": 89, + "pageClipRectHeight": 662, + "pageRange": {"c1": 17, "r1": 3, "c2": 18, "r2": 45, "refType1": 3, "refType2": 3}, + "leftFieldInPx": 38.79527559055118, + "topFieldInPx": 38.79527559055118, + "pageGridLines": false, + "pageHeadings": false, + "indexWorksheet": 0, + "startOffset": 0, + "startOffsetPx": 0, + "scale": 1, + "titleRowRange": {"c1": 17, "r1": 0, "c2": 18, "r2": 2, "refType1": 3, "refType2": 3}, + "titleColRange": {"c1": 0, "r1": 3, "c2": 3, "r2": 45, "refType1": 3, "refType2": 3}, + "titleWidth": 177, + "titleHeight": 45 + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings with titles 6:"); + + page = printPagesData.arrPages[7]; + + referenceObj = { + "pageWidth": 297, + "pageHeight": 210, + "pageClipRectLeft": 37.79527559055118, + "pageClipRectTop": 37.79527559055118, + "pageClipRectWidth": 966, + "pageClipRectHeight": 240, + "pageRange": {"c1": 1, "r1": 46, "c2": 16, "r2": 57, "refType1": 3, "refType2": 3}, + "leftFieldInPx": 38.79527559055118, + "topFieldInPx": 38.79527559055118, + "pageGridLines": false, + "pageHeadings": false, + "indexWorksheet": 0, + "startOffset": 0, + "startOffsetPx": 0, + "scale": 1, + "titleRowRange": {"c1": 1, "r1": 0, "c2": 16, "r2": 4, "refType1": 3, "refType2": 3}, + "titleColRange": {"c1": 0, "r1": 46, "c2": 0, "r2": 57, "refType1": 3, "refType2": 3}, + "titleWidth": 21, + "titleHeight": 73 + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings with titles 8:"); + + undoAll(); + updateView(); + + printPagesData = api.wb.calcPagesPrint(new Asc.asc_CAdjustPrint()); + assert.strictEqual(printPagesData.arrPages.length, 1, "Compare pages length 6 after undo"); + page = printPagesData.arrPages[0]; + referenceObj = { + indexWorksheet: 0, + leftFieldInPx: 38.79527559055118, + pageClipRectHeight: 700.7800000000003, + pageClipRectLeft: 37.79527559055118, + pageClipRectTop: 37.79527559055118, + pageClipRectWidth: 796.2399999999999, + pageGridLines: false, + pageHeadings: false, + pageHeight: 210, + pageWidth: 297, + scale: 0.74, + startOffset: 0, + startOffsetPx: 0, + titleColRange: null, + titleHeight: 0, + titleRowRange: null, + titleWidth: 0, + topFieldInPx: 38.79527559055118, + pageRange: { + c1: 0, + c2: 18, + r1: 0, + r2: 57, + refType1: 3, + refType2: 3 + } + }; + + comparePrintPageSettings(assert, page, referenceObj, "Compare pages settings after undo:"); + AscCommon.History.Clear(); + }); + } + + function checkUndoRedo(fBefore, fAfter, desc, skipLastUndo) { + fAfter("after_" + desc); + AscCommon.History.Undo(); + fBefore("undo_" + desc); + AscCommon.History.Redo(); + fAfter("redo_" + desc); + if (!skipLastUndo) { + AscCommon.History.Undo(); + } + } + + function testPageBreaksManipulation() { + QUnit.test("Test: page break manipulation ", function (assert) { + //add breaks + ws = api.wbModel.aWorksheets[0]; + + let beforeFunc = function(desc) { + assert.strictEqual((ws.colBreaks == null || ws.colBreaks.getCount() === 0) ? null : 1, null, desc); + assert.strictEqual((ws.rowBreaks == null || ws.rowBreaks.getCount() === 0) ? null : 1, null, desc); + }; + + let insertColBreakId = 1; + let insertRowBreakId = 3; + wsView.setSelection(new Asc.Range(insertColBreakId, insertRowBreakId, insertColBreakId, insertRowBreakId)); + api.asc_InsertPageBreak(); + + checkUndoRedo(beforeFunc, function (desc){ + assert.strictEqual(ws.colBreaks.getCount(), 1, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 1, desc + " check row count"); + + assert.strictEqual(ws.colBreaks.containsBreak(insertColBreakId), true, desc + " check col contains"); + assert.strictEqual(ws.rowBreaks.containsBreak(insertRowBreakId), true, desc + " check row contains"); + }, "insert page break_col1row3"); + + + insertColBreakId = 5; + insertRowBreakId = 5; + wsView.setSelection(new Asc.Range(insertColBreakId, insertRowBreakId, insertColBreakId, insertRowBreakId)); + api.asc_InsertPageBreak(); + + checkUndoRedo(beforeFunc, function (desc){ + assert.strictEqual(ws.colBreaks.getCount(), 1, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 1, desc + " check row count"); + + assert.strictEqual(ws.colBreaks.containsBreak(insertColBreakId), true, desc + " check col contains"); + assert.strictEqual(ws.rowBreaks.containsBreak(insertRowBreakId), true, desc + " check row contains"); + }, "insert page break_col5row5"); + + + + insertColBreakId = 1; + insertRowBreakId = 1; + wsView.setSelection(new Asc.Range(insertColBreakId, insertRowBreakId, insertColBreakId, insertRowBreakId)); + api.asc_InsertPageBreak(); + + checkUndoRedo(beforeFunc, function (desc){ + assert.strictEqual(ws.colBreaks.getCount(), 1, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 1, desc + " check row count"); + + assert.strictEqual(ws.colBreaks.containsBreak(insertColBreakId), true, desc + " check col contains"); + assert.strictEqual(ws.rowBreaks.containsBreak(insertRowBreakId), true, desc + " check row contains"); + }, "insert page break_col1row1"); + + insertColBreakId = 0; + insertRowBreakId = 0; + wsView.setSelection(new Asc.Range(insertColBreakId, insertRowBreakId, insertColBreakId, insertRowBreakId)); + api.asc_InsertPageBreak(); + + checkUndoRedo(beforeFunc, function (desc){ + assert.strictEqual(ws.colBreaks.getCount(), 0, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 0, desc + " check row count"); + }, "insert page break_col0row0"); + + insertColBreakId = 0; + insertRowBreakId = 1; + wsView.setSelection(new Asc.Range(insertColBreakId, insertRowBreakId, insertColBreakId, insertRowBreakId)); + api.asc_InsertPageBreak(); + + checkUndoRedo(beforeFunc, function (desc){ + assert.strictEqual(ws.colBreaks.getCount(), 0, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 1, desc + " check row count"); + + assert.strictEqual(ws.rowBreaks.containsBreak(insertRowBreakId), true, desc + " check row contains"); + }, "insert page break_col0row1"); + + insertColBreakId = 1; + insertRowBreakId = 0; + wsView.setSelection(new Asc.Range(insertColBreakId, insertRowBreakId, insertColBreakId, insertRowBreakId)); + api.asc_InsertPageBreak(); + + checkUndoRedo(beforeFunc, function (desc){ + assert.strictEqual(ws.colBreaks.getCount(), 1, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 0, desc + " check row count"); + + assert.strictEqual(ws.colBreaks.containsBreak(insertColBreakId), true, desc + " check col contains"); + }, "insert page break_col1row0"); + + insertColBreakId = 3; + insertRowBreakId = 3; + wsView.setSelection(new Asc.Range(insertColBreakId, insertRowBreakId, insertColBreakId, insertRowBreakId)); + api.asc_InsertPageBreak(); + + checkUndoRedo(beforeFunc, function (desc){ + assert.strictEqual(ws.colBreaks.getCount(), 1, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 1, desc + " check row count"); + + assert.strictEqual(ws.colBreaks.containsBreak(insertColBreakId), true, desc + " check col contains"); + assert.strictEqual(ws.rowBreaks.containsBreak(insertRowBreakId), true, desc + " check row contains"); + }, "insert page break_col3row3", true); + + //remove + insertColBreakId = 4; + insertRowBreakId = 4; + wsView.setSelection(new Asc.Range(insertColBreakId, insertRowBreakId, insertColBreakId, insertRowBreakId)); + api.asc_RemovePageBreak(); + + assert.strictEqual(ws.colBreaks.getCount(), 1, " check col count + remove1"); + assert.strictEqual(ws.rowBreaks.getCount(), 1, " check row count + remove1"); + + assert.strictEqual(ws.colBreaks.containsBreak(3), true, " check col contains + remove1"); + assert.strictEqual(ws.rowBreaks.containsBreak(3), true, " check row contains + remove1"); + + + insertColBreakId = 3; + insertRowBreakId = 3; + wsView.setSelection(new Asc.Range(insertColBreakId, insertRowBreakId, insertColBreakId, insertRowBreakId)); + api.asc_RemovePageBreak(); + + checkUndoRedo(function (desc){ + assert.strictEqual(ws.colBreaks.getCount(), 1, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 1, desc + " check row count"); + + assert.strictEqual(ws.colBreaks.containsBreak(insertColBreakId), true, desc + " check col contains"); + assert.strictEqual(ws.rowBreaks.containsBreak(insertRowBreakId), true, desc + " check row contains"); + }, beforeFunc, "remove page break_col3row3"); + + assert.strictEqual(ws.colBreaks.getCount(), 1, " check col count + remove2"); + assert.strictEqual(ws.rowBreaks.getCount(), 1, " check row count + remove2"); + + assert.strictEqual(ws.colBreaks.containsBreak(3), true, " check col contains + remove2"); + assert.strictEqual(ws.rowBreaks.containsBreak(3), true, " check row contains + remove2"); + + insertColBreakId = 5; + insertRowBreakId = 5; + wsView.setSelection(new Asc.Range(insertColBreakId, insertRowBreakId, insertColBreakId, insertRowBreakId)); + api.asc_InsertPageBreak(); + + checkUndoRedo(function (desc) { + assert.strictEqual(ws.colBreaks.getCount(), 1, desc); + assert.strictEqual(ws.rowBreaks.getCount(), 1, desc); + }, function (desc){ + assert.strictEqual(ws.colBreaks.getCount(), 2, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 2, desc + " check row count"); + + assert.strictEqual(ws.colBreaks.containsBreak(insertColBreakId), true, desc + " check col contains"); + assert.strictEqual(ws.rowBreaks.containsBreak(insertRowBreakId), true, desc + " check row contains"); + }, "insert page break_col5row5", true); + + //reset all + api.asc_ResetAllPageBreaks(); + checkUndoRedo(function (desc) { + assert.strictEqual(ws.colBreaks.getCount(), 2, desc); + assert.strictEqual(ws.rowBreaks.getCount(), 2, desc); + + assert.strictEqual(ws.colBreaks.containsBreak(5), true, desc + " check col contains"); + assert.strictEqual(ws.rowBreaks.containsBreak(5), true, desc + " check row contains"); + assert.strictEqual(ws.colBreaks.containsBreak(3), true, desc + " check col contains"); + assert.strictEqual(ws.rowBreaks.containsBreak(3), true, desc + " check row contains"); + + }, beforeFunc, "remove all page breaks"); + + //move + insertColBreakId = 8; + insertRowBreakId = 8; + wsView.setSelection(new Asc.Range(insertColBreakId, insertRowBreakId, insertColBreakId, insertRowBreakId)); + api.asc_InsertPageBreak(); + + checkUndoRedo(function (desc) { + assert.strictEqual(ws.colBreaks.getCount(), 2, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 2, desc + " check row count"); + }, function (desc){ + assert.strictEqual(ws.colBreaks.getCount(), 3, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 3, desc + " check row count"); + }, "insert page break_col8row8", true); + + wsView.changeRowColBreaks(3, 4, new Asc.Range(0, 0, 16, 57), true, true); + + checkUndoRedo(function (desc) { + assert.strictEqual(ws.colBreaks.getCount(), 3, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 3, desc + " check row count"); + + assert.strictEqual(ws.colBreaks.containsBreak(8), true, desc + " check col contains 8"); + assert.strictEqual(ws.rowBreaks.containsBreak(8), true, desc + " check row contains 8"); + assert.strictEqual(ws.colBreaks.containsBreak(5), true, desc + " check col contains 5"); + assert.strictEqual(ws.rowBreaks.containsBreak(5), true, desc + " check row contains 5"); + assert.strictEqual(ws.colBreaks.containsBreak(3), true, desc + " check col contains 3"); + assert.strictEqual(ws.rowBreaks.containsBreak(3), true, desc + " check row contains 3"); + }, function (desc){ + + assert.strictEqual(ws.colBreaks.getCount(), 3, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 3, desc + " check row count"); + + assert.strictEqual(ws.colBreaks.containsBreak(8), true, desc + " check col contains 8"); + assert.strictEqual(ws.rowBreaks.containsBreak(8), true, desc + " check row contains 8"); + assert.strictEqual(ws.colBreaks.containsBreak(5), true, desc + " check col contains 5"); + assert.strictEqual(ws.rowBreaks.containsBreak(5), true, desc + " check row contains 5"); + assert.strictEqual(ws.colBreaks.containsBreak(4), true, desc + " check col contains 4"); + assert.strictEqual(ws.rowBreaks.containsBreak(3), true, desc + " check row contains 4"); + + }, "change page col break_from3to4"); + + wsView.changeRowColBreaks(3, 12, new Asc.Range(0, 0, 16, 57), true, true); + + checkUndoRedo(function (desc) { + assert.strictEqual(ws.colBreaks.getCount(), 3, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 3, desc + " check row count"); + + assert.strictEqual(ws.colBreaks.containsBreak(8), true, desc + " check col contains 8"); + assert.strictEqual(ws.rowBreaks.containsBreak(8), true, desc + " check row contains 8"); + assert.strictEqual(ws.colBreaks.containsBreak(5), true, desc + " check col contains 5"); + assert.strictEqual(ws.rowBreaks.containsBreak(5), true, desc + " check row contains 5"); + assert.strictEqual(ws.colBreaks.containsBreak(3), true, desc + " check col contains 3"); + assert.strictEqual(ws.rowBreaks.containsBreak(3), true, desc + " check row contains 3"); + }, function (desc){ + + assert.strictEqual(ws.colBreaks.getCount(), 1, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 3, desc + " check row count"); + + assert.strictEqual(ws.colBreaks.containsBreak(12), true, desc + " check col contains 12"); + assert.strictEqual(ws.rowBreaks.containsBreak(8), true, desc + " check row contains 8"); + assert.strictEqual(ws.rowBreaks.containsBreak(5), true, desc + " check row contains 5"); + assert.strictEqual(ws.rowBreaks.containsBreak(3), true, desc + " check row contains 4"); + + }, "change page col break_from3to12"); + + wsView.changeRowColBreaks(3, 12, new Asc.Range(0, 0, 16, 57), null, true); + + checkUndoRedo(function (desc) { + assert.strictEqual(ws.colBreaks.getCount(), 3, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 3, desc + " check row count"); + + assert.strictEqual(ws.colBreaks.containsBreak(8), true, desc + " check col contains 8"); + assert.strictEqual(ws.rowBreaks.containsBreak(8), true, desc + " check row contains 8"); + assert.strictEqual(ws.colBreaks.containsBreak(5), true, desc + " check col contains 5"); + assert.strictEqual(ws.rowBreaks.containsBreak(5), true, desc + " check row contains 5"); + assert.strictEqual(ws.colBreaks.containsBreak(3), true, desc + " check col contains 3"); + assert.strictEqual(ws.rowBreaks.containsBreak(3), true, desc + " check row contains 3"); + }, function (desc){ + + assert.strictEqual(ws.colBreaks.getCount(), 3, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 1, desc + " check row count"); + + assert.strictEqual(ws.rowBreaks.containsBreak(12), true, desc + " check row contains 12"); + assert.strictEqual(ws.colBreaks.containsBreak(8), true, desc + " check col contains 8"); + assert.strictEqual(ws.colBreaks.containsBreak(5), true, desc + " check col contains 5"); + assert.strictEqual(ws.colBreaks.containsBreak(3), true, desc + " check col contains 4"); + + }, "change page row break_from3to12"); + + + wsView.changeRowColBreaks(8, 2, new Asc.Range(0, 0, 16, 57), true, true); + + checkUndoRedo(function (desc) { + assert.strictEqual(ws.colBreaks.getCount(), 3, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 3, desc + " check row count"); + + assert.strictEqual(ws.colBreaks.containsBreak(8), true, desc + " check col contains 8"); + assert.strictEqual(ws.rowBreaks.containsBreak(8), true, desc + " check row contains 8"); + assert.strictEqual(ws.colBreaks.containsBreak(5), true, desc + " check col contains 5"); + assert.strictEqual(ws.rowBreaks.containsBreak(5), true, desc + " check row contains 5"); + assert.strictEqual(ws.colBreaks.containsBreak(3), true, desc + " check col contains 3"); + assert.strictEqual(ws.rowBreaks.containsBreak(3), true, desc + " check row contains 3"); + }, function (desc){ + + assert.strictEqual(ws.colBreaks.getCount(), 1, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 3, desc + " check row count"); + + assert.strictEqual(ws.colBreaks.containsBreak(2), true, desc + " check col contains 12"); + assert.strictEqual(ws.rowBreaks.containsBreak(8), true, desc + " check row contains 8"); + assert.strictEqual(ws.rowBreaks.containsBreak(5), true, desc + " check row contains 5"); + assert.strictEqual(ws.rowBreaks.containsBreak(3), true, desc + " check row contains 4"); + + }, "change page col break_from8to2"); + + wsView.changeRowColBreaks(8, 2, new Asc.Range(0, 0, 16, 57), null, true); + + checkUndoRedo(function (desc) { + assert.strictEqual(ws.colBreaks.getCount(), 3, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 3, desc + " check row count"); + + assert.strictEqual(ws.colBreaks.containsBreak(8), true, desc + " check col contains 8"); + assert.strictEqual(ws.rowBreaks.containsBreak(8), true, desc + " check row contains 8"); + assert.strictEqual(ws.colBreaks.containsBreak(5), true, desc + " check col contains 5"); + assert.strictEqual(ws.rowBreaks.containsBreak(5), true, desc + " check row contains 5"); + assert.strictEqual(ws.colBreaks.containsBreak(3), true, desc + " check col contains 3"); + assert.strictEqual(ws.rowBreaks.containsBreak(3), true, desc + " check row contains 3"); + }, function (desc){ + + assert.strictEqual(ws.colBreaks.getCount(), 3, desc + " check col count"); + assert.strictEqual(ws.rowBreaks.getCount(), 1, desc + " check row count"); + + assert.strictEqual(ws.rowBreaks.containsBreak(2), true, desc + " check row contains 12"); + assert.strictEqual(ws.colBreaks.containsBreak(8), true, desc + " check col contains 8"); + assert.strictEqual(ws.colBreaks.containsBreak(5), true, desc + " check col contains 5"); + assert.strictEqual(ws.colBreaks.containsBreak(3), true, desc + " check col contains 4"); + + }, "change page row break_from8to2"); }); } @@ -358,6 +1394,9 @@ $(function() { function startTests() { QUnit.start(); testPrintFileSettings(); + testPageBreaksSimple(); + testPageBreaksAndTitles(); + testPageBreaksManipulation(); }