include/LibreOfficeKit/LibreOfficeKitEnums.h | 21 ++++++++- libreofficekit/source/gtk/lokdocview.cxx | 6 ++ sw/qa/extras/tiledrendering/tiledrendering.cxx | 17 +++++++ sw/source/uibase/uiview/viewsrch.cxx | 57 ++++++++++++++++++++++++- 4 files changed, 98 insertions(+), 3 deletions(-)
New commits: commit a7b86140d74039995bd4d312790244c1e2d4b501 Author: Miklos Vajna <[email protected]> Date: Tue Oct 6 10:18:18 2015 +0200 CppunitTest_sw_tiledrendering: CALLBACK_SEARCH_RESULT_SELECTION testcase Change-Id: I66a8d73581641c71f2dce2d1992070f3ccce08c2 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 2b6060d6c58b95153c907585d89cad815bc9b1ae Author: Miklos Vajna <[email protected]> Date: Tue Oct 6 09:21:54 2015 +0200 gtktiledviewer: recognize LOK_CALLBACK_SEARCH_RESULT_SELECTION Change-Id: Ib932ee36e41afcb53d15a6362b998cc673d474f2 diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index d5eab90..4ee1e33 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -233,6 +233,8 @@ callbackTypeToString (int nType) return "LOK_CALLBACK_DOCUMENT_SIZE_CHANGED"; case LOK_CALLBACK_SET_PART: return "LOK_CALLBACK_SET_PART"; + case LOK_CALLBACK_SEARCH_RESULT_SELECTION: + return "LOK_CALLBACK_SEARCH_RESULT_SELECTION"; } return 0; } @@ -679,6 +681,10 @@ callback (gpointer pData) setPart(pDocView, pCallback->m_aPayload); } break; + case LOK_CALLBACK_SEARCH_RESULT_SELECTION: + { + } + break; default: g_assert(false); break; commit 94752d5970be7ce22e053f9cd83bd59711446a0a Author: Miklos Vajna <[email protected]> Date: Tue Oct 6 09:21:38 2015 +0200 LOK: add CALLBACK_SEARCH_RESULT_SELECTION and implement it in sw Change-Id: I4c2a5418101976e1cb38c0fa71dbd66fc883f905 diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h index 97c089f..b87f69a 100644 --- a/include/LibreOfficeKit/LibreOfficeKitEnums.h +++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h @@ -161,7 +161,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 20ffed6..0b07ce5 100644 --- a/sw/source/uibase/uiview/viewsrch.cxx +++ b/sw/source/uibase/uiview/viewsrch.cxx @@ -22,6 +22,7 @@ #include <string> #include <memory> +#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 _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
