xref: /aoo42x/main/svx/inc/svx/svdmark.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SVDMARK_HXX
29 #define _SVDMARK_HXX
30 
31 #include <tools/contnr.hxx>
32 #include <tools/string.hxx>
33 #include <tools/list.hxx>
34 #include "svx/svxdllapi.h"
35 #include <svx/sdrobjectuser.hxx>
36 
37 #include <set>
38 
39 class Rectangle;
40 class SdrPage;
41 class SdrObjList;
42 class SdrObject;
43 class SdrPageView;
44 
45 // Ein Container fuer USHORTs (im Prinzip ein dynamisches Array)
46 class SVX_DLLPUBLIC SdrUShortCont
47 {
48 	Container											maArray;
49 	sal_Bool											mbSorted;
50 
51 private:
52 	void CheckSort(sal_uLong nPos);
53 
54 public:
55 	SdrUShortCont(sal_uInt16 nBlock, sal_uInt16 nInit, sal_uInt16 nResize)
56 	:	maArray(nBlock, nInit, nResize),
57 	mbSorted(sal_True)
58 	{}
59 
60 	SdrUShortCont(const SdrUShortCont& rCont)
61 	:	maArray(rCont.maArray),
62 		mbSorted(rCont.mbSorted)
63 	{}
64 
65 	/** helper to migrate to stl containers */
66 	std::set< sal_uInt16 > getContainer();
67 
68 	SdrUShortCont& operator=(const SdrUShortCont& rCont)
69 	{
70 		maArray = rCont.maArray;
71 		mbSorted = rCont.mbSorted;
72 		return *this;
73 	}
74 
75 	sal_Bool operator==(const SdrUShortCont& rCont) const
76 	{
77 		return maArray == rCont.maArray;
78 	}
79 
80 	sal_Bool operator!=(const SdrUShortCont& rCont) const
81 	{
82 		return maArray != rCont.maArray;
83 	}
84 
85 	void Clear()
86 	{
87 		maArray.Clear();
88 		mbSorted = sal_True;
89 	}
90 
91 	void Sort() const;
92 
93 	void ForceSort() const
94 	{
95 		if(!mbSorted)
96 		{
97 			Sort();
98 		}
99 	}
100 
101 	void Insert(sal_uInt16 nElem, sal_uLong nPos = CONTAINER_APPEND)
102 	{
103 		maArray.Insert((void*)sal_uLong(nElem),nPos);
104 
105 		if(mbSorted)
106 		{
107 			CheckSort(nPos);
108 		}
109 	}
110 
111 	void Remove(sal_uLong nPos)
112 	{
113 		maArray.Remove(nPos);
114 	}
115 
116 	void Replace(sal_uInt16 nElem, sal_uLong nPos)
117 	{
118 		maArray.Replace((void*)sal_uLong(nElem), nPos);
119 
120 		if(mbSorted)
121 		{
122 			CheckSort(nPos);
123 		}
124 	}
125 
126 	sal_uInt16 GetObject(sal_uLong nPos) const
127 	{
128 		return sal_uInt16(sal_uIntPtr(maArray.GetObject(nPos)));
129 	}
130 
131 	sal_uLong GetPos(sal_uInt16 nElem) const
132 	{
133 		return maArray.GetPos((void*)(sal_uLong)nElem);
134 	}
135 
136 	sal_uLong GetCount() const
137 	{
138 		return maArray.Count();
139 	}
140 
141 	sal_Bool Exist(sal_uInt16 nElem) const
142 	{
143 		return (CONTAINER_ENTRY_NOTFOUND != maArray.GetPos((void*)(sal_uLong)nElem));
144 	}
145 };
146 
147 // Alles was eine View ueber ein markiertes Objekt wissen muss
148 class SVX_DLLPUBLIC SdrMark : public sdr::ObjectUser
149 {
150 protected:
151 	SdrObject*											mpSelectedSdrObject;	// the seleceted object
152 	SdrPageView*										mpPageView;
153 	SdrUShortCont*										mpPoints;     // Markierte Punkte
154 	SdrUShortCont*										mpLines;      // Markierte Linienabschnitte
155 	SdrUShortCont*										mpGluePoints; // Markierte Klebepunkte (deren Id's)
156 	sal_Bool											mbCon1;       // fuer Connectoren
157 	sal_Bool											mbCon2;       // fuer Connectoren
158 	sal_uInt16											mnUser;       // z.B. fuer CopyObjects, mitkopieren von Edges
159 
160 public:
161 	SdrMark(SdrObject* pNewObj = 0L, SdrPageView* pNewPageView = 0L);
162 	SdrMark(const SdrMark& rMark);
163 	virtual ~SdrMark();
164 
165 	// derived from ObjectUser
166 	virtual void ObjectInDestruction(const SdrObject& rObject);
167 
168 	SdrMark& operator=(const SdrMark& rMark);
169 	sal_Bool operator==(const SdrMark& rMark) const;
170 	sal_Bool operator!=(const SdrMark& rMark) const
171 	{
172 		return !(operator==(rMark));
173 	}
174 
175 	void SetMarkedSdrObj(SdrObject* pNewObj);
176 	SdrObject* GetMarkedSdrObj() const;
177 
178 	SdrPage* GetPage() const;
179 	SdrObjList* GetObjList() const;
180 	SdrPageView* GetPageView() const
181 	{
182 		return mpPageView;
183 	}
184 
185 	void SetPageView(SdrPageView* pNewPageView)
186 	{
187 		mpPageView = pNewPageView;
188 	}
189 
190 	void SetCon1(sal_Bool bOn)
191 	{
192 		mbCon1 = bOn;
193 	}
194 
195 	sal_Bool IsCon1() const
196 	{
197 		return mbCon1;
198 	}
199 
200 	void SetCon2(sal_Bool bOn)
201 	{
202 		mbCon2 = bOn;
203 	}
204 
205 	sal_Bool IsCon2() const
206 	{
207 		return mbCon2;
208 	}
209 
210 	void SetUser(sal_uInt16 nVal)
211 	{
212 		mnUser = nVal;
213 	}
214 
215 	sal_uInt16 GetUser() const
216 	{
217 		return mnUser;
218 	}
219 
220 	const SdrUShortCont* GetMarkedPoints() const
221 	{
222 		return mpPoints;
223 	}
224 
225 	const SdrUShortCont* GetMarkedLines() const
226 	{
227 		return mpLines;
228 	}
229 
230 	const SdrUShortCont* GetMarkedGluePoints() const
231 	{
232 		return mpGluePoints;
233 	}
234 
235 	SdrUShortCont* GetMarkedPoints()
236 	{
237 		return mpPoints;
238 	}
239 
240 	SdrUShortCont* GetMarkedLines()
241 	{
242 		return mpLines;
243 	}
244 
245 	SdrUShortCont* GetMarkedGluePoints()
246 	{
247 		return mpGluePoints;
248 	}
249 
250 	SdrUShortCont* ForceMarkedPoints()
251 	{
252 		if(!mpPoints)
253 			mpPoints = new SdrUShortCont(1024, 32, 32);
254 
255 		return mpPoints;
256 	}
257 
258 	SdrUShortCont* ForceMarkedLines()
259 	{
260 		if(!mpLines)
261 			mpLines = new SdrUShortCont(1024, 32, 32);
262 
263 		return mpLines;
264 	}
265 
266 	SdrUShortCont* ForceMarkedGluePoints()
267 	{
268 		if(!mpGluePoints)
269 			mpGluePoints = new SdrUShortCont(1024, 32, 32);
270 
271 		return mpGluePoints;
272 	}
273 };
274 
275 class SVX_DLLPUBLIC SdrMarkList
276 {
277 protected:
278 	Container											maList;
279 
280 	String												maMarkName;
281 	String												maPointName;
282 	String												maGluePointName;
283 
284 	sal_Bool											mbPointNameOk;
285 	sal_Bool											mbGluePointNameOk;
286 	sal_Bool											mbNameOk;
287 	sal_Bool											mbSorted;
288 
289 private:
290 	SVX_DLLPRIVATE sal_Bool operator==(const SdrMarkList& rCmpMarkList) const;
291 	SVX_DLLPRIVATE void ImpForceSort();
292 
293 private:
294 	SVX_DLLPRIVATE const XubString& GetPointMarkDescription(sal_Bool bGlue) const;
295 
296 public:
297 	SdrMarkList()
298 	:	maList(1024, 64, 64),
299 		mbPointNameOk(sal_False),
300 		mbGluePointNameOk(sal_False),
301 		mbNameOk(sal_False),
302 		mbSorted(sal_True)
303 	{
304 	}
305 
306 	SdrMarkList(const SdrMarkList& rLst)
307 	:	maList(1024, 64, 64)
308 	{
309 		*this = rLst;
310 	}
311 
312 	~SdrMarkList()
313 	{
314 		Clear();
315 	}
316 
317 	void Clear();
318 	void ForceSort() const;
319 	void SetUnsorted()
320 	{
321 		mbSorted = sal_False;
322 	}
323 
324 	sal_uLong GetMarkCount() const
325 	{
326 		return maList.Count();
327 	}
328 
329 	SdrMark* GetMark(sal_uLong nNum) const
330 	{
331 		return (SdrMark*)(maList.GetObject(nNum));
332 	}
333 
334 	sal_uLong FindObject(const SdrObject* pObj) const;
335 	void InsertEntry(const SdrMark& rMark, sal_Bool bChkSort = sal_True);
336 	void DeleteMark(sal_uLong nNum);
337 	void ReplaceMark(const SdrMark& rNewMark, sal_uLong nNum);
338 	void Merge(const SdrMarkList& rSrcList, sal_Bool bReverse = sal_False);
339 	sal_Bool DeletePageView(const SdrPageView& rPV);
340 	sal_Bool InsertPageView(const SdrPageView& rPV);
341 
342 	void SetNameDirty()
343 	{
344 		mbNameOk = sal_False;
345 		mbPointNameOk = sal_False;
346 		mbGluePointNameOk = sal_False;
347 	}
348 
349 	// Eine verbale Beschreibung der markierten Objekte z.B.:
350 	// "27 Linien", "12 Objekte", "Polygon" oder auch "Kein Objekt"
351 	const String& GetMarkDescription() const;
352 	const String& GetPointMarkDescription() const
353 	{
354 		return GetPointMarkDescription(sal_False);
355 	}
356 
357 	const String& GetGluePointMarkDescription() const
358 	{
359 		return GetPointMarkDescription(sal_True);
360 	}
361 
362 	// pPage=0L: Die Markierungen aller! Seiten beruecksichtigen
363 	sal_Bool TakeBoundRect(SdrPageView* pPageView, Rectangle& rRect) const;
364 	sal_Bool TakeSnapRect(SdrPageView* pPageView, Rectangle& rRect) const;
365 
366 	// Es werden saemtliche Entries kopiert!
367 	void operator=(const SdrMarkList& rLst);
368 };
369 
370 ////////////////////////////////////////////////////////////////////////////////////////////////////
371 // migrate selections
372 
373 namespace sdr
374 {
375 	class SVX_DLLPUBLIC ViewSelection
376 	{
377 		SdrMarkList					maMarkedObjectList;
378 		SdrMarkList					maEdgesOfMarkedNodes;
379 		SdrMarkList					maMarkedEdgesOfMarkedNodes;
380 		List						maAllMarkedObjects;
381 
382 		// bitfield
383 		unsigned					mbEdgesOfMarkedNodesDirty : 1;
384 
385 		SVX_DLLPRIVATE void ImpForceEdgesOfMarkedNodes();
386 		SVX_DLLPRIVATE void ImplCollectCompleteSelection(SdrObject* pObj);
387 
388 	public:
389 		ViewSelection();
390 
391 		void SetEdgesOfMarkedNodesDirty();
392 
393 		const SdrMarkList& GetMarkedObjectList() const
394 		{
395 			return maMarkedObjectList;
396 		}
397 
398 		const SdrMarkList& GetEdgesOfMarkedNodes() const;
399 		const SdrMarkList& GetMarkedEdgesOfMarkedNodes() const;
400 		const List& GetAllMarkedObjects() const;
401 
402 		SdrMarkList& GetMarkedObjectListWriteAccess()
403 		{
404 			return maMarkedObjectList;
405 		}
406 	};
407 } // end of namespace sdr
408 
409 ////////////////////////////////////////////////////////////////////////////////////////////////////
410 
411 #endif //_SVDMARK_HXX
412 // eof
413