LCOV - code coverage report
Current view: top level - sd/source/ui/func - fuolbull.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 169 0.6 %
Date: 2014-11-03 Functions: 2 12 16.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 "fuolbull.hxx"
      21             : #include <vcl/msgbox.hxx>
      22             : #include <svl/intitem.hxx>
      23             : #include <editeng/outliner.hxx>
      24             : #include <editeng/eeitem.hxx>
      25             : #include <sfx2/request.hxx>
      26             : #include <editeng/numitem.hxx>
      27             : #include "sdresid.hxx"
      28             : #include "glob.hrc"
      29             : 
      30             : #include <editeng/editdata.hxx>
      31             : #include <svx/svxids.hrc>
      32             : #include "OutlineView.hxx"
      33             : #include "OutlineViewShell.hxx"
      34             : #include "DrawViewShell.hxx"
      35             : #include "Window.hxx"
      36             : #include "drawdoc.hxx"
      37             : #include "sdabstdlg.hxx"
      38             : #include <svx/nbdtmg.hxx>
      39             : #include <svx/nbdtmgfact.hxx>
      40             : #include <svx/svdoutl.hxx>
      41             : #include <boost/scoped_ptr.hpp>
      42             : using namespace svx::sidebar;
      43             : namespace sd {
      44             : 
      45           0 : TYPEINIT1( FuOutlineBullet, FuPoor );
      46             : 
      47           0 : FuOutlineBullet::FuOutlineBullet(ViewShell* pViewShell, ::sd::Window* pWindow,
      48             :                                  ::sd::View* pView, SdDrawDocument* pDoc,
      49             :                                  SfxRequest& rReq)
      50           0 :        : FuPoor(pViewShell, pWindow, pView, pDoc, rReq)
      51             : {
      52           0 : }
      53             : 
      54           0 : rtl::Reference<FuPoor> FuOutlineBullet::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
      55             : {
      56           0 :     rtl::Reference<FuPoor> xFunc( new FuOutlineBullet( pViewSh, pWin, pView, pDoc, rReq ) );
      57           0 :     xFunc->DoExecute(rReq);
      58           0 :     return xFunc;
      59             : }
      60             : 
      61           0 : void FuOutlineBullet::DoExecute( SfxRequest& rReq )
      62             : {
      63           0 :     const sal_uInt16 nSId = rReq.GetSlot();
      64           0 :     if ( nSId == FN_SVX_SET_BULLET || nSId == FN_SVX_SET_NUMBER )
      65             :     {
      66           0 :         SetCurrentBulletsNumbering(rReq);
      67           0 :         return;
      68             :     }
      69             : 
      70           0 :     const SfxItemSet* pArgs = rReq.GetArgs();
      71             : 
      72           0 :     if( !pArgs )
      73             :     {
      74             :         // fill ItemSet for Dialog
      75           0 :         SfxItemSet aEditAttr( mpDoc->GetPool() );
      76           0 :         mpView->GetAttributes( aEditAttr );
      77             : 
      78           0 :         SfxItemSet aNewAttr( mpViewShell->GetPool(),
      79           0 :                              EE_ITEMS_START, EE_ITEMS_END );
      80           0 :         aNewAttr.Put( aEditAttr, false );
      81             : 
      82             :         // create and execute dialog
      83           0 :         SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
      84           0 :         boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact ? pFact->CreateSdOutlineBulletTabDlg( NULL, &aNewAttr, mpView ) : 0);
      85           0 :         if( pDlg )
      86             :         {
      87           0 :             sal_uInt16 nResult = pDlg->Execute();
      88             : 
      89           0 :             switch( nResult )
      90             :             {
      91             :                 case RET_OK:
      92             :                 {
      93           0 :                     SfxItemSet aSet( *pDlg->GetOutputItemSet() );
      94             : 
      95           0 :                     OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
      96             : 
      97           0 :                     boost::scoped_ptr< OutlineViewModelChangeGuard > aGuard;
      98             : 
      99           0 :                     if (mpView->ISA(OutlineView))
     100             :                     {
     101             :                         pOLV = static_cast<OutlineView*>(mpView)
     102           0 :                             ->GetViewByWindow(mpViewShell->GetActiveWindow());
     103             : 
     104           0 :                         aGuard.reset( new OutlineViewModelChangeGuard( static_cast<OutlineView&>(*mpView) ) );
     105             :                     }
     106             : 
     107           0 :                     if( pOLV )
     108           0 :                         pOLV->EnableBullets();
     109             : 
     110           0 :                     rReq.Done( aSet );
     111           0 :                     pArgs = rReq.GetArgs();
     112             :                 }
     113           0 :                 break;
     114             : 
     115             :                 default:
     116           0 :                     return;
     117             :             }
     118           0 :         }
     119             :     }
     120             : 
     121             :     /* not direct to pOlView; therefore, SdDrawView::SetAttributes can catch
     122             :        changes to master page and redirect to a template */
     123           0 :     mpView->SetAttributes(*pArgs);
     124             : 
     125             : /* #i35937#
     126             :     // invalidate possible affected fields
     127             :     mpViewShell->Invalidate( FN_NUM_BULLET_ON );
     128             : */
     129             : }
     130             : 
     131           0 : void FuOutlineBullet::SetCurrentBulletsNumbering(SfxRequest& rReq)
     132             : {
     133           0 :     if (!mpDoc || !mpView)
     134           0 :         return;
     135             : 
     136           0 :     const sal_uInt16 nSId = rReq.GetSlot();
     137           0 :     if ( nSId != FN_SVX_SET_BULLET && nSId != FN_SVX_SET_NUMBER )
     138             :     {
     139             :         // unexpected SfxRequest
     140           0 :         return;
     141             :     }
     142             : 
     143           0 :     SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, nSId, false );
     144           0 :     if ( !pItem )
     145             :     {
     146           0 :         rReq.Done();
     147           0 :         return;
     148             :     }
     149             : 
     150           0 :     SfxItemSet aNewAttr( mpViewShell->GetPool(), EE_ITEMS_START, EE_ITEMS_END );
     151             :     {
     152           0 :         SfxItemSet aEditAttr( mpDoc->GetPool() );
     153           0 :         mpView->GetAttributes( aEditAttr );
     154           0 :         aNewAttr.Put( aEditAttr, false );
     155             :     }
     156             : 
     157           0 :     const DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >(mpViewShell);
     158             :     //Init bullet level in "Customize" tab page in bullet dialog in master page view
     159           0 :     const bool bInMasterView = pDrawViewShell && pDrawViewShell->GetEditMode() == EM_MASTERPAGE;
     160           0 :     if ( bInMasterView )
     161             :     {
     162           0 :         SdrObject* pObj = mpView->GetTextEditObject();
     163           0 :         if( pObj && pObj->GetObjIdentifier() == OBJ_OUTLINETEXT )
     164             :         {
     165           0 :             const sal_uInt16 nLevel = mpView->GetSelectionLevel();
     166           0 :             if( nLevel != 0xFFFF )
     167             :             {
     168             :                 //save the itemset value
     169           0 :                 SfxItemSet aStoreSet( aNewAttr );
     170           0 :                 aNewAttr.ClearItem();
     171             :                 //extend range
     172           0 :                 aNewAttr.MergeRange( SID_PARAM_NUM_PRESET, SID_PARAM_CUR_NUM_LEVEL );
     173           0 :                 aNewAttr.Put( aStoreSet );
     174             :                 //put current level user selected
     175           0 :                 aNewAttr.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ) );
     176             :             }
     177             :         }
     178             :     }
     179             : 
     180           0 :     sal_uInt16 nIdx = pItem->GetValue();
     181           0 :     bool bToggle = false;
     182           0 :     bool bSwitchOff = false;
     183           0 :     if( nIdx == (sal_uInt16)0xFFFF )
     184             :     {
     185             :         // If the nIdx is (sal_uInt16)0xFFFF, means set bullet status to on/off
     186           0 :         nIdx = 1;
     187           0 :         bToggle = true;
     188             :     }
     189           0 :     else if (nIdx == DEFAULT_NONE)
     190             :     {
     191           0 :         bSwitchOff = true;
     192             :     }
     193           0 :     nIdx--;
     194             : 
     195           0 :     sal_uInt32 nNumItemId = SID_ATTR_NUMBERING_RULE;
     196           0 :     const SfxPoolItem* pTmpItem = GetNumBulletItem( aNewAttr, nNumItemId );
     197           0 :     SvxNumRule* pNumRule = NULL;
     198           0 :     if ( pTmpItem )
     199             :     {
     200           0 :         pNumRule = new SvxNumRule(*((SvxNumBulletItem*)pTmpItem)->GetNumRule());
     201             : 
     202             :         // get numbering rule corresponding to <nIdx> and apply the needed number formats to <pNumRule>
     203             :         NBOTypeMgrBase* pNumRuleMgr =
     204             :             NBOutlineTypeMgrFact::CreateInstance(
     205           0 :                 nSId == FN_SVX_SET_BULLET ? eNBOType::MIXBULLETS : eNBOType::NUMBERING );
     206           0 :         if ( pNumRuleMgr )
     207             :         {
     208           0 :             sal_uInt16 nActNumLvl = (sal_uInt16)0xFFFF;
     209           0 :             const SfxPoolItem* pNumLevelItem = NULL;
     210           0 :             if(SfxItemState::SET == aNewAttr.GetItemState(SID_PARAM_CUR_NUM_LEVEL, false, &pNumLevelItem))
     211           0 :                 nActNumLvl = ((const SfxUInt16Item*)pNumLevelItem)->GetValue();
     212             : 
     213           0 :             pNumRuleMgr->SetItems(&aNewAttr);
     214           0 :             SvxNumRule aTmpRule( *pNumRule );
     215           0 :             if ( nSId == FN_SVX_SET_BULLET && bToggle && nIdx==0 )
     216             :             {
     217             :                 // for toggling bullets get default numbering rule
     218           0 :                 pNumRuleMgr->ApplyNumRule( aTmpRule, nIdx, nActNumLvl, true );
     219             :             }
     220             :             else
     221             :             {
     222           0 :                 pNumRuleMgr->ApplyNumRule( aTmpRule, nIdx, nActNumLvl );
     223             :             }
     224             : 
     225           0 :             sal_uInt16 nMask = 1;
     226           0 :             for(sal_uInt16 i = 0; i < pNumRule->GetLevelCount(); i++)
     227             :             {
     228           0 :                 if(nActNumLvl & nMask)
     229             :                 {
     230           0 :                     SvxNumberFormat aFmt(aTmpRule.GetLevel(i));
     231           0 :                     pNumRule->SetLevel(i, aFmt);
     232             :                 }
     233           0 :                 nMask <<= 1;
     234           0 :             }
     235             :         }
     236             :     }
     237             : 
     238           0 :     OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
     239           0 :     boost::scoped_ptr< OutlineViewModelChangeGuard > aGuard;
     240             :     {
     241           0 :         if (mpView->ISA(OutlineView))
     242             :         {
     243             :             pOLV = static_cast<OutlineView*>(mpView)
     244           0 :                 ->GetViewByWindow(mpViewShell->GetActiveWindow());
     245             : 
     246           0 :             aGuard.reset( new OutlineViewModelChangeGuard( static_cast<OutlineView&>(*mpView) ) );
     247             :         }
     248             :     }
     249             : 
     250           0 :     SdrOutliner* pOwner = bInMasterView ? mpView->GetTextEditOutliner() : 0;
     251           0 :     const bool bOutlinerUndoEnabled = pOwner && !pOwner->IsInUndo() && pOwner->IsUndoEnabled();
     252           0 :     SdrModel* pSdrModel = bInMasterView ? mpView->GetModel() : 0;
     253           0 :     const bool bModelUndoEnabled = pSdrModel && pSdrModel->IsUndoEnabled();
     254             : 
     255           0 :     if ( bOutlinerUndoEnabled )
     256             :     {
     257           0 :         pOwner->UndoActionStart( OLUNDO_ATTR );
     258             :     }
     259           0 :     else if ( bModelUndoEnabled )
     260             :     {
     261           0 :         pSdrModel->BegUndo();
     262             :     }
     263             : 
     264           0 :     if ( pOLV )
     265             :     {
     266           0 :         if ( bSwitchOff )
     267             :         {
     268           0 :             pOLV->SwitchOffBulletsNumbering( true );
     269             :         }
     270             :         else
     271             :         {
     272           0 :             pOLV->ToggleBulletsNumbering( bToggle, nSId == FN_SVX_SET_BULLET, bInMasterView ? 0 : pNumRule );
     273             :         }
     274             :     }
     275             :     else
     276             :     {
     277           0 :         mpView->ChangeMarkedObjectsBulletsNumbering( bToggle, nSId == FN_SVX_SET_BULLET, bInMasterView ? 0 : pNumRule, bSwitchOff );
     278             :     }
     279           0 :     if ( bInMasterView )
     280             :     {
     281           0 :         SfxItemSet aSetAttr( mpViewShell->GetPool(), EE_ITEMS_START, EE_ITEMS_END );
     282           0 :         aSetAttr.Put(SvxNumBulletItem( *pNumRule ), nNumItemId);
     283           0 :         mpView->SetAttributes(aSetAttr);
     284             :     }
     285             : 
     286           0 :     if( bOutlinerUndoEnabled )
     287             :     {
     288           0 :         pOwner->UndoActionEnd( OLUNDO_ATTR );
     289             :     }
     290           0 :     else if ( bModelUndoEnabled )
     291             :     {
     292           0 :         pSdrModel->EndUndo();
     293             :     }
     294             : 
     295           0 :     delete pNumRule;
     296           0 :     rReq.Done();
     297             : }
     298             : 
     299           0 : const SfxPoolItem* FuOutlineBullet::GetNumBulletItem(SfxItemSet& aNewAttr, sal_uInt32& nNumItemId)
     300             : {
     301             :     //SvxNumBulletItem* pRetItem = NULL;
     302           0 :     const SfxPoolItem* pTmpItem = NULL;
     303             : 
     304           0 :     if(aNewAttr.GetItemState(nNumItemId, false, &pTmpItem) == SfxItemState::SET)
     305             :     {
     306           0 :         return pTmpItem;
     307             :     }
     308             :     else
     309             :     {
     310           0 :         nNumItemId = aNewAttr.GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE);
     311           0 :         SfxItemState eState = aNewAttr.GetItemState(nNumItemId, false, &pTmpItem);
     312           0 :         if (eState == SfxItemState::SET)
     313           0 :             return pTmpItem;
     314             :         else
     315             :         {
     316           0 :             bool bOutliner = false;
     317           0 :             bool bTitle = false;
     318             : 
     319           0 :             if( mpView )
     320             :             {
     321           0 :                 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
     322           0 :                 const size_t nCount = rMarkList.GetMarkCount();
     323             : 
     324           0 :                 for(size_t nNum = 0; nNum < nCount; ++nNum)
     325             :                 {
     326           0 :                     SdrObject* pObj = rMarkList.GetMark(nNum)->GetMarkedSdrObj();
     327           0 :                     if( pObj->GetObjInventor() == SdrInventor )
     328             :                     {
     329           0 :                         switch(pObj->GetObjIdentifier())
     330             :                         {
     331             :                         case OBJ_TITLETEXT:
     332           0 :                             bTitle = true;
     333           0 :                             break;
     334             :                         case OBJ_OUTLINETEXT:
     335           0 :                             bOutliner = true;
     336           0 :                             break;
     337             :                         }
     338             :                     }
     339             :                 }
     340             :             }
     341             : 
     342           0 :             const SvxNumBulletItem *pItem = NULL;
     343           0 :             if(bOutliner)
     344             :             {
     345           0 :                 SfxStyleSheetBasePool* pSSPool = mpView->GetDocSh()->GetStyleSheetPool();
     346           0 :                 OUString aStyleName(SD_RESSTR(STR_LAYOUT_OUTLINE) + " 1");
     347           0 :                 SfxStyleSheetBase* pFirstStyleSheet = pSSPool->Find( aStyleName, SD_STYLE_FAMILY_PSEUDO);
     348           0 :                 if( pFirstStyleSheet )
     349           0 :                     pFirstStyleSheet->GetItemSet().GetItemState(EE_PARA_NUMBULLET, false, (const SfxPoolItem**)&pItem);
     350             :             }
     351             : 
     352           0 :             if( pItem == NULL )
     353           0 :                 pItem = (SvxNumBulletItem*) aNewAttr.GetPool()->GetSecondaryPool()->GetPoolDefaultItem(EE_PARA_NUMBULLET);
     354             : 
     355             :             //DBG_ASSERT( pItem, "No EE_PARA_NUMBULLET in the Pool!" );
     356             : 
     357           0 :             aNewAttr.Put(*pItem, EE_PARA_NUMBULLET);
     358             : 
     359           0 :             if(bTitle && aNewAttr.GetItemState(EE_PARA_NUMBULLET,true) == SfxItemState::SET )
     360             :             {
     361           0 :                 SvxNumBulletItem* pBulletItem = (SvxNumBulletItem*)aNewAttr.GetItem(EE_PARA_NUMBULLET,true);
     362           0 :                 SvxNumRule* pLclRule = pBulletItem->GetNumRule();
     363           0 :                 if(pLclRule)
     364             :                 {
     365           0 :                     SvxNumRule aNewRule( *pLclRule );
     366           0 :                     aNewRule.SetFeatureFlag( NUM_NO_NUMBERS, true );
     367             : 
     368           0 :                     SvxNumBulletItem aNewItem( aNewRule, EE_PARA_NUMBULLET );
     369           0 :                     aNewAttr.Put(aNewItem);
     370             :                 }
     371             :             }
     372             : 
     373           0 :             SfxItemState eItemState = aNewAttr.GetItemState(nNumItemId, false, &pTmpItem);
     374           0 :             if (eItemState == SfxItemState::SET)
     375           0 :                 return pTmpItem;
     376             : 
     377             :         }
     378             :         //DBG_ASSERT(eState == SfxItemState::SET, "No item found");
     379             :     }
     380           0 :     return pTmpItem;
     381             : }
     382             : 
     383         114 : } // end of namespace sd
     384             : 
     385             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10