| 1 | # Copyright 2012, 2017 Kevin Ryde | ||
| 2 | |||
| 3 | # This file is part of Glib-Ex-ConnectProperties. | ||
| 4 | # | ||
| 5 | # Glib-Ex-ConnectProperties 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 | # Glib-Ex-ConnectProperties is distributed in the hope that it will be | ||
| 11 | # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
| 13 | # Public License for more details. | ||
| 14 | # | ||
| 15 | # You should have received a copy of the GNU General Public License along | ||
| 16 | # with Glib-Ex-ConnectProperties. If not, see <http://www.gnu.org/licenses/>. | ||
| 17 | |||
| 18 | |||
| 19 | package Glib::Ex::ConnectProperties::Element::textbuffer; | ||
| 20 | use 5.008; | ||
| 21 | use strict; | ||
| 22 | use warnings; | ||
| 23 | use Carp; | ||
| 24 | use Glib; | ||
| 25 | use base 'Glib::Ex::ConnectProperties::Element'; | ||
| 26 | |||
| 27 | our $VERSION = 20; | ||
| 28 | |||
| 29 | |||
| 30 | use constant pspec_hash => | ||
| 31 | do { | ||
| 32 | my $bool = Glib::ParamSpec->boolean ('empty', # name | ||
| 33 | '', # nick | ||
| 34 | '', # blurb | ||
| 35 | 1, # default, unused | ||
| 36 | 'readable'); # read-only | ||
| 37 | # anon hash | ||
| 38 | ({ | ||
| 39 | 'empty' => $bool, | ||
| 40 | 'not-empty' => $bool, | ||
| 41 | # dummy name and dummy range, just want an "int" type | ||
| 42 | 'char-count' => Glib::ParamSpec->int ('char-count', # name, unused | ||
| 43 | '', # nick, unused | ||
| 44 | '', # blurb, unused | ||
| 45 | 0, # min, unused | ||
| 46 | 2**31-1, # max, unused | ||
| 47 | 0, # default, unused | ||
| 48 | 'readable'), # read-only | ||
| 49 | |||
| 50 | }) | ||
| 51 | }; | ||
| 52 | |||
| 53 | # "notify::text" doesn't seem to be emitted, as of gtk circa 2.24.8 | ||
| 54 | use constant read_signal => 'changed'; | ||
| 55 | |||
| 56 | sub get_value { | ||
| 57 | my ($self) = @_; | ||
| 58 | my $textbuf = $self->{'object'}; | ||
| 59 | my $pname = $self->{'pname'}; | ||
| 60 | my $char_count = $textbuf->get_char_count; | ||
| 61 | if ($pname eq 'empty') { | ||
| 62 | return $char_count == 0; | ||
| 63 | } elsif ($pname eq 'not-empty') { | ||
| 64 | return $char_count != 0; | ||
| 65 | } else { | ||
| 66 | return $char_count; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | 1; | ||
| 71 | __END__ |