bundled/include/LibreOfficeKit/LibreOfficeKit.h |    3 +
 kit/KitHelper.hpp                               |   32 +++++++++++++++++-
 loleaflet/src/control/Control.Menubar.js        |    1 
 loleaflet/src/control/Control.Tabs.js           |   16 ++++++++-
 loleaflet/src/control/Parts.js                  |   42 ++++++++++++++++++++++++
 loleaflet/src/core/Socket.js                    |    7 ++++
 loleaflet/src/layer/tile/CalcTileLayer.js       |   25 ++++++++++++--
 loleaflet/unocommands.js                        |    3 +
 8 files changed, 124 insertions(+), 5 deletions(-)

New commits:
commit 264c79d16cf6418c3b1359c02c8be813082eae1c
Author: Marco Cecchetti <marco.cecche...@collabora.com>
Date:   Thu Feb 1 16:36:24 2018 +0100

    calc: added support for hidden sheets and validation of cell content
    
    Change-Id: I5db971b8826de7d5be2f88354925cd107082da77
    Reviewed-on: https://gerrit.libreoffice.org/50007
    Reviewed-by: Jan Holesovsky <ke...@collabora.com>
    Tested-by: Jan Holesovsky <ke...@collabora.com>

diff --git a/bundled/include/LibreOfficeKit/LibreOfficeKit.h 
b/bundled/include/LibreOfficeKit/LibreOfficeKit.h
index 2af965e4..e58e6902 100644
--- a/bundled/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/bundled/include/LibreOfficeKit/LibreOfficeKit.h
@@ -295,6 +295,9 @@ struct _LibreOfficeKitDocumentClass
                                    int nType,
                                    const char* pText);
 
+    /// @see lok::Document::getPartInfo().
+    char* (*getPartInfo) (LibreOfficeKitDocument* pThis, int nPart);
+
 #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
 };
 
diff --git a/kit/KitHelper.hpp b/kit/KitHelper.hpp
index f3523a9f..1cc6b7fb 100644
--- a/kit/KitHelper.hpp
+++ b/kit/KitHelper.hpp
@@ -13,6 +13,8 @@
 #include <sstream>
 #include <string>
 
+#include <Util.hpp>
+
 #define LOK_USE_UNSTABLE_API
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 
@@ -140,7 +142,35 @@ namespace LOKitHelper
 
         if (type == LOK_DOCTYPE_SPREADSHEET || type == 
LOK_DOCTYPE_PRESENTATION)
         {
-            for (auto i = 0; i < parts; ++i)
+            if (type == LOK_DOCTYPE_SPREADSHEET)
+            {
+                std::ostringstream hposs;
+                for (int i = 0; i < parts; ++i)
+                {
+
+                    ptrValue = 
loKitDocument->pClass->getPartInfo(loKitDocument, i);
+                    std::string partinfo(ptrValue);
+                    std::free(ptrValue);
+                    const auto aPartInfo = Util::JsonToMap(partinfo);
+                    for (const auto prop: aPartInfo)
+                    {
+                        const std::string& name = prop.first;
+                        if (name == "visible")
+                        {
+                            if (prop.second == "0")
+                                hposs << i << ",";
+                        }
+                    }
+                }
+                std::string hiddenparts = hposs.str();
+                if (!hiddenparts.empty())
+                {
+                    hiddenparts.pop_back();
+                    oss << " hiddenparts=" << hiddenparts;
+                }
+            }
+
+            for (int i = 0; i < parts; ++i)
             {
                 oss << "\n";
                 ptrValue = loKitDocument->pClass->getPartName(loKitDocument, 
i);
diff --git a/loleaflet/src/control/Control.Menubar.js 
b/loleaflet/src/control/Control.Menubar.js
index 8b6a2e99..81dd25fc 100644
--- a/loleaflet/src/control/Control.Menubar.js
+++ b/loleaflet/src/control/Control.Menubar.js
@@ -353,6 +353,7 @@ L.Control.Menubar = L.Control.extend({
                                {uno: '.uno:DataSort'},
                                {uno: '.uno:SortAscending'},
                                {uno: '.uno:SortDescending'},
+                               {uno: '.uno:Validation'},
                                {type: 'separator'},
                                {uno: '.uno:DataFilterAutoFilter'},
                                {name: _UNO('.uno:FilterMenu', 'spreadsheet'), 
type: 'menu', menu: [
diff --git a/loleaflet/src/control/Control.Tabs.js 
b/loleaflet/src/control/Control.Tabs.js
index a2095457..8295f2fd 100644
--- a/loleaflet/src/control/Control.Tabs.js
+++ b/loleaflet/src/control/Control.Tabs.js
@@ -68,7 +68,19 @@ L.Control.Tabs = L.Control.extend({
                                                                                
map.renamePage(data.sheetname, nPos);
                                                                        }
                                                                });
-                                                       }}
+                                                       }},
+                               'showsheets': {
+                                       name: _UNO('.uno:Show', 'spreadsheet', 
true),
+                                       callback: function() {
+                                               map.showPage();
+                                       }
+                               },
+                               'hiddensheets': {
+                                       name: _UNO('.uno:Hide', 'spreadsheet', 
true),
+                                       callback: function() {
+                                               map.hidePage();
+                                       }
+                               }
                        },
                        zIndex: 1000
                });
