DrawingObjects.js 172 KB
Newer Older
1 2 3
"use strict";

/* DrawingObjects.js
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4 5 6 7
 *
 * Author: Dmitry Vikulov
 * Date:   13/08/2012
 */
8

9
if ( !window["Asc"] ) {		// Для вставки диаграмм в Word
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
10
    window["Asc"] = {};
11
}
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
12 13

function isObject(what) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
14
    return ( (what != null) && (typeof(what) == "object") );
15 16
}

17
function isNumber(n) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
18
    return !isNaN(parseFloat(n)) && isFinite(n);
19 20
}

21
function isNullOrEmptyString(str) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
22
    return (str == undefined) || (str == null) || (str == "");
23 24
}

25 26 27 28 29 30 31
function DrawingBounds(minX, maxX, minY, maxY)
{
    this.minX = minX;
    this.maxX = maxX;
    this.minY = minY;
    this.maxY = maxY;
}
32
function getFullImageSrc(src) {
Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
33
    if ( 0 != src.indexOf("http:") && 0 != src.indexOf("data:") && 0 != src.indexOf("https:") && 0 != src.indexOf("ftp:") && 0 != src.indexOf("file:") ) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
34
        var api = window["Asc"]["editor"];
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
        if(api)
        {
            if ( 0 == src.indexOf(g_sResourceServiceLocalUrl + api.documentId) )
                return src;
            return g_sResourceServiceLocalUrl + api.documentId + "/media/" + src;
        }
        else
        {
            if(editor)
            {
                if (0 == src.indexOf(editor.DocumentUrl))
                    return src;
                return editor.DocumentUrl + "media/" + src;
            }
            else
            {
                return src;
            }
        }
Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
54
    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
55 56
    else
        return src;
57
}
Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
58

59
function getCurrentTime() {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
60 61
    var currDate = new Date();
    return currDate.getTime();
62
}
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
63

64
function roundPlus(x, n) { //x - число, n - количество знаков 
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
65 66 67
    if ( isNaN(x) || isNaN(n) ) return false;
    var m = Math.pow(10,n);
    return Math.round(x * m) / m;
68 69
}

70 71 72 73 74 75 76 77 78 79
// Класс для информации о ячейке для объектов ToDo возможно стоит поправить
function CCellObjectInfo () {
	this.col = 0;
	this.row = 0;
	this.colOff = 0;
	this.rowOff = 0;
	this.colOffPx = 0;
	this.rowOffPx = 0;
}

80

Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
81 82
//{ ASC Classes

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
83 84 85
//-----------------------------------------------------------------------------------
// Chart style
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
86
/** @constructor */
87
function asc_CChartStyle() {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
88 89
    this.style = null;
    this.imageUrl = null;
90
}
91

92
asc_CChartStyle.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
93 94
    asc_getStyle: function() { return this.style; },
    asc_setStyle: function(style) { this.style = style; },
95

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
96 97
    asc_getImageUrl: function() { return this.imageUrl; },
    asc_setImageUrl: function(imageUrl) { this.imageUrl = imageUrl; }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
98
};
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
99

100 101 102
//{ asc_CChartStyle export
window["Asc"].asc_CChartStyle = asc_CChartStyle;
window["Asc"]["asc_CChartStyle"] = asc_CChartStyle;
103
var prot = asc_CChartStyle.prototype;
104

105 106 107 108
prot["asc_getStyle"] = prot.asc_getStyle;
prot["asc_setStyle"] = prot.asc_setStyle;

prot["asc_getImageUrl"] = prot.asc_getImageUrl;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
109
prot["asc_setImageUrl"] = prot.asc_setImageUrl;
110 111
//}

112 113 114
//-----------------------------------------------------------------------------------
// Chart translate
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
115
/** @constructor */
116
function asc_CChartTranslate() {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
117 118 119 120 121

    this.title = "Diagram Title";
    this.xAxis = "X Axis";
    this.yAxis = "Y Axis";
    this.series = "Series";
122 123 124
}

asc_CChartTranslate.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
125 126 127 128 129 130 131 132 133 134 135 136

    asc_getTitle: function() { return this.title; },
    asc_setTitle: function(val) { this.title = val; },

    asc_getXAxis: function() { return this.xAxis; },
    asc_setXAxis: function(val) { this.xAxis = val; },

    asc_getYAxis: function() { return this.yAxis; },
    asc_setYAxis: function(val) { this.yAxis = val; },

    asc_getSeries: function() { return this.series; },
    asc_setSeries: function(val) { this.series = val; }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
137
};
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156

//{ asc_CChartTranslate export
window["Asc"].asc_CChartTranslate = asc_CChartTranslate;
window["Asc"]["asc_CChartTranslate"] = asc_CChartTranslate;
prot = asc_CChartTranslate.prototype;

prot["asc_getTitle"] = prot.asc_getTitle;
prot["asc_setTitle"] = prot.asc_setTitle;

prot["asc_getXAxis"] = prot.asc_getXAxis;
prot["asc_setXAxis"] = prot.asc_setXAxis;

prot["asc_getYAxis"] = prot.asc_getYAxis;
prot["asc_setYAxis"] = prot.asc_setYAxis;

prot["asc_getSeries"] = prot.asc_getSeries;
prot["asc_setSeries"] = prot.asc_setSeries;
//}

Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
157 158 159
//-----------------------------------------------------------------------------------
// Chart binary
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
160
/** @constructor */
Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
161
function asc_CChartBinary(chart) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
162 163

    this["binary"] = null;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
164 165
    if (chart && chart.getObjectType() === historyitem_type_ChartSpace)
    {
166
        var writer = new BinaryChartWriter(new CMemory(false)), pptx_writer;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
167 168
        writer.WriteCT_ChartSpace(chart);
        this["binary"] = writer.memory.pos + ";" + writer.memory.GetBase64Memory();
169 170
        if(chart.theme)
        {
171
            pptx_writer = new CBinaryFileWriter();
172 173 174
            pptx_writer.WriteTheme(chart.theme);
            this["themeBinary"] = pptx_writer.pos + ";" + pptx_writer.GetBase64Memory();
        }
175 176 177 178 179 180
        if(chart.colorMap)
        {
            pptx_writer = new CBinaryFileWriter();
            pptx_writer.WriteClrMap(chart.colorMap);
            this["colorMapBinary"] = pptx_writer.pos + ";" + pptx_writer.GetBase64Memory();
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
181
    }
Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
182 183 184
}

asc_CChartBinary.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
185 186

    asc_getBinary: function() { return this["binary"]; },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
187
    asc_setBinary: function(val) { this["binary"] = val; },
188 189
    asc_getThemeBinary: function() { return this["themeBinary"]; },
    asc_setThemeBinary: function(val) { this["themeBinary"] = val; },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
190 191 192 193 194 195 196 197
    getChartSpace: function(workSheet)
    {
        var binary = this["binary"];
        var stream = CreateBinaryReader(this["binary"], 0, this["binary"].length);
        var oNewChartSpace = new CChartSpace();
        var oBinaryChartReader = new BinaryChartReader(stream);
        oBinaryChartReader.ExternalReadCT_ChartSpace(stream.size , oNewChartSpace, workSheet);
        return oNewChartSpace;
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
    },

    getTheme: function()
    {
        var binary = this["themeBinary"];
        if(binary)
        {
            var stream = CreateBinaryReader(binary, 0, binary.length);
            var oBinaryReader = new BinaryPPTYLoader();

            oBinaryReader.stream = new FileStream();
            oBinaryReader.stream.obj    = stream.obj;
            oBinaryReader.stream.data   = stream.data;
            oBinaryReader.stream.size   = stream.size;
            oBinaryReader.stream.pos    = stream.pos;
            oBinaryReader.stream.cur    = stream.cur;
            return oBinaryReader.ReadTheme();
        }
        return null;
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
    },

    getColorMap: function()
    {
        var binary = this["colorMapBinary"];
        if(binary)
        {
            var stream = CreateBinaryReader(binary, 0, binary.length);
            var oBinaryReader = new BinaryPPTYLoader();

            oBinaryReader.stream = new FileStream();
            oBinaryReader.stream.obj    = stream.obj;
            oBinaryReader.stream.data   = stream.data;
            oBinaryReader.stream.size   = stream.size;
            oBinaryReader.stream.pos    = stream.pos;
            oBinaryReader.stream.cur    = stream.cur;
            var ret = new ClrMap();
            oBinaryReader.ReadClrMap(ret);
            return ret;
        }
        return null;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
238 239
    }

Alexander.Trofimov's avatar
Alexander.Trofimov committed
240
};
Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
241 242 243 244 245 246 247 248

//{ asc_CChartBinary export
window["Asc"].asc_CChartBinary = asc_CChartBinary;
window["Asc"]["asc_CChartBinary"] = asc_CChartBinary;
prot = asc_CChartBinary.prototype;

prot["asc_getBinary"] = prot.asc_getBinary;
prot["asc_setBinary"] = prot.asc_setBinary;
249 250
prot["asc_getThemeBinary"] = prot.asc_getThemeBinary;
prot["asc_setThemeBinary"] = prot.asc_setThemeBinary;
251
//}
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
252 253 254 255

//-----------------------------------------------------------------------------------
// Chart series
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
256
/** @constructor */
257
function asc_CChartSeria() {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
258 259 260 261 262 263 264
    this.Val = { Formula: "", NumCache: [] };
    this.xVal = { Formula: "", NumCache: [] };
    this.Cat = { Formula: "", NumCache: [] };
    this.TxCache = { Formula: "", Tx: "" };
    this.Marker = { Size: 0, Symbol: "" };
    this.FormatCode = "";
    this.isHidden = false;
265
}
266

267
asc_CChartSeria.prototype = {
268

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
269 270
    asc_getValFormula: function() { return this.Val.Formula; },
    asc_setValFormula: function(formula) { this.Val.Formula = formula; },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
271

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
    asc_getxValFormula: function() { return this.xVal.Formula; },
    asc_setxValFormula: function(formula) { this.xVal.Formula = formula; },

    asc_getCatFormula: function() { return this.Cat.Formula; },
    asc_setCatFormula: function(formula) { this.Cat.Formula = formula; },

    asc_getTitle: function() { return this.TxCache.Tx; },
    asc_setTitle: function(title) { this.TxCache.Tx = title; },

    asc_getTitleFormula: function() { return this.TxCache.Formula; },
    asc_setTitleFormula: function(val) { this.TxCache.Formula = val; },

    asc_getMarkerSize: function() { return this.Marker.Size; },
    asc_setMarkerSize: function(size) { this.Marker.Size = size; },

    asc_getMarkerSymbol: function() { return this.Marker.Symbol; },
    asc_setMarkerSymbol: function(symbol) { this.Marker.Symbol = symbol; },

    asc_getFormatCode: function() { return this.FormatCode; },
    asc_setFormatCode: function(format) { this.FormatCode = format; }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
292
};
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
293 294

//{ asc_CChartSeria export
295 296 297 298 299 300
window["Asc"].asc_CChartSeria = asc_CChartSeria;
window["Asc"]["asc_CChartSeria"] = asc_CChartSeria;
prot = asc_CChartSeria.prototype;

prot["asc_getValFormula"] = prot.asc_getValFormula;
prot["asc_setValFormula"] = prot.asc_setValFormula;
301

302 303
prot["asc_getxValFormula"] = prot.asc_getxValFormula;
prot["asc_setxValFormula"] = prot.asc_setxValFormula;
304

305 306 307
prot["asc_getCatFormula"] = prot.asc_getCatFormula;
prot["asc_setCatFormula"] = prot.asc_setCatFormula;

308 309
prot["asc_getTitle"] = prot.asc_getTitle;
prot["asc_setTitle"] = prot.asc_setTitle;
310

311 312 313
prot["asc_getTitleFormula"] = prot.asc_getTitleFormula;
prot["asc_setTitleFormula"] = prot.asc_setTitleFormula;

314 315
prot["asc_getMarkerSize"] = prot.asc_getMarkerSize;
prot["asc_setMarkerSize"] = prot.asc_setMarkerSize;
316

317 318
prot["asc_getMarkerSymbol"] = prot.asc_getMarkerSymbol;
prot["asc_setMarkerSymbol"] = prot.asc_setMarkerSymbol;
319

Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
320
prot["asc_getFormatCode"] = prot.asc_getFormatCode;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
321
prot["asc_setFormatCode"] = prot.asc_setFormatCode;
322
//}
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
323

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
324

325 326 327
//-----------------------------------------------------------------------------------
// Selected graphic object(properties)
//-----------------------------------------------------------------------------------	
Alexander.Trofimov's avatar
Alexander.Trofimov committed
328
/** @constructor */
329
function asc_CSelectedObject( type, val ) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
330 331
    this.Type = (undefined != type) ? type : null;
    this.Value = (undefined != val) ? val : null;
332 333 334
}

asc_CSelectedObject.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
335 336
    asc_getObjectType: function() { return this.Type; },
    asc_getObjectValue: function() { return this.Value; }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
337
};
338 339 340 341 342 343 344 345 346 347 348 349 350

//{ asc_CSelectedObject export
window["Asc"].asc_CSelectedObject = asc_CSelectedObject;
window["Asc"]["asc_CSelectedObject"] = asc_CSelectedObject;
prot = asc_CSelectedObject.prototype;

prot["asc_getObjectType"] = prot.asc_getObjectType;
prot["asc_getObjectValue"] = prot.asc_getObjectValue;
//}

//-----------------------------------------------------------------------------------
// CImgProperty
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
351
/** @constructor */
352
function asc_CImgProperty( obj ) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
353 354

    if( obj ) {
355 356
        this.CanBeFlow = (undefined != obj.CanBeFlow) ? obj.CanBeFlow : true;

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
357 358 359 360 361
        this.Width         = (undefined != obj.Width        ) ? obj.Width                          : undefined;
        this.Height        = (undefined != obj.Height       ) ? obj.Height                         : undefined;
        this.WrappingStyle = (undefined != obj.WrappingStyle) ? obj.WrappingStyle                  : undefined;
        this.Paddings      = (undefined != obj.Paddings     ) ? new CPaddings (obj.Paddings)       : undefined;
        this.Position      = (undefined != obj.Position     ) ? new CPosition (obj.Position)       : undefined;
362 363 364 365 366 367
        this.AllowOverlap  = (undefined != obj.AllowOverlap ) ? obj.AllowOverlap                   : undefined;
        this.PositionH     = (undefined != obj.PositionH    ) ? new CImagePositionH(obj.PositionH) : undefined;
        this.PositionV     = (undefined != obj.PositionV    ) ? new CImagePositionV(obj.PositionV) : undefined;

        this.Internal_Position = (undefined != obj.Internal_Position) ? obj.Internal_Position : null;

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
368
        this.ImageUrl = (undefined != obj.ImageUrl) ? obj.ImageUrl : null;
369 370 371 372 373 374 375 376 377 378 379 380 381 382
        this.Locked   = (undefined != obj.Locked) ? obj.Locked : false;


        this.ChartProperties = (undefined != obj.ChartProperties) ? obj.ChartProperties : null;
        this.ShapeProperties = (undefined != obj.ShapeProperties) ? /*CreateAscShapePropFromProp*/(obj.ShapeProperties) : null;

        this.ChangeLevel = (undefined != obj.ChangeLevel) ? obj.ChangeLevel : null;
        this.Group = (obj.Group != undefined) ? obj.Group : null;

        this.fromGroup = obj.fromGroup != undefined ? obj.fromGroup : null;
        this.severalCharts = obj.severalCharts != undefined ? obj.severalCharts : false;
        this.severalChartTypes = obj.severalChartTypes != undefined ? obj.severalChartTypes : undefined;
        this.severalChartStyles = obj.severalChartStyles != undefined ? obj.severalChartStyles : undefined;
        this.verticalTextAlign = obj.verticalTextAlign != undefined ? obj.verticalTextAlign : undefined;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
383 384
    }
    else {
385
        this.CanBeFlow = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
386 387 388 389 390
        this.Width         = undefined;
        this.Height        = undefined;
        this.WrappingStyle = undefined;
        this.Paddings      = undefined;
        this.Position      = undefined;
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
        this.PositionH     = undefined;
        this.PositionV     = undefined;
        this.Internal_Position = null;
        this.ImageUrl = null;
        this.Locked   = false;

        this.ChartProperties = null;
        this.ShapeProperties = null;
        this.ImageProperties = null;

        this.ChangeLevel = null;
        this.Group = null;
        this.fromGroup = null;
        this.severalCharts = false;
        this.severalChartTypes = undefined;
        this.severalChartStyles = undefined;
        this.verticalTextAlign = undefined;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
408
    }
409
}
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
410

411
asc_CImgProperty.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466

    asc_getChangeLevel: function() { return this.ChangeLevel; },
    asc_putChangeLevel: function(v) { this.ChangeLevel = v; },

    asc_getCanBeFlow: function() { return this.CanBeFlow; },
    asc_getWidth: function() { return this.Width; },
    asc_putWidth: function(v) { this.Width = v; },
    asc_getHeight: function() { return this.Height; },
    asc_putHeight: function(v) { this.Height = v; },
    asc_getWrappingStyle: function() { return this.WrappingStyle; },
    asc_putWrappingStyle: function(v) { this.WrappingStyle = v; },

    // Возвращается объект класса CPaddings
    asc_getPaddings: function() { return this.Paddings; },
    // Аргумент объект класса CPaddings
    asc_putPaddings: function(v) { this.Paddings = v; },
    asc_getAllowOverlap: function() {return this.AllowOverlap;},
    asc_putAllowOverlap: function(v) {this.AllowOverlap = v;},
    // Возвращается объект класса CPosition
    asc_getPosition: function() { return this.Position; },
    // Аргумент объект класса CPosition
    asc_putPosition: function(v) { this.Position = v; },
    asc_getPositionH: function()  { return this.PositionH; },
    asc_putPositionH: function(v) { this.PositionH = v; },
    asc_getPositionV: function()  { return this.PositionV; },
    asc_putPositionV: function(v) { this.PositionV = v; },
    asc_getValue_X: function(RelativeFrom) { if ( null != this.Internal_Position ) return this.Internal_Position.Calculate_X_Value(RelativeFrom);  return 0; },
    asc_getValue_Y: function(RelativeFrom) { if ( null != this.Internal_Position ) return this.Internal_Position.Calculate_Y_Value(RelativeFrom);  return 0; },

    asc_getImageUrl: function() { return this.ImageUrl; },
    asc_putImageUrl: function(v) { this.ImageUrl = v; },
    asc_getGroup: function() { return this.Group; },
    asc_putGroup: function(v) { this.Group = v; },
    asc_getFromGroup: function() { return this.fromGroup; },
    asc_putFromGroup: function(v) { this.fromGroup = v; },

    asc_getisChartProps: function() { return this.isChartProps; },
    asc_putisChartPross: function(v) { this.isChartProps = v; },

    asc_getSeveralCharts: function() { return this.severalCharts; },
    asc_putSeveralCharts: function(v) { this.severalCharts = v; },
    asc_getSeveralChartTypes: function() { return this.severalChartTypes; },
    asc_putSeveralChartTypes: function(v) { this.severalChartTypes = v; },

    asc_getSeveralChartStyles: function() { return this.severalChartStyles; },
    asc_putSeveralChartStyles: function(v) { this.severalChartStyles = v; },

    asc_getVerticalTextAlign: function() { return this.verticalTextAlign; },
    asc_putVerticalTextAlign: function(v) { this.verticalTextAlign = v; },

    asc_getLocked: function() { return this.Locked; },
    asc_getChartProperties: function() { return this.ChartProperties; },
    asc_putChartProperties: function(v) { this.ChartProperties = v; },
    asc_getShapeProperties: function() { return this.ShapeProperties; },
    asc_putShapeProperties: function(v) { this.ShapeProperties = v; }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
467
};
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505

//{ asc_CImgProperty export
window["Asc"].asc_CImgProperty = asc_CImgProperty;
window["Asc"]["asc_CImgProperty"] = asc_CImgProperty;
prot = asc_CImgProperty.prototype;

prot["asc_getChangeLevel"] = prot.asc_getChangeLevel;
prot["asc_putChangeLevel"] = prot.asc_putChangeLevel;

prot["asc_getCanBeFlow"] = prot.asc_getCanBeFlow;
prot["asc_getWidth"] = prot.asc_getWidth;
prot["asc_putWidth"] = prot.asc_putWidth;
prot["asc_getHeight"] = prot.asc_getHeight;
prot["asc_putHeight"] = prot.asc_putHeight;
prot["asc_getWrappingStyle"] = prot.asc_getWrappingStyle;
prot["asc_putWrappingStyle"] = prot.asc_putWrappingStyle;

prot["asc_getPaddings"] = prot.asc_getPaddings;
prot["asc_putPaddings"] = prot.asc_putPaddings;
prot["asc_getAllowOverlap"] = prot.asc_getAllowOverlap;
prot["asc_putAllowOverlap"] = prot.asc_putAllowOverlap;
prot["asc_getPosition"] = prot.asc_getPosition;
prot["asc_putPosition"] = prot.asc_putPosition;
prot["asc_getPositionH"] = prot.asc_getPositionH;
prot["asc_putPositionH"] = prot.asc_putPositionH;
prot["asc_getPositionV"] = prot.asc_getPositionV;
prot["asc_putPositionV"] = prot.asc_putPositionV;
prot["asc_getValue_X"] = prot.asc_getValue_X;
prot["asc_getValue_Y"] = prot.asc_getValue_Y;

prot["asc_getImageUrl"] = prot.asc_getImageUrl;
prot["asc_putImageUrl"] = prot.asc_putImageUrl;
prot["asc_getGroup"] = prot.asc_getGroup;
prot["asc_putGroup"] = prot.asc_putGroup;
prot["asc_getFromGroup"] = prot.asc_getFromGroup;
prot["asc_putFromGroup"] = prot.asc_putFromGroup;
prot["asc_getisChartProps"] = prot.asc_getisChartProps;
prot["asc_putisChartPross"] = prot.asc_putisChartPross;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
506

