Commit 5c73516b authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

Вынес extendClass в common.

Убрал inherit, оставил только extendClass

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@58003 954022d7-b5bf-4e40-9824-e11837661b57
parent 8cf7fb6e
...@@ -671,3 +671,26 @@ else ...@@ -671,3 +671,26 @@ else
FDqVBWmtq5oV65JdxpgqUKzTcf0ZEOOGl0Dsui4R+Ni+7wksOZAk+75nycQ6fl8S054+DEN1P25L\ FDqVBWmtq5oV65JdxpgqUKzTcf0ZEOOGl0Dsui4R+Ni+7wksOZAk+75nycQ6fl8S054+DEN1P25L\
M8Zg27Zb0DiOj6CPDE7TlB1rMgpAT2MJpEjSOff436zrGvjOuSCm+PL6z/MMAFiWJZirfz0j3wEA\ M8Zg27Zb0DiOj6CPDE7TlB1rMgpAT2MJpEjSOff436zrGvjOuSCm+PL6z/MMAFiWJZirfz0j3wEA\
emp/gv47IxYAAAAASUVORK5CYII=') 14 8, pointer"; emp/gv47IxYAAAAASUVORK5CYII=') 14 8, pointer";
(
/**
* @param {Window} window
* @param {undefined} undefined
*/
function (window, undefined) {
/*
* Import
* -----------------------------------------------------------------------------
*/
var asc = window["Asc"] ? window["Asc"] : (window["Asc"] = {});
function extendClass (Child, Parent) {
var F = function() { };
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.prototype.constructor = Child;
Child.superclass = Parent.prototype;
}
asc.extendClass = extendClass;
}
)(window);
\ No newline at end of file
...@@ -100,21 +100,18 @@ ...@@ -100,21 +100,18 @@
strictEqual(Asc.round(-.1-.2-.9+.2), -1, "Asc.round(.1+.2+.9-.2)"); // -1.0000...2 strictEqual(Asc.round(-.1-.2-.9+.2), -1, "Asc.round(.1+.2+.9-.2)"); // -1.0000...2
}); });
test("Asc.inherit", function test_inherit() { test("Asc.extendClass", function test_extendClass() {
function Base(b1) { function Base(b1) {
this.b1 = b1; this.b1 = b1;
} }
Base.prototype = { Base.prototype.mb1 = function (b1) {this.b1=b1;};
mb1: function (b1) {this.b1=b1;}
};
function Child(b1, c1) { function Child(b1, c1) {
Child.superclass.constructor.call(this, b1); Child.superclass.constructor.call(this, b1);
this.c1 = c1; this.c1 = c1;
} }
Asc.inherit(Child, Base, { Asc.extendClass(Child, Base);
mc1: function (c1) {this.c1=c1;} Child.prototype.mc1 = function (c1) {this.c1=c1;};
});
var x = new Child(1, 2); var x = new Child(1, 2);
ok(x !== undefined, "x = new Child(1, 2)"); ok(x !== undefined, "x = new Child(1, 2)");
...@@ -130,15 +127,13 @@ ...@@ -130,15 +127,13 @@
equal(x.c1, 4, "x.c1"); equal(x.c1, 4, "x.c1");
}); });
test("Asc.inherit with fabric method", function test_inherit2() { test("Asc.extendClass with fabric method", function test_extendClass2() {
function Base(b1) { function Base(b1) {
if ( !(this instanceof Base) ) {return new Base(b1);} if ( !(this instanceof Base) ) {return new Base(b1);}
this.b1 = b1; this.b1 = b1;
return this; return this;
} }
Base.prototype = { Base.prototype.mb1 = function (b1) {this.b1=b1;};
mb1: function (b1) {this.b1=b1;}
};
function Child(b1, c1) { function Child(b1, c1) {
if ( !(this instanceof Child) ) {return new Child(b1, c1);} if ( !(this instanceof Child) ) {return new Child(b1, c1);}
...@@ -146,9 +141,8 @@ ...@@ -146,9 +141,8 @@
this.c1 = c1; this.c1 = c1;
return this; return this;
} }
Asc.inherit(Child, Base, { Asc.extendClass(Child, Base);
mc1: function (c1) {this.c1=c1;} Child.prototype.mc1 = function (c1) {this.c1=c1;};
});
var x = Child(1, 2); var x = Child(1, 2);
ok(x !== undefined, "x = Child(1, 2)"); ok(x !== undefined, "x = Child(1, 2)");
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
* Author: Dmitry.Sokolov@avsmedia.net * Author: Dmitry.Sokolov@avsmedia.net
* Date: Jan 25, 2012 * Date: Jan 25, 2012
*/ */
( /** (
/**
* @param {jQuery} $ * @param {jQuery} $
* @param {Window} window * @param {Window} window
* @param {undefined} undefined * @param {undefined} undefined
...@@ -123,16 +124,6 @@ ...@@ -123,16 +124,6 @@
return aSizes[i]; return aSizes[i];
} }
function inherit(child, parent, childProto) {
parent.prototype.constructor = parent;
var F = function () {};
F.prototype = parent.prototype;
child.prototype = $.extend(true, new F(), childProto);
child.prototype.constructor = child;
child.superclass = parent.prototype;
}
// Определяет времени работы функции // Определяет времени работы функции
function profileTime(fn/*[, arguments]*/) { function profileTime(fn/*[, arguments]*/) {
var start, end, arg = [], i; var start, end, arg = [], i;
...@@ -399,7 +390,7 @@ ...@@ -399,7 +390,7 @@
this.startRow = 0; // Активная ячейка в выделении this.startRow = 0; // Активная ячейка в выделении
this._updateAdditionalData(); this._updateAdditionalData();
} }
extendClass(ActiveRange, Range); asc.extendClass(ActiveRange, Range);
ActiveRange.prototype.assign = function () { ActiveRange.prototype.assign = function () {
ActiveRange.superclass.assign.apply(this, arguments); ActiveRange.superclass.assign.apply(this, arguments);
...@@ -518,7 +509,7 @@ ...@@ -518,7 +509,7 @@
this.r2Abs = false; this.r2Abs = false;
this.c2Abs = false; this.c2Abs = false;
} }
extendClass(FormulaRange, Range); asc.extendClass(FormulaRange, Range);
FormulaRange.prototype.clone = function(){ FormulaRange.prototype.clone = function(){
var oRes = new FormulaRange(FormulaRange.superclass.clone.apply(this, arguments)); var oRes = new FormulaRange(FormulaRange.superclass.clone.apply(this, arguments));
oRes.r1Abs = this.r1Abs; oRes.r1Abs = this.r1Abs;
...@@ -821,15 +812,6 @@ ...@@ -821,15 +812,6 @@
return val.replace(/^\s+|\s+$/g,''); return val.replace(/^\s+|\s+$/g,'');
} }
function extendClass(Child, Parent){
var F = function() { };
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.prototype.constructor = Child;
Child.superclass = Parent.prototype;
}
function isNumber(val) { function isNumber(val) {
var valTrim = trim(val); var valTrim = trim(val);
return (valTrim - 0) == valTrim && valTrim.length > 0; return (valTrim - 0) == valTrim && valTrim.length > 0;
...@@ -1502,14 +1484,12 @@ ...@@ -1502,14 +1484,12 @@
window["Asc"].floor = floor; window["Asc"].floor = floor;
window["Asc"].ceil = ceil; window["Asc"].ceil = ceil;
window["Asc"].incDecFonSize = incDecFonSize; window["Asc"].incDecFonSize = incDecFonSize;
window["Asc"].inherit = inherit;
window["Asc"].outputDebugStr = outputDebugStr; window["Asc"].outputDebugStr = outputDebugStr;
window["Asc"].isEqual = isEqual; window["Asc"].isEqual = isEqual;
window["Asc"].profileTime = profileTime; window["Asc"].profileTime = profileTime;
window["Asc"].isNumber = isNumber; window["Asc"].isNumber = isNumber;
window["Asc"].isNumberInfinity = isNumberInfinity; window["Asc"].isNumberInfinity = isNumberInfinity;
window["Asc"].trim = trim; window["Asc"].trim = trim;
window["Asc"].extendClass = extendClass;
window["Asc"].arrayToLowerCase = arrayToLowerCase; window["Asc"].arrayToLowerCase = arrayToLowerCase;
window["Asc"].isFixedWidthCell = isFixedWidthCell; window["Asc"].isFixedWidthCell = isFixedWidthCell;
window["Asc"].truncFracPart = truncFracPart; window["Asc"].truncFracPart = truncFracPart;
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
var asc_lastidx = asc.lastIndexOf; var asc_lastidx = asc.lastIndexOf;
var asc_HL = asc.HandlersList; var asc_HL = asc.HandlersList;
var asc_TR = asc.CellTextRender;
var asc_incDecFonSize = asc.incDecFonSize; var asc_incDecFonSize = asc.incDecFonSize;
...@@ -184,7 +183,7 @@ ...@@ -184,7 +183,7 @@
// create text render // create text render
t.drawingCtx = new asc.DrawingContext({canvas: t.canvas, units: 1/*pt*/, fmgrGraphics: this.fmgrGraphics, font: this.m_oFont}); t.drawingCtx = new asc.DrawingContext({canvas: t.canvas, units: 1/*pt*/, fmgrGraphics: this.fmgrGraphics, font: this.m_oFont});
t.overlayCtx = new asc.DrawingContext({canvas: t.canvasOverlay, units: 1/*pt*/, fmgrGraphics: this.fmgrGraphics, font: this.m_oFont}); t.overlayCtx = new asc.DrawingContext({canvas: t.canvasOverlay, units: 1/*pt*/, fmgrGraphics: this.fmgrGraphics, font: this.m_oFont});
t.textRender = asc_TR(t.drawingCtx); t.textRender = new asc.CellTextRender(t.drawingCtx);
t.textRender.setDefaultFont(settings.font.clone()); t.textRender.setDefaultFont(settings.font.clone());
// bind event handlers // bind event handlers
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
* Author: Dmitry.Sokolov@avsmedia.net * Author: Dmitry.Sokolov@avsmedia.net
* Date: May 31, 2012 * Date: May 31, 2012
*/ */
( /** (
/**
* @param {jQuery} $ * @param {jQuery} $
* @param {Window} window * @param {Window} window
* @param {undefined} undefined * @param {undefined} undefined
...@@ -37,54 +38,51 @@ ...@@ -37,54 +38,51 @@
* @memberOf Asc * @memberOf Asc
*/ */
function CellTextRender(drawingCtx) { function CellTextRender(drawingCtx) {
if ( !(this instanceof CellTextRender) ) {return new CellTextRender(drawingCtx);}
CellTextRender.superclass.constructor.call(this, drawingCtx); CellTextRender.superclass.constructor.call(this, drawingCtx);
/** @type RegExp */
this.reWordBegining = XRegExp("[^\\p{L}\\p{N}][\\p{L}\\p{N}]", "i");
return this; return this;
} }
var CellTextRender_methods = { asc.extendClass(CellTextRender, asc.StringRender);
/** @type RegExp */ CellTextRender.prototype.getLinesCount = function () {
reWordBegining: XRegExp("[^\\p{L}\\p{N}][\\p{L}\\p{N}]", "i"),
getLinesCount: function () {
return this.lines.length; return this.lines.length;
}, };
getLineInfo: function (index) { CellTextRender.prototype.getLineInfo = function (index) {
return this.lines.length > 0 && index >=0 && index < this.lines.length ? this.lines[index] : null; return this.lines.length > 0 && index >=0 && index < this.lines.length ? this.lines[index] : null;
}, };
calcLineOffset: function (index) { CellTextRender.prototype.calcLineOffset = function (index) {
for (var i = 0, h = 0, l = this.lines; i < index; ++i) { for (var i = 0, h = 0, l = this.lines; i < index; ++i) {
h += l[i].th; h += l[i].th;
} }
return h; return h;
}, };
getPrevChar: function (pos) { CellTextRender.prototype.getPrevChar = function (pos) {
return pos <= 0 ? 0 : pos <= this.chars.length ? pos - 1 : this.chars.length; return pos <= 0 ? 0 : pos <= this.chars.length ? pos - 1 : this.chars.length;
}, };
getNextChar: function (pos) { CellTextRender.prototype.getNextChar = function (pos) {
return pos >= this.chars.length ? this.chars.length : pos >= 0 ? pos + 1 : 0; return pos >= this.chars.length ? this.chars.length : pos >= 0 ? pos + 1 : 0;
}, };
getPrevWord: function (pos) { CellTextRender.prototype.getPrevWord = function (pos) {
var i = asc_lastindexof(this.chars.slice(0, pos), this.reWordBegining); var i = asc_lastindexof(this.chars.slice(0, pos), this.reWordBegining);
return i >= 0 ? i + 1 : 0; return i >= 0 ? i + 1 : 0;
}, };
getNextWord: function (pos) { CellTextRender.prototype.getNextWord = function (pos) {
var i = this.chars.slice(pos).search(this.reWordBegining); var i = this.chars.slice(pos).search(this.reWordBegining);
return pos + (i >= 0 ? i + 1 : 0); return pos + (i >= 0 ? i + 1 : 0);
}, };
getBeginOfLine: function (pos) { CellTextRender.prototype.getBeginOfLine = function (pos) {
pos = pos < 0 ? 0 : Math.min(pos, this.chars.length); pos = pos < 0 ? 0 : Math.min(pos, this.chars.length);
for (var l = this.lines, i = 0; i < l.length; ++i) { for (var l = this.lines, i = 0; i < l.length; ++i) {
...@@ -95,9 +93,9 @@ ...@@ -95,9 +93,9 @@
var lastLine = l.length - 1; var lastLine = l.length - 1;
var lastChar = this.chars.length - 1; var lastChar = this.chars.length - 1;
return this.charWidths[lastChar] !== 0 ? l[lastLine].beg : pos; return this.charWidths[lastChar] !== 0 ? l[lastLine].beg : pos;
}, };
getEndOfLine: function (pos) { CellTextRender.prototype.getEndOfLine = function (pos) {
pos = pos < 0 ? 0 : Math.min(pos, this.chars.length); pos = pos < 0 ? 0 : Math.min(pos, this.chars.length);
var l = this.lines; var l = this.lines;
...@@ -109,17 +107,17 @@ ...@@ -109,17 +107,17 @@
// pos - на последней линии // pos - на последней линии
var lastChar = this.chars.length - 1; var lastChar = this.chars.length - 1;
return pos > lastChar ? pos : lastChar + (this.charWidths[lastChar] !== 0 ? 1 : 0); return pos > lastChar ? pos : lastChar + (this.charWidths[lastChar] !== 0 ? 1 : 0);
}, };
getBeginOfText: function () { CellTextRender.prototype.getBeginOfText = function () {
return 0; return 0;
}, };
getEndOfText: function () { CellTextRender.prototype.getEndOfText = function () {
return this.chars.length; return this.chars.length;
}, };
getPrevLine: function (pos) { CellTextRender.prototype.getPrevLine = function (pos) {
pos = pos < 0 ? 0 : Math.min(pos, this.chars.length); pos = pos < 0 ? 0 : Math.min(pos, this.chars.length);
for (var l = this.lines, i = 0; i < l.length; ++i) { for (var l = this.lines, i = 0; i < l.length; ++i) {
...@@ -134,9 +132,9 @@ ...@@ -134,9 +132,9 @@
return this.charWidths[lastChar] === 0 || l.length < 2 ? return this.charWidths[lastChar] === 0 || l.length < 2 ?
(0 > lastLine ? 0 : l[lastLine].beg) : (0 > lastLine ? 0 : l[lastLine].beg) :
lastChar > 0 ? Math.min(l[lastLine-1].beg + pos - l[lastLine].beg, l[lastLine-1].end) : 0; lastChar > 0 ? Math.min(l[lastLine-1].beg + pos - l[lastLine].beg, l[lastLine-1].end) : 0;
}, };
getNextLine: function (pos) { CellTextRender.prototype.getNextLine = function (pos) {
pos = pos < 0 ? 0 : Math.min(pos, this.chars.length); pos = pos < 0 ? 0 : Math.min(pos, this.chars.length);
var l = this.lines; var l = this.lines;
...@@ -149,9 +147,9 @@ ...@@ -149,9 +147,9 @@
// pos - на последней линии // pos - на последней линии
return this.chars.length; return this.chars.length;
}, };
getCharInfo: function (pos) { CellTextRender.prototype.getCharInfo = function (pos) {
for (var p = this.charProps[pos]; (!p || !p.font) && pos > 0; --pos) { for (var p = this.charProps[pos]; (!p || !p.font) && pos > 0; --pos) {
p = this.charProps[pos - 1]; p = this.charProps[pos - 1];
} }
...@@ -160,14 +158,14 @@ ...@@ -160,14 +158,14 @@
dh: p && p.lm && p.lm.bl2 > 0 ? p.lm.bl2 - p.lm.bl : 0, dh: p && p.lm && p.lm.bl2 > 0 ? p.lm.bl2 - p.lm.bl : 0,
h: p && p.lm ? p.lm.th: 0 h: p && p.lm ? p.lm.th: 0
}; };
}, };
charOffset: function (pos, lineIndex, h) { CellTextRender.prototype.charOffset = function (pos, lineIndex, h) {
var li = this.lines[lineIndex]; var li = this.lines[lineIndex];
return new CharOffset(li.startX + (pos > 0 ? this._calcCharsWidth(li.beg, pos - 1) : 0), h, li.th, lineIndex); return new CharOffset(li.startX + (pos > 0 ? this._calcCharsWidth(li.beg, pos - 1) : 0), h, li.th, lineIndex);
}, };
calcCharOffset: function (pos) { CellTextRender.prototype.calcCharOffset = function (pos) {
var t = this, l = t.lines, i, h, co; var t = this, l = t.lines, i, h, co;
if (l.length < 1) {return null;} if (l.length < 1) {return null;}
...@@ -194,45 +192,39 @@ ...@@ -194,45 +192,39 @@
} }
return co; return co;
}, };
calcCharHeight: function (pos) { CellTextRender.prototype.calcCharHeight = function (pos) {
var t = this; var t = this;
for (var p = t.charProps[pos]; (!p || !p.font) && pos > 0; --pos) { for (var p = t.charProps[pos]; (!p || !p.font) && pos > 0; --pos) {
p = t.charProps[pos - 1]; p = t.charProps[pos - 1];
} }
return t._calcLineMetrics( return t._calcLineMetrics(
p.fsz !== undefined ? p.fsz : p.font.FontSize, p.va, p.fm, t.drawingCtx.getPPIY()); p.fsz !== undefined ? p.fsz : p.font.FontSize, p.va, p.fm, t.drawingCtx.getPPIY());
}, };
getCharsCount: function () { CellTextRender.prototype.getCharsCount = function () {
return this.chars.length; return this.chars.length;
}, };
getChars: function (pos, len) { CellTextRender.prototype.getChars = function (pos, len) {
return this.chars.slice(pos, pos + len); return this.chars.slice(pos, pos + len);
}, };
getCharWidth: function (pos) { CellTextRender.prototype.getCharWidth = function (pos) {
return this.charWidths[pos]; return this.charWidths[pos];
}, };
isLastCharNL: function () { CellTextRender.prototype.isLastCharNL = function () {
return this.charWidths[this.chars.length - 1] === 0; return this.charWidths[this.chars.length - 1] === 0;
}
}; };
asc_inherit(CellTextRender, asc.StringRender, CellTextRender_methods);
/* /*
* Export * Export
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
*/ */
window["Asc"].CellTextRender = CellTextRender; window["Asc"].CellTextRender = CellTextRender;
} }
)(jQuery, window); )(jQuery, window);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment