Commit 49f6c95e authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander.Trofimov

Изменена структура хранения гиперссылок и merged ячеек для ускорения.Изменена...

Изменена структура хранения гиперссылок и merged ячеек для ускорения.Изменена функция moveRange,чтобы ее можно было использовать и на undo.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@50149 954022d7-b5bf-4e40-9824-e11837661b57
parent d9eee431
...@@ -32,6 +32,8 @@ var historyitem_Worksheet_CreateCol = 21; ...@@ -32,6 +32,8 @@ var historyitem_Worksheet_CreateCol = 21;
var historyitem_Worksheet_CreateCell = 22; var historyitem_Worksheet_CreateCell = 22;
var historyitem_Worksheet_SetViewSettings = 23; var historyitem_Worksheet_SetViewSettings = 23;
var historyitem_Worksheet_RemoveCellFormula = 24; var historyitem_Worksheet_RemoveCellFormula = 24;
var historyitem_Worksheet_ChangeMerge = 25;
var historyitem_Worksheet_ChangeHyperlink = 26;
var historyitem_RowCol_Fontname = 1; var historyitem_RowCol_Fontname = 1;
var historyitem_RowCol_Fontsize = 2; var historyitem_RowCol_Fontsize = 2;
......
...@@ -2152,8 +2152,6 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf ...@@ -2152,8 +2152,6 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf
this.nBorderMapIndex = 0; this.nBorderMapIndex = 0;
this.oNumMap = new Object(); this.oNumMap = new Object();
this.nNumMapIndex = 0; this.nNumMapIndex = 0;
this.oMerged = new Object();
this.oHyperlinks = new Object();
this.idWorksheet = idWorksheet; this.idWorksheet = idWorksheet;
this.oAllColXfsId = null; this.oAllColXfsId = null;
this._getCrc32FromObjWithProperty = function(val) this._getCrc32FromObjWithProperty = function(val)
...@@ -2207,8 +2205,6 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf ...@@ -2207,8 +2205,6 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf
for(var i = 0, length = this.wb.aWorksheets.length; i < length; ++i) for(var i = 0, length = this.wb.aWorksheets.length; i < length; ++i)
{ {
var ws = this.wb.aWorksheets[i]; var ws = this.wb.aWorksheets[i];
this.oMerged = new Object();
this.oHyperlinks = new Object();
if(null == this.idWorksheet || this.idWorksheet == ws.getId()) if(null == this.idWorksheet || this.idWorksheet == ws.getId())
this.bs.WriteItem(c_oSerWorksheetsTypes.Worksheet, function(){oThis.WriteWorksheet(ws, i);}); this.bs.WriteItem(c_oSerWorksheetsTypes.Worksheet, function(){oThis.WriteWorksheet(ws, i);});
} }
...@@ -2239,9 +2235,9 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf ...@@ -2239,9 +2235,9 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf
this.bs.WriteItem(c_oSerWorksheetsTypes.SheetData, function(){oThis.WriteSheetData(ws);}); this.bs.WriteItem(c_oSerWorksheetsTypes.SheetData, function(){oThis.WriteSheetData(ws);});
this.bs.WriteItem(c_oSerWorksheetsTypes.Hyperlinks, function(){oThis.WriteHyperlinks();}); this.bs.WriteItem(c_oSerWorksheetsTypes.Hyperlinks, function(){oThis.WriteHyperlinks(ws);});
this.bs.WriteItem(c_oSerWorksheetsTypes.MergeCells, function(){oThis.WriteMergeCells();}); this.bs.WriteItem(c_oSerWorksheetsTypes.MergeCells, function(){oThis.WriteMergeCells(ws);});
if ( ws.Drawings && (ws.Drawings.length) ) if ( ws.Drawings && (ws.Drawings.length) )
this.bs.WriteItem(c_oSerWorksheetsTypes.Drawings, function(){oThis.WriteDrawings(ws.Drawings);}); this.bs.WriteItem(c_oSerWorksheetsTypes.Drawings, function(){oThis.WriteDrawings(ws.Drawings);});
...@@ -2294,7 +2290,6 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf ...@@ -2294,7 +2290,6 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf
aIndexes.push(i - 0); aIndexes.push(i - 0);
aIndexes.sort(fSortAscending); aIndexes.sort(fSortAscending);
var fInitCol = function(col, nMin, nMax){ var fInitCol = function(col, nMin, nMax){
oThis.AddToMergedAndHyperlink(col);
var oRes = {BestFit: col.BestFit, hd: col.hd, Max: nMax, Min: nMin, xfsid: null, width: col.width, CustomWidth: col.CustomWidth}; var oRes = {BestFit: col.BestFit, hd: col.hd, Max: nMax, Min: nMin, xfsid: null, width: col.width, CustomWidth: col.CustomWidth};
if(null == oRes.width) if(null == oRes.width)
{ {
...@@ -2591,13 +2586,15 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf ...@@ -2591,13 +2586,15 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf
this.memory.WriteBool(bHeadings); this.memory.WriteBool(bHeadings);
} }
}; };
this.WriteHyperlinks = function() this.WriteHyperlinks = function(ws)
{ {
var oThis = this; var oThis = this;
for(var i in this.oHyperlinks) var oHyperlinks = ws.hyperlinkManager.getAll();
//todo sort
for(var i in oHyperlinks)
{ {
var hyp = this.oHyperlinks[i]; var elem = oHyperlinks[i];
this.bs.WriteItem(c_oSerWorksheetsTypes.Hyperlink, function(){oThis.WriteHyperlink(hyp);}); this.bs.WriteItem(c_oSerWorksheetsTypes.Hyperlink, function(){oThis.WriteHyperlink(elem.data);});
} }
}; };
this.WriteHyperlink = function(oHyperlink) this.WriteHyperlink = function(oHyperlink)
...@@ -2623,13 +2620,21 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf ...@@ -2623,13 +2620,21 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf
this.memory.WriteString2(oHyperlink.Tooltip); this.memory.WriteString2(oHyperlink.Tooltip);
} }
}; };
this.WriteMergeCells = function() this.WriteMergeCells = function(ws)
{ {
var oThis = this; var oThis = this;
for(var i in this.oMerged) var oMerged = ws.mergeManager.getAll();
for(var i in oMerged)
{ {
var elem = oMerged[i];
var bbox = elem.bbox;
if(bbox.r1 != bbox.r2 || bbox.c1 != bbox.c2)
{
var oFirst = new CellAddress(bbox.r1, bbox.c1, 0);
var oLast = new CellAddress(bbox.r2, bbox.c2, 0);
this.memory.WriteByte(c_oSerWorksheetsTypes.MergeCell); this.memory.WriteByte(c_oSerWorksheetsTypes.MergeCell);
this.memory.WriteString2(i); this.memory.WriteString2(oFirst.getID() + ":" + oLast.getID());
}
} }
}; };
this.WriteDrawings = function(aDrawings) this.WriteDrawings = function(aDrawings)
...@@ -2744,7 +2749,6 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf ...@@ -2744,7 +2749,6 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf
var row = ws.aGCells[aIndexes[i]]; var row = ws.aGCells[aIndexes[i]];
if(null != row) if(null != row)
{ {
this.AddToMergedAndHyperlink(row);
if(false == row.isEmptyToSave()) if(false == row.isEmptyToSave())
this.bs.WriteItem(c_oSerWorksheetsTypes.Row, function(){oThis.WriteRow(row);}); this.bs.WriteItem(c_oSerWorksheetsTypes.Row, function(){oThis.WriteRow(row);});
} }
...@@ -2801,8 +2805,7 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf ...@@ -2801,8 +2805,7 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf
var cell = aCells[aIndexes[i]]; var cell = aCells[aIndexes[i]];
//готовим ячейку к записи //готовим ячейку к записи
var nXfsId = this.prepareXfs(cell.xfs); var nXfsId = this.prepareXfs(cell.xfs);
this.AddToMergedAndHyperlink(cell); if(0 != nXfsId || false == cell.isEmptyText())
if(0 != nXfsId || false == cell.isEmptyText() || null != cell.merged || cell.hyperlinks.length > 0)
this.bs.WriteItem(c_oSerRowTypes.Cell, function(){oThis.WriteCell(cell, nXfsId);}); this.bs.WriteItem(c_oSerRowTypes.Cell, function(){oThis.WriteCell(cell, nXfsId);});
} }
}; };
...@@ -2921,19 +2924,6 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf ...@@ -2921,19 +2924,6 @@ function BinaryWorksheetsTableWriter(memory, wb, oSharedStrings, oDrawings, aDxf
} }
return nXfsId; return nXfsId;
}; };
this.AddToMergedAndHyperlink = function(container)
{
if(null != container.merged)
this.oMerged[container.merged.getName()] = 1;
if(null != container.hyperlinks)
{
for(var i = 0, length = container.hyperlinks.length; i < length; ++i)
{
var hyperlink = container.hyperlinks[i];
this.oHyperlinks[hyperlink.Ref.getName()] = hyperlink;
}
}
}
this.WriteCell = function(cell, nXfsId) this.WriteCell = function(cell, nXfsId)
{ {
var oThis = this; var oThis = this;
...@@ -5020,7 +5010,7 @@ function Binary_WorksheetTableReader(stream, wb, aSharedStrings, aCellXfs, Dxfs, ...@@ -5020,7 +5010,7 @@ function Binary_WorksheetTableReader(stream, wb, aSharedStrings, aCellXfs, Dxfs,
{ {
var hyperlink = this.aHyperlinks[i]; var hyperlink = this.aHyperlinks[i];
if (null !== hyperlink.Ref) if (null !== hyperlink.Ref)
hyperlink.Ref.setHyperlink(hyperlink, true); hyperlink.Ref.setHyperlinkOpen(hyperlink);
} }
oNewWorksheet.init(); oNewWorksheet.init();
this.wb.aWorksheets.push(oNewWorksheet); this.wb.aWorksheets.push(oNewWorksheet);
......
...@@ -3154,98 +3154,15 @@ UndoRedoWoorksheet.prototype = { ...@@ -3154,98 +3154,15 @@ UndoRedoWoorksheet.prototype = {
} }
else if(historyitem_Worksheet_MoveRange == Type) else if(historyitem_Worksheet_MoveRange == Type)
{ {
if( bUndo ){ //todo worksheetView.autoFilters._moveAutoFilters(worksheetView ,null, null, g_oUndoRedoAutoFiltersMoveData);
var from = Data.from;
var rec = {length:0}, rec2; var to = Data.to;
for(var ind = 0; ind < Data.arr.to.length; ind++ ){ if(bUndo)
var nRow = Data.arr.to[ind].getCellAddress().getRow0(),
nCol = Data.arr.to[ind].getCellAddress().getCol0();
var c = ws._getCell(nRow, nCol)
if( c.sFormula ){
this.wb.cwf[ws.Id].cells[c.getName()] = null;
delete this.wb.cwf[ws.Id].cells[ c.getName()];
}
var oTargetRow = ws._getRow(nRow);
if(Data.arr.to[ind].isEmpty()){
delete oTargetRow.c[nCol];
continue;
}
else{
var sn = ws.workbook.dependencyFormulas.getSlaveNodes(ws.Id,Data.arr.to[ind].getName())
if( sn ){
for( var _id in sn){
rec[_id] = [ sn[_id].sheetId, sn[_id].cellId ];
rec.length++;
}
}
oTargetRow.c[nCol] = Data.arr.to[ind];
if( oTargetRow.c[nCol].sFormula ){
this.wb.cwf[ws.Id].cells[ oTargetRow.c[nCol].getName() ] = oTargetRow.c[nCol].getName();
rec[ getVertexId(ws.Id,oTargetRow.c[nCol].getName()) ] = [ ws.Id, oTargetRow.c[nCol].getName() ];
rec.length++;
}
}
}
for(var ind = 0; ind < Data.arr.from.length; ind++ ){
var nRow = Data.arr.from[ind].getCellAddress().getRow0(),
nCol = Data.arr.from[ind].getCellAddress().getCol0();
var c = ws._getCell(nRow, nCol)
if( c.sFormula ){
this.wb.cwf[ws.Id].cells[c.getName()] = null;
delete this.wb.cwf[ws.Id].cells[ c.getName()];
}
var oTargetRow = ws._getRow(nRow);
if(Data.arr.from[ind].isEmpty()){
delete oTargetRow.c[nCol];
continue;
}
else{
var sn = ws.workbook.dependencyFormulas.getSlaveNodes(ws.Id,Data.arr.from[ind].getName())
if( sn ){
for( var _id in sn){
rec[_id] = [ sn[_id].sheetId, sn[_id].cellId ];
rec.length++;
}
}
oTargetRow.c[nCol] = Data.arr.from[ind];
if( oTargetRow.c[nCol].sFormula ){
this.wb.cwf[ws.Id].cells[ oTargetRow.c[nCol].getName() ] = oTargetRow.c[nCol].getName();
rec[ getVertexId(ws.Id,oTargetRow.c[nCol].getName()) ] = [ ws.Id, oTargetRow.c[nCol].getName() ];
rec.length++;
}
}
}
var offset = { offsetRow : Data.from.r1 - Data.to.r1, offsetCol : Data.from.c1 - Data.to.c1 }
rec2 = ws._moveRecalcGraph(Data.to, offset);
this.wb.buildDependency();
rec.length += rec2.length;
for( var id in rec2 ){
if( id == "length" ) continue;
rec[id] = rec2[id];
}
this.wb.needRecalc = rec;
recalc(this.wb);
if(g_oUndoRedoAutoFiltersMoveData)
{ {
var worksheetView = this.wb.oApi.wb.getWorksheetById(nSheetId); var temp = from;
worksheetView.autoFilters._moveAutoFilters(worksheetView ,null, null, g_oUndoRedoAutoFiltersMoveData); from = to;
g_oUndoRedoAutoFiltersMoveData = null; to = temp;
}
} }
else{
if(false != this.wb.bCollaborativeChanges) if(false != this.wb.bCollaborativeChanges)
{ {
var collaborativeEditing = this.wb.oApi.collaborativeEditing, var collaborativeEditing = this.wb.oApi.collaborativeEditing,
...@@ -3253,20 +3170,28 @@ UndoRedoWoorksheet.prototype = { ...@@ -3253,20 +3170,28 @@ UndoRedoWoorksheet.prototype = {
coBBoxTo = {r1:0,c1:0,r2:0,c2:0 }, coBBoxTo = {r1:0,c1:0,r2:0,c2:0 },
coBBoxFrom = {r1:0,c1:0,r2:0,c2:0 }; coBBoxFrom = {r1:0,c1:0,r2:0,c2:0 };
coBBoxTo.r1 = collaborativeEditing.getLockOtherRow2( nSheetId, Data.to.r1); coBBoxTo.r1 = collaborativeEditing.getLockOtherRow2( nSheetId, to.r1);
coBBoxTo.c1 = collaborativeEditing.getLockOtherColumn2( nSheetId, Data.to.c1); coBBoxTo.c1 = collaborativeEditing.getLockOtherColumn2( nSheetId, to.c1);
coBBoxTo.r2 = collaborativeEditing.getLockOtherRow2( nSheetId, Data.to.r2); coBBoxTo.r2 = collaborativeEditing.getLockOtherRow2( nSheetId, to.r2);
coBBoxTo.c2 = collaborativeEditing.getLockOtherColumn2( nSheetId, Data.to.c2); coBBoxTo.c2 = collaborativeEditing.getLockOtherColumn2( nSheetId, to.c2);
coBBoxFrom.r1 = collaborativeEditing.getLockOtherRow2( nSheetId, Data.from.r1); coBBoxFrom.r1 = collaborativeEditing.getLockOtherRow2( nSheetId, from.r1);
coBBoxFrom.c1 = collaborativeEditing.getLockOtherColumn2( nSheetId, Data.from.c1); coBBoxFrom.c1 = collaborativeEditing.getLockOtherColumn2( nSheetId, from.c1);
coBBoxFrom.r2 = collaborativeEditing.getLockOtherRow2( nSheetId, Data.from.r2); coBBoxFrom.r2 = collaborativeEditing.getLockOtherRow2( nSheetId, from.r2);
coBBoxFrom.c2 = collaborativeEditing.getLockOtherColumn2( nSheetId, Data.from.c2); coBBoxFrom.c2 = collaborativeEditing.getLockOtherColumn2( nSheetId, from.c2);
ws._moveRange(coBBoxFrom, coBBoxTo); ws._moveRange(coBBoxFrom, coBBoxTo);
} }
else{ else{
ws._moveRange(Data.from, Data.to); ws._moveRange(from, to);
}
if(bUndo)
{
if(g_oUndoRedoAutoFiltersMoveData)
{
var worksheetView = this.wb.oApi.wb.getWorksheetById(nSheetId);
worksheetView.autoFilters._moveAutoFilters(worksheetView ,null, null, g_oUndoRedoAutoFiltersMoveData);
g_oUndoRedoAutoFiltersMoveData = null;
} }
} }
} }
...@@ -3309,7 +3234,7 @@ UndoRedoWoorksheet.prototype = { ...@@ -3309,7 +3234,7 @@ UndoRedoWoorksheet.prototype = {
if(bUndo) if(bUndo)
Ref.removeHyperlink(Data); Ref.removeHyperlink(Data);
else else
Ref.setHyperlink(Data); Ref.setHyperlink(Data, true);
} }
else if(historyitem_Worksheet_Rename == Type) else if(historyitem_Worksheet_Rename == Type)
{ {
......
...@@ -19,6 +19,18 @@ var c_oRangeType = ...@@ -19,6 +19,18 @@ var c_oRangeType =
Row:2, Row:2,
All:3 All:3
}; };
function getRangeType(oBBox){
if(null == oBBox)
oBBox = this.bbox;
if(oBBox.c1 == 0 && gc_nMaxCol0 == oBBox.c2 && oBBox.r1 == 0 && gc_nMaxRow0 == oBBox.r2)
return c_oRangeType.All;
if(oBBox.c1 == 0 && gc_nMaxCol0 == oBBox.c2)
return c_oRangeType.Row;
else if(oBBox.r1 == 0 && gc_nMaxRow0 == oBBox.r2)
return c_oRangeType.Col;
else
return c_oRangeType.Range;
}
function consolelog(text){ function consolelog(text){
if( window.g_debug_mode && console && console.log ) if( window.g_debug_mode && console && console.log )
...@@ -2153,6 +2165,39 @@ function Woorksheet(wb, _index, bAddUserId, sId){ ...@@ -2153,6 +2165,39 @@ function Woorksheet(wb, _index, bAddUserId, sId){
this.objForRebuldFormula = {}; this.objForRebuldFormula = {};
this.aComments = new Array(); this.aComments = new Array();
this.aCommentsCoords = new Array(); this.aCommentsCoords = new Array();
var oThis = this;
this.mergeManager = new RangeDataManager(false, function(data, from, to){
if(null != from)
{
from = from.clone();
if(null == to)
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_Unmerge, oThis.getId(), from, new UndoRedoData_BBox(from));
else
{
to = to.clone();
//todo
//нужно добавлять в историю только когда обрезается с краев, потому что на undo будет произведена вставка и ячеек, а диапазон не расширится
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_ChangeMerge, oThis.getId(), from, new UndoRedoData_FromTo(new UndoRedoData_BBox(from), new UndoRedoData_BBox(to)));
}
}
});
this.hyperlinkManager = new RangeDataManager(true, function(data, from, to){
if(null != from)
{
from = from.clone();
if(null == to)
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_RemoveHyperlink, oThis.getId(), from, data);
else
{
data.Ref = oThis.getRange3(to.r1, to.c1, to.r2, to.c2);
to = to.clone();
//нужно добавлять в историю только когда обрезается с краев, потому что на undo будет произведена вставка и ячеек, а диапазон не расширится
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_ChangeHyperlink, oThis.getId(), from, data);
}
oThis.addActionHyperlink(true);
}
});
this.hyperlinkManager.setDependenceManager(this.mergeManager);
this.sheetViews = []; this.sheetViews = [];
this.aConditionalFormatting = []; this.aConditionalFormatting = [];
...@@ -3384,24 +3429,59 @@ Woorksheet.prototype._moveCellVer=function(nRow, nCol, dif){ ...@@ -3384,24 +3429,59 @@ Woorksheet.prototype._moveCellVer=function(nRow, nCol, dif){
} }
}; };
Woorksheet.prototype._prepareMoveRange=function(oBBoxFrom, oBBoxTo){ Woorksheet.prototype._prepareMoveRange=function(oBBoxFrom, oBBoxTo){
var range = this.getRange(new CellAddress(oBBoxTo.r1, oBBoxTo.c1, 0), new CellAddress(oBBoxTo.r2, oBBoxTo.c2, 0)), var res = 0;
merged = range.hasMergedAll(), if(oBBoxFrom.isEqual(oBBoxTo))
res = 0; return res;
if(merged){ var intersection = oBBoxFrom.intersectionSimple(oBBoxTo);
for( var id in merged ){ var aRangesToCheck = [];
var m = merged[id].getBBox0(); if(null != intersection)
if( !(m.r1 >= oBBoxTo.r1 && m.r2 <= oBBoxTo.r2 && m.c1 >= oBBoxTo.c1 && m.c2 <= oBBoxTo.c2) ){ {
return -2; var oThis = this;
var fAddToRangesToCheck = function(aRangesToCheck, r1, c1, r2, c2)
{
if(r1 <= r2 && c1 <= c2)
aRangesToCheck.push(oThis.getRange3(r1, c1, r2, c2));
} }
if(intersection.r1 == oBBoxTo.r1 && intersection.c1 == oBBoxTo.c1)
{
fAddToRangesToCheck(aRangesToCheck, oBBoxTo.r1, intersection.c2 + 1, intersection.r2, oBBoxTo.c2);
fAddToRangesToCheck(aRangesToCheck, intersection.r2 + 1, oBBoxTo.c1, oBBoxTo.r2, oBBoxTo.c2);
} }
else if(intersection.r2 == oBBoxTo.r2 && intersection.c1 == oBBoxTo.c1)
{
fAddToRangesToCheck(aRangesToCheck, oBBoxTo.r1, oBBoxTo.c1, intersection.r1 - 1, oBBoxTo.c2);
fAddToRangesToCheck(aRangesToCheck, intersection.r1, intersection.c2 + 1, oBBoxTo.r2, oBBoxTo.c2);
} }
if( oBBoxFrom.intersection(oBBoxTo) ) else if(intersection.r1 == oBBoxTo.r1 && intersection.c2 == oBBoxTo.c2)
return res; {
fAddToRangesToCheck(aRangesToCheck, oBBoxTo.r1, oBBoxTo.c1, intersection.r2, intersection.c1 - 1);
fAddToRangesToCheck(aRangesToCheck, intersection.r2 + 1, oBBoxTo.c1, oBBoxTo.r2, oBBoxTo.c2);
}
else if(intersection.r2 == oBBoxTo.r2 && intersection.c2 == oBBoxTo.c2)
{
fAddToRangesToCheck(aRangesToCheck, oBBoxTo.r1, oBBoxTo.c1, intersection.r1 - 1, oBBoxTo.c2);
fAddToRangesToCheck(aRangesToCheck, intersection.r1, oBBoxTo.c1, oBBoxTo.r2, intersection.c1 - 1);
}
}
else
aRangesToCheck.push(this.getRange3(oBBoxTo.r1, oBBoxTo.c1, oBBoxTo.r2, oBBoxTo.c2));
for(var i = 0, length = aRangesToCheck.length; i < length; i++)
{
var range = aRangesToCheck[i];
var aMerged = this.mergeManager.get(range.getBBox0());
if(aMerged.outer.length > 0)
return -2;
range._foreachNoEmpty( range._foreachNoEmpty(
function(cell){ function(cell){
if(cell.getValue()!=="") if(!cell.isEmptyTextString())
return res = -1; {
}) res = -1;
return res;
}
});
if(0 != res)
return res;
}
return res; return res;
} }
Woorksheet.prototype._moveRecalcGraph=function(oBBoxFrom, offset){ Woorksheet.prototype._moveRecalcGraph=function(oBBoxFrom, offset){
...@@ -3433,122 +3513,127 @@ Woorksheet.prototype._moveRecalcGraph=function(oBBoxFrom, offset){ ...@@ -3433,122 +3513,127 @@ Woorksheet.prototype._moveRecalcGraph=function(oBBoxFrom, offset){
return rec; return rec;
} }
Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo){ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo){
if(oBBoxFrom.isEqual(oBBoxTo))
return;
var oThis = this;
History.Create_NewPoint(); History.Create_NewPoint();
History.SetSelection(new Asc.Range(oBBoxFrom.c1, oBBoxFrom.r1, oBBoxFrom.c2, oBBoxFrom.r2)); History.SetSelection(new Asc.Range(oBBoxFrom.c1, oBBoxFrom.r1, oBBoxFrom.c2, oBBoxFrom.r2));
History.SetSelectionRedo(new Asc.Range(oBBoxTo.c1, oBBoxTo.r1, oBBoxTo.c2, oBBoxTo.r2)); History.SetSelectionRedo(new Asc.Range(oBBoxTo.c1, oBBoxTo.r1, oBBoxTo.c2, oBBoxTo.r2));
// History.StartTransaction(); History.StartTransaction();
History.TurnOff();
var arrUndo={from:[],to:[]},
offset = { offsetRow : oBBoxTo.r1 - oBBoxFrom.r1, offsetCol : oBBoxTo.c1 - oBBoxFrom.c1 }, rec,
arrFrom = [], arrTo = [];
rec = this._moveRecalcGraph(oBBoxFrom, offset);
for(var nRow = oBBoxFrom.r2; nRow >= oBBoxFrom.r1; nRow-- ){
arrFrom[nRow] = [];
arrTo[nRow+offset.offsetRow] = [];
for(var nCol = oBBoxFrom.c2; nCol >= oBBoxFrom.c1; nCol-- ){
var cellFrom = this._getCell(nRow, nCol);
arrTo[nRow+offset.offsetRow][nCol+offset.offsetCol] = this._getCell(nRow+offset.offsetRow,nCol+offset.offsetCol);
arrFrom[nRow][nCol] = cellFrom.clone();
var cellFromClone = cellFrom.clone();
var cellFromName = cellFrom.getName();
arrUndo.from.push(cellFromClone);
if( cellFrom.sFormula ){ var offset = { offsetRow : oBBoxTo.r1 - oBBoxFrom.r1, offsetCol : oBBoxTo.c1 - oBBoxFrom.c1 };
this.workbook.dependencyFormulas.deleteNode(getVertexId(this.Id,cellFromName)); //запоминаем то что нужно переместить
this.workbook.cwf[this.Id].cells[cellFromName] = null; var aTempObj = {cells: {}, merged: null, hyperlinks: null};
delete this.workbook.cwf[this.Id].cells[cellFromName]; for(var i = oBBoxFrom.r1; i <= oBBoxFrom.r2; i++)
{
var row = this._getRowNoEmpty(i);
if(null != row)
{
var oTempRow = {};
aTempObj.cells[i + offset.offsetRow] = oTempRow;
for(var j = oBBoxFrom.c1; j <= oBBoxFrom.c2; j++)
{
var cell = row.c[j];
if(null != cell)
oTempRow[j + offset.offsetCol] = cell;
} }
var cellTo = this._getCell(nRow+offset.offsetRow,nCol+offset.offsetCol);
arrTo[nRow+offset.offsetRow][nCol+offset.offsetCol] = cellTo.clone();
var cellToName = cellTo.getName();
var sn = this.workbook.dependencyFormulas.getSlaveNodes(this.Id,cellToName);
if( sn ){
for( var _id in sn){
rec[_id] = [ sn[_id].sheetId, sn[_id].cellId ];
rec.length++;
} }
} }
var aMerged = this.mergeManager.get(oBBoxFrom);
if( cellTo.sFormula ){ if(aMerged.inner.length > 0)
this.workbook.dependencyFormulas.deleteNode(getVertexId(this.Id,cellToName)); {
this.workbook.cwf[this.Id].cells[cellToName] = null; aTempObj.merged = aMerged.inner;
delete this.workbook.cwf[this.Id].cells[cellToName]; for(var i = 0, length = aTempObj.merged.length; i < length; i++)
{
var elem = aTempObj.merged[i];
this.mergeManager.remove(elem.bbox, elem, false);
} }
arrUndo.to.push(cellTo.clone());
var oCurRow = this._getRow(nRow);
delete oCurRow.c[nCol];
if( oCurRow.isEmpty() )
delete this.aGCells[nRow];
} }
var aHyperlinks = this.hyperlinkManager.get(oBBoxFrom);
if(aHyperlinks.inner.length > 0)
{
aTempObj.hyperlinks = aHyperlinks.inner;
for(var i = 0, length = aTempObj.hyperlinks.length; i < length; i++)
{
var elem = aTempObj.hyperlinks[i];
this.hyperlinkManager.remove(elem.bbox, elem, false);
} }
for(var nRow = oBBoxFrom.r2; nRow >= oBBoxFrom.r1; nRow-- ){
for(var nCol = oBBoxFrom.c2; nCol >= oBBoxFrom.c1; nCol-- ){
var _cell = arrFrom[nRow][nCol], savedHyperlinks = [];
var idC = getVertexId(this.Id,_cell.getName());
if( idC in rec ){
rec[idC] = null;
delete rec[idC];
} }
//удаляем to через историю, для undo
_cell.moveVer(offset.offsetRow); var oRangeTo = this.getRange3(oBBoxTo.r1, oBBoxTo.c1, oBBoxTo.r2, oBBoxTo.c2);
_cell.moveHor(offset.offsetCol); oRangeTo.cleanAll();
//перемещаем без истории
if( _cell.merged ) History.TurnOff();
_cell.merged.setOffset(offset); //удаляем from без истории, потому что эти данные не терются а перемещаются
var oRangeFrom = this.getRange3(oBBoxFrom.r1, oBBoxFrom.c1, oBBoxFrom.r2, oBBoxFrom.c2);
if( _cell.sFormula ){ oRangeFrom._setPropertyNoEmpty(null, null, function(cell, nRow0, nCol0, nRowStart, nColStart){
this.workbook.cwf[this.Id].cells[_cell.getName()] = _cell.getName(); var row = oThis._getRowNoEmpty(nRow0);
rec[ idC ] = [ this.Id, _cell.getName() ]; if(null != row)
rec.length++; delete row.c[nCol0]
});
//lockDraw(this.workbook);
for(var i in aTempObj.cells)
{
var oTempRow = aTempObj.cells[i];
var row = this._getRow(i - 0);
for(var j in oTempRow)
{
var oTempCell = oTempRow[j];
if(null != oTempCell)
{
oTempCell.moveHor(offset.offsetCol);
oTempCell.moveVer(offset.offsetRow);
row.c[j] = oTempCell;
// var sFormula = oTempCell.getFormula();
// if("" != sFormula)
// oTempCell.setValue("=" + sFormula);
} }
if( _cell.hyperlinks.length > 0 ){
for( var i = 0; i < _cell.hyperlinks.length; i++ ){
if( !( oBBoxFrom.c1 <= _cell.hyperlinks[i].Ref.bbox.c1 && oBBoxFrom.r1 <= _cell.hyperlinks[i].Ref.bbox.r1 && oBBoxFrom.c2 >= _cell.hyperlinks[i].Ref.bbox.c2 && oBBoxFrom.r2 >= _cell.hyperlinks[i].Ref.bbox.r2 ) ){
this.getCell3(nRow,nCol).setHyperlink(_cell.hyperlinks.splice(i,1)[0],true)
i-=1;
} }
else{
_cell.hyperlinks[i].Ref = this.getRange2(_cell.getName());
} }
var rec = this._moveRecalcGraph(oBBoxFrom, offset);
this.workbook.buildDependency();
this.workbook.needRecalc = rec;
recalc(this.workbook);
// this.renameDependencyNodes( offset, oBBoxFrom );
// buildRecalc(this.workbook);
// unLockDraw(this.workbook);
if(null != aTempObj.merged)
{
for(var i = 0, length = aTempObj.merged.length; i < length; i++)
{
var elem = aTempObj.merged[i];
elem.bbox.setOffset(offset);
this.mergeManager.add(elem.bbox, elem.data);
} }
} }
if(null != aTempObj.hyperlinks)
var oTargetRow = this._getRow(nRow + offset.offsetRow); {
oTargetRow.c[nCol+offset.offsetCol] = _cell; for(var i = 0, length = aTempObj.hyperlinks.length; i < length; i++)
{
var elem = aTempObj.hyperlinks[i];
elem.bbox.setOffset(offset);
elem.data.Ref.setOffset(offset);
this.hyperlinkManager.add(elem.bbox, elem.data);
} }
this.addActionHyperlink(true);
} }
//расширяем границы
this.workbook.buildDependency(); if(oBBoxFrom.r2 > this.nRowsCount)
this.workbook.needRecalc = rec; this.nRowsCount = oBBoxFrom.r2 + 1;
if(oBBoxFrom.c2 > this.nColsCount)
recalc(this.workbook); this.nColsCount = oBBoxFrom.c2 + 1;
// History.EndTransaction(); if(oBBoxTo.r2 > this.nRowsCount)
this.nRowsCount = oBBoxTo.r2 + 1;
if(oBBoxTo.c2 > this.nColsCount)
this.nColsCount = oBBoxTo.c2 + 1;
History.TurnOn(); History.TurnOn();
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_MoveRange, History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_MoveRange,
this.getId(), new Asc.Range(0, 0, gc_nMaxCol0, gc_nMaxRow0), this.getId(), new Asc.Range(0, 0, gc_nMaxCol0, gc_nMaxRow0),
new UndoRedoData_FromToCell(oBBoxFrom, oBBoxTo, arrUndo)); new UndoRedoData_FromTo(oBBoxFrom, oBBoxTo));
History.EndTransaction();
return true; return true;
} }
Woorksheet.prototype._shiftCellsLeft=function(oBBox){ Woorksheet.prototype._shiftCellsLeft=function(oBBox){
lockDraw(this.workbook); lockDraw(this.workbook);
...@@ -3917,6 +4002,29 @@ Woorksheet.prototype.getAllCol = function(){ ...@@ -3917,6 +4002,29 @@ Woorksheet.prototype.getAllCol = function(){
this.oAllCol = new Col(this, g_nAllColIndex); this.oAllCol = new Col(this, g_nAllColIndex);
return this.oAllCol; return this.oAllCol;
} }
Woorksheet.prototype.getHyperlinkByCell = function(row, col){
return this.hyperlinkManager.getByCell(row, col);
}
Woorksheet.prototype.getMergedByCell = function(row, col){
return this.mergeManager.getByCell(row, col);
}
Woorksheet.prototype.expandRangeByMerged = function(range){
if(null != range)
{
var aMerged = this.mergeManager.get(range);
if(aMerged.outer.length > 0)
{
range = range.clone();
while(aMerged.outer.length > 0)
{
for(var i = 0, length = aMerged.outer.length; i < length; i++)
range.union2(aMerged.outer[i].bbox);
aMerged = this.mergeManager.get(range);
}
}
}
return range;
}
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
/** /**
* @constructor * @constructor
...@@ -3935,8 +4043,6 @@ function Cell(worksheet){ ...@@ -3935,8 +4043,6 @@ function Cell(worksheet){
this.oFormulaExt = null; this.oFormulaExt = null;
this.sFormula = null; this.sFormula = null;
this.formulaParsed = null; this.formulaParsed = null;
this.merged = null;
this.hyperlinks = new Array();
} }
Cell.prototype.getStyle=function(){ Cell.prototype.getStyle=function(){
if(this.bNeedCompileXfs) if(this.bNeedCompileXfs)
...@@ -3976,11 +4082,6 @@ Cell.prototype.clone=function(){ ...@@ -3976,11 +4082,6 @@ Cell.prototype.clone=function(){
oNewCell.oValue = this.oValue.clone(oNewCell); oNewCell.oValue = this.oValue.clone(oNewCell);
if(null != this.sFormula) if(null != this.sFormula)
oNewCell.sFormula = this.sFormula; oNewCell.sFormula = this.sFormula;
//todo подумать
if(null != this.merged)
oNewCell.merged = this.merged.clone();
for(var i = 0, length = this.hyperlinks.length; i < length; ++i)
oNewCell.hyperlinks.push(this.hyperlinks[i].clone());
return oNewCell; return oNewCell;
}; };
Cell.prototype.create=function(xfs, oId){ Cell.prototype.create=function(xfs, oId){
...@@ -4002,10 +4103,6 @@ Cell.prototype.isEmpty=function(){ ...@@ -4002,10 +4103,6 @@ Cell.prototype.isEmpty=function(){
return false; return false;
if(null != this.xfs) if(null != this.xfs)
return false; return false;
if(null != this.merged)
return false;
if(this.hyperlinks.length > 0)
return false;
return true; return true;
}; };
Cell.prototype.isFormula=function(){ Cell.prototype.isFormula=function(){
...@@ -4126,11 +4223,6 @@ Cell.prototype.setValue=function(val,callback){ ...@@ -4126,11 +4223,6 @@ Cell.prototype.setValue=function(val,callback){
DataNew = this.getValueData(); DataNew = this.getValueData();
if(History.Is_On() && false == DataOld.isEqual(DataNew)) if(History.Is_On() && false == DataOld.isEqual(DataNew))
History.Add(g_oUndoRedoCell, historyitem_Cell_ChangeValue, this.ws.getId(), new Asc.Range(0, this.oId.getRow0(), gc_nMaxCol0, this.oId.getRow0()), new UndoRedoData_CellSimpleData(this.oId.getRow0(), this.oId.getCol0(), DataOld, DataNew)); History.Add(g_oUndoRedoCell, historyitem_Cell_ChangeValue, this.ws.getId(), new Asc.Range(0, this.oId.getRow0(), gc_nMaxCol0, this.oId.getRow0()), new UndoRedoData_CellSimpleData(this.oId.getRow0(), this.oId.getCol0(), DataOld, DataNew));
if(this.isEmptyTextString())
{
var cell = this.ws.getCell(this.oId);
cell.removeHyperlink();
}
return ret; return ret;
}; };
Cell.prototype.setValue2=function(array){ Cell.prototype.setValue2=function(array){
...@@ -4173,11 +4265,6 @@ Cell.prototype.setValue2=function(array){ ...@@ -4173,11 +4265,6 @@ Cell.prototype.setValue2=function(array){
DataNew = this.getValueData(); DataNew = this.getValueData();
if(History.Is_On() && false == DataOld.isEqual(DataNew)) if(History.Is_On() && false == DataOld.isEqual(DataNew))
History.Add(g_oUndoRedoCell, historyitem_Cell_ChangeValue, this.ws.getId(), new Asc.Range(0, this.oId.getRow0(), gc_nMaxCol0, this.oId.getRow0()), new UndoRedoData_CellSimpleData(this.oId.getRow0(), this.oId.getCol0(), DataOld, DataNew)); History.Add(g_oUndoRedoCell, historyitem_Cell_ChangeValue, this.ws.getId(), new Asc.Range(0, this.oId.getRow0(), gc_nMaxCol0, this.oId.getRow0()), new UndoRedoData_CellSimpleData(this.oId.getRow0(), this.oId.getCol0(), DataOld, DataNew));
if(this.isEmptyTextString())
{
var cell = this.ws.getCell(this.oId);
cell.removeHyperlink();
}
}; };
Cell.prototype.setType=function(type){ Cell.prototype.setType=function(type){
return this.oValue.type = type; return this.oValue.type = type;
...@@ -4529,12 +4616,6 @@ Cell.prototype.setFormulaCA = function(ca){ ...@@ -4529,12 +4616,6 @@ Cell.prototype.setFormulaCA = function(ca){
if(ca) this.sFormulaCA = true; if(ca) this.sFormulaCA = true;
else if( this.sFormulaCA ) delete this.sFormulaCA; else if( this.sFormulaCA ) delete this.sFormulaCA;
} }
Cell.prototype.getHyperlinks = function(){
return this.hyperlinks;
}
Cell.prototype.getMerged = function(){
return this.merged;
}
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
/** /**
...@@ -4814,14 +4895,7 @@ Range.prototype._foreachIndex=function(action){ ...@@ -4814,14 +4895,7 @@ Range.prototype._foreachIndex=function(action){
Range.prototype._getRangeType=function(oBBox){ Range.prototype._getRangeType=function(oBBox){
if(null == oBBox) if(null == oBBox)
oBBox = this.bbox; oBBox = this.bbox;
if(oBBox.c1 == 0 && gc_nMaxCol0 == oBBox.c2 && oBBox.r1 == 0 && gc_nMaxRow0 == oBBox.r2) return getRangeType(oBBox);
return c_oRangeType.All;
if(oBBox.c1 == 0 && gc_nMaxCol0 == oBBox.c2)
return c_oRangeType.Row;
else if(oBBox.r1 == 0 && gc_nMaxRow0 == oBBox.r2)
return c_oRangeType.Col;
else
return c_oRangeType.Range;
} }
Range.prototype._setProperty=function(actionRow, actionCol, actionCell){ Range.prototype._setProperty=function(actionRow, actionCol, actionCell){
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
...@@ -4953,6 +5027,11 @@ Range.prototype.setValue2=function(array){ ...@@ -4953,6 +5027,11 @@ Range.prototype.setValue2=function(array){
// if(cell.isEmpty()) // if(cell.isEmpty())
// cell.Remove(); // cell.Remove();
}); });
var sText = "";
for(var i = 0, length = array.length; i < length; i++)
sText += array[i].text;
if("" == sText)
this.removeHyperlink();
History.EndTransaction(); History.EndTransaction();
}; };
Range.prototype.setCellStyle=function(val){ Range.prototype.setCellStyle=function(val){
...@@ -5035,6 +5114,29 @@ Range.prototype.shiftNumFormat=function(nShift, aDigitsCount){ ...@@ -5035,6 +5114,29 @@ Range.prototype.shiftNumFormat=function(nShift, aDigitsCount){
}); });
return bRes; return bRes;
} }
Range.prototype.setFont=function(val){
History.Create_NewPoint();
History.SetSelection(this.bbox.clone());
this.createCellOnRowColCross();
var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType();
if(c_oRangeType.All == nRangeType)
{
this.worksheet.getAllCol().setFont(val);
fSetProperty = this._setPropertyNoEmpty;
}
fSetProperty.call(this, function(row){
if(c_oRangeType.All == nRangeType && null == row.xfs)
return;
row.setFont(val);
},
function(col){
col.setFont(val);
},
function(cell){
cell.setFont(val);
});
};
Range.prototype.setFontname=function(val){ Range.prototype.setFontname=function(val){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox; var oBBox = this.bbox;
...@@ -6659,94 +6761,13 @@ Range.prototype.getVerticalText=function(){ ...@@ -6659,94 +6761,13 @@ Range.prototype.getVerticalText=function(){
} }
Range.prototype.hasMerged=function(){ Range.prototype.hasMerged=function(){
var oThis = this; var oThis = this;
var oRes = null; var aMerged = this.worksheet.mergeManager.get(this.bbox);
if(null != this.worksheet.oAllCol) if(aMerged.all.length > 0)
{ return aMerged.all[0].bbox;
var m = this.worksheet.oAllCol.getMerged();
if (m)
return m.getBBox0();
}
if(this.isOneCell())
{
var cell = this.worksheet._getCellNoEmpty(this.bbox.r1, this.bbox.c1);
if(null != cell)
oRes = cell.getMerged();
if(null == oRes)
{
var row = this.worksheet._getRowNoEmpty(this.bbox.r1);
if(null != row)
oRes = row.getMerged();
}
if(null == oRes)
{
var col = this.worksheet._getColNoEmptyWithAll(this.bbox.c1);
if(null != col)
oRes = col.getMerged();
}
if(null != oRes)
return oRes.getBBox0();
}
else
{
oRes = this._foreachNoEmpty(function(cell){return cell.getMerged();});
if(null == oRes)
oRes = this._foreachRowNoEmpty(function(row){return row.getMerged();}, null);
if(null == oRes)
oRes = this._foreachColNoEmpty(function(col){return col.getMerged();}, null);
if(null != oRes)
return oRes.getBBox0();
}
return null;
};
Range.prototype.hasMergedAll=function(){
var oThis = this;
var oRes = [];
if(null != this.worksheet.oAllCol)
{
var m = this.worksheet.oAllCol.getMerged();
if (m)
oRes.push(m);
}
this._foreachNoEmpty(function(cell){
var m = cell.getMerged();
if (m)
oRes.push(m);
});
this._foreachRowNoEmpty(function(row){
var m = row.getMerged();
if (m)
oRes.push(m);
}, null);
this._foreachColNoEmpty(function(col){
var m = col.getMerged();
if (m)
oRes.push(m);
}, null);
if(0 != oRes.length)
return oRes;
return null; return null;
}; };
Range.prototype.mergeOpen=function(){ Range.prototype.mergeOpen=function(){
var val = this.clone(); this.worksheet.mergeManager.add(this.bbox, 1);
var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType();
if(c_oRangeType.All == nRangeType)
{
this.worksheet.getAllCol().merged = val;
fSetProperty = this._setPropertyNoEmpty;
val = null;
}
fSetProperty.call(this, function(row){
row.merged = val;
},function(col){
col.merged = val;
},
function(cell, nRow, nCol, nRowStart, nColStart){
cell.merged = val;
});
} }
Range.prototype.merge=function(type){ Range.prototype.merge=function(type){
if(null == type) if(null == type)
...@@ -6757,19 +6778,17 @@ Range.prototype.merge=function(type){ ...@@ -6757,19 +6778,17 @@ Range.prototype.merge=function(type){
History.Create_NewPoint(); History.Create_NewPoint();
History.SetSelection(new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2)); History.SetSelection(new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2));
History.StartTransaction(); History.StartTransaction();
var bHasMerged = false;
if(this.hasMerged()) if(this.hasMerged())
{ {
bHasMerged = true;
this.unmerge(); this.unmerge();
} if(type == c_oAscMergeOptions.MergeCenter)
if(type == c_oAscMergeOptions.MergeCenter && bHasMerged)
{ {
//сбрасываем AlignHorizontal //сбрасываем AlignHorizontal
this.setAlignHorizontal("none"); this.setAlignHorizontal("none");
History.EndTransaction(); History.EndTransaction();
return; return;
} }
}
//пробегаемся по границе диапазона, чтобы посмотреть какие границы нужно оставлять //пробегаемся по границе диапазона, чтобы посмотреть какие границы нужно оставлять
var oLeftBorder = null; var oLeftBorder = null;
var oTopBorder = null; var oTopBorder = null;
...@@ -6865,7 +6884,6 @@ Range.prototype.merge=function(type){ ...@@ -6865,7 +6884,6 @@ Range.prototype.merge=function(type){
var oFirstCellHyperlink = null; var oFirstCellHyperlink = null;
this._setPropertyNoEmpty(null,null, this._setPropertyNoEmpty(null,null,
function(cell, nRow0, nCol0, nRowStart, nColStart){ function(cell, nRow0, nCol0, nRowStart, nColStart){
var aHyperlinks = cell.getHyperlinks();
if(bFirst && false == cell.isEmptyText()) if(bFirst && false == cell.isEmptyText())
{ {
bFirst = false; bFirst = false;
...@@ -6873,14 +6891,11 @@ Range.prototype.merge=function(type){ ...@@ -6873,14 +6891,11 @@ Range.prototype.merge=function(type){
oFirstCellValue = cell.getValueData(); oFirstCellValue = cell.getValueData();
oFirstCellRow = cell.oId.getRow0(); oFirstCellRow = cell.oId.getRow0();
oFirstCellCol = cell.oId.getCol0(); oFirstCellCol = cell.oId.getCol0();
for(var i = 0, length = aHyperlinks.length; i < length; ++i) var oCurHyp = oThis.worksheet.hyperlinkManager.getByCell(oFirstCellRow, oFirstCellCol);
{ //todo надо весь массив просмотреть
var oCurHyp = aHyperlinks[i]; if(null != oCurHyp && oCurHyp.data.Ref.isOneCell())
if(oCurHyp.Ref.isOneCell())
{ {
oFirstCellHyperlink = oCurHyp; oFirstCellHyperlink = oCurHyp.data;
break;
}
} }
} }
if(nRow0 == nRowStart || nCol0 == nColStart) if(nRow0 == nRowStart || nCol0 == nColStart)
...@@ -6914,18 +6929,14 @@ Range.prototype.merge=function(type){ ...@@ -6914,18 +6929,14 @@ Range.prototype.merge=function(type){
oTargetStyle = new CellXfs(); oTargetStyle = new CellXfs();
var bEmptyStyle = true; var bEmptyStyle = true;
var bEmptyBorder = true; var bEmptyBorder = true;
var oNewMerged = this.clone();
var fSetProperty = this._setProperty; var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
if(c_oRangeType.All == nRangeType) if(c_oRangeType.All == nRangeType)
{ {
this.worksheet.getAllCol().merged = oNewMerged;
fSetProperty = this._setPropertyNoEmpty; fSetProperty = this._setPropertyNoEmpty;
oNewMerged = null;
oTargetStyle = null oTargetStyle = null
} }
fSetProperty.call(this, function(row){ fSetProperty.call(this, function(row){
row.merged = oNewMerged;
if(null == oTargetStyle) if(null == oTargetStyle)
row.setStyle(null); row.setStyle(null);
else else
...@@ -6944,7 +6955,6 @@ Range.prototype.merge=function(type){ ...@@ -6944,7 +6955,6 @@ Range.prototype.merge=function(type){
row.setStyle(oNewStyle); row.setStyle(oNewStyle);
} }
},function(col){ },function(col){
col.merged = oNewMerged;
if(null == oTargetStyle) if(null == oTargetStyle)
col.setStyle(null); col.setStyle(null);
else else
...@@ -6965,7 +6975,6 @@ Range.prototype.merge=function(type){ ...@@ -6965,7 +6975,6 @@ Range.prototype.merge=function(type){
}, },
function(cell, nRow, nCol, nRowStart, nColStart){ function(cell, nRow, nCol, nRowStart, nColStart){
//важно установить именно здесь, чтобы ячейка не удалилась после применения стилей. //важно установить именно здесь, чтобы ячейка не удалилась после применения стилей.
cell.merged = oNewMerged;
if(null == oTargetStyle) if(null == oTargetStyle)
cell.setStyle(null); cell.setStyle(null);
else else
...@@ -7066,145 +7075,58 @@ Range.prototype.merge=function(type){ ...@@ -7066,145 +7075,58 @@ Range.prototype.merge=function(type){
}); });
if(type == c_oAscMergeOptions.MergeCenter) if(type == c_oAscMergeOptions.MergeCenter)
this.setAlignHorizontal("center"); this.setAlignHorizontal("center");
this.worksheet.mergeManager.add(this.bbox, 1);
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_Merge, this.worksheet.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2), new UndoRedoData_BBox(oBBox)); History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_Merge, this.worksheet.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2), new UndoRedoData_BBox(oBBox));
History.EndTransaction(); History.EndTransaction();
}; };
Range.prototype.unmerge=function(bOnlyInRange){ Range.prototype.unmerge=function(bOnlyInRange){
var oBBox = this.bbox;
if(true == bOnlyInRange)
{
History.Create_NewPoint(); History.Create_NewPoint();
History.SetSelection(new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2)); History.SetSelection(this.bbox.clone());
History.StartTransaction(); History.StartTransaction();
var oAllMerge = null; this.worksheet.mergeManager.remove(this.bbox, null, true);
if(null != this.worksheet.oAllCol)
{
oAllMerge = this.worksheet.oAllCol.getMerged();
if (null != oAllMerge)
this.worksheet.oAllCol.merged = null;
}
if(null == oAllMerge)
{
this._setPropertyNoEmpty(function(row){
row.merged = null;
},function(col){
col.merged = null;
},function(cell, nRow, nCol, nRowStart, nColStart){
cell.merged = null;
cell.merged = null;
});
}
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_Unmerge, this.worksheet.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2), new UndoRedoData_BBox(oBBox));
History.EndTransaction(); History.EndTransaction();
}
else
{
var oAllMerge = null;
if(null != this.worksheet.oAllCol)
{
oAllMerge = this.worksheet.oAllCol.getMerged();
if (oAllMerge)
oAllMerge.unmerge(true);
}
if(null == oAllMerge)
{
var oMerged = new Object();
//собираем замерженые ячейки
this._setPropertyNoEmpty(function(row){
if(null != row.merged)
oMerged[row.merged.getName()] = row.merged;
},function(col){
if(null != col.merged)
oMerged[col.merged.getName()] = col.merged;
},function(cell, nRow, nCol, nRowStart, nColStart){
if(null != cell.merged)
oMerged[cell.merged.getName()] = cell.merged;
});
for(var i in oMerged)
{
var merged = oMerged[i]
merged.unmerge(true);
}
}
}
}; };
Range.prototype._getHyperlinks=function(bStopOnFirst, bAvoidHiddenRow){ Range.prototype._getHyperlinks=function(){
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
var result = []; var result = [];
var oAllCol = this.worksheet.oAllCol;
if(bStopOnFirst && null != oAllCol && oAllCol.hyperlinks.length > 0)
{
result.push({hyperlink: oAllCol.hyperlinks[oAllCol.hyperlinks.length - 1], col: this.bbox.c1, row: this.bbox.r1});
return;
}
var oThis = this; var oThis = this;
if(c_oRangeType.Range == nRangeType) if(c_oRangeType.Range == nRangeType)
{ {
var aRows = this.worksheet._getRows(); var oTempRows = {};
var aCols = this.worksheet._getCols(); var fAddToTempRows = function(oTempRows, bbox, data){
var oTempRows = new Object(); if(null != bbox)
var fAddToTemp = function(oTempRows, hyperlink, nRow, nCol){
var oRow = oTempRows[nRow];
if(null == oRow)
{
oRow = new Object();
oTempRows[nRow] = oRow;
}
oRow[nCol] = hyperlink;
};
var oProcessedMerged = new Object();
var oBBox = this.bbox;
for(var nRow = oBBox.r1; nRow <= oBBox.r2; nRow++){
var row = this.worksheet._getRowNoEmpty(nRow);
if(null != row)
{ {
if(true == row.hd && bAvoidHiddenRow) for(var i = bbox.r1; i <= bbox.r2; i++)
continue;
for(var nCol = oBBox.c1; nCol <= oBBox.c2; nCol++){
var cell = oThis.worksheet._getCellNoEmpty(nRow, nCol);
if(null != cell && cell.hyperlinks.length > 0)
{ {
var oCurHyperlink = cell.hyperlinks[cell.hyperlinks.length - 1]; var row = oTempRows[i];
if(bStopOnFirst) if(null == row)
{ {
result.push({hyperlink: oCurHyperlink, col: nCol, row: nRow}); row = {};
break; oTempRows[i] = row;
} }
else for(var j = bbox.c1; j <= bbox.c2; j++)
{
fAddToTemp(oTempRows, oCurHyperlink, nRow, nCol);
//расширяем гиперссылки в замерженых ячейках
if(null != cell.merged)
{
var sId = cell.merged.getName();
if(null == oProcessedMerged[sId])
{ {
var intersect = oThis.intersect(cell.merged); var cell = row[j];
if(null != intersect) if(null == cell)
{ row[j] = data;
intersect._foreach(function(cell, nRow, nCol, nRowStart, nColStart){
fAddToTemp(oTempRows, oCurHyperlink, nRow, nCol);
});
}
oProcessedMerged[sId] = cell.merged;
}
} }
} }
} }
else };
//todo возможно надо сделать оптимизацию для скрытых строк
var aHyperlinks = this.worksheet.hyperlinkManager.get(this.bbox);
for(var i = 0, length = aHyperlinks.all.length; i < length; i++)
{ {
var row = aRows[nRow]; var hyp = aHyperlinks.all[i];
var col = aCols[nCol]; var hypBBox = hyp.bbox.intersectionSimple(this.bbox);
if(null != row && row.hyperlinks.lengh > 0) fAddToTempRows(oTempRows, hypBBox, hyp.data);
fAddToTemp(oTempRows, row.hyperlinks[row.hyperlinks.length - 1], nRow, nCol); //расширяем гиперссылки на merge ячейках
if(null != col && col.hyperlinks.length > 0) var aMerged = this.worksheet.mergeManager.get(hyp.bbox);
fAddToTemp(oTempRows, col.hyperlinks[col.hyperlinks.length - 1], nRow, nCol); for(var j = 0, length2 = aMerged.all.length; j < length2; j++)
else if(null != oAllCol && oAllCol.hyperlinks.length > 0) {
fAddToTemp(oTempRows, oAllCol.hyperlinks[oAllCol.hyperlinks.length - 1], nRow, nCol); var merge = aMerged.all[j];
} var mergeBBox = merge.bbox.intersectionSimple(this.bbox);
} fAddToTempRows(oTempRows, mergeBBox, hyp.data);
if(bStopOnFirst && result.length > 0)
break;
} }
} }
//формируем результат //формируем результат
...@@ -7223,152 +7145,75 @@ Range.prototype._getHyperlinks=function(bStopOnFirst, bAvoidHiddenRow){ ...@@ -7223,152 +7145,75 @@ Range.prototype._getHyperlinks=function(bStopOnFirst, bAvoidHiddenRow){
return result; return result;
} }
Range.prototype.getHyperlink=function(){ Range.prototype.getHyperlink=function(){
var aHyperlinks = this._getHyperlinks(true, false); var aHyperlinks = this._getHyperlinks();
if(null != aHyperlinks && aHyperlinks.length > 0) if(null != aHyperlinks && aHyperlinks.length > 0)
return aHyperlinks[0].hyperlink; return aHyperlinks[0].hyperlink;
return null; return null;
}; };
Range.prototype.getHyperlinks=function(){ Range.prototype.getHyperlinks=function(){
return this._getHyperlinks(false, true); return this._getHyperlinks();
}; };
Range.prototype.setHyperlinkOpen=function(val){
if(null != val && false == val.isValid())
return;
this.worksheet.hyperlinkManager.add(val.Ref.getBBox0(), val);
}
Range.prototype.setHyperlink=function(val, bWithoutStyle){ Range.prototype.setHyperlink=function(val, bWithoutStyle){
if(null != val && false == val.isValid()) if(null != val && false == val.isValid())
return; return;
//проверяем, может эта ссылка уже существует //проверяем, может эта ссылка уже существует
var aHyperlinks = this.getHyperlinks();
var bExist = false; var bExist = false;
for(var i = 0, length = aHyperlinks.length; i < length; ++i) var aHyperlinks = this.worksheet.hyperlinkManager.get(this.bbox);
for(var i = 0, length = aHyperlinks.all.length; i < length; i++)
{ {
var elem = aHyperlinks[i]; var hyp = aHyperlinks.all[i];
if(elem.hyperlink.isEqual(val)) if(hyp.data.isEqual(val))
{ {
bExist = true; bExist = true;
break; break;
} }
} }
if(bExist) if(false == bExist)
return; {
var oThis = this;
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox; History.SetSelection(this.bbox.clone());
History.SetSelection(new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2));
History.StartTransaction(); History.StartTransaction();
var oThis = this; //удаляем ссылки с тем же адресом
for(var i = 0, length = aHyperlinks.all.length; i < length; i++)
{
var hyp = aHyperlinks.all[i];
if(hyp.bbox.isEqual(this.bbox))
this.worksheet.hyperlinkManager.remove(hyp.bbox, hyp, true);
}
//todo перейти на CellStyle
if(true != bWithoutStyle)
{
var oHyperlinkFont = new Font(); var oHyperlinkFont = new Font();
oHyperlinkFont.fn = this.worksheet.workbook.getDefaultFont(); oHyperlinkFont.fn = this.worksheet.workbook.getDefaultFont();
oHyperlinkFont.fs = this.worksheet.workbook.getDefaultSize(); oHyperlinkFont.fs = this.worksheet.workbook.getDefaultSize();
oHyperlinkFont.u = "single"; oHyperlinkFont.u = "single";
oHyperlinkFont.c = g_oColorManager.getThemeColor(g_nColorHyperlink); oHyperlinkFont.c = g_oColorManager.getThemeColor(g_nColorHyperlink);
var bNeedCheckHyperlink = true; this.setFont(oHyperlinkFont);
var fCheckHyperlink = function(aHyperlinks)
{
if(bNeedCheckHyperlink)
{
bNeedCheckHyperlink = false;
for(var i = 0, length = aHyperlinks.length; i < length; ++i)
{
var hyperlink = aHyperlinks[i];
var oHyperlinkBBox = hyperlink.Ref.getBBox0();
//удаляем ссылку, если диапазоны совпадают
if(oBBox.r1 == oHyperlinkBBox.r1 && oBBox.c1 == oHyperlinkBBox.c1 && oBBox.r2 == oHyperlinkBBox.r2 && oBBox.c2 == oHyperlinkBBox.c2)
hyperlink.Ref.removeHyperlink(hyperlink);
}
}
}
var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType();
if(c_oRangeType.All == nRangeType)
{
var oAllCol = this.worksheet.getAllCol();
fCheckHyperlink(oAllCol.hyperlinks);
if(true != bWithoutStyle)
oAllCol.setFont(oHyperlinkFont);
oAllCol.hyperlinks.push(val);
fSetProperty = this._setPropertyNoEmpty;
} }
fSetProperty.call(this, function(row){ this.worksheet.hyperlinkManager.add(val.Ref.getBBox0(), val);
fCheckHyperlink(row.hyperlinks);
if(true != bWithoutStyle)
row.setFont(oHyperlinkFont);
row.hyperlinks.push(val);
},
function(col){
fCheckHyperlink(col.hyperlinks);
if(true != bWithoutStyle)
col.setFont(oHyperlinkFont);
col.hyperlinks.push(val);
},
function(cell){
fCheckHyperlink(cell.hyperlinks);
if(true != bWithoutStyle)
cell.setFont(oHyperlinkFont);
cell.hyperlinks.push(val);
});
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_SetHyperlink, this.worksheet.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2), val.clone());
History.EndTransaction();
this.worksheet.addActionHyperlink(true); this.worksheet.addActionHyperlink(true);
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_SetHyperlink, this.worksheet.getId(), this.bbox.clone(), val.clone());
History.EndTransaction();
}
}; };
Range.prototype.removeHyperlink=function(val){ Range.prototype.removeHyperlink=function(val){
History.Create_NewPoint(); var bbox = this.bbox;
var oBBox = this.bbox; var elem = null;
History.SetSelection(new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2));
History.StartTransaction();
var oThis = this;
if(null != val) if(null != val)
{ {
var fProcessHyperlink = function(aHyperlinks){ bbox = val.Ref.getBBox0();
for(var i = 0, length = aHyperlinks.length;i < length; ++i) elem = new RangeDataManagerElem(bbox, val);
{
//isEqual нужен, чтобы функцию можно було вызывать при Undo/redo
if(val.isEqual(aHyperlinks[i]))
{
aHyperlinks.splice(i, 1);
break;
}
}
}
if(null != this.worksheet.oAllCol)
fProcessHyperlink(this.worksheet.oAllCol.hyperlinks);
//val не нулевой, когда вызывается remove для конктерной ссылки
this._setPropertyNoEmpty(function(row){
fProcessHyperlink(row.hyperlinks);
}, function(col){
fProcessHyperlink(col.hyperlinks);
}, function(cell){
fProcessHyperlink(cell.hyperlinks);
});
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_RemoveHyperlink, this.worksheet.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2), val.clone());
this.worksheet.addActionHyperlink(true);
}
else
{
//собираем гиперссылки, которые надо удалить
var oHyperlinksToDelete = new Object();
var fProcessHyperlink = function(aHyperlinks)
{
for(var i = 0, length = aHyperlinks.length; i < length; ++i)
{
var hyperlink = aHyperlinks[i];
var sName = hyperlink.Ref.getName();
oHyperlinksToDelete[sName] = hyperlink;
}
}
if(null != this.worksheet.oAllCol)
fProcessHyperlink(this.worksheet.oAllCol.hyperlinks);
this._foreachRowNoEmpty(function(row){
return fProcessHyperlink(row.hyperlinks);
}, null);
this._foreachColNoEmpty(function(col){
return fProcessHyperlink(col.hyperlinks);
}, null);
this._foreachNoEmpty(function(cell){
return fProcessHyperlink(cell.hyperlinks);
});
for(var i in oHyperlinksToDelete)
{
var hyperlink = oHyperlinksToDelete[i];
hyperlink.Ref.removeHyperlink(hyperlink);
}
} }
History.Create_NewPoint();
History.SetSelection(bbox.clone());
History.StartTransaction();
this.worksheet.hyperlinkManager.remove(bbox, elem, true);
History.EndTransaction(); History.EndTransaction();
} }
Range.prototype.deleteCellsShiftUp=function(){ Range.prototype.deleteCellsShiftUp=function(){
...@@ -7389,146 +7234,27 @@ Range.prototype._shiftLeftRight=function(bLeft){ ...@@ -7389,146 +7234,27 @@ Range.prototype._shiftLeftRight=function(bLeft){
var nRangeType = this._getRangeType(oBBox); var nRangeType = this._getRangeType(oBBox);
if(c_oRangeType.Range != nRangeType && c_oRangeType.Col != nRangeType) if(c_oRangeType.Range != nRangeType && c_oRangeType.Col != nRangeType)
return false; return false;
if(null != this.worksheet.oAllCol && null != this.worksheet.oAllCol.merged) var mergeManager = this.worksheet.mergeManager;
return false; var oShiftGet = mergeManager.shiftGet(this.bbox, true);
var aMerged = oShiftGet.elems;
//todo вставить предупреждение, что будет unmerge
History.Create_NewPoint(); History.Create_NewPoint();
History.SetSelection(new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2)); History.SetSelection(new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2));
History.StartTransaction(); History.StartTransaction();
var bChangeHyperlink = false; if(null != aMerged.outer && aMerged.outer.length > 0)
var oExpandedHyperlinkRange = new Object();//hyperlink области которые надо раздвинуть или они выходят за границы и их надо оставить
var fAddHyperlinkToExpanded = function(oExpanded, aHyperlinks)
{
for(var i = 0, length = aHyperlinks.length; i < length ;++i)
{
var hyperlink = aHyperlinks[i];
var oHyperlinkBBox = hyperlink.Ref.getBBox0();
if(false == (oHyperlinkBBox.r1 >= oBBox.r1 && oHyperlinkBBox.c1 >= oBBox.c1 && oHyperlinkBBox.r2 <= oBBox.r2))
{
bChangeHyperlink = true;
var sId = hyperlink.Ref.getName();
oExpanded[sId] = hyperlink;
hyperlink.Ref.removeHyperlink(hyperlink);
}
}
}
var oExpandedRange = new Object();//merge области которые надо раздвинуть
//todo проверка не выходят ли данные за границу
if(c_oRangeType.Range == nRangeType){
//делаем unmerge, если нельзя сдвинуть из-за этого
//временно убираем hyperlink, которые выходят за диапазон, возвращаем после сдвига ячеек
var fProcessEdge = function(range){
range._setPropertyNoEmpty(null, null, function(cell, nRow0, nCol0, nRowStart, nColStart){
if(nCol0 > oBBox.c2)
{
if(null != cell.merged)
{
var oMergedBBox = cell.merged.getBBox0();
if(oMergedBBox.r1 < oBBox.r1 || oMergedBBox.r2 > oBBox.r2)
cell.merged.unmerge(true);
}
fAddHyperlinkToExpanded(oExpandedHyperlinkRange, cell.hyperlinks);
}
});
};
fProcessEdge(this.worksheet.getRange(new CellAddress(oBBox.r1, 0, 0), new CellAddress(oBBox.r1, gc_nMaxCol0, 0)));
if(oBBox.r1 != oBBox.r2)
{
fProcessEdge(this.worksheet.getRange(new CellAddress(oBBox.r2, 0, 0), new CellAddress(oBBox.r2, gc_nMaxCol0, 0)));
//проходим эту область специально для hyperlink
fProcessEdge(this.worksheet.getRange(new CellAddress(oBBox.r1, oBBox.c1, 0), new CellAddress(oBBox.r2, oBBox.c1, 0)));
}
var aCols = this.worksheet._getCols();
for(var i in aCols)
{
var nIndex = i - 0;
if(nIndex > oBBox.c2)
{
var col = aCols[i];
if(null != col.merged)
col.merged.unmerge(true);
}
}
}
else
{
//если выделение попало в середину мерженой области, надо раздвинуть мерженую область
var oTopRow = this.worksheet.getRange(new CellAddress(0, oBBox.c1, 0), new CellAddress(gc_nMaxRow0, oBBox.c2, 0));
oTopRow._setPropertyNoEmpty(null, function(col){
fAddHyperlinkToExpanded(oExpandedHyperlinkRange, col.hyperlinks);
}, function(cell, nRow0, nCol0, nRowStart, nColStart){
if(nCol0 >= oBBox.c1)
{
if(null != cell.merged)
{
var oMergedBBox = cell.merged.getBBox0();
if(oMergedBBox.c1 < oBBox.c1 || (bLeft && oMergedBBox.c1 == oBBox.c1 && oMergedBBox.c2 > oBBox.c2))
{
var sId = cell.merged.getName();
if(null == oExpandedRange[sId])
oExpandedRange[sId] = cell.merged;
}
}
fAddHyperlinkToExpanded(oExpandedHyperlinkRange, cell.hyperlinks);
}
});
}
//сдвигаем merge и hyperlink области
var oProcessedMerged = new Object();
var oProcessedHyperlinks = new Object();
var fAddToProcess = function(index, merged, hyperlinks){
if(oBBox.c1 <= index)
{
if(null != merged)
{
if(bLeft && index <= oBBox.c2)
merged.unmerge(true);
else
{ {
var sId = merged.getName(); var bChanged = false;
if(null == oProcessedMerged[sId] && null == oExpandedRange[sId]) for(var i = 0, length = aMerged.outer.length; i < length; i++)
oProcessedMerged[sId] = merged;
}
}
if(null != hyperlinks)
{
for(var i = 0,length = hyperlinks.length; i < length; ++i)
{
var hyperlink = hyperlinks[i];
if(bLeft && index <= oBBox.c2)
{ {
hyperlink.Ref.removeHyperlink(hyperlink); var elem = aMerged.outer[i];
} if(!(elem.bbox.c1 < oShiftGet.bbox.c1 && oShiftGet.bbox.r1 <= elem.bbox.r1 && elem.bbox.r2 <= oShiftGet.bbox.r2))
else
{ {
var sId = hyperlink.Ref.getName(); mergeManager.remove(elem.bbox, elem, true);
if(null == oProcessedHyperlinks[sId]) bChanged = true;
oProcessedHyperlinks[sId] = hyperlink;
} }
} }
} if(bChanged)
} oShiftGet = null;
};
var oBodyRange = this.worksheet.getRange(new CellAddress(oBBox.r1, 0, 0), new CellAddress(oBBox.r2, gc_nMaxCol0, 0))
oBodyRange._setPropertyNoEmpty(null, function(col){
fAddToProcess(col.index, col.merged, col.hyperlinks);
}, function(cell, nRow0, nCol0, nRowStart, nColStart){
fAddToProcess(nCol0, cell.merged, cell.hyperlinks);
});
for(var i in oProcessedMerged)
{
if(bLeft)
oProcessedMerged[i].setOffset({offsetCol:-nWidth, offsetRow:0});
else
oProcessedMerged[i].setOffset({offsetCol:nWidth, offsetRow:0});
}
for(var i in oProcessedHyperlinks)
{
bChangeHyperlink = true;
if(bLeft)
oProcessedHyperlinks[i].Ref.setOffset({offsetCol:-nWidth, offsetRow:0});
else
oProcessedHyperlinks[i].Ref.setOffset({offsetCol:nWidth, offsetRow:0});
} }
//сдвигаем ячейки //сдвигаем ячейки
if(bLeft) if(bLeft)
...@@ -7545,32 +7271,8 @@ Range.prototype._shiftLeftRight=function(bLeft){ ...@@ -7545,32 +7271,8 @@ Range.prototype._shiftLeftRight=function(bLeft){
else else
this.worksheet._insertColsBefore(oBBox.c1, nWidth); this.worksheet._insertColsBefore(oBBox.c1, nWidth);
} }
//возвращаем oExpandedRange mergeManager.shift(this.bbox, !bLeft, true, oShiftGet);
for(var i in oExpandedRange) this.worksheet.hyperlinkManager.shift(this.bbox, !bLeft, true);
{
var oExpanded = oExpandedRange[i];
if(bLeft)
oExpanded.setOffsetLast({offsetCol:-nWidth, offsetRow:0});
else
oExpanded.setOffsetLast({offsetCol:nWidth, offsetRow:0});
oExpanded.merge();
}
//возвращаем oExpandedRange
for(var i in oExpandedHyperlinkRange)
{
var oExpanded = oExpandedHyperlinkRange[i];
var oHyperlinkBBox = oExpanded.Ref.getBBox0();
if(oHyperlinkBBox.r1 >= oBBox.r1 && oHyperlinkBBox.r2 <= oBBox.r2)
{
if(bLeft)
oExpanded.Ref.setOffsetLast({offsetCol:-nWidth, offsetRow:0});
else
oExpanded.Ref.setOffsetLast({offsetCol:nWidth, offsetRow:0});
}
oExpanded.Ref.setHyperlink(oExpanded, true);
}
if(bChangeHyperlink)
this.worksheet.addActionHyperlink(true);
History.EndTransaction(); History.EndTransaction();
return true; return true;
}; };
...@@ -7580,144 +7282,27 @@ Range.prototype._shiftUpDown=function(bUp){ ...@@ -7580,144 +7282,27 @@ Range.prototype._shiftUpDown=function(bUp){
var nRangeType = this._getRangeType(oBBox); var nRangeType = this._getRangeType(oBBox);
if(c_oRangeType.Range != nRangeType && c_oRangeType.Row != nRangeType) if(c_oRangeType.Range != nRangeType && c_oRangeType.Row != nRangeType)
return false; return false;
var mergeManager = this.worksheet.mergeManager;
var oShiftGet = mergeManager.shiftGet(this.bbox, false);
var aMerged = oShiftGet.elems;
//todo вставить предупреждение, что будет unmerge
History.Create_NewPoint(); History.Create_NewPoint();
History.SetSelection(new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2)); History.SetSelection(new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2));
History.StartTransaction(); History.StartTransaction();
var bChangeHyperlink = false; if(null != aMerged.outer && aMerged.outer.length > 0)
var oExpandedHyperlinkRange = new Object();//hyperlink области которые надо раздвинуть или они выходят за границы и их надо оставить
var fAddHyperlinkToExpanded = function(oExpanded, aHyperlinks)
{
for(var i = 0, length = aHyperlinks.length; i < length ;++i)
{
var hyperlink = aHyperlinks[i];
var oHyperlinkBBox = hyperlink.Ref.getBBox0();
if(false == (oHyperlinkBBox.c1 >= oBBox.c1 && oHyperlinkBBox.r1 >= oBBox.r1 && oHyperlinkBBox.c2 <= oBBox.c2))
{
bChangeHyperlink = true;
var sId = hyperlink.Ref.getName();
oExpanded[sId] = hyperlink;
hyperlink.Ref.removeHyperlink(hyperlink);
}
}
}
var oExpandedRange = new Object();//merge области которые надо раздвинуть
//todo проверка не выходят ли данные за границу
if(c_oRangeType.Range == nRangeType){
//делаем unmerge, если нельзя сдвинуть из-за этого
//временно убираем hyperlink, которые выходят за диапазон, возвращаем после сдвига ячеек
var fProcessEdge = function(range){
range._setPropertyNoEmpty(null, null, function(cell, nRow0, nCol0, nRowStart, nColStart){
if(nRow0 > oBBox.r2)
{
if(null != cell.merged)
{
var oMergedBBox = cell.merged.getBBox0();
if(oMergedBBox.c1 < oBBox.c1 || oMergedBBox.c2 > oBBox.c2)
cell.merged.unmerge(true);
}
fAddHyperlinkToExpanded(oExpandedHyperlinkRange, cell.hyperlinks);
}
});
};
fProcessEdge(this.worksheet.getRange(new CellAddress(0, oBBox.c1, 0), new CellAddress(gc_nMaxRow0, oBBox.c1, 0)));
if(oBBox.r1 != oBBox.r2)
{
fProcessEdge(this.worksheet.getRange(new CellAddress(0, oBBox.c2, 0), new CellAddress(gc_nMaxRow0, oBBox.c2, 0)));
//проходим эту область специально для hyperlink
fProcessEdge(this.worksheet.getRange(new CellAddress(oBBox.r1, oBBox.c1, 0), new CellAddress(oBBox.r1, oBBox.c2, 0)));
}
var aRows = this.worksheet._getRows();
for(var i in aRows)
{
var nIndex = i - 0;
if(nIndex > oBBox.r2)
{
var col = aRows[i];
if(null != col.merged)
col.merged.unmerge(true);
}
}
}
else
{ {
//если выделение попало в середину мерженой области, надо раздвинуть мерженую область var bChanged = false;
var oLeftCol = this.worksheet.getRange(new CellAddress(oBBox.r1, 0, 0), new CellAddress(oBBox.r2, gc_nMaxCol0, 0)); for(var i = 0, length = aMerged.outer.length; i < length; i++)
oLeftCol._setPropertyNoEmpty(function(row){
fAddHyperlinkToExpanded(oExpandedHyperlinkRange, row.hyperlinks);
}, null, function(cell, nRow0, nCol0, nRowStart, nColStart){
if(nRow0 >= oBBox.r1)
{ {
if(null != cell.merged) var elem = aMerged.outer[i];
if(!(elem.bbox.r1 < oShiftGet.bbox.r1 && oShiftGet.bbox.c1 <= elem.bbox.c1 && elem.bbox.c2 <= oShiftGet.bbox.c2))
{ {
var oMergedBBox = cell.merged.getBBox0(); mergeManager.remove(elem.bbox, elem, true);
if(oMergedBBox.r1 < oBBox.r1 || (bUp && oMergedBBox.r1 == oBBox.r1 && oMergedBBox.r2 > oBBox.r2)) bChanged = true;
{
var sId = cell.merged.getName();
if(null == oExpandedRange[sId])
oExpandedRange[sId] = cell.merged;
}
}
fAddHyperlinkToExpanded(oExpandedHyperlinkRange, cell.hyperlinks);
}
});
}
//сдвигаем merge и hyperlink области
var oProcessedMerged = new Object();
var oProcessedHyperlinks = new Object();
var fAddToProcess = function(index, merged, hyperlinks){
if(oBBox.r1 <= index)
{
if(null != merged)
{
if(bUp && index <= oBBox.r2)
merged.unmerge(true);
else
{
var sId = merged.getName();
if(null == oProcessedMerged[sId] && null == oExpandedRange[sId])
oProcessedMerged[sId] = merged;
} }
} }
if(null != hyperlinks) if(bChanged)
{ oShiftGet = null;
for(var i = 0,length = hyperlinks.length; i < length; ++i)
{
var hyperlink = hyperlinks[i];
if(bUp && index <= oBBox.r2)
{
hyperlink.Ref.removeHyperlink(hyperlink);
}
else
{
var sId = hyperlink.Ref.getName();
if(null == oProcessedHyperlinks[sId])
oProcessedHyperlinks[sId] = hyperlink;
}
}
}
}
};
var oBodyRange = this.worksheet.getRange(new CellAddress(0, oBBox.c1, 0), new CellAddress(gc_nMaxRow0, oBBox.c2, 0))
oBodyRange._setPropertyNoEmpty(function(row){
fAddToProcess(row.index, row.merged, row.hyperlinks);
}, null,function(cell, nRow0, nCol0, nRowStart, nColStart){
fAddToProcess(nRow0, cell.merged, cell.hyperlinks);
});
for(var i in oProcessedMerged)
{
if(bUp)
oProcessedMerged[i].setOffset({offsetCol:0, offsetRow:-nHeight});
else
oProcessedMerged[i].setOffset({offsetCol:0, offsetRow:nHeight});
}
for(var i in oProcessedHyperlinks)
{
bChangeHyperlink = true;
if(bUp)
oProcessedHyperlinks[i].Ref.setOffset({offsetCol:0, offsetRow:-nHeight});
else
oProcessedHyperlinks[i].Ref.setOffset({offsetCol:0, offsetRow:nHeight});
} }
//сдвигаем ячейки //сдвигаем ячейки
if(bUp) if(bUp)
...@@ -7734,32 +7319,8 @@ Range.prototype._shiftUpDown=function(bUp){ ...@@ -7734,32 +7319,8 @@ Range.prototype._shiftUpDown=function(bUp){
else else
this.worksheet._insertRowsBefore(oBBox.r1, nHeight); this.worksheet._insertRowsBefore(oBBox.r1, nHeight);
} }
//возвращаем oExpandedRange mergeManager.shift(this.bbox, !bUp, false, oShiftGet);
for(var i in oExpandedRange) this.worksheet.hyperlinkManager.shift(this.bbox, !bUp, false);
{
var oExpanded = oExpandedRange[i];
if(bUp)
oExpanded.setOffsetLast({offsetCol:0, offsetRow:-nHeight});
else
oExpanded.setOffsetLast({offsetCol:0, offsetRow:nHeight});
oExpanded.merge();
}
//возвращаем oExpandedRange
for(var i in oExpandedHyperlinkRange)
{
var oExpanded = oExpandedHyperlinkRange[i];
var oHyperlinkBBox = oExpanded.Ref.getBBox0();
if(oHyperlinkBBox.c1 >= oBBox.c1 && oHyperlinkBBox.c2 <= oBBox.c2)
{
if(bUp)
oExpanded.Ref.setOffsetLast({offsetCol:0, offsetRow:-nHeight});
else
oExpanded.Ref.setOffsetLast({offsetCol:0, offsetRow:nHeight});
}
oExpanded.Ref.setHyperlink(oExpanded, true);
}
if(bChangeHyperlink)
this.worksheet.addActionHyperlink(true);
History.EndTransaction(); History.EndTransaction();
return true; return true;
}; };
...@@ -7855,7 +7416,10 @@ Range.prototype.cleanAll=function(){ ...@@ -7855,7 +7416,10 @@ Range.prototype.cleanAll=function(){
History.SetSelection(new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2)); History.SetSelection(new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2));
History.StartTransaction(); History.StartTransaction();
this.unmerge(); this.unmerge();
this.removeHyperlink(); //удаляем только гиперссылки, которые полностью лежат в области
var aHyperlinks = this.worksheet.hyperlinkManager.get(this.bbox);
for(var i = 0, length = aHyperlinks.inner.length; i < length; ++i)
this.removeHyperlink(aHyperlinks.inner[i].data);
var oThis = this; var oThis = this;
this._setPropertyNoEmpty(function(row){ this._setPropertyNoEmpty(function(row){
row.setStyle(null); row.setStyle(null);
...@@ -8041,22 +7605,7 @@ Range.prototype.sort=function(nOption, nStartCol){ ...@@ -8041,22 +7605,7 @@ Range.prototype.sort=function(nOption, nStartCol){
return oRes; return oRes;
} }
Range.prototype._sortByArray=function(oBBox, aSortData, bUndo){ Range.prototype._sortByArray=function(oBBox, aSortData, bUndo){
//сортируются только одинарные гиперссылки, все неодинарные убираем и восстанавливаем после сортировки
var rec = {length:0}; var rec = {length:0};
var oExpandedHyperlinkRange = new Object();
var oSortRange = this.worksheet.getRange3(oBBox.r1, oBBox.c1, oBBox.r2, oBBox.c2);
oSortRange._setPropertyNoEmpty(null, null, function(cell, nRow0, nCol0, nRowStart, nColStart){
for(var i = 0, length = cell.hyperlinks.length; i < length ;++i)
{
var hyperlink = cell.hyperlinks[i];
if(false == hyperlink.Ref.isOneCell())
{
var sId = hyperlink.Ref.getName();
oExpandedHyperlinkRange[sId] = hyperlink;
hyperlink.Ref.removeHyperlink(hyperlink);
}
}
});
var oSortedIndexes = new Object(); var oSortedIndexes = new Object();
for(var i = 0, length = aSortData.length; i < length; ++i) for(var i = 0, length = aSortData.length; i < length; ++i)
{ {
...@@ -8070,6 +7619,28 @@ Range.prototype._sortByArray=function(oBBox, aSortData, bUndo){ ...@@ -8070,6 +7619,28 @@ Range.prototype._sortByArray=function(oBBox, aSortData, bUndo){
} }
oSortedIndexes[nFrom] = nTo; oSortedIndexes[nFrom] = nTo;
} }
//сортируются только одинарные гиперссылки, все неодинарные оставляем
var aHyperlinks = this.worksheet.hyperlinkManager.get(this.bbox);
var aSortedHyperlinks = new Array();
for(var i = 0, length = aHyperlinks.inner.length; i < length; i++)
{
var elem = aHyperlinks.inner[i];
var hyp = elem.data;
if(hyp.Ref.isOneCell())
{
var nFrom = elem.bbox.r1;
var nTo = oSortedIndexes[nFrom];
if(null != nTo)
{
//удаляем ссылки, а не перемеаем, чтобы не было конфликтов(например в случае если все ячейки имеют ссылки и их надо передвинуть)
var oTempBBox = hyp.Ref.getBBox0();
this.worksheet.hyperlinkManager.remove(oTempBBox, new RangeDataManagerElem(oTempBBox, hyp), false);
var oNewHyp = hyp.clone();
oNewHyp.Ref.setOffset({offsetCol: 0, offsetRow: nTo - nFrom});
aSortedHyperlinks.push(oNewHyp);
}
}
}
//окончательно устанавливаем ячейки //окончательно устанавливаем ячейки
var nColFirst0 = oBBox.c1; var nColFirst0 = oBBox.c1;
var nLastCol0 = oBBox.c2; var nLastCol0 = oBBox.c2;
...@@ -8136,17 +7707,20 @@ Range.prototype._sortByArray=function(oBBox, aSortData, bUndo){ ...@@ -8136,17 +7707,20 @@ Range.prototype._sortByArray=function(oBBox, aSortData, bUndo){
} }
} }
} }
for(var i in oExpandedHyperlinkRange)
{
var hyperlink = oExpandedHyperlinkRange[i];
hyperlink.Ref.setHyperlink(hyperlink);
}
// this.worksheet.workbook.buildDependency(); // this.worksheet.workbook.buildDependency();
// this.worksheet.workbook.needRecalc = rec; // this.worksheet.workbook.needRecalc = rec;
// recalc(this.worksheet.workbook); // recalc(this.worksheet.workbook);
//восстанавливаем удаленые гиперссылки
if(aSortedHyperlinks.length > 0)
{
for(var i = 0, length = aSortedHyperlinks.length; i < length; i++)
{
var hyp = aSortedHyperlinks[i];
this.worksheet.hyperlinkManager.add(hyp.Ref.getBBox0(), hyp);
}
this.worksheet.addActionHyperlink(true);
}
}; };
Range.prototype.promote=function(bCtrl, bVertical, nIndex){ Range.prototype.promote=function(bCtrl, bVertical, nIndex){
var oBBox = this.bbox; var oBBox = this.bbox;
......
...@@ -1914,8 +1914,6 @@ function Col(worksheet, index) ...@@ -1914,8 +1914,6 @@ function Col(worksheet, index)
this.CustomWidth = null; this.CustomWidth = null;
this.width = null; this.width = null;
this.xfs = null; this.xfs = null;
this.merged = null;
this.hyperlinks = new Array();
}; };
Col.prototype = Col.prototype =
{ {
...@@ -1929,7 +1927,7 @@ Col.prototype = ...@@ -1929,7 +1927,7 @@ Col.prototype =
}, },
isEqual : function(obj) isEqual : function(obj)
{ {
var bRes = this.BestFit == obj.BestFit && this.hd == obj.hd && this.width == obj.width && this.CustomWidth == obj.CustomWidth && this.merged == obj.merged && this.hyperlinks.length == obj.hyperlinks.length; var bRes = this.BestFit == obj.BestFit && this.hd == obj.hd && this.width == obj.width && this.CustomWidth == obj.CustomWidth;
if(bRes) if(bRes)
{ {
if(null != this.xfs && null != obj.xfs) if(null != this.xfs && null != obj.xfs)
...@@ -1937,17 +1935,6 @@ Col.prototype = ...@@ -1937,17 +1935,6 @@ Col.prototype =
else if(null != this.xfs || null != obj.xfs) else if(null != this.xfs || null != obj.xfs)
bRes = false; bRes = false;
} }
if(bRes)
{
for(var i = 0, length = this.hyperlinks.length; i < length; ++i)
{
if(false == this.hyperlinks[i].isEqual(obj.hyperlinks[i]))
{
bRes = false;
break;
}
}
}
return bRes; return bRes;
}, },
isEmptyToSave : function() isEmptyToSave : function()
...@@ -1956,7 +1943,7 @@ Col.prototype = ...@@ -1956,7 +1943,7 @@ Col.prototype =
}, },
isEmpty : function() isEmpty : function()
{ {
return this.isEmptyToSave() && null == this.merged && 0 == this.hyperlinks.length; return this.isEmptyToSave();
}, },
Remove : function() Remove : function()
{ {
...@@ -1975,16 +1962,6 @@ Col.prototype = ...@@ -1975,16 +1962,6 @@ Col.prototype =
oNewCol.CustomWidth = this.CustomWidth; oNewCol.CustomWidth = this.CustomWidth;
if(null != this.xfs) if(null != this.xfs)
oNewCol.xfs = this.xfs.clone(); oNewCol.xfs = this.xfs.clone();
//надо быть осторожнее, пока clone используется только с oAllCol
if(null != this.merged)
oNewCol.merged = this.merged;
if(null != this.hyperlinks)
{
oNewCol.hyperlinks = new Array();
for(var i = 0, length = this.hyperlinks.length; i < length; ++i)
oNewCol.hyperlinks.push(this.hyperlinks[i]);
}
//todo hyperlink
return oNewCol; return oNewCol;
}, },
getWidthProp : function() getWidthProp : function()
...@@ -2013,10 +1990,6 @@ Col.prototype = ...@@ -2013,10 +1990,6 @@ Col.prototype =
this.BestFit = null; this.BestFit = null;
} }
}, },
getMerged : function()
{
return this.merged;
},
setStyle : function(xfs) setStyle : function(xfs)
{ {
var oldVal = this.xfs; var oldVal = this.xfs;
...@@ -2197,8 +2170,6 @@ function Row(worksheet) ...@@ -2197,8 +2170,6 @@ function Row(worksheet)
this.h = null; this.h = null;
this.hd = null; this.hd = null;
this.CustomHeight = null; this.CustomHeight = null;
this.merged = null;
this.hyperlinks = new Array();
}; };
Row.prototype = Row.prototype =
{ {
...@@ -2232,7 +2203,7 @@ Row.prototype = ...@@ -2232,7 +2203,7 @@ Row.prototype =
}, },
isEmpty : function() isEmpty : function()
{ {
return this.isEmptyToSave() && null == this.merged && 0 == this.hyperlinks.length; return this.isEmptyToSave();
}, },
Remove : function() Remove : function()
{ {
...@@ -2252,7 +2223,6 @@ Row.prototype = ...@@ -2252,7 +2223,6 @@ Row.prototype =
oNewRow.hd = this.hd; oNewRow.hd = this.hd;
for(var i in this.c) for(var i in this.c)
oNewRow.c[i] = this.c[i].clone(); oNewRow.c[i] = this.c[i].clone();
//todo hyperlink
return oNewRow; return oNewRow;
}, },
getHeightProp : function() getHeightProp : function()
...@@ -2287,10 +2257,6 @@ Row.prototype = ...@@ -2287,10 +2257,6 @@ Row.prototype =
this.CustomHeight = otherRow.CustomHeight; this.CustomHeight = otherRow.CustomHeight;
this.hd = otherRow.hd; this.hd = otherRow.hd;
}, },
getMerged : function()
{
return this.merged;
},
setStyle : function(xfs) setStyle : function(xfs)
{ {
var oldVal = this.xfs; var oldVal = this.xfs;
...@@ -2901,18 +2867,16 @@ CCellValue.prototype = ...@@ -2901,18 +2867,16 @@ CCellValue.prototype =
//для посещенных гиперссылок //для посещенных гиперссылок
if(g_nColorHyperlink == oNewItem.theme && null == oNewItem.tint) if(g_nColorHyperlink == oNewItem.theme && null == oNewItem.tint)
{ {
var aHyperlinks = this.cell.getHyperlinks(); var nRow = this.cell.oId.getRow0();
if(aHyperlinks.length > 0) var nCol = this.cell.oId.getCol0();
{ var hyperlink = this.cell.ws.hyperlinkManager.getByCell(nRow, nCol);
var hyperlink = aHyperlinks[aHyperlinks.length - 1]; if(null != hyperlink && hyperlink.data.getVisited())
if(hyperlink.getVisited())
{ {
oNewItem.format.c = g_oColorManager.getThemeColor(g_nColorHyperlinkVisited, null); oNewItem.format.c = g_oColorManager.getThemeColor(g_nColorHyperlinkVisited, null);
oNewItem.theme = g_nColorHyperlinkVisited; oNewItem.theme = g_nColorHyperlinkVisited;
} }
} }
} }
}
oNewItem.format.c = oNewItem.format.getRgbOrNull(); oNewItem.format.c = oNewItem.format.getRgbOrNull();
oNewItem.format.skip = false; oNewItem.format.skip = false;
oNewItem.format.repeat = false; oNewItem.format.repeat = false;
...@@ -2939,18 +2903,16 @@ CCellValue.prototype = ...@@ -2939,18 +2903,16 @@ CCellValue.prototype =
//для посещенных гиперссылок //для посещенных гиперссылок
if(g_nColorHyperlink == oNewItem.theme && null == oNewItem.tint) if(g_nColorHyperlink == oNewItem.theme && null == oNewItem.tint)
{ {
var aHyperlinks = this.cell.getHyperlinks(); var nRow = this.cell.oId.getRow0();
if(aHyperlinks.length > 0) var nCol = this.cell.oId.getCol0();
{ var hyperlink = this.cell.ws.hyperlinkManager.getByCell(nRow, nCol);
var hyperlink = aHyperlinks[aHyperlinks.length - 1]; if(null != hyperlink && hyperlink.data.getVisited())
if(hyperlink.getVisited())
{ {
oNewItem.format.c = g_oColorManager.getThemeColor(g_nColorHyperlinkVisited, null); oNewItem.format.c = g_oColorManager.getThemeColor(g_nColorHyperlinkVisited, null);
oNewItem.theme = g_nColorHyperlinkVisited; oNewItem.theme = g_nColorHyperlinkVisited;
} }
} }
} }
}
oNewItem.format.c = oNewItem.format.getRgbOrNull(); oNewItem.format.c = oNewItem.format.getRgbOrNull();
aResult.push(oNewItem); aResult.push(oNewItem);
} }
...@@ -3048,7 +3010,9 @@ CCellValue.prototype = ...@@ -3048,7 +3010,9 @@ CCellValue.prototype =
for(var i = 0, length = aVal.length; i < length; ++i) for(var i = 0, length = aVal.length; i < length; ++i)
sSimpleText += aVal[i].text; sSimpleText += aVal[i].text;
this.setValue(sSimpleText); this.setValue(sSimpleText);
if(CellValueType.String == this.type && 0 == this.cell.getHyperlinks().length) var nRow = this.cell.oId.getRow0();
var nCol = this.cell.oId.getCol0();
if(CellValueType.String == this.type && null != this.cell.ws.hyperlinkManager.getByCell(nRow, nCol))
{ {
this.clean(); this.clean();
this.type = CellValueType.String; this.type = CellValueType.String;
...@@ -3267,3 +3231,539 @@ CCellValue.prototype = ...@@ -3267,3 +3231,539 @@ CCellValue.prototype =
} }
} }
}; };
function RangeDataManagerElem(bbox, data)
{
this.bbox = bbox;
this.data = data;
this.id = 0;
}
function RangeDataManager(bAllowIntersect, fChange)
{
this.oGCells = {};
this.oRows = {};
this.oCols = {};
this.oAll = null;
this.oElements = {};
this.nElementsCount = 0;
this.bbox = null;
this.nStopRecalculate = 0;
this.idGen = 0;
this.oDependenceManager = null;
this.bAllowIntersect = bAllowIntersect;
this.fChange = fChange;
}
RangeDataManager.prototype = {
add : function(bbox, data)
{
var oNewElem = new RangeDataManagerElem(new Asc.Range(bbox.c1, bbox.r1, bbox.c2, bbox.r2), data);
oNewElem.id = this.idGen++;
var nRangeType = getRangeType(bbox);
if(c_oRangeType.Range == nRangeType)
{
for(var i = bbox.r1; i <= bbox.r2; i++)
{
var row = this.oGCells[i];
if(null == row)
{
row = {};
this.oGCells[i] = row;
}
for(var j = bbox.c1; j <= bbox.c2; j++)
{
if(this.bAllowIntersect)
{
var elem = row[j];
if(null == elem)
{
elem = [];
row[j] = elem;
}
elem.push(oNewElem);
}
else
row[j] = oNewElem;
}
}
}
else if(c_oRangeType.Col == nRangeType)
{
for(var i = bbox.c1; i <= bbox.c2; i++)
{
if(this.bAllowIntersect)
{
var elem = this.oCols[i];
if(null == elem)
{
elem = [];
this.oCols[i] = elem;
}
elem.push(oNewElem);
}
else
this.oCols[i] = oNewElem;
}
}
else if(c_oRangeType.Row == nRangeType)
{
for(var i = bbox.r1; i <= bbox.r2; i++)
{
if(this.bAllowIntersect)
{
var elem = this.oRows[i];
if(null == elem)
{
elem = [];
this.oRows[i] = elem;
}
elem.push(oNewElem);
}
else
this.oRows[i] = oNewElem;
}
}
else if(c_oRangeType.All == nRangeType)
{
if(this.bAllowIntersect)
this.oAll = [oNewElem];
else
this.oAll = oNewElem;
}
this.oElements[this._getBBoxIndex(bbox)] = oNewElem;
this._recalculate();
},
_getExecElem : function(elem, oFindElems)
{
if(null != elem)
{
if(this.bAllowIntersect)
{
for(var i = 0, length = elem.length; i < length; ++i)
{
var item = elem[i];
oFindElems[item.id] = item;
}
}
else
oFindElems[elem.id] = elem;
}
},
get : function(bbox)
{
var oRes = {all: [], inner: [], outer: []};
if(null != this.bbox)
bbox = this.bbox.intersectionSimple(bbox);
else
bbox = null;
if(null != bbox)
{
var oFindElems = {};
//todo подумать, может в некоторых случаях можно пускать полный перебор
// if(this.nElementsCount < 100)
// {
// for(var i in this.oElements)
// {
// var elem = this.oElements[i];
// if(null != elem.bbox.intersectionSimple(bbox))
// this._getExecElem(elem, oFindElems);
// }
// }
// else
{
var nRangeType = getRangeType(bbox);
if(bbox.r2 < gc_nMaxRow0 / 4)
{
for(var i = bbox.r1; i <= bbox.r2; i++)
{
var row = this.oGCells[i];
if(null != row)
{
if(bbox.c2 < gc_nMaxCol0 / 4)
{
for(var j = bbox.c1; j <= bbox.c2; j++)
{
var cell = row[j];
if(null != cell)
this._getExecElem(cell, oFindElems);
}
}
else
{
for(var j in row)
{
var nIndexJ = j - 0;
if(bbox.c1 <= nIndexJ && nIndexJ <= bbox.c2)
this._getExecElem(row[j], oFindElems);
}
}
}
}
}
else
{
for(var i in this.oGCells)
{
var nIndexI = i - 0;
if(bbox.r1 <= nIndexI && nIndexI <= bbox.r2)
{
var row = this.oGCells[i];
if(null != row)
{
if(bbox.c2 < gc_nMaxCol0 / 4)
{
for(var j = bbox.c1; j <= bbox.c2; j++)
{
var cell = row[j];
if(null != cell)
this._getExecElem(cell, oFindElems);
}
}
else
{
for(var j in row)
{
var nIndexJ = j - 0;
if(bbox.c1 <= nIndexJ && nIndexJ <= bbox.c2)
this._getExecElem(row[j], oFindElems);
}
}
}
}
}
}
if(bbox.c2 < gc_nMaxCol0 / 4)
{
for(var i = bbox.c1; i <= bbox.c2; i++)
this._getExecElem(this.oCols[i], oFindElems);
}
else
{
for(var i in this.oCols)
{
var nIndex = i - 0;
if(bbox.c1 <= nIndex && nIndex <= bbox.c2)
this._getExecElem(this.oCols[i], oFindElems);
}
}
if(bbox.r2 < gc_nMaxRow0 / 4)
{
for(var i = bbox.r1; i <= bbox.r2; i++)
this._getExecElem(this.oRows[i], oFindElems);
}
else
{
for(var i in this.oRows)
{
var nIndex = i - 0;
if(bbox.r1 <= nIndex && nIndex <= bbox.r2)
this._getExecElem(this.oRows[i], oFindElems);
}
}
this._getExecElem(this.oAll, oFindElems);
}
for(var i in oFindElems)
{
var elem = oFindElems[i];
oRes.all.push(elem);
if(bbox.containsRange(elem.bbox))
oRes.inner.push(elem);
else
oRes.outer.push(elem);
}
}
return oRes;
},
_getByCellExecElem : function(elem)
{
var oRes = null;
if(null != elem)
{
if(this.bAllowIntersect)
{
if(elem.length > 0)
oRes = elem[0];
}
else
oRes = elem;
}
return oRes;
},
_getByCell : function(nRow, nCol)
{
var oRes = null;
var row = this.oGCells[nRow];
if(null != row)
oRes = this._getByCellExecElem(row[nCol]);
if(null == oRes)
{
oRes = this._getByCellExecElem(this.oRows[nRow]);
if(null == oRes)
{
oRes = this._getByCellExecElem(this.oCols[nCol]);
if(null == oRes)
oRes = this._getByCellExecElem(this.oAll);
}
}
return oRes;
},
getByCell : function(nRow, nCol)
{
var oRes = null;
if(null != this.bbox)
{
if(this.bbox.contains(nCol, nRow))
oRes = this._getByCell(nRow, nCol);
if(null == oRes && null != this.oDependenceManager)
{
var oDependence = this.oDependenceManager._getByCell(nRow, nCol);
if(null != oDependence)
{
var oTempRes = this.get(oDependence.bbox);
if(oTempRes.all.length > 0)
oRes = oTempRes.all[0];
}
}
}
return oRes;
},
_removeExecElem : function(container, index, elemToDelete)
{
var elem = null;
if(null != index)
elem = container[index];
else
elem = container;
if(null != elem)
{
if(this.bAllowIntersect)
{
for(var i = 0, length = elem.length; i < length; ++i)
{
var item = elem[i];
if(elemToDelete.data == item.data)
{
elem.splice(i, 1);
break;
}
}
if(0 == elem.length)
{
if(null != index)
delete container[index];
else
container = null;
}
}
else
{
if(elemToDelete.data == elem.data)
{
if(null != index)
delete container[index];
else
container = null;
}
}
}
return container;
},
remove : function(bbox, elemToDelete, bTriggerEvent)
{
if(null != elemToDelete)
{
var nRangeType = getRangeType(bbox);
if(c_oRangeType.Range == nRangeType)
{
for(var i = bbox.r1; i <= bbox.r2; i++)
{
var row = this.oGCells[i];
if(null != row)
{
for(var j = bbox.c1; j <= bbox.c2; j++)
this._removeExecElem(row, j, elemToDelete);
}
}
}
else if(c_oRangeType.Col == nRangeType)
{
for(var i = bbox.c1; i <= bbox.c2; i++)
this._removeExecElem(this.oCols, i, elemToDelete);
}
else if(c_oRangeType.Row == nRangeType)
{
for(var i = bbox.r1; i <= bbox.r2; i++)
this._removeExecElem(this.oRows, i, elemToDelete);
}
else if(c_oRangeType.All == nRangeType)
this._removeExecElem(this.oAll, null, elemToDelete);
if(false != bTriggerEvent)
this.fChange.call(this, elemToDelete.data, elemToDelete.bbox, null);
delete this.oElements[this._getBBoxIndex(elemToDelete.bbox)];
this._recalculate();
}
else
{
this.nStopRecalculate++;
var aElems = this.get(bbox);
for(var i = 0, length = aElems.all.length; i < length; ++i)
{
var elem = aElems.all[i];
this.remove(elem.bbox, elem, bTriggerEvent);
}
this.nStopRecalculate--;
this._recalculate();
}
},
shiftGet : function(bbox, bHor)
{
var bboxGet = null;
if(bHor)
bboxGet = {r1: bbox.r1, c1: bbox.c1, r2: bbox.r2, c2: gc_nMaxCol0};
else
bboxGet = {r1: bbox.r1, c1: bbox.c1, r2: gc_nMaxRow0, c2: bbox.c2};
return {bbox: bboxGet, elems: this.get(bboxGet)};
},
shift : function(bbox, bAdd, bHor, oGetRes)
{
this.nStopRecalculate++;
if(null == oGetRes)
oGetRes = this.shiftGet(bbox, bHor);
var elems = oGetRes.elems;
//сдвигаем inner
if(elems.inner.length > 0)
{
var offset = null;
if(bHor)
offset = {offsetRow: 0, offsetCol: bbox.c2 - bbox.c1 + 1};
else
offset = {offsetRow: bbox.r2 - bbox.r1 + 1, offsetCol: 0};
for(var i = 0, length = elems.inner.length; i < length; i++)
{
var elem = elems.inner[i];
this.remove(elem.bbox, elem, false);
}
for(var i = 0, length = elems.inner.length; i < length; i++)
{
var elem = elems.inner[i];
var from = elem.bbox;
var to = null;
if(bAdd)
{
to = elem.bbox.clone();
to.setOffset(offset);
}
else
{
if(!from.containsRange(bbox))
{
to = elem.bbox.clone();
if(bHor)
{
if(to.c1 <= bbox.c2)
to.setOffsetFirst({offsetRow: 0, offsetCol: bbox.c2 - to.c1 + 1});
}
else
{
if(to.r1 <= bbox.r2)
to.setOffsetFirst({offsetRow: bbox.r2 - to.r1 + 1, offsetCol: 0});
}
to.setOffset(offset);
}
}
if(null != to)
this.add(to, elem.data);
if(null != this.fChange)
this.fChange.call(this, elem.data, from, to);
}
}
//меняем outer
if(elems.outer.length > 0)
{
for(var i = 0, length = elems.outer.length; i < length; i++)
{
var elem = elems.outer[i];
var from = elem.bbox;
var to = null;
if(bHor)
{
if(from.c1 < bbox.c1 && bbox.r1 <= from.r1 && from.r2 <= bbox.r2)
{
if(bAdd)
{
to = from.clone();
to.setOffsetLast({offsetRow: 0, offsetCol: bbox.c2 - bbox.c1 + 1});
}
else
{
to = from.clone();
var nTemp1 = from.c2 - bbox.c1 + 1;
var nTemp2 = bbox.c2 - bbox.c1 + 1;
to.setOffsetLast({offsetRow: 0, offsetCol: -Math.min(nTemp1, nTemp2)});
}
}
}
else
{
if(from.r1 < bbox.r1 && bbox.c1 <= from.c1 && from.c2 <= bbox.c2)
{
if(bAdd)
{
to = from.clone();
to.setOffsetLast({offsetRow: bbox.r2 - bbox.r1 + 1, offsetCol: 0});
}
else
{
to = from.clone();
var nTemp1 = from.r2 - bbox.r1 + 1;
var nTemp2 = bbox.r2 - bbox.r1 + 1;
to.setOffsetLast({offsetRow: -Math.min(nTemp1, nTemp2), offsetCol: 0});
}
}
}
if(null != to)
{
if(null != this.fChange)
this.fChange.call(this, elem.data, from, to);
elem.bbox = to;
delete this.oElements[this._getBBoxIndex(from)];
this.oElements[this._getBBoxIndex(to)] = elem;
}
}
}
this.nStopRecalculate--;
this._recalculate();
},
getAll : function()
{
return this.oElements;
},
setDependenceManager : function(oDependenceManager)
{
this.oDependenceManager = oDependenceManager;
},
_getBBoxIndex : function(bbox)
{
return bbox.r1 + "-" + bbox.c1 + "-" + bbox.r2 + "-" + bbox.c2;
},
_recalculate : function()
{
if(0 == this.nStopRecalculate)
{
this.nElementsCount = 0;
this.bbox = null;
for(var i in this.oElements)
{
var elem = this.oElements[i];
if(null != elem)
{
this.nElementsCount++;
if(null == this.bbox)
this.bbox = elem.bbox.clone();
else
this.bbox.union2(elem.bbox);
}
}
}
}
};
\ No newline at end of file
...@@ -226,6 +226,10 @@ ...@@ -226,6 +226,10 @@
return this.c1 <= c && c <= this.c2 && this.r1 <= r && r <= this.r2; return this.c1 <= c && c <= this.c2 && this.r1 <= r && r <= this.r2;
}, },
containsRange: function (range) {
return this.contains(range.c1, range.r1) && this.contains(range.c2, range.r2);
},
intersection: function (range) { intersection: function (range) {
var s1 = this.clone(true), var s1 = this.clone(true),
s2 = range instanceof Range ? range.clone(true) : s2 = range instanceof Range ? range.clone(true) :
...@@ -240,6 +244,17 @@ ...@@ -240,6 +244,17 @@
Math.min(s1.r2, s2.r2)); Math.min(s1.r2, s2.r2));
}, },
intersectionSimple: function (range) {
var oRes = null;
var r1 = Math.max(this.r1, range.r1);
var c1 = Math.max(this.c1, range.c1);
var r2 = Math.min(this.r2, range.r2);
var c2 = Math.min(this.c2, range.c2);
if(r1 <= r2 && c1 <= c2)
oRes = new Range(c1, r1, c2, r2);
return oRes;
},
union: function (range) { union: function (range) {
var s1 = this.clone(true), var s1 = this.clone(true),
s2 = range instanceof Range ? range.clone(true) : s2 = range instanceof Range ? range.clone(true) :
...@@ -255,6 +270,29 @@ ...@@ -255,6 +270,29 @@
this.c2 = Math.max(this.c2, range.c2); this.c2 = Math.max(this.c2, range.c2);
this.r1 = Math.min(this.r1, range.r1); this.r1 = Math.min(this.r1, range.r1);
this.r2 = Math.max(this.r2, range.r2); this.r2 = Math.max(this.r2, range.r2);
},
setOffset : function(offset){
this.setOffsetFirst(offset);
this.setOffsetLast(offset);
},
setOffsetFirst : function(offset){
this.c1 += offset.offsetCol;
if( this.c1 < 0 )
this.c1 = 0;
this.r1 += offset.offsetRow;
if( this.r1 < 0 )
this.r1 = 0;
},
setOffsetLast : function(offset){
this.c2 += offset.offsetCol;
if( this.c2 < 0 )
this.c2 = 0;
this.r2 += offset.offsetRow;
if( this.r2 < 0 )
this.r2 = 0;
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment