| 1 | # Copyright 2010, 2011 Kevin Ryde | ||
| 2 | |||
| 3 | # This file is part of Gtk2-Ex-QuadButton. | ||
| 4 | # | ||
| 5 | # Gtk2-Ex-QuadButton is free software; you can redistribute it and/or | ||
| 6 | # modify it under the terms of the GNU General Public License as published | ||
| 7 | # by the Free Software Foundation; either version 3, or (at your option) any | ||
| 8 | # later version. | ||
| 9 | # | ||
| 10 | # Gtk2-Ex-QuadButton is distributed in the hope that it will be useful, but | ||
| 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
| 12 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 13 | # for more details. | ||
| 14 | # | ||
| 15 | # You should have received a copy of the GNU General Public License along | ||
| 16 | # with Gtk2-Ex-QuadButton. If not, see <http://www.gnu.org/licenses/>. | ||
| 17 | |||
| 18 | package Gtk2::Ex::QuadButton::Scroll; | ||
| 19 | 3 | ▶ | use 5.008; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 3 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 3 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | 0 | ▶ | use Gtk2 1.220; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 23 | use Gtk2::Ex::AdjustmentBits 40; # new v.40 | ||
| 24 | |||
| 25 | # uncomment this to run the ### lines | ||
| 26 | #use Smart::Comments; | ||
| 27 | |||
| 28 | our $VERSION = 1; | ||
| 29 | |||
| 30 | use Gtk2::Ex::QuadButton; | ||
| 31 | use Glib::Object::Subclass | ||
| 32 | 'Gtk2::Ex::QuadButton', | ||
| 33 | signals => { clicked => \&_do_clicked, | ||
| 34 | }, | ||
| 35 | properties => [ Glib::ParamSpec->object | ||
| 36 | ('hadjustment', | ||
| 37 | (do { | ||
| 38 | my $str = 'Horizontal adjustment'; | ||
| 39 | # translation if available | ||
| 40 | eval { require Locale::Messages; | ||
| 41 | Locale::Messages::dgettext('gtk20-properties',$str) | ||
| 42 | } || $str }), | ||
| 43 | 'Blurb.', | ||
| 44 | 'Gtk2::Adjustment', | ||
| 45 | Glib::G_PARAM_READWRITE), | ||
| 46 | |||
| 47 | Glib::ParamSpec->object | ||
| 48 | ('vadjustment', | ||
| 49 | (do { | ||
| 50 | my $str = 'Vertical adjustment'; | ||
| 51 | # translation if available | ||
| 52 | eval { require Locale::Messages; | ||
| 53 | Locale::Messages::dgettext('gtk20-properties',$str) | ||
| 54 | } || $str }), | ||
| 55 | 'Blurb.', | ||
| 56 | 'Gtk2::Adjustment', | ||
| 57 | Glib::G_PARAM_READWRITE), | ||
| 58 | |||
| 59 | Glib::ParamSpec->boolean | ||
| 60 | ('hinverted', | ||
| 61 | 'Horizontal inverted', | ||
| 62 | 'Whether to invert horizontal movement, so left increases and right decreases.', | ||
| 63 | 0, # default no | ||
| 64 | Glib::G_PARAM_READWRITE), | ||
| 65 | |||
| 66 | Glib::ParamSpec->boolean | ||
| 67 | ('vinverted', | ||
| 68 | 'Vertical inverted', | ||
| 69 | 'Whether to invert vertical movement, so up increases and down decreases.', | ||
| 70 | 0, # default no | ||
| 71 | Glib::G_PARAM_READWRITE), | ||
| 72 | ]; | ||
| 73 | |||
| 74 | # sub INIT_INSTANCE { | ||
| 75 | # my ($self) = @_; | ||
| 76 | # } | ||
| 77 | |||
| 78 | # sub SET_PROPERTY { | ||
| 79 | # my ($self, $pspec, $newval) = @_; | ||
| 80 | # my $pname = $pspec->get_name; | ||
| 81 | # $self->{$pname} = $newval; | ||
| 82 | # ### Enum SET_PROPERTY: $pname, $newval | ||
| 83 | # } | ||
| 84 | |||
| 85 | sub _do_clicked { | ||
| 86 | my ($self, $scroll_type) = @_; | ||
| 87 | _scroll_vh_type ($self->{'hadjustment'}, $self->{'vadjustment'}, | ||
| 88 | $scroll_type, | ||
| 89 | $self->{'hinverted'}, $self->{'vinverted'}); | ||
| 90 | |||
| 91 | } | ||
| 92 | |||
| 93 | my %dir_to_argnum = (left => 0, | ||
| 94 | right => 0, | ||
| 95 | up => 1, | ||
| 96 | down => 1); | ||
| 97 | my %dir_to_neg = (left => 1, | ||
| 98 | right => 0, | ||
| 99 | up => 1, | ||
| 100 | down => 0); | ||
| 101 | |||
| 102 | # anything for GtkScrollType page-forward etc or jump ? | ||
| 103 | # | ||
| 104 | sub _scroll_vh_type { | ||
| 105 | my ($hadj, $vadj, $scroll_type, $hinv, $vinv) = @_; | ||
| 106 | |||
| 107 | if ($scroll_type =~ /(page|step)-(up|down|left|right)/) { | ||
| 108 | my $argnum = $dir_to_argnum{$2}; | ||
| 109 | my $adj = $_[$argnum]; | ||
| 110 | my $amount_method = "${1}_increment"; | ||
| 111 | my $add = $adj->$amount_method; | ||
| 112 | if ($dir_to_neg{$2} ^ !!$_[3+$argnum]) { | ||
| 113 | $add = -$add; | ||
| 114 | } | ||
| 115 | Gtk2::Ex::AdjustmentBits::scroll_value ($adj, $add); | ||
| 116 | } | ||
| 117 | } | ||
| 118 | |||
| 119 | 1; | ||
| 120 | __END__ | ||