[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.0' - 5 commits - desktop/source include/LibreOfficeKit sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Wed Oct 7 03:00:51 PDT 2015


 desktop/source/lib/lokandroid.cxx              |    3 -
 include/LibreOfficeKit/LibreOfficeKitEnums.h   |   27 ++++++++++-
 sw/qa/extras/tiledrendering/tiledrendering.cxx |   49 ++++++++++++++++++++
 sw/source/uibase/uiview/viewsrch.cxx           |   59 ++++++++++++++++++++++++-
 4 files changed, 132 insertions(+), 6 deletions(-)

New commits:
commit cd07afe6f10f5a7d7b245b0ae3f100f16450c4db
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Oct 6 10:18:18 2015 +0200

    CppunitTest_sw_tiledrendering: CALLBACK_SEARCH_RESULT_SELECTION testcase
    
    Change-Id: I66a8d73581641c71f2dce2d1992070f3ccce08c2
    (cherry picked from commit a7b86140d74039995bd4d312790244c1e2d4b501)

diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index bcc328e..2fd27dd 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -7,6 +7,9 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#include <string>
+#include <boost/property_tree/json_parser.hpp>
+
 #include <swmodeltestbase.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <comphelper/dispatchcommand.hxx>
@@ -23,7 +26,6 @@
 #include <drawdoc.hxx>
 #include <ndtxt.hxx>
 #include <wrtsh.hxx>
-#include <string>
 
 static const char* DATA_DIRECTORY = "/sw/qa/extras/tiledrendering/data/";
 
@@ -71,6 +73,7 @@ private:
     OString m_aTextSelection;
     bool m_bFound;
     sal_Int32 m_nSearchResultCount;
+    std::vector<OString> m_aSearchResultSelection;
 };
 
 SwTiledRenderingTest::SwTiledRenderingTest()
@@ -137,6 +140,16 @@ void SwTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
         m_nSearchResultCount = std::stoi(aStrPayload.substr(0, aStrPayload.find_first_of(";")));
     }
     break;
+    case LOK_CALLBACK_SEARCH_RESULT_SELECTION:
+    {
+        m_aSearchResultSelection.clear();
+        boost::property_tree::ptree aTree;
+        std::stringstream aStream(pPayload);
+        boost::property_tree::read_json(aStream, aTree);
+        for (boost::property_tree::ptree::value_type& rValue : aTree.get_child("searchResultSelection"))
+            m_aSearchResultSelection.push_back(rValue.second.data().c_str());
+    }
+    break;
     }
 }
 
@@ -466,6 +479,8 @@ void SwTiledRenderingTest::testSearchAll()
     comphelper::dispatchCommand(".uno:ExecuteSearch", aPropertyValues);
     // This was 0; should be 2 results in the body text.
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), m_nSearchResultCount);
+    // Make sure that we get exactly as many rectangle lists as matches.
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), m_aSearchResultSelection.size());
 
     comphelper::LibreOfficeKit::setActive(false);
 #endif
commit c022211c1c09049c70d44bb60b8047ace3732d23
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Oct 6 09:21:38 2015 +0200

    LOK: add CALLBACK_SEARCH_RESULT_SELECTION and implement it in sw
    
    (cherry picked from commit 94752d5970be7ce22e053f9cd83bd59711446a0a)
    
    Conflicts:
    	sw/source/uibase/uiview/viewsrch.cxx
    
    Change-Id: I4c2a5418101976e1cb38c0fa71dbd66fc883f905

diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index 1a4b571..39a324e 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -164,7 +164,26 @@ typedef enum
      * Number of search results followed by the original searched phrase.
      * count;phrase
      */
-    LOK_CALLBACK_SEARCH_RESULT_COUNT
+    LOK_CALLBACK_SEARCH_RESULT_COUNT,
+
+    /**
+     * Selection rectangles of the search result when find all is performed.
+     *
+     * Payload format example, in case of two matches:
+     *
+     * {
+     *     "searchString": "...",
+     *     "searchResultSelection": [
+     *         "...",
+     *         "..."
+     *     ]
+     * }
+     *
+     * - searchString is the search query
+     * - searchResultSelection is an array of rectangle list, in
+     *   LOK_CALLBACK_TEXT_SELECTION format.
+     */
+    LOK_CALLBACK_SEARCH_RESULT_SELECTION
 }
 LibreOfficeKitCallbackType;
 
diff --git a/sw/source/uibase/uiview/viewsrch.cxx b/sw/source/uibase/uiview/viewsrch.cxx
index 3ccc852..570fade 100644
--- a/sw/source/uibase/uiview/viewsrch.cxx
+++ b/sw/source/uibase/uiview/viewsrch.cxx
@@ -22,6 +22,7 @@
 #include <string>
 
 #include <boost/scoped_ptr.hpp>
+#include <boost/property_tree/json_parser.hpp>
 
 #include <hintids.hxx>
 
@@ -58,6 +59,7 @@
 #include <doc.hxx>
 #include <unocrsr.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <comphelper/lok.hxx>
 
 #include <view.hrc>
 #include <SwRewriter.hxx>
