tdf#118129 - return only the caption property of the frame

Change-Id: I3dc875d54c49f233e2784dcd778c2b6fc42e59cd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108958
Tested-by: Jenkins
Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
diff --git a/sc/source/ui/vba/vbawindow.cxx b/sc/source/ui/vba/vbawindow.cxx
index ec76e2a..1691fbb 100644
--- a/sc/source/ui/vba/vbawindow.cxx
+++ b/sc/source/ui/vba/vbawindow.cxx
@@ -301,39 +301,9 @@ ScVbaWindow::ScrollWorkbookTabs( const uno::Any& /*Sheets*/, const uno::Any& /*P
uno::Any SAL_CALL
ScVbaWindow::getCaption()
{
    static const char sCrud[] = " - OpenOffice.org Calc";
    static const sal_Int32 nCrudLen = strlen(sCrud);

    // tdf#118129 - return only the caption property of the frame
    OUString sTitle;
    getFrameProps()->getPropertyValue( SC_UNONAME_TITLE ) >>= sTitle;
    sal_Int32 nCrudIndex = sTitle.indexOf( sCrud );
    // adjust title ( by removing crud )
    // sCrud string present
    if ( nCrudIndex != -1 )
    {
        // and ends with sCrud
        if ( ( nCrudLen + nCrudIndex ) == sTitle.getLength() )
        {
            sTitle = sTitle.copy( 0, nCrudIndex );
            rtl::Reference< ScVbaWorkbook > workbook( new ScVbaWorkbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel ) );
            OUString sName = workbook->getName();
            // rather bizarre hack to make sure the name behavior
            // is like XL
            // if the adjusted title == workbook name, use name
            // if the adjusted title != workbook name but ...
            //  name == title + extension ( .csv, ,odt, .xls )
            //  etc. then also use the name

            if ( sTitle != sName )
            {
                // starts with title
                if ( sName.startsWith( sTitle ) )
                    // extension starts immediately after
                    if ( sName.match( ".", sTitle.getLength() ) )
                        sTitle = sName;
            }
        }
    }
    getFrameProps()->getPropertyValue(SC_UNONAME_TITLE) >>= sTitle;
    return uno::makeAny( sTitle );
}