2010-05-20 11:18:46 -04:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
|
|
|
|
const Cairo = imports.cairo;
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Gtk = imports.gi.Gtk;
|
|
|
|
const Lang = imports.lang;
|
2010-07-22 08:34:02 -04:00
|
|
|
const Shell = imports.gi.Shell;
|
2010-05-20 11:18:46 -04:00
|
|
|
const Signals = imports.signals;
|
2010-07-22 08:34:02 -04:00
|
|
|
const St = imports.gi.St;
|
2010-05-20 11:18:46 -04:00
|
|
|
|
|
|
|
const BoxPointer = imports.ui.boxpointer;
|
2010-07-03 19:47:31 -04:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
const Params = imports.misc.params;
|
2010-05-20 11:18:46 -04:00
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
|
2010-06-17 08:17:01 -04:00
|
|
|
const Gettext = imports.gettext.domain('gnome-shell');
|
|
|
|
const _ = Gettext.gettext;
|
|
|
|
|
2010-10-20 16:41:54 -04:00
|
|
|
const SLIDER_SCROLL_STEP = 0.05; /* Slider scrolling step in % */
|
|
|
|
|
2010-07-03 19:47:31 -04:00
|
|
|
function PopupBaseMenuItem(params) {
|
|
|
|
this._init(params);
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
PopupBaseMenuItem.prototype = {
|
2010-07-03 19:47:31 -04:00
|
|
|
_init: function (params) {
|
|
|
|
params = Params.parse (params, { reactive: true,
|
|
|
|
activate: true,
|
|
|
|
hover: true });
|
2010-10-19 13:41:41 -04:00
|
|
|
this.actor = new Shell.GenericContainer({ style_class: 'popup-menu-item',
|
|
|
|
reactive: params.reactive,
|
2010-10-07 14:15:51 -04:00
|
|
|
track_hover: params.reactive,
|
|
|
|
can_focus: params.reactive });
|
2010-10-19 13:41:41 -04:00
|
|
|
this.actor.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
|
|
|
|
this.actor.connect('get-preferred-height', Lang.bind(this, this._getPreferredHeight));
|
|
|
|
this.actor.connect('allocate', Lang.bind(this, this._allocate));
|
|
|
|
this.actor.connect('style-changed', Lang.bind(this, this._onStyleChanged));
|
2010-05-20 11:18:46 -04:00
|
|
|
this.actor._delegate = this;
|
2010-10-19 13:41:41 -04:00
|
|
|
|
|
|
|
this._children = [];
|
2010-10-20 12:43:22 -04:00
|
|
|
this._dot = null;
|
2010-10-19 13:41:41 -04:00
|
|
|
this._columnWidths = null;
|
|
|
|
this._spacing = 0;
|
2010-05-20 11:18:46 -04:00
|
|
|
this.active = false;
|
|
|
|
|
2010-07-03 19:47:31 -04:00
|
|
|
if (params.reactive && params.activate) {
|
2010-10-07 14:15:51 -04:00
|
|
|
this.actor.connect('button-release-event', Lang.bind(this, this._onButtonReleaseEvent));
|
|
|
|
this.actor.connect('key-press-event', Lang.bind(this, this._onKeyPressEvent));
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
2010-07-03 19:47:31 -04:00
|
|
|
if (params.reactive && params.hover)
|
2010-10-07 14:15:51 -04:00
|
|
|
this.actor.connect('notify::hover', Lang.bind(this, this._onHoverChanged));
|
|
|
|
if (params.reactive)
|
|
|
|
this.actor.connect('key-focus-in', Lang.bind(this, this._onKeyFocusIn));
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2010-10-19 13:41:41 -04:00
|
|
|
_onStyleChanged: function (actor) {
|
2010-10-28 14:03:45 -04:00
|
|
|
this._spacing = actor.get_theme_node().get_length('spacing');
|
2010-10-19 13:41:41 -04:00
|
|
|
},
|
|
|
|
|
2010-10-07 14:15:51 -04:00
|
|
|
_onButtonReleaseEvent: function (actor, event) {
|
2010-11-01 11:03:28 -04:00
|
|
|
this.activate(event);
|
2010-10-07 14:15:51 -04:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onKeyPressEvent: function (actor, event) {
|
|
|
|
let symbol = event.get_key_symbol();
|
|
|
|
|
|
|
|
if (symbol == Clutter.KEY_space || symbol == Clutter.KEY_Return) {
|
2010-11-01 11:03:28 -04:00
|
|
|
this.activate(event);
|
2010-10-07 14:15:51 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onKeyFocusIn: function (actor) {
|
|
|
|
this.setActive(true);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onHoverChanged: function (actor) {
|
2010-05-20 11:18:46 -04:00
|
|
|
this.setActive(actor.hover);
|
|
|
|
},
|
|
|
|
|
|
|
|
activate: function (event) {
|
|
|
|
this.emit('activate', event);
|
|
|
|
},
|
|
|
|
|
|
|
|
setActive: function (active) {
|
|
|
|
let activeChanged = active != this.active;
|
|
|
|
|
|
|
|
if (activeChanged) {
|
|
|
|
this.active = active;
|
2010-10-07 14:15:51 -04:00
|
|
|
if (active) {
|
2010-05-20 11:18:46 -04:00
|
|
|
this.actor.add_style_pseudo_class('active');
|
2010-10-07 14:15:51 -04:00
|
|
|
this.actor.grab_key_focus();
|
|
|
|
} else
|
2010-05-20 11:18:46 -04:00
|
|
|
this.actor.remove_style_pseudo_class('active');
|
|
|
|
this.emit('active-changed', active);
|
|
|
|
}
|
2010-07-03 19:47:31 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
this.actor.destroy();
|
|
|
|
this.emit('destroy');
|
|
|
|
},
|
|
|
|
|
2010-11-17 14:10:12 -05:00
|
|
|
// adds an actor to the menu item; @params can contain %span
|
|
|
|
// (column span; defaults to 1, -1 means "all the remaining width"),
|
|
|
|
// %expand (defaults to #false), and %align (defaults to
|
|
|
|
// #St.Align.START)
|
|
|
|
addActor: function(child, params) {
|
|
|
|
params = Params.parse(params, { span: 1,
|
|
|
|
expand: false,
|
|
|
|
align: St.Align.START });
|
|
|
|
params.actor = child;
|
|
|
|
this._children.push(params);
|
2010-10-28 16:28:17 -04:00
|
|
|
this.actor.connect('destroy', Lang.bind(this, function () { this._removeChild(child); }));
|
2010-10-19 13:41:41 -04:00
|
|
|
this.actor.add_actor(child);
|
|
|
|
},
|
|
|
|
|
2010-10-28 16:28:17 -04:00
|
|
|
_removeChild: function(child) {
|
2010-10-19 13:41:41 -04:00
|
|
|
for (let i = 0; i < this._children.length; i++) {
|
|
|
|
if (this._children[i].actor == child) {
|
|
|
|
this._children.splice(i, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-10-28 16:28:17 -04:00
|
|
|
removeActor: function(child) {
|
|
|
|
this.actor.remove_actor(child);
|
|
|
|
this._removeChild(child);
|
|
|
|
},
|
|
|
|
|
2010-10-20 12:43:22 -04:00
|
|
|
setShowDot: function(show) {
|
|
|
|
if (show) {
|
|
|
|
if (this._dot)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._dot = new St.DrawingArea({ style_class: 'popup-menu-item-dot' });
|
|
|
|
this._dot.connect('repaint', Lang.bind(this, this._onRepaintDot));
|
|
|
|
this.actor.add_actor(this._dot);
|
|
|
|
} else {
|
|
|
|
if (!this._dot)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._dot.destroy();
|
|
|
|
this._dot = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onRepaintDot: function(area) {
|
|
|
|
let cr = area.get_context();
|
|
|
|
let [width, height] = area.get_surface_size();
|
2011-02-14 09:20:22 -05:00
|
|
|
let color = area.get_theme_node().get_foreground_color();
|
2010-10-20 12:43:22 -04:00
|
|
|
|
|
|
|
cr.setSourceRGBA (
|
|
|
|
color.red / 255,
|
|
|
|
color.green / 255,
|
|
|
|
color.blue / 255,
|
|
|
|
color.alpha / 255);
|
|
|
|
cr.arc(width / 2, height / 2, width / 3, 0, 2 * Math.PI);
|
|
|
|
cr.fill();
|
|
|
|
},
|
|
|
|
|
2010-10-19 13:41:41 -04:00
|
|
|
getColumnWidths: function() {
|
|
|
|
let widths = [];
|
|
|
|
for (let i = 0, col = 0; i < this._children.length; i++) {
|
|
|
|
let child = this._children[i];
|
|
|
|
let [min, natural] = child.actor.get_preferred_width(-1);
|
|
|
|
widths[col++] = natural;
|
|
|
|
if (child.span > 1) {
|
|
|
|
for (let j = 1; j < child.span; j++)
|
|
|
|
widths[col++] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return widths;
|
|
|
|
},
|
|
|
|
|
|
|
|
setColumnWidths: function(widths) {
|
|
|
|
this._columnWidths = widths;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getPreferredWidth: function(actor, forHeight, alloc) {
|
|
|
|
let width = 0;
|
|
|
|
if (this._columnWidths) {
|
|
|
|
for (let i = 0; i < this._columnWidths.length; i++) {
|
|
|
|
if (i > 0)
|
|
|
|
width += this._spacing;
|
|
|
|
width += this._columnWidths[i];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (let i = 0; i < this._children.length; i++) {
|
|
|
|
let child = this._children[i];
|
|
|
|
if (i > 0)
|
|
|
|
width += this._spacing;
|
|
|
|
let [min, natural] = child.actor.get_preferred_width(forHeight);
|
|
|
|
width += natural;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
alloc.min_size = alloc.natural_size = width;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getPreferredHeight: function(actor, forWidth, alloc) {
|
|
|
|
let height = 0;
|
|
|
|
for (let i = 0; i < this._children.length; i++) {
|
|
|
|
let child = this._children[i];
|
|
|
|
let [min, natural] = child.actor.get_preferred_height(-1);
|
|
|
|
if (natural > height)
|
|
|
|
height = natural;
|
|
|
|
}
|
|
|
|
alloc.min_size = alloc.natural_size = height;
|
|
|
|
},
|
|
|
|
|
|
|
|
_allocate: function(actor, box, flags) {
|
2010-10-20 12:43:22 -04:00
|
|
|
let height = box.y2 - box.y1;
|
|
|
|
|
|
|
|
if (this._dot) {
|
|
|
|
let dotBox = new Clutter.ActorBox();
|
|
|
|
let dotWidth = Math.round(box.x1 / 2);
|
|
|
|
|
|
|
|
dotBox.x1 = Math.round(box.x1 / 4);
|
|
|
|
dotBox.x2 = dotBox.x1 + dotWidth;
|
|
|
|
dotBox.y1 = Math.round(box.y1 + (height - dotWidth) / 2);
|
|
|
|
dotBox.y2 = dotBox.y1 + dotWidth;
|
|
|
|
this._dot.allocate(dotBox, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
let x = box.x1;
|
2010-10-19 13:41:41 -04:00
|
|
|
for (let i = 0, col = 0; i < this._children.length; i++) {
|
|
|
|
let child = this._children[i];
|
|
|
|
let childBox = new Clutter.ActorBox();
|
2010-11-17 14:10:12 -05:00
|
|
|
|
|
|
|
let [minWidth, naturalWidth] = child.actor.get_preferred_width(-1);
|
|
|
|
let availWidth, extraWidth;
|
2010-10-19 13:41:41 -04:00
|
|
|
if (this._columnWidths) {
|
|
|
|
if (child.span == -1)
|
2010-11-17 14:10:12 -05:00
|
|
|
availWidth = box.x2 - x;
|
2010-10-19 13:41:41 -04:00
|
|
|
else {
|
2010-11-17 14:10:12 -05:00
|
|
|
availWidth = 0;
|
2010-10-19 13:41:41 -04:00
|
|
|
for (let j = 0; j < child.span; j++)
|
2010-11-17 14:10:12 -05:00
|
|
|
availWidth += this._columnWidths[col++];
|
2010-10-19 13:41:41 -04:00
|
|
|
}
|
2010-11-17 14:10:12 -05:00
|
|
|
extraWidth = availWidth - naturalWidth;
|
2010-10-19 13:41:41 -04:00
|
|
|
} else {
|
2010-11-17 14:10:12 -05:00
|
|
|
availWidth = naturalWidth;
|
|
|
|
extraWidth = 0;
|
2010-10-19 13:41:41 -04:00
|
|
|
}
|
2010-11-17 14:10:12 -05:00
|
|
|
|
|
|
|
if (child.expand) {
|
|
|
|
childBox.x1 = x;
|
|
|
|
childBox.x2 = x + availWidth;
|
|
|
|
} else if (child.align === St.Align.CENTER) {
|
|
|
|
childBox.x1 = x + Math.round(extraWidth / 2);
|
|
|
|
childBox.x2 = childBox.x1 + naturalWidth;
|
|
|
|
} else if (child.align === St.Align.END) {
|
|
|
|
childBox.x2 = x + availWidth;
|
|
|
|
childBox.x1 = childBox.x2 - naturalWidth;
|
|
|
|
} else {
|
|
|
|
childBox.x1 = x;
|
|
|
|
childBox.x2 = x + naturalWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
let [minHeight, naturalHeight] = child.actor.get_preferred_height(-1);
|
|
|
|
childBox.y1 = Math.round(box.y1 + (height - naturalHeight) / 2);
|
|
|
|
childBox.y2 = childBox.y1 + naturalHeight;
|
|
|
|
|
2010-10-19 13:41:41 -04:00
|
|
|
child.actor.allocate(childBox, flags);
|
|
|
|
|
2010-11-17 14:10:12 -05:00
|
|
|
x += availWidth + this._spacing;
|
2010-10-19 13:41:41 -04:00
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
Signals.addSignalMethods(PopupBaseMenuItem.prototype);
|
|
|
|
|
2010-11-16 09:22:38 -05:00
|
|
|
function PopupMenuItem() {
|
|
|
|
this._init.apply(this, arguments);
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
PopupMenuItem.prototype = {
|
|
|
|
__proto__: PopupBaseMenuItem.prototype,
|
|
|
|
|
2010-11-16 09:22:38 -05:00
|
|
|
_init: function (text, params) {
|
|
|
|
PopupBaseMenuItem.prototype._init.call(this, params);
|
2010-05-20 11:18:46 -04:00
|
|
|
|
|
|
|
this.label = new St.Label({ text: text });
|
2010-10-19 13:41:41 -04:00
|
|
|
this.addActor(this.label);
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function PopupSeparatorMenuItem() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupSeparatorMenuItem.prototype = {
|
|
|
|
__proto__: PopupBaseMenuItem.prototype,
|
|
|
|
|
|
|
|
_init: function () {
|
2010-07-03 19:47:31 -04:00
|
|
|
PopupBaseMenuItem.prototype._init.call(this, { reactive: false });
|
2010-05-20 11:18:46 -04:00
|
|
|
|
|
|
|
this._drawingArea = new St.DrawingArea({ style_class: 'popup-separator-menu-item' });
|
2010-11-17 14:10:12 -05:00
|
|
|
this.addActor(this._drawingArea, { span: -1, expand: true });
|
2010-05-20 11:18:46 -04:00
|
|
|
this._drawingArea.connect('repaint', Lang.bind(this, this._onRepaint));
|
|
|
|
},
|
|
|
|
|
|
|
|
_onRepaint: function(area) {
|
|
|
|
let cr = area.get_context();
|
|
|
|
let themeNode = area.get_theme_node();
|
|
|
|
let [width, height] = area.get_surface_size();
|
StThemeNode: simplify use of get_color/get_double/get_length
Although within St itself there are situations where the semantics of
these functions (return TRUE or FALSE and return the actual value in
an out parameter) is useful, it's mostly just annoying at the
application level, where you generally know that the CSS property is
going to specified, and there is no especially sane fallback if it's
not.
So rename the current methods to lookup_color, lookup_double, and
lookup_length, and add new get_color, get_double, and get_length
methods that don't take an "inherit" parameter, and return their
values directly. (Well, except for get_color, due to the lack of (out
caller-allocates) in gjs.)
And update the code to use either the old or new methods as appropriate.
https://bugzilla.gnome.org/show_bug.cgi?id=632590
2010-09-26 17:38:36 -04:00
|
|
|
let margin = themeNode.get_length('-margin-horizontal');
|
|
|
|
let gradientHeight = themeNode.get_length('-gradient-height');
|
2011-02-14 09:20:22 -05:00
|
|
|
let startColor = themeNode.get_color('-gradient-start');
|
|
|
|
let endColor = themeNode.get_color('-gradient-end');
|
2010-05-20 11:18:46 -04:00
|
|
|
|
|
|
|
let gradientWidth = (width - margin * 2);
|
|
|
|
let gradientOffset = (height - gradientHeight) / 2;
|
|
|
|
let pattern = new Cairo.LinearGradient(margin, gradientOffset, width - margin, gradientOffset + gradientHeight);
|
|
|
|
pattern.addColorStopRGBA(0, startColor.red / 255, startColor.green / 255, startColor.blue / 255, startColor.alpha / 255);
|
|
|
|
pattern.addColorStopRGBA(0.5, endColor.red / 255, endColor.green / 255, endColor.blue / 255, endColor.alpha / 255);
|
|
|
|
pattern.addColorStopRGBA(1, startColor.red / 255, startColor.green / 255, startColor.blue / 255, startColor.alpha / 255);
|
|
|
|
cr.setSource(pattern);
|
|
|
|
cr.rectangle(margin, gradientOffset, gradientWidth, gradientHeight);
|
|
|
|
cr.fill();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-22 08:34:02 -04:00
|
|
|
function PopupSliderMenuItem() {
|
|
|
|
this._init.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupSliderMenuItem.prototype = {
|
|
|
|
__proto__: PopupBaseMenuItem.prototype,
|
|
|
|
|
|
|
|
_init: function(value) {
|
|
|
|
PopupBaseMenuItem.prototype._init.call(this, { activate: false });
|
|
|
|
|
2010-10-07 14:15:51 -04:00
|
|
|
this.actor.connect('key-press-event', Lang.bind(this, this._onKeyPressEvent));
|
|
|
|
|
2010-07-22 08:34:02 -04:00
|
|
|
if (isNaN(value))
|
|
|
|
// Avoid spreading NaNs around
|
|
|
|
throw TypeError('The slider value must be a number');
|
2010-07-22 20:39:44 -04:00
|
|
|
this._value = Math.max(Math.min(value, 1), 0);
|
2010-07-22 08:34:02 -04:00
|
|
|
|
|
|
|
this._slider = new St.DrawingArea({ style_class: 'popup-slider-menu-item', reactive: true });
|
2010-11-17 14:10:12 -05:00
|
|
|
this.addActor(this._slider, { span: -1, expand: true });
|
2010-07-22 08:34:02 -04:00
|
|
|
this._slider.connect('repaint', Lang.bind(this, this._sliderRepaint));
|
|
|
|
this._slider.connect('button-press-event', Lang.bind(this, this._startDragging));
|
2010-11-01 08:26:49 -04:00
|
|
|
this.actor.connect('scroll-event', Lang.bind(this, this._onScrollEvent));
|
2010-07-22 08:34:02 -04:00
|
|
|
|
|
|
|
this._releaseId = this._motionId = 0;
|
|
|
|
this._dragging = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
setValue: function(value) {
|
|
|
|
if (isNaN(value))
|
|
|
|
throw TypeError('The slider value must be a number');
|
|
|
|
|
2010-07-22 20:39:44 -04:00
|
|
|
this._value = Math.max(Math.min(value, 1), 0);
|
2010-07-22 08:34:02 -04:00
|
|
|
this._slider.queue_repaint();
|
|
|
|
},
|
|
|
|
|
|
|
|
_sliderRepaint: function(area) {
|
|
|
|
let cr = area.get_context();
|
|
|
|
let themeNode = area.get_theme_node();
|
|
|
|
let [width, height] = area.get_surface_size();
|
|
|
|
|
StThemeNode: simplify use of get_color/get_double/get_length
Although within St itself there are situations where the semantics of
these functions (return TRUE or FALSE and return the actual value in
an out parameter) is useful, it's mostly just annoying at the
application level, where you generally know that the CSS property is
going to specified, and there is no especially sane fallback if it's
not.
So rename the current methods to lookup_color, lookup_double, and
lookup_length, and add new get_color, get_double, and get_length
methods that don't take an "inherit" parameter, and return their
values directly. (Well, except for get_color, due to the lack of (out
caller-allocates) in gjs.)
And update the code to use either the old or new methods as appropriate.
https://bugzilla.gnome.org/show_bug.cgi?id=632590
2010-09-26 17:38:36 -04:00
|
|
|
let handleRadius = themeNode.get_length('-slider-handle-radius');
|
2010-07-22 08:34:02 -04:00
|
|
|
|
|
|
|
let sliderWidth = width - 2 * handleRadius;
|
StThemeNode: simplify use of get_color/get_double/get_length
Although within St itself there are situations where the semantics of
these functions (return TRUE or FALSE and return the actual value in
an out parameter) is useful, it's mostly just annoying at the
application level, where you generally know that the CSS property is
going to specified, and there is no especially sane fallback if it's
not.
So rename the current methods to lookup_color, lookup_double, and
lookup_length, and add new get_color, get_double, and get_length
methods that don't take an "inherit" parameter, and return their
values directly. (Well, except for get_color, due to the lack of (out
caller-allocates) in gjs.)
And update the code to use either the old or new methods as appropriate.
https://bugzilla.gnome.org/show_bug.cgi?id=632590
2010-09-26 17:38:36 -04:00
|
|
|
let sliderHeight = themeNode.get_length('-slider-height');
|
2010-07-22 08:34:02 -04:00
|
|
|
|
StThemeNode: simplify use of get_color/get_double/get_length
Although within St itself there are situations where the semantics of
these functions (return TRUE or FALSE and return the actual value in
an out parameter) is useful, it's mostly just annoying at the
application level, where you generally know that the CSS property is
going to specified, and there is no especially sane fallback if it's
not.
So rename the current methods to lookup_color, lookup_double, and
lookup_length, and add new get_color, get_double, and get_length
methods that don't take an "inherit" parameter, and return their
values directly. (Well, except for get_color, due to the lack of (out
caller-allocates) in gjs.)
And update the code to use either the old or new methods as appropriate.
https://bugzilla.gnome.org/show_bug.cgi?id=632590
2010-09-26 17:38:36 -04:00
|
|
|
let sliderBorderWidth = themeNode.get_length('-slider-border-width');
|
2010-07-22 08:34:02 -04:00
|
|
|
|
2011-02-14 09:20:22 -05:00
|
|
|
let sliderBorderColor = themeNode.get_color('-slider-border-color');
|
|
|
|
let sliderColor = themeNode.get_color('-slider-background-color');
|
2010-07-22 08:34:02 -04:00
|
|
|
|
|
|
|
cr.setSourceRGBA (
|
|
|
|
sliderColor.red / 255,
|
|
|
|
sliderColor.green / 255,
|
|
|
|
sliderColor.blue / 255,
|
|
|
|
sliderColor.alpha / 255);
|
|
|
|
cr.rectangle(handleRadius, (height - sliderHeight) / 2, sliderWidth, sliderHeight);
|
|
|
|
cr.fillPreserve();
|
|
|
|
cr.setSourceRGBA (
|
|
|
|
sliderBorderColor.red / 255,
|
|
|
|
sliderBorderColor.green / 255,
|
|
|
|
sliderBorderColor.blue / 255,
|
|
|
|
sliderBorderColor.alpha / 255);
|
|
|
|
cr.setLineWidth(sliderBorderWidth);
|
|
|
|
cr.stroke();
|
|
|
|
|
|
|
|
let handleY = height / 2;
|
2010-07-22 20:39:44 -04:00
|
|
|
let handleX = handleRadius + (width - 2 * handleRadius) * this._value;
|
2010-07-22 08:34:02 -04:00
|
|
|
|
2011-02-14 09:20:22 -05:00
|
|
|
let color = themeNode.get_foreground_color();
|
2010-07-22 08:34:02 -04:00
|
|
|
cr.setSourceRGBA (
|
|
|
|
color.red / 255,
|
|
|
|
color.green / 255,
|
|
|
|
color.blue / 255,
|
|
|
|
color.alpha / 255);
|
|
|
|
cr.arc(handleX, handleY, handleRadius, 0, 2 * Math.PI);
|
|
|
|
cr.fill();
|
|
|
|
},
|
|
|
|
|
|
|
|
_startDragging: function(actor, event) {
|
|
|
|
if (this._dragging) // don't allow two drags at the same time
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._dragging = true;
|
|
|
|
|
|
|
|
// FIXME: we should only grab the specific device that originated
|
|
|
|
// the event, but for some weird reason events are still delivered
|
|
|
|
// outside the slider if using clutter_grab_pointer_for_device
|
|
|
|
Clutter.grab_pointer(this._slider);
|
|
|
|
this._releaseId = this._slider.connect('button-release-event', Lang.bind(this, this._endDragging));
|
|
|
|
this._motionId = this._slider.connect('motion-event', Lang.bind(this, this._motionEvent));
|
|
|
|
let absX, absY;
|
|
|
|
[absX, absY] = event.get_coords();
|
|
|
|
this._moveHandle(absX, absY);
|
|
|
|
},
|
|
|
|
|
|
|
|
_endDragging: function() {
|
|
|
|
if (this._dragging) {
|
|
|
|
this._slider.disconnect(this._releaseId);
|
|
|
|
this._slider.disconnect(this._motionId);
|
|
|
|
|
|
|
|
Clutter.ungrab_pointer();
|
|
|
|
this._dragging = false;
|
|
|
|
|
2010-07-22 20:39:44 -04:00
|
|
|
this.emit('drag-end');
|
2010-07-22 08:34:02 -04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2010-10-20 16:41:54 -04:00
|
|
|
_onScrollEvent: function (actor, event) {
|
|
|
|
let direction = event.get_scroll_direction();
|
|
|
|
|
|
|
|
if (direction == Clutter.ScrollDirection.DOWN) {
|
|
|
|
this._value = Math.max(0, this._value - SLIDER_SCROLL_STEP);
|
|
|
|
}
|
|
|
|
else if (direction == Clutter.ScrollDirection.UP) {
|
|
|
|
this._value = Math.min(1, this._value + SLIDER_SCROLL_STEP);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._slider.queue_repaint();
|
|
|
|
this.emit('value-changed', this._value);
|
|
|
|
},
|
|
|
|
|
2010-07-22 08:34:02 -04:00
|
|
|
_motionEvent: function(actor, event) {
|
|
|
|
let absX, absY;
|
|
|
|
[absX, absY] = event.get_coords();
|
2011-02-08 14:19:04 -05:00
|
|
|
this._moveHandle(absX, absY);
|
2010-07-22 08:34:02 -04:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
_moveHandle: function(absX, absY) {
|
|
|
|
let relX, relY, sliderX, sliderY;
|
|
|
|
[sliderX, sliderY] = this._slider.get_transformed_position();
|
|
|
|
relX = absX - sliderX;
|
|
|
|
relY = absY - sliderY;
|
|
|
|
|
|
|
|
let width = this._slider.width;
|
StThemeNode: simplify use of get_color/get_double/get_length
Although within St itself there are situations where the semantics of
these functions (return TRUE or FALSE and return the actual value in
an out parameter) is useful, it's mostly just annoying at the
application level, where you generally know that the CSS property is
going to specified, and there is no especially sane fallback if it's
not.
So rename the current methods to lookup_color, lookup_double, and
lookup_length, and add new get_color, get_double, and get_length
methods that don't take an "inherit" parameter, and return their
values directly. (Well, except for get_color, due to the lack of (out
caller-allocates) in gjs.)
And update the code to use either the old or new methods as appropriate.
https://bugzilla.gnome.org/show_bug.cgi?id=632590
2010-09-26 17:38:36 -04:00
|
|
|
let handleRadius = this._slider.get_theme_node().get_length('-slider-handle-radius');
|
2010-07-22 08:34:02 -04:00
|
|
|
|
|
|
|
let newvalue;
|
|
|
|
if (relX < handleRadius)
|
|
|
|
newvalue = 0;
|
|
|
|
else if (relX > width - handleRadius)
|
|
|
|
newvalue = 1;
|
|
|
|
else
|
|
|
|
newvalue = (relX - handleRadius) / (width - 2 * handleRadius);
|
2010-07-22 20:39:44 -04:00
|
|
|
this._value = newvalue;
|
2010-07-22 08:34:02 -04:00
|
|
|
this._slider.queue_repaint();
|
2010-07-22 20:39:44 -04:00
|
|
|
this.emit('value-changed', this._value);
|
2010-07-22 08:34:02 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
get value() {
|
|
|
|
return this._value;
|
|
|
|
},
|
|
|
|
|
2010-10-07 14:15:51 -04:00
|
|
|
_onKeyPressEvent: function (actor, event) {
|
2010-07-22 08:34:02 -04:00
|
|
|
let key = event.get_key_symbol();
|
2010-10-07 14:15:51 -04:00
|
|
|
if (key == Clutter.KEY_Right || key == Clutter.KEY_Left) {
|
|
|
|
let delta = key == Clutter.KEY_Right ? 0.1 : -0.1;
|
2010-07-22 20:39:44 -04:00
|
|
|
this._value = Math.max(0, Math.min(this._value + delta, 1));
|
2010-07-22 08:34:02 -04:00
|
|
|
this._slider.queue_repaint();
|
|
|
|
this.emit('value-changed', this._value);
|
2010-07-22 20:39:44 -04:00
|
|
|
this.emit('drag-end');
|
2010-07-22 08:34:02 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-08 14:19:04 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
function Switch() {
|
|
|
|
this._init.apply(this, arguments);
|
2010-07-22 08:34:02 -04:00
|
|
|
}
|
|
|
|
|
2011-02-08 14:19:04 -05:00
|
|
|
Switch.prototype = {
|
|
|
|
_init: function(state) {
|
|
|
|
this.actor = new St.Bin({ style_class: 'toggle-switch' });
|
|
|
|
// Translators: this MUST be either "toggle-switch-us"
|
|
|
|
// (for toggle switches containing the English words
|
|
|
|
// "ON" and "OFF") or "toggle-switch-intl" (for toggle
|
|
|
|
// switches containing "◯" and "|"). Other values will
|
|
|
|
// simply result in invisible toggle switches.
|
|
|
|
this.actor.add_style_class_name(_("toggle-switch-us"));
|
|
|
|
this.setToggleState(state);
|
|
|
|
},
|
|
|
|
|
|
|
|
setToggleState: function(state) {
|
|
|
|
if (state)
|
|
|
|
this.actor.add_style_pseudo_class('checked');
|
|
|
|
else
|
|
|
|
this.actor.remove_style_pseudo_class('checked');
|
|
|
|
this.state = state;
|
|
|
|
},
|
|
|
|
|
|
|
|
toggle: function() {
|
|
|
|
this.setToggleState(!this.state);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-06-17 08:17:01 -04:00
|
|
|
function PopupSwitchMenuItem() {
|
|
|
|
this._init.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupSwitchMenuItem.prototype = {
|
|
|
|
__proto__: PopupBaseMenuItem.prototype,
|
|
|
|
|
|
|
|
_init: function(text, active) {
|
2010-07-03 19:47:31 -04:00
|
|
|
PopupBaseMenuItem.prototype._init.call(this);
|
2010-06-17 08:17:01 -04:00
|
|
|
|
|
|
|
this.label = new St.Label({ text: text });
|
2010-10-13 14:10:38 -04:00
|
|
|
this._switch = new Switch(active);
|
2010-06-17 08:17:01 -04:00
|
|
|
|
2010-10-19 13:41:41 -04:00
|
|
|
this.addActor(this.label);
|
2010-11-17 14:10:12 -05:00
|
|
|
this.addActor(this._switch.actor, { align: St.Align.END });
|
2010-06-17 08:17:01 -04:00
|
|
|
|
|
|
|
this.connect('activate', Lang.bind(this,function(from) {
|
|
|
|
this.toggle();
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
toggle: function() {
|
|
|
|
this._switch.toggle();
|
|
|
|
this.emit('toggled', this._switch.state);
|
|
|
|
},
|
|
|
|
|
|
|
|
get state() {
|
|
|
|
return this._switch.state;
|
|
|
|
},
|
|
|
|
|
|
|
|
setToggleState: function(state) {
|
|
|
|
this._switch.setToggleState(state);
|
|
|
|
}
|
2011-02-08 14:19:04 -05:00
|
|
|
};
|
2010-06-17 08:17:01 -04:00
|
|
|
|
2010-10-19 11:59:23 -04:00
|
|
|
function PopupImageMenuItem(text, iconName) {
|
|
|
|
this._init(text, iconName);
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
PopupImageMenuItem.prototype = {
|
|
|
|
__proto__: PopupBaseMenuItem.prototype,
|
|
|
|
|
2010-10-19 11:59:23 -04:00
|
|
|
_init: function (text, iconName) {
|
2010-07-03 19:47:31 -04:00
|
|
|
PopupBaseMenuItem.prototype._init.call(this);
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-07-06 03:51:53 -04:00
|
|
|
this.label = new St.Label({ text: text });
|
2010-10-19 13:41:41 -04:00
|
|
|
this.addActor(this.label);
|
2010-11-02 18:33:22 -04:00
|
|
|
this._icon = new St.Icon({ style_class: 'popup-menu-icon' });
|
2010-11-17 14:10:12 -05:00
|
|
|
this.addActor(this._icon, { align: St.Align.END });
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-10-19 11:59:23 -04:00
|
|
|
this.setIcon(iconName);
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2010-07-06 03:51:53 -04:00
|
|
|
setIcon: function(name) {
|
2010-11-02 18:33:22 -04:00
|
|
|
this._icon.icon_name = name;
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function mod(a, b) {
|
|
|
|
return (a + b) % b;
|
|
|
|
}
|
|
|
|
|
|
|
|
function findNextInCycle(items, current, direction) {
|
|
|
|
let cur;
|
|
|
|
|
|
|
|
if (items.length == 0)
|
|
|
|
return current;
|
|
|
|
else if (items.length == 1)
|
|
|
|
return items[0];
|
|
|
|
|
|
|
|
if (current)
|
|
|
|
cur = items.indexOf(current);
|
|
|
|
else if (direction == 1)
|
|
|
|
cur = items.length - 1;
|
|
|
|
else
|
|
|
|
cur = 0;
|
|
|
|
|
|
|
|
return items[mod(cur + direction, items.length)];
|
|
|
|
}
|
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
function PopupMenuBase() {
|
|
|
|
throw new TypeError('Trying to instantiate abstract class PopupMenuBase');
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
PopupMenuBase.prototype = {
|
|
|
|
_init: function(sourceActor, styleClass) {
|
2010-05-20 11:18:46 -04:00
|
|
|
this.sourceActor = sourceActor;
|
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
this.box = new St.BoxLayout({ style_class: styleClass,
|
|
|
|
vertical: true });
|
2010-10-07 14:15:51 -04:00
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
this.isOpen = false;
|
|
|
|
this._activeMenuItem = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
addAction: function(title, callback) {
|
|
|
|
var menuItem = new PopupMenuItem(title);
|
|
|
|
this.addMenuItem(menuItem);
|
|
|
|
menuItem.connect('activate', Lang.bind(this, function (menuItem, event) {
|
|
|
|
callback(event);
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2010-11-16 14:35:51 -05:00
|
|
|
addMenuItem: function(menuItem, position) {
|
2010-12-20 13:10:43 -05:00
|
|
|
let before_item = null;
|
|
|
|
if (position == undefined) {
|
2010-11-01 11:03:28 -04:00
|
|
|
this.box.add(menuItem.actor);
|
2010-12-20 13:10:43 -05:00
|
|
|
} else {
|
|
|
|
let items = this.getMenuItems();
|
|
|
|
if (position < items.length) {
|
|
|
|
before_item = items[position].actor;
|
|
|
|
this.box.insert_before(menuItem.actor, before_item);
|
|
|
|
} else
|
|
|
|
this.box.add(menuItem.actor);
|
|
|
|
}
|
2010-11-01 11:03:28 -04:00
|
|
|
if (menuItem instanceof PopupSubMenuMenuItem) {
|
2010-12-20 13:10:43 -05:00
|
|
|
if (before_item == null)
|
2010-11-01 11:03:28 -04:00
|
|
|
this.box.add(menuItem.menu.actor);
|
|
|
|
else
|
2010-12-20 13:10:43 -05:00
|
|
|
this.box.insert_before(menuItem.menu.actor, before_item);
|
2010-11-01 11:03:28 -04:00
|
|
|
menuItem._subMenuActivateId = menuItem.menu.connect('activate', Lang.bind(this, function() {
|
|
|
|
this.emit('activate');
|
2010-11-18 16:18:54 -05:00
|
|
|
this.close(true);
|
2010-11-01 11:03:28 -04:00
|
|
|
}));
|
|
|
|
menuItem._subMenuActiveChangeId = menuItem.menu.connect('active-changed', Lang.bind(this, function(submenu, submenuItem) {
|
|
|
|
if (this._activeMenuItem && this._activeMenuItem != submenuItem)
|
|
|
|
this._activeMenuItem.setActive(false);
|
|
|
|
this._activeMenuItem = submenuItem;
|
|
|
|
this.emit('active-changed', submenuItem);
|
|
|
|
}));
|
|
|
|
menuItem._closingId = this.connect('open-state-changed', function(self, open) {
|
|
|
|
if (!open)
|
2010-11-18 16:18:54 -05:00
|
|
|
menuItem.menu.close(false);
|
2010-11-01 11:03:28 -04:00
|
|
|
});
|
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
menuItem._activeChangeId = menuItem.connect('active-changed', Lang.bind(this, function (menuItem, active) {
|
|
|
|
if (active && this._activeMenuItem != menuItem) {
|
|
|
|
if (this._activeMenuItem)
|
|
|
|
this._activeMenuItem.setActive(false);
|
|
|
|
this._activeMenuItem = menuItem;
|
|
|
|
this.emit('active-changed', menuItem);
|
|
|
|
} else if (!active && this._activeMenuItem == menuItem) {
|
|
|
|
this._activeMenuItem = null;
|
|
|
|
this.emit('active-changed', null);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
menuItem._activateId = menuItem.connect('activate', Lang.bind(this, function (menuItem, event) {
|
|
|
|
this.emit('activate', menuItem);
|
2010-11-18 16:18:54 -05:00
|
|
|
this.close(true);
|
2010-05-20 11:18:46 -04:00
|
|
|
}));
|
2010-07-03 19:47:31 -04:00
|
|
|
menuItem.connect('destroy', Lang.bind(this, function(emitter) {
|
|
|
|
menuItem.disconnect(menuItem._activateId);
|
|
|
|
menuItem.disconnect(menuItem._activeChangeId);
|
2010-11-01 11:03:28 -04:00
|
|
|
if (menuItem.menu) {
|
|
|
|
menuItem.menu.disconnect(menuItem._subMenuActivateId);
|
|
|
|
menuItem.menu.disconnect(menuItem._subMenuActiveChangeId);
|
|
|
|
this.disconnect(menuItem._closingId);
|
|
|
|
}
|
2010-07-03 19:47:31 -04:00
|
|
|
if (menuItem == this._activeMenuItem)
|
|
|
|
this._activeMenuItem = null;
|
|
|
|
}));
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
getColumnWidths: function() {
|
|
|
|
let columnWidths = [];
|
|
|
|
let items = this.box.get_children();
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
if (items[i]._delegate instanceof PopupBaseMenuItem || items[i]._delegate instanceof PopupMenuBase) {
|
|
|
|
let itemColumnWidths = items[i]._delegate.getColumnWidths();
|
|
|
|
for (let j = 0; j < itemColumnWidths.length; j++) {
|
|
|
|
if (j >= columnWidths.length || itemColumnWidths[j] > columnWidths[j])
|
|
|
|
columnWidths[j] = itemColumnWidths[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return columnWidths;
|
|
|
|
},
|
|
|
|
|
|
|
|
setColumnWidths: function(widths) {
|
|
|
|
let items = this.box.get_children();
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
if (items[i]._delegate instanceof PopupBaseMenuItem || items[i]._delegate instanceof PopupMenuBase)
|
|
|
|
items[i]._delegate.setColumnWidths(widths);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
addActor: function(actor) {
|
2010-11-01 11:03:28 -04:00
|
|
|
this.box.add(actor);
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
getMenuItems: function() {
|
2010-11-01 11:03:28 -04:00
|
|
|
return this.box.get_children().map(function (actor) { return actor._delegate; }).filter(function(item) { return item instanceof PopupBaseMenuItem; });
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
removeAll: function() {
|
|
|
|
let children = this.getMenuItems();
|
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
|
let item = children[i];
|
2010-07-03 19:47:31 -04:00
|
|
|
item.destroy();
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-07-03 19:47:31 -04:00
|
|
|
activateFirst: function() {
|
2010-11-01 11:03:28 -04:00
|
|
|
let children = this.box.get_children();
|
2010-07-03 19:47:31 -04:00
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
|
let actor = children[i];
|
2010-11-01 11:03:28 -04:00
|
|
|
if (actor._delegate && actor._delegate instanceof PopupBaseMenuItem && actor.visible && actor.reactive) {
|
2010-07-03 19:47:31 -04:00
|
|
|
actor._delegate.setActive(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
toggle: function() {
|
2010-05-20 11:18:46 -04:00
|
|
|
if (this.isOpen)
|
2010-11-18 16:18:54 -05:00
|
|
|
this.close(true);
|
2010-11-01 11:03:28 -04:00
|
|
|
else
|
2010-11-18 16:18:54 -05:00
|
|
|
this.open(true);
|
2010-11-01 11:03:28 -04:00
|
|
|
},
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
destroy: function() {
|
|
|
|
this.removeAll();
|
|
|
|
this.actor.destroy();
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
this.emit('destroy');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Signals.addSignalMethods(PopupMenuBase.prototype);
|
2010-06-12 12:13:04 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
function PopupMenu() {
|
|
|
|
this._init.apply(this, arguments);
|
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
PopupMenu.prototype = {
|
|
|
|
__proto__: PopupMenuBase.prototype,
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
_init: function(sourceActor, alignment, arrowSide, gap) {
|
|
|
|
PopupMenuBase.prototype._init.call (this, sourceActor, 'popup-menu-content');
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
this._alignment = alignment;
|
|
|
|
this._arrowSide = arrowSide;
|
|
|
|
this._gap = gap;
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
this._boxPointer = new BoxPointer.BoxPointer(arrowSide,
|
|
|
|
{ x_fill: true,
|
|
|
|
y_fill: true,
|
|
|
|
x_align: St.Align.START });
|
|
|
|
this.actor = this._boxPointer.actor;
|
|
|
|
this.actor._delegate = this;
|
|
|
|
this.actor.style_class = 'popup-menu-boxpointer';
|
|
|
|
this._boxWrapper = new Shell.GenericContainer();
|
|
|
|
this._boxWrapper.connect('get-preferred-width', Lang.bind(this, this._boxGetPreferredWidth));
|
|
|
|
this._boxWrapper.connect('get-preferred-height', Lang.bind(this, this._boxGetPreferredHeight));
|
|
|
|
this._boxWrapper.connect('allocate', Lang.bind(this, this._boxAllocate));
|
|
|
|
this._boxPointer.bin.set_child(this._boxWrapper);
|
|
|
|
this._boxWrapper.add_actor(this.box);
|
|
|
|
this.actor.add_style_class_name('popup-menu');
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
global.focus_manager.add_group(this.actor);
|
2010-05-20 11:18:46 -04:00
|
|
|
this.actor.reactive = true;
|
2010-11-01 11:03:28 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_boxGetPreferredWidth: function (actor, forHeight, alloc) {
|
|
|
|
let columnWidths = this.getColumnWidths();
|
|
|
|
this.setColumnWidths(columnWidths);
|
|
|
|
|
|
|
|
// Now they will request the right sizes
|
|
|
|
[alloc.min_size, alloc.natural_size] = this.box.get_preferred_width(forHeight);
|
|
|
|
},
|
|
|
|
|
|
|
|
_boxGetPreferredHeight: function (actor, forWidth, alloc) {
|
|
|
|
[alloc.min_size, alloc.natural_size] = this.box.get_preferred_height(forWidth);
|
|
|
|
},
|
|
|
|
|
|
|
|
_boxAllocate: function (actor, box, flags) {
|
|
|
|
this.box.allocate(box, flags);
|
|
|
|
},
|
|
|
|
|
|
|
|
setArrowOrigin: function(origin) {
|
|
|
|
this._boxPointer.setArrowOrigin(origin);
|
|
|
|
},
|
|
|
|
|
2010-11-18 16:18:54 -05:00
|
|
|
open: function(animate) {
|
2010-11-01 11:03:28 -04:00
|
|
|
if (this.isOpen)
|
|
|
|
return;
|
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
this.isOpen = true;
|
2010-11-01 11:03:28 -04:00
|
|
|
|
|
|
|
this._boxPointer.setPosition(this.sourceActor, this._gap, this._alignment);
|
2010-11-18 16:18:54 -05:00
|
|
|
this._boxPointer.show(animate);
|
2010-11-01 11:03:28 -04:00
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
this.emit('open-state-changed', true);
|
|
|
|
},
|
|
|
|
|
2010-11-18 16:18:54 -05:00
|
|
|
close: function(animate) {
|
2010-05-20 11:18:46 -04:00
|
|
|
if (!this.isOpen)
|
|
|
|
return;
|
|
|
|
|
2010-07-03 19:47:31 -04:00
|
|
|
if (this._activeMenuItem)
|
|
|
|
this._activeMenuItem.setActive(false);
|
2010-11-01 11:03:28 -04:00
|
|
|
|
2010-11-18 16:18:54 -05:00
|
|
|
this._boxPointer.hide(animate);
|
2010-11-01 11:03:28 -04:00
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
this.isOpen = false;
|
|
|
|
this.emit('open-state-changed', false);
|
2010-11-01 11:03:28 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function PopupSubMenu() {
|
|
|
|
this._init.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupSubMenu.prototype = {
|
|
|
|
__proto__: PopupMenuBase.prototype,
|
|
|
|
|
|
|
|
_init: function(sourceActor, sourceArrow) {
|
|
|
|
PopupMenuBase.prototype._init.call(this, sourceActor, 'popup-sub-menu');
|
|
|
|
|
|
|
|
this._arrow = sourceArrow;
|
|
|
|
this._arrow.rotation_center_z_gravity = Clutter.Gravity.CENTER;
|
|
|
|
|
|
|
|
this.actor = this.box;
|
|
|
|
this.actor._delegate = this;
|
|
|
|
this.actor.clip_to_allocation = true;
|
|
|
|
this.actor.connect('key-press-event', Lang.bind(this, this._onKeyPressEvent));
|
|
|
|
this.actor.hide();
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2010-11-18 16:18:54 -05:00
|
|
|
open: function(animate) {
|
2010-05-20 11:18:46 -04:00
|
|
|
if (this.isOpen)
|
2010-11-01 11:03:28 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
this.isOpen = true;
|
|
|
|
|
2010-11-18 16:18:54 -05:00
|
|
|
// we don't implement the !animate case because that doesn't
|
|
|
|
// currently get used...
|
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
let [naturalHeight, minHeight] = this.actor.get_preferred_height(-1);
|
|
|
|
this.actor.height = 0;
|
|
|
|
this.actor.show();
|
|
|
|
this.actor._arrow_rotation = this._arrow.rotation_angle_z;
|
|
|
|
Tweener.addTween(this.actor,
|
|
|
|
{ _arrow_rotation: 90,
|
|
|
|
height: naturalHeight,
|
|
|
|
time: 0.25,
|
|
|
|
onUpdateScope: this,
|
|
|
|
onUpdate: function() {
|
|
|
|
this._arrow.rotation_angle_z = this.actor._arrow_rotation;
|
|
|
|
},
|
|
|
|
onCompleteScope: this,
|
|
|
|
onComplete: function() {
|
|
|
|
this.actor.set_height(-1);
|
|
|
|
this.emit('open-state-changed', true);
|
|
|
|
}
|
|
|
|
});
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2010-11-18 16:18:54 -05:00
|
|
|
close: function(animate) {
|
2010-11-01 11:03:28 -04:00
|
|
|
if (!this.isOpen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.isOpen = false;
|
|
|
|
|
|
|
|
if (this._activeMenuItem)
|
2010-10-07 14:15:51 -04:00
|
|
|
this._activeMenuItem.setActive(false);
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-11-18 16:18:54 -05:00
|
|
|
if (animate) {
|
|
|
|
this.actor._arrow_rotation = this._arrow.rotation_angle_z;
|
|
|
|
Tweener.addTween(this.actor,
|
|
|
|
{ _arrow_rotation: 0,
|
|
|
|
height: 0,
|
|
|
|
time: 0.25,
|
|
|
|
onCompleteScope: this,
|
|
|
|
onComplete: function() {
|
|
|
|
this.actor.hide();
|
|
|
|
this.actor.set_height(-1);
|
|
|
|
|
|
|
|
this.emit('open-state-changed', false);
|
|
|
|
},
|
|
|
|
onUpdateScope: this,
|
|
|
|
onUpdate: function() {
|
|
|
|
this._arrow.rotation_angle_z = this.actor._arrow_rotation;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this._arrow.rotation_angle_z = 0;
|
|
|
|
this.actor.hide();
|
2010-11-01 11:03:28 -04:00
|
|
|
|
2010-11-18 16:18:54 -05:00
|
|
|
this.isOpen = false;
|
|
|
|
this.emit('open-state-changed', false);
|
|
|
|
}
|
2010-07-03 19:47:31 -04:00
|
|
|
},
|
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
_onKeyPressEvent: function(actor, event) {
|
|
|
|
// Move focus back to parent menu if the user types Left.
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
if (this.isOpen && event.get_key_symbol() == Clutter.KEY_Left) {
|
2010-11-18 16:18:54 -05:00
|
|
|
this.close(true);
|
2010-11-01 11:03:28 -04:00
|
|
|
this.sourceActor._delegate.setActive(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-03 19:47:31 -04:00
|
|
|
function PopupSubMenuMenuItem() {
|
|
|
|
this._init.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupSubMenuMenuItem.prototype = {
|
|
|
|
__proto__: PopupBaseMenuItem.prototype,
|
|
|
|
|
|
|
|
_init: function(text) {
|
2010-11-01 11:03:28 -04:00
|
|
|
PopupBaseMenuItem.prototype._init.call(this);
|
|
|
|
|
|
|
|
this.actor.add_style_class_name('popup-submenu-menu-item');
|
2010-07-03 19:47:31 -04:00
|
|
|
|
|
|
|
this.label = new St.Label({ text: text });
|
2010-10-19 13:41:41 -04:00
|
|
|
this.addActor(this.label);
|
2010-11-01 11:03:28 -04:00
|
|
|
this._triangle = new St.Label({ text: '\u25B8' });
|
|
|
|
this.addActor(this._triangle, { align: St.Align.END });
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
this.menu = new PopupSubMenu(this.actor, this._triangle);
|
|
|
|
this.menu.connect('open-state-changed', Lang.bind(this, this._subMenuOpenStateChanged));
|
2010-07-03 19:47:31 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_subMenuOpenStateChanged: function(menu, open) {
|
2010-11-01 11:03:28 -04:00
|
|
|
if (open)
|
|
|
|
this.actor.add_style_pseudo_class('open');
|
|
|
|
else
|
|
|
|
this.actor.remove_style_pseudo_class('open');
|
2010-07-03 19:47:31 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
2010-11-01 11:03:28 -04:00
|
|
|
this.menu.destroy();
|
2010-07-03 19:47:31 -04:00
|
|
|
PopupBaseMenuItem.prototype.destroy.call(this);
|
|
|
|
},
|
|
|
|
|
2010-10-07 14:15:51 -04:00
|
|
|
_onKeyPressEvent: function(actor, event) {
|
|
|
|
if (event.get_key_symbol() == Clutter.KEY_Right) {
|
2010-11-18 16:18:54 -05:00
|
|
|
this.menu.open(true);
|
2010-07-03 19:47:31 -04:00
|
|
|
this.menu.activateFirst();
|
|
|
|
return true;
|
|
|
|
}
|
2010-11-01 11:03:28 -04:00
|
|
|
return PopupBaseMenuItem.prototype._onKeyPressEvent.call(this, actor, event);
|
2010-07-03 19:47:31 -04:00
|
|
|
},
|
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
activate: function(event) {
|
2010-11-18 16:18:54 -05:00
|
|
|
this.menu.open(true);
|
2010-07-03 19:47:31 -04:00
|
|
|
},
|
|
|
|
|
2010-11-01 11:03:28 -04:00
|
|
|
_onButtonReleaseEvent: function(actor) {
|
|
|
|
this.menu.toggle();
|
2010-07-03 19:47:31 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
/* Basic implementation of a menu manager.
|
|
|
|
* Call addMenu to add menus
|
|
|
|
*/
|
|
|
|
function PopupMenuManager(owner) {
|
|
|
|
this._init(owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupMenuManager.prototype = {
|
|
|
|
_init: function(owner) {
|
|
|
|
this._owner = owner;
|
|
|
|
this.grabbed = false;
|
|
|
|
|
|
|
|
this._eventCaptureId = 0;
|
2010-10-07 14:15:51 -04:00
|
|
|
this._keyPressEventId = 0;
|
2010-05-20 11:18:46 -04:00
|
|
|
this._enterEventId = 0;
|
|
|
|
this._leaveEventId = 0;
|
|
|
|
this._activeMenu = null;
|
|
|
|
this._menus = [];
|
2010-11-03 13:30:08 -04:00
|
|
|
this._preGrabInputMode = null;
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2010-10-07 14:15:51 -04:00
|
|
|
addMenu: function(menu, position) {
|
2010-06-25 08:55:03 -04:00
|
|
|
let menudata = {
|
|
|
|
menu: menu,
|
|
|
|
openStateChangeId: menu.connect('open-state-changed', Lang.bind(this, this._onMenuOpenState)),
|
2010-09-29 12:12:38 -04:00
|
|
|
destroyId: menu.connect('destroy', Lang.bind(this, this._onMenuDestroy)),
|
2010-06-25 08:55:03 -04:00
|
|
|
enterId: 0,
|
2010-11-03 13:30:08 -04:00
|
|
|
focusInId: 0,
|
|
|
|
focusOutId: 0
|
2010-06-25 08:55:03 -04:00
|
|
|
};
|
2010-05-20 11:18:46 -04:00
|
|
|
|
|
|
|
let source = menu.sourceActor;
|
|
|
|
if (source) {
|
2010-10-07 14:15:51 -04:00
|
|
|
menudata.enterId = source.connect('enter-event', Lang.bind(this, function() { this._onMenuSourceEnter(menu); }));
|
2010-11-03 13:30:08 -04:00
|
|
|
menudata.focusInId = source.connect('key-focus-in', Lang.bind(this, function() { this._onMenuSourceEnter(menu); }));
|
|
|
|
menudata.focusOutId = source.connect('key-focus-out', Lang.bind(this, function() { this._onKeyFocusOut(menu); }));
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
2010-06-25 08:55:03 -04:00
|
|
|
|
|
|
|
if (position == undefined)
|
|
|
|
this._menus.push(menudata);
|
|
|
|
else
|
|
|
|
this._menus.splice(position, 0, menudata);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeMenu: function(menu) {
|
|
|
|
if (menu == this._activeMenu)
|
|
|
|
this._closeMenu();
|
2010-07-03 19:47:31 -04:00
|
|
|
|
2010-06-25 08:55:03 -04:00
|
|
|
let position = this._findMenu(menu);
|
|
|
|
if (position == -1) // not a menu we manage
|
|
|
|
return;
|
|
|
|
|
|
|
|
let menudata = this._menus[position];
|
|
|
|
menu.disconnect(menudata.openStateChangeId);
|
2010-07-03 19:47:31 -04:00
|
|
|
menu.disconnect(menudata.destroyId);
|
2010-06-25 08:55:03 -04:00
|
|
|
|
|
|
|
if (menudata.enterId)
|
|
|
|
menu.sourceActor.disconnect(menudata.enterId);
|
2010-11-03 13:30:08 -04:00
|
|
|
if (menudata.focusInId)
|
|
|
|
menu.sourceActor.disconnect(menudata.focusInId);
|
|
|
|
if (menudata.focusOutId)
|
|
|
|
menu.sourceActor.disconnect(menudata.focusOutId);
|
2010-06-25 08:55:03 -04:00
|
|
|
|
|
|
|
this._menus.splice(position, 1);
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2010-11-03 13:30:08 -04:00
|
|
|
_grab: function() {
|
2010-05-20 11:18:46 -04:00
|
|
|
Main.pushModal(this._owner.actor);
|
|
|
|
|
|
|
|
this._eventCaptureId = global.stage.connect('captured-event', Lang.bind(this, this._onEventCapture));
|
2010-10-07 14:15:51 -04:00
|
|
|
this._keyPressEventId = global.stage.connect('key-press-event', Lang.bind(this, this._onKeyPressEvent));
|
2010-05-20 11:18:46 -04:00
|
|
|
// captured-event doesn't see enter/leave events
|
|
|
|
this._enterEventId = global.stage.connect('enter-event', Lang.bind(this, this._onEventCapture));
|
|
|
|
this._leaveEventId = global.stage.connect('leave-event', Lang.bind(this, this._onEventCapture));
|
|
|
|
|
|
|
|
this.grabbed = true;
|
|
|
|
},
|
|
|
|
|
2010-11-03 13:30:08 -04:00
|
|
|
_ungrab: function() {
|
2010-05-20 11:18:46 -04:00
|
|
|
global.stage.disconnect(this._eventCaptureId);
|
|
|
|
this._eventCaptureId = 0;
|
2010-10-07 14:15:51 -04:00
|
|
|
global.stage.disconnect(this._keyPressEventId);
|
|
|
|
this._keyPressEventId = 0;
|
2010-05-20 11:18:46 -04:00
|
|
|
global.stage.disconnect(this._enterEventId);
|
|
|
|
this._enterEventId = 0;
|
|
|
|
global.stage.disconnect(this._leaveEventId);
|
|
|
|
this._leaveEventId = 0;
|
|
|
|
|
|
|
|
this.grabbed = false;
|
2010-10-07 14:15:51 -04:00
|
|
|
Main.popModal(this._owner.actor);
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_onMenuOpenState: function(menu, open) {
|
2010-10-07 14:15:51 -04:00
|
|
|
if (open) {
|
2010-11-03 13:30:08 -04:00
|
|
|
if (!this.grabbed) {
|
|
|
|
this._preGrabInputMode = global.stage_input_mode;
|
|
|
|
this._grab();
|
|
|
|
}
|
2010-05-20 11:18:46 -04:00
|
|
|
this._activeMenu = menu;
|
2010-11-03 13:30:08 -04:00
|
|
|
|
|
|
|
// if the focus is not already associated with the menu,
|
|
|
|
// then focus the menu
|
|
|
|
let focus = global.stage.key_focus;
|
|
|
|
if (!this._activeMenuContains(focus))
|
|
|
|
menu.sourceActor.grab_key_focus();
|
2010-10-07 14:15:51 -04:00
|
|
|
} else if (menu == this._activeMenu) {
|
2010-11-03 13:30:08 -04:00
|
|
|
let focus = global.stage.key_focus;
|
|
|
|
let fromActive = this._activeMenuContains(focus);
|
|
|
|
|
2010-10-07 14:15:51 -04:00
|
|
|
if (this.grabbed)
|
2010-11-03 13:30:08 -04:00
|
|
|
this._ungrab();
|
|
|
|
this._activeMenu = null;
|
|
|
|
|
|
|
|
// If keynav was in effect before we grabbed, then we need
|
|
|
|
// to properly re-establish it after we ungrab. (popModal
|
|
|
|
// will have unset the focus.) If some part of the menu
|
|
|
|
// was focused at the time of the ungrab then focus its
|
|
|
|
// sourceActor. Otherwise just reset the focus to where it
|
|
|
|
// was right before the ungrab.
|
|
|
|
if (this._preGrabInputMode == Shell.StageInputMode.FOCUSED) {
|
|
|
|
global.stage_input_mode = Shell.StageInputMode.FOCUSED;
|
|
|
|
if (fromActive)
|
|
|
|
menu.sourceActor.grab_key_focus();
|
|
|
|
else
|
|
|
|
focus.grab_key_focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// change the currently-open menu without dropping grab
|
|
|
|
_changeMenu: function(newMenu) {
|
|
|
|
if (this._activeMenu) {
|
|
|
|
// _onOpenMenuState will drop the grab if it sees
|
|
|
|
// this._activeMenu being closed; so clear _activeMenu
|
|
|
|
// before closing it to keep that from happening
|
|
|
|
let oldMenu = this._activeMenu;
|
|
|
|
this._activeMenu = null;
|
2010-11-18 16:18:54 -05:00
|
|
|
oldMenu.close(false);
|
|
|
|
newMenu.open(false);
|
|
|
|
} else
|
|
|
|
newMenu.open(true);
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2010-10-07 14:15:51 -04:00
|
|
|
_onMenuSourceEnter: function(menu) {
|
2010-05-20 11:18:46 -04:00
|
|
|
if (!this.grabbed || menu == this._activeMenu)
|
|
|
|
return false;
|
|
|
|
|
2010-11-03 13:30:08 -04:00
|
|
|
this._changeMenu(menu);
|
2010-05-20 11:18:46 -04:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2010-11-03 13:30:08 -04:00
|
|
|
_onKeyFocusOut: function(menu) {
|
|
|
|
if (!this.grabbed || menu != this._activeMenu)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// We want to close the menu if the focus has moved somewhere
|
|
|
|
// other than inside the menu or to another menu's sourceActor.
|
|
|
|
// Unfortunately, when key-focus-out is emitted,
|
|
|
|
// stage.key_focus will be null. So we have to wait until
|
|
|
|
// after it emits the key-focus-in as well.
|
|
|
|
let id = global.stage.connect('notify::key-focus', Lang.bind(this,
|
|
|
|
function () {
|
|
|
|
global.stage.disconnect(id);
|
|
|
|
|
|
|
|
if (menu != this._activeMenu)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let focus = global.stage.key_focus;
|
|
|
|
if (!focus || this._activeMenuContains(focus))
|
|
|
|
return;
|
|
|
|
if (focus._delegate && this._findMenu(focus._delegate.menu) != -1)
|
|
|
|
return;
|
2010-11-18 16:18:54 -05:00
|
|
|
menu.close(true);
|
2010-11-03 13:30:08 -04:00
|
|
|
}));
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
2010-07-03 19:47:31 -04:00
|
|
|
_onMenuDestroy: function(menu) {
|
|
|
|
this.removeMenu(menu);
|
|
|
|
},
|
|
|
|
|
2010-11-03 13:30:08 -04:00
|
|
|
_activeMenuContains: function(actor) {
|
2010-05-20 11:18:46 -04:00
|
|
|
return this._activeMenu != null
|
2010-11-03 13:30:08 -04:00
|
|
|
&& (this._activeMenu.actor.contains(actor) ||
|
|
|
|
(this._activeMenu.sourceActor && this._activeMenu.sourceActor.contains(actor)));
|
|
|
|
},
|
|
|
|
|
|
|
|
_eventIsOnActiveMenu: function(event) {
|
|
|
|
return this._activeMenuContains(event.get_source());
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_eventIsOnAnyMenuSource: function(event) {
|
|
|
|
let src = event.get_source();
|
|
|
|
for (let i = 0; i < this._menus.length; i++) {
|
2010-06-25 08:55:03 -04:00
|
|
|
let menu = this._menus[i].menu;
|
2010-07-19 17:27:56 -04:00
|
|
|
if (menu.sourceActor && menu.sourceActor.contains(src))
|
2010-05-20 11:18:46 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2010-06-25 08:55:03 -04:00
|
|
|
_findMenu: function(item) {
|
|
|
|
for (let i = 0; i < this._menus.length; i++) {
|
|
|
|
let menudata = this._menus[i];
|
|
|
|
if (item == menudata.menu)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
},
|
|
|
|
|
2010-12-30 09:22:54 -05:00
|
|
|
_nextMenu: function(pos, direction) {
|
|
|
|
for (let i = 1; i < this._menus.length; i++) {
|
|
|
|
let candidate = mod(pos + i * direction, this._menus.length);
|
|
|
|
let menu = this._menus[candidate].menu;
|
|
|
|
if (!menu.sourceActor || menu.sourceActor.visible)
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
// no menu is found? this should not happen
|
|
|
|
// anyway stay on current menu
|
|
|
|
return this._menus[pos];
|
|
|
|
},
|
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
_onEventCapture: function(actor, event) {
|
|
|
|
if (!this.grabbed)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (this._owner.menuEventFilter &&
|
|
|
|
this._owner.menuEventFilter(event))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
let activeMenuContains = this._eventIsOnActiveMenu(event);
|
|
|
|
let eventType = event.type();
|
|
|
|
if (eventType == Clutter.EventType.BUTTON_RELEASE) {
|
|
|
|
if (activeMenuContains) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
this._closeMenu();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if ((eventType == Clutter.EventType.BUTTON_PRESS && !activeMenuContains)
|
|
|
|
|| (eventType == Clutter.EventType.KEY_PRESS && event.get_key_symbol() == Clutter.Escape)) {
|
|
|
|
this._closeMenu();
|
|
|
|
return true;
|
2010-10-07 14:15:51 -04:00
|
|
|
} else if (activeMenuContains || this._eventIsOnAnyMenuSource(event)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onKeyPressEvent: function(actor, event) {
|
|
|
|
if (!this.grabbed || !this._activeMenu)
|
|
|
|
return false;
|
|
|
|
if (!this._eventIsOnActiveMenu(event))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
let symbol = event.get_key_symbol();
|
|
|
|
if (symbol == Clutter.Left || symbol == Clutter.Right) {
|
|
|
|
let direction = symbol == Clutter.Right ? 1 : -1;
|
2010-06-25 08:55:03 -04:00
|
|
|
let pos = this._findMenu(this._activeMenu);
|
2010-12-30 09:22:54 -05:00
|
|
|
let next = this._nextMenu(pos, direction);
|
2010-05-20 11:18:46 -04:00
|
|
|
if (next != this._activeMenu) {
|
2010-11-03 13:30:08 -04:00
|
|
|
this._changeMenu(next);
|
2010-07-03 19:47:31 -04:00
|
|
|
next.activateFirst();
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-07 14:15:51 -04:00
|
|
|
return false;
|
2010-05-20 11:18:46 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_closeMenu: function() {
|
|
|
|
if (this._activeMenu != null)
|
2010-11-18 16:18:54 -05:00
|
|
|
this._activeMenu.close(true);
|
2010-05-20 11:18:46 -04:00
|
|
|
}
|
|
|
|
};
|