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

3 4 5 6 7 8 9 10 11 12 13 14
/**
 * User: Ilja.Kirillov
 * Date: 13.12.11
 * Time: 14:51
 */

var hdrftr_Header = 0x01;
var hdrftr_Footer = 0x02;

//-----------------------------------------------------------------------------------
// Класс работающий с одним колонтитулом
//-----------------------------------------------------------------------------------
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
15
function CHeaderFooter(Parent, LogicDocument, DrawingDocument, Type)
16 17 18 19 20 21 22 23 24 25 26 27 28
{
    this.Id = g_oIdCounter.Get_NewId();

    this.Parent          = Parent;
    this.DrawingDocument = DrawingDocument;
    this.LogicDocument   = LogicDocument;

    // Содержимое колонтитула

    if ( "undefined" != typeof(LogicDocument) && null != LogicDocument )
    {
        if ( Type === hdrftr_Header )
        {
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
29
            this.Content = new CDocumentContent( this, DrawingDocument, 0, 0, 0, 0, false, true );
30 31 32 33
            this.Content.Content[0].Style_Add( this.Get_Styles().Get_Default_Header() );
        }
        else
        {
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
34
            this.Content = new CDocumentContent( this, DrawingDocument, 0, 0, 0, 0, false, true );
35 36 37 38 39 40 41 42
            this.Content.Content[0].Style_Add( this.Get_Styles().Get_Default_Footer() );
        }
    }

    this.Type = Type;

    this.RecalcInfo =
    {
43 44
        CurPage       : -1, // Текущий выставленный номер страницы
        RecalcObj     : {}, // Постраничные объекты пересчета данного колонтитула
45
        NeedRecalc    : {}, // Объект с ключом - номером страницы, нужно ли пересчитывать данную страницу
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
46
        SectPr        : {}  // Объект с ключом - номером страницы и полем - ссылкой на секцию
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    };

    // Добавляем данный класс в таблицу Id (обязательно в конце конструктора)
    g_oTableId.Add( this, this.Id );
}

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

    Get_Id : function()
    {
        return this.Id;
    },
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
65 66 67 68 69 70 71 72 73 74 75


    Get_Theme: function()
    {
        return this.LogicDocument.Get_Theme();
    },

    Get_ColorMap: function()
    {
        return this.LogicDocument.Get_ColorMap();
    },
76
    
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
77 78 79
    Copy : function()
    {
        var NewHdrFtr = new CHeaderFooter(this.Parent, this.LogicDocument, this.DrawingDocument, this.Type);
80
        NewHdrFtr.Content.Copy2( this.Content );
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
81 82 83
        return NewHdrFtr;
    },
    
84 85
    Set_Page : function(Page_abs)
    {
86
        if (Page_abs !== this.RecalcInfo.CurPage && undefined !== this.LogicDocument.Pages[Page_abs])
87
        {
88 89 90 91 92 93 94
            // Возможна ситуация, когда у нас колонтитул был рассчитан для заданной страницы, но на ней сейчас данный
            // колонтитул не используется. Запрещаем менять у данного колонтитула текущую страницу на заданную.
            var HdrFtrController = this.Parent;
            var HdrFtrPage = this.Parent.Pages[Page_abs];
            if ( undefined === HdrFtrPage || ( this !== HdrFtrPage.Header && this !== HdrFtrPage.Footer ) )
                return;
            
95 96 97 98 99 100 101 102 103
            var RecalcObj = this.RecalcInfo.RecalcObj[Page_abs];
            if ( undefined !== RecalcObj )
            {
                this.RecalcInfo.CurPage = Page_abs;
                this.Content.Load_RecalculateObject( RecalcObj );                
            }            
        }        
    },
    
104
    Is_NeedRecalculate : function(Page_abs)
105
    {
106
        var PageNumInfo = this.LogicDocument.Get_SectionPageNumInfo(Page_abs);
107
        
108
        if ( true === PageNumInfo.Compare( this.RecalcInfo.NeedRecalc[Page_abs] ) && undefined !== this.RecalcInfo.RecalcObj[Page_abs] )
109
            return false;
110
        
111
        return true;
112
    },
113
    
114
    Recalculate : function(Page_abs, SectPr)
115
    {
116 117 118 119 120 121 122 123 124 125 126
        // Логика пересчета колонтитулов следующая:
        // 1. При пересчете страницы каждый раз пересчитывается колонтитул (всмысле заходим в функцию Recalculate,т.е. сюда)
        // 2. Далее мы смотрим, нужно ли вообще пересчитывать данную страницу RecalcInfo.NeedRecalc[Page_abs] если это значение
        //    не false, тогда пересчитывать нужно, а если нет, тогда выходим
        // 3. Если нужно персчитывать, пересчитываем заново и смотрим, изменились ли границы пересчета и позиции плавающих 
        //    картинок, и выставляем RecalcInfo.NeedRecalc[Page_abs] = false.
        
        var bChanges = false;                
        var RecalcObj = this.RecalcInfo.RecalcObj[Page_abs];
        
        var OldSumH    = 0;
127
        var OldBounds  = null;
128
        var OldFlowPos = [];
129 130
            
        if ( undefined === RecalcObj )
131 132 133
            bChanges = true;
        else
        {
134 135 136
            OldSumH   = RecalcObj.Get_SummaryHeight();
            OldBounds = RecalcObj.Get_PageBounds(0);
            RecalcObj.Get_DrawingFlowPos( OldFlowPos );
137
        }
138 139 140 141
        
        // Пересчитаем заново данный колонтитул        
        this.Content.Set_StartPage( Page_abs );
        this.Content.Prepare_RecalculateObject();
142 143 144 145 146

        var CurPage = 0;
        var RecalcResult = recalcresult2_NextPage;
        while ( recalcresult2_End != RecalcResult  )
            RecalcResult = this.Content.Recalculate_Page( CurPage++, true );
147 148
        
        this.RecalcInfo.RecalcObj[Page_abs]  = this.Content.Save_RecalculateObject();
149
        this.RecalcInfo.NeedRecalc[Page_abs] = this.LogicDocument.Get_SectionPageNumInfo(Page_abs);
150
        this.RecalcInfo.SectPr[Page_abs]     = SectPr;
151 152 153 154
        
        // Если у нас до этого был какой-то пересчет, тогда сравним его с текущим.
        // 1. Сравним границы: у верхнего колонтитула смотрим на изменение нижней границы, а нижнего - верхней
        // 2. Сравним положение и размер Flow-объектов
155

156 157 158
        if ( false === bChanges )
        {
            var NewBounds = this.Content.Get_PageBounds( 0 );
159
            if ( ( Math.abs(NewBounds.Bottom - OldBounds.Bottom) > 0.001 && hdrftr_Header === this.Type ) || ( Math.abs(NewBounds.Top - OldBounds.Top) > 0.001 && hdrftr_Footer === this.Type ) )
160 161 162 163 164
                bChanges = true;
        }

        if ( false === bChanges )
        {
165
            var NewFlowPos = [];
166 167 168 169 170 171 172 173
            var AllDrawingObjects = this.Content.Get_AllDrawingObjects();
            var Count = AllDrawingObjects.length;

            for ( var Index = 0; Index < Count; Index++ )
            {
                var Obj = AllDrawingObjects[Index];
                if ( drawing_Anchor === Obj.Get_DrawingType() && true === Obj.Use_TextWrap() )
                {
174
                    var oDistance = Obj.Get_Distance();
175 176
                    var FlowPos =
                    {
177 178 179 180
                        X : Obj.X - oDistance.L,
                        Y : Obj.Y - oDistance.T,
                        W : Obj.Width + oDistance.R,
                        H : Obj.Height + oDistance.B
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
                    };

                    NewFlowPos.push( FlowPos );
                }
            }

            Count = NewFlowPos.length;
            if ( Count != OldFlowPos.length )
                bChanges = true;
            else
            {
                for ( var Index = 0; Index < Count; Index++ )
                {
                    var OldObj = OldFlowPos[Index];
                    var NewObj = NewFlowPos[Index];
                    if ( Math.abs(OldObj.X - NewObj.X) > 0.001 || Math.abs(OldObj.Y - NewObj.Y) > 0.001 || Math.abs(OldObj.H - NewObj.H) > 0.001 || Math.abs(OldObj.W - NewObj.W) > 0.001 )
                    {
                        bChanges = true;
                        break;
                    }
                }
            }
        }

        if ( false === bChanges )
        {
            var NewSumH = this.Content.Get_SummaryHeight();
            if ( Math.abs( OldSumH - NewSumH ) > 0.001 )
                bChanges = true;
        }
211 212 213
        
        // Ежели текущая страница не задана, тогда выставляем ту, которая оказалась пересчитанной первой. В противном
        // случае, выставляем рассчет страницы, которая была до этого.
214
        if ( -1 === this.RecalcInfo.CurPage || false === this.LogicDocument.Get_SectionPageNumInfo(this.RecalcInfo.CurPage).Compare( this.RecalcInfo.NeedRecalc[this.RecalcInfo.CurPage] ) )
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
215
        {
216
            this.RecalcInfo.CurPage = Page_abs;
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
217
            
218
            if ( docpostype_HdrFtr === this.LogicDocument.CurPos.Type )
219 220 221 222 223
            {
                // Обновляем интерфейс, чтобы обновить настройки колонтитула, т.к. мы могли попасть в новую секцию
                this.LogicDocument.Document_UpdateSelectionState();
                this.LogicDocument.Document_UpdateInterfaceState();
            }
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
224
        }
225
        else            
226
        {
227 228
            var RecalcObj = this.RecalcInfo.RecalcObj[this.RecalcInfo.CurPage];
            this.Content.Load_RecalculateObject( RecalcObj );
229
        }
230

231 232
        return bChanges;
    },
233 234
    
    Recalculate2 : function(Page_abs)
235
    {
236 237 238 239 240 241 242
        this.Content.Set_StartPage( Page_abs );
        this.Content.Prepare_RecalculateObject();

        var CurPage = 0;
        var RecalcResult = recalcresult2_NextPage;
        while ( recalcresult2_End != RecalcResult  )
            RecalcResult = this.Content.Recalculate_Page( CurPage++, true );
243 244
    },

245
    Reset_RecalculateCache : function()
246
    {
247
        this.Refresh_RecalcData2();
248
        this.Content.Reset_RecalculateCache();
249 250 251 252 253 254 255 256 257 258 259 260
    },

    Get_Styles : function()
    {
        return this.LogicDocument.Get_Styles();
    },

    Get_TableStyleForPara : function()
    {
        return null;
    },

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
261 262 263 264 265 266
    Get_ShapeStyleForPara: function()
    {
        return null;
    },


267 268 269 270 271
    Get_TextBackGroundColor : function()
    {
        return undefined;
    },

272 273
    Get_PageContentStartPos : function ()
    {
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
274
        return { X : this.Content.X, Y : 0, XLimit : this.Content.XLimit, YLimit : 0 };
275 276
    },

277
    Set_CurrentElement : function(bUpdateStates)
278
    {
279
        var PageIndex = -1;
280

281
        for (var Key in this.Parent.Pages)
282
        {
283
            var PIndex = Key | 0;
284
            if ((this === this.Parent.Pages[PIndex].Header || this === this.Parent.Pages[PIndex].Footer) && (-1 === PageIndex || PageIndex > PIndex))
285 286
                PageIndex = PIndex;
        }
287 288

        this.Parent.CurHdrFtr = this;
289
        this.Parent.WaitMouseDown = true;
290 291 292 293
        this.Parent.CurPage = PageIndex;

        if (-1 === PageIndex)
            this.RecalcInfo.CurPage = -1;
294

295
        var OldDocPosType = this.LogicDocument.CurPos.Type;
296 297
        this.LogicDocument.CurPos.Type = docpostype_HdrFtr;

298
        if (true === bUpdateStates && -1 !== PageIndex)
299
        {
300 301
            this.Set_Page(PageIndex);

302 303 304 305
            this.LogicDocument.Document_UpdateInterfaceState();
            this.LogicDocument.Document_UpdateRulersState();
            this.LogicDocument.Document_UpdateSelectionState();
        }
306

307
        if (docpostype_HdrFtr !== OldDocPosType)
308 309 310 311
        {
            this.DrawingDocument.ClearCachePages();
            this.DrawingDocument.FirePaint();
        }
312 313
    },

Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
314 315 316 317 318 319 320 321
    Is_ThisElementCurrent : function()
    {
        if ( this === this.Parent.CurHdrFtr && docpostype_HdrFtr === this.LogicDocument.CurPos.Type )
            return true;

        return false;
    },

322 323 324 325 326 327 328
    Reset : function(X,Y, XLimit, YLimit)
    {
        this.Content.Reset( X, Y, XLimit, YLimit );
    },

    Draw : function(nPageIndex, pGraphics)
    {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
329 330 331
        //var OldPage = this.RecalcInfo.CurPage;
        //
        //this.Set_Page( nPageIndex );
332
        this.Content.Draw( nPageIndex, pGraphics );
333
        
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
334 335
        //if ( -1 !== OldPage )
        //    this.Set_Page( OldPage );
336 337 338 339 340
    },

    // Пришло сообщение о том, что контент изменился и пересчитался
    OnContentRecalculate : function(bChange, bForceRecalc)
    {
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
341
        return;
342 343 344 345 346 347 348 349 350 351
    },

    OnContentReDraw : function(StartPage, EndPage)
    {
        this.DrawingDocument.ClearCachePages();
        this.DrawingDocument.FirePaint();
    },

    RecalculateCurPos : function()
    {
352
        if ( -1 !== this.RecalcInfo.CurPage )
353 354 355
            return this.Content.RecalculateCurPos();

        return null;
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
    },

    Get_NearestPos : function(X, Y, bAnchor, Drawing)
    {
        return this.Content.Get_NearestPos( this.Content.StartPage, X, Y, bAnchor, Drawing );
    },

    Get_Numbering : function()
    {
        return this.LogicDocument.Get_Numbering();
    },

    Get_Bounds : function()
    {
        return this.Content.Get_PageBounds(0);
    },
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
    
    Get_DividingLine : function(PageIndex)
    {
        var OldPage = this.RecalcInfo.CurPage;
        
        this.Set_Page( PageIndex );
        var Bounds = this.Get_Bounds();
        
        if ( -1 !== OldPage )
            this.Set_Page( OldPage );
        
        if ( hdrftr_Footer === this.Type )
            return Bounds.Top;
        else
            return Bounds.Bottom;
    },
388 389 390 391 392 393

    Is_PointInDrawingObjects : function(X, Y)
    {
        return this.Content.Is_PointInDrawingObjects( X, Y, this.Content.Get_StartPage_Absolute() );
    },

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
394
    CheckRange : function(X0, Y0, X1, Y1, _Y0, _Y1, X_lf, X_rf, bMathWrap)
395
    {
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
396
        return this.Content.CheckRange( X0, Y0, X1, Y1, _Y0, _Y1, X_lf, X_rf, 0, false, bMathWrap );
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
    },

    AddPageNum : function(Align)
    {
        var StyleId = null;
        if ( this.Type === hdrftr_Header )
            StyleId = this.Get_Styles().Get_Default_Header();
        else
            StyleId = this.Get_Styles().Get_Default_Footer();

        this.Content.HdrFtr_AddPageNum( Align, StyleId );
    },

    Is_Cell : function()
    {
        return false;
    },

415 416 417 418 419
    Check_AutoFit : function()
    {
        return false;
    },

420 421 422 423 424 425 426 427
    Is_HdrFtr : function(bReturnHdrFtr)
    {
        if ( true === bReturnHdrFtr )
            return this;

        return true;
    },

428
    Is_DrawingShape : function(bRetShape)
429
    {
430 431 432 433
        if(bRetShape === true)
        {
            return null;
        }
434 435 436 437 438 439 440 441 442 443 444
        return false;
    },

    Is_TopDocument : function(bReturnTopDocument)
    {
        if ( true === bReturnTopDocument )
            return this.Content;

        return true;
    },

445 446 447 448 449 450 451 452
    Is_InTable : function(bReturnTopTable)
    {
        if ( true === bReturnTopTable )
            return null;

        return false;
    },

453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
    Is_SelectionUse : function()
    {
        return this.Content.Is_SelectionUse();
    },

    Is_TextSelectionUse : function()
    {
        return this.Content.Is_TextSelectionUse();
    },

    Is_UseInDocument : function(Id)
    {
        if ( null != this.Parent )
            return this.Parent.Is_UseInDocument(this.Get_Id());

        return false;
    },

    Check_Page : function(PageIndex)
    {
        return this.Parent.Check_Page( this, PageIndex );
    },

    Get_CurPosXY : function()
    {
        return this.Content.Get_CurPosXY();
    },

    Get_SelectedText : function(bClearText)
    {
        return this.Content.Get_SelectedText(bClearText);
    },

    Get_SelectedElementsInfo : function(Info)
    {
        this.Content.Get_SelectedElementsInfo(Info);
    },

491 492 493 494 495
    Get_SelectedContent : function(SelectedContent)
    {
        this.Content.Get_SelectedContent( SelectedContent );
    },

