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