Kaydet (Commit) 43bbcfc7 authored tarafından Cédric Bosdonnat's avatar Cédric Bosdonnat Kaydeden (comit) Fridrich Strba

fdo#61390: simple keybard support in TemplateManager

Adds support for the UP, DOWN, LEFT, RIGHT and RETURN keys in the
thumbnails view but doesn't handle the modifiers yet. There are still
some problems with the focus and key input outside the top level

(cherry picked from commit ee819bdd)

Conflicts:
	sfx2/source/control/thumbnailview.cxx

Change-Id: I5ba67583c835bcc00b075071411c0d6590a07f9a
Reviewed-on: https://gerrit.libreoffice.org/2912Reviewed-by: 's avatarFridrich Strba <fridrich@documentfoundation.org>
Tested-by: 's avatarFridrich Strba <fridrich@documentfoundation.org>
üst e2ce03c2
...@@ -202,6 +202,8 @@ public: ...@@ -202,6 +202,8 @@ public:
void SelectItem( sal_uInt16 nItemId ); void SelectItem( sal_uInt16 nItemId );
void DeselectItem( sal_uInt16 nItemId );
bool IsItemSelected( sal_uInt16 nItemId ) const; bool IsItemSelected( sal_uInt16 nItemId ) const;
void deselectItem (const sal_uInt16 nItemId); void deselectItem (const sal_uInt16 nItemId);
...@@ -239,6 +241,8 @@ public: ...@@ -239,6 +241,8 @@ public:
protected: protected:
virtual void KeyInput( const KeyEvent& rKEvt );
virtual void MouseButtonDown( const MouseEvent& rMEvt ); virtual void MouseButtonDown( const MouseEvent& rMEvt );
virtual void MouseButtonUp( const MouseEvent& rMEvt ); virtual void MouseButtonUp( const MouseEvent& rMEvt );
...@@ -272,8 +276,6 @@ protected: ...@@ -272,8 +276,6 @@ protected:
using Control::ImplInitSettings; using Control::ImplInitSettings;
using Window::ImplInit; using Window::ImplInit;
void calculateColumnsRows ();
void CalculateItemPositions (); void CalculateItemPositions ();
SFX2_DLLPRIVATE void ImplInit(); SFX2_DLLPRIVATE void ImplInit();
...@@ -294,6 +296,7 @@ protected: ...@@ -294,6 +296,7 @@ protected:
protected: protected:
ValueItemList mItemList; ValueItemList mItemList;
ValueItemList mFilteredItemList; ///< Cache to store the filtered items
ScrollBar* mpScrBar; ScrollBar* mpScrBar;
Rectangle maItemListRect; Rectangle maItemListRect;
long mnHeaderHeight; long mnHeaderHeight;
......
...@@ -214,6 +214,8 @@ void ThumbnailView::CalculateItemPositions () ...@@ -214,6 +214,8 @@ void ThumbnailView::CalculateItemPositions ()
WinBits nStyle = GetStyle(); WinBits nStyle = GetStyle();
ScrollBar* pDelScrBar = NULL; ScrollBar* pDelScrBar = NULL;
mFilteredItemList.clear();
// consider the scrolling // consider the scrolling
if ( nStyle & WB_VSCROLL ) if ( nStyle & WB_VSCROLL )
ImplInitScrollBar(); ImplInitScrollBar();
...@@ -298,6 +300,7 @@ void ThumbnailView::CalculateItemPositions () ...@@ -298,6 +300,7 @@ void ThumbnailView::CalculateItemPositions ()
if (maFilterFunc(pItem)) if (maFilterFunc(pItem))
{ {
mFilteredItemList.push_back(pItem);
if ((nCurCount >= nFirstItem) && (nCurCount < nLastItem)) if ((nCurCount >= nFirstItem) && (nCurCount < nLastItem))
{ {
if( !pItem->isVisible()) if( !pItem->isVisible())
...@@ -490,6 +493,73 @@ IMPL_LINK (ThumbnailView, OnItemSelected, ThumbnailViewItem*, pItem) ...@@ -490,6 +493,73 @@ IMPL_LINK (ThumbnailView, OnItemSelected, ThumbnailViewItem*, pItem)
return 0; return 0;
} }
void ThumbnailView::KeyInput( const KeyEvent& rKEvt )
{
// Get the last selected item in the list
size_t nLastPos = 0;
bool bFoundLast = false;
for ( long i = mFilteredItemList.size() - 1; !bFoundLast && i >= 0; --i )
{
ThumbnailViewItem* pItem = mFilteredItemList[i];
if ( pItem->isSelected() )
{
nLastPos = i;
bFoundLast = true;
}
}
KeyCode aKeyCode = rKEvt.GetKeyCode();
ThumbnailViewItem* pNext = NULL;
switch ( aKeyCode.GetCode() )
{
case KEY_RIGHT:
{
size_t nNextPos = nLastPos;
if ( bFoundLast && nLastPos < mFilteredItemList.size( ) - 1 )
nNextPos = nLastPos + 1;
pNext = mFilteredItemList[nNextPos];
}
break;
case KEY_LEFT:
{
size_t nNextPos = nLastPos;
if ( nLastPos > 0 )
nNextPos = nLastPos - 1;
pNext = mFilteredItemList[nNextPos];
}
break;
case KEY_DOWN:
{
size_t nNextPos = nLastPos;
if ( bFoundLast && nLastPos < mFilteredItemList.size( ) - mnCols )
nNextPos = nLastPos + mnCols;
pNext = mFilteredItemList[nNextPos];
}
break;
case KEY_UP:
{
size_t nNextPos = nLastPos;
if ( nLastPos >= mnCols )
nNextPos = nLastPos - mnCols;
pNext = mFilteredItemList[nNextPos];
}
break;
case KEY_RETURN:
{
if ( bFoundLast )
OnItemDblClicked( mFilteredItemList[nLastPos] );
}
default:
Control::KeyInput( rKEvt );
}
if ( pNext && pNext->isVisible() )
{
deselectItems();
SelectItem(pNext->mnId);
}
}
void ThumbnailView::MouseButtonDown( const MouseEvent& rMEvt ) void ThumbnailView::MouseButtonDown( const MouseEvent& rMEvt )
{ {
if ( rMEvt.IsLeft() ) if ( rMEvt.IsLeft() )
...@@ -500,12 +570,17 @@ void ThumbnailView::MouseButtonDown( const MouseEvent& rMEvt ) ...@@ -500,12 +570,17 @@ void ThumbnailView::MouseButtonDown( const MouseEvent& rMEvt )
{ {
if ( rMEvt.GetClicks() == 1 ) if ( rMEvt.GetClicks() == 1 )
{ {
if (!pItem->isSelected() && !rMEvt.IsMod1()) if (pItem->isSelected() && rMEvt.IsMod1())
deselectItems( ); DeselectItem( pItem->mnId );
pItem->setSelection(true); else
{
if (!pItem->isSelected() && !rMEvt.IsMod1())
deselectItems( );
SelectItem( pItem->mnId );
bool bClickOnTitle = pItem->getTextArea().IsInside(rMEvt.GetPosPixel()); bool bClickOnTitle = pItem->getTextArea().IsInside(rMEvt.GetPosPixel());
pItem->setEditTitle(bClickOnTitle); pItem->setEditTitle(bClickOnTitle);
}
if (!pItem->isHighlighted()) if (!pItem->isHighlighted())
DrawItem(pItem); DrawItem(pItem);
...@@ -851,6 +926,25 @@ void ThumbnailView::deselectItem(const sal_uInt16 nItemId) ...@@ -851,6 +926,25 @@ void ThumbnailView::deselectItem(const sal_uInt16 nItemId)
} }
} }
void ThumbnailView::DeselectItem( sal_uInt16 nItemId )
{
size_t nItemPos = GetItemPos( nItemId );
if ( nItemPos == THUMBNAILVIEW_ITEM_NOTFOUND )
return;
ThumbnailViewItem* pItem = mItemList[nItemPos];
if (pItem->isSelected())
{
mItemList[nItemPos]->setSelection(false);
maItemStateHdl.Call(mItemList[nItemPos]);
if (IsReallyVisible() && IsUpdateMode())
Invalidate();
// TODO Trigger event in accessible object?
}
}
bool ThumbnailView::IsItemSelected( sal_uInt16 nItemId ) const bool ThumbnailView::IsItemSelected( sal_uInt16 nItemId ) const
{ {
size_t nItemPos = GetItemPos( nItemId ); size_t nItemPos = GetItemPos( nItemId );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment