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.Header
17 * @extends Ext.container.Container
18 * Simple header class which is used for on {@link Ext.panel.Panel} and {@link Ext.window.Window}
20 Ext.define('Ext.panel.Header', {
21 extend: 'Ext.container.Container',
22 uses: ['Ext.panel.Tool', 'Ext.draw.Component', 'Ext.util.CSS'],
23 alias: 'widget.header',
30 renderTpl: ['<div class="{baseCls}-body<tpl if="bodyCls"> {bodyCls}</tpl><tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-body-{parent.ui}-{.}</tpl></tpl>"<tpl if="bodyStyle"> style="{bodyStyle}"</tpl>></div>'],
32 initComponent: function() {
39 me.indicateDragCls = me.baseCls + '-draggable';
40 me.title = me.title || ' ';
41 me.tools = me.tools || [];
42 me.items = me.items || [];
43 me.orientation = me.orientation || 'horizontal';
44 me.dock = (me.dock) ? me.dock : (me.orientation == 'horizontal') ? 'top' : 'left';
46 //add the dock as a ui
47 //this is so we support top/right/left/bottom headers
48 me.addClsWithUI(me.orientation);
49 me.addClsWithUI(me.dock);
51 Ext.applyIf(me.renderSelectors, {
52 body: '.' + me.baseCls + '-body'
56 if (!Ext.isEmpty(me.iconCls)) {
58 me.items.push(me.iconCmp);
62 if (me.orientation == 'vertical') {
63 // Hack for IE6/7's inability to display an inline-block
64 if (Ext.isIE6 || Ext.isIE7) {
65 me.width = this.width || 24;
66 } else if (Ext.isIEQuirks) {
67 me.width = this.width || 25;
73 clearInnerCtOnLayout: true,
74 bindToOwnerCtContainer: false
77 cls: me.baseCls + '-text',
85 if (Ext.isArray(ui)) {
88 rule = Ext.util.CSS.getRule('.' + me.baseCls + '-text-' + ui);
93 Ext.apply(me.textConfig, {
94 'font-family': style.fontFamily,
95 'font-weight': style.fontWeight,
96 'font-size': style.fontSize,
100 me.titleCmp = Ext.create('Ext.draw.Component', {
101 ariaRole : 'heading',
107 items: [ me.textConfig ],
109 textEl: '.' + me.baseCls + '-text'
116 clearInnerCtOnLayout: true,
117 bindToOwnerCtContainer: false
119 me.titleCmp = Ext.create('Ext.Component', {
121 ariaRole : 'heading',
124 renderTpl : ['<span class="{cls}-text {cls}-text-{ui}">{title}</span>'],
131 textEl: '.' + me.baseCls + '-text'
135 me.items.push(me.titleCmp);
138 me.items = me.items.concat(me.tools);
142 initIconCmp: function() {
143 this.iconCmp = Ext.create('Ext.Component', {
145 renderTpl : ['<img alt="" src="{blank}" class="{cls}-icon {iconCls}"/>'],
147 blank : Ext.BLANK_IMAGE_URL,
149 iconCls: this.iconCls,
150 orientation: this.orientation
153 iconEl: '.' + this.baseCls + '-icon'
155 iconCls: this.iconCls
159 afterRender: function() {
162 me.el.unselectable();
163 if (me.indicateDrag) {
164 me.el.addCls(me.indicateDragCls);
173 afterLayout: function() {
175 me.callParent(arguments);
177 // IE7 needs a forced repaint to make the top framing div expand to full width
184 addUIClsToElement: function(cls, force) {
186 result = me.callParent(arguments),
187 classes = [me.baseCls + '-body-' + cls, me.baseCls + '-body-' + me.ui + '-' + cls],
190 if (!force && me.rendered) {
192 me.body.addCls(me.bodyCls);
194 me.body.addCls(classes);
198 array = me.bodyCls.split(' ');
200 for (i = 0; i < classes.length; i++) {
201 if (!Ext.Array.contains(array, classes[i])) {
202 array.push(classes[i]);
206 me.bodyCls = array.join(' ');
208 me.bodyCls = classes.join(' ');
216 removeUIClsFromElement: function(cls, force) {
218 result = me.callParent(arguments),
219 classes = [me.baseCls + '-body-' + cls, me.baseCls + '-body-' + me.ui + '-' + cls],
222 if (!force && me.rendered) {
224 me.body.removeCls(me.bodyCls);
226 me.body.removeCls(classes);
230 array = me.bodyCls.split(' ');
232 for (i = 0; i < classes.length; i++) {
233 Ext.Array.remove(array, classes[i]);
236 me.bodyCls = array.join(' ');
244 addUIToElement: function(force) {
248 me.callParent(arguments);
250 cls = me.baseCls + '-body-' + me.ui;
251 if (!force && me.rendered) {
253 me.body.addCls(me.bodyCls);
259 array = me.bodyCls.split(' ');
261 if (!Ext.Array.contains(array, cls)) {
265 me.bodyCls = array.join(' ');
271 if (!force && me.titleCmp && me.titleCmp.rendered && me.titleCmp.textEl) {
272 me.titleCmp.textEl.addCls(me.baseCls + '-text-' + me.ui);
277 removeUIFromElement: function() {
281 me.callParent(arguments);
283 cls = me.baseCls + '-body-' + me.ui;
286 me.body.removeCls(me.bodyCls);
288 me.body.removeCls(cls);
292 array = me.bodyCls.split(' ');
293 Ext.Array.remove(array, cls);
294 me.bodyCls = array.join(' ');
300 if (me.titleCmp && me.titleCmp.rendered && me.titleCmp.textEl) {
301 me.titleCmp.textEl.removeCls(me.baseCls + '-text-' + me.ui);
305 onClick: function(e) {
306 if (!e.getTarget(Ext.baseCSSPrefix + 'tool')) {
307 this.fireEvent('click', e);
311 getTargetEl: function() {
312 return this.body || this.frameBody || this.el;
316 * Sets the title of the header.
317 * @param {String} title The title to be set
319 setTitle: function(title) {
322 if (me.titleCmp.rendered) {
323 if (me.titleCmp.surface) {
324 me.title = title || '';
325 var sprite = me.titleCmp.surface.items.items[0],
326 surface = me.titleCmp.surface;
328 surface.remove(sprite);
329 me.textConfig.type = 'text';
330 me.textConfig.text = title;
331 sprite = surface.add(me.textConfig);
332 sprite.setAttributes({
337 me.titleCmp.autoSizeSurface();
339 me.title = title || ' ';
340 me.titleCmp.textEl.update(me.title);
362 * Sets the CSS class that provides the icon image for this panel. This method will replace any existing
363 * icon class if one has already been set and fire the {@link #iconchange} event after completion.
364 * @param {String} cls The new CSS class name
366 setIconCls: function(cls) {
370 this.insert(0, this.iconCmp);
373 if (!cls || !cls.length) {
374 this.iconCmp.destroy();
377 var iconCmp = this.iconCmp,
380 el.removeCls(iconCmp.iconCls);
382 iconCmp.iconCls = cls;
388 * Add a tool to the header
389 * @param {Object} tool
391 addTool: function(tool) {
392 this.tools.push(this.add(tool));
397 * Set up the tools.<tool type> link in the owning Panel.
398 * Bind the tool to its owning Panel.
402 onAdd: function(component, index) {
403 this.callParent([arguments]);
404 if (component instanceof Ext.panel.Tool) {
405 component.bindTo(this.ownerCt);
406 this.tools[component.type] = component;