496 497 498 499 500 501 502 503 504 505
    Update_CursorType : function(X, Y, PageNum_Abs)
    {
        if ( PageNum_Abs != this.Content.Get_StartPage_Absolute() )
            this.DrawingDocument.SetCursorType( "default", new CMouseMoveData() );
        else
            return this.Content.Update_CursorType( X, Y, PageNum_Abs );
    },

    Is_TableBorder : function(X, Y, PageNum_Abs)
    {
506
        this.Set_Page( PageNum_Abs );
507 508 509 510 511
        return this.Content.Is_TableBorder( X, Y, PageNum_Abs );
    },

    Is_InText : function(X, Y, PageNum_Abs)
    {
512
        this.Set_Page( PageNum_Abs );
513 514 515 516 517
        return this.Content.Is_InText( X, Y, PageNum_Abs );
    },

    Is_InDrawing : function(X, Y, PageNum_Abs)
    {
518
        this.Set_Page( PageNum_Abs );
519 520 521 522 523 524 525 526 527 528
        return this.Content.Is_InDrawing( X, Y, PageNum_Abs );
    },

    Document_UpdateInterfaceState : function()
    {
        this.Content.Document_UpdateInterfaceState();
    },

    Document_UpdateRulersState : function()
    {
529 530 531 532 533 534 535
        if ( -1 === this.RecalcInfo.CurPage )
            return;
        
        var Index  = this.LogicDocument.Pages[this.RecalcInfo.CurPage].Pos; 
        var SectPr = this.LogicDocument.SectionsInfo.Get_SectPr(Index).SectPr;
        var Bounds = this.Get_Bounds();
        
536 537
        // нужно обновить линейку
        if ( this.Type === hdrftr_Header )
538
        {
539
            this.DrawingDocument.Set_RulerState_HdrFtr( true, Bounds.Top, Math.max( Bounds.Bottom, SectPr.Get_PageMargin_Top() ) );
540
        }
541 542
        else
        {
543
            this.DrawingDocument.Set_RulerState_HdrFtr( false, Bounds.Top, SectPr.Get_PageHeight() );
544 545 546 547 548 549 550
        }

        this.Content.Document_UpdateRulersState( this.Content.Get_StartPage_Absolute() );
    },

    Document_UpdateSelectionState : function()
    {
551 552 553 554 555 556 557
        if (-1 === this.RecalcInfo.CurPage)
        {
            this.DrawingDocument.TargetEnd();
            this.DrawingDocument.SelectEnabled(false);
            return;
        }

558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
        if ( docpostype_DrawingObjects == this.Content.CurPos.Type )
        {
            return this.LogicDocument.DrawingObjects.documentUpdateSelectionState();
        }
        else //if ( docpostype_Content === this.Content.CurPos.Type )
        {
            // Если у нас есть выделение, тогда убираем курсор и рисуем выделение.
            // Если никакого выделения нет, тогда убираем его и восстанавливаем курсор.
            if ( true === this.Content.Is_SelectionUse() )
            {
                // Выделение нумерации
                if ( selectionflag_Numbering == this.Content.Selection.Flag )
                {
                    this.DrawingDocument.TargetEnd();
                    this.DrawingDocument.SelectEnabled(true);
                    this.DrawingDocument.SelectClear();
                    this.DrawingDocument.SelectShow();
                }
                // Обрабатываем движение границы у таблиц
                else if ( null != this.Content.Selection.Data && true === this.Content.Selection.Data.TableBorder && type_Table == this.Content.Content[this.Content.Selection.Data.Pos].GetType() )
                {
                    // Убираем курсор, если он был
                    this.DrawingDocument.TargetEnd();
                }
                else
                {
                    if ( false === this.Content.Selection_IsEmpty() )
                    {
                        this.DrawingDocument.TargetEnd();
                        this.DrawingDocument.SelectEnabled(true);
                        this.DrawingDocument.SelectClear();
                        this.DrawingDocument.SelectShow();
                    }
                    else
                    {
                        this.DrawingDocument.SelectEnabled(false);
                        this.RecalculateCurPos();

                        this.DrawingDocument.TargetStart();
                        this.DrawingDocument.TargetShow();
                    }
                }
            }
            else
            {
                this.DrawingDocument.SelectEnabled(false);
                this.RecalculateCurPos();

                this.DrawingDocument.TargetStart();
                this.DrawingDocument.TargetShow();
            }
        }
    },

//-----------------------------------------------------------------------------------
// Функции для работы с контентом
//-----------------------------------------------------------------------------------
    Add_NewParagraph : function()
    {
        this.Content.Add_NewParagraph();
    },

    Add_InlineImage : function(W, H, Img, Chart, bFlow)
    {
        this.Content.Add_InlineImage(W,H,Img, Chart, bFlow);
    },

625 626 627 628 629
    Add_TextArt : function(nStyle)
    {
        this.Content.Add_TextArt(nStyle);
    },

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
    Edit_Chart : function(Chart)
    {
        this.Content.Edit_Chart( Chart );
    },

    Add_InlineTable : function(Cols, Rows)
    {
        this.Content.Add_InlineTable( Cols, Rows );
    },

    Paragraph_Add : function( ParaItem, bRecalculate )
    {
        this.Content.Paragraph_Add( ParaItem, bRecalculate );
    },

    Paragraph_ClearFormatting : function()
    {
        this.Content.Paragraph_ClearFormatting();
    },

    Paragraph_Format_Paste : function(TextPr, ParaPr, ApplyPara)
    {
        this.Content.Paragraph_Format_Paste( TextPr, ParaPr, ApplyPara );
    },

655
    Remove : function(Count, bOnlyText, bRemoveOnlySelection, bOnTextAdd)
656
    {
657
        this.Content.Remove(Count, bOnlyText, bRemoveOnlySelection, bOnTextAdd);
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
    },

    Cursor_GetPos : function()
    {
        return this.Content.Cursor_GetPos();
    },

    Cursor_MoveLeft : function(AddToSelect, Word)
    {
        var bRetValue = this.Content.Cursor_MoveLeft( AddToSelect, Word );

        this.Document_UpdateInterfaceState();
        this.Document_UpdateRulersState();

        return bRetValue;
    },

    Cursor_MoveRight : function(AddToSelect, Word)
    {
        var bRetValue = this.Content.Cursor_MoveRight( AddToSelect, Word );

        this.Document_UpdateInterfaceState();
        this.Document_UpdateRulersState();

        return bRetValue;
    },

    Cursor_MoveUp : function(AddToSelect)
    {
        var bRetValue = this.Content.Cursor_MoveUp( AddToSelect );

        this.Document_UpdateInterfaceState();
        this.Document_UpdateRulersState();

        return bRetValue;
    },

    Cursor_MoveDown : function(AddToSelect)
    {
        var bRetValue = this.Content.Cursor_MoveDown( AddToSelect );

        this.Document_UpdateInterfaceState();
        this.Document_UpdateRulersState();

        return bRetValue;
    },

    Cursor_MoveEndOfLine : function(AddToSelect)
    {
        var bRetValue = this.Content.Cursor_MoveEndOfLine( AddToSelect );

        this.Document_UpdateInterfaceState();
        this.Document_UpdateRulersState();

        return bRetValue;
    },

    Cursor_MoveStartOfLine : function(AddToSelect)
    {
        var bRetValue = this.Content.Cursor_MoveStartOfLine( AddToSelect );

        this.Document_UpdateInterfaceState();
        this.Document_UpdateRulersState();

        return bRetValue;
    },

725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
    Cursor_MoveToStartPos : function(AddToSelect)
    {
        var bRetValue = this.Content.Cursor_MoveToStartPos( AddToSelect );

        this.Document_UpdateInterfaceState();
        this.Document_UpdateRulersState();

        return bRetValue;
    },

    Cursor_MoveToEndPos : function(AddToSelect)
    {
        var bRetValue = this.Content.Cursor_MoveToEndPos( AddToSelect );

        this.Document_UpdateInterfaceState();
        this.Document_UpdateRulersState();

        return bRetValue;
    },

745
    Cursor_MoveAt : function(X, Y, PageIndex, AddToSelect, bRemoveOldSelection)
746
    {
747 748
        this.Set_Page(PageIndex);
        return this.Content.Cursor_MoveAt(X, Y, AddToSelect, bRemoveOldSelection, PageIndex);
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
    },

    Cursor_MoveToCell : function(bNext)
    {
        this.Content.Cursor_MoveToCell(bNext);
    },

    Set_ParagraphAlign : function(Align)
    {
        return this.Content.Set_ParagraphAlign( Align );
    },

    Set_ParagraphSpacing : function(Spacing)
    {
        return this.Content.Set_ParagraphSpacing( Spacing );
    },

    Set_ParagraphIndent : function(Ind)
    {
        return this.Content.Set_ParagraphIndent( Ind );
    },

    Set_ParagraphNumbering : function(NumInfo)
    {
        return this.Content.Set_ParagraphNumbering( NumInfo );
    },

    Set_ParagraphShd : function(Shd)
    {
        return this.Content.Set_ParagraphShd( Shd );
    },

    Set_ParagraphStyle : function(Name)
    {
        return this.Content.Set_ParagraphStyle( Name );
    },

    Set_ParagraphTabs : function(Tabs)
    {
        return this.Content.Set_ParagraphTabs( Tabs );
    },

    Set_ParagraphContextualSpacing : function(Value)
    {
        return this.Content.Set_ParagraphContextualSpacing( Value );
    },

    Set_ParagraphPageBreakBefore : function(Value)
    {
        return this.Content.Set_ParagraphPageBreakBefore( Value );
    },

    Set_ParagraphKeepLines : function(Value)
    {
        return this.Content.Set_ParagraphKeepLines( Value );
    },

806 807 808 809 810
    Set_ParagraphKeepNext : function(Value)
    {
        return this.Content.Set_ParagraphKeepNext( Value );
    },

811 812 813 814 815
    Set_ParagraphWidowControl : function(Value)
    {
        return this.Content.Set_ParagraphWidowControl( Value );
    },

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 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860
    Set_ParagraphBorders : function(Value)
    {
        return this.Content.Set_ParagraphBorders( Value );
    },

    Paragraph_IncDecFontSize : function(bIncrease)
    {
        return this.Content.Paragraph_IncDecFontSize(bIncrease);
    },

    Paragraph_IncDecIndent : function(bIncrease)
    {
        return this.Content.Paragraph_IncDecIndent(bIncrease);
    },

    Set_ImageProps : function(Props)
    {
        return this.Content.Set_ImageProps( Props );
    },

    Set_TableProps : function(Props)
    {
        return this.Content.Set_TableProps( Props );
    },

    Get_Paragraph_ParaPr : function()
    {
        return this.Content.Get_Paragraph_ParaPr();
    },

    Get_Paragraph_TextPr : function()
    {
        return this.Content.Get_Paragraph_TextPr();
    },

    Get_Paragraph_TextPr_Copy : function()
    {
        return this.Content.Get_Paragraph_TextPr_Copy();
    },

    Get_Paragraph_ParaPr_Copy : function()
    {
        return this.Content.Get_Paragraph_ParaPr_Copy();
    },

861
    Get_AllParagraphs : function(Props, ParaArray)
862
    {
863
        return this.Content.Get_AllParagraphs(Props, ParaArray);
864 865
    },

866 867 868 869 870
    Get_PrevElementEndInfo : function(CurElement)
    {
        return null;
    },

871
    // Убираем селект
