X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fbuiltin%2Fedit_lib.ibex;fp=src%2Forg%2Fxwt%2Fbuiltin%2Fedit_lib.xwt;h=c842594e9d3e69e7034c860bff34d7b6ef2d14e9;hp=abcc8eb137da886fba2dad0e01a67ecb62159a84;hb=3591b88b94a6bb378af3d4abe6eb5233ce583104;hpb=de378041d5ca2aca1a2b5a31ef15ae90a86c977f diff --git a/src/org/xwt/builtin/edit_lib.xwt b/src/org/ibex/builtin/edit_lib.ibex similarity index 92% rename from src/org/xwt/builtin/edit_lib.xwt rename to src/org/ibex/builtin/edit_lib.ibex index abcc8eb..c842594 100644 --- a/src/org/xwt/builtin/edit_lib.xwt +++ b/src/org/ibex/builtin/edit_lib.ibex @@ -1,11 +1,11 @@ - + var cursors = []; var worddivider = [' ', '-']; - xwt.thread = function() { - while (true) { xwt.sleep(1000); for (var i=0; cursors.length > i; i++) { cursors[i].blink = !cursors[i].blink; } } + ibex.thread = function() { + while (true) { ibex.sleep(1000); for (var i=0; cursors.length > i; i++) { cursors[i].blink = !cursors[i].blink; } } } // Returns the number of characters the pixel position pos is into text t. end is the pixel with of t. @@ -19,20 +19,20 @@ if (pxpos >= pxlen) return t.length; // Inital guess based on average character width. - var guessch = xwt.math.min(t.length, xwt.math.floor(pxpos / (pxlen / t.length))); - var guesspx = xwt.textwidth(tfont, t.substring(0, guessch)); + var guessch = ibex.math.min(t.length, ibex.math.floor(pxpos / (pxlen / t.length))); + var guesspx = ibex.textwidth(tfont, t.substring(0, guessch)); if (guesspx > pxpos) { while (guesspx > pxpos) { // Textwidth of individual character must account for font kerning. - guesspx -= xwt.textwidth(tfont, t.substring(guessch -1, guessch +1)) - xwt.textwidth(tfont, t.charAt(guessch)); + guesspx -= ibex.textwidth(tfont, t.substring(guessch -1, guessch +1)) - ibex.textwidth(tfont, t.charAt(guessch)); guessch--; } } else if (pxpos > guesspx) { while (pxpos > guesspx) { guessch++; if (guessch >= t.length) break; - guesspx += xwt.textwidth(tfont, t.substring(guessch -1, guessch+1)) - xwt.textwidth(tfont, t.charAt(guessch)); + guesspx += ibex.textwidth(tfont, t.substring(guessch -1, guessch+1)) - ibex.textwidth(tfont, t.charAt(guessch)); } guessch--; // Round down. } @@ -60,7 +60,7 @@ _wrap = function(v) { // Used on _SizeChange if wrap needs to know. var resize = function() { - xwt.thread = function() { + ibex.thread = function() { // TODO: Only run this change if the width is different. for (var i = 0; content.numchildren > i; i++) { content[i].fulltext = content[i].fulltext; } }; @@ -69,14 +69,14 @@ if (multiline and v == "line") { content.vshrink = true; content.hshrink = false; - content.maxwidth = xwt.maxdim; // Must reset maxwidth after shrink = true. + content.maxwidth = ibex.maxdim; // Must reset maxwidth after shrink = true. ref_fulltext = fulltext_linewrap; _SizeChange = resize; } else if (multiline and v == "word") { content.vshrink = true; content.hshrink = false; - content.maxwidth = xwt.maxdim; + content.maxwidth = ibex.maxdim; ref_fulltext = fulltext_wordwrap; _SizeChange = resize; @@ -97,7 +97,7 @@ _selecttextcolor = function(v) { sel1.textcolor = sel2.textcolor = v; } _font = function(f) { - lineheight = xwt.textheight(f); + lineheight = ibex.textheight(f); if (lineheight > 0) { minheight = content.minheight = linecount * lineheight; } for (var i=0; content.numchildren > i; i++) { content[i].font = f; } sel1.font = sel2.font = curs.font = f; @@ -166,7 +166,7 @@ // Limit checking. if (limit > 0 and length + t.length > limit) { - xwt.println("WARNING: Limit applied on inserted text."); + ibex.println("WARNING: Limit applied on inserted text."); t = t.substring(0, limit - length); } @@ -196,7 +196,7 @@ moveCursor(cl + newT.length - 1, newT[newT.length -1].length); } else { - xwt.println("WARNING: Single line edit, ignoring all text after the carrige return."); + ibex.println("WARNING: Single line edit, ignoring all text after the carrige return."); content[0].fulltext = content[0].fulltext.substring(0, cx) + newT[0] + content[0].fulltext.substring(cx); moveCursor(0, cx + newT[0].length); @@ -344,12 +344,12 @@ if (sel1.cl == cl1) { for (var i=sel1.cy+1; cy1 >= i; i++) { content[cl1][i].selected = false; } } else if (cl1 > sel1.cl) { - for (var i=xwt.math.max(0, sel1.cl); cl1 >= i; i++) { content[i].selected = false; } + for (var i=ibex.math.max(0, sel1.cl); cl1 >= i; i++) { content[i].selected = false; } } if (sel2.cl == cl2) { for (var i=sel2.cy-1; i >= cy2; i--) { content[cl2][i].selected = false; } } else if (sel2.cl > cl2) { - for (var i=xwt.math.max(0, sel2.cl); i >= cl2; i--) { content[i].selected = false; } + for (var i=ibex.math.max(0, sel2.cl); i >= cl2; i--) { content[i].selected = false; } } // Store point data. @@ -358,7 +358,7 @@ // Place first select box. sel1.y = content[cl1].y + content[cl1][cy1].y; - sel1.x = xwt.textwidth(font, content[cl1][cy1].text.substring(0, px1)); + sel1.x = ibex.textwidth(font, content[cl1][cy1].text.substring(0, px1)); if (cl1 == cl2 and cy1 == cy2) { // Only the first select box is required. @@ -405,7 +405,7 @@ // Move the cursor. curs.cl = cl; curs.cx = cx; curs.cy = cy; curs.px = px; curs.y = content.y + content[cl].y + (lineheight * cy); - curs.x = content.x + xwt.textwidth(font, content[cl][cy].text.substring(0, px)) -1; + curs.x = content.x + ibex.textwidth(font, content[cl][cy].text.substring(0, px)) -1; curs.blink = false; // Speed Hack: As the cursor has values that match the names used by the focusarea variable, we @@ -417,7 +417,7 @@ // Returns a box ready to be a full line, armed with the current fulltext trap. var newLine = function() { - var b = xwt.newBox(); + var b = ibex.newBox(); b.color = color; b.align = "topleft"; @@ -437,7 +437,7 @@ // Returns a box ready to be a soft line; one of the components of a line. var newSoftline = function() { - var b = xwt.newBox(); + var b = ibex.newBox(); b._selected = function(s) { arguments.trapee.color = s ? selectcolor : color; @@ -487,7 +487,7 @@ if (i == arguments.trapee.numchildren) { arguments.trapee[i] = newSoftline(); } // TODO: Switch to getpos - var nl = static.getpos(t, cw, xwt.textwidth(font, t), font); + var nl = static.getpos(t, cw, ibex.textwidth(font, t), font); arguments.trapee[i].text = t.substring(0, nl); t = t.substring(nl); } @@ -507,7 +507,7 @@ for (; t.length > 0; i++) { if (i == arguments.trapee.numchildren) { arguments.trapee[i] = newSoftline(); } - var nl = static.getpos(t, cw, xwt.textwidth(font, t), font); + var nl = static.getpos(t, cw, ibex.textwidth(font, t), font); var rl = nl; if (t.length > nl) { @@ -538,7 +538,7 @@ root._Move = function() { // Update Selection. - var linediff = xwt.math.floor((content.mousey - (content[sel.cl].y + content[sel.cl][sel.cy].y)) / lineheight); + var linediff = ibex.math.floor((content.mousey - (content[sel.cl].y + content[sel.cl][sel.cy].y)) / lineheight); var cl = sel.cl; var cy = sel.cy; @@ -572,7 +572,7 @@ // Set selection root position. clearSelection(); sel.cl = content.indexof(refline); - sel.cy = xwt.math.floor(refline.mousey / lineheight); + sel.cy = ibex.math.floor(refline.mousey / lineheight); if (sel.cy >= refline.numchildren) sel.cy = refline.numchildren -1; else if (0 > sel.cy) sel.cy = 0; @@ -611,7 +611,7 @@ content[curs.cl +1] = newLine(); content[curs.cl +1].fulltext = content[curs.cl].fulltext.substring(curs.cx); content[curs.cl].fulltext = content[curs.cl].fulltext.substring(0, curs.cx); - xwt.thread = function() { moveCursor(curs.cl +1, 0); } + ibex.thread = function() { moveCursor(curs.cl +1, 0); } } key_back_space = function() { @@ -652,7 +652,7 @@ } else { content[curs.cl].fulltext = content[curs.cl].fulltext.substring(0, curs.cx) + k + content[curs.cl].fulltext.substring(curs.cx); - xwt.thread = function() { moveCursor(curs.cl, curs.cx+1); } + ibex.thread = function() { moveCursor(curs.cl, curs.cx+1); } textChanged = true; } @@ -677,4 +677,4 @@ } - +