Presentation.js 176 KB
Newer Older
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1 2
"use strict";

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3
var History = null;
4
var recalcSlideInterval = 30;
5

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
function SlideCopyObject(Slide, ImageUrl)
{
    this.Slide = Slide;
    this.ImageUrl = ImageUrl;
}

function DrawingCopyObject(Drawing, X, Y, ExtX, ExtY, ImageUrl)
{
    this.Drawing = Drawing;
    this.X = X;
    this.Y = Y;
    this.ExtX = ExtX;
    this.ExtY = ExtY;
    this.ImageUrl = ImageUrl;
}

function PresentationSelectedContent()
{
    this.SlideObjects = [];
    this.Drawings = [];
    this.DocContent = null;
}

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
function CreatePresentationTableStyles(Styles, IdMap)
{
    function CreateMiddleStyle2(schemeId)
    {
        var style = new CStyle("Middle Style 2 - accent " + (schemeId + 1), null, null, styletype_Table);
        //style.Id = "{" + GUID() + "}";
        style.TablePr.Set_FromObject(
            {
                TableBorders:
                {
                    Left:
                    {
                        Color : { r : 0, g : 0, b : 0 },
                        Unifill : CreateUnifillSolidFillSchemeColor(12, 0),
                        Space : 0,
                        Size  : 12700/36000,
                        Value : border_Single
                    },

                    Right:
                    {
                        Color : { r : 0, g : 0, b : 0 },
                        Unifill : CreateUnifillSolidFillSchemeColor(12, 0),
                        Space : 0,
                        Size  : 12700/36000,
                        Value : border_Single
                    },

                    Top:
                    {
                        Color : { r : 0, g : 0, b : 0 },
                        Unifill : CreateUnifillSolidFillSchemeColor(12, 0),
                        Space : 0,
                        Size  : 12700/36000,
                        Value : border_Single
                    },

                    Bottom:
                    {
                        Color : { r : 0, g : 0, b : 0 },
                        Unifill : CreateUnifillSolidFillSchemeColor(12, 0),
                        Space : 0,
                        Size  : 12700/36000,
                        Value : border_Single
                    },

                    InsideH:
                    {
                        Color : { r : 0, g : 0, b : 0 },
                        Unifill : CreateUnifillSolidFillSchemeColor(12, 0),
                        Space : 0,
                        Size  : 12700/36000,
                        Value : border_Single
                    },

                    InsideV:
                    {
                        Color : { r : 0, g : 0, b : 0 },
                        Unifill : CreateUnifillSolidFillSchemeColor(12, 0),
                        Space : 0,
                        Size  : 12700/36000,
                        Value : border_Single
                    }
                }
            }
        );
        style.TableWholeTable.Set_FromObject(
            {
                TextPr:
                {
                    FontRef: CreateFontRef(fntStyleInd_minor, CreatePresetColor("black")),
                    Unifill:  CreateUnifillSolidFillSchemeColor(8, 0)
                },
                TableCellPr:
                {
                    Shd:
                    {
                        Unifill: CreateUnifillSolidFillSchemeColor(schemeId, 0.2)
                    }
                }
            }
        );
        var styleObject =    {
            TableCellPr:
            {
                Shd:
                {
                    Unifill: CreateUnifillSolidFillSchemeColor(schemeId, 0.4)
                }
            }
        };
        style.TableBand1Horz.Set_FromObject(styleObject);
        style.TableBand1Vert.Set_FromObject(styleObject);

        styleObject = {
            TextPr:
            {
                Bold: true,
                FontRef: CreateFontRef(fntStyleInd_minor, CreatePresetColor("black")),
                Unifill:  CreateUnifillSolidFillSchemeColor(8, 0)
            },
            TableCellPr:
            {
                Shd:
                {
                    Unifill: CreateUnifillSolidFillSchemeColor(schemeId, 0)
                }
            }
        };
        style.TableLastCol.Set_FromObject(styleObject);
        style.TableFirstCol.Set_FromObject(styleObject);

        styleObject.TableCellPr.TableCellBorders =
        {
            Top:
            {
                Color : { r : 0, g : 0, b : 0 },
                Unifill : CreateUnifillSolidFillSchemeColor(12, 0),
                Space : 0,
                Size  : 38100/36000,
                Value : border_Single
            }
        };
        style.TableLastRow.Set_FromObject(styleObject);
        styleObject.TableCellPr.TableCellBorders =
        {
            Bottom:
            {
                Color : { r : 0, g : 0, b : 0 },
                Unifill : CreateUnifillSolidFillSchemeColor(12, 0),
                Space : 0,
                Size  : 38100/36000,
                Value : border_Single
            }
        };
        styleObject.TextPr =
        {
            Bold: true,
            FontRef: CreateFontRef(fntStyleInd_minor, CreatePresetColor("black")),
            Unifill:  CreateUnifillSolidFillSchemeColor(12, 0)
        };
        style.TableFirstRow.Set_FromObject(styleObject);
        return style;
    }
    var def = CreateMiddleStyle2(0), style;

    style = CreateMiddleStyle2(8);
    Styles.Add(style);
    IdMap[style.Id] = true;

    Styles.Add(def);
    IdMap[def.Id] = true;
    for(var i = 1; i < 6; ++i)
    {
        style = CreateMiddleStyle2(i);
        Styles.Add(style);
        IdMap[style.Id] = true;
    }


    return def.Id;
}

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
192 193 194 195 196 197 198
function CPresentation(DrawingDocument)
{
    this.History = new CHistory(this);
    History = this.History;

    // Создаем глобальные объекты, необходимые для совместного редактирования

199
    g_oTableId = new CTableId();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
200 201 202 203 204 205 206 207 208 209

    //------------------------------------------------------------------------

    this.Id = g_oIdCounter.Get_NewId();

    this.StartPage = 0; // Для совместимости с CDocumentContent
    this.CurPage   = 0;

    this.Orientation = orientation_Portrait; // ориентация страницы

210
    this.slidesToUnlock = [];
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
211 212 213 214 215 216


    this.TurnOffRecalc = false;

    this.DrawingDocument = DrawingDocument;

217 218
    this.SearchEngine = new CDocumentSearch();

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
219 220
    this.NeedUpdateTarget = false;

221 222
    this.noShowContextMenu = false;

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
    this.viewMode = false;
    // Класс для работы с поиском
    this.SearchInfo =
    {
        Id       : null,
        StartPos : 0,
        CurPage  : 0,
        String   : null
    };

    // Позция каретки
    this.TargetPos =
    {
        X       : 0,
        Y       : 0,
        PageNum : 0
    };

    this.CopyTextPr = null; // TextPr для копирования по образцу
    this.CopyParaPr = null; // ParaPr для копирования по образцу


    this.Lock = new CLock();

    this.m_oContentChanges = new CContentChanges(); // список изменений(добавление/удаление элементов)


    this.Slides = [];
    this.themes       = [];
    this.slideMasters = [];
    this.slideLayouts = [];
    this.notesMasters = [];
    this.notes        = [];
256
    this.globalTableStyles = null;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
257

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
258
    this.updateSlideIndex = false;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
259
    this.recalcMap = {};
260
    this.bClearSearch = true;
261
    this.bNeedUpdateTh = false;
262
    this.needSelectPages = [];
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
263 264 265 266

    this.forwardChangeThemeTimeOutId = null;
    this.backChangeThemeTimeOutId = null;
    this.startChangeThemeTimeOutId = null;
267 268 269 270 271
    this.TablesForInterface = null;
    this.LastTheme = null;
    this.LastColorScheme = null;
    this.LastColorMap = null;
    this.LastTableLook = null;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
272 273
    this.DefaultSlideTiming = new CAscSlideTiming();
    this.DefaultSlideTiming.setDefaultParams();
274 275

    this.DefaultTableStyleId = null;
276
    this.TableStylesIdMap = {};
277
    this.bNeedUpdateChartPreview = false;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
278 279
    // Добавляем данный класс в таблицу Id (обязательно в конце конструктора)
    g_oTableId.Add( this, this.Id );
280 281 282 283
   //
   this.themeLock = new PropLocker(this.Id);
   this.schemeLock = new PropLocker(this.Id);
   this.slideSizeLock = new PropLocker(this.Id);
Oleg.Korshul's avatar
Oleg.Korshul committed
284 285

    this.CommentAuthors = {};
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
286
    this.createDefaultTableStyles();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
287
    this.bGoToPage = false;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
288 289 290 291
}

