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
|
// Copyright 2014 Endless Mobile, Inc.
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
// Class for buttons whose :hover and :active CSS pseudoclass states should be
// inherited by some of their child widgets, since as of GTK 3.10 these flags no
// longer propagate from a widget to its children. Widgets in sensitiveChildren
// will listen to this widget's state-flags-changed event and inherit all flag
// values listed in _INHERITED_FLAGS.
const CompositeButton = new Lang.Class({
Name: 'CompositeButton',
GTypeName: 'CompositeButton',
Extends: Gtk.Button,
_INHERITED_FLAGS: [Gtk.StateFlags.PRELIGHT, Gtk.StateFlags.ACTIVE],
_init: function (props) {
this._handlerSet = false;
this._sensitiveChildren = [];
this.parent(props);
},
// Set the list of child widgets which will inherit the CompositeButton's
// hover/active state flags.
setSensitiveChildren: function (children) {
this._sensitiveChildren = children;
// If the handlers for mouse events aren't already set, connect them
if (!this._handlerSet) {
this._connectStateChangedHandler();
}
},
_connectStateChangedHandler: function () {
this.connect('state-flags-changed',
Lang.bind(this, this._stateChangedHandler));
this._handlerSet = true;
},
_stateChangedHandler: function (widget, flags) {
let myFlags = this.get_state_flags();
this._sensitiveChildren.forEach(function (child) {
this._INHERITED_FLAGS.forEach(function (flag) {
// for each flag we want the children to inherit, grab this
// widget's flag value, and set the child's matching flag
// accordingly
let myFlag = myFlags & flag;
if (myFlag !== 0)
child.set_state_flags(flag, false);
else
child.unset_state_flags(flag);
});
}, this);
}
});
|