[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - desktop/source include/LibreOfficeKit include/sfx2 include/svx libreofficekit/source svx/sdi sw/inc sw/sdi sw/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Thu Aug 15 07:46:09 UTC 2019


 desktop/source/lib/init.cxx                  |   16 ++++-
 include/LibreOfficeKit/LibreOfficeKitEnums.h |    9 +++
 include/sfx2/sfxsids.hrc                     |    3 +
 include/svx/svxids.hrc                       |    1 
 libreofficekit/source/gtk/lokdocview.cxx     |    2 
 svx/sdi/svx.sdi                              |   19 ++++++
 sw/inc/crsrsh.hxx                            |    1 
 sw/sdi/_viewsh.sdi                           |    4 +
 sw/source/core/crsr/crsrsh.cxx               |   81 +++++++++++++++++++++++++++
 sw/source/uibase/uiview/viewtab.cxx          |   81 ++++++++++++++++++++++++++-
 10 files changed, 214 insertions(+), 3 deletions(-)

New commits:
commit 3c9e5743bcad46d6a63906bdac7cc335d37039ee
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Aug 14 18:08:18 2019 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Thu Aug 15 09:45:03 2019 +0200

    tdf#122529 lok - table border position manipulation
    
    This adds a new LOK callback (LOK_CALLBACK_TABLE_SELECTED) that
    sends the border positions to the client when the user has the
    cursor or slelection in a table.
    
    In addition this adds a .uno:TableChangeCurrentBorderPosition
    uno command, which implements changing a specific border in
    the current table. Border can be either a column or a row border,
    which is either at the first, middle or last position.
    
    Reviewed-on: https://gerrit.libreoffice.org/77365
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    (cherry picked from commit 43cce4ef2cf865b2bb637e17b70102a4260295b0)
    
    Change-Id: Ife7cff14d91ffc84c95c040f0b42319e3d6194b4
    Reviewed-on: https://gerrit.libreoffice.org/77484
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index f3f3fd0f6f49..884e0d6fd9dd 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -363,9 +363,21 @@ std::vector<beans::PropertyValue> desktop::jsonToPropertyValuesVector(const char
             else if (rType == "long")
                 aValue.Value <<= OString(rValue.c_str()).toInt32();
             else if (rType == "short")
-                aValue.Value <<= static_cast<sal_Int16>(OString(rValue.c_str()).toInt32());
+                aValue.Value <<= sal_Int16(OString(rValue.c_str()).toInt32());
             else if (rType == "unsigned short")
-                aValue.Value <<= static_cast<sal_uInt16>(OString(rValue.c_str()).toUInt32());
+                aValue.Value <<= sal_uInt16(OString(rValue.c_str()).toUInt32());
+            else if (rType == "int64")
+                aValue.Value <<= OString(rValue.c_str()).toInt64();
+            else if (rType == "int32")
+                aValue.Value <<= OString(rValue.c_str()).toInt32();
+            else if (rType == "int16")
+                aValue.Value <<= sal_Int16(OString(rValue.c_str()).toInt32());
+            else if (rType == "uint64")
+                aValue.Value <<= OString(rValue.c_str()).toUInt64();
+            else if (rType == "uint32")
+                aValue.Value <<= OString(rValue.c_str()).toUInt32();
+            else if (rType == "uint16")
+                aValue.Value <<= sal_uInt16(OString(rValue.c_str()).toUInt32());
             else if (rType == "[]byte")
             {
                 aNodeValue = rPair.second.get_child("value", aNodeNull);
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index ddcb9003853d..2746e1c56a57 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -665,6 +665,15 @@ typedef enum
      * Rectangle format is the same as LOK_CALLBACK_INVALIDATE_TILES.
      */
     LOK_CALLBACK_CELL_AUTO_FILL_AREA = 43,
+
+    /**
+     * When the cursor is in a table or a table is selected in the
+     * document, this sends the table's column and row border positions
+     * to the client. If the payload is empty (empty JSON object), then
+     * no table is currently selected or the cursor is not inside a table
+     * cell.
+     */
+    LOK_CALLBACK_TABLE_SELECTED = 44,
 }
 LibreOfficeKitCallbackType;
 
diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc
index c725951cf118..2e14517ad272 100644
--- a/include/sfx2/sfxsids.hrc
+++ b/include/sfx2/sfxsids.hrc
@@ -550,6 +550,9 @@
 #define SID_OPEN_SMARTTAGOPTIONS            (SID_SVX_START + 1062)
 #define SID_RULER_MARGIN1                   (SID_SVX_START + 1063)
 #define SID_RULER_MARGIN2                   (SID_SVX_START + 1064)
+#define SID_TABLE_BORDER_TYPE               (SID_SVX_START + 1065)
+#define SID_TABLE_BORDER_INDEX              (SID_SVX_START + 1066)
+#define SID_TABLE_BORDER_NEW_POSITION       (SID_SVX_START + 1067)
 
 #define FID_SVX_START                       (SID_LIB_START + 500)
 #define FID_SEARCH_NOW                      (FID_SVX_START + 2)
diff --git a/include/svx/svxids.hrc b/include/svx/svxids.hrc
index b3ed3911ac36..d422205b5d9c 100644
--- a/include/svx/svxids.hrc
+++ b/include/svx/svxids.hrc
@@ -253,6 +253,7 @@
 #define SID_ATTR_TRANSFORM_ROT_Y                        ( SID_SVX_START + 94 )
 #define SID_ATTR_TRANSFORM_ANGLE                        ( SID_SVX_START + 95 )
 #define SID_ATTR_TRANSFORM_DELTA_ANGLE                  ( SID_SVX_START + 96 )
+#define SID_TABLE_CHANGE_CURRENT_BORDER_POSITION        ( SID_SVX_START + 100 )
 #define SID_SIZE_ALL                                    ( SID_SVX_START + 101 )
 #define SID_DRAW_LINE                                   ( SID_SVX_START + 102 )
 #define SID_DRAW_XLINE                                  ( SID_SVX_START + 103 )
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 040a9f3bc7b4..817e728dc9a8 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -456,6 +456,8 @@ callbackTypeToString (int nType)
         return "LOK_CALLBACK_CELL_SELECTION_AREA";
     case LOK_CALLBACK_CELL_AUTO_FILL_AREA:
         return "LOK_CALLBACK_CELL_AUTO_FILL_AREA";
+    case LOK_CALLBACK_TABLE_SELECTED:
+        return "LOK_CALLBACK_TABLE_SELECTED";
     }
     g_assert(false);
     return nullptr;
diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi
index e979a8a7057e..c6a4d5bce4b1 100644
--- a/svx/sdi/svx.sdi
+++ b/svx/sdi/svx.sdi
@@ -7177,6 +7177,25 @@ SfxVoidItem RulerChangeState SID_RULER_CHANGE_STATE
     GroupId = ;
 ]
 
+SfxVoidItem TableChangeCurrentBorderPosition SID_TABLE_CHANGE_CURRENT_BORDER_POSITION
+    (SfxStringItem BorderType SID_TABLE_BORDER_TYPE,
+     SfxUInt16Item Index SID_TABLE_BORDER_INDEX,
+     SfxInt32Item NewPosition SID_TABLE_BORDER_NEW_POSITION)
+[
+    AutoUpdate = FALSE,
+    FastCall = TRUE,
+    ReadOnlyDoc = TRUE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+
+
+    AccelConfig = FALSE,
+    MenuConfig = FALSE,
+    ToolBoxConfig = FALSE,
+    GroupId = ;
+]
 
 SfxVoidItem SbaExecuteSql SID_FM_EXECUTE
 ()
diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx
index 13d70e6368c6..6ecee7c54e57 100644
--- a/sw/inc/crsrsh.hxx
+++ b/sw/inc/crsrsh.hxx
@@ -268,6 +268,7 @@ typedef bool (SwCursor:: *FNCursor)();
 
     SAL_DLLPRIVATE const SwRangeRedline* GotoRedline_( SwRedlineTable::size_type nArrPos, bool bSelect );
 
+    SAL_DLLPRIVATE void sendLOKCursorUpdates();
 protected:
 
     inline SwMoveFnCollection const & MakeFindRange( SwDocPositions, SwDocPositions, SwPaM* ) const;
diff --git a/sw/sdi/_viewsh.sdi b/sw/sdi/_viewsh.sdi
index 099033a1a278..59fb4f2fd75d 100644
--- a/sw/sdi/_viewsh.sdi
+++ b/sw/sdi/_viewsh.sdi
@@ -289,6 +289,10 @@ interface BaseTextEditView
         StateMethod = StateTabWin ;
         DisableFlags="SfxDisableFlags::SwOnProtectedCursor";
     ]
+    SID_TABLE_CHANGE_CURRENT_BORDER_POSITION
+    [
+        ExecMethod = ExecTabWin;
+    ]
     FN_EDIT_LINK_DLG // status(final|play)
     [
         ExecMethod = Execute ;
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 2e607d313931..2272c2302248 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -69,6 +69,10 @@
 #include <editeng/editview.hxx>
 #include <PostItMgr.hxx>
 #include <DocumentSettingManager.hxx>
+#include <cntfrm.hxx>
+#include <tabcol.hxx>
+#include <wrtsh.hxx>
+#include <boost/property_tree/json_parser.hpp>
 
 using namespace com::sun::star;
 using namespace util;
@@ -1877,9 +1881,86 @@ void SwCursorShell::UpdateCursor( sal_uInt16 eFlags, bool bIdleEnd )
     if( m_bSVCursorVis )
         m_pVisibleCursor->Show(); // show again
 
+    if (comphelper::LibreOfficeKit::isActive())
+        sendLOKCursorUpdates();
+
     getIDocumentMarkAccess()->NotifyCursorUpdate(*this);
 }
 
+void SwCursorShell::sendLOKCursorUpdates()
+{
+    SwWrtShell* pShell = GetDoc()->GetDocShell()->GetWrtShell();
+    if (!pShell)
+        return;
+
+    SwFrame* pCurrentFrame = GetCurrFrame();
+    SelectionType eType = pShell->GetSelectionType();
+
+    boost::property_tree::ptree aRootTree;
+
+    if (pCurrentFrame && (eType & SelectionType::Table) && pCurrentFrame->IsInTab())
+    {
+        const SwRect& rPageRect = pShell->GetAnyCurRect(CurRectType::Page, nullptr);
+
+        boost::property_tree::ptree aTableColumns;
+        {
+            SwTabCols aTabCols;
+            pShell->GetTabCols(aTabCols);
+
+            const int nColumnOffset = aTabCols.GetLeftMin() + rPageRect.Left();
+
+            aTableColumns.put("left", aTabCols.GetLeft());
+            aTableColumns.put("right", aTabCols.GetRight());
+            aTableColumns.put("tableOffset", nColumnOffset);
+
+            boost::property_tree::ptree aEntries;
+            for (size_t i = 0; i < aTabCols.Count(); ++i)
+            {
+                auto const & rEntry = aTabCols.GetEntry(i);
+                boost::property_tree::ptree aTableColumnEntry;
+                aTableColumnEntry.put("position", rEntry.nPos);
+                aTableColumnEntry.put("min", rEntry.nMin);
+                aTableColumnEntry.put("max", rEntry.nMax);
+                aTableColumnEntry.put("hidden", rEntry.bHidden);
+                aEntries.push_back(std::make_pair("", aTableColumnEntry));
+            }
+            aTableColumns.push_back(std::make_pair("entries", aEntries));
+        }
+
+        boost::property_tree::ptree aTableRows;
+        {
+            SwTabCols aTabRows;
+            pShell->GetTabRows(aTabRows);
+
+            const int nRowOffset = aTabRows.GetLeftMin() + rPageRect.Top();
+
+            aTableRows.put("left", aTabRows.GetLeft());
+            aTableRows.put("right", aTabRows.GetRight());
+            aTableRows.put("tableOffset", nRowOffset);
+
+            boost::property_tree::ptree aEntries;
+            for (size_t i = 0; i < aTabRows.Count(); ++i)
+            {
+                auto const & rEntry = aTabRows.GetEntry(i);
+                boost::property_tree::ptree aTableRowEntry;
+                aTableRowEntry.put("position", rEntry.nPos);
+                aTableRowEntry.put("min", rEntry.nMin);
+                aTableRowEntry.put("max", rEntry.nMax);
+                aTableRowEntry.put("hidden", rEntry.bHidden);
+                aEntries.push_back(std::make_pair("", aTableRowEntry));
+            }
+            aTableRows.push_back(std::make_pair("entries", aEntries));
+        }
+
+        aRootTree.add_child("columns", aTableColumns);
+        aRootTree.add_child("rows", aTableRows);
+    }
+
+    std::stringstream aStream;
+    boost::property_tree::write_json(aStream, aRootTree);
+    GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TABLE_SELECTED, aStream.str().c_str());
+}
+
 void SwCursorShell::RefreshBlockCursor()
 {
     assert(m_pBlockCursor);
diff --git a/sw/source/uibase/uiview/viewtab.cxx b/sw/source/uibase/uiview/viewtab.cxx
index 67667185360a..d822343b885d 100644
--- a/sw/source/uibase/uiview/viewtab.cxx
+++ b/sw/source/uibase/uiview/viewtab.cxx
@@ -53,9 +53,10 @@
 #include <fmtcol.hxx>
 #include <section.hxx>
 #include <swruler.hxx>
-
+#include <cntfrm.hxx>
 #include <ndtxt.hxx>
 #include <pam.hxx>
+#include <tools/helpers.hxx>
 
 #include <IDocumentSettingAccess.hxx>
 
@@ -1010,7 +1011,85 @@ void SwView::ExecTabWin( SfxRequest const & rReq )
             }
         }
         break;
