diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-09-21 17:27:48 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-09-21 19:32:01 +0200 |
commit | d7788287456cb633226203f259e212c143b83050 (patch) | |
tree | bf58cd4fa76b3aa1e72016437c89e8da4929cdd9 /sw | |
parent | cd72269a6a2c85ae9dd4552aa4808ef4fd1f6c0e (diff) |
lok::Document::getCommandValues: expose sw redline author colors
These colors are used in the tiles, so it's a good idea if the client
can use matching colors for cursors and selections. But to be able to do
that, we need an API to expose these colors.
Change-Id: Ia688c07e6c300fecdf8dc428d5a3f000d1857387
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/swmodule.hxx | 2 | ||||
-rw-r--r-- | sw/inc/unotxdoc.hxx | 2 | ||||
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 25 | ||||
-rw-r--r-- | sw/source/uibase/app/swmodul1.cxx | 49 | ||||
-rw-r--r-- | sw/source/uibase/uno/unotxdoc.cxx | 5 |
5 files changed, 74 insertions, 9 deletions
diff --git a/sw/inc/swmodule.hxx b/sw/inc/swmodule.hxx index c7bc02d15da0..6abfe6106b39 100644 --- a/sw/inc/swmodule.hxx +++ b/sw/inc/swmodule.hxx @@ -189,6 +189,8 @@ public: // Redlining. sal_uInt16 GetRedlineAuthor(); OUString GetRedlineAuthor(sal_uInt16 nPos); + /// See SwXTextDocument::getTrackedChangeAuthors(). + OUString GetRedlineAuthorInfo(); sal_uInt16 InsertRedlineAuthor(const OUString& rAuthor); void SetRedlineAuthor(const OUString& rAuthor); // for unit tests diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx index 6b6087db685d..47e29addbb9e 100644 --- a/sw/inc/unotxdoc.hxx +++ b/sw/inc/unotxdoc.hxx @@ -438,6 +438,8 @@ public: virtual void setClientVisibleArea(const Rectangle& rRectangle) override; /// @see vcl::ITiledRenderable::getPointer(). virtual Pointer getPointer() override; + /// @see vcl::ITiledRenderable::getTrackedChangeAuthors(). + OUString getTrackedChangeAuthors() override; // css::tiledrendering::XTiledRenderable virtual void SAL_CALL paintTile( const ::css::uno::Any& Parent, ::sal_Int32 nOutputWidth, ::sal_Int32 nOutputHeight, ::sal_Int32 nTilePosX, ::sal_Int32 nTilePosY, ::sal_Int32 nTileWidth, ::sal_Int32 nTileHeight ) throw (::css::uno::RuntimeException, std::exception) override; diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index f203fcaa3ae8..9d9a100beb98 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -74,6 +74,7 @@ public: void testSetViewGraphicSelection(); void testCreateViewGraphicSelection(); void testCreateViewTextSelection(); + void testRedlineColors(); CPPUNIT_TEST_SUITE(SwTiledRenderingTest); CPPUNIT_TEST(testRegisterCallback); @@ -112,6 +113,7 @@ public: CPPUNIT_TEST(testSetViewGraphicSelection); CPPUNIT_TEST(testCreateViewGraphicSelection); CPPUNIT_TEST(testCreateViewTextSelection); + CPPUNIT_TEST(testRedlineColors); CPPUNIT_TEST_SUITE_END(); private: @@ -1429,6 +1431,29 @@ void SwTiledRenderingTest::testCreateViewTextSelection() comphelper::LibreOfficeKit::setActive(false); } +void SwTiledRenderingTest::testRedlineColors() +{ + // Load a document. + comphelper::LibreOfficeKit::setActive(); + SwXTextDocument* pXTextDocument = createDoc("dummy.fodt"); + + // Turn on track changes, type "zzz" at the end. + uno::Reference<beans::XPropertySet> xPropertySet(mxComponent, uno::UNO_QUERY); + xPropertySet->setPropertyValue("RecordChanges", uno::makeAny(true)); + SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell(); + pWrtShell->EndDoc(); + pWrtShell->Insert("zzz"); + + // Assert that info about exactly one author is returned. + OUString aInfo = pXTextDocument->getTrackedChangeAuthors(); + std::stringstream aStream(aInfo.toUtf8().getStr()); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aTree.get_child("authors").size()); + + comphelper::LibreOfficeKit::setActive(false); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/uibase/app/swmodul1.cxx b/sw/source/uibase/app/swmodul1.cxx index 2e72374bdb66..6d0030bee543 100644 --- a/sw/source/uibase/app/swmodul1.cxx +++ b/sw/source/uibase/app/swmodul1.cxx @@ -18,6 +18,7 @@ */ #include <memory> +#include <boost/property_tree/json_parser.hpp> #include <hintids.hxx> #include <sfx2/request.hxx> @@ -423,6 +424,44 @@ OUString SwModule::GetRedlineAuthor(sal_uInt16 nPos) return (*m_pAuthorNames)[nPos]; } +static ColorData lcl_GetAuthorColor(sal_uInt16 nPos) +{ + static const ColorData aColArr[] = + { + COL_AUTHOR1_DARK, COL_AUTHOR2_DARK, COL_AUTHOR3_DARK, + COL_AUTHOR4_DARK, COL_AUTHOR5_DARK, COL_AUTHOR6_DARK, + COL_AUTHOR7_DARK, COL_AUTHOR8_DARK, COL_AUTHOR9_DARK + }; + + return aColArr[nPos % SAL_N_ELEMENTS(aColArr)]; +} + +/// Returns a JSON representation of a redline author. +boost::property_tree::ptree lcl_AuthorToJson(const OUString& rAuthor, size_t nIndex) +{ + boost::property_tree::ptree aRet; + aRet.put("index", nIndex); + aRet.put("name", rAuthor.toUtf8().getStr()); + aRet.put("color", lcl_GetAuthorColor(nIndex)); + return aRet; +} + +OUString SwModule::GetRedlineAuthorInfo() +{ + boost::property_tree::ptree aTable; + for (size_t nAuthor = 0; nAuthor < m_pAuthorNames->size(); ++nAuthor) + { + boost::property_tree::ptree aAuthor = lcl_AuthorToJson((*m_pAuthorNames)[nAuthor], nAuthor); + aTable.push_back(std::make_pair("", aAuthor)); + } + + boost::property_tree::ptree aTree; + aTree.add_child("authors", aTable); + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + return OUString::fromUtf8(aStream.str().c_str()); +} + sal_uInt16 SwModule::InsertRedlineAuthor(const OUString& rAuthor) { sal_uInt16 nPos = 0; @@ -442,15 +481,7 @@ static void lcl_FillAuthorAttr( sal_uInt16 nAuthor, SfxItemSet &rSet, Color aCol( rAttr.nColor ); if( COL_TRANSPARENT == rAttr.nColor ) - { - static const ColorData aColArr[] = { - COL_AUTHOR1_DARK, COL_AUTHOR2_DARK, COL_AUTHOR3_DARK, - COL_AUTHOR4_DARK, COL_AUTHOR5_DARK, COL_AUTHOR6_DARK, - COL_AUTHOR7_DARK, COL_AUTHOR8_DARK, COL_AUTHOR9_DARK }; - - aCol.SetColor( aColArr[ nAuthor % (sizeof( aColArr ) / - sizeof( aColArr[0] )) ] ); - } + aCol.SetColor(lcl_GetAuthorColor(nAuthor)); bool bBackGr = COL_NONE_COLOR == rAttr.nColor; diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index c65d4dc779fc..901a3011bdfb 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3225,6 +3225,11 @@ Pointer SwXTextDocument::getPointer() return pWrtShell->GetView().GetEditWin().GetPointer(); } +OUString SwXTextDocument::getTrackedChangeAuthors() +{ + return SW_MOD()->GetRedlineAuthorInfo(); +} + int SwXTextDocument::getPart() { SolarMutexGuard aGuard; |