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.form.Button", qx.ui.basic.Atom,
26 function(vText, vIcon, vIconWidth, vIconHeight, vFlash)
28 // ************************************************************************
30 // ************************************************************************
31 qx.ui.basic.Atom.call(this, vText, vIcon, vIconWidth, vIconHeight, vFlash);
37 // ************************************************************************
39 // ************************************************************************
40 this.addEventListener("mouseover", this._onmouseover);
41 this.addEventListener("mouseout", this._onmouseout);
42 this.addEventListener("mousedown", this._onmousedown);
43 this.addEventListener("mouseup", this._onmouseup);
46 // ************************************************************************
48 // ************************************************************************
49 this.addEventListener("keydown", this._onkeydown);
50 this.addEventListener("keyup", this._onkeyup);
53 qx.OO.changeProperty({ name : "appearance", type : "string", defaultValue : "button" });
58 ---------------------------------------------------------------------------
60 ---------------------------------------------------------------------------
63 qx.Proto._onmouseover = function(e)
65 if (e.getTarget() != this) {
69 if (this.hasState("abandoned"))
71 this.removeState("abandoned");
72 this.addState("pressed");
75 this.addState("over");
78 qx.Proto._onmouseout = function(e)
80 if (e.getTarget() != this) {
84 this.removeState("over");
86 if (this.hasState("pressed"))
88 // Activate capturing if the button get a mouseout while
89 // the button is pressed.
90 this.setCapture(true);
92 this.removeState("pressed");
93 this.addState("abandoned");
97 qx.Proto._onmousedown = function(e)
99 if (e.getTarget() != this || !e.isLeftButtonPressed()) {
103 this.removeState("abandoned");
104 this.addState("pressed");
107 qx.Proto._onmouseup = function(e)
109 this.setCapture(false);
111 // We must remove the states before executing the command
112 // because in cases were the window lost the focus while
113 // executing we get the capture phase back (mouseout).
114 var hasPressed = this.hasState("pressed");
115 var hasAbandoned = this.hasState("abandoned");
118 this.removeState("pressed");
122 this.removeState("abandoned");
127 this.addState("over");
135 qx.Proto._onkeydown = function(e)
137 switch(e.getKeyIdentifier())
141 this.removeState("abandoned");
142 this.addState("pressed");
146 qx.Proto._onkeyup = function(e)
148 switch(e.getKeyIdentifier())
152 if (this.hasState("pressed"))
154 this.removeState("abandoned");
155 this.removeState("pressed");
169 ---------------------------------------------------------------------------
171 ---------------------------------------------------------------------------
174 qx.Proto.dispose = function()
176 if (this.getDisposed()) {
180 // ************************************************************************
182 // ************************************************************************
183 this.removeEventListener("mouseover", this._onmouseover, this);
184 this.removeEventListener("mouseout", this._onmouseout, this);
185 this.removeEventListener("mousedown", this._onmousedown, this);
186 this.removeEventListener("mouseup", this._onmouseup, this);
189 // ************************************************************************
191 // ************************************************************************
192 this.removeEventListener("keydown", this._onkeydown, this);
193 this.removeEventListener("keyup", this._onkeyup, this);
196 // ************************************************************************
198 // ************************************************************************
199 return qx.ui.basic.Atom.prototype.dispose.call(this);