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

Generated by: LCOV version 1.10