LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/main - ChartController_TextEdit.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 83 1.2 %
Date: 2012-12-27 Functions: 2 7 28.6 %
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 "ChartController.hxx"
      21             : 
      22             : #include "ResId.hxx"
      23             : #include "UndoGuard.hxx"
      24             : #include "DrawViewWrapper.hxx"
      25             : #include "ChartWindow.hxx"
      26             : #include "TitleHelper.hxx"
      27             : #include "ObjectIdentifier.hxx"
      28             : #include "macros.hxx"
      29             : #include "ControllerLockGuard.hxx"
      30             : #include "AccessibleTextHelper.hxx"
      31             : #include "Strings.hrc"
      32             : #include "chartview/DrawModelWrapper.hxx"
      33             : 
      34             : #include <svx/svdotext.hxx>
      35             : 
      36             : // header for define RET_OK
      37             : #include <vcl/msgbox.hxx>
      38             : // header for class SdrOutliner
      39             : #include <svx/svdoutl.hxx>
      40             : #include <svx/svxdlg.hxx>
      41             : #include <svx/dialogs.hrc>
      42             : #include <vcl/svapp.hxx>
      43             : #include <osl/mutex.hxx>
      44             : #include <com/sun/star/beans/XPropertySet.hpp>
      45             : #include <svl/stritem.hxx>
      46             : #include <editeng/fontitem.hxx>
      47             : 
      48             : //.............................................................................
      49             : namespace chart
      50             : {
      51             : //.............................................................................
      52             : using namespace ::com::sun::star;
      53             : 
      54             : //-----------------------------------------------------------------------------
      55             : //-----------------------------------------------------------------------------
      56             : 
      57           0 : void SAL_CALL ChartController::executeDispatch_EditText( const Point* pMousePixel )
      58             : {
      59           0 :     this->StartTextEdit( pMousePixel );
      60           0 : }
      61             : 
      62             : //-----------------------------------------------------------------------------
      63             : //-----------------------------------------------------------------------------
      64             : 
      65           0 : void ChartController::StartTextEdit( const Point* pMousePixel )
      66             : {
      67             :     //the first marked object will be edited
      68             : 
      69           0 :     SolarMutexGuard aGuard;
      70           0 :     SdrObject* pTextObj = m_pDrawViewWrapper->getTextEditObject();
      71           0 :     if(!pTextObj)
      72           0 :         return;
      73             : 
      74             :     OSL_PRECOND( !m_pTextActionUndoGuard.get(), "ChartController::StartTextEdit: already have a TextUndoGuard!?" );
      75             :     m_pTextActionUndoGuard.reset( new UndoGuard(
      76           0 :         String( SchResId( STR_ACTION_EDIT_TEXT ) ), m_xUndoManager ) );
      77           0 :     SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
      78             : 
      79             :     //#i77362 change notification for changes on additional shapes are missing
      80           0 :     uno::Reference< beans::XPropertySet > xChartViewProps( m_xChartView, uno::UNO_QUERY );
      81           0 :     if( xChartViewProps.is() )
      82           0 :         xChartViewProps->setPropertyValue( C2U("SdrViewIsInEditMode"), uno::makeAny(sal_True) );
      83             : 
      84             :     sal_Bool bEdit = m_pDrawViewWrapper->SdrBeginTextEdit( pTextObj
      85             :                     , m_pDrawViewWrapper->GetPageView()
      86             :                     , m_pChartWindow
      87             :                     , sal_False //bIsNewObj
      88             :                     , pOutliner
      89             :                     , 0L //pOutlinerView
      90             :                     , sal_True //bDontDeleteOutliner
      91             :                     , sal_True //bOnlyOneView
      92           0 :                     );
      93           0 :     if(bEdit)
      94             :     {
      95           0 :         m_pDrawViewWrapper->SetEditMode();
      96             : 
      97             :         // #i12587# support for shapes in chart
      98           0 :         if ( pMousePixel )
      99             :         {
     100           0 :             OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
     101           0 :             if ( pOutlinerView )
     102             :             {
     103           0 :                 MouseEvent aEditEvt( *pMousePixel, 1, MOUSE_SYNTHETIC, MOUSE_LEFT, 0 );
     104           0 :                 pOutlinerView->MouseButtonDown( aEditEvt );
     105           0 :                 pOutlinerView->MouseButtonUp( aEditEvt );
     106             :             }
     107             :         }
     108             : 
     109             :         //we invalidate the outliner region because the outliner has some
     110             :         //paint problems (some characters are painted twice a little bit shifted)
     111           0 :         m_pChartWindow->Invalidate( m_pDrawViewWrapper->GetMarkedObjBoundRect() );
     112           0 :     }
     113             : }
     114             : 
     115           0 : bool ChartController::EndTextEdit()
     116             : {
     117           0 :     m_pDrawViewWrapper->SdrEndTextEdit();
     118             : 
     119             :     //#i77362 change notification for changes on additional shapes are missing
     120           0 :     uno::Reference< beans::XPropertySet > xChartViewProps( m_xChartView, uno::UNO_QUERY );
     121           0 :     if( xChartViewProps.is() )
     122           0 :         xChartViewProps->setPropertyValue( C2U("SdrViewIsInEditMode"), uno::makeAny(sal_False) );
     123             : 
     124           0 :     SdrObject* pTextObject = m_pDrawViewWrapper->getTextEditObject();
     125           0 :     if(!pTextObject)
     126           0 :         return false;
     127             : 
     128           0 :     SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
     129           0 :     OutlinerParaObject* pParaObj = pTextObject->GetOutlinerParaObject();
     130           0 :     if( pParaObj && pOutliner )
     131             :     {
     132           0 :         pOutliner->SetText( *pParaObj );
     133             : 
     134             :         String aString = pOutliner->GetText(
     135             :                             pOutliner->GetParagraph( 0 ),
     136           0 :                             pOutliner->GetParagraphCount() );
     137             : 
     138           0 :         ::rtl::OUString aObjectCID = m_aSelection.getSelectedCID();
     139           0 :         if ( !aObjectCID.isEmpty() )
     140             :         {
     141             :             uno::Reference< beans::XPropertySet > xPropSet =
     142           0 :                 ObjectIdentifier::getObjectPropertySet( aObjectCID, getModel() );
     143             : 
     144             :             // lock controllers till end of block
     145           0 :             ControllerLockGuard aCLGuard( getModel() );
     146             : 
     147             :             TitleHelper::setCompleteString( aString, uno::Reference<
     148           0 :                 ::com::sun::star::chart2::XTitle >::query( xPropSet ), m_xCC );
     149             : 
     150             :             OSL_ENSURE( m_pTextActionUndoGuard.get(), "ChartController::EndTextEdit: no TextUndoGuard!" );
     151           0 :             if ( m_pTextActionUndoGuard.get() )
     152           0 :                 m_pTextActionUndoGuard->commit();
     153             :         }
     154           0 :         m_pTextActionUndoGuard.reset();
     155             :     }
     156           0 :     return true;
     157             : }
     158             : 
     159             : //-----------------------------------------------------------------------------
     160             : //-----------------------------------------------------------------------------
     161             : 
     162           0 : void SAL_CALL ChartController::executeDispatch_InsertSpecialCharacter()
     163             : {
     164           0 :     SolarMutexGuard aGuard;
     165             : 
     166           0 :     if( m_pDrawViewWrapper && !m_pDrawViewWrapper->IsTextEdit() )
     167           0 :         this->StartTextEdit();
     168             : 
     169           0 :     SvxAbstractDialogFactory * pFact = SvxAbstractDialogFactory::Create();
     170             :     OSL_ENSURE( pFact, "No dialog factory" );
     171             : 
     172           0 :     SfxAllItemSet aSet( m_pDrawModelWrapper->GetItemPool() );
     173           0 :     aSet.Put( SfxBoolItem( FN_PARAM_1, sal_False ) );
     174             : 
     175             :     //set fixed current font
     176           0 :     aSet.Put( SfxBoolItem( FN_PARAM_2, sal_True ) ); //maybe not necessary in future
     177             : 
     178           0 :     Font aCurFont = m_pDrawViewWrapper->getOutliner()->GetRefDevice()->GetFont();
     179           0 :     aSet.Put( SvxFontItem( aCurFont.GetFamily(), aCurFont.GetName(), aCurFont.GetStyleName(), aCurFont.GetPitch(), aCurFont.GetCharSet(), SID_ATTR_CHAR_FONT ) );
     180             : 
     181           0 :     SfxAbstractDialog * pDlg = pFact->CreateSfxDialog( m_pChartWindow, aSet, getFrame(), RID_SVXDLG_CHARMAP );
     182             :     OSL_ENSURE( pDlg, "Couldn't create SvxCharacterMap dialog" );
     183           0 :     if( pDlg->Execute() == RET_OK )
     184             :     {
     185           0 :         const SfxItemSet* pSet = pDlg->GetOutputItemSet();
     186           0 :         const SfxPoolItem* pItem=0;
     187           0 :         String aString;
     188           0 :         if ( pSet && pSet->GetItemState( SID_CHARMAP, sal_True, &pItem) == SFX_ITEM_SET &&
     189           0 :              pItem->ISA(SfxStringItem) )
     190           0 :                 aString = dynamic_cast<const SfxStringItem*>(pItem)->GetValue();
     191             : 
     192           0 :         OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
     193           0 :         SdrOutliner*  pOutliner = m_pDrawViewWrapper->getOutliner();
     194             : 
     195           0 :         if(!pOutliner || !pOutlinerView)
     196           0 :             return;
     197             : 
     198             :         // insert string to outliner
     199             : 
     200             :         // prevent flicker
     201           0 :         pOutlinerView->HideCursor();
     202           0 :         pOutliner->SetUpdateMode(sal_False);
     203             : 
     204             :         // delete current selection by inserting empty String, so current
     205             :         // attributes become unique (sel. has to be erased anyway)
     206           0 :         pOutlinerView->InsertText(String());
     207             : 
     208           0 :         pOutlinerView->InsertText(aString, true);
     209             : 
     210           0 :         ESelection aSel = pOutlinerView->GetSelection();
     211           0 :         aSel.nStartPara = aSel.nEndPara;
     212           0 :         aSel.nStartPos = aSel.nEndPos;
     213           0 :         pOutlinerView->SetSelection(aSel);
     214             : 
     215             :         // show changes
     216           0 :         pOutliner->SetUpdateMode(sal_True);
     217           0 :         pOutlinerView->ShowCursor();
     218             :     }
     219             : 
     220           0 :     delete pDlg;
     221             : }
     222             : 
     223             : uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
     224           0 :     ChartController::impl_createAccessibleTextContext()
     225             : {
     226             :     uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > xResult(
     227           0 :         new AccessibleTextHelper( m_pDrawViewWrapper ));
     228             : 
     229           0 :     return xResult;
     230             : }
     231             : 
     232             : 
     233             : //.............................................................................
     234           3 : } //namespace chart
     235             : //.............................................................................
     236             : 
     237             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10