| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright 2007, 2008, 2009, 2010, 2011, 2012 Kevin Ryde |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# This file is part of Gtk2-Ex-WidgetBits. |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# Gtk2-Ex-WidgetBits is free software; you can redistribute it and/or modify |
|
6
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by the |
|
7
|
|
|
|
|
|
|
# Free Software Foundation; either version 3, or (at your option) any later |
|
8
|
|
|
|
|
|
|
# version. |
|
9
|
|
|
|
|
|
|
# |
|
10
|
|
|
|
|
|
|
# Gtk2-Ex-WidgetBits 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-WidgetBits. If not, see . |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package Gtk2::Ex::MenuBits; |
|
19
|
3
|
|
|
3
|
|
34573
|
use 5.008; |
|
|
3
|
|
|
|
|
13
|
|
|
|
3
|
|
|
|
|
147
|
|
|
20
|
3
|
|
|
3
|
|
17
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
149
|
|
|
21
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
113
|
|
|
22
|
3
|
|
|
3
|
|
10669
|
use Gtk2; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use List::Util qw(max); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use Exporter; |
|
26
|
|
|
|
|
|
|
our @ISA = ('Exporter'); |
|
27
|
|
|
|
|
|
|
our @EXPORT_OK = qw(position_widget_topcentre |
|
28
|
|
|
|
|
|
|
mnemonic_escape |
|
29
|
|
|
|
|
|
|
mnemonic_undo); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our $VERSION = 48; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# uncomment this to run the ### lines |
|
34
|
|
|
|
|
|
|
#use Smart::Comments; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub position_widget_topcentre { |
|
37
|
|
|
|
|
|
|
my ($menu, $x, $y, $widget) = @_; |
|
38
|
|
|
|
|
|
|
### position_widget_topcentre(): "@{[$widget||'undef']}" |
|
39
|
|
|
|
|
|
|
if (ref $widget eq 'REF') { $widget = $$widget; } |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
### widget mapped: $widget && $widget->mapped |
|
42
|
|
|
|
|
|
|
### widget screen: "@{[$widget && $widget->get_screen]}" |
|
43
|
|
|
|
|
|
|
### menu screen: "@{[$menu->get_screen]}" |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
if ($widget |
|
46
|
|
|
|
|
|
|
&& (! $widget->can('get_screen') # Gtk 2.0.x single-screen |
|
47
|
|
|
|
|
|
|
|| $widget->get_screen == $menu->get_screen) |
|
48
|
|
|
|
|
|
|
&& $widget->mapped) { |
|
49
|
|
|
|
|
|
|
### mapped and same screen |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
require Gtk2::Ex::WidgetBits; |
|
52
|
|
|
|
|
|
|
if (my ($wx, $wy) = Gtk2::Ex::WidgetBits::get_root_position($widget)) { |
|
53
|
|
|
|
|
|
|
### have root x,y: "$wx,$wy" |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $widget_alloc = $widget->allocation; |
|
56
|
|
|
|
|
|
|
my $menu_req = $menu->requisition; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$x = $wx + max (0, int (($widget_alloc->width - $menu_req->width) / 2)); |
|
59
|
|
|
|
|
|
|
$y = $wy + int (($widget_alloc->height + 1) / 2); # round up |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
### $x |
|
64
|
|
|
|
|
|
|
### $y |
|
65
|
|
|
|
|
|
|
return ($x, $y, 1); # push_in to be visible on screen |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# gtkfilesel.c has an escape_underscores() doing this (not made public), for |
|
71
|
|
|
|
|
|
|
# the same sort of "aribtrary string incorporated into menu label" intended |
|
72
|
|
|
|
|
|
|
# here |
|
73
|
|
|
|
|
|
|
sub mnemonic_escape { |
|
74
|
|
|
|
|
|
|
my ($str) = @_; |
|
75
|
|
|
|
|
|
|
$str =~ s/_/__/g; |
|
76
|
|
|
|
|
|
|
return $str; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub mnemonic_undo { |
|
80
|
|
|
|
|
|
|
my ($str) = @_; |
|
81
|
|
|
|
|
|
|
$str =~ s/_(.)/$1/g; |
|
82
|
|
|
|
|
|
|
return $str; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# maybe ... |
|
86
|
|
|
|
|
|
|
# sub _mnemonic_to_markup { |
|
87
|
|
|
|
|
|
|
# my ($str) = @_; |
|
88
|
|
|
|
|
|
|
# $str =~ s{_(.)} |
|
89
|
|
|
|
|
|
|
# {$1 eq '_' ? '_' : "$1"}ge; |
|
90
|
|
|
|
|
|
|
# return $str; |
|
91
|
|
|
|
|
|
|
# } |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
|
94
|
|
|
|
|
|
|
__END__ |