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