LCOV - code coverage report
Current view: top level - editeng/source/editeng - editview.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 130 701 18.5 %
Date: 2014-11-03 Functions: 38 92 41.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             : 
      21             : #include <sal/macros.h>
      22             : #include <vcl/wrkwin.hxx>
      23             : #include <vcl/dialog.hxx>
      24             : #include <vcl/msgbox.hxx>
      25             : #include <vcl/svapp.hxx>
      26             : 
      27             : #include <com/sun/star/i18n/WordType.hpp>
      28             : #include <com/sun/star/i18n/ScriptType.hpp>
      29             : #include <vcl/metric.hxx>
      30             : 
      31             : #include <i18nlangtag/languagetag.hxx>
      32             : #include <i18nlangtag/mslangid.hxx>
      33             : #include <svl/languageoptions.hxx>
      34             : #include <svtools/ctrltool.hxx>
      35             : #include <svtools/langtab.hxx>
      36             : #include <vcl/graphicfilter.hxx>
      37             : 
      38             : #include <svl/srchitem.hxx>
      39             : 
      40             : #include <impedit.hxx>
      41             : #include <editeng/editeng.hxx>
      42             : #include <editeng/editview.hxx>
      43             : #include <editeng/flditem.hxx>
      44             : #include <editeng/svxacorr.hxx>
      45             : #include <editeng/langitem.hxx>
      46             : #include <editeng/fhgtitem.hxx>
      47             : #include <editeng/eerdll.hxx>
      48             : #include <eerdll2.hxx>
      49             : #include <editeng.hrc>
      50             : #include <helpid.hrc>
      51             : #include <i18nlangtag/lang.h>
      52             : #include <vcl/menu.hxx>
      53             : #include <vcl/window.hxx>
      54             : #include <editeng/acorrcfg.hxx>
      55             : #include <editeng/unolingu.hxx>
      56             : #include <editeng/fontitem.hxx>
      57             : #include <unotools/lingucfg.hxx>
      58             : #include <osl/file.hxx>
      59             : 
      60             : #include <com/sun/star/frame/XStorable.hpp>
      61             : #include <com/sun/star/beans/PropertyValues.hpp>
      62             : #include <com/sun/star/lang/Locale.hpp>
      63             : #include <linguistic/lngprops.hxx>
      64             : #include <vcl/settings.hxx>
      65             : 
      66             : #include <com/sun/star/lang/XServiceInfo.hpp>
      67             : 
      68             : using namespace com::sun::star;
      69             : using namespace com::sun::star::uno;
      70             : using namespace com::sun::star::beans;
      71             : 
      72             : 
      73             : // static
      74           0 : LanguageType EditView::CheckLanguage(
      75             :         const OUString &rText,
      76             :         Reference< linguistic2::XSpellChecker1 > xSpell,
      77             :         Reference< linguistic2::XLanguageGuessing > xLangGuess,
      78             :         bool bIsParaText )
      79             : {
      80           0 :     LanguageType nLang = LANGUAGE_NONE;
      81           0 :     if (bIsParaText)    // check longer texts with language-guessing...
      82             :     {
      83           0 :         if (!xLangGuess.is())
      84           0 :             return nLang;
      85             : 
      86           0 :         LanguageTag aGuessTag( xLangGuess->guessPrimaryLanguage( rText, 0, rText.getLength()) );
      87             : 
      88             :         // If the result from language guessing does not provide a 'Country'
      89             :         // part, try to get it by looking up the locale setting of the office,
      90             :         // "Tools/Options - Language Settings - Languages: Locale setting", if
      91             :         // the language matches.
      92           0 :         if ( aGuessTag.getCountry().isEmpty() )
      93             :         {
      94           0 :             const LanguageTag& rAppLocaleTag = Application::GetSettings().GetLanguageTag();
      95           0 :             if (rAppLocaleTag.getLanguage() == aGuessTag.getLanguage())
      96           0 :                 nLang = rAppLocaleTag.getLanguageType();
      97             :         }
      98           0 :         if (nLang == LANGUAGE_NONE) // language not found by looking up the system language...
      99           0 :             nLang = aGuessTag.makeFallback().getLanguageType();     // best known locale match
     100           0 :         if (nLang == LANGUAGE_SYSTEM)
     101           0 :             nLang = Application::GetSettings().GetLanguageTag().getLanguageType();
     102           0 :         if (nLang == LANGUAGE_DONTKNOW)
     103           0 :             nLang = LANGUAGE_NONE;
     104             :     }
     105             :     else    // check single word
     106             :     {
     107           0 :             if (!xSpell.is())
     108           0 :             return nLang;
     109             : 
     110             : 
     111             :         // build list of languages to check
     112             : 
     113             :         LanguageType aLangList[4];
     114           0 :         const AllSettings& rSettings  = Application::GetSettings();
     115           0 :         SvtLinguOptions aLinguOpt;
     116           0 :         SvtLinguConfig().GetOptions( aLinguOpt );
     117             :         // The default document language from "Tools/Options - Language Settings - Languages: Western"
     118             :         aLangList[0] = MsLangId::resolveSystemLanguageByScriptType( aLinguOpt.nDefaultLanguage,
     119           0 :                 ::com::sun::star::i18n::ScriptType::LATIN);
     120             :         // The one from "Tools/Options - Language Settings - Languages: User interface"
     121           0 :         aLangList[1] = rSettings.GetUILanguageTag().getLanguageType();
     122             :         // The one from "Tools/Options - Language Settings - Languages: Locale setting"
     123           0 :         aLangList[2] = rSettings.GetLanguageTag().getLanguageType();
     124             :         // en-US
     125           0 :         aLangList[3] = LANGUAGE_ENGLISH_US;
     126             : #ifdef DEBUG
     127             :         lang::Locale a0( LanguageTag::convertToLocale( aLangList[0] ) );
     128             :         lang::Locale a1( LanguageTag::convertToLocale( aLangList[1] ) );
     129             :         lang::Locale a2( LanguageTag::convertToLocale( aLangList[2] ) );
     130             :         lang::Locale a3( LanguageTag::convertToLocale( aLangList[3] ) );
     131             : #endif
     132             : 
     133           0 :         sal_Int32 nCount = sizeof (aLangList) / sizeof (aLangList[0]);
     134           0 :         for (sal_Int32 i = 0;  i < nCount;  i++)
     135             :         {
     136           0 :             sal_Int16 nTmpLang = aLangList[i];
     137           0 :             if (nTmpLang != LANGUAGE_NONE  &&  nTmpLang != LANGUAGE_DONTKNOW)
     138             :             {
     139           0 :                 if (xSpell->hasLanguage( nTmpLang ) &&
     140           0 :                     xSpell->isValid( rText, nTmpLang, Sequence< PropertyValue >() ))
     141             :                 {
     142           0 :                     nLang = nTmpLang;
     143           0 :                     break;
     144             :                 }
     145             :             }
     146           0 :         }
     147             :     }
     148             : 
     149           0 :     return nLang;
     150             : }
     151             : 
     152             : // class EditView
     153             : 
     154         554 : EditView::EditView( EditEngine* pEng, vcl::Window* pWindow )
     155             : {
     156         554 :     pImpEditView = new ImpEditView( this, pEng, pWindow );
     157         554 : }
     158             : 
     159        1662 : EditView::~EditView()
     160             : {
     161         554 :     delete pImpEditView;
     162        1108 : }
     163             : 
     164         390 : ImpEditEngine* EditView::GetImpEditEngine() const
     165             : {
     166         390 :     return pImpEditView->pEditEngine->pImpEditEngine;
     167             : }
     168             : 
     169        1497 : EditEngine* EditView::GetEditEngine() const
     170             : {
     171        1497 :     return pImpEditView->pEditEngine;
     172             : }
     173             : 
     174         416 : void EditView::Invalidate()
     175             : {
     176         416 :     if ( !pImpEditView->DoInvalidateMore() )
     177         416 :         pImpEditView->GetWindow()->Invalidate( pImpEditView->aOutArea );
     178             :     else
     179             :     {
     180           0 :         Rectangle aRect( pImpEditView->aOutArea );
     181           0 :         long nMore = pImpEditView->GetWindow()->PixelToLogic( Size( pImpEditView->GetInvalidateMore(), 0 ) ).Width();
     182           0 :         aRect.Left() -= nMore;
     183           0 :         aRect.Right() += nMore;
     184           0 :         aRect.Top() -= nMore;
     185           0 :         aRect.Bottom() += nMore;
     186           0 :         pImpEditView->GetWindow()->Invalidate( aRect );
     187             :     }
     188         416 : }
     189             : 
     190         178 : void EditView::SetReadOnly( bool bReadOnly )
     191             : {
     192         178 :     pImpEditView->bReadOnly = bReadOnly;
     193         178 : }
     194             : 
     195          48 : bool EditView::IsReadOnly() const
     196             : {
     197          48 :     return pImpEditView->bReadOnly;
     198             : }
     199             : 
     200         328 : void EditView::SetSelection( const ESelection& rESel )
     201             : {
     202             :     // If someone has just left an empty attribute, and then the outliner
     203             :     // manipulates the selection:
     204         328 :     if ( !pImpEditView->GetEditSelection().HasRange() )
     205             :     {
     206         326 :         ContentNode* pNode = pImpEditView->GetEditSelection().Max().GetNode();
     207         326 :         pImpEditView->pEditEngine->CursorMoved( pNode );
     208             :     }
     209             :     EditSelection aNewSelection( pImpEditView->pEditEngine->pImpEditEngine->ConvertSelection(
     210         328 :                                             rESel.nStartPara, rESel.nStartPos, rESel.nEndPara, rESel.nEndPos ) );
     211             : 
     212             :     // If the selection is manipulated after a KeyInput:
     213         328 :     pImpEditView->pEditEngine->CheckIdleFormatter();
     214             : 
     215             :     // Selection may not start/end at an invisible paragraph:
     216         328 :     const ParaPortion* pPortion = pImpEditView->pEditEngine->FindParaPortion( aNewSelection.Min().GetNode() );
     217         328 :     if ( !pPortion->IsVisible() )
     218             :     {
     219           0 :         pPortion = pImpEditView->pEditEngine->GetPrevVisPortion( pPortion );
     220           0 :         ContentNode* pNode = pPortion ? pPortion->GetNode() : pImpEditView->pEditEngine->GetEditDoc().GetObject( 0 );
     221           0 :         aNewSelection.Min() = EditPaM( pNode, pNode->Len() );
     222             :     }
     223         328 :     pPortion = pImpEditView->pEditEngine->FindParaPortion( aNewSelection.Max().GetNode() );
     224         328 :     if ( !pPortion->IsVisible() )
     225             :     {
     226           0 :         pPortion = pImpEditView->pEditEngine->GetPrevVisPortion( pPortion );
     227           0 :         ContentNode* pNode = pPortion ? pPortion->GetNode() : pImpEditView->pEditEngine->GetEditDoc().GetObject( 0 );
     228           0 :         aNewSelection.Max() = EditPaM( pNode, pNode->Len() );
     229             :     }
     230             : 
     231         328 :     pImpEditView->DrawSelection();
     232         328 :     pImpEditView->SetEditSelection( aNewSelection );
     233         328 :     pImpEditView->DrawSelection();
     234         328 :     bool bGotoCursor = pImpEditView->DoAutoScroll();
     235         328 :     ShowCursor( bGotoCursor );
     236         328 : }
     237             : 
     238         572 : ESelection EditView::GetSelection() const
     239             : {
     240         572 :     ESelection aSelection;
     241             : 
     242         572 :     aSelection.nStartPara = pImpEditView->pEditEngine->GetEditDoc().GetPos( pImpEditView->GetEditSelection().Min().GetNode() );
     243         572 :     aSelection.nEndPara = pImpEditView->pEditEngine->GetEditDoc().GetPos( pImpEditView->GetEditSelection().Max().GetNode() );
     244             : 
     245         572 :     aSelection.nStartPos = pImpEditView->GetEditSelection().Min().GetIndex();
     246         572 :     aSelection.nEndPos = pImpEditView->GetEditSelection().Max().GetIndex();
     247             : 
     248         572 :     return aSelection;
     249             : }
     250             : 
     251         716 : bool EditView::HasSelection() const
     252             : {
     253         716 :     return pImpEditView->HasSelection();
     254             : }
     255             : 
     256           6 : void EditView::DeleteSelected()
     257             : {
     258           6 :     pImpEditView->DeleteSelected();
     259           6 : }
     260             : 
     261           0 : sal_uInt16 EditView::GetSelectedScriptType() const
     262             : {
     263           0 :     return pImpEditView->pEditEngine->GetScriptType( pImpEditView->GetEditSelection() );
     264             : }
     265             : 
     266         789 : void EditView::Paint( const Rectangle& rRect, OutputDevice* pTargetDevice )
     267             : {
     268         789 :     pImpEditView->pEditEngine->pImpEditEngine->Paint( pImpEditView, rRect, pTargetDevice );
     269         789 : }
     270             : 
     271           0 : void EditView::SetEditEngine( EditEngine* pEditEng )
     272             : {
     273           0 :     pImpEditView->pEditEngine = pEditEng;
     274           0 :     EditSelection aStartSel;
     275           0 :     aStartSel = pImpEditView->pEditEngine->GetEditDoc().GetStartPaM();
     276           0 :     pImpEditView->SetEditSelection( aStartSel );
     277           0 : }
     278             : 
     279         130 : void EditView::SetWindow( vcl::Window* pWin )
     280             : {
     281         130 :     pImpEditView->pOutWin = pWin;
     282         130 :     pImpEditView->pEditEngine->pImpEditEngine->GetSelEngine().Reset();
     283         130 : }
     284             : 
     285         504 : vcl::Window* EditView::GetWindow() const
     286             : {
     287         504 :     return pImpEditView->pOutWin;
     288             : }
     289             : 
     290         280 : void EditView::SetVisArea( const Rectangle& rRect )
     291             : {
     292         280 :     pImpEditView->SetVisDocStartPos( rRect.TopLeft() );
     293         280 : }
     294             : 
     295        3224 : const Rectangle& EditView::GetVisArea() const
     296             : {
     297             :     // Change return value to Rectangle in next incompatible build !!!
     298        3224 :     static Rectangle aRect;
     299        3224 :     aRect = pImpEditView->GetVisDocArea();
     300        3224 :     return aRect;
     301             : }
     302             : 
     303         816 : void EditView::SetOutputArea( const Rectangle& rRect )
     304             : {
     305         816 :     pImpEditView->SetOutputArea( rRect );
     306             : 
     307             :     // the rest here only if it is an API call:
     308         816 :     pImpEditView->CalcAnchorPoint();
     309         816 :     if ( pImpEditView->pEditEngine->pImpEditEngine->GetStatus().AutoPageSize() )
     310           0 :         pImpEditView->RecalcOutputArea();
     311         816 :     pImpEditView->ShowCursor( false, false );
     312         816 : }
     313             : 
     314         220 : const Rectangle& EditView::GetOutputArea() const
     315             : {
     316         220 :     return pImpEditView->GetOutputArea();
     317             : }
     318             : 
     319          90 : const Pointer& EditView::GetPointer() const
     320             : {
     321          90 :     return pImpEditView->GetPointer();
     322             : }
     323             : 
     324         130 : vcl::Cursor* EditView::GetCursor() const
     325             : {
     326         130 :     return pImpEditView->pCursor;
     327             : }
     328             : 
     329          28 : void EditView::InsertText( const OUString& rStr, bool bSelect )
     330             : {
     331             : 
     332          28 :     EditEngine* pEE = pImpEditView->pEditEngine;
     333          28 :     pImpEditView->DrawSelection();
     334             : 
     335          28 :     EditPaM aPaM1;
     336          28 :     if ( bSelect )
     337             :     {
     338           0 :         EditSelection aTmpSel( pImpEditView->GetEditSelection() );
     339           0 :         aTmpSel.Adjust( pEE->GetEditDoc() );
     340           0 :         aPaM1 = aTmpSel.Min();
     341             :     }
     342             : 
     343          28 :     pEE->UndoActionStart( EDITUNDO_INSERT );
     344          28 :     EditPaM aPaM2( pEE->InsertText( pImpEditView->GetEditSelection(), rStr ) );
     345          28 :     pEE->UndoActionEnd( EDITUNDO_INSERT );
     346             : 
     347          28 :     if ( bSelect )
     348             :     {
     349             :         DBG_ASSERT( !aPaM1.DbgIsBuggy( pEE->GetEditDoc() ), "Insert: PaM broken" );
     350           0 :         pImpEditView->SetEditSelection( EditSelection( aPaM1, aPaM2 ) );
     351             :     }
     352             :     else
     353          28 :         pImpEditView->SetEditSelection( EditSelection( aPaM2, aPaM2 ) );
     354             : 
     355          28 :     pEE->FormatAndUpdate( this );
     356          28 : }
     357             : 
     358           0 : bool EditView::PostKeyEvent( const KeyEvent& rKeyEvent, vcl::Window* pFrameWin )
     359             : {
     360           0 :     return pImpEditView->PostKeyEvent( rKeyEvent, pFrameWin );
     361             : }
     362             : 
     363           0 : bool EditView::MouseButtonUp( const MouseEvent& rMouseEvent )
     364             : {
     365           0 :     return pImpEditView->MouseButtonUp( rMouseEvent );
     366             : }
     367             : 
     368           0 : void EditView::ReleaseMouse()
     369             : {
     370           0 :     return pImpEditView->ReleaseMouse();
     371             : }
     372             : 
     373           0 : bool EditView::MouseButtonDown( const MouseEvent& rMouseEvent )
     374             : {
     375           0 :     return pImpEditView->MouseButtonDown( rMouseEvent );
     376             : }
     377             : 
     378           0 : bool EditView::MouseMove( const MouseEvent& rMouseEvent )
     379             : {
     380           0 :     return pImpEditView->MouseMove( rMouseEvent );
     381             : }
     382             : 
     383           0 : void EditView::Command( const CommandEvent& rCEvt )
     384             : {
     385           0 :     pImpEditView->Command( rCEvt );
     386           0 : }
     387             : 
     388        3276 : void EditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor )
     389             : {
     390             : 
     391        3276 :     if ( pImpEditView->pEditEngine->HasView( this ) )
     392             :     {
     393             :         // The control word is more important:
     394        3276 :         if ( !pImpEditView->DoAutoScroll() )
     395           0 :             bGotoCursor = false;
     396        3276 :         pImpEditView->ShowCursor( bGotoCursor, bForceVisCursor );
     397             :     }
     398        3276 : }
     399             : 
     400        1340 : void EditView::HideCursor()
     401             : {
     402        1340 :     pImpEditView->GetCursor()->Hide();
     403        1340 : }
     404             : 
     405         171 : Pair EditView::Scroll( long ndX, long ndY, sal_uInt8 nRangeCheck )
     406             : {
     407         171 :     return pImpEditView->Scroll( ndX, ndY, nRangeCheck );
     408             : }
     409             : 
     410           0 : const SfxItemSet& EditView::GetEmptyItemSet()
     411             : {
     412           0 :     return pImpEditView->pEditEngine->GetEmptyItemSet();
     413             : }
     414             : 
     415         282 : void EditView::SetAttribs( const SfxItemSet& rSet )
     416             : {
     417             :     DBG_ASSERT( !pImpEditView->aEditSelection.IsInvalid(), "Blind Selection in ...." );
     418             : 
     419         282 :     pImpEditView->DrawSelection();
     420         282 :     pImpEditView->pEditEngine->SetAttribs( pImpEditView->GetEditSelection(), rSet, ATTRSPECIAL_WHOLEWORD );
     421         282 :     pImpEditView->pEditEngine->FormatAndUpdate( this );
     422         282 : }
     423             : 
     424           0 : void EditView::RemoveAttribsKeepLanguages( bool bRemoveParaAttribs )
     425             : {
     426             : 
     427           0 :     pImpEditView->DrawSelection();
     428           0 :     pImpEditView->pEditEngine->UndoActionStart( EDITUNDO_RESETATTRIBS );
     429           0 :     EditSelection aSelection( pImpEditView->GetEditSelection() );
     430             : 
     431           0 :     for (sal_uInt16 nWID = EE_ITEMS_START; nWID <= EE_ITEMS_END; ++nWID)
     432             :     {
     433           0 :         bool bIsLang =  EE_CHAR_LANGUAGE     == nWID ||
     434           0 :                         EE_CHAR_LANGUAGE_CJK == nWID ||
     435           0 :                         EE_CHAR_LANGUAGE_CTL == nWID;
     436           0 :         if (!bIsLang)
     437           0 :             pImpEditView->pEditEngine->RemoveCharAttribs( aSelection, bRemoveParaAttribs, nWID );
     438             :     }
     439             : 
     440           0 :     pImpEditView->pEditEngine->UndoActionEnd( EDITUNDO_RESETATTRIBS );
     441           0 :     pImpEditView->pEditEngine->FormatAndUpdate( this );
     442           0 : }
     443             : 
     444           0 : void EditView::RemoveAttribs( bool bRemoveParaAttribs, sal_uInt16 nWhich )
     445             : {
     446             : 
     447           0 :     pImpEditView->DrawSelection();
     448           0 :     pImpEditView->pEditEngine->UndoActionStart( EDITUNDO_RESETATTRIBS );
     449           0 :     pImpEditView->pEditEngine->RemoveCharAttribs( pImpEditView->GetEditSelection(), bRemoveParaAttribs, nWhich  );
     450           0 :     pImpEditView->pEditEngine->UndoActionEnd( EDITUNDO_RESETATTRIBS );
     451           0 :     pImpEditView->pEditEngine->FormatAndUpdate( this );
     452           0 : }
     453             : 
     454           0 : void EditView::RemoveCharAttribs( sal_Int32 nPara, sal_uInt16 nWhich )
     455             : {
     456           0 :     pImpEditView->pEditEngine->UndoActionStart( EDITUNDO_RESETATTRIBS );
     457           0 :     pImpEditView->pEditEngine->RemoveCharAttribs( nPara, nWhich );
     458           0 :     pImpEditView->pEditEngine->UndoActionEnd( EDITUNDO_RESETATTRIBS );
     459           0 :     pImpEditView->pEditEngine->FormatAndUpdate( this );
     460           0 : }
     461             : 
     462         130 : SfxItemSet EditView::GetAttribs()
     463             : {
     464             :     DBG_ASSERT( !pImpEditView->aEditSelection.IsInvalid(), "Blind Selection in ...." );
     465         130 :     return pImpEditView->pEditEngine->pImpEditEngine->GetAttribs( pImpEditView->GetEditSelection() );
     466             : }
     467             : 
     468           0 : void EditView::Undo()
     469             : {
     470           0 :     pImpEditView->pEditEngine->Undo( this );
     471           0 : }
     472             : 
     473           0 : void EditView::Redo()
     474             : {
     475           0 :     pImpEditView->pEditEngine->Redo( this );
     476           0 : }
     477             : 
     478           0 : sal_uInt32 EditView::Read( SvStream& rInput, const OUString& rBaseURL, EETextFormat eFormat, bool bSelect, SvKeyValueIterator* pHTTPHeaderAttrs )
     479             : {
     480           0 :     EditSelection aOldSel( pImpEditView->GetEditSelection() );
     481           0 :     pImpEditView->DrawSelection();
     482           0 :     pImpEditView->pEditEngine->pImpEditEngine->UndoActionStart( EDITUNDO_READ );
     483           0 :     EditPaM aEndPaM = pImpEditView->pEditEngine->pImpEditEngine->Read( rInput, rBaseURL, eFormat, aOldSel, pHTTPHeaderAttrs );
     484           0 :     pImpEditView->pEditEngine->pImpEditEngine->UndoActionEnd( EDITUNDO_READ );
     485           0 :     EditSelection aNewSel( aEndPaM, aEndPaM );
     486           0 :     if ( bSelect )
     487             :     {
     488           0 :         aOldSel.Adjust( pImpEditView->pEditEngine->GetEditDoc() );
     489           0 :         aNewSel.Min() = aOldSel.Min();
     490             :     }
     491             : 
     492           0 :     pImpEditView->SetEditSelection( aNewSel );
     493           0 :     bool bGotoCursor = pImpEditView->DoAutoScroll();
     494           0 :     ShowCursor( bGotoCursor );
     495             : 
     496           0 :     return rInput.GetError();
     497             : }
     498             : 
     499           0 : void EditView::Cut()
     500             : {
     501           0 :     Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipBoard(GetWindow()->GetClipboard());
     502           0 :     pImpEditView->CutCopy( aClipBoard, true );
     503           0 : }
     504             : 
     505           0 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > EditView::GetTransferable()
     506             : {
     507             :     uno::Reference< datatransfer::XTransferable > xData =
     508           0 :         GetEditEngine()->CreateTransferable( pImpEditView->GetEditSelection() );
     509           0 :     return xData;
     510             : }
     511             : 
     512           0 : void EditView::Copy()
     513             : {
     514           0 :     Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipBoard(GetWindow()->GetClipboard());
     515           0 :     pImpEditView->CutCopy( aClipBoard, false );
     516           0 : }
     517             : 
     518           0 : void EditView::Paste()
     519             : {
     520           0 :     Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipBoard(GetWindow()->GetClipboard());
     521           0 :     pImpEditView->Paste( aClipBoard, false );
     522           0 : }
     523             : 
     524           0 : void EditView::PasteSpecial()
     525             : {
     526           0 :     Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipBoard(GetWindow()->GetClipboard());
     527           0 :     pImpEditView->Paste(aClipBoard, true );
     528           0 : }
     529             : 
     530           0 : Point EditView::GetWindowPosTopLeft( sal_Int32 nParagraph )
     531             : {
     532           0 :     Point aDocPos( pImpEditView->pEditEngine->GetDocPosTopLeft( nParagraph ) );
     533           0 :     return pImpEditView->GetWindowPos( aDocPos );
     534             : }
     535             : 
     536         156 : void EditView::SetSelectionMode( EESelectionMode eMode )
     537             : {
     538         156 :     pImpEditView->SetSelectionMode( eMode );
     539         156 : }
     540             : 
     541           0 : OUString EditView::GetSelected()
     542             : {
     543           0 :     return pImpEditView->pEditEngine->pImpEditEngine->GetSelected( pImpEditView->GetEditSelection() );
     544             : }
     545             : 
     546           0 : void EditView::MoveParagraphs( Range aParagraphs, sal_Int32 nNewPos )
     547             : {
     548           0 :     pImpEditView->pEditEngine->pImpEditEngine->UndoActionStart( EDITUNDO_MOVEPARAS );
     549           0 :     pImpEditView->pEditEngine->pImpEditEngine->MoveParagraphs( aParagraphs, nNewPos, this );
     550           0 :     pImpEditView->pEditEngine->pImpEditEngine->UndoActionEnd( EDITUNDO_MOVEPARAS );
     551           0 : }
     552             : 
     553           0 : void EditView::MoveParagraphs( long nDiff )
     554             : {
     555           0 :     ESelection aSel = GetSelection();
     556           0 :     Range aRange( aSel.nStartPara, aSel.nEndPara );
     557           0 :     aRange.Justify();
     558           0 :     long nDest = ( nDiff > 0  ? aRange.Max() : aRange.Min() ) + nDiff;
     559           0 :     if ( nDiff > 0 )
     560           0 :         nDest++;
     561             :     DBG_ASSERT( ( nDest >= 0 ) && ( nDest <= pImpEditView->pEditEngine->GetParagraphCount() ), "MoveParagraphs - wrong Parameters!" );
     562           0 :     MoveParagraphs( aRange, sal::static_int_cast< sal_Int32 >( nDest ) );
     563           0 : }
     564             : 
     565         130 : void EditView::SetBackgroundColor( const Color& rColor )
     566             : {
     567         130 :     pImpEditView->SetBackgroundColor( rColor );
     568         130 : }
     569             : 
     570           0 : Color EditView::GetBackgroundColor() const
     571             : {
     572           0 :     return pImpEditView->GetBackgroundColor();
     573             : }
     574             : 
     575         374 : void EditView::SetControlWord( sal_uInt32 nWord )
     576             : {
     577         374 :     pImpEditView->nControl = nWord;
     578         374 : }
     579             : 
     580         374 : sal_uInt32 EditView::GetControlWord() const
     581             : {
     582         374 :     return pImpEditView->nControl;
     583             : }
     584             : 
     585           0 : EditTextObject* EditView::CreateTextObject()
     586             : {
     587           0 :     return pImpEditView->pEditEngine->pImpEditEngine->CreateTextObject( pImpEditView->GetEditSelection() );
     588             : }
     589             : 
     590           0 : void EditView::InsertText( const EditTextObject& rTextObject )
     591             : {
     592           0 :     pImpEditView->DrawSelection();
     593             : 
     594           0 :     pImpEditView->pEditEngine->UndoActionStart( EDITUNDO_INSERT );
     595           0 :     EditSelection aTextSel( pImpEditView->pEditEngine->InsertText( rTextObject, pImpEditView->GetEditSelection() ) );
     596           0 :     pImpEditView->pEditEngine->UndoActionEnd( EDITUNDO_INSERT );
     597             : 
     598           0 :     aTextSel.Min() = aTextSel.Max();    // Selection not retained.
     599           0 :     pImpEditView->SetEditSelection( aTextSel );
     600           0 :     pImpEditView->pEditEngine->FormatAndUpdate( this );
     601           0 : }
     602             : 
     603           0 : void EditView::InsertText( ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xDataObj, const OUString& rBaseURL, bool bUseSpecial )
     604             : {
     605           0 :     pImpEditView->pEditEngine->UndoActionStart( EDITUNDO_INSERT );
     606           0 :     pImpEditView->DeleteSelected();
     607             :     EditSelection aTextSel =
     608           0 :         pImpEditView->pEditEngine->InsertText(xDataObj, rBaseURL, pImpEditView->GetEditSelection().Max(), bUseSpecial);
     609           0 :     pImpEditView->pEditEngine->UndoActionEnd( EDITUNDO_INSERT );
     610             : 
     611           0 :     aTextSel.Min() = aTextSel.Max();    // Selection not retained.
     612           0 :     pImpEditView->SetEditSelection( aTextSel );
     613           0 :     pImpEditView->pEditEngine->FormatAndUpdate( this );
     614           0 : }
     615             : 
     616         282 : void EditView::SetEditEngineUpdateMode( bool bUpdate )
     617             : {
     618         282 :     pImpEditView->pEditEngine->pImpEditEngine->SetUpdateMode( bUpdate, this );
     619         282 : }
     620             : 
     621         244 : void EditView::ForceUpdate()
     622             : {
     623         244 :     pImpEditView->pEditEngine->pImpEditEngine->SetUpdateMode( true, this, true );
     624         244 : }
     625             : 
     626           0 : SfxStyleSheet* EditView::GetStyleSheet()
     627             : {
     628           0 :     EditSelection aSel( pImpEditView->GetEditSelection() );
     629           0 :     aSel.Adjust( pImpEditView->pEditEngine->GetEditDoc() );
     630           0 :     sal_Int32 nStartPara = pImpEditView->pEditEngine->GetEditDoc().GetPos( aSel.Min().GetNode() );
     631           0 :     sal_Int32 nEndPara = pImpEditView->pEditEngine->GetEditDoc().GetPos( aSel.Max().GetNode() );
     632             : 
     633           0 :     SfxStyleSheet* pStyle = NULL;
     634           0 :     for ( sal_Int32 n = nStartPara; n <= nEndPara; n++ )
     635             :     {
     636           0 :         SfxStyleSheet* pTmpStyle = pImpEditView->pEditEngine->GetStyleSheet( n );
     637           0 :         if ( ( n != nStartPara ) && ( pStyle != pTmpStyle ) )
     638           0 :             return NULL;    // Not unique.
     639           0 :         pStyle = pTmpStyle;
     640             :     }
     641           0 :     return pStyle;
     642             : }
     643             : 
     644           0 : const SfxStyleSheet* EditView::GetStyleSheet() const
     645             : {
     646           0 :     return const_cast< EditView* >( this )->GetStyleSheet();
     647             : }
     648             : 
     649          70 : bool EditView::IsInsertMode() const
     650             : {
     651          70 :     return pImpEditView->IsInsertMode();
     652             : }
     653             : 
     654         334 : void EditView::SetInsertMode( bool bInsert )
     655             : {
     656         334 :     pImpEditView->SetInsertMode( bInsert );
     657         334 : }
     658             : 
     659           0 : void EditView::SetAnchorMode( EVAnchorMode eMode )
     660             : {
     661           0 :     pImpEditView->SetAnchorMode( eMode );
     662           0 : }
     663             : 
     664           0 : EVAnchorMode EditView::GetAnchorMode() const
     665             : {
     666           0 :     return pImpEditView->GetAnchorMode();
     667             : }
     668             : 
     669           0 : void EditView::TransliterateText( sal_Int32 nTransliterationMode )
     670             : {
     671           0 :     EditSelection aOldSel( pImpEditView->GetEditSelection() );
     672           0 :     EditSelection aNewSel = pImpEditView->pEditEngine->TransliterateText( pImpEditView->GetEditSelection(), nTransliterationMode );
     673           0 :     if ( aNewSel != aOldSel )
     674             :     {
     675           0 :         pImpEditView->DrawSelection();
     676           0 :         pImpEditView->SetEditSelection( aNewSel );
     677           0 :         pImpEditView->DrawSelection();
     678             :     }
     679           0 : }
     680             : 
     681           0 : void EditView::CompleteAutoCorrect( vcl::Window* pFrameWin )
     682             : {
     683           0 :     if ( !pImpEditView->HasSelection() && pImpEditView->pEditEngine->pImpEditEngine->GetStatus().DoAutoCorrect() )
     684             :     {
     685           0 :         pImpEditView->DrawSelection();
     686           0 :         EditSelection aSel = pImpEditView->GetEditSelection();
     687           0 :         aSel = pImpEditView->pEditEngine->EndOfWord( aSel.Max() );
     688           0 :         aSel = pImpEditView->pEditEngine->pImpEditEngine->AutoCorrect( aSel, 0, !IsInsertMode(), pFrameWin );
     689           0 :         pImpEditView->SetEditSelection( aSel );
     690           0 :         if ( pImpEditView->pEditEngine->IsModified() )
     691           0 :             pImpEditView->pEditEngine->FormatAndUpdate( this );
     692             :     }
     693           0 : }
     694             : 
     695         130 : EESpellState EditView::StartSpeller( bool bMultipleDoc )
     696             : {
     697         130 :     if ( !pImpEditView->pEditEngine->pImpEditEngine->GetSpeller().is() )
     698           0 :         return EE_SPELL_NOSPELLER;
     699             : 
     700         130 :     return pImpEditView->pEditEngine->pImpEditEngine->Spell( this, bMultipleDoc );
     701             : }
     702             : 
     703           0 : EESpellState EditView::StartThesaurus()
     704             : {
     705           0 :     if ( !pImpEditView->pEditEngine->pImpEditEngine->GetSpeller().is() )
     706           0 :         return EE_SPELL_NOSPELLER;
     707             : 
     708           0 :     return pImpEditView->pEditEngine->pImpEditEngine->StartThesaurus( this );
     709             : }
     710             : 
     711           0 : void EditView::StartTextConversion(
     712             :         LanguageType nSrcLang, LanguageType nDestLang, const vcl::Font *pDestFont,
     713             :         sal_Int32 nOptions, bool bIsInteractive, bool bMultipleDoc )
     714             : {
     715           0 :     pImpEditView->pEditEngine->pImpEditEngine->Convert( this, nSrcLang, nDestLang, pDestFont, nOptions, bIsInteractive, bMultipleDoc );
     716           0 : }
     717             : 
     718             : 
     719           0 : sal_Int32 EditView::StartSearchAndReplace( const SvxSearchItem& rSearchItem )
     720             : {
     721           0 :     return pImpEditView->pEditEngine->pImpEditEngine->StartSearchAndReplace( this, rSearchItem );
     722             : }
     723             : 
     724           0 : bool EditView::IsCursorAtWrongSpelledWord( bool bMarkIfWrong )
     725             : {
     726           0 :     bool bIsWrong = false;
     727           0 :     if ( !HasSelection() )
     728             :     {
     729           0 :         EditPaM aPaM = pImpEditView->GetEditSelection().Max();
     730           0 :         bIsWrong = pImpEditView->IsWrongSpelledWord( aPaM, bMarkIfWrong );
     731             :     }
     732           0 :     return bIsWrong;
     733             : }
     734             : 
     735           0 : bool EditView::IsWrongSpelledWordAtPos( const Point& rPosPixel, bool bMarkIfWrong )
     736             : {
     737           0 :     Point aPos ( pImpEditView->GetWindow()->PixelToLogic( rPosPixel ) );
     738           0 :     aPos = pImpEditView->GetDocPos( aPos );
     739           0 :     EditPaM aPaM = pImpEditView->pEditEngine->GetPaM(aPos, false);
     740           0 :     return pImpEditView->IsWrongSpelledWord( aPaM , bMarkIfWrong );
     741             : }
     742             : 
     743           0 : void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link* pCallBack )
     744             : {
     745             : 
     746           0 :     Point aPos ( pImpEditView->GetWindow()->PixelToLogic( rPosPixel ) );
     747           0 :     aPos = pImpEditView->GetDocPos( aPos );
     748           0 :     EditPaM aPaM = pImpEditView->pEditEngine->GetPaM(aPos, false);
     749           0 :     Reference< linguistic2::XSpellChecker1 >  xSpeller( pImpEditView->pEditEngine->pImpEditEngine->GetSpeller() );
     750           0 :     ESelection aOldSel = GetSelection();
     751           0 :     if ( xSpeller.is() && pImpEditView->IsWrongSpelledWord( aPaM, true ) )
     752             :     {
     753           0 :         PopupMenu aPopupMenu( EditResId( RID_MENU_SPELL ) );
     754           0 :         PopupMenu *pAutoMenu = aPopupMenu.GetPopupMenu( MN_AUTOCORR );
     755           0 :         PopupMenu *pInsertMenu = aPopupMenu.GetPopupMenu( MN_INSERT );  // add word to user-dictionaries
     756           0 :         pInsertMenu->SetMenuFlags( MENU_FLAG_NOAUTOMNEMONICS );         //! necessary to retrieve the correct dictionary names later
     757             : 
     758           0 :         EditPaM aPaM2( aPaM );
     759           0 :         aPaM2.SetIndex( aPaM2.GetIndex()+1 );
     760             : 
     761             :         // Are there any replace suggestions?
     762           0 :         OUString aSelected( GetSelected() );
     763             : 
     764             :         // restrict the maximal number of suggestions displayed
     765             :         // in the context menu.
     766             :         // Note: That could of course be done by clipping the
     767             :         // resulting sequence but the current third party
     768             :         // implementations result differs greatly if the number of
     769             :         // suggestions to be retuned gets changed. Statistically
     770             :         // it gets much better if told to return e.g. only 7 strings
     771             :         // than returning e.g. 16 suggestions and using only the
     772             :         // first 7. Thus we hand down the value to use to that
     773             :         // implementation here by providing an additional parameter.
     774           0 :         Sequence< PropertyValue > aPropVals(1);
     775           0 :         PropertyValue &rVal = aPropVals.getArray()[0];
     776           0 :         rVal.Name = OUString( UPN_MAX_NUMBER_OF_SUGGESTIONS );
     777           0 :         rVal.Value <<= (sal_Int16) 7;
     778             : 
     779             :         // Are there any replace suggestions?
     780             :         Reference< linguistic2::XSpellAlternatives >  xSpellAlt =
     781           0 :                 xSpeller->spell( aSelected, pImpEditView->pEditEngine->pImpEditEngine->GetLanguage( aPaM2 ), aPropVals );
     782             : 
     783           0 :         Reference< linguistic2::XLanguageGuessing >  xLangGuesser( EE_DLL().GetGlobalData()->GetLanguageGuesser() );
     784             : 
     785             :         // check if text might belong to a different language...
     786           0 :         LanguageType nGuessLangWord = LANGUAGE_NONE;
     787           0 :         LanguageType nGuessLangPara = LANGUAGE_NONE;
     788           0 :         if (xSpellAlt.is() && xLangGuesser.is())
     789             :         {
     790           0 :             OUString aParaText;
     791           0 :             ContentNode *pNode = aPaM.GetNode();
     792           0 :             if (pNode)
     793             :             {
     794           0 :                 aParaText = pNode->GetString();
     795             :             }
     796             :             else
     797             :             {
     798             :                 OSL_FAIL( "content node is NULL" );
     799             :             }
     800             : 
     801           0 :             nGuessLangWord = CheckLanguage( xSpellAlt->getWord(), xSpeller, xLangGuesser, false );
     802           0 :             nGuessLangPara = CheckLanguage( aParaText, xSpeller, xLangGuesser, true );
     803             :         }
     804           0 :         if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE)
     805             :         {
     806             :             // make sure LANGUAGE_NONE gets not used as menu entry
     807           0 :             if (nGuessLangWord == LANGUAGE_NONE)
     808           0 :                 nGuessLangWord = nGuessLangPara;
     809           0 :             if (nGuessLangPara == LANGUAGE_NONE)
     810           0 :                 nGuessLangPara = nGuessLangWord;
     811             : 
     812           0 :             aPopupMenu.InsertSeparator();
     813           0 :             OUString aTmpWord( SvtLanguageTable::GetLanguageString( nGuessLangWord ) );
     814           0 :             OUString aTmpPara( SvtLanguageTable::GetLanguageString( nGuessLangPara ) );
     815           0 :             OUString aWordStr( EE_RESSTR( RID_STR_WORD ) );
     816           0 :             aWordStr = aWordStr.replaceFirst( "%x", aTmpWord );
     817           0 :             OUString aParaStr( EE_RESSTR( RID_STR_PARAGRAPH ) );
     818           0 :             aParaStr = aParaStr.replaceFirst( "%x", aTmpPara );
     819           0 :             aPopupMenu.InsertItem( MN_WORDLANGUAGE, aWordStr );
     820           0 :             aPopupMenu.SetHelpId( MN_WORDLANGUAGE, HID_EDITENG_SPELLER_WORDLANGUAGE );
     821           0 :             aPopupMenu.InsertItem( MN_PARALANGUAGE, aParaStr );
     822           0 :             aPopupMenu.SetHelpId( MN_PARALANGUAGE, HID_EDITENG_SPELLER_PARALANGUAGE );
     823             :         }
     824             : 
     825             :         // ## Create mnemonics here
     826           0 :         if ( Application::IsAutoMnemonicEnabled() )
     827             :         {
     828           0 :             aPopupMenu.CreateAutoMnemonics();
     829           0 :             aPopupMenu.SetMenuFlags( aPopupMenu.GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS );
     830             :         }
     831             : 
     832             :         // Replace suggestions...
     833           0 :         Sequence< OUString > aAlt;
     834           0 :         if (xSpellAlt.is())
     835           0 :             aAlt = xSpellAlt->getAlternatives();
     836           0 :         const OUString *pAlt = aAlt.getConstArray();
     837           0 :         sal_uInt16 nWords = (sal_uInt16) aAlt.getLength();
     838           0 :         if ( nWords )
     839             :         {
     840           0 :             for ( sal_uInt16 nW = 0; nW < nWords; nW++ )
     841             :             {
     842           0 :                 OUString aAlternate( pAlt[nW] );
     843           0 :                 aPopupMenu.InsertItem( MN_ALTSTART+nW, aAlternate, MenuItemBits::NONE, OString(), nW );
     844           0 :                 pAutoMenu->InsertItem( MN_AUTOSTART+nW, aAlternate, MenuItemBits::NONE, OString(), nW );
     845           0 :             }
     846           0 :             aPopupMenu.InsertSeparator(OString(), nWords);
     847             :         }
     848             :         else
     849           0 :             aPopupMenu.RemoveItem( MN_AUTOCORR );   // delete?
     850             : 
     851           0 :         SvtLinguConfig aCfg;
     852             : 
     853           0 :         Reference< linguistic2::XSearchableDictionaryList >  xDicList( SvxGetDictionaryList() );
     854           0 :         Sequence< Reference< linguistic2::XDictionary >  > aDics;
     855           0 :         if (xDicList.is())
     856             :         {
     857           0 :             const Reference< linguistic2::XDictionary >  *pDic = NULL;
     858             :             // add the default positive dictionary to dic-list (if not already done).
     859             :             // This is to ensure that there is at least one dictionary to which
     860             :             // words could be added.
     861           0 :             uno::Reference< linguistic2::XDictionary >  xDic( SvxGetOrCreatePosDic( xDicList ) );
     862           0 :             if (xDic.is())
     863           0 :                 xDic->setActive( sal_True );
     864             : 
     865           0 :             aDics = xDicList->getDictionaries();
     866           0 :             pDic  = aDics.getConstArray();
     867           0 :             sal_uInt16 nCheckedLanguage = pImpEditView->pEditEngine->pImpEditEngine->GetLanguage( aPaM2 );
     868           0 :             sal_uInt16 nDicCount = (sal_uInt16)aDics.getLength();
     869           0 :             for (sal_uInt16 i = 0; i < nDicCount; i++)
     870             :             {
     871           0 :                 uno::Reference< linguistic2::XDictionary >  xDicTmp( pDic[i], uno::UNO_QUERY );
     872           0 :                 if (!xDicTmp.is() || SvxGetIgnoreAllList() == xDicTmp)
     873           0 :                     continue;
     874             : 
     875           0 :                 uno::Reference< frame::XStorable > xStor( xDicTmp, uno::UNO_QUERY );
     876           0 :                 LanguageType nActLanguage = LanguageTag( xDicTmp->getLocale() ).getLanguageType();
     877           0 :                 if( xDicTmp->isActive()
     878           0 :                     &&  xDicTmp->getDictionaryType() != linguistic2::DictionaryType_NEGATIVE
     879           0 :                     && (nCheckedLanguage == nActLanguage || LANGUAGE_NONE == nActLanguage )
     880           0 :                     && (!xStor.is() || !xStor->isReadonly()) )
     881             :                 {
     882             :                     // the extra 1 is because of the (possible) external
     883             :                     // linguistic entry above
     884           0 :                     sal_uInt16 nPos = MN_DICTSTART + i;
     885           0 :                     pInsertMenu->InsertItem( nPos, xDicTmp->getName() );
     886           0 :                     aDicNameSingle = xDicTmp->getName();
     887             : 
     888           0 :                     uno::Reference< lang::XServiceInfo > xSvcInfo( xDicTmp, uno::UNO_QUERY );
     889           0 :                     if (xSvcInfo.is())
     890             :                     {
     891             :                         OUString aDictionaryImageUrl( aCfg.GetSpellAndGrammarContextDictionaryImage(
     892           0 :                                 xSvcInfo->getImplementationName()) );
     893           0 :                         if (!aDictionaryImageUrl.isEmpty() )
     894             :                         {
     895           0 :                             Image aImage( aDictionaryImageUrl );
     896           0 :                             pInsertMenu->SetItemImage( nPos, aImage );
     897           0 :                         }
     898           0 :                     }
     899             :                 }
     900           0 :             }
     901             :         }
     902           0 :         if ( pInsertMenu->GetItemCount() != 1)
     903           0 :             aPopupMenu.EnableItem( MN_INSERT_SINGLE, false );
     904           0 :         if ( pInsertMenu->GetItemCount() < 2 )
     905           0 :             aPopupMenu.EnableItem( MN_INSERT, false );
     906             : 
     907           0 :         aPopupMenu.RemoveDisabledEntries( true, true );
     908             : 
     909           0 :         Rectangle aTempRect = pImpEditView->pEditEngine->pImpEditEngine->PaMtoEditCursor( aPaM, GETCRSR_TXTONLY );
     910           0 :         Point aScreenPos = pImpEditView->GetWindowPos( aTempRect.TopLeft() );
     911           0 :         aScreenPos = pImpEditView->GetWindow()->OutputToScreenPixel( aScreenPos );
     912           0 :         aTempRect = pImpEditView->GetWindow()->LogicToPixel( Rectangle(aScreenPos, aTempRect.GetSize() ));
     913             : 
     914           0 :         sal_uInt16 nId = aPopupMenu.Execute( pImpEditView->GetWindow(), aTempRect, POPUPMENU_NOMOUSEUPCLOSE );
     915           0 :         if ( nId == MN_IGNORE )
     916             :         {
     917           0 :             OUString aWord = pImpEditView->SpellIgnoreOrAddWord( false );
     918           0 :             if ( pCallBack )
     919             :             {
     920           0 :                 SpellCallbackInfo aInf( SPELLCMD_IGNOREWORD, aWord );
     921           0 :                 pCallBack->Call( &aInf );
     922             :             }
     923           0 :             SetSelection( aOldSel );
     924             :         }
     925           0 :         else if ( ( nId == MN_WORDLANGUAGE ) || ( nId == MN_PARALANGUAGE ) )
     926             :         {
     927           0 :             LanguageType nLangToUse = (nId == MN_WORDLANGUAGE) ? nGuessLangWord : nGuessLangPara;
     928           0 :             sal_uInt16 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nLangToUse );
     929             : 
     930           0 :             SfxItemSet aAttrs = GetEditEngine()->GetEmptyItemSet();
     931           0 :             if (nScriptType == SCRIPTTYPE_LATIN)
     932           0 :                 aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE ) );
     933           0 :             if (nScriptType == SCRIPTTYPE_COMPLEX)
     934           0 :                 aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE_CTL ) );
     935           0 :             if (nScriptType == SCRIPTTYPE_ASIAN)
     936           0 :                 aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE_CJK ) );
     937           0 :             if ( nId == MN_PARALANGUAGE )
     938             :             {
     939           0 :                 ESelection aSel = GetSelection();
     940           0 :                 aSel.nStartPos = 0;
     941           0 :                 aSel.nEndPos = EE_TEXTPOS_ALL;
     942           0 :                 SetSelection( aSel );
     943             :             }
     944           0 :             SetAttribs( aAttrs );
     945           0 :             pImpEditView->pEditEngine->pImpEditEngine->StartOnlineSpellTimer();
     946             : 
     947           0 :             if ( pCallBack )
     948             :             {
     949           0 :                 SpellCallbackInfo aInf( ( nId == MN_WORDLANGUAGE ) ? SPELLCMD_WORDLANGUAGE : SPELLCMD_PARALANGUAGE, nLangToUse );
     950           0 :                 pCallBack->Call( &aInf );
     951             :             }
     952           0 :             SetSelection( aOldSel );
     953             :         }
     954           0 :         else if ( nId == MN_SPELLING )
     955             :         {
     956           0 :             if ( !pCallBack )
     957             :             {
     958             :                 // Set Cursor before word...
     959           0 :                 EditPaM aCursor = pImpEditView->GetEditSelection().Min();
     960           0 :                 pImpEditView->DrawSelection();
     961           0 :                 pImpEditView->SetEditSelection( EditSelection( aCursor, aCursor ) );
     962           0 :                 pImpEditView->DrawSelection();
     963             :                 // Crashes when no SfxApp
     964           0 :                 pImpEditView->pEditEngine->pImpEditEngine->Spell( this, false );
     965             :             }
     966             :             else
     967             :             {
     968           0 :                 SpellCallbackInfo aInf( SPELLCMD_STARTSPELLDLG, OUString() );
     969           0 :                 pCallBack->Call( &aInf );
     970             :             }
     971             :         }
     972           0 :         else if ( nId >= MN_DICTSTART || nId == MN_INSERT_SINGLE )
     973             :         {
     974           0 :             OUString aDicName;
     975           0 :             if (nId >= MN_DICTSTART)
     976           0 :                 aDicName = pInsertMenu->GetItemText(nId);
     977             :             else
     978           0 :                 aDicName = aDicNameSingle;
     979             : 
     980           0 :             uno::Reference< linguistic2::XDictionary >      xDic;
     981           0 :             if (xDicList.is())
     982           0 :                 xDic = xDicList->getDictionaryByName( aDicName );
     983             : 
     984           0 :             if (xDic.is())
     985           0 :                 xDic->add( aSelected, sal_False, OUString() );
     986             :             // save modified user-dictionary if it is persistent
     987           0 :             Reference< frame::XStorable >  xSavDic( xDic, UNO_QUERY );
     988           0 :             if (xSavDic.is())
     989           0 :                 xSavDic->store();
     990             : 
     991           0 :             aPaM.GetNode()->GetWrongList()->ResetInvalidRange(0, aPaM.GetNode()->Len());
     992           0 :             pImpEditView->pEditEngine->pImpEditEngine->StartOnlineSpellTimer();
     993             : 
     994           0 :             if ( pCallBack )
     995             :             {
     996           0 :                 SpellCallbackInfo aInf( SPELLCMD_ADDTODICTIONARY, aSelected );
     997           0 :                 pCallBack->Call( &aInf );
     998             :             }
     999           0 :             SetSelection( aOldSel );
    1000             :         }
    1001           0 :         else if ( nId >= MN_AUTOSTART )
    1002             :         {
    1003             :             DBG_ASSERT(nId - MN_AUTOSTART < aAlt.getLength(), "index out of range");
    1004           0 :             OUString aWord = pAlt[nId - MN_AUTOSTART];
    1005           0 :             SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
    1006           0 :             if ( pAutoCorrect )
    1007           0 :                 pAutoCorrect->PutText( aSelected, aWord, pImpEditView->pEditEngine->pImpEditEngine->GetLanguage( aPaM2 ) );
    1008           0 :             InsertText( aWord );
    1009             :         }
    1010           0 :         else if ( nId >= MN_ALTSTART )  // Replace
    1011             :         {
    1012             :             DBG_ASSERT(nId - MN_ALTSTART < aAlt.getLength(), "index out of range");
    1013           0 :             OUString aWord = pAlt[nId - MN_ALTSTART];
    1014           0 :             InsertText( aWord );
    1015             :         }
    1016             :         else
    1017             :         {
    1018           0 :             SetSelection( aOldSel );
    1019           0 :         }
    1020           0 :     }
    1021           0 : }
    1022             : 
    1023           0 : bool EditView::SelectCurrentWord( sal_Int16 nWordType )
    1024             : {
    1025           0 :     EditSelection aCurSel( pImpEditView->GetEditSelection() );
    1026           0 :     pImpEditView->DrawSelection();
    1027           0 :     aCurSel = pImpEditView->pEditEngine->SelectWord(aCurSel.Max(), nWordType);
    1028           0 :     pImpEditView->SetEditSelection( aCurSel );
    1029           0 :     pImpEditView->DrawSelection();
    1030           0 :     ShowCursor( true, false );
    1031           0 :     return aCurSel.HasRange();
    1032             : }
    1033             : 
    1034           0 : void EditView::InsertField( const SvxFieldItem& rFld )
    1035             : {
    1036           0 :     EditEngine* pEE = pImpEditView->pEditEngine;
    1037           0 :     pImpEditView->DrawSelection();
    1038           0 :     pEE->UndoActionStart( EDITUNDO_INSERT );
    1039           0 :     EditPaM aPaM( pEE->InsertField( pImpEditView->GetEditSelection(), rFld ) );
    1040           0 :     pEE->UndoActionEnd( EDITUNDO_INSERT );
    1041           0 :     pImpEditView->SetEditSelection( EditSelection( aPaM, aPaM ) );
    1042           0 :     pEE->UpdateFields();
    1043           0 :     pEE->FormatAndUpdate( this );
    1044           0 : }
    1045             : 
    1046           0 : const SvxFieldItem* EditView::GetFieldUnderMousePointer() const
    1047             : {
    1048             :     sal_Int32 nPara;
    1049             :     sal_Int32 nPos;
    1050           0 :     return GetFieldUnderMousePointer( nPara, nPos );
    1051             : }
    1052             : 
    1053           0 : const SvxFieldItem* EditView::GetField( const Point& rPos, sal_Int32* pPara, sal_Int32* pPos ) const
    1054             : {
    1055           0 :     return pImpEditView->GetField( rPos, pPara, pPos );
    1056             : }
    1057             : 
    1058           0 : const SvxFieldItem* EditView::GetFieldUnderMousePointer( sal_Int32& nPara, sal_Int32& nPos ) const
    1059             : {
    1060           0 :     Point aPos = pImpEditView->GetWindow()->GetPointerPosPixel();
    1061           0 :     aPos = pImpEditView->GetWindow()->PixelToLogic( aPos );
    1062           0 :     return GetField( aPos, &nPara, &nPos );
    1063             : }
    1064             : 
    1065           0 : const SvxFieldItem* EditView::GetFieldAtSelection() const
    1066             : {
    1067           0 :     EditSelection aSel( pImpEditView->GetEditSelection() );
    1068           0 :     aSel.Adjust( pImpEditView->pEditEngine->GetEditDoc() );
    1069             :     // Only when cursor is in font of field, no selection,
    1070             :     // or only selecting field
    1071           0 :     if ( ( aSel.Min().GetNode() == aSel.Max().GetNode() ) &&
    1072           0 :          ( ( aSel.Max().GetIndex() == aSel.Min().GetIndex() ) ||
    1073           0 :            ( aSel.Max().GetIndex() == aSel.Min().GetIndex()+1 ) ) )
    1074             :     {
    1075           0 :         EditPaM aPaM = aSel.Min();
    1076           0 :         const CharAttribList::AttribsType& rAttrs = aPaM.GetNode()->GetCharAttribs().GetAttribs();
    1077           0 :         const sal_Int32 nXPos = aPaM.GetIndex();
    1078           0 :         for (size_t nAttr = rAttrs.size(); nAttr; )
    1079             :         {
    1080           0 :             const EditCharAttrib& rAttr = rAttrs[--nAttr];
    1081           0 :             if (rAttr.GetStart() == nXPos)
    1082           0 :                 if (rAttr.Which() == EE_FEATURE_FIELD)
    1083             :                 {
    1084             :                     DBG_ASSERT(rAttr.GetItem()->ISA( SvxFieldItem ), "No FeldItem...");
    1085           0 :                     return static_cast<const SvxFieldItem*>(rAttr.GetItem());
    1086             :                 }
    1087             :         }
    1088             :     }
    1089           0 :     return 0;
    1090             : }
    1091             : 
    1092           0 : void EditView::SetInvalidateMore( sal_uInt16 nPixel )
    1093             : {
    1094           0 :     pImpEditView->SetInvalidateMore( nPixel );
    1095           0 : }
    1096             : 
    1097           0 : sal_uInt16 EditView::GetInvalidateMore() const
    1098             : {
    1099           0 :     return (sal_uInt16)pImpEditView->GetInvalidateMore();
    1100             : }
    1101             : 
    1102           0 : static void ChangeFontSizeImpl( EditView* pEditView, bool bGrow, const ESelection& rSel, const FontList* pFontList )
    1103             : {
    1104           0 :     pEditView->SetSelection( rSel );
    1105             : 
    1106           0 :     SfxItemSet aSet( pEditView->GetAttribs() );
    1107           0 :     if( EditView::ChangeFontSize( bGrow, aSet, pFontList ) )
    1108             :     {
    1109           0 :         SfxItemSet aNewSet( pEditView->GetEmptyItemSet() );
    1110           0 :         aNewSet.Put( aSet.Get( EE_CHAR_FONTHEIGHT ), EE_CHAR_FONTHEIGHT );
    1111           0 :         aNewSet.Put( aSet.Get( EE_CHAR_FONTHEIGHT_CJK ), EE_CHAR_FONTHEIGHT_CJK );
    1112           0 :         aNewSet.Put( aSet.Get( EE_CHAR_FONTHEIGHT_CTL ), EE_CHAR_FONTHEIGHT_CTL );
    1113           0 :         pEditView->SetAttribs( aNewSet );
    1114           0 :     }
    1115           0 : }
    1116             : 
    1117           0 : void EditView::ChangeFontSize( bool bGrow, const FontList* pFontList )
    1118             : {
    1119             : 
    1120           0 :     EditEngine& rEditEngine = *pImpEditView->pEditEngine;
    1121             : 
    1122           0 :     ESelection aSel( GetSelection() );
    1123           0 :     ESelection aOldSelection( aSel );
    1124           0 :     aSel.Adjust();
    1125             : 
    1126           0 :     if( !aSel.HasRange() )
    1127             :     {
    1128           0 :         aSel = rEditEngine.GetWord( aSel, com::sun::star::i18n::WordType::DICTIONARY_WORD );
    1129             :     }
    1130             : 
    1131           0 :     if( aSel.HasRange() )
    1132             :     {
    1133           0 :         for( sal_Int32 nPara = aSel.nStartPara; nPara <= aSel.nEndPara; nPara++ )
    1134             :         {
    1135           0 :             std::vector<sal_Int32> aPortions;
    1136           0 :             rEditEngine.GetPortions( nPara, aPortions );
    1137             : 
    1138           0 :             if( aPortions.empty() )
    1139           0 :                 aPortions.push_back( rEditEngine.GetTextLen(nPara) );
    1140             : 
    1141           0 :             const sal_Int32 nBeginPos = (nPara == aSel.nStartPara) ? aSel.nStartPos : 0;
    1142           0 :             const sal_Int32 nEndPos = (nPara == aSel.nEndPara) ? aSel.nEndPos : EE_TEXTPOS_ALL;
    1143             : 
    1144           0 :             for ( size_t nPos = 0; nPos < aPortions.size(); ++nPos )
    1145             :             {
    1146           0 :                 sal_Int32 nPortionEnd   = aPortions[ nPos ];
    1147           0 :                 sal_Int32 nPortionStart = nPos > 0 ? aPortions[ nPos - 1 ] : 0;
    1148             : 
    1149           0 :                 if( (nPortionEnd < nBeginPos) || (nPortionStart > nEndPos) )
    1150           0 :                     continue;
    1151             : 
    1152           0 :                 if( nPortionStart < nBeginPos )
    1153           0 :                     nPortionStart = nBeginPos;
    1154           0 :                 if( nPortionEnd > nEndPos )
    1155           0 :                     nPortionEnd = nEndPos;
    1156             : 
    1157           0 :                 if( nPortionStart == nPortionEnd )
    1158           0 :                     continue;
    1159             : 
    1160           0 :                 ESelection aPortionSel( nPara, nPortionStart, nPara, nPortionEnd );
    1161           0 :                 ChangeFontSizeImpl( this, bGrow, aPortionSel, pFontList );
    1162             :             }
    1163           0 :         }
    1164             :     }
    1165             :     else
    1166             :     {
    1167           0 :         ChangeFontSizeImpl( this, bGrow, aSel, pFontList );
    1168             :     }
    1169             : 
    1170           0 :     SetSelection( aOldSelection );
    1171           0 : }
    1172             : 
    1173           0 : bool EditView::ChangeFontSize( bool bGrow, SfxItemSet& rSet, const FontList* pFontList )
    1174             : {
    1175             :     static const sal_uInt16 gFontSizeWichMap[] = { EE_CHAR_FONTHEIGHT, EE_CHAR_FONTHEIGHT_CJK, EE_CHAR_FONTHEIGHT_CTL, 0 };
    1176             : 
    1177           0 :     const SvxFontItem* pFontItem = static_cast<const SvxFontItem*>(&rSet.Get( EE_CHAR_FONTINFO ));
    1178           0 :     if( !pFontItem || !pFontList )
    1179           0 :         return false;
    1180             : 
    1181           0 :     bool bRet = false;
    1182             : 
    1183           0 :     const sal_uInt16* pWhich = gFontSizeWichMap;
    1184           0 :     while( *pWhich )
    1185             :     {
    1186           0 :         SvxFontHeightItem aFontHeightItem( static_cast<const SvxFontHeightItem&>(rSet.Get( *pWhich )) );
    1187           0 :         long nHeight = aFontHeightItem.GetHeight();
    1188           0 :         const SfxMapUnit eUnit = rSet.GetPool()->GetMetric( *pWhich );
    1189           0 :         nHeight = OutputDevice::LogicToLogic( nHeight * 10, (MapUnit)eUnit, MAP_POINT );
    1190             : 
    1191           0 :         vcl::FontInfo aFontInfo = pFontList->Get( pFontItem->GetFamilyName(), pFontItem->GetStyleName() );
    1192           0 :         const sal_IntPtr* pAry = pFontList->GetSizeAry( aFontInfo );
    1193             : 
    1194           0 :         if( bGrow )
    1195             :         {
    1196           0 :             while( *pAry )
    1197             :             {
    1198           0 :                 if( *pAry > nHeight )
    1199             :                 {
    1200           0 :                     nHeight = *pAry;
    1201           0 :                     break;
    1202             :                 }
    1203           0 :                 pAry++;
    1204             :             }
    1205             : 
    1206           0 :             if( *pAry == 0 )
    1207             :             {
    1208           0 :                 nHeight += (nHeight + 5) / 10;
    1209           0 :                 if( nHeight > 9999 )
    1210           0 :                     nHeight = 9999;
    1211             :             }
    1212             : 
    1213             :         }
    1214           0 :         else if( *pAry )
    1215             :         {
    1216           0 :             bool bFound = false;
    1217           0 :             if( *pAry < nHeight )
    1218             :             {
    1219           0 :                 pAry++;
    1220           0 :                 while( *pAry )
    1221             :                 {
    1222           0 :                     if( *pAry >= nHeight )
    1223             :                     {
    1224           0 :                         nHeight = pAry[-1];
    1225           0 :                         bFound = true;
    1226           0 :                         break;
    1227             :                     }
    1228           0 :                     pAry++;
    1229             :                 }
    1230             :             }
    1231             : 
    1232           0 :             if( !bFound )
    1233             :             {
    1234           0 :                 nHeight -= (nHeight + 5) / 10;
    1235           0 :                 if( nHeight < 2 )
    1236           0 :                     nHeight = 2;
    1237             :             }
    1238             :         }
    1239             : 
    1240           0 :         if( (nHeight >= 2) && (nHeight <= 9999 ) )
    1241             :         {
    1242           0 :             nHeight = OutputDevice::LogicToLogic( nHeight, MAP_POINT, (MapUnit)eUnit  ) / 10;
    1243             : 
    1244           0 :             if( nHeight != (long)aFontHeightItem.GetHeight() )
    1245             :             {
    1246           0 :                 aFontHeightItem.SetHeight( nHeight );
    1247           0 :                 rSet.Put( aFontHeightItem, *pWhich );
    1248           0 :                 bRet = true;
    1249             :             }
    1250             :         }
    1251           0 :         pWhich++;
    1252           0 :     }
    1253           0 :     return bRet;
    1254             : }
    1255             : 
    1256           0 : OUString EditView::GetSurroundingText() const
    1257             : {
    1258           0 :     EditSelection aSel( pImpEditView->GetEditSelection() );
    1259           0 :     aSel.Adjust( pImpEditView->pEditEngine->GetEditDoc() );
    1260             : 
    1261           0 :     if( HasSelection() )
    1262             :     {
    1263           0 :         OUString aStr = pImpEditView->pEditEngine->GetSelected(aSel);
    1264             : 
    1265             :         // Stop reconversion if the selected text includes a line break.
    1266           0 :         if ( aStr.indexOf( 0x0A ) == -1 )
    1267           0 :           return aStr;
    1268             :         else
    1269           0 :           return OUString();
    1270             :     }
    1271             :     else
    1272             :     {
    1273           0 :         aSel.Min().SetIndex( 0 );
    1274           0 :         aSel.Max().SetIndex( aSel.Max().GetNode()->Len() );
    1275           0 :         return pImpEditView->pEditEngine->GetSelected(aSel);
    1276             :     }
    1277             : }
    1278             : 
    1279           0 : Selection EditView::GetSurroundingTextSelection() const
    1280             : {
    1281           0 :     ESelection aSelection( GetSelection() );
    1282           0 :     aSelection.Adjust();
    1283             : 
    1284           0 :     if( HasSelection() )
    1285             :     {
    1286           0 :         EditSelection aSel( pImpEditView->GetEditSelection() );
    1287           0 :         aSel.Adjust( pImpEditView->pEditEngine->GetEditDoc() );
    1288           0 :         OUString aStr = pImpEditView->pEditEngine->GetSelected(aSel);
    1289             : 
    1290             :         // Stop reconversion if the selected text includes a line break.
    1291           0 :         if ( aStr.indexOf( 0x0A ) == -1 )
    1292           0 :             return Selection( 0, aSelection.nEndPos - aSelection.nStartPos );
    1293             :         else
    1294           0 :             return Selection( 0, 0 );
    1295             :     }
    1296             :     else
    1297             :     {
    1298           0 :         return Selection( aSelection.nStartPos, aSelection.nEndPos );
    1299             :     }
    1300         669 : }
    1301             : 
    1302             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10