tdf#115600 Display messages in Findbar for Table navigation

...and make Table navigation wrap

Change-Id: Iac645cb7db65517519cfb791ca1eb26f2567ee7c
Reviewed-on: https://gerrit.libreoffice.org/52865
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/include/svx/srchdlg.hxx b/include/svx/srchdlg.hxx
index f655931..748ced9 100644
--- a/include/svx/srchdlg.hxx
+++ b/include/svx/srchdlg.hxx
@@ -88,7 +88,8 @@ enum class SearchLabel
    EndSheet,
    NotFound,
    StartWrapped,
    EndWrapped
    EndWrapped,
    NavElementNotFound
};

class SvxSearchDialog;
diff --git a/include/svx/strings.hrc b/include/svx/strings.hrc
index 9593cf5..c38e028 100644
--- a/include/svx/strings.hrc
+++ b/include/svx/strings.hrc
@@ -1255,6 +1255,7 @@
#define RID_SVXSTR_SEARCH_END_WRAPPED                       NC_("RID_SVXSTR_SEARCH_END_WRAPPED", "Reached the end of the document, continued from the beginning")
#define RID_SVXSTR_SEARCH_END_SHEET                         NC_("RID_SVXSTR_SEARCH_END_SHEET", "Reached the end of the sheet")
#define RID_SVXSTR_SEARCH_NOT_FOUND                         NC_("RID_SVXSTR_SEARCH_NOT_FOUND", "Search key not found")
#define RID_SVXSTR_SEARCH_NAV_ELEMENT_NOT_FOUND             NC_("RID_SVXSTR_SEARCH_NAV_ELEMENT_NOT_FOUND", "Navigation Element not found")
#define RID_SVXSTR_SEARCH_START                             NC_("RID_SVXSTR_SEARCH_START", "Reached the beginning of the document")
#define RID_SVXSTR_SEARCH_START_WRAPPED                     NC_("RID_SVXSTR_SEARCH_START_WRAPPED", "Reached the beginning of the document, continued from the end")

diff --git a/svx/source/dialog/srchdlg.cxx b/svx/source/dialog/srchdlg.cxx
index 628d9c9..71f65c8 100644
--- a/svx/source/dialog/srchdlg.cxx
+++ b/svx/source/dialog/srchdlg.cxx
@@ -2448,6 +2448,8 @@ void SvxSearchDialogWrapper::SetSearchLabel(const SearchLabel& rSL)
        sStr = SvxResId(RID_SVXSTR_SEARCH_END_SHEET);
    else if (rSL == SearchLabel::NotFound)
        sStr = SvxResId(RID_SVXSTR_SEARCH_NOT_FOUND);
    else if (rSL == SearchLabel::NavElementNotFound)
        sStr = SvxResId(RID_SVXSTR_SEARCH_NAV_ELEMENT_NOT_FOUND);

    lcl_SetSearchLabelWindow(sStr);
    if (SvxSearchDialogWrapper *pWrp = static_cast<SvxSearchDialogWrapper*>( SfxViewFrame::Current()->
diff --git a/sw/source/core/crsr/trvltbl.cxx b/sw/source/core/crsr/trvltbl.cxx
index 051dffe..43a5f7e 100644
--- a/sw/source/core/crsr/trvltbl.cxx
+++ b/sw/source/core/crsr/trvltbl.cxx
@@ -38,6 +38,7 @@
#include <cellfrm.hxx>
#include <rowfrm.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <svx/srchdlg.hxx>

/// set cursor into next/previous cell
bool SwCursorShell::GoNextCell( bool bAppendLine )
@@ -480,6 +481,8 @@ static bool lcl_FindPrevCell( SwNodeIndex& rIdx, bool bInReadOnly  )
bool GotoPrevTable( SwPaM& rCurrentCursor, SwMoveFnCollection const & fnPosTable,
                    bool bInReadOnly )
{
    SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );

    SwNodeIndex aIdx( rCurrentCursor.GetPoint()->nNode );

    SwTableNode* pTableNd = aIdx.GetNode().FindTableNode();
@@ -497,12 +500,27 @@ bool GotoPrevTable( SwPaM& rCurrentCursor, SwMoveFnCollection const & fnPosTable
            aIdx.Assign( *pTableNd, - 1 );
    }

    SwNodeIndex aOldIdx = aIdx;
    sal_uLong nLastNd = rCurrentCursor.GetDoc()->GetNodes().Count() - 1;
    do {
        while( aIdx.GetIndex() &&
            nullptr == ( pTableNd = aIdx.GetNode().StartOfSectionNode()->GetTableNode()) )
        {
            --aIdx;
            if ( aIdx == aOldIdx )
            {
                SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
                return false;
            }
        }

        if( pTableNd ) // any further table node?
        if ( !aIdx.GetIndex() )
        {
            SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::StartWrapped );
            aIdx = nLastNd;
            continue;
        }

        {
            if( &fnPosTable == &fnMoveForward ) // at the beginning?
            {
@@ -535,7 +553,7 @@ bool GotoPrevTable( SwPaM& rCurrentCursor, SwMoveFnCollection const & fnPosTable
            }
            return true;
        }
    } while( pTableNd );
    } while( true );

    return false;
}
@@ -543,18 +561,35 @@ bool GotoPrevTable( SwPaM& rCurrentCursor, SwMoveFnCollection const & fnPosTable
bool GotoNextTable( SwPaM& rCurrentCursor, SwMoveFnCollection const & fnPosTable,
                    bool bInReadOnly )
{
    SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );

    SwNodeIndex aIdx( rCurrentCursor.GetPoint()->nNode );
    SwTableNode* pTableNd = aIdx.GetNode().FindTableNode();

    if( pTableNd )
        aIdx.Assign( *pTableNd->EndOfSectionNode(), 1 );

    SwNodeIndex aOldIdx = aIdx;
    sal_uLong nLastNd = rCurrentCursor.GetDoc()->GetNodes().Count() - 1;
    do {
        while( aIdx.GetIndex() < nLastNd &&
                nullptr == ( pTableNd = aIdx.GetNode().GetTableNode()) )
        {
            ++aIdx;
        if( pTableNd ) // any further table node?
            if ( aIdx == aOldIdx )
            {
                SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
                return false;
            }
        }

        if ( aIdx.GetIndex() == nLastNd )
        {
            SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::EndWrapped );
            aIdx = 0;
            continue;
        }

        {
            if( &fnPosTable == &fnMoveForward ) // at the beginning?
            {
@@ -587,7 +622,7 @@ bool GotoNextTable( SwPaM& rCurrentCursor, SwMoveFnCollection const & fnPosTable
            }
            return true;
        }
    } while( pTableNd );
    } while( true );

    return false;
}