xref: /aoo4110/main/sd/source/ui/inc/smarttag.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SD_SMARTTAG_HXX_
25 #define _SD_SMARTTAG_HXX_
26 
27 #include "helper/simplereferencecomponent.hxx"
28 #include <rtl/ref.hxx>
29 #include <set>
30 #include <svx/svdhdl.hxx>
31 #include <svx/svdview.hxx>
32 
33 class KeyEvent;
34 class MouseEvent;
35 class SdrHdlList;
36 
37 namespace sd {
38 
39 class View;
40 class SmartHdl;
41 
42 /** a smart tag represents a visual user interface element on the documents edit view
43 	that is not part of the document. It uses derivations from SmartHdl for its visuals.
44 	A SmartTag adds himself to the given view if created. It removes himself if it
45 	is disposed before the view is disposed.
46 
47 	Derive from this class to implement your own smart tag.
48 */
49 class SmartTag : public SimpleReferenceComponent
50 {
51 	friend class SmartTagSet;
52 
53 public:
54 	explicit SmartTag( ::sd::View& rView );
55 	virtual ~SmartTag();
56 
57 	/** returns true if the SmartTag consumes this event. */
58 	virtual bool MouseButtonDown( const MouseEvent&, SmartHdl& );
59 
60 	/** returns true if the SmartTag consumes this event. */
61 	virtual bool KeyInput( const KeyEvent& rKEvt );
62 
63 	/** returns true if the SmartTag consumes this event. */
64     virtual bool RequestHelp( const HelpEvent& rHEvt );
65 
66 	/** returns true if the SmartTag consumes this event. */
67     virtual bool Command( const CommandEvent& rCEvt );
68 
69 	/** returns true if this smart tag is currently selected */
70 	bool isSelected() const;
71 
getView() const72 	::sd::View& getView() const { return mrView; }
73 
74 protected:
75 	virtual sal_uLong GetMarkablePointCount() const;
76 	virtual sal_uLong GetMarkedPointCount() const;
77 	virtual sal_Bool MarkPoint(SdrHdl& rHdl, sal_Bool bUnmark=sal_False);
78 	virtual void CheckPossibilities();
79 	virtual sal_Bool MarkPoints(const Rectangle* pRect, sal_Bool bUnmark);
80 
81 	virtual void addCustomHandles( SdrHdlList& rHandlerList );
82 	virtual void select();
83 	virtual void deselect();
84 	virtual bool getContext( SdrViewContext& rContext );
85 
86 	virtual void disposing();
87 
88 	::sd::View& mrView;
89 	bool mbSelected;
90 
91 private:
92 	SmartTag( const SmartTag& );				// not implemented
93 	SmartTag& operator=( const SmartTag& );	// not implemented
94 };
95 
96 typedef rtl::Reference< SmartTag > SmartTagReference;
97 
98 /** class to administrate the available smart tags for a single view. */
99 class SmartTagSet
100 {
101 	friend class SmartTag;
102 public:
103 	explicit SmartTagSet( ::sd::View& rView );
104 	~SmartTagSet();
105 
106 	/** selects the given smart tag and updates all handles */
107 	void select( const SmartTagReference& xTag );
108 
109 	/** deselects the current selected smart tag and updates all handles */
110 	void deselect();
111 
112 	/** returns the currently selected tag or an empty reference. */
getSelected() const113 	const SmartTagReference& getSelected() const { return mxSelectedTag; }
114 
115 	/** returns true if a SmartTag consumes this event. */
116 	bool MouseButtonDown( const MouseEvent& );
117 
118 	/** returns true if a SmartTag consumes this event. */
119 	bool KeyInput( const KeyEvent& rKEvt );
120 
121 	/** returns true if a SmartTag consumes this event. */
122     bool RequestHelp( const HelpEvent& rHEvt );
123 
124 	/** returns true if a SmartTag consumes this event. */
125     bool Command( const CommandEvent& rCEvt );
126 
127 	/** disposes all smart tags and clears the set */
128 	void Dispose();
129 
130 	/** addes the handles from all smart tags to the given list */
131 	void addCustomHandles( SdrHdlList& rHandlerList );
132 
133 	/** returns true if the currently selected smart tag has
134 		a special context, returned in rContext. */
135 	bool getContext( SdrViewContext& rContext ) const;
136 
137 	// support point editing
138 	sal_Bool HasMarkablePoints() const;
139 	sal_uLong GetMarkablePointCount() const;
140 	sal_Bool HasMarkedPoints() const;
141 	sal_uLong GetMarkedPointCount() const;
142 	sal_Bool IsPointMarkable(const SdrHdl& rHdl) const;
143 	sal_Bool MarkPoint(SdrHdl& rHdl, sal_Bool bUnmark=sal_False);
144 	sal_Bool MarkPoints(const Rectangle* pRect, sal_Bool bUnmark);
145 
146 	void CheckPossibilities();
147 
148 private:
149 	SmartTagSet( const SmartTagSet& );				// not implemented
150 	SmartTagSet& operator=( const SmartTagSet& );	// not implemented
151 
152 	/** adds a new smart tag to this set */
153 	void add( const SmartTagReference& xTag );
154 
155 	/** removes the given smart tag from this set */
156 	void remove( const SmartTagReference& xTag );
157 
158 	 std::set< SmartTagReference > maSet;
159 
160 	::sd::View& mrView;
161 	SmartTagReference mxSelectedTag;
162 	SmartTagReference mxMouseOverTag;
163 };
164 
165 /** a derivation from this handle is the visual representation for a smart tag.
166 	One smart tag can have more than one handle.
167 */
168 class SmartHdl : public SdrHdl
169 {
170 public:
171 	SmartHdl( const SmartTagReference& xTag, SdrObject* pObject, const Point& rPnt, SdrHdlKind eNewKind=HDL_SMARTTAG );
172 	SmartHdl( const SmartTagReference& xTag, const Point& rPnt, SdrHdlKind eNewKind=HDL_SMARTTAG );
173 
getTag() const174 	const SmartTagReference& getTag() const { return mxTag; }
175 
176 	virtual bool isMarkable() const;
177 protected:
178 	SmartTagReference mxTag;
179 };
180 
181 } // end of namespace sd
182 
183 #endif		// _SD_SMARTTAG_HXX_
184 
185