LibreOffice Module sw (master)  1
blink.cxx
Go to the documentation of this file.
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 <memory>
21 #include <viewsh.hxx>
22 #include <rootfrm.hxx>
23 #include <txtfrm.hxx>
24 #include <blink.hxx>
25 #include "porlin.hxx"
26 #include "porlay.hxx"
27 
28 // Visible time
29 #define BLINK_ON_TIME 2400
30 // Invisible time
31 #define BLINK_OFF_TIME 800
32 
39 SwBlink *pBlink = nullptr;
40 
42 {
43  bVisible = true;
44  // Prepare the timer
46  aTimer.SetInvokeHandler( LINK(this, SwBlink, Blinker) );
47 }
48 
50 {
51  aTimer.Stop();
52 }
53 
59 IMPL_LINK_NOARG(SwBlink, Blinker, Timer *, void)
60 {
61  bVisible = !bVisible;
62  if( bVisible )
63  aTimer.SetTimeout( BLINK_ON_TIME );
64  else
65  aTimer.SetTimeout( BLINK_OFF_TIME );
66  if (!m_List.empty())
67  {
68 
69  for (SwBlinkSet::iterator it = m_List.begin(); it != m_List.end(); )
70  {
71  const SwBlinkPortion* pTmp = it->get();
72  if( pTmp->GetRootFrame() &&
73  pTmp->GetRootFrame()->GetCurrShell() )
74  {
75  ++it;
76 
77  Point aPos = pTmp->GetPos();
78  long nWidth, nHeight;
79  switch ( pTmp->GetDirection() )
80  {
81  case 900:
82  aPos.AdjustX( -(pTmp->GetPortion()->GetAscent()) );
83  aPos.AdjustY( -(pTmp->GetPortion()->Width()) );
84  nWidth = pTmp->GetPortion()->SvLSize().Height();
85  nHeight = pTmp->GetPortion()->SvLSize().Width();
86  break;
87  case 1800:
88  aPos.AdjustY( -(pTmp->GetPortion()->Height() -
89  pTmp->GetPortion()->GetAscent()) );
90  aPos.AdjustX( -(pTmp->GetPortion()->Width()) );
91  nWidth = pTmp->GetPortion()->SvLSize().Width();
92  nHeight = pTmp->GetPortion()->SvLSize().Height();
93  break;
94  case 2700:
95  aPos.AdjustX( -(pTmp->GetPortion()->Height() -
96  pTmp->GetPortion()->GetAscent()) );
97  nWidth = pTmp->GetPortion()->SvLSize().Height();
98  nHeight = pTmp->GetPortion()->SvLSize().Width();
99  break;
100  default:
101  aPos.AdjustY( -(pTmp->GetPortion()->GetAscent()) );
102  nWidth = pTmp->GetPortion()->SvLSize().Width();
103  nHeight = pTmp->GetPortion()->SvLSize().Height();
104  }
105 
106  tools::Rectangle aRefresh( aPos, Size( nWidth, nHeight ) );
107  aRefresh.AdjustRight(( aRefresh.Bottom()- aRefresh.Top() ) / 8 );
108  pTmp->GetRootFrame()
109  ->GetCurrShell()->InvalidateWindows( aRefresh );
110  }
111  else // Portions without a shell can be removed from the list
112  it = m_List.erase(it);
113  }
114  }
115  else // If the list is empty, the timer can be stopped
116  aTimer.Stop();
117 }
118 
119 void SwBlink::Insert( const Point& rPoint, const SwLinePortion* pPor,
120  const SwTextFrame *pTextFrame, sal_uInt16 nDir )
121 {
122  std::unique_ptr<SwBlinkPortion> pBlinkPor(new SwBlinkPortion(pPor, nDir));
123 
124  SwBlinkSet::iterator it = m_List.find( pBlinkPor );
125  if (it != m_List.end())
126  {
127  (*it)->SetPos( rPoint );
128  }
129  else
130  {
131  pBlinkPor->SetPos( rPoint );
132  pBlinkPor->SetRootFrame( pTextFrame->getRootFrame() );
133  m_List.insert(std::move(pBlinkPor));
134  pTextFrame->SetBlinkPor();
135  if( pPor->IsLayPortion() || pPor->IsParaPortion() )
136  const_cast<SwLineLayout*>(static_cast<const SwLineLayout*>(pPor))->SetBlinking(true);
137 
138  if( !aTimer.IsActive() )
139  aTimer.Start();
140  }
141 }
142 
143 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  std::unique_ptr<SwBlinkPortion> pBlinkPortion(new SwBlinkPortion(pOld, 0));
148  SwBlinkSet::iterator it = m_List.find( pBlinkPortion );
149  if (it != m_List.end())
150  {
151  std::unique_ptr<SwBlinkPortion> pTmp(new SwBlinkPortion(it->get(), pNew));
152  m_List.erase( it );
153  m_List.insert(std::move(pTmp));
154  }
155 }
156 
157 void SwBlink::Delete( const SwLinePortion* pPor )
158 {
159  // setting direction to 0 because direction does not matter
160  // for this operation
161  std::unique_ptr<SwBlinkPortion> pBlinkPortion(new SwBlinkPortion(pPor, 0));
162  m_List.erase( pBlinkPortion );
163 }
164 
165 void SwBlink::FrameDelete( const SwRootFrame* pRoot )
166 {
167  for (SwBlinkSet::iterator it = m_List.begin(); it != m_List.end(); )
168  {
169  if (pRoot == (*it)->GetRootFrame())
170  it = m_List.erase(it);
171  else
172  ++it;
173  }
174 }
175 
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:149
sal_uInt16 Height() const
Definition: possiz.hxx:44
long AdjustX(long nHorzMove)
void SetBlinkPor() const
Definition: txtfrm.hxx:869
long Height() const
sal_uInt16 GetDirection() const
Definition: blink.hxx:60
Size SvLSize() const
Definition: possiz.hxx:48
const SwRootFrame * GetRootFrame() const
Definition: blink.hxx:58
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
bool IsParaPortion() const
Definition: porlin.hxx:122
bool IsActive() const
bool IsLayPortion() const
Definition: porlin.hxx:121
long Top() const
const Point & GetPos() const
Definition: blink.hxx:56
long AdjustY(long nVertMove)
const SwLinePortion * GetPortion() const
Definition: blink.hxx:59
long Bottom() const
virtual void Start() override
void SetTimeout(sal_uInt64 nTimeoutMs)
void InvalidateWindows(const SwRect &rRect)
Definition: viewsh.cxx:551
Base class for anything that can be part of a line in the Writer layout.
Definition: porlin.hxx:49
long AdjustRight(long nHorzMoveDelta)
void Stop()
void SetInvokeHandler(const Link< Timer *, void > &rLink)
sal_uInt16 Width() const
Definition: possiz.hxx:46
SwViewShell * GetCurrShell() const
Definition: rootfrm.hxx:204
sal_uInt16 & GetAscent()
Definition: porlin.hxx:76
SwRootFrame * getRootFrame()
Definition: frame.hxx:657