[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.0' - 26 commits - desktop/CppunitTest_desktop_lib.mk desktop/qa editeng/source sw/inc sw/Module_sw.mk sw/qa sw/source vcl/source

Miklos Vajna vmiklos at collabora.co.uk
Mon Nov 16 02:39:15 PST 2015


 desktop/CppunitTest_desktop_lib.mk             |    1 
 desktop/qa/desktop_lib/test_desktop_lib.cxx    |   46 +++++
 editeng/source/editeng/impedit.cxx             |   16 ++
 sw/Module_sw.mk                                |    7 
 sw/inc/PostItMgr.hxx                           |    7 
 sw/inc/SidebarWin.hxx                          |    9 +
 sw/inc/docufld.hxx                             |    1 
 sw/inc/drawdoc.hxx                             |    2 
 sw/inc/fldbas.hxx                              |    1 
 sw/inc/fmtfld.hxx                              |    1 
 sw/qa/extras/tiledrendering/tiledrendering.cxx |   34 ----
 sw/source/core/crsr/crsrsh.cxx                 |   10 +
 sw/source/core/draw/drawdoc.cxx                |    6 
 sw/source/core/fields/docufld.cxx              |   16 ++
 sw/source/core/fields/fldbas.cxx               |   29 +--
 sw/source/core/txtnode/atrfld.cxx              |   17 ++
 sw/source/core/view/viewsh.cxx                 |    5 
 sw/source/uibase/docvw/PostItMgr.cxx           |   88 +++++++++++
 sw/source/uibase/docvw/SidebarTxtControl.cxx   |   37 ++++
 sw/source/uibase/docvw/SidebarTxtControl.hxx   |   10 -
 sw/source/uibase/docvw/SidebarWin.cxx          |  193 ++++++++++++++++++++++++-
 sw/source/uibase/docvw/edtwin.cxx              |   46 +++++
 vcl/source/window/seleng.cxx                   |    5 
 23 files changed, 527 insertions(+), 60 deletions(-)

New commits:
commit de0dd50f59de80ee08aa4f4793dd2b61e6e8156e
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Sat Nov 14 17:10:32 2015 +0100

    SwPostItField::dumpAsXml: survive 0 mpText
    
    And no need to copy it to be able to dump it.
    
    Change-Id: I5c0782c489a5d7c24173a81cc82efd195c4aa56e
    (cherry picked from commit 44c7272fc543947792ae8195341b8867d81e3925)

diff --git a/sw/source/core/fields/docufld.cxx b/sw/source/core/fields/docufld.cxx
index c0292e0..ea5f2cc 100644
--- a/sw/source/core/fields/docufld.cxx
+++ b/sw/source/core/fields/docufld.cxx
@@ -1841,8 +1841,9 @@ void SwPostItField::dumpAsXml(xmlTextWriterPtr pWriter) const
     SwField::dumpAsXml(pWriter);
 
     xmlTextWriterStartElement(pWriter, BAD_CAST("mpText"));
-    OutlinerParaObject aParaObject(*mpText);
-    aParaObject.dumpAsXml(pWriter);
+    xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", mpText);
+    if (mpText)
+        mpText->dumpAsXml(pWriter);
     xmlTextWriterEndElement(pWriter);
 
     xmlTextWriterEndElement(pWriter);
commit ac6c75b7ac270454ed77eac0a115f1fae277006c
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Sat Nov 14 16:59:01 2015 +0100

    CppunitTest_desktop_lib: add Writer comments textcase
    
    Fails without e.g. the last hunk of commit
    1ba9d7fd2a7a3e2b4f52ed0f5efdf7df867b9db3 (sw lok: forward key events to
    annotation window if necessary, 2015-11-12).
    
    Change-Id: I7f39530881f6141fea956b751aa57eb2bdcadcb2
    (cherry picked from commit 1118689e70ed49604ded6e1ae83a22bdc995b2fb)

diff --git a/desktop/CppunitTest_desktop_lib.mk b/desktop/CppunitTest_desktop_lib.mk
index ca9d8db..bbedfdc 100644
--- a/desktop/CppunitTest_desktop_lib.mk
+++ b/desktop/CppunitTest_desktop_lib.mk
@@ -67,6 +67,7 @@ $(eval $(call gb_CppunitTest_use_components,desktop_lib,\
     xmloff/util/xo \
     i18npool/source/search/i18nsearch \
     filter/source/graphic/graphicfilter \
+    linguistic/source/lng \
 ))
 
 $(eval $(call gb_CppunitTest_use_configuration,desktop_lib))
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index d6a4eb9..f7c3196 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -10,6 +10,10 @@
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/lang/XComponent.hpp>
 #include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/awt/Key.hpp>
+#include <com/sun/star/awt/XReschedule.hpp>
+#include <com/sun/star/awt/Toolkit.hpp>
 
 #ifdef WNT
 #include <prewin.h>
@@ -75,6 +79,7 @@ public:
     void testPasteWriter();
     void testRowColumnHeaders();
     void testCommandResult();
+    void testWriterComments();
 
     CPPUNIT_TEST_SUITE(DesktopLOKTest);
     CPPUNIT_TEST(testGetStyles);
@@ -89,6 +94,7 @@ public:
     CPPUNIT_TEST(testPasteWriter);
     CPPUNIT_TEST(testRowColumnHeaders);
     CPPUNIT_TEST(testCommandResult);
+    CPPUNIT_TEST(testWriterComments);
     CPPUNIT_TEST_SUITE_END();
 
     uno::Reference<lang::XComponent> mxComponent;
@@ -477,6 +483,46 @@ void DesktopLOKTest::testCommandResult()
     CPPUNIT_ASSERT_EQUAL(aTree.get_child("success").get_value<bool>(), true);
 }
 
+void DesktopLOKTest::testWriterComments()
+{
+    comphelper::LibreOfficeKit::setActive();
+    LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
+    pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this);
+    uno::Reference<awt::XReschedule> xToolkit(com::sun::star::awt::Toolkit::create(comphelper::getProcessComponentContext()), uno::UNO_QUERY);
+
+    // Insert a comment at the beginning of the document and wait till the main
+    // loop grabs the focus, so characters end up in the annotation window.
+    TimeValue aTimeValue = {2 , 0}; // 2 seconds max
+    m_aCommandResultCondition.reset();
+    pDocument->pClass->postUnoCommand(pDocument, ".uno:InsertAnnotation", nullptr, true);
+    m_aCommandResultCondition.wait(&aTimeValue);
+    CPPUNIT_ASSERT(!m_aCommandResult.isEmpty());
+    xToolkit->reschedule();
+
+    // Test that we have a comment.
+    uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xTextDocument->getText(), uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xParagraphEnumeration = xParagraphEnumerationAccess->createEnumeration();
+    uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphEnumeration->nextElement(), uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xTextPortionEnumeration = xParagraph->createEnumeration();
+    uno::Reference<beans::XPropertySet> xTextPortion(xTextPortionEnumeration->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("Annotation"), xTextPortion->getPropertyValue("TextPortionType").get<OUString>());
+
+    // Type "test" and finish editing.
+    pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 't', 0);
+    pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 'e', 0);
+    pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 's', 0);
+    pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 't', 0);
+    pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 0, com::sun::star::awt::Key::ESCAPE);
+
+    // Test that the typed characters ended up in the right window.
+    auto xTextField = xTextPortion->getPropertyValue("TextField").get< uno::Reference<beans::XPropertySet> >();
+    // This was empty, typed characters ended up in the body text.
+    CPPUNIT_ASSERT_EQUAL(OUString("test"), xTextField->getPropertyValue("Content").get<OUString>());
+
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
commit b7dc1edd8492e0bf4bb100e1f761ceed158bdd35
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Sat Nov 14 15:35:18 2015 +0100

    CppunitTest_sw_tiledrendering: replace various ifdefs with a single condition
    
    LOK is Linux-only at the moment, don't bother with disabling each and
    every unit test on Mac/Windows for now.
    
    Change-Id: I2ff1ed47251c16ec6a8d43138789480d95ea720e
    (cherry picked from commit 18dfcbb11a05b7e702dc2161df9db8386a7ca34b)

diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 13453b5..80b1ffb8 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -68,11 +68,16 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_odfexport \
     CppunitTest_sw_odfimport \
     CppunitTest_sw_uiwriter \
-    CppunitTest_sw_tiledrendering \
     CppunitTest_sw_mailmerge \
     CppunitTest_sw_globalfilter \
 ))
 
+ifeq ($(OS),LINUX)
+$(eval $(call gb_Module_add_slowcheck_targets,sw,\
+    CppunitTest_sw_tiledrendering \
+))
+endif
+
 ifneq ($(DISABLE_CVE_TESTS),TRUE)
 $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_filters_test \
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index b1dd9cc..fe441fd 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -157,18 +157,6 @@ void SwTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
 
 void SwTiledRenderingTest::testRegisterCallback()
 {
-#ifdef MACOSX
-    // For some reason this particular test requires window system access on OS X.
-
-    // Without window system access, we do get a number of "<<<WARNING>>>
-    // AquaSalGraphics::CheckContext() FAILED!!!!" [sic] and " <Warning>: CGSConnectionByID: 0 is
-    // not a valid connection ID" warnings while running the other tests, too, but they still
-    // succeed.
-
-    if (!vcl::IsWindowSystemAvailable())
-        return;
-#endif
-
     SwXTextDocument* pXTextDocument = createDoc("dummy.fodt");
     pXTextDocument->registerCallback(&SwTiledRenderingTest::callback, this);
     SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
@@ -177,13 +165,8 @@ void SwTiledRenderingTest::testRegisterCallback()
 
     // Check that the top left 256x256px tile would be invalidated.
     CPPUNIT_ASSERT(!m_aInvalidation.IsEmpty());
-#if !defined(WNT) && !defined(MACOSX)
     Rectangle aTopLeft(0, 0, 256*15, 256*15); // 1 px = 15 twips, assuming 96 DPI.
-    // FIXME - fails on Windows since about cbd48230bb3a90c4c485fa33123c6653234e02e9
-    // [plus minus few commits maybe]
-    // Also on OS X. But is tiled rendering even supposed to work on Windows and OS X?
     CPPUNIT_ASSERT(m_aInvalidation.IsOver(aTopLeft));
-#endif
 }
 
 void SwTiledRenderingTest::testPostKeyEvent()
@@ -297,9 +280,7 @@ void SwTiledRenderingTest::testSetGraphicSelection()
     Rectangle aShapeAfter = pObject->GetSnapRect();
     // Check that a resize happened, but aspect ratio is not kept.
     CPPUNIT_ASSERT_EQUAL(aShapeBefore.getWidth(), aShapeAfter.getWidth());
-#if !defined(MACOSX) // FIXME
     CPPUNIT_ASSERT_EQUAL(aShapeBefore.getHeight() + 1000, aShapeAfter.getHeight());
-#endif
 }
 
 void SwTiledRenderingTest::testResetSelection()
@@ -329,7 +310,6 @@ void SwTiledRenderingTest::testResetSelection()
     CPPUNIT_ASSERT(!pWrtShell->IsSelFrmMode());
 }
 
-#if !(defined WNT || defined MACOSX)
 void lcl_search(bool bBackward)
 {
     uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
@@ -339,11 +319,9 @@ void lcl_search(bool bBackward)
     }));
     comphelper::dispatchCommand(".uno:ExecuteSearch", aPropertyValues);
 }
-#endif
 
 void SwTiledRenderingTest::testSearch()
 {
-#if !defined(WNT) && !defined(MACOSX)
     comphelper::LibreOfficeKit::setActive();
 
     SwXTextDocument* pXTextDocument = createDoc("search.odt");
@@ -384,12 +362,10 @@ void SwTiledRenderingTest::testSearch()
     CPPUNIT_ASSERT_EQUAL(nNode + 1, nActual);
 
     comphelper::LibreOfficeKit::setActive(false);
-#endif
 }
 
 void SwTiledRenderingTest::testSearchViewArea()
 {
-#if !defined(WNT) && !defined(MACOSX)
     SwXTextDocument* pXTextDocument = createDoc("search.odt");
     SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
     // Go to the second page, 1-based.
@@ -411,12 +387,10 @@ void SwTiledRenderingTest::testSearchViewArea()
     comphelper::dispatchCommand(".uno:ExecuteSearch", aPropertyValues);
     // This was just "Heading", i.e. SwView::SearchAndWrap() did not search from only the top of the second page.
     CPPUNIT_ASSERT_EQUAL(OUString("Heading on second page"), pShellCrsr->GetPoint()->nNode.GetNode().GetTextNode()->GetText());
-#endif
 }
 
 void SwTiledRenderingTest::testSearchTextFrame()
 {
-#if !defined(WNT) && !defined(MACOSX)
     comphelper::LibreOfficeKit::setActive();
 
     SwXTextDocument* pXTextDocument = createDoc("search.odt");
@@ -431,12 +405,10 @@ void SwTiledRenderingTest::testSearchTextFrame()
     CPPUNIT_ASSERT(!m_aTextSelection.isEmpty());
 
     comphelper::LibreOfficeKit::setActive(false);
-#endif
 }
 
 void SwTiledRenderingTest::testSearchTextFrameWrapAround()
 {
-#if !defined(WNT) && !defined(MACOSX)
     SwXTextDocument* pXTextDocument = createDoc("search.odt");
     pXTextDocument->registerCallback(&SwTiledRenderingTest::callback, this);
     uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
@@ -449,12 +421,10 @@ void SwTiledRenderingTest::testSearchTextFrameWrapAround()
     comphelper::dispatchCommand(".uno:ExecuteSearch", aPropertyValues);
     // This failed, i.e. the second time 'not found' was reported, instead of wrapping around.
     CPPUNIT_ASSERT(m_bFound);
-#endif
 }
 
 void SwTiledRenderingTest::testDocumentSizeChanged()
 {
-#if !defined(WNT) && !defined(MACOSX)
     // Get the current document size.
     SwXTextDocument* pXTextDocument = createDoc("2-pages.odt");
     pXTextDocument->registerCallback(&SwTiledRenderingTest::callback, this);
@@ -469,12 +439,10 @@ void SwTiledRenderingTest::testDocumentSizeChanged()
     CPPUNIT_ASSERT_EQUAL(aSize.getWidth(), m_aDocumentSize.getWidth());
     // Document height should be smaller now.
     CPPUNIT_ASSERT(aSize.getHeight() > m_aDocumentSize.getHeight());
-#endif
 }
 
 void SwTiledRenderingTest::testSearchAll()
 {
-#if !defined(WNT) && !defined(MACOSX)
     comphelper::LibreOfficeKit::setActive();
 
     SwXTextDocument* pXTextDocument = createDoc("search.odt");
@@ -492,8 +460,8 @@ void SwTiledRenderingTest::testSearchAll()
     CPPUNIT_ASSERT_EQUAL(0, m_aSearchResultPart[0]);
 
     comphelper::LibreOfficeKit::setActive(false);
-#endif
 }
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
commit bd929bc551c586cf5d3ef49ad573a59e9fe1ce33
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Sat Nov 14 14:42:26 2015 +0100

    sw lok comments: implement mouse move and mouse up
    
    As long as we don't tweak the map mode of the comment widgets
    permanently we also have to disable the selection engine's timer, as
    that would emit events without the correct map mode: so disable that for
    the LOK case for now.
    
    (cherry picked from commit b3dc0d7c72c2bb997bfceaeaf25dc9153ceca244)
    
    Conflicts:
    	sw/inc/SidebarWin.hxx
    	sw/source/uibase/docvw/SidebarTxtControl.hxx
    
    Change-Id: If377ff2f064c30feb473f153f9d5b29b8ace7113

diff --git a/sw/inc/SidebarWin.hxx b/sw/inc/SidebarWin.hxx
index f176140..4f7fc33 100644
--- a/sw/inc/SidebarWin.hxx
+++ b/sw/inc/SidebarWin.hxx
@@ -180,6 +180,8 @@ class SwSidebarWin : public vcl::Window
         virtual void    Draw(OutputDevice* pDev, const Point&, const Size&, sal_uLong) SAL_OVERRIDE;
         virtual void KeyInput(const KeyEvent& rKeyEvt) SAL_OVERRIDE;
         virtual void MouseButtonDown(const MouseEvent& rMouseEvent) SAL_OVERRIDE;
+        virtual void MouseButtonUp(const MouseEvent& rMouseEvent) SAL_OVERRIDE;
+        virtual void MouseMove(const MouseEvent& rMouseEvent) SAL_OVERRIDE;
         void PaintTile(vcl::RenderContext& rRenderContext, const Rectangle& rRect);
         /// Is there a matching sub-widget inside this sidebar widget for rPointLogic?
         bool IsHitWindow(const Point& rPointLogic);
diff --git a/sw/source/uibase/docvw/SidebarTxtControl.hxx b/sw/source/uibase/docvw/SidebarTxtControl.hxx
index 57a60d3..15d7c6f 100644
--- a/sw/source/uibase/docvw/SidebarTxtControl.hxx
+++ b/sw/source/uibase/docvw/SidebarTxtControl.hxx
@@ -42,8 +42,6 @@ class SidebarTextControl : public Control
         virtual void    Paint( vcl::RenderContext& rRenderContext, const Rectangle& rRect) SAL_OVERRIDE;
         /// @see OutputDevice::LogicInvalidate().
         void LogicInvalidate(const Rectangle* pRectangle) SAL_OVERRIDE;
-        virtual void    MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
-        virtual void    MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
         virtual void    Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
         virtual void    LoseFocus() SAL_OVERRIDE;
         virtual void    RequestHelp(const HelpEvent &rEvt) SAL_OVERRIDE;
@@ -63,6 +61,8 @@ class SidebarTextControl : public Control
         virtual void GetFocus() SAL_OVERRIDE;
         virtual void KeyInput( const KeyEvent& rKeyEvt ) SAL_OVERRIDE;
         virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
+        virtual void MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
+        virtual void MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
 
         OutlinerView* GetTextView() const;
 
diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index 01ce695..47b335a 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -411,6 +411,20 @@ void SwSidebarWin::KeyInput(const KeyEvent& rKeyEvent)
     }
 }
 
+void SwSidebarWin::MouseMove(const MouseEvent& rMouseEvent)
+{
+    if (mpSidebarTextControl)
+    {
+        mpSidebarTextControl->Push(PushFlags::MAPMODE);
+        MouseEvent aMouseEvent(rMouseEvent);
+        lcl_translateTwips(*EditWin(), *mpSidebarTextControl, &aMouseEvent);
+
+        mpSidebarTextControl->MouseMove(aMouseEvent);
+
+        mpSidebarTextControl->Pop();
+    }
+}
+
 void SwSidebarWin::MouseButtonDown(const MouseEvent& rMouseEvent)
 {
     if (mpSidebarTextControl)
@@ -425,6 +439,20 @@ void SwSidebarWin::MouseButtonDown(const MouseEvent& rMouseEvent)
     }
 }
 
+void SwSidebarWin::MouseButtonUp(const MouseEvent& rMouseEvent)
+{
+    if (mpSidebarTextControl)
+    {
+        mpSidebarTextControl->Push(PushFlags::MAPMODE);
+        MouseEvent aMouseEvent(rMouseEvent);
+        lcl_translateTwips(*EditWin(), *mpSidebarTextControl, &aMouseEvent);
+
+        mpSidebarTextControl->MouseButtonUp(aMouseEvent);
+
+        mpSidebarTextControl->Pop();
+    }
+}
+
 void SwSidebarWin::SetPosSizePixelRect(long nX, long nY, long nWidth, long nHeight,
                                        const SwRect& aAnchorRect, const long aPageBorder)
 {
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index 213e077..07d707b 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -3704,6 +3704,15 @@ void SwEditWin::MouseMove(const MouseEvent& _rMEvt)
 {
     MouseEvent rMEvt(_rMEvt);
 
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        if (vcl::Window* pWindow = m_rView.GetPostItMgr()->IsHitSidebarWindow(rMEvt.GetPosPixel()))
+        {
+            pWindow->MouseMove(rMEvt);
+            return;
+        }
+    }
+
     //ignore key modifiers for format paintbrush
     {
         bool bExecFormatPaintbrush = m_pApplyTempl && m_pApplyTempl->m_pFormatClipboard
@@ -4209,6 +4218,15 @@ void SwEditWin::MouseMove(const MouseEvent& _rMEvt)
  */
 void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt)
 {
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        if (vcl::Window* pWindow = m_rView.GetPostItMgr()->IsHitSidebarWindow(rMEvt.GetPosPixel()))
+        {
+            pWindow->MouseButtonUp(rMEvt);
+            return;
+        }
+    }
+
     bool bCallBase = true;
 
     bool bCallShadowCrsr = m_bWasShdwCrsr;
diff --git a/vcl/source/window/seleng.cxx b/vcl/source/window/seleng.cxx
index 7999818..69b220b 100644
--- a/vcl/source/window/seleng.cxx
+++ b/vcl/source/window/seleng.cxx
@@ -20,6 +20,7 @@
 #include <vcl/window.hxx>
 #include <vcl/seleng.hxx>
 #include <tools/debug.hxx>
+#include <comphelper/lok.hxx>
 
 FunctionSet::~FunctionSet()
 {
@@ -301,7 +302,9 @@ bool SelectionEngine::SelMouseMove( const MouseEvent& rMEvt )
         return true;
 
     aWTimer.SetTimeout( nUpdateInterval );
-    aWTimer.Start();
+    if (!comphelper::LibreOfficeKit::isActive())
+        // Generating fake mouse moves does not work with LOK.
+        aWTimer.Start();
     if ( eSelMode != SINGLE_SELECTION )
     {
         if ( !(nFlags & SelectionEngineFlags::HAS_ANCH) )
commit ac9cf73997ea8e6ea8b5919dd677b4c8faf36acd
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Sat Nov 14 13:39:02 2015 +0100

    sw lok comments: fix cursor position of a newly created sidebar window
    
    With this, pressing ctrl-alt-c to create a new comment has the correct
    cursor position.
    
    Change-Id: Icb8d708dab015d8ffa9bcfe28de66238a75b50bc
    (cherry picked from commit d78432e9a077725046419902c542ce4e5f515705)

diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index bcc1284..01ce695 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -665,7 +665,24 @@ void SwSidebarWin::SetPosAndSize()
     {
         bChange = true;
         SetSizePixel(mPosSize.GetSize());
+
+        if (comphelper::LibreOfficeKit::isActive())
+        {
+            // Position is not yet set at VCL level, but the map mode should
+            // contain the right origin to emit the correct cursor position.
+            mpSidebarTextControl->Push(PushFlags::MAPMODE);
+            Point aOffset(mPosSize.Left(), mPosSize.Top());
+            aOffset = PixelToLogic(aOffset);
+            MapMode aMapMode(mpSidebarTextControl->GetMapMode());
+            aMapMode.SetOrigin(aOffset);
+            mpSidebarTextControl->SetMapMode(aMapMode);
+            mpSidebarTextControl->EnableMapMode(false);
+        }
+
         DoResize();
+
+        if (comphelper::LibreOfficeKit::isActive())
+            mpSidebarTextControl->Pop();
     }
 
     if (GetPosPixel().X() != mPosSize.TopLeft().X() || (std::abs(GetPosPixel().Y() - mPosSize.TopLeft().Y()) > 5) )
commit f06a9ec1fd6d0daad1177f496211ef9befd8849c
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Sat Nov 14 11:06:08 2015 +0100

    sw lok comments: fix callback of newly created outliner views
    
    SwPostItMgr::registerLibreOfficeKitCallback() already took care of
    informing existing outliners, this commit gives a callback to newly
    registered ones as well.
    
    (cherry picked from commit dacc616f7020d045a1cfdb3806436e06046dae10)
    
    Conflicts:
    	sw/inc/drawdoc.hxx
    	sw/source/core/draw/drawdoc.cxx
    
    Change-Id: I660dcb54231a9d404bf80b4284003d119dae6a5c

diff --git a/sw/inc/drawdoc.hxx b/sw/inc/drawdoc.hxx
index bad9c0c..bbf0799 100644
--- a/sw/inc/drawdoc.hxx
+++ b/sw/inc/drawdoc.hxx
@@ -42,6 +42,8 @@ public:
 
     virtual ::com::sun::star::uno::Reference<
                 ::com::sun::star::embed::XStorage> GetDocumentStorage() const SAL_OVERRIDE;
+    /// Get the callback and callback data, previously given to registerLibreOfficeKitCallback().
+    void getLibreOfficeKitCallback(LibreOfficeKitCallback& rCallback, void*& rLibreOfficeKitData);
 
     /// For saving of rectangles as control-replacement for versions < 5.0.
     virtual SdrLayerID GetControlExportLayerId( const SdrObject & ) const SAL_OVERRIDE;
diff --git a/sw/source/core/draw/drawdoc.cxx b/sw/source/core/draw/drawdoc.cxx
index efd0bb1..c7a94d7 100644
--- a/sw/source/core/draw/drawdoc.cxx
+++ b/sw/source/core/draw/drawdoc.cxx
@@ -132,6 +132,12 @@ SdrLayerID SwDrawModel::GetControlExportLayerId( const SdrObject & ) const
     return static_cast<SdrLayerID>(m_pDoc->getIDocumentDrawModelAccess().GetHeavenId());
 }
 
+void SwDrawModel::getLibreOfficeKitCallback(LibreOfficeKitCallback& rCallback, void*& rLibreOfficeKitData)
+{
+    rCallback = mpLibreOfficeKitCallback;
+    rLibreOfficeKitData = mpLibreOfficeKitData;
+}
+
 uno::Reference< uno::XInterface > SwDrawModel::createUnoModel()
 {
     uno::Reference< uno::XInterface > xModel;
diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index 3021c51..bcc1284 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -81,6 +81,8 @@
 #include <drawinglayer/primitive2d/shadowprimitive2d.hxx>
 #include <boost/scoped_ptr.hpp>
 #include <comphelper/lok.hxx>
+#include <IDocumentDrawModelAccess.hxx>
+#include <drawdoc.hxx>
 
 namespace
 {
@@ -531,6 +533,17 @@ void SwSidebarWin::InitControls()
 
     mpOutlinerView->SetAttribs(DefaultItem());
 
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        // If there is a callback already registered, inform the new outliner view about it.
+        SwDrawModel* pDrawModel = mrView.GetWrtShellPtr()->getIDocumentDrawModelAccess()->GetDrawModel();
+        LibreOfficeKitCallback pCallback = 0;
+        void* pData = 0;
+        pDrawModel->getLibreOfficeKitCallback(pCallback, pData);
+        mpOutlinerView->setTiledRendering(mrView.GetWrtShellPtr()->isTiledRendering());
+        mpOutlinerView->registerLibreOfficeKitCallback(pCallback, pData);
+    }
+
     //create Scrollbars
     mpVScrollbar = VclPtr<ScrollBar>::Create(this, WB_3DLOOK |WB_VSCROLL|WB_DRAG);
     mpVScrollbar->EnableNativeWidget(false);
commit 2aa91f0d9408b90c358e5625bf095044aaede1c0
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Sat Nov 14 10:37:45 2015 +0100

    sw lok comments: implement setTextSelection() API
    
    So that it's possible to drag the text selection start/end handles in
    comment text when there is an existing selection.
    
    (cherry picked from commit e320d070bb0d4dd0ceb696f2c7cc5afb7c4273c3)
    
    Conflicts:
    	sw/source/uibase/docvw/SidebarWin.cxx
    
    Change-Id: I3acc4770928d4f385f0ca09a2484a9e112409907

diff --git a/sw/inc/SidebarWin.hxx b/sw/inc/SidebarWin.hxx
index 6fdf77d..f176140 100644
--- a/sw/inc/SidebarWin.hxx
+++ b/sw/inc/SidebarWin.hxx
@@ -183,6 +183,8 @@ class SwSidebarWin : public vcl::Window
         void PaintTile(vcl::RenderContext& rRenderContext, const Rectangle& rRect);
         /// Is there a matching sub-widget inside this sidebar widget for rPointLogic?
         bool IsHitWindow(const Point& rPointLogic);
+        /// Allows adjusting the point or mark of the selection to a document coordinate.
+        void SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool bClearMark);
 
     protected:
         virtual void    DataChanged( const DataChangedEvent& aEvent) SAL_OVERRIDE;
diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index c7b4af6..3021c51 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -82,6 +82,32 @@
 #include <boost/scoped_ptr.hpp>
 #include <comphelper/lok.hxx>
 
+namespace
+{
+
+/// Translate absolute <-> relative twips: LOK wants absolute coordinates as output and gives absolute coordinates as input.
+void lcl_translateTwips(vcl::Window& rParent, vcl::Window& rChild, MouseEvent* pMouseEvent)
+{
+    // Set map mode, so that callback payloads will contain absolute coordinates instead of relative ones.
+    Point aOffset(rChild.GetOutOffXPixel() - rParent.GetOutOffXPixel(), rChild.GetOutOffYPixel() - rParent.GetOutOffYPixel());
+    aOffset = rChild.PixelToLogic(aOffset);
+    MapMode aMapMode(rChild.GetMapMode());
+    aMapMode.SetOrigin(aOffset);
+    rChild.SetMapMode(aMapMode);
+    rChild.EnableMapMode(false);
+
+    if (pMouseEvent)
+    {
+        // Set event coordinates, so they contain relative coordinates instead of absolute ones.
+        Point aPos = pMouseEvent->GetPosPixel();
+        aPos.Move(-aOffset.getX(), -aOffset.getY());
+        MouseEvent aMouseEvent(aPos, pMouseEvent->GetClicks(), pMouseEvent->GetMode(), pMouseEvent->GetButtons(), pMouseEvent->GetModifier());
+        *pMouseEvent = aMouseEvent;
+    }
+}
+
+}
+
 namespace sw { namespace sidebarwindows {
 
 #define METABUTTON_WIDTH        16
@@ -289,6 +315,19 @@ bool SwSidebarWin::IsHitWindow(const Point& rPointLogic)
     return aRectangleLogic.IsInside(rPointLogic);
 }
 
+void SwSidebarWin::SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool bClearMark)
+{
+    mpSidebarTextControl->Push(PushFlags::MAPMODE);
+    MouseEvent aMouseEvent(rPosition);
+    lcl_translateTwips(*EditWin(), *mpSidebarTextControl, &aMouseEvent);
+    Point aPosition(aMouseEvent.GetPosPixel());
+
+    EditView& rEditView = GetOutlinerView()->GetEditView();
+    rEditView.SetCursorLogicPosition(aPosition, bPoint, bClearMark);
+
+    mpSidebarTextControl->Pop();
+}
+
 void SwSidebarWin::Draw(OutputDevice* pDev, const Point& rPt, const Size& rSz, sal_uLong nInFlags)
 {
     if (mpMetadataAuthor->IsVisible() )
@@ -357,27 +396,6 @@ void SwSidebarWin::Draw(OutputDevice* pDev, const Point& rPt, const Size& rSz, s
     }
 }
 
-/// Translate absolute <-> relative twips: LOK wants absolute coordinates as output and gives absolute coordinates as input.
-static void lcl_translateTwips(vcl::Window& rParent, vcl::Window& rChild, MouseEvent* pMouseEvent)
-{
-    // Set map mode, so that callback payloads will contain absolute coordinates instead of relative ones.
-    Point aOffset(rChild.GetOutOffXPixel() - rParent.GetOutOffXPixel(), rChild.GetOutOffYPixel() - rParent.GetOutOffYPixel());
-    aOffset = rChild.PixelToLogic(aOffset);
-    MapMode aMapMode(rChild.GetMapMode());
-    aMapMode.SetOrigin(aOffset);
-    rChild.SetMapMode(aMapMode);
-    rChild.EnableMapMode(false);
-
-    if (pMouseEvent)
-    {
-        // Set event coordinates, so they contain relative coordinates instead of absolute ones.
-        Point aPos = pMouseEvent->GetPosPixel();
-        aPos.Move(-aOffset.getX(), -aOffset.getY());
-        MouseEvent aMouseEvent(aPos, pMouseEvent->GetClicks(), pMouseEvent->GetMode(), pMouseEvent->GetButtons(), pMouseEvent->GetModifier());
-        *pMouseEvent = aMouseEvent;
-    }
-}
-
 void SwSidebarWin::KeyInput(const KeyEvent& rKeyEvent)
 {
     if (mpSidebarTextControl)
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index e2a13fe..213e077 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -6297,6 +6297,16 @@ void SwEditWin::SetCursorTwipPosition(const Point& rPosition, bool bPoint, bool
         }
     }
 
+    if (m_rView.GetPostItMgr())
+    {
+        if (sw::sidebarwindows::SwSidebarWin* pWin = m_rView.GetPostItMgr()->GetActiveSidebarWin())
+        {
+            // Editing postit text.
+            pWin->SetCursorLogicPosition(rPosition, bPoint, bClearMark);
+            return;
+        }
+    }
+
     // Not an SwWrtShell, as that would make SwCrsrShell::GetCrsr() inaccessible.
     SwEditShell& rShell = m_rView.GetWrtShell();
 
commit 33bc6f8b48f41061610e63ea9d35db67b45d7a86
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Sat Nov 14 10:04:38 2015 +0100

    sw lok comments: emit invalidation events in SidebarTextControl
    
    With this, newly typed characters show up instantly in comments, not
    only after changing the zoom level.
    
    (cherry picked from commit 4cbbaf571d3982eccd7f7267df3185b3d321d0da)
    
    Conflicts:
    	sw/source/uibase/docvw/SidebarTxtControl.hxx
    
    Change-Id: I1470db1ec03cc415917375f1f95434cf0944e559

diff --git a/sw/source/uibase/docvw/SidebarTxtControl.cxx b/sw/source/uibase/docvw/SidebarTxtControl.cxx
index c56ce2b..09eca98 100644
--- a/sw/source/uibase/docvw/SidebarTxtControl.cxx
+++ b/sw/source/uibase/docvw/SidebarTxtControl.cxx
@@ -25,6 +25,7 @@
 
 #include <SidebarWin.hxx>
 #include <PostItMgr.hxx>
+#include <edtwin.hxx>
 
 #include <cmdid.h>
 #include <docvw.hrc>
@@ -48,6 +49,7 @@
 #include <editeng/editeng.hxx>
 #include <editeng/editview.hxx>
 #include <editeng/flditem.hxx>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
 
 #include <uitool.hxx>
 #include <view.hxx>
@@ -187,6 +189,30 @@ void SidebarTextControl::Paint(vcl::RenderContext& rRenderContext, const Rectang
     }
 }
 
+void SidebarTextControl::LogicInvalidate(const Rectangle* pRectangle)
+{
+    OString sRectangle;
+    if (!pRectangle)
+        sRectangle = "EMPTY";
+    else
+    {
+        // Convert from relative twips to absolute ones.
+        Rectangle aRectangle(*pRectangle);
+        vcl::Window& rParent = *mrSidebarWin.EditWin();
+        Point aOffset(GetOutOffXPixel() - rParent.GetOutOffXPixel(), GetOutOffYPixel() - rParent.GetOutOffYPixel());
+        rParent.Push(PushFlags::MAPMODE);
+        rParent.EnableMapMode();
+        aOffset = rParent.PixelToLogic(aOffset);
+        rParent.Pop();
+        aRectangle.Move(aOffset.getX(), aOffset.getY());
+
+        sRectangle = aRectangle.toString();
+    }
+
+    SwWrtShell& rWrtShell = mrDocView.GetWrtShell();
+    rWrtShell.libreOfficeKitCallback(LOK_CALLBACK_INVALIDATE_TILES, sRectangle.getStr());
+}
+
 void SidebarTextControl::KeyInput( const KeyEvent& rKeyEvt )
 {
     if (getenv("SW_DEBUG") && rKeyEvt.GetKeyCode().GetCode() == KEY_F12)
diff --git a/sw/source/uibase/docvw/SidebarTxtControl.hxx b/sw/source/uibase/docvw/SidebarTxtControl.hxx
index c428395..57a60d3 100644
--- a/sw/source/uibase/docvw/SidebarTxtControl.hxx
+++ b/sw/source/uibase/docvw/SidebarTxtControl.hxx
@@ -40,6 +40,8 @@ class SidebarTextControl : public Control
 
     protected:
         virtual void    Paint( vcl::RenderContext& rRenderContext, const Rectangle& rRect) SAL_OVERRIDE;
+        /// @see OutputDevice::LogicInvalidate().
+        void LogicInvalidate(const Rectangle* pRectangle) SAL_OVERRIDE;
         virtual void    MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
         virtual void    MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
         virtual void    Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
commit 7e9a60c9b26d8e8942b3efa75be469e8ddda5b3f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Nov 13 17:30:22 2015 +0100

    sw lok comments: fix position of blinking cursor after mouse click
    
    LOK always works in absolute twips (origo being the top left corner of
    SwEditWin), so not only the callbacks have to translate relative twips
    to absolute ones, but the opposite have to be done for mouse event
    coordinates.
    
    With this, clicking at a random position inside a comment places the
    blinking cursor at a reasonable position, not always at 0,0.
    
    (cherry picked from commit 57972554b58a680f47a05f4d6711c99106f80523)
    
    Conflicts:
    	sw/source/uibase/docvw/SidebarWin.cxx
    
    Change-Id: Ic8d20f177acd9e1908acf17698c53a1470bd4aec

diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index de0a44a..c7b4af6 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -357,14 +357,25 @@ void SwSidebarWin::Draw(OutputDevice* pDev, const Point& rPt, const Size& rSz, s
     }
 }
 
-/// We want to work in absolute twips: so set delta between rChild and rParent as origin on rChild, then disable map mode on rChild.
-static void lcl_setAbsoluteTwips(vcl::Window& rParent, vcl::Window& rChild)
+/// Translate absolute <-> relative twips: LOK wants absolute coordinates as output and gives absolute coordinates as input.
+static void lcl_translateTwips(vcl::Window& rParent, vcl::Window& rChild, MouseEvent* pMouseEvent)
 {
+    // Set map mode, so that callback payloads will contain absolute coordinates instead of relative ones.
     Point aOffset(rChild.GetOutOffXPixel() - rParent.GetOutOffXPixel(), rChild.GetOutOffYPixel() - rParent.GetOutOffYPixel());
+    aOffset = rChild.PixelToLogic(aOffset);
     MapMode aMapMode(rChild.GetMapMode());
-    aMapMode.SetOrigin(rChild.PixelToLogic(aOffset));
+    aMapMode.SetOrigin(aOffset);
     rChild.SetMapMode(aMapMode);
     rChild.EnableMapMode(false);
+
+    if (pMouseEvent)
+    {
+        // Set event coordinates, so they contain relative coordinates instead of absolute ones.
+        Point aPos = pMouseEvent->GetPosPixel();
+        aPos.Move(-aOffset.getX(), -aOffset.getY());
+        MouseEvent aMouseEvent(aPos, pMouseEvent->GetClicks(), pMouseEvent->GetMode(), pMouseEvent->GetButtons(), pMouseEvent->GetModifier());
+        *pMouseEvent = aMouseEvent;
+    }
 }
 
 void SwSidebarWin::KeyInput(const KeyEvent& rKeyEvent)
@@ -372,7 +383,7 @@ void SwSidebarWin::KeyInput(const KeyEvent& rKeyEvent)
     if (mpSidebarTextControl)
     {
         mpSidebarTextControl->Push(PushFlags::MAPMODE);
-        lcl_setAbsoluteTwips(*EditWin(), *mpSidebarTextControl);
+        lcl_translateTwips(*EditWin(), *mpSidebarTextControl, nullptr);
 
         mpSidebarTextControl->KeyInput(rKeyEvent);
 
@@ -385,9 +396,10 @@ void SwSidebarWin::MouseButtonDown(const MouseEvent& rMouseEvent)
     if (mpSidebarTextControl)
     {
         mpSidebarTextControl->Push(PushFlags::MAPMODE);
-        lcl_setAbsoluteTwips(*EditWin(), *mpSidebarTextControl);
+        MouseEvent aMouseEvent(rMouseEvent);
+        lcl_translateTwips(*EditWin(), *mpSidebarTextControl, &aMouseEvent);
 
-        mpSidebarTextControl->MouseButtonDown(rMouseEvent);
+        mpSidebarTextControl->MouseButtonDown(aMouseEvent);
 
         mpSidebarTextControl->Pop();
     }
commit f12c15f20d4ce198a467650832cebb29b55255b4
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Nov 13 14:51:13 2015 +0100

    sw lok: disable comment menu button for now
    
    Change-Id: Ic052544b2835181652732b8de9eaf79572a9db6e
    (cherry picked from commit 022c716fc89c7315a7c454c01e2fe70d5aece289)

diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index 31993ea..de0a44a 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -252,6 +252,10 @@ void SwSidebarWin::PaintTile(vcl::RenderContext& rRenderContext, const Rectangle
         if (pChild == mpVScrollbar.get())
             continue;
 
+        // No point in showing this button till click on it are not handled.
+        if (pChild == mpMenuButton.get())
+            continue;
+
         rRenderContext.Push(PushFlags::MAPMODE);
         Point aOffset(PixelToLogic(pChild->GetPosPixel()));
         MapMode aMapMode(rRenderContext.GetMapMode());
commit cac5525f29c686caf1701b793d854784deadee56
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Nov 13 14:42:35 2015 +0100

    editeng lok: respect origin of map mode for TEXT_SELECTION
    
    With this, selections of Writer comment text show up at the correct
    position, not at the top left corner of the window.
    
    Change-Id: If865503d9a02a27730e382d65c42c706dd533a93
    (cherry picked from commit 22e97c130868fe7d7529cfcfb2a240f775bd8916)

diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx
index 19a9bb2..8f60669 100644
--- a/editeng/source/editeng/impedit.cxx
+++ b/editeng/source/editeng/impedit.cxx
@@ -328,6 +328,12 @@ void ImpEditView::DrawSelection( EditSelection aTmpSel, vcl::Region* pRegion, Ou
         if (isTiledRendering() && !pOldRegion)
         {
             bool bMm100ToTwip = pOutWin->GetMapMode().GetMapUnit() == MAP_100TH_MM;
+
+            Point aOrigin;
+            if (pOutWin->GetMapMode().GetMapUnit() == MAP_TWIP)
+                // Writer comments: they use editeng, but are separate widgets.
+                aOrigin = pOutWin->GetMapMode().GetOrigin();
+
             OString sRectangle;
             // If we are not in selection mode, then the exported selection should be empty.
             if (pEditEngine->pImpEditEngine->IsInSelectionMode())
@@ -341,12 +347,14 @@ void ImpEditView::DrawSelection( EditSelection aTmpSel, vcl::Region* pRegion, Ou
                     Rectangle aStart = Rectangle(rStart.Left(), rStart.Top(), rStart.Left() + 1, rStart.Bottom());
                     if (bMm100ToTwip)
                         aStart = OutputDevice::LogicToLogic(aStart, MAP_100TH_MM, MAP_TWIP);
+                    aStart.Move(aOrigin.getX(), aOrigin.getY());
                     libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION_START, aStart.toString().getStr());
 
                     Rectangle& rEnd = aRectangles.back();
                     Rectangle aEnd = Rectangle(rEnd.Right() - 1, rEnd.Top(), rEnd.Right(), rEnd.Bottom());
                     if (bMm100ToTwip)
                         aEnd = OutputDevice::LogicToLogic(aEnd, MAP_100TH_MM, MAP_TWIP);
+                    aEnd.Move(aOrigin.getX(), aOrigin.getY());
                     libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION_END, aEnd.toString().getStr());
                 }
 
@@ -356,6 +364,7 @@ void ImpEditView::DrawSelection( EditSelection aTmpSel, vcl::Region* pRegion, Ou
                     Rectangle& rRectangle = aRectangles[i];
                     if (bMm100ToTwip)
                         rRectangle = OutputDevice::LogicToLogic(rRectangle, MAP_100TH_MM, MAP_TWIP);
+                    rRectangle.Move(aOrigin.getX(), aOrigin.getY());
                     v.push_back(rRectangle.toString().getStr());
                 }
                 sRectangle = comphelper::string::join("; ", v);
commit a792468f017fcd7fc040affe288bd058c1ba6523
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Nov 13 13:33:32 2015 +0100

    sw lok: fix blinking cursor position of comments
    
    With this, it is possible to click inside a comment (and get a blinking
    cursor inside a comment), and also possible to use the arrow keys to
    native around and still get correct blinking cursor position.
    
    (cherry picked from commit 5fb91dfd804cd6f3d585bb4113b9a68083ac71ee)
    
    Conflicts:
    	sw/inc/SidebarWin.hxx
    	sw/source/uibase/docvw/SidebarTxtControl.hxx
    	sw/source/uibase/docvw/SidebarWin.cxx
    
    Change-Id: I29eb1e60e4e571151f0b18bec8cf765ea09af09f

diff --git a/sw/inc/SidebarWin.hxx b/sw/inc/SidebarWin.hxx
index bb1a44a..6fdf77d 100644
--- a/sw/inc/SidebarWin.hxx
+++ b/sw/inc/SidebarWin.hxx
@@ -179,9 +179,10 @@ class SwSidebarWin : public vcl::Window
 
         virtual void    Draw(OutputDevice* pDev, const Point&, const Size&, sal_uLong) SAL_OVERRIDE;
         virtual void KeyInput(const KeyEvent& rKeyEvt) SAL_OVERRIDE;
+        virtual void MouseButtonDown(const MouseEvent& rMouseEvent) SAL_OVERRIDE;
         void PaintTile(vcl::RenderContext& rRenderContext, const Rectangle& rRect);
-        /// Get the matching sub-widget inside this sidebar widget for rPointLogic, if any.
-        vcl::Window* IsHitWindow(const Point& rPointLogic);
+        /// Is there a matching sub-widget inside this sidebar widget for rPointLogic?
+        bool IsHitWindow(const Point& rPointLogic);
 
     protected:
         virtual void    DataChanged( const DataChangedEvent& aEvent) SAL_OVERRIDE;
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx
index 703a433..871a642 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -1736,9 +1736,9 @@ vcl::Window* SwPostItMgr::IsHitSidebarWindow(const Point& rPointLogic)
             if (!pPostIt)
                 continue;
 
-            if (vcl::Window* pWindow = pPostIt->IsHitWindow(rPointLogic))
+            if (pPostIt->IsHitWindow(rPointLogic))
             {
-                pRet = pWindow;
+                pRet = pPostIt;
                 break;
             }
         }
diff --git a/sw/source/uibase/docvw/SidebarTxtControl.hxx b/sw/source/uibase/docvw/SidebarTxtControl.hxx
index 02d52eb..c428395 100644
--- a/sw/source/uibase/docvw/SidebarTxtControl.hxx
+++ b/sw/source/uibase/docvw/SidebarTxtControl.hxx
@@ -41,7 +41,6 @@ class SidebarTextControl : public Control
     protected:
         virtual void    Paint( vcl::RenderContext& rRenderContext, const Rectangle& rRect) SAL_OVERRIDE;
         virtual void    MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
-        virtual void    MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
         virtual void    MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
         virtual void    Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
         virtual void    LoseFocus() SAL_OVERRIDE;
@@ -61,6 +60,7 @@ class SidebarTextControl : public Control
 
         virtual void GetFocus() SAL_OVERRIDE;
         virtual void KeyInput( const KeyEvent& rKeyEvt ) SAL_OVERRIDE;
+        virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
 
         OutlinerView* GetTextView() const;
 
diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index 3fe2953..31993ea 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -279,12 +279,10 @@ void SwSidebarWin::PaintTile(vcl::RenderContext& rRenderContext, const Rectangle
     rRenderContext.Push(PushFlags::NONE);
 }
 
-vcl::Window* SwSidebarWin::IsHitWindow(const Point& rPointLogic)
+bool SwSidebarWin::IsHitWindow(const Point& rPointLogic)
 {
     Rectangle aRectangleLogic(EditWin()->PixelToLogic(GetPosPixel()), EditWin()->PixelToLogic(GetSizePixel()));
-    if (aRectangleLogic.IsInside(rPointLogic))
-        return mpSidebarTextControl;
-    return 0;
+    return aRectangleLogic.IsInside(rPointLogic);
 }
 
 void SwSidebarWin::Draw(OutputDevice* pDev, const Point& rPt, const Size& rSz, sal_uLong nInFlags)
@@ -355,10 +353,40 @@ void SwSidebarWin::Draw(OutputDevice* pDev, const Point& rPt, const Size& rSz, s
     }
 }
 
+/// We want to work in absolute twips: so set delta between rChild and rParent as origin on rChild, then disable map mode on rChild.
+static void lcl_setAbsoluteTwips(vcl::Window& rParent, vcl::Window& rChild)
+{
+    Point aOffset(rChild.GetOutOffXPixel() - rParent.GetOutOffXPixel(), rChild.GetOutOffYPixel() - rParent.GetOutOffYPixel());
+    MapMode aMapMode(rChild.GetMapMode());
+    aMapMode.SetOrigin(rChild.PixelToLogic(aOffset));
+    rChild.SetMapMode(aMapMode);
+    rChild.EnableMapMode(false);
+}
+
 void SwSidebarWin::KeyInput(const KeyEvent& rKeyEvent)
 {
     if (mpSidebarTextControl)
+    {
+        mpSidebarTextControl->Push(PushFlags::MAPMODE);
+        lcl_setAbsoluteTwips(*EditWin(), *mpSidebarTextControl);
+
         mpSidebarTextControl->KeyInput(rKeyEvent);
+
+        mpSidebarTextControl->Pop();
+    }
+}
+
+void SwSidebarWin::MouseButtonDown(const MouseEvent& rMouseEvent)
+{
+    if (mpSidebarTextControl)
+    {
+        mpSidebarTextControl->Push(PushFlags::MAPMODE);
+        lcl_setAbsoluteTwips(*EditWin(), *mpSidebarTextControl);
+
+        mpSidebarTextControl->MouseButtonDown(rMouseEvent);
+
+        mpSidebarTextControl->Pop();
+    }
 }
 
 void SwSidebarWin::SetPosSizePixelRect(long nX, long nY, long nWidth, long nHeight,
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index 9276852..e2a13fe 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -2770,14 +2770,7 @@ void SwEditWin::MouseButtonDown(const MouseEvent& _rMEvt)
     {
         if (vcl::Window* pWindow = m_rView.GetPostItMgr()->IsHitSidebarWindow(rMEvt.GetPosPixel()))
         {
-            bool bDisableMapMode = pWindow->IsMapModeEnabled();
-            if (bDisableMapMode)
-                pWindow->EnableMapMode(false);
-
             pWindow->MouseButtonDown(rMEvt);
-
-            if (bDisableMapMode)
-                pWindow->EnableMapMode();
             return;
         }
     }
commit 739dad1e67468a256c1d0e15e4e99d055668a1b1
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Nov 13 11:33:43 2015 +0100

    editeng lok: respect origin of map mode for INVALIDATE_VISIBLE_CURSOR
    
    Writer comments are separate widgets, but we want to have coordinates in
    absolutes twips, so give Writer a chance to inform us about the delta.
    
    For now only do this in case the map unit is twips, as Impress sets the
    origin already.
    
    Change-Id: Idf340944165e44b0888c00965d6be7798712ff76
    (cherry picked from commit e988ab84f1c32519bfca758086c749ba98a5a85f)

diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx
index f78cfab..19a9bb2 100644
--- a/editeng/source/editeng/impedit.cxx
+++ b/editeng/source/editeng/impedit.cxx
@@ -946,6 +946,13 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor, sal_uInt16
             // LOK output is always in twips, convert from mm100 if necessary.
             if (pOutWin->GetMapMode().GetMapUnit() == MAP_100TH_MM)
                 aRect = OutputDevice::LogicToLogic(aRect, MAP_100TH_MM, MAP_TWIP);
+            else if (pOutWin->GetMapMode().GetMapUnit() == MAP_TWIP)
+            {
+                // Writer comments: they use editeng, but are separate widgets.
+                Point aOrigin = pOutWin->GetMapMode().GetOrigin();
+                // Move the rectangle, so that we output absolute twips.
+                aRect.Move(aOrigin.getX(), aOrigin.getY());
+            }
             // Let the LOK client decide the cursor width.
             aRect.setWidth(0);
 
commit 8d3c71815d897cd1baa82b23ffc6e38edbdd7e9d
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Nov 13 10:03:10 2015 +0100

    sw: don't show main cursor when editing a postit
    
    This is primarily for tiled editing that doesn't know about multiple
    cursors, so if both the postit cursor and the main cursor is shown for a
    short period of time, then the main one is hidden, then gtktiledviewer
    still shows the main one.
    
    OTOH if we can avoid showing the cursor in general just to hide it a bit
    later in general, let's not do that.
    
    With this, the "cursor is shown at the comment anchor, not inside the
    anchor when clicking on the postit" bug disappears.
    
    Change-Id: I2383292c5f84604dc8b126510b0797b8426920ae
    (cherry picked from commit 1c482cb54b4dab4c5b549ecd2395104f042e4101)

diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 9a11182..91646dc 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -66,6 +66,7 @@
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <comphelper/lok.hxx>
 #include <comphelper/string.hxx>
+#include <PostItMgr.hxx>
 
 using namespace com::sun::star;
 using namespace util;
@@ -1292,6 +1293,15 @@ void SwCrsrShell::Paint(vcl::RenderContext& rRenderContext, const Rectangle &rRe
             pAktCrsr->Invalidate( aRect );
 
     }
+
+    if (SwPostItMgr* pPostItMgr = GetPostItMgr())
+    {
+        // No point in showing the cursor for Writer text when there is an
+        // active annotation edit.
+        if (bVis)
+            bVis = !pPostItMgr->HasActiveSidebarWin();
+    }
+
     if( m_bSVCrsrVis && bVis ) // also show SV cursor again
         m_pVisCrsr->Show();
 }
commit ba040aa02ad1aac242c4966905941504e5104fd3
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Nov 12 16:56:45 2015 +0100

    sw lok: forward key events to annotation window if necessary
    
    And to allow proper reaction by the annotation windows, inform them when
    a LOK callback is registered.
    
    With this, it's possible to modify the contents of annotations via LOK.
    
    (cherry picked from commit 1ba9d7fd2a7a3e2b4f52ed0f5efdf7df867b9db3)
    
    Conflicts:
    	sw/inc/PostItMgr.hxx
    	sw/inc/SidebarWin.hxx
    	sw/source/core/view/viewsh.cxx
    	sw/source/uibase/docvw/SidebarTxtControl.hxx
    	sw/source/uibase/docvw/edtwin.cxx
    
    Change-Id: I4489941512197880940e20cbaeb0b47a7a6f26fc

diff --git a/sw/inc/PostItMgr.hxx b/sw/inc/PostItMgr.hxx
index 9451c3f..fb69d29 100644
--- a/sw/inc/PostItMgr.hxx
+++ b/sw/inc/PostItMgr.hxx
@@ -34,6 +34,8 @@
 #include <SidebarWindowsTypes.hxx>
 #include <svl/lstner.hxx>
 #include <vcl/vclptr.hxx>
+#define LOK_USE_UNSTABLE_API
+#include <LibreOfficeKit/LibreOfficeKitTypes.h>
 
 class OutputDevice;
 class SwWrtShell;
@@ -291,6 +293,8 @@ class SwPostItMgr: public SfxListener
 
             void DrawNotesForPage(OutputDevice *pOutDev, sal_uInt32 nPage);
             void PaintTile(OutputDevice& rRenderContext, const Rectangle& rRect);
+            /// Informs already created annotations about a newly registered LOK callback.
+            void registerLibreOfficeKitCallback(LibreOfficeKitCallback pCallback, void* pData);
 };
 
 #endif
