| 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::Desktop | ||
| 16 | # The main desktop object. Arranges windows on one or more workspaces, each containing one or more | ||
| 17 | # workspace grids | ||
| 18 | |||
| 19 | { package Games::Axmud::Obj::Desktop; | ||
| 20 | |||
| 21 | use strict; | ||
| 22 | use warnings; | ||
| 23 | # use diagnostics; | ||
| 24 | |||
| 25 | use Glib qw(TRUE FALSE); | ||
| 26 | |||
| 27 | our @ISA = qw(Games::Axmud); | ||
| 28 | |||
| 29 | ################## | ||
| 30 | # Constructors | ||
| 31 | |||
| 32 | sub new { | ||
| 33 | |||
| 34 | # Called by GA::Client->start | ||
| 35 | # | ||
| 36 | # Expected arguments | ||
| 37 | # (none besides $class) | ||
| 38 | # | ||
| 39 | # Return values | ||
| 40 | # 'undef' on improper arguments or if a GA::Obj::Desktop object already exists | ||
| 41 | # Blessed reference to the newly-created object on success | ||
| 42 | |||
| 43 | my ($class, $check) = @_; | ||
| 44 | |||
| 45 | # Check for improper arguments | ||
| 46 | if (! defined $class || defined $check) { | ||
| 47 | |||
| 48 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 49 | } | ||
| 50 | |||
| 51 | # Only one desktop object can exist | ||
| 52 | if ($axmud::CLIENT->desktopObj) { | ||
| 53 | |||
| 54 | return undef; | ||
| 55 | } | ||
| 56 | |||
| 57 | # Setup | ||
| 58 | my $self = { | ||
| 59 | _objName => 'desktop', | ||
| 60 | _objClass => $class, | ||
| 61 | _parentFile => undef, # No parent file object | ||
| 62 | _parentWorld => undef, # No parent file object | ||
| 63 | _privFlag => TRUE, # All IVs are private | ||
| 64 | |||
| 65 | # Widget registries | ||
| 66 | # ----------------- | ||
| 67 | |||
| 68 | # The GA::Obj::WMCtrl object, based on X11::WMCtrl, which handles multiple workspaces | ||
| 69 | # (on systems that support wmctrl) | ||
| 70 | wmCtrlObj => undef, | ||
| 71 | |||
| 72 | # Registry hash of all workspace objects which still exist. Workspace objects | ||
| 73 | # (GA::Obj::Workspace) handle a single workspace on the desktop, on which 'grid' | ||
| 74 | # windows can be arranged on a 3-dimensional grid to avoid overlapping (each grid is | ||
| 75 | # handled by a workspace grid object, GA::Obj::WorkspaceGrid) | ||
| 76 | # If GA::Client->shareMainWinFlag = TRUE, all sessions share a single 'main' window, | ||
| 77 | # so each session has its own workspace grid object on every workspace. If | ||
| 78 | # GA::CLIENT->shareMainFlag = FALSE, all sessions have their own 'main' window, so | ||
| 79 | # there is only one workspace grid for each workspace, shared by all sessions | ||
| 80 | # NB The workspace object corresponding to the workspace from which Axmud was launched | ||
| 81 | # has the number 0, and cannot be deleted. Unlike GA::Client->initWorkspaceHash, | ||
| 82 | # subsequent workspaces don't have to be numbered sequentially (1, 2, 3...) but are | ||
| 83 | # still numbered in the order in which they're created | ||
| 84 | # Hash in the form | ||
| 85 | # $workspaceHash{unique_number} = blessed_reference_to_workspace_object | ||
| 86 | workspaceHash => {}, | ||
| 87 | # Number of workspace objects ever created (used to give each workspace object a unique | ||
| 88 | # number) | ||
| 89 | workspaceCount => 0, | ||
| 90 | # For convenience, the 'default' workspace object (whose unique number is 0) is stored | ||
| 91 | # here | ||
| 92 | defaultWorkspaceObj => undef, | ||
| 93 | |||
| 94 | # Registry hash of workspace grid objects which still exist. Each workspace objects | ||
| 95 | # usually has one or more workspace grid objects (or none, if | ||
| 96 | # GA::Obj::Workspace->gridEnableFlag is TRUE) | ||
| 97 | # Each workspace grid object either belongs to a single session | ||
| 98 | # (GA::Client->shareMainWinFlag = TRUE), or is shared between all sessions | ||
| 99 | # (GA::CLIENT->shareMainWinFlag = FALSE) | ||
| 100 | # A workspace grid is divided up into zones. Zones can't use partial gridblocks so a | ||
| 101 | # zone size of 15x15 is possible, but not 20.5x15 | ||
| 102 | # Zones can specify that only certain window types can be placed in them, or can specify | ||
| 103 | # that all window types may be placed in them. | ||
| 104 | # Hash in the form | ||
| 105 | # $gridHash{unique_number} = blessed_reference_to_workspace_grid_object | ||
| 106 | gridHash => {}, | ||
| 107 | # Number of workspace grid objects ever created for this workspace (used to give every | ||
| 108 | # workspace grid object a unique number) | ||
| 109 | gridCount => 0, | ||
| 110 | |||
| 111 | # Registry hash of all 'grid' windows which still exist. 'grid' windows are any window | ||
| 112 | # specified by GA::Client->constGridWinTypeHash, specifically, windows which can be | ||
| 113 | # placed on a workspace grid (unlike temporary 'free' windows, which are never placed | ||
| 114 | # on a workspace grid) | ||
| 115 | # 'Grid' windows are handled by GA::Win::Internal or GA::Win::External objects | ||
| 116 | # Hash in the form | ||
| 117 | # $gridWinHash{unique_number} = blessed_reference_to_grid_window_object | ||
| 118 | gridWinHash => {}, | ||
| 119 | # Number of 'grid' window objects ever created (used to give each 'grid' window object a | ||
| 120 | # unique number) | ||
| 121 | gridWinCount => 0, | ||
| 122 | |||
| 123 | # Registry hash of all 'free' windows which still exist (except 'dialogue' windows, | ||
| 124 | # which are not stored in any registry because they automatically close with their | ||
| 125 | # parent window; all code in this object assumes that 'free' windows exclude | ||
| 126 | # 'dialogue' windows) | ||
| 127 | # 'Free' windows are any window specified by GA::Client->constFreeWinTypeHash | ||
| 128 | # (specifically, any temporary window which is never placed on a workspace grid) | ||
| 129 | # 'Free' windows are handled by various objects inheriting from GA::Generic::FreeWin | ||
| 130 | # Hash in the form | ||
| 131 | # $freeWinHash{unique_number} = blessed_reference_to_free_window_object | ||
| 132 | freeWinHash => {}, | ||
| 133 | # Number of 'free' window objects ever created (used to give each 'free' window object a | ||
| 134 | # unique number) | ||
| 135 | freeWinCount => 0, | ||
| 136 | |||
| 137 | # Registry hash of all textview objects (created by all sessions) which still exist. | ||
| 138 | # Textview objects (GA::Obj::TextView) handle a single Gtk3::Textview | ||
| 139 | # NB The code is at liberty to create its own Gtk3::TextViews, not handled by textview | ||
| 140 | # objects, if the code doesn't need the full functionality of a textview object. Those | ||
| 141 | # Gtk3::TextViews are not stored here | ||
| 142 | # Hash in the form | ||
| 143 | # $textViewHash{unique_number} = blessed_reference_to_textview_object | ||
| 144 | textViewHash => {}, | ||
| 145 | # Number of textview objects ever created (used to give each textview object a unique | ||
| 146 | # number) | ||
| 147 | textViewCount => 0, | ||
| 148 | |||
| 149 | # Other IVs | ||
| 150 | # --------- | ||
| 151 | |||
| 152 | # $self->start will set this flag to FALSE if it's not possible to create workspace | ||
| 153 | # grids at all (because the desktop is too small, etc). If set to TRUE, workspace | ||
| 154 | # grids are only created when both this flag and GA::Client->activateGridFlag are | ||
| 155 | # TRUE | ||
| 156 | gridPermitFlag => TRUE, | ||
| 157 | # The number of workspaces that Axmud can potentially use is specified by | ||
| 158 | # GA::Client->initWorkspaceHash. On each workspace allowed, Axmud tests whether a | ||
| 159 | # workspace grid can be placed on it. If that test fails, Axmud takes the following | ||
| 160 | # action: | ||
| 161 | # - If it's the default (first) workspace, the workspace object's | ||
| 162 | # ->gridEnableFlag is set to FALSE. Windows are not arranged on a grid on that | ||
| 163 | # single workspace, and no more workspace objects can be created | ||
| 164 | # - For subsequent workspaces, if the test fails that workspace object is deleted, | ||
| 165 | # and windows can only be opened on previously-created workspaces | ||
| 166 | # In either case, if the test fails, this flag is set to FALSE to prevent more | ||
| 167 | # workspaces being created | ||
| 168 | newWorkspaceFlag => TRUE, | ||
| 169 | |||
| 170 | # A list of Gtk3::Gdk::Pixbufs corresponding to the icons stored in the '/icons/win' | ||
| 171 | # sub-directory for 'main' windows | ||
| 172 | mainWinIconList => [], | ||
| 173 | # A list of Gtk3::Gdk::Pixbufs for 'map' windows | ||
| 174 | mapWinIconList => [], | ||
| 175 | # A list of Gtk3::Gdk::Pixbufs for 'protocol' windows | ||
| 176 | protocolWinIconList => [], | ||
| 177 | # A list of Gtk3::Gdk::Pixbufs for 'fixed' windows | ||
| 178 | fixedWinIconList => [], | ||
| 179 | # A list of Gtk3::Gdk::Pixbufs for 'custom' windows | ||
| 180 | customWinIconList => [], | ||
| 181 | # A list of Gtk3::Gdk::Pixbufs for 'external' windows (the pixbufs are created, but not | ||
| 182 | # used - 'external' windows keep their own icons) | ||
| 183 | externalWinIconList => [], | ||
| 184 | |||
| 185 | # A list of Gtk3::Gdk::Pixbufs for 'viewer' windows | ||
| 186 | viewerWinIconList => [], | ||
| 187 | # A list of Gtk3::Gdk::Pixbufs for 'edit' windows | ||
| 188 | editWinIconList => [], | ||
| 189 | # A list of Gtk3::Gdk::Pixbufs for 'pref' windows | ||
| 190 | prefWinIconList => [], | ||
| 191 | # A list of Gtk3::Gdk::Pixbufs for 'wiz' windows | ||
| 192 | wizWinIconList => [], | ||
| 193 | # A list of Gtk3::Gdk::Pixbufs for 'dialogue' windows | ||
| 194 | dialogueWinIconList => [], | ||
| 195 | # A list of Gtk3::Gdk::Pixbufs for 'other' windows | ||
| 196 | otherWinIconList => [], | ||
| 197 | }; | ||
| 198 | |||
| 199 | # Bless the object into existence | ||
| 200 | bless $self, $class; | ||
| 201 | |||
| 202 | return $self; | ||
| 203 | } | ||
| 204 | |||
| 205 | ################## | ||
| 206 | # Methods | ||
| 207 | |||
| 208 | sub start { | ||
| 209 | |||
| 210 | # Called by GA::Client->start immediately after the call to $self->new | ||
| 211 | # Sets up pixbufs for all window icons, then sets up workspaces, then creates a spare 'main' | ||
| 212 | # window, which doesn't belong to any session, and which will be re-used by the first | ||
| 213 | # session that opens | ||
| 214 | # | ||
| 215 | # Expected arguments | ||
| 216 | # (none besides $self) | ||
| 217 | # | ||
| 218 | # Return values | ||
| 219 | # 'undef' on improper arguments or if the start process fails | ||
| 220 | # 1 otherwise | ||
| 221 | |||
| 222 | my ($self, $check) = @_; | ||
| 223 | |||
| 224 | # Local variables | ||
| 225 | my ($wmCtrlObj, $zonemap, $screen, $workspace, $workspaceObj, $winObj); | ||
| 226 | |||
| 227 | # Check for improper arguments | ||
| 228 | if (defined $check) { | ||
| 229 | |||
| 230 | return $axmud::CLIENT->writeImproper($self->_objClass . '->start', @_); | ||
| 231 | } | ||
| 232 | |||
| 233 | # Set up pixbufs for all Axmud-created windows | ||
| 234 | if (! $self->prepareIcons()) { | ||
| 235 | |||
| 236 | $axmud::CLIENT->writeWarning( | ||
| 237 | 'Could not create icon pixbufs for windows', | ||
| 238 | $self->_objClass . '->start', | ||
| 239 | ); | ||
| 240 | } | ||
| 241 | |||
| 242 | # Set a default workspace number, which the code below may update. On X11::WMCtrl, | ||
| 243 | # workspaces are zero-indexed | ||
| 244 | $workspace = 0; | ||
| 245 | |||
| 246 | # On Axmud 'blind' mode, workspace grids are currently disabled in all circumstances | ||
| 247 | if ($axmud::BLIND_MODE_FLAG) { | ||
| 248 | |||
| 249 | $self->ivPoke('gridPermitFlag', FALSE); | ||
| 250 | |||
| 251 | # Otherwise, set up wmctrl (on compatible systems; it definitely won't work on MS Windows, | ||
| 252 | # and if it's not installed on a Linux system, we'll just disable multiple workspaces) | ||
| 253 | } elsif ($^O ne 'MSWin32') { | ||
| 254 | |||
| 255 | $wmCtrlObj = Games::Axmud::Obj::WMCtrl->new(); | ||
| 256 | if ($wmCtrlObj) { | ||
| 257 | |||
| 258 | $self->ivPoke('wmCtrlObj', $wmCtrlObj); | ||
| 259 | |||
| 260 | # Create a test window | ||
| 261 | my $testWin = Gtk3::Window->new('toplevel'); | ||
| 262 | $testWin->set_title('test_wmctrl'); | ||
| 263 | $testWin->set_size_request(100, 100); | ||
| 264 | $testWin->set_opacity(0); | ||
| 265 | $testWin->set_skip_taskbar_hint(TRUE); | ||
| 266 | $testWin->set_skip_pager_hint(TRUE); | ||
| 267 | $testWin->show_all(); | ||
| 268 | $self->updateWidgets($self->_objClass . '->start'); | ||
| 269 | |||
| 270 | # Work out in which workspace the test window opened, if possible (or continue using | ||
| 271 | # the default value of $workspace, if not) | ||
| 272 | OUTER: foreach my $hashRef ($wmCtrlObj->get_windows()) { | ||
| 273 | |||
| 274 | if ($hashRef->{title} eq 'test_wmctrl') { | ||
| 275 | |||
| 276 | $workspace = $hashRef->{workspace}; | ||
| 277 | last OUTER; | ||
| 278 | } | ||
| 279 | } | ||
| 280 | |||
| 281 | # Destroy the test window immediately | ||
| 282 | $testWin->destroy(); | ||
| 283 | } | ||
| 284 | } | ||
| 285 | |||
| 286 | # GA::Client->initWorkspaceHash should contain at least the following key-value pair: | ||
| 287 | # ->initWorkspaceHash{0} = default_zonemap_for_default_workspace | ||
| 288 | # If it doesn't (for some reason), get the default workspace's default zonemap from the | ||
| 289 | # constant hash instead | ||
| 290 | if (! $axmud::CLIENT->ivExists('initWorkspaceHash', 0)) { | ||
| 291 | $zonemap = $axmud::CLIENT->ivShow('constInitWorkspaceHash', 0); | ||
| 292 | } else { | ||
| 293 | $zonemap = $axmud::CLIENT->ivShow('initWorkspaceHash', 0); | ||
| 294 | } | ||
| 295 | |||
| 296 | # Create the default (first) workspace object, representing the workspace in which Axmud | ||
| 297 | # starts | ||
| 298 | $workspaceObj = $self->add_workspace($workspace); | ||
| 299 | if (! $workspaceObj) { | ||
| 300 | |||
| 301 | return $axmud::CLIENT->writeError( | ||
| 302 | 'Could not set up default workspace', | ||
| 303 | $self->_objClass . '->start', | ||
| 304 | ); | ||
| 305 | |||
| 306 | } else { | ||
| 307 | |||
| 308 | $self->ivPoke('defaultWorkspaceObj', $workspaceObj); | ||
| 309 | |||
| 310 | # Find the available size of the workspace, panels and window controls. Set the | ||
| 311 | # workspace's default zonemap | ||
| 312 | $workspaceObj->start($zonemap); | ||
| 313 | |||
| 314 | # The default workspace object performs certain tests on the workspace. If those tests | ||
| 315 | # fail, workspace grids are disabled on that workspace and no additional workspaces | ||
| 316 | # are used | ||
| 317 | if (! $workspaceObj->gridEnableFlag) { | ||
| 318 | |||
| 319 | $self->ivPoke('gridPermitFlag', FALSE); | ||
| 320 | $self->ivPoke('newWorkspaceFlag', FALSE); | ||
| 321 | } | ||
| 322 | } | ||
| 323 | |||
| 324 | # Create the spare 'main' window on the default workspace, but not placed onto any | ||
| 325 | # workspace grid | ||
| 326 | # (Don't do it in Axmud test mode, which skips the Connections window and goes straight to | ||
| 327 | # the first session) | ||
| 328 | if (! $axmud::TEST_MODE_FLAG) { | ||
| 329 | |||
| 330 | $winObj = $workspaceObj->createSimpleGridWin( | ||
| 331 | 'main', # Window type | ||
| 332 | 'main', # Window name | ||
| 333 | undef, # Window title set automatically | ||
| 334 | 'main_wait', # Use a minimal winmap, replaced by first session | ||
| 335 | 'Games::Axmud::Win::Internal', # Package name | ||
| 336 | undef, # No known Gtk3::Window | ||
| 337 | undef, # No system internal ID | ||
| 338 | $axmud::CLIENT, # Owner | ||
| 339 | undef, # No owner session | ||
| 340 | ); | ||
| 341 | |||
| 342 | if (! $winObj) { | ||
| 343 | |||
| 344 | return $axmud::CLIENT->writeError( | ||
| 345 | 'Could not create spare \'main\' window', | ||
| 346 | $self->_objClass . '->start', | ||
| 347 | ); | ||
| 348 | |||
| 349 | } else { | ||
| 350 | |||
| 351 | # (GA::Client->mainWin is normally set by calls to GA::Client->setCurrentSession) | ||
| 352 | $axmud::CLIENT->set_mainWin($winObj); | ||
| 353 | } | ||
| 354 | } | ||
| 355 | |||
| 356 | return 1; | ||
| 357 | } | ||
| 358 | |||
| 359 | sub stop { | ||
| 360 | |||
| 361 | # Called by GA::Client->stop | ||
| 362 | # Closes any remaining 'internal' windows, restores 'external' windows to their original | ||
| 363 | # size/position, closes any remaining 'free' windows | ||
| 364 | # | ||
| 365 | # Expected arguments | ||
| 366 | # (none besides $self) | ||
| 367 | # | ||
| 368 | # Return values | ||
| 369 | # 'undef' on improper arguments | ||
| 370 | # 1 otherwise | ||
| 371 | |||
| 372 | my ($self, $check) = @_; | ||
| 373 | |||
| 374 | # Local variables | ||
| 375 | my ($workspaceCount, $gridCount, $gridWinCount, $freeWinCount, $textViewCount, $msg); | ||
| 376 | |||
| 377 | # Check for improper arguments | ||
| 378 | if (defined $check) { | ||
| 379 | |||
| 380 | return $axmud::CLIENT->writeImproper($self->_objClass . '->stop', @_); | ||
| 381 | } | ||
| 382 | |||
| 383 | # Close down workspace objects (which closes down its workspace grids and windows), youngest | ||
| 384 | # first | ||
| 385 | foreach my $workspaceObj ( | ||
| 386 | sort {$b->number <=> $a->number} ($self->ivValues('workspaceHash')) | ||
| 387 | ) { | ||
| 388 | if ($workspaceObj->number != 0) { | ||
| 389 | |||
| 390 | $self->del_workspace($workspaceObj); | ||
| 391 | |||
| 392 | } else { | ||
| 393 | |||
| 394 | $workspaceObj->stop(); | ||
| 395 | $self->ivDelete('workspaceHash', 0); | ||
| 396 | } | ||
| 397 | } | ||
| 398 | |||
| 399 | $self->ivUndef('defaultWorkspaceObj'); | ||
| 400 | |||
| 401 | # Check there are no workspaces, workspace grids, 'grid' windows, 'free' windows or | ||
| 402 | # textviews left (for error-detection purposes) | ||
| 403 | $workspaceCount = $self->ivPairs('workspaceHash'); | ||
| 404 | if ($workspaceCount) { | ||
| 405 | |||
| 406 | if ($workspaceCount == 1) { | ||
| 407 | $msg = 'There was 1 un-closed workspace object'; | ||
| 408 | } else { | ||
| 409 | $msg = 'There were ' . $workspaceCount . ' un-closed workspace objects'; | ||
| 410 | } | ||
| 411 | |||
| 412 | $msg .= ' on desktop shutdown'; | ||
| 413 | |||
| 414 | $axmud::CLIENT->writeWarning($msg, $self->_objClass . '->stop'); | ||
| 415 | } | ||
| 416 | |||
| 417 | $gridCount = $self->ivPairs('gridHash'); | ||
| 418 | if ($gridCount) { | ||
| 419 | |||
| 420 | if ($gridCount == 1) { | ||
| 421 | $msg = 'There was 1 un-closed workspace grid object'; | ||
| 422 | } else { | ||
| 423 | $msg = 'There were ' . $gridCount . ' un-closed workspace grid objects'; | ||
| 424 | } | ||
| 425 | |||
| 426 | $msg .= ' on desktop shutdown'; | ||
| 427 | |||
| 428 | $axmud::CLIENT->writeWarning($msg, $self->_objClass . '->stop'); | ||
| 429 | } | ||
| 430 | |||
| 431 | $gridWinCount = $self->ivPairs('gridWinHash'); | ||
| 432 | if ($gridWinCount) { | ||
| 433 | |||
| 434 | if ($gridWinCount == 1) { | ||
| 435 | $msg = 'There was 1 un-closed \'grid\' window object'; | ||
| 436 | } else { | ||
| 437 | $msg = 'There were ' . $gridWinCount . ' un-closed \'grid\' window objects'; | ||
| 438 | } | ||
| 439 | |||
| 440 | $msg .= ' on desktop shutdown'; | ||
| 441 | |||
| 442 | $axmud::CLIENT->writeWarning($msg, $self->_objClass . '->stop'); | ||
| 443 | } | ||
| 444 | |||
| 445 | $freeWinCount = $self->ivPairs('freeWinHash'); | ||
| 446 | if ($freeWinCount) { | ||
| 447 | |||
| 448 | if ($freeWinCount == 1) { | ||
| 449 | $msg = 'There was 1 un-closed \'free\' window object'; | ||
| 450 | } else { | ||
| 451 | $msg = 'There were ' . $freeWinCount . ' un-closed \'free\' window objects'; | ||
| 452 | } | ||
| 453 | |||
| 454 | $msg .= ' on desktop shutdown'; | ||
| 455 | |||
| 456 | $axmud::CLIENT->writeWarning($msg, $self->_objClass . '->stop'); | ||
| 457 | } | ||
| 458 | |||
| 459 | $textViewCount = $self->ivPairs('textViewHash'); | ||
| 460 | if ($textViewCount) { | ||
| 461 | |||
| 462 | if ($textViewCount == 1) { | ||
| 463 | $msg = 'There was 1 un-closed textview object'; | ||
| 464 | } else { | ||
| 465 | $msg = 'There were ' . $textViewCount . ' un-closed textview objects'; | ||
| 466 | } | ||
| 467 | |||
| 468 | $msg .= ' on desktop shutdown'; | ||
| 469 | |||
| 470 | $axmud::CLIENT->writeWarning($msg, $self->_objClass . '->stop'); | ||
| 471 | } | ||
| 472 | |||
| 473 | return 1; | ||
| 474 | } | ||
| 475 | |||
| 476 | sub setupWorkspaces { | ||
| 477 | |||
| 478 | # Called by GA::Client->start | ||
| 479 | # The earlier call to $self->start sets up the default workspace; this function sets up | ||
| 480 | # any further workspaces specified by GA::Client->initWorkspaceHash | ||
| 481 | # Each workspace is handled by a workspace object (GA::Obj::Workspace). The workspace object | ||
| 482 | # performs certain tests on the workspace. If those tests fail, that workspace is not | ||
| 483 | # used, the workspace object is discarded, and no additional workspaces are used | ||
| 484 | # If the test failed on the default workspace created by $self->start, that workspace is | ||
| 485 | # still used, but this function uses no additional workspaces | ||
| 486 | # If $self->newWorkspaceFlag was set to FALSE by $self->start, this function uses no | ||
| 487 | # additional workspaces | ||
| 488 | # | ||
| 489 | # Expected arguments | ||
| 490 | # (none besides $self) | ||
| 491 | # | ||
| 492 | # Return values | ||
| 493 | # 'undef' on improper arguments | ||
| 494 | # 1 otherwise | ||
| 495 | |||
| 496 | my ($self, $check) = @_; | ||
| 497 | |||
| 498 | # Local variables | ||
| 499 | my @useList; | ||
| 500 | |||
| 501 | # Check for improper arguments | ||
| 502 | if (defined $check) { | ||
| 503 | |||
| 504 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setupWorkspaces', @_); | ||
| 505 | } | ||
| 506 | |||
| 507 | if ($self->wmCtrlObj && $self->gridPermitFlag && $self->newWorkspaceFlag) { | ||
| 508 | |||
| 509 | # Get a list of system workspace numbers (zero-indexed), in the order in which they | ||
| 510 | # should be used. The order depends on GA::Client->initWorkspaceDir; the returned list | ||
| 511 | # doesn't include the default workspace | ||
| 512 | @useList = $self->detectWorkspaces(); | ||
| 513 | |||
| 514 | # GA::Client->specifies the workspaces that Axmud should use initially. If it specifies | ||
| 515 | # more workspaces than the 'default' one, create a new workspace object for each of | ||
| 516 | # them (but not if we've run out of available workspaces) | ||
| 517 | foreach my $index (sort {$a <=> $b} ($axmud::CLIENT->ivKeys('initWorkspaceHash'))) { | ||
| 518 | |||
| 519 | my ($workspace, $zonemap, $workspaceObj); | ||
| 520 | |||
| 521 | # The default workspace, numbered 0, already has a GA::Obj::Workspace | ||
| 522 | if ($index) { | ||
| 523 | |||
| 524 | $workspace = shift @useList; | ||
| 525 | $zonemap = $axmud::CLIENT->ivShow('initWorkspaceHash', $index); | ||
| 526 | if ($workspace) { | ||
| 527 | |||
| 528 | $self->useWorkspace($workspace, $zonemap); | ||
| 529 | } | ||
| 530 | } | ||
| 531 | } | ||
| 532 | } | ||
| 533 | |||
| 534 | return 1; | ||
| 535 | } | ||
| 536 | |||
| 537 | sub useWorkspace { | ||
| 538 | |||
| 539 | # Called by $self->setupWorkspaces or GA::Cmd::UseWorkspace->do | ||
| 540 | # Creates a workspace object (GA::Obj::Workspace) for the system workspace | ||
| 541 | # | ||
| 542 | # Expected arguments | ||
| 543 | # $workspace - The system workspace number to use | ||
| 544 | # | ||
| 545 | # Optional arguments | ||
| 546 | # $zonemap - The name of the default zonemap for the workspace object. If 'undef', | ||
| 547 | # this function chooses a default zonemap | ||
| 548 | # | ||
| 549 | # Return values | ||
| 550 | # 'undef' on improper arguments, if new workspaces can't be added, if the workspace object | ||
| 551 | # can't be created or if tests performed on the workspace fail | ||
| 552 | # Otherwise returns the blessed reference of the workspace object created | ||
| 553 | |||
| 554 | my ($self, $workspace, $zonemap, $check) = @_; | ||
| 555 | |||
| 556 | # Local variables | ||
| 557 | my $workspaceObj; | ||
| 558 | |||
| 559 | # Check for improper arguments | ||
| 560 | if (! defined $workspace || defined $check) { | ||
| 561 | |||
| 562 | return $axmud::CLIENT->writeImproper($self->_objClass . '->useWorkspace', @_); | ||
| 563 | } | ||
| 564 | |||
| 565 | # If tests failed during a previous call to this function, use no additional workspaces | ||
| 566 | if (! $self->newWorkspaceFlag) { | ||
| 567 | |||
| 568 | return undef; | ||
| 569 | } | ||
| 570 | |||
| 571 | # If no default zonemap was specified, choose one | ||
| 572 | if (! $zonemap) { | ||
| 573 | |||
| 574 | if ($axmud::CLIENT->shareMainWinFlag) { | ||
| 575 | $zonemap = 'basic'; | ||
| 576 | } else { | ||
| 577 | $zonemap = 'horizontal'; | ||
| 578 | } | ||
| 579 | } | ||
| 580 | |||
| 581 | # Create the workspace object and set it up | ||
| 582 | $workspaceObj = $self->add_workspace($workspace); | ||
| 583 | if (! $workspaceObj) { | ||
| 584 | |||
| 585 | return undef; | ||
| 586 | |||
| 587 | } else { | ||
| 588 | |||
| 589 | $workspaceObj->start($zonemap); | ||
| 590 | |||
| 591 | # $workspaceObj->start performed certain tests on the workspace. If those tests failed, | ||
| 592 | # that workspace object must be discarded and no additional workspaces can be used | ||
| 593 | if (! $workspaceObj->gridEnableFlag) { | ||
| 594 | |||
| 595 | $self->ivPoke('newWorkspaceFlag', FALSE); | ||
| 596 | $self->del_workspace($workspaceObj); | ||
| 597 | |||
| 598 | return undef; | ||
| 599 | |||
| 600 | } else { | ||
| 601 | |||
| 602 | return $workspaceObj; | ||
| 603 | } | ||
| 604 | } | ||
| 605 | } | ||
| 606 | |||
| 607 | sub detectWorkspaces { | ||
| 608 | |||
| 609 | # Called by $self->setupWorkspaces and $self->detectUnusedWorkspaces | ||
| 610 | # Returns a list of system workspace numbers, in the order in which they should be used | ||
| 611 | # System workspaces are zero-indexed. The order of the returned list depends on | ||
| 612 | # GA::Client->initWorkspaceDir; the returned list doesn't include the default workspace | ||
| 613 | # | ||
| 614 | # Expected arguments | ||
| 615 | # (none besides $self) | ||
| 616 | # | ||
| 617 | # Return values | ||
| 618 | # An empty list on improper arguments | ||
| 619 | # Otherwise returns the list of system workspace numbers | ||
| 620 | |||
| 621 | my ($self, $check) = @_; | ||
| 622 | |||
| 623 | # Local variables | ||
| 624 | my ( | ||
| 625 | $workspace, $hashRef, $total, $otherWorkspace, | ||
| 626 | @emptyList, @useList, | ||
| 627 | ); | ||
| 628 | |||
| 629 | # Check for improper arguments | ||
| 630 | if (defined $check) { | ||
| 631 | |||
| 632 | $axmud::CLIENT->writeImproper($self->_objClass . '->detectWorkspaces', @_); | ||
| 633 | return @emptyList; | ||
| 634 | } | ||
| 635 | |||
| 636 | # Get the workspace system number of Axmud's default workspace | ||
| 637 | $workspace = $self->defaultWorkspaceObj->systemNum; | ||
| 638 | # Get the number of system workspaces that actually exist | ||
| 639 | $hashRef = $self->wmCtrlObj->get_workspaces(); | ||
| 640 | $total = scalar (keys %$hashRef); | ||
| 641 | |||
| 642 | # 'move_left' - move left from the default workspace until we reach the left-most | ||
| 643 | # workspace (and then stop) | ||
| 644 | if ($axmud::CLIENT->initWorkspaceDir eq 'move_left') { | ||
| 645 | |||
| 646 | do { | ||
| 647 | |||
| 648 | $otherWorkspace = $workspace - 1; | ||
| 649 | if ($otherWorkspace) { | ||
| 650 | |||
| 651 | push (@useList, $otherWorkspace); | ||
| 652 | $workspace = $otherWorkspace; | ||
| 653 | } | ||
| 654 | |||
| 655 | } until (! $otherWorkspace); | ||
| 656 | |||
| 657 | # 'move_right' - move right from the default workspace until we reach the right-most | ||
| 658 | # workspace (and then stop) | ||
| 659 | } elsif ($axmud::CLIENT->initWorkspaceDir eq 'move_right') { | ||
| 660 | |||
| 661 | do { | ||
| 662 | |||
| 663 | $otherWorkspace = $workspace + 1; | ||
| 664 | if ($otherWorkspace < $total) { | ||
| 665 | |||
| 666 | push (@useList, $otherWorkspace); | ||
| 667 | $workspace = $otherWorkspace; | ||
| 668 | } | ||
| 669 | |||
| 670 | } until ($otherWorkspace >= $total); | ||
| 671 | |||
| 672 | # 'start_left' - after finding the default workspace, the next workspace should be the | ||
| 673 | # left-most one, after that move right until we reach the right-most | ||
| 674 | # workspace (and then stop) | ||
| 675 | } elsif ($axmud::CLIENT->initWorkspaceDir eq 'start_left') { | ||
| 676 | |||
| 677 | foreach my $otherWorkspace (sort {$a <=> $b} (keys %$hashRef)) { | ||
| 678 | |||
| 679 | if ($otherWorkspace != $workspace) { | ||
| 680 | |||
| 681 | push (@useList, $otherWorkspace); | ||
| 682 | } | ||
| 683 | } | ||
| 684 | |||
| 685 | # 'start_right' - after finding the default workspace, the next workspace should be the | ||
| 686 | # right-most one, after that move left until we reach the left-most workspace (and then | ||
| 687 | # stop) | ||
| 688 | } elsif ($axmud::CLIENT->initWorkspaceDir eq 'start_right') { | ||
| 689 | |||
| 690 | foreach my $otherWorkspace (sort {$b <=> $a} (keys %$hashRef)) { | ||
| 691 | |||
| 692 | if ($otherWorkspace != $workspace) { | ||
| 693 | |||
| 694 | push (@useList, $otherWorkspace); | ||
| 695 | } | ||
| 696 | } | ||
| 697 | } | ||
| 698 | |||
| 699 | return @useList; | ||
| 700 | } | ||
| 701 | |||
| 702 | sub detectUnusedWorkspaces { | ||
| 703 | |||
| 704 | # Called by GA::Cmd::ListWorkspace->do | ||
| 705 | # Calls $self->detectWorkspaces to get a list of system workspace numbers, then removes from | ||
| 706 | # that list any workspace already in use by Axmud (i.e. any workspace for which there is a | ||
| 707 | # workspace object, GA::Obj::Workspace) | ||
| 708 | # Returns a list of the remaining system workspaces numbers (which may be empty) | ||
| 709 | # | ||
| 710 | # Expected arguments | ||
| 711 | # (none besides $self) | ||
| 712 | # | ||
| 713 | # Return values | ||
| 714 | # An empty list on improper arguments or if there are no unused workspaces | ||
| 715 | # Otherwise returns the list of system workspace numbers (which may be empty) | ||
| 716 | |||
| 717 | my ($self, $check) = @_; | ||
| 718 | |||
| 719 | # Local variables | ||
| 720 | my (@emptyList, @modList); | ||
| 721 | |||
| 722 | # Check for improper arguments | ||
| 723 | if (defined $check) { | ||
| 724 | |||
| 725 | $axmud::CLIENT->writeImproper($self->_objClass . '->detectUnusedWorkspaces', @_); | ||
| 726 | return @emptyList; | ||
| 727 | } | ||
| 728 | |||
| 729 | if (! $self->wmCtrlObj) { | ||
| 730 | |||
| 731 | # X11::WMCtrl not available, so cannot detect workspaces | ||
| 732 | return @emptyList; | ||
| 733 | |||
| 734 | } else { | ||
| 735 | |||
| 736 | OUTER: foreach my $workspace ($self->detectWorkspaces()) { | ||
| 737 | |||
| 738 | INNER: foreach my $workspaceObj ($self->ivValues('workspaceHash')) { | ||
| 739 | |||
| 740 | if ($workspaceObj->systemNum eq $workspace) { | ||
| 741 | |||
| 742 | next OUTER; | ||
| 743 | } | ||
| 744 | } | ||
| 745 | |||
| 746 | # This workspace is unused | ||
| 747 | push (@modList, $workspace); | ||
| 748 | } | ||
| 749 | |||
| 750 | # Operation complete | ||
| 751 | return @modList; | ||
| 752 | } | ||
| 753 | } | ||
| 754 | |||
| 755 | sub listWorkspaces { | ||
| 756 | |||
| 757 | # Can be called by any function that wants to create a new 'grid' window | ||
| 758 | # If the function wants the window to appear on a particular workspace only, it can call | ||
| 759 | # GA::Obj::Workspace->createGridWin directly | ||
| 760 | # If it wants the window to appear on the first available workspace, it can call this | ||
| 761 | # function first. This function returns an ordered list of workspaces, with the preferred | ||
| 762 | # workspace (if specified) first in the list. The calling function can then call | ||
| 763 | # GA::Obj::Workspace->createGridWin for each workspace on the list until a new window | ||
| 764 | # object is actually created | ||
| 765 | # | ||
| 766 | # Expected arguments | ||
| 767 | # (none besides $self) | ||
| 768 | # | ||
| 769 | # Optional arguments | ||
| 770 | # $preferObj - The preferred GA::Obj::Workspace. If specified, it is placed at the | ||
| 771 | # beginning of the returned list, and the remaining workspace objects are | ||
| 772 | # added to the list in the order in which they were created. If not | ||
| 773 | # specified, all workspace objects are added to the returned list in the | ||
| 774 | # order in which they were created, the 'default' workspace first | ||
| 775 | # | ||
| 776 | # Return values | ||
| 777 | # An empty list on improper arguments | ||
| 778 | # Otherwise, the list of GA::Obj::Workspace objects described above | ||
| 779 | |||
| 780 | my ($self, $preferObj, $check) = @_; | ||
| 781 | |||
| 782 | # Local variables | ||
| 783 | my (@emptyList, @returnList); | ||
| 784 | |||
| 785 | # Check for improper arguments | ||
| 786 | if (defined $check) { | ||
| 787 | |||
| 788 | $axmud::CLIENT->writeImproper($self->_objClass . '->listWorkspaces', @_); | ||
| 789 | return @emptyList; | ||
| 790 | } | ||
| 791 | |||
| 792 | foreach my $workspaceNum (sort {$a <=> $b} ($self->ivKeys('workspaceHash'))) { | ||
| 793 | |||
| 794 | my $workspaceObj = $self->ivShow('workspaceHash', $workspaceNum); | ||
| 795 | |||
| 796 | if (! defined $preferObj || $preferObj ne $workspaceObj) { | ||
| 797 | |||
| 798 | push (@returnList, $workspaceObj); | ||
| 799 | } | ||
| 800 | } | ||
| 801 | |||
| 802 | if (defined $preferObj) { | ||
| 803 | |||
| 804 | unshift (@returnList, $preferObj); | ||
| 805 | } | ||
| 806 | |||
| 807 | return @returnList; | ||
| 808 | } | ||
| 809 | |||
| 810 | sub removeSessionWorkspaceGrids { | ||
| 811 | |||
| 812 | # Called by GA::Session->stop | ||
| 813 | # If each session has its own workspace grids, remove them (which closes any 'grid' windows | ||
| 814 | # on the workspace grid, except for that session's 'main' window) | ||
| 815 | # If sessions share a single workspace grid, do nothing | ||
| 816 | # | ||
| 817 | # Expected arguments | ||
| 818 | # $session - The GA::Session which is closing | ||
| 819 | # | ||
| 820 | # Return values | ||
| 821 | # 'undef' on improper arguments | ||
| 822 | # 1 otherwise | ||
| 823 | |||
| 824 | my ($self, $session, $check) = @_; | ||
| 825 | |||
| 826 | # Check for improper arguments | ||
| 827 | if (! defined $session || defined $check) { | ||
| 828 | |||
| 829 | return $axmud::CLIENT->writeImproper( | ||
| 830 | $self->_objClass . '->removeSessionWorkspaceGrids', | ||
| 831 | @_, | ||
| 832 | ); | ||
| 833 | } | ||
| 834 | |||
| 835 | if ($axmud::CLIENT->shareMainWinFlag) { | ||
| 836 | |||
| 837 | foreach my $workspaceGridObj ( | ||
| 838 | sort {$a->number <=> $b->number} ($self->ivValues('gridHash')) | ||
| 839 | ) { | ||
| 840 | if ($workspaceGridObj->owner && $workspaceGridObj->owner eq $session) { | ||
| 841 | |||
| 842 | $workspaceGridObj->workspaceObj->removeWorkspaceGrid( | ||
| 843 | $workspaceGridObj, | ||
| 844 | $session, | ||
| 845 | ); | ||
| 846 | } | ||
| 847 | } | ||
| 848 | } | ||
| 849 | |||
| 850 | return 1; | ||
| 851 | } | ||
| 852 | |||
| 853 | sub removeSessionWindows { | ||
| 854 | |||
| 855 | # Called by GA::Session->stop | ||
| 856 | # When the session closes, the earlier call to $self->removeSessionWorkspaceGrids removes | ||
| 857 | # any workspace grids used exclusively by that session | ||
| 858 | # Look for any remaining 'grid' windows controlled by the session (there will probably be | ||
| 859 | # some if GA::CLIENT->shareMainWinFlag = FALSE). However, the session's 'main' window is | ||
| 860 | # not closed by this function | ||
| 861 | # | ||
| 862 | # Expected arguments | ||
| 863 | # $session - The GA::Session which is closing | ||
| 864 | # | ||
| 865 | # Return values | ||
| 866 | # 'undef' on improper arguments | ||
| 867 | # 1 otherwise | ||
| 868 | |||
| 869 | my ($self, $session, $check) = @_; | ||
| 870 | |||
| 871 | # Check for improper arguments | ||
| 872 | if (! defined $session || defined $check) { | ||
| 873 | |||
| 874 | return $axmud::CLIENT->writeImproper($self->_objClass . '->removeSessionWindows', @_); | ||
| 875 | } | ||
| 876 | |||
| 877 | foreach my $gridWinObj ($self->ivValues('gridWinHash')) { | ||
| 878 | |||
| 879 | if ( | ||
| 880 | $gridWinObj->winType ne 'main' | ||
| 881 | && ( | ||
| 882 | ($gridWinObj->session && $gridWinObj->session eq $session) | ||
| 883 | # Possible, though unlikely, that ->owner is set, but ->session isn't | ||
| 884 | || ($gridWinObj->owner && $gridWinObj->owner eq $session) | ||
| 885 | ) | ||
| 886 | ) { | ||
| 887 | $gridWinObj->winDestroy(); | ||
| 888 | } | ||
| 889 | } | ||
| 890 | |||
| 891 | return 1; | ||
| 892 | } | ||
| 893 | |||
| 894 | sub activateWorkspaceGrids { | ||
| 895 | |||
| 896 | # Called by GA::Cmd::ActivateGrid->do | ||
| 897 | # For every workspace object, creates workspace grids for every session (or a single | ||
| 898 | # workspace grid, if sessions don't share a 'main' window), places existing windows on the | ||
| 899 | # correct grid and updates IVs | ||
| 900 | # If workspace grids are already activated generally, does nothing | ||
| 901 | # | ||
| 902 | # Expected arguments | ||
| 903 | # (none besides $self) | ||
| 904 | # | ||
| 905 | # Optional arguments | ||
| 906 | # $zonemap - If specified, the name of the zonemap (matches a key in | ||
| 907 | # GA::Client->zonemapHash) to be used as the default zonemap on every | ||
| 908 | # workspace (and which is applied to every new workspace grid) | ||
| 909 | # | ||
| 910 | # Return values | ||
| 911 | # 'undef' on improper arguments | ||
| 912 | # 1 otherwise | ||
| 913 | |||
| 914 | my ($self, $zonemap, $check) = @_; | ||
| 915 | |||
| 916 | # Check for improper arguments | ||
| 917 | if (defined $check) { | ||
| 918 | |||
| 919 | return $axmud::CLIENT->writeImproper( | ||
| 920 | $self->_objClass . '->activateWorkspaceGrids', | ||
| 921 | @_, | ||
| 922 | ); | ||
| 923 | } | ||
| 924 | |||
| 925 | if (! $axmud::CLIENT->activateGridFlag) { | ||
| 926 | |||
| 927 | $axmud::CLIENT->set_activateGridFlag(TRUE); | ||
| 928 | |||
| 929 | foreach my $workspaceObj ($self->ivValues('workspaceHash')) { | ||
| 930 | |||
| 931 | $workspaceObj->enableWorkspaceGrids($zonemap); | ||
| 932 | } | ||
| 933 | } | ||
| 934 | |||
| 935 | return 1; | ||
| 936 | } | ||
| 937 | |||
| 938 | sub disactivateWorkspaceGrids { | ||
| 939 | |||
| 940 | # Called by GA::Cmd::DisactivateGrid->do | ||
| 941 | # Disables workspace grids for every workspace object and updates IVs. If workspace grids | ||
| 942 | # are already disactivated generally, does nothing | ||
| 943 | # | ||
| 944 | # Expected arguments | ||
| 945 | # (none besides $self) | ||
| 946 | # | ||
| 947 | # Return values | ||
| 948 | # 'undef' on improper arguments | ||
| 949 | # 1 otherwise | ||
| 950 | |||
| 951 | my ($self, $check) = @_; | ||
| 952 | |||
| 953 | # Check for improper arguments | ||
| 954 | if (defined $check) { | ||
| 955 | |||
| 956 | return $axmud::CLIENT->writeImproper( | ||
| 957 | $self->_objClass . '->disactivateWorkspaceGrids', | ||
| 958 | @_, | ||
| 959 | ); | ||
| 960 | } | ||
| 961 | |||
| 962 | if ($axmud::CLIENT->activateGridFlag) { | ||
| 963 | |||
| 964 | foreach my $workspaceObj ($self->ivValues('workspaceHash')) { | ||
| 965 | |||
| 966 | $workspaceObj->disableWorkspaceGrids(); | ||
| 967 | } | ||
| 968 | |||
| 969 | $axmud::CLIENT->set_activateGridFlag(FALSE); | ||
| 970 | } | ||
| 971 | |||
| 972 | return 1; | ||
| 973 | } | ||
| 974 | |||
| 975 | sub prepareIcons { | ||
| 976 | |||
| 977 | # Called by $self->start | ||
| 978 | # Sets up Gtk3::Gdk::Pixbufs for use as icons in 'grid' and 'free' windows | ||
| 979 | # | ||
| 980 | # Expected arguments | ||
| 981 | # (none besides $self) | ||
| 982 | # | ||
| 983 | # Return values | ||
| 984 | # 'undef' on improper arguments or if there's an error in creating any pixbuf (even after | ||
| 985 | # an error, the function will continue trying to create icons) | ||
| 986 | # 1 otherwise | ||
| 987 | |||
| 988 | my ($self, $check) = @_; | ||
| 989 | |||
| 990 | # Local variables | ||
| 991 | my ( | ||
| 992 | $failFlag, | ||
| 993 | @list, | ||
| 994 | ); | ||
| 995 | |||
| 996 | # Check for improper arguments | ||
| 997 | if (defined $check) { | ||
| 998 | |||
| 999 | return $axmud::CLIENT->writeImproper($self->_objClass . '->prepareIcons', @_); | ||
| 1000 | } | ||
| 1001 | |||
| 1002 | # Compile a list of window types | ||
| 1003 | @list = ( | ||
| 1004 | $axmud::CLIENT->ivKeys('constGridWinTypeHash'), | ||
| 1005 | $axmud::CLIENT->ivKeys('constFreeWinTypeHash'), | ||
| 1006 | ); | ||
| 1007 | |||
| 1008 | # Different types of Axmud windows have their own icons | ||
| 1009 | OUTER: foreach my $type (@list) { | ||
| 1010 | |||
| 1011 | my @iconList; | ||
| 1012 | |||
| 1013 | INNER: foreach my $size ($axmud::CLIENT->constIconSizeList) { | ||
| 1014 | |||
| 1015 | my ($path, $icon); | ||
| 1016 | |||
| 1017 | # e.g. '/icons/win/icon_main_win_16.png' | ||
| 1018 | $path = $axmud::SHARE_DIR . '/icons/win/icon_' . $type . '_win_' . $size . '.png'; | ||
| 1019 | if (! -e $path) { | ||
| 1020 | |||
| 1021 | # Continue trying to create the other icons | ||
| 1022 | $failFlag = TRUE; | ||
| 1023 | |||
| 1024 | } else { | ||
| 1025 | |||
| 1026 | $icon = Gtk3::Gdk::Pixbuf->new_from_file($path); | ||
| 1027 | if (! $icon) { | ||
| 1028 | |||
| 1029 | # Continue trying to create the other icons | ||
| 1030 | $failFlag = TRUE; | ||
| 1031 | |||
| 1032 | } else { | ||
| 1033 | |||
| 1034 | push (@iconList, $icon); | ||
| 1035 | } | ||
| 1036 | } | ||
| 1037 | } | ||
| 1038 | |||
| 1039 | # Update IVs | ||
| 1040 | if (@iconList) { | ||
| 1041 | |||
| 1042 | $self->ivPush($type . 'WinIconList', @iconList); | ||
| 1043 | } | ||
| 1044 | } | ||
| 1045 | |||
| 1046 | if ($failFlag) { | ||
| 1047 | |||
| 1048 | # At least one icon couldn't be created | ||
| 1049 | return undef; | ||
| 1050 | |||
| 1051 | } else { | ||
| 1052 | |||
| 1053 | # All icons created | ||
| 1054 | return 1; | ||
| 1055 | } | ||
| 1056 | } | ||
| 1057 | |||
| 1058 | sub setTextViewStyle { | ||
| 1059 | |||
| 1060 | # Can be called by anything to set the CSS style for a Gtk3::Textview | ||
| 1061 | # However, Axmud textview objects (GA::Obj::TextView) only call ->setTextViewObjStyle | ||
| 1062 | # | ||
| 1063 | # Expected arguments | ||
| 1064 | # $scheme - The name of the colour scheme object (GA::Obj::ColourScheme) to use | ||
| 1065 | # $textView - The Gtk3::TextView whose CSS style should be set | ||
| 1066 | # | ||
| 1067 | # Return values | ||
| 1068 | # 'undef' on improper arguments | ||
| 1069 | # 1 otherwise | ||
| 1070 | |||
| 1071 | my ($self, $scheme, $textView, $check) = @_; | ||
| 1072 | |||
| 1073 | # Local variables | ||
| 1074 | my ($schemeObj, $provider, $display, $screen, $theming, $context); | ||
| 1075 | |||
| 1076 | # Check for improper arguments | ||
| 1077 | if (! defined $scheme || ! defined $textView || defined $check) { | ||
| 1078 | |||
| 1079 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setTextViewStyle', @_); | ||
| 1080 | } | ||
| 1081 | |||
| 1082 | # Get the named colour scheme object (GA::Obj::ColourScheme). If it doesn't exist, use the | ||
| 1083 | # 'dialogue' colour scheme as a backup | ||
| 1084 | $schemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', $scheme); | ||
| 1085 | if (! $schemeObj) { | ||
| 1086 | |||
| 1087 | $schemeObj = $axmud::CLIENT->ivShow('colourSchemeHash', 'dialogue'); | ||
| 1088 | } | ||
| 1089 | |||
| 1090 | # Prepare the theming data to use | ||
| 1091 | $provider = Gtk3::CssProvider->new(); | ||
| 1092 | $display = Gtk3::Gdk::Display::get_default(); | ||
| 1093 | $screen = Gtk3::Gdk::Display::get_default_screen($display); | ||
| 1094 | Gtk3::StyleContext::add_provider_for_screen($screen, $provider, 600); | ||
| 1095 | |||
| 1096 | $theming = "#css_text_id_" . $scheme . ", textview text {\n" | ||
| 1097 | . " background-color: " | ||
| 1098 | . $axmud::CLIENT->returnRGBColour($schemeObj->backgroundColour) . ";\n" | ||
| 1099 | . " color: " . $axmud::CLIENT->returnRGBColour($schemeObj->textColour) . ";\n" | ||
| 1100 | . "}\n" | ||
| 1101 | . "#css_label_id_" . $scheme . ", textview {\n"; | ||
| 1102 | |||
| 1103 | # v1.2.007 because of some Gtk/Pango issue, if we specify 'monospace' as a fallback font on | ||
| 1104 | # MS Windows, as we do on Linux, the fallback font overrides everything | ||
| 1105 | # Also, a 10pt is much larger on MS Windows, so use 10px instead | ||
| 1106 | if ($^O eq 'MSWin32') { | ||
| 1107 | |||
| 1108 | $theming | ||
| 1109 | .= " font-family: " . $schemeObj->font . ";\n" | ||
| 1110 | . " font-size: " . $schemeObj->fontSize . "px;\n" | ||
| 1111 | . "}"; | ||
| 1112 | |||
| 1113 | } else { | ||
| 1114 | |||
| 1115 | $theming | ||
| 1116 | .= " font-family: " . $schemeObj->font . ", monospace;\n" | ||
| 1117 | . " font-size: " . $schemeObj->fontSize . "pt;\n" | ||
| 1118 | . "}"; | ||
| 1119 | } | ||
| 1120 | |||
| 1121 | $provider->load_from_data ([map ord, split //, $theming]); | ||
| 1122 | |||
| 1123 | $context = $textView->get_style_context(); | ||
| 1124 | $context->add_provider($provider, 600); | ||
| 1125 | |||
| 1126 | return 1; | ||
| 1127 | } | ||
| 1128 | |||
| 1129 | sub setTextViewObjStyle { | ||
| 1130 | |||
| 1131 | # Called by several functions in Axmud textview objects (GA::Obj::TextView) to set the CSS | ||
| 1132 | # style for one or more Gtk3::TextViews | ||
| 1133 | # All other functions creating a Gtk3::TextView should call $self->setTextViewStyle | ||
| 1134 | # | ||
| 1135 | # Expected arguments | ||
| 1136 | # $number - The number of the textview object (GA::Obj::TextView) to which a CSS style | ||
| 1137 | # is being applied | ||
| 1138 | # | ||
| 1139 | # Optional arguments | ||
| 1140 | # $fgColour - The RGB colour to use for the foreground text, e.g. '#000000'. If 'undef', | ||
| 1141 | # the Axmud default colour is used | ||
| 1142 | # $bgColour - The RGB colour to use for the background, e.g. '#FFFFFF'. If 'undef', the | ||
| 1143 | # Axmud default colour is used | ||
| 1144 | # $font - The font to use in the new style | ||
| 1145 | # $fontSize - The font size to use in the new style. If either $font or $fontSize are | ||
| 1146 | # 'undef', the Axmud default font is used | ||
| 1147 | # @tvList - List of one or more Gtk3::TextViews. The CSS style is applied to any | ||
| 1148 | # element in this list which is defined (so 'undef' values are acceptable) | ||
| 1149 | # | ||
| 1150 | # Return values | ||
| 1151 | # 'undef' on improper arguments | ||
| 1152 | # 1 otherwise | ||
| 1153 | |||
| 1154 | my ($self, $number, $fgColour, $bgColour, $font, $fontSize, @tvList) = @_; | ||
| 1155 | |||
| 1156 | # Local variables | ||
| 1157 | my ($provider, $display, $screen, $theming); | ||
| 1158 | |||
| 1159 | # Check for improper arguments | ||
| 1160 | if (! defined $number) { | ||
| 1161 | |||
| 1162 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setTextViewObjStyle', @_); | ||
| 1163 | } | ||
| 1164 | |||
| 1165 | # Use Axmud default colours/fonts, if none were specified | ||
| 1166 | if (! defined $fgColour) { | ||
| 1167 | |||
| 1168 | $fgColour = $axmud::CLIENT->constTextColour; | ||
| 1169 | } | ||
| 1170 | |||
| 1171 | if (! defined $bgColour) { | ||
| 1172 | |||
| 1173 | $bgColour = $axmud::CLIENT->constBackgroundColour; | ||
| 1174 | } | ||
| 1175 | |||
| 1176 | $fgColour = $axmud::CLIENT->returnRGBColour($fgColour); | ||
| 1177 | $bgColour = $axmud::CLIENT->returnRGBColour($bgColour); | ||
| 1178 | |||
| 1179 | if (! defined $font || ! defined $fontSize) { | ||
| 1180 | |||
| 1181 | $font = $axmud::CLIENT->constFont; | ||
| 1182 | $fontSize = $axmud::CLIENT->constFontSize; | ||
| 1183 | } | ||
| 1184 | |||
| 1185 | # Prepare the theming data to use | ||
| 1186 | $provider = Gtk3::CssProvider->new(); | ||
| 1187 | $display = Gtk3::Gdk::Display::get_default(); | ||
| 1188 | $screen = Gtk3::Gdk::Display::get_default_screen($display); | ||
| 1189 | Gtk3::StyleContext::add_provider_for_screen($screen, $provider, 600); | ||
| 1190 | |||
| 1191 | $theming = "#css_tvobj_text_id_" . $number . ", textview text {\n" | ||
| 1192 | . " background-color: $bgColour;\n" | ||
| 1193 | . " color: $fgColour;\n" | ||
| 1194 | . "}\n" | ||
| 1195 | . "#css_tvobj_label_id_" . $number . ", textview {\n"; | ||
| 1196 | |||
| 1197 | # v1.2.007 because of some Gtk/Pango issue, if we specify 'monospace' as a fallback font on | ||
| 1198 | # MS Windows, as we do on Linux, the fallback font overrides everything | ||
| 1199 | # Also, a 10pt is much larger on MS Windows, so use 10px instead | ||
| 1200 | if ($^O eq 'MSWin32') { | ||
| 1201 | |||
| 1202 | $theming | ||
| 1203 | .= " font-family: $font;\n" | ||
| 1204 | . " font-size: ${fontSize}px;\n" | ||
| 1205 | . "}"; | ||
| 1206 | |||
| 1207 | } else { | ||
| 1208 | |||
| 1209 | |||
| 1210 | $theming | ||
| 1211 | .= " font-family: $font, monospace;\n" | ||
| 1212 | . " font-size: ${fontSize}pt;\n" | ||
| 1213 | . "}"; | ||
| 1214 | } | ||
| 1215 | |||
| 1216 | $provider->load_from_data ([map ord, split //, $theming]); | ||
| 1217 | |||
| 1218 | foreach my $textView (@tvList) { | ||
| 1219 | |||
| 1220 | if (defined $textView) { | ||
| 1221 | |||
| 1222 | my $context = $textView->get_style_context(); | ||
| 1223 | $context->add_provider($provider, 600); | ||
| 1224 | } | ||
| 1225 | } | ||
| 1226 | |||
| 1227 | return 1; | ||
| 1228 | } | ||
| 1229 | |||
| 1230 | sub restrictWidgets { | ||
| 1231 | |||
| 1232 | # Many menu bar and toolbar items can be sensitised, or desensitised, depending on | ||
| 1233 | # conditions | ||
| 1234 | # This function can be called by anything, any time one of those conditions changes, so that | ||
| 1235 | # menu bar/toolbar items in all 'internal' windows can be sensitised or desensitised with | ||
| 1236 | # a single function call | ||
| 1237 | # | ||
| 1238 | # Expected arguments | ||
| 1239 | # (none besides $self) | ||
| 1240 | # | ||
| 1241 | # Return values | ||
| 1242 | # 'undef' on improper arguments | ||
| 1243 | # 1 otherwise | ||
| 1244 | |||
| 1245 | my ($self, $check) = @_; | ||
| 1246 | |||
| 1247 | # Check for improper arguments | ||
| 1248 | if (defined $check) { | ||
| 1249 | |||
| 1250 | return $axmud::CLIENT->writeImproper($self->_objClass . '->restrictWidgets', @_); | ||
| 1251 | } | ||
| 1252 | |||
| 1253 | foreach my $winObj ($self->ivValues('gridWinHash')) { | ||
| 1254 | |||
| 1255 | if ( | ||
| 1256 | $winObj->winType eq 'main' | ||
| 1257 | || $winObj->winType eq 'protocol' | ||
| 1258 | || $winObj->winType eq 'custom' | ||
| 1259 | ) { | ||
| 1260 | # Update menu bars in all 'internal' windows | ||
| 1261 | $winObj->restrictMenuBars(); | ||
| 1262 | # Update toolbars in all 'internal' windows | ||
| 1263 | $winObj->restrictToolbars(); | ||
| 1264 | } | ||
| 1265 | } | ||
| 1266 | |||
| 1267 | return 1; | ||
| 1268 | } | ||
| 1269 | |||
| 1270 | # 'grid' windows | ||
| 1271 | |||
| 1272 | sub swapGridWin { | ||
| 1273 | |||
| 1274 | # Called by GA::Cmd::SwapWindow->do or by any other function | ||
| 1275 | # Swaps the size and position, exactly, of two 'grid' windows, first checking that each is | ||
| 1276 | # allowed into the other's zone | ||
| 1277 | # | ||
| 1278 | # Expected arguments | ||
| 1279 | # $winObj1 - Blessed reference to the first window object (inheriting from | ||
| 1280 | # GA::Generic::GridWin) | ||
| 1281 | # $winObj2 - Blessed reference to the second window object | ||
| 1282 | # | ||
| 1283 | # Return values | ||
| 1284 | # 'undef' on improper arguments or if the windows can't be swapped | ||
| 1285 | # 1 if the swapping operation succeeds | ||
| 1286 | |||
| 1287 | my ($self, $winObj1, $winObj2, $check) = @_; | ||
| 1288 | |||
| 1289 | # Local variables | ||
| 1290 | my ($zoneObj1, $zoneObj2, $holder); | ||
| 1291 | |||
| 1292 | # Check for improper arguments | ||
| 1293 | if (! defined $winObj1 || ! defined $winObj2 || defined $check) { | ||
| 1294 | |||
| 1295 | return $axmud::CLIENT->writeImproper($self->_objClass . '->swapGridWin', @_); | ||
| 1296 | } | ||
| 1297 | |||
| 1298 | # Check that each window is a 'grid' window | ||
| 1299 | if ( | ||
| 1300 | $winObj1->winCategory ne 'grid' | ||
| 1301 | || ! $self->ivExists('gridWinHash', $winObj1->number) | ||
| 1302 | || ! $winObj1->areaObj | ||
| 1303 | || ! $winObj1->areaObj->zoneObj | ||
| 1304 | ) { | ||
| 1305 | return $self->writeError( | ||
| 1306 | 'Can\'t swap windows - 1st window is not a \'grid\' window', | ||
| 1307 | $self->_objClass . '->swapGridWin', | ||
| 1308 | ); | ||
| 1309 | |||
| 1310 | } else { | ||
| 1311 | |||
| 1312 | $zoneObj1 = $winObj1->areaObj->zoneObj; | ||
| 1313 | } | ||
| 1314 | |||
| 1315 | if ( | ||
| 1316 | $winObj2->winCategory ne 'grid' | ||
| 1317 | || ! $self->ivExists('gridWinHash', $winObj2->number) | ||
| 1318 | || ! $winObj2->areaObj | ||
| 1319 | || ! $winObj2->areaObj->zoneObj | ||
| 1320 | ) { | ||
| 1321 | return $self->writeError( | ||
| 1322 | 'Can\'t swap windows - 2nd window is not a \'grid\' window', | ||
| 1323 | $self->_objClass . '->swapGridWin', | ||
| 1324 | ); | ||
| 1325 | |||
| 1326 | } else { | ||
| 1327 | |||
| 1328 | $zoneObj2 = $winObj2->areaObj->zoneObj; | ||
| 1329 | } | ||
| 1330 | |||
| 1331 | # Check that each window is allowed in the other's zone - unless they are already in the | ||
| 1332 | # same zone, in which case, don't bother | ||
| 1333 | if ($zoneObj1 ne $zoneObj2) { | ||
| 1334 | |||
| 1335 | if ( | ||
| 1336 | ! $zoneObj1->checkWinAllowed( | ||
| 1337 | $winObj2->winType, | ||
| 1338 | $winObj2->winName, | ||
| 1339 | $winObj2->session, | ||
| 1340 | ) | ||
| 1341 | ) { | ||
| 1342 | return $self->writeError( | ||
| 1343 | 'Can\'t swap windows - 1st window not allowed in 2nd window\'s zone', | ||
| 1344 | $self->_objClass . '->swapGridWin', | ||
| 1345 | ); | ||
| 1346 | |||
| 1347 | } elsif ( | ||
| 1348 | ! $zoneObj2->checkWinAllowed( | ||
| 1349 | $winObj1->winType, | ||
| 1350 | $winObj1->winName, | ||
| 1351 | $winObj1->session, | ||
| 1352 | ) | ||
| 1353 | ) { | ||
| 1354 | return $self->writeError( | ||
| 1355 | 'Can\'t swap windows - 2nd window not allowed in 1st window\'s zone', | ||
| 1356 | $self->_objClass . '->swapGridWin', | ||
| 1357 | ); | ||
| 1358 | } | ||
| 1359 | } | ||
| 1360 | |||
| 1361 | # Add the windows to their new zones | ||
| 1362 | $holder = $winObj1->workspaceObj; | ||
| 1363 | $winObj1->set_workspaceObj($winObj2->workspaceObj); | ||
| 1364 | $winObj2->set_workspaceObj($holder); | ||
| 1365 | |||
| 1366 | $holder = $winObj1->workspaceGridObj; | ||
| 1367 | $winObj1->set_workspaceGridObj($winObj2->workspaceGridObj); | ||
| 1368 | $winObj2->set_workspaceGridObj($holder); | ||
| 1369 | |||
| 1370 | $holder = $winObj1->areaObj; | ||
| 1371 | $winObj1->set_areaObj($winObj2->areaObj); | ||
| 1372 | $winObj1->areaObj->set_win($winObj2); | ||
| 1373 | $winObj2->set_areaObj($holder); | ||
| 1374 | $winObj2->areaObj->set_win($winObj1); | ||
| 1375 | |||
| 1376 | # Move and resize the windows | ||
| 1377 | $winObj1->workspaceObj->moveResizeWin( | ||
| 1378 | $winObj1, | ||
| 1379 | $winObj1->areaObj->xPosPixels, | ||
| 1380 | $winObj1->areaObj->yPosPixels, | ||
| 1381 | $winObj1->areaObj->widthPixels, | ||
| 1382 | $winObj1->areaObj->heightPixels, | ||
| 1383 | ); | ||
| 1384 | |||
| 1385 | $winObj2->workspaceObj->moveResizeWin( | ||
| 1386 | $winObj2, | ||
| 1387 | $winObj2->areaObj->xPosPixels, | ||
| 1388 | $winObj2->areaObj->yPosPixels, | ||
| 1389 | $winObj2->areaObj->widthPixels, | ||
| 1390 | $winObj2->areaObj->heightPixels, | ||
| 1391 | ); | ||
| 1392 | |||
| 1393 | # Restack the windows in the correct layer | ||
| 1394 | $winObj1->areaObj->zoneObj->restackWin(); | ||
| 1395 | if ($winObj1->areaObj->zoneObj ne $winObj2->areaObj->zoneObj) { | ||
| 1396 | |||
| 1397 | $winObj2->areaObj->zoneObj->restackWin(); | ||
| 1398 | } | ||
| 1399 | |||
| 1400 | # Operation complete | ||
| 1401 | return 1; | ||
| 1402 | } | ||
| 1403 | |||
| 1404 | sub revealGridWins { | ||
| 1405 | |||
| 1406 | # Called by GA::Session->stop, ->reactDisconnect and GA::Win::Internal->setVisibleSession | ||
| 1407 | # When a session is made the current session, all of its 'grid' windows on the same | ||
| 1408 | # workspace grid as its 'main' window (but not the 'main' window itself) must be made | ||
| 1409 | # visible | ||
| 1410 | # Do nothing if GA::CLIENT->shareMainWinFlag = FALSE, when all sessions have their own | ||
| 1411 | # 'main' window and share workspace grids | ||
| 1412 | # If GA::Client->gridInvisWinFlag is TRUE, the windows are made visible after earlier being | ||
| 1413 | # made invisible; otherwise they are just restored after being minimised | ||
| 1414 | # | ||
| 1415 | # Expected arguments | ||
| 1416 | # $session - The GA::Session whose windows should be made visible | ||
| 1417 | # | ||
| 1418 | # Return values | ||
| 1419 | # 'undef' on improper arguments | ||
| 1420 | # 1 otherwise | ||
| 1421 | |||
| 1422 | my ($self, $session, $check) = @_; | ||
| 1423 | |||
| 1424 | # Local variables | ||
| 1425 | my ( | ||
| 1426 | $mainWinObj, | ||
| 1427 | @winObjList, | ||
| 1428 | ); | ||
| 1429 | |||
| 1430 | # Check for improper arguments | ||
| 1431 | if (! defined $session || defined $check) { | ||
| 1432 | |||
| 1433 | return $axmud::CLIENT->writeImproper($self->_objClass . '->revealGridWins', @_); | ||
| 1434 | } | ||
| 1435 | |||
| 1436 | if ($axmud::CLIENT->shareMainWinFlag) { | ||
| 1437 | |||
| 1438 | # Get a list of windows owned by the specified session (but ignore the shared 'main' | ||
| 1439 | # window) | ||
| 1440 | foreach my $winObj ($self->ivValues('gridWinHash')) { | ||
| 1441 | |||
| 1442 | if ( | ||
| 1443 | $winObj->winType ne 'main' | ||
| 1444 | && $winObj->session | ||
| 1445 | && $winObj->session eq $session | ||
| 1446 | ) { | ||
| 1447 | push (@winObjList, $winObj); | ||
| 1448 | } | ||
| 1449 | } | ||
| 1450 | |||
| 1451 | # Perform the action on any windows in @winObjList which are in the same workspace | ||
| 1452 | # as the session's 'main' window | ||
| 1453 | if ($session->mainWin && $session->mainWin->workspaceObj) { | ||
| 1454 | |||
| 1455 | foreach my $winObj (@winObjList) { | ||
| 1456 | |||
| 1457 | if ( | ||
| 1458 | $winObj->workspaceObj | ||
| 1459 | && $winObj->workspaceObj eq $session->mainWin->workspaceObj | ||
| 1460 | ) { | ||
| 1461 | if ($axmud::CLIENT->gridInvisWinFlag) { | ||
| 1462 | |||
| 1463 | # Make the window visible | ||
| 1464 | $winObj->setVisible(); | ||
| 1465 | |||
| 1466 | } else { | ||
| 1467 | |||
| 1468 | # Unminimise the window | ||
| 1469 | $winObj->unminimise(); | ||
| 1470 | } | ||
| 1471 | } | ||
| 1472 | } | ||
| 1473 | } | ||
| 1474 | } | ||
| 1475 | |||
| 1476 | return 1; | ||
| 1477 | } | ||
| 1478 | |||
| 1479 | sub hideGridWins { | ||
| 1480 | |||
| 1481 | # Called by GA::Win::Internal->setVisibleSession | ||
| 1482 | # When a session ceases being the current session, all of its 'grid' windows on the same | ||
| 1483 | # workspace grid as its 'main' window (but not the 'main' window itself) must be hidden | ||
| 1484 | # Do nothing if GA::CLIENT->shareMainWinFlag = FALSE, when all sessions have their own | ||
| 1485 | # 'main' window and share workspace grids | ||
| 1486 | # If GA::Client->gridInvisWinFlag is TRUE, the windows are made invisible; otherwise they | ||
| 1487 | # are just minimised | ||
| 1488 | # | ||
| 1489 | # Expected arguments | ||
| 1490 | # $session - The GA::Session whose windows should be made not visible | ||
| 1491 | # | ||
| 1492 | # Return values | ||
| 1493 | # 'undef' on improper arguments | ||
| 1494 | # 1 otherwise | ||
| 1495 | |||
| 1496 | my ($self, $session, $check) = @_; | ||
| 1497 | |||
| 1498 | # Local variables | ||
| 1499 | my ( | ||
| 1500 | $mainWinObj, | ||
| 1501 | @winObjList, | ||
| 1502 | ); | ||
| 1503 | |||
| 1504 | # Check for improper arguments | ||
| 1505 | if (! defined $session || defined $check) { | ||
| 1506 | |||
| 1507 | return $axmud::CLIENT->writeImproper($self->_objClass . '->hideGridWins', @_); | ||
| 1508 | } | ||
| 1509 | |||
| 1510 | if ($axmud::CLIENT->shareMainWinFlag) { | ||
| 1511 | |||
| 1512 | # Get a list of windows owned by the specified session (but ignore the shared 'main' | ||
| 1513 | # window) | ||
| 1514 | foreach my $winObj ($self->ivValues('gridWinHash')) { | ||
| 1515 | |||
| 1516 | if ( | ||
| 1517 | $winObj->winType ne 'main' | ||
| 1518 | && $winObj->session | ||
| 1519 | && $winObj->session eq $session | ||
| 1520 | ) { | ||
| 1521 | push (@winObjList, $winObj); | ||
| 1522 | } | ||
| 1523 | } | ||
| 1524 | |||
| 1525 | # Perform the action on any windows in @winObjList which are in the same workspace | ||
| 1526 | # as the session's 'main' window | ||
| 1527 | if ($session->mainWin && $session->mainWin->workspaceObj) { | ||
| 1528 | |||
| 1529 | foreach my $winObj (@winObjList) { | ||
| 1530 | |||
| 1531 | if ( | ||
| 1532 | $winObj->workspaceObj | ||
| 1533 | && $winObj->workspaceObj eq $session->mainWin->workspaceObj | ||
| 1534 | ) { | ||
| 1535 | if ($axmud::CLIENT->gridInvisWinFlag) { | ||
| 1536 | |||
| 1537 | # Make the window invisible | ||
| 1538 | $winObj->setInvisible(); | ||
| 1539 | |||
| 1540 | } else { | ||
| 1541 | |||
| 1542 | # Minimise the window | ||
| 1543 | $winObj->minimise(); | ||
| 1544 | } | ||
| 1545 | } | ||
| 1546 | } | ||
| 1547 | } | ||
| 1548 | } | ||
| 1549 | |||
| 1550 | return 1; | ||
| 1551 | } | ||
| 1552 | |||
| 1553 | sub listGridWins { | ||
| 1554 | |||
| 1555 | # Returns an ordered list of 'grid' windows of a certain type (or of all 'grid' windows, if | ||
| 1556 | # no type is specified) | ||
| 1557 | # | ||
| 1558 | # Expected arguments | ||
| 1559 | # (none besides $self) | ||
| 1560 | # | ||
| 1561 | # Optional arguments | ||
| 1562 | # $type - A window type, matching a key in GA::Client->constGridWinTypeHash, or the | ||
| 1563 | # string 'internal', matching the window types 'main', 'protocol' and | ||
| 1564 | # 'custom'. If 'undef', all 'grid' windows are returned | ||
| 1565 | # | ||
| 1566 | # Return values | ||
| 1567 | # An empty list on improper arguments, if $type is not a valid 'grid' window type or if | ||
| 1568 | # there are no 'grid' windows of that type open | ||
| 1569 | # Otherwise, returns a list of 'grid' windows in the order in which they were created | ||
| 1570 | |||
| 1571 | my ($self, $type, $check) = @_; | ||
| 1572 | |||
| 1573 | # Local variables | ||
| 1574 | my (@emptyList, @list); | ||
| 1575 | |||
| 1576 | # Check for improper arguments | ||
| 1577 | if (defined $check) { | ||
| 1578 | |||
| 1579 | $axmud::CLIENT->writeImproper($self->_objClass . '->listGridWins', @_); | ||
| 1580 | return @emptyList; | ||
| 1581 | } | ||
| 1582 | |||
| 1583 | # Check $type is a valid 'grid' window type (or the valid string 'internal') | ||
| 1584 | if ( | ||
| 1585 | defined $type | ||
| 1586 | && $type ne 'internal' | ||
| 1587 | && ! $axmud::CLIENT->ivExists('constGridWinTypeHash', $type) | ||
| 1588 | ) { | ||
| 1589 | return @emptyList; | ||
| 1590 | } | ||
| 1591 | |||
| 1592 | # Get the list of windows | ||
| 1593 | foreach my $winObj (sort {$a->number cmp $b->number} ($self->ivValues('gridWinHash'))) { | ||
| 1594 | |||
| 1595 | if ( | ||
| 1596 | ! defined $type | ||
| 1597 | || $winObj->winType eq $type | ||
| 1598 | || ( | ||
| 1599 | $type eq 'internal' | ||
| 1600 | && ( | ||
| 1601 | $winObj->winType eq 'main' | ||
| 1602 | || $winObj->winType eq 'protocol' | ||
| 1603 | || $winObj->winType eq 'custom' | ||
| 1604 | ) | ||
| 1605 | ) | ||
| 1606 | ) { | ||
| 1607 | push (@list, $winObj); | ||
| 1608 | } | ||
| 1609 | } | ||
| 1610 | |||
| 1611 | return @list; | ||
| 1612 | } | ||
| 1613 | |||
| 1614 | sub listSessionGridWins { | ||
| 1615 | |||
| 1616 | # Returns an ordered list of 'grid' windows used by the specified session (either the | ||
| 1617 | # the window's ->session matches the specified session, or it's a 'main' window for the | ||
| 1618 | # specified session) | ||
| 1619 | # | ||
| 1620 | # Expected arguments | ||
| 1621 | # $session - The GA::Session which should be matched against 'grid' windows | ||
| 1622 | # | ||
| 1623 | # Optional arguments | ||
| 1624 | # $internalFlag - If TRUE, only 'internal' windows ('main', 'protocol' and 'custom' | ||
| 1625 | # windows) are returned. If FALSE or 'undef', 'map' and 'fixed' | ||
| 1626 | # windows are returned too. 'external' windows are never returned | ||
| 1627 | # | ||
| 1628 | # Return values | ||
| 1629 | # An empty list on improper arguments | ||
| 1630 | # Otherwise, returns a list of matching 'grid' windows in the order in which they were | ||
| 1631 | # created | ||
| 1632 | |||
| 1633 | my ($self, $session, $internalFlag, $check) = @_; | ||
| 1634 | |||
| 1635 | # Local variables | ||
| 1636 | my (@emptyList, @list); | ||
| 1637 | |||
| 1638 | # Check for improper arguments | ||
| 1639 | if (defined $check) { | ||
| 1640 | |||
| 1641 | $axmud::CLIENT->writeImproper($self->_objClass . '->listSessionGridWins', @_); | ||
| 1642 | return @emptyList; | ||
| 1643 | } | ||
| 1644 | |||
| 1645 | # Get the list of windows | ||
| 1646 | foreach my $winObj (sort {$a->number cmp $b->number} ($self->ivValues('gridWinHash'))) { | ||
| 1647 | |||
| 1648 | if ( | ||
| 1649 | $winObj->winType ne 'external' | ||
| 1650 | && ( | ||
| 1651 | ! $internalFlag | ||
| 1652 | || $winObj->winType eq 'main' | ||
| 1653 | || $winObj->winType eq 'protocol' | ||
| 1654 | || $winObj->winType eq 'custom' | ||
| 1655 | ) && ( | ||
| 1656 | ($winObj->session && $winObj->session eq $session) | ||
| 1657 | || $session->mainWin eq $winObj | ||
| 1658 | ) | ||
| 1659 | ) { | ||
| 1660 | push (@list, $winObj); | ||
| 1661 | } | ||
| 1662 | } | ||
| 1663 | |||
| 1664 | return @list; | ||
| 1665 | } | ||
| 1666 | |||
| 1667 | sub claimZones { | ||
| 1668 | |||
| 1669 | # Called by GA::Obj::Zone->addArea during the process in which a window is moved into a | ||
| 1670 | # zone, when GA::CLIENT->shareMainWinFlag = FALSE | ||
| 1671 | # If the zone's ->ownerString is defined, that zone is reserved for a single session. The | ||
| 1672 | # IV's value can be any non-empty string. All zones with the same ->ownerString are | ||
| 1673 | # reserved for a particular session | ||
| 1674 | # The first session to place one of its windows into any 'owned' zone claims all of | ||
| 1675 | # those zones for itself. If ->ownerString IV is 'undef', the zone is available for any | ||
| 1676 | # session to use (subject to restriction described in the comments in | ||
| 1677 | # GA::Obj::Zone->new) | ||
| 1678 | # This function is called when a window is moved into a zone whose ->ownerString is set, but | ||
| 1679 | # whose ->owner shows the zone hasn't been claimed by a session | ||
| 1680 | # This function checks every zone across all workspace grids, and 'claims' any zone with the | ||
| 1681 | # same ->ownerString for the session | ||
| 1682 | # | ||
| 1683 | # Expected arguments | ||
| 1684 | # $session - The GA::Session which claims the calling zone object | ||
| 1685 | # $ownerString - That zone's ->ownerString | ||
| 1686 | # | ||
| 1687 | # Return values | ||
| 1688 | # 'undef' on improper arguments or if there's an error | ||
| 1689 | # 1 otherwise | ||
| 1690 | |||
| 1691 | my ($self, $session, $ownerString, $check) = @_; | ||
| 1692 | |||
| 1693 | # Local variables | ||
| 1694 | my @list; | ||
| 1695 | |||
| 1696 | # Check for improper arguments | ||
| 1697 | if (! defined $session || ! defined $ownerString || defined $check) { | ||
| 1698 | |||
| 1699 | return $axmud::CLIENT->writeImproper($self->_objClass . '->claimZones', @_); | ||
| 1700 | } | ||
| 1701 | |||
| 1702 | # Get a list of zone objects with the same $ownerString | ||
| 1703 | foreach my $workspaceGridObj ($self->ivValues('gridHash')) { | ||
| 1704 | |||
| 1705 | foreach my $zoneObj ($workspaceGridObj->ivValues('zoneHash')) { | ||
| 1706 | |||
| 1707 | if (defined $zoneObj->ownerString && $zoneObj->ownerString eq $ownerString) { | ||
| 1708 | |||
| 1709 | push (@list, $zoneObj); | ||
| 1710 | |||
| 1711 | if ($zoneObj->owner) { | ||
| 1712 | |||
| 1713 | # No zone with this $ownerString should have an ->owner session set, so | ||
| 1714 | # give up with an error message | ||
| 1715 | return $axmud::CLIENT->writeError( | ||
| 1716 | 'General error assigning owners to zones', | ||
| 1717 | $self->_objClass . '->claimZones', | ||
| 1718 | ); | ||
| 1719 | } | ||
| 1720 | } | ||
| 1721 | } | ||
| 1722 | } | ||
| 1723 | |||
| 1724 | # We now have a list of 0, 1 or more zones that can be claimed by the session | ||
| 1725 | foreach my $zoneObj (@list) { | ||
| 1726 | |||
| 1727 | $zoneObj->set_owner($session); | ||
| 1728 | } | ||
| 1729 | |||
| 1730 | return 1; | ||
| 1731 | } | ||
| 1732 | |||
| 1733 | sub relinquishZones { | ||
| 1734 | |||
| 1735 | # Called by GA::Obj::Zone->removeArea when a window is removed from a zone, and there are | ||
| 1736 | # no more windows left in the zone and when GA::CLIENT->shareMainWinFlag = FALSE | ||
| 1737 | # If the zone's ->ownerString is defined, that zone is reserved for a single session. The | ||
| 1738 | # IV's value can be any non-empty string. All zones with the same ->ownerString are | ||
| 1739 | # reserved for a particular session | ||
| 1740 | # The first session to place one of its windows into any 'owned' zone claims all of | ||
| 1741 | # those zones for itself. If ->ownerString IV is 'undef', the zone is available for any | ||
| 1742 | # session to use (subject to restriction described in the comments in | ||
| 1743 | # GA::Obj::Zone->new) | ||
| 1744 | # This function is called when the zone's ->ownerString and ->owner are both set. It checks | ||
| 1745 | # every zone across all workspace grids, counting how many windows are in zones with the | ||
| 1746 | # same ->ownerString. If there are none, it 'relinquishes' all of these zones for use by a | ||
| 1747 | # different session | ||
| 1748 | # | ||
| 1749 | # Expected arguments | ||
| 1750 | # $ownerString - The calling zone's ->ownerString | ||
| 1751 | # | ||
| 1752 | # Return values | ||
| 1753 | # 'undef' on improper arguments or if there's an error | ||
| 1754 | # 1 otherwise | ||
| 1755 | |||
| 1756 | my ($self, $ownerString, $check) = @_; | ||
| 1757 | |||
| 1758 | # Local variables | ||
| 1759 | my @list; | ||
| 1760 | |||
| 1761 | # Check for improper arguments | ||
| 1762 | if (! defined $ownerString || defined $check) { | ||
| 1763 | |||
| 1764 | return $axmud::CLIENT->writeImproper($self->_objClass . '->relinquishZones', @_); | ||
| 1765 | } | ||
| 1766 | |||
| 1767 | # Get a list of zone objects with the same $ownerString | ||
| 1768 | foreach my $workspaceGridObj ($self->ivValues('gridHash')) { | ||
| 1769 | |||
| 1770 | foreach my $zoneObj ($workspaceGridObj->ivValues('zoneHash')) { | ||
| 1771 | |||
| 1772 | if (defined $zoneObj->ownerString && $zoneObj->ownerString eq $ownerString) { | ||
| 1773 | |||
| 1774 | push (@list, $zoneObj); | ||
| 1775 | |||
| 1776 | if (! $zoneObj->owner) { | ||
| 1777 | |||
| 1778 | # All zones with this $ownerString should have an ->owner session set, so | ||
| 1779 | # give up with an error message | ||
| 1780 | return $axmud::CLIENT->writeError( | ||
| 1781 | 'General error relinquishing zones from their owners', | ||
| 1782 | $self->_objClass . '->relinquishZones', | ||
| 1783 | ); | ||
| 1784 | } | ||
| 1785 | } | ||
| 1786 | } | ||
| 1787 | } | ||
| 1788 | |||
| 1789 | # We have a list of 0, 1 or more zones that can be relinquished | ||
| 1790 | foreach my $zoneObj (@list) { | ||
| 1791 | |||
| 1792 | $zoneObj->reset_owner(); | ||
| 1793 | } | ||
| 1794 | |||
| 1795 | return 1; | ||
| 1796 | } | ||
| 1797 | |||
| 1798 | sub convertSpareMainWin { | ||
| 1799 | |||
| 1800 | # Called by GA::Session->setMainWin | ||
| 1801 | # When there are no sessions, the single 'main' window is called a spare 'main' window | ||
| 1802 | # When a new session starts, the spare 'main' window must be converted into a normal | ||
| 1803 | # 'main' window (owned by a session, not by the GA::Client, and using a winmap that's | ||
| 1804 | # not 'main_wait') | ||
| 1805 | # | ||
| 1806 | # Expected arguments | ||
| 1807 | # $session - The calling GA::Session | ||
| 1808 | # $winObj - The existing spare 'main' window object | ||
| 1809 | # | ||
| 1810 | # Optional arguments | ||
| 1811 | # $winmap - The winmap to use. Set only if a winmap has been marked as the default | ||
| 1812 | # winmap for this world; otherwise 'undef' | ||
| 1813 | # | ||
| 1814 | # Return values | ||
| 1815 | # 'undef' on improper arguments or if the spare 'main' window can't be converted | ||
| 1816 | # 1 otherwise | ||
| 1817 | |||
| 1818 | my ($self, $session, $winObj, $winmap, $check) = @_; | ||
| 1819 | |||
| 1820 | # Local variables | ||
| 1821 | my ($winmapObj, $successFlag); | ||
| 1822 | |||
| 1823 | # Check for improper arguments | ||
| 1824 | if (! defined $session || ! defined $winObj || defined $check) { | ||
| 1825 | |||
| 1826 | return $axmud::CLIENT->writeImproper($self->_objClass . '->convertSpareMainWin', @_); | ||
| 1827 | } | ||
| 1828 | |||
| 1829 | # Update IVs | ||
| 1830 | $winObj->set_owner($session); | ||
| 1831 | $winObj->set_session($session); | ||
| 1832 | |||
| 1833 | # Position it on a workspace grid (if grids are activated generally) | ||
| 1834 | if ($axmud::CLIENT->activateGridFlag && $self->gridPermitFlag) { | ||
| 1835 | |||
| 1836 | OUTER: foreach my $workspaceObj ($axmud::CLIENT->desktopObj->listWorkspaces()) { | ||
| 1837 | |||
| 1838 | foreach my $gridObj ( | ||
| 1839 | sort {$a->number <=> $b->number} ($workspaceObj->ivValues('gridHash')) | ||
| 1840 | ) { | ||
| 1841 | if ($gridObj->repositionGridWin($winObj)) { | ||
| 1842 | |||
| 1843 | # 'main' window repositioned. Decide which winmap to use, if none was | ||
| 1844 | # specified by the calling function | ||
| 1845 | if (! $winmap) { | ||
| 1846 | |||
| 1847 | # Use the default winmap for the window's new zone | ||
| 1848 | $winmapObj = $winObj->workspaceObj->getWinmap( | ||
| 1849 | 'main', | ||
| 1850 | undef, | ||
| 1851 | $winObj->areaObj->zoneObj, | ||
| 1852 | ); | ||
| 1853 | |||
| 1854 | $winmap = $winmapObj->name; | ||
| 1855 | } | ||
| 1856 | |||
| 1857 | # ->repositionGridWin is also called by | ||
| 1858 | # GA::Obj::WorkspaceGrid->applyZonemap, so its ->gridWinHash IV hasn't | ||
| 1859 | # been modified | ||
| 1860 | $gridObj->add_gridWin($winObj); | ||
| 1861 | # Window IVs must also be updated | ||
| 1862 | $winObj->set_workspaceGridObj($gridObj); | ||
| 1863 | $winObj->set_workspaceObj($gridObj->workspaceObj); | ||
| 1864 | |||
| 1865 | $self->updateWidgets($self->_objClass . '->convertSpareMainWin'); | ||
| 1866 | |||
| 1867 | # Position operation complete | ||
| 1868 | $successFlag = TRUE; | ||
| 1869 | last OUTER; | ||
| 1870 | } | ||
| 1871 | } | ||
| 1872 | } | ||
| 1873 | |||
| 1874 | if (! $successFlag) { | ||
| 1875 | |||
| 1876 | # Could not position the 'main' window on any workspace grid, for some reason | ||
| 1877 | return undef; | ||
| 1878 | } | ||
| 1879 | } | ||
| 1880 | |||
| 1881 | # Reset the window's winmap | ||
| 1882 | if (! $winmap) { | ||
| 1883 | |||
| 1884 | if ($axmud::CLIENT->activateGridFlag) { | ||
| 1885 | $winmap = $axmud::CLIENT->constDefaultEnabledWinmap; | ||
| 1886 | } else { | ||
| 1887 | $winmap = $axmud::CLIENT->constDefaultDisabledWinmap; | ||
| 1888 | } | ||
| 1889 | } | ||
| 1890 | |||
| 1891 | $winObj->resetWinmap($winmap); | ||
| 1892 | |||
| 1893 | return 1; | ||
| 1894 | } | ||
| 1895 | |||
| 1896 | sub deconvertSpareMainWin { | ||
| 1897 | |||
| 1898 | # Called by GA::Session->stop | ||
| 1899 | # When a session terminates and there are no sessions left, the last remaining 'main' | ||
| 1900 | # window must be converted into a spare 'main' window (owned by GA::Client, not a session, | ||
| 1901 | # and using the 'main_wait' winmap) | ||
| 1902 | # | ||
| 1903 | # Expected arguments | ||
| 1904 | # $winObj - The existing spare 'main' window object | ||
| 1905 | # | ||
| 1906 | # Return values | ||
| 1907 | # 'undef' on improper arguments | ||
| 1908 | # 1 otherwise | ||
| 1909 | |||
| 1910 | my ($self, $winObj, $check) = @_; | ||
| 1911 | |||
| 1912 | # Check for improper arguments | ||
| 1913 | if (! defined $winObj || defined $check) { | ||
| 1914 | |||
| 1915 | return $axmud::CLIENT->writeImproper($self->_objClass . '->deconvertSpareMainWin', @_); | ||
| 1916 | } | ||
| 1917 | |||
| 1918 | $winObj->resetWinmap('main_wait'); | ||
| 1919 | $winObj->set_owner($axmud::CLIENT); | ||
| 1920 | $winObj->set_session(); | ||
| 1921 | |||
| 1922 | $self->updateWidgets($self->_objClass . '->deconvertSpareMainWin'); | ||
| 1923 | |||
| 1924 | # Operation complete | ||
| 1925 | return 1; | ||
| 1926 | } | ||
| 1927 | |||
| 1928 | sub storeGridWinPosn { | ||
| 1929 | |||
| 1930 | # Called by GA::Cmd::ToggleWindowStorage->do and ApplyWindowStorage->do | ||
| 1931 | # Gets the size and position of every 'grid' window for a specified GA::Session and calls | ||
| 1932 | # GA::Client->add_storeGridPosn to store them | ||
| 1933 | # Works even when GA::Client->storeGridPosnFlag is FALSE, but otherwise ->add_storeGridPosn | ||
| 1934 | # itself decides whether each window's size and position should be stored | ||
| 1935 | # Ignores 'external' windows | ||
| 1936 | # | ||
| 1937 | # Expected arguments | ||
| 1938 | # $session - The GA::Session whose 'grid' windows should be stored | ||
| 1939 | # | ||
| 1940 | # Return values | ||
| 1941 | # 'undef' on improper arguments | ||
| 1942 | # 1 otherwise | ||
| 1943 | |||
| 1944 | my ($self, $session, $check) = @_; | ||
| 1945 | |||
| 1946 | # Check for improper arguments | ||
| 1947 | if (! defined $session || defined $check) { | ||
| 1948 | |||
| 1949 | return $axmud::CLIENT->writeImproper($self->_objClass . '->storeGridWinPosn', @_); | ||
| 1950 | } | ||
| 1951 | |||
| 1952 | foreach my $winObj (sort {$a->number <=> $b->number} ($self->ivValues('gridWinHash'))) { | ||
| 1953 | |||
| 1954 | if ($winObj->winType ne 'external' && $winObj->session eq $session) { | ||
| 1955 | |||
| 1956 | # The TRUE flag means to ignore the setting of GA::Client->storeGridPosnFlag | ||
| 1957 | $axmud::CLIENT->add_storeGridPosn( | ||
| 1958 | $winObj, | ||
| 1959 | $winObj->winWidget->get_position(), | ||
| 1960 | $winObj->winWidget->get_size(), | ||
| 1961 | TRUE, | ||
| 1962 | ); | ||
| 1963 | } | ||
| 1964 | } | ||
| 1965 | |||
| 1966 | return 1; | ||
| 1967 | } | ||
| 1968 | |||
| 1969 | # 'free' windows | ||
| 1970 | |||
| 1971 | sub listFreeWins { | ||
| 1972 | |||
| 1973 | # Returns an ordered list of 'free' windows of a certain type (or of all 'free' windows, if | ||
| 1974 | # no type is specified) | ||
| 1975 | # NB 'dialogue' windows are not stored in this object's IVs, and are not returned in the | ||
| 1976 | # list | ||
| 1977 | # | ||
| 1978 | # Expected arguments | ||
| 1979 | # (none besides $self) | ||
| 1980 | # | ||
| 1981 | # Optional arguments | ||
| 1982 | # $type - A window type, matching a key in GA::Client->constFreeWinTypeHash. If 'undef', | ||
| 1983 | # all 'free' windows except 'dialogue' windows are returned | ||
| 1984 | # | ||
| 1985 | # Return values | ||
| 1986 | # An empty list on improper arguments, if $type is not a valid 'free' window type or if | ||
| 1987 | # there are no 'free' windows of that type open | ||
| 1988 | # Otherwise, returns a list of 'free' windows in the order in which they were created | ||
| 1989 | |||
| 1990 | my ($self, $type, $check) = @_; | ||
| 1991 | |||
| 1992 | # Local variables | ||
| 1993 | my (@emptyList, @list); | ||
| 1994 | |||
| 1995 | # Check for improper arguments | ||
| 1996 | if (defined $check) { | ||
| 1997 | |||
| 1998 | $axmud::CLIENT->writeImproper($self->_objClass . '->listFreeWins', @_); | ||
| 1999 | return @emptyList; | ||
| 2000 | } | ||
| 2001 | |||
| 2002 | # Check $type is a valid 'free' window type | ||
| 2003 | if ( | ||
| 2004 | defined $type | ||
| 2005 | && ! $axmud::CLIENT->ivExists('constFreeWinTypeHash', $type) | ||
| 2006 | ) { | ||
| 2007 | return @emptyList; | ||
| 2008 | } | ||
| 2009 | |||
| 2010 | # Get the list of windows | ||
| 2011 | foreach my $winObj (sort {$a->number <=> $b->number} ($self->ivValues('freeWinHash'))) { | ||
| 2012 | |||
| 2013 | if (! defined $type || $winObj->winType eq $type) { | ||
| 2014 | |||
| 2015 | push (@list, $winObj); | ||
| 2016 | } | ||
| 2017 | } | ||
| 2018 | |||
| 2019 | return @list; | ||
| 2020 | } | ||
| 2021 | |||
| 2022 | sub listSessionFreeWins { | ||
| 2023 | |||
| 2024 | # Returns an ordered list of 'free' windows used by the specified session (when the | ||
| 2025 | # the window's ->session matches the specified session; does not include 'dialogue' | ||
| 2026 | # windows) | ||
| 2027 | # | ||
| 2028 | # Expected arguments | ||
| 2029 | # $session - The GA::Session which should be matched against 'free' windows | ||
| 2030 | # | ||
| 2031 | # Optional arguments | ||
| 2032 | # $singleFlag - If set to TRUE, this functions gives up when it finds the first | ||
| 2033 | # matching window, returning a list containing just that window; | ||
| 2034 | # if set to FALSE (or 'undef'), a list of all matching windows are | ||
| 2035 | # returned | ||
| 2036 | # | ||
| 2037 | # Return values | ||
| 2038 | # An empty list on improper arguments | ||
| 2039 | # Otherwise, returns a list of matching 'free' windows in the order in which they were | ||
| 2040 | # created | ||
| 2041 | |||
| 2042 | my ($self, $session, $singleFlag, $check) = @_; | ||
| 2043 | |||
| 2044 | # Local variables | ||
| 2045 | my (@emptyList, @list); | ||
| 2046 | |||
| 2047 | # Check for improper arguments | ||
| 2048 | if (defined $check) { | ||
| 2049 | |||
| 2050 | $axmud::CLIENT->writeImproper($self->_objClass . '->listSessionFreeWins', @_); | ||
| 2051 | return @emptyList; | ||
| 2052 | } | ||
| 2053 | |||
| 2054 | # Get the list of windows | ||
| 2055 | foreach my $winObj (sort {$a->number <=> $b->number} ($self->ivValues('freeWinHash'))) { | ||
| 2056 | |||
| 2057 | if ($winObj->session && $winObj->session eq $session) { | ||
| 2058 | |||
| 2059 | push (@list, $winObj); | ||
| 2060 | |||
| 2061 | if ($singleFlag) { | ||
| 2062 | |||
| 2063 | # Calling function doesn't care how many matching windows there are, only that | ||
| 2064 | # there is at least one | ||
| 2065 | return @list; | ||
| 2066 | } | ||
| 2067 | } | ||
| 2068 | } | ||
| 2069 | |||
| 2070 | return @list; | ||
| 2071 | } | ||
| 2072 | |||
| 2073 | # Widgets | ||
| 2074 | |||
| 2075 | sub updateWidgets { | ||
| 2076 | |||
| 2077 | # Can be called by anything. Updates Gtk3's events queue | ||
| 2078 | # Used for debugging, so that we can track all lines of code like this, if we need to: | ||
| 2079 | # Gtk3->main_iteration() while Gtk3->events_pending(); | ||
| 2080 | # | ||
| 2081 | # Expected arguments | ||
| 2082 | # (none besides $self) | ||
| 2083 | # | ||
| 2084 | # Optional arguments | ||
| 2085 | # $string - For debugging purposes. Describes the calling function, e.g. | ||
| 2086 | # ->updateWidgets($self->_objClass . '->callingFunction'); | ||
| 2087 | # | ||
| 2088 | # Return values | ||
| 2089 | # 'undef' on improper arguments | ||
| 2090 | # 1 otherwise | ||
| 2091 | |||
| 2092 | my ($self, $string, $check) = @_; | ||
| 2093 | |||
| 2094 | # Check for improper arguments | ||
| 2095 | if (defined $check) { | ||
| 2096 | |||
| 2097 | return $axmud::CLIENT->writeImproper($self->_objClass . '->updateWidgets', @_); | ||
| 2098 | } | ||
| 2099 | |||
| 2100 | # Update Gtk3's events queue | ||
| 2101 | Gtk3::main_iteration() while Gtk3::events_pending(); | ||
| 2102 | |||
| 2103 | # Any textview objects (GA::Obj::TextView) which is waiting to update its size IVs can now | ||
| 2104 | # do so | ||
| 2105 | foreach my $textViewObj ($self->ivValues('textViewHash')) { | ||
| 2106 | |||
| 2107 | if ($textViewObj->sizeUpdateFlag) { | ||
| 2108 | |||
| 2109 | $textViewObj->updateVisibleSize(); | ||
| 2110 | } | ||
| 2111 | } | ||
| 2112 | |||
| 2113 | # Optionally, write information about the calling function to the terminal (for debugging) | ||
| 2114 | # if ($string) { | ||
| 2115 | # | ||
| 2116 | # print "->updateWidgets() call from " . $string . " at " . $axmud::CLIENT->getTime() | ||
| 2117 | # . "\n"; | ||
| 2118 | # | ||
| 2119 | # } else { | ||
| 2120 | # | ||
| 2121 | # print "->updateWidgets() call from unspecified function at " . $axmud::CLIENT->getTime() | ||
| 2122 | # . "\n"; | ||
| 2123 | # } | ||
| 2124 | |||
| 2125 | # Handle any Gtk3::TextView scrolling problems (see the comments in GA::Session->new) | ||
| 2126 | foreach my $session ($axmud::CLIENT->ivValues('sessionHash')) { | ||
| 2127 | |||
| 2128 | $session->forceScrollTextViews(); | ||
| 2129 | } | ||
| 2130 | |||
| 2131 | return 1 | ||
| 2132 | } | ||
| 2133 | |||
| 2134 | sub removeWidget { | ||
| 2135 | |||
| 2136 | # Can be called by anything | ||
| 2137 | # Calls to a Gtk3 widgets ->remove function will cause a crash, if the child is no longer | ||
| 2138 | # inside its parent | ||
| 2139 | # This function checks the child is inside its parent and, if so, calls the ->remove | ||
| 2140 | # function; otherwise it does nothing | ||
| 2141 | # | ||
| 2142 | # Expected arguments | ||
| 2143 | # $parent - The parent Gtk3 widget | ||
| 2144 | # $child - The child Gtk3 widget | ||
| 2145 | # | ||
| 2146 | # Return values | ||
| 2147 | # 'undef' on improper arguments | ||
| 2148 | # 1 otherwise | ||
| 2149 | |||
| 2150 | my ($self, $parent, $child, $check) = @_; | ||
| 2151 | |||
| 2152 | # Check for improper arguments | ||
| 2153 | if (! defined $parent || ! defined $child || defined $check) { | ||
| 2154 | |||
| 2155 | return $axmud::CLIENT->writeImproper($self->_objClass . '->removeWidget', @_); | ||
| 2156 | } | ||
| 2157 | |||
| 2158 | OUTER: foreach my $widget ($parent->get_children()) { | ||
| 2159 | |||
| 2160 | if ($widget eq $child) { | ||
| 2161 | |||
| 2162 | $parent->remove($child); | ||
| 2163 | return 1; | ||
| 2164 | } | ||
| 2165 | } | ||
| 2166 | |||
| 2167 | return 1; | ||
| 2168 | } | ||
| 2169 | |||
| 2170 | sub bufferGetText { | ||
| 2171 | |||
| 2172 | # Can be called by anything | ||
| 2173 | # Gets the entire text displayed in a Gtk3::TextView from its Gtk3::TextBuffer and returns | ||
| 2174 | # it as a string, often containing newline characters | ||
| 2175 | # | ||
| 2176 | # Expected arguments | ||
| 2177 | # $buffer - The Gtk3::TextBuffer whose text should be extracted | ||
| 2178 | # | ||
| 2179 | # Return values | ||
| 2180 | # 'undef' on improper arguments | ||
| 2181 | # Otherwise returns the buffer's contents as a string (may be an empty string) | ||
| 2182 | |||
| 2183 | my ($self, $buffer, $check) = @_; | ||
| 2184 | |||
| 2185 | # Check for improper arguments | ||
| 2186 | if (! defined $buffer || defined $check) { | ||
| 2187 | |||
| 2188 | return $axmud::CLIENT->writeImproper($self->_objClass . '->bufferGetText', @_); | ||
| 2189 | } | ||
| 2190 | |||
| 2191 | return $buffer->get_text( | ||
| 2192 | $buffer->get_start_iter(), | ||
| 2193 | $buffer->get_end_iter(), | ||
| 2194 | # Include hidden chars | ||
| 2195 | TRUE, | ||
| 2196 | ); | ||
| 2197 | } | ||
| 2198 | |||
| 2199 | ################## | ||
| 2200 | # Accessors - set | ||
| 2201 | |||
| 2202 | sub add_freeWin { | ||
| 2203 | |||
| 2204 | # Called by GA::Generic::Win->createFreeWin | ||
| 2205 | |||
| 2206 | my ($self, $obj, $check) = @_; | ||
| 2207 | |||
| 2208 | # Check for improper arguments | ||
| 2209 | if (! defined $obj || defined $check) { | ||
| 2210 | |||
| 2211 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_freeWin', @_); | ||
| 2212 | } | ||
| 2213 | |||
| 2214 | # ($self->freeWinCount is already the same as $winObj->number) | ||
| 2215 | $self->ivAdd('freeWinHash', $self->freeWinCount, $obj); | ||
| 2216 | $self->ivIncrement('freeWinCount'); | ||
| 2217 | |||
| 2218 | return 1; | ||
| 2219 | } | ||
| 2220 | |||
| 2221 | sub del_freeWin { | ||
| 2222 | |||
| 2223 | # Called by GA::Generic::FreeWin->winDestroy | ||
| 2224 | |||
| 2225 | my ($self, $obj, $check) = @_; | ||
| 2226 | |||
| 2227 | # Check for improper arguments | ||
| 2228 | if (! defined $obj || defined $check) { | ||
| 2229 | |||
| 2230 | return $axmud::CLIENT->writeImproper($self->_objClass . '->del_freeWin', @_); | ||
| 2231 | } | ||
| 2232 | |||
| 2233 | if (! $self->ivExists('freeWinHash', $obj->number)) { | ||
| 2234 | |||
| 2235 | return undef; | ||
| 2236 | |||
| 2237 | } else { | ||
| 2238 | |||
| 2239 | $self->ivDelete('freeWinHash', $obj->number); | ||
| 2240 | |||
| 2241 | return 1; | ||
| 2242 | } | ||
| 2243 | } | ||
| 2244 | |||
| 2245 | sub add_grid { | ||
| 2246 | |||
| 2247 | # Called by GA::Obj::Workspace->addWorkspaceGrid | ||
| 2248 | # | ||
| 2249 | # Expected arguments | ||
| 2250 | # $workspaceObj - The calling workspace object | ||
| 2251 | # | ||
| 2252 | # Optional arguments | ||
| 2253 | # $session - (GA::Client->shareMainWinFlag = TRUE) The GA::Session object which | ||
| 2254 | # controls this workspace grid | ||
| 2255 | # - (GA::Client->shareMainWinFlag = FALSE) 'undef' (the grid is shared | ||
| 2256 | # between all sessions) | ||
| 2257 | |||
| 2258 | my ($self, $workspaceObj, $session, $check) = @_; | ||
| 2259 | |||
| 2260 | # Local variables | ||
| 2261 | my $gridObj; | ||
| 2262 | |||
| 2263 | # Check for improper arguments | ||
| 2264 | if (defined $check) { | ||
| 2265 | |||
| 2266 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_grid', @_); | ||
| 2267 | } | ||
| 2268 | |||
| 2269 | $gridObj = Games::Axmud::Obj::WorkspaceGrid->new($self->gridCount, $workspaceObj, $session); | ||
| 2270 | if (! $gridObj) { | ||
| 2271 | |||
| 2272 | return undef; | ||
| 2273 | |||
| 2274 | } else { | ||
| 2275 | |||
| 2276 | $self->ivAdd('gridHash', $self->gridCount, $gridObj); | ||
| 2277 | $self->ivIncrement('gridCount'); | ||
| 2278 | |||
| 2279 | return $gridObj; | ||
| 2280 | } | ||
| 2281 | } | ||
| 2282 | |||
| 2283 | sub del_grid { | ||
| 2284 | |||
| 2285 | # Called by GA::Obj::Workspace->removeWorkspaceGrid | ||
| 2286 | # | ||
| 2287 | # Expected arguments | ||
| 2288 | # $obj - The workspace grid object to remove | ||
| 2289 | # | ||
| 2290 | # Optional arguments | ||
| 2291 | # $session - If defined, that session's 'main' window is disengaged (removed from its | ||
| 2292 | # workspace grid, but not destroyed) | ||
| 2293 | |||
| 2294 | my ($self, $obj, $session, $check) = @_; | ||
| 2295 | |||
| 2296 | # Check for improper arguments | ||
| 2297 | if (! defined $obj || defined $check) { | ||
| 2298 | |||
| 2299 | return $axmud::CLIENT->writeImproper($self->_objClass . '->del_grid', @_); | ||
| 2300 | } | ||
| 2301 | |||
| 2302 | if (! $self->ivExists('gridHash', $obj->number)) { | ||
| 2303 | |||
| 2304 | return undef; | ||
| 2305 | |||
| 2306 | } else { | ||
| 2307 | |||
| 2308 | $obj->stop($session); | ||
| 2309 | |||
| 2310 | $self->ivDelete('gridHash', $obj->number); | ||
| 2311 | |||
| 2312 | return 1; | ||
| 2313 | } | ||
| 2314 | } | ||
| 2315 | |||
| 2316 | sub add_gridWin { | ||
| 2317 | |||
| 2318 | # Called by GA::Obj::Workspace->createGridWin, ->createSimpleGridWin | ||
| 2319 | |||
| 2320 | my ($self, $obj, $check) = @_; | ||
| 2321 | |||
| 2322 | # Check for improper arguments | ||
| 2323 | if (! defined $obj || defined $check) { | ||
| 2324 | |||
| 2325 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_gridWin', @_); | ||
| 2326 | } | ||
| 2327 | |||
| 2328 | # ($self->gridWinCount is already the same as $winObj->number) | ||
| 2329 | $self->ivAdd('gridWinHash', $self->gridWinCount, $obj); | ||
| 2330 | $self->ivIncrement('gridWinCount'); | ||
| 2331 | |||
| 2332 | return 1; | ||
| 2333 | } | ||
| 2334 | |||
| 2335 | sub del_gridWin { | ||
| 2336 | |||
| 2337 | # Called by GA::Win::Internal->winDestroy, etc | ||
| 2338 | |||
| 2339 | my ($self, $winObj, $check) = @_; | ||
| 2340 | |||
| 2341 | # Check for improper arguments | ||
| 2342 | if (! defined $winObj || defined $check) { | ||
| 2343 | |||
| 2344 | return $axmud::CLIENT->writeImproper($self->_objClass . '->del_gridWin', @_); | ||
| 2345 | } | ||
| 2346 | |||
| 2347 | if (! $self->ivExists('gridWinHash', $winObj->number)) { | ||
| 2348 | |||
| 2349 | return undef; | ||
| 2350 | |||
| 2351 | } else { | ||
| 2352 | |||
| 2353 | $self->ivDelete('gridWinHash', $winObj->number); | ||
| 2354 | |||
| 2355 | # If it's a 'main' window, it can exist in several different workspace grids. One of | ||
| 2356 | # them has already been informed; make sure they have all been informed | ||
| 2357 | if ($winObj->winType eq 'main') { | ||
| 2358 | |||
| 2359 | foreach my $gridObj ($self->ivValues('gridHash')) { | ||
| 2360 | |||
| 2361 | if ($gridObj->ivExists('gridWinHash', $winObj->number)) { | ||
| 2362 | |||
| 2363 | $gridObj->del_gridWin($winObj); | ||
| 2364 | } | ||
| 2365 | } | ||
| 2366 | } | ||
| 2367 | |||
| 2368 | return 1; | ||
| 2369 | } | ||
| 2370 | } | ||
| 2371 | |||
| 2372 | sub add_textView { | ||
| 2373 | |||
| 2374 | # Can be called by anything, most commonly by GA::Table::Pane->addTab and | ||
| 2375 | # ->addSimpleTab | ||
| 2376 | |||
| 2377 | my ($self, $session, $winObj, $paneObj, $check) = @_; | ||
| 2378 | |||
| 2379 | # Local variables | ||
| 2380 | my $textViewObj; | ||
| 2381 | |||
| 2382 | # Check for improper arguments | ||
| 2383 | if (! defined $session || ! defined $winObj || defined $check) { | ||
| 2384 | |||
| 2385 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_textView', @_); | ||
| 2386 | } | ||
| 2387 | |||
| 2388 | $textViewObj | ||
| 2389 | = Games::Axmud::Obj::TextView->new($session, $self->textViewCount, $winObj, $paneObj); | ||
| 2390 | |||
| 2391 | if (! $textViewObj) { | ||
| 2392 | |||
| 2393 | return undef; | ||
| 2394 | |||
| 2395 | } else { | ||
| 2396 | |||
| 2397 | $self->ivAdd('textViewHash', $textViewObj->number, $textViewObj); | ||
| 2398 | $self->ivIncrement('textViewCount'); | ||
| 2399 | |||
| 2400 | return $textViewObj; | ||
| 2401 | } | ||
| 2402 | } | ||
| 2403 | |||
| 2404 | sub del_textView { | ||
| 2405 | |||
| 2406 | # GA::Obj::TextView->objDestroy | ||
| 2407 | |||
| 2408 | my ($self, $obj, $check) = @_; | ||
| 2409 | |||
| 2410 | # Check for improper arguments | ||
| 2411 | if (! defined $obj || defined $check) { | ||
| 2412 | |||
| 2413 | return $axmud::CLIENT->writeImproper($self->_objClass . '->del_textView', @_); | ||
| 2414 | } | ||
| 2415 | |||
| 2416 | if (! $self->ivExists('textViewHash', $obj->number)) { | ||
| 2417 | |||
| 2418 | return undef; | ||
| 2419 | |||
| 2420 | } else { | ||
| 2421 | |||
| 2422 | $self->ivDelete('textViewHash', $obj->number); | ||
| 2423 | |||
| 2424 | return 1; | ||
| 2425 | } | ||
| 2426 | } | ||
| 2427 | |||
| 2428 | sub add_workspace { | ||
| 2429 | |||
| 2430 | # Called by $self->start and $self->setupWorkspaces | ||
| 2431 | |||
| 2432 | my ($self, $workspace, $check) = @_; | ||
| 2433 | |||
| 2434 | # Local variables | ||
| 2435 | my $workspaceObj; | ||
| 2436 | |||
| 2437 | # Check for improper arguments | ||
| 2438 | if (defined $check) { | ||
| 2439 | |||
| 2440 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_workspace', @_); | ||
| 2441 | } | ||
| 2442 | |||
| 2443 | $workspaceObj = Games::Axmud::Obj::Workspace->new($self->workspaceCount, $workspace); | ||
| 2444 | |||
| 2445 | if (! $workspaceObj) { | ||
| 2446 | |||
| 2447 | return undef; | ||
| 2448 | |||
| 2449 | } else { | ||
| 2450 | |||
| 2451 | $self->ivAdd('workspaceHash', $self->workspaceCount, $workspaceObj); | ||
| 2452 | $self->ivIncrement('workspaceCount'); | ||
| 2453 | |||
| 2454 | return $workspaceObj; | ||
| 2455 | } | ||
| 2456 | } | ||
| 2457 | |||
| 2458 | sub del_workspace { | ||
| 2459 | |||
| 2460 | # Called by $self->stop and ->setupWorkspaces | ||
| 2461 | |||
| 2462 | my ($self, $obj, $check) = @_; | ||
| 2463 | |||
| 2464 | # Check for improper arguments | ||
| 2465 | if (! defined $obj || defined $check) { | ||
| 2466 | |||
| 2467 | return $axmud::CLIENT->writeImproper($self->_objClass . '->del_workspace', @_); | ||
| 2468 | } | ||
| 2469 | |||
| 2470 | # (Workspace from which Axmud was launched cannot be deleted by this function, but is | ||
| 2471 | # deleted directly by $self->stop) | ||
| 2472 | if ($obj->number == 0 || ! $self->ivExists('workspaceHash', $obj->number)) { | ||
| 2473 | |||
| 2474 | return undef; | ||
| 2475 | |||
| 2476 | } else { | ||
| 2477 | |||
| 2478 | $obj->stop(); | ||
| 2479 | |||
| 2480 | $self->ivDelete('workspaceHash', $obj->number); | ||
| 2481 | |||
| 2482 | return 1; | ||
| 2483 | } | ||
| 2484 | } | ||
| 2485 | |||
| 2486 | ################## | ||
| 2487 | # Accessors - get | ||
| 2488 | |||
| 2489 | sub wmCtrlObj | ||
| 2490 | { $_[0]->{wmCtrlObj} } | ||
| 2491 | |||
| 2492 | sub workspaceHash | ||
| 2493 | { my $self = shift; return %{$self->{workspaceHash}}; } | ||
| 2494 | sub workspaceCount | ||
| 2495 | { $_[0]->{workspaceCount} } | ||
| 2496 | sub defaultWorkspaceObj | ||
| 2497 | { $_[0]->{defaultWorkspaceObj} } | ||
| 2498 | |||
| 2499 | sub gridHash | ||
| 2500 | { my $self = shift; return %{$self->{gridHash}}; } | ||
| 2501 | sub gridCount | ||
| 2502 | { $_[0]->{gridCount} } | ||
| 2503 | |||
| 2504 | sub gridWinHash | ||
| 2505 | { my $self = shift; return %{$self->{gridWinHash}}; } | ||
| 2506 | sub gridWinCount | ||
| 2507 | { $_[0]->{gridWinCount} } | ||
| 2508 | |||
| 2509 | sub freeWinHash | ||
| 2510 | { my $self = shift; return %{$self->{freeWinHash}}; } | ||
| 2511 | sub freeWinCount | ||
| 2512 | { $_[0]->{freeWinCount} } | ||
| 2513 | |||
| 2514 | sub textViewHash | ||
| 2515 | { my $self = shift; return %{$self->{textViewHash}}; } | ||
| 2516 | sub textViewCount | ||
| 2517 | { $_[0]->{textViewCount} } | ||
| 2518 | |||
| 2519 | sub gridPermitFlag | ||
| 2520 | { $_[0]->{gridPermitFlag} } | ||
| 2521 | sub newWorkspaceFlag | ||
| 2522 | { $_[0]->{newWorkspaceFlag} } | ||
| 2523 | |||
| 2524 | sub mainWinIconList | ||
| 2525 | { my $self = shift; return @{$self->{mainWinIconList}}; } | ||
| 2526 | sub mapWinIconList | ||
| 2527 | { my $self = shift; return @{$self->{mapWinIconList}}; } | ||
| 2528 | sub protocolWinIconList | ||
| 2529 | { my $self = shift; return @{$self->{protocolWinIconList}}; } | ||
| 2530 | sub fixedWinIconList | ||
| 2531 | { my $self = shift; return @{$self->{fixedWinIconList}}; } | ||
| 2532 | sub customWinIconList | ||
| 2533 | { my $self = shift; return @{$self->{customWinIconList}}; } | ||
| 2534 | sub externalWinIconList | ||
| 2535 | { my $self = shift; return @{$self->{externalWinIconList}}; } | ||
| 2536 | |||
| 2537 | sub viewerWinIconList | ||
| 2538 | { my $self = shift; return @{$self->{viewerWinIconList}}; } | ||
| 2539 | sub editWinIconList | ||
| 2540 | { my $self = shift; return @{$self->{editWinIconList}}; } | ||
| 2541 | sub prefWinIconList | ||
| 2542 | { my $self = shift; return @{$self->{prefWinIconList}}; } | ||
| 2543 | sub wizWinIconList | ||
| 2544 | { my $self = shift; return @{$self->{wizWinIconList}}; } | ||
| 2545 | sub dialogueWinIconList | ||
| 2546 | { my $self = shift; return @{$self->{dialogueWinIconList}}; } | ||
| 2547 | sub otherWinIconList | ||
| 2548 | { my $self = shift; return @{$self->{otherWinIconList}}; } | ||
| 2549 | } | ||
| 2550 | |||
| 2551 | # Package must return a true value | ||
| 2552 | 1 |