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 /* ************************************************************************
23 ************************************************************************ */
25 qx.OO.defineClass("qx.ui.menu.Button", qx.ui.layout.HorizontalBoxLayout,
26 function(vLabel, vIcon, vCommand, vMenu)
28 qx.ui.layout.HorizontalBoxLayout.call(this);
31 // ************************************************************************
33 // ************************************************************************
35 var io = this._iconObject = new qx.ui.basic.Image;
37 io.setAnonymous(true);
39 var lo = this._labelObject = new qx.ui.basic.Label;
40 lo.setAnonymous(true);
41 lo.setSelectable(false);
43 var so = this._shortcutObject = new qx.ui.basic.Label;
44 so.setAnonymous(true);
45 so.setSelectable(false);
47 var ao = this._arrowObject = new qx.ui.basic.Image("widget/arrows/next.gif");
48 ao.setAnonymous(true);
51 // ************************************************************************
53 // ************************************************************************
55 if (qx.util.Validation.isValidString(vLabel)) {
56 this.setLabel(vLabel);
59 if (qx.util.Validation.isValidString(vIcon)) {
63 if (qx.util.Validation.isValid(vCommand)) {
64 this.setCommand(vCommand);
67 if (qx.util.Validation.isValid(vMenu)) {
72 // ************************************************************************
74 // ************************************************************************
76 this.addEventListener("mouseup", this._onmouseup);
82 ---------------------------------------------------------------------------
84 ---------------------------------------------------------------------------
87 qx.OO.changeProperty({ name : "appearance", type : "string", defaultValue : "menu-button" });
89 qx.OO.addProperty({ name : "icon", type : "string" });
90 qx.OO.addProperty({ name : "label", type : "string" });
91 qx.OO.addProperty({ name : "menu", type : "object" });
99 ---------------------------------------------------------------------------
101 ---------------------------------------------------------------------------
104 qx.Proto._hasIcon = false;
105 qx.Proto._hasLabel = false;
106 qx.Proto._hasShortcut = false;
107 qx.Proto._hasMenu = false;
109 qx.Proto.hasIcon = function() {
110 return this._hasIcon;
113 qx.Proto.hasLabel = function() {
114 return this._hasLabel;
117 qx.Proto.hasShortcut = function() {
118 return this._hasShortcut;
121 qx.Proto.hasMenu = function() {
122 return this._hasMenu;
125 qx.Proto.getIconObject = function() {
126 return this._iconObject;
129 qx.Proto.getLabelObject = function() {
130 return this._labelObject;
133 qx.Proto.getShortcutObject = function() {
134 return this._shortcutObject;
137 qx.Proto.getArrowObject = function() {
138 return this._arrowObject;
141 qx.Proto.getParentMenu = function()
143 var vParent = this.getParent();
146 vParent = vParent.getParent();
148 if (vParent && vParent instanceof qx.ui.menu.Menu) {
161 ---------------------------------------------------------------------------
163 ---------------------------------------------------------------------------
167 This creates an new instance of the layout impl this widget uses
169 qx.Proto._createLayoutImpl = function() {
170 return new qx.renderer.layout.MenuButtonLayoutImpl(this);
178 ---------------------------------------------------------------------------
180 ---------------------------------------------------------------------------
183 qx.Proto._modifyEnabled = function(propValue, propOldValue, propData)
185 if (this._iconObject) {
186 this._iconObject.setEnabled(propValue);
189 if (this._labelObject) {
190 this._labelObject.setEnabled(propValue);
193 if (this._shortcutObject) {
194 this._shortcutObject.setEnabled(propValue);
197 return qx.ui.layout.HorizontalBoxLayout.prototype._modifyEnabled.call(this, propValue, propOldValue, propData);
200 qx.Proto._modifyIcon = function(propValue, propOldValue, propData)
202 this._iconObject.setSource(propValue);
204 if (qx.util.Validation.isValidString(propValue))
206 this._hasIcon = true;
208 if (qx.util.Validation.isInvalidString(propOldValue)) {
209 this.addAtBegin(this._iconObject);
214 this._hasIcon = false;
215 this.remove(this._iconObject);
221 qx.Proto._modifyLabel = function(propValue, propOldValue, propData)
223 this._labelObject.setHtml(propValue);
225 if (qx.util.Validation.isValidString(propValue))
227 this._hasLabel = true;
229 if (qx.util.Validation.isInvalidString(propOldValue)) {
230 this.addAt(this._labelObject, this.getFirstChild() == this._iconObject ? 1 : 0);
235 this._hasLabel = false;
236 this.remove(this._labelObject);
242 qx.Proto._modifyCommand = function(propValue, propOldValue, propData)
244 var vHtml = propValue ? propValue.getShortcut() : "";
246 this._shortcutObject.setHtml(vHtml);
248 if (qx.util.Validation.isValidString(vHtml))
250 this._hasShortcut = true;
252 var vOldHtml = propOldValue ? propOldValue.getShortcut() : "";
254 if (qx.util.Validation.isInvalidString(vOldHtml))
256 if (this.getLastChild() == this._arrowObject)
258 this.addBefore(this._shortcutObject, this._arrowObject);
262 this.addAtEnd(this._shortcutObject);
268 this._hasShortcut = false;
269 this.remove(this._shortcutObject);
275 qx.Proto._modifyMenu = function(propValue, propOldValue, propData)
277 if (qx.util.Validation.isValidObject(propValue))
279 this._hasMenu = true;
281 if (qx.util.Validation.isInvalidObject(propOldValue)) {
282 this.addAtEnd(this._arrowObject);
287 this._hasMenu = false;
288 this.remove(this._arrowObject);
300 ---------------------------------------------------------------------------
302 ---------------------------------------------------------------------------
305 qx.Proto._onmouseup = function(e) {
314 ---------------------------------------------------------------------------
316 ---------------------------------------------------------------------------
319 qx.Proto.dispose = function()
321 if (this.getDisposed()) {
326 if (this._iconObject)
328 this._iconObject.dispose();
329 this._iconObject = null;
332 if (this._labelObject)
334 this._labelObject.dispose();
335 this._labelObject = null;
338 if (this._shortcutObject)
340 this._shortcutObject.dispose();
341 this._shortcutObject = null;
344 if (this._arrowObject)
346 this._arrowObject.dispose();
347 this._arrowObject = null;
350 // Remove event listeners
351 this.removeEventListener("mouseup", this._onmouseup);
353 return qx.ui.layout.HorizontalBoxLayout.prototype.dispose.call(this);