/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 * only, as published by the Free Software Foundation. * * OpenOffice.org is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License version 3 for more details * (a copy is included in the LICENSE file that accompanied this code). * * You should have received a copy of the GNU Lesser General Public License * version 3 along with OpenOffice.org. If not, see * * for a copy of the LGPLv3 License. * ************************************************************************/ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sw.hxx" #include #include #include #include #include #include #include #include #include #include #include #include #include // SwTxtFrm #include #include #include #include #include // GetSearchDialog #include // ResId for query when (switching to?) Search & Replace #include #include #include #include extern void SwCalcPixStatics( OutputDevice *pOut ); // Here static members are defined. They will get changed on alteration of the // MapMode. This is done so that on ShowCrsr the same size does not have to be // expensively determined again and again. long SwSelPaintRects::nPixPtX = 0; long SwSelPaintRects::nPixPtY = 0; MapMode* SwSelPaintRects::pMapMode = 0; // ----- Starting from here: classes / methods for the non-text-cursor ----- SwVisCrsr::SwVisCrsr( const SwCrsrShell * pCShell ) : pCrsrShell( pCShell ) { pCShell->GetWin()->SetCursor( &aTxtCrsr ); bIsVisible = aTxtCrsr.IsVisible(); bIsDragCrsr = sal_False; aTxtCrsr.SetWidth( 0 ); #ifdef SW_CRSR_TIMER bTimerOn = sal_True; SetTimeout( 50 ); // 50 millisecond delay #endif } SwVisCrsr::~SwVisCrsr() { #ifdef SW_CRSR_TIMER if( bTimerOn ) Stop(); // stop timer #endif if( bIsVisible && aTxtCrsr.IsVisible() ) aTxtCrsr.Hide(); pCrsrShell->GetWin()->SetCursor( 0 ); } void SwVisCrsr::Show() { if( !bIsVisible ) { bIsVisible = sal_True; // display at all? if( pCrsrShell->VisArea().IsOver( pCrsrShell->aCharRect ) ) #ifdef SW_CRSR_TIMER { if( bTimerOn ) Start(); // start timer else { if( IsActive() ) Stop(); // stop timer _SetPosAndShow(); } } #else _SetPosAndShow(); #endif } } void SwVisCrsr::Hide() { if( bIsVisible ) { bIsVisible = sal_False; #ifdef SW_CRSR_TIMER if( IsActive() ) Stop(); // stop timer #endif if( aTxtCrsr.IsVisible() ) // Shouldn't the flags be in effect? aTxtCrsr.Hide(); } } #ifdef SW_CRSR_TIMER void SwVisCrsr::Timeout() { OSL_ENSURE( !bIsDragCrsr, "Timer vorher abschalten" ); if( bIsVisible ) { if ( !pCrsrShell->GetWin() ) // SwFrmFmt::GetGraphic suspends Win temporarily! Start(); else _SetPosAndShow(); } } sal_Bool SwCrsrShell::ChgCrsrTimerFlag( sal_Bool bTimerOn ) { return pVisCrsr->ChgTimerFlag( bTimerOn ); } sal_Bool SwVisCrsr::ChgTimerFlag( sal_Bool bFlag ) { bOld = bTimerOn; if( !bFlag && bIsVisible && IsActive() ) { Stop(); // stop timer _SetPosAndShow(); } bTimerOn = bFlag; return bOld; } #endif void SwVisCrsr::_SetPosAndShow() { SwRect aRect; long nTmpY = pCrsrShell->aCrsrHeight.Y(); if( 0 > nTmpY ) { nTmpY = -nTmpY; aTxtCrsr.SetOrientation( 900 ); aRect = SwRect( pCrsrShell->aCharRect.Pos(), Size( pCrsrShell->aCharRect.Height(), nTmpY ) ); aRect.Pos().X() += pCrsrShell->aCrsrHeight.X(); if( pCrsrShell->IsOverwriteCrsr() ) aRect.Pos().Y() += aRect.Width(); } else { aTxtCrsr.SetOrientation( 0 ); aRect = SwRect( pCrsrShell->aCharRect.Pos(), Size( pCrsrShell->aCharRect.Width(), nTmpY ) ); aRect.Pos().Y() += pCrsrShell->aCrsrHeight.X(); } // check if cursor should show the current cursor bidi level aTxtCrsr.SetDirection( CURSOR_DIRECTION_NONE ); const SwCursor* pTmpCrsr = pCrsrShell->_GetCrsr(); if ( pTmpCrsr && !pCrsrShell->IsOverwriteCrsr() ) { SwNode& rNode = pTmpCrsr->GetPoint()->nNode.GetNode(); if( rNode.IsTxtNode() ) { const SwTxtNode& rTNd = *rNode.GetTxtNode(); const SwFrm* pFrm = rTNd.getLayoutFrm( pCrsrShell->GetLayout(), 0, 0, sal_False ); if ( pFrm ) { const SwScriptInfo* pSI = ((SwTxtFrm*)pFrm)->GetScriptInfo(); // cursor level has to be shown if ( pSI && pSI->CountDirChg() > 1 ) { aTxtCrsr.SetDirection( ( pTmpCrsr->GetCrsrBidiLevel() % 2 ) ? CURSOR_DIRECTION_RTL : CURSOR_DIRECTION_LTR ); } if ( pFrm->IsRightToLeft() ) { const OutputDevice *pOut = pCrsrShell->GetOut(); if ( pOut ) { long nSize = pOut->GetSettings().GetStyleSettings().GetCursorSize(); Size aSize( nSize, nSize ); aSize = pOut->PixelToLogic( aSize ); aRect.Left( aRect.Left() - aSize.Width() ); } } } } } if( aRect.Height() ) { ::SwCalcPixStatics( pCrsrShell->GetOut() ); ::SwAlignRect( aRect, (ViewShell*)pCrsrShell ); } if( !pCrsrShell->IsOverwriteCrsr() || bIsDragCrsr || pCrsrShell->IsSelection() ) aRect.Width( 0 ); aTxtCrsr.SetSize( aRect.SSize() ); aTxtCrsr.SetPos( aRect.Pos() ); if ( !pCrsrShell->IsCrsrReadonly() || pCrsrShell->GetViewOptions()->IsSelectionInReadonly() ) { if ( pCrsrShell->GetDrawView() ) ((SwDrawView*)pCrsrShell->GetDrawView())->SetAnimationEnabled( !pCrsrShell->IsSelection() ); sal_uInt16 nStyle = bIsDragCrsr ? CURSOR_SHADOW : 0; if( nStyle != aTxtCrsr.GetStyle() ) { aTxtCrsr.SetStyle( nStyle ); aTxtCrsr.SetWindow( bIsDragCrsr ? pCrsrShell->GetWin() : 0 ); } aTxtCrsr.Show(); } } ////////////////////////////////////////////////////////////////////////////// SwSelPaintRects::SwSelPaintRects( const SwCrsrShell& rCSh ) : SwRects( 0 ), pCShell( &rCSh ), mpCursorOverlay(0) { } SwSelPaintRects::~SwSelPaintRects() { Hide(); } void SwSelPaintRects::swapContent(SwSelPaintRects& rSwap) { SwRects aTempRects; aTempRects.Insert(this, 0); Remove(0, Count()); Insert(&rSwap, 0); rSwap.Remove(0, rSwap.Count()); rSwap.Insert(&aTempRects, 0); // #i75172# also swap mpCursorOverlay sdr::overlay::OverlayObject* pTempOverlay = getCursorOverlay(); setCursorOverlay(rSwap.getCursorOverlay()); rSwap.setCursorOverlay(pTempOverlay); } void SwSelPaintRects::Hide() { if(mpCursorOverlay) { delete mpCursorOverlay; mpCursorOverlay = 0; } SwRects::Remove( 0, Count() ); } void SwSelPaintRects::Show() { SdrView* pView = (SdrView*)pCShell->GetDrawView(); if(pView && pView->PaintWindowCount()) { // reset rects SwRects::Remove( 0, SwRects::Count() ); FillRects(); // get new rects std::vector< basegfx::B2DRange > aNewRanges; for(sal_uInt16 a(0); a < Count(); a++) { const SwRect aNextRect((*this)[a]); const Rectangle aPntRect(aNextRect.SVRect()); aNewRanges.push_back(basegfx::B2DRange( aPntRect.Left(), aPntRect.Top(), aPntRect.Right() + 1, aPntRect.Bottom() + 1)); } if(mpCursorOverlay) { if(!aNewRanges.empty()) { static_cast< sdr::overlay::OverlaySelection* >(mpCursorOverlay)->setRanges(aNewRanges); } else { delete mpCursorOverlay; mpCursorOverlay = 0; } } else if(Count()) { SdrPaintWindow* pCandidate = pView->GetPaintWindow(0); sdr::overlay::OverlayManager* pTargetOverlay = pCandidate->GetOverlayManager(); if(pTargetOverlay) { // #i97672# get the system's highlight color and limit it to the maximum // allowed luminance. This is needed to react on too bright highlight colors // which would otherwise vive a bad visualisation. const OutputDevice *pOut = Application::GetDefaultDevice(); Color aHighlight(pOut->GetSettings().GetStyleSettings().GetHighlightColor()); const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer; const basegfx::BColor aSelection(aHighlight.getBColor()); const double fLuminance(aSelection.luminance()); const double fMaxLum(aSvtOptionsDrawinglayer.GetSelectionMaximumLuminancePercent() / 100.0); if(fLuminance > fMaxLum) { const double fFactor(fMaxLum / fLuminance); const basegfx::BColor aNewSelection( aSelection.getRed() * fFactor, aSelection.getGreen() * fFactor, aSelection.getBlue() * fFactor); aHighlight = Color(aNewSelection); } // create correct selection mpCursorOverlay = new sdr::overlay::OverlaySelection( sdr::overlay::OVERLAY_TRANSPARENT, aHighlight, aNewRanges, true); pTargetOverlay->add(*mpCursorOverlay); } } } } void SwSelPaintRects::Invalidate( const SwRect& rRect ) { sal_uInt16 nSz = Count(); if( !nSz ) return; SwRegionRects aReg( GetShell()->VisArea() ); aReg.Remove( 0, aReg.Count() ); aReg.Insert( this, 0 ); aReg -= rRect; SwRects::Remove( 0, nSz ); SwRects::Insert( &aReg, 0 ); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // If the selection is to the right or at the bottom, outside the // visible area, it is never aligned on one pixel at the right/bottom. // This has to be determined here and if that is the case the // rectangle has to be expanded. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if( GetShell()->bVisPortChgd && 0 != ( nSz = Count()) ) { SwSelPaintRects::Get1PixelInLogic( *GetShell() ); SwRect* pRect = (SwRect*)GetData(); for( ; nSz--; ++pRect ) { if( pRect->Right() == GetShell()->aOldRBPos.X() ) pRect->Right( pRect->Right() + nPixPtX ); if( pRect->Bottom() == GetShell()->aOldRBPos.Y() ) pRect->Bottom( pRect->Bottom() + nPixPtY ); } } } void SwSelPaintRects::Paint( const Rectangle& /*rRect*/ ) { // nothing to do with overlays } // check current MapMode of the shell and set possibly the static members. // Optional set the parameters pX, pY void SwSelPaintRects::Get1PixelInLogic( const ViewShell& rSh, long* pX, long* pY ) { const OutputDevice* pOut = rSh.GetWin(); if ( ! pOut ) pOut = rSh.GetOut(); const MapMode& rMM = pOut->GetMapMode(); if( pMapMode->GetMapUnit() != rMM.GetMapUnit() || pMapMode->GetScaleX() != rMM.GetScaleX() || pMapMode->GetScaleY() != rMM.GetScaleY() ) { *pMapMode = rMM; Size aTmp( 1, 1 ); aTmp = pOut->PixelToLogic( aTmp ); nPixPtX = aTmp.Width(); nPixPtY = aTmp.Height(); } if( pX ) *pX = nPixPtX; if( pY ) *pY = nPixPtY; } SwShellCrsr::SwShellCrsr( const SwCrsrShell& rCShell, const SwPosition &rPos ) : SwCursor(rPos,0,false), SwSelPaintRects(rCShell), pPt(SwPaM::GetPoint()) {} SwShellCrsr::SwShellCrsr( const SwCrsrShell& rCShell, const SwPosition &rPos, const Point& rPtPos, SwPaM* pRing ) : SwCursor(rPos, pRing, false), SwSelPaintRects(rCShell), aMkPt(rPtPos), aPtPt(rPtPos), pPt(SwPaM::GetPoint()) {} SwShellCrsr::SwShellCrsr( SwShellCrsr& rICrsr ) : SwCursor(rICrsr), SwSelPaintRects(*rICrsr.GetShell()), aMkPt(rICrsr.GetMkPos()), aPtPt(rICrsr.GetPtPos()), pPt(SwPaM::GetPoint()) {} SwShellCrsr::~SwShellCrsr() {} bool SwShellCrsr::IsReadOnlyAvailable() const { return GetShell()->IsReadOnlyAvailable(); } void SwShellCrsr::SetMark() { if( SwPaM::GetPoint() == pPt ) aMkPt = aPtPt; else aPtPt = aMkPt; SwPaM::SetMark(); } void SwShellCrsr::FillRects() { // calculate the new rectangles if( HasMark() && GetPoint()->nNode.GetNode().IsCntntNode() && GetPoint()->nNode.GetNode().GetCntntNode()->getLayoutFrm( GetShell()->GetLayout() ) && (GetMark()->nNode == GetPoint()->nNode || (GetMark()->nNode.GetNode().IsCntntNode() && GetMark()->nNode.GetNode().GetCntntNode()->getLayoutFrm( GetShell()->GetLayout() ) ) )) GetShell()->GetLayout()->CalcFrmRects( *this, GetShell()->IsTableMode() ); //swmod 071107//swmod 071225 } void SwShellCrsr::Show() { SwShellCrsr * pTmp = this; do { pTmp->SwSelPaintRects::Show(); } while( this != ( pTmp = dynamic_cast(pTmp->GetNext()) ) ); } // This rectangle gets painted anew, therefore the SSelection in this // area is invalid. void SwShellCrsr::Invalidate( const SwRect& rRect ) { SwShellCrsr * pTmp = this; do { pTmp->SwSelPaintRects::Invalidate( rRect ); // skip any non SwShellCrsr objects in the ring // (see:SwAutoFormat::DeleteSel() Ring* pTmpRing = pTmp; pTmp = 0; do { pTmpRing = pTmpRing->GetNext(); pTmp = dynamic_cast(pTmpRing); } while ( !pTmp ); } while( this != pTmp ); } void SwShellCrsr::Hide() { SwShellCrsr * pTmp = this; do { pTmp->SwSelPaintRects::Hide(); } while( this != ( pTmp = dynamic_cast(pTmp->GetNext()) ) ); } SwCursor* SwShellCrsr::Create( SwPaM* pRing ) const { return new SwShellCrsr( *GetShell(), *GetPoint(), GetPtPos(), pRing ); } short SwShellCrsr::MaxReplaceArived() { short nRet = RET_YES; Window* pDlg = LAYOUT_THIS_WINDOW (::GetSearchDialog()); if( pDlg ) { // Terminate old actions. The table-frames get constructed and // a SSelection can be created. std::vector aArr; sal_uInt16 nActCnt; ViewShell *pShell = const_cast< SwCrsrShell* >( GetShell() ), *pSh = pShell; do { for( nActCnt = 0; pSh->ActionPend(); ++nActCnt ) pSh->EndAction(); aArr.push_back( nActCnt ); } while( pShell != ( pSh = (ViewShell*)pSh->GetNext() ) ); { nRet = QueryBox( pDlg, SW_RES( MSG_COMCORE_ASKSEARCH )).Execute(); } for( sal_uInt16 n = 0; n < aArr.size(); ++n ) { for( nActCnt = aArr[n]; nActCnt--; ) pSh->StartAction(); pSh = (ViewShell*)pSh->GetNext(); } //swmod 071107//swmod 071225 } else // otherwise from the Basic, and than switch to RET_YES nRet = RET_YES; return nRet; } void SwShellCrsr::SaveTblBoxCntnt( const SwPosition* pPos ) { ((SwCrsrShell*)GetShell())->SaveTblBoxCntnt( pPos ); } sal_Bool SwShellCrsr::UpDown( sal_Bool bUp, sal_uInt16 nCnt ) { return SwCursor::UpDown( bUp, nCnt, &GetPtPos(), GetShell()->GetUpDownX() ); } #if OSL_DEBUG_LEVEL > 1 // JP 05.03.98: To test the UNO-Crsr behavior here the implementation on the // visible cursor. sal_Bool SwShellCrsr::IsSelOvr( int eFlags ) { return SwCursor::IsSelOvr( eFlags ); } #endif // TRUE: The cursor can be set to the position. sal_Bool SwShellCrsr::IsAtValidPos( sal_Bool bPoint ) const { if( GetShell() && ( GetShell()->IsAllProtect() || GetShell()->GetViewOptions()->IsReadonly() || ( GetShell()->Imp()->GetDrawView() && GetShell()->Imp()->GetDrawView()->GetMarkedObjectList().GetMarkCount() ))) return sal_True; return SwCursor::IsAtValidPos( bPoint ); } SwShellTableCrsr::SwShellTableCrsr( const SwCrsrShell& rCrsrSh, const SwPosition& rPos ) : SwCursor(rPos,0,false), SwShellCrsr(rCrsrSh, rPos), SwTableCursor(rPos) { } SwShellTableCrsr::SwShellTableCrsr( const SwCrsrShell& rCrsrSh, const SwPosition& rMkPos, const Point& rMkPt, const SwPosition& rPtPos, const Point& rPtPt ) : SwCursor(rPtPos,0,false), SwShellCrsr(rCrsrSh, rPtPos), SwTableCursor(rPtPos) { SetMark(); *GetMark() = rMkPos; GetMkPos() = rMkPt; GetPtPos() = rPtPt; } SwShellTableCrsr::~SwShellTableCrsr() {} void SwShellTableCrsr::SetMark() { SwShellCrsr::SetMark(); } SwCursor* SwShellTableCrsr::Create( SwPaM* pRing ) const { return SwShellCrsr::Create( pRing ); } short SwShellTableCrsr::MaxReplaceArived() { return SwShellCrsr::MaxReplaceArived(); } void SwShellTableCrsr::SaveTblBoxCntnt( const SwPosition* pPos ) { SwShellCrsr::SaveTblBoxCntnt( pPos ); } void SwShellTableCrsr::FillRects() { // Calculate the new rectangles. // JP 16.01.98: If the cursor is still "parked" do nothing!! if( !aSelBoxes.Count() || bParked || !GetPoint()->nNode.GetIndex() ) return; SwRegionRects aReg( GetShell()->VisArea() ); SwNodes& rNds = GetDoc()->GetNodes(); for( sal_uInt16 n = 0; n < aSelBoxes.Count(); ++n ) { const SwStartNode* pSttNd = (*(aSelBoxes.GetData() + n ))->GetSttNd(); const SwTableNode* pSelTblNd = pSttNd->FindTableNode(); SwNodeIndex aIdx( *pSttNd ); SwCntntNode* pCNd = rNds.GoNextSection( &aIdx, sal_True, sal_False ); // TABLE IN TABLE // (see also lcl_FindTopLevelTable in unoobj2.cxx for a different // version to do this) const SwTableNode* pCurTblNd = pCNd->FindTableNode(); while ( pSelTblNd != pCurTblNd && pCurTblNd ) { aIdx = pCurTblNd->EndOfSectionIndex(); pCNd = rNds.GoNextSection( &aIdx, sal_True, sal_False ); pCurTblNd = pCNd->FindTableNode(); } if( !pCNd ) continue; SwFrm* pFrm = pCNd->getLayoutFrm( GetShell()->GetLayout(), &GetSttPos() ); while( pFrm && !pFrm->IsCellFrm() ) pFrm = pFrm->GetUpper(); OSL_ENSURE( pFrm, "Node nicht in einer Tabelle" ); while ( pFrm ) { if( pFrm && aReg.GetOrigin().IsOver( pFrm->Frm() ) ) aReg -= pFrm->Frm(); pFrm = pFrm->GetNextCellLeaf( MAKEPAGE_NONE ); } } aReg.Invert(); Insert( &aReg, 0 ); } // Check if the SPoint is within the Table-SSelection. sal_Bool SwShellTableCrsr::IsInside( const Point& rPt ) const { // Calculate the new rectangles. // JP 16.01.98: If the cursor is still "parked" do nothing!! if( !aSelBoxes.Count() || bParked || !GetPoint()->nNode.GetIndex() ) return sal_False; SwNodes& rNds = GetDoc()->GetNodes(); for( sal_uInt16 n = 0; n < aSelBoxes.Count(); ++n ) { SwNodeIndex aIdx( *(*(aSelBoxes.GetData() + n ))->GetSttNd() ); SwCntntNode* pCNd = rNds.GoNextSection( &aIdx, sal_True, sal_False ); if( !pCNd ) continue; SwFrm* pFrm = pCNd->getLayoutFrm( GetShell()->GetLayout(), &GetPtPos() ); while( pFrm && !pFrm->IsCellFrm() ) pFrm = pFrm->GetUpper(); OSL_ENSURE( pFrm, "Node nicht in einer Tabelle" ); if( pFrm && pFrm->Frm().IsInside( rPt ) ) return sal_True; } return sal_False; } #if OSL_DEBUG_LEVEL > 1 // JP 05.03.98: To test the UNO-Crsr behavior here the implementation on the // visible cursor. sal_Bool SwShellTableCrsr::IsSelOvr( int eFlags ) { return SwShellCrsr::IsSelOvr( eFlags ); } #endif sal_Bool SwShellTableCrsr::IsAtValidPos( sal_Bool bPoint ) const { return SwShellCrsr::IsAtValidPos( bPoint ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */