r20517: re-add cleaned-up webapps
[kai/samba.git] / webapps / qooxdoo-0.6.3-sdk / frontend / framework / source / class / qx / ui / toolbar / ToolBar.js
1 /* ************************************************************************
2
3    qooxdoo - the new era of web development
4
5    http://qooxdoo.org
6
7    Copyright:
8      2004-2006 by 1&1 Internet AG, Germany, http://www.1and1.org
9
10    License:
11      LGPL 2.1: http://www.gnu.org/licenses/lgpl.html
12
13    Authors:
14      * Sebastian Werner (wpbasti)
15      * Andreas Ecker (ecker)
16
17 ************************************************************************ */
18
19 /* ************************************************************************
20
21 #module(ui_toolbar)
22
23 ************************************************************************ */
24
25 qx.OO.defineClass("qx.ui.toolbar.ToolBar", qx.ui.layout.HorizontalBoxLayout,
26 function()
27 {
28   qx.ui.layout.HorizontalBoxLayout.call(this);
29
30   this.addEventListener("keypress", this._onkeypress);
31 });
32
33
34
35 /*
36 ---------------------------------------------------------------------------
37   PROPERTIES
38 ---------------------------------------------------------------------------
39 */
40
41 qx.OO.addProperty({ name : "openMenu", type : "object", instance : "qx.ui.menu.Menu" });
42
43 /*!
44   Appearance of the widget
45 */
46 qx.OO.changeProperty({ name : "appearance", type : "string", defaultValue : "toolbar" });
47
48
49
50
51
52
53
54
55
56 /*
57 ---------------------------------------------------------------------------
58   UTILITIES
59 ---------------------------------------------------------------------------
60 */
61
62 qx.Proto.getAllButtons = function()
63 {
64   var vChildren = this.getChildren();
65   var vLength = vChildren.length;
66   var vDeepChildren = [];
67   var vCurrent;
68
69   for (var i=0; i<vLength; i++)
70   {
71     vCurrent = vChildren[i];
72
73     if (vCurrent instanceof qx.ui.toolbar.MenuButton)
74     {
75       vDeepChildren.push(vCurrent);
76     }
77     else if (vCurrent instanceof qx.ui.toolbar.Part)
78     {
79       vDeepChildren = vDeepChildren.concat(vCurrent.getChildren());
80     }
81   }
82
83   return vDeepChildren;
84 }
85
86
87
88
89
90
91
92 /*
93 ---------------------------------------------------------------------------
94   EVENTS
95 ---------------------------------------------------------------------------
96 */
97
98 /*!
99   Wraps key events to target functions
100 */
101 qx.Proto._onkeypress = function(e)
102 {
103   switch(e.getKeyIdentifier())
104   {
105     case "Left":
106       return this._onkeypress_left();
107
108     case "Right":
109       return this._onkeypress_right();
110   }
111 }
112
113 qx.Proto._onkeypress_left = function()
114 {
115   var vMenu = this.getOpenMenu();
116   if (!vMenu) {
117     return;
118   }
119
120   var vOpener = vMenu.getOpener();
121   if (!vOpener) {
122     return;
123   }
124
125   var vChildren = this.getAllButtons();
126   var vChildrenLength = vChildren.length;
127   var vIndex = vChildren.indexOf(vOpener);
128   var vCurrent;
129   var vPrevButton = null;
130
131   for (var i=vIndex-1; i>=0; i--)
132   {
133     vCurrent = vChildren[i];
134
135     if (vCurrent instanceof qx.ui.toolbar.MenuButton && vCurrent.getEnabled())
136     {
137       vPrevButton = vCurrent;
138       break;
139     }
140   }
141
142   // If none found, try again from the begin (looping)
143   if (!vPrevButton)
144   {
145     for (var i=vChildrenLength-1; i>vIndex; i--)
146     {
147       vCurrent = vChildren[i];
148
149       if (vCurrent instanceof qx.ui.toolbar.MenuButton && vCurrent.getEnabled())
150       {
151         vPrevButton = vCurrent;
152         break;
153       }
154     }
155   }
156
157   if (vPrevButton)
158   {
159     // hide other menus
160     qx.manager.object.MenuManager.getInstance().update();
161
162     // show previous menu
163     vPrevButton._showMenu(true);
164   }
165 }
166
167 qx.Proto._onkeypress_right = function()
168 {
169   var vMenu = this.getOpenMenu();
170   if (!vMenu) {
171     return;
172   }
173
174   var vOpener = vMenu.getOpener();
175   if (!vOpener) {
176     return;
177   }
178
179   var vChildren = this.getAllButtons();
180   var vChildrenLength = vChildren.length;
181   var vIndex = vChildren.indexOf(vOpener);
182   var vCurrent;
183   var vNextButton = null;
184
185   for (var i=vIndex+1; i<vChildrenLength; i++)
186   {
187     vCurrent = vChildren[i];
188
189     if (vCurrent instanceof qx.ui.toolbar.MenuButton && vCurrent.getEnabled())
190     {
191       vNextButton = vCurrent;
192       break;
193     }
194   }
195
196   // If none found, try again from the begin (looping)
197   if (!vNextButton)
198   {
199     for (var i=0; i<vIndex; i++)
200     {
201       vCurrent = vChildren[i];
202
203       if (vCurrent instanceof qx.ui.toolbar.MenuButton && vCurrent.getEnabled())
204       {
205         vNextButton = vCurrent;
206         break;
207       }
208     }
209   }
210
211   if (vNextButton)
212   {
213     // hide other menus
214     qx.manager.object.MenuManager.getInstance().update();
215
216     // show next menu
217     vNextButton._showMenu(true);
218   }
219 }
220
221
222
223
224
225
226
227 /*
228 ---------------------------------------------------------------------------
229   DISPOSER
230 ---------------------------------------------------------------------------
231 */
232
233 qx.Proto.dispose = function()
234 {
235   if (this.getDisposed()) {
236     return;
237   }
238
239   this.removeEventListener("keypress", this._onkeypress);
240
241   return qx.ui.layout.HorizontalBoxLayout.prototype.dispose.call(this);
242 }