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                              |   21 ++++++-
 sw/inc/crsrsh.hxx                            |    1 
 sw/sdi/_viewsh.sdi                           |    4 +
 sw/source/core/crsr/crsrsh.cxx               |   81 +++++++++++++++++++++++++++
 sw/source/uibase/uiview/viewtab.cxx          |   80 ++++++++++++++++++++++++++
 10 files changed, 214 insertions(+), 4 deletions(-)

New commits:
commit 43cce4ef2cf865b2bb637e17b70102a4260295b0
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Wed Aug 14 18:08:18 2019 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Aug 15 04:49:33 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.
    
    Change-Id: Ife7cff14d91ffc84c95c040f0b42319e3d6194b4
    Reviewed-on: https://gerrit.libreoffice.org/77365
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index a2a6ba56f496..2a86c3f6a94f 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -368,9 +368,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 0680c7e6c44f..43762cc54c48 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -674,6 +674,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 20c9e4db5c94..b535f26e7489 100644
--- a/include/sfx2/sfxsids.hrc
+++ b/include/sfx2/sfxsids.hrc
@@ -565,6 +565,9 @@ class SvxSearchItem;
 #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 06bec32a4869..e4851b4f2fb5 100644
--- a/include/svx/svxids.hrc
+++ b/include/svx/svxids.hrc
@@ -241,6 +241,7 @@ class SvxSetItem;
 #define SID_ATTR_TRANSFORM_ROT_Y                        
TypedWhichId<SfxInt32Item>( SID_SVX_START + 94 )
 #define SID_ATTR_TRANSFORM_ANGLE                        
TypedWhichId<SfxInt32Item>( SID_SVX_START + 95 )
 #define SID_ATTR_TRANSFORM_DELTA_ANGLE                  
TypedWhichId<SfxInt32Item>( 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 aedff8870a28..b55ebc9af46f 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -457,6 +457,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 787a0e237839..48810a0f2002 100644
--- a/svx/sdi/svx.sdi
+++ b/svx/sdi/svx.sdi
@@ -7206,6 +7206,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
 ()
@@ -12148,4 +12167,4 @@ SfxVoidItem EditQrCode SID_EDIT_QRCODE
     MenuConfig = TRUE,
     ToolBoxConfig = TRUE,
     GroupId = SfxGroupId::Edit;
-]
\ No newline at end of file
+]
diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx
index 6e1d61d17167..7ccb97c5b954 100644
--- a/sw/inc/crsrsh.hxx
+++ b/sw/inc/crsrsh.hxx
@@ -272,6 +272,7 @@ private:
 
     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 5c4a6234efe9..824eb2f0e6e3 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 33992f06f86f..6abe0046dd81 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -73,6 +73,10 @@
 #include <DocumentSettingManager.hxx>
 #include <vcl/uitest/logger.hxx>
 #include <vcl/uitest/eventdescription.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;
@@ -2025,9 +2029,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 bc7c72c59040..5a13260040d3 100644
--- a/sw/source/uibase/uiview/viewtab.cxx
+++ b/sw/source/uibase/uiview/viewtab.cxx
@@ -58,7 +58,7 @@
 #include <fmtcol.hxx>
 #include <section.hxx>
 #include <swruler.hxx>
-
+#include <cntfrm.hxx>
 #include <ndtxt.hxx>
 #include <pam.hxx>
 
@@ -1009,7 +1009,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 = std::clamp(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 = std::clamp(long(nNewPosition), 
rEntry.nMin, rEntry.nMax - constDistanceOffset);
+                            rEntry.nPos = nPosition;
+                        }
+                    }
+
+                    rSh.SetTabRows(aTabRows, false);
+                }
+            }
+        }
+    }
+    break;
     case SID_ATTR_PAGE_HEADER:
     {
         if ( pReqArgs )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to