872
    Selection_Remove : function(bNoCheckDrawing)
873
    {
874
        return this.Content.Selection_Remove(bNoCheckDrawing);
875 876 877
    },

    // Рисуем селект
878
    Selection_Draw_Page : function(Page_abs)
879
    {
880
        return this.Content.Selection_Draw_Page(Page_abs, true, true);
881 882 883 884 885 886 887 888 889
    },

    Selection_Clear : function()
    {
        return this.Content.Selection_Clear();
    },

    Selection_SetStart : function(X,Y, PageIndex, MouseEvent)
    {
890
        this.Set_Page( PageIndex );
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908

        if ( true === editor.isStartAddShape )
        {
            this.Content.CurPos.Type = docpostype_DrawingObjects;
            this.Content.Selection.Use   = true;
            this.Content.Selection.Start = true;

            if ( true != this.LogicDocument.DrawingObjects.isPolylineAddition() )
                this.LogicDocument.DrawingObjects.startAddShape( editor.addShapePreset );

            this.LogicDocument.DrawingObjects.OnMouseDown(MouseEvent, X, Y, PageIndex);
        }
        else
            return this.Content.Selection_SetStart( X, Y, PageIndex, MouseEvent );
    },

    Selection_SetEnd : function(X, Y, PageIndex, MouseEvent)
    {
909
        this.Set_Page( PageIndex );
910 911 912
        return this.Content.Selection_SetEnd(X, Y, PageIndex, MouseEvent);
    },

913 914 915 916 917
    Selection_Is_TableBorderMove : function()
    {
        return this.Content.Selection_Is_TableBorderMove();
    },

918
    Selection_Check : function(X, Y, Page_Abs, NearPos)
919
    {
920 921 922
        if (-1 === this.RecalcInfo.CurPage)
            return false;

923
        var HdrFtrPage = this.Content.Get_StartPage_Absolute();
924
        if ( undefined !== NearPos || HdrFtrPage === Page_Abs )
925
            return this.Content.Selection_Check( X, Y, Page_Abs, NearPos );
926 927 928 929 930 931 932 933 934 935 936 937 938 939

        return false;
    },

    // Селектим весь параграф
    Select_All : function()
    {
        return this.Content.Select_All();
    },

    Get_CurrentParagraph : function()
    {
        return this.Content.Get_CurrentParagraph();
    },
940 941 942 943 944

    Start_SelectionFromCurPos : function()
    {
        this.Content.Start_SelectionFromCurPos();
    },
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
//-----------------------------------------------------------------------------------
// Функции для работы с номерами страниц
//-----------------------------------------------------------------------------------
    Get_StartPage_Absolute : function()
    {
        return 0;
    },

    Get_StartPage_Relative : function()
    {
        return 0;
    },
//-----------------------------------------------------------------------------------
// Функции для работы с таблицами
//-----------------------------------------------------------------------------------
    Table_AddRow : function(bBefore)
    {
        this.Content.Table_AddRow( bBefore );
    },

    Table_AddCol : function(bBefore)
    {
        this.Content.Table_AddCol( bBefore );
    },

    Table_RemoveRow : function()
    {
        this.Content.Table_RemoveRow();
    },

    Table_RemoveCol : function()
    {
        this.Content.Table_RemoveCol();
    },

    Table_MergeCells : function()
    {
        this.Content.Table_MergeCells();
    },

    Table_SplitCell : function( Cols, Rows )
    {
        this.Content.Table_SplitCell( Cols, Rows );
    },

    Table_RemoveTable : function()
    {
        this.Content.Table_RemoveTable();
    },

    Table_Select : function(Type)
    {
        this.Content.Table_Select(Type);
    },

    Table_CheckMerge : function()
    {
        return this.Content.Table_CheckMerge();
    },

    Table_CheckSplit : function()
    {
        return this.Content.Table_CheckSplit();
    },

    Check_TableCoincidence : function(Table)
    {
        return false;
    },
//-----------------------------------------------------------------------------------
// Undo/Redo функции
1016
//-----------------------------------------------------------------------------------    
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
    Get_ParentObject_or_DocumentPos : function()
    {
        return { Type : historyrecalctype_HdrFtr, Data : this };
    },

    Refresh_RecalcData : function(Data)
    {
        this.Refresh_RecalcData2();
    },

    Refresh_RecalcData2 : function()
    {
1029
        // Сохраняем пересчитаные страницы в старый пересчет, а текущий обнуляем
1030
        this.RecalcInfo.NeedRecalc = {};
1031 1032
        this.RecalcInfo.SectPr     = {};
        this.RecalcInfo.CurPage    = -1;
1033
        
1034 1035
        History.RecalcData_Add( { Type : historyrecalctype_HdrFtr, Data : this } );
    },
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
    
    Refresh_RecalcData_BySection : function(SectPr)
    {
        // Найдем среди пересчитанных страниц те, которые пересчитывались в заданной секции,
        // и среди них найдем ключ с наименьшим номером. Далее, отметим все страницы с номером большим, чем найденный,
        // как не пересчитанные.
        
        var MinPageIndex = -1;
        for ( var PageIndex in this.RecalcInfo.NeedRecalc )
        {
            if ( SectPr === this.RecalcInfo.SectPr[PageIndex] && ( -1 === MinPageIndex || PageIndex < MinPageIndex ) )
                MinPageIndex = PageIndex;                
        }
        
        for ( var PageIndex in this.RecalcInfo.NeedRecalc )
        {
            if ( PageIndex >= MinPageIndex )
            {
                delete this.RecalcInfo.NeedRecalc[PageIndex];
                delete this.RecalcInfo.SectPr[PageIndex];                    
            }
        }
    },
1059 1060 1061 1062 1063 1064 1065 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 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
//-----------------------------------------------------------------------------------
// Функции для работы с гиперссылками
//-----------------------------------------------------------------------------------
    Hyperlink_Add : function(HyperProps)
    {
        this.Content.Hyperlink_Add(HyperProps);
    },

    Hyperlink_Modify : function(HyperProps)
    {
        this.Content.Hyperlink_Modify(HyperProps);
    },

    Hyperlink_Remove : function()
    {
        this.Content.Hyperlink_Remove();
    },

    Hyperlink_CanAdd : function(bCheckInHyperlink)
    {
        return this.Content.Hyperlink_CanAdd(bCheckInHyperlink);
    },

    Hyperlink_Check : function(bCheckEnd)
    {
        return this.Content.Hyperlink_Check(bCheckEnd);
    },
//-----------------------------------------------------------------------------------
// Функции для работы с генерацией карты шрифтов
//-----------------------------------------------------------------------------------
    Document_CreateFontMap : function(FontMap)
    {
        this.Content.Document_CreateFontMap(FontMap);
    },

    Document_CrateFontCharMap : function(FontCharMap)
    {
        this.Content.Document_CreateFontCharMap( FontCharMap );
    },

    Document_Get_AllFontNames : function(AllFonts)
    {
        this.Content.Document_Get_AllFontNames(AllFonts);
    },
//-----------------------------------------------------------------------------------
// Функции для работы с совместным редактирования
//-----------------------------------------------------------------------------------
    Write_ToBinary2 : function(Writer)
    {
        Writer.WriteLong( historyitem_type_HdrFtr );

        // String   : Id
        // Long     : Type
        // String   : Content Id

        Writer.WriteString2( this.Id );
        Writer.WriteLong( this.Type );
        Writer.WriteString2( this.Content.Get_Id() );
    },

    Read_FromBinary2 : function(Reader)
    {
        // String   : Id
        // Long     : Type
        // String   : Content Id

        var LogicDocument = editor.WordControl.m_oLogicDocument;

        this.Parent          = LogicDocument.HdrFtr;
        this.DrawingDocument = LogicDocument.DrawingDocument;
        this.LogicDocument   = LogicDocument;

        this.Id      = Reader.GetString2();
        this.Type    = Reader.GetLong();

Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
1134
        this.Content = g_oTableId.Get_ById( Reader.GetString2() );        
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
    },
//-----------------------------------------------------------------------------------
// Функции для работы с комментариями
//-----------------------------------------------------------------------------------
    Add_Comment : function(Comment)
    {
        this.Content.Add_Comment( Comment, true, true );
    },

    CanAdd_Comment : function()
    {
        return this.Content.CanAdd_Comment();
    }
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
};
CHeaderFooter.prototype.Get_SectPr = function()
{
    if (this.LogicDocument)
    {
        var SectionsInfo = this.LogicDocument.SectionsInfo;
        var Index = SectionsInfo.Find_ByHdrFtr(this);
        if (-1 !== Index)
            return SectionsInfo.Get_SectPr2(Index).SectPr;
    }

    return null;
};
1161 1162 1163 1164
CHeaderFooter.prototype.Set_ParagraphFramePr = function(FramePr, bDelete)
{
    return this.Content.Set_ParagraphFramePr(FramePr, bDelete);
};
1165 1166 1167 1168
CHeaderFooter.prototype.Get_RevisionsChangeParagraph = function(SearchEngine)
{
    return this.Content.Get_RevisionsChangeParagraph(SearchEngine);
};
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182

//-----------------------------------------------------------------------------------
// Класс для работы с колонтитулами
//-----------------------------------------------------------------------------------
function CHeaderFooterController(LogicDocument, DrawingDocument)
{
    this.Id = g_oIdCounter.Get_NewId();

    this.DrawingDocument = DrawingDocument;
    this.LogicDocument   = LogicDocument;

    // Текущий колонтитул
    this.CurHdrFtr = null;

1183
    this.Pages   = {};
1184 1185 1186 1187 1188
    this.CurPage = 0;
    this.ChangeCurPageOnEnd = true;

    this.WaitMouseDown = true;

1189
    this.Lock = new CLock();   
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208

    // Добавляем данный класс в таблицу Id (обязательно в конце конструктора)
    g_oTableId.Add( this, this.Id );
}

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

    Get_Id : function()
    {
        return this.Id;
    },
