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 #ifndef INCLUDED_SD_SOURCE_UI_INC_SMARTTAG_HXX
21 #define INCLUDED_SD_SOURCE_UI_INC_SMARTTAG_HXX
22 
23 #include <helper/simplereferencecomponent.hxx>
24 #include <rtl/ref.hxx>
25 #include <set>
26 #include <svx/svdhdl.hxx>
27 #include <svx/svdview.hxx>
28 
29 class KeyEvent;
30 class MouseEvent;
31 
32 namespace sd {
33 
34 class View;
35 class SmartHdl;
36 
37 /** a smart tag represents a visual user interface element on the documents edit view
38     that is not part of the document. It uses derivations from SmartHdl for its visuals.
39     A SmartTag adds himself to the given view if created. It removes himself if it
40     is disposed before the view is disposed.
41 
42     Derive from this class to implement your own smart tag.
43 */
44 class SmartTag : public SimpleReferenceComponent
45 {
46     friend class SmartTagSet;
47 
48 public:
49     explicit SmartTag( ::sd::View& rView );
50     virtual ~SmartTag() override;
51 
52     /** returns true if the SmartTag consumes this event. */
53     virtual bool MouseButtonDown( const MouseEvent&, SmartHdl& );
54 
55     /** returns true if the SmartTag consumes this event. */
56     virtual bool KeyInput( const KeyEvent& rKEvt );
57 
58     /** returns true if the SmartTag consumes this event. */
59     virtual bool Command( const CommandEvent& rCEvt );
60 
61     /** returns true if this smart tag is currently selected */
isSelected() const62     bool isSelected() const { return mbSelected;}
63 
getView() const64     ::sd::View& getView() const { return mrView; }
65 
66 protected:
67     virtual sal_Int32 GetMarkablePointCount() const;
68     virtual sal_Int32 GetMarkedPointCount() const;
69     virtual bool MarkPoint(SdrHdl& rHdl, bool bUnmark);
70     virtual void CheckPossibilities();
71     virtual bool MarkPoints(const ::tools::Rectangle* pRect, bool bUnmark);
72 
73     virtual void addCustomHandles( SdrHdlList& rHandlerList );
74     virtual void select();
75     virtual void deselect();
76     virtual bool getContext( SdrViewContext& rContext );
77 
78     virtual void disposing() override;
79 
80     ::sd::View& mrView;
81     bool mbSelected;
82 
83 private:
84     SmartTag( const SmartTag& ) = delete;
85     SmartTag& operator=( const SmartTag& ) = delete;
86 };
87 
88 typedef rtl::Reference< SmartTag > SmartTagReference;
89 
90 /** class to administrate the available smart tags for a single view. */
91 class SmartTagSet
92 {
93     friend class SmartTag;
94 public:
95     explicit SmartTagSet( ::sd::View& rView );
96     ~SmartTagSet();
97 
98     /** selects the given smart tag and updates all handles */
99     void select( const SmartTagReference& xTag );
100 
101     /** deselects the current selected smart tag and updates all handles */
102     void deselect();
103 
104     /** returns the currently selected tag or an empty reference. */
getSelected() const105     const SmartTagReference& getSelected() const { return mxSelectedTag; }
106 
107     /** returns true if a SmartTag consumes this event. */
108     bool MouseButtonDown( const MouseEvent& );
109 
110     /** returns true if a SmartTag consumes this event. */
111     bool KeyInput( const KeyEvent& rKEvt );
112 
113     /** returns true if a SmartTag consumes this event. */
114     bool Command( const CommandEvent& rCEvt );
115 
116     /** disposes all smart tags and clears the set */
117     void Dispose();
118 
119     /** adds the handles from all smart tags to the given list */
120     void addCustomHandles( SdrHdlList& rHandlerList );
121 
122     /** returns true if the currently selected smart tag has
123         a special context, returned in rContext. */
124     bool getContext( SdrViewContext& rContext ) const;
125 
126     // support point editing
127     bool HasMarkablePoints() const;
128     sal_uLong GetMarkablePointCount() const;
129     bool HasMarkedPoints() const;
130     sal_uLong GetMarkedPointCount() const;
131     bool MarkPoint(SdrHdl& rHdl, bool bUnmark);
132     bool MarkPoints(const ::tools::Rectangle* pRect, bool bUnmark);
133 
134     void CheckPossibilities();
135 
136 private:
137     SmartTagSet( const SmartTagSet& ) = delete;
138     SmartTagSet& operator=( const SmartTagSet& ) = delete;
139 
140     /** adds a new smart tag to this set */
141     void add( const SmartTagReference& xTag );
142 
143     /** removes the given smart tag from this set */
144     void remove( const SmartTagReference& xTag );
145 
146      std::set< SmartTagReference > maSet;
147 
148     ::sd::View& mrView;
149     SmartTagReference mxSelectedTag;
150     SmartTagReference mxMouseOverTag;
151 };
152 
153 /** a derivation from this handle is the visual representation for a smart tag.
154     One smart tag can have more than one handle.
155 */
156 class SmartHdl : public SdrHdl
157 {
158 public:
159     SmartHdl( const SmartTagReference& xTag, SdrObject* pObject, const Point& rPnt, SdrHdlKind eNewKind );
160     SmartHdl( const SmartTagReference& xTag, const Point& rPnt, SdrHdlKind eNewKind );
161 
getTag() const162     const SmartTagReference& getTag() const { return mxSmartTag; }
163 private:
164     SmartTagReference const mxSmartTag;
165 };
166 
167 } // end of namespace sd
168 
169 #endif // INCLUDED_SD_SOURCE_UI_INC_SMARTTAG_HXX
170 
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
172