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 * @class Ext.panel.Tool
17 * @extends Ext.Component
19 This class is used to display small visual icons in the header of a panel. There are a set of
20 25 icons that can be specified by using the {@link #type} config. The {@link #handler} config
21 can be used to provide a function that will respond to any click events. In general, this class
22 will not be instantiated directly, rather it will be created by specifying the {@link Ext.panel.Panel#tools}
23 configuration on the Panel itself.
27 Ext.create('Ext.panel.Panel', {
30 renderTo: document.body,
46 handler: function(event, target, owner, tool){
48 owner.child('#refresh').show();
55 Ext.define('Ext.panel.Tool', {
56 extend: 'Ext.Component',
57 requires: ['Ext.tip.QuickTipManager'],
60 baseCls: Ext.baseCSSPrefix + 'tool',
61 disabledCls: Ext.baseCSSPrefix + 'tool-disabled',
62 toolPressedCls: Ext.baseCSSPrefix + 'tool-pressed',
63 toolOverCls: Ext.baseCSSPrefix + 'tool-over',
65 renderTpl: ['<img src="{blank}" class="{baseCls}-{type}" role="presentation"/>'],
68 * @cfg {Function} handler
69 * A function to execute when the tool is clicked.
70 * Arguments passed are:
72 * <li><b>event</b> : Ext.EventObject<div class="sub-desc">The click event.</div></li>
73 * <li><b>toolEl</b> : Ext.core.Element<div class="sub-desc">The tool Element.</div></li>
74 * <li><b>panel</b> : Ext.panel.Panel<div class="sub-desc">The host Panel</div></li>
75 * <li><b>tool</b> : Ext.panel.Tool<div class="sub-desc">The tool object</div></li>
81 * The scope to execute the {@link #handler} function. Defaults to the tool.
86 * The type of tool to render. The following types are available:
117 * @cfg {String/Object} tooltip
118 * The tooltip for the tool - can be a string to be used as innerHTML (html tags are accepted) or QuickTips config object
122 * @cfg {Boolean} stopEvent
123 * Defaults to true. Specify as false to allow click event to propagate.
127 initComponent: function() {
132 * Fires when the tool is clicked
133 * @param {Ext.panel.Tool} this
134 * @param {Ext.EventObject} e The event object
168 if (me.id && Ext.Array.indexOf(types, me.id) > -1 && Ext.global.console) {
169 Ext.global.console.warn('When specifying a tool you should use the type option, the id can conflict now that tool is a Component');
173 me.type = me.type || me.id;
175 Ext.applyIf(me.renderData, {
177 blank: Ext.BLANK_IMAGE_URL,
180 me.renderSelectors.toolEl = '.' + me.baseCls + '-' + me.type;
185 afterRender: function() {
187 me.callParent(arguments);
189 if (Ext.isObject(me.qtip)) {
190 Ext.tip.QuickTipManager.register(Ext.apply({
195 me.toolEl.dom.qtip = me.qtip;
201 mousedown: me.onMouseDown,
202 mouseover: me.onMouseOver,
203 mouseout: me.onMouseOut,
209 * Set the type of the tool. Allows the icon to be changed.
210 * @param {String} type The new type. See the {@link #type} config.
211 * @return {Ext.panel.Tool} this
213 setType: function(type) {
218 me.toolEl.dom.className = me.baseCls + '-' + type;
224 * Binds this tool to a component.
226 * @param {Ext.Component} component The component
228 bindTo: function(component) {
229 this.owner = component;
233 * Fired when the tool element is clicked
235 * @param {Ext.EventObject} e
236 * @param {HTMLElement} target The target element
238 onClick: function(e, target) {
245 owner = me.owner || me.ownerCt;
247 //remove the pressed + over class
248 me.el.removeCls(me.toolPressedCls);
249 me.el.removeCls(me.toolOverCls);
251 if (me.stopEvent !== false) {
255 Ext.callback(me.handler, me.scope || me, [e, target, owner, me]);
256 me.fireEvent('click', me, e);
261 onDestroy: function(){
262 if (Ext.isObject(this.tooltip)) {
263 Ext.tip.QuickTipManager.unregister(this.id);
269 * Called then the user pressing their mouse button down on a tool
270 * Adds the press class ({@link #toolPressedCls})
273 onMouseDown: function() {
278 this.el.addCls(this.toolPressedCls);
282 * Called when the user rolls over a tool
283 * Adds the over class ({@link #toolOverCls})
286 onMouseOver: function() {
290 this.el.addCls(this.toolOverCls);
294 * Called when the user rolls out from a tool.
295 * Removes the over class ({@link #toolOverCls})
298 onMouseOut: function() {
299 this.el.removeCls(this.toolOverCls);