lok: add tabstop changing and callback to send tabstop updates

This adds callback LOK_CALLBACK_TAB_STOP_LIST to send the tabstops
for the current paragraph.
In addition it adds .uno:ChangeTabStop action, with which it is
possible to change just one tabstop identified by the index.

Change-Id: I7762ead12e47288cbb0b0a1c8ffb8e9872cee8e8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92147
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
Tomaž Vajngerl 2020-04-14 07:35:02 +02:00 committed by Tomaž Vajngerl
parent fb3a41b328
commit a60b18a8c5
6 changed files with 105 additions and 3 deletions

View File

@ -720,7 +720,12 @@ typedef enum
* Send the list of functions whose name starts with the characters entered
* by the user in the formula input bar.
*/
LOK_CALLBACK_CALC_FUNCTION_LIST = 47
LOK_CALLBACK_CALC_FUNCTION_LIST = 47,
/**
* Sends the tab stop list for the current of the current cursor position.
*/
LOK_CALLBACK_TAB_STOP_LIST = 48,
}
LibreOfficeKitCallbackType;
@ -845,6 +850,8 @@ static inline const char* lokCallbackTypeToString(int nType)
return "LOK_CALLBACK_JSDIALOG";
case LOK_CALLBACK_CALC_FUNCTION_LIST:
return "LOK_CALLBACK_CALC_FUNCTION_LIST";
case LOK_CALLBACK_TAB_STOP_LIST:
return "LOK_CALLBACK_TAB_STOP_LIST";
}
assert(!"Unknown LibreOfficeKitCallbackType type.");

View File

@ -533,6 +533,9 @@ class SvxSetItem;
#define SID_ATTR_ALIGN_DEGREES ( SID_SVX_START + 577 )
#define SID_ATTR_ALIGN_LOCKPOS ( SID_SVX_START + 578 )
#define SID_ATTR_NUMBERFORMAT_ONE_AREA ( SID_SVX_START + 580 )
#define SID_TABSTOP_ADD_OR_CHANGE ( SID_SVX_START + 581 )
#define SID_TABSTOP_ATTR_INDEX ( SID_SVX_START + 582 )
#define SID_TABSTOP_ATTR_POSITION ( SID_SVX_START + 583 )
// CAUTION! Range <587 .. 587> used by EditEngine (!)

View File

@ -1398,6 +1398,7 @@ callback (gpointer pData)
case LOK_CALLBACK_TABLE_SELECTED:
case LOK_CALLBACK_JSDIALOG:
case LOK_CALLBACK_CALC_FUNCTION_LIST:
case LOK_CALLBACK_TAB_STOP_LIST:
{
// TODO: Implement me
break;

View File

@ -7207,6 +7207,25 @@ SfxVoidItem RulerChangeState SID_RULER_CHANGE_STATE
GroupId = ;
]
SfxVoidItem ChangeTabStop SID_TABSTOP_ADD_OR_CHANGE
(SfxInt32Item Index SID_TABSTOP_ATTR_INDEX,
SfxInt32Item Position SID_TABSTOP_ATTR_POSITION)
[
AutoUpdate = FALSE,
FastCall = TRUE,
ReadOnlyDoc = TRUE,
Toggle = FALSE,
Container = FALSE,
RecordAbsolute = FALSE,
RecordPerSet;
AccelConfig = FALSE,
MenuConfig = FALSE,
ToolBoxConfig = FALSE,
GroupId = ;
]
SfxVoidItem TableChangeCurrentBorderPosition SID_TABLE_CHANGE_CURRENT_BORDER_POSITION
(SfxStringItem BorderType SID_TABLE_BORDER_TYPE,
SfxUInt16Item Index SID_TABLE_BORDER_INDEX,

View File

@ -643,6 +643,10 @@ interface BaseTextEditView
StateMethod = StateTabWin ;
DisableFlags="SfxDisableFlags::SwOnProtectedCursor";
]
SID_TABSTOP_ADD_OR_CHANGE // status()
[
ExecMethod = ExecTabWin;
]
// from here Export = FALSE;
FID_SEARCH_ON // status()
[

View File

@ -55,6 +55,9 @@
#include <section.hxx>
#include <ndtxt.hxx>
#include <pam.hxx>
#include <comphelper/lok.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <boost/property_tree/json_parser.hpp>
#include <IDocumentSettingAccess.hxx>
@ -647,6 +650,49 @@ void SwView::ExecTabWin( SfxRequest const & rReq )
rSh.SetAttrItem( aTabStops );
}
break;
case SID_TABSTOP_ADD_OR_CHANGE:
if (pReqArgs)
{
const auto aIndexItem = static_cast<const SfxInt32Item&>(pReqArgs->Get(SID_TABSTOP_ATTR_INDEX));
const auto aPositionItem = static_cast<const SfxInt32Item&>(pReqArgs->Get(SID_TABSTOP_ATTR_POSITION));
const sal_Int32 nIndex = aIndexItem.GetValue();
const sal_Int32 nPosition = aPositionItem.GetValue();
SfxItemSet aItemSet(GetPool(), svl::Items<RES_PARATR_TABSTOP, RES_PARATR_TABSTOP>{});
rSh.GetCurAttr(aItemSet);
SvxTabStopItem aTabStopItem(aItemSet.Get(RES_PARATR_TABSTOP));
lcl_EraseDefTabs(aTabStopItem);
if (nIndex < aTabStopItem.Count())
{
if (nIndex == -1)
{
SvxTabStop aSwTabStop(0, SvxTabAdjust::Default);
aTabStopItem.Insert(aSwTabStop);
const SvxTabStopItem& rDefaultTabs = rSh.GetDefault(RES_PARATR_TABSTOP);
MakeDefTabs(GetTabDist(rDefaultTabs), aTabStopItem);
SvxTabStop aTabStop(nPosition);
aTabStopItem.Insert(aTabStop);
}
else
{
SvxTabStop aTabStop = aTabStopItem.At(nIndex);
aTabStopItem.Remove(nIndex);
aTabStop.GetTabPos() = nPosition;
aTabStopItem.Insert(aTabStop);
SvxTabStop aSwTabStop(0, SvxTabAdjust::Default);
aTabStopItem.Insert(aSwTabStop);
const SvxTabStopItem& rDefaultTabs = rSh.GetDefault(RES_PARATR_TABSTOP);
MakeDefTabs(GetTabDist(rDefaultTabs), aTabStopItem);
}
rSh.SetAttrItem(aTabStopItem);
}
}
break;
case SID_HANGING_INDENT:
{
@ -1266,14 +1312,14 @@ void SwView::ExecTabWin( SfxRequest const & rReq )
// will be submitted to the tab bar.
void SwView::StateTabWin(SfxItemSet& rSet)
{
SwWrtShell &rSh = GetWrtShell();
SwWrtShell &rSh = GetWrtShell();
const Point* pPt = IsTabColFromDoc() || IsTabRowFromDoc() ? &m_aTabColFromDocPos : nullptr;
const FrameTypeFlags nFrameType = rSh.IsObjSelected()
? FrameTypeFlags::DRAWOBJ
: rSh.GetFrameType( pPt, true );
const bool bFrameSelection = rSh.IsFrameSelected();
const bool bFrameSelection = rSh.IsFrameSelected();
const bool bBrowse = rSh.GetViewOptions()->getBrowseMode();
// PageOffset/limiter
const SwRect& rPageRect = rSh.GetAnyCurRect( CurRectType::Page, pPt );
@ -1496,6 +1542,28 @@ void SwView::StateTabWin(SfxItemSet& rSet)
::lcl_EraseDefTabs(aTabStops);
aTabStops.SetWhich(nWhich);
rSet.Put(aTabStops);
if (comphelper::LibreOfficeKit::isActive() && nWhich == RES_PARATR_TABSTOP)
{
boost::property_tree::ptree aRootTree;
boost::property_tree::ptree aEntries;
for (sal_uInt16 i = 0; i < aTabStops.Count(); ++i)
{
SvxTabStop const & rTabStop = aTabStops[i];
boost::property_tree::ptree aEntry;
aEntry.put("position", convertTwipToMm100(rTabStop.GetTabPos()));
aEntry.put("type", sal_uInt16(rTabStop.GetAdjustment()));
aEntry.put("decimal", OUString(rTabStop.GetDecimal()));
aEntry.put("fill", OUString(rTabStop.GetFill()));
aEntries.push_back(std::make_pair("", aEntry));
}
aRootTree.push_back(std::make_pair("tabstops", aEntries));
std::stringstream aStream;
boost::property_tree::write_json(aStream, aRootTree);
rSh.GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TAB_STOP_LIST, aStream.str().c_str());
}
}
break;
}