LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/shells - txtnum.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 212 0.5 %
Date: 2013-07-09 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             : using namespace svx::sidebar;
      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 , sal_False );
      54           0 :         sal_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 :         sal_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 , sal_False );
      83           0 :         sal_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 :         sal_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             :     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 :         bool bHtml = 0 != PTR_CAST(SwWebDocShell, pDocSh);
     117           0 :         const SwNumRule* pCurRule = GetShell().GetCurNumRule();
     118           0 :         if( pCurRule )
     119             :         {
     120           0 :             SvxNumRule aRule = pCurRule->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             :                     const String* pLinkStr;
     130           0 :                     if(pBrush &&
     131           0 :                         0 != (pLinkStr = pBrush->GetGraphicLink()) &&
     132           0 :                             pLinkStr->Len())
     133           0 :                         aFmt.SetNumberingType(SvxExtNumType(SVX_NUM_BITMAP|LINK_TOKEN));
     134           0 :                     aRule.SetLevel(i, aFmt, aRule.Get(i) != 0);
     135             :                 }
     136           0 :             }
     137           0 :             if(bHtml)
     138           0 :                 aRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, sal_False);
     139             : 
     140           0 :             aSet.Put(SvxNumBulletItem(aRule));
     141             :             OSL_ENSURE( GetShell().GetNumLevel() < MAXLEVEL,
     142             :                     "<SwTextShell::ExecEnterNum()> - numbered node without valid list level. Serious defect -> please inform OD." );
     143           0 :             sal_uInt16 nLevel = GetShell().GetNumLevel();
     144           0 :             if( nLevel < MAXLEVEL )
     145             :             {
     146           0 :                 nLevel = 1<<nLevel;
     147           0 :                 aSet.Put( SfxUInt16Item( SID_PARAM_CUR_NUM_LEVEL, nLevel ));
     148           0 :             }
     149             :         }
     150             :         else
     151             :         {
     152           0 :             SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
     153             :                              // #i89178#
     154           0 :                              numfunc::GetDefaultPositionAndSpaceMode() );
     155           0 :             SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
     156           0 :             const bool bRightToLeft = GetShell().IsInRightToLeftText( 0 );
     157             : 
     158           0 :             if( bHtml || bRightToLeft )
     159             :             {
     160           0 :                 for( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
     161             :                 {
     162           0 :                     SvxNumberFormat aFmt( aSvxRule.GetLevel( n ) );
     163           0 :                     if ( n && bHtml )
     164             :                     {
     165             :                         // 1/2" for HTML
     166           0 :                         aFmt.SetLSpace(720);
     167           0 :                         aFmt.SetAbsLSpace(n * 720);
     168             :                     }
     169             :                     // #i38904#  Default alignment for
     170             :                     // numbering/bullet should be rtl in rtl paragraph:
     171           0 :                     if ( bRightToLeft )
     172             :                     {
     173           0 :                         aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
     174             :                     }
     175           0 :                     aSvxRule.SetLevel( n, aFmt, sal_False );
     176           0 :                 }
     177           0 :                 aSvxRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, sal_False);
     178             :             }
     179           0 :             aSet.Put(SvxNumBulletItem(aSvxRule));
     180             :         }
     181             : 
     182           0 :         aSet.Put( SfxBoolItem( SID_PARAM_NUM_PRESET,sal_False ));
     183             : 
     184             :         // Before the dialogue of the HTML mode will be droped at the Docshell.
     185           0 :         pDocSh->PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(pDocSh)));
     186             : 
     187           0 :         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     188             :         OSL_ENSURE(pFact, "Dialogdiet fail!");
     189             :         SfxAbstractTabDialog* pDlg = pFact->CreateSwTabDialog( DLG_SVXTEST_NUM_BULLET,
     190           0 :                                                         GetView().GetWindow(), &aSet, GetShell());
     191             :         OSL_ENSURE(pDlg, "Dialogdiet fail!");
     192           0 :         sal_uInt16 nRet = pDlg->Execute();
     193             :         const SfxPoolItem* pItem;
     194           0 :         if( RET_OK == nRet )
     195             :         {
     196           0 :             if( SFX_ITEM_SET == pDlg->GetOutputItemSet()->GetItemState( SID_ATTR_NUMBERING_RULE, sal_False, &pItem ))
     197             :             {
     198           0 :                 rReq.AppendItem(*pItem);
     199           0 :                 rReq.Done();
     200           0 :                 SvxNumRule* pSetRule = ((SvxNumBulletItem*)pItem)->GetNumRule();
     201           0 :                 pSetRule->UnLinkGraphics();
     202             :                 SwNumRule aSetRule( pCurRule
     203           0 :                                         ? pCurRule->GetName()
     204           0 :                                         : GetShell().GetUniqueNumRuleName(),
     205             :                                     // #i89178#
     206           0 :                                     numfunc::GetDefaultPositionAndSpaceMode() );
     207           0 :                 aSetRule.SetSvxRule( *pSetRule, GetShell().GetDoc());
     208           0 :                 aSetRule.SetAutoRule( sal_True );
     209             :                 // No start of new list, if an existing list style is edited.
     210             :                 // Otherwise start a new list.
     211           0 :                 const bool bCreateList = (pCurRule == 0);
     212           0 :                 GetShell().SetCurNumRule( aSetRule, bCreateList );
     213             :             }
     214             :             // If the Dialog was leaved with OK but nothing was chosen then the
     215             :             // numbering must be at least activated, if it is not already.
     216           0 :             else if( !pCurRule && SFX_ITEM_SET == aSet.GetItemState( SID_ATTR_NUMBERING_RULE, sal_False, &pItem ))
     217             :             {
     218           0 :                 rReq.AppendItem( *pItem );
     219           0 :                 rReq.Done();
     220           0 :                 SvxNumRule* pSetRule = ((SvxNumBulletItem*)pItem)->GetNumRule();
     221           0 :                 SwNumRule aSetRule( GetShell().GetUniqueNumRuleName(),
     222             :                                     // #i89178#
     223           0 :                                     numfunc::GetDefaultPositionAndSpaceMode() );
     224           0 :                 aSetRule.SetSvxRule(*pSetRule, GetShell().GetDoc());
     225           0 :                 aSetRule.SetAutoRule( sal_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 :         delete pDlg;
     234             :     }
     235           0 :     break;
     236             :     default:
     237             :         OSL_FAIL("wrong dispatcher");
     238           0 :         return;
     239             :     }
     240             : }
     241             : 
     242           0 : void SwTextShell::ExecSetNumber(SfxRequest &rReq)
     243             : {
     244           0 :     SwNumRule aRule( GetShell().GetUniqueNumRuleName(),
     245             :                          // #i89178#
     246           0 :                          numfunc::GetDefaultPositionAndSpaceMode() );
     247             : 
     248           0 :     SvxNumRule aSvxRule = aRule.MakeSvxNumRule();
     249           0 :     const bool bRightToLeft = GetShell().IsInRightToLeftText( 0 );
     250             : 
     251           0 :     if( bRightToLeft )
     252             :     {
     253           0 :         for( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
     254             :         {
     255           0 :             SvxNumberFormat aFmt( aSvxRule.GetLevel( n ) );
     256             :            /* if ( n && bHtml )
     257             :             {
     258             :                 // 1/2" for HTML
     259             :                 aFmt.SetLSpace(720);
     260             :                 aFmt.SetAbsLSpace(n * 720);
     261             :             }*/
     262             :             // #i38904#  Default alignment for
     263             :             // numbering/bullet should be rtl in rtl paragraph:
     264           0 :             if ( bRightToLeft )
     265             :             {
     266           0 :                 aFmt.SetNumAdjust( SVX_ADJUST_RIGHT );
     267             :             }
     268           0 :             aSvxRule.SetLevel( n, aFmt, sal_False );
     269           0 :         }
     270           0 :         aSvxRule.SetFeatureFlag(NUM_ENABLE_EMBEDDED_BMP, sal_False);
     271             :     }
     272             : 
     273           0 :     const SwNumRule* pCurRule = GetShell().GetCurNumRule();
     274           0 :     sal_uInt16      nActNumLvl = (sal_uInt16)0xFFFF;
     275           0 :     if( pCurRule )
     276             :     {
     277           0 :         sal_uInt16 nLevel = GetShell().GetNumLevel();
     278           0 :         if( nLevel < MAXLEVEL )
     279             :         {
     280           0 :             nActNumLvl = 1<<nLevel;
     281             :         }
     282             : 
     283           0 :         aSvxRule = pCurRule->MakeSvxNumRule();
     284             : 
     285             :         //convert type of linked bitmaps from SVX_NUM_BITMAP to (SVX_NUM_BITMAP|LINK_TOKEN)
     286           0 :         for(sal_uInt16 i = 0; i < aSvxRule.GetLevelCount(); i++)
     287             :         {
     288           0 :             SvxNumberFormat aFmt(aSvxRule.GetLevel(i));
     289           0 :             if(SVX_NUM_BITMAP == aFmt.GetNumberingType())
     290             :             {
     291           0 :                 const SvxBrushItem* pBrush = aFmt.GetBrush();
     292             :                 const String* pLinkStr;
     293           0 :                 if(pBrush &&
     294           0 :                     0 != (pLinkStr = pBrush->GetGraphicLink()) &&
     295           0 :                         pLinkStr->Len())
     296           0 :                     aFmt.SetNumberingType(SvxExtNumType(SVX_NUM_BITMAP|LINK_TOKEN));
     297           0 :                 aSvxRule.SetLevel(i, aFmt, aSvxRule.Get(i) != 0);
     298             :             }
     299           0 :         }
     300             :     }
     301             : 
     302             : 
     303           0 :     switch(rReq.GetSlot())
     304             :     {
     305             :     case FN_SVX_SET_NUMBER:
     306             :         {
     307           0 :             SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, FN_SVX_SET_NUMBER , sal_False );
     308           0 :             if (pItem)
     309             :             {
     310           0 :                 sal_uInt16 nIdx = pItem->GetValue();
     311           0 :                 if (nIdx==DEFAULT_NONE) {
     312           0 :                     GetShell().DelNumRules();
     313           0 :                     break;
     314             :                 }
     315           0 :                 --nIdx;
     316             : 
     317           0 :                 NBOTypeMgrBase* pNumbering = NBOutlineTypeMgrFact::CreateInstance(eNBOType::NUMBERING);
     318           0 :                 if ( pNumbering )
     319             :                 {
     320           0 :                     SwNumRule aTmpRule( GetShell().GetUniqueNumRuleName(),
     321           0 :                          numfunc::GetDefaultPositionAndSpaceMode() );
     322             : 
     323           0 :                     SvxNumRule aTempRule = aTmpRule.MakeSvxNumRule();
     324             :                     //Sym3_2508, set unit attribute to NB Manager
     325           0 :                     SfxItemSet aSet(GetPool(),
     326             :                             SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
     327           0 :                             0 );
     328           0 :                     aSet.Put(SvxNumBulletItem(aTempRule));
     329           0 :                     pNumbering->SetItems(&aSet);
     330           0 :                     pNumbering->ApplyNumRule(aTempRule,nIdx,nActNumLvl);
     331             : 
     332           0 :                     sal_uInt16 nMask = 1;
     333           0 :                     for(sal_uInt16 i = 0; i < aSvxRule.GetLevelCount(); i++)
     334             :                     {
     335           0 :                         if(nActNumLvl & nMask)
     336             :                         {
     337           0 :                             SvxNumberFormat aFmt(aTempRule.GetLevel(i));
     338           0 :                             aSvxRule.SetLevel(i, aFmt);
     339             :                         }
     340           0 :                         nMask <<= 1 ;
     341             :                     }
     342             : 
     343           0 :                     aSvxRule.UnLinkGraphics();
     344             :                     SwNumRule aSetRule( pCurRule
     345           0 :                                             ? pCurRule->GetName()
     346           0 :                                             : GetShell().GetUniqueNumRuleName(),
     347           0 :                                         numfunc::GetDefaultPositionAndSpaceMode() );
     348           0 :                     aSetRule.SetSvxRule( aSvxRule, GetShell().GetDoc());
     349             : 
     350           0 :                     aSetRule.SetAutoRule( sal_True );
     351           0 :                     const bool bCreateList = (pCurRule == 0);
     352           0 :                     GetShell().SetCurNumRule( aSetRule, bCreateList );
     353             :                 }
     354             :                 //End
     355             :             }
     356           0 :             break;
     357             :         }
     358             :     case FN_SVX_SET_BULLET:
     359             :         {
     360           0 :             SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, FN_SVX_SET_BULLET , sal_False );
     361           0 :             if (pItem)
     362             :             {
     363           0 :                 sal_uInt16 nIdx = pItem->GetValue();
     364           0 :                 if (nIdx==DEFAULT_NONE) {
     365           0 :                     GetShell().DelNumRules();
     366           0 :                     break;
     367             :                 }
     368           0 :                 nIdx--;
     369             : 
     370           0 :                 NBOTypeMgrBase* pBullets = NBOutlineTypeMgrFact::CreateInstance(eNBOType::MIXBULLETS);
     371           0 :                 if ( pBullets )
     372             :                 {
     373           0 :                     SwNumRule aTmpRule( GetShell().GetUniqueNumRuleName(),
     374           0 :                          numfunc::GetDefaultPositionAndSpaceMode() );
     375             : 
     376           0 :                     SvxNumRule aTempRule = aTmpRule.MakeSvxNumRule();
     377             :                     //Sym3_2508, set unit attribute to NB Manager
     378           0 :                     SfxItemSet aSet(GetPool(),
     379             :                             SID_ATTR_NUMBERING_RULE, SID_PARAM_CUR_NUM_LEVEL,
     380           0 :                             0 );
     381           0 :                     aSet.Put(SvxNumBulletItem(aTempRule));
     382           0 :                     pBullets->SetItems(&aSet);
     383             : 
     384             :                     //SvxNumRule aTempRule( 0, 10, false );
     385           0 :                     pBullets->ApplyNumRule(aTempRule,nIdx,nActNumLvl);
     386           0 :                     sal_uInt16 nMask = 1;
     387           0 :                     for(sal_uInt16 i = 0; i < aSvxRule.GetLevelCount(); i++)
     388             :                     {
     389           0 :                         if(nActNumLvl & nMask)
     390             :                         {
     391           0 :                             SvxNumberFormat aFmt(aTempRule.GetLevel(i));
     392           0 :                             aSvxRule.SetLevel(i, aFmt);
     393             :                         }
     394           0 :                         nMask <<= 1;
     395             :                     }
     396           0 :                     aSvxRule.UnLinkGraphics();
     397             : 
     398             :                     SwNumRule aSetRule( pCurRule
     399           0 :                                             ? pCurRule->GetName()
     400           0 :                                             : GetShell().GetUniqueNumRuleName(),
     401           0 :                                         numfunc::GetDefaultPositionAndSpaceMode() );
     402             : 
     403           0 :                     aSetRule.SetSvxRule( aSvxRule, GetShell().GetDoc());
     404             : 
     405           0 :                     aSetRule.SetAutoRule( sal_True );
     406           0 :                     const bool bCreateList = (pCurRule == 0);
     407           0 :                     GetShell().SetCurNumRule( aSetRule, bCreateList );
     408             :                 }
     409             :                 //End
     410             :             }
     411             : 
     412             :         }
     413           0 :         break;
     414           0 :     }
     415          99 : }
     416             : 
     417             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10