Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / examples / desktop / js / StartMenu.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
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.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /*!
16  * Ext JS Library 4.0
17  * Copyright(c) 2006-2011 Sencha Inc.
18  * licensing@sencha.com
19  * http://www.sencha.com/license
20  */
21
22 Ext.define('Ext.ux.desktop.StartMenu', {
23     extend: 'Ext.panel.Panel',
24
25     requires: [
26         'Ext.menu.Menu',
27         'Ext.toolbar.Toolbar'
28     ],
29
30     ariaRole: 'menu',
31
32     cls: 'x-menu ux-start-menu',
33
34     defaultAlign: 'bl-tl',
35
36     iconCls: 'user',
37
38     floating: true,
39
40     shadow: true,
41
42     // We have to hardcode a width because the internal Menu cannot drive our width.
43     // This is combined with changing the align property of the menu's layout from the
44     // typical 'stretchmax' to 'stretch' which allows the the items to fill the menu
45     // area.
46     width: 300,
47
48     initComponent: function() {
49         var me = this, menu = me.menu;
50
51         me.menu = new Ext.menu.Menu({
52             cls: 'ux-start-menu-body',
53             border: false,
54             floating: false,
55             items: menu
56         });
57         me.menu.layout.align = 'stretch';
58
59         me.items = [me.menu];
60         me.layout = 'fit';
61
62         Ext.menu.Manager.register(me);
63         me.callParent();
64         // TODO - relay menu events
65
66         me.toolbar = new Ext.toolbar.Toolbar(Ext.apply({
67             dock: 'right',
68             cls: 'ux-start-menu-toolbar',
69             vertical: true,
70             width: 100
71         }, me.toolConfig));
72
73         me.toolbar.layout.align = 'stretch';
74         me.addDocked(me.toolbar);
75
76         delete me.toolItems;
77
78         me.on('deactivate', function () {
79             me.hide();
80         });
81     },
82
83     addMenuItem: function() {
84         var cmp = this.menu;
85         cmp.add.apply(cmp, arguments);
86     },
87
88     addToolItem: function() {
89         var cmp = this.toolbar;
90         cmp.add.apply(cmp, arguments);
91     },
92
93     showBy: function(cmp, pos, off) {
94         var me = this;
95
96         if (me.floating && cmp) {
97             me.layout.autoSize = true;
98             me.show();
99
100             // Component or Element
101             cmp = cmp.el || cmp;
102
103             // Convert absolute to floatParent-relative coordinates if necessary.
104             var xy = me.el.getAlignToXY(cmp, pos || me.defaultAlign, off);
105             if (me.floatParent) {
106                 var r = me.floatParent.getTargetEl().getViewRegion();
107                 xy[0] -= r.x;
108                 xy[1] -= r.y;
109             }
110             me.showAt(xy);
111             me.doConstrain();
112         }
113         return me;
114     }
115 }); // StartMenu
116