507 508 509 510 511 512 513 514 515 516 517 518 519 520
prot["asc_getSeveralCharts"] = prot.asc_getSeveralCharts;
prot["asc_putSeveralCharts"] = prot.asc_putSeveralCharts;
prot["asc_getSeveralChartTypes"] = prot.asc_getSeveralChartTypes;
prot["asc_putSeveralChartTypes"] = prot.asc_putSeveralChartTypes;
prot["asc_getSeveralChartStyles"] = prot.asc_getSeveralChartStyles;
prot["asc_putSeveralChartStyles"] = prot.asc_putSeveralChartStyles;
prot["asc_getVerticalTextAlign"] = prot.asc_getVerticalTextAlign;
prot["asc_putVerticalTextAlign"] = prot.asc_putVerticalTextAlign;
prot["asc_getLocked"] = prot.asc_getLocked;
prot["asc_getChartProperties"] = prot.asc_getChartProperties;
prot["asc_putChartProperties"] = prot.asc_putChartProperties;
prot["asc_getShapeProperties"] = prot.asc_getShapeProperties;
prot["asc_putShapeProperties"] = prot.asc_putShapeProperties;
//}
521

522 523 524
//-----------------------------------------------------------------------------------
// CShapeProperty
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
525
/** @constructor */
526 527 528 529
function asc_CShapeProperty() {
    this.type = null; // custom
    this.fill = null;
    this.stroke = null;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
530
    this.paddings = null;
531
    this.canFill = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
532
    this.canChangeArrows = false;
533
    this.bFromChart = false;
534 535 536
}

asc_CShapeProperty.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
537 538 539 540 541 542 543

    asc_getType: function() { return this.type; },
    asc_putType: function(v) { this.type = v; },
    asc_getFill: function() { return this.fill; },
    asc_putFill: function(v) { this.fill = v; },
    asc_getStroke: function() { return this.stroke; },
    asc_putStroke: function(v) { this.stroke = v; },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
544
    asc_getPaddings: function() { return this.paddings; },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
545
    asc_putPaddings: function(v) { this.paddings = v; },
Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
546 547
    asc_getCanFill: function() { return this.canFill; },
    asc_putCanFill: function(v) { this.canFill = v; },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
548
    asc_getCanChangeArrows: function() { return this.canChangeArrows; },
549 550 551
    asc_setCanChangeArrows: function(v) { this.canChangeArrows = v; },
    asc_getFromChart: function() { return this.bFromChart; },
    asc_setFromChart: function(v) { this.bFromChart = v; }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
552
};
553 554 555 556 557 558 559 560 561 562 563 564

//{ asc_CShapeProperty export
window["Asc"].asc_CShapeProperty = asc_CShapeProperty;
window["Asc"]["asc_CShapeProperty"] = asc_CShapeProperty;
prot = asc_CShapeProperty.prototype;

prot["asc_getType"] = prot.asc_getType;
prot["asc_putType"] = prot.asc_putType;
prot["asc_getFill"] = prot.asc_getFill;
prot["asc_putFill"] = prot.asc_putFill;
prot["asc_getStroke"] = prot.asc_getStroke;
prot["asc_putStroke"] = prot.asc_putStroke;
Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
565 566
prot["asc_getPaddings"] = prot.asc_getPaddings;
prot["asc_putPaddings"] = prot.asc_putPaddings;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
567 568
prot["asc_getCanFill"] = prot.asc_getCanFill;
prot["asc_putCanFill"] = prot.asc_putCanFill;
Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
569 570
prot["asc_getCanChangeArrows"] = prot.asc_getCanChangeArrows;
prot["asc_setCanChangeArrows"] = prot.asc_setCanChangeArrows;
571 572
prot["asc_getFromChart"] = prot.asc_getFromChart;
prot["asc_setFromChart"] = prot.asc_setFromChart;
573 574
//}

575 576 577
//-----------------------------------------------------------------------------------
// CPaddings
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
578
/** @constructor */
579
function asc_CPaddings(obj) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
580 581

    if ( obj ) {
582 583 584 585 586 587 588 589 590 591 592 593 594 595
        this.Left = (undefined == obj.Left) ? null : obj.Left;
        this.Top = (undefined == obj.Top) ? null : obj.Top;
        this.Bottom = (undefined == obj.Bottom) ? null : obj.Bottom;
        this.Right = (undefined == obj.Right) ? null : obj.Right;
    }
    else {
        this.Left = null;
        this.Top = null;
        this.Bottom = null;
        this.Right = null;
    }
}

asc_CPaddings.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
596 597 598 599 600 601 602 603
    asc_getLeft: function() { return this.Left; },
    asc_putLeft: function(v) { this.Left = v; },
    asc_getTop: function() { return this.Top; },
    asc_putTop: function(v) { this.Top = v; },
    asc_getBottom: function() { return this.Bottom; },
    asc_putBottom: function(v) { this.Bottom = v; },
    asc_getRight: function() { return this.Right; },
    asc_putRight: function(v) { this.Right = v; }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
604
};
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620

//{ asc_CPaddings export
window["Asc"].asc_CPaddings = asc_CPaddings;
window["Asc"]["asc_CPaddings"] = asc_CPaddings;
prot = asc_CPaddings.prototype;

prot["asc_getLeft"] = prot.asc_getLeft;
prot["asc_putLeft"] = prot.asc_putLeft;
prot["asc_getTop"] = prot.asc_getTop;
prot["asc_putTop"] = prot.asc_putTop;
prot["asc_getBottom"] = prot.asc_getBottom;
prot["asc_putBottom"] = prot.asc_putBottom;
prot["asc_getRight"] = prot.asc_getRight;
prot["asc_putRight"] = prot.asc_putRight;
//}

621 622 623
//-----------------------------------------------------------------------------------
// CImageSize
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
624
/** @constructor */
625
function asc_CImageSize( width, height, isCorrect ) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
626 627
    this.Width = (undefined == width) ? 0.0 : width;
    this.Height = (undefined == height) ? 0.0 : height;
628 629 630 631
    this.IsCorrect = isCorrect;
}

asc_CImageSize.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
632 633 634 635

    asc_getImageWidth: function() { return this.Width; },
    asc_getImageHeight: function() { return this.Height; },
    asc_getIsCorrect: function() { return this.IsCorrect; }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
636
};
637 638 639 640 641 642 643 644 645 646 647

//{ asc_CImageSize export
window["Asc"].asc_CImageSize = asc_CImageSize;
window["Asc"]["asc_CImageSize"] = asc_CImageSize;
prot = asc_CImageSize.prototype;

prot["asc_getImageWidth"] = prot.asc_getImageWidth;
prot["asc_getImageHeight"] = prot.asc_getImageHeight;
prot["asc_getIsCorrect"] = prot.asc_getIsCorrect;
//}

Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
648 649 650
//-----------------------------------------------------------------------------------
// CTexture
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
651
/** @constructor */
Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
652 653 654 655 656 657
function asc_CTexture() {
    this.Id = 0;
    this.Image = "";
}

asc_CTexture.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
658 659
    asc_getId: function() { return this.Id; },
    asc_getImage: function() { return this.Image; }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
660
};
Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
661 662 663 664 665 666 667 668 669 670

//{ asc_CTexture export
window["Asc"].asc_CTexture = asc_CTexture;
window["Asc"]["asc_CTexture"] = asc_CTexture;
prot = asc_CTexture.prototype;

prot["asc_getId"] = prot.asc_getId;
prot["asc_getImage"] = prot.asc_getImage;
//}

671 672 673
//-----------------------------------------------------------------------------------
// CParagraphProperty
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
674
/** @constructor */
675
function asc_CParagraphProperty(obj) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
676 677 678 679 680

    if (obj) {
        this.ContextualSpacing = (undefined != obj.ContextualSpacing)              ? obj.ContextualSpacing : null;
        this.Ind               = (undefined != obj.Ind     && null != obj.Ind)     ? new asc_CParagraphInd (obj.Ind) : null;
        this.KeepLines         = (undefined != obj.KeepLines)                      ? obj.KeepLines : null;
681 682
        this.KeepNext          = (undefined != obj.KeepNext)                       ? obj.KeepNext  : undefined;
        this.WidowControl      = (undefined != obj.WidowControl                    ? obj.WidowControl : undefined );
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
683 684 685 686
        this.PageBreakBefore   = (undefined != obj.PageBreakBefore)                ? obj.PageBreakBefore : null;
        this.Spacing           = (undefined != obj.Spacing && null != obj.Spacing) ? new asc_CParagraphSpacing (obj.Spacing) : null;
        this.Brd               = (undefined != obj.Brd     && null != obj.Brd)     ? new asc_CParagraphBorders (obj.Brd) : null;
        this.Shd               = (undefined != obj.Shd     && null != obj.Shd)     ? new asc_CParagraphShd (obj.Shd) : null;
687 688 689 690 691 692 693 694 695 696 697 698 699
        this.Tabs              = (undefined != obj.Tabs)                           ? new asc_CParagraphTabs(obj.Tabs) : undefined;
        this.DefaultTab        = Default_Tab_Stop;
        this.Locked            = (undefined != obj.Locked  && null != obj.Locked ) ? obj.Locked : false;
        this.CanAddTable       = (undefined != obj.CanAddTable )                   ? obj.CanAddTable : true;

        this.Subscript         = (undefined != obj.Subscript)                      ? obj.Subscript : undefined;
        this.Superscript       = (undefined != obj.Superscript)                    ? obj.Superscript : undefined;
        this.SmallCaps         = (undefined != obj.SmallCaps)                      ? obj.SmallCaps : undefined;
        this.AllCaps           = (undefined != obj.AllCaps)                        ? obj.AllCaps : undefined;
        this.Strikeout         = (undefined != obj.Strikeout)                      ? obj.Strikeout : undefined;
        this.DStrikeout        = (undefined != obj.DStrikeout)                     ? obj.DStrikeout : undefined;
        this.TextSpacing       = (undefined != obj.TextSpacing)                    ? obj.TextSpacing : undefined;
        this.Position          = (undefined != obj.Position)                       ? obj.Position : undefined;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
    }
    else {
        //ContextualSpacing : false,            // Удалять ли интервал между параграфами одинакового стиля
        //
        //    Ind :
        //    {
        //        Left      : 0,                    // Левый отступ
        //        Right     : 0,                    // Правый отступ
        //        FirstLine : 0                     // Первая строка
        //    },
        //
        //    Jc : align_Left,                      // Прилегание параграфа
        //
        //    KeepLines : false,                    // переносить параграф на новую страницу,
        //                                          // если на текущей он целиком не убирается
        //    KeepNext  : false,                    // переносить параграф вместе со следующим параграфом
        //
        //    PageBreakBefore : false,              // начинать параграф с новой страницы

        this.ContextualSpacing = undefined;
        this.Ind               = new asc_CParagraphInd();
        this.KeepLines         = undefined;
722 723
        this.KeepNext          = undefined;
        this.WidowControl      = undefined;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
724 725 726
        this.PageBreakBefore   = undefined;
        this.Spacing           = new asc_CParagraphSpacing();
        this.Brd               = undefined;
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
        this.Shd               = undefined;
        this.Locked            = false;
        this.CanAddTable       = true;
        this.Tabs              = undefined;

        this.Subscript         = undefined;
        this.Superscript       = undefined;
        this.SmallCaps         = undefined;
        this.AllCaps           = undefined;
        this.Strikeout         = undefined;
        this.DStrikeout        = undefined;
        this.TextSpacing       = undefined;
        this.Position          = undefined;
    }
}

asc_CParagraphProperty.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784

    asc_getContextualSpacing: function () { return this.ContextualSpacing; },
    asc_putContextualSpacing: function (v) { this.ContextualSpacing = v; },
    asc_getInd: function () { return this.Ind; },
    asc_putInd: function (v) { this.Ind = v; },
    asc_getKeepLines: function () { return this.KeepLines; },
    asc_putKeepLines: function (v) { this.KeepLines = v; },
    asc_getKeepNext: function () { return this.KeepNext; },
    asc_putKeepNext: function (v) { this.KeepNext = v; },
    asc_getPageBreakBefore: function (){ return this.PageBreakBefore; },
    asc_putPageBreakBefore: function (v){ this.PageBreakBefore = v; },
    asc_getWidowControl: function (){ return this.WidowControl; },
    asc_putWidowControl: function (v){ this.WidowControl = v; },
    asc_getSpacing: function () { return this.Spacing; },
    asc_putSpacing: function (v) { this.Spacing = v; },
    asc_getBorders: function () { return this.Brd; },
    asc_putBorders: function (v) { this.Brd = v; },
    asc_getShade: function () { return this.Shd; },
    asc_putShade: function (v) { this.Shd = v; },
    asc_getLocked: function() { return this.Locked; },
    asc_getCanAddTable: function() { return this.CanAddTable; },
    asc_getSubscript: function () { return this.Subscript; },
    asc_putSubscript: function (v) { this.Subscript = v; },
    asc_getSuperscript: function () { return this.Superscript; },
    asc_putSuperscript: function (v) { this.Superscript = v; },
    asc_getSmallCaps: function () { return this.SmallCaps; },
    asc_putSmallCaps: function (v) { this.SmallCaps = v; },
    asc_getAllCaps: function () { return this.AllCaps; },
    asc_putAllCaps: function (v) { this.AllCaps = v; },
    asc_getStrikeout: function () { return this.Strikeout; },
    asc_putStrikeout: function (v) { this.Strikeout = v; },
    asc_getDStrikeout: function () { return this.DStrikeout; },
    asc_putDStrikeout: function (v) { this.DStrikeout = v; },
    asc_getTextSpacing: function () { return this.TextSpacing; },
    asc_putTextSpacing: function (v) { this.TextSpacing = v; },
    asc_getPosition: function () { return this.Position; },
    asc_putPosition: function (v) { this.Position = v; },
    asc_getTabs: function () { return this.Tabs; },
    asc_putTabs: function (v) { this.Tabs = v; },
    asc_getDefaultTab: function () { return this.DefaultTab; },
    asc_putDefaultTab: function (v) { this.DefaultTab = v; }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
785
};
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836

//{ asc_CParagraphProperty export
window["Asc"].asc_CParagraphProperty = asc_CParagraphProperty;
window["Asc"]["asc_CParagraphProperty"] = asc_CParagraphProperty;
prot = asc_CParagraphProperty.prototype;

prot["asc_getContextualSpacing"] = prot.asc_getContextualSpacing;
prot["asc_putContextualSpacing"] = prot.asc_putContextualSpacing;
prot["asc_getInd"] = prot.asc_getInd;
prot["asc_putInd"] = prot.asc_putInd;
prot["asc_getKeepLines"] = prot.asc_getKeepLines;
prot["asc_putKeepLines"] = prot.asc_putKeepLines;
prot["asc_getKeepNext"] = prot.asc_getKeepNext;
prot["asc_putKeepNext"] = prot.asc_putKeepNext;
prot["asc_getPageBreakBefore"] = prot.asc_getPageBreakBefore;
prot["asc_putPageBreakBefore"] = prot.asc_putPageBreakBefore;
prot["asc_getWidowControl"] = prot.asc_getWidowControl;
prot["asc_putWidowControl"] = prot.asc_putWidowControl;
prot["asc_getSpacing"] = prot.asc_getSpacing;
prot["asc_putSpacing"] = prot.asc_putSpacing;
prot["asc_getBorders"] = prot.asc_getBorders;
prot["asc_putBorders"] = prot.asc_putBorders;
prot["asc_getShade"] = prot.asc_getShade;
prot["asc_putShade"] = prot.asc_putShade;
prot["asc_getLocked"] = prot.asc_getLocked;
prot["asc_getCanAddTable"] = prot.asc_getCanAddTable;
prot["asc_getSubscript"] = prot.asc_getSubscript;
prot["asc_putSubscript"] = prot.asc_putSubscript;
prot["asc_getSuperscript"] = prot.asc_getSuperscript;
prot["asc_putSuperscript"] = prot.asc_putSuperscript;
prot["asc_getSmallCaps"] = prot.asc_getSmallCaps;
prot["asc_putSmallCaps"] = prot.asc_putSmallCaps;
prot["asc_getAllCaps"] = prot.asc_getAllCaps;
prot["asc_putAllCaps"] = prot.asc_putAllCaps;
prot["asc_getStrikeout"] = prot.asc_getStrikeout;
prot["asc_putStrikeout"] = prot.asc_putStrikeout;
prot["asc_getDStrikeout"] = prot.asc_getDStrikeout;
prot["asc_putDStrikeout"] = prot.asc_putDStrikeout;
prot["asc_getTextSpacing"] = prot.asc_getTextSpacing;
prot["asc_putTextSpacing"] = prot.asc_putTextSpacing;
prot["asc_getPosition"] = prot.asc_getPosition;
prot["asc_putPosition"] = prot.asc_putPosition;
prot["asc_getTabs"] = prot.asc_getTabs;
prot["asc_putTabs"] = prot.asc_putTabs;
prot["asc_getDefaultTab"] = prot.asc_getDefaultTab;
prot["asc_putDefaultTab"] = prot.asc_putDefaultTab;
//}

//-----------------------------------------------------------------------------------
// CParagraphInd
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
837
/** @constructor */
838
function asc_CParagraphInd(obj) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
839 840 841 842 843 844 845 846 847 848
    if (obj) {
        this.Left      = (undefined != obj.Left     ) ? obj.Left      : null; // Левый отступ
        this.Right     = (undefined != obj.Right    ) ? obj.Right     : null; // Правый отступ
        this.FirstLine = (undefined != obj.FirstLine) ? obj.FirstLine : null; // Первая строка
    }
    else {
        this.Left      = undefined; // Левый отступ
        this.Right     = undefined; // Правый отступ
        this.FirstLine = undefined; // Первая строка
    }
849 850 851
}

asc_CParagraphInd.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
852 853 854 855 856 857
    asc_getLeft: function () { return this.Left; },
    asc_putLeft: function (v) { this.Left = v; },
    asc_getRight: function () { return this.Right; },
    asc_putRight: function (v) { this.Right = v; },
    asc_getFirstLine: function () { return this.FirstLine; },
    asc_putFirstLine: function (v) { this.FirstLine = v; }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
858
};
859 860 861 862 863 864 865 866 867 868 869

//{ asc_CParagraphInd export
window["Asc"].asc_CParagraphInd = asc_CParagraphInd;
window["Asc"]["asc_CParagraphInd"] = asc_CParagraphInd;
prot = asc_CParagraphInd.prototype;

prot["asc_getLeft"] = prot.asc_getLeft;
prot["asc_putLeft"] = prot.asc_putLeft;
prot["asc_getRight"] = prot.asc_getRight;
prot["asc_putRight"] = prot.asc_putRight;
prot["asc_getFirstLine"] = prot.asc_getFirstLine;
870
prot["asc_putFirstLine"] = prot.asc_putFirstLine;
871 872 873 874 875
//}

//-----------------------------------------------------------------------------------
// CParagraphSpacing
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
876
/** @constructor */
877
function asc_CParagraphSpacing(obj) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
878 879 880 881 882 883 884 885 886 887 888 889 890

    if (obj) {
        this.Line     = (undefined != obj.Line    ) ? obj.Line     : null; // Расстояние между строками внутри абзаца
        this.LineRule = (undefined != obj.LineRule) ? obj.LineRule : null; // Тип расстрояния между строками
        this.Before   = (undefined != obj.Before  ) ? obj.Before   : null; // Дополнительное расстояние до абзаца
        this.After    = (undefined != obj.After   ) ? obj.After    : null; // Дополнительное расстояние после абзаца
    }
    else {
        this.Line     = undefined; // Расстояние между строками внутри абзаца
        this.LineRule = undefined; // Тип расстрояния между строками
        this.Before   = undefined; // Дополнительное расстояние до абзаца
        this.After    = undefined; // Дополнительное расстояние после абзаца
    }
891 892 893
}

asc_CParagraphSpacing.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
894 895 896 897
    asc_getLine: function () { return this.Line; },
    asc_getLineRule: function () { return this.LineRule; },
    asc_getBefore: function () { return this.Before; },
    asc_getAfter: function () { return this.After; }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
898
};
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913

//{ asc_CParagraphSpacing export
window["Asc"].asc_CParagraphSpacing = asc_CParagraphSpacing;
window["Asc"]["asc_CParagraphSpacing"] = asc_CParagraphSpacing;
prot = asc_CParagraphSpacing.prototype;

prot["asc_getLine"] = prot.asc_getLine;
prot["asc_getLineRule"] = prot.asc_getLineRule;
prot["asc_getBefore"] = prot.asc_getBefore;
prot["asc_getAfter"] = prot.asc_getAfter;
//}

//-----------------------------------------------------------------------------------
// CParagraphShd
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
914
/** @constructor */
915
function asc_CParagraphShd(obj) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
916 917 918

    if (obj) {
        this.Value = (undefined != obj.Value) ? obj.Value : null;
919 920 921 922 923 924 925 926
        if(obj.Unifill && obj.Unifill.fill && obj.Unifill.fill.type === FILL_TYPE_SOLID && obj.Unifill.fill.color)
        {
            this.Color = CreateAscColor(obj.Unifill.fill.color);
        }
        else
        {
            this.Color = (undefined != obj.Color && null != obj.Color) ? CreateAscColorCustom( obj.Color.r, obj.Color.g, obj.Color.b ) : null;
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
927 928 929 930 931
    }
    else {
        this.Value = shd_Nil;
        this.Color = CreateAscColorCustom(255, 255, 255);
    }
932 933 934
}

asc_CParagraphShd.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
935 936 937 938
    asc_getValue: function (){ return this.Value; },
    asc_putValue: function (v){ this.Value = v; },
    asc_getColor: function (){ return this.Color; },
    asc_putColor: function (v){ this.Color = (v) ? v : null; }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
939
};
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954

//{ asc_CParagraphShd export
window["Asc"].asc_CParagraphShd = asc_CParagraphShd;
window["Asc"]["asc_CParagraphShd"] = asc_CParagraphShd;
prot = asc_CParagraphShd.prototype;

prot["asc_getValue"] = prot.asc_getValue;
prot["asc_putValue"] = prot.asc_putValue;
prot["asc_getColor"] = prot.asc_getColor;
prot["asc_putColor"] = prot.asc_putColor;
//}

//-----------------------------------------------------------------------------------
// CParagraphTab
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
955
/** @constructor */
956 957 958 959 960 961
function asc_CParagraphTab(Pos, Value) {
    this.Pos   = Pos;
    this.Value = Value;
}

asc_CParagraphTab.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
962 963 964 965
    asc_getValue: function (){ return this.Value; },
    asc_putValue: function (v){ this.Value = v; },
    asc_getPos: function (){ return this.Pos; },
    asc_putPos: function (v){ this.Pos = v; }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