@@ -85,6 +87,21 @@ static vcl::Window* GetParentWindow( SvxSearchDialog* pSrchDlg )
     return pSrchDlg && pSrchDlg->IsVisible() ? pSrchDlg : 0;
 }
 
+/// Adds rMatches using rKey as a key to the rTree tree.
+static void lcl_addContainerToJson(boost::property_tree::ptree& rTree, const OString& rKey, const std::vector<OString>& rMatches)
+{
+    boost::property_tree::ptree aChildren;
+
+    for (const OString& rMatch : rMatches)
+    {
+        boost::property_tree::ptree aChild;
+        aChild.put("", rMatch.getStr());
+        aChildren.push_back(std::make_pair("", aChild));
+    }
+
+    rTree.add_child(rKey.getStr(), aChildren);
+}
+
 void SwView::ExecSearch(SfxRequest& rReq, bool bNoMessage)
 {
     const SfxItemSet* pArgs = rReq.GetArgs();
@@ -223,10 +240,48 @@ void SwView::ExecSearch(SfxRequest& rReq, bool bNoMessage)
 #endif
                     m_bFound = false;
                 }
-                else
+                else if (comphelper::LibreOfficeKit::isActive())
                 {
                     OString aPayload = OString::number(nFound) + ";" + m_pSrchItem->GetSearchString().toUtf8();
                     m_pWrtShell->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_COUNT, aPayload.getStr());
+
+                    // Emit a callback also about the selection rectangles, grouped by matches.
+                    if (SwPaM* pPaM = m_pWrtShell->GetCrsr())
+                    {
+                        std::vector<OString> aMatches;
+                        for (SwPaM& rPaM : pPaM->GetRingContainer())
+                        {
+                            if (SwShellCrsr* pShellCrsr = dynamic_cast<SwShellCrsr*>(&rPaM))
+                            {
+                                std::vector<OString> aSelectionRectangles;
+                                pShellCrsr->SwSelPaintRects::Show(&aSelectionRectangles);
+                                std::stringstream ss;
+                                bool bFirst = true;
+                                for (size_t i = 0; i < aSelectionRectangles.size(); ++i)
+                                {
+                                    const OString& rSelectionRectangle = aSelectionRectangles[i];
+                                    if (rSelectionRectangle.isEmpty())
+                                        continue;
+                                    if (bFirst)
+                                        bFirst = false;
+                                    else
+                                        ss << "; ";
+                                    ss << rSelectionRectangle.getStr();
+                                }
+                                OString sRect = ss.str().c_str();
+                                aMatches.push_back(sRect);
+                            }
+                        }
+                        boost::property_tree::ptree aTree;
+                        aTree.put("searchString", m_pSrchItem->GetSearchString().toUtf8().getStr());
+                        lcl_addContainerToJson(aTree, "searchResultSelection", aMatches);
+
+                        std::stringstream aStream;
+                        boost::property_tree::write_json(aStream, aTree);
+                        aPayload = aStream.str().c_str();
+
+                        m_pWrtShell->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr());
+                    }
                 }
                 rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
 #if HAVE_FEATURE_DESKTOP
commit 9702a749d6a16b277c2bc8a57dba93088cc7c557
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Oct 5 18:22:56 2015 +0300

    LOK: add mouse button type and modifier on android
    
    Change-Id: Iab1dca8736eb208e652b5d5dfc0c87c8029679da
    Reviewed-on: https://gerrit.libreoffice.org/19159
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>
    (cherry picked from commit 944bb51dfe4b214bf6d7f9a4b9066728d0da51c7)

diff --git a/desktop/source/lib/lokandroid.cxx b/desktop/source/lib/lokandroid.cxx
index bb1813d..1db7945 100644
--- a/desktop/source/lib/lokandroid.cxx
+++ b/desktop/source/lib/lokandroid.cxx
@@ -11,6 +11,7 @@
 #include <jni.h>
 
 #include <sal/types.h>
+#include <vcl/event.hxx>
 
 #include <android/log.h>
 
@@ -279,7 +280,7 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_postMou
     (JNIEnv* pEnv, jobject aObject, jint type, jint x, jint y, jint count)
 {
     LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
-    pDocument->pClass->postMouseEvent(pDocument, type, x, y, count);
+    pDocument->pClass->postMouseEvent(pDocument, type, x, y, count, MOUSE_LEFT, 0);
 }
 
 extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_postUnoCommand
commit d39c16a4d537c8083134e690bf38e3c4a6cf5341
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Oct 5 17:07:06 2015 +0300

    LOK: add the search phrase to the search result count callback
    
    We need this to notify the user for which search phrase no results were
    found
    
    (cherry picked from commit c30defcf8e34daec6ea0455d772fe296cc26ecc9)
    
    Conflicts:
    	libreofficekit/source/gtk/lokdocview.cxx
    
    Change-Id: I8cc7ab235b9129dfdcb022145456180ff7e4ca92

diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index df5f64d..1a4b571 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -159,7 +159,11 @@ typedef enum
      * Payload is a single 0-based integer.
      */
     LOK_CALLBACK_SET_PART,
-    /// Number of search results, in case something is found.
+
+    /**
+     * Number of search results followed by the original searched phrase.
+     * count;phrase
+     */
     LOK_CALLBACK_SEARCH_RESULT_COUNT
 }
 LibreOfficeKitCallbackType;
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index c836f4b..bcc328e 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -23,6 +23,7 @@
 #include <drawdoc.hxx>
 #include <ndtxt.hxx>
 #include <wrtsh.hxx>
+#include <string>
 
 static const char* DATA_DIRECTORY = "/sw/qa/extras/tiledrendering/data/";
 
@@ -132,7 +133,8 @@ void SwTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
     break;
     case LOK_CALLBACK_SEARCH_RESULT_COUNT:
     {
-        m_nSearchResultCount = OString(pPayload).toInt32();
+        std::string aStrPayload(pPayload);
+        m_nSearchResultCount = std::stoi(aStrPayload.substr(0, aStrPayload.find_first_of(";")));
     }
     break;
     }
diff --git a/sw/source/uibase/uiview/viewsrch.cxx b/sw/source/uibase/uiview/viewsrch.cxx
index 1176412..3ccc852 100644
--- a/sw/source/uibase/uiview/viewsrch.cxx
+++ b/sw/source/uibase/uiview/viewsrch.cxx
@@ -225,7 +225,7 @@ void SwView::ExecSearch(SfxRequest& rReq, bool bNoMessage)
                 }
                 else
                 {
-                    OString aPayload = OString::number(nFound);
+                    OString aPayload = OString::number(nFound) + ";" + m_pSrchItem->GetSearchString().toUtf8();
                     m_pWrtShell->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_COUNT, aPayload.getStr());
                 }
                 rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
commit e4df5a9f8e543fb8ae29062971d8024e718ce090
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Oct 5 15:34:28 2015 +0200

    CppunitTest_sw_tiledrendering: testcase for LOK_CALLBACK_SEARCH_RESULT_COUNT
    
    Change-Id: I9f517bc2f3dfca9a2dc17a229f54c47b7790a355
    (cherry picked from commit b4e75e8f52c17d02a65022303fb6a0e4f1d97592)

diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index e7ab149..c836f4b 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -18,6 +18,7 @@
 #include <vcl/svapp.hxx>
 #include <editeng/editview.hxx>
 #include <editeng/outliner.hxx>
+#include <svl/srchitem.hxx>
 #include <crsskip.hxx>
 #include <drawdoc.hxx>
 #include <ndtxt.hxx>
@@ -42,6 +43,7 @@ public:
     void testSearchTextFrame();
     void testSearchTextFrameWrapAround();
     void testDocumentSizeChanged();
+    void testSearchAll();
 
     CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
     CPPUNIT_TEST(testRegisterCallback);
@@ -56,6 +58,7 @@ public:
     CPPUNIT_TEST(testSearchTextFrame);
     CPPUNIT_TEST(testSearchTextFrameWrapAround);
     CPPUNIT_TEST(testDocumentSizeChanged);
+    CPPUNIT_TEST(testSearchAll);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -66,10 +69,12 @@ private:
     Size m_aDocumentSize;
     OString m_aTextSelection;
     bool m_bFound;
+    sal_Int32 m_nSearchResultCount;
 };
 
 SwTiledRenderingTest::SwTiledRenderingTest()
-    : m_bFound(true)
+    : m_bFound(true),
+      m_nSearchResultCount(0)
 {
 }
 
@@ -125,6 +130,11 @@ void SwTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
         m_bFound = false;
     }
     break;
+    case LOK_CALLBACK_SEARCH_RESULT_COUNT:
+    {
+        m_nSearchResultCount = OString(pPayload).toInt32();
+    }
+    break;
     }
 }
 
@@ -438,6 +448,26 @@ void SwTiledRenderingTest::testDocumentSizeChanged()
 #endif
 }
 
+void SwTiledRenderingTest::testSearchAll()
+{
+#if !defined(WNT) && !defined(MACOSX)
+    comphelper::LibreOfficeKit::setActive();
+
+    SwXTextDocument* pXTextDocument = createDoc("search.odt");
+    pXTextDocument->registerCallback(&SwTiledRenderingTest::callback, this);
+    uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
+    {
+        {"SearchItem.SearchString", uno::makeAny(OUString("shape"))},
+        {"SearchItem.Backward", uno::makeAny(false)},
+        {"SearchItem.Command", uno::makeAny(static_cast<sal_uInt16>(SvxSearchCmd::FIND_ALL))},
+    }));
+    comphelper::dispatchCommand(".uno:ExecuteSearch", aPropertyValues);
+    // This was 0; should be 2 results in the body text.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), m_nSearchResultCount);
+
+    comphelper::LibreOfficeKit::setActive(false);
+#endif
+}
 CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();


More information about the Libreoffice-commits mailing list