| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Kephra::ToolBar; |
|
2
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
2463
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
39
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
1483
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my %toolbar; |
|
8
|
0
|
|
|
0
|
|
|
sub _all { \%toolbar } |
|
9
|
|
|
|
|
|
|
sub _ref { |
|
10
|
0
|
0
|
|
0
|
|
|
if (ref $_[1] eq 'Wx::ToolBar') {$toolbar{$_[0]}{ref} = $_[1]} |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
elsif(exists $toolbar{$_[0]}{ref}) {$toolbar{$_[0]}{ref}} |
|
12
|
|
|
|
|
|
|
} |
|
13
|
0
|
0
|
|
0
|
|
|
sub _data { $toolbar{$_[0]} if stored($_[0]) } |
|
14
|
0
|
0
|
|
0
|
0
|
|
sub stored { 1 if ref $toolbar{$_[0]} eq 'HASH'} |
|
15
|
|
|
|
|
|
|
sub _create_empty { |
|
16
|
0
|
|
|
0
|
|
|
Wx::ToolBar->new( Kephra::App::Window::_ref(), |
|
17
|
|
|
|
|
|
|
-1, [-1,-1], [-1,-1], &Wx::wxTB_HORIZONTAL|&Wx::wxTB_DOCKABLE ); |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub create_new { |
|
21
|
0
|
|
|
0
|
0
|
|
my $bar_id = shift; |
|
22
|
0
|
|
|
|
|
|
my $bar_def = shift; |
|
23
|
0
|
|
|
|
|
|
my $bar = _ref($bar_id); |
|
24
|
|
|
|
|
|
|
# destroy old safely when overwrite |
|
25
|
0
|
0
|
0
|
|
|
|
$bar->Destroy if defined $bar and $bar; |
|
26
|
0
|
|
|
|
|
|
_ref ($bar_id, _create_empty()); |
|
27
|
0
|
|
|
|
|
|
create($bar_id, $bar_def); |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub create { |
|
31
|
0
|
|
|
0
|
0
|
|
my $bar_id = shift; |
|
32
|
0
|
|
|
|
|
|
my $bar_def = shift; |
|
33
|
0
|
|
|
|
|
|
eval_data($bar_id, assemble_data_from_def($bar_def)); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub assemble_data_from_def { |
|
37
|
0
|
|
|
0
|
0
|
|
my $bar_def = shift; |
|
38
|
0
|
0
|
|
|
|
|
return unless ref $bar_def eq 'ARRAY'; |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my @tbds = (); # toolbar data structure |
|
41
|
0
|
|
|
|
|
|
my $cmd_data; |
|
42
|
|
|
|
|
|
|
# |
|
43
|
0
|
|
|
|
|
|
for my $item_def (@$bar_def){ |
|
44
|
|
|
|
|
|
|
# undef means null string |
|
45
|
0
|
0
|
|
|
|
|
$item_def = '' unless defined $item_def; |
|
46
|
0
|
|
|
|
|
|
my %item; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# skipping commented lines |
|
49
|
0
|
0
|
|
|
|
|
next if substr($item_def, -1) eq '#'; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# recursive call for submenus |
|
52
|
0
|
0
|
|
|
|
|
if (ref $item_def eq 'HASH'){} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# "parsing" item data |
|
55
|
0
|
|
|
|
|
|
($item{type}, $item{id}, $item{size}) = split / /, $item_def; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# skip separators |
|
58
|
0
|
0
|
0
|
|
|
|
if (not defined $item{type} or $item{type} eq 'separator'){ |
|
|
|
0
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$item{type} = ''; |
|
60
|
|
|
|
|
|
|
# handle regular toolbar buttons |
|
61
|
|
|
|
|
|
|
} elsif( substr( $item{type}, -4) eq 'item' ) { |
|
62
|
0
|
|
|
|
|
|
$cmd_data = Kephra::CommandList::get_cmd_properties( $item{id} ); |
|
63
|
|
|
|
|
|
|
# skipping when command call is missing |
|
64
|
0
|
0
|
0
|
|
|
|
next unless ref $cmd_data and exists $cmd_data->{call}; |
|
65
|
0
|
|
|
|
|
|
for ('call','enable','enable_event','state', 'state_event','label', |
|
66
|
|
|
|
|
|
|
'help','icon'){ |
|
67
|
0
|
0
|
|
|
|
|
$item{$_} = $cmd_data->{$_} if $cmd_data->{$_} |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
#$item{type} = 'item'if not $cmd_data->{state} and $item{type} eq 'checkitem'; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
0
|
|
|
|
|
|
push @tbds, \%item; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
0
|
|
|
|
|
|
return \@tbds; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub eval_data { |
|
77
|
0
|
|
|
0
|
0
|
|
my $bar_id = shift; |
|
78
|
0
|
|
|
|
|
|
my $bar_data = shift; |
|
79
|
0
|
|
|
|
|
|
my $bar = _ref($bar_id); |
|
80
|
0
|
0
|
|
|
|
|
return $bar unless ref $bar_data eq 'ARRAY'; |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $win = Kephra::App::Window::_ref(); |
|
83
|
0
|
|
|
|
|
|
my $item_kind; |
|
84
|
0
|
|
|
|
|
|
my @rest_items = (); |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
my $bar_item_id = defined $toolbar{$bar_id}{item_id} |
|
87
|
|
|
|
|
|
|
? $toolbar{$bar_id}{item_id} |
|
88
|
|
|
|
|
|
|
: $Kephra::app{GUI}{masterID}++ * 100; |
|
89
|
0
|
|
|
|
|
|
$toolbar{$bar_id}{item_id} = $bar_item_id; |
|
90
|
0
|
|
|
|
|
|
my $respond = Kephra::API::settings()->{app}{toolbar}{responsive}; |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
for my $item_data (@$bar_data){ |
|
93
|
0
|
0
|
0
|
|
|
|
if (not $item_data->{type} or $item_data->{type} eq 'separator'){ |
|
|
|
0
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
$bar->AddSeparator; |
|
95
|
|
|
|
|
|
|
} elsif (ref $item_data->{icon} eq 'Wx::Bitmap'){ |
|
96
|
0
|
0
|
|
|
|
|
if ($item_data->{type} eq 'checkitem'){ |
|
|
|
0
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
$item_kind = &Wx::wxITEM_CHECK |
|
98
|
|
|
|
|
|
|
} elsif ($item_data->{type} eq 'item'){ |
|
99
|
0
|
|
|
|
|
|
$item_kind = &Wx::wxITEM_NORMAL |
|
100
|
0
|
|
|
|
|
|
} else { next } |
|
101
|
0
|
|
|
|
|
|
my $item_id = $bar_item_id++; |
|
102
|
0
|
|
|
|
|
|
my $tool = $bar->AddTool( |
|
103
|
|
|
|
|
|
|
$item_id, '', $item_data->{icon}, &Wx::wxNullBitmap, |
|
104
|
|
|
|
|
|
|
$item_kind, $item_data->{label}, $item_data->{help} |
|
105
|
|
|
|
|
|
|
); |
|
106
|
0
|
|
|
|
|
|
Wx::Event::EVT_TOOL ($win, $item_id, $item_data->{call}); |
|
107
|
0
|
0
|
0
|
|
|
|
if (ref $item_data->{enable} eq 'CODE' and $respond){ |
|
108
|
0
|
|
|
|
|
|
$tool->Enable( $item_data->{enable}() ); |
|
109
|
0
|
|
|
|
|
|
for my $event (split /,/, $item_data->{enable_event}){ |
|
110
|
|
|
|
|
|
|
Kephra::EventTable::add_call ( |
|
111
|
|
|
|
|
|
|
$event, $bar_id.'_tool_enable_'.$item_id, sub{ |
|
112
|
0
|
|
|
0
|
|
|
$bar->EnableTool( $item_id, $item_data->{enable}() ) |
|
113
|
0
|
|
|
|
|
|
}, $bar_id); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
} |
|
116
|
0
|
0
|
0
|
|
|
|
if (ref $item_data->{state} eq 'CODE' |
|
117
|
|
|
|
|
|
|
and $item_data->{type} eq 'checkitem'){ |
|
118
|
0
|
|
|
|
|
|
$bar->ToggleTool( $item_id, $item_data->{state}() ); |
|
119
|
0
|
|
|
|
|
|
for my $event (split /,/, $item_data->{state_event}){ |
|
120
|
|
|
|
|
|
|
Kephra::EventTable::add_call ( |
|
121
|
|
|
|
|
|
|
$event, , $bar_id.'_tool_state_'.$item_id, sub{ |
|
122
|
0
|
|
|
0
|
|
|
$bar->ToggleTool( $item_id, $item_data->{state}() ) |
|
123
|
0
|
|
|
|
|
|
}, $bar_id ); |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
} else { |
|
127
|
0
|
|
|
|
|
|
$item_data->{pos} = $bar_item_id % 100 + @rest_items; |
|
128
|
0
|
|
|
|
|
|
push @rest_items, $item_data; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
} |
|
131
|
0
|
|
|
|
|
|
$bar->Realize; |
|
132
|
0
|
|
|
|
|
|
$bar->SetRows(1); |
|
133
|
0
|
|
|
|
|
|
_ref($bar_id, $bar); |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
return \@rest_items; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub destroy { |
|
139
|
0
|
|
|
0
|
0
|
|
my $bar_ID = shift; |
|
140
|
0
|
|
|
|
|
|
my $bar = _ref( $bar_ID ); |
|
141
|
0
|
0
|
|
|
|
|
return unless $bar; |
|
142
|
0
|
|
|
|
|
|
$bar->Destroy; |
|
143
|
0
|
|
|
|
|
|
Kephra::EventTable::del_own_subscriptions( $bar_ID ); |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |