From ec2f84b376f595b0553297d25b7716f6b97e1b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Date: Wed, 20 Mar 2013 17:06:31 +0100 Subject: [PATCH] Template Manager: select first item when getting focus if no selection Change-Id: Ie012e010ca92728725535345c76fc9f5eb31a254 --- sfx2/source/control/thumbnailview.cxx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx index 78f8e32b43ae..3695068226f9 100644 --- a/sfx2/source/control/thumbnailview.cxx +++ b/sfx2/source/control/thumbnailview.cxx @@ -576,12 +576,29 @@ void ThumbnailView::Paint( const Rectangle &aRect) void ThumbnailView::GetFocus() { - Control::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.size( ) > 0 ) + { + mItemList[0]->setSelection(true); + maItemStateHdl.Call(mItemList[0]); + + if (IsReallyVisible() && IsUpdateMode()) + Invalidate(); + } // Tell the accessible object that we got the focus. ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation( GetAccessible( sal_False ) ); if( pAcc ) pAcc->GetFocus(); + + Control::GetFocus(); } void ThumbnailView::LoseFocus()