1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
&::PukeSendMessage($::PUKE_WIDGET_LOAD,
$::PUKE_CONTROLLER,
$::PWIDGET_LISTBOX,
"plistbox.so",
sub { my %ARG = %{shift()};
if($ARG{'iArg'} == 1){
print "*E* PListBox Load failed!\n";
}
}
);
package PListBox;
@ISA = qw(PTableView);
use strict;
if($PListBox::usage == undef){
$PListBox::usage = 0;
}
sub new {
my $class = shift;
my $self = $class->SUPER::new($class, @_);
$self->{widgetType} = $::PWIDGET_LISTBOX;
if($class eq 'PListBox'){
$self->create();
}
$self->{count} = 0;
$self->{items} = ();
$self->installHandler($::PUKE_LISTBOX_SELECTED_ACK, sub{$self->selected(@_)});
return $self;
}
sub DESTROY {
my $self = shift;
$self->SUPER::DESTROY(@_);
$PListBox::usage--;
if($PListBox::usage == 0){
&::PukeSendMessage($::PUKE_WIDGET_UNLOAD,
0,
$::PWIDGET_LISTBOX,
"",
sub {}
);
}
}
sub insertText {
my $self = shift;
my $text = shift;
my $index = shift;
my $rindex = $index;
if($index < 0 || $index >= $self->{count}){
$rindex = $self->{count};
}
$self->{count} ++;
# Don't need the ouput since GET_TEXT_ACK will be called and
# we'll set it there
$self->sendMessage('iCommand' => $::PUKE_LISTBOX_INSERT,
'iArg' => $rindex,
'cArg' => $text,
'CallBack' => sub {});
}
sub text {
my $self = shift;
my $index = shift;
my %arg = $self->sendMessage('iCommand' => $::PUKE_LISTBOX_GETTEXT,
'iArg' => $index,
'WaitFor' => 1);
if($arg{'iArg'} != 1){
return undef;
}
$arg{'cArg'} =~ s/\000//g;
return $arg{'cArg'};
}
sub insertPixmap {
my $self = shift;
my $file = shift;
my $index = shift;
my $rindex = $index;
if($index < 0 || $index >= $self->{count}){
$rindex = $self->{count};
}
# $self->{items}->[$rindex] = "***PIXMAP***" . $file;
$self->{count} ++;
# Don't need the ouput since GET_TEXT_ACK will be called and
# we'll set it there
$self->sendMessage('iCommand' => $::PUKE_LISTBOX_INSERT_PIXMAP,
'iArg' => $rindex,
'cArg' => $file,
'CallBack' => sub {});
}
sub selected {
my $self = shift;
my %ARGS = %{shift()};
$self->{current} = $ARGS{'iArg'};
$ARGS{'cArg'} =~ s/\000//g;
$self->{currentText} = $ARGS{'cArg'};
}
sub current {
my $self = shift;
return $self->{current};
}
sub currentText {
my $self = shift;
return $self->text($self->{current});
}
sub setCurrentItem {
my $self = shift;
my $index = shift;
my $rindex = $index;
# Async call be default, no need to wait result
$self->sendMessage('iCommand' => $::PUKE_LISTBOX_HIGHLIGHT,
'iArg' => $index,
'CallBack' => sub {});
}
sub removeItem {
my $self = shift;
my $index = shift;
$self->{count} --;
# Async call be default, no need to wait result
$self->sendMessage('iCommand' => $::PUKE_LISTBOX_REMOVE,
'iArg' => $index,
'CallBack' => sub {});
}
sub setScrollBar {
my $self = shift;
$self->sendMessage('iCommand' => $::PUKE_LISTBOX_SET_SCROLLBAR,
'iArg' => shift(),
'CallBack' => sub {});
}
sub setAutoScrollBar {
my $self = shift;
$self->sendMessage('iCommand' => $::PUKE_LISTBOX_SET_AUTO_SCROLLBAR,
'iArg' => shift(),
'CallBack' => sub {});
}
sub clear {
my $self = shift;
$self->{count} = 0;
$self->{items} = ();
$self->sendMessage('iCommand' => $::PUKE_LISTBOX_CLEAR,
'CallBack' => sub {});
}
package main;
1;
|