/src/libreoffice/sw/inc/unocrsr.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 | | #ifndef INCLUDED_SW_INC_UNOCRSR_HXX |
20 | | #define INCLUDED_SW_INC_UNOCRSR_HXX |
21 | | |
22 | | #include "swcrsr.hxx" |
23 | | #include <svl/SfxBroadcaster.hxx> |
24 | | #include <svl/lstner.hxx> |
25 | | #include <utility> |
26 | | |
27 | | namespace sw |
28 | | { |
29 | | struct SW_DLLPUBLIC UnoCursorHint final : public SfxHint |
30 | | { |
31 | 86.6k | UnoCursorHint() : SfxHint(SfxHintId::SwUnoCursorHint) {} |
32 | | virtual ~UnoCursorHint() override; |
33 | | }; |
34 | | } |
35 | | |
36 | | class SAL_DLLPUBLIC_RTTI SwUnoCursor : public virtual SwCursor |
37 | | { |
38 | | private: |
39 | | bool m_bRemainInSection : 1; |
40 | | bool m_bSkipOverHiddenSections : 1; |
41 | | bool m_bSkipOverProtectSections : 1; |
42 | | |
43 | | public: |
44 | | SfxBroadcaster m_aNotifier; |
45 | | SwUnoCursor( const SwPosition &rPos ); |
46 | | virtual ~SwUnoCursor() override; |
47 | | |
48 | | protected: |
49 | | |
50 | | virtual const SwContentFrame* DoSetBidiLevelLeftRight( |
51 | | bool & io_rbLeft, bool bVisualAllowed, bool bInsertCursor) override; |
52 | | virtual void DoSetBidiLevelUpDown() override; |
53 | | |
54 | | public: |
55 | | |
56 | | // Does a selection of content exist in table? |
57 | | // Return value indicates if the cursor remains at its old position. |
58 | | virtual bool IsSelOvr( SwCursorSelOverFlags eFlags = |
59 | | SwCursorSelOverFlags::CheckNodeSection | |
60 | | SwCursorSelOverFlags::Toggle | |
61 | | SwCursorSelOverFlags::ChangePos ) override; |
62 | | |
63 | | virtual bool IsReadOnlyAvailable() const override; |
64 | | |
65 | 576k | bool IsRemainInSection() const { return m_bRemainInSection; } |
66 | 113k | void SetRemainInSection( bool bFlag ) { m_bRemainInSection = bFlag; } |
67 | | |
68 | | virtual bool IsSkipOverProtectSections() const override |
69 | 175k | { return m_bSkipOverProtectSections; } |
70 | | void SetSkipOverProtectSections( bool bFlag ) |
71 | 0 | { m_bSkipOverProtectSections = bFlag; } |
72 | | |
73 | | virtual bool IsSkipOverHiddenSections() const override |
74 | 175k | { return m_bSkipOverHiddenSections; } |
75 | | void SetSkipOverHiddenSections( bool bFlag ) |
76 | 0 | { m_bSkipOverHiddenSections = bFlag; } |
77 | | }; |
78 | | |
79 | | class SwUnoTableCursor final : public virtual SwUnoCursor, public virtual SwTableCursor |
80 | | { |
81 | | // The selection has the same order as the table boxes, i.e. |
82 | | // if something is deleted from the one array at a certain position |
83 | | // it has also to be deleted from the other! |
84 | | SwCursor m_aTableSel; |
85 | | |
86 | | using SwTableCursor::MakeBoxSels; |
87 | | |
88 | | public: |
89 | | SwUnoTableCursor( const SwPosition& rPos ); |
90 | | virtual ~SwUnoTableCursor() override; |
91 | | |
92 | | // Does a selection of content exist in table? |
93 | | // Return value indicates if the cursor remains at its old position. |
94 | | virtual bool IsSelOvr( SwCursorSelOverFlags eFlags = |
95 | | SwCursorSelOverFlags::CheckNodeSection | |
96 | | SwCursorSelOverFlags::Toggle | |
97 | | SwCursorSelOverFlags::ChangePos ) override; |
98 | | |
99 | | void MakeBoxSels(); |
100 | | |
101 | 93 | SwCursor& GetSelRing() { return m_aTableSel; } |
102 | 0 | const SwCursor& GetSelRing() const { return m_aTableSel; } |
103 | | }; |
104 | | |
105 | | namespace sw |
106 | | { |
107 | | class UnoCursorPointer final : public SfxListener |
108 | | { |
109 | | public: |
110 | | UnoCursorPointer() |
111 | 17.4k | {} |
112 | | UnoCursorPointer(std::shared_ptr<SwUnoCursor> pCursor) |
113 | 729k | : m_pCursor(std::move(pCursor)) |
114 | 729k | { |
115 | 729k | StartListening(m_pCursor->m_aNotifier); |
116 | 729k | } |
117 | | UnoCursorPointer(const UnoCursorPointer& rOther) |
118 | 5.45k | : SfxListener() |
119 | 5.45k | , m_pCursor(rOther.m_pCursor) |
120 | 5.45k | { |
121 | 5.45k | if(m_pCursor) |
122 | 5.45k | StartListening(m_pCursor->m_aNotifier); |
123 | 5.45k | } |
124 | | virtual ~UnoCursorPointer() override |
125 | 752k | { |
126 | 752k | if(m_pCursor) |
127 | 6.08k | EndListening(m_pCursor->m_aNotifier); |
128 | 752k | } |
129 | | virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override |
130 | 9.11k | { |
131 | 9.11k | if(m_pCursor) |
132 | 9.11k | { |
133 | 9.11k | if(rHint.GetId() == SfxHintId::SwUnoCursorHint) |
134 | 9.11k | EndListening(rBC); |
135 | 9.11k | } |
136 | 9.11k | if(!GetBroadcasterCount()) |
137 | 9.11k | m_pCursor.reset(); |
138 | 9.11k | }; |
139 | | SwUnoCursor* get() const |
140 | 4.43M | { return m_pCursor.get(); } |
141 | | SwUnoCursor* operator->() const |
142 | 1.31M | { return get(); } |
143 | | SwUnoCursor& operator*() const |
144 | 2.43M | { return *get(); } |
145 | | UnoCursorPointer& operator=(const UnoCursorPointer& aOther) |
146 | 0 | { |
147 | 0 | if (m_pCursor) |
148 | 0 | { |
149 | 0 | EndListening(m_pCursor->m_aNotifier); |
150 | 0 | } |
151 | 0 | if(aOther.m_pCursor) |
152 | 0 | StartListening(aOther.m_pCursor->m_aNotifier); |
153 | 0 | m_pCursor = aOther.m_pCursor; |
154 | 0 | return *this; |
155 | 0 | } |
156 | | explicit operator bool() const |
157 | 2.78M | { return static_cast<bool>(m_pCursor); } |
158 | | void reset(const std::shared_ptr<SwUnoCursor>& pNew) |
159 | 763k | { |
160 | 763k | if(pNew) |
161 | 17.4k | StartListening(pNew->m_aNotifier); |
162 | 763k | if (m_pCursor) |
163 | 737k | EndListening(m_pCursor->m_aNotifier); |
164 | 763k | m_pCursor = pNew; |
165 | 763k | } |
166 | | private: |
167 | | std::shared_ptr<SwUnoCursor> m_pCursor; |
168 | | }; |
169 | | } |
170 | | #endif |
171 | | |
172 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |