diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2019-08-14 18:08:18 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2019-08-15 15:21:42 +0200 |
commit | 820b043101a5b2c64a29ad2f60bc69366189c46c (patch) | |
tree | 7549c0c0f6b71bd34ed5f8ce0c708fc4db4b11cd /sw | |
parent | 78a14ad204b0fea20d97388f958325e8173216c5 (diff) |
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@gmail.com>
(cherry picked from commit 43cce4ef2cf865b2bb637e17b70102a4260295b0)
Change-Id: Ife7cff14d91ffc84c95c040f0b42319e3d6194b4
Reviewed-on: https://gerrit.libreoffice.org/77485
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/crsrsh.hxx | 1 | ||||
-rw-r--r-- | sw/sdi/_viewsh.sdi | 4 | ||||
-rw-r--r-- | sw/source/core/crsr/crsrsh.cxx | 81 | ||||
-rw-r--r-- | sw/source/uibase/uiview/viewtab.cxx | 81 |
4 files changed, 166 insertions, 1 deletions
diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx index b258d6d4af14..7add73be4c23 100644 --- a/sw/inc/crsrsh.hxx +++ b/sw/inc/crsrsh.hxx @@ -275,6 +275,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 43425fc9e6ca..19b15226dac7 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 c655f9e85a34..1edaf9a9f590 100644 --- a/sw/source/core/crsr/crsrsh.cxx +++ b/sw/source/core/crsr/crsrsh.cxx @@ -72,6 +72,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; @@ -2008,9 +2012,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 2a42029afd2c..f64017ab5162 100644 --- a/sw/source/uibase/uiview/viewtab.cxx +++ b/sw/source/uibase/uiview/viewtab.cxx @@ -53,12 +53,13 @@ #include <fmtcol.hxx> #include <section.hxx> #include <swruler.hxx> - +#include <cntfrm.hxx> #include <ndtxt.hxx> #include <pam.hxx> #include <IDocumentSettingAccess.hxx> +#include <o3tl/clamp.hxx> #include <svx/xtable.hxx> using namespace ::com::sun::star; @@ -1005,7 +1006,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 = o3tl::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 = o3tl::clamp(long(nNewPosition), rEntry.nMin, rEntry.nMax - constDistanceOffset); + rEntry.nPos = nPosition; + } + } + + rSh.SetTabRows(aTabRows, false); + } + } + } + } + break; case SID_ATTR_PAGE_HEADER: { if ( pReqArgs ) |