Revision: 3765 http://vexi.svn.sourceforge.net/vexi/?rev=3765&view=rev Author: clrg Date: 2009-12-11 01:31:10 +0000 (Fri, 11 Dec 2009)
Log Message: ----------- Add support for date/time format preferences Modified Paths: -------------- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/layout/cardpane.t trunk/widgets/org.vexi.widgets/src/org/vexi/theme/classic/datefield.t trunk/widgets/org.vexi.widgets/src/org/vexi/theme/classic/timefield.t trunk/widgets/org.vexi.widgets/src/vexi/util/digit.t Added Paths: ----------- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/layout/flow.t trunk/widgets/org.vexi.widgets/src/vexi/conf/settings.t Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/layout/cardpane.t =================================================================== --- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/layout/cardpane.t 2009-12-08 21:04:55 UTC (rev 3764) +++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/layout/cardpane.t 2009-12-11 01:31:10 UTC (rev 3765) @@ -135,7 +135,9 @@ // hide the previously shown card and show the new one showlock = true; - if (show) show.display = false; + if (show) { + show.display = false; + } card.display = true; showlock = false; @@ -169,8 +171,9 @@ /** write trap to show the next card in the cardpane */ static.ncWriteFunc = function(v) { - if (trapee.nextcard) + if (trapee.nextcard) { trapee.show = trapee.nextcard; + } cascade = v; } Added: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/layout/flow.t =================================================================== --- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/layout/flow.t (rev 0) +++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/layout/flow.t 2009-12-11 01:31:10 UTC (rev 3765) @@ -0,0 +1,223 @@ +<!-- Copyright 2009 - see COPYING for details [LGPL] --> + +<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns="org.vexi.lib.role"> + <meta:doc> + <author>Charles Goodwin</author> + <notes>A box that flows children against its orient</notes> + <todo> + * support right to left + * optionally defer reflow + * more thorough documentation + </todo> + </meta:doc> + + <polarizable /> + <ui:box align="topleft" layout="layer"> + + thisbox.flow = true; + thisbox.hardwrap = 0; + + thisbox.v_ALIGN_NEAR = true; + thisbox.v_ALIGN_FAR = false; + + // assign static trap functions + thisbox.Children ++= static.ChildrenWrite; + thisbox.align ++= static.alignWrite; + thisbox.flow ++= static.flowWrite; + thisbox.orient ++= static.invokeReflow; + thisbox.hardwrap ++= static.hardwrapWrite; + thisbox.reflow ++= static.invokeReflow; + + </ui:box> + + /** generic trap to invoke reflow */ + static.invokeReflow = function(v) { + cascade = v; + var t = trapee; + static.reflowBlock(t, t.dim, t.pos, t.flip(t.pos)); + } + + /** synchronizes the block and it's contents with it's current size */ + static.reflowBlock = function(b) { + // do not do anything with 0 sized flow parent + if (b.flow and b[b.dim] == 0 and b.hardwrap == 0) { + return; + } + + var dim = b.dim; + var pos = b.pos; + var f_dim = b.flip(dim); + var f_pos = b.flip(pos); + var contentdim = b.contentdim; + + var cur_dim = 0; // dimension bounds imposed by placing children + var cur_pos = 0; // current position to assign to children + var cur_f_pos = 0; // current flip(position) to assign to children + var cur_f_dim = 0; // current flip(dim) of line + var eol = false; // end of line indicator + var sol = 0; // index of child at start of line + var offset; // used to store alignment offset + var i = 0; // index reference + var c, prevtype; + + // for efficiency, only fetch these once + var numchildren = b.numchildren; + var align_near = b.v_ALIGN_NEAR; + var offset_div = b.v_ALIGN_FAR ? 1 : 2; + var fontheight = b.fontheight; + var wrap_dim = b.hardwrap ? b.hardwrap : b[dim]; + + // single line behaviour + if (!b.flow) { + for (var j=0; numchildren>j; j++) { + c = b[j]; + c[pos] = cur_pos; + c[f_pos] = 0; + cur_pos += c[contentdim]; + c[dim] = c[contentdim]; + if (c[f_contentdim] > cur_f_dim) { + cur_f_dim = c[f_contentdim]; + } + } + if (!align_near) { + offset = (wrap_dim-cur_pos) / offset_div; + for (var j=0; numchildren>j; j++) { + b[j][pos] += offset; + } + } + b[f_mindim] = cur_f_dim; + b[mindim] = cur_pos; + return; + } + + // multiline lay out words + if (numchildren) do { + w = b[i]; + // deal with whitespace + if (1>=w.chartype) { + if (w.linebreak) { + w[pos] = cur_pos; + w[f_pos] = cur_f_pos; + eol = true; + } else if (cur_pos + w[contentdim] > wrap_dim) { + w[dim] = 0; + } else { + w[dim] = w[contentdim]; + w[pos] = cur_pos; + w[f_pos] = cur_f_pos; + cur_pos += w[contentdim]; + } + // normal words + } else { + if (cur_pos + w[contentdim] > wrap_dim and cur_pos > 0) { + eol = true; + i--; + } else { + w[dim] = w[contentdim]; + w[pos] = cur_pos; + w[f_pos] = cur_f_pos; + cur_pos += w[contentdim]; + } + } + // line height + if (!eol and w.minheight > cur_height) { + cur_height = w.minheight; + } + // move onto next word + i++; + // process completed lines + if (eol or i==numchildren) { + offset = align_near ? 0 : ((wrap_dim-cur_pos) / offset_div); + for (var j=sol; i>j; j++) { + w = b[j]; + w[f_dim] = cur_height; + w[pos] += offset; + } + if (cur_pos > cur_dim) { + cur_dim = cur_pos; + } + cur_pos = 0; + cur_f_pos += cur_f_dim; + cur_f_dim = 0; // fontheight + eol = false; + sol = i; + } + } while (numchildren>i); + + // set block height + b[f_dim] = cur_f_pos > 0 ? cur_f_pos : trapee[min_f_dim]; + if (b.hardwrap) { + b[dim] = cur_dim; + } + } + + // trap functions //////////////// + + /** trap: update new children to identify themselves as the current word */ + static.ChildrenWrite = function(v) { + // child added + if (v != null) { + v.Enter --= trapee.activeTrap; + v.Enter ++= trapee.activeTrap; + // child removed + } else { + var c = trapee[arguments.trapname]; + c.Enter --= trapee.activeTrap; + } + // need to do this after removal for c to be valid + cascade = v; + } + + /** trap: set whether this is a flowing (multiline) text block or not (singleline) */ + static.flowWrite = function(v) { + cascade = v; + var t = trapee; + if (v) { + if (!trapee.hardwrap) { + t[t.dim] ++= static.invokeReflow; + } + t[t.mindim] = 0; + } else { + t[t.dim] --= static.invokeReflow; + } + + t.reflow = true; + } + + /** trap to set the textual alignment of this block */ + static.textalignWrite = function(v) { + cascade = v; + switch(v) { + case "left": + trapee.ALIGN_NEAR = true; + trapee.ALIGN_FAR = false; + break; + + case "center": + trapee.ALIGN_NEAR = false; + trapee.ALIGN_FAR = false; + break; + + case "right": + trapee.ALIGN_NEAR = false; + trapee.ALIGN_FAR = true; + break; + } + } + + /** reset block dimensions if wrapwidth is unset */ + static.hardwrapWrite = function(v) { + cascade = v; + var t = trapee; + // if v==0 then v==false - 0 or null unsets + if (v) { + t[t.dim] --= static.invokeReflow; + } else { + t[t.mindim] = 0; + t[t.maxdim] = vexi.ui.maxdim; + t[t.dim] ++= static.invokeReflow; + } + t.reflow = true; + } + +</vexi> Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/theme/classic/datefield.t =================================================================== --- trunk/widgets/org.vexi.widgets/src/org/vexi/theme/classic/datefield.t 2009-12-08 21:04:55 UTC (rev 3764) +++ trunk/widgets/org.vexi.widgets/src/org/vexi/theme/classic/datefield.t 2009-12-11 01:31:10 UTC (rev 3765) @@ -1,7 +1,10 @@ <!-- Copyright 2009 - see COPYING for details [LGPL] --> <vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns="vexi.theme" - xmlns:lib="org.vexi.lib" xmlns:lay="vexi.layout" xmlns:util="vexi.util"> + xmlns:conf="vexi.conf" + xmlns:lib="org.vexi.lib" + xmlns:lay="vexi.layout" + xmlns:util="vexi.util"> <meta:doc> <author>Charles Goodwin</author> </meta:doc> @@ -38,11 +41,6 @@ <datepicker id="datepicker" minwidth="200" minheight="160" shrink="true" /> </lay:border> - thisbox.valueformat = "YYYYMMDD"; - thisbox.valueseparator = "-"; - thisbox.textformat = "DDMMYYYY"; - thisbox.textseparator = "/"; - thisbox.datepick = $datepicker; thisbox.dateview = $dateview; thisbox.dayview = $day; @@ -67,13 +65,10 @@ thisbox.textformat ++= static.textformatWrite; thisbox.valueformat ++= static.valueformatWrite; - thisbox.enabled ++= function(v) { - cascade = v; - $select.enabled = v; - $more.enabled = v; - $less.enabled = v; - $bg.fill = v ? "white" : "#d4d0c8"; - } + thisbox.valueformat = conf.settings..date_valueformat; + thisbox.valueseparator = "-"; + thisbox.textformat = conf.settings..date_textformat; + thisbox.textseparator = "/"; //////// // button actions @@ -88,9 +83,12 @@ $year.Press1 ++= selectPart; $more.action ++= function(v) { - if (year == null) { value = "today"; return; } - else if (selected == $day) { - if (month==null) month = 1; + if (year == null) { + value = "today"; + } else if (selected == $day) { + if (month==null) { + month = 1; + } day = day==null ? 1 : day+1; } else if (selected == $month) { month = month==null ? 1 : month+1; @@ -101,9 +99,12 @@ } $less.action ++= function(v) { - if (year == null) { value = "today"; return; } - else if (selected == $day) { - if (month==null) month = 12; + if (year == null) { + value = "today"; + } else if (selected == $day) { + if (month==null) { + month = 12; + } day = day==null ? monthdays : day-1; } else if (selected == $month) { month = month==null ? 12 : month-1; @@ -151,16 +152,28 @@ finally { $editview.display = false; } } + thisbox.enabled ++= function(v) { + cascade = v; + $select.enabled = v; + $more.enabled = v; + $less.enabled = v; + $bg.fill = v ? "white" : "#d4d0c8"; + } + thisbox.focused ++= function(v) { cascade = v; - if (!focused and $editview.display) editToValue(); + if (!focused and $editview.display) { + editToValue(); + } } /** makes sure we stay the same width */ $editview.display ++= function(v) { cascade = v; $edit.focused = v; - if (v) $edit.v_edit.text = ""; + if (v) { + $edit.v_edit.text = ""; + } $dateview.maxheight = v ? 0 : vexi.ui.maxdim; } @@ -175,36 +188,58 @@ } } else { var x = v.charCodeAt(0); - // accept all non-alpha character presses - if ((65>x or x>90) and (97>x or x>122)) + if ((65>x or x>90) and (97>x or x>122)) { + // accept all non-alpha character presses cascade = v; + } } // cascades already decided return; } thisbox.KeyPressed ++= function(v) { - // delegate to datepicker if it's open if (popped) { + // delegate to datepicker if it's open $datepicker.KeyPressed = v; return; } - // delegate to editview if it's open if ($editview.display) { + // delegate to editview if it's open $edit.v_edit.KeyPressed = v; return; } - // timeview still on display if (v.length>1) { + // timeview still on display var si = dateview.indexof(selected); switch(v) { - case "left": if (si>0) selected = $dateview[si-2]; break; - case "right": if (4>si) selected = $dateview[si+2]; break; - case "up": $more.action = true; break; - case "down": $less.action = true; break; - case "space": $select.action = true; break; - case "enter": if (value==null) value = "today"; break; - case "back_space": case "delete": value = null; break; + case "left": + if (si>0) { + selected = $dateview[si-2]; + } + break; + case "right": + if (4>si) { + selected = $dateview[si+2]; + } + break; + case "up": + $more.action = true; + break; + case "down": + $less.action = true; + break; + case "space": + $select.action = true; + break; + case "enter": + if (value==null) { + value = "today"; + } + break; + case "back_space": + case "delete": + value = null; + break; } } else { var x = v.charCodeAt(0); @@ -282,9 +317,17 @@ var y = trapee.year; var m = trapee.month; var d = trapee.day; - if (y==null or m==null or d==null) return ""; - if (10>m) m = "0"+m; - if (10>d) d = "0"+d; + if (y==null or m==null or d==null) { + return ""; + } + if (10>m) { + // M->MM + m = "0"+m; + } + if (10>d) { + // D->DD + d = "0"+d; + } switch (f) { case "YYYYMMDD": return ""+ y + s + m + s + d; case "DDMMYYYY": return ""+ d + s + m + s + y; @@ -294,7 +337,10 @@ } static.textWrite = function(v) { - if (v == "") { trapee.value = null; return; } + if (v == "") { + trapee.value = null; + return; + } trapee.parseDate(v, trapee.textformat, trapee); } Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/theme/classic/timefield.t =================================================================== --- trunk/widgets/org.vexi.widgets/src/org/vexi/theme/classic/timefield.t 2009-12-08 21:04:55 UTC (rev 3764) +++ trunk/widgets/org.vexi.widgets/src/org/vexi/theme/classic/timefield.t 2009-12-11 01:31:10 UTC (rev 3765) @@ -2,6 +2,7 @@ <vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns="vexi.theme" xmlns:lay="vexi.layout" + xmlns:conf="vexi.conf" xmlns:util="vexi.util" xmlns:role="org.vexi.lib.role" xmlns:text="org.vexi.lib.text"> @@ -16,9 +17,9 @@ <lay:pad id="bg" fill="white" orient="vertical" padding="3"> <ui:box id="timeview"> <util:digit id="hours" /> - <util:digit fieldsize="1" shrink="true">text=":";</util:digit> + <util:digit id="sep1" fieldsize="1" shrink="true">text=":";</util:digit> <util:digit id="mins" /> - <util:digit fieldsize="1" shrink="true">text=":";</util:digit> + <util:digit id="sep2" fieldsize="1" shrink="true">text=":";</util:digit> <util:digit id="period" digit="M" /> </ui:box> <ui:box id="editview" display="false"> @@ -38,21 +39,33 @@ thisbox.v_textbox = false; + thisbox.use24hours = conf.settings..time_use24hours; thisbox.period = null; thisbox.hours = null; thisbox.mins = null; //thisbox.secs; thisbox.setTime = function() { + if (format=="12") { + $period.display = true; + $sep2.display = true; + $period.text = hours>11 and hours!=0?"PM":"AM"; + } else { + $period.display = false; + $sep2.display = false; + } if (hours==null or mins==null) { $period.text = "AM"; $hours.text = "--"; $mins.text = "--"; } else { - $period.text = hours>11 and hours!=0?"PM":"AM"; - var h = (hours>12?hours-12:hours); - h = h==0?12:h; - $hours.text = (h>9?"":"0")+h; + if (format=="12") { + var h = (hours>12?hours-12:hours); + h = h==0?12:h; + $hours.text = (h>9?"":"0")+h; + } else { + $hours.text = (hours>9?"":"0")+hours; + } $mins.text = (mins>9?"":"0")+mins; } } @@ -60,7 +73,7 @@ //////// // public properties - thisbox.format ++= static.setTime; + thisbox.use24hours ++= static.setTime; thisbox.hours ++= static.hoursWrite; thisbox.mins ++= static.minsWrite; thisbox.period ++= static.periodWrite; @@ -94,12 +107,18 @@ $more.action ++= function(v) { if (hours==null or mins==null) { - if (hours==null) hours = 0; - if (mins==null) mins = 0; + if (hours==null) { + hours = 0; + } + if (mins==null) { + mins = 0; + } return; } if (selected == $period) { - if (12>hours) hours += 12; + if (12>hours) { + hours += 12; + } } else if (selected == $hours) { hours = hours+1; } else if (selected == $mins) { @@ -110,11 +129,15 @@ $less.action ++= function(v) { if (selected == $period) { - if (hours>11) hours -= 12; + if (hours>11) { + hours -= 12; + } } else if (selected == $hours) { hours = hours==null ? 23 : hours-1; } else if (selected == $mins) { - if (hours == null) hours = 23; + if (hours == null) { + hours = 23; + } mins = mins==null ? 59 : mins-1; } return; @@ -135,7 +158,9 @@ thisbox.focused ++= function(v) { cascade = v; - if (!focused and $editview.display) editToValue(); + if (!focused and $editview.display) { + editToValue(); + } } /** makes sure we stay the same width */ @@ -160,17 +185,17 @@ } } else { var x = v.charCodeAt(0); - // accept numbers if (x>47 and 58>x) { + // accept numbers cascade = v; - // set PM period using p/P } else if (v=='p' or v=='P') { + // set PM period using p/P $editperiod.text = "PM"; - // set AM period using a/A } else if (v=='a' or v=='A') { + // set AM period using a/A $editperiod.text = "AM"; - // accept all other alpha-character presses } else if ((65>x or x>90) and (97>x or x>122)) { + // accept all other alpha-character presses cascade = v; } } @@ -179,20 +204,35 @@ } thisbox.KeyPressed ++= function(v) { - // delegate to editview if it's open if ($editview.display) { + // delegate to editview if it's open $edit.v_edit.KeyPressed = v; return; } - // timeview still on display if (v.length>1) { + // timeview still on display switch(v) { - case "left": selected = (selected==$period?$mins:$hours); break; - case "right": selected = (selected==$hours?$mins:$period); break; - case "up": $more.action = true; break; - case "down": $less.action = true; break; - case "enter": if (value==null) value = "now"; break; - case "back_space": case "delete": value = null; break; + case "left": + selected = (selected==$period?$mins:$hours); + break; + case "right": + selected = (selected==$hours?$mins:$period); + break; + case "up": + $more.action = true; + break; + case "down": + $less.action = true; + break; + case "enter": + if (value==null) { + value = "now"; + } + break; + case "back_space": + case "delete": + value = null; + break; } } else { $editview.display = true; @@ -209,7 +249,9 @@ } // initialize - if (!arguments[0]) value = null; + if (!arguments[0]) { + value = null; + } </bevel> @@ -218,8 +260,12 @@ /** constrain hours to 24 */ static.hoursWrite = function(v) { - while (v>23) v = v-24; - while (0>v) v = v+24; + while (v>23) { + v = v-24; + } + while (0>v) { + v = v+24; + } cascade = v; trapee.setTime(); } @@ -227,9 +273,17 @@ /** contrain mins to 60 and adjust hours */ static.minsWrite = function(v) { var h = trapee.hours; - while (v>59) { v -= 60; h++; } - while (0>v) { v += 60; h--; } - if (h!=trapee.hours) trapee.hours = h; + while (v>59) { + v -= 60; + h++; + } + while (0>v) { + v += 60; + h--; + } + if (h!=trapee.hours) { + trapee.hours = h; + } cascade = v; trapee.setTime(); } @@ -242,11 +296,13 @@ /** invoke focus/selected visual effect */ static.selectWrite = function(v) { - if (trapee.selected and trapee.selected != v) + if (trapee.selected and trapee.selected != v) { trapee.selected.selected = false; + } cascade = v; - if (trapee.selected) + if (trapee.selected) { trapee.selected.selected = trapee.focused; + } } /** returns the time as a string */ @@ -254,14 +310,19 @@ var h = trapee.hours; var m = trapee.mins; var s = trapee.secs; - if (h==null or m==null) return ""; + if (h==null or m==null) { + return ""; + } return (h>9?"":"0")+h+":"+(m>9?"":"0")+m+":00";//+(s>0?"":"0")+s; } /** for handling writes as a string */ static.textWrite = function(v) { - // reset the time - if (v == "") { trapee.value = null; return; } + if (v == "") { + // reset the time + trapee.value = null; + return; + } // string value var c = v.charCodeAt(0); @@ -300,7 +361,9 @@ //for (var c = v.charCodeAt(i); c>57 or 49>c; c = v.charCodeAt(++i)) { /* skip 0s and non-numbers */ } //for (var c = v.charCodeAt(i); c>47 and 58>c; c = v.charCodeAt(++i)) s2 = s2 + v.charAt(i); if (s0 == "" ) { - if (s1 == "") throw "rethrow"; + if (s1 == "") { + throw "rethrow"; + } s0 = s1; s1 = ""; } @@ -309,7 +372,9 @@ // shorthand for dealing with 2330 or 11 or 230 or 3pm trapee.hours = vexi.string.parseInt(3>l?s0:s0.substring(0,l==3?1:2), 10); trapee.mins = 3>l?0:vexi.string.parseInt(s0.substring(l==3?1:2), 10); - if (12>trapee.hours and pm) trapee.hours += 12; + if (12>trapee.hours and pm) { + trapee.hours += 12; + } } else { var h = vexi.string.parseInt(s0, 10); var m = vexi.string.parseInt(s1, 10); Added: trunk/widgets/org.vexi.widgets/src/vexi/conf/settings.t =================================================================== --- trunk/widgets/org.vexi.widgets/src/vexi/conf/settings.t (rev 0) +++ trunk/widgets/org.vexi.widgets/src/vexi/conf/settings.t 2009-12-11 01:31:10 UTC (rev 3765) @@ -0,0 +1,14 @@ +<!-- Copyright 2009 - see COPYING for details [LGPL] --> + +<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta"> + <meta:doc> + <author>Charles Goodwin</author> + </meta:doc> + + <ui:box /> + + static.date_textformat = "DDMMYYYY"; + static.date_valueformat = "YYYYMMDD"; + static.time_use24hours = false; + +</vexi> Modified: trunk/widgets/org.vexi.widgets/src/vexi/util/digit.t =================================================================== --- trunk/widgets/org.vexi.widgets/src/vexi/util/digit.t 2009-12-08 21:04:55 UTC (rev 3764) +++ trunk/widgets/org.vexi.widgets/src/vexi/util/digit.t 2009-12-11 01:31:10 UTC (rev 3765) @@ -38,8 +38,9 @@ static.forward = function(v) { cascade = v; var t = trapee; - for (var i=0; t.numchildren>i; i++) + for (var i=0; t.numchildren>i; i++) { t[i][trapname] = v; + } } static.fieldsizeWrite = function(v) { @@ -72,8 +73,9 @@ static.textRead = function() { var ret = ""; var t = trapee; - for (var i=0; t.numchildren>i; i++) + for (var i=0; t.numchildren>i; i++) { ret = ret + t[i].text; + } return ret; } @@ -81,12 +83,20 @@ var t = trapee; var f = t.fieldsize; if (v==null) { - for (var i=0; f>i; i++) t[i].text = '-'; + for (var i=0; f>i; i++) { + t[i].text = '-'; + } } else { var choff = f-v.length; - if (0>choff) throw "Text input ("+v.length+") larger than fieldsize ("+f+")"; - for (var i=0; choff>i; i++) t[i].text = '0'; - for (var i=choff; f>i; i++) t[i].text = v.charAt(i-choff); + if (0>choff) { + throw "Text input ("+v.length+") larger than fieldsize ("+f+")"; + } + for (var i=0; choff>i; i++) { + t[i].text = '0'; + } + for (var i=choff; f>i; i++) { + t[i].text = v.charAt(i-choff); + } } return; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Return on Information: Google Enterprise Search pays you back Get the facts. http://p.sf.net/sfu/google-dev2dev _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn