xref: /aoo4110/main/svx/inc/svx/svdmark.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 _SVDMARK_HXX
25 #define _SVDMARK_HXX
26 
27 #include <tools/contnr.hxx>
28 #include <tools/string.hxx>
29 #include <tools/list.hxx>
30 #include "svx/svxdllapi.h"
31 #include <svx/sdrobjectuser.hxx>
32 
33 #include <set>
34 
35 class Rectangle;
36 class SdrPage;
37 class SdrObjList;
38 class SdrObject;
39 class SdrPageView;
40 
41 // Ein Container fuer USHORTs (im Prinzip ein dynamisches Array)
42 class SVX_DLLPUBLIC SdrUShortCont
43 {
44 	Container											maArray;
45 	sal_Bool											mbSorted;
46 
47 private:
48 	void CheckSort(sal_uLong nPos);
49 
50 public:
SdrUShortCont(sal_uInt16 nBlock,sal_uInt16 nInit,sal_uInt16 nResize)51 	SdrUShortCont(sal_uInt16 nBlock, sal_uInt16 nInit, sal_uInt16 nResize)
52 	:	maArray(nBlock, nInit, nResize),
53 	mbSorted(sal_True)
54 	{}
55 
SdrUShortCont(const SdrUShortCont & rCont)56 	SdrUShortCont(const SdrUShortCont& rCont)
57 	:	maArray(rCont.maArray),
58 		mbSorted(rCont.mbSorted)
59 	{}
60 
61 	/** helper to migrate to stl containers */
62 	std::set< sal_uInt16 > getContainer();
63 
operator =(const SdrUShortCont & rCont)64 	SdrUShortCont& operator=(const SdrUShortCont& rCont)
65 	{
66 		maArray = rCont.maArray;
67 		mbSorted = rCont.mbSorted;
68 		return *this;
69 	}
70 
operator ==(const SdrUShortCont & rCont) const71 	sal_Bool operator==(const SdrUShortCont& rCont) const
72 	{
73 		return maArray == rCont.maArray;
74 	}
75 
operator !=(const SdrUShortCont & rCont) const76 	sal_Bool operator!=(const SdrUShortCont& rCont) const
77 	{
78 		return maArray != rCont.maArray;
79 	}
80 
Clear()81 	void Clear()
82 	{
83 		maArray.Clear();
84 		mbSorted = sal_True;
85 	}
86 
87 	void Sort() const;
88 
ForceSort() const89 	void ForceSort() const
90 	{
91 		if(!mbSorted)
92 		{
93 			Sort();
94 		}
95 	}
96 
Insert(sal_uInt16 nElem,sal_uLong nPos=CONTAINER_APPEND)97 	void Insert(sal_uInt16 nElem, sal_uLong nPos = CONTAINER_APPEND)
98 	{
99 		maArray.Insert((void*)sal_uLong(nElem),nPos);
100 
101 		if(mbSorted)
102 		{
103 			CheckSort(nPos);
104 		}
105 	}
106 
Remove(sal_uLong nPos)107 	void Remove(sal_uLong nPos)
108 	{
109 		maArray.Remove(nPos);
110 	}
111 
Replace(sal_uInt16 nElem,sal_uLong nPos)112 	void Replace(sal_uInt16 nElem, sal_uLong nPos)
113 	{
114 		maArray.Replace((void*)sal_uLong(nElem), nPos);
115 
116 		if(mbSorted)
117 		{
118 			CheckSort(nPos);
119 		}
120 	}
121 
GetObject(sal_uLong nPos) const122 	sal_uInt16 GetObject(sal_uLong nPos) const
123 	{
124 		return sal_uInt16(sal_uIntPtr(maArray.GetObject(nPos)));
125 	}
126 
GetPos(sal_uInt16 nElem) const127 	sal_uLong GetPos(sal_uInt16 nElem) const
128 	{
129 		return maArray.GetPos((void*)(sal_uLong)nElem);
130 	}
131 
GetCount() const132 	sal_uLong GetCount() const
133 	{
134 		return maArray.Count();
135 	}
136 
Exist(sal_uInt16 nElem) const137 	sal_Bool Exist(sal_uInt16 nElem) const
138 	{
139 		return (CONTAINER_ENTRY_NOTFOUND != maArray.GetPos((void*)(sal_uLong)nElem));
140 	}
141 };
142 
143 // Alles was eine View ueber ein markiertes Objekt wissen muss
144 class SVX_DLLPUBLIC SdrMark : public sdr::ObjectUser
145 {
146 protected:
147 	SdrObject*											mpSelectedSdrObject;	// the seleceted object
148 	SdrPageView*										mpPageView;
149 	SdrUShortCont*										mpPoints;     // Markierte Punkte
150 	SdrUShortCont*										mpLines;      // Markierte Linienabschnitte
151 	SdrUShortCont*										mpGluePoints; // Markierte Klebepunkte (deren Id's)
152 	sal_Bool											mbCon1;       // fuer Connectoren
153 	sal_Bool											mbCon2;       // fuer Connectoren
154 	sal_uInt16											mnUser;       // z.B. fuer CopyObjects, mitkopieren von Edges
155 
156 public:
157 	SdrMark(SdrObject* pNewObj = 0L, SdrPageView* pNewPageView = 0L);
158 	SdrMark(const SdrMark& rMark);
159 	virtual ~SdrMark();
160 
161 	// derived from ObjectUser
162 	virtual void ObjectInDestruction(const SdrObject& rObject);
163 
164 	SdrMark& operator=(const SdrMark& rMark);
165 	sal_Bool operator==(const SdrMark& rMark) const;
operator !=(const SdrMark & rMark) const166 	sal_Bool operator!=(const SdrMark& rMark) const
167 	{
168 		return !(operator==(rMark));
169 	}
170 
171 	void SetMarkedSdrObj(SdrObject* pNewObj);
172 	SdrObject* GetMarkedSdrObj() const;
173 
174 	SdrPage* GetPage() const;
175 	SdrObjList* GetObjList() const;
GetPageView() const176 	SdrPageView* GetPageView() const
177 	{
178 		return mpPageView;
179 	}
180 
SetPageView(SdrPageView * pNewPageView)181 	void SetPageView(SdrPageView* pNewPageView)
182 	{
183 		mpPageView = pNewPageView;
184 	}
185 
SetCon1(sal_Bool bOn)186 	void SetCon1(sal_Bool bOn)
187 	{
188 		mbCon1 = bOn;
189 	}
190 
IsCon1() const191 	sal_Bool IsCon1() const
192 	{
193 		return mbCon1;
194 	}
195 
SetCon2(sal_Bool bOn)196 	void SetCon2(sal_Bool bOn)
197 	{
198 		mbCon2 = bOn;
199 	}
200 
IsCon2() const201 	sal_Bool IsCon2() const
202 	{
203 		return mbCon2;
204 	}
205 
SetUser(sal_uInt16 nVal)206 	void SetUser(sal_uInt16 nVal)
207 	{
208 		mnUser = nVal;
209 	}
210 
GetUser() const211 	sal_uInt16 GetUser() const
212 	{
213 		return mnUser;
214 	}
215 
GetMarkedPoints() const216 	const SdrUShortCont* GetMarkedPoints() const
217 	{
218 		return mpPoints;
219 	}
220 
GetMarkedLines() const221 	const SdrUShortCont* GetMarkedLines() const
222 	{
223 		return mpLines;
224 	}
225 
GetMarkedGluePoints() const226 	const SdrUShortCont* GetMarkedGluePoints() const
227 	{
228 		return mpGluePoints;
229 	}
230 
GetMarkedPoints()231 	SdrUShortCont* GetMarkedPoints()
232 	{
233 		return mpPoints;
234 	}
235 
GetMarkedLines()236 	SdrUShortCont* GetMarkedLines()
237 	{
238 		return mpLines;
239 	}
240 
GetMarkedGluePoints()241 	SdrUShortCont* GetMarkedGluePoints()
242 	{
243 		return mpGluePoints;
244 	}
245 
ForceMarkedPoints()246 	SdrUShortCont* ForceMarkedPoints()
247 	{
248 		if(!mpPoints)
249 			mpPoints = new SdrUShortCont(1024, 32, 32);
250 
251 		return mpPoints;
252 	}
253 
ForceMarkedLines()254 	SdrUShortCont* ForceMarkedLines()
255 	{
256 		if(!mpLines)
257 			mpLines = new SdrUShortCont(1024, 32, 32);
258 
259 		return mpLines;
260 	}
261 
ForceMarkedGluePoints()262 	SdrUShortCont* ForceMarkedGluePoints()
263 	{
264 		if(!mpGluePoints)
265 			mpGluePoints = new SdrUShortCont(1024, 32, 32);
266 
267 		return mpGluePoints;
268 	}
269 };
270 
271 class SVX_DLLPUBLIC SdrMarkList
272 {
273 protected:
274 	Container											maList;
275 
276 	String												maMarkName;
277 	String												maPointName;
278 	String												maGluePointName;
279 
280 	sal_Bool											mbPointNameOk;
281 	sal_Bool											mbGluePointNameOk;
282 	sal_Bool											mbNameOk;
283 	sal_Bool											mbSorted;
284 
285 private:
286 	SVX_DLLPRIVATE sal_Bool operator==(const SdrMarkList& rCmpMarkList) const;
287 	SVX_DLLPRIVATE void ImpForceSort();
288 
289 private:
290 	SVX_DLLPRIVATE const XubString& GetPointMarkDescription(sal_Bool bGlue) const;
291 
292 public:
SdrMarkList()293 	SdrMarkList()
294 	:	maList(1024, 64, 64),
295 		mbPointNameOk(sal_False),
296 		mbGluePointNameOk(sal_False),
297 		mbNameOk(sal_False),
298 		mbSorted(sal_True)
299 	{
300 	}
301 
SdrMarkList(const SdrMarkList & rLst)302 	SdrMarkList(const SdrMarkList& rLst)
303 	:	maList(1024, 64, 64)
304 	{
305 		*this = rLst;
306 	}
307 
~SdrMarkList()308 	~SdrMarkList()
309 	{
310 		Clear();
311 	}
312 
313 	void Clear();
314 	void ForceSort() const;
SetUnsorted()315 	void SetUnsorted()
316 	{
317 		mbSorted = sal_False;
318 	}
319 
GetMarkCount() const320 	sal_uLong GetMarkCount() const
321 	{
322 		return maList.Count();
323 	}
324 
GetMark(sal_uLong nNum) const325 	SdrMark* GetMark(sal_uLong nNum) const
326 	{
327 		return (SdrMark*)(maList.GetObject(nNum));
328 	}
329 
330 	sal_uLong FindObject(const SdrObject* pObj) const;
331 	void InsertEntry(const SdrMark& rMark, sal_Bool bChkSort = sal_True);
332 	void DeleteMark(sal_uLong nNum);
333 	void ReplaceMark(const SdrMark& rNewMark, sal_uLong nNum);
334 	void Merge(const SdrMarkList& rSrcList, sal_Bool bReverse = sal_False);
335 	sal_Bool DeletePageView(const SdrPageView& rPV);
336 	sal_Bool InsertPageView(const SdrPageView& rPV);
337 
SetNameDirty()338 	void SetNameDirty()
339 	{
340 		mbNameOk = sal_False;
341 		mbPointNameOk = sal_False;
342 		mbGluePointNameOk = sal_False;
343 	}
344 
345 	// Eine verbale Beschreibung der markierten Objekte z.B.:
346 	// "27 Linien", "12 Objekte", "Polygon" oder auch "Kein Objekt"
347 	const String& GetMarkDescription() const;
GetPointMarkDescription() const348 	const String& GetPointMarkDescription() const
349 	{
350 		return GetPointMarkDescription(sal_False);
351 	}
352 
GetGluePointMarkDescription() const353 	const String& GetGluePointMarkDescription() const
354 	{
355 		return GetPointMarkDescription(sal_True);
356 	}
357 
358 	// pPage=0L: Die Markierungen aller! Seiten beruecksichtigen
359 	sal_Bool TakeBoundRect(SdrPageView* pPageView, Rectangle& rRect) const;
360 	sal_Bool TakeSnapRect(SdrPageView* pPageView, Rectangle& rRect) const;
361 
362 	// Es werden saemtliche Entries kopiert!
363 	void operator=(const SdrMarkList& rLst);
364 };
365 
366 ////////////////////////////////////////////////////////////////////////////////////////////////////
367 // migrate selections
368 
369 namespace sdr
370 {
371 	class SVX_DLLPUBLIC ViewSelection
372 	{
373 		SdrMarkList					maMarkedObjectList;
374 		SdrMarkList					maEdgesOfMarkedNodes;
375 		SdrMarkList					maMarkedEdgesOfMarkedNodes;
376 		List						maAllMarkedObjects;
377 
378 		// bitfield
379 		unsigned					mbEdgesOfMarkedNodesDirty : 1;
380 
381 		SVX_DLLPRIVATE void ImpForceEdgesOfMarkedNodes();
382 		SVX_DLLPRIVATE void ImplCollectCompleteSelection(SdrObject* pObj);
383 
384 	public:
385 		ViewSelection();
386 
387 		void SetEdgesOfMarkedNodesDirty();
388 
GetMarkedObjectList() const389 		const SdrMarkList& GetMarkedObjectList() const
390 		{
391 			return maMarkedObjectList;
392 		}
393 
394 		const SdrMarkList& GetEdgesOfMarkedNodes() const;
395 		const SdrMarkList& GetMarkedEdgesOfMarkedNodes() const;
396 		const List& GetAllMarkedObjects() const;
397 
GetMarkedObjectListWriteAccess()398 		SdrMarkList& GetMarkedObjectListWriteAccess()
399 		{
400 			return maMarkedObjectList;
401 		}
402 	};
403 } // end of namespace sdr
404 
405 ////////////////////////////////////////////////////////////////////////////////////////////////////
406 
407 #endif //_SVDMARK_HXX
408 // eof
409