966
};
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981

//{ asc_CParagraphTab export
window["Asc"].asc_CParagraphTab = asc_CParagraphTab;
window["Asc"]["asc_CParagraphTab"] = asc_CParagraphTab;
prot = asc_CParagraphTab.prototype;

prot["asc_getValue"] = prot.asc_getValue;
prot["asc_putValue"] = prot.asc_putValue;
prot["asc_getPos"] = prot.asc_getPos;
prot["asc_putPos"] = prot.asc_putPos;
//}

//-----------------------------------------------------------------------------------
// CParagraphTabs
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
982
/** @constructor */
983
function asc_CParagraphTabs(obj) {
Alexander.Trofimov's avatar
Alexander.Trofimov committed
984
    this.Tabs = [];
985 986 987 988 989 990 991 992 993 994 995

    if ( undefined != obj ) {
        var Count = obj.Tabs.length;
        for (var Index = 0; Index < Count; Index++)
        {
            this.Tabs.push( new asc_CParagraphTab(obj.Tabs[Index].Pos, obj.Tabs[Index].Value) );
        }
    }
}

asc_CParagraphTabs.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
996 997 998 999
    asc_getCount: function (){ return this.Tabs.length; },
    asc_getTab: function (Index){ return this.Tabs[Index]; },
    asc_addTab: function (Tab){ this.Tabs.push(Tab) },
    asc_clear: function (){ this.Tabs.length = 0; },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1000
    add_Tab: function (Tab){ this.Tabs.push(Tab) }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1001
};
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011

//{ asc_CParagraphTabs export
window["Asc"].asc_CParagraphTabs = asc_CParagraphTabs;
window["Asc"]["asc_CParagraphTabs"] = asc_CParagraphTabs;
prot = asc_CParagraphTabs.prototype;

prot["asc_getCount"] = prot.asc_getCount;
prot["asc_getTab"] = prot.asc_getTab;
prot["asc_addTab"] = prot.asc_addTab;
prot["asc_clear"] = prot.asc_clear;
1012 1013
prot["add_Tab"] = prot.add_Tab;

1014 1015
//}

1016 1017 1018
//-----------------------------------------------------------------------------------
// CParagraphBorders
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1019
/** @constructor */
1020
function asc_CParagraphBorders(obj) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035

    if (obj) {
        this.Left = (undefined != obj.Left && null != obj.Left) ? new asc_CTextBorder (obj.Left) : null;
        this.Top = (undefined != obj.Top && null != obj.Top) ? new asc_CTextBorder (obj.Top) : null;
        this.Right = (undefined != obj.Right && null != obj.Right) ? new asc_CTextBorder (obj.Right) : null;
        this.Bottom = (undefined != obj.Bottom && null != obj.Bottom) ? new asc_CTextBorder (obj.Bottom) : null;
        this.Between = (undefined != obj.Between && null != obj.Between) ? new asc_CTextBorder (obj.Between) : null;
    }
    else {
        this.Left = null;
        this.Top = null;
        this.Right = null;
        this.Bottom = null;
        this.Between = null;
    }
1036 1037 1038
}

asc_CParagraphBorders.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
    asc_getLeft: function(){return this.Left; },
    asc_putLeft: function(v){this.Left = (v) ? new asc_CTextBorder (v) : null;},
    asc_getTop: function(){return this.Top; },
    asc_putTop: function(v){this.Top = (v) ? new asc_CTextBorder (v) : null;},
    asc_getRight: function(){return this.Right; },
    asc_putRight: function(v){this.Right = (v) ? new asc_CTextBorder (v) : null;},
    asc_getBottom: function(){return this.Bottom; },
    asc_putBottom: function(v){this.Bottom = (v) ? new asc_CTextBorder (v) : null;},
    asc_getBetween: function(){return this.Between; },
    asc_putBetween: function(v){this.Between = (v) ? new asc_CTextBorder (v) : null;}
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1049
};
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070

//{ asc_CParagraphBorders export
window["Asc"].asc_CParagraphBorders = asc_CParagraphBorders;
window["Asc"]["asc_CParagraphBorders"] = asc_CParagraphBorders;
prot = asc_CParagraphBorders.prototype;

prot["asc_getLeft"] = prot.asc_getLeft;
prot["asc_putLeft"] = prot.asc_putLeft;
prot["asc_getTop"] = prot.asc_getTop;
prot["asc_putTop"] = prot.asc_putTop;
prot["asc_getRight"] = prot.asc_getRight;
prot["asc_putRight"] = prot.asc_putRight;
prot["asc_getBottom"] = prot.asc_getBottom;
prot["asc_putBottom"] = prot.asc_putBottom;
prot["asc_getBetween"] = prot.asc_getBetween;
prot["asc_putBetween"] = prot.asc_putBetween;
//}

//-----------------------------------------------------------------------------------
// CBorder
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1071
/** @constructor */
1072
function asc_CTextBorder(obj) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085

    if (obj) {
        this.Color = (undefined != obj.Color && null != obj.Color) ? CreateAscColorCustomEx(obj.Color.r, obj.Color.g, obj.Color.b) : null;
        this.Size = (undefined != obj.Size) ? obj.Size : null;
        this.Value = (undefined != obj.Value) ? obj.Value : null;
        this.Space = (undefined != obj.Space) ? obj.Space : null;
    }
    else {
        this.Color = CreateAscColorCustomEx(0,0,0);
        this.Size  = 0.5 * g_dKoef_pt_to_mm;
        this.Value = border_Single;
        this.Space = 0;
    }
1086 1087
}

1088
asc_CTextBorder.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
    asc_getColor: function(){return this.Color; },
    asc_putColor: function(v){this.Color = v;},
    asc_getSize: function(){return this.Size; },
    asc_putSize: function(v){this.Size = v;},
    asc_getValue: function(){return this.Value; },
    asc_putValue: function(v){this.Value = v;},
    asc_getSpace: function(){return this.Space; },
    asc_putSpace: function(v){this.Space = v;},
    asc_getForSelectedCells: function(){return this.ForSelectedCells; },
    asc_putForSelectedCells: function(v){this.ForSelectedCells = v;}
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1099
};
1100

1101 1102 1103 1104
//{ asc_CTextBorder export
window["Asc"].asc_CTextBorder = asc_CTextBorder;
window["Asc"]["asc_CTextBorder"] = asc_CTextBorder;
prot = asc_CTextBorder.prototype;
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120

prot["asc_getColor"] = prot.asc_getColor;
prot["asc_putColor"] = prot.asc_putColor;
prot["asc_getSize"] = prot.asc_getSize;
prot["asc_putSize"] = prot.asc_putSize;
prot["asc_getValue"] = prot.asc_getValue;
prot["asc_putValue"] = prot.asc_putValue;
prot["asc_getSpace"] = prot.asc_getSpace;
prot["asc_putSpace"] = prot.asc_putSpace;
prot["asc_getForSelectedCells"] = prot.asc_getForSelectedCells;
prot["asc_putForSelectedCells"] = prot.asc_putForSelectedCells;
//}

//-----------------------------------------------------------------------------------
// CListType
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1121
/** @constructor */
1122
function asc_CListType(obj) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1123 1124 1125 1126 1127 1128 1129 1130 1131

    if (obj) {
        this.Type = (undefined == obj.Type) ? null : obj.Type;
        this.SubType = (undefined == obj.Type) ? null : obj.SubType;
    }
    else {
        this.Type = null;
        this.SubType = null;
    }
1132 1133 1134
}

asc_CListType.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1135 1136
    asc_getListType: function() { return this.Type; },
    asc_getListSubType: function() { return this.SubType; }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1137
};
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150

//{ asc_CListType export
window["Asc"].asc_CListType = asc_CListType;
window["Asc"]["asc_CListType"] = asc_CListType;
prot = asc_CListType.prototype;

prot["asc_getListType"] = prot.asc_getListType;
prot["asc_getListSubType"] = prot.asc_getListSubType;
//}

//-----------------------------------------------------------------------------------
// CTextFontFamily
//-----------------------------------------------------------------------------------
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1151
/** @constructor */
1152
function asc_CTextFontFamily(obj) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1153 1154 1155 1156 1157 1158 1159 1160 1161

    if (obj) {
        this.Name = (undefined != obj.Name) ? obj.Name : null; 		// "Times New Roman"
        this.Index = (undefined != obj.Index) ? obj.Index : null;	// -1
    }
    else {
        this.Name = "Times New Roman";
        this.Index = -1;
    }
1162 1163 1164
}

asc_CTextFontFamily.prototype = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1165 1166
    asc_getName: function () { return this.Name; },
    asc_getIndex: function () { return this.Index; }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1167
};
1168 1169 1170 1171 1172 1173 1174 1175 1176

//{ asc_CTextFontFamily export
window["Asc"].asc_CTextFontFamily = asc_CTextFontFamily;
window["Asc"]["asc_CTextFontFamily"] = asc_CTextFontFamily;
prot = asc_CTextFontFamily.prototype;

prot["asc_getName"] = prot.asc_getName;
prot["asc_getIndex"] = prot.asc_getIndex;
//}
1177

Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
1178 1179
//}

1180 1181 1182
//-----------------------------------------------------------------------------------
// Manager
//-----------------------------------------------------------------------------------
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1183

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1184 1185 1186 1187 1188 1189 1190 1191 1192

function CChangeTableData(changedRange, added, hided, removed)
{
    this.changedRange = changedRange;
    this.added = added;
    this.hided = hided;
    this.removed = removed;
}

1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
function GraphicOption(ws, type, range, aId, offset) {
    this.ws = ws;
	this.type = type;
	this.range = range;
	this.aId = [];
    if (aId && Array.isArray(aId))
		this.aId = aId.concat();

	this.offset = offset;
}
GraphicOption.prototype.checkCol = function (col) {
	while ((col > 0) && !this.ws.cols[col])
		this.ws.expandColsOnScroll(true);
};
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1207

1208 1209 1210 1211
GraphicOption.prototype.checkRow = function (row) {
	while ((row > 0) && !this.ws.rows[row])
		this.ws.expandRowsOnScroll(true);
};
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1212

1213 1214 1215
GraphicOption.prototype.isScrollType = function() {
	return ((this.type === c_oAscGraphicOption.ScrollVertical) || (this.type === c_oAscGraphicOption.ScrollHorizontal));
};
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1216

1217
GraphicOption.prototype.getUpdatedRange = function() {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1218

1219
	var vr = new Asc.Range(this.ws.getFirstVisibleCol(true), this.ws.getFirstVisibleRow(true), this.ws.visibleRange.c2, this.ws.visibleRange.r2);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1220

1221 1222 1223
	//var vr = _this.ws.visibleRange.clone();
	if ( this.isScrollType() && !this.range )
		return vr;
1224

Alexander.Trofimov's avatar
Alexander.Trofimov committed
1225
	var checker, coords;
1226 1227 1228
	switch (this.type) {
		case c_oAscGraphicOption.ScrollVertical:
		case c_oAscGraphicOption.ScrollHorizontal: {
1229
			vr = this.range.clone();
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243
			this.checkCol(++vr.c2);
			this.checkRow(++vr.r2);
		}
			break;

		case c_oAscGraphicOption.AddText: {
			if ( this.ws ) {
				var controller = this.ws.objectRender.controller;
				var selectedObjects = controller.selectedObjects;

				if ( selectedObjects.length === 1 ) {
					if ( selectedObjects[0].isGroup() ) {
						var groupSelectedObjects = selectedObjects[0].selectedObjects;
						if ( groupSelectedObjects.length === 1 ) {
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1244 1245
							checker = this.ws.objectRender.getBoundsChecker(groupSelectedObjects[0]);
							coords = this.ws.objectRender.getBoundsCheckerCoords(checker);
1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259
							if ( coords ) {
								vr.c1 = Math.max(coords.from.col, vr.c1);
								vr.r1 = Math.max(coords.from.row, vr.r1);

								this.checkCol(coords.to.col + 1);
								vr.c2 = Math.min(coords.to.col + 1, vr.c2);

								this.checkRow(coords.to.row + 1);
								vr.r2 = Math.min(coords.to.row + 1, vr.r2);
							}
						}
					}
					else {
						var drawingObject = selectedObjects[0].drawingBase;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1260 1261
						checker = this.ws.objectRender.getBoundsChecker(drawingObject.graphicObject);
						coords = this.ws.objectRender.getBoundsCheckerCoords(checker);
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
						if ( coords ) {
							vr.c1 = Math.max(coords.from.col, vr.c1);
							vr.r1 = Math.max(coords.from.row, vr.r1);

							this.checkCol(coords.to.col + 1);
							vr.c2 = Math.min(coords.to.col + 1, vr.c2);

							this.checkRow(coords.to.row + 1);
							vr.r2 = Math.min(coords.to.row + 1, vr.r2);
						}
					}
				}
			}
		}
			break;
	}
	return vr;
};
GraphicOption.prototype.getOffset = function () {
	return this.offset;
};
1283

