LCOV - code coverage report
Current view: top level - sw/source/core/uibase/shells - txtnum.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 143 0.0 %
Date: 2014-04-14 Functions: 0 4 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 <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             : 
      44           0 : void SwTextShell::ExecEnterNum(SfxRequest &rReq)
      45             : {
      46             :     //Because the record before any shell exchange.
      47           0 :     switch(rReq.GetSlot())
      48             :     {
      49             :     case FN_NUM_NUMBERING_ON:
      50             :     {
      51           0 :         GetShell().StartAllAction();
      52           0 :         SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , false );
      53           0 :         sal_Bool bMode = !GetShell().SelectionHasNumber(); // #i29560#
      54           0 :         if ( pItem )
      55           0 :             bMode = pItem->GetValue();
      56             :         else
      57           0 :             rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
      58             : 
      59           0 :         if ( bMode != (GetShell().SelectionHasNumber()) ) // #i29560#
      60             :         {
      61           0 :             rReq.Done();
      62           0 :             if( bMode )
      63           0 :                 GetShell().NumOn();
      64             :             else
      65           0 :                 GetShell().NumOrBulletOff(); // #i29560#
      66             :         }
      67           0 :         sal_Bool bNewResult = GetShell().SelectionHasNumber();
      68           0 :         if (bNewResult!=bMode) {
      69           0 :             SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
      70           0 :             SfxBoolItem aItem(FN_NUM_NUMBERING_ON,!bNewResult);
      71           0 :             rBindings.SetState(aItem);
      72           0 :             SfxBoolItem aNewItem(FN_NUM_NUMBERING_ON,bNewResult);
      73           0 :             rBindings.SetState(aNewItem);
      74             :         }
      75           0 :         GetShell().EndAllAction();
      76             :     }
      77           0 :     break;
      78             :     case FN_NUM_BULLET_ON:
      79             :     {
      80           0 :         GetShell().StartAllAction();
      81           0 :         SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FN_PARAM_1 , false );
      82           0 :         sal_Bool bMode = !GetShell().SelectionHasBullet(); // #i29560#
      83           0 :         if ( pItem )
      84           0 :             bMode = pItem->GetValue();
      85             :         else
      86           0 :             rReq.AppendItem( SfxBoolItem( FN_PARAM_1, bMode ) );
      87             : 
      88           0 :         if ( bMode != (GetShell().SelectionHasBullet()) ) // #i29560#
      89             :         {
      90           0 :             rReq.Done();
      91           0 :             if( bMode )
      92           0 :                 GetShell().BulletOn();
      93             :             else
      94           0 :                 GetShell().NumOrBulletOff(); // #i29560#
      95             :         }
      96           0 :         sal_Bool bNewResult = GetShell().SelectionHasBullet();
      97           0 :         if (bNewResult!=bMode) {
      98           0 :             SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings();
      99           0 :             SfxBoolItem aItem(FN_NUM_BULLET_ON,!bNewResult);
     100           0 :             rBindings.SetState(aItem);
     101           0 :             SfxBoolItem aNewItem(FN_NUM_BULLET_ON,bNewResult);
     102           0 :             rBindings.SetState(aNewItem);
     103             :         }
     104           0 :         GetShell().EndAllAction();
     105             :     }
     106           0 :     break;
     107             : 
     108             :     case FN_NUMBER_BULLETS:
     109             :     case SID_OUTLINE_BULLET:
     110             :     {
     111           0 :         SfxItemSet aSet( GetPool(),
     112             :                          SID_HTML_MODE, SID_HTML_MODE,
     113             :                          SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
     114           0 :                          0 );
     115           0 :         SwDocShell* pDocSh = GetView().GetDocShell();
     116           0 :         const bool bHtml = 0 != PTR_CAST( SwWebDocShell, pDocSh );
     117           0 :         const SwNumRule* pNumRuleAtCurrentSelection = GetShell().GetNumRuleAtCurrentSelection();
     118           0 :         if ( pNumRuleAtCurrentSelection != NULL )
     119             :         {
     120           0 :             SvxNumRule aRule = pNumRuleAtCurrentSelection->MakeSvxNumRule();
     121             : 
     122             :             //convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
     123           0 :             for ( sal_uInt16 i = 0; i < aRule.GetLevelCount(); i++ )
     124             :             {
     125           0 :                 SvxNumberFormat aFmt( aRule.GetLevel( i ) );
     126           0 :                 if ( SVX_NUM_BITMAP == aFmt.GetNumberingType() )
     127             :                 {
     128           0 :                     const SvxBrushItem* pBrush = aFmt.GetBrush();
     129           0 :                     if(pBrush && !pBrush->GetGraphicLink().isEmpty())
     130           0 :                         aFmt.SetNumberingType(SvxExtNumType(SVX_NUM_BITMAP|LINK_TOKEN));
     131           0 :                     aRule.SetLevel(i, aFmt, aRule.Get(i) != 0);
     132             :                 }
     133           0 :             }
     134           0 :             if(bHtml)
     135           0 :                 aRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, false);
     136             : 
     137           0 :             aSet.Put(SvxNumBulletItem(aRule));
     138             :             OSL_ENSURE( GetShell().GetNumLevel() < MAXLEVEL,
     139             :                     "<SwTextShell::ExecEnterNum()> - numbered node without valid list level. Serious defect -> please inform OD." );
     140           0 :             sal_uInt16 nLevel = GetShell().GetNumLevel();
     141           0 :             if( nLevel < MAXLEVEL )
     142             :             {
     143           0 :                 nLevel = 1 << nLevel;
     144           0 :                 aSet.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ) );
     145           0 :             }
     146             :         }
     147             :         else
     148             :         {
     149           0 :             SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
     150             :                              // #i89178#
     151           0 :                              numfunc::GetDefaultPositionAndSpaceMode() );
     152           0 :             SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
     153           0 :             const bool bRightToLeft = GetShell().IsInRightToLeftText( 0 );
     154             : 
     155           0 :             if ( bHtml || bRightToLeft )
     156             :             {
     157           0 :                 for ( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
     158             :                 {
     159           0 :                     SvxNumberFormat aFmt( aSvxRule.GetLevel( n ) );
     160           0 :                     if ( n && bHtml )
     161             :                     {
     162             :                         // 1/2" for HTML
     163           0 :                         aFmt.SetLSpace(720);
     164           0 :                         aFmt.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 :                         aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
     171             :                     }
     172           0 :                     aSvxRule.SetLevel( n, aFmt, false );
     173           0 :                 }
     174           0 :                 aSvxRule.SetFeatureFlag(NUM_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, "Dialogdiet fail!");
     186             :         SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_SVXTEST_NUM_BULLET,
     187           0 :                                                         GetView().GetWindow(), &aSet, GetShell());
     188             :         OSL_ENSURE(pDlg, "Dialogdiet fail!");
     189           0 :         sal_uInt16 nRet = pDlg->Execute();
     190             :         const SfxPoolItem* pItem;
     191           0 :         if ( RET_OK == nRet )
     192             :         {
     193           0 :             if( SFX_ITEM_SET == pDlg->GetOutputItemSet()->GetItemState( SID_ATTR_NUMBERING_RULE, false, &pItem ))
     194             :             {
     195           0 :                 rReq.AppendItem( *pItem );
     196           0 :                 rReq.Done();
     197           0 :                 SvxNumRule* pSetRule = ( (SvxNumBulletItem*) pItem )->GetNumRule();
     198           0 :                 pSetRule->UnLinkGraphics();
     199             :                 SwNumRule aSetRule( pNumRuleAtCurrentSelection != NULL
     200             :                                     ? pNumRuleAtCurrentSelection->GetName()
     201           0 :                                     : GetShell().GetUniqueNumRuleName(),
     202           0 :                     numfunc::GetDefaultPositionAndSpaceMode() );
     203           0 :                 aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc() );
     204           0 :                 aSetRule.SetAutoRule( sal_True );
     205             :                 // No start of new list, if an existing list style is edited.
     206             :                 // Otherwise start a new list.
     207           0 :                 const bool bCreateList = ( pNumRuleAtCurrentSelection == NULL );
     208           0 :                 GetShell().SetCurNumRule( aSetRule, bCreateList );
     209             :             }
     210             :             // If the Dialog was leaved with OK but nothing was chosen then the
     211             :             // numbering must be at least activated, if it is not already.
     212           0 :             else if ( pNumRuleAtCurrentSelection == NULL
     213           0 :                       && SFX_ITEM_SET == aSet.GetItemState( SID_ATTR_NUMBERING_RULE, false, &pItem ) )
     214             :             {
     215           0 :                 rReq.AppendItem( *pItem );
     216           0 :                 rReq.Done();
     217           0 :                 SvxNumRule* pSetRule = ( (SvxNumBulletItem*) pItem )->GetNumRule();
     218             :                 SwNumRule aSetRule(
     219           0 :                     GetShell().GetUniqueNumRuleName(),
     220           0 :                     numfunc::GetDefaultPositionAndSpaceMode() );
     221           0 :                 aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc() );
     222           0 :                 aSetRule.SetAutoRule( sal_True );
     223             :                 // start new list
     224           0 :                 GetShell().SetCurNumRule( aSetRule, true );
     225             :             }
     226             :         }
     227           0 :         else if ( RET_USER == nRet )
     228           0 :             GetShell().DelNumRules();
     229             : 
     230           0 :         delete pDlg;
     231             :     }
     232           0 :         break;
     233             : 
     234             :     default:
     235             :         OSL_FAIL("wrong dispatcher");
     236           0 :         return;
     237             :     }
     238             : }
     239             : 
     240             : 
     241           0 : void SwTextShell::ExecSetNumber(SfxRequest &rReq)
     242             : {
     243           0 :     const sal_uInt16 nSlot = rReq.GetSlot();
     244           0 :     switch ( nSlot )
     245             :     {
     246             :     case FN_SVX_SET_NUMBER:
     247             :     case FN_SVX_SET_BULLET:
     248             :         {
     249           0 :             SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, nSlot, false );
     250           0 :             if ( pItem != NULL )
     251             :             {
     252           0 :                 const sal_uInt16 nChoosenItemIdx = pItem->GetValue();
     253           0 :                 if ( nChoosenItemIdx == DEFAULT_NONE )
     254             :                 {
     255           0 :                     GetShell().DelNumRules();
     256             :                 }
     257             :                 else
     258             :                 {
     259             :                     svx::sidebar::NBOTypeMgrBase* pNBOTypeMgr =
     260             :                         nSlot == FN_SVX_SET_NUMBER
     261             :                             ? svx::sidebar::NBOutlineTypeMgrFact::CreateInstance( svx::sidebar::eNBOType::NUMBERING )
     262           0 :                             : svx::sidebar::NBOutlineTypeMgrFact::CreateInstance( svx::sidebar::eNBOType::MIXBULLETS );
     263           0 :                     if ( pNBOTypeMgr != NULL )
     264             :                     {
     265           0 :                         const SwNumRule* pNumRuleAtCurrentSelection = GetShell().GetNumRuleAtCurrentSelection();
     266           0 :                         sal_uInt16 nActNumLvl = (sal_uInt16) 0xFFFF;
     267           0 :                         if ( pNumRuleAtCurrentSelection != NULL )
     268             :                         {
     269           0 :                             sal_uInt16 nLevel = GetShell().GetNumLevel();
     270           0 :                             if ( nLevel < MAXLEVEL )
     271             :                             {
     272           0 :                                 nActNumLvl = 1 << nLevel;
     273             :                             }
     274             :                         }
     275             :                         SwNumRule aNewNumRule(
     276           0 :                             pNumRuleAtCurrentSelection != NULL ? pNumRuleAtCurrentSelection->GetName() : GetShell().GetUniqueNumRuleName(),
     277           0 :                             numfunc::GetDefaultPositionAndSpaceMode() );
     278             :                         SvxNumRule aNewSvxNumRule = pNumRuleAtCurrentSelection != NULL
     279             :                                                         ? pNumRuleAtCurrentSelection->MakeSvxNumRule()
     280           0 :                                                         : aNewNumRule.MakeSvxNumRule();
     281             :                         // set unit attribute to NB Manager
     282           0 :                         SfxItemSet aSet( GetPool(), SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL, 0 );
     283           0 :                         aSet.Put( SvxNumBulletItem( aNewSvxNumRule ) );
     284           0 :                         pNBOTypeMgr->SetItems( &aSet );
     285           0 :                         pNBOTypeMgr->ApplyNumRule( aNewSvxNumRule, nChoosenItemIdx - 1, nActNumLvl );
     286             : 
     287           0 :                         aNewNumRule.SetSvxRule( aNewSvxNumRule, GetShell().GetDoc() );
     288           0 :                         aNewNumRule.SetAutoRule( sal_True );
     289           0 :                         const bool bCreateNewList = ( pNumRuleAtCurrentSelection == NULL );
     290           0 :                         GetShell().SetCurNumRule( aNewNumRule, bCreateNewList );
     291             :                     }
     292             :                 }
     293             :             }
     294             :         }
     295           0 :         break;
     296             : 
     297             :     default:
     298             :         OSL_ENSURE(false, "wrong Dispatcher");
     299           0 :         return;
     300             :     }
     301           0 : }
     302             : 
     303             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10