line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################### |
2
|
|
|
|
|
|
|
# subclass of Curses::UI::Row is a widget that can be used to display |
3
|
|
|
|
|
|
|
# and manipulate row in grid model |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# (c) 2004 by Adrian Witas. All rights reserved. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify it |
8
|
|
|
|
|
|
|
# under the same terms as perl itself. |
9
|
|
|
|
|
|
|
############################################################################### |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package Curses::UI::Grid::Row; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
7678
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1323
|
|
16
|
3
|
|
|
3
|
|
28
|
use warnings; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
122
|
|
17
|
|
|
|
|
|
|
|
18
|
3
|
|
|
3
|
|
1634
|
use Curses; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Curses::UI::Common; |
20
|
|
|
|
|
|
|
use Curses::UI::Grid; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use vars qw( |
23
|
|
|
|
|
|
|
$VERSION |
24
|
|
|
|
|
|
|
@ISA |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$VERSION = '0.14'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
@ISA = qw( |
30
|
|
|
|
|
|
|
Curses::UI::Grid |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new () |
35
|
|
|
|
|
|
|
{ |
36
|
|
|
|
|
|
|
my $class = shift; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my %userargs = @_; |
39
|
|
|
|
|
|
|
keys_to_lowercase(\%userargs); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my %args = ( |
42
|
|
|
|
|
|
|
# Parent info |
43
|
|
|
|
|
|
|
-parent => undef # the parent object |
44
|
|
|
|
|
|
|
# Position and size |
45
|
|
|
|
|
|
|
,-y => 0 # vertical position (rel. to -window) |
46
|
|
|
|
|
|
|
# Grid model |
47
|
|
|
|
|
|
|
,-focusable => 1 |
48
|
|
|
|
|
|
|
,-type => undef # row type: head,data |
49
|
|
|
|
|
|
|
,-cells => undef # data cell |
50
|
|
|
|
|
|
|
,-cells_undo => {} # holds data chaned |
51
|
|
|
|
|
|
|
,-bg_ => undef # user defined background color |
52
|
|
|
|
|
|
|
,-fg_ => undef # user defined font color |
53
|
|
|
|
|
|
|
,%userargs |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Create the Row |
57
|
|
|
|
|
|
|
my $this = {%args,-canvasscr=>$args{-parent}->canvasscr}; |
58
|
|
|
|
|
|
|
bless $this; |
59
|
|
|
|
|
|
|
return $this; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub layout { |
64
|
|
|
|
|
|
|
my $this = shift; |
65
|
|
|
|
|
|
|
$this->layout_row; |
66
|
|
|
|
|
|
|
return $this; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub layout_content { |
72
|
|
|
|
|
|
|
my $this = shift; |
73
|
|
|
|
|
|
|
return $this; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub layout_row($;){ |
78
|
|
|
|
|
|
|
my $this = shift; |
79
|
|
|
|
|
|
|
my $p=$this->parent; |
80
|
|
|
|
|
|
|
my $c=\@{ $p->{_cells} }; |
81
|
|
|
|
|
|
|
my $text = ''; |
82
|
|
|
|
|
|
|
my $w = $p->canvaswidth; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
for my $i ( 0 .. $#{$c} ) { |
85
|
|
|
|
|
|
|
my $cell = $p->id2cell($$c[$i]); |
86
|
|
|
|
|
|
|
$text .= ($cell->layout_text() || '') |
87
|
|
|
|
|
|
|
. ' ' |
88
|
|
|
|
|
|
|
unless $cell->hidden; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
$text = substr(sprintf("%-" . $w . "s", $text), 0, $w); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub draw(;$) { |
95
|
|
|
|
|
|
|
my $this = shift; |
96
|
|
|
|
|
|
|
my $no_doupdate = shift || 0; |
97
|
|
|
|
|
|
|
my $grid = $this->parent; |
98
|
|
|
|
|
|
|
return $this if $Curses::UI::screen_too_small; |
99
|
|
|
|
|
|
|
return $this if $this->hidden; |
100
|
|
|
|
|
|
|
$this->layout_row; |
101
|
|
|
|
|
|
|
$this->draw_row($no_doupdate); |
102
|
|
|
|
|
|
|
doupdate() if ! $no_doupdate && ! $grid->test_more; |
103
|
|
|
|
|
|
|
return $this; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub draw_row(;$) { |
109
|
|
|
|
|
|
|
my $this = shift; |
110
|
|
|
|
|
|
|
my $no_doupdate = shift || 0; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Return immediately if this object is hidden. |
113
|
|
|
|
|
|
|
return $this if $this->hidden; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $p=$this->parent(); |
117
|
|
|
|
|
|
|
$this->canvasscr->attron(A_BOLD) if($this->{-focus}); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
$p->run_event('-onrowdraw',$this); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# Let there be color for data cell |
122
|
|
|
|
|
|
|
# for header grid's colors |
123
|
|
|
|
|
|
|
my $fg=($this->type ne 'head') ? $this->fg : $p->{-fg} ; |
124
|
|
|
|
|
|
|
my $bg=($this->type ne 'head') ? $this->bg : $p->{-bg} ; |
125
|
|
|
|
|
|
|
my $pair=$p->set_color($fg,$bg,$this->canvasscr); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my $c=\@{ $p->{_cells} }; |
128
|
|
|
|
|
|
|
for my $i(0 .. $#{$c} ) { |
129
|
|
|
|
|
|
|
$p->id2cell( $$c[$i] )->draw_cell(1,$this);; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
$this->canvasscr->attroff(A_BOLD) if($this->{-focus}); |
132
|
|
|
|
|
|
|
$p->color_off($pair,$this->canvasscr); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
$this->draw_vline() if($this->type ne "head"); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
$this->canvasscr->noutrefresh; |
137
|
|
|
|
|
|
|
return $this; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub draw_vline { |
143
|
|
|
|
|
|
|
my $this = shift; |
144
|
|
|
|
|
|
|
my $grid = $this->parent; |
145
|
|
|
|
|
|
|
my $pair = $grid->set_color( |
146
|
|
|
|
|
|
|
($grid->{-bfg} || '') ne '-1' |
147
|
|
|
|
|
|
|
? $grid->{-bfg} |
148
|
|
|
|
|
|
|
: $grid->{-fg}, |
149
|
|
|
|
|
|
|
$this->bg, |
150
|
|
|
|
|
|
|
$this->canvasscr |
151
|
|
|
|
|
|
|
); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
foreach my $x (@{$grid->vertical_lines}) { |
154
|
|
|
|
|
|
|
$this->canvasscr->move($this->y,$x); |
155
|
|
|
|
|
|
|
$this->canvasscr->vline(ACS_VLINE,1); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
$grid->color_off($pair, $this->canvasscr); |
159
|
|
|
|
|
|
|
$this; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub bg() { |
164
|
|
|
|
|
|
|
my $this = shift; |
165
|
|
|
|
|
|
|
my $bg= shift; |
166
|
|
|
|
|
|
|
$this->{-bg_}=$bg if(defined $bg); |
167
|
|
|
|
|
|
|
return $this->{-bg_} ? $this->{-bg_} : exists( $this->{-bg} ) ? $this->{-bg} : $this->parent()->{-bg}; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub fg() { |
171
|
|
|
|
|
|
|
my $this = shift; |
172
|
|
|
|
|
|
|
my $fg= shift; |
173
|
|
|
|
|
|
|
$this->{-fg_}=$fg if(defined $fg); |
174
|
|
|
|
|
|
|
return $this->{-fg_} ? $this->{-fg_} :exists( $this->{-fg} ) ? $this->{-fg} : $this->parent()->{-fg}; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub event_onfocus() { |
178
|
|
|
|
|
|
|
my $this = shift; |
179
|
|
|
|
|
|
|
my $p=$this->parent; |
180
|
|
|
|
|
|
|
return $p->focus($this) unless($this->focusable); |
181
|
|
|
|
|
|
|
# Let the parent find another widget to focus |
182
|
|
|
|
|
|
|
# if this widget is not focusable. |
183
|
|
|
|
|
|
|
$this->{-focus} = 1; |
184
|
|
|
|
|
|
|
$p->run_event('-onrowfocus',$this); |
185
|
|
|
|
|
|
|
$p->{-row_idx}=$p->{-rowid2idx}{ $this->{-id} }; |
186
|
|
|
|
|
|
|
# clear date change info |
187
|
|
|
|
|
|
|
$this->{-cell_undo} = {}; |
188
|
|
|
|
|
|
|
$this->draw(1); |
189
|
|
|
|
|
|
|
my $cell = $p->get_foused_cell; |
190
|
|
|
|
|
|
|
$cell->event_onfocus if (defined $cell); |
191
|
|
|
|
|
|
|
return $this; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub event_onblur() { |
195
|
|
|
|
|
|
|
my $this = shift; |
196
|
|
|
|
|
|
|
my $p=$this->parent; |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
#check if data row was changed |
199
|
|
|
|
|
|
|
my $changed=0; |
200
|
|
|
|
|
|
|
for my $k (keys %{ $this->{-cell_undo} } ) { |
201
|
|
|
|
|
|
|
if( $this->{-cell_undo}{$k} ne $this->{-cell}{$k} ) { |
202
|
|
|
|
|
|
|
$changed=1; |
203
|
|
|
|
|
|
|
last; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
if($changed) { |
208
|
|
|
|
|
|
|
my $ret= $p->run_event('-onrowchange',$this); |
209
|
|
|
|
|
|
|
#if event return values and it's equal 0 then cancell onblur event |
210
|
|
|
|
|
|
|
if(defined $ret) { |
211
|
|
|
|
|
|
|
if($ret eq "0") { |
212
|
|
|
|
|
|
|
return ''; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
#If the Container loose it focus |
219
|
|
|
|
|
|
|
#the current focused child must be unfocused |
220
|
|
|
|
|
|
|
my $cell = $this->parent->get_foused_cell; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
#test if current row can be unfocused otherwise cancel current event |
223
|
|
|
|
|
|
|
if(defined $cell) { |
224
|
|
|
|
|
|
|
my $ret = $cell->event_onblur(); |
225
|
|
|
|
|
|
|
return 0 if(defined $ret && !$ret); |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
my $ret=$p->run_event('-onrowblur',$this); |
229
|
|
|
|
|
|
|
if(defined $ret) { |
230
|
|
|
|
|
|
|
if($ret eq "0") { |
231
|
|
|
|
|
|
|
return ''; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
$this->{-focus} = 0; |
235
|
|
|
|
|
|
|
$p->{-row_idx_prev}=$p->{-rowid2idx}{ $this->{-id} }; |
236
|
|
|
|
|
|
|
$this->draw; |
237
|
|
|
|
|
|
|
return $this; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
# y position of row |
241
|
|
|
|
|
|
|
sub y(){ |
242
|
|
|
|
|
|
|
my $this = shift; |
243
|
|
|
|
|
|
|
return $this->{-y} ? $this->{-y} +1:$this->{-y}; |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
sub type(){ shift()->{-type}; } |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
sub set_value($;) { |
249
|
|
|
|
|
|
|
my $this = shift; |
250
|
|
|
|
|
|
|
my $cell = shift; |
251
|
|
|
|
|
|
|
my $data = shift; |
252
|
|
|
|
|
|
|
my $cell_id=ref($cell) ? $cell->{-id} : $cell; |
253
|
|
|
|
|
|
|
$this->{-cells}{$cell_id}=$data; |
254
|
|
|
|
|
|
|
$this->draw if($this->{-focus}); |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
sub set_values($;) { |
259
|
|
|
|
|
|
|
my $this = shift; |
260
|
|
|
|
|
|
|
my %data = @_; |
261
|
|
|
|
|
|
|
if(defined $this->{-cells} ) { |
262
|
|
|
|
|
|
|
$this->{-cells}={ %{$this->{-cells}} , %data } ; |
263
|
|
|
|
|
|
|
} else { $this->{-cells}={ %data } ;} |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
$this->draw if($this->{-focus}); |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
sub set_undo_value($;) { |
271
|
|
|
|
|
|
|
my $this = shift; |
272
|
|
|
|
|
|
|
my $cell = shift; |
273
|
|
|
|
|
|
|
my $data = shift; |
274
|
|
|
|
|
|
|
my $cell_id=ref($cell) ? $cell->{-id} : $cell; |
275
|
|
|
|
|
|
|
$this->{-cells_undo}{$cell_id}=$data; |
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
sub get_undo_value($;) { |
279
|
|
|
|
|
|
|
my $this = shift; |
280
|
|
|
|
|
|
|
my $cell = shift; |
281
|
|
|
|
|
|
|
my $result=''; |
282
|
|
|
|
|
|
|
my $cell_id=ref($cell) ? $cell->{-id} : $cell; |
283
|
|
|
|
|
|
|
$result= $this->{-cells_undo}{$cell_id} if(exists($this->{-cells}{$cell_id})); |
284
|
|
|
|
|
|
|
return $result; |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
sub get_value($;) { |
290
|
|
|
|
|
|
|
my $this = shift; |
291
|
|
|
|
|
|
|
my $cell = shift; |
292
|
|
|
|
|
|
|
my $cell_id=ref($cell) ? $cell->{-id} : $cell; |
293
|
|
|
|
|
|
|
return $this->{-cells}{$cell_id}; |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
sub get_values($;) { |
297
|
|
|
|
|
|
|
my $this = shift; |
298
|
|
|
|
|
|
|
return %{ $this->{-cells} }; |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
sub get_values_ref($;) { |
302
|
|
|
|
|
|
|
my $this = shift; |
303
|
|
|
|
|
|
|
return \%{ $this->{-cells} }; |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
sub cleanup { |
308
|
|
|
|
|
|
|
my $this = shift; |
309
|
|
|
|
|
|
|
my $grid = $this->parent or return; |
310
|
|
|
|
|
|
|
delete $grid->{-rowid2idx}{$this->id}; |
311
|
|
|
|
|
|
|
delete $grid->{-id2row}{$this->id}; |
312
|
|
|
|
|
|
|
$grid->{-rows}--; |
313
|
|
|
|
|
|
|
$this->{$_} = '' |
314
|
|
|
|
|
|
|
for (qw(-canvasscr -parent)); |
315
|
|
|
|
|
|
|
} |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
sub DESTROY($;) { |
319
|
|
|
|
|
|
|
my $this = shift; |
320
|
|
|
|
|
|
|
$this->cleanup; |
321
|
|
|
|
|
|
|
} |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
1; |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
__END__ |