1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <GrammarContact.hxx>
29 GrammarContact::GrammarContact()
30 : m_aTimer( "sw::SwGrammarContact TimerRepaint" ),
31 m_isFinished( false ),
34 m_aTimer
.SetTimeout( 2000 ); // Repaint of grammar check after 'setChecked'
35 m_aTimer
.SetInvokeHandler( LINK(this, GrammarContact
, TimerRepaint
) );
38 void GrammarContact::CheckBroadcaster()
42 m_pTextNode
= nullptr;
46 IMPL_LINK( GrammarContact
, TimerRepaint
, Timer
*, pTimer
, void )
53 { //Replace the old wrong list by the proxy list and repaint all frames
54 m_pTextNode
->SetGrammarCheck( std::move(m_pProxyList
) );
55 SwTextFrame::repaintTextFrames( *m_pTextNode
);
60 /* I'm always a client of the current paragraph */
61 void GrammarContact::updateCursorPosition( const SwPosition
& rNewPos
)
64 SwTextNode
* pTextNode
= rNewPos
.GetNode().GetTextNode();
65 if( pTextNode
== m_pTextNode
) // paragraph has been changed
69 if( m_pTextNode
) // My last paragraph has been left
72 { // replace old list by the proxy list and repaint
73 m_pTextNode
->SetGrammarCheck( std::move(m_pProxyList
) );
74 SwTextFrame::repaintTextFrames( *m_pTextNode
);
80 m_pTextNode
= pTextNode
;
82 StartListening(pTextNode
->GetNotifier()); // welcome new paragraph
86 /* deliver a grammar check list for the given text node */
87 SwGrammarMarkUp
* GrammarContact::getGrammarCheck( SwTextNode
& rTextNode
, bool bCreate
)
89 SwGrammarMarkUp
*pRet
= nullptr;
91 if( m_pTextNode
== &rTextNode
) // hey, that's my current paragraph!
92 { // so you will get a proxy list...
101 if( rTextNode
.GetGrammarCheck() )
102 m_pProxyList
.reset( static_cast<SwGrammarMarkUp
*>(rTextNode
.GetGrammarCheck()->Clone()) );
105 m_pProxyList
.reset( new SwGrammarMarkUp() );
106 m_pProxyList
->SetInvalid( 0, COMPLETE_STRING
);
109 m_isFinished
= false;
111 pRet
= m_pProxyList
.get();
115 pRet
= rTextNode
.GetGrammarCheck(); // do you have already a list?
116 if( bCreate
&& !pRet
) // do you want to create a list?
118 pRet
= new SwGrammarMarkUp();
119 pRet
->SetInvalid( 0, COMPLETE_STRING
);
120 rTextNode
.SetGrammarCheck( std::unique_ptr
<SwGrammarMarkUp
>(pRet
) );
121 rTextNode
.SetGrammarCheckDirty( true );
127 void GrammarContact::finishGrammarCheck( SwTextNode
& rTextNode
)
130 if( &rTextNode
!= m_pTextNode
) // not my paragraph
131 SwTextFrame::repaintTextFrames( rTextNode
); // can be repainted directly
137 m_aTimer
.Start(); // will replace old list and repaint with delay
139 else if( m_pTextNode
->GetGrammarCheck() )
140 { // all grammar problems seems to be gone, no delay needed
141 m_pTextNode
->ClearGrammarCheck();
142 SwTextFrame::repaintTextFrames( *m_pTextNode
);
147 sw::GrammarContact
* getGrammarContactFor(const SwTextNode
& rTextNode
)
149 const SwDoc
& rDoc
= rTextNode
.GetDoc();
152 return rDoc
.getGrammarContact().get();
155 void finishGrammarCheckFor(SwTextNode
& rTextNode
)
157 sw::GrammarContact
* pGrammarContact
= getGrammarContactFor(rTextNode
);
160 pGrammarContact
->finishGrammarCheck(rTextNode
);
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */