Update ooo320-m1
[ooovba.git] / sw / source / core / text / blink.cxx
blobf06345c2e29642351a8559b1e63b081b753b6216
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: blink.cxx,v $
10 * $Revision: 1.9 $
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 #include <tools/debug.hxx>
36 #include "viewsh.hxx"
37 #include "rootfrm.hxx" // GetOleShell()
38 #include "txtfrm.hxx" // FindRootFrm()
39 #include "blink.hxx"
40 #include "porlin.hxx"
41 #include "porlay.hxx" // SwLineLayout
43 // Sichtbare Zeit:
44 #define BLINK_ON_TIME 2400L
45 // Nihct sichtbare Zeit:
46 #define BLINK_OFF_TIME 800L
48 /*************************************************************************
49 * pBlink zeigt auf die Instanz, bei der sich blinkende Portions anmelden
50 * muessen, ggf. muss pBlink erst per new SwBlink angelegt werden.
51 * Diese werden dann rhythmisch zum Repaint angeregt und koennen abfragen,
52 * ob sie zur Zeit sichtbar oder unsichtbar sein sollen ( IsVisible() ).
53 *************************************************************************/
54 SwBlink *pBlink = NULL;
57 // Liste von blinkenden Portions
58 SV_IMPL_OP_PTRARR_SORT( SwBlinkList, SwBlinkPortionPtr )
60 SwBlink::SwBlink()
62 bVisible = sal_True;
63 // Den Timer vorbereiten
64 aTimer.SetTimeout( BLINK_ON_TIME );
65 aTimer.SetTimeoutHdl( LINK(this, SwBlink, Blinker) );
68 SwBlink::~SwBlink( )
70 aTimer.Stop();
73 /*************************************************************************
74 * SwBlink::Blinker (Timerablauf):
75 * Sichtbar/unsichtbar-Flag toggeln.
76 * Repaint-Rechtecke der Blinkportions ermitteln und an ihren OleShells
77 * invalidieren.
78 *************************************************************************/
80 IMPL_LINK( SwBlink, Blinker, Timer *, EMPTYARG )
82 bVisible = !bVisible;
83 if( bVisible )
84 aTimer.SetTimeout( BLINK_ON_TIME );
85 else
86 aTimer.SetTimeout( BLINK_OFF_TIME );
87 if( aList.Count() )
90 for( MSHORT nPos = 0; nPos < aList.Count(); )
92 const SwBlinkPortion* pTmp = aList[ nPos ];
93 if( pTmp->GetRootFrm() &&
94 ((SwRootFrm*)pTmp->GetRootFrm())->GetCurrShell() )
96 ++nPos;
98 Point aPos = pTmp->GetPos();
99 long nWidth, nHeight;
100 switch ( pTmp->GetDirection() )
102 case 900:
103 aPos.X() -= pTmp->GetPortion()->GetAscent();
104 aPos.Y() -= pTmp->GetPortion()->Width();
105 nWidth = pTmp->GetPortion()->SvLSize().Height();
106 nHeight = pTmp->GetPortion()->SvLSize().Width();
107 break;
108 case 1800:
109 aPos.Y() -= pTmp->GetPortion()->Height() -
110 pTmp->GetPortion()->GetAscent();
111 aPos.X() -= pTmp->GetPortion()->Width();
112 nWidth = pTmp->GetPortion()->SvLSize().Width();
113 nHeight = pTmp->GetPortion()->SvLSize().Height();
114 break;
115 case 2700:
116 aPos.X() -= pTmp->GetPortion()->Height() -
117 pTmp->GetPortion()->GetAscent();
118 nWidth = pTmp->GetPortion()->SvLSize().Height();
119 nHeight = pTmp->GetPortion()->SvLSize().Width();
120 break;
121 default:
122 aPos.Y() -= pTmp->GetPortion()->GetAscent();
123 nWidth = pTmp->GetPortion()->SvLSize().Width();
124 nHeight = pTmp->GetPortion()->SvLSize().Height();
127 Rectangle aRefresh( aPos, Size( nWidth, nHeight ) );
128 aRefresh.Right() += ( aRefresh.Bottom()- aRefresh.Top() ) / 8;
129 ((SwRootFrm*)pTmp->GetRootFrm())
130 ->GetCurrShell()->InvalidateWindows( aRefresh );
132 else // Portions ohne Shell koennen aus der Liste entfernt werden.
133 aList.Remove( nPos );
136 else // Wenn die Liste leer ist, kann der Timer gestoppt werden.
137 aTimer.Stop();
138 return sal_True;
141 void SwBlink::Insert( const Point& rPoint, const SwLinePortion* pPor,
142 const SwTxtFrm *pTxtFrm, USHORT nDir )
144 SwBlinkPortion *pBlinkPor = new SwBlinkPortion( pPor, nDir );
146 MSHORT nPos;
147 if( aList.Seek_Entry( pBlinkPor, &nPos ) )
149 aList[ nPos ]->SetPos( rPoint );
150 delete pBlinkPor;
152 else
154 pBlinkPor->SetPos( rPoint );
155 pBlinkPor->SetRootFrm( pTxtFrm->FindRootFrm() );
156 aList.Insert( pBlinkPor );
157 pTxtFrm->SetBlinkPor();
158 if( pPor->IsLayPortion() || pPor->IsParaPortion() )
159 ((SwLineLayout*)pPor)->SetBlinking( sal_True );
161 if( !aTimer.IsActive() )
162 aTimer.Start();
166 void SwBlink::Replace( const SwLinePortion* pOld, const SwLinePortion* pNew )
168 // setting direction to 0 because direction does not matter
169 // for this operation
170 SwBlinkPortion aBlink( pOld, 0 );
171 MSHORT nPos;
172 if( aList.Seek_Entry( &aBlink, &nPos ) )
174 SwBlinkPortion* pTmp = new SwBlinkPortion( aList[ nPos ], pNew );
175 aList.Remove( nPos );
176 aList.Insert( pTmp );
180 void SwBlink::Delete( const SwLinePortion* pPor )
182 // setting direction to 0 because direction does not matter
183 // for this operation
184 SwBlinkPortion aBlink( pPor, 0 );
185 MSHORT nPos;
186 if( aList.Seek_Entry( &aBlink, &nPos ) )
187 aList.Remove( nPos );
190 void SwBlink::FrmDelete( const SwRootFrm* pRoot )
192 for( MSHORT nPos = 0; nPos < aList.Count(); )
194 if( pRoot == aList[ nPos ]->GetRootFrm() )
195 aList.Remove( nPos );
196 else
197 ++nPos;