Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / layout / component / field / Trigger.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  * @private
17  * @class Ext.layout.component.field.Trigger
18  * @extends Ext.layout.component.field.Field
19  * Layout class for {@link Ext.form.field.Trigger} fields. Adjusts the input field size to accommodate
20  * the trigger button(s).
21  * @private
22  */
23
24 Ext.define('Ext.layout.component.field.Trigger', {
25
26     /* Begin Definitions */
27
28     alias: ['layout.triggerfield'],
29
30     extend: 'Ext.layout.component.field.Field',
31
32     /* End Definitions */
33
34     type: 'triggerfield',
35
36     sizeBodyContents: function(width, height) {
37         var me = this,
38             owner = me.owner,
39             inputEl = owner.inputEl,
40             triggerWrap = owner.triggerWrap,
41             triggerWidth = owner.getTriggerWidth();
42
43         // If we or our ancestor is hidden, we can get a triggerWidth calculation
44         // of 0.  We don't want to resize in this case.
45         if (owner.hideTrigger || owner.readOnly || triggerWidth > 0) {
46             // Decrease the field's width by the width of the triggers. Both the field and the triggerWrap
47             // are floated left in CSS so they'll stack up side by side.
48             me.setElementSize(inputEl, Ext.isNumber(width) ? width - triggerWidth : width);
49     
50             // Explicitly set the triggerWrap's width, to prevent wrapping
51             triggerWrap.setWidth(triggerWidth);
52         }
53     }
54 });