//-----------------------------------------------------------------------------------
// Функции для работы с колонтитулами
1209
//-----------------------------------------------------------------------------------        
1210 1211 1212 1213 1214 1215 1216 1217
    Set_CurHdrFtr : function(HdrFtr)
    {
        if (null !== this.CurHdrFtr)
            this.CurHdrFtr.Selection_Remove();

        this.CurHdrFtr = HdrFtr;
    },

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
    GoTo_NextHdrFtr : function()
    {
        var CurHdrFtr = this.CurHdrFtr;
        if (null === CurHdrFtr || -1 === CurHdrFtr.RecalcInfo.CurPage)
            return;

        var CurPage = CurHdrFtr.RecalcInfo.CurPage;
        var Pages = this.Pages;

        if (hdrftr_Header === CurHdrFtr.Type && undefined !== Pages[CurPage].Footer)
            CurHdrFtr = Pages[CurPage].Footer;
        else
            CurHdrFtr = null;

        while (null === CurHdrFtr)
        {
            CurPage++;

            if (undefined === Pages[CurPage])
                break;
            else if (undefined !== Pages[CurPage].Header && null !== Pages[CurPage].Header)
                CurHdrFtr = Pages[CurPage].Header;
            else if (undefined !== Pages[CurPage].Footer && null !== Pages[CurPage].Footer)
                CurHdrFtr = Pages[CurPage].Footer;
        }

        if (null !== CurHdrFtr)
        {
            this.CurHdrFtr = CurHdrFtr;
            CurHdrFtr.Set_Page(CurPage);
            CurHdrFtr.Content.Cursor_MoveToStartPos(false);

            return true;
        }
        
        return false;
    },
    
    GoTo_PrevHdrFtr : function()
    {
        var CurHdrFtr = this.CurHdrFtr;
        if (null === CurHdrFtr || -1 === CurHdrFtr.RecalcInfo.CurPage)
            return;
        
        var CurPage = CurHdrFtr.RecalcInfo.CurPage;
        var Pages = this.Pages;
        
        if (hdrftr_Footer === CurHdrFtr.Type && undefined !== Pages[CurPage].Header)
            CurHdrFtr = Pages[CurPage].Header;
        else
            CurHdrFtr = null;
        
        while (null === CurHdrFtr)
        {
            CurPage--;
            
            if (undefined === Pages[CurPage])
                return;
            else if (undefined !== Pages[CurPage].Footer && null !== Pages[CurPage].Footer)
                CurHdrFtr = Pages[CurPage].Footer;
            else if (undefined !== Pages[CurPage].Header && null !== Pages[CurPage].Header)
                CurHdrFtr = Pages[CurPage].Header;
        }
        
        if (null !== CurHdrFtr)
        {
            this.CurHdrFtr = CurHdrFtr;
            CurHdrFtr.Set_Page(CurPage);
            CurHdrFtr.Content.Cursor_MoveToStartPos(false);
            
            return true;
        }
        
        return false;
    },
    
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304
    Get_CurPage : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Content.Get_StartPage_Absolute();

        return 0;
    },

    // Получаем своства колонтитула для интерфейса
    Get_Props : function()
    {
1305
        if ( null != this.CurHdrFtr && -1 !== this.CurHdrFtr.RecalcInfo.CurPage )
1306
        {
1307
            var Pr = {};
1308
            Pr.Type = this.CurHdrFtr.Type;
1309 1310 1311 1312 1313
            
            if ( undefined === this.LogicDocument.Pages[this.CurHdrFtr.RecalcInfo.CurPage] )
                return Pr;
            
            var Index  = this.LogicDocument.Pages[this.CurHdrFtr.RecalcInfo.CurPage].Pos;            
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
1314
            var SectPr = this.LogicDocument.SectionsInfo.Get_SectPr(Index).SectPr;
1315 1316

            if ( hdrftr_Footer === Pr.Type )
1317
                Pr.Position = SectPr.Get_PageMargins_Footer();
1318
            else
1319 1320 1321 1322
                Pr.Position = SectPr.Get_PageMargins_Header();
            
            Pr.DifferentFirst   = SectPr.Get_TitlePage();
            Pr.DifferentEvenOdd = EvenAndOddHeaders;
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340
            
            if ( SectPr === this.LogicDocument.SectionsInfo.Get_SectPr2(0).SectPr )
            {
                // У первой секции не может быть повторяющихся колонтитулов. Посылаем особое значение (null) в меню
                Pr.LinkToPrevious = null;
            }
            else
            {
                // Определим тип колонтитула, в котором мы находимся
                var PageIndex = this.CurHdrFtr.RecalcInfo.CurPage;
                var SectionPageInfo = this.LogicDocument.Get_SectionPageNumInfo( PageIndex );

                var bFirst  = ( true === SectionPageInfo.bFirst && true === SectPr.Get_TitlePage() ? true : false );
                var bEven   = ( true === SectionPageInfo.bEven  && true === EvenAndOddHeaders      ? true : false );
                var bHeader = ( hdrftr_Header === this.CurHdrFtr.Type ? true : false );

                Pr.LinkToPrevious = ( null === SectPr.Get_HdrFtr( bHeader, bFirst, bEven ) ? true : false );
            }
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351

            Pr.Locked = this.Lock.Is_Locked();

            return Pr;
        }
        else
            return null;
    },

    Set_CurHdrFtr_ById : function(Id)
    {
1352
        var HdrFtr = g_oTableId.Get_ById( Id );
1353 1354 1355 1356 1357 1358 1359
        if ( -1 === this.LogicDocument.SectionsInfo.Find_ByHdrFtr( HdrFtr ) )
            return false;
        
        this.CurHdrFtr = HdrFtr;
        HdrFtr.Content.Cursor_MoveToStartPos();
              
        return true;
1360 1361 1362
    },
//-----------------------------------------------------------------------------------
//
1363
//-----------------------------------------------------------------------------------   
1364 1365 1366 1367
    RecalculateCurPos : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.RecalculateCurPos();
1368 1369

        return null;
1370 1371
    },

