initial checkin
[org.ibex.widgets.git] / src / ibex / lib / focusable.t
1 <!-- Copyright 2004 - see COPYING for details [LGPL] -->
2
3 <ibex>
4     <meta:doc>
5         See ibex.theme.focusable for more details
6
7         <author>Charles Goodwin</author>
8         <author>David Crawshaw</author>
9     </meta:doc>
10
11     <ui:box>
12
13         thisbox.enabled;    // whether a focusable is enabled
14         thisbox.focusable;  // whether a focusable may be focused
15         thisbox.focused;    // whether a focusable is focused
16         thisbox.nextfocus;  // read for the focus after thisbox on the surface
17         thisbox.prevfocus;  // read for the focus before thisbox on the surface
18
19         // private function to assign to traps
20         var checkfocus = function(v) { if (!v and focused) focused = false; }
21
22         enabled ++= checkfocus;     // disabling prevents focus
23         focusable ++= checkfocus;   // making unfocusable prevents focus
24
25         // read trap to return focusable state
26         focusable ++= function() { return enabled and cascade; }
27
28         // write trap to set focused state
29         focused ++= function(v) {
30             if (v and surface and focusable) {
31                 if (surface.focus) {
32                     surface.focus.focused = false;
33                 }
34                 surface.focus = thisbox;
35             }
36             else if (!v and surface and surface.focus == thisbox)
37                 surface.focus = null;
38             else cascade = false;
39         }
40
41         // read trap to return the focus after thisbox on the surface
42         nextfocus ++= function() { return surface.nextFocus(thisbox); }
43
44         // read trap to return the focus before thisbox on the surface
45         prevfocus ++= function() { return surface.prevFocus(thisbox); }
46
47         // write trap to handle surface change
48         surface ++= function(v) {
49             // drop from current surface if there is one
50             if (cascade) cascade.dropFocus(thisbox);
51
52             // add to new surface
53             v.addFocus(thisbox);
54         }
55
56         // write trap to focus on Press1
57         Press1 ++= function(v) { if (!focused and focusable) focused = true; }
58
59     </ui:box>
60 </ibex>