LCOV - code coverage report
Current view: top level - sw/source/uibase/shells - txtnum.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 142 0.7 %
Date: 2015-06-13 12:38:46 Functions: 2 4 50.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 <hintids.hxx>
      21             : #include <vcl/msgbox.hxx>
      22             : #include <sfx2/request.hxx>
      23             : #include <svl/eitem.hxx>
      24             : #include <svl/stritem.hxx>
      25             : #include <editeng/numitem.hxx>
      26             : #include <editeng/brushitem.hxx>
      27             : #include <numrule.hxx>
      28             : 
      29             : #include "cmdid.h"
      30             : #include "wrtsh.hxx"
      31             : #include "view.hxx"
      32             : #include "viewopt.hxx"
      33             : #include "wdocsh.hxx"
      34             : #include "textsh.hxx"
      35             : #include "uiitems.hxx"
      36             : #include "swabstdlg.hxx"
      37             : #include <globals.hrc>
      38             : #include <sfx2/tabdlg.hxx>
      39             : #include <svx/nbdtmg.hxx>
      40             : #include <svx/nbdtmgfact.hxx>
      41             : #include <sfx2/viewfrm.hxx>
      42             : #include <sfx2/bindings.hxx>
      43             : #include <boost/scoped_ptr.hpp>
      44             : 
      45           0 : void SwTextShell::ExecEnterNum(SfxRequest &rReq)
      46             : {
      47             :     //Because the record before any shell exchange.
      48           0 :     switch(rReq.GetSlot())
      49             :     {
      50             :     case FN_NUM_NUMBERING_ON:
      51             :     {
      52           0 :         GetShell().StartAllAction();
      53           0 :         SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , false );
      54           0 :         bool bMode = !GetShell().SelectionHasNumber(); // #i29560#
      55           0 :         if ( pItem )
      56           0 :             bMode = pItem->GetValue();
      57             :         else
      58           0 :             rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
      59             : 
      60           0 :         if ( bMode != (GetShell().SelectionHasNumber()) ) // #i29560#
      61             :         {
      62           0 :             rReq.Done();
      63           0 :             if( bMode )
      64           0 :                 GetShell().NumOn();
      65             :             else
      66           0 :                 GetShell().NumOrBulletOff(); // #i29560#
      67             :         }
      68           0 :         bool bNewResult = GetShell().SelectionHasNumber();
      69           0 :         if (bNewResult!=bMode) {
      70           0 :             SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
      71           0 :             SfxBoolItem aItem(FN_NUM_NUMBERING_ON,!bNewResult);
      72           0 :             rBindings.SetState(aItem);
      73           0 :             SfxBoolItem aNewItem(FN_NUM_NUMBERING_ON,bNewResult);
      74           0 :             rBindings.SetState(aNewItem);
      75             :         }
      76           0 :         GetShell().EndAllAction();
      77             :     }
      78           0 :     break;
      79             :     case FN_NUM_BULLET_ON:
      80             :     {
      81           0 :         GetShell().StartAllAction();
      82           0 :         SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , false );
      83           0 :         bool bMode = !GetShell().SelectionHasBullet(); // #i29560#
      84           0 :         if ( pItem )
      85           0 :             bMode = pItem->GetValue();
      86             :         else
      87           0 :             rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
      88             : 
      89           0 :         if ( bMode != (GetShell().SelectionHasBullet()) ) // #i29560#
      90             :         {
      91           0 :             rReq.Done();
      92           0 :             if( bMode )
      93           0 :                 GetShell().BulletOn();
      94             :             else
      95           0 :                 GetShell().NumOrBulletOff(); // #i29560#
      96             :         }
      97           0 :         bool bNewResult = GetShell().SelectionHasBullet();
      98           0 :         if (bNewResult!=bMode) {
      99           0 :             SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
     100           0 :             SfxBoolItem aItem(FN_NUM_BULLET_ON,!bNewResult);
     101           0 :             rBindings.SetState(aItem);
     102           0 :             SfxBoolItem aNewItem(FN_NUM_BULLET_ON,bNewResult);
     103           0 :             rBindings.SetState(aNewItem);
     104             :         }
     105           0 :         GetShell().EndAllAction();
     106             :     }
     107           0 :     break;
     108             : 
     109             :     case FN_NUMBER_BULLETS:
     110             :     case SID_OUTLINE_BULLET:
     111             :     {
     112           0 :         SfxItemSet aSet( GetPool(),
     113             :                          SID_HTML_MODE, SID_HTML_MODE,
     114             :                          SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
     115           0 :                          0 );
     116           0 :         SwDocShell* pDocSh = GetView().GetDocShell();
     117           0 :         const bool bHtml = 0 != PTR_CAST( SwWebDocShell, pDocSh );
     118           0 :         const SwNumRule* pNumRuleAtCurrentSelection = GetShell().GetNumRuleAtCurrentSelection();
     119           0 :         if ( pNumRuleAtCurrentSelection != NULL )
     120             :         {
     121           0 :             SvxNumRule aRule = pNumRuleAtCurrentSelection->MakeSvxNumRule();
     122             : 
     123             :             //convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
     124           0 :             for ( sal_uInt16 i = 0; i < aRule.GetLevelCount(); i++ )
     125             :             {
     126           0 :                 SvxNumberFormat aFormat( aRule.GetLevel( i ) );
     127           0 :                 if ( SVX_NUM_BITMAP == aFormat.GetNumberingType() )
     128             :                 {
     129           0 :                     const SvxBrushItem* pBrush = aFormat.GetBrush();
     130           0 :                     if(pBrush && !pBrush->GetGraphicLink().isEmpty())
     131           0 :                         aFormat.SetNumberingType(SvxExtNumType(SVX_NUM_BITMAP|LINK_TOKEN));
     132           0 :                     aRule.SetLevel(i, aFormat, aRule.Get(i) != 0);
     133             :                 }
     134           0 :             }
     135           0 :             if(bHtml)
     136           0 :                 aRule.SetFeatureFlag(SvxNumRuleFlags::ENABLE_EMBEDDED_BMP, false);
     137             : 
     138           0 :             aSet.Put(SvxNumBulletItem(aRule));
     139             :             OSL_ENSURE( GetShell().GetNumLevel() < MAXLEVEL,
     140             :                     "<SwTextShell::ExecEnterNum()> - numbered node without valid list level. Serious defect -> please inform OD." );
     141           0 :             sal_uInt16 nLevel = GetShell().GetNumLevel();
     142           0 :             if( nLevel < MAXLEVEL )
     143             :             {
     144           0 :                 nLevel = 1 << nLevel;
     145           0 :                 aSet.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ) );
     146           0 :             }
     147             :         }
     148             :         else
     149             :         {
     150           0 :             SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
     151             :                              // #i89178#
     152           0 :                              numfunc::GetDefaultPositionAndSpaceMode() );
     153           0 :             SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
     154           0 :             const bool bRightToLeft = GetShell().IsInRightToLeftText( 0 );
     155             : 
     156           0 :             if ( bHtml || bRightToLeft )
     157             :             {
     158           0 :                 for ( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
     159             :                 {
     160           0 :                     SvxNumberFormat aFormat( aSvxRule.GetLevel( n ) );
     161           0 :                     if ( n && bHtml )
     162             :                     {
     163             :                         // 1/2" for HTML
     164           0 :                         aFormat.SetAbsLSpace(n * 720);
     165             :                     }
     166             :                     // #i38904#  Default alignment for
     167             :                     // numbering/bullet should be rtl in rtl paragraph:
     168           0 :                     if ( bRightToLeft )
     169             :                     {
     170           0 :                         aFormat.SetNumAdjust( SVX_ADJUST_RIGHT );
     171             :                     }
     172           0 :                     aSvxRule.SetLevel( n, aFormat, false );
     173           0 :                 }
     174           0 :                 aSvxRule.SetFeatureFlag(SvxNumRuleFlags::ENABLE_EMBEDDED_BMP, false);
     175             :             }
     176           0 :             aSet.Put( SvxNumBulletItem( aSvxRule ) );
     177             :         }
     178             : 
     179           0 :         aSet.Put( SfxBoolItem( SID_PARAM_NUM_PRESET,false ));
     180             : 
     181             :         // Before the dialogue of the HTML mode will be dropped at the Docshell.
     182           0 :         pDocSh->PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(pDocSh)));
     183             : 
     184           0 :         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     185             :         OSL_ENSURE(pFact, "Dialog creation failed!");
     186             :         boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateSwTabDialog( DLG_SVXTEST_NUM_BULLET,
     187           0 :                                                         GetView().GetWindow(), &aSet, GetShell()));
     188             :         OSL_ENSURE(pDlg, "Dialog creation failed!");
     189           0 :         SFX_REQUEST_ARG( rReq, pPageItem, SfxStringItem, FN_PARAM_1, false );
     190           0 :         if ( pPageItem )
     191           0 :             pDlg->SetCurPageId( OUStringToOString( pPageItem->GetValue(), RTL_TEXTENCODING_UTF8 ) );
     192           0 :         const short nRet = pDlg->Execute();
     193             :         const SfxPoolItem* pItem;
     194           0 :         if ( RET_OK == nRet )
     195             :         {
     196           0 :             if( SfxItemState::SET == pDlg->GetOutputItemSet()->GetItemState( SID_ATTR_NUMBERING_RULE, false, &pItem ))
     197             :             {
     198           0 :                 rReq.AppendItem( *pItem );
     199           0 :                 rReq.Done();
     200           0 :                 SvxNumRule* pSetRule = static_cast<const SvxNumBulletItem*>( pItem )->GetNumRule();
     201           0 :                 pSetRule->UnLinkGraphics();
     202             :                 SwNumRule aSetRule( pNumRuleAtCurrentSelection != NULL
     203             :                                     ? pNumRuleAtCurrentSelection->GetName()
     204           0 :                                     : GetShell().GetUniqueNumRuleName(),
     205           0 :                     numfunc::GetDefaultPositionAndSpaceMode() );
     206           0 :                 aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc() );
     207           0 :                 aSetRule.SetAutoRule( true );
     208             :                 // No start of new list, if an existing list style is edited.
     209             :                 // Otherwise start a new list.
     210           0 :                 const bool bCreateList = ( pNumRuleAtCurrentSelection == NULL );
     211           0 :                 GetShell().SetCurNumRule( aSetRule, bCreateList );
     212             :             }
     213             :             // If the Dialog was leaved with OK but nothing was chosen then the
     214             :             // numbering must be at least activated, if it is not already.
     215           0 :             else if ( pNumRuleAtCurrentSelection == NULL
     216           0 :                       && SfxItemState::SET == aSet.GetItemState( SID_ATTR_NUMBERING_RULE, false, &pItem ) )
     217             :             {
     218           0 :                 rReq.AppendItem( *pItem );
     219           0 :                 rReq.Done();
     220           0 :                 SvxNumRule* pSetRule = static_cast<const SvxNumBulletItem*>( pItem )->GetNumRule();
     221             :                 SwNumRule aSetRule(
     222           0 :                     GetShell().GetUniqueNumRuleName(),
     223           0 :                     numfunc::GetDefaultPositionAndSpaceMode() );
     224           0 :                 aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc() );
     225           0 :                 aSetRule.SetAutoRule( true );
     226             :                 // start new list
     227           0 :                 GetShell().SetCurNumRule( aSetRule, true );
     228             :             }
     229             :         }
     230           0 :         else if ( RET_USER == nRet )
     231           0 :             GetShell().DelNumRules();
     232             :     }
     233           0 :         break;
     234             : 
     235             :     default:
     236             :         OSL_FAIL("wrong dispatcher");
     237           0 :         return;
     238             :     }
     239             : }
     240             : 
     241             : 
     242           0 : void SwTextShell::ExecSetNumber(SfxRequest &rReq)
     243             : {
     244           0 :     const sal_uInt16 nSlot = rReq.GetSlot();
     245           0 :     switch ( nSlot )
     246             :     {
     247             :     case FN_SVX_SET_NUMBER:
     248             :     case FN_SVX_SET_BULLET:
     249             :         {
     250           0 :             SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, nSlot, false );
     251           0 :             if ( pItem != NULL )
     252             :             {
     253           0 :                 const sal_uInt16 nChoosenItemIdx = pItem->GetValue();
     254             :                 svx::sidebar::NBOTypeMgrBase* pNBOTypeMgr =
     255             :                     nSlot == FN_SVX_SET_NUMBER
     256             :                         ? svx::sidebar::NBOutlineTypeMgrFact::CreateInstance( svx::sidebar::eNBOType::NUMBERING )
     257           0 :                         : svx::sidebar::NBOutlineTypeMgrFact::CreateInstance( svx::sidebar::eNBOType::BULLETS );
     258           0 :                 if ( pNBOTypeMgr != NULL )
     259             :                 {
     260           0 :                     const SwNumRule* pNumRuleAtCurrentSelection = GetShell().GetNumRuleAtCurrentSelection();
     261           0 :                     sal_uInt16 nActNumLvl = USHRT_MAX;
     262           0 :                     if ( pNumRuleAtCurrentSelection != NULL )
     263             :                     {
     264           0 :                         const sal_uInt16 nLevel = GetShell().GetNumLevel();
     265           0 :                         if ( nLevel < MAXLEVEL )
     266             :                         {
     267           0 :                             nActNumLvl = 1 << nLevel;
     268             :                         }
     269             :                     }
     270             :                     SwNumRule aNewNumRule(
     271           0 :                         pNumRuleAtCurrentSelection != NULL ? pNumRuleAtCurrentSelection->GetName() : GetShell().GetUniqueNumRuleName(),
     272           0 :                         numfunc::GetDefaultPositionAndSpaceMode() );
     273             :                     SvxNumRule aNewSvxNumRule = pNumRuleAtCurrentSelection != NULL
     274             :                                                     ? pNumRuleAtCurrentSelection->MakeSvxNumRule()
     275           0 :                                                     : aNewNumRule.MakeSvxNumRule();
     276             :                     // set unit attribute to NB Manager
     277           0 :                     SfxItemSet aSet( GetPool(), SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL, 0 );
     278           0 :                     aSet.Put( SvxNumBulletItem( aNewSvxNumRule ) );
     279           0 :                     pNBOTypeMgr->SetItems( &aSet );
     280           0 :                     pNBOTypeMgr->ApplyNumRule( aNewSvxNumRule, nChoosenItemIdx - 1, nActNumLvl );
     281             : 
     282           0 :                     aNewNumRule.SetSvxRule( aNewSvxNumRule, GetShell().GetDoc() );
     283           0 :                     aNewNumRule.SetAutoRule( true );
     284           0 :                     const bool bCreateNewList = ( pNumRuleAtCurrentSelection == NULL );
     285           0 :                     GetShell().SetCurNumRule( aNewNumRule, bCreateNewList );
     286             :                 }
     287             :             }
     288             :         }
     289           0 :         break;
     290             : 
     291             :     default:
     292             :         OSL_ENSURE(false, "wrong Dispatcher");
     293           0 :         return;
     294             :     }
     295         177 : }
     296             : 
     297             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11