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 .
22 #include <SwGrammarMarkUp.hxx>
23 #include <svl/listener.hxx>
24 #include <vcl/timer.hxx>
32 * This class is responsible for the delayed display of grammar checks when a paragraph is edited
33 * It's a client of the paragraph the cursor points to.
34 * If the cursor position changes, updateCursorPosition has to be called
35 * If the grammar checker wants to set a grammar marker at a paragraph, he has to request
36 * the grammar list from this class. If the requested paragraph is not edited, it returns
37 * the normal grammar list. But if the paragraph is the active one, a proxy list will be returned and
38 * all changes are set in this proxy list. If the cursor leaves the paragraph the proxy list
39 * will replace the old list. If the grammar checker has completed the paragraph ('setChecked')
40 * then a timer is setup which replaces the old list as well.
42 class GrammarContact final
: public SvtListener
45 std::unique_ptr
<SwGrammarMarkUp
> m_pProxyList
;
47 SwTextNode
* m_pTextNode
;
48 DECL_LINK(TimerRepaint
, Timer
*, void);
52 ~GrammarContact() { m_aTimer
.Stop(); }
54 /** Update cursor position reacts to a change of the current input cursor
55 As long as the cursor in inside a paragraph, the grammar checking does
56 not show new grammar faults. When the cursor leaves the paragraph, these
60 void updateCursorPosition(const SwPosition
& rNewPos
);
62 /** getGrammarCheck checks if the given text node is blocked by the current cursor
63 if not, the normal markup list is returned
64 if blocked, it will return a markup list "proxy"
65 @returns a markup list (grammar) for the given SwTextNode
67 SwGrammarMarkUp
* getGrammarCheck(SwTextNode
& rTextNode
, bool bCreate
);
69 /** finishGrammarCheck() has to be called if a grammar checking has been completed
70 for a text node. If this text node has not been hidden by the current proxy list
71 it will be repainted. Otherwise the proxy list replaces the old list and the
72 repaint will be triggered by a timer
75 void finishGrammarCheck(SwTextNode
& rTextNode
);
77 void CheckBroadcaster();
80 /* Helper functions */
82 /** getGrammarContact() delivers the grammar contact of the document (for a given textnode)
83 @returns grammar contact
85 GrammarContact
* getGrammarContactFor(const SwTextNode
&);
87 /** finishGrammarCheck() calls the same function of the grammar contact of the document (for a given textnode)
90 void finishGrammarCheckFor(SwTextNode
&);
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */