Update ooo320-m1
[ooovba.git] / sw / source / core / crsr / viscrs.cxx
blob8f31456292b5795a687e5282c1434e15051b0569
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viscrs.cxx,v $
10 * $Revision: 1.31 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #ifndef _SVSTDARR_HXX
36 #define _SVSTDARR_USHORTS
37 #include <svtools/svstdarr.hxx>
38 #endif
40 #include <vcl/dialog.hxx>
41 #include <vcl/msgbox.hxx>
42 #include <vcl/wrkwin.hxx>
43 #include <viewopt.hxx>
44 #include <frmtool.hxx>
45 #include <viscrs.hxx>
46 #include <crsrsh.hxx>
47 #include <doc.hxx>
48 #include <swtable.hxx>
49 #include <viewimp.hxx>
50 #include <dview.hxx>
51 #include <rootfrm.hxx>
52 #include <txtfrm.hxx> // SwTxtFrm
53 #include <docary.hxx>
54 #include <extinput.hxx>
55 #include <ndtxt.hxx>
56 #include <scriptinfo.hxx>
57 #include <mdiexp.hxx> // GetSearchDialog
58 #ifndef _COMCORE_HRC
59 #include <comcore.hrc> // ResId fuer Abfrage wenn zu Search & Replaces
60 #endif
62 #include <svx/sdr/overlay/overlaymanager.hxx>
63 #include <svx/sdrpaintwindow.hxx>
64 #include <vcl/svapp.hxx>
65 #include <svx/sdr/overlay/overlayselection.hxx>
67 extern void SwCalcPixStatics( OutputDevice *pOut );
69 //Damit beim ShowCrsr nicht immer wieder die gleiche Size teuer ermittelt
70 //werden muss, hier statische Member, die beim Wechsel des MapModes
71 // angepasst werden
73 long SwSelPaintRects::nPixPtX = 0;
74 long SwSelPaintRects::nPixPtY = 0;
75 MapMode* SwSelPaintRects::pMapMode = 0;
78 #ifdef SHOW_BOOKMARKS
79 // #include <IMark.hxx>
80 //
81 // class SwBookmarkRects : public SwSelPaintRects
82 // {
83 // virtual void Paint( const Rectangle& rRect );
84 // virtual void FillRects();
85 //
86 // public:
87 // SwBookmarkRects( const SwCrsrShell& rSh ) : SwSelPaintRects( rSh ) {}
88 // };
89 //
90 // void SwBookmarkRects::Paint( const Rectangle& rRect )
91 // {
92 // Window* pWin = GetShell()->GetWin();
93 //
94 // RasterOp eOld( pWin->GetRasterOp() );
95 // BOOL bLCol = pWin->IsLineColor();
96 // Color aLCol( pWin->GetLineColor() );
97 // BOOL bFCol = pWin->IsFillColor();
98 // Color aFCol( pWin->GetFillColor() );
99 //
100 // pWin->SetRasterOp( ROP_XOR );
101 // Color aCol( RGB_COLORDATA( 0xF0, 0xC8, 0xF0 ) ^ COL_WHITE );
102 // pWin->SetFillColor( aCol );
103 // pWin->SetLineColor( aCol );
105 // pWin->DrawRect( rRect );
107 // if( bLCol ) pWin->SetLineColor( aLCol ); else pWin->SetLineColor();
108 // if( bFCol ) pWin->SetFillColor( aFCol ); else pWin->SetFillColor();
109 // pWin->SetRasterOp( eOld );
110 // }
112 // void SwBookmarkRects::FillRects()
113 // {
114 // SwRegionRects aReg( GetShell()->VisArea() );
116 // const SwBookmarks& rBkmkTbl = GetShell()->getIDocumentMarkAccess()->getBookmarks();
117 // SwShellCrsr* pCrsr = 0;
118 // for( USHORT n = 0; n < rBkmkTbl.Count(); ++n )
119 // {
120 // const SwBookmark& rBkmk = *rBkmkTbl[ n ];
121 // if( rBkmk.IsBookMark() && rBkmk.GetOtherPos() )
122 // {
123 // if( !pCrsr )
124 // {
125 // pCrsr = new SwShellCrsr( *GetShell(), rBkmk.GetPos() );
126 // pCrsr->SetMark();
127 // }
128 // else
129 // *pCrsr->GetPoint() = rBkmk.GetPos();
130 // *pCrsr->GetMark() = *rBkmk.GetOtherPos();
131 // pCrsr->FillRects();
132 // for( USHORT i = 0; i < pCrsr->Count(); ++i )
133 // aReg -= (*pCrsr)[ i ];
135 // pCrsr->Remove( 0, i );
136 // }
137 // }
138 // if( pCrsr ) delete pCrsr;
140 // aReg.Invert();
141 // SwRects::Insert( &aReg, 0 );
142 // }
144 // SwBookmarkRects* pBookMarkRects = 0;
146 // void ShowBookmarks( const SwCrsrShell* pSh, int nAction, const SwRect* pRect = 0 )
147 // {
148 // if( !pBookMarkRects && pSh->getIDocumentMarkAccess()->getBookmarks().Count() )
149 // pBookMarkRects = new SwBookmarkRects( *pSh );
151 // if( pBookMarkRects )
152 // {
153 // switch( nAction )
154 // {
155 // case 1: pBookMarkRects->Show(); break;
156 // case 2: pBookMarkRects->Hide(); break;
157 // case 3: pBookMarkRects->Invalidate( *pRect ); break;
158 // }
160 // if( !pBookMarkRects->Count() )
161 // delete pBookMarkRects, pBookMarkRects = 0;
162 // }
163 // }
165 // #define SHOWBOOKMARKS1( nAct ) ShowBookmarks( GetShell(),nAct );
166 // #define SHOWBOOKMARKS2( nAct, pRect ) ShowBookmarks( GetShell(),nAct, pRect );
168 #else
170 #define SHOWBOOKMARKS1( nAct )
171 #define SHOWBOOKMARKS2( nAct, pRect )
173 #endif
175 #ifdef SHOW_REDLINES
176 #include <redline.hxx>
178 class SwRedlineRects : public SwSelPaintRects
180 USHORT nMode;
181 USHORT nNm;
183 virtual void Paint( const Rectangle& rRect );
184 virtual void FillRects();
186 public:
187 SwRedlineRects( const SwCrsrShell& rSh, USHORT nName, USHORT n )
188 : SwSelPaintRects( rSh ), nMode( n ), nNm( nName )
192 void SwRedlineRects::Paint( const Rectangle& rRect )
194 Window* pWin = GetShell()->GetWin();
196 RasterOp eOld( pWin->GetRasterOp() );
197 BOOL bLCol = pWin->IsLineColor();
198 Color aLCol( pWin->GetLineColor() );
199 BOOL bFCol = pWin->IsFillColor();
200 Color aFCol( pWin->GetFillColor() );
202 pWin->SetRasterOp( ROP_XOR );
203 Color aCol;
205 UINT8 nVal = 0xc8 - ( (nMode / 4) * 16 );
206 switch( nMode % 4 )
208 case 0: aCol = RGB_COLORDATA( nVal, nVal, 0xFF ); break;
209 case 1: aCol = RGB_COLORDATA( 0xFF, 0xc8, nVal ); break;
210 case 2: aCol = RGB_COLORDATA( nVal, 0xFF, nVal ); break;
211 case 3: aCol = RGB_COLORDATA( 0xFF, nVal, nVal ); break;
213 aCol = aCol.GetColor() ^ COL_WHITE;
215 pWin->SetFillColor( aCol );
216 pWin->SetLineColor( aCol );
218 pWin->DrawRect( rRect );
220 if( bLCol ) pWin->SetLineColor( aLCol ); else pWin->SetLineColor();
221 if( bFCol ) pWin->SetFillColor( aFCol ); else pWin->SetFillColor();
222 pWin->SetRasterOp( eOld );
225 void SwRedlineRects::FillRects()
227 SwRegionRects aReg( GetShell()->VisArea() );
229 const SwRedlineTbl& rTbl = GetShell()->GetDoc()->GetRedlineTbl();
230 SwShellCrsr* pCrsr = 0;
231 for( USHORT n = 0; n < rTbl.Count(); ++n )
233 const SwRedline& rRed = *rTbl[ n ];
234 if( rRed.HasMark() && (nMode % 4 ) == rRed.GetType() &&
235 nNm == rRed.GetAuthor() )
237 if( !pCrsr )
239 pCrsr = new SwShellCrsr( *GetShell(), *rRed.GetPoint() );
240 pCrsr->SetMark();
242 else
243 *pCrsr->GetPoint() = *rRed.GetPoint();
244 *pCrsr->GetMark() = *rRed.GetMark();
245 pCrsr->FillRects();
246 for( USHORT i = 0; i < pCrsr->Count(); ++i )
247 aReg -= (*pCrsr)[ i ];
249 pCrsr->Remove( 0, i );
252 if( pCrsr ) delete pCrsr;
254 aReg.Invert();
255 SwRects::Insert( &aReg, 0 );
258 SwRedlineRects* aRedlines[ 10 * 4 ];
259 static int bFirstCall = TRUE;
261 void ShowRedlines( const SwCrsrShell* pSh, int nAction, const SwRect* pRect = 0 )
263 if( bFirstCall )
265 memset( aRedlines, 0, sizeof(aRedlines));
266 bFirstCall = FALSE;
269 const SwRedlineTbl& rTbl = pSh->GetDoc()->GetRedlineTbl();
270 const SwRedlineAuthorTbl& rAuthorTbl = pSh->GetDoc()->GetRedlineAuthorTbl();
272 for( USHORT n = 0; n < rAuthorTbl.Count(); ++n )
274 for( int i = 0; i < 4; ++i )
276 SwRedlineRects** ppRedRect = &aRedlines[ n * 4 + i ];
277 if( rTbl.Count() && !*ppRedRect )
278 *ppRedRect = new SwRedlineRects( *pSh, n, n * 4 + i );
280 if( *ppRedRect )
282 switch( nAction )
284 case 1: (*ppRedRect)->Show(); break;
285 case 2: (*ppRedRect)->Hide(); break;
286 case 3: (*ppRedRect)->Invalidate( *pRect ); break;
289 if( !(*ppRedRect)->Count() )
290 delete *ppRedRect, *ppRedRect = 0;
296 #define SHOWREDLINES1( nAct ) ShowRedlines( GetShell(),nAct );
297 #define SHOWREDLINES2( nAct, pRect ) ShowRedlines( GetShell(),nAct, pRect );
299 #else
301 #define SHOWREDLINES1( nAct )
302 #define SHOWREDLINES2( nAct, pRect )
304 #endif
306 #ifdef JP_REDLINE
307 if( GetDoc()->GetRedlineTbl().Count() )
309 SwRedlineTbl& rRedlineTbl = (SwRedlineTbl&)GetDoc()->GetRedlineTbl();
310 for( USHORT i = 0; i < rRedlineTbl.Count(); ++i )
311 rRedlineTbl[ i ]->HideRects( *GetShell() );
313 #endif
315 // -------- Ab hier Klassen / Methoden fuer den nicht Text-Cursor ------
317 SwVisCrsr::SwVisCrsr( const SwCrsrShell * pCShell )
318 : pCrsrShell( pCShell )
320 pCShell->GetWin()->SetCursor( &aTxtCrsr );
321 bIsVisible = aTxtCrsr.IsVisible();
322 bIsDragCrsr = FALSE;
323 aTxtCrsr.SetWidth( 0 );
325 #ifdef SW_CRSR_TIMER
326 bTimerOn = TRUE;
327 SetTimeout( 50 ); // 50msec Verzoegerung
328 #endif
333 SwVisCrsr::~SwVisCrsr()
335 #ifdef SW_CRSR_TIMER
336 if( bTimerOn )
337 Stop(); // Timer stoppen
338 #endif
340 if( bIsVisible && aTxtCrsr.IsVisible() )
341 aTxtCrsr.Hide();
343 pCrsrShell->GetWin()->SetCursor( 0 );
349 void SwVisCrsr::Show()
351 if( !bIsVisible )
353 bIsVisible = TRUE;
355 // muss ueberhaupt angezeigt werden ?
356 if( pCrsrShell->VisArea().IsOver( pCrsrShell->aCharRect ) )
357 #ifdef SW_CRSR_TIMER
359 if( bTimerOn )
360 Start(); // Timer aufsetzen
361 else
363 if( IsActive() )
364 Stop(); // Timer Stoppen
366 _SetPosAndShow();
369 #else
370 _SetPosAndShow();
371 #endif
377 void SwVisCrsr::Hide()
379 if( bIsVisible )
381 bIsVisible = FALSE;
383 #ifdef SW_CRSR_TIMER
384 if( IsActive() )
385 Stop(); // Timer Stoppen
386 #endif
388 if( aTxtCrsr.IsVisible() ) // sollten die Flags nicht gueltig sein?
389 aTxtCrsr.Hide();
393 #ifdef SW_CRSR_TIMER
395 void __EXPORT SwVisCrsr::Timeout()
397 ASSERT( !bIsDragCrsr, "Timer vorher abschalten" );
398 if( bIsVisible )
400 if ( !pCrsrShell->GetWin() ) //SwFrmFmt::GetGraphic setzt das Win temp aus!
401 Start();
402 else
403 _SetPosAndShow();
407 BOOL SwCrsrShell::ChgCrsrTimerFlag( BOOL bTimerOn )
409 return pVisCrsr->ChgTimerFlag( bTimerOn );
413 BOOL SwVisCrsr::ChgTimerFlag( BOOL bFlag )
415 bOld = bTimerOn;
416 if( !bFlag && bIsVisible && IsActive() )
418 Stop(); // Timer Stoppen
419 _SetPosAndShow();
421 bTimerOn = bFlag;
422 return bOld;
425 #endif
428 void SwVisCrsr::_SetPosAndShow()
430 SwRect aRect;
431 long nTmpY = pCrsrShell->aCrsrHeight.Y();
432 if( 0 > nTmpY )
434 nTmpY = -nTmpY;
435 aTxtCrsr.SetOrientation( 900 );
436 aRect = SwRect( pCrsrShell->aCharRect.Pos(),
437 Size( pCrsrShell->aCharRect.Height(), nTmpY ) );
438 aRect.Pos().X() += pCrsrShell->aCrsrHeight.X();
439 if( pCrsrShell->IsOverwriteCrsr() )
440 aRect.Pos().Y() += aRect.Width();
442 else
444 aTxtCrsr.SetOrientation( 0 );
445 aRect = SwRect( pCrsrShell->aCharRect.Pos(),
446 Size( pCrsrShell->aCharRect.Width(), nTmpY ) );
447 aRect.Pos().Y() += pCrsrShell->aCrsrHeight.X();
450 // check if cursor should show the current cursor bidi level
451 aTxtCrsr.SetDirection( CURSOR_DIRECTION_NONE );
452 const SwCursor* pTmpCrsr = pCrsrShell->_GetCrsr();
454 if ( pTmpCrsr && !pCrsrShell->IsOverwriteCrsr() )
456 SwNode& rNode = pTmpCrsr->GetPoint()->nNode.GetNode();
457 if( rNode.IsTxtNode() )
459 const SwTxtNode& rTNd = *rNode.GetTxtNode();
460 const SwFrm* pFrm = rTNd.GetFrm( 0, 0, FALSE );
461 if ( pFrm )
463 const SwScriptInfo* pSI = ((SwTxtFrm*)pFrm)->GetScriptInfo();
464 // cursor level has to be shown
465 if ( pSI && pSI->CountDirChg() > 1 )
467 aTxtCrsr.SetDirection(
468 ( pTmpCrsr->GetCrsrBidiLevel() % 2 ) ?
469 CURSOR_DIRECTION_RTL :
470 CURSOR_DIRECTION_LTR );
473 if ( pFrm->IsRightToLeft() )
475 const OutputDevice *pOut = pCrsrShell->GetOut();
476 if ( pOut )
478 long nSize = pOut->GetSettings().GetStyleSettings().GetCursorSize();
479 Size aSize( nSize, nSize );
480 aSize = pOut->PixelToLogic( aSize );
481 aRect.Left( aRect.Left() - aSize.Width() );
488 if( aRect.Height() )
490 ::SwCalcPixStatics( pCrsrShell->GetOut() );
491 ::SwAlignRect( aRect, (ViewShell*)pCrsrShell );
493 if( !pCrsrShell->IsOverwriteCrsr() || bIsDragCrsr ||
494 pCrsrShell->IsSelection() )
495 aRect.Width( 0 );
497 aTxtCrsr.SetSize( aRect.SSize() );
499 aTxtCrsr.SetPos( aRect.Pos() );
500 if ( !pCrsrShell->IsCrsrReadonly() || pCrsrShell->GetViewOptions()->IsSelectionInReadonly() )
502 if ( pCrsrShell->GetDrawView() )
503 ((SwDrawView*)pCrsrShell->GetDrawView())->SetAnimationEnabled(
504 !pCrsrShell->IsSelection() );
506 USHORT nStyle = bIsDragCrsr ? CURSOR_SHADOW : 0;
507 if( nStyle != aTxtCrsr.GetStyle() )
509 aTxtCrsr.SetStyle( nStyle );
510 aTxtCrsr.SetWindow( bIsDragCrsr ? pCrsrShell->GetWin() : 0 );
513 aTxtCrsr.Show();
517 //////////////////////////////////////////////////////////////////////////////
519 SwSelPaintRects::SwSelPaintRects( const SwCrsrShell& rCSh )
520 : SwRects( 0 ),
521 pCShell( &rCSh ),
522 mpCursorOverlay(0)
526 SwSelPaintRects::~SwSelPaintRects()
528 Hide();
531 void SwSelPaintRects::swapContent(SwSelPaintRects& rSwap)
533 SwRects aTempRects;
534 aTempRects.Insert(this, 0);
536 Remove(0, Count());
537 Insert(&rSwap, 0);
539 rSwap.Remove(0, rSwap.Count());
540 rSwap.Insert(&aTempRects, 0);
542 // #i75172# also swap mpCursorOverlay
543 sdr::overlay::OverlayObject* pTempOverlay = getCursorOverlay();
544 setCursorOverlay(rSwap.getCursorOverlay());
545 rSwap.setCursorOverlay(pTempOverlay);
548 void SwSelPaintRects::Hide()
550 if(mpCursorOverlay)
552 delete mpCursorOverlay;
553 mpCursorOverlay = 0;
556 SwRects::Remove( 0, Count() );
559 void SwSelPaintRects::Show()
561 SdrView* pView = (SdrView*)pCShell->GetDrawView();
563 if(pView && pView->PaintWindowCount())
565 // reset rects
566 SwRects::Remove( 0, SwRects::Count() );
567 FillRects();
569 // get new rects
570 std::vector< basegfx::B2DRange > aNewRanges;
572 for(sal_uInt16 a(0); a < Count(); a++)
574 const SwRect aNextRect((*this)[a]);
575 const Rectangle aPntRect(aNextRect.SVRect());
577 aNewRanges.push_back(basegfx::B2DRange(
578 aPntRect.Left(), aPntRect.Top(),
579 aPntRect.Right() + 1, aPntRect.Bottom() + 1));
582 if(mpCursorOverlay)
584 if(aNewRanges.size())
586 static_cast< sdr::overlay::OverlaySelection* >(mpCursorOverlay)->setRanges(aNewRanges);
588 else
590 delete mpCursorOverlay;
591 mpCursorOverlay = 0;
594 else if(Count())
596 SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
597 sdr::overlay::OverlayManager* pTargetOverlay = pCandidate->GetOverlayManager();
599 if(pTargetOverlay)
601 // #i97672# get the system's hilight color and limit it to the maximum
602 // allowed luminance. This is needed to react on too bright hilight colors
603 // which would otherwise vive a bad visualisation
604 const OutputDevice *pOut = Application::GetDefaultDevice();
605 Color aHighlight(pOut->GetSettings().GetStyleSettings().GetHighlightColor());
606 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
607 const basegfx::BColor aSelection(aHighlight.getBColor());
608 const double fLuminance(aSelection.luminance());
609 const double fMaxLum(aSvtOptionsDrawinglayer.GetSelectionMaximumLuminancePercent() / 100.0);
611 if(fLuminance > fMaxLum)
613 const double fFactor(fMaxLum / fLuminance);
614 const basegfx::BColor aNewSelection(
615 aSelection.getRed() * fFactor,
616 aSelection.getGreen() * fFactor,
617 aSelection.getBlue() * fFactor);
619 aHighlight = Color(aNewSelection);
622 // create correct selection
623 mpCursorOverlay = new sdr::overlay::OverlaySelection(
624 sdr::overlay::OVERLAY_TRANSPARENT,
625 aHighlight,
626 aNewRanges,
627 true);
629 pTargetOverlay->add(*mpCursorOverlay);
635 void SwSelPaintRects::Invalidate( const SwRect& rRect )
637 USHORT nSz = Count();
638 if( !nSz )
639 return;
641 SwRegionRects aReg( GetShell()->VisArea() );
642 aReg.Remove( 0, aReg.Count() );
643 aReg.Insert( this, 0 );
644 aReg -= rRect;
645 SwRects::Remove( 0, nSz );
646 SwRects::Insert( &aReg, 0 );
648 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
649 // Liegt die Selection rechts oder unten ausserhalb des sichtbaren
650 // Bereiches, so ist diese nie auf eine Pixel rechts/unten aligned.
651 // Das muss hier erkannt und ggf. das Rechteckt erweitert werden.
652 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
653 if( GetShell()->bVisPortChgd && 0 != ( nSz = Count()) )
655 SwSelPaintRects::Get1PixelInLogic( *GetShell() );
656 SwRect* pRect = (SwRect*)GetData();
657 for( ; nSz--; ++pRect )
659 if( pRect->Right() == GetShell()->aOldRBPos.X() )
660 pRect->Right( pRect->Right() + nPixPtX );
661 if( pRect->Bottom() == GetShell()->aOldRBPos.Y() )
662 pRect->Bottom( pRect->Bottom() + nPixPtY );
667 void SwSelPaintRects::Paint( const Rectangle& /*rRect*/ )
669 // nothing to do with overlays
673 * Rectangle ist in Dokument-Koordianten !!
674 * pWin != 0 -> auch wirklich malen
675 * == 0 -> nur testen, ob es gemalt werden kann
678 void SwSelPaintRects::Paint( const SwRect& /*rRect*/ )
680 // nothing to do with overlays
683 // check current MapMode of the shell and set possibly the static members.
684 // Optional set the parameters pX, pY
685 void SwSelPaintRects::Get1PixelInLogic( const ViewShell& rSh,
686 long* pX, long* pY )
688 const OutputDevice* pOut = rSh.GetWin();
689 if ( ! pOut )
690 pOut = rSh.GetOut();
692 const MapMode& rMM = pOut->GetMapMode();
693 if( pMapMode->GetMapUnit() != rMM.GetMapUnit() ||
694 pMapMode->GetScaleX() != rMM.GetScaleX() ||
695 pMapMode->GetScaleY() != rMM.GetScaleY() )
697 *pMapMode = rMM;
698 Size aTmp( 1, 1 );
699 aTmp = pOut->PixelToLogic( aTmp );
700 nPixPtX = aTmp.Width();
701 nPixPtY = aTmp.Height();
703 if( pX )
704 *pX = nPixPtX;
705 if( pY )
706 *pY = nPixPtY;
710 /* \f */
712 SwShellCrsr::SwShellCrsr( const SwCrsrShell& rCShell, const SwPosition &rPos )
713 : SwCursor(rPos,0,false), SwSelPaintRects(rCShell), pPt(SwPaM::GetPoint())
717 SwShellCrsr::SwShellCrsr( const SwCrsrShell& rCShell, const SwPosition &rPos,
718 const Point& rPtPos, SwPaM* pRing )
719 : SwCursor(rPos, pRing, false), SwSelPaintRects(rCShell), aMkPt(rPtPos),
720 aPtPt(rPtPos), pPt(SwPaM::GetPoint())
724 SwShellCrsr::SwShellCrsr( SwShellCrsr& rICrsr )
725 : SwCursor(rICrsr), SwSelPaintRects(*rICrsr.GetShell()),
726 aMkPt(rICrsr.GetMkPos()), aPtPt(rICrsr.GetPtPos()), pPt(SwPaM::GetPoint())
729 SwShellCrsr::~SwShellCrsr() {}
732 bool SwShellCrsr::IsReadOnlyAvailable() const
734 return GetShell()->IsReadOnlyAvailable();
737 void SwShellCrsr::SetMark()
739 if( SwPaM::GetPoint() == pPt )
740 aMkPt = aPtPt;
741 else
742 aPtPt = aMkPt;
743 SwPaM::SetMark();
746 void SwShellCrsr::FillRects()
748 // die neuen Rechtecke berechnen
749 if( HasMark() &&
750 GetPoint()->nNode.GetNode().IsCntntNode() &&
751 GetPoint()->nNode.GetNode().GetCntntNode()->GetFrm() &&
752 (GetMark()->nNode == GetPoint()->nNode ||
753 (GetMark()->nNode.GetNode().IsCntntNode() &&
754 GetMark()->nNode.GetNode().GetCntntNode()->GetFrm() ) ))
755 GetDoc()->GetRootFrm()->CalcFrmRects( *this, GetShell()->IsTableMode() );
759 void SwShellCrsr::Show()
761 SwShellCrsr * pTmp = this;
762 do {
763 pTmp->SwSelPaintRects::Show();
764 } while( this != ( pTmp = dynamic_cast<SwShellCrsr*>(pTmp->GetNext()) ) );
766 SHOWBOOKMARKS1( 1 )
767 SHOWREDLINES1( 1 )
771 // Dieses Rechteck wird neu gepaintet, also ist die SSelection in
772 // dem Bereich ungueltig
773 void SwShellCrsr::Invalidate( const SwRect& rRect )
775 SwShellCrsr * pTmp = this;
779 pTmp->SwSelPaintRects::Invalidate( rRect );
781 // --> FME 2005-08-18 #125102#
782 // skip any non SwShellCrsr objects in the ring
783 // (see:SwAutoFormat::DeleteSel()
784 // <--
785 Ring* pTmpRing = pTmp;
786 pTmp = 0;
789 pTmpRing = pTmpRing->GetNext();
790 pTmp = dynamic_cast<SwShellCrsr*>(pTmpRing);
792 while ( !pTmp );
794 while( this != pTmp );
796 SHOWBOOKMARKS2( 3, &rRect )
797 SHOWREDLINES2( 3, &rRect )
801 void SwShellCrsr::Hide()
803 SwShellCrsr * pTmp = this;
804 do {
805 pTmp->SwSelPaintRects::Hide();
806 } while( this != ( pTmp = dynamic_cast<SwShellCrsr*>(pTmp->GetNext()) ) );
808 SHOWBOOKMARKS1( 2 )
809 SHOWREDLINES1( 2 )
812 SwCursor* SwShellCrsr::Create( SwPaM* pRing ) const
814 return new SwShellCrsr( *GetShell(), *GetPoint(), GetPtPos(), pRing );
818 short SwShellCrsr::MaxReplaceArived()
820 short nRet = RET_YES;
821 Window* pDlg = LAYOUT_THIS_WINDOW (::GetSearchDialog());
822 if( pDlg )
824 // alte Actions beenden; die Tabellen-Frames werden angelegt und
825 // eine SSelection kann erzeugt werden
826 SvUShorts aArr;
827 USHORT nActCnt;
828 ViewShell *pShell = GetDoc()->GetRootFrm()->GetCurrShell(),
829 *pSh = pShell;
830 do {
831 for( nActCnt = 0; pSh->ActionPend(); ++nActCnt )
832 pSh->EndAction();
833 aArr.Insert( nActCnt, aArr.Count() );
834 } while( pShell != ( pSh = (ViewShell*)pSh->GetNext() ) );
837 nRet = QueryBox( pDlg, SW_RES( MSG_COMCORE_ASKSEARCH )).Execute();
840 for( USHORT n = 0; n < aArr.Count(); ++n )
842 for( nActCnt = aArr[n]; nActCnt--; )
843 pSh->StartAction();
844 pSh = (ViewShell*)pSh->GetNext();
847 else
848 // ansonsten aus dem Basic, und dann auf RET_YES schalten
849 nRet = RET_YES;
851 return nRet;
854 void SwShellCrsr::SaveTblBoxCntnt( const SwPosition* pPos )
856 ((SwCrsrShell*)GetShell())->SaveTblBoxCntnt( pPos );
859 BOOL SwShellCrsr::UpDown( BOOL bUp, USHORT nCnt )
861 return SwCursor::UpDown( bUp, nCnt,
862 &GetPtPos(), GetShell()->GetUpDownX() );
865 #ifndef PRODUCT
867 // JP 05.03.98: zum Testen des UNO-Crsr Verhaltens hier die Implementierung
868 // am sichtbaren Cursor
870 BOOL SwShellCrsr::IsSelOvr( int eFlags )
872 return SwCursor::IsSelOvr( eFlags );
875 #endif
877 // TRUE: an die Position kann der Cursor gesetzt werden
878 BOOL SwShellCrsr::IsAtValidPos( BOOL bPoint ) const
880 if( GetShell() && ( GetShell()->IsAllProtect() ||
881 GetShell()->GetViewOptions()->IsReadonly() ||
882 ( GetShell()->Imp()->GetDrawView() &&
883 GetShell()->Imp()->GetDrawView()->GetMarkedObjectList().GetMarkCount() )))
884 return TRUE;
886 return SwCursor::IsAtValidPos( bPoint );
889 /* \f */
891 SwShellTableCrsr::SwShellTableCrsr( const SwCrsrShell& rCrsrSh,
892 const SwPosition& rPos )
893 : SwCursor(rPos,0,false), SwShellCrsr(rCrsrSh, rPos), SwTableCursor(rPos)
897 SwShellTableCrsr::SwShellTableCrsr( const SwCrsrShell& rCrsrSh,
898 const SwPosition& rMkPos, const Point& rMkPt,
899 const SwPosition& rPtPos, const Point& rPtPt )
900 : SwCursor(rPtPos,0,false), SwShellCrsr(rCrsrSh, rPtPos), SwTableCursor(rPtPos)
902 SetMark();
903 *GetMark() = rMkPos;
904 GetMkPos() = rMkPt;
905 GetPtPos() = rPtPt;
908 SwShellTableCrsr::~SwShellTableCrsr() {}
910 void SwShellTableCrsr::SetMark() { SwShellCrsr::SetMark(); }
912 SwCursor* SwShellTableCrsr::Create( SwPaM* pRing ) const
914 return SwShellCrsr::Create( pRing );
916 short SwShellTableCrsr::MaxReplaceArived()
918 return SwShellCrsr::MaxReplaceArived();
920 void SwShellTableCrsr::SaveTblBoxCntnt( const SwPosition* pPos )
922 SwShellCrsr::SaveTblBoxCntnt( pPos );
926 void SwShellTableCrsr::FillRects()
928 // die neuen Rechtecke berechnen
929 // JP 16.01.98: wenn der Cursor noch "geparkt" ist nichts machen!!
930 if( !aSelBoxes.Count() || bParked ||
931 !GetPoint()->nNode.GetIndex() )
932 return;
934 SwRegionRects aReg( GetShell()->VisArea() );
935 SwNodes& rNds = GetDoc()->GetNodes();
936 for( USHORT n = 0; n < aSelBoxes.Count(); ++n )
938 const SwStartNode* pSttNd = (*(aSelBoxes.GetData() + n ))->GetSttNd();
939 const SwTableNode* pSelTblNd = pSttNd->FindTableNode();
941 SwNodeIndex aIdx( *pSttNd );
942 SwCntntNode* pCNd = rNds.GoNextSection( &aIdx, TRUE, FALSE );
944 // TABLE IN TABLE
945 // (see also lcl_FindTopLevelTable in unoobj2.cxx for a different
946 // version to do this)
947 const SwTableNode* pCurTblNd = pCNd->FindTableNode();
948 while ( pSelTblNd != pCurTblNd && pCurTblNd )
950 aIdx = pCurTblNd->EndOfSectionIndex();
951 pCNd = rNds.GoNextSection( &aIdx, TRUE, FALSE );
952 pCurTblNd = pCNd->FindTableNode();
955 if( !pCNd )
956 continue;
958 SwFrm* pFrm = pCNd->GetFrm( &GetSttPos() );
959 while( pFrm && !pFrm->IsCellFrm() )
960 pFrm = pFrm->GetUpper();
962 ASSERT( pFrm, "Node nicht in einer Tabelle" );
964 while ( pFrm )
966 if( pFrm && aReg.GetOrigin().IsOver( pFrm->Frm() ) )
967 aReg -= pFrm->Frm();
969 pFrm = pFrm->GetNextCellLeaf( MAKEPAGE_NONE );
972 aReg.Invert();
973 Insert( &aReg, 0 );
977 // Pruefe, ob sich der SPoint innerhalb der Tabellen-SSelection befindet
978 BOOL SwShellTableCrsr::IsInside( const Point& rPt ) const
980 // die neuen Rechtecke berechnen
981 // JP 16.01.98: wenn der Cursor noch "geparkt" ist nichts machen!!
982 if( !aSelBoxes.Count() || bParked ||
983 !GetPoint()->nNode.GetIndex() )
984 return FALSE;
986 SwNodes& rNds = GetDoc()->GetNodes();
987 for( USHORT n = 0; n < aSelBoxes.Count(); ++n )
989 SwNodeIndex aIdx( *(*(aSelBoxes.GetData() + n ))->GetSttNd() );
990 SwCntntNode* pCNd = rNds.GoNextSection( &aIdx, TRUE, FALSE );
991 if( !pCNd )
992 continue;
994 SwFrm* pFrm = pCNd->GetFrm( &GetPtPos() );
995 while( pFrm && !pFrm->IsCellFrm() )
996 pFrm = pFrm->GetUpper();
997 ASSERT( pFrm, "Node nicht in einer Tabelle" );
998 if( pFrm && pFrm->Frm().IsInside( rPt ) )
999 return TRUE;
1001 return FALSE;
1004 #ifndef PRODUCT
1006 // JP 05.03.98: zum Testen des UNO-Crsr Verhaltens hier die Implementierung
1007 // am sichtbaren Cursor
1008 BOOL SwShellTableCrsr::IsSelOvr( int eFlags )
1010 return SwShellCrsr::IsSelOvr( eFlags );
1013 #endif
1015 BOOL SwShellTableCrsr::IsAtValidPos( BOOL bPoint ) const
1017 return SwShellCrsr::IsAtValidPos( bPoint );