LCOV - code coverage report
Current view: top level - sw/source/uibase/uiview - viewling.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 18 415 4.3 %
Date: 2015-06-13 12:38:46 Functions: 4 28 14.3 %
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( DefaultFontType::CJK_TEXT,
     168           0 :                                                     nTargetLang, GetDefaultFontFlags::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().IsTextNode();
     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 :                                 SwTextNode *pTextNode = aPointNodeIndex.GetNode().GetTextNode();
     192             :                                 // check for unexpected error case
     193             :                                 OSL_ENSURE(pTextNode && pTextNode->GetText().getLength() >= nPointIndex,
     194             :                                     "text missing: corrupted node?" );
     195           0 :                                 if (!pTextNode || pTextNode->GetText().getLength() < nPointIndex)
     196           0 :                                     nPointIndex = 0;
     197             :                                 // restore cursor to its original position
     198           0 :                                 m_pWrtShell->GetCrsr()->GetPoint()->nContent.Assign( pTextNode, 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 (SwEditShell::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 = static_cast<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) & FrmTypeFlags::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           4 : void SwView::SpellStart( SvxSpellArea eWhich,
     268             :         bool bStartDone, bool bEndDone,
     269             :         SwConversionArgs *pConvArgs )
     270             : {
     271           4 :     Reference< XLinguProperties >  xProp = ::GetLinguPropertySet();
     272           4 :     bool bIsWrapReverse = !pConvArgs && xProp.is() && xProp->getIsWrapReverse();
     273             : 
     274           4 :     SwDocPositions eStart = DOCPOS_START;
     275           4 :     SwDocPositions eEnd   = DOCPOS_END;
     276           4 :     SwDocPositions eCurr  = DOCPOS_CURR;
     277           4 :     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           4 :             if( bIsWrapReverse )
     287             :             {
     288           0 :                 if( bStartDone )
     289           0 :                     eStart = DOCPOS_CURR;
     290           0 :                 eCurr = DOCPOS_END;
     291             :             }
     292           4 :             else if( bStartDone )
     293           4 :                 eCurr = DOCPOS_START;
     294           4 :             break;
     295             :         case SVX_SPELL_BODY_START:
     296           0 :             if( !bIsWrapReverse )
     297             :             {
     298           0 :                 if( bEndDone )
     299           0 :                     eEnd = 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 :                 eEnd  = DOCPOS_OTHEREND;
     310           0 :                 eCurr = DOCPOS_OTHEREND;
     311             :             }
     312             :             else
     313             :             {
     314           0 :                 eStart = DOCPOS_OTHERSTART;
     315           0 :                 eEnd  = DOCPOS_OTHEREND;
     316           0 :                 eCurr = DOCPOS_OTHERSTART;
     317             :             }
     318           0 :             break;
     319             :         default:
     320             :             OSL_ENSURE( false, "SpellStart with unknown Area" );
     321             :     }
     322           4 :     m_pWrtShell->SpellStart( eStart, eEnd, eCurr, pConvArgs );
     323           4 : }
     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           8 : void SwView::SpellEnd( SwConversionArgs *pConvArgs )
     388             : {
     389           8 :     m_pWrtShell->SpellEnd( pConvArgs );
     390           8 :     if( m_pWrtShell->IsExtMode() )
     391           0 :         m_pWrtShell->SetMark();
     392           8 : }
     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 (SwEditShell::HasHyphIter())
     421             :     {
     422             :         ScopedVclPtr<MessBox>::Create( nullptr, 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 = const_cast<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();
     453           0 :         bool bSelection = static_cast<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) & FrmTypeFlags::BODY) && !bSelection )
     459             :         // turned on no special area
     460             :         {
     461             :             // I want also in special areas hyphenation
     462           0 :             ScopedVclPtrInstance< 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()->IsMultiSelection();
     491           0 :     const bool bSelection = static_cast<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->GetSelText()) : 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 = const_cast<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 = static_cast<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( AsyncExecute, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
     610             : {
     611           0 :     SolarMutexReleaser aReleaser;
     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 :     delete pExecuteInfo;
     624           0 :     return 0;
     625             : }
     626             : //!! End of extra code for context menu modifying extensions
     627             : 
     628           0 : bool SwView::ExecSpellPopup(const Point& rPt)
     629             : {
     630           0 :     bool bRet = false;
     631           0 :     const SwViewOption* pVOpt = m_pWrtShell->GetViewOptions();
     632           0 :     if( pVOpt->IsOnlineSpell() &&
     633           0 :         !m_pWrtShell->IsSelection())
     634             :     {
     635           0 :         if (m_pWrtShell->GetSelectionType() & nsSelectionType::SEL_DRW_TXT)
     636           0 :             bRet = ExecDrwTextSpellPopup(rPt);
     637           0 :         else if (!m_pWrtShell->IsSelFrmMode())
     638             :         {
     639           0 :             const bool bOldViewLock = m_pWrtShell->IsViewLocked();
     640           0 :             m_pWrtShell->LockView( true );
     641           0 :             m_pWrtShell->Push();
     642           0 :             SwRect aToFill;
     643             : 
     644             :             // decide which variant of the context menu to use...
     645             :             // if neither spell checking nor grammar checking provides suggestions use the
     646             :             // default context menu.
     647           0 :             bool bUseGrammarContext = false;
     648           0 :             Reference< XSpellAlternatives >  xAlt( m_pWrtShell->GetCorrection(&rPt, aToFill) );
     649           0 :             ProofreadingResult aGrammarCheckRes;
     650           0 :             sal_Int32 nErrorInResult = -1;
     651           0 :             uno::Sequence< OUString > aSuggestions;
     652           0 :             bool bCorrectionRes = false;
     653           0 :             if (!xAlt.is() || xAlt->getAlternatives().getLength() == 0)
     654             :             {
     655           0 :                 sal_Int32 nErrorPosInText = -1;
     656           0 :                 bCorrectionRes = m_pWrtShell->GetGrammarCorrection( aGrammarCheckRes, nErrorPosInText, nErrorInResult, aSuggestions, &rPt, aToFill );
     657           0 :                 OUString aMessageText;
     658           0 :                 if (nErrorInResult >= 0)
     659           0 :                     aMessageText = aGrammarCheckRes.aErrors[ nErrorInResult ].aShortComment;
     660             :                 // we like to use the grammar checking context menu if we either get
     661             :                 // some suggestions or at least a comment about the error found...
     662           0 :                 bUseGrammarContext = bCorrectionRes &&
     663           0 :                         (aSuggestions.getLength() > 0 || !aMessageText.isEmpty());
     664             :             }
     665             : 
     666             :             // open respective context menu for spell check or grammar errors with correction suggestions...
     667           0 :             if ((!bUseGrammarContext && xAlt.is()) ||
     668           0 :                 (bUseGrammarContext && bCorrectionRes && aGrammarCheckRes.aErrors.getLength() > 0))
     669             :             {
     670             :                 // get paragraph text
     671           0 :                 OUString aParaText;
     672           0 :                 SwPosition aPoint( *m_pWrtShell->GetCrsr()->GetPoint() );
     673             :                 const SwTextNode *pNode = dynamic_cast< const SwTextNode * >(
     674           0 :                                             &aPoint.nNode.GetNode() );
     675           0 :                 if (pNode)
     676           0 :                     aParaText = pNode->GetText();    // this may include hidden text but that should be Ok
     677             :                 else
     678             :                 {
     679             :                     OSL_FAIL("text node expected but not found" );
     680             :                 }
     681             : 
     682           0 :                 bRet = true;
     683           0 :                 m_pWrtShell->SttSelect();
     684           0 :                 boost::scoped_ptr< SwSpellPopup > pPopup;
     685           0 :                 if (bUseGrammarContext)
     686             :                 {
     687           0 :                     sal_Int32 nPos = aPoint.nContent.GetIndex();
     688             :                     (void) nPos;
     689           0 :                     pPopup.reset(new SwSpellPopup( m_pWrtShell, aGrammarCheckRes, nErrorInResult, aSuggestions, aParaText ));
     690             :                 }
     691             :                 else
     692           0 :                     pPopup.reset(new SwSpellPopup( m_pWrtShell, xAlt, aParaText ));
     693           0 :                 ui::ContextMenuExecuteEvent aEvent;
     694           0 :                 const Point aPixPos = GetEditWin().LogicToPixel( rPt );
     695             : 
     696           0 :                 aEvent.SourceWindow = VCLUnoHelper::GetInterface( m_pEditWin );
     697           0 :                 aEvent.ExecutePosition.X = aPixPos.X();
     698           0 :                 aEvent.ExecutePosition.Y = aPixPos.Y();
     699           0 :                 Menu* pMenu = 0;
     700             : 
     701             :                 OUString sMenuName  = bUseGrammarContext ?
     702           0 :                     OUString("private:resource/GrammarContextMenu") : OUString("private:resource/SpellContextMenu");
     703           0 :                 if(TryContextMenuInterception( *pPopup, sMenuName, pMenu, aEvent ))
     704             :                 {
     705             : 
     706             :                     //! happy hacking for context menu modifying extensions of this
     707             :                     //! 'custom made' menu... *sigh* (code copied from sfx2 and framework)
     708           0 :                     if ( pMenu )
     709             :                     {
     710           0 :                         const sal_uInt16 nId = static_cast<PopupMenu*>(pMenu)->Execute(m_pEditWin, aPixPos);
     711           0 :                         OUString aCommand = static_cast<PopupMenu*>(pMenu)->GetItemCommand(nId);
     712           0 :                         if (aCommand.isEmpty() )
     713             :                         {
     714           0 :                             if(!ExecuteMenuCommand(dynamic_cast<PopupMenu&>(*pMenu), *GetViewFrame(), nId ))
     715           0 :                                 pPopup->Execute(nId);
     716             :                         }
     717             :                         else
     718             :                         {
     719           0 :                             SfxViewFrame *pSfxViewFrame = GetViewFrame();
     720           0 :                             uno::Reference< frame::XFrame > xFrame;
     721           0 :                             if ( pSfxViewFrame )
     722           0 :                                 xFrame = pSfxViewFrame->GetFrame().GetFrameInterface();
     723           0 :                             com::sun::star::util::URL aURL;
     724           0 :                             uno::Reference< frame::XDispatchProvider > xDispatchProvider( xFrame, UNO_QUERY );
     725             : 
     726             :                             try
     727             :                             {
     728           0 :                                 uno::Reference< frame::XDispatch > xDispatch;
     729           0 :                                 uno::Reference< util::XURLTransformer > xURLTransformer = util::URLTransformer::create(comphelper::getProcessComponentContext());
     730             : 
     731           0 :                                 aURL.Complete = aCommand;
     732           0 :                                 xURLTransformer->parseStrict(aURL);
     733           0 :                                 uno::Sequence< beans::PropertyValue > aArgs;
     734           0 :                                 xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
     735             : 
     736           0 :                                 if (xDispatch.is())
     737             :                                 {
     738             :                                     // Execute dispatch asynchronously
     739           0 :                                     ExecuteInfo* pExecuteInfo   = new ExecuteInfo;
     740           0 :                                     pExecuteInfo->xDispatch     = xDispatch;
     741           0 :                                     pExecuteInfo->aTargetURL    = aURL;
     742           0 :                                     pExecuteInfo->aArgs         = aArgs;
     743           0 :                                     Application::PostUserEvent( LINK(0, AsyncExecute , ExecuteHdl_Impl), pExecuteInfo );
     744           0 :                                 }
     745             :                             }
     746           0 :                             catch (const Exception&)
     747             :                             {
     748           0 :                             }
     749           0 :                         }
     750             :                     }
     751             :                     else
     752             :                     {
     753           0 :                         pPopup->Execute( aToFill.SVRect(), m_pEditWin );
     754             :                     }
     755           0 :                 }
     756             :             }
     757             : 
     758           0 :             m_pWrtShell->Pop( false );
     759           0 :             m_pWrtShell->LockView( bOldViewLock );
     760             :         }
     761             :     }
     762           0 :     return bRet;
     763             : }
     764             : 
     765             : /** Function: ExecSmartTagPopup
     766             : 
     767             :    This function shows the popup menu for smarttag
     768             :    actions.
     769             : */
     770           0 : bool SwView::ExecSmartTagPopup( const Point& rPt )
     771             : {
     772           0 :     bool bRet = false;
     773           0 :     const bool bOldViewLock = m_pWrtShell->IsViewLocked();
     774           0 :     m_pWrtShell->LockView( true );
     775           0 :     m_pWrtShell->Push();
     776             : 
     777             :     // get word that was clicked on
     778             :     // This data structure maps a smart tag type string to the property bag
     779           0 :     SwRect aToFill;
     780           0 :     Sequence< OUString > aSmartTagTypes;
     781           0 :     Sequence< Reference< container::XStringKeyMap > > aStringKeyMaps;
     782           0 :     Reference<text::XTextRange> xRange;
     783             : 
     784           0 :     m_pWrtShell->GetSmartTagTerm( rPt, aToFill, aSmartTagTypes, aStringKeyMaps, xRange);
     785           0 :     if ( xRange.is() && aSmartTagTypes.getLength() )
     786             :     {
     787           0 :         bRet = true;
     788           0 :         m_pWrtShell->SttSelect();
     789           0 :         SwSmartTagPopup aPopup( this, aSmartTagTypes, aStringKeyMaps, xRange );
     790           0 :         aPopup.Execute( aToFill.SVRect(), m_pEditWin );
     791             :     }
     792             : 
     793           0 :     m_pWrtShell->Pop( false );
     794           0 :     m_pWrtShell->LockView( bOldViewLock );
     795             : 
     796           0 :     return bRet;
     797             : }
     798             : 
     799             : class SwFieldDialog : public FloatingWindow
     800             : {
     801             : private:
     802             :     VclPtr<ListBox> aListBox;
     803             :     IFieldmark *pFieldmark;
     804             : 
     805             :     DECL_LINK( MyListBoxHandler, ListBox * );
     806             : 
     807             : public:
     808             :     SwFieldDialog( SwEditWin* parent, IFieldmark *fieldBM );
     809             :     virtual ~SwFieldDialog();
     810             :     virtual void dispose() SAL_OVERRIDE;
     811             : };
     812             : 
     813           0 : SwFieldDialog::SwFieldDialog( SwEditWin* parent, IFieldmark *fieldBM ) :
     814             :     FloatingWindow( parent, WB_BORDER | WB_SYSTEMWINDOW ),
     815             :     aListBox(VclPtr<ListBox>::Create(this)),
     816           0 :     pFieldmark( fieldBM )
     817             : {
     818           0 :     if ( fieldBM != NULL )
     819             :     {
     820           0 :         const IFieldmark::parameter_map_t* const pParameters = fieldBM->GetParameters();
     821             : 
     822           0 :         OUString sListKey = OUString(  ODF_FORMDROPDOWN_LISTENTRY  );
     823           0 :         IFieldmark::parameter_map_t::const_iterator pListEntries = pParameters->find( sListKey );
     824           0 :         if(pListEntries != pParameters->end())
     825             :         {
     826           0 :             Sequence< OUString > vListEntries;
     827           0 :             pListEntries->second >>= vListEntries;
     828           0 :             for( OUString* pCurrent = vListEntries.getArray();
     829           0 :                 pCurrent != vListEntries.getArray() + vListEntries.getLength();
     830             :                 ++pCurrent)
     831             :             {
     832           0 :                 aListBox->InsertEntry(*pCurrent);
     833           0 :             }
     834             :         }
     835             : 
     836             :         // Select the current one
     837           0 :         OUString sResultKey = OUString( ODF_FORMDROPDOWN_RESULT  );
     838           0 :         IFieldmark::parameter_map_t::const_iterator pResult = pParameters->find( sResultKey );
     839           0 :         if ( pResult != pParameters->end() )
     840             :         {
     841           0 :             sal_Int32 nSelection = -1;
     842           0 :             pResult->second >>= nSelection;
     843           0 :             aListBox->SelectEntryPos( nSelection );
     844           0 :         }
     845             :     }
     846             : 
     847           0 :     Size lbSize(aListBox->GetOptimalSize());
     848           0 :     lbSize.Width()+=50;
     849           0 :     lbSize.Height()+=20;
     850           0 :     aListBox->SetSizePixel(lbSize);
     851           0 :     aListBox->SetSelectHdl( LINK( this, SwFieldDialog, MyListBoxHandler ) );
     852           0 :     aListBox->Show();
     853             : 
     854           0 :     SetSizePixel( lbSize );
     855           0 : }
     856             : 
     857           0 : SwFieldDialog::~SwFieldDialog()
     858             : {
     859           0 :     disposeOnce();
     860           0 : }
     861             : 
     862           0 : void SwFieldDialog::dispose()
     863             : {
     864           0 :     aListBox.disposeAndClear();
     865           0 :     FloatingWindow::dispose();
     866           0 : }
     867             : 
     868           0 : IMPL_LINK( SwFieldDialog, MyListBoxHandler, ListBox *, pBox )
     869             : {
     870           0 :     short res = 0;
     871           0 :     if ( !pBox->IsTravelSelect() )
     872             :     {
     873           0 :         sal_Int32 selection = pBox->GetSelectEntryPos();
     874           0 :         if ( selection >= 0 )
     875             :         {
     876           0 :             OUString sKey = OUString(  ODF_FORMDROPDOWN_RESULT  );
     877           0 :             (*pFieldmark->GetParameters())[ sKey ] = makeAny(selection);
     878           0 :             pFieldmark->Invalidate();
     879           0 :             SwView& rView = static_cast<SwEditWin*>( GetParent() )->GetView();
     880           0 :             rView.GetDocShell()->SetModified( true );
     881             :         }
     882             : 
     883           0 :         EndPopupMode();
     884           0 :         res = 1;
     885             :     }
     886           0 :     return res;
     887             : }
     888             : 
     889           0 : IMPL_LINK_NOARG(SwView, FieldPopupModeEndHdl)
     890             : {
     891           0 :     m_pFieldPopup.disposeAndClear();
     892           0 :     return 0;
     893             : }
     894             : 
     895           0 : void SwView::ExecFieldPopup( const Point& rPt, IFieldmark *fieldBM )
     896             : {
     897           0 :     const Point aPixPos = GetEditWin().LogicToPixel( rPt );
     898             : 
     899           0 :     m_pFieldPopup = VclPtr<SwFieldDialog>::Create( m_pEditWin, fieldBM );
     900           0 :     m_pFieldPopup->SetPopupModeEndHdl( LINK( this, SwView, FieldPopupModeEndHdl ) );
     901             : 
     902           0 :     Rectangle aRect( m_pEditWin->OutputToScreenPixel( aPixPos ), Size( 0, 0 ) );
     903           0 :     m_pFieldPopup->StartPopupMode( aRect, FloatWinPopupFlags::Down|FloatWinPopupFlags::GrabFocus );
     904         177 : }
     905             : 
     906             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11