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

filter: Statementstmt 0.0% 0 / 1048 Branchbran 0.0% 0 / 552 Conditioncond 0.0% 0 / 588 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 64 Podpod 0.0% 0 / 60 totaltotal 0.0% 0 / 2312 CC 277 SCAR 62.3
CC
277
Cov
0%
setKeyPressEvent
2352.0
restrictMenuBars
930.0
drawWidgets
600.0
CRAP 505.8
1 # Copyright (C) 2011-2021 A S Lewis
2 #
3 # This program is free software: you can redistribute it and/or modify it under the terms of the GNU
4 # General Public License as published by the Free Software Foundation, either version 3 of the
5 # License, or (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
8 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License along with this program. If not,
12 # see <http://www.gnu.org/licenses/>.
13 #
14 #
15 # Games::Axmud::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 if (
1159 (
1160 ($axmud::BLIND_MODE_FLAG && $axmud::CLIENT->ttsHijackFlag)
1161 || (! $axmud::BLIND_MODE_FLAG && $axmud::CLIENT->ttsForceHijackFlag)
1162 )
1163 && $self->visibleSession
1164 && $axmud::CLIENT->ivExists('ttsHijackKeycodeHash', $string)
1165 ) {
1166 return $self->visibleSession->pseudoCmd(
1167 $axmud::CLIENT->ivShow('ttsHijackKeycodeHash', $string),
1168 $self->pseudoCmdMode,
1169 );
1170 }
1171  
1172 # Check that direct keys are enabled, if this is a 'main' window
1173 if ($self->visibleSession) {
1174  
1175 if (
1176 $self->visibleSession->currentWorld->ivExists(
1177 'termOverrideHash',
1178 'useDirectKeysFlag',
1179 )
1180 ) {
1181 $directFlag = $self->visibleSession->currentWorld->ivShow(
1182 'termOverrideHash',
1183 'useDirectKeysFlag',
1184 );
1185  
1186 } else {
1187  
1188 $directFlag = $axmud::CLIENT->useDirectKeysFlag;
1189 }
1190 }
1191  
1192 # If direct keys are enabled, send certain keycode strings direct to the world
1193 if ($directFlag && $self->visibleSession) {
1194  
1195 if (
1196 (
1197 $axmud::CLIENT->ivExists('constDirectAppKeysHash', $string)
1198 && (
1199 $self->visibleSession->ctrlKeypadMode eq 'alternate'
1200 || $self->visibleSession->ctrlCursorMode eq 'application'
1201 )
1202 && $self->visibleSession->put(
1203 $axmud::CLIENT->ivShow('constDirectAppKeysHash', $string),
1204 )
1205 ) || (
1206 $axmud::CLIENT->ivExists('constDirectAltKeysHash', $string)
1207 && $self->visibleSession->ctrlKeypadMode eq 'alternate'
1208 && $self->visibleSession->put(
1209 $axmud::CLIENT->ivShow('constDirectAltKeysHash', $string),
1210 )
1211 ) || (
1212 $axmud::CLIENT->ivExists('constDirectKeysHash', $string)
1213 && $self->visibleSession->put(
1214 $axmud::CLIENT->ivShow('constDirectKeysHash', $string),
1215 )
1216 )
1217 ) {
1218 # Return 1 to show that we have interfered with this keypress
1219 return 1;
1220  
1221 } elsif (
1222 $self->visibleSession->specialEchoMode eq 'enabled'
1223 && (! $stripObj || ! $stripObj->specialPreserveFlag)
1224 && $axmud::CLIENT->ivExists('constDirectSpecialKeysHash', $string)
1225 ) {
1226 # Warn the entry strip object about a backspace, which should modify a partial
1227 # world command it's been storing
1228 if ($stripObj && ! $stripObj->specialPreserveFlag && $string eq 'backspace') {
1229  
1230 $stripObj->applyBackspace();
1231 }
1232  
1233 if (
1234 $self->visibleSession->put(
1235 $axmud::CLIENT->ivShow('constDirectSpecialKeysHash', $string),
1236 )
1237 ) {
1238 # Return 1 to show that we have interfered with this keypress
1239 return 1;
1240 }
1241 }
1242 }
1243  
1244 # We don't want to call GA::Session->checkMacros for every keypress (that would be
1245 # inefficient)
1246 # Instead, call it if this is a 'main' window, and if this keycode string is being used
1247 # by any macro in any session (not perfectly efficient, but better)
1248 if (
1249 $self->visibleSession
1250 && $axmud::CLIENT->ivExists('activeKeycodeHash', $string)
1251 && $self->visibleSession->checkMacros($string)
1252 ) {
1253 # Return 1 to show that we have interfered with this keypress (by firing a macro)
1254 return 1;
1255 }
1256  
1257 # If no macro fired as a result of the keypress, then we can process some special keys
1258  
1259 # The first pane object in the entry strip object's ->paneObjList is the one to which
1260 # keypresses are applied
1261 if ($stripObj) {
1262  
1263 $paneObj = $stripObj->ivFirst('paneObjList');
1264  
1265 } else {
1266  
1267 # If there's no entry, then use the first pane object created in this window
1268 $paneObj = $self->findTableObj('pane');
1269 }
1270  
1271 if ($paneObj) {
1272  
1273 # Get the pane's visible tab and the scrollable Gtk3::Textview
1274 $tabObj = $paneObj->getVisibleTab();
1275 if ($tabObj) {
1276  
1277 $splitScreenMode = $tabObj->textViewObj->splitScreenMode;
1278 if ($splitScreenMode eq 'split') {
1279 $textView = $tabObj->textViewObj->textView2;
1280 } else {
1281 $textView = $tabObj->textViewObj->textView;
1282 }
1283 }
1284 }
1285  
1286 # The CTRL+C combination tends to be CTRL+SHIFT+C in Gtk, which is very inconvenient.
1287 # Implement a quick-and-dirty CTRL+C instead
1288 if ($string eq 'ctrl c' && $tabObj) {
1289  
1290 ($startIter, $endIter) = $tabObj->textViewObj->buffer->get_selection_bounds();
1291 if (defined $endIter) {
1292  
1293 $slice = $tabObj->textViewObj->buffer->get_slice($startIter, $endIter, FALSE);
1294 if (defined $slice && $slice ne '') {
1295  
1296 $clipboard = Gtk3::Clipboard::get(Gtk3::Gdk::Atom::intern('CLIPBOARD', 0));
1297 if ($clipboard) {
1298  
1299 $clipboard->set_text($slice);
1300  
1301 # Return 1 to show that we have interfered with this keypress
1302 return 1;
1303 }
1304 }
1305 }
1306  
1307 # If the page up/page down/home/end keys have been pressed, scroll the vertical
1308 # scrollbar containing the textview object
1309 } elsif (
1310 (
1311 $standard eq 'page_up' || $standard eq 'page_down' || $standard eq 'home'
1312 || $standard eq 'end'
1313 )
1314 && $tabObj
1315 && $axmud::CLIENT->useScrollKeysFlag
1316 ) {
1317 $vAdjust = $textView->get_vadjustment();
1318  
1319 # Get the lowest and highest vertical positions of the scrollbar, and the distance
1320 # between them
1321 $high = ($vAdjust->get_upper() - $vAdjust->get_page_size());
1322 $length = $high - $vAdjust->get_lower();
1323 $modValue = $vAdjust->get_value();
1324  
1325 # Set the new position of the vertical scrollbar (assuming one is visible)
1326 if ($length) {
1327  
1328 if (
1329 $axmud::CLIENT->autoSplitKeysFlag
1330 && $modValue >= $high
1331 && (
1332 (
1333 $splitScreenMode ne 'split'
1334 && ($standard eq 'page_up' || $standard eq 'home')
1335 ) || (
1336 $splitScreenMode eq 'split'
1337 && ($standard eq 'page_down' || $standard eq 'end')
1338 )
1339 )
1340 ) {
1341 # Engage/disengage the textview object's split screen mode, if necessary
1342 $paneObj->toggleSplitScreen();
1343  
1344 } else {
1345  
1346 if ($standard eq 'page_up') {
1347  
1348 # Scroll up
1349 if (! $axmud::CLIENT->smoothScrollKeysFlag) {
1350 $modValue -= $vAdjust->get_page_size();
1351 } else {
1352 $modValue -= $vAdjust->get_page_increment();
1353 }
1354  
1355 if ($modValue < 0) {
1356  
1357 $modValue = 0;
1358 }
1359  
1360 } elsif ($standard eq 'page_down') {
1361  
1362 # Scroll down
1363 if (! $axmud::CLIENT->smoothScrollKeysFlag) {
1364 $modValue += $vAdjust->get_page_size();
1365 } else {
1366 $modValue += $vAdjust->get_page_increment();
1367 }
1368  
1369 if ($modValue > $high) {
1370  
1371 $modValue = $high;
1372 }
1373  
1374 } elsif ($standard eq 'home') {
1375  
1376 # Scroll to top
1377 $modValue = 0;
1378  
1379 } else {
1380  
1381 # (End key) scroll to bottom
1382 $modValue = $high;
1383 }
1384  
1385 $vAdjust->set_value($modValue);
1386 }
1387 }
1388  
1389 # Return 1 to show that we have interfered with this keypress
1390 return 1;
1391  
1392 # If the up/down/tab arrow keys have been pressed and the client's auto-complete mode is
1393 # on (i.e. set to 'auto'), apply auto-complete or navigate through command buffers
1394 # However, CTRL+TAB switches between tabs in the pane object. If there's an entry strip
1395 # object, that object specifies which of multiple pane objects to use; if there's no
1396 # strip object, the first pane object created in the window is used
1397 # TAB can be used instead of CTRL+TAB if there is no entry strip object in the window
1398 } elsif ($standard eq 'up' || $standard eq 'down' || $standard eq 'tab') {
1399  
1400 if (
1401 ($self->ctrlKeyFlag || ! $stripObj)
1402 && $standard eq 'tab'
1403 && $paneObj
1404 && $paneObj->notebook
1405 && $axmud::CLIENT->useSwitchKeysFlag
1406 ) {
1407 $paneObj->switchVisibleTab();
1408  
1409 # Return 1 to show that we have interfered with this keypress
1410 return 1;
1411  
1412 } elsif (
1413 ! $self->modifierKeyFlag
1414 && $self->visibleSession
1415 && $stripObj
1416 && $stripObj->entry
1417 && $axmud::CLIENT->autoCompleteMode eq 'auto'
1418 && $axmud::CLIENT->useCompleteKeysFlag
1419 ) {
1420 $entryText = $stripObj->entry->get_text();
1421 if (! defined $stripObj->originalEntryText) {
1422  
1423 $stripObj->set_originalEntryText($entryText);
1424 }
1425  
1426 if ($standard eq 'tab') {
1427  
1428 # Check the instruction/world command buffer for matching instructions/world
1429 # commands so we can auto-complete the instruction/world command displayed
1430 # in the command entry box
1431 $bufferObj = $self->visibleSession->autoCompleteBuffer(
1432 $entryText,
1433 $stripObj->originalEntryText,
1434 );
1435  
1436 } else {
1437  
1438 # Navigate through the instruction/world command buffer to find the
1439 # instruction/world command to display in the command entry box
1440 $bufferObj = $self->visibleSession->navigateBuffer($standard);
1441 }
1442  
1443 if ($bufferObj) {
1444  
1445 # Display this previous instruction in the command entry box, and select
1446 # all text
1447 if ($axmud::CLIENT->autoCompleteType eq 'instruct') {
1448 $stripObj->entry->set_text($bufferObj->instruct);
1449 } else {
1450 $stripObj->entry->set_text($bufferObj->cmd);
1451 }
1452  
1453 $stripObj->entry->grab_focus();
1454  
1455 } else {
1456  
1457 # The returned $bufferObj will be 'undef' (when GA::Client->autoCompleteMode
1458 # = 'auto') when the buffer contains nothing shorter than the text in the
1459 # command entry box
1460 # $bufferObj will also be 'undef' if the buffer object is missing, for some
1461 # reason
1462 $stripObj->entry->set_text('');
1463 }
1464  
1465 # Return 1 to show that we have interfered with this keypress
1466 return 1;
1467 }
1468 }
1469  
1470 # Return 'undef' to show that we haven't interfered with this keypress
1471 return undef;
1472 });
1473  
1474 return 1;
1475 }
1476  
1477 sub setKeyReleaseEvent {
1478  
1479 # Called by $self->winSetup
1480 # Set up a ->signal_connect to watch out for certain key releases
1481 #
1482 # Expected arguments
1483 # (none besides $self)
1484 #
1485 # Return values
1486 # 'undef' on improper arguments or if the ->signal_connect doesn't interfere with the key
1487 # release
1488 # 1 if the ->signal_connect does interfere with the key release, or when the
1489 # ->signal_connect is first set up
1490  
1491 my ($self, $check) = @_;
1492  
1493 # Check for improper arguments
1494 if (defined $check) {
1495  
1496 return $axmud::CLIENT->writeImproper($self->_objClass . '->setKeyReleaseEvent', @_);
1497 }
1498  
1499 $self->winBox->signal_connect('key-release-event' => sub {
1500  
1501 my ($widget, $event) = @_;
1502  
1503 # Local variables
1504 my ($keycode, $standard);
1505  
1506 # Get the system keycode for this keypress
1507 $keycode = Gtk3::Gdk::keyval_name($event->keyval);
1508 # Translate it into a standard Axmud keycode
1509 $standard = $axmud::CLIENT->reverseKeycode($keycode);
1510  
1511 # If it's a CTRL, SHIFT, ALT or ALT-GR keypress, set IVs
1512 if ($standard eq 'ctrl') {
1513 $self->ivPoke('ctrlKeyFlag', FALSE);
1514 } elsif ($standard eq 'shift') {
1515 $self->ivPoke('shiftKeyFlag', FALSE);
1516 } elsif ($standard eq 'alt') {
1517 $self->ivPoke('altKeyFlag', FALSE);
1518 } elsif ($standard eq 'alt_gr') {
1519 $self->ivPoke('altGrKeyFlag', FALSE);
1520 }
1521  
1522 if (
1523 ! $self->ctrlKeyFlag
1524 && ! $self->shiftKeyFlag
1525 && ! $self->altKeyFlag
1526 && ! $self->altGrKeyFlag
1527 ) {
1528 $self->ivPoke('modifierKeyFlag', FALSE);
1529 }
1530  
1531 # Return 'undef' to show that we haven't interfered with this keypress
1532 return undef;
1533 });
1534  
1535 return 1;
1536 }
1537  
1538 sub setConfigureEvent {
1539  
1540 # Called by $self->winEnable
1541 # Set up a ->signal_connect to watch out for changes in the window size and position
1542 #
1543 # Expected arguments
1544 # (none besides $self)
1545 #
1546 # Return values
1547 # 'undef' on improper arguments
1548 # 1 otherwise
1549  
1550 my ($self, $check) = @_;
1551  
1552 # Check for improper arguments
1553 if (defined $check) {
1554  
1555 return $axmud::CLIENT->writeImproper($self->_objClass . '->setConfigureEvent', @_);
1556 }
1557  
1558 $self->winBox->signal_connect('configure-event' => sub {
1559  
1560 my ($widget, $event) = @_;
1561  
1562 # Has the window size actually changed, or just its position?
1563 if (
1564 ! defined $self->actualWinWidth # Windows size checked for the first time
1565 || $event->width != $self->actualWinWidth
1566 || $event->height != $self->actualWinHeight
1567 ) {
1568 $self->ivPoke('actualWinWidth', $event->width);
1569 $self->ivPoke('actualWinHeight', $event->height);
1570 }
1571  
1572 # Every textview object (GA::Obj::TextView) in this window must update its size IVs,
1573 # which informs the GA::Session (so it can send NAWS data to the world)
1574 foreach my $textViewObj ($axmud::CLIENT->desktopObj->ivValues('textViewHash')) {
1575  
1576 if ($textViewObj->winObj eq $self) {
1577  
1578 # Update the IVs once the changes have been rendered
1579 $textViewObj->set_sizeUpdateFlag();
1580 }
1581 }
1582  
1583 # Let the GA::Client store the most recent size and position for a window of this
1584 # ->winName, if it needs to
1585 if ($self->winWidget) {
1586  
1587 $axmud::CLIENT->add_storeGridPosn(
1588 $self,
1589 $self->winWidget->get_position(),
1590 $self->winWidget->get_size(),
1591 );
1592 }
1593  
1594 # Without returning 'undef', the window's strip/table objects aren't resized along with
1595 # the window
1596 return undef;
1597 });
1598  
1599 return 1;
1600 }
1601  
1602 sub setWindowStateEvent {
1603  
1604 # Called by $self->winEnable
1605 # Set up a ->signal_connect to watch out for when the window is maximised and unmaximised
1606 #
1607 # Expected arguments
1608 # (none besides $self)
1609 #
1610 # Return values
1611 # 'undef' on improper arguments
1612 # 1 otherwise
1613  
1614 my ($self, $check) = @_;
1615  
1616 # Check for improper arguments
1617 if (defined $check) {
1618  
1619 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWindowStateEvent', @_);
1620 }
1621  
1622 $self->winBox->signal_connect('window-state-event' => sub {
1623  
1624 # When the window is maximised and unmaximised, gauges in the gauge box (if visible) are
1625 # not redrawn properly. This block of code fixes that problem (but I don't know why it
1626 # works)
1627  
1628 my ($widget, $event) = @_;
1629  
1630 if ($event->changed_mask() =~ m/maximized/) {
1631  
1632 # This code makes sure textview(s) in pane object(s) are scrolled to the bottom
1633 # after un-maximising a window (otherwise, the scrollbar position moves
1634 # confusingly)
1635 if (! $self->maximisedFlag) {
1636  
1637 $self->ivPoke('maximisedFlag', TRUE);
1638  
1639 } else {
1640  
1641 $self->ivPoke('maximisedFlag', FALSE);
1642 $self->rescrollTextViews();
1643 }
1644 }
1645 });
1646 }
1647  
1648 sub setFocusInEvent {
1649  
1650 # Called by $self->winEnable
1651 # Set up a ->signal_connect to watch out for the 'internal' window receiving the focus,
1652 # which should be redirected towards the GA::Strip::Entry object's Gtk3::Entry (if there
1653 # is one)
1654 #
1655 # Expected arguments
1656 # (none besides $self)
1657 #
1658 # Return values
1659 # 'undef' on improper arguments
1660 # 1 otherwise
1661  
1662 my ($self, $check) = @_;
1663  
1664 # Check for improper arguments
1665 if (defined $check) {
1666  
1667 return $axmud::CLIENT->writeImproper($self->_objClass . '->setFocusInEvent', @_);
1668 }
1669  
1670 $self->winBox->signal_connect('focus-in-event' => sub {
1671  
1672 my ($widget, $event) = @_;
1673  
1674 # Update IVs
1675 $self->ivPoke('focusFlag', TRUE);
1676  
1677 # Update the command entry box (if visible)
1678 my $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::Entry');
1679 if ($stripObj && $stripObj->entry) {
1680  
1681 $stripObj->entry->grab_focus();
1682 }
1683  
1684 # For 'main' windows, check active hook interfaces for all sessions using this window
1685 # and fire hooks that are using the 'get_focus' hook event
1686 if ($self->visibleSession) {
1687  
1688 foreach my $session ($axmud::CLIENT->listSessions()) {
1689  
1690 if ($session->mainWin && $session->mainWin eq $self) {
1691  
1692 $session->checkHooks('get_focus');
1693 }
1694 }
1695 }
1696 });
1697  
1698 return 1;
1699 }
1700  
1701 sub setFocusOutEvent {
1702  
1703 # Called by $self->winEnable
1704 # Set up a ->signal_connect to watch out for the 'internal' window losing the focus
1705 #
1706 # Expected arguments
1707 # (none besides $self)
1708 #
1709 # Return values
1710 # 'undef' on improper arguments
1711 # 1 otherwise
1712  
1713 my ($self, $check) = @_;
1714  
1715 # Check for improper arguments
1716 if (defined $check) {
1717  
1718 return $axmud::CLIENT->writeImproper($self->_objClass . '->setFocusInEvent', @_);
1719 }
1720  
1721 $self->winBox->signal_connect('focus-out-event' => sub {
1722  
1723 my ($widget, $event) = @_;
1724  
1725 # Update IVs
1726 $self->ivPoke('focusFlag', FALSE);
1727  
1728 # For 'main' windows, check active hook interfaces for all sessions using this window
1729 # and fire hooks that are using the 'lose_focus' hook event
1730 if ($self->visibleSession) {
1731  
1732 foreach my $session ($axmud::CLIENT->listSessions()) {
1733  
1734 if ($session->mainWin && $session->mainWin eq $self) {
1735  
1736 $session->checkHooks('lose_focus');
1737 }
1738 }
1739 }
1740  
1741 # When the window loses focus, we no longer track SHIFT, ALT, CTRL or NUM LOCK
1742 # keypresses. Set IVs
1743 $self->ivPoke('shiftKeyFlag', FALSE);
1744 $self->ivPoke('altKeyFlag', FALSE);
1745 $self->ivPoke('altGrKeyFlag', FALSE);
1746 $self->ivPoke('ctrlKeyFlag', FALSE);
1747 $self->ivPoke('modifierKeyFlag', FALSE);
1748 });
1749  
1750 return 1;
1751 }
1752  
1753 # Other functions
1754  
1755 sub updateColourScheme {
1756  
1757 # Called by GA::Cmd::UpdateColourScheme->do (usually after a colour scheme is modified) and
1758 # by GA::Cmd::SetXTerm->do (when the xterm colour cube is switched)
1759 # Also called by $self->redrawWidgets, to neutralise Gtk3's charming tendency to redraw all
1760 # our textviews the wrong colour
1761 # Checks all textview objects in all pane objects in this window's Gtk3::Grid and updates
1762 # colours for any textview objects that use the specified colour scheme
1763 #
1764 # Expected arguments
1765 # (none besides $self)
1766 #
1767 # Optional arguments
1768 # $colourScheme - The name of the colour scheme (matches a key in
1769 # GA::Client->colourSchemeHash). If 'undef', all pane objects are
1770 # updated using their existing colour scheme
1771 # $noDrawFlag - TRUE when called by $self->redrawWidgets, meaning that the pane
1772 # objects are told not to call GA::Win::Generic->winShowAll or
1773 # GA::Obj::Desktop->updateWidgets as they normally would, so that
1774 # ->redrawWidgets can do it when ready. FALSE (or 'undef') otherwise
1775 #
1776 # Return values
1777 # 'undef' on improper arguments
1778 # 1 on success
1779  
1780 my ($self, $colourScheme, $noDrawFlag, $check) = @_;
1781  
1782 # Check for improper arguments
1783 if (defined $check) {
1784  
1785 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateColourScheme', @_);
1786 }
1787  
1788 # If $colourScheme was specified, check it's a recognised colour scheme
1789 if (defined $colourScheme) {
1790  
1791 if (! $axmud::CLIENT->ivExists('colourSchemeHash', $colourScheme)) {
1792  
1793 # Update all textview objects
1794 $colourScheme = undef;
1795 }
1796 }
1797  
1798 foreach my $tableObj ($self->tableStripObj->ivValues('tableObjHash')) {
1799  
1800 if ($tableObj->type eq 'pane') {
1801  
1802 $tableObj->updateColourScheme($colourScheme, $noDrawFlag);
1803 }
1804 }
1805  
1806 return 1;
1807 }
1808  
1809 sub applyColourScheme {
1810  
1811 # Called by GA::Cmd::ApplyColourScheme->do
1812 # Applies a colour scheme to all textview objects in all pane objects in this window's
1813 # Gtk3::Grid, replacing any colour schemes used before
1814 #
1815 # Expected arguments
1816 # $colourScheme - The name of the colour scheme to apply (matches a key in
1817 # GA::Client->colourSchemeHash)
1818 #
1819 # Return values
1820 # 'undef' on improper arguments or if $colourScheme doesn't exist
1821 # 1 on success
1822  
1823 my ($self, $colourScheme, $check) = @_;
1824  
1825 # Check for improper arguments
1826 if (defined $check) {
1827  
1828 return $axmud::CLIENT->writeImproper($self->_objClass . '->applyColourScheme', @_);
1829 }
1830  
1831 # Check that $colourScheme exists
1832 if (! $axmud::CLIENT->ivExists('colourSchemeHash', $colourScheme)) {
1833  
1834 return undef;
1835 }
1836  
1837 foreach my $tableObj ($self->tableStripObj->ivValues('tableObjHash')) {
1838  
1839 if ($tableObj->type eq 'pane') {
1840  
1841 $tableObj->applyColourScheme(
1842 undef, # Apply to all tabs in the pane object
1843 $colourScheme,
1844 );
1845 }
1846 }
1847  
1848 return 1;
1849 }
1850  
1851 sub rescrollTextViews {
1852  
1853 # Can be called by anyting
1854 # After a change in position of any window widgets, make sure any textview(s) in pane
1855 # object(s) are scrolled to the bottom (this saves a lot of user frustration)
1856 #
1857 # Expected arguments
1858 # (none besides $self)
1859 #
1860 # Return values
1861 # 'undef' on improper arguments or if this isn't the 'main' window
1862 # 1 otherwise
1863  
1864 my ($self, $check) = @_;
1865  
1866 # Local variables
1867 my $stripObj;
1868  
1869 # Check for improper arguments
1870 if (defined $check) {
1871  
1872 return $axmud::CLIENT->writeImproper($self->_objClass . '->rescrollTextViews', @_);
1873 }
1874  
1875 foreach my $tableObj ($self->tableStripObj->ivValues('tableObjHash')) {
1876  
1877 if ($tableObj->type eq 'pane') {
1878  
1879 foreach my $tabObj ($tableObj->ivValues('tabObjHash')) {
1880  
1881 $tabObj->textViewObj->scrollToBottom();
1882 }
1883 }
1884 }
1885  
1886 # After drawing gauges or unmaximising the window, the focus is lost from the command entry
1887 # box, so restore it
1888 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::Entry');
1889 if ($stripObj && $stripObj->entry) {
1890  
1891 $stripObj->entry->grab_focus();
1892 }
1893  
1894 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->rescrollTextViews');
1895  
1896 return 1;
1897 }
1898  
1899 sub findTableObj {
1900  
1901 # Can be called by anything
1902 # Finds the first table object of a particular type created in the compulsory table strip
1903 # object, if there is one
1904 #
1905 # Expected arguments
1906 # $type - The type of table object; matches the table object's type (e.g. 'pane' for
1907 # pane objects)
1908 #
1909 # Return values
1910 # 'undef' on improper arguments or if there is no table object of the specified type in
1911 # the Gtk3::Grid
1912 # Otherwise returns the table object of the specified type with the lowest ->number
1913  
1914 my ($self, $type, $check) = @_;
1915  
1916 # Local variables
1917 my @tableObjList;
1918  
1919 # Check for improper arguments
1920 if (! defined $type || defined $check) {
1921  
1922 return $axmud::CLIENT->writeImproper($self->_objClass . '->findFirstTableObj', @_);
1923 }
1924  
1925 @tableObjList = sort {$a->number <=> $b->number}
1926 ($self->tableStripObj->ivValues('tableObjHash'));
1927  
1928 foreach my $tableObj (@tableObjList) {
1929  
1930 if ($tableObj->type eq $type) {
1931  
1932 return $tableObj;
1933 }
1934 }
1935  
1936 # No table object of the right $type found
1937 return undef;
1938 }
1939  
1940 sub setVisibleSession {
1941  
1942 # Called by GA::Table::Pane->respondVisibleTab, when a session's default tab becomes the
1943 # visible tab in that pane. Only called when this window is a 'main' window
1944 # Should not be called by anything else - call GA::Table::Pane->setVisibleTab instead
1945 #
1946 # Sets $self->visibleSession and performs a number of housekeeping duties
1947 #
1948 # Expected arguments
1949 # (none besides $self)
1950 #
1951 # Optional arguments
1952 # $session - The GA::Session that is the new visible session. If 'undef', there is no
1953 # visible session in this window
1954 #
1955 # Return values
1956 # 'undef' on improper arguments
1957 # 1 otherwise
1958  
1959 my ($self, $session, $check) = @_;
1960  
1961 # Local variables
1962 my ($tabObj, $paneObj, $visibleTabObj);
1963  
1964 # Check for improper arguments
1965 if (defined $check) {
1966  
1967 return $axmud::CLIENT->writeImproper($self->_objClass . '->setVisibleSession', @_);
1968 }
1969  
1970 # This function shouldn't be called unless this is a 'main' window
1971 if ($self->winType ne 'main') {
1972  
1973 return $self->writeError(
1974 'Cannot set a visible session outside a \'main\' window',
1975 $self->_objClass . '->setVisibleSession',
1976 );
1977 }
1978  
1979 # Cease navigating through instruction/world command buffers in all windows (if the user has
1980 # been doing that using the 'up'/'down' arrow keys in any window)
1981 $axmud::CLIENT->set_instructBufferPosn();
1982 $axmud::CLIENT->set_cmdBufferPosn();
1983 foreach my $otherSession ($axmud::CLIENT->listSessions()) {
1984  
1985 $otherSession->set_instructBufferPosn();
1986 $otherSession->set_cmdBufferPosn();
1987 }
1988  
1989 # No visible session
1990 if (! $session) {
1991  
1992 # Update certain strip objects in any 'internal' window used by the old visible session
1993 # (if any; the TRUE flag means 'return 'internal' windows only)
1994 foreach my $winObj (
1995 $axmud::CLIENT->desktopObj->listSessionGridWins($self->visibleSession, TRUE)
1996 ) {
1997 # Update information stored in the window's connection info strip, if visible
1998 $winObj->setHostLabel('');
1999 $winObj->setTimeLabel('');
2000 # Reset the window's entry box and blinkers, if visible
2001 $winObj->resetEntry();
2002 $winObj->resetBlinkers();
2003 }
2004  
2005 # Update the GA::Client's IVs
2006 if (
2007 $axmud::CLIENT->currentSession
2008 && $self->visibleSession
2009 && $axmud::CLIENT->currentSession eq $self->visibleSession
2010 ) {
2011 $axmud::CLIENT->setCurrentSession();
2012 }
2013  
2014 # Update this window's IVs
2015 $self->ivUndef('visibleSession');
2016 if ($self->winType eq 'main') {
2017  
2018 $self->ivUndef('workspaceGridObj');
2019 }
2020  
2021 # New visible session
2022 } else {
2023  
2024 # If this window is a 'main' window shared by all sessions...
2025 if (
2026 $axmud::CLIENT->shareMainWinFlag
2027 && $self->visibleSession
2028 && $self->visibleSession ne $session
2029 ) {
2030 # ...need to hide windows on the former visible session's workspace grids (though
2031 # obviously not the shared 'main' window)
2032 $axmud::CLIENT->desktopObj->hideGridWins($self->visibleSession);
2033 # The new visible session's windows, on the other hand, need to be un-hidden
2034 $axmud::CLIENT->desktopObj->revealGridWins($session);
2035  
2036 # Fire any hooks that are using the 'not_visible' hook event
2037 $self->visibleSession->checkHooks('not_visible', $session->number);
2038 }
2039  
2040 # Update the GA::Client's IVs
2041 # ->currentSession is modified only when a 'main' window that's in focus changes its
2042 # ->visibleSession (exception - if the IV isn't set at all, set it regardless of
2043 # whether this window has the focus, or not)
2044 if (! $axmud::CLIENT->currentSession || $self->focusFlag) {
2045  
2046 $axmud::CLIENT->setCurrentSession($session);
2047 }
2048  
2049 # Update this window's IVs
2050 $self->ivPoke('visibleSession', $session);
2051 # For 'main' windows only, find the workspace grid used by this session (might be a
2052 # shared grid), and update the IV
2053 if ($self->winType eq 'main' && $self->workspaceObj) {
2054  
2055 # (In case the grid can't be found, use a default 'undef' value)
2056 $self->ivUndef('workspaceGridObj');
2057  
2058 OUTER: foreach my $gridObj (
2059 sort {$a->number <=> $b->number}
2060 ($self->workspaceObj->ivValues('gridHash'))
2061 ) {
2062 if (
2063 ! defined $gridObj->owner # Shared workspace grid
2064 || $gridObj->owner eq $session
2065 ) {
2066 $self->ivPoke('workspaceGridObj', $gridObj);
2067 last OUTER;
2068 }
2069 }
2070 }
2071  
2072 # In case the change of visible session isn't the result of the user clicking a
2073 # session's default tab, make the new visible session's default tab the visible one.
2074 # If that default tab is a simple tab, then there's nothing to do
2075 # ($session->defaultTabObj won't be set yet, if $session->start is still executing)
2076 if ($session->defaultTabObj) {
2077  
2078 $paneObj = $session->defaultTabObj->paneObj;
2079 $tabObj = $paneObj->findSession($session);
2080 $visibleTabObj = $paneObj->getVisibleTab();
2081 if ($paneObj->notebook && $tabObj && $visibleTabObj && $tabObj ne $visibleTabObj) {
2082  
2083 $paneObj->setVisibleTab($tabObj);
2084 }
2085 }
2086  
2087 # If the session's tab label is in a different colour, meaning that text had been
2088 # received from the world but hadn't been viewed by the user yet, reset the flag to
2089 # show that the text is now visible to the user
2090 $session->reset_showNewTextFlag();
2091  
2092 # Update information stored in the 'main' window's connection info strip, if visible
2093 $self->setHostLabel($session->getHostLabelText());
2094 $self->setTimeLabel($session->getTimeLabelText());
2095  
2096 # Update certain strip objects in any 'internal' window used by the new visible session
2097 # (if any; the TRUE flag means 'return 'internal' windows only)
2098 foreach my $winObj ($axmud::CLIENT->desktopObj->listSessionGridWins($session, TRUE)) {
2099  
2100 # Reset the 'internal' window's entry box and blinkers, if any
2101 $winObj->resetEntry();
2102 $winObj->resetBlinkers();
2103 }
2104  
2105 # Fire any hooks that are using the 'visible_session' hook event
2106 $session->checkHooks('visible_session', undef);
2107 # Fire any hooks that are using the 'change_visible' hook event
2108 foreach my $otherSession ($axmud::CLIENT->listSessions()) {
2109  
2110 if ($otherSession ne $session) {
2111  
2112 $otherSession->checkHooks('change_visible', $session->number);
2113 }
2114 }
2115 }
2116  
2117 # Update all 'internal' windows
2118 foreach my $winObj ($axmud::CLIENT->desktopObj->listGridWins()) {
2119  
2120 if (
2121 $winObj->winType eq 'main'
2122 || $winObj->winType eq 'protocol'
2123 || $winObj->winType eq 'custom'
2124 ) {
2125 # Sensitise/desensitise menu items in 'internal' windows, as appropriate
2126 $winObj->restrictMenuBars();
2127 $winObj->restrictToolbars();
2128 # Update the gauge box, if visible
2129 $winObj->updateGauges();
2130  
2131 # Sensitise or desensitise widgets, as appropriate
2132 $winObj->setWidgetsIfSession();
2133 # Update widgets, as appropriate
2134 $winObj->setWidgetsChangeSession();
2135  
2136 # Make any changes visible
2137 $winObj->winShowAll($self->_objClass . '->setVisibleSession');
2138 }
2139 }
2140  
2141 return 1;
2142 }
2143  
2144 sub checkConnectedSessions {
2145  
2146 # Called by $self->setDeleteEvent
2147 # If the user tries to manually close a 'main' window, counts the number of connected
2148 # sessions (not including disconencted or 'connect offline' mode sessions) using this
2149 # window as their 'main' window
2150 # If any are found, prompts the user for confirmation (if the GA::Client flag requires us
2151 # to do that)
2152 #
2153 # Expected arguments
2154 # (none besides $self)
2155 #
2156 # Return values
2157 # 'undef' on improper arguments or if the window should not be closed
2158 # 1 if the window can be closed
2159  
2160 my ($self, $check) = @_;
2161  
2162 # Local variables
2163 my ($count, $choice, $msg);
2164  
2165 # Check for improper arguments
2166 if (defined $check) {
2167  
2168 return $axmud::CLIENT->writeImproper(
2169 $self->_objClass . '->checkConnectedSessions',
2170 @_,
2171 );
2172 }
2173  
2174 if (! $axmud::CLIENT->confirmCloseMainWinFlag) {
2175  
2176 # The window can be closed - no confirmation required
2177 return 1;
2178 }
2179  
2180 # Otherwise, count connected sessions
2181 $count = 0;
2182 foreach my $session ($axmud::CLIENT->ivValues('sessionHash')) {
2183  
2184 if (
2185 $session->mainWin
2186 && $session->mainWin eq $self
2187 && $session->status eq 'connected'
2188 ) {
2189 $count++;
2190 }
2191 }
2192  
2193 if ($count) {
2194  
2195 if ($count == 1) {
2196 $msg = '1 connected session';
2197 } else {
2198 $msg = $count . ' connected sessions';
2199 }
2200  
2201 $choice = $self->showMsgDialogue(
2202 'Close \'main\' window',
2203 'question',
2204 'This window is in use by ' . $msg . '. Are you sure you want to close it?',
2205 'yes-no',
2206 );
2207  
2208 if ($choice && $choice eq 'yes') {
2209  
2210 # Allow the window to close
2211 return 1;
2212  
2213 } else {
2214  
2215 # Don't allow the window to close
2216 return undef;
2217 }
2218  
2219 } else {
2220  
2221 # No connected sessions, allow the window to close
2222 return 1;
2223 }
2224 }
2225  
2226 sub updateGauges {
2227  
2228 # Called by various functions as a shortcut to GA::Strip::GaugeBox->updateGauges
2229 #
2230 # Expected arguments
2231 # (none besides $self)
2232 #
2233 # Return values
2234 # 'undef' on improper arguments
2235 # 1 otherwise
2236  
2237 my ($self, $winmapName, $check) = @_;
2238  
2239 # Local variables
2240 my $stripObj;
2241  
2242 # Check for improper arguments
2243 if (defined $check) {
2244  
2245 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateGauges', @_);
2246 }
2247  
2248 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
2249 if ($stripObj) {
2250  
2251 $stripObj->updateGauges();
2252 }
2253  
2254 return 1;
2255 }
2256  
2257 sub resetEntry {
2258  
2259 # Called by GA::Client->set_autoCompleteMode, ->set_autoCompleteType and
2260 # ->set_autoCompleteParent or any other code which needs to reset the entry box (for some
2261 # reason)
2262 # The user can press the 'up'/'down' arrow keys to change the command displayed in the
2263 # GA::Strip::Entry's command entry box
2264 # The new command depends on various client IVs. If those IVs are changed, the entry box
2265 # must be reset
2266 #
2267 # Expected arguments
2268 # (none besides $self)
2269 #
2270 # Return values
2271 # 'undef' on improper arguments
2272 # 1 otherwise
2273  
2274 my ($self, $check) = @_;
2275  
2276 # Local variables
2277 my $stripObj;
2278  
2279 # Check for improper arguments
2280 if (defined $check) {
2281  
2282 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetEntry', @_);
2283 }
2284  
2285 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::Entry');
2286 if ($stripObj) {
2287  
2288 $stripObj->set_originalEntryText();
2289 if ($stripObj->entry) {
2290  
2291 $stripObj->entry->set_text('');
2292 }
2293 }
2294  
2295 return 1;
2296 }
2297  
2298 sub setHostLabel {
2299  
2300 # Can be called by anything (but usually called by various functions in GA::Session, and
2301 # also by $self->setVisibleSession)
2302 # Sets the text used in the GA::Strip::ConnectInfo strip object to display information
2303 # about the current host (world)
2304 # If the strip object hasn't been added to the window, still store the text in
2305 # $self->hostLabelText so it's available instantly if the strip object is added later
2306 #
2307 # Expected arguments
2308 # (none besides $self)
2309 #
2310 # Optional arguments
2311 # $text - The text to display in this label. If set to 'undef', an empty string is
2312 # displayed
2313 # $tooltip - The text to display as a tooltip. If set to 'undef', no tooltip is
2314 # displayed
2315 #
2316 # Return values
2317 # 'undef' on improper arguments
2318 # 1 otherwise
2319  
2320 my ($self, $text, $tooltip, $check) = @_;
2321  
2322 # Local variables
2323 my $stripObj;
2324  
2325 # Check for improper arguments
2326 if (defined $check) {
2327  
2328 return $axmud::CLIENT->writeImproper($self->_objClass . '->setHostLabel', @_);
2329 }
2330  
2331 if (! $text) {
2332  
2333 $text = '';
2334 }
2335  
2336 $self->ivPoke('hostLabelText', $text);
2337  
2338 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::ConnectInfo');
2339 if ($stripObj) {
2340  
2341 $stripObj->set_hostLabel($text, $tooltip);
2342 }
2343  
2344 return 1;
2345 }
2346  
2347 sub setTimeLabel {
2348  
2349 # Can be called by anything (but usually called by GA::Client->spinClientLoop, various
2350 # functions in GA::Session, and also by $self->setVisibleSession)
2351 # Sets the text used in the GA::Strip::ConnectInfo strip object to display information about
2352 # the current time
2353 # If the strip object hasn't been added to the window, still store the text in
2354 # $self->timeLabelText so it's available instantly if the strip object is added later
2355 #
2356 # Expected arguments
2357 # (none besides $self)
2358 #
2359 # Optional arguments
2360 # $text - The text to display in this label. If set to 'undef', an empty string is
2361 # displayed
2362 #
2363 # Return values
2364 # 'undef' on improper arguments
2365 # 1 otherwise
2366  
2367 my ($self, $text, $check) = @_;
2368  
2369 # Local variables
2370 my $stripObj;
2371  
2372 # Check for improper arguments
2373 if (defined $check) {
2374  
2375 return $axmud::CLIENT->writeImproper($self->_objClass . '->setTimeLabel', @_);
2376 }
2377  
2378 if (! $text) {
2379  
2380 $text = '';
2381 }
2382  
2383 $self->ivPoke('timeLabelText', $text);
2384  
2385 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::ConnectInfo');
2386 if ($stripObj) {
2387  
2388 $stripObj->set_timeLabel($text);
2389 }
2390  
2391 return 1;
2392 }
2393  
2394 sub resetBlinkers {
2395  
2396 # Can be called by anything (but usually called by GA::Session->reactDisconnect and
2397 # $self->setVisibleSession)
2398 # Resets the blinkers drawn in the GA::Strip::ConnectInfo strip object
2399 #
2400 # Expected arguments
2401 # (none besides $self)
2402 #
2403 # Return values
2404 # 'undef' on improper arguments
2405 # 1 otherwise
2406  
2407 my ($self, $check) = @_;
2408  
2409 # Local variables
2410 my $stripObj;
2411  
2412 # Check for improper arguments
2413 if (defined $check) {
2414  
2415 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetBlinkers', @_);
2416 }
2417  
2418 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::ConnectInfo');
2419 if ($stripObj) {
2420  
2421 $stripObj->drawBlinker(-1, FALSE);
2422 }
2423  
2424 return 1;
2425 }
2426  
2427 sub setMainWinTitle {
2428  
2429 # Called by GA::Client->checkMainWinTitles to change each 'main' window's title to something
2430 # like '*Axmud' to show that there are client files that need to be saved, or to something
2431 # like 'Axmud' to show there are no client files that need to be saved
2432 # (Session files are handles separately by GA::Session->checkTabLabels)
2433 #
2434 # Expected arguments
2435 # (none besides $self)
2436 #
2437 # Optional arguments
2438 # $flag - If set to TRUE, show an asterisk. If set to FALSE (or 'undef'), don't show
2439 # an asterisk
2440 #
2441 # Return values
2442 # 'undef' on improper arguments or if this window isn't a 'main' window
2443 # 1 otherwise
2444  
2445 my ($self, $flag, $check) = @_;
2446  
2447 # Check for improper arguments
2448 if (defined $check) {
2449  
2450 return $axmud::CLIENT->writeImproper($self->_objClass . '->setMainWinTitle', @_);
2451 }
2452  
2453 # Ignore this function call for other types of 'grid' window
2454 if ($self->winType eq 'main') {
2455  
2456 return undef;
2457  
2458 # Set the window title
2459 } elsif ($flag) {
2460  
2461 $self->winWidget->set_title('*' . $axmud::SCRIPT);
2462  
2463 } else {
2464  
2465 $self->winWidget->set_title($axmud::SCRIPT);
2466 }
2467  
2468 return 1;
2469 }
2470  
2471 sub setWinTitle {
2472  
2473 # Can be called by anything to change the text in the window's title bar
2474 # Does nothing if this window is a 'main' window (code should call $self->setMainWinTitle
2475 # instead)
2476 #
2477 # Expected arguments
2478 # $text - The text to use
2479 #
2480 # Return values
2481 # 'undef' on improper arguments or if this window isn't a 'main' window
2482 # 1 otherwise
2483  
2484 my ($self, $text, $check) = @_;
2485  
2486 # Check for improper arguments
2487 if (defined $check) {
2488  
2489 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWinTitle', @_);
2490 }
2491  
2492 if ($self->enabledFlag && $self->winType ne 'main' && $self->winWidget eq $self->winBox) {
2493  
2494 $self->winWidget->set_title($text);
2495 }
2496  
2497 return 1;
2498 }
2499  
2500 sub restrictMenuBars {
2501  
2502 # Called by GA::Obj::Desktop->restrictWidgets
2503 # Sensitise or desensitise the menu bar in this 'internal' window, depending on current
2504 # conditions. (Don't do anything if this window doesn't use a strip object for a menu bar)
2505 #
2506 # Expected arguments
2507 # (none besides $self)
2508 #
2509 # Return values
2510 # 'undef' on improper arguments or if this window doesn't use a strip object for a menu
2511 # bar
2512 # 1 otherwise
2513  
2514 my ($self, $check) = @_;
2515  
2516 # Local variables
2517 my (
2518 $stripObj, $openFlag, $setupFlag,
2519 @list, @sensitiseList, @desensitiseList,
2520 );
2521  
2522 # Check for improper arguments
2523 if (defined $check) {
2524  
2525 return $axmud::CLIENT->writeImproper($self->_objClass . '->restrictMenuBars', @_);
2526 }
2527  
2528 # Get the strip object
2529 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::MenuBar');
2530 if (! $stripObj) {
2531  
2532 # Nothing to sensitise/desensitise
2533 return undef;
2534 }
2535  
2536 # Test whether this is a 'main' window with a visible session whose status is 'connected' or
2537 # 'offline' (for the sake of efficiency)
2538 if (
2539 $self->visibleSession
2540 && (
2541 $self->visibleSession->status eq 'connected'
2542 || $self->visibleSession->status eq 'offline'
2543 )
2544 ) {
2545 $openFlag = TRUE;
2546 }
2547  
2548 # Test whether the setup wizwin is open (in which case, almost everything is desensitised)
2549 OUTER: foreach my $winObj ($axmud::CLIENT->desktopObj->ivValues('freeWinHash')) {
2550  
2551 if ($winObj->isa('Games::Axmud::WizWin::Setup')) {
2552  
2553 $setupFlag = TRUE;
2554  
2555 # In addition, the following menu items are desensitised
2556 push (@desensitiseList,
2557 # 'World' column
2558 'connect', 'stop_client',
2559 # 'Edit' column
2560 'test_pattern',
2561 # 'Help' column
2562 'help', 'about', 'credits', 'license',
2563 );
2564  
2565 last OUTER;
2566 }
2567 }
2568  
2569 # Menu bar items that require a 'main' window with a visible session
2570 @list = (
2571 # 'World' column
2572 'reconnect', 'reconnect_offline',
2573 'xconnect', 'xconnect_offline',
2574 'quit_all',
2575 'exit_all',
2576 'stop_session',
2577 # 'File' column
2578 'test_file',
2579 'show_files', 'show_file_meta',
2580 # 'Axbasic' column
2581 'check_script', 'edit_script',
2582 # 'Plugins' column
2583 'load_plugin', 'show_plugin',
2584 );
2585  
2586 if (! $setupFlag && $self->visibleSession) {
2587 push (@sensitiseList, @list);
2588 } else {
2589 push (@desensitiseList, @list);
2590 }
2591  
2592 # Menu bar items that require a 'main' window with a visible session whose status is
2593 # 'connected' or 'offline'
2594 @list = (
2595 # 'World' column
2596 'login',
2597 'quit', 'qquit',
2598 'exit', 'xxit',
2599 # 'File' column
2600 'load_all', 'load_file',
2601 'save_all', 'save', 'save_options',
2602 'import_files',
2603 # 'export_all_files', 'export_file',
2604 'export_file',
2605 'import_data',
2606 'export_data',
2607 'backup_restore_data',
2608 'disable_world_save', 'disable_save_load',
2609 # 'Edit' column
2610 'edit_quick_prefs', 'edit_client_prefs', 'edit_session_prefs',
2611 'edit_current_world',
2612 'run_locator_wiz', 'edit_world_model', 'edit_dictionary',
2613 'simulate',
2614 # 'Interfaces' column
2615 'active_interfaces',
2616 'show_triggers', 'show_aliases', 'show_macros', 'show_timers', 'show_hooks',
2617 'show_cmds', 'show_routes',
2618 # 'Tasks' column
2619 'freeze_tasks', 'chat_task',
2620 'run_locator_wiz_2',
2621 'other_task',
2622 # 'Display' column
2623 'open_automapper', 'open_object_viewer',
2624 'activate_grid', 'activate_grid_with', 'reset_grid', 'disactivate_grid',
2625 'win_components', 'current_layer', 'window_storage',
2626 'test_controls', 'test_panels',
2627 # 'Commands' column
2628 'repeat_cmd', 'repeat_second', 'repeat_interval',
2629 'cancel_repeat',
2630 # 'Axbasic' column
2631 'run_script', 'run_script_task',
2632 );
2633  
2634 if (! $setupFlag && $openFlag) {
2635 push (@sensitiseList, @list);
2636 } else {
2637 push (@desensitiseList, @list);
2638 }
2639  
2640 # Menu bar items that require a 'main' window with a visible session whose status is
2641 # 'connected' or 'offline' and whose ->currentGuild is defined
2642 @list = (
2643 # 'Edit' column
2644 'edit_current_guild',
2645 # 'Interfaces' column
2646 'guild_triggers', 'guild_aliases', 'guild_macros', 'guild_timers', 'guild_hooks',
2647 'guild_cmds', 'guild_routes',
2648 );
2649  
2650 if (! $setupFlag && $openFlag && $self->visibleSession->currentGuild) {
2651 push (@sensitiseList, @list);
2652 } else {
2653 push (@desensitiseList, @list);
2654 }
2655  
2656 # Menu bar items that require a 'main' window with a visible session whose status is
2657 # 'connected' or 'offline' and whose ->currentRace is defined
2658 @list = (
2659 # 'Edit' column
2660 'edit_current_race',
2661 # 'Interfaces' column
2662 'race_triggers', 'race_aliases', 'race_macros', 'race_timers', 'race_hooks',
2663 'race_cmds', 'race_routes',
2664 );
2665  
2666 if (! $setupFlag && $openFlag && $self->visibleSession->currentRace) {
2667 push (@sensitiseList, @list);
2668 } else {
2669 push (@desensitiseList, @list);
2670 }
2671  
2672 # Menu bar items that require a 'main' window with a visible session whose status is
2673 # 'connected' or 'offline' and whose ->currentChar is defined
2674 @list = (
2675 # 'Edit' column
2676 'edit_current_char',
2677 # 'Interfaces' column
2678 'char_triggers', 'char_aliases', 'char_macros', 'char_timers', 'char_hooks',
2679 'char_cmds', 'char_routes',
2680 );
2681  
2682 if (! $setupFlag && $openFlag && $self->visibleSession->currentChar) {
2683 push (@sensitiseList, @list);
2684 } else {
2685 push (@desensitiseList, @list);
2686 }
2687  
2688 # Menu bar items that require a 'main' window with a visible session whose status is
2689 # 'connected' or 'offline' and $stripObj->saveAllSessionsFlag set to FALSE
2690 @list = (
2691 # 'File' column
2692 'save_file',
2693 );
2694  
2695 if (! $setupFlag && $openFlag && ! $stripObj->saveAllSessionsFlag) {
2696 push (@sensitiseList, @list);
2697 } else {
2698 push (@desensitiseList, @list);
2699 }
2700  
2701 # Menu bar items that require a 'main' window with a visible session whose status is
2702 # 'connected' or 'offline' and whose ->recordingPausedFlag is FALSE
2703 @list = (
2704 # 'Recordings' column
2705 'start_stop_recording',
2706 );
2707  
2708 if (! $setupFlag && $openFlag && ! $self->visibleSession->recordingPausedFlag) {
2709 push (@sensitiseList, @list);
2710 } else {
2711 push (@desensitiseList, @list);
2712 }
2713  
2714 # Menu bar items that require a 'main' window with a visible session whose status is
2715 # 'connected' or 'offline' and whose ->recordingFlag is TRUE
2716 @list = (
2717 # 'Recordings' column
2718 'pause_recording',
2719 );
2720  
2721 if (! $setupFlag && $openFlag && $self->visibleSession->recordingFlag) {
2722 push (@sensitiseList, @list);
2723 } else {
2724 push (@desensitiseList, @list);
2725 }
2726  
2727 # Menu bar items that require a 'main' window with a visible session whose status is
2728 # 'connected' or 'offline' and an Advance task
2729 @list = (
2730 # 'Tasks' column
2731 'edit_advance_task',
2732 );
2733  
2734 if (! $setupFlag && $openFlag && $self->visibleSession->advanceTask) {
2735 push (@sensitiseList, @list);
2736 } else {
2737 push (@desensitiseList, @list);
2738 }
2739  
2740 # Menu bar items that require a 'main' window with a visible session whose status is
2741 # 'connected' or 'offline' and a Connections task
2742 @list = (
2743 # 'Tasks' column
2744 'edit_connections_task',
2745 );
2746  
2747 if (! $setupFlag && $openFlag && $self->visibleSession->connectionsTask) {
2748 push (@sensitiseList, @list);
2749 } else {
2750 push (@desensitiseList, @list);
2751 }
2752  
2753 # Menu bar items that require a 'main' window with a visible session whose status is
2754 # 'connected' or 'offline' and an Attack task
2755 @list = (
2756 # 'Tasks' column
2757 'edit_attack_task',
2758 );
2759  
2760 if (! $setupFlag && $openFlag && $self->visibleSession->attackTask) {
2761 push (@sensitiseList, @list);
2762 } else {
2763 push (@desensitiseList, @list);
2764 }
2765  
2766 # Menu bar items that require a 'main' window with a visible session whose status is
2767 # 'connected' or 'offline' and a Chat task
2768 @list = (
2769 # 'Tasks' column
2770 'edit_chat_task',
2771 );
2772  
2773 if (! $setupFlag && $openFlag && $self->visibleSession->chatTask) {
2774 push (@sensitiseList, @list);
2775 } else {
2776 push (@desensitiseList, @list);
2777 }
2778  
2779 # Menu bar items that require a 'main' window with a visible session whose status is
2780 # 'connected' or 'offline' and a Channels task
2781 @list = (
2782 # 'Tasks' column
2783 'channels_task',
2784 );
2785  
2786 if (! $setupFlag && $openFlag && $self->visibleSession->channelsTask) {
2787 push (@sensitiseList, @list);
2788 } else {
2789 push (@desensitiseList, @list);
2790 }
2791  
2792 # Menu bar items that require a 'main' window with a visible session whose status is
2793 # 'connected' or 'offline' and a Compass task
2794 @list = (
2795 # 'Tasks' column
2796 'compass_task',
2797 );
2798  
2799 if (! $setupFlag && $openFlag && $self->visibleSession->compassTask) {
2800 push (@sensitiseList, @list);
2801 } else {
2802 push (@desensitiseList, @list);
2803 }
2804  
2805 # Menu bar items that require a 'main' window with a visible session whose status is
2806 # 'connected' or 'offline' and a Divert task
2807 @list = (
2808 # 'Tasks' column
2809 'divert_task',
2810 );
2811  
2812 if (! $setupFlag && $openFlag && $self->visibleSession->divertTask) {
2813 push (@sensitiseList, @list);
2814 } else {
2815 push (@desensitiseList, @list);
2816 }
2817  
2818 # Menu bar items that require a 'main' window with a visible session whose status is
2819 # 'connected' or 'offline' and an Inventory task
2820 @list = (
2821 # 'Tasks' column
2822 'inventory_task',
2823 );
2824  
2825 if (! $setupFlag && $openFlag && $self->visibleSession->inventoryTask) {
2826 push (@sensitiseList, @list);
2827 } else {
2828 push (@desensitiseList, @list);
2829 }
2830  
2831 # Menu bar items that require a 'main' window with a visible session whose status is
2832 # 'connected' or 'offline' and a Locator task
2833 @list = (
2834 # 'Tasks' column
2835 'locator_task',
2836 );
2837  
2838 if (! $setupFlag && $openFlag && $self->visibleSession->locatorTask) {
2839 push (@sensitiseList, @list);
2840 } else {
2841 push (@desensitiseList, @list);
2842 }
2843  
2844 # Menu bar items that require a 'main' window with a visible session whose status is
2845 # 'connected' or 'offline' and a RawToken task
2846 @list = (
2847 # 'Tasks' column
2848 'raw_token_task',
2849 );
2850  
2851 if (! $setupFlag && $openFlag && $self->visibleSession->rawTokenTask) {
2852 push (@sensitiseList, @list);
2853 } else {
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 push (@sensitiseList, @list);
2866 } else {
2867 push (@desensitiseList, @list);
2868 }
2869  
2870 # Menu bar items that require a 'main' window with a visible session whose status is
2871 # 'connected' or 'offline' and a System task
2872 @list = (
2873 # 'Tasks' column
2874 'edit_system_task',
2875 );
2876  
2877 if (! $setupFlag && $openFlag && $self->visibleSession->systemTask) {
2878 push (@sensitiseList, @list);
2879 } else {
2880 push (@desensitiseList, @list);
2881 }
2882  
2883 # Menu bar items that require a 'main' window with a visible session whose status is
2884 # 'connected' or 'offline' and a Watch task
2885 @list = (
2886 # 'Tasks' column
2887 'watch_task',
2888 );
2889  
2890 if (! $setupFlag && $openFlag && $self->visibleSession->watchTask) {
2891 push (@sensitiseList, @list);
2892 } else {
2893 push (@desensitiseList, @list);
2894 }
2895  
2896 # Menu bar items that require a require a 'main' window with a visible session whose status
2897 # is 'connected' or 'offline' and GA::Session->recordingFlag
2898 @list = (
2899 # 'Recordings' column
2900 'pause_resume_recording',
2901 'recording_add_line', 'recording_add_break',
2902 'recording_set_insertion', 'recording_cancel_insertion',
2903 'recording_delete_line', 'recording_delete_multi', 'recording_delete_last',
2904 );
2905  
2906 if (! $setupFlag && $openFlag && $self->visibleSession->recordingFlag) {
2907 push (@sensitiseList, @list);
2908 } else {
2909 push (@desensitiseList, @list);
2910 }
2911  
2912 # Menu bar items that require a require a 'main' window with a visible session whose status
2913 # is 'connected' or 'offline', and either GA::Session->recordingFlag or ->recordingList
2914 @list = (
2915 # 'Recordings' column
2916 'show_recording', 'copy_recording',
2917 );
2918  
2919 if (
2920 ! $setupFlag
2921 && $openFlag
2922 && ($self->visibleSession->recordingFlag || $self->visibleSession->recordingList)
2923 ) {
2924 push (@sensitiseList, @list);
2925 } else {
2926 push (@desensitiseList, @list);
2927 }
2928  
2929 # Menu bar items that require GA::Client->browserCmd
2930 @list = (
2931 # 'Help' column
2932 'go_website',
2933 );
2934  
2935 if (! $setupFlag && $axmud::CLIENT->browserCmd) {
2936 push (@sensitiseList, @list);
2937 } else {
2938 push (@desensitiseList, @list);
2939 }
2940  
2941 # Sensitise/desensitise menu bar items
2942 $stripObj->sensitiseWidgets(@sensitiseList);
2943 $stripObj->desensitiseWidgets(@desensitiseList);
2944  
2945 # All menu items added by plugins require a 'main' window with a visible session, and the
2946 # plugin itself must be must be enabled
2947 foreach my $plugin ($stripObj->ivKeys('pluginMenuItemHash')) {
2948  
2949 my ($widget, $pluginObj);
2950  
2951 $widget = $stripObj->ivShow('pluginMenuItemHash', $plugin);
2952 $pluginObj = $axmud::CLIENT->ivShow('pluginHash', $plugin);
2953  
2954 if (! $setupFlag && $self->visibleSession && $pluginObj->enabledFlag) {
2955 $widget->set_sensitive(TRUE);
2956 } else {
2957 $widget->set_sensitive(FALSE);
2958 }
2959 }
2960  
2961 return 1;
2962 }
2963  
2964 sub restrictToolbars {
2965  
2966 # Called by GA::Obj::Desktop->restrictWidgets
2967 # Sensitise or desensitise the toolbar in this 'internal' window, depending on current
2968 # conditions. (Don't do anything if this window doesn't use a strip object for a toolbar)
2969 #
2970 # Expected arguments
2971 # (none besides $self)
2972 #
2973 # Return values
2974 # 'undef' on improper arguments or if this window doesn't use a strip object for a toolbar
2975 # 1 otherwise
2976  
2977 my ($self, $check) = @_;
2978  
2979 # Local variables
2980 my (
2981 $stripObj,
2982 @list, @sensitiseList, @desensitiseList,
2983 );
2984  
2985 # Check for improper arguments
2986 if (defined $check) {
2987  
2988 return $axmud::CLIENT->writeImproper($self->_objClass . '->restrictToolbars', @_);
2989 }
2990  
2991 # Get the strip object
2992 $stripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::Toolbar');
2993 if (! $stripObj) {
2994  
2995 # Nothing to sensitise/desensitise
2996 return undef;
2997 }
2998  
2999 # Test whether the setup wizwin is open (in which case, everything is desensitised)
3000 OUTER: foreach my $winObj ($axmud::CLIENT->desktopObj->ivValues('freeWinHash')) {
3001  
3002 if ($winObj->isa('Games::Axmud::WizWin::Setup')) {
3003  
3004 foreach my $widget ($stripObj->toolbarWidgetList) {
3005  
3006 $widget->set_sensitive(FALSE);
3007 }
3008  
3009 return 1;
3010 }
3011 }
3012  
3013 # Toolbar buttons that require a 'main' window with a visible session
3014 @list = $stripObj->ivKeys('requireSessionHash');
3015  
3016 if ($self->visibleSession) {
3017 push (@sensitiseList, @list);
3018 } else {
3019 push (@desensitiseList, @list);
3020 }
3021  
3022 # Toolbar buttons that require a 'main' window with a visible session whose status is
3023 # 'connected' or 'offline'
3024 @list = $stripObj->ivKeys('requireConnectHash');
3025  
3026 if (
3027 $self->visibleSession
3028 && (
3029 $self->visibleSession->status eq 'connected'
3030 || $self->visibleSession->status eq 'offline'
3031 )
3032 ) {
3033 push (@sensitiseList, @list);
3034 } else {
3035 push (@desensitiseList, @list);
3036 }
3037  
3038 # Sensitise/desensitise toolbar items
3039 $stripObj->sensitiseWidgets(@sensitiseList);
3040 $stripObj->desensitiseWidgets(@desensitiseList);
3041  
3042 return 1;
3043 }
3044  
3045 sub setWidgetsIfSession {
3046  
3047 # Called by $self->setVisibleSession
3048 # Calls each strip object (and, for GA::Strip::Table, any child table objects) so they can
3049 # sensitise or desensitise their widgets, depending on whether this window has a
3050 # ->visibleSession, or not
3051 #
3052 # Expected arguments
3053 # (none besides $self)
3054 #
3055 # Return values
3056 # 'undef' on improper arguments
3057 # 1 otherwise
3058  
3059 my ($self, $check) = @_;
3060  
3061 # Local variables
3062 my $flag;
3063  
3064 # Check for improper arguments
3065 if (defined $check) {
3066  
3067 return $axmud::CLIENT->writeImproper($self->_objClass . '->setWidgetsIfSession', @_);
3068 }
3069  
3070 if ($self->visibleSession) {
3071 $flag = TRUE;
3072 } else {
3073 $flag = FALSE;
3074 }
3075  
3076 foreach my $stripObj ($self->ivValues('stripHash')) {
3077  
3078 $stripObj->setWidgetsIfSession($flag);
3079 }
3080  
3081 return 1;
3082 }
3083  
3084 sub setWidgetsChangeSession {
3085  
3086 # Called by $self->setVisibleSession
3087 # Calls each strip object (and, for GA::Strip::Table, any child table objects) so they can
3088 # update their widgets when any 'main' window's ->visibleSession changes
3089 #
3090 # Expected arguments
3091 # (none besides $self)
3092 #
3093 # Return values
3094 # 'undef' on improper arguments
3095 # 1 otherwise
3096  
3097 my ($self, $check) = @_;
3098  
3099 # Check for improper arguments
3100 if (defined $check) {
3101  
3102 return $axmud::CLIENT->writeImproper(
3103 $self->_objClass . '->setWidgetsChangeSession',
3104 @_,
3105 );
3106 }
3107  
3108 foreach my $stripObj ($self->ivValues('stripHash')) {
3109  
3110 $stripObj->setWidgetsChangeSession();
3111 }
3112  
3113 return 1;
3114 }
3115  
3116 # Strip object functions
3117  
3118 sub resetWinmap {
3119  
3120 # Returns the window to its initial state by removing all table objects and strip objects,
3121 # and applying the specified winmap (which might be the same as the previous one)
3122 # Useful for 'main' windows when the 'main_wait' winmap should be applied, or replaced
3123 # after being replied
3124 # Probably not useful for other 'internal' windows, though if code needs to apply the
3125 # equivalent 'internal_wait' winmap and, at some later time, replace it with something
3126 # else, it can
3127 #
3128 # Expected arguments
3129 # $winmapName - The name of the new winmap
3130 #
3131 # Return values
3132 # 'undef' on improper arguments or if the specified winmap doesn't exist
3133 # 1 otherwise
3134  
3135 my ($self, $winmapName, $check) = @_;
3136  
3137 # Local variables
3138 my $winmapObj;
3139  
3140 # Check for improper arguments
3141 if (defined $check) {
3142  
3143 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetWinmap', @_);
3144 }
3145  
3146 # Check the specified winmap exists
3147 $winmapObj = $axmud::CLIENT->ivShow('winmapHash', $winmapName);
3148 if (! $winmapObj) {
3149  
3150 return undef;
3151 }
3152  
3153 # Remove all strip objects (table objects in the compulsory Gtk3::Grid are also destroyed)
3154 foreach my $stripObj ($self->ivValues('stripHash')) {
3155  
3156 $stripObj->objDestroy();
3157  
3158 if ($stripObj->visibleFlag) {
3159  
3160 $axmud::CLIENT->desktopObj->removeWidget($self->packingBox, $stripObj->packingBox);
3161 }
3162 }
3163  
3164 # Remove the Gtk3::HBox or Gtk3::VBox into which everything is packed
3165 $axmud::CLIENT->desktopObj->removeWidget($self->winBox, $self->packingBox);
3166  
3167 # Update IVs
3168 $self->ivUndef('packingBox');
3169 $self->ivEmpty('stripHash');
3170 $self->ivEmpty('firstStripHash');
3171 $self->ivPoke('stripCount', 0);
3172 $self->ivEmpty('stripList');
3173 $self->ivUndef('tableStripObj');
3174  
3175 $self->ivPoke('winmap', $winmapObj->name);
3176  
3177 # Set up the window with its strip objects and table objects as if the window had just been
3178 # created
3179 $self->drawWidgets();
3180 $self->winShowAll($self->_objClass . '->resetWinmap');
3181 # This should already be set
3182 $self->ivPoke('enabledFlag', TRUE);
3183  
3184 return 1;
3185 }
3186  
3187 sub getWinmap {
3188  
3189 # Called by $self->addStripObj and ->revealStripObj
3190 # If $self->winmap is set (to the name of a winmap object), returns the winmap object
3191 # (GA::Obj::Winmap) itself
3192 # Otherwise returns an appropirate default winmap object
3193 #
3194 # Expected arguments
3195 # (none besides $self)
3196 #
3197 # Return values
3198 # 'undef' on improper arguments
3199 # Otherwise returns a winmap object (GA::Obj::Winmap)
3200  
3201 my ($self, $check) = @_;
3202  
3203 # Local variables
3204 my $winmapObj;
3205  
3206 # Check for improper arguments
3207 if (defined $check) {
3208  
3209 return $axmud::CLIENT->writeImproper($self->_objClass . '->getWinmap', @_);
3210 }
3211  
3212 $winmapObj = $axmud::CLIENT->ivShow('winmapHash', $self->winmap);
3213 if (! $winmapObj) {
3214  
3215 if ($self->winType eq 'main') {
3216  
3217 if ($axmud::CLIENT->activateGridFlag) {
3218  
3219 $winmapObj = $axmud::CLIENT->ivShow(
3220 'winmapHash',
3221 $axmud::CLIENT->defaultEnabledWinmap,
3222 );
3223  
3224 } else {
3225  
3226 $winmapObj = $axmud::CLIENT->ivShow(
3227 'winmapHash',
3228 $axmud::CLIENT->defaultDisabledWinmap,
3229 );
3230 }
3231  
3232 } else {
3233  
3234 $winmapObj = $axmud::CLIENT->ivShow(
3235 'winmapHash',
3236 $axmud::CLIENT->defaultInternalWinmap,
3237 );
3238 }
3239 }
3240  
3241 return $winmapObj;
3242 }
3243  
3244 sub addStripObj {
3245  
3246 # Can be called by anything (strip objects are also created by $self->drawWidgets() )
3247 # Adds a strip object (inheriting from GA::Generic::Strip) to the list of strip objects that
3248 # can be displayed in this window (whether the Gtk widget is actually drawn, or not,
3249 # depends on the value of the strip object's ->visibleFlag)
3250 #
3251 # Expected arguments
3252 # $packageName - The package name for the strip object to add, e.g.
3253 # GA::Strip::GaugeBox. This function can't be used to add the
3254 # compulsory GA::Strip::Table which already exists
3255 #
3256 # Optional arguments
3257 # $index - The new strip object's position in the window. Strip objects are
3258 # stored in $self->stripList, in the order in which they're drawn
3259 # (which could be top to bottom, bottom to top, left to right or right
3260 # to left). $index specifies the position in that list at which the
3261 # new strip object is inserted. If $index is 0, the strip object is
3262 # inserted at the beginning of the list. If $index is 1, it's inserted
3263 # second, if $index is 2, it's inserted third, and so on. If $index is
3264 # -1, it's inserted last. If $index is 'undef', or if its index is
3265 # outside the list, the strip object is inserted at the beginning of
3266 # the list
3267 # %initHash - If specified, a reference to a hash containing arbitrary data to use
3268 # as the strip object's initialisation settings (may be an empty
3269 # hash). The strip object should use default initialisation settings
3270 # unless it can succesfully interpret one or more of the key-value
3271 # pairs in the hash, if there are any)
3272 #
3273 # Return values
3274 # 'undef' on improper arguments or if the strip object can't be added
3275 # Otherwise returns the strip object added
3276  
3277 my ($self, $packageName, $index, %initHash) = @_;
3278  
3279 # Local variables
3280 my ($winmapObj, $stripObj, $spacing, $posn, $gaugeStripObj);
3281  
3282 # Check for improper arguments
3283 if (! defined $packageName) {
3284  
3285 return $axmud::CLIENT->writeImproper($self->_objClass . '->addStripObj', @_);
3286 }
3287  
3288 # Get the winmap object specified by $self->winmap, or a default winmap, if $self->winmap
3289 # is 'undef'
3290 $winmapObj = $self->getWinmap();
3291  
3292 # Set the position in the ordered list of strip objects at which the new strip object will
3293 # be inserted
3294 if (
3295 ! defined $index
3296 || $index < -1 # Sanity check
3297 || $index >= scalar ($self->stripList)
3298 ) {
3299 $index = 0;
3300 }
3301  
3302 # Strip objects must inherit from GA::Generic::Strip and must exist (in the case of strip
3303 # objects loaded from a plugin)
3304 if (
3305 ! $packageName =~ m/^Games\:\:Axmud\:\:Strip\:\:/
3306 || ! $axmud::CLIENT->ivExists('customStripHash', $packageName)
3307 ) {
3308 return undef;
3309 }
3310  
3311 # Create the strip object
3312 $stripObj = $packageName->new($self->stripCount, $self, %initHash);
3313 if (! $stripObj) {
3314  
3315 return undef;
3316 }
3317  
3318 # Some strip objects are 'jealous' (only one can be opened per window). If so, and if
3319 # another strip object of this type has already been created, discard the new one
3320 if ($stripObj->jealousyFlag && $self->ivExists('firstStripHash', $packageName)) {
3321  
3322 return undef;
3323 }
3324  
3325 # Some strip objects can't be added in Axmud blind mode
3326 if (! $stripObj->blindFlag && $axmud::BLIND_MODE_FLAG) {
3327  
3328 return undef;
3329 }
3330  
3331 # Draw the strip object's widgets
3332 if (! $stripObj->objEnable($winmapObj)) {
3333  
3334 return undef;
3335  
3336 } else {
3337  
3338 if ($stripObj->allowFocusFlag) {
3339 $stripObj->packingBox->set_can_focus(TRUE);
3340 } else {
3341 $stripObj->packingBox->set_can_focus(FALSE);
3342 }
3343 }
3344  
3345 # Make the strip object visible, if the flag is set
3346 if ($stripObj->visibleFlag) {
3347  
3348 # Pack the newly-visible strip, leaving a gap if it's not at the beginning or end of the
3349 # list
3350 # If $index is -1, it means 'pack at the end'
3351 if ($index == 0 || $index == -1) {
3352 $spacing = 0;
3353 } else {
3354 $spacing = $self->stripSpacingPixels;
3355 }
3356  
3357 if ($index > -1) {
3358  
3359 $self->packingBox->pack_start(
3360 $stripObj->packingBox,
3361 $stripObj->expandFlag,
3362 $stripObj->fillFlag,
3363 $spacing,
3364 );
3365  
3366 if ($index > 0) {
3367  
3368 $self->packingBox->reorder_child($stripObj->packingBox, $posn);
3369 }
3370  
3371 } else {
3372  
3373 $self->packingBox->pack_end(
3374 $stripObj->packingBox,
3375 $stripObj->expandFlag,
3376 $stripObj->fillFlag,
3377 $spacing,
3378 );
3379 }
3380 }
3381  
3382 # Update IVs
3383 $self->ivAdd('stripHash', $stripObj->number, $stripObj);
3384 if (! $self->ivExists('firstStripHash', $packageName)) {
3385  
3386 $self->ivAdd('firstStripHash', $packageName, $stripObj);
3387 }
3388  
3389 $self->ivIncrement('stripCount');
3390 $self->ivSplice('stripList', $index, 0, $stripObj);
3391  
3392 if ($packageName eq 'Games::Axmud::Strip::Table') {
3393  
3394 $self->ivPoke('tableStripObj', $stripObj);
3395 }
3396  
3397 # Notify all other strip objects of the new strip object's birth
3398 foreach my $otherStripObj (
3399 sort {$a->number <=> $b->number} ($self->ivValues('stripHash'))
3400 ) {
3401 if ($otherStripObj ne $stripObj) {
3402  
3403 $otherStripObj->notify_addStripObj($stripObj);
3404 }
3405 }
3406  
3407 # Sensitise/desensitise widgets according to current conditions
3408 $self->restrictMenuBars();
3409 $self->restrictToolbars();
3410  
3411 # Make everything visible
3412 $self->winShowAll($self->_objClass . '->addStripObj');
3413 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->addStripObj');
3414  
3415 # Adding/removing widgets upsets the position of the scrollbar in each tab's textview.
3416 # Make sure all the textviews are scrolled to the bottom
3417 $self->rescrollTextViews();
3418  
3419 # Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
3420 # themselves will have disappeared
3421 $gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
3422 if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
3423  
3424 $gaugeStripObj->updateGauges();
3425 # (Need to call this a second time, or the re-draw doesn't work...)
3426 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->addStripObj');
3427 }
3428  
3429 return $stripObj;
3430 }
3431  
3432 sub removeStripObj {
3433  
3434 # Can be called by anything
3435 # Removes a strip object (inheriting from GA::Generic::Strip) from the list of strip objects
3436 # that can be displayed in this window (whether the Gtk widget was actually drawn, or not,
3437 # depends on the value of the strip object's ->visibleFlag)
3438 # Can't be used to remove the compulsory GA::Strip::Table object
3439 #
3440 # Expected arguments
3441 # $stripObj - The strip object to remove
3442 #
3443 # Return values
3444 # 'undef' on improper arguments, if $stripObj is the compulsory GA::Strip::Table object
3445 # or if the object doesn't exist
3446 # 1 otherwise
3447  
3448 my ($self, $stripObj, $check) = @_;
3449  
3450 # Local variables
3451 my (
3452 $gaugeStripObj,
3453 @stripList, @resetList,
3454 );
3455  
3456 # Check for improper arguments
3457 if (! defined $stripObj || defined $check) {
3458  
3459 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeStripObj', @_);
3460 }
3461  
3462 # The GA::Strip::Table object is compulsory, also check that the strip object actually
3463 # exists in the window
3464 if (
3465 $stripObj->_objClass eq 'Games::Axmud::Strip::Table'
3466 || ! $self->ivExists('stripHash', $stripObj->number)
3467 ) {
3468 return undef
3469 }
3470  
3471 # Tell the strip object it's about to be removed, so it can do any necessary tidying up
3472 $stripObj->objDestroy();
3473 # Remove the Gtk3 widget that's contains the whole strip
3474 $axmud::CLIENT->desktopObj->removeWidget($self->packingBox, $stripObj->packingBox);
3475  
3476 # Remove the object by updating IVs
3477 $self->ivDelete('stripHash', $stripObj->number);
3478  
3479 foreach my $otherObj ($self->stripList) {
3480  
3481 if ($otherObj ne $stripObj) {
3482  
3483 push (@stripList, $otherObj);
3484 }
3485 }
3486  
3487 $self->ivPoke('stripList', @stripList);
3488  
3489 # $self->firstStripHash contains the earliest-created instance of this type of strip object.
3490 # Update or reset it
3491 $self->ivDelete('firstStripHash', $stripObj->_objClass);
3492 @resetList = sort {$a->number <=> $b->number} ($self->ivValues('stripHash'));
3493 OUTER: foreach my $otherObj (@resetList) {
3494  
3495 if ($otherObj->_objClass eq $stripObj->_objClass) {
3496  
3497 $self->ivAdd('firstStripHash', $otherObj->_objClass, $otherObj);
3498 last OUTER;
3499 }
3500 }
3501  
3502 # Notify all other strip objects of this strip object's demise
3503 foreach my $otherStripObj (
3504 sort {$a->number <=> $b->number} ($self->ivValues('stripHash'))
3505 ) {
3506 if ($otherStripObj ne $stripObj) {
3507  
3508 $otherStripObj->notify_removeStripObj($stripObj);
3509 }
3510 }
3511  
3512 # Sensitise/desensitise widgets according to current conditions
3513 $self->restrictMenuBars();
3514 $self->restrictToolbars();
3515  
3516 # Make everything visible
3517 $self->winShowAll($self->_objClass . '->removeStripObj');
3518 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->removeStripObj');
3519  
3520 # Hack to resolve a Gtk3 issue, in which a white area appears at the bottom of textviews
3521 # when the gauge strip object is removed (and possibly in similar situations)
3522 foreach my $tableObj ($self->tableStripObj->ivValues('tableObjHash')) {
3523  
3524 if ($tableObj->type eq 'pane') {
3525  
3526 foreach my $tabObj ($tableObj->ivValues('tabObjHash')) {
3527  
3528 $tabObj->textViewObj->insertNewLine();
3529 }
3530 }
3531 }
3532  
3533 # Adding/removing widgets upsets the position of the scrollbar in each tab's textview.
3534 # Make sure all the textviews are scrolled to the bottom
3535 $self->rescrollTextViews();
3536  
3537 # Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
3538 # themselves will have disappeared
3539 $gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
3540 if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
3541  
3542 $gaugeStripObj->updateGauges();
3543 # (Need to call this a second time, or the re-draw doesn't work...)
3544 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->removeStripObj');
3545 }
3546  
3547 return 1;
3548 }
3549  
3550 sub addStrip {
3551  
3552 # Convenient shortcut to $self->addStripObj, which expects a package name like
3553 # GA::Strip::GaugeBox as an argument
3554 #
3555 # This function accepts a string, which can be any of the following (case-insensitive):
3556 # 'menu' / 'menubar' / 'menu_bar' - adds a GA::Strip::MenuBar
3557 # 'tool' / 'toolbar' / 'tool_bar' - adds a GA::Strip::Toolbar
3558 # 'gauge' / 'gaugebox' / 'gauge_box' - adds a GA::Strip::GaugeBox
3559 # 'entry' - adds a GA::Strip::Entry
3560 # 'connect' / 'info' / 'connectinfo' / 'connect_info'
3561 # - adds a GA::Strip::ConnectInfo
3562 #
3563 # The string can also be a part of the package name itself. For example, if you create your
3564 # own GA::Strip::MyObject (inheriting from GA::Strip::Custom), then this function expects
3565 # the string 'MyObject' (case-sensitive)
3566 # NB This function is not able to check that the package actually exists, although Axmud's
3567 # built-in strip objects always exist
3568 # NB This function can't be used to add the compulsory GA::Strip::Table which already
3569 # exists
3570 #
3571 # Expected arguments
3572 # $string - The string described above
3573 #
3574 # Optional arguments
3575 # $index - The new strip object's position in the window. Strip objects are stored in
3576 # $self->stripList, in the order in which they're drawn (which could be
3577 # top to bottom, bottom to top, left to right or right to left). $index
3578 # specifies the position in that list at which the new strip object is
3579 # inserted. If $index is 0, the strip object is inserted at the beginning
3580 # of the list. If $index is 1, it's inserted second, if $index is 2, it's
3581 # inserted third, and so on. If $index is 'undef', or if its index is
3582 # outside the list, the strip object is inserted at the beginning of the
3583 # list
3584 #
3585 # Return values
3586 # 'undef' on improper arguments or if the strip object can't be added
3587 # Otherwise returns the strip object added
3588  
3589 my ($self, $string, $index, $check) = @_;
3590  
3591 # Local variables
3592 my $packageName;
3593  
3594 # Check for improper arguments
3595 if (! defined $string || defined $check) {
3596  
3597 return $axmud::CLIENT->writeImproper($self->_objClass . '->addStrip', @_);
3598 }
3599  
3600 # Convert $string into a package name
3601 $packageName = $self->convertPackageName($string);
3602 if (! $packageName || $packageName eq 'Games::Axmud::Strip::Table') {
3603  
3604 return undef;
3605  
3606 } else {
3607  
3608 return $self->addStripObj($packageName, $index);
3609 }
3610 }
3611  
3612 sub removeStrip {
3613  
3614 # Convenient shortcut to $self->removeStripObj, which expects a package name like
3615 # GA::Strip::GaugeBox as an argument
3616 #
3617 # This function accepts a string, which can be any of the following (case-insensitive):
3618 # 'menu' / 'menubar' / 'menu_bar' - adds a GA::Strip::MenuBar
3619 # 'tool' / 'toolbar' / 'tool_bar' - adds a GA::Strip::Toolbar
3620 # 'gauge' / 'gaugebox' / 'gauge_box' - adds a GA::Strip::GaugeBox
3621 # 'entry' - adds a GA::Strip::Entry
3622 # 'connect' / 'info' / 'connectinfo' / 'connect_info'
3623 # - adds a GA::Strip::ConnectInfo
3624 #
3625 # The string can also be a part of the package name itself. For example, if you create your
3626 # own GA::Strip::MyObject (inheriting from GA::Strip::Custom), then this function expects
3627 # the string 'MyObject' (case-sensitive)
3628 #
3629 # After converting the string into a package name, this function calls $self->removeStripObj
3630 # to remove the earliest-created instance of that strip object, if any exists
3631 # NB This function is not able to check that the package actually exists, although Axmud's
3632 # built-in strip objects always exist
3633 # NB This function can't be used to remove the compulsory GA::Strip::Table
3634 #
3635 # Expected arguments
3636 # $string - The string described above
3637 #
3638 # Return values
3639 # 'undef' on improper arguments or if no strip object is removed
3640 # 1 if a strip object is removed
3641  
3642 my ($self, $string, $check) = @_;
3643  
3644 # Local variables
3645 my ($packageName, $stripObj);
3646  
3647 # Check for improper arguments
3648 if (! defined $string || defined $check) {
3649  
3650 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeStrip', @_);
3651 }
3652  
3653 # Convert $string into a package name
3654 $packageName = $self->convertPackageName($string);
3655 if (! $packageName || $packageName eq 'Games::Axmud::Strip::Table') {
3656  
3657 return undef;
3658 }
3659  
3660 # Find the earliest-created instance of that strip object
3661 $stripObj = $self->ivShow('firstStripHash', $packageName);
3662 if (! $stripObj) {
3663  
3664 return undef;
3665  
3666 } else {
3667  
3668 return $self->removeStripObj($stripObj);
3669 }
3670 }
3671  
3672 sub hideStripObj {
3673  
3674 # Can be called by anything
3675 # Hides a visible strip object; the strip object remains in the list of strip objects this
3676 # window can display, but the Gtk widget itself is no longer drawn
3677 # Can't be used to hide the compulsory GA::Strip::Table object
3678 #
3679 # Expected arguments
3680 # $stripObj - The strip object to hide
3681 #
3682 # Return values
3683 # 'undef' on improper arguments, if $stripObj is the compulsory GA::Strip::Table object,
3684 # if the object doesn't exist or if it is already hidden
3685 # 1 otherwise
3686  
3687 my ($self, $stripObj, $check) = @_;
3688  
3689 # Local variables
3690 my $gaugeStripObj;
3691  
3692 # Check for improper arguments
3693 if (! defined $stripObj || defined $check) {
3694  
3695 return $axmud::CLIENT->writeImproper($self->_objClass . '->hideStripObj', @_);
3696 }
3697  
3698 # The GA::Strip::Table object is compulsory, also check that the strip object actually
3699 # exists in the window object's list of strip objects and is actually visible
3700 if (
3701 $stripObj->_objClass eq 'Games::Axmud::Strip::Table'
3702 || ! $self->ivExists('stripHash', $stripObj->number)
3703 || ! $stripObj->visibleFlag
3704 ) {
3705 return undef
3706 }
3707  
3708 # Remove the Gtk3 widget that contains the whole strip
3709 $axmud::CLIENT->desktopObj->removeWidget($self->packingBox, $stripObj->packingBox);
3710 # Update IVs
3711 $stripObj->set_visibleFlag(FALSE);
3712  
3713 # Sensitise/desensitise widgets according to current conditions
3714 $self->restrictMenuBars();
3715 $self->restrictToolbars();
3716  
3717 # Make everything visible
3718 $self->winShowAll($self->_objClass . '->hideStripObj');
3719 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->hideStripObj');
3720  
3721 # Hack to resolve a Gtk3 issue, in which a white area appears at the bottom of textviews
3722 # when the gauge strip object is removed (and possibly in similar situations)
3723 foreach my $tableObj ($self->tableStripObj->ivValues('tableObjHash')) {
3724  
3725 if ($tableObj->type eq 'pane') {
3726  
3727 foreach my $tabObj ($tableObj->ivValues('tabObjHash')) {
3728  
3729 $tabObj->textViewObj->insertNewLine();
3730 }
3731 }
3732 }
3733  
3734 # Adding/removing widgets upsets the position of the scrollbar in each tab's textview.
3735 # Make sure all the textviews are scrolled to the bottom
3736 $self->rescrollTextViews();
3737  
3738 # Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
3739 # themselves will have disappeared
3740 $gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
3741 if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
3742  
3743 $gaugeStripObj->updateGauges();
3744 # (Need to call this a second time, or the re-draw doesn't work...)
3745 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->hideStripObj');
3746 }
3747  
3748 return 1;
3749 }
3750  
3751 sub revealStripObj {
3752  
3753 # Can be called by anything
3754 # Reveals a hidden strip object; the strip object was still in the list of strip objects
3755 # this window can display, but the Gtk widget itself was not drawn, so draw it and add it
3756 # to the window
3757 #
3758 # Expected arguments
3759 # $stripObj - The strip object to reveal
3760 #
3761 # Return values
3762 # 'undef' on improper arguments, if the object doesn't exist, if it is already visible or
3763 # if there's an error in revealing it
3764 # 1 otherwise
3765  
3766 my ($self, $stripObj, $check) = @_;
3767  
3768 # Local variables
3769 my ($winmapObj, $count, $posn, $spacing, $gaugeStripObj);
3770  
3771 # Check for improper arguments
3772 if (! defined $stripObj || defined $check) {
3773  
3774 return $axmud::CLIENT->writeImproper($self->_objClass . '->revealStripObj', @_);
3775 }
3776  
3777 # Get the winmap object specified by $self->winmap, or a default winmap, if $self->winmap
3778 # is 'undef'
3779 $winmapObj = $self->getWinmap();
3780  
3781 # Check that the strip object actually exists in the window object's list of strip objects
3782 # and is actually hidden
3783 if (! $self->ivExists('stripHash', $stripObj->number) || $stripObj->visibleFlag) {
3784  
3785 return undef
3786 }
3787  
3788 # Find the strip object's position in the list of visible strip objects
3789 $count = 0;
3790 OUTER: foreach my $otherObj ($self->stripList) {
3791  
3792 if ($otherObj eq $stripObj) {
3793  
3794 $posn = $count;
3795 last OUTER;
3796  
3797 } elsif ($otherObj->visibleFlag) {
3798  
3799 $count++;
3800 }
3801 }
3802  
3803 if (! defined $posn) {
3804  
3805 # Strip object is missing (for some unlikely reason)
3806 return undef;
3807 }
3808  
3809 # Draw the strip object's widgets
3810 if (! $stripObj->objEnable($winmapObj)) {
3811  
3812 return undef;
3813 }
3814  
3815 # Pack the newly-visible strip, leaving a gap if it's not at the beginning or end of the
3816 # list
3817 if (! $count || $posn == ($count - 1)) {
3818 $spacing = 0;
3819 } else {
3820 $spacing = $self->stripSpacingPixels;
3821 }
3822  
3823 $self->packingBox->pack_start(
3824 $stripObj->packingBox,
3825 $stripObj->expandFlag,
3826 $stripObj->fillFlag,
3827 $spacing,
3828 );
3829  
3830 if ($posn != 0) {
3831  
3832 $self->packingBox->reorder_child($stripObj->packingBox, $posn);
3833 }
3834  
3835 # Update IVs
3836 $stripObj->set_visibleFlag(TRUE);
3837  
3838 # Sensitise/desensitise widgets according to current conditions
3839 $self->restrictMenuBars();
3840 $self->restrictToolbars();
3841  
3842 # Make everything visible
3843 $self->winShowAll($self->_objClass . '->revealStripObj');
3844 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->revealStripObj');
3845  
3846 # Adding/removing widgets upsets the position of the scrollbar in each tab's textview.
3847 # Make sure all the textviews are scrolled to the bottom
3848 $self->rescrollTextViews();
3849  
3850 # Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
3851 # themselves will have disappeared
3852 $gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
3853 if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
3854  
3855 $gaugeStripObj->updateGauges();
3856 # (Need to call this a second time, or the re-draw doesn't work...)
3857 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->revealStripObj');
3858 }
3859  
3860 return 1;
3861 }
3862  
3863 sub replaceStripObj {
3864  
3865 # Can be called by anything
3866 # If a strip object has been redrawn for any reason, replace the old Gtk widget with the
3867 # new one. The strip object's ->packingBox IV must already have been set to the new Gtk
3868 # widget before calling this function
3869 #
3870 # Expected arguments
3871 # $stripObj - The strip object to replace
3872 #
3873 # Return values
3874 # 'undef' on improper arguments, if the object doesn't exist or if it hidden
3875 # 1 otherwise
3876  
3877 my ($self, $stripObj, $check) = @_;
3878  
3879 # Local variables
3880 my ($count, $posn, $spacing, $gaugeStripObj);
3881  
3882 # Check for improper arguments
3883 if (! defined $stripObj || defined $check) {
3884  
3885 return $axmud::CLIENT->writeImproper($self->_objClass . '->replaceStripObj', @_);
3886 }
3887  
3888 # Check that the strip object actually exists in the window object's list of strip objects
3889 # and is actually visible
3890 if (! $self->ivExists('stripHash', $stripObj->number) || ! $stripObj->visibleFlag) {
3891  
3892 return undef
3893 }
3894  
3895 # Find the strip object's position in the list of visible strip objects
3896 $count = 0;
3897 OUTER: foreach my $otherObj ($self->stripList) {
3898  
3899 if ($otherObj eq $stripObj) {
3900  
3901 $posn = $count;
3902 last OUTER;
3903  
3904 } elsif ($otherObj->visibleFlag) {
3905  
3906 $count++;
3907 }
3908 }
3909  
3910 if (! defined $posn) {
3911  
3912 # Strip object is missing (for some unlikely reason)
3913 return undef;
3914 }
3915  
3916  
3917 # Remove the old Gtk3 widget that contains the whole strip
3918 $axmud::CLIENT->desktopObj->removeWidget($self->packingBox, $stripObj->packingBox);
3919 # Pack the newly-visible strip, leaving a gap if it's not at the beginning or end of the
3920 # list
3921 if (! $count || $posn == ($count - 1)) {
3922 $spacing = 0;
3923 } else {
3924 $spacing = $self->stripSpacingPixels;
3925 }
3926  
3927 $self->packingBox->pack_start(
3928 $stripObj->packingBox,
3929 $stripObj->expandFlag,
3930 $stripObj->fillFlag,
3931 $spacing,
3932 );
3933  
3934 if ($posn != 0) {
3935  
3936 $self->packingBox->reorder_child($stripObj->packingBox, $posn);
3937 }
3938  
3939 # Sensitise/desensitise widgets according to current conditions
3940 $self->restrictMenuBars();
3941 $self->restrictToolbars();
3942  
3943 # Make everything visible
3944 $self->winShowAll($self->_objClass . '->replaceStripObj');
3945 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->replaceStripObj');
3946  
3947 # Redraw any visible gauges, otherwise the gauge box will be visible, but the gauges
3948 # themselves will have disappeared
3949 $gaugeStripObj = $self->ivShow('firstStripHash', 'Games::Axmud::Strip::GaugeBox');
3950 if ($gaugeStripObj && $gaugeStripObj->visibleFlag) {
3951  
3952 $gaugeStripObj->updateGauges();
3953 # (Need to call this a second time, or the re-draw doesn't work...)
3954 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->replaceStripObj');
3955 }
3956  
3957 return 1;
3958 }
3959  
3960 sub getStrip {
3961  
3962 # Convenient method for getting the blessed reference of the earliest-created instance of a
3963 # type of strip object
3964 #
3965 # This function accepts a string, which can be any of the following (case-insensitive):
3966 # 'menu' / 'menubar' / 'menu_bar' - converts to GA::Strip::MenuBar
3967 # 'tool' / 'toolbar' / 'tool_bar' - converts to GA::Strip::Toolbar
3968 # 'table' - converts to GA::Strip::Table
3969 # 'gauge' / 'gaugebox' / 'gauge_box' - converts to GA::Strip::GaugeBox
3970 # 'search' / 'searchbox' / 'search_box' - converts to GA::Strip::SearchBox
3971 # 'entry' - converts to GA::Strip::Entry
3972 # 'connect' / 'info' / 'connectinfo' / 'connect_info'
3973 # - converts to GA::Strip::ConnectInfo
3974 #
3975 # The string can also be a part of the package name itself. For example, if you create your
3976 # own GA::Strip::MyObject (inheriting from GA::Strip::Custom), then this function expects
3977 # the string 'MyObject' (case-sensitive)
3978 #
3979 # Expected arguments
3980 # $string - The string described above
3981 #
3982 # Return values
3983 # 'undef' on improper arguments or if a strip object of that type doesn't exist in the
3984 # window
3985 # Otherwise returns the blessed reference to the earliest-created instance of the
3986 # specified type of strip object
3987  
3988 my ($self, $string, $check) = @_;
3989  
3990 # Local variables
3991 my $packageName;
3992  
3993 # Check for improper arguments
3994 if (! defined $string || defined $check) {
3995  
3996 return $axmud::CLIENT->writeImproper($self->_objClass . '->getStrip', @_);
3997 }
3998  
3999 # Convert $string into a package name
4000 $packageName = $self->convertPackageName($string);
4001 if (! $packageName || $packageName eq 'Games::Axmud::Strip::Table') {
4002  
4003 return undef;
4004 }
4005  
4006 # Return the earliest-created instance of that strip object (return 'undef' if none exists)
4007 return $self->ivShow('firstStripHash', $packageName);
4008 }
4009  
4010 sub convertPackageName {
4011  
4012 # Called by $self->addStrip, ->getStrip and $self->removeStrip
4013 # Converts a simple string (e.g. 'menu' into the package name of a strip object (e.g.
4014 # 'Games::Axmud::Strip::MenuBar'
4015 #
4016 # This function accepts a string, which can be any of the following (case-insensitive):
4017 # 'menu' / 'menubar' / 'menu_bar' - converts to GA::Strip::MenuBar
4018 # 'tool' / 'toolbar' / 'tool_bar' - converts to GA::Strip::Toolbar
4019 # 'table' - converts to GA::Strip::Table
4020 # 'gauge' / 'gaugebox' / 'gauge_box' - converts to GA::Strip::GaugeBox
4021 # 'search' / 'searchbox' / 'search_box' - converts to GA::Strip::SearchBox
4022 # 'entry' - converts to GA::Strip::Entry
4023 # 'connect' / 'info' / 'connectinfo' / 'connect_info'
4024 # - converts to GA::Strip::ConnectInfo
4025 #
4026 # The string can also be a part of the package name itself. For example, if you create your
4027 # own GA::Strip::MyObject (inheriting from GA::Strip::Custom), then this function expects
4028 # the string 'MyObject' (case-sensitive)
4029 #
4030 # Expected arguments
4031 # $string - The string to convert
4032 #
4033 # Return values
4034 # 'undef' on improper arguments
4035 # Otherwise returns a strip object's package name
4036  
4037 my ($self, $string, $check) = @_;
4038  
4039 # Local variables
4040 my $packageName;
4041  
4042 # Check for improper arguments
4043 if (! defined $string || defined $check) {
4044  
4045 return $axmud::CLIENT->writeImproper($self->_objClass . '->convertPackageName', @_);
4046 }
4047  
4048 if (
4049 lc($string) eq 'menu' || lc($string) eq 'menubar' || lc($string) eq 'menu_bar'
4050 ) {
4051 $packageName = 'Games::Axmud::Strip::MenuBar';
4052  
4053 } elsif (
4054 lc($string) eq 'tool' || lc($string) eq 'toolbar' || lc($string) eq 'tool_bar'
4055 ) {
4056 $packageName = 'Games::Axmud::Strip::Toolbar';
4057  
4058 } elsif (
4059 lc($string) eq 'gauge' || lc($string) eq 'gaugebox' || lc($string) eq 'gauge_box'
4060 ) {
4061 $packageName = 'Games::Axmud::Strip::GaugeBox';
4062  
4063 } elsif (
4064 lc($string) eq 'search' || lc($string) eq 'searchbox' || lc($string) eq 'search_box'
4065 ) {
4066 $packageName = 'Games::Axmud::Strip::SearchBox';
4067  
4068 } elsif (lc($string) eq 'entry') {
4069  
4070 $packageName = 'Games::Axmud::Strip::Entry';
4071  
4072 } elsif (
4073 lc($string) eq 'connect' || lc($string) eq 'info' || lc($string) eq 'connectinfo'
4074 || lc($string) eq 'connect_info'
4075 ) {
4076 $packageName = 'Games::Axmud::Strip::ConnectInfo';
4077  
4078 } else {
4079  
4080 $packageName = 'Games::Axmud::Strip::' . $string;
4081 }
4082  
4083 return $packageName;
4084 }
4085  
4086 ##################
4087 # Accessors - set
4088  
4089 ##################
4090 # Accessors - get
4091  
4092 sub stripHash
4093 { my $self = shift; return %{$self->{stripHash}}; }
4094 sub firstStripHash
4095 { my $self = shift; return %{$self->{firstStripHash}}; }
4096 sub stripCount
4097 { $_[0]->{stripCount} }
4098 sub stripList
4099 { my $self = shift; return @{$self->{stripList}}; }
4100 sub tableStripObj
4101 { $_[0]->{tableStripObj} }
4102 sub stripSpacingPixels
4103 { $_[0]->{stripSpacingPixels} }
4104  
4105 sub visibleSession
4106 { $_[0]->{visibleSession} }
4107  
4108 sub hostLabelText
4109 { $_[0]->{hostLabelText} }
4110 sub timeLabelText
4111 { $_[0]->{timeLabelText} }
4112  
4113 sub ctrlKeyFlag
4114 { $_[0]->{ctrlKeyFlag} }
4115 sub shiftKeyFlag
4116 { $_[0]->{shiftKeyFlag} }
4117 sub altKeyFlag
4118 { $_[0]->{altKeyFlag} }
4119 sub altGrKeyFlag
4120 { $_[0]->{altGrKeyFlag} }
4121 sub modifierKeyFlag
4122 { $_[0]->{modifierKeyFlag} }
4123  
4124 sub actualWinWidth
4125 { $_[0]->{actualWinWidth} }
4126 sub actualWinHeight
4127 { $_[0]->{actualWinHeight} }
4128 sub maximisedFlag
4129 { $_[0]->{maximisedFlag} }
4130 sub focusFlag
4131 { $_[0]->{focusFlag} }
4132 }
4133  
4134 # Package must return a true value
4135 1