LibreOffice Module sw (master) 1
GrammarContact.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 <GrammarContact.hxx>
21#include <doc.hxx>
22#include <pam.hxx>
23#include <ndtxt.hxx>
24#include <txtfrm.hxx>
25
26namespace sw
27{
28
30 : m_aTimer( "sw::SwGrammarContact TimerRepaint" ),
31 m_isFinished( false ),
32 m_pTextNode(nullptr)
33{
34 m_aTimer.SetTimeout( 2000 ); // Repaint of grammar check after 'setChecked'
35 m_aTimer.SetInvokeHandler( LINK(this, GrammarContact, TimerRepaint) );
36}
37
39{
40 if (HasBroadcaster())
41 return;
42 m_pTextNode = nullptr;
43 m_pProxyList.reset();
44}
45
46IMPL_LINK( GrammarContact, TimerRepaint, Timer *, pTimer, void )
47{
48 CheckBroadcaster();
49 if( pTimer )
50 {
51 pTimer->Stop();
52 if( m_pTextNode )
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 );
56 }
57 }
58}
59
60/* I'm always a client of the current paragraph */
62{
64 SwTextNode* pTextNode = rNewPos.GetNode().GetTextNode();
65 if( pTextNode == m_pTextNode ) // paragraph has been changed
66 return;
67
68 m_aTimer.Stop();
69 if( m_pTextNode ) // My last paragraph has been left
70 {
71 if( m_pProxyList )
72 { // replace old list by the proxy list and repaint
75 }
77 }
78 if( pTextNode )
79 {
80 m_pTextNode = pTextNode;
82 StartListening(pTextNode->GetNotifier()); // welcome new paragraph
83 }
84}
85
86/* deliver a grammar check list for the given text node */
88{
89 SwGrammarMarkUp *pRet = nullptr;
91 if( m_pTextNode == &rTextNode ) // hey, that's my current paragraph!
92 { // so you will get a proxy list...
93 if( bCreate )
94 {
95 if( m_isFinished )
96 {
97 m_pProxyList.reset();
98 }
99 if( !m_pProxyList )
100 {
101 if( rTextNode.GetGrammarCheck() )
102 m_pProxyList.reset( static_cast<SwGrammarMarkUp*>(rTextNode.GetGrammarCheck()->Clone()) );
103 else
104 {
105 m_pProxyList.reset( new SwGrammarMarkUp() );
106 m_pProxyList->SetInvalid( 0, COMPLETE_STRING );
107 }
108 }
109 m_isFinished = false;
110 }
111 pRet = m_pProxyList.get();
112 }
113 else
114 {
115 pRet = rTextNode.GetGrammarCheck(); // do you have already a list?
116 if( bCreate && !pRet ) // do you want to create a list?
117 {
118 pRet = new SwGrammarMarkUp();
119 pRet->SetInvalid( 0, COMPLETE_STRING );
120 rTextNode.SetGrammarCheck( std::unique_ptr<SwGrammarMarkUp>(pRet) );
121 rTextNode.SetGrammarCheckDirty( true );
122 }
123 }
124 return pRet;
125}
126
128{
130 if( &rTextNode != m_pTextNode ) // not my paragraph
131 SwTextFrame::repaintTextFrames( rTextNode ); // can be repainted directly
132 else
133 {
134 if( m_pProxyList )
135 {
136 m_isFinished = true;
137 m_aTimer.Start(); // will replace old list and repaint with delay
138 }
139 else if( m_pTextNode->GetGrammarCheck() )
140 { // all grammar problems seems to be gone, no delay needed
143 }
144 }
145}
146
148{
149 const SwDoc& rDoc = rTextNode.GetDoc();
150 if (rDoc.IsInDtor())
151 return nullptr;
152 return rDoc.getGrammarContact().get();
153}
154
156{
157 sw::GrammarContact* pGrammarContact = getGrammarContactFor(rTextNode);
158 if (pGrammarContact)
159 {
160 pGrammarContact->finishGrammarCheck(rTextNode);
161 }
162}
163
164} // end sw
165
166/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool HasBroadcaster() const
void EndListeningAll()
bool StartListening(SvtBroadcaster &rBroadcaster)
Definition: doc.hxx:195
bool IsInDtor() const
Definition: doc.hxx:413
std::unique_ptr< sw::GrammarContact > const & getGrammarContact() const
Definition: doc.hxx:1569
virtual SwWrongList * Clone() override
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:897
SwDoc & GetDoc()
Definition: node.hxx:233
static void repaintTextFrames(const SwTextNode &rNode)
Repaint all text frames of the given text node.
Definition: txtfrm.cxx:4090
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:111
void SetGrammarCheckDirty(bool bNew) const
Definition: txtedt.cxx:2314
void ClearGrammarCheck()
Definition: txtedt.cxx:2241
SwGrammarMarkUp * GetGrammarCheck()
Definition: txtedt.cxx:2251
void SetGrammarCheck(std::unique_ptr< SwGrammarMarkUp > pNew)
Definition: txtedt.cxx:2236
void SetInvalid(sal_Int32 nBegin, sal_Int32 nEnd)
Definition: wrong.cxx:254
void Stop()
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
virtual void Start(bool bStartTimer=true) override
This class is responsible for the delayed display of grammar checks when a paragraph is edited It's a...
SwTextNode * m_pTextNode
std::unique_ptr< SwGrammarMarkUp > m_pProxyList
SwGrammarMarkUp * getGrammarCheck(SwTextNode &rTextNode, bool bCreate)
getGrammarCheck checks if the given text node is blocked by the current cursor if not,...
void updateCursorPosition(const SwPosition &rNewPos)
Update cursor position reacts to a change of the current input cursor As long as the cursor in inside...
void finishGrammarCheck(SwTextNode &rTextNode)
finishGrammarCheck() has to be called if a grammar checking has been completed for a text node.
Dialog to specify the properties of date form field.
sw::GrammarContact * getGrammarContactFor(const SwTextNode &rTextNode)
getGrammarContact() delivers the grammar contact of the document (for a given textnode)
IMPL_LINK(DocumentStatisticsManager, DoIdleStatsUpdate, Timer *, pIdle, void)
void finishGrammarCheckFor(SwTextNode &rTextNode)
finishGrammarCheck() calls the same function of the grammar contact of the document (for a given text...
Marks a position in the document model.
Definition: pam.hxx:37
SwNode & GetNode() const
Definition: pam.hxx:80
constexpr sal_Int32 COMPLETE_STRING
Definition: swtypes.hxx:57