/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
Point IconViewImpl::GetEntryPosition(const SvTreeListEntry* pEntry) const
{
Point result{ -m_pView->GetEntryWidth(), -m_pView->GetEntryHeight() }; // invisible auto FindEntryPos = [pEntry, &result](const EntryAreaInfo& info)
{ if (pEntry == info.entry)
{
result = info.area.TopLeft(); return CallbackResult::Stop;
} return CallbackResult::Continue;
};
IterateVisibleEntryAreas(FindEntryPos, true);
return result;
}
// Returns the last entry (in respective row) if position is just past the last entry
SvTreeListEntry* IconViewImpl::GetClickedEntry( const Point& rPoint ) const
{
DBG_ASSERT( m_pView->GetModel(), "IconViewImpl::GetClickedEntry: how can this ever happen?" ); if ( !m_pView->GetModel() ) return nullptr; if( m_pView->GetEntryCount() == 0 || !m_pStartEntry || !m_pView->GetEntryHeight() || !m_pView->GetEntryWidth()) return nullptr;
SvTreeListEntry* pEntry = nullptr; auto FindEntryByPos = [&pEntry, &rPoint](const EntryAreaInfo& info)
{ if (info.area.Contains(rPoint))
{
pEntry = info.entry; return CallbackResult::Stop;
} elseif (info.area.Top() > rPoint.Y())
{ return CallbackResult::Stop; // we are already below the clicked row
} elseif (info.area.Bottom() > rPoint.Y())
{
pEntry = info.entry; // Same row; store the entry in case the click is past all entries
} return CallbackResult::Continue;
};
IterateVisibleEntryAreas(FindEntryByPos, true);
// number of entries visible within the view const tools::Long nVisibleRows = aOSize.Height() / nEntryHeight;
m_nVisibleCount = nVisibleRows * m_pView->GetColumnsCount();
if (nResult & 0x0002)
m_aHorSBar->Show(); else
m_aHorSBar->Hide();
rSize = aOSize;
}
// returns 0 if position is just past the last entry
SvTreeListEntry* IconViewImpl::GetEntry( const Point& rPoint ) const
{ if( (m_pView->GetEntryCount() == 0) || !m_pStartEntry ||
(rPoint.Y() > m_aOutputSize.Height())
|| !m_pView->GetEntryHeight()
|| !m_pView->GetEntryWidth()) return nullptr;
SvTreeListEntry* pEntry = nullptr; auto FindEntryByPos = [&pEntry, &rPoint](const EntryAreaInfo& info)
{ if (info.area.Contains(rPoint))
{
pEntry = info.entry; return CallbackResult::Stop;
} elseif (info.area.Top() > rPoint.Y())
{ return CallbackResult::Stop; // we are already below the clicked row
} return CallbackResult::Continue;
};
IterateVisibleEntryAreas(FindEntryByPos, true);
if (!m_pStartEntry)
{
m_pStartEntry = m_pView->First();
}
if (!m_pCursor && !mbNoAutoCurEntry)
{ // do not select if multiselection or explicit set bool bNotSelect = (m_aSelEng.GetSelectionMode() == SelectionMode::Multiple ) || ((m_nStyle & WB_NOINITIALSELECTION) == WB_NOINITIALSELECTION);
SetCursor(m_pStartEntry, bNotSelect);
}
auto PaintEntry = [iconView = static_cast<IconView*>(m_pView.get()), &rRect,
&rRenderContext](const EntryAreaInfo& info)
{ if (!info.area.GetIntersection(rRect).IsEmpty())
{
iconView->PaintEntry(*info.entry, info.area.Left(), info.area.Top(), rRenderContext);
} elseif (info.area.Top() > rRect.Bottom())
{ return CallbackResult::Stop; // we are already below the last visible row
} return CallbackResult::Continue;
};
IterateVisibleEntryAreas(PaintEntry, true);
void IconViewImpl::InvalidateEntry( tools::Long nId ) const
{ if( m_nFlags & LBoxFlags::InPaint ) return; if (nId < 0) return;
// nId is a Y coordinate of the top of the element, coming from GetEntryLine
tools::Rectangle aRect( GetVisibleArea() ); if (nId > aRect.Bottom()) return;
aRect.SetTop(nId); // Invalidate everything below
m_pView->Invalidate( aRect );
}
// if there is no next entry, take the current one // this ensures that in case of _one_ entry in the list, this entry is selected when pressing // the cursor key if (!pNewCursor)
pNewCursor = m_pCursor;
m_aSelEng.CursorPosChanging( bShift, bMod1 );
SetCursor( pNewCursor, bMod1 ); // no selection, when Ctrl is on if( !IsEntryInView( pNewCursor ) )
KeyUp( false ); break;
case KEY_RIGHT: if( !IsEntryInView( m_pCursor ) )
MakeVisible( m_pCursor );
// if there is no next entry, take the current one // this ensures that in case of _one_ entry in the list, this entry is selected when pressing // the cursor key if ( !pNewCursor && m_pCursor )
pNewCursor = m_pCursor;
if( pNewCursor )
{
m_aSelEng.CursorPosChanging( bShift, bMod1 ); if( IsEntryInView( pNewCursor ) )
SetCursor( pNewCursor, bMod1 ); // no selection, when Ctrl is on else
{ if( m_pCursor )
m_pView->Select( m_pCursor, false );
KeyDown( false );
SetCursor( pNewCursor, bMod1 ); // no selection, when Ctrl is on
}
} else
KeyDown( false ); // because scrollbar range might still // allow scrolling break;
case KEY_UP:
{
pNewCursor = GoToPrevRow(m_pCursor, 1);
if( pNewCursor )
{
m_aSelEng.CursorPosChanging( bShift, bMod1 );
SetCursor( pNewCursor, bMod1 ); // no selection, when Ctrl is on
ScrollTo(pNewCursor);
} break;
}
case KEY_DOWN:
{
pNewCursor = GoToNextRow(m_pCursor, 1);
if( pNewCursor )
{
m_aSelEng.CursorPosChanging( bShift, bMod1 );
ScrollTo(pNewCursor);
SetCursor(pNewCursor, bMod1); // no selection, when Ctrl is on
} else
KeyDown( false ); // because scrollbar range might still // allow scrolling break;
}
case KEY_PAGEUP: if (!bMod1)
{ const sal_uInt16 nDelta = m_aVerSBar->GetPageSize();
pNewCursor = GoToPrevRow(m_pCursor, nDelta);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.