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: blink.cxx,v $
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>
37 #include "rootfrm.hxx" // GetOleShell()
38 #include "txtfrm.hxx" // FindRootFrm()
41 #include "porlay.hxx" // SwLineLayout
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
)
63 // Den Timer vorbereiten
64 aTimer
.SetTimeout( BLINK_ON_TIME
);
65 aTimer
.SetTimeoutHdl( LINK(this, SwBlink
, Blinker
) );
73 /*************************************************************************
74 * SwBlink::Blinker (Timerablauf):
75 * Sichtbar/unsichtbar-Flag toggeln.
76 * Repaint-Rechtecke der Blinkportions ermitteln und an ihren OleShells
78 *************************************************************************/
80 IMPL_LINK( SwBlink
, Blinker
, Timer
*, EMPTYARG
)
84 aTimer
.SetTimeout( BLINK_ON_TIME
);
86 aTimer
.SetTimeout( BLINK_OFF_TIME
);
90 for( MSHORT nPos
= 0; nPos
< aList
.Count(); )
92 const SwBlinkPortion
* pTmp
= aList
[ nPos
];
93 if( pTmp
->GetRootFrm() &&
94 ((SwRootFrm
*)pTmp
->GetRootFrm())->GetCurrShell() )
98 Point aPos
= pTmp
->GetPos();
100 switch ( pTmp
->GetDirection() )
103 aPos
.X() -= pTmp
->GetPortion()->GetAscent();
104 aPos
.Y() -= pTmp
->GetPortion()->Width();
105 nWidth
= pTmp
->GetPortion()->SvLSize().Height();
106 nHeight
= pTmp
->GetPortion()->SvLSize().Width();
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();
116 aPos
.X() -= pTmp
->GetPortion()->Height() -
117 pTmp
->GetPortion()->GetAscent();
118 nWidth
= pTmp
->GetPortion()->SvLSize().Height();
119 nHeight
= pTmp
->GetPortion()->SvLSize().Width();
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.
141 void SwBlink::Insert( const Point
& rPoint
, const SwLinePortion
* pPor
,
142 const SwTxtFrm
*pTxtFrm
, USHORT nDir
)
144 SwBlinkPortion
*pBlinkPor
= new SwBlinkPortion( pPor
, nDir
);
147 if( aList
.Seek_Entry( pBlinkPor
, &nPos
) )
149 aList
[ nPos
]->SetPos( rPoint
);
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() )
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 );
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 );
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
);