/src/libreoffice/sw/inc/GrammarContact.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include <SwGrammarMarkUp.hxx> |
23 | | #include <svl/listener.hxx> |
24 | | #include <vcl/timer.hxx> |
25 | | |
26 | | struct SwPosition; |
27 | | class SwTextNode; |
28 | | |
29 | | namespace sw |
30 | | { |
31 | | /** |
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. |
41 | | */ |
42 | | class GrammarContact final : public SvtListener |
43 | | { |
44 | | Timer m_aTimer; |
45 | | std::unique_ptr<SwGrammarMarkUp> m_pProxyList; |
46 | | bool m_isFinished; |
47 | | SwTextNode* m_pTextNode; |
48 | | DECL_LINK(TimerRepaint, Timer*, void); |
49 | | |
50 | | public: |
51 | | GrammarContact(); |
52 | 94.3k | ~GrammarContact() { m_aTimer.Stop(); } |
53 | | |
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 |
57 | | faults are shown. |
58 | | @returns void |
59 | | */ |
60 | | void updateCursorPosition(const SwPosition& rNewPos); |
61 | | |
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 |
66 | | */ |
67 | | SwGrammarMarkUp* getGrammarCheck(SwTextNode& rTextNode, bool bCreate); |
68 | | |
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 |
73 | | @returns void |
74 | | */ |
75 | | void finishGrammarCheck(const SwTextNode& rTextNode); |
76 | | |
77 | | void CheckBroadcaster(); |
78 | | }; |
79 | | |
80 | | /* Helper functions */ |
81 | | |
82 | | /** getGrammarContact() delivers the grammar contact of the document (for a given textnode) |
83 | | @returns grammar contact |
84 | | */ |
85 | | GrammarContact* getGrammarContactFor(const SwTextNode&); |
86 | | |
87 | | /** finishGrammarCheck() calls the same function of the grammar contact of the document (for a given textnode) |
88 | | @returns void |
89 | | */ |
90 | | void finishGrammarCheckFor(const SwTextNode&); |
91 | | |
92 | | } // end sw |
93 | | |
94 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |