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 1 : SwBlink::SwBlink()
41 : {
42 1 : bVisible = true;
43 : // Prepare the timer
44 1 : aTimer.SetTimeout( BLINK_ON_TIME );
45 1 : aTimer.SetTimeoutHdl( LINK(this, SwBlink, Blinker) );
46 1 : }
47 :
48 2 : SwBlink::~SwBlink( )
49 : {
50 1 : aTimer.Stop();
51 1 : }
52 :
53 : /**
54 : * SwBlink::Blinker (timer):
55 : * Toggle visibility flag
56 : * Determine the repaint rectangle and invalidate them in their OleShells.
57 : */
58 2 : IMPL_LINK_NOARG_TYPED(SwBlink, Blinker, Timer *, void)
59 : {
60 1 : bVisible = !bVisible;
61 1 : if( bVisible )
62 0 : aTimer.SetTimeout( BLINK_ON_TIME );
63 : else
64 1 : aTimer.SetTimeout( BLINK_OFF_TIME );
65 1 : 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 : 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 : 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 1 : aTimer.Stop();
116 1 : }
117 :
118 58 : void SwBlink::Insert( const Point& rPoint, const SwLinePortion* pPor,
119 : const SwTextFrm *pTextFrm, sal_uInt16 nDir )
120 : {
121 58 : SwBlinkPortion *pBlinkPor = new SwBlinkPortion( pPor, nDir );
122 :
123 58 : SwBlinkList::iterator it = aList.find( *pBlinkPor );
124 58 : if( it != aList.end() )
125 : {
126 4 : (*it).SetPos( rPoint );
127 4 : delete pBlinkPor;
128 : }
129 : else
130 : {
131 54 : pBlinkPor->SetPos( rPoint );
132 54 : pBlinkPor->SetRootFrm( pTextFrm->getRootFrm() );
133 54 : aList.insert( pBlinkPor );
134 54 : pTextFrm->SetBlinkPor();
135 54 : if( pPor->IsLayPortion() || pPor->IsParaPortion() )
136 3 : const_cast<SwLineLayout*>(static_cast<const SwLineLayout*>(pPor))->SetBlinking();
137 :
138 54 : if( !aTimer.IsActive() )
139 1 : aTimer.Start();
140 : }
141 58 : }
142 :
143 0 : void SwBlink::Replace( const SwLinePortion* pOld, const SwLinePortion* pNew )
144 : {
145 : // setting direction to 0 because direction does not matter
146 : // for this operation
147 0 : SwBlinkPortion aBlink( pOld, 0 );
148 0 : SwBlinkList::iterator it = aList.find( aBlink );
149 0 : if( it != aList.end() )
150 : {
151 0 : SwBlinkPortion* aTmp = new SwBlinkPortion( &*it, pNew );
152 0 : aList.erase( it );
153 0 : aList.insert( aTmp );
154 : }
155 0 : }
156 :
157 490 : void SwBlink::Delete( const SwLinePortion* pPor )
158 : {
159 : // setting direction to 0 because direction does not matter
160 : // for this operation
161 490 : SwBlinkPortion aBlink( pPor, 0 );
162 490 : aList.erase( aBlink );
163 490 : }
164 :
165 16 : void SwBlink::FrmDelete( const SwRootFrm* pRoot )
166 : {
167 32 : for( SwBlinkList::iterator it = aList.begin(); it != aList.end(); )
168 : {
169 0 : if( pRoot == (*it).GetRootFrm() )
170 0 : aList.erase( it++ );
171 : else
172 0 : ++it;
173 : }
174 193 : }
175 :
176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|