summaryrefslogtreecommitdiff
path: root/webapps/qooxdoo-0.6.3-sdk/frontend/framework/source/class/qx/ui/pageview/tabview/Button.js
blob: 9566bb2a51361175e8920d46113cdfa3e58d76d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* ************************************************************************

   qooxdoo - the new era of web development

   http://qooxdoo.org

   Copyright:
     2004-2006 by 1&1 Internet AG, Germany, http://www.1and1.org

   License:
     LGPL 2.1: http://www.gnu.org/licenses/lgpl.html

   Authors:
     * Sebastian Werner (wpbasti)
     * Andreas Ecker (ecker)

************************************************************************ */

/* ************************************************************************

#module(ui_tabview)

************************************************************************ */

/**
 * @event closetab {qx.event.type.DataEvent}
 */
qx.OO.defineClass("qx.ui.pageview.tabview.Button", qx.ui.pageview.AbstractButton,
function(vText, vIcon, vIconWidth, vIconHeight, vFlash) {
  qx.ui.pageview.AbstractButton.call(this, vText, vIcon, vIconWidth, vIconHeight, vFlash);
});

qx.OO.changeProperty({ name : "appearance", type : "string", defaultValue : "tab-view-button" });



/*
---------------------------------------------------------------------------
  PROPERTIES
---------------------------------------------------------------------------
 */

/*!
  default Close Tab Button
 */
qx.OO.addProperty({ name : "showCloseButton", type : "boolean", defaultValue : false });

/*!
  Close Tab Icon
 */
qx.OO.addProperty({ name : "closeButtonImage", type : "string", defaultValue : "icon/16/cancel.png"});







/*
---------------------------------------------------------------------------
  EVENT HANDLER
---------------------------------------------------------------------------
*/

qx.Proto._onkeydown = function(e)
{
  var identifier = e.getKeyIdentifier();
  if (identifier == "Enter" || identifier == "Space") {
      // there is no toggeling, just make it checked
      this.setChecked(true);
  }
};


qx.Proto._onkeypress = function(e)
{
  switch(e.getKeyIdentifier())
  {
    case "Left":
      var vPrev = this.getPreviousSibling() || this.getParent().getLastChild();
      if (vPrev && vPrev != this)
      {
        // we want to enable the outline border, because
        // the user used the keyboard for activation
        delete qx.event.handler.FocusHandler.mouseFocus;

        // focus previous tab
        vPrev.setFocused(true);

        // and naturally make it also checked
        vPrev.setChecked(true);
      }
      break;

    case "Right":
      var vNext = this.getNextSibling() || this.getParent().getFirstVisibleChild();
      if (vNext && vNext != this)
      {
        // we want to enable the outline border, because
        // the user used the keyboard for activation
        delete qx.event.handler.FocusHandler.mouseFocus;

        // focus next tab
        vNext.setFocused(true);

        // and naturally make it also checked
        vNext.setChecked(true);
      }
      break;
  }
};


qx.Proto._ontabclose = function(e){
  this.createDispatchDataEvent("closetab", this);
}



/*
---------------------------------------------------------------------------
  MODIFIER
---------------------------------------------------------------------------
 */

qx.Proto._modifyShowCloseButton = function(propValue, propOldValue, propData) {

  // if no image exists, then create one
  if (!this._closeButtonImage) {
    this._closeButtonImage = new qx.ui.basic.Image(this.getCloseButtonImage());
  }
  if (propValue) {
    this._closeButtonImage.addEventListener("click", this._ontabclose, this);
    this.add(this._closeButtonImage);
  } else {
    this.remove(this._closeButtonImage);
    this._closeButtonImage.removeEventListener("click", this._ontabclose);
  }

  return true;
}

qx.Proto._modifyCloseButtonImage = function(propValue, propOldValue, propData) {
  if (this._closeButtonImage) {
    this._closeButtonImage.setSource(propValue);
  }

  return true;
}



/*
---------------------------------------------------------------------------
  APPEARANCE ADDITIONS
---------------------------------------------------------------------------
*/

qx.Proto._applyStateAppearance = function()
{
  this._states.firstChild = this.isFirstVisibleChild();
  this._states.lastChild = this.isLastVisibleChild();
  this._states.alignLeft = this.getView().getAlignTabsToLeft();
  this._states.barTop = this.getView().getPlaceBarOnTop();

  qx.ui.pageview.AbstractButton.prototype._applyStateAppearance.call(this);
}




/*
---------------------------------------------------------------------------
  DISPOSER
---------------------------------------------------------------------------
 */

qx.Proto.dispose = function() {
  if (this.getDisposed()) {
    return;
  }

  if(this._closeButtonImage){
    this._closeButtonImage.dispose();
    this._closeButtonImage = null;
  }

  return qx.ui.pageview.AbstractButton.prototype.dispose.call(this);
}