LCOV - code coverage report
Current view: top level - sw/source/core/uibase/utlui - navipi.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1 753 0.1 %
Date: 2014-04-11 Functions: 1 60 1.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <string>
      21             : #include <comphelper/string.hxx>
      22             : #include <svl/urlbmk.hxx>
      23             : #include <svl/stritem.hxx>
      24             : #include <vcl/graphicfilter.hxx>
      25             : #include <svl/urihelper.hxx>
      26             : #include <sot/formats.hxx>
      27             : #include <sot/filelist.hxx>
      28             : #include <sfx2/event.hxx>
      29             : #include <sfx2/imgmgr.hxx>
      30             : #include <sfx2/dispatch.hxx>
      31             : #include <sfx2/dockwin.hxx>
      32             : #include <vcl/toolbox.hxx>
      33             : #include <vcl/settings.hxx>
      34             : #include <swtypes.hxx>
      35             : #include <swmodule.hxx>
      36             : #include <view.hxx>
      37             : #include <navicfg.hxx>
      38             : #include <wrtsh.hxx>
      39             : #include <docsh.hxx>
      40             : #include <actctrl.hxx>
      41             : #include <IMark.hxx>
      42             : #include <navipi.hxx>
      43             : #include <content.hxx>
      44             : #include <workctrl.hxx>
      45             : #include <section.hxx>
      46             : #include <edtwin.hxx>
      47             : #include <sfx2/app.hxx>
      48             : #include <cmdid.h>
      49             : #include <helpid.h>
      50             : #include <ribbar.hrc>
      51             : #include <navipi.hrc>
      52             : #include <utlui.hrc>
      53             : 
      54             : #include "access.hrc"
      55             : 
      56             : #include <unomid.h>
      57             : 
      58             : #define PAGE_CHANGE_TIMEOUT 1000
      59             : 
      60             : using namespace ::com::sun::star::uno;
      61             : using namespace ::com::sun::star::frame;
      62             : 
      63          37 : SFX_IMPL_CHILDWINDOW_CONTEXT( SwNavigationChild, SID_NAVIGATOR, SwView )
      64             : 
      65             : // Filter the control characters out of the Outline-Entry
      66             : 
      67           0 : OUString SwNavigationPI::CleanEntry(const OUString& rEntry)
      68             : {
      69           0 :     if (rEntry.isEmpty())
      70           0 :         return rEntry;
      71             : 
      72           0 :     OUStringBuffer aEntry(rEntry);
      73           0 :     for (sal_Int32 i = 0; i < rEntry.getLength(); ++i)
      74           0 :         if(aEntry[i] == 10 || aEntry[i] == 9)
      75           0 :             aEntry[i] = 0x20;
      76             : 
      77           0 :     return aEntry.makeStringAndClear();
      78             : }
      79             : 
      80             : // Execution of the drag operation with and without the children.
      81             : 
      82           0 : void SwNavigationPI::MoveOutline(sal_uInt16 nSource, sal_uInt16 nTarget,
      83             :                                                     bool bWithChildren)
      84             : {
      85           0 :     SwView *pView = GetCreateView();
      86           0 :     SwWrtShell &rSh = pView->GetWrtShell();
      87           0 :     if(nTarget < nSource || nTarget == USHRT_MAX)
      88           0 :         nTarget ++;
      89           0 :     if ( rSh.IsOutlineMovable( nSource ))
      90             :     {
      91             : 
      92           0 :         short nMove = nTarget-nSource; //( nDir<0 ) ? 1 : 0 ;
      93           0 :         rSh.GotoOutline(nSource);
      94           0 :         if (bWithChildren)
      95           0 :             rSh.MakeOutlineSel(nSource, nSource, sal_True);
      96             :         // While moving, the selected children does not counting.
      97           0 :         sal_uInt16 nLastOutlinePos = rSh.GetOutlinePos(MAXLEVEL);
      98           0 :         if(bWithChildren && nMove > 1 &&
      99             :                 nLastOutlinePos < nTarget)
     100             :         {
     101           0 :             if(!rSh.IsCrsrPtAtEnd())
     102           0 :                 rSh.SwapPam();
     103           0 :             nMove -= nLastOutlinePos - nSource;
     104             :         }
     105           0 :         if(!bWithChildren || nMove < 1 || nLastOutlinePos < nTarget )
     106           0 :             rSh.MoveOutlinePara( nMove );
     107           0 :         rSh.ClearMark();
     108           0 :         rSh.GotoOutline( nSource + nMove);
     109           0 :         FillBox();
     110             :     }
     111             : 
     112           0 : }
     113             : 
     114             : // After goto cancel the status frame selection
     115             : 
     116           0 : static void lcl_UnSelectFrm(SwWrtShell *pSh)
     117             : {
     118           0 :     if (pSh->IsFrmSelected())
     119             :     {
     120           0 :         pSh->UnSelectFrm();
     121           0 :         pSh->LeaveSelFrmMode();
     122             :     }
     123           0 : }
     124             : 
     125             : // Select the document view
     126             : 
     127           0 : IMPL_LINK( SwNavigationPI, DocListBoxSelectHdl, ListBox *, pBox )
     128             : {
     129           0 :     int nEntryIdx = pBox->GetSelectEntryPos();
     130             :     SwView *pView ;
     131           0 :     pView = SwModule::GetFirstView();
     132           0 :     while (nEntryIdx-- && pView)
     133             :     {
     134           0 :         pView = SwModule::GetNextView(pView);
     135             :     }
     136           0 :     if(!pView)
     137             :     {
     138             :         nEntryIdx == 0 ?
     139           0 :             aContentTree.ShowHiddenShell():
     140           0 :                 aContentTree.ShowActualView();
     141             : 
     142             :     }
     143             :     else
     144             :     {
     145           0 :         aContentTree.SetConstantShell(pView->GetWrtShellPtr());
     146             :     }
     147           0 :     return 0;
     148             : }
     149             : 
     150             : // Filling of the list box for outline view or documents
     151             : // The PI will be set to full size
     152             : 
     153           0 : void SwNavigationPI::FillBox()
     154             : {
     155           0 :     if(pContentWrtShell)
     156             :     {
     157           0 :         aContentTree.SetHiddenShell( pContentWrtShell );
     158           0 :         aContentTree.Display(  false );
     159             :     }
     160             :     else
     161             :     {
     162           0 :         SwView *pView = GetCreateView();
     163           0 :         if(!pView)
     164             :         {
     165           0 :             aContentTree.SetActiveShell(0);
     166             :         }
     167           0 :         else if( pView != pActContView)
     168             :         {
     169           0 :             SwWrtShell* pWrtShell = pView->GetWrtShellPtr();
     170           0 :             aContentTree.SetActiveShell(pWrtShell);
     171             :         }
     172             :         else
     173           0 :             aContentTree.Display( true );
     174           0 :         pActContView = pView;
     175             :     }
     176           0 : }
     177             : 
     178           0 : void SwNavigationPI::UsePage(SwWrtShell *pSh)
     179             : {
     180           0 :     if (!pSh)
     181             :     {
     182           0 :         SwView *pView = GetCreateView();
     183           0 :         pSh = pView ? &pView->GetWrtShell() : 0;
     184           0 :         GetPageEdit().SetValue(1);
     185             :     }
     186           0 :     if (pSh)
     187             :     {
     188           0 :         const sal_uInt16 nPageCnt = pSh->GetPageCnt();
     189             :         sal_uInt16 nPhyPage, nVirPage;
     190           0 :         pSh->GetPageNum(nPhyPage, nVirPage);
     191             : 
     192           0 :         GetPageEdit().SetMax(nPageCnt);
     193           0 :         GetPageEdit().SetLast(nPageCnt);
     194           0 :         GetPageEdit().SetValue(nPhyPage);
     195             :     }
     196           0 : }
     197             : 
     198             : // Select handler of the toolboxes
     199             : 
     200           0 : IMPL_LINK( SwNavigationPI, ToolBoxSelectHdl, ToolBox *, pBox )
     201             : {
     202           0 :     const sal_uInt16 nCurrItemId = pBox->GetCurItemId();
     203           0 :     SwView *pView = GetCreateView();
     204           0 :     if (!pView)
     205           0 :         return 1;
     206           0 :     SwWrtShell &rSh = pView->GetWrtShell();
     207             :     // Get MouseModifier for Outline-Move
     208             : 
     209             :     // Standard: sublevels are taken
     210             :     // do not take sublevels with Ctrl
     211           0 :     sal_Bool bOutlineWithChildren  = ( KEY_MOD1 != pBox->GetModifier());
     212           0 :     int nFuncId = 0;
     213           0 :     bool bFocusToDoc = false;
     214           0 :     switch (nCurrItemId)
     215             :     {
     216             :         case FN_UP:
     217             :         case FN_DOWN:
     218             :         {
     219             :             // #i75416# move the execution of the search to an asynchronously called static link
     220           0 :             bool* pbNext = new bool( FN_DOWN == nCurrItemId );
     221           0 :             Application::PostUserEvent( STATIC_LINK(pView, SwView, MoveNavigationHdl), pbNext );
     222             :         }
     223           0 :         break;
     224             :         case FN_SHOW_ROOT:
     225             :         {
     226           0 :             aContentTree.ToggleToRoot();
     227             :         }
     228           0 :         break;
     229             :         case FN_SHOW_CONTENT_BOX:
     230             :         case FN_SELECT_CONTENT:
     231           0 :             if(pContextWin!=NULL && pContextWin->GetFloatingWindow()!=NULL)
     232             :             {
     233           0 :                 if(_IsZoomedIn() )
     234             :                 {
     235           0 :                     _ZoomOut();
     236             :                 }
     237             :                 else
     238             :                 {
     239           0 :                     _ZoomIn();
     240             :                 }
     241             :             }
     242           0 :             return sal_True;
     243             :         // Functions that will trigger a direct action.
     244             : 
     245             :         case FN_SELECT_FOOTER:
     246             :         {
     247           0 :             rSh.MoveCrsr();
     248           0 :             const sal_uInt16 eType = rSh.GetFrmType(0,sal_False);
     249           0 :             if (eType & FRMTYPE_FOOTER)
     250             :             {
     251           0 :                 if (rSh.EndPg())
     252           0 :                     nFuncId = FN_END_OF_PAGE;
     253             :             }
     254           0 :             else if (rSh.GotoFooterTxt())
     255           0 :                 nFuncId = FN_TO_FOOTER;
     256           0 :             bFocusToDoc = true;
     257             :         }
     258           0 :         break;
     259             :         case FN_SELECT_HEADER:
     260             :         {
     261           0 :             rSh.MoveCrsr();
     262           0 :             const sal_uInt16 eType = rSh.GetFrmType(0,sal_False);
     263           0 :             if (eType & FRMTYPE_HEADER)
     264             :             {
     265           0 :                 if (rSh.SttPg())
     266           0 :                     nFuncId = FN_START_OF_PAGE;
     267             :             }
     268           0 :             else if (rSh.GotoHeaderTxt())
     269           0 :                 nFuncId = FN_TO_HEADER;
     270           0 :             bFocusToDoc = true;
     271             :         }
     272           0 :         break;
     273             :         case FN_SELECT_FOOTNOTE:
     274             :         {
     275           0 :             rSh.MoveCrsr();
     276           0 :             const sal_uInt16 eFrmType = rSh.GetFrmType(0,sal_False);
     277             :                 // Jump from the footnote to the anchor.
     278           0 :             if (eFrmType & FRMTYPE_FOOTNOTE)
     279             :             {
     280           0 :                 if (rSh.GotoFtnAnchor())
     281           0 :                     nFuncId = FN_FOOTNOTE_TO_ANCHOR;
     282             :             }
     283             :                 // Otherwise, jump to the first footnote text;
     284             :                 // go to the next footnote if this is not possible;
     285             :                 // if this is also not possible got to the footnote before.
     286             :             else
     287             :             {
     288           0 :                 if (rSh.GotoFtnTxt())
     289           0 :                     nFuncId = FN_FOOTNOTE_TO_ANCHOR;
     290           0 :                 else if (rSh.GotoNextFtnAnchor())
     291           0 :                     nFuncId = FN_NEXT_FOOTNOTE;
     292           0 :                 else if (rSh.GotoPrevFtnAnchor())
     293           0 :                     nFuncId = FN_PREV_FOOTNOTE;
     294             :             }
     295           0 :             bFocusToDoc = true;
     296             :         }
     297           0 :         break;
     298             : 
     299             :         case FN_SELECT_SET_AUTO_BOOKMARK:
     300           0 :             MakeMark();
     301           0 :         break;
     302             :         case FN_ITEM_DOWN:
     303             :         case FN_ITEM_UP:
     304             :         case FN_ITEM_LEFT:
     305             :         case FN_ITEM_RIGHT:
     306             :         case FN_GLOBAL_EDIT:
     307             :         {
     308           0 :             if(IsGlobalMode())
     309           0 :                 aGlobalTree.ExecCommand(nCurrItemId);
     310             :             else
     311           0 :                 aContentTree.ExecCommand(nCurrItemId, bOutlineWithChildren);
     312             :         }
     313           0 :         break;
     314             :         case FN_GLOBAL_SWITCH:
     315             :         {
     316           0 :             ToggleTree();
     317           0 :             pConfig->SetGlobalActive(IsGlobalMode());
     318             :         }
     319           0 :         break;
     320             :         case FN_GLOBAL_SAVE_CONTENT:
     321             :         {
     322           0 :             sal_Bool bSave = rSh.IsGlblDocSaveLinks();
     323           0 :             rSh.SetGlblDocSaveLinks( !bSave );
     324           0 :             pBox->CheckItem(FN_GLOBAL_SAVE_CONTENT, !bSave );
     325             :         }
     326           0 :         break;
     327             :     }
     328           0 :     if (nFuncId)
     329             :     {
     330           0 :         lcl_UnSelectFrm(&rSh);
     331             :     }
     332           0 :     if(bFocusToDoc)
     333           0 :         pView->GetEditWin().GrabFocus();
     334           0 :     return sal_True;
     335             : }
     336             : 
     337             : // Click handler of the toolboxes
     338             : 
     339           0 : IMPL_LINK( SwNavigationPI, ToolBoxClickHdl, ToolBox *, pBox )
     340             : {
     341           0 :     const sal_uInt16 nCurrItemId = pBox->GetCurItemId();
     342           0 :     switch (nCurrItemId)
     343             :     {
     344             :         case FN_GLOBAL_UPDATE:
     345             :         case FN_GLOBAL_OPEN:
     346             :         {
     347           0 :             aGlobalTree.TbxMenuHdl(nCurrItemId, pBox);
     348             :         }
     349           0 :         break;
     350             :     }
     351             : 
     352           0 :     return sal_True;
     353             : }
     354             : 
     355           0 : IMPL_LINK( SwNavigationPI, ToolBoxDropdownClickHdl, ToolBox*, pBox )
     356             : {
     357           0 :     const sal_uInt16 nCurrItemId = pBox->GetCurItemId();
     358           0 :     switch (nCurrItemId)
     359             :     {
     360             :         case FN_CREATE_NAVIGATION:
     361             :         {
     362           0 :             CreateNavigationTool(pBox->GetItemRect(FN_CREATE_NAVIGATION), true, this);
     363             :         }
     364           0 :         break;
     365             : 
     366             :         case FN_DROP_REGION:
     367             :         {
     368             :             static const char* aHIDs[] =
     369             :             {
     370             :                 HID_NAVI_DRAG_HYP,
     371             :                 HID_NAVI_DRAG_LINK,
     372             :                 HID_NAVI_DRAG_COPY,
     373             :             };
     374           0 :             PopupMenu *pMenu = new PopupMenu;
     375           0 :             for (sal_uInt16 i = 0; i <= REGION_MODE_EMBEDDED; i++)
     376             :             {
     377           0 :                 pMenu->InsertItem( i + 1, aContextArr[i] );
     378           0 :                 pMenu->SetHelpId(i + 1, aHIDs[i]);
     379             :             }
     380           0 :             pMenu->CheckItem( nRegionMode + 1 );
     381           0 :             pMenu->SetSelectHdl(LINK(this, SwNavigationPI, MenuSelectHdl));
     382           0 :             pBox->SetItemDown( nCurrItemId, true );
     383             :             pMenu->Execute( pBox,
     384             :                     pBox->GetItemRect(FN_DROP_REGION),
     385           0 :                     POPUPMENU_EXECUTE_DOWN );
     386           0 :             pBox->SetItemDown( nCurrItemId, false );
     387           0 :             pBox->EndSelection();
     388           0 :             delete pMenu;
     389           0 :             pBox->Invalidate();
     390             :         }
     391           0 :         break;
     392             :         case FN_OUTLINE_LEVEL:
     393             :         {
     394           0 :             PopupMenu *pMenu = new PopupMenu;
     395           0 :             for (sal_uInt16 i = 101; i <= 100 + MAXLEVEL; i++)
     396             :             {
     397           0 :                 pMenu->InsertItem( i, OUString::number(i - 100) );
     398           0 :                 pMenu->SetHelpId( i, HID_NAVI_OUTLINES );
     399             :             }
     400           0 :             pMenu->CheckItem( aContentTree.GetOutlineLevel() + 100 );
     401           0 :             pMenu->SetSelectHdl(LINK(this, SwNavigationPI, MenuSelectHdl));
     402           0 :             pBox->SetItemDown( nCurrItemId, true );
     403             :             pMenu->Execute( pBox,
     404             :                     pBox->GetItemRect(FN_OUTLINE_LEVEL),
     405           0 :                     POPUPMENU_EXECUTE_DOWN );
     406           0 :             pBox->SetItemDown( nCurrItemId, false );
     407           0 :             delete pMenu;
     408           0 :             pBox->EndSelection();
     409           0 :             pBox->Invalidate();
     410             :         }
     411           0 :         break;
     412             :     }
     413           0 :     return sal_True;
     414             : }
     415             : 
     416           0 : SwNavHelpToolBox::SwNavHelpToolBox(SwNavigationPI* pParent, const ResId &rResId) :
     417           0 :             SwHelpToolBox(pParent, rResId)
     418           0 : {}
     419             : 
     420           0 : void SwNavHelpToolBox::MouseButtonDown(const MouseEvent &rEvt)
     421             : {
     422           0 :     if(rEvt.GetButtons() == MOUSE_LEFT &&
     423           0 :             FN_CREATE_NAVIGATION == GetItemId(rEvt.GetPosPixel()))
     424             :     {
     425           0 :         ((SwNavigationPI*)GetParent())->CreateNavigationTool(GetItemRect(FN_CREATE_NAVIGATION), false, this);
     426             :     }
     427             :     else
     428           0 :         SwHelpToolBox::MouseButtonDown(rEvt);
     429           0 : }
     430             : 
     431           0 : void SwNavigationPI::CreateNavigationTool(const Rectangle& rRect, bool bSetFocus, Window *pParent)
     432             : {
     433           0 :     Reference< XFrame > xFrame = GetCreateView()->GetViewFrame()->GetFrame().GetFrameInterface();
     434             :     SwScrollNaviPopup* pPopup = new
     435           0 :         SwScrollNaviPopup(FN_SCROLL_NAVIGATION, xFrame, pParent);
     436             : 
     437           0 :     Rectangle aRect(rRect);
     438           0 :     Point aT1 = aRect.TopLeft();
     439           0 :     aT1 = pPopup->GetParent()->OutputToScreenPixel(pPopup->GetParent()->AbsoluteScreenToOutputPixel(aContentToolBox.OutputToAbsoluteScreenPixel(aT1)));
     440           0 :     aRect.SetPos(aT1);
     441           0 :     pPopup->StartPopupMode(aRect, FLOATWIN_POPUPMODE_RIGHT|FLOATWIN_POPUPMODE_ALLOWTEAROFF);
     442           0 :     SetPopupWindow( pPopup );
     443           0 :     if(bSetFocus)
     444             :     {
     445           0 :         pPopup->EndPopupMode(FLOATWIN_POPUPMODEEND_TEAROFF);
     446           0 :         pPopup->GrabFocus();
     447           0 :     }
     448           0 : }
     449             : 
     450           0 : void  SwNavHelpToolBox::RequestHelp( const HelpEvent& rHEvt )
     451             : {
     452           0 :     sal_uInt16 nItemId = GetItemId(ScreenToOutputPixel(rHEvt.GetMousePosPixel()));
     453           0 :     if( FN_UP == nItemId || FN_DOWN == nItemId )
     454             :     {
     455           0 :         SetItemText(nItemId, SwScrollNaviPopup::GetQuickHelpText((FN_DOWN == nItemId)));
     456             :     }
     457           0 :     SwHelpToolBox::RequestHelp(rHEvt);
     458           0 : }
     459             : 
     460             : // Action-Handler Edit:
     461             : // Switches to the page if the structure view is not turned on.
     462             : 
     463           0 : IMPL_LINK( SwNavigationPI, EditAction, NumEditAction *, pEdit )
     464             : {
     465           0 :     SwView *pView = GetCreateView();
     466           0 :     if (pView)
     467             :     {
     468           0 :         if(aPageChgTimer.IsActive())
     469           0 :             aPageChgTimer.Stop();
     470           0 :         pCreateView->GetWrtShell().GotoPage((sal_uInt16)pEdit->GetValue(), sal_True);
     471           0 :         pCreateView->GetEditWin().GrabFocus();
     472           0 :         pCreateView->GetViewFrame()->GetBindings().Invalidate(FN_STAT_PAGE);
     473             :     }
     474           0 :     return 0;
     475             : }
     476             : 
     477             : // If the page can be set here, the maximum is set.
     478             : 
     479           0 : IMPL_LINK( SwNavigationPI, EditGetFocus, NumEditAction *, pEdit )
     480             : {
     481           0 :     SwView *pView = GetCreateView();
     482           0 :     if (!pView)
     483           0 :         return 0;
     484           0 :     SwWrtShell &rSh = pView->GetWrtShell();
     485             : 
     486           0 :     const sal_uInt16 nPageCnt = rSh.GetPageCnt();
     487           0 :     pEdit->SetMax(nPageCnt);
     488           0 :     pEdit->SetLast(nPageCnt);
     489           0 :     return 0;
     490             : }
     491             : 
     492           0 : sal_Bool SwNavigationPI::Close()
     493             : {
     494           0 :     SfxViewFrame* pVFrame = pCreateView->GetViewFrame();
     495           0 :     pVFrame->GetBindings().Invalidate(SID_NAVIGATOR);
     496           0 :     pVFrame->GetDispatcher()->Execute(SID_NAVIGATOR);
     497           0 :     return sal_True;
     498             : }
     499             : 
     500             : // Setting of an automatic mark
     501             : 
     502           0 : void SwNavigationPI::MakeMark()
     503             : {
     504           0 :     SwView *pView = GetCreateView();
     505           0 :     if (!pView) return;
     506           0 :     SwWrtShell &rSh = pView->GetWrtShell();
     507           0 :     IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
     508             : 
     509             :     // collect and sort navigator reminder names
     510           0 :     ::std::vector< ::rtl::OUString > vNavMarkNames;
     511           0 :     for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getAllMarksBegin();
     512           0 :         ppMark != pMarkAccess->getAllMarksEnd();
     513             :         ++ppMark)
     514           0 :         if( IDocumentMarkAccess::GetType(**ppMark) == IDocumentMarkAccess::NAVIGATOR_REMINDER )
     515           0 :             vNavMarkNames.push_back(ppMark->get()->GetName());
     516           0 :     ::std::sort(vNavMarkNames.begin(), vNavMarkNames.end());
     517             : 
     518             :     // we are maxed out and delete one
     519             :     // nAutoMarkIdx rotates through the available MarkNames
     520             :     // this assumes that IDocumentMarkAccess generates Names in ascending order
     521           0 :     if(vNavMarkNames.size() == MAX_MARKS)
     522           0 :         pMarkAccess->deleteMark(pMarkAccess->findMark(vNavMarkNames[nAutoMarkIdx]));
     523             : 
     524           0 :     rSh.SetBookmark(KeyCode(), OUString(), OUString(), IDocumentMarkAccess::NAVIGATOR_REMINDER);
     525           0 :     SwView::SetActMark( nAutoMarkIdx );
     526             : 
     527           0 :     if(++nAutoMarkIdx == MAX_MARKS)
     528           0 :         nAutoMarkIdx = 0;
     529             : }
     530             : 
     531           0 : void SwNavigationPI::GotoPage()
     532             : {
     533           0 :     if (pContextWin && pContextWin->GetFloatingWindow() && pContextWin->GetFloatingWindow()->IsRollUp())
     534           0 :         _ZoomIn();
     535           0 :     if(IsGlobalMode())
     536           0 :         ToggleTree();
     537           0 :     UsePage(0);
     538           0 :     GetPageEdit().GrabFocus();
     539           0 : }
     540             : 
     541           0 : void SwNavigationPI::_ZoomOut()
     542             : {
     543           0 :     if (_IsZoomedIn())
     544             :     {
     545           0 :         FloatingWindow* pFloat = pContextWin!=NULL ? pContextWin->GetFloatingWindow() : NULL;
     546           0 :         bIsZoomedIn = sal_False;
     547           0 :         Size aSz(GetOutputSizePixel());
     548           0 :         aSz.Height() = nZoomOut;
     549           0 :         Size aMinOutSizePixel = ((SfxDockingWindow*)GetParent())->GetMinOutputSizePixel();
     550           0 :         ((SfxDockingWindow*)GetParent())->SetMinOutputSizePixel(Size(
     551           0 :                             aMinOutSizePixel.Width(),nZoomOutInit));
     552           0 :         if (pFloat != NULL)
     553           0 :             pFloat->SetOutputSizePixel(aSz);
     554           0 :         FillBox();
     555           0 :         if(IsGlobalMode())
     556             :         {
     557           0 :             aGlobalTree.ShowTree();
     558             :         }
     559             :         else
     560             :         {
     561           0 :             aContentTree.ShowTree();
     562           0 :             aDocListBox.Show();
     563             :         }
     564           0 :         SvTreeListEntry* pFirst = aContentTree.FirstSelected();
     565           0 :         if(pFirst)
     566           0 :             aContentTree.Select(pFirst, true); // Enable toolbox
     567           0 :         pConfig->SetSmall( sal_False );
     568           0 :         aContentToolBox.CheckItem(FN_SHOW_CONTENT_BOX);
     569             :     }
     570           0 : }
     571             : 
     572           0 : void SwNavigationPI::_ZoomIn()
     573             : {
     574           0 :     if (pContextWin != NULL)
     575             :     {
     576           0 :         FloatingWindow* pFloat = pContextWin->GetFloatingWindow();
     577           0 :         if (pFloat &&
     578           0 :             (!_IsZoomedIn() || ( pContextWin->GetFloatingWindow()->IsRollUp())))
     579             :         {
     580           0 :             aContentTree.HideTree();
     581           0 :             aDocListBox.Hide();
     582           0 :             aGlobalTree.HideTree();
     583           0 :             bIsZoomedIn = sal_True;
     584           0 :             Size aSz(GetOutputSizePixel());
     585           0 :             if( aSz.Height() > nZoomIn )
     586           0 :                 nZoomOut = ( short ) aSz.Height();
     587             : 
     588           0 :             aSz.Height() = nZoomIn;
     589           0 :             Size aMinOutSizePixel = ((SfxDockingWindow*)GetParent())->GetMinOutputSizePixel();
     590           0 :             ((SfxDockingWindow*)GetParent())->SetMinOutputSizePixel(Size(
     591           0 :                     aMinOutSizePixel.Width(), aSz.Height()));
     592           0 :             pFloat->SetOutputSizePixel(aSz);
     593           0 :             SvTreeListEntry* pFirst = aContentTree.FirstSelected();
     594           0 :             if(pFirst)
     595           0 :                 aContentTree.Select(pFirst, true); // Enable toolbox
     596           0 :             pConfig->SetSmall( sal_True );
     597           0 :             aContentToolBox.CheckItem(FN_SHOW_CONTENT_BOX, false);
     598             :         }
     599             :     }
     600           0 : }
     601             : 
     602           0 : void SwNavigationPI::Resize()
     603             : {
     604           0 :     Window* pParent = GetParent();
     605           0 :     if( !_IsZoomedIn() )
     606             :     {
     607           0 :         Size aNewSize (pParent->GetOutputSizePixel());
     608             : 
     609           0 :         SfxDockingWindow* pDockingParent = dynamic_cast<SfxDockingWindow*>(pParent);
     610           0 :         if (pDockingParent != NULL)
     611             :         {
     612           0 :             FloatingWindow* pFloat =  pDockingParent->GetFloatingWindow();
     613             :             //change the minimum width depending on the dock status
     614           0 :             Size aMinOutSizePixel = pDockingParent->GetMinOutputSizePixel();
     615           0 :             if( pFloat)
     616             :             {
     617           0 :                 aNewSize = pFloat->GetOutputSizePixel();
     618           0 :                 aMinOutSizePixel.Width() = nWishWidth;
     619           0 :                 aMinOutSizePixel.Height() = _IsZoomedIn() ? nZoomIn : nZoomOutInit;
     620             :             }
     621             :             else
     622             :             {
     623           0 :                 aMinOutSizePixel.Width() = 0;
     624           0 :                 aMinOutSizePixel.Height() = 0;
     625             :             }
     626           0 :             pDockingParent->SetMinOutputSizePixel(aMinOutSizePixel);
     627             :         }
     628             : 
     629           0 :         const Point aPos = aContentTree.GetPosPixel();
     630           0 :         Point aLBPos = aDocListBox.GetPosPixel();
     631           0 :         long nDist = aPos.X();
     632           0 :         aNewSize.Height() -= (aPos.Y() + aPos.X() + nDocLBIniHeight + nDist);
     633           0 :         aNewSize.Width() -= 2 * nDist;
     634           0 :         aLBPos.Y() = aPos.Y() + aNewSize.Height() + nDist;
     635           0 :         aDocListBox.Show(!aGlobalTree.IsVisible() && aLBPos.Y() > aPos.Y() );
     636             : 
     637           0 :         Size aDocLBSz = aDocListBox.GetSizePixel();
     638           0 :         aDocLBSz.Width() = aNewSize.Width();
     639           0 :         if(aNewSize.Height() < 0)
     640           0 :             aDocLBSz.Height() = 0;
     641             :         else
     642           0 :             aDocLBSz.Height() = nDocLBIniHeight;
     643           0 :         aContentTree.SetSizePixel(aNewSize);
     644             :         // GlobalTree starts on to the top and goes all the way down.
     645           0 :         aNewSize.Height() += (nDist + nDocLBIniHeight + aPos.Y() - aGlobalTree.GetPosPixel().Y());
     646           0 :         aGlobalTree.SetSizePixel(aNewSize);
     647           0 :         aDocListBox.setPosSizePixel( aLBPos.X(), aLBPos.Y(),
     648           0 :             aDocLBSz.Width(), aDocLBSz.Height(),
     649           0 :             WINDOW_POSSIZE_X|WINDOW_POSSIZE_Y|WINDOW_POSSIZE_WIDTH);
     650             :     }
     651           0 : }
     652             : 
     653           0 : SwNavigationPI::SwNavigationPI( SfxBindings* _pBindings,
     654             :                                 SfxChildWindowContext* pCw,
     655             :                                 Window* pParent) :
     656             : 
     657             :     Window( pParent, SW_RES(DLG_NAVIGATION_PI)),
     658             :     SfxControllerItem( SID_DOCFULLNAME, *_pBindings ),
     659             : 
     660             :     aContentToolBox(this, SW_RES(TB_CONTENT)),
     661             :     aGlobalToolBox(this, SW_RES(TB_GLOBAL)),
     662             :     aContentImageList(SW_RES(IL_CONTENT)),
     663             :     aContentTree(this, SW_RES(TL_CONTENT)),
     664             :     aGlobalTree(this, SW_RES(TL_GLOBAL)),
     665             :     aDocListBox(this, SW_RES(LB_DOCS)),
     666             : 
     667             :     pxObjectShell(0),
     668             :     pContentView(0),
     669             :     pContentWrtShell(0),
     670             :     pActContView(0),
     671             :     pCreateView(0),
     672             :     pPopupWindow(0),
     673             :     pFloatingWindow(0),
     674             : 
     675             :     pContextWin(pCw),
     676             : 
     677           0 :     pConfig(SW_MOD()->GetNavigationConfig()),
     678             :     rBindings(*_pBindings),
     679             : 
     680             :     nWishWidth(0),
     681             :     nAutoMarkIdx(1),
     682             :     nRegionMode(REGION_MODE_NONE),
     683             : 
     684             :     bSmallMode(sal_False),
     685             :     bIsZoomedIn(sal_False),
     686             :     bPageCtrlsVisible(sal_False),
     687           0 :     bGlobalMode(sal_False)
     688             : {
     689           0 :     GetCreateView();
     690           0 :     InitImageList();
     691             : 
     692           0 :     aContentToolBox.SetHelpId(HID_NAVIGATOR_TOOLBOX );
     693           0 :     aGlobalToolBox.SetHelpId(HID_NAVIGATOR_GLOBAL_TOOLBOX);
     694           0 :     aDocListBox.SetHelpId(HID_NAVIGATOR_LISTBOX );
     695             : 
     696           0 :     nDocLBIniHeight = aDocListBox.GetSizePixel().Height();
     697           0 :     nZoomOutInit = nZoomOut = Resource::ReadShortRes();
     698             : 
     699             :     // Insert the numeric field in the toolbox.
     700             :     NumEditAction* pEdit = new NumEditAction(
     701           0 :                     &aContentToolBox, SW_RES(NF_PAGE ));
     702           0 :     pEdit->SetActionHdl(LINK(this, SwNavigationPI, EditAction));
     703           0 :     pEdit->SetGetFocusHdl(LINK(this, SwNavigationPI, EditGetFocus));
     704           0 :     pEdit->SetAccessibleName(pEdit->GetQuickHelpText());
     705           0 :     pEdit->SetUpHdl(LINK(this, SwNavigationPI, PageEditModifyHdl));
     706           0 :     pEdit->SetDownHdl(LINK(this, SwNavigationPI, PageEditModifyHdl));
     707             : 
     708           0 :     bPageCtrlsVisible = sal_True;
     709             : 
     710             :     // Double separators are not allowed, so you have to
     711             :     // determine the suitable size differently.
     712           0 :     Rectangle aFirstRect = aContentToolBox.GetItemRect(FN_SELECT_FOOTNOTE);
     713           0 :     Rectangle aSecondRect = aContentToolBox.GetItemRect(FN_SELECT_HEADER);
     714           0 :     sal_uInt16 nWidth = sal_uInt16(aFirstRect.Left() - aSecondRect.Left());
     715             : 
     716           0 :     Size aItemWinSize( nWidth , aFirstRect.Bottom() - aFirstRect.Top() );
     717           0 :     pEdit->SetSizePixel(aItemWinSize);
     718           0 :     aContentToolBox.InsertSeparator(4);
     719           0 :     aContentToolBox.InsertWindow( FN_PAGENUMBER, pEdit, 0, 4);
     720           0 :     aContentToolBox.InsertSeparator(4);
     721           0 :     aContentToolBox.SetHelpId(FN_PAGENUMBER, HID_NAVI_TBX16);
     722           0 :     aContentToolBox.ShowItem( FN_PAGENUMBER );
     723             : 
     724           0 :     for( sal_uInt16 i = 0; i <= REGION_MODE_EMBEDDED; i++  )
     725             :     {
     726           0 :         aContextArr[i] = SW_RESSTR(ST_HYPERLINK + i);
     727           0 :         aStatusArr[i] = SW_RESSTR(ST_STATUS_FIRST + i);
     728             :     }
     729           0 :     aStatusArr[3] = SW_RESSTR(ST_ACTIVE_VIEW);
     730           0 :     FreeResource();
     731             : 
     732           0 :     const Size& rOutSize =  GetOutputSizePixel();
     733             : 
     734           0 :     nZoomIn = (short)rOutSize.Height();
     735             : 
     736             :     // Make sure the toolbox has a size that fits all its contents
     737           0 :     Size aContentToolboxSize( aContentToolBox.CalcWindowSizePixel() );
     738           0 :     aContentToolBox.SetOutputSizePixel( aContentToolboxSize );
     739             : 
     740             :     // position listbox below toolbar and add some space
     741           0 :     long nListboxYPos = aContentToolBox.GetPosPixel().Y() + aContentToolboxSize.Height() + 4;
     742             : 
     743             :     // The left and right margins around the toolboxes should be equal.
     744           0 :     nWishWidth = aContentToolboxSize.Width();
     745           0 :     nWishWidth += 2 * aContentToolBox.GetPosPixel().X();
     746             : 
     747           0 :     DockingWindow* pDockingParent = dynamic_cast<DockingWindow*>(pParent);
     748           0 :     if (pDockingParent != NULL)
     749             :     {
     750           0 :         FloatingWindow* pFloat =  pDockingParent->GetFloatingWindow();
     751           0 :         Size aMinSize(pFloat ? nWishWidth : 0, pFloat ? nZoomOutInit : 0);
     752           0 :         pDockingParent->SetMinOutputSizePixel(aMinSize);
     753           0 :         SetOutputSizePixel( Size( nWishWidth, nZoomOutInit));
     754             : 
     755           0 :         SfxDockingWindow* pSfxDockingParent = dynamic_cast<SfxDockingWindow*>(pParent);
     756           0 :         if (pSfxDockingParent != NULL)
     757             :         {
     758           0 :             Size aTmpParentSize(pSfxDockingParent->GetSizePixel());
     759           0 :             if (aTmpParentSize.Width() < aMinSize.Width()
     760           0 :                 || aTmpParentSize.Height() < aMinSize.Height())
     761             :             {
     762           0 :                 if (pSfxDockingParent->GetFloatingWindow()
     763           0 :                     && ! pSfxDockingParent->GetFloatingWindow()->IsRollUp())
     764             :                 {
     765           0 :                     pSfxDockingParent->SetOutputSizePixel(aMinSize);
     766             :                 }
     767             :             }
     768             :         }
     769             :     }
     770             : 
     771           0 :     aContentTree.setPosSizePixel( 0, nListboxYPos, 0, 0, WINDOW_POSSIZE_Y );
     772           0 :     aContentTree.SetStyle( aContentTree.GetStyle()|WB_HASBUTTONS|WB_HASBUTTONSATROOT|
     773           0 :                             WB_CLIPCHILDREN|WB_HSCROLL|WB_FORCE_MAKEVISIBLE );
     774           0 :     aContentTree.SetSpaceBetweenEntries(3);
     775           0 :     aContentTree.SetSelectionMode( SINGLE_SELECTION );
     776             :     aContentTree.SetDragDropMode(   SV_DRAGDROP_CTRL_MOVE |
     777             :                                     SV_DRAGDROP_CTRL_COPY |
     778           0 :                                     SV_DRAGDROP_ENABLE_TOP );
     779           0 :     aContentTree.EnableAsyncDrag(true);
     780           0 :     aContentTree.ShowTree();
     781           0 :     aContentToolBox.CheckItem(FN_SHOW_CONTENT_BOX, true);
     782             : 
     783             : //  TreeListBox for global document
     784           0 :     aGlobalTree.setPosSizePixel( 0, nListboxYPos, 0, 0, WINDOW_POSSIZE_Y );
     785           0 :     aGlobalTree.SetSelectionMode( MULTIPLE_SELECTION );
     786           0 :     aGlobalTree.SetStyle( aGlobalTree.GetStyle()|WB_HASBUTTONS|WB_HASBUTTONSATROOT|
     787           0 :                                 WB_CLIPCHILDREN|WB_HSCROLL );
     788           0 :     Size aGlblSize(aGlobalToolBox.CalcWindowSizePixel());
     789           0 :     aGlobalToolBox.SetSizePixel(aGlblSize);
     790             : 
     791             : //  Handler
     792             : 
     793           0 :     Link aLk = LINK(this, SwNavigationPI, ToolBoxSelectHdl);
     794           0 :     aContentToolBox.SetSelectHdl( aLk );
     795           0 :     aGlobalToolBox.SetSelectHdl( aLk );
     796             :     aDocListBox.SetSelectHdl(LINK(this, SwNavigationPI,
     797           0 :                                                     DocListBoxSelectHdl));
     798           0 :     aContentToolBox.SetClickHdl( LINK(this, SwNavigationPI, ToolBoxClickHdl) );
     799           0 :     aContentToolBox.SetDropdownClickHdl( LINK(this, SwNavigationPI, ToolBoxDropdownClickHdl) );
     800           0 :     aGlobalToolBox.SetClickHdl( LINK(this, SwNavigationPI, ToolBoxClickHdl) );
     801           0 :     aGlobalToolBox.SetDropdownClickHdl( LINK(this, SwNavigationPI, ToolBoxDropdownClickHdl) );
     802           0 :     aGlobalToolBox.CheckItem(FN_GLOBAL_SWITCH, true);
     803             : 
     804           0 :     Font aFont(GetFont());
     805           0 :     aFont.SetWeight(WEIGHT_NORMAL);
     806           0 :     GetPageEdit().SetFont(aFont);
     807           0 :     aFont = aContentTree.GetFont();
     808           0 :     aFont.SetWeight(WEIGHT_NORMAL);
     809           0 :     aContentTree.SetFont(aFont);
     810           0 :     aGlobalTree.SetFont(aFont);
     811             : 
     812           0 :     StartListening(*SFX_APP());
     813           0 :     if ( pCreateView )
     814           0 :         StartListening(*pCreateView);
     815           0 :     SfxImageManager* pImgMan = SfxImageManager::GetImageManager( SW_MOD() );
     816           0 :     pImgMan->RegisterToolBox(&aContentToolBox, SFX_TOOLBOX_CHANGEOUTSTYLE);
     817           0 :     pImgMan->RegisterToolBox(&aGlobalToolBox, SFX_TOOLBOX_CHANGEOUTSTYLE);
     818             : 
     819           0 :     aContentToolBox.SetItemBits( FN_CREATE_NAVIGATION, aContentToolBox.GetItemBits( FN_CREATE_NAVIGATION ) | TIB_DROPDOWNONLY );
     820           0 :     aContentToolBox.SetItemBits( FN_DROP_REGION, aContentToolBox.GetItemBits( FN_DROP_REGION ) | TIB_DROPDOWNONLY );
     821           0 :     aContentToolBox.SetItemBits( FN_OUTLINE_LEVEL, aContentToolBox.GetItemBits( FN_OUTLINE_LEVEL ) | TIB_DROPDOWNONLY );
     822             : 
     823           0 :     if(IsGlobalDoc())
     824             :     {
     825           0 :         SwView *pActView = GetCreateView();
     826             :         aGlobalToolBox.CheckItem(FN_GLOBAL_SAVE_CONTENT,
     827           0 :                     pActView->GetWrtShellPtr()->IsGlblDocSaveLinks());
     828           0 :         if(pConfig->IsGlobalActive())
     829           0 :             ToggleTree();
     830           0 :         aGlobalTree.GrabFocus();
     831             :     }
     832             :     else
     833           0 :         aContentTree.GrabFocus();
     834           0 :     UsePage(0);
     835           0 :     aPageChgTimer.SetTimeoutHdl(LINK(this, SwNavigationPI, ChangePageHdl));
     836           0 :     aPageChgTimer.SetTimeout(PAGE_CHANGE_TIMEOUT);
     837             : 
     838           0 :     aContentTree.SetAccessibleName(SW_RESSTR(STR_ACCESS_TL_CONTENT));
     839           0 :     aGlobalTree.SetAccessibleName(SW_RESSTR(STR_ACCESS_TL_GLOBAL));
     840           0 :     aDocListBox.SetAccessibleName(aStatusArr[3]);
     841             : 
     842           0 :     if (pContextWin == NULL)
     843             :     {
     844             :         // When the context window is missing then the navigator is
     845             :         // displayed in the sidebar.  While the navigator could change
     846             :         // its size, the sidebar can not, and the navigator would just
     847             :         // waste space.  Therefore hide this button.
     848           0 :         aContentToolBox.RemoveItem(aContentToolBox.GetItemPos(FN_SHOW_CONTENT_BOX));
     849           0 :     }
     850           0 : }
     851             : 
     852           0 : SwNavigationPI::~SwNavigationPI()
     853             : {
     854           0 :     if(IsGlobalDoc() && !IsGlobalMode())
     855             :     {
     856           0 :         SwView *pView = GetCreateView();
     857           0 :         SwWrtShell &rSh = pView->GetWrtShell();
     858           0 :         if( !rSh.IsAllProtect() )
     859           0 :             pView->GetDocShell()->SetReadOnlyUI(false);
     860             :     }
     861             : 
     862           0 :     EndListening(*SFX_APP());
     863             : 
     864           0 :     SfxImageManager* pImgMan = SfxImageManager::GetImageManager( SW_MOD() );
     865           0 :     pImgMan->ReleaseToolBox(&aContentToolBox);
     866           0 :     pImgMan->ReleaseToolBox(&aGlobalToolBox);
     867           0 :     delete aContentToolBox.GetItemWindow(FN_PAGENUMBER);
     868           0 :     aContentToolBox.Clear();
     869           0 :     if(pxObjectShell)
     870             :     {
     871           0 :         if(pxObjectShell->Is())
     872           0 :             (*pxObjectShell)->DoClose();
     873           0 :         delete pxObjectShell;
     874             :     }
     875           0 :     delete pPopupWindow;
     876           0 :     delete pFloatingWindow;
     877             : 
     878           0 :     if ( IsBound() )
     879           0 :         rBindings.Release(*this);
     880           0 : }
     881             : 
     882           0 : void SwNavigationPI::SetPopupWindow( SfxPopupWindow* pWindow )
     883             : {
     884           0 :     pPopupWindow = pWindow;
     885           0 :     pPopupWindow->SetPopupModeEndHdl( LINK( this, SwNavigationPI, PopupModeEndHdl ));
     886           0 :     pPopupWindow->SetDeleteLink_Impl( LINK( this, SwNavigationPI, ClosePopupWindow ));
     887           0 : }
     888             : 
     889           0 : IMPL_LINK_NOARG(SwNavigationPI, PopupModeEndHdl)
     890             : {
     891           0 :     if ( pPopupWindow->IsVisible() )
     892             :     {
     893             :         // Replace floating window with popup window and destroy
     894             :         // floating window instance.
     895           0 :         delete pFloatingWindow;
     896           0 :         pFloatingWindow = pPopupWindow;
     897           0 :         pPopupWindow    = 0;
     898             :     }
     899             :     else
     900             :     {
     901             :         // Popup window has been closed by the user. No replacement, instance
     902             :         // will destroy itself.
     903           0 :         pPopupWindow = 0;
     904             :     }
     905             : 
     906           0 :     return 1;
     907             : }
     908             : 
     909           0 : IMPL_LINK( SwNavigationPI, ClosePopupWindow, SfxPopupWindow *, pWindow )
     910             : {
     911           0 :     if ( pWindow == pFloatingWindow )
     912           0 :         pFloatingWindow = 0;
     913             :     else
     914           0 :         pPopupWindow = 0;
     915             : 
     916           0 :     return 1;
     917             : }
     918             : 
     919           0 : void SwNavigationPI::StateChanged( sal_uInt16 nSID, SfxItemState /*eState*/,
     920             :                                             const SfxPoolItem* /*pState*/ )
     921             : {
     922           0 :     if(nSID == SID_DOCFULLNAME)
     923             :     {
     924           0 :         SwView *pActView = GetCreateView();
     925           0 :         if(pActView)
     926             :         {
     927           0 :             SwWrtShell* pWrtShell = pActView->GetWrtShellPtr();
     928           0 :             aContentTree.SetActiveShell(pWrtShell);
     929           0 :             sal_Bool bGlobal = IsGlobalDoc();
     930           0 :             aContentToolBox.EnableItem(FN_GLOBAL_SWITCH, bGlobal);
     931           0 :             if( (!bGlobal && IsGlobalMode()) ||
     932           0 :                     (!IsGlobalMode() && pConfig->IsGlobalActive()) )
     933             :             {
     934           0 :                 ToggleTree();
     935             :             }
     936           0 :             if(bGlobal)
     937             :             {
     938           0 :                 aGlobalToolBox.CheckItem(FN_GLOBAL_SAVE_CONTENT, pWrtShell->IsGlblDocSaveLinks());
     939             :             }
     940             :         }
     941             :         else
     942             :         {
     943           0 :             aContentTree.SetActiveShell(0);
     944             :         }
     945           0 :         UpdateListBox();
     946             :     }
     947           0 : }
     948             : 
     949             : // Get the numeric field from the toolbox.
     950             : 
     951           0 : NumEditAction& SwNavigationPI::GetPageEdit()
     952             : {
     953           0 :     return *(NumEditAction*)aContentToolBox.GetItemWindow(FN_PAGENUMBER);
     954             : }
     955             : 
     956           0 : SfxChildAlignment SwNavigationPI::CheckAlignment
     957             :     (
     958             :         SfxChildAlignment eActAlign,
     959             :         SfxChildAlignment eAlign
     960             :     )
     961             : {
     962             : SfxChildAlignment eRetAlign;
     963             : 
     964           0 :     if(_IsZoomedIn())
     965           0 :         eRetAlign = SFX_ALIGN_NOALIGNMENT;
     966             :     else
     967           0 :         switch (eAlign)
     968             :         {
     969             :             case SFX_ALIGN_BOTTOM:
     970             :             case SFX_ALIGN_LOWESTBOTTOM:
     971             :             case SFX_ALIGN_HIGHESTBOTTOM:
     972           0 :                 eRetAlign = eActAlign;
     973           0 :                 break;
     974             : 
     975             :             case SFX_ALIGN_TOP:
     976             :             case SFX_ALIGN_HIGHESTTOP:
     977             :             case SFX_ALIGN_LOWESTTOP:
     978             :             case SFX_ALIGN_LEFT:
     979             :             case SFX_ALIGN_RIGHT:
     980             :             case SFX_ALIGN_FIRSTLEFT:
     981             :             case SFX_ALIGN_LASTLEFT:
     982             :             case SFX_ALIGN_FIRSTRIGHT:
     983             :             case SFX_ALIGN_LASTRIGHT:
     984           0 :                 eRetAlign = eAlign;
     985           0 :                 break;
     986             : 
     987             :             default:
     988           0 :                 eRetAlign = eAlign;
     989           0 :                 break;
     990             :         }
     991           0 :     return eRetAlign;
     992             : 
     993             : }
     994             : 
     995             : // Notification on modified DocInfo
     996             : 
     997           0 : void SwNavigationPI::Notify( SfxBroadcaster& rBrdc, const SfxHint& rHint )
     998             : {
     999           0 :     if(&rBrdc == pCreateView)
    1000             :     {
    1001           0 :         if(rHint.ISA(SfxSimpleHint) && ((SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING)
    1002             :         {
    1003           0 :             pCreateView = 0;
    1004             :         }
    1005             :     }
    1006             :     else
    1007             :     {
    1008           0 :         if(rHint.ISA(SfxEventHint))
    1009             :         {
    1010           0 :             if( pxObjectShell &&
    1011           0 :                         ((SfxEventHint&) rHint).GetEventId() == SFX_EVENT_CLOSEAPP)
    1012             :             {
    1013           0 :                 DELETEZ(pxObjectShell);
    1014             :             }
    1015           0 :             else if(((SfxEventHint&) rHint).GetEventId() == SFX_EVENT_OPENDOC)
    1016             :             {
    1017             : 
    1018           0 :                 SwView *pActView = GetCreateView();
    1019           0 :                 if(pActView)
    1020             :                 {
    1021           0 :                     SwWrtShell* pWrtShell = pActView->GetWrtShellPtr();
    1022           0 :                     aContentTree.SetActiveShell(pWrtShell);
    1023           0 :                     if(aGlobalTree.IsVisible())
    1024             :                     {
    1025           0 :                         if(aGlobalTree.Update( sal_False ))
    1026           0 :                             aGlobalTree.Display();
    1027             :                         else
    1028             :                         // If no update is needed, then paint at least,
    1029             :                         // because of the red entries for the broken links.
    1030           0 :                             aGlobalTree.Invalidate();
    1031             :                     }
    1032             :                 }
    1033             :             }
    1034             :         }
    1035             :     }
    1036           0 : }
    1037             : 
    1038           0 : IMPL_LINK( SwNavigationPI, MenuSelectHdl, Menu *, pMenu )
    1039             : {
    1040           0 :     sal_uInt16 nMenuId = pMenu->GetCurItemId();
    1041           0 :     if(nMenuId != USHRT_MAX)
    1042             :     {
    1043           0 :         if(nMenuId < 100)
    1044           0 :             SetRegionDropMode( --nMenuId);
    1045             :         else
    1046           0 :             aContentTree.SetOutlineLevel( static_cast< sal_uInt8 >(nMenuId - 100) );
    1047             :     }
    1048           0 :     return 0;
    1049             : }
    1050             : 
    1051           0 : void SwNavigationPI::UpdateListBox()
    1052             : {
    1053           0 :     aDocListBox.SetUpdateMode(false);
    1054           0 :     aDocListBox.Clear();
    1055           0 :     SwView *pActView = GetCreateView();
    1056           0 :     bool bDisable = pActView == 0;
    1057           0 :     SwView *pView = SwModule::GetFirstView();
    1058           0 :     sal_uInt16 nCount = 0;
    1059           0 :     sal_uInt16 nAct = 0;
    1060           0 :     sal_uInt16 nConstPos = 0;
    1061           0 :     const SwView* pConstView = aContentTree.IsConstantView() &&
    1062           0 :                                 aContentTree.GetActiveWrtShell() ?
    1063           0 :                                     &aContentTree.GetActiveWrtShell()->GetView():
    1064           0 :                                         0;
    1065           0 :     while (pView)
    1066             :     {
    1067           0 :         SfxObjectShell* pDoc = pView->GetDocShell();
    1068             :         // #i53333# don't show help pages here
    1069           0 :         if ( !pDoc->IsHelpDocument() )
    1070             :         {
    1071           0 :             OUString sEntry = pDoc->GetTitle();
    1072           0 :             sEntry += " (";
    1073           0 :             if (pView == pActView)
    1074             :             {
    1075           0 :                 nAct = nCount;
    1076           0 :                 sEntry += aStatusArr[ST_ACTIVE - ST_STATUS_FIRST];
    1077             :             }
    1078             :             else
    1079           0 :                 sEntry += aStatusArr[ST_INACTIVE - ST_STATUS_FIRST];
    1080           0 :             sEntry += ")";
    1081           0 :             aDocListBox.InsertEntry(sEntry);
    1082             : 
    1083           0 :             if (pConstView && pView == pConstView)
    1084           0 :                 nConstPos = nCount;
    1085             : 
    1086           0 :             nCount++;
    1087             :         }
    1088           0 :         pView = SwModule::GetNextView(pView);
    1089             :     }
    1090           0 :     aDocListBox.InsertEntry(aStatusArr[3]); // "Active Window"
    1091           0 :     nCount++;
    1092             : 
    1093           0 :     if(aContentTree.GetHiddenWrtShell())
    1094             :     {
    1095           0 :         OUString sEntry = aContentTree.GetHiddenWrtShell()->GetView().
    1096           0 :                                         GetDocShell()->GetTitle();
    1097           0 :         sEntry += " (";
    1098           0 :         sEntry += aStatusArr[ST_HIDDEN - ST_STATUS_FIRST];
    1099           0 :         sEntry += ")";
    1100           0 :         aDocListBox.InsertEntry(sEntry);
    1101           0 :         bDisable = false;
    1102             :     }
    1103           0 :     if(aContentTree.IsActiveView())
    1104             :     {
    1105             :         //Either the name of the current Document or "Active Document".
    1106           0 :         sal_uInt16 nTmp = pActView ? nAct : --nCount;
    1107           0 :         aDocListBox.SelectEntryPos( nTmp );
    1108             :     }
    1109           0 :     else if(aContentTree.IsHiddenView())
    1110             :     {
    1111           0 :         aDocListBox.SelectEntryPos(nCount);
    1112             :     }
    1113             :     else
    1114           0 :         aDocListBox.SelectEntryPos(nConstPos);
    1115             : 
    1116           0 :     aDocListBox.Enable( !bDisable );
    1117           0 :     aDocListBox.SetUpdateMode(true);
    1118           0 : }
    1119             : 
    1120           0 : IMPL_LINK(SwNavigationPI, DoneLink, SfxPoolItem *, pItem)
    1121             : {
    1122           0 :     const SfxViewFrameItem* pFrameItem = PTR_CAST(SfxViewFrameItem, pItem );
    1123           0 :     if( pFrameItem )
    1124             :     {
    1125           0 :         SfxViewFrame* pFrame =  pFrameItem->GetFrame();
    1126           0 :         if(pFrame)
    1127             :         {
    1128           0 :             aContentTree.Clear();
    1129           0 :             pContentView = PTR_CAST(SwView, pFrame->GetViewShell());
    1130             :             OSL_ENSURE(pContentView, "no SwView");
    1131           0 :             if(pContentView)
    1132           0 :                 pContentWrtShell = pContentView->GetWrtShellPtr();
    1133             :             else
    1134           0 :                 pContentWrtShell = 0;
    1135           0 :             pxObjectShell = new SfxObjectShellLock(pFrame->GetObjectShell());
    1136           0 :             FillBox();
    1137           0 :             aContentTree.Update();
    1138             :         }
    1139             :     }
    1140           0 :     return 0;
    1141             : }
    1142             : 
    1143           0 : OUString SwNavigationPI::CreateDropFileName( TransferableDataHelper& rData )
    1144             : {
    1145           0 :     OUString sFileName;
    1146             :     sal_uLong nFmt;
    1147           0 :     if( rData.HasFormat( nFmt = FORMAT_FILE_LIST ))
    1148             :     {
    1149           0 :         FileList aFileList;
    1150           0 :         rData.GetFileList( nFmt, aFileList );
    1151           0 :         sFileName = aFileList.GetFile( 0 );
    1152             :     }
    1153           0 :     else if( rData.HasFormat( nFmt = FORMAT_STRING ) ||
    1154           0 :               rData.HasFormat( nFmt = FORMAT_FILE ) ||
    1155           0 :              rData.HasFormat( nFmt = SOT_FORMATSTR_ID_FILENAME ))
    1156           0 :         rData.GetString( nFmt, sFileName );
    1157           0 :     else if( rData.HasFormat( nFmt = SOT_FORMATSTR_ID_SOLK ) ||
    1158           0 :                 rData.HasFormat( nFmt = SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK )||
    1159           0 :                 rData.HasFormat( nFmt = SOT_FORMATSTR_ID_FILECONTENT ) ||
    1160           0 :                 rData.HasFormat( nFmt = SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) ||
    1161           0 :                 rData.HasFormat( nFmt = SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ))
    1162             :     {
    1163           0 :         INetBookmark aBkmk( aEmptyOUStr, aEmptyOUStr );
    1164           0 :         rData.GetINetBookmark( nFmt, aBkmk );
    1165           0 :         sFileName = aBkmk.GetURL();
    1166             :     }
    1167           0 :     if( !sFileName.isEmpty() )
    1168             :     {
    1169           0 :         sFileName = INetURLObject( sFileName ).GetMainURL( INetURLObject::NO_DECODE );
    1170             :     }
    1171           0 :     return sFileName;
    1172             : }
    1173             : 
    1174           0 : sal_Int8 SwNavigationPI::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
    1175             : {
    1176           0 :     return ( !aContentTree.IsInDrag() &&
    1177           0 :         ( aContentTree.IsDropFormatSupported( FORMAT_FILE ) ||
    1178           0 :           aContentTree.IsDropFormatSupported( FORMAT_STRING ) ||
    1179           0 :           aContentTree.IsDropFormatSupported( SOT_FORMATSTR_ID_SOLK ) ||
    1180           0 :            aContentTree.IsDropFormatSupported( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK )||
    1181           0 :            aContentTree.IsDropFormatSupported( SOT_FORMATSTR_ID_FILECONTENT ) ||
    1182           0 :            aContentTree.IsDropFormatSupported( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) ||
    1183           0 :            aContentTree.IsDropFormatSupported( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) ||
    1184           0 :            aContentTree.IsDropFormatSupported( SOT_FORMATSTR_ID_FILENAME )))
    1185             :         ? DND_ACTION_COPY
    1186           0 :         : DND_ACTION_NONE;
    1187             : }
    1188             : 
    1189           0 : sal_Int8 SwNavigationPI::ExecuteDrop( const ExecuteDropEvent& rEvt )
    1190             : {
    1191           0 :     TransferableDataHelper aData( rEvt.maDropEvent.Transferable );
    1192           0 :     sal_Int8 nRet = DND_ACTION_NONE;
    1193           0 :     OUString sFileName;
    1194           0 :     if( !aContentTree.IsInDrag() &&
    1195           0 :         !(sFileName = SwNavigationPI::CreateDropFileName( aData )).isEmpty() )
    1196             :     {
    1197           0 :         INetURLObject aTemp( sFileName );
    1198           0 :         GraphicDescriptor aDesc( aTemp );
    1199           0 :         if( !aDesc.Detect() )   // accept no graphics
    1200             :         {
    1201           0 :             if( -1 == sFileName.indexOf('#')
    1202           0 :                 && (sContentFileName.isEmpty() || sContentFileName != sFileName ))
    1203             :             {
    1204           0 :                 nRet = rEvt.mnAction;
    1205           0 :                 sFileName = comphelper::string::stripEnd(sFileName, 0);
    1206           0 :                 sContentFileName = sFileName;
    1207           0 :                 if(pxObjectShell)
    1208             :                 {
    1209           0 :                     aContentTree.SetHiddenShell( 0 );
    1210           0 :                     (*pxObjectShell)->DoClose();
    1211           0 :                     DELETEZ( pxObjectShell);
    1212             :                 }
    1213           0 :                 SfxStringItem aFileItem(SID_FILE_NAME, sFileName );
    1214           0 :                 SfxStringItem aOptionsItem( SID_OPTIONS, OUString("HRC") );
    1215             :                 SfxLinkItem aLink( SID_DONELINK,
    1216           0 :                                     LINK( this, SwNavigationPI, DoneLink ) );
    1217           0 :                 GetActiveView()->GetViewFrame()->GetDispatcher()->Execute(
    1218             :                             SID_OPENDOC, SFX_CALLMODE_ASYNCHRON,
    1219           0 :                             &aFileItem, &aOptionsItem, &aLink, 0L );
    1220             :             }
    1221           0 :         }
    1222             :     }
    1223           0 :     return nRet;
    1224             : }
    1225             : 
    1226           0 : void SwNavigationPI::SetRegionDropMode(sal_uInt16 nNewMode)
    1227             : {
    1228           0 :     nRegionMode = nNewMode;
    1229           0 :     pConfig->SetRegionMode( nRegionMode );
    1230             : 
    1231           0 :     sal_uInt16 nDropId = FN_DROP_REGION;
    1232           0 :     if(nRegionMode == REGION_MODE_LINK)
    1233           0 :         nDropId = FN_DROP_REGION_LINK;
    1234           0 :     else if(nRegionMode == REGION_MODE_EMBEDDED)
    1235           0 :         nDropId = FN_DROP_REGION_COPY;
    1236             : 
    1237           0 :     ImageList& rImgLst = aContentImageList;
    1238             : 
    1239           0 :     aContentToolBox.SetItemImage( FN_DROP_REGION, rImgLst.GetImage(nDropId));
    1240           0 : }
    1241             : 
    1242           0 : sal_Bool    SwNavigationPI::ToggleTree()
    1243             : {
    1244           0 :     sal_Bool bRet = sal_True;
    1245           0 :     sal_Bool bGlobalDoc = IsGlobalDoc();
    1246           0 :     if(!IsGlobalMode() && bGlobalDoc)
    1247             :     {
    1248           0 :         SetUpdateMode(false);
    1249           0 :         if(_IsZoomedIn())
    1250           0 :             _ZoomOut();
    1251           0 :         aGlobalTree.ShowTree();
    1252           0 :         aGlobalToolBox.Show();
    1253           0 :         aContentTree.HideTree();
    1254           0 :         aContentToolBox.Hide();
    1255           0 :         aDocListBox.Hide();
    1256           0 :         SetGlobalMode(sal_True);
    1257           0 :         SetUpdateMode(true);
    1258             :     }
    1259             :     else
    1260             :     {
    1261           0 :         aGlobalTree.HideTree();
    1262           0 :         aGlobalToolBox.Hide();
    1263           0 :         if(!_IsZoomedIn())
    1264             :         {
    1265           0 :             aContentTree.ShowTree();
    1266           0 :             aContentToolBox.Show();
    1267           0 :             aDocListBox.Show();
    1268             :         }
    1269           0 :         bRet = sal_False;
    1270           0 :         SetGlobalMode(sal_False);
    1271             :     }
    1272           0 :     return bRet;
    1273             : }
    1274             : 
    1275           0 : sal_Bool    SwNavigationPI::IsGlobalDoc() const
    1276             : {
    1277           0 :     sal_Bool bRet = sal_False;
    1278           0 :     SwView *pView = GetCreateView();
    1279           0 :     if(pView)
    1280             :     {
    1281           0 :         SwWrtShell &rSh = pView->GetWrtShell();
    1282           0 :         bRet = rSh.IsGlobalDoc();
    1283             :     }
    1284           0 :     return bRet;
    1285             : }
    1286             : 
    1287           0 : IMPL_LINK_NOARG(SwNavigationPI, ChangePageHdl)
    1288             : {
    1289           0 :     EditAction(&GetPageEdit());
    1290           0 :     GetPageEdit().GrabFocus();
    1291           0 :     return 0;
    1292             : }
    1293             : 
    1294           0 : IMPL_LINK_NOARG(SwNavigationPI, PageEditModifyHdl)
    1295             : {
    1296           0 :     if(aPageChgTimer.IsActive())
    1297           0 :         aPageChgTimer.Stop();
    1298           0 :     aPageChgTimer.Start();
    1299           0 :     return 0;
    1300             : }
    1301             : 
    1302           0 : SwView*  SwNavigationPI::GetCreateView() const
    1303             : {
    1304           0 :     if(!pCreateView)
    1305             :     {
    1306           0 :         SwView* pView = SwModule::GetFirstView();
    1307           0 :         while(pView)
    1308             :         {
    1309           0 :             if(&pView->GetViewFrame()->GetBindings() == &rBindings)
    1310             :             {
    1311           0 :                 ((SwNavigationPI*)this)->pCreateView = pView;
    1312           0 :                 ((SwNavigationPI*)this)->StartListening(*pCreateView);
    1313           0 :                 break;
    1314             :             }
    1315           0 :             pView = SwModule::GetNextView(pView);
    1316             :         }
    1317             :     }
    1318           0 :     return pCreateView;
    1319             : }
    1320             : 
    1321           0 : SwNavigationChild::SwNavigationChild( Window* pParent,
    1322             :                         sal_uInt16 nId,
    1323             :                         SfxBindings* _pBindings,
    1324             :                         SfxChildWinInfo* )
    1325           0 :     : SfxChildWindowContext( nId )
    1326             : {
    1327           0 :     SwNavigationPI* pNavi  = new SwNavigationPI( _pBindings, this, pParent );
    1328           0 :     SetWindow( pNavi );
    1329           0 :     _pBindings->Invalidate(SID_NAVIGATOR);
    1330             : 
    1331           0 :     SwNavigationConfig* pNaviConfig = SW_MOD()->GetNavigationConfig();
    1332             : 
    1333           0 :     sal_uInt16 nRootType = static_cast< sal_uInt16 >( pNaviConfig->GetRootType() );
    1334           0 :     if( nRootType < CONTENT_TYPE_MAX )
    1335             :     {
    1336           0 :         pNavi->aContentTree.SetRootType(nRootType);
    1337           0 :         pNavi->aContentToolBox.CheckItem(FN_SHOW_ROOT, true);
    1338             :     }
    1339           0 :     pNavi->aContentTree.SetOutlineLevel( static_cast< sal_uInt8 >( pNaviConfig->GetOutlineLevel() ) );
    1340           0 :     pNavi->SetRegionDropMode( static_cast< sal_uInt16 >( pNaviConfig->GetRegionMode() ) );
    1341             : 
    1342           0 :     if(GetFloatingWindow() && pNaviConfig->IsSmall())
    1343             :     {
    1344           0 :         pNavi->_ZoomIn();
    1345             :     }
    1346           0 : }
    1347             : 
    1348           0 : void SwNavigationPI::DataChanged( const DataChangedEvent& rDCEvt )
    1349             : {
    1350           0 :     Window::DataChanged( rDCEvt );
    1351           0 :     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
    1352           0 :          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
    1353             :     {
    1354           0 :         InitImageList();
    1355           0 :         const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
    1356           0 :         Color aBgColor = rStyleSettings.GetFaceColor();
    1357           0 :         Wallpaper aBack( aBgColor );
    1358           0 :         SetBackground( aBack );
    1359             :     }
    1360           0 : }
    1361             : 
    1362           0 : void SwNavigationPI::InitImageList()
    1363             : {
    1364             :     sal_uInt16 k;
    1365             : 
    1366           0 :     ImageList& rImgLst = aContentImageList;
    1367           0 :     for( k = 0; k < aContentToolBox.GetItemCount(); k++)
    1368           0 :             aContentToolBox.SetItemImage(aContentToolBox.GetItemId(k),
    1369           0 :                     rImgLst.GetImage(aContentToolBox.GetItemId(k)));
    1370             : 
    1371           0 :     for( k = 0; k < aGlobalToolBox.GetItemCount(); k++)
    1372           0 :             aGlobalToolBox.SetItemImage(aGlobalToolBox.GetItemId(k),
    1373           0 :                     rImgLst.GetImage(aGlobalToolBox.GetItemId(k)));
    1374             : 
    1375           0 :     sal_uInt16 nDropId = FN_DROP_REGION;
    1376           0 :     if(nRegionMode == REGION_MODE_LINK)
    1377           0 :         nDropId = FN_DROP_REGION_LINK;
    1378           0 :     else if(nRegionMode == REGION_MODE_EMBEDDED)
    1379           0 :         nDropId = FN_DROP_REGION_COPY;
    1380             :     aContentToolBox.SetItemImage( FN_DROP_REGION,
    1381           0 :                                     rImgLst.GetImage(nDropId));
    1382           0 : }
    1383             : 
    1384             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10