LCOV - code coverage report
Current view: top level - sw/source/uibase/uiview - viewling.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 18 412 4.4 %
Date: 2014-11-03 Functions: 4 27 14.8 %
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             : 
      22             : #include <com/sun/star/lang/Locale.hpp>
      23             : #include <com/sun/star/linguistic2/XThesaurus.hpp>
      24             : #include <com/sun/star/linguistic2/ProofreadingResult.hpp>
      25             : #include <com/sun/star/i18n/TextConversionOption.hpp>
      26             : #include <linguistic/lngprops.hxx>
      27             : #include <comphelper/processfactory.hxx>
      28             : #include <toolkit/helper/vclunohelper.hxx>
      29             : #include <vcl/msgbox.hxx>
      30             : #include <svtools/ehdl.hxx>
      31             : #include <svl/stritem.hxx>
      32             : #include <sfx2/viewfrm.hxx>
      33             : #include <sfx2/request.hxx>
      34             : #include <svx/dlgutil.hxx>
      35             : #include <svx/dialmgr.hxx>
      36             : #include <editeng/langitem.hxx>
      37             : #include <svx/svxerr.hxx>
      38             : #include <editeng/unolingu.hxx>
      39             : #include <svx/svxdlg.hxx>
      40             : #include <editeng/SpellPortions.hxx>
      41             : #include <swmodule.hxx>
      42             : #include <swwait.hxx>
      43             : #include <initui.hxx>
      44             : #include <uitool.hxx>
      45             : #include <view.hxx>
      46             : #include <wrtsh.hxx>
      47             : #include <basesh.hxx>
      48             : #include <docsh.hxx>
      49             : #include <viewopt.hxx>
      50             : #include <swundo.hxx>
      51             : #include <hyp.hxx>
      52             : #include <olmenu.hxx>
      53             : #include <pam.hxx>
      54             : #include <edtwin.hxx>
      55             : #include <crsskip.hxx>
      56             : #include <ndtxt.hxx>
      57             : #include <vcl/lstbox.hxx>
      58             : #include <cmdid.h>
      59             : #include <globals.hrc>
      60             : #include <comcore.hrc>
      61             : #include <view.hrc>
      62             : #include <hhcwrp.hxx>
      63             : #include <com/sun/star/frame/XStorable.hpp>
      64             : 
      65             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      66             : #include <com/sun/star/lang/XInitialization.hpp>
      67             : #include <com/sun/star/frame/XDispatch.hpp>
      68             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      69             : #include <com/sun/star/frame/XFrame.hpp>
      70             : #include <com/sun/star/util/URL.hpp>
      71             : #include <com/sun/star/beans/PropertyValue.hpp>
      72             : #include <com/sun/star/util/URLTransformer.hpp>
      73             : #include <com/sun/star/util/XURLTransformer.hpp>
      74             : 
      75             : #include <vcl/svapp.hxx>
      76             : #include <rtl/ustring.hxx>
      77             : 
      78             : #include <cppuhelper/bootstrap.hxx>
      79             : #include "stmenu.hxx"
      80             : #include <svx/dialogs.hrc>
      81             : #include <svtools/langtab.hxx>
      82             : #include <unomid.h>
      83             : #include <IMark.hxx>
      84             : #include <xmloff/odffields.hxx>
      85             : 
      86             : #include <editeng/editerr.hxx>
      87             : 
      88             : #include <boost/scoped_ptr.hpp>
      89             : 
      90             : using namespace sw::mark;
      91             : using namespace ::com::sun::star;
      92             : using namespace ::com::sun::star::beans;
      93             : using namespace ::com::sun::star::uno;
      94             : using namespace ::com::sun::star::linguistic2;
      95             : using namespace ::com::sun::star::smarttags;
      96             : 
      97             : // Lingu-Dispatcher
      98             : 
      99           0 : void SwView::ExecLingu(SfxRequest &rReq)
     100             : {
     101           0 :     switch(rReq.GetSlot())
     102             :     {
     103             :         case SID_THESAURUS:
     104           0 :             StartThesaurus();
     105           0 :             rReq.Ignore();
     106           0 :             break;
     107             :         case SID_HANGUL_HANJA_CONVERSION:
     108             :             StartTextConversion( LANGUAGE_KOREAN, LANGUAGE_KOREAN, NULL,
     109           0 :                     i18n::TextConversionOption::CHARACTER_BY_CHARACTER, true );
     110           0 :             break;
     111             :         case SID_CHINESE_CONVERSION:
     112             :         {
     113             :             //open ChineseTranslationDialog
     114             :             Reference< XComponentContext > xContext(
     115           0 :                 ::cppu::defaultBootstrap_InitialComponentContext() ); //@todo get context from calc if that has one
     116           0 :             if(xContext.is())
     117             :             {
     118           0 :                 Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
     119           0 :                 if(xMCF.is())
     120             :                 {
     121             :                     Reference< ui::dialogs::XExecutableDialog > xDialog(
     122           0 :                             xMCF->createInstanceWithContext(
     123             :                                 OUString("com.sun.star.linguistic2.ChineseTranslationDialog")
     124           0 :                                 , xContext), UNO_QUERY);
     125           0 :                     Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
     126           0 :                     if( xInit.is() )
     127             :                     {
     128             :                         //  initialize dialog
     129           0 :                         Reference< awt::XWindow > xDialogParentWindow(0);
     130           0 :                         Sequence<Any> aSeq(1);
     131           0 :                         Any* pArray = aSeq.getArray();
     132           0 :                         PropertyValue aParam;
     133           0 :                         aParam.Name = "ParentWindow";
     134           0 :                         aParam.Value <<= makeAny(xDialogParentWindow);
     135           0 :                         pArray[0] <<= makeAny(aParam);
     136           0 :                         xInit->initialize( aSeq );
     137             : 
     138             :                         //execute dialog
     139           0 :                         sal_Int16 nDialogRet = xDialog->execute();
     140           0 :                         if( RET_OK == nDialogRet )
     141             :                         {
     142             :                             //get some parameters from the dialog
     143           0 :                             bool bToSimplified = true;
     144           0 :                             bool bUseVariants = true;
     145           0 :                             bool bCommonTerms = true;
     146           0 :                             Reference< beans::XPropertySet >  xProp( xDialog, UNO_QUERY );
     147           0 :                             if( xProp.is() )
     148             :                             {
     149             :                                 try
     150             :                                 {
     151           0 :                                     xProp->getPropertyValue( "IsDirectionToSimplified" ) >>= bToSimplified;
     152           0 :                                     xProp->getPropertyValue( "IsUseCharacterVariants" ) >>= bUseVariants;
     153           0 :                                     xProp->getPropertyValue( "IsTranslateCommonTerms" ) >>= bCommonTerms;
     154             :                                 }
     155           0 :                                 catch (const Exception&)
     156             :                                 {
     157             :                                 }
     158             :                             }
     159             : 
     160             :                             //execute translation
     161           0 :                             sal_Int16 nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
     162           0 :                             sal_Int16 nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
     163           0 :                             sal_Int32 nOptions    = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
     164           0 :                             if( !bCommonTerms )
     165           0 :                                 nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
     166             : 
     167             :                             vcl::Font aTargetFont = OutputDevice::GetDefaultFont( DEFAULTFONT_CJK_TEXT,
     168           0 :                                                     nTargetLang, DEFAULTFONT_FLAGS_ONLYONE );
     169             : 
     170             :                             // disallow formatting, updating the view, ... while
     171             :                             // converting the document. (saves time)
     172             :                             // Also remember the current view and cursor position for later
     173           0 :                             m_pWrtShell->StartAction();
     174             : 
     175             :                             // remember cursor position data for later restoration of the cursor
     176           0 :                             const SwPosition *pPoint = m_pWrtShell->GetCrsr()->GetPoint();
     177           0 :                             bool bRestoreCursor = pPoint->nNode.GetNode().IsTxtNode();
     178           0 :                             const SwNodeIndex aPointNodeIndex( pPoint->nNode );
     179           0 :                             sal_Int32 nPointIndex = pPoint->nContent.GetIndex();
     180             : 
     181             :                             // since this conversion is not interactive the whole converted
     182             :                             // document should be undone in a single undo step.
     183           0 :                             m_pWrtShell->StartUndo( UNDO_OVERWRITE );
     184             : 
     185           0 :                             StartTextConversion( nSourceLang, nTargetLang, &aTargetFont, nOptions, false );
     186             : 
     187           0 :                             m_pWrtShell->EndUndo( UNDO_OVERWRITE );
     188             : 
     189           0 :                             if (bRestoreCursor)
     190             :                             {
     191           0 :                                 SwTxtNode *pTxtNode = aPointNodeIndex.GetNode().GetTxtNode();
     192             :                                 // check for unexpected error case
     193             :                                 OSL_ENSURE(pTxtNode && pTxtNode->GetTxt().getLength() >= nPointIndex,
     194             :                                     "text missing: corrupted node?" );
     195           0 :                                 if (!pTxtNode || pTxtNode->GetTxt().getLength() < nPointIndex)
     196           0 :                                     nPointIndex = 0;
     197             :                                 // restore cursor to its original position
     198           0 :                                 m_pWrtShell->GetCrsr()->GetPoint()->nContent.Assign( pTxtNode, nPointIndex );
     199             :                             }
     200             : 
     201             :                             // enable all, restore view and cursor position
     202           0 :                             m_pWrtShell->EndAction();
     203           0 :                         }
     204             :                     }
     205           0 :                     Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
     206           0 :                     if( xComponent.is() )
     207           0 :                         xComponent->dispose();
     208           0 :                 }
     209             :             }
     210           0 :             break;
     211             :         }
     212             :         case FN_HYPHENATE_OPT_DLG:
     213           0 :             HyphenateDocument();
     214           0 :             break;
     215             :         default:
     216             :             OSL_ENSURE(false, "wrong Dispatcher");
     217           0 :             return;
     218             :     }
     219             : }
     220             : 
     221             : // start language specific text conversion
     222             : 
     223           0 : void SwView::StartTextConversion(
     224             :         LanguageType nSourceLang,
     225             :         LanguageType nTargetLang,
     226             :         const vcl::Font *pTargetFont,
     227             :         sal_Int32 nOptions,
     228             :         bool bIsInteractive )
     229             : {
     230             :     // do not do text conversion if it is active elsewhere
     231           0 :     if (GetWrtShell().HasConvIter())
     232             :     {
     233           0 :         return;
     234             :     }
     235             : 
     236           0 :     SpellKontext(true);
     237             : 
     238           0 :     const SwViewOption* pVOpt = m_pWrtShell->GetViewOptions();
     239           0 :     const bool bOldIdle = pVOpt->IsIdle();
     240           0 :     pVOpt->SetIdle( false );
     241             : 
     242           0 :     bool bOldIns = m_pWrtShell->IsInsMode();
     243           0 :     m_pWrtShell->SetInsMode( true );
     244             : 
     245           0 :     const bool bSelection = ((SwCrsrShell*)m_pWrtShell)->HasSelection() ||
     246           0 :         m_pWrtShell->GetCrsr() != m_pWrtShell->GetCrsr()->GetNext();
     247             : 
     248           0 :     const bool  bStart = bSelection || m_pWrtShell->IsStartOfDoc();
     249           0 :     const bool  bOther = !bSelection && !(m_pWrtShell->GetFrmType(0,true) & FRMTYPE_BODY);
     250             : 
     251             :     {
     252             :         const uno::Reference< uno::XComponentContext > xContext(
     253           0 :                     comphelper::getProcessComponentContext() );
     254             :         SwHHCWrapper aWrap( this, xContext, nSourceLang, nTargetLang, pTargetFont,
     255             :                             nOptions, bIsInteractive,
     256           0 :                             bStart, bOther, bSelection );
     257           0 :         aWrap.Convert();
     258             :     }
     259             : 
     260           0 :     m_pWrtShell->SetInsMode( bOldIns );
     261           0 :     pVOpt->SetIdle( bOldIdle );
     262           0 :     SpellKontext(false);
     263             : }
     264             : 
     265             : // spellcheck and text conversion related stuff
     266             : 
     267           8 : void SwView::SpellStart( SvxSpellArea eWhich,
     268             :         bool bStartDone, bool bEndDone,
     269             :         SwConversionArgs *pConvArgs )
     270             : {
     271           8 :     Reference< XLinguProperties >  xProp = ::GetLinguPropertySet();
     272           8 :     bool bIsWrapReverse = (!pConvArgs && xProp.is()) ? xProp->getIsWrapReverse() : sal_False;
     273             : 
     274           8 :     SwDocPositions eStart = DOCPOS_START;
     275           8 :     SwDocPositions eEnde  = DOCPOS_END;
     276           8 :     SwDocPositions eCurr  = DOCPOS_CURR;
     277           8 :     switch ( eWhich )
     278             :     {
     279             :         case SVX_SPELL_BODY:
     280           0 :             if( bIsWrapReverse )
     281           0 :                 eCurr = DOCPOS_END;
     282             :             else
     283           0 :                 eCurr = DOCPOS_START;
     284           0 :             break;
     285             :         case SVX_SPELL_BODY_END:
     286           8 :             if( bIsWrapReverse )
     287             :             {
     288           0 :                 if( bStartDone )
     289           0 :                     eStart = DOCPOS_CURR;
     290           0 :                 eCurr = DOCPOS_END;
     291             :             }
     292           8 :             else if( bStartDone )
     293           8 :                 eCurr = DOCPOS_START;
     294           8 :             break;
     295             :         case SVX_SPELL_BODY_START:
     296           0 :             if( !bIsWrapReverse )
     297             :             {
     298           0 :                 if( bEndDone )
     299           0 :                     eEnde = DOCPOS_CURR;
     300           0 :                 eCurr = DOCPOS_START;
     301             :             }
     302           0 :             else if( bEndDone )
     303           0 :                 eCurr = DOCPOS_END;
     304           0 :             break;
     305             :         case SVX_SPELL_OTHER:
     306           0 :             if( bIsWrapReverse )
     307             :             {
     308           0 :                 eStart = DOCPOS_OTHERSTART;
     309           0 :                 eEnde  = DOCPOS_OTHEREND;
     310           0 :                 eCurr = DOCPOS_OTHEREND;
     311             :             }
     312             :             else
     313             :             {
     314           0 :                 eStart = DOCPOS_OTHERSTART;
     315           0 :                 eEnde  = DOCPOS_OTHEREND;
     316           0 :                 eCurr = DOCPOS_OTHERSTART;
     317             :             }
     318           0 :             break;
     319             :         default:
     320             :             OSL_ENSURE( false, "SpellStart with unknown Area" );
     321             :     }
     322           8 :     m_pWrtShell->SpellStart( eStart, eEnde, eCurr, pConvArgs );
     323           8 : }
     324             : 
     325             : // Error message while Spelling
     326             : 
     327             : // The passed pointer nlang is itself the value
     328           0 : void SwView::SpellError(LanguageType eLang)
     329             : {
     330             : #if OSL_DEBUG_LEVEL > 1
     331             :     sal_Bool bFocus = GetEditWin().HasFocus();
     332             : #endif
     333           0 :     int nPend = 0;
     334             : 
     335           0 :     if ( m_pWrtShell->ActionPend() )
     336             :     {
     337           0 :         m_pWrtShell->Push();
     338           0 :         m_pWrtShell->ClearMark();
     339           0 :         do
     340             :         {
     341           0 :             m_pWrtShell->EndAction();
     342           0 :             ++nPend;
     343             :         }
     344           0 :         while( m_pWrtShell->ActionPend() );
     345             :     }
     346           0 :     OUString aErr(SvtLanguageTable::GetLanguageString( eLang ) );
     347             : 
     348           0 :     SwEditWin &rEditWin = GetEditWin();
     349             : #if OSL_DEBUG_LEVEL > 1
     350             :     bFocus = rEditWin.HasFocus();
     351             : #endif
     352           0 :     int nWaitCnt = 0;
     353           0 :     while( rEditWin.IsWait() )
     354             :     {
     355           0 :         rEditWin.LeaveWait();
     356           0 :         ++nWaitCnt;
     357             :     }
     358           0 :     if ( LANGUAGE_NONE == eLang )
     359           0 :         ErrorHandler::HandleError( ERRCODE_SVX_LINGU_NOLANGUAGE );
     360             :     else
     361           0 :         ErrorHandler::HandleError( *new StringErrorInfo( ERRCODE_SVX_LINGU_LANGUAGENOTEXISTS, aErr ) );
     362             : 
     363           0 :     while( nWaitCnt )
     364             :     {
     365           0 :         rEditWin.EnterWait();
     366           0 :         --nWaitCnt;
     367             :     }
     368             : #if OSL_DEBUG_LEVEL > 1
     369             :     bFocus = GetEditWin().HasFocus();
     370             : #endif
     371             : 
     372           0 :     if ( nPend )
     373             :     {
     374           0 :         while( nPend-- )
     375           0 :             m_pWrtShell->StartAction();
     376           0 :         m_pWrtShell->Combine();
     377           0 :     }
     378             : #if OSL_DEBUG_LEVEL > 1
     379             :     if( !bFocus )
     380             :         GetEditWin().GrabFocus();
     381             : #endif
     382             : 
     383           0 : }
     384             : 
     385             : // Finish spelling and restore cursor
     386             : 
     387          16 : void SwView::SpellEnd( SwConversionArgs *pConvArgs )
     388             : {
     389          16 :     m_pWrtShell->SpellEnd( pConvArgs );
     390          16 :     if( m_pWrtShell->IsExtMode() )
     391           0 :         m_pWrtShell->SetMark();
     392          16 : }
     393             : 
     394           0 : void SwView::HyphStart( SvxSpellArea eWhich )
     395             : {
     396           0 :     switch ( eWhich )
     397             :     {
     398             :         case SVX_SPELL_BODY:
     399           0 :             m_pWrtShell->HyphStart( DOCPOS_START, DOCPOS_END );
     400           0 :             break;
     401             :         case SVX_SPELL_BODY_END:
     402           0 :             m_pWrtShell->HyphStart( DOCPOS_CURR, DOCPOS_END );
     403           0 :             break;
     404             :         case SVX_SPELL_BODY_START:
     405           0 :             m_pWrtShell->HyphStart( DOCPOS_START, DOCPOS_CURR );
     406           0 :             break;
     407             :         case SVX_SPELL_OTHER:
     408           0 :             m_pWrtShell->HyphStart( DOCPOS_OTHERSTART, DOCPOS_OTHEREND );
     409           0 :             break;
     410             :         default:
     411             :             OSL_ENSURE( false, "HyphStart with unknown Area" );
     412             :     }
     413           0 : }
     414             : 
     415             : // Interactive separation
     416             : 
     417           0 : void SwView::HyphenateDocument()
     418             : {
     419             :     // do not hyphenate if interactive hyphenation is active elsewhere
     420           0 :     if (GetWrtShell().HasHyphIter())
     421             :     {
     422             :         MessBox( 0, WB_OK, OUString( SW_RES( STR_HYPH_TITLE ) ),
     423           0 :                 OUString( SW_RES( STR_MULT_INTERACT_HYPH_WARN ) ) ).Execute();
     424           0 :         return;
     425             :     }
     426             : 
     427             :     SfxErrorContext aContext( ERRCTX_SVX_LINGU_HYPHENATION, OUString(), m_pEditWin,
     428           0 :          RID_SVXERRCTX, &DIALOG_MGR() );
     429             : 
     430           0 :     Reference< XHyphenator >  xHyph( ::GetHyphenator() );
     431           0 :     if (!xHyph.is())
     432             :     {
     433           0 :         ErrorHandler::HandleError( ERRCODE_SVX_LINGU_LINGUNOTEXISTS );
     434           0 :         return;
     435             :     }
     436             : 
     437           0 :     if (m_pWrtShell->GetSelectionType() & (nsSelectionType::SEL_DRW_TXT|nsSelectionType::SEL_DRW))
     438             :     {
     439             :         // Hyphenation in a Draw object
     440           0 :         HyphenateDrawText();
     441             :     }
     442             :     else
     443             :     {
     444           0 :         SwViewOption* pVOpt = (SwViewOption*)m_pWrtShell->GetViewOptions();
     445           0 :         bool bOldIdle = pVOpt->IsIdle();
     446           0 :         pVOpt->SetIdle( false );
     447             : 
     448           0 :         Reference< XLinguProperties >  xProp( ::GetLinguPropertySet() );
     449             : 
     450           0 :         m_pWrtShell->StartUndo(UNDO_INSATTR);         // valid later
     451             : 
     452           0 :         bool bHyphSpecial = xProp.is() ? xProp->getIsHyphSpecial() : sal_False;
     453           0 :         bool bSelection = ((SwCrsrShell*)m_pWrtShell)->HasSelection() ||
     454           0 :             m_pWrtShell->GetCrsr() != m_pWrtShell->GetCrsr()->GetNext();
     455           0 :         bool bOther = m_pWrtShell->HasOtherCnt() && bHyphSpecial && !bSelection;
     456           0 :         bool bStart = bSelection || ( !bOther && m_pWrtShell->IsStartOfDoc() );
     457           0 :         bool bStop = false;
     458           0 :         if( !bOther && !(m_pWrtShell->GetFrmType(0,true) & FRMTYPE_BODY) && !bSelection )
     459             :         // turned on no special area
     460             :         {
     461             :             // I want also in special areas hyphenation
     462           0 :             MessageDialog aBox(&GetEditWin(), SW_RES(STR_QUERY_SPECIAL_FORCED), VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
     463           0 :             if( aBox.Execute() == RET_YES )
     464             :             {
     465           0 :                 bOther = true;
     466           0 :                 if (xProp.is())
     467             :                 {
     468           0 :                     xProp->setIsHyphSpecial( sal_True );
     469             :                 }
     470             :             }
     471             :             else
     472           0 :                 bStop = true; // No hyphenation
     473             :         }
     474             : 
     475           0 :         if( !bStop )
     476             :         {
     477           0 :             SwHyphWrapper aWrap( this, xHyph, bStart, bOther, bSelection );
     478           0 :             aWrap.SpellDocument();
     479           0 :             m_pWrtShell->EndUndo(UNDO_INSATTR);
     480             :         }
     481           0 :         pVOpt->SetIdle( bOldIdle );
     482           0 :     }
     483             : }
     484             : 
     485           0 : bool SwView::IsValidSelectionForThesaurus() const
     486             : {
     487             :     // must not be a multi-selection, and if it is a selection it needs
     488             :     // to be within a single paragraph
     489             : 
     490           0 :     const bool bMultiSel = m_pWrtShell->GetCrsr() != m_pWrtShell->GetCrsr()->GetNext();
     491           0 :     const bool bSelection = ((SwCrsrShell*)m_pWrtShell)->HasSelection();
     492           0 :     return !bMultiSel && (!bSelection || m_pWrtShell->IsSelOnePara() );
     493             : }
     494             : 
     495           0 : OUString SwView::GetThesaurusLookUpText( bool bSelection ) const
     496             : {
     497           0 :     return bSelection ? OUString(m_pWrtShell->GetSelTxt()) : m_pWrtShell->GetCurWord();
     498             : }
     499             : 
     500           0 : void SwView::InsertThesaurusSynonym( const OUString &rSynonmText, const OUString &rLookUpText, bool bSelection )
     501             : {
     502           0 :     bool bOldIns = m_pWrtShell->IsInsMode();
     503           0 :     m_pWrtShell->SetInsMode( true );
     504             : 
     505           0 :     m_pWrtShell->StartAllAction();
     506           0 :     m_pWrtShell->StartUndo(UNDO_DELETE);
     507             : 
     508           0 :     if( !bSelection )
     509             :     {
     510           0 :         if(m_pWrtShell->IsEndWrd())
     511           0 :             m_pWrtShell->Left(CRSR_SKIP_CELLS, false, 1, false );
     512             : 
     513           0 :         m_pWrtShell->SelWrd();
     514             : 
     515             :         // make sure the selection build later from the data below does not
     516             :         // include "in word" character to the left and right in order to
     517             :         // preserve those. Therefore count those "in words" in order to modify
     518             :         // the selection accordingly.
     519           0 :         const sal_Unicode* pChar = rLookUpText.getStr();
     520           0 :         sal_Int32 nLeft = 0;
     521           0 :         while (pChar && *pChar++ == CH_TXTATR_INWORD)
     522           0 :             ++nLeft;
     523           0 :         pChar = rLookUpText.getLength() ? rLookUpText.getStr() + rLookUpText.getLength() - 1 : 0;
     524           0 :         sal_Int32 nRight = 0;
     525           0 :         while (pChar && *pChar-- == CH_TXTATR_INWORD)
     526           0 :             ++nRight;
     527             : 
     528             :         // adjust existing selection
     529           0 :         SwPaM *pCrsr = m_pWrtShell->GetCrsr();
     530           0 :         pCrsr->GetPoint()->nContent -= nRight;
     531           0 :         pCrsr->GetMark()->nContent += nLeft;
     532             :     }
     533             : 
     534           0 :     m_pWrtShell->Insert( rSynonmText );
     535             : 
     536           0 :     m_pWrtShell->EndUndo(UNDO_DELETE);
     537           0 :     m_pWrtShell->EndAllAction();
     538             : 
     539           0 :     m_pWrtShell->SetInsMode( bOldIns );
     540           0 : }
     541             : 
     542             : // Start thesaurus
     543             : 
     544           0 : void SwView::StartThesaurus()
     545             : {
     546           0 :     if (!IsValidSelectionForThesaurus())
     547           0 :         return;
     548             : 
     549             :     SfxErrorContext aContext( ERRCTX_SVX_LINGU_THESAURUS, OUString(), m_pEditWin,
     550           0 :          RID_SVXERRCTX, &DIALOG_MGR() );
     551             : 
     552             :     // Determine language
     553           0 :     LanguageType eLang = m_pWrtShell->GetCurLang();
     554           0 :     if( LANGUAGE_SYSTEM == eLang )
     555           0 :        eLang = GetAppLanguage();
     556             : 
     557           0 :     if( eLang == LANGUAGE_DONTKNOW || eLang == LANGUAGE_NONE )
     558             :     {
     559           0 :         SpellError( LANGUAGE_NONE );
     560           0 :         return;
     561             :     }
     562             : 
     563           0 :     SwViewOption* pVOpt = (SwViewOption*)m_pWrtShell->GetViewOptions();
     564           0 :     bool bOldIdle = pVOpt->IsIdle();
     565           0 :     pVOpt->SetIdle( false );
     566             : 
     567             :     // get initial LookUp text
     568           0 :     const bool bSelection = ((SwCrsrShell*)m_pWrtShell)->HasSelection();
     569           0 :     OUString aTmp = GetThesaurusLookUpText( bSelection );
     570             : 
     571           0 :     Reference< XThesaurus >  xThes( ::GetThesaurus() );
     572             : 
     573           0 :     if ( !xThes.is() || !xThes->hasLocale( LanguageTag::convertToLocale( eLang ) ) )
     574           0 :         SpellError( eLang );
     575             :     else
     576             :     {
     577           0 :         boost::scoped_ptr<AbstractThesaurusDialog> pDlg;
     578             :         // create dialog
     579             :         {   //Scope for SwWait-Object
     580           0 :             SwWait aWait( *GetDocShell(), true );
     581             :             // load library with dialog only on demand ...
     582           0 :             SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     583           0 :             pDlg.reset(pFact->CreateThesaurusDialog( &GetEditWin(), xThes, aTmp, eLang ));
     584             :         }
     585             : 
     586           0 :         if ( pDlg->Execute()== RET_OK )
     587           0 :             InsertThesaurusSynonym( pDlg->GetWord(), aTmp, bSelection );
     588             :     }
     589             : 
     590           0 :     pVOpt->SetIdle( bOldIdle );
     591             : }
     592             : 
     593             : // Offer online suggestions
     594             : 
     595             : //!! Start of extra code for context menu modifying extensions
     596           0 : struct ExecuteInfo
     597             : {
     598             :     uno::Reference< frame::XDispatch >  xDispatch;
     599             :     util::URL                           aTargetURL;
     600             :     uno::Sequence< PropertyValue >      aArgs;
     601             : };
     602             : 
     603             : class AsyncExecute
     604             : {
     605             : public:
     606             :     DECL_STATIC_LINK( AsyncExecute, ExecuteHdl_Impl, ExecuteInfo* );
     607             : };
     608             : 
     609           0 : IMPL_STATIC_LINK_NOINSTANCE( AsyncExecute, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
     610             : {
     611           0 :     const sal_uInt32 nRef = Application::ReleaseSolarMutex();
     612             :     try
     613             :     {
     614             :         // Asynchronous execution as this can lead to our own destruction!
     615             :         // Framework can recycle our current frame and the layout manager disposes all user interface
     616             :         // elements if a component gets detached from its frame!
     617           0 :         pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
     618             :     }
     619           0 :     catch (const Exception&)
     620             :     {
     621             :     }
     622             : 
     623           0 :     Application::AcquireSolarMutex( nRef );
     624           0 :     delete pExecuteInfo;
     625           0 :     return 0;
     626             : }
     627             : //!! End of extra code for context menu modifying extensions
     628             : 
     629           0 : bool SwView::ExecSpellPopup(const Point& rPt)
     630             : {
     631           0 :     bool bRet = false;
     632           0 :     const SwViewOption* pVOpt = m_pWrtShell->GetViewOptions();
     633           0 :     if( pVOpt->IsOnlineSpell() &&
     634           0 :         !m_pWrtShell->IsSelection())
     635             :     {
     636           0 :         if (m_pWrtShell->GetSelectionType() & nsSelectionType::SEL_DRW_TXT)
     637           0 :             bRet = ExecDrwTxtSpellPopup(rPt);
     638           0 :         else if (!m_pWrtShell->IsSelFrmMode())
     639             :         {
     640           0 :             const bool bOldViewLock = m_pWrtShell->IsViewLocked();
     641           0 :             m_pWrtShell->LockView( true );
     642           0 :             m_pWrtShell->Push();
     643           0 :             SwRect aToFill;
     644             : 
     645             :             // decide which variant of the context menu to use...
     646             :             // if neither spell checking nor grammar checking provides suggestions use the
     647             :             // default context menu.
     648           0 :             bool bUseGrammarContext = false;
     649           0 :             Reference< XSpellAlternatives >  xAlt( m_pWrtShell->GetCorrection(&rPt, aToFill) );
     650           0 :             ProofreadingResult aGrammarCheckRes;
     651           0 :             sal_Int32 nErrorInResult = -1;
     652           0 :             uno::Sequence< OUString > aSuggestions;
     653           0 :             bool bCorrectionRes = false;
     654           0 :             if (!xAlt.is() || xAlt->getAlternatives().getLength() == 0)
     655             :             {
     656           0 :                 sal_Int32 nErrorPosInText = -1;
     657           0 :                 bCorrectionRes = m_pWrtShell->GetGrammarCorrection( aGrammarCheckRes, nErrorPosInText, nErrorInResult, aSuggestions, &rPt, aToFill );
     658           0 :                 OUString aMessageText;
     659           0 :                 if (nErrorInResult >= 0)
     660           0 :                     aMessageText = aGrammarCheckRes.aErrors[ nErrorInResult ].aShortComment;
     661             :                 // we like to use the grammar checking context menu if we either get
     662             :                 // some suggestions or at least a comment about the error found...
     663           0 :                 bUseGrammarContext = bCorrectionRes &&
     664           0 :                         (aSuggestions.getLength() > 0 || !aMessageText.isEmpty());
     665             :             }
     666             : 
     667             :             // open respective context menu for spell check or grammar errors with correction suggestions...
     668           0 :             if ((!bUseGrammarContext && xAlt.is()) ||
     669           0 :                 (bUseGrammarContext && bCorrectionRes && aGrammarCheckRes.aErrors.getLength() > 0))
     670             :             {
     671             :                 // get paragraph text
     672           0 :                 OUString aParaText;
     673           0 :                 SwPosition aPoint( *m_pWrtShell->GetCrsr()->GetPoint() );
     674             :                 const SwTxtNode *pNode = dynamic_cast< const SwTxtNode * >(
     675           0 :                                             &aPoint.nNode.GetNode() );
     676           0 :                 if (pNode)
     677           0 :                     aParaText = pNode->GetTxt();    // this may include hidden text but that should be Ok
     678             :                 else
     679             :                 {
     680             :                     OSL_FAIL("text node expected but not found" );
     681             :                 }
     682             : 
     683           0 :                 bRet = true;
     684           0 :                 m_pWrtShell->SttSelect();
     685           0 :                 boost::scoped_ptr< SwSpellPopup > pPopup;
     686           0 :                 if (bUseGrammarContext)
     687             :                 {
     688           0 :                     sal_Int32 nPos = aPoint.nContent.GetIndex();
     689             :                     (void) nPos;
     690           0 :                     pPopup.reset(new SwSpellPopup( m_pWrtShell, aGrammarCheckRes, nErrorInResult, aSuggestions, aParaText ));
     691             :                 }
     692             :                 else
     693           0 :                     pPopup.reset(new SwSpellPopup( m_pWrtShell, xAlt, aParaText ));
     694           0 :                 ui::ContextMenuExecuteEvent aEvent;
     695           0 :                 const Point aPixPos = GetEditWin().LogicToPixel( rPt );
     696             : 
     697           0 :                 aEvent.SourceWindow = VCLUnoHelper::GetInterface( m_pEditWin );
     698           0 :                 aEvent.ExecutePosition.X = aPixPos.X();
     699           0 :                 aEvent.ExecutePosition.Y = aPixPos.Y();
     700           0 :                 Menu* pMenu = 0;
     701             : 
     702             :                 OUString sMenuName  = bUseGrammarContext ?
     703           0 :                     OUString("private:resource/GrammarContextMenu") : OUString("private:resource/SpellContextMenu");
     704           0 :                 if(TryContextMenuInterception( *pPopup, sMenuName, pMenu, aEvent ))
     705             :                 {
     706             : 
     707             :                     //! happy hacking for context menu modifying extensions of this
     708             :                     //! 'custom made' menu... *sigh* (code copied from sfx2 and framework)
     709           0 :                     if ( pMenu )
     710             :                     {
     711           0 :                         const sal_uInt16 nId = ((PopupMenu*)pMenu)->Execute(m_pEditWin, aPixPos);
     712           0 :                         OUString aCommand = ((PopupMenu*)pMenu)->GetItemCommand(nId);
     713           0 :                         if (aCommand.isEmpty() )
     714             :                         {
     715           0 :                             if(!ExecuteMenuCommand(dynamic_cast<PopupMenu&>(*pMenu), *GetViewFrame(), nId ))
     716           0 :                                 pPopup->Execute(nId);
     717             :                         }
     718             :                         else
     719             :                         {
     720           0 :                             SfxViewFrame *pSfxViewFrame = GetViewFrame();
     721           0 :                             uno::Reference< frame::XFrame > xFrame;
     722           0 :                             if ( pSfxViewFrame )
     723           0 :                                 xFrame = pSfxViewFrame->GetFrame().GetFrameInterface();
     724           0 :                             com::sun::star::util::URL aURL;
     725           0 :                             uno::Reference< frame::XDispatchProvider > xDispatchProvider( xFrame, UNO_QUERY );
     726             : 
     727             :                             try
     728             :                             {
     729           0 :                                 uno::Reference< frame::XDispatch > xDispatch;
     730           0 :                                 uno::Reference< util::XURLTransformer > xURLTransformer = util::URLTransformer::create(comphelper::getProcessComponentContext());
     731             : 
     732           0 :                                 aURL.Complete = aCommand;
     733           0 :                                 xURLTransformer->parseStrict(aURL);
     734           0 :                                 uno::Sequence< beans::PropertyValue > aArgs;
     735           0 :                                 xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
     736             : 
     737           0 :                                 if (xDispatch.is())
     738             :                                 {
     739             :                                     // Execute dispatch asynchronously
     740           0 :                                     ExecuteInfo* pExecuteInfo   = new ExecuteInfo;
     741           0 :                                     pExecuteInfo->xDispatch     = xDispatch;
     742           0 :                                     pExecuteInfo->aTargetURL    = aURL;
     743           0 :                                     pExecuteInfo->aArgs         = aArgs;
     744           0 :                                     Application::PostUserEvent( STATIC_LINK(0, AsyncExecute , ExecuteHdl_Impl), pExecuteInfo );
     745           0 :                                 }
     746             :                             }
     747           0 :                             catch (const Exception&)
     748             :                             {
     749           0 :                             }
     750           0 :                         }
     751             :                     }
     752             :                     else
     753             :                     {
     754           0 :                         pPopup->Execute( aToFill.SVRect(), m_pEditWin );
     755             :                     }
     756           0 :                 }
     757             :             }
     758             : 
     759           0 :             m_pWrtShell->Pop( false );
     760           0 :             m_pWrtShell->LockView( bOldViewLock );
     761             :         }
     762             :     }
     763           0 :     return bRet;
     764             : }
     765             : 
     766             : /** Function: ExecSmartTagPopup
     767             : 
     768             :    This function shows the popup menu for smarttag
     769             :    actions.
     770             : */
     771           0 : bool SwView::ExecSmartTagPopup( const Point& rPt )
     772             : {
     773           0 :     bool bRet = false;
     774           0 :     const bool bOldViewLock = m_pWrtShell->IsViewLocked();
     775           0 :     m_pWrtShell->LockView( true );
     776           0 :     m_pWrtShell->Push();
     777             : 
     778             :     // get word that was clicked on
     779             :     // This data structure maps a smart tag type string to the property bag
     780           0 :     SwRect aToFill;
     781           0 :     Sequence< OUString > aSmartTagTypes;
     782           0 :     Sequence< Reference< container::XStringKeyMap > > aStringKeyMaps;
     783           0 :     Reference<text::XTextRange> xRange;
     784             : 
     785           0 :     m_pWrtShell->GetSmartTagTerm( rPt, aToFill, aSmartTagTypes, aStringKeyMaps, xRange);
     786           0 :     if ( xRange.is() && aSmartTagTypes.getLength() )
     787             :     {
     788           0 :         bRet = true;
     789           0 :         m_pWrtShell->SttSelect();
     790           0 :         SwSmartTagPopup aPopup( this, aSmartTagTypes, aStringKeyMaps, xRange );
     791           0 :         aPopup.Execute( aToFill.SVRect(), m_pEditWin );
     792             :     }
     793             : 
     794           0 :     m_pWrtShell->Pop( false );
     795           0 :     m_pWrtShell->LockView( bOldViewLock );
     796             : 
     797           0 :     return bRet;
     798             : }
     799             : 
     800           0 : class SwFieldDialog : public FloatingWindow
     801             : {
     802             : private:
     803             :     ListBox aListBox;
     804             :     IFieldmark *pFieldmark;
     805             : 
     806             :     DECL_LINK( MyListBoxHandler, ListBox * );
     807             : 
     808             : public:
     809             :     SwFieldDialog( SwEditWin* parent, IFieldmark *fieldBM );
     810             : };
     811             : 
     812           0 : SwFieldDialog::SwFieldDialog( SwEditWin* parent, IFieldmark *fieldBM ) :
     813             :     FloatingWindow( parent, WB_BORDER | WB_SYSTEMWINDOW ),
     814             :     aListBox(this),
     815           0 :     pFieldmark( fieldBM )
     816             : {
     817           0 :     if ( fieldBM != NULL )
     818             :     {
     819           0 :         const IFieldmark::parameter_map_t* const pParameters = fieldBM->GetParameters();
     820             : 
     821           0 :         OUString sListKey = OUString(  ODF_FORMDROPDOWN_LISTENTRY  );
     822           0 :         IFieldmark::parameter_map_t::const_iterator pListEntries = pParameters->find( sListKey );
     823           0 :         if(pListEntries != pParameters->end())
     824             :         {
     825           0 :             Sequence< OUString > vListEntries;
     826           0 :             pListEntries->second >>= vListEntries;
     827           0 :             for( OUString* pCurrent = vListEntries.getArray();
     828           0 :                 pCurrent != vListEntries.getArray() + vListEntries.getLength();
     829             :                 ++pCurrent)
     830             :             {
     831           0 :                 aListBox.InsertEntry(*pCurrent);
     832           0 :             }
     833             :         }
     834             : 
     835             :         // Select the current one
     836           0 :         OUString sResultKey = OUString( ODF_FORMDROPDOWN_RESULT  );
     837           0 :         IFieldmark::parameter_map_t::const_iterator pResult = pParameters->find( sResultKey );
     838           0 :         if ( pResult != pParameters->end() )
     839             :         {
     840           0 :             sal_Int32 nSelection = -1;
     841           0 :             pResult->second >>= nSelection;
     842           0 :             aListBox.SelectEntryPos( nSelection );
     843           0 :         }
     844             :     }
     845             : 
     846           0 :     Size lbSize(aListBox.GetOptimalSize());
     847           0 :     lbSize.Width()+=50;
     848           0 :     lbSize.Height()+=20;
     849           0 :     aListBox.SetSizePixel(lbSize);
     850           0 :     aListBox.SetSelectHdl( LINK( this, SwFieldDialog, MyListBoxHandler ) );
     851           0 :     aListBox.Show();
     852             : 
     853           0 :     SetSizePixel( lbSize );
     854           0 : }
     855             : 
     856           0 : IMPL_LINK( SwFieldDialog, MyListBoxHandler, ListBox *, pBox )
     857             : {
     858           0 :     short res = 0;
     859           0 :     if ( !pBox->IsTravelSelect() )
     860             :     {
     861           0 :         sal_Int32 selection = pBox->GetSelectEntryPos();
     862           0 :         if ( selection >= 0 )
     863             :         {
     864           0 :             OUString sKey = OUString(  ODF_FORMDROPDOWN_RESULT  );
     865           0 :             (*pFieldmark->GetParameters())[ sKey ] = makeAny(selection);
     866           0 :             pFieldmark->Invalidate();
     867           0 :             SwView& rView = ( ( SwEditWin* )GetParent() )->GetView();
     868           0 :             rView.GetDocShell()->SetModified( true );
     869             :         }
     870             : 
     871           0 :         EndPopupMode();
     872           0 :         res = 1;
     873             :     }
     874           0 :     return res;
     875             : }
     876             : 
     877           0 : IMPL_LINK_NOARG(SwView, FieldPopupModeEndHdl)
     878             : {
     879           0 :     if ( m_pFieldPopup )
     880             :     {
     881           0 :         delete m_pFieldPopup;
     882           0 :         m_pFieldPopup = NULL;
     883             :     }
     884           0 :     return 0;
     885             : }
     886             : 
     887           0 : void SwView::ExecFieldPopup( const Point& rPt, IFieldmark *fieldBM )
     888             : {
     889           0 :     const Point aPixPos = GetEditWin().LogicToPixel( rPt );
     890             : 
     891           0 :     m_pFieldPopup = new SwFieldDialog( m_pEditWin, fieldBM );
     892           0 :     m_pFieldPopup->SetPopupModeEndHdl( LINK( this, SwView, FieldPopupModeEndHdl ) );
     893             : 
     894           0 :     Rectangle aRect( m_pEditWin->OutputToScreenPixel( aPixPos ), Size( 0, 0 ) );
     895           0 :     m_pFieldPopup->StartPopupMode( aRect, FLOATWIN_POPUPMODE_DOWN|FLOATWIN_POPUPMODE_GRABFOCUS );
     896         270 : }
     897             : 
     898             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10