Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / unocrsr.hxx
blobd789bed5db398b267de4d98c39b66a5861347c59
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #ifndef INCLUDED_SW_INC_UNOCRSR_HXX
20 #define INCLUDED_SW_INC_UNOCRSR_HXX
22 #include <swcrsr.hxx>
23 #include <svl/SfxBroadcaster.hxx>
24 #include <svl/lstner.hxx>
26 namespace sw
28 struct SW_DLLPUBLIC UnoCursorHint final : public SfxHint
30 UnoCursorHint() {}
31 virtual ~UnoCursorHint() override;
35 class SwUnoCursor : public virtual SwCursor
37 private:
38 bool m_bRemainInSection : 1;
39 bool m_bSkipOverHiddenSections : 1;
40 bool m_bSkipOverProtectSections : 1;
42 public:
43 SfxBroadcaster m_aNotifier;
44 SwUnoCursor( const SwPosition &rPos );
45 virtual ~SwUnoCursor() override;
47 protected:
49 virtual const SwContentFrame* DoSetBidiLevelLeftRight(
50 bool & io_rbLeft, bool bVisualAllowed, bool bInsertCursor) override;
51 virtual void DoSetBidiLevelUpDown() override;
53 public:
55 // Does a selection of content exist in table?
56 // Return value indicates if the cursor remains at its old position.
57 virtual bool IsSelOvr( SwCursorSelOverFlags eFlags =
58 ( SwCursorSelOverFlags::CheckNodeSection |
59 SwCursorSelOverFlags::Toggle |
60 SwCursorSelOverFlags::ChangePos )) override;
62 virtual bool IsReadOnlyAvailable() const override;
64 bool IsRemainInSection() const { return m_bRemainInSection; }
65 void SetRemainInSection( bool bFlag ) { m_bRemainInSection = bFlag; }
67 virtual bool IsSkipOverProtectSections() const override
68 { return m_bSkipOverProtectSections; }
69 void SetSkipOverProtectSections( bool bFlag )
70 { m_bSkipOverProtectSections = bFlag; }
72 virtual bool IsSkipOverHiddenSections() const override
73 { return m_bSkipOverHiddenSections; }
74 void SetSkipOverHiddenSections( bool bFlag )
75 { m_bSkipOverHiddenSections = bFlag; }
77 DECL_FIXEDMEMPOOL_NEWDEL( SwUnoCursor )
80 class SwUnoTableCursor : public virtual SwUnoCursor, public virtual SwTableCursor
82 // The selection has the same order as the table boxes, i.e.
83 // if something is deleted from the one array at a certain position
84 // it has also to be deleted from the other!
85 SwCursor m_aTableSel;
87 using SwTableCursor::MakeBoxSels;
89 public:
90 SwUnoTableCursor( const SwPosition& rPos );
91 virtual ~SwUnoTableCursor() override;
93 // Does a selection of content exist in table?
94 // Return value indicates if the cursor remains at its old position.
95 virtual bool IsSelOvr( SwCursorSelOverFlags eFlags =
96 ( SwCursorSelOverFlags::CheckNodeSection |
97 SwCursorSelOverFlags::Toggle |
98 SwCursorSelOverFlags::ChangePos )) override;
100 void MakeBoxSels();
102 SwCursor& GetSelRing() { return m_aTableSel; }
103 const SwCursor& GetSelRing() const { return m_aTableSel; }
106 namespace sw
108 class UnoCursorPointer : public SfxListener
110 public:
111 UnoCursorPointer()
112 : m_pCursor(nullptr)
114 UnoCursorPointer(std::shared_ptr<SwUnoCursor> const & pCursor)
115 : m_pCursor(pCursor)
117 StartListening(m_pCursor->m_aNotifier);
119 UnoCursorPointer(const UnoCursorPointer& rOther)
120 : SfxListener()
121 , m_pCursor(rOther.m_pCursor)
123 if(m_pCursor)
124 StartListening(m_pCursor->m_aNotifier);
126 virtual ~UnoCursorPointer() override
128 if(m_pCursor)
129 EndListening(m_pCursor->m_aNotifier);
131 virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override
133 if(m_pCursor)
135 if(typeid(rHint) == typeid(UnoCursorHint))
136 EndListening(rBC);
138 if(!GetBroadcasterCount())
139 m_pCursor.reset();
141 SwUnoCursor* get() const
142 { return m_pCursor.get(); }
143 SwUnoCursor* operator->() const
144 { return get(); }
145 SwUnoCursor& operator*() const
146 { return *get(); }
147 UnoCursorPointer& operator=(UnoCursorPointer aOther)
149 if(aOther.m_pCursor)
150 StartListening(aOther.m_pCursor->m_aNotifier);
151 m_pCursor = aOther.m_pCursor;
152 return *this;
154 explicit operator bool() const
155 { return static_cast<bool>(m_pCursor); }
156 void reset(std::shared_ptr<SwUnoCursor> pNew)
158 if(pNew)
159 StartListening(pNew->m_aNotifier);
160 else if(m_pCursor)
161 EndListening(m_pCursor->m_aNotifier);
162 m_pCursor = pNew;
164 private:
165 std::shared_ptr<SwUnoCursor> m_pCursor;
168 #endif
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */