blib/lib/Games/Axmud/Win/Internal.pm untested

filter: Statementstmt 0.0% 0 / 1046 Branchbran 0.0% 0 / 548 Conditioncond 0.0% 0 / 576 MC/DCmcdc 0.0% 0 / 318 Subroutinesub 0.0% 0 / 63 Podpod 0.0% 0 / 60 totaltotal 0.0% 0 / 2611 CC 275 SCAR 62.3
CC
275
Cov
0%
setKeyPressEvent
2450.0
restrictMenuBars
702.0
drawWidgets
600.0
CRAP 505.7
1 # Copyright (C) 2011-2024 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::Win::Internal
16 # Object handling 'internal' 'grid' windows ('grid' windows whose window type is 'main', 'protocol'
17 # or 'custom'). Doesn't include 'map', 'fixed', 'external' or 'free' windows
18  
19 { package Games::Axmud::Win::Internal;
20  
21 use strict;
22 use warnings;
23 # use diagnostics;
24  
25 use Glib qw(TRUE FALSE);
26  
27 our @ISA = qw(
28 Games::Axmud::Generic::GridWin Games::Axmud::Generic::Win Games::Axmud
29 );
30  
31 ##################
32 # Constructors
33  
34 sub new {
35  
36 # Called by GA::Obj::Workspace->createGridWin and ->createSimpleGridWin
37 # Creates an 'internal' 'grid' window (any window that can be placed on the workspace grid,
38 # and which is created/controlled by Axmud)
39 #
40 # Expected arguments
41 # $number - Unique number for this window object
42 # $winType - The window type, any of the keys in GA::Client->constGridWinTypeHash
43 # (except 'external')
44 # $winName - A name for the window:
45 # $winType $winName
46 # -------- --------
47 # main main
48 # protocol Any string chosen by the protocol code (default value is
49 # 'protocol')
50 # custom Any string chosen by the controlling code. For task windows,
51 # the name of the task (e.g. 'status_task', for other
52 # windows, default value is 'custom'
53 # $workspaceObj
54 # - The GA::Obj::Workspace object for the workspace in which this window is
55 # created
56 #
57 # Optional arguments
58 # $owner - The owner, if known ('undef' if not). Typically it's a GA::Session or a
59 # task (inheriting from GA::Generic::Task); could also be GA::Client. iT
60 # Should not be another window object (inheriting from GA::Generic::Win).
61 # The owner should have its own ->del_winObj function which is called when
62 # $self->winDestroy is called
63 # $session - The owner's session. If $owner is a GA::Session, that session. If it's
64 # something else (like a task), the task's session. If $owner is 'undef',
65 # so is $session
66 # $workspaceGridObj
67 # - The GA::Obj::WorkspaceGrid object into whose grid this window has been
68 # placed. 'undef' in $workspaceObj->gridEnableFlag = FALSE
69 # $areaObj - The GA::Obj::Area (a region of a workspace grid zone) which handles this
70 # window. 'undef' in $workspaceObj->gridEnableFlag = FALSE
71 # $winmap - The ->name of the GA::Obj::Winmap object that specifies the Gtk3::Window's
72 # layout when it is first created. If 'undef', a default winmap is used
73 #
74 # Return values
75 # 'undef' on improper arguments
76 # Blessed reference to the newly-created object on success
77  
78 my (
79 $class, $number, $winType, $winName, $workspaceObj, $owner, $session, $workspaceGridObj,
80 $areaObj, $winmap, $check,
81 ) = @_;
82  
83 # Check for improper arguments
84 if (
85 ! defined $class || ! defined $number || ! defined $winType || ! defined $winName
86 || ! defined $workspaceObj || defined $check
87 ) {
88 return $axmud::CLIENT->writeImproper($class . '->new', @_);
89 }
90  
91 # Check that the $winType is valid
92 if (
93 ! $axmud::CLIENT->ivExists('constGridWinTypeHash', $winType)
94 || ($winType ne 'main' && $winType ne 'protocol' && $winType ne 'custom')
95 ) {
96 return $axmud::CLIENT->writeError(
97 'Internal window error: invalid \'internal\' window type \'' . $winType . '\'',
98 $class . '->new',
99 );
100 }
101  
102 # Setup
103 my $self = {
104 _objName => 'internal_win_' . $number,
105 _objClass => $class,
106 _parentFile => undef, # No parent file object
107 _parentWorld => undef, # No parent file object
108 _privFlag => TRUE, # All IVs are private
109  
110 # Standard window object IVs
111 # --------------------------
112  
113 # Unique number for this window object
114 number => $number,
115 # The window category - 'grid' or 'free'
116 winCategory => 'grid',
117 # The window type, any of the keys in GA::Client->constGridWinTypeHash (except
118 # 'external')
119 winType => $winType,
120 # A name for the window:
121 # $winType $winName
122 # -------- --------
123 # main main
124 # protocol Any string chosen by the protocol code (default value is 'protocol')
125 # custom Any string chosen by the controlling code. For task windows, the
126 # name of the task (e.g. 'status_task', for other windows, default
127 # value is 'custom'
128 winName => $winName,
129 # The GA::Obj::Workspace object for the workspace in which this window is created
130 workspaceObj => $workspaceObj,
131 # The owner, if known ('undef' if not). Typically it's a GA::Session or a task
132 # (inheriting from GA::Generic::Task); could also be GA::Client. It should not be
133 # another window object (inheriting from GA::Generic::Win). The owner must have its
134 # own ->del_winObj function which is called when $self->winDestroy is called
135 owner => $owner,
136 # The owner's session ('undef' if no owner). If ->owner is a GA::Session, that session.
137 # If it's something else (like a task), the task's sesssion. If ->owner is 'undef', so
138 # is ->session
139 session => $session,
140 # When GA::Session->pseudoCmd is called to execute a client command, the mode in which
141 # it should be called (usually 'win_error' or 'win_only', which causes errors to be
142 # displayed in a 'dialogue' window)
143 pseudoCmdMode => 'win_error',
144  
145 # The window widget. For most window objects, the Gtk3::Window. For pseudo-windows, the
146 # parent 'main' window's Gtk3::Window
147 # The code should use this IV when it wants to do something to the window itself
148 # (minimise it, make it active, etc)
149 winWidget => undef,
150 # The window container. For most window objects, the Gtk3::Window. For pseudo-windows,
151 # the parent GA::Table::PseudoWin table object
152 # The code should use this IV when it wants to add, modify or remove widgets inside the
153 # window itself
154 winBox => undef,
155 # Flag set to TRUE if the window actually exists (after a call to $self->winEnable),
156 # FALSE if not
157 enabledFlag => FALSE,
158 # Flag set to TRUE if the Gtk3 window itself is visible (after a call to
159 # $self->setVisible), FALSE if it is not visible (after a call to $self->setInvisible)
160 visibleFlag => TRUE,
161 # Registry hash of 'free' windows (excluding 'dialogue' windows) for which this window
162 # is the parent, a subset of GA::Obj::Desktop->freeWinHash. Hash in the form
163 # $childFreeWinHash{unique_number} = blessed_reference_to_window_object
164 childFreeWinHash => {},
165 # When a child 'free' window (excluding 'dialogue' windows) is destroyed, this parent
166 # window is informed via a call to $self->del_childFreeWin
167 # When the child is destroyed, this window might want to call some of its own functions
168 # to update various widgets and/or IVs, in which case this window adds an entry to
169 # this hash; a hash in the form
170 # $childDestroyHash{unique_number} = list_reference
171 # ...where 'unique_number' is the child window's ->number, and 'list_reference' is a
172 # reference to a list in groups of 2, in the form
173 # (sub_name, argument_list_ref, sub_name, argument_list_ref...)
174 childDestroyHash => {},
175  
176 # The container widget into which all other widgets are packed (usually a Gtk3::VBox or
177 # Gtk3::HBox, but any container widget can be used; takes up the whole window client
178 # area)
179 packingBox => undef,
180  
181 # Standard IVs for 'grid' windows
182  
183 # The GA::Obj::WorkspaceGrid object into whose grid this window has been placed. 'undef'
184 # in $workspaceObj->gridEnableFlag = FALSE
185 # For 'main' windows only, $self->setVisibleSession changes the value of this IV every
186 # time the visible session changes
187 workspaceGridObj => $workspaceGridObj,
188 # The GA::Obj::Area object for this window. An area object is a part of a zone's
189 # internal grid, handling a single window (this one). Set to 'undef' in
190 # $workspaceObj->gridEnableFlag = FALSE
191 areaObj => $areaObj,
192 # For pseudo-windows (in which a window object is created, but its widgets are drawn
193 # inside a GA::Table::PseudoWin table object), the table object created. 'undef' if
194 # this window object is a real 'grid' window
195 # NB 'main' windows can't be pseudo-windows, but 'protocol' and 'custom' windows can
196 pseudoWinTableObj => undef,
197 # The ->name of the GA::Obj::Winmap object that specifies the Gtk3::Window's layout when
198 # it is first created. If 'undef', a default winmap is used
199 winmap => $winmap,
200  
201 # IVs for 'internal' windows
202  
203 # Hash of strip objects (inheriting from GA::Generic::Strip) currently packed into
204 # $self->packingBox. Hash in the form
205 # $stripHash{number} = blessed_reference_to_strip_object
206 stripHash => {},
207 # A hash of the first instance of each type of strip object that was packed into
208 # $self->packingBox and is still there (a subset of $self->stripHash)
209 # For 'jealous' strip objects, we can use this hash to find a strip object of a
210 # particular type quickly. For other strip, we can use this hash to treat the first
211 # instance of a particular type as the default one
212 # Hash in the form
213 # $firstStripHash{object_class} = blessed_reference_to_strip_object
214 firstStripHash => {},
215 # Number of strip objects ever created for this window (used to give every strip object
216 # a number unique to the window)
217 stripCount => 0,
218 # A list of strip objects in the order in which they were packed into the window (the
219 # order in which they were created by $self->drawWidgets or the order in which they
220 # were re-packed by $self->redrawWidgets, ->addStripObj, ->hideStripObj etc)
221 stripList => [],
222 # A shortcut to the compulsory GA::Strip::Table object (also stored as a value in
223 # $self->stripHash)
224 tableStripObj => undef,
225 # Leave a small gap between strip objects
226 stripSpacingPixels => 2,
227  
228 # Other IVs
229  
230 # If GA::CLIENT->shareMainWinFlag = TRUE, all sessions share the same default pane
231 # object (GA::Table::Pane) in a single shared 'main' window. In that default pane
232 # object, only one session's default textview object is visible; that session is the
233 # visible session
234 # If GA::Client->shareMainWinFlag = FALSE, the GA::Session which controls this 'main'
235 # window
236 # In both cases, set to 'undef' for windows that aren't 'main' windows or if there are
237 # no sessions running at all
238 visibleSession => undef,
239  
240 # Whenever some of other Axmud function wants to set (or reset) the text used in the
241 # the GA::Strip::ConnectInfo strip object, it calls $self->setHostLabel and/or
242 # ->setTimeLabel. The text is stored here so it's available immediately, if the strip
243 # object is brought into existence; if the strip object already exists, it is updated
244 hostLabelText => '',
245 timeLabelText => '',
246  
247 # Flags capturing keypresses. When these flags are TRUE, the key is held down; they're
248 # set to FALSE when the key is released (or when this window loses focus)
249 # Flags set by $self->setKeyPressEvent and reset by ->setKeyReleaseEvent
250 ctrlKeyFlag => FALSE,
251 shiftKeyFlag => FALSE,
252 altKeyFlag => FALSE,
253 altGrKeyFlag => FALSE,
254 # Flag set to FALSE if none of the CTRL, SHIFT, ALT and ALT-GR keys are held down; set
255 # to TRUE if one of those keys is held down
256 modifierKeyFlag => FALSE,
257  
258 # The actual window size (in pixels). $self->winEnable sets up a ->signal_connect to
259 # react when the window size changes, but the same ->signal_connect fires when (for
260 # example) text is written to a Gtk3::TextView
261 # The new size is stored in these IVs every time the ->signal_connect fires, so we can
262 # tell if the window's actual size has changed, or not
263 actualWinWidth => undef,
264 actualWinHeight => undef,
265 # A flag set to TRUE when the window is maximised, then set back to FALSE when it is
266 # unmaximised. Required for drawing gauges correctly
267 maximisedFlag => FALSE,
268 # A flag set to TRUE when the window receives keyboard focus, then back to FALSE when it
269 # loses the focus
270 focusFlag => FALSE,
271 };
272  
273 # Bless the object into existence
274 bless $self, $class;
275  
276 return $self;
277 }
278  
279 ##################
280 # Methods
281  
282 # Standard window object functions
283  
284 sub winSetup {
285  
286 # Called by GA::Obj::Workspace->createGridWin or ->createSimpleGridWin
287 # Creates the Gtk3::Window itself
288 #
289 # Expected arguments
290 # (none besides $self)
291 #
292 # Optional arguments
293 # $title - The window title. If 'undef' or an empty string, a default title will be
294 # used
295 # $listRef - Reference to a list of functions to call, just after the Gtk3::Window is
296 # created (can be used to set up further ->signal_connects, if this
297 # window needs them)
298 #
299 # Return values
300 # 'undef' on improper arguments or if the window can't be opened
301 # 1 on success
302  
303 my ($self, $title, $listRef, $check) = @_;
304  
305 # Local variables
306 my $iv;
307  
308 # Check for improper arguments
309 if (defined $check) {
310  
311 return $axmud::CLIENT->writeImproper($self->_objClass . '->winSetup', @_);
312 }
313  
314 # Don't create a new window, if it already exists
315 if ($self->enabledFlag) {
316  
317 return undef;
318 }
319  
320 # Create the Gtk3::Window
321 my $winWidget = Gtk3::Window->new('toplevel');
322 if (! $winWidget) {
323  
324 return undef;
325  
326 } else {
327  
328 # Store the IV now, as subsequent code needs it
329 $self->ivPoke('winWidget', $winWidget);
330 $self->ivPoke('winBox', $winWidget);
331 }
332  
333 # Set up ->signal_connects (other ->signal_connects are set up in the call to
334 # $self->winEnable() )
335 $self->setDeleteEvent(); # 'delete-event'
336 $self->setKeyPressEvent(); # 'key-press-event'
337 $self->setKeyReleaseEvent(); # 'key-release-event'
338 # Set up ->signal_connects specified by the calling function, if any
339 if ($listRef) {
340  
341 foreach my $func (@$listRef) {
342  
343 $self->$func();
344 }
345 }
346  
347 # Set the window title. If $title wasn't specified, use a suitable default title
348 if (! $title) {
349  
350 if ($self->winType eq 'main') {
351  
352 $title = $axmud::SCRIPT;
353  
354 } elsif ($self->winName) {
355  
356 $title = $self->winName;
357  
358 } else {
359  
360 # Emergency fallback - $self->winName should be set
361 $title = 'Untitled window';
362 }
363 }
364  
365 $winWidget->set_title($title);
366  
367 # Set the window's default size and position (this will almost certainly be changed before
368 # the call to $self->winEnable() )
369 if ($self->winType eq 'main') {
370  
371 $winWidget->set_default_size(
372 $axmud::CLIENT->customMainWinWidth,
373 $axmud::CLIENT->customMainWinHeight,
374 );
375  
376 $winWidget->set_border_width($axmud::CLIENT->constMainBorderPixels);
377  
378 # When workspace grids are disabled, 'main' windows should appear in the middle of the
379 # desktop
380 if (! $self->workspaceObj->gridEnableFlag) {
381  
382 $winWidget->set_position('center');
383 }
384  
385 } else {
386  
387 $winWidget->set_default_size(
388 $axmud::CLIENT->customGridWinWidth,
389 $axmud::CLIENT->customGridWinHeight,
390 );
391  
392 $winWidget->set_border_width($axmud::CLIENT->constGridBorderPixels);
393 }
394  
395 # Set the icon list for this window
396 $iv = $self->winType . 'WinIconList';
397 $winWidget->set_icon_list($axmud::CLIENT->desktopObj->{$iv});
398  
399 # Draw the widgets used by this window
400 if (! $self->drawWidgets()) {
401  
402 return undef;
403 }
404  
405 # The calling function can now move the window into position, before calling
406 # $self->winEnable to make it visible, and to set up any more ->signal_connects()
407 return 1;
408 }
409  
410 sub winEnable {
411  
412 # Called by GA::Obj::Workspace->createGridWin or ->createSimpleGridWin
413 # After the Gtk3::Window has been setup and moved into position, makes it visible and calls
414 # any further ->signal_connects that must be not be setup until the window is visible
415 #
416 # Expected arguments
417 # (none besides $self)
418 #
419 # Optional arguments
420 # $listRef - Reference to a list of functions to call, just after the Gtk3::Window is
421 # created (can be used to set up further ->signal_connects, if this
422 # window needs them)
423 #
424 # Return values
425 # 'undef' on improper arguments
426 # 1 on success
427  
428 my ($self, $listRef, $check) = @_;
429  
430 # Check for improper arguments
431 if (defined $check) {
432  
433 return $axmud::CLIENT->writeImproper($self->_objClass . '->winEnable', @_);
434 }
435  
436 # Make the window appear on the desktop
437 $self->winShowAll($self->_objClass . '->winEnable');
438 $self->ivPoke('enabledFlag', TRUE);
439  
440 # # For windows about to be placed on a grid, briefly minimise the window so it doesn't
441 # # appear in the centre of the desktop before being moved to its correct workspace, size
442 # # and position
443 # if ($self->workspaceGridObj && $self->winWidget eq $self->winBox) {
444 #
445 # $self->minimise();
446 # }
447  
448 # Set up ->signal_connects that must not be set up until the window is visible
449 $self->setConfigureEvent(); # 'configure-event'
450 $self->setWindowStateEvent(); # 'window-state-event'
451 $self->setFocusInEvent(); # 'focus-in-event'
452 $self->setFocusOutEvent(); # 'focus-out-event'
453 # Set up ->signal_connects specified by the calling function, if any
454 if ($listRef) {
455  
456 foreach my $func (@$listRef) {
457  
458 $self->$func();
459 }
460 }
461  
462 return 1;
463 }
464  
465 sub winDestroy {
466  
467 # Called by GA::Obj::WorkspaceGrid->stop or by any other function
468 # Informs the window's strip objects of their imminent demise, informs the parent workspace
469 # grid (if this 'grid' window is on a workspace grid) and the desktop object, and then
470 # destroys the Gtk3::Window (if it is open)
471 #
472 # Expected arguments
473 # (none besides $self)
474 #
475 # Return values
476 # 'undef' on improper arguments, if the window can't be destroyed or if it has already
477 # been destroyed
478 # 1 on success
479  
480 my ($self, $check) = @_;
481  
482 # Check for improper arguments
483 if (defined $check) {
484  
485 return $axmud::CLIENT->writeImproper($self->_objClass . '->winDestroy', @_);
486 }
487  
488 if (! $self->winBox) {
489  
490 # Window already destroyed in a previous call to this function
491 return undef;
492 }
493  
494 # Inform this window's strip objects of their imminent demise (in the order in which they
495 # were created
496 foreach my $stripObj (sort {$a->number <=> $b->number} ($self->ivValues('stripHash'))) {
497  
498 $stripObj->objDestroy();
499 }
500  
501 # Close any 'free' windows for which this window is a parent
502 foreach my $winObj ($self->ivValues('childFreeWinHash')) {
503  
504 $winObj->winDestroy();
505 }
506  
507 # Inform the parent workspace grid object (if any)
508 if ($self->workspaceGridObj) {
509  
510 $self->workspaceGridObj->del_gridWin($self);
511 }
512  
513 # Inform the desktop object
514 $axmud::CLIENT->desktopObj->del_gridWin($self);
515  
516 # Destroy the Gtk3::Window
517 eval { $self->winBox->destroy(); };
518 if ($@) {
519  
520 # Window can't be destroyed
521 return undef;
522  
523 } else {
524  
525 $self->ivUndef('winWidget');
526 $self->ivUndef('winBox');
527 }
528  
529 # Inform the ->owner, if there is one
530 if ($self->owner) {
531  
532 $self->owner->del_winObj($self);
533 }
534  
535 return 1;
536 }
537  
538 sub winDisengage {
539  
540 # Called by GA::Obj::Desktop->removeSessionWindows and GA::Obj::WorkspaceGrid->stop
541 # Removes this window object from its workspace grid, but does not close the window
542 # Should not be called, in general
543 #
544 # Expected arguments
545 # (none besides $self)
546 #
547 # Optional arguments
548 # $session - When called by the functions listed above, the GA::Session which is
549 # closing; otherwise 'undef'
550 #
551 # Return values
552 # 'undef' on improper arguments or if the window can't be disengaged
553 # 1 on success
554  
555 my ($self, $session, $check) = @_;
556  
557 # Check for improper arguments
558 if (defined $check) {
559  
560 return $axmud::CLIENT->writeImproper($self->_objClass . '->winDisengage', @_);
561 }
562  
563 # Close any 'free' windows for which this window is a parent (but not when a session is
564 # closing; in that case, only close 'free' windows connected to that session)
565 foreach my $winObj ($self->ivValues('childFreeWinHash')) {
566  
567 if (! $session || ($winObj->session && $winObj->session eq $session)) {
568  
569 $winObj->winDestroy();
570 }
571 }
572  
573 # Inform the parent workspace grid object (if any)
574 if ($self->workspaceGridObj) {
575  
576 $self->workspaceGridObj->del_gridWin($self);
577 }
578  
579 # Update IVs
580 $self->ivUndef('workspaceGridObj');
581 $self->ivUndef('areaObj');
582 $self->ivUndef('session');
583 if ($self->owner && $session && $self->owner eq $session) {
584  
585 $self->ivUndef('owner');
586 }
587  
588 if ($self->visibleSession && $session && $self->visibleSession eq $session) {
589  
590 # Don't close tabs - assume that GA::Session->close is about to apply a new winmap
591 $self->ivUndef('visibleSession');
592 }
593  
594 return 1;
595 }
596  
597 # sub winShowAll {} # Inherited from GA::Generic::Win
598  
599 sub drawWidgets {
600  
601 # Called by $self->winSetup (also by $self->resetWinmap)
602 # Sets up the Gtk3::Window by drawing the strip objects and table objects specified by
603 # $self->winmap (the name of a GA::Obj::Winmap object)
604 #
605 # Expected arguments
606 # (none besides $self)
607 #
608 # Return values
609 # 'undef' on improper arguments, if the winmap can't be found or if any of the widgets are
610 # not drawn
611 # 1 on success
612  
613 my ($self, $check) = @_;
614  
615 # Local variables
616 my (
617 $winmap, $winmapObj, $matchFlag, $count,
618 @initList, @objList, @winzoneList,
619 %checkHash,
620 );
621  
622 # Check for improper arguments
623 if (defined $check) {
624  
625 return $axmud::CLIENT->writeImproper($self->_objClass . '->drawWidgets', @_);
626 }
627  
628 # This function shouldn't be called by anything but $self->winSetup, but reset IVs
629 # anyway, just in case
630 $self->ivUndef('packingBox');
631 $self->ivEmpty('stripHash');
632 $self->ivEmpty('firstStripHash');
633 $self->ivPoke('stripCount', 0);
634 $self->ivEmpty('stripList');
635 $self->ivUndef('tableStripObj');
636  
637 # If no winmap was specified, use a default one
638 if (! $self->winmap) {
639  
640 if ($self->winType eq 'main') {
641  
642 if ($axmud::CLIENT->activateGridFlag) {
643 $winmap = $axmud::CLIENT->defaultEnabledWinmap;
644 } else {
645 $winmap = $axmud::CLIENT->defaultDisabledWinmap;
646 }
647  
648 } else {
649  
650 $winmap = $axmud::CLIENT->defaultInternalWinmap;
651 }
652  
653 } else {
654  
655 $winmap = $self->winmap;
656 }
657  
658 $winmapObj = $axmud::CLIENT->ivShow('winmapHash', $winmap);
659 if (! $winmapObj) {
660  
661 return undef;
662  
663 } else {
664  
665 # (Set this IV for the first time)
666 $self->ivPoke('winmap', $winmapObj->name);
667 }
668  
669 # Create a packing box
670 my $packingBox;
671 if ($winmapObj->orientation eq 'top' || $winmapObj->orientation eq 'bottom') {
672 $packingBox = Gtk3::VBox->new(FALSE, 0);
673 } else {
674 $packingBox = Gtk3::HBox->new(FALSE, 0);
675 }
676  
677 $self->winBox->add($packingBox);
678 $packingBox->set_border_width(0);
679  
680 # Update IVs immediately
681 $self->ivPoke('packingBox', $packingBox);
682  
683 # Check the list of strip objects specified by the winmap. It must contain the compulsory
684 # GA::Strip::Table object; if not, add that object to the beginning of the list (so it
685 # appears first; normally at the top of the window)
686 @initList = $winmapObj->stripInitList;
687 if (@initList) {
688  
689 do {
690  
691 my ($packageName, $hashRef);
692  
693 $packageName = shift @initList;
694 $hashRef = shift @initList;
695  
696 if ($packageName eq 'Games::Axmud::Strip::Table') {
697  
698 $matchFlag = TRUE;
699 }
700  
701 } until ($matchFlag || ! @initList);
702 }
703  
704 @initList = $winmapObj->stripInitList;
705 if (! $matchFlag) {
706  
707 unshift(@initList, 'Games::Axmud::Strip::Table');
708 }
709  
710 # Add each strip object in turn
711 $count = 0;
712 do {
713  
714 my ($packageName, $hashRef, $stripObj, $spacing);
715  
716 $packageName = shift @initList;
717 $hashRef = shift @initList;
718  
719 $count++;
720  
721 # Strip objects must inherit from GA::Generic::Strip and must exist (in the case of
722 # strip objects loaded from a plugin)
723 if (
724 $packageName =~ m/^Games\:\:Axmud\:\:Strip\:\:/
725 && $axmud::CLIENT->ivExists('customStripHash', $packageName)
726 ) {
727 $stripObj = $packageName->new($self->stripCount, $self, %$hashRef);
728 if ($stripObj) {
729  
730 # Some strip objects are 'jealous' (only one can be opened per window)
731 if ($stripObj->jealousyFlag) {
732  
733 # If another strip object of this type has already been created, discard the
734 # newest one
735 if (exists $checkHash{$packageName}) {
736  
737 $stripObj = undef;
738 }
739 }
740  
741 # Some strip objects can't be added in Axmud blind mode
742 if ($stripObj && ! $stripObj->blindFlag && $axmud::BLIND_MODE_FLAG) {
743  
744 $stripObj = undef;
745 }
746  
747 # This strip object can be added
748 if ($stripObj && $stripObj->objEnable($winmapObj)) {
749  
750 $checkHash{$packageName} = undef;
751  
752 if ($stripObj->packingBox) {
753  
754 if ($stripObj->allowFocusFlag) {
755 $stripObj->packingBox->set_can_focus(TRUE);
756 } else {
757 $stripObj->packingBox->set_can_focus(FALSE);
758 }
759 }
760  
761 # Update IVs
762 $self->ivIncrement('stripCount');
763 $self->ivPush('stripList', $stripObj);
764 $self->ivAdd('stripHash', $stripObj->number, $stripObj);
765 if (! $self->ivExists('firstStripHash', $stripObj->_objClass)) {
766  
767 $self->ivAdd('firstStripHash', $stripObj->_objClass, $stripObj);
768 }
769  
770 if (
771 $packageName eq 'Games::Axmud::Strip::Table'
772 && ! $self->tableStripObj
773 ) {
774 $self->ivPoke('tableStripObj', $stripObj);
775 }
776  
777 # Set the spacing between this strip object and adjacent ones
778 if (! $stripObj->spacingFlag || $count == 1 || ! @initList) {
779 $spacing = 0;
780 } else {
781 $spacing = $self->stripSpacingPixels;
782 }
783  
784 # Add the strip object to the packing box
785 if ($stripObj->visibleFlag) {
786  
787 if (
788 $winmapObj->orientation eq 'top'
789 || $winmapObj->orientation eq 'left'
790 ) {
791 $packingBox->pack_start(
792 $stripObj->packingBox,
793 $stripObj->expandFlag,
794 $stripObj->fillFlag,
795 $spacing,
796 );
797  
798 } else {
799  
800 $packingBox->pack_end(
801 $stripObj->packingBox,
802 $stripObj->expandFlag,
803 $stripObj->fillFlag,
804 $spacing,
805 );
806 }
807 }
808  
809 # Inform all existing strip objects of this strip object's birth
810 foreach my $otherStripObj ($self->stripList) {
811  
812 if ($stripObj ne $otherStripObj) {
813  
814 $stripObj->notify_addStripObj($otherStripObj);
815 }
816 }
817 }
818 }
819 }
820  
821 } until (! @initList);
822  
823 # Now draw table objects on the GA::Strip::Table, using the layout specified by the winmap's
824 # winzones. We assume that the winmap has already checked that its winzones have valid
825 # sizes and don't overlap each other
826 @winzoneList = sort {$a->number <=> $b->number} ($winmapObj->ivValues('zoneHash'));
827 foreach my $winzoneObj (@winzoneList) {
828  
829 $self->tableStripObj->addTableObj(
830 $winzoneObj->packageName,
831 $winzoneObj->left,
832 $winzoneObj->right,
833 $winzoneObj->top,
834 $winzoneObj->bottom,
835 $winzoneObj->objName,
836 $winzoneObj->initHash,
837 );
838 }
839  
840 # Sensitise/desensitise widgets according to current conditions
841 $self->restrictMenuBars();
842 $self->restrictToolbars();
843  
844 return 1;
845 }
846  
847 sub redrawWidgets {
848  
849 # Can be called by anything
850 # Resets the Gtk3::Window by re-packing the strip objects in $self->stripList
851 # When called by $self->addStripObj, the new strip object will be packed for the first time.
852 # When called by $self->removeStripObj, the removed strip object won't be packed at all
853 #
854 # NB This is a legacy function that probably should not be called at all. Due to Gtk
855 # performance issues, it's nearly always better to call $self->hideStripObj,
856 # ->revealStripObj or ->replaceStripObj instead
857 #
858 # Expected arguments
859 # (none besides $self)
860 #
861 # Return values
862 # 'undef' on improper arguments
863 # 1 on success
864  
865 my ($self, $check) = @_;
866  
867 # Local variables
868 my (
869 $winmapObj, $gaugeStripObj,
870 @modList,
871 );
872  
873 # Check for improper arguments
874 if (defined $check) {
875  
876 return $axmud::CLIENT->writeImproper($self->_objClass . '->redrawWidgets', @_);
877 }
878  
879 # Get the winmap object specified by $self->winmap, or a default winmap, if $self->winmap
880 # is 'undef'
881 $winmapObj = $self->getWinmap();
882  
883 # Empty the packing box of existing strips
884 foreach my $child ($self->packingBox->get_children()) {
885  
886 $self->packingBox->remove($child);
887 }
888  
889 # Get a list of existing strips that are actually visible
890 foreach my $stripObj ($self->stripList) {
891  
892 if ($stripObj->visibleFlag) {
893  
894 push (@modList, $stripObj);
895 }
896 }
897  
898 # Re-pack all visible strips, leaving a gap between strips that aren't at the beginning or
899 # end of the list
900 if (@modList) {
901  
902 for (my $count = 0; $count < (scalar @modList); $count++) {
903  
904 my ($stripObj, $spacing);
905  
906 $stripObj = $modList[$count];
907 if (! $stripObj->spacingFlag || $count == 0 || $count == (scalar @modList - 1)) {
908 $spacing = 0;
909 } else {
910 $spacing = $self->stripSpacingPixels;
911 }
912  
913 if (
914 $winmapObj->orientation eq 'top'
915 || $winmapObj->orientation eq 'left'
916 ) {
917 $self->packingBox->pack_start(
918 $stripObj->packingBox,
919 $stripObj->expandFlag,
920 $stripObj->fillFlag,
921 $spacing,
922 );
923  
924 } else {
925  
926 $self->packingBox->pack_end(
927 $stripObj->packingBox,
928 $stripObj->expandFlag,
929 $stripObj->fillFlag,
930 $spacing,
931 );
932 }
933 }
934 }
935  
936 # Sensitise/desensitise widgets according to current conditions
937 $self->restrictMenuBars();
938 $self->restrictToolbars();
939  
940 # Any Gtk3::TextViews will now be using the colours of the most recently-created
941 # Gtk3::TextView, not the colours that we want them to use. Update colours for all pane
942 # objects (GA::Table::Pane) before the forthcoming call to ->winShowAll
943 $self->updateColourScheme(undef, TRUE);
944  
945 # Make everything visible
946 $self->winShowAll($self->_objClass . '->redrawWidgets');
947 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->redrawWidgets');
948  
949 # Adding/removing widgets upsets the position of the scrollbar in each tab's textview.
950 # Make sure all the textviews are scrolled to the bottom
951 $self->rescrollTextViews();
952  
953 # Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
954 # themselves will have disappeared
955 $gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
956 if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
957  
958 $gaugeStripObj->updateGauges();
959 # (Need to call this a second time, or the re-draw doesn't work...)
960 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->redrawWidgets');
961 }
962  
963 return 1;
964 }
965  
966 # ->signal_connects
967  
968 sub setDeleteEvent {
969  
970 # Called by $self->winSetup
971 # Set up a ->signal_connect to watch out for the user manually closing the 'internal' window
972 # If it's a 'main' window and there are no 'main' windows left, halt the client
973 #
974 # Expected arguments
975 # (none besides $self)
976 #
977 # Return values
978 # 'undef' on improper arguments
979 # 1 otherwise
980  
981 my ($self, $check) = @_;
982  
983 # Check for improper arguments
984 if (defined $check) {
985  
986 return $axmud::CLIENT->writeImproper($self->_objClass . '->setDeleteEvent', @_);
987 }
988  
989 if ($self->winType eq 'main' && $axmud::CLIENT->shareMainWinFlag) {
990  
991 $self->winBox->signal_connect('delete-event' => sub {
992  
993 # Prompt the user for confirmation, if required
994 if (! $self->checkConnectedSessions()) {
995  
996 # Don't close the 'main' window
997 return 1;
998 }
999  
1000 # Inform this window's strip objects of their imminent demise (in the order in which
1001 # they were created
1002 foreach my $stripObj (
1003 sort {$a->number <=> $b->number} ($self->ivValues('stripHash'))
1004 ) {
1005 $stripObj->objDestroy();
1006 }
1007  
1008 # Close any 'free' windows for which this window is a parent
1009 foreach my $winObj ($self->ivValues('childFreeWinHash')) {
1010  
1011 $winObj->winDestroy();
1012 }
1013  
1014 # Inform the parent workspace grid object (if any)
1015 if ($self->workspaceGridObj) {
1016  
1017 $self->workspaceGridObj->del_gridWin($self);
1018 }
1019  
1020 # Inform the desktop object
1021 $axmud::CLIENT->desktopObj->del_gridWin($self);
1022  
1023 # Halt the client
1024 $axmud::CLIENT->stop();
1025  
1026 # Allow Gtk3 to close the window directly
1027 return undef;
1028 });
1029  
1030 } else {
1031  
1032 $self->winBox->signal_connect('delete-event' => sub {
1033  
1034 # Prompt the user for confirmation, if required
1035 if ($self->winType eq 'main' && ! $self->checkConnectedSessions()) {
1036  
1037 # Don't close the 'main' window
1038 return 1;
1039 }
1040  
1041 # Prevent Gtk3 from taking action directly. Instead redirect the request to
1042 # $self->winDestroy, which does things like resetting a portion of the workspace
1043 # grid, as well as actually destroying the window
1044 return $self->winDestroy();
1045 });
1046 }
1047  
1048 return 1;
1049 }
1050  
1051 sub setKeyPressEvent {
1052  
1053 # Called by $self->winSetup
1054 # Set up a ->signal_connect to watch out for certain key presses
1055 #
1056 # Expected arguments
1057 # (none besides $self)
1058 #
1059 # Return values
1060 # 'undef' on improper arguments or if the ->signal_connect doesn't interfere with the key
1061 # press
1062 # 1 if the ->signal_connect does interfere with the key press, or when the
1063 # ->signal_connect is first set up
1064  
1065 my ($self, $check) = @_;
1066  
1067 # Check for improper arguments
1068 if (defined $check) {
1069  
1070 return $axmud::CLIENT->writeImproper($self->_objClass . '->setKeyPressEvent', @_);
1071 }
1072  
1073 $self->winBox->signal_connect('key-press-event' => sub {
1074  
1075 my ($widget, $event) = @_;
1076  
1077 # Local variables
1078 my (
1079 $keycode, $standard, $string, $directFlag, $stripObj, $paneObj, $tabObj,
1080 $splitScreenMode, $textView, $slice, $clipboard, $vAdjust, $high, $length,
1081 $modValue, $entryText, $bufferObj, $startIter, $endIter,
1082 @list,
1083 );
1084  
1085 # Get the system keycode for this keypress
1086 $keycode = Gtk3::Gdk::keyval_name($event->keyval);
1087 # Translate it into a standard Axmud keycode
1088 $standard = $axmud::CLIENT->reverseKeycode($keycode);
1089  
1090 # If it's a CTRL, SHIFT, ALT or ALT-GR keypress, set IVs
1091 if ($standard eq 'ctrl') {
1092  
1093 $self->ivPoke('ctrlKeyFlag', TRUE);
1094 $self->ivPoke('modifierKeyFlag', TRUE);
1095  
1096 } elsif ($standard eq 'shift') {
1097  
1098 $self->ivPoke('shiftKeyFlag', TRUE);
1099 $self->ivPoke('modifierKeyFlag', TRUE);
1100  
1101 } elsif ($standard eq 'alt') {
1102  
1103 $self->ivPoke('altKeyFlag', TRUE);
1104 $self->ivPoke('modifierKeyFlag', TRUE);
1105  
1106 } elsif ($standard eq 'alt_gr') {
1107  
1108 $self->ivPoke('altGrKeyFlag', TRUE);
1109 $self->ivPoke('modifierKeyFlag', TRUE);
1110 }
1111  
1112 # Now, create a keycode string, containing a sequence of keycodes (for example, the F5
1113 # key creates a keycode string containing a single keycode - 'F5' - but CTRL+SHIFT+F5
1114 # produces the keycode string 'ctrl shift f5')
1115 if ($self->ctrlKeyFlag) {
1116  
1117 if ($standard ne 'ctrl') {
1118  
1119 push (@list, 'ctrl');
1120 }
1121 }
1122  
1123 if ($self->shiftKeyFlag) {
1124  
1125 if ($standard ne 'shift') {
1126  
1127 push (@list, 'shift');
1128 }
1129 }
1130  
1131 if ($self->altKeyFlag) {
1132  
1133 if ($standard ne 'alt') {
1134  
1135 push (@list, 'alt');
1136 }
1137 }
1138  
1139 if ($self->altGrKeyFlag) {
1140  
1141 if ($standard ne 'alt_gr') {
1142  
1143 push (@list, 'alt_gr');
1144 }
1145 }
1146  
1147 push (@list, $standard);
1148  
1149 # (Below, use a keycode string, consisting of one or more standard keycodes separated by
1150 # a space)
1151 $string = '' . join(' ', @list);
1152  
1153 # Get this window's entry strip object (if any)
1154 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::Entry');
1155  
1156 # In blind mode, and if this is a 'main' window, hijack the cursor keys and the escape
1157 # key for navigating the text-to-speech buffer
1158 # The user can bypass the hijack by holding down the shift key, for example by using
1159 # SHIFT+UP to navigate the command buffer
1160 if (
1161 (
1162 ($axmud::BLIND_MODE_FLAG && $axmud::CLIENT->ttsHijackFlag)
1163 || (! $axmud::BLIND_MODE_FLAG && $axmud::CLIENT->ttsForceHijackFlag)
1164 )
1165 && $self->visibleSession
1166 && $axmud::CLIENT->ivExists('ttsHijackKeycodeHash', $string)
1167 && ! $self->shiftKeyFlag
1168 ) {
1169 return $self->visibleSession->pseudoCmd(
1170 $axmud::CLIENT->ivShow('ttsHijackKeycodeHash', $string),
1171 $self->pseudoCmdMode,
1172 );
1173 }
1174  
1175 # Check that direct keys are enabled, if this is a 'main' window
1176 if ($self->visibleSession) {
1177  
1178 if (
1179 $self->visibleSession->currentWorld->ivExists(
1180 'termOverrideHash',
1181 'useDirectKeysFlag',
1182 )
1183 ) {
1184 $directFlag = $self->visibleSession->currentWorld->ivShow(
1185 'termOverrideHash',
1186 'useDirectKeysFlag',
1187 );
1188  
1189 } else {
1190  
1191 $directFlag = $axmud::CLIENT->useDirectKeysFlag;
1192 }
1193 }
1194  
1195 # If direct keys are enabled, send certain keycode strings direct to the world
1196 if ($directFlag && $self->visibleSession) {
1197  
1198 if (
1199 (
1200 $axmud::CLIENT->ivExists('constDirectAppKeysHash', $string)
1201 && (
1202 $self->visibleSession->ctrlKeypadMode eq 'alternate'
1203 || $self->visibleSession->ctrlCursorMode eq 'application'
1204 )
1205 && $self->visibleSession->put(
1206 $axmud::CLIENT->ivShow('constDirectAppKeysHash', $string),
1207 )
1208 ) || (
1209 $axmud::CLIENT->ivExists('constDirectAltKeysHash', $string)
1210 && $self->visibleSession->ctrlKeypadMode eq 'alternate'
1211 && $self->visibleSession->put(
1212 $axmud::CLIENT->ivShow('constDirectAltKeysHash', $string),
1213 )
1214 ) || (
1215 $axmud::CLIENT->ivExists('constDirectKeysHash', $string)
1216 && $self->visibleSession->put(
1217 $axmud::CLIENT->ivShow('constDirectKeysHash', $string),
1218 )
1219 )
1220 ) {
1221 # Return 1 to show that we have interfered with this keypress
1222 return 1;
1223  
1224 } elsif (
1225 $self->visibleSession->specialEchoMode eq 'enabled'
1226 && (! $stripObj || ! $stripObj->specialPreserveFlag)
1227 && $axmud::CLIENT->ivExists('constDirectSpecialKeysHash', $string)
1228 ) {
1229 # Warn the entry strip object about a backspace, which should modify a partial
1230 # world command it's been storing
1231 if ($stripObj && ! $stripObj->specialPreserveFlag && $string eq 'backspace') {
1232  
1233 $stripObj->applyBackspace();
1234 }
1235  
1236 if (
1237 $self->visibleSession->put(
1238 $axmud::CLIENT->ivShow('constDirectSpecialKeysHash', $string),
1239 )
1240 ) {
1241 # Return 1 to show that we have interfered with this keypress
1242 return 1;
1243 }
1244 }
1245 }
1246  
1247 # We don't want to call GA::Session->checkMacros for every keypress (that would be
1248 # inefficient)
1249 # Instead, call it if this is a 'main' window, and if this keycode string is being used
1250 # by any macro in any session (not perfectly efficient, but better)
1251 if (
1252 $self->visibleSession
1253 && $axmud::CLIENT->ivExists('activeKeycodeHash', $string)
1254 && $self->visibleSession->checkMacros($string)
1255 ) {
1256 # Return 1 to show that we have interfered with this keypress (by firing a macro)
1257 return 1;
1258 }
1259  
1260 # If no macro fired as a result of the keypress, then we can process some special keys
1261  
1262 # The first pane object in the entry strip object's ->paneObjList is the one to which
1263 # keypresses are applied
1264 if ($stripObj) {
1265  
1266 $paneObj = $stripObj->ivFirst('paneObjList');
1267  
1268 } else {
1269  
1270 # If there's no entry, then use the first pane object created in this window
1271 $paneObj = $self->findTableObj('pane');
1272 }
1273  
1274 if ($paneObj) {
1275  
1276 # Get the pane's visible tab and the scrollable Gtk3::Textview
1277 $tabObj = $paneObj->getVisibleTab();
1278 if ($tabObj) {
1279  
1280 $splitScreenMode = $tabObj->textViewObj->splitScreenMode;
1281 if ($splitScreenMode eq 'split') {
1282 $textView = $tabObj->textViewObj->textView2;
1283 } else {
1284 $textView = $tabObj->textViewObj->textView;
1285 }
1286 }
1287 }
1288  
1289 # The CTRL+C combination tends to be CTRL+SHIFT+C in Gtk, which is very inconvenient.
1290 # Implement a quick-and-dirty CTRL+C instead
1291 if ($string eq 'ctrl c' && $tabObj) {
1292  
1293 ($startIter, $endIter) = $tabObj->textViewObj->buffer->get_selection_bounds();
1294 if (defined $endIter) {
1295  
1296 $slice = $tabObj->textViewObj->buffer->get_slice($startIter, $endIter, FALSE);
1297 if (defined $slice && $slice ne '') {
1298  
1299 $clipboard = Gtk3::Clipboard::get(Gtk3::Gdk::Atom::intern('CLIPBOARD', 0));
1300 if ($clipboard) {
1301  
1302 $clipboard->set_text($slice);
1303  
1304 # Return 1 to show that we have interfered with this keypress
1305 return 1;
1306 }
1307 }
1308 }
1309  
1310 # If the page up/page down/home/end keys have been pressed, scroll the vertical
1311 # scrollbar containing the textview object
1312 } elsif (
1313 (
1314 $standard eq 'page_up' || $standard eq 'page_down' || $standard eq 'home'
1315 || $standard eq 'end'
1316 )
1317 && $tabObj
1318 && $axmud::CLIENT->useScrollKeysFlag
1319 ) {
1320 $vAdjust = $textView->get_vadjustment();
1321  
1322 # Get the lowest and highest vertical positions of the scrollbar, and the distance
1323 # between them
1324 $high = ($vAdjust->get_upper() - $vAdjust->get_page_size());
1325 $length = $high - $vAdjust->get_lower();
1326 $modValue = $vAdjust->get_value();
1327  
1328 # Set the new position of the vertical scrollbar (assuming one is visible)
1329 if ($length) {
1330  
1331 if (
1332 $axmud::CLIENT->autoSplitKeysFlag
1333 && $modValue >= $high
1334 && (
1335 (
1336 $splitScreenMode ne 'split'
1337 && ($standard eq 'page_up' || $standard eq 'home')
1338 ) || (
1339 $splitScreenMode eq 'split'
1340 && ($standard eq 'page_down' || $standard eq 'end')
1341 )
1342 )
1343 ) {
1344 # Engage/disengage the textview object's split screen mode, if necessary
1345 $paneObj->toggleSplitScreen();
1346  
1347 } else {
1348  
1349 if ($standard eq 'page_up') {
1350  
1351 # Scroll up
1352 if (! $axmud::CLIENT->smoothScrollKeysFlag) {
1353 $modValue -= $vAdjust->get_page_size();
1354 } else {
1355 $modValue -= $vAdjust->get_page_increment();
1356 }
1357  
1358 if ($modValue < 0) {
1359  
1360 $modValue = 0;
1361 }
1362  
1363 } elsif ($standard eq 'page_down') {
1364  
1365 # Scroll down
1366 if (! $axmud::CLIENT->smoothScrollKeysFlag) {
1367 $modValue += $vAdjust->get_page_size();
1368 } else {
1369 $modValue += $vAdjust->get_page_increment();
1370 }
1371  
1372 if ($modValue > $high) {
1373  
1374 $modValue = $high;
1375 }
1376  
1377 } elsif ($standard eq 'home') {
1378  
1379 # Scroll to top
1380 $modValue = 0;
1381  
1382 } else {
1383  
1384 # (End key) scroll to bottom
1385 $modValue = $high;
1386 }
1387  
1388 $vAdjust->set_value($modValue);
1389 }
1390 }
1391  
1392 # Return 1 to show that we have interfered with this keypress
1393 return 1;
1394  
1395 # If the up/down/tab arrow keys have been pressed and the client's auto-complete mode is
1396 # on (i.e. set to 'auto'), apply auto-complete or navigate through command buffers
1397 # However, CTRL+TAB switches between tabs in the pane object. If there's an entry strip
1398 # object, that object specifies which of multiple pane objects to use; if there's no
1399 # strip object, the first pane object created in the window is used
1400 # TAB can be used instead of CTRL+TAB if there is no entry strip object in the window
1401 } elsif ($standard eq 'up' || $standard eq 'down' || $standard eq 'tab') {
1402  
1403 if (
1404 ($self->ctrlKeyFlag || ! $stripObj)
1405 && $standard eq 'tab'
1406 && $paneObj
1407 && $paneObj->notebook
1408 && $axmud::CLIENT->useSwitchKeysFlag
1409 ) {
1410 $paneObj->switchVisibleTab();
1411  
1412 # Return 1 to show that we have interfered with this keypress
1413 return 1;
1414  
1415 } elsif (
1416 (! $self->modifierKeyFlag || ($self->shiftKeyFlag && $axmud::BLIND_MODE_FLAG))
1417 && $self->visibleSession
1418 && $stripObj
1419 && $stripObj->entry
1420 && $axmud::CLIENT->autoCompleteMode eq 'auto'
1421 && $axmud::CLIENT->useCompleteKeysFlag
1422 ) {
1423 $entryText = $stripObj->entry->get_text();
1424 if (! defined $stripObj->originalEntryText) {
1425  
1426 $stripObj->set_originalEntryText($entryText);
1427 }
1428  
1429 if ($standard eq 'tab') {
1430  
1431 # Check the instruction/world command buffer for matching instructions/world
1432 # commands so we can auto-complete the instruction/world command displayed
1433 # in the command entry box
1434 $bufferObj = $self->visibleSession->autoCompleteBuffer(
1435 $entryText,
1436 $stripObj->originalEntryText,
1437 );
1438  
1439 } else {
1440  
1441 # Navigate through the instruction/world command buffer to find the
1442 # instruction/world command to display in the command entry box
1443 $bufferObj = $self->visibleSession->navigateBuffer($standard);
1444 }
1445  
1446 if ($bufferObj) {
1447  
1448 # Display this previous instruction in the command entry box, and select
1449 # all text
1450 if ($axmud::CLIENT->autoCompleteType eq 'instruct') {
1451 $stripObj->entry->set_text($bufferObj->instruct);
1452 } else {
1453 $stripObj->entry->set_text($bufferObj->cmd);
1454 }
1455  
1456 $stripObj->entry->grab_focus();
1457  
1458 # In blind mode only, read allowed the selected command
1459 if ($axmud::BLIND_MODE_FLAG && $stripObj->entry->get_text() =~ m/\w/) {
1460  
1461 $axmud::CLIENT->tts(
1462 'Selected command: ' . $stripObj->entry->get_text(),
1463 'system',
1464 'system',
1465 $self->visibleSession,
1466 );
1467 }
1468  
1469 } else {
1470  
1471 # The returned $bufferObj will be 'undef' (when GA::Client->autoCompleteMode
1472 # = 'auto') when the buffer contains nothing shorter than the text in the
1473 # command entry box
1474 # $bufferObj will also be 'undef' if the buffer object is missing, for some
1475 # reason
1476 $stripObj->entry->set_text('');
1477 }
1478  
1479 # Return 1 to show that we have interfered with this keypress
1480 return 1;
1481 }
1482 }
1483  
1484 # Return 'undef' to show that we haven't interfered with this keypress
1485 return undef;
1486 });
1487  
1488 return 1;
1489 }
1490  
1491 sub setKeyReleaseEvent {
1492  
1493 # Called by $self->winSetup
1494 # Set up a ->signal_connect to watch out for certain key releases
1495 #
1496 # Expected arguments
1497 # (none besides $self)
1498 #
1499 # Return values
1500 # 'undef' on improper arguments or if the ->signal_connect doesn't interfere with the key
1501 # release
1502 # 1 if the ->signal_connect does interfere with the key release, or when the
1503 # ->signal_connect is first set up
1504  
1505 my ($self, $check) = @_;
1506  
1507 # Check for improper arguments
1508 if (defined $check) {
1509  
1510 return $axmud::CLIENT->writeImproper($self->_objClass . '->setKeyReleaseEvent', @_);
1511 }
1512  
1513 $self->winBox->signal_connect('key-release-event' => sub {
1514  
1515 my ($widget, $event) = @_;
1516  
1517 # Local variables
1518 my ($keycode, $standard);
1519  
1520 # Get the system keycode for this keypress
1521 $keycode = Gtk3::Gdk::keyval_name($event->keyval);
1522 # Translate it into a standard Axmud keycode
1523 $standard = $axmud::CLIENT->reverseKeycode($keycode);
1524  
1525 # If it's a CTRL, SHIFT, ALT or ALT-GR keypress, set IVs
1526 if ($standard eq 'ctrl') {
1527 $self->ivPoke('ctrlKeyFlag', FALSE);
1528 } elsif ($standard eq 'shift') {
1529 $self->ivPoke('shiftKeyFlag', FALSE);
1530 } elsif ($standard eq 'alt') {
1531 $self->ivPoke('altKeyFlag', FALSE);
1532 } elsif ($standard eq 'alt_gr') {
1533 $self->ivPoke('altGrKeyFlag', FALSE);
1534 }
1535  
1536 if (
1537 ! $self->ctrlKeyFlag
1538 && ! $self->shiftKeyFlag
1539 && ! $self->altKeyFlag
1540 && ! $self->altGrKeyFlag
1541 ) {
1542 $self->ivPoke('modifierKeyFlag', FALSE);
1543 }
1544  
1545 # Return 'undef' to show that we haven't interfered with this keypress
1546 return undef;
1547 });
1548  
1549 return 1;
1550 }
1551  
1552 sub setConfigureEvent {
1553  
1554 # Called by $self->winEnable
1555 # Set up a ->signal_connect to watch out for changes in the window size and position
1556 #
1557 # Expected arguments
1558 # (none besides $self)
1559 #
1560 # Return values
1561 # 'undef' on improper arguments
1562 # 1 otherwise
1563  
1564 my ($self, $check) = @_;
1565  
1566 # Check for improper arguments
1567 if (defined $check) {
1568  
1569 return $axmud::CLIENT->writeImproper($self->_objClass . '->setConfigureEvent', @_);
1570 }
1571  
1572 $self->winBox->signal_connect('configure-event' => sub {
1573  
1574 my ($widget, $event) = @_;
1575  
1576 # Has the window size actually changed, or just its position?
1577 if (
1578 ! defined $self->actualWinWidth # Windows size checked for the first time
1579 || $event->width != $self->actualWinWidth
1580 || $event->height != $self->actualWinHeight
1581 ) {
1582 $self->ivPoke('actualWinWidth', $event->width);
1583 $self->ivPoke('actualWinHeight', $event->height);
1584 }
1585  
1586 # Every textview object (GA::Obj::TextView) in this window must update its size IVs,
1587 # which informs the GA::Session (so it can send NAWS data to the world)
1588 foreach my $textViewObj ($axmud::CLIENT->desktopObj->ivValues('textViewHash')) {
1589  
1590 if ($textViewObj->winObj eq $self) {
1591  
1592 # Update the IVs once the changes have been rendered
1593 $textViewObj->set_sizeUpdateFlag();
1594 }
1595 }
1596  
1597 # Let the GA::Client store the most recent size and position for a window of this
1598 # ->winName, if it needs to
1599 if ($self->winWidget) {
1600  
1601 $axmud::CLIENT->add_storeGridPosn(
1602 $self,
1603 $self->winWidget->get_position(),
1604 $self->winWidget->get_size(),
1605 );
1606 }
1607  
1608 # Without returning 'undef', the window's strip/table objects aren't resized along with
1609 # the window
1610 return undef;
1611 });
1612  
1613 return 1;
1614 }
1615  
1616 sub setWindowStateEvent {
1617  
1618 # Called by $self->winEnable
1619 # Set up a ->signal_connect to watch out for when the window is maximised and unmaximised
1620 #
1621 # Expected arguments
1622 # (none besides $self)
1623 #
1624 # Return values
1625 # 'undef' on improper arguments
1626 # 1 otherwise
1627  
1628 my ($self, $check) = @_;
1629  
1630 # Check for improper arguments
1631 if (defined $check) {
1632  
1633 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWindowStateEvent', @_);
1634 }
1635  
1636 $self->winBox->signal_connect('window-state-event' => sub {
1637  
1638 # When the window is maximised and unmaximised, gauges in the gauge box (if visible) are
1639 # not redrawn properly. This block of code fixes that problem (but I don't know why it
1640 # works)
1641  
1642 my ($widget, $event) = @_;
1643  
1644 if ($event->changed_mask() =~ m/maximized/) {
1645  
1646 # This code makes sure textview(s) in pane object(s) are scrolled to the bottom
1647 # after un-maximising a window (otherwise, the scrollbar position moves
1648 # confusingly)
1649 if (! $self->maximisedFlag) {
1650  
1651 $self->ivPoke('maximisedFlag', TRUE);
1652  
1653 } else {
1654  
1655 $self->ivPoke('maximisedFlag', FALSE);
1656 $self->rescrollTextViews();
1657 }
1658 }
1659 });
1660 }
1661  
1662 sub setFocusInEvent {
1663  
1664 # Called by $self->winEnable
1665 # Set up a ->signal_connect to watch out for the 'internal' window receiving the focus,
1666 # which should be redirected towards the GA::Strip::Entry object's Gtk3::Entry (if there
1667 # is one)
1668 #
1669 # Expected arguments
1670 # (none besides $self)
1671 #
1672 # Return values
1673 # 'undef' on improper arguments
1674 # 1 otherwise
1675  
1676 my ($self, $check) = @_;
1677  
1678 # Check for improper arguments
1679 if (defined $check) {
1680  
1681 return $axmud::CLIENT->writeImproper($self->_objClass . '->setFocusInEvent', @_);
1682 }
1683  
1684 $self->winBox->signal_connect('focus-in-event' => sub {
1685  
1686 my ($widget, $event) = @_;
1687  
1688 # Update IVs
1689 $self->ivPoke('focusFlag', TRUE);
1690  
1691 # Update the command entry box (if visible)
1692 my $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::Entry');
1693 if ($stripObj && $stripObj->entry) {
1694  
1695 $stripObj->entry->grab_focus();
1696 }
1697  
1698 # For 'main' windows, check active hook interfaces for all sessions using this window
1699 # and fire hooks that are using the 'get_focus' hook event
1700 if ($self->visibleSession) {
1701  
1702 foreach my $session ($axmud::CLIENT->listSessions()) {
1703  
1704 if ($session->mainWin && $session->mainWin eq $self) {
1705  
1706 $session->checkHooks('get_focus');
1707 }
1708 }
1709 }
1710 });
1711  
1712 return 1;
1713 }
1714  
1715 sub setFocusOutEvent {
1716  
1717 # Called by $self->winEnable
1718 # Set up a ->signal_connect to watch out for the 'internal' window losing the focus
1719 #
1720 # Expected arguments
1721 # (none besides $self)
1722 #
1723 # Return values
1724 # 'undef' on improper arguments
1725 # 1 otherwise
1726  
1727 my ($self, $check) = @_;
1728  
1729 # Check for improper arguments
1730 if (defined $check) {
1731  
1732 return $axmud::CLIENT->writeImproper($self->_objClass . '->setFocusInEvent', @_);
1733 }
1734  
1735 $self->winBox->signal_connect('focus-out-event' => sub {
1736  
1737 my ($widget, $event) = @_;
1738  
1739 # Update IVs
1740 $self->ivPoke('focusFlag', FALSE);
1741  
1742 # For 'main' windows, check active hook interfaces for all sessions using this window
1743 # and fire hooks that are using the 'lose_focus' hook event
1744 if ($self->visibleSession) {
1745  
1746 foreach my $session ($axmud::CLIENT->listSessions()) {
1747  
1748 if ($session->mainWin && $session->mainWin eq $self) {
1749  
1750 $session->checkHooks('lose_focus');
1751 }
1752 }
1753 }
1754  
1755 # When the window loses focus, we no longer track SHIFT, ALT, CTRL or NUM LOCK
1756 # keypresses. Set IVs
1757 $self->ivPoke('shiftKeyFlag', FALSE);
1758 $self->ivPoke('altKeyFlag', FALSE);
1759 $self->ivPoke('altGrKeyFlag', FALSE);
1760 $self->ivPoke('ctrlKeyFlag', FALSE);
1761 $self->ivPoke('modifierKeyFlag', FALSE);
1762 });
1763  
1764 return 1;
1765 }
1766  
1767 # Other functions
1768  
1769 sub updateColourScheme {
1770  
1771 # Called by GA::Cmd::UpdateColourScheme->do (usually after a colour scheme is modified) and
1772 # by GA::Cmd::SetXTerm->do (when the xterm colour cube is switched)
1773 # Also called by $self->redrawWidgets, to neutralise Gtk3's charming tendency to redraw all
1774 # our textviews the wrong colour
1775 # Checks all textview objects in all pane objects in this window's Gtk3::Grid and updates
1776 # colours for any textview objects that use the specified colour scheme
1777 #
1778 # Expected arguments
1779 # (none besides $self)
1780 #
1781 # Optional arguments
1782 # $colourScheme - The name of the colour scheme (matches a key in
1783 # GA::Client->colourSchemeHash). If 'undef', all pane objects are
1784 # updated using their existing colour scheme
1785 # $noDrawFlag - TRUE when called by $self->redrawWidgets, meaning that the pane
1786 # objects are told not to call GA::Win::Generic->winShowAll or
1787 # GA::Obj::Desktop->updateWidgets as they normally would, so that
1788 # ->redrawWidgets can do it when ready. FALSE (or 'undef') otherwise
1789 #
1790 # Return values
1791 # 'undef' on improper arguments
1792 # 1 on success
1793  
1794 my ($self, $colourScheme, $noDrawFlag, $check) = @_;
1795  
1796 # Check for improper arguments
1797 if (defined $check) {
1798  
1799 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateColourScheme', @_);
1800 }
1801  
1802 # If $colourScheme was specified, check it's a recognised colour scheme
1803 if (defined $colourScheme) {
1804  
1805 if (! $axmud::CLIENT->ivExists('colourSchemeHash', $colourScheme)) {
1806  
1807 # Update all textview objects
1808 $colourScheme = undef;
1809 }
1810 }
1811  
1812 foreach my $tableObj ($self->tableStripObj->ivValues('tableObjHash')) {
1813  
1814 if ($tableObj->type eq 'pane') {
1815  
1816 $tableObj->updateColourScheme($colourScheme, $noDrawFlag);
1817 }
1818 }
1819  
1820 return 1;
1821 }
1822  
1823 sub applyColourScheme {
1824  
1825 # Called by GA::Cmd::ApplyColourScheme->do
1826 # Applies a colour scheme to all textview objects in all pane objects in this window's
1827 # Gtk3::Grid, replacing any colour schemes used before
1828 #
1829 # Expected arguments
1830 # $colourScheme - The name of the colour scheme to apply (matches a key in
1831 # GA::Client->colourSchemeHash)
1832 #
1833 # Return values
1834 # 'undef' on improper arguments or if $colourScheme doesn't exist
1835 # 1 on success
1836  
1837 my ($self, $colourScheme, $check) = @_;
1838  
1839 # Check for improper arguments
1840 if (defined $check) {
1841  
1842 return $axmud::CLIENT->writeImproper($self->_objClass . '->applyColourScheme', @_);
1843 }
1844  
1845 # Check that $colourScheme exists
1846 if (! $axmud::CLIENT->ivExists('colourSchemeHash', $colourScheme)) {
1847  
1848 return undef;
1849 }
1850  
1851 foreach my $tableObj ($self->tableStripObj->ivValues('tableObjHash')) {
1852  
1853 if ($tableObj->type eq 'pane') {
1854  
1855 $tableObj->applyColourScheme(
1856 undef, # Apply to all tabs in the pane object
1857 $colourScheme,
1858 );
1859 }
1860 }
1861  
1862 return 1;
1863 }
1864  
1865 sub rescrollTextViews {
1866  
1867 # Can be called by anyting
1868 # After a change in position of any window widgets, make sure any textview(s) in pane
1869 # object(s) are scrolled to the bottom (this saves a lot of user frustration)
1870 #
1871 # Expected arguments
1872 # (none besides $self)
1873 #
1874 # Return values
1875 # 'undef' on improper arguments or if this isn't the 'main' window
1876 # 1 otherwise
1877  
1878 my ($self, $check) = @_;
1879  
1880 # Local variables
1881 my $stripObj;
1882  
1883 # Check for improper arguments
1884 if (defined $check) {
1885  
1886 return $axmud::CLIENT->writeImproper($self->_objClass . '->rescrollTextViews', @_);
1887 }
1888  
1889 foreach my $tableObj ($self->tableStripObj->ivValues('tableObjHash')) {
1890  
1891 if ($tableObj->type eq 'pane') {
1892  
1893 foreach my $tabObj ($tableObj->ivValues('tabObjHash')) {
1894  
1895 $tabObj->textViewObj->scrollToBottom();
1896 }
1897 }
1898 }
1899  
1900 # After drawing gauges or unmaximising the window, the focus is lost from the command entry
1901 # box, so restore it
1902 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::Entry');
1903 if ($stripObj && $stripObj->entry) {
1904  
1905 $stripObj->entry->grab_focus();
1906 }
1907  
1908 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->rescrollTextViews');
1909  
1910 return 1;
1911 }
1912  
1913 sub findTableObj {
1914  
1915 # Can be called by anything
1916 # Finds the first table object of a particular type created in the compulsory table strip
1917 # object, if there is one
1918 #
1919 # Expected arguments
1920 # $type - The type of table object; matches the table object's type (e.g. 'pane' for
1921 # pane objects)
1922 #
1923 # Return values
1924 # 'undef' on improper arguments or if there is no table object of the specified type in
1925 # the Gtk3::Grid
1926 # Otherwise returns the table object of the specified type with the lowest ->number
1927  
1928 my ($self, $type, $check) = @_;
1929  
1930 # Local variables
1931 my @tableObjList;
1932  
1933 # Check for improper arguments
1934 if (! defined $type || defined $check) {
1935  
1936 return $axmud::CLIENT->writeImproper($self->_objClass . '->findFirstTableObj', @_);
1937 }
1938  
1939 @tableObjList = sort {$a->number <=> $b->number}
1940 ($self->tableStripObj->ivValues('tableObjHash'));
1941  
1942 foreach my $tableObj (@tableObjList) {
1943  
1944 if ($tableObj->type eq $type) {
1945  
1946 return $tableObj;
1947 }
1948 }
1949  
1950 # No table object of the right $type found
1951 return undef;
1952 }
1953  
1954 sub setVisibleSession {
1955  
1956 # Called by GA::Table::Pane->respondVisibleTab, when a session's default tab becomes the
1957 # visible tab in that pane. Only called when this window is a 'main' window
1958 # Should not be called by anything else - call GA::Table::Pane->setVisibleTab instead
1959 #
1960 # Sets $self->visibleSession and performs a number of housekeeping duties
1961 #
1962 # Expected arguments
1963 # (none besides $self)
1964 #
1965 # Optional arguments
1966 # $session - The GA::Session that is the new visible session. If 'undef', there is no
1967 # visible session in this window
1968 #
1969 # Return values
1970 # 'undef' on improper arguments
1971 # 1 otherwise
1972  
1973 my ($self, $session, $check) = @_;
1974  
1975 # Local variables
1976 my ($tabObj, $paneObj, $visibleTabObj);
1977  
1978 # Check for improper arguments
1979 if (defined $check) {
1980  
1981 return $axmud::CLIENT->writeImproper($self->_objClass . '->setVisibleSession', @_);
1982 }
1983  
1984 # This function shouldn't be called unless this is a 'main' window
1985 if ($self->winType ne 'main') {
1986  
1987 return $self->writeError(
1988 'Cannot set a visible session outside a \'main\' window',
1989 $self->_objClass . '->setVisibleSession',
1990 );
1991 }
1992  
1993 # Cease navigating through instruction/world command buffers in all windows (if the user has
1994 # been doing that using the 'up'/'down' arrow keys in any window)
1995 $axmud::CLIENT->set_instructBufferPosn();
1996 $axmud::CLIENT->set_cmdBufferPosn();
1997 foreach my $otherSession ($axmud::CLIENT->listSessions()) {
1998  
1999 $otherSession->set_instructBufferPosn();
2000 $otherSession->set_cmdBufferPosn();
2001 }
2002  
2003 # No visible session
2004 if (! $session) {
2005  
2006 # Update certain strip objects in any 'internal' window used by the old visible session
2007 # (if any; the TRUE flag means 'return 'internal' windows only)
2008 foreach my $winObj (
2009 $axmud::CLIENT->desktopObj->listSessionGridWins($self->visibleSession, TRUE)
2010 ) {
2011 # Update information stored in the window's connection info strip, if visible
2012 $winObj->setHostLabel('');
2013 $winObj->setTimeLabel('');
2014 # Reset the window's entry box and blinkers, if visible
2015 $winObj->resetEntry();
2016 $winObj->resetBlinkers();
2017 }
2018  
2019 # Update the GA::Client's IVs
2020 if (
2021 $axmud::CLIENT->currentSession
2022 && $self->visibleSession
2023 && $axmud::CLIENT->currentSession eq $self->visibleSession
2024 ) {
2025 $axmud::CLIENT->setCurrentSession();
2026 }
2027  
2028 # Update this window's IVs
2029 $self->ivUndef('visibleSession');
2030 if ($self->winType eq 'main') {
2031  
2032 $self->ivUndef('workspaceGridObj');
2033 }
2034  
2035 # New visible session
2036 } else {
2037  
2038 # If this window is a 'main' window shared by all sessions...
2039 if (
2040 $axmud::CLIENT->shareMainWinFlag
2041 && $self->visibleSession
2042 && $self->visibleSession ne $session
2043 ) {
2044 # ...need to hide windows on the former visible session's workspace grids (though
2045 # obviously not the shared 'main' window)
2046 $axmud::CLIENT->desktopObj->hideGridWins($self->visibleSession);
2047 # The new visible session's windows, on the other hand, need to be un-hidden
2048 $axmud::CLIENT->desktopObj->revealGridWins($session);
2049  
2050 # Fire any hooks that are using the 'not_visible' hook event
2051 $self->visibleSession->checkHooks('not_visible', $session->number);
2052 }
2053  
2054 # Update the GA::Client's IVs
2055 # ->currentSession is modified only when a 'main' window that's in focus changes its
2056 # ->visibleSession (exception - if the IV isn't set at all, set it regardless of
2057 # whether this window has the focus, or not)
2058 if (! $axmud::CLIENT->currentSession || $self->focusFlag) {
2059  
2060 $axmud::CLIENT->setCurrentSession($session);
2061 }
2062  
2063 # Update this window's IVs
2064 $self->ivPoke('visibleSession', $session);
2065 # For 'main' windows only, find the workspace grid used by this session (might be a
2066 # shared grid), and update the IV
2067 if ($self->winType eq 'main' && $self->workspaceObj) {
2068  
2069 # (In case the grid can't be found, use a default 'undef' value)
2070 $self->ivUndef('workspaceGridObj');
2071  
2072 OUTER: foreach my $gridObj (
2073 sort {$a->number <=> $b->number}
2074 ($self->workspaceObj->ivValues('gridHash'))
2075 ) {
2076 if (
2077 ! defined $gridObj->owner # Shared workspace grid
2078 || $gridObj->owner eq $session
2079 ) {
2080 $self->ivPoke('workspaceGridObj', $gridObj);
2081 last OUTER;
2082 }
2083 }
2084 }
2085  
2086 # In case the change of visible session isn't the result of the user clicking a
2087 # session's default tab, make the new visible session's default tab the visible one.
2088 # If that default tab is a simple tab, then there's nothing to do
2089 # ($session->defaultTabObj won't be set yet, if $session->start is still executing)
2090 if ($session->defaultTabObj) {
2091  
2092 $paneObj = $session->defaultTabObj->paneObj;
2093 $tabObj = $paneObj->findSession($session);
2094 $visibleTabObj = $paneObj->getVisibleTab();
2095 if ($paneObj->notebook && $tabObj && $visibleTabObj && $tabObj ne $visibleTabObj) {
2096  
2097 $paneObj->setVisibleTab($tabObj);
2098 }
2099 }
2100  
2101 # If the session's tab label is in a different colour, meaning that text had been
2102 # received from the world but hadn't been viewed by the user yet, reset the flag to
2103 # show that the text is now visible to the user
2104 $session->reset_showNewTextFlag();
2105  
2106 # Update information stored in the 'main' window's connection info strip, if visible
2107 $self->setHostLabel($session->getHostLabelText());
2108 $self->setTimeLabel($session->getTimeLabelText());
2109  
2110 # Update certain strip objects in any 'internal' window used by the new visible session
2111 # (if any; the TRUE flag means 'return 'internal' windows only)
2112 foreach my $winObj ($axmud::CLIENT->desktopObj->listSessionGridWins($session, TRUE)) {
2113  
2114 # Reset the 'internal' window's entry box and blinkers, if any
2115 $winObj->resetEntry();
2116 $winObj->resetBlinkers();
2117 }
2118  
2119 # Fire any hooks that are using the 'visible_session' hook event
2120 $session->checkHooks('visible_session', undef);
2121 # Fire any hooks that are using the 'change_visible' hook event
2122 foreach my $otherSession ($axmud::CLIENT->listSessions()) {
2123  
2124 if ($otherSession ne $session) {
2125  
2126 $otherSession->checkHooks('change_visible', $session->number);
2127 }
2128 }
2129 }
2130  
2131 # Update all 'internal' windows
2132 foreach my $winObj ($axmud::CLIENT->desktopObj->listGridWins()) {
2133  
2134 if (
2135 $winObj->winType eq 'main'
2136 || $winObj->winType eq 'protocol'
2137 || $winObj->winType eq 'custom'
2138 ) {
2139 # Sensitise/desensitise menu items in 'internal' windows, as appropriate
2140 $winObj->restrictMenuBars();
2141 $winObj->restrictToolbars();
2142 # Update the gauge box, if visible
2143 $winObj->updateGauges();
2144  
2145 # Sensitise or desensitise widgets, as appropriate
2146 $winObj->setWidgetsIfSession();
2147 # Update widgets, as appropriate
2148 $winObj->setWidgetsChangeSession();
2149  
2150 # Make any changes visible
2151 $winObj->winShowAll($self->_objClass . '->setVisibleSession');
2152 }
2153 }
2154  
2155 return 1;
2156 }
2157  
2158 sub checkConnectedSessions {
2159  
2160 # Called by $self->setDeleteEvent
2161 # If the user tries to manually close a 'main' window, counts the number of connected
2162 # sessions (not including disconencted or 'connect offline' mode sessions) using this
2163 # window as their 'main' window
2164 # If any are found, prompts the user for confirmation (if the GA::Client flag requires us
2165 # to do that)
2166 #
2167 # Expected arguments
2168 # (none besides $self)
2169 #
2170 # Return values
2171 # 'undef' on improper arguments or if the window should not be closed
2172 # 1 if the window can be closed
2173  
2174 my ($self, $check) = @_;
2175  
2176 # Local variables
2177 my ($count, $choice, $msg);
2178  
2179 # Check for improper arguments
2180 if (defined $check) {
2181  
2182 return $axmud::CLIENT->writeImproper(
2183 $self->_objClass . '->checkConnectedSessions',
2184 @_,
2185 );
2186 }
2187  
2188 if (! $axmud::CLIENT->confirmCloseMainWinFlag) {
2189  
2190 # The window can be closed - no confirmation required
2191 return 1;
2192 }
2193  
2194 # Otherwise, count connected sessions
2195 $count = 0;
2196 foreach my $session ($axmud::CLIENT->ivValues('sessionHash')) {
2197  
2198 if (
2199 $session->mainWin
2200 && $session->mainWin eq $self
2201 && $session->status eq 'connected'
2202 ) {
2203 $count++;
2204 }
2205 }
2206  
2207 if ($count) {
2208  
2209 if ($count == 1) {
2210 $msg = '1 connected session';
2211 } else {
2212 $msg = $count . ' connected sessions';
2213 }
2214  
2215 $choice = $self->showMsgDialogue(
2216 'Close \'main\' window',
2217 'question',
2218 'This window is in use by ' . $msg . '. Are you sure you want to close it?',
2219 'yes-no',
2220 );
2221  
2222 if ($choice && $choice eq 'yes') {
2223  
2224 # Allow the window to close
2225 return 1;
2226  
2227 } else {
2228  
2229 # Don't allow the window to close
2230 return undef;
2231 }
2232  
2233 } else {
2234  
2235 # No connected sessions, allow the window to close
2236 return 1;
2237 }
2238 }
2239  
2240 sub updateGauges {
2241  
2242 # Called by various functions as a shortcut to GA::Strip::GaugeBox->updateGauges
2243 #
2244 # Expected arguments
2245 # (none besides $self)
2246 #
2247 # Return values
2248 # 'undef' on improper arguments
2249 # 1 otherwise
2250  
2251 my ($self, $winmapName, $check) = @_;
2252  
2253 # Local variables
2254 my $stripObj;
2255  
2256 # Check for improper arguments
2257 if (defined $check) {
2258  
2259 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateGauges', @_);
2260 }
2261  
2262 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
2263 if ($stripObj) {
2264  
2265 $stripObj->updateGauges();
2266 }
2267  
2268 return 1;
2269 }
2270  
2271 sub resetEntry {
2272  
2273 # Called by GA::Client->set_autoCompleteMode, ->set_autoCompleteType and
2274 # ->set_autoCompleteParent or any other code which needs to reset the entry box (for some
2275 # reason)
2276 # The user can press the 'up'/'down' arrow keys to change the command displayed in the
2277 # GA::Strip::Entry's command entry box
2278 # The new command depends on various client IVs. If those IVs are changed, the entry box
2279 # must be reset
2280 #
2281 # Expected arguments
2282 # (none besides $self)
2283 #
2284 # Return values
2285 # 'undef' on improper arguments
2286 # 1 otherwise
2287  
2288 my ($self, $check) = @_;
2289  
2290 # Local variables
2291 my $stripObj;
2292  
2293 # Check for improper arguments
2294 if (defined $check) {
2295  
2296 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetEntry', @_);
2297 }
2298  
2299 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::Entry');
2300 if ($stripObj) {
2301  
2302 $stripObj->set_originalEntryText();
2303 if ($stripObj->entry) {
2304  
2305 $stripObj->entry->set_text('');
2306 }
2307 }
2308  
2309 return 1;
2310 }
2311  
2312 sub setHostLabel {
2313  
2314 # Can be called by anything (but usually called by various functions in GA::Session, and
2315 # also by $self->setVisibleSession)
2316 # Sets the text used in the GA::Strip::ConnectInfo strip object to display information
2317 # about the current host (world)
2318 # If the strip object hasn't been added to the window, still store the text in
2319 # $self->hostLabelText so it's available instantly if the strip object is added later
2320 #
2321 # Expected arguments
2322 # (none besides $self)
2323 #
2324 # Optional arguments
2325 # $text - The text to display in this label. If set to 'undef', an empty string is
2326 # displayed
2327 # $tooltip - The text to display as a tooltip. If set to 'undef', no tooltip is
2328 # displayed
2329 #
2330 # Return values
2331 # 'undef' on improper arguments
2332 # 1 otherwise
2333  
2334 my ($self, $text, $tooltip, $check) = @_;
2335  
2336 # Local variables
2337 my $stripObj;
2338  
2339 # Check for improper arguments
2340 if (defined $check) {
2341  
2342 return $axmud::CLIENT->writeImproper($self->_objClass . '->setHostLabel', @_);
2343 }
2344  
2345 if (! $text) {
2346  
2347 $text = '';
2348 }
2349  
2350 $self->ivPoke('hostLabelText', $text);
2351  
2352 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::ConnectInfo');
2353 if ($stripObj) {
2354  
2355 $stripObj->set_hostLabel($text, $tooltip);
2356 }
2357  
2358 return 1;
2359 }
2360  
2361 sub setTimeLabel {
2362  
2363 # Can be called by anything (but usually called by GA::Client->spinClientLoop, various
2364 # functions in GA::Session, and also by $self->setVisibleSession)
2365 # Sets the text used in the GA::Strip::ConnectInfo strip object to display information about
2366 # the current time
2367 # If the strip object hasn't been added to the window, still store the text in
2368 # $self->timeLabelText so it's available instantly if the strip object is added later
2369 #
2370 # Expected arguments
2371 # (none besides $self)
2372 #
2373 # Optional arguments
2374 # $text - The text to display in this label. If set to 'undef', an empty string is
2375 # displayed
2376 #
2377 # Return values
2378 # 'undef' on improper arguments
2379 # 1 otherwise
2380  
2381 my ($self, $text, $check) = @_;
2382  
2383 # Local variables
2384 my $stripObj;
2385  
2386 # Check for improper arguments
2387 if (defined $check) {
2388  
2389 return $axmud::CLIENT->writeImproper($self->_objClass . '->setTimeLabel', @_);
2390 }
2391  
2392 if (! $text) {
2393  
2394 $text = '';
2395 }
2396  
2397 $self->ivPoke('timeLabelText', $text);
2398  
2399 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::ConnectInfo');
2400 if ($stripObj) {
2401  
2402 $stripObj->set_timeLabel($text);
2403 }
2404  
2405 return 1;
2406 }
2407  
2408 sub resetBlinkers {
2409  
2410 # Can be called by anything (but usually called by GA::Session->reactDisconnect and
2411 # $self->setVisibleSession)
2412 # Resets the blinkers drawn in the GA::Strip::ConnectInfo strip object
2413 #
2414 # Expected arguments
2415 # (none besides $self)
2416 #
2417 # Return values
2418 # 'undef' on improper arguments
2419 # 1 otherwise
2420  
2421 my ($self, $check) = @_;
2422  
2423 # Local variables
2424 my $stripObj;
2425  
2426 # Check for improper arguments
2427 if (defined $check) {
2428  
2429 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetBlinkers', @_);
2430 }
2431  
2432 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::ConnectInfo');
2433 if ($stripObj) {
2434  
2435 $stripObj->drawBlinker(-1, FALSE);
2436 }
2437  
2438 return 1;
2439 }
2440  
2441 sub setMainWinTitle {
2442  
2443 # Called by GA::Client->checkMainWinTitles to change each 'main' window's title to something
2444 # like '*Axmud' to show that there are client files that need to be saved, or to something
2445 # like 'Axmud' to show there are no client files that need to be saved
2446 # (Session files are handles separately by GA::Session->checkTabLabels)
2447 #
2448 # Expected arguments
2449 # (none besides $self)
2450 #
2451 # Optional arguments
2452 # $flag - If set to TRUE, show an asterisk. If set to FALSE (or 'undef'), don't show
2453 # an asterisk
2454 #
2455 # Return values
2456 # 'undef' on improper arguments or if this window isn't a 'main' window
2457 # 1 otherwise
2458  
2459 my ($self, $flag, $check) = @_;
2460  
2461 # Check for improper arguments
2462 if (defined $check) {
2463  
2464 return $axmud::CLIENT->writeImproper($self->_objClass . '->setMainWinTitle', @_);
2465 }
2466  
2467 # Ignore this function call for other types of 'grid' window
2468 if ($self->winType eq 'main') {
2469  
2470 return undef;
2471  
2472 # Set the window title
2473 } elsif ($flag) {
2474  
2475 $self->winWidget->set_title('*' . $axmud::SCRIPT);
2476  
2477 } else {
2478  
2479 $self->winWidget->set_title($axmud::SCRIPT);
2480 }
2481  
2482 return 1;
2483 }
2484  
2485 sub setWinTitle {
2486  
2487 # Can be called by anything to change the text in the window's title bar
2488 # Does nothing if this window is a 'main' window (code should call $self->setMainWinTitle
2489 # instead)
2490 #
2491 # Expected arguments
2492 # $text - The text to use
2493 #
2494 # Return values
2495 # 'undef' on improper arguments or if this window isn't a 'main' window
2496 # 1 otherwise
2497  
2498 my ($self, $text, $check) = @_;
2499  
2500 # Check for improper arguments
2501 if (defined $check) {
2502  
2503 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWinTitle', @_);
2504 }
2505  
2506 if ($self->enabledFlag && $self->winType ne 'main' && $self->winWidget eq $self->winBox) {
2507  
2508 $self->winWidget->set_title($text);
2509 }
2510  
2511 return 1;
2512 }
2513  
2514 sub restrictMenuBars {
2515  
2516 # Called by GA::Obj::Desktop->restrictWidgets
2517 # Sensitise or desensitise the menu bar in this 'internal' window, depending on current
2518 # conditions. (Don't do anything if this window doesn't use a strip object for a menu bar)
2519 #
2520 # Expected arguments
2521 # (none besides $self)
2522 #
2523 # Return values
2524 # 'undef' on improper arguments or if this window doesn't use a strip object for a menu
2525 # bar
2526 # 1 otherwise
2527  
2528 my ($self, $check) = @_;
2529  
2530 # Local variables
2531 my (
2532 $stripObj, $openFlag, $setupFlag,
2533 @list, @sensitiseList, @desensitiseList,
2534 );
2535  
2536 # Check for improper arguments
2537 if (defined $check) {
2538  
2539 return $axmud::CLIENT->writeImproper($self->_objClass . '->restrictMenuBars', @_);
2540 }
2541  
2542 # Get the strip object
2543 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::MenuBar');
2544 if (! $stripObj) {
2545  
2546 # Nothing to sensitise/desensitise
2547 return undef;
2548 }
2549  
2550 # Test whether this is a 'main' window with a visible session whose status is 'connected' or
2551 # 'offline' (for the sake of efficiency)
2552 if (
2553 $self->visibleSession
2554 && (
2555 $self->visibleSession->status eq 'connected'
2556 || $self->visibleSession->status eq 'offline'
2557 )
2558 ) {
2559 $openFlag = TRUE;
2560 }
2561  
2562 # Test whether the setup wizwin is open (in which case, almost everything is desensitised)
2563 OUTER: foreach my $winObj ($axmud::CLIENT->desktopObj->ivValues('freeWinHash')) {
2564  
2565 if ($winObj->isa('Games::Axmud::WizWin::Setup')) {
2566  
2567 $setupFlag = TRUE;
2568  
2569 # In addition, the following menu items are desensitised
2570 push (@desensitiseList,
2571 # 'World' column
2572 'connect', 'stop_client',
2573 # 'Edit' column
2574 'test_pattern',
2575 # 'Help' column
2576 'help', 'about', 'credits', 'license',
2577 );
2578  
2579 last OUTER;
2580 }
2581 }
2582  
2583 # Menu bar items that require a 'main' window with a visible session
2584 @list = (
2585 # 'World' column
2586 'reconnect', 'reconnect_offline',
2587 'xconnect', 'xconnect_offline',
2588 'quit_all',
2589 'exit_all',
2590 'stop_session',
2591 # 'File' column
2592 'test_file',
2593 'show_files', 'show_file_meta',
2594 # 'Axbasic' column
2595 'check_script', 'edit_script',
2596 # 'Plugins' column
2597 'load_plugin', 'show_plugin',
2598 );
2599  
2600 if (! $setupFlag && $self->visibleSession) {
2601 push (@sensitiseList, @list);
2602 } else {
2603 push (@desensitiseList, @list);
2604 }
2605  
2606 # Menu bar items that require a 'main' window with a visible session whose status is
2607 # 'connected' or 'offline'
2608 @list = (
2609 # 'World' column
2610 'login',
2611 'quit', 'qquit',
2612 'exit', 'xxit',
2613 # 'File' column
2614 'load_all', 'load_file',
2615 'save_all', 'save', 'save_options',
2616 'import_files',
2617 # 'export_all_files', 'export_file',
2618 'export_file',
2619 'import_data',
2620 'export_data',
2621 'backup_restore_data',
2622 'disable_world_save', 'disable_save_load',
2623 # 'Edit' column
2624 'edit_quick_prefs', 'edit_client_prefs', 'edit_session_prefs',
2625 'edit_current_world',
2626 'run_locator_wiz', 'edit_world_model', 'edit_dictionary',
2627 'simulate',
2628 # 'Interfaces' column
2629 'active_interfaces',
2630 'show_triggers', 'show_aliases', 'show_macros', 'show_timers', 'show_hooks',
2631 'show_cmds', 'show_routes',
2632 # 'Tasks' column
2633 'freeze_tasks', 'start_new_task', 'chat_task', 'chat_task_start',
2634 'run_locator_wiz_2',
2635 'other_task',
2636 # 'Display' column
2637 'open_automapper', 'open_object_viewer',
2638 'activate_grid', 'activate_grid_with', 'reset_grid', 'disactivate_grid',
2639 'win_components', 'current_layer', 'window_storage',
2640 'test_controls', 'test_panels',
2641 # 'Commands' column
2642 'repeat_cmd', 'repeat_second', 'repeat_interval',
2643 'cancel_repeat',
2644 # 'Axbasic' column
2645 'run_script', 'run_script_task',
2646 );
2647  
2648 if (! $setupFlag && $openFlag) {
2649 push (@sensitiseList, @list);
2650 } else {
2651 push (@desensitiseList, @list);
2652 }
2653  
2654 # Menu bar items that require a 'main' window with a visible session whose status is
2655 # 'connected' or 'offline' and whose ->currentGuild is defined
2656 @list = (
2657 # 'Edit' column
2658 'edit_current_guild',
2659 # 'Interfaces' column
2660 'guild_triggers', 'guild_aliases', 'guild_macros', 'guild_timers', 'guild_hooks',
2661 'guild_cmds', 'guild_routes',
2662 );
2663  
2664 if (! $setupFlag && $openFlag && $self->visibleSession->currentGuild) {
2665 push (@sensitiseList, @list);
2666 } else {
2667 push (@desensitiseList, @list);
2668 }
2669  
2670 # Menu bar items that require a 'main' window with a visible session whose status is
2671 # 'connected' or 'offline' and whose ->currentRace is defined
2672 @list = (
2673 # 'Edit' column
2674 'edit_current_race',
2675 # 'Interfaces' column
2676 'race_triggers', 'race_aliases', 'race_macros', 'race_timers', 'race_hooks',
2677 'race_cmds', 'race_routes',
2678 );
2679  
2680 if (! $setupFlag && $openFlag && $self->visibleSession->currentRace) {
2681 push (@sensitiseList, @list);
2682 } else {
2683 push (@desensitiseList, @list);
2684 }
2685  
2686 # Menu bar items that require a 'main' window with a visible session whose status is
2687 # 'connected' or 'offline' and whose ->currentChar is defined
2688 @list = (
2689 # 'Edit' column
2690 'edit_current_char',
2691 # 'Interfaces' column
2692 'char_triggers', 'char_aliases', 'char_macros', 'char_timers', 'char_hooks',
2693 'char_cmds', 'char_routes',
2694 );
2695  
2696 if (! $setupFlag && $openFlag && $self->visibleSession->currentChar) {
2697 push (@sensitiseList, @list);
2698 } else {
2699 push (@desensitiseList, @list);
2700 }
2701  
2702 # Menu bar items that require a 'main' window with a visible session whose status is
2703 # 'connected' or 'offline' and $stripObj->saveAllSessionsFlag set to FALSE
2704 @list = (
2705 # 'File' column
2706 'save_file',
2707 );
2708  
2709 if (! $setupFlag && $openFlag && ! $stripObj->saveAllSessionsFlag) {
2710 push (@sensitiseList, @list);
2711 } else {
2712 push (@desensitiseList, @list);
2713 }
2714  
2715 # Menu bar items that require a 'main' window with a visible session whose status is
2716 # 'connected' or 'offline' and whose ->recordingPausedFlag is FALSE
2717 @list = (
2718 # 'Recordings' column
2719 'start_stop_recording',
2720 );
2721  
2722 if (! $setupFlag && $openFlag && ! $self->visibleSession->recordingPausedFlag) {
2723 push (@sensitiseList, @list);
2724 } else {
2725 push (@desensitiseList, @list);
2726 }
2727  
2728 # Menu bar items that require a 'main' window with a visible session whose status is
2729 # 'connected' or 'offline' and whose ->recordingFlag is TRUE
2730 @list = (
2731 # 'Recordings' column
2732 'pause_recording',
2733 );
2734  
2735 if (! $setupFlag && $openFlag && $self->visibleSession->recordingFlag) {
2736 push (@sensitiseList, @list);
2737 } else {
2738 push (@desensitiseList, @list);
2739 }
2740  
2741 # Menu bar items that require a 'main' window with a visible session whose status is
2742 # 'connected' or 'offline' and a Chat task
2743 @list = (
2744 # 'Tasks' column
2745 'edit_chat_task',
2746 );
2747  
2748 if (! $setupFlag && $openFlag && $self->visibleSession->chatTask) {
2749 push (@sensitiseList, @list);
2750 } else {
2751 push (@desensitiseList, @list);
2752 }
2753  
2754 # Menu bar items that require a 'main' window with a visible session whose status is
2755 # 'connected' or 'offline' and a Channels task
2756 @list = (
2757 # 'Tasks' column
2758 'channels_task',
2759 );
2760  
2761 if (! $setupFlag && $openFlag && $self->visibleSession->channelsTask) {
2762  
2763 push (@sensitiseList, @list);
2764 push (@desensitiseList, 'channels_task_start');
2765  
2766 } else {
2767  
2768 push (@sensitiseList, 'channels_task_start');
2769 push (@desensitiseList, @list);
2770 }
2771  
2772 # Menu bar items that require a 'main' window with a visible session whose status is
2773 # 'connected' or 'offline' and a Compass task
2774 @list = (
2775 # 'Tasks' column
2776 'compass_task',
2777 );
2778  
2779 if (! $setupFlag && $openFlag && $self->visibleSession->compassTask) {
2780  
2781 push (@sensitiseList, @list);
2782 push (@desensitiseList, 'compass_task_start');
2783  
2784 } else {
2785  
2786 push (@sensitiseList, 'compass_task_start');
2787 push (@desensitiseList, @list);
2788 }
2789  
2790 # Menu bar items that require a 'main' window with a visible session whose status is
2791 # 'connected' or 'offline' and NO Condition task
2792 @list = (
2793 # 'Tasks' column
2794 'condition_task_start',
2795 );
2796  
2797 if (! $setupFlag && $openFlag && ! defined $self->visibleSession->conditionTask) {
2798 push (@sensitiseList, @list);
2799 } else {
2800 push (@desensitiseList, @list);
2801 }
2802  
2803 # Menu bar items that require a 'main' window with a visible session whose status is
2804 # 'connected' or 'offline' and a Divert task
2805 @list = (
2806 # 'Tasks' column
2807 'divert_task',
2808 );
2809  
2810 if (! $setupFlag && $openFlag && $self->visibleSession->divertTask) {
2811  
2812 push (@sensitiseList, @list);
2813 push (@desensitiseList, 'divert_task_start');
2814  
2815 } else {
2816  
2817 push (@sensitiseList, 'divert_task_start');
2818 push (@desensitiseList, @list);
2819 }
2820  
2821 # Menu bar items that require a 'main' window with a visible session whose status is
2822 # 'connected' or 'offline' and an Inventory task
2823 @list = (
2824 # 'Tasks' column
2825 'inventory_task',
2826 );
2827  
2828 if (! $setupFlag && $openFlag && $self->visibleSession->inventoryTask) {
2829  
2830 push (@sensitiseList, @list);
2831 push (@desensitiseList, 'inventory_task_start');
2832  
2833 } else {
2834  
2835 push (@sensitiseList, 'inventory_task_start');
2836 push (@desensitiseList, @list);
2837 }
2838  
2839 # Menu bar items that require a 'main' window with a visible session whose status is
2840 # 'connected' or 'offline' and a Locator task
2841 @list = (
2842 # 'Tasks' column
2843 'locator_task',
2844 );
2845  
2846 if (! $setupFlag && $openFlag && $self->visibleSession->locatorTask) {
2847  
2848 push (@sensitiseList, @list);
2849 push (@desensitiseList, 'locator_task_start');
2850  
2851 } else {
2852  
2853 push (@sensitiseList, 'locator_task_start');
2854 push (@desensitiseList, @list);
2855 }
2856  
2857 # Menu bar items that require a 'main' window with a visible session whose status is
2858 # 'connected' or 'offline' and a Status task
2859 @list = (
2860 # 'Tasks' column
2861 'status_task',
2862 );
2863  
2864 if (! $setupFlag && $openFlag && $self->visibleSession->statusTask) {
2865  
2866 push (@sensitiseList, @list);
2867 push (@desensitiseList, 'status_task_start');
2868  
2869 } else {
2870  
2871 push (@sensitiseList, 'status_task_start');
2872 push (@desensitiseList, @list);
2873 }
2874  
2875 # Menu bar items that require a 'main' window with a visible session whose status is
2876 # 'connected' or 'offline' and a Watch task
2877 @list = (
2878 # 'Tasks' column
2879 'watch_task',
2880 );
2881  
2882 if (! $setupFlag && $openFlag && $self->visibleSession->watchTask) {
2883  
2884 push (@sensitiseList, @list);
2885 push (@desensitiseList, 'watch_task_start');
2886  
2887 } else {
2888  
2889 push (@sensitiseList, 'watch_task_start');
2890 push (@desensitiseList, @list);
2891 }
2892  
2893 # Menu bar items that require a require a 'main' window with a visible session whose status
2894 # is 'connected' or 'offline' and GA::Session->recordingFlag
2895 @list = (
2896 # 'Recordings' column
2897 'pause_resume_recording',
2898 'recording_add_line', 'recording_add_break',
2899 'recording_set_insertion', 'recording_cancel_insertion',
2900 'recording_delete_line', 'recording_delete_multi', 'recording_delete_last',
2901 );
2902  
2903 if (! $setupFlag && $openFlag && $self->visibleSession->recordingFlag) {
2904 push (@sensitiseList, @list);
2905 } else {
2906 push (@desensitiseList, @list);
2907 }
2908  
2909 # Menu bar items that require a require a 'main' window with a visible session whose status
2910 # is 'connected' or 'offline', and either GA::Session->recordingFlag or ->recordingList
2911 @list = (
2912 # 'Recordings' column
2913 'show_recording', 'copy_recording',
2914 );
2915  
2916 if (
2917 ! $setupFlag
2918 && $openFlag
2919 && ($self->visibleSession->recordingFlag || $self->visibleSession->recordingList)
2920 ) {
2921 push (@sensitiseList, @list);
2922 } else {
2923 push (@desensitiseList, @list);
2924 }
2925  
2926 # Menu bar items that require GA::Client->browserCmd
2927 @list = (
2928 # 'Help' column
2929 'go_website',
2930 );
2931  
2932 if (! $setupFlag && $axmud::CLIENT->browserCmd) {
2933 push (@sensitiseList, @list);
2934 } else {
2935 push (@desensitiseList, @list);
2936 }
2937  
2938 # Sensitise/desensitise menu bar items
2939 $stripObj->sensitiseWidgets(@sensitiseList);
2940 $stripObj->desensitiseWidgets(@desensitiseList);
2941  
2942 # All menu items added by plugins require a 'main' window with a visible session, and the
2943 # plugin itself must be must be enabled
2944 foreach my $plugin ($stripObj->ivKeys('pluginMenuItemHash')) {
2945  
2946 my ($widget, $pluginObj);
2947  
2948 $widget = $stripObj->ivShow('pluginMenuItemHash', $plugin);
2949 $pluginObj = $axmud::CLIENT->ivShow('pluginHash', $plugin);
2950  
2951 if (! $setupFlag && $self->visibleSession && $pluginObj->enabledFlag) {
2952 $widget->set_sensitive(TRUE);
2953 } else {
2954 $widget->set_sensitive(FALSE);
2955 }
2956 }
2957  
2958 return 1;
2959 }
2960  
2961 sub restrictToolbars {
2962  
2963 # Called by GA::Obj::Desktop->restrictWidgets
2964 # Sensitise or desensitise the toolbar in this 'internal' window, depending on current
2965 # conditions. (Don't do anything if this window doesn't use a strip object for a toolbar)
2966 #
2967 # Expected arguments
2968 # (none besides $self)
2969 #
2970 # Return values
2971 # 'undef' on improper arguments or if this window doesn't use a strip object for a toolbar
2972 # 1 otherwise
2973  
2974 my ($self, $check) = @_;
2975  
2976 # Local variables
2977 my (
2978 $stripObj,
2979 @list, @sensitiseList, @desensitiseList,
2980 );
2981  
2982 # Check for improper arguments
2983 if (defined $check) {
2984  
2985 return $axmud::CLIENT->writeImproper($self->_objClass . '->restrictToolbars', @_);
2986 }
2987  
2988 # Get the strip object
2989 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::Toolbar');
2990 if (! $stripObj) {
2991  
2992 # Nothing to sensitise/desensitise
2993 return undef;
2994 }
2995  
2996 # Test whether the setup wizwin is open (in which case, everything is desensitised)
2997 OUTER: foreach my $winObj ($axmud::CLIENT->desktopObj->ivValues('freeWinHash')) {
2998  
2999 if ($winObj->isa('Games::Axmud::WizWin::Setup')) {
3000  
3001 foreach my $widget ($stripObj->toolbarWidgetList) {
3002  
3003 $widget->set_sensitive(FALSE);
3004 }
3005  
3006 return 1;
3007 }
3008 }
3009  
3010 # Toolbar buttons that require a 'main' window with a visible session
3011 @list = $stripObj->ivKeys('requireSessionHash');
3012  
3013 if ($self->visibleSession) {
3014 push (@sensitiseList, @list);
3015 } else {
3016 push (@desensitiseList, @list);
3017 }
3018  
3019 # Toolbar buttons that require a 'main' window with a visible session whose status is
3020 # 'connected' or 'offline'
3021 @list = $stripObj->ivKeys('requireConnectHash');
3022  
3023 if (
3024 $self->visibleSession
3025 && (
3026 $self->visibleSession->status eq 'connected'
3027 || $self->visibleSession->status eq 'offline'
3028 )
3029 ) {
3030 push (@sensitiseList, @list);
3031 } else {
3032 push (@desensitiseList, @list);
3033 }
3034  
3035 # Sensitise/desensitise toolbar items
3036 $stripObj->sensitiseWidgets(@sensitiseList);
3037 $stripObj->desensitiseWidgets(@desensitiseList);
3038  
3039 return 1;
3040 }
3041  
3042 sub setWidgetsIfSession {
3043  
3044 # Called by $self->setVisibleSession
3045 # Calls each strip object (and, for GA::Strip::Table, any child table objects) so they can
3046 # sensitise or desensitise their widgets, depending on whether this window has a
3047 # ->visibleSession, or not
3048 #
3049 # Expected arguments
3050 # (none besides $self)
3051 #
3052 # Return values
3053 # 'undef' on improper arguments
3054 # 1 otherwise
3055  
3056 my ($self, $check) = @_;
3057  
3058 # Local variables
3059 my $flag;
3060  
3061 # Check for improper arguments
3062 if (defined $check) {
3063  
3064 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWidgetsIfSession', @_);
3065 }
3066  
3067 if ($self->visibleSession) {
3068 $flag = TRUE;
3069 } else {
3070 $flag = FALSE;
3071 }
3072  
3073 foreach my $stripObj ($self->ivValues('stripHash')) {
3074  
3075 $stripObj->setWidgetsIfSession($flag);
3076 }
3077  
3078 return 1;
3079 }
3080  
3081 sub setWidgetsChangeSession {
3082  
3083 # Called by $self->setVisibleSession
3084 # Calls each strip object (and, for GA::Strip::Table, any child table objects) so they can
3085 # update their widgets when any 'main' window's ->visibleSession changes
3086 #
3087 # Expected arguments
3088 # (none besides $self)
3089 #
3090 # Return values
3091 # 'undef' on improper arguments
3092 # 1 otherwise
3093  
3094 my ($self, $check) = @_;
3095  
3096 # Check for improper arguments
3097 if (defined $check) {
3098  
3099 return $axmud::CLIENT->writeImproper(
3100 $self->_objClass . '->setWidgetsChangeSession',
3101 @_,
3102 );
3103 }
3104  
3105 foreach my $stripObj ($self->ivValues('stripHash')) {
3106  
3107 $stripObj->setWidgetsChangeSession();
3108 }
3109  
3110 return 1;
3111 }
3112  
3113 # Strip object functions
3114  
3115 sub resetWinmap {
3116  
3117 # Returns the window to its initial state by removing all table objects and strip objects,
3118 # and applying the specified winmap (which might be the same as the previous one)
3119 # Useful for 'main' windows when the 'main_wait' winmap should be applied, or replaced
3120 # after being replied
3121 # Probably not useful for other 'internal' windows, though if code needs to apply the
3122 # equivalent 'internal_wait' winmap and, at some later time, replace it with something
3123 # else, it can
3124 #
3125 # Expected arguments
3126 # $winmapName - The name of the new winmap
3127 #
3128 # Return values
3129 # 'undef' on improper arguments or if the specified winmap doesn't exist
3130 # 1 otherwise
3131  
3132 my ($self, $winmapName, $check) = @_;
3133  
3134 # Local variables
3135 my $winmapObj;
3136  
3137 # Check for improper arguments
3138 if (defined $check) {
3139  
3140 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetWinmap', @_);
3141 }
3142  
3143 # Check the specified winmap exists
3144 $winmapObj = $axmud::CLIENT->ivShow('winmapHash', $winmapName);
3145 if (! $winmapObj) {
3146  
3147 return undef;
3148 }
3149  
3150 # Remove all strip objects (table objects in the compulsory Gtk3::Grid are also destroyed)
3151 foreach my $stripObj ($self->ivValues('stripHash')) {
3152  
3153 $stripObj->objDestroy();
3154  
3155 if ($stripObj->visibleFlag) {
3156  
3157 $axmud::CLIENT->desktopObj->removeWidget($self->packingBox, $stripObj->packingBox);
3158 }
3159 }
3160  
3161 # Remove the Gtk3::HBox or Gtk3::VBox into which everything is packed
3162 $axmud::CLIENT->desktopObj->removeWidget($self->winBox, $self->packingBox);
3163  
3164 # Update IVs
3165 $self->ivUndef('packingBox');
3166 $self->ivEmpty('stripHash');
3167 $self->ivEmpty('firstStripHash');
3168 $self->ivPoke('stripCount', 0);
3169 $self->ivEmpty('stripList');
3170 $self->ivUndef('tableStripObj');
3171  
3172 $self->ivPoke('winmap', $winmapObj->name);
3173  
3174 # Set up the window with its strip objects and table objects as if the window had just been
3175 # created
3176 $self->drawWidgets();
3177 $self->winShowAll($self->_objClass . '->resetWinmap');
3178 # This should already be set
3179 $self->ivPoke('enabledFlag', TRUE);
3180  
3181 return 1;
3182 }
3183  
3184 sub getWinmap {
3185  
3186 # Called by $self->addStripObj and ->revealStripObj
3187 # If $self->winmap is set (to the name of a winmap object), returns the winmap object
3188 # (GA::Obj::Winmap) itself
3189 # Otherwise returns an appropirate default winmap object
3190 #
3191 # Expected arguments
3192 # (none besides $self)
3193 #
3194 # Return values
3195 # 'undef' on improper arguments
3196 # Otherwise returns a winmap object (GA::Obj::Winmap)
3197  
3198 my ($self, $check) = @_;
3199  
3200 # Local variables
3201 my $winmapObj;
3202  
3203 # Check for improper arguments
3204 if (defined $check) {
3205  
3206 return $axmud::CLIENT->writeImproper($self->_objClass . '->getWinmap', @_);
3207 }
3208  
3209 $winmapObj = $axmud::CLIENT->ivShow('winmapHash', $self->winmap);
3210 if (! $winmapObj) {
3211  
3212 if ($self->winType eq 'main') {
3213  
3214 if ($axmud::CLIENT->activateGridFlag) {
3215  
3216 $winmapObj = $axmud::CLIENT->ivShow(
3217 'winmapHash',
3218 $axmud::CLIENT->defaultEnabledWinmap,
3219 );
3220  
3221 } else {
3222  
3223 $winmapObj = $axmud::CLIENT->ivShow(
3224 'winmapHash',
3225 $axmud::CLIENT->defaultDisabledWinmap,
3226 );
3227 }
3228  
3229 } else {
3230  
3231 $winmapObj = $axmud::CLIENT->ivShow(
3232 'winmapHash',
3233 $axmud::CLIENT->defaultInternalWinmap,
3234 );
3235 }
3236 }
3237  
3238 return $winmapObj;
3239 }
3240  
3241 sub addStripObj {
3242  
3243 # Can be called by anything (strip objects are also created by $self->drawWidgets() )
3244 # Adds a strip object (inheriting from GA::Generic::Strip) to the list of strip objects that
3245 # can be displayed in this window (whether the Gtk widget is actually drawn, or not,
3246 # depends on the value of the strip object's ->visibleFlag)
3247 #
3248 # Expected arguments
3249 # $packageName - The package name for the strip object to add, e.g.
3250 # GA::Strip::GaugeBox. This function can't be used to add the
3251 # compulsory GA::Strip::Table which already exists
3252 #
3253 # Optional arguments
3254 # $index - The new strip object's position in the window. Strip objects are
3255 # stored in $self->stripList, in the order in which they're drawn
3256 # (which could be top to bottom, bottom to top, left to right or right
3257 # to left). $index specifies the position in that list at which the
3258 # new strip object is inserted. If $index is 0, the strip object is
3259 # inserted at the beginning of the list. If $index is 1, it's inserted
3260 # second, if $index is 2, it's inserted third, and so on. If $index is
3261 # -1, it's inserted last. If $index is 'undef', or if its index is
3262 # outside the list, the strip object is inserted at the beginning of
3263 # the list
3264 # %initHash - If specified, a reference to a hash containing arbitrary data to use
3265 # as the strip object's initialisation settings (may be an empty
3266 # hash). The strip object should use default initialisation settings
3267 # unless it can succesfully interpret one or more of the key-value
3268 # pairs in the hash, if there are any)
3269 #
3270 # Return values
3271 # 'undef' on improper arguments or if the strip object can't be added
3272 # Otherwise returns the strip object added
3273  
3274 my ($self, $packageName, $index, %initHash) = @_;
3275  
3276 # Local variables
3277 my ($winmapObj, $stripObj, $spacing, $posn, $gaugeStripObj);
3278  
3279 # Check for improper arguments
3280 if (! defined $packageName) {
3281  
3282 return $axmud::CLIENT->writeImproper($self->_objClass . '->addStripObj', @_);
3283 }
3284  
3285 # Get the winmap object specified by $self->winmap, or a default winmap, if $self->winmap
3286 # is 'undef'
3287 $winmapObj = $self->getWinmap();
3288  
3289 # Set the position in the ordered list of strip objects at which the new strip object will
3290 # be inserted
3291 if (
3292 ! defined $index
3293 || $index < -1 # Sanity check
3294 || $index >= scalar ($self->stripList)
3295 ) {
3296 $index = 0;
3297 }
3298  
3299 # Strip objects must inherit from GA::Generic::Strip and must exist (in the case of strip
3300 # objects loaded from a plugin)
3301 if (
3302 ! $packageName =~ m/^Games\:\:Axmud\:\:Strip\:\:/
3303 || ! $axmud::CLIENT->ivExists('customStripHash', $packageName)
3304 ) {
3305 return undef;
3306 }
3307  
3308 # Create the strip object
3309 $stripObj = $packageName->new($self->stripCount, $self, %initHash);
3310 if (! $stripObj) {
3311  
3312 return undef;
3313 }
3314  
3315 # Some strip objects are 'jealous' (only one can be opened per window). If so, and if
3316 # another strip object of this type has already been created, discard the new one
3317 if ($stripObj->jealousyFlag && $self->ivExists('firstStripHash', $packageName)) {
3318  
3319 return undef;
3320 }
3321  
3322 # Some strip objects can't be added in Axmud blind mode
3323 if (! $stripObj->blindFlag && $axmud::BLIND_MODE_FLAG) {
3324  
3325 return undef;
3326 }
3327  
3328 # Draw the strip object's widgets
3329 if (! $stripObj->objEnable($winmapObj)) {
3330  
3331 return undef;
3332  
3333 # (Most, but not all strip objects set a ->packingBox in their ->objEnable() function)
3334 } elsif ($stripObj->packingBox) {
3335  
3336 if ($stripObj->allowFocusFlag) {
3337 $stripObj->packingBox->set_can_focus(TRUE);
3338 } else {
3339 $stripObj->packingBox->set_can_focus(FALSE);
3340 }
3341 }
3342  
3343 # Make the strip object visible, if the flag is set
3344 if ($stripObj->visibleFlag) {
3345  
3346 # Pack the newly-visible strip, leaving a gap if it's not at the beginning or end of the
3347 # list
3348 # If $index is -1, it means 'pack at the end'
3349 if ($index == 0 || $index == -1) {
3350 $spacing = 0;
3351 } else {
3352 $spacing = $self->stripSpacingPixels;
3353 }
3354  
3355 if ($index > -1) {
3356  
3357 $self->packingBox->pack_start(
3358 $stripObj->packingBox,
3359 $stripObj->expandFlag,
3360 $stripObj->fillFlag,
3361 $spacing,
3362 );
3363  
3364 if ($index > 0) {
3365  
3366 $self->packingBox->reorder_child($stripObj->packingBox, $posn);
3367 }
3368  
3369 } else {
3370  
3371 $self->packingBox->pack_end(
3372 $stripObj->packingBox,
3373 $stripObj->expandFlag,
3374 $stripObj->fillFlag,
3375 $spacing,
3376 );
3377 }
3378 }
3379  
3380 # Update IVs
3381 $self->ivAdd('stripHash', $stripObj->number, $stripObj);
3382 if (! $self->ivExists('firstStripHash', $packageName)) {
3383  
3384 $self->ivAdd('firstStripHash', $packageName, $stripObj);
3385 }
3386  
3387 $self->ivIncrement('stripCount');
3388 $self->ivSplice('stripList', $index, 0, $stripObj);
3389  
3390 if ($packageName eq 'Games::Axmud::Strip::Table') {
3391  
3392 $self->ivPoke('tableStripObj', $stripObj);
3393 }
3394  
3395 # Notify all other strip objects of the new strip object's birth
3396 foreach my $otherStripObj (
3397 sort {$a->number <=> $b->number} ($self->ivValues('stripHash'))
3398 ) {
3399 if ($otherStripObj ne $stripObj) {
3400  
3401 $otherStripObj->notify_addStripObj($stripObj);
3402 }
3403 }
3404  
3405 # Sensitise/desensitise widgets according to current conditions
3406 $self->restrictMenuBars();
3407 $self->restrictToolbars();
3408  
3409 # Make everything visible
3410 $self->winShowAll($self->_objClass . '->addStripObj');
3411 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->addStripObj');
3412  
3413 # Adding/removing widgets upsets the position of the scrollbar in each tab's textview.
3414 # Make sure all the textviews are scrolled to the bottom
3415 $self->rescrollTextViews();
3416  
3417 # Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
3418 # themselves will have disappeared
3419 $gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
3420 if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
3421  
3422 $gaugeStripObj->updateGauges();
3423 # (Need to call this a second time, or the re-draw doesn't work...)
3424 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->addStripObj');
3425 }
3426  
3427 return $stripObj;
3428 }
3429  
3430 sub removeStripObj {
3431  
3432 # Can be called by anything
3433 # Removes a strip object (inheriting from GA::Generic::Strip) from the list of strip objects
3434 # that can be displayed in this window (whether the Gtk widget was actually drawn, or not,
3435 # depends on the value of the strip object's ->visibleFlag)
3436 # Can't be used to remove the compulsory GA::Strip::Table object
3437 #
3438 # Expected arguments
3439 # $stripObj - The strip object to remove
3440 #
3441 # Return values
3442 # 'undef' on improper arguments, if $stripObj is the compulsory GA::Strip::Table object
3443 # or if the object doesn't exist
3444 # 1 otherwise
3445  
3446 my ($self, $stripObj, $check) = @_;
3447  
3448 # Local variables
3449 my (
3450 $gaugeStripObj,
3451 @stripList, @resetList,
3452 );
3453  
3454 # Check for improper arguments
3455 if (! defined $stripObj || defined $check) {
3456  
3457 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeStripObj', @_);
3458 }
3459  
3460 # The GA::Strip::Table object is compulsory, also check that the strip object actually
3461 # exists in the window
3462 if (
3463 $stripObj->_objClass eq 'Games::Axmud::Strip::Table'
3464 || ! $self->ivExists('stripHash', $stripObj->number)
3465 ) {
3466 return undef
3467 }
3468  
3469 # Tell the strip object it's about to be removed, so it can do any necessary tidying up
3470 $stripObj->objDestroy();
3471 # Remove the Gtk3 widget that's contains the whole strip
3472 $axmud::CLIENT->desktopObj->removeWidget($self->packingBox, $stripObj->packingBox);
3473  
3474 # Remove the object by updating IVs
3475 $self->ivDelete('stripHash', $stripObj->number);
3476  
3477 foreach my $otherObj ($self->stripList) {
3478  
3479 if ($otherObj ne $stripObj) {
3480  
3481 push (@stripList, $otherObj);
3482 }
3483 }
3484  
3485 $self->ivPoke('stripList', @stripList);
3486  
3487 # $self->firstStripHash contains the earliest-created instance of this type of strip object.
3488 # Update or reset it
3489 $self->ivDelete('firstStripHash', $stripObj->_objClass);
3490 @resetList = sort {$a->number <=> $b->number} ($self->ivValues('stripHash'));
3491 OUTER: foreach my $otherObj (@resetList) {
3492  
3493 if ($otherObj->_objClass eq $stripObj->_objClass) {
3494  
3495 $self->ivAdd('firstStripHash', $otherObj->_objClass, $otherObj);
3496 last OUTER;
3497 }
3498 }
3499  
3500 # Notify all other strip objects of this strip object's demise
3501 foreach my $otherStripObj (
3502 sort {$a->number <=> $b->number} ($self->ivValues('stripHash'))
3503 ) {
3504 if ($otherStripObj ne $stripObj) {
3505  
3506 $otherStripObj->notify_removeStripObj($stripObj);
3507 }
3508 }
3509  
3510 # Sensitise/desensitise widgets according to current conditions
3511 $self->restrictMenuBars();
3512 $self->restrictToolbars();
3513  
3514 # Make everything visible
3515 $self->winShowAll($self->_objClass . '->removeStripObj');
3516 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->removeStripObj');
3517  
3518 # Hack to resolve a Gtk3 issue, in which a white area appears at the bottom of textviews
3519 # when the gauge strip object is removed (and possibly in similar situations)
3520 foreach my $tableObj ($self->tableStripObj->ivValues('tableObjHash')) {
3521  
3522 if ($tableObj->type eq 'pane') {
3523  
3524 foreach my $tabObj ($tableObj->ivValues('tabObjHash')) {
3525  
3526 $tabObj->textViewObj->insertNewLine();
3527 }
3528 }
3529 }
3530  
3531 # Adding/removing widgets upsets the position of the scrollbar in each tab's textview.
3532 # Make sure all the textviews are scrolled to the bottom
3533 $self->rescrollTextViews();
3534  
3535 # Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
3536 # themselves will have disappeared
3537 $gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
3538 if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
3539  
3540 $gaugeStripObj->updateGauges();
3541 # (Need to call this a second time, or the re-draw doesn't work...)
3542 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->removeStripObj');
3543 }
3544  
3545 return 1;
3546 }
3547  
3548 sub addStrip {
3549  
3550 # Convenient shortcut to $self->addStripObj, which expects a package name like
3551 # GA::Strip::GaugeBox as an argument
3552 #
3553 # This function accepts a string, which can be any of the following (case-insensitive):
3554 # 'menu' / 'menubar' / 'menu_bar' - adds a GA::Strip::MenuBar
3555 # 'tool' / 'toolbar' / 'tool_bar' - adds a GA::Strip::Toolbar
3556 # 'gauge' / 'gaugebox' / 'gauge_box' - adds a GA::Strip::GaugeBox
3557 # 'entry' - adds a GA::Strip::Entry
3558 # 'connect' / 'info' / 'connectinfo' / 'connect_info'
3559 # - adds a GA::Strip::ConnectInfo
3560 #
3561 # The string can also be a part of the package name itself. For example, if you create your
3562 # own GA::Strip::MyObject (inheriting from GA::Strip::Custom), then this function expects
3563 # the string 'MyObject' (case-sensitive)
3564 # NB This function is not able to check that the package actually exists, although Axmud's
3565 # built-in strip objects always exist
3566 # NB This function can't be used to add the compulsory GA::Strip::Table which already
3567 # exists
3568 #
3569 # Expected arguments
3570 # $string - The string described above
3571 #
3572 # Optional arguments
3573 # $index - The new strip object's position in the window. Strip objects are stored in
3574 # $self->stripList, in the order in which they're drawn (which could be
3575 # top to bottom, bottom to top, left to right or right to left). $index
3576 # specifies the position in that list at which the new strip object is
3577 # inserted. If $index is 0, the strip object is inserted at the beginning
3578 # of the list. If $index is 1, it's inserted second, if $index is 2, it's
3579 # inserted third, and so on. If $index is 'undef', or if its index is
3580 # outside the list, the strip object is inserted at the beginning of the
3581 # list
3582 #
3583 # Return values
3584 # 'undef' on improper arguments or if the strip object can't be added
3585 # Otherwise returns the strip object added
3586  
3587 my ($self, $string, $index, $check) = @_;
3588  
3589 # Local variables
3590 my $packageName;
3591  
3592 # Check for improper arguments
3593 if (! defined $string || defined $check) {
3594  
3595 return $axmud::CLIENT->writeImproper($self->_objClass . '->addStrip', @_);
3596 }
3597  
3598 # Convert $string into a package name
3599 $packageName = $self->convertPackageName($string);
3600 if (! $packageName || $packageName eq 'Games::Axmud::Strip::Table') {
3601  
3602 return undef;
3603  
3604 } else {
3605  
3606 return $self->addStripObj($packageName, $index);
3607 }
3608 }
3609  
3610 sub removeStrip {
3611  
3612 # Convenient shortcut to $self->removeStripObj, which expects a package name like
3613 # GA::Strip::GaugeBox as an argument
3614 #
3615 # This function accepts a string, which can be any of the following (case-insensitive):
3616 # 'menu' / 'menubar' / 'menu_bar' - adds a GA::Strip::MenuBar
3617 # 'tool' / 'toolbar' / 'tool_bar' - adds a GA::Strip::Toolbar
3618 # 'gauge' / 'gaugebox' / 'gauge_box' - adds a GA::Strip::GaugeBox
3619 # 'entry' - adds a GA::Strip::Entry
3620 # 'connect' / 'info' / 'connectinfo' / 'connect_info'
3621 # - adds a GA::Strip::ConnectInfo
3622 #
3623 # The string can also be a part of the package name itself. For example, if you create your
3624 # own GA::Strip::MyObject (inheriting from GA::Strip::Custom), then this function expects
3625 # the string 'MyObject' (case-sensitive)
3626 #
3627 # After converting the string into a package name, this function calls $self->removeStripObj
3628 # to remove the earliest-created instance of that strip object, if any exists
3629 # NB This function is not able to check that the package actually exists, although Axmud's
3630 # built-in strip objects always exist
3631 # NB This function can't be used to remove the compulsory GA::Strip::Table
3632 #
3633 # Expected arguments
3634 # $string - The string described above
3635 #
3636 # Return values
3637 # 'undef' on improper arguments or if no strip object is removed
3638 # 1 if a strip object is removed
3639  
3640 my ($self, $string, $check) = @_;
3641  
3642 # Local variables
3643 my ($packageName, $stripObj);
3644  
3645 # Check for improper arguments
3646 if (! defined $string || defined $check) {
3647  
3648 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeStrip', @_);
3649 }
3650  
3651 # Convert $string into a package name
3652 $packageName = $self->convertPackageName($string);
3653 if (! $packageName || $packageName eq 'Games::Axmud::Strip::Table') {
3654  
3655 return undef;
3656 }
3657  
3658 # Find the earliest-created instance of that strip object
3659 $stripObj = $self->ivShow('firstStripHash', $packageName);
3660 if (! $stripObj) {
3661  
3662 return undef;
3663  
3664 } else {
3665  
3666 return $self->removeStripObj($stripObj);
3667 }
3668 }
3669  
3670 sub hideStripObj {
3671  
3672 # Can be called by anything
3673 # Hides a visible strip object; the strip object remains in the list of strip objects this
3674 # window can display, but the Gtk widget itself is no longer drawn
3675 # Can't be used to hide the compulsory GA::Strip::Table object
3676 #
3677 # Expected arguments
3678 # $stripObj - The strip object to hide
3679 #
3680 # Return values
3681 # 'undef' on improper arguments, if $stripObj is the compulsory GA::Strip::Table object,
3682 # if the object doesn't exist or if it is already hidden
3683 # 1 otherwise
3684  
3685 my ($self, $stripObj, $check) = @_;
3686  
3687 # Local variables
3688 my $gaugeStripObj;
3689  
3690 # Check for improper arguments
3691 if (! defined $stripObj || defined $check) {
3692  
3693 return $axmud::CLIENT->writeImproper($self->_objClass . '->hideStripObj', @_);
3694 }
3695  
3696 # The GA::Strip::Table object is compulsory, also check that the strip object actually
3697 # exists in the window object's list of strip objects and is actually visible
3698 if (
3699 $stripObj->_objClass eq 'Games::Axmud::Strip::Table'
3700 || ! $self->ivExists('stripHash', $stripObj->number)
3701 || ! $stripObj->visibleFlag
3702 ) {
3703 return undef
3704 }
3705  
3706 # Remove the Gtk3 widget that contains the whole strip
3707 $axmud::CLIENT->desktopObj->removeWidget($self->packingBox, $stripObj->packingBox);
3708 # Update IVs
3709 $stripObj->set_visibleFlag(FALSE);
3710  
3711 # Sensitise/desensitise widgets according to current conditions
3712 $self->restrictMenuBars();
3713 $self->restrictToolbars();
3714  
3715 # Make everything visible
3716 $self->winShowAll($self->_objClass . '->hideStripObj');
3717 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->hideStripObj');
3718  
3719 # Hack to resolve a Gtk3 issue, in which a white area appears at the bottom of textviews
3720 # when the gauge strip object is removed (and possibly in similar situations)
3721 foreach my $tableObj ($self->tableStripObj->ivValues('tableObjHash')) {
3722  
3723 if ($tableObj->type eq 'pane') {
3724  
3725 foreach my $tabObj ($tableObj->ivValues('tabObjHash')) {
3726  
3727 $tabObj->textViewObj->insertNewLine();
3728 }
3729 }
3730 }
3731  
3732 # Adding/removing widgets upsets the position of the scrollbar in each tab's textview.
3733 # Make sure all the textviews are scrolled to the bottom
3734 $self->rescrollTextViews();
3735  
3736 # Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
3737 # themselves will have disappeared
3738 $gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
3739 if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
3740  
3741 $gaugeStripObj->updateGauges();
3742 # (Need to call this a second time, or the re-draw doesn't work...)
3743 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->hideStripObj');
3744 }
3745  
3746 return 1;
3747 }
3748  
3749 sub revealStripObj {
3750  
3751 # Can be called by anything
3752 # Reveals a hidden strip object; the strip object was still in the list of strip objects
3753 # this window can display, but the Gtk widget itself was not drawn, so draw it and add it
3754 # to the window
3755 #
3756 # Expected arguments
3757 # $stripObj - The strip object to reveal
3758 #
3759 # Return values
3760 # 'undef' on improper arguments, if the object doesn't exist, if it is already visible or
3761 # if there's an error in revealing it
3762 # 1 otherwise
3763  
3764 my ($self, $stripObj, $check) = @_;
3765  
3766 # Local variables
3767 my ($winmapObj, $count, $posn, $spacing, $gaugeStripObj);
3768  
3769 # Check for improper arguments
3770 if (! defined $stripObj || defined $check) {
3771  
3772 return $axmud::CLIENT->writeImproper($self->_objClass . '->revealStripObj', @_);
3773 }
3774  
3775 # Get the winmap object specified by $self->winmap, or a default winmap, if $self->winmap
3776 # is 'undef'
3777 $winmapObj = $self->getWinmap();
3778  
3779 # Check that the strip object actually exists in the window object's list of strip objects
3780 # and is actually hidden
3781 if (! $self->ivExists('stripHash', $stripObj->number) || $stripObj->visibleFlag) {
3782  
3783 return undef
3784 }
3785  
3786 # Find the strip object's position in the list of visible strip objects
3787 $count = 0;
3788 OUTER: foreach my $otherObj ($self->stripList) {
3789  
3790 if ($otherObj eq $stripObj) {
3791  
3792 $posn = $count;
3793 last OUTER;
3794  
3795 } elsif ($otherObj->visibleFlag) {
3796  
3797 $count++;
3798 }
3799 }
3800  
3801 if (! defined $posn) {
3802  
3803 # Strip object is missing (for some unlikely reason)
3804 return undef;
3805 }
3806  
3807 # Draw the strip object's widgets
3808 if (! $stripObj->objEnable($winmapObj)) {
3809  
3810 return undef;
3811 }
3812  
3813 # Pack the newly-visible strip, leaving a gap if it's not at the beginning or end of the
3814 # list
3815 if (! $count || $posn == ($count - 1)) {
3816 $spacing = 0;
3817 } else {
3818 $spacing = $self->stripSpacingPixels;
3819 }
3820  
3821 $self->packingBox->pack_start(
3822 $stripObj->packingBox,
3823 $stripObj->expandFlag,
3824 $stripObj->fillFlag,
3825 $spacing,
3826 );
3827  
3828 if ($posn != 0) {
3829  
3830 $self->packingBox->reorder_child($stripObj->packingBox, $posn);
3831 }
3832  
3833 # Update IVs
3834 $stripObj->set_visibleFlag(TRUE);
3835  
3836 # Sensitise/desensitise widgets according to current conditions
3837 $self->restrictMenuBars();
3838 $self->restrictToolbars();
3839  
3840 # Make everything visible
3841 $self->winShowAll($self->_objClass . '->revealStripObj');
3842 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->revealStripObj');
3843  
3844 # Adding/removing widgets upsets the position of the scrollbar in each tab's textview.
3845 # Make sure all the textviews are scrolled to the bottom
3846 $self->rescrollTextViews();
3847  
3848 # Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
3849 # themselves will have disappeared
3850 $gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
3851 if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
3852  
3853 $gaugeStripObj->updateGauges();
3854 # (Need to call this a second time, or the re-draw doesn't work...)
3855 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->revealStripObj');
3856 }
3857  
3858 return 1;
3859 }
3860  
3861 sub replaceStripObj {
3862  
3863 # Can be called by anything
3864 # If a strip object has been redrawn for any reason, replace the old Gtk widget with the
3865 # new one. The strip object's ->packingBox IV must already have been set to the new Gtk
3866 # widget before calling this function
3867 #
3868 # Expected arguments
3869 # $stripObj - The strip object to replace
3870 #
3871 # Return values
3872 # 'undef' on improper arguments, if the object doesn't exist or if it hidden
3873 # 1 otherwise
3874  
3875 my ($self, $stripObj, $check) = @_;
3876  
3877 # Local variables
3878 my ($count, $posn, $spacing, $gaugeStripObj);
3879  
3880 # Check for improper arguments
3881 if (! defined $stripObj || defined $check) {
3882  
3883 return $axmud::CLIENT->writeImproper($self->_objClass . '->replaceStripObj', @_);
3884 }
3885  
3886 # Check that the strip object actually exists in the window object's list of strip objects
3887 # and is actually visible
3888 if (! $self->ivExists('stripHash', $stripObj->number) || ! $stripObj->visibleFlag) {
3889  
3890 return undef
3891 }
3892  
3893 # Find the strip object's position in the list of visible strip objects
3894 $count = 0;
3895 OUTER: foreach my $otherObj ($self->stripList) {
3896  
3897 if ($otherObj eq $stripObj) {
3898  
3899 $posn = $count;
3900 last OUTER;
3901  
3902 } elsif ($otherObj->visibleFlag) {
3903  
3904 $count++;
3905 }
3906 }
3907  
3908 if (! defined $posn) {
3909  
3910 # Strip object is missing (for some unlikely reason)
3911 return undef;
3912 }
3913  
3914  
3915 # Remove the old Gtk3 widget that contains the whole strip
3916 $axmud::CLIENT->desktopObj->removeWidget($self->packingBox, $stripObj->packingBox);
3917 # Pack the newly-visible strip, leaving a gap if it's not at the beginning or end of the
3918 # list
3919 if (! $count || $posn == ($count - 1)) {
3920 $spacing = 0;
3921 } else {
3922 $spacing = $self->stripSpacingPixels;
3923 }
3924  
3925 $self->packingBox->pack_start(
3926 $stripObj->packingBox,
3927 $stripObj->expandFlag,
3928 $stripObj->fillFlag,
3929 $spacing,
3930 );
3931  
3932 if ($posn != 0) {
3933  
3934 $self->packingBox->reorder_child($stripObj->packingBox, $posn);
3935 }
3936  
3937 # Sensitise/desensitise widgets according to current conditions
3938 $self->restrictMenuBars();
3939 $self->restrictToolbars();
3940  
3941 # Make everything visible
3942 $self->winShowAll($self->_objClass . '->replaceStripObj');
3943 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->replaceStripObj');
3944  
3945 # Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
3946 # themselves will have disappeared
3947 $gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
3948 if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
3949  
3950 $gaugeStripObj->updateGauges();
3951 # (Need to call this a second time, or the re-draw doesn't work...)
3952 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->replaceStripObj');
3953 }
3954  
3955 return 1;
3956 }
3957  
3958 sub getStrip {
3959  
3960 # Convenient method for getting the blessed reference of the earliest-created instance of a
3961 # type of strip object
3962 #
3963 # This function accepts a string, which can be any of the following (case-insensitive):
3964 # 'menu' / 'menubar' / 'menu_bar' - converts to GA::Strip::MenuBar
3965 # 'tool' / 'toolbar' / 'tool_bar' - converts to GA::Strip::Toolbar
3966 # 'table' - converts to GA::Strip::Table
3967 # 'gauge' / 'gaugebox' / 'gauge_box' - converts to GA::Strip::GaugeBox
3968 # 'search' / 'searchbox' / 'search_box' - converts to GA::Strip::SearchBox
3969 # 'entry' - converts to GA::Strip::Entry
3970 # 'connect' / 'info' / 'connectinfo' / 'connect_info'
3971 # - converts to GA::Strip::ConnectInfo
3972 #
3973 # The string can also be a part of the package name itself. For example, if you create your
3974 # own GA::Strip::MyObject (inheriting from GA::Strip::Custom), then this function expects
3975 # the string 'MyObject' (case-sensitive)
3976 #
3977 # Expected arguments
3978 # $string - The string described above
3979 #
3980 # Return values
3981 # 'undef' on improper arguments or if a strip object of that type doesn't exist in the
3982 # window
3983 # Otherwise returns the blessed reference to the earliest-created instance of the
3984 # specified type of strip object
3985  
3986 my ($self, $string, $check) = @_;
3987  
3988 # Local variables
3989 my $packageName;
3990  
3991 # Check for improper arguments
3992 if (! defined $string || defined $check) {
3993  
3994 return $axmud::CLIENT->writeImproper($self->_objClass . '->getStrip', @_);
3995 }
3996  
3997 # Convert $string into a package name
3998 $packageName = $self->convertPackageName($string);
3999 if (! $packageName || $packageName eq 'Games::Axmud::Strip::Table') {
4000  
4001 return undef;
4002 }
4003  
4004 # Return the earliest-created instance of that strip object (return 'undef' if none exists)
4005 return $self->ivShow('firstStripHash', $packageName);
4006 }
4007  
4008 sub convertPackageName {
4009  
4010 # Called by $self->addStrip, ->getStrip and $self->removeStrip
4011 # Converts a simple string (e.g. 'menu' into the package name of a strip object (e.g.
4012 # 'Games::Axmud::Strip::MenuBar'
4013 #
4014 # This function accepts a string, which can be any of the following (case-insensitive):
4015 # 'menu' / 'menubar' / 'menu_bar' - converts to GA::Strip::MenuBar
4016 # 'tool' / 'toolbar' / 'tool_bar' - converts to GA::Strip::Toolbar
4017 # 'table' - converts to GA::Strip::Table
4018 # 'gauge' / 'gaugebox' / 'gauge_box' - converts to GA::Strip::GaugeBox
4019 # 'search' / 'searchbox' / 'search_box' - converts to GA::Strip::SearchBox
4020 # 'entry' - converts to GA::Strip::Entry
4021 # 'connect' / 'info' / 'connectinfo' / 'connect_info'
4022 # - converts to GA::Strip::ConnectInfo
4023 #
4024 # The string can also be a part of the package name itself. For example, if you create your
4025 # own GA::Strip::MyObject (inheriting from GA::Strip::Custom), then this function expects
4026 # the string 'MyObject' (case-sensitive)
4027 #
4028 # Expected arguments
4029 # $string - The string to convert
4030 #
4031 # Return values
4032 # 'undef' on improper arguments
4033 # Otherwise returns a strip object's package name
4034  
4035 my ($self, $string, $check) = @_;
4036  
4037 # Local variables
4038 my $packageName;
4039  
4040 # Check for improper arguments
4041 if (! defined $string || defined $check) {
4042  
4043 return $axmud::CLIENT->writeImproper($self->_objClass . '->convertPackageName', @_);
4044 }
4045  
4046 if (
4047 lc($string) eq 'menu' || lc($string) eq 'menubar' || lc($string) eq 'menu_bar'
4048 ) {
4049 $packageName = 'Games::Axmud::Strip::MenuBar';
4050  
4051 } elsif (
4052 lc($string) eq 'tool' || lc($string) eq 'toolbar' || lc($string) eq 'tool_bar'
4053 ) {
4054 $packageName = 'Games::Axmud::Strip::Toolbar';
4055  
4056 } elsif (
4057 lc($string) eq 'gauge' || lc($string) eq 'gaugebox' || lc($string) eq 'gauge_box'
4058 ) {
4059 $packageName = 'Games::Axmud::Strip::GaugeBox';
4060  
4061 } elsif (
4062 lc($string) eq 'search' || lc($string) eq 'searchbox' || lc($string) eq 'search_box'
4063 ) {
4064 $packageName = 'Games::Axmud::Strip::SearchBox';
4065  
4066 } elsif (lc($string) eq 'entry') {
4067  
4068 $packageName = 'Games::Axmud::Strip::Entry';
4069  
4070 } elsif (
4071 lc($string) eq 'connect' || lc($string) eq 'info' || lc($string) eq 'connectinfo'
4072 || lc($string) eq 'connect_info'
4073 ) {
4074 $packageName = 'Games::Axmud::Strip::ConnectInfo';
4075  
4076 } else {
4077  
4078 $packageName = 'Games::Axmud::Strip::' . $string;
4079 }
4080  
4081 return $packageName;
4082 }
4083  
4084 ##################
4085 # Accessors - set
4086  
4087 ##################
4088 # Accessors - get
4089  
4090 sub stripHash
4091 { my $self = shift; return %{$self->{stripHash}}; }
4092 sub firstStripHash
4093 { my $self = shift; return %{$self->{firstStripHash}}; }
4094 sub stripCount
4095 { $_[0]->{stripCount} }
4096 sub stripList
4097 { my $self = shift; return @{$self->{stripList}}; }
4098 sub tableStripObj
4099 { $_[0]->{tableStripObj} }
4100 sub stripSpacingPixels
4101 { $_[0]->{stripSpacingPixels} }
4102  
4103 sub visibleSession
4104 { $_[0]->{visibleSession} }
4105  
4106 sub hostLabelText
4107 { $_[0]->{hostLabelText} }
4108 sub timeLabelText
4109 { $_[0]->{timeLabelText} }
4110  
4111 sub ctrlKeyFlag
4112 { $_[0]->{ctrlKeyFlag} }
4113 sub shiftKeyFlag
4114 { $_[0]->{shiftKeyFlag} }
4115 sub altKeyFlag
4116 { $_[0]->{altKeyFlag} }
4117 sub altGrKeyFlag
4118 { $_[0]->{altGrKeyFlag} }
4119 sub modifierKeyFlag
4120 { $_[0]->{modifierKeyFlag} }
4121  
4122 sub actualWinWidth
4123 { $_[0]->{actualWinWidth} }
4124 sub actualWinHeight
4125 { $_[0]->{actualWinHeight} }
4126 sub maximisedFlag
4127 { $_[0]->{maximisedFlag} }
4128 sub focusFlag
4129 { $_[0]->{focusFlag} }
4130 }
4131  
4132 # Package must return a true value
4133 1