1 /* ************************************************************************
3 qooxdoo - the new era of web development
8 2004-2006 by 1&1 Internet AG, Germany, http://www.1and1.org
11 LGPL 2.1: http://www.gnu.org/licenses/lgpl.html
14 * Sebastian Werner (wpbasti)
15 * Andreas Ecker (ecker)
17 ************************************************************************ */
19 /* ************************************************************************
22 #optional(qx.ui.embed.Flash)
24 ************************************************************************ */
27 A multi-prupose widget used by many more complex widgets.
29 The intended purpose of qx.ui.basic.Atom is to easily align the common icon-text combination in different ways.
30 This is useful for all types of buttons, menuentires, tooltips, ...
32 qx.OO.defineClass("qx.ui.basic.Atom", qx.ui.layout.BoxLayout,
33 function(vLabel, vIcon, vIconWidth, vIconHeight, vFlash)
35 qx.ui.layout.BoxLayout.call(this);
37 if (this.getOrientation() == null) {
38 this.setOrientation("horizontal");
42 this.setSelectable(false);
44 // Disable flex support
45 this.getLayoutImpl().setEnableFlexSupport(false);
47 // Apply constructor arguments
48 if (qx.util.Validation.isValidString(vLabel)) {
49 this.setLabel(vLabel);
54 // Simple flash wrapper
55 if (qx.OO.isAvailable("qx.ui.embed.Flash") && qx.util.Validation.isValidString(vFlash) && qx.util.Validation.isValidNumber(vIconWidth) && qx.util.Validation.isValidNumber(vIconHeight) && qx.ui.embed.Flash.getPlayerVersion().getMajor() > 0)
57 this._flashMode = true;
61 // flash needs explicit dimensions!
62 this.setIconWidth(vIconWidth);
63 this.setIconHeight(vIconHeight);
65 else if (qx.util.Validation.isValidString(vIcon))
69 if (qx.util.Validation.isValidNumber(vIconWidth)) {
70 this.setIconWidth(vIconWidth);
73 if (qx.util.Validation.isValidNumber(vIconHeight)) {
74 this.setIconHeight(vIconHeight);
79 qx.ui.basic.Atom.SHOW_LABEL = "label";
80 qx.ui.basic.Atom.SHOW_ICON = "icon";
81 qx.ui.basic.Atom.SHOW_BOTH = "both";
85 ---------------------------------------------------------------------------
87 ---------------------------------------------------------------------------
91 The label/caption/text of the qx.ui.basic.Atom instance
93 qx.OO.addProperty({ name : "label", type : "string" });
96 Any URI String supported by qx.ui.basic.Image to display a icon
98 qx.OO.addProperty({ name : "icon", type : "string" });
101 * Any URI String supported by qx.ui.basic.Image to display a disabled icon.
103 * If not set the normal icon is shown transparently.
105 qx.OO.addProperty({ name : "disabledIcon", type : "string" });
108 Configure the visibility of the sub elements/widgets.
109 Possible values: both, text, icon, none
111 qx.OO.addProperty({ name : "show", type : "string", defaultValue : "both", possibleValues : [ "both", "label", "icon", "none", null ] });
114 The position of the icon in relation to the text.
115 Only useful/needed if text and icon is configured and 'show' is configured as 'both' (default)
117 qx.OO.addProperty({ name : "iconPosition", type : "string", defaultValue : "left", possibleValues : [ "top", "right", "bottom", "left" ] });
120 The width of the icon.
121 If configured, this makes qx.ui.basic.Atom a little bit faster as it does not need to wait until the image loading is finished.
123 qx.OO.addProperty({ name : "iconWidth", type : "number" });
126 The height of the icon
127 If configured, this makes qx.ui.basic.Atom a little bit faster as it does not need to wait until the image loading is finished.
129 qx.OO.addProperty({ name : "iconHeight", type : "number" });
131 qx.OO.changeProperty({ name : "appearance", type : "string", defaultValue : "atom" });
138 ---------------------------------------------------------------------------
140 ---------------------------------------------------------------------------
143 qx.Proto._flashMode = false;
145 qx.Proto._labelObject = null;
146 qx.Proto._iconObject = null;
148 qx.Proto._createLabel = function()
150 var l = this._labelObject = new qx.ui.basic.Label(this.getLabel());
152 l.setAnonymous(true);
153 l.setEnabled(this.getEnabled());
154 l.setSelectable(false);
156 this.addAt(l, this._iconObject ? 1 : 0);
159 qx.Proto._createIcon = function()
161 if (this._flashMode && qx.OO.isAvailable("qx.ui.embed.Flash"))
163 var i = this._iconObject = new qx.ui.embed.Flash(this.getIcon());
167 var i = this._iconObject = new qx.ui.basic.Image();
170 i.setAnonymous(true);
177 qx.Proto._updateIcon = function() {
178 // NOTE: We have to check whether the properties "icon" and "disabledIcon"
179 // exist, because some child classes remove them.
180 if (this._iconObject && this.getIcon && this.getDisabledIcon) {
181 var disabledIcon = this.getDisabledIcon();
183 if (this.getEnabled()) {
184 this._iconObject.setSource(this.getIcon());
186 this._iconObject.setSource(disabledIcon);
188 this._iconObject.setEnabled(true);
190 this._iconObject.setSource(this.getIcon());
191 this._iconObject.setEnabled(this.getEnabled());
196 qx.Proto.getLabelObject = function() {
197 return this._labelObject;
200 qx.Proto.getIconObject = function() {
201 return this._iconObject;
210 ---------------------------------------------------------------------------
212 ---------------------------------------------------------------------------
215 qx.Proto._modifyEnabled = function(propValue, propOldValue, propData)
219 if (this._labelObject) {
220 this._labelObject.setEnabled(propValue);
223 return qx.ui.layout.BoxLayout.prototype._modifyEnabled.call(this, propValue, propOldValue, propData);
226 qx.Proto._modifyIconPosition = function(propValue, propOldValue, propData)
232 this.setOrientation("vertical");
233 this.setReverseChildrenOrder(propValue == "bottom");
237 this.setOrientation("horizontal");
238 this.setReverseChildrenOrder(propValue == "right");
245 qx.Proto._modifyShow = function(propValue, propOldValue, propData)
253 qx.Proto._modifyLabel = function(propValue, propOldValue, propData)
255 if (this._labelObject) {
256 this._labelObject.setHtml(propValue);
264 qx.Proto._modifyIcon = function(propValue, propOldValue, propData)
272 qx.Proto._modifyDisabledIcon = function(propValue, propOldValue, propData)
280 qx.Proto._modifyIconWidth = function(propValue, propOldValue, propData)
282 this._iconObject.setWidth(propValue);
286 qx.Proto._modifyIconHeight = function(propValue, propOldValue, propData)
288 this._iconObject.setHeight(propValue);
298 ---------------------------------------------------------------------------
300 ---------------------------------------------------------------------------
303 qx.Proto._iconIsVisible = false;
304 qx.Proto._labelIsVisible = false;
306 qx.Proto._handleLabel = function()
308 switch(this.getShow())
310 case qx.ui.basic.Atom.SHOW_LABEL:
311 case qx.ui.basic.Atom.SHOW_BOTH:
312 this._labelIsVisible = qx.util.Validation.isValidString(this.getLabel());
316 this._labelIsVisible = false;
319 if (this._labelIsVisible)
321 this._labelObject ? this._labelObject.setDisplay(true) : this._createLabel();
323 else if (this._labelObject)
325 this._labelObject.setDisplay(false);
329 qx.Proto._handleIcon = function()
331 switch(this.getShow())
333 case qx.ui.basic.Atom.SHOW_ICON:
334 case qx.ui.basic.Atom.SHOW_BOTH:
335 this._iconIsVisible = qx.util.Validation.isValidString(this.getIcon());
339 this._iconIsVisible = false;
342 if (this._iconIsVisible)
344 this._iconObject ? this._iconObject.setDisplay(true) : this._createIcon();
346 else if (this._iconObject)
348 this._iconObject.setDisplay(false);
358 ---------------------------------------------------------------------------
360 ---------------------------------------------------------------------------
363 // Omit recursive cloning
364 qx.Proto._cloneRecursive = qx.util.Return.returnTrue;
373 ---------------------------------------------------------------------------
375 ---------------------------------------------------------------------------
378 qx.Proto.dispose = function()
380 if (this.getDisposed()) {
384 if (this._iconObject)
386 this._iconObject.dispose();
387 this._iconObject = null;
390 if (this._labelObject)
392 this._labelObject.dispose();
393 this._labelObject = null;
396 return qx.ui.layout.BoxLayout.prototype.dispose.call(this);