xref: /trunk/main/sw/source/core/text/blink.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 #include <tools/debug.hxx>
33 #include "viewsh.hxx"
34 #include "rootfrm.hxx"  // GetOleShell()
35 #include "txtfrm.hxx"   // FindRootFrm()
36 #include "blink.hxx"
37 #include "porlin.hxx"
38 #include "porlay.hxx"   // SwLineLayout
39 
40 // Sichtbare Zeit:
41 #define BLINK_ON_TIME       2400L
42 // Nihct sichtbare Zeit:
43 #define BLINK_OFF_TIME      800L
44 
45 /*************************************************************************
46  * pBlink zeigt auf die Instanz, bei der sich blinkende Portions anmelden
47  * muessen, ggf. muss pBlink erst per new SwBlink angelegt werden.
48  * Diese werden dann rhythmisch zum Repaint angeregt und koennen abfragen,
49  * ob sie zur Zeit sichtbar oder unsichtbar sein sollen ( IsVisible() ).
50  *************************************************************************/
51 SwBlink *pBlink = NULL;
52 
53 
54 // Liste von blinkenden Portions
55 SV_IMPL_OP_PTRARR_SORT( SwBlinkList, SwBlinkPortionPtr )
56 
57 SwBlink::SwBlink()
58 {
59     bVisible = sal_True;
60     // Den Timer vorbereiten
61     aTimer.SetTimeout( BLINK_ON_TIME );
62     aTimer.SetTimeoutHdl( LINK(this, SwBlink, Blinker) );
63 }
64 
65 SwBlink::~SwBlink( )
66 {
67     aTimer.Stop();
68 }
69 
70 /*************************************************************************
71  * SwBlink::Blinker (Timerablauf):
72  * Sichtbar/unsichtbar-Flag toggeln.
73  * Repaint-Rechtecke der Blinkportions ermitteln und an ihren OleShells
74  * invalidieren.
75  *************************************************************************/
76 
77 IMPL_LINK( SwBlink, Blinker, Timer *, EMPTYARG )
78 {
79     bVisible = !bVisible;
80     if( bVisible )
81         aTimer.SetTimeout( BLINK_ON_TIME );
82     else
83         aTimer.SetTimeout( BLINK_OFF_TIME );
84     if( aList.Count() )
85     {
86 
87         for( MSHORT nPos = 0; nPos < aList.Count(); )
88         {
89             const SwBlinkPortion* pTmp = aList[ nPos ];
90             if( pTmp->GetRootFrm() &&
91                 ((SwRootFrm*)pTmp->GetRootFrm())->GetCurrShell() )
92             {
93                 ++nPos;
94 
95                 Point aPos = pTmp->GetPos();
96                 long nWidth, nHeight;
97                 switch ( pTmp->GetDirection() )
98                 {
99                     case 900:
100                         aPos.X() -= pTmp->GetPortion()->GetAscent();
101                         aPos.Y() -= pTmp->GetPortion()->Width();
102                         nWidth = pTmp->GetPortion()->SvLSize().Height();
103                         nHeight = pTmp->GetPortion()->SvLSize().Width();
104                         break;
105                     case 1800:
106                         aPos.Y() -= pTmp->GetPortion()->Height() -
107                                     pTmp->GetPortion()->GetAscent();
108                         aPos.X() -= pTmp->GetPortion()->Width();
109                         nWidth = pTmp->GetPortion()->SvLSize().Width();
110                         nHeight = pTmp->GetPortion()->SvLSize().Height();
111                         break;
112                     case 2700:
113                         aPos.X() -= pTmp->GetPortion()->Height() -
114                                     pTmp->GetPortion()->GetAscent();
115                         nWidth = pTmp->GetPortion()->SvLSize().Height();
116                         nHeight = pTmp->GetPortion()->SvLSize().Width();
117                         break;
118                     default:
119                         aPos.Y() -= pTmp->GetPortion()->GetAscent();
120                         nWidth = pTmp->GetPortion()->SvLSize().Width();
121                         nHeight = pTmp->GetPortion()->SvLSize().Height();
122                 }
123 
124                 Rectangle aRefresh( aPos, Size( nWidth, nHeight ) );
125                 aRefresh.Right() += ( aRefresh.Bottom()- aRefresh.Top() ) / 8;
126                 ((SwRootFrm*)pTmp->GetRootFrm())
127                     ->GetCurrShell()->InvalidateWindows( aRefresh );
128             }
129             else // Portions ohne Shell koennen aus der Liste entfernt werden.
130                 aList.Remove( nPos );
131         }
132     }
133     else // Wenn die Liste leer ist, kann der Timer gestoppt werden.
134         aTimer.Stop();
135     return sal_True;
136 }
137 
138 void SwBlink::Insert( const Point& rPoint, const SwLinePortion* pPor,
139                       const SwTxtFrm *pTxtFrm, sal_uInt16 nDir )
140 {
141     SwBlinkPortion *pBlinkPor = new SwBlinkPortion( pPor, nDir );
142 
143     MSHORT nPos;
144     if( aList.Seek_Entry( pBlinkPor, &nPos ) )
145     {
146         aList[ nPos ]->SetPos( rPoint );
147         delete pBlinkPor;
148     }
149     else
150     {
151         pBlinkPor->SetPos( rPoint );
152         pBlinkPor->SetRootFrm( pTxtFrm->getRootFrm() );
153         aList.Insert( pBlinkPor );
154         pTxtFrm->SetBlinkPor();
155         if( pPor->IsLayPortion() || pPor->IsParaPortion() )
156             ((SwLineLayout*)pPor)->SetBlinking( sal_True );
157 
158         if( !aTimer.IsActive() )
159             aTimer.Start();
160     }
161 }
162 
163 void SwBlink::Replace( const SwLinePortion* pOld, const SwLinePortion* pNew )
164 {
165     // setting direction to 0 because direction does not matter
166     // for this operation
167     SwBlinkPortion aBlink( pOld, 0 );
168     MSHORT nPos;
169     if( aList.Seek_Entry( &aBlink, &nPos ) )
170     {
171         SwBlinkPortion* pTmp = new SwBlinkPortion( aList[ nPos ], pNew );
172         aList.Remove( nPos );
173         aList.Insert( pTmp );
174     }
175 }
176 
177 void SwBlink::Delete( const SwLinePortion* pPor )
178 {
179     // setting direction to 0 because direction does not matter
180     // for this operation
181     SwBlinkPortion aBlink( pPor, 0 );
182     MSHORT nPos;
183     if( aList.Seek_Entry( &aBlink, &nPos ) )
184         aList.Remove( nPos );
185 }
186 
187 void SwBlink::FrmDelete( const SwRootFrm* pRoot )
188 {
189     for( MSHORT nPos = 0; nPos < aList.Count(); )
190     {
191         if( pRoot == aList[ nPos ]->GetRootFrm() )
192             aList.Remove( nPos );
193         else
194             ++nPos;
195     }
196 }
197 
198 
199