1372 1373 1374 1375
    Recalculate : function(PageIndex)    
    {
        // Определим четность страницы и является ли она первой в данной секции. Заметим, что четность страницы 
        // отсчитывается от начала текущей секции и не зависит от настроек нумерации страниц для данной секции.
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
1376
        var SectionPageInfo = this.LogicDocument.Get_SectionPageNumInfo( PageIndex );
1377
        
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
1378 1379
        var bFirst = SectionPageInfo.bFirst;
        var bEven  = SectionPageInfo.bEven;
1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392
        
        // Запросим нужный нам колонтитул 
        var HdrFtr = this.LogicDocument.Get_SectionHdrFtr( PageIndex, bFirst, bEven );
        
        var Header = HdrFtr.Header;
        var Footer = HdrFtr.Footer;
        var SectPr = HdrFtr.SectPr;

        this.Pages[PageIndex] = new CHdrFtrPage();
        this.Pages[PageIndex].Header = Header;
        this.Pages[PageIndex].Footer = Footer;
        var X, XLimit;
        
1393 1394
        var X      = SectPr.Get_PageMargin_Left();
        var XLimit = SectPr.Get_PageWidth() - SectPr.Get_PageMargin_Right();
1395
        
1396
        var bRecalcHeader = false;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1397 1398

        var HeaderDrawings, HeaderTables, FooterDrawings, FooterTables;
1399 1400
        // Рассчитываем верхний колонтитул
        if ( null !== Header )
1401
        {
1402 1403 1404
            if ( true === Header.Is_NeedRecalculate( PageIndex ) )
            {
                var Y      = SectPr.Get_PageMargins_Header();
1405
                var YLimit = SectPr.Get_PageHeight() / 2;
1406 1407

                Header.Reset( X, Y, XLimit, YLimit );
1408
                bRecalcHeader = Header.Recalculate(PageIndex, SectPr);
1409 1410 1411
            }
            else 
            {
1412
               if ( -1 === Header.RecalcInfo.CurPage )
1413 1414
                    Header.Set_Page(PageIndex);
            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1415
            HeaderDrawings = Header.Content.Get_AllDrawingObjects([]);
1416
            HeaderTables = Header.Content.Get_AllFloatElements();
1417
        }
1418
        
1419 1420
        var bRecalcFooter = false;
        
1421 1422
        // Рассчитываем нижний колонтитул
        if ( null !== Footer )
1423
        {
1424 1425 1426 1427
            if ( true === Footer.Is_NeedRecalculate( PageIndex ) )
            {
                // Нижний колонтитул рассчитываем 2 раза. Сначала, с 0 позиции, чтобы рассчитать суммарную высоту колонитула.
                // Исходя из уже известной высоты располагаем и рассчитываем колонтитул.
1428

1429
                var Y      = 0;
1430
                var YLimit = SectPr.Get_PageHeight();
1431

1432 1433 1434 1435 1436 1437 1438
                Footer.Reset( X, Y, XLimit, YLimit );
                Footer.Recalculate2(PageIndex);

                var SummaryHeight = Footer.Content.Get_SummaryHeight();
                Y = Math.max( 2 * YLimit / 3, YLimit - SectPr.Get_PageMargins_Footer() - SummaryHeight );

                Footer.Reset( X, Y, XLimit, YLimit );
1439
                bRecalcFooter = Footer.Recalculate(PageIndex, SectPr);
1440 1441 1442 1443 1444 1445
            }
            else
            {
                if ( -1 === Footer.RecalcInfo.CurPage )
                    Footer.Set_Page(PageIndex);
            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1446
            FooterDrawings = Footer.Content.Get_AllDrawingObjects([]);
1447
            FooterTables = Footer.Content.Get_AllFloatElements();
1448
        }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1449
        this.LogicDocument.DrawingObjects.mergeDrawings(PageIndex, HeaderDrawings, HeaderTables, FooterDrawings, FooterTables);
1450 1451 1452 1453
        if ( true === bRecalcHeader || true === bRecalcFooter )
            return true;
        
        return false;
1454
    },    
1455

1456 1457 1458
    // Отрисовка колонтитулов на данной странице
    Draw : function(nPageIndex, pGraphics)
    {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1459

1460 1461
        var Header = this.Pages[nPageIndex].Header;
        var Footer = this.Pages[nPageIndex].Footer;
1462

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1463 1464 1465 1466 1467
        var OldPageHdr = Header && Header.RecalcInfo.CurPage;
        var OldPageFtr = Footer && Footer.RecalcInfo.CurPage;

        Header &&  Header.Set_Page(nPageIndex);
        Footer && Footer.Set_Page(nPageIndex);
1468 1469 1470
        this.LogicDocument.DrawingObjects.drawBehindDocHdrFtr( nPageIndex, pGraphics );
        this.LogicDocument.DrawingObjects.drawWrappingObjectsHdrFtr( nPageIndex, pGraphics );

1471 1472
        if ( null !== Header )
            Header.Draw( nPageIndex, pGraphics );
1473

1474 1475
        if ( null !== Footer )
            Footer.Draw( nPageIndex, pGraphics );
1476 1477

        this.LogicDocument.DrawingObjects.drawBeforeObjectsHdrFtr( nPageIndex, pGraphics );
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1478 1479 1480

        Header &&  Header.Set_Page(OldPageHdr);
        Footer && Footer.Set_Page(OldPageFtr);
1481 1482
    },

Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1483
    CheckRange : function(X0, Y0, X1, Y1, _Y0, _Y1, X_lf, X_rf, PageIndex, bMathWrap)
1484
    {
1485 1486 1487
        if (undefined === this.Pages[PageIndex])
            return [];

1488 1489
        var Header = this.Pages[PageIndex].Header;
        var Footer = this.Pages[PageIndex].Footer;              
1490 1491 1492 1493 1494

        var HeaderRange = [];
        var FooterRange = [];

        if ( null != Header )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1495
            HeaderRange = Header.CheckRange( X0, Y0, X1, Y1, _Y0, _Y1, X_lf, X_rf, bMathWrap );
1496 1497

        if ( null != Footer )
Sergey.Luzyanin's avatar
Sergey.Luzyanin committed
1498
            FooterRange = Footer.CheckRange( X0, Y0, X1, Y1, _Y0, _Y1, X_lf, X_rf, bMathWrap );
1499 1500 1501 1502 1503

        return HeaderRange.concat( FooterRange );
    },

    // Запрашиваем низ у верхнего колонтитула для данной страницы
1504
    Get_HdrFtrLines : function(PageIndex)
1505
    {
1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523
        var Header = null;
        var Footer = null;
        
        if ( undefined !== this.Pages[PageIndex] )
        {
            Header = this.Pages[PageIndex].Header;
            Footer = this.Pages[PageIndex].Footer;
        }
        
        var Top = null; 
        if ( null !== Header )
            Top = Header.Get_DividingLine(PageIndex);
        
        var Bottom = null;
        if ( null !== Footer )
            Bottom = Footer.Get_DividingLine(PageIndex);
        
        return { Top : Top, Bottom : Bottom };
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631
    },

    Update_CursorType : function( X, Y, PageNum_Abs )
    {
        if ( true === this.Lock.Is_Locked() )
        {
            var PageLimits = this.LogicDocument.Get_PageContentStartPos( PageNum_Abs );

            var MMData_header = new CMouseMoveData();
            var Coords = this.DrawingDocument.ConvertCoordsToCursorWR( PageLimits.X, PageLimits.Y, PageNum_Abs );
            MMData_header.X_abs            = Coords.X;
            MMData_header.Y_abs            = Coords.Y + 2;
            MMData_header.Type             = c_oAscMouseMoveDataTypes.LockedObject;
            MMData_header.UserId           = this.Lock.Get_UserId();
            MMData_header.HaveChanges      = this.Lock.Have_Changes();
            MMData_header.LockedObjectType = c_oAscMouseMoveLockedObjectType.Header;
            editor.sync_MouseMoveCallback( MMData_header );

            var MMData_footer = new CMouseMoveData();
            Coords = this.DrawingDocument.ConvertCoordsToCursorWR( PageLimits.X, PageLimits.YLimit, PageNum_Abs );
            MMData_footer.X_abs            = Coords.X;
            MMData_footer.Y_abs            = Coords.Y - 2;
            MMData_footer.Type             = c_oAscMouseMoveDataTypes.LockedObject;
            MMData_footer.UserId           = this.Lock.Get_UserId();
            MMData_footer.HaveChanges      = this.Lock.Have_Changes();
            MMData_footer.LockedObjectType = c_oAscMouseMoveLockedObjectType.Footer;
            editor.sync_MouseMoveCallback( MMData_footer );
        }

        // TODO: Сделать выбор в зависимости колонтитула от номера страница PageNum_Abs
        if ( null != this.CurHdrFtr )
        {
            // Если мы попадаем в заселекченную автофигуру, пусть она даже выходит за пределы
            if ( true === this.LogicDocument.DrawingObjects.pointInSelectedObject(X, Y, PageNum_Abs) )
            {
                var NewPos = this.DrawingDocument.ConvertCoordsToAnotherPage(X, Y, PageNum_Abs, this.CurPage);
                var _X = NewPos.X;
                var _Y = NewPos.Y;
                return this.CurHdrFtr.Update_CursorType( _X, _Y, this.CurPage );
            }
            else
                return this.CurHdrFtr.Update_CursorType( X, Y, PageNum_Abs );
        }
    },

    Is_TableBorder : function( X, Y, PageNum_Abs )
    {
        var HdrFtr = this.Internal_GetContentByXY( X, Y, PageNum_Abs );
        if ( null != HdrFtr )
            return HdrFtr.Is_TableBorder( X, Y, PageNum_Abs );

        return null;
    },

    Is_InText : function(X,Y, PageNum_Abs)
    {
        var HdrFtr = this.Internal_GetContentByXY( X, Y, PageNum_Abs );
        if ( null != HdrFtr )
            return HdrFtr.Is_InText( X, Y, PageNum_Abs );

        return null;
    },

    Is_InDrawing : function(X,Y, PageNum_Abs)
    {
        var HdrFtr = this.Internal_GetContentByXY( X, Y, PageNum_Abs );
        if ( null != HdrFtr )
            return HdrFtr.Is_InDrawing( X, Y, PageNum_Abs );

        return null;
    },

    Document_UpdateInterfaceState : function()
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Document_UpdateInterfaceState();
    },

    Document_UpdateRulersState : function(CurPage)
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Document_UpdateRulersState(CurPage);
    },

    Document_UpdateSelectionState : function()
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Document_UpdateSelectionState();
    },

    Is_SelectionUse : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Is_SelectionUse();

        return false;
    },

    Is_TextSelectionUse : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Is_TextSelectionUse();

        return false;
    },

    Is_UseInDocument : function(Id)
    {
1632
        var HdrFtr = g_oTableId.Get_ById( Id );
1633 1634
        if ( -1 === this.LogicDocument.SectionsInfo.Find_ByHdrFtr( HdrFtr ) )
            return false;        
1635

1636
        return true;                
1637 1638 1639 1640
    },

    Check_Page : function(HdrFtr, PageIndex)
    {
1641 1642
        var Header = this.Pages[PageIndex].Header;
        var Footer = this.Pages[PageIndex].Footer;
1643

1644
        if ( HdrFtr === Header || HdrFtr === Footer )
1645
            return true;
1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671

        return false;
    },

    Get_CurPosXY : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Get_CurPosXY();

        return { X : 0, Y : 0 };
    },

    Get_SelectedText : function(bClearText)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Get_SelectedText(bClearText);

        return null;
    },

    Get_SelectedElementsInfo : function(Info)
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Get_SelectedElementsInfo(Info);
    },

1672 1673 1674 1675 1676 1677
    Get_SelectedContent : function(SelectedContent)
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Get_SelectedContent( SelectedContent );
    },

1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692
//-----------------------------------------------------------------------------------
// Функции для работы с контентом
//-----------------------------------------------------------------------------------
    Add_NewParagraph : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Add_NewParagraph();
    },

    Add_InlineImage : function(W, H, Img, Chart, bFlow)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Add_InlineImage(W,H,Img, Chart, bFlow);
    },

1693 1694 1695 1696 1697 1698
    Add_TextArt : function(nStyle)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Add_TextArt(nStyle);
    },

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
    Edit_Chart : function(Chart)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Edit_Chart( Chart );
    },

    Add_InlineTable : function(Cols, Rows)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Add_InlineTable( Cols, Rows );
    },

    Paragraph_Add : function( ParaItem, bRecalculate )
    {
        // PageBreak убираем из колонтитула
        if ( para_NewLine === ParaItem.Type && break_Page === ParaItem.BreakType )
            return;

        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Paragraph_Add( ParaItem, bRecalculate );
    },

    Paragraph_ClearFormatting : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Paragraph_ClearFormatting();
    },

    Paragraph_Format_Paste : function(TextPr, ParaPr, ApplyPara)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Paragraph_Format_Paste( TextPr, ParaPr, ApplyPara );
    },

