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
197
198
199
200
201
|
package PBoxLayout;
@ISA = qw(PBase);
use strict;
# setup default handlers
$PBoxLayout::LeftToRight = 0;
$PBoxLayout::RightToLeft = 1;
$PBoxLayout::TopToBottom = 2;
$PBoxLayout::BottomToTop = 3;
$PBoxLayout::AlignLeft = 0x0001;
$PBoxLayout::AlignRight = 0x0002;
$PboxLayout::AlignHCenter = 0x0004;
$PBoxLayout::AlignTop = 0x0008;
$PBoxLayout::AlignBottom = 0x0010;
$PBoxLayout::AlignVCenter = 0x0020;
$PBoxLayout::AlignCenter = $PBoxLayout::AlignVCenter |
$PBoxLayout::AlignHCenter;
sub new {
my $class = shift;
my $self = $class->SUPER::new($class, @_);
my $widget = shift;
# print "Widget: " . ref($widget) . "\n";
# if(ref($widget) eq ''){
# print "*E* Error Creating PBoxLayout, did not give valid parent\n";
# return;
#}
# elsif(ref($widget) eq 'PBoxLayout'){
# $self->{Parent} = $widget;
# $self->{ParentType} = 'Layout';
# $self->{Direction} = shift;
# $self->{Border} = shift;
# $self->{Added} = 0;
#}
# else{
if(ref($widget) ne ''){
# print "*\cbI\cb* Generic Non-topleve layout type\n";
$self->{Parent} = $widget;
$self->{ParentType} = 'Widget';
$self->{Direction} = shift;
$self->{Border} = shift;
$self->{Added} = 1;
}
else{
$self->{Parent} = undef;
$self->{ParentType} = 'Layout';
$self->{Direction} = $widget;
$self->{Border} = shift;
$self->{Added} = 0;
}
$self->{IAmALayout} = 1;
$self->{Widgets} = ();
$self->create();
return $self;
}
sub create {
my $self = shift;
#
# PLayout redefines create since it uses a special cArg
#
my($paren_id) = 0;
$paren_id = $self->{Parent}->{iWinId} if $self->{Parent} != -1;
if($paren_id eq ''){
$paren_id = "0";
}
my $carg = $paren_id . "\t" . $::POBJECT_LAYOUT . "\t" . $self->{Direction} . "\t" . $self->{Border} . "\t" . $self->{initId},
my %REPLY;
%REPLY = $self->sendMessage('iCommand' => $::PUKE_WIDGET_CREATE,
'iWinId' => $::PUKE_CONTROLLER,
'cArg' => $carg,
'CallBack' => sub { },
'WaitFor' => 1);
$self->ackWinId(%REPLY);
}
sub addWidget {
my $self = shift;
my $widget = shift;
my $stretch = shift;
my $align = shift;
if($self->{Added} == 0){
print "*E* Burp: Can't add widget without first being added to parent layout\n";
return;
}
$align = $PBoxLayout::AlignCenter if $align == undef;
$stretch = 0 if $stretch == undef;
# $widget->immortal(); # If it's a widget, it cannot be deleted
if($widget->{iWinId} <= 0){
print "*E* Trying to add invalid widget " . ref($widget) . "\n";
return;
}
my $cArg = pack("CC", $stretch, $align);
$self->sendMessage('iCommand' => $::PUKE_LAYOUT_ADDWIDGET,
'iArg' => $widget->{iWinId},
'cArg' => $cArg,
'CallBack' => sub { },
'WaitFor' => 1);
$self->{Widgets}->[ $#{$self->{Widgets}} + 1] = $widget;
}
sub addLayout {
my $self = shift;
if($self->{Added} == 0){
print "*E* Burp: Can't add layout without first being added to parent layout\n";
}
my $layout = shift;
if(ref($layout) ne 'PBoxLayout'){
print "*E* Passed non layout type to addLayout\n";
return 1;
}
if($layout->{iWinId} <= 0){
print "*E* Trying to add invalid layout " . ref($layout) . "\n";
return;
}
# make sure we can run, and the widget we want to add can run.
# my @ARG = ($layout);
#$self->canRun($self, \&PBoxLayout::addLayout, \@ARG) || return;
#$layout->canRun($self, \&PBoxLayout::addLayout, \@ARG) || return;
my %REPLY = $self->sendMessage('iCommand' => $::PUKE_LAYOUT_ADDLAYOUT,
'iWinId' => $self->{iWinId},
'iArg' => $layout->{iWinId},
'cArg' => pack("C", 0),
'CallBack' => sub { },
'WaitFor' => 1);
# print "*I* Adding layout\n";
if($REPLY{'iArg'} != 0){
print "*E* AddLayout call failed\n";
}
else{
# print "*I* Added new Layout for " . $layout->{iWinId} . "\n";
$layout->{Added} = 1;
}
}
sub DESTROY {
my $self = shift;
# print "*I* Layout Deleted\n";
# if($self->{DESTROYED} != 1){
# $self->sendMessage('iCommand' => $::PUKE_WIDGET_DELETE,
# 'CallBack' => sub { print "Deleted\n"; });
#}
$self->{iWinId} = -1;
$self->{DESTROYED} = 1;
}
sub activate {
my $self = shift;
if($self->{ParentType} != 'Widget'){
print "*E* Only call for TopLevel managers\n";
return;
}
$self->sendMessage('iCommand' => $::PUKE_LAYOUT_ACTIVATE,
'CallBack' => sub { },
'WaitFor' => 1);
}
package main;
1;
|