LCOV - code coverage report
Current view: top level - sd/source/ui/func - fubullet.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 11 166 6.6 %
Date: 2015-06-13 12:38:46 Functions: 3 13 23.1 %
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 "fubullet.hxx"
      21             : 
      22             : #include <sfx2/bindings.hxx>
      23             : #include <editeng/eeitem.hxx>
      24             : #include <svl/poolitem.hxx>
      25             : #include <editeng/fontitem.hxx>
      26             : #include "OutlineViewShell.hxx"
      27             : #include "DrawViewShell.hxx"
      28             : #include "Window.hxx"
      29             : #include "drawdoc.hxx"
      30             : #include "strings.hrc"
      31             : #include "sdresid.hxx"
      32             : #include <svx/svdoutl.hxx>
      33             : #include <vcl/msgbox.hxx>
      34             : #include <sfx2/request.hxx>
      35             : #include <svl/ctloptions.hxx>
      36             : #include <svl/itempool.hxx>
      37             : 
      38             : #include <svx/svxdlg.hxx>
      39             : #include <svx/dialogs.hrc>
      40             : #include "drawview.hxx"
      41             : #include <boost/scoped_ptr.hpp>
      42             : 
      43             : #include "app.hrc"
      44             : 
      45             : namespace sd {
      46             : 
      47             : const sal_Unicode CHAR_HARDBLANK    =   ((sal_Unicode)0x00A0);
      48             : const sal_Unicode CHAR_HARDHYPHEN   =   ((sal_Unicode)0x2011);
      49             : const sal_Unicode CHAR_SOFTHYPHEN   =   ((sal_Unicode)0x00AD);
      50             : const sal_Unicode CHAR_RLM          =   ((sal_Unicode)0x200F);
      51             : const sal_Unicode CHAR_LRM          =   ((sal_Unicode)0x200E);
      52             : const sal_Unicode CHAR_ZWSP         =   ((sal_Unicode)0x200B);
      53             : const sal_Unicode CHAR_ZWNBSP       =   ((sal_Unicode)0x2060);
      54             : 
      55           0 : TYPEINIT1( FuBullet, FuPoor );
      56             : 
      57           0 : FuBullet::FuBullet (
      58             :     ViewShell* pViewSh,
      59             :     ::sd::Window* pWin,
      60             :     ::sd::View* _pView,
      61             :     SdDrawDocument* pDoc,
      62             :     SfxRequest& rReq)
      63           0 :     : FuPoor(pViewSh, pWin, _pView, pDoc, rReq)
      64             : {
      65           0 : }
      66             : 
      67           0 : rtl::Reference<FuPoor> FuBullet::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
      68             : {
      69           0 :     rtl::Reference<FuPoor> xFunc( new FuBullet( pViewSh, pWin, pView, pDoc, rReq ) );
      70           0 :     xFunc->DoExecute(rReq);
      71           0 :     return xFunc;
      72             : }
      73             : 
      74           0 : void FuBullet::DoExecute( SfxRequest& rReq )
      75             : {
      76           0 :     if( rReq.GetSlot() == SID_CHARMAP )
      77           0 :         InsertSpecialCharacter(rReq);
      78             :     else
      79             :     {
      80           0 :         sal_Unicode cMark = 0;
      81           0 :         switch( rReq.GetSlot() )
      82             :         {
      83           0 :             case FN_INSERT_SOFT_HYPHEN: cMark = CHAR_SOFTHYPHEN ; break;
      84           0 :             case FN_INSERT_HARDHYPHEN:  cMark = CHAR_HARDHYPHEN ; break;
      85           0 :             case FN_INSERT_HARD_SPACE:  cMark = CHAR_HARDBLANK ; break;
      86           0 :             case SID_INSERT_RLM : cMark = CHAR_RLM ; break;
      87           0 :             case SID_INSERT_LRM : cMark = CHAR_LRM ; break;
      88           0 :             case SID_INSERT_ZWSP : cMark = CHAR_ZWSP ; break;
      89           0 :             case SID_INSERT_ZWNBSP: cMark = CHAR_ZWNBSP; break;
      90             :         }
      91             : 
      92             :         DBG_ASSERT( cMark != 0, "FuBullet::FuBullet(), illegal slot used!" );
      93             : 
      94           0 :         if( cMark )
      95           0 :             InsertFormattingMark( cMark );
      96             :     }
      97             : 
      98           0 : }
      99             : 
     100           0 : void FuBullet::InsertFormattingMark( sal_Unicode cMark )
     101             : {
     102           0 :     OutlinerView* pOV = NULL;
     103           0 :     ::Outliner*   pOL = NULL;
     104             : 
     105             :     // depending on ViewShell set Outliner and OutlinerView
     106           0 :     if (mpViewShell->ISA(DrawViewShell))
     107             :     {
     108           0 :         pOV = mpView->GetTextEditOutlinerView();
     109           0 :         if (pOV)
     110           0 :             pOL = mpView->GetTextEditOutliner();
     111             :     }
     112           0 :     else if (mpViewShell->ISA(OutlineViewShell))
     113             :     {
     114           0 :         pOL = &static_cast<OutlineView*>(mpView)->GetOutliner();
     115             :         pOV = static_cast<OutlineView*>(mpView)->GetViewByWindow(
     116           0 :             mpViewShell->GetActiveWindow());
     117             :     }
     118             : 
     119             :     // insert string
     120           0 :     if(pOV && pOL)
     121             :     {
     122             :         // prevent flickering
     123           0 :         pOV->HideCursor();
     124           0 :         pOL->SetUpdateMode(false);
     125             : 
     126             :         // remove old selected text
     127           0 :         pOV->InsertText( aEmptyStr );
     128             : 
     129             :         // prepare undo
     130           0 :         ::svl::IUndoManager& rUndoMgr =  pOL->GetUndoManager();
     131             :         rUndoMgr.EnterListAction(SD_RESSTR(STR_UNDO_INSERT_SPECCHAR),
     132           0 :                                     aEmptyStr );
     133             : 
     134             :         // insert given text
     135           0 :         OUString aStr( cMark );
     136           0 :         pOV->InsertText( aStr, true);
     137             : 
     138           0 :         ESelection aSel = pOV->GetSelection();
     139           0 :         aSel.nStartPara = aSel.nEndPara;
     140           0 :         aSel.nStartPos = aSel.nEndPos;
     141           0 :         pOV->SetSelection(aSel);
     142             : 
     143           0 :         rUndoMgr.LeaveListAction();
     144             : 
     145             :         // restart repainting
     146           0 :         pOL->SetUpdateMode(true);
     147           0 :         pOV->ShowCursor();
     148             :     }
     149           0 : }
     150             : 
     151           0 : void FuBullet::InsertSpecialCharacter( SfxRequest& rReq )
     152             : {
     153           0 :     const SfxItemSet *pArgs = rReq.GetArgs();
     154           0 :     const SfxPoolItem* pItem = 0;
     155           0 :     if( pArgs )
     156           0 :         pArgs->GetItemState(mpDoc->GetPool().GetWhich(SID_CHARMAP), false, &pItem);
     157             : 
     158           0 :     OUString aChars;
     159           0 :     vcl::Font aFont;
     160           0 :     if ( pItem )
     161             :     {
     162           0 :         aChars = static_cast<const SfxStringItem*>(pItem)->GetValue();
     163           0 :         const SfxPoolItem* pFtItem = NULL;
     164           0 :         pArgs->GetItemState( mpDoc->GetPool().GetWhich(SID_ATTR_SPECIALCHAR), false, &pFtItem);
     165           0 :         const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
     166           0 :         if ( pFontItem )
     167             :         {
     168           0 :             OUString aFontName = pFontItem->GetValue();
     169           0 :             aFont = vcl::Font( aFontName, Size(1,1) );
     170             :         }
     171             :         else
     172             :         {
     173           0 :             SfxItemSet aFontAttr( mpDoc->GetPool() );
     174           0 :             mpView->GetAttributes( aFontAttr );
     175           0 :             const SvxFontItem* pFItem = static_cast<const SvxFontItem*>(aFontAttr.GetItem( SID_ATTR_CHAR_FONT ));
     176           0 :             if( pFItem )
     177           0 :                 aFont = vcl::Font( pFItem->GetFamilyName(), pFItem->GetStyleName(), Size( 1, 1 ) );
     178             :         }
     179             :     }
     180             : 
     181           0 :     if (aChars.isEmpty())
     182             :     {
     183           0 :         SfxAllItemSet aSet( mpDoc->GetPool() );
     184           0 :         aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
     185             : 
     186           0 :         SfxItemSet aFontAttr( mpDoc->GetPool() );
     187           0 :         mpView->GetAttributes( aFontAttr );
     188           0 :         const SvxFontItem* pFontItem = static_cast<const SvxFontItem*>(aFontAttr.GetItem( SID_ATTR_CHAR_FONT ));
     189           0 :         if( pFontItem )
     190           0 :             aSet.Put( *pFontItem );
     191             : 
     192           0 :         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     193           0 :         boost::scoped_ptr<SfxAbstractDialog> pDlg(pFact ? pFact->CreateSfxDialog( &mpView->GetViewShell()->GetViewFrame()->GetWindow(), aSet,
     194           0 :             mpView->GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface(),
     195           0 :             RID_SVXDLG_CHARMAP ) : 0);
     196           0 :         if( !pDlg )
     197           0 :             return;
     198             : 
     199             :         // If a character is selected, it can be shown
     200             :         // pDLg->SetFont( );
     201             :         // pDlg->SetChar( );
     202           0 :         sal_uInt16 nResult = pDlg->Execute();
     203           0 :         if( nResult == RET_OK )
     204             :         {
     205           0 :             SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pCItem, SfxStringItem, SID_CHARMAP, false );
     206           0 :             SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFItem, SvxFontItem, SID_ATTR_CHAR_FONT, false );
     207           0 :             if ( pFItem )
     208             :             {
     209           0 :                 aFont.SetName( pFItem->GetFamilyName() );
     210           0 :                 aFont.SetStyleName( pFItem->GetStyleName() );
     211           0 :                 aFont.SetCharSet( pFItem->GetCharSet() );
     212           0 :                 aFont.SetPitch( pFItem->GetPitch() );
     213             :             }
     214             : 
     215           0 :             if ( pCItem )
     216           0 :                 aChars  = pCItem->GetValue();
     217           0 :         }
     218             :     }
     219             : 
     220           0 :     if (!aChars.isEmpty())
     221             :     {
     222           0 :         OutlinerView* pOV = NULL;
     223           0 :         ::Outliner*   pOL = NULL;
     224             : 
     225             :         // determine depending on ViewShell Outliner and OutlinerView
     226           0 :         if(mpViewShell && mpViewShell->ISA(DrawViewShell))
     227             :         {
     228           0 :             pOV = mpView->GetTextEditOutlinerView();
     229           0 :             if (pOV)
     230             :             {
     231           0 :                 pOL = mpView->GetTextEditOutliner();
     232             :             }
     233             :         }
     234           0 :         else if(mpViewShell && mpViewShell->ISA(OutlineViewShell))
     235             :         {
     236           0 :             pOL = &static_cast<OutlineView*>(mpView)->GetOutliner();
     237             :             pOV = static_cast<OutlineView*>(mpView)->GetViewByWindow(
     238           0 :                 mpViewShell->GetActiveWindow());
     239             :         }
     240             : 
     241             :         // insert special character
     242           0 :         if (pOV)
     243             :         {
     244             :             // prevent flicker
     245           0 :             pOV->HideCursor();
     246           0 :             pOL->SetUpdateMode(false);
     247             : 
     248             :             /* remember old attributes:
     249             :                To do that, remove selected area before (it has to go anyway).
     250             :                With that, we get unique attributes (and since there is no
     251             :                DeleteSelected() in OutlinerView, it is deleted by inserting an
     252             :                empty string). */
     253           0 :             pOV->InsertText( aEmptyStr );
     254             : 
     255           0 :             SfxItemSet aOldSet( mpDoc->GetPool(), EE_CHAR_FONTINFO, EE_CHAR_FONTINFO, 0 );
     256           0 :             aOldSet.Put( pOV->GetAttribs() );
     257             : 
     258           0 :             ::svl::IUndoManager& rUndoMgr =  pOL->GetUndoManager();
     259             :             rUndoMgr.EnterListAction(SD_RESSTR(STR_UNDO_INSERT_SPECCHAR),
     260           0 :                                      aEmptyStr );
     261           0 :             pOV->InsertText(aChars, true);
     262             : 
     263             :             // set attributes (set font)
     264           0 :             SfxItemSet aSet(pOL->GetEmptyItemSet());
     265           0 :             SvxFontItem aFontItem (aFont.GetFamily(),    aFont.GetName(),
     266           0 :                                    aFont.GetStyleName(), aFont.GetPitch(),
     267           0 :                                    aFont.GetCharSet(),
     268           0 :                                    EE_CHAR_FONTINFO);
     269           0 :             aSet.Put(aFontItem);
     270           0 :             aSet.Put(aFontItem, EE_CHAR_FONTINFO_CJK);
     271           0 :             aSet.Put(aFontItem, EE_CHAR_FONTINFO_CTL);
     272           0 :             pOV->SetAttribs(aSet);
     273             : 
     274           0 :             ESelection aSel = pOV->GetSelection();
     275           0 :             aSel.nStartPara = aSel.nEndPara;
     276           0 :             aSel.nStartPos = aSel.nEndPos;
     277           0 :             pOV->SetSelection(aSel);
     278             : 
     279             :             // do not go ahead with setting attributes of special characters
     280           0 :             pOV->GetOutliner()->QuickSetAttribs(aOldSet, aSel);
     281             : 
     282           0 :             rUndoMgr.LeaveListAction();
     283             : 
     284             :             // show it again
     285           0 :             pOL->SetUpdateMode(true);
     286           0 :             pOV->ShowCursor();
     287             :         }
     288           0 :     }
     289             : }
     290             : 
     291        4175 : void FuBullet::GetSlotState( SfxItemSet& rSet, ViewShell* pViewShell, SfxViewFrame* pViewFrame )
     292             : {
     293       12525 :     if( SfxItemState::DEFAULT == rSet.GetItemState( SID_CHARMAP ) ||
     294        8350 :         SfxItemState::DEFAULT == rSet.GetItemState( FN_INSERT_SOFT_HYPHEN ) ||
     295        8350 :         SfxItemState::DEFAULT == rSet.GetItemState( FN_INSERT_HARDHYPHEN ) ||
     296        8350 :         SfxItemState::DEFAULT == rSet.GetItemState( FN_INSERT_HARD_SPACE ) ||
     297        8350 :         SfxItemState::DEFAULT == rSet.GetItemState( SID_INSERT_RLM ) ||
     298        8350 :         SfxItemState::DEFAULT == rSet.GetItemState( SID_INSERT_LRM ) ||
     299       12525 :         SfxItemState::DEFAULT == rSet.GetItemState( SID_INSERT_ZWNBSP ) ||
     300        4175 :         SfxItemState::DEFAULT == rSet.GetItemState( SID_INSERT_ZWSP ))
     301             :     {
     302           0 :         ::sd::View* pView = pViewShell ? pViewShell->GetView() : 0;
     303           0 :         OutlinerView* pOLV = pView ? pView->GetTextEditOutlinerView() : 0;
     304             : 
     305           0 :         const bool bTextEdit = pOLV;
     306             : 
     307           0 :         SvtCTLOptions aCTLOptions;
     308           0 :         const bool bCtlEnabled = aCTLOptions.IsCTLFontEnabled();
     309             : 
     310           0 :         if(!bTextEdit )
     311             :         {
     312           0 :             rSet.DisableItem(FN_INSERT_SOFT_HYPHEN);
     313           0 :             rSet.DisableItem(FN_INSERT_HARDHYPHEN);
     314           0 :             rSet.DisableItem(FN_INSERT_HARD_SPACE);
     315             :         }
     316             : 
     317           0 :         if( !bTextEdit && (dynamic_cast<OutlineViewShell*>( pViewShell ) == 0) )
     318           0 :             rSet.DisableItem(SID_CHARMAP);
     319             : 
     320           0 :         if(!bTextEdit || !bCtlEnabled )
     321             :         {
     322           0 :             rSet.DisableItem(SID_INSERT_RLM);
     323           0 :             rSet.DisableItem(SID_INSERT_LRM);
     324           0 :             rSet.DisableItem(SID_INSERT_ZWNBSP);
     325           0 :             rSet.DisableItem(SID_INSERT_ZWSP);
     326             :         }
     327             : 
     328           0 :         if( pViewFrame )
     329             :         {
     330           0 :             SfxBindings& rBindings = pViewFrame->GetBindings();
     331             : 
     332           0 :             rBindings.SetVisibleState( SID_INSERT_RLM, bCtlEnabled );
     333           0 :             rBindings.SetVisibleState( SID_INSERT_LRM, bCtlEnabled );
     334           0 :             rBindings.SetVisibleState( SID_INSERT_ZWNBSP, bCtlEnabled );
     335           0 :             rBindings.SetVisibleState( SID_INSERT_ZWSP, bCtlEnabled );
     336           0 :         }
     337             :     }
     338        4175 : }
     339          66 : } // end of namespace sd
     340             : 
     341             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11