+    case SID_TABLE_CHANGE_CURRENT_BORDER_POSITION:
+    {
+        if (pReqArgs)
+        {
+            const SfxPoolItem *pBorderType;
+            const SfxPoolItem *pIndex;
+            const SfxPoolItem *pNewPosition;
+            constexpr long constDistanceOffset = 40;
+
+            if (pReqArgs->GetItemState(SID_TABLE_BORDER_TYPE, true, &pBorderType) == SfxItemState::SET
+            && pReqArgs->GetItemState(SID_TABLE_BORDER_INDEX, true, &pIndex) == SfxItemState::SET
+            && pReqArgs->GetItemState(SID_TABLE_BORDER_NEW_POSITION, true, &pNewPosition) == SfxItemState::SET)
+            {
+                const OUString sType = static_cast<const SfxStringItem*>(pBorderType)->GetValue();
+                const sal_uInt16 nIndex = static_cast<const SfxUInt16Item*>(pIndex)->GetValue();
+                const sal_Int32 nNewPosition = static_cast<const SfxInt32Item*>(pNewPosition)->GetValue();
+
+                if (sType.startsWith("column"))
+                {
+                    SwTabCols aTabCols;
+                    rSh.GetTabCols(aTabCols);
+
+                    if (sType == "column-left")
+                    {
+                        auto & rEntry = aTabCols.GetEntry(0);
+                        long nPosition = std::min(long(nNewPosition), rEntry.nPos - constDistanceOffset);
+                        aTabCols.SetLeft(nPosition);
+                    }
+                    else if (sType == "column-right")
+                    {
+                        auto & rEntry = aTabCols.GetEntry(aTabCols.Count() - 1);
+                        long nPosition = std::max(long(nNewPosition), rEntry.nPos + constDistanceOffset);
+                        aTabCols.SetRight(nPosition);
+                    }
+                    else if (sType == "column-middle")
+                    {
+                        if (nIndex < aTabCols.Count())
+                        {
+                            auto & rEntry = aTabCols.GetEntry(nIndex);
+                            long nPosition = MinMax(long(nNewPosition), rEntry.nMin, rEntry.nMax - constDistanceOffset);
+                            rEntry.nPos = nPosition;
+                        }
+                    }
 
+                    rSh.SetTabCols(aTabCols, false);
+                }
+                else if (sType.startsWith("row"))
+                {
+                    SwTabCols aTabRows;
+                    rSh.GetTabRows(aTabRows);
+
+                    if (sType == "row-left")
+                    {
+                        auto & rEntry = aTabRows.GetEntry(0);
+                        long nPosition = std::min(long(nNewPosition), rEntry.nPos - constDistanceOffset);
+                        aTabRows.SetLeft(nPosition);
+                    }
+                    else if (sType == "row-right")
+                    {
+                        auto & rEntry = aTabRows.GetEntry(aTabRows.Count() - 1);
+                        long nPosition = std::max(long(nNewPosition), rEntry.nPos + constDistanceOffset);
+                        aTabRows.SetRight(nPosition);
+                    }
+                    else if (sType == "row-middle")
+                    {
+                        if (nIndex < aTabRows.Count())
+                        {
+                            auto & rEntry = aTabRows.GetEntry(nIndex);
+                            long nPosition = MinMax(long(nNewPosition), rEntry.nMin, rEntry.nMax - constDistanceOffset);
+                            rEntry.nPos = nPosition;
+                        }
+                    }
+
+                    rSh.SetTabRows(aTabRows, false);
+                }
+            }
+        }
+    }
+    break;
     case SID_ATTR_PAGE_HEADER:
     {
         if ( pReqArgs )


More information about the Libreoffice-commits mailing list