cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / inc / smarttag.hxx
blob6d004ffc6cc4ae2cdec16d7401a43bf01a678160
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 .
20 #pragma once
22 #include <helper/simplereferencecomponent.hxx>
23 #include <rtl/ref.hxx>
24 #include <set>
25 #include <svx/svdhdl.hxx>
26 #include <svx/svdview.hxx>
28 class KeyEvent;
29 class MouseEvent;
31 namespace sd
33 class View;
34 class SmartHdl;
36 /** a smart tag represents a visual user interface element on the documents edit view
37 that is not part of the document. It uses derivations from SmartHdl for its visuals.
38 A SmartTag adds himself to the given view if created. It removes himself if it
39 is disposed before the view is disposed.
41 Derive from this class to implement your own smart tag.
43 class SmartTag : public SimpleReferenceComponent
45 friend class SmartTagSet;
47 public:
48 explicit SmartTag(::sd::View& rView);
49 virtual ~SmartTag() override;
51 /** returns true if the SmartTag consumes this event. */
52 virtual bool MouseButtonDown(const MouseEvent&, SmartHdl&);
54 /** returns true if the SmartTag consumes this event. */
55 virtual bool KeyInput(const KeyEvent& rKEvt);
57 /** returns true if the SmartTag consumes this event. */
58 virtual bool Command(const CommandEvent& rCEvt);
60 /** returns true if this smart tag is currently selected */
61 bool isSelected() const { return mbSelected; }
63 protected:
64 virtual sal_Int32 GetMarkablePointCount() const;
65 virtual sal_Int32 GetMarkedPointCount() const;
66 virtual bool MarkPoint(SdrHdl& rHdl, bool bUnmark);
67 virtual void CheckPossibilities();
68 virtual bool MarkPoints(const ::tools::Rectangle* pRect, bool bUnmark);
70 virtual void addCustomHandles(SdrHdlList& rHandlerList);
71 virtual void select();
72 virtual void deselect();
73 virtual bool getContext(SdrViewContext& rContext);
75 virtual void disposing() override;
77 ::sd::View& mrView;
78 bool mbSelected;
80 private:
81 SmartTag(const SmartTag&) = delete;
82 SmartTag& operator=(const SmartTag&) = delete;
85 typedef rtl::Reference<SmartTag> SmartTagReference;
87 /** class to administrate the available smart tags for a single view. */
88 class SmartTagSet
90 friend class SmartTag;
92 public:
93 explicit SmartTagSet(::sd::View& rView);
94 ~SmartTagSet();
96 /** selects the given smart tag and updates all handles */
97 void select(const SmartTagReference& xTag);
99 /** deselects the current selected smart tag and updates all handles */
100 void deselect();
102 /** returns the currently selected tag or an empty reference. */
103 const SmartTagReference& getSelected() const { return mxSelectedTag; }
105 /** returns true if a SmartTag consumes this event. */
106 bool MouseButtonDown(const MouseEvent&);
108 /** returns true if a SmartTag consumes this event. */
109 bool KeyInput(const KeyEvent& rKEvt);
111 /** returns true if a SmartTag consumes this event. */
112 bool Command(const CommandEvent& rCEvt);
114 /** disposes all smart tags and clears the set */
115 void Dispose();
117 /** adds the handles from all smart tags to the given list */
118 void addCustomHandles(SdrHdlList& rHandlerList);
120 /** returns true if the currently selected smart tag has
121 a special context, returned in rContext. */
122 bool getContext(SdrViewContext& rContext) const;
124 // support point editing
125 bool HasMarkablePoints() const;
126 sal_uLong GetMarkablePointCount() const;
127 bool HasMarkedPoints() const;
128 sal_uLong GetMarkedPointCount() const;
129 bool MarkPoint(SdrHdl& rHdl, bool bUnmark);
130 bool MarkPoints(const ::tools::Rectangle* pRect, bool bUnmark);
132 void CheckPossibilities();
134 private:
135 SmartTagSet(const SmartTagSet&) = delete;
136 SmartTagSet& operator=(const SmartTagSet&) = delete;
138 /** adds a new smart tag to this set */
139 void add(const SmartTagReference& xTag);
141 /** removes the given smart tag from this set */
142 void remove(const SmartTagReference& xTag);
144 std::set<SmartTagReference> maSet;
146 ::sd::View& mrView;
147 SmartTagReference mxSelectedTag;
148 SmartTagReference mxMouseOverTag;
151 /** a derivation from this handle is the visual representation for a smart tag.
152 One smart tag can have more than one handle.
154 class SmartHdl : public SdrHdl
156 public:
157 SmartHdl(SmartTagReference xTag, SdrObject* pObject, const Point& rPnt, SdrHdlKind eNewKind);
158 SmartHdl(SmartTagReference xTag, const Point& rPnt, SdrHdlKind eNewKind);
160 const SmartTagReference& getTag() const { return mxSmartTag; }
162 private:
163 SmartTagReference mxSmartTag;
166 } // end of namespace sd
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */