Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/control/imivctl2.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <algorithm>
21
22
#include "imivctl.hxx"
23
#include <sal/log.hxx>
24
25
IcnCursor_Impl::IcnCursor_Impl( SvxIconChoiceCtrl_Impl* pOwner )
26
0
{
27
0
    pView       = pOwner;
28
0
    pCurEntry   = nullptr;
29
0
    nDeltaWidth = 0;
30
0
    nDeltaHeight= 0;
31
0
    nCols       = 0;
32
0
    nRows       = 0;
33
0
}
34
35
IcnCursor_Impl::~IcnCursor_Impl()
36
0
{
37
0
}
38
39
sal_uInt16 IcnCursor_Impl::GetSortListPos( SvxIconChoiceCtrlEntryPtrVec& rList, tools::Long nValue,
40
    bool bVertical )
41
0
{
42
0
    sal_uInt16 nCount = rList.size();
43
0
    if( !nCount )
44
0
        return 0;
45
46
0
    sal_uInt16 nCurPos = 0;
47
0
    tools::Long nPrevValue = LONG_MIN;
48
0
    while( nCount )
49
0
    {
50
0
        const tools::Rectangle& rRect = pView->GetEntryBoundRect( rList[nCurPos] );
51
0
        tools::Long nCurValue;
52
0
        if( bVertical )
53
0
            nCurValue = rRect.Top();
54
0
        else
55
0
            nCurValue = rRect.Left();
56
0
        if( nValue >= nPrevValue && nValue <= nCurValue )
57
0
            return nCurPos;
58
0
        nPrevValue = nCurValue;
59
0
        nCount--;
60
0
        nCurPos++;
61
0
    }
62
0
    return rList.size();
63
0
}
64
65
void IcnCursor_Impl::ImplCreate()
66
0
{
67
0
    pView->CheckBoundingRects();
68
0
    DBG_ASSERT(xColumns==nullptr&&xRows==nullptr,"ImplCreate: Not cleared");
69
70
0
    SetDeltas();
71
72
0
    xColumns.reset(new IconChoiceMap);
73
0
    xRows.reset(new IconChoiceMap);
74
75
0
    size_t nCount = pView->maEntries.size();
76
0
    for( size_t nCur = 0; nCur < nCount; nCur++ )
77
0
    {
78
0
        SvxIconChoiceCtrlEntry* pEntry = pView->maEntries[ nCur ].get();
79
        // const Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
80
0
        tools::Rectangle rRect( pView->CalcBmpRect( pEntry ) );
81
0
        short nY = static_cast<short>( ((rRect.Top()+rRect.Bottom())/2) / nDeltaHeight );
82
0
        short nX = static_cast<short>( ((rRect.Left()+rRect.Right())/2) / nDeltaWidth );
83
84
        // capture rounding errors
85
0
        if( nY >= nRows )
86
0
            nY = sal::static_int_cast< short >(nRows - 1);
87
0
        if( nX >= nCols )
88
0
            nX = sal::static_int_cast< short >(nCols - 1);
89
90
0
        SvxIconChoiceCtrlEntryPtrVec& rColEntry = (*xColumns)[nX];
91
0
        sal_uInt16 nIns = GetSortListPos( rColEntry, rRect.Top(), true );
92
0
        rColEntry.insert( rColEntry.begin() + nIns, pEntry );
93
94
0
        SvxIconChoiceCtrlEntryPtrVec& rRowEntry = (*xRows)[nY];
95
0
        nIns = GetSortListPos( rRowEntry, rRect.Left(), false );
96
0
        rRowEntry.insert( rRowEntry.begin() + nIns, pEntry );
97
98
0
        pEntry->nX = nX;
99
0
        pEntry->nY = nY;
100
0
    }
101
0
}
102
103
104
void IcnCursor_Impl::Clear()
105
0
{
106
0
    if( xColumns )
107
0
    {
108
0
        xColumns.reset();
109
0
        xRows.reset();
110
0
        pCurEntry = nullptr;
111
0
        nDeltaWidth = 0;
112
0
        nDeltaHeight = 0;
113
0
    }
114
0
}
115
116
SvxIconChoiceCtrlEntry* IcnCursor_Impl::SearchCol(sal_uInt16 nCol, sal_uInt16 nTop, sal_uInt16 nBottom,
117
    bool bDown, bool bSimple )
118
0
{
119
0
    DBG_ASSERT(pCurEntry, "SearchCol: No reference entry");
120
0
    IconChoiceMap::iterator mapIt = xColumns->find( nCol );
121
0
    if ( mapIt == xColumns->end() )
122
0
        return nullptr;
123
0
    SvxIconChoiceCtrlEntryPtrVec const & rList = mapIt->second;
124
0
    const sal_uInt16 nCount = rList.size();
125
0
    if( !nCount )
126
0
        return nullptr;
127
128
0
    const tools::Rectangle& rRefRect = pView->GetEntryBoundRect(pCurEntry);
129
130
0
    if( bSimple )
131
0
    {
132
0
        SvxIconChoiceCtrlEntryPtrVec::const_iterator it = std::find( rList.begin(), rList.end(), pCurEntry );
133
134
0
        assert(it != rList.end()); //Entry not in Col-List
135
0
        if (it == rList.end())
136
0
            return nullptr;
137
138
0
        if( bDown )
139
0
        {
140
0
            while( ++it != rList.end() )
141
0
            {
142
0
                SvxIconChoiceCtrlEntry* pEntry = *it;
143
0
                const tools::Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
144
0
                if( rRect.Top() > rRefRect.Top() )
145
0
                    return pEntry;
146
0
            }
147
0
            return nullptr;
148
0
        }
149
0
        else
150
0
        {
151
0
            SvxIconChoiceCtrlEntryPtrVec::const_reverse_iterator it2(it);
152
0
            while (it2 != rList.rend())
153
0
            {
154
0
                SvxIconChoiceCtrlEntry* pEntry = *it2;
155
0
                const tools::Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
156
0
                if( rRect.Top() < rRefRect.Top() )
157
0
                    return pEntry;
158
0
                ++it2;
159
0
            }
160
0
            return nullptr;
161
0
        }
162
0
    }
163
164
0
    if( nTop > nBottom )
165
0
        std::swap(nTop, nBottom);
166
167
0
    tools::Long nMinDistance = LONG_MAX;
168
0
    SvxIconChoiceCtrlEntry* pResult = nullptr;
169
0
    for( sal_uInt16 nCur = 0; nCur < nCount; nCur++ )
170
0
    {
171
0
        SvxIconChoiceCtrlEntry* pEntry = rList[ nCur ];
172
0
        if( pEntry != pCurEntry )
173
0
        {
174
0
            sal_uInt16 nY = pEntry->nY;
175
0
            if( nY >= nTop && nY <= nBottom )
176
0
            {
177
0
                const tools::Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
178
0
                tools::Long nDistance = rRect.Top() - rRefRect.Top();
179
0
                if( nDistance < 0 )
180
0
                    nDistance *= -1;
181
0
                if( nDistance && nDistance < nMinDistance )
182
0
                {
183
0
                    nMinDistance = nDistance;
184
0
                    pResult = pEntry;
185
0
                }
186
0
            }
187
0
        }
188
0
    }
189
0
    return pResult;
190
0
}
191
192
SvxIconChoiceCtrlEntry* IcnCursor_Impl::SearchRow(sal_uInt16 nRow, sal_uInt16 nLeft, sal_uInt16 nRight,
193
    bool bRight, bool bSimple )
194
0
{
195
0
    DBG_ASSERT(pCurEntry,"SearchRow: No reference entry");
196
0
    IconChoiceMap::iterator mapIt = xRows->find( nRow );
197
0
    if ( mapIt == xRows->end() )
198
0
        return nullptr;
199
0
    SvxIconChoiceCtrlEntryPtrVec const & rList = mapIt->second;
200
0
    const sal_uInt16 nCount = rList.size();
201
0
    if( !nCount )
202
0
        return nullptr;
203
204
0
    const tools::Rectangle& rRefRect = pView->GetEntryBoundRect(pCurEntry);
205
206
0
    if( bSimple )
207
0
    {
208
0
        SvxIconChoiceCtrlEntryPtrVec::const_iterator it = std::find( rList.begin(), rList.end(), pCurEntry );
209
210
0
        assert(it != rList.end()); //Entry not in Row-List
211
0
        if (it == rList.end())
212
0
            return nullptr;
213
214
0
        if( bRight )
215
0
        {
216
0
            while( ++it != rList.end() )
217
0
            {
218
0
                SvxIconChoiceCtrlEntry* pEntry = *it;
219
0
                const tools::Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
220
0
                if( rRect.Left() > rRefRect.Left() )
221
0
                    return pEntry;
222
0
            }
223
0
            return nullptr;
224
0
        }
225
0
        else
226
0
        {
227
0
            SvxIconChoiceCtrlEntryPtrVec::const_reverse_iterator it2(it);
228
0
            while (it2 != rList.rend())
229
0
            {
230
0
                SvxIconChoiceCtrlEntry* pEntry = *it2;
231
0
                const tools::Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
232
0
                if( rRect.Left() < rRefRect.Left() )
233
0
                    return pEntry;
234
0
                ++it2;
235
0
            }
236
0
            return nullptr;
237
0
        }
238
239
0
    }
240
0
    if( nRight < nLeft )
241
0
        std::swap(nRight, nLeft);
242
243
0
    tools::Long nMinDistance = LONG_MAX;
244
0
    SvxIconChoiceCtrlEntry* pResult = nullptr;
245
0
    for( sal_uInt16 nCur = 0; nCur < nCount; nCur++ )
246
0
    {
247
0
        SvxIconChoiceCtrlEntry* pEntry = rList[ nCur ];
248
0
        if( pEntry != pCurEntry )
249
0
        {
250
0
            sal_uInt16 nX = pEntry->nX;
251
0
            if( nX >= nLeft && nX <= nRight )
252
0
            {
253
0
                const tools::Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
254
0
                tools::Long nDistance = rRect.Left() - rRefRect.Left();
255
0
                if( nDistance < 0 )
256
0
                    nDistance *= -1;
257
0
                if( nDistance && nDistance < nMinDistance )
258
0
                {
259
0
                    nMinDistance = nDistance;
260
0
                    pResult = pEntry;
261
0
                }
262
0
            }
263
0
        }
264
0
    }
265
0
    return pResult;
266
0
}
267
268
269
/*
270
    Searches, starting from the passed value, the next entry to the left/to the
271
    right. Example for bRight = sal_True:
272
273
                  c
274
                b c
275
              a b c
276
            S 1 1 1      ====> search direction
277
              a b c
278
                b c
279
                  c
280
281
    S : starting position
282
    1 : first searched rectangle
283
    a,b,c : 2nd, 3rd, 4th searched rectangle
284
*/
285
286
SvxIconChoiceCtrlEntry* IcnCursor_Impl::GoLeftRight( SvxIconChoiceCtrlEntry* pCtrlEntry, bool bRight )
287
0
{
288
0
    SvxIconChoiceCtrlEntry* pResult;
289
0
    pCurEntry = pCtrlEntry;
290
0
    Create();
291
0
    sal_uInt16 nY = pCtrlEntry->nY;
292
0
    sal_uInt16 nX = pCtrlEntry->nX;
293
0
    DBG_ASSERT(nY< nRows,"GoLeftRight:Bad column");
294
0
    DBG_ASSERT(nX< nCols,"GoLeftRight:Bad row");
295
    // neighbor in same row?
296
0
    if( bRight )
297
0
        pResult = SearchRow(
298
0
            nY, nX, sal::static_int_cast< sal_uInt16 >(nCols-1), true, true );
299
0
    else
300
0
        pResult = SearchRow( nY, 0, nX, false, true );
301
0
    if( pResult )
302
0
        return pResult;
303
304
0
    tools::Long nCurCol = nX;
305
306
0
    tools::Long nColOffs, nLastCol;
307
0
    if( bRight )
308
0
    {
309
0
        nColOffs = 1;
310
0
        nLastCol = nCols;
311
0
    }
312
0
    else
313
0
    {
314
0
        nColOffs = -1;
315
0
        nLastCol = -1;   // 0-1
316
0
    }
317
318
0
    sal_uInt16 nRowMin = nY;
319
0
    sal_uInt16 nRowMax = nY;
320
0
    do
321
0
    {
322
0
        SvxIconChoiceCtrlEntry* pEntry = SearchCol(static_cast<sal_uInt16>(nCurCol), nRowMin, nRowMax, true, false);
323
0
        if( pEntry )
324
0
            return pEntry;
325
0
        if( nRowMin )
326
0
            nRowMin--;
327
0
        if( nRowMax < (nRows-1))
328
0
            nRowMax++;
329
0
        nCurCol += nColOffs;
330
0
    } while( nCurCol != nLastCol );
331
0
    return nullptr;
332
0
}
333
334
SvxIconChoiceCtrlEntry* IcnCursor_Impl::GoPageUpDown( const SvxIconChoiceCtrlEntry* pStart, bool bDown)
335
0
{
336
0
    const tools::Long nPos = static_cast<tools::Long>(pView->GetEntryListPos( pStart ));
337
0
    tools::Long nEntriesInView = pView->aOutputSize.Height() / pView->nGridDY;
338
0
    nEntriesInView *=
339
0
        ((pView->aOutputSize.Width()+(pView->nGridDX/2)) / pView->nGridDX );
340
0
    tools::Long nNewPos = nPos;
341
0
    if( bDown )
342
0
    {
343
0
        nNewPos += nEntriesInView;
344
0
        if( nNewPos >= static_cast<tools::Long>(pView->maEntries.size()) )
345
0
            nNewPos = pView->maEntries.size() - 1;
346
0
    }
347
0
    else
348
0
    {
349
0
        nNewPos -= nEntriesInView;
350
0
        if( nNewPos < 0 )
351
0
            nNewPos = 0;
352
0
    }
353
0
    if( nPos != nNewPos )
354
0
        return pView->maEntries[ static_cast<size_t>(nNewPos) ].get();
355
0
    return nullptr;
356
0
}
357
358
SvxIconChoiceCtrlEntry* IcnCursor_Impl::GoUpDown(const SvxIconChoiceCtrlEntry* pCtrlEntry,
359
                                                 bool bDown, bool bWrap /* = false */)
360
0
{
361
0
    sal_uLong nPos = pView->GetEntryListPos(pCtrlEntry);
362
0
    if (bDown)
363
0
    {
364
0
        if (nPos < (pView->maEntries.size() - 1))
365
0
            return pView->maEntries[nPos + 1].get();
366
0
        else if (bWrap)
367
0
            return pView->maEntries.front().get();
368
0
    }
369
0
    else //!bDown
370
0
    {
371
0
        if (nPos > 0)
372
0
            return pView->maEntries[nPos - 1].get();
373
0
        else if (bWrap)
374
0
            return pView->maEntries.back().get();
375
0
    }
376
0
    return nullptr;
377
0
}
378
379
void IcnCursor_Impl::SetDeltas()
380
0
{
381
0
    const Size& rSize = pView->aVirtOutputSize;
382
0
    nCols = rSize.Width() / pView->nGridDX;
383
0
    if( !nCols )
384
0
        nCols = 1;
385
0
    nRows = rSize.Height() / pView->nGridDY;
386
0
    if( (nRows * pView->nGridDY) < rSize.Height() )
387
0
        nRows++;
388
0
    if( !nRows )
389
0
        nRows = 1;
390
391
0
    nDeltaWidth = static_cast<short>(rSize.Width() / nCols);
392
0
    nDeltaHeight = static_cast<short>(rSize.Height() / nRows);
393
0
    if( !nDeltaHeight )
394
0
    {
395
0
        nDeltaHeight = 1;
396
0
        SAL_INFO("vcl", "SetDeltas:Bad height");
397
0
    }
398
0
    if( !nDeltaWidth )
399
0
    {
400
0
        nDeltaWidth = 1;
401
0
        SAL_INFO("vcl", "SetDeltas:Bad width");
402
0
    }
403
0
}
404
405
IcnGridMap_Impl::IcnGridMap_Impl(SvxIconChoiceCtrl_Impl* pView)
406
0
 : _pView(pView), _nGridCols(0), _nGridRows(0)
407
0
{
408
0
}
409
410
IcnGridMap_Impl::~IcnGridMap_Impl()
411
0
{
412
0
}
413
414
void IcnGridMap_Impl::Expand()
415
0
{
416
0
    if( !_pGridMap )
417
0
        Create_Impl();
418
0
    else
419
0
    {
420
0
        sal_uInt16 nNewGridRows = _nGridRows;
421
0
        sal_uInt16 nNewGridCols = _nGridCols;
422
0
        nNewGridCols += 50;
423
424
0
        size_t nNewCellCount = static_cast<size_t>(nNewGridRows) * nNewGridCols;
425
0
        bool* pNewGridMap = new bool[nNewCellCount];
426
0
        size_t nOldCellCount = static_cast<size_t>(_nGridRows) * _nGridCols;
427
0
        std::copy_n(_pGridMap.get(), nOldCellCount, pNewGridMap);
428
0
        memset(pNewGridMap + nOldCellCount, 0, (nNewCellCount-nOldCellCount) * sizeof(bool));
429
0
        _pGridMap.reset( pNewGridMap );
430
0
        _nGridRows = nNewGridRows;
431
0
        _nGridCols = nNewGridCols;
432
0
    }
433
0
}
434
435
void IcnGridMap_Impl::Create_Impl()
436
0
{
437
0
    DBG_ASSERT(!_pGridMap,"Unnecessary call to IcnGridMap_Impl::Create_Impl()");
438
0
    if( _pGridMap )
439
0
        return;
440
0
    GetMinMapSize( _nGridCols, _nGridRows );
441
0
    _nGridCols += 50;
442
443
0
    size_t nCellCount = static_cast<size_t>(_nGridRows) * _nGridCols;
444
0
    _pGridMap.reset( new bool[nCellCount] );
445
0
    memset(_pGridMap.get(), 0, nCellCount * sizeof(bool));
446
447
0
    const size_t nCount = _pView->maEntries.size();
448
0
    for( size_t nCur=0; nCur < nCount; nCur++ )
449
0
        OccupyGrids( _pView->maEntries[ nCur ].get() );
450
0
}
451
452
void IcnGridMap_Impl::GetMinMapSize( sal_uInt16& rDX, sal_uInt16& rDY ) const
453
0
{
454
    // The view grows in horizontal direction. Its max. height is _pView->nMaxVirtHeight
455
0
    tools::Long nY = _pView->nMaxVirtHeight;
456
0
    if( !nY )
457
0
        nY = _pView->pView->GetOutputSizePixel().Height();
458
0
    if( !(_pView->nFlags & IconChoiceFlags::Arranging) )
459
0
        nY -= _pView->nHorSBarHeight;
460
461
0
    tools::Long nX = _pView->aVirtOutputSize.Width();
462
463
0
    if( !nX )
464
0
        nX = DEFAULT_MAX_VIRT_WIDTH;
465
0
    if( !nY )
466
0
        nY = DEFAULT_MAX_VIRT_HEIGHT;
467
468
0
    tools::Long nDX = nX / _pView->nGridDX;
469
0
    tools::Long nDY = nY / _pView->nGridDY;
470
471
0
    if( !nDX )
472
0
        nDX++;
473
0
    if( !nDY )
474
0
        nDY++;
475
476
0
    rDX = static_cast<sal_uInt16>(nDX);
477
0
    rDY = static_cast<sal_uInt16>(nDY);
478
0
}
479
480
GridId IcnGridMap_Impl::GetGrid( sal_uInt16 nGridX, sal_uInt16 nGridY )
481
0
{
482
0
    Create();
483
0
    return nGridY + ( static_cast<GridId>(nGridX) * _nGridRows );
484
0
}
485
486
GridId IcnGridMap_Impl::GetGrid( const Point& rDocPos )
487
0
{
488
0
    Create();
489
490
0
    tools::Long nX = rDocPos.X();
491
0
    tools::Long nY = rDocPos.Y();
492
0
    nX -= LROFFS_WINBORDER;
493
0
    nY -= TBOFFS_WINBORDER;
494
0
    nX /= _pView->nGridDX;
495
0
    nY /= _pView->nGridDY;
496
0
    if( nX >= _nGridCols )
497
0
    {
498
0
        nX = _nGridCols - 1;
499
0
    }
500
0
    if( nY >= _nGridRows )
501
0
    {
502
0
        nY = _nGridRows - 1;
503
0
    }
504
0
    GridId nId = GetGrid( static_cast<sal_uInt16>(nX), static_cast<sal_uInt16>(nY) );
505
0
    DBG_ASSERT(nId <o3tl::make_unsigned(_nGridCols*_nGridRows),"GetGrid failed");
506
0
    return nId;
507
0
}
508
509
tools::Rectangle IcnGridMap_Impl::GetGridRect( GridId nId )
510
0
{
511
0
    Create();
512
0
    sal_uInt16 nGridX, nGridY;
513
0
    GetGridCoord( nId, nGridX, nGridY );
514
0
    const tools::Long nLeft = nGridX * _pView->nGridDX+ LROFFS_WINBORDER;
515
0
    const tools::Long nTop = nGridY * _pView->nGridDY + TBOFFS_WINBORDER;
516
0
    return tools::Rectangle(
517
0
        nLeft, nTop,
518
0
        nLeft + _pView->nGridDX,
519
0
        nTop + _pView->nGridDY );
520
0
}
521
522
GridId IcnGridMap_Impl::GetUnoccupiedGrid()
523
0
{
524
0
    Create();
525
0
    sal_uLong nStart = 0;
526
0
    bool bExpanded = false;
527
528
0
    while( true )
529
0
    {
530
0
        const sal_uLong nCount = static_cast<sal_uInt16>(_nGridCols * _nGridRows);
531
0
        for( sal_uLong nCur = nStart; nCur < nCount; nCur++ )
532
0
        {
533
0
            if( !_pGridMap[ nCur ] )
534
0
            {
535
0
                _pGridMap[ nCur ] = true;
536
0
                return static_cast<GridId>(nCur);
537
0
            }
538
0
        }
539
0
        DBG_ASSERT(!bExpanded,"ExpandGrid failed");
540
0
        if( bExpanded )
541
0
            return 0; // prevent never ending loop
542
0
        bExpanded = true;
543
0
        Expand();
544
0
        nStart = nCount;
545
0
    }
546
0
}
547
548
// An entry only means that there's a GridRect lying under its center. This
549
// variant is much faster than allocating via the bounding rectangle but can
550
// lead to small overlaps.
551
void IcnGridMap_Impl::OccupyGrids( const SvxIconChoiceCtrlEntry* pEntry )
552
0
{
553
0
    if( !_pGridMap || !SvxIconChoiceCtrl_Impl::IsBoundingRectValid( pEntry->aRect ))
554
0
        return;
555
0
    OccupyGrid( GetGrid( pEntry->aRect.Center()) );
556
0
}
557
558
void IcnGridMap_Impl::Clear()
559
0
{
560
0
    if( _pGridMap )
561
0
    {
562
0
        _pGridMap.reset();
563
0
        _nGridRows = 0;
564
0
        _nGridCols = 0;
565
0
        _aLastOccupiedGrid.SetEmpty();
566
0
    }
567
0
}
568
569
sal_uLong IcnGridMap_Impl::GetGridCount( const Size& rSizePixel, sal_uInt16 nDX, sal_uInt16 nDY)
570
0
{
571
0
    tools::Long ndx = (rSizePixel.Width() - LROFFS_WINBORDER) / nDX;
572
0
    if( ndx < 0 ) ndx *= -1;
573
0
    tools::Long ndy = (rSizePixel.Height() - TBOFFS_WINBORDER) / nDY;
574
0
    if( ndy < 0 ) ndy *= -1;
575
0
    return static_cast<sal_uLong>(ndx * ndy);
576
0
}
577
578
void IcnGridMap_Impl::OutputSizeChanged()
579
0
{
580
0
    if( !_pGridMap )
581
0
        return;
582
583
0
    sal_uInt16 nCols, nRows;
584
0
    GetMinMapSize( nCols, nRows );
585
0
    if( nRows != _nGridRows )
586
0
        Clear();
587
0
    else if( nCols >= _nGridCols )
588
0
        Expand();
589
0
}
590
591
// the gridmap should contain the data in a continuous region, to make it possible
592
// to copy the whole block if the gridmap needs to be expanded.
593
void IcnGridMap_Impl::GetGridCoord( GridId nId, sal_uInt16& rGridX, sal_uInt16& rGridY )
594
0
{
595
0
    rGridX = static_cast<sal_uInt16>(nId / _nGridRows);
596
0
    rGridY = static_cast<sal_uInt16>(nId % _nGridRows);
597
0
}
598
599
600
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */