include/LibreOfficeKit/LibreOfficeKitEnums.h | 31 ++++++++++++++++++++++++++ libreofficekit/source/gtk/lokdocview.cxx | 1 sc/inc/prnsave.hxx | 3 ++ sc/source/core/tool/prnsave.cxx | 32 +++++++++++++++++++++++++++ sc/source/ui/undo/undotab.cxx | 15 ++++++++++++ sc/source/ui/view/viewfun2.cxx | 11 +++++++++ 6 files changed, 93 insertions(+)
New commits: commit b846fb660a91130aceee52fed11170a95b2f3934 Author: Dennis Francis <dennis.fran...@collabora.com> AuthorDate: Thu May 12 13:13:35 2022 +0530 Commit: Dennis Francis <dennis.fran...@collabora.com> CommitDate: Sat May 21 09:14:42 2022 +0200 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. Conflicts: include/LibreOfficeKit/LibreOfficeKitEnums.h libreofficekit/source/gtk/lokdocview.cxx Change-Id: Ie19351d4420e0f3d4191f6a354ce99ab830aede2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134375 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Pranam Lashkari <lpra...@collabora.com> (cherry picked from commit 172bc7a8f4eeab907adac077407186fbbd046a77) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134527 Reviewed-by: Gökay ŞATIR <gokaysa...@collabora.com> (cherry picked from commit 29b7b25d454e0a6cd07c00e13fdb83cc8a381583) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134614 Tested-by: Jenkins Reviewed-by: Dennis Francis <dennis.fran...@collabora.com> diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h index 0fda66777a09..05544b5473a5 100644 --- a/include/LibreOfficeKit/LibreOfficeKitEnums.h +++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h @@ -811,6 +811,35 @@ typedef enum * } */ LOK_CALLBACK_CONTENT_CONTROL = 55, + + /** + * This is Calc specific. The payload contains print ranges of all + * sheets in the document. + * + * Payload example: + * { + * "printranges" : [ + * { + * "sheet": 0, + * "ranges": [ + * [0, 0, 4, 5], + * [5, 100, 8, 150] + * ] + * }, + * { + * "sheet": 3, + * "ranges": [ + * [1, 0, 6, 10], + * [3, 200, 6, 230] + * ] + * } + * ] + * } + * + * The format of the inner "ranges" array for each sheet is + * [<startColumn>, <startRow>, <endColumn>, <endRow>] + */ + LOK_CALLBACK_PRINT_RANGES = 56, } LibreOfficeKitCallbackType; @@ -951,6 +980,8 @@ static inline const char* lokCallbackTypeToString(int nType) return "LOK_CALLBACK_SC_FOLLOW_JUMP"; case LOK_CALLBACK_CONTENT_CONTROL: return "LOK_CALLBACK_CONTENT_CONTROL"; + case LOK_CALLBACK_PRINT_RANGES: + return "LOK_CALLBACK_PRINT_RANGES"; } assert(!"Unknown LibreOfficeKitCallbackType type."); diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index b20cc85af875..aafaa084be9c 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -1439,6 +1439,7 @@ callback (gpointer pData) case LOK_CALLBACK_DOCUMENT_BACKGROUND_COLOR: case LOK_COMMAND_BLOCKED: case LOK_CALLBACK_SC_FOLLOW_JUMP: + case LOK_CALLBACK_PRINT_RANGES: { // TODO: Implement me break; diff --git a/sc/inc/prnsave.hxx b/sc/inc/prnsave.hxx index ef6f50d587dc..af2824b40cf8 100644 --- a/sc/inc/prnsave.hxx +++ b/sc/inc/prnsave.hxx @@ -23,6 +23,8 @@ #include <vector> #include <memory> +namespace tools { class JsonWriter; } + class ScPrintSaverTab { typedef ::std::vector< ScRange > ScRangeVec; @@ -59,6 +61,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 e5a2e92f1a44..f5700cbd3e08 100644 --- a/sc/source/core/tool/prnsave.cxx +++ b/sc/source/core/tool/prnsave.cxx @@ -21,6 +21,7 @@ #include <address.hxx> #include <osl/diagnose.h> +#include <tools/json_writer.hxx> // Data per table @@ -86,6 +87,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()) + + (nLast == nIdx ? std::string_view("]") : std::string_view("], "))); + } + + 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 7ce4c23d17c2..b898faf8075f 100644 --- a/sc/source/ui/undo/undotab.cxx +++ b/sc/source/ui/undo/undotab.cxx @@ -49,6 +49,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> @@ -1317,6 +1320,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 dd1c48f73164..c1f301fd0ea2 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -87,6 +87,7 @@ #include <vector> #include <memory> #include <boost/property_tree/json_parser.hpp> +#include <tools/json_writer.hxx> #include <officecfg/Office/Calc.hxx> @@ -1131,6 +1132,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) ) ); }