| 1 | # Copyright (C) 2011-2024 A S Lewis | ||
| 2 | # | ||
| 3 | # This program is free software: you can redistribute it and/or modify it under the terms of the GNU | ||
| 4 | # General Public License as published by the Free Software Foundation, either version 3 of the | ||
| 5 | # License, or (at your option) any later version. | ||
| 6 | # | ||
| 7 | # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
| 8 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 9 | # General Public License for more details. | ||
| 10 | # | ||
| 11 | # You should have received a copy of the GNU General Public License along with this program. If not, | ||
| 12 | # see <http://www.gnu.org/licenses/>. | ||
| 13 | # | ||
| 14 | # | ||
| 15 | # Games::Axmud::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 | $axmud::CLIENT->ttsVerboseFlag | ||
| 4142 | && defined $self->session->ttsLastType | ||
| 4143 | && $self->session->ttsLastType ne 'system' | ||
| 4144 | ) { | ||
| 4145 | # Last TTS conversion was something other than a system message | ||
| 4146 | $axmud::CLIENT->tts( | ||
| 4147 | 'System message: ' . $self->systemTextBuffer, | ||
| 4148 | 'system', | ||
| 4149 | 'system', | ||
| 4150 | $self->session, | ||
| 4151 | ); | ||
| 4152 | |||
| 4153 | } else { | ||
| 4154 | |||
| 4155 | # (Don't read out 'system message' again and again and again! | ||
| 4156 | $axmud::CLIENT->tts( | ||
| 4157 | $self->systemTextBuffer, | ||
| 4158 | 'system', | ||
| 4159 | 'system', | ||
| 4160 | $self->session, | ||
| 4161 | ); | ||
| 4162 | } | ||
| 4163 | } | ||
| 4164 | |||
| 4165 | # Fire any hooks that are using the system hook events | ||
| 4166 | $self->session->checkHooks('system_text', $self->systemTextBuffer); | ||
| 4167 | $self->session->checkHooks('system_all', $self->systemTextBuffer); | ||
| 4168 | |||
| 4169 | $self->ivUndef('systemTextBuffer'); | ||
| 4170 | } | ||
| 4171 | |||
| 4172 | # This type of system message always requires a return value of 1 | ||
| 4173 | return 1; | ||
| 4174 | } | ||
| 4175 | |||
| 4176 | sub showError { | ||
| 4177 | |||
| 4178 | # Called by Games::Axmud->writeError | ||
| 4179 | # Inserts a system error message into the Gtk3::TextBuffer and/or updates the System task's | ||
| 4180 | # window | ||
| 4181 | # | ||
| 4182 | # Expected arguments | ||
| 4183 | # (none besides $self) | ||
| 4184 | # | ||
| 4185 | # Optional arguments | ||
| 4186 | # $text - The system text to write. If undefined, the text <<undef>> is written | ||
| 4187 | # $func - The function that produced the error (e.g. | ||
| 4188 | # 'Games::Axmud::Client->helloWorld'). If 'undef', the function is not | ||
| 4189 | # displayed | ||
| 4190 | # | ||
| 4191 | # Return values | ||
| 4192 | # 'undef' | ||
| 4193 | |||
| 4194 | my ($self, $text, $func, $check) = @_; | ||
| 4195 | |||
| 4196 | # Local variables | ||
| 4197 | my ( | ||
| 4198 | $colourSchemeObj, $monochromeFlag, $textColour, $msg, $systemTask, $hereFlag, $taskFlag, | ||
| 4199 | $consoleFlag, $iter, $beforeFlag, | ||
| 4200 | ); | ||
| 4201 | |||
| 4202 | # Check for improper arguments | ||
| 4203 | if (defined $check) { | ||
| 4204 | |||
| 4205 | return $axmud::CLIENT->writeImproper($self->_objClass . '->showError', @_); | ||
| 4206 | } | ||
| 4207 | |||
| 4208 | # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag) | ||
| 4209 | $self->removeCursor(); | ||
| 4210 | # If the buffer is due to be cleared before inserting any text, then clear it | ||
| 4211 | if ($self->clearAfterInsertFlag) { | ||
| 4212 | |||
| 4213 | # The TRUE argument means 'don't remove/move the cursor' | ||
| 4214 | $self->clearBuffer(undef, TRUE); | ||
| 4215 | } | ||
| 4216 | |||
| 4217 | # Import the colour scheme in use | ||
| 4218 | $colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme); | ||
| 4219 | # Choose which colour tags to use (in monochrome mode, text/underlay colours are ignored, | ||
| 4220 | # but in this case we don't any apply overrides specified by the colour scheme) | ||
| 4221 | if ($self->monochromeFlag || ($colourSchemeObj && $colourSchemeObj->overrideAllFlag)) { | ||
| 4222 | $monochromeFlag = TRUE; | ||
| 4223 | } else { | ||
| 4224 | $textColour = $axmud::CLIENT->customShowErrorColour; | ||
| 4225 | } | ||
| 4226 | |||
| 4227 | # Call to ->writeLog requires a TRUE/FALSE value | ||
| 4228 | $beforeFlag = FALSE; | ||
| 4229 | |||
| 4230 | # Prepare the message to send | ||
| 4231 | if (! defined $text) { | ||
| 4232 | |||
| 4233 | # 'undef' is a valid value - represent it | ||
| 4234 | $text = "<<undef>>"; | ||
| 4235 | } | ||
| 4236 | |||
| 4237 | if ($func) { | ||
| 4238 | $msg = "ERROR: $func: $text"; | ||
| 4239 | } else { | ||
| 4240 | $msg = "ERROR: $text"; | ||
| 4241 | } | ||
| 4242 | |||
| 4243 | # Whether the message is written only in this textview (mode 'original'), or in both this | ||
| 4244 | # textview and the System task's window ('both'), or in the System task's window only | ||
| 4245 | # (mode 'task'), depends on the System task's IVs (if the task is running) | ||
| 4246 | $systemTask = $self->session->systemTask; | ||
| 4247 | if (! $systemTask) { | ||
| 4248 | |||
| 4249 | $hereFlag = TRUE; | ||
| 4250 | |||
| 4251 | } else { | ||
| 4252 | |||
| 4253 | if ($systemTask->errorMode eq 'original') { | ||
| 4254 | |||
| 4255 | $hereFlag = TRUE; | ||
| 4256 | |||
| 4257 | } elsif ($systemTask->errorMode eq 'both') { | ||
| 4258 | |||
| 4259 | $hereFlag = TRUE; | ||
| 4260 | $taskFlag = TRUE; | ||
| 4261 | |||
| 4262 | } else { | ||
| 4263 | |||
| 4264 | $taskFlag = TRUE; | ||
| 4265 | } | ||
| 4266 | } | ||
| 4267 | |||
| 4268 | # If not allowed to write a system message in this textview, write to the Session Console | ||
| 4269 | # window instead | ||
| 4270 | if ( | ||
| 4271 | $hereFlag | ||
| 4272 | && (! $axmud::CLIENT->mainWinSystemMsgFlag || $self->overwriteFlag) | ||
| 4273 | ) { | ||
| 4274 | $hereFlag = FALSE; | ||
| 4275 | $consoleFlag = TRUE; | ||
| 4276 | } | ||
| 4277 | |||
| 4278 | if ($hereFlag) { | ||
| 4279 | |||
| 4280 | # If the previous call to $self->showSystemText displayed a message that didn't end in a | ||
| 4281 | # newline character, $self->systemInsertMark is set | ||
| 4282 | # In that case, we must insert an artificial newline character, so this system message | ||
| 4283 | # is displayed on its own line | ||
| 4284 | if ($self->systemInsertMark) { | ||
| 4285 | |||
| 4286 | $iter = $self->buffer->get_iter_at_mark($self->systemInsertMark); | ||
| 4287 | $iter = $self->insertNewLine($iter); | ||
| 4288 | $self->ivUndef('systemInsertMark'); | ||
| 4289 | |||
| 4290 | # If the last piece of text inserted at the Gtk3::TextBuffer via a call to | ||
| 4291 | # $self->insertText didn't end in a newline character, we need to insert an artifical | ||
| 4292 | # newline character so the system message appears on its own line, at the end of the | ||
| 4293 | # buffer | ||
| 4294 | } elsif ( | ||
| 4295 | # Last character in the buffer isn't a newline character | ||
| 4296 | ! $self->newLineFlag | ||
| 4297 | # The insertion point for $self->insertText and ->insertCmd is the end of the buffer | ||
| 4298 | && ! $self->insertMark | ||
| 4299 | ) { | ||
| 4300 | $iter = $self->buffer->get_end_iter(); | ||
| 4301 | $self->ivPoke( | ||
| 4302 | 'tempInsertMark', | ||
| 4303 | $self->buffer->create_mark('temp_insert_mark', $iter, TRUE), | ||
| 4304 | ); | ||
| 4305 | |||
| 4306 | $beforeFlag = TRUE; | ||
| 4307 | } | ||
| 4308 | |||
| 4309 | # If the cursor is visible, remove it temporarily (i.e. remove the existing | ||
| 4310 | # Gtk3::TextTag) | ||
| 4311 | $self->removeCursor(); | ||
| 4312 | # If the buffer is due to be cleared before inserting any text, then clear it | ||
| 4313 | if ($self->clearAfterInsertFlag) { | ||
| 4314 | |||
| 4315 | # The TRUE argument means 'don't remove/move the cursor' | ||
| 4316 | $self->clearBuffer(undef, TRUE); | ||
| 4317 | } | ||
| 4318 | |||
| 4319 | # Set the insertion point | ||
| 4320 | $iter = $self->buffer->get_end_iter(); | ||
| 4321 | |||
| 4322 | # Insert the text into the Gtk3::TextBuffer | ||
| 4323 | if ($beforeFlag) { | ||
| 4324 | |||
| 4325 | # (Make sure the beginning of a link appears after the artificially-inserted newline | ||
| 4326 | # character, not before it) | ||
| 4327 | $iter = $self->insertNewLine($iter); | ||
| 4328 | } | ||
| 4329 | |||
| 4330 | if ($monochromeFlag) { | ||
| 4331 | $iter = $self->insertWithTags($iter, $msg); | ||
| 4332 | } else { | ||
| 4333 | $iter = $self->insertWithTags($iter, $msg, $textColour); | ||
| 4334 | } | ||
| 4335 | |||
| 4336 | $self->insertNewLine($iter); | ||
| 4337 | |||
| 4338 | # Restore the cursor | ||
| 4339 | if ($self->tempInsertMark) { | ||
| 4340 | $self->moveCursor($self->buffer->get_iter_at_mark($self->tempInsertMark)); | ||
| 4341 | } else { | ||
| 4342 | $self->replaceCursor(); | ||
| 4343 | } | ||
| 4344 | |||
| 4345 | if ($self->scrollLockFlag) { | ||
| 4346 | |||
| 4347 | if ($self->scrollLockType eq 'top') { | ||
| 4348 | $self->scrollToTop(); | ||
| 4349 | } else { | ||
| 4350 | $self->scrollToBottom(); | ||
| 4351 | } | ||
| 4352 | } | ||
| 4353 | } | ||
| 4354 | |||
| 4355 | if (defined $msg && $msg ne '') { | ||
| 4356 | |||
| 4357 | if ($taskFlag) { | ||
| 4358 | |||
| 4359 | # Write the message in the System task window | ||
| 4360 | $self->session->systemTask->showError($msg); | ||
| 4361 | } | ||
| 4362 | |||
| 4363 | if ($consoleFlag) { | ||
| 4364 | |||
| 4365 | # Send the message to the GA::Session, for display (now or later) in the Session | ||
| 4366 | # Console window | ||
| 4367 | $self->session->add_systemMsg('error', $msg); | ||
| 4368 | } | ||
| 4369 | |||
| 4370 | # Write to logs | ||
| 4371 | $axmud::CLIENT->writeLog( | ||
| 4372 | $self->session, | ||
| 4373 | TRUE, # Not world-specific logs | ||
| 4374 | $msg, | ||
| 4375 | $beforeFlag, | ||
| 4376 | TRUE, # Use final newline character | ||
| 4377 | 'main', 'errors', 'error', # Write to these files | ||
| 4378 | ); | ||
| 4379 | |||
| 4380 | # Fire any hooks that are using the system hook events | ||
| 4381 | $self->session->checkHooks('system_error', $msg); | ||
| 4382 | $self->session->checkHooks('system_all', $msg); | ||
| 4383 | $self->session->checkHooks('system_all_error', $msg); | ||
| 4384 | } | ||
| 4385 | |||
| 4386 | # Play a sound effect (if allowed, and if this textview object hasn't played the same | ||
| 4387 | # sound effect recently) | ||
| 4388 | if (! $self->soundCheckTime || $self->soundCheckTime < $axmud::CLIENT->clientTime) { | ||
| 4389 | |||
| 4390 | $axmud::CLIENT->playSound('error'); | ||
| 4391 | # Don't play it again for a few seconds | ||
| 4392 | $self->ivPoke('soundCheckTime', ($axmud::CLIENT->clientTime + $self->soundDelayTime)); | ||
| 4393 | } | ||
| 4394 | |||
| 4395 | # Convert text-to-speech, if required (but don't try to convert an 'undef' or text | ||
| 4396 | # containing no readable characters) | ||
| 4397 | if ( | ||
| 4398 | $axmud::CLIENT->systemAllowTTSFlag | ||
| 4399 | && $axmud::CLIENT->ttsSystemErrorFlag | ||
| 4400 | && defined $text | ||
| 4401 | && $text =~ m/\w/ | ||
| 4402 | # Also, temporarily don't convert system messages if the GA::Session flag is set | ||
| 4403 | && ! $self->session->ttsTempDisableFlag | ||
| 4404 | ) { | ||
| 4405 | # Make sure the received text is visible in the textview(s)... | ||
| 4406 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showError'); | ||
| 4407 | |||
| 4408 | # ...before converting text to speech | ||
| 4409 | if ( | ||
| 4410 | $axmud::CLIENT->ttsVerboseFlag | ||
| 4411 | && defined $self->session->ttsLastType | ||
| 4412 | && $self->session->ttsLastType ne 'error' | ||
| 4413 | ) { | ||
| 4414 | # Last TTS conversion was something other than a system error (etc) message | ||
| 4415 | $axmud::CLIENT->tts('System error: ' . $text, 'error', 'error', $self->session); | ||
| 4416 | |||
| 4417 | } else { | ||
| 4418 | |||
| 4419 | # (Don't read out 'system error' again and again and again! | ||
| 4420 | $axmud::CLIENT->tts($text, 'error', 'error', $self->session); | ||
| 4421 | } | ||
| 4422 | } | ||
| 4423 | |||
| 4424 | # This type of system message always requires a return value of 'undef' | ||
| 4425 | return undef; | ||
| 4426 | } | ||
| 4427 | |||
| 4428 | sub showWarning { | ||
| 4429 | |||
| 4430 | # Called by Games::Axmud->writeWarning | ||
| 4431 | # Inserts a system warning message into the Gtk3::TextBuffer and/or updates the System | ||
| 4432 | # task's window | ||
| 4433 | # | ||
| 4434 | # Expected arguments | ||
| 4435 | # (none besides $self) | ||
| 4436 | # | ||
| 4437 | # Optional arguments | ||
| 4438 | # $text - The system text to write. If undefined, the text <<undef>> is written | ||
| 4439 | # $func - The function that produced the warning (e.g. | ||
| 4440 | # 'Games::Axmud::Client->helloWorld'). If 'undef', the function is not | ||
| 4441 | # displayed | ||
| 4442 | # | ||
| 4443 | # Return values | ||
| 4444 | # 'undef' | ||
| 4445 | |||
| 4446 | my ($self, $text, $func, $check) = @_; | ||
| 4447 | |||
| 4448 | # Local variables | ||
| 4449 | my ( | ||
| 4450 | $colourSchemeObj, $monochromeFlag, $textColour, $msg, $systemTask, $hereFlag, $taskFlag, | ||
| 4451 | $consoleFlag, $iter, $beforeFlag, | ||
| 4452 | ); | ||
| 4453 | |||
| 4454 | # Check for improper arguments | ||
| 4455 | if (defined $check) { | ||
| 4456 | |||
| 4457 | return $axmud::CLIENT->writeImproper($self->_objClass . '->showWarning', @_); | ||
| 4458 | } | ||
| 4459 | |||
| 4460 | # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag) | ||
| 4461 | $self->removeCursor(); | ||
| 4462 | # If the buffer is due to be cleared before inserting any text, then clear it | ||
| 4463 | if ($self->clearAfterInsertFlag) { | ||
| 4464 | |||
| 4465 | # The TRUE argument means 'don't remove/move the cursor' | ||
| 4466 | $self->clearBuffer(undef, TRUE); | ||
| 4467 | } | ||
| 4468 | |||
| 4469 | # Import the colour scheme in use | ||
| 4470 | $colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme); | ||
| 4471 | # Choose which colour tags to use (in monochrome mode, text/underlay colours are ignored, | ||
| 4472 | # but in this case we don't any apply overrides specified by the colour scheme) | ||
| 4473 | if ($self->monochromeFlag || ($colourSchemeObj && $colourSchemeObj->overrideAllFlag)) { | ||
| 4474 | $monochromeFlag = TRUE; | ||
| 4475 | } else { | ||
| 4476 | $textColour = $axmud::CLIENT->customShowWarningColour; | ||
| 4477 | } | ||
| 4478 | |||
| 4479 | # Call to ->writeLog requires a TRUE/FALSE value | ||
| 4480 | $beforeFlag = FALSE; | ||
| 4481 | |||
| 4482 | # Prepare the message to send | ||
| 4483 | if (! defined $text) { | ||
| 4484 | |||
| 4485 | # 'undef' is a valid value - represent it | ||
| 4486 | $text = "<<undef>>"; | ||
| 4487 | } | ||
| 4488 | |||
| 4489 | if ($func) { | ||
| 4490 | $msg = "WARNING: $func: $text"; | ||
| 4491 | } else { | ||
| 4492 | $msg = "WARNING: $text"; | ||
| 4493 | } | ||
| 4494 | |||
| 4495 | # Whether the message is written only in this textview (mode 'original'), or in both this | ||
| 4496 | # textview and the System task's window ('both'), or in the System task's window only | ||
| 4497 | # (mode 'task'), depends on the System task's IVs (if the task is running) | ||
| 4498 | $systemTask = $self->session->systemTask; | ||
| 4499 | if (! $systemTask) { | ||
| 4500 | |||
| 4501 | $hereFlag = TRUE; | ||
| 4502 | |||
| 4503 | } else { | ||
| 4504 | |||
| 4505 | if ($systemTask->warningMode eq 'original') { | ||
| 4506 | |||
| 4507 | $hereFlag = TRUE; | ||
| 4508 | |||
| 4509 | } elsif ($systemTask->warningMode eq 'both') { | ||
| 4510 | |||
| 4511 | $hereFlag = TRUE; | ||
| 4512 | $taskFlag = TRUE; | ||
| 4513 | |||
| 4514 | } else { | ||
| 4515 | |||
| 4516 | $taskFlag = TRUE; | ||
| 4517 | } | ||
| 4518 | } | ||
| 4519 | |||
| 4520 | # If not allowed to write a system message in this textview, write to the Session Console | ||
| 4521 | # window instead | ||
| 4522 | if ( | ||
| 4523 | $hereFlag | ||
| 4524 | && (! $axmud::CLIENT->mainWinSystemMsgFlag || $self->overwriteFlag) | ||
| 4525 | ) { | ||
| 4526 | $hereFlag = FALSE; | ||
| 4527 | $consoleFlag = TRUE; | ||
| 4528 | } | ||
| 4529 | |||
| 4530 | if ($hereFlag) { | ||
| 4531 | |||
| 4532 | # If the previous call to $self->showSystemText displayed a message that didn't end in a | ||
| 4533 | # newline character, $self->systemInsertMark is set | ||
| 4534 | # In that case, we must insert an artificial newline character, so this system message | ||
| 4535 | # is displayed on its own line | ||
| 4536 | if ($self->systemInsertMark) { | ||
| 4537 | |||
| 4538 | $iter = $self->buffer->get_iter_at_mark($self->systemInsertMark); | ||
| 4539 | $iter = $self->insertNewLine($iter); | ||
| 4540 | $self->ivUndef('systemInsertMark'); | ||
| 4541 | |||
| 4542 | # If the last piece of text inserted at the Gtk3::TextBuffer via a call to | ||
| 4543 | # $self->insertText didn't end in a newline character, we need to insert an artifical | ||
| 4544 | # newline character so the system message appears on its own line, at the end of the | ||
| 4545 | # buffer | ||
| 4546 | } elsif ( | ||
| 4547 | # Last character in the buffer isn't a newline character | ||
| 4548 | ! $self->newLineFlag | ||
| 4549 | # The insertion point for $self->insertText and ->insertCmd is the end of the buffer | ||
| 4550 | && ! $self->insertMark | ||
| 4551 | ) { | ||
| 4552 | $iter = $self->buffer->get_end_iter(); | ||
| 4553 | $self->ivPoke( | ||
| 4554 | 'tempInsertMark', | ||
| 4555 | $self->buffer->create_mark('temp_insert_mark', $iter, TRUE), | ||
| 4556 | ); | ||
| 4557 | |||
| 4558 | $beforeFlag = TRUE; | ||
| 4559 | } | ||
| 4560 | |||
| 4561 | # If the cursor is visible, remove it temporarily (i.e. remove the existing | ||
| 4562 | # Gtk3::TextTag) | ||
| 4563 | $self->removeCursor(); | ||
| 4564 | # If the buffer is due to be cleared before inserting any text, then clear it | ||
| 4565 | if ($self->clearAfterInsertFlag) { | ||
| 4566 | |||
| 4567 | # The TRUE argument means 'don't remove/move the cursor' | ||
| 4568 | $self->clearBuffer(undef, TRUE); | ||
| 4569 | } | ||
| 4570 | |||
| 4571 | # Set the insertion point | ||
| 4572 | $iter = $self->buffer->get_end_iter(); | ||
| 4573 | |||
| 4574 | # Insert the text into the Gtk3::TextBuffer | ||
| 4575 | if ($beforeFlag) { | ||
| 4576 | |||
| 4577 | # (Make sure the beginning of a link appears after the artificially-inserted newline | ||
| 4578 | # character, not before it) | ||
| 4579 | $iter = $self->insertNewLine($iter); | ||
| 4580 | } | ||
| 4581 | |||
| 4582 | if ($monochromeFlag) { | ||
| 4583 | $iter = $self->insertWithTags($iter, $msg); | ||
| 4584 | } else { | ||
| 4585 | $iter = $self->insertWithTags($iter, $msg, $textColour); | ||
| 4586 | } | ||
| 4587 | |||
| 4588 | $self->insertNewLine($iter); | ||
| 4589 | |||
| 4590 | # Restore the cursor | ||
| 4591 | if ($self->tempInsertMark) { | ||
| 4592 | $self->moveCursor($self->buffer->get_iter_at_mark($self->tempInsertMark)); | ||
| 4593 | } else { | ||
| 4594 | $self->replaceCursor(); | ||
| 4595 | } | ||
| 4596 | |||
| 4597 | if ($self->scrollLockFlag) { | ||
| 4598 | |||
| 4599 | if ($self->scrollLockType eq 'top') { | ||
| 4600 | $self->scrollToTop(); | ||
| 4601 | } else { | ||
| 4602 | $self->scrollToBottom(); | ||
| 4603 | } | ||
| 4604 | } | ||
| 4605 | } | ||
| 4606 | |||
| 4607 | if (defined $msg && $msg ne '') { | ||
| 4608 | |||
| 4609 | if ($taskFlag) { | ||
| 4610 | |||
| 4611 | # Write the message in the System task window | ||
| 4612 | $self->session->systemTask->showWarning($msg); | ||
| 4613 | } | ||
| 4614 | |||
| 4615 | if ($consoleFlag) { | ||
| 4616 | |||
| 4617 | # Send the message to the GA::Session, for display (now or later) in the Session | ||
| 4618 | # Console window | ||
| 4619 | $self->session->add_systemMsg('warning', $msg); | ||
| 4620 | } | ||
| 4621 | |||
| 4622 | # Write to logs | ||
| 4623 | $axmud::CLIENT->writeLog( | ||
| 4624 | $self->session, | ||
| 4625 | TRUE, # Not world-specific logs | ||
| 4626 | $msg, | ||
| 4627 | $beforeFlag, | ||
| 4628 | TRUE, # Use final newline character | ||
| 4629 | 'main', 'errors', 'warning', # Write to these files | ||
| 4630 | ); | ||
| 4631 | |||
| 4632 | # Fire any hooks that are using the system hook events | ||
| 4633 | $self->session->checkHooks('system_warning', $msg); | ||
| 4634 | $self->session->checkHooks('system_all', $msg); | ||
| 4635 | $self->session->checkHooks('system_all_error', $msg); | ||
| 4636 | } | ||
| 4637 | |||
| 4638 | # Play a sound effect (if allowed, and if this textview object hasn't played the same | ||
| 4639 | # sound effect recently) | ||
| 4640 | if (! $self->soundCheckTime || $self->soundCheckTime < $axmud::CLIENT->clientTime) { | ||
| 4641 | |||
| 4642 | $axmud::CLIENT->playSound('error'); | ||
| 4643 | # Don't play it again for a few seconds | ||
| 4644 | $self->ivPoke('soundCheckTime', ($axmud::CLIENT->clientTime + $self->soundDelayTime)); | ||
| 4645 | } | ||
| 4646 | |||
| 4647 | # Convert text-to-speech, if required (but don't try to convert an 'undef' or text | ||
| 4648 | # containing no readable characters) | ||
| 4649 | if ( | ||
| 4650 | $axmud::CLIENT->systemAllowTTSFlag | ||
| 4651 | && $axmud::CLIENT->ttsSystemErrorFlag | ||
| 4652 | && defined $text | ||
| 4653 | && $text =~ m/\w/ | ||
| 4654 | # Also, temporarily don't convert system messages if the GA::Session flag is set | ||
| 4655 | && ! $self->session->ttsTempDisableFlag | ||
| 4656 | ) { | ||
| 4657 | # Make sure the received text is visible in the textview(s)... | ||
| 4658 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showWarning'); | ||
| 4659 | |||
| 4660 | # ...before converting text to speech | ||
| 4661 | if ( | ||
| 4662 | $axmud::CLIENT->ttsVerboseFlag | ||
| 4663 | && defined $self->session->ttsLastType | ||
| 4664 | && $self->session->ttsLastType ne 'error' | ||
| 4665 | ) { | ||
| 4666 | # Last TTS conversion was something other than a system error (etc) message | ||
| 4667 | $axmud::CLIENT->tts('System warning: ' . $text, 'error', 'error', $self->session); | ||
| 4668 | |||
| 4669 | } else { | ||
| 4670 | |||
| 4671 | # (Don't read out 'system warning' again and again and again! | ||
| 4672 | $axmud::CLIENT->tts($text, 'error', 'error', $self->session); | ||
| 4673 | } | ||
| 4674 | } | ||
| 4675 | |||
| 4676 | # This type of system message always requires a return value of 'undef' | ||
| 4677 | return undef; | ||
| 4678 | } | ||
| 4679 | |||
| 4680 | sub showDebug { | ||
| 4681 | |||
| 4682 | # Called by Games::Axmud->writeDebug or ->wd | ||
| 4683 | # Inserts a system debug message into the Gtk3::TextBuffer and/or updates the System task's | ||
| 4684 | # window | ||
| 4685 | # | ||
| 4686 | # Expected arguments | ||
| 4687 | # (none besides $self) | ||
| 4688 | # | ||
| 4689 | # Optional arguments | ||
| 4690 | # $text - The system text to write. If undefined, the text <<undef>> is written | ||
| 4691 | # $func - The function that produced the debug message (e.g. | ||
| 4692 | # 'Games::Axmud::Client->helloWorld'). If 'undef', the function is not | ||
| 4693 | # displayed | ||
| 4694 | # | ||
| 4695 | # Return values | ||
| 4696 | # 'undef' | ||
| 4697 | |||
| 4698 | my ($self, $text, $func, $check) = @_; | ||
| 4699 | |||
| 4700 | # Local variables | ||
| 4701 | my ( | ||
| 4702 | $colourSchemeObj, $monochromeFlag, $textColour, $msg, $systemTask, $hereFlag, $taskFlag, | ||
| 4703 | $consoleFlag, $iter, $beforeFlag, | ||
| 4704 | ); | ||
| 4705 | |||
| 4706 | # Check for improper arguments | ||
| 4707 | if (defined $check) { | ||
| 4708 | |||
| 4709 | return $axmud::CLIENT->writeImproper($self->_objClass . '->showDebug', @_); | ||
| 4710 | } | ||
| 4711 | |||
| 4712 | # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag) | ||
| 4713 | $self->removeCursor(); | ||
| 4714 | # If the buffer is due to be cleared before inserting any text, then clear it | ||
| 4715 | if ($self->clearAfterInsertFlag) { | ||
| 4716 | |||
| 4717 | # The TRUE argument means 'don't remove/move the cursor' | ||
| 4718 | $self->clearBuffer(undef, TRUE); | ||
| 4719 | } | ||
| 4720 | |||
| 4721 | # Import the colour scheme in use | ||
| 4722 | $colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme); | ||
| 4723 | # Choose which colour tags to use (in monochrome mode, text/underlay colours are ignored, | ||
| 4724 | # but in this case we don't any apply overrides specified by the colour scheme) | ||
| 4725 | if ($self->monochromeFlag || ($colourSchemeObj && $colourSchemeObj->overrideAllFlag)) { | ||
| 4726 | $monochromeFlag = TRUE; | ||
| 4727 | } else { | ||
| 4728 | $textColour = $axmud::CLIENT->customShowDebugColour; | ||
| 4729 | } | ||
| 4730 | |||
| 4731 | # Call to ->writeLog requires a TRUE/FALSE value | ||
| 4732 | $beforeFlag = FALSE; | ||
| 4733 | |||
| 4734 | # Prepare the message to send | ||
| 4735 | if (! defined $text) { | ||
| 4736 | |||
| 4737 | # 'undef' is a valid value - represent it | ||
| 4738 | $text = "<<undef>>"; | ||
| 4739 | } | ||
| 4740 | |||
| 4741 | if ($func) { | ||
| 4742 | $msg = "DEBUG: $func: $text"; | ||
| 4743 | } else { | ||
| 4744 | $msg = "DEBUG: $text"; | ||
| 4745 | } | ||
| 4746 | |||
| 4747 | # Whether the message is written only in this textview (mode 'original'), or in both this | ||
| 4748 | # textview and the System task's window ('both'), or in the System task's window only | ||
| 4749 | # (mode 'task'), depends on the System task's IVs (if the task is running) | ||
| 4750 | $systemTask = $self->session->systemTask; | ||
| 4751 | if (! $systemTask) { | ||
| 4752 | |||
| 4753 | $hereFlag = TRUE; | ||
| 4754 | |||
| 4755 | } else { | ||
| 4756 | |||
| 4757 | if ($systemTask->debugMode eq 'original') { | ||
| 4758 | |||
| 4759 | $hereFlag = TRUE; | ||
| 4760 | |||
| 4761 | } elsif ($systemTask->debugMode eq 'both') { | ||
| 4762 | |||
| 4763 | $hereFlag = TRUE; | ||
| 4764 | $taskFlag = TRUE; | ||
| 4765 | |||
| 4766 | } else { | ||
| 4767 | |||
| 4768 | $taskFlag = TRUE; | ||
| 4769 | } | ||
| 4770 | } | ||
| 4771 | |||
| 4772 | # If not allowed to write a system message in this textview, write to the Session Console | ||
| 4773 | # window instead | ||
| 4774 | if ( | ||
| 4775 | $hereFlag | ||
| 4776 | && (! $axmud::CLIENT->mainWinSystemMsgFlag || $self->overwriteFlag) | ||
| 4777 | ) { | ||
| 4778 | $hereFlag = FALSE; | ||
| 4779 | $consoleFlag = TRUE; | ||
| 4780 | } | ||
| 4781 | |||
| 4782 | if ($hereFlag) { | ||
| 4783 | |||
| 4784 | # If the previous call to $self->showSystemText displayed a message that didn't end in a | ||
| 4785 | # newline character, $self->systemInsertMark is set | ||
| 4786 | # In that case, we must insert an artificial newline character, so this system message | ||
| 4787 | # is displayed on its own line | ||
| 4788 | if ($self->systemInsertMark) { | ||
| 4789 | |||
| 4790 | $iter = $self->buffer->get_iter_at_mark($self->systemInsertMark); | ||
| 4791 | $iter = $self->insertNewLine($iter); | ||
| 4792 | $self->ivUndef('systemInsertMark'); | ||
| 4793 | |||
| 4794 | # If the last piece of text inserted at the Gtk3::TextBuffer via a call to | ||
| 4795 | # $self->insertText didn't end in a newline character, we need to insert an artifical | ||
| 4796 | # newline character so the system message appears on its own line, at the end of the | ||
| 4797 | # buffer | ||
| 4798 | } elsif ( | ||
| 4799 | # Last character in the buffer isn't a newline character | ||
| 4800 | ! $self->newLineFlag | ||
| 4801 | # The insertion point for $self->insertText and ->insertCmd is the end of the buffer | ||
| 4802 | && ! $self->insertMark | ||
| 4803 | ) { | ||
| 4804 | $iter = $self->buffer->get_end_iter(); | ||
| 4805 | $self->ivPoke( | ||
| 4806 | 'tempInsertMark', | ||
| 4807 | $self->buffer->create_mark('temp_insert_mark', $iter, TRUE), | ||
| 4808 | ); | ||
| 4809 | |||
| 4810 | $beforeFlag = TRUE; | ||
| 4811 | } | ||
| 4812 | # If the cursor is visible, remove it temporarily (i.e. remove the existing | ||
| 4813 | # Gtk3::TextTag) | ||
| 4814 | $self->removeCursor(); | ||
| 4815 | # If the buffer is due to be cleared before inserting any text, then clear it | ||
| 4816 | if ($self->clearAfterInsertFlag) { | ||
| 4817 | |||
| 4818 | # The TRUE argument means 'don't remove/move the cursor' | ||
| 4819 | $self->clearBuffer(undef, TRUE); | ||
| 4820 | } | ||
| 4821 | |||
| 4822 | # Set the insertion point | ||
| 4823 | $iter = $self->buffer->get_end_iter(); | ||
| 4824 | |||
| 4825 | # Insert the text into the Gtk3::TextBuffer | ||
| 4826 | if ($beforeFlag) { | ||
| 4827 | |||
| 4828 | # (Make sure the beginning of a link appears after the artificially-inserted newline | ||
| 4829 | # character, not before it) | ||
| 4830 | $iter = $self->insertNewLine($iter); | ||
| 4831 | } | ||
| 4832 | |||
| 4833 | if ($monochromeFlag) { | ||
| 4834 | $iter = $self->insertWithTags($iter, $msg); | ||
| 4835 | } else { | ||
| 4836 | $iter = $self->insertWithTags($iter, $msg, $textColour); | ||
| 4837 | } | ||
| 4838 | |||
| 4839 | $self->insertNewLine($iter); | ||
| 4840 | |||
| 4841 | # Restore the cursor | ||
| 4842 | if ($self->tempInsertMark) { | ||
| 4843 | $self->moveCursor($self->buffer->get_iter_at_mark($self->tempInsertMark)); | ||
| 4844 | } else { | ||
| 4845 | $self->replaceCursor(); | ||
| 4846 | } | ||
| 4847 | |||
| 4848 | if ($self->scrollLockFlag) { | ||
| 4849 | |||
| 4850 | if ($self->scrollLockType eq 'top') { | ||
| 4851 | $self->scrollToTop(); | ||
| 4852 | } else { | ||
| 4853 | $self->scrollToBottom(); | ||
| 4854 | } | ||
| 4855 | } | ||
| 4856 | } | ||
| 4857 | |||
| 4858 | if (defined $msg && $msg ne '') { | ||
| 4859 | |||
| 4860 | if ($taskFlag) { | ||
| 4861 | |||
| 4862 | # Write the message in the System task window | ||
| 4863 | $self->session->systemTask->showDebug($msg); | ||
| 4864 | } | ||
| 4865 | |||
| 4866 | if ($consoleFlag) { | ||
| 4867 | |||
| 4868 | # Send the message to the GA::Session, for display (now or later) in the Session | ||
| 4869 | # Console window | ||
| 4870 | $self->session->add_systemMsg('debug', $msg); | ||
| 4871 | } | ||
| 4872 | |||
| 4873 | # Write to logs | ||
| 4874 | $axmud::CLIENT->writeLog( | ||
| 4875 | $self->session, | ||
| 4876 | TRUE, # Not world-specific logs | ||
| 4877 | $msg, | ||
| 4878 | $beforeFlag, | ||
| 4879 | TRUE, # Use final newline character | ||
| 4880 | 'main', 'errors', 'debug', # Write to these files | ||
| 4881 | ); | ||
| 4882 | |||
| 4883 | # Fire any hooks that are using the system hook events | ||
| 4884 | $self->session->checkHooks('system_debug', $msg); | ||
| 4885 | $self->session->checkHooks('system_all', $msg); | ||
| 4886 | $self->session->checkHooks('system_all_error', $msg); | ||
| 4887 | } | ||
| 4888 | |||
| 4889 | # Play a sound effect (if allowed, and if this textview object hasn't played the same | ||
| 4890 | # sound effect recently) | ||
| 4891 | if (! $self->soundCheckTime || $self->soundCheckTime < $axmud::CLIENT->clientTime) { | ||
| 4892 | |||
| 4893 | $axmud::CLIENT->playSound('error'); | ||
| 4894 | # Don't play it again for a few seconds | ||
| 4895 | $self->ivPoke('soundCheckTime', ($axmud::CLIENT->clientTime + $self->soundDelayTime)); | ||
| 4896 | } | ||
| 4897 | |||
| 4898 | # Convert text-to-speech, if required (but don't try to convert an 'undef' or text | ||
| 4899 | # containing no readable characters) | ||
| 4900 | if ( | ||
| 4901 | $axmud::CLIENT->systemAllowTTSFlag | ||
| 4902 | && $axmud::CLIENT->ttsSystemErrorFlag | ||
| 4903 | && defined $text | ||
| 4904 | && $text =~ m/\w/ | ||
| 4905 | # Also, temporarily don't convert system messages if the GA::Session flag is set | ||
| 4906 | && ! $self->session->ttsTempDisableFlag | ||
| 4907 | ) { | ||
| 4908 | # Make sure the received text is visible in the textview(s)... | ||
| 4909 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showDebug'); | ||
| 4910 | |||
| 4911 | # ...before converting text to speech | ||
| 4912 | if ( | ||
| 4913 | $axmud::CLIENT->ttsVerboseFlag | ||
| 4914 | && defined $self->session->ttsLastType | ||
| 4915 | && $self->session->ttsLastType ne 'error' | ||
| 4916 | ) { | ||
| 4917 | # Last TTS conversion was something other than a system error (etc) message | ||
| 4918 | $axmud::CLIENT->tts('System debug: ' . $text, 'error', 'error', $self->session); | ||
| 4919 | |||
| 4920 | } else { | ||
| 4921 | |||
| 4922 | # (Don't read out 'system debug' again and again and again! | ||
| 4923 | $axmud::CLIENT->tts($text, 'error', 'error', $self->session); | ||
| 4924 | } | ||
| 4925 | } | ||
| 4926 | |||
| 4927 | # This type of system message always requires a return value of 'undef' | ||
| 4928 | return undef; | ||
| 4929 | } | ||
| 4930 | |||
| 4931 | sub showImproper { | ||
| 4932 | |||
| 4933 | # Called by Games::Axmud->writeImproper | ||
| 4934 | # Inserts a system 'improper arguments' message into the Gtk3::TextBuffer and/or updates the | ||
| 4935 | # System task's window | ||
| 4936 | # | ||
| 4937 | # Expected arguments | ||
| 4938 | # $func - The function that produced the message (e.g. | ||
| 4939 | # 'Games::Axmud::Client->helloWorld') | ||
| 4940 | # | ||
| 4941 | # Optional arguments | ||
| 4942 | # @args - A list of arguments passed by the function that called the | ||
| 4943 | # ->writeImproper() function. If no arguments were passed, an empty list | ||
| 4944 | # | ||
| 4945 | # Return values | ||
| 4946 | # 'undef' | ||
| 4947 | |||
| 4948 | my ($self, $func, @args) = @_; | ||
| 4949 | |||
| 4950 | # Local variables | ||
| 4951 | my ( | ||
| 4952 | $colourSchemeObj, $monochromeFlag, $textColour, $msg, $systemTask, $hereFlag, $taskFlag, | ||
| 4953 | $consoleFlag, $iter, $beforeFlag, | ||
| 4954 | ); | ||
| 4955 | |||
| 4956 | # Check for improper arguments | ||
| 4957 | if (! defined $func) { | ||
| 4958 | |||
| 4959 | # This function mustn't call itself, so write something to the terminal | ||
| 4960 | print "ERROR: Recursive improper arguments call from $func\n"; | ||
| 4961 | return undef; | ||
| 4962 | } | ||
| 4963 | |||
| 4964 | # Import the colour scheme in use | ||
| 4965 | $colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme); | ||
| 4966 | # Choose which colour tags to use (in monochrome mode, text/underlay colours are ignored, | ||
| 4967 | # but in this case we don't any apply overrides specified by the colour scheme) | ||
| 4968 | if ($self->monochromeFlag || ($colourSchemeObj && $colourSchemeObj->overrideAllFlag)) { | ||
| 4969 | $monochromeFlag = TRUE; | ||
| 4970 | } else { | ||
| 4971 | $textColour = $axmud::CLIENT->customShowImproperColour; | ||
| 4972 | } | ||
| 4973 | |||
| 4974 | # Call to ->writeLog requires a TRUE/FALSE value | ||
| 4975 | $beforeFlag = FALSE; | ||
| 4976 | |||
| 4977 | # Prepare the message to send. Some of the values in @args might be 'undef'; these need to | ||
| 4978 | # be replaced by some text that can actually be displayed | ||
| 4979 | foreach my $arg (@args) { | ||
| 4980 | |||
| 4981 | if (! defined $arg) { | ||
| 4982 | |||
| 4983 | $arg = "<<undef>>"; | ||
| 4984 | } | ||
| 4985 | } | ||
| 4986 | |||
| 4987 | $msg = "IMPROPER ARGS: $func() " . join (" ", @args); | ||
| 4988 | |||
| 4989 | # Whether the message is written only in this textview (mode 'original'), or in both this | ||
| 4990 | # textview and the System task's window ('both'), or in the System task's window only | ||
| 4991 | # (mode 'task'), depends on the System task's IVs (if the task is running) | ||
| 4992 | $systemTask = $self->session->systemTask; | ||
| 4993 | if (! $systemTask) { | ||
| 4994 | |||
| 4995 | $hereFlag = TRUE; | ||
| 4996 | |||
| 4997 | } else { | ||
| 4998 | |||
| 4999 | if ($systemTask->improperMode eq 'original') { | ||
| 5000 | |||
| 5001 | $hereFlag = TRUE; | ||
| 5002 | |||
| 5003 | } elsif ($systemTask->improperMode eq 'both') { | ||
| 5004 | |||
| 5005 | $hereFlag = TRUE; | ||
| 5006 | $taskFlag = TRUE; | ||
| 5007 | |||
| 5008 | } else { | ||
| 5009 | |||
| 5010 | $taskFlag = TRUE; | ||
| 5011 | } | ||
| 5012 | } | ||
| 5013 | |||
| 5014 | # If not allowed to write a system message in this textview, write to the Session Console | ||
| 5015 | # window instead | ||
| 5016 | if ( | ||
| 5017 | $hereFlag | ||
| 5018 | && (! $axmud::CLIENT->mainWinSystemMsgFlag || $self->overwriteFlag) | ||
| 5019 | ) { | ||
| 5020 | $hereFlag = FALSE; | ||
| 5021 | $consoleFlag = TRUE; | ||
| 5022 | } | ||
| 5023 | |||
| 5024 | if ($hereFlag) { | ||
| 5025 | |||
| 5026 | # If the previous call to $self->showSystemText displayed a message that didn't end in a | ||
| 5027 | # newline character, $self->systemInsertMark is set | ||
| 5028 | # In that case, we must insert an artificial newline character, so this system message | ||
| 5029 | # is displayed on its own line | ||
| 5030 | if ($self->systemInsertMark) { | ||
| 5031 | |||
| 5032 | $iter = $self->buffer->get_iter_at_mark($self->systemInsertMark); | ||
| 5033 | $iter = $self->insertNewLine($iter); | ||
| 5034 | $self->ivUndef('systemInsertMark'); | ||
| 5035 | |||
| 5036 | # If the last piece of text inserted at the Gtk3::TextBuffer via a call to | ||
| 5037 | # $self->insertText didn't end in a newline character, we need to insert an artifical | ||
| 5038 | # newline character so the system message appears on its own line, at the end of the | ||
| 5039 | # buffer | ||
| 5040 | } elsif ( | ||
| 5041 | # Last character in the buffer isn't a newline character | ||
| 5042 | ! $self->newLineFlag | ||
| 5043 | # The insertion point for $self->insertText and ->insertCmd is the end of the buffer | ||
| 5044 | && ! $self->insertMark | ||
| 5045 | ) { | ||
| 5046 | $iter = $self->buffer->get_end_iter(); | ||
| 5047 | $self->ivPoke( | ||
| 5048 | 'tempInsertMark', | ||
| 5049 | $self->buffer->create_mark('temp_insert_mark', $iter, TRUE), | ||
| 5050 | ); | ||
| 5051 | |||
| 5052 | $beforeFlag = TRUE; | ||
| 5053 | } | ||
| 5054 | |||
| 5055 | # If the cursor is visible, remove it temporarily (i.e. remove the existing | ||
| 5056 | # Gtk3::TextTag) | ||
| 5057 | $self->removeCursor(); | ||
| 5058 | # If the buffer is due to be cleared before inserting any text, then clear it | ||
| 5059 | if ($self->clearAfterInsertFlag) { | ||
| 5060 | |||
| 5061 | # The TRUE argument means 'don't remove/move the cursor' | ||
| 5062 | $self->clearBuffer(undef, TRUE); | ||
| 5063 | } | ||
| 5064 | |||
| 5065 | # Set the insertion point | ||
| 5066 | $iter = $self->buffer->get_end_iter(); | ||
| 5067 | |||
| 5068 | # Insert the text into the Gtk3::TextBuffer | ||
| 5069 | if ($beforeFlag) { | ||
| 5070 | |||
| 5071 | # (Make sure the beginning of a link appears after the artificially-inserted newline | ||
| 5072 | # character, not before it) | ||
| 5073 | $iter = $self->insertNewLine($iter); | ||
| 5074 | } | ||
| 5075 | |||
| 5076 | if ($monochromeFlag) { | ||
| 5077 | $iter = $self->insertWithTags($iter, $msg); | ||
| 5078 | } else { | ||
| 5079 | $iter = $self->insertWithTags($iter, $msg, $textColour); | ||
| 5080 | } | ||
| 5081 | |||
| 5082 | $self->insertNewLine($iter); | ||
| 5083 | |||
| 5084 | # Restore the cursor | ||
| 5085 | if ($self->tempInsertMark) { | ||
| 5086 | $self->moveCursor($self->buffer->get_iter_at_mark($self->tempInsertMark)); | ||
| 5087 | } else { | ||
| 5088 | $self->replaceCursor(); | ||
| 5089 | } | ||
| 5090 | |||
| 5091 | if ($self->scrollLockFlag) { | ||
| 5092 | |||
| 5093 | if ($self->scrollLockType eq 'top') { | ||
| 5094 | $self->scrollToTop(); | ||
| 5095 | } else { | ||
| 5096 | $self->scrollToBottom(); | ||
| 5097 | } | ||
| 5098 | } | ||
| 5099 | } | ||
| 5100 | |||
| 5101 | if (defined $msg && $msg ne '') { | ||
| 5102 | |||
| 5103 | if ($taskFlag) { | ||
| 5104 | |||
| 5105 | # Write the message in the System task window | ||
| 5106 | $self->session->systemTask->showImproper($msg); | ||
| 5107 | } | ||
| 5108 | |||
| 5109 | if ($consoleFlag) { | ||
| 5110 | |||
| 5111 | # Send the message to the GA::Session, for display (now or later) in the Session | ||
| 5112 | # Console window | ||
| 5113 | $self->session->add_systemMsg('improper', $msg); | ||
| 5114 | } | ||
| 5115 | |||
| 5116 | # Write to logs | ||
| 5117 | $axmud::CLIENT->writeLog( | ||
| 5118 | $self->session, | ||
| 5119 | TRUE, # Not world-specific logs | ||
| 5120 | $msg, | ||
| 5121 | $beforeFlag, | ||
| 5122 | TRUE, # Use final newline character | ||
| 5123 | 'main', 'errors', 'improper', # Write to these files | ||
| 5124 | ); | ||
| 5125 | |||
| 5126 | # Fire any hooks that are using the system hook events | ||
| 5127 | $self->session->checkHooks('system_improper', $msg); | ||
| 5128 | $self->session->checkHooks('system_all', $msg); | ||
| 5129 | $self->session->checkHooks('system_all_error', $msg); | ||
| 5130 | } | ||
| 5131 | |||
| 5132 | # Play a sound effect (if allowed, and if this textview object hasn't played the same | ||
| 5133 | # sound effect recently) | ||
| 5134 | if (! $self->soundCheckTime || $self->soundCheckTime < $axmud::CLIENT->clientTime) { | ||
| 5135 | |||
| 5136 | $axmud::CLIENT->playSound('error'); | ||
| 5137 | # Don't play it again for a few seconds | ||
| 5138 | $self->ivPoke('soundCheckTime', ($axmud::CLIENT->clientTime + $self->soundDelayTime)); | ||
| 5139 | } | ||
| 5140 | |||
| 5141 | # # v1.2.208 Improper args messages are incomprehensible, when converted to speech; so this | ||
| 5142 | # # is now disabled | ||
| 5143 | # # Convert text-to-speech, if required (but don't try to convert an 'undef' or text | ||
| 5144 | # # containing no readable characters) | ||
| 5145 | # if ( | ||
| 5146 | # $axmud::CLIENT->systemAllowTTSFlag | ||
| 5147 | # && $axmud::CLIENT->ttsSystemFlag | ||
| 5148 | # && defined $msg | ||
| 5149 | # && $msg =~ m/\w/ | ||
| 5150 | # # Also, temporarily don't convert system messages if the GA::Session flag is set | ||
| 5151 | # && ! $self->session->ttsTempDisableFlag | ||
| 5152 | # ) { | ||
| 5153 | # # Make sure the received text is visible in the textview(s)... | ||
| 5154 | # $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->showImproper'); | ||
| 5155 | # | ||
| 5156 | # # ...before converting text to speech | ||
| 5157 | # $axmud::CLIENT->tts( | ||
| 5158 | # 'System error: improper arguments in function: ' . $func, | ||
| 5159 | # 'error', | ||
| 5160 | # 'error', | ||
| 5161 | # $self->session, | ||
| 5162 | # ); | ||
| 5163 | # } | ||
| 5164 | |||
| 5165 | # This type of system message always requires a return value of 'undef' | ||
| 5166 | return undef; | ||
| 5167 | } | ||
| 5168 | |||
| 5169 | sub showImage { | ||
| 5170 | |||
| 5171 | # Can be called by anything | ||
| 5172 | # Inserts an image pixbuf into the textview at the current insertion point | ||
| 5173 | # | ||
| 5174 | # Expected arguments | ||
| 5175 | # $pixbuf - The Gtk3::Gdk::Pixbuf or Gtk3::Gdk::PixbufAnimation of the image to | ||
| 5176 | # display | ||
| 5177 | # | ||
| 5178 | # Optional arguments | ||
| 5179 | # $linkObj - For clickable images, the corresponding GA::Obj::Link object. Can be a an | ||
| 5180 | # incomplete link object created by GA::Session's MXP functions (for | ||
| 5181 | # example), or a completed link object stored in this textview object's | ||
| 5182 | # ->linkObjHash; otherwise 'undef' | ||
| 5183 | # $padWidth, $padHeight | ||
| 5184 | # - Optional padding around the image, in pixels (not the width/height of the | ||
| 5185 | # image itself; that is only specified by the pixbuf) | ||
| 5186 | # @args - Optional list of arguments, in any order: | ||
| 5187 | # - 'empty' (empties the buffer before writing $text) | ||
| 5188 | # - 'before' (prepends a newline character to $text) | ||
| 5189 | # - 'after' or 'nl' (appends a newline character to $text) | ||
| 5190 | # - 'echo' (does not prepend/append a newline character, overrides | ||
| 5191 | # 'before', 'after' and 'nl' if they are specified) | ||
| 5192 | # | ||
| 5193 | # - NB The default behaviour is set by $self->defaultNewLine, which is set to | ||
| 5194 | # 'before', 'after', 'nl' or 'echo'. This default behaviour is only | ||
| 5195 | # applied if none of 'before', 'after', 'nl' and 'echo' are specified | ||
| 5196 | # - NB If @args contains Axmud colour/style tags (as they might in a call to | ||
| 5197 | # $self->insertText), they are ignored | ||
| 5198 | # | ||
| 5199 | # Return values | ||
| 5200 | # 'undef' on improper arguments | ||
| 5201 | # 1 otherwise | ||
| 5202 | |||
| 5203 | my ($self, $pixbuf, $linkObj, $padWidth, $padHeight, @args) = @_; | ||
| 5204 | |||
| 5205 | # Local variables | ||
| 5206 | my ( | ||
| 5207 | $animFlag, $emptyFlag, $beforeFlag, $afterFlag, $mark, $iter, $image, $packWidget, | ||
| 5208 | $ebox, $anchor, $lineNum, $posn, $newMark, $newIter, $tempInsertFlag, | ||
| 5209 | ); | ||
| 5210 | |||
| 5211 | # Check for improper arguments | ||
| 5212 | if (! defined $pixbuf) { | ||
| 5213 | |||
| 5214 | return $axmud::CLIENT->writeImproper($self->_objClass . '->showImage', @_); | ||
| 5215 | } | ||
| 5216 | |||
| 5217 | # Test whether the $pixbuf is an animated gif, received by this function as a | ||
| 5218 | # Gtk3::Gdk::PixbufAnimation-related object, or an unanimated image (including gifs), | ||
| 5219 | # received by this function as a Gtk3::Gdk::Pixbuf | ||
| 5220 | if (ref ($pixbuf) =~ /Anim/) { | ||
| 5221 | |||
| 5222 | $animFlag = TRUE; | ||
| 5223 | } | ||
| 5224 | |||
| 5225 | # If the cursor is visible, remove it temporarily (i.e. remove the existing Gtk3::TextTag) | ||
| 5226 | $self->removeCursor(); | ||
| 5227 | # If the buffer is due to be cleared before inserting any text, then clear it | ||
| 5228 | if ($self->clearAfterInsertFlag || $emptyFlag) { | ||
| 5229 | |||
| 5230 | # The TRUE argument means 'don't remove/move the cursor' | ||
| 5231 | $self->clearBuffer(undef, TRUE); | ||
| 5232 | } | ||
| 5233 | |||
| 5234 | # Interpret the list of @args, ignoring most of the usual return values | ||
| 5235 | ($emptyFlag, $beforeFlag, $afterFlag) = $self->interpretTags($self->newLineDefault, @args); | ||
| 5236 | |||
| 5237 | # Set the insertion point | ||
| 5238 | if ($self->insertMark) { | ||
| 5239 | |||
| 5240 | $mark = $self->insertMark; | ||
| 5241 | |||
| 5242 | } elsif ($self->tempInsertMark) { | ||
| 5243 | |||
| 5244 | $mark = $self->tempInsertMark; | ||
| 5245 | if ($afterFlag) { | ||
| 5246 | |||
| 5247 | # This code prevents a blank line being inserted between a world's prompt and the | ||
| 5248 | # already-displayed Axmud system message | ||
| 5249 | $self->ivUndef('tempInsertMark'); | ||
| 5250 | $afterFlag = FALSE; | ||
| 5251 | $tempInsertFlag = TRUE; | ||
| 5252 | } | ||
| 5253 | } | ||
| 5254 | |||
| 5255 | if ($mark) { | ||
| 5256 | $iter = $self->buffer->get_iter_at_mark($mark); | ||
| 5257 | } elsif (! $self->systemInsertMark) { | ||
| 5258 | $iter = $self->buffer->get_end_iter(); | ||
| 5259 | } else { | ||
| 5260 | |||
| 5261 | # Incomplete system message after a call to $self->showSystemText without a newline | ||
| 5262 | # character. Must insert an artificial newline character, and display $pixbuf after | ||
| 5263 | # that | ||
| 5264 | $iter = $self->buffer->get_iter_at_mark($self->systemInsertMark); | ||
| 5265 | $iter = $self->insertNewLine($iter); | ||
| 5266 | } | ||
| 5267 | |||
| 5268 | # (Don't prepend a newline character if the buffer is empty) | ||
| 5269 | if ($beforeFlag && $self->bufferTextFlag) { | ||
| 5270 | |||
| 5271 | # (Make sure the beginning of a link appears after the extra newline character, not | ||
| 5272 | # before it) | ||
| 5273 | $iter = $self->insertNewLine($iter); | ||
| 5274 | } | ||
| 5275 | |||
| 5276 | # Get the position of the iter now, before it becomes invalid | ||
| 5277 | $lineNum = $iter->get_line(); | ||
| 5278 | $posn = $iter->get_visible_line_offset(); | ||
| 5279 | |||
| 5280 | # Create the image | ||
| 5281 | if (! $animFlag) { | ||
| 5282 | |||
| 5283 | $image = $packWidget = Gtk3::Image->new_from_pixbuf($pixbuf); | ||
| 5284 | |||
| 5285 | } else { | ||
| 5286 | |||
| 5287 | $image = $packWidget = Gtk3::Image->new(); | ||
| 5288 | $image->set_from_animation($pixbuf); | ||
| 5289 | } | ||
| 5290 | |||
| 5291 | # If the image should be clickable, pack it inside an event box | ||
| 5292 | if (defined $linkObj) { | ||
| 5293 | |||
| 5294 | $ebox = Gtk3::EventBox->new(); | ||
| 5295 | $ebox->signal_connect('button-press-event' => sub { | ||
| 5296 | |||
| 5297 | my ($widget, $event) = @_; | ||
| 5298 | |||
| 5299 | # Local variables | ||
| 5300 | my ($x, $y, $href); | ||
| 5301 | |||
| 5302 | # Check the link is completed (not temporary) and that it hasn't expired | ||
| 5303 | if ( | ||
| 5304 | defined $linkObj->number | ||
| 5305 | && $linkObj->number != -1 | ||
| 5306 | && $self->ivExists('linkObjHash', $linkObj->number) | ||
| 5307 | ) { | ||
| 5308 | # Substitute for %x and %y | ||
| 5309 | $x = $event->x; | ||
| 5310 | $y = $event->y; | ||
| 5311 | $href = $linkObj->href; | ||
| 5312 | |||
| 5313 | $href =~ s/\%x/$x/; | ||
| 5314 | $href =~ s/\%y/$y/; | ||
| 5315 | |||
| 5316 | if ($linkObj->mxpInvisFlag) { | ||
| 5317 | $self->session->send($href); | ||
| 5318 | } else { | ||
| 5319 | $self->session->worldCmd($href); | ||
| 5320 | } | ||
| 5321 | } | ||
| 5322 | }); | ||
| 5323 | |||
| 5324 | $ebox->signal_connect('enter-notify-event' => sub { | ||
| 5325 | |||
| 5326 | $self->textView->get_window('text')->set_cursor($axmud::CLIENT->constWWWCursor); | ||
| 5327 | }); | ||
| 5328 | |||
| 5329 | $ebox->signal_connect('leave-notify-event' => sub { | ||
| 5330 | |||
| 5331 | $self->textView->get_window('text')->set_cursor($axmud::CLIENT->constNormalCursor); | ||
| 5332 | }); | ||
| 5333 | |||
| 5334 | $ebox->add($image); | ||
| 5335 | $packWidget = $ebox; | ||
| 5336 | } | ||
| 5337 | |||
| 5338 | # Apply padding, if specified | ||
| 5339 | if ($padWidth && ! ($padWidth =~ m/\D/)) { | ||
| 5340 | |||
| 5341 | my $hBox = Gtk3::HBox->new(); | ||
| 5342 | $hBox->pack_start($packWidget, FALSE, FALSE, $padWidth); | ||
| 5343 | |||
| 5344 | $packWidget = $hBox; | ||
| 5345 | } | ||
| 5346 | |||
| 5347 | if ($padHeight && ! ($padHeight =~ m/\D/)) { | ||
| 5348 | |||
| 5349 | my $vBox = Gtk3::VBox->new(); | ||
| 5350 | $vBox->pack_start($packWidget, FALSE, FALSE, $padHeight); | ||
| 5351 | |||
| 5352 | $packWidget = $vBox; | ||
| 5353 | } | ||
| 5354 | |||
| 5355 | # Insert the image into the textview | ||
| 5356 | $anchor = $self->buffer->create_child_anchor($iter); | ||
| 5357 | $self->textView->add_child_at_anchor($packWidget, $anchor); | ||
| 5358 | |||
| 5359 | # Set the new insert iter. The Gtk docs state that the image counts as one character | ||
| 5360 | $newIter = $self->buffer->get_iter_at_line_offset($lineNum, ($posn + 1)); | ||
| 5361 | |||
| 5362 | if ($afterFlag) { | ||
| 5363 | |||
| 5364 | # (Make sure the end of a link appears before the extra newline character, not | ||
| 5365 | # after it) | ||
| 5366 | $newIter = $self->insertNewLine($newIter); | ||
| 5367 | } | ||
| 5368 | |||
| 5369 | if ($self->insertMark) { | ||
| 5370 | |||
| 5371 | # The next call to $self->insertText, ->insertCmd etc uses the insertion point | ||
| 5372 | # immediately after $newIter | ||
| 5373 | $newMark = $self->buffer->create_mark('insert_mark', $newIter, TRUE); | ||
| 5374 | $self->ivPoke('insertMark', $newMark); | ||
| 5375 | # If the cursor is visible, move it to this position (i.e. insert a new Gtk3::TextTag) | ||
| 5376 | $self->moveCursor($self->buffer->get_iter_at_mark($mark)); | ||
| 5377 | |||
| 5378 | } elsif ($tempInsertFlag) { | ||
| 5379 | |||
| 5380 | # Continue using this temporary insertion point, before a line with a system message | ||
| 5381 | # (and don't restore the cursor yet) | ||
| 5382 | $newMark = $self->buffer->create_mark('temp_insert_mark', $newIter, TRUE); | ||
| 5383 | $self->ivPoke('tempInsertMark', $newMark); | ||
| 5384 | |||
| 5385 | } else { | ||
| 5386 | |||
| 5387 | # If the cursor is visible, move it to the end of the buffer (i.e. insert a new | ||
| 5388 | # Gtk3::TextTag) | ||
| 5389 | $self->moveCursor(); | ||
| 5390 | } | ||
| 5391 | |||
| 5392 | if ($self->scrollLockFlag) { | ||
| 5393 | |||
| 5394 | if ($self->scrollLockType eq 'top') { | ||
| 5395 | $self->scrollToTop(); | ||
| 5396 | } else { | ||
| 5397 | $self->scrollToBottom(); | ||
| 5398 | } | ||
| 5399 | |||
| 5400 | } else { | ||
| 5401 | |||
| 5402 | # Scroll to the point immediately after the image's insertion point | ||
| 5403 | $self->scrollToIter($newIter); | ||
| 5404 | } | ||
| 5405 | |||
| 5406 | # Animated pixbufs will not be visible reliably without this line | ||
| 5407 | $self->winObj->winShowAll($self->_objClass . '->showImage'); | ||
| 5408 | |||
| 5409 | return 1; | ||
| 5410 | } | ||
| 5411 | |||
| 5412 | sub removeCursor { | ||
| 5413 | |||
| 5414 | # Called by $self->insertText, ->insertMultipleText, ->insertQuick and ->insertCmd | ||
| 5415 | # 'Removes' the visible cursor, usually before a call to $self->moveCursor to move it | ||
| 5416 | # somewhere else | ||
| 5417 | # Also removes the extract space character at the end of the buffer, if one was created by | ||
| 5418 | # $self->moveCursor | ||
| 5419 | # | ||
| 5420 | # Expected arguments | ||
| 5421 | # (none besides $self) | ||
| 5422 | # | ||
| 5423 | # Return values | ||
| 5424 | # 'undef' on improper arguments, if visible cursors are disabled in this textview or if no | ||
| 5425 | # visible cursor has been drawn yet | ||
| 5426 | # 1 otherwise | ||
| 5427 | |||
| 5428 | my ($self, $check) = @_; | ||
| 5429 | |||
| 5430 | # Local variables | ||
| 5431 | my ($nextIter, $iter); | ||
| 5432 | |||
| 5433 | # Check for improper arguments | ||
| 5434 | if (defined $check) { | ||
| 5435 | |||
| 5436 | return $axmud::CLIENT->writeImproper($self->_objClass . '->removeCursor', @_); | ||
| 5437 | } | ||
| 5438 | |||
| 5439 | # Do nothing if visible cursors are disabled in this textview, or if no cursor has been | ||
| 5440 | # drawn by an earlier call to $self->moveCursor | ||
| 5441 | if (! $self->cursorEnableFlag || ! $self->cursorMark) { | ||
| 5442 | |||
| 5443 | return undef; | ||
| 5444 | } | ||
| 5445 | |||
| 5446 | $nextIter = $self->buffer->get_iter_at_mark($self->cursorMark); | ||
| 5447 | if (! $nextIter) { | ||
| 5448 | |||
| 5449 | return undef; | ||
| 5450 | |||
| 5451 | } else { | ||
| 5452 | |||
| 5453 | $nextIter->forward_char(); | ||
| 5454 | $iter = $self->buffer->get_iter_at_mark($self->cursorMark); | ||
| 5455 | } | ||
| 5456 | |||
| 5457 | # Remove the Gtk3::TextTag | ||
| 5458 | $self->buffer->remove_tag_by_name( | ||
| 5459 | 'cursor', | ||
| 5460 | # Would like to remove the text tag just for the one space character, but it doesn't | ||
| 5461 | # work | ||
| 5462 | $iter, | ||
| 5463 | $self->buffer->get_end_iter(), | ||
| 5464 | ); | ||
| 5465 | |||
| 5466 | # Remove the extra space that was added, if the cursor was position at the end of the buffer | ||
| 5467 | # (if a system message has been displayed, it might not be the end of the buffer now) | ||
| 5468 | if ($self->cursorEndFlag) { | ||
| 5469 | |||
| 5470 | $self->buffer->delete($iter, $nextIter); | ||
| 5471 | } | ||
| 5472 | |||
| 5473 | # Remove the mark | ||
| 5474 | $self->buffer->delete_mark($self->cursorMark); | ||
| 5475 | |||
| 5476 | # Update IVs | ||
| 5477 | $self->ivUndef('cursorMark'); | ||
| 5478 | $self->ivPoke('cursorEndFlag', FALSE); | ||
| 5479 | |||
| 5480 | return 1; | ||
| 5481 | } | ||
| 5482 | |||
| 5483 | sub moveCursor { | ||
| 5484 | |||
| 5485 | # Called by $self->insertText, ->insertMultipleText, ->insertQuick and ->insertCmd | ||
| 5486 | # 'Moves' the visible cursor to a specified position, or to the end of the buffer | ||
| 5487 | # If at the end of the buffer, or at the end of line, adds an extra space character so that | ||
| 5488 | # the cursor is actually visible | ||
| 5489 | # | ||
| 5490 | # Expected arguments | ||
| 5491 | # (none besides $self) | ||
| 5492 | # | ||
| 5493 | # Optional arguments | ||
| 5494 | # $iter - The Gtk3::TextIter at which to position the cursor. If 'undef', the cursor is | ||
| 5495 | # positioned at the end of the buffer | ||
| 5496 | # | ||
| 5497 | # Return values | ||
| 5498 | # 'undef' on improper arguments or if visible cursors are disabled in this textview | ||
| 5499 | # 1 otherwise | ||
| 5500 | |||
| 5501 | my ($self, $iter, $check) = @_; | ||
| 5502 | |||
| 5503 | # Local variables | ||
| 5504 | my ($endIter, $lastFlag, $cursorMark, $nextIter, $length); | ||
| 5505 | |||
| 5506 | # Check for improper arguments | ||
| 5507 | if (defined $check) { | ||
| 5508 | |||
| 5509 | return $axmud::CLIENT->writeImproper($self->_objClass . '->moveCursor', @_); | ||
| 5510 | } | ||
| 5511 | |||
| 5512 | # Do nothing if visible cursors are disabled in this textview | ||
| 5513 | if (! $self->cursorEnableFlag) { | ||
| 5514 | |||
| 5515 | return undef; | ||
| 5516 | } | ||
| 5517 | |||
| 5518 | $endIter = $self->buffer->get_end_iter(); | ||
| 5519 | if (! $iter || $endIter->get_line() == $iter->get_line()) { | ||
| 5520 | |||
| 5521 | # Insert position is on the buffer's last line | ||
| 5522 | $lastFlag = TRUE; | ||
| 5523 | } | ||
| 5524 | |||
| 5525 | if ( | ||
| 5526 | ! defined $iter | ||
| 5527 | || ( | ||
| 5528 | $lastFlag | ||
| 5529 | && $endIter->get_visible_line_offset() == $iter->get_visible_line_offset() | ||
| 5530 | ) | ||
| 5531 | ) { | ||
| 5532 | $cursorMark = $self->buffer->create_mark('cursor_mark', $endIter, TRUE); | ||
| 5533 | |||
| 5534 | # Insert a space character at the end of the buffer, so that the visible cursor is | ||
| 5535 | # actually visible | ||
| 5536 | $self->buffer->insert_with_tags_by_name( | ||
| 5537 | $self->buffer->get_end_iter(), | ||
| 5538 | ' ', | ||
| 5539 | 'cursor', | ||
| 5540 | ); | ||
| 5541 | |||
| 5542 | # Update IVs | ||
| 5543 | $self->ivPoke('cursorMark', $cursorMark); | ||
| 5544 | $self->ivPoke('cursorEndFlag', TRUE); | ||
| 5545 | |||
| 5546 | } else { | ||
| 5547 | |||
| 5548 | $cursorMark = $self->buffer->create_mark('cursor_mark', $iter, TRUE); | ||
| 5549 | |||
| 5550 | $nextIter = $self->buffer->get_iter_at_mark($cursorMark); | ||
| 5551 | if (! $nextIter) { | ||
| 5552 | |||
| 5553 | return undef; | ||
| 5554 | |||
| 5555 | } else { | ||
| 5556 | |||
| 5557 | $nextIter->forward_char(); | ||
| 5558 | $iter = $self->buffer->get_iter_at_mark($cursorMark); | ||
| 5559 | } | ||
| 5560 | |||
| 5561 | # If the visible cursor is at the end of a line (i.e. just before a newline character), | ||
| 5562 | # insert a space character there so that the visible cursor is actually visible | ||
| 5563 | $length = $self->getLineLength($iter); | ||
| 5564 | if ( | ||
| 5565 | ($lastFlag && $iter->get_visible_line_offset() >= $length) | ||
| 5566 | || (! $lastFlag && $iter->get_visible_line_offset() >= ($length - 1)) | ||
| 5567 | ) { | ||
| 5568 | $self->buffer->insert_with_tags_by_name( | ||
| 5569 | $iter, | ||
| 5570 | ' ', | ||
| 5571 | 'cursor', | ||
| 5572 | ); | ||
| 5573 | |||
| 5574 | } else { | ||
| 5575 | |||
| 5576 | # Just insert the Gtk3::TextTag for the cursor at this position | ||
| 5577 | $self->buffer->apply_tag_by_name( | ||
| 5578 | 'cursor', | ||
| 5579 | $iter, | ||
| 5580 | $nextIter, | ||
| 5581 | ); | ||
| 5582 | } | ||
| 5583 | |||
| 5584 | # Update IVs | ||
| 5585 | $self->ivPoke('cursorMark', $cursorMark); | ||
| 5586 | $self->ivPoke('cursorEndFlag', FALSE); | ||
| 5587 | } | ||
| 5588 | |||
| 5589 | return 1; | ||
| 5590 | } | ||
| 5591 | |||
| 5592 | sub replaceCursor { | ||
| 5593 | |||
| 5594 | # Called by the clear buffer/clear line operations (e.g. $self->clearBufferAfterMark, | ||
| 5595 | # ->clearLineAroundPosn, etc) | ||
| 5596 | # Calls $self->moveCursor with the correct arguments for the current situation | ||
| 5597 | # | ||
| 5598 | # Expected arguments | ||
| 5599 | # (none besides $self) | ||
| 5600 | # | ||
| 5601 | # Return values | ||
| 5602 | # 'undef' on improper arguments | ||
| 5603 | # Otherwise returns the result of the call to $self-> moveCursor | ||
| 5604 | |||
| 5605 | my ($self, $check) = @_; | ||
| 5606 | |||
| 5607 | # Check for improper arguments | ||
| 5608 | if (defined $check) { | ||
| 5609 | |||
| 5610 | return $axmud::CLIENT->writeImproper($self->_objClass . '->replaceCursor', @_); | ||
| 5611 | } | ||
| 5612 | |||
| 5613 | if ($self->insertMark) { | ||
| 5614 | return $self->moveCursor($self->buffer->get_iter_at_mark($self->insertMark)); | ||
| 5615 | } else { | ||
| 5616 | return $self->moveCursor($self->buffer->get_end_iter()); | ||
| 5617 | } | ||
| 5618 | } | ||
| 5619 | |||
| 5620 | # Other functions - search the buffer | ||
| 5621 | |||
| 5622 | sub setSearchMark { | ||
| 5623 | |||
| 5624 | # Can be called by anything | ||
| 5625 | # Moves the Gtk3::TextMark used for searching the buffer from its current position to a new | ||
| 5626 | # position | ||
| 5627 | # | ||
| 5628 | # Expected arguments | ||
| 5629 | # (none besides $self) | ||
| 5630 | # | ||
| 5631 | # Optional arguments | ||
| 5632 | # $line - The line number at which to place the mark. Use 0 for the beginning of the | ||
| 5633 | # buffer, 1 for the second line, and so on. If 'undef' or if $line is greater | ||
| 5634 | # than the size of the buffer, the mark is placed at the end of the buffer | ||
| 5635 | # $offset - The offset on the line at which to place the mark. Use 0 for the beginning of | ||
| 5636 | # the line, 1 to place the mark before the 2nd character, and so on. If | ||
| 5637 | # 'undef', the mark is placed at the end of the line (but before the newline | ||
| 5638 | # character, if any) | ||
| 5639 | # | ||
| 5640 | # Return values | ||
| 5641 | # 'undef' on improper arguments | ||
| 5642 | # 1 otherwise | ||
| 5643 | |||
| 5644 | my ($self, $line, $offset, $check) = @_; | ||
| 5645 | |||
| 5646 | # Local variables | ||
| 5647 | my ($size, $startIter, $length, $endIter); | ||
| 5648 | |||
| 5649 | # Check for improper arguments | ||
| 5650 | if (defined $check) { | ||
| 5651 | |||
| 5652 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setSearchMark', @_); | ||
| 5653 | } | ||
| 5654 | |||
| 5655 | # Get the current size of the buffer | ||
| 5656 | $size = $self->buffer->get_line_count(); | ||
| 5657 | if (! defined $line || $line >= $size) { | ||
| 5658 | |||
| 5659 | $line = $size - 1; | ||
| 5660 | } | ||
| 5661 | |||
| 5662 | # Get the iter at the start of that line | ||
| 5663 | $startIter = $self->buffer->get_iter_at_line_offset($line, 0); | ||
| 5664 | $length = $self->getLineLength($startIter); | ||
| 5665 | |||
| 5666 | # Get the iter at the end of the buffer. If this line is not the last line in the buffer, | ||
| 5667 | # we need to take account of the newline character | ||
| 5668 | $endIter = $self->buffer->get_end_iter(); | ||
| 5669 | if ($endIter->get_line() != $startIter->get_line()) { | ||
| 5670 | |||
| 5671 | $length--; | ||
| 5672 | } | ||
| 5673 | |||
| 5674 | if (! defined $offset || $offset >= $length) { | ||
| 5675 | |||
| 5676 | $offset = $length - 1; | ||
| 5677 | # Sanity check | ||
| 5678 | if ($offset < 0) { | ||
| 5679 | |||
| 5680 | $offset = 0; | ||
| 5681 | } | ||
| 5682 | } | ||
| 5683 | |||
| 5684 | # Move the search mark to the specified location | ||
| 5685 | $self->ivPoke( | ||
| 5686 | 'searchMark', | ||
| 5687 | $self->buffer->create_mark( | ||
| 5688 | 'search_mark', | ||
| 5689 | $self->buffer->get_iter_at_line_offset($line, $offset), | ||
| 5690 | TRUE, | ||
| 5691 | ), | ||
| 5692 | ); | ||
| 5693 | |||
| 5694 | return 1; | ||
| 5695 | } | ||
| 5696 | |||
| 5697 | sub searchBuffer { | ||
| 5698 | |||
| 5699 | # Can be called by anything | ||
| 5700 | # Searches the buffer using a specified pattern, stopping at the first matching text | ||
| 5701 | # If the beginning of the buffer is reached and no match is found, the search continues | ||
| 5702 | # from the end of the buffer (and vice versa) | ||
| 5703 | # If a match is found, moves $self->searchMark to just before (or after) that location, so | ||
| 5704 | # the next search can continue from that point | ||
| 5705 | # | ||
| 5706 | # Expected arguments | ||
| 5707 | # $regex - The regex to match | ||
| 5708 | # $mode - FALSE to search, line by line, from before $self->searchMark; TRUE to | ||
| 5709 | # search, line by line, from after $self->searchMark | ||
| 5710 | # | ||
| 5711 | # Optional arguments | ||
| 5712 | # $selectFlag - If TRUE, the matching text is selected and the textview is scrolled to the | ||
| 5713 | # matching text | ||
| 5714 | # $caseFlag - If TRUE, a case-sensitive match is performed. If FALSE (or 'undef'), a | ||
| 5715 | # case-insensitive match is performed | ||
| 5716 | # | ||
| 5717 | # Return values | ||
| 5718 | # An empty list on improper arguments or if no matching text is found | ||
| 5719 | # 1 otherwise | ||
| 5720 | |||
| 5721 | my ($self, $regex, $mode, $selectFlag, $caseFlag, $check) = @_; | ||
| 5722 | |||
| 5723 | # Local variables | ||
| 5724 | my ( | ||
| 5725 | $size, $searchIter, $searchLine, $searchPosn, $text, $matchLine, $matchPosn, $matchLen, | ||
| 5726 | $matchIter, | ||
| 5727 | @emptyList, | ||
| 5728 | ); | ||
| 5729 | |||
| 5730 | # Check for improper arguments | ||
| 5731 | if (defined $check) { | ||
| 5732 | |||
| 5733 | $axmud::CLIENT->writeImproper($self->_objClass . '->searchBuffer', @_); | ||
| 5734 | return @emptyList; | ||
| 5735 | } | ||
| 5736 | |||
| 5737 | # Obviously, if the regex is empty, then there's nothing so search | ||
| 5738 | if ($regex eq '') { | ||
| 5739 | |||
| 5740 | return @emptyList; | ||
| 5741 | } | ||
| 5742 | |||
| 5743 | # Get the size of the buffer | ||
| 5744 | $size = $self->buffer->get_line_count(); | ||
| 5745 | if (! $size) { | ||
| 5746 | |||
| 5747 | # Buffer is empty | ||
| 5748 | return @emptyList; | ||
| 5749 | } | ||
| 5750 | |||
| 5751 | # $self->searchIter records the position of the last successful search (or the position at | ||
| 5752 | # which to start a search), so we'll start there | ||
| 5753 | $searchIter = $self->buffer->get_iter_at_mark($self->searchMark); | ||
| 5754 | if (! $searchIter) { | ||
| 5755 | |||
| 5756 | # Something's gone wrong | ||
| 5757 | return @emptyList; | ||
| 5758 | } | ||
| 5759 | |||
| 5760 | # If searching forwards, start searching from the first character after $searchIter | ||
| 5761 | if ($mode) { | ||
| 5762 | |||
| 5763 | $searchIter->forward_char(); | ||
| 5764 | } | ||
| 5765 | |||
| 5766 | $searchLine = $searchIter->get_line(); | ||
| 5767 | $searchPosn = $searchIter->get_line_offset(); | ||
| 5768 | |||
| 5769 | # Search lines, one by one, starting with $searchLine | ||
| 5770 | if (! $mode) { | ||
| 5771 | |||
| 5772 | $text = $self->buffer->get_text( | ||
| 5773 | $self->buffer->get_iter_at_line_offset($searchLine, 0), | ||
| 5774 | $searchIter, | ||
| 5775 | FALSE, | ||
| 5776 | ); | ||
| 5777 | |||
| 5778 | } elsif ($searchLine >= ($size - 1)) { | ||
| 5779 | |||
| 5780 | $text = $self->buffer->get_text( | ||
| 5781 | $searchIter, | ||
| 5782 | $self->buffer->get_end_iter(), | ||
| 5783 | FALSE, | ||
| 5784 | ); | ||
| 5785 | |||
| 5786 | } else { | ||
| 5787 | |||
| 5788 | $text = $self->buffer->get_text( | ||
| 5789 | $searchIter, | ||
| 5790 | $self->buffer->get_iter_at_line_offset(($searchLine + 1), 0), | ||
| 5791 | FALSE, | ||
| 5792 | ); | ||
| 5793 | } | ||
| 5794 | |||
| 5795 | if ( | ||
| 5796 | $text ne '' | ||
| 5797 | && ( | ||
| 5798 | # Find last match in $text, just before $searchMark | ||
| 5799 | ( | ||
| 5800 | ! $mode | ||
| 5801 | && ( | ||
| 5802 | (! $caseFlag && $text =~ m/$regex/gi) | ||
| 5803 | || ($caseFlag && $text =~ m/$regex/g) | ||
| 5804 | ) | ||
| 5805 | # Find first match in $text, just after $searchMark | ||
| 5806 | ) || ( | ||
| 5807 | $mode | ||
| 5808 | && ( | ||
| 5809 | (! $caseFlag && $text =~ m/$regex/i) | ||
| 5810 | || ($caseFlag && $text =~ m/$regex/) | ||
| 5811 | ) | ||
| 5812 | ) | ||
| 5813 | ) | ||
| 5814 | ) { | ||
| 5815 | # Match found! | ||
| 5816 | $matchLine = $searchLine; | ||
| 5817 | $matchPosn = $-[0]; | ||
| 5818 | $matchLen = $+[0] - $matchPosn; | ||
| 5819 | if ($mode) { | ||
| 5820 | |||
| 5821 | $matchPosn += $searchPosn; | ||
| 5822 | } | ||
| 5823 | |||
| 5824 | $self->setSearchMark($matchLine, $matchPosn); | ||
| 5825 | if ($selectFlag) { | ||
| 5826 | |||
| 5827 | $self->selectTextInLine($matchLine, $matchPosn, $matchLen, TRUE); | ||
| 5828 | } | ||
| 5829 | |||
| 5830 | return ($matchLine, $matchPosn, $matchLen); | ||
| 5831 | } | ||
| 5832 | |||
| 5833 | # Search before (or after) $searchLine | ||
| 5834 | if ($size > 1) { | ||
| 5835 | |||
| 5836 | if (! $mode && $searchLine > 0) { | ||
| 5837 | |||
| 5838 | for (my $count = ($searchLine - 1); $count >= 0; $count--) { | ||
| 5839 | |||
| 5840 | $text = $self->buffer->get_text( | ||
| 5841 | $self->buffer->get_iter_at_line_offset($count, 0), | ||
| 5842 | $self->buffer->get_iter_at_line_offset(($count + 1), 0), | ||
| 5843 | FALSE, | ||
| 5844 | ); | ||
| 5845 | |||
| 5846 | # Find last match in $text | ||
| 5847 | if ( | ||
| 5848 | $text ne '' | ||
| 5849 | && ( | ||
| 5850 | (! $caseFlag && $text =~ m/$regex/gi) | ||
| 5851 | || ($caseFlag && $text =~ m/$regex/g) | ||
| 5852 | ) | ||
| 5853 | ) { | ||
| 5854 | # Match found! | ||
| 5855 | $matchLine = $count; | ||
| 5856 | $matchPosn = $-[0]; | ||
| 5857 | $matchLen = $+[0] - $matchPosn; | ||
| 5858 | |||
| 5859 | $self->setSearchMark($matchLine, $matchPosn); | ||
| 5860 | if ($selectFlag) { | ||
| 5861 | |||
| 5862 | $self->selectTextInLine($matchLine, $matchPosn, $matchLen, TRUE); | ||
| 5863 | } | ||
| 5864 | |||
| 5865 | return ($matchLine, $matchPosn, $matchLen); | ||
| 5866 | } | ||
| 5867 | } | ||
| 5868 | |||
| 5869 | } elsif ($mode && $searchLine < ($size - 1)) { | ||
| 5870 | |||
| 5871 | for (my $count = ($searchLine + 1); $count <= ($size - 1); $count++) { | ||
| 5872 | |||
| 5873 | $text = $self->buffer->get_text( | ||
| 5874 | $self->buffer->get_iter_at_line_offset($count, 0), | ||
| 5875 | $self->buffer->get_iter_at_line_offset(($count + 1), 0), | ||
| 5876 | FALSE, | ||
| 5877 | ); | ||
| 5878 | |||
| 5879 | # Find first match in $text | ||
| 5880 | if ( | ||
| 5881 | $text ne '' | ||
| 5882 | && ( | ||
| 5883 | (! $caseFlag && $text =~ m/$regex/i) | ||
| 5884 | || ($caseFlag && $text =~ m/$regex/) | ||
| 5885 | ) | ||
| 5886 | ) { | ||
| 5887 | # Match found! | ||
| 5888 | $matchLine = $count; | ||
| 5889 | $matchPosn = $-[0]; | ||
| 5890 | $matchLen = $+[0] - $matchPosn; | ||
| 5891 | |||
| 5892 | $self->setSearchMark($matchLine, $matchPosn); | ||
| 5893 | if ($selectFlag) { | ||
| 5894 | |||
| 5895 | $self->selectTextInLine($matchLine, $matchPosn, $matchLen, TRUE); | ||
| 5896 | } | ||
| 5897 | |||
| 5898 | return ($matchLine, $matchPosn, $matchLen); | ||
| 5899 | } | ||
| 5900 | } | ||
| 5901 | } | ||
| 5902 | |||
| 5903 | # Reached the beginning (or the end) of the buffer, so now search the other part of the | ||
| 5904 | # buffer from the opposite direction (i.e. if we reached the beginning of the buffer, | ||
| 5905 | # search from the end) | ||
| 5906 | if (! $mode && $searchLine < ($size - 1)) { | ||
| 5907 | |||
| 5908 | for (my $count = ($size - 1); $count > $searchLine; $count--) { | ||
| 5909 | |||
| 5910 | $text = $self->buffer->get_text( | ||
| 5911 | $self->buffer->get_iter_at_line_offset($count, 0), | ||
| 5912 | $self->buffer->get_iter_at_line_offset(($count + 1), 0), | ||
| 5913 | FALSE, | ||
| 5914 | ); | ||
| 5915 | |||
| 5916 | # Find first match in $text | ||
| 5917 | if ( | ||
| 5918 | $text ne '' | ||
| 5919 | && ( | ||
| 5920 | (! $caseFlag && $text =~ m/$regex/i) | ||
| 5921 | || ($caseFlag && $text =~ m/$regex/) | ||
| 5922 | ) | ||
| 5923 | ) { | ||
| 5924 | # Match found! | ||
| 5925 | $matchLine = $count; | ||
| 5926 | $matchPosn = $-[0]; | ||
| 5927 | $matchLen = $+[0] - $matchPosn; | ||
| 5928 | |||
| 5929 | $self->setSearchMark($matchLine, $matchPosn); | ||
| 5930 | if ($selectFlag) { | ||
| 5931 | |||
| 5932 | $self->selectTextInLine($matchLine, $matchPosn, $matchLen, TRUE); | ||
| 5933 | } | ||
| 5934 | |||
| 5935 | return ($matchLine, $matchPosn, $matchLen); | ||
| 5936 | } | ||
| 5937 | } | ||
| 5938 | |||
| 5939 | } elsif ($mode && $searchLine > 0) { | ||
| 5940 | |||
| 5941 | for (my $count = 0; $count < $searchLine; $count++) { | ||
| 5942 | |||
| 5943 | $text = $self->buffer->get_text( | ||
| 5944 | $self->buffer->get_iter_at_line_offset($count, 0), | ||
| 5945 | $self->buffer->get_iter_at_line_offset(($count + 1), 0), | ||
| 5946 | FALSE, | ||
| 5947 | ); | ||
| 5948 | |||
| 5949 | # Find first match in $text | ||
| 5950 | if ( | ||
| 5951 | $text ne '' | ||
| 5952 | && ( | ||
| 5953 | (! $caseFlag && $text =~ m/$regex/gi) | ||
| 5954 | || ($caseFlag && $text =~ m/$regex/g) | ||
| 5955 | ) | ||
| 5956 | ) { | ||
| 5957 | # Match found! | ||
| 5958 | $matchLine = $count; | ||
| 5959 | $matchPosn = $-[0]; | ||
| 5960 | $matchLen = $+[0] - $matchPosn; | ||
| 5961 | |||
| 5962 | $self->setSearchMark($matchLine, $matchPosn); | ||
| 5963 | if ($selectFlag) { | ||
| 5964 | |||
| 5965 | $self->selectTextInLine($matchLine, $matchPosn, $matchLen, TRUE); | ||
| 5966 | } | ||
| 5967 | |||
| 5968 | return ($matchLine, $matchPosn, $matchLen); | ||
| 5969 | } | ||
| 5970 | } | ||
| 5971 | } | ||
| 5972 | } | ||
| 5973 | |||
| 5974 | # Now search the other part of $searchLine | ||
| 5975 | if ($mode) { | ||
| 5976 | |||
| 5977 | $text = $self->buffer->get_text( | ||
| 5978 | $self->buffer->get_iter_at_line_offset($searchLine, 0), | ||
| 5979 | $searchIter, | ||
| 5980 | FALSE, | ||
| 5981 | ); | ||
| 5982 | |||
| 5983 | } elsif ($searchLine >= ($size - 1)) { | ||
| 5984 | |||
| 5985 | $text = $self->buffer->get_text( | ||
| 5986 | $searchIter, | ||
| 5987 | $self->buffer->get_end_iter(), | ||
| 5988 | FALSE, | ||
| 5989 | ); | ||
| 5990 | |||
| 5991 | } else { | ||
| 5992 | |||
| 5993 | $text = $self->buffer->get_text( | ||
| 5994 | $searchIter, | ||
| 5995 | $self->buffer->get_iter_at_line_offset(($searchLine + 1), 0), | ||
| 5996 | FALSE, | ||
| 5997 | ); | ||
| 5998 | } | ||
| 5999 | |||
| 6000 | if ( | ||
| 6001 | $text ne '' | ||
| 6002 | && ( | ||
| 6003 | # Find last match in $text, just before $searchMark | ||
| 6004 | ( | ||
| 6005 | $mode | ||
| 6006 | && ( | ||
| 6007 | (! $caseFlag && $text =~ m/$regex/gi) | ||
| 6008 | || ($caseFlag && $text =~ m/$regex/g) | ||
| 6009 | ) | ||
| 6010 | # Find first match in $text, just after $searchMark | ||
| 6011 | ) || ( | ||
| 6012 | ! $mode | ||
| 6013 | && ( | ||
| 6014 | (! $caseFlag && $text =~ m/$regex/i) | ||
| 6015 | || ($caseFlag && $text =~ m/$regex/) | ||
| 6016 | ) | ||
| 6017 | ) | ||
| 6018 | ) | ||
| 6019 | ) { | ||
| 6020 | # Match found! | ||
| 6021 | $matchLine = $searchLine; | ||
| 6022 | $matchPosn = $-[0]; | ||
| 6023 | $matchLen = $+[0] - $matchPosn; | ||
| 6024 | if ($mode) { | ||
| 6025 | |||
| 6026 | $matchPosn += $searchPosn; | ||
| 6027 | } | ||
| 6028 | |||
| 6029 | $self->setSearchMark($matchLine, $matchPosn); | ||
| 6030 | if ($selectFlag) { | ||
| 6031 | |||
| 6032 | $self->selectTextInLine($matchLine, $matchPosn, $matchLen, TRUE); | ||
| 6033 | } | ||
| 6034 | |||
| 6035 | return ($matchLine, $matchPosn, $matchLen); | ||
| 6036 | } | ||
| 6037 | |||
| 6038 | # No matches found | ||
| 6039 | return @emptyList; | ||
| 6040 | } | ||
| 6041 | |||
| 6042 | sub selectTextInLine { | ||
| 6043 | |||
| 6044 | # Can be called by anything, but mainly called by $self->searchBuffer | ||
| 6045 | # Selects some text on a single line, from one specified position to another. If required, | ||
| 6046 | # the textview is scrolled to the start of the selected text | ||
| 6047 | # | ||
| 6048 | # Expected arguments | ||
| 6049 | # $line - The line number at which to select text. If the buffer doesn't contain | ||
| 6050 | # enough lines, no text is selected | ||
| 6051 | # $offset - The offset on the line from which to select text. If the line doesn't | ||
| 6052 | # contain enough characters, no text is selected | ||
| 6053 | # $selectLength - The length of the selected text. If it's longer than the line itself, | ||
| 6054 | # $selectLength is shortened so that only text on one line is selected | ||
| 6055 | # | ||
| 6056 | # Optional arguments | ||
| 6057 | # $scrollFlag - If TRUE, the textview is scrolled to $line. If FALSE or 'undef', no | ||
| 6058 | # scrolling takes place | ||
| 6059 | # | ||
| 6060 | # Return values | ||
| 6061 | # 'undef' on improper arguments or if no text can be selected | ||
| 6062 | # 1 otherwise | ||
| 6063 | |||
| 6064 | my ($self, $line, $offset, $selectLength, $scrollFlag, $check) = @_; | ||
| 6065 | |||
| 6066 | # Local variables | ||
| 6067 | my ($size, $startIter, $lineLength, $endIter); | ||
| 6068 | |||
| 6069 | # Check for improper arguments | ||
| 6070 | if (! defined $line || ! defined $offset || ! defined $selectLength || defined $check) { | ||
| 6071 | |||
| 6072 | return $axmud::CLIENT->writeImproper($self->_objClass . '->selectTextInLine', @_); | ||
| 6073 | } | ||
| 6074 | |||
| 6075 | # Get the current size of the buffer | ||
| 6076 | $size = $self->buffer->get_line_count(); | ||
| 6077 | if ($line >= $size) { | ||
| 6078 | |||
| 6079 | # Buffer isn't big enough | ||
| 6080 | return undef; | ||
| 6081 | } | ||
| 6082 | |||
| 6083 | # Get the iter at the specified position | ||
| 6084 | $startIter = $self->buffer->get_iter_at_line_offset($line, $offset); | ||
| 6085 | $lineLength = $self->getLineLength($startIter); | ||
| 6086 | |||
| 6087 | # Get the iter at the end of the buffer. If this line is not the last line in the buffer, | ||
| 6088 | # we need to take account of the newline character | ||
| 6089 | $endIter = $self->buffer->get_end_iter(); | ||
| 6090 | if ($endIter->get_line() != $startIter->get_line()) { | ||
| 6091 | |||
| 6092 | $lineLength--; | ||
| 6093 | } | ||
| 6094 | |||
| 6095 | if ($offset >= $lineLength) { | ||
| 6096 | |||
| 6097 | # The specified offset occurs after the end of the line | ||
| 6098 | return undef; | ||
| 6099 | |||
| 6100 | } elsif (($offset + $selectLength) >= $lineLength) { | ||
| 6101 | |||
| 6102 | # Reduce $selectLength so that text to the end of the line is selected | ||
| 6103 | $selectLength = $lineLength - $offset; | ||
| 6104 | if (! $selectLength) { | ||
| 6105 | |||
| 6106 | # No text to select | ||
| 6107 | return undef; | ||
| 6108 | } | ||
| 6109 | } | ||
| 6110 | |||
| 6111 | # Select the text | ||
| 6112 | $self->buffer->select_range( | ||
| 6113 | $startIter, | ||
| 6114 | $self->buffer->get_iter_at_line_offset($line, ($offset + $selectLength)), | ||
| 6115 | ); | ||
| 6116 | |||
| 6117 | # Scroll the textview, if required | ||
| 6118 | if ($scrollFlag) { | ||
| 6119 | |||
| 6120 | if ($endIter->get_line() == $startIter->get_line()) { | ||
| 6121 | |||
| 6122 | $self->scrollToBottom(); | ||
| 6123 | |||
| 6124 | } else { | ||
| 6125 | |||
| 6126 | # Scroll to one line after the the matching text, as it looks nicer. The TRUE | ||
| 6127 | # argument means to scroll $self->textView2, if split-screen mode is one | ||
| 6128 | $self->scrollToIter( | ||
| 6129 | $self->buffer->get_iter_at_line_offset(($line + 1), 0), | ||
| 6130 | TRUE, | ||
| 6131 | ); | ||
| 6132 | } | ||
| 6133 | } | ||
| 6134 | |||
| 6135 | return 1; | ||
| 6136 | } | ||
| 6137 | |||
| 6138 | sub unselectText { | ||
| 6139 | |||
| 6140 | # Can be called by anything | ||
| 6141 | # Unselects any text in the textview (possibly from an earlier call to | ||
| 6142 | # $self->selectTextInLine) | ||
| 6143 | # | ||
| 6144 | # Expected arguments | ||
| 6145 | # (none besides $self) | ||
| 6146 | # | ||
| 6147 | # Return values | ||
| 6148 | # 'undef' on improper arguments | ||
| 6149 | # 1 otherwise | ||
| 6150 | |||
| 6151 | my ($self, $check) = @_; | ||
| 6152 | |||
| 6153 | # Local variables | ||
| 6154 | my $iter; | ||
| 6155 | |||
| 6156 | # Check for improper arguments | ||
| 6157 | if (defined $check) { | ||
| 6158 | |||
| 6159 | return $axmud::CLIENT->writeImproper($self->_objClass . '->unselectText', @_); | ||
| 6160 | } | ||
| 6161 | |||
| 6162 | $iter = $self->buffer->get_iter_at_mark($self->searchMark); | ||
| 6163 | $self->buffer->select_range($iter, $iter); | ||
| 6164 | |||
| 6165 | return 1; | ||
| 6166 | } | ||
| 6167 | |||
| 6168 | # Other functions - must be called by specific code | ||
| 6169 | |||
| 6170 | sub setupScroller { | ||
| 6171 | |||
| 6172 | # Called by $self->objEnable, ->objUpdate and ->enableSingleScreen | ||
| 6173 | # Sets up the container widgets in which a single textview is displayed (when split screen | ||
| 6174 | # mode is off) | ||
| 6175 | # | ||
| 6176 | # Expected arguments | ||
| 6177 | # $textView - The Gtk3::TextView to pack into its container widgets | ||
| 6178 | # | ||
| 6179 | # Return values | ||
| 6180 | # 'undef' on improper arguments | ||
| 6181 | # Otherwise returns the Gtk3::ScrolledWindow which contains the textview | ||
| 6182 | |||
| 6183 | my ($self, $textView, $check) = @_; | ||
| 6184 | |||
| 6185 | # Check for improper arguments | ||
| 6186 | if (! defined $textView || defined $check) { | ||
| 6187 | |||
| 6188 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setupScroller', @_); | ||
| 6189 | } | ||
| 6190 | |||
| 6191 | my $scroll = Gtk3::ScrolledWindow->new(undef, undef); | ||
| 6192 | $scroll->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 6193 | $scroll->set_policy('automatic', 'automatic'); # But word-wrapping turned on | ||
| 6194 | $scroll->set_border_width(0); | ||
| 6195 | |||
| 6196 | # Pack the textview | ||
| 6197 | $scroll->add($textView); | ||
| 6198 | |||
| 6199 | # Set up a ->signal_connect to detect scrolling, so we can reset the cursor (so the user | ||
| 6200 | # can't move the cursor above a link, wait until the link scrolls away, and then still | ||
| 6201 | # click the link) | ||
| 6202 | $self->setTextViewScrollEvent($scroll, $textView); | ||
| 6203 | |||
| 6204 | return $scroll; | ||
| 6205 | } | ||
| 6206 | |||
| 6207 | sub setupVPaned { | ||
| 6208 | |||
| 6209 | # Called by $self->objUpdate, ->enableSplitScreen and ->enableHiddenSplitScreen | ||
| 6210 | # Sets up the container widgets in which the two textviews are displayed (when split screen | ||
| 6211 | # mode is on) | ||
| 6212 | # | ||
| 6213 | # Expected arguments | ||
| 6214 | # $textView, $textView2 | ||
| 6215 | # - The Gtk3::TextViews to pack into their container widgets | ||
| 6216 | # | ||
| 6217 | # Return values | ||
| 6218 | # An empty list on improper arguments | ||
| 6219 | # Otherwise returns a list in the form | ||
| 6220 | # (vpaned, scrolled_window, scrolled_window) | ||
| 6221 | |||
| 6222 | my ($self, $textView, $textView2, $check) = @_; | ||
| 6223 | |||
| 6224 | # Local variables | ||
| 6225 | my ( | ||
| 6226 | $width, $height, | ||
| 6227 | @emptyList, | ||
| 6228 | ); | ||
| 6229 | |||
| 6230 | # Check for improper arguments | ||
| 6231 | if (! defined $textView || ! defined $textView2 || defined $check) { | ||
| 6232 | |||
| 6233 | $axmud::CLIENT->writeImproper($self->_objClass . '->setupVPaned', @_); | ||
| 6234 | return @emptyList; | ||
| 6235 | } | ||
| 6236 | |||
| 6237 | my $vPaned = Gtk3::VPaned->new(); | ||
| 6238 | $vPaned->set_wide_handle(TRUE); | ||
| 6239 | |||
| 6240 | # Decide where to put the Gtk3::VPaned divider | ||
| 6241 | $self->setDividerPosn($vPaned); | ||
| 6242 | |||
| 6243 | # When replacing a single textview with two, the original textview ($textView) is added to | ||
| 6244 | # the bottom half of the vpaned | ||
| 6245 | my $scroll = Gtk3::ScrolledWindow->new(undef, undef); | ||
| 6246 | $vPaned->pack2($scroll, FALSE, FALSE); | ||
| 6247 | $scroll->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 6248 | $scroll->set_policy('automatic', 'automatic'); # But word-wrapping turned on | ||
| 6249 | $scroll->set_border_width(0); | ||
| 6250 | |||
| 6251 | my $scroll2 = Gtk3::ScrolledWindow->new(undef, undef); | ||
| 6252 | $vPaned->pack1($scroll2, FALSE, TRUE); | ||
| 6253 | $scroll2->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 6254 | $scroll2->set_policy('automatic', 'automatic'); # But word-wrapping turned on | ||
| 6255 | $scroll2->set_border_width(0); | ||
| 6256 | |||
| 6257 | # Pack the textviews | ||
| 6258 | if ($textView->get_parent()) { | ||
| 6259 | |||
| 6260 | $textView->unparent(); | ||
| 6261 | } | ||
| 6262 | |||
| 6263 | $scroll->add($textView); | ||
| 6264 | $scroll2->add($textView2); | ||
| 6265 | |||
| 6266 | # Set up ->signal_connects to detect textview scrolling, so we can reset the cursor (so the | ||
| 6267 | # user can't move the cursor above a link, wait until the link scrolls away, and then | ||
| 6268 | # still click the link) | ||
| 6269 | $self->setTextViewScrollEvent($scroll, $textView); | ||
| 6270 | $self->setTextViewScrollEvent($scroll2, $textView2); | ||
| 6271 | |||
| 6272 | return ($vPaned, $scroll, $scroll2) | ||
| 6273 | } | ||
| 6274 | |||
| 6275 | sub setDividerPosn { | ||
| 6276 | |||
| 6277 | # Called by $self->setupVPaned, ->enableSplitScreen and ->enableHiddenSplitScreen | ||
| 6278 | # In split screen modes 'split' and 'hidden', sets the position of the Gtk3::VPaned's | ||
| 6279 | # divider | ||
| 6280 | # | ||
| 6281 | # Expected arguments | ||
| 6282 | # $vPaned - The Gtk3::VPaned object | ||
| 6283 | # | ||
| 6284 | # Return values | ||
| 6285 | # 'undef' on improper arguments | ||
| 6286 | # 1 otherwise | ||
| 6287 | |||
| 6288 | my ($self, $vPaned, $check) = @_; | ||
| 6289 | |||
| 6290 | # Local variables | ||
| 6291 | my ($width, $height); | ||
| 6292 | |||
| 6293 | # Check for improper arguments | ||
| 6294 | if (! defined $vPaned || defined $check) { | ||
| 6295 | |||
| 6296 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setDividerPosn', @_); | ||
| 6297 | } | ||
| 6298 | |||
| 6299 | # Decide where to put the divider | ||
| 6300 | if ($self->splitScreenMode eq 'split') { | ||
| 6301 | |||
| 6302 | ($width, $height) = $self->paneObj->getTabSize(); | ||
| 6303 | if (! defined $height) { | ||
| 6304 | $vPaned->set_position(100); | ||
| 6305 | } else { | ||
| 6306 | $vPaned->set_position(int($height / 2)); | ||
| 6307 | } | ||
| 6308 | |||
| 6309 | } elsif ($self->splitScreenMode eq 'hidden') { | ||
| 6310 | |||
| 6311 | # Setting the position of the divider directly to 0 does not work, but this does work, | ||
| 6312 | # for reasons unknown | ||
| 6313 | $vPaned->set_position(1); | ||
| 6314 | $vPaned->set_position(0); | ||
| 6315 | } | ||
| 6316 | |||
| 6317 | return 1; | ||
| 6318 | } | ||
| 6319 | |||
| 6320 | sub createTextViewWidget { | ||
| 6321 | |||
| 6322 | # Called by various functions in this textview object (only) to create a uniform | ||
| 6323 | # Gtk3::Textview widget | ||
| 6324 | # | ||
| 6325 | # Expected arguments | ||
| 6326 | # $buffer - The Gtk3::TextBuffer to use in the textview | ||
| 6327 | # | ||
| 6328 | # Optional arguments | ||
| 6329 | # $schemeObj - The colour scheme object (GA::Obj::ColourScheme), if known; otherwise, | ||
| 6330 | # this function looks it up | ||
| 6331 | # | ||
| 6332 | # Return values | ||
| 6333 | # 'undef' on improper arguments | ||
| 6334 | # 1 otherwise | ||
| 6335 | |||
| 6336 | my ($self, $buffer, $schemeObj, $check) = @_; | ||
| 6337 | |||
| 6338 | # Check for improper arguments | ||
| 6339 | if (! defined $buffer || defined $check) { | ||
| 6340 | |||
| 6341 | return $axmud::CLIENT->writeImproper($self->_objClass . '->createTextViewWidget', @_); | ||
| 6342 | } | ||
| 6343 | |||
| 6344 | # Fetch the colour scheme object, if not supplied | ||
| 6345 | if (! $schemeObj) { | ||
| 6346 | |||
| 6347 | $schemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme); | ||
| 6348 | } | ||
| 6349 | |||
| 6350 | # Create the new textview | ||
| 6351 | my $textView = Gtk3::TextView->new_with_buffer($buffer); | ||
| 6352 | |||
| 6353 | $textView->set_editable(FALSE); | ||
| 6354 | $textView->set_cursor_visible(FALSE); # Invisible cursor | ||
| 6355 | $textView->set_can_focus(FALSE); | ||
| 6356 | $textView->set_justification('left'); | ||
| 6357 | $textView->set_overwrite($self->overwriteFlag); | ||
| 6358 | |||
| 6359 | if ($schemeObj->wrapMode eq 'no_wrap') { | ||
| 6360 | $textView->set_wrap_mode('none'); | ||
| 6361 | } elsif ($schemeObj->wrapMode eq 'wrap_char') { | ||
| 6362 | $textView->set_wrap_mode('char'); | ||
| 6363 | } elsif ($schemeObj->wrapMode eq 'wrap_word') { | ||
| 6364 | $textView->set_wrap_mode('word'); | ||
| 6365 | } elsif ($schemeObj->wrapMode eq 'wrap_word_char') { | ||
| 6366 | $textView->set_wrap_mode('word-char'); | ||
| 6367 | } | ||
| 6368 | |||
| 6369 | # Set up ->signal_connects | ||
| 6370 | $self->setMotionNotifyEvent($textView); # 'motion-notify-event' | ||
| 6371 | $self->setLeaveNotifyEvent($textView); # 'leave-notify-event' | ||
| 6372 | $self->setFocusOutEvent($textView); # 'focus-out-event' | ||
| 6373 | $self->setButtonPressEvent($textView); # 'button-press-event' | ||
| 6374 | |||
| 6375 | return $textView; | ||
| 6376 | } | ||
| 6377 | |||
| 6378 | sub createColourTags { | ||
| 6379 | |||
| 6380 | # Called by $self->objEnable | ||
| 6381 | # Defines the colour tags used by this Gtk3::TextView to change text and underlay colours | ||
| 6382 | # | ||
| 6383 | # Expected arguments | ||
| 6384 | # (none besides $self) | ||
| 6385 | # | ||
| 6386 | # Return values | ||
| 6387 | # 'undef' on improper arguments | ||
| 6388 | # 1 otherwise | ||
| 6389 | |||
| 6390 | my ($self, $check) = @_; | ||
| 6391 | |||
| 6392 | # Local variables | ||
| 6393 | my (%colourTagHash, %boldColourTagHash, %xTermColourTagHash); | ||
| 6394 | |||
| 6395 | # Check for improper arguments | ||
| 6396 | if (defined $check) { | ||
| 6397 | |||
| 6398 | return $axmud::CLIENT->writeImproper($self->_objClass . '->createColourTags', @_); | ||
| 6399 | } | ||
| 6400 | |||
| 6401 | # Import IVs (for convenience) | ||
| 6402 | %colourTagHash = $axmud::CLIENT->colourTagHash; | ||
| 6403 | %boldColourTagHash = $axmud::CLIENT->boldColourTagHash; | ||
| 6404 | %xTermColourTagHash = $axmud::CLIENT->xTermColourHash; | ||
| 6405 | |||
| 6406 | # Standard (normal) colour tags | ||
| 6407 | foreach my $tag (keys %colourTagHash) { | ||
| 6408 | |||
| 6409 | # Text colours have tags in the format 'green' for normal colours and 'GREEN' for bold | ||
| 6410 | # colours | ||
| 6411 | $self->buffer->create_tag( | ||
| 6412 | $tag, | ||
| 6413 | 'foreground' => $colourTagHash{$tag}, | ||
| 6414 | ); | ||
| 6415 | |||
| 6416 | # Underlay colours have tags in the format 'ul_green' for normal colours and 'UL_GREEN' | ||
| 6417 | # for bold colours | ||
| 6418 | $self->buffer->create_tag( | ||
| 6419 | 'ul_' . $tag, | ||
| 6420 | 'background' => $colourTagHash{$tag}, | ||
| 6421 | ); | ||
| 6422 | } | ||
| 6423 | |||
| 6424 | # Standard (bold) colour tags | ||
| 6425 | foreach my $tag (keys %boldColourTagHash) { | ||
| 6426 | |||
| 6427 | $self->buffer->create_tag( | ||
| 6428 | $tag, | ||
| 6429 | 'foreground' => $boldColourTagHash{$tag}, | ||
| 6430 | ); | ||
| 6431 | |||
| 6432 | $self->buffer->create_tag( | ||
| 6433 | 'UL_' . $tag, | ||
| 6434 | 'background' => $boldColourTagHash{$tag}, | ||
| 6435 | ); | ||
| 6436 | } | ||
| 6437 | |||
| 6438 | # XTerm colour tags | ||
| 6439 | foreach my $tag (keys %xTermColourTagHash) { | ||
| 6440 | |||
| 6441 | # Text colours, e.g. 'x255' | ||
| 6442 | $self->buffer->create_tag( | ||
| 6443 | $tag, | ||
| 6444 | 'foreground' => $xTermColourTagHash{$tag}, | ||
| 6445 | ); | ||
| 6446 | |||
| 6447 | # Underlay colours, e.g. 'ux255' | ||
| 6448 | $self->buffer->create_tag( | ||
| 6449 | 'u' . $tag, | ||
| 6450 | 'background' => $xTermColourTagHash{$tag}, | ||
| 6451 | ); | ||
| 6452 | } | ||
| 6453 | |||
| 6454 | # (NB RGB colour tags, e.g. '#ABCDEF', are created by $self->interpretTags when required) | ||
| 6455 | |||
| 6456 | return 1; | ||
| 6457 | } | ||
| 6458 | |||
| 6459 | sub updateStandardTag { | ||
| 6460 | |||
| 6461 | # Called by GA::Cmd::SetColour->do | ||
| 6462 | # Updates the Gtk3::TextTag for a specified Axmud standard text colour tag, when the colour | ||
| 6463 | # is modified | ||
| 6464 | # If the Gtk3::TextTag doesn't exist (for some reason), creates it | ||
| 6465 | # | ||
| 6466 | # Expected arguments | ||
| 6467 | # $tag - An Axmud standard text or underlay colour tag, e.g. 'red', 'BLUE', 'ul_red', | ||
| 6468 | # 'UL_BLUE') | ||
| 6469 | # | ||
| 6470 | # Return values | ||
| 6471 | # 'undef' on improper arguments or if $tag isn't an Axmud standard colour tag | ||
| 6472 | # 1 otherwise | ||
| 6473 | |||
| 6474 | my ($self, $tag, $check) = @_; | ||
| 6475 | |||
| 6476 | # Local variables | ||
| 6477 | my ($type, $underlayFlag, $boldType, $tagTable, $textTag, $rgb); | ||
| 6478 | |||
| 6479 | # Check for improper arguments | ||
| 6480 | if (! defined $tag || defined $check) { | ||
| 6481 | |||
| 6482 | return $axmud::CLIENT->writeImproper($self->_objClass . '->updateStandardTag', @_); | ||
| 6483 | } | ||
| 6484 | |||
| 6485 | # Check $tag is an Axmud standard colour tag | ||
| 6486 | ($type, $underlayFlag) = $axmud::CLIENT->checkColourTags($tag); | ||
| 6487 | $boldType = $axmud::CLIENT->checkBoldTags($tag); | ||
| 6488 | |||
| 6489 | if (! $type || $type ne 'standard') { | ||
| 6490 | |||
| 6491 | return undef; | ||
| 6492 | } | ||
| 6493 | |||
| 6494 | # Get Gtk3 objects | ||
| 6495 | $tagTable = $self->buffer->get_tag_table(); | ||
| 6496 | $textTag = $tagTable->lookup($tag); | ||
| 6497 | if (! $textTag) { | ||
| 6498 | |||
| 6499 | # Add a new Gtk3::TextTag | ||
| 6500 | if (! $boldType) { | ||
| 6501 | |||
| 6502 | if (! $underlayFlag) { | ||
| 6503 | |||
| 6504 | $self->buffer->create_tag( | ||
| 6505 | $tag, | ||
| 6506 | 'foreground' => $axmud::CLIENT->ivShow('colourTagHash', $tag), | ||
| 6507 | ); | ||
| 6508 | |||
| 6509 | } else { | ||
| 6510 | |||
| 6511 | $self->buffer->create_tag( | ||
| 6512 | $tag, | ||
| 6513 | 'background' => $axmud::CLIENT->returnRGBColour($tag), | ||
| 6514 | ); | ||
| 6515 | } | ||
| 6516 | |||
| 6517 | } else { | ||
| 6518 | |||
| 6519 | if ($boldType eq 'text') { | ||
| 6520 | |||
| 6521 | $self->buffer->create_tag( | ||
| 6522 | $tag, | ||
| 6523 | 'foreground' => $axmud::CLIENT->ivShow('boldColourTagHash', $tag), | ||
| 6524 | ); | ||
| 6525 | |||
| 6526 | } else { | ||
| 6527 | |||
| 6528 | $self->buffer->create_tag( | ||
| 6529 | $tag, | ||
| 6530 | 'background' => $axmud::CLIENT->returnRGBColour($tag), | ||
| 6531 | ); | ||
| 6532 | } | ||
| 6533 | } | ||
| 6534 | |||
| 6535 | } else { | ||
| 6536 | |||
| 6537 | # Modify an existing Gtk3::TextTag | ||
| 6538 | if (! $boldType) { | ||
| 6539 | |||
| 6540 | if (! $underlayFlag) { | ||
| 6541 | |||
| 6542 | $textTag->set_property( | ||
| 6543 | 'foreground' => $axmud::CLIENT->ivShow('colourTagHash', $tag), | ||
| 6544 | ); | ||
| 6545 | |||
| 6546 | } else { | ||
| 6547 | |||
| 6548 | $textTag->set_property( | ||
| 6549 | 'background' => $axmud::CLIENT->returnRGBColour($tag), | ||
| 6550 | ); | ||
| 6551 | } | ||
| 6552 | |||
| 6553 | } else { | ||
| 6554 | |||
| 6555 | if ($boldType eq 'text') { | ||
| 6556 | |||
| 6557 | $textTag->set_property( | ||
| 6558 | 'foreground' => $axmud::CLIENT->ivShow('boldColourTagHash', $tag), | ||
| 6559 | ); | ||
| 6560 | |||
| 6561 | } else { | ||
| 6562 | |||
| 6563 | $textTag->set_property( | ||
| 6564 | 'background' => $axmud::CLIENT->returnRGBColour($tag), | ||
| 6565 | ); | ||
| 6566 | } | ||
| 6567 | } | ||
| 6568 | } | ||
| 6569 | |||
| 6570 | return 1; | ||
| 6571 | } | ||
| 6572 | |||
| 6573 | sub updateXTermTags { | ||
| 6574 | |||
| 6575 | # Called by GA::Cmd::SetXTerm->do | ||
| 6576 | # Updates all Gtk3::TextTags for xterm colour tags, usually after the xterm colour cube is | ||
| 6577 | # switched | ||
| 6578 | # If the Gtk3::TextTag doesn't exist (for some reason), creates it | ||
| 6579 | # | ||
| 6580 | # Expected arguments | ||
| 6581 | # (none besides $self) | ||
| 6582 | # | ||
| 6583 | # Return values | ||
| 6584 | # 'undef' on improper arguments | ||
| 6585 | # 1 otherwise | ||
| 6586 | |||
| 6587 | my ($self, $check) = @_; | ||
| 6588 | |||
| 6589 | # Local variables | ||
| 6590 | my ( | ||
| 6591 | $tagTable, | ||
| 6592 | %tagHash, | ||
| 6593 | ); | ||
| 6594 | |||
| 6595 | # Check for improper arguments | ||
| 6596 | if (defined $check) { | ||
| 6597 | |||
| 6598 | return $axmud::CLIENT->writeImproper($self->_objClass . '->updateXTermTags', @_); | ||
| 6599 | } | ||
| 6600 | |||
| 6601 | # Import the IV | ||
| 6602 | %tagHash = $axmud::CLIENT->xTermColourHash; | ||
| 6603 | # Get Gtk3::TextTagTable | ||
| 6604 | $tagTable = $self->buffer->get_tag_table(); | ||
| 6605 | |||
| 6606 | # Update (or create) each xterm colour tag in turn | ||
| 6607 | foreach my $tag (keys %tagHash) { | ||
| 6608 | |||
| 6609 | my ($textTag, $underlayTag); | ||
| 6610 | |||
| 6611 | # Text colours, e.g. 'x255' | ||
| 6612 | $textTag = $tagTable->lookup($tag); | ||
| 6613 | if (! $textTag) { | ||
| 6614 | |||
| 6615 | $self->buffer->create_tag( | ||
| 6616 | $tag, | ||
| 6617 | 'foreground' => $tagHash{$tag}, | ||
| 6618 | ); | ||
| 6619 | |||
| 6620 | } else { | ||
| 6621 | |||
| 6622 | $textTag->set_property( | ||
| 6623 | 'foreground' => $tagHash{$tag}, | ||
| 6624 | ); | ||
| 6625 | } | ||
| 6626 | |||
| 6627 | # Underlay colours, e.g. 'ux255' | ||
| 6628 | $underlayTag = $tagTable->lookup('u' . $tag); | ||
| 6629 | if (! $underlayTag) { | ||
| 6630 | |||
| 6631 | $self->buffer->create_tag( | ||
| 6632 | 'u' . $tag, | ||
| 6633 | 'background' => $tagHash{$tag}, | ||
| 6634 | ); | ||
| 6635 | |||
| 6636 | } else { | ||
| 6637 | |||
| 6638 | $underlayTag->set_property( | ||
| 6639 | 'background' => $tagHash{$tag}, | ||
| 6640 | ); | ||
| 6641 | } | ||
| 6642 | } | ||
| 6643 | |||
| 6644 | return 1; | ||
| 6645 | } | ||
| 6646 | |||
| 6647 | sub updateRGBTags { | ||
| 6648 | |||
| 6649 | # Called by $self->objEnable and ->objUpdate (only) | ||
| 6650 | # When a colour scheme is applied to this textview, $self->textColour and/or | ||
| 6651 | # ->underlayColour might be set | ||
| 6652 | # Gtk3::TextTags are usually created only as needed by $self->interpretTags, but that | ||
| 6653 | # function won't have a chance to create Gtk3::TextTags if $self->textColour and/or | ||
| 6654 | # ->underlayColour are now set to RGB colour tags like '#ABCDEF and 'u#ABCDEF' | ||
| 6655 | # Check which (if any) Gtk3::TextTags must be created, and create them | ||
| 6656 | # | ||
| 6657 | # Expected arguments | ||
| 6658 | # (none besides $self) | ||
| 6659 | # | ||
| 6660 | # Return values | ||
| 6661 | # 'undef' on improper arguments | ||
| 6662 | # 1 otherwise | ||
| 6663 | |||
| 6664 | my ($self, $check) = @_; | ||
| 6665 | |||
| 6666 | # Local variables | ||
| 6667 | my ($textColour, $underlayColour, $type, $ulFlag); | ||
| 6668 | |||
| 6669 | # Check for improper arguments | ||
| 6670 | if (defined $check) { | ||
| 6671 | |||
| 6672 | return $axmud::CLIENT->writeImproper($self->_objClass . '->updateRGBTags', @_); | ||
| 6673 | } | ||
| 6674 | |||
| 6675 | if ($self->textColour) { | ||
| 6676 | |||
| 6677 | $textColour = $self->textColour; | ||
| 6678 | |||
| 6679 | ($type, $ulFlag) = $axmud::CLIENT->checkColourTags($textColour, 'rgb'); | ||
| 6680 | if (defined $type && ! $self->buffer->get_tag_table->lookup($textColour)) { | ||
| 6681 | |||
| 6682 | if (! $ulFlag) { | ||
| 6683 | |||
| 6684 | $self->buffer->create_tag( | ||
| 6685 | $textColour, # e.g. '#FFFFFF' | ||
| 6686 | 'foreground' => $textColour, # e.g. '#FFFFFF' | ||
| 6687 | ); | ||
| 6688 | |||
| 6689 | } else { | ||
| 6690 | |||
| 6691 | # This should never be executed, but it's better to be safe than sorry | ||
| 6692 | $self->buffer->create_tag( | ||
| 6693 | $textColour, # e.g. 'u#FFFFFF' | ||
| 6694 | 'background' => substr($textColour, 1), # e.g. '#FFFFFF' | ||
| 6695 | ); | ||
| 6696 | } | ||
| 6697 | } | ||
| 6698 | } | ||
| 6699 | |||
| 6700 | if ($self->underlayColour) { | ||
| 6701 | |||
| 6702 | $underlayColour = $self->underlayColour; | ||
| 6703 | |||
| 6704 | ($type, $ulFlag) = $axmud::CLIENT->checkColourTags($underlayColour, 'rgb'); | ||
| 6705 | if (defined $type && ! $self->buffer->get_tag_table->lookup($underlayColour)) { | ||
| 6706 | |||
| 6707 | if ($ulFlag) { | ||
| 6708 | |||
| 6709 | $self->buffer->create_tag( | ||
| 6710 | $underlayColour, # e.g. 'u#FFFFFF' | ||
| 6711 | 'background' => substr($underlayColour, 1), # e.g. '#FFFFFF' | ||
| 6712 | ); | ||
| 6713 | |||
| 6714 | } else { | ||
| 6715 | |||
| 6716 | # This should never be executed, but it's better to be safe than sorry | ||
| 6717 | $self->buffer->create_tag( | ||
| 6718 | $underlayColour, # e.g. '#FFFFFF' | ||
| 6719 | 'foreground' => $underlayColour, # e.g. '#FFFFFF' | ||
| 6720 | ); | ||
| 6721 | |||
| 6722 | } | ||
| 6723 | } | ||
| 6724 | } | ||
| 6725 | |||
| 6726 | return 1; | ||
| 6727 | } | ||
| 6728 | |||
| 6729 | sub updateLinkTag { | ||
| 6730 | |||
| 6731 | # Called by GA::Session->detectPueblo | ||
| 6732 | # When Pueblo is enabled, links are displayed in cyan and with no underline (normally, they | ||
| 6733 | # are displayed with no particular colour, but with an underline) | ||
| 6734 | # This function modifies the Gtk3::TextTag's properties to display links in the correct way | ||
| 6735 | # | ||
| 6736 | # Expected arguments | ||
| 6737 | # (none besides $self) | ||
| 6738 | # | ||
| 6739 | # Return values | ||
| 6740 | # 'undef' on improper arguments or if the 'link' tag is not updated | ||
| 6741 | # 1 if the 'link' tag is updated | ||
| 6742 | |||
| 6743 | my ($self, $check) = @_; | ||
| 6744 | |||
| 6745 | # Local variables | ||
| 6746 | my $linkTag; | ||
| 6747 | |||
| 6748 | if (! $self->buffer || $self->session->puebloMode ne 'client_agree') { | ||
| 6749 | |||
| 6750 | return undef; | ||
| 6751 | } | ||
| 6752 | |||
| 6753 | $linkTag = $self->buffer->get_tag_table->lookup('link'); | ||
| 6754 | if (! $linkTag) { | ||
| 6755 | |||
| 6756 | return undef; | ||
| 6757 | } | ||
| 6758 | |||
| 6759 | $linkTag->set_property( | ||
| 6760 | 'foreground', | ||
| 6761 | $axmud::CLIENT->returnRGBColour($axmud::CLIENT->constPuebloLinkColour), | ||
| 6762 | ); | ||
| 6763 | $linkTag->set_property('foreground-set', TRUE); | ||
| 6764 | $linkTag->set_property('underline', 'none'); | ||
| 6765 | |||
| 6766 | return 1; | ||
| 6767 | } | ||
| 6768 | |||
| 6769 | sub createStyleTags { | ||
| 6770 | |||
| 6771 | # Called by $self->objEnable | ||
| 6772 | # Defines the style tags used by this Gtk3::TextView to change the text style | ||
| 6773 | # | ||
| 6774 | # Expected arguments | ||
| 6775 | # (none besides $self) | ||
| 6776 | # | ||
| 6777 | # Return values | ||
| 6778 | # 'undef' on improper arguments | ||
| 6779 | # 1 otherwise | ||
| 6780 | |||
| 6781 | my ($self, $check) = @_; | ||
| 6782 | |||
| 6783 | # Local variables | ||
| 6784 | my $background; | ||
| 6785 | |||
| 6786 | # Check for improper arguments | ||
| 6787 | if (defined $check) { | ||
| 6788 | |||
| 6789 | return $axmud::CLIENT->writeImproper($self->_objClass . '->createStyleTags', @_); | ||
| 6790 | } | ||
| 6791 | |||
| 6792 | # Italics | ||
| 6793 | $self->buffer->create_tag( | ||
| 6794 | 'italics', | ||
| 6795 | 'style' => 'italic', | ||
| 6796 | ); | ||
| 6797 | |||
| 6798 | # Underline | ||
| 6799 | $self->buffer->create_tag( | ||
| 6800 | 'underline', | ||
| 6801 | 'underline' => 'single', | ||
| 6802 | ); | ||
| 6803 | |||
| 6804 | # Blink: because the 'blink_slow' tag is sent to Gtk3 after the text and/or underlay tags, | ||
| 6805 | # it overrules them when 'foreground-set' and 'background-set' are TRUE, but doesn't | ||
| 6806 | # overrule them when 'foreground-set' and 'background-set' are FALSE. We can make the text | ||
| 6807 | # blink by alternating the values between TRUE and FALSE. | ||
| 6808 | # NB Gtk3 doesn't understand Axmud colour tags like 'ul_green', so we must convert them to | ||
| 6809 | # RGB | ||
| 6810 | $background = $axmud::CLIENT->returnRGBColour($self->backgroundColour); | ||
| 6811 | |||
| 6812 | # Blink slow | ||
| 6813 | $self->buffer->create_tag( | ||
| 6814 | 'blink_slow', | ||
| 6815 | 'foreground' => $background, | ||
| 6816 | 'foreground-set' => TRUE, # Text initially invisible | ||
| 6817 | 'background' => $background, | ||
| 6818 | 'background-set' => TRUE, # Underlay initially invisible | ||
| 6819 | ); | ||
| 6820 | |||
| 6821 | # Blink fast | ||
| 6822 | $self->buffer->create_tag( | ||
| 6823 | 'blink_fast', | ||
| 6824 | 'foreground' => $background, | ||
| 6825 | 'foreground-set' => TRUE, | ||
| 6826 | 'background' => $background, | ||
| 6827 | 'background-set' => TRUE, | ||
| 6828 | ); | ||
| 6829 | |||
| 6830 | # Strikethrough | ||
| 6831 | $self->buffer->create_tag( | ||
| 6832 | 'strike', | ||
| 6833 | 'strikethrough' => 1, | ||
| 6834 | ); | ||
| 6835 | |||
| 6836 | # Clickable links | ||
| 6837 | if ($self->session->puebloMode eq 'client_agree') { | ||
| 6838 | |||
| 6839 | # In Pueblo mode, clickable links are cyan, and not underlined | ||
| 6840 | $self->buffer->create_tag( | ||
| 6841 | 'link', | ||
| 6842 | 'foreground' => $axmud::CLIENT->returnRGBColour( | ||
| 6843 | $axmud::CLIENT->constPuebloLinkColour, | ||
| 6844 | ), | ||
| 6845 | 'foreground-set' => TRUE, | ||
| 6846 | ); | ||
| 6847 | |||
| 6848 | } else { | ||
| 6849 | |||
| 6850 | # At all other times, clickable links are just underlined | ||
| 6851 | $self->buffer->create_tag( | ||
| 6852 | 'link', | ||
| 6853 | 'underline' => 'single', | ||
| 6854 | ); | ||
| 6855 | } | ||
| 6856 | |||
| 6857 | # Justification | ||
| 6858 | $self->buffer->create_tag( | ||
| 6859 | 'justify_left', | ||
| 6860 | 'justification' => 'left', | ||
| 6861 | ); | ||
| 6862 | |||
| 6863 | $self->buffer->create_tag( | ||
| 6864 | 'justify_centre', | ||
| 6865 | 'justification' => 'center', | ||
| 6866 | ); | ||
| 6867 | |||
| 6868 | $self->buffer->create_tag( | ||
| 6869 | 'justify_right', | ||
| 6870 | 'justification' => 'right', | ||
| 6871 | ); | ||
| 6872 | |||
| 6873 | $self->buffer->create_tag( | ||
| 6874 | 'justify_default', | ||
| 6875 | 'justification' => 'left', | ||
| 6876 | ); | ||
| 6877 | |||
| 6878 | # A special tag, not related to any Axmud colour/style tag, which handles a visible cursor | ||
| 6879 | # in the textview. Only one position in $self->buffer (if any) uses this tag at a time | ||
| 6880 | # It's added to the buffer after any text insertion operation, so it should overrule any | ||
| 6881 | # 'underline' tag that already exists at that position | ||
| 6882 | $self->buffer->create_tag( | ||
| 6883 | 'cursor', | ||
| 6884 | 'underline' => 'single', | ||
| 6885 | ); | ||
| 6886 | |||
| 6887 | return 1; | ||
| 6888 | } | ||
| 6889 | |||
| 6890 | sub setMonochromeMode { | ||
| 6891 | |||
| 6892 | # Called by GA::Table::Pane->applyMonochrome (must not be called directly) | ||
| 6893 | # Applies a monochrome colour scheme to the textview(s), using the specified background | ||
| 6894 | # colour, and choosing for itself a suitable text colour (if no text colour is | ||
| 6895 | # also specified) | ||
| 6896 | # Sets $self->monochromeFlag to TRUE, if it's not already set | ||
| 6897 | # | ||
| 6898 | # Expected arguments | ||
| 6899 | # (none besides $self) | ||
| 6900 | # | ||
| 6901 | # Optional arguments | ||
| 6902 | # $backgroundColour | ||
| 6903 | # - The background colour to use (can be any Axmud colour tag, e.g 'red'). If it's | ||
| 6904 | # an underlay tag like 'ul_red', the equivalent colour tag is used instead. If | ||
| 6905 | # 'undef', the background colour specified by $self->colourScheme is used | ||
| 6906 | # $textColour | ||
| 6907 | # - The text colour to use. Is normally 'undef', in which case this function will | ||
| 6908 | # choose a suitable text colour to match the background. Should be specified | ||
| 6909 | # if $backgroundColour is an Xterm or RGB colour tag, otherwise the text | ||
| 6910 | # colour might not suit the background colour | ||
| 6911 | # | ||
| 6912 | # Return values | ||
| 6913 | # 'undef' on improper arguments or if a specified $backgroundColour is not a recognised | ||
| 6914 | # Axmud colour tag | ||
| 6915 | # 1 otherwise | ||
| 6916 | |||
| 6917 | my ($self, $backgroundColour, $textColour, $check) = @_; | ||
| 6918 | |||
| 6919 | # Local variables | ||
| 6920 | my ($colourSchemeObj, $defaultFlag, $type, $underlayFlag); | ||
| 6921 | |||
| 6922 | # Check for improper arguments | ||
| 6923 | if (defined $check) { | ||
| 6924 | |||
| 6925 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setMonochromeMode', @_); | ||
| 6926 | } | ||
| 6927 | |||
| 6928 | $colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme); | ||
| 6929 | |||
| 6930 | # If no $backgroundColour was specified, use the background colour from $self->colourScheme | ||
| 6931 | if (! defined $backgroundColour) { | ||
| 6932 | |||
| 6933 | if ($colourSchemeObj) { | ||
| 6934 | |||
| 6935 | $backgroundColour = $colourSchemeObj->backgroundColour; | ||
| 6936 | $defaultFlag = TRUE; | ||
| 6937 | |||
| 6938 | } else { | ||
| 6939 | |||
| 6940 | # Emergency fallback colour | ||
| 6941 | $backgroundColour = 'black'; | ||
| 6942 | } | ||
| 6943 | |||
| 6944 | } else { | ||
| 6945 | |||
| 6946 | # Convert an underlay tag into a normal tag | ||
| 6947 | ($type, $underlayFlag) = $axmud::CLIENT->checkColourTags($backgroundColour); | ||
| 6948 | if ($type && $underlayFlag) { | ||
| 6949 | |||
| 6950 | $backgroundColour = $axmud::CLIENT->swapColours($backgroundColour); | ||
| 6951 | } | ||
| 6952 | } | ||
| 6953 | |||
| 6954 | # If no text colour was specified, choose one to match the background colour | ||
| 6955 | if (! $textColour) { | ||
| 6956 | |||
| 6957 | if ($axmud::CLIENT->ivExists('constMonochromeHash', $backgroundColour)) { | ||
| 6958 | |||
| 6959 | $textColour = $axmud::CLIENT->ivShow('constMonochromeHash', $backgroundColour); | ||
| 6960 | |||
| 6961 | } elsif (! $defaultFlag) { | ||
| 6962 | |||
| 6963 | # Non-standard background colour tag. Use a fallback text colour; if it doesn't | ||
| 6964 | # match the background colour well, that's the fault of the calling function for | ||
| 6965 | # not specifying $textColour | ||
| 6966 | if (uc($backgroundColour) eq '#FFFFFF' || lc($backgroundColour) eq 'x255') { | ||
| 6967 | $textColour = 'black'; | ||
| 6968 | } else { | ||
| 6969 | $textColour = 'WHITE'; | ||
| 6970 | } | ||
| 6971 | |||
| 6972 | } elsif ($colourSchemeObj) { | ||
| 6973 | |||
| 6974 | # Non-standard background colour tag supplied by the colour scheme, so use the text | ||
| 6975 | # colour supplied by the colour scheme | ||
| 6976 | $textColour = $colourSchemeObj->textColour; | ||
| 6977 | |||
| 6978 | } else { | ||
| 6979 | |||
| 6980 | # Emergency fallback colour | ||
| 6981 | $backgroundColour = 'white'; | ||
| 6982 | } | ||
| 6983 | } | ||
| 6984 | |||
| 6985 | # Update IVs. Underlay colours are not used in monochrome mode, so that IV is set to 'undef' | ||
| 6986 | $self->ivPoke('textColour', $textColour); | ||
| 6987 | $self->ivUndef('underlayColour'); | ||
| 6988 | $self->ivPoke('backgroundColour', $backgroundColour); | ||
| 6989 | $self->ivPoke('monochromeFlag', TRUE); | ||
| 6990 | |||
| 6991 | if (! $colourSchemeObj || $colourSchemeObj->backgroundColour eq $backgroundColour) { | ||
| 6992 | $self->ivPoke('monochromeModFlag', FALSE); | ||
| 6993 | } else { | ||
| 6994 | $self->ivPoke('monochromeModFlag', TRUE); | ||
| 6995 | } | ||
| 6996 | |||
| 6997 | # Apply the monochrome colour scheme | ||
| 6998 | return $self->objUpdate(); | ||
| 6999 | } | ||
| 7000 | |||
| 7001 | sub resetMonochromeMode { | ||
| 7002 | |||
| 7003 | # Called by GA::Table::Pane->removeMonochrome (must not be called directly) | ||
| 7004 | # Removes the monochrome colour scheme currently being used, and restores the colour scheme | ||
| 7005 | # specified by $self->colourScheme | ||
| 7006 | # Sets $self->monochromeFlag to FALSE, if it's not already set | ||
| 7007 | # | ||
| 7008 | # Expected arguments | ||
| 7009 | # (none besides $self) | ||
| 7010 | # | ||
| 7011 | # Return values | ||
| 7012 | # 'undef' on improper arguments or if a monochrome colour scheme isn't in use currently | ||
| 7013 | # 1 otherwise | ||
| 7014 | |||
| 7015 | my ($self, $check) = @_; | ||
| 7016 | |||
| 7017 | # Check for improper arguments | ||
| 7018 | if (defined $check) { | ||
| 7019 | |||
| 7020 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetMonochromeMode', @_); | ||
| 7021 | } | ||
| 7022 | |||
| 7023 | if (! $self->monochromeFlag) { | ||
| 7024 | |||
| 7025 | return undef; | ||
| 7026 | |||
| 7027 | } else { | ||
| 7028 | |||
| 7029 | $self->ivPoke('monochromeFlag', FALSE); | ||
| 7030 | $self->ivPoke('monochromeModFlag', FALSE); | ||
| 7031 | |||
| 7032 | return $self->objUpdate($self->colourScheme); | ||
| 7033 | } | ||
| 7034 | } | ||
| 7035 | |||
| 7036 | sub applyColourStyleTags { | ||
| 7037 | |||
| 7038 | # Called by GA::Session->processLineSegment and ->applyTriggerStyle | ||
| 7039 | # Also called by GA::Buffer::Display->copyLine | ||
| 7040 | # | ||
| 7041 | # GA::CLIENT->constColourStyleHash specifies a standard format for describing the Axmud | ||
| 7042 | # colour/style tags that apply at some offset in some text | ||
| 7043 | # This function takes a hash in that format, describing the tags that apply to an | ||
| 7044 | # unspecified offset in this textview (which might have been displayed already, or not) | ||
| 7045 | # The hash is then updated using a list of Axmud colour/style tags, so that hash describes | ||
| 7046 | # the tags that apply to a later offset in this textview (that hasn't been displayed yet) | ||
| 7047 | # | ||
| 7048 | # Expected arguments | ||
| 7049 | # $session - The calling GA::Session | ||
| 7050 | # $listRef - A reference to a list of Axmud colour/style tags which are used to modify | ||
| 7051 | # the hash (can be an empty list) | ||
| 7052 | # | ||
| 7053 | # Optional arguments | ||
| 7054 | # %tagHash - A hash in the format specified by GA::CLIENT->constColourStyleHash, i.e. | ||
| 7055 | # | ||
| 7056 | # 'text' => 'undef' or an Axmud text colour tag, e.g. 'red' or | ||
| 7057 | # 'x230' | ||
| 7058 | # 'underlay' => 'undef' or an Axmud underlay colour tag, e.g. 'ul_white' | ||
| 7059 | # 'italics' => TRUE or FALSE | ||
| 7060 | # 'underline' => TRUE or FALSE | ||
| 7061 | # 'blink_slow' => TRUE or FALSE | ||
| 7062 | # 'blink_fast' => TRUE or FALSE | ||
| 7063 | # 'strike' => TRUE or FALSE | ||
| 7064 | # 'link' => TRUE or FALSE | ||
| 7065 | # 'mxp_font' => TRUE or FALSE | ||
| 7066 | # 'justify' => 'left', 'right', 'centre', or 'undef' to represent the | ||
| 7067 | # style tag 'justify_default' | ||
| 7068 | # | ||
| 7069 | # Return values | ||
| 7070 | # An empty list on improper arguments | ||
| 7071 | # Otherwise, returns the modified hash | ||
| 7072 | |||
| 7073 | my ($self, $session, $listRef, %tagHash) = @_; | ||
| 7074 | |||
| 7075 | # Local variables | ||
| 7076 | my ( | ||
| 7077 | $attribsOffFlag, | ||
| 7078 | %styleHash, %justifyHash, %dummyHash, | ||
| 7079 | ); | ||
| 7080 | |||
| 7081 | # Check for improper arguments | ||
| 7082 | if (! defined $session || ! defined $listRef) { | ||
| 7083 | |||
| 7084 | return $axmud::CLIENT->writeImproper($self->_objClass . '->applyColourStyleTags', @_); | ||
| 7085 | } | ||
| 7086 | |||
| 7087 | # Import IVs (for quick lookup) | ||
| 7088 | %styleHash = $axmud::CLIENT->constStyleTagHash; | ||
| 7089 | %justifyHash = $axmud::CLIENT->constJustifyTagHash; | ||
| 7090 | %dummyHash = $axmud::CLIENT->constDummyTagHash; | ||
| 7091 | |||
| 7092 | foreach my $tag (@$listRef) { | ||
| 7093 | |||
| 7094 | my ($type, $underlayFlag, $boldishTag); | ||
| 7095 | |||
| 7096 | # When called by GA::Session->applyTriggerStyle, @tagList can contain bold text colour | ||
| 7097 | # tags like 'BLUE'. When called by GA::Session->processLineSegment, @tagList would | ||
| 7098 | # instead contain the pair 'bold', 'blue' | ||
| 7099 | # @tagList might also contain bold underlay colours like 'UL_BLUE', but that doesn't | ||
| 7100 | # affect the setting of $tagHash{'bold'} (which only applies to text colours) | ||
| 7101 | $type = $axmud::CLIENT->checkBoldTags($tag); | ||
| 7102 | if ($type && $type eq 'text') { | ||
| 7103 | |||
| 7104 | # $tag is a bold colour tag. Pretend that we processed a 'bold' dummy tag during | ||
| 7105 | # the last iteration of this loop | ||
| 7106 | $tagHash{'bold'} = TRUE; | ||
| 7107 | # Since we're about to change the text colour, we can rely on the following code to | ||
| 7108 | # take care of $tagHash{'text'}, $tagHash{'real_text'} and so on | ||
| 7109 | $tag = lc($tag); | ||
| 7110 | } | ||
| 7111 | |||
| 7112 | # PART 1: 'Dummy' style tags | ||
| 7113 | if (exists $dummyHash{$tag}) { | ||
| 7114 | |||
| 7115 | if ($tag eq 'attribs_off') { | ||
| 7116 | |||
| 7117 | # A dummy tag created by GA::Session->processEscSequence, which corresponds to | ||
| 7118 | # 'all attributes off'. We implement this by resetting %tagHash | ||
| 7119 | %tagHash = $axmud::CLIENT->constColourStyleHash; | ||
| 7120 | $attribsOffFlag = TRUE; | ||
| 7121 | |||
| 7122 | } elsif ($tag eq 'bold') { | ||
| 7123 | |||
| 7124 | # A 'dummy' style tag | ||
| 7125 | if (! $tagHash{'bold'}) { | ||
| 7126 | |||
| 7127 | $tagHash{'bold'} = TRUE; | ||
| 7128 | |||
| 7129 | # (If %tagHash currently contains no text colour, we have to add one, so | ||
| 7130 | # that the bold text is visible) | ||
| 7131 | if (! $tagHash{'real_text'}) { | ||
| 7132 | $tagHash{'real_text'} = uc($self->textColour); | ||
| 7133 | } else { | ||
| 7134 | $tagHash{'real_text'} = uc($tagHash{'real_text'}); | ||
| 7135 | } | ||
| 7136 | |||
| 7137 | # In conceal mode we don't make any changes to $tagHash{'text'} and | ||
| 7138 | # $tagHash{'underlay'} | ||
| 7139 | if ($tagHash{'reverse'}) { | ||
| 7140 | |||
| 7141 | $tagHash{'underlay'} | ||
| 7142 | = $axmud::CLIENT->swapColours($tagHash{'real_text'}); | ||
| 7143 | |||
| 7144 | } elsif (! $tagHash{'conceal'}) { | ||
| 7145 | |||
| 7146 | $tagHash{'text'} = $tagHash{'real_text'}; | ||
| 7147 | } | ||
| 7148 | |||
| 7149 | # In conceal mode and reverse video mode, changing the underlay colour has | ||
| 7150 | # no effect | ||
| 7151 | if (! $tagHash{'conceal'} && ! $tagHash{'reverse'}) { | ||
| 7152 | |||
| 7153 | $tagHash{'underlay'} = $tagHash{'real_underlay'}; | ||
| 7154 | } | ||
| 7155 | } | ||
| 7156 | |||
| 7157 | # (A second 'bold' tag is ignored) | ||
| 7158 | |||
| 7159 | } elsif ($tag eq 'bold_off') { | ||
| 7160 | |||
| 7161 | # A 'dummy' style tag | ||
| 7162 | if ($tagHash{'bold'}) { | ||
| 7163 | |||
| 7164 | $tagHash{'bold'} = FALSE; | ||
| 7165 | |||
| 7166 | if ($tagHash{'real_text'}) { | ||
| 7167 | |||
| 7168 | $tagHash{'real_text'} = lc($tagHash{'real_text'}); | ||
| 7169 | } | ||
| 7170 | |||
| 7171 | if ($tagHash{'reverse'}) { | ||
| 7172 | |||
| 7173 | $tagHash{'underlay'} | ||
| 7174 | = $axmud::CLIENT->swapColours($tagHash{'real_text'}); | ||
| 7175 | |||
| 7176 | } elsif (! $tagHash{'conceal'}) { | ||
| 7177 | |||
| 7178 | $tagHash{'text'} = $tagHash{'real_text'}; | ||
| 7179 | } | ||
| 7180 | |||
| 7181 | # In conceal mode and reverse video mode, changing the underlay colour has | ||
| 7182 | # no effect | ||
| 7183 | if (! $tagHash{'conceal'} && ! $tagHash{'reverse'}) { | ||
| 7184 | |||
| 7185 | $tagHash{'underlay'} = $tagHash{'real_underlay'}; | ||
| 7186 | } | ||
| 7187 | } | ||
| 7188 | |||
| 7189 | # (A second consecutive 'bold_off' tag is ignored) | ||
| 7190 | |||
| 7191 | } elsif ($tag eq 'reverse') { | ||
| 7192 | |||
| 7193 | # A 'dummy' style tag | ||
| 7194 | if (! $tagHash{'reverse'}) { | ||
| 7195 | |||
| 7196 | $tagHash{'reverse'} = TRUE; | ||
| 7197 | |||
| 7198 | # In reverse video mode, the existing text colour is used as the underlay | ||
| 7199 | # colour. The existing underlay colour is ignored, if it is set, because | ||
| 7200 | # reverse video was designed for monochrome monitors | ||
| 7201 | # In addition, the textview background colour is used as the new text colour | ||
| 7202 | |||
| 7203 | # Conceal mode takes priority over reverse video mode, if that is already on | ||
| 7204 | if (! $tagHash{'conceal'}) { | ||
| 7205 | |||
| 7206 | $tagHash{'text'} = $self->backgroundColour; | ||
| 7207 | if ($tagHash{'real_text'}) { | ||
| 7208 | |||
| 7209 | $tagHash{'underlay'} | ||
| 7210 | = $axmud::CLIENT->swapColours($tagHash{'real_text'}); | ||
| 7211 | |||
| 7212 | } else { | ||
| 7213 | |||
| 7214 | $tagHash{'underlay'} | ||
| 7215 | = $axmud::CLIENT->swapColours($self->textColour); | ||
| 7216 | } | ||
| 7217 | } | ||
| 7218 | } | ||
| 7219 | |||
| 7220 | # (A second 'reverse' tag is ignored) | ||
| 7221 | |||
| 7222 | } elsif ($tag eq 'reverse_off') { | ||
| 7223 | |||
| 7224 | # A 'dummy' style tag | ||
| 7225 | if ($tagHash{'reverse'}) { | ||
| 7226 | |||
| 7227 | $tagHash{'reverse'} = FALSE; | ||
| 7228 | if (! $tagHash{'conceal'}) { | ||
| 7229 | |||
| 7230 | $tagHash{'text'} = $tagHash{'real_text'}; | ||
| 7231 | $tagHash{'underlay'} = $tagHash{'real_underlay'}; | ||
| 7232 | } | ||
| 7233 | } | ||
| 7234 | |||
| 7235 | # (A second consecutive 'reverse_off' tag is ignored) | ||
| 7236 | |||
| 7237 | } elsif ($tag eq 'conceal') { | ||
| 7238 | |||
| 7239 | # A 'dummy' style tag | ||
| 7240 | if (! $tagHash{'conceal'}) { | ||
| 7241 | |||
| 7242 | $tagHash{'conceal'} = TRUE; | ||
| 7243 | |||
| 7244 | # In conceal mode, both the text and underlay colours are set to the same as | ||
| 7245 | # the textview background colour, so that the text is invisible unless the | ||
| 7246 | # user selects it with the mouse | ||
| 7247 | # Conceal mode takes priority over reverse video mode, if that is already on | ||
| 7248 | $tagHash{'text'} = $self->backgroundColour; | ||
| 7249 | $tagHash{'underlay'} | ||
| 7250 | = $axmud::CLIENT->swapColours($self->backgroundColour); | ||
| 7251 | } | ||
| 7252 | |||
| 7253 | # (A second 'conceal' tag is ignored) | ||
| 7254 | |||
| 7255 | } elsif ($tag eq 'conceal_off') { | ||
| 7256 | |||
| 7257 | # A 'dummy' style tag | ||
| 7258 | if ($tagHash{'conceal'}) { | ||
| 7259 | |||
| 7260 | $tagHash{'conceal'} = FALSE; | ||
| 7261 | if ($tagHash{'reverse'}) { | ||
| 7262 | |||
| 7263 | $tagHash{'text'} = $self->backgroundColour; | ||
| 7264 | $tagHash{'underlay'} | ||
| 7265 | = $axmud::CLIENT->swapColours($tagHash{'real_text'}); | ||
| 7266 | |||
| 7267 | } else { | ||
| 7268 | |||
| 7269 | $tagHash{'text'} = $tagHash{'real_text'}; | ||
| 7270 | $tagHash{'underlay'} = $tagHash{'real_underlay'}; | ||
| 7271 | } | ||
| 7272 | } | ||
| 7273 | |||
| 7274 | # (A second consecutive 'conceal_off' tag is ignored) | ||
| 7275 | |||
| 7276 | } elsif ($tag eq 'mxpf_off') { | ||
| 7277 | |||
| 7278 | # (Other 'mxpf_...' tags are handled below) | ||
| 7279 | $tagHash{'mxp_font'} = undef; | ||
| 7280 | } | ||
| 7281 | |||
| 7282 | # PART 2: Justification style tags | ||
| 7283 | } elsif (exists $justifyHash{$tag}) { | ||
| 7284 | |||
| 7285 | if ($tag eq 'justify_default') { | ||
| 7286 | $tagHash{'justify'} = undef; | ||
| 7287 | } else { | ||
| 7288 | $tagHash{'justify'} = substr($tag, 8); | ||
| 7289 | } | ||
| 7290 | |||
| 7291 | # PART 3: Style tags | ||
| 7292 | } elsif (exists $styleHash{$tag}) { | ||
| 7293 | |||
| 7294 | # (Codes listed in rough order of popularity) | ||
| 7295 | if ($tag eq 'link') { | ||
| 7296 | |||
| 7297 | if ($tagHash{'link'}) { | ||
| 7298 | $tagHash{'link'} = FALSE; | ||
| 7299 | } else { | ||
| 7300 | $tagHash{'link'} = TRUE; | ||
| 7301 | } | ||
| 7302 | |||
| 7303 | } elsif ($tag eq 'link_off') { | ||
| 7304 | |||
| 7305 | $tagHash{'link'} = FALSE; | ||
| 7306 | |||
| 7307 | } elsif ( | ||
| 7308 | $tag eq 'italics' | ||
| 7309 | || $tag eq 'underline' | ||
| 7310 | || $tag eq 'blink_slow' | ||
| 7311 | || $tag eq 'blink_fast' | ||
| 7312 | || $tag eq 'strike' | ||
| 7313 | ) { | ||
| 7314 | # (A second consecutive tag reinforces the previous one) | ||
| 7315 | $tagHash{$tag} = TRUE; | ||
| 7316 | |||
| 7317 | } elsif ($tag eq 'italics_off') { | ||
| 7318 | |||
| 7319 | $tagHash{'italics'} = FALSE; | ||
| 7320 | |||
| 7321 | } elsif ($tag eq 'underline_off') { | ||
| 7322 | |||
| 7323 | $tagHash{'underline'} = FALSE; | ||
| 7324 | |||
| 7325 | } elsif ($tag eq 'blink_off') { | ||
| 7326 | |||
| 7327 | $tagHash{'blink_slow'} = FALSE; | ||
| 7328 | $tagHash{'blink_fast'} = FALSE; | ||
| 7329 | |||
| 7330 | } elsif ($tag eq 'strike_off') { | ||
| 7331 | |||
| 7332 | $tagHash{'strike'} = FALSE; | ||
| 7333 | } | ||
| 7334 | |||
| 7335 | # PART 4: MXP style tags | ||
| 7336 | } elsif (substr($tag, 0, 5) eq 'mxpf_') { | ||
| 7337 | |||
| 7338 | # Dummy style tags used for MXP fonts | ||
| 7339 | # Store the whole dummy tag, e.g. 'mxpf_monospace_bold_12' (NB 'mxpf_off' was | ||
| 7340 | # handled further above) | ||
| 7341 | $tagHash{'mxp_font'} = $tag; | ||
| 7342 | |||
| 7343 | } elsif (substr($tag, 0, 5) eq 'mxpm_') { | ||
| 7344 | |||
| 7345 | # Dummy style tag used for MXP modes in the range 10-12, 19, 20-99 (which don't | ||
| 7346 | # affect text attributes, so we don't add them to %tagHash) | ||
| 7347 | # ... | ||
| 7348 | |||
| 7349 | # PART 5: Colour tags | ||
| 7350 | } else { | ||
| 7351 | |||
| 7352 | ($type, $underlayFlag) = $axmud::CLIENT->checkColourTags($tag); | ||
| 7353 | if ($type) { | ||
| 7354 | |||
| 7355 | if ($type eq 'standard') { | ||
| 7356 | |||
| 7357 | # We're going to check $tag against the textview's object colour in a | ||
| 7358 | # moment, which is stored as (for example) 'RED' if it's a bold colour. We | ||
| 7359 | # need to compare it with 'RED', not 'red', if bold is on | ||
| 7360 | if ($tagHash{'bold'}) { | ||
| 7361 | $boldishTag = uc($tag); | ||
| 7362 | } else { | ||
| 7363 | $boldishTag = $tag; | ||
| 7364 | } | ||
| 7365 | |||
| 7366 | } else { | ||
| 7367 | |||
| 7368 | # xterm/RGB colour tags should be case insensitive | ||
| 7369 | $boldishTag = lc($tag); | ||
| 7370 | } | ||
| 7371 | } | ||
| 7372 | |||
| 7373 | # PART 5a: Text colour tags | ||
| 7374 | if ($type && ! $underlayFlag) { | ||
| 7375 | |||
| 7376 | if ( | ||
| 7377 | defined $tagHash{'real_text'} | ||
| 7378 | && $tagHash{'real_text'} eq $tag | ||
| 7379 | ) { | ||
| 7380 | # (The re-occuring tag is ignored) | ||
| 7381 | |||
| 7382 | } elsif ($attribsOffFlag && $boldishTag eq $self->textColour) { | ||
| 7383 | |||
| 7384 | # After an 'attribs off', if the tag matches the 'main' window's normal text | ||
| 7385 | # colour, let that be the text colour | ||
| 7386 | # (This takes care of ANSI escape sequences like '^[0;37;40m', meaning | ||
| 7387 | # 'attribs off - white text - black underlay'. If we set | ||
| 7388 | # $tagHash{'underlay'} to 'ul_black', the next 'bold' tag - which was | ||
| 7389 | # intended to apply only to the text colour - will be applied to the | ||
| 7390 | # underlay colour, too.) | ||
| 7391 | $tagHash{'real_text'} = undef; | ||
| 7392 | if ($tagHash{'reverse'}) { | ||
| 7393 | |||
| 7394 | $tagHash{'text'} = $self->backgroundColour; | ||
| 7395 | $tagHash{'underlay'} | ||
| 7396 | = $axmud::CLIENT->swapColours($self->textColour); | ||
| 7397 | |||
| 7398 | } else { | ||
| 7399 | |||
| 7400 | $tagHash{'text'} = $tagHash{'real_text'}; | ||
| 7401 | } | ||
| 7402 | |||
| 7403 | } elsif ($tagHash{'bold'} && $type eq 'standard') { | ||
| 7404 | |||
| 7405 | # Bold text colour | ||
| 7406 | $tagHash{'real_text'} = uc($tag); | ||
| 7407 | # If the world is using an OSC colour palette to modify this colour, use the | ||
| 7408 | # modified form | ||
| 7409 | if ($session->ivExists('oscColourHash', $tagHash{'real_text'})) { | ||
| 7410 | |||
| 7411 | $tagHash{'real_text'} | ||
| 7412 | = $session->ivShow('oscColourHash', $tagHash{'real_text'}); | ||
| 7413 | } | ||
| 7414 | |||
| 7415 | # In conceal mode we don't make any changes to $tagHash{'text'} and | ||
| 7416 | # $tagHash{'underlay'} | ||
| 7417 | if ($tagHash{'reverse'}) { | ||
| 7418 | |||
| 7419 | $tagHash{'underlay'} | ||
| 7420 | = $axmud::CLIENT->swapColours($tagHash{'real_text'}); | ||
| 7421 | |||
| 7422 | } elsif (! $tagHash{'conceal'}) { | ||
| 7423 | |||
| 7424 | $tagHash{'text'} = $tagHash{'real_text'}; | ||
| 7425 | } | ||
| 7426 | |||
| 7427 | } else { | ||
| 7428 | |||
| 7429 | # Normal colour, or a bold underlay colour like 'UL_BLUE', specified | ||
| 7430 | # directly by a call from GA::Session->applyTriggerStyle | ||
| 7431 | $tagHash{'real_text'} = $tag; | ||
| 7432 | # If the world is using an OSC colour palette to modify this colour, use the | ||
| 7433 | # modified form | ||
| 7434 | if ($session->ivExists('oscColourHash', $tagHash{'real_text'})) { | ||
| 7435 | |||
| 7436 | $tagHash{'real_text'} | ||
| 7437 | = $session->ivShow('oscColourHash', $tagHash{'real_text'}); | ||
| 7438 | } | ||
| 7439 | |||
| 7440 | if ($tagHash{'reverse'}) { | ||
| 7441 | |||
| 7442 | $tagHash{'underlay'} | ||
| 7443 | = $axmud::CLIENT->swapColours($tagHash{'real_text'}); | ||
| 7444 | |||
| 7445 | } elsif (! $tagHash{'conceal'}) { | ||
| 7446 | |||
| 7447 | $tagHash{'text'} = $tagHash{'real_text'}; | ||
| 7448 | } | ||
| 7449 | } | ||
| 7450 | |||
| 7451 | # PART 5b: Underlay colour tags | ||
| 7452 | } elsif ($type && $underlayFlag) { | ||
| 7453 | |||
| 7454 | if ( | ||
| 7455 | defined $tagHash{'real_underlay'} | ||
| 7456 | && $tagHash{'real_underlay'} eq $tag | ||
| 7457 | ) { | ||
| 7458 | # (The re-occuring tag is ignored) | ||
| 7459 | |||
| 7460 | } elsif ($attribsOffFlag && $boldishTag eq $self->underlayColour) { | ||
| 7461 | |||
| 7462 | # After an 'attribs off', if the tag matches the 'main' window's normal | ||
| 7463 | # underlay colour, let that be the underlay colour | ||
| 7464 | $tagHash{'real_underlay'} = undef; | ||
| 7465 | |||
| 7466 | } else { | ||
| 7467 | |||
| 7468 | $tagHash{'real_underlay'} = $tag; | ||
| 7469 | |||
| 7470 | # If the world is using an OSC colour palette to modify this colour, use the | ||
| 7471 | # modified form | ||
| 7472 | if ($session->ivExists('oscColourHash', $tagHash{'real_underlay'})) { | ||
| 7473 | |||
| 7474 | $tagHash{'real_underlay'} | ||
| 7475 | = $session->ivShow('oscColourHash', $tagHash{'real_underlay'}); | ||
| 7476 | } | ||
| 7477 | } | ||
| 7478 | |||
| 7479 | # In conceal mode and reverse video mode, changing the underlay colour has no | ||
| 7480 | # effect | ||
| 7481 | if (! $tagHash{'conceal'} && ! $tagHash{'reverse'}) { | ||
| 7482 | |||
| 7483 | $tagHash{'underlay'} = $tagHash{'real_underlay'}; | ||
| 7484 | } | ||
| 7485 | } | ||
| 7486 | } | ||
| 7487 | } | ||
| 7488 | |||
| 7489 | return %tagHash; | ||
| 7490 | } | ||
| 7491 | |||
| 7492 | sub listColourStyleTags { | ||
| 7493 | |||
| 7494 | # Called by GA::Session->processLineSegment and GA::Buffer::Display->new, ->update | ||
| 7495 | # The argument is a hash, in the form specified by GA::CLIENT->constColourStyleHash, of | ||
| 7496 | # Axmud colour/style tags that apply at some offset in the textview. This function | ||
| 7497 | # converts the hash to a simple list | ||
| 7498 | # | ||
| 7499 | # Expected arguments | ||
| 7500 | # (none besides $self) | ||
| 7501 | # | ||
| 7502 | # Optional arguments | ||
| 7503 | # %tagHash - A hash of Axmud colour/style tags in the form specified by | ||
| 7504 | # GA::CLIENT->constColourStyleHash. If an empty hash, | ||
| 7505 | # $self->colourStyleHash is used instead | ||
| 7506 | # | ||
| 7507 | # Return values | ||
| 7508 | # An empty list on improper arguments | ||
| 7509 | # Otherwise, returns the converted list of Axmud colour/style tags (may be an empty list) | ||
| 7510 | |||
| 7511 | my ($self, %tagHash) = @_; | ||
| 7512 | |||
| 7513 | # Local variables | ||
| 7514 | my @returnList; | ||
| 7515 | |||
| 7516 | # (No improper arguments to check) | ||
| 7517 | |||
| 7518 | # Import this textview's current hash of colour/style tags, if no hash was specified | ||
| 7519 | if (! %tagHash) { | ||
| 7520 | |||
| 7521 | %tagHash = $self->colourStyleHash; | ||
| 7522 | } | ||
| 7523 | |||
| 7524 | # Compile a list of colour/style tags which now apply (tags listed in rough order of | ||
| 7525 | # popularity) | ||
| 7526 | if (defined $tagHash{'text'}) { | ||
| 7527 | |||
| 7528 | push (@returnList, $tagHash{'text'}); | ||
| 7529 | } | ||
| 7530 | |||
| 7531 | if (defined $tagHash{'underlay'}) { | ||
| 7532 | |||
| 7533 | push (@returnList, $tagHash{'underlay'}); | ||
| 7534 | } | ||
| 7535 | |||
| 7536 | if ($tagHash{'link'}) { | ||
| 7537 | |||
| 7538 | push (@returnList, 'link'); | ||
| 7539 | } | ||
| 7540 | |||
| 7541 | if ($tagHash{'italics'}) { | ||
| 7542 | |||
| 7543 | push (@returnList, 'italics'); | ||
| 7544 | } | ||
| 7545 | |||
| 7546 | if ($tagHash{'underline'}) { | ||
| 7547 | |||
| 7548 | push (@returnList, 'underline'); | ||
| 7549 | } | ||
| 7550 | |||
| 7551 | if ($tagHash{'blink_slow'}) { | ||
| 7552 | |||
| 7553 | push (@returnList, 'blink_slow'); | ||
| 7554 | } | ||
| 7555 | |||
| 7556 | if ($tagHash{'blink_fast'}) { | ||
| 7557 | |||
| 7558 | push (@returnList, 'blink_fast'); | ||
| 7559 | } | ||
| 7560 | |||
| 7561 | if ($tagHash{'strike'}) { | ||
| 7562 | |||
| 7563 | push (@returnList, 'strike'); | ||
| 7564 | } | ||
| 7565 | |||
| 7566 | if (defined $tagHash{'mxp_font'}) { | ||
| 7567 | |||
| 7568 | push (@returnList, $tagHash{'mxp_font'}); | ||
| 7569 | } | ||
| 7570 | |||
| 7571 | if (defined $tagHash{'justify'}) { | ||
| 7572 | |||
| 7573 | # e.g. 'justify_left' | ||
| 7574 | push (@returnList, 'justify_' . $tagHash{'justify'}); | ||
| 7575 | } | ||
| 7576 | |||
| 7577 | return @returnList; | ||
| 7578 | } | ||
| 7579 | |||
| 7580 | sub showLinkTooltips { | ||
| 7581 | |||
| 7582 | # Called by $self->checkMousePosn | ||
| 7583 | # Shows the tooltips window to display a link hint | ||
| 7584 | # | ||
| 7585 | # Expected arguments | ||
| 7586 | # $linkObj - The GA::Obj::Link whose ->hint must be displayed in the tooltip | ||
| 7587 | # | ||
| 7588 | # Return values | ||
| 7589 | # 'undef' on improper arguments or if the tooltip can't be shown | ||
| 7590 | # 1 otherwise | ||
| 7591 | |||
| 7592 | my ($self, $linkObj, $check) = @_; | ||
| 7593 | |||
| 7594 | # Local variables | ||
| 7595 | my $hint; | ||
| 7596 | |||
| 7597 | # Check for improper arguments | ||
| 7598 | if (! defined $linkObj || defined $check) { | ||
| 7599 | |||
| 7600 | return $axmud::CLIENT->writeImproper($self->_objClass . '->showLinkTooltips', @_); | ||
| 7601 | } | ||
| 7602 | |||
| 7603 | # Don't show tooltips if the parent window isn't active, or if the GA::Obj::Link object | ||
| 7604 | # doesn't have a ->hint set | ||
| 7605 | $hint = $linkObj->hint; | ||
| 7606 | if (! $self->winObj->winWidget->is_active() || ! $hint) { | ||
| 7607 | |||
| 7608 | return undef; | ||
| 7609 | |||
| 7610 | } else { | ||
| 7611 | |||
| 7612 | $self->textView->set_tooltip_text($hint); | ||
| 7613 | if ($self->textView2) { | ||
| 7614 | |||
| 7615 | $self->textView2->set_tooltip_text($hint); | ||
| 7616 | } | ||
| 7617 | |||
| 7618 | return 1; | ||
| 7619 | } | ||
| 7620 | } | ||
| 7621 | |||
| 7622 | sub showSessionTooltips { | ||
| 7623 | |||
| 7624 | # Called by $self->checkMousePosn (but only if this is the session's default textview, and | ||
| 7625 | # if the mouse is hovering over a line containing text received from the world) | ||
| 7626 | # Shows the tooltips window to display information about the display buffer objects | ||
| 7627 | # (GA::Buffer::Display) corresponding to this line | ||
| 7628 | # | ||
| 7629 | # Expected arguments | ||
| 7630 | # $lineNum - The line number of the Gtk3::TextBuffer line above which the mouse is | ||
| 7631 | # hovering | ||
| 7632 | # | ||
| 7633 | # Return values | ||
| 7634 | # 'undef' on improper arguments or if the tooltip can't be shown | ||
| 7635 | # 1 otherwise | ||
| 7636 | |||
| 7637 | my ($self, $lineNum, $check) = @_; | ||
| 7638 | |||
| 7639 | # Local variables | ||
| 7640 | my $tooltip; | ||
| 7641 | |||
| 7642 | # Check for improper arguments | ||
| 7643 | if (! defined $lineNum || defined $check) { | ||
| 7644 | |||
| 7645 | return $axmud::CLIENT->writeImproper($self->_objClass . '->showSessionTooltips', @_); | ||
| 7646 | } | ||
| 7647 | |||
| 7648 | # Don't show tooltips if the parent window isn't active | ||
| 7649 | if (! $self->winObj->winWidget->is_active()) { | ||
| 7650 | |||
| 7651 | return undef; | ||
| 7652 | } | ||
| 7653 | |||
| 7654 | if (defined $self->lastTooltipLine && $self->lastTooltipLine != $lineNum) { | ||
| 7655 | |||
| 7656 | # The mouse has moved over a new line. Make the tooltip window 'follow' it by | ||
| 7657 | # briefly resetting the tooltip | ||
| 7658 | $self->textView->set_tooltip_text(''); | ||
| 7659 | if ($self->textView2) { | ||
| 7660 | |||
| 7661 | $self->textView2->set_tooltip_text(''); | ||
| 7662 | } | ||
| 7663 | |||
| 7664 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->checkMousePosn'); | ||
| 7665 | } | ||
| 7666 | |||
| 7667 | # Show the window | ||
| 7668 | $tooltip = $self->ivShow('tooltipHash', $lineNum); | ||
| 7669 | $self->textView->set_tooltip_text($tooltip); | ||
| 7670 | if ($self->textView2) { | ||
| 7671 | |||
| 7672 | $self->textView2->set_tooltip_text($tooltip); | ||
| 7673 | } | ||
| 7674 | |||
| 7675 | $self->ivPoke('lastTooltipLine', $lineNum); | ||
| 7676 | |||
| 7677 | return 1; | ||
| 7678 | } | ||
| 7679 | |||
| 7680 | sub hideTooltips { | ||
| 7681 | |||
| 7682 | # Called by $self->checkMousePosn and various ->signal_connects in this textview object | ||
| 7683 | # | ||
| 7684 | # Expected arguments | ||
| 7685 | # (none besides $self) | ||
| 7686 | # | ||
| 7687 | # Return values | ||
| 7688 | # 'undef' on improper arguments or if the tooltip can't be hidden | ||
| 7689 | # 1 otherwise | ||
| 7690 | |||
| 7691 | my ($self, $check) = @_; | ||
| 7692 | |||
| 7693 | # Check for improper arguments | ||
| 7694 | if (defined $check) { | ||
| 7695 | |||
| 7696 | return $axmud::CLIENT->writeImproper($self->_objClass . '->hideTooltips', @_); | ||
| 7697 | } | ||
| 7698 | |||
| 7699 | # Hide the tooltips window | ||
| 7700 | $self->textView->set_tooltip_text(''); | ||
| 7701 | if ($self->textView2) { | ||
| 7702 | |||
| 7703 | $self->textView2->set_tooltip_text(''); | ||
| 7704 | } | ||
| 7705 | |||
| 7706 | # Update IVs | ||
| 7707 | $self->ivUndef('lastTooltipLine'); | ||
| 7708 | |||
| 7709 | return 1; | ||
| 7710 | } | ||
| 7711 | |||
| 7712 | sub useDisplayBufferNum { | ||
| 7713 | |||
| 7714 | # Called by GA::Session->processLineSegment (only) | ||
| 7715 | # The calling function is informing us that this textview object is its default textview | ||
| 7716 | # object, that it's about to call ->insertText, and that we should make a note of the | ||
| 7717 | # session's current display buffer line number, so we can display our tooltips correctly | ||
| 7718 | # | ||
| 7719 | # Expected arguments | ||
| 7720 | # $sessionLineNum - The session's display buffer line number (matching | ||
| 7721 | # GA::Session->displayBufferCount) | ||
| 7722 | # | ||
| 7723 | # Return values | ||
| 7724 | # 'undef' on improper arguments | ||
| 7725 | |||
| 7726 | # 1 otherwise | ||
| 7727 | |||
| 7728 | my ($self, $sessionLineNum, $check) = @_; | ||
| 7729 | |||
| 7730 | # Local variables | ||
| 7731 | my $iter; | ||
| 7732 | |||
| 7733 | # Check for improper arguments | ||
| 7734 | if (! defined $sessionLineNum || defined $check) { | ||
| 7735 | |||
| 7736 | return $axmud::CLIENT->writeImproper($self->_objClass . '->useDisplayBufferNum', @_); | ||
| 7737 | } | ||
| 7738 | |||
| 7739 | # The hash only needs to be updated, once per line of non-system message text | ||
| 7740 | # The Gtk3::Textbuffer renumbers its line every time we delete one from the beginning of the | ||
| 7741 | # buffer, so here we must add $self->nextDeleteLine | ||
| 7742 | if (! $self->insertMark && $self->newLineFlag) { | ||
| 7743 | |||
| 7744 | $iter = $self->buffer->get_end_iter(); | ||
| 7745 | $self->ivAdd( | ||
| 7746 | 'tooltipHash', | ||
| 7747 | ($iter->get_line() + $self->nextDeleteLine), | ||
| 7748 | 'Line ' . $sessionLineNum . ', ' . $axmud::CLIENT->localTime, | ||
| 7749 | ); | ||
| 7750 | } | ||
| 7751 | |||
| 7752 | return 1; | ||
| 7753 | } | ||
| 7754 | |||
| 7755 | sub createPopupMenu { | ||
| 7756 | |||
| 7757 | # Called by ->signal_connect in $self->setButtonPressEvent | ||
| 7758 | # After the user has clicked on $self->currentLinkObj, creates a popup menu from which the | ||
| 7759 | # user can select one of several menu items. If the user clicks on a menu item, the | ||
| 7760 | # corresponding world command is sent | ||
| 7761 | # The menu options and corresponding world commands are (usually) set by an MXP | ||
| 7762 | # <SEND>..</SEND> construction | ||
| 7763 | # | ||
| 7764 | # Expected arguments | ||
| 7765 | # $event - The 'button_press_event' signal emitted when the user clicks on a | ||
| 7766 | # clickable link in the tab | ||
| 7767 | # | ||
| 7768 | # Return values | ||
| 7769 | # 'undef' on improper arguments or if the popup menu can't be created | ||
| 7770 | # 1 otherwise | ||
| 7771 | |||
| 7772 | my ($self, $event, $check) = @_; | ||
| 7773 | |||
| 7774 | # Local variables | ||
| 7775 | my ( | ||
| 7776 | $linkObj, $count, | ||
| 7777 | @optionList, | ||
| 7778 | ); | ||
| 7779 | |||
| 7780 | # Check for improper arguments | ||
| 7781 | if (! defined $event || defined $check) { | ||
| 7782 | |||
| 7783 | return $axmud::CLIENT->writeImproper($self->_objClass . '->createPopupMenu', @_); | ||
| 7784 | } | ||
| 7785 | |||
| 7786 | # Check there is a current link object set (no reason why there shouldn't be) | ||
| 7787 | if (! $self->currentLinkObj) { | ||
| 7788 | |||
| 7789 | return undef; | ||
| 7790 | |||
| 7791 | } else { | ||
| 7792 | |||
| 7793 | # $self->currentLinkObj will be set to 'undef' as soon as the popup menu is clicked, | ||
| 7794 | # and before this function returns, so store the object as a local variable) | ||
| 7795 | $linkObj = $self->currentLinkObj; | ||
| 7796 | } | ||
| 7797 | |||
| 7798 | # Create the popup menu | ||
| 7799 | my $menu = Gtk3::Menu->new(); | ||
| 7800 | |||
| 7801 | # The GA::Obj::Link stores menu items and corresponding world commands each as a single | ||
| 7802 | # string, with items/commands separated by a | character | ||
| 7803 | # (If there was an extra item in @optionList, representing an extra tooltip hint to show | ||
| 7804 | # e.g. "Click to see the menu", it has already been removed) | ||
| 7805 | @optionList = $linkObj->popupItemList; | ||
| 7806 | |||
| 7807 | $count = -1; | ||
| 7808 | foreach my $cmd ($linkObj->popupCmdList) { | ||
| 7809 | |||
| 7810 | my ($hint, $menuItem); | ||
| 7811 | |||
| 7812 | $count++; | ||
| 7813 | |||
| 7814 | # Prefer to use a hint over a raw command, if a hint was supplied | ||
| 7815 | $hint = shift (@optionList); | ||
| 7816 | $menuItem = Gtk3::MenuItem->new_with_label(''); | ||
| 7817 | |||
| 7818 | my $label = $menuItem->get_child(); | ||
| 7819 | if ($hint) { | ||
| 7820 | |||
| 7821 | if (! $count) { | ||
| 7822 | $label->set_markup('<b>' . $hint . '</b>'); | ||
| 7823 | } else { | ||
| 7824 | $label->set_markup($hint); | ||
| 7825 | } | ||
| 7826 | |||
| 7827 | } else { | ||
| 7828 | |||
| 7829 | if (! $count) { | ||
| 7830 | $label->set_markup('<b>' . $cmd . '</b>'); | ||
| 7831 | } else { | ||
| 7832 | $label->set_markup($cmd); | ||
| 7833 | } | ||
| 7834 | } | ||
| 7835 | |||
| 7836 | $menu->append($menuItem); | ||
| 7837 | $menuItem->signal_connect('activate' => sub { | ||
| 7838 | |||
| 7839 | my $stripObj = $self->paneObj->winObj->getStrip('entry'); | ||
| 7840 | |||
| 7841 | if ($linkObj->mxpPromptFlag && $stripObj) { | ||
| 7842 | $stripObj->commandeerEntry($self->session, $cmd); | ||
| 7843 | } else { | ||
| 7844 | $self->session->worldCmd($cmd); | ||
| 7845 | } | ||
| 7846 | }); | ||
| 7847 | } | ||
| 7848 | |||
| 7849 | $menu->popup( | ||
| 7850 | undef, undef, undef, undef, | ||
| 7851 | $event->button, | ||
| 7852 | $event->time, | ||
| 7853 | ); | ||
| 7854 | |||
| 7855 | $menu->show_all(); | ||
| 7856 | |||
| 7857 | # Store as an IV, so that $self->resetCurrentLink can destroy it, if the link expires | ||
| 7858 | $self->ivPoke('popupMenu', $menu); | ||
| 7859 | $menu->signal_connect('delete-event' => sub { | ||
| 7860 | |||
| 7861 | $self->ivUndef('popupMenu'); | ||
| 7862 | |||
| 7863 | return undef; | ||
| 7864 | }); | ||
| 7865 | |||
| 7866 | return 1; | ||
| 7867 | } | ||
| 7868 | |||
| 7869 | sub resetCurrentLink { | ||
| 7870 | |||
| 7871 | # Called by GA::Session->processMxpOfficialElement when the GA::Obj::Link object stored in | ||
| 7872 | # $self->currentLinkObj expires | ||
| 7873 | # Hides tooltips, resets the cursor, closes the popup menu | ||
| 7874 | # | ||
| 7875 | # Expected arguments | ||
| 7876 | # (none besides $self) | ||
| 7877 | # | ||
| 7878 | # Return values | ||
| 7879 | # 'undef' on improper arguments or if this isn't the 'main' window | ||
| 7880 | # 1 otherwise | ||
| 7881 | |||
| 7882 | my ($self, $check) = @_; | ||
| 7883 | |||
| 7884 | # Check for improper arguments | ||
| 7885 | if (defined $check) { | ||
| 7886 | |||
| 7887 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetCurrentLink', @_); | ||
| 7888 | } | ||
| 7889 | |||
| 7890 | # Hide tooltips, if visible | ||
| 7891 | $self->hideTooltips(); | ||
| 7892 | |||
| 7893 | # Reset the cursor | ||
| 7894 | if ($self->textView) { | ||
| 7895 | |||
| 7896 | $self->textView->get_window('text')->set_cursor($axmud::CLIENT->constNormalCursor); | ||
| 7897 | } | ||
| 7898 | |||
| 7899 | # Close the popup menu | ||
| 7900 | if ($self->popupMenu) { | ||
| 7901 | |||
| 7902 | $self->popupMenu->destroy(); | ||
| 7903 | |||
| 7904 | $self->ivUndef('popupMenu'); | ||
| 7905 | } | ||
| 7906 | |||
| 7907 | return 1; | ||
| 7908 | } | ||
| 7909 | |||
| 7910 | sub toggleScrollLock { | ||
| 7911 | |||
| 7912 | # Called by GA::Table::Pane->toggleScrollLock | ||
| 7913 | # Enables or disables this textview object's scroll lock mode, in which the textview scrolls | ||
| 7914 | # to the bottom every time text is received from the world. (If split screen mode is | ||
| 7915 | # enabled, only the original lower textview scrolls) | ||
| 7916 | # | ||
| 7917 | # Expected arguments | ||
| 7918 | # (none besides $self) | ||
| 7919 | # | ||
| 7920 | # Return values | ||
| 7921 | # 'undef' on improper arguments | ||
| 7922 | # 1 otherwise | ||
| 7923 | |||
| 7924 | my ($self, $check) = @_; | ||
| 7925 | |||
| 7926 | # Check for improper arguments | ||
| 7927 | if (defined $check) { | ||
| 7928 | |||
| 7929 | return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleScrollLock', @_); | ||
| 7930 | } | ||
| 7931 | |||
| 7932 | if (! $self->scrollLockFlag) { | ||
| 7933 | |||
| 7934 | $self->ivPoke('scrollLockFlag', TRUE); | ||
| 7935 | |||
| 7936 | # Scroll to the beginning/end of the buffer in the (original) textview immediately | ||
| 7937 | if ($self->scrollLockType eq 'top') { | ||
| 7938 | $self->scrollToTop(); | ||
| 7939 | } else { | ||
| 7940 | $self->scrollToBottom(); | ||
| 7941 | } | ||
| 7942 | |||
| 7943 | } else { | ||
| 7944 | |||
| 7945 | $self->ivPoke('scrollLockFlag', FALSE); | ||
| 7946 | |||
| 7947 | $self->winObj->winShowAll($self->_objClass . '->toggleScrollLock'); | ||
| 7948 | } | ||
| 7949 | |||
| 7950 | # Operation complete | ||
| 7951 | return 1; | ||
| 7952 | } | ||
| 7953 | |||
| 7954 | sub setSplitScreenMode { | ||
| 7955 | |||
| 7956 | # Called by GA::Table::Pane->convertSimpleTab, ->convertTab and ->toggleSplitScreen | ||
| 7957 | # Sets this textview object's split screen mode, adding or removing a second textview and | ||
| 7958 | # repositioning the divider between two textviews as required | ||
| 7959 | # This is a convenience function. Axmud code is free to call $self->enableSingleScreen, | ||
| 7960 | # ->enableSplitScreen or ->enableHiddenSplitScreen directly, if preferred | ||
| 7961 | # | ||
| 7962 | # Expected arguments | ||
| 7963 | # $mode - One of the recognised values for $self->splitScreenMode, i.e. 'single', | ||
| 7964 | # 'split' or 'hidden' | ||
| 7965 | # | ||
| 7966 | # Return values | ||
| 7967 | # 'undef' on improper arguments or on general failure | ||
| 7968 | # If $mode is already the same value as $self->splitScreenMode, nothing happens and | ||
| 7969 | # 'undef' is returned | ||
| 7970 | # If $mode is 'split' or 'hidden', and if $self->splitScreenMode is already 'split' or | ||
| 7971 | # 'hidden', returns 'undef' (as no Gtk3 widgets need to be repacked) | ||
| 7972 | # If $mode is 'single' and $self->splitScreenMode is not 'single', or vice-versa, then | ||
| 7973 | # returns a packable widget which should be packed into the space occupied by the | ||
| 7974 | # previous packable widget | ||
| 7975 | |||
| 7976 | my ($self, $mode, $check) = @_; | ||
| 7977 | |||
| 7978 | # Check for improper arguments | ||
| 7979 | if ( | ||
| 7980 | ! defined $mode | ||
| 7981 | || ($mode ne 'single' && $mode ne 'split' && $mode ne 'hidden') | ||
| 7982 | || defined $check | ||
| 7983 | ) { | ||
| 7984 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setSplitScreenMode', @_); | ||
| 7985 | } | ||
| 7986 | |||
| 7987 | if ($mode eq $self->splitScreenMode) { | ||
| 7988 | |||
| 7989 | # No changes required | ||
| 7990 | return undef; | ||
| 7991 | |||
| 7992 | } elsif ($mode eq 'single') { | ||
| 7993 | |||
| 7994 | return $self->enableSingleScreen(); | ||
| 7995 | |||
| 7996 | } elsif ($mode eq 'split') { | ||
| 7997 | |||
| 7998 | return $self->enableSplitScreen(); | ||
| 7999 | |||
| 8000 | } elsif ($mode eq 'hidden') { | ||
| 8001 | |||
| 8002 | return $self->enableHiddenSplitScreen(); | ||
| 8003 | } | ||
| 8004 | } | ||
| 8005 | |||
| 8006 | sub enableSingleScreen { | ||
| 8007 | |||
| 8008 | # Called by $self->setSplitScreenMode (or directly by any code) | ||
| 8009 | # Sets $self->splitScreenMode to 'single' | ||
| 8010 | # If $self->splitScreenMode was 'split' or 'hidden', replaces the existing Gtk3::VPaned, | ||
| 8011 | # containing two textviews, with a Gtk3::Frame containing a single textview, and returns | ||
| 8012 | # the frame. The calling function should pack the frame into the space previously occupied | ||
| 8013 | # by the vpaned | ||
| 8014 | # | ||
| 8015 | # Expected arguments | ||
| 8016 | # (none besides $self) | ||
| 8017 | # | ||
| 8018 | # Return values | ||
| 8019 | # 'undef' on improper arguments or if $self->splitScreenMode is already 'single' | ||
| 8020 | # Otherwise, returns the Gtk3::Frame | ||
| 8021 | |||
| 8022 | my ($self, $check) = @_; | ||
| 8023 | |||
| 8024 | # Check for improper arguments | ||
| 8025 | if (defined $check) { | ||
| 8026 | |||
| 8027 | return $axmud::CLIENT->writeImproper($self->_objClass . '->enableSingleScreen'); | ||
| 8028 | } | ||
| 8029 | |||
| 8030 | if ($self->splitScreenMode eq 'single') { | ||
| 8031 | |||
| 8032 | # Nothing needs to be re-packed | ||
| 8033 | return undef | ||
| 8034 | |||
| 8035 | } else { | ||
| 8036 | |||
| 8037 | # Set the new mode | ||
| 8038 | $self->ivPoke('splitScreenMode', 'single'); | ||
| 8039 | |||
| 8040 | # Create the new Gtk3::TextView, using the same Gtk3::TextBuffer as the original one | ||
| 8041 | my $textView = $self->createTextViewWidget($self->buffer); | ||
| 8042 | |||
| 8043 | # Set the textview's CSS style | ||
| 8044 | $axmud::CLIENT->desktopObj->setTextViewObjStyle( | ||
| 8045 | $self->number, | ||
| 8046 | $self->textColour, | ||
| 8047 | $self->backgroundColour, | ||
| 8048 | $self->font, | ||
| 8049 | $self->fontSize, | ||
| 8050 | $textView, | ||
| 8051 | ); | ||
| 8052 | |||
| 8053 | # Pack the textview into a container widget | ||
| 8054 | my $scroll = $self->setupScroller($textView); | ||
| 8055 | |||
| 8056 | # Update IVs again | ||
| 8057 | $self->ivPoke('textView', $textView); | ||
| 8058 | $self->ivUndef('textView2'); | ||
| 8059 | $self->ivUndef('vPaned'); | ||
| 8060 | $self->ivPoke('scroll', $scroll); | ||
| 8061 | $self->ivUndef('scroll2'); | ||
| 8062 | |||
| 8063 | # In case split screen mode has just been turned off, check that the textview's size | ||
| 8064 | # hasn't change (as soon as possible) | ||
| 8065 | $self->ivPoke('sizeUpdateFlag', TRUE); | ||
| 8066 | |||
| 8067 | # Operation complete | ||
| 8068 | return $scroll; | ||
| 8069 | } | ||
| 8070 | } | ||
| 8071 | |||
| 8072 | sub enableSplitScreen { | ||
| 8073 | |||
| 8074 | # Called by $self->setSplitScreenMode (or directly by any code) | ||
| 8075 | # Sets $self->splitScreenMode to 'split' | ||
| 8076 | # If $self->splitScreenMode was 'single', replaces the existing Gtk3::Frame, containing a | ||
| 8077 | # single textview, with a Gtk3::VPaned, containing two textviews, and returns the vpaned. | ||
| 8078 | # The calling function should pack the vpaned into the space previously occupied by the | ||
| 8079 | # frame | ||
| 8080 | # If $self->splitScreenMode was 'hidden', moves the divider so that the hidden textview | ||
| 8081 | # becomes visible (if the user manually moved the divider, this function moves the | ||
| 8082 | # divider to its default position for this mode) | ||
| 8083 | # | ||
| 8084 | # Expected arguments | ||
| 8085 | # (none besides $self) | ||
| 8086 | # | ||
| 8087 | # Return values | ||
| 8088 | # 'undef' on improper arguments or if $self->splitScreenMode is currently 'split' or | ||
| 8089 | # 'hidden' | ||
| 8090 | # Otherwise, returns the Gtk3::VPaned | ||
| 8091 | |||
| 8092 | my ($self, $check) = @_; | ||
| 8093 | |||
| 8094 | # Check for improper arguments | ||
| 8095 | if (defined $check) { | ||
| 8096 | |||
| 8097 | return $axmud::CLIENT->writeImproper($self->_objClass . '->enableSplitScreen'); | ||
| 8098 | } | ||
| 8099 | |||
| 8100 | if ($self->splitScreenMode eq 'split') { | ||
| 8101 | |||
| 8102 | # Nothing needs to be re-packed | ||
| 8103 | return undef | ||
| 8104 | |||
| 8105 | } else { | ||
| 8106 | |||
| 8107 | if ($self->splitScreenMode eq 'hidden') { | ||
| 8108 | |||
| 8109 | # Set the new mode | ||
| 8110 | $self->ivPoke('splitScreenMode', 'split'); | ||
| 8111 | |||
| 8112 | # Move the divider and rescroll textviews to the bottom (for tidiest visual effect) | ||
| 8113 | $self->setDividerPosn($self->vPaned); | ||
| 8114 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->enableSplitScreen'); | ||
| 8115 | $self->scrollToLock(); | ||
| 8116 | |||
| 8117 | # Nothing needs to be re-packed | ||
| 8118 | return undef | ||
| 8119 | |||
| 8120 | } else { | ||
| 8121 | |||
| 8122 | # Set the new mode | ||
| 8123 | $self->ivPoke('splitScreenMode', 'split'); | ||
| 8124 | |||
| 8125 | # Create the new Gtk3::TextView, using the same Gtk3::TextBuffer as the original one | ||
| 8126 | my $textView2 = $self->createTextViewWidget($self->buffer); | ||
| 8127 | |||
| 8128 | # Update the textviews' CSS style | ||
| 8129 | $axmud::CLIENT->desktopObj->setTextViewObjStyle( | ||
| 8130 | $self->number, | ||
| 8131 | $self->textColour, | ||
| 8132 | $self->backgroundColour, | ||
| 8133 | $self->font, | ||
| 8134 | $self->fontSize, | ||
| 8135 | $self->textView, | ||
| 8136 | $textView2, | ||
| 8137 | ); | ||
| 8138 | |||
| 8139 | # Pack the textviews into a container widget | ||
| 8140 | my ($vPaned, $scroll, $scroll2) = $self->setupVPaned($self->textView, $textView2); | ||
| 8141 | |||
| 8142 | # Update IVs again | ||
| 8143 | $self->ivPoke('textView2', $textView2); | ||
| 8144 | $self->ivPoke('vPaned', $vPaned); | ||
| 8145 | $self->ivPoke('scroll', $scroll); | ||
| 8146 | $self->ivPoke('scroll2', $scroll2); | ||
| 8147 | |||
| 8148 | # Operation complete | ||
| 8149 | return $vPaned; | ||
| 8150 | } | ||
| 8151 | } | ||
| 8152 | } | ||
| 8153 | |||
| 8154 | sub enableHiddenSplitScreen { | ||
| 8155 | |||
| 8156 | # Called by $self->setSplitScreenMode (or directly by any code) | ||
| 8157 | # Sets $self->splitScreenMode to 'hidden' | ||
| 8158 | # If $self->splitScreenMode was 'single', replaces the existing Gtk3::Frame, containing a | ||
| 8159 | # single textview, with a Gtk3::VPaned, containing two textviews, and returns the vpaned. | ||
| 8160 | # The calling function should pack the vpaned into the space previously occupied by the | ||
| 8161 | # frame | ||
| 8162 | # If $self->splitScreenMode was 'split', moves the divider so that the second textview | ||
| 8163 | # becomes hidden | ||
| 8164 | # | ||
| 8165 | # Expected arguments | ||
| 8166 | # (none besides $self) | ||
| 8167 | # | ||
| 8168 | # Return values | ||
| 8169 | # 'undef' on improper arguments or if $self->splitScreenMode is currently 'split' or | ||
| 8170 | # 'hidden' | ||
| 8171 | # Otherwise, returns the Gtk3::VPaned | ||
| 8172 | |||
| 8173 | my ($self, $check) = @_; | ||
| 8174 | |||
| 8175 | # Check for improper arguments | ||
| 8176 | if (defined $check) { | ||
| 8177 | |||
| 8178 | return $axmud::CLIENT->writeImproper($self->_objClass . '->enableHiddenSplitScreen'); | ||
| 8179 | } | ||
| 8180 | |||
| 8181 | if ($self->splitScreenMode eq 'hidden') { | ||
| 8182 | |||
| 8183 | # Nothing needs to be re-packed | ||
| 8184 | return undef | ||
| 8185 | |||
| 8186 | } else { | ||
| 8187 | |||
| 8188 | if ($self->splitScreenMode eq 'split') { | ||
| 8189 | |||
| 8190 | # Set the new mode | ||
| 8191 | $self->ivPoke('splitScreenMode', 'hidden'); | ||
| 8192 | |||
| 8193 | # Move the divider and rescroll textviews to the bottom (for tidiest visual effect) | ||
| 8194 | $self->setDividerPosn($self->vPaned); | ||
| 8195 | $axmud::CLIENT->desktopObj->updateWidgets( | ||
| 8196 | $self->_objClass . '->enableHiddenSplitScreen', | ||
| 8197 | ); | ||
| 8198 | |||
| 8199 | $self->scrollToLock(); | ||
| 8200 | |||
| 8201 | # In case split screen mode has just been turned off, check that the textview's size | ||
| 8202 | # hasn't change (as soon as possible) | ||
| 8203 | $self->ivPoke('sizeUpdateFlag', TRUE); | ||
| 8204 | |||
| 8205 | # Nothing needs to be re-packed | ||
| 8206 | return undef | ||
| 8207 | |||
| 8208 | } else { | ||
| 8209 | |||
| 8210 | # Set the new mode | ||
| 8211 | $self->ivPoke('splitScreenMode', 'hidden'); | ||
| 8212 | |||
| 8213 | # Create the new Gtk3::TextView, using the same Gtk3::TextBuffer as the original one | ||
| 8214 | my $textView2 = $self->createTextViewWidget($self->buffer); | ||
| 8215 | |||
| 8216 | # Update the textviews' CSS style | ||
| 8217 | $axmud::CLIENT->desktopObj->setTextViewObjStyle( | ||
| 8218 | $self->number, | ||
| 8219 | $self->textColour, | ||
| 8220 | $self->backgroundColour, | ||
| 8221 | $self->font, | ||
| 8222 | $self->fontSize, | ||
| 8223 | $self->textView, | ||
| 8224 | $textView2, | ||
| 8225 | ); | ||
| 8226 | |||
| 8227 | # Pack the textviews into a container widget | ||
| 8228 | my ($vPaned, $scroll, $scroll2) = $self->setupVPaned($self->textView, $textView2); | ||
| 8229 | |||
| 8230 | # Update IVs again | ||
| 8231 | $self->ivPoke('textView2', $textView2); | ||
| 8232 | $self->ivPoke('vPaned', $vPaned); | ||
| 8233 | $self->ivPoke('scroll', $scroll); | ||
| 8234 | $self->ivPoke('scroll2', $scroll2); | ||
| 8235 | |||
| 8236 | # Operation complete | ||
| 8237 | return $vPaned; | ||
| 8238 | } | ||
| 8239 | } | ||
| 8240 | } | ||
| 8241 | |||
| 8242 | sub checkMousePosn { | ||
| 8243 | |||
| 8244 | # Called by ->signal_connects in $self->setMotionNotifyEvent | ||
| 8245 | # When the mouse moves over a clickable link in a Gtk3::TextView, we should change the mouse | ||
| 8246 | # cursor. When the mouse moves away from a clickable link, we should restore the mouse | ||
| 8247 | # cursor | ||
| 8248 | # | ||
| 8249 | # NB This function isn't used for clickable images. ->signal_connects for that are found in | ||
| 8250 | # $self->showImage | ||
| 8251 | # | ||
| 8252 | # Expected arguments | ||
| 8253 | # $textView - The Gtk3::TextView over which the mouse is moving | ||
| 8254 | # $event - The Gtk3::Gdk::Event | ||
| 8255 | # | ||
| 8256 | # Return values | ||
| 8257 | # 'undef' on improper arguments | ||
| 8258 | # 1 on success | ||
| 8259 | |||
| 8260 | my ($self, $textView, $event, $check) = @_; | ||
| 8261 | |||
| 8262 | # Local variables | ||
| 8263 | my ( | ||
| 8264 | $xPos, $yPos, $iter, $lineNum, $posn, $hoverFlag, $listRef, $window, $listRef2, | ||
| 8265 | $linkObj, $tooltipsFlag, $tooltip, | ||
| 8266 | ); | ||
| 8267 | |||
| 8268 | # Check for improper arguments | ||
| 8269 | if (! defined $textView || ! defined $event || defined $check) { | ||
| 8270 | |||
| 8271 | return $axmud::CLIENT->writeImproper($self->_objClass . '->checkMousePosn', @_); | ||
| 8272 | } | ||
| 8273 | |||
| 8274 | # Get the mouse's position over the textview's buffer | ||
| 8275 | ($xPos, $yPos) = $textView->window_to_buffer_coords('widget', $event->x, $event->y); | ||
| 8276 | # Get the buffer iter corresponding to that position | ||
| 8277 | $iter = $textView->get_iter_at_location($xPos, $yPos); | ||
| 8278 | # Get the offsets for the buffer line and character directly beneath the mouse | ||
| 8279 | $lineNum = $iter->get_line(); | ||
| 8280 | $posn = $iter->get_visible_line_offset(); | ||
| 8281 | |||
| 8282 | # Get all the tags associated with this iter, looking for the Axmud style tag 'link' | ||
| 8283 | # (Setting this flag makes any debug messages we might insert work without errors) | ||
| 8284 | $hoverFlag = FALSE; | ||
| 8285 | $listRef = $iter->get_tags(); | ||
| 8286 | if (defined $listRef) { | ||
| 8287 | |||
| 8288 | OUTER: foreach my $tag (@$listRef) { | ||
| 8289 | |||
| 8290 | if ($tag->get_property('name') eq 'link') { | ||
| 8291 | |||
| 8292 | $hoverFlag = TRUE; | ||
| 8293 | last OUTER; | ||
| 8294 | } | ||
| 8295 | } | ||
| 8296 | } | ||
| 8297 | |||
| 8298 | # Only change the cursor, if the mouse has moved from a link to normal space, or vice-versa; | ||
| 8299 | # of if the mouse has moved from one link to another | ||
| 8300 | $window = $textView->get_window('text'); | ||
| 8301 | if (! $hoverFlag && $self->currentLinkObj) { | ||
| 8302 | |||
| 8303 | # Reset the cursor | ||
| 8304 | $self->ivUndef('currentLinkObj'); | ||
| 8305 | $window->set_cursor($axmud::CLIENT->constNormalCursor); | ||
| 8306 | # Hide tooltips | ||
| 8307 | $self->hideTooltips(); | ||
| 8308 | |||
| 8309 | } elsif ($hoverFlag) { | ||
| 8310 | |||
| 8311 | # Find the corresponding GA::Obj::Link | ||
| 8312 | $listRef = $self->ivShow('linkObjLineHash', $lineNum + $self->nextDeleteLine); | ||
| 8313 | if (defined $listRef) { | ||
| 8314 | |||
| 8315 | OUTER: foreach my $thisLinkObj (@$listRef) { | ||
| 8316 | |||
| 8317 | my $endPosn = $thisLinkObj->posn + length ($thisLinkObj->text); | ||
| 8318 | |||
| 8319 | if ($posn >= $thisLinkObj->posn && $posn < $endPosn) { | ||
| 8320 | |||
| 8321 | # Found the corresponding GA::Obj::Link | ||
| 8322 | $linkObj = $thisLinkObj; | ||
| 8323 | last OUTER; | ||
| 8324 | } | ||
| 8325 | } | ||
| 8326 | } | ||
| 8327 | |||
| 8328 | if (! $linkObj) { | ||
| 8329 | |||
| 8330 | # Mouse is not above a link (or error finding a link) | ||
| 8331 | $self->ivUndef('currentLinkObj'); | ||
| 8332 | $window->set_cursor($axmud::CLIENT->constNormalCursor); | ||
| 8333 | # Hide tooltips | ||
| 8334 | $self->hideTooltips(); | ||
| 8335 | |||
| 8336 | } elsif (! $self->currentLinkObj || $self->currentLinkObj ne $linkObj) { | ||
| 8337 | |||
| 8338 | # Mouse is above a new link | ||
| 8339 | if ($linkObj->expiredFlag) { | ||
| 8340 | |||
| 8341 | # It's an expired link | ||
| 8342 | $self->ivUndef('currentLinkObj'); | ||
| 8343 | $window->set_cursor($axmud::CLIENT->constNormalCursor); | ||
| 8344 | # Hide tooltips | ||
| 8345 | $self->hideTooltips(); | ||
| 8346 | |||
| 8347 | } else { | ||
| 8348 | |||
| 8349 | # Not an expired link | ||
| 8350 | $self->ivPoke('currentLinkObj', $linkObj); | ||
| 8351 | |||
| 8352 | if ($linkObj->type eq 'www') { | ||
| 8353 | |||
| 8354 | $window->set_cursor($axmud::CLIENT->constWWWCursor); | ||
| 8355 | |||
| 8356 | } elsif ($linkObj->type eq 'cmd') { | ||
| 8357 | |||
| 8358 | # (Check ->popupFlag first, because a popup menu can also redirect to a | ||
| 8359 | # prompt) | ||
| 8360 | if ($linkObj->popupFlag) { | ||
| 8361 | $window->set_cursor($axmud::CLIENT->constPopupCursor); | ||
| 8362 | } elsif ($linkObj->mxpPromptFlag) { | ||
| 8363 | $window->set_cursor($axmud::CLIENT->constPromptCursor); | ||
| 8364 | } else { | ||
| 8365 | $window->set_cursor($axmud::CLIENT->constCmdCursor); | ||
| 8366 | } | ||
| 8367 | |||
| 8368 | } elsif ($linkObj->type eq 'mail') { | ||
| 8369 | |||
| 8370 | $window->set_cursor($axmud::CLIENT->constMailCursor); | ||
| 8371 | |||
| 8372 | } elsif ( | ||
| 8373 | $linkObj->type eq 'telnet' | ||
| 8374 | || $linkObj->type eq 'ssh' | ||
| 8375 | || $linkObj->type eq 'ssl' | ||
| 8376 | ) { | ||
| 8377 | $window->set_cursor($axmud::CLIENT->constTelnetCursor); | ||
| 8378 | |||
| 8379 | } elsif ($linkObj->type eq 'image') { | ||
| 8380 | |||
| 8381 | $axmud::CLIENT->writeDebug( | ||
| 8382 | 'Mouse above image link; examine code please', | ||
| 8383 | $self->_objClass . '->checkMousePosn', | ||
| 8384 | ); | ||
| 8385 | |||
| 8386 | } elsif ($linkObj->type eq 'other') { | ||
| 8387 | |||
| 8388 | $window->set_cursor($axmud::CLIENT->constNormalCursor); | ||
| 8389 | } | ||
| 8390 | |||
| 8391 | # If it's an MXP link with a hint, show the hint in the tooltip window | ||
| 8392 | if ($linkObj->hint) { | ||
| 8393 | |||
| 8394 | # Unhide the tooltips window and display $linkObj's ->hint | ||
| 8395 | $self->showLinkTooltips($linkObj); | ||
| 8396 | $tooltipsFlag = TRUE; | ||
| 8397 | |||
| 8398 | } else { | ||
| 8399 | |||
| 8400 | # Hide the tooltips window | ||
| 8401 | $self->hideTooltips(); | ||
| 8402 | } | ||
| 8403 | } | ||
| 8404 | } | ||
| 8405 | } | ||
| 8406 | |||
| 8407 | # If there's no link tooltip visible, consider showing the session tooltip instead | ||
| 8408 | if ($axmud::CLIENT->mainWinTooltipFlag && ! $tooltipsFlag && ! $self->currentLinkObj) { | ||
| 8409 | |||
| 8410 | # Only lines created by the GA::Session, and displayed in its default textview object, | ||
| 8411 | # cause key-value pairs to be added to this hash | ||
| 8412 | # NB The Gtk3::Textbuffer renumbers its line every time we delete one from the | ||
| 8413 | # beginning of the buffer, so here we must add $self->nextDeleteLine | ||
| 8414 | if ($self->ivExists('tooltipHash', ($lineNum + $self->nextDeleteLine))) { | ||
| 8415 | |||
| 8416 | $self->showSessionTooltips($lineNum + $self->nextDeleteLine); | ||
| 8417 | |||
| 8418 | } elsif ($self->lastTooltipLine) { | ||
| 8419 | |||
| 8420 | $self->hideTooltips(); | ||
| 8421 | } | ||
| 8422 | } | ||
| 8423 | |||
| 8424 | return 1; | ||
| 8425 | } | ||
| 8426 | |||
| 8427 | sub updateVisibleSize { | ||
| 8428 | |||
| 8429 | # Called by Games::Axmud::Obj::Desktop->updateWidgets (only) for any textview object whose | ||
| 8430 | # ->sizeUpdateFlag is set | ||
| 8431 | # Updates IVs and informs the GA::Session | ||
| 8432 | # | ||
| 8433 | # Expected arguments | ||
| 8434 | # (none besides $self) | ||
| 8435 | # | ||
| 8436 | # Return values | ||
| 8437 | # 'undef' on improper arguments | ||
| 8438 | # 1 otherwise | ||
| 8439 | |||
| 8440 | my ($self, $check) = @_; | ||
| 8441 | |||
| 8442 | # Local variables | ||
| 8443 | my ($charWidth, $charHeight, $hashRef, $textViewWidth, $textViewHeight); | ||
| 8444 | |||
| 8445 | # Check for improper arguments | ||
| 8446 | if (defined $check) { | ||
| 8447 | |||
| 8448 | return $axmud::CLIENT->writeImproper($self->_objClass . '->updateVisibleSize', @_); | ||
| 8449 | } | ||
| 8450 | |||
| 8451 | # Do nothing while split screen mode is on | ||
| 8452 | if ($self->splitScreenMode ne 'split') { | ||
| 8453 | |||
| 8454 | # Get the width/height of a character in the Gtk3::TextView | ||
| 8455 | ($charWidth, $charHeight) = $self->getCharSize(); | ||
| 8456 | # Get a Gtk3::Gdk::Rectangle | ||
| 8457 | $hashRef = $self->textView->get_visible_rect(); | ||
| 8458 | # Get the size of the textview | ||
| 8459 | $textViewWidth = int($$hashRef{width} / $charWidth); | ||
| 8460 | $textViewHeight = int($$hashRef{height} / $charHeight); | ||
| 8461 | |||
| 8462 | if ( | ||
| 8463 | ! defined $self->textWidthChars | ||
| 8464 | || $textViewWidth != $self->textWidthChars | ||
| 8465 | || $textViewHeight != $self->textHeightChars | ||
| 8466 | ) { | ||
| 8467 | # The size has changed. Update IVs... | ||
| 8468 | $self->ivPoke('textWidthChars', $textViewWidth); | ||
| 8469 | $self->ivPoke('textHeightChars', $textViewHeight); | ||
| 8470 | # ...and inform the parent GA::Session | ||
| 8471 | $self->session->textViewSizeUpdate($self); | ||
| 8472 | } | ||
| 8473 | } | ||
| 8474 | |||
| 8475 | $self->ivPoke('sizeUpdateFlag', FALSE); | ||
| 8476 | |||
| 8477 | return 1; | ||
| 8478 | } | ||
| 8479 | |||
| 8480 | sub getCharSize { | ||
| 8481 | |||
| 8482 | # Called by $self->updateVisibleSize | ||
| 8483 | # Gets the size (in pixels) of a single character in the Gtk3::TextView | ||
| 8484 | # | ||
| 8485 | # Expected arguments | ||
| 8486 | # (none besides $self) | ||
| 8487 | # | ||
| 8488 | # Optional arguments | ||
| 8489 | # $char - The character whose size should be found. If 'undef', the character 'w' | ||
| 8490 | # is tested | ||
| 8491 | # | ||
| 8492 | # Return values | ||
| 8493 | # An empty list on improper arguments | ||
| 8494 | # Otherwise returns a list in the form (width_pixels, height_pixels) | ||
| 8495 | |||
| 8496 | my ($self, $char, $check) = @_; | ||
| 8497 | |||
| 8498 | # Local variables | ||
| 8499 | my ( | ||
| 8500 | $layout, $inkRect, $logicalRect, | ||
| 8501 | @emptyList, | ||
| 8502 | ); | ||
| 8503 | |||
| 8504 | # Check for improper arguments | ||
| 8505 | if (defined $check) { | ||
| 8506 | |||
| 8507 | $axmud::CLIENT->writeImproper($self->_objClass . '->getCharSize', @_); | ||
| 8508 | return @emptyList; | ||
| 8509 | } | ||
| 8510 | |||
| 8511 | if (! $char) { | ||
| 8512 | |||
| 8513 | $char = 'w'; | ||
| 8514 | } | ||
| 8515 | |||
| 8516 | # Get the Pango::Layout representing the character in this session's textview | ||
| 8517 | $layout = $self->textView->create_pango_layout($char); | ||
| 8518 | |||
| 8519 | # Get the width/height of the character | ||
| 8520 | ($inkRect, $logicalRect) = $layout->get_pixel_extents(); | ||
| 8521 | |||
| 8522 | return ($$logicalRect{'width'}, $$logicalRect{'height'}); | ||
| 8523 | } | ||
| 8524 | |||
| 8525 | sub getLineLength { | ||
| 8526 | |||
| 8527 | # For reasons unknown, calls to Gtk3::TextIter->get_chars_in_line returns the actual number | ||
| 8528 | # of characters in a line, plus 10,000 | ||
| 8529 | # Return the number of characters in a line, subtracting 10,000 if necessary | ||
| 8530 | # | ||
| 8531 | # Expected arguments | ||
| 8532 | # $iter - A Gtk3::TextIter anywhere on the line | ||
| 8533 | # | ||
| 8534 | # Return values | ||
| 8535 | # 'undef' on improper arguments | ||
| 8536 | # Otherwise returns the (real) number of characters on the line | ||
| 8537 | |||
| 8538 | my ($self, $iter, $check) = @_; | ||
| 8539 | |||
| 8540 | # Local variables | ||
| 8541 | my $count; | ||
| 8542 | |||
| 8543 | # Check for improper arguments | ||
| 8544 | if (! defined $iter || defined $check) { | ||
| 8545 | |||
| 8546 | return $axmud::CLIENT->writeImproper($self->_objClass . '->getLineLength', @_); | ||
| 8547 | } | ||
| 8548 | |||
| 8549 | $count = $iter->get_chars_in_line(); | ||
| 8550 | if ($count >= 10000) { | ||
| 8551 | |||
| 8552 | $count -= 10000; | ||
| 8553 | } | ||
| 8554 | |||
| 8555 | return $count; | ||
| 8556 | } | ||
| 8557 | |||
| 8558 | sub setupLink { | ||
| 8559 | |||
| 8560 | # Called by $self->insertText and ->showSystemText | ||
| 8561 | # Just before a clickable link is displayed in the textview, creates a GA::Obj::Link (or | ||
| 8562 | # amends an existing one) to store data until the user clicks on the link | ||
| 8563 | # | ||
| 8564 | # Expected arguments | ||
| 8565 | # $iter - The Gtk3::TextIter marking the position in the Gtk3::TextBuffer | ||
| 8566 | # (stored in $self->buffer) at which the link will be displayed | ||
| 8567 | # $text - The text of the link itself | ||
| 8568 | # | ||
| 8569 | # Return values | ||
| 8570 | # 'undef' on improper arguments or if the link can't be created/amended | ||
| 8571 | # 1 otherwise | ||
| 8572 | |||
| 8573 | my ($self, $iter, $text, $check) = @_; | ||
| 8574 | |||
| 8575 | # Local variables | ||
| 8576 | my ($lineNum, $posn, $short, $email, $type, $listRef, $objNum, $linkObj); | ||
| 8577 | |||
| 8578 | # Check for improper arguments | ||
| 8579 | if (! defined $iter || ! defined $text || defined $check) { | ||
| 8580 | |||
| 8581 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setupLink', @_); | ||
| 8582 | } | ||
| 8583 | |||
| 8584 | # Get the position of the start of the link. If the buffer is full, take account of any | ||
| 8585 | # lines that have been deleted from the start of it | ||
| 8586 | $lineNum = $iter->get_line() + $self->nextDeleteLine; | ||
| 8587 | $posn = $iter->get_line_offset(); | ||
| 8588 | |||
| 8589 | # Check $text to see if it matches the start of an acceptable link, in the form | ||
| 8590 | # http://deathmud.org - a URL opened by GA::Client->browserCmd | ||
| 8591 | # deathmud.org - a URL opened by GA::Client->browserCmd | ||
| 8592 | # mailto:god@deathmud.org - an email sent by GA::Client->emailCmd | ||
| 8593 | # admin@deathmud.org - an email sent by GA::Client->emailCmd | ||
| 8594 | # telnet://deathmud.org:6666 - a new connection to a world, using telnet | ||
| 8595 | # telnet://deathmud.org - a new connection to a world, port 23 | ||
| 8596 | # ssh://deathmud.org:6666 - a new connection to a world, using SSH | ||
| 8597 | # ssh://deathmud.org - a new connection to a world, generic port | ||
| 8598 | # ssl://deathmud.org:6666 - a new connection to a world, using SSL | ||
| 8599 | # ssl://deathmud.org - a new connection to a world, generic port | ||
| 8600 | # NB We don't check against GA::Client->constUrlRegex, etc, because $text might not contain | ||
| 8601 | # the whole link, but we do check against GA::Client->constShortUrlRegex and against an | ||
| 8602 | # email link without the mailto: part, in the hope that it was probably displayed by a | ||
| 8603 | # single call to $self->insertText, etc | ||
| 8604 | # NB This function isn't used for MXP links, for which a GA::Obj::Link has already been | ||
| 8605 | # created | ||
| 8606 | $short = '^' . $axmud::CLIENT->constShortUrlRegex; | ||
| 8607 | $email = '^' . $axmud::CLIENT->constEmailRegex; | ||
| 8608 | |||
| 8609 | # (Check email first, otherwise gmail.com is detected and fred@gmail.com isn't) | ||
| 8610 | if ($text =~ m/^mailto\:/i || $text =~ m/$email/i) { | ||
| 8611 | |||
| 8612 | $type = 'mail'; | ||
| 8613 | |||
| 8614 | } elsif ( | ||
| 8615 | $text =~ m/^https?\:\/\//i | ||
| 8616 | || ($axmud::CLIENT->shortUrlFlag && $text =~ m/$short/i) | ||
| 8617 | ) { | ||
| 8618 | $type = 'www'; | ||
| 8619 | |||
| 8620 | } elsif ($text =~ m/^telnet\:\/\//i) { | ||
| 8621 | |||
| 8622 | $type = 'telnet'; | ||
| 8623 | |||
| 8624 | } elsif ($text =~ m/^ssh\:\/\//i) { | ||
| 8625 | |||
| 8626 | $type = 'ssh'; | ||
| 8627 | |||
| 8628 | } elsif ($text =~ m/^ssl\:\/\//i) { | ||
| 8629 | |||
| 8630 | $type = 'ssl'; | ||
| 8631 | |||
| 8632 | } else { | ||
| 8633 | |||
| 8634 | # This shouldn't happen | ||
| 8635 | $type = 'other'; | ||
| 8636 | } | ||
| 8637 | |||
| 8638 | # A single link may be created by one or more successive calls to $self->insertText (etc). | ||
| 8639 | # If $text isn't the start of a link, we will be looking to add it to the end of an | ||
| 8640 | # existing link | ||
| 8641 | # This textview object stores its own list of GA::Obj::Link objects which apply to the | ||
| 8642 | # current insertion point; a hash in the form | ||
| 8643 | # ->linkObjLineHash{line} = reference_to_list_of_GA::Obj::Link_objects | ||
| 8644 | $listRef = $self->ivShow('linkObjLineHash', $lineNum); | ||
| 8645 | |||
| 8646 | if (defined $listRef) { | ||
| 8647 | |||
| 8648 | # Check each GA::Obj::Link object in turn. If there's one which ends at $posn, we'll | ||
| 8649 | # need to check if $text is part of the same link, or the start of a new link | ||
| 8650 | # (Don't need to check MXP links, which are always created whole) | ||
| 8651 | OUTER: foreach my $obj (@$listRef) { | ||
| 8652 | |||
| 8653 | my $endPosn = $obj->posn + length ($obj->text); | ||
| 8654 | if (! $obj->mxpFlag && $endPosn == $posn) { | ||
| 8655 | |||
| 8656 | # $text is almost certainly part of the previous link | ||
| 8657 | $linkObj = $obj; | ||
| 8658 | # (->href and ->text are the same for non-MXP links) | ||
| 8659 | $linkObj->ivPoke('href', $obj->href . $text); | ||
| 8660 | $linkObj->ivPoke('text', $obj->text . $text); | ||
| 8661 | last OUTER; | ||
| 8662 | } | ||
| 8663 | } | ||
| 8664 | } | ||
| 8665 | |||
| 8666 | if (! $linkObj) { | ||
| 8667 | |||
| 8668 | # Create a new GA::Obj::Link object | ||
| 8669 | $linkObj = $self->add_link($lineNum, $posn, $type); | ||
| 8670 | if (! $linkObj) { | ||
| 8671 | |||
| 8672 | return undef; | ||
| 8673 | } | ||
| 8674 | |||
| 8675 | # (For non-MXP links, ->href and ->text are the same) | ||
| 8676 | $linkObj->ivPoke('href', $text); | ||
| 8677 | $linkObj->ivPoke('text', $text); | ||
| 8678 | } | ||
| 8679 | |||
| 8680 | return 1; | ||
| 8681 | } | ||
| 8682 | |||
| 8683 | sub createMxpStackObj { | ||
| 8684 | |||
| 8685 | # Called by GA::Session->processMxpModalElement | ||
| 8686 | # Creates an mxp stack object (GA::Mxp::StackObj) and adds it to this textview's stack | ||
| 8687 | # | ||
| 8688 | # Expected arguments | ||
| 8689 | # $session - The calling GA::Session | ||
| 8690 | # $keyword - The MXP element keyword (already converted to upper case) | ||
| 8691 | # | ||
| 8692 | # Optional arguments | ||
| 8693 | # %stackHash - A hash of key-value pairs which updates $self->mxpModalStackHash by | ||
| 8694 | # replacing one or more of its key-value pairs (might be an empty | ||
| 8695 | # hash) | ||
| 8696 | # | ||
| 8697 | # Return values | ||
| 8698 | # 'undef' on improper arguments or if the stack object can't be created | ||
| 8699 | # Blessed reference to the newly-created object on success | ||
| 8700 | |||
| 8701 | my ($self, $session, $keyword, %stackHash) = @_; | ||
| 8702 | |||
| 8703 | # Local variables | ||
| 8704 | my $stackObj; | ||
| 8705 | |||
| 8706 | # Check for improper arguments | ||
| 8707 | if (! defined $session || ! defined $keyword) { | ||
| 8708 | |||
| 8709 | return $axmud::CLIENT->writeImproper($self->_objClass . '->createMxpStackObj', @_); | ||
| 8710 | } | ||
| 8711 | |||
| 8712 | # Create a new MXP stack object which preserves current MXP text attributes, just before we | ||
| 8713 | # update $self->mxpModalStackHash | ||
| 8714 | $stackObj = Games::Axmud::Mxp::StackObj->new($session, $keyword, $self->mxpModalStackHash); | ||
| 8715 | if (! $stackObj ) { | ||
| 8716 | |||
| 8717 | return undef; | ||
| 8718 | } | ||
| 8719 | |||
| 8720 | # Update IVs | ||
| 8721 | $self->ivPush('mxpModalStackList', $stackObj); | ||
| 8722 | |||
| 8723 | # Apply the new text attributes specified by %stackHash | ||
| 8724 | foreach my $key (keys %stackHash) { | ||
| 8725 | |||
| 8726 | $self->ivAdd('mxpModalStackHash', $key, $stackHash{$key}); | ||
| 8727 | } | ||
| 8728 | |||
| 8729 | return $stackObj; | ||
| 8730 | } | ||
| 8731 | |||
| 8732 | sub interpretTags { | ||
| 8733 | |||
| 8734 | # Called by $self->insertText and ->showSystemText | ||
| 8735 | # Interprets a list of arguments passed to those functions, including Axmud colour and style | ||
| 8736 | # tags and some additional strings for implementing newline characters and clearing the | ||
| 8737 | # buffer | ||
| 8738 | # For RGB colour tags (e.g. '#FFFFFF' and 'u#FFFFFF'), a new Gtk3::TextTag is created, if | ||
| 8739 | # one does not already exist | ||
| 8740 | # Duplicate arguments are ignored. Only the first text colour tag (if any) is used, and only | ||
| 8741 | # the first underlay colour tag (if any) is used. Unrecognised tags are ignored | ||
| 8742 | # | ||
| 8743 | # Expected arguments | ||
| 8744 | # $newLineDefault - The default behaviour for newline characters, if no behaviour is | ||
| 8745 | # specified in @args: 'before' prepends a newline character to the | ||
| 8746 | # text, 'after'/'nl' appends a newline character to the text, 'echo' | ||
| 8747 | # does not prepend/append a newline character at all | ||
| 8748 | # | ||
| 8749 | # Optional arguments | ||
| 8750 | # @args - The list of arguments to interpret, in any order: | ||
| 8751 | # - 'empty' (empties the buffer before writing text) | ||
| 8752 | # - 'before' (prepends a newline character to the text) | ||
| 8753 | # - 'after' or 'nl' (appends a newline character to $text) | ||
| 8754 | # - 'echo' (does not prepend/append a newline character, overrides | ||
| 8755 | # 'before', 'after' and 'nl' if they are specified) | ||
| 8756 | # - one or more Axmud colour tags. Only the first text colour (e.g. 'red') | ||
| 8757 | # is used, and only the first underlay colour ('UL_RED') is used. | ||
| 8758 | # The range of Axmud colour tags include: | ||
| 8759 | # - standard colour tags like 'red', 'BLUE', 'ul_red', 'UL_BLUE' | ||
| 8760 | # (case-sensititive) | ||
| 8761 | # - xterm colour tags (strings in the range 'x0' to 'x255', or | ||
| 8762 | # 'ux0' to 'ux255'; case-insensitive, so 'X0' is valid) | ||
| 8763 | # - RGB colour tags (strings in the range '#000000' to '#FFFFFF', or | ||
| 8764 | # 'u#000000' to 'u#FFFFFF'; case-insensitive, so 'U#AbCdEf' is | ||
| 8765 | # valid) | ||
| 8766 | # - one or more Axmud style tags ('italics', 'strike', 'link' etc) | ||
| 8767 | # | ||
| 8768 | # Return values | ||
| 8769 | # An empty list on improper arguments | ||
| 8770 | # Otherwise returns a list in the form | ||
| 8771 | # ( | ||
| 8772 | # $emptyFlag, $beforeFlag, $afterFlag, $linkFlag, $textColour, $underlayColour, | ||
| 8773 | # @styleTags, | ||
| 8774 | # ) | ||
| 8775 | # ...where the flags are set to TRUE or FALSE, $textColour is set to the first text | ||
| 8776 | # colour tag found (or 'undef' if none are found), $underlayColour is set to the | ||
| 8777 | # first underlay colour tag found (or 'undef' if none are found), and @styleTags | ||
| 8778 | # contains a list of Axmud style tags (an empty list if none are found) | ||
| 8779 | # NB If the 'link' style tag appears in @args, then $linkFlag will be TRUE, and the style | ||
| 8780 | # tag will also appear in @styleTags | ||
| 8781 | |||
| 8782 | my ($self, $newLineDefault, @args) = @_; | ||
| 8783 | |||
| 8784 | # Local variables | ||
| 8785 | my ( | ||
| 8786 | $emptyFlag, $beforeFlag, $afterFlag, $echoFlag, $linkFlag, $textColour, $underlayColour, | ||
| 8787 | $mxpfFlag, $relatedFlag, | ||
| 8788 | @styleTags, | ||
| 8789 | %styleHash, | ||
| 8790 | ); | ||
| 8791 | |||
| 8792 | # Check for improper arguments | ||
| 8793 | if (! defined $newLineDefault) { | ||
| 8794 | |||
| 8795 | return $axmud::CLIENT->writeImproper($self->_objClass . '->interpretTags', @_); | ||
| 8796 | } | ||
| 8797 | |||
| 8798 | # The flags are FALSE by default ($newLineDefault is applied at the end, if necessary) | ||
| 8799 | $emptyFlag = FALSE; | ||
| 8800 | $beforeFlag = FALSE; | ||
| 8801 | $afterFlag = FALSE; | ||
| 8802 | $echoFlag = FALSE; | ||
| 8803 | $linkFlag = FALSE; | ||
| 8804 | |||
| 8805 | foreach my $item (@args) { | ||
| 8806 | |||
| 8807 | my ( | ||
| 8808 | $first, $second, $fontString, $spacing, $tag, $type, $underlayFlag, | ||
| 8809 | @wordList, | ||
| 8810 | ); | ||
| 8811 | |||
| 8812 | $first = lc(substr($item, 0, 1)); | ||
| 8813 | $second = lc(substr($item, 0, 2)); | ||
| 8814 | |||
| 8815 | if ($item eq 'empty') { | ||
| 8816 | |||
| 8817 | $emptyFlag = TRUE; | ||
| 8818 | $relatedFlag = TRUE; | ||
| 8819 | |||
| 8820 | } elsif ($item eq 'before') { | ||
| 8821 | |||
| 8822 | $beforeFlag = TRUE; | ||
| 8823 | $relatedFlag = TRUE; | ||
| 8824 | |||
| 8825 | } elsif ($item eq 'after' || $item eq 'nl') { | ||
| 8826 | |||
| 8827 | $afterFlag = TRUE; | ||
| 8828 | $relatedFlag = TRUE; | ||
| 8829 | |||
| 8830 | } elsif ($item eq 'echo') { | ||
| 8831 | |||
| 8832 | $echoFlag = TRUE; | ||
| 8833 | $relatedFlag = TRUE; | ||
| 8834 | |||
| 8835 | } elsif ($axmud::CLIENT->ivExists('constStyleTagHash', $item)) { | ||
| 8836 | |||
| 8837 | # It's an Axmud style tag (not including dummy style tags). Ignore duplicate style | ||
| 8838 | # tags | ||
| 8839 | if (! exists $styleHash{$item}) { | ||
| 8840 | |||
| 8841 | push (@styleTags, $item); | ||
| 8842 | $styleHash{$item} = undef; | ||
| 8843 | |||
| 8844 | if ($item eq 'link' && $self->allowLinkFlag) { | ||
| 8845 | |||
| 8846 | # (As well as adding the tag to @styleTags, set a flag; this saves a bit of | ||
| 8847 | # time for the calling function) | ||
| 8848 | $linkFlag = TRUE; | ||
| 8849 | } | ||
| 8850 | } | ||
| 8851 | |||
| 8852 | } elsif (substr($item, 0, 5) eq 'mxpf_') { | ||
| 8853 | |||
| 8854 | # It's a dummy style tag in the form 'mxpf_monospace_bold_12_p5', containing one or | ||
| 8855 | # more of the following, separated by underlines: the font name (e.g. | ||
| 8856 | # 'monospace'), a font name modifier (e.g. 'bold'), the font size (e.g. '12') and | ||
| 8857 | # the pixel spacing above and below the text (used for MXP HTML headings, e.g. | ||
| 8858 | # 'p5'; when not specified, a spacing of 0 is used) | ||
| 8859 | # Ignore duplicate 'mxpf_' tags | ||
| 8860 | if (! $mxpfFlag) { | ||
| 8861 | |||
| 8862 | # If a Gtk3::TextTag for this exact combination of fonts and font sizes doesn't | ||
| 8863 | # exist, create a new one | ||
| 8864 | if (! $self->buffer->get_tag_table->lookup($item)) { | ||
| 8865 | |||
| 8866 | # Remove the 'mxpf' and replace underlines with whitespace, getting | ||
| 8867 | # something like 'monospace bold 12 p5' | ||
| 8868 | $fontString = substr($item, 5); | ||
| 8869 | $fontString =~ s/\_/ /g; | ||
| 8870 | |||
| 8871 | # The default pixel spacing is 0 (only MXP HTML headings need more) | ||
| 8872 | $spacing = 0; | ||
| 8873 | # Remove the pixel spacing component, if it was specified. Use only the | ||
| 8874 | # first one; ignore any subsequent ones | ||
| 8875 | foreach my $word (split(/\s+/, $fontString)) { | ||
| 8876 | |||
| 8877 | if ($word =~ m/^p(\d+)$/) { | ||
| 8878 | |||
| 8879 | # (Ignore subsequent spacings) | ||
| 8880 | if (! $spacing) { | ||
| 8881 | |||
| 8882 | $spacing = $1; | ||
| 8883 | } | ||
| 8884 | |||
| 8885 | } else { | ||
| 8886 | |||
| 8887 | push (@wordList, $word); | ||
| 8888 | } | ||
| 8889 | } | ||
| 8890 | |||
| 8891 | $fontString = join(' ', @wordList); | ||
| 8892 | |||
| 8893 | $self->buffer->create_tag( | ||
| 8894 | $item, # e.g. 'mxpf_monospace_bold_12' | ||
| 8895 | 'font' => $fontString, # e.g. 'monospace bold 12' | ||
| 8896 | 'pixels-above-lines' => $spacing, # e.g. 5 | ||
| 8897 | 'pixels-below-lines' => $spacing, # e.g. 5 | ||
| 8898 | ); | ||
| 8899 | } | ||
| 8900 | |||
| 8901 | push (@styleTags, $item); | ||
| 8902 | $mxpfFlag = TRUE; | ||
| 8903 | } | ||
| 8904 | |||
| 8905 | } elsif ($second eq 'ux') { | ||
| 8906 | |||
| 8907 | # It's an xterm colour tag for the underlay. Check that it's valid before using it | ||
| 8908 | # (and ignore an additional underlay colour, if one has already been specified) | ||
| 8909 | if (! $underlayColour) { | ||
| 8910 | |||
| 8911 | $tag = substr($item, 1); # Strip away the initial 'u' | ||
| 8912 | if ($axmud::CLIENT->ivExists('xTermColourHash', lc($tag))) { | ||
| 8913 | |||
| 8914 | # (xterm colour tags are lower-case, by default) | ||
| 8915 | $underlayColour = lc($item); | ||
| 8916 | } | ||
| 8917 | } | ||
| 8918 | |||
| 8919 | } elsif ($first eq 'x') { | ||
| 8920 | |||
| 8921 | # It's an xterm colour tag for text. Check that it's valid before using it | ||
| 8922 | # (and ignore an additional text colour, if one has already been specified) | ||
| 8923 | if (! $textColour && $axmud::CLIENT->ivExists('xTermColourHash', lc($item))) { | ||
| 8924 | |||
| 8925 | # (xterm colour tags are lower-case, by default) | ||
| 8926 | $textColour = lc($item); | ||
| 8927 | } | ||
| 8928 | |||
| 8929 | } elsif ($second eq 'u#') { | ||
| 8930 | |||
| 8931 | # It's an RGB colour tag for the underlay | ||
| 8932 | if (! $underlayColour) { | ||
| 8933 | |||
| 8934 | $tag = substr($item, 1); # Strip away the initial 'u' | ||
| 8935 | if ($tag =~ m/^\#[A-Fa-f0-9]{6}$/) { | ||
| 8936 | |||
| 8937 | # (Gtk3 expects an upper-case string like '#FFFFFF') | ||
| 8938 | $underlayColour = 'u' . uc($tag); | ||
| 8939 | # There are 16.7 million possible RGB colour tags, so we take the pragmatic | ||
| 8940 | # approach and create a Gtk3::TextTag for each one, only when it is needed | ||
| 8941 | if (! $self->buffer->get_tag_table->lookup($underlayColour)) { | ||
| 8942 | |||
| 8943 | $self->buffer->create_tag( | ||
| 8944 | $underlayColour, # e.g. 'u#FFFFFF' | ||
| 8945 | 'background' => uc($tag), # e.g. '#FFFFFF' | ||
| 8946 | ); | ||
| 8947 | } | ||
| 8948 | } | ||
| 8949 | } | ||
| 8950 | |||
| 8951 | } elsif ($first eq '#') { | ||
| 8952 | |||
| 8953 | # It's an RGB colour tag for text | ||
| 8954 | if (! $textColour && $item =~ m/^\#[A-Fa-f0-9]{6}$/) { | ||
| 8955 | |||
| 8956 | # (Gtk3 expects an upper-case string like '#FFFFFF') | ||
| 8957 | $textColour = uc($item); | ||
| 8958 | # There are 16.7 million possible RGB colour tags, so we take the pragmatic | ||
| 8959 | # approach and create a Gtk3::TextTag for each one, only when it is needed | ||
| 8960 | if (! $self->buffer->get_tag_table->lookup($textColour)) { | ||
| 8961 | |||
| 8962 | $self->buffer->create_tag( | ||
| 8963 | $textColour, # e.g. '#FFFFFF' | ||
| 8964 | 'foreground' => $textColour, # e.g. '#FFFFFF' | ||
| 8965 | ); | ||
| 8966 | } | ||
| 8967 | } | ||
| 8968 | |||
| 8969 | } else { | ||
| 8970 | |||
| 8971 | # It's presumably an Axmud colour tag | ||
| 8972 | ($type, $underlayFlag) = $axmud::CLIENT->checkColourTags($item, 'standard'); | ||
| 8973 | if ($type) { | ||
| 8974 | |||
| 8975 | # (Only use the first underlay colour tag) | ||
| 8976 | if ($underlayFlag && ! $underlayColour) { | ||
| 8977 | |||
| 8978 | $underlayColour = $item; | ||
| 8979 | |||
| 8980 | } elsif (! $underlayFlag && ! $textColour) { | ||
| 8981 | |||
| 8982 | $textColour = $item; | ||
| 8983 | } | ||
| 8984 | } | ||
| 8985 | } | ||
| 8986 | } | ||
| 8987 | |||
| 8988 | # 'echo' overrides 'before', 'after' and 'nl', it specified | ||
| 8989 | if ($echoFlag) { | ||
| 8990 | |||
| 8991 | $beforeFlag = FALSE; | ||
| 8992 | $afterFlag = FALSE; | ||
| 8993 | } | ||
| 8994 | |||
| 8995 | # If none of 'before', 'after' and 'echo' were specified, use the default behaviour | ||
| 8996 | if (! $relatedFlag) { | ||
| 8997 | |||
| 8998 | if ($newLineDefault eq 'echo') { | ||
| 8999 | $echoFlag = TRUE; | ||
| 9000 | } elsif ($newLineDefault eq 'before') { | ||
| 9001 | $beforeFlag = TRUE; | ||
| 9002 | } elsif ($newLineDefault eq 'after' || $newLineDefault eq 'nl') { | ||
| 9003 | $afterFlag = TRUE; | ||
| 9004 | } | ||
| 9005 | } | ||
| 9006 | |||
| 9007 | return ( | ||
| 9008 | $emptyFlag, $beforeFlag, $afterFlag, $linkFlag, $textColour, $underlayColour, | ||
| 9009 | @styleTags, | ||
| 9010 | ); | ||
| 9011 | } | ||
| 9012 | |||
| 9013 | sub modifyColourTags { | ||
| 9014 | |||
| 9015 | # Called by $self->insertText after an earlier call to $self->interpretTags | ||
| 9016 | # Imports the colour scheme in use, then applies any colour overrides specified by that | ||
| 9017 | # colour scheme or by this object's own monochrome mode | ||
| 9018 | # | ||
| 9019 | # Expected arguments | ||
| 9020 | # (none besides $self) | ||
| 9021 | # | ||
| 9022 | # Optional arguments | ||
| 9023 | # $textColour - The text colour tag that's going to be inserted into the | ||
| 9024 | # Gtk3::TextView (or 'undef' if no colour tag is going to be used) | ||
| 9025 | # $underlayColour - The underlay colour tag that's going to be inserted into the | ||
| 9026 | # Gtk3::TextView (or 'undef' if no colour tag is going to be used) | ||
| 9027 | # | ||
| 9028 | # Return values | ||
| 9029 | # An empty list on improper arguments | ||
| 9030 | # Otherwise returns a list in the form | ||
| 9031 | # (monochrome_flag, text_colour, underlay_colour) | ||
| 9032 | # ...where 'text_colour' and 'underlay_colour' are the modified (or unmodified) values, | ||
| 9033 | # and 'monochrome_flag' is TRUE is no colours can be used at all, FALSE otherwise | ||
| 9034 | |||
| 9035 | my ($self, $textColour, $underlayColour, $check) = @_; | ||
| 9036 | |||
| 9037 | # Local variables | ||
| 9038 | my ( | ||
| 9039 | $colourSchemeObj, $monochromeFlag, | ||
| 9040 | @emptyList, | ||
| 9041 | ); | ||
| 9042 | |||
| 9043 | # Check for improper arguments | ||
| 9044 | if (defined $check) { | ||
| 9045 | |||
| 9046 | $axmud::CLIENT->writeImproper($self->_objClass . '->insertWithTags', @_); | ||
| 9047 | return @emptyList; | ||
| 9048 | } | ||
| 9049 | |||
| 9050 | # Import the colour scheme in use | ||
| 9051 | $colourSchemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $self->colourScheme); | ||
| 9052 | # Apply any colour overrides specified by the colour scheme or by this object's own | ||
| 9053 | # monochrome mode | ||
| 9054 | if ($self->monochromeFlag || ($colourSchemeObj && $colourSchemeObj->overrideAllFlag)) { | ||
| 9055 | |||
| 9056 | $monochromeFlag = TRUE; | ||
| 9057 | |||
| 9058 | } else { | ||
| 9059 | |||
| 9060 | $monochromeFlag = FALSE; | ||
| 9061 | |||
| 9062 | if ($colourSchemeObj) { | ||
| 9063 | |||
| 9064 | if ( | ||
| 9065 | defined $textColour | ||
| 9066 | && $colourSchemeObj->ivExists('overrideHash', $textColour) | ||
| 9067 | ) { | ||
| 9068 | $textColour = $colourSchemeObj->ivShow('overrideHash', $textColour); | ||
| 9069 | } | ||
| 9070 | |||
| 9071 | if ( | ||
| 9072 | defined $underlayColour | ||
| 9073 | && $colourSchemeObj->ivExists('overrideHash', $underlayColour) | ||
| 9074 | ) { | ||
| 9075 | $underlayColour = $colourSchemeObj->ivShow('overrideHash', $underlayColour); | ||
| 9076 | } | ||
| 9077 | } | ||
| 9078 | } | ||
| 9079 | |||
| 9080 | return ($monochromeFlag, $textColour, $underlayColour); | ||
| 9081 | } | ||
| 9082 | |||
| 9083 | sub insertWithTags { | ||
| 9084 | |||
| 9085 | # Called by $self->insertText, ->insertCmd, ->showSystemText, ->showError, ->showWarning, | ||
| 9086 | # ->showDebug, ->showImproper and ->showImage | ||
| 9087 | # Inserts some text and (optionally) colour and style tags into the Gtk3::TextBuffer | ||
| 9088 | # | ||
| 9089 | # Expected arguments | ||
| 9090 | # $iter - The Gtk3::TextIter, representing the point in the buffer at which the text | ||
| 9091 | # is inserted | ||
| 9092 | # $text - A string consisting of 0, 1 or more characters which aren't newline | ||
| 9093 | # characters | ||
| 9094 | # | ||
| 9095 | # Optional arguments | ||
| 9096 | # @tags - A list of Axmud colour/style tags that apply to the whole of $text, but | ||
| 9097 | # not necessarily any text that was inserted before it (or will be | ||
| 9098 | # inserted after it). Can be an empty list | ||
| 9099 | # | ||
| 9100 | # Return values | ||
| 9101 | # 'undef' on improper arguments | ||
| 9102 | # Otherwise returns the Gtk3::TextIter immediately after the inserted text (which might be | ||
| 9103 | # the end of the textbuffer, or not) | ||
| 9104 | |||
| 9105 | my ($self, $iter, $text, @tags) = @_; | ||
| 9106 | |||
| 9107 | # Local variables | ||
| 9108 | my ($lineNum, $posn, $endIter, $length, $stopPosn, $stopIter, $newIter, $newLength); | ||
| 9109 | |||
| 9110 | # Check for improper arguments | ||
| 9111 | if (! defined $iter || ! defined $text) { | ||
| 9112 | |||
| 9113 | return $axmud::CLIENT->writeImproper($self->_objClass . '->insertWithTags', @_); | ||
| 9114 | } | ||
| 9115 | |||
| 9116 | # Get the iter's position in the textview buffer | ||
| 9117 | $lineNum = $iter->get_line(); | ||
| 9118 | $posn = $iter->get_visible_line_offset(); | ||
| 9119 | |||
| 9120 | # Strip any newline characters ($text shouldn't contain any, but we'll check anyway) | ||
| 9121 | # Also strip any null chars (in the text length calculations below, they have a length of | ||
| 9122 | # both 0 and 1, which causes an Axmud crash) | ||
| 9123 | $text =~ s/[\n\r\x00]//; | ||
| 9124 | |||
| 9125 | # # Insert the text and tags into the Gtk3::TextBuffer | ||
| 9126 | # $self->buffer->insert_with_tags_by_name($iter, $text, @tags); | ||
| 9127 | # Gtk overwrite mode doesn't work (for some reason), so we're forced to implement our own | ||
| 9128 | # overwrite mode by deleting existing text before inserting new text | ||
| 9129 | $endIter = $self->buffer->get_end_iter(); | ||
| 9130 | if ($self->overwriteFlag && $iter ne $endIter) { | ||
| 9131 | |||
| 9132 | my ($length, $stopPosn, $stopIter); | ||
| 9133 | |||
| 9134 | $length = $self->getLineLength($iter); | ||
| 9135 | $stopPosn = $posn + length($text); | ||
| 9136 | if ($endIter->get_line() == $iter->get_line()) { | ||
| 9137 | |||
| 9138 | if ($stopPosn > $length) { | ||
| 9139 | |||
| 9140 | $stopPosn = $length; | ||
| 9141 | } | ||
| 9142 | |||
| 9143 | } else { | ||
| 9144 | |||
| 9145 | if (! $length) { | ||
| 9146 | |||
| 9147 | $stopPosn = $length; | ||
| 9148 | |||
| 9149 | } elsif ($stopPosn >= $length) { | ||
| 9150 | |||
| 9151 | $stopPosn = $length - 1; | ||
| 9152 | } | ||
| 9153 | } | ||
| 9154 | |||
| 9155 | $stopIter = $self->buffer->get_iter_at_line_offset($lineNum, $stopPosn); | ||
| 9156 | if ($stopIter ne $endIter) { | ||
| 9157 | |||
| 9158 | $self->buffer->delete($iter, $stopIter); | ||
| 9159 | } | ||
| 9160 | } | ||
| 9161 | |||
| 9162 | $self->buffer->insert_with_tags_by_name($iter, $text, @tags); | ||
| 9163 | |||
| 9164 | # Get the iter after immediately after the inserted text. Gtk, for some reason, crashes if | ||
| 9165 | # we try to get an iter outside the buffer, and some worlds (e.g. Kallisti) can cause | ||
| 9166 | # such a crash, so we have to do a sanity check | ||
| 9167 | $posn += length ($text); | ||
| 9168 | $newLength = $self->getLineLength($iter); | ||
| 9169 | |||
| 9170 | if ($posn > $newLength) { | ||
| 9171 | |||
| 9172 | $posn = $newLength; | ||
| 9173 | } | ||
| 9174 | |||
| 9175 | $newIter = $self->buffer->get_iter_at_line_offset($lineNum, $posn); | ||
| 9176 | |||
| 9177 | # $self->insertNewLineFlag is set on every call to this function | ||
| 9178 | $self->ivPoke('insertNewLineFlag', FALSE); | ||
| 9179 | # $self->newLineFlag must be set if the buffer now ends with a newline character | ||
| 9180 | $endIter = $self->buffer->get_end_iter(); | ||
| 9181 | |||
| 9182 | # Confusingly, $newIter and $endIter are not the same, even if they both point at the same | ||
| 9183 | # position in the buffer | ||
| 9184 | if ( | ||
| 9185 | $newIter->get_line() eq $endIter->get_line() | ||
| 9186 | && $newIter->get_visible_line_offset eq $endIter->get_visible_line_offset() | ||
| 9187 | ) { | ||
| 9188 | $self->ivPoke('newLineFlag', FALSE); | ||
| 9189 | # Let's return $endIter rather than $newIter... | ||
| 9190 | $newIter = $endIter; | ||
| 9191 | } | ||
| 9192 | |||
| 9193 | # Update IVs | ||
| 9194 | if ($text ne '') { | ||
| 9195 | |||
| 9196 | $self->ivPoke('bufferTextFlag', TRUE); | ||
| 9197 | $self->ivPoke('sizeUpdateFlag', TRUE); | ||
| 9198 | } | ||
| 9199 | |||
| 9200 | return $newIter; | ||
| 9201 | } | ||
| 9202 | |||
| 9203 | sub insertNewLine { | ||
| 9204 | |||
| 9205 | # Called by $self->insertText, ->insertMultipleText, ->insertCmd, ->showSystemText, | ||
| 9206 | # ->showError, ->showWarning, ->showDebug, ->showImproper and ->showImage | ||
| 9207 | # Also called by $self->setInsertPosn to add empty lines, if they don't already exist | ||
| 9208 | # Inserts a newline character into the Gtk3::TextBuffer and updates IVs | ||
| 9209 | # | ||
| 9210 | # Expected arguments | ||
| 9211 | # (none besides $self) | ||
| 9212 | # | ||
| 9213 | # Optional arguments | ||
| 9214 | # $iter - The Gtk3::TextIter, representing the point in the buffer at which the newline | ||
| 9215 | # character is inserted. If 'undef', the newline character is inserted at the | ||
| 9216 | # end of the buffer | ||
| 9217 | # | ||
| 9218 | # Return values | ||
| 9219 | # 'undef' on improper arguments | ||
| 9220 | # Otherwise returns the Gtk3::TextIter immediately after the inserted newline character | ||
| 9221 | # (which might be the end of the textbuffer, or not) | ||
| 9222 | |||
| 9223 | my ($self, $iter, $check) = @_; | ||
| 9224 | |||
| 9225 | # Local variables | ||
| 9226 | my ($lineNum, $posn, $endIter, $forceFlag); | ||
| 9227 | |||
| 9228 | # Check for improper arguments | ||
| 9229 | if (defined $check) { | ||
| 9230 | |||
| 9231 | return $axmud::CLIENT->writeImproper($self->_objClass . '->insertNewLine', @_); | ||
| 9232 | } | ||
| 9233 | |||
| 9234 | if (! defined $iter) { | ||
| 9235 | |||
| 9236 | $iter = $self->buffer->get_end_iter(); | ||
| 9237 | } | ||
| 9238 | |||
| 9239 | # Get the iter's position in the textview buffer | ||
| 9240 | $lineNum = $iter->get_line(); | ||
| 9241 | $posn = $iter->get_visible_line_offset(); | ||
| 9242 | $endIter = $self->buffer->get_end_iter(); | ||
| 9243 | |||
| 9244 | if ($endIter->get_line() == $lineNum) { | ||
| 9245 | |||
| 9246 | # We're on the buffer's last line | ||
| 9247 | if ($self->getLineLength($endIter) == $posn) { | ||
| 9248 | |||
| 9249 | # We're at the end of the buffer, so insert a newline character as normal | ||
| 9250 | $self->buffer->insert($iter, "\n"); | ||
| 9251 | $self->ivPoke('newLineFlag', TRUE); | ||
| 9252 | |||
| 9253 | # Create a mark after this newline character, so the next line (which currently | ||
| 9254 | # contains no characters at all) can be deleted when the buffer exceeds its | ||
| 9255 | # maximum number of lines | ||
| 9256 | # (Lines aren't deleted in overwrite mode, so don't bother creating the marks) | ||
| 9257 | if (! $self->overwriteFlag) { | ||
| 9258 | |||
| 9259 | $self->buffer->create_mark( | ||
| 9260 | 'line_' . ($lineNum + 1 + $self->nextDeleteLine), | ||
| 9261 | $self->buffer->get_end_iter(), | ||
| 9262 | TRUE, | ||
| 9263 | ); | ||
| 9264 | |||
| 9265 | # If the buffer has exceeded its maximum number of lines, delete the oldest | ||
| 9266 | # remaining line | ||
| 9267 | if ($self->maxLines && $lineNum >= $self->maxLines) { | ||
| 9268 | |||
| 9269 | $self->removeOldLine(); | ||
| 9270 | } | ||
| 9271 | } | ||
| 9272 | |||
| 9273 | } else { | ||
| 9274 | |||
| 9275 | # We're somewhere on the buffer's last line, but not at the end | ||
| 9276 | # Add a newline character to the end of the buffer, then move the insertion position | ||
| 9277 | # to the beginning of the next line | ||
| 9278 | $self->buffer->insert($endIter, "\n"); | ||
| 9279 | $self->setInsertPosn(($lineNum + 1), 0); | ||
| 9280 | } | ||
| 9281 | |||
| 9282 | } else { | ||
| 9283 | |||
| 9284 | # We're somewhere on a line, but not the buffer's last line | ||
| 9285 | # This line already ends with a newline character, so just move the insertion position | ||
| 9286 | # to the beginning of the next line | ||
| 9287 | $self->setInsertPosn(($lineNum + 1), 0); | ||
| 9288 | # If a scrolling region scrolls, we're forced to add newline character(s) anyway | ||
| 9289 | $forceFlag = TRUE; | ||
| 9290 | } | ||
| 9291 | |||
| 9292 | # $self->insertNewLineFlag is set on every call to this function (unless | ||
| 9293 | # $self->tempInsertMark is set, in which case this newline follows a system message, and | ||
| 9294 | # the actual insertion point is on some earlier line, in which case, we retain the current | ||
| 9295 | # value of $self->insertNewLineFlag) | ||
| 9296 | if (! $self->tempInsertMark) { | ||
| 9297 | |||
| 9298 | $self->ivPoke('insertNewLineFlag', TRUE); | ||
| 9299 | } | ||
| 9300 | |||
| 9301 | # This flag is TRUE even if the buffer contains only a newline character | ||
| 9302 | $self->ivPoke('bufferTextFlag', TRUE); | ||
| 9303 | $self->ivPoke('sizeUpdateFlag', TRUE); | ||
| 9304 | |||
| 9305 | if (defined $self->scrlRegionBottom && $self->scrlRegionBottom eq $lineNum) { | ||
| 9306 | |||
| 9307 | # If a scroll region is defined, and if this function was called when the insertion | ||
| 9308 | # position was on the line at the bottom of that region, then scroll all the lines in | ||
| 9309 | # the region up by one (by deleting the first line in the region) | ||
| 9310 | $self->scrlRegionUp(1, $forceFlag); | ||
| 9311 | |||
| 9312 | return $self->buffer->get_iter_at_line_offset($lineNum, 0); | ||
| 9313 | |||
| 9314 | } else { | ||
| 9315 | |||
| 9316 | # Just return the Gtk3::TextIter at the new insertion position | ||
| 9317 | return $self->buffer->get_iter_at_line_offset(($lineNum + 1), 0); | ||
| 9318 | } | ||
| 9319 | } | ||
| 9320 | |||
| 9321 | sub removeOldLine { | ||
| 9322 | |||
| 9323 | # Called by $self->insertNewLine | ||
| 9324 | # When the Gtk3::TextBuffer is full (i.e. the number of lines in the buffer exceeds the | ||
| 9325 | # maximum), remove the oldest line | ||
| 9326 | # Also check $self->insertMark, etc, just in case they no longer exist (and update them, if | ||
| 9327 | # so) | ||
| 9328 | # Never called in overwrite mode (i.e. when $self->overwriteFlag is TRUE) | ||
| 9329 | # | ||
| 9330 | # Expected arguments | ||
| 9331 | # (none besides $self) | ||
| 9332 | # | ||
| 9333 | # Return values | ||
| 9334 | # 'undef' on improper arguments | ||
| 9335 | # 1 otherwise | ||
| 9336 | |||
| 9337 | my ($self, $check) = @_; | ||
| 9338 | |||
| 9339 | # Local variables | ||
| 9340 | my ($number, $startIter, $stopIter, $listRef, $ordinaryLineNum); | ||
| 9341 | |||
| 9342 | # Check for improper arguments | ||
| 9343 | if (defined $check) { | ||
| 9344 | |||
| 9345 | return $axmud::CLIENT->writeImproper($self->_objClass . '->removeOldLine', @_); | ||
| 9346 | } | ||
| 9347 | |||
| 9348 | # v1.2.0 - because of Gtk3 performance issues, we no longer delete one line at a time, | ||
| 9349 | # therefore keeping a constant number of lines in the buffer (once full) | ||
| 9350 | # Instead, we delete 100 lines at a time (or fewer, if the maximum textview size is small) | ||
| 9351 | if ($self->maxLines >= 1000) { | ||
| 9352 | |||
| 9353 | $number = 100; | ||
| 9354 | |||
| 9355 | } else { | ||
| 9356 | |||
| 9357 | $number = int($self->maxLines / 10); | ||
| 9358 | if (! $number) { | ||
| 9359 | |||
| 9360 | $number = 1; | ||
| 9361 | } | ||
| 9362 | } | ||
| 9363 | |||
| 9364 | $startIter = $self->buffer->get_start_iter(); | ||
| 9365 | $stopIter = $self->buffer->get_iter_at_line_offset($number, 0); | ||
| 9366 | if ($startIter && $stopIter) { | ||
| 9367 | |||
| 9368 | # Perform the deletion operation | ||
| 9369 | $self->buffer->delete($startIter, $stopIter); | ||
| 9370 | |||
| 9371 | for (my $count = 0; $count < $number; $count++) { | ||
| 9372 | |||
| 9373 | # Remove any link objects for links on the deleted line(s) | ||
| 9374 | $listRef = $self->ivShow('linkObjLineHash', $self->nextDeleteLine); | ||
| 9375 | if (defined $listRef) { | ||
| 9376 | |||
| 9377 | foreach my $linkObj (@$listRef) { | ||
| 9378 | |||
| 9379 | $self->ivDelete('linkObjHash', $linkObj->number); | ||
| 9380 | } | ||
| 9381 | |||
| 9382 | $self->ivDelete('linkObjLineHash', $self->nextDeleteLine); | ||
| 9383 | } | ||
| 9384 | |||
| 9385 | # No need to display a tooltip for this line every again | ||
| 9386 | $self->ivDelete('tooltipHash', $self->nextDeleteLine); | ||
| 9387 | } | ||
| 9388 | |||
| 9389 | # Do the IVs $self->insertMark, etc refer to a position on these line(s)? If so, they | ||
| 9390 | # must be reset | ||
| 9391 | if ($self->insertMark && ! $self->insertMark->get_buffer()) { | ||
| 9392 | |||
| 9393 | $self->ivPoke('insertMark', undef); | ||
| 9394 | $self->ivPoke('insertNewLineFlag', FALSE); | ||
| 9395 | } | ||
| 9396 | |||
| 9397 | if ($self->restoreInsertMark && ! $self->restoreInsertMark->get_buffer()) { | ||
| 9398 | |||
| 9399 | $self->ivPoke('restoreInsertMark', undef); | ||
| 9400 | } | ||
| 9401 | |||
| 9402 | if ($self->tempInsertMark && ! $self->tempInsertMark->get_buffer()) { | ||
| 9403 | |||
| 9404 | $self->ivPoke('tempInsertMark', undef); | ||
| 9405 | } | ||
| 9406 | |||
| 9407 | if ($self->systemInsertMark && ! $self->systemInsertMark->get_buffer()) { | ||
| 9408 | |||
| 9409 | $self->ivPoke('systemInsertMark', undef); | ||
| 9410 | } | ||
| 9411 | |||
| 9412 | $self->ivIncrement('nextDeleteLine'); | ||
| 9413 | } | ||
| 9414 | |||
| 9415 | return 1; | ||
| 9416 | } | ||
| 9417 | |||
| 9418 | sub enableOverwrite { | ||
| 9419 | |||
| 9420 | # Mostly called by functions in this textview object, but can (in theory) be called by | ||
| 9421 | # anything | ||
| 9422 | # Enables overwrite mode | ||
| 9423 | # | ||
| 9424 | # Expected arguments | ||
| 9425 | # (none besides $self) | ||
| 9426 | # | ||
| 9427 | # Return values | ||
| 9428 | # 'undef' on improper arguments | ||
| 9429 | # 1 otherwise | ||
| 9430 | |||
| 9431 | my ($self, $check) = @_; | ||
| 9432 | |||
| 9433 | # Check for improper arguments | ||
| 9434 | if (defined $check) { | ||
| 9435 | |||
| 9436 | return $axmud::CLIENT->writeImproper($self->_objClass . '->enableOverwrite', @_); | ||
| 9437 | } | ||
| 9438 | |||
| 9439 | $self->ivPoke('overwriteFlag', TRUE); | ||
| 9440 | |||
| 9441 | $self->textView->set_overwrite(TRUE); | ||
| 9442 | if ($self->textView2) { | ||
| 9443 | |||
| 9444 | $self->textView2->set_overwrite(TRUE); | ||
| 9445 | } | ||
| 9446 | |||
| 9447 | return 1; | ||
| 9448 | } | ||
| 9449 | |||
| 9450 | sub disableOverwrite { | ||
| 9451 | |||
| 9452 | # Should only be called by GA::Session->doDisconnect or ->reactDisconnect when a (real) | ||
| 9453 | # connection terminates, and when this is the session's default textview | ||
| 9454 | # Turns off overwrite mode (if on), and moves the insertion point to the end of | ||
| 9455 | # $self->buffer | ||
| 9456 | # | ||
| 9457 | # Expected arguments | ||
| 9458 | # (none besides $self) | ||
| 9459 | # | ||
| 9460 | # Return values | ||
| 9461 | # 'undef' on improper arguments | ||
| 9462 | # 1 otherwise | ||
| 9463 | |||
| 9464 | my ($self, $check) = @_; | ||
| 9465 | |||
| 9466 | # Check for improper arguments | ||
| 9467 | if (defined $check) { | ||
| 9468 | |||
| 9469 | return $axmud::CLIENT->writeImproper($self->_objClass . '->disableOverwrite', @_); | ||
| 9470 | } | ||
| 9471 | |||
| 9472 | if ($self->overwriteFlag) { | ||
| 9473 | |||
| 9474 | $self->ivPoke('overwriteFlag', FALSE); | ||
| 9475 | $self->ivUndef('insertMark'); | ||
| 9476 | $self->ivUndef('restoreInsertMark'); | ||
| 9477 | $self->ivUndef('tempInsertMark'); | ||
| 9478 | $self->ivUndef('systemInsertMark'); | ||
| 9479 | $self->ivUndef('scrlRegionTop'); | ||
| 9480 | $self->ivUndef('scrlRegionBottom'); | ||
| 9481 | |||
| 9482 | if ($self->bufferTextFlag && ! $self->newLineFlag) { | ||
| 9483 | |||
| 9484 | $self->insertNewLine($self->buffer->get_end_iter()); | ||
| 9485 | } | ||
| 9486 | } | ||
| 9487 | |||
| 9488 | return 1; | ||
| 9489 | } | ||
| 9490 | |||
| 9491 | ################## | ||
| 9492 | # Accessors - set | ||
| 9493 | |||
| 9494 | sub set_allowLinkFlag { | ||
| 9495 | |||
| 9496 | my ($self, $flag, $check) = @_; | ||
| 9497 | |||
| 9498 | # Check for improper arguments | ||
| 9499 | if (! defined $flag || defined $check) { | ||
| 9500 | |||
| 9501 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_allowLinkFlag', @_); | ||
| 9502 | } | ||
| 9503 | |||
| 9504 | if ($flag) { | ||
| 9505 | $self->ivPoke('allowLinkFlag', TRUE); | ||
| 9506 | } else { | ||
| 9507 | $self->ivPoke('allowLinkFlag', FALSE); | ||
| 9508 | } | ||
| 9509 | |||
| 9510 | return 1; | ||
| 9511 | } | ||
| 9512 | |||
| 9513 | sub set_clearAfterInsert { | ||
| 9514 | |||
| 9515 | my ($self, $check) = @_; | ||
| 9516 | |||
| 9517 | # Check for improper arguments | ||
| 9518 | if (defined $check) { | ||
| 9519 | |||
| 9520 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_clearAfterInsert', @_); | ||
| 9521 | } | ||
| 9522 | |||
| 9523 | $self->ivPoke('clearAfterInsertFlag', TRUE); | ||
| 9524 | |||
| 9525 | return 1; | ||
| 9526 | } | ||
| 9527 | |||
| 9528 | sub set_colourStyleHash { | ||
| 9529 | |||
| 9530 | # Called by GA::Session->processLineSegment | ||
| 9531 | |||
| 9532 | my ($self, %hash) = @_; | ||
| 9533 | |||
| 9534 | # (No improper arguments to check) | ||
| 9535 | |||
| 9536 | $self->ivPoke('colourStyleHash', %hash); | ||
| 9537 | |||
| 9538 | return 1; | ||
| 9539 | } | ||
| 9540 | |||
| 9541 | sub set_cursorEnableFlag { | ||
| 9542 | |||
| 9543 | my ($self, $flag, $check) = @_; | ||
| 9544 | |||
| 9545 | # Check for improper arguments | ||
| 9546 | if (! defined $flag || defined $check) { | ||
| 9547 | |||
| 9548 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_cursorEnableFlag', @_); | ||
| 9549 | } | ||
| 9550 | |||
| 9551 | if ($flag) { | ||
| 9552 | |||
| 9553 | $self->ivPoke('cursorEnableFlag', TRUE); | ||
| 9554 | |||
| 9555 | $self->moveCursor(); | ||
| 9556 | |||
| 9557 | } else { | ||
| 9558 | |||
| 9559 | if ($self->cursorEnableFlag) { | ||
| 9560 | |||
| 9561 | $self->removeCursor(); | ||
| 9562 | } | ||
| 9563 | |||
| 9564 | $self->ivPoke('cursorEnableFlag', FALSE); | ||
| 9565 | } | ||
| 9566 | |||
| 9567 | return 1; | ||
| 9568 | } | ||
| 9569 | |||
| 9570 | sub add_incompleteLink { | ||
| 9571 | |||
| 9572 | # Called by various MXP functions in GA::Session to convert an incomplete link (one in | ||
| 9573 | # which the link hasn't actually been applied to the Gtk3::TextView yet) into a complete | ||
| 9574 | # one, stored in IVs in this textview object | ||
| 9575 | |||
| 9576 | my ($self, $linkObj, $check) = @_; | ||
| 9577 | |||
| 9578 | # Local variables | ||
| 9579 | my ( | ||
| 9580 | $listRef, $modLineNum, $beginIter, $length, $endIter, $lastLineFlag, $startPosn, | ||
| 9581 | $startIter, $stopPosn, $stopIter, | ||
| 9582 | ); | ||
| 9583 | |||
| 9584 | # Check for improper arguments | ||
| 9585 | if (! defined $linkObj || defined $check) { | ||
| 9586 | |||
| 9587 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_incompleteLink', @_); | ||
| 9588 | } | ||
| 9589 | |||
| 9590 | if ($linkObj->number != -1) { | ||
| 9591 | |||
| 9592 | # Not an incomplete link object | ||
| 9593 | return undef; | ||
| 9594 | } | ||
| 9595 | |||
| 9596 | # Update IVs | ||
| 9597 | $linkObj->ivPoke('number', $self->linkObjCount); | ||
| 9598 | |||
| 9599 | $self->ivAdd('linkObjHash', $linkObj->number, $linkObj); | ||
| 9600 | |||
| 9601 | if (! $self->ivExists('linkObjLineHash', $linkObj->lineNum)) { | ||
| 9602 | |||
| 9603 | $self->ivAdd('linkObjLineHash', $linkObj->lineNum, []); | ||
| 9604 | } | ||
| 9605 | |||
| 9606 | $listRef = $self->ivShow('linkObjLineHash', $linkObj->lineNum); | ||
| 9607 | push (@$listRef, $linkObj); | ||
| 9608 | $self->ivAdd('linkObjLineHash', $linkObj->lineNum, $listRef); | ||
| 9609 | |||
| 9610 | $self->ivIncrement('linkObjCount'); | ||
| 9611 | |||
| 9612 | # The link object stores a line number which corresponds to the total number of lines | ||
| 9613 | # displayed; if the buffer is full, take account of any lines that have been deleted | ||
| 9614 | $modLineNum = $linkObj->lineNum - $self->nextDeleteLine; | ||
| 9615 | |||
| 9616 | # This function has historically been the cause of sudden crashes when $stopIter or even | ||
| 9617 | # $startIter have been outside the length of the line, so we need to check both of them | ||
| 9618 | $beginIter = $self->buffer->get_iter_at_line_offset($modLineNum, 0); | ||
| 9619 | $length = $self->getLineLength($beginIter); | ||
| 9620 | $endIter = $self->buffer->get_end_iter(); | ||
| 9621 | |||
| 9622 | if ($endIter->get_line() == $beginIter->get_line()) { | ||
| 9623 | |||
| 9624 | $lastLineFlag = TRUE; | ||
| 9625 | } | ||
| 9626 | |||
| 9627 | # If the link starts beyond the end of the line (an unlikely but actually observed error), | ||
| 9628 | # don't display a clickable link at all | ||
| 9629 | $startPosn = $linkObj->posn; | ||
| 9630 | if ( | ||
| 9631 | ($lastLineFlag && $startPosn > $length) | ||
| 9632 | || (! $lastLineFlag && $startPosn > ($length - 1)) | ||
| 9633 | ) { | ||
| 9634 | return undef; | ||
| 9635 | |||
| 9636 | } else { | ||
| 9637 | |||
| 9638 | $startIter = $self->buffer->get_iter_at_line_offset($modLineNum, $startPosn); | ||
| 9639 | } | ||
| 9640 | |||
| 9641 | # If the link ends beyond the end of the line, move the end of the link to the end of the | ||
| 9642 | # line so a clickable link can be displayed | ||
| 9643 | $stopPosn = $linkObj->posn + length ($linkObj->text); | ||
| 9644 | if ($endIter->get_line() == $startIter->get_line() && $stopPosn > $length) { | ||
| 9645 | $stopPosn = $length; | ||
| 9646 | } elsif ($endIter->get_line() != $startIter->get_line() && $stopPosn > ($length - 1)) { | ||
| 9647 | $stopPosn = $length - 1; | ||
| 9648 | } | ||
| 9649 | |||
| 9650 | $stopIter = $self->buffer->get_iter_at_line_offset($modLineNum, $stopPosn); | ||
| 9651 | |||
| 9652 | # Add Axmud 'link' and 'link_off' tags at the appropriate places | ||
| 9653 | if ($startIter && $stopIter) { | ||
| 9654 | |||
| 9655 | $self->buffer->apply_tag_by_name('link', $startIter, $stopIter); | ||
| 9656 | return 1; | ||
| 9657 | |||
| 9658 | } else { | ||
| 9659 | |||
| 9660 | return undef; | ||
| 9661 | } | ||
| 9662 | } | ||
| 9663 | |||
| 9664 | sub add_link { | ||
| 9665 | |||
| 9666 | # Called by $self->setupLink | ||
| 9667 | |||
| 9668 | my ($self, $lineNum, $posn, $type, $check) = @_; | ||
| 9669 | |||
| 9670 | # Local variables | ||
| 9671 | my ($linkObj, $listRef); | ||
| 9672 | |||
| 9673 | # Check for improper arguments | ||
| 9674 | if (! defined $lineNum || ! defined $posn || ! defined $type || defined $check) { | ||
| 9675 | |||
| 9676 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_link', @_); | ||
| 9677 | } | ||
| 9678 | |||
| 9679 | $linkObj = Games::Axmud::Obj::Link->new($self->linkObjCount, $self, $lineNum, $posn, $type); | ||
| 9680 | if (! $linkObj) { | ||
| 9681 | |||
| 9682 | return undef; | ||
| 9683 | |||
| 9684 | } else { | ||
| 9685 | |||
| 9686 | $self->ivAdd('linkObjHash', $linkObj->number, $linkObj); | ||
| 9687 | |||
| 9688 | if (! $self->ivExists('linkObjLineHash', $lineNum)) { | ||
| 9689 | |||
| 9690 | $self->ivAdd('linkObjLineHash', $lineNum, []); | ||
| 9691 | } | ||
| 9692 | |||
| 9693 | $listRef = $self->ivShow('linkObjLineHash', $lineNum); | ||
| 9694 | push (@$listRef, $linkObj); | ||
| 9695 | |||
| 9696 | $self->ivIncrement('linkObjCount'); | ||
| 9697 | |||
| 9698 | return $linkObj; | ||
| 9699 | } | ||
| 9700 | } | ||
| 9701 | |||
| 9702 | sub reset_link { | ||
| 9703 | |||
| 9704 | # Called by $self->clearBuffer | ||
| 9705 | |||
| 9706 | my ($self, $check) = @_; | ||
| 9707 | |||
| 9708 | # Check for improper arguments | ||
| 9709 | if (defined $check) { | ||
| 9710 | |||
| 9711 | return $axmud::CLIENT->writeImproper($self->_objClass . '->reset_link', @_); | ||
| 9712 | } | ||
| 9713 | |||
| 9714 | $self->ivEmpty('linkObjHash'); | ||
| 9715 | $self->ivEmpty('linkObjLineHash'); | ||
| 9716 | $self->ivPoke('linkObjCount', 0); | ||
| 9717 | |||
| 9718 | return 1; | ||
| 9719 | } | ||
| 9720 | |||
| 9721 | sub set_maxLines { | ||
| 9722 | |||
| 9723 | # Called by GA::Cmd::SetTextView->do | ||
| 9724 | |||
| 9725 | my ($self, $max, $check) = @_; | ||
| 9726 | |||
| 9727 | # Local variables | ||
| 9728 | my ($endIter, $lineNum); | ||
| 9729 | |||
| 9730 | # Check for improper arguments | ||
| 9731 | if (defined $check) { | ||
| 9732 | |||
| 9733 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_maxLines', @_); | ||
| 9734 | } | ||
| 9735 | |||
| 9736 | $self->ivPoke('maxLines', $max); | ||
| 9737 | |||
| 9738 | # If $max is 'undef' or 0, the buffer is unlimited | ||
| 9739 | # For other integer values, check whether the buffer has exceeded its maximum number of | ||
| 9740 | # lines and, if so, delete one or more lines | ||
| 9741 | if ($max) { | ||
| 9742 | |||
| 9743 | # Get the line number of the last line | ||
| 9744 | $endIter = $self->buffer->get_end_iter(); | ||
| 9745 | $lineNum = $endIter->get_line(); | ||
| 9746 | |||
| 9747 | if ($lineNum && ($lineNum - $self->nextDeleteLine) > $max) { | ||
| 9748 | |||
| 9749 | do { | ||
| 9750 | |||
| 9751 | my ($mark, $listRef); | ||
| 9752 | |||
| 9753 | $mark = $self->buffer->get_mark('line_' . $self->nextDeleteLine); | ||
| 9754 | if ($mark) { | ||
| 9755 | |||
| 9756 | $self->buffer->delete( | ||
| 9757 | $self->buffer->get_start_iter(), | ||
| 9758 | $self->buffer->get_iter_at_mark($mark), | ||
| 9759 | ); | ||
| 9760 | } | ||
| 9761 | |||
| 9762 | |||
| 9763 | # Remove any link objects for links on the deleted line | ||
| 9764 | $listRef = $self->ivShow('linkObjLineHash', $self->nextDeleteLine); | ||
| 9765 | if (defined $listRef) { | ||
| 9766 | |||
| 9767 | foreach my $linkObj (@$listRef) { | ||
| 9768 | |||
| 9769 | $self->ivDelete('linkObjHash', $linkObj->number); | ||
| 9770 | } | ||
| 9771 | |||
| 9772 | $self->ivDelete('linkObjLineHash', $self->nextDeleteLine); | ||
| 9773 | } | ||
| 9774 | |||
| 9775 | $self->ivIncrement('nextDeleteLine'); | ||
| 9776 | |||
| 9777 | } until (($lineNum - $self->nextDeleteLine) <= $max); | ||
| 9778 | } | ||
| 9779 | } | ||
| 9780 | |||
| 9781 | return 1; | ||
| 9782 | } | ||
| 9783 | |||
| 9784 | sub set_mxpModalStackList { | ||
| 9785 | |||
| 9786 | # Called by GA::Session->popMxpStack | ||
| 9787 | |||
| 9788 | my ($self, @list) = @_; | ||
| 9789 | |||
| 9790 | # (No improper arguments to check) | ||
| 9791 | |||
| 9792 | $self->ivPoke('mxpModalStackList', @list); | ||
| 9793 | |||
| 9794 | return 1; | ||
| 9795 | } | ||
| 9796 | |||
| 9797 | sub set_mxpModalStackHash { | ||
| 9798 | |||
| 9799 | # Called by GA::Session->processLineSegment | ||
| 9800 | |||
| 9801 | my ($self, %hash) = @_; | ||
| 9802 | |||
| 9803 | # (No improper arguments to check) | ||
| 9804 | |||
| 9805 | $self->ivPoke('mxpModalStackHash', %hash); | ||
| 9806 | |||
| 9807 | return 1; | ||
| 9808 | } | ||
| 9809 | |||
| 9810 | sub set_newLineDefault { | ||
| 9811 | |||
| 9812 | my ($self, $default, $check) = @_; | ||
| 9813 | |||
| 9814 | # Check for improper arguments | ||
| 9815 | if (! defined $default || defined $check) { | ||
| 9816 | |||
| 9817 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_newLineDefault', @_); | ||
| 9818 | } | ||
| 9819 | |||
| 9820 | if ($default eq 'before' || $default eq 'after' || $default eq 'nl' || $default eq 'echo') { | ||
| 9821 | |||
| 9822 | $self->ivPoke('newLineDefault', $default); | ||
| 9823 | return 1; | ||
| 9824 | |||
| 9825 | } else { | ||
| 9826 | |||
| 9827 | return undef; | ||
| 9828 | } | ||
| 9829 | } | ||
| 9830 | |||
| 9831 | sub set_scrollLockType { | ||
| 9832 | |||
| 9833 | my ($self, $type, $check) = @_; | ||
| 9834 | |||
| 9835 | # Check for improper arguments | ||
| 9836 | if (! defined $type || defined $check) { | ||
| 9837 | |||
| 9838 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_scrollLockType', @_); | ||
| 9839 | } | ||
| 9840 | |||
| 9841 | if ($type eq 'top') { | ||
| 9842 | $self->ivPoke('scrollLockType', 'top'); | ||
| 9843 | } else { | ||
| 9844 | $self->ivPoke('scrollLockType', 'bottom'); | ||
| 9845 | } | ||
| 9846 | |||
| 9847 | return 1; | ||
| 9848 | } | ||
| 9849 | |||
| 9850 | sub set_scrlRegion { | ||
| 9851 | |||
| 9852 | my ($self, $top, $bottom, $check) = @_; | ||
| 9853 | |||
| 9854 | # Check for improper arguments | ||
| 9855 | if (! defined $top || ! defined $bottom || defined $check) { | ||
| 9856 | |||
| 9857 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_scrlRegion', @_); | ||
| 9858 | } | ||
| 9859 | |||
| 9860 | $self->ivPoke('scrlRegionTop', $top); | ||
| 9861 | $self->ivPoke('scrlRegionBottom', $bottom); | ||
| 9862 | |||
| 9863 | return 1; | ||
| 9864 | } | ||
| 9865 | |||
| 9866 | sub reset_scrlRegion { | ||
| 9867 | |||
| 9868 | my ($self, $check) = @_; | ||
| 9869 | |||
| 9870 | # Check for improper arguments | ||
| 9871 | if (defined $check) { | ||
| 9872 | |||
| 9873 | return $axmud::CLIENT->writeImproper($self->_objClass . '->reset_scrlRegion', @_); | ||
| 9874 | } | ||
| 9875 | |||
| 9876 | $self->ivUndef('scrlRegionTop'); | ||
| 9877 | $self->ivUndef('scrlRegionBottom'); | ||
| 9878 | |||
| 9879 | return 1; | ||
| 9880 | } | ||
| 9881 | |||
| 9882 | sub set_sizeUpdateFlag { | ||
| 9883 | |||
| 9884 | my ($self, $check) = @_; | ||
| 9885 | |||
| 9886 | # Check for improper arguments | ||
| 9887 | if (defined $check) { | ||
| 9888 | |||
| 9889 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_sizeUpdateFlag', @_); | ||
| 9890 | } | ||
| 9891 | |||
| 9892 | $self->ivPoke('sizeUpdateFlag', TRUE); | ||
| 9893 | |||
| 9894 | return 1; | ||
| 9895 | } | ||
| 9896 | |||
| 9897 | ################## | ||
| 9898 | # Accessors - get | ||
| 9899 | |||
| 9900 | sub session | ||
| 9901 | { $_[0]->{session} } | ||
| 9902 | sub number | ||
| 9903 | { $_[0]->{number} } | ||
| 9904 | sub winObj | ||
| 9905 | { $_[0]->{winObj} } | ||
| 9906 | sub paneObj | ||
| 9907 | { $_[0]->{paneObj} } | ||
| 9908 | |||
| 9909 | sub textView | ||
| 9910 | { $_[0]->{textView} } | ||
| 9911 | sub textView2 | ||
| 9912 | { $_[0]->{textView2} } | ||
| 9913 | sub buffer | ||
| 9914 | { $_[0]->{buffer} } | ||
| 9915 | sub vPaned | ||
| 9916 | { $_[0]->{vPaned} } | ||
| 9917 | sub scroll | ||
| 9918 | { $_[0]->{scroll} } | ||
| 9919 | sub scroll2 | ||
| 9920 | { $_[0]->{scroll2} } | ||
| 9921 | sub startMark | ||
| 9922 | { $_[0]->{startMark} } | ||
| 9923 | sub endMark | ||
| 9924 | { $_[0]->{endMark} } | ||
| 9925 | sub searchMark | ||
| 9926 | { $_[0]->{searchMark} } | ||
| 9927 | sub popupMenu | ||
| 9928 | { $_[0]->{popupMenu} } | ||
| 9929 | |||
| 9930 | sub scrollLockFlag | ||
| 9931 | { $_[0]->{scrollLockFlag} } | ||
| 9932 | sub scrollLockType | ||
| 9933 | { $_[0]->{scrollLockType} } | ||
| 9934 | sub splitScreenMode | ||
| 9935 | { $_[0]->{splitScreenMode} } | ||
| 9936 | |||
| 9937 | sub colourScheme | ||
| 9938 | { $_[0]->{colourScheme} } | ||
| 9939 | sub textColour | ||
| 9940 | { $_[0]->{textColour} } | ||
| 9941 | sub underlayColour | ||
| 9942 | { $_[0]->{underlayColour} } | ||
| 9943 | sub backgroundColour | ||
| 9944 | { $_[0]->{backgroundColour} } | ||
| 9945 | sub font | ||
| 9946 | { $_[0]->{font} } | ||
| 9947 | sub fontSize | ||
| 9948 | { $_[0]->{fontSize} } | ||
| 9949 | sub monochromeFlag | ||
| 9950 | { $_[0]->{monochromeFlag} } | ||
| 9951 | sub monochromeModFlag | ||
| 9952 | { $_[0]->{monochromeModFlag} } | ||
| 9953 | sub overwriteFlag | ||
| 9954 | { $_[0]->{overwriteFlag} } | ||
| 9955 | |||
| 9956 | sub maxLines | ||
| 9957 | { $_[0]->{maxLines} } | ||
| 9958 | sub nextDeleteLine | ||
| 9959 | { $_[0]->{nextDeleteLine} } | ||
| 9960 | |||
| 9961 | sub scrlRegionTop | ||
| 9962 | { $_[0]->{scrlRegionTop} } | ||
| 9963 | sub scrlRegionBottom | ||
| 9964 | { $_[0]->{scrlRegionBottom} } | ||
| 9965 | |||
| 9966 | sub bufferTextFlag | ||
| 9967 | { $_[0]->{bufferTextFlag} } | ||
| 9968 | sub sizeUpdateFlag | ||
| 9969 | { $_[0]->{sizeUpdateFlag} } | ||
| 9970 | sub textWidthChars | ||
| 9971 | { $_[0]->{textWidthChars} } | ||
| 9972 | sub textHeightChars | ||
| 9973 | { $_[0]->{textHeightChars} } | ||
| 9974 | sub newLineFlag | ||
| 9975 | { $_[0]->{newLineFlag} } | ||
| 9976 | sub insertNewLineFlag | ||
| 9977 | { $_[0]->{insertNewLineFlag} } | ||
| 9978 | sub newLineDefault | ||
| 9979 | { $_[0]->{newLineDefault} } | ||
| 9980 | sub clearAfterInsertFlag | ||
| 9981 | { $_[0]->{clearAfterInsertFlag} } | ||
| 9982 | |||
| 9983 | sub insertMark | ||
| 9984 | { $_[0]->{insertMark} } | ||
| 9985 | sub restoreInsertMark | ||
| 9986 | { $_[0]->{restoreInsertMark} } | ||
| 9987 | sub tempInsertMark | ||
| 9988 | { $_[0]->{tempInsertMark} } | ||
| 9989 | sub systemInsertMark | ||
| 9990 | { $_[0]->{systemInsertMark} } | ||
| 9991 | sub systemTextBuffer | ||
| 9992 | { $_[0]->{systemTextBuffer} } | ||
| 9993 | |||
| 9994 | sub cursorEnableFlag | ||
| 9995 | { $_[0]->{cursorEnableFlag} } | ||
| 9996 | sub cursorOnFlag | ||
| 9997 | { $_[0]->{cursorOnFlag} } | ||
| 9998 | sub cursorMark | ||
| 9999 | { $_[0]->{cursorMark} } | ||
| 10000 | sub cursorEndFlag | ||
| 10001 | { $_[0]->{cursorEndFlag} } | ||
| 10002 | sub storePosnYPos | ||
| 10003 | { $_[0]->{storePosnYPos} } | ||
| 10004 | sub storePosnXPos | ||
| 10005 | { $_[0]->{storePosnXPos} } | ||
| 10006 | |||
| 10007 | sub linkObjHash | ||
| 10008 | { my $self = shift; return %{$self->{linkObjHash}}; } | ||
| 10009 | sub linkObjLineHash | ||
| 10010 | { my $self = shift; return %{$self->{linkObjLineHash}}; } | ||
| 10011 | sub linkObjCount | ||
| 10012 | { $_[0]->{linkObjCount} } | ||
| 10013 | sub currentLinkObj | ||
| 10014 | { $_[0]->{currentLinkObj} } | ||
| 10015 | sub allowLinkFlag | ||
| 10016 | { $_[0]->{allowLinkFlag} } | ||
| 10017 | |||
| 10018 | sub tooltipHash | ||
| 10019 | { my $self = shift; return %{$self->{tooltipHash}}; } | ||
| 10020 | sub lastTooltipLine | ||
| 10021 | { $_[0]->{lastTooltipLine} } | ||
| 10022 | |||
| 10023 | sub soundDelayTime | ||
| 10024 | { $_[0]->{soundDelayTime} } | ||
| 10025 | sub soundCheckTime | ||
| 10026 | { $_[0]->{soundCheckTime} } | ||
| 10027 | |||
| 10028 | sub colourStyleHash | ||
| 10029 | { my $self = shift; return %{$self->{colourStyleHash}}; } | ||
| 10030 | sub prevColourStyleHash | ||
| 10031 | { my $self = shift; return %{$self->{prevColourStyleHash}}; } | ||
| 10032 | |||
| 10033 | sub mxpModalStackList | ||
| 10034 | { my $self = shift; return @{$self->{mxpModalStackList}}; } | ||
| 10035 | sub mxpModalStackHash | ||
| 10036 | { my $self = shift; return %{$self->{mxpModalStackHash}}; } | ||
| 10037 | } | ||
| 10038 | |||
| 10039 | # Package must return a true value | ||
| 10040 | 1 |