Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "viewsh.hxx"
21 : #include "rootfrm.hxx"
22 : #include "txtfrm.hxx"
23 : #include "blink.hxx"
24 : #include "porlin.hxx"
25 : #include "porlay.hxx"
26 :
27 : // Visible time
28 : #define BLINK_ON_TIME 2400L
29 : // Invisible time
30 : #define BLINK_OFF_TIME 800L
31 :
32 : /**
33 : * pBlink points to the instance where blinking portions need to register.
34 : * If necessary, it needs to be created by SwBlink.
35 : * They are then triggered rhythimcally for a repaint. They can query
36 : * for being visible or invisible with IsVisible().
37 : */
38 : SwBlink *pBlink = NULL;
39 :
40 2 : SwBlink::SwBlink()
41 : {
42 2 : bVisible = true;
43 : // Prepare the timer
44 2 : aTimer.SetTimeout( BLINK_ON_TIME );
45 2 : aTimer.SetTimeoutHdl( LINK(this, SwBlink, Blinker) );
46 2 : }
47 :
48 4 : SwBlink::~SwBlink( )
49 : {
50 2 : aTimer.Stop();
51 2 : }
52 :
53 : /**
54 : * SwBlink::Blinker (timer):
55 : * Toggle visibility flag
56 : * Determine the repaint rectangle and invalidate them in their OleShells.
57 : */
58 8 : IMPL_LINK_NOARG(SwBlink, Blinker)
59 : {
60 4 : bVisible = !bVisible;
61 4 : if( bVisible )
62 2 : aTimer.SetTimeout( BLINK_ON_TIME );
63 : else
64 2 : aTimer.SetTimeout( BLINK_OFF_TIME );
65 4 : if( !aList.empty() )
66 : {
67 :
68 0 : for( SwBlinkList::iterator it = aList.begin(); it != aList.end(); )
69 : {
70 0 : const SwBlinkPortion* pTmp = &*it;
71 0 : if( pTmp->GetRootFrm() &&
72 0 : ((SwRootFrm*)pTmp->GetRootFrm())->GetCurrShell() )
73 : {
74 0 : ++it;
75 :
76 0 : Point aPos = pTmp->GetPos();
77 : long nWidth, nHeight;
78 0 : switch ( pTmp->GetDirection() )
79 : {
80 : case 900:
81 0 : aPos.X() -= pTmp->GetPortion()->GetAscent();
82 0 : aPos.Y() -= pTmp->GetPortion()->Width();
83 0 : nWidth = pTmp->GetPortion()->SvLSize().Height();
84 0 : nHeight = pTmp->GetPortion()->SvLSize().Width();
85 0 : break;
86 : case 1800:
87 0 : aPos.Y() -= pTmp->GetPortion()->Height() -
88 0 : pTmp->GetPortion()->GetAscent();
89 0 : aPos.X() -= pTmp->GetPortion()->Width();
90 0 : nWidth = pTmp->GetPortion()->SvLSize().Width();
91 0 : nHeight = pTmp->GetPortion()->SvLSize().Height();
92 0 : break;
93 : case 2700:
94 0 : aPos.X() -= pTmp->GetPortion()->Height() -
95 0 : pTmp->GetPortion()->GetAscent();
96 0 : nWidth = pTmp->GetPortion()->SvLSize().Height();
97 0 : nHeight = pTmp->GetPortion()->SvLSize().Width();
98 0 : break;
99 : default:
100 0 : aPos.Y() -= pTmp->GetPortion()->GetAscent();
101 0 : nWidth = pTmp->GetPortion()->SvLSize().Width();
102 0 : nHeight = pTmp->GetPortion()->SvLSize().Height();
103 : }
104 :
105 0 : Rectangle aRefresh( aPos, Size( nWidth, nHeight ) );
106 0 : aRefresh.Right() += ( aRefresh.Bottom()- aRefresh.Top() ) / 8;
107 0 : ((SwRootFrm*)pTmp->GetRootFrm())
108 0 : ->GetCurrShell()->InvalidateWindows( aRefresh );
109 : }
110 : else // Portions without a shell can be removed from the list
111 0 : it = aList.erase(it);
112 : }
113 : }
114 : else // If the list is empty, the timer can be stopped
115 4 : aTimer.Stop();
116 4 : return 1;
117 : }
118 :
119 216 : void SwBlink::Insert( const Point& rPoint, const SwLinePortion* pPor,
120 : const SwTxtFrm *pTxtFrm, sal_uInt16 nDir )
121 : {
122 216 : SwBlinkPortion *pBlinkPor = new SwBlinkPortion( pPor, nDir );
123 :
124 216 : SwBlinkList::iterator it = aList.find( *pBlinkPor );
125 216 : if( it != aList.end() )
126 : {
127 0 : (*it).SetPos( rPoint );
128 0 : delete pBlinkPor;
129 : }
130 : else
131 : {
132 216 : pBlinkPor->SetPos( rPoint );
133 216 : pBlinkPor->SetRootFrm( pTxtFrm->getRootFrm() );
134 216 : aList.insert( pBlinkPor );
135 216 : pTxtFrm->SetBlinkPor();
136 216 : if( pPor->IsLayPortion() || pPor->IsParaPortion() )
137 12 : ((SwLineLayout*)pPor)->SetBlinking();
138 :
139 216 : if( !aTimer.IsActive() )
140 4 : aTimer.Start();
141 : }
142 216 : }
143 :
144 0 : void SwBlink::Replace( const SwLinePortion* pOld, const SwLinePortion* pNew )
145 : {
146 : // setting direction to 0 because direction does not matter
147 : // for this operation
148 0 : SwBlinkPortion aBlink( pOld, 0 );
149 0 : SwBlinkList::iterator it = aList.find( aBlink );
150 0 : if( it != aList.end() )
151 : {
152 0 : SwBlinkPortion* aTmp = new SwBlinkPortion( &*it, pNew );
153 0 : aList.erase( it );
154 0 : aList.insert( aTmp );
155 : }
156 0 : }
157 :
158 4306 : void SwBlink::Delete( const SwLinePortion* pPor )
159 : {
160 : // setting direction to 0 because direction does not matter
161 : // for this operation
162 4306 : SwBlinkPortion aBlink( pPor, 0 );
163 4306 : aList.erase( aBlink );
164 4306 : }
165 :
166 73 : void SwBlink::FrmDelete( const SwRootFrm* pRoot )
167 : {
168 146 : for( SwBlinkList::iterator it = aList.begin(); it != aList.end(); )
169 : {
170 0 : if( pRoot == (*it).GetRootFrm() )
171 0 : aList.erase( it++ );
172 : else
173 0 : ++it;
174 : }
175 343 : }
176 :
177 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|