blib/lib/Games/Axmud/Obj/TextView.pm untested

filter: Statementstmt 0.0% 0 / 2712 Branchbran 0.0% 0 / 1482 Conditioncond 0.0% 0 / 993 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 173 Podpod 0.0% 0 / 169 totaltotal 0.0% 0 / 5529 CC 742 SCAR 62.9
CC
742
Cov
0%
applyColourStyleTags
3906.0
interpretTags
1190.0
showSystemText
930.0
CRAP 539.5
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::Obj::TextView
16 # A textview object, which handles a single Gtk3::TextView
17  
18 { package Games::Axmud::Obj::TextView;
19  
20 use strict;
21 use warnings;
22 use diagnostics;
23  
24 use Glib qw(TRUE FALSE);
25  
26 our @ISA = qw(Games::Axmud);
27  
28 ##################
29 # Constructors
30  
31 sub new {
32  
33 # Called by GA::Obj::Desktop->add_textview()
34 # Creates a textview object, which handles a single Gtk3::TextView (or, in split screen
35 # mode, two textviews sharing a single Gtk3::TextBuffer)
36 #
37 # Expected arguments
38 # $session - The GA::Session which controls this textview
39 # $number - Unique number for this textview object across all sessions (matches
40 # GA::Obj::Desktop->textViewCount)
41 # $winObj - The window object (inheriting from GA::Generic::Win) in which this
42 # object's textview(s) are displayed
43 #
44 # Optional aguments
45 # $paneObj - For textview objects that will be added to the Gtk3::Grid in an 'internal'
46 # window (specifically, added directly to a GA::Strip::Table object), that
47 # GA::Strip::Table object. Set to 'undef' for a textview object created
48 # for any other reason
49 #
50 # Return values
51 # 'undef' on improper arguments
52 # Blessed reference to the newly-created object on success
53  
54 my ($class, $session, $number, $winObj, $paneObj, $check) = @_;
55  
56 # Local variables
57 my %colourStyleHash;
58  
59 # Check for improper arguments
60 if (
61 ! defined $class || ! defined $session || ! defined $number || ! defined $winObj
62 || defined $check
63 ) {
64 return $axmud::CLIENT->writeImproper($class . '->new', @_);
65 }
66  
67 # Import constant hash with inintial values we need
68 %colourStyleHash = $axmud::CLIENT->constColourStyleHash;
69  
70 # Setup
71 my $self = {
72 _objName => 'textview_' . $number,
73 _objClass => $class,
74 _parentFile => undef, # No parent file object
75 _parentWorld => undef, # No parent file object
76 _privFlag => TRUE, # All IVs are private
77  
78 # IVs
79 # ---
80  
81 # The GA::Session which controls this textview
82 session => $session,
83 # Unique number for this textview object across all sessions (matches
84 # GA::Obj::Desktop->textViewCount)
85 number => $number,
86 # The window object (inheriting from GA::Generic::Win) in which this object's
87 # textview(s) are displayed
88 winObj => $winObj,
89 # For textview objects that will be added to the Gtk3::Grid in an 'internal' window
90 # (specifically, added directly to a GA::Strip::Table object), that
91 # GA::Strip::Table object. Set to 'undef' for a textview object created for any
92 # other reason
93 paneObj => $paneObj,
94  
95 # Widgets
96 textView => undef, # Gtk3::TextView
97 textView2 => undef, # Gtk3::TextView
98 buffer => undef, # Gtk3::TextBuffer
99 vPaned => undef, # Gtk3::VPaned
100 scroll => undef, # Gtk3::ScrolledWindow
101 scroll2 => undef, # Gtk3::ScrolledWindow
102 startMark => undef, # Gtk3::TextMark
103 endMark => undef, # Gtk3::TextMark
104 searchMark => undef, # Gtk3::TextMark
105 popupMenu => undef, # Gtk3::Menu
106  
107 # Other IVs
108  
109 # Flag set to TRUE when the scroll lock is enabled, FALSE when it is disabled (only
110 # applies to the original Gtk3::TextView)
111 scrollLockFlag => TRUE,
112 # What type of scroll lock to apply - 'top' if the original textview should remain
113 # scrolled to the top, 'bottom' if it should remain scrolled to the bottom
114 scrollLockType => 'bottom',
115 # Split screen mode. Because of performance issues with very large Gtk3::TextBuffers,
116 # if the user is likely to want a split screen (with two Gtk3::TextView, separated by
117 # a divider and sharing the same Gtk3::TextBuffer), it's usually better to create both
118 # Gtk3::TextViews when this textview object is created, rather than starting with a
119 # single textview and creating (or destroying) the second one as need be
120 # This IV is set to the current split screen mode, and is updated whenever the mode is
121 # changed via calls to $self->setSplitScreenMode:
122 # 'single' - Only one Gtk3::TextView
123 # 'split' - Two Gtk3::TextViews with a divider between them, positioned so
124 # they are both visible
125 # 'hidden' - Two Gtk3::TextViews with a divider between them, positioned at the
126 # top of the screen so the second textview is invisible (and the
127 # divider itself is almost invisible); however, the user is free
128 # to move it manually, and when they do so, the IV remains set to
129 # 'hidden')
130 splitScreenMode => 'single',
131  
132 # The colour scheme applied to this textview object (matches a key in
133 # GA::Client->colourSchemeHash)
134 # To apply a colour scheme, the textview object must not be called directly; instead,
135 # call $self->paneObj->updateColourScheme, ->applyColourScheme, ->applyMonochrome or
136 # ->removeMonochrome
137 colourScheme => undef,
138 # The text colours
139 textColour => undef,
140 underlayColour => undef,
141 backgroundColour => undef,
142 # The font and fontsize
143 font => undef,
144 fontSize => undef,
145 # Some parts of the code (for example the Status task) want to use a textview with only
146 # two colours - text and background. This is called 'monochrome mode'
147 # Set to TRUE on the first call to $self->setMonochromeMode which changes the textview's
148 # background colour to a specified colour, and chooses suitable text/underlay colours
149 # (for example, specify 'blue' for white text on a blue background). The colours can
150 # be changed any time with further calls to ->setMonochromeMode
151 # When TRUE, calls to ->insertText and ->showSystemText ignore any Axmud colour tags
152 # that are specified (but not Axmud style tags, which are processed as usual). Calls
153 # to ->insertCmd, ->showError, ->showWarning, ->showDebug, ->showImproper do not use
154 # their normal text colours
155 # When TRUE, the colour scheme only changes on calls to ->setMonochromeMode. It doesn't
156 # change when a new colour scheme is applied (via a call to $self->objUpdate, itself
157 # called by GA::Table::Pane->applyColourScheme)
158 # Set back to FALSE by a call to $self->resetMonochromeMode, at which point the colour
159 # scheme stored in $self->colourScheme is applied (it might have changed since this
160 # flag was first set to TRUE)
161 monochromeFlag => FALSE,
162 # In monochrome mode, we need to know when the colours used are the same as those
163 # specified by the colour scheme, and when they're different (because if the colour
164 # scheme's colours change, by the time $self->objUpdate is called, there is no way
165 # of comparing the colour scheme's previous colours to the colours currently used in
166 # this textview)
167 # Flag set whenever ->monochromeFlag is set to TRUE (and reset if ->monochromeFlag is
168 # set to FALSE)
169 # When ->setMonochromeMode is called, this flag checks the textview's current
170 # background colour against the background specified by the colour scheme (we don't
171 # check the text colour, because it's normally set automatically to match the
172 # background)
173 # If the background colours are different, this flag is set to TRUE. If they're the
174 # same, this flag is set to FALSE
175 # When ->resetMonochromeMode is called, this flag is set back to FALSE
176 monochromeModFlag => FALSE,
177 # Ovewrite mode. The default value is FALSE, in which calls to $self->insertText (etc)
178 # and ->insertCmd insert text at the end of the Gtk3::TextBuffer (or very near the
179 # end, if system messages are visible on the final lines)
180 # Any code that uses cursor control to overwrite existing lines will call
181 # $self->setInsertPosn, ->adjustInsertPosn, ->adjustInsertLine, ->adjustInsertOffset
182 # or ->restoreInsertPosn
183 # Calls to any of these functions turn on ovewrite mode, which sets the flag to TRUE.
184 # (Overwite mode can also be turned on via a call to $self->enableOverwrite(), or by
185 # specifying an optional argument in calls to $self->clearBufferAfterPosn,
186 # ->storeInsertPosn, etc
187 # Once turned on, overwrite mode should not be turned off unless a connection to a world
188 # terminates (in which case, GA::Session->doDisconnect or ->reactDisconnect call
189 # $self->disableOverwrite()
190 # When turned on, system messages are not displayed in the textview (and are instead
191 # diverted to the Session Console window), and when the buffer's size exceeds the
192 # maximum number of lines, the oldest line is not deleted
193 overwriteFlag => FALSE,
194  
195 # The maximum number of lines that the Gtk3::TextBuffer can contain. If 'undef' or 0,
196 # unlimited lines; otherwise when the maximum is reached, the earliest line is
197 # removed when a new line is added
198 maxLines => $axmud::CLIENT->customTextBufferSize,
199 # The oldest remaining line to delete when the buffer is full
200 nextDeleteLine => 0,
201  
202 # A scrolling region inside the buffer. If enabled, these two IVs are set to the line
203 # numbers of the top and bottom line of the scrolling region. If disabled, these two
204 # IVs are 'undef'
205 # If defined, ->scrlRegionTop must be at least one less than ->scrlRegionBottom.
206 # ->scrlRegionTop must be 0 or above. If ->scrlRegionBottom is larger than the size
207 # of the buffer, then the size of the buffer is used
208 scrlRegionTop => undef,
209 scrlRegionBottom => undef,
210  
211 # Flag set to TRUE when the buffer contains some text, and FALSE when it is empty (is
212 # TRUE if the buffer contains a single newline character; is FALSE if an empty buffer
213 # has an empty string 'inserted' into it along with one or more tags)
214 bufferTextFlag => FALSE,
215 # When the size of the visible textview needs to be updated, the new size can't be
216 # worked out until the changes have been rendered (via calls to either
217 # GA::Obj::Desktop->updateWidgets or GA::Generic::Win->winShowAll)
218 # If the size must be updated, any code can set this flag (by calling
219 # $self->set_sizeUpdateFlag)
220 sizeUpdateFlag => FALSE,
221 # GA::Obj::Desktop->updateWidgets and GA::Generic::Win->winShowAll, when called, check
222 # the flag and call $self->updateVisibleSize() to set the following IVs
223 textWidthChars => undef,
224 textHeightChars => undef,
225 # Flag set to TRUE when the last line of the buffer ends in a newline character; FALSE
226 # if it ends in any other character. Initially set to TRUE, since an empty buffer is
227 # treated as though a whole line, ending in a newline character, has been removed
228 # from the beginning of the buffer (whether or not it has)
229 newLineFlag => TRUE,
230 # Flag set to TRUE when the current insertion position is preceded by a newline
231 # character (or if the the insertion position is at the beginning of the buffer, or if
232 # the buffer is empty), FALSE if the current insertion position is preceded by any
233 # other character
234 insertNewLineFlag => TRUE,
235 # The default behaviour for calls to $self->insertText (but not to ->showSystemText)
236 # 'before' - prepends a newline character to the text
237 # 'after' - appends a newline character to the text
238 # 'nl' - same behaviour as 'after'
239 # 'echo' - does not prepend/append a newline character by default
240 newLineDefault => 'after',
241 # Flag than can be set to TRUE by anything (via a call to $self->set_clearAfterInsert)
242 # if the buffer should be emptied, the next time any non-system or system text is
243 # inserted into it (the flag is automatically set back to FALSE after that operation)
244 clearAfterInsertFlag => TRUE,
245  
246 # The Gtk3::TextMark which marks the point in the Gtk3::TextBuffer at which
247 # $self->insertText inserts text, and at which $self->insertCmd inserts world
248 # commands. Whenever it is 'undef', both are inserted at the end of the buffer. Code
249 # can call $self->setInsertPosn to set a different insert position, and then call
250 # $self->resetInsertPosn to reset the insert position
251 insertMark => undef,
252 # When code wants to specify an insert position, it calls $self->setInsertPosn, which
253 # sets $self->insertMark
254 # However, if some code (such as GA::Session->processMxpDestElement) needs to
255 # temporarily insert text at a particular location, we need to store the value of
256 # $self->insertMark before the call to ->setInsertPosn, so it can be restored when the
257 # calling code is ready (via a call to $self->resetInsertPosn)
258 # In most cases, $self->insertMark will have been 'undef' meaning that text is inserted
259 # at the end of the buffer, in which case $self->resetInsertPosn will restore its
260 # value to 'undef'
261 restoreInsertMark => undef,
262 # When $self->newLineFlag is FALSE (meaning the buffer doesn't end with a newline
263 # character) and a system message needs to be shown (via a call to
264 # $self->showSystemText, ->showError, ->showWarning, ->showDebug or ->showImproper),
265 # the Gtk3::TextMark is created at the end of the buffer and stored in this IV
266 # An artificial newline character is then added to the end of the buffer, and the
267 # system message is shown after that. The next call to $self->insertText or
268 # ->insertCmd when $self->insertMark is set to 'undef' (meaning, the usual insertion
269 # point is at the end of the buffer) uses this iter as its insertion point. When the
270 # next newline character is shown, this IV is set back to 'undef', and the next call
271 # to $self->insertText/->insertCmd uses the end of the buffer as its insertion point
272 # again (showing new text after the system message)
273 tempInsertMark => undef,
274 # $self->showError, ->showWarning, ->showDebug and ->showImproper always show text on
275 # separate lines and newline characters are automatically inserted after the system
276 # message. However, calls to ->showSystemText only insert a newline character by
277 # default; code can call ->showSystemText several times, to display a system message
278 # with different tags (for example, to show a system message containing a link), in
279 # the expectation that the final call will specify a newline character
280 # This IV is set by $self->showSystemText (only) when a system message is displayed
281 # without a newline character, storing the mark at the end of the system message, that
282 # being the insertion point for the next call to $self->showSystemText
283 # It is reset when $self->showSystemText displays a system message with a newline
284 # character, or when $self->showError, ->showWarning, ->showDebug or ->showImproper
285 # show a system message
286 systemInsertMark => undef,
287 # When a system message without a newline character is displayed, it is also stored
288 # here, appended to any previous portions of the same line. When a system message with
289 # a newline character is displayed, it is appended to the contents of this IV (if
290 # any), the whole line is written to logs, and the IV is set back to 'undef'
291 systemTextBuffer => undef,
292  
293 # If a visible cursor is used, we have to implement it ourselves (a Gtk cursor is only
294 # visible when the textview has the focus, which is never)
295 # Flag set to TRUE if a visible cursor is enabled, FALSE if it's disabled
296 cursorEnableFlag => FALSE,
297 # Flag set to TRUE if the visible cursor is enabled and 'on', and set to FALSE if the
298 # visible cursor is either disabled or 'off'
299 cursorOnFlag => FALSE,
300 # A visible cursor is implemented by creating a single Gtk3::TextTag and turning its
301 # underline on/off (i.e. from ->spinClientLoop)
302 # Only one of these text tags exist; to move the visible cursor's position, we just
303 # remove the old tag and insert a new one
304 # This Gtk3::TextMark stores the position at which the visible cursor has been placed
305 # (i.e. the position at which the Gtk3::TextTag has been inserted)
306 cursorMark => undef,
307 # If the visible cursor is at the end of the buffer, we have to add an extra space
308 # character, at that point, so the cursor is visible. The space character is
309 # destroyed before any text is inserted, and a new space character inserted afterwards
310 # Flag set to TRUE if the visible cursor is at the end of the buffer, FALSE otherwise
311 cursorEndFlag => FALSE,
312 # The ANSI control sequences 'Save Cursor Position' and 'Restore Cursor Position'
313 # require us to store and later retrieve a cursor position. Store the position as
314 # (y, x), rather than using a Gtk mark or iter
315 # In case anything calls $self->restoreInsertPosn before calling ->storeInsertPosn, use
316 # a default position of the top-left corner
317 storePosnYPos => 0,
318 storePosnXPos => 0,
319  
320 # A hash of current GA::Obj::Link objects
321 # Links objects can be added to the hash as soon as they are detected or (as is the case
322 # for MXP links) when the whole link has been processed
323 # The link object is removed from the hash if the link expires (as is the case for some
324 # MXP links)
325 # Hash in the form
326 # $linkObjHash{unique_number} = blessed_reference_of_link_object
327 # ...where 'unique_number' is a number unique within this textview object
328 linkObjHash => {},
329 # A parallel hash of GA::Obj::Link objects, sorted by the Gtk3::TextBuffer line on
330 # which they appear (so that when the buffer is full and the earliest line is removed,
331 # any links on that line can also be removed)
332 # Hash in the form
333 # $linkObjLineHash{line_num} = reference_to_list_of_link_objects
334 # ... where 'reference_to_list_of_link_objects' is a list of GA::Obj::Link objects
335 # appearing on 'line_num', in order from left to right
336 linkObjLineHash => {},
337 # Number of link objects objects ever created for this textview object (used to give
338 # each link object a unique number)
339 linkObjCount => 0,
340 # If the mouse is hovering over a clickable link, the corresponding GA::Obj::Link (set
341 # to 'undef' when the mouse isn't hovering over a clickable link)
342 currentLinkObj => undef,
343 # Flag set to TRUE if links are allowed at all in this textview object, FALSE if they're
344 # not allowed (in which case, any 'link' tags are ignored)
345 allowLinkFlag => TRUE,
346  
347 # A hash of buffer lines created by the GA::Session when this textview object is the
348 # session's default textview, so we can display an appropriate tooltip for lines of
349 # text received from the world (but not system messages, nor in textview objects that
350 # are not a session's default textview)
351 # The tooltip is in the form 'Line 11, 09:17:12, Thu Dec 18, 2010', where the line
352 # number is the number of the corresponding display buffer object
353 # (GA::Buffer::Display)
354 # Hash in the form
355 # $tooltipHash{our_line_num} = tooltip_text
356 # ...where 'our_line_num' is the Gtk3::TextBuffer line number of the insert position
357 # used
358 tooltipHash => {},
359 # The 'our_line_num' for the last tooltip displayed, so when the mouse moves over a new
360 # line, we can make the tooltip 'follow' it. Set to 'undef' when no tooltip is
361 # displayed
362 lastTooltipLine => undef,
363  
364 # $self->showError, ->showWarning etc usually call GA::Client->playSound to play the
365 # 'error' sound effect (nothing happens during the call if sound is turned off or if
366 # the effect is not available)
367 # However, several system messages occuring one after the other might cause a cacophony
368 # of noise, so ->showError, ->showWarning etc don't make multiple calls to
369 # ->playSound within a certain period of time
370 # When ->showError, ->showWarning etc call ->playSound, this IV is set to the time at
371 # which the next call to ->playSound is allowed
372 # NB Any other part of the Axmud code can play the 'error' sound effect, any time it
373 # wants
374 # How many seconds to wait between calls to ->playSound
375 soundDelayTime => 10,
376 # The time (matches GA::Client->clientTime) at which the next call to ->playSound is
377 # allowed ('undef' if calls to ->playSound are allowed now)
378 soundCheckTime => undef,
379  
380 # 'Set Graphics Mode' ANSI escape sequences in text received from the world applies
381 # until the next occurence of that sequence. Each GA::Session needs to keep track
382 # of which graphic modes apply right now in the session's current textview object
383 # (For protocols like MXP which use multiple frames, which Axmud implementes as multiple
384 # pane objects, we assume that ANSI escape sequences only apply in the current pane)
385 # Hash of graphics modes which currently apply in this textview object, in the same
386 # form as GA::Client->constColourStyleHash:
387 #
388 # %colourStyleHash = (
389 # # Colour tags - when set to 'undef', the default colours are used. Standard or
390 # # xterm colour tags, but not RGB colour tags (because ANSI escape sequences
391 # # don't use them, and because unlike standard/xterm colour, Gtk3::TextTags
392 # # for RGB colours are not created until needed)
393 # text => undef, # Axmud colour tag, e.g. 'red' or 'x230'
394 # underlay => undef, # Axmud underlay colour tag, e.g. 'ul_white'
395 # # Style tags
396 # italics => FALSE,
397 # underline => FALSE,
398 # blink_slow => FALSE,
399 # blink_fast => FALSE,
400 # strike => FALSE,
401 # link => FALSE,
402 # # MXP font tags (which are dummy style tags)
403 # mxp_font => undef, # A string like 'mxpf_monospace_bold_12'
404 # # Justification
405 # justify => 'left', 'right', 'centre' or 'undef' to represent the
406 # style tag 'justify_default'
407 # );
408 #
409 colourStyleHash => {%colourStyleHash},
410 # Hash of graphics modes which applied at the end of the previous line, in the same
411 # form as $self->colourStyleHash
412 # Set by $self->insertText after every newline character (and also by
413 # $self->clearBuffer), but not by calls to ->showSystemText, etc)
414 prevColourStyleHash => {%colourStyleHash},
415  
416 # List of MXP open modal tags forming a stack. When an opening tag like <FONT> is found,
417 # it's 'pushed' to the stack. When the matching </FONT> tag is found, every tag from
418 # the top of the stack is 'popped' until we find the matching <FONT> tag
419 # This allows for nested font and colour changes. It works well if the world uses only
420 # MXP colours or only ANSI escape sequence colours; not so well if it tries to
421 # combine them - because GA::Session->parseMxpElement is called to process the MXP
422 # tags, but it doesn't know the actual text attributes being used, because they're not
423 # set until the later call to $self->applyColourStyleTags
424 # Every item in the list is a GA::Mxp::StackObj object
425 mxpModalStackList => [],
426 # Hash of current MXP text attributes, modified whenever a GA::Mxp::StackObj object is
427 # pushed to/popped from the stack
428 mxpModalStackHash => {
429 'bold_flag' => FALSE,
430 'italics_flag' => FALSE,
431 'underline_flag' => FALSE,
432 'strike_flag' => FALSE,
433 'colour_foreground' => '', # Use '' rather than 'undef' so we can use 'eq'
434 'colour_background' => '',
435 'high_flag' => FALSE, # NB <HIGH> is implemented the same way as <B>
436 'font_name' => '',
437 'font_size' => '',
438 # 'font_foreground' => '', # Font colours stored in 'colour_xxx'
439 # 'font_background' => '',
440 'blink_flag' => FALSE,
441 'spacing' => 0, # Used only with HTML elements like <H1>, <HR>
442 },
443 };
444  
445 # Bless the object into existence
446 bless $self, $class;
447  
448 return $self;
449 }
450  
451 ##################
452 # Methods
453  
454 sub objEnable {
455  
456 # Called by anything after the call to $self->new
457 # Creates the Gtk3::TextView itself, packed into a Gtk3::ScrolledWindow (the scrolled window
458 # is returned)
459 #
460 # Expected arguments
461 # (none besides $self)
462 #
463 # Optional arguments
464 # $splitScreenMode
465 # - Sets the textview object's initial split screen mode - 'single' for a
466 # single Gtk3::TextView, 'split' for two Gtk3::TextViews with a
467 # divider between them, positioned so they are both visible, or
468 # 'hidden' for two Gtk3::Textviews with a divider between them,
469 # positioned at the top of the screen so the second textview is
470 # invisible (and the divider itself is almost invisible). If 'undef'
471 # or an unrecognised value, the default value of 'single' is used
472 # $colourScheme - The name of the GA::Obj::ColourScheme to use (matches a key in
473 # GA::CLIENT->colourSchemeHash). If 'undef', the default colour
474 # scheme for the parent window type is used
475 # $maxLines - The maximum number of lines that can be shown in the Gtk3::TextView
476 # (when the limit is reached, the earliest line is removed when a
477 # new line is added)
478 # $newLineDefault - The default behaviour when a string is inserted into the
479 # Gtk3::TextView: 'before' prepends a newline character to the string,
480 # 'after'/'nl' prepends a newline character after the string, 'echo'
481 # does not prepend/a newline character by default. If 'undef' or an
482 # unrecognised value, 'after' is used
483 # $oldBuffer - If we want the new Gtk3::TextView to use an existing Gtk3::TextBuffer
484 # any reason, that buffer; set to 'undef' otherwise
485 #
486 # Return values
487 # 'undef' on improper arguments
488 # Otherwise returns the Gtk3::ScrolledWindow
489  
490 my (
491 $self, $splitScreenMode, $colourScheme, $maxLines, $newLineDefault, $oldBuffer, $check
492 ) = @_;
493  
494 # Local variables
495 my ($colourSchemeObj, $bufferClass);
496  
497 # Check for improper arguments
498 if (defined $check) {
499  
500 return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
501 }
502  
503 # Apply split screen mode, using a default value if no recognised value was specified
504 if (
505 defined $splitScreenMode
506 && (
507 $splitScreenMode eq 'single' || $splitScreenMode eq 'split'
508 || $splitScreenMode eq 'hidden'
509 )
510 ) {
511 $self->ivPoke('splitScreenMode', $splitScreenMode);
512 }
513  
514 # Apply the colour scheme, using a default one if none was specified
515 if (! $colourScheme || ! $axmud::CLIENT->ivShow('colourSchemeHash', $colourScheme)) {
516  
517 $colourScheme = $self->winObj->winType;
518 }
519  
520 $colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $colourScheme);
521  
522 $self->ivPoke('colourScheme', $colourSchemeObj->name);
523 $self->ivPoke('textColour', $colourSchemeObj->textColour);
524 $self->ivPoke('underlayColour', $colourSchemeObj->underlayColour);
525 $self->ivPoke('backgroundColour', $colourSchemeObj->backgroundColour);
526 $self->ivPoke('font', $colourSchemeObj->font);
527 $self->ivPoke('fontSize', $colourSchemeObj->fontSize);
528  
529 # Apply the maximum number of lines, if specified; otherwise keep using the default value
530 if (defined $maxLines) {
531  
532 $self->ivPoke('maxLines', $maxLines);
533 }
534  
535 # Apply the default newline behaviour, if specified, otherwise keep using the default value
536 if (
537 defined $newLineDefault
538 && (
539 $newLineDefault eq 'before'
540 || $newLineDefault eq 'after'
541 || $newLineDefault eq 'nl'
542 || $newLineDefault eq 'echo'
543 )
544 ) {
545 $self->ivPoke('newLineDefault', $newLineDefault);
546 }
547  
548 # If $oldBuffer wasn't specified, create a new Gtk3::TextBuffer
549 if (! $oldBuffer) {
550  
551 $self->ivPoke('buffer', Gtk3::TextBuffer->new());
552  
553 # Create colour/style tags for the new textbuffer
554 $self->createColourTags();
555 $self->createStyleTags();
556  
557 } else {
558  
559 $self->ivPoke('buffer', $oldBuffer);
560 }
561  
562 # Create the Gtk3::TextView(s)
563 my ($scroll, $scroll2, $vPaned, $textView, $textView2);
564 $textView = $self->createTextViewWidget($self->buffer, $colourSchemeObj);
565 if ($self->splitScreenMode eq 'single') {
566  
567 # Pack the textview into a container widget
568 $scroll = $self->setupScroller($textView);
569  
570 } else {
571  
572 $textView2 = $self->createTextViewWidget($self->buffer, $colourSchemeObj);
573  
574 # Pack the textviews into a container widget
575 ($vPaned, $scroll, $scroll2) = $self->setupVPaned($textView, $textView2);
576 }
577  
578 # Set the textview's CSS style
579 $axmud::CLIENT->desktopObj->setTextViewObjStyle(
580 $self->number,
581 $axmud::CLIENT->returnRGBColour($self->textColour),
582 $axmud::CLIENT->returnRGBColour($self->backgroundColour),
583 $self->font,
584 $self->fontSize,
585 $textView,
586 $textView2,
587 );
588  
589 # Update IVs
590 $self->ivPoke('textView', $textView);
591 $self->ivPoke('textView2', $textView2);
592 $self->ivPoke('vPaned', $vPaned);
593 $self->ivPoke('scroll', $scroll);
594 $self->ivPoke('scroll2', $scroll2);
595 $self->ivPoke('sizeUpdateFlag', TRUE);
596  
597 # Create a mark at the end of the buffer, with right gravity, so that whenever text is
598 # inserted, we can scroll to that mark (and the mark stays at the end)
599 # Also create a mark at the beginning of the buffer, with left gravity, for scrolling to the
600 # top
601 my $startMark
602 = $self->buffer->create_mark('start_mark', $self->buffer->get_start_iter(), TRUE);
603 my $endMark
604 = $self->buffer->create_mark('end_mark', $self->buffer->get_end_iter(), FALSE);
605 # ($self->insertNewLine creates a 'line_N' mark after every newline character, but not at
606 # the beginning of the Gtk3::TextBuffer)
607 $self->buffer->create_mark('line_0', $self->buffer->get_start_iter(), TRUE);
608  
609 # Create a search mark which moves whenever $self->searchBuffer is called, and is initially
610 # at the beginning of the buffer
611 my $searchMark
612 = $self->buffer->create_mark('search_mark', $self->buffer->get_start_iter(), TRUE);
613  
614 # Update IVs again
615 $self->ivPoke('startMark', $startMark);
616 $self->ivPoke('endMark', $endMark);
617 $self->ivPoke('searchMark', $searchMark);
618  
619 # Gtk3::TextTags might not exist for any RGB tags that have just been copied to
620 # $self->textColour and/or $self->underlayColour, and $self->interpretTags won't have the
621 # opportunity to create them, so create them right away
622 $self->updateRGBTags();
623  
624 if ($self->splitScreenMode eq 'single') {
625 return $scroll;
626 } else {
627 return $vPaned;
628 }
629 }
630  
631 sub objDestroy {
632  
633 # Called by GA::Table::Pane->objDestroy, ->removeSessionTab and ->removeTab
634 #
635 # Expected arguments
636 # (none besides $self)
637 #
638 # Return values
639 # 'undef' on improper arguments
640 # 1 otherwise
641  
642 my ($self, $check) = @_;
643  
644 # Check for improper arguments
645 if (defined $check) {
646  
647 return $axmud::CLIENT->writeImproper($self->_objClass . '->objUpdate', @_);
648 }
649  
650 # Update the GA::Obj::Desktop registry
651 $axmud::CLIENT->desktopObj->del_textView($self);
652  
653 return 1;
654 }
655  
656 sub objUpdate {
657  
658 # Called by GA::Table::Pane->applyColourScheme or ->updateColourScheme (must not be called
659 # directly)
660 # Also called by $self->setMonochromeMode and ->resetMonochromeMode when a monochrome colour
661 # scheme is applied/removed
662 #
663 # Applies a colour scheme to this object's Gtk3::TextView(s)
664 #
665 # Expected arguments
666 # (none besides $self)
667 #
668 # Optional arguments
669 # $colourScheme
670 # - The new colour scheme to use (matches a key in GA::Client->colourSchemeHash).
671 # 'undef' when called by $self->applyMonochrome, in which the colours already
672 # stored in $self->textColour, ->underlayColour and ->backgroundColour are used
673 #
674 # Return values
675 # 'undef' on improper arguments or if the specified colour scheme doesn't exist
676 # 1 otherwise
677  
678 my ($self, $colourScheme, $check) = @_;
679  
680 # Local variables
681 my (
682 $colourSchemeObj, $backgroundColour, $textColour,
683 @list,
684 );
685  
686 # Check for improper arguments
687 if (defined $check) {
688  
689 return $axmud::CLIENT->writeImproper($self->_objClass . '->objUpdate', @_);
690 }
691  
692 # Get the colour scheme object (the calling function has already checked it exists)
693 if ($colourScheme) {
694  
695 $colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $colourScheme);
696 if (! $colourSchemeObj) {
697  
698 return undef;
699  
700 } else {
701  
702 # Make sure the colour scheme's colour/font values are acceptable, to avoid getting
703 # nasty Gtk errors
704 $colourSchemeObj->repair();
705  
706 # Update IVs. When the colour scheme is updated, the scheme's colours aren't applied
707 # in monochrome mode with modified colours (because some code, usually a task,
708 # specifically requested those colours)
709 $self->ivPoke('colourScheme', $colourSchemeObj->name);
710  
711 if (! $self->monochromeFlag) {
712  
713 $self->ivPoke('textColour', $colourSchemeObj->textColour);
714 $self->ivPoke('underlayColour', $colourSchemeObj->underlayColour);
715 $self->ivPoke('backgroundColour', $colourSchemeObj->backgroundColour);
716  
717 } elsif (! $self->monochromeModFlag) {
718  
719 $backgroundColour = $colourSchemeObj->backgroundColour;
720  
721 if ($axmud::CLIENT->ivExists('constMonochromeHash', $backgroundColour)) {
722  
723 # Choose a text colour to match the background colour in the standard way,
724 # ignoring the text colour specified by the colour scheme
725 $textColour = $axmud::CLIENT->ivShow(
726 'constMonochromeHash',
727 $backgroundColour,
728 );
729  
730 } else {
731  
732 # Non-standard background colour tag, in which case use the colour specified
733 # by the colour scheme itself, rather than choosing a matching colour
734 # (It's up to the person who edits the colour scheme to choose a suitable
735 # colour)
736 $textColour = $colourSchemeObj->textColour;
737 }
738  
739 # In monochrome mode, the underlay colour is always the same as the background
740 $self->ivPoke('textColour', $textColour);
741 $self->ivPoke('underlayColour', undef);
742 $self->ivPoke('backgroundColour', $backgroundColour);
743 }
744  
745 # The fonts are applied in all situations
746 $self->ivPoke('font', $colourSchemeObj->font);
747 $self->ivPoke('fontSize', $colourSchemeObj->fontSize);
748 }
749 }
750  
751 # Update the textview's CSS style
752 $axmud::CLIENT->desktopObj->setTextViewObjStyle(
753 $self->number,
754 $self->textColour,
755 $self->backgroundColour,
756 $self->font,
757 $self->fontSize,
758 $self->textView,
759 $self->textView2, # May be 'undef'
760 );
761  
762 # Gtk3::TextTags might not exist for any RGB tags that have just been copied to
763 # $self->textColour and/or $self->underlayColour, and $self->interpretTags won't have the
764 # opportunity to create them, so create them right away
765 $self->updateRGBTags();
766  
767 # Create any new Gtk3::TextTags that don't already exist, using a phoney call to
768 # $self->interpretTags
769 # NB Default values for these IVs are 'undef', so we have to check for that
770 if ($self->textColour) {
771  
772 push (@list, $self->textColour);
773 }
774  
775 if ($self->underlayColour) {
776  
777 push (@list, $self->underlayColour);
778 }
779  
780 if ($self->backgroundColour) {
781  
782 push (@list, $self->backgroundColour);
783 }
784  
785 if (@list) {
786  
787 $self->interpretTags($self->newLineDefault, @list);
788 }
789  
790 # Operation complete
791 return 1;
792 }
793  
794 # ->signal_connects
795  
796 sub setMotionNotifyEvent {
797  
798 # Called by $self->createTextViewWidget
799 # Set up a ->signal_connect to watch out for the motion over clickable links
800 #
801 # Expected arguments
802 # $textView - The Gtk3::TextView that generated the signal (later stored in either
803 # $self->textView or $self->textView2)
804 #
805 # Return values
806 # 'undef' on improper arguments
807 # 1 otherwise
808  
809 my ($self, $textView, $check) = @_;
810  
811 # Check for improper arguments
812 if (! defined $textView || defined $check) {
813  
814 return $axmud::CLIENT->writeImproper($self->_objClass . '->setMotionNotifyEvent', @_);
815 }
816  
817 $textView->signal_connect('motion-notify-event' => sub {
818  
819 $self->checkMousePosn(@_);
820  
821 # Return 'undef' to show that we haven't interfered with the widget
822 return undef;
823 });
824  
825 return 1;
826 }
827  
828 sub setLeaveNotifyEvent {
829  
830 # Called by $self->createTextViewWidget
831 # Set up a ->signal_connect to watch out for the motion over clickable links
832 #
833 # Expected arguments
834 # $textView - The Gtk3::TextView that generated the signal (later stored in either
835 # $self->textView or $self->textView2)
836 #
837 # Return values
838 # 'undef' on improper arguments
839 # 1 otherwise
840  
841 my ($self, $textView, $check) = @_;
842  
843 # Check for improper arguments
844 if (! defined $textView || defined $check) {
845  
846 return $axmud::CLIENT->writeImproper($self->_objClass . '->setLeaveNotifyEvent', @_);
847 }
848  
849 $textView->signal_connect('leave-notify-event' => sub {
850  
851 my ($widget, $event) = @_;
852  
853 $self->hideTooltips();
854  
855 # Return 'undef' to show that we haven't interfered with the widget
856 return undef;
857 });
858  
859 return 1;
860 }
861  
862 sub setFocusOutEvent {
863  
864 # Called by $self->createTextViewWidget
865 # Set up a ->signal_connect to watch out for the motion over clickable links
866 #
867 # Expected arguments
868 # $textView - The Gtk3::TextView that generated the signal (later stored in either
869 # $self->textView or $self->textView2)
870 #
871 # Return values
872 # 'undef' on improper arguments
873 # 1 otherwise
874  
875 my ($self, $textView, $check) = @_;
876  
877 # Check for improper arguments
878 if (! defined $textView || defined $check) {
879  
880 return $axmud::CLIENT->writeImproper($self->_objClass . '->setFocusOutEvent', @_);
881 }
882  
883 $textView->signal_connect('focus-out-event' => sub {
884  
885 my ($widget, $event) = @_;
886  
887 $self->hideTooltips();
888  
889 # Return 'undef' to show that we haven't interfered with the widget
890 return undef;
891 });
892  
893 return 1;
894 }
895  
896 sub setButtonPressEvent {
897  
898 # Called by $self->createTextViewWidget
899 # Set up a ->signal_connect to watch out for mouse clicks on a clickable link
900 #
901 # Expected arguments
902 # $textView - The Gtk3::TextView that generated the signal (later stored in either
903 # $self->textView or $self->textView2)
904 #
905 # Return values
906 # 'undef' on improper arguments
907 # 1 otherwise
908  
909 my ($self, $textView, $check) = @_;
910  
911 # Check for improper arguments
912 if (! defined $textView || defined $check) {
913  
914 return $axmud::CLIENT->writeImproper($self->_objClass . '->setButtonPressEvent', @_);
915 }
916  
917 $textView->signal_connect('button-press-event' => sub {
918  
919 my ($widget, $event) = @_;
920  
921 # Local vars
922 my ($result, $host, $port, $stripObj);
923  
924 # Any mouse click hides tooltips
925 $self->hideTooltips();
926  
927 # If the mouse is currently above a clickable link, $self->currentLinkObj will be
928 # defined
929 if ($event->type eq 'button-press' && defined $self->currentLinkObj) {
930  
931 # Left button
932 if ($event->button == 1) {
933  
934 if ($self->currentLinkObj->type eq 'www') {
935  
936 $result = $axmud::CLIENT->openURL($self->currentLinkObj->href);
937  
938 } elsif ($self->currentLinkObj->type eq 'mail') {
939  
940 $result = $axmud::CLIENT->openEmail($self->currentLinkObj->href);
941  
942 } elsif ($self->currentLinkObj->type eq 'telnet') {
943  
944 # The link should be in the form telnet://deathmud.org:6666 or
945 # telnet://deathmud.org
946 # Separate that into a host and a port
947 if ($self->currentLinkObj->href =~ m/^telnet\:\/\/([^\:\s]+)(\:(\d+))?/) {
948  
949 $host = $1;
950 $port = $3; # May be 'undef';
951  
952 if ($host && $port) {
953  
954 $result
955 = $self->session->pseudoCmd('telnet ' . $host . ' ' . $port);
956  
957 } else {
958  
959 $result = $self->session->pseudoCmd('telnet ' . $host);
960 }
961 }
962  
963 } elsif ($self->currentLinkObj->type eq 'ssh') {
964  
965 # The link should be in the form ssh://deathmud.org:6666 or
966 # ssh://deathmud.org
967 # Separate that into a host and a port
968 if ($self->currentLinkObj->href =~ m/^ssh\:\/\/([^\:\s]+)(\:(\d+))?/) {
969  
970 $host = $1;
971 $port = $3; # May be 'undef';
972  
973 if ($host && $port) {
974 $result = $self->session->pseudoCmd('ssh ' . $host . ' ' . $port);
975 } else {
976 $result = $self->session->pseudoCmd('ssh ' . $host);
977 }
978 }
979  
980 } elsif ($self->currentLinkObj->type eq 'ssl') {
981  
982 # The link should be in the form ssl://deathmud.org:6666 or
983 # ssl://deathmud.org
984 # Separate that into a host and a port
985 if ($self->currentLinkObj->href =~ m/^ssl\:\/\/([^\:\s]+)(\:(\d+))?/) {
986  
987 $host = $1;
988 $port = $3; # May be 'undef';
989  
990 if ($host && $port) {
991 $result = $self->session->pseudoCmd('ssl ' . $host . ' ' . $port);
992 } else {
993 $result = $self->session->pseudoCmd('ssl ' . $host);
994 }
995 }
996  
997 } elsif ($self->currentLinkObj->type eq 'cmd') {
998  
999 if ($self->currentLinkObj->mxpPromptFlag) {
1000  
1001 # Instead of sending a world command, copy the world command into the
1002 # 'main' window's entry box
1003 $stripObj = $self->paneObj->winObj->getStrip('entry');
1004 if ($stripObj) {
1005  
1006 $result = $stripObj->commandeerEntry(
1007 $self->session,
1008 $self->currentLinkObj->href,
1009 );
1010 }
1011  
1012 } elsif ($self->currentLinkObj->popupCmdList) {
1013  
1014 $result = $self->session->worldCmd(
1015 $self->currentLinkObj->ivFirst('popupCmdList'),
1016 );
1017  
1018 } elsif ($self->currentLinkObj->href) {
1019  
1020 $result = $self->session->worldCmd($self->currentLinkObj->href);
1021  
1022 } else {
1023  
1024 $result = $self->session->worldCmd($self->currentLinkObj->text);
1025 }
1026 }
1027  
1028 # Right button
1029 } elsif ($event->button == 3) {
1030  
1031 if ($self->currentLinkObj->type eq 'cmd' && $self->currentLinkObj->popupFlag) {
1032  
1033 # Create a popup menu, and send a world command if the user clicks on a menu
1034 # item
1035 $result = $self->createPopupMenu($event);
1036 }
1037 }
1038  
1039 # Clicking on a link resets the cursor
1040 $self->ivUndef('currentLinkObj');
1041 $textView->get_window('text')->set_cursor($axmud::CLIENT->constNormalCursor);
1042 return $result;
1043 }
1044  
1045 # Otherwise return 'undef' to show that we haven't interfered with the widget
1046 return undef;
1047 });
1048  
1049 return 1;
1050 }
1051  
1052 sub setTextViewScrollEvent {
1053  
1054 # Called by $self->enableSplitScreen and ->enableHiddenSplitScreen, as well as by
1055 # GA::Table::Pane->addSimpleTab and ->addTab
1056 # Set up a ->signal_connect to watch out for scrolling in the Gtk3::ScrolledWindow which
1057 # contains a textview
1058 #
1059 # Expected arguments
1060 # $scroll - The Gtk3::ScrolledWindow that generated the signal
1061 # $textView - The Gtk3::TextView it contains
1062 #
1063 # Return values
1064 # 'undef' on improper arguments
1065 # 1 otherwise
1066  
1067 my ($self, $scroll, $textView, $check) = @_;
1068  
1069 # Check for improper arguments
1070 if (! defined $scroll || ! defined $textView || defined $check) {
1071  
1072 return $axmud::CLIENT->writeImproper(
1073 $self->_objClass . '->setTextViewScrollEvent',
1074 @_,
1075 );
1076 }
1077  
1078 # Detect scrolling, so we can reset the cursor (so the user can't move the cursor above a
1079 # link, wait until the link scrolls away, and then still click the link)
1080 my $adjust = $scroll->get_vadjustment();
1081 $adjust->signal_connect('value-changed' => sub {
1082  
1083 my $window = $textView->get_window('text');
1084  
1085 if ($self->currentLinkObj) {
1086  
1087 $self->ivUndef('currentLinkObj');
1088 $window->set_cursor($axmud::CLIENT->constNormalCursor);
1089 }
1090  
1091 # (Any scrolling in the window hides tooltips)
1092 $self->hideTooltips();
1093  
1094 # Without this line, changes to the visible textview size, caused by the addition/
1095 # removal of a scrollbar, are applied quickly enough
1096 $self->ivPoke('sizeUpdateFlag', TRUE);
1097 });
1098  
1099 return 1;
1100 }
1101  
1102 # Other functions - called by anything
1103  
1104 sub scrollToTop {
1105  
1106 # Can be called by anything
1107 # Scrolls the textview to the top
1108 #
1109 # Expected arguments
1110 # (none besides $self)
1111 #
1112 # Optional arguments
1113 # $flag - If set to TRUE, the second textview (created in split screen mode) is
1114 # scrolled, if it exists. Otherwise, the original textview is scrolled
1115 #
1116 # Return values
1117 # 'undef' on improper arguments
1118 # 1 otherwise
1119  
1120 my ($self, $flag, $check) = @_;
1121  
1122 # Local variables
1123 my $textView;
1124  
1125 # Check for improper arguments
1126 if (defined $check) {
1127  
1128 return $axmud::CLIENT->writeImproper($self->_objClass . '->scrollToTop', @_);
1129 }
1130  
1131 if ($flag && $self->textView2 && $self->splitScreenMode eq 'split') {
1132 $textView = $self->textView2;
1133 } elsif ($self->textView) {
1134 $textView = $self->textView;
1135 }
1136  
1137 if ($textView) {
1138  
1139 # Apply the nice visual effect...
1140 $textView->scroll_to_mark($self->buffer->get_mark('start_mark'), 0.0, TRUE, 0, 0);
1141  
1142 # ...and instruct the GA::Session to make sure, on the next spin of its maintain loop,
1143 # that the textview really is scrolled to the top
1144 $self->session->add_textViewScrollUp($textView);
1145 }
1146  
1147 return 1;
1148 }
1149  
1150 sub scrollToBottom {
1151  
1152 # Can be called by anything
1153 # Scrolls the textview to the bottom
1154 #
1155 # Expected arguments
1156 # (none besides $self)
1157 #
1158 # Optional arguments
1159 # $flag - If set to TRUE, the second textview (created in split screen mode) is
1160 # scrolled, if it exists. Otherwise, the original textview is scrolled
1161 #
1162 # Return values
1163 # 'undef' on improper arguments
1164 # 1 otherwise
1165  
1166 my ($self, $flag, $check) = @_;
1167  
1168 # Local variables
1169 my $textView;
1170  
1171 # Check for improper arguments
1172 if (defined $check) {
1173  
1174 return $axmud::CLIENT->writeImproper($self->_objClass . '->scrollToBottom', @_);
1175 }
1176  
1177 if ($flag && $self->textView2 && $self->splitScreenMode eq 'split') {
1178 $textView = $self->textView2;
1179 } elsif ($self->textView) {
1180 $textView = $self->textView;
1181 }
1182  
1183 if ($textView) {
1184  
1185 # Apply the nice visual effect...
1186 $textView->scroll_to_mark($self->buffer->get_mark('end_mark'), 0.0, TRUE, 0, 1);
1187  
1188 # ...and instruct the GA::Session to make sure, on the next spin of its maintain loop,
1189 # that the textview really is scrolled to the bottom
1190 $self->session->add_textViewScrollDown($textView);
1191 }
1192  
1193 return 1;
1194 }
1195  
1196 sub scrollToIter {
1197  
1198 # Can be called by anything
1199 # Scrolls the (original) textview to a specified Gtk3::TextIter (if split screen mode
1200 # applies, the upper textview doesn't scroll)
1201 #
1202 # Expected arguments
1203 # $iter - Scroll to this Gtk3::TextIter
1204 #
1205 # Optional arguments
1206 # $flag - If set to TRUE, the second textview (created in split screen mode) is
1207 # scrolled, if it exists. Otherwise, the original textview is scrolled
1208 #
1209 # Return values
1210 # 'undef' on improper arguments
1211 # 1 otherwise
1212  
1213 my ($self, $iter, $flag, $check) = @_;
1214  
1215 # Check for improper arguments
1216 if (! defined $iter || defined $check) {
1217  
1218 return $axmud::CLIENT->writeImproper($self->_objClass . '->scrollToIter', @_);
1219 }
1220  
1221 if ($flag && $self->textView2 && $self->splitScreenMode eq 'split') {
1222 $self->textView2->scroll_to_iter($iter, 0.0, TRUE, 0, 1);
1223 } elsif ($self->textView) {
1224 $self->textView->scroll_to_iter($iter, 0.0, TRUE, 0, 1);
1225 }
1226  
1227 $self->winObj->winShowAll($self->_objClass . '->scrollToIter');
1228  
1229 return 1;
1230 }
1231  
1232 sub scrollToMark {
1233  
1234 # Can be called by anything
1235 # Scrolls the (original) textview to a specified Gtk3::TextMark (if split screen mode
1236 # applies, the upper textview doesn't scroll)
1237 #
1238 # Expected arguments
1239 # $mark - Scroll to this Gtk3::TextMark
1240 #
1241 # Optional arguments
1242 # $flag - If set to TRUE, the second textview (created in split screen mode) is
1243 # scrolled, if it exists. Otherwise, the original textview is scrolled
1244 #
1245 # Return values
1246 # 'undef' on improper arguments
1247 # 1 otherwise
1248  
1249 my ($self, $mark, $flag, $check) = @_;
1250  
1251 # Check for improper arguments
1252 if (! defined $mark || defined $check) {
1253  
1254 return $axmud::CLIENT->writeImproper($self->_objClass . '->scrollToMark', @_);
1255 }
1256  
1257 if ($flag && $self->textView2 && $self->splitScreenMode eq 'split') {
1258 $self->textView2->scroll_to_mark($mark, 0.0, TRUE, 0, 1);
1259 } elsif ($self->textView) {
1260 $self->textView->scroll_to_mark($mark, 0.0, TRUE, 0, 1);
1261 }
1262  
1263 $self->winObj->winShowAll($self->_objClass . '->scrollToMark');
1264  
1265 return 1;
1266 }
1267  
1268 sub scrollToLock {
1269  
1270 # Can be called by anything
1271 # Convenience function for scrolling both textviews (or the single textview, if there is
1272 # only one) to their 'locked' position
1273 #
1274 # Expected arguments
1275 # (none besides $self)
1276 #
1277 # Return values
1278 # 'undef' on improper arguments
1279 # 1 otherwise
1280  
1281 my ($self, $check) = @_;
1282  
1283 # Check for improper arguments
1284 if (defined $check) {
1285  
1286 return $axmud::CLIENT->writeImproper($self->_objClass . '->scrollToLock', @_);
1287 }
1288  
1289 # Scroll to the end of the buffer in each textview
1290 if ($self->scrollLockType eq 'top') {
1291  
1292 $self->scrollToTop();
1293 $self->scrollToTop(TRUE);
1294  
1295 } else {
1296  
1297 $self->scrollToBottom();
1298 $self->scrollToBottom(TRUE);
1299 }
1300  
1301 return 1;
1302 }
1303  
1304 sub clearBuffer {
1305  
1306 # Can be called by anything (also called by $self->insertText, ->insertQuick,
1307 # ->showSystemText and ->showImage)
1308 # Empties the Gtk3::TextBuffer of text
1309 #
1310 # Expected arguments
1311 # (none besides $self)
1312 #
1313 # Optional arguments
1314 # $overwriteFlag - If TRUE, overwite mode is turned on (if not already on). If FALSE or
1315 # 'undef', no change to overwrite mode is made
1316 # $noCursorFlag - If TRUE, don't call ->removeCursor or ->moveCursor, because the
1317 # calling function wants to handle visible cursors. If FALSE or
1318 # 'undef', ->removeCursor and ->moveCursor are called as normal
1319 #
1320 # Return values
1321 # 'undef' on improper arguments
1322 # 1 otherwise
1323  
1324 my ($self, $overwriteFlag, $noCursorFlag, $check) = @_;
1325  
1326 # Check for improper arguments
1327 if (defined $check) {
1328  
1329 return $axmud::CLIENT->writeImproper($self->_objClass . '->clearBuffer', @_);
1330 }
1331  
1332 # Turn on overwrite mode, if required by the calling function (and if it's not already
1333 # turned on)
1334 if ($overwriteFlag && ! $self->overwriteFlag) {
1335  
1336 $self->enableOverwrite();
1337 }
1338  
1339 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
1340 if (! $noCursorFlag) {
1341  
1342 $self->removeCursor();
1343 }
1344  
1345 # Empty the buffer
1346 $self->buffer->set_text('');
1347 # Destroy any GA::Obj::Link objects whose links are no longer visible
1348 $self->reset_link();
1349  
1350 # If the cursor is visible, move it to the end of the buffer (i.e. insert a new
1351 # Gtk3::TextTag)
1352 if (! $noCursorFlag) {
1353  
1354 $self->moveCursor();
1355 }
1356  
1357 # Update IVs
1358 $self->ivPoke('nextDeleteLine', 0);
1359 $self->ivPoke('bufferTextFlag', FALSE);
1360 $self->ivPoke('newLineFlag', TRUE);
1361 $self->ivPoke('insertNewLineFlag', TRUE);
1362 $self->ivPoke('clearAfterInsertFlag', FALSE);
1363 $self->ivUndef('insertMark');
1364 $self->ivUndef('restoreInsertMark');
1365 $self->ivUndef('tempInsertMark');
1366 $self->ivUndef('systemInsertMark');
1367 $self->ivUndef('systemTextBuffer');
1368 $self->ivPoke('cursorEnableFlag', FALSE);
1369 $self->ivPoke('cursorOnFlag', FALSE);
1370 $self->ivUndef('cursorMark');
1371 $self->ivPoke('cursorEndFlag', FALSE);
1372 $self->ivPoke('storePosnYPos', 0);
1373 $self->ivPoke('storePosnXPos', 0);
1374 $self->ivEmpty('linkObjHash');
1375 $self->ivEmpty('linkObjLineHash');
1376 $self->ivPoke('linkObjCount', 0);
1377 $self->ivUndef('currentLinkObj');
1378 $self->ivEmpty('tooltipHash');
1379 $self->ivPoke('lastTooltipLine', undef);
1380 # Reset colours/styles
1381 $self->ivPoke('colourStyleHash', $axmud::CLIENT->constColourStyleHash);
1382 $self->ivPoke('prevColourStyleHash', $axmud::CLIENT->constColourStyleHash);
1383  
1384 return 1;
1385 }
1386  
1387 sub clearBufferBeforeMark {
1388  
1389 # Can be called by anything
1390 # Empties the Gtk3::TextBuffer of text before a specified mark
1391 #
1392 # Expected arguments
1393 # $mark - The Gtk3::TextMark before which the buffer should be cleared
1394 #
1395 # Optional arguments
1396 # $overwriteFlag - If TRUE, overwite mode is turned on (if not already on). If FALSE or
1397 # 'undef', no change to overwrite mode is made
1398 #
1399 # Return values
1400 # 'undef' on improper arguments or if the text can't be emptied
1401 # 1 otherwise
1402  
1403 my ($self, $mark, $overwriteFlag, $check) = @_;
1404  
1405 # Local variables
1406 my (
1407 $stopIter, $lineNum, $posn, $startIter,
1408 %tooltipHash, %newHash,
1409 );
1410  
1411 # Check for improper arguments
1412 if (! defined $mark || defined $check) {
1413  
1414 return $axmud::CLIENT->writeImproper($self->_objClass . '->clearBufferBeforeMark', @_);
1415 }
1416  
1417 # Turn on overwrite mode, if required by the calling function (and if it's not already
1418 # turned on)
1419 if ($overwriteFlag && ! $self->overwriteFlag) {
1420  
1421 $self->enableOverwrite();
1422 }
1423  
1424 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
1425 $self->removeCursor();
1426  
1427 $stopIter = $self->buffer->get_iter_at_mark($mark);
1428 $lineNum = $stopIter->get_line();
1429 $posn = $stopIter->get_visible_line_offset();
1430 $startIter = $self->buffer->get_start_iter();
1431 if (! $startIter || ! $stopIter) {
1432  
1433 return undef;
1434 }
1435  
1436 # Empty the buffer before the specified mark
1437 $self->buffer->delete($startIter, $stopIter);
1438  
1439 # Update IVs generally
1440 $self->ivPoke('nextDeleteLine', 0);
1441  
1442 if (! $self->buffer->get_char_count()) {
1443  
1444 $self->ivPoke('bufferTextFlag', FALSE);
1445 $self->ivPoke('newLineFlag', TRUE);
1446  
1447 } else {
1448  
1449 $self->ivPoke('bufferTextFlag', TRUE);
1450 # (->newLineFlag retains its current value)
1451 }
1452  
1453 $self->ivPoke('sizeUpdateFlag', TRUE);
1454 $self->ivPoke('insertNewLineFlag', TRUE);
1455 $self->ivUndef('insertMark');
1456 $self->ivUndef('restoreInsertMark');
1457 $self->ivUndef('tempInsertMark');
1458 $self->ivUndef('systemInsertMark');
1459  
1460 if ($self->storePosnYPos < $lineNum) {
1461  
1462 $self->ivPoke('storePosnYPos', 0);
1463 $self->ivPoke('storePosnXPos', 0);
1464  
1465 } elsif ($self->storePosnYPos == $lineNum) {
1466  
1467 $self->ivPoke('storePosnYPos', 0);
1468 $self->ivPoke('storePosnXPos', $self->storePosnXPos - $posn);
1469  
1470 } else {
1471  
1472 $self->ivPoke('storePosnYPos', $self->storePosnYPos - $lineNum);
1473 }
1474  
1475 %tooltipHash = $self->tooltipHash;
1476 foreach my $key (keys %tooltipHash) {
1477  
1478 my ($value, $modKey);
1479  
1480 $value = $tooltipHash{$key};
1481 $modKey = $key - $lineNum;
1482  
1483 if ($modKey >= 0) {
1484  
1485 $newHash{$modKey} = $value;
1486 }
1487 }
1488  
1489 $self->ivPoke('tooltipHash', %newHash);
1490 $self->ivUndef('lastTooltipLine');
1491  
1492 # Destroy any GA::Obj::Link objects whose links are no longer visible
1493 $self->reset_link();
1494  
1495 # In case the visible cursor is at a position that's now been overwritten, redraw it
1496 $self->replaceCursor();
1497  
1498 return 1;
1499 }
1500  
1501 sub clearBufferAfterMark {
1502  
1503 # Can be called by anything
1504 # Empties the Gtk3::TextBuffer of text after a specified mark
1505 #
1506 # Expected arguments
1507 # $mark - The Gtk3::TextMark after which the buffer should be cleared
1508 #
1509 # Optional arguments
1510 # $overwriteFlag - If TRUE, overwite mode is turned on (if not already on). If FALSE or
1511 # 'undef', no change to overwrite mode is made
1512 #
1513 # Return values
1514 # 'undef' on improper arguments or if the text can't be emptied
1515 # 1 otherwise
1516  
1517 my ($self, $mark, $overwriteFlag, $check) = @_;
1518  
1519 # Local variables
1520 my ($startIter, $lineNum, $posn, $stopIter, $oldBufferSize, $lastChar);
1521  
1522 # Check for improper arguments
1523 if (! defined $mark || defined $check) {
1524  
1525 return $axmud::CLIENT->writeImproper($self->_objClass . '->clearBufferAfterMark', @_);
1526 }
1527  
1528 # Turn on overwrite mode, if required by the calling function (and if it's not already
1529 # turned on)
1530 if ($overwriteFlag && ! $self->overwriteFlag) {
1531  
1532 $self->enableOverwrite();
1533 }
1534  
1535 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
1536 $self->removeCursor();
1537  
1538 $startIter = $self->buffer->get_iter_at_mark($mark);
1539 $lineNum = $startIter->get_line();
1540 $posn = $startIter->get_visible_line_offset();
1541 $stopIter = $self->buffer->get_end_iter();
1542 $oldBufferSize = $stopIter->get_line();
1543 if (! $startIter || ! $stopIter) {
1544  
1545 return undef;
1546 }
1547  
1548 # Empty the buffer after the specified mark
1549 $self->buffer->delete($startIter, $stopIter);
1550  
1551 # Update IVs generally
1552 if ($self->nextDeleteLine < $lineNum) {
1553  
1554 $self->ivPoke('nextDeleteLine', $lineNum);
1555 }
1556  
1557 # Test the last character in the remaining buffer
1558 $stopIter = $self->buffer->get_end_iter();
1559 if (! $stopIter->backward_char()) {
1560  
1561 $self->ivPoke('bufferTextFlag', FALSE);
1562  
1563 } else {
1564  
1565 $self->ivPoke('bufferTextFlag', TRUE);
1566 $lastChar = $stopIter->get_text($self->buffer->get_end_iter());
1567 if ($lastChar eq "\n") {
1568 $self->ivPoke('newLineFlag', TRUE);
1569 } else {
1570 $self->ivPoke('newLineFlag', FALSE);
1571 }
1572 }
1573  
1574 $self->ivPoke('sizeUpdateFlag', TRUE);
1575  
1576 foreach my $iv (qw( insertMark restoreInsertMark systemInsertMark systemTextBuffer) ) {
1577  
1578 if (defined $self->$iv && ! $self->buffer->get_iter_at_mark($self->$iv)) {
1579  
1580 $self->ivUndef($iv);
1581 if ($iv eq 'insertMark') {
1582  
1583 # If buffer is empty, this flag is TRUE
1584 if (! $self->buffer->get_char_count()) {
1585 $self->ivPoke('insertNewLineFlag', TRUE);
1586 } else {
1587 $self->ivPoke('insertNewLineFlag', FALSE);
1588 }
1589 }
1590 }
1591 }
1592  
1593 if (
1594 $self->storePosnYPos > $lineNum
1595 || ($self->storePosnYPos == $lineNum && $self->storePosnXPos > $posn)
1596 ) {
1597 # The stored cursor location is invalidated
1598 $self->ivPoke('storePosnYPos', 0);
1599 $self->ivPoke('storePosnXPos', 0);
1600 }
1601  
1602 if ($oldBufferSize > $lineNum) {
1603  
1604 for (my $key = ($lineNum + 1); $key <= $oldBufferSize; $key++) {
1605  
1606 # (For speed, don't use ->ivDelete)
1607 delete $self->{tooltipHash}{$key};
1608 }
1609 }
1610  
1611 $self->ivUndef('lastTooltipLine');
1612  
1613 # Destroy any GA::Obj::Link objects whose links are no longer visible
1614 $self->reset_link();
1615  
1616 # In case the visible cursor is at a position that's now been overwritten, redraw it
1617 $self->replaceCursor();
1618  
1619 return 1;
1620 }
1621  
1622 sub clearLineBeforeMark {
1623  
1624 # Can be called by anything
1625 # Given a specified mark on a line in the Gtk3::TextBuffer, empties everything on the line
1626 # up to that point
1627 # (In other words, all characters before the mark are replaced by space characters)
1628 #
1629 # Expected arguments
1630 # $mark - The Gtk3::TextMark before which the line should be emptied
1631 #
1632 # Optional arguments
1633 # $overwriteFlag - If TRUE, overwite mode is turned on (if not already on). If FALSE or
1634 # 'undef', no change to overwrite mode is made
1635 #
1636 # Return values
1637 # 'undef' on improper arguments or if the text can't be cleared
1638 # 1 otherwise
1639  
1640 my ($self, $mark, $overwriteFlag, $check) = @_;
1641  
1642 # Local variables
1643 my ($stopIter, $lineNum, $posn, $startIter, $text);
1644  
1645 # Check for improper arguments
1646 if (! defined $mark || defined $check) {
1647  
1648 return $axmud::CLIENT->writeImproper($self->_objClass . '->clearLineAfterMark', @_);
1649 }
1650  
1651 # Turn on overwrite mode, if required by the calling function (and if it's not already
1652 # turned on)
1653 if ($overwriteFlag && ! $self->overwriteFlag) {
1654  
1655 $self->enableOverwrite();
1656 }
1657  
1658 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
1659 $self->removeCursor();
1660  
1661 $stopIter = $self->buffer->get_iter_at_mark($mark);
1662 $lineNum = $stopIter->get_line();
1663 $posn = $stopIter->get_visible_line_offset();
1664  
1665 if ($posn == 0) {
1666  
1667 # Nothing to remove, as the insert position is at the beginning of the line
1668 return 1;
1669 }
1670  
1671 $startIter = $self->buffer->get_iter_at_line_offset($lineNum, 0);
1672 $text = ' ' x $posn;
1673  
1674 $self->buffer->insert_with_tags_by_name($startIter, $text);
1675  
1676 # (No IVs to update generally)
1677  
1678 # In case the visible cursor is at a position that's now been overwritten, redraw it
1679 $self->replaceCursor();
1680  
1681 return 1;
1682 }
1683  
1684 sub clearLineAroundMark {
1685  
1686 # Can be called by anything
1687 # Clears the line at the specified mark
1688 # (In other words, all characters on the same line are replaced by space characters)
1689 #
1690 # Expected arguments
1691 # $mark - The Gtk3::TextMark after which the line should be emptied
1692 #
1693 # Optional arguments
1694 # $overwriteFlag - If TRUE, overwite mode is turned on (if not already on). If FALSE or
1695 # 'undef', no change to overwrite mode is made
1696 #
1697 # Return values
1698 # 'undef' on improper arguments or if the text can't be cleared
1699 # 1 otherwise
1700  
1701 my ($self, $mark, $overwriteFlag, $check) = @_;
1702  
1703 # Local variables
1704 my ($midIter, $lineNum, $posn, $startIter, $stopIter, $length, $text);
1705  
1706 # Check for improper arguments
1707 if (! defined $mark || defined $check) {
1708  
1709 return $axmud::CLIENT->writeImproper($self->_objClass . '->clearLineAfterMark', @_);
1710 }
1711  
1712 # Turn on overwrite mode, if required by the calling function (and if it's not already
1713 # turned on)
1714 if ($overwriteFlag && ! $self->overwriteFlag) {
1715  
1716 $self->enableOverwrite();
1717 }
1718  
1719 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
1720 $self->removeCursor();
1721  
1722 $midIter = $self->buffer->get_iter_at_mark($mark);
1723 $lineNum = $midIter->get_line();
1724 $posn = $midIter->get_visible_line_offset();
1725  
1726 $startIter = $self->buffer->get_iter_at_line_offset($lineNum, 0);
1727 $stopIter = $self->buffer->get_iter_at_line_offset(($lineNum + 1), 0);
1728 $stopIter->backward_char();
1729 $length = $stopIter->get_visible_line_offset() - $startIter->get_visible_line_offset();
1730 $text = ' ' x $length;
1731 $self->buffer->insert_with_tags_by_name($startIter, $text);
1732  
1733 # (No IVs to update generally)
1734  
1735 # In case the visible cursor is at a position that's now been overwritten, redraw it
1736 $self->replaceCursor();
1737  
1738 return 1;
1739 }
1740  
1741 sub clearLineAfterMark {
1742  
1743 # Can be called by anything
1744 # Given a specified mark on a line in the Gtk3::TextBuffer, empties the rest of the line
1745 # (In other words, all characters after the mark are replaced by space characters, but the
1746 # newline character is preserved, if present)
1747 #
1748 # Expected arguments
1749 # $mark - The Gtk3::TextMark after which the line should be emptied
1750 #
1751 # Optional arguments
1752 # $overwriteFlag - If TRUE, overwite mode is turned on (if not already on). If FALSE or
1753 # 'undef', no change to overwrite mode is made
1754 #
1755 # Return values
1756 # 'undef' on improper arguments or if the text can't be cleared
1757 # 1 otherwise
1758  
1759 my ($self, $mark, $overwriteFlag, $check) = @_;
1760  
1761 # Local variables
1762 my ($startIter, $lineNum, $posn, $length, $endIter, $stopIter);
1763  
1764 # Check for improper arguments
1765 if (! defined $mark || defined $check) {
1766  
1767 return $axmud::CLIENT->writeImproper($self->_objClass . '->clearLineAfterMark', @_);
1768 }
1769  
1770 # Turn on overwrite mode, if required by the calling function (and if it's not already
1771 # turned on)
1772 if ($overwriteFlag && ! $self->overwriteFlag) {
1773  
1774 $self->enableOverwrite();
1775 }
1776  
1777 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
1778 $self->removeCursor();
1779  
1780 $startIter = $self->buffer->get_iter_at_mark($mark);
1781 $lineNum = $startIter->get_line();
1782 $posn = $startIter->get_visible_line_offset();
1783 $length = $self->getLineLength($startIter);
1784  
1785 $endIter = $self->buffer->get_end_iter();
1786 if ($endIter->get_line() == $startIter->get_line()) {
1787  
1788 # Clear text to the end of the buffer, as we're on the last line
1789 $stopIter = $endIter;
1790  
1791 } else {
1792  
1793 # Preserve newline character at end of line
1794 $stopIter = $self->buffer->get_iter_at_line_offset($lineNum, ($length - 1));
1795 }
1796  
1797 if (! $startIter && ! $stopIter) {
1798  
1799 return undef;
1800 }
1801  
1802 # Clear the line portion
1803 $self->buffer->delete($startIter, $stopIter);
1804  
1805 # Update IVs generally
1806 foreach my $iv (qw( insertMark restoreInsertMark systemInsertMark systemTextBuffer) ) {
1807  
1808 if (defined $self->$iv && ! $self->buffer->get_iter_at_mark($self->$iv)) {
1809  
1810 $self->ivUndef($iv);
1811 if ($iv eq 'insertMark') {
1812  
1813 # If buffer is empty, this flag is TRUE
1814 if (! $self->buffer->get_char_count()) {
1815 $self->ivPoke('insertNewLineFlag', TRUE);
1816 } else {
1817 $self->ivPoke('insertNewLineFlag', FALSE);
1818 }
1819 }
1820 }
1821 }
1822  
1823 if (
1824 $self->storePosnYPos == $lineNum
1825 && $self->storePosnXPos >= $posn
1826 && $self->storePosnXPos <= $length
1827 ) {
1828 # The stored cursor location is invalidated
1829 $self->ivPoke('storePosnYPos', 0);
1830 $self->ivPoke('storePosnXPos', 0);
1831 }
1832  
1833 # In case the visible cursor is at a position that's now been overwritten, redraw it
1834 $self->replaceCursor();
1835  
1836 return 1;
1837 }
1838  
1839 sub clearBufferBeforePosn {
1840  
1841 # Can be called by anything
1842 # Empties the Gtk3::TextBuffer of text before a specified position
1843 #
1844 # Expected arguments
1845 # (none besides $self)
1846 #
1847 # Optional arguments
1848 # $overwriteFlag - If TRUE, overwite mode is turned on (if not already on). If FALSE or
1849 # 'undef', no change to overwrite mode is made
1850 # $currentYPos, $currentXPos
1851 # - The position to use. If either are not defined, the current insertion
1852 # position is used
1853 #
1854 # Return values
1855 # 'undef' on improper arguments or if the text can't be emptied
1856 # 1 otherwise
1857  
1858 my ($self, $overwriteFlag, $currentYPos, $currentXPos, $check) = @_;
1859  
1860 # Local variables
1861 my (
1862 $stopIter, $lineNum, $posn, $startIter,
1863 %tooltipHash, %newHash,
1864 );
1865  
1866 # Check for improper arguments
1867 if (defined $check) {
1868  
1869 return $axmud::CLIENT->writeImproper($self->_objClass . '->clearBufferBeforePosn', @_);
1870 }
1871  
1872 # Turn on overwrite mode, if required by the calling function (and if it's not already
1873 # turned on)
1874 if ($overwriteFlag && ! $self->overwriteFlag) {
1875  
1876 $self->enableOverwrite();
1877 }
1878  
1879 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
1880 $self->removeCursor();
1881  
1882 if (! defined $currentYPos || ! defined $currentXPos) {
1883  
1884 # Get the current insertion position (or the end of the buffer, if no insertion position
1885 # is set)
1886 ($currentYPos, $currentXPos) = $self->getInsertPosn();
1887 }
1888  
1889 $stopIter = $self->buffer->get_iter_at_line_offset($currentYPos, $currentXPos);
1890 $lineNum = $stopIter->get_line();
1891 $posn = $stopIter->get_visible_line_offset();
1892 $startIter = $self->buffer->get_start_iter();
1893 if (! $startIter || ! $stopIter) {
1894  
1895 return undef;
1896 }
1897  
1898 # Empty the buffer up to the specified position
1899 $self->buffer->delete($startIter, $stopIter);
1900  
1901 # Update IVs generally
1902 $self->ivPoke('nextDeleteLine', 0);
1903  
1904 if (! $self->buffer->get_char_count()) {
1905  
1906 $self->ivPoke('bufferTextFlag', FALSE);
1907 $self->ivPoke('newLineFlag', TRUE);
1908  
1909 } else {
1910  
1911 $self->ivPoke('bufferTextFlag', TRUE);
1912 # (->newLineFlag retains its current value)
1913 }
1914  
1915 $self->ivPoke('sizeUpdateFlag', TRUE);
1916 $self->ivPoke('insertNewLineFlag', TRUE);
1917 $self->ivUndef('insertMark');
1918 $self->ivUndef('restoreInsertMark');
1919 $self->ivUndef('tempInsertMark');
1920 $self->ivUndef('systemInsertMark');
1921  
1922 if ($self->storePosnYPos < $currentYPos) {
1923  
1924 $self->ivPoke('storePosnYPos', 0);
1925 $self->ivPoke('storePosnXPos', 0);
1926  
1927 } elsif ($self->storePosnYPos == $currentYPos) {
1928  
1929 $self->ivPoke('storePosnYPos', 0);
1930 $self->ivPoke('storePosnXPos', $self->storePosnXPos - $posn);
1931  
1932 } else {
1933  
1934 $self->ivPoke('storePosnYPos', $self->storePosnYPos - $lineNum);
1935 }
1936  
1937 %tooltipHash = $self->tooltipHash;
1938 foreach my $key (keys %tooltipHash) {
1939  
1940 my ($value, $modKey);
1941  
1942 $value = $tooltipHash{$key};
1943 $modKey = $key - $currentYPos;
1944  
1945 if ($modKey >= 0) {
1946  
1947 $newHash{$modKey} = $value;
1948 }
1949 }
1950  
1951 $self->ivPoke('tooltipHash', %newHash);
1952 $self->ivUndef('lastTooltipLine');
1953  
1954 # Destroy any GA::Obj::Link objects whose links are no longer visible
1955 $self->reset_link();
1956  
1957 # In case the visible cursor is at a position that's now been overwritten, redraw it
1958 $self->replaceCursor();
1959  
1960 return 1;
1961 }
1962  
1963 sub clearBufferAfterPosn {
1964  
1965 # Can be called by anything
1966 # Empties the Gtk3::TextBuffer of text after a specified position
1967 #
1968 # Expected arguments
1969 # (none besides $self)
1970 #
1971 # Optional arguments
1972 # $overwriteFlag - If TRUE, overwite mode is turned on (if not already on). If FALSE or
1973 # 'undef', no change to overwrite mode is made
1974 # $currentYPos, $currentXPos
1975 # - The position to use. If either are not defined, the current insertion
1976 # position is used
1977 #
1978 # Return values
1979 # 'undef' on improper arguments or if the text can't be emptied
1980 # 1 otherwise
1981  
1982 my ($self, $overwriteFlag, $currentYPos, $currentXPos, $check) = @_;
1983  
1984 # Local variables
1985 my ($startIter, $lineNum, $posn, $stopIter, $lastChar, $oldBufferSize);
1986  
1987 # Check for improper arguments
1988 if (defined $check) {
1989  
1990 return $axmud::CLIENT->writeImproper($self->_objClass . '->clearBufferAfterPosn', @_);
1991 }
1992  
1993 # Turn on overwrite mode, if required by the calling function (and if it's not already
1994 # turned on)
1995 if ($overwriteFlag && ! $self->overwriteFlag) {
1996  
1997 $self->enableOverwrite();
1998 }
1999  
2000 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
2001 $self->removeCursor();
2002  
2003 if (! defined $currentYPos || ! defined $currentXPos) {
2004  
2005 # Get the current insertion position (or the end of the buffer, if no insertion position
2006 # is set)
2007 ($currentYPos, $currentXPos) = $self->getInsertPosn();
2008 }
2009  
2010 $startIter = $self->buffer->get_iter_at_line_offset($currentYPos, $currentXPos);
2011 $lineNum = $startIter->get_line();
2012 $posn = $startIter->get_visible_line_offset();
2013 $stopIter = $self->buffer->get_end_iter();
2014 $oldBufferSize = $stopIter->get_line();
2015 if (! $startIter || ! $stopIter) {
2016  
2017 return undef;
2018 }
2019  
2020 # Empty the buffer from the specified position
2021 $self->buffer->delete($startIter, $stopIter);
2022  
2023 # Update IVs generally
2024 if ($self->nextDeleteLine < $lineNum) {
2025  
2026 $self->ivPoke('nextDeleteLine', $lineNum);
2027 }
2028  
2029 # Test the last character in the remaining buffer
2030 $stopIter = $self->buffer->get_end_iter();
2031 if (! $stopIter->backward_char()) {
2032  
2033 $self->ivPoke('bufferTextFlag', FALSE);
2034  
2035 } else {
2036  
2037 $self->ivPoke('bufferTextFlag', TRUE);
2038 $lastChar = $stopIter->get_text($self->buffer->get_end_iter());
2039 if ($lastChar eq "\n") {
2040 $self->ivPoke('newLineFlag', TRUE);
2041 } else {
2042 $self->ivPoke('newLineFlag', FALSE);
2043 }
2044 }
2045  
2046 $self->ivPoke('sizeUpdateFlag', TRUE);
2047  
2048 foreach my $iv (qw( insertMark restoreInsertMark systemInsertMark systemTextBuffer) ) {
2049  
2050 if (defined $self->$iv && ! $self->buffer->get_iter_at_mark($self->$iv)) {
2051  
2052 $self->ivUndef($iv);
2053 if ($iv eq 'insertMark') {
2054  
2055 # If buffer is empty, this flag is TRUE
2056 if (! $self->buffer->get_char_count()) {
2057 $self->ivPoke('insertNewLineFlag', TRUE);
2058 } else {
2059 $self->ivPoke('insertNewLineFlag', FALSE);
2060 }
2061 }
2062 }
2063 }
2064  
2065 if (
2066 $self->storePosnYPos > $lineNum
2067 || ($self->storePosnYPos == $lineNum && $self->storePosnXPos > $posn)
2068 ) {
2069 # The stored cursor location is invalidated
2070 $self->ivPoke('storePosnYPos', 0);
2071 $self->ivPoke('storePosnXPos', 0);
2072 }
2073  
2074 if ($oldBufferSize > $lineNum) {
2075  
2076 for (my $key = ($lineNum + 1); $key <= $oldBufferSize; $key++) {
2077  
2078 # (For speed, don't use ->ivDelete)
2079 delete $self->{tooltipHash}{$key};
2080 }
2081 }
2082  
2083 $self->ivUndef('lastTooltipLine');
2084  
2085 # Destroy any GA::Obj::Link objects whose links are no longer visible
2086 $self->reset_link();
2087  
2088 # In case the visible cursor is at a position that's now been overwritten, redraw it
2089 $self->replaceCursor();
2090  
2091 return 1;
2092 }
2093  
2094 sub clearLineBeforePosn {
2095  
2096 # Called by GA::Session->processCtrlSequence (or by any other code)
2097 # Given a specified position on a line in the Gtk3::TextBuffer, empties everything on the
2098 # line up to that point
2099 # (In other words, all characters before the position are replaced by space characters)
2100 #
2101 # Expected arguments
2102 # (none besides $self)
2103 #
2104 # Optional arguments
2105 # $overwriteFlag - If TRUE, overwite mode is turned on (if not already on). If FALSE or
2106 # 'undef', no change to overwrite mode is made
2107 # $currentYPos, $currentXPos
2108 # - The position to use. If either are not defined, the current insertion
2109 # position is used
2110 #
2111 # Return values
2112 # 'undef' on improper arguments or if the text can't be cleared
2113 # 1 otherwise
2114  
2115 my ($self, $overwriteFlag, $currentYPos, $currentXPos, $check) = @_;
2116  
2117 # Local variables
2118 my ($startIter, $text);
2119  
2120 # Check for improper arguments
2121 if (defined $check) {
2122  
2123 return $axmud::CLIENT->writeImproper($self->_objClass . '->clearLineBeforePosn', @_);
2124 }
2125  
2126 # Turn on overwrite mode, if required by the calling function (and if it's not already
2127 # turned on)
2128 if ($overwriteFlag && ! $self->overwriteFlag) {
2129  
2130 $self->enableOverwrite();
2131 }
2132  
2133 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
2134 $self->removeCursor();
2135  
2136 if (! defined $currentYPos || ! defined $currentXPos) {
2137  
2138 # Get the current insertion position (or the end of the buffer, if no insertion position
2139 # is set)
2140 ($currentYPos, $currentXPos) = $self->getInsertPosn();
2141 }
2142  
2143 if ($currentXPos == 0) {
2144  
2145 # Nothing to remove, as the insert position is at the beginning of the line
2146 return 1;
2147 }
2148  
2149 $startIter = $self->buffer->get_iter_at_line_offset($currentYPos, 0);
2150 $text = ' ' x $currentXPos;
2151  
2152 $self->buffer->insert_with_tags_by_name($startIter, $text);
2153  
2154 # (No IVs to update generally)
2155  
2156 # In case the visible cursor is at a position that's now been overwritten, redraw it
2157 $self->replaceCursor();
2158  
2159 return 1;
2160 }
2161  
2162 sub clearLineAroundPosn {
2163  
2164 # Called by GA::Session->processCtrlSequence (or by any other code)
2165 # Clears the line at the specified position
2166 # (In other words, all characters on the same line are replaced by space characters)
2167 #
2168 # Expected arguments
2169 # (none besides $self)
2170 #
2171 # Optional arguments
2172 # $overwriteFlag - If TRUE, overwite mode is turned on (if not already on). If FALSE or
2173 # 'undef', no change to overwrite mode is made
2174 # $currentYPos, $currentXPos
2175 # - The position to use. If either are not defined, the current insertion
2176 # position is used
2177 #
2178 # Return values
2179 # 'undef' on improper arguments or if the text can't be cleared
2180 # 1 otherwise
2181  
2182 my ($self, $overwriteFlag, $currentYPos, $currentXPos, $check) = @_;
2183  
2184 # Local variables
2185 my ($startIter, $stopIter, $length, $text);
2186  
2187 # Check for improper arguments
2188 if (defined $check) {
2189  
2190 return $axmud::CLIENT->writeImproper($self->_objClass . '->clearLineAroundPosn', @_);
2191 }
2192  
2193 # Turn on overwrite mode, if required by the calling function (and if it's not already
2194 # turned on)
2195 if ($overwriteFlag && ! $self->overwriteFlag) {
2196  
2197 $self->enableOverwrite();
2198 }
2199  
2200 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
2201 $self->removeCursor();
2202  
2203 if (! defined $currentYPos || ! defined $currentXPos) {
2204  
2205 # Get the current insertion position (or the end of the buffer, if no insertion position
2206 # is set)
2207 ($currentYPos, $currentXPos) = $self->getInsertPosn();
2208 }
2209  
2210 $startIter = $self->buffer->get_iter_at_line_offset($currentYPos, 0);
2211 $stopIter = $self->buffer->get_iter_at_line_offset(($currentYPos + 1), 0);
2212 $stopIter->backward_char();
2213 $length = $stopIter->get_visible_line_offset() - $startIter->get_visible_line_offset();
2214 $text = ' ' x $length;
2215 $self->buffer->insert_with_tags_by_name($startIter, $text);
2216  
2217 # (No IVs to update generally)
2218  
2219 # In case the visible cursor is at a position that's now been overwritten, redraw it
2220 $self->replaceCursor();
2221  
2222 return 1;
2223 }
2224  
2225 sub clearLineAfterPosn {
2226  
2227 # Called by GA::Session->processCtrlSequence (or by any other code)
2228 # Given a specified position on a line in the Gtk3::TextBuffer, empties the rest of the line
2229 # (In other words, all characters after the position are replaced by space characters, but
2230 # the newline character is preserved, if present)
2231 #
2232 # Expected arguments
2233 # (none besides $self)
2234 #
2235 # Optional arguments
2236 # $overwriteFlag - If TRUE, overwite mode is turned on (if not already on). If FALSE or
2237 # 'undef', no change to overwrite mode is made
2238 # $currentYPos, $currentXPos
2239 # - The position to use. If either are not defined, the current insertion
2240 # position is used
2241 #
2242 # Return values
2243 # 'undef' on improper arguments or if the text can't be cleared
2244 # 1 otherwise
2245  
2246 my ($self, $overwriteFlag, $currentYPos, $currentXPos, $check) = @_;
2247  
2248 # Local variables
2249 my ($startIter, $lineNum, $length, $endIter, $stopIter);
2250  
2251 # Check for improper arguments
2252 if (defined $check) {
2253  
2254 return $axmud::CLIENT->writeImproper($self->_objClass . '->clearLineAfterPosn', @_);
2255 }
2256  
2257 # Turn on overwrite mode, if required by the calling function (and if it's not already
2258 # turned on)
2259 if ($overwriteFlag && ! $self->overwriteFlag) {
2260  
2261 $self->enableOverwrite();
2262 }
2263  
2264 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
2265 $self->removeCursor();
2266  
2267 if (! defined $currentYPos || ! defined $currentXPos) {
2268  
2269 # Get the current insertion position (or the end of the buffer, if no insertion position
2270 # is set)
2271 ($currentYPos, $currentXPos) = $self->getInsertPosn();
2272 }
2273  
2274 $startIter = $self->buffer->get_iter_at_line_offset($currentYPos, $currentXPos);
2275 $lineNum = $startIter->get_line();
2276 $length = $self->getLineLength($startIter);
2277  
2278 $endIter = $self->buffer->get_end_iter();
2279 if ($endIter->get_line() == $startIter->get_line()) {
2280  
2281 # Clear text to the end of the buffer, as we're on the last line
2282 $stopIter = $endIter;
2283  
2284 } else {
2285  
2286 # Preserve newline character at end of line
2287 $stopIter = $self->buffer->get_iter_at_line_offset($lineNum, ($length - 1));
2288 }
2289  
2290 # Clear the line portion
2291 $self->buffer->delete($startIter, $stopIter);
2292  
2293 # Update IVs generally
2294 foreach my $iv (qw( insertMark restoreInsertMark systemInsertMark systemTextBuffer) ) {
2295  
2296 if (defined $self->$iv && ! $self->buffer->get_iter_at_mark($self->$iv)) {
2297  
2298 $self->ivUndef($iv);
2299 if ($iv eq 'insertMark') {
2300  
2301 # If buffer is empty, this flag is TRUE
2302 if (! $self->buffer->get_char_count()) {
2303 $self->ivPoke('insertNewLineFlag', TRUE);
2304 } else {
2305 $self->ivPoke('insertNewLineFlag', FALSE);
2306 }
2307 }
2308 }
2309 }
2310  
2311 if (
2312 $self->storePosnYPos == $lineNum
2313 && $self->storePosnXPos >= $currentXPos
2314 && $self->storePosnXPos <= $length
2315 ) {
2316 # The stored cursor location is invalidated
2317 $self->ivPoke('storePosnYPos', 0);
2318 $self->ivPoke('storePosnXPos', 0);
2319 }
2320  
2321 # In case the visible cursor is at a position that's now been overwritten, redraw it
2322 $self->replaceCursor();
2323  
2324 return 1;
2325 }
2326  
2327 sub getInsertPosn {
2328  
2329 # Called by several functions in this textview object
2330 # Also alled by GA::Session->processMxpLinkElement, ->processMxpSendElement,
2331 # GA::Session->processLineSegment or by any other code
2332 # Gets the position in the Gtk3::TextBuffer at which text is being inserted (via calls to
2333 # $self->insertText), expressed in a line number and character offset
2334 # If no insertion position is specified by $self->insertMark or ->tempInsertMark, returns
2335 # the position of the end of the buffer, as if the insertion position was set to that
2336 #
2337 # Expected arguments
2338 # (none besides $self)
2339 #
2340 # Return values
2341 # An empty list on improper arguments
2342 # Otherwise, a list in the form (line_number, character_number)
2343  
2344 my ($self, $check) = @_;
2345  
2346 # Local variables
2347 my (
2348 $mark, $iter,
2349 @emptyList,
2350 );
2351  
2352 # Check for improper arguments
2353 if (defined $check) {
2354  
2355 $axmud::CLIENT->writeImproper($self->_objClass . '->getInsertPosn', @_);
2356 return @emptyList;
2357 }
2358  
2359 # Get the current insertion point
2360 if ($self->insertMark) {
2361 $mark = $self->insertMark;
2362 } elsif ($self->tempInsertMark) {
2363 $mark = $self->tempInsertMark;
2364 } elsif ($self->cursorMark) {
2365 $mark = $self->cursorMark;
2366 }
2367  
2368 if ($mark) {
2369 $iter = $self->buffer->get_iter_at_mark($mark);
2370 } else {
2371 $iter = $self->buffer->get_end_iter();
2372 }
2373  
2374 return ($iter->get_line(), $iter->get_visible_line_offset());
2375 }
2376  
2377 sub setInsertPosn {
2378  
2379 # Called by GA::Session->processMxpDestElement, GA::Session->processCtrlSequence (or by any
2380 # other code)
2381 # Sets the position in the Gtk3::TextBuffer at which text is being inserted (via calls to
2382 # $self->insertText, ->insertMultipleText, ->insertWithLinks or ->insertCmd)
2383 # The position is expressed as a line number and character offset
2384 # If the specified position doesn't exist, newline character and whitespace are added to
2385 # the buffer so that text can be inserted there
2386 #
2387 # Expected arguments
2388 # (none besides $self)
2389 #
2390 # Optional arguments
2391 # $yPos - The line number. If 'undef', line 0 is used
2392 # $xPos - The character offset. If 'undef', offset 0 is used
2393 #
2394 # Return values
2395 # 'undef' on improper arguments
2396 # 1 otherwise
2397  
2398 my ($self, $yPos, $xPos, $check) = @_;
2399  
2400 # Local variables
2401 my (
2402 $lineIter, $length, $endIter, $posn, $beforeIter, $beforeString, $insertIter,
2403 $insertMark, $restoreMark,
2404 );
2405  
2406 # Check for improper arguments
2407 if (defined $check) {
2408  
2409 return $axmud::CLIENT->writeImproper($self->_objClass . '->setInsertPosn', @_);
2410 }
2411  
2412 # Turn on overwrite mode, if it's not already on
2413 if (! $self->overwriteFlag) {
2414  
2415 $self->enableOverwrite();
2416 }
2417  
2418 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
2419 $self->removeCursor();
2420  
2421 # Use default line number/character offset if they weren't specified
2422 if (! defined $yPos) {
2423  
2424 $yPos = 0;
2425 }
2426  
2427 if (! defined $xPos) {
2428  
2429 $xPos = 0;
2430 }
2431  
2432 # Before v3.20, Gtk doesn't allow the use of an invalid position, so we must check it's
2433 # valid before proceeding
2434  
2435 # Check the end of the buffer
2436 if ($yPos > ($self->buffer->get_line_count() - 1)) {
2437  
2438 # The specified line doesn't exist, so we need to add some new (empty) ones
2439 do {
2440  
2441 $self->buffer->insert($self->buffer->get_end_iter(), "\n");
2442  
2443 } until ($yPos <= ($self->buffer->get_line_count() - 1));
2444 }
2445  
2446 # Check the size of the specified line
2447 $lineIter = $self->buffer->get_iter_at_line($yPos);
2448 $length = $self->getLineLength($lineIter);
2449 # Get the position of the iter just before the line's newline character, if any (there won't
2450 # be one if this line is at the end of the buffer)
2451 # (Don't need to check that $endIter->get_visible_line_offset() matches the same value in
2452 # $lineIter, since we already know it's the last line)
2453 $endIter = $self->buffer->get_end_iter();
2454 if ($endIter->get_line() == $lineIter->get_line()) {
2455 $posn = $length;
2456 } else {
2457 $posn = $length - 1;
2458 }
2459  
2460 # Check the length of the specified line
2461 if ($xPos > $posn) {
2462  
2463 # The specified line offset doesn't exist, so we need to add some empty space
2464 $beforeIter = $self->buffer->get_iter_at_line_offset($yPos, $posn);
2465 $beforeString = ' ' x ($xPos - $posn);
2466 $self->buffer->insert($beforeIter, $beforeString);
2467 }
2468  
2469 # Set the new insert position, storing the current position in case $self->resetInsertPosn
2470 # is called
2471 $insertIter = $self->buffer->get_iter_at_line_offset($yPos, $xPos);
2472 $insertMark = $self->buffer->create_mark('insert_mark', $insertIter, TRUE);
2473 $self->ivPoke('insertMark', $insertMark);
2474  
2475 $insertIter = $self->buffer->get_iter_at_line_offset($yPos, $xPos);
2476 $restoreMark = $self->buffer->create_mark('restore_insert_mark', $insertIter, TRUE);
2477 $self->ivPoke('restoreInsertMark', $restoreMark);
2478  
2479 # If the cursor is visible, move it to this position (i.e. insert a new Gtk3::TextTag)
2480 $self->moveCursor($self->buffer->get_iter_at_mark($insertMark));
2481  
2482 return 1;
2483 }
2484  
2485 sub resetInsertPosn {
2486  
2487 # Called by GA::Session->processMxpDestElement (or by any other code)
2488 # Resets the position in the Gtk3::TextBuffer at which text is being inserted to the
2489 # position before the most recent call to $self->setInsertPosn
2490 #
2491 # Expected arguments
2492 # (none besides $self)
2493 #
2494 # Return values
2495 # 'undef' on improper arguments
2496 # 1 otherwise
2497  
2498 my ($self, $check) = @_;
2499  
2500 # Check for improper arguments
2501 if (defined $check) {
2502  
2503 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetInsertPosn', @_);
2504 }
2505  
2506 $self->ivPoke('insertMark', $self->restoreInsertMark);
2507 $self->ivUndef('restoreInsertMark');
2508  
2509 return 1;
2510 }
2511  
2512 sub adjustInsertPosn {
2513  
2514 # Called by GA::Session->processCtrlSequence (or by any other code)
2515 # Adjusts the position of the current insertion position
2516 #
2517 # Expected arguments
2518 # $yAdjust - The line number adjustment, e.g. -1 to move up a line, +2 to move down 2
2519 # lines, 0 to stay on the same line
2520 # $xAdjust - The character offset adjustment, e.g. -1 to move back one character, +2 to
2521 # move forwards 2 characters, 0 to stay in the same column
2522 #
2523 # Return values
2524 # 'undef' on improper arguments
2525 # Otherwise returns the result of the call to $self->setInsertPosn
2526  
2527 my ($self, $yAdjust, $xAdjust, $check) = @_;
2528  
2529 # Local variables
2530 my ($yPos, $xPos, $iter);
2531  
2532 # Check for improper arguments
2533 if (! defined $yAdjust || ! defined $xAdjust || defined $check) {
2534  
2535 return $axmud::CLIENT->writeImproper($self->_objClass . '->adjustInsertPosn', @_);
2536 }
2537  
2538 # Turn on overwrite mode, if it's not already on
2539 if (! $self->overwriteFlag) {
2540  
2541 $self->enableOverwrite();
2542 }
2543  
2544 # Get the current insertion position (or the end of the buffer, if no insertion position is
2545 # set)
2546 ($yPos, $xPos) = $self->getInsertPosn();
2547  
2548 # Make the adjustment
2549 $yPos += $yAdjust;
2550 $xPos += $xAdjust;
2551  
2552 # Sanity checks. If $xPos is now greater than the length of the existing line,
2553 # $self->setInsertPosn will add extra spaces; otherwise, we have to adjust bad values
2554 # ourselves
2555 if ($yPos < 0) {
2556  
2557 $yPos = 0;
2558 }
2559  
2560 if ($xPos < 0) {
2561  
2562 $xPos = 0;
2563 }
2564  
2565 $iter = $self->buffer->get_end_iter();
2566 if ($yPos > $iter->get_line()) {
2567  
2568 $yPos = $iter->get_line();
2569 }
2570  
2571 # Change the insertion position
2572 return $self->setInsertPosn($yPos, $xPos);
2573 }
2574  
2575 sub adjustInsertLine {
2576  
2577 # Called by GA::Session->processCtrlSequence (or by any other code)
2578 # Adjusts the position of the current insertion position, moving it to the beginning of a
2579 # line
2580 #
2581 # Expected arguments
2582 # $yAdjust - The line number adjustment, e.g. -1 to move up a line, +2 to move down 2
2583 # lines, 0 to stay on the same line
2584 #
2585 # Return values
2586 # 'undef' on improper arguments
2587 # Otherwise returns the result of the call to $self->setInsertPosn
2588  
2589 my ($self, $yAdjust, $check) = @_;
2590  
2591 # Local variables
2592 my ($yPos, $xPos, $iter);
2593  
2594 # Check for improper arguments
2595 if (! defined $yAdjust || defined $check) {
2596  
2597 return $axmud::CLIENT->writeImproper($self->_objClass . '->adjustInsertLine', @_);
2598 }
2599  
2600 # Turn on overwrite mode, if it's not already on
2601 if (! $self->overwriteFlag) {
2602  
2603 $self->enableOverwrite();
2604 }
2605  
2606 # Get the current insertion position (or the end of the buffer, if no insertion position is
2607 # set)
2608 ($yPos) = $self->getInsertPosn();
2609  
2610 # Make the adjustment
2611 $yPos += $yAdjust;
2612 $xPos = 0;
2613  
2614 # Sanity checks. If $xPos is now greater than the length of the existing line,
2615 # $self->setInsertPosn will add extra spaces; otherwise, we have to adjust bad values
2616 # ourselves
2617 if ($yPos < 0) {
2618  
2619 $yPos = 0;
2620 }
2621  
2622 $iter = $self->buffer->get_end_iter();
2623 if ($yPos > $iter->get_line()) {
2624  
2625 $yPos = $iter->get_line();
2626 }
2627  
2628 # Change the insertion position
2629 return $self->setInsertPosn($yPos, $xPos);
2630 }
2631  
2632 sub adjustInsertOffset {
2633  
2634 # Called by GA::Session->processCtrlSequence (or by any other code)
2635 # Adjusts the position of the current insertion position
2636 #
2637 # Expected arguments
2638 # $xPos - The character offset. If 'undef', offset 0 is used
2639 #
2640 # Return values
2641 # 'undef' on improper arguments
2642 # Otherwise returns the result of the call to $self->setInsertPosn
2643  
2644 my ($self, $xPos, $check) = @_;
2645  
2646 # Local variables
2647 my $yPos;
2648  
2649 # Check for improper arguments
2650 if (! defined $xPos || defined $check) {
2651  
2652 return $axmud::CLIENT->writeImproper($self->_objClass . '->adjustInsertOffset', @_);
2653 }
2654  
2655 # Turn on overwrite mode, if it's not already on
2656 if (! $self->overwriteFlag) {
2657  
2658 $self->enableOverwrite();
2659 }
2660  
2661 # Get the current insertion position (or the end of the buffer, if no insertion position is
2662 # set)
2663 ($yPos) = $self->getInsertPosn();
2664  
2665 # Sanity checks. If $xPos is now greater than the length of the existing line,
2666 # $self->setInsertPosn will add extra spaces; otherwise, we have to adjust bad values
2667 # ourselves
2668 if ($xPos < 0) {
2669  
2670 $xPos = 0;
2671 }
2672  
2673 # Change the insertion position
2674 return $self->setInsertPosn($yPos, $xPos);
2675 }
2676  
2677 sub storeInsertPosn {
2678  
2679 # Called by GA::Session->processCtrlSequence (or by any other code)
2680 # Stores the current insertion position, so it can be re-used as the new insertion position
2681 # at some point in the future
2682 #
2683 # Expected arguments
2684 # (none besides $self)
2685 #
2686 # Optional arguments
2687 # $overwriteFlag - If TRUE, overwite mode is turned on (if not already on). If FALSE or
2688 # 'undef', no change to overwrite mode is made
2689 #
2690 # Return values
2691 # 'undef' on improper arguments
2692 # 1 otherwise
2693  
2694 my ($self, $overwriteFlag, $check) = @_;
2695  
2696 # Local variables
2697 my ($currentYPos, $currentXPos);
2698  
2699 # Check for improper arguments
2700 if (defined $check) {
2701  
2702 return $axmud::CLIENT->writeImproper($self->_objClass . '->storeInsertPosn', @_);
2703 }
2704  
2705 # Turn on overwrite mode, if required by the calling function (and if it's not already
2706 # turned on)
2707 if ($overwriteFlag && ! $self->overwriteFlag) {
2708  
2709 $self->enableOverwrite();
2710 }
2711  
2712 # Get the current insertion position (or the end of the buffer, if no insertion position is
2713 # set)
2714 ($currentYPos, $currentXPos) = $self->getInsertPosn();
2715  
2716 $self->ivPoke('storePosnYPos', $currentYPos);
2717 $self->ivPoke('storePosnXPos', $currentXPos);
2718  
2719 return 1;
2720 }
2721  
2722 sub restoreInsertPosn {
2723  
2724 # Called by GA::Session->processCtrlSequence (or by any other code)
2725 # Restores the cursor position stored in an earlier call to $self->storeInsertPosn
2726 #
2727 # Expected arguments
2728 # (none besides $self)
2729 #
2730 # Return values
2731 # 'undef' on improper arguments
2732 # Otherwise returns the result of the call to $self->setInsertPosn
2733  
2734 my ($self, $check) = @_;
2735  
2736 # Check for improper arguments
2737 if (defined $check) {
2738  
2739 return $axmud::CLIENT->writeImproper($self->_objClass . '->restoreInsertPosn', @_);
2740 }
2741  
2742 # Turn on overwrite mode, if it's not already on
2743 if (! $self->overwriteFlag) {
2744  
2745 $self->enableOverwrite();
2746 }
2747  
2748 return $self->setInsertPosn($self->storePosnYPos, $self->storePosnXPos);
2749 }
2750  
2751 sub insertBackspace {
2752  
2753 # Called mostly by GA::Session->processIncomingData
2754 # Inserts a string probably containing one or more backspace characters
2755 # If overwrite mode is one, processes the string as received. If overwrite mode is off,
2756 # replaces the backspace character with good ol' fashioned '^H', and displays it as a
2757 # normal string
2758 #
2759 # Expected arguments
2760 # $string - The string to insert. It's usually in the form "\b \b", or just "\b", but can
2761 # contain any combination of characters (including an empty string)
2762 #
2763 # Return values
2764 # 'undef' on improper arguments
2765 # 1 otherwise
2766  
2767 my ($self, $string, $check) = @_;
2768  
2769 # Local variables
2770 my @list;
2771  
2772 # Check for improper arguments
2773 if (! defined $string || defined $check) {
2774  
2775 return $axmud::CLIENT->writeImproper($self->_objClass . '->insertBackspace', @_);
2776 }
2777  
2778 if ($string eq '') {
2779  
2780 # Nothing to insert
2781 return 1;
2782  
2783 } elsif (! $self->overwriteFlag) {
2784  
2785 # Replace the backspace characters with ^H, and display $string as an ordinary string
2786 $string =~ s/\b/^H/g;
2787 return $self->insertText($string, 'echo');
2788 }
2789  
2790 # Otherwise, split $string into segments, adjusting the insert position for each backspace
2791 # character it contains
2792 do {
2793  
2794 my ($index, $yPos, $xPos);
2795  
2796 $index = index($string, "\b");
2797 if ($index == 0) {
2798  
2799 # Set the new insert position one character earlier in the line (but if already at
2800 # the beginning of a line, don't go any further backwards in the buffer)
2801 ($yPos, $xPos) = $self->getInsertPosn();
2802 if ($xPos > 0) {
2803  
2804 $self->setInsertPosn($yPos, ($xPos - 1));
2805 }
2806  
2807 $string = substr($string, 1);
2808  
2809 } elsif ($index == -1 ) {
2810  
2811 # The rest of $string contains no backspace characters
2812 $self->insertText($string, 'echo');
2813 $string = '';
2814  
2815 } else {
2816  
2817 # String starts with one or more non-backspace characters
2818 $self->insertText(substr($string, 0, $index), 'echo');
2819 $string = substr($string, $index);
2820 }
2821  
2822 } until ($string eq '');
2823  
2824 return 1;
2825 }
2826  
2827 sub scrlRegionUp {
2828  
2829 # Called by $self->insertNewLine and GA::Session->processCtrlSequence
2830 # VT100 (and similar terminal standards) define an area of the textview, the scroll region,
2831 # which should 'scroll' independently of the rest of the textview
2832 # Actually, when the region 'scrolls', we just delete the line at the top of the region,
2833 # and add a new line at the bottom of it
2834 #
2835 # Expected arguments
2836 # $num - The number of lines to scroll (when called by $self->insertNewLine, set
2837 # to 1)
2838 #
2839 # Optional arguments
2840 # $nlFlag - Set to TRUE if the calling function hasn't inserted a newline character at
2841 # the bottom of the region (in which case, this function needs to do it).
2842 # Set to FALSE (or 'undef') if the newline character has already been
2843 # inserted, in which case this function only needs to delete the line at
2844 # the top of the region
2845 #
2846 # Return values
2847 # 'undef' on improper arguments, if the scroll region doesn't exist, if $num is not a
2848 # positive integer or if the scroll region's IVs are set to invalid values
2849 # 1 otherwise
2850  
2851 my ($self, $num, $nlFlag, $check) = @_;
2852  
2853 # Check for improper arguments
2854 if (! defined $num || defined $check) {
2855  
2856 return $axmud::CLIENT->writeImproper($self->_objClass . '->scrlRegionUp', @_);
2857 }
2858  
2859 # Check a scrolling region is defined, that $num is a valid integer, and that the buffer
2860 # actually contains at least as many lines as specified by $self->scrlRegionBottom
2861 if (
2862 ! defined $self->scrlRegionTop
2863 || ! $axmud::CLIENT->intCheck($num, 1)
2864 || ($self->buffer->get_line_count() - 1) < ($self->scrlRegionBottom + 1)
2865 ) {
2866 return undef;
2867 }
2868  
2869 # Update the scrolling region $num times
2870 for (my $count = 0; $count < $num; $count++) {
2871  
2872 $self->buffer->delete(
2873 $self->buffer->get_iter_at_line_offset($self->scrlRegionTop, 0),
2874 $self->buffer->get_iter_at_line_offset(($self->scrlRegionTop + 1), 0),
2875 );
2876  
2877 if ($nlFlag) {
2878  
2879 # Newline character(s) haven't been inserted into the buffer by the calling
2880 # function, so we need to insert them here
2881 $self->buffer->insert(
2882 $self->buffer->get_iter_at_line_offset($self->scrlRegionBottom, 0),
2883 "\n",
2884 );
2885 }
2886  
2887 # Update the tooltip IVs
2888 for (my $line = ($self->scrlRegionTop + 1); $line <= $self->scrlRegionBottom; $line++) {
2889  
2890 $self->ivAdd('tooltipHash', ($line - 1), $self->ivShow('tooltipHash', $line));
2891 }
2892  
2893 $self->ivAdd('tooltipHash', $self->scrlRegionBottom, '');
2894 $self->ivPoke('lastTooltipLine', undef);
2895 }
2896  
2897 # Operation complete
2898 return 1;
2899 }
2900  
2901 sub scrlRegionDown {
2902  
2903 # Called by GA::Session->processCtrlSequence (only)
2904 # VT100 (and similar terminal standards) define an area of the textview, the scroll region,
2905 # which should 'scroll' independently of the rest of the textview
2906 # Actually, when the region 'scrolls', we just delete the line at the bottom of the region,
2907 # and add a new line at the top of it
2908 #
2909 # Expected arguments
2910 # $num - The number of lines to scroll
2911 #
2912 # Return values
2913 # 'undef' on improper arguments, if the scroll region doesn't exist, if $num is not a
2914 # positive integer or if the scroll region's IVs are set to invalid values
2915 # 1 otherwise
2916  
2917 my ($self, $num, $nlFlag, $check) = @_;
2918  
2919 # Check for improper arguments
2920 if (! defined $num || defined $check) {
2921  
2922 return $axmud::CLIENT->writeImproper($self->_objClass . '->scrlRegionDown', @_);
2923 }
2924  
2925 # Check a scrolling region is defined, that $num is a valid integer, and that the buffer
2926 # actually contains at least as many lines as specified by $self->scrlRegionTop
2927 if (
2928 ! defined $self->scrlRegionTop
2929 || ! $axmud::CLIENT->intCheck($num, 1)
2930 || ($self->buffer->get_line_count() - 1) < ($self->scrlRegionTop + 1)
2931 ) {
2932 return undef;
2933 }
2934  
2935 # Update the scrolling region $num times
2936 for (my $count = 0; $count < $num; $count++) {
2937  
2938 $self->buffer->delete(
2939 $self->buffer->get_iter_at_line_offset($self->scrlRegionBottom, 0),
2940 $self->buffer->get_iter_at_line_offset(($self->scrlRegionBottom + 1), 0),
2941 );
2942  
2943 # Newline character(s) haven't been inserted into the buffer by the calling
2944 # function, so we need to insert them here
2945 $self->buffer->insert(
2946 $self->buffer->get_iter_at_line_offset($self->scrlRegionTop, 0),
2947 "\n",
2948 );
2949  
2950 # Update the tooltip IVs
2951 for (my $line = ($self->scrlRegionBottom - 1); $line >= $self->scrlRegionTop; $line++) {
2952  
2953 $self->ivAdd('tooltipHash', ($line + 1), $self->ivShow('tooltipHash', $line));
2954 }
2955  
2956 $self->ivAdd('tooltipHash', $self->scrlRegionTop, '');
2957 $self->ivPoke('lastTooltipLine', undef);
2958 }
2959  
2960 # Operation complete
2961 return 1;
2962 }
2963  
2964 # Other functions - text insertion
2965  
2966 sub insertText {
2967  
2968 # Can be called by anything
2969 # Inserts text into the Gtk3::TextBuffer, optionally applying Axmud colour/style tags and/or
2970 # a newline character, and optionally emptying the buffer of text
2971 # NB This function doesn't write to any log files; the calling function can do that, if
2972 # required
2973 #
2974 # Expected arguments
2975 # (none besides $self)
2976 #
2977 # Optional arguments
2978 # $text - The text to write. If undefined, the text <<undef>> is written
2979 # @args - Optional list of arguments, in any order:
2980 # - 'empty' (empties the buffer before writing $text)
2981 # - 'before' (prepends a newline character to $text)
2982 # - 'after' or 'nl' (appends a newline character to $text)
2983 # - 'echo' (does not prepend/append a newline character, overrides
2984 # 'before', 'after' and 'nl' if they are specified)
2985 # - one or more Axmud colour tags. Only the first text colour (e.g. 'red')
2986 # is used, and only the first underlay colour ('UL_RED') is used.
2987 # The range of Axmud colour tags include:
2988 # - standard colour tags like 'red', 'BLUE', 'ul_red', 'UL_BLUE'
2989 # (case-sensititive)
2990 # - xterm colour tags (strings in the range 'x0' to 'x255', or
2991 # 'ux0' to 'ux255'; case-insensitive, so 'X0' is valid)
2992 # - RGB colour tags (strings in the range '#000000' to '#FFFFFF', or
2993 # 'u#000000' to 'u#FFFFFF'; case-insensitive, so 'U#AbCdEf' is
2994 # valid)
2995 # - one or more Axmud style tags ('italics', 'strike', etc)
2996 #
2997 # - NB The default behaviour is set by $self->defaultNewLine, which is set to
2998 # 'before', 'after', 'nl' or 'echo'. This default behaviour is only
2999 # applied if none of 'before', 'after', 'nl' and 'echo' are specified
3000 #
3001 # Notes
3002 # If both 'echo' and any of 'before'/'after'/'nl' are specified (or if neither is
3003 # specified), a newline character is NOT appended
3004 #
3005 # Return values
3006 # 'undef' on improper arguments
3007 # 1 otherwise
3008  
3009 my ($self, $text, @args) = @_;
3010  
3011 # Local variables
3012 my (
3013 $emptyFlag, $beforeFlag, $afterFlag, $linkFlag, $textColour, $underlayColour,
3014 $monochromeFlag, $beep, $mark, $iter, $tempInsertFlag,
3015 @styleTags,
3016 );
3017  
3018 # (No improper arguments to check)
3019  
3020 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
3021 $self->removeCursor();
3022 # If the buffer is due to be cleared before inserting any text, then clear it
3023 if ($self->clearAfterInsertFlag) {
3024  
3025 # The TRUE argument means 'don't remove/move the cursor'
3026 $self->clearBuffer(undef, TRUE);
3027 }
3028  
3029 # Interpret the list of @args
3030 ($emptyFlag, $beforeFlag, $afterFlag, $linkFlag, $textColour, $underlayColour, @styleTags)
3031 = $self->interpretTags($self->newLineDefault, @args);
3032 # Apply any colour overrides specified by the colour scheme or by this object's own
3033 # monochrome mode
3034 ($monochromeFlag, $textColour, $underlayColour) = $self->modifyColourTags(
3035 $textColour,
3036 $underlayColour,
3037 );
3038  
3039 # Choose which colour tags to use (in monochrome mode, text/underlay colours are ignored)
3040 if (! $textColour) {
3041  
3042 $textColour = $self->textColour;
3043 }
3044  
3045 if (! $underlayColour) {
3046  
3047 $underlayColour = $self->underlayColour;
3048 }
3049  
3050 # If allowed, convert the colour of invisible text (e.g. black text with a black underlay
3051 # on a black background) to something visible
3052 if (
3053 $axmud::CLIENT->convertInvisibleFlag
3054 && $textColour eq $self->backgroundColour
3055 && (
3056 $underlayColour eq 'ul_' . $self->backgroundColour
3057 || $underlayColour eq 'UL_' . $self->backgroundColour
3058 )
3059 ) {
3060 if ($axmud::CLIENT->ivExists('constPrettyTagHash', $textColour)) {
3061 $textColour = uc($textColour);
3062 } else {
3063 $textColour = lc($textColour);
3064 }
3065 }
3066  
3067 # Empty the buffer before writing text, if required
3068 if ($emptyFlag) {
3069  
3070 # The TRUE argument means 'don't remove/move the cursor'
3071 $self->clearBuffer(undef, TRUE);
3072 }
3073  
3074 # Prepare the message to send
3075 if (! defined $text) {
3076  
3077 # 'undef' is a valid value - represent it
3078 $text = "<<undef>>";
3079 }
3080  
3081 # If $text contains any ASCII 7 characters (bells) and sound is on, play the 'bell' sound.
3082 # After that, even if sound is off, remove the ASCII 7 character from $text
3083 $beep = chr(7);
3084 if ($text =~ m/$beep/) {
3085  
3086 # Don't display the ASCII 7 character
3087 $text =~ s/$beep//g;
3088  
3089 # Play the bell once, if allowed (even if the character appears multiple times in $text;
3090 # the call to ->playSound checks the status of GA::Client->allowSoundFlag)
3091 if ($axmud::CLIENT->allowAsciiBellFlag) {
3092  
3093 $axmud::CLIENT->playSound('bell');
3094 }
3095 }
3096  
3097 # Set the insertion point
3098 if ($self->insertMark) {
3099  
3100 $mark = $self->insertMark;
3101  
3102 } elsif ($self->tempInsertMark) {
3103  
3104 $mark = $self->tempInsertMark;
3105 if ($afterFlag) {
3106  
3107 # This code prevents a blank line being inserted between a world's prompt and the
3108 # already-displayed Axmud system message
3109 $self->ivUndef('tempInsertMark');
3110 $afterFlag = FALSE;
3111 $tempInsertFlag = TRUE;
3112 }
3113 }
3114  
3115 if ($mark) {
3116 $iter = $self->buffer->get_iter_at_mark($mark);
3117 } elsif (! $self->systemInsertMark) {
3118 $iter = $self->buffer->get_end_iter();
3119 } else {
3120  
3121 # Incomplete system message after a call to $self->showSystemText without a newline
3122 # character. Must insert an artificial newline character, and display $text after
3123 # that
3124 $iter = $self->buffer->get_iter_at_mark($self->systemInsertMark);
3125 $iter = $self->insertNewLine($iter);
3126 $self->ivPoke('prevColourStyleHash', $self->colourStyleHash);
3127 }
3128  
3129 # (Don't prepend a newline character if the buffer is empty)
3130 if ($beforeFlag && $self->bufferTextFlag) {
3131  
3132 # (Make sure the beginning of a link appears after the extra newline character, not
3133 # before it)
3134 $iter = $self->insertNewLine($iter);
3135 $self->ivPoke('prevColourStyleHash', $self->colourStyleHash);
3136 }
3137  
3138 # Create a link object, if required
3139 if ($linkFlag && $text) {
3140  
3141 $self->setupLink($iter, $text);
3142 }
3143  
3144 # Insert the text into the Gtk3::TextBuffer
3145 if (! $monochromeFlag) {
3146  
3147 $iter = $self->insertWithTags(
3148 $iter,
3149 $text,
3150 $textColour,
3151 $underlayColour,
3152 @styleTags,
3153 );
3154  
3155 } else {
3156  
3157 $iter = $self->insertWithTags(
3158 $iter,
3159 $text,
3160 @styleTags,
3161 );
3162 }
3163  
3164 if ($afterFlag) {
3165  
3166 # (Make sure the end of a link appears before the extra newline character, not
3167 # after it)
3168 $iter = $self->insertNewLine($iter);
3169 $self->ivPoke('prevColourStyleHash', $self->colourStyleHash);
3170 }
3171  
3172 if ($self->insertMark) {
3173  
3174 # The next call to $self->insertText, ->insertCmd etc uses the insertion point
3175 # immediately after $iter
3176 $mark = $self->buffer->create_mark('insert_mark', $iter, TRUE);
3177 $self->ivPoke('insertMark', $mark);
3178 # If the cursor is visible, move it to this position (i.e. insert a new Gtk3::TextTag)
3179 $self->moveCursor($self->buffer->get_iter_at_mark($mark));
3180  
3181 } elsif ($tempInsertFlag) {
3182  
3183 # Continue using this temporary insertion point, before a line with a system message
3184 # (and don't restore the cursor yet)
3185 $mark = $self->buffer->create_mark('temp_insert_mark', $iter, TRUE);
3186 $self->ivPoke('tempInsertMark', $mark);
3187  
3188 } else {
3189  
3190 # If the cursor is visible, move it to the end of the buffer (i.e. insert a new
3191 # Gtk3::TextTag)
3192 $self->moveCursor();
3193 }
3194  
3195 # Apply scroll lock, if required
3196 if ($self->scrollLockFlag) {
3197  
3198 if ($self->scrollLockType eq 'top') {
3199 $self->scrollToTop();
3200 } else {
3201 $self->scrollToBottom();
3202 }
3203 }
3204  
3205 return 1;
3206 }
3207  
3208 sub insertMultipleText {
3209  
3210 # Can be called by anything (but mostly called by Session->displayLinePieces)
3211 # Instead of calling $self->insertText multiple times, this function can be called a single
3212 # time for multiple pieces of text (which should save some processing time)
3213 #
3214 # Calls to $self->insertText use the default behaviour specified by $self->defaultNewLine,
3215 # if none of the arguments 'empty', 'before', 'after', 'nl' or 'echo' are specified
3216 # However, this function ignores those arguments, except for 'before' for the first text
3217 # piece and 'after' for the last text piece (if specified); for every other text piece,
3218 # the default behaviour 'echo' is used
3219 #
3220 # Expected arguments
3221 # @displayList - List in groups of 2, in the form
3222 # (piece_of_text, reference_to_list_of_arguments)
3223 # ...where each group of 2 is the same as the arguments used in a single
3224 # call to $self->insertText
3225 #
3226 # Return values
3227 # 'undef' on improper arguments
3228 # 1 otherwise
3229  
3230 my ($self, @displayList) = @_;
3231  
3232 # Local variables
3233 my ($firstFlag, $iter, $mark, $finalAfterFlag, $tempInsertFlag);
3234  
3235 # Check for improper arguments
3236 if (! @displayList) {
3237  
3238 return $axmud::CLIENT->writeImproper($self->_objClass . '->insertMultipleText', @_);
3239 }
3240  
3241 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
3242 $self->removeCursor();
3243 # If the buffer is due to be cleared before inserting any text, then clear it
3244 if ($self->clearAfterInsertFlag) {
3245  
3246 # The TRUE argument means 'don't remove/move the cursor'
3247 $self->clearBuffer(undef, TRUE);
3248 }
3249  
3250 # Some operations are only executed for the first 'piece_of_text' in @displayList
3251 $firstFlag = TRUE;
3252  
3253 # Process each text piece in turn
3254 do {
3255  
3256 my (
3257 $text, $listRef, $emptyFlag, $beforeFlag, $afterFlag, $linkFlag, $textColour,
3258 $underlayColour, $monochromeFlag, $beep,
3259 @styleTags,
3260 );
3261  
3262 $text = shift @displayList;
3263 $listRef = shift @displayList;
3264  
3265 # Interpret the list of @args
3266 (
3267 $emptyFlag, $beforeFlag, $afterFlag, $linkFlag, $textColour, $underlayColour,
3268 @styleTags,
3269 ) = $self->interpretTags($self->newLineDefault, @$listRef);
3270 # Apply any colour overrides specified by the colour scheme or by this object's own
3271 # monochrome mode
3272 ($monochromeFlag, $textColour, $underlayColour) = $self->modifyColourTags(
3273 $textColour,
3274 $underlayColour,
3275 );
3276  
3277 # Choose which colour tags to use (in monochrome mode, text/underlay colours are
3278 # ignored)
3279 if (! $textColour) {
3280  
3281 $textColour = $self->textColour;
3282 }
3283  
3284 if (! $underlayColour) {
3285  
3286 $underlayColour = $self->underlayColour;
3287 }
3288  
3289 # If allowed, convert the colour of invisible text (e.g. black text with a black
3290 # underlay on a black background) to something visible
3291 if (
3292 $axmud::CLIENT->convertInvisibleFlag
3293 && $textColour eq $self->backgroundColour
3294 && (
3295 $underlayColour eq 'ul_' . $self->backgroundColour
3296 || $underlayColour eq 'UL_' . $self->backgroundColour
3297 )
3298 ) {
3299 if ($axmud::CLIENT->ivExists('constPrettyTagHash', $textColour)) {
3300 $textColour = uc($textColour);
3301 } else {
3302 $textColour = lc($textColour);
3303 }
3304 }
3305  
3306 # Empty the buffer before writing text, if required
3307 if ($emptyFlag) {
3308  
3309 # The TRUE argument means 'don't remove/move the cursor'
3310 $self->clearBuffer(undef, TRUE);
3311 }
3312  
3313 # Prepare the message to send
3314 if (! defined $text) {
3315  
3316 # 'undef' is a valid value - represent it
3317 $text = "<<undef>>";
3318 }
3319  
3320 # If $text contains any ASCII 7 characters (bells) and sound is on, play the 'bell'
3321 # sound. After that, even if sound is off, remove the ASCII 7 character from $text
3322 $beep = chr(7);
3323 if ($text =~ m/$beep/) {
3324  
3325 # Don't display the ASCII 7 character
3326 $text =~ s/$beep//g;
3327  
3328 # Play the bell once, if allowed (even if the character appears multiple times in
3329 # $text; the call to ->playSound checks the status of GA::Client->allowSoundFlag)
3330 if ($axmud::CLIENT->allowAsciiBellFlag) {
3331  
3332 $axmud::CLIENT->playSound('bell');
3333 }
3334 }
3335  
3336 # For the first text piece, set the insertion point (all other pieces are inserted
3337 # directly after that)
3338 if ($firstFlag) {
3339  
3340 # Set the insertion point
3341 if ($self->insertMark) {
3342  
3343 $mark = $self->insertMark;
3344  
3345 } elsif ($self->tempInsertMark) {
3346  
3347 $mark = $self->tempInsertMark;
3348 if ($afterFlag) {
3349  
3350 # This code prevents a blank line being inserted between a world's prompt
3351 # and the already-displayed Axmud system message
3352 $self->ivUndef('tempInsertMark');
3353 $afterFlag = FALSE;
3354 # Act on the temporary insertion point once we've finished this do... loop
3355 $tempInsertFlag = TRUE;
3356 }
3357 }
3358  
3359 if ($mark) {
3360 $iter = $self->buffer->get_iter_at_mark($mark);
3361 } elsif (! $self->systemInsertMark) {
3362 $iter = $self->buffer->get_end_iter();
3363 } else {
3364  
3365 # Incomplete system message after a call to $self->showSystemText without a
3366 # newline character. Must insert an artificial newline character, and display
3367 # $text after that
3368 $iter = $self->buffer->get_iter_at_mark($self->systemInsertMark);
3369 $iter = $self->insertNewLine($iter);
3370 $self->ivPoke('prevColourStyleHash', $self->colourStyleHash);
3371 }
3372  
3373 # (Don't prepend a newline character if the buffer is empty, or for any text piece
3374 # besides the first one)
3375 if ($beforeFlag && $self->bufferTextFlag) {
3376  
3377 # (Make sure the beginning of a link appears after the extra newline character,
3378 # not before it)
3379 $iter = $self->insertNewLine($iter);
3380 $self->ivPoke('prevColourStyleHash', $self->colourStyleHash);
3381 }
3382 }
3383  
3384 # Create a link object, if required
3385 if ($linkFlag && $text) {
3386  
3387 $self->setupLink($iter, $text);
3388 }
3389  
3390 # Insert the text into the Gtk3::TextBuffer
3391 if (! $monochromeFlag) {
3392  
3393 $iter = $self->insertWithTags(
3394 $iter,
3395 $text,
3396 $textColour,
3397 $underlayColour,
3398 @styleTags,
3399 );
3400  
3401 } else {
3402  
3403 $iter = $self->insertWithTags(
3404 $iter,
3405 $text,
3406 @styleTags,
3407 );
3408 }
3409  
3410 # (Don't append a newline character for any text piece besides the last one)
3411 if (! @displayList && ($afterFlag || $tempInsertFlag)) {
3412  
3413 if (! $tempInsertFlag) {
3414  
3415 # (Make sure the end of a link appears before the extra newline character, not
3416 # after it)
3417 $iter = $self->insertNewLine($iter);
3418 $self->ivPoke('prevColourStyleHash', $self->colourStyleHash);
3419  
3420 } else {
3421  
3422 $iter = $self->buffer->get_end_iter();
3423 }
3424  
3425 $finalAfterFlag = TRUE;
3426 }
3427  
3428 # (Don't execute this some code blocks more than once)
3429 $firstFlag = FALSE;
3430  
3431 } until (! @displayList);
3432  
3433 if ($self->insertMark) {
3434  
3435 # The next call to $self->insertText, ->insertCmd etc uses the insertion point
3436 # immediately after $iter
3437 $mark = $self->buffer->create_mark('insert_mark', $iter, TRUE);
3438 $self->ivPoke('insertMark', $mark);
3439 # If the cursor is visible, move it to this position (i.e. insert a new Gtk3::TextTag)
3440 $self->moveCursor($self->buffer->get_iter_at_mark($mark));
3441  
3442 } elsif ($tempInsertFlag && ! $finalAfterFlag) {
3443  
3444 # Continue using this temporary insertion point, before a line with a system message
3445 # (and don't restore the cursor yet)
3446 $mark = $self->buffer->create_mark('temp_insert_mark', $iter, TRUE);
3447 $self->ivPoke('tempInsertMark', $mark);
3448  
3449 } else {
3450  
3451 # If the cursor is visible, move it to the end of the buffer (i.e. insert a new
3452 # Gtk3::TextTag)
3453 $self->moveCursor();
3454 }
3455  
3456 # Apply scroll lock, if required
3457 if ($self->scrollLockFlag) {
3458  
3459 if ($self->scrollLockType eq 'top') {
3460 $self->scrollToTop();
3461 } else {
3462 $self->scrollToBottom();
3463 }
3464 }
3465  
3466 return 1;
3467 }
3468  
3469 sub insertWithLinks {
3470  
3471 # Can be called by any code
3472 # When a GA::Session receives text from the world, it automatically searches it for
3473 # anything that looks like a clickable link, and divides the text into segments,
3474 # assigning Axmud style tags as appropriate to make each link clickable
3475 # This function can be called by any non-session code that wants to send a piece of text to
3476 # $self->insertText, and to have any links converted into clickable links automatically
3477 # The calling function specifies some $text. This function splits it into one or more
3478 # segments, and calls $self->insertText for each segment, adding a 'link' tag when the
3479 # whole segment is a clickable link, but otherwise preserving the calling function's
3480 # arguments
3481 #
3482 # Expected arguments
3483 # (none besides $self)
3484 #
3485 # Optional arguments
3486 # $text - The text to write. If undefined, the text <<undef>> is written
3487 # @args - Optional list of arguments, in any order:
3488 # - 'empty' (empties the buffer before writing $text)
3489 # - 'before' (prepends a newline character to $text)
3490 # - 'after' or 'nl' (appends a newline character to $text)
3491 # - 'echo' (does not prepend/append a newline character, overrides
3492 # 'before', 'after' and 'nl' if they are specified)
3493 # - one or more Axmud colour tags. Only the first text colour (e.g. 'red')
3494 # is used, and only the first underlay colour ('UL_RED') is used.
3495 # The range of Axmud colour tags include:
3496 # - standard colour tags like 'red', 'BLUE', 'ul_red', 'UL_BLUE'
3497 # (case-sensititive)
3498 # - xterm colour tags (strings in the range 'x0' to 'x255', or
3499 # 'ux0' to 'ux255'; case-insensitive, so 'X0' is valid)
3500 # - RGB colour tags (strings in the range '#000000' to '#FFFFFF', or
3501 # 'u#000000' to 'u#FFFFFF'; case-insensitive, so 'U#AbCdEf' is
3502 # valid)
3503 # - one or more Axmud style tags ('italics', 'strike', etc. If it includes
3504 # 'link', $text isn't split into segments; we just call
3505 # $self->insertText directly)
3506 #
3507 # Return values
3508 # 'undef' on improper arguments
3509 # Otherwise returns the return value of the final call to $self->insertText
3510  
3511 my ($self, $text, @args) = @_;
3512  
3513 # Local variables
3514 my (
3515 $url, $shortUrl, $longMail, $mail, $result,
3516 @firstArgs, @lastArgs, @otherArgs,
3517 );
3518  
3519 # (No improper arguments to check)
3520  
3521 # Special case - if $text contains no characters, no point searching it for clickable links
3522 if (! $text) {
3523  
3524 return $self->insertText($text, @args);
3525 }
3526  
3527 # Remove 'empty', 'before', 'after', 'nl' and 'echo' from @args temporarily, so they can be
3528 # used in the first/last calls to ->insertText as required
3529 # If @args contains 'link', then the whole of $text is treated as a clickable link and we
3530 # can call ->insertText immediately
3531 foreach my $item (@args) {
3532  
3533 my $flag;
3534  
3535 if ($item eq 'link') {
3536  
3537 return $self->insertText($text, @args);
3538 }
3539  
3540 if ($item eq 'empty' || $item eq 'before' || $item eq 'echo') {
3541  
3542 push (@firstArgs, $item);
3543 $flag = TRUE;
3544 }
3545  
3546 if ($item eq 'after' || $item eq 'nl' || $item eq 'echo') {
3547  
3548 push (@lastArgs, $item);
3549 $flag = TRUE;
3550 }
3551  
3552 if (! $flag) {
3553  
3554 push (@otherArgs, $item);
3555 }
3556 }
3557  
3558 # (Unlike $self->setupLink, it's safe to assume that we have the entire link contained
3559 # within $text)
3560 $url = $axmud::CLIENT->constUrlRegex;
3561 $shortUrl = $axmud::CLIENT->constShortUrlRegex;
3562 $longMail = "mailto\: " . $axmud::CLIENT->constEmailRegex;
3563 $mail = $axmud::CLIENT->constEmailRegex;
3564  
3565 # Now divide $text into one or more segments, and apply the 'link' tag to each segment, or
3566 # not, as required
3567 do {
3568  
3569 my ($segment, $posn, $before);
3570  
3571 # (Check email first, otherwise gmail.com is detected and fred@gmail.com isn't)
3572 if (
3573 $text =~ m/($mail)/
3574 || $text =~ m/($url)/
3575 || $text =~ m/($longMail)/
3576 || ($axmud::CLIENT->shortUrlFlag && $text =~ m/($shortUrl)/)
3577 || $text =~ m/(telnet\:\/\/([^\:\s]+)(\:(\d+))?)/
3578 || $text =~ m/(ssh\:\/\/([^\:\s]+)(\:(\d+))?)/
3579 || $text =~ m/(ssl\:\/\/([^\:\s]+)(\:(\d+))?)/
3580 ) {
3581 $segment = $1;
3582 $posn = $-[1];
3583 }
3584  
3585 if (! $segment) {
3586  
3587 # Nothing in the rest of $text is a link
3588 $result = $self->insertText($text, @firstArgs, @lastArgs, @otherArgs);
3589 $text = '';
3590 # (Items in @firstArgs should only be sent on the first call to ->insertText; after
3591 # that, we make sure everything appears on the same line by specifiying 'echo')
3592 @firstArgs = ('echo');
3593  
3594 } else {
3595  
3596 # Process everything before the matching portion
3597 if ($posn > 0) {
3598  
3599 $result = $self->insertText(substr($text, 0, $posn), @firstArgs, @otherArgs);
3600 @firstArgs = ('echo');
3601 }
3602  
3603 # Process the matching portion as a clickable link
3604 $result = $self->insertText($segment, 'link', @firstArgs, @otherArgs);
3605 @firstArgs = ('echo');
3606  
3607 # Remove everything up to and including the matching portion
3608 $text = substr($text, ($posn + length($segment)));
3609 }
3610  
3611 } until (! $text);
3612  
3613 # The return value is the return value of the most recent call to $self->insertText
3614 return $result;
3615 }
3616  
3617 sub insertQuick {
3618  
3619 # Can be called by any code
3620 # A combination of $self->clearBuffer and ->insertText, intended for task windows and the
3621 # like which want to frequently replace the contents of the textview with a single
3622 # string, and don't need to use Axmud colour/style tags or links (probably because
3623 # $self->monochromeFlag is TRUE or the current colour scheme's ->overrideAllFlag is TRUE)
3624 # Empties the buffer and replaces it with a string, which can contain multiple newline
3625 # characters. No newline characters are prepended/appended by this function
3626 #
3627 # Expected arguments
3628 # (none besides $self)
3629 #
3630 # Optional arguments
3631 # $string - The string to display. If 'undef' (or an empty string), the buffer is simply
3632 # emptied
3633 #
3634 # Return values
3635 # 'undef' on improper arguments
3636 # 1 otherwise
3637  
3638 my ($self, $string, $check) = @_;
3639  
3640 # Check for improper arguments
3641 if (defined $check) {
3642  
3643 return $axmud::CLIENT->writeImproper($self->_objClass . '->insertQuick', @_);
3644 }
3645  
3646 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
3647 $self->removeCursor();
3648  
3649 # Clear the buffer. The TRUE argument means 'don't remove/move the cursor'
3650 $self->clearBuffer(undef, TRUE);
3651 # Fill the empty buffer with text
3652 if ($string) {
3653  
3654 $self->buffer->set_text($string);
3655 }
3656  
3657 # If the cursor is visible, move it to the end of the buffer (i.e. insert a new
3658 # Gtk3::TextTag)
3659 $self->moveCursor();
3660  
3661 # Update IVs
3662 if ($string) {
3663  
3664 $self->ivPoke('bufferTextFlag', TRUE);
3665 $self->ivPoke('sizeUpdateFlag', TRUE);
3666  
3667 if ($string =~ m/\n$/) {
3668  
3669 $self->ivPoke('newLineFlag', TRUE);
3670 $self->ivPoke('insertNewLineFlag', TRUE);
3671  
3672 } else {
3673  
3674 $self->ivPoke('newLineFlag', FALSE);
3675 $self->ivPoke('insertNewLineFlag', FALSE);
3676 }
3677  
3678 } else {
3679  
3680 $self->ivPoke('bufferTextFlag', FALSE);
3681 $self->ivPoke('sizeUpdateFlag', TRUE);
3682 }
3683  
3684 # Scroll the textview to the bottom
3685 $self->scrollToBottom();
3686  
3687 return 1;
3688 }
3689  
3690 sub insertCmd {
3691  
3692 # Called by GA::Session->dispatchCmd and ->dispatchPassword when this textview object is
3693 # the session's default textview object
3694 # Inserts text into the Gtk3::TextBuffer to show the world command/password, using a
3695 # standard colour
3696 # NB This function doesn't write to any log files; the calling function does that
3697 #
3698 # Expected arguments
3699 # $cmd - The command to show. When GA::Session->dispatchCmd/->dispatchPassword
3700 # need to cancel a prompt, an empty string. A newline character is
3701 # automatically appended in both cases
3702 #
3703 # Return values
3704 # 'undef' on improper arguments
3705 # 1 otherwise
3706  
3707 my ($self, $cmd, $check) = @_;
3708  
3709 # Local variables
3710 my (
3711 $colourSchemeObj, $monochromeFlag, $textColour, $mark, $noNewLineFlag, $iter, $endIter,
3712 $endLine,
3713 );
3714  
3715 # Check for improper arguments
3716 if (! defined $cmd || defined $check) {
3717  
3718 return $axmud::CLIENT->writeImproper($self->_objClass . '->insertCmd', @_);
3719 }
3720  
3721 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
3722 $self->removeCursor();
3723 # If the buffer is due to be cleared before inserting any text, then clear it
3724 if ($self->clearAfterInsertFlag) {
3725  
3726 # The TRUE argument means 'don't remove/move the cursor'
3727 $self->clearBuffer(undef, TRUE);
3728 }
3729  
3730 # Import the colour scheme in use
3731 $colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme);
3732 # Choose which colour tags to use (in monochrome mode, text/underlay colours are ignored,
3733 # but in this case we don't any apply overrides specified by the colour scheme)
3734 if ($self->monochromeFlag || ($colourSchemeObj && $colourSchemeObj->overrideAllFlag)) {
3735 $monochromeFlag = TRUE;
3736 } else {
3737 $textColour = $axmud::CLIENT->customInsertCmdColour;
3738 }
3739  
3740 # Set the insertion point
3741 if ($self->insertMark) {
3742  
3743 $mark = $self->insertMark;
3744  
3745 } elsif ($self->tempInsertMark) {
3746  
3747 $mark = $self->tempInsertMark;
3748 # This code prevents a blank line being inserted between a world's prompt and the
3749 # already-displayed Axmud system message
3750 $self->ivUndef('tempInsertMark');
3751 $noNewLineFlag = TRUE;
3752 }
3753  
3754 if ($mark) {
3755 $iter = $self->buffer->get_iter_at_mark($mark);
3756 } elsif (! $self->systemInsertMark) {
3757 $iter = $self->buffer->get_end_iter();
3758 } else {
3759  
3760 # Incomplete system message after a call to $self->showSystemText without a newline
3761 # character. Must insert an artificial newline character, and display $text after
3762 # that
3763 $iter = $self->buffer->get_iter_at_mark($self->systemInsertMark);
3764 $iter = $self->insertNewLine($iter);
3765 }
3766  
3767 # Insert the text into the Gtk3::TextBuffer
3768 if ($cmd ne '') {
3769  
3770 if ($monochromeFlag) {
3771 $iter = $self->insertWithTags($iter, $cmd);
3772 } else {
3773 $iter = $self->insertWithTags($iter, $cmd, $textColour);
3774 }
3775 }
3776  
3777 # In overwrite mode, don't insert a newline character on the bottom line
3778 if (! $noNewLineFlag && $self->overwriteFlag) {
3779  
3780 $endIter = $self->buffer->get_end_iter();
3781 $endLine = $endIter->get_line();
3782  
3783 if ($endLine == $iter->get_line() && $endLine == ($self->textHeightChars - 1)) {
3784  
3785 $noNewLineFlag = TRUE;
3786  
3787 # Remove any text between the end of the world command, and the end of the buffer
3788 # (so that the previous world command, if longer than this one, is no longer
3789 # visible)
3790 if ($endIter->get_visible_line_offset() > $iter->get_visible_line_offset()) {
3791  
3792 $self->buffer->delete($iter, $endIter);
3793 }
3794  
3795 # Move the insertion point back to the beginning of the line, so the next world
3796 # command overwrites this one
3797 $iter = $self->buffer->get_iter_at_line_offset($endLine, 0);
3798 }
3799 }
3800  
3801 if (! $noNewLineFlag) {
3802  
3803 $iter = $self->insertNewLine($iter);
3804 }
3805  
3806 if ($self->insertMark) {
3807  
3808 # The next call to $self->insertText, ->insertCmd etc uses the insertion point
3809 # immediately after $iter
3810 $mark = $self->buffer->create_mark('insert_mark', $iter, TRUE);
3811 $self->ivPoke('insertMark', $mark);
3812 # If the cursor is visible, move it to this position (i.e. insert a new Gtk3::TextTag)
3813 $self->moveCursor($self->buffer->get_iter_at_mark($mark));
3814  
3815 } else {
3816  
3817 # If the cursor is visible, move it to the end of the buffer (i.e. insert a new
3818 # Gtk3::TextTag)
3819 $self->moveCursor();
3820 }
3821  
3822 if ($self->scrollLockFlag) {
3823  
3824 if ($self->scrollLockType eq 'top') {
3825 $self->scrollToTop();
3826 } else {
3827 $self->scrollToBottom();
3828 }
3829 }
3830  
3831 return 1;
3832 }
3833  
3834 sub showSystemText {
3835  
3836 # Called by Games::Axmud->writeText
3837 # Inserts system text into the Gtk3::TextBuffer, optionally applying Axmud colour/style tags
3838 # and/or newline characters, and optionally emptying the buffer of text
3839 # Optionally updates the System task's window
3840 #
3841 # Expected arguments
3842 # (none besides $self)
3843 #
3844 # Optional arguments
3845 # $text - The system text to write. If undefined, the text <<undef>> is written
3846 # @args - List of arguments, in any order:
3847 # - 'empty' (empties the buffer before writing $text)
3848 # - 'before' (prepends a newline character to $text)
3849 # - 'after' or 'nl' (appends a newline character to $text)
3850 # - 'echo' (does not prepend/append a newline character, overrides
3851 # 'before', 'after' and 'nl' if they are specified)
3852 # - one or more Axmud colour tags. Only the first text colour (e.g. 'red')
3853 # is used, and only the first underlay colour ('UL_RED') is used.
3854 # The range of Axmud colour tags include:
3855 # - standard colour tags like 'red', 'BLUE', 'ul_red', 'UL_BLUE'
3856 # (case-sensititive)
3857 # - xterm colour tags (strings in the range 'x0' to 'x255', or
3858 # 'ux0' to 'ux255'; case-insensitive, so 'X0' is valid)
3859 # - RGB colour tags (strings in the range '#000000' to '#FFFFFF', or
3860 # 'u#000000' to 'u#FFFFFF'; case-insensitive, so 'U#AbCdEf' is
3861 # valid)
3862 # - one or more Axmud style tags ('italics', 'strike', etc)
3863 #
3864 # Notes
3865 # If both 'nl'/'after' and 'echo' are specified (or if neither is specified), a newline
3866 # character IS appended
3867 #
3868 # Return values
3869 # 1
3870  
3871 my ($self, $text, @args) = @_;
3872  
3873 # Local variables
3874 my (
3875 $emptyFlag, $beforeFlag, $afterFlag, $linkFlag, $textColour, $underlayColour,
3876 $systemTask, $hereFlag, $taskFlag, $consoleFlag, $colourSchemeObj, $monochromeFlag,
3877 $modText, $beep, $iter,
3878 @styleTags, @modArgs,
3879 );
3880  
3881 # (No improper arguments to check)
3882  
3883 # Interpret the list of @args
3884 ($emptyFlag, $beforeFlag, $afterFlag, $linkFlag, $textColour, $underlayColour, @styleTags)
3885 = $self->interpretTags('after', @args);
3886  
3887 # Import the colour scheme in use
3888 $colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme);
3889 # Choose which colour tags to use (in monochrome mode, text/underlay colours are ignored,
3890 # but in this case we don't any apply overrides specified by the colour scheme)
3891 if ($self->monochromeFlag || ($colourSchemeObj && $colourSchemeObj->overrideAllFlag)) {
3892  
3893 $monochromeFlag = TRUE;
3894  
3895 } else {
3896  
3897 if (! $textColour) {
3898  
3899 $textColour = $axmud::CLIENT->customShowSystemTextColour;
3900 }
3901  
3902 if (! $underlayColour) {
3903  
3904 $underlayColour = $self->underlayColour;
3905 }
3906 }
3907  
3908 # Whether the message is written only in this textview (mode 'original'), or in both this
3909 # textview and the System task's window ('both'), or in the System task's window only
3910 # (mode 'task'), depends on the System task's IVs (if the task is running)
3911 $systemTask = $self->session->systemTask;
3912 if (! $systemTask) {
3913  
3914 $hereFlag = TRUE;
3915  
3916 } else {
3917  
3918 if ($systemTask->systemMode eq 'original') {
3919  
3920 $hereFlag = TRUE;
3921  
3922 } elsif ($systemTask->systemMode eq 'both') {
3923  
3924 $hereFlag = TRUE;
3925 $taskFlag = TRUE;
3926  
3927 } else {
3928  
3929 $taskFlag = TRUE;
3930 }
3931 }
3932  
3933 # If not allowed to write a system message in this textview, write to the Session Console
3934 # window instead
3935 if (
3936 $hereFlag
3937 && (! $axmud::CLIENT->mainWinSystemMsgFlag || $self->overwriteFlag)
3938 ) {
3939 $hereFlag = FALSE;
3940 $consoleFlag = TRUE;
3941 }
3942  
3943 # Empty the buffer before writing text, if required (but not in the System task window or in
3944 # the Session console window)
3945 if ($emptyFlag && $hereFlag) {
3946  
3947 # The TRUE argument means 'don't remove/move the cursor'
3948 $self->clearBuffer(undef, TRUE);
3949 }
3950  
3951 # Prepare the message to send
3952 $modText = $text;
3953 if (! defined $modText) {
3954  
3955 # 'undef' is a valid value - represent it
3956 $modText = "<<undef>>";
3957 }
3958  
3959 # If $text/$modText contains any ASCII 7 characters (bells), filter them out
3960 $beep = chr(7);
3961 $modText =~ s/$beep//g;
3962 if ($text) {
3963  
3964 $text =~ s/$beep//g;
3965 }
3966  
3967 if ($hereFlag) {
3968  
3969 # If the last piece of text inserted at the Gtk3::TextBuffer via a call to
3970 # $self->insertText didn't end in a newline character, we need to insert an artifical
3971 # newline character so the system message appears on its own line, at the end of the
3972 # buffer
3973 if (
3974 # Last character in the buffer isn't a newline character
3975 ! $self->newLineFlag
3976 # The insertion point for $self->insertText and ->insertCmd is the end of the buffer
3977 && ! $self->insertMark
3978 # The call to this function wasn't preceded by another call to this function which
3979 # didn't use a newline character
3980 && ! $self->systemInsertMark
3981 ) {
3982 $iter = $self->buffer->get_end_iter();
3983 $self->ivPoke(
3984 'tempInsertMark',
3985 $self->buffer->create_mark('temp_insert_mark', $iter, TRUE),
3986 );
3987  
3988 $beforeFlag = TRUE;
3989 }
3990  
3991 # If the cursor is visible, remove it temporarily (i.e. remove the existing
3992 # Gtk3::TextTag)
3993 $self->removeCursor();
3994 # If the buffer is due to be cleared before inserting any text, then clear it
3995 if ($self->clearAfterInsertFlag) {
3996  
3997 # The TRUE argument means 'don't remove/move the cursor'
3998 $self->clearBuffer(undef, TRUE);
3999 }
4000  
4001 # Set the insertion point
4002 if ($self->systemInsertMark) {
4003 $iter = $self->buffer->get_iter_at_mark($self->systemInsertMark);
4004 } else {
4005 $iter = $self->buffer->get_end_iter();
4006 }
4007  
4008 # Insert a newline character into the Gtk3::TextBuffer
4009 if ($beforeFlag) {
4010  
4011 # (Make sure the beginning of a link appears after the extra newline character, not
4012 # before it)
4013 $iter = $self->insertNewLine($iter);
4014 }
4015  
4016 # Create a link object, if required
4017 if ($linkFlag && $modText) {
4018  
4019 # Create a link object, if required
4020 $self->setupLink($iter, $modText);
4021 }
4022  
4023 # Insert the text into the Gtk3::TextBuffer
4024 if ($monochromeFlag) {
4025  
4026 $iter = $self->insertWithTags(
4027 $iter,
4028 $modText,
4029 @styleTags,
4030 );
4031  
4032 } else {
4033  
4034 $iter = $self->insertWithTags(
4035 $iter,
4036 $modText,
4037 $textColour,
4038 $underlayColour,
4039 @styleTags,
4040 );
4041 }
4042  
4043 if ($afterFlag) {
4044  
4045 # (Make sure the end of a link appears before the extra newline character, not
4046 # after it)
4047 $self->insertNewLine($iter);
4048 $self->ivUndef('systemInsertMark');
4049  
4050 # Restore the cursor
4051 if ($self->tempInsertMark) {
4052 $self->moveCursor($self->buffer->get_iter_at_mark($self->tempInsertMark));
4053 } else {
4054 $self->replaceCursor();
4055 }
4056  
4057 } else {
4058  
4059 # (System message in the next call to this function is appended to this system
4060 # message, which didn't end with a newline character)
4061 $self->ivPoke(
4062 'systemInsertMark',
4063 $self->buffer->create_mark('system_insert_mark', $iter, TRUE),
4064 );
4065  
4066 # (Don't restore the cursor until the complete line is displayed)
4067 }
4068  
4069 if ($self->scrollLockFlag) {
4070  
4071 if ($self->scrollLockType eq 'top') {
4072 $self->scrollToTop();
4073 } else {
4074 $self->scrollToBottom();
4075 }
4076 }
4077 }
4078  
4079 if (defined $text && $text ne '') {
4080  
4081 if ($taskFlag) {
4082  
4083 # Write the message in the System task window, but remove an 'empty' argument if one
4084 # was specified for the 'main' window
4085 foreach my $item (@args) {
4086  
4087 if ($item ne 'empty') {
4088  
4089 push (@modArgs, $item);
4090 }
4091 }
4092  
4093 $self->session->systemTask->showSystemText($text, @modArgs);
4094 }
4095  
4096 if ($consoleFlag) {
4097  
4098 # Send the message to the GA::Session, for display (now or later) in the Session
4099 # Console window
4100 $self->session->add_systemMsg('system', $text);
4101 }
4102  
4103 # Write to logs and convert text-to-speech, if required
4104 # Only a complete line (ending in a newline character) is written to logs and/or
4105 # converted to text-to-speech; until then, a partial system message is stored in a
4106 # buffer
4107 if (! $self->systemTextBuffer) {
4108 $self->ivPoke('systemTextBuffer', $text);
4109 } else {
4110 $self->ivPoke('systemTextBuffer', $self->systemTextBuffer . $text);
4111 }
4112 }
4113  
4114 if (($beforeFlag || $afterFlag) && $self->systemTextBuffer) {
4115  
4116 # Write to logs
4117 $axmud::CLIENT->writeLog(
4118 $self->session,
4119 TRUE, # Not world-specific logs
4120 $self->systemTextBuffer,
4121 $beforeFlag,
4122 $afterFlag,
4123 'main', 'system', # Write to these files
4124 );
4125  
4126 # Convert text-to-speech, if required (but don't try to convert an 'undef' or text
4127 # containing no readable characters)
4128 if (
4129 $axmud::CLIENT->systemAllowTTSFlag
4130 && $axmud::CLIENT->ttsSystemFlag
4131 && defined $self->systemTextBuffer
4132 && $self->systemTextBuffer =~ m/\w/
4133 # Also, temporarily don't convert system messages if the GA::Session flag is set
4134 && ! $self->session->ttsTempDisableFlag
4135 ) {
4136 # Make sure the received text is visible in the textview(s)...
4137 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showSystemText');
4138  
4139 # ...before converting text to speech
4140 if (
4141 defined $self->session->ttsLastType
4142 && $self->session->ttsLastType eq 'system'
4143 ) {
4144 # (Don't read out 'system message' again and again and again!
4145 $axmud::CLIENT->tts(
4146 $self->systemTextBuffer,
4147 'system',
4148 'system',
4149 $self->session,
4150 );
4151  
4152 } else {
4153  
4154 # Last TTS conversion was something other than a system message
4155 $axmud::CLIENT->tts(
4156 'System message: ' . $self->systemTextBuffer,
4157 'system',
4158 'system',
4159 $self->session,
4160 );
4161 }
4162 }
4163  
4164 # Fire any hooks that are using the system hook events
4165 $self->session->checkHooks('system_text', $self->systemTextBuffer);
4166 $self->session->checkHooks('system_all', $self->systemTextBuffer);
4167  
4168 $self->ivUndef('systemTextBuffer');
4169 }
4170  
4171 # This type of system message always requires a return value of 1
4172 return 1;
4173 }
4174  
4175 sub showError {
4176  
4177 # Called by Games::Axmud->writeError
4178 # Inserts a system error message into the Gtk3::TextBuffer and/or updates the System task's
4179 # window
4180 #
4181 # Expected arguments
4182 # (none besides $self)
4183 #
4184 # Optional arguments
4185 # $text - The system text to write. If undefined, the text <<undef>> is written
4186 # $func - The function that produced the error (e.g.
4187 # 'Games::Axmud::Client->helloWorld'). If 'undef', the function is not
4188 # displayed
4189 #
4190 # Return values
4191 # 'undef'
4192  
4193 my ($self, $text, $func, $check) = @_;
4194  
4195 # Local variables
4196 my (
4197 $colourSchemeObj, $monochromeFlag, $textColour, $msg, $systemTask, $hereFlag, $taskFlag,
4198 $consoleFlag, $iter, $beforeFlag,
4199 );
4200  
4201 # Check for improper arguments
4202 if (defined $check) {
4203  
4204 return $axmud::CLIENT->writeImproper($self->_objClass . '->showError', @_);
4205 }
4206  
4207 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
4208 $self->removeCursor();
4209 # If the buffer is due to be cleared before inserting any text, then clear it
4210 if ($self->clearAfterInsertFlag) {
4211  
4212 # The TRUE argument means 'don't remove/move the cursor'
4213 $self->clearBuffer(undef, TRUE);
4214 }
4215  
4216 # Import the colour scheme in use
4217 $colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme);
4218 # Choose which colour tags to use (in monochrome mode, text/underlay colours are ignored,
4219 # but in this case we don't any apply overrides specified by the colour scheme)
4220 if ($self->monochromeFlag || ($colourSchemeObj && $colourSchemeObj->overrideAllFlag)) {
4221 $monochromeFlag = TRUE;
4222 } else {
4223 $textColour = $axmud::CLIENT->customShowErrorColour;
4224 }
4225  
4226 # Call to ->writeLog requires a TRUE/FALSE value
4227 $beforeFlag = FALSE;
4228  
4229 # Prepare the message to send
4230 if (! defined $text) {
4231  
4232 # 'undef' is a valid value - represent it
4233 $text = "<<undef>>";
4234 }
4235  
4236 if ($func) {
4237 $msg = "ERROR: $func: $text";
4238 } else {
4239 $msg = "ERROR: $text";
4240 }
4241  
4242 # Whether the message is written only in this textview (mode 'original'), or in both this
4243 # textview and the System task's window ('both'), or in the System task's window only
4244 # (mode 'task'), depends on the System task's IVs (if the task is running)
4245 $systemTask = $self->session->systemTask;
4246 if (! $systemTask) {
4247  
4248 $hereFlag = TRUE;
4249  
4250 } else {
4251  
4252 if ($systemTask->errorMode eq 'original') {
4253  
4254 $hereFlag = TRUE;
4255  
4256 } elsif ($systemTask->errorMode eq 'both') {
4257  
4258 $hereFlag = TRUE;
4259 $taskFlag = TRUE;
4260  
4261 } else {
4262  
4263 $taskFlag = TRUE;
4264 }
4265 }
4266  
4267 # If not allowed to write a system message in this textview, write to the Session Console
4268 # window instead
4269 if (
4270 $hereFlag
4271 && (! $axmud::CLIENT->mainWinSystemMsgFlag || $self->overwriteFlag)
4272 ) {
4273 $hereFlag = FALSE;
4274 $consoleFlag = TRUE;
4275 }
4276  
4277 if ($hereFlag) {
4278  
4279 # If the previous call to $self->showSystemText displayed a message that didn't end in a
4280 # newline character, $self->systemInsertMark is set
4281 # In that case, we must insert an artificial newline character, so this system message
4282 # is displayed on its own line
4283 if ($self->systemInsertMark) {
4284  
4285 $iter = $self->buffer->get_iter_at_mark($self->systemInsertMark);
4286 $iter = $self->insertNewLine($iter);
4287 $self->ivUndef('systemInsertMark');
4288  
4289 # If the last piece of text inserted at the Gtk3::TextBuffer via a call to
4290 # $self->insertText didn't end in a newline character, we need to insert an artifical
4291 # newline character so the system message appears on its own line, at the end of the
4292 # buffer
4293 } elsif (
4294 # Last character in the buffer isn't a newline character
4295 ! $self->newLineFlag
4296 # The insertion point for $self->insertText and ->insertCmd is the end of the buffer
4297 && ! $self->insertMark
4298 ) {
4299 $iter = $self->buffer->get_end_iter();
4300 $self->ivPoke(
4301 'tempInsertMark',
4302 $self->buffer->create_mark('temp_insert_mark', $iter, TRUE),
4303 );
4304  
4305 $beforeFlag = TRUE;
4306 }
4307  
4308 # If the cursor is visible, remove it temporarily (i.e. remove the existing
4309 # Gtk3::TextTag)
4310 $self->removeCursor();
4311 # If the buffer is due to be cleared before inserting any text, then clear it
4312 if ($self->clearAfterInsertFlag) {
4313  
4314 # The TRUE argument means 'don't remove/move the cursor'
4315 $self->clearBuffer(undef, TRUE);
4316 }
4317  
4318 # Set the insertion point
4319 $iter = $self->buffer->get_end_iter();
4320  
4321 # Insert the text into the Gtk3::TextBuffer
4322 if ($beforeFlag) {
4323  
4324 # (Make sure the beginning of a link appears after the artificially-inserted newline
4325 # character, not before it)
4326 $iter = $self->insertNewLine($iter);
4327 }
4328  
4329 if ($monochromeFlag) {
4330 $iter = $self->insertWithTags($iter, $msg);
4331 } else {
4332 $iter = $self->insertWithTags($iter, $msg, $textColour);
4333 }
4334  
4335 $self->insertNewLine($iter);
4336  
4337 # Restore the cursor
4338 if ($self->tempInsertMark) {
4339 $self->moveCursor($self->buffer->get_iter_at_mark($self->tempInsertMark));
4340 } else {
4341 $self->replaceCursor();
4342 }
4343  
4344 if ($self->scrollLockFlag) {
4345  
4346 if ($self->scrollLockType eq 'top') {
4347 $self->scrollToTop();
4348 } else {
4349 $self->scrollToBottom();
4350 }
4351 }
4352 }
4353  
4354 if (defined $msg && $msg ne '') {
4355  
4356 if ($taskFlag) {
4357  
4358 # Write the message in the System task window
4359 $self->session->systemTask->showError($msg);
4360 }
4361  
4362 if ($consoleFlag) {
4363  
4364 # Send the message to the GA::Session, for display (now or later) in the Session
4365 # Console window
4366 $self->session->add_systemMsg('error', $msg);
4367 }
4368  
4369 # Write to logs
4370 $axmud::CLIENT->writeLog(
4371 $self->session,
4372 TRUE, # Not world-specific logs
4373 $msg,
4374 $beforeFlag,
4375 TRUE, # Use final newline character
4376 'main', 'errors', 'error', # Write to these files
4377 );
4378  
4379 # Fire any hooks that are using the system hook events
4380 $self->session->checkHooks('system_error', $msg);
4381 $self->session->checkHooks('system_all', $msg);
4382 $self->session->checkHooks('system_all_error', $msg);
4383 }
4384  
4385 # Play a sound effect (if allowed, and if this textview object hasn't played the same
4386 # sound effect recently)
4387 if (! $self->soundCheckTime || $self->soundCheckTime < $axmud::CLIENT->clientTime) {
4388  
4389 $axmud::CLIENT->playSound('error');
4390 # Don't play it again for a few seconds
4391 $self->ivPoke('soundCheckTime', ($axmud::CLIENT->clientTime + $self->soundDelayTime));
4392 }
4393  
4394 # Convert text-to-speech, if required (but don't try to convert an 'undef' or text
4395 # containing no readable characters)
4396 if (
4397 $axmud::CLIENT->systemAllowTTSFlag
4398 && $axmud::CLIENT->ttsSystemFlag
4399 && defined $text
4400 && $text =~ m/\w/
4401 # Also, temporarily don't convert system messages if the GA::Session flag is set
4402 && ! $self->session->ttsTempDisableFlag
4403 ) {
4404 # Make sure the received text is visible in the textview(s)...
4405 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showError');
4406  
4407 # ...before converting text to speech
4408 if (defined $self->session->ttsLastType && $self->session->ttsLastType eq 'error') {
4409  
4410 # (Don't read out 'system error' again and again and again!
4411 $axmud::CLIENT->tts($text, 'error', 'error', $self->session);
4412  
4413 } else {
4414  
4415 # Last TTS conversion was something other than a system error (etc) message
4416 $axmud::CLIENT->tts('System error: ' . $text, 'error', 'error', $self->session);
4417 }
4418 }
4419  
4420 # This type of system message always requires a return value of 'undef'
4421 return undef;
4422 }
4423  
4424 sub showWarning {
4425  
4426 # Called by Games::Axmud->writeWarning
4427 # Inserts a system warning message into the Gtk3::TextBuffer and/or updates the System
4428 # task's window
4429 #
4430 # Expected arguments
4431 # (none besides $self)
4432 #
4433 # Optional arguments
4434 # $text - The system text to write. If undefined, the text <<undef>> is written
4435 # $func - The function that produced the warning (e.g.
4436 # 'Games::Axmud::Client->helloWorld'). If 'undef', the function is not
4437 # displayed
4438 #
4439 # Return values
4440 # 'undef'
4441  
4442 my ($self, $text, $func, $check) = @_;
4443  
4444 # Local variables
4445 my (
4446 $colourSchemeObj, $monochromeFlag, $textColour, $msg, $systemTask, $hereFlag, $taskFlag,
4447 $consoleFlag, $iter, $beforeFlag,
4448 );
4449  
4450 # Check for improper arguments
4451 if (defined $check) {
4452  
4453 return $axmud::CLIENT->writeImproper($self->_objClass . '->showWarning', @_);
4454 }
4455  
4456 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
4457 $self->removeCursor();
4458 # If the buffer is due to be cleared before inserting any text, then clear it
4459 if ($self->clearAfterInsertFlag) {
4460  
4461 # The TRUE argument means 'don't remove/move the cursor'
4462 $self->clearBuffer(undef, TRUE);
4463 }
4464  
4465 # Import the colour scheme in use
4466 $colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme);
4467 # Choose which colour tags to use (in monochrome mode, text/underlay colours are ignored,
4468 # but in this case we don't any apply overrides specified by the colour scheme)
4469 if ($self->monochromeFlag || ($colourSchemeObj && $colourSchemeObj->overrideAllFlag)) {
4470 $monochromeFlag = TRUE;
4471 } else {
4472 $textColour = $axmud::CLIENT->customShowWarningColour;
4473 }
4474  
4475 # Call to ->writeLog requires a TRUE/FALSE value
4476 $beforeFlag = FALSE;
4477  
4478 # Prepare the message to send
4479 if (! defined $text) {
4480  
4481 # 'undef' is a valid value - represent it
4482 $text = "<<undef>>";
4483 }
4484  
4485 if ($func) {
4486 $msg = "WARNING: $func: $text";
4487 } else {
4488 $msg = "WARNING: $text";
4489 }
4490  
4491 # Whether the message is written only in this textview (mode 'original'), or in both this
4492 # textview and the System task's window ('both'), or in the System task's window only
4493 # (mode 'task'), depends on the System task's IVs (if the task is running)
4494 $systemTask = $self->session->systemTask;
4495 if (! $systemTask) {
4496  
4497 $hereFlag = TRUE;
4498  
4499 } else {
4500  
4501 if ($systemTask->warningMode eq 'original') {
4502  
4503 $hereFlag = TRUE;
4504  
4505 } elsif ($systemTask->warningMode eq 'both') {
4506  
4507 $hereFlag = TRUE;
4508 $taskFlag = TRUE;
4509  
4510 } else {
4511  
4512 $taskFlag = TRUE;
4513 }
4514 }
4515  
4516 # If not allowed to write a system message in this textview, write to the Session Console
4517 # window instead
4518 if (
4519 $hereFlag
4520 && (! $axmud::CLIENT->mainWinSystemMsgFlag || $self->overwriteFlag)
4521 ) {
4522 $hereFlag = FALSE;
4523 $consoleFlag = TRUE;
4524 }
4525  
4526 if ($hereFlag) {
4527  
4528 # If the previous call to $self->showSystemText displayed a message that didn't end in a
4529 # newline character, $self->systemInsertMark is set
4530 # In that case, we must insert an artificial newline character, so this system message
4531 # is displayed on its own line
4532 if ($self->systemInsertMark) {
4533  
4534 $iter = $self->buffer->get_iter_at_mark($self->systemInsertMark);
4535 $iter = $self->insertNewLine($iter);
4536 $self->ivUndef('systemInsertMark');
4537  
4538 # If the last piece of text inserted at the Gtk3::TextBuffer via a call to
4539 # $self->insertText didn't end in a newline character, we need to insert an artifical
4540 # newline character so the system message appears on its own line, at the end of the
4541 # buffer
4542 } elsif (
4543 # Last character in the buffer isn't a newline character
4544 ! $self->newLineFlag
4545 # The insertion point for $self->insertText and ->insertCmd is the end of the buffer
4546 && ! $self->insertMark
4547 ) {
4548 $iter = $self->buffer->get_end_iter();
4549 $self->ivPoke(
4550 'tempInsertMark',
4551 $self->buffer->create_mark('temp_insert_mark', $iter, TRUE),
4552 );
4553  
4554 $beforeFlag = TRUE;
4555 }
4556  
4557 # If the cursor is visible, remove it temporarily (i.e. remove the existing
4558 # Gtk3::TextTag)
4559 $self->removeCursor();
4560 # If the buffer is due to be cleared before inserting any text, then clear it
4561 if ($self->clearAfterInsertFlag) {
4562  
4563 # The TRUE argument means 'don't remove/move the cursor'
4564 $self->clearBuffer(undef, TRUE);
4565 }
4566  
4567 # Set the insertion point
4568 $iter = $self->buffer->get_end_iter();
4569  
4570 # Insert the text into the Gtk3::TextBuffer
4571 if ($beforeFlag) {
4572  
4573 # (Make sure the beginning of a link appears after the artificially-inserted newline
4574 # character, not before it)
4575 $iter = $self->insertNewLine($iter);
4576 }
4577  
4578 if ($monochromeFlag) {
4579 $iter = $self->insertWithTags($iter, $msg);
4580 } else {
4581 $iter = $self->insertWithTags($iter, $msg, $textColour);
4582 }
4583  
4584 $self->insertNewLine($iter);
4585  
4586 # Restore the cursor
4587 if ($self->tempInsertMark) {
4588 $self->moveCursor($self->buffer->get_iter_at_mark($self->tempInsertMark));
4589 } else {
4590 $self->replaceCursor();
4591 }
4592  
4593 if ($self->scrollLockFlag) {
4594  
4595 if ($self->scrollLockType eq 'top') {
4596 $self->scrollToTop();
4597 } else {
4598 $self->scrollToBottom();
4599 }
4600 }
4601 }
4602  
4603 if (defined $msg && $msg ne '') {
4604  
4605 if ($taskFlag) {
4606  
4607 # Write the message in the System task window
4608 $self->session->systemTask->showWarning($msg);
4609 }
4610  
4611 if ($consoleFlag) {
4612  
4613 # Send the message to the GA::Session, for display (now or later) in the Session
4614 # Console window
4615 $self->session->add_systemMsg('warning', $msg);
4616 }
4617  
4618 # Write to logs
4619 $axmud::CLIENT->writeLog(
4620 $self->session,
4621 TRUE, # Not world-specific logs
4622 $msg,
4623 $beforeFlag,
4624 TRUE, # Use final newline character
4625 'main', 'errors', 'warning', # Write to these files
4626 );
4627  
4628 # Fire any hooks that are using the system hook events
4629 $self->session->checkHooks('system_warning', $msg);
4630 $self->session->checkHooks('system_all', $msg);
4631 $self->session->checkHooks('system_all_error', $msg);
4632 }
4633  
4634 # Play a sound effect (if allowed, and if this textview object hasn't played the same
4635 # sound effect recently)
4636 if (! $self->soundCheckTime || $self->soundCheckTime < $axmud::CLIENT->clientTime) {
4637  
4638 $axmud::CLIENT->playSound('error');
4639 # Don't play it again for a few seconds
4640 $self->ivPoke('soundCheckTime', ($axmud::CLIENT->clientTime + $self->soundDelayTime));
4641 }
4642  
4643 # Convert text-to-speech, if required (but don't try to convert an 'undef' or text
4644 # containing no readable characters)
4645 if (
4646 $axmud::CLIENT->systemAllowTTSFlag
4647 && $axmud::CLIENT->ttsSystemFlag
4648 && defined $text
4649 && $text =~ m/\w/
4650 # Also, temporarily don't convert system messages if the GA::Session flag is set
4651 && ! $self->session->ttsTempDisableFlag
4652 ) {
4653 # Make sure the received text is visible in the textview(s)...
4654 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showWarning');
4655  
4656 # ...before converting text to speech
4657 if (defined $self->session->ttsLastType && $self->session->ttsLastType eq 'error') {
4658  
4659 # (Don't read out 'system warning' again and again and again!
4660 $axmud::CLIENT->tts($text, 'error', 'error', $self->session);
4661  
4662 } else {
4663  
4664 # Last TTS conversion was something other than a system error (etc) message
4665 $axmud::CLIENT->tts('System warning: ' . $text, 'error', 'error', $self->session);
4666 }
4667 }
4668  
4669 # This type of system message always requires a return value of 'undef'
4670 return undef;
4671 }
4672  
4673 sub showDebug {
4674  
4675 # Called by Games::Axmud->writeDebug or ->wd
4676 # Inserts a system debug message into the Gtk3::TextBuffer and/or updates the System task's
4677 # window
4678 #
4679 # Expected arguments
4680 # (none besides $self)
4681 #
4682 # Optional arguments
4683 # $text - The system text to write. If undefined, the text <<undef>> is written
4684 # $func - The function that produced the debug message (e.g.
4685 # 'Games::Axmud::Client->helloWorld'). If 'undef', the function is not
4686 # displayed
4687 #
4688 # Return values
4689 # 'undef'
4690  
4691 my ($self, $text, $func, $check) = @_;
4692  
4693 # Local variables
4694 my (
4695 $colourSchemeObj, $monochromeFlag, $textColour, $msg, $systemTask, $hereFlag, $taskFlag,
4696 $consoleFlag, $iter, $beforeFlag,
4697 );
4698  
4699 # Check for improper arguments
4700 if (defined $check) {
4701  
4702 return $axmud::CLIENT->writeImproper($self->_objClass . '->showDebug', @_);
4703 }
4704  
4705 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
4706 $self->removeCursor();
4707 # If the buffer is due to be cleared before inserting any text, then clear it
4708 if ($self->clearAfterInsertFlag) {
4709  
4710 # The TRUE argument means 'don't remove/move the cursor'
4711 $self->clearBuffer(undef, TRUE);
4712 }
4713  
4714 # Import the colour scheme in use
4715 $colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme);
4716 # Choose which colour tags to use (in monochrome mode, text/underlay colours are ignored,
4717 # but in this case we don't any apply overrides specified by the colour scheme)
4718 if ($self->monochromeFlag || ($colourSchemeObj && $colourSchemeObj->overrideAllFlag)) {
4719 $monochromeFlag = TRUE;
4720 } else {
4721 $textColour = $axmud::CLIENT->customShowDebugColour;
4722 }
4723  
4724 # Call to ->writeLog requires a TRUE/FALSE value
4725 $beforeFlag = FALSE;
4726  
4727 # Prepare the message to send
4728 if (! defined $text) {
4729  
4730 # 'undef' is a valid value - represent it
4731 $text = "<<undef>>";
4732 }
4733  
4734 if ($func) {
4735 $msg = "DEBUG: $func: $text";
4736 } else {
4737 $msg = "DEBUG: $text";
4738 }
4739  
4740 # Whether the message is written only in this textview (mode 'original'), or in both this
4741 # textview and the System task's window ('both'), or in the System task's window only
4742 # (mode 'task'), depends on the System task's IVs (if the task is running)
4743 $systemTask = $self->session->systemTask;
4744 if (! $systemTask) {
4745  
4746 $hereFlag = TRUE;
4747  
4748 } else {
4749  
4750 if ($systemTask->debugMode eq 'original') {
4751  
4752 $hereFlag = TRUE;
4753  
4754 } elsif ($systemTask->debugMode eq 'both') {
4755  
4756 $hereFlag = TRUE;
4757 $taskFlag = TRUE;
4758  
4759 } else {
4760  
4761 $taskFlag = TRUE;
4762 }
4763 }
4764  
4765 # If not allowed to write a system message in this textview, write to the Session Console
4766 # window instead
4767 if (
4768 $hereFlag
4769 && (! $axmud::CLIENT->mainWinSystemMsgFlag || $self->overwriteFlag)
4770 ) {
4771 $hereFlag = FALSE;
4772 $consoleFlag = TRUE;
4773 }
4774  
4775 if ($hereFlag) {
4776  
4777 # If the previous call to $self->showSystemText displayed a message that didn't end in a
4778 # newline character, $self->systemInsertMark is set
4779 # In that case, we must insert an artificial newline character, so this system message
4780 # is displayed on its own line
4781 if ($self->systemInsertMark) {
4782  
4783 $iter = $self->buffer->get_iter_at_mark($self->systemInsertMark);
4784 $iter = $self->insertNewLine($iter);
4785 $self->ivUndef('systemInsertMark');
4786  
4787 # If the last piece of text inserted at the Gtk3::TextBuffer via a call to
4788 # $self->insertText didn't end in a newline character, we need to insert an artifical
4789 # newline character so the system message appears on its own line, at the end of the
4790 # buffer
4791 } elsif (
4792 # Last character in the buffer isn't a newline character
4793 ! $self->newLineFlag
4794 # The insertion point for $self->insertText and ->insertCmd is the end of the buffer
4795 && ! $self->insertMark
4796 ) {
4797 $iter = $self->buffer->get_end_iter();
4798 $self->ivPoke(
4799 'tempInsertMark',
4800 $self->buffer->create_mark('temp_insert_mark', $iter, TRUE),
4801 );
4802  
4803 $beforeFlag = TRUE;
4804 }
4805 # If the cursor is visible, remove it temporarily (i.e. remove the existing
4806 # Gtk3::TextTag)
4807 $self->removeCursor();
4808 # If the buffer is due to be cleared before inserting any text, then clear it
4809 if ($self->clearAfterInsertFlag) {
4810  
4811 # The TRUE argument means 'don't remove/move the cursor'
4812 $self->clearBuffer(undef, TRUE);
4813 }
4814  
4815 # Set the insertion point
4816 $iter = $self->buffer->get_end_iter();
4817  
4818 # Insert the text into the Gtk3::TextBuffer
4819 if ($beforeFlag) {
4820  
4821 # (Make sure the beginning of a link appears after the artificially-inserted newline
4822 # character, not before it)
4823 $iter = $self->insertNewLine($iter);
4824 }
4825  
4826 if ($monochromeFlag) {
4827 $iter = $self->insertWithTags($iter, $msg);
4828 } else {
4829 $iter = $self->insertWithTags($iter, $msg, $textColour);
4830 }
4831  
4832 $self->insertNewLine($iter);
4833  
4834 # Restore the cursor
4835 if ($self->tempInsertMark) {
4836 $self->moveCursor($self->buffer->get_iter_at_mark($self->tempInsertMark));
4837 } else {
4838 $self->replaceCursor();
4839 }
4840  
4841 if ($self->scrollLockFlag) {
4842  
4843 if ($self->scrollLockType eq 'top') {
4844 $self->scrollToTop();
4845 } else {
4846 $self->scrollToBottom();
4847 }
4848 }
4849 }
4850  
4851 if (defined $msg && $msg ne '') {
4852  
4853 if ($taskFlag) {
4854  
4855 # Write the message in the System task window
4856 $self->session->systemTask->showDebug($msg);
4857 }
4858  
4859 if ($consoleFlag) {
4860  
4861 # Send the message to the GA::Session, for display (now or later) in the Session
4862 # Console window
4863 $self->session->add_systemMsg('debug', $msg);
4864 }
4865  
4866 # Write to logs
4867 $axmud::CLIENT->writeLog(
4868 $self->session,
4869 TRUE, # Not world-specific logs
4870 $msg,
4871 $beforeFlag,
4872 TRUE, # Use final newline character
4873 'main', 'errors', 'debug', # Write to these files
4874 );
4875  
4876 # Fire any hooks that are using the system hook events
4877 $self->session->checkHooks('system_debug', $msg);
4878 $self->session->checkHooks('system_all', $msg);
4879 $self->session->checkHooks('system_all_error', $msg);
4880 }
4881  
4882 # Play a sound effect (if allowed, and if this textview object hasn't played the same
4883 # sound effect recently)
4884 if (! $self->soundCheckTime || $self->soundCheckTime < $axmud::CLIENT->clientTime) {
4885  
4886 $axmud::CLIENT->playSound('error');
4887 # Don't play it again for a few seconds
4888 $self->ivPoke('soundCheckTime', ($axmud::CLIENT->clientTime + $self->soundDelayTime));
4889 }
4890  
4891 # Convert text-to-speech, if required (but don't try to convert an 'undef' or text
4892 # containing no readable characters)
4893 if (
4894 $axmud::CLIENT->systemAllowTTSFlag
4895 && $axmud::CLIENT->ttsSystemFlag
4896 && defined $text
4897 && $text =~ m/\w/
4898 # Also, temporarily don't convert system messages if the GA::Session flag is set
4899 && ! $self->session->ttsTempDisableFlag
4900 ) {
4901 # Make sure the received text is visible in the textview(s)...
4902 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showDebug');
4903  
4904 # ...before converting text to speech
4905 if (defined $self->session->ttsLastType && $self->session->ttsLastType eq 'error') {
4906  
4907 # (Don't read out 'system debug' again and again and again!
4908 $axmud::CLIENT->tts($text, 'error', 'error', $self->session);
4909  
4910 } else {
4911  
4912 # Last TTS conversion was something other than a system error (etc) message
4913 $axmud::CLIENT->tts('System debug: ' . $text, 'error', 'error', $self->session);
4914 }
4915 }
4916  
4917 # This type of system message always requires a return value of 'undef'
4918 return undef;
4919 }
4920  
4921 sub showImproper {
4922  
4923 # Called by Games::Axmud->writeImproper
4924 # Inserts a system 'improper arguments' message into the Gtk3::TextBuffer and/or updates the
4925 # System task's window
4926 #
4927 # Expected arguments
4928 # $func - The function that produced the message (e.g.
4929 # 'Games::Axmud::Client->helloWorld')
4930 #
4931 # Optional arguments
4932 # @args - A list of arguments passed by the function that called the
4933 # ->writeImproper() function. If no arguments were passed, an empty list
4934 #
4935 # Return values
4936 # 'undef'
4937  
4938 my ($self, $func, @args) = @_;
4939  
4940 # Local variables
4941 my (
4942 $colourSchemeObj, $monochromeFlag, $textColour, $msg, $systemTask, $hereFlag, $taskFlag,
4943 $consoleFlag, $iter, $beforeFlag,
4944 );
4945  
4946 # Check for improper arguments
4947 if (! defined $func) {
4948  
4949 # This function mustn't call itself, so write something to the terminal
4950 print "ERROR: Recursive improper arguments call from $func\n";
4951 return undef;
4952 }
4953  
4954 # Import the colour scheme in use
4955 $colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme);
4956 # Choose which colour tags to use (in monochrome mode, text/underlay colours are ignored,
4957 # but in this case we don't any apply overrides specified by the colour scheme)
4958 if ($self->monochromeFlag || ($colourSchemeObj && $colourSchemeObj->overrideAllFlag)) {
4959 $monochromeFlag = TRUE;
4960 } else {
4961 $textColour = $axmud::CLIENT->customShowImproperColour;
4962 }
4963  
4964 # Call to ->writeLog requires a TRUE/FALSE value
4965 $beforeFlag = FALSE;
4966  
4967 # Prepare the message to send. Some of the values in @args might be 'undef'; these need to
4968 # be replaced by some text that can actually be displayed
4969 foreach my $arg (@args) {
4970  
4971 if (! defined $arg) {
4972  
4973 $arg = "<<undef>>";
4974 }
4975 }
4976  
4977 $msg = "IMPROPER ARGS: $func() " . join (" ", @args);
4978  
4979 # Whether the message is written only in this textview (mode 'original'), or in both this
4980 # textview and the System task's window ('both'), or in the System task's window only
4981 # (mode 'task'), depends on the System task's IVs (if the task is running)
4982 $systemTask = $self->session->systemTask;
4983 if (! $systemTask) {
4984  
4985 $hereFlag = TRUE;
4986  
4987 } else {
4988  
4989 if ($systemTask->improperMode eq 'original') {
4990  
4991 $hereFlag = TRUE;
4992  
4993 } elsif ($systemTask->improperMode eq 'both') {
4994  
4995 $hereFlag = TRUE;
4996 $taskFlag = TRUE;
4997  
4998 } else {
4999  
5000 $taskFlag = TRUE;
5001 }
5002 }
5003  
5004 # If not allowed to write a system message in this textview, write to the Session Console
5005 # window instead
5006 if (
5007 $hereFlag
5008 && (! $axmud::CLIENT->mainWinSystemMsgFlag || $self->overwriteFlag)
5009 ) {
5010 $hereFlag = FALSE;
5011 $consoleFlag = TRUE;
5012 }
5013  
5014 if ($hereFlag) {
5015  
5016 # If the previous call to $self->showSystemText displayed a message that didn't end in a
5017 # newline character, $self->systemInsertMark is set
5018 # In that case, we must insert an artificial newline character, so this system message
5019 # is displayed on its own line
5020 if ($self->systemInsertMark) {
5021  
5022 $iter = $self->buffer->get_iter_at_mark($self->systemInsertMark);
5023 $iter = $self->insertNewLine($iter);
5024 $self->ivUndef('systemInsertMark');
5025  
5026 # If the last piece of text inserted at the Gtk3::TextBuffer via a call to
5027 # $self->insertText didn't end in a newline character, we need to insert an artifical
5028 # newline character so the system message appears on its own line, at the end of the
5029 # buffer
5030 } elsif (
5031 # Last character in the buffer isn't a newline character
5032 ! $self->newLineFlag
5033 # The insertion point for $self->insertText and ->insertCmd is the end of the buffer
5034 && ! $self->insertMark
5035 ) {
5036 $iter = $self->buffer->get_end_iter();
5037 $self->ivPoke(
5038 'tempInsertMark',
5039 $self->buffer->create_mark('temp_insert_mark', $iter, TRUE),
5040 );
5041  
5042 $beforeFlag = TRUE;
5043 }
5044  
5045 # If the cursor is visible, remove it temporarily (i.e. remove the existing
5046 # Gtk3::TextTag)
5047 $self->removeCursor();
5048 # If the buffer is due to be cleared before inserting any text, then clear it
5049 if ($self->clearAfterInsertFlag) {
5050  
5051 # The TRUE argument means 'don't remove/move the cursor'
5052 $self->clearBuffer(undef, TRUE);
5053 }
5054  
5055 # Set the insertion point
5056 $iter = $self->buffer->get_end_iter();
5057  
5058 # Insert the text into the Gtk3::TextBuffer
5059 if ($beforeFlag) {
5060  
5061 # (Make sure the beginning of a link appears after the artificially-inserted newline
5062 # character, not before it)
5063 $iter = $self->insertNewLine($iter);
5064 }
5065  
5066 if ($monochromeFlag) {
5067 $iter = $self->insertWithTags($iter, $msg);
5068 } else {
5069 $iter = $self->insertWithTags($iter, $msg, $textColour);
5070 }
5071  
5072 $self->insertNewLine($iter);
5073  
5074 # Restore the cursor
5075 if ($self->tempInsertMark) {
5076 $self->moveCursor($self->buffer->get_iter_at_mark($self->tempInsertMark));
5077 } else {
5078 $self->replaceCursor();
5079 }
5080  
5081 if ($self->scrollLockFlag) {
5082  
5083 if ($self->scrollLockType eq 'top') {
5084 $self->scrollToTop();
5085 } else {
5086 $self->scrollToBottom();
5087 }
5088 }
5089 }
5090  
5091 if (defined $msg && $msg ne '') {
5092  
5093 if ($taskFlag) {
5094  
5095 # Write the message in the System task window
5096 $self->session->systemTask->showImproper($msg);
5097 }
5098  
5099 if ($consoleFlag) {
5100  
5101 # Send the message to the GA::Session, for display (now or later) in the Session
5102 # Console window
5103 $self->session->add_systemMsg('improper', $msg);
5104 }
5105  
5106 # Write to logs
5107 $axmud::CLIENT->writeLog(
5108 $self->session,
5109 TRUE, # Not world-specific logs
5110 $msg,
5111 $beforeFlag,
5112 TRUE, # Use final newline character
5113 'main', 'errors', 'improper', # Write to these files
5114 );
5115  
5116 # Fire any hooks that are using the system hook events
5117 $self->session->checkHooks('system_improper', $msg);
5118 $self->session->checkHooks('system_all', $msg);
5119 $self->session->checkHooks('system_all_error', $msg);
5120 }
5121  
5122 # Play a sound effect (if allowed, and if this textview object hasn't played the same
5123 # sound effect recently)
5124 if (! $self->soundCheckTime || $self->soundCheckTime < $axmud::CLIENT->clientTime) {
5125  
5126 $axmud::CLIENT->playSound('error');
5127 # Don't play it again for a few seconds
5128 $self->ivPoke('soundCheckTime', ($axmud::CLIENT->clientTime + $self->soundDelayTime));
5129 }
5130  
5131 # # v1.2.208 Improper args messages are incomprehensible, when converted to speech; so this
5132 # # is now disabled
5133 # # Convert text-to-speech, if required (but don't try to convert an 'undef' or text
5134 # # containing no readable characters)
5135 # if (
5136 # $axmud::CLIENT->systemAllowTTSFlag
5137 # && $axmud::CLIENT->ttsSystemFlag
5138 # && defined $msg
5139 # && $msg =~ m/\w/
5140 # # Also, temporarily don't convert system messages if the GA::Session flag is set
5141 # && ! $self->session->ttsTempDisableFlag
5142 # ) {
5143 # # Make sure the received text is visible in the textview(s)...
5144 # $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showImproper');
5145 #
5146 # # ...before converting text to speech
5147 # $axmud::CLIENT->tts(
5148 # 'System error: improper arguments in function: ' . $func,
5149 # 'error',
5150 # 'error',
5151 # $self->session,
5152 # );
5153 # }
5154  
5155 # This type of system message always requires a return value of 'undef'
5156 return undef;
5157 }
5158  
5159 sub showImage {
5160  
5161 # Can be called by anything
5162 # Inserts an image pixbuf into the textview at the current insertion point
5163 #
5164 # Expected arguments
5165 # $pixbuf - The Gtk3::Gdk::Pixbuf or Gtk3::Gdk::PixbufAnimation of the image to
5166 # display
5167 #
5168 # Optional arguments
5169 # $linkObj - For clickable images, the corresponding GA::Obj::Link object. Can be a an
5170 # incomplete link object created by GA::Session's MXP functions (for
5171 # example), or a completed link object stored in this textview object's
5172 # ->linkObjHash; otherwise 'undef'
5173 # $padWidth, $padHeight
5174 # - Optional padding around the image, in pixels (not the width/height of the
5175 # image itself; that is only specified by the pixbuf)
5176 # @args - Optional list of arguments, in any order:
5177 # - 'empty' (empties the buffer before writing $text)
5178 # - 'before' (prepends a newline character to $text)
5179 # - 'after' or 'nl' (appends a newline character to $text)
5180 # - 'echo' (does not prepend/append a newline character, overrides
5181 # 'before', 'after' and 'nl' if they are specified)
5182 #
5183 # - NB The default behaviour is set by $self->defaultNewLine, which is set to
5184 # 'before', 'after', 'nl' or 'echo'. This default behaviour is only
5185 # applied if none of 'before', 'after', 'nl' and 'echo' are specified
5186 # - NB If @args contains Axmud colour/style tags (as they might in a call to
5187 # $self->insertText), they are ignored
5188 #
5189 # Return values
5190 # 'undef' on improper arguments
5191 # 1 otherwise
5192  
5193 my ($self, $pixbuf, $linkObj, $padWidth, $padHeight, @args) = @_;
5194  
5195 # Local variables
5196 my (
5197 $animFlag, $emptyFlag, $beforeFlag, $afterFlag, $mark, $iter, $image, $packWidget,
5198 $ebox, $anchor, $lineNum, $posn, $newMark, $newIter, $tempInsertFlag,
5199 );
5200  
5201 # Check for improper arguments
5202 if (! defined $pixbuf) {
5203  
5204 return $axmud::CLIENT->writeImproper($self->_objClass . '->showImage', @_);
5205 }
5206  
5207 # Test whether the $pixbuf is an animated gif, received by this function as a
5208 # Gtk3::Gdk::PixbufAnimation-related object, or an unanimated image (including gifs),
5209 # received by this function as a Gtk3::Gdk::Pixbuf
5210 if (ref ($pixbuf) =~ /Anim/) {
5211  
5212 $animFlag = TRUE;
5213 }
5214  
5215 # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag)
5216 $self->removeCursor();
5217 # If the buffer is due to be cleared before inserting any text, then clear it
5218 if ($self->clearAfterInsertFlag || $emptyFlag) {
5219  
5220 # The TRUE argument means 'don't remove/move the cursor'
5221 $self->clearBuffer(undef, TRUE);
5222 }
5223  
5224 # Interpret the list of @args, ignoring most of the usual return values
5225 ($emptyFlag, $beforeFlag, $afterFlag) = $self->interpretTags($self->newLineDefault, @args);
5226  
5227 # Set the insertion point
5228 if ($self->insertMark) {
5229  
5230 $mark = $self->insertMark;
5231  
5232 } elsif ($self->tempInsertMark) {
5233  
5234 $mark = $self->tempInsertMark;
5235 if ($afterFlag) {
5236  
5237 # This code prevents a blank line being inserted between a world's prompt and the
5238 # already-displayed Axmud system message
5239 $self->ivUndef('tempInsertMark');
5240 $afterFlag = FALSE;
5241 $tempInsertFlag = TRUE;
5242 }
5243 }
5244  
5245 if ($mark) {
5246 $iter = $self->buffer->get_iter_at_mark($mark);
5247 } elsif (! $self->systemInsertMark) {
5248 $iter = $self->buffer->get_end_iter();
5249 } else {
5250  
5251 # Incomplete system message after a call to $self->showSystemText without a newline
5252 # character. Must insert an artificial newline character, and display $pixbuf after
5253 # that
5254 $iter = $self->buffer->get_iter_at_mark($self->systemInsertMark);
5255 $iter = $self->insertNewLine($iter);
5256 }
5257  
5258 # (Don't prepend a newline character if the buffer is empty)
5259 if ($beforeFlag && $self->bufferTextFlag) {
5260  
5261 # (Make sure the beginning of a link appears after the extra newline character, not
5262 # before it)
5263 $iter = $self->insertNewLine($iter);
5264 }
5265  
5266 # Get the position of the iter now, before it becomes invalid
5267 $lineNum = $iter->get_line();
5268 $posn = $iter->get_visible_line_offset();
5269  
5270 # Create the image
5271 if (! $animFlag) {
5272  
5273 $image = $packWidget = Gtk3::Image->new_from_pixbuf($pixbuf);
5274  
5275 } else {
5276  
5277 $image = $packWidget = Gtk3::Image->new();
5278 $image->set_from_animation($pixbuf);
5279 }
5280  
5281 # If the image should be clickable, pack it inside an event box
5282 if (defined $linkObj) {
5283  
5284 $ebox = Gtk3::EventBox->new();
5285 $ebox->signal_connect('button-press-event' => sub {
5286  
5287 my ($widget, $event) = @_;
5288  
5289 # Local variables
5290 my ($x, $y, $href);
5291  
5292 # Check the link is completed (not temporary) and that it hasn't expired
5293 if (
5294 defined $linkObj->number
5295 && $linkObj->number != -1
5296 && $self->ivExists('linkObjHash', $linkObj->number)
5297 ) {
5298 # Substitute for %x and %y
5299 $x = $event->x;
5300 $y = $event->y;
5301 $href = $linkObj->href;
5302  
5303 $href =~ s/\%x/$x/;
5304 $href =~ s/\%y/$y/;
5305  
5306 if ($linkObj->mxpInvisFlag) {
5307 $self->session->send($href);
5308 } else {
5309 $self->session->worldCmd($href);
5310 }
5311 }
5312 });
5313  
5314 $ebox->signal_connect('enter-notify-event' => sub {
5315  
5316 $self->textView->get_window('text')->set_cursor($axmud::CLIENT->constWWWCursor);
5317 });
5318  
5319 $ebox->signal_connect('leave-notify-event' => sub {
5320  
5321 $self->textView->get_window('text')->set_cursor($axmud::CLIENT->constNormalCursor);
5322 });
5323  
5324 $ebox->add($image);
5325 $packWidget = $ebox;
5326 }
5327  
5328 # Apply padding, if specified
5329 if ($padWidth && ! ($padWidth =~ m/\D/)) {
5330  
5331 my $hBox = Gtk3::HBox->new();
5332 $hBox->pack_start($packWidget, FALSE, FALSE, $padWidth);
5333  
5334 $packWidget = $hBox;
5335 }
5336  
5337 if ($padHeight && ! ($padHeight =~ m/\D/)) {
5338  
5339 my $vBox = Gtk3::VBox->new();
5340 $vBox->pack_start($packWidget, FALSE, FALSE, $padHeight);
5341  
5342 $packWidget = $vBox;
5343 }
5344  
5345 # Insert the image into the textview
5346 $anchor = $self->buffer->create_child_anchor($iter);
5347 $self->textView->add_child_at_anchor($packWidget, $anchor);
5348  
5349 # Set the new insert iter. The Gtk docs state that the image counts as one character
5350 $newIter = $self->buffer->get_iter_at_line_offset($lineNum, ($posn + 1));
5351  
5352 if ($afterFlag) {
5353  
5354 # (Make sure the end of a link appears before the extra newline character, not
5355 # after it)
5356 $newIter = $self->insertNewLine($newIter);
5357 }
5358  
5359 if ($self->insertMark) {
5360  
5361 # The next call to $self->insertText, ->insertCmd etc uses the insertion point
5362 # immediately after $newIter
5363 $newMark = $self->buffer->create_mark('insert_mark', $newIter, TRUE);
5364 $self->ivPoke('insertMark', $newMark);
5365 # If the cursor is visible, move it to this position (i.e. insert a new Gtk3::TextTag)
5366 $self->moveCursor($self->buffer->get_iter_at_mark($mark));
5367  
5368 } elsif ($tempInsertFlag) {
5369  
5370 # Continue using this temporary insertion point, before a line with a system message
5371 # (and don't restore the cursor yet)
5372 $newMark = $self->buffer->create_mark('temp_insert_mark', $newIter, TRUE);
5373 $self->ivPoke('tempInsertMark', $newMark);
5374  
5375 } else {
5376  
5377 # If the cursor is visible, move it to the end of the buffer (i.e. insert a new
5378 # Gtk3::TextTag)
5379 $self->moveCursor();
5380 }
5381  
5382 if ($self->scrollLockFlag) {
5383  
5384 if ($self->scrollLockType eq 'top') {
5385 $self->scrollToTop();
5386 } else {
5387 $self->scrollToBottom();
5388 }
5389  
5390 } else {
5391  
5392 # Scroll to the point immediately after the image's insertion point
5393 $self->scrollToIter($newIter);
5394 }
5395  
5396 # Animated pixbufs will not be visible reliably without this line
5397 $self->winObj->winShowAll($self->_objClass . '->showImage');
5398  
5399 return 1;
5400 }
5401  
5402 sub removeCursor {
5403  
5404 # Called by $self->insertText, ->insertMultipleText, ->insertQuick and ->insertCmd
5405 # 'Removes' the visible cursor, usually before a call to $self->moveCursor to move it
5406 # somewhere else
5407 # Also removes the extract space character at the end of the buffer, if one was created by
5408 # $self->moveCursor
5409 #
5410 # Expected arguments
5411 # (none besides $self)
5412 #
5413 # Return values
5414 # 'undef' on improper arguments, if visible cursors are disabled in this textview or if no
5415 # visible cursor has been drawn yet
5416 # 1 otherwise
5417  
5418 my ($self, $check) = @_;
5419  
5420 # Local variables
5421 my ($nextIter, $iter);
5422  
5423 # Check for improper arguments
5424 if (defined $check) {
5425  
5426 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeCursor', @_);
5427 }
5428  
5429 # Do nothing if visible cursors are disabled in this textview, or if no cursor has been
5430 # drawn by an earlier call to $self->moveCursor
5431 if (! $self->cursorEnableFlag || ! $self->cursorMark) {
5432  
5433 return undef;
5434 }
5435  
5436 $nextIter = $self->buffer->get_iter_at_mark($self->cursorMark);
5437 if (! $nextIter) {
5438  
5439 return undef;
5440  
5441 } else {
5442  
5443 $nextIter->forward_char();
5444 $iter = $self->buffer->get_iter_at_mark($self->cursorMark);
5445 }
5446  
5447 # Remove the Gtk3::TextTag
5448 $self->buffer->remove_tag_by_name(
5449 'cursor',
5450 # Would like to remove the text tag just for the one space character, but it doesn't
5451 # work
5452 $iter,
5453 $self->buffer->get_end_iter(),
5454 );
5455  
5456 # Remove the extra space that was added, if the cursor was position at the end of the buffer
5457 # (if a system message has been displayed, it might not be the end of the buffer now)
5458 if ($self->cursorEndFlag) {
5459  
5460 $self->buffer->delete($iter, $nextIter);
5461 }
5462  
5463 # Remove the mark
5464 $self->buffer->delete_mark($self->cursorMark);
5465  
5466 # Update IVs
5467 $self->ivUndef('cursorMark');
5468 $self->ivPoke('cursorEndFlag', FALSE);
5469  
5470 return 1;
5471 }
5472  
5473 sub moveCursor {
5474  
5475 # Called by $self->insertText, ->insertMultipleText, ->insertQuick and ->insertCmd
5476 # 'Moves' the visible cursor to a specified position, or to the end of the buffer
5477 # If at the end of the buffer, or at the end of line, adds an extra space character so that
5478 # the cursor is actually visible
5479 #
5480 # Expected arguments
5481 # (none besides $self)
5482 #
5483 # Optional arguments
5484 # $iter - The Gtk3::TextIter at which to position the cursor. If 'undef', the cursor is
5485 # positioned at the end of the buffer
5486 #
5487 # Return values
5488 # 'undef' on improper arguments or if visible cursors are disabled in this textview
5489 # 1 otherwise
5490  
5491 my ($self, $iter, $check) = @_;
5492  
5493 # Local variables
5494 my ($endIter, $lastFlag, $cursorMark, $nextIter, $length);
5495  
5496 # Check for improper arguments
5497 if (defined $check) {
5498  
5499 return $axmud::CLIENT->writeImproper($self->_objClass . '->moveCursor', @_);
5500 }
5501  
5502 # Do nothing if visible cursors are disabled in this textview
5503 if (! $self->cursorEnableFlag) {
5504  
5505 return undef;
5506 }
5507  
5508 $endIter = $self->buffer->get_end_iter();
5509 if (! $iter || $endIter->get_line() == $iter->get_line()) {
5510  
5511 # Insert position is on the buffer's last line
5512 $lastFlag = TRUE;
5513 }
5514  
5515 if (
5516 ! defined $iter
5517 || (
5518 $lastFlag
5519 && $endIter->get_visible_line_offset() == $iter->get_visible_line_offset()
5520 )
5521 ) {
5522 $cursorMark = $self->buffer->create_mark('cursor_mark', $endIter, TRUE);
5523  
5524 # Insert a space character at the end of the buffer, so that the visible cursor is
5525 # actually visible
5526 $self->buffer->insert_with_tags_by_name(
5527 $self->buffer->get_end_iter(),
5528 ' ',
5529 'cursor',
5530 );
5531  
5532 # Update IVs
5533 $self->ivPoke('cursorMark', $cursorMark);
5534 $self->ivPoke('cursorEndFlag', TRUE);
5535  
5536 } else {
5537  
5538 $cursorMark = $self->buffer->create_mark('cursor_mark', $iter, TRUE);
5539  
5540 $nextIter = $self->buffer->get_iter_at_mark($cursorMark);
5541 if (! $nextIter) {
5542  
5543 return undef;
5544  
5545 } else {
5546  
5547 $nextIter->forward_char();
5548 $iter = $self->buffer->get_iter_at_mark($cursorMark);
5549 }
5550  
5551 # If the visible cursor is at the end of a line (i.e. just before a newline character),
5552 # insert a space character there so that the visible cursor is actually visible
5553 $length = $self->getLineLength($iter);
5554 if (
5555 ($lastFlag && $iter->get_visible_line_offset() >= $length)
5556 || (! $lastFlag && $iter->get_visible_line_offset() >= ($length - 1))
5557 ) {
5558 $self->buffer->insert_with_tags_by_name(
5559 $iter,
5560 ' ',
5561 'cursor',
5562 );
5563  
5564 } else {
5565  
5566 # Just insert the Gtk3::TextTag for the cursor at this position
5567 $self->buffer->apply_tag_by_name(
5568 'cursor',
5569 $iter,
5570 $nextIter,
5571 );
5572 }
5573  
5574 # Update IVs
5575 $self->ivPoke('cursorMark', $cursorMark);
5576 $self->ivPoke('cursorEndFlag', FALSE);
5577 }
5578  
5579 return 1;
5580 }
5581  
5582 sub replaceCursor {
5583  
5584 # Called by the clear buffer/clear line operations (e.g. $self->clearBufferAfterMark,
5585 # ->clearLineAroundPosn, etc)
5586 # Calls $self->moveCursor with the correct arguments for the current situation
5587 #
5588 # Expected arguments
5589 # (none besides $self)
5590 #
5591 # Return values
5592 # 'undef' on improper arguments
5593 # Otherwise returns the result of the call to $self-> moveCursor
5594  
5595 my ($self, $check) = @_;
5596  
5597 # Check for improper arguments
5598 if (defined $check) {
5599  
5600 return $axmud::CLIENT->writeImproper($self->_objClass . '->replaceCursor', @_);
5601 }
5602  
5603 if ($self->insertMark) {
5604 return $self->moveCursor($self->buffer->get_iter_at_mark($self->insertMark));
5605 } else {
5606 return $self->moveCursor($self->buffer->get_end_iter());
5607 }
5608 }
5609  
5610 # Other functions - search the buffer
5611  
5612 sub setSearchMark {
5613  
5614 # Can be called by anything
5615 # Moves the Gtk3::TextMark used for searching the buffer from its current position to a new
5616 # position
5617 #
5618 # Expected arguments
5619 # (none besides $self)
5620 #
5621 # Optional arguments
5622 # $line - The line number at which to place the mark. Use 0 for the beginning of the
5623 # buffer, 1 for the second line, and so on. If 'undef' or if $line is greater
5624 # than the size of the buffer, the mark is placed at the end of the buffer
5625 # $offset - The offset on the line at which to place the mark. Use 0 for the beginning of
5626 # the line, 1 to place the mark before the 2nd character, and so on. If
5627 # 'undef', the mark is placed at the end of the line (but before the newline
5628 # character, if any)
5629 #
5630 # Return values
5631 # 'undef' on improper arguments
5632 # 1 otherwise
5633  
5634 my ($self, $line, $offset, $check) = @_;
5635  
5636 # Local variables
5637 my ($size, $startIter, $length, $endIter);
5638  
5639 # Check for improper arguments
5640 if (defined $check) {
5641  
5642 return $axmud::CLIENT->writeImproper($self->_objClass . '->setSearchMark', @_);
5643 }
5644  
5645 # Get the current size of the buffer
5646 $size = $self->buffer->get_line_count();
5647 if (! defined $line || $line >= $size) {
5648  
5649 $line = $size - 1;
5650 }
5651  
5652 # Get the iter at the start of that line
5653 $startIter = $self->buffer->get_iter_at_line_offset($line, 0);
5654 $length = $self->getLineLength($startIter);
5655  
5656 # Get the iter at the end of the buffer. If this line is not the last line in the buffer,
5657 # we need to take account of the newline character
5658 $endIter = $self->buffer->get_end_iter();
5659 if ($endIter->get_line() != $startIter->get_line()) {
5660  
5661 $length--;
5662 }
5663  
5664 if (! defined $offset || $offset >= $length) {
5665  
5666 $offset = $length - 1;
5667 # Sanity check
5668 if ($offset < 0) {
5669  
5670 $offset = 0;
5671 }
5672 }
5673  
5674 # Move the search mark to the specified location
5675 $self->ivPoke(
5676 'searchMark',
5677 $self->buffer->create_mark(
5678 'search_mark',
5679 $self->buffer->get_iter_at_line_offset($line, $offset),
5680 TRUE,
5681 ),
5682 );
5683  
5684 return 1;
5685 }
5686  
5687 sub searchBuffer {
5688  
5689 # Can be called by anything
5690 # Searches the buffer using a specified pattern, stopping at the first matching text
5691 # If the beginning of the buffer is reached and no match is found, the search continues
5692 # from the end of the buffer (and vice versa)
5693 # If a match is found, moves $self->searchMark to just before (or after) that location, so
5694 # the next search can continue from that point
5695 #
5696 # Expected arguments
5697 # $regex - The regex to match
5698 # $mode - FALSE to search, line by line, from before $self->searchMark; TRUE to
5699 # search, line by line, from after $self->searchMark
5700 #
5701 # Optional arguments
5702 # $selectFlag - If TRUE, the matching text is selected and the textview is scrolled to the
5703 # matching text
5704 # $caseFlag - If TRUE, a case-sensitive match is performed. If FALSE (or 'undef'), a
5705 # case-insensitive match is performed
5706 #
5707 # Return values
5708 # An empty list on improper arguments or if no matching text is found
5709 # 1 otherwise
5710  
5711 my ($self, $regex, $mode, $selectFlag, $caseFlag, $check) = @_;
5712  
5713 # Local variables
5714 my (
5715 $size, $searchIter, $searchLine, $searchPosn, $text, $matchLine, $matchPosn, $matchLen,
5716 $matchIter,
5717 @emptyList,
5718 );
5719  
5720 # Check for improper arguments
5721 if (defined $check) {
5722  
5723 $axmud::CLIENT->writeImproper($self->_objClass . '->searchBuffer', @_);
5724 return @emptyList;
5725 }
5726  
5727 # Obviously, if the regex is empty, then there's nothing so search
5728 if ($regex eq '') {
5729  
5730 return @emptyList;
5731 }
5732  
5733 # Get the size of the buffer
5734 $size = $self->buffer->get_line_count();
5735 if (! $size) {
5736  
5737 # Buffer is empty
5738 return @emptyList;
5739 }
5740  
5741 # $self->searchIter records the position of the last successful search (or the position at
5742 # which to start a search), so we'll start there
5743 $searchIter = $self->buffer->get_iter_at_mark($self->searchMark);
5744 if (! $searchIter) {
5745  
5746 # Something's gone wrong
5747 return @emptyList;
5748 }
5749  
5750 # If searching forwards, start searching from the first character after $searchIter
5751 if ($mode) {
5752  
5753 $searchIter->forward_char();
5754 }
5755  
5756 $searchLine = $searchIter->get_line();
5757 $searchPosn = $searchIter->get_line_offset();
5758  
5759 # Search lines, one by one, starting with $searchLine
5760 if (! $mode) {
5761  
5762 $text = $self->buffer->get_text(
5763 $self->buffer->get_iter_at_line_offset($searchLine, 0),
5764 $searchIter,
5765 FALSE,
5766 );
5767  
5768 } elsif ($searchLine >= ($size - 1)) {
5769  
5770 $text = $self->buffer->get_text(
5771 $searchIter,
5772 $self->buffer->get_end_iter(),
5773 FALSE,
5774 );
5775  
5776 } else {
5777  
5778 $text = $self->buffer->get_text(
5779 $searchIter,
5780 $self->buffer->get_iter_at_line_offset(($searchLine + 1), 0),
5781 FALSE,
5782 );
5783 }
5784  
5785 if (
5786 $text ne ''
5787 && (
5788 # Find last match in $text, just before $searchMark
5789 (
5790 ! $mode
5791 && (
5792 (! $caseFlag && $text =~ m/$regex/gi)
5793 || ($caseFlag && $text =~ m/$regex/g)
5794 )
5795 # Find first match in $text, just after $searchMark
5796 ) || (
5797 $mode
5798 && (
5799 (! $caseFlag && $text =~ m/$regex/i)
5800 || ($caseFlag && $text =~ m/$regex/)
5801 )
5802 )
5803 )
5804 ) {
5805 # Match found!
5806 $matchLine = $searchLine;
5807 $matchPosn = $-[0];
5808 $matchLen = $+[0] - $matchPosn;
5809 if ($mode) {
5810  
5811 $matchPosn += $searchPosn;
5812 }
5813  
5814 $self->setSearchMark($matchLine, $matchPosn);
5815 if ($selectFlag) {
5816  
5817 $self->selectTextInLine($matchLine, $matchPosn, $matchLen, TRUE);
5818 }
5819  
5820 return ($matchLine, $matchPosn, $matchLen);
5821 }
5822  
5823 # Search before (or after) $searchLine
5824 if ($size > 1) {
5825  
5826 if (! $mode && $searchLine > 0) {
5827  
5828 for (my $count = ($searchLine - 1); $count >= 0; $count--) {
5829  
5830 $text = $self->buffer->get_text(
5831 $self->buffer->get_iter_at_line_offset($count, 0),
5832 $self->buffer->get_iter_at_line_offset(($count + 1), 0),
5833 FALSE,
5834 );
5835  
5836 # Find last match in $text
5837 if (
5838 $text ne ''
5839 && (
5840 (! $caseFlag && $text =~ m/$regex/gi)
5841 || ($caseFlag && $text =~ m/$regex/g)
5842 )
5843 ) {
5844 # Match found!
5845 $matchLine = $count;
5846 $matchPosn = $-[0];
5847 $matchLen = $+[0] - $matchPosn;
5848  
5849 $self->setSearchMark($matchLine, $matchPosn);
5850 if ($selectFlag) {
5851  
5852 $self->selectTextInLine($matchLine, $matchPosn, $matchLen, TRUE);
5853 }
5854  
5855 return ($matchLine, $matchPosn, $matchLen);
5856 }
5857 }
5858  
5859 } elsif ($mode && $searchLine < ($size - 1)) {
5860  
5861 for (my $count = ($searchLine + 1); $count <= ($size - 1); $count++) {
5862  
5863 $text = $self->buffer->get_text(
5864 $self->buffer->get_iter_at_line_offset($count, 0),
5865 $self->buffer->get_iter_at_line_offset(($count + 1), 0),
5866 FALSE,
5867 );
5868  
5869 # Find first match in $text
5870 if (
5871 $text ne ''
5872 && (
5873 (! $caseFlag && $text =~ m/$regex/i)
5874 || ($caseFlag && $text =~ m/$regex/)
5875 )
5876 ) {
5877 # Match found!
5878 $matchLine = $count;
5879 $matchPosn = $-[0];
5880 $matchLen = $+[0] - $matchPosn;
5881  
5882 $self->setSearchMark($matchLine, $matchPosn);
5883 if ($selectFlag) {
5884  
5885 $self->selectTextInLine($matchLine, $matchPosn, $matchLen, TRUE);
5886 }
5887  
5888 return ($matchLine, $matchPosn, $matchLen);
5889 }
5890 }
5891 }
5892  
5893 # Reached the beginning (or the end) of the buffer, so now search the other part of the
5894 # buffer from the opposite direction (i.e. if we reached the beginning of the buffer,
5895 # search from the end)
5896 if (! $mode && $searchLine < ($size - 1)) {
5897  
5898 for (my $count = ($size - 1); $count > $searchLine; $count--) {
5899  
5900 $text = $self->buffer->get_text(
5901 $self->buffer->get_iter_at_line_offset($count, 0),
5902 $self->buffer->get_iter_at_line_offset(($count + 1), 0),
5903 FALSE,
5904 );
5905  
5906 # Find first match in $text
5907 if (
5908 $text ne ''
5909 && (
5910 (! $caseFlag && $text =~ m/$regex/i)
5911 || ($caseFlag && $text =~ m/$regex/)
5912 )
5913 ) {
5914 # Match found!
5915 $matchLine = $count;
5916 $matchPosn = $-[0];
5917 $matchLen = $+[0] - $matchPosn;
5918  
5919 $self->setSearchMark($matchLine, $matchPosn);
5920 if ($selectFlag) {
5921  
5922 $self->selectTextInLine($matchLine, $matchPosn, $matchLen, TRUE);
5923 }
5924  
5925 return ($matchLine, $matchPosn, $matchLen);
5926 }
5927 }
5928  
5929 } elsif ($mode && $searchLine > 0) {
5930  
5931 for (my $count = 0; $count < $searchLine; $count++) {
5932  
5933 $text = $self->buffer->get_text(
5934 $self->buffer->get_iter_at_line_offset($count, 0),
5935 $self->buffer->get_iter_at_line_offset(($count + 1), 0),
5936 FALSE,
5937 );
5938  
5939 # Find first match in $text
5940 if (
5941 $text ne ''
5942 && (
5943 (! $caseFlag && $text =~ m/$regex/gi)
5944 || ($caseFlag && $text =~ m/$regex/g)
5945 )
5946 ) {
5947 # Match found!
5948 $matchLine = $count;
5949 $matchPosn = $-[0];
5950 $matchLen = $+[0] - $matchPosn;
5951  
5952 $self->setSearchMark($matchLine, $matchPosn);
5953 if ($selectFlag) {
5954  
5955 $self->selectTextInLine($matchLine, $matchPosn, $matchLen, TRUE);
5956 }
5957  
5958 return ($matchLine, $matchPosn, $matchLen);
5959 }
5960 }
5961 }
5962 }
5963  
5964 # Now search the other part of $searchLine
5965 if ($mode) {
5966  
5967 $text = $self->buffer->get_text(
5968 $self->buffer->get_iter_at_line_offset($searchLine, 0),
5969 $searchIter,
5970 FALSE,
5971 );
5972  
5973 } elsif ($searchLine >= ($size - 1)) {
5974  
5975 $text = $self->buffer->get_text(
5976 $searchIter,
5977 $self->buffer->get_end_iter(),
5978 FALSE,
5979 );
5980  
5981 } else {
5982  
5983 $text = $self->buffer->get_text(
5984 $searchIter,
5985 $self->buffer->get_iter_at_line_offset(($searchLine + 1), 0),
5986 FALSE,
5987 );
5988 }
5989  
5990 if (
5991 $text ne ''
5992 && (
5993 # Find last match in $text, just before $searchMark
5994 (
5995 $mode
5996 && (
5997 (! $caseFlag && $text =~ m/$regex/gi)
5998 || ($caseFlag && $text =~ m/$regex/g)
5999 )
6000 # Find first match in $text, just after $searchMark
6001 ) || (
6002 ! $mode
6003 && (
6004 (! $caseFlag && $text =~ m/$regex/i)
6005 || ($caseFlag && $text =~ m/$regex/)
6006 )
6007 )
6008 )
6009 ) {
6010 # Match found!
6011 $matchLine = $searchLine;
6012 $matchPosn = $-[0];
6013 $matchLen = $+[0] - $matchPosn;
6014 if ($mode) {
6015  
6016 $matchPosn += $searchPosn;
6017 }
6018  
6019 $self->setSearchMark($matchLine, $matchPosn);
6020 if ($selectFlag) {
6021  
6022 $self->selectTextInLine($matchLine, $matchPosn, $matchLen, TRUE);
6023 }
6024  
6025 return ($matchLine, $matchPosn, $matchLen);
6026 }
6027  
6028 # No matches found
6029 return @emptyList;
6030 }
6031  
6032 sub selectTextInLine {
6033  
6034 # Can be called by anything, but mainly called by $self->searchBuffer
6035 # Selects some text on a single line, from one specified position to another. If required,
6036 # the textview is scrolled to the start of the selected text
6037 #
6038 # Expected arguments
6039 # $line - The line number at which to select text. If the buffer doesn't contain
6040 # enough lines, no text is selected
6041 # $offset - The offset on the line from which to select text. If the line doesn't
6042 # contain enough characters, no text is selected
6043 # $selectLength - The length of the selected text. If it's longer than the line itself,
6044 # $selectLength is shortened so that only text on one line is selected
6045 #
6046 # Optional arguments
6047 # $scrollFlag - If TRUE, the textview is scrolled to $line. If FALSE or 'undef', no
6048 # scrolling takes place
6049 #
6050 # Return values
6051 # 'undef' on improper arguments or if no text can be selected
6052 # 1 otherwise
6053  
6054 my ($self, $line, $offset, $selectLength, $scrollFlag, $check) = @_;
6055  
6056 # Local variables
6057 my ($size, $startIter, $lineLength, $endIter);
6058  
6059 # Check for improper arguments
6060 if (! defined $line || ! defined $offset || ! defined $selectLength || defined $check) {
6061  
6062 return $axmud::CLIENT->writeImproper($self->_objClass . '->selectTextInLine', @_);
6063 }
6064  
6065 # Get the current size of the buffer
6066 $size = $self->buffer->get_line_count();
6067 if ($line >= $size) {
6068  
6069 # Buffer isn't big enough
6070 return undef;
6071 }
6072  
6073 # Get the iter at the specified position
6074 $startIter = $self->buffer->get_iter_at_line_offset($line, $offset);
6075 $lineLength = $self->getLineLength($startIter);
6076  
6077 # Get the iter at the end of the buffer. If this line is not the last line in the buffer,
6078 # we need to take account of the newline character
6079 $endIter = $self->buffer->get_end_iter();
6080 if ($endIter->get_line() != $startIter->get_line()) {
6081  
6082 $lineLength--;
6083 }
6084  
6085 if ($offset >= $lineLength) {
6086  
6087 # The specified offset occurs after the end of the line
6088 return undef;
6089  
6090 } elsif (($offset + $selectLength) >= $lineLength) {
6091  
6092 # Reduce $selectLength so that text to the end of the line is selected
6093 $selectLength = $lineLength - $offset;
6094 if (! $selectLength) {
6095  
6096 # No text to select
6097 return undef;
6098 }
6099 }
6100  
6101 # Select the text
6102 $self->buffer->select_range(
6103 $startIter,
6104 $self->buffer->get_iter_at_line_offset($line, ($offset + $selectLength)),
6105 );
6106  
6107 # Scroll the textview, if required
6108 if ($scrollFlag) {
6109  
6110 if ($endIter->get_line() == $startIter->get_line()) {
6111  
6112 $self->scrollToBottom();
6113  
6114 } else {
6115  
6116 # Scroll to one line after the the matching text, as it looks nicer. The TRUE
6117 # argument means to scroll $self->textView2, if split-screen mode is one
6118 $self->scrollToIter(
6119 $self->buffer->get_iter_at_line_offset(($line + 1), 0),
6120 TRUE,
6121 );
6122 }
6123 }
6124  
6125 return 1;
6126 }
6127  
6128 sub unselectText {
6129  
6130 # Can be called by anything
6131 # Unselects any text in the textview (possibly from an earlier call to
6132 # $self->selectTextInLine)
6133 #
6134 # Expected arguments
6135 # (none besides $self)
6136 #
6137 # Return values
6138 # 'undef' on improper arguments
6139 # 1 otherwise
6140  
6141 my ($self, $check) = @_;
6142  
6143 # Local variables
6144 my $iter;
6145  
6146 # Check for improper arguments
6147 if (defined $check) {
6148  
6149 return $axmud::CLIENT->writeImproper($self->_objClass . '->unselectText', @_);
6150 }
6151  
6152 $iter = $self->buffer->get_iter_at_mark($self->searchMark);
6153 $self->buffer->select_range($iter, $iter);
6154  
6155 return 1;
6156 }
6157  
6158 # Other functions - must be called by specific code
6159  
6160 sub setupScroller {
6161  
6162 # Called by $self->objEnable, ->objUpdate and ->enableSingleScreen
6163 # Sets up the container widgets in which a single textview is displayed (when split screen
6164 # mode is off)
6165 #
6166 # Expected arguments
6167 # $textView - The Gtk3::TextView to pack into its container widgets
6168 #
6169 # Return values
6170 # 'undef' on improper arguments
6171 # Otherwise returns the Gtk3::ScrolledWindow which contains the textview
6172  
6173 my ($self, $textView, $check) = @_;
6174  
6175 # Check for improper arguments
6176 if (! defined $textView || defined $check) {
6177  
6178 return $axmud::CLIENT->writeImproper($self->_objClass . '->setupScroller', @_);
6179 }
6180  
6181 my $scroll = Gtk3::ScrolledWindow->new(undef, undef);
6182 $scroll->set_shadow_type($axmud::CLIENT->constShadowType);
6183 $scroll->set_policy('automatic', 'automatic'); # But word-wrapping turned on
6184 $scroll->set_border_width(0);
6185  
6186 # Pack the textview
6187 $scroll->add($textView);
6188  
6189 # Set up a ->signal_connect to detect scrolling, so we can reset the cursor (so the user
6190 # can't move the cursor above a link, wait until the link scrolls away, and then still
6191 # click the link)
6192 $self->setTextViewScrollEvent($scroll, $textView);
6193  
6194 return $scroll;
6195 }
6196  
6197 sub setupVPaned {
6198  
6199 # Called by $self->objUpdate, ->enableSplitScreen and ->enableHiddenSplitScreen
6200 # Sets up the container widgets in which the two textviews are displayed (when split screen
6201 # mode is on)
6202 #
6203 # Expected arguments
6204 # $textView, $textView2
6205 # - The Gtk3::TextViews to pack into their container widgets
6206 #
6207 # Return values
6208 # An empty list on improper arguments
6209 # Otherwise returns a list in the form
6210 # (vpaned, scrolled_window, scrolled_window)
6211  
6212 my ($self, $textView, $textView2, $check) = @_;
6213  
6214 # Local variables
6215 my (
6216 $width, $height,
6217 @emptyList,
6218 );
6219  
6220 # Check for improper arguments
6221 if (! defined $textView || ! defined $textView2 || defined $check) {
6222  
6223 $axmud::CLIENT->writeImproper($self->_objClass . '->setupVPaned', @_);
6224 return @emptyList;
6225 }
6226  
6227 my $vPaned = Gtk3::VPaned->new();
6228 $vPaned->set_wide_handle(TRUE);
6229  
6230 # Decide where to put the Gtk3::VPaned divider
6231 $self->setDividerPosn($vPaned);
6232  
6233 # When replacing a single textview with two, the original textview ($textView) is added to
6234 # the bottom half of the vpaned
6235 my $scroll = Gtk3::ScrolledWindow->new(undef, undef);
6236 $vPaned->pack2($scroll, FALSE, FALSE);
6237 $scroll->set_shadow_type($axmud::CLIENT->constShadowType);
6238 $scroll->set_policy('automatic', 'automatic'); # But word-wrapping turned on
6239 $scroll->set_border_width(0);
6240  
6241 my $scroll2 = Gtk3::ScrolledWindow->new(undef, undef);
6242 $vPaned->pack1($scroll2, FALSE, TRUE);
6243 $scroll2->set_shadow_type($axmud::CLIENT->constShadowType);
6244 $scroll2->set_policy('automatic', 'automatic'); # But word-wrapping turned on
6245 $scroll2->set_border_width(0);
6246  
6247 # Pack the textviews
6248 if ($textView->get_parent()) {
6249  
6250 $textView->unparent();
6251 }
6252  
6253 $scroll->add($textView);
6254 $scroll2->add($textView2);
6255  
6256 # Set up ->signal_connects to detect textview scrolling, so we can reset the cursor (so the
6257 # user can't move the cursor above a link, wait until the link scrolls away, and then
6258 # still click the link)
6259 $self->setTextViewScrollEvent($scroll, $textView);
6260 $self->setTextViewScrollEvent($scroll2, $textView2);
6261  
6262 return ($vPaned, $scroll, $scroll2)
6263 }
6264  
6265 sub setDividerPosn {
6266  
6267 # Called by $self->setupVPaned, ->enableSplitScreen and ->enableHiddenSplitScreen
6268 # In split screen modes 'split' and 'hidden', sets the position of the Gtk3::VPaned's
6269 # divider
6270 #
6271 # Expected arguments
6272 # $vPaned - The Gtk3::VPaned object
6273 #
6274 # Return values
6275 # 'undef' on improper arguments
6276 # 1 otherwise
6277  
6278 my ($self, $vPaned, $check) = @_;
6279  
6280 # Local variables
6281 my ($width, $height);
6282  
6283 # Check for improper arguments
6284 if (! defined $vPaned || defined $check) {
6285  
6286 return $axmud::CLIENT->writeImproper($self->_objClass . '->setDividerPosn', @_);
6287 }
6288  
6289 # Decide where to put the divider
6290 if ($self->splitScreenMode eq 'split') {
6291  
6292 ($width, $height) = $self->paneObj->getTabSize();
6293 if (! defined $height) {
6294 $vPaned->set_position(100);
6295 } else {
6296 $vPaned->set_position(int($height / 2));
6297 }
6298  
6299 } elsif ($self->splitScreenMode eq 'hidden') {
6300  
6301 # Setting the position of the divider directly to 0 does not work, but this does work,
6302 # for reasons unknown
6303 $vPaned->set_position(1);
6304 $vPaned->set_position(0);
6305 }
6306  
6307 return 1;
6308 }
6309  
6310 sub createTextViewWidget {
6311  
6312 # Called by various functions in this textview object (only) to create a uniform
6313 # Gtk3::Textview widget
6314 #
6315 # Expected arguments
6316 # $buffer - The Gtk3::TextBuffer to use in the textview
6317 #
6318 # Optional arguments
6319 # $schemeObj - The colour scheme object (GA::Obj::ColourScheme), if known; otherwise,
6320 # this function looks it up
6321 #
6322 # Return values
6323 # 'undef' on improper arguments
6324 # 1 otherwise
6325  
6326 my ($self, $buffer, $schemeObj, $check) = @_;
6327  
6328 # Check for improper arguments
6329 if (! defined $buffer || defined $check) {
6330  
6331 return $axmud::CLIENT->writeImproper($self->_objClass . '->createTextViewWidget', @_);
6332 }
6333  
6334 # Fetch the colour scheme object, if not supplied
6335 if (! $schemeObj) {
6336  
6337 $schemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme);
6338 }
6339  
6340 # Create the new textview
6341 my $textView = Gtk3::TextView->new_with_buffer($buffer);
6342  
6343 $textView->set_editable(FALSE);
6344 $textView->set_cursor_visible(FALSE); # Invisible cursor
6345 $textView->set_can_focus(FALSE);
6346 $textView->set_justification('left');
6347 $textView->set_overwrite($self->overwriteFlag);
6348  
6349 if ($schemeObj->wrapMode eq 'no_wrap') {
6350 $textView->set_wrap_mode('none');
6351 } elsif ($schemeObj->wrapMode eq 'wrap_char') {
6352 $textView->set_wrap_mode('char');
6353 } elsif ($schemeObj->wrapMode eq 'wrap_word') {
6354 $textView->set_wrap_mode('word');
6355 } elsif ($schemeObj->wrapMode eq 'wrap_word_char') {
6356 $textView->set_wrap_mode('word-char');
6357 }
6358  
6359 # Set up ->signal_connects
6360 $self->setMotionNotifyEvent($textView); # 'motion-notify-event'
6361 $self->setLeaveNotifyEvent($textView); # 'leave-notify-event'
6362 $self->setFocusOutEvent($textView); # 'focus-out-event'
6363 $self->setButtonPressEvent($textView); # 'button-press-event'
6364  
6365 return $textView;
6366 }
6367  
6368 sub createColourTags {
6369  
6370 # Called by $self->objEnable
6371 # Defines the colour tags used by this Gtk3::TextView to change text and underlay colours
6372 #
6373 # Expected arguments
6374 # (none besides $self)
6375 #
6376 # Return values
6377 # 'undef' on improper arguments
6378 # 1 otherwise
6379  
6380 my ($self, $check) = @_;
6381  
6382 # Local variables
6383 my (%colourTagHash, %boldColourTagHash, %xTermColourTagHash);
6384  
6385 # Check for improper arguments
6386 if (defined $check) {
6387  
6388 return $axmud::CLIENT->writeImproper($self->_objClass . '->createColourTags', @_);
6389 }
6390  
6391 # Import IVs (for convenience)
6392 %colourTagHash = $axmud::CLIENT->colourTagHash;
6393 %boldColourTagHash = $axmud::CLIENT->boldColourTagHash;
6394 %xTermColourTagHash = $axmud::CLIENT->xTermColourHash;
6395  
6396 # Standard (normal) colour tags
6397 foreach my $tag (keys %colourTagHash) {
6398  
6399 # Text colours have tags in the format 'green' for normal colours and 'GREEN' for bold
6400 # colours
6401 $self->buffer->create_tag(
6402 $tag,
6403 'foreground' => $colourTagHash{$tag},
6404 );
6405  
6406 # Underlay colours have tags in the format 'ul_green' for normal colours and 'UL_GREEN'
6407 # for bold colours
6408 $self->buffer->create_tag(
6409 'ul_' . $tag,
6410 'background' => $colourTagHash{$tag},
6411 );
6412 }
6413  
6414 # Standard (bold) colour tags
6415 foreach my $tag (keys %boldColourTagHash) {
6416  
6417 $self->buffer->create_tag(
6418 $tag,
6419 'foreground' => $boldColourTagHash{$tag},
6420 );
6421  
6422 $self->buffer->create_tag(
6423 'UL_' . $tag,
6424 'background' => $boldColourTagHash{$tag},
6425 );
6426 }
6427  
6428 # XTerm colour tags
6429 foreach my $tag (keys %xTermColourTagHash) {
6430  
6431 # Text colours, e.g. 'x255'
6432 $self->buffer->create_tag(
6433 $tag,
6434 'foreground' => $xTermColourTagHash{$tag},
6435 );
6436  
6437 # Underlay colours, e.g. 'ux255'
6438 $self->buffer->create_tag(
6439 'u' . $tag,
6440 'background' => $xTermColourTagHash{$tag},
6441 );
6442 }
6443  
6444 # (NB RGB colour tags, e.g. '#ABCDEF', are created by $self->interpretTags when required)
6445  
6446 return 1;
6447 }
6448  
6449 sub updateStandardTag {
6450  
6451 # Called by GA::Cmd::SetColour->do
6452 # Updates the Gtk3::TextTag for a specified Axmud standard text colour tag, when the colour
6453 # is modified
6454 # If the Gtk3::TextTag doesn't exist (for some reason), creates it
6455 #
6456 # Expected arguments
6457 # $tag - An Axmud standard text or underlay colour tag, e.g. 'red', 'BLUE', 'ul_red',
6458 # 'UL_BLUE')
6459 #
6460 # Return values
6461 # 'undef' on improper arguments or if $tag isn't an Axmud standard colour tag
6462 # 1 otherwise
6463  
6464 my ($self, $tag, $check) = @_;
6465  
6466 # Local variables
6467 my ($type, $underlayFlag, $boldType, $tagTable, $textTag, $rgb);
6468  
6469 # Check for improper arguments
6470 if (! defined $tag || defined $check) {
6471  
6472 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateStandardTag', @_);
6473 }
6474  
6475 # Check $tag is an Axmud standard colour tag
6476 ($type, $underlayFlag) = $axmud::CLIENT->checkColourTags($tag);
6477 $boldType = $axmud::CLIENT->checkBoldTags($tag);
6478  
6479 if (! $type || $type ne 'standard') {
6480  
6481 return undef;
6482 }
6483  
6484 # Get Gtk3 objects
6485 $tagTable = $self->buffer->get_tag_table();
6486 $textTag = $tagTable->lookup($tag);
6487 if (! $textTag) {
6488  
6489 # Add a new Gtk3::TextTag
6490 if (! $boldType) {
6491  
6492 if (! $underlayFlag) {
6493  
6494 $self->buffer->create_tag(
6495 $tag,
6496 'foreground' => $axmud::CLIENT->ivShow('colourTagHash', $tag),
6497 );
6498  
6499 } else {
6500  
6501 $self->buffer->create_tag(
6502 $tag,
6503 'background' => $axmud::CLIENT->returnRGBColour($tag),
6504 );
6505 }
6506  
6507 } else {
6508  
6509 if ($boldType eq 'text') {
6510  
6511 $self->buffer->create_tag(
6512 $tag,
6513 'foreground' => $axmud::CLIENT->ivShow('boldColourTagHash', $tag),
6514 );
6515  
6516 } else {
6517  
6518 $self->buffer->create_tag(
6519 $tag,
6520 'background' => $axmud::CLIENT->returnRGBColour($tag),
6521 );
6522 }
6523 }
6524  
6525 } else {
6526  
6527 # Modify an existing Gtk3::TextTag
6528 if (! $boldType) {
6529  
6530 if (! $underlayFlag) {
6531  
6532 $textTag->set_property(
6533 'foreground' => $axmud::CLIENT->ivShow('colourTagHash', $tag),
6534 );
6535  
6536 } else {
6537  
6538 $textTag->set_property(
6539 'background' => $axmud::CLIENT->returnRGBColour($tag),
6540 );
6541 }
6542  
6543 } else {
6544  
6545 if ($boldType eq 'text') {
6546  
6547 $textTag->set_property(
6548 'foreground' => $axmud::CLIENT->ivShow('boldColourTagHash', $tag),
6549 );
6550  
6551 } else {
6552  
6553 $textTag->set_property(
6554 'background' => $axmud::CLIENT->returnRGBColour($tag),
6555 );
6556 }
6557 }
6558 }
6559  
6560 return 1;
6561 }
6562  
6563 sub updateXTermTags {
6564  
6565 # Called by GA::Cmd::SetXTerm->do
6566 # Updates all Gtk3::TextTags for xterm colour tags, usually after the xterm colour cube is
6567 # switched
6568 # If the Gtk3::TextTag doesn't exist (for some reason), creates it
6569 #
6570 # Expected arguments
6571 # (none besides $self)
6572 #
6573 # Return values
6574 # 'undef' on improper arguments
6575 # 1 otherwise
6576  
6577 my ($self, $check) = @_;
6578  
6579 # Local variables
6580 my (
6581 $tagTable,
6582 %tagHash,
6583 );
6584  
6585 # Check for improper arguments
6586 if (defined $check) {
6587  
6588 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateXTermTags', @_);
6589 }
6590  
6591 # Import the IV
6592 %tagHash = $axmud::CLIENT->xTermColourHash;
6593 # Get Gtk3::TextTagTable
6594 $tagTable = $self->buffer->get_tag_table();
6595  
6596 # Update (or create) each xterm colour tag in turn
6597 foreach my $tag (keys %tagHash) {
6598  
6599 my ($textTag, $underlayTag);
6600  
6601 # Text colours, e.g. 'x255'
6602 $textTag = $tagTable->lookup($tag);
6603 if (! $textTag) {
6604  
6605 $self->buffer->create_tag(
6606 $tag,
6607 'foreground' => $tagHash{$tag},
6608 );
6609  
6610 } else {
6611  
6612 $textTag->set_property(
6613 'foreground' => $tagHash{$tag},
6614 );
6615 }
6616  
6617 # Underlay colours, e.g. 'ux255'
6618 $underlayTag = $tagTable->lookup('u' . $tag);
6619 if (! $underlayTag) {
6620  
6621 $self->buffer->create_tag(
6622 'u' . $tag,
6623 'background' => $tagHash{$tag},
6624 );
6625  
6626 } else {
6627  
6628 $underlayTag->set_property(
6629 'background' => $tagHash{$tag},
6630 );
6631 }
6632 }
6633  
6634 return 1;
6635 }
6636  
6637 sub updateRGBTags {
6638  
6639 # Called by $self->objEnable and ->objUpdate (only)
6640 # When a colour scheme is applied to this textview, $self->textColour and/or
6641 # ->underlayColour might be set
6642 # Gtk3::TextTags are usually created only as needed by $self->interpretTags, but that
6643 # function won't have a chance to create Gtk3::TextTags if $self->textColour and/or
6644 # ->underlayColour are now set to RGB colour tags like '#ABCDEF and 'u#ABCDEF'
6645 # Check which (if any) Gtk3::TextTags must be created, and create them
6646 #
6647 # Expected arguments
6648 # (none besides $self)
6649 #
6650 # Return values
6651 # 'undef' on improper arguments
6652 # 1 otherwise
6653  
6654 my ($self, $check) = @_;
6655  
6656 # Local variables
6657 my ($textColour, $underlayColour, $type, $ulFlag);
6658  
6659 # Check for improper arguments
6660 if (defined $check) {
6661  
6662 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateRGBTags', @_);
6663 }
6664  
6665 if ($self->textColour) {
6666  
6667 $textColour = $self->textColour;
6668  
6669 ($type, $ulFlag) = $axmud::CLIENT->checkColourTags($textColour, 'rgb');
6670 if (defined $type && ! $self->buffer->get_tag_table->lookup($textColour)) {
6671  
6672 if (! $ulFlag) {
6673  
6674 $self->buffer->create_tag(
6675 $textColour, # e.g. '#FFFFFF'
6676 'foreground' => $textColour, # e.g. '#FFFFFF'
6677 );
6678  
6679 } else {
6680  
6681 # This should never be executed, but it's better to be safe than sorry
6682 $self->buffer->create_tag(
6683 $textColour, # e.g. 'u#FFFFFF'
6684 'background' => substr($textColour, 1), # e.g. '#FFFFFF'
6685 );
6686 }
6687 }
6688 }
6689  
6690 if ($self->underlayColour) {
6691  
6692 $underlayColour = $self->underlayColour;
6693  
6694 ($type, $ulFlag) = $axmud::CLIENT->checkColourTags($underlayColour, 'rgb');
6695 if (defined $type && ! $self->buffer->get_tag_table->lookup($underlayColour)) {
6696  
6697 if ($ulFlag) {
6698  
6699 $self->buffer->create_tag(
6700 $underlayColour, # e.g. 'u#FFFFFF'
6701 'background' => substr($underlayColour, 1), # e.g. '#FFFFFF'
6702 );
6703  
6704 } else {
6705  
6706 # This should never be executed, but it's better to be safe than sorry
6707 $self->buffer->create_tag(
6708 $underlayColour, # e.g. '#FFFFFF'
6709 'foreground' => $underlayColour, # e.g. '#FFFFFF'
6710 );
6711  
6712 }
6713 }
6714 }
6715  
6716 return 1;
6717 }
6718  
6719 sub updateLinkTag {
6720  
6721 # Called by GA::Session->detectPueblo
6722 # When Pueblo is enabled, links are displayed in cyan and with no underline (normally, they
6723 # are displayed with no particular colour, but with an underline)
6724 # This function modifies the Gtk3::TextTag's properties to display links in the correct way
6725 #
6726 # Expected arguments
6727 # (none besides $self)
6728 #
6729 # Return values
6730 # 'undef' on improper arguments or if the 'link' tag is not updated
6731 # 1 if the 'link' tag is updated
6732  
6733 my ($self, $check) = @_;
6734  
6735 # Local variables
6736 my $linkTag;
6737  
6738 if (! $self->buffer || $self->session->puebloMode ne 'client_agree') {
6739  
6740 return undef;
6741 }
6742  
6743 $linkTag = $self->buffer->get_tag_table->lookup('link');
6744 if (! $linkTag) {
6745  
6746 return undef;
6747 }
6748  
6749 $linkTag->set_property(
6750 'foreground',
6751 $axmud::CLIENT->returnRGBColour($axmud::CLIENT->constPuebloLinkColour),
6752 );
6753 $linkTag->set_property('foreground-set', TRUE);
6754 $linkTag->set_property('underline', 'none');
6755  
6756 return 1;
6757 }
6758  
6759 sub createStyleTags {
6760  
6761 # Called by $self->objEnable
6762 # Defines the style tags used by this Gtk3::TextView to change the text style
6763 #
6764 # Expected arguments
6765 # (none besides $self)
6766 #
6767 # Return values
6768 # 'undef' on improper arguments
6769 # 1 otherwise
6770  
6771 my ($self, $check) = @_;
6772  
6773 # Local variables
6774 my $background;
6775  
6776 # Check for improper arguments
6777 if (defined $check) {
6778  
6779 return $axmud::CLIENT->writeImproper($self->_objClass . '->createStyleTags', @_);
6780 }
6781  
6782 # Italics
6783 $self->buffer->create_tag(
6784 'italics',
6785 'style' => 'italic',
6786 );
6787  
6788 # Underline
6789 $self->buffer->create_tag(
6790 'underline',
6791 'underline' => 'single',
6792 );
6793  
6794 # Blink: because the 'blink_slow' tag is sent to Gtk3 after the text and/or underlay tags,
6795 # it overrules them when 'foreground-set' and 'background-set' are TRUE, but doesn't
6796 # overrule them when 'foreground-set' and 'background-set' are FALSE. We can make the text
6797 # blink by alternating the values between TRUE and FALSE.
6798 # NB Gtk3 doesn't understand Axmud colour tags like 'ul_green', so we must convert them to
6799 # RGB
6800 $background = $axmud::CLIENT->returnRGBColour($self->backgroundColour);
6801  
6802 # Blink slow
6803 $self->buffer->create_tag(
6804 'blink_slow',
6805 'foreground' => $background,
6806 'foreground-set' => TRUE, # Text initially invisible
6807 'background' => $background,
6808 'background-set' => TRUE, # Underlay initially invisible
6809 );
6810  
6811 # Blink fast
6812 $self->buffer->create_tag(
6813 'blink_fast',
6814 'foreground' => $background,
6815 'foreground-set' => TRUE,
6816 'background' => $background,
6817 'background-set' => TRUE,
6818 );
6819  
6820 # Strikethrough
6821 $self->buffer->create_tag(
6822 'strike',
6823 'strikethrough' => 1,
6824 );
6825  
6826 # Clickable links
6827 if ($self->session->puebloMode eq 'client_agree') {
6828  
6829 # In Pueblo mode, clickable links are cyan, and not underlined
6830 $self->buffer->create_tag(
6831 'link',
6832 'foreground' => $axmud::CLIENT->returnRGBColour(
6833 $axmud::CLIENT->constPuebloLinkColour,
6834 ),
6835 'foreground-set' => TRUE,
6836 );
6837  
6838 } else {
6839  
6840 # At all other times, clickable links are just underlined
6841 $self->buffer->create_tag(
6842 'link',
6843 'underline' => 'single',
6844 );
6845 }
6846  
6847 # Justification
6848 $self->buffer->create_tag(
6849 'justify_left',
6850 'justification' => 'left',
6851 );
6852  
6853 $self->buffer->create_tag(
6854 'justify_centre',
6855 'justification' => 'center',
6856 );
6857  
6858 $self->buffer->create_tag(
6859 'justify_right',
6860 'justification' => 'right',
6861 );
6862  
6863 $self->buffer->create_tag(
6864 'justify_default',
6865 'justification' => 'left',
6866 );
6867  
6868 # A special tag, not related to any Axmud colour/style tag, which handles a visible cursor
6869 # in the textview. Only one position in $self->buffer (if any) uses this tag at a time
6870 # It's added to the buffer after any text insertion operation, so it should overrule any
6871 # 'underline' tag that already exists at that position
6872 $self->buffer->create_tag(
6873 'cursor',
6874 'underline' => 'single',
6875 );
6876  
6877 return 1;
6878 }
6879  
6880 sub setMonochromeMode {
6881  
6882 # Called by GA::Table::Pane->applyMonochrome (must not be called directly)
6883 # Applies a monochrome colour scheme to the textview(s), using the specified background
6884 # colour, and choosing for itself a suitable text colour (if no text colour is
6885 # also specified)
6886 # Sets $self->monochromeFlag to TRUE, if it's not already set
6887 #
6888 # Expected arguments
6889 # (none besides $self)
6890 #
6891 # Optional arguments
6892 # $backgroundColour
6893 # - The background colour to use (can be any Axmud colour tag, e.g 'red'). If it's
6894 # an underlay tag like 'ul_red', the equivalent colour tag is used instead. If
6895 # 'undef', the background colour specified by $self->colourScheme is used
6896 # $textColour
6897 # - The text colour to use. Is normally 'undef', in which case this function will
6898 # choose a suitable text colour to match the background. Should be specified
6899 # if $backgroundColour is an Xterm or RGB colour tag, otherwise the text
6900 # colour might not suit the background colour
6901 #
6902 # Return values
6903 # 'undef' on improper arguments or if a specified $backgroundColour is not a recognised
6904 # Axmud colour tag
6905 # 1 otherwise
6906  
6907 my ($self, $backgroundColour, $textColour, $check) = @_;
6908  
6909 # Local variables
6910 my ($colourSchemeObj, $defaultFlag, $type, $underlayFlag);
6911  
6912 # Check for improper arguments
6913 if (defined $check) {
6914  
6915 return $axmud::CLIENT->writeImproper($self->_objClass . '->setMonochromeMode', @_);
6916 }
6917  
6918 $colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme);
6919  
6920 # If no $backgroundColour was specified, use the background colour from $self->colourScheme
6921 if (! defined $backgroundColour) {
6922  
6923 if ($colourSchemeObj) {
6924  
6925 $backgroundColour = $colourSchemeObj->backgroundColour;
6926 $defaultFlag = TRUE;
6927  
6928 } else {
6929  
6930 # Emergency fallback colour
6931 $backgroundColour = 'black';
6932 }
6933  
6934 } else {
6935  
6936 # Convert an underlay tag into a normal tag
6937 ($type, $underlayFlag) = $axmud::CLIENT->checkColourTags($backgroundColour);
6938 if ($type && $underlayFlag) {
6939  
6940 $backgroundColour = $axmud::CLIENT->swapColours($backgroundColour);
6941 }
6942 }
6943  
6944 # If no text colour was specified, choose one to match the background colour
6945 if (! $textColour) {
6946  
6947 if ($axmud::CLIENT->ivExists('constMonochromeHash', $backgroundColour)) {
6948  
6949 $textColour = $axmud::CLIENT->ivShow('constMonochromeHash', $backgroundColour);
6950  
6951 } elsif (! $defaultFlag) {
6952  
6953 # Non-standard background colour tag. Use a fallback text colour; if it doesn't
6954 # match the background colour well, that's the fault of the calling function for
6955 # not specifying $textColour
6956 if (uc($backgroundColour) eq '#FFFFFF' || lc($backgroundColour) eq 'x255') {
6957 $textColour = 'black';
6958 } else {
6959 $textColour = 'WHITE';
6960 }
6961  
6962 } elsif ($colourSchemeObj) {
6963  
6964 # Non-standard background colour tag supplied by the colour scheme, so use the text
6965 # colour supplied by the colour scheme
6966 $textColour = $colourSchemeObj->textColour;
6967  
6968 } else {
6969  
6970 # Emergency fallback colour
6971 $backgroundColour = 'white';
6972 }
6973 }
6974  
6975 # Update IVs. Underlay colours are not used in monochrome mode, so that IV is set to 'undef'
6976 $self->ivPoke('textColour', $textColour);
6977 $self->ivUndef('underlayColour');
6978 $self->ivPoke('backgroundColour', $backgroundColour);
6979 $self->ivPoke('monochromeFlag', TRUE);
6980  
6981 if (! $colourSchemeObj || $colourSchemeObj->backgroundColour eq $backgroundColour) {
6982 $self->ivPoke('monochromeModFlag', FALSE);
6983 } else {
6984 $self->ivPoke('monochromeModFlag', TRUE);
6985 }
6986  
6987 # Apply the monochrome colour scheme
6988 return $self->objUpdate();
6989 }
6990  
6991 sub resetMonochromeMode {
6992  
6993 # Called by GA::Table::Pane->removeMonochrome (must not be called directly)
6994 # Removes the monochrome colour scheme currently being used, and restores the colour scheme
6995 # specified by $self->colourScheme
6996 # Sets $self->monochromeFlag to FALSE, if it's not already set
6997 #
6998 # Expected arguments
6999 # (none besides $self)
7000 #
7001 # Return values
7002 # 'undef' on improper arguments or if a monochrome colour scheme isn't in use currently
7003 # 1 otherwise
7004  
7005 my ($self, $check) = @_;
7006  
7007 # Check for improper arguments
7008 if (defined $check) {
7009  
7010 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetMonochromeMode', @_);
7011 }
7012  
7013 if (! $self->monochromeFlag) {
7014  
7015 return undef;
7016  
7017 } else {
7018  
7019 $self->ivPoke('monochromeFlag', FALSE);
7020 $self->ivPoke('monochromeModFlag', FALSE);
7021  
7022 return $self->objUpdate($self->colourScheme);
7023 }
7024 }
7025  
7026 sub applyColourStyleTags {
7027  
7028 # Called by GA::Session->processLineSegment and ->applyTriggerStyle
7029 # Also called by GA::Buffer::Display->copyLine
7030 #
7031 # GA::CLIENT->constColourStyleHash specifies a standard format for describing the Axmud
7032 # colour/style tags that apply at some offset in some text
7033 # This function takes a hash in that format, describing the tags that apply to an
7034 # unspecified offset in this textview (which might have been displayed already, or not)
7035 # The hash is then updated using a list of Axmud colour/style tags, so that hash describes
7036 # the tags that apply to a later offset in this textview (that hasn't been displayed yet)
7037 #
7038 # Expected arguments
7039 # $session - The calling GA::Session
7040 # $listRef - A reference to a list of Axmud colour/style tags which are used to modify
7041 # the hash (can be an empty list)
7042 #
7043 # Optional arguments
7044 # %tagHash - A hash in the format specified by GA::CLIENT->constColourStyleHash, i.e.
7045 #
7046 # 'text' => 'undef' or an Axmud text colour tag, e.g. 'red' or
7047 # 'x230'
7048 # 'underlay' => 'undef' or an Axmud underlay colour tag, e.g. 'ul_white'
7049 # 'italics' => TRUE or FALSE
7050 # 'underline' => TRUE or FALSE
7051 # 'blink_slow' => TRUE or FALSE
7052 # 'blink_fast' => TRUE or FALSE
7053 # 'strike' => TRUE or FALSE
7054 # 'link' => TRUE or FALSE
7055 # 'mxp_font' => TRUE or FALSE
7056 # 'justify' => 'left', 'right', 'centre', or 'undef' to represent the
7057 # style tag 'justify_default'
7058 #
7059 # Return values
7060 # An empty list on improper arguments
7061 # Otherwise, returns the modified hash
7062  
7063 my ($self, $session, $listRef, %tagHash) = @_;
7064  
7065 # Local variables
7066 my (
7067 $attribsOffFlag,
7068 %styleHash, %justifyHash, %dummyHash,
7069 );
7070  
7071 # Check for improper arguments
7072 if (! defined $session || ! defined $listRef) {
7073  
7074 return $axmud::CLIENT->writeImproper($self->_objClass . '->applyColourStyleTags', @_);
7075 }
7076  
7077 # Import IVs (for quick lookup)
7078 %styleHash = $axmud::CLIENT->constStyleTagHash;
7079 %justifyHash = $axmud::CLIENT->constJustifyTagHash;
7080 %dummyHash = $axmud::CLIENT->constDummyTagHash;
7081  
7082 foreach my $tag (@$listRef) {
7083  
7084 my ($type, $underlayFlag, $boldishTag);
7085  
7086 # When called by GA::Session->applyTriggerStyle, @tagList can contain bold text colour
7087 # tags like 'BLUE'. When called by GA::Session->processLineSegment, @tagList would
7088 # instead contain the pair 'bold', 'blue'
7089 # @tagList might also contain bold underlay colours like 'UL_BLUE', but that doesn't
7090 # affect the setting of $tagHash{'bold'} (which only applies to text colours)
7091 $type = $axmud::CLIENT->checkBoldTags($tag);
7092 if ($type && $type eq 'text') {
7093  
7094 # $tag is a bold colour tag. Pretend that we processed a 'bold' dummy tag during
7095 # the last iteration of this loop
7096 $tagHash{'bold'} = TRUE;
7097 # Since we're about to change the text colour, we can rely on the following code to
7098 # take care of $tagHash{'text'}, $tagHash{'real_text'} and so on
7099 $tag = lc($tag);
7100 }
7101  
7102 # PART 1: 'Dummy' style tags
7103 if (exists $dummyHash{$tag}) {
7104  
7105 if ($tag eq 'attribs_off') {
7106  
7107 # A dummy tag created by GA::Session->processEscSequence, which corresponds to
7108 # 'all attributes off'. We implement this by resetting %tagHash
7109 %tagHash = $axmud::CLIENT->constColourStyleHash;
7110 $attribsOffFlag = TRUE;
7111  
7112 } elsif ($tag eq 'bold') {
7113  
7114 # A 'dummy' style tag
7115 if (! $tagHash{'bold'}) {
7116  
7117 $tagHash{'bold'} = TRUE;
7118  
7119 # (If %tagHash currently contains no text colour, we have to add one, so
7120 # that the bold text is visible)
7121 if (! $tagHash{'real_text'}) {
7122 $tagHash{'real_text'} = uc($self->textColour);
7123 } else {
7124 $tagHash{'real_text'} = uc($tagHash{'real_text'});
7125 }
7126  
7127 # In conceal mode we don't make any changes to $tagHash{'text'} and
7128 # $tagHash{'underlay'}
7129 if ($tagHash{'reverse'}) {
7130  
7131 $tagHash{'underlay'}
7132 = $axmud::CLIENT->swapColours($tagHash{'real_text'});
7133  
7134 } elsif (! $tagHash{'conceal'}) {
7135  
7136 $tagHash{'text'} = $tagHash{'real_text'};
7137 }
7138  
7139 # In conceal mode and reverse video mode, changing the underlay colour has
7140 # no effect
7141 if (! $tagHash{'conceal'} && ! $tagHash{'reverse'}) {
7142  
7143 $tagHash{'underlay'} = $tagHash{'real_underlay'};
7144 }
7145 }
7146  
7147 # (A second 'bold' tag is ignored)
7148  
7149 } elsif ($tag eq 'bold_off') {
7150  
7151 # A 'dummy' style tag
7152 if ($tagHash{'bold'}) {
7153  
7154 $tagHash{'bold'} = FALSE;
7155  
7156 if ($tagHash{'real_text'}) {
7157  
7158 $tagHash{'real_text'} = lc($tagHash{'real_text'});
7159 }
7160  
7161 if ($tagHash{'reverse'}) {
7162  
7163 $tagHash{'underlay'}
7164 = $axmud::CLIENT->swapColours($tagHash{'real_text'});
7165  
7166 } elsif (! $tagHash{'conceal'}) {
7167  
7168 $tagHash{'text'} = $tagHash{'real_text'};
7169 }
7170  
7171 # In conceal mode and reverse video mode, changing the underlay colour has
7172 # no effect
7173 if (! $tagHash{'conceal'} && ! $tagHash{'reverse'}) {
7174  
7175 $tagHash{'underlay'} = $tagHash{'real_underlay'};
7176 }
7177 }
7178  
7179 # (A second consecutive 'bold_off' tag is ignored)
7180  
7181 } elsif ($tag eq 'reverse') {
7182  
7183 # A 'dummy' style tag
7184 if (! $tagHash{'reverse'}) {
7185  
7186 $tagHash{'reverse'} = TRUE;
7187  
7188 # In reverse video mode, the existing text colour is used as the underlay
7189 # colour. The existing underlay colour is ignored, if it is set, because
7190 # reverse video was designed for monochrome monitors
7191 # In addition, the textview background colour is used as the new text colour
7192  
7193 # Conceal mode takes priority over reverse video mode, if that is already on
7194 if (! $tagHash{'conceal'}) {
7195  
7196 $tagHash{'text'} = $self->backgroundColour;
7197 if ($tagHash{'real_text'}) {
7198  
7199 $tagHash{'underlay'}
7200 = $axmud::CLIENT->swapColours($tagHash{'real_text'});
7201  
7202 } else {
7203  
7204 $tagHash{'underlay'}
7205 = $axmud::CLIENT->swapColours($self->textColour);
7206 }
7207 }
7208 }
7209  
7210 # (A second 'reverse' tag is ignored)
7211  
7212 } elsif ($tag eq 'reverse_off') {
7213  
7214 # A 'dummy' style tag
7215 if ($tagHash{'reverse'}) {
7216  
7217 $tagHash{'reverse'} = FALSE;
7218 if (! $tagHash{'conceal'}) {
7219  
7220 $tagHash{'text'} = $tagHash{'real_text'};
7221 $tagHash{'underlay'} = $tagHash{'real_underlay'};
7222 }
7223 }
7224  
7225 # (A second consecutive 'reverse_off' tag is ignored)
7226  
7227 } elsif ($tag eq 'conceal') {
7228  
7229 # A 'dummy' style tag
7230 if (! $tagHash{'conceal'}) {
7231  
7232 $tagHash{'conceal'} = TRUE;
7233  
7234 # In conceal mode, both the text and underlay colours are set to the same as
7235 # the textview background colour, so that the text is invisible unless the
7236 # user selects it with the mouse
7237 # Conceal mode takes priority over reverse video mode, if that is already on
7238 $tagHash{'text'} = $self->backgroundColour;
7239 $tagHash{'underlay'}
7240 = $axmud::CLIENT->swapColours($self->backgroundColour);
7241 }
7242  
7243 # (A second 'conceal' tag is ignored)
7244  
7245 } elsif ($tag eq 'conceal_off') {
7246  
7247 # A 'dummy' style tag
7248 if ($tagHash{'conceal'}) {
7249  
7250 $tagHash{'conceal'} = FALSE;
7251 if ($tagHash{'reverse'}) {
7252  
7253 $tagHash{'text'} = $self->backgroundColour;
7254 $tagHash{'underlay'}
7255 = $axmud::CLIENT->swapColours($tagHash{'real_text'});
7256  
7257 } else {
7258  
7259 $tagHash{'text'} = $tagHash{'real_text'};
7260 $tagHash{'underlay'} = $tagHash{'real_underlay'};
7261 }
7262 }
7263  
7264 # (A second consecutive 'conceal_off' tag is ignored)
7265  
7266 } elsif ($tag eq 'mxpf_off') {
7267  
7268 # (Other 'mxpf_...' tags are handled below)
7269 $tagHash{'mxp_font'} = undef;
7270 }
7271  
7272 # PART 2: Justification style tags
7273 } elsif (exists $justifyHash{$tag}) {
7274  
7275 if ($tag eq 'justify_default') {
7276 $tagHash{'justify'} = undef;
7277 } else {
7278 $tagHash{'justify'} = substr($tag, 8);
7279 }
7280  
7281 # PART 3: Style tags
7282 } elsif (exists $styleHash{$tag}) {
7283  
7284 # (Codes listed in rough order of popularity)
7285 if ($tag eq 'link') {
7286  
7287 if ($tagHash{'link'}) {
7288 $tagHash{'link'} = FALSE;
7289 } else {
7290 $tagHash{'link'} = TRUE;
7291 }
7292  
7293 } elsif ($tag eq 'link_off') {
7294  
7295 $tagHash{'link'} = FALSE;
7296  
7297 } elsif (
7298 $tag eq 'italics'
7299 || $tag eq 'underline'
7300 || $tag eq 'blink_slow'
7301 || $tag eq 'blink_fast'
7302 || $tag eq 'strike'
7303 ) {
7304 # (A second consecutive tag reinforces the previous one)
7305 $tagHash{$tag} = TRUE;
7306  
7307 } elsif ($tag eq 'italics_off') {
7308  
7309 $tagHash{'italics'} = FALSE;
7310  
7311 } elsif ($tag eq 'underline_off') {
7312  
7313 $tagHash{'underline'} = FALSE;
7314  
7315 } elsif ($tag eq 'blink_off') {
7316  
7317 $tagHash{'blink_slow'} = FALSE;
7318 $tagHash{'blink_fast'} = FALSE;
7319  
7320 } elsif ($tag eq 'strike_off') {
7321  
7322 $tagHash{'strike'} = FALSE;
7323 }
7324  
7325 # PART 4: MXP style tags
7326 } elsif (substr($tag, 0, 5) eq 'mxpf_') {
7327  
7328 # Dummy style tags used for MXP fonts
7329 # Store the whole dummy tag, e.g. 'mxpf_monospace_bold_12' (NB 'mxpf_off' was
7330 # handled further above)
7331 $tagHash{'mxp_font'} = $tag;
7332  
7333 } elsif (substr($tag, 0, 5) eq 'mxpm_') {
7334  
7335 # Dummy style tag used for MXP modes in the range 10-12, 19, 20-99 (which don't
7336 # affect text attributes, so we don't add them to %tagHash)
7337 # ...
7338  
7339 # PART 5: Colour tags
7340 } else {
7341  
7342 ($type, $underlayFlag) = $axmud::CLIENT->checkColourTags($tag);
7343 if ($type) {
7344  
7345 if ($type eq 'standard') {
7346  
7347 # We're going to check $tag against the textview's object colour in a
7348 # moment, which is stored as (for example) 'RED' if it's a bold colour. We
7349 # need to compare it with 'RED', not 'red', if bold is on
7350 if ($tagHash{'bold'}) {
7351 $boldishTag = uc($tag);
7352 } else {
7353 $boldishTag = $tag;
7354 }
7355  
7356 } else {
7357  
7358 # xterm/RGB colour tags should be case insensitive
7359 $boldishTag = lc($tag);
7360 }
7361 }
7362  
7363 # PART 5a: Text colour tags
7364 if ($type && ! $underlayFlag) {
7365  
7366 if (
7367 defined $tagHash{'real_text'}
7368 && $tagHash{'real_text'} eq $tag
7369 ) {
7370 # (The re-occuring tag is ignored)
7371  
7372 } elsif ($attribsOffFlag && $boldishTag eq $self->textColour) {
7373  
7374 # After an 'attribs off', if the tag matches the 'main' window's normal text
7375 # colour, let that be the text colour
7376 # (This takes care of ANSI escape sequences like '^[0;37;40m', meaning
7377 # 'attribs off - white text - black underlay'. If we set
7378 # $tagHash{'underlay'} to 'ul_black', the next 'bold' tag - which was
7379 # intended to apply only to the text colour - will be applied to the
7380 # underlay colour, too.)
7381 $tagHash{'real_text'} = undef;
7382 if ($tagHash{'reverse'}) {
7383  
7384 $tagHash{'text'} = $self->backgroundColour;
7385 $tagHash{'underlay'}
7386 = $axmud::CLIENT->swapColours($self->textColour);
7387  
7388 } else {
7389  
7390 $tagHash{'text'} = $tagHash{'real_text'};
7391 }
7392  
7393 } elsif ($tagHash{'bold'} && $type eq 'standard') {
7394  
7395 # Bold text colour
7396 $tagHash{'real_text'} = uc($tag);
7397 # If the world is using an OSC colour palette to modify this colour, use the
7398 # modified form
7399 if ($session->ivExists('oscColourHash', $tagHash{'real_text'})) {
7400  
7401 $tagHash{'real_text'}
7402 = $session->ivShow('oscColourHash', $tagHash{'real_text'});
7403 }
7404  
7405 # In conceal mode we don't make any changes to $tagHash{'text'} and
7406 # $tagHash{'underlay'}
7407 if ($tagHash{'reverse'}) {
7408  
7409 $tagHash{'underlay'}
7410 = $axmud::CLIENT->swapColours($tagHash{'real_text'});
7411  
7412 } elsif (! $tagHash{'conceal'}) {
7413  
7414 $tagHash{'text'} = $tagHash{'real_text'};
7415 }
7416  
7417 } else {
7418  
7419 # Normal colour, or a bold underlay colour like 'UL_BLUE', specified
7420 # directly by a call from GA::Session->applyTriggerStyle
7421 $tagHash{'real_text'} = $tag;
7422 # If the world is using an OSC colour palette to modify this colour, use the
7423 # modified form
7424 if ($session->ivExists('oscColourHash', $tagHash{'real_text'})) {
7425  
7426 $tagHash{'real_text'}
7427 = $session->ivShow('oscColourHash', $tagHash{'real_text'});
7428 }
7429  
7430 if ($tagHash{'reverse'}) {
7431  
7432 $tagHash{'underlay'}
7433 = $axmud::CLIENT->swapColours($tagHash{'real_text'});
7434  
7435 } elsif (! $tagHash{'conceal'}) {
7436  
7437 $tagHash{'text'} = $tagHash{'real_text'};
7438 }
7439 }
7440  
7441 # PART 5b: Underlay colour tags
7442 } elsif ($type && $underlayFlag) {
7443  
7444 if (
7445 defined $tagHash{'real_underlay'}
7446 && $tagHash{'real_underlay'} eq $tag
7447 ) {
7448 # (The re-occuring tag is ignored)
7449  
7450 } elsif ($attribsOffFlag && $boldishTag eq $self->underlayColour) {
7451  
7452 # After an 'attribs off', if the tag matches the 'main' window's normal
7453 # underlay colour, let that be the underlay colour
7454 $tagHash{'real_underlay'} = undef;
7455  
7456 } else {
7457  
7458 $tagHash{'real_underlay'} = $tag;
7459  
7460 # If the world is using an OSC colour palette to modify this colour, use the
7461 # modified form
7462 if ($session->ivExists('oscColourHash', $tagHash{'real_underlay'})) {
7463  
7464 $tagHash{'real_underlay'}
7465 = $session->ivShow('oscColourHash', $tagHash{'real_underlay'});
7466 }
7467 }
7468  
7469 # In conceal mode and reverse video mode, changing the underlay colour has no
7470 # effect
7471 if (! $tagHash{'conceal'} && ! $tagHash{'reverse'}) {
7472  
7473 $tagHash{'underlay'} = $tagHash{'real_underlay'};
7474 }
7475 }
7476 }
7477 }
7478  
7479 return %tagHash;
7480 }
7481  
7482 sub listColourStyleTags {
7483  
7484 # Called by GA::Session->processLineSegment and GA::Buffer::Display->new, ->update
7485 # The argument is a hash, in the form specified by GA::CLIENT->constColourStyleHash, of
7486 # Axmud colour/style tags that apply at some offset in the textview. This function
7487 # converts the hash to a simple list
7488 #
7489 # Expected arguments
7490 # (none besides $self)
7491 #
7492 # Optional arguments
7493 # %tagHash - A hash of Axmud colour/style tags in the form specified by
7494 # GA::CLIENT->constColourStyleHash. If an empty hash,
7495 # $self->colourStyleHash is used instead
7496 #
7497 # Return values
7498 # An empty list on improper arguments
7499 # Otherwise, returns the converted list of Axmud colour/style tags (may be an empty list)
7500  
7501 my ($self, %tagHash) = @_;
7502  
7503 # Local variables
7504 my @returnList;
7505  
7506 # (No improper arguments to check)
7507  
7508 # Import this textview's current hash of colour/style tags, if no hash was specified
7509 if (! %tagHash) {
7510  
7511 %tagHash = $self->colourStyleHash;
7512 }
7513  
7514 # Compile a list of colour/style tags which now apply (tags listed in rough order of
7515 # popularity)
7516 if (defined $tagHash{'text'}) {
7517  
7518 push (@returnList, $tagHash{'text'});
7519 }
7520  
7521 if (defined $tagHash{'underlay'}) {
7522  
7523 push (@returnList, $tagHash{'underlay'});
7524 }
7525  
7526 if ($tagHash{'link'}) {
7527  
7528 push (@returnList, 'link');
7529 }
7530  
7531 if ($tagHash{'italics'}) {
7532  
7533 push (@returnList, 'italics');
7534 }
7535  
7536 if ($tagHash{'underline'}) {
7537  
7538 push (@returnList, 'underline');
7539 }
7540  
7541 if ($tagHash{'blink_slow'}) {
7542  
7543 push (@returnList, 'blink_slow');
7544 }
7545  
7546 if ($tagHash{'blink_fast'}) {
7547  
7548 push (@returnList, 'blink_fast');
7549 }
7550  
7551 if ($tagHash{'strike'}) {
7552  
7553 push (@returnList, 'strike');
7554 }
7555  
7556 if (defined $tagHash{'mxp_font'}) {
7557  
7558 push (@returnList, $tagHash{'mxp_font'});
7559 }
7560  
7561 if (defined $tagHash{'justify'}) {
7562  
7563 # e.g. 'justify_left'
7564 push (@returnList, 'justify_' . $tagHash{'justify'});
7565 }
7566  
7567 return @returnList;
7568 }
7569  
7570 sub showLinkTooltips {
7571  
7572 # Called by $self->checkMousePosn
7573 # Shows the tooltips window to display a link hint
7574 #
7575 # Expected arguments
7576 # $linkObj - The GA::Obj::Link whose ->hint must be displayed in the tooltip
7577 #
7578 # Return values
7579 # 'undef' on improper arguments or if the tooltip can't be shown
7580 # 1 otherwise
7581  
7582 my ($self, $linkObj, $check) = @_;
7583  
7584 # Local variables
7585 my $hint;
7586  
7587 # Check for improper arguments
7588 if (! defined $linkObj || defined $check) {
7589  
7590 return $axmud::CLIENT->writeImproper($self->_objClass . '->showLinkTooltips', @_);
7591 }
7592  
7593 # Don't show tooltips if the parent window isn't active, or if the GA::Obj::Link object
7594 # doesn't have a ->hint set
7595 $hint = $linkObj->hint;
7596 if (! $self->winObj->winWidget->is_active() || ! $hint) {
7597  
7598 return undef;
7599  
7600 } else {
7601  
7602 $self->textView->set_tooltip_text($hint);
7603 if ($self->textView2) {
7604  
7605 $self->textView2->set_tooltip_text($hint);
7606 }
7607  
7608 return 1;
7609 }
7610 }
7611  
7612 sub showSessionTooltips {
7613  
7614 # Called by $self->checkMousePosn (but only if this is the session's default textview, and
7615 # if the mouse is hovering over a line containing text received from the world)
7616 # Shows the tooltips window to display information about the display buffer objects
7617 # (GA::Buffer::Display) corresponding to this line
7618 #
7619 # Expected arguments
7620 # $lineNum - The line number of the Gtk3::TextBuffer line above which the mouse is
7621 # hovering
7622 #
7623 # Return values
7624 # 'undef' on improper arguments or if the tooltip can't be shown
7625 # 1 otherwise
7626  
7627 my ($self, $lineNum, $check) = @_;
7628  
7629 # Local variables
7630 my $tooltip;
7631  
7632 # Check for improper arguments
7633 if (! defined $lineNum || defined $check) {
7634  
7635 return $axmud::CLIENT->writeImproper($self->_objClass . '->showSessionTooltips', @_);
7636 }
7637  
7638 # Don't show tooltips if the parent window isn't active
7639 if (! $self->winObj->winWidget->is_active()) {
7640  
7641 return undef;
7642 }
7643  
7644 if (defined $self->lastTooltipLine && $self->lastTooltipLine != $lineNum) {
7645  
7646 # The mouse has moved over a new line. Make the tooltip window 'follow' it by
7647 # briefly resetting the tooltip
7648 $self->textView->set_tooltip_text('');
7649 if ($self->textView2) {
7650  
7651 $self->textView2->set_tooltip_text('');
7652 }
7653  
7654 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->checkMousePosn');
7655 }
7656  
7657 # Show the window
7658 $tooltip = $self->ivShow('tooltipHash', $lineNum);
7659 $self->textView->set_tooltip_text($tooltip);
7660 if ($self->textView2) {
7661  
7662 $self->textView2->set_tooltip_text($tooltip);
7663 }
7664  
7665 $self->ivPoke('lastTooltipLine', $lineNum);
7666  
7667 return 1;
7668 }
7669  
7670 sub hideTooltips {
7671  
7672 # Called by $self->checkMousePosn and various ->signal_connects in this textview object
7673 #
7674 # Expected arguments
7675 # (none besides $self)
7676 #
7677 # Return values
7678 # 'undef' on improper arguments or if the tooltip can't be hidden
7679 # 1 otherwise
7680  
7681 my ($self, $check) = @_;
7682  
7683 # Check for improper arguments
7684 if (defined $check) {
7685  
7686 return $axmud::CLIENT->writeImproper($self->_objClass . '->hideTooltips', @_);
7687 }
7688  
7689 # Hide the tooltips window
7690 $self->textView->set_tooltip_text('');
7691 if ($self->textView2) {
7692  
7693 $self->textView2->set_tooltip_text('');
7694 }
7695  
7696 # Update IVs
7697 $self->ivUndef('lastTooltipLine');
7698  
7699 return 1;
7700 }
7701  
7702 sub useDisplayBufferNum {
7703  
7704 # Called by GA::Session->processLineSegment (only)
7705 # The calling function is informing us that this textview object is its default textview
7706 # object, that it's about to call ->insertText, and that we should make a note of the
7707 # session's current display buffer line number, so we can display our tooltips correctly
7708 #
7709 # Expected arguments
7710 # $sessionLineNum - The session's display buffer line number (matching
7711 # GA::Session->displayBufferCount)
7712 #
7713 # Return values
7714 # 'undef' on improper arguments
7715  
7716 # 1 otherwise
7717  
7718 my ($self, $sessionLineNum, $check) = @_;
7719  
7720 # Local variables
7721 my $iter;
7722  
7723 # Check for improper arguments
7724 if (! defined $sessionLineNum || defined $check) {
7725  
7726 return $axmud::CLIENT->writeImproper($self->_objClass . '->useDisplayBufferNum', @_);
7727 }
7728  
7729 # The hash only needs to be updated, once per line of non-system message text
7730 # The Gtk3::Textbuffer renumbers its line every time we delete one from the beginning of the
7731 # buffer, so here we must add $self->nextDeleteLine
7732 if (! $self->insertMark && $self->newLineFlag) {
7733  
7734 $iter = $self->buffer->get_end_iter();
7735 $self->ivAdd(
7736 'tooltipHash',
7737 ($iter->get_line() + $self->nextDeleteLine),
7738 'Line ' . $sessionLineNum . ', ' . $axmud::CLIENT->localTime,
7739 );
7740 }
7741  
7742 return 1;
7743 }
7744  
7745 sub createPopupMenu {
7746  
7747 # Called by ->signal_connect in $self->setButtonPressEvent
7748 # After the user has clicked on $self->currentLinkObj, creates a popup menu from which the
7749 # user can select one of several menu items. If the user clicks on a menu item, the
7750 # corresponding world command is sent
7751 # The menu options and corresponding world commands are (usually) set by an MXP
7752 # <SEND>..</SEND> construction
7753 #
7754 # Expected arguments
7755 # $event - The 'button_press_event' signal emitted when the user clicks on a
7756 # clickable link in the tab
7757 #
7758 # Return values
7759 # 'undef' on improper arguments or if the popup menu can't be created
7760 # 1 otherwise
7761  
7762 my ($self, $event, $check) = @_;
7763  
7764 # Local variables
7765 my (
7766 $linkObj, $count,
7767 @optionList,
7768 );
7769  
7770 # Check for improper arguments
7771 if (! defined $event || defined $check) {
7772  
7773 return $axmud::CLIENT->writeImproper($self->_objClass . '->createPopupMenu', @_);
7774 }
7775  
7776 # Check there is a current link object set (no reason why there shouldn't be)
7777 if (! $self->currentLinkObj) {
7778  
7779 return undef;
7780  
7781 } else {
7782  
7783 # $self->currentLinkObj will be set to 'undef' as soon as the popup menu is clicked,
7784 # and before this function returns, so store the object as a local variable)
7785 $linkObj = $self->currentLinkObj;
7786 }
7787  
7788 # Create the popup menu
7789 my $menu = Gtk3::Menu->new();
7790  
7791 # The GA::Obj::Link stores menu items and corresponding world commands each as a single
7792 # string, with items/commands separated by a | character
7793 # (If there was an extra item in @optionList, representing an extra tooltip hint to show
7794 # e.g. "Click to see the menu", it has already been removed)
7795 @optionList = $linkObj->popupItemList;
7796  
7797 $count = -1;
7798 foreach my $cmd ($linkObj->popupCmdList) {
7799  
7800 my ($hint, $menuItem);
7801  
7802 $count++;
7803  
7804 # Prefer to use a hint over a raw command, if a hint was supplied
7805 $hint = shift (@optionList);
7806 $menuItem = Gtk3::MenuItem->new_with_label('');
7807  
7808 my $label = $menuItem->get_child();
7809 if ($hint) {
7810  
7811 if (! $count) {
7812 $label->set_markup('<b>' . $hint . '</b>');
7813 } else {
7814 $label->set_markup($hint);
7815 }
7816  
7817 } else {
7818  
7819 if (! $count) {
7820 $label->set_markup('<b>' . $cmd . '</b>');
7821 } else {
7822 $label->set_markup($cmd);
7823 }
7824 }
7825  
7826 $menu->append($menuItem);
7827 $menuItem->signal_connect('activate' => sub {
7828  
7829 my $stripObj = $self->paneObj->winObj->getStrip('entry');
7830  
7831 if ($linkObj->mxpPromptFlag && $stripObj) {
7832 $stripObj->commandeerEntry($self->session, $cmd);
7833 } else {
7834 $self->session->worldCmd($cmd);
7835 }
7836 });
7837 }
7838  
7839 $menu->popup(
7840 undef, undef, undef, undef,
7841 $event->button,
7842 $event->time,
7843 );
7844  
7845 $menu->show_all();
7846  
7847 # Store as an IV, so that $self->resetCurrentLink can destroy it, if the link expires
7848 $self->ivPoke('popupMenu', $menu);
7849 $menu->signal_connect('delete-event' => sub {
7850  
7851 $self->ivUndef('popupMenu');
7852  
7853 return undef;
7854 });
7855  
7856 return 1;
7857 }
7858  
7859 sub resetCurrentLink {
7860  
7861 # Called by GA::Session->processMxpOfficialElement when the GA::Obj::Link object stored in
7862 # $self->currentLinkObj expires
7863 # Hides tooltips, resets the cursor, closes the popup menu
7864 #
7865 # Expected arguments
7866 # (none besides $self)
7867 #
7868 # Return values
7869 # 'undef' on improper arguments or if this isn't the 'main' window
7870 # 1 otherwise
7871  
7872 my ($self, $check) = @_;
7873  
7874 # Check for improper arguments
7875 if (defined $check) {
7876  
7877 return $axmud::CLIENT->writeImproper($self->_objClass . '->resetCurrentLink', @_);
7878 }
7879  
7880 # Hide tooltips, if visible
7881 $self->hideTooltips();
7882  
7883 # Reset the cursor
7884 if ($self->textView) {
7885  
7886 $self->textView->get_window('text')->set_cursor($axmud::CLIENT->constNormalCursor);
7887 }
7888  
7889 # Close the popup menu
7890 if ($self->popupMenu) {
7891  
7892 $self->popupMenu->destroy();
7893  
7894 $self->ivUndef('popupMenu');
7895 }
7896  
7897 return 1;
7898 }
7899  
7900 sub toggleScrollLock {
7901  
7902 # Called by GA::Table::Pane->toggleScrollLock
7903 # Enables or disables this textview object's scroll lock mode, in which the textview scrolls
7904 # to the bottom every time text is received from the world. (If split screen mode is
7905 # enabled, only the original lower textview scrolls)
7906 #
7907 # Expected arguments
7908 # (none besides $self)
7909 #
7910 # Return values
7911 # 'undef' on improper arguments
7912 # 1 otherwise
7913  
7914 my ($self, $check) = @_;
7915  
7916 # Check for improper arguments
7917 if (defined $check) {
7918  
7919 return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleScrollLock', @_);
7920 }
7921  
7922 if (! $self->scrollLockFlag) {
7923  
7924 $self->ivPoke('scrollLockFlag', TRUE);
7925  
7926 # Scroll to the beginning/end of the buffer in the (original) textview immediately
7927 if ($self->scrollLockType eq 'top') {
7928 $self->scrollToTop();
7929 } else {
7930 $self->scrollToBottom();
7931 }
7932  
7933 } else {
7934  
7935 $self->ivPoke('scrollLockFlag', FALSE);
7936  
7937 $self->winObj->winShowAll($self->_objClass . '->toggleScrollLock');
7938 }
7939  
7940 # Operation complete
7941 return 1;
7942 }
7943  
7944 sub setSplitScreenMode {
7945  
7946 # Called by GA::Table::Pane->convertSimpleTab, ->convertTab and ->toggleSplitScreen
7947 # Sets this textview object's split screen mode, adding or removing a second textview and
7948 # repositioning the divider between two textviews as required
7949 # This is a convenience function. Axmud code is free to call $self->enableSingleScreen,
7950 # ->enableSplitScreen or ->enableHiddenSplitScreen directly, if preferred
7951 #
7952 # Expected arguments
7953 # $mode - One of the recognised values for $self->splitScreenMode, i.e. 'single',
7954 # 'split' or 'hidden'
7955 #
7956 # Return values
7957 # 'undef' on improper arguments or on general failure
7958 # If $mode is already the same value as $self->splitScreenMode, nothing happens and
7959 # 'undef' is returned
7960 # If $mode is 'split' or 'hidden', and if $self->splitScreenMode is already 'split' or
7961 # 'hidden', returns 'undef' (as no Gtk3 widgets need to be repacked)
7962 # If $mode is 'single' and $self->splitScreenMode is not 'single', or vice-versa, then
7963 # returns a packable widget which should be packed into the space occupied by the
7964 # previous packable widget
7965  
7966 my ($self, $mode, $check) = @_;
7967  
7968 # Check for improper arguments
7969 if (
7970 ! defined $mode
7971 || ($mode ne 'single' && $mode ne 'split' && $mode ne 'hidden')
7972 || defined $check
7973 ) {
7974 return $axmud::CLIENT->writeImproper($self->_objClass . '->setSplitScreenMode', @_);
7975 }
7976  
7977 if ($mode eq $self->splitScreenMode) {
7978  
7979 # No changes required
7980 return undef;
7981  
7982 } elsif ($mode eq 'single') {
7983  
7984 return $self->enableSingleScreen();
7985  
7986 } elsif ($mode eq 'split') {
7987  
7988 return $self->enableSplitScreen();
7989  
7990 } elsif ($mode eq 'hidden') {
7991  
7992 return $self->enableHiddenSplitScreen();
7993 }
7994 }
7995  
7996 sub enableSingleScreen {
7997  
7998 # Called by $self->setSplitScreenMode (or directly by any code)
7999 # Sets $self->splitScreenMode to 'single'
8000 # If $self->splitScreenMode was 'split' or 'hidden', replaces the existing Gtk3::VPaned,
8001 # containing two textviews, with a Gtk3::Frame containing a single textview, and returns
8002 # the frame. The calling function should pack the frame into the space previously occupied
8003 # by the vpaned
8004 #
8005 # Expected arguments
8006 # (none besides $self)
8007 #
8008 # Return values
8009 # 'undef' on improper arguments or if $self->splitScreenMode is already 'single'
8010 # Otherwise, returns the Gtk3::Frame
8011  
8012 my ($self, $check) = @_;
8013  
8014 # Check for improper arguments
8015 if (defined $check) {
8016  
8017 return $axmud::CLIENT->writeImproper($self->_objClass . '->enableSingleScreen');
8018 }
8019  
8020 if ($self->splitScreenMode eq 'single') {
8021  
8022 # Nothing needs to be re-packed
8023 return undef
8024  
8025 } else {
8026  
8027 # Set the new mode
8028 $self->ivPoke('splitScreenMode', 'single');
8029  
8030 # Create the new Gtk3::TextView, using the same Gtk3::TextBuffer as the original one
8031 my $textView = $self->createTextViewWidget($self->buffer);
8032  
8033 # Set the textview's CSS style
8034 $axmud::CLIENT->desktopObj->setTextViewObjStyle(
8035 $self->number,
8036 $self->textColour,
8037 $self->backgroundColour,
8038 $self->font,
8039 $self->fontSize,
8040 $textView,
8041 );
8042  
8043 # Pack the textview into a container widget
8044 my $scroll = $self->setupScroller($textView);
8045  
8046 # Update IVs again
8047 $self->ivPoke('textView', $textView);
8048 $self->ivUndef('textView2');
8049 $self->ivUndef('vPaned');
8050 $self->ivPoke('scroll', $scroll);
8051 $self->ivUndef('scroll2');
8052  
8053 # In case split screen mode has just been turned off, check that the textview's size
8054 # hasn't change (as soon as possible)
8055 $self->ivPoke('sizeUpdateFlag', TRUE);
8056  
8057 # Operation complete
8058 return $scroll;
8059 }
8060 }
8061  
8062 sub enableSplitScreen {
8063  
8064 # Called by $self->setSplitScreenMode (or directly by any code)
8065 # Sets $self->splitScreenMode to 'split'
8066 # If $self->splitScreenMode was 'single', replaces the existing Gtk3::Frame, containing a
8067 # single textview, with a Gtk3::VPaned, containing two textviews, and returns the vpaned.
8068 # The calling function should pack the vpaned into the space previously occupied by the
8069 # frame
8070 # If $self->splitScreenMode was 'hidden', moves the divider so that the hidden textview
8071 # becomes visible (if the user manually moved the divider, this function moves the
8072 # divider to its default position for this mode)
8073 #
8074 # Expected arguments
8075 # (none besides $self)
8076 #
8077 # Return values
8078 # 'undef' on improper arguments or if $self->splitScreenMode is currently 'split' or
8079 # 'hidden'
8080 # Otherwise, returns the Gtk3::VPaned
8081  
8082 my ($self, $check) = @_;
8083  
8084 # Check for improper arguments
8085 if (defined $check) {
8086  
8087 return $axmud::CLIENT->writeImproper($self->_objClass . '->enableSplitScreen');
8088 }
8089  
8090 if ($self->splitScreenMode eq 'split') {
8091  
8092 # Nothing needs to be re-packed
8093 return undef
8094  
8095 } else {
8096  
8097 if ($self->splitScreenMode eq 'hidden') {
8098  
8099 # Set the new mode
8100 $self->ivPoke('splitScreenMode', 'split');
8101  
8102 # Move the divider and rescroll textviews to the bottom (for tidiest visual effect)
8103 $self->setDividerPosn($self->vPaned);
8104 $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->enableSplitScreen');
8105 $self->scrollToLock();
8106  
8107 # Nothing needs to be re-packed
8108 return undef
8109  
8110 } else {
8111  
8112 # Set the new mode
8113 $self->ivPoke('splitScreenMode', 'split');
8114  
8115 # Create the new Gtk3::TextView, using the same Gtk3::TextBuffer as the original one
8116 my $textView2 = $self->createTextViewWidget($self->buffer);
8117  
8118 # Update the textviews' CSS style
8119 $axmud::CLIENT->desktopObj->setTextViewObjStyle(
8120 $self->number,
8121 $self->textColour,
8122 $self->backgroundColour,
8123 $self->font,
8124 $self->fontSize,
8125 $self->textView,
8126 $textView2,
8127 );
8128  
8129 # Pack the textviews into a container widget
8130 my ($vPaned, $scroll, $scroll2) = $self->setupVPaned($self->textView, $textView2);
8131  
8132 # Update IVs again
8133 $self->ivPoke('textView2', $textView2);
8134 $self->ivPoke('vPaned', $vPaned);
8135 $self->ivPoke('scroll', $scroll);
8136 $self->ivPoke('scroll2', $scroll2);
8137  
8138 # Operation complete
8139 return $vPaned;
8140 }
8141 }
8142 }
8143  
8144 sub enableHiddenSplitScreen {
8145  
8146 # Called by $self->setSplitScreenMode (or directly by any code)
8147 # Sets $self->splitScreenMode to 'hidden'
8148 # If $self->splitScreenMode was 'single', replaces the existing Gtk3::Frame, containing a
8149 # single textview, with a Gtk3::VPaned, containing two textviews, and returns the vpaned.
8150 # The calling function should pack the vpaned into the space previously occupied by the
8151 # frame
8152 # If $self->splitScreenMode was 'split', moves the divider so that the second textview
8153 # becomes hidden
8154 #
8155 # Expected arguments
8156 # (none besides $self)
8157 #
8158 # Return values
8159 # 'undef' on improper arguments or if $self->splitScreenMode is currently 'split' or
8160 # 'hidden'
8161 # Otherwise, returns the Gtk3::VPaned
8162  
8163 my ($self, $check) = @_;
8164  
8165 # Check for improper arguments
8166 if (defined $check) {
8167  
8168 return $axmud::CLIENT->writeImproper($self->_objClass . '->enableHiddenSplitScreen');
8169 }
8170  
8171 if ($self->splitScreenMode eq 'hidden') {
8172  
8173 # Nothing needs to be re-packed
8174 return undef
8175  
8176 } else {
8177  
8178 if ($self->splitScreenMode eq 'split') {
8179  
8180 # Set the new mode
8181 $self->ivPoke('splitScreenMode', 'hidden');
8182  
8183 # Move the divider and rescroll textviews to the bottom (for tidiest visual effect)
8184 $self->setDividerPosn($self->vPaned);
8185 $axmud::CLIENT->desktopObj->updateWidgets(
8186 $self->_objClass . '->enableHiddenSplitScreen',
8187 );
8188  
8189 $self->scrollToLock();
8190  
8191 # In case split screen mode has just been turned off, check that the textview's size
8192 # hasn't change (as soon as possible)
8193 $self->ivPoke('sizeUpdateFlag', TRUE);
8194  
8195 # Nothing needs to be re-packed
8196 return undef
8197  
8198 } else {
8199  
8200 # Set the new mode
8201 $self->ivPoke('splitScreenMode', 'hidden');
8202  
8203 # Create the new Gtk3::TextView, using the same Gtk3::TextBuffer as the original one
8204 my $textView2 = $self->createTextViewWidget($self->buffer);
8205  
8206 # Update the textviews' CSS style
8207 $axmud::CLIENT->desktopObj->setTextViewObjStyle(
8208 $self->number,
8209 $self->textColour,
8210 $self->backgroundColour,
8211 $self->font,
8212 $self->fontSize,
8213 $self->textView,
8214 $textView2,
8215 );
8216  
8217 # Pack the textviews into a container widget
8218 my ($vPaned, $scroll, $scroll2) = $self->setupVPaned($self->textView, $textView2);
8219  
8220 # Update IVs again
8221 $self->ivPoke('textView2', $textView2);
8222 $self->ivPoke('vPaned', $vPaned);
8223 $self->ivPoke('scroll', $scroll);
8224 $self->ivPoke('scroll2', $scroll2);
8225  
8226 # Operation complete
8227 return $vPaned;
8228 }
8229 }
8230 }
8231  
8232 sub checkMousePosn {
8233  
8234 # Called by ->signal_connects in $self->setMotionNotifyEvent
8235 # When the mouse moves over a clickable link in a Gtk3::TextView, we should change the mouse
8236 # cursor. When the mouse moves away from a clickable link, we should restore the mouse
8237 # cursor
8238 #
8239 # NB This function isn't used for clickable images. ->signal_connects for that are found in
8240 # $self->showImage
8241 #
8242 # Expected arguments
8243 # $textView - The Gtk3::TextView over which the mouse is moving
8244 # $event - The Gtk3::Gdk::Event
8245 #
8246 # Return values
8247 # 'undef' on improper arguments
8248 # 1 on success
8249  
8250 my ($self, $textView, $event, $check) = @_;
8251  
8252 # Local variables
8253 my (
8254 $xPos, $yPos, $iter, $lineNum, $posn, $hoverFlag, $listRef, $window, $listRef2,
8255 $linkObj, $tooltipsFlag, $tooltip,
8256 );
8257  
8258 # Check for improper arguments
8259 if (! defined $textView || ! defined $event || defined $check) {
8260  
8261 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkMousePosn', @_);
8262 }
8263  
8264 # Get the mouse's position over the textview's buffer
8265 ($xPos, $yPos) = $textView->window_to_buffer_coords('widget', $event->x, $event->y);
8266 # Get the buffer iter corresponding to that position
8267 $iter = $textView->get_iter_at_location($xPos, $yPos);
8268 # Get the offsets for the buffer line and character directly beneath the mouse
8269 $lineNum = $iter->get_line();
8270 $posn = $iter->get_visible_line_offset();
8271  
8272 # Get all the tags associated with this iter, looking for the Axmud style tag 'link'
8273 # (Setting this flag makes any debug messages we might insert work without errors)
8274 $hoverFlag = FALSE;
8275 $listRef = $iter->get_tags();
8276 if (defined $listRef) {
8277  
8278 OUTER: foreach my $tag (@$listRef) {
8279  
8280 if ($tag->get_property('name') eq 'link') {
8281  
8282 $hoverFlag = TRUE;
8283 last OUTER;
8284 }
8285 }
8286 }
8287  
8288 # Only change the cursor, if the mouse has moved from a link to normal space, or vice-versa;
8289 # of if the mouse has moved from one link to another
8290 $window = $textView->get_window('text');
8291 if (! $hoverFlag && $self->currentLinkObj) {
8292  
8293 # Reset the cursor
8294 $self->ivUndef('currentLinkObj');
8295 $window->set_cursor($axmud::CLIENT->constNormalCursor);
8296 # Hide tooltips
8297 $self->hideTooltips();
8298  
8299 } elsif ($hoverFlag) {
8300  
8301 # Find the corresponding GA::Obj::Link
8302 $listRef = $self->ivShow('linkObjLineHash', $lineNum + $self->nextDeleteLine);
8303 if (defined $listRef) {
8304  
8305 OUTER: foreach my $thisLinkObj (@$listRef) {
8306  
8307 my $endPosn = $thisLinkObj->posn + length ($thisLinkObj->text);
8308  
8309 if ($posn >= $thisLinkObj->posn && $posn < $endPosn) {
8310  
8311 # Found the corresponding GA::Obj::Link
8312 $linkObj = $thisLinkObj;
8313 last OUTER;
8314 }
8315 }
8316 }
8317  
8318 if (! $linkObj) {
8319  
8320 # Mouse is not above a link (or error finding a link)
8321 $self->ivUndef('currentLinkObj');
8322 $window->set_cursor($axmud::CLIENT->constNormalCursor);
8323 # Hide tooltips
8324 $self->hideTooltips();
8325  
8326 } elsif (! $self->currentLinkObj || $self->currentLinkObj ne $linkObj) {
8327  
8328 # Mouse is above a new link
8329 if ($linkObj->expiredFlag) {
8330  
8331 # It's an expired link
8332 $self->ivUndef('currentLinkObj');
8333 $window->set_cursor($axmud::CLIENT->constNormalCursor);
8334 # Hide tooltips
8335 $self->hideTooltips();
8336  
8337 } else {
8338  
8339 # Not an expired link
8340 $self->ivPoke('currentLinkObj', $linkObj);
8341  
8342 if ($linkObj->type eq 'www') {
8343  
8344 $window->set_cursor($axmud::CLIENT->constWWWCursor);
8345  
8346 } elsif ($linkObj->type eq 'cmd') {
8347  
8348 # (Check ->popupFlag first, because a popup menu can also redirect to a
8349 # prompt)
8350 if ($linkObj->popupFlag) {
8351 $window->set_cursor($axmud::CLIENT->constPopupCursor);
8352 } elsif ($linkObj->mxpPromptFlag) {
8353 $window->set_cursor($axmud::CLIENT->constPromptCursor);
8354 } else {
8355 $window->set_cursor($axmud::CLIENT->constCmdCursor);
8356 }
8357  
8358 } elsif ($linkObj->type eq 'mail') {
8359  
8360 $window->set_cursor($axmud::CLIENT->constMailCursor);
8361  
8362 } elsif (
8363 $linkObj->type eq 'telnet'
8364 || $linkObj->type eq 'ssh'
8365 || $linkObj->type eq 'ssl'
8366 ) {
8367 $window->set_cursor($axmud::CLIENT->constTelnetCursor);
8368  
8369 } elsif ($linkObj->type eq 'image') {
8370  
8371 $axmud::CLIENT->writeDebug(
8372 'Mouse above image link; examine code please',
8373 $self->_objClass . '->checkMousePosn',
8374 );
8375  
8376 } elsif ($linkObj->type eq 'other') {
8377  
8378 $window->set_cursor($axmud::CLIENT->constNormalCursor);
8379 }
8380  
8381 # If it's an MXP link with a hint, show the hint in the tooltip window
8382 if ($linkObj->hint) {
8383  
8384 # Unhide the tooltips window and display $linkObj's ->hint
8385 $self->showLinkTooltips($linkObj);
8386 $tooltipsFlag = TRUE;
8387  
8388 } else {
8389  
8390 # Hide the tooltips window
8391 $self->hideTooltips();
8392 }
8393 }
8394 }
8395 }
8396  
8397 # If there's no link tooltip visible, consider showing the session tooltip instead
8398 if ($axmud::CLIENT->mainWinTooltipFlag && ! $tooltipsFlag && ! $self->currentLinkObj) {
8399  
8400 # Only lines created by the GA::Session, and displayed in its default textview object,
8401 # cause key-value pairs to be added to this hash
8402 # NB The Gtk3::Textbuffer renumbers its line every time we delete one from the
8403 # beginning of the buffer, so here we must add $self->nextDeleteLine
8404 if ($self->ivExists('tooltipHash', ($lineNum + $self->nextDeleteLine))) {
8405  
8406 $self->showSessionTooltips($lineNum + $self->nextDeleteLine);
8407  
8408 } elsif ($self->lastTooltipLine) {
8409  
8410 $self->hideTooltips();
8411 }
8412 }
8413  
8414 return 1;
8415 }
8416  
8417 sub updateVisibleSize {
8418  
8419 # Called by Games::Axmud::Obj::Desktop->updateWidgets (only) for any textview object whose
8420 # ->sizeUpdateFlag is set
8421 # Updates IVs and informs the GA::Session
8422 #
8423 # Expected arguments
8424 # (none besides $self)
8425 #
8426 # Return values
8427 # 'undef' on improper arguments
8428 # 1 otherwise
8429  
8430 my ($self, $check) = @_;
8431  
8432 # Local variables
8433 my ($charWidth, $charHeight, $hashRef, $textViewWidth, $textViewHeight);
8434  
8435 # Check for improper arguments
8436 if (defined $check) {
8437  
8438 return $axmud::CLIENT->writeImproper($self->_objClass . '->updateVisibleSize', @_);
8439 }
8440  
8441 # Do nothing while split screen mode is on
8442 if ($self->splitScreenMode ne 'split') {
8443  
8444 # Get the width/height of a character in the Gtk3::TextView
8445 ($charWidth, $charHeight) = $self->getCharSize();
8446 # Get a Gtk3::Gdk::Rectangle
8447 $hashRef = $self->textView->get_visible_rect();
8448 # Get the size of the textview
8449 $textViewWidth = int($$hashRef{width} / $charWidth);
8450 $textViewHeight = int($$hashRef{height} / $charHeight);
8451  
8452 if (
8453 ! defined $self->textWidthChars
8454 || $textViewWidth != $self->textWidthChars
8455 || $textViewHeight != $self->textHeightChars
8456 ) {
8457 # The size has changed. Update IVs...
8458 $self->ivPoke('textWidthChars', $textViewWidth);
8459 $self->ivPoke('textHeightChars', $textViewHeight);
8460 # ...and inform the parent GA::Session
8461 $self->session->textViewSizeUpdate($self);
8462 }
8463 }
8464  
8465 $self->ivPoke('sizeUpdateFlag', FALSE);
8466  
8467 return 1;
8468 }
8469  
8470 sub getCharSize {
8471  
8472 # Called by $self->updateVisibleSize
8473 # Gets the size (in pixels) of a single character in the Gtk3::TextView
8474 #
8475 # Expected arguments
8476 # (none besides $self)
8477 #
8478 # Optional arguments
8479 # $char - The character whose size should be found. If 'undef', the character 'w'
8480 # is tested
8481 #
8482 # Return values
8483 # An empty list on improper arguments
8484 # Otherwise returns a list in the form (width_pixels, height_pixels)
8485  
8486 my ($self, $char, $check) = @_;
8487  
8488 # Local variables
8489 my (
8490 $layout, $inkRect, $logicalRect,
8491 @emptyList,
8492 );
8493  
8494 # Check for improper arguments
8495 if (defined $check) {
8496  
8497 $axmud::CLIENT->writeImproper($self->_objClass . '->getCharSize', @_);
8498 return @emptyList;
8499 }
8500  
8501 if (! $char) {
8502  
8503 $char = 'w';
8504 }
8505  
8506 # Get the Pango::Layout representing the character in this session's textview
8507 $layout = $self->textView->create_pango_layout($char);
8508  
8509 # Get the width/height of the character
8510 ($inkRect, $logicalRect) = $layout->get_pixel_extents();
8511  
8512 return ($$logicalRect{'width'}, $$logicalRect{'height'});
8513 }
8514  
8515 sub getLineLength {
8516  
8517 # For reasons unknown, calls to Gtk3::TextIter->get_chars_in_line returns the actual number
8518 # of characters in a line, plus 10,000
8519 # Return the number of characters in a line, subtracting 10,000 if necessary
8520 #
8521 # Expected arguments
8522 # $iter - A Gtk3::TextIter anywhere on the line
8523 #
8524 # Return values
8525 # 'undef' on improper arguments
8526 # Otherwise returns the (real) number of characters on the line
8527  
8528 my ($self, $iter, $check) = @_;
8529  
8530 # Local variables
8531 my $count;
8532  
8533 # Check for improper arguments
8534 if (! defined $iter || defined $check) {
8535  
8536 return $axmud::CLIENT->writeImproper($self->_objClass . '->getLineLength', @_);
8537 }
8538  
8539 $count = $iter->get_chars_in_line();
8540 if ($count >= 10000) {
8541  
8542 $count -= 10000;
8543 }
8544  
8545 return $count;
8546 }
8547  
8548 sub setupLink {
8549  
8550 # Called by $self->insertText and ->showSystemText
8551 # Just before a clickable link is displayed in the textview, creates a GA::Obj::Link (or
8552 # amends an existing one) to store data until the user clicks on the link
8553 #
8554 # Expected arguments
8555 # $iter - The Gtk3::TextIter marking the position in the Gtk3::TextBuffer
8556 # (stored in $self->buffer) at which the link will be displayed
8557 # $text - The text of the link itself
8558 #
8559 # Return values
8560 # 'undef' on improper arguments or if the link can't be created/amended
8561 # 1 otherwise
8562  
8563 my ($self, $iter, $text, $check) = @_;
8564  
8565 # Local variables
8566 my ($lineNum, $posn, $short, $email, $type, $listRef, $objNum, $linkObj);
8567  
8568 # Check for improper arguments
8569 if (! defined $iter || ! defined $text || defined $check) {
8570  
8571 return $axmud::CLIENT->writeImproper($self->_objClass . '->setupLink', @_);
8572 }
8573  
8574 # Get the position of the start of the link. If the buffer is full, take account of any
8575 # lines that have been deleted from the start of it
8576 $lineNum = $iter->get_line() + $self->nextDeleteLine;
8577 $posn = $iter->get_line_offset();
8578  
8579 # Check $text to see if it matches the start of an acceptable link, in the form
8580 # http://deathmud.org - a URL opened by GA::Client->browserCmd
8581 # deathmud.org - a URL opened by GA::Client->browserCmd
8582 # mailto:god@deathmud.org - an email sent by GA::Client->emailCmd
8583 # admin@deathmud.org - an email sent by GA::Client->emailCmd
8584 # telnet://deathmud.org:6666 - a new connection to a world, using telnet
8585 # telnet://deathmud.org - a new connection to a world, port 23
8586 # ssh://deathmud.org:6666 - a new connection to a world, using SSH
8587 # ssh://deathmud.org - a new connection to a world, generic port
8588 # ssl://deathmud.org:6666 - a new connection to a world, using SSL
8589 # ssl://deathmud.org - a new connection to a world, generic port
8590 # NB We don't check against GA::Client->constUrlRegex, etc, because $text might not contain
8591 # the whole link, but we do check against GA::Client->constShortUrlRegex and against an
8592 # email link without the mailto: part, in the hope that it was probably displayed by a
8593 # single call to $self->insertText, etc
8594 # NB This function isn't used for MXP links, for which a GA::Obj::Link has already been
8595 # created
8596 $short = '^' . $axmud::CLIENT->constShortUrlRegex;
8597 $email = '^' . $axmud::CLIENT->constEmailRegex;
8598  
8599 # (Check email first, otherwise gmail.com is detected and fred@gmail.com isn't)
8600 if ($text =~ m/^mailto\:/i || $text =~ m/$email/i) {
8601  
8602 $type = 'mail';
8603  
8604 } elsif (
8605 $text =~ m/^https?\:\/\//i
8606 || ($axmud::CLIENT->shortUrlFlag && $text =~ m/$short/i)
8607 ) {
8608 $type = 'www';
8609  
8610 } elsif ($text =~ m/^telnet\:\/\//i) {
8611  
8612 $type = 'telnet';
8613  
8614 } elsif ($text =~ m/^ssh\:\/\//i) {
8615  
8616 $type = 'ssh';
8617  
8618 } elsif ($text =~ m/^ssl\:\/\//i) {
8619  
8620 $type = 'ssl';
8621  
8622 } else {
8623  
8624 # This shouldn't happen
8625 $type = 'other';
8626 }
8627  
8628 # A single link may be created by one or more successive calls to $self->insertText (etc).
8629 # If $text isn't the start of a link, we will be looking to add it to the end of an
8630 # existing link
8631 # This textview object stores its own list of GA::Obj::Link objects which apply to the
8632 # current insertion point; a hash in the form
8633 # ->linkObjLineHash{line} = reference_to_list_of_GA::Obj::Link_objects
8634 $listRef = $self->ivShow('linkObjLineHash', $lineNum);
8635  
8636 if (defined $listRef) {
8637  
8638 # Check each GA::Obj::Link object in turn. If there's one which ends at $posn, we'll
8639 # need to check if $text is part of the same link, or the start of a new link
8640 # (Don't need to check MXP links, which are always created whole)
8641 OUTER: foreach my $obj (@$listRef) {
8642  
8643 my $endPosn = $obj->posn + length ($obj->text);
8644 if (! $obj->mxpFlag && $endPosn == $posn) {
8645  
8646 # $text is almost certainly part of the previous link
8647 $linkObj = $obj;
8648 # (->href and ->text are the same for non-MXP links)
8649 $linkObj->ivPoke('href', $obj->href . $text);
8650 $linkObj->ivPoke('text', $obj->text . $text);
8651 last OUTER;
8652 }
8653 }
8654 }
8655  
8656 if (! $linkObj) {
8657  
8658 # Create a new GA::Obj::Link object
8659 $linkObj = $self->add_link($lineNum, $posn, $type);
8660 if (! $linkObj) {
8661  
8662 return undef;
8663 }
8664  
8665 # (For non-MXP links, ->href and ->text are the same)
8666 $linkObj->ivPoke('href', $text);
8667 $linkObj->ivPoke('text', $text);
8668 }
8669  
8670 return 1;
8671 }
8672  
8673 sub createMxpStackObj {
8674  
8675 # Called by GA::Session->processMxpModalElement
8676 # Creates an mxp stack object (GA::Mxp::StackObj) and adds it to this textview's stack
8677 #
8678 # Expected arguments
8679 # $session - The calling GA::Session
8680 # $keyword - The MXP element keyword (already converted to upper case)
8681 #
8682 # Optional arguments
8683 # %stackHash - A hash of key-value pairs which updates $self->mxpModalStackHash by
8684 # replacing one or more of its key-value pairs (might be an empty
8685 # hash)
8686 #
8687 # Return values
8688 # 'undef' on improper arguments or if the stack object can't be created
8689 # Blessed reference to the newly-created object on success
8690  
8691 my ($self, $session, $keyword, %stackHash) = @_;
8692  
8693 # Local variables
8694 my $stackObj;
8695  
8696 # Check for improper arguments
8697 if (! defined $session || ! defined $keyword) {
8698  
8699 return $axmud::CLIENT->writeImproper($self->_objClass . '->createMxpStackObj', @_);
8700 }
8701  
8702 # Create a new MXP stack object which preserves current MXP text attributes, just before we
8703 # update $self->mxpModalStackHash
8704 $stackObj = Games::Axmud::Mxp::StackObj->new($session, $keyword, $self->mxpModalStackHash);
8705 if (! $stackObj ) {
8706  
8707 return undef;
8708 }
8709  
8710 # Update IVs
8711 $self->ivPush('mxpModalStackList', $stackObj);
8712  
8713 # Apply the new text attributes specified by %stackHash
8714 foreach my $key (keys %stackHash) {
8715  
8716 $self->ivAdd('mxpModalStackHash', $key, $stackHash{$key});
8717 }
8718  
8719 return $stackObj;
8720 }
8721  
8722 sub interpretTags {
8723  
8724 # Called by $self->insertText and ->showSystemText
8725 # Interprets a list of arguments passed to those functions, including Axmud colour and style
8726 # tags and some additional strings for implementing newline characters and clearing the
8727 # buffer
8728 # For RGB colour tags (e.g. '#FFFFFF' and 'u#FFFFFF'), a new Gtk3::TextTag is created, if
8729 # one does not already exist
8730 # Duplicate arguments are ignored. Only the first text colour tag (if any) is used, and only
8731 # the first underlay colour tag (if any) is used. Unrecognised tags are ignored
8732 #
8733 # Expected arguments
8734 # $newLineDefault - The default behaviour for newline characters, if no behaviour is
8735 # specified in @args: 'before' prepends a newline character to the
8736 # text, 'after'/'nl' appends a newline character to the text, 'echo'
8737 # does not prepend/append a newline character at all
8738 #
8739 # Optional arguments
8740 # @args - The list of arguments to interpret, in any order:
8741 # - 'empty' (empties the buffer before writing text)
8742 # - 'before' (prepends a newline character to the text)
8743 # - 'after' or 'nl' (appends a newline character to $text)
8744 # - 'echo' (does not prepend/append a newline character, overrides
8745 # 'before', 'after' and 'nl' if they are specified)
8746 # - one or more Axmud colour tags. Only the first text colour (e.g. 'red')
8747 # is used, and only the first underlay colour ('UL_RED') is used.
8748 # The range of Axmud colour tags include:
8749 # - standard colour tags like 'red', 'BLUE', 'ul_red', 'UL_BLUE'
8750 # (case-sensititive)
8751 # - xterm colour tags (strings in the range 'x0' to 'x255', or
8752 # 'ux0' to 'ux255'; case-insensitive, so 'X0' is valid)
8753 # - RGB colour tags (strings in the range '#000000' to '#FFFFFF', or
8754 # 'u#000000' to 'u#FFFFFF'; case-insensitive, so 'U#AbCdEf' is
8755 # valid)
8756 # - one or more Axmud style tags ('italics', 'strike', 'link' etc)
8757 #
8758 # Return values
8759 # An empty list on improper arguments
8760 # Otherwise returns a list in the form
8761 # (
8762 # $emptyFlag, $beforeFlag, $afterFlag, $linkFlag, $textColour, $underlayColour,
8763 # @styleTags,
8764 # )
8765 # ...where the flags are set to TRUE or FALSE, $textColour is set to the first text
8766 # colour tag found (or 'undef' if none are found), $underlayColour is set to the
8767 # first underlay colour tag found (or 'undef' if none are found), and @styleTags
8768 # contains a list of Axmud style tags (an empty list if none are found)
8769 # NB If the 'link' style tag appears in @args, then $linkFlag will be TRUE, and the style
8770 # tag will also appear in @styleTags
8771  
8772 my ($self, $newLineDefault, @args) = @_;
8773  
8774 # Local variables
8775 my (
8776 $emptyFlag, $beforeFlag, $afterFlag, $echoFlag, $linkFlag, $textColour, $underlayColour,
8777 $mxpfFlag, $relatedFlag,
8778 @styleTags,
8779 %styleHash,
8780 );
8781  
8782 # Check for improper arguments
8783 if (! defined $newLineDefault) {
8784  
8785 return $axmud::CLIENT->writeImproper($self->_objClass . '->interpretTags', @_);
8786 }
8787  
8788 # The flags are FALSE by default ($newLineDefault is applied at the end, if necessary)
8789 $emptyFlag = FALSE;
8790 $beforeFlag = FALSE;
8791 $afterFlag = FALSE;
8792 $echoFlag = FALSE;
8793 $linkFlag = FALSE;
8794  
8795 foreach my $item (@args) {
8796  
8797 my (
8798 $first, $second, $fontString, $spacing, $tag, $type, $underlayFlag,
8799 @wordList,
8800 );
8801  
8802 $first = lc(substr($item, 0, 1));
8803 $second = lc(substr($item, 0, 2));
8804  
8805 if ($item eq 'empty') {
8806  
8807 $emptyFlag = TRUE;
8808 $relatedFlag = TRUE;
8809  
8810 } elsif ($item eq 'before') {
8811  
8812 $beforeFlag = TRUE;
8813 $relatedFlag = TRUE;
8814  
8815 } elsif ($item eq 'after' || $item eq 'nl') {
8816  
8817 $afterFlag = TRUE;
8818 $relatedFlag = TRUE;
8819  
8820 } elsif ($item eq 'echo') {
8821  
8822 $echoFlag = TRUE;
8823 $relatedFlag = TRUE;
8824  
8825 } elsif ($axmud::CLIENT->ivExists('constStyleTagHash', $item)) {
8826  
8827 # It's an Axmud style tag (not including dummy style tags). Ignore duplicate style
8828 # tags
8829 if (! exists $styleHash{$item}) {
8830  
8831 push (@styleTags, $item);
8832 $styleHash{$item} = undef;
8833  
8834 if ($item eq 'link' && $self->allowLinkFlag) {
8835  
8836 # (As well as adding the tag to @styleTags, set a flag; this saves a bit of
8837 # time for the calling function)
8838 $linkFlag = TRUE;
8839 }
8840 }
8841  
8842 } elsif (substr($item, 0, 5) eq 'mxpf_') {
8843  
8844 # It's a dummy style tag in the form 'mxpf_monospace_bold_12_p5', containing one or
8845 # more of the following, separated by underlines: the font name (e.g.
8846 # 'monospace'), a font name modifier (e.g. 'bold'), the font size (e.g. '12') and
8847 # the pixel spacing above and below the text (used for MXP HTML headings, e.g.
8848 # 'p5'; when not specified, a spacing of 0 is used)
8849 # Ignore duplicate 'mxpf_' tags
8850 if (! $mxpfFlag) {
8851  
8852 # If a Gtk3::TextTag for this exact combination of fonts and font sizes doesn't
8853 # exist, create a new one
8854 if (! $self->buffer->get_tag_table->lookup($item)) {
8855  
8856 # Remove the 'mxpf' and replace underlines with whitespace, getting
8857 # something like 'monospace bold 12 p5'
8858 $fontString = substr($item, 5);
8859 $fontString =~ s/\_/ /g;
8860  
8861 # The default pixel spacing is 0 (only MXP HTML headings need more)
8862 $spacing = 0;
8863 # Remove the pixel spacing component, if it was specified. Use only the
8864 # first one; ignore any subsequent ones
8865 foreach my $word (split(/\s+/, $fontString)) {
8866  
8867 if ($word =~ m/^p(\d+)$/) {
8868  
8869 # (Ignore subsequent spacings)
8870 if (! $spacing) {
8871  
8872 $spacing = $1;
8873 }
8874  
8875 } else {
8876  
8877 push (@wordList, $word);
8878 }
8879 }
8880  
8881 $fontString = join(' ', @wordList);
8882  
8883 $self->buffer->create_tag(
8884 $item, # e.g. 'mxpf_monospace_bold_12'
8885 'font' => $fontString, # e.g. 'monospace bold 12'
8886 'pixels-above-lines' => $spacing, # e.g. 5
8887 'pixels-below-lines' => $spacing, # e.g. 5
8888 );
8889 }
8890  
8891 push (@styleTags, $item);
8892 $mxpfFlag = TRUE;
8893 }
8894  
8895 } elsif ($second eq 'ux') {
8896  
8897 # It's an xterm colour tag for the underlay. Check that it's valid before using it
8898 # (and ignore an additional underlay colour, if one has already been specified)
8899 if (! $underlayColour) {
8900  
8901 $tag = substr($item, 1); # Strip away the initial 'u'
8902 if ($axmud::CLIENT->ivExists('xTermColourHash', lc($tag))) {
8903  
8904 # (xterm colour tags are lower-case, by default)
8905 $underlayColour = lc($item);
8906 }
8907 }
8908  
8909 } elsif ($first eq 'x') {
8910  
8911 # It's an xterm colour tag for text. Check that it's valid before using it
8912 # (and ignore an additional text colour, if one has already been specified)
8913 if (! $textColour && $axmud::CLIENT->ivExists('xTermColourHash', lc($item))) {
8914  
8915 # (xterm colour tags are lower-case, by default)
8916 $textColour = lc($item);
8917 }
8918  
8919 } elsif ($second eq 'u#') {
8920  
8921 # It's an RGB colour tag for the underlay
8922 if (! $underlayColour) {
8923  
8924 $tag = substr($item, 1); # Strip away the initial 'u'
8925 if ($tag =~ m/^\#[A-Fa-f0-9]{6}$/) {
8926  
8927 # (Gtk3 expects an upper-case string like '#FFFFFF')
8928 $underlayColour = 'u' . uc($tag);
8929 # There are 16.7 million possible RGB colour tags, so we take the pragmatic
8930 # approach and create a Gtk3::TextTag for each one, only when it is needed
8931 if (! $self->buffer->get_tag_table->lookup($underlayColour)) {
8932  
8933 $self->buffer->create_tag(
8934 $underlayColour, # e.g. 'u#FFFFFF'
8935 'background' => uc($tag), # e.g. '#FFFFFF'
8936 );
8937 }
8938 }
8939 }
8940  
8941 } elsif ($first eq '#') {
8942  
8943 # It's an RGB colour tag for text
8944 if (! $textColour && $item =~ m/^\#[A-Fa-f0-9]{6}$/) {
8945  
8946 # (Gtk3 expects an upper-case string like '#FFFFFF')
8947 $textColour = uc($item);
8948 # There are 16.7 million possible RGB colour tags, so we take the pragmatic
8949 # approach and create a Gtk3::TextTag for each one, only when it is needed
8950 if (! $self->buffer->get_tag_table->lookup($textColour)) {
8951  
8952 $self->buffer->create_tag(
8953 $textColour, # e.g. '#FFFFFF'
8954 'foreground' => $textColour, # e.g. '#FFFFFF'
8955 );
8956 }
8957 }
8958  
8959 } else {
8960  
8961 # It's presumably an Axmud colour tag
8962 ($type, $underlayFlag) = $axmud::CLIENT->checkColourTags($item, 'standard');
8963 if ($type) {
8964  
8965 # (Only use the first underlay colour tag)
8966 if ($underlayFlag && ! $underlayColour) {
8967  
8968 $underlayColour = $item;
8969  
8970 } elsif (! $underlayFlag && ! $textColour) {
8971  
8972 $textColour = $item;
8973 }
8974 }
8975 }
8976 }
8977  
8978 # 'echo' overrides 'before', 'after' and 'nl', it specified
8979 if ($echoFlag) {
8980  
8981 $beforeFlag = FALSE;
8982 $afterFlag = FALSE;
8983 }
8984  
8985 # If none of 'before', 'after' and 'echo' were specified, use the default behaviour
8986 if (! $relatedFlag) {
8987  
8988 if ($newLineDefault eq 'echo') {
8989 $echoFlag = TRUE;
8990 } elsif ($newLineDefault eq 'before') {
8991 $beforeFlag = TRUE;
8992 } elsif ($newLineDefault eq 'after' || $newLineDefault eq 'nl') {
8993 $afterFlag = TRUE;
8994 }
8995 }
8996  
8997 return (
8998 $emptyFlag, $beforeFlag, $afterFlag, $linkFlag, $textColour, $underlayColour,
8999 @styleTags,
9000 );
9001 }
9002  
9003 sub modifyColourTags {
9004  
9005 # Called by $self->insertText after an earlier call to $self->interpretTags
9006 # Imports the colour scheme in use, then applies any colour overrides specified by that
9007 # colour scheme or by this object's own monochrome mode
9008 #
9009 # Expected arguments
9010 # (none besides $self)
9011 #
9012 # Optional arguments
9013 # $textColour - The text colour tag that's going to be inserted into the
9014 # Gtk3::TextView (or 'undef' if no colour tag is going to be used)
9015 # $underlayColour - The underlay colour tag that's going to be inserted into the
9016 # Gtk3::TextView (or 'undef' if no colour tag is going to be used)
9017 #
9018 # Return values
9019 # An empty list on improper arguments
9020 # Otherwise returns a list in the form
9021 # (monochrome_flag, text_colour, underlay_colour)
9022 # ...where 'text_colour' and 'underlay_colour' are the modified (or unmodified) values,
9023 # and 'monochrome_flag' is TRUE is no colours can be used at all, FALSE otherwise
9024  
9025 my ($self, $textColour, $underlayColour, $check) = @_;
9026  
9027 # Local variables
9028 my (
9029 $colourSchemeObj, $monochromeFlag,
9030 @emptyList,
9031 );
9032  
9033 # Check for improper arguments
9034 if (defined $check) {
9035  
9036 $axmud::CLIENT->writeImproper($self->_objClass . '->insertWithTags', @_);
9037 return @emptyList;
9038 }
9039  
9040 # Import the colour scheme in use
9041 $colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme);
9042 # Apply any colour overrides specified by the colour scheme or by this object's own
9043 # monochrome mode
9044 if ($self->monochromeFlag || ($colourSchemeObj && $colourSchemeObj->overrideAllFlag)) {
9045  
9046 $monochromeFlag = TRUE;
9047  
9048 } else {
9049  
9050 $monochromeFlag = FALSE;
9051  
9052 if ($colourSchemeObj) {
9053  
9054 if (
9055 defined $textColour
9056 && $colourSchemeObj->ivExists('overrideHash', $textColour)
9057 ) {
9058 $textColour = $colourSchemeObj->ivShow('overrideHash', $textColour);
9059 }
9060  
9061 if (
9062 defined $underlayColour
9063 && $colourSchemeObj->ivExists('overrideHash', $underlayColour)
9064 ) {
9065 $underlayColour = $colourSchemeObj->ivShow('overrideHash', $underlayColour);
9066 }
9067 }
9068 }
9069  
9070 return ($monochromeFlag, $textColour, $underlayColour);
9071 }
9072  
9073 sub insertWithTags {
9074  
9075 # Called by $self->insertText, ->insertCmd, ->showSystemText, ->showError, ->showWarning,
9076 # ->showDebug, ->showImproper and ->showImage
9077 # Inserts some text and (optionally) colour and style tags into the Gtk3::TextBuffer
9078 #
9079 # Expected arguments
9080 # $iter - The Gtk3::TextIter, representing the point in the buffer at which the text
9081 # is inserted
9082 # $text - A string consisting of 0, 1 or more characters which aren't newline
9083 # characters
9084 #
9085 # Optional arguments
9086 # @tags - A list of Axmud colour/style tags that apply to the whole of $text, but
9087 # not necessarily any text that was inserted before it (or will be
9088 # inserted after it). Can be an empty list
9089 #
9090 # Return values
9091 # 'undef' on improper arguments
9092 # Otherwise returns the Gtk3::TextIter immediately after the inserted text (which might be
9093 # the end of the textbuffer, or not)
9094  
9095 my ($self, $iter, $text, @tags) = @_;
9096  
9097 # Local variables
9098 my ($lineNum, $posn, $endIter, $length, $stopPosn, $stopIter, $newIter, $newLength);
9099  
9100 # Check for improper arguments
9101 if (! defined $iter || ! defined $text) {
9102  
9103 return $axmud::CLIENT->writeImproper($self->_objClass . '->insertWithTags', @_);
9104 }
9105  
9106 # Get the iter's position in the textview buffer
9107 $lineNum = $iter->get_line();
9108 $posn = $iter->get_visible_line_offset();
9109  
9110 # Strip any newline characters ($text shouldn't contain any, but we'll check anyway)
9111 # Also strip any null chars (in the text length calculations below, they have a length of
9112 # both 0 and 1, which causes an Axmud crash)
9113 $text =~ s/[\n\r\x00]//;
9114  
9115 # # Insert the text and tags into the Gtk3::TextBuffer
9116 # $self->buffer->insert_with_tags_by_name($iter, $text, @tags);
9117 # Gtk overwrite mode doesn't work (for some reason), so we're forced to implement our own
9118 # overwrite mode by deleting existing text before inserting new text
9119 $endIter = $self->buffer->get_end_iter();
9120 if ($self->overwriteFlag && $iter ne $endIter) {
9121  
9122 my ($length, $stopPosn, $stopIter);
9123  
9124 $length = $self->getLineLength($iter);
9125 $stopPosn = $posn + length($text);
9126 if ($endIter->get_line() == $iter->get_line()) {
9127  
9128 if ($stopPosn > $length) {
9129  
9130 $stopPosn = $length;
9131 }
9132  
9133 } else {
9134  
9135 if (! $length) {
9136  
9137 $stopPosn = $length;
9138  
9139 } elsif ($stopPosn >= $length) {
9140  
9141 $stopPosn = $length - 1;
9142 }
9143 }
9144  
9145 $stopIter = $self->buffer->get_iter_at_line_offset($lineNum, $stopPosn);
9146 if ($stopIter ne $endIter) {
9147  
9148 $self->buffer->delete($iter, $stopIter);
9149 }
9150 }
9151  
9152 $self->buffer->insert_with_tags_by_name($iter, $text, @tags);
9153  
9154 # Get the iter after immediately after the inserted text. Gtk, for some reason, crashes if
9155 # we try to get an iter outside the buffer, and some worlds (e.g. Kallisti) can cause
9156 # such a crash, so we have to do a sanity check
9157 $posn += length ($text);
9158 $newLength = $self->getLineLength($iter);
9159  
9160 if ($posn > $newLength) {
9161  
9162 $posn = $newLength;
9163 }
9164  
9165 $newIter = $self->buffer->get_iter_at_line_offset($lineNum, $posn);
9166  
9167 # $self->insertNewLineFlag is set on every call to this function
9168 $self->ivPoke('insertNewLineFlag', FALSE);
9169 # $self->newLineFlag must be set if the buffer now ends with a newline character
9170 $endIter = $self->buffer->get_end_iter();
9171  
9172 # Confusingly, $newIter and $endIter are not the same, even if they both point at the same
9173 # position in the buffer
9174 if (
9175 $newIter->get_line() eq $endIter->get_line()
9176 && $newIter->get_visible_line_offset eq $endIter->get_visible_line_offset()
9177 ) {
9178 $self->ivPoke('newLineFlag', FALSE);
9179 # Let's return $endIter rather than $newIter...
9180 $newIter = $endIter;
9181 }
9182  
9183 # Update IVs
9184 if ($text ne '') {
9185  
9186 $self->ivPoke('bufferTextFlag', TRUE);
9187 $self->ivPoke('sizeUpdateFlag', TRUE);
9188 }
9189  
9190 return $newIter;
9191 }
9192  
9193 sub insertNewLine {
9194  
9195 # Called by $self->insertText, ->insertMultipleText, ->insertCmd, ->showSystemText,
9196 # ->showError, ->showWarning, ->showDebug, ->showImproper and ->showImage
9197 # Also called by $self->setInsertPosn to add empty lines, if they don't already exist
9198 # Inserts a newline character into the Gtk3::TextBuffer and updates IVs
9199 #
9200 # Expected arguments
9201 # (none besides $self)
9202 #
9203 # Optional arguments
9204 # $iter - The Gtk3::TextIter, representing the point in the buffer at which the newline
9205 # character is inserted. If 'undef', the newline character is inserted at the
9206 # end of the buffer
9207 #
9208 # Return values
9209 # 'undef' on improper arguments
9210 # Otherwise returns the Gtk3::TextIter immediately after the inserted newline character
9211 # (which might be the end of the textbuffer, or not)
9212  
9213 my ($self, $iter, $check) = @_;
9214  
9215 # Local variables
9216 my ($lineNum, $posn, $endIter, $forceFlag);
9217  
9218 # Check for improper arguments
9219 if (defined $check) {
9220  
9221 return $axmud::CLIENT->writeImproper($self->_objClass . '->insertNewLine', @_);
9222 }
9223  
9224 if (! defined $iter) {
9225  
9226 $iter = $self->buffer->get_end_iter();
9227 }
9228  
9229 # Get the iter's position in the textview buffer
9230 $lineNum = $iter->get_line();
9231 $posn = $iter->get_visible_line_offset();
9232 $endIter = $self->buffer->get_end_iter();
9233  
9234 if ($endIter->get_line() == $lineNum) {
9235  
9236 # We're on the buffer's last line
9237 if ($self->getLineLength($endIter) == $posn) {
9238  
9239 # We're at the end of the buffer, so insert a newline character as normal
9240 $self->buffer->insert($iter, "\n");
9241 $self->ivPoke('newLineFlag', TRUE);
9242  
9243 # Create a mark after this newline character, so the next line (which currently
9244 # contains no characters at all) can be deleted when the buffer exceeds its
9245 # maximum number of lines
9246 # (Lines aren't deleted in overwrite mode, so don't bother creating the marks)
9247 if (! $self->overwriteFlag) {
9248  
9249 $self->buffer->create_mark(
9250 'line_' . ($lineNum + 1 + $self->nextDeleteLine),
9251 $self->buffer->get_end_iter(),
9252 TRUE,
9253 );
9254  
9255 # If the buffer has exceeded its maximum number of lines, delete the oldest
9256 # remaining line
9257 if ($self->maxLines && $lineNum >= $self->maxLines) {
9258  
9259 $self->removeOldLine();
9260 }
9261 }
9262  
9263 } else {
9264  
9265 # We're somewhere on the buffer's last line, but not at the end
9266 # Add a newline character to the end of the buffer, then move the insertion position
9267 # to the beginning of the next line
9268 $self->buffer->insert($endIter, "\n");
9269 $self->setInsertPosn(($lineNum + 1), 0);
9270 }
9271  
9272 } else {
9273  
9274 # We're somewhere on a line, but not the buffer's last line
9275 # This line already ends with a newline character, so just move the insertion position
9276 # to the beginning of the next line
9277 $self->setInsertPosn(($lineNum + 1), 0);
9278 # If a scrolling region scrolls, we're forced to add newline character(s) anyway
9279 $forceFlag = TRUE;
9280 }
9281  
9282 # $self->insertNewLineFlag is set on every call to this function (unless
9283 # $self->tempInsertMark is set, in which case this newline follows a system message, and
9284 # the actual insertion point is on some earlier line, in which case, we retain the current
9285 # value of $self->insertNewLineFlag)
9286 if (! $self->tempInsertMark) {
9287  
9288 $self->ivPoke('insertNewLineFlag', TRUE);
9289 }
9290  
9291 # This flag is TRUE even if the buffer contains only a newline character
9292 $self->ivPoke('bufferTextFlag', TRUE);
9293 $self->ivPoke('sizeUpdateFlag', TRUE);
9294  
9295 if (defined $self->scrlRegionBottom && $self->scrlRegionBottom eq $lineNum) {
9296  
9297 # If a scroll region is defined, and if this function was called when the insertion
9298 # position was on the line at the bottom of that region, then scroll all the lines in
9299 # the region up by one (by deleting the first line in the region)
9300 $self->scrlRegionUp(1, $forceFlag);
9301  
9302 return $self->buffer->get_iter_at_line_offset($lineNum, 0);
9303  
9304 } else {
9305  
9306 # Just return the Gtk3::TextIter at the new insertion position
9307 return $self->buffer->get_iter_at_line_offset(($lineNum + 1), 0);
9308 }
9309 }
9310  
9311 sub removeOldLine {
9312  
9313 # Called by $self->insertNewLine
9314 # When the Gtk3::TextBuffer is full (i.e. the number of lines in the buffer exceeds the
9315 # maximum), remove the oldest line
9316 # Also check $self->insertMark, etc, just in case they no longer exist (and update them, if
9317 # so)
9318 # Never called in overwrite mode (i.e. when $self->overwriteFlag is TRUE)
9319 #
9320 # Expected arguments
9321 # (none besides $self)
9322 #
9323 # Return values
9324 # 'undef' on improper arguments
9325 # 1 otherwise
9326  
9327 my ($self, $check) = @_;
9328  
9329 # Local variables
9330 my ($number, $startIter, $stopIter, $listRef, $ordinaryLineNum);
9331  
9332 # Check for improper arguments
9333 if (defined $check) {
9334  
9335 return $axmud::CLIENT->writeImproper($self->_objClass . '->removeOldLine', @_);
9336 }
9337  
9338 # v1.2.0 - because of Gtk3 performance issues, we no longer delete one line at a time,
9339 # therefore keeping a constant number of lines in the buffer (once full)
9340 # Instead, we delete 100 lines at a time (or fewer, if the maximum textview size is small)
9341 if ($self->maxLines >= 1000) {
9342  
9343 $number = 100;
9344  
9345 } else {
9346  
9347 $number = int($self->maxLines / 10);
9348 if (! $number) {
9349  
9350 $number = 1;
9351 }
9352 }
9353  
9354 $startIter = $self->buffer->get_start_iter();
9355 $stopIter = $self->buffer->get_iter_at_line_offset($number, 0);
9356 if ($startIter && $stopIter) {
9357  
9358 # Perform the deletion operation
9359 $self->buffer->delete($startIter, $stopIter);
9360  
9361 for (my $count = 0; $count < $number; $count++) {
9362  
9363 # Remove any link objects for links on the deleted line(s)
9364 $listRef = $self->ivShow('linkObjLineHash', $self->nextDeleteLine);
9365 if (defined $listRef) {
9366  
9367 foreach my $linkObj (@$listRef) {
9368  
9369 $self->ivDelete('linkObjHash', $linkObj->number);
9370 }
9371  
9372 $self->ivDelete('linkObjLineHash', $self->nextDeleteLine);
9373 }
9374  
9375 # No need to display a tooltip for this line every again
9376 $self->ivDelete('tooltipHash', $self->nextDeleteLine);
9377 }
9378  
9379 # Do the IVs $self->insertMark, etc refer to a position on these line(s)? If so, they
9380 # must be reset
9381 if ($self->insertMark && ! $self->insertMark->get_buffer()) {
9382  
9383 $self->ivPoke('insertMark', undef);
9384 $self->ivPoke('insertNewLineFlag', FALSE);
9385 }
9386  
9387 if ($self->restoreInsertMark && ! $self->restoreInsertMark->get_buffer()) {
9388  
9389 $self->ivPoke('restoreInsertMark', undef);
9390 }
9391  
9392 if ($self->tempInsertMark && ! $self->tempInsertMark->get_buffer()) {
9393  
9394 $self->ivPoke('tempInsertMark', undef);
9395 }
9396  
9397 if ($self->systemInsertMark && ! $self->systemInsertMark->get_buffer()) {
9398  
9399 $self->ivPoke('systemInsertMark', undef);
9400 }
9401  
9402 $self->ivIncrement('nextDeleteLine');
9403 }
9404  
9405 return 1;
9406 }
9407  
9408 sub enableOverwrite {
9409  
9410 # Mostly called by functions in this textview object, but can (in theory) be called by
9411 # anything
9412 # Enables overwrite mode
9413 #
9414 # Expected arguments
9415 # (none besides $self)
9416 #
9417 # Return values
9418 # 'undef' on improper arguments
9419 # 1 otherwise
9420  
9421 my ($self, $check) = @_;
9422  
9423 # Check for improper arguments
9424 if (defined $check) {
9425  
9426 return $axmud::CLIENT->writeImproper($self->_objClass . '->enableOverwrite', @_);
9427 }
9428  
9429 $self->ivPoke('overwriteFlag', TRUE);
9430  
9431 $self->textView->set_overwrite(TRUE);
9432 if ($self->textView2) {
9433  
9434 $self->textView2->set_overwrite(TRUE);
9435 }
9436  
9437 return 1;
9438 }
9439  
9440 sub disableOverwrite {
9441  
9442 # Should only be called by GA::Session->doDisconnect or ->reactDisconnect when a (real)
9443 # connection terminates, and when this is the session's default textview
9444 # Turns off overwrite mode (if on), and moves the insertion point to the end of
9445 # $self->buffer
9446 #
9447 # Expected arguments
9448 # (none besides $self)
9449 #
9450 # Return values
9451 # 'undef' on improper arguments
9452 # 1 otherwise
9453  
9454 my ($self, $check) = @_;
9455  
9456 # Check for improper arguments
9457 if (defined $check) {
9458  
9459 return $axmud::CLIENT->writeImproper($self->_objClass . '->disableOverwrite', @_);
9460 }
9461  
9462 if ($self->overwriteFlag) {
9463  
9464 $self->ivPoke('overwriteFlag', FALSE);
9465 $self->ivUndef('insertMark');
9466 $self->ivUndef('restoreInsertMark');
9467 $self->ivUndef('tempInsertMark');
9468 $self->ivUndef('systemInsertMark');
9469 $self->ivUndef('scrlRegionTop');
9470 $self->ivUndef('scrlRegionBottom');
9471  
9472 if ($self->bufferTextFlag && ! $self->newLineFlag) {
9473  
9474 $self->insertNewLine($self->buffer->get_end_iter());
9475 }
9476 }
9477  
9478 return 1;
9479 }
9480  
9481 ##################
9482 # Accessors - set
9483  
9484 sub set_allowLinkFlag {
9485  
9486 my ($self, $flag, $check) = @_;
9487  
9488 # Check for improper arguments
9489 if (! defined $flag || defined $check) {
9490  
9491 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_allowLinkFlag', @_);
9492 }
9493  
9494 if ($flag) {
9495 $self->ivPoke('allowLinkFlag', TRUE);
9496 } else {
9497 $self->ivPoke('allowLinkFlag', FALSE);
9498 }
9499  
9500 return 1;
9501 }
9502  
9503 sub set_clearAfterInsert {
9504  
9505 my ($self, $check) = @_;
9506  
9507 # Check for improper arguments
9508 if (defined $check) {
9509  
9510 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_clearAfterInsert', @_);
9511 }
9512  
9513 $self->ivPoke('clearAfterInsertFlag', TRUE);
9514  
9515 return 1;
9516 }
9517  
9518 sub set_colourStyleHash {
9519  
9520 # Called by GA::Session->processLineSegment
9521  
9522 my ($self, %hash) = @_;
9523  
9524 # (No improper arguments to check)
9525  
9526 $self->ivPoke('colourStyleHash', %hash);
9527  
9528 return 1;
9529 }
9530  
9531 sub set_cursorEnableFlag {
9532  
9533 my ($self, $flag, $check) = @_;
9534  
9535 # Check for improper arguments
9536 if (! defined $flag || defined $check) {
9537  
9538 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_cursorEnableFlag', @_);
9539 }
9540  
9541 if ($flag) {
9542  
9543 $self->ivPoke('cursorEnableFlag', TRUE);
9544  
9545 $self->moveCursor();
9546  
9547 } else {
9548  
9549 if ($self->cursorEnableFlag) {
9550  
9551 $self->removeCursor();
9552 }
9553  
9554 $self->ivPoke('cursorEnableFlag', FALSE);
9555 }
9556  
9557 return 1;
9558 }
9559  
9560 sub add_incompleteLink {
9561  
9562 # Called by various MXP functions in GA::Session to convert an incomplete link (one in
9563 # which the link hasn't actually been applied to the Gtk3::TextView yet) into a complete
9564 # one, stored in IVs in this textview object
9565  
9566 my ($self, $linkObj, $check) = @_;
9567  
9568 # Local variables
9569 my (
9570 $listRef, $modLineNum, $beginIter, $length, $endIter, $lastLineFlag, $startPosn,
9571 $startIter, $stopPosn, $stopIter,
9572 );
9573  
9574 # Check for improper arguments
9575 if (! defined $linkObj || defined $check) {
9576  
9577 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_incompleteLink', @_);
9578 }
9579  
9580 if ($linkObj->number != -1) {
9581  
9582 # Not an incomplete link object
9583 return undef;
9584 }
9585  
9586 # Update IVs
9587 $linkObj->ivPoke('number', $self->linkObjCount);
9588  
9589 $self->ivAdd('linkObjHash', $linkObj->number, $linkObj);
9590  
9591 if (! $self->ivExists('linkObjLineHash', $linkObj->lineNum)) {
9592  
9593 $self->ivAdd('linkObjLineHash', $linkObj->lineNum, []);
9594 }
9595  
9596 $listRef = $self->ivShow('linkObjLineHash', $linkObj->lineNum);
9597 push (@$listRef, $linkObj);
9598 $self->ivAdd('linkObjLineHash', $linkObj->lineNum, $listRef);
9599  
9600 $self->ivIncrement('linkObjCount');
9601  
9602 # The link object stores a line number which corresponds to the total number of lines
9603 # displayed; if the buffer is full, take account of any lines that have been deleted
9604 $modLineNum = $linkObj->lineNum - $self->nextDeleteLine;
9605  
9606 # This function has historically been the cause of sudden crashes when $stopIter or even
9607 # $startIter have been outside the length of the line, so we need to check both of them
9608 $beginIter = $self->buffer->get_iter_at_line_offset($modLineNum, 0);
9609 $length = $self->getLineLength($beginIter);
9610 $endIter = $self->buffer->get_end_iter();
9611  
9612 if ($endIter->get_line() == $beginIter->get_line()) {
9613  
9614 $lastLineFlag = TRUE;
9615 }
9616  
9617 # If the link starts beyond the end of the line (an unlikely but actually observed error),
9618 # don't display a clickable link at all
9619 $startPosn = $linkObj->posn;
9620 if (
9621 ($lastLineFlag && $startPosn > $length)
9622 || (! $lastLineFlag && $startPosn > ($length - 1))
9623 ) {
9624 return undef;
9625  
9626 } else {
9627  
9628 $startIter = $self->buffer->get_iter_at_line_offset($modLineNum, $startPosn);
9629 }
9630  
9631 # If the link ends beyond the end of the line, move the end of the link to the end of the
9632 # line so a clickable link can be displayed
9633 $stopPosn = $linkObj->posn + length ($linkObj->text);
9634 if ($endIter->get_line() == $startIter->get_line() && $stopPosn > $length) {
9635 $stopPosn = $length;
9636 } elsif ($endIter->get_line() != $startIter->get_line() && $stopPosn > ($length - 1)) {
9637 $stopPosn = $length - 1;
9638 }
9639  
9640 $stopIter = $self->buffer->get_iter_at_line_offset($modLineNum, $stopPosn);
9641  
9642 # Add Axmud 'link' and 'link_off' tags at the appropriate places
9643 if ($startIter && $stopIter) {
9644  
9645 $self->buffer->apply_tag_by_name('link', $startIter, $stopIter);
9646 return 1;
9647  
9648 } else {
9649  
9650 return undef;
9651 }
9652 }
9653  
9654 sub add_link {
9655  
9656 # Called by $self->setupLink
9657  
9658 my ($self, $lineNum, $posn, $type, $check) = @_;
9659  
9660 # Local variables
9661 my ($linkObj, $listRef);
9662  
9663 # Check for improper arguments
9664 if (! defined $lineNum || ! defined $posn || ! defined $type || defined $check) {
9665  
9666 return $axmud::CLIENT->writeImproper($self->_objClass . '->add_link', @_);
9667 }
9668  
9669 $linkObj = Games::Axmud::Obj::Link->new($self->linkObjCount, $self, $lineNum, $posn, $type);
9670 if (! $linkObj) {
9671  
9672 return undef;
9673  
9674 } else {
9675  
9676 $self->ivAdd('linkObjHash', $linkObj->number, $linkObj);
9677  
9678 if (! $self->ivExists('linkObjLineHash', $lineNum)) {
9679  
9680 $self->ivAdd('linkObjLineHash', $lineNum, []);
9681 }
9682  
9683 $listRef = $self->ivShow('linkObjLineHash', $lineNum);
9684 push (@$listRef, $linkObj);
9685  
9686 $self->ivIncrement('linkObjCount');
9687  
9688 return $linkObj;
9689 }
9690 }
9691  
9692 sub reset_link {
9693  
9694 # Called by $self->clearBuffer
9695  
9696 my ($self, $check) = @_;
9697  
9698 # Check for improper arguments
9699 if (defined $check) {
9700  
9701 return $axmud::CLIENT->writeImproper($self->_objClass . '->reset_link', @_);
9702 }
9703  
9704 $self->ivEmpty('linkObjHash');
9705 $self->ivEmpty('linkObjLineHash');
9706 $self->ivPoke('linkObjCount', 0);
9707  
9708 return 1;
9709 }
9710  
9711 sub set_maxLines {
9712  
9713 # Called by GA::Cmd::SetTextView->do
9714  
9715 my ($self, $max, $check) = @_;
9716  
9717 # Local variables
9718 my ($endIter, $lineNum);
9719  
9720 # Check for improper arguments
9721 if (defined $check) {
9722  
9723 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_maxLines', @_);
9724 }
9725  
9726 $self->ivPoke('maxLines', $max);
9727  
9728 # If $max is 'undef' or 0, the buffer is unlimited
9729 # For other integer values, check whether the buffer has exceeded its maximum number of
9730 # lines and, if so, delete one or more lines
9731 if ($max) {
9732  
9733 # Get the line number of the last line
9734 $endIter = $self->buffer->get_end_iter();
9735 $lineNum = $endIter->get_line();
9736  
9737 if ($lineNum && ($lineNum - $self->nextDeleteLine) > $max) {
9738  
9739 do {
9740  
9741 my ($mark, $listRef);
9742  
9743 $mark = $self->buffer->get_mark('line_' . $self->nextDeleteLine);
9744 if ($mark) {
9745  
9746 $self->buffer->delete(
9747 $self->buffer->get_start_iter(),
9748 $self->buffer->get_iter_at_mark($mark),
9749 );
9750 }
9751  
9752  
9753 # Remove any link objects for links on the deleted line
9754 $listRef = $self->ivShow('linkObjLineHash', $self->nextDeleteLine);
9755 if (defined $listRef) {
9756  
9757 foreach my $linkObj (@$listRef) {
9758  
9759 $self->ivDelete('linkObjHash', $linkObj->number);
9760 }
9761  
9762 $self->ivDelete('linkObjLineHash', $self->nextDeleteLine);
9763 }
9764  
9765 $self->ivIncrement('nextDeleteLine');
9766  
9767 } until (($lineNum - $self->nextDeleteLine) <= $max);
9768 }
9769 }
9770  
9771 return 1;
9772 }
9773  
9774 sub set_mxpModalStackList {
9775  
9776 # Called by GA::Session->popMxpStack
9777  
9778 my ($self, @list) = @_;
9779  
9780 # (No improper arguments to check)
9781  
9782 $self->ivPoke('mxpModalStackList', @list);
9783  
9784 return 1;
9785 }
9786  
9787 sub set_mxpModalStackHash {
9788  
9789 # Called by GA::Session->processLineSegment
9790  
9791 my ($self, %hash) = @_;
9792  
9793 # (No improper arguments to check)
9794  
9795 $self->ivPoke('mxpModalStackHash', %hash);
9796  
9797 return 1;
9798 }
9799  
9800 sub set_newLineDefault {
9801  
9802 my ($self, $default, $check) = @_;
9803  
9804 # Check for improper arguments
9805 if (! defined $default || defined $check) {
9806  
9807 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_newLineDefault', @_);
9808 }
9809  
9810 if ($default eq 'before' || $default eq 'after' || $default eq 'nl' || $default eq 'echo') {
9811  
9812 $self->ivPoke('newLineDefault', $default);
9813 return 1;
9814  
9815 } else {
9816  
9817 return undef;
9818 }
9819 }
9820  
9821 sub set_scrollLockType {
9822  
9823 my ($self, $type, $check) = @_;
9824  
9825 # Check for improper arguments
9826 if (! defined $type || defined $check) {
9827  
9828 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_scrollLockType', @_);
9829 }
9830  
9831 if ($type eq 'top') {
9832 $self->ivPoke('scrollLockType', 'top');
9833 } else {
9834 $self->ivPoke('scrollLockType', 'bottom');
9835 }
9836  
9837 return 1;
9838 }
9839  
9840 sub set_scrlRegion {
9841  
9842 my ($self, $top, $bottom, $check) = @_;
9843  
9844 # Check for improper arguments
9845 if (! defined $top || ! defined $bottom || defined $check) {
9846  
9847 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_scrlRegion', @_);
9848 }
9849  
9850 $self->ivPoke('scrlRegionTop', $top);
9851 $self->ivPoke('scrlRegionBottom', $bottom);
9852  
9853 return 1;
9854 }
9855  
9856 sub reset_scrlRegion {
9857  
9858 my ($self, $check) = @_;
9859  
9860 # Check for improper arguments
9861 if (defined $check) {
9862  
9863 return $axmud::CLIENT->writeImproper($self->_objClass . '->reset_scrlRegion', @_);
9864 }
9865  
9866 $self->ivUndef('scrlRegionTop');
9867 $self->ivUndef('scrlRegionBottom');
9868  
9869 return 1;
9870 }
9871  
9872 sub set_sizeUpdateFlag {
9873  
9874 my ($self, $check) = @_;
9875  
9876 # Check for improper arguments
9877 if (defined $check) {
9878  
9879 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_sizeUpdateFlag', @_);
9880 }
9881  
9882 $self->ivPoke('sizeUpdateFlag', TRUE);
9883  
9884 return 1;
9885 }
9886  
9887 ##################
9888 # Accessors - get
9889  
9890 sub session
9891 { $_[0]->{session} }
9892 sub number
9893 { $_[0]->{number} }
9894 sub winObj
9895 { $_[0]->{winObj} }
9896 sub paneObj
9897 { $_[0]->{paneObj} }
9898  
9899 sub textView
9900 { $_[0]->{textView} }
9901 sub textView2
9902 { $_[0]->{textView2} }
9903 sub buffer
9904 { $_[0]->{buffer} }
9905 sub vPaned
9906 { $_[0]->{vPaned} }
9907 sub scroll
9908 { $_[0]->{scroll} }
9909 sub scroll2
9910 { $_[0]->{scroll2} }
9911 sub startMark
9912 { $_[0]->{startMark} }
9913 sub endMark
9914 { $_[0]->{endMark} }
9915 sub searchMark
9916 { $_[0]->{searchMark} }
9917 sub popupMenu
9918 { $_[0]->{popupMenu} }
9919  
9920 sub scrollLockFlag
9921 { $_[0]->{scrollLockFlag} }
9922 sub scrollLockType
9923 { $_[0]->{scrollLockType} }
9924 sub splitScreenMode
9925 { $_[0]->{splitScreenMode} }
9926  
9927 sub colourScheme
9928 { $_[0]->{colourScheme} }
9929 sub textColour
9930 { $_[0]->{textColour} }
9931 sub underlayColour
9932 { $_[0]->{underlayColour} }
9933 sub backgroundColour
9934 { $_[0]->{backgroundColour} }
9935 sub font
9936 { $_[0]->{font} }
9937 sub fontSize
9938 { $_[0]->{fontSize} }
9939 sub monochromeFlag
9940 { $_[0]->{monochromeFlag} }
9941 sub monochromeModFlag
9942 { $_[0]->{monochromeModFlag} }
9943 sub overwriteFlag
9944 { $_[0]->{overwriteFlag} }
9945  
9946 sub maxLines
9947 { $_[0]->{maxLines} }
9948 sub nextDeleteLine
9949 { $_[0]->{nextDeleteLine} }
9950  
9951 sub scrlRegionTop
9952 { $_[0]->{scrlRegionTop} }
9953 sub scrlRegionBottom
9954 { $_[0]->{scrlRegionBottom} }
9955  
9956 sub bufferTextFlag
9957 { $_[0]->{bufferTextFlag} }
9958 sub sizeUpdateFlag
9959 { $_[0]->{sizeUpdateFlag} }
9960 sub textWidthChars
9961 { $_[0]->{textWidthChars} }
9962 sub textHeightChars
9963 { $_[0]->{textHeightChars} }
9964 sub newLineFlag
9965 { $_[0]->{newLineFlag} }
9966 sub insertNewLineFlag
9967 { $_[0]->{insertNewLineFlag} }
9968 sub newLineDefault
9969 { $_[0]->{newLineDefault} }
9970 sub clearAfterInsertFlag
9971 { $_[0]->{clearAfterInsertFlag} }
9972  
9973 sub insertMark
9974 { $_[0]->{insertMark} }
9975 sub restoreInsertMark
9976 { $_[0]->{restoreInsertMark} }
9977 sub tempInsertMark
9978 { $_[0]->{tempInsertMark} }
9979 sub systemInsertMark
9980 { $_[0]->{systemInsertMark} }
9981 sub systemTextBuffer
9982 { $_[0]->{systemTextBuffer} }
9983  
9984 sub cursorEnableFlag
9985 { $_[0]->{cursorEnableFlag} }
9986 sub cursorOnFlag
9987 { $_[0]->{cursorOnFlag} }
9988 sub cursorMark
9989 { $_[0]->{cursorMark} }
9990 sub cursorEndFlag
9991 { $_[0]->{cursorEndFlag} }
9992 sub storePosnYPos
9993 { $_[0]->{storePosnYPos} }
9994 sub storePosnXPos
9995 { $_[0]->{storePosnXPos} }
9996  
9997 sub linkObjHash
9998 { my $self = shift; return %{$self->{linkObjHash}}; }
9999 sub linkObjLineHash
10000 { my $self = shift; return %{$self->{linkObjLineHash}}; }
10001 sub linkObjCount
10002 { $_[0]->{linkObjCount} }
10003 sub currentLinkObj
10004 { $_[0]->{currentLinkObj} }
10005 sub allowLinkFlag
10006 { $_[0]->{allowLinkFlag} }
10007  
10008 sub tooltipHash
10009 { my $self = shift; return %{$self->{tooltipHash}}; }
10010 sub lastTooltipLine
10011 { $_[0]->{lastTooltipLine} }
10012  
10013 sub soundDelayTime
10014 { $_[0]->{soundDelayTime} }
10015 sub soundCheckTime
10016 { $_[0]->{soundCheckTime} }
10017  
10018 sub colourStyleHash
10019 { my $self = shift; return %{$self->{colourStyleHash}}; }
10020 sub prevColourStyleHash
10021 { my $self = shift; return %{$self->{prevColourStyleHash}}; }
10022  
10023 sub mxpModalStackList
10024 { my $self = shift; return @{$self->{mxpModalStackList}}; }
10025 sub mxpModalStackHash
10026 { my $self = shift; return %{$self->{mxpModalStackHash}}; }
10027 }
10028  
10029 # Package must return a true value
10030 1