diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-10-17 19:35:07 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-10-22 20:35:58 +0200 |
commit | 7476e6d987ce54c3a1058bafac8152e5b1abc52a (patch) | |
tree | e3a0620af4b3b14ddcd51a3e0b81dc2bb80d1c67 /sfx2/source | |
parent | 2a635ba02b51a2523feef71fb28643cad540f942 (diff) |
drop newly unused ThumbnailView
Change-Id: I6c025120abf7f7dfbc1c06ad47e80e1d23ba731d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104536
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sfx2/source')
-rw-r--r-- | sfx2/source/control/recentdocsviewitem.cxx | 2 | ||||
-rw-r--r-- | sfx2/source/control/recentdocsviewitem.hxx | 2 | ||||
-rw-r--r-- | sfx2/source/control/templatelocalview.cxx | 2 | ||||
-rw-r--r-- | sfx2/source/control/thumbnailview.cxx | 1073 | ||||
-rw-r--r-- | sfx2/source/control/thumbnailviewacc.cxx | 563 | ||||
-rw-r--r-- | sfx2/source/control/thumbnailviewacc.hxx | 101 |
6 files changed, 68 insertions, 1675 deletions
diff --git a/sfx2/source/control/recentdocsviewitem.cxx b/sfx2/source/control/recentdocsviewitem.cxx index 9b73ef2c88ef..090e2881e000 100644 --- a/sfx2/source/control/recentdocsviewitem.cxx +++ b/sfx2/source/control/recentdocsviewitem.cxx @@ -54,7 +54,7 @@ RecentDocsViewItem::RecentDocsViewItem(sfx2::RecentDocsView &rView, const OUStri //fdo#74834: only load thumbnail if the corresponding option is not disabled in the configuration if (aThumbnail.IsEmpty() && aURLObj.GetProtocol() == INetProtocol::File && officecfg::Office::Common::History::RecentDocsThumbnail::get()) - aThumbnail = ThumbnailView::readThumbnail(rURL); + aThumbnail = SfxThumbnailView::readThumbnail(rURL); if (aThumbnail.IsEmpty()) { diff --git a/sfx2/source/control/recentdocsviewitem.hxx b/sfx2/source/control/recentdocsviewitem.hxx index cb6320e9ee74..4d06d91b0f28 100644 --- a/sfx2/source/control/recentdocsviewitem.hxx +++ b/sfx2/source/control/recentdocsviewitem.hxx @@ -12,8 +12,6 @@ #include <sfx2/thumbnailviewitem.hxx> -class ThumbnailView; - namespace sfx2 { class RecentDocsView; diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx index 40f0418b9206..157df66e7bcd 100644 --- a/sfx2/source/control/templatelocalview.cxx +++ b/sfx2/source/control/templatelocalview.cxx @@ -942,7 +942,7 @@ BitmapEx SfxTemplateLocalView::getDefaultThumbnail( const OUString& rPath ) BitmapEx SfxTemplateLocalView::fetchThumbnail (const OUString &msURL, tools::Long width, tools::Long height) { - return SfxTemplateLocalView::scaleImg(ThumbnailView::readThumbnail(msURL), width, height); + return SfxTemplateLocalView::scaleImg(SfxThumbnailView::readThumbnail(msURL), width, height); } void SfxTemplateLocalView::OnItemDblClicked (ThumbnailViewItem *pItem) diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx index de2415c8640e..6ba29958a35b 100644 --- a/sfx2/source/control/thumbnailview.cxx +++ b/sfx2/source/control/thumbnailview.cxx @@ -48,1069 +48,6 @@ using namespace drawinglayer::primitive2d; constexpr int gnFineness = 5; -ThumbnailView::ThumbnailView (vcl::Window *pParent) - : Control( pParent, WB_TABSTOP ) - , mpItemAttrs(new ThumbnailItemAttributes) -{ - ImplInit(); -} - -ThumbnailView::~ThumbnailView() -{ - disposeOnce(); -} - -void ThumbnailView::dispose() -{ - css::uno::Reference< css::lang::XComponent> xComponent(GetAccessible(false), css::uno::UNO_QUERY); - - if (xComponent.is()) - xComponent->dispose (); - - mpScrBar.disposeAndClear(); - mpItemAttrs.reset(); - - ImplDeleteItems(); - Control::dispose(); -} - -void ThumbnailView::MouseMove(const MouseEvent& rMEvt) -{ - size_t nItemCount = mFilteredItemList.size(); - Point aPoint = rMEvt.GetPosPixel(); - OUString aHelp; - - for (size_t i = 0; i < nItemCount; i++) - { - ThumbnailViewItem *pItem = mFilteredItemList[i]; - - if (pItem->mbVisible && !rMEvt.IsLeaveWindow() && pItem->getDrawArea().IsInside(aPoint)) - { - aHelp = pItem->getHelpText(); - } - - ::tools::Rectangle aToInvalidate(pItem->updateHighlight(pItem->mbVisible && !rMEvt.IsLeaveWindow(), aPoint)); - - if (!aToInvalidate.IsEmpty() && IsReallyVisible() && IsUpdateMode()) - Invalidate(aToInvalidate); - } - - if (mbShowTooltips) - SetQuickHelpText(aHelp); -} - -void ThumbnailView::AppendItem(std::unique_ptr<ThumbnailViewItem> pItem) -{ - if (maFilterFunc(pItem.get())) - { - // Save current start,end range, iterator might get invalidated - size_t nSelStartPos = 0; - ThumbnailViewItem *pSelStartItem = nullptr; - - if (mpStartSelRange != mFilteredItemList.end()) - { - pSelStartItem = *mpStartSelRange; - nSelStartPos = mpStartSelRange - mFilteredItemList.begin(); - } - - mFilteredItemList.push_back(pItem.get()); - mpStartSelRange = pSelStartItem != nullptr ? mFilteredItemList.begin() + nSelStartPos : mFilteredItemList.end(); - } - - mItemList.push_back(std::move(pItem)); -} - -void ThumbnailView::ImplInit() -{ - mpScrBar = nullptr; - mnItemWidth = 0; - mnItemHeight = 0; - mnItemPadding = 0; - mnVisLines = 0; - mnLines = 0; - mnFirstLine = 0; - mnCols = 0; - mbScroll = false; - mbHasVisibleItems = false; - mbShowTooltips = false; - maFilterFunc = ViewFilterAll(); - maFillColor = GetSettings().GetStyleSettings().GetFieldColor(); - maTextColor = GetSettings().GetStyleSettings().GetWindowTextColor(); - maHighlightColor = GetSettings().GetStyleSettings().GetHighlightColor(); - maHighlightTextColor = GetSettings().GetStyleSettings().GetHighlightTextColor(); - maSelectHighlightColor = GetSettings().GetStyleSettings().GetActiveColor(); - maSelectHighlightTextColor = GetSettings().GetStyleSettings().GetActiveTextColor(); - - const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer; - mfHighlightTransparence = aSvtOptionsDrawinglayer.GetTransparentSelectionPercent() * 0.01; - - mpStartSelRange = mFilteredItemList.end(); - - ApplySettings(*this); -} - -void ThumbnailView::ImplDeleteItems() -{ - const size_t n = mItemList.size(); - - for ( size_t i = 0; i < n; ++i ) - { - ThumbnailViewItem *const pItem = mItemList[i].get(); - - // deselect all current selected items and fire events - if (pItem->isSelected()) - { - pItem->setSelection(false); - // fire accessible event??? - } - - if ( pItem->isVisible() && ImplHasAccessibleListeners() ) - { - css::uno::Any aOldAny, aNewAny; - - aOldAny <<= pItem->GetAccessible( false ); - ImplFireAccessibleEvent( css::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny ); - } - - mItemList[i].reset(); - } - - mItemList.clear(); - mFilteredItemList.clear(); - - mpStartSelRange = mFilteredItemList.end(); -} - -void ThumbnailView::ApplySettings(vcl::RenderContext& rRenderContext) -{ - const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings(); - - ApplyControlFont(*this, rStyleSettings.GetAppFont()); - ApplyControlForeground(*this, rStyleSettings.GetButtonTextColor()); - rRenderContext.SetTextFillColor(); - rRenderContext.SetBackground(maFillColor); - - mpItemAttrs->aFillColor = maFillColor.getBColor(); - mpItemAttrs->aTextColor = maTextColor.getBColor(); - mpItemAttrs->aHighlightColor = maHighlightColor.getBColor(); - mpItemAttrs->aHighlightTextColor = maHighlightTextColor.getBColor(); - mpItemAttrs->aSelectHighlightColor = maSelectHighlightColor.getBColor(); - mpItemAttrs->aSelectHighlightTextColor = maSelectHighlightTextColor.getBColor(); - mpItemAttrs->fHighlightTransparence = mfHighlightTransparence; - mpItemAttrs->aFontAttr = getFontAttributeFromVclFont(mpItemAttrs->aFontSize,GetFont(),false,true); - mpItemAttrs->nMaxTextLength = 0; -} - -void ThumbnailView::DrawItem(ThumbnailViewItem const *pItem) -{ - if (pItem->isVisible()) - { - ::tools::Rectangle aRect = pItem->getDrawArea(); - - if (!aRect.IsEmpty()) - Invalidate(aRect); - } -} - -void ThumbnailView::OnItemDblClicked (ThumbnailViewItem*) -{ -} - -css::uno::Reference< css::accessibility::XAccessible > ThumbnailView::CreateAccessible() -{ - return new ThumbnailViewAcc( this ); -} - -css::uno::Reference< css::accessibility::XAccessible > ThumbnailView::getAccessible() -{ - return GetAccessible(); -} - -void ThumbnailView::CalculateItemPositions (bool bScrollBarUsed) -{ - if (!mnItemHeight || !mnItemWidth) - return; - - Size aWinSize = GetOutputSizePixel(); - size_t nItemCount = mFilteredItemList.size(); - WinBits nStyle = GetStyle(); - VclPtr<ScrollBar> pDelScrBar; - tools::Long nScrBarWidth = 0; - - // consider the scrolling - if ( nStyle & WB_VSCROLL ) - { - if ( !mpScrBar ) - { - mpScrBar = VclPtr<ScrollBar>::Create( this, WB_VSCROLL | WB_DRAG ); - mpScrBar->SetScrollHdl( LINK( this, ThumbnailView, ImplScrollHdl ) ); - } - - // adapt the width because of the changed settings - nScrBarWidth = GetSettings().GetStyleSettings().GetScrollBarSize(); - } - else - { - if ( mpScrBar ) - { - // delete ScrollBar not until later, to prevent recursive calls - pDelScrBar = mpScrBar; - mpScrBar = nullptr; - } - } - - // calculate window scroll ratio - float nScrollRatio; - if( bScrollBarUsed && mpScrBar ) - nScrollRatio = static_cast<float>(mpScrBar->GetThumbPos()) / - static_cast<float>(mpScrBar->GetRangeMax() - mpScrBar->GetVisibleSize()); - else - nScrollRatio = 0; - - // calculate maximum number of visible columns - mnCols = static_cast<sal_uInt16>((aWinSize.Width()-nScrBarWidth) / mnItemWidth); - - if (!mnCols) - mnCols = 1; - - // calculate maximum number of visible rows - mnVisLines = static_cast<sal_uInt16>(aWinSize.Height() / mnItemHeight); - - // calculate empty space - tools::Long nHSpace = aWinSize.Width()-nScrBarWidth - mnCols*mnItemWidth; - tools::Long nVSpace = aWinSize.Height() - mnVisLines*mnItemHeight; - tools::Long nHItemSpace = nHSpace / (mnCols+1); - tools::Long nVItemSpace = nVSpace / (mnVisLines+1); - - // calculate maximum number of rows - // Floor( (M+N-1)/N )==Ceiling( M/N ) - mnLines = (static_cast<tools::Long>(nItemCount)+mnCols-1) / mnCols; - - if ( !mnLines ) - mnLines = 1; - - if ( mnLines <= mnVisLines ) - mnFirstLine = 0; - else if ( mnFirstLine > o3tl::make_unsigned(mnLines-mnVisLines) ) - mnFirstLine = static_cast<sal_uInt16>(mnLines-mnVisLines); - - mbHasVisibleItems = true; - - tools::Long nFullSteps = (mnLines > mnVisLines) ? mnLines - mnVisLines + 1 : 1; - - tools::Long nItemHeightOffset = mnItemHeight + nVItemSpace; - tools::Long nHiddenLines = static_cast<tools::Long>((nFullSteps - 1) * nScrollRatio); - - // calculate offsets - tools::Long nStartX = nHItemSpace; - tools::Long nStartY = nVItemSpace; - - // calculate and draw items - tools::Long x = nStartX; - tools::Long y = nStartY - ((nFullSteps - 1) * nScrollRatio - nHiddenLines) * nItemHeightOffset; - - // draw items - // Unless we are scrolling (via scrollbar) we just use the precalculated - // mnFirstLine -- our nHiddenLines calculation takes into account only - // what the user has done with the scrollbar but not any changes of selection - // using the keyboard, meaning we could accidentally hide the selected item - // if we believe the scrollbar (fdo#72287). - size_t nFirstItem = (bScrollBarUsed ? nHiddenLines : mnFirstLine) * mnCols; - size_t nLastItem = nFirstItem + (mnVisLines + 1) * mnCols; - - // If want also draw parts of items in the last line, - // then we add one more line if parts of this line are visible - - size_t nCurCount = 0; - for ( size_t i = 0; i < nItemCount; i++ ) - { - ThumbnailViewItem *const pItem = mFilteredItemList[i]; - - if ((nCurCount >= nFirstItem) && (nCurCount < nLastItem)) - { - if( !pItem->isVisible()) - { - if ( ImplHasAccessibleListeners() ) - { - css::uno::Any aOldAny, aNewAny; - - aNewAny <<= pItem->GetAccessible( false ); - ImplFireAccessibleEvent( css::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny ); - } - - pItem->show(true); - } - - pItem->setDrawArea(::tools::Rectangle( Point(x,y), Size(mnItemWidth, mnItemHeight) )); - pItem->calculateItemsPosition(mnThumbnailHeight,mnItemPadding,mpItemAttrs->nMaxTextLength,mpItemAttrs.get()); - - if ( !((nCurCount+1) % mnCols) ) - { - x = nStartX; - y += mnItemHeight+nVItemSpace; - } - else - x += mnItemWidth+nHItemSpace; - } - else - { - if( pItem->isVisible()) - { - if ( ImplHasAccessibleListeners() ) - { - css::uno::Any aOldAny, aNewAny; - - aOldAny <<= pItem->GetAccessible( false ); - ImplFireAccessibleEvent( css::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny ); - } - - pItem->show(false); - } - - } - - ++nCurCount; - } - - // arrange ScrollBar, set values and show it - if ( mpScrBar ) - { - mnLines = (nCurCount+mnCols-1)/mnCols; - - // check if scroll is needed - mbScroll = mnLines > mnVisLines; - - - Point aPos( aWinSize.Width() - nScrBarWidth, 0 ); - Size aSize( nScrBarWidth, aWinSize.Height() ); - - mpScrBar->SetPosSizePixel( aPos, aSize ); - mpScrBar->SetRangeMax(mnLines * gnFineness); - mpScrBar->SetVisibleSize(mnVisLines * gnFineness); - if (!bScrollBarUsed) - mpScrBar->SetThumbPos( static_cast<tools::Long>(mnFirstLine)*gnFineness ); - tools::Long nPageSize = mnVisLines; - if ( nPageSize < 1 ) - nPageSize = 1; - mpScrBar->SetPageSize( nPageSize ); - mpScrBar->Show( mbScroll ); - mpScrBar->Enable( mbScroll ); - } - - // delete ScrollBar - pDelScrBar.disposeAndClear(); -} - -size_t ThumbnailView::ImplGetItem( const Point& rPos ) const -{ - if ( !mbHasVisibleItems ) - { - return THUMBNAILVIEW_ITEM_NOTFOUND; - } - - for (size_t i = 0; i < mFilteredItemList.size(); ++i) - { - if (mFilteredItemList[i]->isVisible() && mFilteredItemList[i]->getDrawArea().IsInside(rPos)) - return i; - } - - return THUMBNAILVIEW_ITEM_NOTFOUND; -} - -ThumbnailViewItem* ThumbnailView::ImplGetItem( size_t nPos ) -{ - return ( nPos < mFilteredItemList.size() ) ? mFilteredItemList[nPos] : nullptr; -} - -sal_uInt16 ThumbnailView::ImplGetVisibleItemCount() const -{ - sal_uInt16 nRet = 0; - const size_t nItemCount = mItemList.size(); - - for ( size_t n = 0; n < nItemCount; ++n ) - { - if ( mItemList[n]->isVisible() ) - ++nRet; - } - - return nRet; -} - -ThumbnailViewItem* ThumbnailView::ImplGetVisibleItem( sal_uInt16 nVisiblePos ) -{ - const size_t nItemCount = mItemList.size(); - - for ( size_t n = 0; n < nItemCount; ++n ) - { - ThumbnailViewItem *const pItem = mItemList[n].get(); - - if ( pItem->isVisible() && !nVisiblePos-- ) - return pItem; - } - - return nullptr; -} - -void ThumbnailView::ImplFireAccessibleEvent( short nEventId, const css::uno::Any& rOldValue, const css::uno::Any& rNewValue ) -{ - ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation( GetAccessible( false ) ); - - if( pAcc ) - pAcc->FireAccessibleEvent( nEventId, rOldValue, rNewValue ); -} - -bool ThumbnailView::ImplHasAccessibleListeners() -{ - ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation( GetAccessible( false ) ); - return( pAcc && pAcc->HasAccessibleListeners() ); -} - -IMPL_LINK( ThumbnailView,ImplScrollHdl, ScrollBar*, pScrollBar, void ) -{ - if ( pScrollBar->GetDelta() ) - { - CalculateItemPositions(true); - - if ( IsReallyVisible() && IsUpdateMode() ) - Invalidate(); - } -} - -void ThumbnailView::KeyInput( const KeyEvent& rKEvt ) -{ - // Get the last selected item in the list - size_t nLastPos = 0; - bool bFoundLast = false; - for ( tools::Long i = mFilteredItemList.size() - 1; !bFoundLast && i >= 0; --i ) - { - ThumbnailViewItem* pItem = mFilteredItemList[i]; - if ( pItem->isSelected() ) - { - nLastPos = i; - bFoundLast = true; - } - } - - bool bValidRange = false; - bool bHasSelRange = mpStartSelRange != mFilteredItemList.end(); - size_t nNextPos = nLastPos; - vcl::KeyCode aKeyCode = rKEvt.GetKeyCode(); - ThumbnailViewItem* pNext = nullptr; - - if (aKeyCode.IsShift() && bHasSelRange) - { - //If the last element selected is the start range position - //search for the first selected item - size_t nSelPos = mpStartSelRange - mFilteredItemList.begin(); - - if (nLastPos == nSelPos) - { - while (nLastPos && mFilteredItemList[nLastPos-1]->isSelected()) - --nLastPos; - } - } - - switch ( aKeyCode.GetCode() ) - { - case KEY_RIGHT: - if (!mFilteredItemList.empty()) - { - if ( bFoundLast && nLastPos + 1 < mFilteredItemList.size() ) - { - bValidRange = true; - nNextPos = nLastPos + 1; - } - - pNext = mFilteredItemList[nNextPos]; - } - break; - case KEY_LEFT: - if (!mFilteredItemList.empty()) - { - if ( nLastPos > 0 ) - { - bValidRange = true; - nNextPos = nLastPos - 1; - } - - pNext = mFilteredItemList[nNextPos]; - } - break; - case KEY_DOWN: - if (!mFilteredItemList.empty()) - { - if ( bFoundLast ) - { - //If we are in the second last row just go the one in - //the row below, if there's not row below just go to the - //last item but for the last row don't do anything. - if ( nLastPos + mnCols < mFilteredItemList.size( ) ) - { - bValidRange = true; - nNextPos = nLastPos + mnCols; - } - else - { - int curRow = nLastPos/mnCols; - - if (curRow < mnLines-1) - nNextPos = mFilteredItemList.size()-1; - } - } - - pNext = mFilteredItemList[nNextPos]; - } - break; - case KEY_UP: - if (!mFilteredItemList.empty()) - { - if ( nLastPos >= mnCols ) - { - bValidRange = true; - nNextPos = nLastPos - mnCols; - } - - pNext = mFilteredItemList[nNextPos]; - } - break; - case KEY_RETURN: - { - if ( bFoundLast ) - OnItemDblClicked( mFilteredItemList[nLastPos] ); - } - [[fallthrough]]; - default: - Control::KeyInput( rKEvt ); - } - - if ( !pNext ) - return; - - if (aKeyCode.IsShift() && bValidRange) - { - std::pair<size_t,size_t> aRange; - size_t nSelPos = mpStartSelRange - mFilteredItemList.begin(); - - if (nLastPos < nSelPos) - { - if (nNextPos > nLastPos) - { - if ( nNextPos > nSelPos) - aRange = std::make_pair(nLastPos,nNextPos); - else - aRange = std::make_pair(nLastPos,nNextPos-1); - } - else - aRange = std::make_pair(nNextPos,nLastPos-1); - } - else if (nLastPos == nSelPos) - { - if (nNextPos > nLastPos) - aRange = std::make_pair(nLastPos+1,nNextPos); - else - aRange = std::make_pair(nNextPos,nLastPos-1); - } - else - { - if (nNextPos > nLastPos) - aRange = std::make_pair(nLastPos+1,nNextPos); - else - { - if ( nNextPos < nSelPos) - aRange = std::make_pair(nNextPos,nLastPos); - else - aRange = std::make_pair(nNextPos+1,nLastPos); - } - } - - for (size_t i = aRange.first; i <= aRange.second; ++i) - { - if (i != nSelPos) - { - ThumbnailViewItem *pCurItem = mFilteredItemList[i]; - - pCurItem->setSelection(!pCurItem->isSelected()); - - if (pCurItem->isVisible()) - DrawItem(pCurItem); - } - } - } - else if (!aKeyCode.IsShift()) - { - deselectItems(); - SelectItem(pNext->mnId); - - //Mark it as the selection range start position - mpStartSelRange = mFilteredItemList.begin() + nNextPos; - } - - MakeItemVisible(pNext->mnId); -} - -void ThumbnailView::MakeItemVisible( sal_uInt16 nItemId ) -{ - // Get the item row - size_t nPos = 0; - bool bFound = false; - for ( size_t i = 0; !bFound && i < mFilteredItemList.size(); ++i ) - { - ThumbnailViewItem* pItem = mFilteredItemList[i]; - if ( pItem->mnId == nItemId ) - { - nPos = i; - bFound = true; - } - } - sal_uInt16 nRow = mnCols ? nPos / mnCols : 0; - - // Move the visible rows as little as possible to include that one - if ( nRow < mnFirstLine ) - mnFirstLine = nRow; - else if ( nRow > mnFirstLine + mnVisLines ) - mnFirstLine = nRow - mnVisLines; - - CalculateItemPositions(); - Invalidate(); -} - -void ThumbnailView::MouseButtonDown( const MouseEvent& rMEvt ) -{ - if ( !rMEvt.IsLeft() ) - { - Control::MouseButtonDown( rMEvt ); - return; - } - - size_t nPos = ImplGetItem(rMEvt.GetPosPixel()); - ThumbnailViewItem* pItem = ImplGetItem(nPos); - - if ( !pItem ) - { - deselectItems(); - Control::MouseButtonDown( rMEvt ); - return; - } - - if ( rMEvt.GetClicks() == 2 ) - { - OnItemDblClicked(pItem); - return; - } - - if(rMEvt.GetClicks() != 1) - return; - - if (rMEvt.IsMod1()) - { - //Keep selected item group state and just invert current desired one state - pItem->setSelection(!pItem->isSelected()); - - //This one becomes the selection range start position if it changes its state to selected otherwise resets it - mpStartSelRange = pItem->isSelected() ? mFilteredItemList.begin() + nPos : mFilteredItemList.end(); - } - else if (rMEvt.IsShift() && mpStartSelRange != mFilteredItemList.end()) - { - std::pair<size_t,size_t> aNewRange; - aNewRange.first = mpStartSelRange - mFilteredItemList.begin(); - aNewRange.second = nPos; - - if (aNewRange.first > aNewRange.second) - std::swap(aNewRange.first,aNewRange.second); - - //Deselect the ones outside of it - for (size_t i = 0, n = mFilteredItemList.size(); i < n; ++i) - { - ThumbnailViewItem *pCurItem = mFilteredItemList[i]; - - if (pCurItem->isSelected() && (i < aNewRange.first || i > aNewRange.second)) - { - pCurItem->setSelection(false); - - if (pCurItem->isVisible()) - DrawItem(pCurItem); - } - } - - size_t nSelPos = mpStartSelRange - mFilteredItemList.begin(); - - //Select the items between start range and the selected item - if (nSelPos != nPos) - { - int dir = nSelPos < nPos ? 1 : -1; - size_t nCurPos = nSelPos + dir; - - while (nCurPos != nPos) - { - ThumbnailViewItem *pCurItem = mFilteredItemList[nCurPos]; - - if (!pCurItem->isSelected()) - { - pCurItem->setSelection(true); - - if (pCurItem->isVisible()) - DrawItem(pCurItem); - } - - nCurPos += dir; - } - } - - pItem->setSelection(true); - } - else - { - //If we got a group of selected items deselect the rest and only keep the desired one - //mark items as not selected to not fire unnecessary change state events. - pItem->setSelection(false); - deselectItems(); - pItem->setSelection(true); - - //Mark as initial selection range position and reset end one - mpStartSelRange = mFilteredItemList.begin() + nPos; - } - - if (!pItem->isHighlighted()) - DrawItem(pItem); - - //fire accessible event?? -} - -void ThumbnailView::Command( const CommandEvent& rCEvt ) -{ - if ( (rCEvt.GetCommand() == CommandEventId::Wheel) || - (rCEvt.GetCommand() == CommandEventId::StartAutoScroll) || - (rCEvt.GetCommand() == CommandEventId::AutoScroll) ) - { - if ( HandleScrollCommand( rCEvt, nullptr, mpScrBar ) ) - return; - } - - Control::Command( rCEvt ); -} - -void ThumbnailView::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle& rRect) -{ - size_t nItemCount = mItemList.size(); - - // Draw background - drawinglayer::primitive2d::Primitive2DContainer aSeq(1); - aSeq[0] = drawinglayer::primitive2d::Primitive2DReference( - new PolyPolygonColorPrimitive2D( - B2DPolyPolygon( ::tools::Polygon(::tools::Rectangle(Point(), GetOutputSizePixel()), 0, 0).getB2DPolygon()), - maFillColor.getBColor())); - - // Create the processor and process the primitives - const drawinglayer::geometry::ViewInformation2D aNewViewInfos; - - std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor( - drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(rRenderContext, aNewViewInfos)); - pProcessor->process(aSeq); - - // draw items - for (size_t i = 0; i < nItemCount; i++) - { - ThumbnailViewItem *const pItem = mItemList[i].get(); - - if (pItem->isVisible()) - { - pItem->Paint(pProcessor.get(), mpItemAttrs.get()); - } - } - - if (mpScrBar && mpScrBar->IsVisible()) - mpScrBar->Invalidate(rRect); -} - -void ThumbnailView::GetFocus() -{ - // Select the first item if nothing selected - int nSelected = -1; - for (size_t i = 0, n = mItemList.size(); i < n && nSelected == -1; ++i) - { - if (mItemList[i]->isSelected()) - nSelected = i; - } - - if (nSelected == -1 && !mItemList.empty()) - { - SelectItem(1); - } - - // Tell the accessible object that we got the focus. - ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation( GetAccessible( false ) ); - if( pAcc ) - pAcc->GetFocus(); - - Control::GetFocus(); -} - -void ThumbnailView::LoseFocus() -{ - Control::LoseFocus(); - - // Tell the accessible object that we lost the focus. - ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation( GetAccessible( false ) ); - if( pAcc ) - pAcc->LoseFocus(); -} - -void ThumbnailView::Resize() -{ - Control::Resize(); - CalculateItemPositions(); - - if ( IsReallyVisible() && IsUpdateMode() ) - Invalidate(); -} - -void ThumbnailView::StateChanged( StateChangedType nType ) -{ - Control::StateChanged( nType ); - - if ( nType == StateChangedType::InitShow ) - { - if ( IsReallyVisible() && IsUpdateMode() ) - Invalidate(); - } - else if ( nType == StateChangedType::UpdateMode ) - { - if ( IsReallyVisible() && IsUpdateMode() ) - Invalidate(); - } - else if ( nType == StateChangedType::Text ) - { - } - else if ( (nType == StateChangedType::Zoom) || - (nType == StateChangedType::ControlFont) ) - { - Invalidate(); - } - else if ( nType == StateChangedType::ControlForeground ) - { - Invalidate(); - } - else if ( nType == StateChangedType::ControlBackground ) - { - Invalidate(); - } - else if ( (nType == StateChangedType::Style) || (nType == StateChangedType::Enable) ) - { - Invalidate(); - } -} - -void ThumbnailView::DataChanged( const DataChangedEvent& rDCEvt ) -{ - Control::DataChanged( rDCEvt ); - - if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) || - (rDCEvt.GetType() == DataChangedEventType::DISPLAY) || - (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) || - ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) && - (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) ) - { - Invalidate(); - } -} - -void ThumbnailView::Clear() -{ - ImplDeleteItems(); - - // reset variables - mnFirstLine = 0; - - CalculateItemPositions(); - - if ( IsReallyVisible() && IsUpdateMode() ) - Invalidate(); -} - -void ThumbnailView::updateItems (std::vector<std::unique_ptr<ThumbnailViewItem>> items) -{ - ImplDeleteItems(); - - // reset variables - mnFirstLine = 0; - - mItemList = std::move(items); - - filterItems(maFilterFunc); -} - -size_t ThumbnailView::GetItemPos( sal_uInt16 nItemId ) const -{ - for ( size_t i = 0, n = mFilteredItemList.size(); i < n; ++i ) { - if ( mFilteredItemList[i]->mnId == nItemId ) { - return i; - } - } - return THUMBNAILVIEW_ITEM_NOTFOUND; -} - -sal_uInt16 ThumbnailView::GetItemId( size_t nPos ) const -{ - return ( nPos < mFilteredItemList.size() ) ? mFilteredItemList[nPos]->mnId : 0 ; -} - -sal_uInt16 ThumbnailView::GetItemId( const Point& rPos ) const -{ - size_t nItemPos = ImplGetItem( rPos ); - if ( nItemPos != THUMBNAILVIEW_ITEM_NOTFOUND ) - return GetItemId( nItemPos ); - - return 0; -} - -void ThumbnailView::setItemMaxTextLength(sal_uInt32 nLength) -{ - mpItemAttrs->nMaxTextLength = nLength; -} - -void ThumbnailView::setItemDimensions(tools::Long itemWidth, tools::Long thumbnailHeight, tools::Long displayHeight, int itemPadding) -{ - mnItemWidth = itemWidth + 2*itemPadding; - mnThumbnailHeight = thumbnailHeight; - mnDisplayHeight = displayHeight; - mnItemPadding = itemPadding; - mnItemHeight = mnDisplayHeight + mnThumbnailHeight + 2*itemPadding; -} - -void ThumbnailView::SelectItem( sal_uInt16 nItemId ) -{ - size_t nItemPos = GetItemPos( nItemId ); - if ( nItemPos == THUMBNAILVIEW_ITEM_NOTFOUND ) - return; - - ThumbnailViewItem* pItem = mFilteredItemList[nItemPos]; - if (pItem->isSelected()) - return; - - pItem->setSelection(true); - - if (IsReallyVisible() && IsUpdateMode()) - Invalidate(); - - bool bNewOut = IsReallyVisible() && IsUpdateMode(); - - // if necessary scroll to the visible area - if (mbScroll && nItemId && mnCols) - { - sal_uInt16 nNewLine = static_cast<sal_uInt16>(nItemPos / mnCols); - if ( nNewLine < mnFirstLine ) - { - mnFirstLine = nNewLine; - } - else if ( mnVisLines != 0 && nNewLine > o3tl::make_unsigned(mnFirstLine+mnVisLines-1) ) - { - mnFirstLine = static_cast<sal_uInt16>(nNewLine-mnVisLines+1); - } - } - - if ( bNewOut ) - { - if ( IsReallyVisible() && IsUpdateMode() ) - Invalidate(); - } - - if( !ImplHasAccessibleListeners() ) - return; - - // focus event (select) - ThumbnailViewItemAcc* pItemAcc = ThumbnailViewItemAcc::getImplementation( pItem->GetAccessible( false ) ); - - if( pItemAcc ) - { - css::uno::Any aOldAny, aNewAny; - aNewAny <<= css::uno::Reference< css::uno::XInterface >( - static_cast< ::cppu::OWeakObject* >( pItemAcc )); - ImplFireAccessibleEvent( css::accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, aNewAny ); - } - - // selection event - css::uno::Any aOldAny, aNewAny; - ImplFireAccessibleEvent( css::accessibility::AccessibleEventId::SELECTION_CHANGED, aOldAny, aNewAny ); -} - -bool ThumbnailView::IsItemSelected( sal_uInt16 nItemId ) const -{ - size_t nItemPos = GetItemPos( nItemId ); - if ( nItemPos == THUMBNAILVIEW_ITEM_NOTFOUND ) - return false; - - ThumbnailViewItem* pItem = mFilteredItemList[nItemPos]; - return pItem->isSelected(); -} - -void ThumbnailView::deselectItems() -{ - for (std::unique_ptr<ThumbnailViewItem>& p : mItemList) - { - if (p->isSelected()) - { - p->setSelection(false); - } - } - - if (IsReallyVisible() && IsUpdateMode()) - Invalidate(); -} - -void ThumbnailView::ShowTooltips( bool bShowTooltips ) -{ - mbShowTooltips = bShowTooltips; -} - -void ThumbnailView::filterItems(const std::function<bool (const ThumbnailViewItem*)> &func) -{ - mnFirstLine = 0; // start at the top of the list instead of the current position - maFilterFunc = func; - - size_t nSelPos = 0; - bool bHasSelRange = false; - ThumbnailViewItem *curSel = mpStartSelRange != mFilteredItemList.end() ? *mpStartSelRange : nullptr; - - mFilteredItemList.clear(); - - for (size_t i = 0, n = mItemList.size(); i < n; ++i) - { - ThumbnailViewItem *const pItem = mItemList[i].get(); - - if (maFilterFunc(pItem)) - { - if (curSel == pItem) - { - nSelPos = i; - bHasSelRange = true; - } - - mFilteredItemList.push_back(pItem); - } - else - { - if( pItem->isVisible()) - { - if ( ImplHasAccessibleListeners() ) - { - css::uno::Any aOldAny, aNewAny; - - aOldAny <<= pItem->GetAccessible( false ); - ImplFireAccessibleEvent( css::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny ); - } - - pItem->show(false); - pItem->setSelection(false); - } - } - } - - mpStartSelRange = bHasSelRange ? mFilteredItemList.begin() + nSelPos : mFilteredItemList.end(); - CalculateItemPositions(); - - Invalidate(); -} - bool ThumbnailViewBase::renameItem(ThumbnailViewItem*, const OUString&) { // Do nothing by default @@ -1121,7 +58,7 @@ ThumbnailViewBase::~ThumbnailViewBase() { } -BitmapEx ThumbnailView::readThumbnail(const OUString &msURL) +BitmapEx SfxThumbnailView::readThumbnail(const OUString &msURL) { using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -1606,7 +543,7 @@ ThumbnailViewItem* SfxThumbnailView::ImplGetVisibleItem( sal_uInt16 nVisiblePos void SfxThumbnailView::ImplFireAccessibleEvent( short nEventId, const css::uno::Any& rOldValue, const css::uno::Any& rNewValue ) { - ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation(mxAccessible); + SfxThumbnailViewAcc* pAcc = SfxThumbnailViewAcc::getImplementation(mxAccessible); if( pAcc ) pAcc->FireAccessibleEvent( nEventId, rOldValue, rNewValue ); @@ -1614,7 +551,7 @@ void SfxThumbnailView::ImplFireAccessibleEvent( short nEventId, const css::uno:: bool SfxThumbnailView::ImplHasAccessibleListeners() { - ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation(mxAccessible); + SfxThumbnailViewAcc* pAcc = SfxThumbnailViewAcc::getImplementation(mxAccessible); return( pAcc && pAcc->HasAccessibleListeners() ); } @@ -2018,7 +955,7 @@ void SfxThumbnailView::GetFocus() } // Tell the accessible object that we got the focus. - ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation(mxAccessible); + SfxThumbnailViewAcc* pAcc = SfxThumbnailViewAcc::getImplementation(mxAccessible); if( pAcc ) pAcc->GetFocus(); @@ -2030,7 +967,7 @@ void SfxThumbnailView::LoseFocus() CustomWidgetController::LoseFocus(); // Tell the accessible object that we lost the focus. - ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation(mxAccessible); + SfxThumbnailViewAcc* pAcc = SfxThumbnailViewAcc::getImplementation(mxAccessible); if( pAcc ) pAcc->LoseFocus(); } diff --git a/sfx2/source/control/thumbnailviewacc.cxx b/sfx2/source/control/thumbnailviewacc.cxx index 53423bd567ae..d439cf43d4cf 100644 --- a/sfx2/source/control/thumbnailviewacc.cxx +++ b/sfx2/source/control/thumbnailviewacc.cxx @@ -36,58 +36,33 @@ using namespace ::com::sun::star; -ThumbnailViewAcc::ThumbnailViewAcc( ThumbnailView* pParent ) : +SfxThumbnailViewAcc::SfxThumbnailViewAcc( SfxThumbnailView* pParent ) : ValueSetAccComponentBase (m_aMutex), mpParent( pParent ), mbIsFocused(false) { } -ThumbnailViewAcc::~ThumbnailViewAcc() +SfxThumbnailViewAcc::~SfxThumbnailViewAcc() { } -void ThumbnailViewAcc::FireAccessibleEvent( short nEventId, const uno::Any& rOldValue, const uno::Any& rNewValue ) -{ - if( !nEventId ) - return; - - ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > > aTmpListeners( mxEventListeners ); - accessibility::AccessibleEventObject aEvtObject; - - aEvtObject.EventId = nEventId; - aEvtObject.Source = static_cast<uno::XWeak*>(this); - aEvtObject.NewValue = rNewValue; - aEvtObject.OldValue = rOldValue; - - for (auto const& tmpListener : aTmpListeners) - { - try - { - tmpListener->notifyEvent( aEvtObject ); - } - catch(const uno::Exception&) - { - } - } -} - namespace { - class theValueSetAccUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theValueSetAccUnoTunnelId > {}; + class theSfxValueSetAccUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSfxValueSetAccUnoTunnelId > {}; } -const uno::Sequence< sal_Int8 >& ThumbnailViewAcc::getUnoTunnelId() +const uno::Sequence< sal_Int8 >& SfxThumbnailViewAcc::getUnoTunnelId() { - return theValueSetAccUnoTunnelId::get().getSeq(); + return theSfxValueSetAccUnoTunnelId::get().getSeq(); } -ThumbnailViewAcc* ThumbnailViewAcc::getImplementation( const uno::Reference< uno::XInterface >& rxData ) +SfxThumbnailViewAcc* SfxThumbnailViewAcc::getImplementation( const uno::Reference< uno::XInterface >& rxData ) throw() { try { - return comphelper::getUnoTunnelImplementation<ThumbnailViewAcc>(rxData); + return comphelper::getUnoTunnelImplementation<SfxThumbnailViewAcc>(rxData); } catch(const css::uno::Exception&) { @@ -95,481 +70,6 @@ ThumbnailViewAcc* ThumbnailViewAcc::getImplementation( const uno::Reference< uno } } -void ThumbnailViewAcc::GetFocus() -{ - mbIsFocused = true; - - // Broadcast the state change. - css::uno::Any aOldState, aNewState; - aNewState <<= css::accessibility::AccessibleStateType::FOCUSED; - FireAccessibleEvent( - css::accessibility::AccessibleEventId::STATE_CHANGED, - aOldState, aNewState); -} - -void ThumbnailViewAcc::LoseFocus() -{ - mbIsFocused = false; - - // Broadcast the state change. - css::uno::Any aOldState, aNewState; - aOldState <<= css::accessibility::AccessibleStateType::FOCUSED; - FireAccessibleEvent( - css::accessibility::AccessibleEventId::STATE_CHANGED, - aOldState, aNewState); -} - -uno::Reference< accessibility::XAccessibleContext > SAL_CALL ThumbnailViewAcc::getAccessibleContext() -{ - ThrowIfDisposed(); - return this; -} - -sal_Int32 SAL_CALL ThumbnailViewAcc::getAccessibleChildCount() -{ - const SolarMutexGuard aSolarGuard; - ThrowIfDisposed(); - - sal_Int32 nCount = mpParent->ImplGetVisibleItemCount(); - return nCount; -} - -uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAccessibleChild( sal_Int32 i ) -{ - ThrowIfDisposed(); - const SolarMutexGuard aSolarGuard; - ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(i)); - - if( !pItem ) - throw lang::IndexOutOfBoundsException(); - - uno::Reference< accessibility::XAccessible > xRet = pItem->GetAccessible( /*bIsTransientChildrenDisabled*/false ); - return xRet; -} - -uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAccessibleParent() -{ - ThrowIfDisposed(); - const SolarMutexGuard aSolarGuard; - vcl::Window* pParent = mpParent->GetParent(); - uno::Reference< accessibility::XAccessible > xRet; - - if( pParent ) - xRet = pParent->GetAccessible(); - - return xRet; -} - -sal_Int32 SAL_CALL ThumbnailViewAcc::getAccessibleIndexInParent() -{ - ThrowIfDisposed(); - const SolarMutexGuard aSolarGuard; - vcl::Window* pParent = mpParent->GetParent(); - sal_Int32 nRet = 0; - - if( pParent ) - { - bool bFound = false; - - for( sal_uInt16 i = 0, nCount = pParent->GetChildCount(); ( i < nCount ) && !bFound; i++ ) - { - if( pParent->GetChild( i ) == mpParent ) - { - nRet = i; - bFound = true; - } - } - } - - return nRet; -} - -sal_Int16 SAL_CALL ThumbnailViewAcc::getAccessibleRole() -{ - ThrowIfDisposed(); - // #i73746# As the Java Access Bridge (v 2.0.1) uses "managesDescendants" - // always if the role is LIST, we need a different role in this case - return accessibility::AccessibleRole::LIST; -} - -OUString SAL_CALL ThumbnailViewAcc::getAccessibleDescription() -{ - ThrowIfDisposed(); - return "ThumbnailView"; -} - -OUString SAL_CALL ThumbnailViewAcc::getAccessibleName() -{ - ThrowIfDisposed(); - const SolarMutexGuard aSolarGuard; - OUString aRet; - - if ( mpParent ) - { - aRet = mpParent->GetAccessibleName(); - if (aRet.isEmpty()) - { - vcl::Window* pLabel = mpParent->GetAccessibleRelationLabeledBy(); - if (pLabel && pLabel != mpParent) - aRet = OutputDevice::GetNonMnemonicString( pLabel->GetText() ); - } - } - - return aRet; -} - -uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ThumbnailViewAcc::getAccessibleRelationSet() -{ - ThrowIfDisposed(); - return uno::Reference< accessibility::XAccessibleRelationSet >(); -} - -uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ThumbnailViewAcc::getAccessibleStateSet() -{ - ThrowIfDisposed(); - ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper(); - - // Set some states. - pStateSet->AddState (accessibility::AccessibleStateType::ENABLED); - pStateSet->AddState (accessibility::AccessibleStateType::SENSITIVE); - pStateSet->AddState (accessibility::AccessibleStateType::SHOWING); - pStateSet->AddState (accessibility::AccessibleStateType::VISIBLE); - pStateSet->AddState (accessibility::AccessibleStateType::MANAGES_DESCENDANTS); - pStateSet->AddState (accessibility::AccessibleStateType::FOCUSABLE); - if (mbIsFocused) - pStateSet->AddState (accessibility::AccessibleStateType::FOCUSED); - - return pStateSet; -} - -lang::Locale SAL_CALL ThumbnailViewAcc::getLocale() -{ - ThrowIfDisposed(); - const SolarMutexGuard aSolarGuard; - uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() ); - lang::Locale aRet( "", "", "" ); - - if( xParent.is() ) - { - uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() ); - - if( xParentContext.is() ) - aRet = xParentContext->getLocale (); - } - - return aRet; -} - -void SAL_CALL ThumbnailViewAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener ) -{ - ThrowIfDisposed(); - ::osl::MutexGuard aGuard (m_aMutex); - - if( !rxListener.is() ) - return; - - bool bFound = false; - - for (auto const& eventListener : mxEventListeners) - { - if( eventListener == rxListener ) - { - bFound = true; - break; - } - } - - if (!bFound) - mxEventListeners.push_back( rxListener ); -} - -void SAL_CALL ThumbnailViewAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener ) -{ - ThrowIfDisposed(); - ::osl::MutexGuard aGuard (m_aMutex); - - if( rxListener.is() ) - { - std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter = - std::find(mxEventListeners.begin(), mxEventListeners.end(), rxListener); - - if (aIter != mxEventListeners.end()) - mxEventListeners.erase( aIter ); - } -} - -sal_Bool SAL_CALL ThumbnailViewAcc::containsPoint( const awt::Point& aPoint ) -{ - ThrowIfDisposed(); - const awt::Rectangle aRect( getBounds() ); - const Point aSize( aRect.Width, aRect.Height ); - const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y ); - - return tools::Rectangle( aNullPoint, aSize ).IsInside( aTestPoint ); -} - -uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAccessibleAtPoint( const awt::Point& aPoint ) -{ - ThrowIfDisposed(); - const SolarMutexGuard aSolarGuard; - const sal_uInt16 nItemId = mpParent->GetItemId( Point( aPoint.X, aPoint.Y ) ); - uno::Reference< accessibility::XAccessible > xRet; - - if ( nItemId ) - { - const size_t nItemPos = mpParent->GetItemPos( nItemId ); - - if( THUMBNAILVIEW_ITEM_NONEITEM != nItemPos ) - { - ThumbnailViewItem *const pItem = mpParent->mFilteredItemList[nItemPos]; - xRet = pItem->GetAccessible( /*bIsTransientChildrenDisabled*/false ); - } - } - - return xRet; -} - -awt::Rectangle SAL_CALL ThumbnailViewAcc::getBounds() -{ - ThrowIfDisposed(); - const SolarMutexGuard aSolarGuard; - const Point aOutPos( mpParent->GetPosPixel() ); - const Size aOutSize( mpParent->GetOutputSizePixel() ); - awt::Rectangle aRet; - - aRet.X = aOutPos.X(); - aRet.Y = aOutPos.Y(); - aRet.Width = aOutSize.Width(); - aRet.Height = aOutSize.Height(); - - return aRet; -} - -awt::Point SAL_CALL ThumbnailViewAcc::getLocation() -{ - ThrowIfDisposed(); - const awt::Rectangle aRect( getBounds() ); - awt::Point aRet; - - aRet.X = aRect.X; - aRet.Y = aRect.Y; - - return aRet; -} - -awt::Point SAL_CALL ThumbnailViewAcc::getLocationOnScreen() -{ - ThrowIfDisposed(); - const SolarMutexGuard aSolarGuard; - const Point aScreenPos( mpParent->OutputToAbsoluteScreenPixel( Point() ) ); - awt::Point aRet; - - aRet.X = aScreenPos.X(); - aRet.Y = aScreenPos.Y(); - - return aRet; -} - -awt::Size SAL_CALL ThumbnailViewAcc::getSize() -{ - ThrowIfDisposed(); - const awt::Rectangle aRect( getBounds() ); - awt::Size aRet; - - aRet.Width = aRect.Width; - aRet.Height = aRect.Height; - - return aRet; -} - -void SAL_CALL ThumbnailViewAcc::grabFocus() -{ - ThrowIfDisposed(); - const SolarMutexGuard aSolarGuard; - mpParent->GrabFocus(); -} - -sal_Int32 SAL_CALL ThumbnailViewAcc::getForeground( ) -{ - ThrowIfDisposed(); - Color nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor(); - return static_cast<sal_Int32>(nColor); -} - -sal_Int32 SAL_CALL ThumbnailViewAcc::getBackground( ) -{ - ThrowIfDisposed(); - Color nColor = Application::GetSettings().GetStyleSettings().GetWindowColor(); - return static_cast<sal_Int32>(nColor); -} - -void SAL_CALL ThumbnailViewAcc::selectAccessibleChild( sal_Int32 nChildIndex ) -{ - ThrowIfDisposed(); - const SolarMutexGuard aSolarGuard; - ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex)); - - if(pItem == nullptr) - throw lang::IndexOutOfBoundsException(); - - mpParent->SelectItem( pItem->mnId ); -} - -sal_Bool SAL_CALL ThumbnailViewAcc::isAccessibleChildSelected( sal_Int32 nChildIndex ) -{ - ThrowIfDisposed(); - const SolarMutexGuard aSolarGuard; - ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex)); - - if (pItem == nullptr) - throw lang::IndexOutOfBoundsException(); - - return mpParent->IsItemSelected( pItem->mnId ); -} - -void SAL_CALL ThumbnailViewAcc::clearAccessibleSelection() -{ - ThrowIfDisposed(); -} - -void SAL_CALL ThumbnailViewAcc::selectAllAccessibleChildren() -{ - ThrowIfDisposed(); - // unsupported due to single selection only -} - -sal_Int32 SAL_CALL ThumbnailViewAcc::getSelectedAccessibleChildCount() -{ - ThrowIfDisposed(); - const SolarMutexGuard aSolarGuard; - sal_Int32 nRet = 0; - - for( sal_uInt16 i = 0, nCount = getItemCount(); i < nCount; i++ ) - { - ThumbnailViewItem* pItem = getItem (i); - - if( pItem && mpParent->IsItemSelected( pItem->mnId ) ) - ++nRet; - } - - return nRet; -} - -uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) -{ - ThrowIfDisposed(); - const SolarMutexGuard aSolarGuard; - uno::Reference< accessibility::XAccessible > xRet; - - for( sal_uInt16 i = 0, nCount = getItemCount(), nSel = 0; ( i < nCount ) && !xRet.is(); i++ ) - { - ThumbnailViewItem* pItem = getItem(i); - - if( pItem && mpParent->IsItemSelected( pItem->mnId ) && ( nSelectedChildIndex == static_cast< sal_Int32 >( nSel++ ) ) ) - xRet = pItem->GetAccessible( /*bIsTransientChildrenDisabled*/false ); - } - - return xRet; -} - -void SAL_CALL ThumbnailViewAcc::deselectAccessibleChild( sal_Int32 ) -{ - ThrowIfDisposed(); - const SolarMutexGuard aSolarGuard; - // Because of the single selection we can reset the whole selection when - // the specified child is currently selected. -//FIXME TODO if (isAccessibleChildSelected(nChildIndex)) -//FIXME TODO ; -} - -sal_Int64 SAL_CALL ThumbnailViewAcc::getSomething( const uno::Sequence< sal_Int8 >& rId ) -{ - sal_Int64 nRet; - - if( isUnoTunnelId<ThumbnailViewAcc>(rId) ) - nRet = reinterpret_cast< sal_Int64 >( this ); - else - nRet = 0; - - return nRet; -} - -void SAL_CALL ThumbnailViewAcc::disposing() -{ - ::std::vector<uno::Reference<accessibility::XAccessibleEventListener> > aListenerListCopy; - - { - // Make a copy of the list and clear the original. - const SolarMutexGuard aSolarGuard; - ::osl::MutexGuard aGuard (m_aMutex); - aListenerListCopy = mxEventListeners; - mxEventListeners.clear(); - - // Reset the pointer to the parent. It has to be the one who has - // disposed us because he is dying. - mpParent = nullptr; - } - - // Inform all listeners that this objects is disposing. - lang::EventObject aEvent (static_cast<accessibility::XAccessible*>(this)); - for (auto const& listener : aListenerListCopy) - { - try - { - listener->disposing (aEvent); - } - catch(const uno::Exception&) - { - // Ignore exceptions. - } - } -} - -sal_uInt16 ThumbnailViewAcc::getItemCount() const -{ - return mpParent->ImplGetVisibleItemCount(); -} - -ThumbnailViewItem* ThumbnailViewAcc::getItem (sal_uInt16 nIndex) const -{ - return mpParent->ImplGetVisibleItem (nIndex); -} - -void ThumbnailViewAcc::ThrowIfDisposed() -{ - if (rBHelper.bDisposed || rBHelper.bInDispose) - { - SAL_WARN("sfx", "Calling disposed object. Throwing exception:"); - throw lang::DisposedException ( - "object has been already disposed", - static_cast<uno::XWeak*>(this)); - } - else - { - DBG_ASSERT (mpParent!=nullptr, "ValueSetAcc not disposed but mpParent == NULL"); - } -} - -SfxThumbnailViewAcc::SfxThumbnailViewAcc( SfxThumbnailView* pParent ) : - ValueSetAccComponentBase (m_aMutex), - mpParent( pParent ) -{ -} - -SfxThumbnailViewAcc::~SfxThumbnailViewAcc() -{ -} - -namespace -{ - class theSfxValueSetAccUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSfxValueSetAccUnoTunnelId > {}; -} - -const uno::Sequence< sal_Int8 >& SfxThumbnailViewAcc::getUnoTunnelId() -{ - return theSfxValueSetAccUnoTunnelId::get().getSeq(); -} - uno::Reference< accessibility::XAccessibleContext > SAL_CALL SfxThumbnailViewAcc::getAccessibleContext() { ThrowIfDisposed(); @@ -1026,6 +526,31 @@ void ThumbnailViewItemAcc::ParentDestroyed() mpParent = nullptr; } +void SfxThumbnailViewAcc::FireAccessibleEvent( short nEventId, const uno::Any& rOldValue, const uno::Any& rNewValue ) +{ + if( !nEventId ) + return; + + ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > > aTmpListeners( mxEventListeners ); + accessibility::AccessibleEventObject aEvtObject; + + aEvtObject.EventId = nEventId; + aEvtObject.Source = static_cast<uno::XWeak*>(this); + aEvtObject.NewValue = rNewValue; + aEvtObject.OldValue = rOldValue; + + for (auto const& tmpListener : aTmpListeners) + { + try + { + tmpListener->notifyEvent( aEvtObject ); + } + catch(const uno::Exception&) + { + } + } +} + namespace { class theValueItemAccUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theValueItemAccUnoTunnelId > {}; @@ -1049,6 +574,30 @@ ThumbnailViewItemAcc* ThumbnailViewItemAcc::getImplementation( const uno::Refere } } +void SfxThumbnailViewAcc::GetFocus() +{ + mbIsFocused = true; + + // Broadcast the state change. + css::uno::Any aOldState, aNewState; + aNewState <<= css::accessibility::AccessibleStateType::FOCUSED; + FireAccessibleEvent( + css::accessibility::AccessibleEventId::STATE_CHANGED, + aOldState, aNewState); +} + +void SfxThumbnailViewAcc::LoseFocus() +{ + mbIsFocused = false; + + // Broadcast the state change. + css::uno::Any aOldState, aNewState; + aOldState <<= css::accessibility::AccessibleStateType::FOCUSED; + FireAccessibleEvent( + css::accessibility::AccessibleEventId::STATE_CHANGED, + aOldState, aNewState); +} + uno::Reference< accessibility::XAccessibleContext > SAL_CALL ThumbnailViewItemAcc::getAccessibleContext() { return this; diff --git a/sfx2/source/control/thumbnailviewacc.hxx b/sfx2/source/control/thumbnailviewacc.hxx index 1aaed600a9b0..9679eaa3b8fa 100644 --- a/sfx2/source/control/thumbnailviewacc.hxx +++ b/sfx2/source/control/thumbnailviewacc.hxx @@ -35,7 +35,6 @@ #include <vcl/vclptr.hxx> #include <vector> -class ThumbnailView; class SfxThumbnailView; class ThumbnailViewItem; @@ -48,14 +47,14 @@ typedef ::cppu::WeakComponentImplHelper< css::lang::XUnoTunnel > ValueSetAccComponentBase; -class ThumbnailViewAcc : +class SfxThumbnailViewAcc : public ::cppu::BaseMutex, public ValueSetAccComponentBase { public: - ThumbnailViewAcc( ThumbnailView* pParent ); - virtual ~ThumbnailViewAcc() override; + SfxThumbnailViewAcc( SfxThumbnailView* pParent ); + virtual ~SfxThumbnailViewAcc() override; void FireAccessibleEvent( short nEventId, const css::uno::Any& rOldValue, @@ -63,10 +62,9 @@ public: bool HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); } - static ThumbnailViewAcc* getImplementation( const css::uno::Reference< css::uno::XInterface >& rxData ) throw(); + static SfxThumbnailViewAcc* getImplementation( const css::uno::Reference< css::uno::XInterface >& rxData ) throw(); public: - /** Called by the corresponding ValueSet when it gets the focus. Stores the new focus state and broadcasts a state change event. */ @@ -123,7 +121,7 @@ public: private: ::std::vector< css::uno::Reference< css::accessibility::XAccessibleEventListener > > mxEventListeners; - VclPtr<ThumbnailView> mpParent; + SfxThumbnailView* mpParent; /// The current FOCUSED state. bool mbIsFocused; @@ -157,95 +155,6 @@ private: void ThrowIfDisposed(); }; -class SfxThumbnailViewAcc : - public ::cppu::BaseMutex, - public ValueSetAccComponentBase -{ -public: - - SfxThumbnailViewAcc( SfxThumbnailView* pParent ); - virtual ~SfxThumbnailViewAcc() override; - -public: - - // XAccessible - virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) override; - - // XAccessibleEventBroadcaster - virtual void SAL_CALL addAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override; - virtual void SAL_CALL removeAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override; - - // XAccessibleContext - virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) override; - virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) override; - virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) override; - virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) override; - virtual sal_Int16 SAL_CALL getAccessibleRole( ) override; - virtual OUString SAL_CALL getAccessibleDescription( ) override; - virtual OUString SAL_CALL getAccessibleName( ) override; - virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) override; - virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) override; - virtual css::lang::Locale SAL_CALL getLocale( ) override; - - // XAccessibleComponent - virtual sal_Bool SAL_CALL containsPoint( const css::awt::Point& aPoint ) override; - virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const css::awt::Point& aPoint ) override; - virtual css::awt::Rectangle SAL_CALL getBounds( ) override; - virtual css::awt::Point SAL_CALL getLocation( ) override; - virtual css::awt::Point SAL_CALL getLocationOnScreen( ) override; - virtual css::awt::Size SAL_CALL getSize( ) override; - virtual void SAL_CALL grabFocus( ) override; - virtual sal_Int32 SAL_CALL getForeground( ) override; - virtual sal_Int32 SAL_CALL getBackground( ) override; - - // XAccessibleSelection - virtual void SAL_CALL selectAccessibleChild( sal_Int32 nChildIndex ) override; - virtual sal_Bool SAL_CALL isAccessibleChildSelected( sal_Int32 nChildIndex ) override; - virtual void SAL_CALL clearAccessibleSelection( ) override; - virtual void SAL_CALL selectAllAccessibleChildren( ) override; - virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount( ) override; - virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) override; - virtual void SAL_CALL deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) override; - - // XUnoTunnel - static const css::uno::Sequence< sal_Int8 >& getUnoTunnelId(); - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& rId ) override; - -private: - ::std::vector< css::uno::Reference< - css::accessibility::XAccessibleEventListener > > mxEventListeners; - SfxThumbnailView* mpParent; - - /** Tell all listeners that the object is dying. This callback is - usually called from the WeakComponentImplHelper class. - */ - virtual void SAL_CALL disposing() override; - - /** Return the number of items. This takes the None-Item into account. - */ - sal_uInt16 getItemCount() const; - - /** Return the item associated with the given index. The None-Item is - taken into account which, when present, is taken to be the first - (with index 0) item. - @param nIndex - Index of the item to return. The index 0 denotes the None-Item - when present. - @return - Returns NULL when the given index is out of range. - */ - ThumbnailViewItem* getItem (sal_uInt16 nIndex) const; - - /** Check whether or not the object has been disposed (or is in the - state of being disposed). If that is the case then - DisposedException is thrown to inform the (indirect) caller of the - foul deed. - - @throws css::lang::DisposedException - */ - void ThrowIfDisposed(); -}; - class ThumbnailViewItemAcc : public ::cppu::WeakImplHelper< css::accessibility::XAccessible, css::accessibility::XAccessibleEventBroadcaster, |