@@ -103,6 +115,8 @@ L.Control.Tabs = L.Control.extend({
                                ssTabScroll.id = 'spreadsheet-tab-scroll';
 
                                for (var i = 0; i < parts; i++) {
+                                       if (e.hiddenParts.indexOf(i) !== -1)
+                                               continue;
                                        var id = 'spreadsheet-tab' + i;
                                        var tab = L.DomUtil.create('div', 
'spreadsheet-tab', ssTabScroll);
                                        tab.innerHTML = e.partNames[i];
diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js
index 1071db03..0b8d9e1a 100644
--- a/loleaflet/src/control/Parts.js
+++ b/loleaflet/src/control/Parts.js
@@ -233,6 +233,10 @@ L.Map.include({
                        return;
                }
 
+               if (this.getDocType() === 'spreadsheet' && docLayer._parts <= 
docLayer.hiddenParts() + 1) {
+                       return;
+               }
+
                this.fire('deletepage', {
                        selectedPart: docLayer._selectedPart,
                        parts:        docLayer._parts
@@ -269,6 +273,30 @@ L.Map.include({
                }
        },
 
+       showPage: function () {
+               if (this.getDocType() === 'spreadsheet' && 
this.hasAnyHiddenPart()) {
+                       this._socket.sendMessage('uno .uno:Show');
+               }
+       },
+
+       hidePage: function () {
+               if (this.getDocType() === 'spreadsheet' && 
this.getNumberOfVisibleParts() > 1) {
+                       this._socket.sendMessage('uno .uno:Hide');
+               }
+       },
+
+       isHiddenPart: function (part) {
+               if (this.getDocType() !== 'spreadsheet')
+                       return false;
+               return this._docLayer.isHiddenPart(part);
+       },
+
+       hasAnyHiddenPart: function () {
+               if (this.getDocType() !== 'spreadsheet')
+                       return false;
+               return this._docLayer.hasAnyHiddenPart();
+       },
+
        getNumberOfPages: function () {
                return this._docLayer._pages;
        },
@@ -277,6 +305,20 @@ L.Map.include({
                return this._docLayer._parts;
        },
 
+       getNumberOfVisibleParts: function () {
+               return this.getNumberOfParts() - this._docLayer.hiddenParts();
+       },
+
+       getHiddenPartNames: function () {
+               var partNames = this._docLayer._partNames;
+               var names = [];
+               for (var i = 0; i < partNames.length; ++i) {
+                       if (this.isHiddenPart(i))
+                               names.push(partNames[i]);
+               }
+               return names.join(',');
+       },
+
        getCurrentPageNumber: function () {
                return this._docLayer._currentPage;
        },
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 068edc9a..4b609f28 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -862,6 +862,13 @@ L.Socket = L.Class.extend({
                        else if (tokens[i].substring(0, 10) === 'rectangle=') {
                                command.rectangle = tokens[i].substring(10);
                        }
+                       else if (tokens[i].substring(0, 12) === 'hiddenparts=') 
{
+                               var hiddenparts = 
tokens[i].substring(12).split(',');
+                               command.hiddenparts = [];
+                               hiddenparts.forEach(function (item) {
+                                       
command.hiddenparts.push(parseInt(item));
+                               });
+                       }
                }
                if (command.tileWidth && command.tileHeight && 
this._map._docLayer) {
                        var defaultZoom = this._map.options.zoom;
diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js 
b/loleaflet/src/layer/tile/CalcTileLayer.js
index a485746d..d9f52c4e 100644
--- a/loleaflet/src/layer/tile/CalcTileLayer.js
+++ b/loleaflet/src/layer/tile/CalcTileLayer.js
@@ -5,8 +5,8 @@
 
 L.CalcTileLayer = L.TileLayer.extend({
        STD_EXTRA_WIDTH: 113, /* 2mm extra for optimal width,
-                              * 0.1986cm with TeX points,
-                              * 0.1993cm with PS points. */
+                                                         * 0.1986cm with TeX 
points,
+                                                         * 0.1993cm with PS 
points. */
 
        twipsToHMM: function (twips) {
                return (twips * 127 + 36) / 72;
@@ -103,6 +103,23 @@ L.CalcTileLayer = L.TileLayer.extend({
                }
        },
 
+       isHiddenPart: function (part) {
+               if (!this._hiddenParts)
+                       return false;
+               return this._hiddenParts.indexOf(part) !== -1;
+       },
+
+       hiddenParts: function () {
+               if (!this._hiddenParts)
+                       return 0;
+               return this._hiddenParts.length;
+       },
+
+       hasAnyHiddenPart: function () {
+               if (!this._hiddenParts)
+                       return false;
+               return this.hiddenParts() !== 0;
+       },
        _onAnnotationCancel: function (e) {
                if (e.annotation._data.id === 'new') {
                        this.hideAnnotation(e.annotation._tag);
@@ -333,7 +350,7 @@ L.CalcTileLayer = L.TileLayer.extend({
 
        _onSetPartMsg: function (textMsg) {
                var part = parseInt(textMsg.match(/\d+/g)[0]);
-               if (part !== this._selectedPart) {
+               if (part !== this._selectedPart && !this.isHiddenPart(part)) {
                        this._map.setPart(part, true);
                        this._map.fire('setpart', {selectedPart: 
this._selectedPart});
                        // TODO: test it!
@@ -401,6 +418,7 @@ L.CalcTileLayer = L.TileLayer.extend({
                        else {
                                this._updateMaxBounds(true);
                        }
+                       this._hiddenParts = command.hiddenparts || [];
                        this._documentInfo = textMsg;
                        var partNames = textMsg.match(/[^\r\n]+/g);
                        // only get the last matches
@@ -410,6 +428,7 @@ L.CalcTileLayer = L.TileLayer.extend({
                                parts: this._parts,
                                docType: this._docType,
                                partNames: this._partNames,
+                               hiddenParts: this._hiddenParts,
                                source: 'status'
                        });
                        this._resetPreFetching(true);
diff --git a/loleaflet/unocommands.js b/loleaflet/unocommands.js
index 4ad52b93..0a1f4fc9 100644
--- a/loleaflet/unocommands.js
+++ b/loleaflet/unocommands.js
@@ -77,6 +77,7 @@ var unoCommandsArray = {
        GroupOutlineMenu:{spreadsheet:{menu:_('~Group and Outline'),},},
        Grow:{global:{menu:_('Increase Size'),},},
        HelpMenu:{global:{menu:_('~Help'),},},
+       Hide:{spreadsheet:{menu:_('~Hide Sheet'),},},
        HideColumn:{spreadsheet:{context:_('H~ide Columns'),menu:_('~Hide'),},},
        HideDetail:{global:{menu:_('~Hide Details'),},},
        HideRow:{spreadsheet:{context:_('H~ide Rows'),menu:_('H~ide'),},},
@@ -193,6 +194,7 @@ var unoCommandsArray = {
        SetOptimalRowHeight:{spreadsheet:{menu:_('~Optimal 
Height...'),},text:{menu:_('Optimal Row Height'),},},
        Shadowed:{global:{menu:_('Shadow'),},},
        SheetMenu:{spreadsheet:{menu:_('~Sheet'),},},
+       Show:{spreadsheet:{menu:_('~Show Sheet...'),},},
        ShowColumn:{spreadsheet:{context:_('S~how Columns'),menu:_('~Show'),},},
        ShowDetail:{global:{menu:_('~Show Details'),},},
        ShowRow:{spreadsheet:{context:_('Sho~w Rows'),menu:_('~Show'),},},
@@ -229,6 +231,7 @@ var unoCommandsArray = {
        Ungroup:{global:{menu:_('~Ungroup...'),},},
        UpSearch:{global:{menu:_('Find Previous'),},},
        UpdateCurIndex:{text:{context:_('Update index'),menu:_('Current 
~Index'),},},
+       Validation:{spreadsheet:{menu:_('~Validity...'),},},
        ViewMenu:{global:{menu:_('~View'),},},
        WordCountDialog:{text:{menu:_('~Word Count'),},},
        WrapAnchorOnly:{text:{menu:_('~First Paragraph'),},},
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to