xref: /trunk/main/sw/source/core/text/blink.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 #include <tools/debug.hxx>
29 #include "viewsh.hxx"
30 #include "rootfrm.hxx"  // GetOleShell()
31 #include "txtfrm.hxx"	// FindRootFrm()
32 #include "blink.hxx"
33 #include "porlin.hxx"
34 #include "porlay.hxx"   // SwLineLayout
35 
36 // Sichtbare Zeit:
37 #define BLINK_ON_TIME		2400L
38 // Nihct sichtbare Zeit:
39 #define BLINK_OFF_TIME		800L
40 
41 /*************************************************************************
42  * pBlink zeigt auf die Instanz, bei der sich blinkende Portions anmelden
43  * muessen, ggf. muss pBlink erst per new SwBlink angelegt werden.
44  * Diese werden dann rhythmisch zum Repaint angeregt und koennen abfragen,
45  * ob sie zur Zeit sichtbar oder unsichtbar sein sollen ( IsVisible() ).
46  *************************************************************************/
47 SwBlink *pBlink = NULL;
48 
49 
50 // Liste von blinkenden Portions
SV_IMPL_OP_PTRARR_SORT(SwBlinkList,SwBlinkPortionPtr)51 SV_IMPL_OP_PTRARR_SORT( SwBlinkList, SwBlinkPortionPtr )
52 
53 SwBlink::SwBlink()
54 {
55 	bVisible = sal_True;
56 	// Den Timer vorbereiten
57 	aTimer.SetTimeout( BLINK_ON_TIME );
58 	aTimer.SetTimeoutHdl( LINK(this, SwBlink, Blinker) );
59 }
60 
~SwBlink()61 SwBlink::~SwBlink( )
62 {
63 	aTimer.Stop();
64 }
65 
66 /*************************************************************************
67  * SwBlink::Blinker (Timerablauf):
68  * Sichtbar/unsichtbar-Flag toggeln.
69  * Repaint-Rechtecke der Blinkportions ermitteln und an ihren OleShells
70  * invalidieren.
71  *************************************************************************/
72 
IMPL_LINK(SwBlink,Blinker,Timer *,EMPTYARG)73 IMPL_LINK( SwBlink, Blinker, Timer *, EMPTYARG )
74 {
75 	bVisible = !bVisible;
76 	if( bVisible )
77 		aTimer.SetTimeout( BLINK_ON_TIME );
78 	else
79 		aTimer.SetTimeout( BLINK_OFF_TIME );
80 	if( aList.Count() )
81 	{
82 
83 		for( MSHORT nPos = 0; nPos < aList.Count(); )
84 		{
85 			const SwBlinkPortion* pTmp = aList[ nPos ];
86 			if( pTmp->GetRootFrm() &&
87 				((SwRootFrm*)pTmp->GetRootFrm())->GetCurrShell() )
88 			{
89 				++nPos;
90 
91                 Point aPos = pTmp->GetPos();
92                 long nWidth, nHeight;
93                 switch ( pTmp->GetDirection() )
94                 {
95                     case 900:
96                         aPos.X() -= pTmp->GetPortion()->GetAscent();
97                         aPos.Y() -= pTmp->GetPortion()->Width();
98                         nWidth = pTmp->GetPortion()->SvLSize().Height();
99                         nHeight = pTmp->GetPortion()->SvLSize().Width();
100                         break;
101 					case 1800:
102                         aPos.Y() -= pTmp->GetPortion()->Height() -
103 									pTmp->GetPortion()->GetAscent();
104 						aPos.X() -= pTmp->GetPortion()->Width();
105                         nWidth = pTmp->GetPortion()->SvLSize().Width();
106                         nHeight = pTmp->GetPortion()->SvLSize().Height();
107 						break;
108                     case 2700:
109                         aPos.X() -= pTmp->GetPortion()->Height() -
110                                     pTmp->GetPortion()->GetAscent();
111                         nWidth = pTmp->GetPortion()->SvLSize().Height();
112                         nHeight = pTmp->GetPortion()->SvLSize().Width();
113                         break;
114                     default:
115                         aPos.Y() -= pTmp->GetPortion()->GetAscent();
116                         nWidth = pTmp->GetPortion()->SvLSize().Width();
117                         nHeight = pTmp->GetPortion()->SvLSize().Height();
118                 }
119 
120                 Rectangle aRefresh( aPos, Size( nWidth, nHeight ) );
121 				aRefresh.Right() += ( aRefresh.Bottom()- aRefresh.Top() ) / 8;
122 				((SwRootFrm*)pTmp->GetRootFrm())
123 					->GetCurrShell()->InvalidateWindows( aRefresh );
124 			}
125 			else // Portions ohne Shell koennen aus der Liste entfernt werden.
126 				aList.Remove( nPos );
127 		}
128 	}
129 	else // Wenn die Liste leer ist, kann der Timer gestoppt werden.
130 		aTimer.Stop();
131 	return sal_True;
132 }
133 
Insert(const Point & rPoint,const SwLinePortion * pPor,const SwTxtFrm * pTxtFrm,sal_uInt16 nDir)134 void SwBlink::Insert( const Point& rPoint, const SwLinePortion* pPor,
135                       const SwTxtFrm *pTxtFrm, sal_uInt16 nDir )
136 {
137     SwBlinkPortion *pBlinkPor = new SwBlinkPortion( pPor, nDir );
138 
139 	MSHORT nPos;
140 	if( aList.Seek_Entry( pBlinkPor, &nPos ) )
141 	{
142         aList[ nPos ]->SetPos( rPoint );
143 		delete pBlinkPor;
144 	}
145 	else
146 	{
147         pBlinkPor->SetPos( rPoint );
148 		pBlinkPor->SetRootFrm( pTxtFrm->getRootFrm() );
149 		aList.Insert( pBlinkPor );
150 		pTxtFrm->SetBlinkPor();
151 		if( pPor->IsLayPortion() || pPor->IsParaPortion() )
152 			((SwLineLayout*)pPor)->SetBlinking( sal_True );
153 
154 		if( !aTimer.IsActive() )
155 			aTimer.Start();
156 	}
157 }
158 
Replace(const SwLinePortion * pOld,const SwLinePortion * pNew)159 void SwBlink::Replace( const SwLinePortion* pOld, const SwLinePortion* pNew )
160 {
161     // setting direction to 0 because direction does not matter
162     // for this operation
163     SwBlinkPortion aBlink( pOld, 0 );
164 	MSHORT nPos;
165 	if( aList.Seek_Entry( &aBlink, &nPos ) )
166 	{
167 		SwBlinkPortion* pTmp = new SwBlinkPortion( aList[ nPos ], pNew );
168 		aList.Remove( nPos );
169 		aList.Insert( pTmp );
170 	}
171 }
172 
Delete(const SwLinePortion * pPor)173 void SwBlink::Delete( const SwLinePortion* pPor )
174 {
175     // setting direction to 0 because direction does not matter
176     // for this operation
177     SwBlinkPortion aBlink( pPor, 0 );
178 	MSHORT nPos;
179 	if( aList.Seek_Entry( &aBlink, &nPos ) )
180 		aList.Remove( nPos );
181 }
182 
FrmDelete(const SwRootFrm * pRoot)183 void SwBlink::FrmDelete( const SwRootFrm* pRoot )
184 {
185 	for( MSHORT nPos = 0; nPos < aList.Count(); )
186 	{
187 		if( pRoot == aList[ nPos ]->GetRootFrm() )
188 			aList.Remove( nPos );
189 		else
190 			++nPos;
191 	}
192 }
193 
194 
195