diff options
author | Dennis Francis <dennis.francis@collabora.com> | 2022-05-12 13:13:35 +0530 |
---|---|---|
committer | Pranam Lashkari <lpranam@collabora.com> | 2022-05-17 15:17:41 +0200 |
commit | 172bc7a8f4eeab907adac077407186fbbd046a77 (patch) | |
tree | 634720716e36534c7c055b97b14ebfea6f09be2e /sc | |
parent | 7260b8724fafd41294761382f69ece7fe09588c4 (diff) |
lok-calc: new callback for print ranges
With this callback the lok clients can read and draw the print ranges on
each sheet of the Calc document.
Change-Id: Ie19351d4420e0f3d4191f6a354ce99ab830aede2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134375
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Pranam Lashkari <lpranam@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/prnsave.hxx | 3 | ||||
-rw-r--r-- | sc/source/core/tool/prnsave.cxx | 32 | ||||
-rw-r--r-- | sc/source/ui/undo/undotab.cxx | 15 | ||||
-rw-r--r-- | sc/source/ui/view/viewfun2.cxx | 11 |
4 files changed, 61 insertions, 0 deletions
diff --git a/sc/inc/prnsave.hxx b/sc/inc/prnsave.hxx index ca928f908dd1..a2e6810554e7 100644 --- a/sc/inc/prnsave.hxx +++ b/sc/inc/prnsave.hxx @@ -24,6 +24,8 @@ #include <vector> #include <memory> +namespace tools { class JsonWriter; } + class ScPrintSaverTab { typedef ::std::vector< ScRange > ScRangeVec; @@ -60,6 +62,7 @@ public: SCTAB GetTabCount() const { return nTabCount; } ScPrintSaverTab& GetTabData(SCTAB nTab); const ScPrintSaverTab& GetTabData(SCTAB nTab) const; + void GetPrintRangesInfo(tools::JsonWriter& rPrintRanges) const; bool operator==( const ScPrintRangeSaver& rCmp ) const; }; diff --git a/sc/source/core/tool/prnsave.cxx b/sc/source/core/tool/prnsave.cxx index c07eda00f9ed..09e4c7f48473 100644 --- a/sc/source/core/tool/prnsave.cxx +++ b/sc/source/core/tool/prnsave.cxx @@ -22,6 +22,7 @@ #include <address.hxx> #include <osl/diagnose.h> +#include <tools/json_writer.hxx> // Data per table @@ -87,6 +88,37 @@ const ScPrintSaverTab& ScPrintRangeSaver::GetTabData(SCTAB nTab) const return pData[nTab]; } +void ScPrintRangeSaver::GetPrintRangesInfo(tools::JsonWriter& rPrintRanges) const +{ + // Array for sheets in the document. + auto printRanges = rPrintRanges.startArray("printranges"); + for (SCTAB nTab = 0; nTab < nTabCount; nTab++) + { + auto sheetNode = rPrintRanges.startStruct(); + const ScPrintSaverTab& rPsTab = pData[nTab]; + const std::vector<ScRange>& rRangeVec = rPsTab.GetPrintRanges(); + + rPrintRanges.put("sheet", static_cast<sal_Int32>(nTab)); + + // Array for ranges within each sheet. + auto sheetRanges = rPrintRanges.startArray("ranges"); + OStringBuffer aRanges; + sal_Int32 nLast = rRangeVec.size() - 1; + for (sal_Int32 nIdx = 0; nIdx <= nLast; ++nIdx) + { + const ScRange& rRange = rRangeVec[nIdx]; + aRanges.append("[ " + + OString::number(rRange.aStart.Col()) + ", " + + OString::number(rRange.aStart.Row()) + ", " + + OString::number(rRange.aEnd.Col()) + ", " + + OString::number(rRange.aEnd.Row()) + + OString(nLast == nIdx ? "]" : "], ")); + } + + rPrintRanges.putRaw(aRanges.getStr()); + } +} + bool ScPrintRangeSaver::operator==( const ScPrintRangeSaver& rCmp ) const { bool bEqual = ( nTabCount == rCmp.nTabCount ); diff --git a/sc/source/ui/undo/undotab.cxx b/sc/source/ui/undo/undotab.cxx index 85c2708367e4..8e674517c0c5 100644 --- a/sc/source/ui/undo/undotab.cxx +++ b/sc/source/ui/undo/undotab.cxx @@ -48,6 +48,9 @@ #include <drwlayer.hxx> #include <scresid.hxx> #include <sheetevents.hxx> +#include <LibreOfficeKit/LibreOfficeKitEnums.h> +#include <comphelper/lok.hxx> +#include <tools/json_writer.hxx> #include <memory> #include <utility> @@ -1315,6 +1318,18 @@ void ScUndoPrintRange::DoChange(bool bUndo) ScPrintFunc( pDocShell, pDocShell->GetPrinter(), nTab ).UpdatePages(); + if (pViewShell && comphelper::LibreOfficeKit::isActive()) + { + tools::JsonWriter aJsonWriter; + if (bUndo) + pOldRanges->GetPrintRangesInfo(aJsonWriter); + else + pNewRanges->GetPrintRangesInfo(aJsonWriter); + + const std::string message = aJsonWriter.extractAsStdString(); + pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_PRINT_RANGES, message.c_str()); + } + pDocShell->PostPaint( ScRange(0,0,nTab,rDoc.MaxCol(),rDoc.MaxRow(),nTab), PaintPartFlags::Grid ); } diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index 8fc4e7597a25..97f63fb4a300 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -86,6 +86,7 @@ #include <vector> #include <memory> #include <boost/property_tree/json_parser.hpp> +#include <tools/json_writer.hxx> #include <officecfg/Office/Calc.hxx> @@ -1101,6 +1102,16 @@ void ScViewFunc::SetPrintRanges( bool bEntireSheet, const OUString* pPrint, { SCTAB nCurTab = GetViewData().GetTabNo(); std::unique_ptr<ScPrintRangeSaver> pNewRanges = rDoc.CreatePrintRangeSaver(); + if (comphelper::LibreOfficeKit::isActive()) + { + tools::JsonWriter aJsonWriter; + pNewRanges->GetPrintRangesInfo(aJsonWriter); + + SfxViewShell* pViewShell = GetViewData().GetViewShell(); + const std::string message = aJsonWriter.extractAsStdString(); + pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_PRINT_RANGES, message.c_str()); + } + pDocSh->GetUndoManager()->AddUndoAction( std::make_unique<ScUndoPrintRange>( pDocSh, nCurTab, std::move(pOldRanges), std::move(pNewRanges) ) ); } |