1284 1285
function DrawingObjects() {

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1286 1287 1288 1289 1290 1291 1292 1293
    //-----------------------------------------------------------------------------------
    // Scroll offset
    //-----------------------------------------------------------------------------------

    var ScrollOffset = function() {

        this.getX = function() {
            return -ptToPx((worksheet.cols[worksheet.getFirstVisibleCol(true)].left - worksheet.cellsLeft)) + worksheet.getCellLeft(0, 0);
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1294
        };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1295 1296 1297 1298

        this.getY = function() {
            return -ptToPx((worksheet.rows[worksheet.getFirstVisibleRow(true)].top - worksheet.cellsTop)) + worksheet.getCellTop(0, 0);
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1299
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319

    //-----------------------------------------------------------------------------------
    // Private
    //-----------------------------------------------------------------------------------

    var _this = this;
    var asc = window["Asc"];
    var api = asc["editor"];
    var worksheet = null;
    var asc_Range = asc.Range;

    var drawingCtx = null;
    var overlayCtx = null;
    var shapeCtx = null;
    var shapeOverlayCtx = null;

    var trackOverlay = null;
    var autoShapeTrack = null;
    var scrollOffset = new ScrollOffset();

1320 1321
    var aObjects = [];
    var aImagesSync = [];
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345
    var aBoundsCheckers = [];

    _this.zoom = { last: 1, current: 1 };
    _this.isViewerMode = null;
    _this.objectLocker = null;
    _this.drawingArea = null;
    _this.coordsManager = null;
    _this.drawingDocument = null;
    _this.asyncImageEndLoaded = null;
    _this.asyncImagesDocumentEndLoaded = null;

    // Task timer
    var aDrawTasks = [];

    function drawTaskFunction() {

        // При скролах нужно выполнить все задачи

        var taskLen = aDrawTasks.length;
        if ( taskLen ) {
            var lastTask = aDrawTasks[taskLen - 1];
            _this.showDrawingObjectsEx(lastTask.params.clearCanvas, lastTask.params.graphicOption, lastTask.params.printOptions);
            aDrawTasks.splice(0, (taskLen - 1 > 0) ? taskLen - 1 : 1);
        }
1346 1347

		api._autoSave();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1348 1349 1350 1351 1352 1353 1354
    }

    //-----------------------------------------------------------------------------------
    // Create drawing
    //-----------------------------------------------------------------------------------

    function DrawingBase(ws) {
1355
        this.worksheet = ws;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1356

1357 1358 1359
		this.imageUrl = "";
		this.Type = c_oAscCellAnchorType.cellanchorTwoCell;
		this.Pos = { X: 0, Y: 0 };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1360

1361 1362 1363 1364
		this.from = new CCellObjectInfo();
		this.to = new CCellObjectInfo();
		this.ext = { cx: 0, cy: 0 };
		this.size = { width: 0, height: 0 };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1365

1366
		this.graphicObject = null; // CImage, CShape, GroupShape or CChartAsGroup
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1367

1368 1369 1370 1371 1372 1373
        this.boundsFromTo =
        {
            from: new CCellObjectInfo(),
            to  : new CCellObjectInfo()
        };

1374
		this.flags = {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1375 1376 1377 1378 1379 1380 1381 1382 1383
            anchorUpdated: false,
            lockState: c_oAscLockTypes.kLockTypeNone
        };
    }

    //{ prototype
    DrawingBase.prototype.getAllFonts = function(AllFonts) {
        var _t = this;
        _t.graphicObject && _t.graphicObject.documentGetAllFontNames && _t.graphicObject.documentGetAllFontNames(AllFonts);
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1384
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1385 1386 1387 1388

    DrawingBase.prototype.isImage = function() {
        var _t = this;
        return _t.graphicObject ? _t.graphicObject.isImage() : false;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1389
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1390 1391 1392 1393

    DrawingBase.prototype.isShape = function() {
        var _t = this;
        return _t.graphicObject ? _t.graphicObject.isShape() : false;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1394
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1395 1396 1397 1398

    DrawingBase.prototype.isGroup = function() {
        var _t = this;
        return _t.graphicObject ? _t.graphicObject.isGroup() : false;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1399
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1400 1401 1402 1403

    DrawingBase.prototype.isChart = function() {
        var _t = this;
        return _t.graphicObject ? _t.graphicObject.isChart() : false;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1404
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1405 1406 1407 1408

    DrawingBase.prototype.isGraphicObject = function() {
        var _t = this;
        return _t.graphicObject != null;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1409
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1410 1411 1412 1413

    DrawingBase.prototype.isLocked = function() {
        var _t = this;
        return ( (_t.graphicObject.lockType != c_oAscLockTypes.kLockTypeNone) && (_t.graphicObject.lockType != c_oAscLockTypes.kLockTypeMine) )
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1414
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1415

Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
1416 1417
    DrawingBase.prototype.getCanvasContext = function() {
        return _this.drawingDocument.CanvasHitContext;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1418
    };
1419

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1420 1421 1422 1423 1424
    // GraphicObject: x, y, extX, extY
    DrawingBase.prototype.getGraphicObjectMetrics = function() {
        var _t = this;
        var metrics = { x: 0, y: 0, extX: 0, extY: 0 };

1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450
        var coordsFrom, coordsTo;
        switch(_t.Type)
        {
            case c_oAscCellAnchorType.cellanchorOneCell:
            case c_oAscCellAnchorType.cellanchorAbsolute:
            {

                coordsFrom = _this.coordsManager.calculateCoords(_t.from);
                metrics.x = pxToMm( coordsFrom.x );
                metrics.y = pxToMm( coordsFrom.y );
                metrics.extX = this.ext.cx;
                metrics.extY = this.ext.cy;
                break;
            }
            case c_oAscCellAnchorType.cellanchorTwoCell:
            {
                coordsFrom = _this.coordsManager.calculateCoords(_t.from);
                metrics.x = pxToMm( coordsFrom.x );
                metrics.y = pxToMm( coordsFrom.y );

                coordsTo = _this.coordsManager.calculateCoords(_t.to);
                metrics.extX = pxToMm( coordsTo.x - coordsFrom.x );
                metrics.extY = pxToMm( coordsTo.y - coordsFrom.y );
                break;
            }
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1451 1452 1453


        return metrics;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1454
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1455 1456 1457 1458

    // Считаем From/To исходя из graphicObject
    DrawingBase.prototype.setGraphicObjectCoords = function() {
        var _t = this;
1459

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1460 1461
        if ( _t.isGraphicObject() ) {

1462
            if ( (_t.graphicObject.x < 0) || (_t.graphicObject.y < 0) || (_t.graphicObject.extX < 0) || (_t.graphicObject.extY < 0) )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1463 1464
                return;

1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534
            var fromX =  mmToPt(_t.graphicObject.x), fromY =  mmToPt(_t.graphicObject.y),
                toX = mmToPt(_t.graphicObject.x + _t.graphicObject.extX), toY = mmToPt(_t.graphicObject.y + _t.graphicObject.extY);
            var bReinitHorScroll = false, bReinitVertScroll = false;

            var fromColCell = worksheet.findCellByXY(fromX, fromY, true, false, true);
            while(fromColCell.col === null && worksheet.cols.length < gc_nMaxCol)
            {
                worksheet.expandColsOnScroll(true);
                fromColCell = worksheet.findCellByXY(fromX, fromY, true, false, true);
                bReinitHorScroll = true;
            }
            if(fromColCell.col === null)
            {
                fromColCell.col = gc_nMaxCol;
            }
            var fromRowCell = worksheet.findCellByXY(fromX, fromY, true, true, false);

            while(fromRowCell.row === null && worksheet.rows.length < gc_nMaxRow)
            {
                worksheet.expandRowsOnScroll(true);
                fromRowCell = worksheet.findCellByXY(fromX, fromY, true, true, false);
                bReinitVertScroll = true;
            }
            if(fromRowCell.row === null)
            {
                fromRowCell.row = gc_nMaxRow;
            }


            var toColCell = worksheet.findCellByXY(toX, toY, true, false, true);
            while(toColCell.col === null && worksheet.cols.length < gc_nMaxCol)
            {
                worksheet.expandColsOnScroll(true);
                toColCell = worksheet.findCellByXY(toX, toY, true, false, true);
                bReinitHorScroll = true;
            }
            if(toColCell.col === null)
            {
                toColCell.col = gc_nMaxCol;
            }
            var toRowCell = worksheet.findCellByXY(toX, toY, true, true, false);

            while(toRowCell.row === null && worksheet.rows.length < gc_nMaxRow)
            {
                worksheet.expandRowsOnScroll(true);
                toRowCell = worksheet.findCellByXY(toX, toY, true, true, false);
                bReinitVertScroll = true;
            }
            if(toRowCell.row === null)
            {
                toRowCell.row = gc_nMaxRow;
            }

            _t.from.col = fromColCell.col;
            _t.from.colOff = ptToMm(fromColCell.colOff);
            _t.from.row = fromRowCell.row;
            _t.from.rowOff = ptToMm(fromRowCell.rowOff);

            _t.to.col = toColCell.col;
            _t.to.colOff = ptToMm(toColCell.colOff);
            _t.to.row = toRowCell.row;
            _t.to.rowOff = ptToMm(toRowCell.rowOff);
            if(bReinitHorScroll)
            {
                worksheet.handlers.trigger("reinitializeScrollX");
            }
            if(bReinitVertScroll)
            {
                worksheet.handlers.trigger("reinitializeScrollY");
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1535
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1536
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1537

1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620

    DrawingBase.prototype.checkBoundsFromTo = function() {
        var _t = this;

        if ( _t.isGraphicObject() && _t.graphicObject.bounds) {

            var bounds = _t.graphicObject.bounds;
            if ( (bounds.x < 0) || (bounds.y < 0) || (bounds.w < 0) || (bounds.h < 0) )
                return;

            var fromX =  mmToPt(bounds.x), fromY =  mmToPt(bounds.y),
                toX = mmToPt(bounds.x + bounds.w), toY = mmToPt(bounds.y + bounds.h);
            var bReinitHorScroll = false, bReinitVertScroll = false;

            var fromColCell = worksheet.findCellByXY(fromX, fromY, true, false, true);
            while(fromColCell.col === null && worksheet.cols.length < gc_nMaxCol)
            {
                worksheet.expandColsOnScroll(true);
                fromColCell = worksheet.findCellByXY(fromX, fromY, true, false, true);
                bReinitHorScroll = true;
            }
            if(fromColCell.col === null)
            {
                fromColCell.col = gc_nMaxCol;
            }
            var fromRowCell = worksheet.findCellByXY(fromX, fromY, true, true, false);

            while(fromRowCell.row === null && worksheet.rows.length < gc_nMaxRow)
            {
                worksheet.expandRowsOnScroll(true);
                fromRowCell = worksheet.findCellByXY(fromX, fromY, true, true, false);
                bReinitVertScroll = true;
            }
            if(fromRowCell.row === null)
            {
                fromRowCell.row = gc_nMaxRow;
            }


            var toColCell = worksheet.findCellByXY(toX, toY, true, false, true);
            while(toColCell.col === null && worksheet.cols.length < gc_nMaxCol)
            {
                worksheet.expandColsOnScroll(true);
                toColCell = worksheet.findCellByXY(toX, toY, true, false, true);
                bReinitHorScroll = true;
            }
            if(toColCell.col === null)
            {
                toColCell.col = gc_nMaxCol;
            }
            var toRowCell = worksheet.findCellByXY(toX, toY, true, true, false);

            while(toRowCell.row === null && worksheet.rows.length < gc_nMaxRow)
            {
                worksheet.expandRowsOnScroll(true);
                toRowCell = worksheet.findCellByXY(toX, toY, true, true, false);
                bReinitVertScroll = true;
            }
            if(toRowCell.row === null)
            {
                toRowCell.row = gc_nMaxRow;
            }

            _t.boundsFromTo.from.col = fromColCell.col;
            _t.boundsFromTo.from.colOff = ptToMm(fromColCell.colOff);
            _t.boundsFromTo.from.row = fromRowCell.row;
            _t.boundsFromTo.from.rowOff = ptToMm(fromRowCell.rowOff);

            _t.boundsFromTo.to.col = toColCell.col;
            _t.boundsFromTo.to.colOff = ptToMm(toColCell.colOff);
            _t.boundsFromTo.to.row = toRowCell.row;
            _t.boundsFromTo.to.rowOff = ptToMm(toRowCell.rowOff);
            if(bReinitHorScroll)
            {
                worksheet.handlers.trigger("reinitializeScrollX");
            }
            if(bReinitVertScroll)
            {
                worksheet.handlers.trigger("reinitializeScrollY");
            }
        }
    };

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648
    // Проверяет выход за границы
    DrawingBase.prototype.inVisibleArea = function(scrollType) {
        var _t = this;
        var result = true;
        var fvc, fvr, lvc, lvr;

        var checker = _this.getBoundsChecker(_t.graphicObject);
        var coords = _this.getBoundsCheckerCoords(checker);
        if ( coords ) {
            if ( scrollType ) {
                var updatedRange = scrollType.getUpdatedRange();
                fvc = updatedRange.c1;
                fvr = updatedRange.r1;
                lvc = updatedRange.c2;
                lvr = updatedRange.r2;
            }
            else {
                fvc = _t.worksheet.getFirstVisibleCol(true);
                fvr = _t.worksheet.getFirstVisibleRow(true);
                lvc = _t.worksheet.getLastVisibleCol();
                lvr = _t.worksheet.getLastVisibleRow();

            }
            if ( (fvr >= coords.to.row + 1) || (lvr <= coords.from.row - 1) || (fvc >= coords.to.col + 1) || (lvc <= coords.from.col - 1) )
                result = false;
        }

        return result;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1649
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1650

1651 1652 1653 1654 1655 1656 1657 1658 1659 1660
    DrawingBase.prototype.calculateCell = function(x, y)//pix
    {

    };

    DrawingBase.prototype.getColUnderCursor = function(x)
    {
        var col = worksheet._findColUnderCursor(x, true);
        while(!col)
        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1661 1662
            if ( worksheet.cols.length >= gc_nMaxCol ) {
               return null;
1663
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1664 1665
            worksheet.expandColsOnScroll(true);
            col = worksheet._findColUnderCursor(x, true);
1666 1667 1668 1669
        }
        return col;
    };

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684

    DrawingBase.prototype.getRowUnderCursor = function(y)
    {
        var row = worksheet._findRowUnderCursor(y, true);
        while(!row)
        {
            if ( worksheet.rows.length >= gc_nMaxRow ) {
                return null;
            }
            worksheet.expandRowsOnScroll(true);
            row = worksheet._findRowUnderCursor(y, true);
        }
        return row;
    };

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1685 1686 1687 1688 1689
    // Реальное смещение по высоте
    DrawingBase.prototype.getRealTopOffset = function() {
        var _t = this;
        var val = _t.worksheet.getCellTop(_t.from.row, 0) + mmToPx(_t.from.rowOff);
        return asc.round(val);
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1690
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1691 1692 1693 1694 1695 1696

    // Реальное смещение по ширине
    DrawingBase.prototype.getRealLeftOffset = function() {
        var _t = this;
        var val = _t.worksheet.getCellLeft(_t.from.col, 0) + mmToPx(_t.from.colOff);
        return asc.round(val);
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1697
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1698 1699 1700

    // Ширина по координатам
    DrawingBase.prototype.getWidthFromTo = function() {
1701 1702
        return (this.worksheet.getCellLeft(this.to.col, 0) + mmToPx(this.to.colOff) -
			this.worksheet.getCellLeft(this.from.col, 0) - mmToPx(this.from.colOff));
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1703
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1704 1705 1706

    // Высота по координатам
    DrawingBase.prototype.getHeightFromTo = function() {
1707 1708
        return this.worksheet.getCellTop(this.to.row, 0) + mmToPx(this.to.rowOff) -
			this.worksheet.getCellTop(this.from.row, 0) - mmToPx(this.from.rowOff);
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1709
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1710 1711 1712 1713 1714 1715 1716

    // Видимое смещение объекта от первой видимой строки
    DrawingBase.prototype.getVisibleTopOffset = function(withHeader) {
        var _t = this;
        var headerRowOff = _t.worksheet.getCellTop(0, 0);
        var fvr = _t.worksheet.getCellTop(_t.worksheet.getFirstVisibleRow(true), 0);
        var off = _t.getRealTopOffset() - fvr;
1717
        off = (off > 0) ? off : 0;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1718
        return withHeader ? headerRowOff + off : off;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1719
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1720 1721 1722 1723 1724 1725 1726

    // Видимое смещение объекта от первой видимой колонки
    DrawingBase.prototype.getVisibleLeftOffset = function(withHeader) {
        var _t = this;
        var headerColOff = _t.worksheet.getCellLeft(0, 0);
        var fvc = _t.worksheet.getCellLeft(_t.worksheet.getFirstVisibleCol(true), 0);
        var off = _t.getRealLeftOffset() - fvc;
1727
        off = (off > 0) ? off : 0;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1728
        return withHeader ? headerColOff + off : off;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1729
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1730 1731 1732 1733 1734 1735 1736

    // смещение по высоте внутри объекта
    DrawingBase.prototype.getInnerOffsetTop = function() {
        var _t = this;
        var fvr = _t.worksheet.getCellTop(_t.worksheet.getFirstVisibleRow(true), 0);
        var off = _t.getRealTopOffset() - fvr;
        return (off > 0) ? 0 : asc.round( Math.abs(off) );
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1737
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1738 1739 1740 1741 1742 1743 1744

    // смещение по ширине внутри объекта
    DrawingBase.prototype.getInnerOffsetLeft = function() {
        var _t = this;
        var fvc = _t.worksheet.getCellLeft(_t.worksheet.getFirstVisibleCol(true), 0);
        var off = _t.getRealLeftOffset() - fvc;
        return (off > 0) ? 0 : asc.round( Math.abs(off) );
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1745
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1746 1747 1748

    DrawingBase.prototype.getDrawingObjects = function() {
        return _this;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1749
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1750 1751 1752 1753 1754 1755 1756

    //}

    //-----------------------------------------------------------------------------------
    // Constructor
    //-----------------------------------------------------------------------------------

1757 1758 1759 1760 1761 1762 1763
    _this.createDrawingObject = function(type) {
        var drawingBase = new DrawingBase(worksheet);
        if(isRealNumber(type))
        {
            drawingBase.Type = type;
        }
        return drawingBase;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787
    };

    _this.cloneDrawingObject = function(object) {

        var copyObject = _this.createDrawingObject();

        copyObject.Type = object.Type;
        copyObject.Pos.X = object.Pos.X;
        copyObject.Pos.Y = object.Pos.Y;
        copyObject.ext.cx = object.ext.cx;
        copyObject.ext.cy = object.ext.cy;

        copyObject.from.col = object.from.col;
        copyObject.from.colOff = object.from.colOff;
        copyObject.from.row = object.from.row;
        copyObject.from.rowOff = object.from.rowOff;

        copyObject.to.col = object.to.col;
        copyObject.to.colOff = object.to.colOff;
        copyObject.to.row = object.to.row;
        copyObject.to.rowOff = object.to.rowOff;

        copyObject.graphicObject = object.graphicObject;
        return copyObject;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1788
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1789 1790 1791 1792 1793 1794 1795

    //-----------------------------------------------------------------------------------
    // Public methods
    //-----------------------------------------------------------------------------------

    _this.init = function(currentSheet) {

1796
        setInterval(drawTaskFunction, 5);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1797 1798

        var api = window["Asc"]["editor"];
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812
        worksheet = currentSheet;

        drawingCtx = currentSheet.drawingGraphicCtx;
        overlayCtx = currentSheet.overlayGraphicCtx;
        shapeCtx = currentSheet.shapeCtx;
        shapeOverlayCtx = currentSheet.shapeOverlayCtx;

        trackOverlay = new COverlay();
        trackOverlay.init( shapeOverlayCtx.m_oContext, "ws-canvas-graphic-overlay", 0, 0, shapeOverlayCtx.m_lWidthPix, shapeOverlayCtx.m_lHeightPix, shapeOverlayCtx.m_dWidthMM, shapeOverlayCtx.m_dHeightMM );

        autoShapeTrack = new CAutoshapeTrack();
        autoShapeTrack.init( trackOverlay, 0, 0, shapeOverlayCtx.m_lWidthPix, shapeOverlayCtx.m_lHeightPix, shapeOverlayCtx.m_dWidthMM, shapeOverlayCtx.m_dHeightMM );
        shapeCtx.m_oAutoShapesTrack = autoShapeTrack;

1813

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1814 1815 1816 1817
        _this.objectLocker = new ObjectLocker(worksheet);
        _this.drawingArea = currentSheet.drawingArea;
        _this.drawingArea.init();
        _this.coordsManager = new CoordsManager(worksheet, true);
1818
        _this.drawingDocument = currentSheet.model.DrawingDocument ? currentSheet.model.DrawingDocument : new CDrawingDocument(this);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1819 1820 1821 1822
        _this.drawingDocument.drawingObjects = this;
        _this.drawingDocument.AutoShapesTrack = autoShapeTrack;
        _this.drawingDocument.TargetHtmlElement = document.getElementById('id_target_cursor');
        _this.drawingDocument.InitGuiCanvasShape(api.shapeElementId);
1823
        _this.controller = new DrawingObjectsController(_this);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1824 1825 1826 1827 1828

        _this.isViewerMode = function() { return worksheet.handlers.trigger("getViewerMode"); };

        aImagesSync = [];

Alexander.Trofimov's avatar
Alexander.Trofimov committed
1829
		var i;
1830
        aObjects = currentSheet.model.Drawings;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1831
        for (i = 0; currentSheet.model.Drawings && (i < currentSheet.model.Drawings.length); i++)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1832
        {
1833 1834
            aObjects[i] = _this.cloneDrawingObject(aObjects[i]);
            var drawingObject = aObjects[i];
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1835
            // Check drawing area
1836 1837
            drawingObject.drawingArea = _this.drawingArea;
            drawingObject.worksheet = currentSheet;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849
            if ( !worksheet.cols[drawingObject.to.col] ) {
                while ( !worksheet.cols[drawingObject.to.col] ) {
                    worksheet.expandColsOnScroll(true);
                }
                worksheet.expandColsOnScroll(true); 	// для colOff
            }
            if ( !worksheet.rows[drawingObject.to.row] ) {
                while ( !worksheet.rows[drawingObject.to.row] ) {
                    worksheet.expandRowsOnScroll(true);
                }
                worksheet.expandRowsOnScroll(true); 	// для rowOff
            }
1850 1851
            var metrics = drawingObject.getGraphicObjectMetrics();
            CheckSpPrXfrm(drawingObject.graphicObject);
1852 1853
			var isSerialize = drawingObject.graphicObject.fromSerialize;
            if(!api.wbModel.bCollaborativeChanges && isSerialize)
1854 1855 1856 1857
            {
                drawingObject.graphicObject.spPr.xfrm.setOffX(metrics.x);
                drawingObject.graphicObject.spPr.xfrm.setOffY(metrics.y);
            }
1858
            if(drawingObject.graphicObject.getObjectType() !== historyitem_type_GroupShape && !api.wbModel.bCollaborativeChanges && isSerialize)
1859
            {
1860 1861
                drawingObject.graphicObject.spPr.xfrm.setExtX(metrics.extX);
                drawingObject.graphicObject.spPr.xfrm.setExtY(metrics.extY);
1862
            }
1863
            delete drawingObject.graphicObject.fromSerialize;
1864

1865 1866 1867
            drawingObject.graphicObject.drawingBase = aObjects[i];
            drawingObject.graphicObject.drawingObjects = _this;
            drawingObject.graphicObject.getAllRasterImages(aImagesSync);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1868
        }
1869

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1870 1871 1872 1873 1874
        for(i = 0; i < aImagesSync.length; ++i)
        {
            aImagesSync[i] = getFullImageSrc(aImagesSync[i]);
        }

1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890
        // Загружаем все картинки листа
        _this.asyncImagesDocumentEndLoaded = function()
        {
            _this.showDrawingObjects(true);
        };

        if(aImagesSync.length > 0)
        {
            var old_val = api.ImageLoader.bIsAsyncLoadDocumentImages;
            api.ImageLoader.bIsAsyncLoadDocumentImages = true;
            api.ImageLoader.LoadDocumentImages(aImagesSync, null);
            api.ImageLoader.bIsAsyncLoadDocumentImages = old_val;
        }

		_this.recalculate(true);

Alexander.Trofimov's avatar
Alexander.Trofimov committed
1891
        for (i = 0; i < currentSheet.model.Drawings.length; ++i)
1892 1893 1894 1895 1896
        {
            var boundsChecker = _this.getBoundsChecker(drawingObject.graphicObject);
            aBoundsCheckers.push(boundsChecker);
        }

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1897 1898 1899 1900 1901 1902

        // Upload event
        if (window.addEventListener) {
            window.addEventListener("message", _this._uploadMessage, false);
        }

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1903
        _this.shiftMap = {};
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1904
        worksheet.model.Drawings = aObjects;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1905
    };
1906

1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934

    _this.getSelectedDrawingsRange = function()
    {
        var i, rmin=gc_nMaxRow, rmax = 0, cmin = gc_nMaxCol, cmax = 0, selectedObjects = this.controller.selectedObjects, drawingBase;
        for(i = 0; i < selectedObjects.length; ++i)
        {

            drawingBase = selectedObjects[i].drawingBase;
            if(drawingBase)
            {
                if(drawingBase.from.col < cmin)
                {
                    cmin = drawingBase.from.col;
                }
                if(drawingBase.from.row < rmin)
                {
                    rmin = drawingBase.from.row;
                }
                if(drawingBase.to.col > cmax)
                {
                    cmax = drawingBase.to.col;
                }
                if(drawingBase.to.row > rmax)
                {
                    rmax = drawingBase.to.row;
                }
            }
        }
1935
        return new asc.ActiveRange(cmin, rmin, cmax, rmax, true);
1936 1937
    };

1938 1939
    _this.recalculate =  function(all)
    {
1940
        _this.controller.recalculate2(all);
1941 1942
    };

1943
    _this.preCopy = function() {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1944 1945 1946 1947
        _this.shiftMap = {};
        var selected_objects = _this.controller.selectedObjects;
        if(selected_objects.length > 0)
        {
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1948
            var min_x, min_y, i;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1949 1950
            min_x = selected_objects[0].x;
            min_y = selected_objects[0].y;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1951
            for(i = 1; i < selected_objects.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1952 1953 1954 1955 1956 1957 1958
            {
                if(selected_objects[i].x < min_x)
                    min_x = selected_objects[i].x;

                if(selected_objects[i].y < min_y)
                    min_y = selected_objects[i].y;
            }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1959
            for(i = 0; i < selected_objects.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1960 1961 1962 1963 1964 1965 1966
            {
                _this.shiftMap[selected_objects[i].Get_Id()] = {x: selected_objects[i].x - min_x, y: selected_objects[i].y - min_y};
            }
        }

    };

1967
    _this.getAllFonts = function(AllFonts) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1968

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1969
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1970

1971 1972 1973
    _this.getOverlay = function() {
        return trackOverlay;
    };
1974

Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
1975
    _this.OnUpdateOverlay = function() {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1976
        _this.drawingArea.drawSelection(_this.drawingDocument);
1977
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1978

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1979
    _this.changeZoom = function(factor) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1980

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1981 1982
        _this.zoom.last = _this.zoom.current;
        _this.zoom.current = factor;
1983

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1984
        _this.resizeCanvas();
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1985
    };
1986

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1987
    _this.resizeCanvas = function() {
1988
		_this.drawingArea.init();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1989 1990 1991 1992 1993 1994 1995 1996 1997 1998

        shapeCtx.init( drawingCtx.ctx, drawingCtx.getWidth(0), drawingCtx.getHeight(0), drawingCtx.getWidth(3), drawingCtx.getHeight(3) );
        shapeCtx.CalculateFullTransform();

        shapeOverlayCtx.init( overlayCtx.ctx, overlayCtx.getWidth(0), overlayCtx.getHeight(0), overlayCtx.getWidth(3), overlayCtx.getHeight(3) );
        shapeOverlayCtx.CalculateFullTransform();

        trackOverlay.init( shapeOverlayCtx.m_oContext, "ws-canvas-graphic-overlay", 0, 0, shapeOverlayCtx.m_lWidthPix, shapeOverlayCtx.m_lHeightPix, shapeOverlayCtx.m_dWidthMM, shapeOverlayCtx.m_dHeightMM );
        autoShapeTrack.init( trackOverlay, 0, 0, shapeOverlayCtx.m_lWidthPix, shapeOverlayCtx.m_lHeightPix, shapeOverlayCtx.m_dWidthMM, shapeOverlayCtx.m_dHeightMM );
        autoShapeTrack.Graphics.CalculateFullTransform();
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1999
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2000 2001 2002

    _this.getCanvasContext = function() {
        return _this.drawingDocument.CanvasHitContext;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2003
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2004 2005 2006

    _this.getDrawingObjects = function() {
        return aObjects;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2007
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2008 2009 2010

    _this.getWorksheet = function() {
        return worksheet;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2011
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2012

2013 2014 2015 2016 2017 2018 2019
	_this.getContextWidth = function () {
		return drawingCtx.getWidth();
	};
	_this.getContextHeight = function () {
		return drawingCtx.getHeight();
	};

2020 2021 2022 2023
    _this.getWorksheetModel = function() {
        return worksheet.model;
    };

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056
    _this._uploadMessage = function(event) {
        if ( null != event && null != event.data ) {
            try {
                var data = JSON.parse(event.data);
                if ((null != data) && (null != data["type"]))
                {
                    if (PostMessageType.UploadImage == data["type"]) {
                        if (c_oAscServerError.NoError == data["error"]) {
                            var sheetId = null;
                            if (null != data["input"])
                                sheetId = data["input"]["sheetId"];
                            var urls = data["urls"];

                            if (urls && urls.length > 0 && sheetId == worksheet.model.getId()) {
                                var url = urls[0];
                                if ( api.isImageChangeUrl || api.isShapeImageChangeUrl )
                                    _this.editImageDrawingObject(url);
                                else
                                    _this.addImageDrawingObject(url, null);
                            }
                            else
                                worksheet.model.workbook.handlers.trigger("asc_onEndAction", c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.LoadImage);
                        }
                        else {
                            worksheet.model.workbook.handlers.trigger("asc_onError", api.asc_mapAscServerErrorToAscError(data["error"]), c_oAscError.Level.NoCritical);
                            worksheet.model.workbook.handlers.trigger("asc_onEndAction", c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.LoadImage);
                        }
                    }
                }
            }
            catch(e) {
            }
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2057
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2058 2059 2060 2061

    _this.callTrigger = function(triggerName, param) {
        if ( triggerName )
            worksheet.model.workbook.handlers.trigger(triggerName, param);
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2062
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091

    _this.getBoundsChecker = function(graphicObject) {
        if ( graphicObject ) {
            // Коррекция для селекта при блокировке
            var delta = 4;
            var boundsChecker = new  CSlideBoundsChecker();
            boundsChecker.objectId = graphicObject.Id;

            if ( graphicObject.bounds ) {
                boundsChecker.Bounds.min_x = Math.max(1, graphicObject.bounds.x - delta);
                boundsChecker.Bounds.min_y = Math.max(1, graphicObject.bounds.y - delta);
                boundsChecker.Bounds.max_x = graphicObject.bounds.x + graphicObject.bounds.w + delta;
                boundsChecker.Bounds.max_y = graphicObject.bounds.y + graphicObject.bounds.h + delta;
            }
            else {
                boundsChecker.init(1, 1, 1, 1);
                boundsChecker.transform3(graphicObject.transform);
                boundsChecker.rect(0,0, graphicObject.extX, graphicObject.extY);
                graphicObject.draw(boundsChecker);
                boundsChecker.CorrectBounds();
                boundsChecker.Bounds.min_x = Math.max(1, boundsChecker.Bounds.min_x - delta);
                boundsChecker.Bounds.min_y = Math.max(1, boundsChecker.Bounds.min_y - delta);
                boundsChecker.Bounds.max_x += delta;
                boundsChecker.Bounds.max_y += delta;
            }

            return boundsChecker;
        }
        return null;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2092
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107

    _this.getBoundsCheckerCoords = function(checker) {

        if ( checker ) {
            var coords = { from: null, to: null };

            //coords.from = _this.coordsManager.calculateCell( mmToPx(checker.Bounds.min_x), mmToPx(checker.Bounds.min_y) );
            //coords.to = _this.coordsManager.calculateCell( mmToPx(checker.Bounds.max_x), mmToPx(checker.Bounds.max_y) );

            coords.from = _this.drawingArea.calculateCell( mmToPx(checker.Bounds.min_x), mmToPx(checker.Bounds.min_y) );
            coords.to = _this.drawingArea.calculateCell( mmToPx(checker.Bounds.max_x), mmToPx(checker.Bounds.max_y) );

            return coords;
        }
        return null;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2108
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2109 2110

    _this.clearDrawingObjects = function(graphicOption) {
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2111
		var i;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2112
        // Чистим предыдущие области
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2113
        for (i = 0; i < aBoundsCheckers.length; i++) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125

            var bSkip = false;
            if ( graphicOption && (graphicOption.type === c_oAscGraphicOption.ChangePosition) && graphicOption.aId.length ) {
                if ( graphicOption.aId.indexOf(aBoundsCheckers[i].objectId) === -1 )
                    bSkip = true;
            }
            if ( !bSkip )
                _this.restoreSheetArea(aBoundsCheckers[i]);
        }
        aBoundsCheckers = [];

        // Сохраняем текущие области
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2126
        for (i = 0; i < aObjects.length; i++ ) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2127 2128 2129 2130 2131
            if ( !aObjects[i].inVisibleArea() )
                continue;
            var boundsChecker = _this.getBoundsChecker(aObjects[i].graphicObject);
            aBoundsCheckers.push(boundsChecker);
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2132
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2133 2134 2135 2136 2137 2138 2139 2140

    _this.restoreSheetArea = function(checker) {

        var coords = _this.getBoundsCheckerCoords(checker);
        if ( coords ) {

            var range = asc_Range( coords.from.col, coords.from.row, coords.to.col, coords.to.row );
            var r_ = range.intersection(worksheet.visibleRange);
2141

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162
            if ( r_ ) {
                var offsetX = worksheet.cols[worksheet.getFirstVisibleCol(true)].left - worksheet.cellsLeft;
                var offsetY = worksheet.rows[worksheet.getFirstVisibleRow(true)].top - worksheet.cellsTop;

                while ( !worksheet.cols[r_.c2 + 1] ) {
                    worksheet.expandColsOnScroll(true);
                }
                while ( !worksheet.rows[r_.r2 + 1] ) {
                    worksheet.expandRowsOnScroll(true);
                }

                var x1 = worksheet.cols[r_.c1].left - offsetX;
                var y1 = worksheet.rows[r_.r1].top - offsetY;
                var x2 = worksheet.cols[r_.c2 + 1].left - offsetX;
                var y2 = worksheet.rows[r_.r2 + 1].top - offsetY;
                var w = x2 - x1;
                var h = y2 - y1;

                drawingCtx.clearRect( x1, y1, w, h );
                drawingCtx.setFillStyle(worksheet.settings.cells.defaultState.background).fillRect(x1, y1, w, h);
                worksheet._drawGrid(/*drawingCtx*/undefined, r_);
2163
                worksheet._drawCellsAndBorders(/*drawingCtx*/undefined, r_);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2164 2165
            }
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2166
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2167

2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181
    _this.getDrawingObjectsBounds = function()
    {
        var arr_x = [], arr_y = [], bounds;
        for(var i = 0; i < aObjects.length; ++i)
        {
            bounds = aObjects[i].graphicObject.bounds;
            arr_x.push(bounds.l);
            arr_x.push(bounds.r);
            arr_y.push(bounds.t);
            arr_y.push(bounds.b);
        }
        return new DrawingBounds(Math.min.apply(Math, arr_x), Math.max.apply(Math, arr_x), Math.min.apply(Math, arr_y), Math.max.apply(Math, arr_y));
    };

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192
    //-----------------------------------------------------------------------------------
    // Drawing objects
    //-----------------------------------------------------------------------------------

    _this.showDrawingObjects = function(clearCanvas, graphicOption, printOptions) {

        var currTime = getCurrentTime();
        if ( aDrawTasks.length ) {

            var lastTask = aDrawTasks[aDrawTasks.length - 1];

2193
			// ToDo не всегда грамотно так делать, т.к. в одном scroll я могу прислать 2 области (и их объединять не нужно)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204
            if ( lastTask.params.graphicOption && lastTask.params.graphicOption.isScrollType() && graphicOption && (lastTask.params.graphicOption.type === graphicOption.type) ) {
                lastTask.params.graphicOption.range.c1 = Math.min(lastTask.params.graphicOption.range.c1, graphicOption.range.c1);
                lastTask.params.graphicOption.range.r1 = Math.min(lastTask.params.graphicOption.range.r1, graphicOption.range.r1);
                lastTask.params.graphicOption.range.c2 = Math.max(lastTask.params.graphicOption.range.c2, graphicOption.range.c2);
                lastTask.params.graphicOption.range.r2 = Math.max(lastTask.params.graphicOption.range.r2, graphicOption.range.r2);
                return;
            }
            if ( (currTime - lastTask.time < 40) )
                return;
        }
        aDrawTasks.push({ time: currTime, params: { clearCanvas: clearCanvas, graphicOption: graphicOption, printOptions: printOptions} });
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2205
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2206 2207 2208 2209 2210 2211 2212

    _this.showDrawingObjectsEx = function(clearCanvas, graphicOption, printOptions) {

        /*********** Print Options ***************
         printOptions : {
			ctx,
			printPagesData
2213
		}
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2214 2215 2216 2217 2218 2219 2220 2221
         *****************************************/

        // Undo/Redo
        if ( (worksheet.model.index != api.wb.model.getActive()) && !printOptions )
            return;

        if ( drawingCtx ) {
            if ( clearCanvas ) {
2222
                _this.drawingArea.clear();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2223 2224 2225
            }

            if ( aObjects.length ) {
2226 2227 2228 2229 2230
                if (graphicOption) {
                    // Выставляем нужный диапазон для отрисовки
                    var updatedRect = { x: 0, y: 0, w: 0, h: 0 };
                    var updatedRange = graphicOption.getUpdatedRange();

2231
					var x1 = worksheet.getCellLeft(updatedRange.c1, 1);// - offsetX;
2232 2233 2234
                    var y1 = worksheet.getCellTop(updatedRange.r1, 1) ;//- offsetY;
                    var x2 = worksheet.getCellLeft(updatedRange.c2, 1);// - offsetX;
                    var y2 = worksheet.getCellTop(updatedRange.r2, 1);//- offsetY;
2235 2236
                    var w = x2 - x1;
                    var h = y2 - y1;
2237
					var offset = worksheet.getCellsOffset(1);
2238

2239 2240
                    updatedRect.x = ptToMm(x1 - offset.left);//ptToMm(x1);
                    updatedRect.y = ptToMm(y1 - offset.top);//ptToMm(y1);
2241 2242 2243
                    updatedRect.w = ptToMm(w);
                    updatedRect.h = ptToMm(h);

2244
					var offsetScroll = graphicOption.getOffset();
2245 2246
					shapeCtx.m_oContext.save();
					shapeCtx.m_oContext.beginPath();
2247
					shapeCtx.m_oContext.rect(ptToPx(x1 - offsetScroll.offsetX), ptToPx(y1 - offsetScroll.offsetY), ptToPx(w), ptToPx(h));
2248
                    shapeCtx.m_oContext.clip();
2249 2250 2251 2252

                    shapeCtx.updatedRect = updatedRect;
                } else
                    shapeCtx.updatedRect = null;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2253

2254

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276
                for (var i = 0; i < aObjects.length; i++) {
                    var drawingObject = aObjects[i];

                    // Shape render (drawForPrint)
                    if ( drawingObject.isGraphicObject() ) {
                        if ( printOptions ) {

                            var range = printOptions.printPagesData.pageRange;
                            var printPagesData = printOptions.printPagesData;
                            var offsetCols = printPagesData.startOffsetPt;

                            var left = worksheet.getCellLeft(range.c1, 3) - worksheet.getCellLeft(0, 3) - ptToMm(printPagesData.leftFieldInPt);
                            var top = worksheet.getCellTop(range.r1, 3) - worksheet.getCellTop(0, 3) - ptToMm(printPagesData.topFieldInPt);

                            _this.printGraphicObject(drawingObject.graphicObject, printOptions.ctx.DocumentRenderer, top, left);

                            if ( printPagesData.pageHeadings ) {
                                worksheet._drawColumnHeaders(printOptions.ctx, range.c1, range.c2, /*style*/ undefined, worksheet.cols[range.c1].left - printPagesData.leftFieldInPt + offsetCols, printPagesData.topFieldInPt - worksheet.cellsTop);
                                worksheet._drawRowHeaders(printOptions.ctx, range.r1, range.r2, /*style*/ undefined, printPagesData.leftFieldInPt - worksheet.cellsLeft, worksheet.rows[range.r1].top - printPagesData.topFieldInPt);
                            }
                        }
                        else {
2277
                            _this.drawingArea.drawObject(drawingObject);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2278 2279 2280
                        }
                    }
                }
2281 2282

				if (graphicOption)
2283 2284 2285
                {
                    shapeCtx.m_oContext.restore();
                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2286 2287 2288 2289 2290 2291 2292
            }
            worksheet.model.Drawings = aObjects;
        }

        if ( !printOptions ) {
            if ( aObjects.length ) {
                if ( _this.controller.selectedObjects.length )
2293
                {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2294
                    _this.OnUpdateOverlay();
2295 2296 2297
                    _this.drawingDocument.CheckTargetShow();
                    _this.controller.updateSelectionState(true);
                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2298 2299
            }
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2300
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2301

2302 2303 2304 2305 2306
    _this.getDrawingDocument = function()
    {
        return _this.drawingDocument;
    };

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2307 2308 2309 2310 2311 2312 2313 2314 2315 2316
    _this.printGraphicObject = function(graphicObject, ctx, top, left) {

        if ( graphicObject && ctx ) {
            // Image
            if ( graphicObject instanceof CImageShape )
                printImage(graphicObject, ctx, top, left);
            // Shape
            else if ( graphicObject instanceof CShape )
                printShape(graphicObject, ctx, top, left);
            // Chart
2317
            else if (graphicObject instanceof CChartSpace)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369
                printChart(graphicObject, ctx, top, left);
            // Group
            else if ( graphicObject instanceof CGroupShape )
                printGroup(graphicObject, ctx, top, left);
        }

        // Print functions
        function printImage(graphicObject, ctx, top, left) {

            if ( (graphicObject instanceof CImageShape) && graphicObject && ctx ) {
                // Save
                var tx = graphicObject.transform.tx;
                var ty = graphicObject.transform.ty;
                graphicObject.transform.tx -= left;
                graphicObject.transform.ty -= top;
                // Print
                graphicObject.draw( ctx );
                // Restore
                graphicObject.transform.tx = tx;
                graphicObject.transform.ty = ty;
            }
        }

        function printShape(graphicObject, ctx, top, left) {

            if ( (graphicObject instanceof CShape) && graphicObject && ctx ) {
                // Save
                var tx = graphicObject.transform.tx;
                var ty = graphicObject.transform.ty;
                graphicObject.transform.tx -= left;
                graphicObject.transform.ty -= top;
                var txTxt, tyTxt;
                if ( graphicObject.txBody && graphicObject.transformText ) {
                    txTxt = graphicObject.transformText.tx;
                    tyTxt = graphicObject.transformText.ty;
                    graphicObject.transformText.tx -= left;
                    graphicObject.transformText.ty -= top;
                }
                // Print
                graphicObject.draw( ctx );
                // Restore
                graphicObject.transform.tx = tx;
                graphicObject.transform.ty = ty;
                if ( graphicObject.txBody && graphicObject.transformText ) {
                    graphicObject.transformText.tx = txTxt;
                    graphicObject.transformText.ty = tyTxt;
                }
            }
        }

        function printChart(graphicObject, ctx, top, left) {

2370
            if ( (graphicObject instanceof CChartSpace) && graphicObject && ctx ) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2371 2372 2373 2374 2375 2376 2377

                // Save
                var tx = graphicObject.transform.tx;
                var ty = graphicObject.transform.ty;
                graphicObject.transform.tx -= left;
                graphicObject.transform.ty -= top;

2378
                graphicObject.updateChildLabelsTransform(graphicObject.transform.tx, graphicObject.transform.ty);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2379 2380 2381 2382 2383
                // Print
                graphicObject.draw( ctx );
                // Restore
                graphicObject.transform.tx = tx;
                graphicObject.transform.ty = ty;
2384
                graphicObject.updateChildLabelsTransform(graphicObject.transform.tx, graphicObject.transform.ty);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400

            }
        }

        function printGroup(graphicObject, ctx, top, left) {

            if ( (graphicObject instanceof CGroupShape) && graphicObject && ctx ) {
                for ( var i = 0; i < graphicObject.arrGraphicObjects.length; i++ ) {
                    var graphicItem = graphicObject.arrGraphicObjects[i];

                    if ( graphicItem instanceof CImageShape )
                        printImage(graphicItem, ctx, top, left);

                    else if ( graphicItem instanceof CShape )
                        printShape(graphicItem, ctx, top, left);

2401
                    else if (graphicItem instanceof CChartSpace )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2402 2403 2404 2405
                        printChart(graphicItem, ctx, top, left);
                }
            }
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2406
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2407 2408 2409 2410 2411 2412 2413 2414 2415 2416

    _this.getDrawingAreaMetrics = function() {

        /*
         *	Объект, определяющий max колонку и строчку для отрисовки объектов листа
         */

        var metrics = {
            maxCol: 0,
            maxRow: 0
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2417
        };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2418 2419 2420 2421 2422 2423 2424 2425 2426 2427

        for (var i = 0; aObjects && (i < aObjects.length); i++) {

            var drawingObject = aObjects[i];
            if ( drawingObject.to.col >= metrics.maxCol )
                metrics.maxCol = drawingObject.to.col + 1; // учитываем colOff
            if ( drawingObject.to.row >= metrics.maxRow )
                metrics.maxRow = drawingObject.to.row + 1; // учитываем rowOff
        }
        return metrics;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2428
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465

    _this.clipGraphicsCanvas = function(canvas, graphicOption) {
        if ( canvas instanceof CGraphics ) {

            var x, y, w, h;

            if ( graphicOption ) {
                var updatedRange = graphicOption.getUpdatedRange();

                var offsetX = worksheet.cols[worksheet.getFirstVisibleCol(true)].left - worksheet.cellsLeft;
                var offsetY = worksheet.rows[worksheet.getFirstVisibleRow(true)].top - worksheet.cellsTop;

                var vr = worksheet.visibleRange;
                var borderOffsetX = (updatedRange.c1 <= vr.c1) ? 0 : 3;
                var borderOffsetY = (updatedRange.r1 <= vr.r1) ? 0 : 3;

                x = ptToPx(worksheet.getCellLeft(updatedRange.c1, 1) - offsetX) - borderOffsetX;
                y = ptToPx(worksheet.getCellTop(updatedRange.r1, 1) - offsetY) - borderOffsetY;
                w = worksheet.getCellLeft(updatedRange.c2, 0) - worksheet.getCellLeft(updatedRange.c1, 0) + 3;
                h = worksheet.getCellTop(updatedRange.r2, 0) - worksheet.getCellTop(updatedRange.r1, 0) + 3;

                /*canvas.m_oContext.beginPath();
                 canvas.m_oContext.strokeStyle = "#FF0000";
                 canvas.m_oContext.rect(x + 0.5, y + 0.5, w, h);
                 canvas.m_oContext.stroke();*/
            }
            else {
                x = worksheet.getCellLeft(0, 0);
                y = worksheet.getCellTop(0, 0);
                w = shapeCtx.m_lWidthPix - x;
                h = shapeCtx.m_lHeightPix - y;
            }

            canvas.m_oContext.save();
            canvas.m_oContext.beginPath();
            canvas.m_oContext.rect(x, y, w, h);
            canvas.m_oContext.clip();
2466 2467 2468

            // этот сэйв нужен для восстановления сложных вложенных клипов
            canvas.m_oContext.save();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2469
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2470
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2471 2472 2473 2474 2475 2476

    _this.restoreGraphicsCanvas = function(canvas) {
        if ( canvas instanceof CGraphics ) {
            canvas.m_oContext.restore();

            // этот рестор нужен для восстановления сложных вложенных клипов
2477 2478
            canvas.m_oContext.restore();
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2479
    };
2480

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2481 2482
    _this._drawWorksheetLayer = function (range, offsetLeft, offsetTop) {
        worksheet._drawGrid(/*drawingCtx*/undefined, range, offsetLeft, offsetTop);
2483
        worksheet._drawCellsAndBorders(/*drawingCtx*/undefined, range, offsetLeft, offsetTop);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2484
    };
2485

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548
    _this.drawWorksheetLayer = function (range) {
        var c1, c2, r1, r2, tmpRange;
        var vr = worksheet.getVisibleRange();
        var oFrozenCell = worksheet.getFrozenCell();
        if (null !== oFrozenCell) {
            // Отрисовка диапазона, входящего в фиксированную область
            var cFrozen = oFrozenCell.getCol0();
            var rFrozen = oFrozenCell.getRow0();

            var offsetX, offsetY;

            if (range.c1 < cFrozen && range.r1 < rFrozen) {
                // Левый угол
                offsetX = worksheet.cols[0].left - worksheet.cellsLeft;
                offsetY = worksheet.rows[0].top - worksheet.cellsTop;
                c1 = Math.max(0, range.c1);
                c2 = Math.min(cFrozen - 1, range.c2);
                r1 = Math.max(0, range.r1);
                r2 = Math.min(rFrozen - 1, range.r2);
                tmpRange = asc_Range(c1, r1, c2, r2);
                _this._drawWorksheetLayer(tmpRange, offsetX, offsetY);
            }
            if (range.c1 < cFrozen && range.r2 > vr.r1) {
                offsetX = worksheet.cols[0].left - worksheet.cellsLeft;
                offsetY = undefined;
                c1 = Math.max(0, range.c1);
                c2 = Math.min(cFrozen - 1, range.c2);
                r1 = Math.max(range.r1, vr.r1);
                r2 = Math.min(range.r2, vr.r2);
                tmpRange = asc_Range(c1, r1, c2, r2);
                _this._drawWorksheetLayer(tmpRange, offsetX, offsetY);
            }
            if (range.r1 < rFrozen && range.c2 > vr.c1) {
                offsetX = undefined;
                offsetY = worksheet.rows[0].top - worksheet.cellsTop;
                c1 = Math.max(range.c1, vr.c1);
                c2 = Math.min(range.c2, vr.c2);
                r1 = Math.max(0, range.r1);
                r2 = Math.min(rFrozen - 1, range.r2);
                tmpRange = asc_Range(c1, r1, c2, r2);
                _this._drawWorksheetLayer(tmpRange, offsetX, offsetY);
            }
        }

        c1 = Math.max(range.c1, vr.c1);
        c2 = Math.min(range.c2, vr.c2);
        r1 = Math.max(range.r1, vr.r1);
        r2 = Math.min(range.r2, vr.r2);
        if (c1 <= c2 && r1 <= r2) {
            tmpRange = asc_Range(c1, r1, c2, r2);
            _this._drawWorksheetLayer(tmpRange);
        }

        worksheet._drawFrozenPaneLines();
    };

    //-----------------------------------------------------------------------------------
    // For object type
    //-----------------------------------------------------------------------------------

    _this.addImageDrawingObject = function(imageUrl, options) {


2549
            if ( imageUrl && !_this.isViewerMode() ) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2550

2551 2552
                var _image = api.ImageLoader.LoadImage(imageUrl, 1);
                var isOption = options && options.cell;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2553

2554 2555 2556
                var calculateObjectMetrics = function (object, width, height) {
                    // Обработка картинок большого разрешения
                    var metricCoeff = 1;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2557

2558 2559 2560
                    var coordsFrom = _this.coordsManager.calculateCoords(object.from);
                    var realTopOffset = coordsFrom.y;
                    var realLeftOffset = coordsFrom.x;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2561

2562 2563 2564
                    var areaWidth = worksheet.getCellLeft(worksheet.getLastVisibleCol(), 0) - worksheet.getCellLeft(worksheet.getFirstVisibleCol(true), 0); 	// по ширине
                    if (areaWidth < width) {
                        metricCoeff = width / areaWidth;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2565

2566 2567 2568
                        width = areaWidth;
                        height /= metricCoeff;
                    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2569

2570 2571 2572
                    var areaHeight = worksheet.getCellTop(worksheet.getLastVisibleRow(), 0) - worksheet.getCellTop(worksheet.getFirstVisibleRow(true), 0); 	// по высоте
                    if (areaHeight < height) {
                        metricCoeff = height / areaHeight;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2573

2574 2575 2576
                        height = areaHeight;
                        width /= metricCoeff;
                    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2577

2578 2579 2580 2581 2582 2583
                    //var cellTo = _this.coordsManager.calculateCell(realLeftOffset + width, realTopOffset + height);
                    var cellTo = _this.drawingArea.calculateCell(realLeftOffset + width, realTopOffset + height);
                    object.to.col = cellTo.col;
                    object.to.colOff = cellTo.colOff;
                    object.to.row = cellTo.row;
                    object.to.rowOff = cellTo.rowOff;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2584

2585 2586
                    worksheet.handlers.trigger("reinitializeScroll");
                };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2587

2588
                var addImageObject = function (_image) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2589

2590 2591
                    if ( !_image.Image ) {
                        worksheet.model.workbook.handlers.trigger("asc_onError", c_oAscError.ID.UplImageUrl, c_oAscError.Level.NoCritical);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2592
                    }
2593
                    else {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2594

2595 2596
                        var drawingObject = _this.createDrawingObject();
                        drawingObject.worksheet = worksheet;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2597

2598 2599
                        drawingObject.from.col = isOption ? options.cell.col : worksheet.getSelectedColumnIndex();
                        drawingObject.from.row = isOption ? options.cell.row : worksheet.getSelectedRowIndex();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2600

2601 2602 2603 2604 2605
                        // Проверяем начальные координаты при вставке
                        while ( !worksheet.cols[drawingObject.from.col] ) {
                            worksheet.expandColsOnScroll(true);
                        }
                        worksheet.expandColsOnScroll(true); 	// для colOff
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2606

2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618
                        while ( !worksheet.rows[drawingObject.from.row] ) {
                            worksheet.expandRowsOnScroll(true);
                        }
                        worksheet.expandRowsOnScroll(true); 	// для rowOff

                        calculateObjectMetrics(drawingObject, isOption ? options.width : _image.Image.width, isOption ? options.height : _image.Image.height);

                        var coordsFrom = _this.coordsManager.calculateCoords(drawingObject.from);
                        var coordsTo = _this.coordsManager.calculateCoords(drawingObject.to);

                        // CImage
                        _this.objectLocker.reset();
2619
                        _this.objectLocker.addObjectId(g_oIdCounter.Get_NewId());
2620 2621 2622 2623 2624 2625 2626
                        _this.objectLocker.checkObjects(function(bLock){
                            if(bLock !== true)
                                return;
                            _this.controller.resetSelection();
                            _this.controller.addImageFromParams(_image.src, pxToMm(coordsFrom.x), pxToMm(coordsFrom.y), pxToMm(coordsTo.x - coordsFrom.x), pxToMm(coordsTo.y - coordsFrom.y));
                        });
                    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2627

2628 2629 2630
                    worksheet.model.workbook.handlers.trigger("asc_onEndAction", c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.LoadImage);
                    worksheet.setSelectionShape(true);
                };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2631

2632
                if (null != _image) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2633
                    addImageObject(_image);
2634 2635 2636 2637 2638 2639
                }
                else {
                    _this.asyncImageEndLoaded = function(_image) {
                        addImageObject(_image);
                        _this.asyncImageEndLoaded = null;
                    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2640 2641
                }
            }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2642
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687

    _this.editImageDrawingObject = function(imageUrl) {

        if ( imageUrl ) {
            var _image = api.ImageLoader.LoadImage(imageUrl, 1);

            var addImageObject = function (_image) {

                if ( !_image.Image ) {
                    worksheet.model.workbook.handlers.trigger("asc_onError", c_oAscError.ID.UplImageUrl, c_oAscError.Level.NoCritical);
                }
                else {
                    if ( api.isImageChangeUrl ) {
                        var imageProp = new asc_CImgProperty();
                        imageProp.ImageUrl = _image.src;
                        _this.setGraphicObjectProps(imageProp);
                        api.isImageChangeUrl = false;
                    }
                    else if ( api.isShapeImageChangeUrl ) {
                        var imgProps = new asc_CImgProperty();
                        var shapeProp = new asc_CShapeProperty();
                        imgProps.ShapeProperties = shapeProp;
                        shapeProp.fill = new asc_CShapeFill();
                        shapeProp.fill.type = c_oAscFill.FILL_TYPE_BLIP;
                        shapeProp.fill.fill = new asc_CFillBlip();
                        shapeProp.fill.fill.asc_putUrl(_image.src);
                        _this.setGraphicObjectProps(imgProps);
                        api.isShapeImageChangeUrl = false;
                    }

                    _this.showDrawingObjects(true);
                }
                worksheet.model.workbook.handlers.trigger("asc_onEndAction", c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.LoadImage);
            };

            if (null != _image) {
                addImageObject(_image);
            }
            else {
                _this.asyncImageEndLoaded = function(_image) {
                    addImageObject(_image);
                    _this.asyncImageEndLoaded = null;
                }
            }
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2688
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2689

2690
    _this.addChartDrawingObject = function(chart) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2691 2692 2693 2694 2695 2696

        if ( _this.isViewerMode() )
            return;

        worksheet.setSelectionShape(true);

2697 2698
        if ( chart instanceof asc_ChartSettings )
        {
2699 2700
            if(api.isChartEditor)
            {
2701 2702
				_this.controller.selectObject(aObjects[0].graphicObject, 0);
				_this.controller.editChartDrawingObjects(chart);
2703 2704
                return;
            }
2705

2706
            _this.objectLocker.reset();
2707
            _this.objectLocker.addObjectId(g_oIdCounter.Get_NewId());
2708 2709 2710 2711 2712 2713
            _this.objectLocker.checkObjects(function(bLock){
                if(bLock)
                {
                    _this.controller.addChartDrawingObject(chart);
                }
            });
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2714
        }
2715 2716
        else if ( isObject(chart) && chart["binary"] )
        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2717
            History.TurnOff();
2718
            aObjects.length = 0;
2719 2720 2721 2722 2723 2724
            var listRange = new Range(worksheet.model, 0, 0, worksheet.nRowsCount - 1, worksheet.nColsCount - 1);
            listRange.cleanAll();
            if ( worksheet.isChartAreaEditMode ) {
                worksheet.isChartAreaEditMode = false;
                worksheet.arrActiveChartsRanges = [];
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2725 2726
            var asc_chart_binary = new Asc.asc_CChartBinary();
            asc_chart_binary.asc_setBinary(chart["binary"]);
2727
            asc_chart_binary.asc_setThemeBinary(chart["themeBinary"]);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2728
            var oNewChartSpace = asc_chart_binary.getChartSpace(worksheet.model);
2729 2730 2731 2732
            var theme = asc_chart_binary.getTheme();
            if(theme)
            {
                worksheet.model.workbook.theme = theme;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2733
            }
2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745
            var font_map = {};
            oNewChartSpace.documentGetAllFontNames(font_map);
            checkThemeFonts(font_map, worksheet.model.workbook.theme.themeElements.fontScheme);
            window["Asc"]["editor"]._loadFonts(font_map,
                function()
                {
                    var min_r = 0, max_r = 0, min_c = 0, max_c = 0;

                    var series = oNewChartSpace.chart.plotArea.charts[0].series, ser;
                    function fillTableFromRef(ref)
                    {
                        var cache = ref.numCache ? ref.numCache : (ref.strCache ? ref.strCache : null);
2746
                        var lit_format_code;
2747 2748
                        if(cache)
                        {
2749 2750 2751 2752 2753 2754 2755 2756 2757

                            if(typeof cache.formatCode === "string" && cache.formatCode.length > 0)
                            {
                                lit_format_code = cache.formatCode;
                            }
                            else
                            {
                                lit_format_code = "General"
                            }
2758 2759 2760 2761 2762 2763 2764
                            var sFormula = ref.f + "";
                            if(sFormula[0] === '(')
                                sFormula = sFormula.slice(1);
                            if(sFormula[sFormula.length-1] === ')')
                                sFormula = sFormula.slice(0, -1);
                            var f1 = sFormula;

2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784
                            var arr_f = f1.split(",");
                            var pt_index = 0, i, j, cell, pt;
                            for(i = 0; i < arr_f.length; ++i)
                            {
                                var parsed_ref = parserHelp.parse3DRef(arr_f[i]);
                                if(parsed_ref)
                                {
                                    var source_worksheet = worksheet.model.workbook.getWorksheetByName(parsed_ref.sheet);
                                    if(source_worksheet === worksheet.model)
                                    {
                                        var range1 = source_worksheet.getRange2(parsed_ref.range);
                                        if(range1)
                                        {
                                            var range = range1.bbox;
                                            while ( worksheet.cols.length < range.c2 ) {
                                                worksheet.expandColsOnScroll(true);
                                            }
                                            while ( worksheet.rows.length < range.r2 ) {
                                                worksheet.expandRowsOnScroll(true);
                                            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2785

2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808
                                            if(range.r1 > max_r)
                                                max_r = range.r1;
                                            if(range.r2 > max_r)
                                                max_r = range.r2;
                                            if(range.r1 < min_r)
                                                min_r = range.r1;
                                            if(range.r2 < min_r)
                                                min_r = range.r2;

                                            if(range.c1 > max_c)
                                                max_c = range.c1;
                                            if(range.c2 > max_c)
                                                max_c = range.c2;
                                            if(range.c1 < min_c)
                                                min_c = range.c1;
                                            if(range.c2 < min_c)
                                                min_c = range.c2;

                                            if(range.r1 === range.r2)
                                            {
                                                for(j = range.c1;  j <= range.c2; ++j)
                                                {

2809
                                                    cell = source_worksheet.getCell3(range.r1, j);
2810 2811 2812
                                                    pt = cache.getPtByIndex(pt_index);
                                                    if(pt)
                                                    {
2813
                                                        cell.setNumFormat(typeof pt.formatCode === "string" && pt.formatCode.length > 0 ? pt.formatCode : lit_format_code);
2814 2815 2816 2817 2818 2819 2820 2821 2822
                                                        cell.setValue(pt.val + "");
                                                    }
                                                    ++pt_index;
                                                }
                                            }
                                            else
                                            {
                                                for(j = range.r1; j <= range.r2; ++j)
                                                {
2823
                                                    cell = source_worksheet.getCell3(j, range.c1);
2824 2825 2826
                                                    pt = cache.getPtByIndex(pt_index);
                                                    if(pt)
                                                    {
2827
                                                        cell.setNumFormat(typeof pt.formatCode === "string" && pt.formatCode.length > 0 ? pt.formatCode : lit_format_code);
2828 2829 2830 2831 2832 2833 2834 2835 2836 2837
                                                        cell.setValue(pt.val + "");
                                                    }
                                                    ++pt_index;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2838 2839


2840
                    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2841

2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858
                    var first_num_ref;
                    if(series[0])
                    {
                        if(series[0].val)
                            first_num_ref = series[0].val.numRef;
                        else if(series[0].yVal)
                            first_num_ref = series[0].yVal.numRef;
                    }
                    if(first_num_ref)
                    {
                        var resultRef = parserHelp.parse3DRef(first_num_ref.f);
                        if(resultRef)
                        {
                            worksheet.model.workbook.aWorksheets[0].sName = resultRef.sheet;
                            if(series[0] && series[0].xVal && series[0].xVal.numRef)
                            {
                                fillTableFromRef(series[0].xVal.numRef);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2859
                            }
2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885
                            if(series[0].cat && series[0].cat.strRef)
                            {
                                fillTableFromRef(series[0].cat.strRef);
                            }
                            for(var i = 0; i < series.length; ++i)
                            {
                                ser = series[i];
                                if(ser.val && ser.val.numRef)
                                {
                                    fillTableFromRef(ser.val.numRef);
                                }
                                if(ser.yVal && ser.yVal.numRef)
                                {
                                    fillTableFromRef(ser.yVal.numRef);
                                }
                                if(ser.cat && ser.cat.numRef)
                                {
                                    fillTableFromRef(ser.cat.numRef);
                                }
                                if(ser.cat && ser.cat.strRef)
                                {
                                    fillTableFromRef(ser.cat.strRef);
                                }
                                if(ser.tx && ser.tx.strRef)
                                {
                                    fillTableFromRef(ser.tx.strRef);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2886 2887 2888 2889
                                }
                            }
                        }
                    }
2890
                    worksheet._updateCellsRange(new asc_Range(0, 0, Math.max(worksheet.nColsCount - 1, max_c),  Math.max(worksheet.nRowsCount - 1, max_r)));
2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912
                    oNewChartSpace.getAllRasterImages(aImagesSync);
                    oNewChartSpace.setBDeleted(false);
                    oNewChartSpace.setWorksheet(worksheet.model);
                    oNewChartSpace.addToDrawingObjects();
                    oNewChartSpace.recalculate();
                    CheckSpPrXfrm(oNewChartSpace);

                    var canvas_height = worksheet.drawingCtx.getHeight(3);
                    var pos_y = (canvas_height - oNewChartSpace.spPr.xfrm.extY)/2;
                    if(pos_y < 0)
                    {
                        pos_y = 0;
                    }

                    var canvas_width = worksheet.drawingCtx.getWidth(3);
                    var pos_x = (canvas_width - oNewChartSpace.spPr.xfrm.extX)/2;
                    if(pos_x < 0)
                    {
                        pos_x = 0;
                    }
                    oNewChartSpace.spPr.xfrm.setOffX(pos_x);
                    oNewChartSpace.spPr.xfrm.setOffY(pos_y);
2913
                    oNewChartSpace.checkDrawingBaseCoords();
2914
                    oNewChartSpace.recalculate();
2915 2916
                    var d = worksheet._calcActiveCellOffset(_this.getSelectedDrawingsRange());
                    window["Asc"]["editor"].wb.controller.scroll(d);
2917
                    _this.showDrawingObjects(false);
2918
                    _this.controller.resetSelection();
2919 2920
                    _this.controller.selectObject(oNewChartSpace, 0);
                    _this.sendGraphicObjectProps();
2921
                    History.TurnOn();
2922 2923 2924 2925
                    if(aImagesSync.length > 0)
                    {
                        window["Asc"]["editor"].ImageLoader.LoadDocumentImages(aImagesSync, null, function(){_this.showDrawingObjects(true)});
                    }
2926
                });
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2927 2928 2929


        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2930
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2931

2932 2933 2934 2935
    _this.editChartDrawingObject = function(chart)
    {
        if ( chart )
        {
2936 2937
            if(api.isChartEditor)
            {
2938
				_this.controller.selectObject(aObjects[0].graphicObject, 0);
2939
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2940 2941 2942
            _this.controller.editChartDrawingObjects(chart);
            _this.showDrawingObjects(false);
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2943
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2944

2945
    _this.rebuildChartGraphicObjects = function(data)
2946
    {
2947 2948
        if(!worksheet)
            return;
2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959
        ExecuteNoHistory(function(){
            var wsViews = Asc["editor"].wb.wsViews;
            var changedArr = [];
            if(data.changedRange)
            {
                changedArr.push(new BBoxInfo(worksheet.model, asc_Range(data.changedRange.c1, data.changedRange.r1, data.changedRange.c2, data.changedRange.r2)))
            }
            if(data.added)
            {
                changedArr.push(new BBoxInfo(worksheet.model, asc_Range(data.added.c1, data.added.r1, data.added.c2, data.added.r2)))
            }
2960

2961
            if(data.hided)
2962
            {
2963
                changedArr.push(new BBoxInfo(worksheet.model, asc_Range(data.hided.c1, data.hided.r1, data.hided.c2, data.hided.r2)))
2964
            }
2965 2966 2967 2968 2969 2970 2971 2972 2973 2974

            if(data.removed)
            {
                changedArr.push(new BBoxInfo(worksheet.model, asc_Range(data.removed.c1, data.removed.r1, data.removed.c2, data.removed.r2)))
            }

            for(var i = 0; i < wsViews.length; ++i)
            {
                if(wsViews[i])
                {
2975
                    wsViews[i].objectRender && wsViews[i].objectRender.rebuildCharts(changedArr);
2976 2977 2978 2979
                }
            }
        }, _this, []);

2980 2981 2982

    };

2983 2984 2985 2986 2987 2988 2989 2990 2991
    _this.pushToAObjects = function(aDrawing)
    {
        aObjects = [];
        for(var i = 0; i < aDrawing.length; ++i)
        {
            aObjects.push(aDrawing[i]);
        }
    };

2992
    _this.rebuildCharts = function(data)
2993 2994 2995
    {
        for(var i = 0; i < aObjects.length; ++i)
        {
2996
            if(aObjects[i].graphicObject.rebuildSeries)
2997
            {
2998
                aObjects[i].graphicObject.rebuildSeries(data);
2999 3000
            }
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3001
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3002 3003 3004

    _this.updateDrawingObject = function(bInsert, operType, updateRange) {

3005 3006
        if(History.TurnOffHistory > 0)
            return;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3007
        var metrics = null;
3008 3009 3010 3011 3012 3013 3014
		var count, bNeedRedraw = false, offset;
       //this.controller.checkObjectsAndCallback(
       //    function()
       //    {
            for (var i = 0; i < aObjects.length; i++)
            {
                var obj = aObjects[i];
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3015 3016 3017 3018 3019 3020
                    metrics = { from: {}, to: {} };
                    metrics.from.col = obj.from.col; metrics.to.col = obj.to.col;
                    metrics.from.colOff = obj.from.colOff; metrics.to.colOff = obj.to.colOff;
                    metrics.from.row = obj.from.row; metrics.to.row = obj.to.row;
                    metrics.from.rowOff = obj.from.rowOff; metrics.to.rowOff = obj.to.rowOff;

3021 3022 3023 3024
                    if (bInsert)
                    {		// Insert
                        switch (operType)
                        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3025 3026
                            case c_oAscInsertOptions.InsertColumns:
                            {
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3027
                                count = updateRange.c2 - updateRange.c1 + 1;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041
                                // Position
                                if (updateRange.c1 <= obj.from.col) {
                                    metrics.from.col += count;
                                    metrics.to.col += count;
                                }
                                else if ((updateRange.c1 > obj.from.col) && (updateRange.c1 <= obj.to.col)) {
                                    metrics.to.col += count;
                                }
                                else
                                    metrics = null;

                            }
                                break;
                            case c_oAscInsertOptions.InsertCellsAndShiftRight:
3042

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3043 3044 3045 3046 3047
                                break;

                            case c_oAscInsertOptions.InsertRows:
                            {
                                // Position
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3048
                                count = updateRange.r2 - updateRange.r1 + 1;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061

                                if (updateRange.r1 <= obj.from.row) {
                                    metrics.from.row += count;
                                    metrics.to.row += count;
                                }
                                else if ((updateRange.r1 > obj.from.row) && (updateRange.r1 <= obj.to.row)) {
                                    metrics.to.row += count;
                                }
                                else
                                    metrics = null;
                            }
                                break;
                            case c_oAscInsertOptions.InsertCellsAndShiftDown:
3062

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3063 3064 3065 3066
                                break;
                        }
                    }
                    else {				// Delete
3067 3068
                        switch (operType)
                        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3069 3070 3071 3072
                            case c_oAscDeleteOptions.DeleteColumns:
                            {

                                // Position
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3073
                                count = updateRange.c2 - updateRange.c1 + 1;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086

                                if (updateRange.c1 <= obj.from.col) {

                                    // outside
                                    if (updateRange.c2 < obj.from.col) {
                                        metrics.from.col -= count;
                                        metrics.to.col -= count;
                                    }
                                    // inside
                                    else {
                                        metrics.from.col = updateRange.c1;
                                        metrics.from.colOff = 0;

Alexander.Trofimov's avatar
Alexander.Trofimov committed
3087
                                        offset = 0;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115
                                        if (obj.to.col - updateRange.c2 - 1 > 0)
                                            offset = obj.to.col - updateRange.c2 - 1;
                                        else {
                                            offset = 1;
                                            metrics.to.colOff = 0;
                                        }
                                        metrics.to.col = metrics.from.col + offset;
                                    }
                                }

                                else if ((updateRange.c1 > obj.from.col) && (updateRange.c1 <= obj.to.col)) {

                                    // outside
                                    if (updateRange.c2 >= obj.to.col) {
                                        metrics.to.col = updateRange.c1;
                                        metrics.to.colOff = 0;
                                    }
                                    else
                                        metrics.to.col -= count;
                                }
                                else
                                    metrics = null;


                            }
                                break;
                            case c_oAscDeleteOptions.DeleteCellsAndShiftLeft:
                                // Range
3116

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3117 3118 3119 3120 3121 3122
                                break;

                            case c_oAscDeleteOptions.DeleteRows:
                            {

                                // Position
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3123
                                count = updateRange.r2 - updateRange.r1 + 1;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136

                                if (updateRange.r1 <= obj.from.row) {

                                    // outside
                                    if (updateRange.r2 < obj.from.row) {
                                        metrics.from.row -= count;
                                        metrics.to.row -= count;
                                    }
                                    // inside
                                    else {
                                        metrics.from.row = updateRange.r1;
                                        metrics.from.colOff = 0;

Alexander.Trofimov's avatar
Alexander.Trofimov committed
3137
                                        offset = 0;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164
                                        if (obj.to.row - updateRange.r2 - 1 > 0)
                                            offset = obj.to.row - updateRange.r2 - 1;
                                        else {
                                            offset = 1;
                                            metrics.to.colOff = 0;
                                        }
                                        metrics.to.row = metrics.from.row + offset;
                                    }
                                }

                                else if ((updateRange.r1 > obj.from.row) && (updateRange.r1 <= obj.to.row)) {

                                    // outside
                                    if (updateRange.r2 >= obj.to.row) {
                                        metrics.to.row = updateRange.r1;
                                        metrics.to.colOff = 0;
                                    }
                                    else
                                        metrics.to.row -= count;
                                }
                                else
                                    metrics = null;

                            }
                                break;
                            case c_oAscDeleteOptions.DeleteCellsAndShiftTop:
                                // Range
3165

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3166 3167 3168 3169 3170
                                break;
                        }
                    }

                    // Normalize position
3171 3172 3173 3174
                    if (metrics)
                    {
                        if (metrics.from.col < 0)
                        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202
                            metrics.from.col = 0;
                            metrics.from.colOff = 0;
                        }

                        if (metrics.to.col <= 0) {
                            metrics.to.col = 1;
                            metrics.to.colOff = 0;
                        }

                        if (metrics.from.row < 0) {
                            metrics.from.row = 0;
                            metrics.from.rowOff = 0;
                        }

                        if (metrics.to.row <= 0) {
                            metrics.to.row = 1;
                            metrics.to.rowOff = 0;
                        }

                        if (metrics.from.col == metrics.to.col) {
                            metrics.to.col++;
                            metrics.to.colOff = 0;
                        }
                        if (metrics.from.row == metrics.to.row) {
                            metrics.to.row++;
                            metrics.to.rowOff = 0;
                        }

3203 3204 3205 3206
                        obj.from.col = metrics.from.col;
                        obj.from.colOff = metrics.from.colOff;
                        obj.from.row = metrics.from.row;
                        obj.from.rowOff = metrics.from.rowOff;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3207

3208 3209 3210 3211
                        obj.to.col = metrics.to.col;
                        obj.to.colOff = metrics.to.colOff;
                        obj.to.row = metrics.to.row;
                        obj.to.rowOff = metrics.to.rowOff;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3212 3213

                        var coords = _this.coordsManager.calculateCoords(obj.from);
3214 3215
                        obj.graphicObject.spPr.xfrm.setOffX( pxToMm(coords.x));
                        obj.graphicObject.spPr.xfrm.setOffY( pxToMm(coords.y));
3216
                        obj.graphicObject.checkDrawingBaseCoords();
3217 3218
                        obj.graphicObject.recalculate();
                        bNeedRedraw = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3219 3220
                    }
                }
3221 3222 3223

        //    },  []);
        bNeedRedraw && _this.showDrawingObjects(true);
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3224
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3225

3226
    _this.moveRangeDrawingObject = function(oBBoxFrom, oBBoxTo) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3227

3228 3229
        if ( oBBoxFrom && oBBoxTo )
        {
3230
            var selected_objects = _this.controller.selection.groupSelection ? _this.controller.selection.groupSelection.selectedObjects : _this.controller.selectedObjects;
3231 3232 3233 3234 3235
            var chart;
            if(selected_objects.length === 1 && selected_objects[0].getObjectType() === historyitem_type_ChartSpace)
            {
                chart = selected_objects[0];
            }
3236 3237
            var object_to_check  = _this.controller.selection.groupSelection ? _this.controller.selection.groupSelection : chart;

3238 3239 3240 3241
            if(chart && !(!chart.bbox || !chart.bbox.seriesBBox || oBBoxTo.isEqual(chart.bbox.seriesBBox)))
            {
                var editChart = function (drawingObject)
                {
3242 3243
					var options = new asc_ChartSettings();
					var catHeadersBBox, serHeadersBBox;
3244 3245 3246
                    var final_bbox = oBBoxTo.clone();
                    if(chart.bbox.seriesBBox.bVert)
                    {
3247
						options.putInColumns(false);
3248
                        if(chart.bbox.catBBox && chart.bbox.catBBox.r1 === chart.bbox.catBBox.r2 && oBBoxTo.r1 > chart.bbox.catBBox.r1)
3249
                        {
3250
							catHeadersBBox = {
3251 3252 3253 3254 3255
                                r1: chart.bbox.catBBox.r1,
                                r2: chart.bbox.catBBox.r1,
                                c1: oBBoxTo.c1,
                                c2: oBBoxTo.c2
                            };
3256
                        }
3257 3258 3259


                        if(chart.bbox.serBBox && chart.bbox.serBBox && chart.bbox.serBBox.c1 === chart.bbox.serBBox.c2 && chart.bbox.serBBox.c1 < oBBoxTo.c1)
3260
                        {
3261
                            serHeadersBBox = {
3262 3263 3264 3265 3266
                                r1: oBBoxTo.r1,
                                r2: oBBoxTo.r2,
                                c1: chart.bbox.serBBox.c1,
                                c2: chart.bbox.serBBox.c2
                            };
3267
                        }
3268 3269 3270 3271 3272 3273 3274 3275 3276
                      //
                      //  if(chart.bbox.catBBox && oBBoxTo.r1 === chart.bbox.seriesBBox.r1)
                      //  {
                      //      --final_bbox.r1;
                      //  }
                      //  if(chart.bbox.serBBox && oBBoxTo.c1 === chart.bbox.seriesBBox.c1)
                      //  {
                      //      --final_bbox.c1;
                      //  }
3277 3278 3279
                    }
                    else
                    {
3280
						options.putInColumns(true);
3281 3282

                        if(chart.bbox.catBBox && chart.bbox.catBBox.c1 === chart.bbox.catBBox.c2 && oBBoxTo.c1 > chart.bbox.catBBox.c1)
3283
                        {
3284
                            catHeadersBBox = {
3285 3286 3287 3288 3289
                                r1: oBBoxTo.r1,
                                r2: oBBoxTo.r2,
                                c1: chart.bbox.catBBox.c1,
                                c2: chart.bbox.catBBox.c2
                            };
3290
                        }
3291 3292 3293


                        if(chart.bbox.serBBox && chart.bbox.serBBox && chart.bbox.serBBox.r1 === chart.bbox.serBBox.r2 && chart.bbox.serBBox.r1 < oBBoxTo.r1)
3294
                        {
3295
                            serHeadersBBox = {
3296 3297 3298 3299 3300
                                r1: chart.bbox.serBBox.r1,
                                r2: chart.bbox.serBBox.r2,
                                c1: oBBoxTo.c1,
                                c2: oBBoxTo.c2
                            };
3301
                        }
3302 3303 3304 3305 3306 3307 3308 3309 3310 3311


                        //if(chart.bbox.catBBox && oBBoxTo.c1 === chart.bbox.seriesBBox.c1)
                        //{
                        //    --final_bbox.c1;
                        //}
                        //if(chart.bbox.serBBox && oBBoxTo.r1 === chart.bbox.seriesBBox.r1)
                        //{
                        //    --final_bbox.r1;
                        //}
3312
                    }
3313

3314 3315
                    var startCell = new CellAddress(final_bbox.r1, final_bbox.c1, 0);
                    var endCell = new CellAddress(final_bbox.r2, final_bbox.c2, 0);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3316

3317 3318
                    if (startCell && endCell)
                    {
3319
						options.range = parserHelp.get3DRef(worksheet.model.sName,
3320 3321
								startCell.getID() === endCell.getID() ? startCell.getID() :
									startCell.getID() + ':' + endCell.getID());
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3322
                    }
3323 3324
					var chartSeries = getChartSeries(worksheet.model, options, catHeadersBBox, serHeadersBBox);
					drawingObject.rebuildSeriesFromAsc(chartSeries);
3325
                    _this.controller.startRecalculate();
3326
                    _this.sendGraphicObjectProps();
3327 3328 3329 3330 3331 3332 3333 3334
                };
                var callbackCheck = function (result) {
                    if(result)
                    {
                        History.Create_NewPoint();
                        editChart(chart);
                        _this.showDrawingObjects(true);
                    }
3335 3336 3337 3338
                    else
                    {
                        _this.selectDrawingObjectRange(chart);
                    }
3339 3340
                };
                _this.objectLocker.reset();
3341
                _this.objectLocker.addObjectId(object_to_check.Get_Id());
3342
                _this.objectLocker.checkObjects(callbackCheck);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3343 3344
            }
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3345
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3346 3347 3348 3349 3350 3351

    //-----------------------------------------------------------------------------------
    // Chart
    //-----------------------------------------------------------------------------------

    _this.calcChartInterval = function(chart) {
3352 3353
        if (chart.range.intervalObject)
        {
3354
            chart.range.interval = _this.bboxToInterval(chart.range.intervalObject.getBBox0(), chart.range.intervalObject.worksheet.sName);
3355 3356
        }
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3357

3358 3359 3360 3361
    _this.bboxToInterval = function(box, wsName)
    {
        var startCell = new CellAddress(box.r1, box.c1, 0);
        var endCell = new CellAddress(box.r2, box.c2, 0);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3362

3363 3364 3365
        if (startCell && endCell)
			return startCell.getID() === endCell.getID() ? startCell.getID() :
				parserHelp.get3DRef(wsName, startCell.getID() + ':' + endCell.getID());
3366
        return "";
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3367
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3368

3369
    _this.updateChartReferences = function(oldWorksheet, newWorksheet, bNoRedraw)
3370 3371 3372 3373
    {
        ExecuteNoHistory(function(){
            for (var i = 0; i < aObjects.length; i++) {
                var graphicObject = aObjects[i].graphicObject;
3374
                if ( graphicObject.updateChartReferences )
3375
                {
3376
                    graphicObject.updateChartReferences(oldWorksheet, newWorksheet);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3377 3378
                }
            }
3379 3380
        }, this, []);

Alexander.Trofimov's avatar
Alexander.Trofimov committed
3381
    };
3382 3383 3384 3385
    _this.updateChartReferences2 = function(oldWorksheet, newWorksheet)
    {
        for (var i = 0; i < aObjects.length; i++) {
            var graphicObject = aObjects[i].graphicObject;
3386
            if ( graphicObject.updateChartReferences2 )
3387
            {
3388
                graphicObject.updateChartReferences2(oldWorksheet, newWorksheet);
3389 3390 3391
            }
        }
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3392 3393 3394 3395 3396 3397 3398 3399 3400 3401

    //-----------------------------------------------------------------------------------
    // Graphic object
    //-----------------------------------------------------------------------------------

    _this.addGraphicObject = function(graphic, position, lockByDefault) {

        worksheet.cleanSelection();
        var drawingObject = _this.createDrawingObject();
        drawingObject.graphicObject = graphic;
Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
3402
        graphic.setDrawingBase(drawingObject);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3403

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3404
        var ret;
3405
        if (isRealNumber(position)) {
Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
3406
            aObjects.splice(position, 0, drawingObject);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3407 3408
            ret = position;
        }
3409
        else {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3410
            ret = aObjects.length;
Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
3411
            aObjects.push(drawingObject);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3412
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3413

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424
        if ( lockByDefault ) {
            _this.objectLocker.reset();
            _this.objectLocker.addObjectId(drawingObject.graphicObject.Id);
            _this.objectLocker.checkObjects( function(result) {} );
        }
        worksheet.setSelectionShape(true);

        /*var boundsChecker = _this.getBoundsChecker(drawingObject.graphicObject);
         aBoundsCheckers.push(boundsChecker);*/

        return ret;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3425
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3426 3427 3428 3429 3430 3431 3432

    _this.groupGraphicObjects = function() {

        if ( _this.controller.canGroup() ) {
            _this.controller.createGroup(null);
            worksheet.setSelectionShape(true);
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3433
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3434 3435 3436 3437 3438 3439 3440 3441

    _this.unGroupGraphicObjects = function() {

        if ( _this.controller.canUnGroup() ) {
            _this.controller.unGroup();
            worksheet.setSelectionShape(true);
            api.isStartAddShape = false;
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3442
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3443 3444 3445 3446 3447

    _this.insertUngroupedObjects = function(idGroup, aGraphics) {

        if ( idGroup && aGraphics.length ) {

Alexander.Trofimov's avatar
Alexander.Trofimov committed
3448 3449
            var i, aSingleObjects = [];
            for (i = 0; i < aGraphics.length; i++) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3450 3451 3452 3453 3454 3455 3456 3457 3458

                var obj = _this.createDrawingObject();
                obj.graphicObject = aGraphics[i];
                aGraphics[i].setDrawingBase(obj);
                obj.graphicObject.select(_this.controller);
                obj.setGraphicObjectCoords();
                aSingleObjects.push(obj);
            }

Alexander.Trofimov's avatar
Alexander.Trofimov committed
3459
            for (i = 0; i < aObjects.length; i++) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472

                if ( idGroup == aObjects[i].graphicObject.Id ) {

                    aObjects.splice(i, 1);

                    for (var j = aSingleObjects.length - 1; j > -1; j--) {
                        aObjects.splice(i, 0, aSingleObjects[j]);
                    }
                    _this.showDrawingObjects(true);
                    break;
                }
            }
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3473
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3474 3475 3476 3477 3478 3479 3480

    _this.getDrawingBase = function(graphicId) {
        for (var i = 0; i < aObjects.length; i++) {
            if ( aObjects[i].graphicObject.Id == graphicId )
                return aObjects[i];
        }
        return null;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3481
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516

    _this.deleteDrawingBase = function(graphicId) {

        var position = null;
        var bRedraw = false;
        for (var i = 0; i < aObjects.length; i++) {
            if ( aObjects[i].graphicObject.Id == graphicId ) {
                aObjects[i].graphicObject.deselect(_this.controller);
                if ( aObjects[i].isChart() )
                    worksheet.arrActiveChartsRanges = [];
                aObjects.splice(i, 1);
                bRedraw = true;
                position = i;
                break;
            }
        }

        /*if ( bRedraw ) {
         worksheet._checkSelectionShape();
         _this.sendGraphicObjectProps();
         _this.showDrawingObjects(true);
         }*/

        return position;
    };

    _this.checkGraphicObjectPosition = function(x, y, w, h) {

        /*	Принцип:
         true - если перемещение в области или требуется увеличить лист вправо/вниз
         false - наезд на хидеры
         */

        var response = { result: true, x: 0, y: 0 };

3517 3518
        var bottom = worksheet.getCellTop(worksheet.rows.length - 1, 3) + worksheet.getRowHeight(worksheet.rows.length - 1, 3) - worksheet.getCellTop(0, 3);
        var right = worksheet.getCellLeft(worksheet.cols.length - 1, 3) + worksheet.getColumnWidth(worksheet.cols.length - 1, 3) - worksheet.getCellLeft(0, 3);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534

        // выход за границу слева или сверху
        if ( y < 0 ) {
            response.result = false;
            response.y = Math.abs(y);
        }
        if ( x < 0 ) {
            response.result = false;
            response.x = Math.abs(x);
        }

        // выход за границу справа
        if ( x + w > right ) {
            var scrollX = scrollOffset.getX();
            var foundCol = worksheet._findColUnderCursor(mmToPt(x + w) + scrollX, true);
            while ( foundCol == null ) {
3535 3536 3537 3538 3539 3540 3541
                if ( worksheet.isMaxCol() )
                {
                    var lastCol = worksheet.cols[worksheet.nColsCount - 1];
                    if ( mmToPt(x + w) + scrollX > lastCol.left ) {
                        response.result = false;
                        response.x = ptToMm( lastCol.left - (mmToPt(x + w) + scrollX) );
                    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3542
                    break;
3543
                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3544 3545 3546 3547 3548 3549 3550 3551 3552 3553
                worksheet.expandColsOnScroll(true);
                worksheet.handlers.trigger("reinitializeScrollX");
                foundCol = worksheet._findColUnderCursor(mmToPt(x + w) + scrollX, true);
            }
        }
        // выход за границу снизу
        if ( y + h > bottom ) {
            var scrollY = scrollOffset.getY();
            var foundRow = worksheet._findRowUnderCursor(mmToPt(y + h) + scrollY, true);
            while ( foundRow == null ) {
3554 3555 3556 3557 3558 3559 3560
                if ( worksheet.isMaxRow() )
                {
                    var lastRow = worksheet.rows[worksheet.nRowsCount - 1];
                    if ( mmToPt(y + h) + scrollY > lastRow.top ) {
                        response.result = false;
                        response.y = ptToMm( lastRow.top - (mmToPt(y + h) + scrollY) );
                    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3561
                    break;
3562
                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3563 3564 3565 3566 3567 3568 3569
                worksheet.expandRowsOnScroll(true);
                worksheet.handlers.trigger("reinitializeScrollY");
                foundRow = worksheet._findRowUnderCursor(mmToPt(y + h) + scrollY, true);
            }
        }

        return response;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3570
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3571 3572 3573 3574 3575 3576

    _this.resetLockedGraphicObjects = function() {

        for (var i = 0; i < aObjects.length; i++) {
            aObjects[i].graphicObject.lockType = c_oAscLockTypes.kLockTypeNone;
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3577
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589

    _this.tryResetLockedGraphicObject = function(id) {

        var bObjectFound = false;
        for (var i = 0; i < aObjects.length; i++) {
            if ( aObjects[i].graphicObject.Id == id ) {
                aObjects[i].graphicObject.lockType = c_oAscLockTypes.kLockTypeNone;
                bObjectFound = true;
                break;
            }
        }
        return bObjectFound;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3590
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3591 3592 3593

    _this.getDrawingCanvas = function() {
        return { shapeCtx: shapeCtx, shapeOverlayCtx: shapeOverlayCtx, autoShapeTrack: autoShapeTrack, trackOverlay: trackOverlay };
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3594
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3595 3596 3597 3598 3599 3600

    _this.convertMetric = function(val, from, to) {
        /* Параметры конвертирования (from/to)
         0 - px, 1 - pt, 2 - in, 3 - mm
         */
        return val * ascCvtRatio(from, to);
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3601
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3602

3603 3604
    _this.convertPixToMM = function(pix)
    {
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3605
        return _this.convertMetric(pix, 0, 3);
3606
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3607 3608
    _this.getSelectedGraphicObjects = function() {
        return _this.controller.selectedObjects;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3609
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3610 3611

    _this.selectedGraphicObjectsExists = function() {
3612
        return _this.controller && _this.controller.selectedObjects.length > 0;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3613
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635

    _this.loadImageRedraw = function(imageUrl) {

        var _image = api.ImageLoader.LoadImage(imageUrl, 1);

        if (null != _image) {
            imageLoaded(_image);
        }
        else {
            _this.asyncImageEndLoaded = function(_image) {
                imageLoaded(_image);
                _this.asyncImageEndLoaded = null;
            }
        }

        function imageLoaded(_image) {
            if ( !_image.Image ) {
                worksheet.model.workbook.handlers.trigger("asc_onError", c_oAscError.ID.UplImageUrl, c_oAscError.Level.NoCritical);
            }
            else
                _this.showDrawingObjects(true);
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3636
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660

    _this.getOriginalImageSize = function() {

        var selectedObjects = _this.controller.selectedObjects;
        if ( (selectedObjects.length == 1) && selectedObjects[0].isImage() ) {

            var imageUrl = selectedObjects[0].getImageUrl();

            var _image = api.ImageLoader.map_image_index[getFullImageSrc(imageUrl)];
            if (_image != undefined && _image.Image != null && _image.Status == ImageLoadStatus.Complete) {

                var _w = 1, _h = 1;
                var bIsCorrect = false;
                if (_image.Image != null) {

                    bIsCorrect = true;
                    _w = Math.max( pxToMm(_image.Image.width), 1 );
                    _h = Math.max( pxToMm(_image.Image.height), 1 );
                }

                return new asc_CImageSize( _w, _h, bIsCorrect);
            }
        }
        return new asc_CImageSize( 50, 50, false );
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3661
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3662 3663 3664 3665

    _this.sendGraphicObjectProps = function() {
        if ( worksheet )
            worksheet.handlers.trigger("selectionChanged", worksheet.getSelectionInfo());
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3666
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3667 3668 3669 3670 3671

    _this.setGraphicObjectProps = function(props) {

        var objectProperties = props;

Alexander.Trofimov's avatar
Alexander.Trofimov committed
3672
		var _img;
3673
        if ( !isNullOrEmptyString(objectProperties.ImageUrl) ) {
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3674
            _img = api.ImageLoader.LoadImage(objectProperties.ImageUrl, 1);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3675 3676

            if (null != _img) {
3677 3678 3679 3680 3681
                _this.controller.setGraphicObjectProps( objectProperties );
            }
            else {
                _this.asyncImageEndLoaded = function(_image) {
                    _this.controller.setGraphicObjectProps( objectProperties );
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3682
                    _this.asyncImageEndLoaded = null;
3683 3684 3685
                }
            }
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3686 3687 3688
        else if ( objectProperties.ShapeProperties && objectProperties.ShapeProperties.fill && objectProperties.ShapeProperties.fill.fill &&
            !isNullOrEmptyString(objectProperties.ShapeProperties.fill.fill.url) ) {

Alexander.Trofimov's avatar
Alexander.Trofimov committed
3689
            _img = api.ImageLoader.LoadImage(objectProperties.ShapeProperties.fill.fill.url, 1);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3690
            if ( null != _img ) {
3691 3692 3693 3694 3695
                _this.controller.setGraphicObjectProps( objectProperties );
            }
            else {
                _this.asyncImageEndLoaded = function(_image) {
                    _this.controller.setGraphicObjectProps( objectProperties );
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3696
                    _this.asyncImageEndLoaded = null;
3697 3698 3699 3700 3701 3702 3703
                }
            }
        }
        else {
            objectProperties.ImageUrl = null;
            _this.controller.setGraphicObjectProps( objectProperties );
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3704 3705

        _this.sendGraphicObjectProps();
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3706
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3707 3708 3709

    _this.showChartSettings = function() {
        api.wb.handlers.trigger("asc_onShowChartDialog", true);
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3710
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3711 3712 3713 3714

    _this.setDrawImagePlaceParagraph = function(element_id, props) {
        _this.drawingDocument.InitGuiCanvasTextProps(element_id);
        _this.drawingDocument.DrawGuiCanvasTextProps(props);
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3715
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3716 3717 3718 3719 3720 3721

    //-----------------------------------------------------------------------------------
    // Graphic object mouse & keyboard events
    //-----------------------------------------------------------------------------------

    _this.graphicObjectMouseDown = function(e, x, y) {
3722
        var offsets = _this.drawingArea.getOffsets(x, y, true);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3723 3724
        if ( offsets )
            _this.controller.onMouseDown( e, pxToMm(x - offsets.x), pxToMm(y - offsets.y) );
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3725
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3726 3727 3728 3729

    _this.graphicObjectMouseMove = function(e, x, y) {
        e.IsLocked = e.isLocked;

3730
        var offsets = _this.drawingArea.getOffsets(x, y, true);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3731 3732
        if ( offsets )
            _this.controller.onMouseMove( e, pxToMm(x - offsets.x), pxToMm(y - offsets.y) );
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3733
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3734 3735

    _this.graphicObjectMouseUp = function(e, x, y) {
3736
        var offsets = _this.drawingArea.getOffsets(x, y, true);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3737 3738
        if ( offsets )
            _this.controller.onMouseUp( e, pxToMm(x - offsets.x), pxToMm(y - offsets.y) );
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3739
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3740 3741 3742 3743 3744

    // keyboard

    _this.graphicObjectKeyDown = function(e) {
        return _this.controller.onKeyDown( e );
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3745
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3746 3747 3748 3749

    _this.graphicObjectKeyPress = function(e) {

        e.KeyCode = e.keyCode;
3750
        e.CtrlKey = e.metaKey || e.ctrlKey;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3751 3752 3753 3754
        e.AltKey = e.altKey;
        e.ShiftKey = e.shiftKey;
        e.Which = e.which;
        return _this.controller.onKeyPress( e );
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3755
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775

    //-----------------------------------------------------------------------------------
    // Asc
    //-----------------------------------------------------------------------------------

    _this.cleanWorksheet = function() {
        for (var i = 0; i < aObjects.length; i++) {
            aObjects[i].graphicObject.deleteDrawingBase();
        }
        aBoundsCheckers = [];

        worksheet._clean();
        var listRange = new Range(worksheet.model, 0, 0, worksheet.nRowsCount - 1, worksheet.nColsCount - 1);
        listRange.cleanAll();

        _this.controller.resetSelection();
        shapeCtx.m_oContext.clearRect(0, 0, shapeCtx.m_lWidthPix, shapeCtx.m_lHeightPix);
        shapeOverlayCtx.m_oContext.clearRect(0, 0, shapeOverlayCtx.m_lWidthPix, shapeOverlayCtx.m_lHeightPix);
        _this.OnUpdateOverlay();
        History.Clear();
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3776
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788

    _this.getWordChartObject = function() {
        for (var i = 0; i < aObjects.length; i++) {
            var drawingObject = aObjects[i];

            if ( drawingObject.isChart() ) {
                var chart = new asc_CChartBinary(drawingObject.graphicObject);
                _this.cleanWorksheet();
                return chart;
            }
        }
        return null;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3789
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3790 3791 3792

    _this.getAscChartObject = function() {

3793 3794 3795
        var settings;
        if(api.isChartEditor)
        {
3796
            return _this.controller.getPropsFromChart(aObjects[0].graphicObject);
3797 3798
        }
        settings = _this.controller.getChartProps();
3799 3800 3801 3802 3803 3804 3805 3806 3807
        if ( !settings )
        {
            settings = new asc_ChartSettings();
            var selectedRange = worksheet.getSelectedRange();
            if (selectedRange)
            {
                var box = selectedRange.getBBox0();
                settings.putInColumns(!(box.r2 - box.r1 < box.c2 - box.c1));
            }
3808
            settings.putRange(worksheet.getSelectionRangeValue());
3809 3810
            settings.putStyle(2);
            settings.putType(c_oAscChartTypeSettings.lineNormal);
3811
            settings.putTitle(c_oAscChartTitleShowSettings.noOverlay);
3812 3813 3814 3815 3816 3817 3818 3819
            settings.putLegendPos(c_oAscChartLegendShowSettings.right);
            settings.putHorAxisLabel(c_oAscChartHorAxisLabelShowSettings.none);
            settings.putVertAxisLabel(c_oAscChartVertAxisLabelShowSettings.none);
            settings.putDataLabelsPos(c_oAscChartDataLabelsPos.none);
            settings.putHorGridLines(c_oAscGridLinesSettings.major);
            settings.putVertGridLines(c_oAscGridLinesSettings.none);
            settings.putInColumns(false);
            settings.putSeparator(",");
3820 3821
            settings.putLine(true);
            settings.putShowMarker(false);
3822 3823 3824 3825 3826 3827 3828 3829

            var vert_axis_settings = new asc_ValAxisSettings();
            settings.putVertAxisProps(vert_axis_settings);
            vert_axis_settings.setDefault();

            var hor_axis_settings = new asc_CatAxisSettings();
            settings.putHorAxisProps(hor_axis_settings);
            hor_axis_settings.setDefault();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3830
        }
3831
        return settings;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3832
    };
3833

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3834 3835 3836
    //-----------------------------------------------------------------------------------
    // Selection
    //-----------------------------------------------------------------------------------
3837

3838
    _this.selectDrawingObjectRange = function(drawing) {
3839

3840
		worksheet.cleanSelection();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3841
        worksheet.arrActiveChartsRanges = [];
3842

3843
        if(!drawing.bbox || drawing.bbox.worksheet !== worksheet.model)
3844
            return;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3845

3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861
        var stroke_color, fill_color;
        if(drawing.bbox.serBBox)
        {
            stroke_color = fill_color = new CColor(0, 128, 0);
            worksheet._drawElements(worksheet, worksheet._drawSelectionElement,
                asc.Range(drawing.bbox.serBBox.c1, drawing.bbox.serBBox.r1, drawing.bbox.serBBox.c2, drawing.bbox.serBBox.r2, true),
                false, 1,
                stroke_color, fill_color);
        }
        if(drawing.bbox.catBBox)
        {
            stroke_color = fill_color = new CColor(153, 0, 204);
            worksheet._drawElements(worksheet, worksheet._drawSelectionElement,
                asc.Range(drawing.bbox.catBBox.c1, drawing.bbox.catBBox.r1, drawing.bbox.catBBox.c2, drawing.bbox.catBBox.r2, true),
                false, 1,
                stroke_color, fill_color);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3862
        }
3863 3864 3865 3866
        var BB = drawing.bbox.seriesBBox;
        var range = asc.Range(BB.c1, BB.r1, BB.c2, BB.r2, true);
        worksheet.arrActiveChartsRanges.push(range);
        worksheet.isChartAreaEditMode = true;
3867
		worksheet._drawSelection();
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3868
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886

    _this.unselectDrawingObjects = function() {

        if ( worksheet.isChartAreaEditMode ) {
            worksheet.isChartAreaEditMode = false;
            worksheet.arrActiveChartsRanges = [];
        }
        _this.controller.resetSelectionState();
        _this.OnUpdateOverlay();
    };

    _this.getDrawingObject = function(id) {

        for (var i = 0; i < aObjects.length; i++) {
            if (aObjects[i].graphicObject.Id == id)
                return aObjects[i];
        }
        return null;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3887
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3888 3889 3890

    _this.getGraphicSelectionType = function(id) {

3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911
        var selected_objects, selection, controller = _this.controller;
        if(controller.selection.groupSelection)
        {
            selected_objects = controller.selection.groupSelection.selectedObjects;
            selection = controller.selection.groupSelection.selection;
        }
        else
        {
            selected_objects = controller.selectedObjects;
            selection = controller.selection;
        }
        if(selection.chartSelection && selection.chartSelection.selection.textSelection)
        {
            return c_oAscSelectionType.RangeChartText;
        }
        if(selection.textSelection)
        {
            return c_oAscSelectionType.RangeShapeText;
        }
        if(selected_objects[0] )
        {
3912
            if(selected_objects[0].getObjectType() === historyitem_type_ChartSpace && selected_objects.length === 1)
3913
                return c_oAscSelectionType.RangeChart;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3914

3915 3916
            if(selected_objects[0].getObjectType() === historyitem_type_ImageShape)
                return c_oAscSelectionType.RangeImage;
3917 3918 3919

            return c_oAscSelectionType.RangeShape;

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3920 3921
        }
        return undefined;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3922
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3923 3924 3925 3926 3927 3928 3929

    //-----------------------------------------------------------------------------------
    // Position
    //-----------------------------------------------------------------------------------

    _this.setGraphicObjectLayer = function(layerType) {
        _this.controller.setGraphicObjectLayer(layerType);
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3930
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3931 3932 3933 3934 3935 3936 3937 3938 3939

    _this.saveSizeDrawingObjects = function() {

        for (var i = 0; i < aObjects.length; i++) {
            var obj = aObjects[i];

            obj.size.width = obj.getWidthFromTo();
            obj.size.height = obj.getHeightFromTo();
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3940
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3941

3942
    _this.updateSizeDrawingObjects = function(target) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3943

3944
        ExecuteNoHistory(function(){
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3945

3946 3947 3948 3949 3950
            var i, bNeedRecalc = false, drawingObject, coords, cellTo;
            if(target.target === c_oTargetType.RowResize)
            {
                for (i = 0; i < aObjects.length; i++) {
                    drawingObject = aObjects[i];
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3951

3952 3953 3954 3955 3956 3957
                    if(drawingObject.from.row >= target.row)
                    {
                        coords = _this.coordsManager.calculateCoords(drawingObject.from);
                        CheckSpPrXfrm(drawingObject.graphicObject);
                        drawingObject.graphicObject.spPr.xfrm.setOffX( pxToMm(coords.x));
                        drawingObject.graphicObject.spPr.xfrm.setOffY( pxToMm(coords.y) );
3958
                        drawingObject.graphicObject.checkDrawingBaseCoords();
3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973
                        bNeedRecalc = true;
                    }
                }
            }
            else
            {
                for (i = 0; i < aObjects.length; i++) {
                    drawingObject = aObjects[i];

                    if(drawingObject.from.col >= target.col)
                    {
                        coords = _this.coordsManager.calculateCoords(drawingObject.from);
                        CheckSpPrXfrm(drawingObject.graphicObject);
                        drawingObject.graphicObject.spPr.xfrm.setOffX( pxToMm(coords.x));
                        drawingObject.graphicObject.spPr.xfrm.setOffY( pxToMm(coords.y) );
3974
                        drawingObject.graphicObject.checkDrawingBaseCoords();
3975 3976 3977 3978 3979 3980
                        bNeedRecalc = true;
                    }
                }
            }
            if(bNeedRecalc)
            {
3981
                _this.controller.recalculate2();
3982 3983 3984
                _this.showDrawingObjects(true);
            }
        }, _this, []);
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3985
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003

    _this.checkCursorDrawingObject = function(x, y) {

        var offsets = _this.drawingArea.getOffsets(x, y);
        if ( offsets ) {
            var objectInfo = { cursor: null, id: null, object: null };
            var graphicObjectInfo = _this.controller.isPointInDrawingObjects( pxToMm(x - offsets.x), pxToMm(y - offsets.y) );

            if ( graphicObjectInfo && graphicObjectInfo.objectId ) {
                objectInfo.id = graphicObjectInfo.objectId;
                objectInfo.object = _this.getDrawingBase(graphicObjectInfo.objectId);
                objectInfo.cursor = graphicObjectInfo.cursorType;
                objectInfo.hyperlink = graphicObjectInfo.hyperlink;

                return objectInfo;
            }
        }
        return null;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
4004
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4005 4006 4007

    _this.getPositionInfo = function(x, y) {

4008
        var info = new CCellObjectInfo();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021

        var tmp = worksheet._findColUnderCursor(pxToPt(x), true);
        if (tmp) {
            info.col = tmp.col;
            info.colOff = pxToMm(x - worksheet.getCellLeft(info.col, 0));
        }
        tmp = worksheet._findRowUnderCursor(pxToPt(y), true);
        if (tmp) {
            info.row = tmp.row;
            info.rowOff = pxToMm(y - worksheet.getCellTop(info.row, 0));
        }

        return info;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
4022
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057

    //-----------------------------------------------------------------------------------
    // File Dialog
    //-----------------------------------------------------------------------------------

    _this.showImageFileDialog = function(documentId, documentFormat) {

        if ( _this.isViewerMode() )
            return;

        var frameWindow = GetUploadIFrame();
        var content = '<html><head></head><body><form action="' + g_sUploadServiceLocalUrl + '?sheetId=' + worksheet.model.getId() + '&key=' + documentId + '" method="POST" enctype="multipart/form-data"><input id="apiiuFile" name="apiiuFile" type="file" accept="image/*" size="1"><input id="apiiuSubmit" name="apiiuSubmit" type="submit" style="display:none;"></form></body></html>';
        frameWindow.document.open();
        frameWindow.document.write(content);
        frameWindow.document.close();

        var fileName = frameWindow.document.getElementById("apiiuFile");
        var fileSubmit = frameWindow.document.getElementById("apiiuSubmit");

        fileName.onchange = function(e) {
            var bNeedSubmit = true;
            if(e && e.target && e.target.files)
            {
                var nError = ValidateUploadImage(e.target.files);
                if(c_oAscServerError.NoError != nError)
                {
                    bNeedSubmit = false;
                    worksheet.model.workbook.handlers.trigger("asc_onError", api.asc_mapAscServerErrorToAscError(nError), c_oAscError.Level.NoCritical);
                }
            }
            if(bNeedSubmit)
            {
                worksheet.model.workbook.handlers.trigger("asc_onStartAction", c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.LoadImage);
                fileSubmit.click();
            }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
4058
        };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4059

Alexander.Trofimov's avatar
Alexander.Trofimov committed
4060
        if (AscBrowser.isOpera)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4061 4062 4063
            setTimeout(function() { fileName.click(); }, 0);
        else
            fileName.click();
Alexander.Trofimov's avatar
Alexander.Trofimov committed
4064
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084

    //-----------------------------------------------------------------------------------
    // Shapes controller
    //-----------------------------------------------------------------------------------


    //-----------------------------------------------------------------------------------
    // Private Misc Methods
    //-----------------------------------------------------------------------------------

    function ascCvtRatio(fromUnits, toUnits) {
        return asc.getCvtRatio( fromUnits, toUnits, drawingCtx.getPPIX() );
    }

    function setCanvasZIndex(canvas, value) {
        if (canvas && (value >= 0) && (value <= 1))
            canvas.globalAlpha = value;
    }

    function emuToPx(emu) {
4085
        return emu * 20 * 96 / 2.54 / 72 / 100 / 1000;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4086 4087 4088
    }

    function pxToEmu(px) {
4089
        return px * 2.54 * 72 * 100 * 1000 / 20 / 96;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4090 4091 4092
    }

    function pxToPt(val) {
4093
        return val * ascCvtRatio(0, 1);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4094 4095 4096
    }

    function ptToPx(val) {
4097
        return val * ascCvtRatio(1, 0);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4098 4099 4100
    }

    function ptToMm(val) {
4101
        return val * ascCvtRatio(1, 3);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4102 4103 4104
    }

    function mmToPx(val) {
4105
        return val * ascCvtRatio(3, 0);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4106 4107 4108
    }

    function mmToPt(val) {
4109
        return val * ascCvtRatio(3, 1);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4110 4111 4112
    }

    function pxToMm(val) {
4113
        return val * ascCvtRatio(0, 3);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4114
    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4115
}
4116 4117 4118 4119 4120 4121

//-----------------------------------------------------------------------------------
// Universal object locker/checker
//-----------------------------------------------------------------------------------

function ObjectLocker(ws) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141
    var asc = window["Asc"];
    var asc_applyFunction = asc.applyFunction;

    var _t = this;
    _t.bLock = true;
    var aObjectId = [];
    var worksheet = ws;

    _t.reset = function() {
        _t.bLock = true;
        aObjectId = [];
    };

    _t.addObjectId = function(id) {
        aObjectId.push(id);
    };

    // For array of objects -=Use reset before use=-
    _t.checkObjects = function(callback) {

4142
        function callbackEx(result, sync) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4143 4144 4145
            //if ( worksheet )
            //	worksheet._drawCollaborativeElements(true);
            if ( callback )
4146
                callback(result, sync);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4147 4148 4149 4150
        }

        if ( !aObjectId.length || (false === worksheet.collaborativeEditing.isCoAuthoringExcellEnable()) ) {
            // Запрещено совместное редактирование
4151
            asc_applyFunction(callbackEx, true, true);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162
            return;
        }

        var sheetId = worksheet.model.getId();
        worksheet.collaborativeEditing.onStartCheckLock();
        for ( var i = 0; i < aObjectId.length; i++ ) {

            var lockInfo = worksheet.collaborativeEditing.getLockInfo( c_oAscLockTypeElem.Object, /*subType*/null, sheetId, aObjectId[i] );

            if ( false === worksheet.collaborativeEditing.getCollaborativeEditing() ) {
                // Пользователь редактирует один: не ждем ответа, а сразу продолжаем редактирование
4163
                asc_applyFunction(callbackEx, true, true);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180
                callback = undefined;
            }
            if ( false !== worksheet.collaborativeEditing.getLockIntersection(lockInfo, c_oAscLockTypes.kLockTypeMine) ) {
                // Редактируем сами, проверяем дальше
                continue;
            }
            else if ( false !== worksheet.collaborativeEditing.getLockIntersection(lockInfo, c_oAscLockTypes.kLockTypeOther) ) {
                // Уже ячейку кто-то редактирует
                asc_applyFunction(callbackEx, false);
                return;
            }
            if ( _t.bLock )
                worksheet.collaborativeEditing.addCheckLock(lockInfo);
        }
        if ( _t.bLock )
            worksheet.collaborativeEditing.onEndCheckLock(callbackEx);
        else
4181
            asc_applyFunction(callbackEx, true, true);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4182
    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4183 4184
}

4185
function ClickCounter() {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213

    var _this = this;
    _this.x = 0;
    _this.y = 0;
    _this.button = 0;
    _this.time = 0;
    _this.clickCount = 0;
    _this.log = false;

    _this.mouseDownEvent = function(x, y, button) {

        var currTime = getCurrentTime();
        if ( (_this.button === button) && (_this.x === x) && (_this.y === y) && (currTime - _this.time < 500) ) {
            _this.clickCount = _this.clickCount + 1;
            _this.clickCount = Math.min(_this.clickCount, 3);
        }
        else
            _this.clickCount = 1;

        if ( _this.log ) {
            console.log("-----");
            console.log("x-> " + _this.x + " : " + x);
            console.log("y-> " + _this.y + " : " + y);
            console.log("Time: " + (currTime - _this.time));
            console.log("Count: " + _this.clickCount);
            console.log("");
        }
        _this.time = currTime;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
4214
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4215 4216 4217 4218 4219 4220 4221 4222 4223 4224

    _this.mouseMoveEvent = function(x, y) {
        if ( (_this.x != x) || (_this.y != y) ) {
            _this.x = x;
            _this.y = y;
            _this.clickCount = 0;

            if ( _this.log )
                console.log("Reset counter");
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
4225
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4226 4227 4228 4229

    _this.getClickCount = function() {
        return _this.clickCount;
    }
4230 4231
}

4232
function CoordsManager(ws) {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4233 4234 4235 4236 4237 4238

    var _t = this;
    var worksheet = ws;

    _t.calculateCell = function(x, y) {

4239
        var cell = new CCellObjectInfo();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302

        var _x = x + worksheet.getCellLeft(0, 0);
        var _y = y + worksheet.getCellTop(0, 0);

        var xPt = worksheet.objectRender.convertMetric(_x, 0, 1);
        var yPt = worksheet.objectRender.convertMetric(_y, 0, 1);

        var offsetX = worksheet.cols[worksheet.getFirstVisibleCol(true)].left - worksheet.cellsLeft;
        var offsetY = worksheet.rows[worksheet.getFirstVisibleRow(true)].top - worksheet.cellsTop;

        /* Проверки на максимум в листе */
        function isMaxCol() {
            var result = false;
            if ( worksheet.cols.length >= gc_nMaxCol )
                result = true;
            return result;
        }

        function isMaxRow() {
            var result = false;
            if ( worksheet.rows.length >= gc_nMaxRow )
                result = true;
            return result;
        }
        //

        var delta = 0;
        var what = roundPlus(xPt - offsetX, 3);
        var col = worksheet._findColUnderCursor( what, true );
        while (col == null) {
            if ( isMaxCol() ) {
                col = worksheet._findColUnderCursor( worksheet.cols[gc_nMaxCol - 1].left - 1, true );
                break;
            }
            worksheet.expandColsOnScroll(true);
            worksheet.handlers.trigger("reinitializeScrollX");
            col = worksheet._findColUnderCursor( what + delta, true );
            if ( what < 0 )
                delta++;
        }
        cell.col = col.col;
        cell.colOffPx = Math.max(0, _x - worksheet.getCellLeft(cell.col, 0));
        cell.colOff = worksheet.objectRender.convertMetric(cell.colOffPx, 0, 3);

        delta = 0;
        what = roundPlus(yPt - offsetY, 3);
        var row = worksheet._findRowUnderCursor( what, true );
        while (row == null) {
            if ( isMaxRow() ) {
                row = worksheet._findRowUnderCursor( worksheet.rows[gc_nMaxRow - 1].top - 1, true );
                break;
            }
            worksheet.expandRowsOnScroll(true);
            worksheet.handlers.trigger("reinitializeScrollY");
            row = worksheet._findRowUnderCursor( what + delta, true );
            if ( what < 0 )
                delta++;
        }
        cell.row = row.row;
        cell.rowOffPx = Math.max(0, _y - worksheet.getCellTop(cell.row, 0));
        cell.rowOff = worksheet.objectRender.convertMetric(cell.rowOffPx, 0, 3);

        return cell;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
4303
    };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4304 4305 4306 4307

    _t.calculateCoords = function(cell) {

        var coords = { x: 0, y: 0 };
4308
        //0 - px, 1 - pt, 2 - in, 3 - mm
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4309
        if ( cell ) {
4310 4311 4312 4313 4314 4315
            var rowHeight = worksheet.getRowHeight(cell.row, 3);
            var colWidth = worksheet.getColumnWidth(cell.col, 3);
            var resultRowOff = cell.rowOff > rowHeight ? rowHeight : cell.rowOff;
            var resultColOff = cell.colOff > colWidth ? colWidth : cell.colOff;
            coords.y = worksheet.getCellTop(cell.row, 0) + worksheet.objectRender.convertMetric(resultRowOff, 3, 0) - worksheet.getCellTop(0, 0);
            coords.x = worksheet.getCellLeft(cell.col, 0) + worksheet.objectRender.convertMetric(resultColOff, 3, 0) - worksheet.getCellLeft(0, 0);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4316 4317 4318
        }
        return coords;
    }
Dmitry.Vikulov's avatar
Dmitry.Vikulov committed
4319 4320
}

4321
//{ Common
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4322 4323


Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4324

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4325

4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343
var CARD_DIRECTION_N = 0;
var CARD_DIRECTION_NE = 1;
var CARD_DIRECTION_E = 2;
var CARD_DIRECTION_SE = 3;
var CARD_DIRECTION_S = 4;
var CARD_DIRECTION_SW = 5;
var CARD_DIRECTION_W = 6;
var CARD_DIRECTION_NW = 7;

var CURSOR_TYPES_BY_CARD_DIRECTION = [];
CURSOR_TYPES_BY_CARD_DIRECTION[CARD_DIRECTION_N]  = "n-resize";
CURSOR_TYPES_BY_CARD_DIRECTION[CARD_DIRECTION_NE] = "ne-resize";
CURSOR_TYPES_BY_CARD_DIRECTION[CARD_DIRECTION_E]  = "e-resize";
CURSOR_TYPES_BY_CARD_DIRECTION[CARD_DIRECTION_SE] = "se-resize";
CURSOR_TYPES_BY_CARD_DIRECTION[CARD_DIRECTION_S]  = "s-resize";
CURSOR_TYPES_BY_CARD_DIRECTION[CARD_DIRECTION_SW] = "sw-resize";
CURSOR_TYPES_BY_CARD_DIRECTION[CARD_DIRECTION_W]  = "w-resize";
CURSOR_TYPES_BY_CARD_DIRECTION[CARD_DIRECTION_NW] = "nw-resize";