1733
    Remove : function(Count, bOnlyText, bRemoveOnlySelection, bOnTextAdd)
1734 1735
    {
        if ( null != this.CurHdrFtr )
1736
            return this.CurHdrFtr.Remove(Count, bOnlyText, bRemoveOnlySelection, bOnTextAdd);
1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780
    },

    Cursor_GetPos : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Cursor_GetPos();
    },

    Cursor_MoveLeft : function(AddToSelect, Word)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Cursor_MoveLeft( AddToSelect, Word );
    },

    Cursor_MoveRight : function(AddToSelect, Word)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Cursor_MoveRight( AddToSelect, Word );
    },

    Cursor_MoveUp : function(AddToSelect)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Cursor_MoveUp( AddToSelect );
    },

    Cursor_MoveDown : function(AddToSelect)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Cursor_MoveDown( AddToSelect );
    },

    Cursor_MoveEndOfLine : function(AddToSelect)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Cursor_MoveEndOfLine( AddToSelect );
    },

    Cursor_MoveStartOfLine : function(AddToSelect)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Cursor_MoveStartOfLine( AddToSelect );
    },

1781
    Cursor_MoveAt : function( X, Y, PageIndex, AddToSelect )
1782 1783
    {
        if ( null != this.CurHdrFtr )
1784
            return this.CurHdrFtr.Cursor_MoveAt( X, Y, PageIndex, AddToSelect );
1785 1786
    },

1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798
    Cursor_MoveToStartPos : function(AddToSelect)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Cursor_MoveToStartPos( AddToSelect );
    },

    Cursor_MoveToEndPos : function(AddToSelect)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Cursor_MoveToEndPos( AddToSelect );
    },

1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864
    Cursor_MoveToCell : function(bNext)
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Cursor_MoveToCell(bNext);
    },

    Set_ParagraphAlign : function(Align)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Set_ParagraphAlign( Align );
    },

    Set_ParagraphSpacing : function(Spacing)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Set_ParagraphSpacing( Spacing );
    },

    Set_ParagraphIndent : function(Ind)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Set_ParagraphIndent( Ind );
    },

    Set_ParagraphNumbering : function(NumInfo)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Set_ParagraphNumbering( NumInfo );
    },

    Set_ParagraphShd : function(Shd)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Set_ParagraphShd( Shd );
    },

    Set_ParagraphStyle : function(Name)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Set_ParagraphStyle( Name );
    },

    Set_ParagraphTabs : function(Tabs)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Set_ParagraphTabs( Tabs );
    },

    Set_ParagraphContextualSpacing : function(Value)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Set_ParagraphContextualSpacing( Value );
    },

    Set_ParagraphPageBreakBefore : function(Value)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Set_ParagraphPageBreakBefore( Value );
    },

    Set_ParagraphKeepLines : function(Value)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Set_ParagraphKeepLines( Value );
    },

1865 1866 1867 1868 1869 1870
    Set_ParagraphKeepNext : function(Value)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Set_ParagraphKeepNext( Value );
    },

1871 1872 1873 1874 1875 1876
    Set_ParagraphWidowControl : function(Value)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Set_ParagraphWidowControl( Value );
    },

1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932
    Set_ParagraphBorders : function(Value)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Set_ParagraphBorders( Value );
    },

    Paragraph_IncDecFontSize : function(bIncrease)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Paragraph_IncDecFontSize(bIncrease);
    },

    Paragraph_IncDecIndent : function(bIncrease)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Paragraph_IncDecIndent(bIncrease);
    },

    Set_ImageProps : function(Props)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Set_ImageProps( Props );
    },

    Set_TableProps : function(Props)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Set_TableProps( Props );
    },

    Get_Paragraph_ParaPr : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Get_Paragraph_ParaPr();
    },

    Get_Paragraph_TextPr : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Get_Paragraph_TextPr();
    },

    Get_Paragraph_TextPr_Copy : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Get_Paragraph_TextPr_Copy();

        return null;
    },

    Get_Paragraph_ParaPr_Copy : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Get_Paragraph_ParaPr_Copy();

        return null;
1933
    },    
1934 1935

    // Убираем селект
1936
    Selection_Remove : function(bNoCheckDrawing)
1937 1938
    {
        if ( null != this.CurHdrFtr )
1939
            return this.CurHdrFtr.Selection_Remove(bNoCheckDrawing);
1940 1941 1942
    },

    // Рисуем селект
1943
    Selection_Draw_Page : function(Page_abs)
1944 1945
    {
        if ( null != this.CurHdrFtr )
1946
            return this.CurHdrFtr.Selection_Draw_Page(Page_abs);
1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965
    },

    Selection_Clear : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Selection_Clear();
    },

    Selection_SetStart : function(X,Y, PageIndex, MouseEvent, bActivate)
    {
        // Если мы попадаем в заселекченную автофигуру, пусть она даже выходит за пределы
        if ( true === this.LogicDocument.DrawingObjects.pointInSelectedObject(X, Y, PageIndex) )
        {
            var NewPos = this.DrawingDocument.ConvertCoordsToAnotherPage(X, Y, PageIndex, this.CurPage);
            var _X = NewPos.X;
            var _Y = NewPos.Y;
            this.CurHdrFtr.Selection_SetStart( _X, _Y, this.CurPage, MouseEvent );
            this.ChangeCurPageOnEnd = false;

Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
1966 1967
            this.WaitMouseDown = false;

1968 1969 1970 1971 1972 1973
            return true;
        }

        this.ChangeCurPageOnEnd = true;

        var OldPage = this.CurPage;
1974

1975 1976 1977 1978 1979
        // Сначала проверяем, не попали ли мы в контент документа. Если да, тогда надо
        // активировать работу с самим документом (просто вернуть false здесь)

        var TempHdrFtr = null;
        var PageMetrics = this.LogicDocument.Get_PageContentStartPos( PageIndex );
1980
        
1981
        if ( MouseEvent.ClickCount >= 2 && true != editor.isStartAddShape &&
1982 1983
            !( Y <= PageMetrics.Y      || ( null !== ( TempHdrFtr = this.Pages[PageIndex].Header ) && true === TempHdrFtr.Is_PointInDrawingObjects( X, Y ) ) ) &&
            !( Y >= PageMetrics.YLimit || ( null !== ( TempHdrFtr = this.Pages[PageIndex].Footer ) && true === TempHdrFtr.Is_PointInDrawingObjects( X, Y ) ) ) )
1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996
        {
            // Убираем селект, если он был
            if ( null != this.CurHdrFtr )
            {
                this.CurHdrFtr.Selection_Remove();
            }

            MouseEvent.ClickCount = 1;
            return false;
        }

        this.CurPage = PageIndex;

1997
        var HdrFtr = null;
1998 1999 2000

        // Проверяем попали ли мы в колонтитул, если он есть. Если мы попали в
        // область колонтитула, а его там нет, тогда добавим новый колонтитул.
2001
        if ( Y <= PageMetrics.Y || ( null !== ( TempHdrFtr = this.Pages[PageIndex].Header ) && true === TempHdrFtr.Is_PointInDrawingObjects( X, Y ) ) || true === editor.isStartAddShape )
2002
        {
2003
            if ( null === this.Pages[PageIndex].Header )
2004 2005 2006
            {
                if ( false === editor.WordControl.m_oLogicDocument.Document_Is_SelectionLocked(changestype_HdrFtr) )
                {
2007
                    // Меняем старый режим редактирования, чтобы при Undo/Redo возвращаться в режим редактирования документа
2008
                    this.LogicDocument.CurPos.Type = docpostype_Content;
2009
                    History.Create_NewPoint(historydescription_Document_AddHeader);
2010
                    this.LogicDocument.CurPos.Type = docpostype_HdrFtr;
2011 2012
                    HdrFtr = this.LogicDocument.Create_SectionHdrFtr( hdrftr_Header, PageIndex );
                    this.LogicDocument.Recalculate();
2013 2014 2015 2016
                }
                else
                    return false;
            }
2017 2018
            else
                HdrFtr = this.Pages[PageIndex].Header;
2019
        }
2020
        else if ( Y >= PageMetrics.YLimit || ( null !== ( TempHdrFtr = this.Pages[PageIndex].Footer ) && true === TempHdrFtr.Is_PointInDrawingObjects( X, Y ) ) )
2021
        {
2022
            if ( null === this.Pages[PageIndex].Footer )
2023 2024 2025
            {
                if ( false === editor.WordControl.m_oLogicDocument.Document_Is_SelectionLocked(changestype_HdrFtr) )
                {
2026
                    // Меняем старый режим редактирования, чтобы при Undo/Redo возвращаться в режим редактирования документа
2027
                    this.LogicDocument.CurPos.Type = docpostype_Content;
2028
                    History.Create_NewPoint(historydescription_Document_AddFooter);
2029
                    this.LogicDocument.CurPos.Type = docpostype_HdrFtr;
2030 2031
                    HdrFtr = this.LogicDocument.Create_SectionHdrFtr( hdrftr_Footer, PageIndex );
                    this.LogicDocument.Recalculate();
2032 2033 2034 2035
                }
                else
                    return false;
            }
2036 2037
            else
                HdrFtr = this.Pages[PageIndex].Footer;
2038 2039
        }

2040
        if ( null === HdrFtr )
2041 2042 2043 2044
        {
            // Ничего не делаем и отключаем дальнейшую обработку MouseUp и MouseMove
            this.WaitMouseDown = true;

Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
2045
            return true;
2046 2047 2048 2049 2050 2051 2052 2053 2054 2055
        }
        else
        {
            this.WaitMouseDown = false;
        }

        // В зависимости от страницы и позиции на странице мы активируем(делаем текущим)
        // соответствующий колонтитул

        var OldHdrFtr = this.CurHdrFtr;
2056
        this.CurHdrFtr = HdrFtr;
2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068

        if ( null != OldHdrFtr && (OldHdrFtr != this.CurHdrFtr || OldPage != this.CurPage) )
        {
            // Удаляем селект, если он был на предыдущем колонтитуле
            OldHdrFtr.Selection_Remove();
        }

        if ( null != this.CurHdrFtr )
        {
            this.CurHdrFtr.Selection_SetStart( X, Y, PageIndex, MouseEvent );
            if ( true === bActivate )
            {
2069
                var NewMouseEvent = {};
2070 2071 2072
                NewMouseEvent.Type       = g_mouse_event_type_up;
                NewMouseEvent.ClickCount = 1;
                this.CurHdrFtr.Selection_SetEnd( X, Y, PageIndex, NewMouseEvent );
2073
                this.CurHdrFtr.Content.Cursor_MoveToStartPos(false);
2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093
            }
        }

        return true;
    },

    Selection_SetEnd : function(X, Y, PageIndex, MouseEvent)
    {
        if ( true === this.WaitMouseDown )
            return;

        if ( null != this.CurHdrFtr )
        {
            // Селект может происходить только внутри одного колонтитула, а колонтитул
            // не может быть разбит на несколько страниц
            var ResY = Y;

            if ( docpostype_DrawingObjects != this.CurHdrFtr.Content.CurPos.Type )
            {
                if ( PageIndex > this.CurPage )
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
2094
                    ResY = this.LogicDocument.Get_PageLimits(this.CurPage).YLimit + 10;
2095 2096 2097 2098 2099 2100 2101 2102 2103
                else if ( PageIndex < this.CurPage )
                    ResY = -10;

                PageIndex = this.CurPage;
            }

            this.CurHdrFtr.Selection_SetEnd(X, ResY, PageIndex, MouseEvent);

            if ( false === this.ChangeCurPageOnEnd )
2104 2105 2106
            {
                this.CurHdrFtr.Set_Page( this.CurPage );
            }
2107 2108 2109
        }
    },

