blib/lib/Games/Axmud/Table.pm untested

filter: Statementstmt 0.0% 0 / 2175 Branchbran 0.0% 0 / 934 Conditioncond 0.0% 0 / 681 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 255 Podpod 0.0% 0 / 199 totaltotal 0.0% 0 / 4244 CC 468 SCAR 38.7
CC
468
Cov
0%
objEnable
306.0
objEnable
272.0
addTab
272.0
CRAP 48.2
1 # Copyright (C) 2011-2021 A S Lewis
2 #
3 # This program is free software: you can redistribute it and/or modify it under the terms of the GNU
4 # General Public License as published by the Free Software Foundation, either version 3 of the
5 # License, or (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
8 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License along with this program. If not,
12 # see <http://www.gnu.org/licenses/>.
13 #
14 #
15 # Games::Axmud::Table::xxx
16 # Table objects, which handle individual widgets (usually groups of widgets, within a single
17 # container widget) on an 'internal' window's Gtk3::Table
18  
19 # Container table objects
20  
21 { package Games::Axmud::Table::Holder;
22  
23 use strict;
24 use warnings;
25 use diagnostics;
26  
27 use Glib qw(TRUE FALSE);
28  
29 our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud);
30  
31 ##################
32 # Constructors
33  
34 sub new {
35  
36 # Called by GA::Strip::Table->addTableObj
37 # Creates the GA::Table::Holder, which reserves an area of the table for some other table
38 # object (and creates no widgets of its own)
39 #
40 # Expected arguments
41 # $number - The table object's number within the parent strip object (matches
42 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object
43 # created to access its default IVs)
44 # $name - A name for the table object. Can be any string or, if no name was
45 # specified in the call to the calling function, $name is the same as
46 # $number. (No part of the code checks that table object names are unique;
47 # if two or more table objects share the same ->name, usually the one with
48 # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
49 # chars)
50 # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table
51 # objects
52 # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
53 # parent strip object's Gtk3::Grid for use exclusively by this table
54 # object. 'temp' for temporary table objects
55 #
56 # Optional arguments
57 # %initHash - A hash containing arbitrary data to use as the table object's
58 # initialisation settings. The table object should use default
59 # initialisation settings unless it can succesfully interpret one or more
60 # of the key-value pairs in the hash, if there are any
61 # - This type of table object recognises these initialisation settings:
62 #
63 # 'id' - If specified, can be any non-empty string. Any other code (for
64 # example, a task) can look for holders with a certain ID and, if
65 # one is found, replace it with their choice of table object; the
66 # area occupied by the holder remains empty until that time. Values
67 # might include types of 'grid' window such as 'map', or 'task' for
68 # task windows in general, or 'status_task' for the Status task in
69 # particular. If not specified, 'undef' or an empty string, 'task' is
70 # used as a default value
71 #
72 # Return values
73 # 'undef' on improper arguments
74 # Blessed reference to the newly-created object on success
75  
76 my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
77  
78 # Local variables
79 my (
80 $winObj,
81 %modHash,
82 );
83  
84 # Check for improper arguments
85 if (
86 ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
87 || ! defined $zoneObj
88 ) {
89 return $axmud::CLIENT->writeImproper($class . '->new', @_);
90 }
91  
92 # Deal with temporary table objects
93 if ($stripObj eq 'temp') {
94 $winObj = 'temp';
95 } else {
96 $winObj = $stripObj->winObj;
97 }
98  
99 # Default initialisation settings
100 %modHash = (
101 'id' => 'task',
102 );
103  
104 # Interpret the initialisation settings in %initHash, if any
105 foreach my $key (keys %modHash) {
106  
107 $modHash{$key} = $initHash{$key};
108 }
109  
110 # Setup
111 my $self = {
112 _objName => 'table_obj_' . $number,
113 _objClass => $class,
114 _parentFile => undef, # No parent file object
115 _parentWorld => undef, # No parent file object
116 _privFlag => TRUE, # All IVs are private
117  
118 # Standard table object IVs
119 # -------------------------
120  
121 # The table object's number within the parent strip object (matches
122 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to
123 # access its default IVs)
124 number => $number,
125 # A name for the table object. Can be any string or, if no name was specified in the
126 # call to the calling function, $name is the same as $number. (No part of the code
127 # checks that table object names are unique; if two or more table objects share the
128 # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary
129 # table objects. Max 16 chars)
130 name => $name,
131 # The type of table object (custom table objects should use a ->type starting with
132 # 'custom_' to avoid clashing with future built-in table objects)
133 type => 'holder',
134 # The parent strip object (GA::Strip::Table)
135 stripObj => $stripObj,
136 # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for
137 # temporary table objects
138 winObj => $winObj,
139 # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip
140 # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary
141 # table objects
142 zoneObj => $zoneObj,
143  
144 # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is
145 # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as
146 # when a connection to a world terminates)
147 allowRemoveFlag => TRUE,
148 # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is
149 # created. Set to FALSE if it can't be resized
150 allowResizeFlag => TRUE,
151 # Initialisation settings stored as a hash (see the comments above)
152 initHash => \%modHash,
153 # Reference to a function to call when some widget is used. This IV is set only when
154 # required by this type of table object. It can be set by a call to
155 # $self->set_func() or by some setting in $self->initHash, which is applied in the
156 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
157 # generic object function Games::Axmud->getMethodRef()
158 funcRef => undef,
159 # A value passed to ->funcRef when it is called which identifies this table object and
160 # its widget(s). Can be any value, including 'undef'. It can be set by a call to
161 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
162 # to $self->objEnable()
163 funcID => '',
164  
165 # The container widget(s) for this table object; both IVs are always set to the same
166 # widget
167 packingBox => undef, # Gtk3::Grid
168 packingBox2 => undef, # Gtk3::Grid
169  
170 # Other IVs
171 # ---------
172  
173 # Any non-empty string which identifies what kind of table object can be put here (see
174 # comments above)
175 id => 'task',
176 };
177  
178 # Bless the object into existence
179 bless $self, $class;
180  
181 return $self;
182 }
183  
184 ##################
185 # Methods
186  
187 # Standard table object functions
188  
189 sub objEnable {
190  
191 # Called by GA::Strip::Table->addTableObj
192 # Sets up the table object's widgets
193 #
194 # Expected arguments
195 # (none besides $self)
196 #
197 # Return values
198 # 'undef' on improper arguments
199 # 1 on success
200  
201 my ($self, $check) = @_;
202  
203 # Local variables
204 my $id;
205  
206 # Check for improper arguments
207 if (defined $check) {
208  
209 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
210 }
211  
212 # Interpret $self->initHash, replacing any invalid values
213 $id = $self->ivShow('initHash', 'id');
214 if (defined $id && $id ne '') {
215  
216 $id = 'task';
217 }
218  
219 # Create the packing box, depending on $type
220 my $packingBox = Gtk3::Grid->new();
221  
222 # For this table object, ->packingBox and ->packingBox2 always refer to the same widget
223 my $packingBox2 = $packingBox;
224  
225 # Set expansion
226 $packingBox->set_hexpand(TRUE);
227 $packingBox->set_vexpand(TRUE);
228  
229 # Update IVs
230 $self->ivPoke('packingBox', $packingBox);
231 $self->ivPoke('packingBox2', $packingBox2);
232 $self->ivPoke('id', $id);
233  
234 return 1;
235 }
236  
237 # sub objDestroy { # Inherited from GA::Generic::Table
238  
239 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table
240  
241 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table
242  
243 # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table
244  
245 # ->signal_connects
246  
247 # Other functions
248  
249 ##################
250 # Accessors - set
251  
252 # (Get equivalents)
253  
254 ##################
255 # Accessors - get
256  
257 sub id
258 { $_[0]->{id} }
259 }
260  
261 { package Games::Axmud::Table::Container;
262  
263 use strict;
264 use warnings;
265 use diagnostics;
266  
267 use Glib qw(TRUE FALSE);
268  
269 our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud);
270  
271 ##################
272 # Constructors
273  
274 sub new {
275  
276 # Called by GA::Strip::Table->addTableObj
277 # Creates the GA::Table::Container, which creates a container widget into which other
278 # widgets can be freely added
279 #
280 # Expected arguments
281 # $number - The table object's number within the parent strip object (matches
282 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object
283 # created to access its default IVs)
284 # $name - A name for the table object. Can be any string or, if no name was
285 # specified in the call to the calling function, $name is the same as
286 # $number. (No part of the code checks that table object names are unique;
287 # if two or more table objects share the same ->name, usually the one with
288 # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
289 # chars)
290 # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table
291 # objects
292 # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
293 # parent strip object's Gtk3::Grid for use exclusively by this table
294 # object. 'temp' for temporary table objects
295 #
296 # Optional arguments
297 # %initHash - A hash containing arbitrary data to use as the table object's
298 # initialisation settings. The table object should use default
299 # initialisation settings unless it can succesfully interpret one or more
300 # of the key-value pairs in the hash, if there are any
301 # - This type of table object recognises these initialisation settings:
302 #
303 # 'type' - 'grid' for a Gtk3::Grid, 'horizontal'/'hbox' for a Gtk3::HBox,
304 # 'vertical'/'vbox' for a Gtk3::VBox, 'scroll'/'scroller' for a
305 # Gtk3::ScrolledWindow, 'frame' for a Gtk3::Frame. If an invalid
306 # 'type' or if 'type' is not specified, 'grid' is used
307 # 'expand_horizontal_flag' - Ignored if 'type' is 'horizontal' or
308 # 'vertical'. If TRUE or not specified, the table object expands
309 # horizontally; if FALSE, it doesn't
310 # 'expand_vertical_flag' - Ignored if 'type' is 'horizontal' or
311 # 'vertical'. If TRUE or not specified, the table object expands
312 # vertically; if FALSE, it doesn't
313 # 'equal_flag' - Ignored if 'type' is not 'horizontal' or 'vertical'.
314 # If TRUE, sets the container's homogeneity flag to TRUE; if FALSE,
315 # 'undef' or not specified, sets it to FALSE
316 # 'spacing' - Ignored if 'type' is not 'grid', 'horizontal' or 'vertical'.
317 # Sets the spacing between widgets packed into the box. If specified,
318 # must be an integer, >= 0
319 # 'scroll_horizontal' - Ignored if 'type' is not 'scroll' or 'scroller'.
320 # Sets the horizontal scrolling policy; the value must be 'always',
321 # 'automatic' or 'never'. If 'undef', not specified or an invalid
322 # value, 'automatic' is used
323 # 'scroll_vertical' - Ignored if 'type' is not 'scroll' or 'scroller'.
324 # Sets the vertical scrolling policy; the value must be 'always',
325 # 'automatic' or 'never'. If 'undef', not specified or an invalid
326 # value, 'automatic' is used #
327 # 'frame_title' - Ignored if 'type' is not 'frame' (this is different from
328 # the behaviour of some other table objects, for which 'frame_title'
329 # creates a frame). If a non-empty string, the string is used as the
330 # frame title
331 #
332 # Return values
333 # 'undef' on improper arguments
334 # Blessed reference to the newly-created object on success
335  
336 my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
337  
338 # Local variables
339 # Local variables
340 my (
341 $winObj,
342 %modHash,
343 );
344  
345 # Check for improper arguments
346 if (
347 ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
348 || ! defined $zoneObj
349 ) {
350 return $axmud::CLIENT->writeImproper($class . '->new', @_);
351 }
352  
353 # Deal with temporary table objects
354 if ($stripObj eq 'temp') {
355 $winObj = 'temp';
356 } else {
357 $winObj = $stripObj->winObj;
358 }
359  
360 # Default initialisation settings
361 %modHash = (
362 'type' => 'grid',
363 'expand_horizontal_flag' => TRUE,
364 'expand_vertical_flag' => TRUE,
365 'equal_flag' => FALSE,
366 'spacing' => 0,
367 'scroll_horizontal' => 'automatic',
368 'scroll_vertical' => 'automatic',
369 'frame_title' => '',
370 );
371  
372 # Interpret the initialisation settings in %initHash, if any
373 foreach my $key (keys %modHash) {
374  
375 if (exists $initHash{$key}) {
376  
377 if ($key =~ m/flag$/) {
378  
379 if ($initHash{$key}) {
380 $modHash{$key} = TRUE;
381 } else {
382 $modHash{$key} = FALSE;
383 }
384  
385 } else {
386  
387 $modHash{$key} = $initHash{$key};
388 }
389 }
390 }
391  
392 # Setup
393 my $self = {
394 _objName => 'table_obj_' . $number,
395 _objClass => $class,
396 _parentFile => undef, # No parent file object
397 _parentWorld => undef, # No parent file object
398 _privFlag => TRUE, # All IVs are private
399  
400 # Standard table object IVs
401 # -------------------------
402  
403 # The table object's number within the parent strip object (matches
404 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to
405 # access its default IVs)
406 number => $number,
407 # A name for the table object. Can be any string or, if no name was specified in the
408 # call to the calling function, $name is the same as $number. (No part of the code
409 # checks that table object names are unique; if two or more table objects share the
410 # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary
411 # table objects. Max 16 chars)
412 name => $name,
413 # The type of table object (custom table objects should use a ->type starting with
414 # 'custom_' to avoid clashing with future built-in table objects)
415 type => 'container',
416 # The parent strip object (GA::Strip::Table)
417 stripObj => $stripObj,
418 # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for
419 # temporary table objects
420 winObj => $winObj,
421 # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip
422 # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary
423 # table objects
424 zoneObj => $zoneObj,
425  
426 # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is
427 # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as
428 # when a connection to a world terminates)
429 allowRemoveFlag => TRUE,
430 # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is
431 # created. Set to FALSE if it can't be resized
432 allowResizeFlag => TRUE,
433 # Initialisation settings stored as a hash (see the comments above)
434 initHash => \%modHash,
435 # Reference to a function to call when some widget is used. This IV is set only when
436 # required by this type of table object. It can be set by a call to
437 # $self->set_func() or by some setting in $self->initHash, which is applied in the
438 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
439 # generic object function Games::Axmud->getMethodRef()
440 funcRef => undef,
441 # A value passed to ->funcRef when it is called which identifies this table object and
442 # its widget(s). Can be any value, including 'undef'. It can be set by a call to
443 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
444 # to $self->objEnable()
445 funcID => '',
446  
447 # The container widget(s) for this table object; both IVs are always set to the same
448 # widget
449 packingBox => undef, # Gtk3::Grid, Gtk3::HBox, ::VBox,
450 # ::ScrolledWindow, ::Frame
451 packingBox2 => undef, # ditto
452  
453 # Other IVs
454 # ---------
455  
456 # The container type: 'horizontal', 'vertical', 'scroll' or 'frame'. The alternative
457 # type values 'hbox', 'vbox' and 'scroller' are converted, if specified in %initHash
458 type => undef,
459 };
460  
461 # Bless the object into existence
462 bless $self, $class;
463  
464 return $self;
465 }
466  
467 ##################
468 # Methods
469  
470 # Standard table object functions
471  
472 sub objEnable {
473  
474 # Called by GA::Strip::Table->addTableObj
475 # Sets up the table object's widgets
476 #
477 # Expected arguments
478 # (none besides $self)
479 #
480 # Return values
481 # 'undef' on improper arguments
482 # 1 on success
483  
484 my ($self, $check) = @_;
485  
486 # Local variables
487 my ($type, $hExpandFlag, $vExpandFlag, $equalFlag, $spacing, $hScroll, $vScroll, $label);
488  
489 # Check for improper arguments
490 if (defined $check) {
491  
492 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
493 }
494  
495 # Interpret $self->initHash, replacing any invalid values
496 $type = $self->ivShow('initHash', 'type');
497 if ($type eq 'horizontal' || $type eq 'hbox') {
498 $type = 'horizontal';
499 } elsif ($type eq 'vertical' || $type eq 'vbox') {
500 $type = 'vertical';
501 } elsif ($type eq 'scroll' || $type eq 'scroller') {
502 $type = 'scroll';
503 } elsif ($type eq 'frame') {
504 $type = 'frame';
505 } else {
506 $type = 'grid';
507 }
508  
509 $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag'));
510 $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag'));
511 $equalFlag = $self->testFlag($self->ivShow('initHash', 'equal_flag'));
512 $spacing = $self->testInt($self->ivShow('initHash', 'spacing'), 0, 0);
513  
514 $hScroll = $self->ivShow('initHash', 'scroll_horizontal');
515 if ($hScroll ne 'always' && $hScroll ne 'automatic' && $hScroll ne 'never') {
516  
517 $hScroll = 'automatic';
518 }
519  
520 $vScroll = $self->ivShow('initHash', 'scroll_vertical');
521 if ($vScroll ne 'always' && $vScroll ne 'automatic' && $vScroll ne 'never') {
522  
523 $vScroll = 'automatic';
524 }
525  
526 $label = $self->ivShow('initHash', 'frame_title');
527 if (! defined $label) {
528  
529 $label = '';
530 }
531  
532 # Create the packing box, depending on $type
533 my ($packingBox, $packingBox2);
534 if ($type eq 'grid') {
535  
536 $packingBox = Gtk3::Grid->new();
537 $packingBox->set_row_spacing($spacing);
538 $packingBox->set_column_spacing($spacing);
539  
540 } elsif ($type eq 'horizontal' || $type eq 'hbox') {
541  
542 $packingBox = Gtk3::HBox->new($equalFlag, $spacing);
543 $type = 'horizontal';
544  
545 } elsif ($type eq 'vertical' || $type eq 'vbox') {
546  
547 $packingBox = Gtk3::VBox->new($equalFlag, $spacing);
548 $type = 'vertical';
549  
550 } elsif ($type eq 'scroll' || $type eq 'scroller') {
551  
552 $packingBox = Gtk3::ScrolledWindow->new();
553 $packingBox->set_policy($hScroll, $vScroll);
554 $type = 'scroll';
555  
556 } elsif ($type eq 'frame') {
557  
558 if (! $label) {
559 $packingBox = Gtk3::Frame->new();
560 } else {
561 $packingBox = Gtk3::Frame->new($label);
562 }
563 }
564  
565 # Set expansion
566 if ($type eq 'grid' || $type eq 'scroll' || $type eq 'frame') {
567  
568 $packingBox->set_hexpand($hExpandFlag);
569 $packingBox->set_vexpand($vExpandFlag);
570  
571 } else {
572  
573 $packingBox->set_hexpand(TRUE);
574 $packingBox->set_vexpand(TRUE);
575 }
576  
577 # For this table object, ->packingBox and ->packingBox2 always refer to the same widget
578 $packingBox2 = $packingBox;
579  
580 # Update IVs
581 $self->ivPoke('packingBox', $packingBox);
582 $self->ivPoke('packingBox2', $packingBox2);
583 $self->ivPoke('type', $type);
584  
585 return 1;
586 }
587  
588 # sub objDestroy { # Inherited from GA::Generic::Table
589  
590 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table
591  
592 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table
593  
594 # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table
595  
596 # ->signal_connects
597  
598 # Other functions
599  
600 sub packStart {
601  
602 # Can be called by anything to add a widget to the main container widget
603 # If $self->type is 'horizontal' or 'vertical', this function and/or $self->packEnd can be
604 # called any number of times
605 # If $self->type is 'scroll' or 'frame', either this function or $self->packEnd can be
606 # called once (in that case, both functions behave identically)
607 #
608 # Expected arguments
609 # $widget - The Gtk3 widget to add to the main container widget
610 #
611 # Optional arguments (ignored if $self->type is not 'horizontal' or 'vertical'
612 # $expandFlag - If TRUE, the widget receives extra space when the container gets bigger.
613 # If FALSE (or 'undef'), it stays the same size (default is FALSE)
614 # $fillFlag - If TRUE, extra space given to the widget is allocated to the widget. If
615 # FALSE (or 'undef'), extra space is used as padding (default is FALSE)
616 # $spacing - The space (in pixels) between this widget and its neighbours. If
617 # specified, must be an integer, >= 0 (default is 0)
618 #
619 # Return values
620 # 'undef' on improper arguments or if the main container widget is full
621 # 1 on success
622  
623 my ($self, $widget, $expandFlag, $fillFlag, $spacing, $check) = @_;
624  
625 # Check for improper arguments
626 if (! defined $widget || defined $check) {
627  
628 return $axmud::CLIENT->writeImproper($self->_objClass . '->packStart', @_);
629 }
630  
631 if ($self->type eq 'horizontal' || $self->type eq 'vertical') {
632  
633 # Use TRUE or FALSE flags
634 if (! $expandFlag) {
635 $expandFlag = FALSE;
636 } else {
637 $expandFlag = TRUE;
638 }
639  
640 if (! $fillFlag) {
641 $fillFlag = FALSE;
642 } else {
643 $fillFlag = TRUE;
644 }
645  
646 # Check $spacing is an integer, or use a default value
647 if (! defined $spacing || ! $axmud::CLIENT->intCheck($spacing, 0)) {
648  
649 $spacing = 0;
650 }
651  
652 $self->packingBox2->pack_start($widget, $expandFlag, $fillFlag, $spacing);
653  
654 return 1;
655  
656 } else {
657  
658 # Can't pack the widget if the main container widget already contains something
659 if ($self->packingBox2->get_children()) {
660  
661 return undef;
662 }
663  
664 if ($self->type eq 'scroll') {
665 $self->packingBox2->add_with_viewport($widget);
666 } else {
667 $self->packingBox2->add($widget);
668 }
669  
670 return 1;
671 }
672 }
673  
674 sub packEnd {
675  
676 # Can be called by anything to add a widget to the main container widget
677 # If $self->type is 'horizontal' or 'vertical', this function and/or $self->packStart can be
678 # called any number of times
679 # If $self->type is 'scroll' or 'frame', either this function or $self->packStart can be
680 # called once (in that case, both functions behave identically)
681 #
682 # Expected arguments
683 # $widget - The Gtk3 widget to add to the main container widget
684 #
685 # Optional arguments (ignored if $self->type is not 'horizontal' or 'vertical'
686 # $expandFlag - If TRUE, the widget receives extra space when the container gets bigger.
687 # If FALSE (or 'undef'), it stays the same size (default is FALSE)
688 # $fillFlag - If TRUE, extra space given to the widget is allocated to the widget. If
689 # FALSE (or 'undef'), extra space is used as padding (default is FALSE)
690 # $spacing - The space (in pixels) between this widget and its neighbours. If
691 # specified, must be an integer, >= 0 (default is 0)
692 #
693 # Return values
694 # 'undef' on improper arguments or if the main container widget is full
695 # 1 on success
696  
697 my ($self, $widget, $expandFlag, $fillFlag, $spacing, $check) = @_;
698  
699 # Check for improper arguments
700 if (! defined $widget || defined $check) {
701  
702 return $axmud::CLIENT->writeImproper($self->_objClass . '->packEnd', @_);
703 }
704  
705 if ($self->type eq 'horizontal' || $self->type eq 'vertical') {
706  
707 # Use TRUE or FALSE flags
708 if (! $expandFlag) {
709 $expandFlag = FALSE;
710 } else {
711 $expandFlag = TRUE;
712 }
713  
714 if (! $fillFlag) {
715 $fillFlag = FALSE;
716 } else {
717 $fillFlag = TRUE;
718 }
719  
720 # Check $spacing is an integer, or use a default value
721 if (! defined $spacing || ! $axmud::CLIENT->intCheck($spacing, 0)) {
722  
723 $spacing = 0;
724 }
725  
726 $self->packingBox2->pack_end($widget, $expandFlag, $fillFlag, $spacing);
727  
728 return 1;
729  
730 } else {
731  
732 # Can't pack the widget if the main container widget already contains something
733 if ($self->packingBox2->get_children()) {
734  
735 return undef;
736 }
737  
738 if ($self->type eq 'scroll') {
739 $self->packingBox2->add_with_viewport($widget);
740 } else {
741 $self->packingBox2->add($widget);
742 }
743  
744 return 1;
745 }
746 }
747  
748 sub remove {
749  
750 # Can be called by anything to remove a widget from the main container widget
751 #
752 # Expected arguments
753 # $widget - The Gtk3 widget to remove from the main container widget
754 #
755 # Return values
756 # 'undef' on improper arguments
757 # 1 otherwise
758  
759 my ($self, $widget, $check) = @_;
760  
761 # Check for improper arguments
762 if (! defined $widget || defined $check) {
763  
764 return $axmud::CLIENT->writeImproper($self->_objClass . '->remove', @_);
765 }
766  
767 return $axmud::CLIENT->desktopObj->removeWidget($self->packingBox2, $widget);
768 }
769  
770 sub empty {
771  
772 # Can be called by anything to remove all widgets from the main container widget
773 #
774 # Expected arguments
775 # (none besides $self)
776 #
777 # Return values
778 # 'undef' on improper arguments
779 # 1 otherwise
780  
781 my ($self, $check) = @_;
782  
783 # Check for improper arguments
784 if (defined $check) {
785  
786 return $axmud::CLIENT->writeImproper($self->_objClass . '->empty', @_);
787 }
788  
789 foreach my $child ($self->packingBox2->get_children()) {
790  
791 $self->packingBox2->remove($child);
792 }
793  
794 return 1;
795 }
796  
797 ##################
798 # Accessors - set
799  
800 sub set_equal {
801  
802 my ($self, $flag, $check) = @_;
803  
804 # Check for improper arguments
805 if (! defined $flag || defined $check) {
806  
807 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_equal', @_);
808 }
809  
810 if ($self->type ne 'horizontal' && $self->type ne 'vertical') {
811  
812 return undef;
813 }
814  
815 if (! $flag) {
816  
817 $self->packingBox2->set_column_homogeneous(FALSE);
818 $self->packingBox2->set_row_homogeneous(FALSE);
819  
820 } else {
821  
822 $self->packingBox2->set_column_homogeneous(TRUE);
823 $self->packingBox2->set_row_homogeneous(TRUE);
824 }
825  
826 return 1;
827 }
828  
829 sub set_label {
830  
831 my ($self, $label, $check) = @_;
832  
833 # Check for improper arguments
834 if (! defined $label || defined $check) {
835  
836 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_label', @_);
837 }
838  
839 if ($self->type ne 'frame') {
840  
841 return undef;
842 }
843  
844 $self->packingBox2->set_label($label);
845  
846 return 1;
847 }
848  
849 sub set_scroll {
850  
851 my ($self, $hScroll, $vScroll, $check) = @_;
852  
853 # Check for improper arguments
854 if (! defined $hScroll || ! defined $vScroll || defined $check) {
855  
856 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_scroll', @_);
857 }
858  
859 if ($self->type ne 'scroll') {
860  
861 return undef;
862 }
863  
864 foreach my $policy ($hScroll, $vScroll) {
865  
866 if ($policy ne 'always' && $policy ne 'automatic' && $policy ne 'never') {
867  
868 return undef;
869 }
870 }
871  
872 $self->packingBox2->set_policy($hScroll, $vScroll);
873  
874 return 1;
875 }
876  
877 sub set_spacing {
878  
879 my ($self, $spacing, $check) = @_;
880  
881 # Check for improper arguments
882 if (! defined $spacing || defined $check) {
883  
884 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_spacing', @_);
885 }
886  
887 if (
888 ($self->type ne 'horizontal' && $self->type ne 'vertical')
889 || ! $axmud::CLIENT->intCheck($spacing, 0)
890 ) {
891 return undef;
892 }
893  
894 $self->packingBox2->set_spacing();
895  
896 return 1;
897 }
898  
899 # (Get equivalents)
900  
901 sub get_equal {
902  
903 # Returns flag
904  
905 my ($self, $check) = @_;
906  
907 # Check for improper arguments
908 if (defined $check) {
909  
910 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_equal', @_);
911 }
912  
913 if ($self->type ne 'horizontal' && $self->type ne 'vertical') {
914  
915 return undef;
916 }
917  
918 # Columns and rows are set together, so we can return a single value
919 if (! $self->packingBox2->get_column_homogeneous()) {
920 return FALSE;
921 } else {
922 return TRUE;
923 }
924 }
925  
926 sub get_label {
927  
928 # Returns a string (might be an empty string)
929  
930 my ($self, $check) = @_;
931  
932 # Check for improper arguments
933 if (defined $check) {
934  
935 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_label', @_);
936 }
937  
938 if ($self->type ne 'frame') {
939  
940 return undef;
941  
942 } else {
943  
944 return $self->packingBox2->get_label();
945 }
946 }
947  
948 sub get_scroll {
949  
950 # Returns list in form (policy, policy), where 'policy' is one of the strings 'always',
951 # 'automatic', 'never'
952  
953 my ($self, $check) = @_;
954  
955 # Local variables
956 my (@emptyList, @policyList);
957  
958 # Check for improper arguments
959 if (defined $check) {
960  
961 $axmud::CLIENT->writeImproper($self->_objClass . '->get_scroll', @_);
962 return @emptyList;
963 }
964  
965 if ($self->type ne 'scroll') {
966  
967 return @emptyList;
968 }
969  
970 @policyList = $self->packingBox2->get_policy();
971  
972 foreach my $policy (@policyList) {
973  
974 if ($policy eq 'GTK_POLICY_ALWAYS') {
975 $policy = 'always';
976 } elsif ($policy eq 'GTK_POLICY_AUTOMATIC') {
977 $policy = 'automatic';
978 } elsif ($policy eq 'GTK_POLICY_NEVER') {
979 $policy = 'never';
980 }
981 }
982  
983 return @policyList;
984 }
985  
986 sub get_spacing {
987  
988 # Returns integer
989  
990 my ($self, $check) = @_;
991  
992 # Check for improper arguments
993 if (defined $check) {
994  
995 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_spacing', @_);
996 }
997  
998 if ($self->type ne 'horizontal' && $self->type ne 'vertical') {
999  
1000 return undef;
1001  
1002 } else {
1003  
1004 return $self->packingBox2->get_spacing();
1005 }
1006 }
1007  
1008 sub get_widgets {
1009  
1010 # Returns the list of widgets in the main container (may be an empty list)
1011  
1012 my ($self, $check) = @_;
1013  
1014 # Local variables
1015 my @emptyList;
1016  
1017 # Check for improper arguments
1018 if (defined $check) {
1019  
1020 $axmud::CLIENT->writeImproper($self->_objClass . '->get_widgets', @_);
1021 return @emptyList;
1022 }
1023  
1024 return $self->packingBox2->get_children();
1025 }
1026  
1027 ##################
1028 # Accessors - get
1029  
1030 sub type
1031 { $_[0]->{type} }
1032 }
1033  
1034 { package Games::Axmud::Table::MiniTable;
1035  
1036 use strict;
1037 use warnings;
1038 use diagnostics;
1039  
1040 use Glib qw(TRUE FALSE);
1041  
1042 our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud);
1043  
1044 ##################
1045 # Constructors
1046  
1047 sub new {
1048  
1049 # Called by GA::Strip::Table->addTableObj
1050 # Creates the GA::Table::MiniTable, which creates a table within a table, to which other
1051 # widgets can be freely added
1052 #
1053 # Expected arguments
1054 # $number - The table object's number within the parent strip object (matches
1055 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object
1056 # created to access its default IVs)
1057 # $name - A name for the table object. Can be any string or, if no name was
1058 # specified in the call to the calling function, $name is the same as
1059 # $number. (No part of the code checks that table object names are unique;
1060 # if two or more table objects share the same ->name, usually the one with
1061 # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
1062 # chars)
1063 # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table
1064 # objects
1065 # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
1066 # parent strip object's Gtk3::Grid for use exclusively by this table
1067 # object. 'temp' for temporary table objects
1068 #
1069 # Optional arguments
1070 # %initHash - A hash containing arbitrary data to use as the table object's
1071 # initialisation settings. The table object should use default
1072 # initialisation settings unless it can succesfully interpret one or more
1073 # of the key-value pairs in the hash, if there are any
1074 # - This type of table object recognises these initialisation settings:
1075 #
1076 # 'column_equal_flag' - If TRUE, sets the table's homogeneity flag for
1077 # columns to TRUE; if FALSE, 'undef' or not specified, sets it to
1078 # FALSE
1079 # 'row_equal_flag' - If TRUE, sets the table's homogeneity flag for rows
1080 # to TRUE; if FALSE, 'undef' or not specified, sets it to FALSE
1081 # 'column_spacing' - Sets the horizontal spacing between table widgets, in
1082 # pixels (must be an integer, >= 0). If not specified or an invalid
1083 # value, a spacing of 0 is used
1084 # 'row_spacing' - Sets the vertical spacing between table widgets, in
1085 # pixels (must be an integer, >= 0). If not specified or an invalid
1086 # value, a spacing of 0 is used
1087 # 'expand_horizontal_flag' - If TRUE or not specified, the table object
1088 # expands horizontally; if FALSE, it doesn't
1089 # 'expand_vertical_flag' - If TRUE or not specified, the table object
1090 # expands vertically; if FALSE, it doesn't
1091 #
1092 # Return values
1093 # 'undef' on improper arguments
1094 # Blessed reference to the newly-created object on success
1095  
1096 my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
1097  
1098 # Local variables
1099 my (
1100 $winObj,
1101 %modHash,
1102 );
1103  
1104 # Check for improper arguments
1105 if (
1106 ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
1107 || ! defined $zoneObj
1108 ) {
1109 return $axmud::CLIENT->writeImproper($class . '->new', @_);
1110 }
1111  
1112 # Deal with temporary table objects
1113 if ($stripObj eq 'temp') {
1114 $winObj = 'temp';
1115 } else {
1116 $winObj = $stripObj->winObj;
1117 }
1118  
1119 # Default initialisation settings
1120 %modHash = (
1121 'column_equal_flag' => FALSE,
1122 'row_equal_flag' => FALSE,
1123 'column_spacing' => 0,
1124 'row_spacing' => 0,
1125 'expand_horizontal_flag' => TRUE,
1126 'expand_vertical_flag' => TRUE,
1127 );
1128  
1129 # Interpret the initialisation settings in %initHash, if any
1130 foreach my $key (keys %modHash) {
1131  
1132 if (exists $initHash{$key}) {
1133  
1134 if ($key =~ m/flag$/) {
1135  
1136 if ($initHash{$key}) {
1137 $modHash{$key} = TRUE;
1138 } else {
1139 $modHash{$key} = FALSE;
1140 }
1141  
1142 } else {
1143  
1144 $modHash{$key} = $initHash{$key};
1145 }
1146 }
1147 }
1148  
1149 # Setup
1150 my $self = {
1151 _objName => 'table_obj_' . $number,
1152 _objClass => $class,
1153 _parentFile => undef, # No parent file object
1154 _parentWorld => undef, # No parent file object
1155 _privFlag => TRUE, # All IVs are private
1156  
1157 # Standard table object IVs
1158 # -------------------------
1159  
1160 # The table object's number within the parent strip object (matches
1161 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to
1162 # access its default IVs)
1163 number => $number,
1164 # A name for the table object. Can be any string or, if no name was specified in the
1165 # call to the calling function, $name is the same as $number. (No part of the code
1166 # checks that table object names are unique; if two or more table objects share the
1167 # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary
1168 # table objects. Max 16 chars)
1169 name => $name,
1170 # The type of table object (custom table objects should use a ->type starting with
1171 # 'custom_' to avoid clashing with future built-in table objects)
1172 type => 'mini_table',
1173 # The parent strip object (GA::Strip::Table)
1174 stripObj => $stripObj,
1175 # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for
1176 # temporary table objects
1177 winObj => $winObj,
1178 # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip
1179 # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary
1180 # table objects
1181 zoneObj => $zoneObj,
1182  
1183 # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is
1184 # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as
1185 # when a connection to a world terminates)
1186 allowRemoveFlag => TRUE,
1187 # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is
1188 # created. Set to FALSE if it can't be resized
1189 allowResizeFlag => TRUE,
1190 # Initialisation settings stored as a hash (see the comments above)
1191 initHash => \%modHash,
1192 # Reference to a function to call when some widget is used. This IV is set only when
1193 # required by this type of table object. It can be set by a call to
1194 # $self->set_func() or by some setting in $self->initHash, which is applied in the
1195 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
1196 # generic object function Games::Axmud->getMethodRef()
1197 funcRef => undef,
1198 # A value passed to ->funcRef when it is called which identifies this table object and
1199 # its widget(s). Can be any value, including 'undef'. It can be set by a call to
1200 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
1201 # to $self->objEnable()
1202 funcID => '',
1203  
1204 # The container widget(s) for this table object; both IVs are always set to the same
1205 # widget
1206 packingBox => undef, # Gtk3::Grid
1207 packingBox2 => undef, # Gtk3::Grid
1208  
1209 # Other IVs
1210 # ---------
1211  
1212 # (none)
1213 };
1214  
1215 # Bless the object into existence
1216 bless $self, $class;
1217  
1218 return $self;
1219 }
1220  
1221 ##################
1222 # Methods
1223  
1224 # Standard table object functions
1225  
1226 sub objEnable {
1227  
1228 # Called by GA::Strip::Table->addTableObj
1229 # Sets up the table object's widgets
1230 #
1231 # Expected arguments
1232 # (none besides $self)
1233 #
1234 # Return values
1235 # 'undef' on improper arguments
1236 # 1 on success
1237  
1238 my ($self, $check) = @_;
1239  
1240 # Local variables
1241 my ($colEqualFlag, $rowEqualFlag, $colSpacing, $rowSpacing, $hExpandFlag, $vExpandFlag);
1242  
1243 # Check for improper arguments
1244 if (defined $check) {
1245  
1246 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
1247 }
1248  
1249 # Interpret $self->initHash, replacing any invalid values
1250 $colEqualFlag = $self->testFlag($self->ivShow('initHash', 'column_equal_flag'));
1251 $rowEqualFlag = $self->testFlag($self->ivShow('initHash', 'row_equal_flag'));
1252 $colSpacing = $self->testInt($self->ivShow('initHash', 'column_spacing'), 0, 0);
1253 $rowSpacing = $self->testInt($self->ivShow('initHash', 'row_spacing'), 0, 0);
1254 $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag'));
1255 $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag'));
1256  
1257 # Create the packing box
1258 my ($packingBox, $packingBox2);
1259 $packingBox = $packingBox2 = Gtk3::Grid->new();
1260 $packingBox2->set_column_homogeneous($colEqualFlag);
1261 $packingBox2->set_row_homogeneous($rowEqualFlag);
1262 $packingBox2->set_column_spacing($colSpacing);
1263 $packingBox2->set_row_spacing($rowSpacing);
1264  
1265 # Set expansion
1266 $packingBox->set_hexpand($hExpandFlag);
1267 $packingBox->set_vexpand($vExpandFlag);
1268  
1269 # Update IVs
1270 $self->ivPoke('packingBox', $packingBox);
1271 $self->ivPoke('packingBox2', $packingBox2);
1272  
1273 return 1;
1274 }
1275  
1276 # sub objDestroy { # Inherited from GA::Generic::Table
1277  
1278 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table
1279  
1280 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table
1281  
1282 # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table
1283  
1284 # ->signal_connects
1285  
1286 # Other functions
1287  
1288 sub pack {
1289  
1290 # Can be called by anything to add a widget to the mini-table
1291 # Unlike GA::Strip::Table, this code doesn't perform any checks; the widget is added
1292 # regardless of any existing widgets that are already on the table
1293 #
1294 # Expected arguments
1295 # $widget - The Gtk3 widget to add to the main container widget
1296 # $left, Right, $top, $bottom
1297 # - The table coordinates to use
1298 #
1299 # Return values
1300 # 'undef' on improper arguments
1301 # 1 on success
1302  
1303 my ($self, $widget, $left, $right, $top, $bottom, $check) = @_;
1304  
1305 # Check for improper arguments
1306 if (
1307 ! defined $widget || ! defined $left || ! defined $right || ! defined $top
1308 || ! defined $bottom || defined $check
1309 ) {
1310 return $axmud::CLIENT->writeImproper($self->_objClass . '->pack', @_);
1311 }
1312  
1313 $self->packingBox2->attach($widget, $left, $right, $top, $bottom);
1314  
1315 return 1;
1316 }
1317  
1318 sub remove {
1319  
1320 # Can be called by anything to remove a widget from the mini-table
1321 #
1322 # Expected arguments
1323 # $widget - The Gtk3 widget to remove from the mini-table
1324 #
1325 # Return values
1326 # 'undef' on improper arguments
1327 # 1 otherwise
1328  
1329 my ($self, $widget, $check) = @_;
1330  
1331 # Check for improper arguments
1332 if (! defined $widget || defined $check) {
1333  
1334 return $axmud::CLIENT->writeImproper($self->_objClass . '->remove', @_);
1335 }
1336  
1337 return $axmud::CLIENT->desktopObj->removeWidget($self->packingBox2, $widget);
1338 }
1339  
1340 sub empty {
1341  
1342 # Can be called by anything to remove all widgets from the mini-table
1343 #
1344 # Expected arguments
1345 # (none besides $self)
1346 #
1347 # Return values
1348 # 'undef' on improper arguments
1349 # 1 otherwise
1350  
1351 my ($self, $check) = @_;
1352  
1353 # Check for improper arguments
1354 if (defined $check) {
1355  
1356 return $axmud::CLIENT->writeImproper($self->_objClass . '->empty', @_);
1357 }
1358  
1359 foreach my $child ($self->packingBox2->get_children()) {
1360  
1361 $self->packingBox2->remove($child);
1362 }
1363  
1364 return 1;
1365 }
1366  
1367 ##################
1368 # Accessors - set
1369  
1370 sub set_equal {
1371  
1372 my ($self, $colFlag, $rowFlag, $check) = @_;
1373  
1374 # Check for improper arguments
1375 if (defined $check) {
1376  
1377 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_homo', @_);
1378 }
1379  
1380 if ($self->type ne 'horizontal' && $self->type ne 'vertical') {
1381  
1382 return undef;
1383 }
1384  
1385 if (! $colFlag) {
1386 $self->packingBox2->set_column_homogeneous(FALSE);
1387 } else {
1388 $self->packingBox2->set_column_homogeneous(TRUE);
1389 }
1390  
1391 if (! $rowFlag) {
1392 $self->packingBox2->set_row_homogeneous(FALSE);
1393 } else {
1394 $self->packingBox2->set_row_homogeneous(TRUE);
1395 }
1396  
1397 return 1;
1398 }
1399  
1400 sub set_spacing {
1401  
1402 my ($self, $rowSpacing, $colSpacing, $check) = @_;
1403  
1404 # Check for improper arguments
1405 if (! defined $rowSpacing || ! defined $colSpacing || defined $check) {
1406  
1407 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_spacing', @_);
1408 }
1409  
1410 if (
1411 ! $axmud::CLIENT->intCheck($rowSpacing, 0)
1412 || ! $axmud::CLIENT->intCheck($colSpacing, 0)
1413 ) {
1414 return undef;
1415  
1416 } else {
1417  
1418 $self->packingBox2->set_column_spacing($colSpacing);
1419 $self->packingBox2->set_row_spacing($rowSpacing);
1420  
1421 return 1;
1422 }
1423 }
1424  
1425 # (Get equivalents)
1426  
1427 sub get_equal {
1428  
1429 # Returns list in form (col_flag, row_flag)
1430  
1431 my ($self, $check) = @_;
1432  
1433 # Local variables
1434 my (@emptyList, @returnList);
1435  
1436 # Check for improper arguments
1437 if (defined $check) {
1438  
1439 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_equal', @_);
1440 }
1441  
1442 if ($self->type ne 'horizontal' && $self->type ne 'vertical') {
1443  
1444 return @emptyList;
1445 }
1446  
1447 if (! $self->packingBox2->get_column_homogeneous()) {
1448 push (@emptyList, FALSE);
1449 } else {
1450 push (@emptyList, TRUE);
1451 }
1452  
1453 if (! $self->packingBox2->get_row_homogeneous()) {
1454 push (@returnList, FALSE);
1455 } else {
1456 push (@returnList, TRUE);
1457 }
1458  
1459 return @returnList;
1460 }
1461  
1462 sub get_spacing {
1463  
1464 # Returns list in form (col_spacing, row_spacing)
1465  
1466 my ($self, $check) = @_;
1467  
1468 # Local variables
1469 my @emptyList;
1470  
1471 # Check for improper arguments
1472 if (defined $check) {
1473  
1474 $axmud::CLIENT->writeImproper($self->_objClass . '->get_spacing', @_);
1475 return @emptyList;
1476 }
1477  
1478 return (
1479 $self->packingBox2->get_default_row_spacing,
1480 $self->packingBox2->get_default_col_spacing,
1481 );
1482 }
1483  
1484 sub get_widgets {
1485  
1486 # Returns the list of widgets in the mini-table (may be an empty list)
1487  
1488 my ($self, $check) = @_;
1489  
1490 # Local variables
1491 my @emptyList;
1492  
1493 # Check for improper arguments
1494 if (defined $check) {
1495  
1496 $axmud::CLIENT->writeImproper($self->_objClass . '->get_widgets', @_);
1497 return @emptyList;
1498 }
1499  
1500 return $self->packingBox2->get_children();
1501 }
1502  
1503 ##################
1504 # Accessors - get
1505 }
1506  
1507 # Simple table objects
1508  
1509 { package Games::Axmud::Table::Label;
1510  
1511 use strict;
1512 use warnings;
1513 use diagnostics;
1514  
1515 use Glib qw(TRUE FALSE);
1516  
1517 our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud);
1518  
1519 ##################
1520 # Constructors
1521  
1522 sub new {
1523  
1524 # Called by GA::Strip::Table->addTableObj
1525 # Creates the GA::Table::Label, which contains a simple Gtk3::Label
1526 #
1527 # Expected arguments
1528 # $number - The table object's number within the parent strip object (matches
1529 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object
1530 # created to access its default IVs)
1531 # $name - A name for the table object. Can be any string or, if no name was
1532 # specified in the call to the calling function, $name is the same as
1533 # $number. (No part of the code checks that table object names are unique;
1534 # if two or more table objects share the same ->name, usually the one with
1535 # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
1536 # chars)
1537 # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table
1538 # objects
1539 # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
1540 # parent strip object's Gtk3::Grid for use exclusively by this table
1541 # object. 'temp' for temporary table objects
1542 #
1543 # Optional arguments
1544 # %initHash - A hash containing arbitrary data to use as the table object's
1545 # initialisation settings. The table object should use default
1546 # initialisation settings unless it can succesfully interpret one or more
1547 # of the key-value pairs in the hash, if there are any
1548 # - This type of table object recognises these initialisation settings:
1549 #
1550 # 'text' - The text to display in the Gtk3::Label. Can be plain text or
1551 # pango markup text. If not specified, 'undef' or an empty string, an
1552 # empty string is used
1553 # 'justify' - The text's justification. If specified, should be 'left',
1554 # 'right', 'centre'/'center' or 'fill' (of a Gtk3::Justification like
1555 # 'GTK_JUSTIFY_LEFT'). If not specified, 'left' is used. Ignored if
1556 # 'text' is not specified
1557 # 'underline_flag' - If TRUE, text is underlined. If FALSE (or not
1558 # specified), text is not underlined. Ignored if 'text' is not
1559 # specified
1560 # 'tooltips' - The text to display as tooltips for the button. Can be
1561 # plain text or pango markup text. If not specified, 'undef' or an
1562 # empty string, no tooltips are displayed
1563 # 'align_x', 'align_y' - the Gtk3::Label's alignment, values in the range
1564 # 0-1. If not specified, 'align_x' is set to 0, 'align_y' is set to
1565 # 0.5. Ignored if 'text' is not specified
1566 # 'expand_horizontal_flag' - If TRUE or unspecified, the table object
1567 # expands horizontally; if FALSE, it doesn't. Note that typically,
1568 # alignment does not work unless expansion is enabled
1569 # 'expand_vertical_flag' - If TRUE or unspecified, the table object
1570 # expands vertically; if FALSE, it doesn't
1571 #
1572 # Return values
1573 # 'undef' on improper arguments
1574 # Blessed reference to the newly-created object on success
1575  
1576 my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
1577  
1578 # Local variables
1579 my (
1580 $winObj,
1581 %modHash,
1582 );
1583  
1584 # Check for improper arguments
1585 if (
1586 ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
1587 || ! defined $zoneObj
1588 ) {
1589 return $axmud::CLIENT->writeImproper($class . '->new', @_);
1590 }
1591  
1592 # Deal with temporary table objects
1593 if ($stripObj eq 'temp') {
1594 $winObj = 'temp';
1595 } else {
1596 $winObj = $stripObj->winObj;
1597 }
1598  
1599 # Default initialisation settings
1600 %modHash = (
1601 'text' => '',
1602 'justify' => 'left',
1603 'underline_flag' => TRUE,
1604 'tooltips' => undef,
1605 'align_x' => 0,
1606 'align_y' => 0.5,
1607 'expand_horizontal_flag' => TRUE,
1608 'expand_vertical_flag' => TRUE,
1609 );
1610  
1611 # Interpret the initialisation settings in %initHash, if any
1612 foreach my $key (keys %modHash) {
1613  
1614 if (exists $initHash{$key}) {
1615  
1616 if ($key =~ m/flag$/) {
1617  
1618 if ($initHash{$key}) {
1619 $modHash{$key} = TRUE;
1620 } else {
1621 $modHash{$key} = FALSE;
1622 }
1623  
1624 } else {
1625  
1626 $modHash{$key} = $initHash{$key};
1627 }
1628 }
1629 }
1630  
1631 # Setup
1632 my $self = {
1633 _objName => 'table_obj_' . $number,
1634 _objClass => $class,
1635 _parentFile => undef, # No parent file object
1636 _parentWorld => undef, # No parent file object
1637 _privFlag => TRUE, # All IVs are private
1638  
1639 # Standard table object IVs
1640 # -------------------------
1641  
1642 # The table object's number within the parent strip object (matches
1643 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to
1644 # access its default IVs)
1645 number => $number,
1646 # A name for the table object. Can be any string or, if no name was specified in the
1647 # call to the calling function, $name is the same as $number. (No part of the code
1648 # checks that table object names are unique; if two or more table objects share the
1649 # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary
1650 # table objects. Max 16 chars)
1651 name => $name,
1652 # The type of table object (custom table objects should use a ->type starting with
1653 # 'custom_' to avoid clashing with future built-in table objects)
1654 type => 'label',
1655 # The parent strip object (GA::Strip::Table)
1656 stripObj => $stripObj,
1657 # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for
1658 # temporary table objects
1659 winObj => $winObj,
1660 # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip
1661 # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary
1662 # table objects
1663 zoneObj => $zoneObj,
1664  
1665 # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is
1666 # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as
1667 # when a connection to a world terminates)
1668 allowRemoveFlag => TRUE,
1669 # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is
1670 # created. Set to FALSE if it can't be resized
1671 allowResizeFlag => TRUE,
1672 # Initialisation settings stored as a hash (see the comments above)
1673 initHash => \%modHash,
1674 # Reference to a function to call when some widget is used. This IV is set only when
1675 # required by this type of table object. It can be set by a call to
1676 # $self->set_func() or by some setting in $self->initHash, which is applied in the
1677 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
1678 # generic object function Games::Axmud->getMethodRef()
1679 funcRef => undef,
1680 # A value passed to ->funcRef when it is called which identifies this table object and
1681 # its widget(s). Can be any value, including 'undef'. It can be set by a call to
1682 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
1683 # to $self->objEnable()
1684 funcID => '',
1685  
1686 # The container widget(s) for this table object
1687 packingBox => undef, # Gtk3::Grid
1688 packingBox2 => undef, # Gtk3::Grid
1689  
1690 # Other IVs
1691 # ---------
1692  
1693 # Widgets
1694 label => undef, # Gtk3::Label
1695 };
1696  
1697 # Bless the object into existence
1698 bless $self, $class;
1699  
1700 return $self;
1701 }
1702  
1703 ##################
1704 # Methods
1705  
1706 # Standard table object functions
1707  
1708 sub objEnable {
1709  
1710 # Called by GA::Strip::Table->addTableObj
1711 # Sets up the table object's widgets
1712 #
1713 # Expected arguments
1714 # (none besides $self)
1715 #
1716 # Return values
1717 # 'undef' on improper arguments
1718 # 1 on success
1719  
1720 my ($self, $check) = @_;
1721  
1722 # Local variables
1723 my (
1724 $text, $noTextFlag, $justify, $underlineFlag, $tooltips, $alignX, $alignY, $hExpandFlag,
1725 $vExpandFlag,
1726 );
1727  
1728 # Check for improper arguments
1729 if (defined $check) {
1730  
1731 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
1732 }
1733  
1734 # Interpret $self->initHash, replacing any invalid values
1735 $text = $self->ivShow('initHash', 'text');
1736 if (! defined $text) {
1737  
1738 $text = '';
1739 $noTextFlag = TRUE;
1740 }
1741  
1742 $justify = $self->testJustify($self->ivShow('initHash', 'justify'));
1743 $underlineFlag = $self->testFlag($self->ivShow('initHash', 'underline_flag'));
1744 $tooltips = $self->ivShow('initHash', 'tooltips');
1745 $alignX = $self->testAlign($self->ivShow('initHash', 'align_x'), 0);
1746 $alignY = $self->testAlign($self->ivShow('initHash', 'align_y'), 0.5);
1747 $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag'));
1748 $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag'));
1749  
1750 # Create packing box(es)
1751 my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::Grid->new());
1752  
1753 # Create the Gtk3::Label
1754 my $label = Gtk3::Label->new();
1755 $packingBox2->attach($label, 0, 0, 1, 1);
1756 $label->set_markup($self->ivShow('initHash', 'text'));
1757  
1758 if (! $noTextFlag) {
1759  
1760 $label->set_justify($justify);
1761 $label->set_use_underline($underlineFlag);
1762 $label->set_alignment($alignX, $alignY);
1763 }
1764  
1765 if (defined $tooltips && $tooltips ne '') {
1766  
1767 $label->set_tooltip_markup($tooltips);
1768 }
1769  
1770 # Set expansion
1771 $label->set_hexpand($hExpandFlag);
1772 $label->set_vexpand($vExpandFlag);
1773  
1774 # Update IVs
1775 $self->ivPoke('packingBox', $packingBox);
1776 $self->ivPoke('packingBox2', $packingBox2);
1777 $self->ivPoke('label', $label);
1778  
1779 return 1;
1780 }
1781  
1782 # sub objDestroy { # Inherited from GA::Generic::Table
1783  
1784 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table
1785  
1786 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table
1787  
1788 # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table
1789  
1790 # ->signal_connects
1791  
1792 # Other functions
1793  
1794 ##################
1795 # Accessors - set
1796  
1797 sub set_align {
1798  
1799 my ($self, $alignX, $alignY, $check) = @_;
1800  
1801 # Check for improper arguments
1802 if (defined $check) {
1803  
1804 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_align', @_);
1805 }
1806  
1807 $alignX = $self->testAlign($alignX, 0);
1808 $alignY = $self->testAlign($alignY, 0.5);
1809  
1810 $self->label->set_alignment($alignX, $alignY);
1811  
1812 return 1;
1813 }
1814  
1815 sub set_justify {
1816  
1817 my ($self, $justify, $check) = @_;
1818  
1819 # Check for improper arguments
1820 if (defined $check) {
1821  
1822 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_justify', @_);
1823 }
1824  
1825 $self->label->set_justify($self->testJustify($justify));
1826  
1827 return 1;
1828 }
1829  
1830 sub set_text {
1831  
1832 my ($self, $text, $check) = @_;
1833  
1834 # Check for improper arguments
1835 if (defined $check) {
1836  
1837 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_text', @_);
1838 }
1839  
1840 if (! defined $text) {
1841  
1842 $text = '';
1843 }
1844  
1845 $self->label->set_markup($text);
1846  
1847 return 1;
1848 }
1849  
1850 sub set_tooltips {
1851  
1852 my ($self, $tooltips, $check) = @_;
1853  
1854 # Check for improper arguments
1855 if (defined $check) {
1856  
1857 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_tooltips', @_);
1858 }
1859  
1860 if (! defined $tooltips || $tooltips eq '') {
1861 $self->label->set_tooltip_text(undef);
1862 } else {
1863 $self->label->set_tooltip_markup($tooltips);
1864 }
1865  
1866 return 1;
1867 }
1868  
1869 sub set_underline {
1870  
1871 my ($self, $flag, $check) = @_;
1872  
1873 # Check for improper arguments
1874 if (defined $check) {
1875  
1876 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_underline', @_);
1877 }
1878  
1879 $self->label->set_use_underline($self->testFlag($flag));
1880  
1881 return 1;
1882 }
1883  
1884 # (Get equivalents)
1885  
1886 sub get_align {
1887  
1888 # Returns list in form ($alignX, $alignY);
1889  
1890 my ($self, $alignX, $alignY, $check) = @_;
1891  
1892 # Check for improper arguments
1893 if (defined $check) {
1894  
1895 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_align', @_);
1896 }
1897  
1898 return $self->label->get_alignment();
1899 }
1900  
1901 sub get_justify {
1902  
1903 # Returns 'left', 'right', 'centre', 'fill' or 'other'
1904  
1905 my ($self, $check) = @_;
1906  
1907 # Local variables
1908 my $justify;
1909  
1910 # Check for improper arguments
1911 if (defined $check) {
1912  
1913 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_justify', @_);
1914 }
1915  
1916 $justify = $self->label->get_justify();
1917 if ($justify eq 'GTK_JUSTIFY_LEFT') {
1918 return 'left';
1919 } elsif ($justify eq 'GTK_JUSTIFY_RIGHT') {
1920 return 'right';
1921 } elsif ($justify eq 'GTK_JUSTIFY_CENTER') {
1922 return 'centre';
1923 } elsif ($justify eq 'GTK_JUSTIFY_FILL') {
1924 return 'fill';
1925 } else {
1926 return 'other';
1927 }
1928 }
1929  
1930 sub get_text {
1931  
1932 # Returns string
1933 my ($self, $check) = @_;
1934  
1935 # Check for improper arguments
1936 if (defined $check) {
1937  
1938 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_text', @_);
1939 }
1940  
1941 return $self->label->get_text();
1942 }
1943  
1944 sub get_tooltips {
1945  
1946 # Returns string
1947  
1948 my ($self, $check) = @_;
1949  
1950 # Check for improper arguments
1951 if (defined $check) {
1952  
1953 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_tooltips', @_);
1954 }
1955  
1956 return $self->label->get_tooltip_text();
1957 }
1958  
1959 sub get_underline {
1960  
1961 # Returns TRUE or FALSE
1962  
1963 my ($self, $check) = @_;
1964  
1965 # Check for improper arguments
1966 if (defined $check) {
1967  
1968 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_underline', @_);
1969 }
1970  
1971 if ($self->label->get_use_underline()) {
1972 return TRUE;
1973 } else {
1974 return FALSE;
1975 }
1976 }
1977  
1978 ##################
1979 # Accessors - get
1980  
1981 sub label
1982 { $_[0]->{label} }
1983 }
1984  
1985 { package Games::Axmud::Table::Button;
1986  
1987 use strict;
1988 use warnings;
1989 use diagnostics;
1990  
1991 use Glib qw(TRUE FALSE);
1992  
1993 our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud);
1994  
1995 ##################
1996 # Constructors
1997  
1998 sub new {
1999  
2000 # Called by GA::Strip::Table->addTableObj
2001 # Creates the GA::Table::Button, which contains a simple Gtk3::Button
2002 #
2003 # Expected arguments
2004 # $number - The table object's number within the parent strip object (matches
2005 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object
2006 # created to access its default IVs)
2007 # $name - A name for the table object. Can be any string or, if no name was
2008 # specified in the call to the calling function, $name is the same as
2009 # $number. (No part of the code checks that table object names are unique;
2010 # if two or more table objects share the same ->name, usually the one with
2011 # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
2012 # chars)
2013 # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table
2014 # objects
2015 # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
2016 # parent strip object's Gtk3::Grid for use exclusively by this table
2017 # object. 'temp' for temporary table objects
2018 #
2019 # Optional arguments
2020 # %initHash - A hash containing arbitrary data to use as the table object's
2021 # initialisation settings. The table object should use default
2022 # initialisation settings unless it can succesfully interpret one or more
2023 # of the key-value pairs in the hash, if there are any
2024 # - This type of table object recognises these initialisation settings:
2025 #
2026 # 'func' - Reference to a function to call when the button is clicked. If
2027 # not specified or 'undef', it's up to the calling code to create its
2028 # own ->signal_connect. To obtain a reference to an OOP method, you
2029 # can use the generic object function Games::Axmud->getMethodRef()
2030 # 'id' - A value passed to the function which identifies the button. If
2031 # specified, can be any value except 'undef'. It's up to the
2032 # calling code to keep track of the widgets it has created and their
2033 # corresponding 'id' values
2034 # 'text' - The text to display in the button. In Gtk, 'text' is
2035 # officially called a mnemonic, i.e. if any character is preceded by
2036 # an underline, that character is used as a keyboard accelerator
2037 # ('press' the button by pressing ALT + character). Must be plain
2038 # text, not pango markup. If not specified, 'undef' or an empty
2039 # string, no text is displayed
2040 # 'stock' - The stock Gtk3 icon and text to use on the button (e.g.
2041 # 'gtk-yes', 'gtk-save'. Ignored if 'text' is specified
2042 # 'image' - A Gtk3::Widget to display as an image on the button. Ignored
2043 # if 'text' or 'stock' are specified
2044 # 'underline_flag' - If TRUE, text is underlined. If FALSE (or not
2045 # specified), text is not underlined. Ignored if 'text' is not
2046 # specified
2047 # 'tooltips' - The text to display as tooltips for the button. Can be
2048 # plain text or pango markup text. If not specified, 'undef' or an
2049 # empty string, no tooltips are displayed
2050 # 'align_x', 'align_y' - The Gtk3::Button's alignment, values in the
2051 # range 0-1. If not specified, 'align_x' and/or 'align_y' are set to
2052 # 0.5. Ignored if 'text' is not specified
2053 # 'normal_flag' - If TRUE (or not specified), the button's state is
2054 # 'normal'. If FALSE, the button's state is 'insensitive' (nothing can
2055 # interact with it)
2056 # 'expand_horizontal_flag' - If TRUE or unspecified, the table object
2057 # expands horizontally; if FALSE, it doesn't. Note that typically,
2058 # alignment does not work unless expansion is enabled
2059 # 'expand_vertical_flag' - If TRUE or unspecified, the table object
2060 # expands vertically; if FALSE, it doesn't
2061 # 'expand_flag' - Deprecated since v1.2.170; ignored if specified
2062 #
2063 # Return values
2064 # 'undef' on improper arguments
2065 # Blessed reference to the newly-created object on success
2066  
2067 my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
2068  
2069 # Local variables
2070 my (
2071 $winObj,
2072 %modHash,
2073 );
2074  
2075 # Check for improper arguments
2076 if (
2077 ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
2078 || ! defined $zoneObj
2079 ) {
2080 return $axmud::CLIENT->writeImproper($class . '->new', @_);
2081 }
2082  
2083 # Deal with temporary table objects
2084 if ($stripObj eq 'temp') {
2085 $winObj = 'temp';
2086 } else {
2087 $winObj = $stripObj->winObj;
2088 }
2089  
2090 # Default initialisation settings
2091 %modHash = (
2092 'func' => undef,
2093 'id' => '',
2094 'text' => '',
2095 'stock' => undef,
2096 'image' => undef,
2097 'underline_flag' => FALSE,
2098 'tooltips' => undef,
2099 'align_x' => 0.5,
2100 'align_y' => 0.5,
2101 'normal_flag' => TRUE,
2102 'expand_horizontal_flag' => TRUE,
2103 'expand_vertical_flag' => TRUE,
2104 'expand_flag' => FALSE, # Deprecated since v1.2.170
2105 );
2106  
2107 # Interpret the initialisation settings in %initHash, if any
2108 foreach my $key (keys %modHash) {
2109  
2110 if (exists $initHash{$key}) {
2111  
2112 if ($key =~ m/flag$/) {
2113  
2114 if ($initHash{$key}) {
2115 $modHash{$key} = TRUE;
2116 } else {
2117 $modHash{$key} = FALSE;
2118 }
2119  
2120 } elsif ($key eq 'id' && ! defined $initHash{$key}) {
2121  
2122 $modHash{$key} = ''; # 'id' value must not be 'undef'
2123  
2124 } else {
2125  
2126 $modHash{$key} = $initHash{$key};
2127 }
2128 }
2129 }
2130  
2131 # Setup
2132 my $self = {
2133 _objName => 'table_obj_' . $number,
2134 _objClass => $class,
2135 _parentFile => undef, # No parent file object
2136 _parentWorld => undef, # No parent file object
2137 _privFlag => TRUE, # All IVs are private
2138  
2139 # Standard table object IVs
2140 # -------------------------
2141  
2142 # The table object's number within the parent strip object (matches
2143 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to
2144 # access its default IVs)
2145 number => $number,
2146 # A name for the table object. Can be any string or, if no name was specified in the
2147 # call to the calling function, $name is the same as $number. (No part of the code
2148 # checks that table object names are unique; if two or more table objects share the
2149 # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary
2150 # table objects. Max 16 chars)
2151 name => $name,
2152 # The type of table object (custom table objects should use a ->type starting with
2153 # 'custom_' to avoid clashing with future built-in table objects)
2154 type => 'button',
2155 # The parent strip object (GA::Strip::Table)
2156 stripObj => $stripObj,
2157 # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for
2158 # temporary table objects
2159 winObj => $winObj,
2160 # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip
2161 # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary
2162 # table objects
2163 zoneObj => $zoneObj,
2164  
2165 # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is
2166 # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as
2167 # when a connection to a world terminates)
2168 allowRemoveFlag => TRUE,
2169 # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is
2170 # created. Set to FALSE if it can't be resized
2171 allowResizeFlag => TRUE,
2172 # Initialisation settings stored as a hash (see the comments above)
2173 initHash => \%modHash,
2174 # Reference to a function to call when some widget is used. This IV is set only when
2175 # required by this type of table object. It can be set by a call to
2176 # $self->set_func() or by some setting in $self->initHash, which is applied in the
2177 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
2178 # generic object function Games::Axmud->getMethodRef()
2179 funcRef => undef,
2180 # A value passed to ->funcRef when it is called which identifies this table object and
2181 # its widget(s). Can be any value except 'undef'. It can be set by a call to
2182 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
2183 # to $self->objEnable()
2184 funcID => '',
2185  
2186 # The container widget(s) for this table object
2187 packingBox => undef, # Gtk3::Grid
2188 packingBox2 => undef, # Gtk3::Grid
2189  
2190  
2191 # Other IVs
2192 # ---------
2193  
2194 # Widgets
2195 button => undef, # Gtk3::Button
2196 };
2197  
2198 # Bless the object into existence
2199 bless $self, $class;
2200  
2201 return $self;
2202 }
2203  
2204 ##################
2205 # Methods
2206  
2207 # Standard table object functions
2208  
2209 sub objEnable {
2210  
2211 # Called by GA::Strip::Table->addTableObj
2212 # Sets up the table object's widgets
2213 #
2214 # Expected arguments
2215 # (none besides $self)
2216 #
2217 # Return values
2218 # 'undef' on improper arguments
2219 # 1 on success
2220  
2221 my ($self, $check) = @_;
2222  
2223 # Local variables
2224 my (
2225 $funcRef, $funcID, $text, $stock, $image, $underlineFlag, $tooltips, $alignX, $alignY,
2226 $normalFlag, $hExpandFlag, $vExpandFlag,
2227 );
2228  
2229 # Check for improper arguments
2230 if (defined $check) {
2231  
2232 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
2233 }
2234  
2235 # Interpret $self->initHash, replacing any invalid values
2236 $funcRef = $self->ivShow('initHash', 'func');
2237 $funcID = $self->ivShow('initHash', 'id');
2238 $text = $self->ivShow('initHash', 'text');
2239 $stock = $self->testStock($self->ivShow('initHash', 'stock'));
2240 $image = $self->ivShow('initHash', 'image');
2241 $underlineFlag = $self->testFlag($self->ivShow('initHash', 'underline_flag'));
2242 $tooltips = $self->ivShow('initHash', 'tooltips');
2243 $alignX = $self->testAlign($self->ivShow('initHash', 'align_x'), 0.5);
2244 $alignY = $self->testAlign($self->ivShow('initHash', 'align_y'), 0.5);
2245 $normalFlag = $self->testFlag($self->ivShow('initHash', 'normal_flag'));
2246 $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag'));
2247 $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag'));
2248  
2249 # Create packing box(es)
2250 my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::Grid->new());
2251  
2252 # Create the Gtk3::Button
2253 my $button;
2254 if (defined $text && $text ne '') {
2255 $button = Gtk3::Button->new($text);
2256 } elsif ($stock) {
2257 $button = Gtk3::Button->new_from_stock($stock);
2258 } else {
2259 $button = Gtk3::Button->new();
2260 }
2261  
2262 $packingBox2->attach($button, 0, 0, 1, 1);
2263  
2264 if (defined $text && $text ne '') {
2265  
2266 $button->set_use_underline($underlineFlag);
2267 $button->set_alignment($alignX, $alignY);
2268  
2269 } elsif (! $stock && $image) {
2270  
2271 $button->set_image($image);
2272 }
2273  
2274 if (defined $tooltips && $tooltips ne '') {
2275  
2276 $button->set_tooltip_markup($tooltips);
2277 }
2278  
2279 if (! $normalFlag) {
2280  
2281 $button->set_state('insensitive');
2282 }
2283  
2284 # Set expansion
2285 $button->set_hexpand($hExpandFlag);
2286 $button->set_vexpand($vExpandFlag);
2287  
2288 # Update IVs
2289 $self->ivPoke('funcRef', $funcRef);
2290 $self->ivPoke('funcID', $funcID);
2291 $self->ivPoke('packingBox', $packingBox);
2292 $self->ivPoke('packingBox2', $packingBox2);
2293 $self->ivPoke('button', $button);
2294  
2295 # Set up ->signal_connects
2296 $self->setClickedEvent();
2297  
2298 return 1;
2299 }
2300  
2301 # sub objDestroy { # Inherited from GA::Generic::Table
2302  
2303 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table
2304  
2305 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table
2306  
2307 # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table
2308  
2309 # ->signal_connects
2310  
2311 sub setClickedEvent {
2312  
2313 # Called by $self->objEnable
2314 #
2315 # Expected arguments
2316 # (none besides $self)
2317 #
2318 # Return values
2319 # 'undef' on improper arguments
2320 # 1 otherwise
2321  
2322 my ($self, $check) = @_;
2323  
2324 # Check for improper arguments
2325 if (defined $check) {
2326  
2327 return $axmud::CLIENT->writeImproper($self->_objClass . '->setClickedEvent', @_);
2328 }
2329  
2330 $self->button->signal_connect('clicked' => sub {
2331  
2332 my $currentFuncRef = $self->funcRef;
2333  
2334 if ($currentFuncRef) {
2335  
2336 &$currentFuncRef($self, $self->button, $self->funcID);
2337 }
2338 });
2339  
2340 return 1;
2341 }
2342  
2343 # Other functions
2344  
2345 ##################
2346 # Accessors - set
2347  
2348 sub set_align {
2349  
2350 my ($self, $alignX, $alignY, $check) = @_;
2351  
2352 # Check for improper arguments
2353 if (defined $check) {
2354  
2355 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_align', @_);
2356 }
2357  
2358 $alignX = $self->testAlign($alignX, 0);
2359 $alignY = $self->testAlign($alignY, 0.5);
2360  
2361 $self->button->set_alignment($alignX, $alignY);
2362  
2363 return 1;
2364 }
2365  
2366 # sub set_func {} # Inherited from GA::Generic::Table
2367  
2368 # sub set_id {} # Inherited from GA::Generic::Table
2369  
2370 sub set_normal {
2371  
2372 my ($self, $flag, $check) = @_;
2373  
2374 # Check for improper arguments
2375 if (defined $check) {
2376  
2377 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_normal', @_);
2378 }
2379  
2380 if (! $flag) {
2381 $self->button->set_sensitive(FALSE);
2382 } else {
2383 $self->button->set_sensitive(TRUE);
2384 }
2385  
2386 return 1;
2387 }
2388  
2389 sub set_text {
2390  
2391 my ($self, $text, $check) = @_;
2392  
2393 # Check for improper arguments
2394 if (defined $check) {
2395  
2396 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_text', @_);
2397 }
2398  
2399 if (! defined $text) {
2400  
2401 $text = '';
2402 }
2403  
2404 $self->button->set_label($text);
2405  
2406 return 1;
2407 }
2408  
2409 sub set_tooltips {
2410  
2411 my ($self, $tooltips, $check) = @_;
2412  
2413 # Check for improper arguments
2414 if (defined $check) {
2415  
2416 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_tooltips', @_);
2417 }
2418  
2419 if (! defined $tooltips || $tooltips eq '') {
2420 $self->button->set_tooltip_text(undef);
2421 } else {
2422 $self->button->set_tooltip_markup($tooltips);
2423 }
2424  
2425 return 1;
2426 }
2427  
2428 sub set_underline {
2429  
2430 my ($self, $flag, $check) = @_;
2431  
2432 # Check for improper arguments
2433 if (defined $check) {
2434  
2435 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_underline', @_);
2436 }
2437  
2438 $self->button->set_use_underline($self->testFlag($flag));
2439  
2440 return 1;
2441 }
2442  
2443 # (Get equivalents)
2444  
2445 sub get_align {
2446  
2447 # Returns list in form ($alignX, $alignY);
2448  
2449 my ($self, $alignX, $alignY, $check) = @_;
2450  
2451 # Check for improper arguments
2452 if (defined $check) {
2453  
2454 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_align', @_);
2455 }
2456  
2457 return $self->button->get_alignment();
2458 }
2459  
2460 sub get_normal {
2461  
2462 # Returns TRUE for 'normal', FALSE for 'insensitive' or any other value
2463  
2464 my ($self, $check) = @_;
2465  
2466 # Check for improper arguments
2467 if (defined $check) {
2468  
2469 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_normal', @_);
2470 }
2471  
2472 if ($self->button->get_sensitive()) {
2473 return TRUE;
2474 } else {
2475 return FALSE;
2476 }
2477  
2478 return 1;
2479 }
2480  
2481 sub get_text {
2482  
2483 # Returns string
2484 my ($self, $check) = @_;
2485  
2486 # Check for improper arguments
2487 if (defined $check) {
2488  
2489 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_text', @_);
2490 }
2491  
2492 return $self->button->get_label();
2493 }
2494  
2495 sub get_tooltips {
2496  
2497 # Returns string
2498  
2499 my ($self, $check) = @_;
2500  
2501 # Check for improper arguments
2502 if (defined $check) {
2503  
2504 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_tooltips', @_);
2505 }
2506  
2507 return $self->button->get_tooltip_text();
2508 }
2509  
2510 sub get_underline {
2511  
2512 # Returns TRUE or FALSE
2513  
2514 my ($self, $check) = @_;
2515  
2516 # Check for improper arguments
2517 if (defined $check) {
2518  
2519 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_underline', @_);
2520 }
2521  
2522 if ($self->button->get_use_underline()) {
2523 return TRUE;
2524 } else {
2525 return FALSE;
2526 }
2527 }
2528  
2529 ##################
2530 # Accessors - get
2531  
2532 sub button
2533 { $_[0]->{button} }
2534 }
2535  
2536 { package Games::Axmud::Table::CheckButton;
2537  
2538 use strict;
2539 use warnings;
2540 use diagnostics;
2541  
2542 use Glib qw(TRUE FALSE);
2543  
2544 our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud);
2545  
2546 ##################
2547 # Constructors
2548  
2549 sub new {
2550  
2551 # Called by GA::Strip::Table->addTableObj
2552 # Creates the GA::Table::CheckButton, which contains a simple Gtk3::CheckButton
2553 #
2554 # Expected arguments
2555 # $number - The table object's number within the parent strip object (matches
2556 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object
2557 # created to access its default IVs)
2558 # $name - A name for the table object. Can be any string or, if no name was
2559 # specified in the call to the calling function, $name is the same as
2560 # $number. (No part of the code checks that table object names are unique;
2561 # if two or more table objects share the same ->name, usually the one with
2562 # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
2563 # chars)
2564 # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table
2565 # objects
2566 # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
2567 # parent strip object's Gtk3::Grid for use exclusively by this table
2568 # object. 'temp' for temporary table objects
2569 #
2570 # Optional arguments
2571 # %initHash - A hash containing arbitrary data to use as the table object's
2572 # initialisation settings. The table object should use default
2573 # initialisation settings unless it can succesfully interpret one or more
2574 # of the key-value pairs in the hash, if there are any
2575 # - This type of table object recognises these initialisation settings:
2576 #
2577 # 'func' - Reference to a function to call when the button is clicked. If
2578 # not specified or 'undef', it's up to the calling code to create its
2579 # own ->signal_connect. To obtain a reference to an OOP method, you
2580 # can use the generic object function Games::Axmud->getMethodRef()
2581 # 'id' - A value passed to the function which identifies the button. If
2582 # specified, can be any value except 'undef'. It's up to the
2583 # calling code to keep track of the widgets it has created and their
2584 # corresponding 'id' values
2585 # 'text' - The text to display as a label next to the button. In In Gtk,
2586 # 'text' is officially called a mnemonic, i.e. if any character is
2587 # preceded by an underline, that character is used as a keyboard
2588 # accelerator ('press' the button by pressing ALT + character). Must
2589 # be plain text, not pango markup. If not specified, 'undef' or an
2590 # empty string, no text is displayed
2591 # 'tooltips' - The text to display as tooltips for the button. Can be
2592 # plain text or pango markup text. If not specified, 'undef' or an
2593 # empty string, no tooltips are displayed
2594 # 'align_x', 'align_y' - The Gtk3::Button's alignment, values in the
2595 # range 0-1. If not specified, 'align_x' is set to 0, 'align_y' is set
2596 # to 0.5. Ignored if 'text' is not specified
2597 # 'select_flag' - If TRUE, the button is selected (checked) initially, if
2598 # FALSE (or not specified), it is not checked initially
2599 # 'normal_flag' - If TRUE (or not specified), the button's state is
2600 # 'normal'. If FALSE, the button's state is 'insensitive' (nothing can
2601 # interact with it)
2602 # 'expand_horizontal_flag' - If TRUE or unspecified, the table object
2603 # expands horizontally; if FALSE, it doesn't. Note that typically,
2604 # alignment does not work unless expansion is enabled
2605 # 'expand_vertical_flag' - If TRUE or unspecified, the table object
2606 # expands vertically; if FALSE, it doesn't
2607 #
2608 # Return values
2609 # 'undef' on improper arguments
2610 # Blessed reference to the newly-created object on success
2611  
2612 my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
2613  
2614 # Local variables
2615 my (
2616 $winObj,
2617 %modHash,
2618 );
2619  
2620 # Check for improper arguments
2621 if (
2622 ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
2623 || ! defined $zoneObj
2624 ) {
2625 return $axmud::CLIENT->writeImproper($class . '->new', @_);
2626 }
2627  
2628 # Deal with temporary table objects
2629 if ($stripObj eq 'temp') {
2630 $winObj = 'temp';
2631 } else {
2632 $winObj = $stripObj->winObj;
2633 }
2634  
2635 # Default initialisation settings
2636 %modHash = (
2637 'func' => undef,
2638 'id' => '',
2639 'text' => undef,
2640 'tooltips' => undef,
2641 'align_x' => 0,
2642 'align_y' => 0.5,
2643 'select_flag' => FALSE,
2644 'normal_flag' => TRUE,
2645 'expand_horizontal_flag' => TRUE,
2646 'expand_vertical_flag' => TRUE,
2647 );
2648  
2649 # Interpret the initialisation settings in %initHash, if any
2650 foreach my $key (keys %modHash) {
2651  
2652 if (exists $initHash{$key}) {
2653  
2654 if ($key =~ m/flag$/) {
2655  
2656 if ($initHash{$key}) {
2657 $modHash{$key} = TRUE;
2658 } else {
2659 $modHash{$key} = FALSE;
2660 }
2661  
2662 } elsif ($key eq 'id' && ! defined $initHash{$key}) {
2663  
2664 $modHash{$key} = ''; # 'id' value must not be 'undef'
2665  
2666 } else {
2667  
2668 $modHash{$key} = $initHash{$key};
2669 }
2670 }
2671 }
2672  
2673 # Setup
2674 my $self = {
2675 _objName => 'table_obj_' . $number,
2676 _objClass => $class,
2677 _parentFile => undef, # No parent file object
2678 _parentWorld => undef, # No parent file object
2679 _privFlag => TRUE, # All IVs are private
2680  
2681 # Standard table object IVs
2682 # -------------------------
2683  
2684 # The table object's number within the parent strip object (matches
2685 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to
2686 # access its default IVs)
2687 number => $number,
2688 # A name for the table object. Can be any string or, if no name was specified in the
2689 # call to the calling function, $name is the same as $number. (No part of the code
2690 # checks that table object names are unique; if two or more table objects share the
2691 # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary
2692 # table objects. Max 16 chars)
2693 name => $name,
2694 # The type of table object (custom table objects should use a ->type starting with
2695 # 'custom_' to avoid clashing with future built-in table objects)
2696 type => 'check_button',
2697 # The parent strip object (GA::Strip::Table)
2698 stripObj => $stripObj,
2699 # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for
2700 # temporary table objects
2701 winObj => $winObj,
2702 # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip
2703 # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary
2704 # table objects
2705 zoneObj => $zoneObj,
2706  
2707 # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is
2708 # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as
2709 # when a connection to a world terminates)
2710 allowRemoveFlag => TRUE,
2711 # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is
2712 # created. Set to FALSE if it can't be resized
2713 allowResizeFlag => TRUE,
2714 # Initialisation settings stored as a hash (see the comments above)
2715 initHash => \%modHash,
2716 # Reference to a function to call when some widget is used. This IV is set only when
2717 # required by this type of table object. It can be set by a call to
2718 # $self->set_func() or by some setting in $self->initHash, which is applied in the
2719 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
2720 # generic object function Games::Axmud->getMethodRef()
2721 funcRef => undef,
2722 # A value passed to ->funcRef when it is called which identifies this table object and
2723 # its widget(s). Can be any value except 'undef'. It can be set by a call to
2724 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
2725 # to $self->objEnable()
2726 funcID => '',
2727  
2728 # The container widget(s) for this table object
2729 packingBox => undef, # Gtk3::Grid
2730 packingBox2 => undef, # Gtk3::Grid
2731  
2732  
2733 # Other IVs
2734 # ---------
2735  
2736 # Widgets
2737 button => undef, # Gtk3::CheckButton
2738 };
2739  
2740 # Bless the object into existence
2741 bless $self, $class;
2742  
2743 return $self;
2744 }
2745  
2746 ##################
2747 # Methods
2748  
2749 # Standard table object functions
2750  
2751 sub objEnable {
2752  
2753 # Called by GA::Strip::Table->addTableObj
2754 # Sets up the table object's widgets
2755 #
2756 # Expected arguments
2757 # (none besides $self)
2758 #
2759 # Return values
2760 # 'undef' on improper arguments
2761 # 1 on success
2762  
2763 my ($self, $check) = @_;
2764  
2765 # Local variables
2766 my (
2767 $funcRef, $funcID, $text, $tooltips, $alignX, $alignY, $selectFlag, $normalFlag,
2768 $hExpandFlag, $vExpandFlag,
2769 );
2770  
2771 # Check for improper arguments
2772 if (defined $check) {
2773  
2774 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
2775 }
2776  
2777 # Interpret $self->initHash, replacing any invalid values
2778 $funcRef = $self->ivShow('initHash', 'func');
2779 $funcID = $self->ivShow('initHash', 'id');
2780 $text = $self->ivShow('initHash', 'text');
2781 $tooltips = $self->ivShow('initHash', 'tooltips');
2782 $alignX = $self->testAlign($self->ivShow('initHash', 'align_x'), 0);
2783 $alignY = $self->testAlign($self->ivShow('initHash', 'align_y'), 0.5);
2784 $selectFlag = $self->testFlag($self->ivShow('initHash', 'select_flag'));
2785 $normalFlag = $self->testFlag($self->ivShow('initHash', 'normal_flag'));
2786 $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag'));
2787 $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag'));
2788  
2789 # Create packing box(es)
2790 my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::Grid->new());
2791  
2792 # Create the Gtk3::CheckButton
2793 my $button;
2794 if (defined $text && $text ne '') {
2795 $button = Gtk3::CheckButton->new_with_mnemonic($text);
2796 } else {
2797 $button = Gtk3::CheckButton->new();
2798 }
2799  
2800 $packingBox2->attach($button, 0, 0, 1, 1);
2801  
2802 if (defined $text && $text ne '') {
2803  
2804 $button->set_alignment($alignX, $alignY);
2805 }
2806  
2807 if (defined $tooltips && $tooltips ne '') {
2808  
2809 $button->set_tooltip_markup($tooltips);
2810 }
2811  
2812 $button->set_active($selectFlag);
2813 if (! $normalFlag) {
2814  
2815 $button->set_state('insensitive');
2816 }
2817  
2818 # Set expansion
2819 $button->set_hexpand($hExpandFlag);
2820 $button->set_vexpand($vExpandFlag);
2821  
2822 # Update IVs
2823 $self->ivPoke('funcRef', $funcRef);
2824 $self->ivPoke('funcID', $funcID);
2825 $self->ivPoke('packingBox', $packingBox);
2826 $self->ivPoke('packingBox2', $packingBox2);
2827 $self->ivPoke('button', $button);
2828  
2829 # Set up ->signal_connects
2830 $self->setToggledEvent();
2831  
2832 return 1;
2833 }
2834  
2835 # sub objDestroy { # Inherited from GA::Generic::Table
2836  
2837 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table
2838  
2839 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table
2840  
2841 # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table
2842  
2843 # ->signal_connects
2844  
2845 sub setToggledEvent {
2846  
2847 # Called by $self->objEnable
2848 #
2849 # Expected arguments
2850 # (none besides $self)
2851 #
2852 # Return values
2853 # 'undef' on improper arguments
2854 # 1 otherwise
2855  
2856 my ($self, $check) = @_;
2857  
2858 # Check for improper arguments
2859 if (defined $check) {
2860  
2861 return $axmud::CLIENT->writeImproper($self->_objClass . '->setToggledEvent', @_);
2862 }
2863  
2864 # ->signal_connect
2865 $self->button->signal_connect('toggled' => sub {
2866  
2867 my $currentFuncRef = $self->funcRef;
2868  
2869 if ($currentFuncRef) {
2870  
2871 if ($self->button->get_active()) {
2872 &$currentFuncRef($self, $self->button, $self->funcID, TRUE);
2873 } else {
2874 &$currentFuncRef($self, $self->button, $self->funcID, FALSE);
2875 }
2876 }
2877 });
2878  
2879 return 1;
2880 }
2881  
2882 # Other functions
2883  
2884 ##################
2885 # Accessors - set
2886  
2887 sub set_align {
2888  
2889 my ($self, $alignX, $alignY, $check) = @_;
2890  
2891 # Check for improper arguments
2892 if (defined $check) {
2893  
2894 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_align', @_);
2895 }
2896  
2897 $alignX = $self->testAlign($alignX, 0);
2898 $alignY = $self->testAlign($alignY, 0.5);
2899  
2900 $self->button->set_alignment($alignX, $alignY);
2901  
2902 return 1;
2903 }
2904  
2905 # sub set_func {} # Inherited from GA::Generic::Table
2906  
2907 # sub set_id {} # Inherited from GA::Generic::Table
2908  
2909 sub set_select {
2910  
2911 my ($self, $flag, $check) = @_;
2912  
2913 # Check for improper arguments
2914 if (defined $check) {
2915  
2916 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_select', @_);
2917 }
2918  
2919 $self->button->set_active($self->testFlag($flag));
2920  
2921 return 1;
2922 }
2923  
2924 sub set_normal {
2925  
2926 my ($self, $flag, $check) = @_;
2927  
2928 # Check for improper arguments
2929 if (defined $check) {
2930  
2931 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_normal', @_);
2932 }
2933  
2934 if (! $flag) {
2935 $self->button->set_state('insensitive');
2936 } else {
2937 $self->button->set_state('normal');
2938 }
2939  
2940 return 1;
2941 }
2942  
2943 sub set_text {
2944  
2945 my ($self, $text, $check) = @_;
2946  
2947 # Check for improper arguments
2948 if (defined $check) {
2949  
2950 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_text', @_);
2951 }
2952  
2953 if (! defined $text) {
2954  
2955 $text = '';
2956 }
2957  
2958 $self->button->set_label($text);
2959  
2960 return 1;
2961 }
2962  
2963 sub set_tooltips {
2964  
2965 my ($self, $tooltips, $check) = @_;
2966  
2967 # Check for improper arguments
2968 if (defined $check) {
2969  
2970 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_tooltips', @_);
2971 }
2972  
2973 if (! defined $tooltips || $tooltips eq '') {
2974 $self->button->set_tooltip_text(undef);
2975 } else {
2976 $self->button->set_tooltip_markup($tooltips);
2977 }
2978  
2979 return 1;
2980 }
2981  
2982 # (Get equivalents)
2983  
2984 sub get_align {
2985  
2986 # Returns list in form ($alignX, $alignY);
2987  
2988 my ($self, $alignX, $alignY, $check) = @_;
2989  
2990 # Check for improper arguments
2991 if (defined $check) {
2992  
2993 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_align', @_);
2994 }
2995  
2996 return $self->button->get_alignment();
2997 }
2998  
2999 sub get_normal {
3000  
3001 # Returns TRUE for 'normal', FALSE for 'insensitive' or any other value
3002  
3003 my ($self, $check) = @_;
3004  
3005 # Check for improper arguments
3006 if (defined $check) {
3007  
3008 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_normal', @_);
3009 }
3010  
3011 if ($self->button->get_state eq 'normal') {
3012 return TRUE;
3013 } else {
3014 return FALSE;
3015 }
3016  
3017 return 1;
3018 }
3019  
3020 sub get_select {
3021  
3022 # Returns TRUE or FALSE
3023  
3024 my ($self, $check) = @_;
3025  
3026 # Check for improper arguments
3027 if (defined $check) {
3028  
3029 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_select', @_);
3030 }
3031  
3032 if ($self->button->get_active()) {
3033 return TRUE;
3034 } else {
3035 return FALSE;
3036 }
3037  
3038 return 1;
3039 }
3040  
3041 sub get_text {
3042  
3043 # Returns string
3044 my ($self, $check) = @_;
3045  
3046 # Check for improper arguments
3047 if (defined $check) {
3048  
3049 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_text', @_);
3050 }
3051  
3052 return $self->button->get_label();
3053 }
3054  
3055 sub get_tooltips {
3056  
3057 # Returns string
3058  
3059 my ($self, $check) = @_;
3060  
3061 # Check for improper arguments
3062 if (defined $check) {
3063  
3064 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_tooltips', @_);
3065 }
3066  
3067 return $self->button->get_tooltip_text();
3068 }
3069  
3070 ##################
3071 # Accessors - get
3072  
3073 sub button
3074 { $_[0]->{button} }
3075 }
3076  
3077 { package Games::Axmud::Table::RadioButton;
3078  
3079 use strict;
3080 use warnings;
3081 use diagnostics;
3082  
3083 use Glib qw(TRUE FALSE);
3084  
3085 our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud);
3086  
3087 ##################
3088 # Constructors
3089  
3090 sub new {
3091  
3092 # Called by GA::Strip::Table->addTableObj
3093 # Creates the GA::Table::RadioButton, which contains a simple Gtk3::RadioButton
3094 #
3095 # Expected arguments
3096 # $number - The table object's number within the parent strip object (matches
3097 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object
3098 # created to access its default IVs)
3099 # $name - A name for the table object. Can be any string or, if no name was
3100 # specified in the call to the calling function, $name is the same as
3101 # $number. (No part of the code checks that table object names are unique;
3102 # if two or more table objects share the same ->name, usually the one with
3103 # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
3104 # chars)
3105 # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table
3106 # objects
3107 # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
3108 # parent strip object's Gtk3::Grid for use exclusively by this table
3109 # object. 'temp' for temporary table objects
3110 #
3111 # Optional arguments
3112 # %initHash - A hash containing arbitrary data to use as the table object's
3113 # initialisation settings. The table object should use default
3114 # initialisation settings unless it can succesfully interpret one or more
3115 # of the key-value pairs in the hash, if there are any
3116 # - This type of table object recognises these initialisation settings:
3117 #
3118 # 'func' - Reference to a function to call when the button is clicked. If
3119 # not specified or 'undef', it's up to the calling code to create its
3120 # own ->signal_connect. To obtain a reference to an OOP method, you
3121 # can use the generic object function Games::Axmud->getMethodRef()
3122 # 'id' - A value passed to the function which identifies the button. If
3123 # specified, can be any value except 'undef'. It's up to the
3124 # calling code to keep track of the widgets it has created and their
3125 # corresponding 'id' values
3126 # 'text' - The text to display as a label next to the button. In In Gtk,
3127 # 'text' is officially called a mnemonic, i.e. if any character is
3128 # preceded by an underline, that character is used as a keyboard
3129 # accelerator ('press' the button by pressing ALT + character). Must
3130 # be plain text, not pango markup. If not specified, 'undef' or an
3131 # empty string, no text is displayed
3132 # 'tooltips' - The text to display as tooltips for the button. Can be
3133 # plain text or pango markup text. If not specified, 'undef' or an
3134 # empty string, no tooltips are displayed
3135 # 'align_x', 'align_y' - The Gtk3::Button's alignment, values in the
3136 # range 0-1. If not specified, 'align_x' is set to 0, 'align_y' is set
3137 # to 0.5. Ignored if 'text' is not specified
3138 # 'select_flag' - If TRUE, the button is selected initially, if FALSE (or
3139 # not specified), it is not selected initially
3140 # 'normal_flag' - If TRUE (or not specified), the button's state is
3141 # 'normal'. If FALSE, the button's state is 'insensitive' (nothing can
3142 # interact with it)
3143 # 'group' - The radio button group from a previously-created
3144 # GA::Table::RadioButton object (and stored in its ->group IV). If
3145 # not specified or 'undef', this is the first radio button in its
3146 # group
3147 # 'expand_horizontal_flag' - If TRUE or unspecified, the table object
3148 # expands horizontally; if FALSE, it doesn't. Note that typically,
3149 # alignment does not work unless expansion is enabled
3150 # 'expand_vertical_flag' - If TRUE or unspecified, the table object
3151 # expands vertically; if FALSE, it doesn't
3152 #
3153 # Return values
3154 # 'undef' on improper arguments
3155 # Blessed reference to the newly-created object on success
3156  
3157 my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
3158  
3159 # Local variables
3160 my (
3161 $winObj,
3162 %modHash,
3163 );
3164  
3165 # Check for improper arguments
3166 if (
3167 ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
3168 || ! defined $zoneObj
3169 ) {
3170 return $axmud::CLIENT->writeImproper($class . '->new', @_);
3171 }
3172  
3173 # Deal with temporary table objects
3174 if ($stripObj eq 'temp') {
3175 $winObj = 'temp';
3176 } else {
3177 $winObj = $stripObj->winObj;
3178 }
3179  
3180 # Default initialisation settings
3181 %modHash = (
3182 'func' => undef,
3183 'id' => '',
3184 'text' => undef,
3185 'tooltips' => undef,
3186 'align_x' => 0,
3187 'align_y' => 0.5,
3188 'select_flag' => FALSE,
3189 'normal_flag' => TRUE,
3190 'group' => undef,
3191 'expand_horizontal_flag' => TRUE,
3192 'expand_vertical_flag' => TRUE,
3193 );
3194  
3195 # Interpret the initialisation settings in %initHash, if any
3196 foreach my $key (keys %modHash) {
3197  
3198 if (exists $initHash{$key}) {
3199  
3200 if ($key =~ m/flag$/) {
3201  
3202 if ($initHash{$key}) {
3203 $modHash{$key} = TRUE;
3204 } else {
3205 $modHash{$key} = FALSE;
3206 }
3207  
3208 } elsif ($key eq 'id' && ! defined $initHash{$key}) {
3209  
3210 $modHash{$key} = ''; # 'id' value must not be 'undef'
3211  
3212 } else {
3213  
3214 $modHash{$key} = $initHash{$key};
3215 }
3216 }
3217 }
3218  
3219 # Setup
3220 my $self = {
3221 _objName => 'table_obj_' . $number,
3222 _objClass => $class,
3223 _parentFile => undef, # No parent file object
3224 _parentWorld => undef, # No parent file object
3225 _privFlag => TRUE, # All IVs are private
3226  
3227 # Standard table object IVs
3228 # -------------------------
3229  
3230 # The table object's number within the parent strip object (matches
3231 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to
3232 # access its default IVs)
3233 number => $number,
3234 # A name for the table object. Can be any string or, if no name was specified in the
3235 # call to the calling function, $name is the same as $number. (No part of the code
3236 # checks that table object names are unique; if two or more table objects share the
3237 # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary
3238 # table objects. Max 16 chars)
3239 name => $name,
3240 # The type of table object (custom table objects should use a ->type starting with
3241 # 'custom_' to avoid clashing with future built-in table objects)
3242 type => 'radio_button',
3243 # The parent strip object (GA::Strip::Table)
3244 stripObj => $stripObj,
3245 # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for
3246 # temporary table objects
3247 winObj => $winObj,
3248 # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip
3249 # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary
3250 # table objects
3251 zoneObj => $zoneObj,
3252  
3253 # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is
3254 # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as
3255 # when a connection to a world terminates)
3256 allowRemoveFlag => TRUE,
3257 # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is
3258 # created. Set to FALSE if it can't be resized
3259 allowResizeFlag => TRUE,
3260 # Initialisation settings stored as a hash (see the comments above)
3261 initHash => \%modHash,
3262 # Reference to a function to call when some widget is used. This IV is set only when
3263 # required by this type of table object. It can be set by a call to
3264 # $self->set_func() or by some setting in $self->initHash, which is applied in the
3265 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
3266 # generic object function Games::Axmud->getMethodRef()
3267 funcRef => undef,
3268 # A value passed to ->funcRef when it is called which identifies this table object and
3269 # its widget(s). Can be any value except 'undef'. It can be set by a call to
3270 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
3271 # to $self->objEnable()
3272 funcID => '',
3273  
3274 # The container widget(s) for this table object
3275 packingBox => undef, # Gtk3::Grid
3276 packingBox2 => undef, # Gtk3::Grid
3277  
3278 # Other IVs
3279 # ---------
3280  
3281 # Widgets
3282 button => undef, # Gtk3::RadioButton
3283 group => undef, # Reference to array of widget references
3284 };
3285  
3286 # Bless the object into existence
3287 bless $self, $class;
3288  
3289 return $self;
3290 }
3291  
3292 ##################
3293 # Methods
3294  
3295 # Standard table object functions
3296  
3297 sub objEnable {
3298  
3299 # Called by GA::Strip::Table->addTableObj
3300 # Sets up the table object's widgets
3301 #
3302 # Expected arguments
3303 # (none besides $self)
3304 #
3305 # Return values
3306 # 'undef' on improper arguments
3307 # 1 on success
3308  
3309 my ($self, $check) = @_;
3310  
3311 # Local variables
3312 my (
3313 $funcRef, $funcID, $text, $tooltips, $alignX, $alignY, $selectFlag, $normalFlag, $group,
3314 $hExpandFlag, $vExpandFlag,
3315 );
3316  
3317 # Check for improper arguments
3318 if (defined $check) {
3319  
3320 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
3321 }
3322  
3323 # Interpret $self->initHash, replacing any invalid values
3324 $funcRef = $self->ivShow('initHash', 'func');
3325 $funcID = $self->ivShow('initHash', 'id');
3326 $text = $self->ivShow('initHash', 'text');
3327 $tooltips = $self->ivShow('initHash', 'tooltips');
3328 $alignX = $self->testAlign($self->ivShow('initHash', 'align_x'), 0);
3329 $alignY = $self->testAlign($self->ivShow('initHash', 'align_y'), 0.5);
3330 $selectFlag = $self->testFlag($self->ivShow('initHash', 'select_flag'));
3331 $normalFlag = $self->testFlag($self->ivShow('initHash', 'normal_flag'));
3332 $group = $self->ivShow('initHash', 'group');
3333 $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag'));
3334 $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag'));
3335  
3336 # Create packing box(es)
3337 my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::Grid->new());
3338  
3339 # Create the Gtk3::RadioButton
3340 my $button = Gtk3::RadioButton->new();
3341 $packingBox2->attach($button, 0, 0, 1, 1);
3342  
3343 if (defined $text && $text ne '') {
3344  
3345 $button->set_label($text);
3346 $button->set_alignment($alignX, $alignY);
3347 }
3348  
3349 if (defined $tooltips && $tooltips ne '') {
3350  
3351 $button->set_tooltip_markup($tooltips);
3352 }
3353  
3354 if ($group) {
3355  
3356 $button->set_group($group);
3357 }
3358  
3359 $button->set_active($selectFlag);
3360 if (! $normalFlag) {
3361  
3362 $button->set_state('insensitive');
3363 }
3364  
3365 # Set expansion
3366 $button->set_hexpand($hExpandFlag);
3367 $button->set_vexpand($vExpandFlag);
3368  
3369 # Update IVs
3370 $self->ivPoke('funcRef', $funcRef);
3371 $self->ivPoke('funcID', $funcID);
3372 $self->ivPoke('packingBox', $packingBox);
3373 $self->ivPoke('packingBox2', $packingBox2);
3374 $self->ivPoke('button', $button);
3375 $self->ivPoke('group', $button->get_group());
3376  
3377 # Set up ->signal_connects
3378 $self->setToggledEvent();
3379  
3380 return 1;
3381 }
3382  
3383 # sub objDestroy { # Inherited from GA::Generic::Table
3384  
3385 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table
3386  
3387 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table
3388  
3389 # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table
3390  
3391 # ->signal_connects
3392  
3393 sub setToggledEvent {
3394  
3395 # Called by $self->objEnable
3396 #
3397 # Expected arguments
3398 # (none besides $self)
3399 #
3400 # Return values
3401 # 'undef' on improper arguments
3402 # 1 otherwise
3403  
3404 my ($self, $check) = @_;
3405  
3406 # Check for improper arguments
3407 if (defined $check) {
3408  
3409 return $axmud::CLIENT->writeImproper($self->_objClass . '->setToggledEvent', @_);
3410 }
3411  
3412 $self->button->signal_connect('toggled' => sub {
3413  
3414 my $currentFuncRef = $self->funcRef;
3415  
3416 # (Only call the function is the radio button is now active)
3417 if ($currentFuncRef && $self->button->get_active()) {
3418  
3419 &$currentFuncRef($self, $self->button, $self->funcID);
3420 }
3421 });
3422  
3423 return 1;
3424 }
3425  
3426 # Other functions
3427  
3428 ##################
3429 # Accessors - set
3430  
3431 sub set_align {
3432  
3433 my ($self, $alignX, $alignY, $check) = @_;
3434  
3435 # Check for improper arguments
3436 if (defined $check) {
3437  
3438 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_align', @_);
3439 }
3440  
3441 $alignX = $self->testAlign($alignX, 0);
3442 $alignY = $self->testAlign($alignY, 0.5);
3443  
3444 $self->button->set_alignment($alignX, $alignY);
3445  
3446 return 1;
3447 }
3448  
3449 # sub set_func {} # Inherited from GA::Generic::Table
3450  
3451 # sub set_id {} # Inherited from GA::Generic::Table
3452  
3453 sub set_normal {
3454  
3455 my ($self, $flag, $check) = @_;
3456  
3457 # Check for improper arguments
3458 if (defined $check) {
3459  
3460 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_normal', @_);
3461 }
3462  
3463 if (! $flag) {
3464 $self->button->set_state('insensitive');
3465 } else {
3466 $self->button->set_state('normal');
3467 }
3468  
3469 return 1;
3470 }
3471  
3472 sub set_select {
3473  
3474 my ($self, $flag, $check) = @_;
3475  
3476 # Check for improper arguments
3477 if (defined $check) {
3478  
3479 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_select', @_);
3480 }
3481  
3482 $self->button->set_active($self->testFlag($flag));
3483  
3484 return 1;
3485 }
3486  
3487 sub set_text {
3488  
3489 my ($self, $text, $check) = @_;
3490  
3491 # Check for improper arguments
3492 if (defined $check) {
3493  
3494 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_text', @_);
3495 }
3496  
3497 if (! defined $text) {
3498  
3499 $text = '';
3500 }
3501  
3502 $self->button->set_label($text);
3503  
3504 return 1;
3505 }
3506  
3507 sub set_tooltips {
3508  
3509 my ($self, $tooltips, $check) = @_;
3510  
3511 # Check for improper arguments
3512 if (defined $check) {
3513  
3514 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_tooltips', @_);
3515 }
3516  
3517 if (! defined $tooltips || $tooltips eq '') {
3518 $self->button->set_tooltip_text(undef);
3519 } else {
3520 $self->button->set_tooltip_markup($tooltips);
3521 }
3522  
3523 return 1;
3524 }
3525  
3526 # (Get equivalents)
3527  
3528 sub get_align {
3529  
3530 # Returns list in form ($alignX, $alignY);
3531  
3532 my ($self, $alignX, $alignY, $check) = @_;
3533  
3534 # Check for improper arguments
3535 if (defined $check) {
3536  
3537 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_align', @_);
3538 }
3539  
3540 return $self->button->get_alignment();
3541 }
3542  
3543 sub get_normal {
3544  
3545 # Returns TRUE for 'normal', FALSE for 'insensitive' or any other value
3546  
3547 my ($self, $check) = @_;
3548  
3549 # Check for improper arguments
3550 if (defined $check) {
3551  
3552 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_normal', @_);
3553 }
3554  
3555 if ($self->button->get_state eq 'normal') {
3556 return TRUE;
3557 } else {
3558 return FALSE;
3559 }
3560  
3561 return 1;
3562 }
3563  
3564 sub get_select {
3565  
3566 # Returns TRUE or FALSE
3567  
3568 my ($self, $check) = @_;
3569  
3570 # Check for improper arguments
3571 if (defined $check) {
3572  
3573 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_select', @_);
3574 }
3575  
3576 if ($self->button->get_active()) {
3577 return TRUE;
3578 } else {
3579 return FALSE;
3580 }
3581  
3582 return 1;
3583 }
3584  
3585 sub get_text {
3586  
3587 # Returns string
3588 my ($self, $check) = @_;
3589  
3590 # Check for improper arguments
3591 if (defined $check) {
3592  
3593 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_text', @_);
3594 }
3595  
3596 return $self->button->get_label();
3597 }
3598  
3599 sub get_tooltips {
3600  
3601 # Returns string
3602  
3603 my ($self, $check) = @_;
3604  
3605 # Check for improper arguments
3606 if (defined $check) {
3607  
3608 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_tooltips', @_);
3609 }
3610  
3611 return $self->button->get_tooltip_text();
3612 }
3613  
3614 ##################
3615 # Accessors - get
3616  
3617 sub button
3618 { $_[0]->{button} }
3619 sub group
3620 { $_[0]->{group} }
3621 }
3622  
3623 { package Games::Axmud::Table::Entry;
3624  
3625 use strict;
3626 use warnings;
3627 use diagnostics;
3628  
3629 use Glib qw(TRUE FALSE);
3630  
3631 our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud);
3632  
3633 ##################
3634 # Constructors
3635  
3636 sub new {
3637  
3638 # Called by GA::Strip::Table->addTableObj
3639 # Creates the GA::Table::Entry, which contains a simple Gtk3::Entry
3640 #
3641 # Expected arguments
3642 # $number - The table object's number within the parent strip object (matches
3643 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object
3644 # created to access its default IVs)
3645 # $name - A name for the table object. Can be any string or, if no name was
3646 # specified in the call to the calling function, $name is the same as
3647 # $number. (No part of the code checks that table object names are unique;
3648 # if two or more table objects share the same ->name, usually the one with
3649 # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
3650 # chars)
3651 # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table
3652 # objects
3653 # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
3654 # parent strip object's Gtk3::Grid for use exclusively by this table
3655 # object. 'temp' for temporary table objects
3656 #
3657 # Optional arguments
3658 # %initHash - A hash containing arbitrary data to use as the table object's
3659 # initialisation settings. The table object should use default
3660 # initialisation settings unless it can succesfully interpret one or more
3661 # of the key-value pairs in the hash, if there are any
3662 # - This type of table object recognises these initialisation settings:
3663 #
3664 # 'func' - Reference to a function to call when the user types something
3665 # in the entry box and presses 'return'. If not specified or 'undef',
3666 # it's up to the calling code to create its own ->signal_connect. To
3667 # obtain a reference to an OOP method, you can use the generic object
3668 # function Games::Axmud->getMethodRef()
3669 # 'id' - A value passed to the function which identifies the button. If
3670 # specified, can be any value except 'undef'. It's up to the
3671 # calling code to keep track of the widgets it has created and their
3672 # corresponding 'id' values
3673 # 'text' - The initial contents of the entry. If an empty string or
3674 # 'undef', the entry is initially empty
3675 # 'width_chars' - The width of the entry, in characters. If not
3676 # specified, 0 or 'undef', a width is not applied to the entry
3677 # 'max_chars' - The maximum number of characters the entry can contain.
3678 # If not specified, 0 or 'undef', no maximum is applied to the entry
3679 # 'tooltips' - The text to display as tooltips for the entry. Can be
3680 # plain text or pango markup text. If not specified, 'undef' or an
3681 # empty string, no tooltips are displayed
3682 # 'normal_flag' - If TRUE (or not specified), the entry's state is
3683 # 'normal'. If FALSE, the button's state is 'insensitive' (nothing can
3684 # interact with it)
3685 # 'expand_flag' - Deprecated since v1.2.170; ignored if specified
3686 # 'expand_horizontal_flag' - If TRUE or unspecified, the table object
3687 # expands horizontally; if FALSE, it doesn't
3688 # 'expand_vertical_flag' - If TRUE or unspecified, the table object
3689 # expands vertically; if FALSE, it doesn't
3690 # 'check_flag' - If specified, the entry contains a stock icon which
3691 # indicates whether the entry's text is acceptable. The function
3692 # specified by 'func' will then only be called when the user presses
3693 # 'return' AND the entry's text is acceptable
3694 # 'check_yes' - The stock icon to use to show the entry's text is
3695 # acceptable. If not specified, 'gtk-yes' is used. (Ignored when
3696 # 'check_flag' is not specified)
3697 # 'check_no' - The stock icon to use to show the entry's text is not
3698 # acceptable. If not specified, 'gtk-no' is used. (Ignored when
3699 # 'check_flag' is not specified)
3700 # 'check_func' - Reference to a function which receives the entry's text
3701 # as an argument, and returns 1 if the text is acceptable, but 'undef'
3702 # if it's not acceptable. If not specified, 'check_type' is used to
3703 # judge acceptability instead. (Ignored when 'check_flag' is not
3704 # specified)
3705 # 'check_type' - Set to 'int' (to be acceptable, the entry's text must be
3706 # an integer), 'odd' (the entry's text must be an odd-numbered
3707 # integer), 'even' (the entry's text must be an even-numbered
3708 # integer), 'float' (the entry's text must be an integer or floating
3709 # point number), 'string' (the entry's text can contain anything, even
3710 # an empty string). If not specified, 'string' is used as a default.
3711 # (Ignored when 'check_flag' is not specified or if 'check_func' is
3712 # specified)
3713 # 'check_min', 'check_max' - For 'int'/'float', the minimum/maximum
3714 # values that are acceptable. For 'odd'/'even', the minimum/maximum
3715 # values that are acceptable; if the minimum value is less than 1 or 2
3716 # respectively, then 1 or 2 are used instead. For 'string', the
3717 # minimum/maximum length of the string. If either or both values are
3718 # not specified or 'undef', then no minimumx and/or maximum applies.
3719 # (Ignored when 'check_flag' is not specified or if 'check_func' is
3720 # specified)
3721 #
3722 # Return values
3723 # 'undef' on improper arguments
3724 # Blessed reference to the newly-created object on success
3725  
3726 my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
3727  
3728 # Local variables
3729 my (
3730 $winObj,
3731 %modHash,
3732 );
3733  
3734 # Check for improper arguments
3735 if (
3736 ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
3737 || ! defined $zoneObj
3738 ) {
3739 return $axmud::CLIENT->writeImproper($class . '->new', @_);
3740 }
3741  
3742 # Deal with temporary table objects
3743 if ($stripObj eq 'temp') {
3744 $winObj = 'temp';
3745 } else {
3746 $winObj = $stripObj->winObj;
3747 }
3748  
3749 # Default initialisation settings
3750 %modHash = (
3751 'func' => undef,
3752 'id' => '',
3753 'text' => undef,
3754 'width_chars' => 0,
3755 'max_chars' => 0,
3756 'tooltips' => undef,
3757 'normal_flag' => TRUE,
3758 'expand_flag' => TRUE, # Deprecated since v1.2.170
3759 'expand_horizontal_flag' => TRUE,
3760 'expand_vertical_flag' => TRUE,
3761 'check_flag' => FALSE,
3762 'check_yes' => 'gtk-yes',
3763 'check_no' => 'gtk-no',
3764 'check_func' => undef,
3765 'check_type' => 'string',
3766 'check_min' => undef,
3767 'check_max' => undef,
3768 );
3769  
3770 # Interpret the initialisation settings in %initHash, if any
3771 foreach my $key (keys %modHash) {
3772  
3773 if (exists $initHash{$key}) {
3774  
3775 if ($key =~ m/flag$/) {
3776  
3777 if ($initHash{$key}) {
3778 $modHash{$key} = TRUE;
3779 } else {
3780 $modHash{$key} = FALSE;
3781 }
3782  
3783 } elsif ($key eq 'id' && ! defined $initHash{$key}) {
3784  
3785 $modHash{$key} = ''; # 'id' value must not be 'undef'
3786  
3787 } else {
3788  
3789 $modHash{$key} = $initHash{$key};
3790 }
3791 }
3792 }
3793  
3794 # Setup
3795 my $self = {
3796 _objName => 'table_obj_' . $number,
3797 _objClass => $class,
3798 _parentFile => undef, # No parent file object
3799 _parentWorld => undef, # No parent file object
3800 _privFlag => TRUE, # All IVs are private
3801  
3802 # Standard table object IVs
3803 # -------------------------
3804  
3805 # The table object's number within the parent strip object (matches
3806 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to
3807 # access its default IVs)
3808 number => $number,
3809 # A name for the table object. Can be any string or, if no name was specified in the
3810 # call to the calling function, $name is the same as $number. (No part of the code
3811 # checks that table object names are unique; if two or more table objects share the
3812 # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary
3813 # table objects. Max 16 chars)
3814 name => $name,
3815 # The type of table object (custom table objects should use a ->type starting with
3816 # 'custom_' to avoid clashing with future built-in table objects)
3817 type => 'entry',
3818 # The parent strip object (GA::Strip::Table)
3819 stripObj => $stripObj,
3820 # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for
3821 # temporary table objects
3822 winObj => $winObj,
3823 # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip
3824 # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary
3825 # table objects
3826 zoneObj => $zoneObj,
3827  
3828 # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is
3829 # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as
3830 # when a connection to a world terminates)
3831 allowRemoveFlag => TRUE,
3832 # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is
3833 # created. Set to FALSE if it can't be resized
3834 allowResizeFlag => TRUE,
3835 # Initialisation settings stored as a hash (see the comments above)
3836 initHash => \%modHash,
3837 # Reference to a function to call when some widget is used. This IV is set only when
3838 # required by this type of table object. It can be set by a call to
3839 # $self->set_func() or by some setting in $self->initHash, which is applied in the
3840 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
3841 # generic object function Games::Axmud->getMethodRef()
3842 funcRef => undef,
3843 # A value passed to ->funcRef when it is called which identifies this table object and
3844 # its widget(s). Can be any value except 'undef'. It can be set by a call to
3845 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
3846 # to $self->objEnable()
3847 funcID => '',
3848  
3849 # The container widget(s) for this table object
3850 packingBox => undef, # Gtk3::Grid
3851 packingBox2 => undef, # Gtk3::Grid
3852  
3853 # Other IVs
3854 # ---------
3855  
3856 # Widgets
3857 entry => undef, # Gtk3::Entry
3858  
3859 # IVs set by $self->objEnable, using values from $self->initHash after checking they're
3860 # valid (and using default values, if not)
3861 checkFlag => undef,
3862 checkYes => undef,
3863 checkNo => undef,
3864 checkFunc => undef,
3865 checkType => undef,
3866 checkMin => undef,
3867 checkMax => undef,
3868 };
3869  
3870 # Bless the object into existence
3871 bless $self, $class;
3872  
3873 return $self;
3874 }
3875  
3876 ##################
3877 # Methods
3878  
3879 # Standard table object functions
3880  
3881 sub objEnable {
3882  
3883 # Called by GA::Strip::Table->addTableObj
3884 # Sets up the table object's widgets
3885 #
3886 # Expected arguments
3887 # (none besides $self)
3888 #
3889 # Return values
3890 # 'undef' on improper arguments
3891 # 1 on success
3892  
3893 my ($self, $check) = @_;
3894  
3895 # Local variables
3896 my (
3897 $funcRef, $funcID, $text, $widthChars, $maxChars, $tooltips, $normalFlag, $hExpandFlag,
3898 $vExpandFlag, $checkFlag, $checkYes, $checkNo, $checkFunc, $checkType, $checkMin,
3899 $checkMax,
3900 );
3901  
3902 # Check for improper arguments
3903 if (defined $check) {
3904  
3905 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
3906 }
3907  
3908 # Interpret $self->initHash, replacing any invalid values
3909 $funcRef = $self->ivShow('initHash', 'func');
3910 $funcID = $self->ivShow('initHash', 'id');
3911 $text = $self->ivShow('initHash', 'text');
3912 $widthChars = $self->testInt($self->ivShow('initHash', 'width_chars'), 0, 0);
3913 $maxChars = $self->testInt($self->ivShow('initHash', 'max_chars'), 0, 0);
3914 $tooltips = $self->ivShow('initHash', 'tooltips');
3915 $normalFlag = $self->testFlag($self->ivShow('initHash', 'normal_flag'));
3916 $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag'));
3917 $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag'));
3918 $checkFlag = $self->testFlag($self->ivShow('initHash', 'check_flag'));
3919  
3920 if ($checkFlag) {
3921  
3922 $checkYes = $self->testStock($self->ivShow('initHash', 'check_yes'), 'gtk-yes');
3923 $checkNo = $self->testStock($self->ivShow('initHash', 'check_no'), 'gtk-no');
3924 $checkFunc = $self->ivShow('initHash', 'check_func');
3925 $checkType = $self->ivShow('initHash', 'check_type');
3926 if (
3927 ! defined $checkType
3928 || (
3929 $checkType ne 'int'
3930 && $checkType ne 'even'
3931 && $checkType ne 'odd'
3932 && $checkType ne 'float'
3933 && $checkType ne 'string'
3934 )
3935 ) {
3936 $checkType = 'string';
3937 }
3938  
3939 $checkMin = $self->testInt($self->ivShow('initHash', 'check_min'), undef, undef);
3940 $checkMax = $self->testInt($self->ivShow('initHash', 'check_max'), undef, undef);
3941 if (defined $checkMin && defined $checkMax && $checkMin > $checkMax) {
3942  
3943 $checkMin = undef;
3944 $checkMax = undef;
3945 }
3946  
3947 if (defined $checkType) {
3948  
3949 if ($checkType eq 'odd' && defined $checkMin && $checkMin < 1) {
3950  
3951 $checkMin = 1;
3952  
3953 } elsif ($checkType eq 'even' && defined $checkMin && $checkMin < 2) {
3954  
3955 $checkMin = 2;
3956 }
3957  
3958 if ($checkType eq 'string' && defined $checkMin && $checkMin < 0) {
3959  
3960 $checkMin = 0;
3961 }
3962  
3963 if ($checkType eq 'string' && defined $checkMax && $checkMax < 0) {
3964  
3965 $checkMax = 0;
3966 }
3967 }
3968 }
3969  
3970 # Create packing box(es)
3971 my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::Grid->new());
3972  
3973 # Create the Gtk3::Entry
3974 my $entry = Gtk3::Entry->new();
3975 $packingBox2->attach($entry, 0, 0, 1, 1);
3976 if (defined $text && $text ne '') {
3977  
3978 $entry->set_text($text);
3979 }
3980  
3981 if ($checkFlag && ! $checkFunc) {
3982  
3983 if ($self->testIconValue($text, $checkType, $checkMax, $checkMin)) {
3984 $entry->set_icon_from_stock('secondary', $self->checkNo);
3985 } else {
3986 $entry->set_icon_from_stock('secondary', $self->checkYes);
3987 }
3988 }
3989  
3990 if ($widthChars) {
3991  
3992 $entry->set_width_chars($widthChars);
3993 }
3994  
3995 if ($maxChars) {
3996  
3997 $entry->set_max_length($maxChars);
3998 }
3999  
4000 if (defined $tooltips && $tooltips ne '') {
4001  
4002 $entry->set_tooltip_markup($tooltips);
4003 }
4004  
4005 if (! $normalFlag) {
4006  
4007 $entry->set_state('insensitive');
4008 }
4009  
4010 # Set expansion
4011 $entry->set_hexpand($hExpandFlag);
4012 $entry->set_vexpand($vExpandFlag);
4013  
4014 # Update IVs
4015 $self->ivPoke('funcRef', $funcRef);
4016 $self->ivPoke('funcID', $funcID);
4017 $self->ivPoke('packingBox', $packingBox);
4018 $self->ivPoke('packingBox2', $packingBox2);
4019 $self->ivPoke('entry', $entry);
4020 $self->ivPoke('checkFlag', $checkFlag);
4021 $self->ivPoke('checkYes', $checkYes);
4022 $self->ivPoke('checkNo', $checkNo);
4023 $self->ivPoke('checkFunc', $checkFunc);
4024 $self->ivPoke('checkType', $checkType);
4025 $self->ivPoke('checkMin', $checkMin);
4026 $self->ivPoke('checkMax', $checkMax);
4027  
4028 # Set up ->signal_connects
4029 $self->setChangedEvent();
4030 $self->setActivateEvent();
4031  
4032 return 1;
4033 }
4034  
4035 # sub objDestroy { # Inherited from GA::Generic::Table
4036  
4037 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table
4038  
4039 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table
4040  
4041 # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table
4042  
4043 # ->signal_connects
4044  
4045 sub setChangedEvent {
4046  
4047 # Called by $self->objEnable
4048 #
4049 # Expected arguments
4050 # (none besides $self)
4051 #
4052 # Return values
4053 # 'undef' on improper arguments
4054 # 1 otherwise
4055  
4056 my ($self, $check) = @_;
4057  
4058 # Check for improper arguments
4059 if (defined $check) {
4060  
4061 return $axmud::CLIENT->writeImproper($self->_objClass . '->setChangedEvent', @_);
4062 }
4063  
4064 $self->entry->signal_connect('changed' => sub {
4065  
4066 my ($value, $thisCheckFunc);
4067  
4068 $value = $self->entry->get_text();
4069 $thisCheckFunc = $self->checkFunc;
4070  
4071 if ($self->checkFlag) {
4072  
4073 if (! $thisCheckFunc) {
4074  
4075 if (
4076 ! $self->testIconValue(
4077 $value,
4078 $self->checkType,
4079 $self->checkMin,
4080 $self->checkMax,
4081 )
4082 ) {
4083 $self->entry->set_icon_from_stock('secondary', $self->checkNo);
4084 } else {
4085 $self->entry->set_icon_from_stock('secondary', $self->checkYes);
4086 }
4087  
4088 } else {
4089  
4090 if (! &$thisCheckFunc($self, $self->entry, $self->funcID, $value)) {
4091 $self->entry->set_icon_from_stock('secondary', $self->checkNo);
4092 } else {
4093 $self->entry->set_icon_from_stock('secondary', $self->checkYes);
4094 }
4095 }
4096 }
4097 });
4098  
4099 return 1;
4100 }
4101  
4102 sub setActivateEvent {
4103  
4104 # Called by $self->objEnable
4105 #
4106 # Expected arguments
4107 # (none besides $self)
4108 #
4109 # Return values
4110 # 'undef' on improper arguments
4111 # 1 otherwise
4112  
4113 my ($self, $check) = @_;
4114  
4115 # Check for improper arguments
4116 if (defined $check) {
4117  
4118 return $axmud::CLIENT->writeImproper($self->_objClass . '->setActivateEvent', @_);
4119 }
4120  
4121 $self->entry->signal_connect('activate' => sub {
4122  
4123 my ($value, $thisFuncRef);
4124  
4125 $value = $self->entry->get_text();
4126 $thisFuncRef = $self->funcRef;
4127  
4128 if (
4129 $thisFuncRef
4130 && (
4131 ! $self->checkFlag || $self->testIconValue(
4132 $value,
4133 $self->checkType,
4134 $self->checkMin,
4135 $self->checkMax,
4136 )
4137 )
4138 ) {
4139 &$thisFuncRef($self, $self->entry, $self->funcID, $value);
4140 }
4141  
4142 $self->entry->set_text('');
4143 });
4144  
4145 return 1;
4146 }
4147  
4148 # Other functions
4149  
4150 ##################
4151 # Accessors - set
4152  
4153 sub set_check_func {
4154  
4155 # If $funcRef is 'undef', $self->checkType is used to judge acceptability instead
4156  
4157 my ($self, $funcRef, $check) = @_;
4158  
4159 # Check for improper arguments
4160 if (defined $check) {
4161  
4162 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_check_func', @_);
4163 }
4164  
4165 if (! $self->checkFlag) {
4166  
4167 return undef;
4168  
4169 } else {
4170  
4171 $self->ivPoke('checkFunc', $funcRef);
4172  
4173 return 1;
4174 }
4175 }
4176  
4177 sub set_check_max {
4178  
4179 my ($self, $num, $check) = @_;
4180  
4181 # Check for improper arguments
4182 if (defined $check) {
4183  
4184 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_check_max', @_);
4185 }
4186  
4187 if (! $self->checkFlag) {
4188  
4189 return undef;
4190  
4191 } else {
4192  
4193 $self->ivPoke('checkMax', $self->testInt($num, undef, undef));
4194  
4195 return 1;
4196 }
4197 }
4198  
4199 sub set_check_min {
4200  
4201 my ($self, $num, $check) = @_;
4202  
4203 # Check for improper arguments
4204 if (defined $check) {
4205  
4206 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_check_min', @_);
4207 }
4208  
4209 if (! $self->checkFlag) {
4210  
4211 return undef;
4212  
4213 } else {
4214  
4215 $self->ivPoke('checkMin', $self->testInt($num, undef, undef));
4216  
4217 return 1;
4218 }
4219 }
4220  
4221 sub set_check_type {
4222  
4223 my ($self, $type, $check) = @_;
4224  
4225 # Check for improper arguments
4226 if (defined $check) {
4227  
4228 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_check_type', @_);
4229 }
4230  
4231 if (! $self->checkFlag) {
4232  
4233 return undef;
4234 }
4235  
4236 if (
4237 ! defined $type
4238 || (
4239 $type ne 'int'
4240 && $type ne 'even'
4241 && $type ne 'odd'
4242 && $type ne 'float'
4243 && $type ne 'string'
4244 )
4245 ) {
4246 $type = 'string';
4247 }
4248  
4249 $self->ivPoke('checkType', $type);
4250  
4251 return 1;
4252 }
4253  
4254 # sub set_func {} # Inherited from GA::Generic::Table
4255  
4256 # sub set_id {} # Inherited from GA::Generic::Table
4257  
4258 sub set_max_chars {
4259  
4260 my ($self, $num, $check) = @_;
4261  
4262 # Check for improper arguments
4263 if (defined $check) {
4264  
4265 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_max_chars', @_);
4266 }
4267  
4268 $self->entry->set_max_length($self->testInt($num, 0, 0));
4269  
4270 return 1;
4271 }
4272  
4273 sub set_normal {
4274  
4275 my ($self, $flag, $check) = @_;
4276  
4277 # Check for improper arguments
4278 if (defined $check) {
4279  
4280 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_normal', @_);
4281 }
4282  
4283 if (! $flag) {
4284 $self->entry->set_state('insensitive');
4285 } else {
4286 $self->entry->set_state('normal');
4287 }
4288  
4289 return 1;
4290 }
4291  
4292 sub set_text {
4293  
4294 my ($self, $text, $check) = @_;
4295  
4296 # Check for improper arguments
4297 if (defined $check) {
4298  
4299 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_text', @_);
4300 }
4301  
4302 if (! defined $text) {
4303  
4304 $text = '';
4305 }
4306  
4307 $self->entry->set_text($text);
4308  
4309 return 1;
4310 }
4311  
4312 sub set_tooltips {
4313  
4314 my ($self, $tooltips, $check) = @_;
4315  
4316 # Check for improper arguments
4317 if (defined $check) {
4318  
4319 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_tooltips', @_);
4320 }
4321  
4322 if (! defined $tooltips || $tooltips eq '') {
4323 $self->entry->set_tooltip_text(undef);
4324 } else {
4325 $self->entry->set_tooltip_markup($tooltips);
4326 }
4327  
4328 return 1;
4329 }
4330  
4331 sub set_width_chars {
4332  
4333 my ($self, $num, $check) = @_;
4334  
4335 # Check for improper arguments
4336 if (defined $check) {
4337  
4338 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_width_chars', @_);
4339 }
4340  
4341 $self->entry->set_width_chars($self->testInt($num, 0, 0));
4342  
4343 return 1;
4344 }
4345  
4346 # (Get equivalents)
4347  
4348 sub get_max_chars {
4349  
4350 # Returns string
4351 my ($self, $check) = @_;
4352  
4353 # Check for improper arguments
4354 if (defined $check) {
4355  
4356 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_max_chars', @_);
4357 }
4358  
4359 return $self->entry->get_max_length();
4360 }
4361  
4362 sub get_normal {
4363  
4364 # Returns TRUE for 'normal', FALSE for 'insensitive' or any other value
4365  
4366 my ($self, $check) = @_;
4367  
4368 # Check for improper arguments
4369 if (defined $check) {
4370  
4371 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_normal', @_);
4372 }
4373  
4374 if ($self->entry->get_state eq 'normal') {
4375 return TRUE;
4376 } else {
4377 return FALSE;
4378 }
4379  
4380 return 1;
4381 }
4382  
4383 sub get_text {
4384  
4385 # Returns string
4386 my ($self, $check) = @_;
4387  
4388 # Check for improper arguments
4389 if (defined $check) {
4390  
4391 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_text', @_);
4392 }
4393  
4394 return $self->entry->get_text();
4395 }
4396  
4397 sub get_tooltips {
4398  
4399 # Returns string
4400  
4401 my ($self, $check) = @_;
4402  
4403 # Check for improper arguments
4404 if (defined $check) {
4405  
4406 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_tooltips', @_);
4407 }
4408  
4409 return $self->entry->get_tooltip_text();
4410 }
4411  
4412 sub get_width_chars {
4413  
4414 # Returns string
4415 my ($self, $check) = @_;
4416  
4417 # Check for improper arguments
4418 if (defined $check) {
4419  
4420 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_width_chars', @_);
4421 }
4422  
4423 return $self->entry->get_width_chars();
4424 }
4425  
4426 ##################
4427 # Accessors - get
4428  
4429 sub entry
4430 { $_[0]->{entry} }
4431  
4432 sub checkFlag
4433 { $_[0]->{checkFlag} }
4434 sub checkYes
4435 { $_[0]->{checkYes} }
4436 sub checkNo
4437 { $_[0]->{checkNo} }
4438 sub checkFunc
4439 { $_[0]->{checkFunc} }
4440 sub checkType
4441 { $_[0]->{checkType} }
4442 sub checkMin
4443 { $_[0]->{checkMin} }
4444 sub checkMax
4445 { $_[0]->{checkMax} }
4446 }
4447  
4448 { package Games::Axmud::Table::ComboBox;
4449  
4450 use strict;
4451 use warnings;
4452 use diagnostics;
4453  
4454 use Glib qw(TRUE FALSE);
4455  
4456 our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud);
4457  
4458 ##################
4459 # Constructors
4460  
4461 sub new {
4462  
4463 # Called by GA::Strip::Table->addTableObj
4464 # Creates the GA::Table::ComboBox, which contains a simple Gtk3::ComboBox
4465 #
4466 # Expected arguments
4467 # $number - The table object's number within the parent strip object (matches
4468 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object
4469 # created to access its default IVs)
4470 # $name - A name for the table object. Can be any string or, if no name was
4471 # specified in the call to the calling function, $name is the same as
4472 # $number. (No part of the code checks that table object names are unique;
4473 # if two or more table objects share the same ->name, usually the one with
4474 # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
4475 # chars)
4476 # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table
4477 # objects
4478 # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
4479 # parent strip object's Gtk3::Grid for use exclusively by this table
4480 # object. 'temp' for temporary table objects
4481 #
4482 # Optional arguments
4483 # %initHash - A hash containing arbitrary data to use as the table object's
4484 # initialisation settings. The table object should use default
4485 # initialisation settings unless it can succesfully interpret one or more
4486 # of the key-value pairs in the hash, if there are any
4487 # - This type of table object recognises these initialisation settings:
4488 #
4489 # 'func' - Reference to a function to call when an item in the combobox
4490 # is selected. If not specified or 'undef', it's up to the calling
4491 # code to create its own ->signal_connect. To obtain a reference to an
4492 # OOP method, you can use the generic object function
4493 # Games::Axmud->getMethodRef()
4494 # 'id' - A value passed to the function which identifies the button. If
4495 # specified, can be any value except 'undef'. It's up to the
4496 # calling code to keep track of the widgets it has created and their
4497 # corresponding 'id' values
4498 # 'list_ref' - Reference to a list used to fill the combobox. If 'undef'
4499 # or if the referenced list is empty, the combobox is empty
4500 # 'title' - A string to use as the combobox's title, e.g. 'Choose your
4501 # favourite cat'. If 'undef', a title isn't used
4502 # 'tooltips' - The text to display as tooltips for the button. Can be
4503 # plain text or pango markup text. If not specified, 'undef' or an
4504 # empty string, no tooltips are displayed
4505 # 'normal_flag' - If TRUE (or not specified), the button's state is
4506 # 'normal'. If FALSE, the button's state is 'insensitive' (nothing can
4507 # interact with it)
4508 # 'expand_flag' - Deprecated since v1.2.170; ignored if specified
4509 # 'expand_horizontal_flag' - If TRUE or unspecified, the table object
4510 # expands horizontally; if FALSE, it doesn't
4511 # 'expand_vertical_flag' - If TRUE or unspecified, the table object
4512 # expands vertically; if FALSE, it doesn't
4513 #
4514 # Return values
4515 # 'undef' on improper arguments
4516 # Blessed reference to the newly-created object on success
4517  
4518 my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
4519  
4520 # Local variables
4521 my (
4522 $winObj,
4523 %modHash,
4524 );
4525  
4526 # Check for improper arguments
4527 if (
4528 ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
4529 || ! defined $zoneObj
4530 ) {
4531 return $axmud::CLIENT->writeImproper($class . '->new', @_);
4532 }
4533  
4534 # Deal with temporary table objects
4535 if ($stripObj eq 'temp') {
4536 $winObj = 'temp';
4537 } else {
4538 $winObj = $stripObj->winObj;
4539 }
4540  
4541 # Default initialisation settings
4542 %modHash = (
4543 'func' => undef,
4544 'id' => '',
4545 'list_ref' => undef,
4546 'title' => undef,
4547 'tooltips' => undef,
4548 'normal_flag' => TRUE,
4549 'expand_flag' => TRUE, # Deprecated since v1.2.170
4550 'expand_horizontal_flag' => TRUE,
4551 'expand_vertical_flag' => TRUE,
4552 );
4553  
4554 # Interpret the initialisation settings in %initHash, if any
4555 foreach my $key (keys %modHash) {
4556  
4557 if (exists $initHash{$key}) {
4558  
4559 if ($key =~ m/flag$/) {
4560  
4561 if ($initHash{$key}) {
4562 $modHash{$key} = TRUE;
4563 } else {
4564 $modHash{$key} = FALSE;
4565 }
4566  
4567 } elsif ($key eq 'id' && ! defined $initHash{$key}) {
4568  
4569 $modHash{$key} = ''; # 'id' value must not be 'undef'
4570  
4571 } else {
4572  
4573 $modHash{$key} = $initHash{$key};
4574 }
4575 }
4576 }
4577  
4578 # Setup
4579 my $self = {
4580 _objName => 'table_obj_' . $number,
4581 _objClass => $class,
4582 _parentFile => undef, # No parent file object
4583 _parentWorld => undef, # No parent file object
4584 _privFlag => TRUE, # All IVs are private
4585  
4586 # Standard table object IVs
4587 # -------------------------
4588  
4589 # The table object's number within the parent strip object (matches
4590 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to
4591 # access its default IVs)
4592 number => $number,
4593 # A name for the table object. Can be any string or, if no name was specified in the
4594 # call to the calling function, $name is the same as $number. (No part of the code
4595 # checks that table object names are unique; if two or more table objects share the
4596 # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary
4597 # table objects. Max 16 chars)
4598 name => $name,
4599 # The type of table object (custom table objects should use a ->type starting with
4600 # 'custom_' to avoid clashing with future built-in table objects)
4601 type => 'combo_box',
4602 # The parent strip object (GA::Strip::Table)
4603 stripObj => $stripObj,
4604 # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for
4605 # temporary table objects
4606 winObj => $winObj,
4607 # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip
4608 # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary
4609 # table objects
4610 zoneObj => $zoneObj,
4611  
4612 # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is
4613 # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as
4614 # when a connection to a world terminates)
4615 allowRemoveFlag => TRUE,
4616 # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is
4617 # created. Set to FALSE if it can't be resized
4618 allowResizeFlag => TRUE,
4619 # Initialisation settings stored as a hash (see the comments above)
4620 initHash => \%modHash,
4621 # Reference to a function to call when some widget is used. This IV is set only when
4622 # required by this type of table object. It can be set by a call to
4623 # $self->set_func() or by some setting in $self->initHash, which is applied in the
4624 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
4625 # generic object function Games::Axmud->getMethodRef()
4626 funcRef => undef,
4627 # A value passed to ->funcRef when it is called which identifies this table object and
4628 # its widget(s). Can be any value except 'undef'. It can be set by a call to
4629 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
4630 # to $self->objEnable()
4631 funcID => '',
4632  
4633 # The container widget(s) for this table object
4634 packingBox => undef, # Gtk3::Grid
4635 packingBox2 => undef, # Gtk3::Grid
4636  
4637 # Other IVs
4638 # ---------
4639  
4640 # Widgets
4641 comboBox => undef, # Gtk3::ComboBox
4642  
4643 # Item in the combobox used as a title ('undef' if no title specified). Set by
4644 # $self->objEnable from $self->initHash
4645 title => undef,
4646 };
4647  
4648 # Bless the object into existence
4649 bless $self, $class;
4650  
4651 return $self;
4652 }
4653  
4654 ##################
4655 # Methods
4656  
4657 # Standard table object functions
4658  
4659 sub objEnable {
4660  
4661 # Called by GA::Strip::Table->addTableObj
4662 # Sets up the table object's widgets
4663 #
4664 # Expected arguments
4665 # (none besides $self)
4666 #
4667 # Return values
4668 # 'undef' on improper arguments
4669 # 1 on success
4670  
4671 my ($self, $check) = @_;
4672  
4673 # Local variables
4674 my (
4675 $funcRef, $funcID, $listRef, $title, $tooltips, $normalFlag, $hExpandFlag, $vExpandFlag,
4676 );
4677  
4678 # Check for improper arguments
4679 if (defined $check) {
4680  
4681 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
4682 }
4683  
4684 # Interpret $self->initHash, replacing any invalid values
4685 $funcRef = $self->ivShow('initHash', 'func');
4686 $funcID = $self->ivShow('initHash', 'id');
4687 $listRef = $self->ivShow('initHash', 'list_ref');
4688 $title = $self->ivShow('initHash', 'title');
4689 $tooltips = $self->ivShow('initHash', 'tooltips');
4690 $normalFlag = $self->testFlag($self->ivShow('initHash', 'normal_flag'));
4691 $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag'));
4692 $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag'));
4693  
4694 # Create packing box(es)
4695 my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::Grid->new());
4696  
4697 # Create the Gtk3::ComboBox
4698 my $comboBox = Gtk3::ComboBoxText->new();
4699 $packingBox2->attach($comboBox, 0, 0, 1, 1);
4700 if (defined $title) {
4701  
4702 $comboBox->append_text($title);
4703 }
4704  
4705 foreach my $item (@$listRef) {
4706  
4707 $comboBox->append_text($item);
4708 }
4709  
4710 # The first item in the combobox is the first one selected
4711 $comboBox->set_active(0);
4712  
4713 if (defined $tooltips && $tooltips ne '') {
4714  
4715 $comboBox->set_tooltip_markup($tooltips);
4716 }
4717  
4718 if (! $normalFlag) {
4719  
4720 $comboBox->set_state('insensitive');
4721 }
4722  
4723 # Set expansion
4724 $comboBox->set_hexpand($hExpandFlag);
4725 $comboBox->set_vexpand($vExpandFlag);
4726  
4727 # Update IVs
4728 $self->ivPoke('funcRef', $funcRef);
4729 $self->ivPoke('funcID', $funcID);
4730 $self->ivPoke('packingBox', $packingBox);
4731 $self->ivPoke('packingBox2', $packingBox2);
4732 $self->ivPoke('comboBox', $comboBox);
4733 $self->ivPoke('title', $title);
4734  
4735 # Set up ->signal_connects
4736 $self->setChangedEvent();
4737  
4738 return 1;
4739 }
4740  
4741 # sub objDestroy { # Inherited from GA::Generic::Table
4742  
4743 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table
4744  
4745 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table
4746  
4747 # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table
4748  
4749 # ->signal_connects
4750  
4751 sub setChangedEvent {
4752  
4753 # Called by $self->objEnable
4754 #
4755 # Expected arguments
4756 # (none besides $self)
4757 #
4758 # Return values
4759 # 'undef' on improper arguments
4760 # 1 otherwise
4761  
4762 my ($self, $check) = @_;
4763  
4764 # Check for improper arguments
4765 if (defined $check) {
4766  
4767 return $axmud::CLIENT->writeImproper($self->_objClass . '->setChangedEvent', @_);
4768 }
4769  
4770 $self->comboBox->signal_connect('changed' => sub {
4771  
4772 my ($currentFuncRef, $value);
4773  
4774 $currentFuncRef = $self->funcRef;
4775 $value = $self->comboBox->get_active_text();
4776  
4777 # (If the user selects the title, ignore it)
4778 if ($currentFuncRef && (! defined $self->title || $value ne $self->title)) {
4779  
4780 &$currentFuncRef($self, $self->comboBox, $self->funcID, $value);
4781 }
4782 });
4783  
4784 return 1;
4785 }
4786  
4787 # Other functions
4788  
4789 sub resetCombo {
4790  
4791 # Can be called by anything
4792 # Resets the appearance of the combobox
4793  
4794 # Expected arguments
4795 # (none besides $self)
4796 #
4797 # Return values
4798 # 'undef' on improper arguments
4799 # 1 otherwise
4800  
4801 my ($self, $check) = @_;
4802  
4803 # Check for improper arguments
4804 if (defined $check) {
4805  
4806 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetCombo', @_);
4807 }
4808  
4809 $self->comboBox->set_active(0);
4810 $self->comboBox->popdown();
4811  
4812 return 1;
4813 }
4814  
4815 ##################
4816 # Accessors - set
4817  
4818 # sub set_func {} # Inherited from GA::Generic::Table
4819  
4820 # sub set_id {} # Inherited from GA::Generic::Table
4821  
4822 sub set_list {
4823  
4824 my ($self, $title, @list) = @_;
4825  
4826 # Local variables
4827 my ($funcRef, $model);
4828  
4829 # (No improper arguments to check)
4830  
4831 # Temporarily resetting $self->funcRef prevents the ->signal_connect from calling that
4832 # function while we're resetting the combobox
4833 $funcRef = $self->funcRef;
4834 $self->ivUndef('funcRef');
4835  
4836 # Empty the combobox...
4837 $model = $self->comboBox->get_model();
4838 $model->clear();
4839  
4840 # ...and refill it (if specified)
4841 if (defined $title) {
4842  
4843 $self->comboBox->append_text($title);
4844 $self->ivPoke('title', $title);
4845  
4846 } else {
4847  
4848 $self->ivUndef($title);
4849 }
4850  
4851 foreach my $item (@list) {
4852  
4853 $self->comboBox->append_text($item);
4854 }
4855  
4856 # The first item in the combobox is the first one selected
4857 $self->comboBox->set_active(0);
4858 $self->comboBox->popdown();
4859  
4860 # Restore the combobox to normal operations
4861 $self->ivPoke('funcRef', $funcRef);
4862  
4863 return 1;
4864 }
4865  
4866 sub set_normal {
4867  
4868 my ($self, $flag, $check) = @_;
4869  
4870 # Check for improper arguments
4871 if (defined $check) {
4872  
4873 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_normal', @_);
4874 }
4875  
4876 if (! $flag) {
4877 $self->comboBox->set_state('insensitive');
4878 } else {
4879 $self->comboBox->set_state('normal');
4880 }
4881  
4882 return 1;
4883 }
4884  
4885 sub set_tooltips {
4886  
4887 my ($self, $tooltips, $check) = @_;
4888  
4889 # Check for improper arguments
4890 if (defined $check) {
4891  
4892 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_tooltips', @_);
4893 }
4894  
4895 if (! defined $tooltips || $tooltips eq '') {
4896 $self->comboBox->set_tooltip_text(undef);
4897 } else {
4898 $self->comboBox->set_tooltip_markup($tooltips);
4899 }
4900  
4901 return 1;
4902 }
4903  
4904 # (Get equivalents)
4905  
4906 sub get_normal {
4907  
4908 # Returns TRUE for 'normal', FALSE for 'insensitive' or any other value
4909  
4910 my ($self, $check) = @_;
4911  
4912 # Check for improper arguments
4913 if (defined $check) {
4914  
4915 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_normal', @_);
4916 }
4917  
4918 if ($self->comboBox->get_state eq 'normal') {
4919 return TRUE;
4920 } else {
4921 return FALSE;
4922 }
4923  
4924 return 1;
4925 }
4926  
4927 sub get_text {
4928  
4929 # Returns 'undef' if the combobox's title is selected
4930  
4931 my ($self, $check) = @_;
4932  
4933 # Local variables
4934 my $text;
4935  
4936 # Check for improper arguments
4937 if (defined $check) {
4938  
4939 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_text', @_);
4940 }
4941  
4942 $text = $self->comboBox->get_active_text();
4943  
4944 if (defined $self->title && $self->title eq $text) {
4945 return undef;
4946 } else {
4947 return $text;
4948 }
4949 }
4950  
4951 sub get_tooltips {
4952  
4953 # Returns string
4954  
4955 my ($self, $check) = @_;
4956  
4957 # Check for improper arguments
4958 if (defined $check) {
4959  
4960 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_tooltips', @_);
4961 }
4962  
4963 return $self->comboBox->get_tooltip_text();
4964 }
4965  
4966 ##################
4967 # Accessors - get
4968  
4969 sub comboBox
4970 { $_[0]->{comboBox} }
4971 sub title
4972 { $_[0]->{title} }
4973 }
4974  
4975 { package Games::Axmud::Table::SimpleList;
4976  
4977 use strict;
4978 use warnings;
4979 use diagnostics;
4980  
4981 use Glib qw(TRUE FALSE);
4982  
4983 our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud);
4984  
4985 ##################
4986 # Constructors
4987  
4988 sub new {
4989  
4990 # Called by GA::Strip::Table->addTableObj
4991 # Creates the GA::Table::SimpleList, which contains a simple GA::Obj::SimpleList
4992 #
4993 # Expected arguments
4994 # $number - The table object's number within the parent strip object (matches
4995 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object
4996 # created to access its default IVs)
4997 # $name - A name for the table object. Can be any string or, if no name was
4998 # specified in the call to the calling function, $name is the same as
4999 # $number. (No part of the code checks that table object names are unique;
5000 # if two or more table objects share the same ->name, usually the one with
5001 # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
5002 # chars)
5003 # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table
5004 # objects
5005 # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
5006 # parent strip object's Gtk3::Grid for use exclusively by this table
5007 # object. 'temp' for temporary table objects
5008 #
5009 # Optional arguments
5010 # %initHash - A hash containing arbitrary data to use as the table object's
5011 # initialisation settings. The table object should use default
5012 # initialisation settings unless it can succesfully interpret one or more
5013 # of the key-value pairs in the hash, if there are any
5014 # - This type of table object recognises these initialisation settings:
5015 #
5016 # 'frame_title' - If specified, the table object is drawn inside a frame
5017 # with the specified title. If 'undef', an empty string or not
5018 # specified, the table object does not use a frame and title
5019 # 'func' - Reference to a function to call when an item in the combobox
5020 # is selected. If not specified or 'undef', it's up to the calling
5021 # code to create its own ->signal_connect. To obtain a reference to an
5022 # OOP method, you can use the generic object function
5023 # Games::Axmud->getMethodRef()
5024 # 'id' - A value passed to the function which identifies the button. If
5025 # specified, can be any value except 'undef'. It's up to the
5026 # calling code to keep track of the widgets it has created and their
5027 # corresponding 'id' values
5028 # 'column_ref' - Reference to a list of column headings and types, in the
5029 # form ('heading', 'column_type', 'heading', 'column_type'...), where
5030 # 'column_type' is one of the column types recognised by
5031 # GA::Obj::SimpleList, i.e. 'text', 'markup', 'int', 'double',
5032 # 'bool', 'scalar' or 'pixbuf'. If 'undef' or an empty list, a single
5033 # column of type 'text' is created. If the list contains an odd
5034 # number of items, the final one is discarded
5035 # 'data_ref' - Reference to a list used to populate the
5036 # GA::Obj::SimpleList. If there are 2 columns, a list in the form
5037 # (a, b, a, b...) is expected. If there are 3 columns, a list in the
5038 # form (a, b, c, a, b, c) is expected. If 'undef' or an empty list,
5039 # nothing is added to the simple list
5040 # 'expand_horizontal_flag' - If TRUE or not specified, the table object
5041 # expands horizontally; if FALSE, it doesn't
5042 # 'expand_vertical_flag' - If TRUE or not specified, the table object
5043 # expands vertically; if FALSE, it doesn't
5044 #
5045 # Return values
5046 # 'undef' on improper arguments
5047 # Blessed reference to the newly-created object on success
5048  
5049 my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
5050  
5051 # Local variables
5052 my (
5053 $winObj,
5054 %modHash,
5055 );
5056  
5057 # Check for improper arguments
5058 if (
5059 ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
5060 || ! defined $zoneObj
5061 ) {
5062 return $axmud::CLIENT->writeImproper($class . '->new', @_);
5063 }
5064  
5065 # Deal with temporary table objects
5066 if ($stripObj eq 'temp') {
5067 $winObj = 'temp';
5068 } else {
5069 $winObj = $stripObj->winObj;
5070 }
5071  
5072 # Default initialisation settings
5073 %modHash = (
5074 'frame_title' => undef,
5075 'func' => undef,
5076 'id' => '',
5077 'column_ref' => undef,
5078 'data_ref' => undef,
5079 'expand_horizontal_flag' => TRUE,
5080 'expand_vertical_flag' => TRUE,
5081 );
5082  
5083 # Interpret the initialisation settings in %initHash, if any
5084 foreach my $key (keys %modHash) {
5085  
5086 if (exists $initHash{$key}) {
5087  
5088 if ($key =~ m/flag$/) {
5089  
5090 if ($initHash{$key}) {
5091 $modHash{$key} = TRUE;
5092 } else {
5093 $modHash{$key} = FALSE;
5094 }
5095  
5096 } elsif ($key eq 'id' && ! defined $initHash{$key}) {
5097  
5098 $modHash{$key} = ''; # 'id' value must not be 'undef'
5099  
5100 } else {
5101  
5102 $modHash{$key} = $initHash{$key};
5103 }
5104 }
5105 }
5106  
5107 # Setup
5108 my $self = {
5109 _objName => 'table_obj_' . $number,
5110 _objClass => $class,
5111 _parentFile => undef, # No parent file object
5112 _parentWorld => undef, # No parent file object
5113 _privFlag => TRUE, # All IVs are private
5114  
5115 # Standard table object IVs
5116 # -------------------------
5117  
5118 # The table object's number within the parent strip object (matches
5119 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to
5120 # access its default IVs)
5121 number => $number,
5122 # A name for the table object. Can be any string or, if no name was specified in the
5123 # call to the calling function, $name is the same as $number. (No part of the code
5124 # checks that table object names are unique; if two or more table objects share the
5125 # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary
5126 # table objects. Max 16 chars)
5127 name => $name,
5128 # The type of table object (custom table objects should use a ->type starting with
5129 # 'custom_' to avoid clashing with future built-in table objects)
5130 type => 'simple_list',
5131 # The parent strip object (GA::Strip::Table)
5132 stripObj => $stripObj,
5133 # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for
5134 # temporary table objects
5135 winObj => $winObj,
5136 # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip
5137 # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary
5138 # table objects
5139 zoneObj => $zoneObj,
5140  
5141 # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is
5142 # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as
5143 # when a connection to a world terminates)
5144 allowRemoveFlag => TRUE,
5145 # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is
5146 # created. Set to FALSE if it can't be resized
5147 allowResizeFlag => TRUE,
5148 # Initialisation settings stored as a hash (see the comments above)
5149 initHash => \%modHash,
5150 # Reference to a function to call when some widget is used. This IV is set only when
5151 # required by this type of table object. It can be set by a call to
5152 # $self->set_func() or by some setting in $self->initHash, which is applied in the
5153 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
5154 # generic object function Games::Axmud->getMethodRef()
5155 funcRef => undef,
5156 # A value passed to ->funcRef when it is called which identifies this table object and
5157 # its widget(s). Can be any value except 'undef'. It can be set by a call to
5158 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
5159 # to $self->objEnable()
5160 funcID => '',
5161  
5162 # The container widget(s) for this table object
5163 packingBox => undef, # Gtk3::ScrolledWindow or Gtk3::Frame
5164 packingBox2 => undef, # Gtk3::ScrolledWindow
5165  
5166 # Other IVs
5167 # ---------
5168  
5169 # Widgets
5170 slWidget => undef, # GA::Obj::SimpleList
5171  
5172 # The number of columns in the simple list (minimum 1)
5173 numColumns => undef,
5174 };
5175  
5176 # Bless the object into existence
5177 bless $self, $class;
5178  
5179 return $self;
5180 }
5181  
5182 ##################
5183 # Methods
5184  
5185 # Standard table object functions
5186  
5187 sub objEnable {
5188  
5189 # Called by GA::Strip::Table->addTableObj
5190 # Sets up the table object's widgets
5191 #
5192 # Expected arguments
5193 # (none besides $self)
5194 #
5195 # Return values
5196 # 'undef' on improper arguments
5197 # 1 on success
5198  
5199 my ($self, $check) = @_;
5200  
5201 # Local variables
5202 my (
5203 $funcRef, $funcID, $columnListRef, $dataListRef, $hExpandFlag, $vExpandFlag,
5204 $numColumns, $count,
5205 @columnList, @dataList,
5206 );
5207  
5208 # Check for improper arguments
5209 if (defined $check) {
5210  
5211 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
5212 }
5213  
5214 # Interpret $self->initHash, replacing any invalid values
5215 $funcRef = $self->ivShow('initHash', 'func');
5216 $funcID = $self->ivShow('initHash', 'id');
5217 $columnListRef = $self->ivShow('initHash', 'column_ref');
5218 $dataListRef = $self->ivShow('initHash', 'data_ref');
5219 $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag'));
5220 $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag'));
5221  
5222 if (defined $columnListRef) {
5223  
5224 @columnList = @$columnListRef;
5225 }
5226  
5227 if (! (scalar @columnList) % 2) {
5228  
5229 # List should be in the form ('heading', 'column_type', 'heading', 'column_type'...) but
5230 # a 'column_type' is missing; discard the unpaired 'heading'
5231 pop @columnList;
5232 }
5233  
5234 if (! @columnList) {
5235  
5236 # List contains no 'heading' or 'column_type', use default ones
5237 push (@columnList, 'Items', 'text');
5238 }
5239  
5240 if (defined $dataListRef) {
5241  
5242 @dataList = @$dataListRef;
5243 }
5244  
5245 # Create packing box(es)
5246 my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::ScrolledWindow->new());
5247 $packingBox2->set_policy('automatic', 'automatic');
5248  
5249 # Create the GA::Obj::SimpleList
5250 my $slWidget = Games::Axmud::Obj::SimpleList->new(@columnList);
5251 $packingBox2->add_with_viewport($slWidget);
5252  
5253 # Make all columns of type 'bool' (which are composed of checkbuttons) non-activatable, so
5254 # that the user can't click them on and off
5255 $numColumns = scalar (@columnList / 2);
5256 $count = -1;
5257 do {
5258  
5259 my ($heading, $type);
5260  
5261 $heading = shift @columnList;
5262 $type = shift @columnList;
5263  
5264 $count++;
5265  
5266 if ($type eq 'bool') {
5267  
5268 my ($cellRenderer) = $slWidget->get_column($count)->get_cells();
5269 $cellRenderer->set(activatable => FALSE);
5270 }
5271  
5272 } until (! @columnList);
5273  
5274 # Fill the simple list
5275 @{$slWidget->{data}} = @dataList;
5276  
5277 # Set expansion
5278 $slWidget->set_hexpand($hExpandFlag);
5279 $slWidget->set_vexpand($vExpandFlag);
5280  
5281 # Update IVs
5282 $self->ivPoke('funcRef', $funcRef);
5283 $self->ivPoke('funcID', $funcID);
5284 $self->ivPoke('packingBox', $packingBox);
5285 $self->ivPoke('packingBox2', $packingBox2);
5286 $self->ivPoke('slWidget', $slWidget);
5287 $self->ivPoke('numColumns', $numColumns);
5288  
5289 return 1;
5290 }
5291  
5292 # sub objDestroy { # Inherited from GA::Generic::Table
5293  
5294 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table
5295  
5296 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table
5297  
5298 # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table
5299  
5300 # ->signal_connects
5301  
5302 # Other functions
5303  
5304 ##################
5305 # Accessors - set
5306  
5307 sub set_cell {
5308  
5309 my ($self, $x, $y, $item, $check) = @_;
5310  
5311 # Local variables
5312 my $slWidget;
5313  
5314 # Check for improper arguments
5315 if (! defined $x || ! defined $y || defined $check) {
5316  
5317 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_cell', @_);
5318 }
5319  
5320 $slWidget = $self->slWidget;
5321 ${$slWidget->{data}}[$x][$y] = $item;
5322  
5323 return 1;
5324 }
5325  
5326 # sub set_func {} # Inherited from GA::Generic::Table
5327  
5328 # sub set_id {} # Inherited from GA::Generic::Table
5329  
5330 sub set_list {
5331  
5332 my ($self, @list) = @_;
5333  
5334 # Local variables
5335 my $slWidget;
5336  
5337 # (No improper arguments to check)
5338  
5339 $slWidget = $self->slWidget;
5340 @{$slWidget->{data}} = @list;
5341  
5342 return 1;
5343 }
5344  
5345 sub set_row {
5346  
5347 my ($self, $y, @list) = @_;
5348  
5349 # Local variables
5350 my $slWidget;
5351  
5352 # Check for improper arguments
5353 if (! defined $y) {
5354  
5355 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_item', @_);
5356 }
5357  
5358 $slWidget = $self->slWidget;
5359 ${$slWidget->{data}}[$y] = \@list;
5360  
5361 return 1;
5362 }
5363  
5364 sub set_select {
5365  
5366 my ($self, $y, $check) = @_;
5367  
5368 # Check for improper arguments
5369 if (defined $check) {
5370  
5371 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_select', @_);
5372 }
5373  
5374 if (defined $y) {
5375 $self->slWidget->select($y);
5376 } else {
5377 $self->slWidget->unselect_all();
5378 }
5379  
5380 return 1;
5381 }
5382  
5383 # (Get equivalents)
5384  
5385 sub get_cell {
5386  
5387 my ($self, $x, $y, $check) = @_;
5388  
5389 # Local variables
5390 my $slWidget;
5391  
5392 # Check for improper arguments
5393 if (! defined $x || ! defined $y || defined $check) {
5394  
5395 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_cell', @_);
5396 }
5397  
5398 $slWidget = $self->slWidget;
5399 return ${$slWidget->{data}}[$x][$y];
5400 }
5401  
5402 sub get_row {
5403  
5404 my ($self, $y, $check) = @_;
5405  
5406 # Local variables
5407 my $slWidget;
5408  
5409 # Check for improper arguments
5410 if (! defined $y || defined $check) {
5411  
5412 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_item', @_);
5413 }
5414  
5415 $slWidget = $self->slWidget;
5416 return ${$slWidget->{data}}[$y];
5417 }
5418  
5419 sub get_select {
5420  
5421 my ($self, $check) = @_;
5422  
5423 # Local variables
5424 my $rowNum;
5425  
5426 # Check for improper arguments
5427 if (defined $check) {
5428  
5429 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_select', @_);
5430 }
5431  
5432 ($rowNum) = $self->slWidget->get_selected_indices();
5433  
5434 return $rowNum;
5435 }
5436  
5437 ##################
5438 # Accessors - get
5439  
5440 sub slWidget
5441 { $_[0]->{slWidget} }
5442  
5443 sub numColumns
5444 { $_[0]->{numColumns} }
5445 }
5446  
5447 { package Games::Axmud::Table::TextView;
5448  
5449 use strict;
5450 use warnings;
5451 use diagnostics;
5452  
5453 use Glib qw(TRUE FALSE);
5454  
5455 our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud);
5456  
5457 ##################
5458 # Constructors
5459  
5460 sub new {
5461  
5462 # Called by GA::Strip::Table->addTableObj
5463 # Creates the GA::Table::TextView, which contains a simple Gtk3::TextView
5464 # If all you want to do is to display some monochrome text in a scrolling textview (and
5465 # optionally allow the user to edit it), use this table object
5466 # For anything more ambitious, use a GA::Table::Pane object
5467 #
5468 # Expected arguments
5469 # $number - The table object's number within the parent strip object (matches
5470 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object
5471 # created to access its default IVs)
5472 # $name - A name for the table object. Can be any string or, if no name was
5473 # specified in the call to the calling function, $name is the same as
5474 # $number. (No part of the code checks that table object names are unique;
5475 # if two or more table objects share the same ->name, usually the one with
5476 # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
5477 # chars)
5478 # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table
5479 # objects
5480 # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
5481 # parent strip object's Gtk3::Grid for use exclusively by this table
5482 # object. 'temp' for temporary table objects
5483 #
5484 # Optional arguments
5485 # %initHash - A hash containing arbitrary data to use as the table object's
5486 # initialisation settings. The table object should use default
5487 # initialisation settings unless it can succesfully interpret one or more
5488 # of the key-value pairs in the hash, if there are any
5489 # - This type of table object recognises these initialisation settings:
5490 #
5491 # 'frame_title' - If specified, the table object is drawn inside a frame
5492 # with the specified title. If 'undef', an empty string or not
5493 # specified, the table object does not use a frame and title
5494 # 'func' - Reference to a function to call when an the contents of the
5495 # textview is edited. If not specified or 'undef', it's up to the
5496 # calling code to create its own ->signal_connect. To obtain a
5497 # reference to an OOP method, you can use the generic object function
5498 # Games::Axmud->getMethodRef()
5499 # 'id' - A value passed to the function which identifies the button. If
5500 # specified, can be any value except 'undef'. It's up to the
5501 # calling code to keep track of the widgets it has created and their
5502 # corresponding 'id' values
5503 # 'text' - String containing text and newline characters. If 'undef' or
5504 # not specified, the textview is initially empty
5505 # 'edit_flag' - If TRUE, the contents of the textview can be edited. If
5506 # FALSE (or not specified), the contents can't be edited
5507 # 'system_flag' - If TRUE, the system's preferred colours/fonts are
5508 # used. If FALSE (or not specified), an Axmud colour scheme is used
5509 # 'colour_scheme' - The name of the colour scheme to use (matches a key
5510 # in GA::Client->colourSchemeHash). If not specified or 'undef', the
5511 # parent window's colour scheme is used
5512 # 'spacing' - The size (in pixels) of the gap between the textview itself
5513 # and its containing Gtk3::Frame. A value in the range 0-100. If
5514 # 'undef', not specified or an invalid value, a value of 0 is used
5515 # 'expand_horizontal_flag' - If TRUE or not specified, the table object
5516 # expands horizontally; if FALSE, it doesn't
5517 # 'expand_vertical_flag' - If TRUE or not specified, the table object
5518 # expands vertically; if FALSE, it doesn't
5519 #
5520 # Return values
5521 # 'undef' on improper arguments
5522 # Blessed reference to the newly-created object on success
5523  
5524 my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
5525  
5526 # Local variables
5527 my (
5528 $winObj,
5529 %modHash,
5530 );
5531  
5532 # Check for improper arguments
5533 if (
5534 ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
5535 || ! defined $zoneObj
5536 ) {
5537 return $axmud::CLIENT->writeImproper($class . '->new', @_);
5538 }
5539  
5540 # Deal with temporary table objects
5541 if ($stripObj eq 'temp') {
5542 $winObj = 'temp';
5543 } else {
5544 $winObj = $stripObj->winObj;
5545 }
5546  
5547 # Default initialisation settings
5548 %modHash = (
5549 'frame_title' => undef,
5550 'func' => undef,
5551 'id' => '',
5552 'text' => '',
5553 'edit_flag' => FALSE,
5554 'system_flag' => FALSE,
5555 'colour_scheme' => undef,
5556 'spacing' => 0,
5557 'expand_horizontal_flag' => TRUE,
5558 'expand_vertical_flag' => TRUE,
5559 );
5560  
5561 # Interpret the initialisation settings in %initHash, if any
5562 foreach my $key (keys %modHash) {
5563  
5564 if (exists $initHash{$key}) {
5565  
5566 if ($key =~ m/flag$/) {
5567  
5568 if ($initHash{$key}) {
5569 $modHash{$key} = TRUE;
5570 } else {
5571 $modHash{$key} = FALSE;
5572 }
5573  
5574 } elsif ($key eq 'id' && ! defined $initHash{$key}) {
5575  
5576 $modHash{$key} = ''; # 'id' value must not be 'undef'
5577  
5578 } else {
5579  
5580 $modHash{$key} = $initHash{$key};
5581 }
5582 }
5583 }
5584  
5585 # Setup
5586 my $self = {
5587 _objName => 'table_obj_' . $number,
5588 _objClass => $class,
5589 _parentFile => undef, # No parent file object
5590 _parentWorld => undef, # No parent file object
5591 _privFlag => TRUE, # All IVs are private
5592  
5593 # Standard table object IVs
5594 # -------------------------
5595  
5596 # The table object's number within the parent strip object (matches
5597 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to
5598 # access its default IVs)
5599 number => $number,
5600 # A name for the table object. Can be any string or, if no name was specified in the
5601 # call to the calling function, $name is the same as $number. (No part of the code
5602 # checks that table object names are unique; if two or more table objects share the
5603 # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary
5604 # table objects. Max 16 chars)
5605 name => $name,
5606 # The type of table object (custom table objects should use a ->type starting with
5607 # 'custom_' to avoid clashing with future built-in table objects)
5608 type => 'text_view',
5609 # The parent strip object (GA::Strip::Table)
5610 stripObj => $stripObj,
5611 # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for
5612 # temporary table objects
5613 winObj => $winObj,
5614 # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip
5615 # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary
5616 # table objects
5617 zoneObj => $zoneObj,
5618  
5619 # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is
5620 # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as
5621 # when a connection to a world terminates)
5622 allowRemoveFlag => TRUE,
5623 # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is
5624 # created. Set to FALSE if it can't be resized
5625 allowResizeFlag => TRUE,
5626 # Initialisation settings stored as a hash (see the comments above)
5627 initHash => \%modHash,
5628 # Reference to a function to call when some widget is used. This IV is set only when
5629 # required by this type of table object. It can be set by a call to
5630 # $self->set_func() or by some setting in $self->initHash, which is applied in the
5631 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
5632 # generic object function Games::Axmud->getMethodRef()
5633 funcRef => undef,
5634 # A value passed to ->funcRef when it is called which identifies this table object and
5635 # its widget(s). Can be any value except 'undef'. It can be set by a call to
5636 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
5637 # to $self->objEnable()
5638 funcID => '',
5639  
5640 # The container widget(s) for this table object
5641 packingBox => undef, # Gtk3::Grid or Gtk3::Frame
5642 packingBox2 => undef, # Gtk3::Grid
5643  
5644 # Other IVs
5645 # ---------
5646  
5647 # Widgets
5648 frame => undef, # Gtk3::Frame (may be 'undef')
5649 scroll => undef, # Gtk3::ScrolledWindow
5650 textView => undef, # Gtk3::TextView
5651 buffer => undef, # Gtk3::TextBuffer
5652 };
5653  
5654 # Bless the object into existence
5655 bless $self, $class;
5656  
5657 return $self;
5658 }
5659  
5660 ##################
5661 # Methods
5662  
5663 # Standard table object functions
5664  
5665 sub objEnable {
5666  
5667 # Called by GA::Strip::Table->addTableObj
5668 # Sets up the table object's widgets
5669 #
5670 # Expected arguments
5671 # (none besides $self)
5672 #
5673 # Return values
5674 # 'undef' on improper arguments
5675 # 1 on success
5676  
5677 my ($self, $check) = @_;
5678  
5679 # Local variables
5680 my (
5681 $funcRef, $funcID, $text, $editFlag, $systemFlag, $colourScheme, $spacing, $hExpandFlag,
5682 $vExpandFlag, $winType,
5683 );
5684  
5685 # Check for improper arguments
5686 if (defined $check) {
5687  
5688 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
5689 }
5690  
5691 # Interpret $self->initHash, replacing any invalid values
5692 $funcRef = $self->ivShow('initHash', 'func');
5693 $funcID = $self->ivShow('initHash', 'id');
5694 $text = $self->ivShow('initHash', 'text');
5695 if (! defined $text) {
5696  
5697 $text = '';
5698 }
5699  
5700 $editFlag = $self->testFlag($self->ivShow('initHash', 'edit_flag'));
5701 $systemFlag = $self->testFlag($self->ivShow('initHash', 'system_flag'));
5702 $colourScheme = $self->ivShow('initHash', 'colour_scheme');
5703 $spacing = $self->testInt($self->ivShow('initHash', 'spacing'), 0, 0);
5704 $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag'));
5705 $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag'));
5706  
5707 # Create packing box(es)
5708 my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::Grid->new());
5709  
5710 # Create the Gtk3::TextView inside a Gtk3::Frame and Gtk3::ScrolledWindow. However, if
5711 # $packingBox is itself a Gtk3::Frame, don't create a second one
5712 my ($frame, $scroll);
5713 if (! $packingBox->isa('Gtk3::Frame')) {
5714  
5715 $frame = Gtk3::Frame->new(undef);
5716 $packingBox2->attach($frame, 0, 0, 1, 1);
5717 $frame->set_border_width($spacing);
5718  
5719 $scroll = Gtk3::ScrolledWindow->new(undef, undef);
5720 $frame->add($scroll);
5721  
5722 } else {
5723  
5724 my $scroll = Gtk3::ScrolledWindow->new(undef, undef);
5725 $packingBox2->attach($scroll, 0, 0, 1, 1);
5726 }
5727  
5728 $scroll->set_shadow_type($axmud::CLIENT->constShadowType);
5729 $scroll->set_policy('automatic', 'automatic');
5730 $scroll->set_border_width($spacing);
5731  
5732 # Create a textview
5733 my $textView = Gtk3::TextView->new();
5734 $scroll->add($textView);
5735 my $buffer = Gtk3::TextBuffer->new();
5736 $textView->set_buffer($buffer);
5737  
5738 if (! $editFlag) {
5739  
5740 $textView->set_editable(FALSE);
5741 $textView->set_cursor_visible(FALSE);
5742 $textView->set_can_focus(FALSE);
5743  
5744 } else {
5745  
5746 $textView->set_editable(TRUE);
5747 $textView->set_cursor_visible(TRUE);
5748 $textView->set_can_focus(TRUE);
5749 }
5750  
5751 $textView->set_wrap_mode('word-char'); # Wrap words if possible, characters if not
5752 $textView->set_justification('left');
5753  
5754 if ($systemFlag && $axmud::CLIENT->ivExists('colourSchemeHash', $colourScheme)) {
5755 $axmud::CLIENT->desktopObj->setTextViewStyle($colourScheme, $textView);
5756 } else {
5757 $axmud::CLIENT->desktopObj->setTextViewStyle($self->winObj->winType, $textView);
5758 }
5759  
5760 $buffer->set_text($text);
5761  
5762 # Set expansion
5763 $textView->set_hexpand($hExpandFlag);
5764 $textView->set_vexpand($vExpandFlag);
5765  
5766 # Update IVs
5767 $self->ivPoke('funcRef', $funcRef);
5768 $self->ivPoke('funcID', $funcID);
5769 $self->ivPoke('packingBox', $packingBox);
5770 $self->ivPoke('packingBox2', $packingBox2);
5771 $self->ivPoke('frame', $frame);
5772 $self->ivPoke('scroll', $scroll);
5773 $self->ivPoke('textView', $textView);
5774 $self->ivPoke('buffer', $buffer);
5775  
5776 # Set up ->signal_connects
5777 $self->setChangedEvent();
5778  
5779 return 1;
5780 }
5781  
5782 # sub objDestroy { # Inherited from GA::Generic::Table
5783  
5784 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table
5785  
5786 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table
5787  
5788 # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table
5789  
5790 # ->signal_connects
5791  
5792 sub setChangedEvent {
5793  
5794 # Called by $self->objEnable
5795 #
5796 # Expected arguments
5797 # (none besides $self)
5798 #
5799 # Return values
5800 # 'undef' on improper arguments
5801 # 1 otherwise
5802  
5803 my ($self, $check) = @_;
5804  
5805 # Check for improper arguments
5806 if (defined $check) {
5807  
5808 return $axmud::CLIENT->writeImproper($self->_objClass . '->setChangedEvent', @_);
5809 }
5810  
5811 $self->buffer->signal_connect('changed' => sub {
5812  
5813 my $currentFuncRef = $self->funcRef;
5814  
5815 if ($currentFuncRef) {
5816  
5817 &$currentFuncRef(
5818 $self,
5819 $self->textView,
5820 $self->buffer,
5821 $self->funcID,
5822 $axmud::CLIENT->desktopObj->bufferGetText($self->buffer),
5823 );
5824 }
5825 });
5826  
5827 return 1;
5828 }
5829  
5830 # Other functions
5831  
5832 ##################
5833 # Accessors - set
5834  
5835 sub set_editable {
5836  
5837 my ($self, $flag, $check) = @_;
5838  
5839 # Check for improper arguments
5840 if (defined $check) {
5841  
5842 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_editable', @_);
5843 }
5844  
5845 if (! $flag) {
5846  
5847 $self->textView->set_editable(FALSE);
5848 $self->textView->set_cursor_visible(FALSE);
5849 $self->textView->set_can_focus(FALSE);
5850  
5851 } else {
5852  
5853 $self->textView->set_editable(TRUE);
5854 $self->textView->set_cursor_visible(TRUE);
5855 $self->textView->set_can_focus(TRUE);
5856 }
5857  
5858 return 1;
5859 }
5860  
5861 # sub set_func {} # Inherited from GA::Generic::Table
5862  
5863 # sub set_id {} # Inherited from GA::Generic::Table
5864  
5865 sub set_text {
5866  
5867 my ($self, $text, $check) = @_;
5868  
5869 # Check for improper arguments
5870 if (defined $check) {
5871  
5872 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_text', @_);
5873 }
5874  
5875 if (! defined $text) {
5876  
5877 $text = '';
5878 }
5879  
5880 $self->buffer->set_text($text);
5881  
5882 return 1;
5883 }
5884  
5885 sub insert_text {
5886  
5887 my ($self, $text, $check) = @_;
5888  
5889 # Check for improper arguments
5890 if (defined $check) {
5891  
5892 return $axmud::CLIENT->writeImproper($self->_objClass . '->insert_text_at_cursor', @_);
5893 }
5894  
5895 if (! defined $text) {
5896  
5897 $text = '';
5898 }
5899  
5900 $self->buffer->insert_at_cursor ($text);
5901  
5902 return 1;
5903 }
5904  
5905 # (Get equivalents)
5906  
5907 sub get_editable {
5908  
5909 my ($self, $check) = @_;
5910  
5911 # Check for improper arguments
5912 if (defined $check) {
5913  
5914 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_editable', @_);
5915 }
5916  
5917 if ($self->textView->get_editable()) {
5918 return TRUE;
5919 } else {
5920 return FALSE;
5921 }
5922 }
5923  
5924 sub get_text {
5925  
5926 my ($self, $check) = @_;
5927  
5928 # Check for improper arguments
5929 if (defined $check) {
5930  
5931 return $axmud::CLIENT->writeImproper($self->_objClass . '->get_text', @_);
5932 }
5933  
5934 return $axmud::CLIENT->desktopObj->bufferGetText($self->buffer);
5935 }
5936  
5937 ##################
5938 # Accessors - get
5939  
5940 sub frame
5941 { $_[0]->{frame} }
5942 sub scroll
5943 { $_[0]->{scroll} }
5944 sub textView
5945 { $_[0]->{textView} }
5946 sub buffer
5947 { $_[0]->{buffer} }
5948 }
5949  
5950 # Complex table objects
5951  
5952 { package Games::Axmud::Table::Pane;
5953  
5954 use strict;
5955 use warnings;
5956 use diagnostics;
5957  
5958 use Glib qw(TRUE FALSE);
5959  
5960 our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud);
5961  
5962 ##################
5963 # Constructors
5964  
5965 sub new {
5966  
5967 # Called by GA::Strip::Table->addTableObj
5968 # Creates the GA::Table::Pane, which contains one or more Gtk3::TextViews sharing a single
5969 # Gtk3::TextBuffer
5970 #
5971 # Expected arguments
5972 # $number - The table object's number within the parent strip object (matches
5973 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object
5974 # created to access its default IVs)
5975 # $name - A name for the table object. Can be any string or, if no name was
5976 # specified in the call to the calling function, $name is the same as
5977 # $number. (No part of the code checks that table object names are unique;
5978 # if two or more table objects share the same ->name, usually the one with
5979 # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
5980 # chars)
5981 # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table
5982 # objects
5983 # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
5984 # parent strip object's Gtk3::Grid for use exclusively by this table
5985 # object. 'temp' for temporary table objects
5986 #
5987 # Optional arguments
5988 # %initHash - A hash containing arbitrary data to use as the table object's
5989 # initialisation settings. The table object should use default
5990 # initialisation settings unless it can succesfully interpret one or more
5991 # of the key-value pairs in the hash, if there are any
5992 # - This type of table object recognises these initialisation settings:
5993 #
5994 # 'frame_title' - If specified, the table object is drawn inside a frame
5995 # with the specified title. If 'undef', an empty string or not
5996 # specified, the table object does not use a frame and title
5997 # 'entry_flag' - TRUE if a Gtk3::Entry should be drawn beneath the
5998 # textview(s), FALSE if not. Ignored if 'func' is not also specified
5999 # 'func' - Reference to a function to call when the user types something
6000 # in the pane's own entry box and presses 'return'. If not specified
6001 # or 'undef', it's up to the calling code to create its own
6002 # ->signal_connect. Ignored if 'entry_flag' is FALSE. To obtain a
6003 # reference to an OOP method, you can use the generic object function
6004 # Games::Axmud->getMethodRef()
6005 # 'id' - A value passed to the function which identifies this pane. If
6006 # specified, can be any value except 'undef'. It's up to the
6007 # calling code to keep track of the widgets it has created and their
6008 # corresponding 'id' values
6009 # 'switch_func' - Reference to a function to call when a tab becomes the
6010 # visible one (including when it is created). Not required for
6011 # sessions using this pane object for their default tabs, as the
6012 # code checks for that separately
6013 # 'switch_id' - A value passed to the function which identifies this
6014 # pane. If specified, can be any value except 'undef'. It's up to the
6015 # calling code to keep track of the widgets it has created and their
6016 # corresponding 'id' values
6017 # 'close_func' - Reference to a function to call when a tab is closed. Not
6018 # required for sessions using this pane object for their default tabs,
6019 # as the code checks for that separately
6020 # 'close_id' - A value passed to the function which identifies this
6021 # pane. If specified, can be any value except 'undef'. It's up to the
6022 # calling code to keep track of the widgets it has created and their
6023 # corresponding 'id' values
6024 # 'can_close_flag' - TRUE if tabs with labels also have a small button for
6025 # closing the tab, FALSE (or 'undef') if not. Ignored for 'simple'
6026 # tabs which have no label
6027 # 'split_mode' - 'single' if split screen mode is off, 'split' or 'hidden'
6028 # if split screen mode is on (for 'hidden', the divider is initially
6029 # positioned at the top of the screen). If not specified or an
6030 # unrecognised value, 'single' is used
6031 # 'colour_scheme' - The name of a colour scheme to use in this pane's
6032 # textviews (if the colour scheme is updated, so are the colours and
6033 # fonts used in the textviews). If not specified or if the named
6034 # colour scheme doesn't exist, uses the colour scheme named after the
6035 # window type
6036 # 'max_lines' - The maximum number of lines for the textview buffer. If
6037 # specified, must be 0 (meaning no maximum; not recommended) or a
6038 # positive integer between GA::Client->constMinBufferSize and
6039 # ->constMaxBufferSize (inclusive)
6040 # 'new_line' - The default behaviour when a string is inserted into the
6041 # tab's textview: 'before' prepends a newline character to the string,
6042 # 'after' prepends a newline character after the string, 'echo' does
6043 # not prepend/a newline character by default. If 'undef' or an
6044 # unrecognised value, 'after' is used
6045 #
6046 # Return values
6047 # 'undef' on improper arguments
6048 # Blessed reference to the newly-created object on success
6049  
6050 my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
6051  
6052 # Local variables
6053 my (
6054 $winObj, $colourScheme,
6055 %modHash,
6056 );
6057  
6058 # Check for improper arguments
6059 if (
6060 ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
6061 || ! defined $zoneObj
6062 ) {
6063 return $axmud::CLIENT->writeImproper($class . '->new', @_);
6064 }
6065  
6066 # Deal with temporary table objects
6067 if ($stripObj eq 'temp') {
6068 $winObj = 'temp';
6069 } else {
6070 $winObj = $stripObj->winObj;
6071 }
6072  
6073 # Default initialisation settings
6074 if (
6075 $number != -1
6076 && (! $colourScheme || ! $axmud::CLIENT->ivShow('colourSchemeHash', $colourScheme))
6077 ) {
6078 $colourScheme = $stripObj->winObj->winType;
6079 }
6080  
6081 %modHash = (
6082 'frame_title' => undef,
6083 'entry_flag' => FALSE,
6084 'func' => undef,
6085 'id' => '',
6086 'switch_func' => undef,
6087 'switch_id' => '',
6088 'close_func' => undef,
6089 'close_id' => '',
6090 'can_close_flag' => TRUE,
6091 'split_mode' => 'single',
6092 'colour_scheme' => $colourScheme,
6093 'max_lines' => $axmud::CLIENT->customTextBufferSize,
6094 'new_line' => 'after',
6095 );
6096  
6097 # Interpret the initialisation settings in %initHash, if any
6098 foreach my $key (keys %modHash) {
6099  
6100 if (exists $initHash{$key}) {
6101  
6102 if ($key =~ m/flag$/) {
6103  
6104 if ($initHash{$key}) {
6105 $modHash{$key} = TRUE;
6106 } else {
6107 $modHash{$key} = FALSE;
6108 }
6109  
6110 } elsif ($key eq 'max_lines') {
6111  
6112 if (
6113 $initHash{$key} == 0
6114 || (
6115 $initHash{$key} >= $axmud::CLIENT->constMinBufferSize
6116 && $initHash{$key} <= $axmud::CLIENT->constMaxBufferSize
6117 )
6118 ) {
6119 $modHash{$key} = $initHash{$key};
6120 }
6121  
6122 } elsif (
6123 ($key eq 'id' || $key eq 'switch_id' || $key eq 'close_id')
6124 && ! defined $initHash{$key}
6125 ) {
6126 $modHash{$key} = ''; # 'id' value must not be 'undef'
6127  
6128 } elsif (
6129 $key eq 'split_mode'
6130 && (
6131 $initHash{$key} eq 'single' || $initHash{$key} eq 'split'
6132 || $initHash{$key} eq 'hidden'
6133 )
6134 ) {
6135 $modHash{$key} = $initHash{$key};
6136  
6137 } elsif (
6138 $key eq 'new_line'
6139 && defined $initHash{$key}
6140 && ($initHash{$key} eq 'echo' || $initHash{$key} eq 'before')
6141 ) {
6142 $modHash{$key} = $initHash{$key};
6143  
6144 } else {
6145  
6146 $modHash{$key} = $initHash{$key};
6147 }
6148 }
6149 }
6150  
6151 # Setup
6152 my $self = {
6153 _objName => 'table_obj_' . $number,
6154 _objClass => $class,
6155 _parentFile => undef, # No parent file object
6156 _parentWorld => undef, # No parent file object
6157 _privFlag => TRUE, # All IVs are private
6158  
6159 # Standard table object IVs
6160 # -------------------------
6161  
6162 # The table object's number within the parent strip object (matches
6163 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to
6164 # access its default IVs)
6165 number => $number,
6166 # A name for the table object. Can be any string or, if no name was specified in the
6167 # call to the calling function, $name is the same as $number. (No part of the code
6168 # checks that table object names are unique; if two or more table objects share the
6169 # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary
6170 # table objects. Max 16 chars)
6171 name => $name,
6172 # The type of table object (custom table objects should use a ->type starting with
6173 # 'custom_' to avoid clashing with future built-in table objects)
6174 type => 'pane',
6175 # The parent strip object (GA::Strip::Table)
6176 stripObj => $stripObj,
6177 # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for
6178 # temporary table objects
6179 winObj => $winObj,
6180 # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip
6181 # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary
6182 # table objects
6183 zoneObj => $zoneObj,
6184  
6185 # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is
6186 # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as
6187 # when a connection to a world terminates)
6188 allowRemoveFlag => TRUE,
6189 # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is
6190 # created. Set to FALSE if it can't be resized
6191 allowResizeFlag => TRUE,
6192 # Initialisation settings stored as a hash (see the comments above)
6193 initHash => \%modHash,
6194 # Reference to a function to call when some widget is used. This IV is set only when
6195 # required by this type of table object. It can be set by a call to
6196 # $self->set_func() or by some setting in $self->initHash, which is applied in the
6197 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
6198 # generic object function Games::Axmud->getMethodRef()
6199 funcRef => undef,
6200 # A value passed to ->funcRef when it is called which identifies this table object and
6201 # its widget(s). Can be any value except 'undef'. It can be set by a call to
6202 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
6203 # to $self->objEnable()
6204 funcID => '',
6205  
6206 # The container widget(s) for this table object
6207 packingBox => undef, # Gtk3::VBox or Gtk3::Frame
6208 packingBox2 => undef, # Gtk3::VBox
6209  
6210 # Other IVs
6211 # ---------
6212  
6213 # Widgets
6214 notebook => undef, # Gtk3::Notebook
6215 hBox => undef, # Gtk3::HBox
6216 entry => undef, # Gtk3::Entry
6217  
6218 # The normal and modified border widths to apply to $self->packingBox2 when this pane is
6219 # selected and unselected by the switcher button in
6220 # GA::Strip::Entry->setSwitchSignals
6221 normalBorderWidth => 0,
6222 selectBorderWidth => 5,
6223  
6224 # Hashes of tabs and their corresponding tab objects (GA::Obj::Tab), which store the
6225 # widgets required to create, modify or remove each tab
6226 # Every tab contains a single textview object (GA::Obj::TextView). A textview object
6227 # handles either a single Gtk3::TextView, or two Gtk3::TextViews sharing a single
6228 # Gtk3::TextBuffer (depending on whether split screen mode is off or on)
6229 # The tab object stores that textview object, the controlling session (GA::Session)
6230 # and details of which Gtk3 widgets to pack/unpack when the appearance of the tab is
6231 # modified
6232 #
6233 # When a Gtk3::Notebook is in use, the Gtk3 inheritance tree looks like this:
6234 # Gtk3::VBox ($self->packingBox, ->packingBox2)
6235 # Gtk3::Notebook
6236 # Gtk3::VBox ($tabObj->packableObj)
6237 # Gtk3::ScrolledWindow ($tabObj->packedObj)
6238 # Gtk3::TextView ($tabObj->textViewObj->textView)
6239 # ...or like this, when split screen mode is on:
6240 # Gtk3::VBox ($self->packingBox, ->packingBox2)
6241 # Gtk3::Notebook
6242 # Gtk3::VBox ($tabObj->packableObj)
6243 # Gtk3::VPaned ($tabObj->packedObj)
6244 # Gtk3::Scroll
6245 # Gtk3::TextView ($tabObj->textViewObj->textView)
6246 # Gtk3::Scroll
6247 # Gtk3::TextView ($tabObj->textViewObj->textView2)
6248 # ..and the hash in the form
6249 # $tabObjHash{unique_number} = blessed_reference_to_tab_object
6250 #
6251 # When a Gtk3::Notebook is not in use, the comments in this table object describe a
6252 # 'simple tab'. In actuality, the simplified inheritance tree looks like this:
6253 # Gtk3::VBox ($self->packingBox, ->packingBox2)
6254 # Gtk3::ScrolledWindow ($tabObj->packedObj)
6255 # Gtk3::TextView ($tabObj->textViewObj->textView)
6256 # ...or like this, when split screen mode is on:
6257 # Gtk3::VBox ($self->packingBox, ->packingBox2)
6258 # Gtk3::VPaned ($tabObj->packedObj)
6259 # Gtk3::ScrolledWindow
6260 # Gtk3::TextView ($tabObj->textViewObj->textView)
6261 # Gtk3::ScrolledWindow
6262 # Gtk3::TextView ($tabObj->textViewObj->textView2)
6263 # ...and the hash contains a single key-value pair, in the form
6264 # $tabObjHash{0} = blessed_reference_to_tab_object
6265 #
6266 # NB If a 'frame_title' was specified by the calling function, $self->packingBox will
6267 # be a Gtk3::Frame, and $self->packingBox2 will be a Gtk3::VBox. If not, both
6268 # $self->packingBox and ->packingBox2 will be the same Gtk3::VBox widget
6269 tabObjHash => {},
6270 # Number of tab objects created since this pane object was created (used to give each
6271 # tab object a unique number). When converting from a simple tab to (normal) tabs, or
6272 # vice-versa, ->tabObjHash is emptied and ->tabObjCount is reset
6273 tabObjCount => 0,
6274 # The visible tab object; set by $self->respondVisibleTab when the visible tab actually
6275 # changes
6276 currentTabObj => undef,
6277 # When a simple tab is created, this flag is set to TRUE. If a second tab is added, the
6278 # existing simple tab is converted into a normal tab, and this flag is unchanged. If
6279 # tabs are removed and there's only one tab left, that tab is converted into a simple
6280 # tab if this flag is TRUE. When there are no tabs left, the flag is set back to
6281 # FALSE
6282 # In that way, whether the pane uses simple tabs or not depends entirely on the calling
6283 # code, which can create its first tab through a call ->addSimpleTab or ->addTab
6284 simpleTabFlag => FALSE,
6285 # Flag set to TRUE while $self->convertSimpleTab and ->convertTab are in progress, so
6286 # that various ->signal_connects know not to take action
6287 tabConvertFlag => FALSE,
6288 # Flag set to TRUE if tabs with labels also have a small button for closing the tab,
6289 # FALSE if not. Ignored for 'simple' tabs which have no label
6290 # If modified via a call to $self->set_canCloseFlag, the new setting will only be
6291 # applied to tabs opened after that
6292 canCloseFlag => TRUE,
6293  
6294 # Reference to a function to call when a tab becomes the visible one (including when it
6295 # is created). Not required for sessions using this pane object for their default
6296 # tabs, as the code checks for that separately
6297 switchFuncRef => undef,
6298 # A value passed to the $self->switchFuncRef which identifies this pane. If specified,
6299 # can be any value except 'undef'. It's up to the calling code to keep track of the
6300 # widgets it has created and their corresponding 'id' values
6301 switchFuncID => '',
6302 # Reference to a function to call when a tab is closed. Not required for sessions using
6303 # this pane object for their default tabs, as the code checks for that separately
6304 closeFuncRef => undef,
6305 # A value passed to the $self->closeFuncRef which identifies this pane. If specified,
6306 # can be any value except 'undef'. It's up to the calling code to keep track of the
6307 # widgets it has created and their corresponding 'id' values
6308 closeFuncID => '',
6309 };
6310  
6311 # Bless the object into existence
6312 bless $self, $class;
6313  
6314 return $self;
6315 }
6316  
6317 ##################
6318 # Methods
6319  
6320 # Standard table object functions
6321  
6322 sub objEnable {
6323  
6324 # Called by GA::Strip::Table->addTableObj
6325 # Sets up the table object's widgets
6326 #
6327 # Expected arguments
6328 # (none besides $self)
6329 #
6330 # Return values
6331 # 'undef' on improper arguments
6332 # 1 on success
6333  
6334 my ($self, $check) = @_;
6335  
6336 # Check for improper arguments
6337 if (defined $check) {
6338  
6339 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
6340 }
6341  
6342 # Create packing box(es)
6343 my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::VBox->new(FALSE, 0));
6344 $packingBox2->set_border_width($self->normalBorderWidth);
6345  
6346 # Draw a Gtk3::Entry, if specified
6347 my ($hBox, $entry);
6348 if (
6349 $self->ivShow('initHash', 'entry_flag')
6350 && $self->ivShow('initHash', 'func')
6351 ) {
6352 $hBox = Gtk3::HBox->new(FALSE, 0);
6353 $packingBox2->pack_end($hBox, FALSE, FALSE, $axmud::CLIENT->constGridSpacingPixels);
6354  
6355 $entry = Gtk3::Entry->new();
6356 $hBox->pack_start($entry, TRUE, TRUE, $axmud::CLIENT->constGridSpacingPixels);
6357 }
6358  
6359 # Set expansion
6360 $packingBox->set_hexpand(TRUE);
6361 $packingBox->set_vexpand(TRUE);
6362  
6363 # Update IVs
6364 $self->ivPoke('funcRef', $self->ivShow('initHash', 'func'));
6365 $self->ivPoke('funcID', $self->ivShow('initHash', 'id'));
6366 $self->ivPoke('packingBox', $packingBox);
6367 $self->ivPoke('packingBox2', $packingBox2);
6368 $self->ivPoke('hBox', $hBox);
6369 $self->ivPoke('entry', $entry);
6370  
6371 if ($self->ivShow('initHash', 'can_close_flag')) {
6372 $self->ivPoke('canCloseFlag', TRUE);
6373 } else {
6374 $self->ivPoke('canCloseFlag', FALSE);
6375 }
6376  
6377 $self->ivPoke('switchFuncRef', $self->ivShow('initHash', 'switch_func'));
6378 $self->ivPoke('switchFuncID', $self->ivShow('initHash', 'switch_id'));
6379 $self->ivPoke('closeFuncRef', $self->ivShow('initHash', 'close_func'));
6380 $self->ivPoke('closeFuncID', $self->ivShow('initHash', 'close_id'));
6381  
6382 # Set up ->signal_connects
6383 if ($self->entry) {
6384  
6385 $self->setActivateEvent();
6386 }
6387  
6388 return 1;
6389 }
6390  
6391 sub objDestroy {
6392  
6393 # Called by GA::Strip::Table->objDestroy, just before that strip is removed from its parent
6394 # window, to give this object a chance to do any necessary tidying up
6395 # Generic function that can be inherited by any table object that doesn't need to do any
6396 # tidying up
6397 #
6398 # Expected arguments
6399 # (none besides $self)
6400 #
6401 # Return values
6402 # 'undef' on improper arguments
6403 # 1 otherwise
6404  
6405 my ($self, $check) = @_;
6406  
6407 # Check for improper arguments
6408 if (defined $check) {
6409  
6410 return $axmud::CLIENT->writeImproper($self->_objClass . '->objDestroy', @_);
6411 }
6412  
6413 # Tidy up any textview objects
6414 foreach my $tabObj ($self->ivValues('tabObjHash')) {
6415  
6416 $tabObj->textViewObj->objDestroy();
6417 }
6418  
6419 return 1;
6420 }
6421  
6422 # sub setWidgetsIfSession {}
6423  
6424 # sub setWidgetsChangeSession {}
6425  
6426 sub setWidgetsOnResize {
6427  
6428 # Called by GA::Strip::Table->resizeTableObj
6429 # Allows this table object to update its widgets whenever the table object is resized on its
6430 # Gtk3::Grid
6431 #
6432 # Expected arguments
6433 # $left, $right, $top, $bottom
6434 # - The coordinates of the top-left ($left, $top) and bottom-right ($right, $bottom)
6435 # corners of the table object on the table after the resize
6436 #
6437 # Return values
6438 # 'undef' on improper arguments
6439 # 1 otherwise
6440  
6441 my ($self, $left, $right, $top, $bottom, $check) = @_;
6442  
6443 # Check for improper arguments
6444 if (
6445 ! defined $left || ! defined $right || ! defined $top || ! defined $bottom
6446 || defined $check
6447 ) {
6448 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWidgetsOnResize', @_);
6449 }
6450  
6451 # For some reason, resizing the table object makes the Gtk3::TextView use the most recent
6452 # rc file, which messes up the colours; therefore, we have to re-apply the colour scheme
6453 # for each tab
6454 $self->updateColourScheme();
6455  
6456 return 1;
6457 }
6458  
6459 # ->signal_connects
6460  
6461 sub setSwitchPageEvent {
6462  
6463 # Called by $self->drawNotebook
6464 #
6465 # Expected arguments
6466 # $notebook - The Gtk3::Notebook which emits the signal
6467 #
6468 # Return values
6469 # 'undef' on improper arguments
6470 # 1 otherwise
6471  
6472 my ($self, $notebook, $check) = @_;
6473  
6474 # Check for improper arguments
6475 if (! defined $notebook || defined $check) {
6476  
6477 return $axmud::CLIENT->writeImproper($self->_objClass . '->setSwitchPageEvent', @_);
6478 }
6479  
6480 # This callback is intended to detect when the user clicks on one of the notebook's tabs,
6481 # making that tab visible
6482 $notebook->signal_connect('switch-page' => sub {
6483  
6484 my ($widget, $num, $page) = @_;
6485  
6486 my $tabObj = $self->findPage($page);
6487 if ($tabObj) {
6488  
6489 $self->respondVisibleTab($tabObj);
6490 }
6491 });
6492  
6493 return 1;
6494 }
6495  
6496 sub setButtonClicked {
6497  
6498 # Called by $self->addTab
6499 #
6500 # Expected arguments
6501 # $button - The Gtk3::Button which emits the signal
6502 # $tabObj - The corresponding GA::Obj::Tab
6503 #
6504 # Optional arguments
6505 # $session - If the tab is a session's default tab, the GA::Session for the tab
6506 #
6507 # Return values
6508 # 'undef' on improper arguments
6509 # 1 otherwise
6510  
6511 my ($self, $button, $tabObj, $session, $check) = @_;
6512  
6513 # Check for improper arguments
6514 if (! defined $button || ! defined $tabObj || defined $check) {
6515  
6516 return $axmud::CLIENT->writeImproper($self->_objClass . '->setButtonClicked', @_);
6517 }
6518  
6519 $button->signal_connect('clicked' => sub {
6520  
6521 my $choice;
6522  
6523 if ($session) {
6524  
6525 if ($session->status eq 'connected' && $axmud::CLIENT->confirmCloseTabFlag) {
6526  
6527 $choice = $self->winObj->showMsgDialogue(
6528 'Close tab',
6529 'question',
6530 'This session is connected to a world. Are you sure you want to close it?',
6531 'yes-no',
6532 );
6533  
6534 if ($choice && $choice eq 'yes') {
6535  
6536 # ->stopSession calls this object's ->removeSessionTab
6537 $session->pseudoCmd('stopsession', $self->winObj->pseudoCmdMode);
6538 }
6539  
6540 } else {
6541  
6542 $session->pseudoCmd('stopsession', $self->winObj->pseudoCmdMode);
6543 }
6544  
6545 } else {
6546  
6547 # If this isn't a session's default tab, we can remove the tab directly
6548 $self->removeTab($tabObj);
6549 }
6550 });
6551  
6552 return 1;
6553 }
6554  
6555 sub setActivateEvent {
6556  
6557 # Called by $self->objEnable
6558 #
6559 # Expected arguments
6560 # (none besides $self)
6561 #
6562 # Return values
6563 # 'undef' on improper arguments
6564 # 1 otherwise
6565  
6566 my ($self, $check) = @_;
6567  
6568 # Check for improper arguments
6569 if (defined $check) {
6570  
6571 return $axmud::CLIENT->writeImproper($self->_objClass . '->setActivateEvent', @_);
6572 }
6573  
6574 $self->entry->signal_connect('activate' => sub {
6575  
6576 my ($value, $thisFuncRef);
6577  
6578 $value = $self->entry->get_text();
6579 $thisFuncRef = $self->funcRef;
6580  
6581 if ($thisFuncRef) {
6582  
6583 &$thisFuncRef($self, $self->entry, $self->funcID, $value);
6584 }
6585  
6586 $self->entry->set_text('');
6587 });
6588  
6589 return 1;
6590 }
6591  
6592 # Other functions
6593  
6594 sub drawNotebook {
6595  
6596 # Called by $self->addTab and $self->convertSimpleTab
6597 # Draws a Gtk3::Notebook whose tabs can each contain a Gtk3::TextView
6598 #
6599 # Expected arguments
6600 # (none besides $self)
6601 #
6602 # Return values
6603 # 'undef' on improper arguments or if the widget can't be drawn
6604 # Otherwise returns the Gtk3::Notebook
6605  
6606 my ($self, $check) = @_;
6607  
6608 # Check for improper arguments
6609 if (defined $check) {
6610  
6611 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawNotebook', @_);
6612 }
6613  
6614 # Create the notebook, stored in $self->notebook
6615 my $notebook = Gtk3::Notebook->new();
6616 $notebook->set_scrollable(TRUE);
6617 $notebook->popup_enable();
6618 $notebook->set_can_focus(FALSE);
6619  
6620 # Gtk3::Notebook created
6621 $self->packingBox2->pack_start($notebook, TRUE, TRUE, 0);
6622 # Set up ->signal_connects
6623 $self->setSwitchPageEvent($notebook);
6624  
6625 # Update IVs
6626 $self->ivPoke('notebook', $notebook);
6627  
6628 return $notebook;
6629 }
6630  
6631 sub addSimpleTab {
6632  
6633 # Called by GA::Session->setDefaultTab, $self->convertTab or any other code
6634 # Adds a simple tab (containing a standalone textview object, not a page in a notebook)
6635 #
6636 # Expected arguments
6637 # $session - The GA::Session that will control the tab (and the textview object
6638 # it contains)
6639 #
6640 # Optional arguments
6641 # $colourScheme - If specified, the name of the colour scheme to use. If 'undef' (or if
6642 # the specified colour scheme doesn't exist), the colour scheme
6643 # specified by $self->initHash is used
6644 # $sessionFlag - Flag set to TRUE if this tab was called by
6645 # GA::Session->setDefaultTab, FALSE (or 'undef') if it was called by
6646 # anything else
6647 # $defaultFlag - Flag set to TRUE if this tab will be $session's default tab (where
6648 # text received from the world is usually displayed), FALSE (or
6649 # 'undef') otherwise (might be TRUE even if $sessionFlag is FALSE)
6650 # $labelText - The text to use in the tab label, ignored if specified (exists for
6651 # compatibility with other functions in this group)
6652 # $oldBuffer - If a Gtk3::Notebook with a single tab is being replaced by a
6653 # standalone textview object, the old textview object's
6654 # Gtk3::TextBuffer, which is transferred to the new textview object
6655 # ('undef' otherwise)
6656 #
6657 # Return values
6658 # 'undef' on improper arguments or if the simple tab can't be drawn
6659 # Otherwise returns the tab object (GA::Obj::Tab) created, which stores (among other
6660 # things) the textview object created
6661  
6662 my (
6663 $self, $session, $colourScheme, $sessionFlag, $defaultFlag, $labelText, $oldBuffer,
6664 $check,
6665 ) = @_;
6666  
6667 # Local variables
6668 my ($textViewObj, $packedObj, $tabObj);
6669  
6670 # Check for improper arguments
6671 if (! defined $session || defined $check) {
6672  
6673 return $axmud::CLIENT->writeImproper($self->_objClass . '->addSimpleTab', @_);
6674 }
6675  
6676 # If this pane object has drawn a notebook, not a simple container (a Gtk3::ScrolledWindow
6677 # or Gtk3::VPaned), $self->addTab should have been called instead. Show a warning, then
6678 # redirect the function call
6679 if ($self->notebook) {
6680  
6681 $self->winObj->session->writeWarning(
6682 'Tried to add a simple tab to a notebook; code should call ->addTab, not'
6683 . ' ->addSimpleTab',
6684 $self->_objClass . '->addSimpleTab',
6685 );
6686  
6687 return $self->addTab(
6688 $session,
6689 $colourScheme,
6690 $sessionFlag,
6691 $defaultFlag,
6692 $labelText,
6693 $oldBuffer,
6694 );
6695  
6696 # If there is already a simple tab, don't create another one
6697 } elsif ($self->tabObjHash) {
6698  
6699 return $self->writeError(
6700 'Tried to add a simple tab, but one or more tabs already exist',
6701 $self->_objClass . '->addSimpleTab',
6702 );
6703 }
6704  
6705 # Create a new GA::Obj::Textview object to handle the Gtk3::Textview(s)
6706 $textViewObj = $axmud::CLIENT->desktopObj->add_textView(
6707 $session,
6708 $self->winObj,
6709 $self,
6710 );
6711  
6712 if (! $textViewObj) {
6713  
6714 return undef;
6715 }
6716  
6717 # Set the colour scheme to use
6718 if (
6719 ! defined $colourScheme
6720 || ! $axmud::CLIENT->ivExists('colourSchemeHash', $colourScheme)
6721 ) {
6722 $colourScheme = $self->ivShow('initHash', 'colour_scheme');
6723 }
6724  
6725 # Create the Gtk3::TextView(s) themselves. The function call returns a Gtk3::ScrolledWindow
6726 # or a Gtk3::VPaned containing the textview(s)
6727 $packedObj = $textViewObj->objEnable(
6728 $self->ivShow('initHash', 'split_mode'),
6729 $colourScheme,
6730 $self->ivShow('initHash', 'max_lines'),
6731 $self->ivShow('initHash', 'new_line'),
6732 $oldBuffer,
6733 );
6734  
6735 if (! $packedObj) {
6736  
6737 $textViewObj->objDestroy();
6738 return undef;
6739 }
6740  
6741 # Pack the Gtk3::ScrolledWindow/Gtk3::VPaned into our main Gtk3::VBox
6742 $self->packingBox2->pack_start($packedObj, TRUE, TRUE, 0);
6743  
6744 # Create a tab object to store details about the tab
6745 $tabObj = Games::Axmud::Obj::Tab->new(
6746 0, # ->number
6747 $self,
6748 $session,
6749 $defaultFlag,
6750 $textViewObj,
6751 $self->packingBox2, # ->packableObj
6752 $packedObj, # ->packedObj
6753 );
6754  
6755 # Update IVs. The code above has already checked that $self->tabObjHash is empty
6756 $self->ivAdd('tabObjHash', $tabObj->number, $tabObj);
6757 $self->ivIncrement('tabObjCount');
6758 $self->ivPoke('simpleTabFlag', TRUE);
6759  
6760 # Make the changes visible
6761 $self->winObj->winShowAll($self->_objClass . '->addSimpleTab');
6762  
6763 # The new tab is the visible tab
6764 $self->respondVisibleTab($tabObj, $sessionFlag);
6765  
6766 return $tabObj;
6767 }
6768  
6769 sub addTab {
6770  
6771 # Called by GA::Session->setDefaultTab, $self->convertSimpleTab or by any other code
6772 # Adds a (normal) tab to the Gtk3::Notebook
6773 #
6774 # Expected arguments
6775 # $session - The GA::Session that will control the tab (and the textview object
6776 # it contains)
6777 #
6778 # Optional arguments
6779 # $colourScheme - If specified, the name of the colour scheme to use. If 'undef' (or if
6780 # the specified colour scheme doesn't exist), the colour scheme
6781 # specified by $self->initHash is used
6782 # $sessionFlag - Flag set to TRUE if this tab was called by
6783 # GA::Session->setDefaultTab, FALSE (or 'undef') if it was called by
6784 # anything else
6785 # $defaultFlag - Flag set to TRUE if this tab will be $session's default tab (where
6786 # text received from the world is usually displayed), FALSE (or
6787 # 'undef') otherwise (might be TRUE even if $sessionFlag is FALSE)
6788 # $labelText - The text to use in the tab label (empty strings are acceptable). If
6789 # 'undef', 'Tab #' is used
6790 # $oldBuffer - If a standalone textview object is being replaced by a Gtk3::Notebook
6791 # with a single tab, the old textview object's Gtk3::TextBuffer, which
6792 # is transferred to the new textview object ('undef' otherwise)
6793 #
6794 # Return values
6795 # 'undef' on improper arguments or if the tab can't be drawn
6796 # Otherwise returns the tab object (GA::Obj::Tab) created, which stores (among other
6797 # things) the textview object created
6798  
6799 my (
6800 $self, $session, $colourScheme, $sessionFlag, $defaultFlag, $labelText, $oldBuffer,
6801 $check,
6802 ) = @_;
6803  
6804 # Local variables
6805 my ($textViewObj, $packedObj, $tabObj);
6806  
6807 # Check for improper arguments
6808 if (! defined $session || defined $check) {
6809  
6810 return $axmud::CLIENT->writeImproper($self->_objClass . '->addTab', @_);
6811 }
6812  
6813 # If this table object isn't using a notebook, but a simple container (a
6814 # Gtk3::ScrolledWindow or a Gtk3::VPaned), convert from the latter to the former
6815 if (! $self->notebook) {
6816  
6817 if ($self->tabObjHash) {
6818  
6819 # Convert the existing single tab to a normal tab
6820 if (! $self->convertSimpleTab()) {
6821  
6822 # (Error message displayed by called function)
6823 return undef;
6824 }
6825  
6826 } else {
6827  
6828 # No tabs exist, so create the notebook, then we can continue creating the first
6829 # tab in it
6830 if (! $self->drawNotebook()) {
6831  
6832 return $self->writeWarning(
6833 'General error adding a tab',
6834 $self->_objClass . '->addTab',
6835 );
6836 }
6837 }
6838 }
6839  
6840 # Create the tab
6841  
6842 # The tab contains a vertical packing box, which contains everything else
6843 my $vBox = Gtk3::VBox->new(FALSE, 0);
6844 $vBox->set_border_width(0);
6845  
6846 # A horizontal packing box is used as the tab's label (in place of a Gtk3::Label)
6847 my $hBox = Gtk3::HBox->new(FALSE, 0);
6848 my $label = Gtk3::Label->new();
6849 $hBox->pack_start($label, FALSE, FALSE, 0);
6850 $label->show();
6851  
6852 # Add an 'X' button to close the tab, if required
6853 my $button;
6854 if ($self->canCloseFlag) {
6855  
6856 $button = Gtk3::Button->new();
6857 $hBox->pack_start($button, FALSE, FALSE, 0);
6858 $button->set_image(Gtk3::Image->new_from_stock('gtk-close', 'menu'));
6859 $button->set_relief('none');
6860 $button->show();
6861 }
6862  
6863 # Create a new GA::Obj::Textview object to handle the Gtk3::Textview(s)
6864 $textViewObj = $axmud::CLIENT->desktopObj->add_textView(
6865 $session,
6866 $self->winObj,
6867 $self,
6868 );
6869  
6870 if (! $textViewObj) {
6871  
6872 return undef;
6873 }
6874  
6875 # Set the colour scheme to use
6876 if (
6877 ! defined $colourScheme
6878 || ! $axmud::CLIENT->ivExists('colourSchemeHash', $colourScheme)
6879 ) {
6880 $colourScheme = $self->ivShow('initHash', 'colour_scheme');
6881 }
6882  
6883 # Create the Gtk3::TextView(s) themselves. The function call returns a Gtk3::ScrolledWindow
6884 # or a Gtk3::VPaned containing the textview(s)
6885 $packedObj = $textViewObj->objEnable(
6886 $self->ivShow('initHash', 'split_mode'),
6887 $colourScheme,
6888 $self->ivShow('initHash', 'max_lines'),
6889 $self->ivShow('initHash', 'new_line'),
6890 $oldBuffer,
6891 );
6892  
6893 if (! $packedObj) {
6894  
6895 $textViewObj->objDestroy();
6896 return undef;
6897 }
6898  
6899 # Pack the Gtk3::ScrolledWindow/Gtk3::VPaned into this tab's Gtk3::VBox
6900 $vBox->pack_start($packedObj, TRUE, TRUE, 0);
6901  
6902 # From Gtk documentation: 'Note that due to historical reasons, GtkNotebook refuses to
6903 # switch to a page unless the child widget is visible. Therefore, it is recommended to
6904 # show child widgets before adding them to a notebook.'
6905 $vBox->show();
6906 $hBox->show();
6907  
6908 # Add the tab to the notebook
6909 my $tabNum = $self->notebook->append_page($vBox, $hBox);
6910  
6911 # Make the tab re-orderable
6912 my $tabWidget = $self->notebook->get_nth_page($tabNum);
6913 $self->notebook->set_tab_reorderable($tabWidget, TRUE);
6914  
6915 # If no label text was specified, use the default text
6916 if (! defined $labelText) {
6917  
6918 $labelText = 'Tab #' . $tabNum;
6919 }
6920  
6921 $label->set_markup($labelText);
6922  
6923 # Create a tab object to store details about the tab
6924 $tabObj = Games::Axmud::Obj::Tab->new(
6925 $self->tabObjCount, # ->number
6926 $self,
6927 $session,
6928 $defaultFlag,
6929 $textViewObj,
6930 $vBox, # ->packableObj
6931 $packedObj, # ->packedObj
6932 $vBox, # ->tabWidget
6933 $label, # ->tabLabel
6934 );
6935  
6936 # Update IVs
6937 $self->ivAdd('tabObjHash', $tabObj->number, $tabObj);
6938 $self->ivIncrement('tabObjCount');
6939  
6940 # The new tab should be the visible (current) one
6941 # NB When replacing a standalone textview object with a Gtk3::Notebook, adding the old
6942 # textview object's buffer to the new notebook's first tab, we don't set the first tab as
6943 # the current page - because the calling function wants to set the (new) second tab as the
6944 # current page
6945 if (! $oldBuffer) {
6946  
6947 $self->notebook->set_current_page($tabNum);
6948 }
6949  
6950 # After replacing a standalone textview object with a Gtk3::Notebook, the original session's
6951 # textview(s) don't scroll to the bottom (as it should) without this code (and placing the
6952 # code anywhere else doesn't work, either)
6953 if ($oldBuffer) {
6954  
6955 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->addTab');
6956 }
6957  
6958 # Set up ->signal_connects for the close button, if it was created
6959 if ($button) {
6960  
6961 if (! $defaultFlag) {
6962 $self->setButtonClicked($button, $tabObj);
6963 } else {
6964 $self->setButtonClicked($button, $tabObj, $session);
6965 }
6966 }
6967  
6968 # Make the changes visible
6969 $self->winObj->winShowAll($self->_objClass . '->addTab');
6970  
6971 # The new tab is the visible tab. The call above to ->set_current_page ought to have
6972 # caused a call to $self->respondVisibleTab, but if $sessionFlag is set, call it again,
6973 # forcing it to call GA::Win::Internal->setVisibleSession at least once
6974 if ($sessionFlag) {
6975  
6976 $self->respondVisibleTab($tabObj, $sessionFlag);
6977 }
6978  
6979 return $tabObj;
6980 }
6981  
6982 sub removeSessionTab {
6983  
6984 # Called by GA::Session->stop (only)
6985 # Removes the tab containing the default textview object for the calling session (if other
6986 # parts of the code want to remove a non-default tab, they should call
6987 # $self->removeTabNum)
6988 # After removing the tab, if there is then only a single session open, and if the
6989 # initialisation setting demands that we use a simple tab rather than a Gtk3::Notebook
6990 # tab, replace the notebook with a simple tab
6991 #
6992 # Expected arguments
6993 # $session - The GA::Session for the tab to be removed
6994 #
6995 # Return values
6996 # 'undef' on improper arguments, or if the tab widgets can't be removed or if the
6997 # session's default tab can't be found
6998 # 1 on success
6999  
7000 my ($self, $session, $check) = @_;
7001  
7002 # Local variables
7003 my ($tabObj, $count, $newTabObj);
7004  
7005 # Check for improper arguments
7006 if (! defined $session || defined $check) {
7007  
7008 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeTab', @_);
7009 }
7010  
7011 if (! $self->notebook) {
7012  
7013 # A simple tab, containing a standalone textview object
7014 $tabObj = $self->ivShow('tabObjHash', 0);
7015 if (! $tabObj || ! $tabObj->defaultFlag || $tabObj->session ne $session) {
7016  
7017 # (Error message displayed by calling function)
7018 return undef;
7019 }
7020  
7021 # Remove the simple tab by removing everything from the main packing box
7022 $axmud::CLIENT->desktopObj->removeWidget($self->packingBox2, $tabObj->packedObj);
7023 # Inform the textview object (if any) of its demise
7024 if ($tabObj->textViewObj) {
7025  
7026 $tabObj->textViewObj->objDestroy();
7027 }
7028  
7029 # Update IVs
7030 $self->ivEmpty('tabObjHash');
7031 $self->ivPoke('tabObjCount', 0);
7032  
7033 } else {
7034  
7035 # A tab in a Gtk3::Notebook. Find which one corresponds to the session
7036 $tabObj = $self->findSession($session);
7037 if (! defined $tabObj) {
7038  
7039 # (Error message displayed by calling function)
7040 return undef;
7041 }
7042  
7043 # Remove the tab from its Gtk3::Notebook
7044 $self->notebook->remove_page($self->notebook->page_num($tabObj->tabWidget));
7045 # Inform the textview object (if any) of its demise
7046 if ($tabObj->textViewObj) {
7047  
7048 $tabObj->textViewObj->objDestroy();
7049 }
7050  
7051 # Update IVs
7052 $self->ivDelete('tabObjHash', $tabObj->number);
7053  
7054 # If there is only one tab left, and the first tab created (since the pane was last
7055 # empty of tabs) was a simple tab, convert a normal tab into a simple tab
7056 $count = $self->ivPairs('tabObjHash');
7057 if ($count == 1 && $self->simpleTabFlag) {
7058  
7059 if (! $self->convertTab()) {
7060  
7061 # (Error message already displayed)
7062 return undef;
7063 }
7064  
7065 # If there are no tabs left, remove the notebook itself, so the next tab to be added can
7066 # be a simple or normal tab
7067 } elsif (! $count) {
7068  
7069 $axmud::CLIENT->desktopObj->removeWidget($self->packingBox2, $self->notebook);
7070  
7071 $self->ivUndef('notebook');
7072 }
7073 }
7074  
7075 # If there are no tabs left, the calling code can create a simple tab or a normal tab
7076 if (! $self->tabObjHash) {
7077  
7078 $self->ivPoke('simpleTabFlag', FALSE);
7079 }
7080  
7081 # Make the changes visible
7082 $self->winObj->winShowAll($self->_objClass . '->removeTab');
7083  
7084 return 1;
7085 }
7086  
7087 sub removeTab {
7088  
7089 # Called by callback in $self->setButtonClicked (only)
7090 # Removes the specified tab
7091 #
7092 # Expected arguments
7093 # $tabObj - The GA::Obj::Tab to remove
7094 #
7095 # Return values
7096 # 'undef' on improper arguments, or if the specified tab doesn't exist
7097 # 1 on success
7098  
7099 my ($self, $tabObj, $check) = @_;
7100  
7101 # Local variables
7102 my ($count, $funcRef);
7103  
7104 # Check for improper arguments
7105 if (! defined $tabObj || defined $check) {
7106  
7107 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeTab', @_);
7108 }
7109  
7110 # Check the tab exists
7111 if (! $self->ivExists('tabObjHash', $tabObj->number)) {
7112  
7113 return undef;
7114 }
7115  
7116 # Remove the tab
7117 if (! $self->notebook) {
7118  
7119 # A simple tab, containing a standalone textview object
7120  
7121 # Remove the simple tab by removing everything from the main packing box
7122 $axmud::CLIENT->desktopObj->removeWidget($self->packingBox2, $tabObj->packedObj);
7123 # Inform the textview object (if any) of its demise
7124 if ($tabObj->textViewObj) {
7125  
7126 $tabObj->textViewObj->objDestroy();
7127 }
7128  
7129 # Update IVs
7130 $self->ivEmpty('tabObjHash');
7131 $self->ivPoke('tabObjCount', 0);
7132  
7133 } else {
7134  
7135 # A tab in a Gtk3::Notebook
7136  
7137 # Remove the tab from its Gtk3::Notebook
7138 $self->notebook->remove_page($self->notebook->page_num($tabObj->tabWidget));
7139 # Inform the textview object (if any) of its demise
7140 if ($tabObj->textViewObj) {
7141  
7142 $tabObj->textViewObj->objDestroy();
7143 }
7144  
7145 # Update IVs
7146 $self->ivDelete('tabObjHash', $tabObj->number);
7147  
7148 # If there is only one tab left, and the first tab created (since the pane was last
7149 # empty of tabs) was a simple tab, convert a normal tab into a simple tab
7150 $count = $self->ivPairs('tabObjHash');
7151 if ($count == 1 && $self->simpleTabFlag) {
7152  
7153 if (! $self->convertTab()) {
7154  
7155 # (Error message already displayed)
7156 return undef;
7157 }
7158  
7159 # If there are no tabs left, remove the notebook itself, so the next tab to be added can
7160 # be a simple or normal tab
7161 } elsif (! $count) {
7162  
7163 $axmud::CLIENT->desktopObj->removeWidget($self->packingBox2, $self->notebook);
7164  
7165 $self->ivUndef('notebook');
7166 }
7167 }
7168  
7169 # If there are no tabs left, the calling code can create a simple tab or a normal tab
7170 if (! $self->tabObjHash) {
7171  
7172 $self->ivPoke('simpleTabFlag', FALSE);
7173 }
7174  
7175 # Inform any code that wants to be informed when the tab changes
7176 if ($self->closeFuncRef) {
7177  
7178 $funcRef = $self->closeFuncRef;
7179 &$funcRef($self, $tabObj, $self->closeFuncID);
7180 }
7181  
7182 # Make the changes visible
7183 $self->winObj->winShowAll($self->_objClass . '->removeTab');
7184  
7185 return 1;
7186 }
7187  
7188 sub convertSimpleTab {
7189  
7190 # Called by $self->addTab, when a simple tab is currently visible
7191 #
7192 # Converts the standalone textview object (a simple tab) into a new tab on a Gtk3::Notebook,
7193 # preserving the Gtk3::TextBuffer
7194 #
7195 # Expected arguments
7196 # (none besides $self)
7197 #
7198 # Return values
7199 # 'undef' on improper arguments or if there's an error
7200 # 1 on success
7201  
7202 my ($self, $check) = @_;
7203  
7204 # Local variables
7205 my ($oldTabObj, $newTabObj, $notebook, $oldLabelText);
7206  
7207 # Check for improper arguments
7208 if (defined $check) {
7209  
7210 return $axmud::CLIENT->writeImproper($self->_objClass . '->convertSimpleTab', @_);
7211 }
7212  
7213 # Set a flag that various ->signal_connects can use to avoid responding when a tab
7214 # conversion operation is in progress
7215 $self->ivPoke('tabConvertFlag', TRUE);
7216  
7217 # Get the single existing tab
7218 $oldTabObj = $self->ivShow('tabObjHash', 0);
7219  
7220 # Remove the standalone textview object
7221 $axmud::CLIENT->desktopObj->removeWidget($self->packingBox2, $oldTabObj->packedObj);
7222  
7223 # Add a Gtk3::Notebook in its place
7224 $notebook = $self->drawNotebook();
7225 if (! $notebook) {
7226  
7227 # Emergency fallback - put the old textview back, as if nothing had happened (but show a
7228 # warning)
7229 $self->packingBox2->pack_start($oldTabObj->packedObj, TRUE, TRUE, 0);
7230  
7231 return $self->writeWarning(
7232 'General error converting simple tab',
7233 $self->_objClass . '->convertSimpleTab',
7234 );
7235 }
7236  
7237 # Update IVs
7238 $self->ivEmpty('tabObjHash');
7239 $self->ivPoke('tabObjCount', 0);
7240  
7241 # Add a tab in its place, using the old textview object's buffer and the old session number
7242 if ($oldTabObj->defaultFlag) {
7243  
7244 $oldLabelText = $oldTabObj->session->getTabLabelText();
7245 }
7246  
7247 $newTabObj = $self->addTab(
7248 $oldTabObj->session,
7249 $oldTabObj->textViewObj->colourScheme,
7250 undef, # Not called by GA::Session->setDefaultTab
7251 $oldTabObj->defaultFlag,
7252 $oldLabelText,
7253 $oldTabObj->textViewObj->buffer,
7254 );
7255  
7256 # Restore the scroll lock, if it was enabled in the old single textview
7257 if ($oldTabObj->textViewObj->scrollLockFlag) {
7258  
7259 $newTabObj->textViewObj->toggleScrollLock();
7260 }
7261  
7262 # Restore the old single textview's split screen mode
7263 $newTabObj->textViewObj->setSplitScreenMode($oldTabObj->textViewObj->splitScreenMode);
7264  
7265 # Update the GA::Session's tab IVs, as required
7266 if (
7267 $oldTabObj->session->defaultTabObj
7268 && $oldTabObj->session->defaultTabObj eq $oldTabObj
7269 ) {
7270 $oldTabObj->session->set_defaultTabObj($newTabObj);
7271 }
7272  
7273 if (
7274 $oldTabObj->session->currentTabObj
7275 && $oldTabObj->session->currentTabObj eq $oldTabObj
7276 ) {
7277 $oldTabObj->session->set_currentTabObj($newTabObj);
7278 }
7279  
7280 # Operation complete
7281 $self->ivPoke('tabConvertFlag', FALSE);
7282  
7283 return 1;
7284 }
7285  
7286 sub convertTab {
7287  
7288 # Called by $self->removeSessionTab or ->removeTab when there's only a single Gtk3::Notebook
7289 # tab left, and the initialisation setting specifies that a tab label shouldn't be visible
7290 # Converts the Gtk3::Notebook containing a single remaining tab into a standalone textview
7291 # object, preserving its Gtk3::TextBuffer (a simple tab)
7292 #
7293 # Expected arguments
7294 # (none besides $self)
7295 #
7296 # Return values
7297 # 'undef' on improper arguments or if there's an error
7298 # 1 on success
7299  
7300 my ($self, $tabObj, $check) = @_;
7301  
7302 # Local variables
7303 my ($oldTabObj, $scroll, $newTabObj, $oldLabelText);
7304  
7305 # Check for improper arguments
7306 if (defined $check) {
7307  
7308 return $axmud::CLIENT->writeImproper($self->_objClass . '->convertTab', @_);
7309 }
7310  
7311 # Set a flag that various ->signal_connects can use to avoid responding when a tab
7312 # conversion operation is in progress
7313 $self->ivPoke('tabConvertFlag', TRUE);
7314  
7315 # Get the single remaining tab (the calling function has already checked there is only one)
7316 ($oldTabObj) = $self->ivValues('tabObjHash');
7317 if (! $oldTabObj) {
7318  
7319 return $self->writeWarning(
7320 'General error converting tab',
7321 $self->_objClass . '->convertTab',
7322 );
7323 }
7324  
7325 # Remove the Gtk3::Notebook
7326 $axmud::CLIENT->desktopObj->removeWidget($self->packingBox2, $self->notebook);
7327  
7328 # v1.1.128 This is not necessary, and in fact messes up everything
7329 # # Replace it with a standalone textview object
7330 # $axmud::CLIENT->desktopObj->removeWidget($oldTabObj->packableObj, $oldTabObj->packedObj);
7331 # $self->packingBox2->pack_start($oldTabObj->packedObj, TRUE, TRUE, 0);
7332  
7333 # Update IVs
7334 $self->ivUndef('notebook');
7335 $self->ivEmpty('tabObjHash');
7336 $self->ivPoke('tabObjCount', 0);
7337  
7338 # Add a simple tab, using the old tab's buffer and the old session
7339 if ($oldTabObj->defaultFlag) {
7340  
7341 $oldLabelText = $oldTabObj->session->getTabLabelText();
7342 }
7343  
7344 $newTabObj = $self->addSimpleTab(
7345 $oldTabObj->session,
7346 $oldTabObj->textViewObj->colourScheme,
7347 undef, # Not called by GA::Session->setDefaultTab
7348 $oldTabObj->defaultFlag,
7349 $oldLabelText,
7350 $oldTabObj->textViewObj->buffer,
7351 );
7352  
7353 # Restore the scroll lock, if it was enabled in the old single textview
7354 if ($oldTabObj->textViewObj->scrollLockFlag) {
7355  
7356 $newTabObj->textViewObj->toggleScrollLock();
7357 }
7358  
7359 # Restore the old single textview's split screen mode
7360 $newTabObj->textViewObj->setSplitScreenMode($oldTabObj->textViewObj->splitScreenMode);
7361  
7362 # Update the GA::Session's tab IVs, as required
7363 if (
7364 $oldTabObj->session->defaultTabObj
7365 && $oldTabObj->session->defaultTabObj eq $oldTabObj
7366 ) {
7367 $oldTabObj->session->set_defaultTabObj($newTabObj);
7368 }
7369  
7370 if (
7371 $oldTabObj->session->currentTabObj
7372 && $oldTabObj->session->currentTabObj eq $oldTabObj
7373 ) {
7374 $oldTabObj->session->set_currentTabObj($newTabObj);
7375 }
7376  
7377 # Operation complete
7378 $self->ivPoke('tabConvertFlag', FALSE);
7379  
7380 return 1;
7381 }
7382  
7383 sub updateColourScheme {
7384  
7385 # Called by GA::Win::Internal->updateColourScheme (only)
7386 # When a colour scheme is modified, checks all textview objects in this pane object and
7387 # updates any that use the modified colour scheme. Alternatively, when no colour scheme is
7388 # specified, updates all textview objects
7389 #
7390 # Expected arguments
7391 # (none besides $self)
7392 #
7393 # Optional arguments
7394 # $colourScheme - The name of the modified colour scheme (matches a key in
7395 # GA::Client->colourSchemeHash; the calling function has already
7396 # checked it is valid). If 'undef', all pane objects are updated
7397 # $noDrawFlag - TRUE when the calling function was itself called by
7398 # GA::Win::Internal->redrawWidgets, which doesn't want this function
7399 # to call GA::Win::Generic->winShowAll or
7400 # GA::Obj::Desktop->updateWidgets as it normally would. FALSE (or
7401 # 'undef') otherwise
7402 #
7403 # Return values
7404 # 'undef' on improper arguments
7405 # 1 on success
7406  
7407 my ($self, $colourScheme, $noDrawFlag, $check) = @_;
7408  
7409 # Check for improper arguments
7410 if (defined $check) {
7411  
7412 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateColourScheme', @_);
7413 }
7414  
7415 # Update each tab in turn
7416 OUTER: foreach my $tabObj ($self->ivValues('tabObjHash')) {
7417  
7418 my $packedObj;
7419  
7420 if (! $colourScheme || $tabObj->textViewObj->colourScheme eq $colourScheme) {
7421  
7422 $tabObj->textViewObj->objUpdate($colourScheme);
7423 }
7424 }
7425  
7426 return 1;
7427 }
7428  
7429 sub applyColourScheme {
7430  
7431 # Can be called by anything to apply a new colour scheme to one or more of this pane
7432 # object's tabs (in contrast to $self->updateColourScheme, which is only called by
7433 # GA::Win::Internal->winUpdate and applies a modified colour scheme to any textview
7434 # object that uses it)
7435 #
7436 # Expected arguments
7437 # (none besides $self)
7438 #
7439 # Optional arguments
7440 # $tabObj - The tab object (GA::Obj::Tab) containing the textview object to which
7441 # the colour scheme must be applied. If 'undef', the colour scheme is
7442 # applied to all tabs in this pane object
7443 # $colourScheme - The name of the colour scheme to apply (matches a key in
7444 # GA::Client->colourSchemeHash). If unrecognised or 'undef', a default
7445 # colour scheme for the parent window is applied to the textview
7446 #
7447 # Return values
7448 # 'undef' on improper arguments or if there's an error
7449 # 1 on success
7450  
7451 my ($self, $tabObj, $colourScheme, $check) = @_;
7452  
7453 # Local variables
7454 my @tabList;
7455  
7456 # Check for improper arguments
7457 if (defined $check) {
7458  
7459 return $axmud::CLIENT->writeImproper($self->_objClass . '->applyColourScheme', @_);
7460 }
7461  
7462 # Compile a list of tabs whose textview objects should be modified
7463 if ($tabObj) {
7464 push (@tabList, $tabObj);
7465 } else {
7466 push (@tabList, $self->ivValues('tabObjHash'));
7467 }
7468  
7469 # Set the colour scheme to use, if a valid one wasn't specified
7470 if (
7471 ! defined $colourScheme
7472 || ! $axmud::CLIENT->ivExists('colourSchemeHash', $colourScheme)
7473 ) {
7474 $colourScheme = $self->winObj->winType;
7475 }
7476  
7477 # Apply the colour scheme
7478 foreach my $thisTabObj (@tabList) {
7479  
7480 $thisTabObj->textViewObj->objUpdate($colourScheme);
7481 }
7482  
7483 return 1;
7484 }
7485  
7486 sub applyMonochrome {
7487  
7488 # Can be called by anything to switch on monochrome mode for one or more of the tabs in this
7489 # pane object (or, for any tabs already in monochrome mode, to change the colour used)
7490 #
7491 # Expected arguments
7492 # (none besides $self)
7493 #
7494 # Optional arguments
7495 # $tabObj - The tab object (GA::Obj::Tab) containing the textview object whose monochrome
7496 # mode must be switched on. If 'undef', monochrome mode is switched on for
7497 # all tabs in this pane object
7498 # $backgroundColour
7499 # - The background colour to use (can be any Axmud colour tag, e.g 'red'). If it's
7500 # an underlay tag like 'ul_red', the equivalent colour tag is used instead. If
7501 # 'undef', the tab's current colour scheme (set by a call to
7502 # $self->applyColourScheme) is used to select a background colour
7503 # $textColour
7504 # - The text colour to use. Is normally 'undef', in which case this function will
7505 # choose a suitable text colour to match the background. Should be specified
7506 # if $backgroundColour is an Xterm or RGB colour tag, otherwise the text
7507 # colour might not suit the background colour
7508 #
7509 # Return values
7510 # 'undef' on improper arguments or if there's an error
7511 # 1 on success
7512  
7513 my ($self, $tabObj, $backgroundColour, $textColour, $check) = @_;
7514  
7515 # Local variables
7516 my (
7517 $type,
7518 @tabList,
7519 );
7520  
7521 # Check for improper arguments
7522 if (defined $check) {
7523  
7524 return $axmud::CLIENT->writeImproper($self->_objClass . '->applyMonochrome', @_);
7525 }
7526  
7527 # Compile a list of tabs whose textview objects should be modified
7528 if ($tabObj) {
7529 push (@tabList, $tabObj);
7530 } else {
7531 push (@tabList, $self->ivValues('tabObjHash'));
7532 }
7533  
7534 # If colours were specified, check they are valid
7535 if (defined $backgroundColour) {
7536  
7537 ($type) = defined $axmud::CLIENT->checkColourTags($backgroundColour);
7538 if (! $type) {
7539  
7540 return undef;
7541 }
7542  
7543 } elsif (defined $textColour) {
7544  
7545 ($type) = defined $axmud::CLIENT->checkColourTags($textColour);
7546 if (! $type) {
7547  
7548 return undef;
7549 }
7550 }
7551  
7552 # Switch on monochrome mode for the specified tab(s)
7553 foreach my $thisTabObj (@tabList) {
7554  
7555 $thisTabObj->textViewObj->setMonochromeMode($backgroundColour, $textColour);
7556 }
7557  
7558 return 1;
7559 }
7560  
7561 sub removeMonochrome {
7562  
7563 # Can be called by anything to switch off monochrome mode for one or more of the tabs in
7564 # this pane object
7565 #
7566 # Expected arguments
7567 # (none besides $self)
7568 #
7569 # Optional arguments
7570 # $tabObj - The tab object (GA::Obj::Tab) containing the textview object whose monochrome
7571 # mode must be switched off. If 'undef', monochrome mode is switched off for
7572 # all tabs in this pane object
7573 #
7574 # Return values
7575 # 'undef' on improper arguments or if there's an error
7576 # 1 on success
7577  
7578 my ($self, $tabObj, $check) = @_;
7579  
7580 # Local variables
7581 my @tabList;
7582  
7583 # Check for improper arguments
7584 if (defined $check) {
7585  
7586 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeMonochrome', @_);
7587 }
7588  
7589 # Compile a list of tabs whose textview objects should be modified
7590 if ($tabObj) {
7591 push (@tabList, $tabObj);
7592 } else {
7593 push (@tabList, $self->ivValues('tabObjHash'));
7594 }
7595  
7596 # Switch off monochrome mode for the specified tab(s)
7597 foreach my $thisTabObj (@tabList) {
7598  
7599 $thisTabObj->textViewObj->resetMonochromeMode();
7600 }
7601  
7602 return 1;
7603 }
7604  
7605 sub toggleScrollLock {
7606  
7607 # Called by GA::Cmd::ScrollLock->do or GA::Strip::Entry->setScrollSignals
7608 # Toggles the scroll lock in the active textview object
7609 #
7610 # Expected arguments
7611 # (none besides $self)
7612 #
7613 # Return values
7614 # 'undef' on improper arguments or if the toggle operation fails
7615 # 1 on success
7616  
7617 my ($self, $check) = @_;
7618  
7619 # Local variables
7620 my ($tabObj, $entryObj);
7621  
7622 # Check for improper arguments
7623 if (defined $check) {
7624  
7625 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleScrollLock', @_);
7626 }
7627  
7628 # Get the visible tab's tab object
7629 if (! $self->notebook) {
7630 $tabObj = $self->ivShow('tabObjHash', 0);
7631 } else {
7632 $tabObj = $self->ivShow('tabObjHash', $self->notebook->get_current_page());
7633 }
7634  
7635 if (! $tabObj || ! $tabObj->textViewObj) {
7636  
7637 return undef;
7638 }
7639  
7640 # Toggle scroll lock
7641 $tabObj->textViewObj->toggleScrollLock();
7642  
7643 # Find the entry strip object (if it exists)
7644 $entryObj = $self->winObj->ivShow('firstStripHash', 'Games::Axmud::Strip::Entry');
7645 if ($entryObj) {
7646  
7647 # Update the toolbutton icon for its scroll lock button
7648 $entryObj->updateScrollButton($tabObj->textViewObj->scrollLockFlag);
7649 }
7650  
7651 $self->winObj->winShowAll($self->_objClass . '->toggleScrollLock');
7652  
7653 return 1;
7654 }
7655  
7656 sub toggleSplitScreen {
7657  
7658 # Called by GA::Cmd::SplitScreen->do or GA::Strip::Entry->setSplitSignals
7659 # Toggles between split screen modes in the active textview object
7660 #
7661 # Before v1.0.905, textview objects had two split screen modes, 'on' and 'off'. Since then,
7662 # textview objects have had three modes, but pane objects continue to distinguish only
7663 # between 'on' and 'off'
7664 # The textview object modes 'single' and 'hidden' are considered 'off', and this function
7665 # converts them to 'split'
7666 # The textview object mode 'split' is considered 'off', and this function converts it to
7667 # 'hidden'
7668 # In this way, for textview objects created by a pane object, split screen mode is only
7669 # 'single' when the textview object is created with that mode set. Once the mode is
7670 # changed (by this function), it cannot be restored to 'single' (by this function)
7671 #
7672 # This change has been made because of Gtk3 performance issues, particularly with
7673 # Gtk3::TextViews with large buffers. In general, any pane in which split screen mode
7674 # might be turned 'on' should probably create the textview object using the mode 'hidden'
7675 # rather than 'single'
7676 #
7677 # Expected arguments
7678 # (none besides $self)
7679 #
7680 # Return values
7681 # 'undef' on improper arguments or if the toggle operation fails
7682 # 1 on success
7683  
7684 my ($self, $check) = @_;
7685  
7686 # Local variables
7687 my ($tabObj, $packedObj, $viewport, $entryObj);
7688  
7689 # Check for improper arguments
7690 if (defined $check) {
7691  
7692 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleSplitScreen', @_);
7693 }
7694  
7695 # Get the visible tab's tab object
7696 if (! $self->notebook) {
7697 $tabObj = $self->ivShow('tabObjHash', 0);
7698 } else {
7699 $tabObj = $self->ivShow('tabObjHash', $self->notebook->get_current_page());
7700 }
7701  
7702 if (! $tabObj || ! $tabObj->textViewObj) {
7703  
7704 return undef;
7705 }
7706  
7707 # Get a new packable widget
7708 if (
7709 $tabObj->textViewObj->splitScreenMode eq 'single'
7710 || $tabObj->textViewObj->splitScreenMode eq 'hidden'
7711 ) {
7712 $packedObj = $tabObj->textViewObj->setSplitScreenMode('split');
7713 } else {
7714 $packedObj = $tabObj->textViewObj->setSplitScreenMode('hidden');
7715 }
7716  
7717 # If $packedObj is defined, it must be re-packed, replacing the old packable widget
7718 if ($packedObj) {
7719  
7720 $axmud::CLIENT->desktopObj->removeWidget($tabObj->packableObj, $tabObj->packedObj);
7721 $tabObj->packableObj->pack_start($packedObj, TRUE, TRUE, 0);
7722 $tabObj->ivPoke('packedObj', $packedObj);
7723 }
7724  
7725 # Find the entry strip object (if it exists)
7726 $entryObj = $self->winObj->ivShow('firstStripHash', 'Games::Axmud::Strip::Entry');
7727 if ($entryObj) {
7728  
7729 # Update the toolbutton icon for its scroll lock button
7730 if ($tabObj->textViewObj->splitScreenMode eq 'split') {
7731 $entryObj->updateSplitButton(TRUE);
7732 } else {
7733 $entryObj->updateSplitButton(FALSE);
7734 }
7735 }
7736  
7737 if ($packedObj) {
7738  
7739 # (If we try to scroll the textviews before they've been re-packed, we get an
7740 # uncomfortable flash, so the scrolling function is called last)
7741 $self->winObj->winShowAll($self->_objClass . '->toggleSplitScreen');
7742 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->toggleSplitScreen');
7743 $tabObj->textViewObj->scrollToLock();
7744 }
7745  
7746 return 1;
7747 }
7748  
7749 sub findPage {
7750  
7751 # Can be called by anything
7752 # Finds the tab object (GA::Obj::Tab) corresponding to a specified page in the
7753 # Gtk3::Notebook, when normal tabs (not simple tabs) are visible
7754 # If there is a simple tab visible and the specified page is 0, return it
7755 #
7756 # Expected arguments
7757 # $page - The tab's current page number in the notebook (0 for the first tab, 1
7758 # for the second, etc)
7759 #
7760 # Return values
7761 # 'undef' on improper arguments or if a matching tab object doesn't exist
7762 # Otherwise, returns the tab object
7763  
7764 my ($self, $page, $check) = @_;
7765  
7766 # Check for improper arguments
7767 if (! defined $page || defined $check) {
7768  
7769 return $axmud::CLIENT->writeImproper($self->_objClass . '->findPage', @_);
7770 }
7771  
7772 # If there is a simple tab visible and the specified page is 0, return it
7773 if (! $self->notebook) {
7774  
7775 if ($page == 0) {
7776 return $self->ivShow('tabObjHash', 0);
7777 } else {
7778 return undef;
7779 }
7780 }
7781  
7782 # Otherwise, check each tab in turn until we find the right page number
7783 foreach my $tabObj ($self->ivValues('tabObjHash')) {
7784  
7785 my $num = $self->notebook->page_num($tabObj->tabWidget);
7786 if ($num == $page) {
7787  
7788 return $tabObj;
7789 }
7790 }
7791  
7792 # Corresponding tab object not found
7793 return undef;
7794 }
7795  
7796 sub findSession {
7797  
7798 # Can be called by anything
7799 # Finds the tab object (GA::Obj::Tab) for the tab/simple tab which contains the specified
7800 # session's default textview object (GA::Obj::TextView)
7801 #
7802 # Expected arguments
7803 # $session - The GA::Session whose tab we want to find
7804 #
7805 # Return values
7806 # 'undef' on improper arguments or if a matching tab object doesn't exist
7807 # Otherwise, returns the tab object
7808  
7809 my ($self, $session, $check) = @_;
7810  
7811 # Check for improper arguments
7812 if (! defined $session || defined $check) {
7813  
7814 return $axmud::CLIENT->writeImproper($self->_objClass . '->findSession', @_);
7815 }
7816  
7817 # No session should have more than one tab. Nevertheless, search tabs in ascending order and
7818 # return the first one matching the specified session
7819 foreach my $tabObj (sort {$a->number <=> $b->number} ($self->ivValues('tabObjHash'))) {
7820  
7821 if ($tabObj->defaultFlag && $tabObj->session && $tabObj->session eq $session) {
7822  
7823 return $tabObj;
7824 }
7825 }
7826  
7827 # No tab matching the specified session found
7828 return undef;
7829 }
7830  
7831 sub findTextView {
7832  
7833 # Can be called by anything
7834 # Finds the tab object (GA::Obj::Tab) for the tab/simple tab which uses the specified
7835 # textview object
7836 #
7837 # Expected arguments
7838 # $textViewObj - The GA::Obj::Textview whose tab we want to find
7839 #
7840 # Return values
7841 # 'undef' on improper arguments or if no tab uses the specified textview object
7842 # Otherwise, returns the tab object
7843  
7844 my ($self, $textViewObj, $check) = @_;
7845  
7846 # Check for improper arguments
7847 if (! defined $textViewObj || defined $check) {
7848  
7849 return $axmud::CLIENT->writeImproper($self->_objClass . '->findTextView', @_);
7850 }
7851  
7852 # No textview object should be used by more than one tab. Nevertheless, search tabs in
7853 # ascending order and return the first one matching the specified textview object
7854 foreach my $tabObj (sort {$a->number <=> $b->number} ($self->ivValues('tabObjHash'))) {
7855  
7856 if ($tabObj->textViewObj && $tabObj->textViewObj eq $textViewObj) {
7857  
7858 return $tabObj;
7859 }
7860 }
7861  
7862 # No tab matching using the specified textview object found
7863 return undef;
7864 }
7865  
7866 sub getVisibleTab {
7867  
7868 # Can be called by anything
7869 # Finds the visible tab and returns its corresponding GA::Obj::Tab object
7870 #
7871 # Expected arguments
7872 # (none besides $self)
7873 #
7874 # Return values
7875 # 'undef' on improper arguments or if there is no visible tab
7876 # Otherwise returns the visible tab's tab object
7877  
7878 my ($self, $check) = @_;
7879  
7880 # Check for improper arguments
7881 if (defined $check) {
7882  
7883 return $axmud::CLIENT->writeImproper($self->_objClass . '->getVisibleTab', @_);
7884 }
7885  
7886 if (! $self->notebook) {
7887  
7888 return $self->ivShow('tabObjHash', 0);
7889  
7890 } else {
7891  
7892 return $self->findPage($self->notebook->get_current_page());
7893 }
7894 }
7895  
7896 sub setVisibleTab {
7897  
7898 # Can be called by anything
7899 # Sets the visible tab (unless the tab is already the visible one, in which case nothing
7900 # happens)
7901 #
7902 # Expected arguments
7903 # $tabObj - The new visible tab's GA::Obj::Tab
7904 #
7905 # Return values
7906 # 'undef' on improper arguments or if the tab object doesn't exist
7907 # Otherwise returns $tabObj to show the new visible tab
7908  
7909 my ($self, $tabObj, $check) = @_;
7910  
7911 # Check for improper arguments
7912 if (! defined $tabObj || defined $check) {
7913  
7914 return $axmud::CLIENT->writeImproper($self->_objClass . '->setVisibleTab', @_);
7915 }
7916  
7917 # Check the tab still exists
7918 if (! $self->ivShow('tabObjHash', $tabObj->number)) {
7919  
7920 return undef;
7921 }
7922  
7923 # If a simple tab exists, it is the only tab that exists, so it's already the visible one
7924 if ($self->notebook) {
7925  
7926 $self->notebook->set_current_page($self->notebook->page_num($tabObj->tabWidget));
7927 }
7928  
7929 return $tabObj;
7930 }
7931  
7932 sub switchVisibleTab {
7933  
7934 # Called by GA::Win::Internal->setKeyPressEvent when the user presses the 'tab' key
7935 # Switches to the next tab (moving from left to right). If we're already at the right-most
7936 # tab, switches to the first tab
7937 #
7938 # Expected arguments
7939 # (none besides $self)
7940 #
7941 # Return values
7942 # 'undef' on improper arguments or if there's an error
7943 # Otherwise, returns the tab object for the new tab
7944  
7945 my ($self, $check) = @_;
7946  
7947 # Local variables
7948 my ($currentPage, $tabCount, $nextPage);
7949  
7950 # Check for improper arguments
7951 if (defined $check) {
7952  
7953 return $axmud::CLIENT->writeImproper($self->_objClass . '->switchVisibleTab', @_);
7954 }
7955  
7956 # Deal with simple tabs first, for which the tab can't be switched
7957 if (! $self->notebook) {
7958  
7959 return $self->ivShow('tabObjHash', 0);
7960 }
7961  
7962 # Get the current visible tab
7963 $currentPage = $self->notebook->get_current_page();
7964 # Get the number of visible tabs
7965 $tabCount = $self->ivPairs('tabObjHash');
7966  
7967 if ($currentPage >= ($tabCount - 1)) {
7968  
7969 $nextPage = 0;
7970  
7971 } else {
7972  
7973 $nextPage = $currentPage + 1;
7974 }
7975  
7976 # Set the new visible tab
7977 $self->notebook->set_current_page($nextPage);
7978  
7979 return $self->findPage($nextPage);
7980 }
7981  
7982 sub respondVisibleTab {
7983  
7984 # Called by $self->setSwitchPageEvent, ->addSimpleTab and (either directly, or via a call
7985 # from the ->signal_connect in $self->setSwitchPageEvent) ->addTab
7986 #
7987 # When a tab becomes the visible tab, inform any code that wants to know. A number of
7988 # occurences can cause the ->signal_connect in $self->setSwitchPageEvent to be
7989 # emitted. When called by ->setSwitchpageEvent, this function only takes action if the
7990 # visible tab has actually changed
7991 # To artificially change the visible tab, call $self->switchVisibleTab or
7992 # ->setVisibleTab
7993 #
7994 # Expected arguments
7995 # $tabObj - The new visible tab's GA::Obj::Tab
7996 #
7997 # Optional arguments
7998 # $sessionFlag - Set to TRUE when called by ->addSimpleTab/->addTab, which in turn
7999 # were called by GA::Session->setDefaultTab; FALSE (or 'undef')
8000 # otherwise
8001 #
8002 # Return values
8003 # 'undef' on improper arguments or if the tab hasn't finished setting up yet
8004 # 1 otherwise
8005  
8006 my ($self, $tabObj, $sessionFlag, $check) = @_;
8007  
8008 # Local variables
8009 my ($changeFlag, $winObj, $funcRef);
8010  
8011 # Check for improper arguments
8012 if (! defined $tabObj || defined $check) {
8013  
8014 return $axmud::CLIENT->writeImproper($self->_objClass . '->respondVisibleTab', @_);
8015 }
8016  
8017 # Import the parent window (for convenience)
8018 $winObj = $self->winObj;
8019  
8020 # Update IVs
8021 if (! $self->currentTabObj || $self->currentTabObj ne $tabObj) {
8022  
8023 $self->ivPoke('currentTabObj', $tabObj);
8024 $changeFlag = TRUE;
8025 }
8026  
8027 # If this is a session's default tab, inform the parent window so it can update its visible
8028 # visible session
8029 if (
8030 $sessionFlag
8031 || (
8032 $tabObj->session->defaultTabObj
8033 && $tabObj->session->defaultTabObj eq $tabObj
8034 && (
8035 ! $winObj->visibleSession
8036 || $winObj->visibleSession ne $tabObj->session
8037 )
8038 )
8039 ) {
8040 $winObj->setVisibleSession($tabObj->session);
8041 }
8042  
8043 # Inform any code that wants to be informed when the tab changes
8044 if (! $sessionFlag && $changeFlag && $self->switchFuncRef) {
8045  
8046 $funcRef = $self->switchFuncRef;
8047 &$funcRef($self, $tabObj, $self->switchFuncID);
8048 }
8049  
8050 return 1;
8051 }
8052  
8053 sub setSessionTabLabel {
8054  
8055 # Called by GA::Session->spinTaskLoop and ->checkTabLabels to change the label of the
8056 # session's default tab's to something like '*Deathmud (Gandalf)' to show that there are
8057 # files that need to be saved, or to something like 'Deathmud (Gandalf)', to show there
8058 # are no longer files that need to be saved
8059 #
8060 # Expected arguments
8061 # $session - The calling GA::Session which uses a default tab (or default simple tab)
8062 # $string - The string to use (resembles one of the strings described above). Empty
8063 # strings are acceptable, if some code wants to do that
8064 #
8065 # Optional arguments
8066 # $flag - If set to TRUE, show an asterisk. If set to FALSE (or 'undef'), don't show
8067 # an asterisk
8068 #
8069 # Return values
8070 # 'undef' on improper arguments or if the session's default tab doesn't exist
8071 # 1 otherwise
8072  
8073 my ($self, $session, $string, $flag, $check) = @_;
8074  
8075 # Local variables
8076 my $tabObj;
8077  
8078 # Check for improper arguments
8079 if (! defined $session || ! defined $string || defined $check) {
8080  
8081 return $axmud::CLIENT->writeImproper($self->_objClass . '->setSessionTabLabel', @_);
8082 }
8083  
8084 # Find the session's tab
8085 $tabObj = $self->findSession($session);
8086 if (! $tabObj) {
8087  
8088 return undef;
8089 }
8090  
8091 # Set the tab label, but don't modify a simple tab (which has no tab label)
8092 if ($self->notebook && $tabObj->tabLabel) {
8093  
8094 if ($flag) {
8095  
8096 $tabObj->tabLabel->set_markup('*' . $string);
8097  
8098 } else {
8099  
8100 $tabObj->tabLabel->set_markup($string);
8101 }
8102 }
8103  
8104 return 1;
8105 }
8106  
8107 sub setTabLabel {
8108  
8109 # Can be called by anything
8110 # Changes the specified tab's label
8111 #
8112 # Expected arguments
8113 # $tabNum - The number of the tab object (GA::Obj::Tab) whose label should be changed
8114 # $string - The string to use. Empty strings are acceptable, if some code wants to do
8115 # that
8116 #
8117 # Return values
8118 # 'undef' on improper arguments or if the specified tab doesn't exist in this window
8119 # 1 otherwise
8120  
8121 my ($self, $tabNum, $string, $check) = @_;
8122  
8123 # Local variables
8124 my $tabObj;
8125  
8126 # Check for improper arguments
8127 if (! defined $tabNum || ! defined $string || defined $check) {
8128  
8129 return $axmud::CLIENT->writeImproper($self->_objClass . '->setTabLabel', @_);
8130 }
8131  
8132 # Check the tab exists in this window
8133 $tabObj = $self->ivShow('tabObjHash', $tabNum);
8134 if (! $tabObj) {
8135  
8136 return undef;
8137 }
8138  
8139 # Set the tab label, but don't modify a simple tab (which has no tab label)
8140 if ($self->notebook && $tabObj->tabLabel) {
8141  
8142 $tabObj->tabLabel->set_markup($string);
8143 }
8144  
8145 return 1;
8146 }
8147  
8148 sub getTabSize {
8149  
8150 # Called by GA::Obj::TextView->setupVPaned or by any other code
8151 # Returns the size of the area occupied by a tab in this pane object
8152 # If there is only a simple tab, it's the same size as the pane. If the pane object is
8153 # using a Gtk3::Notebook, it's the size of the notebook page
8154 #
8155 # Expected arguments
8156 # (none besides $self)
8157 #
8158 # Return values
8159 # An empty list on improper arguments or if there are no tabs open
8160 # Otherwise, returns a list in the form ($width, $height)
8161  
8162 my ($self, $check) = @_;
8163  
8164 # Local variables
8165 my (
8166 $tabObj, $hashRef,
8167 @emptyList,
8168 );
8169  
8170 # Check for improper arguments
8171 if (defined $check) {
8172  
8173 $axmud::CLIENT->writeImproper($self->_objClass . '->getTabSize', @_);
8174 return @emptyList;
8175 }
8176  
8177 # All tabs in this pane object have the same size, so use the first one
8178 $tabObj = $self->ivShow('tabObjHash', 0);
8179 if (! $tabObj) {
8180  
8181 # No tabs visible
8182 return @emptyList;
8183  
8184 } else {
8185  
8186 $hashRef = $tabObj->packableObj->get_allocation;
8187 return ($$hashRef{'width'}, $$hashRef{'height'});
8188 }
8189 }
8190  
8191 ##################
8192 # Accessors - set
8193  
8194 sub set_borderWidth {
8195  
8196 # Called by $axmud::CLIENT->paneModifyBorder or ->paneRestoreBorder
8197  
8198 my ($self, $flag, $check) = @_;
8199  
8200 if (! $flag && $self->packingBox2->get_border_width() ne $self->normalBorderWidth) {
8201  
8202 # Restore border width
8203 $self->packingBox2->set_border_width($self->normalBorderWidth);
8204  
8205 } elsif ($flag && $self->packingBox2->get_border_width() ne $self->selectBorderWidth) {
8206  
8207 # Modify border width
8208 $self->packingBox2->set_border_width($self->selectBorderWidth);
8209 }
8210  
8211 return 1;
8212 }
8213  
8214 sub set_canCloseFlag {
8215  
8216 my ($self, $flag, $check) = @_;
8217  
8218 # Check for improper arguments
8219 if (! defined $flag || defined $check) {
8220  
8221 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_canCloseFlag', @_);
8222 }
8223  
8224 if (! $flag) {
8225 $self->ivPoke('canCloseFlag', FALSE);
8226 } else {
8227 $self->ivPoke('canCloseFlag', TRUE);
8228 }
8229  
8230 return 1;
8231 }
8232  
8233 sub set_closeFunc {
8234  
8235 # A ->set_func exists in the generic table object for setting $self->funcRef, but there's
8236 # no generic ->closeFuncRef and therefore no generic accessor function
8237  
8238 my ($self, $funcRef, $check) = @_;
8239  
8240 # Check for improper arguments
8241 if (defined $check) {
8242  
8243 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_closeFunc', @_);
8244 }
8245  
8246 $self->ivPoke('closeFuncRef', $funcRef);
8247  
8248 return 1;
8249 }
8250  
8251 sub set_closeID {
8252  
8253 my ($self, $funcID, $check) = @_;
8254  
8255 # Check for improper arguments
8256 if (defined $check) {
8257  
8258 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_closeID', @_);
8259 }
8260  
8261 $self->ivPoke('closeFuncID', $funcID);
8262  
8263 return 1;
8264 }
8265  
8266 sub set_switchFunc {
8267  
8268 # A ->set_func exists in the generic table object for setting $self->funcRef, but there's
8269 # no generic ->switchFuncRef and therefore no generic accessor function
8270  
8271 my ($self, $funcRef, $check) = @_;
8272  
8273 # Check for improper arguments
8274 if (defined $check) {
8275  
8276 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_switchFunc', @_);
8277 }
8278  
8279 $self->ivPoke('switchFuncRef', $funcRef);
8280  
8281 return 1;
8282 }
8283  
8284 sub set_switchID {
8285  
8286 my ($self, $funcID, $check) = @_;
8287  
8288 # Check for improper arguments
8289 if (defined $check) {
8290  
8291 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_switchID', @_);
8292 }
8293  
8294 $self->ivPoke('switchFuncID', $funcID);
8295  
8296 return 1;
8297 }
8298  
8299 ##################
8300 # Accessors - get
8301  
8302 sub notebook
8303 { $_[0]->{notebook} }
8304 sub entry
8305 { $_[0]->{entry} }
8306  
8307 sub normalBorderWidth
8308 { $_[0]->{normalBorderWidth} }
8309 sub selectBorderWidth
8310 { $_[0]->{selectBorderWidth} }
8311  
8312 sub tabObjHash
8313 { my $self = shift; return %{$self->{tabObjHash}}; }
8314 sub tabObjCount
8315 { $_[0]->{tabObjCount} }
8316 sub currentTabObj
8317 { $_[0]->{currentTabObj} }
8318 sub simpleTabFlag
8319 { $_[0]->{simpleTabFlag} }
8320 sub tabConvertFlag
8321 { $_[0]->{tabConvertFlag} }
8322 sub canCloseFlag
8323 { $_[0]->{canCloseFlag} }
8324  
8325 sub switchFuncRef
8326 { $_[0]->{switchFuncRef} }
8327 sub switchFuncID
8328 { $_[0]->{switchFuncID} }
8329 sub closeFuncRef
8330 { $_[0]->{closeFuncRef} }
8331 sub closeFuncID
8332 { $_[0]->{closeFuncID} }
8333 }
8334  
8335 # 'Grid' window substitutes
8336  
8337 { package Games::Axmud::Table::PseudoWin;
8338  
8339 use strict;
8340 use warnings;
8341 use diagnostics;
8342  
8343 use Glib qw(TRUE FALSE);
8344  
8345 our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud);
8346  
8347 ##################
8348 # Constructors
8349  
8350 sub new {
8351  
8352 # Called by GA::Strip::Table->addTableObj
8353 # Creates the GA::Table::PseudoWin, which creates a container widget and a pseudo-window
8354 # containing all the widgets normally drawn inside a separate 'grid' window object
8355 # NB Not all 'grid' windows can be used as a pseudo-window. 'main' and 'external' windows
8356 # can never be used
8357 # Other types of window can be used, but the code handling them might need to be modified;
8358 # for example, tasks tend to call functions in GA::Generic::Task rather than functions
8359 # inherited from GA::Generic::Win
8360 # In general, the main problem is using the window object's ->winWidget and ->winBox IVs. In
8361 # most windows, these IVs are set to the same value (the Gtk3::Window), but in
8362 # pseudo-windows, ->winWidget is set to the parent window's Gtk3::Window, and ->winBox is
8363 # set to this table object's ->packingBox, a Gtk3::VBox
8364 # When you wants to do something to the Gtk3::Window in its capacity as a window (such as
8365 # minimise it or make it active), the code should use ->winWidget. When you want to do
8366 # something to the Gtk3::Window in its capacity as a container (such as add or remove
8367 # widgets), the code should use ->winBox
8368 #
8369 # Expected arguments
8370 # $number - The table object's number within the parent strip object (matches
8371 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object
8372 # created to access its default IVs)
8373 # $name - A name for the table object. Can be any string or, if no name was
8374 # specified in the call to the calling function, $name is the same as
8375 # $number. (No part of the code checks that table object names are unique;
8376 # if two or more table objects share the same ->name, usually the one with
8377 # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
8378 # chars)
8379 # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table
8380 # objects
8381 # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
8382 # parent strip object's Gtk3::Grid for use exclusively by this table
8383 # object. 'temp' for temporary table objects
8384 #
8385 # Optional arguments
8386 # %initHash - A hash containing arbitrary data to use as the table object's
8387 # initialisation settings. The table object should use default
8388 # initialisation settings unless it can succesfully interpret one or more
8389 # of the key-value pairs in the hash, if there are any
8390 # - This type of table object recognises these initialisation settings:
8391 #
8392 # 'frame_title' - If specified, the table object is drawn inside a frame
8393 # with the specified title. If 'undef', an empty string or not
8394 # specified, the table object does not use a frame and title
8395 # 'win_type' - The 'grid' window type, can be 'map', 'protocol', 'fixed'
8396 # or 'custom' (but not 'main' or 'external'). If 'undef' or not
8397 # specified, 'custom' is used. If an invalid value is specified, the
8398 # table object is not created
8399 # 'win_name' - The window name. For 'protocol' windows, any string chosen
8400 # by the protocol code. If not specified, 'undef' or an mpty string,
8401 # 'win_type' and 'win_name' have the same value
8402 # 'package' - The perl package name for the window object. Only needs to
8403 # be specified for 'fixed' windows (e.g. GA::FixedWin::Something);
8404 # however, if a package is specified for any window object type, it is
8405 # used ('grid' windows only). For 'fixed' windows, if 'undef' or not
8406 # specified, the table object is not created
8407 # 'owner' - The owner of the window object ('undef' or not specified if no
8408 # owner). Typically it's a GA::Session or a task (inheriting from
8409 # GA::Generic::Task); could also be GA::Client. It should not be
8410 # another window object (inheriting from GA::Generic::Win). The owner
8411 # should have its own ->del_winObj function which is called when the
8412 # window object's ->winDestroy is called
8413 # 'session' - The owner's session. If $owner is a GA::Session, that
8414 # session. If it's something else (like a task), the task's session.
8415 # If $owner is 'undef' or not specified, so is 'session'
8416 # 'winmap' - The name of the winmap to use in the pseudo-window. If
8417 # 'undef', not specified or not a recognised winmap, a default winmap
8418 # is used
8419 #
8420 # Return values
8421 # 'undef' on improper arguments
8422 # Blessed reference to the newly-created object on success
8423  
8424 my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
8425  
8426 # Local variables
8427 my (
8428 $winObj,
8429 %modHash,
8430 );
8431  
8432 # Check for improper arguments
8433 if (
8434 ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
8435 || ! defined $zoneObj
8436 ) {
8437 return $axmud::CLIENT->writeImproper($class . '->new', @_);
8438 }
8439  
8440 # Deal with temporary table objects
8441 if ($stripObj eq 'temp') {
8442 $winObj = 'temp';
8443 } else {
8444 $winObj = $stripObj->winObj;
8445 }
8446  
8447 # Default initialisation settings
8448 %modHash = (
8449 'frame_title' => undef,
8450 'win_type' => 'custom',
8451 'win_name' => 'custom',
8452 'package' => undef,
8453 'owner' => undef,
8454 'session' => undef,
8455 'winmap' => undef,
8456 );
8457  
8458 # Interpret the initialisation settings in %initHash, if any
8459 foreach my $key (keys %modHash) {
8460  
8461 if (exists $initHash{$key}) {
8462  
8463 $modHash{$key} = $initHash{$key};
8464 }
8465 }
8466  
8467 # Setup
8468 my $self = {
8469 _objName => 'table_obj_' . $number,
8470 _objClass => $class,
8471 _parentFile => undef, # No parent file object
8472 _parentWorld => undef, # No parent file object
8473 _privFlag => TRUE, # All IVs are private
8474  
8475 # Standard table object IVs
8476 # -------------------------
8477  
8478 # The table object's number within the parent strip object (matches
8479 # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to
8480 # access its default IVs)
8481 number => $number,
8482 # A name for the table object. Can be any string or, if no name was specified in the
8483 # call to the calling function, $name is the same as $number. (No part of the code
8484 # checks that table object names are unique; if two or more table objects share the
8485 # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary
8486 # table objects. Max 16 chars)
8487 name => $name,
8488 # The type of table object (custom table objects should use a ->type starting with
8489 # 'custom_' to avoid clashing with future built-in table objects)
8490 type => 'internal',
8491 # The parent strip object (GA::Strip::Table)
8492 stripObj => $stripObj,
8493 # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for
8494 # temporary table objects
8495 winObj => $winObj,
8496 # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip
8497 # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary
8498 # table objects
8499 zoneObj => $zoneObj,
8500  
8501 # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is
8502 # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as
8503 # when a connection to a world terminates)
8504 allowRemoveFlag => TRUE,
8505 # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is
8506 # created. Set to FALSE if it can't be resized
8507 allowResizeFlag => TRUE,
8508 # Initialisation settings stored as a hash (see the comments above)
8509 initHash => \%modHash,
8510 # Reference to a function to call when some widget is used. This IV is set only when
8511 # required by this type of table object. It can be set by a call to
8512 # $self->set_func() or by some setting in $self->initHash, which is applied in the
8513 # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
8514 # generic object function Games::Axmud->getMethodRef()
8515 funcRef => undef,
8516 # A value passed to ->funcRef when it is called which identifies this table object and
8517 # its widget(s). Can be any value, including 'undef'. It can be set by a call to
8518 # $self->set_id() or by some setting in $self->initHash, which is applied in the call
8519 # to $self->objEnable()
8520 funcID => '',
8521  
8522 # The container widget(s) for this table object; both IVs are always set to the same
8523 # widget
8524 packingBox => undef, # Gtk3::VBox
8525 packingBox2 => undef, # Gtk3::VBox
8526  
8527 # Other IVs
8528 # ---------
8529  
8530 # The pseudo-window's window object, an ordinary 'grid' window object whose ->number is
8531 # -1 to mark it as a pseudo-window, created via a direct call to its ->new function
8532 # rather than calling GA::Obj::Workspace->createGridWin as we normally would
8533 # Its ->winSetup and ->winEnable functions are never called; instead, the code in this
8534 # table object sets up the window's widgets
8535 pseudoWinObj => undef,
8536 };
8537  
8538 # Bless the object into existence
8539 bless $self, $class;
8540  
8541 return $self;
8542 }
8543  
8544 ##################
8545 # Methods
8546  
8547 # Standard table object functions
8548  
8549 sub objEnable {
8550  
8551 # Called by GA::Strip::Table->addTableObj
8552 # Sets up the table object's widgets
8553 #
8554 # Expected arguments
8555 # (none besides $self)
8556 #
8557 # Return values
8558 # 'undef' on improper arguments or if the table object can't be created
8559 # 1 on success
8560  
8561 my ($self, $check) = @_;
8562  
8563 # Local variables
8564 my ($winType, $winName, $package, $owner, $session, $winmap);
8565  
8566 # Check for improper arguments
8567 if (defined $check) {
8568  
8569 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
8570 }
8571  
8572 # Interpret $self->initHash, replacing any invalid values
8573 $winType = $self->ivShow('initHash', 'win_type');
8574 $winName = $self->ivShow('initHash', 'win_name');
8575 $package = $self->ivShow('initHash', 'package');
8576 $owner = $self->ivShow('initHash', 'owner');
8577 $session = $self->ivShow('initHash', 'session');
8578 $winmap = $self->ivShow('initHash', 'winmap');
8579  
8580 if (
8581 ! $winType
8582 || (
8583 $winType ne 'map' && $winType ne 'protocol' && $winType ne 'fixed'
8584 && $winType ne 'custom'
8585 ) || ($winType eq 'fixed' && ! $package)
8586 ) {
8587 return undef;
8588 }
8589  
8590 if (! $winName) {
8591  
8592 $winName = $winType;
8593 }
8594  
8595 # Create the packing box
8596 my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::VBox->new(FALSE, 0));
8597  
8598 # Set the package name (for 'fixed' windows, $package is definitely set)
8599 if (! $package) {
8600  
8601 if ($winType eq 'map') {
8602 $package = 'Games::Axmud::Win::Map';
8603 } else {
8604 $package = 'Games::Axmud::Win::Internal';
8605 }
8606 }
8607  
8608 # Create a pseudo-window object
8609 my $winObj = $package->new(
8610 -1, # Pseudo-window objects have the ->number -1
8611 $winType,
8612 $winName,
8613 $self->winObj->workspaceObj,
8614 $owner, # May be 'undef'
8615 $session, # May be 'undef'
8616 undef, # No workspace grid
8617 undef, # No area object
8618 $winmap, # May be 'undef'
8619 );
8620  
8621 if (! $winObj) {
8622  
8623 return undef;
8624 }
8625  
8626 # Update IVs for the window object
8627 $winObj->ivPoke('pseudoWinTableObj', $self);
8628  
8629 if ($winType eq 'protocol' || $winType eq 'custom') {
8630  
8631 # Code to replace the pseudo-window object's ->winSetup
8632 $winObj->set_winWidget($self->winObj->winWidget);
8633 $winObj->set_winBox($packingBox2);
8634 $winObj->setKeyPressEvent(); # 'key-press-event'
8635 $winObj->setKeyReleaseEvent(); # 'key-release-event'
8636 $winObj->drawWidgets();
8637  
8638 # Code to replace the pseudo-window object's ->winEnable
8639 $winObj->set_enabledFlag(TRUE);
8640 $winObj->setConfigureEvent(); # 'check-resize'
8641 $winObj->setFocusInEvent(); # 'focus-in-event'
8642 $winObj->setFocusOutEvent(); # 'focus-out-event'
8643  
8644 } elsif ($winType eq 'map') {
8645  
8646 # Code to replace the pseudo-window object's ->winSetup
8647 $winObj->set_winWidget($self->winObj->winWidget);
8648 $winObj->set_winBox($packingBox2);
8649 $winObj->setFocusOutEvent(); # 'focus-out-event'
8650 $winObj->drawWidgets();
8651  
8652 # Code to replace the pseudo-window object's ->winEnable
8653 $winObj->set_enabledFlag(TRUE);
8654 if ($session) {
8655  
8656 $session->set_mapWin($winObj);
8657 $session->mapObj->set_trackAloneFlag(FALSE);
8658 }
8659  
8660 } elsif ($winType eq 'fixed') {
8661  
8662 # Code to replace the pseudo-window object's ->winSetup
8663 $winObj->set_winWidget($self->winObj->winWidget);
8664 $winObj->set_winBox($packingBox2);
8665 $winObj->drawWidgets();
8666  
8667 # Code to replace the pseudo-window object's ->winEnable
8668 $winObj->set_enabledFlag(TRUE);
8669 }
8670  
8671 # Set expansion
8672 $packingBox->set_hexpand(TRUE);
8673 $packingBox->set_vexpand(TRUE);
8674  
8675 # Update IVs for this table object
8676 $self->ivPoke('packingBox', $packingBox);
8677 $self->ivPoke('packingBox2', $packingBox2);
8678 $self->ivPoke('pseudoWinObj', $winObj);
8679  
8680 return 1;
8681 }
8682  
8683 # sub objDestroy { # Inherited from GA::Generic::Table
8684  
8685 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table
8686  
8687 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table
8688  
8689 # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table
8690  
8691 # ->signal_connects
8692  
8693 # Other functions
8694  
8695 ##################
8696 # Accessors - set
8697  
8698 # (Get equivalents)
8699  
8700 ##################
8701 # Accessors - get
8702  
8703 sub pseudoWinObj
8704 { $_[0]->{pseudoWinObj} }
8705 }
8706  
8707 # Custom table objects
8708  
8709 { package Games::Axmud::Table::Custom;
8710  
8711 # Any user-written table objects should inherit from this object
8712  
8713 use strict;
8714 use warnings;
8715 use diagnostics;
8716  
8717 use Glib qw(TRUE FALSE);
8718  
8719 our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud);
8720  
8721 ##################
8722 # Constructors
8723  
8724 # sub new {} # Inherited from GA::Generic::Table
8725  
8726 ##################
8727 # Methods
8728  
8729 # Standard table object functions
8730  
8731 # sub objEnable {} # Inherited from GA::Generic::Table
8732  
8733 # sub objDestroy {} # Inherited from GA::Generic::Table
8734  
8735 # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table
8736  
8737 # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table
8738  
8739 # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table
8740  
8741 # ->signal_connects
8742  
8743 # Other functions
8744  
8745 ##################
8746 # Accessors - set
8747  
8748 ##################
8749 # Accessors - get
8750 }
8751  
8752 # Package must return a true value
8753 1