3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * Ext JS Library 3.3.1
17 * Copyright(c) 2006-2010 Sencha Inc.
18 * licensing@sencha.com
19 * http://www.sencha.com/license
22 * @class Ext.ux.TaskBar
23 * @extends Ext.util.Observable
25 Ext.ux.TaskBar = function(app){
30 Ext.extend(Ext.ux.TaskBar, Ext.util.Observable, {
32 this.startMenu = new Ext.ux.StartMenu(Ext.apply({
36 title: 'Tommy Maintz',
38 }, this.app.startConfig));
40 this.startBtn = new Ext.Button({
46 renderTo: 'ux-taskbar-start',
47 clickEvent: 'mousedown',
48 template: new Ext.Template(
49 '<table cellspacing="0" class="x-btn"><tbody class="{1}"><tr>',
50 '<td class="ux-startbutton-left"><i> </i></td>',
51 '<td class="ux-startbutton-center"><em class="{2} unselectable="on">',
52 '<button class="x-btn-text" type="{0}" style="height:30px;"></button>',
54 '<td class="ux-startbutton-right"><i> </i></td>',
55 '</tr></tbody></table>')
58 var width = this.startBtn.getEl().getWidth()+10;
60 var sbBox = new Ext.BoxComponent({
61 el: 'ux-taskbar-start',
69 this.tbPanel = new Ext.ux.TaskButtonsPanel({
70 el: 'ux-taskbuttons-panel',
75 var container = new Ext.ux.TaskBarContainer({
78 items: [sbBox,this.tbPanel]
84 addTaskButton : function(win){
85 return this.tbPanel.addButton(win, 'ux-taskbuttons-panel');
88 removeTaskButton : function(btn){
89 this.tbPanel.removeButton(btn);
92 setActiveButton : function(btn){
93 this.tbPanel.setActiveButton(btn);
100 * @class Ext.ux.TaskBarContainer
101 * @extends Ext.Container
103 Ext.ux.TaskBarContainer = Ext.extend(Ext.Container, {
104 initComponent : function() {
105 Ext.ux.TaskBarContainer.superclass.initComponent.call(this);
107 this.el = Ext.get(this.el) || Ext.getBody();
108 this.el.setHeight = Ext.emptyFn;
109 this.el.setWidth = Ext.emptyFn;
110 this.el.setSize = Ext.emptyFn;
116 this.el.dom.scroll = 'no';
117 this.allowDomMove = false;
118 this.autoWidth = true;
119 this.autoHeight = true;
120 Ext.EventManager.onWindowResize(this.fireResize, this);
121 this.renderTo = this.el;
124 fireResize : function(w, h){
125 this.onResize(w, h, w, h);
126 this.fireEvent('resize', this, w, h, w, h);
133 * @class Ext.ux.TaskButtonsPanel
134 * @extends Ext.BoxComponent
136 Ext.ux.TaskButtonsPanel = Ext.extend(Ext.BoxComponent, {
140 scrollRepeatInterval: 400,
147 buttonWidthSet: false,
149 initComponent : function() {
150 Ext.ux.TaskButtonsPanel.superclass.initComponent.call(this);
151 this.on('resize', this.delegateUpdates);
154 this.stripWrap = Ext.get(this.el).createChild({
155 cls: 'ux-taskbuttons-strip-wrap',
157 tag:'ul', cls:'ux-taskbuttons-strip'
160 this.stripSpacer = Ext.get(this.el).createChild({
161 cls:'ux-taskbuttons-strip-spacer'
163 this.strip = new Ext.Element(this.stripWrap.dom.firstChild);
165 this.edge = this.strip.createChild({
167 cls:'ux-taskbuttons-edge'
169 this.strip.createChild({
174 addButton : function(win){
175 var li = this.strip.createChild({tag:'li'}, this.edge); // insert before the edge
176 var btn = new Ext.ux.TaskBar.TaskButton(win, li);
178 this.items.push(btn);
180 if(!this.buttonWidthSet){
181 this.lastButtonWidth = btn.container.getWidth();
184 this.setActiveButton(btn);
188 removeButton : function(btn){
189 var li = document.getElementById(btn.container.id);
191 li.parentNode.removeChild(li);
194 for(var i = 0, len = this.items.length; i < len; i++) {
195 if(this.items[i] != btn){
196 s.push(this.items[i]);
201 this.delegateUpdates();
204 setActiveButton : function(btn){
205 this.activeButton = btn;
206 this.delegateUpdates();
209 delegateUpdates : function(){
210 /*if(this.suspendUpdates){
213 if(this.resizeButtons && this.rendered){
216 if(this.enableScroll && this.rendered){
221 autoSize : function(){
222 var count = this.items.length;
223 var ow = this.el.dom.offsetWidth;
224 var aw = this.el.dom.clientWidth;
226 if(!this.resizeButtons || count < 1 || !aw){ // !aw for display:none
230 var each = Math.max(Math.min(Math.floor((aw-4) / count) - this.buttonMargin, this.buttonWidth), this.minButtonWidth); // -4 for float errors in IE
231 var btns = this.stripWrap.dom.getElementsByTagName('button');
233 this.lastButtonWidth = Ext.get(btns[0].id).findParent('li').offsetWidth;
235 for(var i = 0, len = btns.length; i < len; i++) {
238 var tw = Ext.get(btns[i].id).findParent('li').offsetWidth;
239 var iw = btn.offsetWidth;
241 btn.style.width = (each - (tw-iw)) + 'px';
245 autoScroll : function(){
246 var count = this.items.length;
247 var ow = this.el.dom.offsetWidth;
248 var tw = this.el.dom.clientWidth;
250 var wrap = this.stripWrap;
251 var cw = wrap.dom.offsetWidth;
252 var pos = this.getScrollPos();
253 var l = this.edge.getOffsetsTo(this.stripWrap)[0] + pos;
255 if(!this.enableScroll || count < 1 || cw < 20){ // 20 to prevent display:none issues
259 wrap.setWidth(tw); // moved to here because of problem in Safari
262 wrap.dom.scrollLeft = 0;
263 //wrap.setWidth(tw); moved from here because of problem in Safari
265 this.scrolling = false;
266 this.el.removeClass('x-taskbuttons-scrolling');
267 this.scrollLeft.hide();
268 this.scrollRight.hide();
272 this.el.addClass('x-taskbuttons-scrolling');
274 tw -= wrap.getMargins('lr');
275 wrap.setWidth(tw > 20 ? tw : 20);
277 if(!this.scrollLeft){
278 this.createScrollers();
280 this.scrollLeft.show();
281 this.scrollRight.show();
284 this.scrolling = true;
285 if(pos > (l-tw)){ // ensure it stays within bounds
286 wrap.dom.scrollLeft = l-tw;
287 }else{ // otherwise, make sure the active button is still visible
288 this.scrollToButton(this.activeButton, true); // true to animate
290 this.updateScrollButtons();
294 createScrollers : function(){
295 var h = this.el.dom.offsetHeight; //var h = this.stripWrap.dom.offsetHeight;
298 var sl = this.el.insertFirst({
299 cls:'ux-taskbuttons-scroller-left'
302 sl.addClassOnOver('ux-taskbuttons-scroller-left-over');
303 this.leftRepeater = new Ext.util.ClickRepeater(sl, {
304 interval : this.scrollRepeatInterval,
305 handler: this.onScrollLeft,
308 this.scrollLeft = sl;
311 var sr = this.el.insertFirst({
312 cls:'ux-taskbuttons-scroller-right'
315 sr.addClassOnOver('ux-taskbuttons-scroller-right-over');
316 this.rightRepeater = new Ext.util.ClickRepeater(sr, {
317 interval : this.scrollRepeatInterval,
318 handler: this.onScrollRight,
321 this.scrollRight = sr;
324 getScrollWidth : function(){
325 return this.edge.getOffsetsTo(this.stripWrap)[0] + this.getScrollPos();
328 getScrollPos : function(){
329 return parseInt(this.stripWrap.dom.scrollLeft, 10) || 0;
332 getScrollArea : function(){
333 return parseInt(this.stripWrap.dom.clientWidth, 10) || 0;
336 getScrollAnim : function(){
338 duration: this.scrollDuration,
339 callback: this.updateScrollButtons,
344 getScrollIncrement : function(){
345 return (this.scrollIncrement || this.lastButtonWidth+2);
348 /* getBtnEl : function(item){
349 return document.getElementById(item.id);
352 scrollToButton : function(item, animate){
353 item = item.el.dom.parentNode; // li
355 var el = item; //this.getBtnEl(item);
356 var pos = this.getScrollPos(), area = this.getScrollArea();
357 var left = Ext.fly(el).getOffsetsTo(this.stripWrap)[0] + pos;
358 var right = left + el.offsetWidth;
360 this.scrollTo(left, animate);
361 }else if(right > (pos + area)){
362 this.scrollTo(right - area, animate);
366 scrollTo : function(pos, animate){
367 this.stripWrap.scrollTo('left', pos, animate ? this.getScrollAnim() : false);
369 this.updateScrollButtons();
373 onScrollRight : function(){
374 var sw = this.getScrollWidth()-this.getScrollArea();
375 var pos = this.getScrollPos();
376 var s = Math.min(sw, pos + this.getScrollIncrement());
378 this.scrollTo(s, this.animScroll);
382 onScrollLeft : function(){
383 var pos = this.getScrollPos();
384 var s = Math.max(0, pos - this.getScrollIncrement());
386 this.scrollTo(s, this.animScroll);
390 updateScrollButtons : function(){
391 var pos = this.getScrollPos();
392 this.scrollLeft[pos == 0 ? 'addClass' : 'removeClass']('ux-taskbuttons-scroller-left-disabled');
393 this.scrollRight[pos >= (this.getScrollWidth()-this.getScrollArea()) ? 'addClass' : 'removeClass']('ux-taskbuttons-scroller-right-disabled');
400 * @class Ext.ux.TaskBar.TaskButton
401 * @extends Ext.Button
403 Ext.ux.TaskBar.TaskButton = function(win, el){
405 Ext.ux.TaskBar.TaskButton.superclass.constructor.call(this, {
406 iconCls: win.iconCls,
407 text: Ext.util.Format.ellipsis(win.title, 12),
409 handler : function(){
410 if(win.minimized || win.hidden){
412 }else if(win == win.manager.getActive()){
418 clickEvent:'mousedown',
419 template: new Ext.Template(
420 '<table cellspacing="0" class="x-btn {3}"><tbody><tr>',
421 '<td class="ux-taskbutton-left"><i> </i></td>',
422 '<td class="ux-taskbutton-center"><em class="{5} unselectable="on">',
423 '<button class="x-btn-text {2}" type="{1}" style="height:28px;">{0}</button>',
425 '<td class="ux-taskbutton-right"><i> </i></td>',
426 "</tr></tbody></table>")
430 Ext.extend(Ext.ux.TaskBar.TaskButton, Ext.Button, {
431 onRender : function(){
432 Ext.ux.TaskBar.TaskButton.superclass.onRender.apply(this, arguments);
434 this.cmenu = new Ext.menu.Menu({
438 if(!this.win.isVisible()){
447 handler: this.win.minimize,
451 handler: this.win.maximize,
455 handler: this.closeWin.createDelegate(this, this.win, true),
460 this.cmenu.on('beforeshow', function(){
461 var items = this.cmenu.items.items;
463 items[0].setDisabled(w.maximized !== true && w.hidden !== true);
464 items[1].setDisabled(w.minimized === true);
465 items[2].setDisabled(w.maximized === true || w.hidden === true);
468 this.el.on('contextmenu', function(e){
474 xy[1] -= this.cmenu.el.getHeight();
475 this.cmenu.showAt(xy);
479 closeWin : function(cMenu, e, win){
480 if(!win.isVisible()){