LCOV - code coverage report
Current view: top level - sw/source/uibase/docvw - edtwin.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 635 3240 19.6 %
Date: 2015-06-13 12:38:46 Functions: 34 84 40.5 %
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 <config_features.h>
      21             : 
      22             : #include <swtypes.hxx>
      23             : #include <hintids.hxx>
      24             : #include <com/sun/star/accessibility/XAccessible.hpp>
      25             : #include <comphelper/processfactory.hxx>
      26             : #include <comphelper/string.hxx>
      27             : #include <com/sun/star/i18n/XBreakIterator.hpp>
      28             : #include <com/sun/star/i18n/ScriptType.hpp>
      29             : #include <com/sun/star/i18n/InputSequenceCheckMode.hpp>
      30             : 
      31             : #include <com/sun/star/i18n/UnicodeScript.hpp>
      32             : 
      33             : #include <vcl/help.hxx>
      34             : #include <vcl/graph.hxx>
      35             : #include <vcl/msgbox.hxx>
      36             : #include <sot/storage.hxx>
      37             : #include <svl/macitem.hxx>
      38             : #include <unotools/securityoptions.hxx>
      39             : #include <basic/sbxvar.hxx>
      40             : #include <svl/ctloptions.hxx>
      41             : #include <basic/sbx.hxx>
      42             : #include <svl/eitem.hxx>
      43             : #include <svl/stritem.hxx>
      44             : #include <sfx2/ipclient.hxx>
      45             : #include <sfx2/viewfrm.hxx>
      46             : #include <sfx2/request.hxx>
      47             : #include <sfx2/bindings.hxx>
      48             : #include <sfx2/dispatch.hxx>
      49             : #include <svl/ptitem.hxx>
      50             : #include <editeng/sizeitem.hxx>
      51             : #include <editeng/langitem.hxx>
      52             : #include <sfx2/htmlmode.hxx>
      53             : #include <svx/svdview.hxx>
      54             : #include <svx/svdhdl.hxx>
      55             : #include <svx/svdoutl.hxx>
      56             : #include <editeng/editeng.hxx>
      57             : #include <editeng/editview.hxx>
      58             : #include <editeng/svxacorr.hxx>
      59             : #include <editeng/scripttypeitem.hxx>
      60             : #include <editeng/flditem.hxx>
      61             : #include <editeng/colritem.hxx>
      62             : #include <editeng/brushitem.hxx>
      63             : #include <editeng/wghtitem.hxx>
      64             : #include <editeng/udlnitem.hxx>
      65             : #include <editeng/postitem.hxx>
      66             : #include <editeng/protitem.hxx>
      67             : #include <unotools/charclass.hxx>
      68             : #include <basegfx/color/bcolortools.hxx>
      69             : #include <basegfx/polygon/b2dpolygon.hxx>
      70             : 
      71             : #include <LibreOfficeKit/LibreOfficeKitEnums.h>
      72             : 
      73             : #include <editeng/acorrcfg.hxx>
      74             : #include <SwSmartTagMgr.hxx>
      75             : #include <edtwin.hxx>
      76             : #include <view.hxx>
      77             : #include <wrtsh.hxx>
      78             : #include <IDocumentSettingAccess.hxx>
      79             : #include <IDocumentDrawModelAccess.hxx>
      80             : #include <textboxhelper.hxx>
      81             : #include <dcontact.hxx>
      82             : #include <fldbas.hxx>
      83             : #include <swmodule.hxx>
      84             : #include <docsh.hxx>
      85             : #include <viewopt.hxx>
      86             : #include <drawbase.hxx>
      87             : #include <dselect.hxx>
      88             : #include <textsh.hxx>
      89             : #include <shdwcrsr.hxx>
      90             : #include <txatbase.hxx>
      91             : #include <fmtanchr.hxx>
      92             : #include <fmtornt.hxx>
      93             : #include <fmtfsize.hxx>
      94             : #include <fmtclds.hxx>
      95             : #include <fmthdft.hxx>
      96             : #include <frmfmt.hxx>
      97             : #include <modcfg.hxx>
      98             : #include <fmtcol.hxx>
      99             : #include <wview.hxx>
     100             : #include <listsh.hxx>
     101             : #include <gloslst.hxx>
     102             : #include <inputwin.hxx>
     103             : #include <gloshdl.hxx>
     104             : #include <swundo.hxx>
     105             : #include <drwtxtsh.hxx>
     106             : #include <fchrfmt.hxx>
     107             : #include <fmturl.hxx>
     108             : #include <romenu.hxx>
     109             : #include <initui.hxx>
     110             : #include <frmatr.hxx>
     111             : #include <extinput.hxx>
     112             : #include <acmplwrd.hxx>
     113             : #include <swcalwrp.hxx>
     114             : #include <swdtflvr.hxx>
     115             : #include <wdocsh.hxx>
     116             : #include <crsskip.hxx>
     117             : #include <breakit.hxx>
     118             : #include <checkit.hxx>
     119             : #include <pagefrm.hxx>
     120             : #include <HeaderFooterWin.hxx>
     121             : 
     122             : #include <helpid.h>
     123             : #include <cmdid.h>
     124             : #include <docvw.hrc>
     125             : #include <uitool.hxx>
     126             : #include <fmtfollowtextflow.hxx>
     127             : #include <toolkit/helper/vclunohelper.hxx>
     128             : #include <charfmt.hxx>
     129             : #include <numrule.hxx>
     130             : #include <pagedesc.hxx>
     131             : #include <svtools/ruler.hxx>
     132             : #include "formatclipboard.hxx"
     133             : #include <osl/mutex.hxx>
     134             : #include <vcl/svapp.hxx>
     135             : #include <docstat.hxx>
     136             : #include <wordcountdialog.hxx>
     137             : #include <swwait.hxx>
     138             : #include <txtfld.hxx>
     139             : #include <fmtfld.hxx>
     140             : 
     141             : #include <IMark.hxx>
     142             : #include <doc.hxx>
     143             : #include <xmloff/odffields.hxx>
     144             : 
     145             : #include <PostItMgr.hxx>
     146             : 
     147             : #include <algorithm>
     148             : #include <vector>
     149             : 
     150             : #include "../../core/inc/rootfrm.hxx"
     151             : 
     152             : #include <unotools/syslocaleoptions.hxx>
     153             : #include <boost/scoped_array.hpp>
     154             : #include <boost/scoped_ptr.hpp>
     155             : 
     156             : using namespace sw::mark;
     157             : using namespace ::com::sun::star;
     158             : 
     159             : /**
     160             :  * Globals
     161             :  */
     162             : static bool g_bInputLanguageSwitched = false;
     163             : extern bool g_bNoInterrupt;       // in mainwn.cxx
     164             : 
     165             : // Usually in MouseButtonUp a selection is revoked when the selection is
     166             : // not currently being pulled open. Unfortunately in MouseButtonDown there
     167             : // is being selected at double/triple click. That selection is completely
     168             : // finished in the Handler and thus can't be distinguished in the Up.
     169             : // To resolve this g_bHoldSelection is set in Down at evaluated in Up.
     170             : static bool g_bHoldSelection      = false;
     171             : 
     172             : bool g_bFrmDrag                   = false;
     173             : bool g_bValidCrsrPos              = false;
     174             : bool g_bModePushed                = false;
     175             : bool g_bDDTimerStarted            = false;
     176             : bool g_bFlushCharBuffer           = false;
     177             : bool g_bDDINetAttr                = false;
     178             : SdrHdlKind g_eSdrMoveHdl          = HDL_USER;
     179             : 
     180             : QuickHelpData* SwEditWin::m_pQuickHlpData = 0;
     181             : 
     182             : long    SwEditWin::m_nDDStartPosY = 0;
     183             : long    SwEditWin::m_nDDStartPosX = 0;
     184             : /**
     185             :  * The initial color shown on the button is set in /core/svx/source/tbxctrls/tbxcolorupdate.cxx
     186             :  * (ToolboxButtonColorUpdater::ToolboxButtonColorUpdater()) .
     187             :  * The initial color used by the button is set in /core/svx/source/tbxcntrls/tbcontrl.cxx
     188             :  * (SvxColorToolBoxControl::SvxColorToolBoxControl())
     189             :  * and in case of writer for text(background)color also in /core/sw/source/uibase/docvw/edtwin.cxx
     190             :  * (SwEditWin::m_aTextBackColor and SwEditWin::m_aTextColor)
     191             :  */
     192          59 : Color   SwEditWin::m_aWaterCanTextBackColor(COL_YELLOW);
     193          59 : Color   SwEditWin::m_aWaterCanTextColor(COL_RED);
     194             : 
     195             : extern bool     g_bExecuteDrag;
     196             : 
     197             : static SfxShell* lcl_GetShellFromDispatcher( SwView& rView, TypeId nType );
     198             : 
     199             : class SwAnchorMarker
     200             : {
     201             :     SdrHdl* pHdl;
     202             :     Point aHdlPos;
     203             :     Point aLastPos;
     204             :     bool bTopRightHandle;
     205             : public:
     206           0 :     explicit SwAnchorMarker( SdrHdl* pH )
     207             :         : pHdl( pH )
     208           0 :         , aHdlPos( pH->GetPos() )
     209           0 :         , aLastPos( pH->GetPos() )
     210           0 :         , bTopRightHandle( pH->GetKind() == HDL_ANCHOR_TR )
     211           0 :     {}
     212           0 :     const Point& GetLastPos() const { return aLastPos; }
     213           0 :     void SetLastPos( const Point& rNew ) { aLastPos = rNew; }
     214           0 :     void SetPos( const Point& rNew ) { pHdl->SetPos( rNew ); }
     215           0 :     const Point& GetPos() { return pHdl->GetPos(); }
     216           0 :     const Point& GetHdlPos() { return aHdlPos; }
     217           0 :     SdrHdl* GetHdl() const { return pHdl; }
     218           0 :     void ChgHdl( SdrHdl* pNew )
     219             :     {
     220           0 :         pHdl = pNew;
     221           0 :         if ( pHdl )
     222             :         {
     223           0 :             bTopRightHandle = (pHdl->GetKind() == HDL_ANCHOR_TR);
     224             :         }
     225           0 :     }
     226           0 :     const Point GetPosForHitTest( const OutputDevice& rOut )
     227             :     {
     228           0 :         Point aHitTestPos( GetPos() );
     229           0 :         aHitTestPos = rOut.LogicToPixel( aHitTestPos );
     230           0 :         if ( bTopRightHandle )
     231             :         {
     232           0 :             aHitTestPos += Point( -1, 1 );
     233             :         }
     234             :         else
     235             :         {
     236           0 :             aHitTestPos += Point( 1, 1 );
     237             :         }
     238           0 :         aHitTestPos = rOut.PixelToLogic( aHitTestPos );
     239             : 
     240           0 :         return aHitTestPos;
     241             :     }
     242             : };
     243             : 
     244             : /// Assists with auto-completion of AutoComplete words and AutoText names.
     245          60 : struct QuickHelpData
     246             : {
     247             :     /// Strings that at least partially match an input word.
     248             :     std::vector<OUString> m_aHelpStrings;
     249             :     /// Index of the current help string.
     250             :     sal_uInt16 nCurArrPos;
     251             :     /// Length of the input word associated with the help data.
     252             :     sal_uInt16 nLen;
     253             : 
     254             :     /// Help data stores AutoText names rather than AutoComplete words.
     255             :     bool m_bIsAutoText;
     256             :     /// Display help string as a tip rather than inline.
     257             :     bool m_bIsTip;
     258             :     /// Tip ID when a help string is displayed as a tip.
     259             :     sal_uLong nTipId;
     260             :     /// Append a space character to the displayed help string (if appropriate).
     261             :     bool m_bAppendSpace;
     262             : 
     263             :     /// Help string is currently displayed.
     264             :     bool m_bIsDisplayed;
     265             : 
     266          60 :     QuickHelpData() { ClearContent(); }
     267             : 
     268             :     void Move( QuickHelpData& rCpy );
     269             :     void ClearContent();
     270             :     void Start( SwWrtShell& rSh, sal_uInt16 nWrdLen );
     271             :     void Stop( SwWrtShell& rSh );
     272             : 
     273           1 :     bool HasContent() const { return !m_aHelpStrings.empty() && 0 != nLen; }
     274             : 
     275             :     /// Next help string.
     276           0 :     void Next( bool bEndLess )
     277             :     {
     278           0 :         if( ++nCurArrPos >= m_aHelpStrings.size() )
     279           0 :             nCurArrPos = (bEndLess && !m_bIsAutoText ) ? 0 : nCurArrPos-1;
     280           0 :     }
     281             :     /// Previous help string.
     282           0 :     void Previous( bool bEndLess )
     283             :     {
     284           0 :         if( 0 == nCurArrPos-- )
     285           0 :             nCurArrPos = (bEndLess && !m_bIsAutoText ) ? m_aHelpStrings.size()-1 : 0;
     286           0 :     }
     287             : 
     288             :     // Fills internal structures with hopefully helpful information.
     289             :     void FillStrArr( SwWrtShell& rSh, const OUString& rWord );
     290             :     void SortAndFilter(const OUString &rOrigWord);
     291             : };
     292             : 
     293             : /**
     294             :  * Avoid minimal movement shiver
     295             :  */
     296             : #define HIT_PIX  2 /* hit tolerance in pixel  */
     297             : #define MIN_MOVE 4
     298             : 
     299           1 : inline bool IsMinMove(const Point &rStartPos, const Point &rLPt)
     300             : {
     301           1 :     return std::abs(rStartPos.X() - rLPt.X()) > MIN_MOVE ||
     302           1 :            std::abs(rStartPos.Y() - rLPt.Y()) > MIN_MOVE;
     303             : }
     304             : 
     305             : /**
     306             :  * For MouseButtonDown - determine whether a DrawObject
     307             :  * an NO SwgFrame was hit! Shift/Ctrl should only result
     308             :  * in selecting, with DrawObjects; at SwgFlys to trigger
     309             :  * hyperlinks if applicable (Download/NewWindow!)
     310             :  */
     311           0 : inline bool IsDrawObjSelectable( const SwWrtShell& rSh, const Point& rPt )
     312             : {
     313           0 :     bool bRet = true;
     314             :     SdrObject* pObj;
     315           0 :     switch( rSh.GetObjCntType( rPt, pObj ))
     316             :     {
     317             :     case OBJCNT_NONE:
     318             :     case OBJCNT_FLY:
     319             :     case OBJCNT_GRF:
     320             :     case OBJCNT_OLE:
     321           0 :         bRet = false;
     322           0 :         break;
     323             :     default:; //prevent warning
     324             :     }
     325           0 :     return bRet;
     326             : }
     327             : 
     328             : /*
     329             :  * Switch pointer
     330             :  */
     331        2781 : void SwEditWin::UpdatePointer(const Point &rLPt, sal_uInt16 nModifier )
     332             : {
     333        2781 :     SwWrtShell &rSh = m_rView.GetWrtShell();
     334        2781 :     if( m_pApplyTempl )
     335             :     {
     336           0 :         PointerStyle eStyle = PointerStyle::Fill;
     337           0 :         if ( rSh.IsOverReadOnlyPos( rLPt ) )
     338             :         {
     339           0 :             delete m_pUserMarker;
     340           0 :             m_pUserMarker = 0L;
     341             : 
     342           0 :             eStyle = PointerStyle::NotAllowed;
     343             :         }
     344             :         else
     345             :         {
     346           0 :             SwRect aRect;
     347           0 :             SwRect* pRect = &aRect;
     348           0 :             const SwFrameFormat* pFormat = 0;
     349             : 
     350           0 :             bool bFrameIsValidTarget = false;
     351           0 :             if( m_pApplyTempl->m_pFormatClipboard )
     352           0 :                 bFrameIsValidTarget = m_pApplyTempl->m_pFormatClipboard->HasContentForThisType( nsSelectionType::SEL_FRM );
     353           0 :             else if( !m_pApplyTempl->nColor )
     354           0 :                 bFrameIsValidTarget = ( m_pApplyTempl->eType == SFX_STYLE_FAMILY_FRAME );
     355             : 
     356           0 :             if( bFrameIsValidTarget &&
     357           0 :                         0 !=(pFormat = rSh.GetFormatFromObj( rLPt, &pRect )) &&
     358           0 :                         PTR_CAST(SwFlyFrameFormat, pFormat))
     359             :             {
     360             :                 //turn on highlight for frame
     361           0 :                 Rectangle aTmp( pRect->SVRect() );
     362             : 
     363           0 :                 if ( !m_pUserMarker )
     364             :                 {
     365           0 :                     m_pUserMarker = new SdrDropMarkerOverlay( *rSh.GetDrawView(), aTmp );
     366             :                 }
     367             :             }
     368             :             else
     369             :             {
     370           0 :                 delete m_pUserMarker;
     371           0 :                 m_pUserMarker = 0L;
     372             :             }
     373             : 
     374           0 :             rSh.SwCrsrShell::SetVisCrsr( rLPt );
     375             :         }
     376           0 :         SetPointer( eStyle );
     377         588 :         return;
     378             :     }
     379             : 
     380        2781 :     if( !rSh.VisArea().Width() )
     381         588 :         return;
     382             : 
     383        2193 :     SET_CURR_SHELL(&rSh);
     384             : 
     385        2193 :     if ( IsChainMode() )
     386             :     {
     387           0 :         SwRect aRect;
     388           0 :         SwChainRet nChainable = rSh.Chainable( aRect, *rSh.GetFlyFrameFormat(), rLPt );
     389             :         PointerStyle eStyle = nChainable != SwChainRet::OK
     390           0 :                 ? PointerStyle::ChainNotAllowed : PointerStyle::Chain;
     391           0 :         if ( nChainable == SwChainRet::OK )
     392             :         {
     393           0 :             Rectangle aTmp( aRect.SVRect() );
     394             : 
     395           0 :             if ( !m_pUserMarker )
     396             :             {
     397           0 :                 m_pUserMarker = new SdrDropMarkerOverlay( *rSh.GetDrawView(), aTmp );
     398             :             }
     399             :         }
     400             :         else
     401             :         {
     402           0 :             delete m_pUserMarker;
     403           0 :             m_pUserMarker = 0L;
     404             :         }
     405             : 
     406           0 :         SetPointer( eStyle );
     407           0 :         return;
     408             :     }
     409             : 
     410        2193 :     bool bExecHyperlinks = m_rView.GetDocShell()->IsReadOnly();
     411        2193 :     if ( !bExecHyperlinks )
     412             :     {
     413        2191 :         SvtSecurityOptions aSecOpts;
     414        2191 :         const bool bSecureOption = aSecOpts.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK );
     415        4382 :         if ( (  bSecureOption && nModifier == KEY_MOD1 ) ||
     416        2191 :              ( !bSecureOption && nModifier != KEY_MOD1 ) )
     417           0 :             bExecHyperlinks = true;
     418             :     }
     419             : 
     420        2193 :     const bool bExecSmarttags  = nModifier == KEY_MOD1;
     421             : 
     422        2193 :     SdrView *pSdrView = rSh.GetDrawView();
     423        2193 :     bool bPrefSdrPointer = false;
     424        2193 :     bool bHitHandle = false;
     425        2193 :     bool bCntAtPos = false;
     426        2195 :     bool bIsDocReadOnly = m_rView.GetDocShell()->IsReadOnly() &&
     427        2195 :                           rSh.IsCrsrReadonly();
     428        2193 :     m_aActHitType = SDRHIT_NONE;
     429        2193 :     PointerStyle eStyle = PointerStyle::Text;
     430        2193 :     if ( !pSdrView )
     431           0 :         bCntAtPos = true;
     432        2193 :     else if ( (bHitHandle = pSdrView->PickHandle( rLPt ) != 0) )
     433             :     {
     434           2 :         m_aActHitType = SDRHIT_OBJECT;
     435           2 :         bPrefSdrPointer = true;
     436             :     }
     437             :     else
     438             :     {
     439        2191 :         const bool bNotInSelObj = !rSh.IsInsideSelectedObj( rLPt );
     440        2191 :         if ( m_rView.GetDrawFuncPtr() && !m_bInsDraw && bNotInSelObj )
     441             :         {
     442           0 :             m_aActHitType = SDRHIT_OBJECT;
     443           0 :             if (IsObjectSelect())
     444           0 :                 eStyle = PointerStyle::Arrow;
     445             :             else
     446           0 :                 bPrefSdrPointer = true;
     447             :         }
     448             :         else
     449             :         {
     450             :             SdrObject* pObj; SdrPageView* pPV;
     451        2191 :             pSdrView->SetHitTolerancePixel( HIT_PIX );
     452        2193 :             if ( bNotInSelObj && bExecHyperlinks &&
     453           2 :                  pSdrView->PickObj( rLPt, pSdrView->getHitTolLog(), pObj, pPV, SdrSearchOptions::PICKMACRO ))
     454             :             {
     455           0 :                 SdrObjMacroHitRec aTmp;
     456           0 :                 aTmp.aPos = rLPt;
     457           0 :                 aTmp.pPageView = pPV;
     458           0 :                 SetPointer( pObj->GetMacroPointer( aTmp ) );
     459           0 :                 return;
     460             :             }
     461             :             else
     462             :             {
     463             :                 // dvo: IsObjSelectable() eventually calls SdrView::PickObj, so
     464             :                 // apparently this is used to determine whether this is a
     465             :                 // drawling layer object or not.
     466        2191 :                 if ( rSh.IsObjSelectable( rLPt ) )
     467             :                 {
     468           0 :                     if (pSdrView->IsTextEdit())
     469             :                     {
     470           0 :                         m_aActHitType = SDRHIT_NONE;
     471           0 :                         bPrefSdrPointer = true;
     472             :                     }
     473             :                     else
     474             :                     {
     475           0 :                         SdrViewEvent aVEvt;
     476           0 :                         SdrHitKind eHit = pSdrView->PickAnything(rLPt, aVEvt);
     477             : 
     478           0 :                         if (eHit == SDRHIT_URLFIELD && bExecHyperlinks)
     479             :                         {
     480           0 :                             m_aActHitType = SDRHIT_OBJECT;
     481           0 :                             bPrefSdrPointer = true;
     482             :                         }
     483             :                         else
     484             :                         {
     485             :                             // if we're over a selected object, we show an
     486             :                             // ARROW by default. We only show a MOVE if 1) the
     487             :                             // object is selected, and 2) it may be moved
     488             :                             // (i.e., position is not protected).
     489             :                             bool bMovable =
     490           0 :                                 (!bNotInSelObj) &&
     491           0 :                                 (rSh.IsObjSelected() || rSh.IsFrmSelected()) &&
     492           0 :                                 (rSh.IsSelObjProtected(FlyProtectFlags::Pos) == FlyProtectFlags::NONE);
     493             : 
     494           0 :                             SdrObject* pSelectableObj = rSh.GetObjAt(rLPt);
     495             :                             // Don't update pointer if this is a background image only.
     496           0 :                             if (pSelectableObj->GetLayer() != rSh.GetDoc()->getIDocumentDrawModelAccess().GetHellId())
     497           0 :                                 eStyle = bMovable ? PointerStyle::Move : PointerStyle::Arrow;
     498           0 :                             m_aActHitType = SDRHIT_OBJECT;
     499           0 :                         }
     500             :                     }
     501             :                 }
     502             :                 else
     503             :                 {
     504        2191 :                     if ( rSh.IsFrmSelected() && !bNotInSelObj )
     505             :                     {
     506             :                         // dvo: this branch appears to be dead and should be
     507             :                         // removed in a future version. Reason: The condition
     508             :                         // !bNotInSelObj means that this branch will only be
     509             :                         // executed in the cursor points inside a selected
     510             :                         // object. However, if this is the case, the previous
     511             :                         // if( rSh.IsObjSelectable(rLPt) ) must always be true:
     512             :                         // rLPt is inside a selected object, then obviously
     513             :                         // rLPt is over a selectable object.
     514           0 :                         if (rSh.IsSelObjProtected(FlyProtectFlags::Size) != FlyProtectFlags::NONE)
     515           0 :                             eStyle = PointerStyle::NotAllowed;
     516             :                         else
     517           0 :                             eStyle = PointerStyle::Move;
     518           0 :                         m_aActHitType = SDRHIT_OBJECT;
     519             :                     }
     520             :                     else
     521             :                     {
     522        2191 :                         if ( m_rView.GetDrawFuncPtr() )
     523           0 :                             bPrefSdrPointer = true;
     524             :                         else
     525        2191 :                             bCntAtPos = true;
     526             :                     }
     527             :                 }
     528             :             }
     529             :         }
     530             :     }
     531        2193 :     if ( bPrefSdrPointer )
     532             :     {
     533           2 :         if (bIsDocReadOnly || (rSh.IsObjSelected() && rSh.IsSelObjProtected(FlyProtectFlags::Content) != FlyProtectFlags::NONE))
     534           0 :             SetPointer( PointerStyle::NotAllowed );
     535             :         else
     536             :         {
     537           2 :             if (m_rView.GetDrawFuncPtr() && m_rView.GetDrawFuncPtr()->IsInsertForm() && !bHitHandle)
     538           0 :                 SetPointer( PointerStyle::DrawRect );
     539             :             else
     540           2 :                 SetPointer( pSdrView->GetPreferredPointer( rLPt, rSh.GetOut() ) );
     541             :         }
     542             :     }
     543             :     else
     544             :     {
     545        2191 :         if( !rSh.IsPageAtPos( rLPt ) || m_pAnchorMarker )
     546        2190 :             eStyle = PointerStyle::Arrow;
     547             :         else
     548             :         {
     549             :             // Even if we already have something, prefer URLs if possible.
     550           1 :             SwContentAtPos aUrlPos(SwContentAtPos::SW_INETATTR);
     551           1 :             if (bCntAtPos || rSh.GetContentAtPos(rLPt, aUrlPos))
     552             :             {
     553             :                 SwContentAtPos aSwContentAtPos(
     554             :                     SwContentAtPos::SW_FIELD |
     555             :                     SwContentAtPos::SW_CLICKFIELD |
     556             :                     SwContentAtPos::SW_INETATTR |
     557             :                     SwContentAtPos::SW_FTN |
     558           1 :                     SwContentAtPos::SW_SMARTTAG );
     559           1 :                 if( rSh.GetContentAtPos( rLPt, aSwContentAtPos) )
     560             :                 {
     561             :                     // Is edit inline input field
     562           0 :                     if (SwContentAtPos::SW_FIELD == aSwContentAtPos.eContentAtPos)
     563             :                     {
     564           0 :                         if ( aSwContentAtPos.pFndTextAttr != NULL
     565           0 :                             && aSwContentAtPos.pFndTextAttr->Which() == RES_TXTATR_INPUTFIELD)
     566             :                         {
     567           0 :                             const SwField *pCrsrField = rSh.CrsrInsideInputField() ? rSh.GetCurField( true ) : NULL;
     568           0 :                             if (!(pCrsrField && pCrsrField == aSwContentAtPos.pFndTextAttr->GetFormatField().GetField()))
     569           0 :                                 eStyle = PointerStyle::RefHand;
     570             :                         }
     571             :                     }
     572             :                     else
     573             :                     {
     574           0 :                         const bool bClickToFollow = SwContentAtPos::SW_INETATTR == aSwContentAtPos.eContentAtPos ||
     575           0 :                                                     SwContentAtPos::SW_SMARTTAG == aSwContentAtPos.eContentAtPos;
     576           0 :                         if( !bClickToFollow ||
     577           0 :                             (SwContentAtPos::SW_INETATTR == aSwContentAtPos.eContentAtPos && bExecHyperlinks) ||
     578           0 :                             (SwContentAtPos::SW_SMARTTAG == aSwContentAtPos.eContentAtPos && bExecSmarttags) )
     579           0 :                             eStyle = PointerStyle::RefHand;
     580             :                     }
     581           1 :                 }
     582           1 :             }
     583             :         }
     584             : 
     585             :         // which kind of text pointer have we to show - horz / vert - ?
     586        2191 :         if( PointerStyle::Text == eStyle && rSh.IsInVerticalText( &rLPt ))
     587           0 :             eStyle = PointerStyle::TextVertical;
     588             : 
     589        2191 :         SetPointer( eStyle );
     590        2193 :     }
     591             : }
     592             : 
     593             : /**
     594             :  * Increase timer for selection
     595             :  */
     596           0 : IMPL_LINK_NOARG_TYPED(SwEditWin, TimerHandler, Timer *, void)
     597             : {
     598           0 :     SwWrtShell &rSh = m_rView.GetWrtShell();
     599           0 :     Point aModPt( m_aMovePos );
     600           0 :     const SwRect aOldVis( rSh.VisArea() );
     601           0 :     bool bDone = false;
     602             : 
     603           0 :     if ( !rSh.VisArea().IsInside( aModPt ) )
     604             :     {
     605           0 :         if ( m_bInsDraw )
     606             :         {
     607           0 :             const int nMaxScroll = 40;
     608           0 :             m_rView.Scroll( Rectangle(aModPt,Size(1,1)), nMaxScroll, nMaxScroll);
     609           0 :             bDone = true;
     610             :         }
     611           0 :         else if ( g_bFrmDrag )
     612             :         {
     613           0 :             rSh.Drag(&aModPt, false);
     614           0 :             bDone = true;
     615             :         }
     616           0 :         if ( !bDone )
     617           0 :             aModPt = rSh.GetContentPos( aModPt,aModPt.Y() > rSh.VisArea().Bottom() );
     618             :     }
     619           0 :     if ( !bDone && !(g_bFrmDrag || m_bInsDraw) )
     620             :     {
     621           0 :         if ( m_pRowColumnSelectionStart )
     622             :         {
     623           0 :             Point aPos( aModPt );
     624           0 :             rSh.SelectTableRowCol( *m_pRowColumnSelectionStart, &aPos, m_bIsRowDrag );
     625             :         }
     626             :         else
     627           0 :             rSh.SetCursor( &aModPt, false );
     628             : 
     629             :         // It can be that a "jump" over a table cannot be accomplished like
     630             :         // that. So we jump over the table by Up/Down here.
     631           0 :         const SwRect& rVisArea = rSh.VisArea();
     632           0 :         if( aOldVis == rVisArea && !rSh.IsStartOfDoc() && !rSh.IsEndOfDoc() )
     633             :         {
     634             :             // take the center point of VisArea to
     635             :             // decide in which direction the user want.
     636           0 :             if( aModPt.Y() < ( rVisArea.Top() + rVisArea.Height() / 2 ) )
     637           0 :                 rSh.Up( true, 1 );
     638             :             else
     639           0 :                 rSh.Down( true, 1 );
     640             :         }
     641             :     }
     642             : 
     643           0 :     m_aMovePos += rSh.VisArea().Pos() - aOldVis.Pos();
     644           0 :     JustifyAreaTimer();
     645           0 : }
     646             : 
     647           0 : void SwEditWin::JustifyAreaTimer()
     648             : {
     649           0 :     const Rectangle &rVisArea = GetView().GetVisArea();
     650             : #ifdef UNX
     651           0 :     const long coMinLen = 100;
     652             : #else
     653             :     const long coMinLen = 50;
     654             : #endif
     655           0 :     long nTimeout = 800,
     656             :          nDiff = std::max(
     657           0 :          std::max( m_aMovePos.Y() - rVisArea.Bottom(), rVisArea.Top() - m_aMovePos.Y() ),
     658           0 :          std::max( m_aMovePos.X() - rVisArea.Right(),  rVisArea.Left() - m_aMovePos.X()));
     659           0 :     m_aTimer.SetTimeout( std::max( coMinLen, nTimeout - nDiff*2L) );
     660           0 : }
     661             : 
     662           0 : void SwEditWin::LeaveArea(const Point &rPos)
     663             : {
     664           0 :     m_aMovePos = rPos;
     665           0 :     JustifyAreaTimer();
     666           0 :     if( !m_aTimer.IsActive() )
     667           0 :         m_aTimer.Start();
     668           0 :     delete m_pShadCrsr, m_pShadCrsr = 0;
     669           0 : }
     670             : 
     671           4 : inline void SwEditWin::EnterArea()
     672             : {
     673           4 :     m_aTimer.Stop();
     674           4 : }
     675             : 
     676             : /**
     677             :  * Insert mode for frames
     678             :  */
     679           0 : void SwEditWin::InsFrm(sal_uInt16 nCols)
     680             : {
     681           0 :     StdDrawMode( OBJ_NONE, false );
     682           0 :     m_bInsFrm = true;
     683           0 :     m_nInsFrmColCount = nCols;
     684           0 : }
     685             : 
     686           0 : void SwEditWin::StdDrawMode( SdrObjKind eSdrObjectKind, bool bObjSelect )
     687             : {
     688           0 :     SetSdrDrawMode( eSdrObjectKind );
     689             : 
     690           0 :     if (bObjSelect)
     691           0 :         m_rView.SetDrawFuncPtr(new DrawSelection( &m_rView.GetWrtShell(), this, &m_rView ));
     692             :     else
     693           0 :         m_rView.SetDrawFuncPtr(new SwDrawBase( &m_rView.GetWrtShell(), this, &m_rView ));
     694             : 
     695           0 :     m_rView.SetSelDrawSlot();
     696           0 :     SetSdrDrawMode( eSdrObjectKind );
     697           0 :     if (bObjSelect)
     698           0 :         m_rView.GetDrawFuncPtr()->Activate( SID_OBJECT_SELECT );
     699             :     else
     700           0 :         m_rView.GetDrawFuncPtr()->Activate( sal::static_int_cast< sal_uInt16 >(eSdrObjectKind) );
     701           0 :     m_bInsFrm = false;
     702           0 :     m_nInsFrmColCount = 1;
     703           0 : }
     704             : 
     705           0 : void SwEditWin::StopInsFrm()
     706             : {
     707           0 :     if (m_rView.GetDrawFuncPtr())
     708             :     {
     709           0 :         m_rView.GetDrawFuncPtr()->Deactivate();
     710           0 :         m_rView.SetDrawFuncPtr(NULL);
     711             :     }
     712           0 :     m_rView.LeaveDrawCreate();    // leave construction mode
     713           0 :     m_bInsFrm = false;
     714           0 :     m_nInsFrmColCount = 1;
     715           0 : }
     716             : 
     717           1 : bool SwEditWin::IsInputSequenceCheckingRequired( const OUString &rText, const SwPaM& rCrsr )
     718             : {
     719           1 :     const SvtCTLOptions& rCTLOptions = SW_MOD()->GetCTLOptions();
     720           2 :     if ( !rCTLOptions.IsCTLFontEnabled() ||
     721           1 :          !rCTLOptions.IsCTLSequenceChecking() )
     722           1 :          return false;
     723             : 
     724           0 :     if ( 0 == rCrsr.Start()->nContent.GetIndex() ) /* first char needs not to be checked */
     725           0 :         return false;
     726             : 
     727           0 :     SwBreakIt *pBreakIter = SwBreakIt::Get();
     728           0 :     uno::Reference < i18n::XBreakIterator > xBI = pBreakIter->GetBreakIter();
     729           0 :     long nCTLScriptPos = -1;
     730             : 
     731           0 :     if (xBI.is())
     732             :     {
     733           0 :         if (xBI->getScriptType( rText, 0 ) == i18n::ScriptType::COMPLEX)
     734           0 :             nCTLScriptPos = 0;
     735             :         else
     736           0 :             nCTLScriptPos = xBI->nextScript( rText, 0, i18n::ScriptType::COMPLEX );
     737             :     }
     738             : 
     739           0 :     return (0 <= nCTLScriptPos && nCTLScriptPos <= rText.getLength());
     740             : }
     741             : 
     742             : //return INVALID_HINT if language should not be explicitly overridden, the correct
     743             : //HintId to use for the eBufferLanguage otherwise
     744           1 : static sal_uInt16 lcl_isNonDefaultLanguage(LanguageType eBufferLanguage, SwView& rView,
     745             :     const OUString &rInBuffer)
     746             : {
     747           1 :     sal_uInt16 nWhich = INVALID_HINT;
     748             : 
     749             :     //If the option to IgnoreLanguageChange is set, short-circuit this method
     750             :     //which results in the document/paragraph language remaining the same
     751             :     //despite a change to the keyboard/input language
     752           1 :     SvtSysLocaleOptions aSysLocaleOptions;
     753           1 :     if(aSysLocaleOptions.IsIgnoreLanguageChange())
     754             :     {
     755           0 :         return INVALID_HINT;
     756             :     }
     757             : 
     758           1 :     bool bLang = true;
     759           1 :     if(eBufferLanguage != LANGUAGE_DONTKNOW)
     760             :     {
     761           0 :         switch( SvtLanguageOptions::GetI18NScriptTypeOfLanguage( eBufferLanguage ))
     762             :         {
     763           0 :             case  i18n::ScriptType::ASIAN:     nWhich = RES_CHRATR_CJK_LANGUAGE; break;
     764           0 :             case  i18n::ScriptType::COMPLEX:   nWhich = RES_CHRATR_CTL_LANGUAGE; break;
     765           0 :             case  i18n::ScriptType::LATIN:     nWhich = RES_CHRATR_LANGUAGE; break;
     766           0 :             default: bLang = false;
     767             :         }
     768           0 :         if(bLang)
     769             :         {
     770           0 :             SfxItemSet aLangSet(rView.GetPool(), nWhich, nWhich);
     771           0 :             SwWrtShell& rSh = rView.GetWrtShell();
     772           0 :             rSh.GetCurAttr(aLangSet);
     773           0 :             if(SfxItemState::DEFAULT <= aLangSet.GetItemState(nWhich, true))
     774             :             {
     775           0 :                 LanguageType eLang = static_cast<const SvxLanguageItem&>(aLangSet.Get(nWhich)).GetLanguage();
     776           0 :                 if ( eLang == eBufferLanguage )
     777             :                 {
     778             :                     // current language attribute equal to language reported from system
     779           0 :                     bLang = false;
     780             :                 }
     781           0 :                 else if ( !g_bInputLanguageSwitched && RES_CHRATR_LANGUAGE == nWhich )
     782             :                 {
     783             :                     // special case: switching between two "LATIN" languages
     784             :                     // In case the current keyboard setting might be suitable
     785             :                     // for both languages we can't safely assume that the user
     786             :                     // wants to use the language reported from the system,
     787             :                     // except if we knew that it was explicitly switched (thus
     788             :                     // the check for "bInputLangeSwitched").
     789             : 
     790             :                     // The language reported by the system could be just the
     791             :                     // system default language that the user is not even aware
     792             :                     // of, because no language selection tool is installed at
     793             :                     // all. In this case the OOo language should get preference
     794             :                     // as it might have been selected by the user explicitly.
     795             : 
     796             :                     // Usually this case happens if the OOo language is
     797             :                     // different to the system language but the system keyboard
     798             :                     // is still suitable for the OOo language (e.g. writing
     799             :                     // English texts with a German keyboard).
     800             : 
     801             :                     // For non-latin keyboards overwriting the attribute is
     802             :                     // still valid. We do this for kyrillic and greek ATM.  In
     803             :                     // future versions of OOo this should be replaced by a
     804             :                     // configuration switch that allows to give the preference
     805             :                     // to the OOo setting or the system setting explicitly
     806             :                     // and/or a better handling of the script type.
     807           0 :                     i18n::UnicodeScript eType = !rInBuffer.isEmpty() ?
     808           0 :                         (i18n::UnicodeScript)GetAppCharClass().getScript( rInBuffer, 0 ) :
     809           0 :                         i18n::UnicodeScript_kScriptCount;
     810             : 
     811           0 :                     bool bSystemIsNonLatin = false;
     812           0 :                     switch ( eType )
     813             :                     {
     814             :                         case i18n::UnicodeScript_kGreek:
     815             :                         case i18n::UnicodeScript_kCyrillic:
     816             :                             // in case other UnicodeScripts require special
     817             :                             // keyboards they can be added here
     818           0 :                             bSystemIsNonLatin = true;
     819           0 :                             break;
     820             :                         default:
     821           0 :                             break;
     822             :                     }
     823             : 
     824           0 :                     bool bOOoLangIsNonLatin = MsLangId::isNonLatinWestern( eLang);
     825             : 
     826           0 :                     bLang = (bSystemIsNonLatin != bOOoLangIsNonLatin);
     827             :                 }
     828           0 :             }
     829             :         }
     830             :     }
     831           1 :     return bLang ? nWhich : INVALID_HINT;
     832             : }
     833             : 
     834             : /**
     835             :  * Character buffer is inserted into the document
     836             :  */
     837           5 : void SwEditWin::FlushInBuffer()
     838             : {
     839           5 :     if ( !m_aInBuffer.isEmpty() )
     840             :     {
     841           1 :         SwWrtShell& rSh = m_rView.GetWrtShell();
     842             : 
     843             :         // generate new sequence input checker if not already done
     844           1 :         if ( !pCheckIt )
     845           1 :             pCheckIt = new SwCheckIt;
     846             : 
     847           1 :         uno::Reference < i18n::XExtendedInputSequenceChecker > xISC = pCheckIt->xCheck;
     848           1 :         if ( xISC.is() && IsInputSequenceCheckingRequired( m_aInBuffer, *rSh.GetCrsr() ) )
     849             :         {
     850             : 
     851             :             // apply (Thai) input sequence checking/correction
     852             : 
     853           0 :             rSh.Push(); // push current cursor to stack
     854             : 
     855             :             // get text from the beginning (i.e left side) of current selection
     856             :             // to the start of the paragraph
     857           0 :             rSh.NormalizePam();     // make point be the first (left) one
     858           0 :             if (!rSh.GetCrsr()->HasMark())
     859           0 :                 rSh.GetCrsr()->SetMark();
     860           0 :             rSh.GetCrsr()->GetMark()->nContent = 0;
     861             : 
     862           0 :             const OUString aOldText( rSh.GetCrsr()->GetText() );
     863           0 :             const sal_Int32 nOldLen = aOldText.getLength();
     864             : 
     865           0 :             SvtCTLOptions& rCTLOptions = SW_MOD()->GetCTLOptions();
     866             : 
     867           0 :             sal_Int32 nExpandSelection = 0;
     868           0 :             if (nOldLen > 0)
     869             :             {
     870           0 :                 sal_Int32 nTmpPos = nOldLen;
     871           0 :                 sal_Int16 nCheckMode = rCTLOptions.IsCTLSequenceCheckingRestricted() ?
     872           0 :                         i18n::InputSequenceCheckMode::STRICT : i18n::InputSequenceCheckMode::BASIC;
     873             : 
     874           0 :                 OUString aNewText( aOldText );
     875           0 :                 if (rCTLOptions.IsCTLSequenceCheckingTypeAndReplace())
     876             :                 {
     877           0 :                     for( sal_Int32 k = 0;  k < m_aInBuffer.getLength();  ++k)
     878             :                     {
     879           0 :                         const sal_Unicode cChar = m_aInBuffer[k];
     880           0 :                         const sal_Int32 nPrevPos =xISC->correctInputSequence( aNewText, nTmpPos - 1, cChar, nCheckMode );
     881             : 
     882             :                         // valid sequence or sequence could be corrected:
     883           0 :                         if (nPrevPos != aNewText.getLength())
     884           0 :                             nTmpPos = nPrevPos + 1;
     885             :                     }
     886             : 
     887             :                     // find position of first character that has changed
     888           0 :                     sal_Int32 nNewLen = aNewText.getLength();
     889           0 :                     const sal_Unicode *pOldText = aOldText.getStr();
     890           0 :                     const sal_Unicode *pNewText = aNewText.getStr();
     891           0 :                     sal_Int32 nChgPos = 0;
     892           0 :                     while ( nChgPos < nOldLen && nChgPos < nNewLen &&
     893           0 :                             pOldText[nChgPos] == pNewText[nChgPos] )
     894           0 :                         ++nChgPos;
     895             : 
     896           0 :                     const sal_Int32 nChgLen = nNewLen - nChgPos;
     897           0 :                     if (nChgLen)
     898             :                     {
     899           0 :                         m_aInBuffer = aNewText.copy( nChgPos, nChgLen );
     900           0 :                         nExpandSelection = nOldLen - nChgPos;
     901             :                     }
     902             :                     else
     903           0 :                         m_aInBuffer.clear();
     904             :                 }
     905             :                 else
     906             :                 {
     907           0 :                     for( sal_Int32 k = 0;  k < m_aInBuffer.getLength(); ++k )
     908             :                     {
     909           0 :                         const sal_Unicode cChar = m_aInBuffer[k];
     910           0 :                         if (xISC->checkInputSequence( aNewText, nTmpPos - 1, cChar, nCheckMode ))
     911             :                         {
     912             :                             // character can be inserted:
     913           0 :                             aNewText += OUString( (sal_Unicode) cChar );
     914           0 :                             ++nTmpPos;
     915             :                         }
     916             :                     }
     917           0 :                     m_aInBuffer = aNewText.copy( aOldText.getLength() );  // copy new text to be inserted to buffer
     918           0 :                 }
     919             :             }
     920             : 
     921             :             // at this point now we will insert the buffer text 'normally' some lines below...
     922             : 
     923           0 :             rSh.Pop( false );  // pop old cursor from stack
     924             : 
     925           0 :             if (m_aInBuffer.isEmpty())
     926           5 :                 return;
     927             : 
     928             :             // if text prior to the original selection needs to be changed
     929             :             // as well, we now expand the selection accordingly.
     930           0 :             SwPaM &rCrsr = *rSh.GetCrsr();
     931           0 :             const sal_Int32 nCrsrStartPos = rCrsr.Start()->nContent.GetIndex();
     932             :             OSL_ENSURE( nCrsrStartPos >= nExpandSelection, "cannot expand selection as specified!!" );
     933           0 :             if (nExpandSelection && nCrsrStartPos >= nExpandSelection)
     934             :             {
     935           0 :                 if (!rCrsr.HasMark())
     936           0 :                     rCrsr.SetMark();
     937           0 :                 rCrsr.Start()->nContent -= nExpandSelection;
     938           0 :             }
     939             :         }
     940             : 
     941             :         uno::Reference< frame::XDispatchRecorder > xRecorder =
     942           2 :                 m_rView.GetViewFrame()->GetBindings().GetRecorder();
     943           1 :         if ( xRecorder.is() )
     944             :         {
     945             :             // determine shell
     946           0 :             SfxShell *pSfxShell = lcl_GetShellFromDispatcher( m_rView, TYPE(SwTextShell) );
     947             :             // generate request and record
     948           0 :             if (pSfxShell)
     949             :             {
     950           0 :                 SfxRequest aReq( m_rView.GetViewFrame(), FN_INSERT_STRING );
     951           0 :                 aReq.AppendItem( SfxStringItem( FN_INSERT_STRING, m_aInBuffer ) );
     952           0 :                 aReq.Done();
     953             :             }
     954             :         }
     955             : 
     956           1 :         sal_uInt16 nWhich = lcl_isNonDefaultLanguage(m_eBufferLanguage, m_rView, m_aInBuffer);
     957           1 :         if (nWhich != INVALID_HINT )
     958             :         {
     959           0 :             SvxLanguageItem aLangItem( m_eBufferLanguage, nWhich );
     960           0 :             rSh.SetAttrItem( aLangItem );
     961             :         }
     962             : 
     963           1 :         rSh.Insert( m_aInBuffer );
     964           1 :         m_eBufferLanguage = LANGUAGE_DONTKNOW;
     965           1 :         m_aInBuffer.clear();
     966           2 :         g_bFlushCharBuffer = false;
     967             :     }
     968             : }
     969             : 
     970             : #define MOVE_LEFT_SMALL     0
     971             : #define MOVE_UP_SMALL       1
     972             : #define MOVE_RIGHT_BIG      2
     973             : #define MOVE_DOWN_BIG       3
     974             : #define MOVE_LEFT_BIG       4
     975             : #define MOVE_UP_BIG         5
     976             : #define MOVE_RIGHT_SMALL    6
     977             : #define MOVE_DOWN_SMALL     7
     978             : 
     979             : // #i121236# Support for shift key in writer
     980             : #define MOVE_LEFT_HUGE      8
     981             : #define MOVE_UP_HUGE        9
     982             : #define MOVE_RIGHT_HUGE     10
     983             : #define MOVE_DOWN_HUGE      11
     984             : 
     985           0 : void SwEditWin::ChangeFly( sal_uInt8 nDir, bool bWeb )
     986             : {
     987           0 :     SwWrtShell &rSh = m_rView.GetWrtShell();
     988           0 :     SwRect aTmp = rSh.GetFlyRect();
     989           0 :     if( aTmp.HasArea() &&
     990           0 :         rSh.IsSelObjProtected( FlyProtectFlags::Pos ) == FlyProtectFlags::NONE )
     991             :     {
     992           0 :         SfxItemSet aSet(rSh.GetAttrPool(),
     993             :                         RES_FRM_SIZE, RES_FRM_SIZE,
     994             :                         RES_VERT_ORIENT, RES_ANCHOR,
     995             :                         RES_COL, RES_COL,
     996             :                         RES_PROTECT, RES_PROTECT,
     997           0 :                         RES_FOLLOW_TEXT_FLOW, RES_FOLLOW_TEXT_FLOW, 0);
     998           0 :         rSh.GetFlyFrmAttr( aSet );
     999           0 :         RndStdIds eAnchorId = static_cast<const SwFormatAnchor&>(aSet.Get(RES_ANCHOR)).GetAnchorId();
    1000           0 :         Size aSnap;
    1001           0 :         bool bHuge(MOVE_LEFT_HUGE == nDir ||
    1002           0 :             MOVE_UP_HUGE == nDir ||
    1003           0 :             MOVE_RIGHT_HUGE == nDir ||
    1004           0 :             MOVE_DOWN_HUGE == nDir);
    1005             : 
    1006           0 :         if(MOVE_LEFT_SMALL == nDir ||
    1007           0 :             MOVE_UP_SMALL == nDir ||
    1008           0 :             MOVE_RIGHT_SMALL == nDir ||
    1009             :             MOVE_DOWN_SMALL == nDir )
    1010             :         {
    1011           0 :             aSnap = PixelToLogic(Size(1,1));
    1012             :         }
    1013             :         else
    1014             :         {
    1015           0 :             aSnap = rSh.GetViewOptions()->GetSnapSize();
    1016           0 :             short nDiv = rSh.GetViewOptions()->GetDivisionX();
    1017           0 :             if ( nDiv > 0 )
    1018           0 :                 aSnap.Width() = std::max( (sal_uLong)1, (sal_uLong)aSnap.Width() / nDiv );
    1019           0 :             nDiv = rSh.GetViewOptions()->GetDivisionY();
    1020           0 :             if ( nDiv > 0 )
    1021           0 :                 aSnap.Height() = std::max( (sal_uLong)1, (sal_uLong)aSnap.Height() / nDiv );
    1022             :         }
    1023             : 
    1024           0 :         if(bHuge)
    1025             :         {
    1026             :             // #i121236# 567twips == 1cm, but just take three times the normal snap
    1027           0 :             aSnap = Size(aSnap.Width() * 3, aSnap.Height() * 3);
    1028             :         }
    1029             : 
    1030           0 :         SwRect aBoundRect;
    1031           0 :         Point aRefPoint;
    1032             :         // adjustment for allowing vertical position
    1033             :         // aligned to page for fly frame anchored to paragraph or to character.
    1034             :         {
    1035           0 :             SwFormatVertOrient aVert( static_cast<const SwFormatVertOrient&>(aSet.Get(RES_VERT_ORIENT)) );
    1036             :             const bool bFollowTextFlow =
    1037           0 :                     static_cast<const SwFormatFollowTextFlow&>(aSet.Get(RES_FOLLOW_TEXT_FLOW)).GetValue();
    1038           0 :             const SwPosition* pToCharContentPos = static_cast<const SwFormatAnchor&>(aSet.Get(RES_ANCHOR)).GetContentAnchor();
    1039             :             rSh.CalcBoundRect( aBoundRect, eAnchorId,
    1040           0 :                                text::RelOrientation::FRAME, aVert.GetRelationOrient(),
    1041             :                                pToCharContentPos, bFollowTextFlow,
    1042           0 :                                false, &aRefPoint );
    1043             :         }
    1044           0 :         long nLeft = std::min( aTmp.Left() - aBoundRect.Left(), aSnap.Width() );
    1045           0 :         long nRight = std::min( aBoundRect.Right() - aTmp.Right(), aSnap.Width() );
    1046           0 :         long nUp = std::min( aTmp.Top() - aBoundRect.Top(), aSnap.Height() );
    1047           0 :         long nDown = std::min( aBoundRect.Bottom() - aTmp.Bottom(), aSnap.Height() );
    1048             : 
    1049           0 :         switch ( nDir )
    1050             :         {
    1051             :             case MOVE_LEFT_BIG:
    1052             :             case MOVE_LEFT_HUGE:
    1053           0 :             case MOVE_LEFT_SMALL: aTmp.Left( aTmp.Left() - nLeft );
    1054           0 :                 break;
    1055             : 
    1056             :             case MOVE_UP_BIG:
    1057             :             case MOVE_UP_HUGE:
    1058           0 :             case MOVE_UP_SMALL: aTmp.Top( aTmp.Top() - nUp );
    1059           0 :                 break;
    1060             : 
    1061             :             case MOVE_RIGHT_SMALL:
    1062           0 :                 if( aTmp.Width() < aSnap.Width() + MINFLY )
    1063           0 :                     break;
    1064           0 :                 nRight = aSnap.Width(); // no break
    1065             :             case MOVE_RIGHT_HUGE:
    1066           0 :             case MOVE_RIGHT_BIG: aTmp.Left( aTmp.Left() + nRight );
    1067           0 :                 break;
    1068             : 
    1069             :             case MOVE_DOWN_SMALL:
    1070           0 :                 if( aTmp.Height() < aSnap.Height() + MINFLY )
    1071           0 :                     break;
    1072           0 :                 nDown = aSnap.Height(); // no break
    1073             :             case MOVE_DOWN_HUGE:
    1074           0 :             case MOVE_DOWN_BIG: aTmp.Top( aTmp.Top() + nDown );
    1075           0 :                 break;
    1076             : 
    1077             :             default: OSL_ENSURE(true, "ChangeFly: Unknown direction." );
    1078             :         }
    1079           0 :         bool bSet = false;
    1080           0 :         if ((FLY_AS_CHAR == eAnchorId) && ( nDir % 2 ))
    1081             :         {
    1082           0 :             long aDiff = aTmp.Top() - aRefPoint.Y();
    1083           0 :             if( aDiff > 0 )
    1084           0 :                 aDiff = 0;
    1085           0 :             else if ( aDiff < -aTmp.Height() )
    1086           0 :                 aDiff = -aTmp.Height();
    1087           0 :             SwFormatVertOrient aVert( static_cast<const SwFormatVertOrient&>(aSet.Get(RES_VERT_ORIENT)) );
    1088             :             sal_Int16 eNew;
    1089           0 :             if( bWeb )
    1090             :             {
    1091           0 :                 eNew = aVert.GetVertOrient();
    1092           0 :                 bool bDown = 0 != ( nDir & 0x02 );
    1093           0 :                 switch( eNew )
    1094             :                 {
    1095             :                     case text::VertOrientation::CHAR_TOP:
    1096           0 :                         if( bDown ) eNew = text::VertOrientation::CENTER;
    1097           0 :                     break;
    1098             :                     case text::VertOrientation::CENTER:
    1099           0 :                         eNew = bDown ? text::VertOrientation::TOP : text::VertOrientation::CHAR_TOP;
    1100           0 :                     break;
    1101             :                     case text::VertOrientation::TOP:
    1102           0 :                         if( !bDown ) eNew = text::VertOrientation::CENTER;
    1103           0 :                     break;
    1104             :                     case text::VertOrientation::LINE_TOP:
    1105           0 :                         if( bDown ) eNew = text::VertOrientation::LINE_CENTER;
    1106           0 :                     break;
    1107             :                     case text::VertOrientation::LINE_CENTER:
    1108           0 :                         eNew = bDown ? text::VertOrientation::LINE_BOTTOM : text::VertOrientation::LINE_TOP;
    1109           0 :                     break;
    1110             :                     case text::VertOrientation::LINE_BOTTOM:
    1111           0 :                         if( !bDown ) eNew = text::VertOrientation::LINE_CENTER;
    1112           0 :                     break;
    1113             :                     default:; //prevent warning
    1114             :                 }
    1115             :             }
    1116             :             else
    1117             :             {
    1118           0 :                 aVert.SetPos( aDiff );
    1119           0 :                 eNew = text::VertOrientation::NONE;
    1120             :             }
    1121           0 :             aVert.SetVertOrient( eNew );
    1122           0 :             aSet.Put( aVert );
    1123           0 :             bSet = true;
    1124             :         }
    1125           0 :         if (bWeb && (FLY_AT_PARA == eAnchorId)
    1126           0 :             && ( nDir==MOVE_LEFT_SMALL || nDir==MOVE_RIGHT_BIG ))
    1127             :         {
    1128           0 :             SwFormatHoriOrient aHori( static_cast<const SwFormatHoriOrient&>(aSet.Get(RES_HORI_ORIENT)) );
    1129             :             sal_Int16 eNew;
    1130           0 :             eNew = aHori.GetHoriOrient();
    1131           0 :             switch( eNew )
    1132             :             {
    1133             :                 case text::HoriOrientation::RIGHT:
    1134           0 :                     if( nDir==MOVE_LEFT_SMALL )
    1135           0 :                         eNew = text::HoriOrientation::LEFT;
    1136           0 :                 break;
    1137             :                 case text::HoriOrientation::LEFT:
    1138           0 :                     if( nDir==MOVE_RIGHT_BIG )
    1139           0 :                         eNew = text::HoriOrientation::RIGHT;
    1140           0 :                 break;
    1141             :                 default:; //prevent warning
    1142             :             }
    1143           0 :             if( eNew != aHori.GetHoriOrient() )
    1144             :             {
    1145           0 :                 aHori.SetHoriOrient( eNew );
    1146           0 :                 aSet.Put( aHori );
    1147           0 :                 bSet = true;
    1148           0 :             }
    1149             :         }
    1150           0 :         rSh.StartAllAction();
    1151           0 :         if( bSet )
    1152           0 :             rSh.SetFlyFrmAttr( aSet );
    1153           0 :         bool bSetPos = (FLY_AS_CHAR != eAnchorId);
    1154           0 :         if(bSetPos && bWeb)
    1155             :         {
    1156           0 :             if (FLY_AT_PAGE != eAnchorId)
    1157             :             {
    1158           0 :                 bSetPos = false;
    1159             :             }
    1160             :             else
    1161             :             {
    1162           0 :                 bSetPos = true;
    1163             :             }
    1164             :         }
    1165           0 :         if( bSetPos )
    1166           0 :             rSh.SetFlyPos( aTmp.Pos() );
    1167           0 :         rSh.EndAllAction();
    1168             :     }
    1169           0 : }
    1170             : 
    1171           0 : void SwEditWin::ChangeDrawing( sal_uInt8 nDir )
    1172             : {
    1173             :     // start undo action in order to get only one
    1174             :     // undo action for this change.
    1175           0 :     SwWrtShell &rSh = m_rView.GetWrtShell();
    1176           0 :     rSh.StartUndo();
    1177             : 
    1178           0 :     long nX = 0;
    1179           0 :     long nY = 0;
    1180             :     const bool bOnePixel(
    1181           0 :         MOVE_LEFT_SMALL == nDir ||
    1182           0 :         MOVE_UP_SMALL == nDir ||
    1183           0 :         MOVE_RIGHT_SMALL == nDir ||
    1184           0 :         MOVE_DOWN_SMALL == nDir);
    1185             :     const bool bHuge(
    1186           0 :         MOVE_LEFT_HUGE == nDir ||
    1187           0 :         MOVE_UP_HUGE == nDir ||
    1188           0 :         MOVE_RIGHT_HUGE == nDir ||
    1189           0 :         MOVE_DOWN_HUGE == nDir);
    1190           0 :     SwMove nAnchorDir = SwMove::UP;
    1191           0 :     switch(nDir)
    1192             :     {
    1193             :         case MOVE_LEFT_SMALL:
    1194             :         case MOVE_LEFT_HUGE:
    1195             :         case MOVE_LEFT_BIG:
    1196           0 :             nX = -1;
    1197           0 :             nAnchorDir = SwMove::LEFT;
    1198           0 :         break;
    1199             :         case MOVE_UP_SMALL:
    1200             :         case MOVE_UP_HUGE:
    1201             :         case MOVE_UP_BIG:
    1202           0 :             nY = -1;
    1203           0 :         break;
    1204             :         case MOVE_RIGHT_SMALL:
    1205             :         case MOVE_RIGHT_HUGE:
    1206             :         case MOVE_RIGHT_BIG:
    1207           0 :             nX = +1;
    1208           0 :             nAnchorDir = SwMove::RIGHT;
    1209           0 :         break;
    1210             :         case MOVE_DOWN_SMALL:
    1211             :         case MOVE_DOWN_HUGE:
    1212             :         case MOVE_DOWN_BIG:
    1213           0 :             nY = +1;
    1214           0 :             nAnchorDir = SwMove::DOWN;
    1215           0 :         break;
    1216             :     }
    1217             : 
    1218           0 :     if(0 != nX || 0 != nY)
    1219             :     {
    1220           0 :         FlyProtectFlags nProtect = rSh.IsSelObjProtected( FlyProtectFlags::Pos|FlyProtectFlags::Size );
    1221           0 :         Size aSnap( rSh.GetViewOptions()->GetSnapSize() );
    1222           0 :         short nDiv = rSh.GetViewOptions()->GetDivisionX();
    1223           0 :         if ( nDiv > 0 )
    1224           0 :             aSnap.Width() = std::max( (sal_uLong)1, (sal_uLong)aSnap.Width() / nDiv );
    1225           0 :         nDiv = rSh.GetViewOptions()->GetDivisionY();
    1226           0 :         if ( nDiv > 0 )
    1227           0 :             aSnap.Height() = std::max( (sal_uLong)1, (sal_uLong)aSnap.Height() / nDiv );
    1228             : 
    1229           0 :         if(bOnePixel)
    1230             :         {
    1231           0 :             aSnap = PixelToLogic(Size(1,1));
    1232             :         }
    1233           0 :         else if(bHuge)
    1234             :         {
    1235             :             // #i121236# 567twips == 1cm, but just take three times the normal snap
    1236           0 :             aSnap = Size(aSnap.Width() * 3, aSnap.Height() * 3);
    1237             :         }
    1238             : 
    1239           0 :         nX *= aSnap.Width();
    1240           0 :         nY *= aSnap.Height();
    1241             : 
    1242           0 :         SdrView *pSdrView = rSh.GetDrawView();
    1243           0 :         const SdrHdlList& rHdlList = pSdrView->GetHdlList();
    1244           0 :         SdrHdl* pHdl = rHdlList.GetFocusHdl();
    1245           0 :         rSh.StartAllAction();
    1246           0 :         if(0L == pHdl)
    1247             :         {
    1248             :             // now move the selected draw objects
    1249             :             // if the object's position is not protected
    1250           0 :             if(!(nProtect&FlyProtectFlags::Pos))
    1251             :             {
    1252             :                 // Check if object is anchored as character and move direction
    1253             :                 bool bDummy1, bDummy2;
    1254           0 :                 const bool bVertAnchor = rSh.IsFrmVertical( true, bDummy1, bDummy2 );
    1255           0 :                 bool bHoriMove = !bVertAnchor == !( nDir % 2 );
    1256             :                 bool bMoveAllowed =
    1257           0 :                     !bHoriMove || (rSh.GetAnchorId() != FLY_AS_CHAR);
    1258           0 :                 if ( bMoveAllowed )
    1259             :                 {
    1260           0 :                     pSdrView->MoveAllMarked(Size(nX, nY));
    1261           0 :                     rSh.SetModified();
    1262             :                 }
    1263             :             }
    1264             :         }
    1265             :         else
    1266             :         {
    1267             :             // move handle with index nHandleIndex
    1268           0 :             if(pHdl && (nX || nY))
    1269             :             {
    1270           0 :                 if( HDL_ANCHOR == pHdl->GetKind() ||
    1271           0 :                     HDL_ANCHOR_TR == pHdl->GetKind() )
    1272             :                 {
    1273             :                     // anchor move cannot be allowed when position is protected
    1274           0 :                     if(!(nProtect&FlyProtectFlags::Pos))
    1275           0 :                         rSh.MoveAnchor( nAnchorDir );
    1276             :                 }
    1277             :                 //now resize if size is protected
    1278           0 :                 else if(!(nProtect&FlyProtectFlags::Size))
    1279             :                 {
    1280             :                     // now move the Handle (nX, nY)
    1281           0 :                     Point aStartPoint(pHdl->GetPos());
    1282           0 :                     Point aEndPoint(pHdl->GetPos() + Point(nX, nY));
    1283           0 :                     const SdrDragStat& rDragStat = pSdrView->GetDragStat();
    1284             : 
    1285             :                     // start dragging
    1286           0 :                     pSdrView->BegDragObj(aStartPoint, 0, pHdl, 0);
    1287             : 
    1288           0 :                     if(pSdrView->IsDragObj())
    1289             :                     {
    1290           0 :                         bool bWasNoSnap = rDragStat.IsNoSnap();
    1291           0 :                         bool bWasSnapEnabled = pSdrView->IsSnapEnabled();
    1292             : 
    1293             :                         // switch snapping off
    1294           0 :                         if(!bWasNoSnap)
    1295           0 :                             const_cast<SdrDragStat&>(rDragStat).SetNoSnap(true);
    1296           0 :                         if(bWasSnapEnabled)
    1297           0 :                             pSdrView->SetSnapEnabled(false);
    1298             : 
    1299           0 :                         pSdrView->MovAction(aEndPoint);
    1300           0 :                         pSdrView->EndDragObj();
    1301           0 :                         rSh.SetModified();
    1302             : 
    1303             :                         // restore snap
    1304           0 :                         if(!bWasNoSnap)
    1305           0 :                             const_cast<SdrDragStat&>(rDragStat).SetNoSnap(bWasNoSnap);
    1306           0 :                         if(bWasSnapEnabled)
    1307           0 :                             pSdrView->SetSnapEnabled(bWasSnapEnabled);
    1308             :                     }
    1309             :                 }
    1310             :             }
    1311             :         }
    1312           0 :         rSh.EndAllAction();
    1313             :     }
    1314             : 
    1315           0 :     rSh.EndUndo();
    1316           0 : }
    1317             : 
    1318             : /**
    1319             :  * KeyEvents
    1320             :  */
    1321           1 : void SwEditWin::KeyInput(const KeyEvent &rKEvt)
    1322             : {
    1323           1 :     SwWrtShell &rSh = m_rView.GetWrtShell();
    1324             : 
    1325           2 :     if( rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE &&
    1326           1 :         m_pApplyTempl && m_pApplyTempl->m_pFormatClipboard )
    1327             :     {
    1328           0 :         m_pApplyTempl->m_pFormatClipboard->Erase();
    1329           0 :         SetApplyTemplate(SwApplyTemplate());
    1330           0 :         m_rView.GetViewFrame()->GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
    1331             :     }
    1332           1 :     else if ( rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE &&
    1333           0 :             rSh.IsHeaderFooterEdit( ) )
    1334             :     {
    1335           0 :         bool bHeader = bool(FrmTypeFlags::HEADER & rSh.GetFrmType(0,false));
    1336           0 :         if ( bHeader )
    1337           0 :             rSh.SttPg();
    1338             :         else
    1339           0 :             rSh.EndPg();
    1340           0 :         rSh.ToggleHeaderFooterEdit();
    1341             :     }
    1342             : 
    1343           1 :     SfxObjectShell *pObjSh = m_rView.GetViewFrame()->GetObjectShell();
    1344           1 :     if ( m_bLockInput || (pObjSh && pObjSh->GetProgress()) )
    1345             :         // When the progress bar is active or a progress is
    1346             :         // running on a document, no order is being taken
    1347           0 :         return;
    1348             : 
    1349           1 :     delete m_pShadCrsr, m_pShadCrsr = 0;
    1350           1 :     m_aKeyInputFlushTimer.Stop();
    1351             : 
    1352           1 :     bool bIsDocReadOnly = m_rView.GetDocShell()->IsReadOnly() &&
    1353           1 :                           rSh.IsCrsrReadonly();
    1354             : 
    1355             :     //if the language changes the buffer must be flushed
    1356           1 :     LanguageType eNewLanguage = GetInputLanguage();
    1357           1 :     if(!bIsDocReadOnly && m_eBufferLanguage != eNewLanguage && !m_aInBuffer.isEmpty())
    1358             :     {
    1359           0 :         FlushInBuffer();
    1360             :     }
    1361           1 :     m_eBufferLanguage = eNewLanguage;
    1362             : 
    1363           1 :     QuickHelpData aTmpQHD;
    1364           1 :     if( m_pQuickHlpData->m_bIsDisplayed )
    1365             :     {
    1366           0 :         aTmpQHD.Move( *m_pQuickHlpData );
    1367           0 :         m_pQuickHlpData->Stop( rSh );
    1368             :     }
    1369             : 
    1370             :     // OS:the DrawView also needs a readonly-Flag as well
    1371           1 :     if ( !bIsDocReadOnly && rSh.GetDrawView() && rSh.GetDrawView()->KeyInput( rKEvt, this ) )
    1372             :     {
    1373           0 :         rSh.GetView().GetViewFrame()->GetBindings().InvalidateAll( false );
    1374           0 :         rSh.SetModified();
    1375           0 :         return; // Event evaluated by SdrView
    1376             :     }
    1377             : 
    1378           1 :     if ( m_rView.GetDrawFuncPtr() && m_bInsFrm )
    1379             :     {
    1380           0 :         StopInsFrm();
    1381           0 :         rSh.Edit();
    1382             :     }
    1383             : 
    1384           1 :     bool bFlushBuffer = false;
    1385           1 :     bool bNormalChar = false;
    1386           1 :     bool bAppendSpace = m_pQuickHlpData->m_bAppendSpace;
    1387           1 :     m_pQuickHlpData->m_bAppendSpace = false;
    1388             : 
    1389           1 :     if ( getenv("SW_DEBUG") && rKEvt.GetKeyCode().GetCode() == KEY_F12 )
    1390             :     {
    1391           0 :         if( rKEvt.GetKeyCode().IsShift())
    1392             :         {
    1393           0 :             GetView().GetDocShell()->GetDoc()->dumpAsXml();
    1394           0 :             return;
    1395             :         }
    1396             :         else
    1397             :         {
    1398           0 :             SwRootFrm* pLayout = GetView().GetDocShell()->GetWrtShell()->GetLayout();
    1399           0 :             pLayout->dumpAsXml( );
    1400           0 :             return;
    1401             :         }
    1402             :     }
    1403             : 
    1404           1 :     KeyEvent aKeyEvent( rKEvt );
    1405             :     // look for vertical mappings
    1406           1 :     if( !bIsDocReadOnly && !rSh.IsSelFrmMode() && !rSh.IsObjSelected() )
    1407             :     {
    1408             :         // must changed from switch to if, because the Linux
    1409             :         // compiler has problem with the code. Has to remove if the new general
    1410             :         // handler exist.
    1411           1 :         sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
    1412             : 
    1413           1 :         if( KEY_UP == nKey || KEY_DOWN == nKey ||
    1414           1 :             KEY_LEFT == nKey || KEY_RIGHT == nKey )
    1415             :         {
    1416             :             // In general, we want to map the direction keys if we are inside
    1417             :             // some vertical formatted text.
    1418             :             // 1. Exception: For a table cursor in a horizontal table, the
    1419             :             //               directions should never be mapped.
    1420             :             // 2. Exception: For a table cursor in a vertical table, the
    1421             :             //               directions should always be mapped.
    1422           0 :             const bool bVertText = rSh.IsInVerticalText();
    1423           0 :             const bool bTableCrsr = rSh.GetTableCrsr();
    1424           0 :             const bool bVertTable = rSh.IsTableVertical();
    1425           0 :             if( ( bVertText && ( !bTableCrsr || bVertTable ) ) ||
    1426           0 :                 ( bTableCrsr && bVertTable ) )
    1427             :             {
    1428             :                 // Attempt to integrate cursor travelling for mongolian layout does not work.
    1429             :                 // Thus, back to previous mapping of cursor keys to direction keys.
    1430           0 :                 if( KEY_UP == nKey ) nKey = KEY_LEFT;
    1431           0 :                 else if( KEY_DOWN == nKey ) nKey = KEY_RIGHT;
    1432           0 :                 else if( KEY_LEFT == nKey ) nKey = KEY_DOWN;
    1433           0 :                 else if( KEY_RIGHT == nKey ) nKey = KEY_UP;
    1434             :             }
    1435             : 
    1436           0 :             if ( rSh.IsInRightToLeftText() )
    1437             :             {
    1438           0 :                 if( KEY_LEFT == nKey ) nKey = KEY_RIGHT;
    1439           0 :                 else if( KEY_RIGHT == nKey ) nKey = KEY_LEFT;
    1440             :             }
    1441             : 
    1442           0 :             aKeyEvent = KeyEvent( rKEvt.GetCharCode(),
    1443           0 :                                   vcl::KeyCode( nKey, rKEvt.GetKeyCode().GetModifier() ),
    1444           0 :                                   rKEvt.GetRepeat() );
    1445             :         }
    1446             :     }
    1447             : 
    1448           1 :     const vcl::KeyCode& rKeyCode = aKeyEvent.GetKeyCode();
    1449           1 :     sal_Unicode aCh = aKeyEvent.GetCharCode();
    1450             : 
    1451             :     // enable switching to notes ankor with Ctrl - Alt - Page Up/Down
    1452             :     // pressing this inside a note will switch to next/previous note
    1453           1 :     if ((rKeyCode.IsMod1() && rKeyCode.IsMod2()) && ((rKeyCode.GetCode() == KEY_PAGEUP) || (rKeyCode.GetCode() == KEY_PAGEDOWN)))
    1454             :     {
    1455           0 :         const bool bNext = rKeyCode.GetCode()==KEY_PAGEDOWN;
    1456           0 :         const SwFieldType* pFieldType = rSh.GetFieldType( 0, RES_POSTITFLD );
    1457           0 :         rSh.MoveFieldType( pFieldType, bNext );
    1458           0 :         return;
    1459             :     }
    1460             : 
    1461           1 :     const SwFrameFormat* pFlyFormat = rSh.GetFlyFrameFormat();
    1462           1 :     if( pFlyFormat )
    1463             :     {
    1464             :         sal_uInt16 nEvent;
    1465             : 
    1466           0 :         if( 32 <= aCh &&
    1467           0 :             0 == (( KEY_MOD1 | KEY_MOD2 ) & rKeyCode.GetModifier() ))
    1468           0 :             nEvent = SW_EVENT_FRM_KEYINPUT_ALPHA;
    1469             :         else
    1470           0 :             nEvent = SW_EVENT_FRM_KEYINPUT_NOALPHA;
    1471             : 
    1472           0 :         const SvxMacro* pMacro = pFlyFormat->GetMacro().GetMacroTable().Get( nEvent );
    1473           0 :         if( pMacro )
    1474             :         {
    1475           0 :             SbxArrayRef xArgs = new SbxArray;
    1476           0 :             SbxVariableRef xVar = new SbxVariable;
    1477           0 :             xVar->PutString( pFlyFormat->GetName() );
    1478           0 :             xArgs->Put( &xVar, 1 );
    1479             : 
    1480           0 :             xVar = new SbxVariable;
    1481           0 :             if( SW_EVENT_FRM_KEYINPUT_ALPHA == nEvent )
    1482           0 :                 xVar->PutChar( aCh );
    1483             :             else
    1484           0 :                 xVar->PutUShort( rKeyCode.GetModifier() | rKeyCode.GetCode() );
    1485           0 :             xArgs->Put( &xVar, 2 );
    1486             : 
    1487           0 :             OUString sRet;
    1488           0 :             rSh.ExecMacro( *pMacro, &sRet, &xArgs );
    1489           0 :             if( !sRet.isEmpty() && sRet.toInt32()!=0 )
    1490           0 :                 return ;
    1491             :         }
    1492             :     }
    1493             :     int nLclSelectionType;
    1494             :     //A is converted to 1
    1495           2 :     if( rKeyCode.GetFullCode() == (KEY_A | KEY_MOD1 |KEY_SHIFT)
    1496           1 :         && rSh.HasDrawView() &&
    1497           0 :         (0 != (nLclSelectionType = rSh.GetSelectionType()) &&
    1498           0 :         ((nLclSelectionType & (nsSelectionType::SEL_FRM|nsSelectionType::SEL_GRF)) ||
    1499           0 :         ((nLclSelectionType & (nsSelectionType::SEL_DRW|nsSelectionType::SEL_DRW_FORM)) &&
    1500           0 :                 rSh.GetDrawView()->GetMarkedObjectList().GetMarkCount() == 1))))
    1501             :     {
    1502           0 :         SdrHdlList& rHdlList = (SdrHdlList&)rSh.GetDrawView()->GetHdlList();
    1503           0 :         SdrHdl* pAnchor = rHdlList.GetHdl(HDL_ANCHOR);
    1504           0 :         if ( ! pAnchor )
    1505           0 :             pAnchor = rHdlList.GetHdl(HDL_ANCHOR_TR);
    1506           0 :         if(pAnchor)
    1507           0 :             rHdlList.SetFocusHdl(pAnchor);
    1508           0 :         return;
    1509             :     }
    1510             : 
    1511           1 :     SvxAutoCorrCfg* pACfg = 0;
    1512           1 :     SvxAutoCorrect* pACorr = 0;
    1513             : 
    1514             :     uno::Reference< frame::XDispatchRecorder > xRecorder =
    1515           2 :             m_rView.GetViewFrame()->GetBindings().GetRecorder();
    1516           1 :     if ( !xRecorder.is() )
    1517             :     {
    1518           1 :         pACfg = &SvxAutoCorrCfg::Get();
    1519           1 :         pACorr = pACfg->GetAutoCorrect();
    1520             :     }
    1521             : 
    1522           1 :     SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
    1523             : 
    1524           1 :     TableChgWidthHeightType eTableChgMode = nsTableChgWidthHeightType::WH_COL_LEFT;    // initialization just for warning-free code
    1525           1 :     sal_uInt16 nTableChgSize = 0;
    1526           1 :     bool bStopKeyInputTimer = true;
    1527           2 :     OUString sFormulaEntry;
    1528             : 
    1529             :     enum SW_KeyState { KS_Start,
    1530             :                        KS_CheckKey, KS_InsChar, KS_InsTab,
    1531             :                        KS_NoNum, KS_NumOff, KS_NumOrNoNum, KS_NumDown, KS_NumUp,
    1532             :                        KS_NumIndentInc, KS_NumIndentDec,
    1533             : 
    1534             :                        KS_OutlineLvOff,
    1535             :                        KS_NextCell, KS_PrevCell, KS_OutlineUp, KS_OutlineDown,
    1536             :                        KS_GlossaryExpand, KS_NextPrevGlossary,
    1537             :                        KS_AutoFormatByInput,
    1538             :                        KS_NextObject, KS_PrevObject,
    1539             :                        KS_KeyToView,
    1540             :                        KS_LaunchOLEObject, KS_GoIntoFly, KS_GoIntoDrawing,
    1541             :                        KS_EnterDrawHandleMode,
    1542             :                        KS_CheckDocReadOnlyKeys,
    1543             :                        KS_CheckAutoCorrect, KS_EditFormula,
    1544             :                        KS_ColLeftBig, KS_ColRightBig,
    1545             :                        KS_ColLeftSmall, KS_ColRightSmall,
    1546             :                        KS_ColTopBig, KS_ColBottomBig,
    1547             :                        KS_ColTopSmall, KS_ColBottomSmall,
    1548             :                        KS_CellLeftBig, KS_CellRightBig,
    1549             :                        KS_CellLeftSmall, KS_CellRightSmall,
    1550             :                        KS_CellTopBig, KS_CellBottomBig,
    1551             :                        KS_CellTopSmall, KS_CellBottomSmall,
    1552             : 
    1553             :                        KS_InsDel_ColLeftBig, KS_InsDel_ColRightBig,
    1554             :                        KS_InsDel_ColLeftSmall, KS_InsDel_ColRightSmall,
    1555             :                        KS_InsDel_ColTopBig, KS_InsDel_ColBottomBig,
    1556             :                        KS_InsDel_ColTopSmall, KS_InsDel_ColBottomSmall,
    1557             :                        KS_InsDel_CellLeftBig, KS_InsDel_CellRightBig,
    1558             :                        KS_InsDel_CellLeftSmall, KS_InsDel_CellRightSmall,
    1559             :                        KS_InsDel_CellTopBig, KS_InsDel_CellBottomBig,
    1560             :                        KS_InsDel_CellTopSmall, KS_InsDel_CellBottomSmall,
    1561             :                        KS_TableColCellInsDel,
    1562             : 
    1563             :                        KS_Fly_Change, KS_Draw_Change,
    1564             :                        KS_SpecialInsert,
    1565             :                        KS_EnterCharCell,
    1566             :                        KS_GotoNextFieldMark,
    1567             :                        KS_GotoPrevFieldMark,
    1568             :                        KS_End };
    1569             : 
    1570           1 :     SW_KeyState eKeyState = bIsDocReadOnly ? KS_CheckDocReadOnlyKeys : KS_CheckKey;
    1571           1 :     SW_KeyState eNextKeyState = KS_End;
    1572           1 :     sal_uInt8 nDir = 0;
    1573             : 
    1574           1 :     if (m_nKS_NUMDOWN_Count > 0)
    1575           0 :         m_nKS_NUMDOWN_Count--;
    1576             : 
    1577           1 :     if (m_nKS_NUMINDENTINC_Count > 0)
    1578           0 :         m_nKS_NUMINDENTINC_Count--;
    1579             : 
    1580           5 :     while( KS_End != eKeyState )
    1581             :     {
    1582           3 :         SW_KeyState eFlyState = KS_KeyToView;
    1583             : 
    1584           3 :         switch( eKeyState )
    1585             :         {
    1586             :         case KS_CheckKey:
    1587           1 :             eKeyState = KS_KeyToView;       // default forward to View
    1588             : 
    1589             : #if OSL_DEBUG_LEVEL > 1
    1590             : //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    1591             :             // for switching cursor behaviour in ReadOnly regions
    1592             :             if( 0x7210 == rKeyCode.GetFullCode() )
    1593             :                 rSh.SetReadOnlyAvailable( !rSh.IsReadOnlyAvailable() );
    1594             :             else
    1595             : //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    1596             : #endif
    1597             : 
    1598           3 :             if( !rKeyCode.IsMod2() && '=' == aCh &&
    1599           0 :                 !rSh.IsTableMode() && rSh.GetTableFormat() &&
    1600           1 :                 rSh.IsSttPara() &&
    1601           0 :                 !rSh.HasReadonlySel() )
    1602             :             {
    1603             :                 // at the beginning of the table's cell a '=' ->
    1604             :                 // call EditRow (F2-functionality)
    1605           0 :                 rSh.Push();
    1606           0 :                 if( !rSh.MoveSection( fnSectionCurr, fnSectionStart) &&
    1607           0 :                     !rSh.IsTableBoxTextFormat() )
    1608             :                 {
    1609             :                     // is at the beginning of the box
    1610           0 :                     eKeyState = KS_EditFormula;
    1611           0 :                     if( rSh.HasMark() )
    1612           0 :                         rSh.SwapPam();
    1613             :                     else
    1614           0 :                         rSh.SttSelect();
    1615           0 :                     rSh.MoveSection( fnSectionCurr, fnSectionEnd );
    1616           0 :                     rSh.Pop( true );
    1617           0 :                     rSh.EndSelect();
    1618           0 :                     sFormulaEntry = "=";
    1619             :                 }
    1620             :                 else
    1621           0 :                     rSh.Pop( false );
    1622             :             }
    1623             :             else
    1624             :             {
    1625           2 :                 if( pACorr && aTmpQHD.HasContent() && !rSh.HasSelection() &&
    1626           1 :                     !rSh.HasReadonlySel() && !aTmpQHD.m_bIsAutoText &&
    1627           0 :                     pACorr->GetSwFlags().nAutoCmpltExpandKey ==
    1628           0 :                     (rKeyCode.GetModifier() | rKeyCode.GetCode()) )
    1629             :                 {
    1630           0 :                     eKeyState = KS_GlossaryExpand;
    1631           0 :                     break;
    1632             :                 }
    1633             : 
    1634           1 :                 switch( rKeyCode.GetModifier() | rKeyCode.GetCode() )
    1635             :                 {
    1636             :                 case KEY_RIGHT | KEY_MOD2:
    1637           0 :                     eKeyState = KS_ColRightBig;
    1638           0 :                     eFlyState = KS_Fly_Change;
    1639           0 :                     nDir = MOVE_RIGHT_SMALL;
    1640           0 :                     goto KEYINPUT_CHECKTABLE;
    1641             : 
    1642             :                 case KEY_LEFT | KEY_MOD2:
    1643           0 :                     eKeyState = KS_ColRightSmall;
    1644           0 :                     eFlyState = KS_Fly_Change;
    1645           0 :                     nDir = MOVE_LEFT_SMALL;
    1646           0 :                     goto KEYINPUT_CHECKTABLE;
    1647             : 
    1648             :                 case KEY_RIGHT | KEY_MOD2 | KEY_SHIFT:
    1649           0 :                     eKeyState = KS_ColLeftSmall;
    1650           0 :                     goto KEYINPUT_CHECKTABLE;
    1651             : 
    1652             :                 case KEY_LEFT | KEY_MOD2 | KEY_SHIFT:
    1653           0 :                     eKeyState = KS_ColLeftBig;
    1654           0 :                     goto KEYINPUT_CHECKTABLE;
    1655             : 
    1656             :                 case KEY_RIGHT | KEY_MOD2 | KEY_MOD1:
    1657           0 :                     eKeyState = KS_CellRightBig;
    1658           0 :                     goto KEYINPUT_CHECKTABLE;
    1659             : 
    1660             :                 case KEY_LEFT | KEY_MOD2 | KEY_MOD1:
    1661           0 :                     eKeyState = KS_CellRightSmall;
    1662           0 :                     goto KEYINPUT_CHECKTABLE;
    1663             : 
    1664             :                 case KEY_RIGHT | KEY_MOD2 | KEY_SHIFT | KEY_MOD1:
    1665           0 :                     eKeyState = KS_CellLeftSmall;
    1666           0 :                     goto KEYINPUT_CHECKTABLE;
    1667             : 
    1668             :                 case KEY_LEFT | KEY_MOD2 | KEY_SHIFT | KEY_MOD1:
    1669           0 :                     eKeyState = KS_CellLeftBig;
    1670           0 :                     goto KEYINPUT_CHECKTABLE;
    1671             : 
    1672             :                 case KEY_UP | KEY_MOD2:
    1673           0 :                     eKeyState = KS_ColBottomSmall;
    1674           0 :                     eFlyState = KS_Fly_Change;
    1675           0 :                     nDir = MOVE_UP_SMALL;
    1676           0 :                     goto KEYINPUT_CHECKTABLE;
    1677             : 
    1678             :                 case KEY_DOWN | KEY_MOD2:
    1679           0 :                     eKeyState = KS_ColBottomBig;
    1680           0 :                     eFlyState = KS_Fly_Change;
    1681           0 :                     nDir = MOVE_DOWN_SMALL;
    1682           0 :                     goto KEYINPUT_CHECKTABLE;
    1683             : 
    1684             :                 case KEY_UP | KEY_MOD2 | KEY_MOD1:
    1685           0 :                     eKeyState = KS_CellBottomSmall;
    1686           0 :                     goto KEYINPUT_CHECKTABLE;
    1687             : 
    1688             :                 case KEY_DOWN | KEY_MOD2 | KEY_MOD1:
    1689           0 :                     eKeyState = KS_CellBottomBig;
    1690           0 :                     goto KEYINPUT_CHECKTABLE;
    1691             : 
    1692             :                 case KEY_UP | KEY_MOD2 | KEY_SHIFT | KEY_MOD1:
    1693           0 :                     eKeyState = KS_CellTopBig;
    1694           0 :                     goto KEYINPUT_CHECKTABLE;
    1695             : 
    1696             :                 case KEY_DOWN | KEY_MOD2 | KEY_SHIFT | KEY_MOD1:
    1697           0 :                     eKeyState = KS_CellTopSmall;
    1698           0 :                     goto KEYINPUT_CHECKTABLE;
    1699             : 
    1700             : KEYINPUT_CHECKTABLE:
    1701           0 :                     if( rSh.IsTableMode() || !rSh.GetTableFormat() )
    1702             :                     {
    1703           0 :                         if(KS_KeyToView != eFlyState)
    1704             :                         {
    1705           0 :                             if(!pFlyFormat && KS_KeyToView != eFlyState &&
    1706           0 :                                 (rSh.GetSelectionType() & (nsSelectionType::SEL_DRW|nsSelectionType::SEL_DRW_FORM))  &&
    1707           0 :                                     rSh.GetDrawView()->AreObjectsMarked())
    1708           0 :                                 eKeyState = KS_Draw_Change;
    1709             :                         }
    1710             : 
    1711           0 :                         if( pFlyFormat )
    1712           0 :                             eKeyState = eFlyState;
    1713           0 :                         else if( KS_Draw_Change != eKeyState)
    1714           0 :                             eKeyState = KS_EnterCharCell;
    1715             :                     }
    1716           0 :                     break;
    1717             : 
    1718             :                 // huge object move
    1719             :                 case KEY_RIGHT | KEY_SHIFT:
    1720             :                 case KEY_LEFT | KEY_SHIFT:
    1721             :                 case KEY_UP | KEY_SHIFT:
    1722             :                 case KEY_DOWN | KEY_SHIFT:
    1723             :                 {
    1724           0 :                     const int nSelectionType = rSh.GetSelectionType();
    1725           0 :                     if ( ( pFlyFormat
    1726           0 :                            && ( nSelectionType & (nsSelectionType::SEL_FRM|nsSelectionType::SEL_OLE|nsSelectionType::SEL_GRF) ) )
    1727           0 :                          || ( ( nSelectionType & (nsSelectionType::SEL_DRW|nsSelectionType::SEL_DRW_FORM) )
    1728           0 :                               && rSh.GetDrawView()->AreObjectsMarked() ) )
    1729             :                     {
    1730           0 :                         eKeyState = pFlyFormat ? KS_Fly_Change : KS_Draw_Change;
    1731           0 :                         switch ( rKeyCode.GetCode() )
    1732             :                         {
    1733           0 :                             case KEY_RIGHT: nDir = MOVE_RIGHT_HUGE; break;
    1734           0 :                             case KEY_LEFT: nDir = MOVE_LEFT_HUGE; break;
    1735           0 :                             case KEY_UP: nDir = MOVE_UP_HUGE; break;
    1736           0 :                             case KEY_DOWN: nDir = MOVE_DOWN_HUGE; break;
    1737             :                         }
    1738             :                     }
    1739           0 :                     break;
    1740             :                 }
    1741             : 
    1742             :                 case KEY_LEFT:
    1743             :                 case KEY_LEFT | KEY_MOD1:
    1744             :                 {
    1745           0 :                     bool bMod1 = 0 != (rKeyCode.GetModifier() & KEY_MOD1);
    1746           0 :                     if(!bMod1)
    1747             :                     {
    1748           0 :                         eFlyState = KS_Fly_Change;
    1749           0 :                         nDir = MOVE_LEFT_BIG;
    1750             :                     }
    1751             :                     eTableChgMode = nsTableChgWidthHeightType::WH_FLAG_INSDEL |
    1752             :                             ( bMod1
    1753             :                                 ? nsTableChgWidthHeightType::WH_CELL_LEFT
    1754           0 :                                 : nsTableChgWidthHeightType::WH_COL_LEFT );
    1755           0 :                     nTableChgSize = pModOpt->GetTableVInsert();
    1756             :                 }
    1757           0 :                     goto KEYINPUT_CHECKTABLE_INSDEL;
    1758             :                 case KEY_RIGHT | KEY_MOD1:
    1759             :                 {
    1760           0 :                     eTableChgMode = nsTableChgWidthHeightType::WH_FLAG_INSDEL | nsTableChgWidthHeightType::WH_CELL_RIGHT;
    1761           0 :                     nTableChgSize = pModOpt->GetTableVInsert();
    1762             :                 }
    1763           0 :                     goto KEYINPUT_CHECKTABLE_INSDEL;
    1764             :                 case KEY_UP:
    1765             :                 case KEY_UP | KEY_MOD1:
    1766             :                 {
    1767           0 :                     bool bMod1 = 0 != (rKeyCode.GetModifier() & KEY_MOD1);
    1768           0 :                     if(!bMod1)
    1769             :                     {
    1770           0 :                         eFlyState = KS_Fly_Change;
    1771           0 :                         nDir = MOVE_UP_BIG;
    1772             :                     }
    1773             :                     eTableChgMode = nsTableChgWidthHeightType::WH_FLAG_INSDEL |
    1774             :                             ( bMod1
    1775             :                                 ? nsTableChgWidthHeightType::WH_CELL_TOP
    1776           0 :                                 : nsTableChgWidthHeightType::WH_ROW_TOP );
    1777           0 :                     nTableChgSize = pModOpt->GetTableHInsert();
    1778             :                 }
    1779           0 :                     goto KEYINPUT_CHECKTABLE_INSDEL;
    1780             :                 case KEY_DOWN:
    1781             :                 case KEY_DOWN | KEY_MOD1:
    1782             :                 {
    1783           0 :                     bool bMod1 = 0 != (rKeyCode.GetModifier() & KEY_MOD1);
    1784           0 :                     if(!bMod1)
    1785             :                     {
    1786           0 :                         eFlyState = KS_Fly_Change;
    1787           0 :                         nDir = MOVE_DOWN_BIG;
    1788             :                     }
    1789             :                     eTableChgMode = nsTableChgWidthHeightType::WH_FLAG_INSDEL |
    1790             :                             ( bMod1
    1791             :                                 ? nsTableChgWidthHeightType::WH_CELL_BOTTOM
    1792           0 :                                 : nsTableChgWidthHeightType::WH_ROW_BOTTOM );
    1793           0 :                     nTableChgSize = pModOpt->GetTableHInsert();
    1794             :                 }
    1795           0 :                     goto KEYINPUT_CHECKTABLE_INSDEL;
    1796             : 
    1797             : KEYINPUT_CHECKTABLE_INSDEL:
    1798           0 :                     if( rSh.IsTableMode() || !rSh.GetTableFormat() ||
    1799           0 :                         !m_bTableInsDelMode ||
    1800             :                         false /* table protected */
    1801             :                             )
    1802             :                     {
    1803           0 :                         const int nSelectionType = rSh.GetSelectionType();
    1804             : 
    1805           0 :                         eKeyState = KS_KeyToView;
    1806           0 :                         if(KS_KeyToView != eFlyState)
    1807             :                         {
    1808           0 :                             if((nSelectionType & (nsSelectionType::SEL_DRW|nsSelectionType::SEL_DRW_FORM))  &&
    1809           0 :                                     rSh.GetDrawView()->AreObjectsMarked())
    1810           0 :                                 eKeyState = KS_Draw_Change;
    1811           0 :                             else if(nSelectionType & (nsSelectionType::SEL_FRM|nsSelectionType::SEL_OLE|nsSelectionType::SEL_GRF))
    1812           0 :                                 eKeyState = KS_Fly_Change;
    1813             :                         }
    1814             :                     }
    1815             :                     else
    1816             :                     {
    1817           0 :                         if( !m_bTableIsInsMode )
    1818           0 :                             eTableChgMode = eTableChgMode | nsTableChgWidthHeightType::WH_FLAG_BIGGER;
    1819           0 :                         eKeyState = KS_TableColCellInsDel;
    1820             :                     }
    1821           0 :                     break;
    1822             : 
    1823             :                 case KEY_DELETE:
    1824           0 :                     if ( !rSh.HasReadonlySel() )
    1825             :                     {
    1826           0 :                         if (rSh.IsInFrontOfLabel() && rSh.NumOrNoNum(false))
    1827           0 :                             eKeyState = KS_NumOrNoNum;
    1828             :                     }
    1829             :                     else
    1830             :                     {
    1831             :                         ScopedVclPtrInstance<MessageDialog>::Create(this, "InfoReadonlyDialog",
    1832           0 :                             "modules/swriter/ui/inforeadonlydialog.ui")->Execute();
    1833           0 :                         eKeyState = KS_End;
    1834             :                     }
    1835           0 :                     break;
    1836             : 
    1837             :                 case KEY_DELETE | KEY_MOD2:
    1838           0 :                     if( !rSh.IsTableMode() && rSh.GetTableFormat() )
    1839             :                     {
    1840           0 :                         eKeyState = KS_End;
    1841           0 :                         m_bTableInsDelMode = true;
    1842           0 :                         m_bTableIsInsMode = false;
    1843           0 :                         m_aKeyInputTimer.Start();
    1844           0 :                         bStopKeyInputTimer = false;
    1845             :                     }
    1846           0 :                     break;
    1847             :                 case KEY_INSERT | KEY_MOD2:
    1848           0 :                     if( !rSh.IsTableMode() && rSh.GetTableFormat() )
    1849             :                     {
    1850           0 :                         eKeyState = KS_End;
    1851           0 :                         m_bTableInsDelMode = true;
    1852           0 :                         m_bTableIsInsMode = true;
    1853           0 :                         m_aKeyInputTimer.Start();
    1854           0 :                         bStopKeyInputTimer = false;
    1855             :                     }
    1856           0 :                     break;
    1857             : 
    1858             :                 case KEY_RETURN:
    1859             :                 {
    1860           0 :                     if ( !rSh.HasReadonlySel()
    1861           0 :                          && !rSh.CrsrInsideInputField() )
    1862             :                     {
    1863           0 :                         const int nSelectionType = rSh.GetSelectionType();
    1864           0 :                         if(nSelectionType & nsSelectionType::SEL_OLE)
    1865           0 :                             eKeyState = KS_LaunchOLEObject;
    1866           0 :                         else if(nSelectionType & nsSelectionType::SEL_FRM)
    1867           0 :                             eKeyState = KS_GoIntoFly;
    1868           0 :                         else if((nSelectionType & nsSelectionType::SEL_DRW) &&
    1869           0 :                                 0 == (nSelectionType & nsSelectionType::SEL_DRW_TXT) &&
    1870           0 :                                 rSh.GetDrawView()->GetMarkedObjectList().GetMarkCount() == 1)
    1871           0 :                             eKeyState = KS_GoIntoDrawing;
    1872           0 :                         else if( aTmpQHD.HasContent() && !rSh.HasSelection() &&
    1873             :                             aTmpQHD.m_bIsAutoText )
    1874           0 :                             eKeyState = KS_GlossaryExpand;
    1875             : 
    1876             :                         //RETURN and empty paragraph in numbering -> end numbering
    1877           0 :                         else if( m_aInBuffer.isEmpty() &&
    1878           0 :                                  rSh.GetNumRuleAtCurrCrsrPos() &&
    1879           0 :                                  !rSh.GetNumRuleAtCurrCrsrPos()->IsOutlineRule() &&
    1880           0 :                                  !rSh.HasSelection() &&
    1881           0 :                                 rSh.IsSttPara() && rSh.IsEndPara() )
    1882           0 :                             eKeyState = KS_NumOff, eNextKeyState = KS_OutlineLvOff;
    1883             : 
    1884             :                         //RETURN for new paragraph with AutoFormating
    1885           0 :                         else if( pACfg && pACfg->IsAutoFormatByInput() &&
    1886           0 :                                 !(nSelectionType & (nsSelectionType::SEL_GRF |
    1887             :                                     nsSelectionType::SEL_OLE | nsSelectionType::SEL_FRM |
    1888             :                                     nsSelectionType::SEL_TBL_CELLS | nsSelectionType::SEL_DRW |
    1889             :                                     nsSelectionType::SEL_DRW_TXT)) )
    1890           0 :                             eKeyState = KS_CheckAutoCorrect, eNextKeyState = KS_AutoFormatByInput;
    1891             :                         else
    1892           0 :                             eNextKeyState = eKeyState, eKeyState = KS_CheckAutoCorrect;
    1893             :                     }
    1894             :                 }
    1895           0 :                 break;
    1896             :                 case KEY_RETURN | KEY_MOD2:
    1897             :                 {
    1898           0 :                     if ( !rSh.HasReadonlySel()
    1899           0 :                          && !rSh.IsSttPara()
    1900           0 :                          && rSh.GetNumRuleAtCurrCrsrPos()
    1901           0 :                          && !rSh.CrsrInsideInputField() )
    1902             :                     {
    1903           0 :                         eKeyState = KS_NoNum;
    1904             :                     }
    1905           0 :                     else if( rSh.CanSpecialInsert() )
    1906           0 :                         eKeyState = KS_SpecialInsert;
    1907             :                 }
    1908           0 :                 break;
    1909             :                 case KEY_BACKSPACE:
    1910             :                 case KEY_BACKSPACE | KEY_SHIFT:
    1911           0 :                     if ( !rSh.HasReadonlySel() )
    1912             :                     {
    1913           0 :                         bool bDone = false;
    1914             :                         // try to add comment for code snip:
    1915             :                         // Remove the paragraph indent, if the cursor is at the
    1916             :                         // beginning of a paragraph, there is no selection
    1917             :                         // and no numbering rule found at the current paragraph
    1918             :                         // Also try to remove indent, if current paragraph
    1919             :                         // has numbering rule, but isn't counted and only
    1920             :                         // key <backspace> is hit.
    1921           0 :                         const bool bOnlyBackspaceKey( KEY_BACKSPACE == rKeyCode.GetFullCode() );
    1922           0 :                         if ( rSh.IsSttPara()
    1923           0 :                              && !rSh.HasSelection()
    1924           0 :                              && ( rSh.GetNumRuleAtCurrCrsrPos() == NULL
    1925           0 :                                   || ( rSh.IsNoNum() && bOnlyBackspaceKey ) ) )
    1926             :                         {
    1927           0 :                             bDone = rSh.TryRemoveIndent();
    1928             :                         }
    1929             : 
    1930           0 :                         if (bDone)
    1931           0 :                             eKeyState = KS_End;
    1932             :                         else
    1933             :                         {
    1934           0 :                             if ( rSh.IsSttPara() && !rSh.IsNoNum() )
    1935             :                             {
    1936           0 :                                 if (m_nKS_NUMDOWN_Count > 0 &&
    1937           0 :                                     0 < rSh.GetNumLevel())
    1938             :                                 {
    1939           0 :                                     eKeyState = KS_NumUp;
    1940           0 :                                     m_nKS_NUMDOWN_Count = 2;
    1941           0 :                                     bDone = true;
    1942             :                                 }
    1943           0 :                                 else if (m_nKS_NUMINDENTINC_Count > 0)
    1944             :                                 {
    1945           0 :                                     eKeyState = KS_NumIndentDec;
    1946           0 :                                     m_nKS_NUMINDENTINC_Count = 2;
    1947           0 :                                     bDone = true;
    1948             :                                 }
    1949             :                             }
    1950             : 
    1951             :                             // If the cursor is in an empty paragraph, which has
    1952             :                             // a numbering, but not the outline numbering, and
    1953             :                             // there is no selection, the numbering has to be
    1954             :                             // deleted on key <Backspace>.
    1955             :                             // Otherwise method <SwEditShell::NumOrNoNum(..)>
    1956             :                             // should only change the <IsCounted()> state of
    1957             :                             // the current paragraph depending of the key.
    1958             :                             // On <backspace> it is set to <false>,
    1959             :                             // on <shift-backspace> it is set to <true>.
    1960             :                             // Thus, assure that method <SwEditShell::NumOrNum(..)>
    1961             :                             // is only called for the intended purpose.
    1962           0 :                             if ( !bDone && rSh.IsSttPara() )
    1963             :                             {
    1964           0 :                                 bool bCallNumOrNoNum( false );
    1965           0 :                                 if ( bOnlyBackspaceKey && !rSh.IsNoNum() )
    1966             :                                 {
    1967           0 :                                     bCallNumOrNoNum = true;
    1968             :                                 }
    1969           0 :                                 else if ( !bOnlyBackspaceKey && rSh.IsNoNum() )
    1970             :                                 {
    1971           0 :                                     bCallNumOrNoNum = true;
    1972             :                                 }
    1973           0 :                                 else if ( bOnlyBackspaceKey
    1974           0 :                                           && rSh.IsSttPara()
    1975           0 :                                           && rSh.IsEndPara()
    1976           0 :                                           && !rSh.HasSelection() )
    1977             :                                 {
    1978           0 :                                     const SwNumRule* pCurrNumRule( rSh.GetNumRuleAtCurrCrsrPos() );
    1979           0 :                                     if ( pCurrNumRule != NULL
    1980           0 :                                          && pCurrNumRule != rSh.GetOutlineNumRule() )
    1981             :                                     {
    1982           0 :                                         bCallNumOrNoNum = true;
    1983             :                                     }
    1984             :                                 }
    1985           0 :                                 if ( bCallNumOrNoNum
    1986           0 :                                      && rSh.NumOrNoNum( !bOnlyBackspaceKey, true ) )
    1987             :                                 {
    1988           0 :                                     eKeyState = KS_NumOrNoNum;
    1989             :                                 }
    1990             :                             }
    1991             :                         }
    1992             :                     }
    1993             :                     else
    1994             :                     {
    1995             :                         ScopedVclPtrInstance<MessageDialog>::Create(this, "InfoReadonlyDialog",
    1996           0 :                             "modules/swriter/ui/inforeadonlydialog.ui")->Execute();
    1997           0 :                         eKeyState = KS_End;
    1998             :                     }
    1999           0 :                     break;
    2000             : 
    2001             :                 case KEY_RIGHT:
    2002             :                     {
    2003           0 :                         eFlyState = KS_Fly_Change;
    2004           0 :                         nDir = MOVE_RIGHT_BIG;
    2005           0 :                         eTableChgMode = nsTableChgWidthHeightType::WH_FLAG_INSDEL | nsTableChgWidthHeightType::WH_COL_RIGHT;
    2006           0 :                         nTableChgSize = pModOpt->GetTableVInsert();
    2007           0 :                         goto KEYINPUT_CHECKTABLE_INSDEL;
    2008             :                     }
    2009             :                 case KEY_TAB:
    2010             :                 {
    2011             : 
    2012           0 :                     if (rSh.IsFormProtected() || rSh.GetCurrentFieldmark() || rSh.GetChar(false)==CH_TXT_ATR_FORMELEMENT)
    2013             :                     {
    2014           0 :                         eKeyState=KS_GotoNextFieldMark;
    2015             :                     }
    2016           0 :                     else if ( !rSh.IsMultiSelection() && rSh.CrsrInsideInputField() )
    2017             :                     {
    2018           0 :                         GetView().GetViewFrame()->GetDispatcher()->Execute( FN_GOTO_NEXT_INPUTFLD );
    2019           0 :                         eKeyState = KS_End;
    2020             :                     }
    2021           0 :                     else if( rSh.GetNumRuleAtCurrCrsrPos()
    2022           0 :                              && rSh.IsSttOfPara()
    2023           0 :                              && !rSh.HasReadonlySel() )
    2024             :                     {
    2025           0 :                         if ( !rSh.IsMultiSelection()
    2026           0 :                              && rSh.IsFirstOfNumRuleAtCrsrPos()
    2027           0 :                              && numfunc::ChangeIndentOnTabAtFirstPosOfFirstListItem() )
    2028           0 :                             eKeyState = KS_NumIndentInc;
    2029             :                         else
    2030           0 :                             eKeyState = KS_NumDown;
    2031             :                     }
    2032           0 :                     else if ( rSh.GetTableFormat() )
    2033             :                     {
    2034           0 :                         if( rSh.HasSelection() || rSh.HasReadonlySel() )
    2035           0 :                             eKeyState = KS_NextCell;
    2036             :                         else
    2037           0 :                             eKeyState = KS_CheckAutoCorrect, eNextKeyState = KS_NextCell;
    2038             :                     }
    2039           0 :                     else if ( rSh.GetSelectionType() &
    2040             :                                 (nsSelectionType::SEL_GRF |
    2041             :                                     nsSelectionType::SEL_FRM |
    2042             :                                     nsSelectionType::SEL_OLE |
    2043             :                                     nsSelectionType::SEL_DRW |
    2044             :                                     nsSelectionType::SEL_DRW_FORM))
    2045             : 
    2046           0 :                             eKeyState = KS_NextObject;
    2047             :                     else
    2048             :                     {
    2049           0 :                         eKeyState = KS_InsTab;
    2050           0 :                         if( rSh.IsSttOfPara() && !rSh.HasReadonlySel() )
    2051             :                         {
    2052           0 :                             SwTextFormatColl* pColl = rSh.GetCurTextFormatColl();
    2053           0 :                             if( pColl &&
    2054             : 
    2055           0 :                                 pColl->IsAssignedToListLevelOfOutlineStyle()
    2056           0 :                                 && MAXLEVEL-1 > pColl->GetAssignedOutlineStyleLevel() )
    2057           0 :                                 eKeyState = KS_OutlineDown;
    2058             :                         }
    2059             :                     }
    2060             :                 }
    2061           0 :                 break;
    2062             :                 case KEY_TAB | KEY_SHIFT:
    2063             :                 {
    2064           0 :                     if (rSh.IsFormProtected() || rSh.GetCurrentFieldmark()|| rSh.GetChar(false)==CH_TXT_ATR_FORMELEMENT)
    2065             :                     {
    2066           0 :                         eKeyState=KS_GotoPrevFieldMark;
    2067             :                     }
    2068           0 :                     else if ( !rSh.IsMultiSelection() && rSh.CrsrInsideInputField() )
    2069             :                     {
    2070           0 :                         GetView().GetViewFrame()->GetDispatcher()->Execute( FN_GOTO_PREV_INPUTFLD );
    2071           0 :                         eKeyState = KS_End;
    2072             :                     }
    2073           0 :                     else if( rSh.GetNumRuleAtCurrCrsrPos()
    2074           0 :                              && rSh.IsSttOfPara()
    2075           0 :                              && !rSh.HasReadonlySel() )
    2076             :                     {
    2077           0 :                         if ( !rSh.IsMultiSelection()
    2078           0 :                              && rSh.IsFirstOfNumRuleAtCrsrPos()
    2079           0 :                              && numfunc::ChangeIndentOnTabAtFirstPosOfFirstListItem() )
    2080           0 :                             eKeyState = KS_NumIndentDec;
    2081             :                         else
    2082           0 :                             eKeyState = KS_NumUp;
    2083             :                     }
    2084           0 :                     else if ( rSh.GetTableFormat() )
    2085             :                     {
    2086           0 :                         if( rSh.HasSelection() || rSh.HasReadonlySel() )
    2087           0 :                             eKeyState = KS_PrevCell;
    2088             :                         else
    2089           0 :                             eKeyState = KS_CheckAutoCorrect, eNextKeyState = KS_PrevCell;
    2090             :                     }
    2091           0 :                     else if ( rSh.GetSelectionType() &
    2092             :                                 (nsSelectionType::SEL_GRF |
    2093             :                                     nsSelectionType::SEL_FRM |
    2094             :                                     nsSelectionType::SEL_OLE |
    2095             :                                     nsSelectionType::SEL_DRW |
    2096             :                                     nsSelectionType::SEL_DRW_FORM))
    2097             : 
    2098           0 :                             eKeyState = KS_PrevObject;
    2099             :                     else
    2100             :                     {
    2101           0 :                         eKeyState = KS_End;
    2102           0 :                         if( rSh.IsSttOfPara() && !rSh.HasReadonlySel() )
    2103             :                         {
    2104           0 :                             SwTextFormatColl* pColl = rSh.GetCurTextFormatColl();
    2105           0 :                             if( pColl &&
    2106           0 :                                 pColl->IsAssignedToListLevelOfOutlineStyle() &&
    2107           0 :                                 0 < pColl->GetAssignedOutlineStyleLevel())
    2108           0 :                                 eKeyState = KS_OutlineUp;
    2109             :                         }
    2110             :                     }
    2111             :                 }
    2112           0 :                 break;
    2113             :                 case KEY_TAB | KEY_MOD1:
    2114             :                 case KEY_TAB | KEY_MOD2:
    2115           0 :                     if( !rSh.HasReadonlySel() )
    2116             :                     {
    2117           0 :                         if( aTmpQHD.HasContent() && !rSh.HasSelection() )
    2118             :                         {
    2119             :                             // Next auto-complete suggestion
    2120           0 :                             aTmpQHD.Next( pACorr &&
    2121           0 :                                           pACorr->GetSwFlags().bAutoCmpltEndless );
    2122           0 :                             eKeyState = KS_NextPrevGlossary;
    2123             :                         }
    2124           0 :                         else if( rSh.GetTableFormat() )
    2125           0 :                             eKeyState = KS_InsTab;
    2126           0 :                         else if((rSh.GetSelectionType() &
    2127             :                                     (nsSelectionType::SEL_DRW|nsSelectionType::SEL_DRW_FORM|
    2128           0 :                                         nsSelectionType::SEL_FRM|nsSelectionType::SEL_OLE|nsSelectionType::SEL_GRF))  &&
    2129           0 :                                 rSh.GetDrawView()->AreObjectsMarked())
    2130           0 :                             eKeyState = KS_EnterDrawHandleMode;
    2131             :                         else
    2132             :                         {
    2133           0 :                             eKeyState = KS_InsTab;
    2134             :                         }
    2135             :                     }
    2136           0 :                     break;
    2137             : 
    2138             :                     case KEY_TAB | KEY_MOD1 | KEY_SHIFT:
    2139             :                     {
    2140           0 :                         if( aTmpQHD.HasContent() && !rSh.HasSelection() &&
    2141           0 :                             !rSh.HasReadonlySel() )
    2142             :                         {
    2143             :                             // Previous auto-complete suggestion.
    2144           0 :                             aTmpQHD.Previous( pACorr &&
    2145           0 :                                               pACorr->GetSwFlags().bAutoCmpltEndless );
    2146           0 :                             eKeyState = KS_NextPrevGlossary;
    2147             :                         }
    2148           0 :                         else if((rSh.GetSelectionType() & (nsSelectionType::SEL_DRW|nsSelectionType::SEL_DRW_FORM|
    2149           0 :                                         nsSelectionType::SEL_FRM|nsSelectionType::SEL_OLE|nsSelectionType::SEL_GRF)) &&
    2150           0 :                                 rSh.GetDrawView()->AreObjectsMarked())
    2151             :                         {
    2152           0 :                             eKeyState = KS_EnterDrawHandleMode;
    2153             :                         }
    2154             :                     }
    2155           0 :                     break;
    2156             :                     case KEY_F2 :
    2157           0 :                     if( !rSh.HasReadonlySel() )
    2158             :                     {
    2159           0 :                         const int nSelectionType = rSh.GetSelectionType();
    2160           0 :                         if(nSelectionType & nsSelectionType::SEL_FRM)
    2161           0 :                             eKeyState = KS_GoIntoFly;
    2162           0 :                         else if((nSelectionType & nsSelectionType::SEL_DRW))
    2163           0 :                             eKeyState = KS_GoIntoDrawing;
    2164             :                     }
    2165           0 :                     break;
    2166             :                 }
    2167             :             }
    2168           1 :             break;
    2169             :         case KS_CheckDocReadOnlyKeys:
    2170             :             {
    2171           0 :                 eKeyState = KS_KeyToView;
    2172           0 :                 switch( rKeyCode.GetModifier() | rKeyCode.GetCode() )
    2173             :                 {
    2174             :                     case KEY_TAB:
    2175             :                     case KEY_TAB | KEY_SHIFT:
    2176           0 :                         bNormalChar = false;
    2177           0 :                         eKeyState = KS_End;
    2178           0 :                         if ( rSh.GetSelectionType() &
    2179             :                                 (nsSelectionType::SEL_GRF |
    2180             :                                     nsSelectionType::SEL_FRM |
    2181             :                                     nsSelectionType::SEL_OLE |
    2182             :                                     nsSelectionType::SEL_DRW |
    2183             :                                     nsSelectionType::SEL_DRW_FORM))
    2184             : 
    2185             :                         {
    2186           0 :                             eKeyState = rKeyCode.GetModifier() & KEY_SHIFT ?
    2187           0 :                                                 KS_PrevObject : KS_NextObject;
    2188             :                         }
    2189           0 :                         else if ( !rSh.IsMultiSelection() && rSh.CrsrInsideInputField() )
    2190             :                         {
    2191           0 :                             GetView().GetViewFrame()->GetDispatcher()->Execute(
    2192           0 :                                 KEY_SHIFT != rKeyCode.GetModifier() ? FN_GOTO_NEXT_INPUTFLD : FN_GOTO_PREV_INPUTFLD );
    2193             :                         }
    2194             :                         else
    2195             :                         {
    2196           0 :                             rSh.SelectNextPrevHyperlink( KEY_SHIFT != rKeyCode.GetModifier() );
    2197             :                         }
    2198           0 :                     break;
    2199             :                     case KEY_RETURN:
    2200             :                     {
    2201           0 :                         const int nSelectionType = rSh.GetSelectionType();
    2202           0 :                         if(nSelectionType & nsSelectionType::SEL_FRM)
    2203           0 :                             eKeyState = KS_GoIntoFly;
    2204             :                         else
    2205             :                         {
    2206           0 :                             SfxItemSet aSet(rSh.GetAttrPool(), RES_TXTATR_INETFMT, RES_TXTATR_INETFMT);
    2207           0 :                             rSh.GetCurAttr(aSet);
    2208           0 :                             if(SfxItemState::SET == aSet.GetItemState(RES_TXTATR_INETFMT, false))
    2209             :                             {
    2210           0 :                                 const SfxPoolItem& rItem = aSet.Get(RES_TXTATR_INETFMT, true);
    2211           0 :                                 bNormalChar = false;
    2212           0 :                                 eKeyState = KS_End;
    2213           0 :                                 rSh.ClickToINetAttr(static_cast<const SwFormatINetFormat&>(rItem), URLLOAD_NOFILTER);
    2214           0 :                             }
    2215             :                         }
    2216             :                     }
    2217           0 :                     break;
    2218             :                 }
    2219             :             }
    2220           0 :             break;
    2221             : 
    2222             :         case KS_EnterCharCell:
    2223             :             {
    2224           0 :                 eKeyState = KS_KeyToView;
    2225           0 :                 switch ( rKeyCode.GetModifier() | rKeyCode.GetCode() )
    2226             :                 {
    2227             :                     case KEY_RIGHT | KEY_MOD2:
    2228           0 :                         rSh.Right( CRSR_SKIP_CHARS, false, 1, false );
    2229           0 :                         eKeyState = KS_End;
    2230           0 :                         FlushInBuffer();
    2231           0 :                         break;
    2232             :                     case KEY_LEFT | KEY_MOD2:
    2233           0 :                         rSh.Left( CRSR_SKIP_CHARS, false, 1, false );
    2234           0 :                         eKeyState = KS_End;
    2235           0 :                         FlushInBuffer();
    2236           0 :                         break;
    2237             :                 }
    2238             :             }
    2239           0 :             break;
    2240             : 
    2241             :         case KS_KeyToView:
    2242             :             {
    2243           1 :                 eKeyState = KS_End;
    2244             :                 bNormalChar =
    2245           2 :                     !rKeyCode.IsMod2() &&
    2246           2 :                     rKeyCode.GetModifier() != (KEY_MOD1) &&
    2247           4 :                     rKeyCode.GetModifier() != (KEY_MOD1|KEY_SHIFT) &&
    2248           2 :                     SW_ISPRINTABLE( aCh );
    2249             : 
    2250           1 :                 if( bNormalChar && rSh.IsInFrontOfLabel() )
    2251             :                 {
    2252           0 :                     rSh.NumOrNoNum(false);
    2253             :                 }
    2254             : 
    2255           1 :                 if( !m_aInBuffer.isEmpty() && ( !bNormalChar || bIsDocReadOnly ))
    2256           0 :                     FlushInBuffer();
    2257             : 
    2258           1 :                 if( m_rView.KeyInput( aKeyEvent ) )
    2259           0 :                     bFlushBuffer = true, bNormalChar = false;
    2260             :                 else
    2261             :                 {
    2262             :                     // Because Sfx accelerators are only called when they were
    2263             :                     // enabled at the last status update, copy has to called
    2264             :                     // 'forcefully' by us if necessary.
    2265           1 :                     if( rKeyCode.GetFunction() == KeyFuncType::COPY )
    2266           0 :                         GetView().GetViewFrame()->GetBindings().Execute(SID_COPY);
    2267             : 
    2268           1 :                     if( !bIsDocReadOnly && bNormalChar )
    2269             :                     {
    2270           1 :                         const int nSelectionType = rSh.GetSelectionType();
    2271           2 :                         if((nSelectionType & nsSelectionType::SEL_DRW) &&
    2272           1 :                             0 == (nSelectionType & nsSelectionType::SEL_DRW_TXT) &&
    2273           0 :                             rSh.GetDrawView()->GetMarkedObjectList().GetMarkCount() == 1)
    2274             :                         {
    2275           0 :                             SdrObject* pObj = rSh.GetDrawView()->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
    2276           0 :                             if(pObj)
    2277             :                             {
    2278           0 :                                 EnterDrawTextMode(pObj->GetLogicRect().Center());
    2279           0 :                                 if ( m_rView.GetCurShell()->ISA(SwDrawTextShell) )
    2280           0 :                                     static_cast<SwDrawTextShell*>(m_rView.GetCurShell())->Init();
    2281           0 :                                 rSh.GetDrawView()->KeyInput( rKEvt, this );
    2282             :                             }
    2283             :                         }
    2284           1 :                         else if(nSelectionType & nsSelectionType::SEL_FRM)
    2285             :                         {
    2286           0 :                             rSh.UnSelectFrm();
    2287           0 :                             rSh.LeaveSelFrmMode();
    2288           0 :                             m_rView.AttrChangedNotify(&rSh);
    2289           0 :                             rSh.MoveSection( fnSectionCurr, fnSectionEnd );
    2290             :                         }
    2291           1 :                         eKeyState = KS_InsChar;
    2292             :                     }
    2293             :                     else
    2294             :                     {
    2295           0 :                         bNormalChar = false;
    2296           0 :                         Window::KeyInput( aKeyEvent );
    2297             :                     }
    2298             :                 }
    2299             :             }
    2300           1 :             break;
    2301             :         case KS_LaunchOLEObject:
    2302             :         {
    2303           0 :             rSh.LaunchOLEObj();
    2304           0 :             eKeyState = KS_End;
    2305             :         }
    2306           0 :         break;
    2307             :         case KS_GoIntoFly:
    2308             :         {
    2309           0 :             rSh.UnSelectFrm();
    2310           0 :             rSh.LeaveSelFrmMode();
    2311           0 :             m_rView.AttrChangedNotify(&rSh);
    2312           0 :             rSh.MoveSection( fnSectionCurr, fnSectionEnd );
    2313           0 :             eKeyState = KS_End;
    2314             :         }
    2315           0 :         break;
    2316             :         case KS_GoIntoDrawing:
    2317             :         {
    2318           0 :             SdrObject* pObj = rSh.GetDrawView()->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
    2319           0 :             if(pObj)
    2320             :             {
    2321           0 :                 EnterDrawTextMode(pObj->GetLogicRect().Center());
    2322           0 :                 if ( m_rView.GetCurShell()->ISA(SwDrawTextShell) )
    2323           0 :                     static_cast<SwDrawTextShell*>(m_rView.GetCurShell())->Init();
    2324             :             }
    2325           0 :             eKeyState = KS_End;
    2326             :         }
    2327           0 :         break;
    2328             :         case KS_EnterDrawHandleMode:
    2329             :         {
    2330           0 :             const SdrHdlList& rHdlList = rSh.GetDrawView()->GetHdlList();
    2331           0 :             bool bForward(!aKeyEvent.GetKeyCode().IsShift());
    2332             : 
    2333           0 :             const_cast<SdrHdlList&>(rHdlList).TravelFocusHdl(bForward);
    2334           0 :             eKeyState = KS_End;
    2335             :         }
    2336           0 :         break;
    2337             :         case KS_InsTab:
    2338           0 :             if( m_rView.ISA( SwWebView ))     // no Tab for WebView
    2339             :             {
    2340             :                 // then it should be passed along
    2341           0 :                 Window::KeyInput( aKeyEvent );
    2342           0 :                 eKeyState = KS_End;
    2343           0 :                 break;
    2344             :             }
    2345           0 :             aCh = '\t';
    2346             :             // no break!
    2347             :         case KS_InsChar:
    2348           1 :             if (rSh.GetChar(false)==CH_TXT_ATR_FORMELEMENT)
    2349             :             {
    2350             :                 ::sw::mark::ICheckboxFieldmark* pFieldmark =
    2351             :                     dynamic_cast< ::sw::mark::ICheckboxFieldmark* >
    2352           0 :                         (rSh.GetCurrentFieldmark());
    2353             :                 OSL_ENSURE(pFieldmark,
    2354             :                     "Where is my FieldMark??");
    2355           0 :                 if(pFieldmark)
    2356             :                 {
    2357           0 :                     pFieldmark->SetChecked(!pFieldmark->IsChecked());
    2358             :                     OSL_ENSURE(pFieldmark->IsExpanded(),
    2359             :                         "where is the otherpos?");
    2360           0 :                     if (pFieldmark->IsExpanded())
    2361             :                     {
    2362           0 :                         rSh.CalcLayout();
    2363             :                     }
    2364             :                 }
    2365           0 :                 eKeyState = KS_End;
    2366             :             }
    2367           2 :             else if ( !rSh.HasReadonlySel()
    2368           1 :                       || rSh.CrsrInsideInputField() )
    2369             :             {
    2370             :                 const bool bIsNormalChar =
    2371           1 :                     GetAppCharClass().isLetterNumeric( OUString( aCh ), 0 );
    2372           1 :                 if( bAppendSpace && bIsNormalChar &&
    2373           0 :                     (!m_aInBuffer.isEmpty() || !rSh.IsSttPara() || !rSh.IsEndPara() ))
    2374             :                 {
    2375             :                     // insert a blank ahead of the character. this ends up
    2376             :                     // between the expanded text and the new "non-word-separator".
    2377           0 :                     m_aInBuffer += " ";
    2378             :                 }
    2379             : 
    2380           1 :                 const bool bIsAutoCorrectChar =  SvxAutoCorrect::IsAutoCorrectChar( aCh );
    2381           1 :                 const bool bRunNext = pACorr != NULL && pACorr->HasRunNext();
    2382           3 :                 if( !aKeyEvent.GetRepeat() && pACorr && ( bIsAutoCorrectChar || bRunNext ) &&
    2383           1 :                         pACfg->IsAutoFormatByInput() &&
    2384           0 :                     (( pACorr->IsAutoCorrFlag( ChgWeightUnderl ) &&
    2385           0 :                         ( '*' == aCh || '_' == aCh ) ) ||
    2386           0 :                      ( pACorr->IsAutoCorrFlag( ChgQuotes ) && ('\"' == aCh ))||
    2387           0 :                      ( pACorr->IsAutoCorrFlag( ChgSglQuotes ) && ( '\'' == aCh))))
    2388             :                 {
    2389           0 :                     FlushInBuffer();
    2390           0 :                     rSh.AutoCorrect( *pACorr, aCh );
    2391           0 :                     if( '\"' != aCh && '\'' != aCh )        // only call when "*_"!
    2392           0 :                         rSh.UpdateAttr();
    2393             :                 }
    2394           3 :                 else if( !aKeyEvent.GetRepeat() && pACorr && ( bIsAutoCorrectChar || bRunNext ) &&
    2395           0 :                         pACfg->IsAutoFormatByInput() &&
    2396             :                     pACorr->IsAutoCorrFlag( CapitalStartSentence | CapitalStartWord |
    2397             :                                             ChgOrdinalNumber | AddNonBrkSpace |
    2398             :                                             ChgToEnEmDash | SetINetAttr |
    2399           0 :                                             Autocorrect ) &&
    2400           1 :                     '\"' != aCh && '\'' != aCh && '*' != aCh && '_' != aCh
    2401             :                     )
    2402             :                 {
    2403           0 :                     FlushInBuffer();
    2404           0 :                     rSh.AutoCorrect( *pACorr, aCh );
    2405             :                 }
    2406             :                 else
    2407             :                 {
    2408           1 :                     OUStringBuffer aBuf(m_aInBuffer);
    2409             :                     comphelper::string::padToLength(aBuf,
    2410           1 :                         m_aInBuffer.getLength() + aKeyEvent.GetRepeat() + 1, aCh);
    2411           1 :                     m_aInBuffer = aBuf.makeStringAndClear();
    2412           1 :                     g_bFlushCharBuffer = Application::AnyInput( VclInputFlags::KEYBOARD );
    2413           1 :                     bFlushBuffer = !g_bFlushCharBuffer;
    2414           1 :                     if( g_bFlushCharBuffer )
    2415           0 :                         m_aKeyInputFlushTimer.Start();
    2416             :                 }
    2417           1 :                 eKeyState = KS_End;
    2418             :             }
    2419             :             else
    2420             :             {
    2421             :                 ScopedVclPtrInstance<MessageDialog>::Create(this, "InfoReadonlyDialog",
    2422           0 :                     "modules/swriter/ui/inforeadonlydialog.ui")->Execute();
    2423           0 :                 eKeyState = KS_End;
    2424             :             }
    2425           1 :         break;
    2426             : 
    2427             :         case KS_CheckAutoCorrect:
    2428             :         {
    2429           0 :             if( pACorr && pACfg->IsAutoFormatByInput() &&
    2430             :                 pACorr->IsAutoCorrFlag( CapitalStartSentence | CapitalStartWord |
    2431             :                                         ChgOrdinalNumber |
    2432             :                                         ChgToEnEmDash | SetINetAttr |
    2433           0 :                                         Autocorrect ) &&
    2434           0 :                 !rSh.HasReadonlySel() )
    2435             :             {
    2436           0 :                 FlushInBuffer();
    2437           0 :                 rSh.AutoCorrect( *pACorr, static_cast< sal_Unicode >('\0') );
    2438             :             }
    2439           0 :             eKeyState = eNextKeyState;
    2440             :         }
    2441           0 :         break;
    2442             : 
    2443             :         default:
    2444             :         {
    2445           0 :             sal_uInt16 nSlotId = 0;
    2446           0 :             FlushInBuffer();
    2447           0 :             switch( eKeyState )
    2448             :             {
    2449             :             case KS_SpecialInsert:
    2450           0 :                 rSh.DoSpecialInsert();
    2451           0 :                 break;
    2452             : 
    2453             :             case KS_NoNum:
    2454           0 :                 rSh.NoNum();
    2455           0 :                 break;
    2456             : 
    2457             :             case KS_NumOff:
    2458             :                 // shell change - so record in advance
    2459           0 :                 rSh.DelNumRules();
    2460           0 :                 eKeyState = eNextKeyState;
    2461           0 :                 break;
    2462             :             case KS_OutlineLvOff: // delete autofmt outlinelevel later
    2463           0 :                 break;
    2464             : 
    2465             :             case KS_NumDown:
    2466           0 :                 rSh.NumUpDown( true );
    2467           0 :                 m_nKS_NUMDOWN_Count = 2;
    2468           0 :                 break;
    2469             :             case KS_NumUp:
    2470           0 :                 rSh.NumUpDown( false );
    2471           0 :                 break;
    2472             : 
    2473             :             case KS_NumIndentInc:
    2474           0 :                 rSh.ChangeIndentOfAllListLevels(360);
    2475           0 :                 m_nKS_NUMINDENTINC_Count = 2;
    2476           0 :                 break;
    2477             : 
    2478             :             case KS_GotoNextFieldMark:
    2479             :                 {
    2480           0 :                     ::sw::mark::IFieldmark const * const pFieldmark = rSh.GetFieldmarkAfter();
    2481           0 :                     if(pFieldmark) rSh.GotoFieldmark(pFieldmark);
    2482             :                 }
    2483           0 :                 break;
    2484             : 
    2485             :             case KS_GotoPrevFieldMark:
    2486             :                 {
    2487           0 :                     ::sw::mark::IFieldmark const * const pFieldmark = rSh.GetFieldmarkBefore();
    2488           0 :                     if( pFieldmark )
    2489           0 :                         rSh.GotoFieldmark(pFieldmark);
    2490             :                 }
    2491           0 :                 break;
    2492             : 
    2493             :             case KS_NumIndentDec:
    2494           0 :                 rSh.ChangeIndentOfAllListLevels(-360);
    2495           0 :                 break;
    2496             : 
    2497             :             case KS_OutlineDown:
    2498           0 :                 rSh.OutlineUpDown( 1 );
    2499           0 :                 break;
    2500             :             case KS_OutlineUp:
    2501           0 :                 rSh.OutlineUpDown( -1 );
    2502           0 :                 break;
    2503             : 
    2504             :             case KS_NextCell:
    2505             :                 // always 'flush' in tables
    2506           0 :                 rSh.GoNextCell();
    2507           0 :                 nSlotId = FN_GOTO_NEXT_CELL;
    2508           0 :                 break;
    2509             :             case KS_PrevCell:
    2510           0 :                 rSh.GoPrevCell();
    2511           0 :                 nSlotId = FN_GOTO_PREV_CELL;
    2512           0 :                 break;
    2513             :             case KS_AutoFormatByInput:
    2514           0 :                 rSh.SplitNode( true );
    2515           0 :                 break;
    2516             : 
    2517             :             case KS_NextObject:
    2518             :             case KS_PrevObject:
    2519           0 :                 if(rSh.GotoObj( KS_NextObject == eKeyState, GotoObjFlags::Any))
    2520             :                 {
    2521           0 :                     if( rSh.IsFrmSelected() &&
    2522           0 :                         m_rView.GetDrawFuncPtr() )
    2523             :                     {
    2524           0 :                         m_rView.GetDrawFuncPtr()->Deactivate();
    2525           0 :                         m_rView.SetDrawFuncPtr(NULL);
    2526           0 :                         m_rView.LeaveDrawCreate();
    2527           0 :                         m_rView.AttrChangedNotify( &rSh );
    2528             :                     }
    2529           0 :                     rSh.HideCrsr();
    2530           0 :                     rSh.EnterSelFrmMode();
    2531             :                 }
    2532           0 :             break;
    2533             :             case KS_GlossaryExpand:
    2534             :             {
    2535             :                 // replace the word or abbreviation with the auto text
    2536           0 :                 rSh.StartUndo( UNDO_START );
    2537             : 
    2538           0 :                 OUString sFnd( aTmpQHD.m_aHelpStrings[ aTmpQHD.nCurArrPos ] );
    2539           0 :                 if( aTmpQHD.m_bIsAutoText )
    2540             :                 {
    2541           0 :                     SwGlossaryList* pList = ::GetGlossaryList();
    2542           0 :                     OUString sShrtNm;
    2543           0 :                     OUString sGroup;
    2544           0 :                     if(pList->GetShortName( sFnd, sShrtNm, sGroup))
    2545             :                     {
    2546           0 :                         rSh.SttSelect();
    2547           0 :                         rSh.ExtendSelection( false, aTmpQHD.nLen );
    2548           0 :                         SwGlossaryHdl* pGlosHdl = GetView().GetGlosHdl();
    2549           0 :                         pGlosHdl->SetCurGroup(sGroup, true);
    2550           0 :                         pGlosHdl->InsertGlossary( sShrtNm);
    2551           0 :                         m_pQuickHlpData->m_bAppendSpace = true;
    2552           0 :                     }
    2553             :                 }
    2554             :                 else
    2555             :                 {
    2556           0 :                     sFnd = sFnd.copy( aTmpQHD.nLen );
    2557           0 :                     rSh.Insert( sFnd );
    2558           0 :                     m_pQuickHlpData->m_bAppendSpace = !pACorr ||
    2559           0 :                             pACorr->GetSwFlags().bAutoCmpltAppendBlanc;
    2560             :                 }
    2561           0 :                 rSh.EndUndo( UNDO_END );
    2562             :             }
    2563           0 :             break;
    2564             : 
    2565             :             case KS_NextPrevGlossary:
    2566           0 :                 m_pQuickHlpData->Move( aTmpQHD );
    2567           0 :                 m_pQuickHlpData->Start( rSh, USHRT_MAX );
    2568           0 :                 break;
    2569             : 
    2570             :             case KS_EditFormula:
    2571             :             {
    2572           0 :                 const sal_uInt16 nId = SwInputChild::GetChildWindowId();
    2573             : 
    2574           0 :                 SfxViewFrame* pVFrame = GetView().GetViewFrame();
    2575           0 :                 pVFrame->ToggleChildWindow( nId );
    2576             :                 SwInputChild* pChildWin = static_cast<SwInputChild*>(pVFrame->
    2577           0 :                                                     GetChildWindow( nId ));
    2578           0 :                 if( pChildWin )
    2579           0 :                     pChildWin->SetFormula( sFormulaEntry );
    2580             :             }
    2581           0 :             break;
    2582             : 
    2583           0 :             case KS_ColLeftBig:         rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_COL_LEFT|nsTableChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTableHMove() );   break;
    2584           0 :             case KS_ColRightBig:        rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_COL_RIGHT|nsTableChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTableHMove() );  break;
    2585           0 :             case KS_ColLeftSmall:       rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_COL_LEFT, pModOpt->GetTableHMove() );   break;
    2586           0 :             case KS_ColRightSmall:      rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_COL_RIGHT, pModOpt->GetTableHMove() );  break;
    2587           0 :             case KS_ColBottomBig:       rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_ROW_BOTTOM|nsTableChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTableVMove() ); break;
    2588           0 :             case KS_ColBottomSmall:     rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_ROW_BOTTOM, pModOpt->GetTableVMove() ); break;
    2589           0 :             case KS_CellLeftBig:        rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_CELL_LEFT|nsTableChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTableHMove() );  break;
    2590           0 :             case KS_CellRightBig:       rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_CELL_RIGHT|nsTableChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTableHMove() ); break;
    2591           0 :             case KS_CellLeftSmall:      rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_CELL_LEFT, pModOpt->GetTableHMove() );  break;
    2592           0 :             case KS_CellRightSmall:     rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_CELL_RIGHT, pModOpt->GetTableHMove() ); break;
    2593           0 :             case KS_CellTopBig:         rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_CELL_TOP|nsTableChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTableVMove() );   break;
    2594           0 :             case KS_CellBottomBig:      rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_CELL_BOTTOM|nsTableChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTableVMove() );    break;
    2595           0 :             case KS_CellTopSmall:       rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_CELL_TOP, pModOpt->GetTableVMove() );   break;
    2596           0 :             case KS_CellBottomSmall:    rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_CELL_BOTTOM, pModOpt->GetTableVMove() );    break;
    2597             : 
    2598           0 :             case KS_InsDel_ColLeftBig:          rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_FLAG_INSDEL|nsTableChgWidthHeightType::WH_COL_LEFT|nsTableChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTableHInsert() ); break;
    2599           0 :             case KS_InsDel_ColRightBig:         rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_FLAG_INSDEL|nsTableChgWidthHeightType::WH_COL_RIGHT|nsTableChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTableHInsert() );    break;
    2600           0 :             case KS_InsDel_ColLeftSmall:        rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_FLAG_INSDEL|nsTableChgWidthHeightType::WH_COL_LEFT, pModOpt->GetTableHInsert() ); break;
    2601           0 :             case KS_InsDel_ColRightSmall:       rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_FLAG_INSDEL|nsTableChgWidthHeightType::WH_COL_RIGHT, pModOpt->GetTableHInsert() );    break;
    2602           0 :             case KS_InsDel_ColTopBig:           rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_FLAG_INSDEL|nsTableChgWidthHeightType::WH_ROW_TOP|nsTableChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTableVInsert() );  break;
    2603           0 :             case KS_InsDel_ColBottomBig:        rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_FLAG_INSDEL|nsTableChgWidthHeightType::WH_ROW_BOTTOM|nsTableChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTableVInsert() );   break;
    2604           0 :             case KS_InsDel_ColTopSmall:         rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_FLAG_INSDEL|nsTableChgWidthHeightType::WH_ROW_TOP, pModOpt->GetTableVInsert() );  break;
    2605           0 :             case KS_InsDel_ColBottomSmall:      rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_FLAG_INSDEL|nsTableChgWidthHeightType::WH_ROW_BOTTOM, pModOpt->GetTableVInsert() );   break;
    2606           0 :             case KS_InsDel_CellLeftBig:         rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_FLAG_INSDEL|nsTableChgWidthHeightType::WH_CELL_LEFT|nsTableChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTableHInsert() );    break;
    2607           0 :             case KS_InsDel_CellRightBig:        rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_FLAG_INSDEL|nsTableChgWidthHeightType::WH_CELL_RIGHT|nsTableChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTableHInsert() );   break;
    2608           0 :             case KS_InsDel_CellLeftSmall:       rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_FLAG_INSDEL|nsTableChgWidthHeightType::WH_CELL_LEFT, pModOpt->GetTableHInsert() );    break;
    2609           0 :             case KS_InsDel_CellRightSmall:      rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_FLAG_INSDEL|nsTableChgWidthHeightType::WH_CELL_RIGHT, pModOpt->GetTableHInsert() );   break;
    2610           0 :             case KS_InsDel_CellTopBig:          rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_FLAG_INSDEL|nsTableChgWidthHeightType::WH_CELL_TOP|nsTableChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTableVInsert() ); break;
    2611           0 :             case KS_InsDel_CellBottomBig:       rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_FLAG_INSDEL|nsTableChgWidthHeightType::WH_CELL_BOTTOM|nsTableChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTableVInsert() );  break;
    2612           0 :             case KS_InsDel_CellTopSmall:        rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_FLAG_INSDEL|nsTableChgWidthHeightType::WH_CELL_TOP, pModOpt->GetTableVInsert() ); break;
    2613           0 :             case KS_InsDel_CellBottomSmall:     rSh.SetColRowWidthHeight( nsTableChgWidthHeightType::WH_FLAG_INSDEL|nsTableChgWidthHeightType::WH_CELL_BOTTOM, pModOpt->GetTableVInsert() );  break;
    2614             : 
    2615             :             case KS_TableColCellInsDel:
    2616           0 :                 rSh.SetColRowWidthHeight( eTableChgMode, nTableChgSize );
    2617           0 :                 break;
    2618             :             case KS_Fly_Change:
    2619             :             {
    2620           0 :                 SdrView *pSdrView = rSh.GetDrawView();
    2621           0 :                 const SdrHdlList& rHdlList = pSdrView->GetHdlList();
    2622           0 :                 if(rHdlList.GetFocusHdl())
    2623           0 :                     ChangeDrawing( nDir );
    2624             :                 else
    2625           0 :                     ChangeFly( nDir, m_rView.ISA( SwWebView ) );
    2626             :             }
    2627           0 :             break;
    2628             :             case KS_Draw_Change :
    2629           0 :                 ChangeDrawing( nDir );
    2630           0 :                 break;
    2631             :             default:
    2632           0 :                 break;
    2633             :             }
    2634           0 :             if( nSlotId && m_rView.GetViewFrame()->GetBindings().GetRecorder().is() )
    2635             :             {
    2636           0 :                 SfxRequest aReq(m_rView.GetViewFrame(), nSlotId );
    2637           0 :                 aReq.Done();
    2638             :             }
    2639           0 :             eKeyState = KS_End;
    2640             :         }
    2641             :         }
    2642             :     }
    2643             : 
    2644           1 :     if( bStopKeyInputTimer )
    2645             :     {
    2646           1 :         m_aKeyInputTimer.Stop();
    2647           1 :         m_bTableInsDelMode = false;
    2648             :     }
    2649             : 
    2650             :     // in case the buffered characters are inserted
    2651           1 :     if( bFlushBuffer && !m_aInBuffer.isEmpty() )
    2652             :     {
    2653             :         // bFlushCharBuffer was not resetted here
    2654             :         // why not?
    2655           1 :         bool bSave = g_bFlushCharBuffer;
    2656           1 :         FlushInBuffer();
    2657           1 :         g_bFlushCharBuffer = bSave;
    2658             : 
    2659             :         // maybe show Tip-Help
    2660           1 :         OUString sWord;
    2661           3 :         if( bNormalChar && pACfg && pACorr &&
    2662           2 :             ( pACfg->IsAutoTextTip() ||
    2663           2 :               pACorr->GetSwFlags().bAutoCompleteWords ) &&
    2664           0 :             rSh.GetPrevAutoCorrWord( *pACorr, sWord ) )
    2665             :         {
    2666           0 :             ShowAutoTextCorrectQuickHelp(sWord, pACfg, pACorr);
    2667           1 :         }
    2668             :     }
    2669             : 
    2670             :     // get the word count dialog to update itself
    2671           1 :     SwWordCountWrapper *pWrdCnt = static_cast<SwWordCountWrapper*>(GetView().GetViewFrame()->GetChildWindow(SwWordCountWrapper::GetChildWindowId()));
    2672           1 :     if( pWrdCnt )
    2673           1 :         pWrdCnt->UpdateCounts();
    2674             : 
    2675             : }
    2676             : 
    2677             : /**
    2678             :  * MouseEvents
    2679             :  */
    2680           0 : void SwEditWin::RstMBDownFlags()
    2681             : {
    2682             :     // Not on all systems a MouseButtonUp is used ahead
    2683             :     // of the modal dialog (like on WINDOWS).
    2684             :     // So reset the statuses here and release the mouse
    2685             :     // for the dialog.
    2686           0 :     m_bMBPressed = false;
    2687           0 :     g_bNoInterrupt = false;
    2688           0 :     EnterArea();
    2689           0 :     ReleaseMouse();
    2690           0 : }
    2691             : 
    2692             : /**
    2693             :  * Determines if the current position has a clickable url over a background
    2694             :  * frame. In that case, ctrl-click should select the url, not the frame.
    2695             :  */
    2696           0 : static bool lcl_urlOverBackground(SwWrtShell& rSh, const Point& rDocPos)
    2697             : {
    2698           0 :     SwContentAtPos aSwContentAtPos(SwContentAtPos::SW_INETATTR);
    2699           0 :     SdrObject* pSelectableObj = rSh.GetObjAt(rDocPos);
    2700             : 
    2701           0 :     return rSh.GetContentAtPos(rDocPos, aSwContentAtPos) && pSelectableObj->GetLayer() == rSh.GetDoc()->getIDocumentDrawModelAccess().GetHellId();
    2702             : }
    2703             : 
    2704           1 : void SwEditWin::MoveCursor( SwWrtShell &rSh, const Point& rDocPos,
    2705             :                             const bool bOnlyText, bool bLockView )
    2706             : {
    2707           1 :     const bool bTmpNoInterrupt = g_bNoInterrupt;
    2708           1 :     g_bNoInterrupt = false;
    2709             : 
    2710           1 :     int nTmpSetCrsr = 0;
    2711             : 
    2712           1 :     if( !rSh.IsViewLocked() && bLockView )
    2713           0 :         rSh.LockView( true );
    2714             :     else
    2715           1 :         bLockView = false;
    2716             : 
    2717             :     {
    2718             :         // only temporary generate move context because otherwise
    2719             :         // the query to the content form doesn't work!!!
    2720           1 :         SwMvContext aMvContext( &rSh );
    2721           1 :         nTmpSetCrsr = rSh.SetCursor(&rDocPos, bOnlyText);
    2722           1 :         g_bValidCrsrPos = !(CRSR_POSCHG & nTmpSetCrsr);
    2723             :     }
    2724             : 
    2725             :     // notify the edit window that from now on we do not use the input language
    2726           1 :     if ( !(CRSR_POSOLD & nTmpSetCrsr) )
    2727           1 :         SetUseInputLanguage( false );
    2728             : 
    2729           1 :     if( bLockView )
    2730           0 :         rSh.LockView( false );
    2731             : 
    2732           1 :     g_bNoInterrupt = bTmpNoInterrupt;
    2733           1 : }
    2734             : 
    2735           2 : void SwEditWin::MouseButtonDown(const MouseEvent& _rMEvt)
    2736             : {
    2737           2 :     SwWrtShell &rSh = m_rView.GetWrtShell();
    2738           2 :     const SwField *pCrsrField = rSh.CrsrInsideInputField() ? rSh.GetCurField( true ) : NULL;
    2739             : 
    2740             :     // We have to check if a context menu is shown and we have an UI
    2741             :     // active inplace client. In that case we have to ignore the mouse
    2742             :     // button down event. Otherwise we would crash (context menu has been
    2743             :     // opened by inplace client and we would deactivate the inplace client,
    2744             :     // the contex menu is closed by VCL asynchronously which in the end
    2745             :     // would work on deleted objects or the context menu has no parent anymore)
    2746           2 :     SfxInPlaceClient* pIPClient = rSh.GetSfxViewShell()->GetIPClient();
    2747           2 :     bool bIsOleActive = ( pIPClient && pIPClient->IsObjectInPlaceActive() );
    2748             : 
    2749           2 :     if ( bIsOleActive && PopupMenu::IsInExecute() )
    2750           1 :         return;
    2751             : 
    2752           2 :     MouseEvent rMEvt(_rMEvt);
    2753             : 
    2754           2 :     if (m_rView.GetPostItMgr()->IsHit(rMEvt.GetPosPixel()))
    2755           0 :         return;
    2756             : 
    2757           2 :     m_rView.GetPostItMgr()->SetActiveSidebarWin(0);
    2758             : 
    2759           2 :     GrabFocus();
    2760             : 
    2761             :     //ignore key modifiers for format paintbrush
    2762             :     {
    2763           0 :         bool bExecFormatPaintbrush = m_pApplyTempl && m_pApplyTempl->m_pFormatClipboard
    2764           2 :                                 &&  m_pApplyTempl->m_pFormatClipboard->HasContent();
    2765           2 :         if( bExecFormatPaintbrush )
    2766           0 :             rMEvt = MouseEvent( _rMEvt.GetPosPixel(), _rMEvt.GetClicks(),
    2767           0 :                                     _rMEvt.GetMode(), _rMEvt.GetButtons() );
    2768             :     }
    2769             : 
    2770           2 :     m_bWasShdwCrsr = 0 != m_pShadCrsr;
    2771           2 :     delete m_pShadCrsr, m_pShadCrsr = 0;
    2772             : 
    2773           2 :     const Point aDocPos( PixelToLogic( rMEvt.GetPosPixel() ) );
    2774             : 
    2775             :     // How many clicks do we need to select a fly frame?
    2776             :     FrameControlType eControl;
    2777           2 :     bool bOverFly = false;
    2778           2 :     bool bPageAnchored = false;
    2779           2 :     bool bOverHeaderFooterFly = IsOverHeaderFooterFly( aDocPos, eControl, bOverFly, bPageAnchored );
    2780             : 
    2781           2 :     bool bIsDocReadOnly = m_rView.GetDocShell()->IsReadOnly();
    2782           2 :     if (bOverHeaderFooterFly && (!bIsDocReadOnly && rSh.GetCurField()))
    2783             :         // We have a field here, that should have priority over header/footer fly.
    2784           0 :         bOverHeaderFooterFly = false;
    2785             : 
    2786           2 :     int nNbFlyClicks = 1;
    2787             :     // !bOverHeaderFooterFly doesn't mean we have a frame to select
    2788           4 :     if ( !bPageAnchored && ( ( rSh.IsHeaderFooterEdit( ) && !bOverHeaderFooterFly && bOverFly ) ||
    2789           4 :          ( !rSh.IsHeaderFooterEdit( ) && bOverHeaderFooterFly ) ) )
    2790             :     {
    2791           0 :         nNbFlyClicks = 2;
    2792           0 :         if ( _rMEvt.GetClicks( ) < nNbFlyClicks )
    2793           0 :             return;
    2794             :     }
    2795             : 
    2796             :     // Are we clicking on a blank header/footer area?
    2797           2 :     if ( IsInHeaderFooter( aDocPos, eControl ) || bOverHeaderFooterFly )
    2798             :     {
    2799           0 :         const SwPageFrm* pPageFrm = rSh.GetLayout()->GetPageAtPos( aDocPos );
    2800             : 
    2801             :         // Is it active?
    2802           0 :         bool bActive = true;
    2803           0 :         const SwPageDesc* pDesc = pPageFrm->GetPageDesc();
    2804             : 
    2805           0 :         const SwFrameFormat* pFormat = pDesc->GetLeftFormat();
    2806           0 :         if ( pPageFrm->OnRightPage() )
    2807           0 :              pFormat = pDesc->GetRightFormat();
    2808             : 
    2809           0 :         if ( pFormat )
    2810             :         {
    2811           0 :             if ( eControl == Header )
    2812           0 :                 bActive = pFormat->GetHeader().IsActive();
    2813             :             else
    2814           0 :                 bActive = pFormat->GetFooter().IsActive();
    2815             :         }
    2816             : 
    2817           0 :         if ( !bActive )
    2818             :         {
    2819           0 :             SwPaM aPam( *rSh.GetCurrentShellCursor().GetPoint() );
    2820           0 :             bool bWasInHeader = aPam.GetPoint( )->nNode.GetNode( ).FindHeaderStartNode( ) != NULL;
    2821           0 :             bool bWasInFooter = aPam.GetPoint( )->nNode.GetNode( ).FindFooterStartNode( ) != NULL;
    2822             : 
    2823             :             // Is the cursor in a part like similar to the one we clicked on? For example,
    2824             :             // if the cursor is in a header and we click on an empty header... don't change anything to
    2825             :             // keep consistent behaviour due to header edit mode (and the same for the footer as well).
    2826             : 
    2827             :             // Otherwise, we hide the header/footer control if a separator is shown, and vice versa.
    2828           0 :             if ( !( bWasInHeader && eControl == Header ) &&
    2829           0 :                  !( bWasInFooter && eControl == Footer ) )
    2830             :             {
    2831           0 :                 rSh.SetShowHeaderFooterSeparator( eControl, !rSh.IsShowHeaderFooterSeparator( eControl ) );
    2832             :             }
    2833             : 
    2834             :             // Repaint everything
    2835           0 :             Invalidate();
    2836             :         }
    2837             :         else
    2838             :         {
    2839             :             // Make sure we have the proper Header/Footer separators shown
    2840             :             // as these may be changed if clicking on an empty Header/Footer
    2841           0 :             rSh.SetShowHeaderFooterSeparator( Header, eControl == Header );
    2842           0 :             rSh.SetShowHeaderFooterSeparator( Footer, eControl == Footer );
    2843             : 
    2844           0 :             if ( !rSh.IsHeaderFooterEdit() )
    2845           0 :                 rSh.ToggleHeaderFooterEdit();
    2846             : 
    2847             :             // Repaint everything
    2848           0 :             rSh.GetWin()->Invalidate();
    2849             :         }
    2850             :     }
    2851             :     else
    2852             :     {
    2853           2 :         if ( rSh.IsHeaderFooterEdit( ) )
    2854           0 :             rSh.ToggleHeaderFooterEdit( );
    2855             :         else
    2856             :         {
    2857             :             // Make sure that the separators are hidden
    2858           2 :             rSh.SetShowHeaderFooterSeparator( Header, false );
    2859           2 :             rSh.SetShowHeaderFooterSeparator( Footer, false );
    2860             : 
    2861             :             // Repaint everything
    2862             :             // FIXME fdo#67358 for unknown reasons this causes painting
    2863             :             // problems when resizing table columns, so disable it
    2864             : //            rSh.GetWin()->Invalidate();
    2865             :         }
    2866             :     }
    2867             : 
    2868           2 :     if ( IsChainMode() )
    2869             :     {
    2870           0 :         SetChainMode( false );
    2871           0 :         SwRect aDummy;
    2872           0 :         SwFlyFrameFormat *pFormat = static_cast<SwFlyFrameFormat*>(rSh.GetFlyFrameFormat());
    2873           0 :         if ( rSh.Chainable( aDummy, *pFormat, aDocPos ) == SwChainRet::OK )
    2874           0 :             rSh.Chain( *pFormat, aDocPos );
    2875           0 :         UpdatePointer( aDocPos, rMEvt.GetModifier() );
    2876           0 :         return;
    2877             :     }
    2878             : 
    2879             :     // After GrabFocus a shell should be pushed. That should actually
    2880             :     // work but in practice ...
    2881           2 :     m_rView.SelectShellForDrop();
    2882             : 
    2883           2 :     bool bCallBase = true;
    2884             : 
    2885           2 :     if( m_pQuickHlpData->m_bIsDisplayed )
    2886           0 :         m_pQuickHlpData->Stop( rSh );
    2887           2 :     m_pQuickHlpData->m_bAppendSpace = false;
    2888             : 
    2889           2 :     if( rSh.FinishOLEObj() )
    2890           0 :         return; // end InPlace and the click doesn't count anymore
    2891             : 
    2892           2 :     SET_CURR_SHELL( &rSh );
    2893             : 
    2894           2 :     SdrView *pSdrView = rSh.GetDrawView();
    2895           2 :     if ( pSdrView )
    2896             :     {
    2897           2 :         if (pSdrView->MouseButtonDown( rMEvt, this ) )
    2898             :         {
    2899           0 :             rSh.GetView().GetViewFrame()->GetBindings().InvalidateAll(false);
    2900           0 :             return; // SdrView's event evaluated
    2901             :         }
    2902             :     }
    2903             : 
    2904           2 :     m_bIsInMove = false;
    2905           2 :     m_aStartPos = rMEvt.GetPosPixel();
    2906           2 :     m_aRszMvHdlPt.X() = 0, m_aRszMvHdlPt.Y() = 0;
    2907             : 
    2908           2 :     SwTab nMouseTabCol = SwTab::COL_NONE;
    2909           6 :     const bool bTmp = !rSh.IsDrawCreate() && !m_pApplyTempl && !rSh.IsInSelect() &&
    2910           6 :          rMEvt.GetClicks() == 1 && MOUSE_LEFT == rMEvt.GetButtons();
    2911           4 :     if (  bTmp &&
    2912           2 :          SwTab::COL_NONE != (nMouseTabCol = rSh.WhichMouseTabCol( aDocPos ) ) &&
    2913           0 :          !rSh.IsObjSelectable( aDocPos ) )
    2914             :     {
    2915             :         // Enhanced table selection
    2916           0 :         if ( SwTab::SEL_HORI <= nMouseTabCol && SwTab::COLSEL_VERT >= nMouseTabCol )
    2917             :         {
    2918           0 :             rSh.EnterStdMode();
    2919           0 :             rSh.SelectTableRowCol( aDocPos );
    2920           0 :             if( SwTab::SEL_HORI  != nMouseTabCol && SwTab::SEL_HORI_RTL  != nMouseTabCol)
    2921             :             {
    2922           0 :                 m_pRowColumnSelectionStart = new Point( aDocPos );
    2923           0 :                 m_bIsRowDrag = SwTab::ROWSEL_HORI == nMouseTabCol||
    2924           0 :                             SwTab::ROWSEL_HORI_RTL == nMouseTabCol ||
    2925           0 :                             SwTab::COLSEL_VERT == nMouseTabCol;
    2926           0 :                 m_bMBPressed = true;
    2927           0 :                 CaptureMouse();
    2928             :             }
    2929           0 :             return;
    2930             :         }
    2931             : 
    2932           0 :         if ( !rSh.IsTableMode() )
    2933             :         {
    2934             :             // comes from table columns out of the document.
    2935           0 :             if(SwTab::COL_VERT == nMouseTabCol || SwTab::COL_HORI == nMouseTabCol)
    2936           0 :                 m_rView.SetTabColFromDoc( true );
    2937             :             else
    2938           0 :                 m_rView.SetTabRowFromDoc( true );
    2939             : 
    2940           0 :             m_rView.SetTabColFromDocPos( aDocPos );
    2941           0 :             m_rView.InvalidateRulerPos();
    2942           0 :             SfxBindings& rBind = m_rView.GetViewFrame()->GetBindings();
    2943           0 :             rBind.Update();
    2944           0 :             if ( RulerColumnDrag( rMEvt,
    2945           0 :                     (SwTab::COL_VERT == nMouseTabCol || SwTab::ROW_HORI == nMouseTabCol)) )
    2946             :             {
    2947           0 :                 m_rView.SetTabColFromDoc( false );
    2948           0 :                 m_rView.SetTabRowFromDoc( false );
    2949           0 :                 m_rView.InvalidateRulerPos();
    2950           0 :                 rBind.Update();
    2951           0 :                 bCallBase = false;
    2952             :             }
    2953             :             else
    2954             :             {
    2955           0 :                 return;
    2956             :             }
    2957             :         }
    2958             :     }
    2959           4 :     else if (bTmp &&
    2960           2 :              rSh.IsNumLabel(aDocPos))
    2961             :     {
    2962           0 :         SwTextNode* pNodeAtPos = rSh.GetNumRuleNodeAtPos( aDocPos );
    2963           0 :         m_rView.SetNumRuleNodeFromDoc( pNodeAtPos );
    2964           0 :         m_rView.InvalidateRulerPos();
    2965           0 :         SfxBindings& rBind = m_rView.GetViewFrame()->GetBindings();
    2966           0 :         rBind.Update();
    2967             : 
    2968           0 :         if ( RulerMarginDrag( rMEvt,
    2969           0 :                         SwFEShell::IsVerticalModeAtNdAndPos( *pNodeAtPos, aDocPos ) ) )
    2970             :         {
    2971           0 :             m_rView.SetNumRuleNodeFromDoc( NULL );
    2972           0 :             m_rView.InvalidateRulerPos();
    2973           0 :             rBind.Update();
    2974           0 :             bCallBase = false;
    2975             :         }
    2976             :         else
    2977             :         {
    2978             :             // Make sure the pointer is set to 0, otherwise it may point to
    2979             :             // nowhere after deleting the corresponding text node.
    2980           0 :             m_rView.SetNumRuleNodeFromDoc( NULL );
    2981           0 :             return;
    2982             :         }
    2983             :     }
    2984             : 
    2985           2 :     if ( rSh.IsInSelect() )
    2986           0 :         rSh.EndSelect();
    2987             : 
    2988             :     // query against LEFT because otherwise for example also a right
    2989             :     // click releases the selection.
    2990           2 :     if ( MOUSE_LEFT == rMEvt.GetButtons() )
    2991             :     {
    2992           2 :         bool bOnlyText = false;
    2993           2 :         m_bMBPressed = true;
    2994           2 :         g_bNoInterrupt = true;
    2995           2 :         m_nKS_NUMDOWN_Count = 0;
    2996             : 
    2997           2 :         CaptureMouse();
    2998             : 
    2999             :         // reset cursor position if applicable
    3000           2 :         rSh.ResetCursorStack();
    3001             : 
    3002           2 :         switch ( rMEvt.GetModifier() + rMEvt.GetButtons() )
    3003             :         {
    3004             :             case MOUSE_LEFT:
    3005             :             case MOUSE_LEFT + KEY_SHIFT:
    3006             :             case MOUSE_LEFT + KEY_MOD2:
    3007           2 :                 if( rSh.IsObjSelected() )
    3008             :                 {
    3009             :                     SdrHdl* pHdl;
    3010           3 :                     if( !bIsDocReadOnly &&
    3011           2 :                         !m_pAnchorMarker &&
    3012           1 :                         pSdrView &&
    3013           3 :                         0 != ( pHdl = pSdrView->PickHandle(aDocPos) ) &&
    3014           2 :                             ( pHdl->GetKind() == HDL_ANCHOR ||
    3015           1 :                               pHdl->GetKind() == HDL_ANCHOR_TR ) )
    3016             :                     {
    3017             :                         // #i121463# Set selected during drag
    3018           0 :                         pHdl->SetSelected(true);
    3019           0 :                         m_pAnchorMarker = new SwAnchorMarker( pHdl );
    3020           0 :                         UpdatePointer( aDocPos, rMEvt.GetModifier() );
    3021           0 :                         return;
    3022             :                     }
    3023             :                 }
    3024           2 :                 if ( EnterDrawMode( rMEvt, aDocPos ) )
    3025             :                 {
    3026           0 :                     g_bNoInterrupt = false;
    3027           0 :                     return;
    3028             :                 }
    3029           2 :                 else  if ( m_rView.GetDrawFuncPtr() && m_bInsFrm )
    3030             :                 {
    3031           0 :                     StopInsFrm();
    3032           0 :                     rSh.Edit();
    3033             :                 }
    3034             : 
    3035             :                 // Without SHIFT because otherwise Toggle doesn't work at selection
    3036           2 :                 if (rMEvt.GetClicks() == 1)
    3037             :                 {
    3038           2 :                     if ( rSh.IsSelFrmMode())
    3039             :                     {
    3040           0 :                         SdrHdl* pHdl = rSh.GetDrawView()->PickHandle(aDocPos);
    3041           0 :                         bool bHitHandle = pHdl && pHdl->GetKind() != HDL_ANCHOR &&
    3042           0 :                                                   pHdl->GetKind() != HDL_ANCHOR_TR;
    3043             : 
    3044           0 :                         if ((rSh.IsInsideSelectedObj(aDocPos) || bHitHandle) &&
    3045           0 :                             !(rMEvt.GetModifier() == KEY_SHIFT && !bHitHandle))
    3046             :                         {
    3047           0 :                             rSh.EnterSelFrmMode( &aDocPos );
    3048           0 :                             if ( !m_pApplyTempl )
    3049             :                             {
    3050             :                                 // only if no position to size was hit.
    3051           0 :                                 if (!bHitHandle)
    3052             :                                 {
    3053           0 :                                     StartDDTimer();
    3054           0 :                                     SwEditWin::m_nDDStartPosY = aDocPos.Y();
    3055           0 :                                     SwEditWin::m_nDDStartPosX = aDocPos.X();
    3056             :                                 }
    3057           0 :                                 g_bFrmDrag = true;
    3058             :                             }
    3059           0 :                             g_bNoInterrupt = false;
    3060           0 :                             return;
    3061             :                         }
    3062             :                     }
    3063             :                 }
    3064             :         }
    3065             : 
    3066           2 :         bool bExecHyperlinks = m_rView.GetDocShell()->IsReadOnly();
    3067           2 :         if ( !bExecHyperlinks )
    3068             :         {
    3069           2 :             SvtSecurityOptions aSecOpts;
    3070           2 :             const bool bSecureOption = aSecOpts.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK );
    3071           4 :             if ( (  bSecureOption && rMEvt.GetModifier() == KEY_MOD1 ) ||
    3072           2 :                  ( !bSecureOption && rMEvt.GetModifier() != KEY_MOD1 ) )
    3073           0 :                 bExecHyperlinks = true;
    3074             :         }
    3075             : 
    3076             :         // Enhanced selection
    3077           2 :         sal_uInt8 nNumberOfClicks = static_cast< sal_uInt8 >(rMEvt.GetClicks() % 4);
    3078           2 :         if ( 0 == nNumberOfClicks && 0 < rMEvt.GetClicks() )
    3079           0 :             nNumberOfClicks = 4;
    3080             : 
    3081           2 :         bool bExecDrawTextLink = false;
    3082             : 
    3083           2 :         switch ( rMEvt.GetModifier() + rMEvt.GetButtons() )
    3084             :         {
    3085             :             case MOUSE_LEFT:
    3086             :             case MOUSE_LEFT + KEY_MOD1:
    3087             :             case MOUSE_LEFT + KEY_MOD2:
    3088             :             {
    3089             : 
    3090             :                 // fdo#79604: first, check if a link has been clicked - do not
    3091             :                 // select fly in this case!
    3092           2 :                 if (1 == nNumberOfClicks)
    3093             :                 {
    3094           2 :                     UpdatePointer( aDocPos, rMEvt.GetModifier() );
    3095           2 :                     SwEditWin::m_nDDStartPosY = aDocPos.Y();
    3096           2 :                     SwEditWin::m_nDDStartPosX = aDocPos.X();
    3097             : 
    3098             :                     // hit an URL in DrawText object?
    3099           2 :                     if (bExecHyperlinks && pSdrView)
    3100             :                     {
    3101           0 :                         SdrViewEvent aVEvt;
    3102           0 :                         pSdrView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
    3103             : 
    3104           0 :                         if (aVEvt.eEvent == SDREVENT_EXECUTEURL)
    3105           0 :                             bExecDrawTextLink = true;
    3106             :                     }
    3107             :                 }
    3108             : 
    3109           2 :                 bool bHandledFlyClick = false;
    3110           2 :                 if (!bExecDrawTextLink && nNumberOfClicks == nNbFlyClicks)
    3111             :                 {
    3112           2 :                     bHandledFlyClick = true;
    3113             :                     // only try to select frame, if pointer already was
    3114             :                     // switched accordingly
    3115           6 :                     if ( m_aActHitType != SDRHIT_NONE && !rSh.IsSelFrmMode() &&
    3116           4 :                         !GetView().GetViewFrame()->GetDispatcher()->IsLocked() &&
    3117           1 :                         !bExecDrawTextLink)
    3118             :                     {
    3119             :                         // Test if there is a draw object at that position and if it should be selected.
    3120           1 :                         bool bShould = rSh.ShouldObjectBeSelected(aDocPos);
    3121             : 
    3122           1 :                         if(bShould)
    3123             :                         {
    3124           1 :                             m_rView.NoRotate();
    3125           1 :                             rSh.HideCrsr();
    3126             : 
    3127           1 :                             bool bUnLockView = !rSh.IsViewLocked();
    3128           1 :                             rSh.LockView( true );
    3129             :                             bool bSelObj = rSh.SelectObj( aDocPos,
    3130           1 :                                            rMEvt.IsMod1() ? SW_ENTER_GROUP : 0);
    3131           1 :                             if( bUnLockView )
    3132           1 :                                 rSh.LockView( false );
    3133             : 
    3134           1 :                             if( bSelObj )
    3135             :                             {
    3136             :                                 // if the frame was deselected in the macro
    3137             :                                 // the cursor just has to be displayed again
    3138           1 :                                 if( FrmTypeFlags::NONE == rSh.GetSelFrmType() )
    3139           0 :                                     rSh.ShowCrsr();
    3140             :                                 else
    3141             :                                 {
    3142           1 :                                     if (rSh.IsFrmSelected() && m_rView.GetDrawFuncPtr())
    3143             :                                     {
    3144           0 :                                         m_rView.GetDrawFuncPtr()->Deactivate();
    3145           0 :                                         m_rView.SetDrawFuncPtr(NULL);
    3146           0 :                                         m_rView.LeaveDrawCreate();
    3147           0 :                                         m_rView.AttrChangedNotify( &rSh );
    3148             :                                     }
    3149             : 
    3150           1 :                                     rSh.EnterSelFrmMode( &aDocPos );
    3151           1 :                                     g_bFrmDrag = true;
    3152           1 :                                     UpdatePointer( aDocPos, rMEvt.GetModifier() );
    3153             :                                 }
    3154           1 :                                 return;
    3155             :                             }
    3156             :                             else
    3157           0 :                                 bOnlyText = rSh.IsObjSelectable( aDocPos );
    3158             : 
    3159           0 :                             if (!m_rView.GetDrawFuncPtr())
    3160           0 :                                 rSh.ShowCrsr();
    3161             :                         }
    3162             :                         else
    3163           0 :                             bOnlyText = KEY_MOD1 != rMEvt.GetModifier();
    3164             :                     }
    3165           1 :                     else if ( rSh.IsSelFrmMode() &&
    3166           0 :                               (m_aActHitType == SDRHIT_NONE ||
    3167           0 :                                !rSh.IsInsideSelectedObj( aDocPos )))
    3168             :                     {
    3169           0 :                         m_rView.NoRotate();
    3170             :                         SdrHdl *pHdl;
    3171           0 :                         if( !bIsDocReadOnly && !m_pAnchorMarker && 0 !=
    3172           0 :                             ( pHdl = pSdrView->PickHandle(aDocPos) ) &&
    3173           0 :                                 ( pHdl->GetKind() == HDL_ANCHOR ||
    3174           0 :                                   pHdl->GetKind() == HDL_ANCHOR_TR ) )
    3175             :                         {
    3176           0 :                             m_pAnchorMarker = new SwAnchorMarker( pHdl );
    3177           0 :                             UpdatePointer( aDocPos, rMEvt.GetModifier() );
    3178           0 :                             return;
    3179             :                         }
    3180             :                         else
    3181             :                         {
    3182           0 :                             bool bUnLockView = !rSh.IsViewLocked();
    3183           0 :                             rSh.LockView( true );
    3184           0 :                             sal_uInt8 nFlag = rMEvt.IsShift() ? SW_ADD_SELECT :0;
    3185           0 :                             if( rMEvt.IsMod1() )
    3186           0 :                                 nFlag = nFlag | SW_ENTER_GROUP;
    3187             : 
    3188           0 :                             if ( rSh.IsSelFrmMode() )
    3189             :                             {
    3190           0 :                                 rSh.UnSelectFrm();
    3191           0 :                                 rSh.LeaveSelFrmMode();
    3192           0 :                                 m_rView.AttrChangedNotify(&rSh);
    3193             :                             }
    3194             : 
    3195           0 :                             bool bSelObj = rSh.SelectObj( aDocPos, nFlag );
    3196           0 :                             if( bUnLockView )
    3197           0 :                                 rSh.LockView( false );
    3198             : 
    3199           0 :                             if( !bSelObj )
    3200             :                             {
    3201             :                                 // move cursor here so that it is not drawn in the
    3202             :                                 // frame first; ShowCrsr() happens in LeaveSelFrmMode()
    3203           0 :                                 g_bValidCrsrPos = !(CRSR_POSCHG & rSh.SetCursor(&aDocPos, false));
    3204           0 :                                 rSh.LeaveSelFrmMode();
    3205           0 :                                 m_rView.AttrChangedNotify( &rSh );
    3206           0 :                                 bCallBase = false;
    3207             :                             }
    3208             :                             else
    3209             :                             {
    3210           0 :                                 rSh.HideCrsr();
    3211           0 :                                 rSh.EnterSelFrmMode( &aDocPos );
    3212           0 :                                 rSh.SelFlyGrabCrsr();
    3213           0 :                                 rSh.MakeSelVisible();
    3214           0 :                                 g_bFrmDrag = true;
    3215           0 :                                 if( rSh.IsFrmSelected() &&
    3216           0 :                                     m_rView.GetDrawFuncPtr() )
    3217             :                                 {
    3218           0 :                                     m_rView.GetDrawFuncPtr()->Deactivate();
    3219           0 :                                     m_rView.SetDrawFuncPtr(NULL);
    3220           0 :                                     m_rView.LeaveDrawCreate();
    3221           0 :                                     m_rView.AttrChangedNotify( &rSh );
    3222             :                                 }
    3223           0 :                                 UpdatePointer( aDocPos, rMEvt.GetModifier() );
    3224           0 :                                 return;
    3225             :                             }
    3226             :                         }
    3227             :                     }
    3228             :                 }
    3229             : 
    3230           1 :                 switch ( nNumberOfClicks )
    3231             :                 {
    3232             :                     case 1:
    3233           1 :                         break;
    3234             :                     case 2:
    3235             :                     {
    3236           0 :                         g_bFrmDrag = false;
    3237           0 :                         if ( !bHandledFlyClick && !bIsDocReadOnly && rSh.IsInsideSelectedObj(aDocPos) &&
    3238           0 :                              FlyProtectFlags::NONE == rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) )
    3239             :                         {
    3240             :                         /* This is no good: on the one hand GetSelectionType is used as flag field
    3241             :                          * (take a look into the GetSelectionType method) and on the other hand the
    3242             :                          * return value is used in a switch without proper masking (very nice), this must lead to trouble
    3243             :                          */
    3244           0 :                             switch ( rSh.GetSelectionType() &~ ( nsSelectionType::SEL_FONTWORK | nsSelectionType::SEL_EXTRUDED_CUSTOMSHAPE ) )
    3245             :                             {
    3246             :                             case nsSelectionType::SEL_GRF:
    3247           0 :                                 RstMBDownFlags();
    3248           0 :                                 if (!rSh.isTiledRendering())
    3249             :                                 {
    3250           0 :                                     GetView().GetViewFrame()->GetBindings().Execute(
    3251             :                                         FN_FORMAT_GRAFIC_DLG, 0, 0,
    3252           0 :                                         SfxCallMode::RECORD|SfxCallMode::SLOT);
    3253             :                                 }
    3254           0 :                                 return;
    3255             : 
    3256             :                             // double click on OLE object --> OLE-InPlace
    3257             :                             case nsSelectionType::SEL_OLE:
    3258           0 :                                 if (rSh.IsSelObjProtected(FlyProtectFlags::Content) == FlyProtectFlags::NONE)
    3259             :                                 {
    3260           0 :                                     RstMBDownFlags();
    3261           0 :                                     rSh.LaunchOLEObj();
    3262             :                                 }
    3263           0 :                                 return;
    3264             : 
    3265             :                             case nsSelectionType::SEL_FRM:
    3266           0 :                                 RstMBDownFlags();
    3267           0 :                                 if (!rSh.isTiledRendering())
    3268             :                                 {
    3269           0 :                                     GetView().GetViewFrame()->GetBindings().Execute(
    3270             :                                         FN_FORMAT_FRAME_DLG, 0, 0,
    3271           0 :                                         SfxCallMode::RECORD|SfxCallMode::SLOT);
    3272             :                                 }
    3273           0 :                                 return;
    3274             : 
    3275             :                             case nsSelectionType::SEL_DRW:
    3276           0 :                                 RstMBDownFlags();
    3277           0 :                                 EnterDrawTextMode(aDocPos);
    3278           0 :                                 if ( m_rView.GetCurShell()->ISA(SwDrawTextShell) )
    3279           0 :                                     static_cast<SwDrawTextShell*>(m_rView.GetCurShell())->Init();
    3280           0 :                                 return;
    3281             :                             }
    3282             :                         }
    3283             : 
    3284             :                         // if the cursor position was corrected or if a Fly
    3285             :                         // was selected in ReadOnlyMode, no word selection, except when tiled rendering.
    3286           0 :                         if ((!g_bValidCrsrPos || rSh.IsFrmSelected()) && !rSh.isTiledRendering())
    3287           0 :                             return;
    3288             : 
    3289             :                         SwField *pField;
    3290           0 :                         bool bFootnote = false;
    3291             : 
    3292           0 :                         if( !bIsDocReadOnly &&
    3293           0 :                             ( 0 != ( pField = rSh.GetCurField() ) ||
    3294           0 :                               ( bFootnote = rSh.GetCurFootnote() )        ) )
    3295             :                         {
    3296           0 :                             RstMBDownFlags();
    3297           0 :                             if( bFootnote )
    3298           0 :                                 GetView().GetViewFrame()->GetBindings().Execute( FN_EDIT_FOOTNOTE );
    3299             :                             else
    3300             :                             {
    3301           0 :                                 sal_uInt16 nTypeId = pField->GetTypeId();
    3302           0 :                                 SfxViewFrame* pVFrame = GetView().GetViewFrame();
    3303           0 :                                 switch( nTypeId )
    3304             :                                 {
    3305             :                                 case TYP_POSTITFLD:
    3306             :                                 case TYP_SCRIPTFLD:
    3307             :                                 {
    3308             :                                     // if it's a Readonly region, status has to be enabled
    3309           0 :                                     sal_uInt16 nSlot = TYP_POSTITFLD == nTypeId ? FN_POSTIT : FN_JAVAEDIT;
    3310           0 :                                     SfxBoolItem aItem(nSlot, true);
    3311           0 :                                     pVFrame->GetBindings().SetState(aItem);
    3312           0 :                                     pVFrame->GetBindings().Execute(nSlot);
    3313           0 :                                     break;
    3314             :                                 }
    3315             :                                 case TYP_AUTHORITY :
    3316           0 :                                     pVFrame->GetBindings().Execute(FN_EDIT_AUTH_ENTRY_DLG);
    3317           0 :                                 break;
    3318             :                                 default:
    3319           0 :                                     pVFrame->GetBindings().Execute(FN_EDIT_FIELD);
    3320             :                                 }
    3321             :                             }
    3322           0 :                             return;
    3323             :                         }
    3324             :                         // in extended mode double and triple
    3325             :                         // click has no effect.
    3326           0 :                         if ( rSh.IsExtMode() || rSh.IsBlockMode() )
    3327           0 :                             return;
    3328             : 
    3329             :                         // select work, AdditionalMode if applicable
    3330           0 :                         if ( KEY_MOD1 == rMEvt.GetModifier() && !rSh.IsAddMode() )
    3331             :                         {
    3332           0 :                             rSh.EnterAddMode();
    3333           0 :                             rSh.SelWrd( &aDocPos );
    3334           0 :                             rSh.LeaveAddMode();
    3335             :                         }
    3336             :                         else
    3337             :                         {
    3338           0 :                             if (!rSh.SelWrd(&aDocPos) && rSh.isTiledRendering())
    3339             :                                 // Double click did not select any word: try to
    3340             :                                 // select the current cell in case we are in a
    3341             :                                 // table.
    3342           0 :                                 rSh.SelTableBox();
    3343             :                         }
    3344           0 :                         g_bHoldSelection = true;
    3345           0 :                         return;
    3346             :                     }
    3347             :                     case 3:
    3348             :                     case 4:
    3349             :                     {
    3350           0 :                         g_bFrmDrag = false;
    3351             :                         // in extended mode double and triple
    3352             :                         // click has no effect.
    3353           0 :                         if ( rSh.IsExtMode() )
    3354           0 :                             return;
    3355             : 
    3356             :                         // if the cursor position was corrected or if a Fly
    3357             :                         // was selected in ReadOnlyMode, no word selection.
    3358           0 :                         if ( !g_bValidCrsrPos || rSh.IsFrmSelected() )
    3359           0 :                             return;
    3360             : 
    3361             :                         // select line, AdditionalMode if applicable
    3362           0 :                         const bool bMod = KEY_MOD1 == rMEvt.GetModifier() &&
    3363           0 :                                          !rSh.IsAddMode();
    3364             : 
    3365           0 :                         if ( bMod )
    3366           0 :                             rSh.EnterAddMode();
    3367             : 
    3368             :                         // Enhanced selection
    3369           0 :                         if ( 3 == nNumberOfClicks )
    3370           0 :                             rSh.SelSentence( &aDocPos );
    3371             :                         else
    3372           0 :                             rSh.SelPara( &aDocPos );
    3373             : 
    3374           0 :                         if ( bMod )
    3375           0 :                             rSh.LeaveAddMode();
    3376             : 
    3377           0 :                         g_bHoldSelection = true;
    3378           0 :                         return;
    3379             :                     }
    3380             : 
    3381             :                     default:
    3382           0 :                         return;
    3383             :                 }
    3384             :             }
    3385             :             /* no break */
    3386             :             case MOUSE_LEFT + KEY_SHIFT:
    3387             :             case MOUSE_LEFT + KEY_SHIFT + KEY_MOD1:
    3388             :             {
    3389           1 :                 bool bLockView = m_bWasShdwCrsr;
    3390             : 
    3391           1 :                 switch ( rMEvt.GetModifier() )
    3392             :                 {
    3393             :                     case KEY_MOD1 + KEY_SHIFT:
    3394             :                     {
    3395           0 :                         if ( !m_bInsDraw && IsDrawObjSelectable( rSh, aDocPos ) )
    3396             :                         {
    3397           0 :                             m_rView.NoRotate();
    3398           0 :                             rSh.HideCrsr();
    3399           0 :                             if ( rSh.IsSelFrmMode() )
    3400           0 :                                 rSh.SelectObj(aDocPos, SW_ADD_SELECT | SW_ENTER_GROUP);
    3401             :                             else
    3402           0 :                             {   if ( rSh.SelectObj( aDocPos, SW_ADD_SELECT | SW_ENTER_GROUP ) )
    3403             :                                 {
    3404           0 :                                     rSh.EnterSelFrmMode( &aDocPos );
    3405           0 :                                     SwEditWin::m_nDDStartPosY = aDocPos.Y();
    3406           0 :                                     SwEditWin::m_nDDStartPosX = aDocPos.X();
    3407           0 :                                     g_bFrmDrag = true;
    3408           0 :                                     return;
    3409             :                                 }
    3410             :                             }
    3411             :                         }
    3412           0 :                         else if( rSh.IsSelFrmMode() &&
    3413           0 :                                  rSh.GetDrawView()->PickHandle( aDocPos ))
    3414             :                         {
    3415           0 :                             g_bFrmDrag = true;
    3416           0 :                             g_bNoInterrupt = false;
    3417           0 :                             return;
    3418             :                         }
    3419             :                     }
    3420           0 :                     break;
    3421             :                     case KEY_MOD1:
    3422           0 :                     if ( !bExecDrawTextLink )
    3423             :                     {
    3424           0 :                         if ( !m_bInsDraw && IsDrawObjSelectable( rSh, aDocPos ) && !lcl_urlOverBackground( rSh, aDocPos ) )
    3425             :                         {
    3426           0 :                             m_rView.NoRotate();
    3427           0 :                             rSh.HideCrsr();
    3428           0 :                             if ( rSh.IsSelFrmMode() )
    3429           0 :                                 rSh.SelectObj(aDocPos, SW_ENTER_GROUP);
    3430             :                             else
    3431           0 :                             {   if ( rSh.SelectObj( aDocPos, SW_ENTER_GROUP ) )
    3432             :                                 {
    3433           0 :                                     rSh.EnterSelFrmMode( &aDocPos );
    3434           0 :                                     SwEditWin::m_nDDStartPosY = aDocPos.Y();
    3435           0 :                                     SwEditWin::m_nDDStartPosX = aDocPos.X();
    3436           0 :                                     g_bFrmDrag = true;
    3437           0 :                                     return;
    3438             :                                 }
    3439             :                             }
    3440             :                         }
    3441           0 :                         else if( rSh.IsSelFrmMode() &&
    3442           0 :                                  rSh.GetDrawView()->PickHandle( aDocPos ))
    3443             :                         {
    3444           0 :                             g_bFrmDrag = true;
    3445           0 :                             g_bNoInterrupt = false;
    3446           0 :                             return;
    3447             :                         }
    3448             :                         else
    3449             :                         {
    3450           0 :                             if ( !rSh.IsAddMode() && !rSh.IsExtMode() && !rSh.IsBlockMode() )
    3451             :                             {
    3452           0 :                                 rSh.PushMode();
    3453           0 :                                 g_bModePushed = true;
    3454             : 
    3455           0 :                                 bool bUnLockView = !rSh.IsViewLocked();
    3456           0 :                                 rSh.LockView( true );
    3457           0 :                                 rSh.EnterAddMode();
    3458           0 :                                 if( bUnLockView )
    3459           0 :                                     rSh.LockView( false );
    3460             :                             }
    3461           0 :                             bCallBase = false;
    3462             :                         }
    3463             :                     }
    3464           0 :                     break;
    3465             :                     case KEY_MOD2:
    3466             :                     {
    3467           0 :                         if ( !rSh.IsAddMode() && !rSh.IsExtMode() && !rSh.IsBlockMode() )
    3468             :                         {
    3469           0 :                             rSh.PushMode();
    3470           0 :                             g_bModePushed = true;
    3471           0 :                             bool bUnLockView = !rSh.IsViewLocked();
    3472           0 :                             rSh.LockView( true );
    3473           0 :                             rSh.EnterBlockMode();
    3474           0 :                             if( bUnLockView )
    3475           0 :                                 rSh.LockView( false );
    3476             :                         }
    3477           0 :                         bCallBase = false;
    3478             :                     }
    3479           0 :                     break;
    3480             :                     case KEY_SHIFT:
    3481             :                     {
    3482           0 :                         if ( !m_bInsDraw && IsDrawObjSelectable( rSh, aDocPos ) )
    3483             :                         {
    3484           0 :                             m_rView.NoRotate();
    3485           0 :                             rSh.HideCrsr();
    3486           0 :                             if ( rSh.IsSelFrmMode() )
    3487             :                             {
    3488           0 :                                 rSh.SelectObj(aDocPos, SW_ADD_SELECT);
    3489             : 
    3490           0 :                                 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
    3491           0 :                                 if (rMarkList.GetMark(0) == NULL)
    3492             :                                 {
    3493           0 :                                     rSh.LeaveSelFrmMode();
    3494           0 :                                     m_rView.AttrChangedNotify(&rSh);
    3495           0 :                                     g_bFrmDrag = false;
    3496             :                                 }
    3497             :                             }
    3498             :                             else
    3499           0 :                             {   if ( rSh.SelectObj( aDocPos ) )
    3500             :                                 {
    3501           0 :                                     rSh.EnterSelFrmMode( &aDocPos );
    3502           0 :                                     SwEditWin::m_nDDStartPosY = aDocPos.Y();
    3503           0 :                                     SwEditWin::m_nDDStartPosX = aDocPos.X();
    3504           0 :                                     g_bFrmDrag = true;
    3505           0 :                                     return;
    3506             :                                 }
    3507             :                             }
    3508             :                         }
    3509             :                         else
    3510             :                         {
    3511           0 :                             if ( rSh.IsSelFrmMode() &&
    3512           0 :                                  rSh.IsInsideSelectedObj( aDocPos ) )
    3513             :                             {
    3514           0 :                                 rSh.EnterSelFrmMode( &aDocPos );
    3515           0 :                                 SwEditWin::m_nDDStartPosY = aDocPos.Y();
    3516           0 :                                 SwEditWin::m_nDDStartPosX = aDocPos.X();
    3517           0 :                                 g_bFrmDrag = true;
    3518           0 :                                 return;
    3519             :                             }
    3520           0 :                             if ( rSh.IsSelFrmMode() )
    3521             :                             {
    3522           0 :                                 rSh.UnSelectFrm();
    3523           0 :                                 rSh.LeaveSelFrmMode();
    3524           0 :                                 m_rView.AttrChangedNotify(&rSh);
    3525           0 :                                 g_bFrmDrag = false;
    3526             :                             }
    3527           0 :                             if ( !rSh.IsExtMode() )
    3528             :                             {
    3529             :                                 // don't start a selection when an
    3530             :                                 // URL field or a graphic is clicked
    3531           0 :                                 bool bSttSelect = rSh.HasSelection() ||
    3532           0 :                                                 Pointer(PointerStyle::RefHand) != GetPointer();
    3533             : 
    3534           0 :                                 if( !bSttSelect )
    3535             :                                 {
    3536           0 :                                     bSttSelect = true;
    3537           0 :                                     if( bExecHyperlinks )
    3538             :                                     {
    3539             :                                         SwContentAtPos aContentAtPos(
    3540             :                                             SwContentAtPos::SW_FTN |
    3541           0 :                                             SwContentAtPos::SW_INETATTR );
    3542             : 
    3543           0 :                                         if( rSh.GetContentAtPos( aDocPos, aContentAtPos ) )
    3544             :                                         {
    3545           0 :                                             if( !rSh.IsViewLocked() &&
    3546           0 :                                                 !rSh.IsReadOnlyAvailable() &&
    3547           0 :                                                 aContentAtPos.IsInProtectSect() )
    3548           0 :                                                     bLockView = true;
    3549             : 
    3550           0 :                                             bSttSelect = false;
    3551             :                                         }
    3552           0 :                                         else if( rSh.IsURLGrfAtPos( aDocPos ))
    3553           0 :                                             bSttSelect = false;
    3554             :                                     }
    3555             :                                 }
    3556             : 
    3557           0 :                                 if( bSttSelect )
    3558           0 :                                     rSh.SttSelect();
    3559             :                             }
    3560             :                         }
    3561           0 :                         bCallBase = false;
    3562           0 :                         break;
    3563             :                     }
    3564             :                     default:
    3565           1 :                         if( !rSh.IsViewLocked() )
    3566             :                         {
    3567             :                             SwContentAtPos aContentAtPos( SwContentAtPos::SW_CLICKFIELD |
    3568           1 :                                                         SwContentAtPos::SW_INETATTR );
    3569           2 :                             if( rSh.GetContentAtPos( aDocPos, aContentAtPos, false ) &&
    3570           1 :                                 !rSh.IsReadOnlyAvailable() &&
    3571           0 :                                 aContentAtPos.IsInProtectSect() )
    3572           0 :                                 bLockView = true;
    3573             :                         }
    3574             :                 }
    3575             : 
    3576           1 :                 if ( rSh.IsGCAttr() )
    3577             :                 {
    3578           0 :                     rSh.GCAttr();
    3579           0 :                     rSh.ClearGCAttr();
    3580             :                 }
    3581             : 
    3582           1 :                 SwContentAtPos aFieldAtPos(SwContentAtPos::SW_FIELD);
    3583           1 :                 bool bEditableFieldClicked = false;
    3584             : 
    3585             :                 // Are we clicking on a field?
    3586           1 :                 if (rSh.GetContentAtPos(aDocPos, aFieldAtPos))
    3587             :                 {
    3588           0 :                     bool bEditableField = (aFieldAtPos.pFndTextAttr != NULL
    3589           0 :                         && aFieldAtPos.pFndTextAttr->Which() == RES_TXTATR_INPUTFIELD);
    3590             : 
    3591           0 :                     if (!bEditableField)
    3592             :                     {
    3593           0 :                         rSh.SetCursor(&aDocPos, bOnlyText);
    3594             :                         // Unfortunately the cursor may be on field
    3595             :                         // position or on position after field depending on which
    3596             :                         // half of the field was clicked on.
    3597           0 :                         SwTextAttr const*const pTextField(aFieldAtPos.pFndTextAttr);
    3598           0 :                         if (rSh.GetCurrentShellCursor().GetPoint()->nContent
    3599           0 :                                 .GetIndex() != pTextField->GetStart())
    3600             :                         {
    3601             :                             assert(rSh.GetCurrentShellCursor().GetPoint()->nContent
    3602             :                                     .GetIndex() == (pTextField->GetStart() + 1));
    3603           0 :                             rSh.Left( CRSR_SKIP_CHARS, false, 1, false );
    3604             :                         }
    3605             :                         // don't go into the !bOverSelect block below - it moves
    3606             :                         // the cursor
    3607           0 :                         break;
    3608             :                     }
    3609             :                     else
    3610             :                     {
    3611           0 :                         bEditableFieldClicked = true;
    3612             :                     }
    3613             :                 }
    3614             : 
    3615           1 :                 bool bOverSelect = rSh.ChgCurrPam( aDocPos ), bOverURLGrf = false;
    3616           1 :                 if( !bOverSelect )
    3617           1 :                     bOverURLGrf = bOverSelect = 0 != rSh.IsURLGrfAtPos( aDocPos );
    3618             : 
    3619           1 :                 if ( !bOverSelect )
    3620             :                 {
    3621           1 :                     MoveCursor( rSh, aDocPos, bOnlyText, bLockView );
    3622           1 :                     bCallBase = false;
    3623             :                 }
    3624           1 :                 if (!bOverURLGrf && !bExecDrawTextLink && !bOnlyText)
    3625             :                 {
    3626           1 :                     const int nSelType = rSh.GetSelectionType();
    3627             :                     // Check in general, if an object is selectable at given position.
    3628             :                     // Thus, also text fly frames in background become selectable via Ctrl-Click.
    3629           3 :                     if ( ( nSelType & nsSelectionType::SEL_OLE ||
    3630           2 :                          nSelType & nsSelectionType::SEL_GRF ||
    3631           2 :                          rSh.IsObjSelectable( aDocPos ) ) && !lcl_urlOverBackground( rSh, aDocPos ) )
    3632             :                     {
    3633           0 :                         SwMvContext aMvContext( &rSh );
    3634           0 :                         rSh.EnterSelFrmMode();
    3635           0 :                         bCallBase = false;
    3636             :                     }
    3637             :                 }
    3638           1 :                 if ( !bOverSelect && bEditableFieldClicked && (!pCrsrField ||
    3639           0 :                      pCrsrField != aFieldAtPos.pFndTextAttr->GetFormatField().GetField()))
    3640             :                 {
    3641             :                     // select content of Input Field, but exclude CH_TXT_ATR_INPUTFIELDSTART
    3642             :                     // and CH_TXT_ATR_INPUTFIELDEND
    3643           0 :                     rSh.SttSelect();
    3644           0 :                     rSh.SelectText( aFieldAtPos.pFndTextAttr->GetStart() + 1,
    3645           0 :                                  *(aFieldAtPos.pFndTextAttr->End()) - 1 );
    3646             :                 }
    3647             :                 // don't reset here any longer so that, in case through MouseMove
    3648             :                 // with pressed Ctrl key a multiple-selection should happen,
    3649             :                 // the previous selection is not released in Drag.
    3650           1 :                 break;
    3651             :             }
    3652             :         }
    3653             :     }
    3654           0 :     else if ( MOUSE_RIGHT == rMEvt.GetButtons() && !rMEvt.GetModifier()
    3655           0 :         && static_cast< sal_uInt8 >(rMEvt.GetClicks() % 4) == 1
    3656           0 :         && !rSh.ChgCurrPam( aDocPos ) )
    3657             :     {
    3658           0 :         SwContentAtPos aFieldAtPos(SwContentAtPos::SW_FIELD);
    3659             : 
    3660             :         // Are we clicking on a field?
    3661           0 :         if (g_bValidCrsrPos
    3662           0 :             && rSh.GetContentAtPos(aDocPos, aFieldAtPos)
    3663           0 :             && aFieldAtPos.pFndTextAttr != NULL
    3664           0 :             && aFieldAtPos.pFndTextAttr->Which() == RES_TXTATR_INPUTFIELD
    3665           0 :             && (!pCrsrField || pCrsrField != aFieldAtPos.pFndTextAttr->GetFormatField().GetField()))
    3666             :         {
    3667             :             // Move the cursor
    3668           0 :             MoveCursor( rSh, aDocPos, rSh.IsObjSelectable( aDocPos ), m_bWasShdwCrsr );
    3669           0 :             bCallBase = false;
    3670             : 
    3671             :             // select content of Input Field, but exclude CH_TXT_ATR_INPUTFIELDSTART
    3672             :             // and CH_TXT_ATR_INPUTFIELDEND
    3673           0 :             rSh.SttSelect();
    3674           0 :             rSh.SelectText( aFieldAtPos.pFndTextAttr->GetStart() + 1,
    3675           0 :                          *(aFieldAtPos.pFndTextAttr->End()) - 1 );
    3676           0 :         }
    3677             :     }
    3678             : 
    3679           1 :     if (bCallBase)
    3680           0 :         Window::MouseButtonDown(rMEvt);
    3681             : }
    3682             : 
    3683           2 : void SwEditWin::MouseMove(const MouseEvent& _rMEvt)
    3684             : {
    3685           2 :     MouseEvent rMEvt(_rMEvt);
    3686             : 
    3687             :     //ignore key modifiers for format paintbrush
    3688             :     {
    3689           0 :         bool bExecFormatPaintbrush = m_pApplyTempl && m_pApplyTempl->m_pFormatClipboard
    3690           2 :                                 &&  m_pApplyTempl->m_pFormatClipboard->HasContent();
    3691           2 :         if( bExecFormatPaintbrush )
    3692           0 :             rMEvt = MouseEvent( _rMEvt.GetPosPixel(), _rMEvt.GetClicks(),
    3693           0 :                                     _rMEvt.GetMode(), _rMEvt.GetButtons() );
    3694             :     }
    3695             : 
    3696             :     // as long as an action is running the MouseMove should be disconnected
    3697             :     // otherwise bug 40102 occurs
    3698           2 :     SwWrtShell &rSh = m_rView.GetWrtShell();
    3699           2 :     if( rSh.ActionPend() )
    3700           2 :         return ;
    3701             : 
    3702           2 :     if( m_pShadCrsr && 0 != (rMEvt.GetModifier() + rMEvt.GetButtons() ) )
    3703           0 :         delete m_pShadCrsr, m_pShadCrsr = 0;
    3704             : 
    3705           2 :     bool bIsDocReadOnly = m_rView.GetDocShell()->IsReadOnly();
    3706             : 
    3707           2 :     SET_CURR_SHELL( &rSh );
    3708             : 
    3709             :     //aPixPt == Point in Pixel, relative to ChildWin
    3710             :     //aDocPt == Point in Twips, document coordinates
    3711           2 :     const Point aPixPt( rMEvt.GetPosPixel() );
    3712           2 :     const Point aDocPt( PixelToLogic( aPixPt ) );
    3713             : 
    3714           2 :     if ( IsChainMode() )
    3715             :     {
    3716           0 :         UpdatePointer( aDocPt, rMEvt.GetModifier() );
    3717           0 :         return;
    3718             :     }
    3719             : 
    3720           2 :     SdrView *pSdrView = rSh.GetDrawView();
    3721             : 
    3722           2 :     const SwCallMouseEvent aLastCallEvent( m_aSaveCallEvent );
    3723           2 :     m_aSaveCallEvent.Clear();
    3724             : 
    3725           2 :     if ( !bIsDocReadOnly && pSdrView && pSdrView->MouseMove(rMEvt,this) )
    3726             :     {
    3727           0 :         SetPointer( PointerStyle::Text );
    3728           0 :         return; // evaluate SdrView's event
    3729             :     }
    3730             : 
    3731           2 :     const Point aOldPt( rSh.VisArea().Pos() );
    3732           2 :     const bool bInsWin = rSh.VisArea().IsInside( aDocPt ) || rSh.isTiledRendering();
    3733             : 
    3734           2 :     if( m_pShadCrsr && !bInsWin )
    3735           0 :         delete m_pShadCrsr, m_pShadCrsr = 0;
    3736             : 
    3737           2 :     if( bInsWin && m_pRowColumnSelectionStart )
    3738             :     {
    3739           0 :         EnterArea();
    3740           0 :         Point aPos( aDocPt );
    3741           0 :         if( rSh.SelectTableRowCol( *m_pRowColumnSelectionStart, &aPos, m_bIsRowDrag ))
    3742           0 :             return;
    3743             :     }
    3744             : 
    3745             :     // position is necessary for OS/2 because obviously after a MB-Down
    3746             :     // a MB-Move is called immediately.
    3747           2 :     if( g_bDDTimerStarted )
    3748             :     {
    3749           0 :         Point aDD( SwEditWin::m_nDDStartPosX, SwEditWin::m_nDDStartPosY );
    3750           0 :         aDD = LogicToPixel( aDD );
    3751           0 :         Rectangle aRect( aDD.X()-3, aDD.Y()-3, aDD.X()+3, aDD.Y()+3 );
    3752           0 :         if ( !aRect.IsInside( aPixPt ) )
    3753           0 :             StopDDTimer( &rSh, aDocPt );
    3754             :     }
    3755             : 
    3756           2 :     if(m_rView.GetDrawFuncPtr())
    3757             :     {
    3758           0 :         if( m_bInsDraw  )
    3759             :         {
    3760           0 :             m_rView.GetDrawFuncPtr()->MouseMove( rMEvt );
    3761           0 :             if ( !bInsWin )
    3762             :             {
    3763           0 :                 Point aTmp( aDocPt );
    3764           0 :                 aTmp += rSh.VisArea().Pos() - aOldPt;
    3765           0 :                 LeaveArea( aTmp );
    3766             :             }
    3767             :             else
    3768           0 :                 EnterArea();
    3769           0 :             return;
    3770             :         }
    3771           0 :         else if(!rSh.IsFrmSelected() && !rSh.IsObjSelected())
    3772             :         {
    3773           0 :             SfxBindings &rBnd = rSh.GetView().GetViewFrame()->GetBindings();
    3774           0 :             Point aRelPos = rSh.GetRelativePagePosition(aDocPt);
    3775           0 :             if(aRelPos.X() >= 0)
    3776             :             {
    3777           0 :                 FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, &GetView()));
    3778           0 :                 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)));
    3779           0 :                 const SfxPointItem aTmp1( SID_ATTR_POSITION, aRelPos );
    3780           0 :                 rBnd.SetState( aTmp1 );
    3781             :             }
    3782             :             else
    3783             :             {
    3784           0 :                 rBnd.Invalidate(SID_ATTR_POSITION);
    3785             :             }
    3786           0 :             rBnd.Invalidate(SID_ATTR_SIZE);
    3787           0 :             const SfxStringItem aCell( SID_TABLE_CELL, OUString() );
    3788           0 :             rBnd.SetState( aCell );
    3789             :         }
    3790             :     }
    3791             : 
    3792             :     SwTab nMouseTabCol;
    3793           2 :     if( !bIsDocReadOnly && bInsWin && !m_pApplyTempl && !rSh.IsInSelect() )
    3794             :     {
    3795           2 :         if ( SwTab::COL_NONE != (nMouseTabCol = rSh.WhichMouseTabCol( aDocPt ) ) &&
    3796           0 :              !rSh.IsObjSelectable( aDocPt ) )
    3797             :         {
    3798           0 :             PointerStyle nPointer = PointerStyle::Null;
    3799           0 :             bool bChkTableSel = false;
    3800             : 
    3801           0 :             switch ( nMouseTabCol )
    3802             :             {
    3803             :                 case SwTab::COL_VERT :
    3804             :                 case SwTab::ROW_HORI :
    3805           0 :                     nPointer = PointerStyle::VSizeBar;
    3806           0 :                     bChkTableSel = true;
    3807           0 :                     break;
    3808             :                 case SwTab::ROW_VERT :
    3809             :                 case SwTab::COL_HORI :
    3810           0 :                     nPointer = PointerStyle::HSizeBar;
    3811           0 :                     bChkTableSel = true;
    3812           0 :                     break;
    3813             :                 // Enhanced table selection
    3814             :                 case SwTab::SEL_HORI :
    3815           0 :                     nPointer = PointerStyle::TabSelectSE;
    3816           0 :                     break;
    3817             :                 case SwTab::SEL_HORI_RTL :
    3818             :                 case SwTab::SEL_VERT :
    3819           0 :                     nPointer = PointerStyle::TabSelectSW;
    3820           0 :                     break;
    3821             :                 case SwTab::COLSEL_HORI :
    3822             :                 case SwTab::ROWSEL_VERT :
    3823           0 :                     nPointer = PointerStyle::TabSelectS;
    3824           0 :                     break;
    3825             :                 case SwTab::ROWSEL_HORI :
    3826           0 :                     nPointer = PointerStyle::TabSelectE;
    3827           0 :                     break;
    3828             :                 case SwTab::ROWSEL_HORI_RTL :
    3829             :                 case SwTab::COLSEL_VERT :
    3830           0 :                     nPointer = PointerStyle::TabSelectW;
    3831           0 :                     break;
    3832           0 :                 default: break; // prevent compiler warning
    3833             :             }
    3834             : 
    3835           0 :             if ( PointerStyle::Null != nPointer &&
    3836             :                 // i#35543 - Enhanced table selection is explicitly allowed in table mode
    3837           0 :                 ( !bChkTableSel || !rSh.IsTableMode() ) )
    3838             :             {
    3839           0 :                 SetPointer( nPointer );
    3840             :             }
    3841             : 
    3842           0 :             return;
    3843             :         }
    3844           2 :         else if (rSh.IsNumLabel(aDocPt, RULER_MOUSE_MARGINWIDTH))
    3845             :         {
    3846             :             // i#42921 - consider vertical mode
    3847           0 :             SwTextNode* pNodeAtPos = rSh.GetNumRuleNodeAtPos( aDocPt );
    3848             :             const PointerStyle nPointer =
    3849           0 :                     SwFEShell::IsVerticalModeAtNdAndPos( *pNodeAtPos, aDocPt )
    3850             :                     ? PointerStyle::VSizeBar
    3851           0 :                     : PointerStyle::HSizeBar;
    3852           0 :             SetPointer( nPointer );
    3853             : 
    3854           0 :             return;
    3855             :         }
    3856             :     }
    3857             : 
    3858           2 :     bool bDelShadCrsr = true;
    3859             : 
    3860           2 :     switch ( rMEvt.GetModifier() + rMEvt.GetButtons() )
    3861             :     {
    3862             :         case MOUSE_LEFT:
    3863           2 :             if( m_pAnchorMarker )
    3864             :             {
    3865             :                 // Now we need to refresh the SdrHdl pointer of m_pAnchorMarker.
    3866             :                 // This looks a little bit tricky, but it solves the following
    3867             :                 // problem: the m_pAnchorMarker contains a pointer to an SdrHdl,
    3868             :                 // if the FindAnchorPos-call cause a scrolling of the visible
    3869             :                 // area, it's possible that the SdrHdl will be destroyed and a
    3870             :                 // new one will initialized at the original position(GetHdlPos).
    3871             :                 // So the m_pAnchorMarker has to find the right SdrHdl, if it's
    3872             :                 // the old one, it will find it with position aOld, if this one
    3873             :                 // is destroyed, it will find a new one at position GetHdlPos().
    3874             : 
    3875           0 :                 const Point aOld = m_pAnchorMarker->GetPosForHitTest( *(rSh.GetOut()) );
    3876           0 :                 Point aNew = rSh.FindAnchorPos( aDocPt );
    3877             :                 SdrHdl* pHdl;
    3878           0 :                 if( pSdrView && (0!=( pHdl = pSdrView->PickHandle( aOld ) )||
    3879           0 :                     0 !=(pHdl = pSdrView->PickHandle( m_pAnchorMarker->GetHdlPos()) ) ) &&
    3880           0 :                         ( pHdl->GetKind() == HDL_ANCHOR ||
    3881           0 :                           pHdl->GetKind() == HDL_ANCHOR_TR ) )
    3882             :                 {
    3883           0 :                     m_pAnchorMarker->ChgHdl( pHdl );
    3884           0 :                     if( aNew.X() || aNew.Y() )
    3885             :                     {
    3886           0 :                         m_pAnchorMarker->SetPos( aNew );
    3887           0 :                         m_pAnchorMarker->SetLastPos( aDocPt );
    3888             :                     }
    3889             :                 }
    3890             :                 else
    3891             :                 {
    3892           0 :                     delete m_pAnchorMarker;
    3893           0 :                     m_pAnchorMarker = NULL;
    3894             :                 }
    3895             :             }
    3896           2 :             if ( m_bInsDraw )
    3897             :             {
    3898           0 :                 if ( !m_bMBPressed )
    3899           0 :                     break;
    3900           0 :                 if ( m_bIsInMove || IsMinMove( m_aStartPos, aPixPt ) )
    3901             :                 {
    3902           0 :                     if ( !bInsWin )
    3903           0 :                         LeaveArea( aDocPt );
    3904             :                     else
    3905           0 :                         EnterArea();
    3906           0 :                     if ( m_rView.GetDrawFuncPtr() )
    3907             :                     {
    3908           0 :                         pSdrView->SetOrtho(false);
    3909           0 :                         m_rView.GetDrawFuncPtr()->MouseMove( rMEvt );
    3910             :                     }
    3911           0 :                     m_bIsInMove = true;
    3912             :                 }
    3913           0 :                 return;
    3914             :             }
    3915             : 
    3916             :             {
    3917           2 :             SwWordCountWrapper *pWrdCnt = static_cast<SwWordCountWrapper*>(GetView().GetViewFrame()->GetChildWindow(SwWordCountWrapper::GetChildWindowId()));
    3918           2 :             if (pWrdCnt)
    3919           0 :                 pWrdCnt->UpdateCounts();
    3920             :             }
    3921             : 
    3922             :         case MOUSE_LEFT + KEY_SHIFT:
    3923             :         case MOUSE_LEFT + KEY_SHIFT + KEY_MOD1:
    3924           2 :             if ( !m_bMBPressed )
    3925           0 :                 break;
    3926             :         case MOUSE_LEFT + KEY_MOD1:
    3927           2 :             if ( g_bFrmDrag && rSh.IsSelFrmMode() )
    3928             :             {
    3929           2 :                 if( !m_bMBPressed )
    3930           0 :                     break;
    3931             : 
    3932           2 :                 if ( m_bIsInMove || IsMinMove( m_aStartPos, aPixPt ) )
    3933             :                 {
    3934             :                     // event processing for resizing
    3935           2 :                     if (pSdrView && pSdrView->AreObjectsMarked())
    3936             :                     {
    3937             :                         const SwFrameFormat* pFlyFormat;
    3938             :                         const SvxMacro* pMacro;
    3939             : 
    3940           2 :                         const Point aSttPt( PixelToLogic( m_aStartPos ) );
    3941             : 
    3942             :                         // can we start?
    3943           2 :                         if( HDL_USER == g_eSdrMoveHdl )
    3944             :                         {
    3945           1 :                             SdrHdl* pHdl = pSdrView->PickHandle( aSttPt );
    3946           1 :                             g_eSdrMoveHdl = pHdl ? pHdl->GetKind() : HDL_MOVE;
    3947             :                         }
    3948             : 
    3949           2 :                         sal_uInt16 nEvent = HDL_MOVE == g_eSdrMoveHdl
    3950             :                                             ? SW_EVENT_FRM_MOVE
    3951           2 :                                             : SW_EVENT_FRM_RESIZE;
    3952             : 
    3953           4 :                         if( 0 != ( pFlyFormat = rSh.GetFlyFrameFormat() ) &&
    3954           0 :                             0 != ( pMacro = pFlyFormat->GetMacro().GetMacroTable().
    3955           2 :                             Get( nEvent )) &&
    3956             :                         // or notify only e.g. every 20 Twip?
    3957           0 :                             m_aRszMvHdlPt != aDocPt )
    3958             :                         {
    3959           0 :                             m_aRszMvHdlPt = aDocPt;
    3960           0 :                             sal_uInt16 nPos = 0;
    3961           0 :                             SbxArrayRef xArgs = new SbxArray;
    3962           0 :                             SbxVariableRef xVar = new SbxVariable;
    3963           0 :                             xVar->PutString( pFlyFormat->GetName() );
    3964           0 :                             xArgs->Put( &xVar, ++nPos );
    3965             : 
    3966           0 :                             if( SW_EVENT_FRM_RESIZE == nEvent )
    3967             :                             {
    3968           0 :                                 xVar = new SbxVariable;
    3969           0 :                                 xVar->PutUShort( static_cast< sal_uInt16 >(g_eSdrMoveHdl) );
    3970           0 :                                 xArgs->Put( &xVar, ++nPos );
    3971             :                             }
    3972             : 
    3973           0 :                             xVar = new SbxVariable;
    3974           0 :                             xVar->PutLong( aDocPt.X() - aSttPt.X() );
    3975           0 :                             xArgs->Put( &xVar, ++nPos );
    3976           0 :                             xVar = new SbxVariable;
    3977           0 :                             xVar->PutLong( aDocPt.Y() - aSttPt.Y() );
    3978           0 :                             xArgs->Put( &xVar, ++nPos );
    3979             : 
    3980           0 :                             OUString sRet;
    3981             : 
    3982           0 :                             ReleaseMouse();
    3983             : 
    3984           0 :                             rSh.ExecMacro( *pMacro, &sRet, &xArgs );
    3985             : 
    3986           0 :                             CaptureMouse();
    3987             : 
    3988           0 :                             if( !sRet.isEmpty() && sRet.toInt32()!=0 )
    3989           0 :                                 return ;
    3990             :                         }
    3991             :                     }
    3992             :                     // event processing for resizing
    3993             : 
    3994           2 :                     if( bIsDocReadOnly )
    3995           0 :                         break;
    3996             : 
    3997           2 :                     bool bIsSelectionGfx = rSh.GetSelectionType() & nsSelectionType::SEL_GRF;
    3998           2 :                     bool bisResize = g_eSdrMoveHdl != HDL_MOVE;
    3999             : 
    4000           2 :                     if (pSdrView)
    4001             :                     {
    4002           2 :                         if (pSdrView->GetDragMode() == SDRDRAG_CROP)
    4003           0 :                             bisResize = false;
    4004             : 
    4005           2 :                         if (rMEvt.IsShift())
    4006             :                         {
    4007           0 :                             pSdrView->SetAngleSnapEnabled(!bIsSelectionGfx);
    4008           0 :                             if (bisResize)
    4009           0 :                                 pSdrView->SetOrtho(!bIsSelectionGfx);
    4010             :                             else
    4011           0 :                                 pSdrView->SetOrtho(true);
    4012             :                         }
    4013             :                         else
    4014             :                         {
    4015           2 :                             pSdrView->SetAngleSnapEnabled(bIsSelectionGfx);
    4016           2 :                             if (bisResize)
    4017           2 :                                 pSdrView->SetOrtho(bIsSelectionGfx);
    4018             :                             else
    4019           0 :                                 pSdrView->SetOrtho(false);
    4020             :                         }
    4021             :                     }
    4022             : 
    4023           2 :                     rSh.Drag( &aDocPt, rMEvt.IsShift() );
    4024           2 :                     m_bIsInMove = true;
    4025             :                 }
    4026           0 :                 else if( bIsDocReadOnly )
    4027           0 :                     break;
    4028             : 
    4029           2 :                 if ( !bInsWin )
    4030             :                 {
    4031           0 :                     Point aTmp( aDocPt );
    4032           0 :                     aTmp += rSh.VisArea().Pos() - aOldPt;
    4033           0 :                     LeaveArea( aTmp );
    4034             :                 }
    4035           2 :                 else if(m_bIsInMove)
    4036           2 :                     EnterArea();
    4037           2 :                 return;
    4038             :             }
    4039           0 :             if ( !rSh.IsSelFrmMode() && !g_bDDINetAttr &&
    4040           0 :                 (IsMinMove( m_aStartPos,aPixPt ) || m_bIsInMove) &&
    4041           0 :                 (rSh.IsInSelect() || !rSh.ChgCurrPam( aDocPt )) )
    4042             :             {
    4043           0 :                 if ( pSdrView )
    4044             :                 {
    4045           0 :                     if ( rMEvt.IsShift() )
    4046           0 :                         pSdrView->SetOrtho(true);
    4047             :                     else
    4048           0 :                         pSdrView->SetOrtho(false);
    4049             :                 }
    4050           0 :                 if ( !bInsWin )
    4051             :                 {
    4052           0 :                     Point aTmp( aDocPt );
    4053           0 :                     aTmp += rSh.VisArea().Pos() - aOldPt;
    4054           0 :                     LeaveArea( aTmp );
    4055             :                 }
    4056             :                 else
    4057             :                 {
    4058           0 :                     if( !rMEvt.IsSynthetic() &&
    4059             :                             !(( MOUSE_LEFT + KEY_MOD1 ==
    4060           0 :                             rMEvt.GetModifier() + rMEvt.GetButtons() ) &&
    4061           0 :                             rSh.Is_FnDragEQBeginDrag() && !rSh.IsAddMode() ))
    4062             :                     {
    4063           0 :                         rSh.Drag( &aDocPt, false );
    4064             : 
    4065           0 :                         g_bValidCrsrPos = !(CRSR_POSCHG & rSh.SetCursor(&aDocPt, false));
    4066           0 :                         EnterArea();
    4067             :                     }
    4068             :                 }
    4069             :             }
    4070           0 :             g_bDDINetAttr = false;
    4071           0 :             break;
    4072             :         case 0:
    4073             :         {
    4074           0 :             if ( m_pApplyTempl )
    4075             :             {
    4076           0 :                 UpdatePointer(aDocPt, 0); // maybe a frame has to be marked here
    4077           0 :                 break;
    4078             :             }
    4079             :             // change ui if mouse is over SwPostItField
    4080             :             // TODO: do the same thing for redlines SW_REDLINE
    4081           0 :             SwRect aFieldRect;
    4082           0 :             SwContentAtPos aContentAtPos( SwContentAtPos::SW_FIELD);
    4083           0 :             if( rSh.GetContentAtPos( aDocPt, aContentAtPos, false, &aFieldRect ) )
    4084             :             {
    4085           0 :                 const SwField* pField = aContentAtPos.aFnd.pField;
    4086           0 :                 if (pField->Which()== RES_POSTITFLD)
    4087             :                 {
    4088           0 :                     m_rView.GetPostItMgr()->SetShadowState(reinterpret_cast<const SwPostItField*>(pField),false);
    4089             :                 }
    4090             :                 else
    4091           0 :                     m_rView.GetPostItMgr()->SetShadowState(0,false);
    4092             :             }
    4093             :             else
    4094           0 :                 m_rView.GetPostItMgr()->SetShadowState(0,false);
    4095             :         }
    4096             :         // no break;
    4097             :         case KEY_SHIFT:
    4098             :         case KEY_MOD2:
    4099             :         case KEY_MOD1:
    4100           0 :             if ( !m_bInsDraw )
    4101             :             {
    4102           0 :                 bool bTstShdwCrsr = true;
    4103             : 
    4104           0 :                 UpdatePointer( aDocPt, rMEvt.GetModifier() );
    4105             : 
    4106           0 :                 const SwFrameFormat* pFormat = 0;
    4107           0 :                 const SwFormatINetFormat* pINet = 0;
    4108           0 :                 SwContentAtPos aContentAtPos( SwContentAtPos::SW_INETATTR );
    4109           0 :                 if( rSh.GetContentAtPos( aDocPt, aContentAtPos ) )
    4110           0 :                     pINet = static_cast<const SwFormatINetFormat*>(aContentAtPos.aFnd.pAttr);
    4111             : 
    4112           0 :                 const void* pTmp = pINet;
    4113             : 
    4114           0 :                 if( pINet ||
    4115           0 :                     0 != ( pTmp = pFormat = rSh.GetFormatFromAnyObj( aDocPt )))
    4116             :                 {
    4117           0 :                     bTstShdwCrsr = false;
    4118           0 :                     if( pTmp == pINet )
    4119           0 :                         m_aSaveCallEvent.Set( pINet );
    4120             :                     else
    4121             :                     {
    4122           0 :                         IMapObject* pIMapObj = pFormat->GetIMapObject( aDocPt );
    4123           0 :                         if( pIMapObj )
    4124           0 :                             m_aSaveCallEvent.Set( pFormat, pIMapObj );
    4125             :                         else
    4126           0 :                             m_aSaveCallEvent.Set( EVENT_OBJECT_URLITEM, pFormat );
    4127             :                     }
    4128             : 
    4129             :                     // should be over a InternetField with an
    4130             :                     // embedded macro?
    4131           0 :                     if( m_aSaveCallEvent != aLastCallEvent )
    4132             :                     {
    4133           0 :                         if( aLastCallEvent.HasEvent() )
    4134             :                             rSh.CallEvent( SFX_EVENT_MOUSEOUT_OBJECT,
    4135           0 :                                             aLastCallEvent, true );
    4136             :                         // 0 says that the object doesn't have any table
    4137           0 :                         if( !rSh.CallEvent( SFX_EVENT_MOUSEOVER_OBJECT,
    4138           0 :                                         m_aSaveCallEvent ))
    4139           0 :                             m_aSaveCallEvent.Clear();
    4140             :                     }
    4141             :                 }
    4142           0 :                 else if( aLastCallEvent.HasEvent() )
    4143             :                 {
    4144             :                     // cursor was on an object
    4145             :                     rSh.CallEvent( SFX_EVENT_MOUSEOUT_OBJECT,
    4146           0 :                                     aLastCallEvent, true );
    4147             :                 }
    4148             : 
    4149           0 :                 if( bTstShdwCrsr && bInsWin && !bIsDocReadOnly &&
    4150           0 :                     !m_bInsFrm &&
    4151           0 :                     !rSh.GetViewOptions()->getBrowseMode() &&
    4152           0 :                     rSh.GetViewOptions()->IsShadowCursor() &&
    4153           0 :                     !(rMEvt.GetModifier() + rMEvt.GetButtons()) &&
    4154           0 :                     !rSh.HasSelection() && !GetConnectMetaFile() )
    4155             :                 {
    4156           0 :                     SwRect aRect;
    4157             :                     sal_Int16 eOrient;
    4158           0 :                     SwFillMode eMode = (SwFillMode)rSh.GetViewOptions()->GetShdwCrsrFillMode();
    4159           0 :                     if( rSh.GetShadowCrsrPos( aDocPt, eMode, aRect, eOrient ))
    4160             :                     {
    4161           0 :                         if( !m_pShadCrsr )
    4162             :                             m_pShadCrsr = new SwShadowCursor( *this,
    4163           0 :                                 SwViewOption::GetDirectCursorColor() );
    4164           0 :                         if( text::HoriOrientation::RIGHT != eOrient && text::HoriOrientation::CENTER != eOrient )
    4165           0 :                             eOrient = text::HoriOrientation::LEFT;
    4166           0 :                         m_pShadCrsr->SetPos( aRect.Pos(), aRect.Height(), static_cast< sal_uInt16 >(eOrient) );
    4167           0 :                         bDelShadCrsr = false;
    4168             :                     }
    4169           0 :                 }
    4170             :             }
    4171           0 :             break;
    4172             :         case MOUSE_LEFT + KEY_MOD2:
    4173           0 :             if( rSh.IsBlockMode() && !rMEvt.IsSynthetic() )
    4174             :             {
    4175           0 :                 rSh.Drag( &aDocPt, false );
    4176           0 :                 g_bValidCrsrPos = !(CRSR_POSCHG & rSh.SetCursor(&aDocPt, false));
    4177           0 :                 EnterArea();
    4178             :             }
    4179           0 :         break;
    4180             :     }
    4181             : 
    4182           0 :     if( bDelShadCrsr && m_pShadCrsr )
    4183           0 :         delete m_pShadCrsr, m_pShadCrsr = 0;
    4184           0 :     m_bWasShdwCrsr = false;
    4185             : }
    4186             : 
    4187             : /**
    4188             :  * Button Up
    4189             :  */
    4190           2 : void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt)
    4191             : {
    4192           2 :     bool bCallBase = true;
    4193             : 
    4194           2 :     bool bCallShadowCrsr = m_bWasShdwCrsr;
    4195           2 :     m_bWasShdwCrsr = false;
    4196           2 :     if( m_pShadCrsr )
    4197           0 :         delete m_pShadCrsr, m_pShadCrsr = 0;
    4198             : 
    4199           2 :     if( m_pRowColumnSelectionStart )
    4200           0 :         DELETEZ( m_pRowColumnSelectionStart );
    4201             : 
    4202           2 :     SdrHdlKind eOldSdrMoveHdl = g_eSdrMoveHdl;
    4203           2 :     g_eSdrMoveHdl = HDL_USER;     // for MoveEvents - reset again
    4204             : 
    4205             :     // preventively reset
    4206           2 :     m_rView.SetTabColFromDoc( false );
    4207           2 :     m_rView.SetNumRuleNodeFromDoc(NULL);
    4208             : 
    4209           2 :     SwWrtShell &rSh = m_rView.GetWrtShell();
    4210           2 :     SET_CURR_SHELL( &rSh );
    4211           2 :     SdrView *pSdrView = rSh.GetDrawView();
    4212           2 :     if ( pSdrView )
    4213             :     {
    4214             :         // tdf34555: ortho was always reset before being used in EndSdrDrag
    4215             :         // Now, it is reset only if not in Crop mode.
    4216           2 :         if (pSdrView->GetDragMode() != SDRDRAG_CROP)
    4217           2 :             pSdrView->SetOrtho(false);
    4218             : 
    4219           2 :         if ( pSdrView->MouseButtonUp( rMEvt,this ) )
    4220             :         {
    4221           0 :             rSh.GetView().GetViewFrame()->GetBindings().InvalidateAll(false);
    4222           0 :             return; // SdrView's event evaluated
    4223             :         }
    4224             :     }
    4225             :     // only process MouseButtonUp when the Down went to that windows as well.
    4226           2 :     if ( !m_bMBPressed )
    4227             :     {
    4228             :     // Undo for the watering can is already in CommandHdl
    4229             :     // that's the way it should be!
    4230             : 
    4231           0 :         return;
    4232             :     }
    4233             : 
    4234           2 :     Point aDocPt( PixelToLogic( rMEvt.GetPosPixel() ) );
    4235             : 
    4236           2 :     if ( g_bDDTimerStarted )
    4237             :     {
    4238           0 :         StopDDTimer( &rSh, aDocPt );
    4239           0 :         m_bMBPressed = false;
    4240           0 :         if ( rSh.IsSelFrmMode() )
    4241             :         {
    4242           0 :             rSh.EndDrag( &aDocPt, false );
    4243           0 :             g_bFrmDrag = false;
    4244             :         }
    4245           0 :         g_bNoInterrupt = false;
    4246           0 :         const Point aDocPos( PixelToLogic( rMEvt.GetPosPixel() ) );
    4247           0 :         if ((PixelToLogic(m_aStartPos).Y() == (aDocPos.Y())) && (PixelToLogic(m_aStartPos).X() == (aDocPos.X())))//To make sure it was not moved
    4248             :         {
    4249             :             SdrObject* pObj;
    4250             :             SdrPageView* pPV;
    4251           0 :             if (pSdrView && pSdrView->PickObj(aDocPos, pSdrView->getHitTolLog(), pObj, pPV, SdrSearchOptions::ALSOONMASTER ))
    4252             :             {
    4253           0 :                 std::map<SwFrameFormat*, SwFrameFormat*> aTextBoxShapes = SwTextBoxHelper::findShapes(rSh.GetDoc());
    4254           0 :                 SwDrawContact* pDrawContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
    4255           0 :                 SwFrameFormat* pFormat = pDrawContact->GetFormat();
    4256           0 :                 if (aTextBoxShapes.find(pFormat) == aTextBoxShapes.end())
    4257             :                 {
    4258           0 :                     pSdrView->UnmarkAllObj();
    4259           0 :                     pSdrView->MarkObj(pObj,pPV,false,false);
    4260             :                 }
    4261             :                 else
    4262             :                 {
    4263             :                     // If the fly frame is a textbox of a shape, then select the shape instead.
    4264           0 :                     SdrObject* pShape = aTextBoxShapes[pFormat]->FindSdrObject();
    4265           0 :                     pSdrView->UnmarkAllObj();
    4266           0 :                     pSdrView->MarkObj(pShape, pPV, false, false);
    4267           0 :                 }
    4268             :             }
    4269             :         }
    4270           0 :         ReleaseMouse();
    4271           0 :         return;
    4272             :     }
    4273             : 
    4274           2 :     if( m_pAnchorMarker )
    4275             :     {
    4276           0 :         if(m_pAnchorMarker->GetHdl())
    4277             :         {
    4278             :             // #i121463# delete selected after drag
    4279           0 :             m_pAnchorMarker->GetHdl()->SetSelected(false);
    4280             :         }
    4281             : 
    4282           0 :         Point aPnt( m_pAnchorMarker->GetLastPos() );
    4283           0 :         DELETEZ( m_pAnchorMarker );
    4284           0 :         if( aPnt.X() || aPnt.Y() )
    4285           0 :             rSh.FindAnchorPos( aPnt, true );
    4286             :     }
    4287           2 :     if ( m_bInsDraw && m_rView.GetDrawFuncPtr() )
    4288             :     {
    4289           0 :         if ( m_rView.GetDrawFuncPtr()->MouseButtonUp( rMEvt ) )
    4290             :         {
    4291           0 :             if (m_rView.GetDrawFuncPtr()) // could have been destroyed in MouseButtonUp
    4292             :             {
    4293           0 :                 m_rView.GetDrawFuncPtr()->Deactivate();
    4294             : 
    4295           0 :                 if (!m_rView.IsDrawMode())
    4296             :                 {
    4297           0 :                     m_rView.SetDrawFuncPtr(NULL);
    4298           0 :                     SfxBindings& rBind = m_rView.GetViewFrame()->GetBindings();
    4299           0 :                     rBind.Invalidate( SID_ATTR_SIZE );
    4300           0 :                     rBind.Invalidate( SID_TABLE_CELL );
    4301             :                 }
    4302             :             }
    4303             : 
    4304           0 :             if ( rSh.IsObjSelected() )
    4305             :             {
    4306           0 :                 rSh.EnterSelFrmMode();
    4307           0 :                 if (!m_rView.GetDrawFuncPtr())
    4308           0 :                     StdDrawMode( OBJ_NONE, true );
    4309             :             }
    4310           0 :             else if ( rSh.IsFrmSelected() )
    4311             :             {
    4312           0 :                 rSh.EnterSelFrmMode();
    4313           0 :                 StopInsFrm();
    4314             :             }
    4315             :             else
    4316             :             {
    4317           0 :                 const Point aDocPos( PixelToLogic( m_aStartPos ) );
    4318           0 :                 g_bValidCrsrPos = !(CRSR_POSCHG & rSh.SetCursor(&aDocPos, false));
    4319           0 :                 rSh.Edit();
    4320             :             }
    4321             : 
    4322           0 :             m_rView.AttrChangedNotify( &rSh );
    4323             :         }
    4324           0 :         else if (rMEvt.GetButtons() == MOUSE_RIGHT && rSh.IsDrawCreate())
    4325           0 :             m_rView.GetDrawFuncPtr()->BreakCreate();   // abort drawing
    4326             : 
    4327           0 :         g_bNoInterrupt = false;
    4328           0 :         ReleaseMouse();
    4329           0 :         return;
    4330             :     }
    4331           2 :     bool bPopMode = false;
    4332           2 :     switch ( rMEvt.GetModifier() + rMEvt.GetButtons() )
    4333             :     {
    4334             :         case MOUSE_LEFT:
    4335           2 :             if ( m_bInsDraw && rSh.IsDrawCreate() )
    4336             :             {
    4337           0 :                 if ( m_rView.GetDrawFuncPtr() && m_rView.GetDrawFuncPtr()->MouseButtonUp(rMEvt) )
    4338             :                 {
    4339           0 :                     m_rView.GetDrawFuncPtr()->Deactivate();
    4340           0 :                     m_rView.AttrChangedNotify( &rSh );
    4341           0 :                     if ( rSh.IsObjSelected() )
    4342           0 :                         rSh.EnterSelFrmMode();
    4343           0 :                     if ( m_rView.GetDrawFuncPtr() && m_bInsFrm )
    4344           0 :                         StopInsFrm();
    4345             :                 }
    4346           0 :                 bCallBase = false;
    4347           0 :                 break;
    4348             :             }
    4349             :         case MOUSE_LEFT + KEY_MOD1:
    4350             :         case MOUSE_LEFT + KEY_MOD2:
    4351             :         case MOUSE_LEFT + KEY_SHIFT + KEY_MOD1:
    4352           2 :             if ( g_bFrmDrag && rSh.IsSelFrmMode() )
    4353             :             {
    4354           1 :                 if ( rMEvt.IsMod1() ) // copy and don't move.
    4355             :                 {
    4356             :                     // abort drag, use internal Copy instead
    4357           0 :                     Rectangle aRect;
    4358           0 :                     rSh.GetDrawView()->TakeActionRect( aRect );
    4359           0 :                     if (!aRect.IsEmpty())
    4360             :                     {
    4361           0 :                         rSh.BreakDrag();
    4362           0 :                         Point aEndPt, aSttPt;
    4363           0 :                         if ( rSh.GetSelFrmType() & FrmTypeFlags::FLY_ATCNT )
    4364             :                         {
    4365           0 :                             aEndPt = aRect.TopLeft();
    4366           0 :                             aSttPt = rSh.GetDrawView()->GetAllMarkedRect().TopLeft();
    4367             :                         }
    4368             :                         else
    4369             :                         {
    4370           0 :                             aEndPt = aRect.Center();
    4371           0 :                             aSttPt = rSh.GetDrawView()->GetAllMarkedRect().Center();
    4372             :                         }
    4373           0 :                         if ( aSttPt != aEndPt )
    4374             :                         {
    4375           0 :                             rSh.StartUndo( UNDO_UI_DRAG_AND_COPY );
    4376           0 :                             rSh.Copy(&rSh, aSttPt, aEndPt, false);
    4377           0 :                             rSh.EndUndo( UNDO_UI_DRAG_AND_COPY );
    4378             :                         }
    4379             :                     }
    4380             :                     else {
    4381           0 :                         rSh.EndDrag( &aDocPt, false );
    4382             :                     }
    4383             :                 }
    4384             :                 else
    4385             :                 {
    4386             :                     {
    4387             :                         const SwFrameFormat* pFlyFormat;
    4388             :                         const SvxMacro* pMacro;
    4389             : 
    4390             :                         sal_uInt16 nEvent = HDL_MOVE == eOldSdrMoveHdl
    4391             :                                             ? SW_EVENT_FRM_MOVE
    4392           1 :                                             : SW_EVENT_FRM_RESIZE;
    4393             : 
    4394           1 :                         if( 0 != ( pFlyFormat = rSh.GetFlyFrameFormat() ) &&
    4395           0 :                             0 != ( pMacro = pFlyFormat->GetMacro().GetMacroTable().
    4396           0 :                             Get( nEvent )) )
    4397             :                         {
    4398           0 :                             const Point aSttPt( PixelToLogic( m_aStartPos ) );
    4399           0 :                             m_aRszMvHdlPt = aDocPt;
    4400           0 :                             sal_uInt16 nPos = 0;
    4401           0 :                             SbxArrayRef xArgs = new SbxArray;
    4402           0 :                             SbxVariableRef xVar = new SbxVariable;
    4403           0 :                             xVar->PutString( pFlyFormat->GetName() );
    4404           0 :                             xArgs->Put( &xVar, ++nPos );
    4405             : 
    4406           0 :                             if( SW_EVENT_FRM_RESIZE == nEvent )
    4407             :                             {
    4408           0 :                                 xVar = new SbxVariable;
    4409           0 :                                 xVar->PutUShort( static_cast< sal_uInt16 >(eOldSdrMoveHdl) );
    4410           0 :                                 xArgs->Put( &xVar, ++nPos );
    4411             :                             }
    4412             : 
    4413           0 :                             xVar = new SbxVariable;
    4414           0 :                             xVar->PutLong( aDocPt.X() - aSttPt.X() );
    4415           0 :                             xArgs->Put( &xVar, ++nPos );
    4416           0 :                             xVar = new SbxVariable;
    4417           0 :                             xVar->PutLong( aDocPt.Y() - aSttPt.Y() );
    4418           0 :                             xArgs->Put( &xVar, ++nPos );
    4419             : 
    4420           0 :                             xVar = new SbxVariable;
    4421           0 :                             xVar->PutUShort( 1 );
    4422           0 :                             xArgs->Put( &xVar, ++nPos );
    4423             : 
    4424           0 :                             ReleaseMouse();
    4425             : 
    4426           0 :                             rSh.ExecMacro( *pMacro, 0, &xArgs );
    4427             : 
    4428           0 :                             CaptureMouse();
    4429             :                         }
    4430             :                     }
    4431           1 :                     rSh.EndDrag( &aDocPt, false );
    4432             :                 }
    4433           1 :                 g_bFrmDrag = false;
    4434           1 :                 bCallBase = false;
    4435           1 :                 break;
    4436             :             }
    4437           1 :             bPopMode = true;
    4438             :             // no break
    4439             :         case MOUSE_LEFT + KEY_SHIFT:
    4440           1 :             if (rSh.IsSelFrmMode())
    4441             :             {
    4442             : 
    4443           0 :                 rSh.EndDrag( &aDocPt, false );
    4444           0 :                 g_bFrmDrag = false;
    4445           0 :                 bCallBase = false;
    4446           0 :                 break;
    4447             :             }
    4448             : 
    4449           1 :             if( g_bHoldSelection )
    4450             :             {
    4451             :                 // the EndDrag should be called in any case
    4452           0 :                 g_bHoldSelection = false;
    4453           0 :                 rSh.EndDrag( &aDocPt, false );
    4454             :             }
    4455             :             else
    4456             :             {
    4457           1 :                 SwContentAtPos aFieldAtPos ( SwContentAtPos::SW_FIELD );
    4458           1 :                 if ( !rSh.IsInSelect() && rSh.ChgCurrPam( aDocPt ) && !rSh.GetContentAtPos( aDocPt, aFieldAtPos ) )
    4459             :                 {
    4460           0 :                     const bool bTmpNoInterrupt = g_bNoInterrupt;
    4461           0 :                     g_bNoInterrupt = false;
    4462             :                     {   // create only temporary move context because otherwise
    4463             :                         // the query to the content form doesn't work!!!
    4464           0 :                         SwMvContext aMvContext( &rSh );
    4465           0 :                         const Point aDocPos( PixelToLogic( m_aStartPos ) );
    4466           0 :                         g_bValidCrsrPos = !(CRSR_POSCHG & rSh.SetCursor(&aDocPos, false));
    4467             :                     }
    4468           0 :                     g_bNoInterrupt = bTmpNoInterrupt;
    4469             : 
    4470             :                 }
    4471             :                 else
    4472             :                 {
    4473           1 :                     bool bInSel = rSh.IsInSelect();
    4474           1 :                     rSh.EndDrag( &aDocPt, false );
    4475             : 
    4476             :                     // Internetfield? --> call link (load doc!!)
    4477           1 :                     if( !bInSel )
    4478             :                     {
    4479           1 :                         sal_uInt16 nFilter = URLLOAD_NOFILTER;
    4480           1 :                         if( KEY_MOD1 == rMEvt.GetModifier() )
    4481           0 :                             nFilter |= URLLOAD_NEWVIEW;
    4482             : 
    4483           1 :                         bool bExecHyperlinks = m_rView.GetDocShell()->IsReadOnly();
    4484           1 :                         if ( !bExecHyperlinks )
    4485             :                         {
    4486           1 :                             SvtSecurityOptions aSecOpts;
    4487           1 :                             const bool bSecureOption = aSecOpts.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK );
    4488           2 :                             if ( (  bSecureOption && rMEvt.GetModifier() == KEY_MOD1 ) ||
    4489           1 :                                  ( !bSecureOption && rMEvt.GetModifier() != KEY_MOD1 ) )
    4490           0 :                                 bExecHyperlinks = true;
    4491             :                         }
    4492             : 
    4493           1 :                         const bool bExecSmarttags = rMEvt.GetModifier() == KEY_MOD1;
    4494             : 
    4495           1 :                         if(m_pApplyTempl)
    4496           0 :                             bExecHyperlinks = false;
    4497             : 
    4498             :                         SwContentAtPos aContentAtPos( SwContentAtPos::SW_FIELD |
    4499             :                                                     SwContentAtPos::SW_INETATTR |
    4500           1 :                                                     SwContentAtPos::SW_SMARTTAG  | SwContentAtPos::SW_FORMCTRL);
    4501             : 
    4502           1 :                         if( rSh.GetContentAtPos( aDocPt, aContentAtPos, false ) )
    4503             :                         {
    4504             :                             // Do it again if we're not on a field/hyperlink to update the cursor accordingly
    4505           0 :                             if ( SwContentAtPos::SW_FIELD != aContentAtPos.eContentAtPos
    4506           0 :                                  && SwContentAtPos::SW_INETATTR != aContentAtPos.eContentAtPos )
    4507           0 :                                 rSh.GetContentAtPos( aDocPt, aContentAtPos, true );
    4508             : 
    4509           0 :                             bool bViewLocked = rSh.IsViewLocked();
    4510           0 :                             if( !bViewLocked && !rSh.IsReadOnlyAvailable() &&
    4511           0 :                                 aContentAtPos.IsInProtectSect() )
    4512           0 :                                 rSh.LockView( true );
    4513             : 
    4514           0 :                             ReleaseMouse();
    4515             : 
    4516           0 :                             if( SwContentAtPos::SW_FIELD == aContentAtPos.eContentAtPos )
    4517             :                             {
    4518           0 :                                 bool bAddMode(false);
    4519             :                                 // AdditionalMode if applicable
    4520           0 :                                 if (KEY_MOD1 == rMEvt.GetModifier()
    4521           0 :                                     && !rSh.IsAddMode())
    4522             :                                 {
    4523           0 :                                     bAddMode = true;
    4524           0 :                                     rSh.EnterAddMode();
    4525             :                                 }
    4526           0 :                                 if ( aContentAtPos.pFndTextAttr != NULL
    4527           0 :                                      && aContentAtPos.pFndTextAttr->Which() == RES_TXTATR_INPUTFIELD )
    4528             :                                 {
    4529           0 :                                     if (!rSh.IsInSelect())
    4530             :                                     {
    4531             :                                         // create only temporary move context because otherwise
    4532             :                                         // the query to the content form doesn't work!!!
    4533           0 :                                         SwMvContext aMvContext( &rSh );
    4534           0 :                                         const Point aDocPos( PixelToLogic( m_aStartPos ) );
    4535           0 :                                         g_bValidCrsrPos = !(CRSR_POSCHG & rSh.SetCursor(&aDocPos, false));
    4536             :                                     }
    4537             :                                     else
    4538             :                                     {
    4539           0 :                                         g_bValidCrsrPos = true;
    4540             :                                     }
    4541             :                                 }
    4542             :                                 else
    4543             :                                 {
    4544           0 :                                     rSh.ClickToField( *aContentAtPos.aFnd.pField );
    4545             :                                     // a bit of a mystery what this is good for?
    4546             :                                     // in this case we assume it's valid since we
    4547             :                                     // just selected a field
    4548           0 :                                     g_bValidCrsrPos = true;
    4549             :                                 }
    4550           0 :                                 if (bAddMode)
    4551             :                                 {
    4552           0 :                                     rSh.LeaveAddMode();
    4553             :                                 }
    4554             :                             }
    4555           0 :                             else if ( SwContentAtPos::SW_SMARTTAG == aContentAtPos.eContentAtPos )
    4556             :                             {
    4557             :                                     // execute smarttag menu
    4558           0 :                                     if ( bExecSmarttags && SwSmartTagMgr::Get().IsSmartTagsEnabled() )
    4559           0 :                                         m_rView.ExecSmartTagPopup( aDocPt );
    4560             :                             }
    4561           0 :                             else if ( SwContentAtPos::SW_FORMCTRL == aContentAtPos.eContentAtPos )
    4562             :                             {
    4563             :                                 OSL_ENSURE( aContentAtPos.aFnd.pFieldmark != NULL, "where is my field ptr???");
    4564           0 :                                 if ( aContentAtPos.aFnd.pFieldmark != NULL)
    4565             :                                 {
    4566           0 :                                     IFieldmark *fieldBM = const_cast< IFieldmark* > ( aContentAtPos.aFnd.pFieldmark );
    4567           0 :                                     if ( fieldBM->GetFieldname( ) == ODF_FORMCHECKBOX )
    4568             :                                     {
    4569           0 :                                         ICheckboxFieldmark& rCheckboxFm = dynamic_cast<ICheckboxFieldmark&>(*fieldBM);
    4570           0 :                                         rCheckboxFm.SetChecked(!rCheckboxFm.IsChecked());
    4571           0 :                                         rCheckboxFm.Invalidate();
    4572           0 :                                         rSh.InvalidateWindows( m_rView.GetVisArea() );
    4573           0 :                                     } else if ( fieldBM->GetFieldname() == ODF_FORMDROPDOWN ) {
    4574           0 :                                         m_rView.ExecFieldPopup( aDocPt, fieldBM );
    4575           0 :                                         fieldBM->Invalidate();
    4576           0 :                                         rSh.InvalidateWindows( m_rView.GetVisArea() );
    4577             :                                     } else {
    4578             :                                         // unknown type..
    4579             :                                     }
    4580             :                                 }
    4581             :                             }
    4582           0 :                             else if ( SwContentAtPos::SW_INETATTR == aContentAtPos.eContentAtPos )
    4583             :                             {
    4584           0 :                                 if ( bExecHyperlinks && aContentAtPos.aFnd.pAttr )
    4585           0 :                                     rSh.ClickToINetAttr( *static_cast<const SwFormatINetFormat*>(aContentAtPos.aFnd.pAttr), nFilter );
    4586             :                             }
    4587             : 
    4588           0 :                             rSh.LockView( bViewLocked );
    4589           0 :                             bCallShadowCrsr = false;
    4590             :                         }
    4591             :                         else
    4592             :                         {
    4593           1 :                             aContentAtPos = SwContentAtPos( SwContentAtPos::SW_FTN );
    4594           1 :                             if( !rSh.GetContentAtPos( aDocPt, aContentAtPos, true ) && bExecHyperlinks )
    4595             :                             {
    4596           0 :                                 SdrViewEvent aVEvt;
    4597             : 
    4598           0 :                                 if (pSdrView)
    4599           0 :                                     pSdrView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
    4600             : 
    4601           0 :                                 if (pSdrView && aVEvt.eEvent == SDREVENT_EXECUTEURL)
    4602             :                                 {
    4603             :                                     // hit URL field
    4604           0 :                                     const SvxURLField *pField = aVEvt.pURLField;
    4605           0 :                                     if (pField)
    4606             :                                     {
    4607           0 :                                         OUString sURL(pField->GetURL());
    4608           0 :                                         OUString sTarget(pField->GetTargetFrame());
    4609           0 :                                         ::LoadURL(rSh, sURL, nFilter, sTarget);
    4610             :                                     }
    4611           0 :                                     bCallShadowCrsr = false;
    4612             :                                 }
    4613             :                                 else
    4614             :                                 {
    4615             :                                     // hit graphic
    4616           0 :                                     ReleaseMouse();
    4617           0 :                                     if( rSh.ClickToINetGrf( aDocPt, nFilter ))
    4618           0 :                                         bCallShadowCrsr = false;
    4619           0 :                                 }
    4620             :                             }
    4621             :                         }
    4622             : 
    4623           1 :                         if( bCallShadowCrsr &&
    4624           0 :                             rSh.GetViewOptions()->IsShadowCursor() &&
    4625           0 :                             MOUSE_LEFT == (rMEvt.GetModifier() + rMEvt.GetButtons()) &&
    4626           0 :                             !rSh.HasSelection() &&
    4627           1 :                             !GetConnectMetaFile() &&
    4628           0 :                             rSh.VisArea().IsInside( aDocPt ))
    4629             :                         {
    4630           0 :                             SwUndoId nLastUndoId(UNDO_EMPTY);
    4631           0 :                             if (rSh.GetLastUndoInfo(0, & nLastUndoId))
    4632             :                             {
    4633           0 :                                 if (UNDO_INS_FROM_SHADOWCRSR == nLastUndoId)
    4634             :                                 {
    4635           0 :                                     rSh.Undo();
    4636             :                                 }
    4637             :                             }
    4638           0 :                             SwFillMode eMode = (SwFillMode)rSh.GetViewOptions()->GetShdwCrsrFillMode();
    4639           0 :                             rSh.SetShadowCrsrPos( aDocPt, eMode );
    4640           1 :                         }
    4641             :                     }
    4642             :                 }
    4643           1 :                 bCallBase = false;
    4644             : 
    4645             :             }
    4646             : 
    4647             :             // reset pushed mode in Down again if applicable
    4648           1 :             if ( bPopMode && g_bModePushed )
    4649             :             {
    4650           0 :                 rSh.PopMode();
    4651           0 :                 g_bModePushed = false;
    4652           0 :                 bCallBase = false;
    4653             :             }
    4654           1 :             break;
    4655             : 
    4656             :         default:
    4657           0 :             ReleaseMouse();
    4658           0 :             return;
    4659             :     }
    4660             : 
    4661           2 :     if( m_pApplyTempl )
    4662             :     {
    4663           0 :         int eSelection = rSh.GetSelectionType();
    4664           0 :         SwFormatClipboard* pFormatClipboard = m_pApplyTempl->m_pFormatClipboard;
    4665           0 :         if( pFormatClipboard )//apply format paintbrush
    4666             :         {
    4667             :             //get some parameters
    4668           0 :             SwWrtShell& rWrtShell = m_rView.GetWrtShell();
    4669           0 :             SfxStyleSheetBasePool* pPool=0;
    4670           0 :             bool bNoCharacterFormats = false;
    4671           0 :             bool bNoParagraphFormats = true;
    4672             :             {
    4673           0 :                 SwDocShell* pDocSh = m_rView.GetDocShell();
    4674           0 :                 if(pDocSh)
    4675           0 :                     pPool = pDocSh->GetStyleSheetPool();
    4676           0 :                 if( (rMEvt.GetModifier()&KEY_MOD1) && (rMEvt.GetModifier()&KEY_SHIFT) )
    4677             :                 {
    4678           0 :                     bNoCharacterFormats = true;
    4679           0 :                     bNoParagraphFormats = false;
    4680             :                 }
    4681           0 :                 else if( rMEvt.GetModifier() & KEY_MOD1 )
    4682           0 :                     bNoParagraphFormats = false;
    4683             :             }
    4684             :             //execute paste
    4685           0 :             pFormatClipboard->Paste( rWrtShell, pPool, bNoCharacterFormats, bNoParagraphFormats );
    4686             : 
    4687             :             //if the clipboard is empty after paste remove the ApplyTemplate
    4688           0 :             if(!pFormatClipboard->HasContent())
    4689           0 :                 SetApplyTemplate(SwApplyTemplate());
    4690             :         }
    4691           0 :         else if( m_pApplyTempl->nColor )
    4692             :         {
    4693           0 :             sal_uInt16 nId = 0;
    4694           0 :             switch( m_pApplyTempl->nColor )
    4695             :             {
    4696             :                 case SID_ATTR_CHAR_COLOR_EXT:
    4697             :                 case SID_ATTR_CHAR_COLOR2:
    4698           0 :                     nId = RES_CHRATR_COLOR;
    4699           0 :                     break;
    4700             :                 case SID_ATTR_CHAR_COLOR_BACKGROUND_EXT:
    4701             :                 case SID_ATTR_CHAR_COLOR_BACKGROUND:
    4702           0 :                     nId = RES_CHRATR_BACKGROUND;
    4703           0 :                     break;
    4704             :             }
    4705           0 :             if( nId && (nsSelectionType::SEL_TXT|nsSelectionType::SEL_TBL) & eSelection)
    4706             :             {
    4707           0 :                 if( rSh.IsSelection() && !rSh.HasReadonlySel() )
    4708             :                 {
    4709           0 :                     if(nId == RES_CHRATR_BACKGROUND)
    4710           0 :                         rSh.SetAttrItem( SvxBrushItem( SwEditWin::m_aWaterCanTextBackColor, nId ) );
    4711             :                     else
    4712           0 :                         rSh.SetAttrItem( SvxColorItem( SwEditWin::m_aWaterCanTextColor, nId ) );
    4713           0 :                     rSh.UnSetVisCrsr();
    4714           0 :                     rSh.EnterStdMode();
    4715           0 :                     rSh.SetVisCrsr(aDocPt);
    4716             : 
    4717           0 :                     m_pApplyTempl->bUndo = true;
    4718           0 :                     bCallBase = false;
    4719           0 :                     m_aTemplateIdle.Stop();
    4720             :                 }
    4721           0 :                 else if(rMEvt.GetClicks() == 1)
    4722             :                 {
    4723             :                     // no selection -> so turn off watering can
    4724           0 :                     m_aTemplateIdle.Start();
    4725             :                 }
    4726             :             }
    4727             :         }
    4728             :         else
    4729             :         {
    4730           0 :             OUString aStyleName;
    4731           0 :             switch ( m_pApplyTempl->eType )
    4732             :             {
    4733             :                 case SFX_STYLE_FAMILY_PARA:
    4734           0 :                     if( (( nsSelectionType::SEL_TXT | nsSelectionType::SEL_TBL )
    4735           0 :                          & eSelection ) && !rSh.HasReadonlySel() )
    4736             :                     {
    4737           0 :                         rSh.SetTextFormatColl( m_pApplyTempl->aColl.pTextColl );
    4738           0 :                         m_pApplyTempl->bUndo = true;
    4739           0 :                         bCallBase = false;
    4740           0 :                         if ( m_pApplyTempl->aColl.pTextColl )
    4741           0 :                             aStyleName = m_pApplyTempl->aColl.pTextColl->GetName();
    4742             :                     }
    4743           0 :                     break;
    4744             :                 case SFX_STYLE_FAMILY_CHAR:
    4745           0 :                     if( (( nsSelectionType::SEL_TXT | nsSelectionType::SEL_TBL )
    4746           0 :                          & eSelection ) && !rSh.HasReadonlySel() )
    4747             :                     {
    4748           0 :                         rSh.SetAttrItem( SwFormatCharFormat(m_pApplyTempl->aColl.pCharFormat) );
    4749           0 :                         rSh.UnSetVisCrsr();
    4750           0 :                         rSh.EnterStdMode();
    4751           0 :                         rSh.SetVisCrsr(aDocPt);
    4752           0 :                         m_pApplyTempl->bUndo = true;
    4753           0 :                         bCallBase = false;
    4754           0 :                         if ( m_pApplyTempl->aColl.pCharFormat )
    4755           0 :                             aStyleName = m_pApplyTempl->aColl.pCharFormat->GetName();
    4756             :                     }
    4757           0 :                     break;
    4758             :                 case SFX_STYLE_FAMILY_FRAME :
    4759             :                 {
    4760           0 :                     const SwFrameFormat* pFormat = rSh.GetFormatFromObj( aDocPt );
    4761           0 :                     if(PTR_CAST(SwFlyFrameFormat, pFormat))
    4762             :                     {
    4763           0 :                         rSh.SetFrameFormat( m_pApplyTempl->aColl.pFrameFormat, false, &aDocPt );
    4764           0 :                         m_pApplyTempl->bUndo = true;
    4765           0 :                         bCallBase = false;
    4766           0 :                         if( m_pApplyTempl->aColl.pFrameFormat )
    4767           0 :                             aStyleName = m_pApplyTempl->aColl.pFrameFormat->GetName();
    4768             :                     }
    4769           0 :                     break;
    4770             :                 }
    4771             :                 case SFX_STYLE_FAMILY_PAGE:
    4772             :                     // no Undo with page templates
    4773           0 :                     rSh.ChgCurPageDesc( *m_pApplyTempl->aColl.pPageDesc );
    4774           0 :                     if ( m_pApplyTempl->aColl.pPageDesc )
    4775           0 :                         aStyleName = m_pApplyTempl->aColl.pPageDesc->GetName();
    4776           0 :                     bCallBase = false;
    4777           0 :                     break;
    4778             :                 case SFX_STYLE_FAMILY_PSEUDO:
    4779           0 :                     if( !rSh.HasReadonlySel() )
    4780             :                     {
    4781             :                         rSh.SetCurNumRule( *m_pApplyTempl->aColl.pNumRule,
    4782             :                                            false,
    4783           0 :                                            m_pApplyTempl->aColl.pNumRule->GetDefaultListId() );
    4784           0 :                         bCallBase = false;
    4785           0 :                         m_pApplyTempl->bUndo = true;
    4786           0 :                         if( m_pApplyTempl->aColl.pNumRule )
    4787           0 :                             aStyleName = m_pApplyTempl->aColl.pNumRule->GetName();
    4788             :                     }
    4789           0 :                     break;
    4790             :             }
    4791             : 
    4792             :             uno::Reference< frame::XDispatchRecorder > xRecorder =
    4793           0 :                     m_rView.GetViewFrame()->GetBindings().GetRecorder();
    4794           0 :             if ( !aStyleName.isEmpty() && xRecorder.is() )
    4795             :             {
    4796           0 :                 SfxShell *pSfxShell = lcl_GetShellFromDispatcher( m_rView, TYPE(SwTextShell) );
    4797           0 :                 if ( pSfxShell )
    4798             :                 {
    4799           0 :                     SfxRequest aReq( m_rView.GetViewFrame(), SID_STYLE_APPLY );
    4800           0 :                     aReq.AppendItem( SfxStringItem( SID_STYLE_APPLY, aStyleName ) );
    4801           0 :                     aReq.AppendItem( SfxUInt16Item( SID_STYLE_FAMILY, (sal_uInt16) m_pApplyTempl->eType ) );
    4802           0 :                     aReq.Done();
    4803             :                 }
    4804           0 :             }
    4805             :         }
    4806             : 
    4807             :     }
    4808           2 :     ReleaseMouse();
    4809             :     // Only processed MouseEvents arrive here; only at these the moduses can
    4810             :     // be resetted.
    4811           2 :     m_bMBPressed = false;
    4812             : 
    4813             :     // Make this call just to be sure. Selecting has finished surely by now.
    4814             :     // Otherwise the timeout's timer could give problems.
    4815           2 :     EnterArea();
    4816           2 :     g_bNoInterrupt = false;
    4817             : 
    4818           2 :     if (bCallBase)
    4819           0 :         Window::MouseButtonUp(rMEvt);
    4820             : 
    4821           2 :     if (pSdrView && rMEvt.GetClicks() == 1 && rSh.isTiledRendering())
    4822             :     {
    4823             :         // When tiled rendering, single click on a shape text starts editing already.
    4824           2 :         SdrViewEvent aViewEvent;
    4825           2 :         SdrHitKind eHit = pSdrView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONUP, aViewEvent);
    4826           2 :         const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
    4827           2 :         if (eHit == SDRHIT_TEXTEDITOBJ && rMarkList.GetMarkCount() == 1)
    4828             :         {
    4829           0 :             if (SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj())
    4830             :             {
    4831           0 :                 EnterDrawTextMode(pObj->GetLogicRect().Center());
    4832           0 :                 if (m_rView.GetCurShell()->ISA(SwDrawTextShell))
    4833           0 :                     static_cast<SwDrawTextShell*>(m_rView.GetCurShell())->Init();
    4834             :             }
    4835           2 :         }
    4836           2 :     }
    4837             : }
    4838             : 
    4839             : /**
    4840             :  * Apply template
    4841             :  */
    4842           0 : void SwEditWin::SetApplyTemplate(const SwApplyTemplate &rTempl)
    4843             : {
    4844             :     static bool bIdle = false;
    4845           0 :     DELETEZ(m_pApplyTempl);
    4846           0 :     SwWrtShell &rSh = m_rView.GetWrtShell();
    4847             : 
    4848           0 :     if(rTempl.m_pFormatClipboard)
    4849             :     {
    4850           0 :         m_pApplyTempl = new SwApplyTemplate( rTempl );
    4851           0 :               SetPointer( PointerStyle::Fill );//@todo #i20119# maybe better a new brush pointer here in future
    4852           0 :               rSh.NoEdit( false );
    4853           0 :               bIdle = rSh.GetViewOptions()->IsIdle();
    4854           0 :               rSh.GetViewOptions()->SetIdle( false );
    4855             :     }
    4856           0 :     else if(rTempl.nColor)
    4857             :     {
    4858           0 :         m_pApplyTempl = new SwApplyTemplate( rTempl );
    4859           0 :         SetPointer( PointerStyle::Fill );
    4860           0 :         rSh.NoEdit( false );
    4861           0 :         bIdle = rSh.GetViewOptions()->IsIdle();
    4862           0 :         rSh.GetViewOptions()->SetIdle( false );
    4863             :     }
    4864           0 :     else if( rTempl.eType )
    4865             :     {
    4866           0 :         m_pApplyTempl = new SwApplyTemplate( rTempl );
    4867           0 :         SetPointer( PointerStyle::Fill  );
    4868           0 :         rSh.NoEdit( false );
    4869           0 :         bIdle = rSh.GetViewOptions()->IsIdle();
    4870           0 :         rSh.GetViewOptions()->SetIdle( false );
    4871             :     }
    4872             :     else
    4873             :     {
    4874           0 :         SetPointer( PointerStyle::Text );
    4875           0 :         rSh.UnSetVisCrsr();
    4876             : 
    4877           0 :         rSh.GetViewOptions()->SetIdle( bIdle );
    4878           0 :         if ( !rSh.IsSelFrmMode() )
    4879           0 :             rSh.Edit();
    4880             :     }
    4881             : 
    4882             :     static sal_uInt16 aInva[] =
    4883             :     {
    4884             :         SID_STYLE_WATERCAN,
    4885             :         SID_ATTR_CHAR_COLOR_EXT,
    4886             :         SID_ATTR_CHAR_COLOR_BACKGROUND_EXT,
    4887             :         0
    4888             :     };
    4889           0 :     m_rView.GetViewFrame()->GetBindings().Invalidate(aInva);
    4890           0 : }
    4891             : 
    4892             : /**
    4893             :  * Ctor
    4894             :  */
    4895        2761 : SwEditWin::SwEditWin(vcl::Window *pParent, SwView &rMyView):
    4896             :     Window(pParent, WinBits(WB_CLIPCHILDREN | WB_DIALOGCONTROL)),
    4897             :     DropTargetHelper( this ),
    4898             :     DragSourceHelper( this ),
    4899             : 
    4900             :     m_eBufferLanguage(LANGUAGE_DONTKNOW),
    4901             :     m_pApplyTempl(0),
    4902             :     m_pAnchorMarker( 0 ),
    4903             :     m_pUserMarker( 0 ),
    4904             :     m_pUserMarkerObj( 0 ),
    4905             :     m_pShadCrsr( 0 ),
    4906             :     m_pRowColumnSelectionStart( 0 ),
    4907             : 
    4908             :     m_rView( rMyView ),
    4909             : 
    4910             :     m_aActHitType(SDRHIT_NONE),
    4911             :     m_nDropFormat( SotClipboardFormatId::NONE ),
    4912             :     m_nDropAction( 0 ),
    4913             :     m_nDropDestination( SotExchangeDest::NONE ),
    4914             : 
    4915             :     m_eBezierMode(SID_BEZIER_INSERT),
    4916             :     m_nInsFrmColCount( 1 ),
    4917             :     m_eDrawMode(OBJ_NONE),
    4918             : 
    4919             :     m_bMBPressed(false),
    4920             :     m_bInsDraw(false),
    4921             :     m_bInsFrm(false),
    4922             :     m_bIsInMove(false),
    4923             :     m_bIsInDrag(false),
    4924             :     m_bOldIdle(false),
    4925             :     m_bOldIdleSet(false),
    4926             :     m_bTableInsDelMode(false),
    4927             :     m_bTableIsInsMode(false),
    4928             :     m_bChainMode(false),
    4929             :     m_bWasShdwCrsr(false),
    4930             :     m_bLockInput(false),
    4931             :     m_bIsRowDrag(false),
    4932             :     m_bUseInputLanguage(false),
    4933             :     m_bObjectSelect(false),
    4934             :     m_nKS_NUMDOWN_Count(0),
    4935             :     m_nKS_NUMINDENTINC_Count(0),
    4936        2761 :     m_aFrameControlsManager( this )
    4937             : {
    4938        2761 :     SetHelpId(HID_EDIT_WIN);
    4939        2761 :     EnableChildTransparentMode();
    4940        2761 :     SetDialogControlFlags( DialogControlFlags::Return | DialogControlFlags::WantFocus );
    4941             : 
    4942             :     m_bMBPressed = m_bInsDraw = m_bInsFrm =
    4943        2761 :     m_bIsInDrag = m_bOldIdle = m_bOldIdleSet = m_bChainMode = m_bWasShdwCrsr = false;
    4944             :     // initially use the input language
    4945        2761 :     m_bUseInputLanguage = true;
    4946             : 
    4947        2761 :     SetMapMode(MapMode(MAP_TWIP));
    4948             : 
    4949        2761 :     SetPointer( PointerStyle::Text );
    4950        2761 :     m_aTimer.SetTimeoutHdl(LINK(this, SwEditWin, TimerHandler));
    4951             : 
    4952        2761 :     m_bTableInsDelMode = false;
    4953        2761 :     m_aKeyInputTimer.SetTimeout( 3000 );
    4954        2761 :     m_aKeyInputTimer.SetTimeoutHdl(LINK(this, SwEditWin, KeyInputTimerHandler));
    4955             : 
    4956        2761 :     m_aKeyInputFlushTimer.SetTimeout( 200 );
    4957        2761 :     m_aKeyInputFlushTimer.SetTimeoutHdl(LINK(this, SwEditWin, KeyInputFlushHandler));
    4958             : 
    4959             :     // TemplatePointer for colors should be resetted without
    4960             :     // selection after single click
    4961        2761 :     m_aTemplateIdle.SetPriority(SchedulerPriority::LOWEST);
    4962        2761 :     m_aTemplateIdle.SetIdleHdl(LINK(this, SwEditWin, TemplateTimerHdl));
    4963             : 
    4964             :     // temporary solution!!! Should set the font of the current
    4965             :     // insert position at every cursor movement!
    4966        2761 :     if( !rMyView.GetDocShell()->IsReadOnly() )
    4967             :     {
    4968        2760 :         vcl::Font aFont;
    4969        5520 :         SetInputContext( InputContext( aFont, InputContextFlags::Text |
    4970        5520 :                                             InputContextFlags::ExtText ) );
    4971             :     }
    4972        2761 : }
    4973             : 
    4974           0 : SwEditWin::~SwEditWin()
    4975             : {
    4976           0 :     disposeOnce();
    4977           0 : }
    4978             : 
    4979        2757 : void SwEditWin::dispose()
    4980             : {
    4981        2757 :     m_aKeyInputTimer.Stop();
    4982             : 
    4983        2757 :     delete m_pShadCrsr;
    4984        2757 :     m_pShadCrsr = NULL;
    4985             : 
    4986        2757 :     delete m_pRowColumnSelectionStart;
    4987        2757 :     m_pRowColumnSelectionStart = NULL;
    4988             : 
    4989        2757 :     if( m_pQuickHlpData->m_bIsDisplayed && m_rView.GetWrtShellPtr() )
    4990           0 :         m_pQuickHlpData->Stop( m_rView.GetWrtShell() );
    4991        2757 :     g_bExecuteDrag = false;
    4992        2757 :     delete m_pApplyTempl;
    4993        2757 :     m_pApplyTempl = NULL;
    4994             : 
    4995        2757 :     m_rView.SetDrawFuncPtr(NULL);
    4996             : 
    4997        2757 :     delete m_pUserMarker;
    4998        2757 :     m_pUserMarker = NULL;
    4999             : 
    5000        2757 :     delete m_pAnchorMarker;
    5001        2757 :     m_pAnchorMarker = NULL;
    5002             : 
    5003        2757 :     m_aFrameControlsManager.dispose();
    5004             : 
    5005        2757 :     vcl::Window::dispose();
    5006        2757 : }
    5007             : 
    5008             : /**
    5009             :  * Turn on DrawTextEditMode
    5010             :  */
    5011           0 : void SwEditWin::EnterDrawTextMode( const Point& aDocPos )
    5012             : {
    5013           0 :     if ( m_rView.EnterDrawTextMode(aDocPos) )
    5014             :     {
    5015           0 :         if (m_rView.GetDrawFuncPtr())
    5016             :         {
    5017           0 :             m_rView.GetDrawFuncPtr()->Deactivate();
    5018           0 :             m_rView.SetDrawFuncPtr(NULL);
    5019           0 :             m_rView.LeaveDrawCreate();
    5020             :         }
    5021           0 :         m_rView.NoRotate();
    5022           0 :         m_rView.AttrChangedNotify( &m_rView.GetWrtShell() );
    5023             :     }
    5024           0 : }
    5025             : 
    5026             : /**
    5027             :  * Turn on DrawMode
    5028             :  */
    5029           2 : bool SwEditWin::EnterDrawMode(const MouseEvent& rMEvt, const Point& aDocPos)
    5030             : {
    5031           2 :     SwWrtShell &rSh = m_rView.GetWrtShell();
    5032           2 :     SdrView *pSdrView = rSh.GetDrawView();
    5033             : 
    5034           2 :     if ( m_rView.GetDrawFuncPtr() )
    5035             :     {
    5036           0 :         if (rSh.IsDrawCreate())
    5037           0 :             return true;
    5038             : 
    5039           0 :         bool bRet = m_rView.GetDrawFuncPtr()->MouseButtonDown( rMEvt );
    5040           0 :         m_rView.AttrChangedNotify( &rSh );
    5041           0 :         return bRet;
    5042             :     }
    5043             : 
    5044           2 :     if ( pSdrView && pSdrView->IsTextEdit() )
    5045             :     {
    5046           0 :         bool bUnLockView = !rSh.IsViewLocked();
    5047           0 :         rSh.LockView( true );
    5048             : 
    5049           0 :         rSh.EndTextEdit(); // clicked aside, end Edit
    5050           0 :         rSh.SelectObj( aDocPos );
    5051           0 :         if ( !rSh.IsObjSelected() && !rSh.IsFrmSelected() )
    5052           0 :             rSh.LeaveSelFrmMode();
    5053             :         else
    5054             :         {
    5055           0 :             SwEditWin::m_nDDStartPosY = aDocPos.Y();
    5056           0 :             SwEditWin::m_nDDStartPosX = aDocPos.X();
    5057           0 :             g_bFrmDrag = true;
    5058             :         }
    5059           0 :         if( bUnLockView )
    5060           0 :             rSh.LockView( false );
    5061           0 :         m_rView.AttrChangedNotify( &rSh );
    5062           0 :         return true;
    5063             :     }
    5064           2 :     return false;
    5065             : }
    5066             : 
    5067           0 : bool SwEditWin::IsDrawSelMode()
    5068             : {
    5069           0 :     return IsObjectSelect();
    5070             : }
    5071             : 
    5072        2466 : void SwEditWin::GetFocus()
    5073             : {
    5074        2466 :     if ( m_rView.GetPostItMgr()->HasActiveSidebarWin() )
    5075             :     {
    5076           0 :         m_rView.GetPostItMgr()->GrabFocusOnActiveSidebarWin();
    5077             :     }
    5078             :     else
    5079             :     {
    5080        2466 :         m_rView.GotFocus();
    5081        2466 :         Window::GetFocus();
    5082        2466 :         m_rView.GetWrtShell().InvalidateAccessibleFocus();
    5083             :     }
    5084        2466 : }
    5085             : 
    5086        2465 : void SwEditWin::LoseFocus()
    5087             : {
    5088        2465 :     if (m_rView.GetWrtShellPtr())
    5089        2465 :         m_rView.GetWrtShell().InvalidateAccessibleFocus();
    5090        2465 :     Window::LoseFocus();
    5091        2465 :     if( m_pQuickHlpData && m_pQuickHlpData->m_bIsDisplayed )
    5092           0 :         m_pQuickHlpData->Stop( m_rView.GetWrtShell() );
    5093        2465 : }
    5094             : 
    5095           0 : void SwEditWin::Command( const CommandEvent& rCEvt )
    5096             : {
    5097           0 :     SwWrtShell &rSh = m_rView.GetWrtShell();
    5098             : 
    5099           0 :     if ( !m_rView.GetViewFrame() )
    5100             :     {
    5101             :         // If ViewFrame dies shortly, no popup anymore!
    5102           0 :         Window::Command(rCEvt);
    5103           0 :         return;
    5104             :     }
    5105             : 
    5106             :     // The command event is send to the window after a possible context
    5107             :     // menu from an inplace client has been closed. Now we have the chance
    5108             :     // to deactivate the inplace client without any problem regarding parent
    5109             :     // windows and code on the stack.
    5110           0 :     SfxInPlaceClient* pIPClient = rSh.GetSfxViewShell()->GetIPClient();
    5111           0 :     bool bIsOleActive = ( pIPClient && pIPClient->IsObjectInPlaceActive() );
    5112           0 :     if ( bIsOleActive && ( rCEvt.GetCommand() == CommandEventId::ContextMenu ))
    5113             :     {
    5114           0 :         rSh.FinishOLEObj();
    5115           0 :         return;
    5116             :     }
    5117             : 
    5118           0 :     bool bCallBase      = true;
    5119             : 
    5120           0 :     switch ( rCEvt.GetCommand() )
    5121             :     {
    5122             :     case CommandEventId::ContextMenu:
    5123             :     {
    5124           0 :             const sal_uInt16 nId = SwInputChild::GetChildWindowId();
    5125           0 :             SwInputChild* pChildWin = static_cast<SwInputChild*>(GetView().GetViewFrame()->
    5126           0 :                                                 GetChildWindow( nId ));
    5127             : 
    5128           0 :             if (m_rView.GetPostItMgr()->IsHit(rCEvt.GetMousePosPixel()))
    5129           0 :                 return;
    5130             : 
    5131           0 :             Point aDocPos( PixelToLogic( rCEvt.GetMousePosPixel() ) );
    5132           0 :             if ( !rCEvt.IsMouseEvent() )
    5133           0 :                 aDocPos = rSh.GetCharRect().Center();
    5134             : 
    5135             :             // Don't trigger the command on a frame anchored to header/footer is not editing it
    5136             :             FrameControlType eControl;
    5137           0 :             bool bOverFly = false;
    5138           0 :             bool bPageAnchored = false;
    5139           0 :             bool bOverHeaderFooterFly = IsOverHeaderFooterFly( aDocPos, eControl, bOverFly, bPageAnchored );
    5140             :             // !bOverHeaderFooterFly doesn't mean we have a frame to select
    5141           0 :             if ( !bPageAnchored && rCEvt.IsMouseEvent( ) &&
    5142           0 :                  ( ( rSh.IsHeaderFooterEdit( ) && !bOverHeaderFooterFly && bOverFly ) ||
    5143           0 :                    ( !rSh.IsHeaderFooterEdit( ) && bOverHeaderFooterFly ) ) )
    5144             :             {
    5145           0 :                 return;
    5146             :             }
    5147             : 
    5148           0 :             if((!pChildWin || pChildWin->GetView() != &m_rView) &&
    5149           0 :                 !rSh.IsDrawCreate() && !IsDrawAction())
    5150             :             {
    5151           0 :                 SET_CURR_SHELL( &rSh );
    5152           0 :                 if (!m_pApplyTempl)
    5153             :                 {
    5154           0 :                     if (g_bNoInterrupt)
    5155             :                     {
    5156           0 :                         ReleaseMouse();
    5157           0 :                         g_bNoInterrupt = false;
    5158           0 :                         m_bMBPressed = false;
    5159             :                     }
    5160           0 :                     if ( rCEvt.IsMouseEvent() )
    5161             :                     {
    5162           0 :                         SelectMenuPosition(rSh, rCEvt.GetMousePosPixel());
    5163           0 :                         m_rView.StopShellTimer();
    5164             :                     }
    5165           0 :                     const Point aPixPos = LogicToPixel( aDocPos );
    5166             : 
    5167           0 :                     if ( m_rView.GetDocShell()->IsReadOnly() )
    5168             :                     {
    5169           0 :                         boost::scoped_ptr<SwReadOnlyPopup> pROPopup(new SwReadOnlyPopup( aDocPos, m_rView ));
    5170             : 
    5171           0 :                         ui::ContextMenuExecuteEvent aEvent;
    5172           0 :                         aEvent.SourceWindow = VCLUnoHelper::GetInterface( this );
    5173           0 :                         aEvent.ExecutePosition.X = aPixPos.X();
    5174           0 :                         aEvent.ExecutePosition.Y = aPixPos.Y();
    5175           0 :                         Menu* pMenu = 0;
    5176           0 :                         OUString sMenuName("private:resource/ReadonlyContextMenu");
    5177           0 :                         if( GetView().TryContextMenuInterception( *pROPopup, sMenuName, pMenu, aEvent ) )
    5178             :                         {
    5179           0 :                             if ( pMenu )
    5180             :                             {
    5181           0 :                                 sal_uInt16 nExecId = static_cast<PopupMenu*>(pMenu)->Execute(this, aPixPos);
    5182           0 :                                 if( !::ExecuteMenuCommand( *static_cast<PopupMenu*>(pMenu), *m_rView.GetViewFrame(), nExecId ))
    5183           0 :                                     pROPopup->Execute(this, nExecId);
    5184             :                             }
    5185             :                             else
    5186           0 :                                 pROPopup->Execute(this, aPixPos);
    5187           0 :                         }
    5188             :                     }
    5189           0 :                     else if ( !m_rView.ExecSpellPopup( aDocPos ) )
    5190           0 :                         SfxDispatcher::ExecutePopup( 0, this, &aPixPos);
    5191             :                 }
    5192           0 :                 else if (m_pApplyTempl->bUndo)
    5193           0 :                     rSh.Do(SwWrtShell::UNDO);
    5194           0 :                 bCallBase = false;
    5195             :             }
    5196             :     }
    5197           0 :     break;
    5198             : 
    5199             :     case CommandEventId::Wheel:
    5200             :     case CommandEventId::StartAutoScroll:
    5201             :     case CommandEventId::AutoScroll:
    5202           0 :             if( m_pShadCrsr )
    5203           0 :                 delete m_pShadCrsr, m_pShadCrsr = 0;
    5204           0 :             bCallBase = !m_rView.HandleWheelCommands( rCEvt );
    5205           0 :             break;
    5206             : 
    5207             :     case CommandEventId::StartExtTextInput:
    5208             :     {
    5209           0 :         bool bIsDocReadOnly = m_rView.GetDocShell()->IsReadOnly() &&
    5210           0 :                               rSh.IsCrsrReadonly();
    5211           0 :         if(!bIsDocReadOnly)
    5212             :         {
    5213           0 :             if( rSh.HasDrawView() && rSh.GetDrawView()->IsTextEdit() )
    5214             :             {
    5215           0 :                 bCallBase = false;
    5216           0 :                 rSh.GetDrawView()->GetTextEditOutlinerView()->Command( rCEvt );
    5217             :             }
    5218             :             else
    5219             :             {
    5220           0 :                 if( rSh.HasSelection() )
    5221           0 :                     rSh.DelRight();
    5222             : 
    5223           0 :                 bCallBase = false;
    5224           0 :                 LanguageType eInputLanguage = GetInputLanguage();
    5225           0 :                 rSh.CreateExtTextInput(eInputLanguage);
    5226             :             }
    5227             :         }
    5228           0 :         break;
    5229             :     }
    5230             :     case CommandEventId::EndExtTextInput:
    5231             :     {
    5232           0 :         bool bIsDocReadOnly = m_rView.GetDocShell()->IsReadOnly() &&
    5233           0 :                               rSh.IsCrsrReadonly();
    5234           0 :         if(!bIsDocReadOnly)
    5235             :         {
    5236           0 :             if( rSh.HasDrawView() && rSh.GetDrawView()->IsTextEdit() )
    5237             :             {
    5238           0 :                 bCallBase = false;
    5239           0 :                 rSh.GetDrawView()->GetTextEditOutlinerView()->Command( rCEvt );
    5240             :             }
    5241             :             else
    5242             :             {
    5243           0 :                 bCallBase = false;
    5244           0 :                 OUString sRecord = rSh.DeleteExtTextInput();
    5245             :                 uno::Reference< frame::XDispatchRecorder > xRecorder =
    5246           0 :                         m_rView.GetViewFrame()->GetBindings().GetRecorder();
    5247             : 
    5248           0 :                 if ( !sRecord.isEmpty() )
    5249             :                 {
    5250             :                     // convert quotes in IME text
    5251             :                     // works on the last input character, this is escpecially in Korean text often done
    5252             :                     // quotes that are inside of the string are not replaced!
    5253           0 :                     const sal_Unicode aCh = sRecord[sRecord.getLength() - 1];
    5254           0 :                     SvxAutoCorrCfg& rACfg = SvxAutoCorrCfg::Get();
    5255           0 :                     SvxAutoCorrect* pACorr = rACfg.GetAutoCorrect();
    5256           0 :                     if(pACorr &&
    5257           0 :                         (( pACorr->IsAutoCorrFlag( ChgQuotes ) && ('\"' == aCh ))||
    5258           0 :                         ( pACorr->IsAutoCorrFlag( ChgSglQuotes ) && ( '\'' == aCh))))
    5259             :                     {
    5260           0 :                         rSh.DelLeft();
    5261           0 :                         rSh.AutoCorrect( *pACorr, aCh );
    5262             :                     }
    5263             : 
    5264           0 :                     if ( xRecorder.is() )
    5265             :                     {
    5266             :                         // determine Shell
    5267           0 :                         SfxShell *pSfxShell = lcl_GetShellFromDispatcher( m_rView, TYPE(SwTextShell) );
    5268             :                         // generate request and record
    5269           0 :                         if (pSfxShell)
    5270             :                         {
    5271           0 :                             SfxRequest aReq( m_rView.GetViewFrame(), FN_INSERT_STRING );
    5272           0 :                             aReq.AppendItem( SfxStringItem( FN_INSERT_STRING, sRecord ) );
    5273           0 :                             aReq.Done();
    5274             :                         }
    5275             :                     }
    5276           0 :                 }
    5277             :             }
    5278             :         }
    5279             :     }
    5280           0 :     break;
    5281             :     case CommandEventId::ExtTextInput:
    5282             :     {
    5283           0 :         bool bIsDocReadOnly = m_rView.GetDocShell()->IsReadOnly() &&
    5284           0 :                               rSh.IsCrsrReadonly();
    5285           0 :         if(!bIsDocReadOnly)
    5286             :         {
    5287           0 :             if( m_pQuickHlpData->m_bIsDisplayed )
    5288           0 :                 m_pQuickHlpData->Stop( rSh );
    5289             : 
    5290           0 :             OUString sWord;
    5291           0 :             if( rSh.HasDrawView() && rSh.GetDrawView()->IsTextEdit() )
    5292             :             {
    5293           0 :                 bCallBase = false;
    5294           0 :                 rSh.GetDrawView()->GetTextEditOutlinerView()->Command( rCEvt );
    5295             :             }
    5296             :             else
    5297             :             {
    5298           0 :                 const CommandExtTextInputData* pData = rCEvt.GetExtTextInputData();
    5299           0 :                 if( pData )
    5300             :                 {
    5301           0 :                     sWord = pData->GetText();
    5302           0 :                     bCallBase = false;
    5303           0 :                     rSh.SetExtTextInputData( *pData );
    5304             :                 }
    5305             :             }
    5306             :                 uno::Reference< frame::XDispatchRecorder > xRecorder =
    5307           0 :                         m_rView.GetViewFrame()->GetBindings().GetRecorder();
    5308           0 :                 if(!xRecorder.is())
    5309             :                 {
    5310           0 :                     SvxAutoCorrCfg& rACfg = SvxAutoCorrCfg::Get();
    5311           0 :                     SvxAutoCorrect* pACorr = rACfg.GetAutoCorrect();
    5312           0 :                     if( pACorr &&
    5313             :                         // If autocompletion required...
    5314           0 :                         ( rACfg.IsAutoTextTip() ||
    5315           0 :                           pACorr->GetSwFlags().bAutoCompleteWords ) &&
    5316             :                         // ... and extraction of last word from text input was successful...
    5317           0 :                         rSh.GetPrevAutoCorrWord( *pACorr, sWord ) )
    5318             :                     {
    5319             :                         // ... request for auto completion help to be shown.
    5320           0 :                         ShowAutoTextCorrectQuickHelp(sWord, &rACfg, pACorr, true);
    5321             :                     }
    5322           0 :                 }
    5323             :         }
    5324             :     }
    5325           0 :     break;
    5326             :     case CommandEventId::CursorPos:
    5327             :         // will be handled by the base class
    5328           0 :         break;
    5329             : 
    5330             :     case CommandEventId::PasteSelection:
    5331           0 :         if( !m_rView.GetDocShell()->IsReadOnly() )
    5332             :         {
    5333             :             TransferableDataHelper aDataHelper(
    5334           0 :                         TransferableDataHelper::CreateFromSelection( this ));
    5335           0 :             if( !aDataHelper.GetXTransferable().is() )
    5336           0 :                 break;
    5337             : 
    5338             :             SotClipboardFormatId nDropFormat;
    5339             :             sal_uInt16 nEventAction, nDropAction;
    5340             :             SotExchangeDest nDropDestination;
    5341           0 :             nDropDestination = GetDropDestination( rCEvt.GetMousePosPixel() );
    5342           0 :             if( !bool(nDropDestination) )
    5343           0 :                 break;
    5344             : 
    5345             :             nDropAction = SotExchange::GetExchangeAction(
    5346           0 :                                 aDataHelper.GetDataFlavorExVector(),
    5347             :                                 nDropDestination, EXCHG_IN_ACTION_COPY,
    5348             :                                 EXCHG_IN_ACTION_COPY, nDropFormat,
    5349           0 :                                 nEventAction );
    5350           0 :             if( EXCHG_INOUT_ACTION_NONE != nDropAction )
    5351             :             {
    5352           0 :                 const Point aDocPt( PixelToLogic( rCEvt.GetMousePosPixel() ) );
    5353             :                 SwTransferable::PasteData( aDataHelper, rSh, nDropAction,
    5354             :                                     nDropFormat, nDropDestination, false,
    5355             :                                     false, &aDocPt, EXCHG_IN_ACTION_COPY,
    5356           0 :                                     true );
    5357           0 :             }
    5358             :         }
    5359           0 :         break;
    5360             :         case CommandEventId::ModKeyChange :
    5361             :         {
    5362           0 :             const CommandModKeyData* pCommandData = rCEvt.GetModKeyData();
    5363           0 :             if (pCommandData->IsMod1() && !pCommandData->IsMod2())
    5364             :             {
    5365           0 :                 sal_uInt16 nSlot = 0;
    5366           0 :                 if(pCommandData->IsLeftShift() && !pCommandData->IsRightShift())
    5367           0 :                     nSlot = SID_ATTR_PARA_LEFT_TO_RIGHT;
    5368           0 :                 else if(!pCommandData->IsLeftShift() && pCommandData->IsRightShift())
    5369           0 :                     nSlot = SID_ATTR_PARA_RIGHT_TO_LEFT;
    5370           0 :                 if(nSlot && SW_MOD()->GetCTLOptions().IsCTLFontEnabled())
    5371           0 :                     GetView().GetViewFrame()->GetDispatcher()->Execute(nSlot);
    5372             :             }
    5373             :         }
    5374           0 :         break;
    5375             :         case CommandEventId::HangulHanjaConversion :
    5376           0 :             GetView().GetViewFrame()->GetDispatcher()->Execute(SID_HANGUL_HANJA_CONVERSION);
    5377           0 :         break;
    5378             :         case CommandEventId::InputLanguageChange :
    5379             :             // i#42732 - update state of fontname if input language changes
    5380           0 :             g_bInputLanguageSwitched = true;
    5381           0 :             SetUseInputLanguage( true );
    5382           0 :         break;
    5383             :         case CommandEventId::SelectionChange:
    5384             :         {
    5385           0 :             const CommandSelectionChangeData *pData = rCEvt.GetSelectionChangeData();
    5386           0 :             rSh.SttCrsrMove();
    5387           0 :             rSh.GoStartSentence();
    5388           0 :             rSh.GetCrsr()->GetPoint()->nContent += sal::static_int_cast<sal_uInt16, sal_uLong>(pData->GetStart());
    5389           0 :             rSh.SetMark();
    5390           0 :             rSh.GetCrsr()->GetMark()->nContent += sal::static_int_cast<sal_uInt16, sal_uLong>(pData->GetEnd() - pData->GetStart());
    5391           0 :             rSh.EndCrsrMove( true );
    5392             :         }
    5393           0 :         break;
    5394             :         case CommandEventId::PrepareReconversion:
    5395           0 :         if( rSh.HasSelection() )
    5396             :         {
    5397           0 :             SwPaM *pCrsr = rSh.GetCrsr();
    5398             : 
    5399           0 :             if( rSh.IsMultiSelection() )
    5400             :             {
    5401           0 :                 if (pCrsr && !pCrsr->HasMark() &&
    5402           0 :                     pCrsr->GetPoint() == pCrsr->GetMark())
    5403             :                 {
    5404           0 :                     rSh.GoPrevCrsr();
    5405           0 :                     pCrsr = rSh.GetCrsr();
    5406             :                 }
    5407             : 
    5408             :                 // Cancel all selections other than the last selected one.
    5409           0 :                 while( rSh.GetCrsr()->GetNext() != rSh.GetCrsr() )
    5410           0 :                     delete rSh.GetCrsr()->GetNext();
    5411             :             }
    5412             : 
    5413           0 :             if( pCrsr )
    5414             :             {
    5415           0 :                 sal_uLong nPosNodeIdx = pCrsr->GetPoint()->nNode.GetIndex();
    5416           0 :                 const sal_Int32 nPosIdx = pCrsr->GetPoint()->nContent.GetIndex();
    5417           0 :                 sal_uLong nMarkNodeIdx = pCrsr->GetMark()->nNode.GetIndex();
    5418           0 :                 const sal_Int32 nMarkIdx = pCrsr->GetMark()->nContent.GetIndex();
    5419             : 
    5420           0 :                 if( !rSh.GetCrsr()->HasMark() )
    5421           0 :                     rSh.GetCrsr()->SetMark();
    5422             : 
    5423           0 :                 rSh.SttCrsrMove();
    5424             : 
    5425           0 :                 if( nPosNodeIdx < nMarkNodeIdx )
    5426             :                 {
    5427           0 :                 rSh.GetCrsr()->GetPoint()->nNode = nPosNodeIdx;
    5428           0 :                 rSh.GetCrsr()->GetPoint()->nContent = nPosIdx;
    5429           0 :                 rSh.GetCrsr()->GetMark()->nNode = nPosNodeIdx;
    5430           0 :                 rSh.GetCrsr()->GetMark()->nContent =
    5431           0 :                     rSh.GetCrsr()->GetContentNode( true )->Len();
    5432             :                 }
    5433           0 :                 else if( nPosNodeIdx == nMarkNodeIdx )
    5434             :                 {
    5435           0 :                 rSh.GetCrsr()->GetPoint()->nNode = nPosNodeIdx;
    5436           0 :                 rSh.GetCrsr()->GetPoint()->nContent = nPosIdx;
    5437           0 :                 rSh.GetCrsr()->GetMark()->nNode = nMarkNodeIdx;
    5438           0 :                 rSh.GetCrsr()->GetMark()->nContent = nMarkIdx;
    5439             :                 }
    5440             :                 else
    5441             :                 {
    5442           0 :                 rSh.GetCrsr()->GetMark()->nNode = nMarkNodeIdx;
    5443           0 :                 rSh.GetCrsr()->GetMark()->nContent = nMarkIdx;
    5444           0 :                 rSh.GetCrsr()->GetPoint()->nNode = nMarkNodeIdx;
    5445           0 :                 rSh.GetCrsr()->GetPoint()->nContent =
    5446           0 :                     rSh.GetCrsr()->GetContentNode( false )->Len();
    5447             :                 }
    5448             : 
    5449           0 :                 rSh.EndCrsrMove( true );
    5450             :             }
    5451             :         }
    5452           0 :         break;
    5453             :         case CommandEventId::QueryCharPosition:
    5454             :         {
    5455           0 :             bool bVertical = rSh.IsInVerticalText();
    5456           0 :             const SwPosition& rPos = *rSh.GetCrsr()->GetPoint();
    5457           0 :             SwDocShell* pDocSh = m_rView.GetDocShell();
    5458           0 :             SwDoc *pDoc = pDocSh->GetDoc();
    5459           0 :             SwExtTextInput* pInput = pDoc->GetExtTextInput( rPos.nNode.GetNode(), rPos.nContent.GetIndex() );
    5460           0 :             if ( pInput )
    5461             :             {
    5462           0 :                 const SwPosition& rStart = *pInput->Start();
    5463           0 :                 const SwPosition& rEnd = *pInput->End();
    5464           0 :                 int nSize = 0;
    5465           0 :                 for ( SwIndex nIndex = rStart.nContent; nIndex < rEnd.nContent; ++nIndex )
    5466             :                 {
    5467           0 :                     ++nSize;
    5468           0 :                 }
    5469           0 :                 vcl::Window& rWin = rSh.GetView().GetEditWin();
    5470           0 :                 if ( nSize == 0 )
    5471             :                 {
    5472             :                     // When the composition does not exist, use Caret rect instead.
    5473           0 :                     SwRect aCaretRect ( rSh.GetCharRect() );
    5474           0 :                     Rectangle aRect( aCaretRect.Left(), aCaretRect.Top(), aCaretRect.Right(), aCaretRect.Bottom() );
    5475           0 :                     rWin.SetCompositionCharRect( &aRect, 1, bVertical );
    5476             :                 }
    5477             :                 else
    5478             :                 {
    5479           0 :                     boost::scoped_array<Rectangle> aRects(new Rectangle[ nSize ]);
    5480           0 :                     int nRectIndex = 0;
    5481           0 :                     for ( SwIndex nIndex = rStart.nContent; nIndex < rEnd.nContent; ++nIndex )
    5482             :                     {
    5483           0 :                         const SwPosition aPos( rStart.nNode, nIndex );
    5484           0 :                         SwRect aRect ( rSh.GetCharRect() );
    5485           0 :                         rSh.GetCharRectAt( aRect, &aPos );
    5486           0 :                         aRects[ nRectIndex ] = Rectangle( aRect.Left(), aRect.Top(), aRect.Right(), aRect.Bottom() );
    5487           0 :                         ++nRectIndex;
    5488           0 :                     }
    5489           0 :                     rWin.SetCompositionCharRect( aRects.get(), nSize, bVertical );
    5490             :                 }
    5491             :             }
    5492           0 :             bCallBase = false;
    5493             :         }
    5494           0 :         break;
    5495             :         default:
    5496             : #if OSL_DEBUG_LEVEL > 0
    5497             :             OSL_ENSURE( false, "unknown command." );
    5498             : #endif
    5499           0 :         break;
    5500             :     }
    5501           0 :     if (bCallBase)
    5502           0 :         Window::Command(rCEvt);
    5503             : }
    5504             : 
    5505             : /*  i#18686 select the object/cursor at the mouse
    5506             :     position of the context menu request */
    5507           0 : bool SwEditWin::SelectMenuPosition(SwWrtShell& rSh, const Point& rMousePos )
    5508             : {
    5509           0 :     bool bRet = false;
    5510           0 :     const Point aDocPos( PixelToLogic( rMousePos ) );
    5511           0 :     const bool bIsInsideSelectedObj( rSh.IsInsideSelectedObj( aDocPos ) );
    5512             :     //create a synthetic mouse event out of the coordinates
    5513           0 :     MouseEvent aMEvt(rMousePos);
    5514           0 :     SdrView *pSdrView = rSh.GetDrawView();
    5515           0 :     if ( pSdrView )
    5516             :     {
    5517             :         // no close of insert_draw and reset of
    5518             :         // draw mode, if context menu position is inside a selected object.
    5519           0 :         if ( !bIsInsideSelectedObj && m_rView.GetDrawFuncPtr() )
    5520             :         {
    5521             : 
    5522           0 :             m_rView.GetDrawFuncPtr()->Deactivate();
    5523           0 :             m_rView.SetDrawFuncPtr(NULL);
    5524           0 :             m_rView.LeaveDrawCreate();
    5525           0 :             SfxBindings& rBind = m_rView.GetViewFrame()->GetBindings();
    5526           0 :             rBind.Invalidate( SID_ATTR_SIZE );
    5527           0 :             rBind.Invalidate( SID_TABLE_CELL );
    5528             :         }
    5529             : 
    5530             :         // if draw text is active and there's a text selection
    5531             :         // at the mouse position then do nothing
    5532           0 :         if(rSh.GetSelectionType() & nsSelectionType::SEL_DRW_TXT)
    5533             :         {
    5534           0 :             OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
    5535           0 :             ESelection aSelection = pOLV->GetSelection();
    5536           0 :             if(!aSelection.IsZero())
    5537             :             {
    5538           0 :                 SdrOutliner* pOutliner = pSdrView->GetTextEditOutliner();
    5539           0 :                 bool bVertical = pOutliner->IsVertical();
    5540           0 :                 const EditEngine& rEditEng = pOutliner->GetEditEngine();
    5541           0 :                 Point aEEPos(aDocPos);
    5542           0 :                 const Rectangle& rOutputArea = pOLV->GetOutputArea();
    5543             :                 // regard vertical mode
    5544           0 :                 if(bVertical)
    5545             :                 {
    5546           0 :                     aEEPos -= rOutputArea.TopRight();
    5547             :                     //invert the horizontal direction and exchange X and Y
    5548           0 :                     long nTemp = -aEEPos.X();
    5549           0 :                     aEEPos.X() = aEEPos.Y();
    5550           0 :                     aEEPos.Y() = nTemp;
    5551             :                 }
    5552             :                 else
    5553           0 :                     aEEPos -= rOutputArea.TopLeft();
    5554             : 
    5555           0 :                 EPosition aDocPosition = rEditEng.FindDocPosition(aEEPos);
    5556           0 :                 ESelection aCompare(aDocPosition.nPara, aDocPosition.nIndex);
    5557             :                 // make it a forward selection - otherwise the IsLess/IsGreater do not work :-(
    5558           0 :                 aSelection.Adjust();
    5559           0 :                 if(!aCompare.IsLess(aSelection)  && !aCompare.IsGreater(aSelection))
    5560             :                 {
    5561           0 :                     return false;
    5562             :                 }
    5563             :             }
    5564             : 
    5565             :         }
    5566             : 
    5567           0 :         if (pSdrView->MouseButtonDown( aMEvt, this ) )
    5568             :         {
    5569           0 :             pSdrView->MouseButtonUp( aMEvt, this );
    5570           0 :             rSh.GetView().GetViewFrame()->GetBindings().InvalidateAll(false);
    5571           0 :             return true;
    5572             :         }
    5573             :     }
    5574           0 :     rSh.ResetCursorStack();
    5575             : 
    5576           0 :     if ( EnterDrawMode( aMEvt, aDocPos ) )
    5577             :     {
    5578           0 :         return true;
    5579             :     }
    5580           0 :     if ( m_rView.GetDrawFuncPtr() && m_bInsFrm )
    5581             :     {
    5582           0 :         StopInsFrm();
    5583           0 :         rSh.Edit();
    5584             :     }
    5585             : 
    5586           0 :     UpdatePointer( aDocPos, 0 );
    5587             : 
    5588           0 :     if( !rSh.IsSelFrmMode() &&
    5589           0 :         !GetView().GetViewFrame()->GetDispatcher()->IsLocked() )
    5590             :     {
    5591             :         // Test if there is a draw object at that position and if it should be selected.
    5592           0 :         bool bShould = rSh.ShouldObjectBeSelected(aDocPos);
    5593             : 
    5594           0 :         if(bShould)
    5595             :         {
    5596           0 :             m_rView.NoRotate();
    5597           0 :             rSh.HideCrsr();
    5598             : 
    5599           0 :             bool bUnLockView = !rSh.IsViewLocked();
    5600           0 :             rSh.LockView( true );
    5601           0 :             bool bSelObj = rSh.SelectObj( aDocPos, 0);
    5602           0 :             if( bUnLockView )
    5603           0 :                 rSh.LockView( false );
    5604             : 
    5605           0 :             if( bSelObj )
    5606             :             {
    5607           0 :                 bRet = true;
    5608             :                 // in case the frame was deselected in the macro
    5609             :                 // just the cursor has to be displayed again.
    5610           0 :                 if( FrmTypeFlags::NONE == rSh.GetSelFrmType() )
    5611           0 :                     rSh.ShowCrsr();
    5612             :                 else
    5613             :                 {
    5614           0 :                     if (rSh.IsFrmSelected() && m_rView.GetDrawFuncPtr())
    5615             :                     {
    5616           0 :                         m_rView.GetDrawFuncPtr()->Deactivate();
    5617           0 :                         m_rView.SetDrawFuncPtr(NULL);
    5618           0 :                         m_rView.LeaveDrawCreate();
    5619           0 :                         m_rView.AttrChangedNotify( &rSh );
    5620             :                     }
    5621             : 
    5622           0 :                     rSh.EnterSelFrmMode( &aDocPos );
    5623           0 :                     g_bFrmDrag = true;
    5624           0 :                     UpdatePointer( aDocPos, 0 );
    5625           0 :                     return bRet;
    5626             :                 }
    5627             :             }
    5628             : 
    5629           0 :             if (!m_rView.GetDrawFuncPtr())
    5630           0 :                 rSh.ShowCrsr();
    5631             :         }
    5632             :     }
    5633           0 :     else if ( rSh.IsSelFrmMode() &&
    5634           0 :               (m_aActHitType == SDRHIT_NONE ||
    5635           0 :                !bIsInsideSelectedObj))
    5636             :     {
    5637           0 :         m_rView.NoRotate();
    5638           0 :         bool bUnLockView = !rSh.IsViewLocked();
    5639           0 :         rSh.LockView( true );
    5640           0 :         sal_uInt8 nFlag = 0;
    5641             : 
    5642           0 :         if ( rSh.IsSelFrmMode() )
    5643             :         {
    5644           0 :             rSh.UnSelectFrm();
    5645           0 :             rSh.LeaveSelFrmMode();
    5646           0 :             m_rView.AttrChangedNotify(&rSh);
    5647           0 :             bRet = true;
    5648             :         }
    5649             : 
    5650           0 :         bool bSelObj = rSh.SelectObj( aDocPos, nFlag );
    5651           0 :         if( bUnLockView )
    5652           0 :             rSh.LockView( false );
    5653             : 
    5654           0 :         if( !bSelObj )
    5655             :         {
    5656             :             // move cursor here so that it is not drawn in the
    5657             :             // frame at first; ShowCrsr() happens in LeaveSelFrmMode()
    5658           0 :             g_bValidCrsrPos = !(CRSR_POSCHG & rSh.SetCursor(&aDocPos, false));
    5659           0 :             rSh.LeaveSelFrmMode();
    5660           0 :             m_rView.LeaveDrawCreate();
    5661           0 :             m_rView.AttrChangedNotify( &rSh );
    5662           0 :             bRet = true;
    5663             :         }
    5664             :         else
    5665             :         {
    5666           0 :             rSh.HideCrsr();
    5667           0 :             rSh.EnterSelFrmMode( &aDocPos );
    5668           0 :             rSh.SelFlyGrabCrsr();
    5669           0 :             rSh.MakeSelVisible();
    5670           0 :             g_bFrmDrag = true;
    5671           0 :             if( rSh.IsFrmSelected() &&
    5672           0 :                 m_rView.GetDrawFuncPtr() )
    5673             :             {
    5674           0 :                 m_rView.GetDrawFuncPtr()->Deactivate();
    5675           0 :                 m_rView.SetDrawFuncPtr(NULL);
    5676           0 :                 m_rView.LeaveDrawCreate();
    5677           0 :                 m_rView.AttrChangedNotify( &rSh );
    5678             :             }
    5679           0 :             UpdatePointer( aDocPos, 0 );
    5680           0 :             bRet = true;
    5681             :         }
    5682             :     }
    5683           0 :     else if ( rSh.IsSelFrmMode() && bIsInsideSelectedObj )
    5684             :     {
    5685             :         // Object at the mouse cursor is already selected - do nothing
    5686           0 :         return false;
    5687             :     }
    5688             : 
    5689           0 :     if ( rSh.IsGCAttr() )
    5690             :     {
    5691           0 :         rSh.GCAttr();
    5692           0 :         rSh.ClearGCAttr();
    5693             :     }
    5694             : 
    5695           0 :     bool bOverSelect = rSh.ChgCurrPam( aDocPos ), bOverURLGrf = false;
    5696           0 :     if( !bOverSelect )
    5697           0 :         bOverURLGrf = bOverSelect = 0 != rSh.IsURLGrfAtPos( aDocPos );
    5698             : 
    5699           0 :     if ( !bOverSelect )
    5700             :     {
    5701             :         {   // create only temporary move context because otherwise
    5702             :             // the query against the content form doesn't work!!!
    5703           0 :             SwMvContext aMvContext( &rSh );
    5704           0 :             rSh.SetCursor(&aDocPos, false);
    5705           0 :             bRet = true;
    5706             :         }
    5707             :     }
    5708           0 :     if( !bOverURLGrf )
    5709             :     {
    5710           0 :         const int nSelType = rSh.GetSelectionType();
    5711           0 :         if( nSelType == nsSelectionType::SEL_OLE ||
    5712             :             nSelType == nsSelectionType::SEL_GRF )
    5713             :         {
    5714           0 :             SwMvContext aMvContext( &rSh );
    5715           0 :             if( !rSh.IsFrmSelected() )
    5716           0 :                 rSh.GotoNextFly();
    5717           0 :             rSh.EnterSelFrmMode();
    5718           0 :             bRet = true;
    5719             :         }
    5720             :     }
    5721           0 :     return bRet;
    5722             : }
    5723             : 
    5724           0 : static SfxShell* lcl_GetShellFromDispatcher( SwView& rView, TypeId nType )
    5725             : {
    5726             :     // determine Shell
    5727             :     SfxShell* pShell;
    5728           0 :     SfxDispatcher* pDispatcher = rView.GetViewFrame()->GetDispatcher();
    5729           0 :     for(sal_uInt16  i = 0; true; ++i )
    5730             :     {
    5731           0 :         pShell = pDispatcher->GetShell( i );
    5732           0 :         if( !pShell || pShell->IsA( nType ) )
    5733           0 :             break;
    5734           0 :     }
    5735           0 :     return pShell;
    5736             : }
    5737             : 
    5738           0 : IMPL_LINK_NOARG_TYPED(SwEditWin, KeyInputFlushHandler, Timer *, void)
    5739             : {
    5740           0 :     FlushInBuffer();
    5741           0 : }
    5742             : 
    5743           0 : IMPL_LINK_NOARG_TYPED(SwEditWin, KeyInputTimerHandler, Timer *, void)
    5744             : {
    5745           0 :     m_bTableInsDelMode = false;
    5746           0 : }
    5747             : 
    5748          59 : void SwEditWin::_InitStaticData()
    5749             : {
    5750          59 :     m_pQuickHlpData = new QuickHelpData();
    5751          59 : }
    5752             : 
    5753          59 : void SwEditWin::_FinitStaticData()
    5754             : {
    5755          59 :     delete m_pQuickHlpData;
    5756          59 : }
    5757             : /* i#3370 - remove quick help to prevent saving
    5758             :  * of autocorrection suggestions */
    5759         111 : void SwEditWin::StopQuickHelp()
    5760             : {
    5761         111 :     if( HasFocus() && m_pQuickHlpData && m_pQuickHlpData->m_bIsDisplayed  )
    5762           0 :         m_pQuickHlpData->Stop( m_rView.GetWrtShell() );
    5763         111 : }
    5764             : 
    5765           0 : IMPL_LINK_NOARG_TYPED(SwEditWin, TemplateTimerHdl, Idle *, void)
    5766             : {
    5767           0 :     SetApplyTemplate(SwApplyTemplate());
    5768           0 : }
    5769             : 
    5770           0 : void SwEditWin::SetChainMode( bool bOn )
    5771             : {
    5772           0 :     if ( !m_bChainMode )
    5773           0 :         StopInsFrm();
    5774             : 
    5775           0 :     if ( m_pUserMarker )
    5776             :     {
    5777           0 :         delete m_pUserMarker;
    5778           0 :         m_pUserMarker = 0L;
    5779             :     }
    5780             : 
    5781           0 :     m_bChainMode = bOn;
    5782             : 
    5783             :     static sal_uInt16 aInva[] =
    5784             :     {
    5785             :         FN_FRAME_CHAIN, FN_FRAME_UNCHAIN, 0
    5786             :     };
    5787           0 :     m_rView.GetViewFrame()->GetBindings().Invalidate(aInva);
    5788           0 : }
    5789             : 
    5790          12 : uno::Reference< ::com::sun::star::accessibility::XAccessible > SwEditWin::CreateAccessible()
    5791             : {
    5792          12 :     SolarMutexGuard aGuard;   // this should have happened already!!!
    5793          12 :     SwWrtShell *pSh = m_rView.GetWrtShellPtr();
    5794             :     OSL_ENSURE( pSh, "no writer shell, no accessible object" );
    5795             :     uno::Reference<
    5796          12 :         ::com::sun::star::accessibility::XAccessible > xAcc;
    5797          12 :     if( pSh )
    5798          12 :         xAcc = pSh->CreateAccessible();
    5799             : 
    5800          12 :     return xAcc;
    5801             : }
    5802             : 
    5803           0 : void QuickHelpData::Move( QuickHelpData& rCpy )
    5804             : {
    5805           0 :     m_aHelpStrings.clear();
    5806           0 :     m_aHelpStrings.swap( rCpy.m_aHelpStrings );
    5807             : 
    5808           0 :     m_bIsDisplayed = rCpy.m_bIsDisplayed;
    5809           0 :     nLen = rCpy.nLen;
    5810           0 :     nCurArrPos = rCpy.nCurArrPos;
    5811           0 :     m_bAppendSpace = rCpy.m_bAppendSpace;
    5812           0 :     m_bIsTip = rCpy.m_bIsTip;
    5813           0 :     m_bIsAutoText = rCpy.m_bIsAutoText;
    5814           0 : }
    5815             : 
    5816          60 : void QuickHelpData::ClearContent()
    5817             : {
    5818          60 :     nLen = nCurArrPos = 0;
    5819          60 :     m_bIsDisplayed = m_bAppendSpace = false;
    5820          60 :     nTipId = 0;
    5821          60 :     m_aHelpStrings.clear();
    5822          60 :     m_bIsTip = true;
    5823          60 :     m_bIsAutoText = true;
    5824          60 : }
    5825             : 
    5826           0 : void QuickHelpData::Start( SwWrtShell& rSh, sal_uInt16 nWrdLen )
    5827             : {
    5828           0 :     if( USHRT_MAX != nWrdLen )
    5829             :     {
    5830           0 :         nLen = nWrdLen;
    5831           0 :         nCurArrPos = 0;
    5832             :     }
    5833           0 :     m_bIsDisplayed = true;
    5834             : 
    5835           0 :     vcl::Window& rWin = rSh.GetView().GetEditWin();
    5836           0 :     if( m_bIsTip )
    5837             :     {
    5838             :         Point aPt( rWin.OutputToScreenPixel( rWin.LogicToPixel(
    5839           0 :                     rSh.GetCharRect().Pos() )));
    5840           0 :         aPt.Y() -= 3;
    5841             :         nTipId = Help::ShowTip( &rWin, Rectangle( aPt, Size( 1, 1 )),
    5842           0 :                         m_aHelpStrings[ nCurArrPos ],
    5843           0 :                         QuickHelpFlags::Left | QuickHelpFlags::Bottom );
    5844             :     }
    5845             :     else
    5846             :     {
    5847           0 :         OUString sStr( m_aHelpStrings[ nCurArrPos ] );
    5848           0 :         sStr = sStr.copy( nLen );
    5849           0 :         sal_uInt16 nL = sStr.getLength();
    5850             :         const sal_uInt16 nVal = EXTTEXTINPUT_ATTR_DOTTEDUNDERLINE |
    5851           0 :                                 EXTTEXTINPUT_ATTR_HIGHLIGHT;
    5852           0 :         const std::vector<sal_uInt16> aAttrs( nL, nVal );
    5853           0 :         CommandExtTextInputData aCETID( sStr, &aAttrs[0], nL,
    5854           0 :                                         0, false );
    5855             : 
    5856             :         //fdo#33092. If the current input language is the default
    5857             :         //language that text would appear in if typed, then don't
    5858             :         //force a language on for the ExtTextInput.
    5859           0 :         LanguageType eInputLanguage = rWin.GetInputLanguage();
    5860           0 :         if (lcl_isNonDefaultLanguage(eInputLanguage,
    5861           0 :             rSh.GetView(), sStr) == INVALID_HINT)
    5862             :         {
    5863           0 :             eInputLanguage = LANGUAGE_DONTKNOW;
    5864             :         }
    5865             : 
    5866           0 :         rSh.CreateExtTextInput(eInputLanguage);
    5867           0 :         rSh.SetExtTextInputData( aCETID );
    5868             :     }
    5869           0 : }
    5870             : 
    5871           0 : void QuickHelpData::Stop( SwWrtShell& rSh )
    5872             : {
    5873           0 :     if( !m_bIsTip )
    5874           0 :         rSh.DeleteExtTextInput( 0, false );
    5875           0 :     else if( nTipId )
    5876           0 :         Help::HideTip( nTipId );
    5877           0 :     ClearContent();
    5878           0 : }
    5879             : 
    5880           0 : void QuickHelpData::FillStrArr( SwWrtShell& rSh, const OUString& rWord )
    5881             : {
    5882             :     enum Capitalization { CASE_LOWER, CASE_UPPER, CASE_SENTENCE, CASE_OTHER };
    5883             : 
    5884             :     // Determine word capitalization
    5885           0 :     const CharClass& rCC = GetAppCharClass();
    5886           0 :     const OUString sWordLower = rCC.lowercase( rWord );
    5887           0 :     Capitalization aWordCase = CASE_OTHER;
    5888           0 :     if ( !rWord.isEmpty() )
    5889             :     {
    5890           0 :         if ( rWord[0] == sWordLower[0] )
    5891             :         {
    5892           0 :             if ( rWord == sWordLower )
    5893           0 :                 aWordCase = CASE_LOWER;
    5894             :         }
    5895             :         else
    5896             :         {
    5897             :             // First character is not lower case i.e. assume upper or title case
    5898           0 :             OUString sWordSentence = sWordLower;
    5899           0 :             sWordSentence = sWordSentence.replaceAt( 0, 1, OUString(rWord[0]) );
    5900           0 :             if ( rWord == sWordSentence )
    5901           0 :                 aWordCase = CASE_SENTENCE;
    5902             :             else
    5903             :             {
    5904           0 :                 if ( rWord == rCC.uppercase( rWord ) )
    5905           0 :                     aWordCase = CASE_UPPER;
    5906           0 :             }
    5907             :         }
    5908             :     }
    5909             : 
    5910           0 :     salhelper::SingletonRef<SwCalendarWrapper>* pCalendar = s_getCalendarWrapper();
    5911           0 :     (*pCalendar)->LoadDefaultCalendar( rSh.GetCurLang() );
    5912             : 
    5913             :     // Add matching calendar month and day names
    5914           0 :     uno::Sequence< i18n::CalendarItem2 > aNames( (*pCalendar)->getMonths() );
    5915           0 :     for ( sal_uInt16 i = 0; i < 2; ++i )
    5916             :     {
    5917           0 :         for ( long n = 0; n < aNames.getLength(); ++n )
    5918             :         {
    5919           0 :             const OUString& rStr( aNames[n].FullName );
    5920             :             // Check string longer than word and case insensitive match
    5921           0 :             if( rStr.getLength() > rWord.getLength() &&
    5922           0 :                 rCC.lowercase( rStr, 0, rWord.getLength() ) == sWordLower )
    5923             :             {
    5924             :                 //fdo#61251 if it's an exact match, ensure unchanged replacement
    5925             :                 //exists as a candidate
    5926           0 :                 if (rStr.startsWith(rWord))
    5927           0 :                     m_aHelpStrings.push_back(rStr);
    5928             : 
    5929           0 :                 if ( aWordCase == CASE_LOWER )
    5930           0 :                     m_aHelpStrings.push_back( rCC.lowercase( rStr ) );
    5931           0 :                 else if ( aWordCase == CASE_SENTENCE )
    5932             :                 {
    5933           0 :                     OUString sTmp = rCC.lowercase( rStr );
    5934           0 :                     sTmp = sTmp.replaceAt( 0, 1, OUString(rStr[0]) );
    5935           0 :                     m_aHelpStrings.push_back( sTmp );
    5936             :                 }
    5937           0 :                 else if ( aWordCase == CASE_UPPER )
    5938           0 :                     m_aHelpStrings.push_back( rCC.uppercase( rStr ) );
    5939             :                 else // CASE_OTHER - use retrieved capitalization
    5940           0 :                     m_aHelpStrings.push_back( rStr );
    5941             :             }
    5942             :         }
    5943             :         // Data for second loop iteration
    5944           0 :         if ( i == 0 )
    5945           0 :             aNames = (*pCalendar)->getDays();
    5946             :     }
    5947             : 
    5948             :     // Add matching words from AutoCompleteWord list
    5949           0 :     const SwAutoCompleteWord& rACList = SwEditShell::GetAutoCompleteWords();
    5950           0 :     std::vector<OUString> strings;
    5951             : 
    5952           0 :     if ( rACList.GetWordsMatching( rWord, strings ) )
    5953             :     {
    5954           0 :         for (size_t i= 0; i<strings.size(); i++)
    5955             :         {
    5956           0 :             OUString aCompletedString = strings[i];
    5957             :             //fdo#61251 if it's an exact match, ensure unchanged replacement
    5958             :             //exists as a candidate
    5959           0 :             if (aCompletedString.startsWith(rWord))
    5960           0 :                 m_aHelpStrings.push_back(aCompletedString);
    5961           0 :             if ( aWordCase == CASE_LOWER )
    5962           0 :                 m_aHelpStrings.push_back( rCC.lowercase( aCompletedString ) );
    5963           0 :             else if ( aWordCase == CASE_SENTENCE )
    5964             :             {
    5965           0 :                 OUString sTmp = rCC.lowercase( aCompletedString );
    5966           0 :                 sTmp = sTmp.replaceAt( 0, 1, OUString(aCompletedString[0]) );
    5967           0 :                 m_aHelpStrings.push_back( sTmp );
    5968             :             }
    5969           0 :             else if ( aWordCase == CASE_UPPER )
    5970           0 :                 m_aHelpStrings.push_back( rCC.uppercase( aCompletedString ) );
    5971             :             else // CASE_OTHER - use retrieved capitalization
    5972           0 :                 m_aHelpStrings.push_back( aCompletedString );
    5973           0 :         }
    5974           0 :     }
    5975             : 
    5976           0 : }
    5977             : 
    5978             : namespace {
    5979             : 
    5980             : class CompareIgnoreCaseAsciiFavorExact
    5981             :     : public std::binary_function<const OUString&, const OUString&, bool>
    5982             : {
    5983             :     const OUString &m_rOrigWord;
    5984             : public:
    5985           0 :     explicit CompareIgnoreCaseAsciiFavorExact(const OUString& rOrigWord)
    5986           0 :         : m_rOrigWord(rOrigWord)
    5987             :     {
    5988           0 :     }
    5989             : 
    5990           0 :     bool operator()(const OUString& s1, const OUString& s2) const
    5991             :     {
    5992           0 :         int nRet = s1.compareToIgnoreAsciiCase(s2);
    5993           0 :         if (nRet == 0)
    5994             :         {
    5995             :             //fdo#61251 sort stuff that starts with the exact rOrigWord before
    5996             :             //another ignore-case candidate
    5997           0 :             int n1StartsWithOrig = s1.startsWith(m_rOrigWord) ? 0 : 1;
    5998           0 :             int n2StartsWithOrig = s2.startsWith(m_rOrigWord) ? 0 : 1;
    5999           0 :             return n1StartsWithOrig < n2StartsWithOrig;
    6000             :         }
    6001           0 :         return nRet < 0;
    6002             :     }
    6003             : };
    6004             : 
    6005             : struct EqualIgnoreCaseAscii
    6006             : {
    6007           0 :     bool operator()(const OUString& s1, const OUString& s2) const
    6008             :     {
    6009           0 :         return s1.equalsIgnoreAsciiCase(s2);
    6010             :     }
    6011             : };
    6012             : 
    6013             : } // anonymous namespace
    6014             : 
    6015             : // TODO Implement an i18n aware sort
    6016           0 : void QuickHelpData::SortAndFilter(const OUString &rOrigWord)
    6017             : {
    6018             :     std::sort( m_aHelpStrings.begin(),
    6019             :                m_aHelpStrings.end(),
    6020           0 :                CompareIgnoreCaseAsciiFavorExact(rOrigWord) );
    6021             : 
    6022             :     std::vector<OUString>::iterator it = std::unique( m_aHelpStrings.begin(),
    6023             :                                                     m_aHelpStrings.end(),
    6024           0 :                                                     EqualIgnoreCaseAscii() );
    6025           0 :     m_aHelpStrings.erase( it, m_aHelpStrings.end() );
    6026             : 
    6027           0 :     nCurArrPos = 0;
    6028           0 : }
    6029             : 
    6030           0 : void SwEditWin::ShowAutoTextCorrectQuickHelp(
    6031             :         const OUString& rWord, SvxAutoCorrCfg* pACfg, SvxAutoCorrect* pACorr,
    6032             :         bool bFromIME )
    6033             : {
    6034           0 :     SwWrtShell& rSh = m_rView.GetWrtShell();
    6035           0 :     m_pQuickHlpData->ClearContent();
    6036           0 :     if( pACfg->IsAutoTextTip() )
    6037             :     {
    6038           0 :         SwGlossaryList* pList = ::GetGlossaryList();
    6039           0 :         pList->HasLongName( rWord, &m_pQuickHlpData->m_aHelpStrings );
    6040             :     }
    6041             : 
    6042           0 :     if( m_pQuickHlpData->m_aHelpStrings.empty() &&
    6043           0 :         pACorr->GetSwFlags().bAutoCompleteWords )
    6044             :     {
    6045           0 :         m_pQuickHlpData->m_bIsAutoText = false;
    6046           0 :         m_pQuickHlpData->m_bIsTip = bFromIME ||
    6047           0 :                     !pACorr ||
    6048           0 :                     pACorr->GetSwFlags().bAutoCmpltShowAsTip;
    6049             : 
    6050             :         // Get the necessary data to show help text.
    6051           0 :         m_pQuickHlpData->FillStrArr( rSh, rWord );
    6052             :     }
    6053             : 
    6054           0 :     if( !m_pQuickHlpData->m_aHelpStrings.empty() )
    6055             :     {
    6056           0 :         m_pQuickHlpData->SortAndFilter(rWord);
    6057           0 :         m_pQuickHlpData->Start( rSh, rWord.getLength() );
    6058             :     }
    6059           0 : }
    6060             : 
    6061           2 : bool SwEditWin::IsInHeaderFooter( const Point &rDocPt, FrameControlType &rControl ) const
    6062             : {
    6063           2 :     SwWrtShell &rSh = m_rView.GetWrtShell();
    6064           2 :     const SwPageFrm* pPageFrm = rSh.GetLayout()->GetPageAtPos( rDocPt );
    6065             : 
    6066           2 :     if ( pPageFrm && pPageFrm->IsOverHeaderFooterArea( rDocPt, rControl ) )
    6067           0 :         return true;
    6068             : 
    6069           2 :     if ( rSh.IsShowHeaderFooterSeparator( Header ) || rSh.IsShowHeaderFooterSeparator( Footer ) )
    6070             :     {
    6071           0 :         SwFrameControlsManager &rMgr = rSh.GetView().GetEditWin().GetFrameControlsManager();
    6072           0 :         Point aPoint( LogicToPixel( rDocPt ) );
    6073             : 
    6074           0 :         if ( rSh.IsShowHeaderFooterSeparator( Header ) )
    6075             :         {
    6076           0 :             SwFrameControlPtr pControl = rMgr.GetControl( Header, pPageFrm );
    6077           0 :             if ( pControl.get() && pControl->Contains( aPoint ) )
    6078             :             {
    6079           0 :                 rControl = Header;
    6080           0 :                 return true;
    6081           0 :             }
    6082             :         }
    6083             : 
    6084           0 :         if ( rSh.IsShowHeaderFooterSeparator( Footer ) )
    6085             :         {
    6086           0 :             SwFrameControlPtr pControl = rMgr.GetControl( Footer, pPageFrm );
    6087           0 :             if ( pControl.get() && pControl->Contains( aPoint ) )
    6088             :             {
    6089           0 :                 rControl = Footer;
    6090           0 :                 return true;
    6091           0 :             }
    6092             :         }
    6093             :     }
    6094             : 
    6095           2 :     return false;
    6096             : }
    6097             : 
    6098           2 : bool SwEditWin::IsOverHeaderFooterFly( const Point& rDocPos, FrameControlType& rControl, bool& bOverFly, bool& bPageAnchored ) const
    6099             : {
    6100           2 :     bool bRet = false;
    6101           2 :     Point aPt( rDocPos );
    6102           2 :     SwWrtShell &rSh = m_rView.GetWrtShell();
    6103           2 :     SwPaM aPam( *rSh.GetCurrentShellCursor().GetPoint() );
    6104           2 :     rSh.GetLayout()->GetCrsrOfst( aPam.GetPoint(), aPt, NULL, true );
    6105             : 
    6106           2 :     const SwStartNode* pStartFly = aPam.GetPoint()->nNode.GetNode().FindFlyStartNode();
    6107           2 :     if ( pStartFly )
    6108             :     {
    6109           0 :         bOverFly = true;
    6110           0 :         SwFrameFormat* pFlyFormat = pStartFly->GetFlyFormat( );
    6111           0 :         if ( pFlyFormat )
    6112             :         {
    6113           0 :             const SwPosition* pAnchor = pFlyFormat->GetAnchor( ).GetContentAnchor( );
    6114           0 :             if ( pAnchor )
    6115             :             {
    6116           0 :                 bool bInHeader = pAnchor->nNode.GetNode( ).FindHeaderStartNode( ) != NULL;
    6117           0 :                 bool bInFooter = pAnchor->nNode.GetNode( ).FindFooterStartNode( ) != NULL;
    6118             : 
    6119           0 :                 bRet = bInHeader || bInFooter;
    6120           0 :                 if ( bInHeader )
    6121           0 :                     rControl = Header;
    6122           0 :                 else if ( bInFooter )
    6123           0 :                     rControl = Footer;
    6124             :             }
    6125             :             else
    6126           0 :                 bPageAnchored = pFlyFormat->GetAnchor( ).GetAnchorId( ) == FLY_AT_PAGE;
    6127             :         }
    6128             :     }
    6129             :     else
    6130           2 :         bOverFly = false;
    6131           2 :     return bRet;
    6132             : }
    6133             : 
    6134           1 : void SwEditWin::SetUseInputLanguage( bool bNew )
    6135             : {
    6136           1 :     if ( bNew || m_bUseInputLanguage )
    6137             :     {
    6138           1 :         SfxBindings& rBind = GetView().GetViewFrame()->GetBindings();
    6139           1 :         rBind.Invalidate( SID_ATTR_CHAR_FONT );
    6140           1 :         rBind.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
    6141             :     }
    6142           1 :     m_bUseInputLanguage = bNew;
    6143           1 : }
    6144             : 
    6145           0 : OUString SwEditWin::GetSurroundingText() const
    6146             : {
    6147           0 :     OUString sReturn;
    6148           0 :     SwWrtShell& rSh = m_rView.GetWrtShell();
    6149           0 :     if( rSh.HasSelection() && !rSh.IsMultiSelection() && rSh.IsSelOnePara() )
    6150           0 :         rSh.GetSelectedText( sReturn, GETSELTXT_PARABRK_TO_ONLYCR  );
    6151           0 :     else if( !rSh.HasSelection() )
    6152             :     {
    6153           0 :         SwPosition *pPos = rSh.GetCrsr()->GetPoint();
    6154           0 :         const sal_Int32 nPos = pPos->nContent.GetIndex();
    6155             : 
    6156             :         // get the sentence around the cursor
    6157           0 :         rSh.HideCrsr();
    6158           0 :         rSh.GoStartSentence();
    6159           0 :         rSh.SetMark();
    6160           0 :         rSh.GoEndSentence();
    6161           0 :         rSh.GetSelectedText( sReturn, GETSELTXT_PARABRK_TO_ONLYCR  );
    6162             : 
    6163           0 :         pPos->nContent = nPos;
    6164           0 :         rSh.ClearMark();
    6165           0 :         rSh.HideCrsr();
    6166             :     }
    6167             : 
    6168           0 :     return sReturn;
    6169             : }
    6170             : 
    6171           0 : Selection SwEditWin::GetSurroundingTextSelection() const
    6172             : {
    6173           0 :     SwWrtShell& rSh = m_rView.GetWrtShell();
    6174           0 :     if( rSh.HasSelection() )
    6175             :     {
    6176           0 :         OUString sReturn;
    6177           0 :         rSh.GetSelectedText( sReturn, GETSELTXT_PARABRK_TO_ONLYCR  );
    6178           0 :         return Selection( 0, sReturn.getLength() );
    6179             :     }
    6180             :     else
    6181             :     {
    6182             :         // Return the position of the visible cursor in the sentence
    6183             :         // around the visible cursor.
    6184           0 :         SwPosition *pPos = rSh.GetCrsr()->GetPoint();
    6185           0 :         const sal_Int32 nPos = pPos->nContent.GetIndex();
    6186             : 
    6187           0 :         rSh.HideCrsr();
    6188           0 :         rSh.GoStartSentence();
    6189           0 :         const sal_Int32 nStartPos = rSh.GetCrsr()->GetPoint()->nContent.GetIndex();
    6190             : 
    6191           0 :         pPos->nContent = nPos;
    6192           0 :         rSh.ClearMark();
    6193           0 :         rSh.ShowCrsr();
    6194             : 
    6195           0 :         return Selection( nPos - nStartPos, nPos - nStartPos );
    6196             :     }
    6197             : }
    6198             : 
    6199       58755 : void SwEditWin::LogicInvalidate(const Rectangle* pRectangle)
    6200             : {
    6201       58755 :     OString sRectangle;
    6202       58755 :     if (!pRectangle)
    6203       36391 :         sRectangle = "EMPTY";
    6204             :     else
    6205       22364 :         sRectangle = pRectangle->toString();
    6206       58755 :     m_rView.GetWrtShell().libreOfficeKitCallback(LOK_CALLBACK_INVALIDATE_TILES, sRectangle.getStr());
    6207       58755 : }
    6208             : 
    6209           1 : void SwEditWin::LogicMouseButtonDown(const MouseEvent& rMouseEvent)
    6210             : {
    6211             :     // When we're not doing tiled rendering, then positions must be passed as pixels.
    6212             :     assert(m_rView.GetWrtShell().isTiledRendering());
    6213             : 
    6214           1 :     Point aPoint = GetPointerPosPixel();
    6215           1 :     SetLastMousePos(rMouseEvent.GetPosPixel());
    6216             : 
    6217           1 :     MouseButtonDown(rMouseEvent);
    6218             : 
    6219           1 :     SetPointerPosPixel(aPoint);
    6220           1 : }
    6221             : 
    6222           1 : void SwEditWin::LogicMouseButtonUp(const MouseEvent& rMouseEvent)
    6223             : {
    6224             :     // When we're not doing tiled rendering, then positions must be passed as pixels.
    6225             :     assert(m_rView.GetWrtShell().isTiledRendering());
    6226             : 
    6227           1 :     Point aPoint = GetPointerPosPixel();
    6228           1 :     SetLastMousePos(rMouseEvent.GetPosPixel());
    6229             : 
    6230           1 :     MouseButtonUp(rMouseEvent);
    6231             : 
    6232           1 :     SetPointerPosPixel(aPoint);
    6233           1 : }
    6234             : 
    6235           0 : void SwEditWin::LogicMouseMove(const MouseEvent& rMouseEvent)
    6236             : {
    6237             :     // When we're not doing tiled rendering, then positions must be passed as pixels.
    6238             :     assert(m_rView.GetWrtShell().isTiledRendering());
    6239             : 
    6240           0 :     Point aPoint = GetPointerPosPixel();
    6241           0 :     SetLastMousePos(rMouseEvent.GetPosPixel());
    6242             : 
    6243           0 :     MouseMove(rMouseEvent);
    6244             : 
    6245           0 :     SetPointerPosPixel(aPoint);
    6246           0 : }
    6247             : 
    6248           3 : void SwEditWin::SetCursorTwipPosition(const Point& rPosition, bool bPoint, bool bClearMark)
    6249             : {
    6250           3 :     if (SdrView* pSdrView = m_rView.GetWrtShell().GetDrawView())
    6251             :     {
    6252             :         // Editing shape text, then route the call to editeng.
    6253           3 :         if (pSdrView->GetTextEditObject())
    6254             :         {
    6255           0 :             EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView();
    6256           0 :             rEditView.SetCursorLogicPosition(rPosition, bPoint, bClearMark);
    6257           3 :             return;
    6258             :         }
    6259             :     }
    6260             : 
    6261             :     // Not an SwWrtShell, as that would make SwCrsrShell::GetCrsr() inaccessible.
    6262           3 :     SwEditShell& rShell = m_rView.GetWrtShell();
    6263             : 
    6264           3 :     bool bCreateSelection = false;
    6265             :     {
    6266           3 :         SwMvContext aMvContext(&rShell);
    6267           3 :         if (bClearMark)
    6268           1 :             rShell.ClearMark();
    6269             :         else
    6270           2 :             bCreateSelection = !rShell.HasMark();
    6271             : 
    6272           3 :         if (bCreateSelection)
    6273           1 :             m_rView.GetWrtShell().SttSelect();
    6274             : 
    6275             :         // If the mark is to be updated, then exchange the point and mark before
    6276             :         // and after, as we can't easily set the mark.
    6277           3 :         if (!bPoint)
    6278           1 :             rShell.getShellCrsr(/*bBlock=*/false)->Exchange();
    6279           3 :         rShell.SetCrsr(rPosition);
    6280           3 :         if (!bPoint)
    6281           1 :             rShell.getShellCrsr(/*bBlock=*/false)->Exchange();
    6282             :     }
    6283             : 
    6284           3 :     if (bCreateSelection)
    6285           1 :         m_rView.GetWrtShell().EndSelect();
    6286             : }
    6287             : 
    6288           2 : void SwEditWin::SetGraphicTwipPosition(bool bStart, const Point& rPosition)
    6289             : {
    6290           2 :     if (bStart)
    6291             :     {
    6292           1 :         MouseEvent aClickEvent(rPosition, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT);
    6293           1 :         MouseButtonDown(aClickEvent);
    6294           1 :         MouseEvent aMoveEvent(Point(rPosition.getX() + MIN_MOVE + 1, rPosition.getY()), 0, MouseEventModifiers::SIMPLEMOVE, MOUSE_LEFT);
    6295           1 :         MouseMove(aMoveEvent);
    6296             :     }
    6297             :     else
    6298             :     {
    6299           1 :         MouseEvent aMoveEvent(Point(rPosition.getX() - MIN_MOVE - 1, rPosition.getY()), 0, MouseEventModifiers::SIMPLEMOVE, MOUSE_LEFT);
    6300           1 :         MouseMove(aMoveEvent);
    6301           1 :         MouseEvent aClickEvent(rPosition, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT);
    6302           1 :         MouseButtonUp(aClickEvent);
    6303             :     }
    6304         179 : }
    6305             : 
    6306             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11