LCOV - code coverage report
Current view: top level - sw/source/core/crsr - viscrs.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 235 355 66.2 %
Date: 2014-04-11 Functions: 33 49 67.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <config_features.h>
      21             : 
      22             : #include <vcl/dialog.hxx>
      23             : #include <vcl/msgbox.hxx>
      24             : #include <vcl/wrkwin.hxx>
      25             : #include <vcl/settings.hxx>
      26             : #include <viewopt.hxx>
      27             : #include <frmtool.hxx>
      28             : #include <viscrs.hxx>
      29             : #include <crsrsh.hxx>
      30             : #include <doc.hxx>
      31             : #include <swtable.hxx>
      32             : #include <viewimp.hxx>
      33             : #include <dview.hxx>
      34             : #include <rootfrm.hxx>
      35             : #include <txtfrm.hxx>
      36             : #include <docary.hxx>
      37             : #include <extinput.hxx>
      38             : #include <ndtxt.hxx>
      39             : #include <txtfld.hxx>
      40             : #include <scriptinfo.hxx>
      41             : #include <mdiexp.hxx>
      42             : #include <wrtsh.hxx>
      43             : #include <comcore.hrc>
      44             : #include <view.hxx>
      45             : 
      46             : #include <svx/sdr/overlay/overlaymanager.hxx>
      47             : #include <svx/sdrpaintwindow.hxx>
      48             : #include <vcl/svapp.hxx>
      49             : #include <svx/sdr/overlay/overlayselection.hxx>
      50             : #include <overlayrangesoutline.hxx>
      51             : 
      52             : #include <boost/scoped_ptr.hpp>
      53             : 
      54             : #include <touch/touch.h>
      55             : 
      56             : extern void SwCalcPixStatics( OutputDevice *pOut );
      57             : 
      58             : // Here static members are defined. They will get changed on alteration of the
      59             : // MapMode. This is done so that on ShowCrsr the same size does not have to be
      60             : // expensively determined again and again.
      61             : 
      62             : long SwSelPaintRects::nPixPtX = 0;
      63             : long SwSelPaintRects::nPixPtY = 0;
      64             : MapMode* SwSelPaintRects::pMapMode = 0;
      65             : 
      66             : // -----  Starting from here: classes / methods for the non-text-cursor -----
      67             : 
      68        1732 : SwVisCrsr::SwVisCrsr( const SwCrsrShell * pCShell )
      69        1732 :     : m_pCrsrShell( pCShell )
      70             : {
      71        1732 :     pCShell->GetWin()->SetCursor( &m_aTxtCrsr );
      72        1732 :     m_bIsVisible = m_aTxtCrsr.IsVisible();
      73        1732 :     m_bIsDragCrsr = false;
      74        1732 :     m_aTxtCrsr.SetWidth( 0 );
      75        1732 : }
      76             : 
      77        3462 : SwVisCrsr::~SwVisCrsr()
      78             : {
      79        1731 :     if( m_bIsVisible && m_aTxtCrsr.IsVisible() )
      80           5 :         m_aTxtCrsr.Hide();
      81             : 
      82        1731 :     m_pCrsrShell->GetWin()->SetCursor( 0 );
      83        1731 : }
      84             : 
      85       74804 : void SwVisCrsr::Show()
      86             : {
      87       74804 :     if( !m_bIsVisible )
      88             :     {
      89       32837 :         m_bIsVisible = true;
      90             : 
      91             :         // display at all?
      92       32837 :         if( m_pCrsrShell->VisArea().IsOver( m_pCrsrShell->m_aCharRect ) )
      93       29548 :             _SetPosAndShow();
      94             :     }
      95       74804 : }
      96             : 
      97       38656 : void SwVisCrsr::Hide()
      98             : {
      99       38656 :     if( m_bIsVisible )
     100             :     {
     101       32812 :         m_bIsVisible = false;
     102             : 
     103       32812 :         if( m_aTxtCrsr.IsVisible() )      // Shouldn't the flags be in effect?
     104       29534 :             m_aTxtCrsr.Hide();
     105             :     }
     106       38656 : }
     107             : 
     108       29548 : void SwVisCrsr::_SetPosAndShow()
     109             : {
     110       29548 :     SwRect aRect;
     111       29548 :     long nTmpY = m_pCrsrShell->m_aCrsrHeight.getY();
     112       29548 :     if( 0 > nTmpY )
     113             :     {
     114           0 :         nTmpY = -nTmpY;
     115           0 :         m_aTxtCrsr.SetOrientation( 900 );
     116           0 :         aRect = SwRect( m_pCrsrShell->m_aCharRect.Pos(),
     117           0 :            Size( m_pCrsrShell->m_aCharRect.Height(), nTmpY ) );
     118           0 :         aRect.Pos().setX(aRect.Pos().getX() + m_pCrsrShell->m_aCrsrHeight.getX());
     119           0 :         if( m_pCrsrShell->IsOverwriteCrsr() )
     120           0 :             aRect.Pos().setY(aRect.Pos().getY() + aRect.Width());
     121             :     }
     122             :     else
     123             :     {
     124       29548 :         m_aTxtCrsr.SetOrientation( 0 );
     125       59096 :         aRect = SwRect( m_pCrsrShell->m_aCharRect.Pos(),
     126       29548 :            Size( m_pCrsrShell->m_aCharRect.Width(), nTmpY ) );
     127       29548 :         aRect.Pos().setY(aRect.Pos().getY() + m_pCrsrShell->m_aCrsrHeight.getX());
     128             :     }
     129             : 
     130             :     // check if cursor should show the current cursor bidi level
     131       29548 :     m_aTxtCrsr.SetDirection( CURSOR_DIRECTION_NONE );
     132       29548 :     const SwCursor* pTmpCrsr = m_pCrsrShell->_GetCrsr();
     133             : 
     134       29548 :     if ( pTmpCrsr && !m_pCrsrShell->IsOverwriteCrsr() )
     135             :     {
     136       29548 :         SwNode& rNode = pTmpCrsr->GetPoint()->nNode.GetNode();
     137       29548 :         if( rNode.IsTxtNode() )
     138             :         {
     139       29548 :             const SwTxtNode& rTNd = *rNode.GetTxtNode();
     140       29548 :             const SwFrm* pFrm = rTNd.getLayoutFrm( m_pCrsrShell->GetLayout(), 0, 0, false );
     141       29548 :             if ( pFrm )
     142             :             {
     143       29548 :                 const SwScriptInfo* pSI = ((SwTxtFrm*)pFrm)->GetScriptInfo();
     144             :                  // cursor level has to be shown
     145       29548 :                 if ( pSI && pSI->CountDirChg() > 1 )
     146             :                 {
     147             :                     m_aTxtCrsr.SetDirection(
     148          14 :                         ( pTmpCrsr->GetCrsrBidiLevel() % 2 ) ?
     149             :                           CURSOR_DIRECTION_RTL :
     150          14 :                           CURSOR_DIRECTION_LTR );
     151             :                 }
     152       29548 :                 if ( pFrm->IsRightToLeft() )
     153             :                 {
     154          47 :                     const OutputDevice *pOut = m_pCrsrShell->GetOut();
     155          47 :                     if ( pOut )
     156             :                     {
     157          47 :                         long nSize = pOut->GetSettings().GetStyleSettings().GetCursorSize();
     158          47 :                         Size aSize( nSize, nSize );
     159          47 :                         aSize = pOut->PixelToLogic( aSize );
     160          47 :                         aRect.Left( aRect.Left() - aSize.Width() );
     161             :                     }
     162             :                 }
     163             :             }
     164             :         }
     165             :     }
     166             : 
     167       29548 :     if( aRect.Height() )
     168             :     {
     169       29478 :         ::SwCalcPixStatics( m_pCrsrShell->GetOut() );
     170       29478 :         ::SwAlignRect( aRect, (SwViewShell*)m_pCrsrShell );
     171             :     }
     172       29548 :     if( !m_pCrsrShell->IsOverwriteCrsr() || m_bIsDragCrsr ||
     173           0 :         m_pCrsrShell->IsSelection() )
     174       29548 :         aRect.Width( 0 );
     175             : 
     176       29548 :     m_aTxtCrsr.SetSize( aRect.SSize() );
     177             : 
     178       29548 :     m_aTxtCrsr.SetPos( aRect.Pos() );
     179       29548 :     if ( !m_pCrsrShell->IsCrsrReadonly()  || m_pCrsrShell->GetViewOptions()->IsSelectionInReadonly() )
     180             :     {
     181       29539 :         if ( m_pCrsrShell->GetDrawView() )
     182       29539 :             ((SwDrawView*)m_pCrsrShell->GetDrawView())->SetAnimationEnabled(
     183       59078 :                     !m_pCrsrShell->IsSelection() );
     184             : 
     185       29539 :         sal_uInt16 nStyle = m_bIsDragCrsr ? CURSOR_SHADOW : 0;
     186       29539 :         if( nStyle != m_aTxtCrsr.GetStyle() )
     187             :         {
     188           0 :             m_aTxtCrsr.SetStyle( nStyle );
     189           0 :             m_aTxtCrsr.SetWindow( m_bIsDragCrsr ? m_pCrsrShell->GetWin() : 0 );
     190             :         }
     191             : 
     192       29539 :         m_aTxtCrsr.Show();
     193             :     }
     194       29548 : }
     195             : 
     196        2042 : SwSelPaintRects::SwSelPaintRects( const SwCrsrShell& rCSh )
     197             :     : SwRects()
     198             :     , pCShell( &rCSh )
     199             : #if HAVE_FEATURE_DESKTOP
     200             :     , mpCursorOverlay( 0 )
     201             :     , mbShowTxtInputFldOverlay( true )
     202        2042 :     , mpTxtInputFldOverlay( NULL )
     203             : #endif
     204             : {
     205        2042 : }
     206             : 
     207        4082 : SwSelPaintRects::~SwSelPaintRects()
     208             : {
     209        2041 :     Hide();
     210        2041 : }
     211             : 
     212           0 : void SwSelPaintRects::swapContent(SwSelPaintRects& rSwap)
     213             : {
     214           0 :     SwRects::swap(rSwap);
     215             : 
     216             : #if HAVE_FEATURE_DESKTOP
     217             :     // #i75172# also swap mpCursorOverlay
     218           0 :     sdr::overlay::OverlayObject* pTempOverlay = getCursorOverlay();
     219           0 :     setCursorOverlay(rSwap.getCursorOverlay());
     220           0 :     rSwap.setCursorOverlay(pTempOverlay);
     221             : 
     222           0 :     const bool bTempShowTxtInputFldOverlay = mbShowTxtInputFldOverlay;
     223           0 :     mbShowTxtInputFldOverlay = rSwap.mbShowTxtInputFldOverlay;
     224           0 :     rSwap.mbShowTxtInputFldOverlay = bTempShowTxtInputFldOverlay;
     225             : 
     226           0 :     sw::overlay::OverlayRangesOutline* pTempTxtInputFldOverlay = mpTxtInputFldOverlay;
     227           0 :     mpTxtInputFldOverlay = rSwap.mpTxtInputFldOverlay;
     228           0 :     rSwap.mpTxtInputFldOverlay = pTempTxtInputFldOverlay;
     229             : #endif
     230           0 : }
     231             : 
     232        7441 : void SwSelPaintRects::Hide()
     233             : {
     234             : #if HAVE_FEATURE_DESKTOP
     235        7441 :     if(mpCursorOverlay)
     236             :     {
     237          74 :         delete mpCursorOverlay;
     238          74 :         mpCursorOverlay = 0;
     239             :     }
     240             : 
     241        7441 :     if ( mpTxtInputFldOverlay != NULL )
     242             :     {
     243           0 :         delete mpTxtInputFldOverlay;
     244           0 :         mpTxtInputFldOverlay = NULL;
     245             :     }
     246             : #endif
     247             : 
     248        7441 :     SwRects::clear();
     249        7441 : }
     250             : 
     251       58979 : void SwSelPaintRects::Show()
     252             : {
     253       58979 :     SdrView* pView = (SdrView*)pCShell->GetDrawView();
     254             : 
     255       58979 :     if(pView && pView->PaintWindowCount())
     256             :     {
     257             :         // reset rects
     258       58979 :         SwRects::clear();
     259       58979 :         FillRects();
     260             : 
     261             : #if HAVE_FEATURE_DESKTOP
     262             :         // get new rects
     263       58979 :         std::vector< basegfx::B2DRange > aNewRanges;
     264             : 
     265       59439 :         for(sal_uInt16 a(0); a < size(); a++)
     266             :         {
     267         460 :             const SwRect aNextRect((*this)[a]);
     268         460 :             const Rectangle aPntRect(aNextRect.SVRect());
     269             : 
     270             :             aNewRanges.push_back(basegfx::B2DRange(
     271         920 :                 aPntRect.Left(), aPntRect.Top(),
     272        1380 :                 aPntRect.Right() + 1, aPntRect.Bottom() + 1));
     273             :         }
     274             : 
     275       58979 :         if(mpCursorOverlay)
     276             :         {
     277         222 :             if(!aNewRanges.empty())
     278             :             {
     279         210 :                 static_cast< sdr::overlay::OverlaySelection* >(mpCursorOverlay)->setRanges(aNewRanges);
     280             :             }
     281             :             else
     282             :             {
     283          12 :                 delete mpCursorOverlay;
     284          12 :                 mpCursorOverlay = 0;
     285             :             }
     286             :         }
     287       58757 :         else if(!empty())
     288             :         {
     289          86 :             SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
     290          86 :             rtl::Reference< ::sdr::overlay::OverlayManager > xTargetOverlay = pCandidate->GetOverlayManager();
     291             : 
     292          86 :             if (xTargetOverlay.is())
     293             :             {
     294             :                 // get the system's hilight color
     295          86 :                 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
     296          86 :                 const Color aHighlight(aSvtOptionsDrawinglayer.getHilightColor());
     297             : 
     298             :                 // create correct selection
     299             :                 mpCursorOverlay = new sdr::overlay::OverlaySelection(
     300             :                     sdr::overlay::OVERLAY_TRANSPARENT,
     301             :                     aHighlight,
     302             :                     aNewRanges,
     303          86 :                     true);
     304             : 
     305          86 :                 xTargetOverlay->add(*mpCursorOverlay);
     306          86 :             }
     307             :         }
     308             : 
     309       58979 :         HighlightInputFld();
     310             : #else
     311             :         const OutputDevice* pOut = GetShell()->GetWin();
     312             :         if ( ! pOut )
     313             :             pOut = GetShell()->GetOut();
     314             :         SwWrtShell *pWrtShell = dynamic_cast<SwWrtShell*>(const_cast<SwCrsrShell*>(GetShell()));
     315             :         if (!empty())
     316             :         {
     317             :             if (pWrtShell)
     318             :             {
     319             :                 // Buffer will be deallocated in the UI layer
     320             :                 MLORect *rects = (MLORect *) malloc((sizeof(MLORect))*size());
     321             :                 for (size_t i = 0; i < size(); ++i)
     322             :                 {
     323             :                     Point origin = pOut->LogicToPixel((*this)[i].Pos());
     324             :                     Size ssize = pOut->LogicToPixel((*this)[i].SSize());
     325             : #ifdef IOS
     326             :                     rects[i] = CGRectMake(origin.X(), origin.Y(),
     327             :                                           ssize.Width(), ssize.Height());
     328             : #else
     329             :                     // Not yet implemented
     330             :                     (void) origin;
     331             :                     (void) ssize;
     332             : #endif
     333             :                 }
     334             :                 // GetShell returns a SwCrsrShell which actually is a SwWrtShell
     335             :                 touch_ui_selection_start(MLOSelectionText, pWrtShell, rects, size(), NULL);
     336             :             }
     337             :         }
     338             :         else
     339             :         {
     340             :             touch_ui_selection_none();
     341             :         }
     342             : #endif
     343             :     }
     344       58979 : }
     345             : 
     346             : #if !HAVE_FEATURE_DESKTOP
     347             : 
     348             : extern "C" void touch_lo_selection_attempt_resize(const void * /* documentHandle */,
     349             :                                                   MLORect * /* selectedRectangles */,
     350             :                                                   int /* numberOfRectangles */)
     351             : {
     352             : }
     353             : 
     354             : #endif
     355             : 
     356       58979 : void SwSelPaintRects::HighlightInputFld()
     357             : {
     358       58979 :     std::vector< basegfx::B2DRange > aInputFldRanges;
     359             : 
     360       58979 :     if ( mbShowTxtInputFldOverlay )
     361             :     {
     362             :         SwTxtInputFld* pCurTxtInputFldAtCrsr =
     363       58348 :             dynamic_cast<SwTxtInputFld*>(GetShell()->GetTxtFldAtPos( GetShell()->GetCrsr()->Start(), false ));
     364       58348 :         if ( pCurTxtInputFldAtCrsr != NULL )
     365             :         {
     366           0 :             SwTxtNode* pTxtNode = pCurTxtInputFldAtCrsr->GetpTxtNode();
     367             :             ::boost::scoped_ptr<SwShellCrsr> pCrsrForInputTxtFld(
     368           0 :                 new SwShellCrsr( *GetShell(), SwPosition( *pTxtNode, *(pCurTxtInputFldAtCrsr->GetStart()) ) ) );
     369           0 :             pCrsrForInputTxtFld->SetMark();
     370           0 :             pCrsrForInputTxtFld->GetMark()->nNode = *pTxtNode;
     371           0 :             pCrsrForInputTxtFld->GetMark()->nContent.Assign( pTxtNode, *(pCurTxtInputFldAtCrsr->End()) );
     372             : 
     373           0 :             pCrsrForInputTxtFld->FillRects();
     374             : 
     375           0 :             for (size_t a(0); a < pCrsrForInputTxtFld->size(); ++a)
     376             :             {
     377           0 :                 const SwRect aNextRect((*pCrsrForInputTxtFld)[a]);
     378           0 :                 const Rectangle aPntRect(aNextRect.SVRect());
     379             : 
     380             :                 aInputFldRanges.push_back(basegfx::B2DRange(
     381           0 :                     aPntRect.Left(), aPntRect.Top(),
     382           0 :                     aPntRect.Right() + 1, aPntRect.Bottom() + 1));
     383           0 :             }
     384             :         }
     385             :     }
     386             : 
     387       58979 :     if ( aInputFldRanges.size() > 0 )
     388             :     {
     389           0 :         if ( mpTxtInputFldOverlay != NULL )
     390             :         {
     391           0 :             mpTxtInputFldOverlay->setRanges( aInputFldRanges );
     392             :         }
     393             :         else
     394             :         {
     395           0 :             SdrView* pView = (SdrView*)GetShell()->GetDrawView();
     396           0 :             SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
     397           0 :             rtl::Reference<sdr::overlay::OverlayManager> xTargetOverlay = pCandidate->GetOverlayManager();
     398             : 
     399           0 :             if (xTargetOverlay.is())
     400             :             {
     401             :                 // use system's hilight color with decreased luminance as highlight color
     402           0 :                 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
     403           0 :                 Color aHighlight(aSvtOptionsDrawinglayer.getHilightColor());
     404           0 :                 aHighlight.DecreaseLuminance( 128 );
     405             : 
     406           0 :                 mpTxtInputFldOverlay = new sw::overlay::OverlayRangesOutline( aHighlight, aInputFldRanges );
     407           0 :                 xTargetOverlay->add( *mpTxtInputFldOverlay );
     408           0 :             }
     409             :         }
     410             :     }
     411             :     else
     412             :     {
     413       58979 :         if ( mpTxtInputFldOverlay != NULL )
     414             :         {
     415           0 :             delete mpTxtInputFldOverlay;
     416           0 :             mpTxtInputFldOverlay = NULL;
     417             :         }
     418       58979 :     }
     419       58979 : }
     420             : 
     421        3824 : void SwSelPaintRects::Invalidate( const SwRect& rRect )
     422             : {
     423        3824 :     sal_uInt16 nSz = size();
     424        3824 :     if( !nSz )
     425        7639 :         return;
     426             : 
     427           9 :     SwRegionRects aReg( GetShell()->VisArea() );
     428           9 :     aReg.assign( begin(), end() );
     429           9 :     aReg -= rRect;
     430           9 :     SwRects::erase( begin(), begin() + nSz );
     431           9 :     SwRects::insert( begin(), aReg.begin(), aReg.end() );
     432             : 
     433             :     // If the selection is to the right or at the bottom, outside the
     434             :     // visible area, it is never aligned on one pixel at the right/bottom.
     435             :     // This has to be determined here and if that is the case the
     436             :     // rectangle has to be expanded.
     437           9 :     if( GetShell()->m_bVisPortChgd && 0 != ( nSz = size()) )
     438             :     {
     439           0 :         SwSelPaintRects::Get1PixelInLogic( *GetShell() );
     440           0 :         iterator it = begin();
     441           0 :         for( ; nSz--; ++it )
     442             :         {
     443           0 :             SwRect& rRectIt = *it;
     444           0 :             if( rRectIt.Right() == GetShell()->m_aOldRBPos.X() )
     445           0 :                 rRectIt.Right( rRectIt.Right() + nPixPtX );
     446           0 :             if( rRectIt.Bottom() == GetShell()->m_aOldRBPos.Y() )
     447           0 :                 rRectIt.Bottom( rRectIt.Bottom() + nPixPtY );
     448             :         }
     449           9 :     }
     450             : }
     451             : 
     452           0 : void SwSelPaintRects::Paint( const Rectangle& /*rRect*/ )
     453             : {
     454             :     // nothing to do with overlays
     455           0 : }
     456             : 
     457             : // check current MapMode of the shell and set possibly the static members.
     458             : // Optional set the parameters pX, pY
     459          15 : void SwSelPaintRects::Get1PixelInLogic( const SwViewShell& rSh,
     460             :                                         long* pX, long* pY )
     461             : {
     462          15 :     const OutputDevice* pOut = rSh.GetWin();
     463          15 :     if ( ! pOut )
     464           0 :         pOut = rSh.GetOut();
     465             : 
     466          15 :     const MapMode& rMM = pOut->GetMapMode();
     467          43 :     if( pMapMode->GetMapUnit() != rMM.GetMapUnit() ||
     468          28 :         pMapMode->GetScaleX() != rMM.GetScaleX() ||
     469          13 :         pMapMode->GetScaleY() != rMM.GetScaleY() )
     470             :     {
     471           2 :         *pMapMode = rMM;
     472           2 :         Size aTmp( 1, 1 );
     473           2 :         aTmp = pOut->PixelToLogic( aTmp );
     474           2 :         nPixPtX = aTmp.Width();
     475           2 :         nPixPtY = aTmp.Height();
     476             :     }
     477          15 :     if( pX )
     478          15 :         *pX = nPixPtX;
     479          15 :     if( pY )
     480          15 :         *pY = nPixPtY;
     481          15 : }
     482             : 
     483        1999 : SwShellCrsr::SwShellCrsr(
     484             :     const SwCrsrShell& rCShell,
     485             :     const SwPosition &rPos )
     486             :     : SwCursor(rPos,0,false)
     487             :     , SwSelPaintRects(rCShell)
     488        1999 :     , pPt(SwPaM::GetPoint())
     489        1999 : {}
     490             : 
     491          43 : SwShellCrsr::SwShellCrsr(
     492             :     const SwCrsrShell& rCShell,
     493             :     const SwPosition &rPos,
     494             :     const Point& rPtPos,
     495             :     SwPaM* pRing )
     496             :     : SwCursor(rPos, pRing, false)
     497             :     , SwSelPaintRects(rCShell)
     498             :     , aMkPt(rPtPos)
     499             :     , aPtPt(rPtPos)
     500          43 :     , pPt(SwPaM::GetPoint())
     501          43 : {}
     502             : 
     503           0 : SwShellCrsr::SwShellCrsr( SwShellCrsr& rICrsr )
     504             :     : SwCursor(rICrsr)
     505           0 :     , SwSelPaintRects(*rICrsr.GetShell())
     506           0 :     , aMkPt(rICrsr.GetMkPos())
     507           0 :     , aPtPt(rICrsr.GetPtPos())
     508           0 :     , pPt(SwPaM::GetPoint())
     509           0 : {}
     510             : 
     511        6111 : SwShellCrsr::~SwShellCrsr()
     512        6111 : {}
     513             : 
     514         172 : bool SwShellCrsr::IsReadOnlyAvailable() const
     515             : {
     516         172 :     return GetShell()->IsReadOnlyAvailable();
     517             : }
     518             : 
     519         352 : void SwShellCrsr::SetMark()
     520             : {
     521         352 :     if( SwPaM::GetPoint() == pPt )
     522         314 :         aMkPt = aPtPt;
     523             :     else
     524          38 :         aPtPt = aMkPt;
     525         352 :     SwPaM::SetMark();
     526         352 : }
     527             : 
     528       59216 : void SwShellCrsr::FillRects()
     529             : {
     530             :     // calculate the new rectangles
     531      118986 :     if( HasMark() &&
     532        1108 :         GetPoint()->nNode.GetNode().IsCntntNode() &&
     533       60878 :         GetPoint()->nNode.GetNode().GetCntntNode()->getLayoutFrm( GetShell()->GetLayout() ) &&
     534         643 :         (GetMark()->nNode == GetPoint()->nNode ||
     535         178 :         (GetMark()->nNode.GetNode().IsCntntNode() &&
     536          89 :          GetMark()->nNode.GetNode().GetCntntNode()->getLayoutFrm( GetShell()->GetLayout() ) )   ))
     537         554 :         GetShell()->GetLayout()->CalcFrmRects( *this, GetShell()->IsTableMode() );
     538       59216 : }
     539             : 
     540       33374 : void SwShellCrsr::Show()
     541             : {
     542       33374 :     SwShellCrsr * pTmp = this;
     543       33374 :     do {
     544       33374 :         pTmp->SwSelPaintRects::Show();
     545       33374 :     } while( this != ( pTmp = dynamic_cast<SwShellCrsr*>(pTmp->GetNext()) ) );
     546       33374 : }
     547             : 
     548             : // This rectangle gets painted anew, therefore the SSelection in this
     549             : // area is invalid.
     550        3824 : void SwShellCrsr::Invalidate( const SwRect& rRect )
     551             : {
     552        3824 :     SwShellCrsr * pTmp = this;
     553             : 
     554        3824 :     do
     555             :     {
     556        3824 :         pTmp->SwSelPaintRects::Invalidate( rRect );
     557             : 
     558             :         // skip any non SwShellCrsr objects in the ring
     559             :         // see also: SwAutoFormat::DeleteSel()
     560        3824 :         Ring* pTmpRing = pTmp;
     561        3824 :         pTmp = 0;
     562        3824 :         do
     563             :         {
     564        3824 :             pTmpRing = pTmpRing->GetNext();
     565        3824 :             pTmp = dynamic_cast<SwShellCrsr*>(pTmpRing);
     566             :         }
     567             :         while ( !pTmp );
     568             :     }
     569             :     while( this != pTmp );
     570        3824 : }
     571             : 
     572        5394 : void SwShellCrsr::Hide()
     573             : {
     574        5394 :     SwShellCrsr * pTmp = this;
     575        5394 :     do {
     576        5394 :         pTmp->SwSelPaintRects::Hide();
     577        5394 :     } while( this != ( pTmp = dynamic_cast<SwShellCrsr*>(pTmp->GetNext()) ) );
     578        5394 : }
     579             : 
     580          14 : SwCursor* SwShellCrsr::Create( SwPaM* pRing ) const
     581             : {
     582          14 :     return new SwShellCrsr( *GetShell(), *GetPoint(), GetPtPos(), pRing );
     583             : }
     584             : 
     585           0 : short SwShellCrsr::MaxReplaceArived()
     586             : {
     587           0 :     short nRet = RET_YES;
     588           0 :     Window* pDlg = (Window*) SwView::GetSearchDialog();
     589           0 :     if( pDlg )
     590             :     {
     591             :         // Terminate old actions. The table-frames get constructed and
     592             :         // a SSelection can be created.
     593           0 :         std::vector<sal_uInt16> aArr;
     594             :         sal_uInt16 nActCnt;
     595           0 :         SwViewShell *pShell = const_cast< SwCrsrShell* >( GetShell() ),
     596           0 :                   *pSh = pShell;
     597           0 :         do {
     598           0 :             for( nActCnt = 0; pSh->ActionPend(); ++nActCnt )
     599           0 :                 pSh->EndAction();
     600           0 :             aArr.push_back( nActCnt );
     601           0 :         } while( pShell != ( pSh = (SwViewShell*)pSh->GetNext() ) );
     602             : 
     603             :         {
     604           0 :             nRet = QueryBox( pDlg, SW_RES( MSG_COMCORE_ASKSEARCH )).Execute();
     605             :         }
     606             : 
     607           0 :         for( sal_uInt16 n = 0; n < aArr.size(); ++n )
     608             :         {
     609           0 :             for( nActCnt = aArr[n]; nActCnt--; )
     610           0 :                 pSh->StartAction();
     611           0 :             pSh = (SwViewShell*)pSh->GetNext();
     612           0 :         }
     613             :     }
     614             :     else
     615             :         // otherwise from the Basic, and than switch to RET_YES
     616           0 :         nRet = RET_YES;
     617             : 
     618           0 :     return nRet;
     619             : }
     620             : 
     621           0 : void SwShellCrsr::SaveTblBoxCntnt( const SwPosition* pPos )
     622             : {
     623           0 :     ((SwCrsrShell*)GetShell())->SaveTblBoxCntnt( pPos );
     624           0 : }
     625             : 
     626           0 : bool SwShellCrsr::UpDown( bool bUp, sal_uInt16 nCnt )
     627             : {
     628             :     return SwCursor::UpDown( bUp, nCnt,
     629           0 :                             &GetPtPos(), GetShell()->GetUpDownX() );
     630             : }
     631             : 
     632             : // if <true> than the cursor can be set to the position.
     633           5 : bool SwShellCrsr::IsAtValidPos( bool bPoint ) const
     634             : {
     635          10 :     if( GetShell() && ( GetShell()->IsAllProtect() ||
     636          10 :         GetShell()->GetViewOptions()->IsReadonly() ||
     637          10 :         ( GetShell()->Imp()->GetDrawView() &&
     638           5 :           GetShell()->Imp()->GetDrawView()->GetMarkedObjectList().GetMarkCount() )))
     639           0 :         return true;
     640             : 
     641           5 :     return SwCursor::IsAtValidPos( bPoint );
     642             : }
     643             : 
     644           3 : SwShellTableCrsr::SwShellTableCrsr( const SwCrsrShell& rCrsrSh,
     645             :                                     const SwPosition& rPos )
     646           3 :     : SwCursor(rPos,0,false), SwShellCrsr(rCrsrSh, rPos), SwTableCursor(rPos)
     647             : {
     648           3 : }
     649             : 
     650           3 : SwShellTableCrsr::SwShellTableCrsr( const SwCrsrShell& rCrsrSh,
     651             :                     const SwPosition& rMkPos, const Point& rMkPt,
     652             :                     const SwPosition& rPtPos, const Point& rPtPt )
     653           3 :     : SwCursor(rPtPos,0,false), SwShellCrsr(rCrsrSh, rPtPos), SwTableCursor(rPtPos)
     654             : {
     655           3 :     SetMark();
     656           3 :     *GetMark() = rMkPos;
     657           3 :     GetMkPos() = rMkPt;
     658           3 :     GetPtPos() = rPtPt;
     659           3 : }
     660             : 
     661          12 : SwShellTableCrsr::~SwShellTableCrsr() {}
     662             : 
     663           6 : void SwShellTableCrsr::SetMark()                { SwShellCrsr::SetMark(); }
     664             : 
     665           0 : SwCursor* SwShellTableCrsr::Create( SwPaM* pRing ) const
     666             : {
     667           0 :     return SwShellCrsr::Create( pRing );
     668             : }
     669             : 
     670           0 : short SwShellTableCrsr::MaxReplaceArived()
     671             : {
     672           0 :     return SwShellCrsr::MaxReplaceArived();
     673             : }
     674             : 
     675           0 : void SwShellTableCrsr::SaveTblBoxCntnt( const SwPosition* pPos )
     676             : {
     677           0 :     SwShellCrsr::SaveTblBoxCntnt( pPos );
     678           0 : }
     679             : 
     680          24 : void SwShellTableCrsr::FillRects()
     681             : {
     682             :     // Calculate the new rectangles. If the cursor is still "parked" do nothing
     683          24 :     if (m_SelectedBoxes.empty() || bParked || !GetPoint()->nNode.GetIndex())
     684          24 :         return;
     685             : 
     686          24 :     SwRegionRects aReg( GetShell()->VisArea() );
     687          24 :     SwNodes& rNds = GetDoc()->GetNodes();
     688          88 :     for (size_t n = 0; n < m_SelectedBoxes.size(); ++n)
     689             :     {
     690          64 :         const SwStartNode* pSttNd = m_SelectedBoxes[n]->GetSttNd();
     691          64 :         const SwTableNode* pSelTblNd = pSttNd->FindTableNode();
     692             : 
     693          64 :         SwNodeIndex aIdx( *pSttNd );
     694          64 :         SwCntntNode* pCNd = rNds.GoNextSection( &aIdx, true, false );
     695             : 
     696             :         // table in table
     697             :         // (see also lcl_FindTopLevelTable in unoobj2.cxx for a different
     698             :         // version to do this)
     699          64 :         const SwTableNode* pCurTblNd = pCNd ? pCNd->FindTableNode() : NULL;
     700         128 :         while ( pSelTblNd != pCurTblNd && pCurTblNd )
     701             :         {
     702           0 :             aIdx = pCurTblNd->EndOfSectionIndex();
     703           0 :             pCNd = rNds.GoNextSection( &aIdx, true, false );
     704           0 :             pCurTblNd = pCNd->FindTableNode();
     705             :         }
     706             : 
     707          64 :         if( !pCNd )
     708           0 :             continue;
     709             : 
     710          64 :         SwFrm* pFrm = pCNd->getLayoutFrm( GetShell()->GetLayout(), &GetSttPos() );
     711         192 :         while( pFrm && !pFrm->IsCellFrm() )
     712          64 :             pFrm = pFrm->GetUpper();
     713             : 
     714             :         OSL_ENSURE( pFrm, "Node not in a table" );
     715             : 
     716         192 :         while ( pFrm )
     717             :         {
     718          64 :             if( aReg.GetOrigin().IsOver( pFrm->Frm() ) )
     719          64 :                 aReg -= pFrm->Frm();
     720             : 
     721          64 :             pFrm = pFrm->GetNextCellLeaf( MAKEPAGE_NONE );
     722             :         }
     723          64 :     }
     724          24 :     aReg.Invert();
     725          24 :     insert( begin(), aReg.begin(), aReg.end() );
     726             : }
     727             : 
     728             : // Check if the SPoint is within the Table-SSelection.
     729           0 : bool SwShellTableCrsr::IsInside( const Point& rPt ) const
     730             : {
     731             :     // Calculate the new rectangles. If the cursor is still "parked" do nothing
     732           0 :     if (m_SelectedBoxes.empty() || bParked || !GetPoint()->nNode.GetIndex())
     733           0 :         return false;
     734             : 
     735           0 :     SwNodes& rNds = GetDoc()->GetNodes();
     736           0 :     for (size_t n = 0; n < m_SelectedBoxes.size(); ++n)
     737             :     {
     738           0 :         SwNodeIndex aIdx( *m_SelectedBoxes[n]->GetSttNd() );
     739           0 :         SwCntntNode* pCNd = rNds.GoNextSection( &aIdx, true, false );
     740           0 :         if( !pCNd )
     741           0 :             continue;
     742             : 
     743           0 :         SwFrm* pFrm = pCNd->getLayoutFrm( GetShell()->GetLayout(), &GetPtPos() );
     744           0 :         while( pFrm && !pFrm->IsCellFrm() )
     745           0 :             pFrm = pFrm->GetUpper();
     746             :         OSL_ENSURE( pFrm, "Node not in a table" );
     747           0 :         if( pFrm && pFrm->Frm().IsInside( rPt ) )
     748           0 :             return true;
     749           0 :     }
     750           0 :     return false;
     751             : }
     752             : 
     753           3 : bool SwShellTableCrsr::IsAtValidPos( bool bPoint ) const
     754             : {
     755           3 :     return SwShellCrsr::IsAtValidPos( bPoint );
     756             : }
     757             : 
     758             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10