xref: /aoo41x/main/svtools/source/contnr/imivctl2.cxx (revision 5900e8ec)
1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5900e8ecSAndrew Rist  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5900e8ecSAndrew Rist  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19*5900e8ecSAndrew Rist  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir #include "imivctl.hxx"
27cdf0e10cSrcweir 
IcnCursor_Impl(SvxIconChoiceCtrl_Impl * pOwner)28cdf0e10cSrcweir IcnCursor_Impl::IcnCursor_Impl( SvxIconChoiceCtrl_Impl* pOwner )
29cdf0e10cSrcweir {
30cdf0e10cSrcweir 	pView 		= pOwner;
31cdf0e10cSrcweir 	pColumns	= 0;
32cdf0e10cSrcweir 	pRows 		= 0;
33cdf0e10cSrcweir 	pCurEntry 	= 0;
34cdf0e10cSrcweir 	nDeltaWidth = 0;
35cdf0e10cSrcweir 	nDeltaHeight= 0;
36cdf0e10cSrcweir 	nCols		= 0;
37cdf0e10cSrcweir 	nRows		= 0;
38cdf0e10cSrcweir }
39cdf0e10cSrcweir 
~IcnCursor_Impl()40cdf0e10cSrcweir IcnCursor_Impl::~IcnCursor_Impl()
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 	delete[] pColumns;
43cdf0e10cSrcweir 	delete[] pRows;
44cdf0e10cSrcweir }
45cdf0e10cSrcweir 
GetSortListPos(SvPtrarr * pList,long nValue,int bVertical)46cdf0e10cSrcweir sal_uInt16 IcnCursor_Impl::GetSortListPos( SvPtrarr* pList, long nValue,
47cdf0e10cSrcweir 	int bVertical )
48cdf0e10cSrcweir {
49cdf0e10cSrcweir 	sal_uInt16 nCount = (sal_uInt16)pList->Count();
50cdf0e10cSrcweir 	if( !nCount )
51cdf0e10cSrcweir 		return 0;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 	sal_uInt16 nCurPos = 0;
54cdf0e10cSrcweir 	long nPrevValue = LONG_MIN;
55cdf0e10cSrcweir 	while( nCount )
56cdf0e10cSrcweir 	{
57cdf0e10cSrcweir 		const Rectangle& rRect=
58cdf0e10cSrcweir 			pView->GetEntryBoundRect((SvxIconChoiceCtrlEntry*)(pList->GetObject(nCurPos)));
59cdf0e10cSrcweir 		long nCurValue;
60cdf0e10cSrcweir 		if( bVertical )
61cdf0e10cSrcweir 			nCurValue = rRect.Top();
62cdf0e10cSrcweir 		else
63cdf0e10cSrcweir 			nCurValue = rRect.Left();
64cdf0e10cSrcweir 		if( nValue >= nPrevValue && nValue <= nCurValue )
65cdf0e10cSrcweir 			return (sal_uInt16)nCurPos;
66cdf0e10cSrcweir 		nPrevValue = nCurValue;
67cdf0e10cSrcweir 		nCount--;
68cdf0e10cSrcweir 		nCurPos++;
69cdf0e10cSrcweir 	}
70cdf0e10cSrcweir 	return pList->Count();
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
ImplCreate()73cdf0e10cSrcweir void IcnCursor_Impl::ImplCreate()
74cdf0e10cSrcweir {
75cdf0e10cSrcweir 	pView->CheckBoundingRects();
76cdf0e10cSrcweir 	DBG_ASSERT(pColumns==0&&pRows==0,"ImplCreate: Not cleared");
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	SetDeltas();
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	pColumns = new SvPtrarr[ nCols ];
81cdf0e10cSrcweir 	pRows = new SvPtrarr[ nRows ];
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	sal_uLong nCount = pView->aEntries.Count();
84cdf0e10cSrcweir 	for( sal_uLong nCur = 0; nCur < nCount; nCur++ )
85cdf0e10cSrcweir 	{
86cdf0e10cSrcweir 		SvxIconChoiceCtrlEntry* pEntry = (SvxIconChoiceCtrlEntry*)pView->aEntries.GetObject( nCur );
87cdf0e10cSrcweir 		// const Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
88cdf0e10cSrcweir 		Rectangle rRect( pView->CalcBmpRect( pEntry,0 ) );
89cdf0e10cSrcweir 		short nY = (short)( ((rRect.Top()+rRect.Bottom())/2) / nDeltaHeight );
90cdf0e10cSrcweir 		short nX = (short)( ((rRect.Left()+rRect.Right())/2) / nDeltaWidth );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 		// Rundungsfehler abfangen
93cdf0e10cSrcweir 		if( nY >= nRows )
94cdf0e10cSrcweir 			nY = sal::static_int_cast< short >(nRows - 1);
95cdf0e10cSrcweir 		if( nX >= nCols )
96cdf0e10cSrcweir 			nX = sal::static_int_cast< short >(nCols - 1);
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 		sal_uInt16 nIns = GetSortListPos( &pColumns[nX], rRect.Top(), sal_True );
99cdf0e10cSrcweir 		pColumns[ nX ].Insert( pEntry, nIns );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 		nIns = GetSortListPos( &pRows[nY], rRect.Left(), sal_False );
102cdf0e10cSrcweir 		pRows[ nY ].Insert( pEntry, nIns );
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 		pEntry->nX = nX;
105cdf0e10cSrcweir 		pEntry->nY = nY;
106cdf0e10cSrcweir 	}
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 
Clear()112cdf0e10cSrcweir void IcnCursor_Impl::Clear()
113cdf0e10cSrcweir {
114cdf0e10cSrcweir 	if( pColumns )
115cdf0e10cSrcweir 	{
116cdf0e10cSrcweir 		delete[] pColumns;
117cdf0e10cSrcweir 		delete[] pRows;
118cdf0e10cSrcweir 		pColumns = 0;
119cdf0e10cSrcweir 		pRows = 0;
120cdf0e10cSrcweir 		pCurEntry = 0;
121cdf0e10cSrcweir 		nDeltaWidth = 0;
122cdf0e10cSrcweir 		nDeltaHeight = 0;
123cdf0e10cSrcweir 	}
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
SearchCol(sal_uInt16 nCol,sal_uInt16 nTop,sal_uInt16 nBottom,sal_uInt16,sal_Bool bDown,sal_Bool bSimple)126cdf0e10cSrcweir SvxIconChoiceCtrlEntry* IcnCursor_Impl::SearchCol(sal_uInt16 nCol,sal_uInt16 nTop,sal_uInt16 nBottom,
127cdf0e10cSrcweir 	sal_uInt16, sal_Bool bDown, sal_Bool bSimple  )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir 	DBG_ASSERT(pCurEntry,"SearchCol: No reference entry");
130cdf0e10cSrcweir 	SvPtrarr* pList = &(pColumns[ nCol ]);
131cdf0e10cSrcweir 	const sal_uInt16 nCount = pList->Count();
132cdf0e10cSrcweir 	if( !nCount )
133cdf0e10cSrcweir 		return 0;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	const Rectangle& rRefRect = pView->GetEntryBoundRect(pCurEntry);
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	if( bSimple )
138cdf0e10cSrcweir 	{
139cdf0e10cSrcweir 		sal_uInt16 nListPos = pList->GetPos( pCurEntry );
140cdf0e10cSrcweir 		DBG_ASSERT(nListPos!=0xffff,"Entry not in Col-List");
141cdf0e10cSrcweir 		if( bDown )
142cdf0e10cSrcweir 		{
143cdf0e10cSrcweir 			while( nListPos < nCount-1 )
144cdf0e10cSrcweir 			{
145cdf0e10cSrcweir 				nListPos++;
146cdf0e10cSrcweir 				SvxIconChoiceCtrlEntry* pEntry = (SvxIconChoiceCtrlEntry*)pList->GetObject( nListPos );
147cdf0e10cSrcweir 				const Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
148cdf0e10cSrcweir 				if( rRect.Top() > rRefRect.Top() )
149cdf0e10cSrcweir 					return pEntry;
150cdf0e10cSrcweir 			}
151cdf0e10cSrcweir 			return 0;
152cdf0e10cSrcweir 		}
153cdf0e10cSrcweir 		else
154cdf0e10cSrcweir 		{
155cdf0e10cSrcweir 			while( nListPos )
156cdf0e10cSrcweir 			{
157cdf0e10cSrcweir 				nListPos--;
158cdf0e10cSrcweir 				if( nListPos < nCount )
159cdf0e10cSrcweir 				{
160cdf0e10cSrcweir 					SvxIconChoiceCtrlEntry* pEntry = (SvxIconChoiceCtrlEntry*)pList->GetObject( nListPos );
161cdf0e10cSrcweir 					const Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
162cdf0e10cSrcweir 					if( rRect.Top() < rRefRect.Top() )
163cdf0e10cSrcweir 						return pEntry;
164cdf0e10cSrcweir 				}
165cdf0e10cSrcweir 			}
166cdf0e10cSrcweir 			return 0;
167cdf0e10cSrcweir 		}
168cdf0e10cSrcweir 	}
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 	if( nTop > nBottom )
171cdf0e10cSrcweir 	{
172cdf0e10cSrcweir 		sal_uInt16 nTemp = nTop;
173cdf0e10cSrcweir 		nTop = nBottom;
174cdf0e10cSrcweir 		nBottom = nTemp;
175cdf0e10cSrcweir 	}
176cdf0e10cSrcweir 	long nMinDistance = LONG_MAX;
177cdf0e10cSrcweir 	SvxIconChoiceCtrlEntry* pResult = 0;
178cdf0e10cSrcweir 	for( sal_uInt16 nCur = 0; nCur < nCount; nCur++ )
179cdf0e10cSrcweir 	{
180cdf0e10cSrcweir 		SvxIconChoiceCtrlEntry* pEntry = (SvxIconChoiceCtrlEntry*)(pList->GetObject( nCur ));
181cdf0e10cSrcweir 		if( pEntry != pCurEntry )
182cdf0e10cSrcweir 		{
183cdf0e10cSrcweir 			sal_uInt16 nY = pEntry->nY;
184cdf0e10cSrcweir 			if( nY >= nTop && nY <= nBottom )
185cdf0e10cSrcweir 			{
186cdf0e10cSrcweir 				const Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
187cdf0e10cSrcweir 				long nDistance = rRect.Top() - rRefRect.Top();
188cdf0e10cSrcweir 				if( nDistance < 0 )
189cdf0e10cSrcweir 					nDistance *= -1;
190cdf0e10cSrcweir 				if( nDistance && nDistance < nMinDistance )
191cdf0e10cSrcweir 				{
192cdf0e10cSrcweir 					nMinDistance = nDistance;
193cdf0e10cSrcweir 					pResult = pEntry;
194cdf0e10cSrcweir 				}
195cdf0e10cSrcweir 			}
196cdf0e10cSrcweir 		}
197cdf0e10cSrcweir 	}
198cdf0e10cSrcweir 	return pResult;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
SearchRow(sal_uInt16 nRow,sal_uInt16 nLeft,sal_uInt16 nRight,sal_uInt16,sal_Bool bRight,sal_Bool bSimple)201cdf0e10cSrcweir SvxIconChoiceCtrlEntry* IcnCursor_Impl::SearchRow(sal_uInt16 nRow,sal_uInt16 nLeft,sal_uInt16 nRight,
202cdf0e10cSrcweir 	sal_uInt16, sal_Bool bRight, sal_Bool bSimple )
203cdf0e10cSrcweir {
204cdf0e10cSrcweir 	DBG_ASSERT(pCurEntry,"SearchRow: No reference entry");
205cdf0e10cSrcweir 	SvPtrarr* pList = &(pRows[ nRow ]);
206cdf0e10cSrcweir 	const sal_uInt16 nCount = pList->Count();
207cdf0e10cSrcweir 	if( !nCount )
208cdf0e10cSrcweir 		return 0;
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 	const Rectangle& rRefRect = pView->GetEntryBoundRect(pCurEntry);
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 	if( bSimple )
213cdf0e10cSrcweir 	{
214cdf0e10cSrcweir 		sal_uInt16 nListPos = pList->GetPos( pCurEntry );
215cdf0e10cSrcweir 		DBG_ASSERT(nListPos!=0xffff,"Entry not in Row-List");
216cdf0e10cSrcweir 		if( bRight )
217cdf0e10cSrcweir 		{
218cdf0e10cSrcweir 			while( nListPos < nCount-1 )
219cdf0e10cSrcweir 			{
220cdf0e10cSrcweir 				nListPos++;
221cdf0e10cSrcweir 				SvxIconChoiceCtrlEntry* pEntry = (SvxIconChoiceCtrlEntry*)pList->GetObject( nListPos );
222cdf0e10cSrcweir 				const Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
223cdf0e10cSrcweir 				if( rRect.Left() > rRefRect.Left() )
224cdf0e10cSrcweir 					return pEntry;
225cdf0e10cSrcweir 			}
226cdf0e10cSrcweir 			return 0;
227cdf0e10cSrcweir 		}
228cdf0e10cSrcweir 		else
229cdf0e10cSrcweir 		{
230cdf0e10cSrcweir 			while( nListPos )
231cdf0e10cSrcweir 			{
232cdf0e10cSrcweir 				nListPos--;
233cdf0e10cSrcweir 				if( nListPos < nCount )
234cdf0e10cSrcweir 				{
235cdf0e10cSrcweir 					SvxIconChoiceCtrlEntry* pEntry = (SvxIconChoiceCtrlEntry*)pList->GetObject( nListPos );
236cdf0e10cSrcweir 					const Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
237cdf0e10cSrcweir 					if( rRect.Left() < rRefRect.Left() )
238cdf0e10cSrcweir 						return pEntry;
239cdf0e10cSrcweir 				}
240cdf0e10cSrcweir 			}
241cdf0e10cSrcweir 			return 0;
242cdf0e10cSrcweir 		}
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 	}
245cdf0e10cSrcweir 	if( nRight < nLeft )
246cdf0e10cSrcweir 	{
247cdf0e10cSrcweir 		sal_uInt16 nTemp = nRight;
248cdf0e10cSrcweir 		nRight = nLeft;
249cdf0e10cSrcweir 		nLeft = nTemp;
250cdf0e10cSrcweir 	}
251cdf0e10cSrcweir 	long nMinDistance = LONG_MAX;
252cdf0e10cSrcweir 	SvxIconChoiceCtrlEntry* pResult = 0;
253cdf0e10cSrcweir 	for( sal_uInt16 nCur = 0; nCur < nCount; nCur++ )
254cdf0e10cSrcweir 	{
255cdf0e10cSrcweir 		SvxIconChoiceCtrlEntry* pEntry = (SvxIconChoiceCtrlEntry*)(pList->GetObject( nCur ));
256cdf0e10cSrcweir 		if( pEntry != pCurEntry )
257cdf0e10cSrcweir 		{
258cdf0e10cSrcweir 			sal_uInt16 nX = pEntry->nX;
259cdf0e10cSrcweir 			if( nX >= nLeft && nX <= nRight )
260cdf0e10cSrcweir 			{
261cdf0e10cSrcweir 				const Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
262cdf0e10cSrcweir 				long nDistance = rRect.Left() - rRefRect.Left();
263cdf0e10cSrcweir 				if( nDistance < 0 )
264cdf0e10cSrcweir 					nDistance *= -1;
265cdf0e10cSrcweir 				if( nDistance && nDistance < nMinDistance )
266cdf0e10cSrcweir 				{
267cdf0e10cSrcweir 					nMinDistance = nDistance;
268cdf0e10cSrcweir 					pResult = pEntry;
269cdf0e10cSrcweir 				}
270cdf0e10cSrcweir 			}
271cdf0e10cSrcweir 		}
272cdf0e10cSrcweir 	}
273cdf0e10cSrcweir 	return pResult;
274cdf0e10cSrcweir }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 
278cdf0e10cSrcweir /*
279cdf0e10cSrcweir 	Sucht ab dem uebergebenen Eintrag den naechsten rechts- bzw.
280cdf0e10cSrcweir 	linksstehenden. Suchverfahren am Beispiel bRight = sal_True:
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 				  c
283cdf0e10cSrcweir 				b c
284cdf0e10cSrcweir 			  a b c
285cdf0e10cSrcweir 			S 1 1 1      ====> Suchrichtung
286cdf0e10cSrcweir 			  a b c
287cdf0e10cSrcweir 				b c
288cdf0e10cSrcweir 				  c
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 	S : Startposition
291cdf0e10cSrcweir 	1 : erstes Suchrechteck
292cdf0e10cSrcweir 	a,b,c : 2., 3., 4. Suchrechteck
293cdf0e10cSrcweir */
294cdf0e10cSrcweir 
GoLeftRight(SvxIconChoiceCtrlEntry * pCtrlEntry,sal_Bool bRight)295cdf0e10cSrcweir SvxIconChoiceCtrlEntry* IcnCursor_Impl::GoLeftRight( SvxIconChoiceCtrlEntry* pCtrlEntry, sal_Bool bRight )
296cdf0e10cSrcweir {
297cdf0e10cSrcweir 	SvxIconChoiceCtrlEntry* pResult;
298cdf0e10cSrcweir 	pCurEntry = pCtrlEntry;
299cdf0e10cSrcweir 	Create();
300cdf0e10cSrcweir 	sal_uInt16 nY = pCtrlEntry->nY;
301cdf0e10cSrcweir 	sal_uInt16 nX = pCtrlEntry->nX;
302cdf0e10cSrcweir 	DBG_ASSERT(nY< nRows,"GoLeftRight:Bad column");
303cdf0e10cSrcweir 	DBG_ASSERT(nX< nCols,"GoLeftRight:Bad row");
304cdf0e10cSrcweir 	// Nachbar auf gleicher Zeile ?
305cdf0e10cSrcweir 	if( bRight )
306cdf0e10cSrcweir 		pResult = SearchRow(
307cdf0e10cSrcweir             nY, nX, sal::static_int_cast< sal_uInt16 >(nCols-1), nX, sal_True, sal_True );
308cdf0e10cSrcweir 	else
309cdf0e10cSrcweir 		pResult = SearchRow( nY, nX ,0, nX, sal_False, sal_True );
310cdf0e10cSrcweir 	if( pResult )
311cdf0e10cSrcweir 		return pResult;
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 	long nCurCol = nX;
314cdf0e10cSrcweir 
315cdf0e10cSrcweir 	long nColOffs, nLastCol;
316cdf0e10cSrcweir 	if( bRight )
317cdf0e10cSrcweir 	{
318cdf0e10cSrcweir 		nColOffs = 1;
319cdf0e10cSrcweir 		nLastCol = nCols;
320cdf0e10cSrcweir 	}
321cdf0e10cSrcweir 	else
322cdf0e10cSrcweir 	{
323cdf0e10cSrcweir 		nColOffs = -1;
324cdf0e10cSrcweir 		nLastCol = -1;   // 0-1
325cdf0e10cSrcweir 	}
326cdf0e10cSrcweir 
327cdf0e10cSrcweir 	sal_uInt16 nRowMin = nY;
328cdf0e10cSrcweir 	sal_uInt16 nRowMax = nY;
329cdf0e10cSrcweir 	do
330cdf0e10cSrcweir 	{
331cdf0e10cSrcweir 		SvxIconChoiceCtrlEntry* pEntry = SearchCol((sal_uInt16)nCurCol,nRowMin,nRowMax,nY,sal_True, sal_False);
332cdf0e10cSrcweir 		if( pEntry )
333cdf0e10cSrcweir 			return pEntry;
334cdf0e10cSrcweir 		if( nRowMin )
335cdf0e10cSrcweir 			nRowMin--;
336cdf0e10cSrcweir 		if( nRowMax < (nRows-1))
337cdf0e10cSrcweir 			nRowMax++;
338cdf0e10cSrcweir 		nCurCol += nColOffs;
339cdf0e10cSrcweir 	} while( nCurCol != nLastCol );
340cdf0e10cSrcweir 	return 0;
341cdf0e10cSrcweir }
342cdf0e10cSrcweir 
GoPageUpDown(SvxIconChoiceCtrlEntry * pStart,sal_Bool bDown)343cdf0e10cSrcweir SvxIconChoiceCtrlEntry* IcnCursor_Impl::GoPageUpDown( SvxIconChoiceCtrlEntry* pStart, sal_Bool bDown)
344cdf0e10cSrcweir {
345cdf0e10cSrcweir 	if(	pView->IsAutoArrange() && !(pView->nWinBits & WB_ALIGN_TOP) )
346cdf0e10cSrcweir 	{
347cdf0e10cSrcweir 		const long nPos = (long)pView->GetEntryListPos( pStart );
348cdf0e10cSrcweir 		long nEntriesInView = (pView->aOutputSize.Height() / pView->nGridDY);
349cdf0e10cSrcweir 		nEntriesInView *=
350cdf0e10cSrcweir 			((pView->aOutputSize.Width()+(pView->nGridDX/2)) / pView->nGridDX );
351cdf0e10cSrcweir 		long nNewPos = nPos;
352cdf0e10cSrcweir 		if( bDown )
353cdf0e10cSrcweir 		{
354cdf0e10cSrcweir 			nNewPos += nEntriesInView;
355cdf0e10cSrcweir 			if( nNewPos >= (long)pView->aEntries.Count() )
356cdf0e10cSrcweir 				nNewPos = pView->aEntries.Count() - 1;
357cdf0e10cSrcweir 		}
358cdf0e10cSrcweir 		else
359cdf0e10cSrcweir 		{
360cdf0e10cSrcweir 			nNewPos -= nEntriesInView;
361cdf0e10cSrcweir 			if( nNewPos < 0 )
362cdf0e10cSrcweir 				nNewPos = 0;
363cdf0e10cSrcweir 		}
364cdf0e10cSrcweir 		if( nPos != nNewPos )
365cdf0e10cSrcweir 			return (SvxIconChoiceCtrlEntry*)pView->aEntries.GetObject( (sal_uLong)nNewPos );
366cdf0e10cSrcweir 		return 0;
367cdf0e10cSrcweir 	}
368cdf0e10cSrcweir 	long nOpt = pView->GetEntryBoundRect( pStart ).Top();
369cdf0e10cSrcweir 	if( bDown )
370cdf0e10cSrcweir 	{
371cdf0e10cSrcweir 		nOpt += pView->aOutputSize.Height();
372cdf0e10cSrcweir 		nOpt -= pView->nGridDY;
373cdf0e10cSrcweir 	}
374cdf0e10cSrcweir 	else
375cdf0e10cSrcweir 	{
376cdf0e10cSrcweir 		nOpt -= pView->aOutputSize.Height();
377cdf0e10cSrcweir 		nOpt += pView->nGridDY;
378cdf0e10cSrcweir 	}
379cdf0e10cSrcweir 	if( nOpt < 0 )
380cdf0e10cSrcweir 		nOpt = 0;
381cdf0e10cSrcweir 
382cdf0e10cSrcweir 	long nPrevErr = LONG_MAX;
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 	SvxIconChoiceCtrlEntry* pPrev = pStart;
385cdf0e10cSrcweir 	SvxIconChoiceCtrlEntry* pNext = GoUpDown( pStart, bDown );
386cdf0e10cSrcweir 	while( pNext )
387cdf0e10cSrcweir 	{
388cdf0e10cSrcweir 		long nCur = pView->GetEntryBoundRect( pNext ).Top();
389cdf0e10cSrcweir 		long nErr = nOpt - nCur;
390cdf0e10cSrcweir 		if( nErr < 0 )
391cdf0e10cSrcweir 			nErr *= -1;
392cdf0e10cSrcweir 		if( nErr > nPrevErr )
393cdf0e10cSrcweir 			return pPrev;
394cdf0e10cSrcweir 		nPrevErr = nErr;
395cdf0e10cSrcweir 		pPrev = pNext;
396cdf0e10cSrcweir 		pNext = GoUpDown( pNext, bDown );
397cdf0e10cSrcweir 	}
398cdf0e10cSrcweir 	if( pPrev != pStart )
399cdf0e10cSrcweir 		return pPrev;
400cdf0e10cSrcweir 	return 0;
401cdf0e10cSrcweir }
402cdf0e10cSrcweir 
GoUpDown(SvxIconChoiceCtrlEntry * pCtrlEntry,sal_Bool bDown)403cdf0e10cSrcweir SvxIconChoiceCtrlEntry* IcnCursor_Impl::GoUpDown( SvxIconChoiceCtrlEntry* pCtrlEntry, sal_Bool bDown)
404cdf0e10cSrcweir {
405cdf0e10cSrcweir 	if(	pView->IsAutoArrange() && !(pView->nWinBits & WB_ALIGN_TOP) )
406cdf0e10cSrcweir 	{
407cdf0e10cSrcweir 		sal_uLong nPos = pView->GetEntryListPos( pCtrlEntry );
408cdf0e10cSrcweir 		if( bDown && nPos < (pView->aEntries.Count() - 1) )
409cdf0e10cSrcweir 			return (SvxIconChoiceCtrlEntry*)pView->aEntries.GetObject( nPos + 1 );
410cdf0e10cSrcweir 		else if( !bDown && nPos > 0 )
411cdf0e10cSrcweir 			return (SvxIconChoiceCtrlEntry*)pView->aEntries.GetObject( nPos - 1 );
412cdf0e10cSrcweir 		return 0;
413cdf0e10cSrcweir 	}
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 	SvxIconChoiceCtrlEntry* pResult;
416cdf0e10cSrcweir 	pCurEntry = pCtrlEntry;
417cdf0e10cSrcweir 	Create();
418cdf0e10cSrcweir 	sal_uInt16 nY = pCtrlEntry->nY;
419cdf0e10cSrcweir 	sal_uInt16 nX = pCtrlEntry->nX;
420cdf0e10cSrcweir 	DBG_ASSERT(nY<nRows,"GoUpDown:Bad column");
421cdf0e10cSrcweir 	DBG_ASSERT(nX<nCols,"GoUpDown:Bad row");
422cdf0e10cSrcweir 
423cdf0e10cSrcweir 	// Nachbar in gleicher Spalte ?
424cdf0e10cSrcweir 	if( bDown )
425cdf0e10cSrcweir 		pResult = SearchCol(
426cdf0e10cSrcweir             nX, nY, sal::static_int_cast< sal_uInt16 >(nRows-1), nY, sal_True, sal_True );
427cdf0e10cSrcweir 	else
428cdf0e10cSrcweir 		pResult = SearchCol( nX, nY ,0, nY, sal_False, sal_True );
429cdf0e10cSrcweir 	if( pResult )
430cdf0e10cSrcweir 		return pResult;
431cdf0e10cSrcweir 
432cdf0e10cSrcweir 	long nCurRow = nY;
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 	long nRowOffs, nLastRow;
435cdf0e10cSrcweir 	if( bDown )
436cdf0e10cSrcweir 	{
437cdf0e10cSrcweir 		nRowOffs = 1;
438cdf0e10cSrcweir 		nLastRow = nRows;
439cdf0e10cSrcweir 	}
440cdf0e10cSrcweir 	else
441cdf0e10cSrcweir 	{
442cdf0e10cSrcweir 		nRowOffs = -1;
443cdf0e10cSrcweir 		nLastRow = -1;   // 0-1
444cdf0e10cSrcweir 	}
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 	sal_uInt16 nColMin = nX;
447cdf0e10cSrcweir 	sal_uInt16 nColMax = nX;
448cdf0e10cSrcweir 	do
449cdf0e10cSrcweir 	{
450cdf0e10cSrcweir 		SvxIconChoiceCtrlEntry* pEntry = SearchRow((sal_uInt16)nCurRow,nColMin,nColMax,nX,sal_True, sal_False);
451cdf0e10cSrcweir 		if( pEntry )
452cdf0e10cSrcweir 			return pEntry;
453cdf0e10cSrcweir 		if( nColMin )
454cdf0e10cSrcweir 			nColMin--;
455cdf0e10cSrcweir 		if( nColMax < (nCols-1))
456cdf0e10cSrcweir 			nColMax++;
457cdf0e10cSrcweir 		nCurRow += nRowOffs;
458cdf0e10cSrcweir 	} while( nCurRow != nLastRow );
459cdf0e10cSrcweir 	return 0;
460cdf0e10cSrcweir }
461cdf0e10cSrcweir 
SetDeltas()462cdf0e10cSrcweir void IcnCursor_Impl::SetDeltas()
463cdf0e10cSrcweir {
464cdf0e10cSrcweir 	const Size& rSize = pView->aVirtOutputSize;
465cdf0e10cSrcweir 	nCols = rSize.Width() / pView->nGridDX;
466cdf0e10cSrcweir 	if( !nCols )
467cdf0e10cSrcweir 		nCols = 1;
468cdf0e10cSrcweir 	nRows = rSize.Height() / pView->nGridDY;
469cdf0e10cSrcweir 	if( (nRows * pView->nGridDY) < rSize.Height() )
470cdf0e10cSrcweir 		nRows++;
471cdf0e10cSrcweir 	if( !nRows )
472cdf0e10cSrcweir 		nRows = 1;
473cdf0e10cSrcweir 
474cdf0e10cSrcweir 	nDeltaWidth = (short)(rSize.Width() / nCols);
475cdf0e10cSrcweir 	nDeltaHeight = (short)(rSize.Height() / nRows);
476cdf0e10cSrcweir 	if( !nDeltaHeight )
477cdf0e10cSrcweir 	{
478cdf0e10cSrcweir 		nDeltaHeight = 1;
479cdf0e10cSrcweir 		DBG_WARNING("SetDeltas:Bad height");
480cdf0e10cSrcweir 	}
481cdf0e10cSrcweir 	if( !nDeltaWidth )
482cdf0e10cSrcweir 	{
483cdf0e10cSrcweir 		nDeltaWidth = 1;
484cdf0e10cSrcweir 		DBG_WARNING("SetDeltas:Bad width");
485cdf0e10cSrcweir 	}
486cdf0e10cSrcweir }
487cdf0e10cSrcweir 
CreateGridAjustData(SvPtrarr & rLists,SvxIconChoiceCtrlEntry * pRefEntry)488cdf0e10cSrcweir void IcnCursor_Impl::CreateGridAjustData( SvPtrarr& rLists, SvxIconChoiceCtrlEntry* pRefEntry)
489cdf0e10cSrcweir {
490cdf0e10cSrcweir 	if( !pRefEntry )
491cdf0e10cSrcweir 	{
492cdf0e10cSrcweir 		sal_uInt16 nGridRows = (sal_uInt16)(pView->aVirtOutputSize.Height() / pView->nGridDY);
493cdf0e10cSrcweir 		nGridRows++; // wg. Abrundung!
494cdf0e10cSrcweir 
495cdf0e10cSrcweir 		if( !nGridRows )
496cdf0e10cSrcweir 			return;
497cdf0e10cSrcweir 		for( sal_uInt16 nCurList = 0; nCurList < nGridRows; nCurList++ )
498cdf0e10cSrcweir 		{
499cdf0e10cSrcweir 			SvPtrarr* pRow = new SvPtrarr;
500cdf0e10cSrcweir 			rLists.Insert( (void*)pRow, nCurList );
501cdf0e10cSrcweir 		}
502cdf0e10cSrcweir 		const sal_uLong nCount = pView->aEntries.Count();
503cdf0e10cSrcweir 		for( sal_uLong nCur = 0; nCur < nCount; nCur++ )
504cdf0e10cSrcweir 		{
505cdf0e10cSrcweir 			SvxIconChoiceCtrlEntry* pEntry = (SvxIconChoiceCtrlEntry*)pView->aEntries.GetObject( nCur );
506cdf0e10cSrcweir 			const Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
507cdf0e10cSrcweir 			short nY = (short)( ((rRect.Top()+rRect.Bottom())/2) / pView->nGridDY );
508cdf0e10cSrcweir 			sal_uInt16 nIns = GetSortListPos((SvPtrarr*)rLists[nY],rRect.Left(),sal_False);
509cdf0e10cSrcweir 			((SvPtrarr*)rLists[ nY ])->Insert( pEntry, nIns );
510cdf0e10cSrcweir 		}
511cdf0e10cSrcweir 	}
512cdf0e10cSrcweir 	else
513cdf0e10cSrcweir 	{
514cdf0e10cSrcweir 		// Aufbau eines hor. "Schlauchs" auf der RefEntry-Zeile
515cdf0e10cSrcweir 		// UEBERLEGEN: BoundingRect nehmen wg. Ueberlappungen???
516cdf0e10cSrcweir 		Rectangle rRefRect( pView->CalcBmpRect( pRefEntry ) );
517cdf0e10cSrcweir 		//const Rectangle& rRefRect = pView->GetEntryBoundRect( pRefEntry );
518cdf0e10cSrcweir 		short nRefRow = (short)( ((rRefRect.Top()+rRefRect.Bottom())/2) / pView->nGridDY );
519cdf0e10cSrcweir 		SvPtrarr* pRow = new SvPtrarr;
520cdf0e10cSrcweir 		rLists.Insert( (void*)pRow, 0 );
521cdf0e10cSrcweir 		sal_uLong nCount = pView->aEntries.Count();
522cdf0e10cSrcweir 		for( sal_uLong nCur = 0; nCur < nCount; nCur++ )
523cdf0e10cSrcweir 		{
524cdf0e10cSrcweir 			SvxIconChoiceCtrlEntry* pEntry = (SvxIconChoiceCtrlEntry*)pView->aEntries.GetObject( nCur );
525cdf0e10cSrcweir 			Rectangle rRect( pView->CalcBmpRect(pEntry) );
526cdf0e10cSrcweir 			//const Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
527cdf0e10cSrcweir 			short nY = (short)( ((rRect.Top()+rRect.Bottom())/2) / pView->nGridDY );
528cdf0e10cSrcweir 			if( nY == nRefRow )
529cdf0e10cSrcweir 			{
530cdf0e10cSrcweir 				sal_uInt16 nIns = GetSortListPos( pRow, rRect.Left(), sal_False );
531cdf0e10cSrcweir 				pRow->Insert( pEntry, nIns );
532cdf0e10cSrcweir 			}
533cdf0e10cSrcweir 		}
534cdf0e10cSrcweir 	}
535cdf0e10cSrcweir }
536cdf0e10cSrcweir 
537cdf0e10cSrcweir //static
DestroyGridAdjustData(SvPtrarr & rLists)538cdf0e10cSrcweir void IcnCursor_Impl::DestroyGridAdjustData( SvPtrarr& rLists )
539cdf0e10cSrcweir {
540cdf0e10cSrcweir 	const sal_uInt16 nCount = rLists.Count();
541cdf0e10cSrcweir 	for( sal_uInt16 nCur = 0; nCur < nCount; nCur++ )
542cdf0e10cSrcweir 	{
543cdf0e10cSrcweir 		SvPtrarr* pArr = (SvPtrarr*)rLists[ nCur ];
544cdf0e10cSrcweir 		delete pArr;
545cdf0e10cSrcweir 	}
546cdf0e10cSrcweir 	rLists.Remove( 0, rLists.Count() );
547cdf0e10cSrcweir }
548cdf0e10cSrcweir 
IcnGridMap_Impl(SvxIconChoiceCtrl_Impl * pView)549cdf0e10cSrcweir IcnGridMap_Impl::IcnGridMap_Impl(SvxIconChoiceCtrl_Impl* pView)
550cdf0e10cSrcweir {
551cdf0e10cSrcweir 	_pView = pView;
552cdf0e10cSrcweir 	_pGridMap = 0;
553cdf0e10cSrcweir 	_nGridCols = 0;
554cdf0e10cSrcweir 	_nGridRows = 0;
555cdf0e10cSrcweir }
556cdf0e10cSrcweir 
~IcnGridMap_Impl()557cdf0e10cSrcweir IcnGridMap_Impl::~IcnGridMap_Impl()
558cdf0e10cSrcweir {
559cdf0e10cSrcweir 	delete[] _pGridMap, _pGridMap=0;
560cdf0e10cSrcweir }
561cdf0e10cSrcweir 
Expand()562cdf0e10cSrcweir void IcnGridMap_Impl::Expand()
563cdf0e10cSrcweir {
564cdf0e10cSrcweir 	if( !_pGridMap )
565cdf0e10cSrcweir 		Create_Impl();
566cdf0e10cSrcweir 	else
567cdf0e10cSrcweir 	{
568cdf0e10cSrcweir 		sal_uInt16 nNewGridRows = _nGridRows;
569cdf0e10cSrcweir 		sal_uInt16 nNewGridCols = _nGridCols;
570cdf0e10cSrcweir 		if( _pView->nWinBits & WB_ALIGN_TOP )
571cdf0e10cSrcweir 			nNewGridRows += 50;
572cdf0e10cSrcweir 		else
573cdf0e10cSrcweir 			nNewGridCols += 50;
574cdf0e10cSrcweir 
575cdf0e10cSrcweir 		sal_Bool* pNewGridMap = new sal_Bool[nNewGridRows*nNewGridCols];
576cdf0e10cSrcweir 		memset( pNewGridMap, 0, nNewGridRows * nNewGridCols * sizeof(sal_Bool) );
577cdf0e10cSrcweir 		memcpy( pNewGridMap, _pGridMap, _nGridRows * _nGridCols * sizeof(sal_Bool) );
578cdf0e10cSrcweir 		delete[] _pGridMap;
579cdf0e10cSrcweir 		_pGridMap = pNewGridMap;
580cdf0e10cSrcweir 		_nGridRows = nNewGridRows;
581cdf0e10cSrcweir 		_nGridCols = nNewGridCols;
582cdf0e10cSrcweir 	}
583cdf0e10cSrcweir }
584cdf0e10cSrcweir 
Create_Impl()585cdf0e10cSrcweir void IcnGridMap_Impl::Create_Impl()
586cdf0e10cSrcweir {
587cdf0e10cSrcweir 	DBG_ASSERT(!_pGridMap,"Unnecessary call to IcnGridMap_Impl::Create_Impl()");
588cdf0e10cSrcweir 	if( _pGridMap )
589cdf0e10cSrcweir 		return;
590cdf0e10cSrcweir 	GetMinMapSize( _nGridCols, _nGridRows );
591cdf0e10cSrcweir 	if( _pView->nWinBits & WB_ALIGN_TOP )
592cdf0e10cSrcweir 		_nGridRows += 50;  // avoid resize of gridmap too often
593cdf0e10cSrcweir 	else
594cdf0e10cSrcweir 		_nGridCols += 50;
595cdf0e10cSrcweir 
596cdf0e10cSrcweir 	_pGridMap = new sal_Bool[ _nGridRows * _nGridCols];
597cdf0e10cSrcweir 	memset( (void*)_pGridMap, 0, _nGridRows * _nGridCols );
598cdf0e10cSrcweir 
599cdf0e10cSrcweir 	const sal_uLong nCount = _pView->aEntries.Count();
600cdf0e10cSrcweir 	for( sal_uLong nCur=0; nCur < nCount; nCur++ )
601cdf0e10cSrcweir 		OccupyGrids( (SvxIconChoiceCtrlEntry*)_pView->aEntries.GetObject( nCur ));
602cdf0e10cSrcweir }
603cdf0e10cSrcweir 
GetMinMapSize(sal_uInt16 & rDX,sal_uInt16 & rDY) const604cdf0e10cSrcweir void IcnGridMap_Impl::GetMinMapSize( sal_uInt16& rDX, sal_uInt16& rDY ) const
605cdf0e10cSrcweir {
606cdf0e10cSrcweir 	long nX, nY;
607cdf0e10cSrcweir 	if( _pView->nWinBits & WB_ALIGN_TOP )
608cdf0e10cSrcweir 	{
609cdf0e10cSrcweir 		// The view grows in vertical direction. Its max. width is _pView->nMaxVirtWidth
610cdf0e10cSrcweir 		nX = _pView->nMaxVirtWidth;
611cdf0e10cSrcweir 		if( !nX )
612cdf0e10cSrcweir 			nX = _pView->pView->GetOutputSizePixel().Width();
613cdf0e10cSrcweir 		if( !(_pView->nFlags & F_ARRANGING) )
614cdf0e10cSrcweir 			nX -= _pView->nVerSBarWidth;
615cdf0e10cSrcweir 
616cdf0e10cSrcweir 		nY = _pView->aVirtOutputSize.Height();
617cdf0e10cSrcweir 	}
618cdf0e10cSrcweir 	else
619cdf0e10cSrcweir 	{
620cdf0e10cSrcweir 		// The view grows in horizontal direction. Its max. height is _pView->nMaxVirtHeight
621cdf0e10cSrcweir 		nY = _pView->nMaxVirtHeight;
622cdf0e10cSrcweir 		if( !nY )
623cdf0e10cSrcweir 			nY = _pView->pView->GetOutputSizePixel().Height();
624cdf0e10cSrcweir 		if( !(_pView->nFlags & F_ARRANGING) )
625cdf0e10cSrcweir 			nY -= _pView->nHorSBarHeight;
626cdf0e10cSrcweir 		nX = _pView->aVirtOutputSize.Width();
627cdf0e10cSrcweir 	}
628cdf0e10cSrcweir 
629cdf0e10cSrcweir 	if( !nX )
630cdf0e10cSrcweir 		nX = DEFAULT_MAX_VIRT_WIDTH;
631cdf0e10cSrcweir 	if( !nY )
632cdf0e10cSrcweir 		nY = DEFAULT_MAX_VIRT_HEIGHT;
633cdf0e10cSrcweir 
634cdf0e10cSrcweir 	long nDX = nX / _pView->nGridDX;
635cdf0e10cSrcweir 	long nDY = nY / _pView->nGridDY;
636cdf0e10cSrcweir 
637cdf0e10cSrcweir 	if( !nDX )
638cdf0e10cSrcweir 		nDX++;
639cdf0e10cSrcweir 	if( !nDY )
640cdf0e10cSrcweir 		nDY++;
641cdf0e10cSrcweir 
642cdf0e10cSrcweir 	rDX = (sal_uInt16)nDX;
643cdf0e10cSrcweir 	rDY = (sal_uInt16)nDY;
644cdf0e10cSrcweir }
645cdf0e10cSrcweir 
GetGrid(sal_uInt16 nGridX,sal_uInt16 nGridY)646cdf0e10cSrcweir GridId IcnGridMap_Impl::GetGrid( sal_uInt16 nGridX, sal_uInt16 nGridY )
647cdf0e10cSrcweir {
648cdf0e10cSrcweir 	Create();
649cdf0e10cSrcweir 	if( _pView->nWinBits & WB_ALIGN_TOP )
650cdf0e10cSrcweir 		return nGridX + ( nGridY * _nGridCols );
651cdf0e10cSrcweir 	else
652cdf0e10cSrcweir 		return nGridY + ( nGridX * _nGridRows );
653cdf0e10cSrcweir }
654cdf0e10cSrcweir 
GetGrid(const Point & rDocPos,sal_Bool * pbClipped)655cdf0e10cSrcweir GridId IcnGridMap_Impl::GetGrid( const Point& rDocPos, sal_Bool* pbClipped )
656cdf0e10cSrcweir {
657cdf0e10cSrcweir 	Create();
658cdf0e10cSrcweir 
659cdf0e10cSrcweir 	long nX = rDocPos.X();
660cdf0e10cSrcweir 	long nY = rDocPos.Y();
661cdf0e10cSrcweir 	nX -= LROFFS_WINBORDER;
662cdf0e10cSrcweir 	nY -= TBOFFS_WINBORDER;
663cdf0e10cSrcweir 	nX /= _pView->nGridDX;
664cdf0e10cSrcweir 	nY /= _pView->nGridDY;
665cdf0e10cSrcweir 	sal_Bool bClipped = sal_False;
666cdf0e10cSrcweir 	if( nX >= _nGridCols )
667cdf0e10cSrcweir 	{
668cdf0e10cSrcweir 		nX = _nGridCols - 1;
669cdf0e10cSrcweir 		bClipped = sal_True;
670cdf0e10cSrcweir 	}
671cdf0e10cSrcweir 	if( nY >= _nGridRows )
672cdf0e10cSrcweir 	{
673cdf0e10cSrcweir 		nY = _nGridRows - 1;
674cdf0e10cSrcweir 		bClipped = sal_True;
675cdf0e10cSrcweir 	}
676cdf0e10cSrcweir 	GridId nId = GetGrid( (sal_uInt16)nX, (sal_uInt16)nY );
677cdf0e10cSrcweir 	if( pbClipped )
678cdf0e10cSrcweir 		*pbClipped = bClipped;
679cdf0e10cSrcweir 	DBG_ASSERT(nId <(sal_uLong)(_nGridCols*_nGridRows),"GetGrid failed");
680cdf0e10cSrcweir 	return nId;
681cdf0e10cSrcweir }
682cdf0e10cSrcweir 
GetGridRect(GridId nId)683cdf0e10cSrcweir Rectangle IcnGridMap_Impl::GetGridRect( GridId nId )
684cdf0e10cSrcweir {
685cdf0e10cSrcweir 	Create();
686cdf0e10cSrcweir 	sal_uInt16 nGridX, nGridY;
687cdf0e10cSrcweir 	GetGridCoord( nId, nGridX, nGridY );
688cdf0e10cSrcweir 	const long nLeft = nGridX * _pView->nGridDX+ LROFFS_WINBORDER;
689cdf0e10cSrcweir 	const long nTop = nGridY * _pView->nGridDY + TBOFFS_WINBORDER;
690cdf0e10cSrcweir 	return Rectangle(
691cdf0e10cSrcweir 		nLeft, nTop,
692cdf0e10cSrcweir 		nLeft + _pView->nGridDX,
693cdf0e10cSrcweir 		nTop + _pView->nGridDY );
694cdf0e10cSrcweir }
695cdf0e10cSrcweir 
GetUnoccupiedGrid(sal_Bool bOccupyFound)696cdf0e10cSrcweir GridId IcnGridMap_Impl::GetUnoccupiedGrid( sal_Bool bOccupyFound )
697cdf0e10cSrcweir {
698cdf0e10cSrcweir 	Create();
699cdf0e10cSrcweir 	sal_uLong nStart = 0;
700cdf0e10cSrcweir 	sal_Bool bExpanded = sal_False;
701cdf0e10cSrcweir 
702cdf0e10cSrcweir 	while( 1 )
703cdf0e10cSrcweir 	{
704cdf0e10cSrcweir 		const sal_uLong nCount = (sal_uInt16)(_nGridCols * _nGridRows);
705cdf0e10cSrcweir 		for( sal_uLong nCur = nStart; nCur < nCount; nCur++ )
706cdf0e10cSrcweir 		{
707cdf0e10cSrcweir 			if( !_pGridMap[ nCur ] )
708cdf0e10cSrcweir 			{
709cdf0e10cSrcweir 				if( bOccupyFound )
710cdf0e10cSrcweir 					_pGridMap[ nCur ] = sal_True;
711cdf0e10cSrcweir 				return (GridId)nCur;
712cdf0e10cSrcweir 			}
713cdf0e10cSrcweir 		}
714cdf0e10cSrcweir 		DBG_ASSERT(!bExpanded,"ExpandGrid failed");
715cdf0e10cSrcweir 		if( bExpanded )
716cdf0e10cSrcweir 			return 0; // prevent never ending loop
717cdf0e10cSrcweir 		bExpanded = sal_True;
718cdf0e10cSrcweir 		Expand();
719cdf0e10cSrcweir 		nStart = nCount;
720cdf0e10cSrcweir 	}
721cdf0e10cSrcweir }
722cdf0e10cSrcweir 
723cdf0e10cSrcweir // ein Eintrag belegt nur das unter seinem Zentrum liegende GridRect
724cdf0e10cSrcweir // diese Variante ist bedeutend schneller als die Belegung ueber das
725cdf0e10cSrcweir // Bounding-Rect, kann aber zu kleinen Ueberlappungen fuehren
726cdf0e10cSrcweir #define OCCUPY_CENTER
727cdf0e10cSrcweir 
OccupyGrids(const SvxIconChoiceCtrlEntry * pEntry,sal_Bool bOccupy)728cdf0e10cSrcweir void IcnGridMap_Impl::OccupyGrids( const SvxIconChoiceCtrlEntry* pEntry, sal_Bool bOccupy )
729cdf0e10cSrcweir {
730cdf0e10cSrcweir 	if( !_pGridMap || !_pView->IsBoundingRectValid( pEntry->aRect ))
731cdf0e10cSrcweir 		return;
732cdf0e10cSrcweir #ifndef OCCUPY_CENTER
733cdf0e10cSrcweir 	OccupyGrids( pEntry->aRect, bOccupy );
734cdf0e10cSrcweir #else
735cdf0e10cSrcweir 	OccupyGrid( GetGrid( pEntry->aRect.Center()), bOccupy );
736cdf0e10cSrcweir #endif
737cdf0e10cSrcweir 
738cdf0e10cSrcweir }
739cdf0e10cSrcweir 
OccupyGrids(const Rectangle & rRect,sal_Bool bUsed)740cdf0e10cSrcweir void IcnGridMap_Impl::OccupyGrids( const Rectangle& rRect, sal_Bool bUsed )
741cdf0e10cSrcweir {
742cdf0e10cSrcweir 	if( !_pGridMap )
743cdf0e10cSrcweir 		return;
744cdf0e10cSrcweir 
745cdf0e10cSrcweir 	if( bUsed )
746cdf0e10cSrcweir 	{
747cdf0e10cSrcweir 		if( _aLastOccupiedGrid == rRect )
748cdf0e10cSrcweir 			return;
749cdf0e10cSrcweir 		_aLastOccupiedGrid = rRect;
750cdf0e10cSrcweir 	}
751cdf0e10cSrcweir 	else
752cdf0e10cSrcweir 		_aLastOccupiedGrid.SetEmpty();
753cdf0e10cSrcweir 
754cdf0e10cSrcweir 	sal_Bool bTopLeftClipped, bBottomRightClipped;
755cdf0e10cSrcweir 	GridId nIdTL = GetGrid( rRect.TopLeft(), &bTopLeftClipped );
756cdf0e10cSrcweir 	GridId nIdBR = GetGrid( rRect.BottomRight(), &bBottomRightClipped );
757cdf0e10cSrcweir 
758cdf0e10cSrcweir 	if( bTopLeftClipped && bBottomRightClipped )
759cdf0e10cSrcweir 		return;
760cdf0e10cSrcweir 
761cdf0e10cSrcweir 	sal_uInt16 nX1,nX2,nY1,nY2;
762cdf0e10cSrcweir 	GetGridCoord( nIdTL, nX1, nY1 );
763cdf0e10cSrcweir 	GetGridCoord( nIdBR, nX2, nY2 );
764cdf0e10cSrcweir 	sal_uInt16 nTemp;
765cdf0e10cSrcweir 	if( nX1 > nX2 )
766cdf0e10cSrcweir 	{
767cdf0e10cSrcweir 		nTemp = nX1;
768cdf0e10cSrcweir 		nX1 = nX2;
769cdf0e10cSrcweir 		nX2 = nTemp;
770cdf0e10cSrcweir 	}
771cdf0e10cSrcweir 	if( nY1 > nY2 )
772cdf0e10cSrcweir 	{
773cdf0e10cSrcweir 		nTemp = nY1;
774cdf0e10cSrcweir 		nY1 = nY2;
775cdf0e10cSrcweir 		nY2 = nTemp;
776cdf0e10cSrcweir 	}
777cdf0e10cSrcweir 	for( ; nX1 <= nX2; nX1++ )
778cdf0e10cSrcweir 		for( ; nY1 <= nY2; nY1++ )
779cdf0e10cSrcweir 			OccupyGrid( GetGrid( nX1, nY1 ) );
780cdf0e10cSrcweir }
781cdf0e10cSrcweir 
Clear()782cdf0e10cSrcweir void IcnGridMap_Impl::Clear()
783cdf0e10cSrcweir {
784cdf0e10cSrcweir 	if( _pGridMap )
785cdf0e10cSrcweir 	{
786cdf0e10cSrcweir 		delete[] _pGridMap, _pGridMap=0;
787cdf0e10cSrcweir 		_nGridRows = 0;
788cdf0e10cSrcweir 		_nGridCols = 0;
789cdf0e10cSrcweir 		_aLastOccupiedGrid.SetEmpty();
790cdf0e10cSrcweir 	}
791cdf0e10cSrcweir }
792cdf0e10cSrcweir 
GetGridCount(const Size & rSizePixel,sal_uInt16 nDX,sal_uInt16 nDY)793cdf0e10cSrcweir sal_uLong IcnGridMap_Impl::GetGridCount( const Size& rSizePixel, sal_uInt16 nDX, sal_uInt16 nDY)
794cdf0e10cSrcweir {
795cdf0e10cSrcweir 	long ndx = (rSizePixel.Width() - LROFFS_WINBORDER) / nDX;
796cdf0e10cSrcweir 	if( ndx < 0 ) ndx *= -1;
797cdf0e10cSrcweir 	long ndy = (rSizePixel.Height() - TBOFFS_WINBORDER) / nDY;
798cdf0e10cSrcweir 	if( ndy < 0 ) ndy *= -1;
799cdf0e10cSrcweir 	return (sal_uLong)(ndx * ndy);
800cdf0e10cSrcweir }
801cdf0e10cSrcweir 
OutputSizeChanged()802cdf0e10cSrcweir void IcnGridMap_Impl::OutputSizeChanged()
803cdf0e10cSrcweir {
804cdf0e10cSrcweir 	if( _pGridMap )
805cdf0e10cSrcweir 	{
806cdf0e10cSrcweir 		sal_uInt16 nCols, nRows;
807cdf0e10cSrcweir 		GetMinMapSize( nCols, nRows );
808cdf0e10cSrcweir 		if( _pView->nWinBits & WB_ALIGN_TOP )
809cdf0e10cSrcweir 		{
810cdf0e10cSrcweir 			if( nCols != _nGridCols )
811cdf0e10cSrcweir 				Clear();
812cdf0e10cSrcweir 			else if( nRows >= _nGridRows )
813cdf0e10cSrcweir 				Expand();
814cdf0e10cSrcweir 		}
815cdf0e10cSrcweir 		else
816cdf0e10cSrcweir 		{
817cdf0e10cSrcweir 			if( nRows != _nGridRows )
818cdf0e10cSrcweir 				Clear();
819cdf0e10cSrcweir 			else if( nCols >= _nGridCols )
820cdf0e10cSrcweir 				Expand();
821cdf0e10cSrcweir 		}
822cdf0e10cSrcweir 	}
823cdf0e10cSrcweir }
824cdf0e10cSrcweir 
825cdf0e10cSrcweir // Independendly of the views alignment (TOP or LEFT) the gridmap
826cdf0e10cSrcweir // should contain the data in a continues region, to make it possible
827cdf0e10cSrcweir // to copy the whole block if the gridmap needs to be expanded.
GetGridCoord(GridId nId,sal_uInt16 & rGridX,sal_uInt16 & rGridY)828cdf0e10cSrcweir void IcnGridMap_Impl::GetGridCoord( GridId nId, sal_uInt16& rGridX, sal_uInt16& rGridY )
829cdf0e10cSrcweir {
830cdf0e10cSrcweir 	Create();
831cdf0e10cSrcweir 	if( _pView->nWinBits & WB_ALIGN_TOP )
832cdf0e10cSrcweir 	{
833cdf0e10cSrcweir 		rGridX = (sal_uInt16)(nId % _nGridCols);
834cdf0e10cSrcweir 		rGridY = (sal_uInt16)(nId / _nGridCols);
835cdf0e10cSrcweir 	}
836cdf0e10cSrcweir 	else
837cdf0e10cSrcweir 	{
838cdf0e10cSrcweir 		rGridX = (sal_uInt16)(nId / _nGridRows);
839cdf0e10cSrcweir 		rGridY = (sal_uInt16)(nId % _nGridRows);
840cdf0e10cSrcweir 	}
841cdf0e10cSrcweir }
842cdf0e10cSrcweir 
843cdf0e10cSrcweir 
844cdf0e10cSrcweir 
845