[Libreoffice-commits] online.git: loleaflet/src

Henry Castro hcastro at collabora.com
Thu Sep 1 03:35:30 UTC 2016


 loleaflet/src/control/Control.ColumnHeader.js |   20 ++++++++++++++--
 loleaflet/src/control/Control.MetricInput.js  |   31 ++++++++++++++++++--------
 loleaflet/src/control/Control.RowHeader.js    |   18 ++++++++++++---
 loleaflet/src/layer/tile/CalcTileLayer.js     |    4 +++
 4 files changed, 58 insertions(+), 15 deletions(-)

New commits:
commit 1370c42afa95cbc276aaade460202aed352202ee
Author: Henry Castro <hcastro at collabora.com>
Date:   Wed Aug 31 23:34:45 2016 -0400

    loleaflet: update extra width/height for optimal column/row

diff --git a/loleaflet/src/control/Control.ColumnHeader.js b/loleaflet/src/control/Control.ColumnHeader.js
index 74949ab..ef67d60 100644
--- a/loleaflet/src/control/Control.ColumnHeader.js
+++ b/loleaflet/src/control/Control.ColumnHeader.js
@@ -49,7 +49,7 @@ L.Control.ColumnHeader = L.Control.Header.extend({
 					}
 				},
 				'optimalwidth': {
-					name: _('Optimal Width'),
+					name: _('Optimal Width') + '...',
 					callback: function(key, options) {
 						var colAlpha = options.$trigger.attr('rel').split('spreadsheet-column-')[1];
 						colHeaderObj.optimalWidth.call(colHeaderObj, colAlpha);
@@ -62,11 +62,14 @@ L.Control.ColumnHeader = L.Control.Header.extend({
 
 	optimalWidth: function(colAlpha) {
 		if (!this._dialog) {
-			this._dialog = L.control.metricInput(this._onDialogResult, this, {title: _('Optimal Column Width')});
+			this._dialog = L.control.metricInput(this._onDialogResult, this,
+							     this._map._docLayer.twipsToHMM(this._map._docLayer.STD_EXTRA_WIDTH),
+							     {title: _('Optimal Column Width')});
 		}
+		this._selectColumn(colAlpha, 0);
 		this._dialog.addTo(this._map);
 		this._map.enable(false);
-		this._dialog.update();
+		this._dialog.show();
 	},
 
 	insertColumn: function(colAlpha) {
@@ -194,6 +197,17 @@ L.Control.ColumnHeader = L.Control.Header.extend({
 	},
 
 	_onDialogResult: function (e) {
+		if (e.type === 'submit' && !isNaN(e.value)) {
+			var extra = {
+				aExtraWidth: {
+					type: 'unsigned short',
+					value: e.value
+				}
+			};
+
+			this._map.sendUnoCommand('.uno:SetOptimalColumnWidth', extra);
+		}
+
 		this._map.enable(true);
 	},
 
diff --git a/loleaflet/src/control/Control.MetricInput.js b/loleaflet/src/control/Control.MetricInput.js
index 88d3f69..df616d5 100644
--- a/loleaflet/src/control/Control.MetricInput.js
+++ b/loleaflet/src/control/Control.MetricInput.js
@@ -8,11 +8,12 @@ L.Control.MetricInput = L.Control.extend({
 		title: ''
 	},
 
-	initialize: function (callback, context, options) {
+	initialize: function (callback, context, value, options) {
 		L.setOptions(this, options);
 
 		this._callback = callback;
 		this._context = context;
+		this._default = value;
 	},
 
 	onAdd: function (map) {
@@ -34,7 +35,7 @@ L.Control.MetricInput = L.Control.extend({
 		var wrapper = L.DomUtil.create('div', 'leaflet-popup-content-wrapper', container);
 		var content = L.DomUtil.create('div', 'leaflet-popup-content', wrapper);
 		var labelTitle = document.createElement('span');
-		labelTitle.innerHTML = '<b>' + this.options.title + '</b>';
+		labelTitle.innerHTML = '<b>' + this.options.title + ' ' + _('(100th/mm)') + '</b>';
 		content.appendChild(labelTitle);
 		content.appendChild(document.createElement('br'));
 		content.appendChild(document.createElement('br'));
@@ -43,8 +44,9 @@ L.Control.MetricInput = L.Control.extend({
 		labelAdd.innerHTML = _('Add: ');
 		content.appendChild(labelAdd);
 
-		var inputMetric = document.createElement('input');
+		var inputMetric = this._input = document.createElement('input');
 		inputMetric.type = 'text';
+		inputMetric.value = this._default;
 		content.appendChild(inputMetric);
 		content.appendChild(document.createElement('br'));
 		content.appendChild(document.createElement('br'));
@@ -52,6 +54,7 @@ L.Control.MetricInput = L.Control.extend({
 		var inputValue = document.createElement('input');
 		inputValue.type = 'checkbox';
 		inputValue.checked = true;
+		L.DomEvent.on(inputValue, 'click', this._onDefaultClick, this);
 		content.appendChild(inputValue);
 
 		var labelValue = document.createElement('span');
@@ -62,28 +65,38 @@ L.Control.MetricInput = L.Control.extend({
 
 		var inputButton = document.createElement('input');
 		inputButton.type = 'button';
-		inputButton.value = _('OK');
+		inputButton.value = _('Submit');
 		L.DomEvent.on(inputButton, 'click', this._onOKButtonClick, this);
 
 		content.appendChild(inputButton);
 	},
 
-	update: function () {
+	onRemove: function (map) {
+		this._input = null;
+	},
+
+	show: function () {
 		this._container.style.marginLeft = (-this._container.offsetWidth / 2) + 'px';
 		this._container.style.visibility = '';
+		this._input.focus();
+	},
+
+	_onDefaultClick: function (e) {
+		this._input.value = this._default;
 	},
 
 	_onOKButtonClick: function (e) {
+		var data = parseFloat(this._input.value);
 		this.remove();
-		this._callback.call(this._context, {type: 'ok', data: 0});
+		this._callback.call(this._context, {type: 'submit', value: data});
 	},
 
 	_onCloseButtonClick: function (e) {
 		this.remove();
-		this._callback.call(this._context, {type : 'cancel'});
+		this._callback.call(this._context, {type : 'close'});
 	}
 });
 
-L.control.metricInput = function (callback, context, options) {
-	return new L.Control.MetricInput(callback, context, options);
+L.control.metricInput = function (callback, context, value, options) {
+	return new L.Control.MetricInput(callback, context, value, options);
 };
diff --git a/loleaflet/src/control/Control.RowHeader.js b/loleaflet/src/control/Control.RowHeader.js
index 2395d3e..2236c20 100644
--- a/loleaflet/src/control/Control.RowHeader.js
+++ b/loleaflet/src/control/Control.RowHeader.js
@@ -47,7 +47,7 @@ L.Control.RowHeader = L.Control.Header.extend({
 					}
 				},
 				'optimalheight': {
-					name: _('Optimal Height'),
+					name: _('Optimal Height') + '...',
 					callback: function(key, options) {
 						var row = parseInt(options.$trigger.attr('rel').split('spreadsheet-row-')[1]);
 						rowHeaderObj.optimalHeight.call(rowHeaderObj, row);
@@ -60,11 +60,12 @@ L.Control.RowHeader = L.Control.Header.extend({
 
 	optimalHeight: function(row) {
 		if (!this._dialog) {
-			this._dialog = L.control.metricInput(this._onDialogResult, this, {title: _('Optimal Row Height')});
+			this._dialog = L.control.metricInput(this._onDialogResult, this, 0, {title: _('Optimal Row Height')});
 		}
+		this._selectRow(row, 0);
 		this._dialog.addTo(this._map);
 		this._map.enable(false);
-		this._dialog.update();
+		this._dialog.show();
 	},
 
 	insertRow: function(row) {
@@ -176,6 +177,17 @@ L.Control.RowHeader = L.Control.Header.extend({
 	},
 
 	_onDialogResult: function (e) {
+		if (e.type === 'submit' && !isNaN(e.value)) {
+			var extra = {
+				aExtraHeight: {
+					type: 'unsigned short',
+					value: e.value
+				}
+			};
+
+			this._map.sendUnoCommand('.uno:SetOptimalRowHeight', extra);
+		}
+
 		this._map.enable(true);
 	},
 
diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js
index 9989aa8..b3ac37f 100644
--- a/loleaflet/src/layer/tile/CalcTileLayer.js
+++ b/loleaflet/src/layer/tile/CalcTileLayer.js
@@ -7,6 +7,10 @@ L.CalcTileLayer = L.TileLayer.extend({
                               * 0.1986cm with TeX points,
                               * 0.1993cm with PS points. */
 
+	twipsToHMM: function (twips) {
+		return (twips * 127 + 36) / 72;
+	},
+
 	beforeAdd: function (map) {
 		map._addZoomLimit(this);
 		map.on('zoomend', this._onZoomRowColumns, this);


More information about the Libreoffice-commits mailing list