diff --git a/sw/inc/SidebarWin.hxx b/sw/inc/SidebarWin.hxx
index fc95ec8..bb1a44a 100644
--- a/sw/inc/SidebarWin.hxx
+++ b/sw/inc/SidebarWin.hxx
@@ -178,6 +178,7 @@ class SwSidebarWin : public vcl::Window
         virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible() SAL_OVERRIDE;
 
         virtual void    Draw(OutputDevice* pDev, const Point&, const Size&, sal_uLong) SAL_OVERRIDE;
+        virtual void KeyInput(const KeyEvent& rKeyEvt) SAL_OVERRIDE;
         void PaintTile(vcl::RenderContext& rRenderContext, const Rectangle& rRect);
         /// Get the matching sub-widget inside this sidebar widget for rPointLogic, if any.
         vcl::Window* IsHitWindow(const Point& rPointLogic);
diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx
index a27630f..e7f65b5 100644
--- a/sw/source/core/view/viewsh.cxx
+++ b/sw/source/core/view/viewsh.cxx
@@ -120,6 +120,8 @@ void SwViewShell::ToggleHeaderFooterEdit()
 void SwViewShell::registerLibreOfficeKitCallback(LibreOfficeKitCallback pCallback, void* pData)
 {
     getIDocumentDrawModelAccess()->GetDrawModel()->registerLibreOfficeKitCallback(pCallback, pData);
+    if (SwPostItMgr* pPostItMgr = GetPostItMgr())
+        pPostItMgr->registerLibreOfficeKitCallback(pCallback, pData);
 }
 
 void SwViewShell::libreOfficeKitCallback(int nType, const char* pPayload) const
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx
index eb5755e..703a433 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -881,6 +881,19 @@ void SwPostItMgr::PaintTile(OutputDevice& rRenderContext, const Rectangle& /*rRe
     }
 }
 
+void SwPostItMgr::registerLibreOfficeKitCallback(LibreOfficeKitCallback pCallback, void* pData)
+{
+    for (SwSidebarItem* pItem : mvPostItFields)
+    {
+        SwSidebarWin* pPostIt = pItem->pPostIt;
+        if (!pPostIt)
+            continue;
+
+        pPostIt->GetOutlinerView()->setTiledRendering(mpWrtShell->isTiledRendering());
+        pPostIt->GetOutlinerView()->registerLibreOfficeKitCallback(pCallback, pData);
+    }
+}
+
 void SwPostItMgr::Scroll(const long lScroll,const unsigned long aPage)
 {
     OSL_ENSURE((lScroll % GetScrollSize() )==0,"SwPostItMgr::Scroll: scrolling by wrong value");
diff --git a/sw/source/uibase/docvw/SidebarTxtControl.hxx b/sw/source/uibase/docvw/SidebarTxtControl.hxx
index 1a6d667..02d52eb 100644
--- a/sw/source/uibase/docvw/SidebarTxtControl.hxx
+++ b/sw/source/uibase/docvw/SidebarTxtControl.hxx
@@ -40,7 +40,6 @@ class SidebarTextControl : public Control
 
     protected:
         virtual void    Paint( vcl::RenderContext& rRenderContext, const Rectangle& rRect) SAL_OVERRIDE;
-        virtual void    KeyInput( const KeyEvent& rKeyEvt ) SAL_OVERRIDE;
         virtual void    MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
         virtual void    MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
         virtual void    MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
@@ -61,6 +60,7 @@ class SidebarTextControl : public Control
         virtual void dispose() SAL_OVERRIDE;
 
         virtual void GetFocus() SAL_OVERRIDE;
+        virtual void KeyInput( const KeyEvent& rKeyEvt ) SAL_OVERRIDE;
 
         OutlinerView* GetTextView() const;
 
diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index dab3a92..3fe2953 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -355,6 +355,12 @@ void SwSidebarWin::Draw(OutputDevice* pDev, const Point& rPt, const Size& rSz, s
     }
 }
 
+void SwSidebarWin::KeyInput(const KeyEvent& rKeyEvent)
+{
+    if (mpSidebarTextControl)
+        mpSidebarTextControl->KeyInput(rKeyEvent);
+}
+
 void SwSidebarWin::SetPosSizePixelRect(long nX, long nY, long nWidth, long nHeight,
                                        const SwRect& aAnchorRect, const long aPageBorder)
 {
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index 11ca172..9276852 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -145,6 +145,7 @@
 #include <xmloff/odffields.hxx>
 
 #include <PostItMgr.hxx>
+#include <SidebarWin.hxx>
 
 #include <algorithm>
 #include <vector>
@@ -1324,6 +1325,15 @@ void SwEditWin::KeyInput(const KeyEvent &rKEvt)
 {
     SwWrtShell &rSh = m_rView.GetWrtShell();
 
+    if (comphelper::LibreOfficeKit::isActive() && m_rView.GetPostItMgr())
+    {
+        if (vcl::Window* pWindow = m_rView.GetPostItMgr()->GetActiveSidebarWin())
+        {
+            pWindow->KeyInput(rKEvt);
+            return;
+        }
+    }
+
     if( rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE &&
         m_pApplyTempl && m_pApplyTempl->m_pFormatClipboard )
     {
commit 2f6784080df8e22bc29d9e817ea9b17ecbcbf700
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Nov 12 14:21:03 2015 +0100

    sw lok: route SwEditWin::MouseButtonDown to SidebarTextControl if necessary
    
    LOK sends all mouse events to SwEditWin, so add initial hit testing in
    its mouse handler to forward the mouse events to the right VCL widget.
    
    (cherry picked from commit b7ecf6279ef3343f12fce776862c027bfeff6617)
    
    Conflicts:
    	sw/inc/PostItMgr.hxx
    	sw/source/uibase/docvw/SidebarWin.cxx
    	sw/source/uibase/docvw/edtwin.cxx
    
    Change-Id: I67e8e19f47156261fd7c7eafd4e63f743e0c4ce9

diff --git a/sw/inc/PostItMgr.hxx b/sw/inc/PostItMgr.hxx
index 2f9e328..9451c3f 100644
--- a/sw/inc/PostItMgr.hxx
+++ b/sw/inc/PostItMgr.hxx
@@ -234,6 +234,8 @@ class SwPostItMgr: public SfxListener
             Rectangle GetTopScrollRect(const unsigned long aPage) const;
 
             bool IsHit(const Point &aPointPixel);
+            /// Get the matching window that is responsible for handling mouse events of rPointLogic, if any.
+            vcl::Window* IsHitSidebarWindow(const Point& rPointLogic);
             Color GetArrowColor(sal_uInt16 aDirection,unsigned long aPage) const;
 
             sw::annotation::SwAnnotationWin* GetAnnotationWin(const SwPostItField* pField) const;
diff --git a/sw/inc/SidebarWin.hxx b/sw/inc/SidebarWin.hxx
index 59d3ea6..fc95ec8 100644
--- a/sw/inc/SidebarWin.hxx
+++ b/sw/inc/SidebarWin.hxx
@@ -179,6 +179,8 @@ class SwSidebarWin : public vcl::Window
 
         virtual void    Draw(OutputDevice* pDev, const Point&, const Size&, sal_uLong) SAL_OVERRIDE;
         void PaintTile(vcl::RenderContext& rRenderContext, const Rectangle& rRect);
+        /// Get the matching sub-widget inside this sidebar widget for rPointLogic, if any.
+        vcl::Window* IsHitWindow(const Point& rPointLogic);
 
     protected:
         virtual void    DataChanged( const DataChangedEvent& aEvent) SAL_OVERRIDE;
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx
index 2a2e5d5..eb5755e 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -1706,6 +1706,37 @@ bool SwPostItMgr::IsHit(const Point &aPointPixel)
     }
     return false;
 }
+
+vcl::Window* SwPostItMgr::IsHitSidebarWindow(const Point& rPointLogic)
+{
+    vcl::Window* pRet = 0;
+
+    if (HasNotes() && ShowNotes())
+    {
+        bool bEnableMapMode = !mpEditWin->IsMapModeEnabled();
+        if (bEnableMapMode)
+            mpEditWin->EnableMapMode();
+
+        for (SwSidebarItem* pItem : mvPostItFields)
+        {
+            SwSidebarWin* pPostIt = pItem->pPostIt;
+            if (!pPostIt)
+                continue;
+
+            if (vcl::Window* pWindow = pPostIt->IsHitWindow(rPointLogic))
+            {
+                pRet = pWindow;
+                break;
+            }
+        }
+
+        if (bEnableMapMode)
+            mpEditWin->EnableMapMode(false);
+    }
+
+    return pRet;
+}
+
 Rectangle SwPostItMgr::GetBottomScrollRect(const unsigned long aPage) const
 {
     SwRect aPageRect = mPages[aPage-1]->mPageRect;
diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index b8fcf7c..dab3a92 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -279,6 +279,14 @@ void SwSidebarWin::PaintTile(vcl::RenderContext& rRenderContext, const Rectangle
     rRenderContext.Push(PushFlags::NONE);
 }
 
+vcl::Window* SwSidebarWin::IsHitWindow(const Point& rPointLogic)
+{
+    Rectangle aRectangleLogic(EditWin()->PixelToLogic(GetPosPixel()), EditWin()->PixelToLogic(GetSizePixel()));
+    if (aRectangleLogic.IsInside(rPointLogic))
+        return mpSidebarTextControl;
+    return 0;
+}
+
 void SwSidebarWin::Draw(OutputDevice* pDev, const Point& rPt, const Size& rSz, sal_uLong nInFlags)
 {
     if (mpMetadataAuthor->IsVisible() )
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index f392010..11ca172 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -2756,6 +2756,21 @@ void SwEditWin::MouseButtonDown(const MouseEvent& _rMEvt)
     if (m_rView.GetPostItMgr()->IsHit(rMEvt.GetPosPixel()))
         return;
 
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        if (vcl::Window* pWindow = m_rView.GetPostItMgr()->IsHitSidebarWindow(rMEvt.GetPosPixel()))
+        {
+            bool bDisableMapMode = pWindow->IsMapModeEnabled();
+            if (bDisableMapMode)
+                pWindow->EnableMapMode(false);
+
+            pWindow->MouseButtonDown(rMEvt);
+
+            if (bDisableMapMode)
+                pWindow->EnableMapMode();
+            return;
+        }
+    }
     m_rView.GetPostItMgr()->SetActiveSidebarWin(0);
 
     GrabFocus();
commit 932353ebd8422a393405c52923c8a0e3a5dc4e50
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Nov 11 18:05:45 2015 +0100

    sw lok: fix sidebarwindows::SwSidebarWin pixel position
    
    So SwSidebarWin member functions don't get twip values when they call
    GetPosPixel().
    
    Change-Id: Ied4ff7f49d0320766b045d78f731900af92d37ef
    (cherry picked from commit c4ef30ea916752ba5a057b49960a60a55f70c84c)

diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx
index 2310dd6..2a2e5d5 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -593,6 +593,10 @@ void SwPostItMgr::PreparePageContainer()
 
 void SwPostItMgr::LayoutPostIts()
 {
+    bool bEnableMapMode = comphelper::LibreOfficeKit::isActive() && !mpEditWin->IsMapModeEnabled();
+    if (bEnableMapMode)
+        mpEditWin->EnableMapMode();
+
     if ( !mvPostItFields.empty() && !mbWaitingForCalcRects )
     {
         mbLayouting = true;
@@ -809,6 +813,9 @@ void SwPostItMgr::LayoutPostIts()
 
         mbLayouting = false;
     }
+
+    if (bEnableMapMode)
+        mpEditWin->EnableMapMode(false);
 }
 
 bool SwPostItMgr::BorderOverPageBorder(unsigned long aPage) const
@@ -856,6 +863,8 @@ void SwPostItMgr::PaintTile(OutputDevice& rRenderContext, const Rectangle& /*rRe
         if (!pPostIt)
             continue;
 
+        bool bEnableMapMode = !mpEditWin->IsMapModeEnabled();
+        mpEditWin->EnableMapMode();
         rRenderContext.Push(PushFlags::MAPMODE);
         Point aOffset(mpEditWin->PixelToLogic(pPostIt->GetPosPixel()));
         MapMode aMapMode(rRenderContext.GetMapMode());
@@ -867,6 +876,8 @@ void SwPostItMgr::PaintTile(OutputDevice& rRenderContext, const Rectangle& /*rRe
         pPostIt->PaintTile(rRenderContext, aRectangle);
 
         rRenderContext.Pop();
+        if (bEnableMapMode)
+            mpEditWin->EnableMapMode(false);
     }
 }
 
commit 1ec988edf529d1e4f5984364abd4e3cc577f7b7c
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Nov 10 20:08:49 2015 +0100

    This PixelToLogic() call can be conditional in SwSidebarWin::SetPosAndSize()
    
    It is only needed when tiled rendering.
    
    (cherry picked from commit 88f4866803fc766503292252cb36af4a70ea98fd)
    
    Conflicts:
    	sw/source/uibase/docvw/SidebarWin.cxx
    
    Change-Id: Ie1668f5f3d4d17abc212e2262a6c155dcb855d2e

diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index 7741499..b8fcf7c 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -607,15 +607,15 @@ void SwSidebarWin::SetPosAndSize()
 
         // LOK has map mode disabled, and we still want to perform pixel ->
         // twips conversion for the size of the line above the note.
-        bool bEnableMapMode = comphelper::LibreOfficeKit::isActive() && !EditWin()->IsMapModeEnabled();
-        if (bEnableMapMode)
+        if (comphelper::LibreOfficeKit::isActive() && !EditWin()->IsMapModeEnabled())
+        {
             EditWin()->EnableMapMode();
-        Size aSize(aLineEnd.getX() - aLineStart.getX(), aLineEnd.getY() - aLineStart.getY());
-        aSize = EditWin()->PixelToLogic(aSize);
-        aLineEnd = aLineStart;
-        aLineEnd.Move(aSize.getWidth(), aSize.getHeight());
-        if (bEnableMapMode)
+            Size aSize(aLineEnd.getX() - aLineStart.getX(), aLineEnd.getY() - aLineStart.getY());
+            aSize = EditWin()->PixelToLogic(aSize);
+            aLineEnd = aLineStart;
+            aLineEnd.Move(aSize.getWidth(), aSize.getHeight());
             EditWin()->EnableMapMode(false);
+        }
 
         if (!IsPreview())
         {
commit 155c57d4ceee04056c4ca655e67ebd551f388f2f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Nov 10 19:29:22 2015 +0100

    sw lok: fix length of the line overlay above the notes
    
    With this, e.g. a line above a note (with width of 180 px) is also 180
    px, not 12 px.
    
    (cherry picked from commit 096408073c2de484cba3736d13b57d22b7f48775)
    
    Change-Id: I7c4eeda1bc904242dc298013411b9671ba0f2149

diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index 75b3f39..7741499 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -605,6 +605,18 @@ void SwSidebarWin::SetPosAndSize()
             break;
         }
 
+        // LOK has map mode disabled, and we still want to perform pixel ->
+        // twips conversion for the size of the line above the note.
+        bool bEnableMapMode = comphelper::LibreOfficeKit::isActive() && !EditWin()->IsMapModeEnabled();
+        if (bEnableMapMode)
+            EditWin()->EnableMapMode();
+        Size aSize(aLineEnd.getX() - aLineStart.getX(), aLineEnd.getY() - aLineStart.getY());
+        aSize = EditWin()->PixelToLogic(aSize);
+        aLineEnd = aLineStart;
+        aLineEnd.Move(aSize.getWidth(), aSize.getHeight());
+        if (bEnableMapMode)
+            EditWin()->EnableMapMode(false);
+
         if (!IsPreview())
         {
             if (mpAnchor)
commit 0d990874e8b87e131843415c558b8dedd0efe556
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Nov 10 14:08:26 2015 +0100

    sw lok: fix width of the notes sidebar
    
    The map mode is in general disabled during tiled rendering, so mouse
    positions can be sent in using twips, but here we have to temporarily
    enable it, otherwise the width will be returned always in pixels.
    
    With this, the gray background of the sidebar has the proper width, not
    e.g. fifteenth of the expected value (using default zoom).
    
    Change-Id: I4380ee0ba6bcda97cf71735161dbdc826e7a2532
    (cherry picked from commit 6c3dbdbccbcccf914360dac1167599c5b89446a8)

diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx
index 35152d0..2310dd6 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -74,6 +74,7 @@
 
 #include <i18nlangtag/mslangid.hxx>
 #include <i18nlangtag/lang.h>
+#include <comphelper/lok.hxx>
 
 #include "annotsh.hxx"
 #include "swabstdlg.hxx"
@@ -1813,7 +1814,15 @@ unsigned long SwPostItMgr::GetSidebarWidth(bool bPx) const
     if (bPx)
         return aWidth;
     else
-        return mpEditWin->PixelToLogic(Size( aWidth ,0)).Width();
+    {
+        bool bEnableMapMode = comphelper::LibreOfficeKit::isActive() && !mpEditWin->IsMapModeEnabled();
+        if (bEnableMapMode)
+            mpEditWin->EnableMapMode();
+        long nRet = mpEditWin->PixelToLogic(Size(aWidth, 0)).Width();
+        if (bEnableMapMode)
+            mpEditWin->EnableMapMode(false);
+        return nRet;
+    }
 }
 
 unsigned long SwPostItMgr::GetSidebarBorderWidth(bool bPx) const
commit 769be57ca47581ae1669b154a92eb1410c7e5f90
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Nov 10 11:42:36 2015 +0100

    sw: allow doc model xml dump creation while editing comment text
    
    Change-Id: Ie682cfe97b8c48bc66575b89875ca617dbb8ab4e
    (cherry picked from commit b3b9f2c5b4dde4c5ea9736f8ceda4cdb98036b0b)

diff --git a/sw/source/uibase/docvw/SidebarTxtControl.cxx b/sw/source/uibase/docvw/SidebarTxtControl.cxx
index e9e1e34..c56ce2b 100644
--- a/sw/source/uibase/docvw/SidebarTxtControl.cxx
+++ b/sw/source/uibase/docvw/SidebarTxtControl.cxx
@@ -20,6 +20,8 @@
 #include <SidebarTxtControl.hxx>
 
 #include <SidebarTxtControlAcc.hxx>
+#include <docsh.hxx>
+#include <doc.hxx>
 
 #include <SidebarWin.hxx>
 #include <PostItMgr.hxx>
@@ -187,6 +189,15 @@ void SidebarTextControl::Paint(vcl::RenderContext& rRenderContext, const Rectang
 
 void SidebarTextControl::KeyInput( const KeyEvent& rKeyEvt )
 {
+    if (getenv("SW_DEBUG") && rKeyEvt.GetKeyCode().GetCode() == KEY_F12)
+    {
+        if (rKeyEvt.GetKeyCode().IsShift())
+        {
+            mrDocView.GetDocShell()->GetDoc()->dumpAsXml();
+            return;
+        }
+    }
+
     const vcl::KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
     sal_uInt16 nKey = rKeyCode.GetCode();
     if ( ( rKeyCode.IsMod1() && rKeyCode.IsMod2() ) &&
commit 4fcd60730969c3f7259141840ffd069874935d88
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Nov 10 11:33:03 2015 +0100

    sw doc model xml dump: show comment text
    
    (cherry picked from commit 9b504ad3ae9f71ea02df2ab6f2c2fbd59d38ae9a)
    
    Conflicts:
    	sw/inc/docufld.hxx
    
    Change-Id: If15ca89f2b7c54441f076eb233c4e1414dac25c0

diff --git a/sw/inc/docufld.hxx b/sw/inc/docufld.hxx
index f7d8cf4..6a7f0e6 100644
--- a/sw/inc/docufld.hxx
+++ b/sw/inc/docufld.hxx
@@ -487,6 +487,7 @@ public:
     virtual bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const SAL_OVERRIDE;
     virtual bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) SAL_OVERRIDE;
     virtual OUString    GetDescription() const SAL_OVERRIDE;
+    virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const SAL_OVERRIDE;
 };
 
 class SwDocInfoFieldType : public SwValueFieldType
diff --git a/sw/inc/fldbas.hxx b/sw/inc/fldbas.hxx
index 6406fae..95c86b2 100644
--- a/sw/inc/fldbas.hxx
+++ b/sw/inc/fldbas.hxx
@@ -365,6 +365,7 @@ public:
     virtual OUString    GetDescription() const;
     /// Is this field clickable?
     bool IsClickable() const;
+    virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const;
 };
 
 inline SwFieldType* SwField::GetTyp() const
diff --git a/sw/inc/fmtfld.hxx b/sw/inc/fmtfld.hxx
index 0d4f86b..a5b7137 100644
--- a/sw/inc/fmtfld.hxx
+++ b/sw/inc/fmtfld.hxx
@@ -115,6 +115,7 @@ public:
     SAL_DLLPRIVATE void SetXTextField(::com::sun::star::uno::Reference<
                     ::com::sun::star::text::XTextField> const& xTextField)
             { m_wXTextField = xTextField; }
+    void dumpAsXml(struct _xmlTextWriter* pWriter) const override;
 };
 
 enum class SwFormatFieldHintWhich
diff --git a/sw/source/core/fields/docufld.cxx b/sw/source/core/fields/docufld.cxx
index 6c7b4d5..c0292e0 100644
--- a/sw/source/core/fields/docufld.cxx
+++ b/sw/source/core/fields/docufld.cxx
@@ -1833,6 +1833,21 @@ bool SwPostItField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     return true;
 }
 
+void SwPostItField::dumpAsXml(xmlTextWriterPtr pWriter) const
+{
+    xmlTextWriterStartElement(pWriter, BAD_CAST("swPostItField"));
+    xmlTextWriterWriteAttribute(pWriter, BAD_CAST("name"), BAD_CAST(GetName().toUtf8().getStr()));
+
+    SwField::dumpAsXml(pWriter);
+
+    xmlTextWriterStartElement(pWriter, BAD_CAST("mpText"));
+    OutlinerParaObject aParaObject(*mpText);
+    aParaObject.dumpAsXml(pWriter);
+    xmlTextWriterEndElement(pWriter);
+
+    xmlTextWriterEndElement(pWriter);
+}
+
 // extended user information field type
 
 SwExtUserFieldType::SwExtUserFieldType()
diff --git a/sw/source/core/fields/fldbas.cxx b/sw/source/core/fields/fldbas.cxx
index 40b96c2..5a7d561 100644
--- a/sw/source/core/fields/fldbas.cxx
+++ b/sw/source/core/fields/fldbas.cxx
@@ -162,24 +162,8 @@ void SwFieldTypes::dumpAsXml(xmlTextWriterPtr pWriter) const
     {
         const SwFieldType *pCurType = (*this)[nType];
         SwIterator<SwFormatField, SwFieldType> aIter(*pCurType);
-        for (const SwFormatField* pCurFieldFormat = aIter.First(); pCurFieldFormat; pCurFieldFormat = aIter.Next())
-        {
-            xmlTextWriterStartElement(pWriter, BAD_CAST("swFormatField"));
-            xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", pCurFieldFormat);
-            xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("txtField"), "%p", pCurFieldFormat->GetTextField());
-
-            xmlTextWriterStartElement(pWriter, BAD_CAST("swField"));
-            xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("symbol"), "%s", BAD_CAST(typeid(*pCurFieldFormat->GetField()).name()));
-            xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", pCurFieldFormat->GetField());
-            if (pCurFieldFormat->GetField()->GetTyp()->Which() == RES_POSTITFLD)
-            {
-                const SwPostItField* pField = static_cast<const SwPostItField*>(pCurFieldFormat->GetField());
-                xmlTextWriterWriteAttribute(pWriter, BAD_CAST("name"), BAD_CAST(pField->GetName().toUtf8().getStr()));
-            }
-            xmlTextWriterEndElement(pWriter);
-
-            xmlTextWriterEndElement(pWriter);
-        }
+        for (const SwFormatField* pFormatField = aIter.First(); pFormatField; pFormatField = aIter.Next())
+            pFormatField->dumpAsXml(pWriter);
     }
     xmlTextWriterEndElement(pWriter);
 }
@@ -774,4 +758,13 @@ bool SwField::IsClickable() const
     return false;
 }
 
+void SwField::dumpAsXml(xmlTextWriterPtr pWriter) const
+{
+    xmlTextWriterStartElement(pWriter, BAD_CAST("swField"));
+    xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("symbol"), "%s", BAD_CAST(typeid(*this).name()));
+    xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
+
+    xmlTextWriterEndElement(pWriter);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/txtnode/atrfld.cxx b/sw/source/core/txtnode/atrfld.cxx
index 0a25e59..3f98917 100644
--- a/sw/source/core/txtnode/atrfld.cxx
+++ b/sw/source/core/txtnode/atrfld.cxx
@@ -17,8 +17,11 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include "fldbas.hxx"
 #include <fmtfld.hxx>
+
+#include <libxml/xmlwriter.h>
+
+#include "fldbas.hxx"
 #include <txtfld.hxx>
 #include <txtannotationfld.hxx>
 #include <docfld.hxx>
@@ -330,6 +333,18 @@ bool SwFormatField::IsProtect() const
            && mpTextField->GetpTextNode()->IsProtect();
 }
 
+void SwFormatField::dumpAsXml(xmlTextWriterPtr pWriter) const
+{
+    xmlTextWriterStartElement(pWriter, BAD_CAST("swFormatField"));
+    xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
+    xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("mpTextField"), "%p", mpTextField);
+
+    SfxPoolItem::dumpAsXml(pWriter);
+    GetField()->dumpAsXml(pWriter);
+
+    xmlTextWriterEndElement(pWriter);
+}
+
 // class SwTextField ////////////////////////////////////////////////////
 
 SwTextField::SwTextField(
commit a3afe96c4973c1a620754c2a400adcbf19c8eefe
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Nov 6 17:12:46 2015 +0100

    sc lok annotations: paint range and anchor overlay
    
    Change-Id: I16e51e074704026a45471e7a08c3b96846d44053
    (cherry picked from commit 5f68759810496ff3fadf5a883203449772c7392f)

diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index c1d1b57..75b3f39 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -262,6 +262,21 @@ void SwSidebarWin::PaintTile(vcl::RenderContext& rRenderContext, const Rectangle
 
         rRenderContext.Pop();
     }
+
+    const drawinglayer::geometry::ViewInformation2D aViewInformation;
+    std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(rRenderContext, aViewInformation));
+
+    // drawinglayer sets the map mode to pixels, not needed here.
+    rRenderContext.Pop();
+    // Work in document-global twips.
+    rRenderContext.Pop();
+    if (mpAnchor)
+        pProcessor->process(mpAnchor->getOverlayObjectPrimitive2DSequence());
+    if (mpTextRangeOverlay)
+        pProcessor->process(mpTextRangeOverlay->getOverlayObjectPrimitive2DSequence());
+    rRenderContext.Push(PushFlags::NONE);
+    pProcessor.reset();
+    rRenderContext.Push(PushFlags::NONE);
 }
 
 void SwSidebarWin::Draw(OutputDevice* pDev, const Point& rPt, const Size& rSz, sal_uLong nInFlags)
commit 3880944cc3e3646eda063635e577758203bbd56f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Nov 6 13:30:54 2015 +0100

    sw lok annotations: disable the scrollbar for now
    
    Change-Id: I7493eaab55c23c79ca0878c34a97dfb4af857260
    (cherry picked from commit 8fc6aafcb4769271bc7b208e9b9b430b875b6104)

diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index 743a8e5..c1d1b57 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -246,6 +246,12 @@ void SwSidebarWin::PaintTile(vcl::RenderContext& rRenderContext, const Rectangle
     for (sal_uInt16 i = 0; i < GetChildCount(); ++i)
     {
         vcl::Window* pChild = GetChild(i);
+
+        // This would at the moment just draw a gray rectangle at the top right
+        // corner, need to sort out later.
+        if (pChild == mpVScrollbar.get())
+            continue;
+
         rRenderContext.Push(PushFlags::MAPMODE);
         Point aOffset(PixelToLogic(pChild->GetPosPixel()));
         MapMode aMapMode(rRenderContext.GetMapMode());
commit 93a5544c5735838187b02b489862cde09f3820af
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Nov 6 10:29:38 2015 +0100

    sw lok annotations: paint all child window
    
    And use map modes to get the painting to the correct position instead of
    manually adjusting each and every Paint() method.
    
    (cherry picked from commit 177e375d2e63f1c3db9f5ab41e4281af740625fb)
    
    Conflicts:
    	sw/source/uibase/docvw/SidebarTxtControl.cxx
    	sw/source/uibase/docvw/SidebarTxtControl.hxx
    
    Change-Id: I66798321b8bbf2c7968d6ac1edebb1f8df60bce8

diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx
index b6bc52c..35152d0 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -855,10 +855,17 @@ void SwPostItMgr::PaintTile(OutputDevice& rRenderContext, const Rectangle& /*rRe
         if (!pPostIt)
             continue;
 
-        Point aPoint(mpEditWin->PixelToLogic(pPostIt->GetPosPixel()));
+        rRenderContext.Push(PushFlags::MAPMODE);
+        Point aOffset(mpEditWin->PixelToLogic(pPostIt->GetPosPixel()));
+        MapMode aMapMode(rRenderContext.GetMapMode());
+        aMapMode.SetOrigin(aMapMode.GetOrigin() + aOffset);
+        rRenderContext.SetMapMode(aMapMode);
         Size aSize(pPostIt->PixelToLogic(pPostIt->GetSizePixel()));
-        Rectangle aRectangle(aPoint, aSize);
+        Rectangle aRectangle(Point(0, 0), aSize);
+
         pPostIt->PaintTile(rRenderContext, aRectangle);
+
+        rRenderContext.Pop();
     }
 }
 
diff --git a/sw/source/uibase/docvw/SidebarTxtControl.cxx b/sw/source/uibase/docvw/SidebarTxtControl.cxx
index 6ac99be..e9e1e34 100644
--- a/sw/source/uibase/docvw/SidebarTxtControl.cxx
+++ b/sw/source/uibase/docvw/SidebarTxtControl.cxx
@@ -53,7 +53,6 @@
 #include <shellres.hxx>
 #include <SwRewriter.hxx>
 #include <boost/scoped_ptr.hpp>
-#include <comphelper/lok.hxx>
 
 namespace sw { namespace sidebarwindows {
 
@@ -152,37 +151,25 @@ void SidebarTextControl::Draw(OutputDevice* pDev, const Point& rPt, const Size&
     }
 }
 
-void SidebarTextControl::PaintTile(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
-{
-    Paint(rRenderContext, rRect);
-}
-
 void SidebarTextControl::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
 {
-    Point aPoint(0, 0);
-    if (comphelper::LibreOfficeKit::isActive())
-        aPoint = rRect.TopLeft();
-
     if (!rRenderContext.GetSettings().GetStyleSettings().GetHighContrastMode())
     {
         if (mrSidebarWin.IsMouseOverSidebarWin() || HasFocus())
         {
-            rRenderContext.DrawGradient(Rectangle(aPoint, rRenderContext.PixelToLogic(GetSizePixel())),
+            rRenderContext.DrawGradient(Rectangle(Point(0,0), rRenderContext.PixelToLogic(GetSizePixel())),
                                         Gradient(GradientStyle_LINEAR, mrSidebarWin.ColorDark(), mrSidebarWin.ColorDark()));
         }
         else
         {
-            rRenderContext.DrawGradient(Rectangle(aPoint, rRenderContext.PixelToLogic(GetSizePixel())),
+            rRenderContext.DrawGradient(Rectangle(Point(0,0), rRenderContext.PixelToLogic(GetSizePixel())),
                            Gradient(GradientStyle_LINEAR, mrSidebarWin.ColorLight(), mrSidebarWin.ColorDark()));
         }
     }
 
     if (GetTextView())
     {
-        if (comphelper::LibreOfficeKit::isActive())
-            GetTextView()->GetOutliner()->Draw(&rRenderContext, rRect);
-        else
-            GetTextView()->Paint(rRect, &rRenderContext);
+        GetTextView()->Paint(rRect, &rRenderContext);
     }
 
     if (mrSidebarWin.GetLayoutStatus() == SwPostItHelper::DELETED)
diff --git a/sw/source/uibase/docvw/SidebarTxtControl.hxx b/sw/source/uibase/docvw/SidebarTxtControl.hxx
index b3a286a..1a6d667 100644
--- a/sw/source/uibase/docvw/SidebarTxtControl.hxx
+++ b/sw/source/uibase/docvw/SidebarTxtControl.hxx
@@ -69,7 +69,6 @@ class SidebarTextControl : public Control
         virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible() SAL_OVERRIDE;
 
         virtual void Draw(OutputDevice* pDev, const Point&, const Size&, sal_uLong) SAL_OVERRIDE;
-        void PaintTile(vcl::RenderContext& rRenderContext, const Rectangle& rRect);
 };
 
 } } // end of namespace sw::sidebarwindows
diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index f76691e4..743a8e5 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -246,10 +246,15 @@ void SwSidebarWin::PaintTile(vcl::RenderContext& rRenderContext, const Rectangle
     for (sal_uInt16 i = 0; i < GetChildCount(); ++i)
     {
         vcl::Window* pChild = GetChild(i);
-        if (pChild == mpSidebarTextControl.get())
-            mpSidebarTextControl->PaintTile(rRenderContext, rRect);
-        else
-            SAL_WARN("sw.uibase", "SwSidebarWin::PaintTile: unhandled child " << pChild);
+        rRenderContext.Push(PushFlags::MAPMODE);
+        Point aOffset(PixelToLogic(pChild->GetPosPixel()));
+        MapMode aMapMode(rRenderContext.GetMapMode());
+        aMapMode.SetOrigin(aMapMode.GetOrigin() + aOffset);
+        rRenderContext.SetMapMode(aMapMode);
+
+        pChild->Paint(rRenderContext, rRect);
+
+        rRenderContext.Pop();
     }
 }
 
commit 266f8b8abc5ac1687f9d0841673ce8620dbe017b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Nov 5 15:58:55 2015 +0100

    sw tiled rendering: initial annotation support
    
    (cherry picked from commit d54aaea33bf2dab86c0ead4bd142c593d017f930)
    
    Conflicts:
    	sw/inc/PostItMgr.hxx
    	sw/inc/SidebarWin.hxx
    	sw/source/uibase/docvw/SidebarTxtControl.cxx
    	sw/source/uibase/docvw/SidebarTxtControl.hxx
    	sw/source/uibase/docvw/SidebarWin.cxx
    
    Change-Id: I4fcb05f8a58965341cf44a1b7e2367b5cbff981d

diff --git a/sw/inc/PostItMgr.hxx b/sw/inc/PostItMgr.hxx
index 8d1ddd0..2f9e328 100644
--- a/sw/inc/PostItMgr.hxx
+++ b/sw/inc/PostItMgr.hxx
@@ -288,6 +288,7 @@ class SwPostItMgr: public SfxListener
                                          std::vector< vcl::Window* >* pChildren );
 
             void DrawNotesForPage(OutputDevice *pOutDev, sal_uInt32 nPage);
+            void PaintTile(OutputDevice& rRenderContext, const Rectangle& rRect);
 };
 
 #endif
diff --git a/sw/inc/SidebarWin.hxx b/sw/inc/SidebarWin.hxx
index 9514ac0..59d3ea6 100644
--- a/sw/inc/SidebarWin.hxx
+++ b/sw/inc/SidebarWin.hxx
@@ -178,6 +178,7 @@ class SwSidebarWin : public vcl::Window
         virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible() SAL_OVERRIDE;
 
         virtual void    Draw(OutputDevice* pDev, const Point&, const Size&, sal_uLong) SAL_OVERRIDE;
+        void PaintTile(vcl::RenderContext& rRenderContext, const Rectangle& rRect);
 
     protected:
         virtual void    DataChanged( const DataChangedEvent& aEvent) SAL_OVERRIDE;
diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx
index 8c16e2d..a27630f 100644
--- a/sw/source/core/view/viewsh.cxx
+++ b/sw/source/core/view/viewsh.cxx
@@ -1901,6 +1901,9 @@ void SwViewShell::PaintTile(VirtualDevice &rDevice, int contextWidth, int contex
     // draw - works in logic coordinates
     Paint(rDevice, aOutRect);
 
+    if (SwPostItMgr* pPostItMgr = GetPostItMgr())
+        pPostItMgr->PaintTile(rDevice, aOutRect);
+
     // SwViewShell's output device tear down
     mpOut = pSaveOut;
     mbInLibreOfficeKitCallback = false;
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx
index 98a9896..b6bc52c 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -847,6 +847,21 @@ void SwPostItMgr::DrawNotesForPage(OutputDevice *pOutDev, sal_uInt32 nPage)
     }
 }
 
+void SwPostItMgr::PaintTile(OutputDevice& rRenderContext, const Rectangle& /*rRect*/)
+{
+    for (SwSidebarItem* pItem : mvPostItFields)
+    {
+        SwSidebarWin* pPostIt = pItem->pPostIt;
+        if (!pPostIt)
+            continue;
+
+        Point aPoint(mpEditWin->PixelToLogic(pPostIt->GetPosPixel()));
+        Size aSize(pPostIt->PixelToLogic(pPostIt->GetSizePixel()));
+        Rectangle aRectangle(aPoint, aSize);
+        pPostIt->PaintTile(rRenderContext, aRectangle);
+    }
+}
+
 void SwPostItMgr::Scroll(const long lScroll,const unsigned long aPage)
 {
     OSL_ENSURE((lScroll % GetScrollSize() )==0,"SwPostItMgr::Scroll: scrolling by wrong value");
diff --git a/sw/source/uibase/docvw/SidebarTxtControl.cxx b/sw/source/uibase/docvw/SidebarTxtControl.cxx
index e9e1e34..6ac99be 100644
--- a/sw/source/uibase/docvw/SidebarTxtControl.cxx
+++ b/sw/source/uibase/docvw/SidebarTxtControl.cxx
@@ -53,6 +53,7 @@
 #include <shellres.hxx>
 #include <SwRewriter.hxx>
 #include <boost/scoped_ptr.hpp>
+#include <comphelper/lok.hxx>
 
 namespace sw { namespace sidebarwindows {
 
@@ -151,25 +152,37 @@ void SidebarTextControl::Draw(OutputDevice* pDev, const Point& rPt, const Size&
     }
 }
 
+void SidebarTextControl::PaintTile(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
+{
+    Paint(rRenderContext, rRect);
+}
+
 void SidebarTextControl::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
 {
+    Point aPoint(0, 0);
+    if (comphelper::LibreOfficeKit::isActive())
+        aPoint = rRect.TopLeft();
+
     if (!rRenderContext.GetSettings().GetStyleSettings().GetHighContrastMode())
     {
         if (mrSidebarWin.IsMouseOverSidebarWin() || HasFocus())
         {
-            rRenderContext.DrawGradient(Rectangle(Point(0,0), rRenderContext.PixelToLogic(GetSizePixel())),
+            rRenderContext.DrawGradient(Rectangle(aPoint, rRenderContext.PixelToLogic(GetSizePixel())),
                                         Gradient(GradientStyle_LINEAR, mrSidebarWin.ColorDark(), mrSidebarWin.ColorDark()));
         }
         else
         {
-            rRenderContext.DrawGradient(Rectangle(Point(0,0), rRenderContext.PixelToLogic(GetSizePixel())),
+            rRenderContext.DrawGradient(Rectangle(aPoint, rRenderContext.PixelToLogic(GetSizePixel())),
                            Gradient(GradientStyle_LINEAR, mrSidebarWin.ColorLight(), mrSidebarWin.ColorDark()));
         }
     }
 
     if (GetTextView())
     {
-        GetTextView()->Paint(rRect, &rRenderContext);
+        if (comphelper::LibreOfficeKit::isActive())
+            GetTextView()->GetOutliner()->Draw(&rRenderContext, rRect);
+        else
+            GetTextView()->Paint(rRect, &rRenderContext);
     }
 
     if (mrSidebarWin.GetLayoutStatus() == SwPostItHelper::DELETED)
diff --git a/sw/source/uibase/docvw/SidebarTxtControl.hxx b/sw/source/uibase/docvw/SidebarTxtControl.hxx
index 1a6d667..b3a286a 100644
--- a/sw/source/uibase/docvw/SidebarTxtControl.hxx
+++ b/sw/source/uibase/docvw/SidebarTxtControl.hxx
@@ -69,6 +69,7 @@ class SidebarTextControl : public Control
         virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible() SAL_OVERRIDE;
 
         virtual void Draw(OutputDevice* pDev, const Point&, const Size&, sal_uLong) SAL_OVERRIDE;
+        void PaintTile(vcl::RenderContext& rRenderContext, const Rectangle& rRect);
 };
 
 } } // end of namespace sw::sidebarwindows
diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index 9825839..f76691e4 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -80,6 +80,7 @@
 #include <drawinglayer/processor2d/processorfromoutputdevice.hxx>
 #include <drawinglayer/primitive2d/shadowprimitive2d.hxx>
 #include <boost/scoped_ptr.hpp>
+#include <comphelper/lok.hxx>
 
 namespace sw { namespace sidebarwindows {
 
@@ -230,7 +231,25 @@ void SwSidebarWin::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rR
                              Size(GetMetaButtonAreaWidth(),
                                   mpMetadataAuthor->GetSizePixel().Height() + mpMetadataDate->GetSizePixel().Height()));
 
-        rRenderContext.DrawRect(PixelToLogic(aRectangle));
+        if (comphelper::LibreOfficeKit::isActive())
+            aRectangle = rRect;
+        else
+            aRectangle = PixelToLogic(aRectangle);
+        rRenderContext.DrawRect(aRectangle);
+    }
+}
+
+void SwSidebarWin::PaintTile(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
+{
+    Paint(rRenderContext, rRect);
+
+    for (sal_uInt16 i = 0; i < GetChildCount(); ++i)
+    {
+        vcl::Window* pChild = GetChild(i);
+        if (pChild == mpSidebarTextControl.get())
+            mpSidebarTextControl->PaintTile(rRenderContext, rRect);
+        else
+            SAL_WARN("sw.uibase", "SwSidebarWin::PaintTile: unhandled child " << pChild);
     }
 }
 


More information about the Libreoffice-commits mailing list