diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-07-23 09:06:59 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-07-23 09:06:59 +0200 |
commit | 4ea2cc3bd4a7d9b1c54a9d33e6a1cf82e7c8c21d (patch) | |
tree | d2e54377d14d604356c86862a326f64ae64dadd6 /src/util/ui.vala |
Imported Upstream version 0.18.1upstream/0.18.1
Diffstat (limited to 'src/util/ui.vala')
-rw-r--r-- | src/util/ui.vala | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/util/ui.vala b/src/util/ui.vala new file mode 100644 index 0000000..9f66de8 --- /dev/null +++ b/src/util/ui.vala @@ -0,0 +1,98 @@ +/* Copyright 2011-2014 Yorba Foundation + * + * This software is licensed under the GNU Lesser General Public License + * (version 2.1 or later). See the COPYING file in this distribution. + */ + +public enum AdjustmentRelation { + BELOW, + IN_RANGE, + ABOVE +} + +public enum CompassPoint { + NORTH, + SOUTH, + EAST, + WEST +} + +public enum Direction { + FORWARD, + BACKWARD; + + public Spit.Transitions.Direction to_transition_direction() { + switch (this) { + case FORWARD: + return Spit.Transitions.Direction.FORWARD; + + case BACKWARD: + return Spit.Transitions.Direction.BACKWARD; + + default: + error("Unknown Direction %s", this.to_string()); + } + } +} + +public void spin_event_loop() { + while (Gtk.events_pending()) + Gtk.main_iteration(); +} + +public AdjustmentRelation get_adjustment_relation(Gtk.Adjustment adjustment, int value) { + if (value < (int) adjustment.get_value()) + return AdjustmentRelation.BELOW; + else if (value > (int) (adjustment.get_value() + adjustment.get_page_size())) + return AdjustmentRelation.ABOVE; + else + return AdjustmentRelation.IN_RANGE; +} + +public Gdk.Rectangle get_adjustment_page(Gtk.Adjustment hadj, Gtk.Adjustment vadj) { + Gdk.Rectangle rect = Gdk.Rectangle(); + rect.x = (int) hadj.get_value(); + rect.y = (int) vadj.get_value(); + rect.width = (int) hadj.get_page_size(); + rect.height = (int) vadj.get_page_size(); + + return rect; +} + +// Verifies that only the mask bits are set in the modifier field, disregarding mouse and +// key modifers that are not normally of concern (i.e. Num Lock, Caps Lock, etc.). Mask can be +// one or more bits set, but should only consist of these values: +// * Gdk.ModifierType.SHIFT_MASK +// * Gdk.ModifierType.CONTROL_MASK +// * Gdk.ModifierType.MOD1_MASK (Alt) +// * Gdk.ModifierType.MOD3_MASK +// * Gdk.ModifierType.MOD4_MASK +// * Gdk.ModifierType.MOD5_MASK +// * Gdk.ModifierType.SUPER_MASK +// * Gdk.ModifierType.HYPER_MASK +// * Gdk.ModifierType.META_MASK +// +// (Note: MOD2 seems to be Num Lock in GDK.) +public bool has_only_key_modifier(Gdk.ModifierType field, Gdk.ModifierType mask) { + return (field + & (Gdk.ModifierType.SHIFT_MASK + | Gdk.ModifierType.CONTROL_MASK + | Gdk.ModifierType.MOD1_MASK + | Gdk.ModifierType.MOD3_MASK + | Gdk.ModifierType.MOD4_MASK + | Gdk.ModifierType.MOD5_MASK + | Gdk.ModifierType.SUPER_MASK + | Gdk.ModifierType.HYPER_MASK + | Gdk.ModifierType.META_MASK)) == mask; +} + +public string build_dummy_ui_string(Gtk.ActionGroup[] groups) { + string ui_string = "<ui>"; + foreach (Gtk.ActionGroup group in groups) { + foreach (Gtk.Action action in group.list_actions()) + ui_string += "<accelerator name=\"%s\" action=\"%s\" />".printf(action.name, action.name); + } + ui_string += "</ui>"; + + return ui_string; +} |