2110 2111 2112 2113 2114 2115 2116 2117
    Selection_Is_TableBorderMove : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Selection_Is_TableBorderMove();

        return false;
    },

2118
    Selection_Check : function(X, Y, Page_Abs, NearPos)
2119 2120
    {
        if ( null != this.CurHdrFtr )
2121
            return this.CurHdrFtr.Selection_Check( X, Y, Page_Abs, NearPos );
2122 2123
    },

2124 2125 2126 2127 2128 2129 2130 2131
    Selection_IsEmpty : function(bCheckHidden)
    {
        if (null !== this.CurHdrFtr)
            return this.CurHdrFtr.Content.Selection_IsEmpty(bCheckHidden);

        return true;
    },

2132 2133 2134 2135 2136 2137 2138 2139 2140
    // Селектим весь параграф
    Select_All : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Select_All();
    },

    Get_NearestPos : function(PageNum, X, Y, bAnchor, Drawing)
    {
2141 2142
        var HdrFtr = (true === editor.isStartAddShape ? this.CurHdrFtr : this.Internal_GetContentByXY( X, Y, PageNum ));
        
2143 2144 2145 2146 2147 2148 2149 2150 2151 2152
        if ( null != HdrFtr )
            return HdrFtr.Get_NearestPos( X, Y, bAnchor, Drawing );
        else
            return { X : -1, Y : -1, Height : -1 };
    },

    Get_CurrentParagraph : function()
    {
        return this.CurHdrFtr.Get_CurrentParagraph();
    },
2153 2154 2155 2156 2157 2158

    Start_SelectionFromCurPos : function()
    {
        if (null !== this.CurHdrFtr)
            this.CurHdrFtr.Start_SelectionFromCurPos();
    },
2159 2160 2161 2162 2163 2164 2165 2166 2167 2168
//-----------------------------------------------------------------------------------
// Внутренние(вспомогательные) функции
//-----------------------------------------------------------------------------------

    // Возвращаем колонтитул по данной позиции
    Internal_GetContentByXY : function( X, Y, PageIndex )
    {
        var Header = null;
        var Footer = null;

2169
        if ( undefined !== this.Pages[PageIndex] )
2170
        {
2171 2172
            Header = this.Pages[PageIndex].Header;
            Footer = this.Pages[PageIndex].Footer;
2173
        }
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
2174 2175
        
        var PageH = this.LogicDocument.Get_PageLimits( PageIndex).YLimit;
2176

Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
2177
        if ( Y <= PageH / 2 && null != Header )
2178
            return Header;
Ilya.Kirillov's avatar
 
Ilya.Kirillov committed
2179
        else if ( Y >= PageH / 2 && null != Footer )
2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255
            return Footer;
        else if ( null != Header )
            return Header;
        else
            return Footer;

        return null;
    },

//-----------------------------------------------------------------------------------
// Функции для работы с таблицами
//-----------------------------------------------------------------------------------
    Table_AddRow : function(bBefore)
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Table_AddRow( bBefore );
    },

    Table_AddCol : function(bBefore)
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Table_AddCol( bBefore );
    },

    Table_RemoveRow : function()
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Table_RemoveRow();
    },

    Table_RemoveCol : function()
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Table_RemoveCol();
    },

    Table_MergeCells : function()
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Table_MergeCells();
    },

    Table_SplitCell : function( Cols, Rows )
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Table_SplitCell( Cols, Rows );
    },

    Table_RemoveTable : function()
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Table_RemoveTable();
    },

    Table_Select : function(Type)
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Table_Select(Type);
    },

    Table_CheckMerge : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Table_CheckMerge();
    },

    Table_CheckSplit : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Table_CheckSplit();
    },
//-----------------------------------------------------------------------------------
// Undo/Redo функции
//-----------------------------------------------------------------------------------
    Get_SelectionState : function()
    {
2256
        var HdrFtrState = {};
2257 2258 2259 2260 2261 2262
        HdrFtrState.CurHdrFtr = this.CurHdrFtr;

        var State = null;
        if ( null != this.CurHdrFtr )
            State = this.CurHdrFtr.Content.Get_SelectionState();
        else
2263
            State = [];
2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279

        State.push( HdrFtrState );

        return State;
    },

    Set_SelectionState : function(State, StateIndex)
    {
        if ( State.length <= 0 )
            return;

        var HdrFtrState = State[StateIndex];
        this.CurHdrFtr = HdrFtrState.CurHdrFtr;

        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Content.Set_SelectionState(State, StateIndex - 1);
2280
    },    
2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335
//-----------------------------------------------------------------------------------
// Функции для работы с гиперссылками
//-----------------------------------------------------------------------------------
    Hyperlink_Add : function(HyperProps)
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Hyperlink_Add(HyperProps);
    },

    Hyperlink_Modify : function(HyperProps)
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Hyperlink_Modify(HyperProps);
    },

    Hyperlink_Remove : function()
    {
        if ( null != this.CurHdrFtr )
            this.CurHdrFtr.Hyperlink_Remove();
    },

    Hyperlink_CanAdd : function(bCheckInHyperlink)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Hyperlink_CanAdd(bCheckInHyperlink);

        return false;
    },

    Hyperlink_Check : function(bCheckEnd)
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Hyperlink_Check(bCheckEnd);

        return null;
    },
//-----------------------------------------------------------------------------------
// Функции для работы с комментариями
//-----------------------------------------------------------------------------------
    Add_Comment : function(Comment)
    {
        if ( null != this.CurHdrFtr )
        {
            // Отмечаем, что данный комментарий добавлен к колонтитулу
            Comment.Set_TypeInfo( comment_type_HdrFtr, this.CurHdrFtr );
            this.CurHdrFtr.Add_Comment( Comment );
        }
    },

    CanAdd_Comment : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.CanAdd_Comment();

        return false;
2336 2337 2338 2339 2340 2341 2342 2343
    },
    
    Get_SelectionAnchorPos : function()
    {
        if ( null != this.CurHdrFtr )
            return this.CurHdrFtr.Content.Get_SelectionAnchorPos();
        
        return { X : 0, Y : 0, Page : 0 };
2344
    }
2345 2346 2347 2348 2349 2350 2351 2352
};
CHeaderFooterController.prototype.Get_StyleFromFormatting = function()
{
    if (null != this.CurHdrFtr)
        return this.CurHdrFtr.Content.Get_StyleFromFormatting();

    return null;
};
2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367
CHeaderFooterController.prototype.Set_ParagraphFramePr = function(FramePr, bDelete)
{
    if (null !== this.CurHdrFtr)
        this.CurHdrFtr.Set_ParagraphFramePr(FramePr, bDelete);
};
CHeaderFooterController.prototype.Accept_RevisionChanges = function(Type, bAll)
{
    if (null !== this.CurHdrFtr)
        this.CurHdrFtr.Content.Accept_RevisionChanges(Type, bAll);
};
CHeaderFooterController.prototype.Reject_RevisionChanges = function(Type, bAll)
{
    if (null !== this.CurHdrFtr)
        this.CurHdrFtr.Content.Reject_RevisionChanges(Type, bAll);
};
2368

2369 2370 2371 2372 2373

function CHdrFtrPage()
{
    this.Header = null;
    this.Footer = null;
2374
}