CPresentation.prototype =
{
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
292 293
    createDefaultTableStyles: function()
    {
294
        //ExecuteNoHistory(function(){
295
            this.globalTableStyles = new CStyles();
296 297
            this.DefaultTableStyleId = CreatePresentationTableStyles(this.globalTableStyles, this.TableStylesIdMap);
        //}, this, []);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
298
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
299 300 301 302 303 304
    // Проводим начальные действия, исходя из Документа
    Init : function()
    {

    },

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
305 306
    addSlideMaster: function(pos, master)
    {
307
        History.Add(this, {Type: historyitem_Presentation_AddSlideMaster, pos: pos, master: master});
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
308 309 310
        this.slideMasters.splice(pos, 0, master);
    },

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
    Get_Id : function()
    {
        return this.Id;
    },

    Set_Id : function(newId)
    {
        g_oTableId.Reset_Id( this, newId, this.Id );
        this.Id = newId;
    },

    LoadEmptyDocument : function()
    {
        this.DrawingDocument.TargetStart();
        this.Recalculate();

        this.Interface_Update_ParaPr();
        this.Interface_Update_TextPr();
    },

331 332

    GetRecalculateMaps: function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
333
    {
334 335 336 337
        var ret = {
            layouts: {},
            masters: {}
        };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
338

339
        for(var i = 0; i < this.Slides.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
340
        {
341 342 343 344 345 346 347 348
            if(this.Slides[i].Layout)
            {
                ret.layouts[this.Slides[i].Layout.Id] = this.Slides[i].Layout;
                if(this.Slides[i].Layout.Master)
                {
                    ret.masters[this.Slides[i].Layout.Master.Id] = this.Slides[i].Layout.Master;
                }
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
349
        }
350 351
        return ret;
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
352 353


354 355
    Recalculate : function(RecalcData)
    {
Oleg.Korshul's avatar
Oleg.Korshul committed
356 357 358 359 360 361 362 363 364 365 366
        if (undefined === RecalcData)
        {
            // Проверяем можно ли сделать быстрый пересчет
            var SimpleChanges = History.Is_SimpleChanges();
            if ( 1 === SimpleChanges.length )
            {
                var Run  = SimpleChanges[0].Class;
                var Para = Run.Paragraph;
                var Res  = Para.Recalculate_FastRange( SimpleChanges );
                if ( -1 !== Res )
                {
367 368 369 370 371 372
                    if( this.Slides[this.CurPage])
                    {
                        this.DrawingDocument.OnRecalculatePage(this.CurPage, this.Slides[this.CurPage]);
                        this.DrawingDocument.OnEndRecalculate();
                    }
                    History.Reset_RecalcIndex();
Oleg.Korshul's avatar
Oleg.Korshul committed
373 374 375 376
                    return;
                }
            }
        }
377 378 379 380 381
        if(this.bClearSearch)
        {
            this.SearchEngine.Clear();
            this.bClearSearch = false;
        }
382 383
        var _RecalcData = RecalcData ? RecalcData : History.Get_RecalcData(), key, recalcMap, bSync = true, i, bRedrawAllSlides = false, aToRedrawSlides = [], redrawSlideIndexMap = {}, slideIndex;
        this.updateSlideIndexes();
384
        var b_check_layout = false;
385
        if(_RecalcData.Drawings.All || _RecalcData.Drawings.ThemeInfo)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
386
        {
387
            b_check_layout = true;
388 389
            recalcMap = this.GetRecalculateMaps();
            for(key in recalcMap.masters)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
390
            {
391
                if(recalcMap.masters.hasOwnProperty(key))
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
392
                {
393
                    recalcMap.masters[key].recalculate();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
394
                }
395 396 397 398
            }
            for(key in recalcMap.layouts)
            {
                if(recalcMap.layouts.hasOwnProperty(key))
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
399
                {
400 401 402
                    recalcMap.layouts[key].recalculate();
                }
            }
403
            this.bNeedUpdateChartPreview = true;
404 405 406 407 408 409 410 411 412 413
            if(_RecalcData.Drawings.ThemeInfo)
            {
                this.clearThemeTimeouts();
                var startRecalcIndex = _RecalcData.Drawings.ThemeInfo.ArrInd.indexOf(this.CurPage);
                if(startRecalcIndex === -1)
                {
                    startRecalcIndex = 0;
                }
                var oThis = this;
                bSync = false;
414 415
                aToRedrawSlides = [].concat(_RecalcData.Drawings.ThemeInfo.ArrInd);
                redrawSlide(oThis.Slides[_RecalcData.Drawings.ThemeInfo.ArrInd[startRecalcIndex]], oThis, aToRedrawSlides, startRecalcIndex,  0, oThis.Slides);
416 417 418
            }
            else
            {
419
                bRedrawAllSlides = true;
420 421
                for(key = 0; key < this.Slides.length; ++key)
                {
422
                    this.Slides[key].recalcText();
423
                    this.Slides[key].recalculate()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
424 425 426
                }
            }
        }
427
        else
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
428
        {
429 430 431 432 433
            for(key in _RecalcData.Drawings.Map)
            {
                if(_RecalcData.Drawings.Map.hasOwnProperty(key))
                {
                    _RecalcData.Drawings.Map[key].recalculate();
434 435 436 437 438 439 440 441 442 443 444 445
                    if(_RecalcData.Drawings.Map[key].getSlideIndex)
                    {
                        slideIndex = _RecalcData.Drawings.Map[key].getSlideIndex();
                        if(slideIndex !== null)
                        {
                            if(redrawSlideIndexMap[slideIndex] !== true )
                            {
                                redrawSlideIndexMap[slideIndex] = true;
                                aToRedrawSlides.push(slideIndex);
                            }
                        }
                    }
446 447
                }
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
448
        }
449
        History.Reset_RecalcIndex();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
450
        this.RecalculateCurPos();
451
        if(bSync)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
452
        {
453 454 455 456 457 458 459 460
            if(bRedrawAllSlides)
            {
                for(i = 0; i < this.Slides.length; ++i)
                {
                    this.DrawingDocument.OnRecalculatePage(i, this.Slides[i]);
                }
            }
            else
461
            {
462 463 464 465 466
                aToRedrawSlides.sort(fSortAscending);
                for(i = 0; i < aToRedrawSlides.length; ++i)
                {
                    this.DrawingDocument.OnRecalculatePage(aToRedrawSlides[i], this.Slides[aToRedrawSlides[i]]);
                }
467 468
            }
            this.DrawingDocument.OnEndRecalculate();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
469
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
470 471 472 473 474 475
        if(!this.Slides[this.CurPage])
        {
            this.DrawingDocument.m_oWordControl.GoToPage(this.Slides.length - 1);

            //this.Set_CurPage(this.Slides.length - 1);
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
476 477 478 479 480 481 482
        else
        {
            if(this.bGoToPage)
            {
                this.DrawingDocument.m_oWordControl.GoToPage(this.CurPage);
                this.bGoToPage = false;
            }
483 484 485 486
            else if(b_check_layout)
            {
                this.DrawingDocument.m_oWordControl.CheckLayouts();
            }
487 488 489 490 491 492 493 494
            if(this.needSelectPages.length > 0)
            {
                //for(slideIndex = 0; i < this.needSelectPages.length; ++i)
                //{
                //    this.DrawingDocument.SelectPage(this.needSelectPages[slideIndex]);
                //}
                this.needSelectPages.length = 0;
            }
495 496 497 498 499
            if(this.bNeedUpdateTh)
            {
                this.DrawingDocument.UpdateThumbnailsAttack();
                this.bNeedUpdateTh = false;
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
500
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
501 502
        if(this.Slides[this.CurPage])
            this.Slides[this.CurPage].graphicObjects.updateSelectionState();
503
        for(i = 0; i < this.slidesToUnlock.length; ++i)
504 505 506 507
        {
            this.DrawingDocument.UnLockSlide(this.slidesToUnlock[i]);
        }
        this.slidesToUnlock.length = 0;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
508 509
    },

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
510 511 512 513 514 515 516 517
    updateSlideIndexes: function()
    {
        for(var i = 0; i < this.Slides.length; ++i)
        {
            this.Slides[i].changeNum(i);
        }
    },

Oleg.Korshul's avatar
Oleg.Korshul committed
518 519 520 521 522 523 524 525 526 527 528 529 530 531
    GenerateThumbnails : function(_drawerThemes, _drawerLayouts)
    {
        var _masters = this.slideMasters;
        var _len = _masters.length;
        for (var i = 0; i < _len; i++)
        {
            _masters[i].ImageBase64 = _drawerThemes.GetThumbnail(_masters[i]);
        }

        var _layouts = this.slideLayouts;
        _len = _layouts.length;
        for (var i = 0; i < _len; i++)
        {
            _layouts[i].ImageBase64 = _drawerLayouts.GetThumbnail(_layouts[i]);
Oleg.Korshul's avatar
Oleg.Korshul committed
532 533
            _layouts[i].Width64 = _drawerLayouts.WidthPx;
            _layouts[i].Height64 = _drawerLayouts.HeightPx;
Oleg.Korshul's avatar
Oleg.Korshul committed
534 535
        }
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
536

537
    Stop_Recalculate : function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
538
    {
539 540
        this.DrawingDocument.OnStartRecalculate( 0 );
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
541

542 543 544
    OnContentReDraw : function(StartPage, EndPage)
    {
        this.ReDraw( StartPage, EndPage );
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
545 546
    },

547
    CheckTargetUpdate : function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
548
    {
549
        if (this.DrawingDocument.UpdateTargetFromPaint === true)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
550
        {
551 552 553
            if (true === this.DrawingDocument.UpdateTargetCheck)
                this.NeedUpdateTarget = this.DrawingDocument.UpdateTargetCheck;
            this.DrawingDocument.UpdateTargetCheck = false;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
554 555
        }

556 557 558 559 560 561
        if ( true === this.NeedUpdateTarget)
        {
            this.RecalculateCurPos();
            this.NeedUpdateTarget = false;
        }
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
562

563 564 565 566 567
    RecalculateCurPos : function()
    {
        if(this.Slides[this.CurPage])
            this.Slides[this.CurPage].graphicObjects.recalculateCurPos();
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
568

569 570 571 572 573 574
    Set_TargetPos : function(X, Y, PageNum)
    {
        this.TargetPos.X       = X;
        this.TargetPos.Y       = Y;
        this.TargetPos.PageNum = PageNum;
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
575

576 577 578 579 580 581 582
    // Вызываем перерисовку нужных страниц
    ReDraw : function(StartPage, EndPage)
    {
        if ( "undefined" === typeof(StartPage) )
            StartPage = 0;
        if ( "undefined" === typeof(EndPage) )
            EndPage = this.DrawingDocument.m_lCountCalculatePages;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
583

584 585 586
        for ( var CurPage = StartPage; CurPage <= EndPage; CurPage++ )
            this.DrawingDocument.OnRepaintPage( CurPage );
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
587

588 589 590 591
    DrawPage : function(nPageIndex, pGraphics)
    {
        this.Draw( nPageIndex, pGraphics);
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
592

593 594 595 596 597
    // Отрисовка содержимого Документа
    Draw : function(nPageIndex, pGraphics)
    {
        this.Slides[nPageIndex] && this.Slides[nPageIndex].draw(pGraphics);
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
598 599 600

    Add_NewParagraph : function(bRecalculate)
    {
601
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.addNewParagraph, []);
602
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
603 604
    },

605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 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 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 837 838 839 840 841 842 843
    Search : function(Str, Props)
    {
        if ( true === this.SearchEngine.Compare( Str, Props ) )
            return this.SearchEngine;
        this.SearchEngine.Clear();
        this.SearchEngine.Set( Str, Props );

        for(var i = 0; i < this.Slides.length; ++i)
        {
            this.Slides[i].Search( Str, Props, this.SearchEngine, search_Common );
        }
        this.DrawingDocument.ClearCachePages();
        this.DrawingDocument.FirePaint();
        this.bClearSearch = true;
        return this.SearchEngine;
    },

    Search_GetId : function(isNext)
    {
        if(this.Slides.length > 0)
        {
            var i, Id, content, start_index;
            var target_text_object = getTargetTextObject(this.Slides[this.CurPage].graphicObjects);
            if(target_text_object)
            {
                if(target_text_object.getObjectType() === historyitem_type_GraphicFrame)
                {
                    Id = target_text_object.graphicObject.Search_GetId(isNext, true);
                    if(Id !== null)
                    {
                        return Id;
                    }
                }
                else
                {
                    content = target_text_object.getDocContent();
                    if(content)
                    {
                        Id = content.Search_GetId(isNext, true);
                        if(Id !== null)
                        {
                            return Id;
                        }
                    }
                }
            }
            var sp_tree = this.Slides[this.CurPage].cSld.spTree, group_shapes, group_start_index;
            if(isNext)
            {
                if(this.Slides[this.CurPage].graphicObjects.selection.groupSelection)
                {
                    group_shapes = this.Slides[this.CurPage].graphicObjects.selection.groupSelection.arrGraphicObjects;
                    for(i = 0; i < group_shapes.length; ++i)
                    {
                        if(group_shapes[i].selected && group_shapes[i].getObjectType() === historyitem_type_Shape)
                        {
                            content = group_shapes[i].getDocContent();
                            if(content)
                            {
                                Id = content.Search_GetId(isNext, isRealObject(target_text_object));
                                if(Id !== null)
                                {
                                    return Id;
                                }
                            }
                            group_start_index = i + 1;
                        }
                    }
                    for(i = group_start_index; i < group_shapes.length; ++i)
                    {
                        if(group_shapes[i].getObjectType() === historyitem_type_Shape)
                        {
                            content = group_shapes[i].getDocContent();
                            if(content)
                            {
                                Id = content.Search_GetId(isNext, false);
                                if(Id !== null)
                                {
                                    return Id;
                                }
                            }
                        }
                    }

                    for(i = 0; i < sp_tree.length; ++i)
                    {
                        if(sp_tree[i] === this.Slides[this.CurPage].graphicObjects.selection.groupSelection)
                        {
                            start_index = i + 1;
                            break;
                        }
                    }
                    if(i === sp_tree.length)
                    {
                        start_index = sp_tree.length;
                    }
                }
                else if(this.Slides[this.CurPage].graphicObjects.selectedObjects.length === 0)
                {
                    start_index = 0;
                }
                else
                {
                    for(i = 0; i < sp_tree.length; ++i)
                    {
                        if(sp_tree[i].selected)
                        {
                            start_index =  target_text_object ? i + 1 : i;
                            break;
                        }
                    }
                    if(i === sp_tree.length)
                    {
                        start_index = sp_tree.length;
                    }
                }
                Id = this.Slides[this.CurPage].Search_GetId(isNext, start_index);
                if(Id !== null)
                {
                    return Id;
                }
                for(i = this.CurPage + 1; i < this.Slides.length; ++i)
                {
                    Id = this.Slides[i].Search_GetId(isNext, 0);
                    if(Id !== null)
                    {
                        return Id;
                    }
                }
                for(i = 0; i < this.CurPage; ++i)
                {
                    Id = this.Slides[i].Search_GetId(isNext, 0);
                    if(Id !== null)
                    {
                        return Id;
                    }
                }
            }
            else
            {
                if(this.Slides[this.CurPage].graphicObjects.selection.groupSelection)
                {
                    group_shapes = this.Slides[this.CurPage].graphicObjects.selection.groupSelection.arrGraphicObjects;
                    for(i = group_shapes.length - 1; i > -1; --i)
                    {
                        if(group_shapes[i].selected && group_shapes[i].getObjectType() === historyitem_type_Shape)
                        {
                            content = group_shapes[i].getDocContent();
                            if(content)
                            {
                                Id = content.Search_GetId(isNext, isRealObject(target_text_object));
                                if(Id !== null)
                                {
                                    return Id;
                                }
                            }
                            group_start_index = i - 1;
                        }
                    }
                    for(i = group_start_index; i > -1; --i)
                    {
                        if(group_shapes[i].getObjectType() === historyitem_type_Shape)
                        {
                            content = group_shapes[i].getDocContent();
                            if(content)
                            {
                                Id = content.Search_GetId(isNext, false);
                                if(Id !== null)
                                {
                                    return Id;
                                }
                            }
                        }
                    }

                    for(i = 0; i < sp_tree.length; ++i)
                    {
                        if(sp_tree[i] === this.Slides[this.CurPage].graphicObjects.selection.groupSelection)
                        {
                            start_index = i - 1;
                            break;
                        }
                    }
                    if(i === sp_tree.length)
                    {
                        start_index = sp_tree.length;
                    }
                }
                else if(this.Slides[this.CurPage].graphicObjects.selectedObjects.length === 0)
                {
                    start_index = sp_tree.length - 1;
                }
                else
                {
                    for(i = sp_tree.length - 1; i > -1; --i)
                    {
                        if(sp_tree[i].selected)
                        {
                            start_index = target_text_object ? i - 1 : i;
                            break;
                        }
                    }
                    if(i === sp_tree.length)
                    {
                        start_index = -1;
                    }
                }
                Id = this.Slides[this.CurPage].Search_GetId(isNext, start_index);
                if(Id !== null)
                {
                    return Id;
                }
                for(i = this.CurPage - 1; i > -1; --i)
                {
                    Id = this.Slides[i].Search_GetId(isNext, this.Slides[i].cSld.spTree.length - 1);
                    if(Id !== null)
                    {
                        return Id;
                    }
                }
                for(i = this.Slides.length - 1; i > this.CurPage; --i)
                {
                    Id = this.Slides[i].Search_GetId(isNext, this.Slides[i].cSld.spTree.length - 1);
                    if(Id !== null)
                    {
                        return Id;
                    }
                }
            }
        }
        return null;
    },

    Search_Select : function(Id)
    {
        this.SearchEngine.Select(Id);

        this.Document_UpdateInterfaceState();
        this.Document_UpdateSelectionState();
844
       // this.Document_UpdateRulersState();
845 846 847
        editor.WordControl.OnUpdateOverlay();
    },

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
    findText: function(text, scanForward)
    {
        if(typeof(text) != "string")
        {
            return;
        }
        if(scanForward === undefined)
        {
            scanForward = true;
        }

        var slide_num;
        var search_select_data = null;
        if(scanForward)
        {
            for(slide_num = this.CurPage; slide_num < this.Slides.length; ++slide_num)
            {
                search_select_data = this.Slides[slide_num].graphicObjects.startSearchText(text, scanForward);
                if(search_select_data != null)
                {
                    this.DrawingDocument.m_oWordControl.GoToPage(slide_num);
                    this.Slides[slide_num].graphicObjects.setSelectionState(search_select_data);
                    this.Document_UpdateSelectionState();
                    return true;
                }
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
874
            for(slide_num = 0; slide_num <= this.CurPage; ++slide_num)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
875
            {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
876
                search_select_data = this.Slides[slide_num].graphicObjects.startSearchText(text, scanForward, true);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898
                if(search_select_data != null)
                {
                    this.DrawingDocument.m_oWordControl.GoToPage(slide_num);
                    this.Slides[slide_num].graphicObjects.setSelectionState(search_select_data);
                    this.Document_UpdateSelectionState();
                    return true;
                }
            }
        }
        else
        {
            for(slide_num = this.CurPage; slide_num > -1; --slide_num)
            {
                search_select_data = this.Slides[slide_num].graphicObjects.startSearchText(text, scanForward);
                if(search_select_data != null)
                {
                    this.DrawingDocument.m_oWordControl.GoToPage(slide_num);
                    this.Slides[slide_num].graphicObjects.setSelectionState(search_select_data);
                    this.Document_UpdateSelectionState();
                    return true;
                }
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
899
            for(slide_num = this.Slides.length - 1; slide_num >= this.CurPage; --slide_num)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
900
            {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
901
                search_select_data = this.Slides[slide_num].graphicObjects.startSearchText(text, scanForward, true);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
902 903 904 905 906 907 908 909 910
                if(search_select_data != null)
                {
                    this.DrawingDocument.m_oWordControl.GoToPage(slide_num);
                    this.Slides[slide_num].graphicObjects.setSelectionState(search_select_data);
                    this.Document_UpdateSelectionState();
                    return true;
                }
            }
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
911

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
912 913 914
        return false;
    },

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
915 916
    groupShapes: function()
    {
917
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.createGroup, []);
918
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
919 920
    },

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
921 922
    unGroupShapes: function()
    {
923
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.unGroupCallback, []);
924
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
925 926
    },

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
927 928
    Add_FlowImage : function(W, H, Img)
    {
929
        if(this.Slides[this.CurPage])
930
        {
931 932 933 934 935
            History.Create_NewPoint();
            var Image = this.Slides[this.CurPage].graphicObjects.createImage(Img, (this.Slides[this.CurPage].Width - W)/2, (this.Slides[this.CurPage].Height - H)/2, W, H);
            Image.setParent(this.Slides[this.CurPage]);
            Image.addToDrawingObjects();
            this.Slides[this.CurPage].graphicObjects.resetSelection();
936
            this.Slides[this.CurPage].graphicObjects.selectObject(Image, 0);
937
            this.Recalculate();
938
            this.Document_UpdateInterfaceState();
939 940
        }
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
941

942
    addChart: function(binary)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
943
    {
944 945
        var _this = this;
        _this.Slides[_this.CurPage] && _this.Slides[_this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
946
        {
947 948 949 950 951 952
            var Image = _this.Slides[_this.CurPage].graphicObjects.getChartSpace2(binary, null);
            Image.setParent(_this.Slides[_this.CurPage]);
            Image.addToDrawingObjects();
            Image.spPr.xfrm.setOffX((_this.Slides[_this.CurPage].Width - Image.spPr.xfrm.extX)/2);
            Image.spPr.xfrm.setOffY((_this.Slides[_this.CurPage].Height - Image.spPr.xfrm.extY)/2);
            _this.Slides[_this.CurPage].graphicObjects.resetSelection();
953
            _this.Slides[_this.CurPage].graphicObjects.selectObject(Image, 0);
954
            _this.Document_UpdateInterfaceState();
955
        }, []);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
956 957
    },

958 959 960
    Selection_Remove: function()
    {},

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
961
    Edit_Chart : function(binary)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
962
    {
963 964 965 966
        var _this = this;
        _this.Slides[_this.CurPage] && _this.Slides[_this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(function()
        {
            _this.Slides[_this.CurPage].graphicObjects.editChart(binary);
967
            _this.Document_UpdateInterfaceState();
968
        }, [binary]);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
969 970
    },

971
    Get_ChartObject: function(type)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
972
    {
973
        return this.Slides[this.CurPage].graphicObjects.getChartObject(type);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
974 975
    },

976 977 978 979 980 981 982 983 984 985
    Check_GraphicFrameRowHeight: function(grFrame)
    {
        grFrame.recalculate();
        var content = grFrame.graphicObject.Content, i;
        for(i = 0; i < content.length; ++i)
        {
            content[i].Set_Height(content[i].Height, heightrule_AtLeast );
        }
    },

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
986 987
    Add_FlowTable : function(Cols, Rows)
    {
988 989
        if(!this.Slides[this.CurPage])
            return;
990

991
        History.Create_NewPoint();
992
        var graphic_frame = this.Create_TableGraphicFrame(Cols, Rows, this.Slides[this.CurPage], this.DefaultTableStyleId);
993 994 995
        if(this.Document_Is_SelectionLocked(changestype_AddShape, graphic_frame) === false)
        {
            this.Slides[this.CurPage].graphicObjects.resetSelection();
996
            this.Slides[this.CurPage].graphicObjects.selectObject(graphic_frame, 0);
997
            this.Check_GraphicFrameRowHeight(graphic_frame);
998
            this.Slides[this.CurPage].addToSpTreeToPos(this.Slides[this.CurPage].cSld.spTree.length, graphic_frame);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
999
            this.Recalculate();
1000

1001
            this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1002
        }
1003 1004 1005 1006
        else
        {
            this.Document_Undo();
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1007 1008
    },

1009

1010
    Create_TableGraphicFrame : function(Cols, Rows, Parent, StyleId, Width, Height, PosX, PosY, bInline)
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
    {
        var W;
        if(isRealNumber(Width))
        {
            W = Width;
        }
        else
        {
            W = this.Width*2/3;
        }
        var X, Y;
        if(isRealNumber(PosX) && isRealNumber(PosY))
        {
            X = PosX;
            Y = PosY;
        }
        else
        {
            X = 0;
            Y = 0;
        }
1032 1033 1034 1035 1036
        var Inline = false;
        if(isRealBool(bInline))
        {
            Inline = bInline;
        }
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
        var Grid = [];

        for ( var Index = 0; Index < Cols; Index++ )
            Grid[Index] = W / Cols;

        var RowHeight;
        if(isRealNumber(Height))
        {
            RowHeight = Height / Rows;
        }

        var graphic_frame = new CGraphicFrame();
        graphic_frame.setParent(Parent);
        graphic_frame.setSpPr(new CSpPr());
        graphic_frame.spPr.setParent(graphic_frame);
        graphic_frame.spPr.setXfrm(new CXfrm());
        graphic_frame.spPr.xfrm.setParent(graphic_frame.spPr);
        graphic_frame.spPr.xfrm.setOffX((this.Width - W)/2);
        graphic_frame.spPr.xfrm.setOffY(this.Height/5);
        graphic_frame.spPr.xfrm.setExtX(W);
        graphic_frame.spPr.xfrm.setExtY(7.478268771701388 * Rows);
        graphic_frame.setNvSpPr(new UniNvPr());

1060 1061 1062 1063 1064 1065
        var table = new CTable(this.DrawingDocument, graphic_frame, Inline, 0, X, Y, W, 100000, Rows, Cols, Grid, true);
        if(!Inline)
        {
            table.Set_PositionH(c_oAscHAnchor.Page, false, 0);
            table.Set_PositionV(c_oAscVAnchor.Page, false, 0);
        }
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
        table.Set_TableLayout(tbllayout_Fixed);
        if(typeof StyleId === "string")
        {
            table.Set_TableStyle(StyleId);
        }
        table.Set_TableLook(new CTableLook(false, true, false, false, true, false));
        for(var i = 0; i < table.Content.length; ++i)
        {
            var Row = table.Content[i];
            if(isRealNumber(RowHeight))
            {
                Row.Set_Height(RowHeight, heightrule_AtLeast);
            }
            //for(var j = 0; j < Row.Content.length; ++j)
            //{
            //    var cell = Row.Content[j];
            //    var props = new CTableCellPr();
            //    props.TableCellMar = {};
            //    props.TableCellMar.Top    = new CTableMeasurement(tblwidth_Mm, 1.27);
            //    props.TableCellMar.Left   = new CTableMeasurement(tblwidth_Mm, 2.54);
            //    props.TableCellMar.Bottom = new CTableMeasurement(tblwidth_Mm, 1.27);
            //    props.TableCellMar.Right  = new CTableMeasurement(tblwidth_Mm, 2.54);
            //    props.Merge(cell.Pr);
            //    cell.Set_Pr(props);
            //}
        }
        graphic_frame.setGraphicObject(table);
        graphic_frame.setBDeleted(false);
        return graphic_frame;
    },


1098 1099 1100
    Paragraph_Add : function( ParaItem, bRecalculate )
    {
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.paragraphAdd, [ParaItem, bRecalculate]);
1101

1102 1103 1104 1105 1106
    },

    Paragraph_ClearFormatting : function()
    {
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.paragraphClearFormatting, []);
1107
        this.Document_UpdateInterfaceState();
1108 1109 1110
    },

    Remove : function(Count, bOnlyText, bRemoveOnlySelection)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1111
    {
1112
        if(editor.WordControl.Thumbnails.FocusObjType === FOCUS_OBJECT_THUMBNAILS)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1113
        {
1114 1115
            this.deleteSlides(editor.WordControl.Thumbnails.GetSelectedArray());
            return;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1116
        }
1117 1118 1119 1120
        if ( "undefined" === typeof(bRemoveOnlySelection) )
            bRemoveOnlySelection = false;

        if(this.Slides[this.CurPage])
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1121
        {
1122
            this.Slides[this.CurPage].graphicObjects.remove(Count, bOnlyText, bRemoveOnlySelection);
1123
            this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1124 1125 1126 1127 1128 1129
        }
    },


    Cursor_MoveToStartPos : function()
    {
1130
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.cursorMoveToStartPos();
1131 1132
        this.Document_UpdateSelectionState();
        this.Document_UpdateInterfaceState();
1133
        return true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1134 1135 1136 1137
    },

    Cursor_MoveToEndPos : function()
    {
1138
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.cursorMoveToEndPos();
1139 1140
        this.Document_UpdateSelectionState();
        this.Document_UpdateInterfaceState();
1141
        return true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1142 1143 1144 1145
    },

    Cursor_MoveLeft : function(AddToSelect, Word)
    {
1146
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.cursorMoveLeft(AddToSelect, Word);
1147
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1148 1149 1150 1151 1152
        return true;
    },

    Cursor_MoveRight : function(AddToSelect, Word)
    {
1153
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.cursorMoveRight(AddToSelect, Word);
1154
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1155 1156 1157 1158 1159
        return true;
    },

    Cursor_MoveUp : function(AddToSelect)
    {
1160
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.cursorMoveUp(AddToSelect);
1161
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1162 1163 1164 1165 1166
        return true;
    },

    Cursor_MoveDown : function(AddToSelect)
    {
1167
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.cursorMoveDown(AddToSelect);
1168
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1169 1170 1171 1172 1173
        return true;
    },

    Cursor_MoveEndOfLine : function(AddToSelect)
    {
1174
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.cursorMoveEndOfLine(AddToSelect);
1175
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1176 1177 1178 1179 1180
        return true;
    },

    Cursor_MoveStartOfLine : function(AddToSelect)
    {
1181
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.cursorMoveStartOfLine(AddToSelect);
1182
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1183 1184 1185 1186 1187
        return true;
    },

    Cursor_MoveAt : function( X, Y, AddToSelect )
    {
1188
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.cursorMoveAt(X, Y, AddToSelect);
1189
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1190 1191 1192 1193 1194 1195 1196 1197
        return true;
    },

    Cursor_MoveToCell : function(bNext)
    {

    },

1198
    Get_PresentationBulletByNumInfo : function(NumInfo)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1199
    {
1200 1201
        var bullet = new CBullet();
        if(NumInfo.SubType < 0)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1202
        {
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328
            bullet.bulletType = new CBulletType();
            bullet.bulletType.type = BULLET_TYPE_BULLET_NONE;
        }
        else
        {
            switch (NumInfo.Type)
            {
                case 0 : /*bulletChar*/
                {
                    switch(NumInfo.SubType)
                    {
                        case 0:
                        case 1:
                        {
                            var bulletText = "";
                            bullet.bulletTypeface = new CBulletTypeface();
                            bullet.bulletTypeface.type = BULLET_TYPE_TYPEFACE_BUFONT;
                            bullet.bulletTypeface.typeface = "Arial";
                            break;
                        }
                        case 2:
                        {
                            bulletText = "o";
                            bullet.bulletTypeface = new CBulletTypeface();
                            bullet.bulletTypeface.type = BULLET_TYPE_TYPEFACE_BUFONT;
                            bullet.bulletTypeface.typeface = "Courier New";
                            break;
                        }
                        case 3:
                        {
                            bulletText = "§";
                            bullet.bulletTypeface = new CBulletTypeface();
                            bullet.bulletTypeface.type = BULLET_TYPE_TYPEFACE_BUFONT;
                            bullet.bulletTypeface.typeface = "Wingdings";
                            break;
                        }
                        case 4:
                        {
                            bulletText = String.fromCharCode( 0x0076 );
                            bullet.bulletTypeface = new CBulletTypeface();
                            bullet.bulletTypeface.type = BULLET_TYPE_TYPEFACE_BUFONT;
                            bullet.bulletTypeface.typeface = "Wingdings";
                            break;
                        }
                        case 5:
                        {
                            bulletText = String.fromCharCode( 0x00D8 );
                            bullet.bulletTypeface = new CBulletTypeface();
                            bullet.bulletTypeface.type = BULLET_TYPE_TYPEFACE_BUFONT;
                            bullet.bulletTypeface.typeface = "Wingdings";
                            break;
                        }
                        case 6:
                        {
                            bulletText = String.fromCharCode( 0x00FC );
                            bullet.bulletTypeface = new CBulletTypeface();
                            bullet.bulletTypeface.type = BULLET_TYPE_TYPEFACE_BUFONT;
                            bullet.bulletTypeface.typeface = "Wingdings";
                            break;
                        }
                        case 7:
                        {

                            bulletText = String.fromCharCode(119);
                            bullet.bulletTypeface = new CBulletTypeface();
                            bullet.bulletTypeface.type = BULLET_TYPE_TYPEFACE_BUFONT;
                            bullet.bulletTypeface.typeface = "Wingdings";
                            break;
                        }
                    }
                    bullet.bulletType = new CBulletType();
                    bullet.bulletType.type = BULLET_TYPE_BULLET_CHAR;
                    bullet.bulletType.Char = bulletText;
                    break;
                }
                case 1 : /*autonum*/
                {
                    switch(NumInfo.SubType)
                    {
                        case 0 :
                        case 1 :
                        {
                            var numberingType = 12;//numbering_numfmt_arabicPeriod;
                            break;
                        }
                        case 2:
                        {
                            numberingType = 11;//numbering_numfmt_arabicParenR;
                            break;
                        }
                        case 3 :
                        {
                            numberingType = 34;//numbering_numfmt_romanUcPeriod;
                            break;
                        }
                        case 4 :
                        {
                            numberingType = 5;//numbering_numfmt_alphaUcPeriod;
                            break;
                        }
                        case 5 :
                        {
                            numberingType = 8;
                            break;
                        }
                        case 6 :
                        {
                            numberingType = 40;
                            break;
                        }
                        case 7 :
                        {
                            numberingType = 31;//numbering_numfmt_romanLcPeriod;
                            break;
                        }
                    }
                    bullet.bulletType = new CBulletType();
                    bullet.bulletType.type = BULLET_TYPE_BULLET_AUTONUM;
                    bullet.bulletType.AutoNumType = numberingType;
                    break;
                }
                default :
                {
                    break;
                }
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1329
        }
1330 1331
        return bullet;
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1332

1333 1334 1335
    Set_ParagraphAlign : function(Align)
    {
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.setParagraphAlign, [Align]);
1336
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1337 1338 1339 1340
    },

    Set_ParagraphSpacing : function(Spacing)
    {
1341
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.setParagraphSpacing, [Spacing]);
1342
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1343 1344 1345 1346
    },

    Set_ParagraphTabs : function(Tabs)
    {
1347
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.setParagraphTabs, [Tabs]);
1348
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1349 1350 1351 1352
    },

    Set_ParagraphIndent : function(Ind)
    {
1353
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.setParagraphIndent, [Ind]);
1354
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1355 1356 1357 1358
    },

    Set_ParagraphNumbering : function(NumInfo)
    {
1359 1360
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.setParagraphNumbering, [this.Get_PresentationBulletByNumInfo(NumInfo)]);
        this.Document_UpdateInterfaceState();   //TODO
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1361 1362
    },

1363
    Paragraph_IncDecFontSize : function(bIncrease)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1364
    {
1365
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.paragraphIncDecFontSize, [bIncrease]);
1366
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1367 1368
    },

1369
    Paragraph_IncDecIndent : function(bIncrease)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1370
    {
1371
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.paragraphIncDecIndent, [bIncrease]);
1372
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1373 1374
    },

1375
    Can_IncreaseParagraphLevel : function(bIncrease)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1376
    {
1377
        return isRealObject(this.Slides[this.CurPage]) && this.Slides[this.CurPage].graphicObjects.canIncreaseParagraphLevel(bIncrease);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1378 1379
    },

1380
    Set_ImageProps : function(Props)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1381
    {
1382
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.applyDrawingProps, [Props]);
1383
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1384 1385
    },

1386
    ShapeApply: function(shapeProps)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1387
    {
1388 1389

        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.applyDrawingProps, [shapeProps]);
1390
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1391 1392
    },

1393
    ChartApply: function(chartProps)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1394
    {
1395
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.applyDrawingProps, [chartProps]);
1396
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1397 1398
    },

1399
    changeShapeType : function(shapeType)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1400
    {
1401
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.applyDrawingProps, [{type:shapeType}]);
1402
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1403 1404
    },

1405
    setVerticalAlign: function(align)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1406
    {
1407 1408 1409
        if(this.Slides[this.CurPage])
        {
            this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.applyDrawingProps, [{verticalTextAlign: align}]);
1410
            this.Document_UpdateInterfaceState();
1411
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1412 1413
    },

1414
    Get_Styles: function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1415
    {
1416 1417
        var styles = new CStyles();
        return {styles: styles, lastId: styles.Get_Default_Paragraph()}
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1418 1419
    },

1420
    Is_TableCellContent: function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1421
    {
1422
        return false;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1423 1424
    },

1425 1426

    Get_Theme: function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1427
    {
1428
        return this.themes[0];
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1429 1430
    },

1431
    Get_ColorMap: function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1432
    {
1433
        return G_O_DEFAULT_COLOR_MAP;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1434 1435
    },

1436
    Get_PageFields: function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1437
    {
1438
        return { X : 0, Y : 0, XLimit : 2000, YLimit : 2000};
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1439 1440
    },

1441 1442 1443 1444 1445
    Get_PageLimits : function(PageIndex)
    {
        return this.Get_PageFields();
    },

1446
    CheckRange: function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1447
    {
1448 1449
        return [];
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1450 1451


1452 1453 1454
    Is_Cell: function()
    {
        return false;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1455 1456
    },

1457
    Get_PrevElementEndInfo : function(CurElement)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1458
    {
1459 1460 1461 1462 1463
        return null;
    },
    Get_TextBackGroundColor: function()
    {
        return new CDocumentColor(255, 255, 255, false);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476
    },


    Set_TableProps : function(Props)
    {
        this.Slides[this.CurPage].graphicObjects.setTableProps(Props);
        this.Recalculate();
        this.Document_UpdateInterfaceState();
        this.Document_UpdateSelectionState();
    },

    Get_Paragraph_ParaPr : function()
    {
1477 1478 1479 1480 1481 1482 1483 1484 1485
        if(this.Slides[this.CurPage])
        {
            var ret = this.Slides[this.CurPage].graphicObjects.getParagraphParaPr();
            if(ret)
            {
                return ret;
            }
        }
        return new CParaPr();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1486 1487 1488 1489
    },

    Get_Paragraph_TextPr : function()
    {
1490 1491 1492 1493 1494 1495 1496 1497 1498
        if(this.Slides[this.CurPage])
        {
            var ret = this.Slides[this.CurPage].graphicObjects.getParagraphTextPr();
            if(ret)
            {
                return ret;
            }
        }
        return new CTextPr();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1499 1500 1501 1502
    },

    Get_Paragraph_TextPr_Copy : function()
    {
1503 1504 1505 1506 1507
        if(this.Slides[this.CurPage])
        {
            return this.Slides[this.CurPage].graphicObjects.getParagraphTextPr();
        }
        return new CTextPr();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1508 1509 1510 1511
    },

    Get_Paragraph_ParaPr_Copy : function()
    {
1512 1513 1514 1515 1516
        if(this.Slides[this.CurPage])
        {
            return this.Slides[this.CurPage].graphicObjects.getParagraphParaPr();
        }
        return new CParaPr();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1517 1518
    },

1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545

    GetTableStyleIdMap : function(oMap)
    {
        for(var i = 0; i < this.Slides.length; ++i)
        {
            this.CollectStyleId(oMap, this.Slides[i].cSld.spTree);
        }
    },

    CollectStyleId : function(oMap, aSpTree)
    {
        for(var i = 0; i < aSpTree.length; ++i)
        {
            if(aSpTree[i].getObjectType() === historyitem_type_GraphicFrame)
            {
                if(isRealObject(aSpTree[i].graphicObject) && typeof aSpTree[i].graphicObject.TableStyle === "string" && isRealObject(g_oTableId.Get_ById(aSpTree[i].graphicObject.TableStyle)))
                {
                    oMap[aSpTree[i].graphicObject.TableStyle] = true;
                }
            }
            else if(aSpTree[i].getObjectType() === historyitem_type_GroupShape)
            {
                this.CollectStyleId(oMap, aSpTree[i].spTree);
            }
        }
    },

1546 1547
    // Обновляем данные в интерфейсе о свойствах параграфа
    Interface_Update_ParaPr : function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569
    {

        var ParaPr = this.Slides[this.CurPage].graphicObjects.getPropsArrays().paraPr;

        if ( null != ParaPr )
        {
            if ( undefined != ParaPr.Tabs )
                editor.Update_ParaTab( Default_Tab_Stop, ParaPr.Tabs );

            editor.UpdateParagraphProp( ParaPr );
        }
    },

    // Обновляем данные в интерфейсе о свойствах текста
    Interface_Update_TextPr : function()
    {
        var TextPr =this.Slides[this.CurPage].graphicObjects.getPropsArrays().textPr;

        if ( null != TextPr )
            editor.UpdateTextPr(TextPr);
    },

1570 1571

    getAllTableStyles: function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1572
    {
1573
        for(var  i = 0; i < this.globalTableStyles.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1574
        {
1575
            this.globalTableStyles[i].stylesId = i;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1576
        }
1577
        return this.globalTableStyles;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1578 1579
    },

1580 1581 1582 1583


    // Селектим весь параграф
    Select_All : function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1584
    {
1585
        if(this.Slides[this.CurPage])
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1586
        {
1587 1588
            this.Slides[this.CurPage].graphicObjects.selectAll();
            this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1589 1590 1591 1592
        }
    },


1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607
    Update_CursorType : function( X, Y, MouseEvent )
    {
        var graphicObjectInfo = this.Slides[this.CurPage].graphicObjects.isPointInDrawingObjects(X, Y, MouseEvent);
        if(graphicObjectInfo)
        {
           if(!graphicObjectInfo.updated)
           {
               this.DrawingDocument.SetCursorType(graphicObjectInfo.cursorType);
           }
        }
        else
        {
            this.DrawingDocument.SetCursorType("default");
        }
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1608 1609


1610 1611 1612 1613
    OnKeyDown : function(e)
    {
        var bUpdateSelection = true;
        var bRetValue = false;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1614

1615
        if ( e.KeyCode == 8 && false === editor.isViewMode ) // BackSpace
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1616
        {
1617 1618
            this.Remove( -1, true );
            bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1619
        }
1620 1621
        else if ( e.KeyCode == 9 && false === editor.isViewMode ) // Tab
        {
1622 1623 1624
            if(this.Slides[this.CurPage])
            {
                var graphicObjects = this.Slides[this.CurPage].graphicObjects;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640
                var target_content = graphicObjects.getTargetDocContent(undefined, true);
                if(target_content)
                {
                    if(target_content instanceof CTable)
                    {
                        target_content.Cursor_MoveToCell( true === e.ShiftKey ? false : true );
                    }
                    else
                    {
                        this.Paragraph_Add( new ParaTab() );
                    }
                }
                else
                {
                    graphicObjects.selectNextObject(!e.ShiftKey ? 1 : -1);
                }
1641 1642 1643
                this.Document_UpdateInterfaceState();
            }
            bRetValue = true;
1644 1645
        }
        else if ( e.KeyCode == 13 && false === editor.isViewMode ) // Enter
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1646
        {
1647 1648 1649
            var Hyperlink = this.Hyperlink_Check(false);
            if ( null != Hyperlink && false === e.ShiftKey )
            {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1650
                editor.sync_HyperlinkClickCallback( Hyperlink.Get_Value() );
1651
                Hyperlink.Set_Visited(true);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1652

1653 1654 1655 1656 1657 1658 1659 1660 1661
                // TODO: Пока сделаем так, потом надо будет переделать
                this.DrawingDocument.ClearCachePages();
                this.DrawingDocument.FirePaint();
            }
            else
            {
                if ( e.ShiftKey )
                {
                    this.Paragraph_Add( new ParaNewLine( break_Line ) );
1662
                    this.Document_UpdateInterfaceState();
1663 1664 1665 1666
                }
                else if ( e.CtrlKey )
                {
                    this.Paragraph_Add( new ParaNewLine( break_Page ) );
1667
                    this.Document_UpdateInterfaceState();
1668 1669 1670 1671 1672 1673
                }
                else
                {
                    this.Add_NewParagraph();
                }
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1674

1675 1676 1677 1678
            bRetValue = true;
        }
        else if ( e.KeyCode == 27 ) // Esc
        {
1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757
            if(this.Slides[this.CurPage])
            {
                var oDrawingObjects = this.Slides[this.CurPage].graphicObjects;
                var oTargetTextObject = getTargetTextObject(oDrawingObjects);

                var bNeedRedraw;
                if(oTargetTextObject && oTargetTextObject.isEmptyPlaceholder && oTargetTextObject.isEmptyPlaceholder())
                {
                    bNeedRedraw = true;
                }
                else
                {
                    bNeedRedraw = false;
                }
                if(e.ShiftKey || (!oDrawingObjects.selection.groupSelection && !oDrawingObjects.selection.textSelection && !oDrawingObjects.selection.chartSelection))
                {
                    oDrawingObjects.resetSelection();
                }
                else
                {
                    if(oDrawingObjects.selection.groupSelection)
                    {
                        var oGroupSelection = oDrawingObjects.selection.groupSelection.selection;
                        if(oGroupSelection.textSelection)
                        {
                            if(oGroupSelection.textSelection.getObjectType() === historyitem_type_GraphicFrame)
                            {
                                if(oGroupSelection.textSelection.graphicObject)
                                {
                                    oGroupSelection.textSelection.graphicObject.Selection_Remove();
                                }
                            }
                            else
                            {
                                var content = oGroupSelection.textSelection.getDocContent();
                                content && content.Selection_Remove();
                            }
                            oGroupSelection.textSelection = null;
                        }
                        else if(oGroupSelection.chartSelection)
                        {
                            oGroupSelection.chartSelection.resetSelection(false);
                            oGroupSelection.chartSelection = null;
                        }
                        else
                        {
                            oDrawingObjects.selection.groupSelection.resetSelection(this);
                            oDrawingObjects.selection.groupSelection = null;
                        }
                    }
                    else if(oDrawingObjects.selection.textSelection)
                    {
                        if(oDrawingObjects.selection.textSelection.getObjectType() === historyitem_type_GraphicFrame)
                        {
                            if(oDrawingObjects.selection.textSelection.graphicObject)
                            {
                                oDrawingObjects.selection.textSelection.graphicObject.Selection_Remove();
                            }
                        }
                        else
                        {
                            var content = oDrawingObjects.selection.textSelection.getDocContent();
                            content && content.Selection_Remove();
                        }
                        oDrawingObjects.selection.textSelection = null;
                    }
                    else if(oDrawingObjects.selection.chartSelection)
                    {
                        oDrawingObjects.selection.chartSelection.resetSelection(false);
                        oDrawingObjects.selection.chartSelection = null;
                    }
                }
                if(bNeedRedraw)
                {
                    this.DrawingDocument.OnRecalculatePage(this.CurPage, this.Slides[this.CurPage]);
                }
                this.Document_UpdateSelectionState();
                this.Document_UpdateInterfaceState();
            }
1758 1759 1760 1761 1762
            bRetValue = true;
        }
        else if ( e.KeyCode == 32 && false === editor.isViewMode ) // Space
        {
            if ( true === e.ShiftKey && true === e.CtrlKey )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1763
            {
1764 1765
                this.DrawingDocument.TargetStart();
                this.DrawingDocument.TargetShow();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1766

1767
                this.Paragraph_Add( new ParaText( String.fromCharCode( 0x00A0 ) ) );
1768
                this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1769
            }
1770
            else if ( true === e.CtrlKey )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1771
            {
1772
                this.Paragraph_ClearFormatting();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1773
            }
1774 1775
            else
            {
1776 1777
               // this.DrawingDocument.TargetStart();
               // this.DrawingDocument.TargetShow();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1778

1779
                this.Paragraph_Add( new ParaSpace( 1 ) );
1780
                this.Document_UpdateInterfaceState();
1781
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1782

1783
            bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1784
        }
1785
        else if ( e.KeyCode == 33 ) // PgUp
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1786
        {
1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798
            if ( true === e.AltKey )
            {
                // bRetValue = false;
            }
            else
            {
                if(this.CurPage  > 0)
                {
                    this.DrawingDocument.m_oWordControl.GoToPage(this.CurPage - 1);
                    bRetValue = true;
                }
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1799
        }
1800
        else if ( e.KeyCode == 34 ) // PgDn
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1801
        {
1802 1803 1804 1805 1806
            if ( true === e.AltKey )
            {
                // bRetValue = false;
            }
            else
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1807
            {
1808
                if(this.CurPage + 1 < this.Slides.length)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1809
                {
1810 1811
                    this.DrawingDocument.m_oWordControl.GoToPage(this.CurPage + 1);
                    bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1812 1813 1814
                }
            }
        }
1815
        else if ( e.KeyCode == 35 ) // клавиша End
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1816
        {
1817 1818 1819 1820 1821 1822 1823 1824 1825 1826
            if ( true === e.CtrlKey ) // Ctrl + End - переход в конец документа
            {
                this.Cursor_MoveToEndPos();
            }
            else // Переходим в конец строки
            {
                this.Cursor_MoveEndOfLine( true === e.ShiftKey );
            }

            bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1827
        }
1828
        else if ( e.KeyCode == 36 ) // клавиша Home
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1829
        {
1830
            if ( true === e.CtrlKey ) // Ctrl + Home - переход в начало документа
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1831
            {
1832 1833 1834 1835 1836
                this.Cursor_MoveToStartPos();
            }
            else // Переходим в начало строки
            {
                this.Cursor_MoveStartOfLine( true === e.ShiftKey );
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1837 1838
            }

1839
            bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1840
        }
1841 1842 1843 1844 1845
        else if ( e.KeyCode == 37 ) // Left Arrow
        {
            // Чтобы при зажатой клавише курсор не пропадал
           // if ( true != e.ShiftKey )
           //     this.DrawingDocument.TargetStart();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1846

1847 1848 1849 1850
            this.Cursor_MoveLeft( true === e.ShiftKey, true === e.CtrlKey );
            bRetValue = true;
        }
        else if ( e.KeyCode == 38 ) // Top Arrow
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1851
        {
1852 1853 1854 1855 1856 1857
            // Чтобы при зажатой клавише курсор не пропадал
            //if ( true != e.ShiftKey )
            //    this.DrawingDocument.TargetStart();

            this.Cursor_MoveUp( true === e.ShiftKey );
            bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1858
        }
1859
        else if ( e.KeyCode == 39 ) // Right Arrow
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1860
        {
1861 1862 1863 1864 1865 1866
            // Чтобы при зажатой клавише курсор не пропадал
           // if ( true != e.ShiftKey )
           //     this.DrawingDocument.TargetStart();

            this.Cursor_MoveRight( true === e.ShiftKey, true === e.CtrlKey );
            bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1867
        }
1868
        else if ( e.KeyCode == 40 ) // Bottom Arrow
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1869
        {
1870 1871 1872
            // Чтобы при зажатой клавише курсор не пропадал
            //if ( true != e.ShiftKey )
            //    this.DrawingDocument.TargetStart();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1873

1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884
            this.Cursor_MoveDown( true === e.ShiftKey );
            bRetValue = true;
        }
        else if ( e.KeyCode == 45 ) // Insert
        {
            if ( true === e.CtrlKey ) // Ctrl + Insert (аналогично Ctrl + C)
            {
                Editor_Copy(this.DrawingDocument.m_oWordControl.m_oApi);
                //не возвращаем true чтобы не было preventDefault
            }
            else if ( true === e.ShiftKey && false === editor.isViewMode ) // Shift + Insert (аналогично Ctrl + V)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1885
            {
1886
                if ( false === this.Document_Is_SelectionLocked(changestype_Drawing_Props) )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1887
                {
1888
                    if (!window.GlobalPasteFlag)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1889
                    {
1890
                        if (!window.USER_AGENT_SAFARI_MACOS)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1891
                        {
1892
                            this.Create_NewHistoryPoint();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1893

1894
                            window.GlobalPasteFlag = true;
1895
                            editor.waitSave = true;
1896 1897
                            Editor_Paste(this.DrawingDocument.m_oWordControl.m_oApi, true);
                            //не возвращаем true чтобы не было preventDefault
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1898
                        }
1899
                        else
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1900
                        {
1901 1902 1903
                            if (0 === window.GlobalPasteFlagCounter)
                            {
                                this.Create_NewHistoryPoint();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1904

1905 1906
                                SafariIntervalFocus();
                                window.GlobalPasteFlag = true;
1907
                                editor.waitSave = true;
1908 1909 1910
                                Editor_Paste(this.DrawingDocument.m_oWordControl.m_oApi, true);
                                //не возвращаем true чтобы не было preventDefault
                            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1911 1912 1913
                        }
                    }
                }
1914
                //не возвращаем true чтобы не было preventDefault
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1915 1916
            }
        }
1917
        else if ( e.KeyCode == 46 && false === editor.isViewMode ) // Delete
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1918
        {
1919
            if ( true != e.ShiftKey )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1920
            {
1921
                //if ( false === this.Document_Is_SelectionLocked(changestype_Drawing_Props) )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1922
                {
1923 1924
                    //this.Create_NewHistoryPoint();
                    this.Remove( 1, true );
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1925
                }
1926 1927 1928 1929 1930
                bRetValue = true;
            }
            else // Shift + Delete (аналогично Ctrl + X)
            {
                if ( false === this.Document_Is_SelectionLocked(changestype_Drawing_Props) )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1931
                {
1932 1933
                    this.Create_NewHistoryPoint();
                    Editor_Copy(this.DrawingDocument.m_oWordControl.m_oApi, true);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1934
                }
1935
                //не возвращаем true чтобы не было preventDefault
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1936 1937
            }
        }
1938
        else if ( e.KeyCode == 49 && false === editor.isViewMode && true === e.CtrlKey && true === e.AltKey ) // Alt + Ctrl + Num1 - применяем стиль Heading1
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1939
        {
1940
            if ( false === this.Document_Is_SelectionLocked(changestype_Paragraph_Properties) )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1941
            {
1942 1943 1944
                this.Create_NewHistoryPoint();
                this.Set_ParagraphStyle( "Heading 1" );
                this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1945
            }
1946 1947 1948 1949 1950
            bRetValue = true;
        }
        else if ( e.KeyCode == 50 && false === editor.isViewMode && true === e.CtrlKey && true === e.AltKey ) // Alt + Ctrl + Num2 - применяем стиль Heading2
        {
            if ( false === this.Document_Is_SelectionLocked(changestype_Paragraph_Properties) )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1951
            {
1952 1953 1954
                this.Create_NewHistoryPoint();
                this.Set_ParagraphStyle( "Heading 2" );
                this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1955
            }
1956 1957 1958 1959 1960
            bRetValue = true;
        }
        else if ( e.KeyCode == 51 && false === editor.isViewMode && true === e.CtrlKey && true === e.AltKey ) // Alt + Ctrl + Num3 - применяем стиль Heading3
        {
            if ( false === this.Document_Is_SelectionLocked(changestype_Paragraph_Properties) )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1961
            {
1962 1963 1964
                this.Create_NewHistoryPoint();
                this.Set_ParagraphStyle( "Heading 3" );
                this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1965
            }
1966
            bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1967
        }
1968
        else if ( e.KeyCode == 56 && true === e.CtrlKey && true === e.ShiftKey ) // Ctrl + Shift + 8 - showParaMarks
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1969
        {
1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982
            editor.ShowParaMarks = !editor.ShowParaMarks;
            if(this.Slides[this.CurPage])
                this.DrawingDocument.OnRecalculatePage(this.CurPage, this.Slides[this.CurPage]);
        }
        else if ( e.KeyCode == 65 && true === e.CtrlKey ) // Ctrl + A - выделяем все
        {
            this.Select_All();
            bRetValue = true;
        }
        else if ( e.KeyCode == 66 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + B - делаем текст жирным
        {
            var TextPr = this.Get_Paragraph_TextPr();
            if ( null != TextPr )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1983
            {
1984 1985 1986
                this.Paragraph_Add( new ParaTextPr( { Bold : TextPr.Bold === true ? false : true } ) );
                this.Document_UpdateInterfaceState();
                bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1987 1988
            }
        }
1989
        else if ( e.KeyCode == 67 && true === e.CtrlKey ) // Ctrl + C + ...
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1990
        {
1991
            if ( true === e.ShiftKey ) // Ctrl + Shift + C - копирование форматирования текста
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1992
            {
1993 1994
                this.Document_Format_Copy();
                bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1995
            }
1996
            else // Ctrl + C - copy
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1997
            {
1998 1999
                Editor_Copy(this.DrawingDocument.m_oWordControl.m_oApi);
                //не возвращаем true чтобы не было preventDefault
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2000 2001
            }
        }
2002
        else if ( e.KeyCode == 69 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + E - переключение прилегания параграфа между center и left
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2003
        {
2004
            if ( true !== e.AltKey ) // Ctrl + E - переключение прилегания параграфа между center и left
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2005
            {
2006 2007
                var ParaPr = this.Get_Paragraph_ParaPr();
                if ( null != ParaPr )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2008
                {
2009 2010 2011 2012
                    this.Create_NewHistoryPoint();
                    this.Set_ParagraphAlign( ParaPr.Jc === align_Center ? align_Left : align_Center );
                    this.Document_UpdateInterfaceState();
                    bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2013 2014
                }
            }
2015 2016
            else // Ctrl + Alt + E - добавляем знак евро €
            {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2017

2018
                this.Paragraph_Add( new ParaText( "" ) );
2019
                this.Document_UpdateInterfaceState();
2020 2021
                bRetValue = true;
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2022
        }
2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034
        else if ( e.KeyCode == 71 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + G - группируем объекты
        {
            if(true === e.ShiftKey)
            {
                this.unGroupShapes();
            }
            else
            {
                this.groupShapes();
            }
            bRetValue = true;
        }
2035
        else if ( e.KeyCode == 73 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + I - делаем текст наклонным
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2036
        {
2037 2038
            var TextPr = this.Get_Paragraph_TextPr();
            if ( null != TextPr )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2039
            {
2040
                this.Paragraph_Add( new ParaTextPr( { Italic : TextPr.Italic === true ? false : true } ) );
2041
                this.Document_UpdateInterfaceState();
2042
                bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2043 2044
            }
        }
2045
        else if ( e.KeyCode == 74 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + J переключение прилегания параграфа между justify и left
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2046
        {
2047 2048
            var ParaPr = this.Get_Paragraph_ParaPr();
            if ( null != ParaPr )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2049
            {
2050 2051 2052 2053 2054 2055 2056
                if ( false === this.Document_Is_SelectionLocked(changestype_Paragraph_Properties) )
                {
                    this.Create_NewHistoryPoint();
                    this.Set_ParagraphAlign( ParaPr.Jc === align_Justify ? align_Left : align_Justify );
                    this.Document_UpdateInterfaceState();
                }
                bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2057 2058
            }
        }
2059
        else if ( e.KeyCode == 75 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + K - добавление гиперссылки
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2060
        {
2061 2062
            if ( true === this.Hyperlink_CanAdd(false) )
                editor.sync_DialogAddHyperlink();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2063

2064
            bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2065
        }
2066
        else if ( e.KeyCode == 76 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + L + ...
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2067
        {
2068
            if ( true === e.ShiftKey ) // Ctrl + Shift + L - добавляем список к данному параграфу
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2069
            {
2070
                if ( false === this.Document_Is_SelectionLocked(changestype_Drawing_Props) )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2071
                {
2072 2073 2074
                    this.Create_NewHistoryPoint();
                    this.Set_ParagraphNumbering( { Type : 0, SubType : 1 } );
                    this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2075
                }
2076
                bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2077
            }
2078
            else // Ctrl + L - переключение прилегания параграфа между left и justify
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2079
            {
2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090
                var ParaPr = this.Get_Paragraph_ParaPr();
                if ( null != ParaPr )
                {
                    if ( false === this.Document_Is_SelectionLocked(changestype_Paragraph_Properties) )
                    {
                        this.Create_NewHistoryPoint();
                        this.Set_ParagraphAlign( ParaPr.Jc === align_Left ? align_Justify : align_Left );
                        this.Document_UpdateInterfaceState();
                    }
                    bRetValue = true;
                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2091 2092
            }
        }
2093
        else if ( e.KeyCode == 77 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + M + ...
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2094
        {
2095 2096 2097 2098
            if ( true === e.ShiftKey ) // Ctrl + Shift + M - уменьшаем левый отступ
                editor.DecreaseIndent();
            else // Ctrl + M - увеличиваем левый отступ
                editor.IncreaseIndent();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2099
        }
2100
        else if ( e.KeyCode == 80 && true === e.CtrlKey ) // Ctrl + P + ...
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2101
        {
2102 2103 2104 2105 2106 2107 2108 2109 2110
            if ( true === e.ShiftKey && false === editor.isViewMode ) // Ctrl + Shift + P - добавляем номер страницы в текущую позицию
            {
                bRetValue = true;
            }
            else // Ctrl + P - print
            {
                this.DrawingDocument.m_oWordControl.m_oApi.asc_Print();
                bRetValue = true;
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2111
        }
2112
        else if ( e.KeyCode == 82 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + R - переключение прилегания параграфа между right и left
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2113
        {
2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126
            var ParaPr = this.Get_Paragraph_ParaPr();
            if ( null != ParaPr )
            {
                if ( false === this.Document_Is_SelectionLocked(changestype_Paragraph_Properties) )
                {
                    this.Create_NewHistoryPoint();
                    this.Set_ParagraphAlign( ParaPr.Jc === align_Right ? align_Left : align_Right );
                    this.Document_UpdateInterfaceState();
                }
                bRetValue = true;
            }
        }
        else if ( e.KeyCode == 83 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + S - save
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2127
        {
2128 2129 2130 2131
            if (true === this.History.Have_Changes() || CollaborativeEditing.m_aChanges.length > 0)
            {
                this.DrawingDocument.m_oWordControl.m_oApi.asc_Save();
            }
2132 2133 2134 2135 2136 2137
            bRetValue = true;
        }
        else if ( e.KeyCode == 85 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + U - делаем текст подчеркнутым
        {
            var TextPr = this.Get_Paragraph_TextPr();
            if ( null != TextPr )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2138
            {
2139
                this.Paragraph_Add( new ParaTextPr( { Underline : TextPr.Underline === true ? false : true } ) );
2140
                this.Document_UpdateInterfaceState();
2141 2142 2143
                bRetValue = true;
            }
        }
2144 2145 2146 2147 2148 2149 2150 2151 2152 2153
        else if ( e.KeyCode == 53 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + 5 - делаем текст зачеркнутым
        {
            var TextPr = this.Get_Paragraph_TextPr();
            if ( null != TextPr )
            {
                this.Paragraph_Add( new ParaTextPr( { Strikeout : TextPr.Strikeout === true ? false : true } ) );
                this.Document_UpdateInterfaceState();
                bRetValue = true;
            }
        }
2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165
        else if ( e.KeyCode == 86 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + V - paste
        {
            if ( false === this.Document_Is_SelectionLocked(changestype_Drawing_Props) )
            {
                if ( true === e.ShiftKey ) // Ctrl + Shift + V - вставляем по образцу
                {
                    this.Document_Format_Paste();
                    bRetValue = true;
                }
                else // Ctrl + V - paste
                {
                    if (!window.GlobalPasteFlag)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2166
                    {
2167
                        if (!window.USER_AGENT_SAFARI_MACOS)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2168
                        {
2169 2170 2171
                            this.Create_NewHistoryPoint();

                            window.GlobalPasteFlag = true;
2172
                            editor.waitSave = true;
2173 2174
                            Editor_Paste(this.DrawingDocument.m_oWordControl.m_oApi, true);
                            //не возвращаем true чтобы не было preventDefault
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2175 2176 2177
                        }
                        else
                        {
2178 2179 2180 2181 2182 2183
                            if (0 === window.GlobalPasteFlagCounter)
                            {
                                this.Create_NewHistoryPoint();

                                SafariIntervalFocus();
                                window.GlobalPasteFlag = true;
2184
                                editor.waitSave = true;
2185 2186 2187
                                Editor_Paste(this.DrawingDocument.m_oWordControl.m_oApi, true);
                                //не возвращаем true чтобы не было preventDefault
                            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2188 2189
                        }
                    }
2190
                    else
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2191
                    {
2192 2193
                        if (!window.USER_AGENT_SAFARI_MACOS)
                            bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2194
                    }
2195
                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2196 2197
            }
        }
2198
        else if ( e.KeyCode == 88 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + X - cut
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2199
        {
2200 2201 2202 2203 2204 2205
            if ( false === this.Document_Is_SelectionLocked(changestype_Drawing_Props) )
            {
                this.Create_NewHistoryPoint();
                Editor_Copy(this.DrawingDocument.m_oWordControl.m_oApi, true);
            }
            //не возвращаем true чтобы не было preventDefault
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2206
        }
2207
        else if ( e.KeyCode == 89 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + Y - Redo
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2208
        {
2209 2210
            this.Document_Redo();
            bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2211
        }
2212
        else if ( e.KeyCode == 90 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + Z - Undo
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2213
        {
2214 2215
            this.Document_Undo();
            bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2216
        }
2217
        else if ( e.KeyCode == 93 || 57351 == e.KeyCode /*в Opera такой код*/  || (e.KeyCode == 121 && true === e.ShiftKey /*shift + f10*/)) // контекстное меню
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2218
        {
2219 2220 2221 2222
            if(editor.WordControl.Thumbnails.FocusObjType === FOCUS_OBJECT_MAIN)
            {
                if(this.Slides[this.CurPage] )
                {
2223 2224 2225
                    var oPosition = this.Slides[this.CurPage].graphicObjects.getContextMenuPosition(0);
                    var ConvertedPos = this.DrawingDocument.ConvertCoordsToCursorWR( oPosition.X, oPosition.Y, this.PageNum );
                    editor.sync_ContextMenuCallback(new CContextMenuData({ Type : c_oAscContextMenuTypes.Main, X_abs : ConvertedPos.X, Y_abs : ConvertedPos.Y }) );
2226 2227
                }
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2228

2229 2230
            bUpdateSelection = false;
            bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2231
        }
2232
        else if ( e.KeyCode == 144 ) // Num Lock
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2233
        {
2234 2235
            // Ничего не делаем
            bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2236
        }
2237
        else if ( e.KeyCode == 145 ) // Scroll Lock
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2238
        {
2239 2240
            // Ничего не делаем
            bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2241
        }
2242
        else if ( e.KeyCode == 187 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + Shift + +, Ctrl + = - superscript/subscript
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2243
        {
2244 2245
            var TextPr = this.Get_Paragraph_TextPr();
            if ( null != TextPr )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2246
            {
2247 2248 2249 2250
                if ( true === e.ShiftKey )
                    this.Paragraph_Add( new ParaTextPr( { VertAlign : TextPr.VertAlign === vertalign_SuperScript ? vertalign_Baseline : vertalign_SuperScript } ) );
                else
                    this.Paragraph_Add( new ParaTextPr( { VertAlign : TextPr.VertAlign === vertalign_SubScript ? vertalign_Baseline : vertalign_SubScript } ) );
2251
                this.Document_UpdateInterfaceState();
2252
                bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2253 2254
            }
        }
2255
        else if ( e.KeyCode == 188 && true === e.CtrlKey ) // Ctrl + ,
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2256
        {
2257 2258
            var TextPr = this.Get_Paragraph_TextPr();
            if ( null != TextPr )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2259
            {
2260
                this.Paragraph_Add( new ParaTextPr( { VertAlign : TextPr.VertAlign === vertalign_SuperScript ? vertalign_Baseline : vertalign_SuperScript } ) );
2261
                this.Document_UpdateInterfaceState();
2262
                bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2263 2264
            }
        }
2265
        else if ( e.KeyCode == 189 && false === editor.isViewMode ) // Клавиша Num-
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2266
        {
2267 2268
            this.DrawingDocument.TargetStart();
            this.DrawingDocument.TargetShow();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2269

2270 2271 2272 2273
            var Item = null;
            if ( true === e.CtrlKey && true === e.ShiftKey )
            {
                Item = new ParaText( String.fromCharCode( 0x2013 ) );
2274
                Item.SpaceAfter = false;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2275
            }
2276 2277 2278 2279
            else if ( true === e.ShiftKey )
                Item = new ParaText( "_" );
            else
                Item = new ParaText( "-" );
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2280

2281
            this.Paragraph_Add( Item );
2282
            this.Document_UpdateInterfaceState();
2283
            bRetValue = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2284
        }
2285
        else if ( e.KeyCode == 190 && true === e.CtrlKey ) // Ctrl + .
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2286
        {
2287 2288 2289 2290 2291 2292 2293
            var TextPr = this.Get_Paragraph_TextPr();
            if ( null != TextPr )
            {
                this.Paragraph_Add( new ParaTextPr( { VertAlign : TextPr.VertAlign === vertalign_SubScript ? vertalign_Baseline : vertalign_SubScript } ) );
                this.Document_UpdateInterfaceState();
                bRetValue = true;
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2294
        }
2295
        else if ( e.KeyCode == 219 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + [
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2296
        {
2297 2298
            editor.FontSizeOut();
            this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2299
        }
2300
        else if ( e.KeyCode == 221 && false === editor.isViewMode && true === e.CtrlKey ) // Ctrl + ]
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2301
        {
2302
            editor.FontSizeIn();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2303 2304 2305
            this.Document_UpdateInterfaceState();
        }

2306 2307
        if ( true == bRetValue && true === bUpdateSelection )
            this.Document_UpdateSelectionState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2308

2309
        return bRetValue;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2310 2311
    },

2312
    Set_DocumentDefaultTab: function(DTab)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2313
    {
2314 2315
       //History.Add( this, { Type : historyitem_Document_DefaultTab, Old : Default_Tab_Stop, New : DTab } );
        Default_Tab_Stop = DTab;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2316 2317
    },

2318 2319 2320 2321 2322
    Set_DocumentMargin: function()
    {

    },

2323
    OnKeyPress : function(e)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2324
    {
2325 2326
        if ( true === editor.isViewMode )
            return false;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2327

2328 2329 2330 2331
        //Ctrl и Atl только для команд, word не водит текста с зажатыми Ctrl или Atl
        //команды полностью обрабатываются в keypress
        if(e.CtrlKey || e.AltKey)
            return false;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2332

2333 2334 2335 2336 2337 2338 2339
        var Code;
        if (null != e.Which)
            Code = e.Which;
        else if (e.KeyCode)
            Code = e.KeyCode;
        else
            Code = 0;//special char
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2340

2341
        var bRetValue = false;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2342

2343 2344 2345 2346 2347 2348 2349
        /*
         if ( 1105 == Code )
         {
         this.LoadTestDocument();
         return true;
         }
         else*/ if ( Code > 0x20 )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2350
    {
2351
        //if ( false === this.Document_Is_SelectionLocked(changestype_Drawing_Props) )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2352
        {
2353
            //this.Create_NewHistoryPoint();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2354

2355 2356
           //this.DrawingDocument.TargetStart();
           //this.DrawingDocument.TargetShow();
2357 2358 2359 2360 2361
            var target_doc_content1, target_doc_content2, b_update_interface = false;
            if(this.Slides[this.CurPage])
            {
                target_doc_content1 = this.Slides[this.CurPage].graphicObjects.getTargetDocContent();
            }
2362
            this.Paragraph_Add( new ParaText( String.fromCharCode( Code ) ) );
2363 2364 2365 2366 2367 2368 2369 2370 2371
            if(this.Slides[this.CurPage])
            {
                target_doc_content2 = this.Slides[this.CurPage].graphicObjects.getTargetDocContent();
            }
            if(!target_doc_content1 && target_doc_content2)
            {
                b_update_interface = true;
                this.Document_UpdateInterfaceState();
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2372
        }
2373 2374
        bRetValue = true;
    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2375

2376
        if ( true == bRetValue )
2377
        {
2378
            this.Document_UpdateSelectionState();
2379 2380 2381 2382
            if(!b_update_interface)
            {
                this.Document_UpdateUndoRedoState();
            }
2383
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2384

2385
        return bRetValue;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2386 2387
    },

2388
    OnMouseDown : function(e, X, Y, PageIndex)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2389
    {
2390
        this.CurPage = PageIndex;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2391 2392


2393 2394 2395 2396 2397 2398
        if ( PageIndex < 0 )
            return;

        this.CurPage = PageIndex;
        e.ctrlKey = e.CtrlKey;
        e.shiftKey = e.ShiftKey;
2399
       //if(e.Button === 0)
2400 2401 2402
        {
            var ret = this.Slides[this.CurPage].graphicObjects.onMouseDown(e, X, Y);
            if(!ret)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2403
            {
2404 2405 2406 2407
                if(e.ClickCount < 2)
                {
                    this.Slides[this.CurPage].graphicObjects.resetSelection();
                }
2408
                this.Document_UpdateSelectionState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2409 2410
            }
        }
2411 2412 2413 2414 2415
        //else if(e.Button === 2 && this.viewMode === false )
        //{
        //    this.Slides[this.CurPage].graphicObjects.onMouseDown2(e, X, Y);
        //}
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2416 2417
    },

2418
    OnMouseUp : function(e, X, Y, PageIndex)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2419
    {
2420 2421
        e.ctrlKey = e.CtrlKey;
        e.shiftKey = e.ShiftKey;
2422
        this.Slides[this.CurPage].graphicObjects && this.Slides[this.CurPage].graphicObjects.onMouseUp(e, X, Y);
2423
        if(e.Button === g_mouse_button_right && !this.noShowContextMenu)
2424 2425 2426 2427 2428 2429 2430 2431
        {
            var ContextData = new CContextMenuData();
            var ConvertedPos = this.DrawingDocument.ConvertCoordsToCursorWR( X, Y, PageIndex );
            ContextData.X_abs = ConvertedPos.X;
            ContextData.Y_abs = ConvertedPos.Y;
            ContextData.IsSlideSelect = false;
            editor.sync_ContextMenuCallback( ContextData );
        }
2432
        this.noShowContextMenu = false;
2433
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2434 2435
    },

2436 2437 2438 2439 2440 2441
    OnMouseMove : function(e, X, Y, PageIndex)
    {
        e.ctrlKey = e.CtrlKey;
        e.shiftKey = e.ShiftKey;
        editor.sync_MouseMoveStartCallback();
        this.CurPage = PageIndex;
2442
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.onMouseMove(e, X, Y);
2443 2444
        this.Update_CursorType(X, Y,  e );
        editor.sync_MouseMoveEndCallback();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2445 2446 2447 2448
    },



2449
    Get_TableStyleForPara : function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2450
    {
2451 2452
        return null;
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2453 2454 2455



2456 2457 2458
    Get_SelectionAnchorPos: function()
    {
        if(this.Slides[this.CurPage])
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2459
        {
2460 2461
            var selected_objects = this.Slides[this.CurPage].graphicObjects.selectedObjects;
            if(selected_objects.length  > 0)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2462
            {
2463
                var last_object = selected_objects[selected_objects.length - 1];
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2464 2465 2466
                var Coords1 = editor.WordControl.m_oDrawingDocument.ConvertCoordsToCursorWR_Comment( last_object.x, last_object.y, this.CurPage);
                var Coords2 = editor.WordControl.m_oDrawingDocument.ConvertCoordsToCursorWR_Comment( last_object.x + last_object.extX, last_object.y, this.CurPage);
                return  { X0 : Coords1.X, X1 : Coords2.X, Y : Coords1.Y};
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2467
            }
2468
            else
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2469
            {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2470 2471 2472 2473

                var Pos = editor.WordControl.m_oDrawingDocument.ConvertCoordsFromCursor2(global_mouseEvent.X, global_mouseEvent.Y);
                var Coords1 = editor.WordControl.m_oDrawingDocument.ConvertCoordsToCursorWR_Comment( 0, 0, this.CurPage);
                return  { X0 : Coords1.X, X1 : Coords1.X, Y : Coords1.Y};
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2474
            }
2475 2476 2477
        }
        return { X0 : 0, X1 : 0, Y : 0};
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2478

2479 2480 2481 2482
    Clear_ContentChanges : function()
    {
        this.m_oContentChanges.Clear();
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2483

2484 2485 2486 2487
    Add_ContentChanges : function(Changes)
    {
        this.m_oContentChanges.Add( Changes );
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2488

2489 2490 2491
    Refresh_ContentChanges : function()
    {
        this.m_oContentChanges.Refresh();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2492 2493
    },

2494 2495

    Document_Format_Copy : function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2496
    {
2497 2498 2499
        this.CopyTextPr = this.Get_Paragraph_TextPr_Copy();
        this.CopyParaPr = this.Get_Paragraph_ParaPr_Copy();
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2500

Oleg.Korshul's avatar
 
Oleg.Korshul committed
2501 2502 2503 2504
    Document_Format_Paste : function()
    {
        // TODO: (начать с создания точки истории, либо добавить ее при обработке клавиш)
    },
2505 2506 2507 2508 2509

    // Возвращаем выделенный текст, если в выделении не более 1 параграфа, и там нет картинок, нумерации страниц и т.д.
    Get_SelectedText : function(bClearText)
    {
        return this.Slides[this.CurPage].graphicObjects.Get_SelectedText(bClearText);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2510
    },
2511

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2512 2513 2514
//-----------------------------------------------------------------------------------
// Функции для работы с таблицами
//-----------------------------------------------------------------------------------
2515
    ApplyTableFunction : function(Function, bBefore, bAll, Cols, Rows)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2516
    {
2517
        if(this.Slides[this.CurPage])
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2518
        {
2519 2520
            var args;
            if(isRealNumber(Rows) && isRealNumber(Cols))
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2521
            {
2522
                args = [Rows, Cols];
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2523
            }
2524
            else
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2525
            {
2526
                args = [bBefore];
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2527
            }
2528 2529
            var target_text_object = getTargetTextObject(this.Slides[this.CurPage].graphicObjects);
            if(target_text_object && target_text_object.getObjectType() === historyitem_type_GraphicFrame)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2530
            {
2531 2532 2533 2534 2535 2536
                Function.apply(target_text_object.graphicObject, args);
                if(target_text_object.graphicObject.Content.length === 0)
                {
                    this.Table_RemoveTable();
                    return;
                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2537
                this.Recalculate();
2538
                this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2539
            }
2540
            else
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2541
            {
2542 2543
                var by_types = this.Slides[this.CurPage].graphicObjects.getSelectedObjectsByTypes(true);
                if(by_types.tables.length === 1)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2544
                {
2545 2546
                    by_types.tables[0].Set_CurrentElement();
                    if(!(bAll === true))
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2547
                    {
2548
                        if(bBefore)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2549
                        {
2550
                            by_types.tables[0].graphicObject.Cursor_MoveToStartPos();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2551 2552 2553
                        }
                        else
                        {
2554
                            by_types.tables[0].graphicObject.Cursor_MoveToStartPos();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2555 2556
                        }
                    }
2557 2558 2559 2560 2561 2562 2563 2564 2565 2566
                    else
                    {
                        by_types.tables[0].graphicObject.Select_All();
                    }
                    Function.apply(by_types.tables[0].graphicObject, args);
                    if(by_types.tables[0].graphicObject.Content.length === 0)
                    {
                        this.Table_RemoveTable();
                        return;
                    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2567
                    this.Recalculate();
2568 2569
                    this.Document_UpdateSelectionState();
                    this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2570
                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2571 2572
            }
        }
2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583
    },


    Table_AddRow : function(bBefore)
    {
        this.ApplyTableFunction(CTable.prototype.Row_Add, bBefore);
    },

    Table_AddCol : function(bBefore)
    {
        this.ApplyTableFunction(CTable.prototype.Col_Add, bBefore);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2584 2585 2586 2587
    },

    Table_RemoveRow : function()
    {
2588
        this.ApplyTableFunction(CTable.prototype.Row_Remove, undefined);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2589 2590 2591 2592
    },

    Table_RemoveCol : function()
    {
2593
        this.ApplyTableFunction(CTable.prototype.Col_Remove, true);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2594 2595 2596 2597
    },

    Table_MergeCells : function()
    {
2598
        this.ApplyTableFunction(CTable.prototype.Cell_Merge, true, true);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2599 2600 2601 2602
    },

    Table_SplitCell : function( Cols, Rows )
    {
2603
        this.ApplyTableFunction(CTable.prototype.Cell_Split, true, true, parseInt(Cols, 10), parseInt(Rows, 10) );
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2604 2605
    },

2606
    Table_RemoveTable : function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2607
    {
2608
        if(this.Slides[this.CurPage])
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2609
        {
2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627
            var by_types = this.Slides[this.CurPage].graphicObjects.getSelectedObjectsByTypes(true);
            if(by_types.tables.length === 1)
            {
                by_types.tables[0].deselect(this.Slides[this.CurPage].graphicObjects);
                this.Slides[this.CurPage].graphicObjects.resetInternalSelection();
                if(by_types.tables[0].group)
                {
                    by_types.tables[0].group.removeFromSpTree(by_types.tables[0].Id);
                }
                else
                {
                    this.Slides[this.CurPage].removeFromSpTreeById(by_types.tables[0].Id);
                }
                by_types.tables[0].setBDeleted(true);
                this.Recalculate();
                this.Document_UpdateInterfaceState();
                this.Document_UpdateSelectionState();
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2628 2629 2630 2631 2632
        }
    },

    Table_Select : function(Type)
    {
2633
        if(this.Slides[this.CurPage])
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2634
        {
2635 2636 2637 2638 2639 2640 2641 2642
            var by_types = this.Slides[this.CurPage].graphicObjects.getSelectedObjectsByTypes(true);
            if(by_types.tables.length === 1)
            {
                by_types.tables[0].Set_CurrentElement();
                by_types.tables[0].graphicObject.Table_Select(Type);
                this.Document_UpdateSelectionState();
                this.Document_UpdateInterfaceState();
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2643 2644 2645
        }
    },

2646
    Table_CheckFunction : function(Function)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2647
    {
2648
        if(this.Slides[this.CurPage])
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2649
        {
2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667
            var target_text_object = getTargetTextObject(this.Slides[this.CurPage].graphicObjects);
            if(target_text_object && target_text_object.getObjectType() === historyitem_type_GraphicFrame)
            {
                return Function.apply(target_text_object.graphicObject, []);
            }
           //else
           //{
           //    return
           //    var by_types = this.Slides[this.CurPage].graphicObjects.getSelectedObjectsByTypes(true);
           //    if(by_types.tables.length === 1)
           //    {
           //        var ret;
           //        by_types.tables[0].graphicObject.Set_ApplyToAll(true);
           //        ret = Function.apply(by_types.tables[0].graphicObject, []);
           //        by_types.tables[0].graphicObject.Set_ApplyToAll(false);
           //        return ret;
           //    }
           //}
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2668 2669 2670 2671
        }
        return false;
    },

2672 2673 2674 2675 2676
    Table_CheckMerge : function()
    {
        return this.Table_CheckFunction(CTable.prototype.Check_Merge);
    },

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2677 2678
    Table_CheckSplit : function()
    {
2679
        return this.Table_CheckFunction(CTable.prototype.Check_Split);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690
    },

    Check_TableCoincidence : function(Table)
    {
        return false;
    },
//-----------------------------------------------------------------------------------
// Дополнительные функции
//-----------------------------------------------------------------------------------
    Document_CreateFontMap : function()
    {
2691
        //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2692 2693 2694 2695 2696
        return;
    },

    Document_CreateFontCharMap : function(FontCharMap)
    {
2697
        //TODO !!!!!!!!!!
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2698 2699 2700 2701
    },

    Document_Get_AllFontNames : function()
    {
2702
        var AllFonts = {};
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2703
        for(var i =0 ; i < this.Slides.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2704
        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2705
            this.Slides[i].getAllFonts(AllFonts)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2706 2707 2708 2709 2710 2711 2712 2713 2714
        }
        return AllFonts;
    },

    // Обновляем текущее состояние (определяем где мы находимся, картинка/параграф/таблица/колонтитул)
    Document_UpdateInterfaceState : function()
    {
        editor.sync_BeginCatchSelectedElements();
        editor.ClearPropObjCallback();
2715 2716 2717 2718 2719 2720
        if(this.Slides[this.CurPage])
        {
            editor.sync_slidePropCallback(this.Slides[this.CurPage]);
            var graphic_objects = this.Slides[this.CurPage].graphicObjects;
            var target_content = graphic_objects.getTargetDocContent(), drawing_props = graphic_objects.getDrawingProps(), i;
            var para_pr = graphic_objects.getParagraphParaPr(), text_pr = graphic_objects.getParagraphTextPr();
2721
            var flag = undefined;
2722 2723 2724
            if(!para_pr)
            {
                para_pr = new CParaPr();
2725
                flag = true;
2726 2727 2728 2729 2730
            }
            if(!text_pr)
            {
                text_pr = new CTextPr();
            }
2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746
            var theme = graphic_objects.getTheme();
            if(text_pr.RFonts)
            {
                if(text_pr.RFonts.Ascii)
                    text_pr.RFonts.Ascii.Name    = theme.themeElements.fontScheme.checkFont(text_pr.RFonts.Ascii.Name);
                if(text_pr.RFonts.EastAsia)
                    text_pr.RFonts.EastAsia.Name = theme.themeElements.fontScheme.checkFont(text_pr.RFonts.EastAsia.Name);
                if(text_pr.RFonts.HAnsi)
                    text_pr.RFonts.HAnsi.Name    = theme.themeElements.fontScheme.checkFont(text_pr.RFonts.HAnsi.Name);
                if(text_pr.RFonts.CS)
                    text_pr.RFonts.CS.Name       = theme.themeElements.fontScheme.checkFont(text_pr.RFonts.CS.Name);
            }
            if(text_pr.FontFamily)
            {
                text_pr.FontFamily.Name = theme.themeElements.fontScheme.checkFont(text_pr.FontFamily.Name);
            }
2747
            editor.sync_PrLineSpacingCallBack(para_pr.Spacing);
2748 2749
            if(!target_content)
            {
2750
               //editor.UpdateParagraphProp( para_pr, flag );
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2751 2752 2753 2754 2755 2756
                //if(selected_objects.length === 1 )
                //{
                //    if ( "undefined" != typeof(para_props.Tabs) && null != para_props.Tabs )
                //        editor.Update_ParaTab( Default_Tab_Stop, para_props.Tabs );//TODO:
                //}
                editor.UpdateTextPr(text_pr);
2757
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2758

2759 2760 2761
            if(drawing_props.imageProps)
            {
                editor.sync_ImgPropCallback(drawing_props.imageProps);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2762 2763
            }

2764 2765 2766
            if(drawing_props.shapeProps)
            {
                editor.sync_shapePropCallback(drawing_props.shapeProps);
2767
                editor.sync_VerticalTextAlign(drawing_props.shapeProps.verticalTextAlign);
2768 2769
            }

2770
            if(drawing_props.chartProps && drawing_props.chartProps.chartProps)
2771
            {
2772 2773 2774 2775 2776 2777
                if(this.bNeedUpdateChartPreview)
                {
                    editor.chartPreviewManager.clearPreviews();
                    editor.asc_fireCallback("asc_onUpdateChartStyles");
                    this.bNeedUpdateChartPreview = false;
                }
2778 2779
                editor.sync_ImgPropCallback(drawing_props.chartProps);
            }
2780

2781

2782 2783
            if(drawing_props.tableProps)
            {
2784
                this.CheckTableStyles(this.Slides[this.CurPage], drawing_props.tableProps.TableLook);
2785 2786
                editor.sync_TblPropCallback(drawing_props.tableProps);
            }
2787 2788
            if(target_content)
            {
2789 2790
                target_content.Document_UpdateInterfaceState();
               /* if(para_pr)
2791
                {
2792
                    editor.UpdateParagraphProp( para_pr, flag );
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2793

2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804
                    editor.sync_PrLineSpacingCallBack(para_pr.Spacing);
                    //if(selected_objects.length === 1 )
                    //{
                    //    if ( "undefined" != typeof(para_props.Tabs) && null != para_props.Tabs )
                    //        editor.Update_ParaTab( Default_Tab_Stop, para_props.Tabs );//TODO:
                    //}
                }
                if(text_pr)
                {
                    editor.UpdateTextPr(text_pr);
                }
2805 2806 2807 2808 2809 2810 2811 2812 2813

                var Hyperlink = this.Hyperlink_Check(false);
                if (Hyperlink )
                {
                    var HyperText = new CParagraphGetText();
                    Hyperlink.Get_Text( HyperText );
                    var HyperProps = new CHyperlinkProperty(Hyperlink);
                    HyperProps.put_Text( HyperText.Text );
                    editor.sync_HyperlinkPropCallback(HyperProps);
2814
                }*/
2815
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2816
        }
2817
        editor.sync_EndCatchSelectedElements();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2818
        this.Document_UpdateUndoRedoState();
2819
        this.Document_UpdateRulersState();
2820

2821
        this.Document_UpdateCanAddHyperlinkState();
2822 2823 2824
        editor.asc_fireCallback("asc_onPresentationSize", this.Width, this.Height);
        editor.asc_fireCallback("asc_canIncreaseIndent", this.Can_IncreaseParagraphLevel(true));
        editor.asc_fireCallback("asc_canDecreaseIndent", this.Can_IncreaseParagraphLevel(false));
2825 2826
        editor.asc_fireCallback("asc_onCanGroup", this.canGroup());
        editor.asc_fireCallback("asc_onCanUnGroup", this.canUnGroup());
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2827 2828
    },

2829
    changeBackground: function(bg, arr_ind, bNoCreatePoint)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2830
    {
2831
        if(bNoCreatePoint === true || this.Document_Is_SelectionLocked(changestype_SlideBg) === false)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2832
        {
2833 2834 2835 2836
            if(!(bNoCreatePoint === true ))
            {
                History.Create_NewPoint();
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2837 2838 2839
            for(var i = 0; i <arr_ind.length; ++i)
            {
                this.Slides[arr_ind[i]].changeBackground(bg);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2840 2841 2842 2843 2844
            }

            this.Recalculate();
            for(var i = 0; i <arr_ind.length; ++i)
            {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2845 2846
                this.DrawingDocument.OnRecalculatePage(arr_ind[i], this.Slides[arr_ind[i]]);
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2847

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2848
            this.DrawingDocument.OnEndRecalculate(true, false);
2849 2850 2851 2852
            if(!(bNoCreatePoint === true ))
            {
                this.Document_UpdateInterfaceState();
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2853 2854 2855
        }
    },

2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875
    CheckTableStyles: function(Slide, TableLook)
    {
        if(!this.TablesForInterface)
        {
            this.TablesForInterface = [];
            var _x_mar = 10;
            var _y_mar = 10;
            var _r_mar = 10;
            var _b_mar = 10;
            var _pageW = 297;
            var _pageH = 210;

            var W = (_pageW - _x_mar - _r_mar);
            var H = (_pageH - _y_mar - _b_mar);
            var index = 0;
            ExecuteNoHistory(function(){
            for(var key in this.TableStylesIdMap)
            {
                if(this.TableStylesIdMap[key])
                {
2876
                    this.TablesForInterface[index] = this.Create_TableGraphicFrame(5, 5, Slide, key, W, H, _x_mar, _y_mar, true);
2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945
                    this.TablesForInterface[index].setBDeleted(true);
                    index++;
                }
            }
            }, this, []);
        }
        if(this.TablesForInterface.length === 0)
            return;
        var b_table_look = false;
        if(!this.LastTheme || this.LastTheme !== Slide.Layout.Master.Theme
            || this.LastColorScheme !== Slide.Layout.Master.Theme.themeElements.clrScheme
            || !this.LastColorMap || !this.LastColorMap.compare(Slide.Get_ColorMap())
        || !this.LastTableLook
        || (b_table_look = TableLook.m_bFirst_Col !== this.LastTableLook.m_bFirst_Col
                        || TableLook.m_bFirst_Row !== this.LastTableLook.m_bFirst_Row
                        || TableLook.m_bLast_Col  !== this.LastTableLook.m_bLast_Col
                        || TableLook.m_bLast_Row  !== this.LastTableLook.m_bLast_Row
                        || TableLook.m_bBand_Hor  !== this.LastTableLook.m_bBand_Hor
                        || TableLook.m_bBand_Ver  !== this.LastTableLook.m_bBand_Ver ) )
        {


            var only_redraw = !b_table_look && this.LastTheme === Slide.Layout.Master.Theme /*&& this.LastColorScheme === Slide.Layout.Master.Theme.themeElements.clrScheme && Slide.Get_ColorMap().compare(this.LastColorMap)*/;
            this.LastTheme = Slide.Layout.Master.Theme;
            this.LastColorScheme = Slide.Layout.Master.Theme.themeElements.clrScheme;
            this.LastColorMap = Slide.Get_ColorMap();
            this.LastTableLook = TableLook;
            var need_set_recalc = true, i;

            ExecuteNoHistory(function(){
                if(!only_redraw)
                {
                    var TableLook2;
                    if(b_table_look)
                    {
                        TableLook2 = new CTableLook(TableLook.m_bFirst_Col, TableLook.m_bFirst_Row, TableLook.m_bLast_Col, TableLook.m_bLast_Row, TableLook.m_bBand_Hor, TableLook.m_bBand_Ver);
                    }
                    if(this.TablesForInterface[0].parent !== Slide)
                    {
                        need_set_recalc = false;
                        for(i = 0; i < this.TablesForInterface.length; ++i)
                        {
                            this.TablesForInterface[i].setParent(Slide);
                            this.TablesForInterface[i].handleUpdateTheme();
                            if(TableLook2)
                            {
                                this.TablesForInterface[i].graphicObject.Set_TableLook(TableLook2);
                                this.TablesForInterface[i].graphicObject.Recalculate_Page(0);
                            }
                        }
                    }
                    if(need_set_recalc)
                    {
                        for(i = 0; i < this.TablesForInterface.length; ++i)
                        {
                            if(TableLook)
                            {
                                this.TablesForInterface[i].graphicObject.Set_TableLook(TableLook);
                            }
                            this.TablesForInterface[i].handleUpdateTheme();
                            this.TablesForInterface[i].graphicObject.Recalculate_Page(0);
                        }
                    }
                }
                this.DrawingDocument.CheckTableStyles();
            }, this, []);
        }
    },

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2946 2947 2948
    // Обновляем линейки
    Document_UpdateRulersState : function()
    {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2949
        if(this.Slides[this.CurPage])
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2950
        {
2951
            var target_content = this.Slides[this.CurPage].graphicObjects.getTargetDocContent(undefined, true);
2952
            if(target_content && target_content.Parent && target_content.Parent.getObjectType && target_content.Parent.getObjectType() === historyitem_type_TextBody)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2953
            {
2954
                return this.DrawingDocument.Set_RulerState_Paragraph( null , target_content.Parent.getMargins());
2955 2956 2957 2958
            }
            else if(target_content instanceof CTable)
            {
                return target_content.Document_UpdateRulersState(this.CurPage);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2959 2960
            }
        }
2961
        this.DrawingDocument.Set_RulerState_Paragraph(null);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2962 2963 2964 2965 2966
    },

    // Обновляем линейки
    Document_UpdateSelectionState : function()
    {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2967
        if(this.Slides[this.CurPage])
2968 2969 2970
        {
            this.Slides[this.CurPage].graphicObjects.updateSelectionState();
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986
    },

    Document_UpdateUndoRedoState : function()
    {

        // Проверяем состояние Undo/Redo
        editor.sync_CanUndoCallback( this.History.Can_Undo() );
        editor.sync_CanRedoCallback( this.History.Can_Redo() );

        if ( true === History.Have_Changes() )
        {
            editor.isDocumentModify = true;

            // дублирование евента. когда будет undo-redo - тогда
            // эти евенты начнут отличаться
            editor.asc_fireCallback("asc_onDocumentModifiedChanged");
2987
			editor._onUpdateDocumentCanSave();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001
        }
        else
        {
            editor.SetUnchangedDocument();
        }
    },

    Document_UpdateCanAddHyperlinkState : function()
    {
        editor.sync_CanAddHyperlinkCallback( this.Hyperlink_CanAdd(false) );
    },

    Set_CurPage : function(PageNum)
    {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3002 3003 3004
        if (-1 == PageNum)
        {
            this.CurPage = -1;
3005
            this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3006 3007 3008 3009
            return;
        }

        var oldCurPage = this.CurPage;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3010
        this.CurPage = Math.min( this.Slides.length - 1, Math.max( 0, PageNum ) );
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3011 3012
        if(oldCurPage != this.CurPage && this.CurPage < this.Slides.length)
        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3013 3014 3015 3016
            if(this.Slides[oldCurPage])
            {
                this.Slides[oldCurPage].graphicObjects.resetSelectionState();
            }
3017
            editor.asc_hideComments();
3018
            this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3019
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3020 3021 3022 3023 3024 3025 3026 3027
    },

    Get_CurPage : function()
    {
        return this.CurPage;
    },

    resetStateCurSlide: function()
3028 3029 3030
    {
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.resetSelection();
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043
//-----------------------------------------------------------------------------------
// Undo/Redo функции
//-----------------------------------------------------------------------------------
    Create_NewHistoryPoint : function()
    {
        this.History.Create_NewPoint();
    },

    Document_Undo : function()
    {
        if ( true === CollaborativeEditing.Get_GlobalLock() )
            return;

3044
        this.clearThemeTimeouts();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3045
        this.History.Undo();
3046
        this.Recalculate(this.History.RecalculateData);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3047 3048 3049 3050 3051 3052 3053 3054 3055 3056

        this.Document_UpdateSelectionState();
        this.Document_UpdateInterfaceState();
    },

    Document_Redo : function()
    {
        if ( true === CollaborativeEditing.Get_GlobalLock() )
            return;

3057
        this.clearThemeTimeouts();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3058
        this.History.Redo();
3059
        this.Recalculate(this.History.RecalculateData);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3060 3061 3062 3063 3064 3065 3066 3067 3068

        this.Document_UpdateSelectionState();
        this.Document_UpdateInterfaceState();
    },

    Get_SelectionState : function()
    {
        var s = {};
        s.CurPage = this.CurPage;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3069
        if(this.CurPage > -1)
3070 3071 3072 3073
            s.slideSelection = this.Slides[this.CurPage].graphicObjects.getSelectionState();
        return s;
    },

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3074 3075
    Get_SelectedContent : function()
    {
3076
        return ExecuteNoHistory(function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3077
        {
3078 3079
            var ret = new PresentationSelectedContent(), i;
            if(this.Slides.length > 0)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3080
            {
3081
                switch(editor.WordControl.Thumbnails.FocusObjType)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3082
                {
3083
                    case FOCUS_OBJECT_MAIN:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3084
                    {
3085 3086
                        var target_text_object = getTargetTextObject(this.Slides[this.CurPage].graphicObjects);
                        if(target_text_object)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3087
                        {
3088 3089
                            var doc_content = this.Slides[this.CurPage].graphicObjects.getTargetDocContent();
                            if(target_text_object.getObjectType() === historyitem_type_GraphicFrame && !doc_content)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3090
                            {
3091 3092 3093 3094 3095 3096 3097 3098 3099 3100
                                if(target_text_object.graphicObject)
                                {
                                    var GraphicFrame = target_text_object.copy();
                                    var SelectedContent = new CSelectedContent();
                                    target_text_object.graphicObject.Get_SelectedContent(SelectedContent);
                                    var Table = SelectedContent.Elements[0].Element;
                                    GraphicFrame.setGraphicObject(Table);
                                    Table.Set_Parent(GraphicFrame);
                                    ret.Drawings.push(new DrawingCopyObject(GraphicFrame, target_text_object.x, target_text_object.y, target_text_object.extX, target_text_object.extY, target_text_object.getBase64Img()) );
                                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3101
                            }
3102
                            else
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3103
                            {
3104 3105 3106 3107 3108 3109
                                if(doc_content)
                                {
                                    var SelectedContent = new CSelectedContent();
                                    doc_content.Get_SelectedContent(SelectedContent);
                                    ret.DocContent = SelectedContent;
                                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3110 3111
                            }
                        }
3112
                        else
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3113
                        {
3114

3115
                            var selector = this.Slides[this.CurPage].graphicObjects.selection.groupSelection ? this.Slides[this.CurPage].graphicObjects.selection.groupSelection : this.Slides[this.CurPage].graphicObjects;
3116
                            if(selector.selection.chartSelection && selector.selection.chartSelection.selection.title)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3117
                            {
3118 3119 3120
                                var doc_content = selector.selection.chartSelection.selection.title.getDocContent();
                                if(doc_content)
                                {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3121

3122 3123 3124 3125 3126 3127
                                    var SelectedContent = new CSelectedContent();
                                    doc_content.Set_ApplyToAll(true);
                                    doc_content.Get_SelectedContent(SelectedContent);
                                    doc_content.Set_ApplyToAll(false);
                                    ret.DocContent = SelectedContent;
                                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3128
                            }
3129
                            else
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3130
                            {
3131 3132 3133
                                var bRecursive = isRealObject(this.Slides[this.CurPage].graphicObjects.selection.groupSelection);
                                var aSpTree = bRecursive ? this.Slides[this.CurPage].graphicObjects.selection.groupSelection.spTree : this.Slides[this.CurPage].cSld.spTree;
                                collectSelectedObjects(aSpTree, ret.Drawings, bRecursive);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3134 3135
                            }
                        }
3136
                        break;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3137
                    }
3138
                    case FOCUS_OBJECT_THUMBNAILS :
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3139
                    {
3140 3141 3142 3143 3144
                        var selected_slides = editor.WordControl.Thumbnails.GetSelectedArray();
                        for(i = 0; i < selected_slides.length; ++i)
                        {
                            ret.SlideObjects.push(new SlideCopyObject(this.Slides[selected_slides[i]].createDuplicate(), this.Slides[selected_slides[i]].getBase64Img()));
                        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3145 3146 3147
                    }
                }
            }
3148 3149
            return ret;
        }, this, []);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3150 3151 3152 3153 3154 3155 3156
    },

    Insert_Content : function(Content)
    {
        var selected_slides = editor.WordControl.Thumbnails.GetSelectedArray(), i;
        if(Content.SlideObjects.length > 0)
        {
3157
            var las_slide_index = selected_slides.length > 0 ? selected_slides[selected_slides.length-1] : -1;
3158 3159

            this.needSelectPages.length = 0;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3160 3161 3162
            for(i = 0; i < Content.SlideObjects.length; ++i)
            {
                this.insertSlide(las_slide_index + i + 1, Content.SlideObjects[i].Slide);
3163
                this.needSelectPages.push(las_slide_index + i + 1);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3164
            }
3165 3166
            this.CurPage = las_slide_index + 1;
            this.bGoToPage = true;
3167
            this.bNeedUpdateTh = true;
3168

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3169 3170 3171 3172 3173
        }
        else if(this.Slides[this.CurPage])
        {
            if(Content.Drawings.length > 0)
            {
3174
                this.Slides[this.CurPage].graphicObjects.resetSelection();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3175 3176
                for(i = 0; i < Content.Drawings.length; ++i)
                {
3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187
                    if(Content.Drawings[i].Drawing.bDeleted)
                    {
                        if(Content.Drawings[i].Drawing.setBDeleted2)
                        {
                            Content.Drawings[i].Drawing.setBDeleted2(false);
                        }
                        else if(Content.Drawings[i].Drawing.setBDeleted)
                        {
                            Content.Drawings[i].Drawing.setBDeleted(false);
                        }
                    }
3188
                    Content.Drawings[i].Drawing.setParent2(this.Slides[this.CurPage]);
3189 3190 3191 3192
                    if(Content.Drawings[i].Drawing.getObjectType() === historyitem_type_GraphicFrame)
                    {
                        this.Check_GraphicFrameRowHeight(Content.Drawings[i].Drawing);
                    }
3193
                    Content.Drawings[i].Drawing.addToDrawingObjects();
3194
                    this.Slides[this.CurPage].graphicObjects.selectObject(Content.Drawings[i].Drawing, 0);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3195 3196 3197 3198
                }
            }
            else if(Content.DocContent)
            {
3199
                var target_doc_content = this.Slides[this.CurPage].graphicObjects.getTargetDocContent(true), paragraph, NearPos;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3200 3201
                if(target_doc_content)
                {
3202 3203 3204 3205 3206
                    if(target_doc_content.Selection.Use)
                    {
                        this.Slides[this.CurPage].graphicObjects.removeCallback(1);
                    }
                    paragraph = target_doc_content.Content[target_doc_content.CurPos.ContentPos];
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3207 3208
                    if (null != paragraph && type_Paragraph == paragraph.GetType())
                    {
3209
                        NearPos = { Paragraph: paragraph, ContentPos: paragraph.Get_ParaContentPos(false, false) };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3210 3211 3212 3213 3214 3215 3216 3217 3218
                        paragraph.Check_NearestPos(NearPos);
                        target_doc_content.Insert_Content(Content.DocContent, NearPos);
                    }
                }
                else
                {
                    var track_object = new NewShapeTrack("textRect", 0, 0, this.Slides[this.CurPage].Layout.Master.Theme, this.Slides[this.CurPage].Layout.Master, this.Slides[this.CurPage].Layout, this.Slides[this.CurPage], this.CurPage);
                    track_object.track({}, 0, 0);
                    var shape = track_object.getShape(false, this.DrawingDocument, this.Slides[this.CurPage]);
3219 3220 3221 3222 3223 3224 3225 3226
                    shape.setParent(this.Slides[this.CurPage]);
                    paragraph = shape.txBody.content.Content[0];
                    NearPos = { Paragraph: paragraph, ContentPos: paragraph.Get_ParaContentPos(false, false) };
                    paragraph.Check_NearestPos(NearPos);
                    var old_val = Content.DocContent.MoveDrawing;
                    Content.DocContent.MoveDrawing = true;
                    shape.txBody.content.Insert_Content(Content.DocContent, NearPos);
                    Content.DocContent.MoveDrawing = old_val;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3227 3228 3229 3230 3231 3232 3233 3234 3235
                    var body_pr = shape.getBodyPr();
                    var w = shape.txBody.getMaxContentWidth(this.Width/2, true) + body_pr.lIns + body_pr.rIns;
                    var h = shape.txBody.content.Get_SummaryHeight() + body_pr.tIns + body_pr.bIns;
                    shape.spPr.xfrm.setExtX(w);
                    shape.spPr.xfrm.setExtY(h);
                    shape.spPr.xfrm.setOffX((this.Width - w) / 2);
                    shape.spPr.xfrm.setOffY((this.Height - h) / 2);
                    shape.setParent(this.Slides[this.CurPage]);
                    shape.addToDrawingObjects();
3236
                    this.Slides[this.CurPage].graphicObjects.resetSelection();
3237
                    this.Slides[this.CurPage].graphicObjects.selectObject(shape, 0);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3238 3239 3240 3241 3242
                }
            }
        }
    },

3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253
    Check_CursorMoveRight : function()
    {
        if(this.Slides[this.CurPage])
        {
            if(this.Slides[this.CurPage].graphicObjects.getTargetDocContent(false, false))
            {
                this.Slides[this.CurPage].graphicObjects.cursorMoveRight(false, false);
            }
        }
    },

3254 3255 3256 3257
    Set_SelectionState : function(State)
    {
        if(State.CurPage > -1)
            this.Slides[State.CurPage].graphicObjects.setSelectionState(State.slideSelection);
3258 3259 3260 3261 3262
        if(State.CurPage !== this.CurPage)
            this.bGoToPage = true;
        this.CurPage = State.CurPage;
        //this.Set_CurPage(State.CurPage);

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3263 3264 3265 3266 3267 3268 3269 3270
    },

    Undo : function(Data)
    {
        var Type = Data.Type;

        switch ( Type )
        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3271 3272 3273 3274 3275 3276
            case historyitem_Document_DefaultTab:
            {
                Default_Tab_Stop = Data.Old;

                break;
            }
3277
            case historyitem_Presentation_AddSlide:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3278 3279
            {
                this.Slides.splice(Data.Pos, 1);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3280 3281 3282 3283
                for(var i = 0; i < this.Slides.length; ++i)
                {
                    this.DrawingDocument.OnRecalculatePage(i, this.Slides[i]);
                }
3284
                this.DrawingDocument.OnEndRecalculate();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3285 3286
                break;
            }
3287
            case historyitem_Presentation_RemoveSlide:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3288 3289
            {
                this.Slides.splice(Data.Pos, 0, g_oTableId.Get_ById(Data.Id));
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3290 3291 3292 3293
                for(var i = 0; i < this.Slides.length; ++i)
                {
                    this.DrawingDocument.OnRecalculatePage(i, this.Slides[i]);
                }
3294
                this.DrawingDocument.OnEndRecalculate();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3295 3296
                break;
            }
3297
            case historyitem_Presentation_SlideSize:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3298 3299 3300
            {
                var kw = Data.oldW/this.Width;
                var kh = Data.oldH/this.Height;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3301 3302 3303

                this.Width = Data.oldW;
                this.Height = Data.oldH;
3304
                this.changeSlideSizeFunction(this.Width, this.Height);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3305 3306
                editor.asc_fireCallback("asc_onPresentationSize", this.Width, this.Height);

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3307 3308
                break;
            }
3309
            case historyitem_Presentation_AddSlideMaster:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3310 3311 3312 3313
            {
                this.slideMasters.splice(Data.pos, 1);
                break;
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3314 3315 3316 3317 3318 3319 3320 3321 3322
        }
    },

    Redo : function(Data)
    {
        var Type = Data.Type;

        switch ( Type )
        {
3323
            case historyitem_Presentation_AddSlide:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3324 3325
            {
                this.Slides.splice(Data.Pos, 0, g_oTableId.Get_ById(Data.Id));
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3326 3327 3328 3329
                for(var i = 0; i < this.Slides.length; ++i)
                {
                    this.DrawingDocument.OnRecalculatePage(i, this.Slides[i]);
                }
3330
                this.DrawingDocument.OnEndRecalculate();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3331 3332
                break;
            }
3333
            case historyitem_Presentation_RemoveSlide:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3334 3335
            {
                this.Slides.splice(Data.Pos, 1);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3336 3337 3338 3339
                for(var i = 0; i < this.Slides.length; ++i)
                {
                    this.DrawingDocument.OnRecalculatePage(i, this.Slides[i]);
                }
3340
                this.DrawingDocument.OnEndRecalculate();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3341 3342
                break;
            }
3343
            case historyitem_Presentation_SlideSize:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3344 3345 3346
            {
                var kw = Data.newW/this.Width;
                var kh = Data.newH/this.Height;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3347 3348
                this.Width = Data.newW;
                this.Height = Data.newH;
3349
                this.changeSlideSizeFunction(this.Width, this.Height);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3350
                editor.asc_fireCallback("asc_onPresentationSize", this.Width, this.Height);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3351 3352
                break;
            }
3353
            case historyitem_Presentation_AddSlideMaster:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3354 3355 3356 3357
            {
                this.slideMasters.splice(Data.pos, 0, Data.master);
                break;
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3358 3359 3360 3361 3362 3363 3364 3365 3366 3367
        }
    },

    Get_ParentObject_or_DocumentPos : function(Index)
    {
        return { Type : historyrecalctype_Inline, Data : Index };
    },

    Refresh_RecalcData : function(Data)
    {
3368 3369
        var recalculateMaps, key;
        switch ( Data.Type )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3370
        {
3371
            case historyitem_Presentation_AddSlide:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3372 3373 3374
            {
                break;
            }
3375
            case historyitem_Presentation_RemoveSlide:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3376
            {
3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434
                break;
            }
            case historyitem_Presentation_SlideSize:
            {
                recalculateMaps = this.GetRecalculateMaps();
                for(key in recalculateMaps.masters)
                {
                    if(recalculateMaps.masters.hasOwnProperty(key))
                    {
                        recalculateMaps.masters[key].checkSlideSize();
                    }
                }
                for(key in recalculateMaps.layouts)
                {
                    if(recalculateMaps.layouts.hasOwnProperty(key))
                    {
                        recalculateMaps.layouts[key].checkSlideSize();
                    }
                }
                for(key = 0; key < this.Slides.length; ++key)
                {
                    this.Slides[key].checkSlideSize();
                }
                break;
            }
            case historyitem_Presentation_AddSlideMaster:
            {
                break;
            }
            case historyitem_Presentation_ChangeTheme:
            {
                for(var i = 0; i < Data.arrIndex.length; ++i)
                {
                    this.Slides[Data.arrIndex[i]] && this.Slides[Data.arrIndex[i]].checkSlideTheme();
                }
                break;
            }
            case historyitem_Presentation_ChangeColorScheme:
            {
                recalculateMaps = this.GetRecalculateMaps();
                for(key in recalculateMaps.masters)
                {
                    if(recalculateMaps.masters.hasOwnProperty(key))
                    {
                        recalculateMaps.masters[key].checkSlideColorScheme();
                    }
                }
                for(key in recalculateMaps.layouts)
                {
                    if(recalculateMaps.layouts.hasOwnProperty(key))
                    {
                        recalculateMaps.layouts[key].checkSlideColorScheme();
                    }
                }
                for(var i = 0; i < Data.arrIndex.length; ++i)
                {
                    this.Slides[Data.arrIndex[i]] && this.Slides[Data.arrIndex[i]].checkSlideTheme();
                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3435 3436 3437
                break;
            }
        }
3438
        this.Refresh_RecalcData2(Data);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3439 3440
    },

3441
    Refresh_RecalcData2 : function(Data)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3442
    {
3443
        switch ( Data.Type )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3444
        {
3445
            case historyitem_Presentation_AddSlide:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3446
            {
3447
                break;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3448
            }
3449
            case historyitem_Presentation_RemoveSlide:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3450
            {
3451
                break;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3452
            }
3453
            case historyitem_Presentation_SlideSize:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3454
            {
3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469
                History.RecalcData_Add({Type: historyrecalctype_Drawing, All: true});
                break;
            }
            case historyitem_Presentation_AddSlideMaster:
            {
                break;
            }
            case historyitem_Presentation_ChangeTheme:
            {
                History.RecalcData_Add({Type: historyrecalctype_Drawing, Theme: true, ArrInd: Data.arrIndex});
                break;
            }
            case historyitem_Presentation_ChangeColorScheme:
            {
                History.RecalcData_Add({Type: historyrecalctype_Drawing, ColorScheme: true, ArrInd: Data.arrIndex});
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3470 3471 3472 3473 3474 3475 3476 3477 3478 3479
                break;
            }
        }
    },

//-----------------------------------------------------------------------------------
// Функции для работы с гиперссылками
//-----------------------------------------------------------------------------------
    Hyperlink_Add : function(HyperProps)
    {
3480 3481 3482
        if(this.Slides[this.CurPage])
        {
            this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.hyperlinkAdd, [HyperProps]);
3483
            this.Document_UpdateInterfaceState();
3484
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3485 3486 3487 3488
    },

    Hyperlink_Modify : function(HyperProps)
    {
3489 3490 3491
        if(this.Slides[this.CurPage])
        {
            this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.hyperlinkModify, [HyperProps]);
3492
            this.Document_UpdateInterfaceState();
3493
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3494 3495 3496 3497
    },

    Hyperlink_Remove : function()
    {
3498 3499 3500
        if(this.Slides[this.CurPage])
        {
            this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.hyperlinkRemove, []);
3501
            this.Document_UpdateInterfaceState();
3502
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3503 3504 3505 3506
    },

    Hyperlink_CanAdd : function(bCheckInHyperlink)
    {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3507
        if(this.Slides[this.CurPage])
3508
            return this.Slides[this.CurPage].graphicObjects.hyperlinkCanAdd(bCheckInHyperlink);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3509
        return false;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3510 3511 3512 3513
    },

    canGroup: function()
    {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3514 3515 3516
        if(this.Slides[this.CurPage])
            return this.Slides[this.CurPage].graphicObjects.canGroup();
        return false
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3517 3518 3519 3520
    },

    canUnGroup: function()
    {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3521 3522 3523
        if(this.Slides[this.CurPage])
            return this.Slides[this.CurPage].graphicObjects.canUnGroup();
        return false;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3524 3525 3526 3527
    },

    alignLeft : function()
    {
3528
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.alignLeft(editor.bAlignBySelected);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3529 3530 3531 3532
    },

    alignRight : function()
    {
3533
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.alignRight(editor.bAlignBySelected);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3534 3535 3536 3537
    },

    alignTop : function()
    {
3538
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.alignTop(editor.bAlignBySelected);
3539
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3540 3541 3542

    alignBottom : function()
    {
3543
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.alignBottom(editor.bAlignBySelected);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3544 3545 3546 3547
    },

    alignCenter : function()
    {
3548
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.alignCenter(editor.bAlignBySelected);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3549 3550 3551 3552
    },

    alignMiddle : function()
    {
3553
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.alignMiddle(editor.bAlignBySelected);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3554 3555 3556 3557
    },

    distributeHor : function()
    {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3558
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.distributeHor, [editor.bAlignBySelected]);
3559
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3560 3561 3562
    },
    distributeVer : function()
    {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3563
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.distributeVer, [editor.bAlignBySelected]);
3564
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3565 3566 3567 3568
    },

    bringToFront : function()
    {
3569
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.bringToFront);   //TODO: Передавать тип проверки
3570
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3571 3572 3573 3574
    },

    bringForward : function()
    {
3575
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.bringForward);   //TODO: Передавать тип проверки
3576
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3577 3578 3579 3580
    },

    sendToBack : function()
    {
3581 3582

        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.sendToBack);   //TODO: Передавать тип проверки
3583
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3584 3585 3586 3587 3588
    },


    bringBackward : function()
    {
3589
        this.Slides[this.CurPage] && this.Slides[this.CurPage].graphicObjects.checkSelectedObjectsAndCallback(this.Slides[this.CurPage].graphicObjects.bringBackward);   //TODO: Передавать тип проверки
3590
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3591 3592 3593 3594 3595
    },

    // Проверяем, находимся ли мы в гиперссылке сейчас
    Hyperlink_Check : function(bCheckEnd)
    {
3596
        return isRealObject(this.Slides[this.CurPage]) && this.Slides[this.CurPage].graphicObjects.hyperlinkCheck(bCheckEnd);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3597 3598 3599
    },


Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3600
    addNextSlide: function(layoutIndex)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3601
    {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3602
        History.Create_NewPoint();
3603
        var  new_slide, layout, i, _ph_type, sp;
3604
        if(this.Slides[this.CurPage])
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3605
        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3606 3607
            var cur_slide = this.Slides[this.CurPage];

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3608
            layout = isRealNumber(layoutIndex) ? (cur_slide.Layout.Master.sldLayoutLst[layoutIndex] ?  cur_slide.Layout.Master.sldLayoutLst[layoutIndex]:  cur_slide.Layout) : cur_slide.Layout.Master.getMatchingLayout(cur_slide.Layout.type, cur_slide.Layout.matchingName, cur_slide.Layout.cSld.name);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3609
            new_slide = new Slide(this, layout, this.CurPage + 1);
3610
            for(i = 0; i < layout.cSld.spTree.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3611 3612 3613
            {
                if(layout.cSld.spTree[i].isPlaceholder())
                {
3614
                    _ph_type = layout.cSld.spTree[i].getPhType();
3615 3616
                    if(_ph_type != phType_dt && _ph_type != phType_ftr && _ph_type != phType_hdr && _ph_type != phType_sldNum)
                    {
3617
                        sp = layout.cSld.spTree[i].copy();
3618 3619
                        sp.setParent(new_slide);
                        sp.clearContent && sp.clearContent();
3620 3621
                        new_slide.addToSpTreeToPos(new_slide.cSld.spTree.length, sp);
                    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3622 3623 3624
                }
            }
            new_slide.setSlideNum(this.CurPage + 1);
3625
            new_slide.setSlideSize(this.Width, this.Height);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3626 3627
            this.insertSlide(this.CurPage+1,  new_slide);

3628
            for(i = this.CurPage + 2; i < this.Slides.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3629 3630 3631
            {
                this.Slides[i].setSlideNum(i);
            }
3632
            this.Recalculate();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3633 3634 3635
        }
        else
        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3636
            var master = this.slideMasters[0];
3637 3638 3639 3640 3641

            layout = isRealNumber(layoutIndex) ? (master.sldLayoutLst[layoutIndex] ?  master.sldLayoutLst[layoutIndex]:  master.sldLayoutLst[0]) : master.sldLayoutLst[0];


            new_slide = new Slide(this, layout, this.CurPage + 1);
3642
            for(i = 0; i < layout.cSld.spTree.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3643
            {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3644 3645
                if(layout.cSld.spTree[i].isPlaceholder())
                {
3646
                    _ph_type = layout.cSld.spTree[i].getPhType();
3647 3648
                    if(_ph_type != phType_dt && _ph_type != phType_ftr && _ph_type != phType_hdr && _ph_type != phType_sldNum)
                    {
3649
                        sp = layout.cSld.spTree[i].copy();
3650 3651 3652 3653
                        sp.setParent(new_slide);
                        sp.clearContent && sp.clearContent();
                        new_slide.addToSpTreeToPos(new_slide.cSld.spTree.length, sp);
                    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3654
                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3655
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3656
            new_slide.setSlideNum(this.CurPage + 1);
3657
            new_slide.setSlideSize(this.Width, this.Height);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3658
            this.insertSlide(this.CurPage+1,  new_slide);
3659
            this.Recalculate();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3660
        }
3661
        this.DrawingDocument.m_oWordControl.GoToPage(this.CurPage + 1);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3662
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3663 3664 3665
    },


Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3666 3667 3668 3669 3670 3671 3672
    DublicateSlide: function()
    {
        var selected_slides = editor.WordControl.Thumbnails.GetSelectedArray();
        this.shiftSlides(Math.max.apply(Math, selected_slides) + 1, selected_slides, true);
    },

    shiftSlides: function(pos, array, bCopy)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3673 3674
    {
        History.Create_NewPoint();
3675
        array.sort(fSortAscending);
3676
        var deleted = [], i;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3677 3678

        if(!(bCopy === true || global_mouseEvent.CtrlKey))
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3679
        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3680 3681 3682 3683
            for(i = array.length -1; i > - 1; --i)
            {
                deleted.push(this.removeSlide(array[i]));
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3684

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3685 3686 3687 3688 3689 3690 3691 3692 3693
            for(i = 0; i < array.length; ++i)
            {
                if(array[i] < pos)
                    --pos;
                else
                    break;
            }
        }
        else
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3694
        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3695 3696 3697 3698
            for(i = array.length -1; i > - 1; --i)
            {
                deleted.push(this.Slides[array[i]].createDuplicate());
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3699 3700
        }

3701 3702 3703
        var _selectedPage = this.CurPage;
        var _newSelectedPage = 0;

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3704
        deleted.reverse();
3705
        for(i = 0; i < deleted.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3706 3707 3708 3709 3710
        {
            this.insertSlide(pos + i, deleted[i]);
        }
        for(i = 0; i < this.Slides.length; ++i)
        {
3711 3712 3713
            if (this.Slides[i].num == _selectedPage)
                _newSelectedPage = i;

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3714 3715
            this.Slides[i].changeNum(i);
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3716
        this.Recalculate();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3717 3718 3719
        this.Document_UpdateUndoRedoState();
        this.DrawingDocument.OnEndRecalculate();
        this.DrawingDocument.UpdateThumbnailsAttack();
3720
        this.DrawingDocument.m_oWordControl.GoToPage(_newSelectedPage);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3721 3722 3723 3724
    },

    deleteSlides: function(array)
    {
3725
        if(array.length > 0 && this.Document_Is_SelectionLocked(changestype_RemoveSlide, null) === false)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3726 3727
        {
            History.Create_NewPoint();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3728
            var oldLen = this.Slides.length;
3729
            array.sort(fSortAscending);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3730 3731 3732 3733 3734 3735 3736 3737
            for(var i = array.length -1; i > - 1; --i)
            {
                this.removeSlide(array[i]);
            }
            for(i = 0; i < this.Slides.length; ++i)
            {
                this.Slides[i].changeNum(i);
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3738 3739
            if(array[array.length-1] != oldLen-1)
            {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3740 3741 3742
                //this.Set_CurPage(array[array.length-1]+1 - array.length);
                this.DrawingDocument.m_oWordControl.GoToPage(array[array.length-1]+1 - array.length);

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3743 3744 3745
            }
            else
            {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3746 3747 3748
                //this.Set_CurPage(this.Slides.length -1);
                this.DrawingDocument.m_oWordControl.GoToPage(this.Slides.length -1);

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3749
            }
3750
            editor.sync_HideComment();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3751 3752 3753 3754 3755 3756
            this.Document_UpdateUndoRedoState();
            this.DrawingDocument.OnEndRecalculate();
            this.DrawingDocument.UpdateThumbnailsAttack();
        }
    },

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3757 3758 3759 3760
    changeLayout: function(_array, MasterLayouts, layout_index)
    {
        if(this.Document_Is_SelectionLocked(changestype_Layout) === false)
        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3761
            History.Create_NewPoint();
3762 3763 3764 3765
            if(this.Slides[this.CurPage])
            {
                this.Slides[this.CurPage].graphicObjects.resetSelection();
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3766 3767 3768
            var layout = MasterLayouts.sldLayoutLst[layout_index];
            for(var i = 0; i < _array.length; ++i)
            {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3769
                var slide = this.Slides[_array[i]];
3770
                slide.setLayout(layout);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3771 3772 3773 3774 3775 3776
                for(var j = slide.cSld.spTree.length-1; j  > -1 ; --j)
                {
                    if(slide.cSld.spTree[j].isEmptyPlaceholder && slide.cSld.spTree[j].isEmptyPlaceholder())
                    {
                        slide.removeFromSpTreeById(slide.cSld.spTree[j].Get_Id());
                    }
3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795
                    else
                    {
                        var shape = slide.cSld.spTree[j];
                        if(shape.isPlaceholder() && (!shape.spPr || !shape.spPr.xfrm || !shape.spPr.xfrm.isNotNull()))
                        {
                            var hierarchy = shape.getHierarchy();
                            for(var t = 0; t < hierarchy.length; ++t)
                            {
                                if(hierarchy[t] && hierarchy[t].spPr && hierarchy[t].spPr.xfrm && hierarchy[t].spPr.xfrm.isNotNull())
                                {
                                    break;
                                }
                            }
                            if(t === hierarchy.length)
                            {
                                CheckSpPrXfrm(shape);
                            }
                        }
                    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3796 3797 3798 3799 3800
                }
                for(var j = 0; j < layout.cSld.spTree.length; ++j)
                {
                    if(layout.cSld.spTree[j].isPlaceholder())
                    {
3801 3802
                        var _ph_type = layout.cSld.spTree[j].getPhType();
                        if(_ph_type != phType_dt && _ph_type != phType_ftr && _ph_type != phType_hdr && _ph_type != phType_sldNum)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3803
                        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3804
                            var matching_shape =  slide.getMatchingShape(layout.cSld.spTree[j].getPlaceholderType(), layout.cSld.spTree[j].getPlaceholderIndex(), layout.cSld.spTree[j].getIsSingleBody ? layout.cSld.spTree[j].getIsSingleBody() : false);
3805
                            if(matching_shape == null && layout.cSld.spTree[j])
3806
                            {
3807 3808 3809
                                var sp = layout.cSld.spTree[j].copy();
                                sp.setParent(slide);
                                sp.clearContent && sp.clearContent();
3810 3811
                                slide.addToSpTreeToPos(slide.cSld.spTree.length, sp)
                            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3812 3813 3814
                        }
                    }
                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3815
            }
3816
            this.Recalculate();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3817
            this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3818 3819 3820
        }
    },

3821
    clearThemeTimeouts: function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834
    {
        if(this.startChangeThemeTimeOutId != null)
        {
            clearTimeout(this.startChangeThemeTimeOutId);
        }
        if(this.backChangeThemeTimeOutId != null)
        {
            clearTimeout(this.backChangeThemeTimeOutId);
        }
        if(this.forwardChangeThemeTimeOutId != null)
        {
            clearTimeout(this.forwardChangeThemeTimeOutId);
        }
3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856
    },

    changeTheme : function(themeInfo, arrInd)
    {
        if(this.viewMode === true)
        {
            return;
        }
        var arr_ind, i;
        if(!Array.isArray(arrInd))
        {
            arr_ind = [];
            for(i = 0; i < this.Slides.length; ++i)
            {
                arr_ind.push(i);
            }
        }
        else
        {
            arr_ind = arrInd;
        }
        this.clearThemeTimeouts();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3857

3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868
        for(i = 0; i < this.slideMasters.length; ++i)
        {
            if(this.slideMasters[i] === themeInfo.Master)
            {
                break;
            }
        }
        if(i === this.slideMasters.length)
        {
            this.addSlideMaster(this.slideMasters.length, themeInfo.Master);
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3869 3870 3871 3872
        var _new_master = themeInfo.Master;
        _new_master.presentation = this;
        var _master_width = _new_master.Width;
        var _master_height = _new_master.Height;
3873 3874
        themeInfo.Master.changeSize(this.Width, this.Height);
        for(i = 0; i < themeInfo.Master.sldLayoutLst.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3875
        {
3876
            themeInfo.Master.sldLayoutLst[i].changeSize(this.Width, this.Height);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3877
        }
3878 3879
        var slides_array = [];
        for(i = 0; i < arr_ind.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3880
        {
3881
            slides_array.push(this.Slides[arr_ind[i]]);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3882
        }
3883 3884
        var new_layout;
        for(i = 0; i < slides_array.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3885
        {
3886
            if(slides_array[i].Layout.calculatedType == null)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3887
            {
3888
                slides_array[i].Layout.calculateType();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3889
            }
3890 3891
            new_layout = _new_master.getMatchingLayout(slides_array[i].Layout.type, slides_array[i].Layout.matchingName, slides_array[i].Layout.cSld.name, true);
            if(!isRealObject(new_layout))
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3892
            {
3893
                new_layout = _new_master.sldLayoutLst[0];
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3894
            }
3895 3896
            slides_array[i].setLayout(new_layout);
            slides_array[i].checkNoTransformPlaceholder();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3897
        }
3898
        History.Add(this, {Type: historyitem_Presentation_ChangeTheme, arrIndex: arr_ind});
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3899
        this.resetStateCurSlide();
3900 3901
        this.Recalculate();
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3902 3903
    },

3904
    changeSlideSizeFunction: function(width, height)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3905
    {
3906
        ExecuteNoHistory(function()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3907 3908 3909
        {
            for(var i = 0; i < this.slideMasters.length; ++i)
            {
3910
                this.slideMasters[i].changeSize(width, height);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3911 3912 3913
                var master = this.slideMasters[i];
                for(var j = 0; j < master.sldLayoutLst.length; ++j)
                {
3914
                    master.sldLayoutLst[j].changeSize(width, height);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3915
                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3916 3917 3918
            }
            for(var i = 0; i < this.Slides.length; ++i)
            {
3919
                this.Slides[i].changeSize(width, height);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3920
            }
3921 3922
        }, this, []);
    },
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3923

3924 3925 3926 3927 3928 3929 3930 3931
    changeSlideSize: function(width, height)
    {
        if(this.Document_Is_SelectionLocked(changestype_SlideSize) === false)
        {
            History.Create_NewPoint();
            History.Add(this, {Type: historyitem_Presentation_SlideSize, oldW: this.Width, newW: width, oldH: this.Height, newH:  height});
            this.Width = width;
            this.Height = height;
3932
            this.changeSlideSizeFunction(this.Width, this.Height);
3933
            this.Recalculate();
3934
            this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3935
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953
    },

    changeColorScheme: function(colorScheme)
    {
        if(this.viewMode === true)
        {
            return;
        }

        if(!(this.Document_Is_SelectionLocked(changestype_Theme) === false))
            return;

        if(!(colorScheme instanceof ClrScheme))
        {
            return;
        }
        History.Create_NewPoint();

3954 3955
        var arrInd = [];
        for(var i = 0; i < this.Slides.length; ++i)
3956
        {
3957
            if(!this.Slides[i].Layout.Master.Theme.themeElements.clrScheme.isIdentical(colorScheme))
3958
            {
3959
                this.Slides[i].Layout.Master.Theme.changeColorScheme(colorScheme.createDuplicate());
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3960
            }
3961
            arrInd.push(i);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3962
        }
3963 3964
        History.Add(this, {Type: historyitem_Presentation_ChangeColorScheme, arrIndex: arrInd});
        this.Recalculate();
3965
        this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3966 3967
    },

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3968 3969 3970 3971 3972

    removeSlide: function(pos)
    {
        if(isRealNumber(pos) && pos > -1 && pos < this.Slides.length)
        {
3973
            History.Add(this, {Type: historyitem_Presentation_RemoveSlide, Pos: pos, Id: this.Slides[pos].Get_Id()});
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3974 3975 3976 3977 3978 3979 3980
            return this.Slides.splice(pos, 1)[0];
        }
        return null;
    },

    insertSlide: function(pos, slide)
    {
3981
        History.Add(this, {Type: historyitem_Presentation_AddSlide, Pos: pos, Id: slide.Get_Id()});
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
3982 3983
        this.Slides.splice(pos, 0, slide);
    },
3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001
	
	moveSlides: function(slidesIndexes, pos)
	{
		var insert_pos = pos;
		var removed_slides = [];
		for(var i = slidesIndexes.length - 1; i > -1; --i)
		{
			removed_slides.push(this.removeSlide(slidesIndexes[i]));
			if(slidesIndexes[i] < pos)
			{
				--insert_pos;
			}
		}
		removed_slides.reverse();
		for(i = 0; i < removed_slides.length; ++i)
		{
			this.insertSlide(insert_pos + i, removed_slides[i]);
		}
4002 4003
        this.Recalculate();
        this.DrawingDocument.UpdateThumbnailsAttack();
4004
	},
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4005 4006 4007 4008 4009 4010 4011 4012
//-----------------------------------------------------------------------------------
// Функции для работы с совместным редактирования
//-----------------------------------------------------------------------------------

    Document_Is_SelectionLocked : function(CheckType, AdditionalData)
    {
        if ( true === CollaborativeEditing.Get_GlobalLock() )
            return true;
4013 4014
        if(this.Slides.length === 0)
            return false;
4015 4016 4017 4018
        if(changestype_Document_SectPr === CheckType)
        {
            return true;
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4019

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4020 4021 4022 4023 4024 4025
        if(CheckType === changestype_None && isRealObject(AdditionalData) && AdditionalData.CheckType === changestype_Table_Properties)
        {
            CheckType = changestype_Drawing_Props;
        }


Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4026
        var cur_slide = this.Slides[this.CurPage];
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4027
        var slide_id = cur_slide.deleteLock.Get_Id();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4028 4029 4030 4031 4032 4033


        CollaborativeEditing.OnStart_CheckLock();

        if(CheckType === changestype_Drawing_Props)
        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4034
            if(cur_slide.deleteLock.Lock.Type !== locktype_Mine && cur_slide.deleteLock.Lock.Type !== locktype_None)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4035
                return true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049
            var selected_objects = cur_slide.graphicObjects.selectedObjects;
            for(var i = 0; i < selected_objects.length; ++i)
            {
                var check_obj =
                {
                    "type": c_oAscLockTypeElemPresentation.Object,
                    "slideId": slide_id,
                    "objId": selected_objects[i].Get_Id(),
                    "guid": selected_objects[i].Get_Id()
                };
                selected_objects[i].Lock.Check(check_obj);
            }
        }

4050
        if(CheckType === changestype_AddShape || CheckType === changestype_AddComment)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062
        {
            if(cur_slide.deleteLock.Lock.Type !== locktype_Mine && cur_slide.deleteLock.Lock.Type !== locktype_None)
                return true;
            var check_obj =
            {
                "type": c_oAscLockTypeElemPresentation.Object,
                "slideId": slide_id,
                "objId": AdditionalData.Get_Id(),
                "guid": AdditionalData.Get_Id()
            };
            AdditionalData.Lock.Check(check_obj);
        }
4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078
        if(CheckType === changestype_AddShapes)
        {
            if(cur_slide.deleteLock.Lock.Type !== locktype_Mine && cur_slide.deleteLock.Lock.Type !== locktype_None)
                return true;
            for(var i = 0; i < AdditionalData.length; ++i)
            {
                var check_obj =
                {
                    "type": c_oAscLockTypeElemPresentation.Object,
                    "slideId": slide_id,
                    "objId": AdditionalData[i].Get_Id(),
                    "guid": AdditionalData[i].Get_Id()
                };
                AdditionalData[i].Lock.Check(check_obj);
            }
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4079

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4080 4081
        if(CheckType === changestype_MoveComment)
        {
4082 4083
            var comment = g_oTableId.Get_ById(AdditionalData);
            if(isRealObject(comment))
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4084
            {
4085 4086 4087
                var slides = this.Slides;
                var check_slide = null;
                for(var i = 0; i < slides.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4088
                {
4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122
                    if(slides[i].slideComments)
                    {
                        var comments = slides[i].slideComments.comments;
                        for(var j = 0; j < comments.length; ++j)
                        {
                            if(comments[j] === comment)
                            {
                                check_slide = slides[i];
                                break;
                            }
                        }
                        if(j < comments.length)
                        {
                            break;
                        }
                    }
                }
                if(isRealObject(check_slide))
                {
                    if(check_slide.deleteLock.Lock.Type !== locktype_Mine && check_slide.deleteLock.Lock.Type !== locktype_None)
                        return true;
                    var check_obj =
                    {
                        "type": c_oAscLockTypeElemPresentation.Object,
                        "slideId": slide_id,
                        "objId": comment.Get_Id(),
                        "guid": comment.Get_Id()
                    };
                    comment.Lock.Check(check_obj);
                }
                else
                {
                    return true;
                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4123
            }
4124 4125 4126 4127 4128 4129
            else
            {
                return true;
            }


Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4130 4131
        }

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146
        if(CheckType === changestype_SlideBg)
        {
            var selected_slides = editor.WordControl.Thumbnails.GetSelectedArray();
            for(var i = 0; i < selected_slides.length; ++i)
            {
                var check_obj =
                {
                    "type": c_oAscLockTypeElemPresentation.Slide,
                    "val": this.Slides[selected_slides[i]].backgroundLock.Get_Id(),
                    "guid": this.Slides[selected_slides[i]].backgroundLock.Get_Id()
                };
                this.Slides[selected_slides[i]].backgroundLock.Lock.Check(check_obj);
            }
        }

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161
        if(CheckType === changestype_SlideTiming)
        {
            var selected_slides = editor.WordControl.Thumbnails.GetSelectedArray();
            for(var i = 0; i < selected_slides.length; ++i)
            {
                var check_obj =
                {
                    "type": c_oAscLockTypeElemPresentation.Slide,
                    "val": this.Slides[selected_slides[i]].timingLock.Get_Id(),
                    "guid": this.Slides[selected_slides[i]].timingLock.Get_Id()
                };
                this.Slides[selected_slides[i]].timingLock.Lock.Check(check_obj);
            }
        }

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4162 4163
        if(CheckType === changestype_Text_Props)
        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4164
            if(cur_slide.deleteLock.Lock.Type !== locktype_Mine && cur_slide.deleteLock.Lock.Type !== locktype_None)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4165
                return true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4166 4167 4168
            var selected_objects = cur_slide.graphicObjects.selectedObjects;
            for(var i = 0; i < selected_objects.length; ++i)
            {
4169
                var check_obj =
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4170
                {
4171 4172 4173 4174 4175 4176
                    "type": c_oAscLockTypeElemPresentation.Object,
                    "slideId": slide_id,
                    "objId": selected_objects[i].Get_Id(),
                    "guid":selected_objects[i].Get_Id()
                };
                selected_objects[i].Lock.Check(check_obj);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4177 4178 4179 4180 4181 4182 4183
            }
        }

        if(CheckType === changestype_RemoveSlide)
        {
            var selected_slides = editor.WordControl.Thumbnails.GetSelectedArray();
            for(var i = 0; i < selected_slides.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4184 4185 4186 4187 4188
            {
                if(this.Slides[selected_slides[i]].isLockedObject())
                    return true;
            }
            for(var i = 0; i < selected_slides.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4189 4190 4191 4192
            {
                var check_obj =
                {
                    "type": c_oAscLockTypeElemPresentation.Slide,
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4193 4194
                    "val": this.Slides[selected_slides[i]].deleteLock.Get_Id(),
                    "guid": this.Slides[selected_slides[i]].deleteLock.Get_Id()
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4195
                };
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4196
                this.Slides[selected_slides[i]].deleteLock.Lock.Check(check_obj);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4197 4198
            }
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210

        if(CheckType === changestype_Theme)
        {
            var check_obj =
            {
                "type": c_oAscLockTypeElemPresentation.Slide,
                "val": this.themeLock.Get_Id(),
                "guid": this.themeLock.Get_Id()
            };
            this.themeLock.Lock.Check(check_obj);
        }

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224
        if(CheckType === changestype_Layout)
        {
            var selected_slides = editor.WordControl.Thumbnails.GetSelectedArray();
            for(var i = 0; i < selected_slides.length; ++i)
            {
                var check_obj =
                {
                    "type": c_oAscLockTypeElemPresentation.Slide,
                    "val": this.Slides[selected_slides[i]].layoutLock.Get_Id(),
                    "guid": this.Slides[selected_slides[i]].layoutLock.Get_Id()
                };
                this.Slides[selected_slides[i]].layoutLock.Lock.Check(check_obj);
            }
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246
        if(CheckType === changestype_ColorScheme)
        {
            var check_obj =
            {
                "type": c_oAscLockTypeElemPresentation.Slide,
                "val": this.schemeLock.Get_Id(),
                "guid": this.schemeLock.Get_Id()
            };
            this.schemeLock.Lock.Check(check_obj);
        }

        if(CheckType === changestype_SlideSize)
        {
            var check_obj =
            {
                "type": c_oAscLockTypeElemPresentation.Slide,
                "val": this.slideSizeLock.Get_Id(),
                "guid": this.slideSizeLock.Get_Id()
            };
            this.slideSizeLock.Lock.Check(check_obj);
        }

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257
        var bResult = CollaborativeEditing.OnEnd_CheckLock();

        if ( true === bResult )
        {
            this.Document_UpdateSelectionState();
            this.Document_UpdateInterfaceState();
        }

        return bResult;
    },

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4258

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270
    Save_Changes : function(Data, Writer)
    {
        Writer.WriteLong( historyitem_type_Document );

        var Type = Data.Type;

        // Пишем тип
        Writer.WriteLong( Type );


        switch ( Type )
        {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4271 4272 4273 4274 4275 4276 4277 4278
            case historyitem_Document_DefaultTab:
            {
                // Double : Default Tab

                Writer.WriteDouble( Data.New );

                break;
            }
4279 4280
            case historyitem_Presentation_RemoveSlide:
            case historyitem_Presentation_AddSlide:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4281
            {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4282 4283
                var Pos = Data.UseArray ? Data.PosArray[0] : Data.Pos;
                Writer.WriteLong(Pos);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4284 4285 4286
                Writer.WriteString2(Data.Id);
                break;
            }
4287
            case historyitem_Presentation_SlideSize:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4288 4289 4290 4291 4292
            {
                Writer.WriteDouble(Data.newW);
                Writer.WriteDouble(Data.newH);
                break;
            }
4293
            case historyitem_Presentation_AddSlideMaster:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4294 4295 4296 4297 4298
            {
                Writer.WriteLong(Data.pos);
                Writer.WriteString2(Data.master.Get_Id());
                break;
            }
4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311

            case historyitem_Presentation_ChangeTheme:
            case historyitem_Presentation_ChangeColorScheme:
            {
                //TODO: массив индексов возможно нужно перезаписать после принятия чужих изменений с изменением порядка слайдов
                Writer.WriteLong(Data.arrIndex.length);
                for(var i = 0; i < Data.arrIndex.length; ++i)
                {
                    Writer.WriteLong(Data.arrIndex[i]);
                }
                break;
            }

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332
        }

        return Writer;
    },


    Load_Changes : function(Reader, Reader2)
    {
        // Сохраняем изменения из тех, которые используются для Undo/Redo в бинарный файл.
        // Long : тип класса
        // Long : тип изменений

        var ClassType = Reader.GetLong();
        if ( historyitem_type_Document != ClassType )
            return;

        var Type = Reader.GetLong();


        switch ( Type )
        {
4333
            case historyitem_Presentation_AddSlide:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4334 4335 4336
            {
                var pos = this.m_oContentChanges.Check( contentchanges_Add, Reader.GetLong());
                var Id = Reader.GetString2();
4337 4338 4339 4340 4341 4342
                var oSlide = g_oTableId.Get_ById(Id);
                if(oSlide)
                {
                    this.Slides.splice(pos, 0, oSlide);
                    CollaborativeEditing.Add_ChangedClass(this);
                }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4343 4344
                break;
            }
4345
            case historyitem_Presentation_RemoveSlide:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4346 4347 4348 4349 4350 4351 4352 4353 4354
            {
                var pos = Reader.GetLong();
                Reader.GetString2();

                var ChangesPos = this.m_oContentChanges.Check( contentchanges_Remove, pos);

                // действие совпало, не делаем его
                if ( false === ChangesPos )
                    break;
4355
                this.slidesToUnlock.push(ChangesPos);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4356 4357 4358
                this.Slides.splice(ChangesPos, 1);
                break;
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4359

4360
            case historyitem_Presentation_SlideSize:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4361 4362 4363 4364 4365 4366 4367
            {
                var w = Reader.GetDouble();
                var h = Reader.GetDouble();
                var kw = w/this.Width;
                var kh = h/this.Height;
                this.Width = w;
                this.Height = h;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4368 4369
                CollaborativeEditing.ScaleX = kw;
                CollaborativeEditing.ScaleY = kh;
4370
                this.changeSlideSizeFunction(this.Width, this.Height);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4371
                editor.asc_fireCallback("asc_onPresentationSize", this.Width, this.Height);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4372 4373
                break;
            }
4374
            case historyitem_Presentation_AddSlideMaster:
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4375 4376 4377 4378
            {
                var pos = Reader.GetLong();
                var id = Reader.GetString2();
                this.slideMasters.splice(pos, 0, g_oTableId.Get_ById(id));
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4379
                this.bGoToPage = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4380
                break;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4381
            }
4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416
            case historyitem_Presentation_ChangeTheme:
            {
                var _len = Reader.GetLong(), index;
                for(var i = 0; i < _len; ++i)
                {
                    index = Reader.GetLong();
                    this.Slides[index] && this.Slides[index].checkSlideTheme();
                }
                break;
            }
            case historyitem_Presentation_ChangeColorScheme:
            {
                var recalculateMaps = this.GetRecalculateMaps(), key;
                for(key in recalculateMaps.masters)
                {
                    if(recalculateMaps.masters.hasOwnProperty(key))
                    {
                        recalculateMaps.masters[key].checkSlideColorScheme();
                    }
                }
                for(key in recalculateMaps.layouts)
                {
                    if(recalculateMaps.layouts.hasOwnProperty(key))
                    {
                        recalculateMaps.layouts[key].checkSlideColorScheme();
                    }
                }
                var _len = Reader.GetLong(), index;
                for(var i = 0; i < _len; ++i)
                {
                    index = Reader.GetLong();
                    this.Slides[index] && this.Slides[index].checkSlideTheme();
                }
                break;
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4417 4418 4419 4420 4421
        }
        return true;
    },


4422 4423
    Clear_CollaborativeMarks: function()
    {},
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4424 4425 4426 4427 4428 4429

//-----------------------------------------------------------------------------------
// Функции для работы с комментариями
//-----------------------------------------------------------------------------------
    Add_Comment : function(CommentData)
    {
4430
        if(this.Slides[this.CurPage])
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4431
        {
4432 4433 4434 4435
            History.Create_NewPoint();
            var Comment = new CComment( this.Comments, CommentData );
            Comment.selected = true;
            var slide = this.Slides[this.CurPage];
4436
            var selected_objects = slide.graphicObjects.selection.groupSelection ? slide.graphicObjects.selection.groupSelection.selectedObjects : slide.graphicObjects.selectedObjects;
4437
            if(selected_objects.length  > 0)
4438
            {
4439 4440
                var last_object = selected_objects[selected_objects.length - 1];
                Comment.setPosition(last_object.x + last_object.extX, last_object.y);
4441
            }
4442 4443 4444 4445 4446 4447 4448 4449 4450 4451
            else
            {
                Comment.setPosition(this.Slides[this.CurPage].commentX, this.Slides[this.CurPage].commentY);
            }
            var Flags = 0;
            var dd = editor.WordControl.m_oDrawingDocument;
            var W = dd.GetCommentWidth(Flags);
            var  H = dd.GetCommentHeight(Flags);
            this.Slides[this.CurPage].commentX += W;
            this.Slides[this.CurPage].commentY += H;
4452

4453 4454 4455 4456 4457 4458 4459 4460 4461 4462
            if(this.Document_Is_SelectionLocked(changestype_AddComment, Comment) === false)
            {
                for(var i = this.Slides[this.CurPage].slideComments.comments.length - 1; i > -1; --i)
                {
                    this.Slides[this.CurPage].slideComments.comments[i].selected = false;
                }
                this.Slides[this.CurPage].addComment(Comment);

                this.DrawingDocument.OnRecalculatePage(this.CurPage, this.Slides[this.CurPage]);
                this.DrawingDocument.OnEndRecalculate();
4463
                this.Document_UpdateInterfaceState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4464 4465 4466 4467 4468

                var Coords = editor.WordControl.m_oDrawingDocument.ConvertCoordsToCursorWR_Comment( Comment.x, Comment.y, this.CurPage);
                editor.sync_AddComment( Comment.Get_Id(), CommentData );
                editor.sync_HideComment();
                editor.sync_ShowComment(Comment.Id, Coords.X, Coords.Y );
4469 4470 4471 4472 4473 4474
                return Comment;
            }
            else
            {
                this.Document_Undo();
            }
4475
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4476 4477 4478 4479
    },

    Change_Comment : function(Id, CommentData)
    {
4480
        if(this.Document_Is_SelectionLocked(changestype_MoveComment, Id) === false)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4481 4482
        {
            History.Create_NewPoint();
4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510
            var comment = g_oTableId.Get_ById(Id);
            if(isRealObject(comment))
            {
                var slides = this.Slides;
                var check_slide = null;
                var slide_num = null;
                for(var i = 0; i < slides.length; ++i)
                {
                    if(slides[i].slideComments)
                    {
                        var comments = slides[i].slideComments.comments;
                        for(var j = 0; j < comments.length; ++j)
                        {
                            if(comments[j] === comment)
                            {
                                check_slide = slides[i];
                                slide_num = i;
                                break;
                            }
                        }
                        if(j < comments.length)
                        {
                            break;
                        }
                    }
                }
                if(isRealObject(check_slide))
                {
4511 4512 4513 4514
                    if(slide_num !== this.CurPage)
                    {
                        this.DrawingDocument.m_oWordControl.GoToPage(slide_num);
                    }
4515
                    this.Slides[this.CurPage].changeComment( Id, CommentData );
4516
                    editor.sync_ChangeCommentData( Id, CommentData );
4517 4518 4519 4520 4521 4522 4523
                    this.Recalculate()
                }
                else
                {
                    return true;
                }
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4524 4525
        }

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4526 4527 4528 4529 4530 4531 4532
    },

    Remove_Comment : function(Id, bSendEvent)
    {
        if ( null === Id )
            return;

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4533
        for(var i = 0; i < this.Slides.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4534
        {
4535
            var comments =   this.Slides[i].slideComments.comments;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4536 4537 4538 4539
            for(var j = 0; j < comments.length; ++j)
            {
                if(comments[j].Id === Id)
                {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4540
                    //this.Set_CurPage(i);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4541 4542 4543
                    this.Slides[i].removeComment(Id);
                    if ( true === bSendEvent )
                        editor.sync_RemoveComment( Id );
4544 4545 4546 4547 4548
                    this.Recalculate();
                    if(this.CurPage !== i)
                    {
                        this.DrawingDocument.m_oWordControl.GoToPage(i);
                    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4549 4550 4551
                    return;
                }
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4552
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4553
        editor.sync_HideComment();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4554 4555 4556 4557
    },

    CanAdd_Comment : function()
    {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4558
        return true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4559 4560 4561 4562 4563 4564 4565 4566 4567 4568
    },

    Select_Comment : function(Id)
    {

    },

    Show_Comment : function(Id)
    {

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4569
        for(var i = 0; i < this.Slides.length; ++i)
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4570
        {
4571
            var comments =   this.Slides[i].slideComments.comments;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4572 4573 4574 4575
            for(var j = 0; j < comments.length; ++j)
            {
                if(comments[j].Id === Id)
                {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4576
                    //this.Set_CurPage(i);
4577 4578 4579 4580
                    if(this.CurPage !== i)
                    {
                        this.DrawingDocument.m_oWordControl.GoToPage(i);
                    }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4581

Oleg.Korshul's avatar
Oleg.Korshul committed
4582
                    var Coords = this.DrawingDocument.ConvertCoordsToCursorWR_Comment(comments[j].x, comments[j].y, i);
4583
                    this.Slides[i].showComment(Id, Coords.X, Coords.Y);
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4584 4585 4586
                    return;
                }
            }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4587
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4588
        editor.sync_HideComment();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4589 4590 4591 4592 4593 4594 4595 4596
    },

    Show_Comments : function()
    {
    },

    Hide_Comments : function()
    {
4597
        //this.Slides[this.CurPage].graphicObjects.hideComment();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4598 4599 4600 4601 4602 4603
    },
//-----------------------------------------------------------------------------------
// Функции для работы с textbox
//-----------------------------------------------------------------------------------
    TextBox_Put : function(sText)
    {
4604 4605 4606
        // Отключаем пересчет, включим перед последним добавлением. Поскольку,
        // у нас все добавляется в 1 параграф, так можно делать.
        this.TurnOffRecalc = true;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4607

4608 4609 4610 4611 4612
        var Count = sText.length;
        for ( var Index = 0; Index < Count; Index++ )
        {
            if ( Index === Count - 1 )
                this.TurnOffRecalc = false;
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4613

4614 4615 4616 4617 4618
            var _char = sText.charAt(Index);
            if (" " == _char)
                this.Paragraph_Add( new ParaSpace(1) );
            else
                this.Paragraph_Add( new ParaText(_char) );
4619

4620
        // На случай, если Count = 0
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4621 4622
            this.TurnOffRecalc = false;
        }
4623
        this.Document_UpdateUndoRedoState();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4624 4625 4626 4627
    },

    StartAddShape: function(preset, _is_apply)
    {
4628
        if(this.Slides[this.CurPage])
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4629
        {
4630
            if(!(_is_apply === false))
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4631
            {
4632 4633 4634 4635 4636 4637 4638 4639 4640
                this.Slides[this.CurPage].graphicObjects.startTrackNewShape(preset);
            }
            else
            {
                //this.Slides[this.CurPage].graphicObjects.clearTrackObjects();
                //this.Slides[this.CurPage].graphicObjects.clearPreTrackObjects();
                //this.Slides[this.CurPage].graphicObjects.resetSelectionState();
                //this.DrawingDocument.m_oWordControl.OnUpdateOverlay();
                editor.sync_EndAddShape();
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4641 4642
            }
        }
Oleg.Korshul's avatar
Oleg.Korshul committed
4643 4644 4645 4646 4647 4648 4649
    },

    CalculateComments : function()
    {
        this.CommentAuthors = {};
        var _AuthorId = 0;
        var _slidesCount = this.Slides.length;
Oleg.Korshul's avatar
Oleg.Korshul committed
4650 4651

        var _uniIdSplitter = ";__teamlab__;";
Oleg.Korshul's avatar
Oleg.Korshul committed
4652 4653 4654 4655
        for (var _sldIdx = 0; _sldIdx < _slidesCount; _sldIdx++)
        {
            this.Slides[_sldIdx].writecomments = [];

4656
            var _comments = this.Slides[_sldIdx].slideComments.comments;
Oleg.Korshul's avatar
Oleg.Korshul committed
4657 4658 4659 4660 4661 4662 4663
            var _commentsCount = _comments.length;

            for (var i = 0; i < _commentsCount; i++)
            {
                var _data = _comments[i].Data;
                var _commId = 0;

Oleg.Korshul's avatar
Oleg.Korshul committed
4664 4665
                var _autID = _data.m_sUserId + _uniIdSplitter + _data.m_sUserName;
                var _author = this.CommentAuthors[_autID];
Oleg.Korshul's avatar
Oleg.Korshul committed
4666 4667
                if (!_author)
                {
Oleg.Korshul's avatar
Oleg.Korshul committed
4668 4669
                    this.CommentAuthors[_autID] = new CCommentAuthor();
                    _author = this.CommentAuthors[_autID];
Oleg.Korshul's avatar
Oleg.Korshul committed
4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688
                    _author.Name = _data.m_sUserName;
                    _author.Calculate();

                    _AuthorId++;
                    _author.Id = _AuthorId;
                }

                _author.LastId++;
                _commId = _author.LastId;

                var _new_data = new CWriteCommentData();
                _new_data.Data = _data;
                _new_data.WriteAuthorId = _author.Id;
                _new_data.WriteCommentId = _commId;
                _new_data.WriteParentAuthorId = 0;
                _new_data.WriteParentCommentId = 0;
                _new_data.x = _comments[i].x;
                _new_data.y = _comments[i].y;

Oleg.Korshul's avatar
Oleg.Korshul committed
4689
                _new_data.Calculate();
Oleg.Korshul's avatar
Oleg.Korshul committed
4690 4691 4692 4693 4694 4695 4696 4697 4698
                this.Slides[_sldIdx].writecomments.push(_new_data);

                var _comments2 = _data.m_aReplies;
                var _commentsCount2 = _comments2.length;

                for (var j = 0; j < _commentsCount2; j++)
                {
                    var _data2 = _comments2[j];

Oleg.Korshul's avatar
Oleg.Korshul committed
4699 4700
                    var _autID2 = _data2.m_sUserId + _uniIdSplitter + _data2.m_sUserName;
                    var _author2 = this.CommentAuthors[_autID2];
Oleg.Korshul's avatar
Oleg.Korshul committed
4701 4702
                    if (!_author2)
                    {
Oleg.Korshul's avatar
Oleg.Korshul committed
4703 4704
                        this.CommentAuthors[_autID2] = new CCommentAuthor();
                        _author2 = this.CommentAuthors[_autID2];
Oleg.Korshul's avatar
Oleg.Korshul committed
4705
                        _author2.Name = _data2.m_sUserName;
4706
                        _author2.Calculate();
Oleg.Korshul's avatar
Oleg.Korshul committed
4707 4708 4709 4710 4711 4712 4713 4714

                        _AuthorId++;
                        _author2.Id = _AuthorId;
                    }

                    _author2.LastId++;

                    var _new_data2 = new CWriteCommentData();
Oleg.Korshul's avatar
Oleg.Korshul committed
4715
                    _new_data2.Data = _data2;
Oleg.Korshul's avatar
Oleg.Korshul committed
4716 4717 4718 4719 4720 4721
                    _new_data2.WriteAuthorId = _author2.Id;
                    _new_data2.WriteCommentId = _author2.LastId;
                    _new_data2.WriteParentAuthorId = _author.Id;
                    _new_data2.WriteParentCommentId = _commId;
                    _new_data2.x = _new_data.x;
                    _new_data2.y = _new_data.y + 136 * (j + 1); // так уж делает микрософт
Oleg.Korshul's avatar
Oleg.Korshul committed
4722
                    _new_data2.Calculate();
Oleg.Korshul's avatar
Oleg.Korshul committed
4723 4724 4725 4726
                    this.Slides[_sldIdx].writecomments.push(_new_data2);
                }
            }
        }
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
4727 4728
    }
};
4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744


function collectSelectedObjects(aSpTree, aCollectArray, bRecursive)
{
    for(var i = 0; i < aSpTree.length; ++i)
    {
        if(aSpTree[i].selected)
        {
            aCollectArray.push(new DrawingCopyObject(aSpTree[i].copy(), aSpTree[i].x, aSpTree[i].y, aSpTree[i].extX, aSpTree[i].extY, aSpTree[i].getBase64Img()));
        }
        if(bRecursive && aSpTree[i].getObjectType() === historyitem_type_GroupShape)
        {
            collectSelectedObjects(aSpTree[i].spTree, aCollectArray, bRecursive);
        }
    }
}