| 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::Table::xxx | ||
| 16 | # Table objects, which handle individual widgets (usually groups of widgets, within a single | ||
| 17 | # container widget) on an 'internal' window's Gtk3::Table | ||
| 18 | |||
| 19 | # Container table objects | ||
| 20 | |||
| 21 | { package Games::Axmud::Table::Holder; | ||
| 22 | |||
| 23 | use strict; | ||
| 24 | use warnings; | ||
| 25 | # use diagnostics; | ||
| 26 | |||
| 27 | use Glib qw(TRUE FALSE); | ||
| 28 | |||
| 29 | our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud); | ||
| 30 | |||
| 31 | ################## | ||
| 32 | # Constructors | ||
| 33 | |||
| 34 | sub new { | ||
| 35 | |||
| 36 | # Called by GA::Strip::Table->addTableObj | ||
| 37 | # Creates the GA::Table::Holder, which reserves an area of the table for some other table | ||
| 38 | # object (and creates no widgets of its own) | ||
| 39 | # | ||
| 40 | # Expected arguments | ||
| 41 | # $number - The table object's number within the parent strip object (matches | ||
| 42 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object | ||
| 43 | # created to access its default IVs) | ||
| 44 | # $name - A name for the table object. Can be any string or, if no name was | ||
| 45 | # specified in the call to the calling function, $name is the same as | ||
| 46 | # $number. (No part of the code checks that table object names are unique; | ||
| 47 | # if two or more table objects share the same ->name, usually the one with | ||
| 48 | # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16 | ||
| 49 | # chars) | ||
| 50 | # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table | ||
| 51 | # objects | ||
| 52 | # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the | ||
| 53 | # parent strip object's Gtk3::Grid for use exclusively by this table | ||
| 54 | # object. 'temp' for temporary table objects | ||
| 55 | # | ||
| 56 | # Optional arguments | ||
| 57 | # %initHash - A hash containing arbitrary data to use as the table object's | ||
| 58 | # initialisation settings. The table object should use default | ||
| 59 | # initialisation settings unless it can succesfully interpret one or more | ||
| 60 | # of the key-value pairs in the hash, if there are any | ||
| 61 | # - This type of table object recognises these initialisation settings: | ||
| 62 | # | ||
| 63 | # 'id' - If specified, can be any non-empty string. Any other code (for | ||
| 64 | # example, a task) can look for holders with a certain ID and, if | ||
| 65 | # one is found, replace it with their choice of table object; the | ||
| 66 | # area occupied by the holder remains empty until that time. Values | ||
| 67 | # might include types of 'grid' window such as 'map', or 'task' for | ||
| 68 | # task windows in general, or 'status_task' for the Status task in | ||
| 69 | # particular. If not specified, 'undef' or an empty string, 'task' is | ||
| 70 | # used as a default value | ||
| 71 | # | ||
| 72 | # Return values | ||
| 73 | # 'undef' on improper arguments | ||
| 74 | # Blessed reference to the newly-created object on success | ||
| 75 | |||
| 76 | my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_; | ||
| 77 | |||
| 78 | # Local variables | ||
| 79 | my ( | ||
| 80 | $winObj, | ||
| 81 | %modHash, | ||
| 82 | ); | ||
| 83 | |||
| 84 | # Check for improper arguments | ||
| 85 | if ( | ||
| 86 | ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj | ||
| 87 | || ! defined $zoneObj | ||
| 88 | ) { | ||
| 89 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 90 | } | ||
| 91 | |||
| 92 | # Deal with temporary table objects | ||
| 93 | if ($stripObj eq 'temp') { | ||
| 94 | $winObj = 'temp'; | ||
| 95 | } else { | ||
| 96 | $winObj = $stripObj->winObj; | ||
| 97 | } | ||
| 98 | |||
| 99 | # Default initialisation settings | ||
| 100 | %modHash = ( | ||
| 101 | 'id' => 'task', | ||
| 102 | ); | ||
| 103 | |||
| 104 | # Interpret the initialisation settings in %initHash, if any | ||
| 105 | foreach my $key (keys %modHash) { | ||
| 106 | |||
| 107 | $modHash{$key} = $initHash{$key}; | ||
| 108 | } | ||
| 109 | |||
| 110 | # Setup | ||
| 111 | my $self = { | ||
| 112 | _objName => 'table_obj_' . $number, | ||
| 113 | _objClass => $class, | ||
| 114 | _parentFile => undef, # No parent file object | ||
| 115 | _parentWorld => undef, # No parent file object | ||
| 116 | _privFlag => TRUE, # All IVs are private | ||
| 117 | |||
| 118 | # Standard table object IVs | ||
| 119 | # ------------------------- | ||
| 120 | |||
| 121 | # The table object's number within the parent strip object (matches | ||
| 122 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to | ||
| 123 | # access its default IVs) | ||
| 124 | number => $number, | ||
| 125 | # A name for the table object. Can be any string or, if no name was specified in the | ||
| 126 | # call to the calling function, $name is the same as $number. (No part of the code | ||
| 127 | # checks that table object names are unique; if two or more table objects share the | ||
| 128 | # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary | ||
| 129 | # table objects. Max 16 chars) | ||
| 130 | name => $name, | ||
| 131 | # The type of table object (custom table objects should use a ->type starting with | ||
| 132 | # 'custom_' to avoid clashing with future built-in table objects) | ||
| 133 | type => 'holder', | ||
| 134 | # The parent strip object (GA::Strip::Table) | ||
| 135 | stripObj => $stripObj, | ||
| 136 | # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for | ||
| 137 | # temporary table objects | ||
| 138 | winObj => $winObj, | ||
| 139 | # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip | ||
| 140 | # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary | ||
| 141 | # table objects | ||
| 142 | zoneObj => $zoneObj, | ||
| 143 | |||
| 144 | # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is | ||
| 145 | # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as | ||
| 146 | # when a connection to a world terminates) | ||
| 147 | allowRemoveFlag => TRUE, | ||
| 148 | # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is | ||
| 149 | # created. Set to FALSE if it can't be resized | ||
| 150 | allowResizeFlag => TRUE, | ||
| 151 | # Initialisation settings stored as a hash (see the comments above) | ||
| 152 | initHash => \%modHash, | ||
| 153 | # Reference to a function to call when some widget is used. This IV is set only when | ||
| 154 | # required by this type of table object. It can be set by a call to | ||
| 155 | # $self->set_func() or by some setting in $self->initHash, which is applied in the | ||
| 156 | # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the | ||
| 157 | # generic object function Games::Axmud->getMethodRef() | ||
| 158 | funcRef => undef, | ||
| 159 | # A value passed to ->funcRef when it is called which identifies this table object and | ||
| 160 | # its widget(s). Can be any value, including 'undef'. It can be set by a call to | ||
| 161 | # $self->set_id() or by some setting in $self->initHash, which is applied in the call | ||
| 162 | # to $self->objEnable() | ||
| 163 | funcID => '', | ||
| 164 | |||
| 165 | # The container widget(s) for this table object; both IVs are always set to the same | ||
| 166 | # widget | ||
| 167 | packingBox => undef, # Gtk3::Grid | ||
| 168 | packingBox2 => undef, # Gtk3::Grid | ||
| 169 | |||
| 170 | # Other IVs | ||
| 171 | # --------- | ||
| 172 | |||
| 173 | # Any non-empty string which identifies what kind of table object can be put here (see | ||
| 174 | # comments above) | ||
| 175 | id => 'task', | ||
| 176 | }; | ||
| 177 | |||
| 178 | # Bless the object into existence | ||
| 179 | bless $self, $class; | ||
| 180 | |||
| 181 | return $self; | ||
| 182 | } | ||
| 183 | |||
| 184 | ################## | ||
| 185 | # Methods | ||
| 186 | |||
| 187 | # Standard table object functions | ||
| 188 | |||
| 189 | sub objEnable { | ||
| 190 | |||
| 191 | # Called by GA::Strip::Table->addTableObj | ||
| 192 | # Sets up the table object's widgets | ||
| 193 | # | ||
| 194 | # Expected arguments | ||
| 195 | # (none besides $self) | ||
| 196 | # | ||
| 197 | # Return values | ||
| 198 | # 'undef' on improper arguments | ||
| 199 | # 1 on success | ||
| 200 | |||
| 201 | my ($self, $check) = @_; | ||
| 202 | |||
| 203 | # Local variables | ||
| 204 | my $id; | ||
| 205 | |||
| 206 | # Check for improper arguments | ||
| 207 | if (defined $check) { | ||
| 208 | |||
| 209 | return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_); | ||
| 210 | } | ||
| 211 | |||
| 212 | # Interpret $self->initHash, replacing any invalid values | ||
| 213 | $id = $self->ivShow('initHash', 'id'); | ||
| 214 | if (defined $id && $id ne '') { | ||
| 215 | |||
| 216 | $id = 'task'; | ||
| 217 | } | ||
| 218 | |||
| 219 | # Create the packing box, depending on $type | ||
| 220 | my $packingBox = Gtk3::Grid->new(); | ||
| 221 | |||
| 222 | # For this table object, ->packingBox and ->packingBox2 always refer to the same widget | ||
| 223 | my $packingBox2 = $packingBox; | ||
| 224 | |||
| 225 | # Set expansion | ||
| 226 | $packingBox->set_hexpand(TRUE); | ||
| 227 | $packingBox->set_vexpand(TRUE); | ||
| 228 | |||
| 229 | # Update IVs | ||
| 230 | $self->ivPoke('packingBox', $packingBox); | ||
| 231 | $self->ivPoke('packingBox2', $packingBox2); | ||
| 232 | $self->ivPoke('id', $id); | ||
| 233 | |||
| 234 | return 1; | ||
| 235 | } | ||
| 236 | |||
| 237 | # sub objDestroy { # Inherited from GA::Generic::Table | ||
| 238 | |||
| 239 | # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table | ||
| 240 | |||
| 241 | # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table | ||
| 242 | |||
| 243 | # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table | ||
| 244 | |||
| 245 | # ->signal_connects | ||
| 246 | |||
| 247 | # Other functions | ||
| 248 | |||
| 249 | ################## | ||
| 250 | # Accessors - set | ||
| 251 | |||
| 252 | # (Get equivalents) | ||
| 253 | |||
| 254 | ################## | ||
| 255 | # Accessors - get | ||
| 256 | |||
| 257 | sub id | ||
| 258 | { $_[0]->{id} } | ||
| 259 | } | ||
| 260 | |||
| 261 | { package Games::Axmud::Table::Container; | ||
| 262 | |||
| 263 | use strict; | ||
| 264 | use warnings; | ||
| 265 | # use diagnostics; | ||
| 266 | |||
| 267 | use Glib qw(TRUE FALSE); | ||
| 268 | |||
| 269 | our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud); | ||
| 270 | |||
| 271 | ################## | ||
| 272 | # Constructors | ||
| 273 | |||
| 274 | sub new { | ||
| 275 | |||
| 276 | # Called by GA::Strip::Table->addTableObj | ||
| 277 | # Creates the GA::Table::Container, which creates a container widget into which other | ||
| 278 | # widgets can be freely added | ||
| 279 | # | ||
| 280 | # Expected arguments | ||
| 281 | # $number - The table object's number within the parent strip object (matches | ||
| 282 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object | ||
| 283 | # created to access its default IVs) | ||
| 284 | # $name - A name for the table object. Can be any string or, if no name was | ||
| 285 | # specified in the call to the calling function, $name is the same as | ||
| 286 | # $number. (No part of the code checks that table object names are unique; | ||
| 287 | # if two or more table objects share the same ->name, usually the one with | ||
| 288 | # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16 | ||
| 289 | # chars) | ||
| 290 | # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table | ||
| 291 | # objects | ||
| 292 | # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the | ||
| 293 | # parent strip object's Gtk3::Grid for use exclusively by this table | ||
| 294 | # object. 'temp' for temporary table objects | ||
| 295 | # | ||
| 296 | # Optional arguments | ||
| 297 | # %initHash - A hash containing arbitrary data to use as the table object's | ||
| 298 | # initialisation settings. The table object should use default | ||
| 299 | # initialisation settings unless it can succesfully interpret one or more | ||
| 300 | # of the key-value pairs in the hash, if there are any | ||
| 301 | # - This type of table object recognises these initialisation settings: | ||
| 302 | # | ||
| 303 | # 'type' - 'grid' for a Gtk3::Grid, 'horizontal'/'hbox' for a Gtk3::HBox, | ||
| 304 | # 'vertical'/'vbox' for a Gtk3::VBox, 'scroll'/'scroller' for a | ||
| 305 | # Gtk3::ScrolledWindow, 'frame' for a Gtk3::Frame. If an invalid | ||
| 306 | # 'type' or if 'type' is not specified, 'grid' is used | ||
| 307 | # 'expand_horizontal_flag' - Ignored if 'type' is 'horizontal' or | ||
| 308 | # 'vertical'. If TRUE or not specified, the table object expands | ||
| 309 | # horizontally; if FALSE, it doesn't | ||
| 310 | # 'expand_vertical_flag' - Ignored if 'type' is 'horizontal' or | ||
| 311 | # 'vertical'. If TRUE or not specified, the table object expands | ||
| 312 | # vertically; if FALSE, it doesn't | ||
| 313 | # 'equal_flag' - Ignored if 'type' is not 'horizontal' or 'vertical'. | ||
| 314 | # If TRUE, sets the container's homogeneity flag to TRUE; if FALSE, | ||
| 315 | # 'undef' or not specified, sets it to FALSE | ||
| 316 | # 'spacing' - Ignored if 'type' is not 'grid', 'horizontal' or 'vertical'. | ||
| 317 | # Sets the spacing between widgets packed into the box. If specified, | ||
| 318 | # must be an integer, >= 0 | ||
| 319 | # 'scroll_horizontal' - Ignored if 'type' is not 'scroll' or 'scroller'. | ||
| 320 | # Sets the horizontal scrolling policy; the value must be 'always', | ||
| 321 | # 'automatic' or 'never'. If 'undef', not specified or an invalid | ||
| 322 | # value, 'automatic' is used | ||
| 323 | # 'scroll_vertical' - Ignored if 'type' is not 'scroll' or 'scroller'. | ||
| 324 | # Sets the vertical scrolling policy; the value must be 'always', | ||
| 325 | # 'automatic' or 'never'. If 'undef', not specified or an invalid | ||
| 326 | # value, 'automatic' is used # | ||
| 327 | # 'frame_title' - Ignored if 'type' is not 'frame' (this is different from | ||
| 328 | # the behaviour of some other table objects, for which 'frame_title' | ||
| 329 | # creates a frame). If a non-empty string, the string is used as the | ||
| 330 | # frame title | ||
| 331 | # | ||
| 332 | # Return values | ||
| 333 | # 'undef' on improper arguments | ||
| 334 | # Blessed reference to the newly-created object on success | ||
| 335 | |||
| 336 | my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_; | ||
| 337 | |||
| 338 | # Local variables | ||
| 339 | # Local variables | ||
| 340 | my ( | ||
| 341 | $winObj, | ||
| 342 | %modHash, | ||
| 343 | ); | ||
| 344 | |||
| 345 | # Check for improper arguments | ||
| 346 | if ( | ||
| 347 | ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj | ||
| 348 | || ! defined $zoneObj | ||
| 349 | ) { | ||
| 350 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 351 | } | ||
| 352 | |||
| 353 | # Deal with temporary table objects | ||
| 354 | if ($stripObj eq 'temp') { | ||
| 355 | $winObj = 'temp'; | ||
| 356 | } else { | ||
| 357 | $winObj = $stripObj->winObj; | ||
| 358 | } | ||
| 359 | |||
| 360 | # Default initialisation settings | ||
| 361 | %modHash = ( | ||
| 362 | 'type' => 'grid', | ||
| 363 | 'expand_horizontal_flag' => TRUE, | ||
| 364 | 'expand_vertical_flag' => TRUE, | ||
| 365 | 'equal_flag' => FALSE, | ||
| 366 | 'spacing' => 0, | ||
| 367 | 'scroll_horizontal' => 'automatic', | ||
| 368 | 'scroll_vertical' => 'automatic', | ||
| 369 | 'frame_title' => '', | ||
| 370 | ); | ||
| 371 | |||
| 372 | # Interpret the initialisation settings in %initHash, if any | ||
| 373 | foreach my $key (keys %modHash) { | ||
| 374 | |||
| 375 | if (exists $initHash{$key}) { | ||
| 376 | |||
| 377 | if ($key =~ m/flag$/) { | ||
| 378 | |||
| 379 | if ($initHash{$key}) { | ||
| 380 | $modHash{$key} = TRUE; | ||
| 381 | } else { | ||
| 382 | $modHash{$key} = FALSE; | ||
| 383 | } | ||
| 384 | |||
| 385 | } else { | ||
| 386 | |||
| 387 | $modHash{$key} = $initHash{$key}; | ||
| 388 | } | ||
| 389 | } | ||
| 390 | } | ||
| 391 | |||
| 392 | # Setup | ||
| 393 | my $self = { | ||
| 394 | _objName => 'table_obj_' . $number, | ||
| 395 | _objClass => $class, | ||
| 396 | _parentFile => undef, # No parent file object | ||
| 397 | _parentWorld => undef, # No parent file object | ||
| 398 | _privFlag => TRUE, # All IVs are private | ||
| 399 | |||
| 400 | # Standard table object IVs | ||
| 401 | # ------------------------- | ||
| 402 | |||
| 403 | # The table object's number within the parent strip object (matches | ||
| 404 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to | ||
| 405 | # access its default IVs) | ||
| 406 | number => $number, | ||
| 407 | # A name for the table object. Can be any string or, if no name was specified in the | ||
| 408 | # call to the calling function, $name is the same as $number. (No part of the code | ||
| 409 | # checks that table object names are unique; if two or more table objects share the | ||
| 410 | # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary | ||
| 411 | # table objects. Max 16 chars) | ||
| 412 | name => $name, | ||
| 413 | # The type of table object (custom table objects should use a ->type starting with | ||
| 414 | # 'custom_' to avoid clashing with future built-in table objects) | ||
| 415 | type => 'container', | ||
| 416 | # The parent strip object (GA::Strip::Table) | ||
| 417 | stripObj => $stripObj, | ||
| 418 | # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for | ||
| 419 | # temporary table objects | ||
| 420 | winObj => $winObj, | ||
| 421 | # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip | ||
| 422 | # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary | ||
| 423 | # table objects | ||
| 424 | zoneObj => $zoneObj, | ||
| 425 | |||
| 426 | # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is | ||
| 427 | # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as | ||
| 428 | # when a connection to a world terminates) | ||
| 429 | allowRemoveFlag => TRUE, | ||
| 430 | # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is | ||
| 431 | # created. Set to FALSE if it can't be resized | ||
| 432 | allowResizeFlag => TRUE, | ||
| 433 | # Initialisation settings stored as a hash (see the comments above) | ||
| 434 | initHash => \%modHash, | ||
| 435 | # Reference to a function to call when some widget is used. This IV is set only when | ||
| 436 | # required by this type of table object. It can be set by a call to | ||
| 437 | # $self->set_func() or by some setting in $self->initHash, which is applied in the | ||
| 438 | # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the | ||
| 439 | # generic object function Games::Axmud->getMethodRef() | ||
| 440 | funcRef => undef, | ||
| 441 | # A value passed to ->funcRef when it is called which identifies this table object and | ||
| 442 | # its widget(s). Can be any value, including 'undef'. It can be set by a call to | ||
| 443 | # $self->set_id() or by some setting in $self->initHash, which is applied in the call | ||
| 444 | # to $self->objEnable() | ||
| 445 | funcID => '', | ||
| 446 | |||
| 447 | # The container widget(s) for this table object; both IVs are always set to the same | ||
| 448 | # widget | ||
| 449 | packingBox => undef, # Gtk3::Grid, Gtk3::HBox, ::VBox, | ||
| 450 | # ::ScrolledWindow, ::Frame | ||
| 451 | packingBox2 => undef, # ditto | ||
| 452 | |||
| 453 | # Other IVs | ||
| 454 | # --------- | ||
| 455 | |||
| 456 | # The container type: 'horizontal', 'vertical', 'scroll' or 'frame'. The alternative | ||
| 457 | # type values 'hbox', 'vbox' and 'scroller' are converted, if specified in %initHash | ||
| 458 | type => undef, | ||
| 459 | }; | ||
| 460 | |||
| 461 | # Bless the object into existence | ||
| 462 | bless $self, $class; | ||
| 463 | |||
| 464 | return $self; | ||
| 465 | } | ||
| 466 | |||
| 467 | ################## | ||
| 468 | # Methods | ||
| 469 | |||
| 470 | # Standard table object functions | ||
| 471 | |||
| 472 | sub objEnable { | ||
| 473 | |||
| 474 | # Called by GA::Strip::Table->addTableObj | ||
| 475 | # Sets up the table object's widgets | ||
| 476 | # | ||
| 477 | # Expected arguments | ||
| 478 | # (none besides $self) | ||
| 479 | # | ||
| 480 | # Return values | ||
| 481 | # 'undef' on improper arguments | ||
| 482 | # 1 on success | ||
| 483 | |||
| 484 | my ($self, $check) = @_; | ||
| 485 | |||
| 486 | # Local variables | ||
| 487 | my ($type, $hExpandFlag, $vExpandFlag, $equalFlag, $spacing, $hScroll, $vScroll, $label); | ||
| 488 | |||
| 489 | # Check for improper arguments | ||
| 490 | if (defined $check) { | ||
| 491 | |||
| 492 | return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_); | ||
| 493 | } | ||
| 494 | |||
| 495 | # Interpret $self->initHash, replacing any invalid values | ||
| 496 | $type = $self->ivShow('initHash', 'type'); | ||
| 497 | if ($type eq 'horizontal' || $type eq 'hbox') { | ||
| 498 | $type = 'horizontal'; | ||
| 499 | } elsif ($type eq 'vertical' || $type eq 'vbox') { | ||
| 500 | $type = 'vertical'; | ||
| 501 | } elsif ($type eq 'scroll' || $type eq 'scroller') { | ||
| 502 | $type = 'scroll'; | ||
| 503 | } elsif ($type eq 'frame') { | ||
| 504 | $type = 'frame'; | ||
| 505 | } else { | ||
| 506 | $type = 'grid'; | ||
| 507 | } | ||
| 508 | |||
| 509 | $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag')); | ||
| 510 | $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag')); | ||
| 511 | $equalFlag = $self->testFlag($self->ivShow('initHash', 'equal_flag')); | ||
| 512 | $spacing = $self->testInt($self->ivShow('initHash', 'spacing'), 0, 0); | ||
| 513 | |||
| 514 | $hScroll = $self->ivShow('initHash', 'scroll_horizontal'); | ||
| 515 | if ($hScroll ne 'always' && $hScroll ne 'automatic' && $hScroll ne 'never') { | ||
| 516 | |||
| 517 | $hScroll = 'automatic'; | ||
| 518 | } | ||
| 519 | |||
| 520 | $vScroll = $self->ivShow('initHash', 'scroll_vertical'); | ||
| 521 | if ($vScroll ne 'always' && $vScroll ne 'automatic' && $vScroll ne 'never') { | ||
| 522 | |||
| 523 | $vScroll = 'automatic'; | ||
| 524 | } | ||
| 525 | |||
| 526 | $label = $self->ivShow('initHash', 'frame_title'); | ||
| 527 | if (! defined $label) { | ||
| 528 | |||
| 529 | $label = ''; | ||
| 530 | } | ||
| 531 | |||
| 532 | # Create the packing box, depending on $type | ||
| 533 | my ($packingBox, $packingBox2); | ||
| 534 | if ($type eq 'grid') { | ||
| 535 | |||
| 536 | $packingBox = Gtk3::Grid->new(); | ||
| 537 | $packingBox->set_row_spacing($spacing); | ||
| 538 | $packingBox->set_column_spacing($spacing); | ||
| 539 | |||
| 540 | } elsif ($type eq 'horizontal' || $type eq 'hbox') { | ||
| 541 | |||
| 542 | $packingBox = Gtk3::HBox->new($equalFlag, $spacing); | ||
| 543 | $type = 'horizontal'; | ||
| 544 | |||
| 545 | } elsif ($type eq 'vertical' || $type eq 'vbox') { | ||
| 546 | |||
| 547 | $packingBox = Gtk3::VBox->new($equalFlag, $spacing); | ||
| 548 | $type = 'vertical'; | ||
| 549 | |||
| 550 | } elsif ($type eq 'scroll' || $type eq 'scroller') { | ||
| 551 | |||
| 552 | $packingBox = Gtk3::ScrolledWindow->new(); | ||
| 553 | $packingBox->set_policy($hScroll, $vScroll); | ||
| 554 | $type = 'scroll'; | ||
| 555 | |||
| 556 | } elsif ($type eq 'frame') { | ||
| 557 | |||
| 558 | if (! $label) { | ||
| 559 | $packingBox = Gtk3::Frame->new(); | ||
| 560 | } else { | ||
| 561 | $packingBox = Gtk3::Frame->new($label); | ||
| 562 | } | ||
| 563 | } | ||
| 564 | |||
| 565 | # Set expansion | ||
| 566 | if ($type eq 'grid' || $type eq 'scroll' || $type eq 'frame') { | ||
| 567 | |||
| 568 | $packingBox->set_hexpand($hExpandFlag); | ||
| 569 | $packingBox->set_vexpand($vExpandFlag); | ||
| 570 | |||
| 571 | } else { | ||
| 572 | |||
| 573 | $packingBox->set_hexpand(TRUE); | ||
| 574 | $packingBox->set_vexpand(TRUE); | ||
| 575 | } | ||
| 576 | |||
| 577 | # For this table object, ->packingBox and ->packingBox2 always refer to the same widget | ||
| 578 | $packingBox2 = $packingBox; | ||
| 579 | |||
| 580 | # Update IVs | ||
| 581 | $self->ivPoke('packingBox', $packingBox); | ||
| 582 | $self->ivPoke('packingBox2', $packingBox2); | ||
| 583 | $self->ivPoke('type', $type); | ||
| 584 | |||
| 585 | return 1; | ||
| 586 | } | ||
| 587 | |||
| 588 | # sub objDestroy { # Inherited from GA::Generic::Table | ||
| 589 | |||
| 590 | # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table | ||
| 591 | |||
| 592 | # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table | ||
| 593 | |||
| 594 | # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table | ||
| 595 | |||
| 596 | # ->signal_connects | ||
| 597 | |||
| 598 | # Other functions | ||
| 599 | |||
| 600 | sub packStart { | ||
| 601 | |||
| 602 | # Can be called by anything to add a widget to the main container widget | ||
| 603 | # If $self->type is 'horizontal' or 'vertical', this function and/or $self->packEnd can be | ||
| 604 | # called any number of times | ||
| 605 | # If $self->type is 'scroll' or 'frame', either this function or $self->packEnd can be | ||
| 606 | # called once (in that case, both functions behave identically) | ||
| 607 | # | ||
| 608 | # Expected arguments | ||
| 609 | # $widget - The Gtk3 widget to add to the main container widget | ||
| 610 | # | ||
| 611 | # Optional arguments (ignored if $self->type is not 'horizontal' or 'vertical' | ||
| 612 | # $expandFlag - If TRUE, the widget receives extra space when the container gets bigger. | ||
| 613 | # If FALSE (or 'undef'), it stays the same size (default is FALSE) | ||
| 614 | # $fillFlag - If TRUE, extra space given to the widget is allocated to the widget. If | ||
| 615 | # FALSE (or 'undef'), extra space is used as padding (default is FALSE) | ||
| 616 | # $spacing - The space (in pixels) between this widget and its neighbours. If | ||
| 617 | # specified, must be an integer, >= 0 (default is 0) | ||
| 618 | # | ||
| 619 | # Return values | ||
| 620 | # 'undef' on improper arguments or if the main container widget is full | ||
| 621 | # 1 on success | ||
| 622 | |||
| 623 | my ($self, $widget, $expandFlag, $fillFlag, $spacing, $check) = @_; | ||
| 624 | |||
| 625 | # Check for improper arguments | ||
| 626 | if (! defined $widget || defined $check) { | ||
| 627 | |||
| 628 | return $axmud::CLIENT->writeImproper($self->_objClass . '->packStart', @_); | ||
| 629 | } | ||
| 630 | |||
| 631 | if ($self->type eq 'horizontal' || $self->type eq 'vertical') { | ||
| 632 | |||
| 633 | # Use TRUE or FALSE flags | ||
| 634 | if (! $expandFlag) { | ||
| 635 | $expandFlag = FALSE; | ||
| 636 | } else { | ||
| 637 | $expandFlag = TRUE; | ||
| 638 | } | ||
| 639 | |||
| 640 | if (! $fillFlag) { | ||
| 641 | $fillFlag = FALSE; | ||
| 642 | } else { | ||
| 643 | $fillFlag = TRUE; | ||
| 644 | } | ||
| 645 | |||
| 646 | # Check $spacing is an integer, or use a default value | ||
| 647 | if (! defined $spacing || ! $axmud::CLIENT->intCheck($spacing, 0)) { | ||
| 648 | |||
| 649 | $spacing = 0; | ||
| 650 | } | ||
| 651 | |||
| 652 | $self->packingBox2->pack_start($widget, $expandFlag, $fillFlag, $spacing); | ||
| 653 | |||
| 654 | return 1; | ||
| 655 | |||
| 656 | } else { | ||
| 657 | |||
| 658 | # Can't pack the widget if the main container widget already contains something | ||
| 659 | if ($self->packingBox2->get_children()) { | ||
| 660 | |||
| 661 | return undef; | ||
| 662 | } | ||
| 663 | |||
| 664 | if ($self->type eq 'scroll') { | ||
| 665 | $self->packingBox2->add_with_viewport($widget); | ||
| 666 | } else { | ||
| 667 | $self->packingBox2->add($widget); | ||
| 668 | } | ||
| 669 | |||
| 670 | return 1; | ||
| 671 | } | ||
| 672 | } | ||
| 673 | |||
| 674 | sub packEnd { | ||
| 675 | |||
| 676 | # Can be called by anything to add a widget to the main container widget | ||
| 677 | # If $self->type is 'horizontal' or 'vertical', this function and/or $self->packStart can be | ||
| 678 | # called any number of times | ||
| 679 | # If $self->type is 'scroll' or 'frame', either this function or $self->packStart can be | ||
| 680 | # called once (in that case, both functions behave identically) | ||
| 681 | # | ||
| 682 | # Expected arguments | ||
| 683 | # $widget - The Gtk3 widget to add to the main container widget | ||
| 684 | # | ||
| 685 | # Optional arguments (ignored if $self->type is not 'horizontal' or 'vertical' | ||
| 686 | # $expandFlag - If TRUE, the widget receives extra space when the container gets bigger. | ||
| 687 | # If FALSE (or 'undef'), it stays the same size (default is FALSE) | ||
| 688 | # $fillFlag - If TRUE, extra space given to the widget is allocated to the widget. If | ||
| 689 | # FALSE (or 'undef'), extra space is used as padding (default is FALSE) | ||
| 690 | # $spacing - The space (in pixels) between this widget and its neighbours. If | ||
| 691 | # specified, must be an integer, >= 0 (default is 0) | ||
| 692 | # | ||
| 693 | # Return values | ||
| 694 | # 'undef' on improper arguments or if the main container widget is full | ||
| 695 | # 1 on success | ||
| 696 | |||
| 697 | my ($self, $widget, $expandFlag, $fillFlag, $spacing, $check) = @_; | ||
| 698 | |||
| 699 | # Check for improper arguments | ||
| 700 | if (! defined $widget || defined $check) { | ||
| 701 | |||
| 702 | return $axmud::CLIENT->writeImproper($self->_objClass . '->packEnd', @_); | ||
| 703 | } | ||
| 704 | |||
| 705 | if ($self->type eq 'horizontal' || $self->type eq 'vertical') { | ||
| 706 | |||
| 707 | # Use TRUE or FALSE flags | ||
| 708 | if (! $expandFlag) { | ||
| 709 | $expandFlag = FALSE; | ||
| 710 | } else { | ||
| 711 | $expandFlag = TRUE; | ||
| 712 | } | ||
| 713 | |||
| 714 | if (! $fillFlag) { | ||
| 715 | $fillFlag = FALSE; | ||
| 716 | } else { | ||
| 717 | $fillFlag = TRUE; | ||
| 718 | } | ||
| 719 | |||
| 720 | # Check $spacing is an integer, or use a default value | ||
| 721 | if (! defined $spacing || ! $axmud::CLIENT->intCheck($spacing, 0)) { | ||
| 722 | |||
| 723 | $spacing = 0; | ||
| 724 | } | ||
| 725 | |||
| 726 | $self->packingBox2->pack_end($widget, $expandFlag, $fillFlag, $spacing); | ||
| 727 | |||
| 728 | return 1; | ||
| 729 | |||
| 730 | } else { | ||
| 731 | |||
| 732 | # Can't pack the widget if the main container widget already contains something | ||
| 733 | if ($self->packingBox2->get_children()) { | ||
| 734 | |||
| 735 | return undef; | ||
| 736 | } | ||
| 737 | |||
| 738 | if ($self->type eq 'scroll') { | ||
| 739 | $self->packingBox2->add_with_viewport($widget); | ||
| 740 | } else { | ||
| 741 | $self->packingBox2->add($widget); | ||
| 742 | } | ||
| 743 | |||
| 744 | return 1; | ||
| 745 | } | ||
| 746 | } | ||
| 747 | |||
| 748 | sub remove { | ||
| 749 | |||
| 750 | # Can be called by anything to remove a widget from the main container widget | ||
| 751 | # | ||
| 752 | # Expected arguments | ||
| 753 | # $widget - The Gtk3 widget to remove from the main container widget | ||
| 754 | # | ||
| 755 | # Return values | ||
| 756 | # 'undef' on improper arguments | ||
| 757 | # 1 otherwise | ||
| 758 | |||
| 759 | my ($self, $widget, $check) = @_; | ||
| 760 | |||
| 761 | # Check for improper arguments | ||
| 762 | if (! defined $widget || defined $check) { | ||
| 763 | |||
| 764 | return $axmud::CLIENT->writeImproper($self->_objClass . '->remove', @_); | ||
| 765 | } | ||
| 766 | |||
| 767 | return $axmud::CLIENT->desktopObj->removeWidget($self->packingBox2, $widget); | ||
| 768 | } | ||
| 769 | |||
| 770 | sub empty { | ||
| 771 | |||
| 772 | # Can be called by anything to remove all widgets from the main container widget | ||
| 773 | # | ||
| 774 | # Expected arguments | ||
| 775 | # (none besides $self) | ||
| 776 | # | ||
| 777 | # Return values | ||
| 778 | # 'undef' on improper arguments | ||
| 779 | # 1 otherwise | ||
| 780 | |||
| 781 | my ($self, $check) = @_; | ||
| 782 | |||
| 783 | # Check for improper arguments | ||
| 784 | if (defined $check) { | ||
| 785 | |||
| 786 | return $axmud::CLIENT->writeImproper($self->_objClass . '->empty', @_); | ||
| 787 | } | ||
| 788 | |||
| 789 | foreach my $child ($self->packingBox2->get_children()) { | ||
| 790 | |||
| 791 | $self->packingBox2->remove($child); | ||
| 792 | } | ||
| 793 | |||
| 794 | return 1; | ||
| 795 | } | ||
| 796 | |||
| 797 | ################## | ||
| 798 | # Accessors - set | ||
| 799 | |||
| 800 | sub set_equal { | ||
| 801 | |||
| 802 | my ($self, $flag, $check) = @_; | ||
| 803 | |||
| 804 | # Check for improper arguments | ||
| 805 | if (! defined $flag || defined $check) { | ||
| 806 | |||
| 807 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_equal', @_); | ||
| 808 | } | ||
| 809 | |||
| 810 | if ($self->type ne 'horizontal' && $self->type ne 'vertical') { | ||
| 811 | |||
| 812 | return undef; | ||
| 813 | } | ||
| 814 | |||
| 815 | if (! $flag) { | ||
| 816 | |||
| 817 | $self->packingBox2->set_column_homogeneous(FALSE); | ||
| 818 | $self->packingBox2->set_row_homogeneous(FALSE); | ||
| 819 | |||
| 820 | } else { | ||
| 821 | |||
| 822 | $self->packingBox2->set_column_homogeneous(TRUE); | ||
| 823 | $self->packingBox2->set_row_homogeneous(TRUE); | ||
| 824 | } | ||
| 825 | |||
| 826 | return 1; | ||
| 827 | } | ||
| 828 | |||
| 829 | sub set_label { | ||
| 830 | |||
| 831 | my ($self, $label, $check) = @_; | ||
| 832 | |||
| 833 | # Check for improper arguments | ||
| 834 | if (! defined $label || defined $check) { | ||
| 835 | |||
| 836 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_label', @_); | ||
| 837 | } | ||
| 838 | |||
| 839 | if ($self->type ne 'frame') { | ||
| 840 | |||
| 841 | return undef; | ||
| 842 | } | ||
| 843 | |||
| 844 | $self->packingBox2->set_label($label); | ||
| 845 | |||
| 846 | return 1; | ||
| 847 | } | ||
| 848 | |||
| 849 | sub set_scroll { | ||
| 850 | |||
| 851 | my ($self, $hScroll, $vScroll, $check) = @_; | ||
| 852 | |||
| 853 | # Check for improper arguments | ||
| 854 | if (! defined $hScroll || ! defined $vScroll || defined $check) { | ||
| 855 | |||
| 856 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_scroll', @_); | ||
| 857 | } | ||
| 858 | |||
| 859 | if ($self->type ne 'scroll') { | ||
| 860 | |||
| 861 | return undef; | ||
| 862 | } | ||
| 863 | |||
| 864 | foreach my $policy ($hScroll, $vScroll) { | ||
| 865 | |||
| 866 | if ($policy ne 'always' && $policy ne 'automatic' && $policy ne 'never') { | ||
| 867 | |||
| 868 | return undef; | ||
| 869 | } | ||
| 870 | } | ||
| 871 | |||
| 872 | $self->packingBox2->set_policy($hScroll, $vScroll); | ||
| 873 | |||
| 874 | return 1; | ||
| 875 | } | ||
| 876 | |||
| 877 | sub set_spacing { | ||
| 878 | |||
| 879 | my ($self, $spacing, $check) = @_; | ||
| 880 | |||
| 881 | # Check for improper arguments | ||
| 882 | if (! defined $spacing || defined $check) { | ||
| 883 | |||
| 884 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_spacing', @_); | ||
| 885 | } | ||
| 886 | |||
| 887 | if ( | ||
| 888 | ($self->type ne 'horizontal' && $self->type ne 'vertical') | ||
| 889 | || ! $axmud::CLIENT->intCheck($spacing, 0) | ||
| 890 | ) { | ||
| 891 | return undef; | ||
| 892 | } | ||
| 893 | |||
| 894 | $self->packingBox2->set_spacing(); | ||
| 895 | |||
| 896 | return 1; | ||
| 897 | } | ||
| 898 | |||
| 899 | # (Get equivalents) | ||
| 900 | |||
| 901 | sub get_equal { | ||
| 902 | |||
| 903 | # Returns flag | ||
| 904 | |||
| 905 | my ($self, $check) = @_; | ||
| 906 | |||
| 907 | # Check for improper arguments | ||
| 908 | if (defined $check) { | ||
| 909 | |||
| 910 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_equal', @_); | ||
| 911 | } | ||
| 912 | |||
| 913 | if ($self->type ne 'horizontal' && $self->type ne 'vertical') { | ||
| 914 | |||
| 915 | return undef; | ||
| 916 | } | ||
| 917 | |||
| 918 | # Columns and rows are set together, so we can return a single value | ||
| 919 | if (! $self->packingBox2->get_column_homogeneous()) { | ||
| 920 | return FALSE; | ||
| 921 | } else { | ||
| 922 | return TRUE; | ||
| 923 | } | ||
| 924 | } | ||
| 925 | |||
| 926 | sub get_label { | ||
| 927 | |||
| 928 | # Returns a string (might be an empty string) | ||
| 929 | |||
| 930 | my ($self, $check) = @_; | ||
| 931 | |||
| 932 | # Check for improper arguments | ||
| 933 | if (defined $check) { | ||
| 934 | |||
| 935 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_label', @_); | ||
| 936 | } | ||
| 937 | |||
| 938 | if ($self->type ne 'frame') { | ||
| 939 | |||
| 940 | return undef; | ||
| 941 | |||
| 942 | } else { | ||
| 943 | |||
| 944 | return $self->packingBox2->get_label(); | ||
| 945 | } | ||
| 946 | } | ||
| 947 | |||
| 948 | sub get_scroll { | ||
| 949 | |||
| 950 | # Returns list in form (policy, policy), where 'policy' is one of the strings 'always', | ||
| 951 | # 'automatic', 'never' | ||
| 952 | |||
| 953 | my ($self, $check) = @_; | ||
| 954 | |||
| 955 | # Local variables | ||
| 956 | my (@emptyList, @policyList); | ||
| 957 | |||
| 958 | # Check for improper arguments | ||
| 959 | if (defined $check) { | ||
| 960 | |||
| 961 | $axmud::CLIENT->writeImproper($self->_objClass . '->get_scroll', @_); | ||
| 962 | return @emptyList; | ||
| 963 | } | ||
| 964 | |||
| 965 | if ($self->type ne 'scroll') { | ||
| 966 | |||
| 967 | return @emptyList; | ||
| 968 | } | ||
| 969 | |||
| 970 | @policyList = $self->packingBox2->get_policy(); | ||
| 971 | |||
| 972 | foreach my $policy (@policyList) { | ||
| 973 | |||
| 974 | if ($policy eq 'GTK_POLICY_ALWAYS') { | ||
| 975 | $policy = 'always'; | ||
| 976 | } elsif ($policy eq 'GTK_POLICY_AUTOMATIC') { | ||
| 977 | $policy = 'automatic'; | ||
| 978 | } elsif ($policy eq 'GTK_POLICY_NEVER') { | ||
| 979 | $policy = 'never'; | ||
| 980 | } | ||
| 981 | } | ||
| 982 | |||
| 983 | return @policyList; | ||
| 984 | } | ||
| 985 | |||
| 986 | sub get_spacing { | ||
| 987 | |||
| 988 | # Returns integer | ||
| 989 | |||
| 990 | my ($self, $check) = @_; | ||
| 991 | |||
| 992 | # Check for improper arguments | ||
| 993 | if (defined $check) { | ||
| 994 | |||
| 995 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_spacing', @_); | ||
| 996 | } | ||
| 997 | |||
| 998 | if ($self->type ne 'horizontal' && $self->type ne 'vertical') { | ||
| 999 | |||
| 1000 | return undef; | ||
| 1001 | |||
| 1002 | } else { | ||
| 1003 | |||
| 1004 | return $self->packingBox2->get_spacing(); | ||
| 1005 | } | ||
| 1006 | } | ||
| 1007 | |||
| 1008 | sub get_widgets { | ||
| 1009 | |||
| 1010 | # Returns the list of widgets in the main container (may be an empty list) | ||
| 1011 | |||
| 1012 | my ($self, $check) = @_; | ||
| 1013 | |||
| 1014 | # Local variables | ||
| 1015 | my @emptyList; | ||
| 1016 | |||
| 1017 | # Check for improper arguments | ||
| 1018 | if (defined $check) { | ||
| 1019 | |||
| 1020 | $axmud::CLIENT->writeImproper($self->_objClass . '->get_widgets', @_); | ||
| 1021 | return @emptyList; | ||
| 1022 | } | ||
| 1023 | |||
| 1024 | return $self->packingBox2->get_children(); | ||
| 1025 | } | ||
| 1026 | |||
| 1027 | ################## | ||
| 1028 | # Accessors - get | ||
| 1029 | |||
| 1030 | sub type | ||
| 1031 | { $_[0]->{type} } | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | { package Games::Axmud::Table::MiniTable; | ||
| 1035 | |||
| 1036 | use strict; | ||
| 1037 | use warnings; | ||
| 1038 | # use diagnostics; | ||
| 1039 | |||
| 1040 | use Glib qw(TRUE FALSE); | ||
| 1041 | |||
| 1042 | our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud); | ||
| 1043 | |||
| 1044 | ################## | ||
| 1045 | # Constructors | ||
| 1046 | |||
| 1047 | sub new { | ||
| 1048 | |||
| 1049 | # Called by GA::Strip::Table->addTableObj | ||
| 1050 | # Creates the GA::Table::MiniTable, which creates a table within a table, to which other | ||
| 1051 | # widgets can be freely added | ||
| 1052 | # | ||
| 1053 | # Expected arguments | ||
| 1054 | # $number - The table object's number within the parent strip object (matches | ||
| 1055 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object | ||
| 1056 | # created to access its default IVs) | ||
| 1057 | # $name - A name for the table object. Can be any string or, if no name was | ||
| 1058 | # specified in the call to the calling function, $name is the same as | ||
| 1059 | # $number. (No part of the code checks that table object names are unique; | ||
| 1060 | # if two or more table objects share the same ->name, usually the one with | ||
| 1061 | # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16 | ||
| 1062 | # chars) | ||
| 1063 | # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table | ||
| 1064 | # objects | ||
| 1065 | # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the | ||
| 1066 | # parent strip object's Gtk3::Grid for use exclusively by this table | ||
| 1067 | # object. 'temp' for temporary table objects | ||
| 1068 | # | ||
| 1069 | # Optional arguments | ||
| 1070 | # %initHash - A hash containing arbitrary data to use as the table object's | ||
| 1071 | # initialisation settings. The table object should use default | ||
| 1072 | # initialisation settings unless it can succesfully interpret one or more | ||
| 1073 | # of the key-value pairs in the hash, if there are any | ||
| 1074 | # - This type of table object recognises these initialisation settings: | ||
| 1075 | # | ||
| 1076 | # 'column_equal_flag' - If TRUE, sets the table's homogeneity flag for | ||
| 1077 | # columns to TRUE; if FALSE, 'undef' or not specified, sets it to | ||
| 1078 | # FALSE | ||
| 1079 | # 'row_equal_flag' - If TRUE, sets the table's homogeneity flag for rows | ||
| 1080 | # to TRUE; if FALSE, 'undef' or not specified, sets it to FALSE | ||
| 1081 | # 'column_spacing' - Sets the horizontal spacing between table widgets, in | ||
| 1082 | # pixels (must be an integer, >= 0). If not specified or an invalid | ||
| 1083 | # value, a spacing of 0 is used | ||
| 1084 | # 'row_spacing' - Sets the vertical spacing between table widgets, in | ||
| 1085 | # pixels (must be an integer, >= 0). If not specified or an invalid | ||
| 1086 | # value, a spacing of 0 is used | ||
| 1087 | # 'expand_horizontal_flag' - If TRUE or not specified, the table object | ||
| 1088 | # expands horizontally; if FALSE, it doesn't | ||
| 1089 | # 'expand_vertical_flag' - If TRUE or not specified, the table object | ||
| 1090 | # expands vertically; if FALSE, it doesn't | ||
| 1091 | # | ||
| 1092 | # Return values | ||
| 1093 | # 'undef' on improper arguments | ||
| 1094 | # Blessed reference to the newly-created object on success | ||
| 1095 | |||
| 1096 | my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_; | ||
| 1097 | |||
| 1098 | # Local variables | ||
| 1099 | my ( | ||
| 1100 | $winObj, | ||
| 1101 | %modHash, | ||
| 1102 | ); | ||
| 1103 | |||
| 1104 | # Check for improper arguments | ||
| 1105 | if ( | ||
| 1106 | ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj | ||
| 1107 | || ! defined $zoneObj | ||
| 1108 | ) { | ||
| 1109 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 1110 | } | ||
| 1111 | |||
| 1112 | # Deal with temporary table objects | ||
| 1113 | if ($stripObj eq 'temp') { | ||
| 1114 | $winObj = 'temp'; | ||
| 1115 | } else { | ||
| 1116 | $winObj = $stripObj->winObj; | ||
| 1117 | } | ||
| 1118 | |||
| 1119 | # Default initialisation settings | ||
| 1120 | %modHash = ( | ||
| 1121 | 'column_equal_flag' => FALSE, | ||
| 1122 | 'row_equal_flag' => FALSE, | ||
| 1123 | 'column_spacing' => 0, | ||
| 1124 | 'row_spacing' => 0, | ||
| 1125 | 'expand_horizontal_flag' => TRUE, | ||
| 1126 | 'expand_vertical_flag' => TRUE, | ||
| 1127 | ); | ||
| 1128 | |||
| 1129 | # Interpret the initialisation settings in %initHash, if any | ||
| 1130 | foreach my $key (keys %modHash) { | ||
| 1131 | |||
| 1132 | if (exists $initHash{$key}) { | ||
| 1133 | |||
| 1134 | if ($key =~ m/flag$/) { | ||
| 1135 | |||
| 1136 | if ($initHash{$key}) { | ||
| 1137 | $modHash{$key} = TRUE; | ||
| 1138 | } else { | ||
| 1139 | $modHash{$key} = FALSE; | ||
| 1140 | } | ||
| 1141 | |||
| 1142 | } else { | ||
| 1143 | |||
| 1144 | $modHash{$key} = $initHash{$key}; | ||
| 1145 | } | ||
| 1146 | } | ||
| 1147 | } | ||
| 1148 | |||
| 1149 | # Setup | ||
| 1150 | my $self = { | ||
| 1151 | _objName => 'table_obj_' . $number, | ||
| 1152 | _objClass => $class, | ||
| 1153 | _parentFile => undef, # No parent file object | ||
| 1154 | _parentWorld => undef, # No parent file object | ||
| 1155 | _privFlag => TRUE, # All IVs are private | ||
| 1156 | |||
| 1157 | # Standard table object IVs | ||
| 1158 | # ------------------------- | ||
| 1159 | |||
| 1160 | # The table object's number within the parent strip object (matches | ||
| 1161 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to | ||
| 1162 | # access its default IVs) | ||
| 1163 | number => $number, | ||
| 1164 | # A name for the table object. Can be any string or, if no name was specified in the | ||
| 1165 | # call to the calling function, $name is the same as $number. (No part of the code | ||
| 1166 | # checks that table object names are unique; if two or more table objects share the | ||
| 1167 | # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary | ||
| 1168 | # table objects. Max 16 chars) | ||
| 1169 | name => $name, | ||
| 1170 | # The type of table object (custom table objects should use a ->type starting with | ||
| 1171 | # 'custom_' to avoid clashing with future built-in table objects) | ||
| 1172 | type => 'mini_table', | ||
| 1173 | # The parent strip object (GA::Strip::Table) | ||
| 1174 | stripObj => $stripObj, | ||
| 1175 | # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for | ||
| 1176 | # temporary table objects | ||
| 1177 | winObj => $winObj, | ||
| 1178 | # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip | ||
| 1179 | # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary | ||
| 1180 | # table objects | ||
| 1181 | zoneObj => $zoneObj, | ||
| 1182 | |||
| 1183 | # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is | ||
| 1184 | # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as | ||
| 1185 | # when a connection to a world terminates) | ||
| 1186 | allowRemoveFlag => TRUE, | ||
| 1187 | # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is | ||
| 1188 | # created. Set to FALSE if it can't be resized | ||
| 1189 | allowResizeFlag => TRUE, | ||
| 1190 | # Initialisation settings stored as a hash (see the comments above) | ||
| 1191 | initHash => \%modHash, | ||
| 1192 | # Reference to a function to call when some widget is used. This IV is set only when | ||
| 1193 | # required by this type of table object. It can be set by a call to | ||
| 1194 | # $self->set_func() or by some setting in $self->initHash, which is applied in the | ||
| 1195 | # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the | ||
| 1196 | # generic object function Games::Axmud->getMethodRef() | ||
| 1197 | funcRef => undef, | ||
| 1198 | # A value passed to ->funcRef when it is called which identifies this table object and | ||
| 1199 | # its widget(s). Can be any value, including 'undef'. It can be set by a call to | ||
| 1200 | # $self->set_id() or by some setting in $self->initHash, which is applied in the call | ||
| 1201 | # to $self->objEnable() | ||
| 1202 | funcID => '', | ||
| 1203 | |||
| 1204 | # The container widget(s) for this table object; both IVs are always set to the same | ||
| 1205 | # widget | ||
| 1206 | packingBox => undef, # Gtk3::Grid | ||
| 1207 | packingBox2 => undef, # Gtk3::Grid | ||
| 1208 | |||
| 1209 | # Other IVs | ||
| 1210 | # --------- | ||
| 1211 | |||
| 1212 | # (none) | ||
| 1213 | }; | ||
| 1214 | |||
| 1215 | # Bless the object into existence | ||
| 1216 | bless $self, $class; | ||
| 1217 | |||
| 1218 | return $self; | ||
| 1219 | } | ||
| 1220 | |||
| 1221 | ################## | ||
| 1222 | # Methods | ||
| 1223 | |||
| 1224 | # Standard table object functions | ||
| 1225 | |||
| 1226 | sub objEnable { | ||
| 1227 | |||
| 1228 | # Called by GA::Strip::Table->addTableObj | ||
| 1229 | # Sets up the table object's widgets | ||
| 1230 | # | ||
| 1231 | # Expected arguments | ||
| 1232 | # (none besides $self) | ||
| 1233 | # | ||
| 1234 | # Return values | ||
| 1235 | # 'undef' on improper arguments | ||
| 1236 | # 1 on success | ||
| 1237 | |||
| 1238 | my ($self, $check) = @_; | ||
| 1239 | |||
| 1240 | # Local variables | ||
| 1241 | my ($colEqualFlag, $rowEqualFlag, $colSpacing, $rowSpacing, $hExpandFlag, $vExpandFlag); | ||
| 1242 | |||
| 1243 | # Check for improper arguments | ||
| 1244 | if (defined $check) { | ||
| 1245 | |||
| 1246 | return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_); | ||
| 1247 | } | ||
| 1248 | |||
| 1249 | # Interpret $self->initHash, replacing any invalid values | ||
| 1250 | $colEqualFlag = $self->testFlag($self->ivShow('initHash', 'column_equal_flag')); | ||
| 1251 | $rowEqualFlag = $self->testFlag($self->ivShow('initHash', 'row_equal_flag')); | ||
| 1252 | $colSpacing = $self->testInt($self->ivShow('initHash', 'column_spacing'), 0, 0); | ||
| 1253 | $rowSpacing = $self->testInt($self->ivShow('initHash', 'row_spacing'), 0, 0); | ||
| 1254 | $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag')); | ||
| 1255 | $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag')); | ||
| 1256 | |||
| 1257 | # Create the packing box | ||
| 1258 | my ($packingBox, $packingBox2); | ||
| 1259 | $packingBox = $packingBox2 = Gtk3::Grid->new(); | ||
| 1260 | $packingBox2->set_column_homogeneous($colEqualFlag); | ||
| 1261 | $packingBox2->set_row_homogeneous($rowEqualFlag); | ||
| 1262 | $packingBox2->set_column_spacing($colSpacing); | ||
| 1263 | $packingBox2->set_row_spacing($rowSpacing); | ||
| 1264 | |||
| 1265 | # Set expansion | ||
| 1266 | $packingBox->set_hexpand($hExpandFlag); | ||
| 1267 | $packingBox->set_vexpand($vExpandFlag); | ||
| 1268 | |||
| 1269 | # Update IVs | ||
| 1270 | $self->ivPoke('packingBox', $packingBox); | ||
| 1271 | $self->ivPoke('packingBox2', $packingBox2); | ||
| 1272 | |||
| 1273 | return 1; | ||
| 1274 | } | ||
| 1275 | |||
| 1276 | # sub objDestroy { # Inherited from GA::Generic::Table | ||
| 1277 | |||
| 1278 | # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table | ||
| 1279 | |||
| 1280 | # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table | ||
| 1281 | |||
| 1282 | # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table | ||
| 1283 | |||
| 1284 | # ->signal_connects | ||
| 1285 | |||
| 1286 | # Other functions | ||
| 1287 | |||
| 1288 | sub pack { | ||
| 1289 | |||
| 1290 | # Can be called by anything to add a widget to the mini-table | ||
| 1291 | # Unlike GA::Strip::Table, this code doesn't perform any checks; the widget is added | ||
| 1292 | # regardless of any existing widgets that are already on the table | ||
| 1293 | # | ||
| 1294 | # Expected arguments | ||
| 1295 | # $widget - The Gtk3 widget to add to the main container widget | ||
| 1296 | # $left, Right, $top, $bottom | ||
| 1297 | # - The table coordinates to use | ||
| 1298 | # | ||
| 1299 | # Return values | ||
| 1300 | # 'undef' on improper arguments | ||
| 1301 | # 1 on success | ||
| 1302 | |||
| 1303 | my ($self, $widget, $left, $right, $top, $bottom, $check) = @_; | ||
| 1304 | |||
| 1305 | # Check for improper arguments | ||
| 1306 | if ( | ||
| 1307 | ! defined $widget || ! defined $left || ! defined $right || ! defined $top | ||
| 1308 | || ! defined $bottom || defined $check | ||
| 1309 | ) { | ||
| 1310 | return $axmud::CLIENT->writeImproper($self->_objClass . '->pack', @_); | ||
| 1311 | } | ||
| 1312 | |||
| 1313 | $self->packingBox2->attach($widget, $left, $right, $top, $bottom); | ||
| 1314 | |||
| 1315 | return 1; | ||
| 1316 | } | ||
| 1317 | |||
| 1318 | sub remove { | ||
| 1319 | |||
| 1320 | # Can be called by anything to remove a widget from the mini-table | ||
| 1321 | # | ||
| 1322 | # Expected arguments | ||
| 1323 | # $widget - The Gtk3 widget to remove from the mini-table | ||
| 1324 | # | ||
| 1325 | # Return values | ||
| 1326 | # 'undef' on improper arguments | ||
| 1327 | # 1 otherwise | ||
| 1328 | |||
| 1329 | my ($self, $widget, $check) = @_; | ||
| 1330 | |||
| 1331 | # Check for improper arguments | ||
| 1332 | if (! defined $widget || defined $check) { | ||
| 1333 | |||
| 1334 | return $axmud::CLIENT->writeImproper($self->_objClass . '->remove', @_); | ||
| 1335 | } | ||
| 1336 | |||
| 1337 | return $axmud::CLIENT->desktopObj->removeWidget($self->packingBox2, $widget); | ||
| 1338 | } | ||
| 1339 | |||
| 1340 | sub empty { | ||
| 1341 | |||
| 1342 | # Can be called by anything to remove all widgets from the mini-table | ||
| 1343 | # | ||
| 1344 | # Expected arguments | ||
| 1345 | # (none besides $self) | ||
| 1346 | # | ||
| 1347 | # Return values | ||
| 1348 | # 'undef' on improper arguments | ||
| 1349 | # 1 otherwise | ||
| 1350 | |||
| 1351 | my ($self, $check) = @_; | ||
| 1352 | |||
| 1353 | # Check for improper arguments | ||
| 1354 | if (defined $check) { | ||
| 1355 | |||
| 1356 | return $axmud::CLIENT->writeImproper($self->_objClass . '->empty', @_); | ||
| 1357 | } | ||
| 1358 | |||
| 1359 | foreach my $child ($self->packingBox2->get_children()) { | ||
| 1360 | |||
| 1361 | $self->packingBox2->remove($child); | ||
| 1362 | } | ||
| 1363 | |||
| 1364 | return 1; | ||
| 1365 | } | ||
| 1366 | |||
| 1367 | ################## | ||
| 1368 | # Accessors - set | ||
| 1369 | |||
| 1370 | sub set_equal { | ||
| 1371 | |||
| 1372 | my ($self, $colFlag, $rowFlag, $check) = @_; | ||
| 1373 | |||
| 1374 | # Check for improper arguments | ||
| 1375 | if (defined $check) { | ||
| 1376 | |||
| 1377 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_homo', @_); | ||
| 1378 | } | ||
| 1379 | |||
| 1380 | if ($self->type ne 'horizontal' && $self->type ne 'vertical') { | ||
| 1381 | |||
| 1382 | return undef; | ||
| 1383 | } | ||
| 1384 | |||
| 1385 | if (! $colFlag) { | ||
| 1386 | $self->packingBox2->set_column_homogeneous(FALSE); | ||
| 1387 | } else { | ||
| 1388 | $self->packingBox2->set_column_homogeneous(TRUE); | ||
| 1389 | } | ||
| 1390 | |||
| 1391 | if (! $rowFlag) { | ||
| 1392 | $self->packingBox2->set_row_homogeneous(FALSE); | ||
| 1393 | } else { | ||
| 1394 | $self->packingBox2->set_row_homogeneous(TRUE); | ||
| 1395 | } | ||
| 1396 | |||
| 1397 | return 1; | ||
| 1398 | } | ||
| 1399 | |||
| 1400 | sub set_spacing { | ||
| 1401 | |||
| 1402 | my ($self, $rowSpacing, $colSpacing, $check) = @_; | ||
| 1403 | |||
| 1404 | # Check for improper arguments | ||
| 1405 | if (! defined $rowSpacing || ! defined $colSpacing || defined $check) { | ||
| 1406 | |||
| 1407 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_spacing', @_); | ||
| 1408 | } | ||
| 1409 | |||
| 1410 | if ( | ||
| 1411 | ! $axmud::CLIENT->intCheck($rowSpacing, 0) | ||
| 1412 | || ! $axmud::CLIENT->intCheck($colSpacing, 0) | ||
| 1413 | ) { | ||
| 1414 | return undef; | ||
| 1415 | |||
| 1416 | } else { | ||
| 1417 | |||
| 1418 | $self->packingBox2->set_column_spacing($colSpacing); | ||
| 1419 | $self->packingBox2->set_row_spacing($rowSpacing); | ||
| 1420 | |||
| 1421 | return 1; | ||
| 1422 | } | ||
| 1423 | } | ||
| 1424 | |||
| 1425 | # (Get equivalents) | ||
| 1426 | |||
| 1427 | sub get_equal { | ||
| 1428 | |||
| 1429 | # Returns list in form (col_flag, row_flag) | ||
| 1430 | |||
| 1431 | my ($self, $check) = @_; | ||
| 1432 | |||
| 1433 | # Local variables | ||
| 1434 | my (@emptyList, @returnList); | ||
| 1435 | |||
| 1436 | # Check for improper arguments | ||
| 1437 | if (defined $check) { | ||
| 1438 | |||
| 1439 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_equal', @_); | ||
| 1440 | } | ||
| 1441 | |||
| 1442 | if ($self->type ne 'horizontal' && $self->type ne 'vertical') { | ||
| 1443 | |||
| 1444 | return @emptyList; | ||
| 1445 | } | ||
| 1446 | |||
| 1447 | if (! $self->packingBox2->get_column_homogeneous()) { | ||
| 1448 | push (@emptyList, FALSE); | ||
| 1449 | } else { | ||
| 1450 | push (@emptyList, TRUE); | ||
| 1451 | } | ||
| 1452 | |||
| 1453 | if (! $self->packingBox2->get_row_homogeneous()) { | ||
| 1454 | push (@returnList, FALSE); | ||
| 1455 | } else { | ||
| 1456 | push (@returnList, TRUE); | ||
| 1457 | } | ||
| 1458 | |||
| 1459 | return @returnList; | ||
| 1460 | } | ||
| 1461 | |||
| 1462 | sub get_spacing { | ||
| 1463 | |||
| 1464 | # Returns list in form (col_spacing, row_spacing) | ||
| 1465 | |||
| 1466 | my ($self, $check) = @_; | ||
| 1467 | |||
| 1468 | # Local variables | ||
| 1469 | my @emptyList; | ||
| 1470 | |||
| 1471 | # Check for improper arguments | ||
| 1472 | if (defined $check) { | ||
| 1473 | |||
| 1474 | $axmud::CLIENT->writeImproper($self->_objClass . '->get_spacing', @_); | ||
| 1475 | return @emptyList; | ||
| 1476 | } | ||
| 1477 | |||
| 1478 | return ( | ||
| 1479 | $self->packingBox2->get_default_row_spacing, | ||
| 1480 | $self->packingBox2->get_default_col_spacing, | ||
| 1481 | ); | ||
| 1482 | } | ||
| 1483 | |||
| 1484 | sub get_widgets { | ||
| 1485 | |||
| 1486 | # Returns the list of widgets in the mini-table (may be an empty list) | ||
| 1487 | |||
| 1488 | my ($self, $check) = @_; | ||
| 1489 | |||
| 1490 | # Local variables | ||
| 1491 | my @emptyList; | ||
| 1492 | |||
| 1493 | # Check for improper arguments | ||
| 1494 | if (defined $check) { | ||
| 1495 | |||
| 1496 | $axmud::CLIENT->writeImproper($self->_objClass . '->get_widgets', @_); | ||
| 1497 | return @emptyList; | ||
| 1498 | } | ||
| 1499 | |||
| 1500 | return $self->packingBox2->get_children(); | ||
| 1501 | } | ||
| 1502 | |||
| 1503 | ################## | ||
| 1504 | # Accessors - get | ||
| 1505 | } | ||
| 1506 | |||
| 1507 | # Simple table objects | ||
| 1508 | |||
| 1509 | { package Games::Axmud::Table::Label; | ||
| 1510 | |||
| 1511 | use strict; | ||
| 1512 | use warnings; | ||
| 1513 | # use diagnostics; | ||
| 1514 | |||
| 1515 | use Glib qw(TRUE FALSE); | ||
| 1516 | |||
| 1517 | our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud); | ||
| 1518 | |||
| 1519 | ################## | ||
| 1520 | # Constructors | ||
| 1521 | |||
| 1522 | sub new { | ||
| 1523 | |||
| 1524 | # Called by GA::Strip::Table->addTableObj | ||
| 1525 | # Creates the GA::Table::Label, which contains a simple Gtk3::Label | ||
| 1526 | # | ||
| 1527 | # Expected arguments | ||
| 1528 | # $number - The table object's number within the parent strip object (matches | ||
| 1529 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object | ||
| 1530 | # created to access its default IVs) | ||
| 1531 | # $name - A name for the table object. Can be any string or, if no name was | ||
| 1532 | # specified in the call to the calling function, $name is the same as | ||
| 1533 | # $number. (No part of the code checks that table object names are unique; | ||
| 1534 | # if two or more table objects share the same ->name, usually the one with | ||
| 1535 | # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16 | ||
| 1536 | # chars) | ||
| 1537 | # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table | ||
| 1538 | # objects | ||
| 1539 | # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the | ||
| 1540 | # parent strip object's Gtk3::Grid for use exclusively by this table | ||
| 1541 | # object. 'temp' for temporary table objects | ||
| 1542 | # | ||
| 1543 | # Optional arguments | ||
| 1544 | # %initHash - A hash containing arbitrary data to use as the table object's | ||
| 1545 | # initialisation settings. The table object should use default | ||
| 1546 | # initialisation settings unless it can succesfully interpret one or more | ||
| 1547 | # of the key-value pairs in the hash, if there are any | ||
| 1548 | # - This type of table object recognises these initialisation settings: | ||
| 1549 | # | ||
| 1550 | # 'text' - The text to display in the Gtk3::Label. Can be plain text or | ||
| 1551 | # pango markup text. If not specified, 'undef' or an empty string, an | ||
| 1552 | # empty string is used | ||
| 1553 | # 'justify' - The text's justification. If specified, should be 'left', | ||
| 1554 | # 'right', 'centre'/'center' or 'fill' (of a Gtk3::Justification like | ||
| 1555 | # 'GTK_JUSTIFY_LEFT'). If not specified, 'left' is used. Ignored if | ||
| 1556 | # 'text' is not specified | ||
| 1557 | # 'underline_flag' - If TRUE, text is underlined. If FALSE (or not | ||
| 1558 | # specified), text is not underlined. Ignored if 'text' is not | ||
| 1559 | # specified | ||
| 1560 | # 'tooltips' - The text to display as tooltips for the button. Can be | ||
| 1561 | # plain text or pango markup text. If not specified, 'undef' or an | ||
| 1562 | # empty string, no tooltips are displayed | ||
| 1563 | # 'align_x', 'align_y' - the Gtk3::Label's alignment, values in the range | ||
| 1564 | # 0-1. If not specified, 'align_x' is set to 0, 'align_y' is set to | ||
| 1565 | # 0.5. Ignored if 'text' is not specified | ||
| 1566 | # 'expand_horizontal_flag' - If TRUE or unspecified, the table object | ||
| 1567 | # expands horizontally; if FALSE, it doesn't. Note that typically, | ||
| 1568 | # alignment does not work unless expansion is enabled | ||
| 1569 | # 'expand_vertical_flag' - If TRUE or unspecified, the table object | ||
| 1570 | # expands vertically; if FALSE, it doesn't | ||
| 1571 | # | ||
| 1572 | # Return values | ||
| 1573 | # 'undef' on improper arguments | ||
| 1574 | # Blessed reference to the newly-created object on success | ||
| 1575 | |||
| 1576 | my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_; | ||
| 1577 | |||
| 1578 | # Local variables | ||
| 1579 | my ( | ||
| 1580 | $winObj, | ||
| 1581 | %modHash, | ||
| 1582 | ); | ||
| 1583 | |||
| 1584 | # Check for improper arguments | ||
| 1585 | if ( | ||
| 1586 | ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj | ||
| 1587 | || ! defined $zoneObj | ||
| 1588 | ) { | ||
| 1589 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 1590 | } | ||
| 1591 | |||
| 1592 | # Deal with temporary table objects | ||
| 1593 | if ($stripObj eq 'temp') { | ||
| 1594 | $winObj = 'temp'; | ||
| 1595 | } else { | ||
| 1596 | $winObj = $stripObj->winObj; | ||
| 1597 | } | ||
| 1598 | |||
| 1599 | # Default initialisation settings | ||
| 1600 | %modHash = ( | ||
| 1601 | 'text' => '', | ||
| 1602 | 'justify' => 'left', | ||
| 1603 | 'underline_flag' => TRUE, | ||
| 1604 | 'tooltips' => undef, | ||
| 1605 | 'align_x' => 0, | ||
| 1606 | 'align_y' => 0.5, | ||
| 1607 | 'expand_horizontal_flag' => TRUE, | ||
| 1608 | 'expand_vertical_flag' => TRUE, | ||
| 1609 | ); | ||
| 1610 | |||
| 1611 | # Interpret the initialisation settings in %initHash, if any | ||
| 1612 | foreach my $key (keys %modHash) { | ||
| 1613 | |||
| 1614 | if (exists $initHash{$key}) { | ||
| 1615 | |||
| 1616 | if ($key =~ m/flag$/) { | ||
| 1617 | |||
| 1618 | if ($initHash{$key}) { | ||
| 1619 | $modHash{$key} = TRUE; | ||
| 1620 | } else { | ||
| 1621 | $modHash{$key} = FALSE; | ||
| 1622 | } | ||
| 1623 | |||
| 1624 | } else { | ||
| 1625 | |||
| 1626 | $modHash{$key} = $initHash{$key}; | ||
| 1627 | } | ||
| 1628 | } | ||
| 1629 | } | ||
| 1630 | |||
| 1631 | # Setup | ||
| 1632 | my $self = { | ||
| 1633 | _objName => 'table_obj_' . $number, | ||
| 1634 | _objClass => $class, | ||
| 1635 | _parentFile => undef, # No parent file object | ||
| 1636 | _parentWorld => undef, # No parent file object | ||
| 1637 | _privFlag => TRUE, # All IVs are private | ||
| 1638 | |||
| 1639 | # Standard table object IVs | ||
| 1640 | # ------------------------- | ||
| 1641 | |||
| 1642 | # The table object's number within the parent strip object (matches | ||
| 1643 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to | ||
| 1644 | # access its default IVs) | ||
| 1645 | number => $number, | ||
| 1646 | # A name for the table object. Can be any string or, if no name was specified in the | ||
| 1647 | # call to the calling function, $name is the same as $number. (No part of the code | ||
| 1648 | # checks that table object names are unique; if two or more table objects share the | ||
| 1649 | # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary | ||
| 1650 | # table objects. Max 16 chars) | ||
| 1651 | name => $name, | ||
| 1652 | # The type of table object (custom table objects should use a ->type starting with | ||
| 1653 | # 'custom_' to avoid clashing with future built-in table objects) | ||
| 1654 | type => 'label', | ||
| 1655 | # The parent strip object (GA::Strip::Table) | ||
| 1656 | stripObj => $stripObj, | ||
| 1657 | # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for | ||
| 1658 | # temporary table objects | ||
| 1659 | winObj => $winObj, | ||
| 1660 | # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip | ||
| 1661 | # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary | ||
| 1662 | # table objects | ||
| 1663 | zoneObj => $zoneObj, | ||
| 1664 | |||
| 1665 | # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is | ||
| 1666 | # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as | ||
| 1667 | # when a connection to a world terminates) | ||
| 1668 | allowRemoveFlag => TRUE, | ||
| 1669 | # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is | ||
| 1670 | # created. Set to FALSE if it can't be resized | ||
| 1671 | allowResizeFlag => TRUE, | ||
| 1672 | # Initialisation settings stored as a hash (see the comments above) | ||
| 1673 | initHash => \%modHash, | ||
| 1674 | # Reference to a function to call when some widget is used. This IV is set only when | ||
| 1675 | # required by this type of table object. It can be set by a call to | ||
| 1676 | # $self->set_func() or by some setting in $self->initHash, which is applied in the | ||
| 1677 | # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the | ||
| 1678 | # generic object function Games::Axmud->getMethodRef() | ||
| 1679 | funcRef => undef, | ||
| 1680 | # A value passed to ->funcRef when it is called which identifies this table object and | ||
| 1681 | # its widget(s). Can be any value, including 'undef'. It can be set by a call to | ||
| 1682 | # $self->set_id() or by some setting in $self->initHash, which is applied in the call | ||
| 1683 | # to $self->objEnable() | ||
| 1684 | funcID => '', | ||
| 1685 | |||
| 1686 | # The container widget(s) for this table object | ||
| 1687 | packingBox => undef, # Gtk3::Grid | ||
| 1688 | packingBox2 => undef, # Gtk3::Grid | ||
| 1689 | |||
| 1690 | # Other IVs | ||
| 1691 | # --------- | ||
| 1692 | |||
| 1693 | # Widgets | ||
| 1694 | label => undef, # Gtk3::Label | ||
| 1695 | }; | ||
| 1696 | |||
| 1697 | # Bless the object into existence | ||
| 1698 | bless $self, $class; | ||
| 1699 | |||
| 1700 | return $self; | ||
| 1701 | } | ||
| 1702 | |||
| 1703 | ################## | ||
| 1704 | # Methods | ||
| 1705 | |||
| 1706 | # Standard table object functions | ||
| 1707 | |||
| 1708 | sub objEnable { | ||
| 1709 | |||
| 1710 | # Called by GA::Strip::Table->addTableObj | ||
| 1711 | # Sets up the table object's widgets | ||
| 1712 | # | ||
| 1713 | # Expected arguments | ||
| 1714 | # (none besides $self) | ||
| 1715 | # | ||
| 1716 | # Return values | ||
| 1717 | # 'undef' on improper arguments | ||
| 1718 | # 1 on success | ||
| 1719 | |||
| 1720 | my ($self, $check) = @_; | ||
| 1721 | |||
| 1722 | # Local variables | ||
| 1723 | my ( | ||
| 1724 | $text, $noTextFlag, $justify, $underlineFlag, $tooltips, $alignX, $alignY, $hExpandFlag, | ||
| 1725 | $vExpandFlag, | ||
| 1726 | ); | ||
| 1727 | |||
| 1728 | # Check for improper arguments | ||
| 1729 | if (defined $check) { | ||
| 1730 | |||
| 1731 | return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_); | ||
| 1732 | } | ||
| 1733 | |||
| 1734 | # Interpret $self->initHash, replacing any invalid values | ||
| 1735 | $text = $self->ivShow('initHash', 'text'); | ||
| 1736 | if (! defined $text) { | ||
| 1737 | |||
| 1738 | $text = ''; | ||
| 1739 | $noTextFlag = TRUE; | ||
| 1740 | } | ||
| 1741 | |||
| 1742 | $justify = $self->testJustify($self->ivShow('initHash', 'justify')); | ||
| 1743 | $underlineFlag = $self->testFlag($self->ivShow('initHash', 'underline_flag')); | ||
| 1744 | $tooltips = $self->ivShow('initHash', 'tooltips'); | ||
| 1745 | $alignX = $self->testAlign($self->ivShow('initHash', 'align_x'), 0); | ||
| 1746 | $alignY = $self->testAlign($self->ivShow('initHash', 'align_y'), 0.5); | ||
| 1747 | $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag')); | ||
| 1748 | $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag')); | ||
| 1749 | |||
| 1750 | # Create packing box(es) | ||
| 1751 | my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::Grid->new()); | ||
| 1752 | |||
| 1753 | # Create the Gtk3::Label | ||
| 1754 | my $label = Gtk3::Label->new(); | ||
| 1755 | $packingBox2->attach($label, 0, 0, 1, 1); | ||
| 1756 | $label->set_markup($self->ivShow('initHash', 'text')); | ||
| 1757 | |||
| 1758 | if (! $noTextFlag) { | ||
| 1759 | |||
| 1760 | $label->set_justify($justify); | ||
| 1761 | $label->set_use_underline($underlineFlag); | ||
| 1762 | $label->set_alignment($alignX, $alignY); | ||
| 1763 | } | ||
| 1764 | |||
| 1765 | if (defined $tooltips && $tooltips ne '') { | ||
| 1766 | |||
| 1767 | $label->set_tooltip_markup($tooltips); | ||
| 1768 | } | ||
| 1769 | |||
| 1770 | # Set expansion | ||
| 1771 | $label->set_hexpand($hExpandFlag); | ||
| 1772 | $label->set_vexpand($vExpandFlag); | ||
| 1773 | |||
| 1774 | # Update IVs | ||
| 1775 | $self->ivPoke('packingBox', $packingBox); | ||
| 1776 | $self->ivPoke('packingBox2', $packingBox2); | ||
| 1777 | $self->ivPoke('label', $label); | ||
| 1778 | |||
| 1779 | return 1; | ||
| 1780 | } | ||
| 1781 | |||
| 1782 | # sub objDestroy { # Inherited from GA::Generic::Table | ||
| 1783 | |||
| 1784 | # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table | ||
| 1785 | |||
| 1786 | # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table | ||
| 1787 | |||
| 1788 | # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table | ||
| 1789 | |||
| 1790 | # ->signal_connects | ||
| 1791 | |||
| 1792 | # Other functions | ||
| 1793 | |||
| 1794 | ################## | ||
| 1795 | # Accessors - set | ||
| 1796 | |||
| 1797 | sub set_align { | ||
| 1798 | |||
| 1799 | my ($self, $alignX, $alignY, $check) = @_; | ||
| 1800 | |||
| 1801 | # Check for improper arguments | ||
| 1802 | if (defined $check) { | ||
| 1803 | |||
| 1804 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_align', @_); | ||
| 1805 | } | ||
| 1806 | |||
| 1807 | $alignX = $self->testAlign($alignX, 0); | ||
| 1808 | $alignY = $self->testAlign($alignY, 0.5); | ||
| 1809 | |||
| 1810 | $self->label->set_alignment($alignX, $alignY); | ||
| 1811 | |||
| 1812 | return 1; | ||
| 1813 | } | ||
| 1814 | |||
| 1815 | sub set_justify { | ||
| 1816 | |||
| 1817 | my ($self, $justify, $check) = @_; | ||
| 1818 | |||
| 1819 | # Check for improper arguments | ||
| 1820 | if (defined $check) { | ||
| 1821 | |||
| 1822 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_justify', @_); | ||
| 1823 | } | ||
| 1824 | |||
| 1825 | $self->label->set_justify($self->testJustify($justify)); | ||
| 1826 | |||
| 1827 | return 1; | ||
| 1828 | } | ||
| 1829 | |||
| 1830 | sub set_text { | ||
| 1831 | |||
| 1832 | my ($self, $text, $check) = @_; | ||
| 1833 | |||
| 1834 | # Check for improper arguments | ||
| 1835 | if (defined $check) { | ||
| 1836 | |||
| 1837 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_text', @_); | ||
| 1838 | } | ||
| 1839 | |||
| 1840 | if (! defined $text) { | ||
| 1841 | |||
| 1842 | $text = ''; | ||
| 1843 | } | ||
| 1844 | |||
| 1845 | $self->label->set_markup($text); | ||
| 1846 | |||
| 1847 | return 1; | ||
| 1848 | } | ||
| 1849 | |||
| 1850 | sub set_tooltips { | ||
| 1851 | |||
| 1852 | my ($self, $tooltips, $check) = @_; | ||
| 1853 | |||
| 1854 | # Check for improper arguments | ||
| 1855 | if (defined $check) { | ||
| 1856 | |||
| 1857 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_tooltips', @_); | ||
| 1858 | } | ||
| 1859 | |||
| 1860 | if (! defined $tooltips || $tooltips eq '') { | ||
| 1861 | $self->label->set_tooltip_text(undef); | ||
| 1862 | } else { | ||
| 1863 | $self->label->set_tooltip_markup($tooltips); | ||
| 1864 | } | ||
| 1865 | |||
| 1866 | return 1; | ||
| 1867 | } | ||
| 1868 | |||
| 1869 | sub set_underline { | ||
| 1870 | |||
| 1871 | my ($self, $flag, $check) = @_; | ||
| 1872 | |||
| 1873 | # Check for improper arguments | ||
| 1874 | if (defined $check) { | ||
| 1875 | |||
| 1876 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_underline', @_); | ||
| 1877 | } | ||
| 1878 | |||
| 1879 | $self->label->set_use_underline($self->testFlag($flag)); | ||
| 1880 | |||
| 1881 | return 1; | ||
| 1882 | } | ||
| 1883 | |||
| 1884 | # (Get equivalents) | ||
| 1885 | |||
| 1886 | sub get_align { | ||
| 1887 | |||
| 1888 | # Returns list in form ($alignX, $alignY); | ||
| 1889 | |||
| 1890 | my ($self, $alignX, $alignY, $check) = @_; | ||
| 1891 | |||
| 1892 | # Check for improper arguments | ||
| 1893 | if (defined $check) { | ||
| 1894 | |||
| 1895 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_align', @_); | ||
| 1896 | } | ||
| 1897 | |||
| 1898 | return $self->label->get_alignment(); | ||
| 1899 | } | ||
| 1900 | |||
| 1901 | sub get_justify { | ||
| 1902 | |||
| 1903 | # Returns 'left', 'right', 'centre', 'fill' or 'other' | ||
| 1904 | |||
| 1905 | my ($self, $check) = @_; | ||
| 1906 | |||
| 1907 | # Local variables | ||
| 1908 | my $justify; | ||
| 1909 | |||
| 1910 | # Check for improper arguments | ||
| 1911 | if (defined $check) { | ||
| 1912 | |||
| 1913 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_justify', @_); | ||
| 1914 | } | ||
| 1915 | |||
| 1916 | $justify = $self->label->get_justify(); | ||
| 1917 | if ($justify eq 'GTK_JUSTIFY_LEFT') { | ||
| 1918 | return 'left'; | ||
| 1919 | } elsif ($justify eq 'GTK_JUSTIFY_RIGHT') { | ||
| 1920 | return 'right'; | ||
| 1921 | } elsif ($justify eq 'GTK_JUSTIFY_CENTER') { | ||
| 1922 | return 'centre'; | ||
| 1923 | } elsif ($justify eq 'GTK_JUSTIFY_FILL') { | ||
| 1924 | return 'fill'; | ||
| 1925 | } else { | ||
| 1926 | return 'other'; | ||
| 1927 | } | ||
| 1928 | } | ||
| 1929 | |||
| 1930 | sub get_text { | ||
| 1931 | |||
| 1932 | # Returns string | ||
| 1933 | my ($self, $check) = @_; | ||
| 1934 | |||
| 1935 | # Check for improper arguments | ||
| 1936 | if (defined $check) { | ||
| 1937 | |||
| 1938 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_text', @_); | ||
| 1939 | } | ||
| 1940 | |||
| 1941 | return $self->label->get_text(); | ||
| 1942 | } | ||
| 1943 | |||
| 1944 | sub get_tooltips { | ||
| 1945 | |||
| 1946 | # Returns string | ||
| 1947 | |||
| 1948 | my ($self, $check) = @_; | ||
| 1949 | |||
| 1950 | # Check for improper arguments | ||
| 1951 | if (defined $check) { | ||
| 1952 | |||
| 1953 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_tooltips', @_); | ||
| 1954 | } | ||
| 1955 | |||
| 1956 | return $self->label->get_tooltip_text(); | ||
| 1957 | } | ||
| 1958 | |||
| 1959 | sub get_underline { | ||
| 1960 | |||
| 1961 | # Returns TRUE or FALSE | ||
| 1962 | |||
| 1963 | my ($self, $check) = @_; | ||
| 1964 | |||
| 1965 | # Check for improper arguments | ||
| 1966 | if (defined $check) { | ||
| 1967 | |||
| 1968 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_underline', @_); | ||
| 1969 | } | ||
| 1970 | |||
| 1971 | if ($self->label->get_use_underline()) { | ||
| 1972 | return TRUE; | ||
| 1973 | } else { | ||
| 1974 | return FALSE; | ||
| 1975 | } | ||
| 1976 | } | ||
| 1977 | |||
| 1978 | ################## | ||
| 1979 | # Accessors - get | ||
| 1980 | |||
| 1981 | sub label | ||
| 1982 | { $_[0]->{label} } | ||
| 1983 | } | ||
| 1984 | |||
| 1985 | { package Games::Axmud::Table::Button; | ||
| 1986 | |||
| 1987 | use strict; | ||
| 1988 | use warnings; | ||
| 1989 | # use diagnostics; | ||
| 1990 | |||
| 1991 | use Glib qw(TRUE FALSE); | ||
| 1992 | |||
| 1993 | our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud); | ||
| 1994 | |||
| 1995 | ################## | ||
| 1996 | # Constructors | ||
| 1997 | |||
| 1998 | sub new { | ||
| 1999 | |||
| 2000 | # Called by GA::Strip::Table->addTableObj | ||
| 2001 | # Creates the GA::Table::Button, which contains a simple Gtk3::Button | ||
| 2002 | # | ||
| 2003 | # Expected arguments | ||
| 2004 | # $number - The table object's number within the parent strip object (matches | ||
| 2005 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object | ||
| 2006 | # created to access its default IVs) | ||
| 2007 | # $name - A name for the table object. Can be any string or, if no name was | ||
| 2008 | # specified in the call to the calling function, $name is the same as | ||
| 2009 | # $number. (No part of the code checks that table object names are unique; | ||
| 2010 | # if two or more table objects share the same ->name, usually the one with | ||
| 2011 | # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16 | ||
| 2012 | # chars) | ||
| 2013 | # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table | ||
| 2014 | # objects | ||
| 2015 | # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the | ||
| 2016 | # parent strip object's Gtk3::Grid for use exclusively by this table | ||
| 2017 | # object. 'temp' for temporary table objects | ||
| 2018 | # | ||
| 2019 | # Optional arguments | ||
| 2020 | # %initHash - A hash containing arbitrary data to use as the table object's | ||
| 2021 | # initialisation settings. The table object should use default | ||
| 2022 | # initialisation settings unless it can succesfully interpret one or more | ||
| 2023 | # of the key-value pairs in the hash, if there are any | ||
| 2024 | # - This type of table object recognises these initialisation settings: | ||
| 2025 | # | ||
| 2026 | # 'func' - Reference to a function to call when the button is clicked. If | ||
| 2027 | # not specified or 'undef', it's up to the calling code to create its | ||
| 2028 | # own ->signal_connect. To obtain a reference to an OOP method, you | ||
| 2029 | # can use the generic object function Games::Axmud->getMethodRef() | ||
| 2030 | # 'id' - A value passed to the function which identifies the button. If | ||
| 2031 | # specified, can be any value except 'undef'. It's up to the | ||
| 2032 | # calling code to keep track of the widgets it has created and their | ||
| 2033 | # corresponding 'id' values | ||
| 2034 | # 'text' - The text to display in the button. In Gtk, 'text' is | ||
| 2035 | # officially called a mnemonic, i.e. if any character is preceded by | ||
| 2036 | # an underline, that character is used as a keyboard accelerator | ||
| 2037 | # ('press' the button by pressing ALT + character). Must be plain | ||
| 2038 | # text, not pango markup. If not specified, 'undef' or an empty | ||
| 2039 | # string, no text is displayed | ||
| 2040 | # 'stock' - The stock Gtk3 icon and text to use on the button (e.g. | ||
| 2041 | # 'gtk-yes', 'gtk-save'. Ignored if 'text' is specified | ||
| 2042 | # 'image' - A Gtk3::Widget to display as an image on the button. Ignored | ||
| 2043 | # if 'text' or 'stock' are specified | ||
| 2044 | # 'underline_flag' - If TRUE, text is underlined. If FALSE (or not | ||
| 2045 | # specified), text is not underlined. Ignored if 'text' is not | ||
| 2046 | # specified | ||
| 2047 | # 'tooltips' - The text to display as tooltips for the button. Can be | ||
| 2048 | # plain text or pango markup text. If not specified, 'undef' or an | ||
| 2049 | # empty string, no tooltips are displayed | ||
| 2050 | # 'align_x', 'align_y' - The Gtk3::Button's alignment, values in the | ||
| 2051 | # range 0-1. If not specified, 'align_x' and/or 'align_y' are set to | ||
| 2052 | # 0.5. Ignored if 'text' is not specified | ||
| 2053 | # 'normal_flag' - If TRUE (or not specified), the button's state is | ||
| 2054 | # 'normal'. If FALSE, the button's state is 'insensitive' (nothing can | ||
| 2055 | # interact with it) | ||
| 2056 | # 'expand_horizontal_flag' - If TRUE or unspecified, the table object | ||
| 2057 | # expands horizontally; if FALSE, it doesn't. Note that typically, | ||
| 2058 | # alignment does not work unless expansion is enabled | ||
| 2059 | # 'expand_vertical_flag' - If TRUE or unspecified, the table object | ||
| 2060 | # expands vertically; if FALSE, it doesn't | ||
| 2061 | # 'expand_flag' - Deprecated since v1.2.170; ignored if specified | ||
| 2062 | # | ||
| 2063 | # Return values | ||
| 2064 | # 'undef' on improper arguments | ||
| 2065 | # Blessed reference to the newly-created object on success | ||
| 2066 | |||
| 2067 | my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_; | ||
| 2068 | |||
| 2069 | # Local variables | ||
| 2070 | my ( | ||
| 2071 | $winObj, | ||
| 2072 | %modHash, | ||
| 2073 | ); | ||
| 2074 | |||
| 2075 | # Check for improper arguments | ||
| 2076 | if ( | ||
| 2077 | ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj | ||
| 2078 | || ! defined $zoneObj | ||
| 2079 | ) { | ||
| 2080 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 2081 | } | ||
| 2082 | |||
| 2083 | # Deal with temporary table objects | ||
| 2084 | if ($stripObj eq 'temp') { | ||
| 2085 | $winObj = 'temp'; | ||
| 2086 | } else { | ||
| 2087 | $winObj = $stripObj->winObj; | ||
| 2088 | } | ||
| 2089 | |||
| 2090 | # Default initialisation settings | ||
| 2091 | %modHash = ( | ||
| 2092 | 'func' => undef, | ||
| 2093 | 'id' => '', | ||
| 2094 | 'text' => '', | ||
| 2095 | 'stock' => undef, | ||
| 2096 | 'image' => undef, | ||
| 2097 | 'underline_flag' => FALSE, | ||
| 2098 | 'tooltips' => undef, | ||
| 2099 | 'align_x' => 0.5, | ||
| 2100 | 'align_y' => 0.5, | ||
| 2101 | 'normal_flag' => TRUE, | ||
| 2102 | 'expand_horizontal_flag' => TRUE, | ||
| 2103 | 'expand_vertical_flag' => TRUE, | ||
| 2104 | 'expand_flag' => FALSE, # Deprecated since v1.2.170 | ||
| 2105 | ); | ||
| 2106 | |||
| 2107 | # Interpret the initialisation settings in %initHash, if any | ||
| 2108 | foreach my $key (keys %modHash) { | ||
| 2109 | |||
| 2110 | if (exists $initHash{$key}) { | ||
| 2111 | |||
| 2112 | if ($key =~ m/flag$/) { | ||
| 2113 | |||
| 2114 | if ($initHash{$key}) { | ||
| 2115 | $modHash{$key} = TRUE; | ||
| 2116 | } else { | ||
| 2117 | $modHash{$key} = FALSE; | ||
| 2118 | } | ||
| 2119 | |||
| 2120 | } elsif ($key eq 'id' && ! defined $initHash{$key}) { | ||
| 2121 | |||
| 2122 | $modHash{$key} = ''; # 'id' value must not be 'undef' | ||
| 2123 | |||
| 2124 | } else { | ||
| 2125 | |||
| 2126 | $modHash{$key} = $initHash{$key}; | ||
| 2127 | } | ||
| 2128 | } | ||
| 2129 | } | ||
| 2130 | |||
| 2131 | # Setup | ||
| 2132 | my $self = { | ||
| 2133 | _objName => 'table_obj_' . $number, | ||
| 2134 | _objClass => $class, | ||
| 2135 | _parentFile => undef, # No parent file object | ||
| 2136 | _parentWorld => undef, # No parent file object | ||
| 2137 | _privFlag => TRUE, # All IVs are private | ||
| 2138 | |||
| 2139 | # Standard table object IVs | ||
| 2140 | # ------------------------- | ||
| 2141 | |||
| 2142 | # The table object's number within the parent strip object (matches | ||
| 2143 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to | ||
| 2144 | # access its default IVs) | ||
| 2145 | number => $number, | ||
| 2146 | # A name for the table object. Can be any string or, if no name was specified in the | ||
| 2147 | # call to the calling function, $name is the same as $number. (No part of the code | ||
| 2148 | # checks that table object names are unique; if two or more table objects share the | ||
| 2149 | # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary | ||
| 2150 | # table objects. Max 16 chars) | ||
| 2151 | name => $name, | ||
| 2152 | # The type of table object (custom table objects should use a ->type starting with | ||
| 2153 | # 'custom_' to avoid clashing with future built-in table objects) | ||
| 2154 | type => 'button', | ||
| 2155 | # The parent strip object (GA::Strip::Table) | ||
| 2156 | stripObj => $stripObj, | ||
| 2157 | # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for | ||
| 2158 | # temporary table objects | ||
| 2159 | winObj => $winObj, | ||
| 2160 | # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip | ||
| 2161 | # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary | ||
| 2162 | # table objects | ||
| 2163 | zoneObj => $zoneObj, | ||
| 2164 | |||
| 2165 | # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is | ||
| 2166 | # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as | ||
| 2167 | # when a connection to a world terminates) | ||
| 2168 | allowRemoveFlag => TRUE, | ||
| 2169 | # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is | ||
| 2170 | # created. Set to FALSE if it can't be resized | ||
| 2171 | allowResizeFlag => TRUE, | ||
| 2172 | # Initialisation settings stored as a hash (see the comments above) | ||
| 2173 | initHash => \%modHash, | ||
| 2174 | # Reference to a function to call when some widget is used. This IV is set only when | ||
| 2175 | # required by this type of table object. It can be set by a call to | ||
| 2176 | # $self->set_func() or by some setting in $self->initHash, which is applied in the | ||
| 2177 | # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the | ||
| 2178 | # generic object function Games::Axmud->getMethodRef() | ||
| 2179 | funcRef => undef, | ||
| 2180 | # A value passed to ->funcRef when it is called which identifies this table object and | ||
| 2181 | # its widget(s). Can be any value except 'undef'. It can be set by a call to | ||
| 2182 | # $self->set_id() or by some setting in $self->initHash, which is applied in the call | ||
| 2183 | # to $self->objEnable() | ||
| 2184 | funcID => '', | ||
| 2185 | |||
| 2186 | # The container widget(s) for this table object | ||
| 2187 | packingBox => undef, # Gtk3::Grid | ||
| 2188 | packingBox2 => undef, # Gtk3::Grid | ||
| 2189 | |||
| 2190 | |||
| 2191 | # Other IVs | ||
| 2192 | # --------- | ||
| 2193 | |||
| 2194 | # Widgets | ||
| 2195 | button => undef, # Gtk3::Button | ||
| 2196 | }; | ||
| 2197 | |||
| 2198 | # Bless the object into existence | ||
| 2199 | bless $self, $class; | ||
| 2200 | |||
| 2201 | return $self; | ||
| 2202 | } | ||
| 2203 | |||
| 2204 | ################## | ||
| 2205 | # Methods | ||
| 2206 | |||
| 2207 | # Standard table object functions | ||
| 2208 | |||
| 2209 | sub objEnable { | ||
| 2210 | |||
| 2211 | # Called by GA::Strip::Table->addTableObj | ||
| 2212 | # Sets up the table object's widgets | ||
| 2213 | # | ||
| 2214 | # Expected arguments | ||
| 2215 | # (none besides $self) | ||
| 2216 | # | ||
| 2217 | # Return values | ||
| 2218 | # 'undef' on improper arguments | ||
| 2219 | # 1 on success | ||
| 2220 | |||
| 2221 | my ($self, $check) = @_; | ||
| 2222 | |||
| 2223 | # Local variables | ||
| 2224 | my ( | ||
| 2225 | $funcRef, $funcID, $text, $stock, $image, $underlineFlag, $tooltips, $alignX, $alignY, | ||
| 2226 | $normalFlag, $hExpandFlag, $vExpandFlag, | ||
| 2227 | ); | ||
| 2228 | |||
| 2229 | # Check for improper arguments | ||
| 2230 | if (defined $check) { | ||
| 2231 | |||
| 2232 | return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_); | ||
| 2233 | } | ||
| 2234 | |||
| 2235 | # Interpret $self->initHash, replacing any invalid values | ||
| 2236 | $funcRef = $self->ivShow('initHash', 'func'); | ||
| 2237 | $funcID = $self->ivShow('initHash', 'id'); | ||
| 2238 | $text = $self->ivShow('initHash', 'text'); | ||
| 2239 | $stock = $self->testStock($self->ivShow('initHash', 'stock')); | ||
| 2240 | $image = $self->ivShow('initHash', 'image'); | ||
| 2241 | $underlineFlag = $self->testFlag($self->ivShow('initHash', 'underline_flag')); | ||
| 2242 | $tooltips = $self->ivShow('initHash', 'tooltips'); | ||
| 2243 | $alignX = $self->testAlign($self->ivShow('initHash', 'align_x'), 0.5); | ||
| 2244 | $alignY = $self->testAlign($self->ivShow('initHash', 'align_y'), 0.5); | ||
| 2245 | $normalFlag = $self->testFlag($self->ivShow('initHash', 'normal_flag')); | ||
| 2246 | $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag')); | ||
| 2247 | $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag')); | ||
| 2248 | |||
| 2249 | # Create packing box(es) | ||
| 2250 | my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::Grid->new()); | ||
| 2251 | |||
| 2252 | # Create the Gtk3::Button | ||
| 2253 | my $button; | ||
| 2254 | if (defined $text && $text ne '') { | ||
| 2255 | $button = Gtk3::Button->new($text); | ||
| 2256 | } elsif ($stock) { | ||
| 2257 | $button = Gtk3::Button->new_from_stock($stock); | ||
| 2258 | } else { | ||
| 2259 | $button = Gtk3::Button->new(); | ||
| 2260 | } | ||
| 2261 | |||
| 2262 | $packingBox2->attach($button, 0, 0, 1, 1); | ||
| 2263 | |||
| 2264 | if (defined $text && $text ne '') { | ||
| 2265 | |||
| 2266 | $button->set_use_underline($underlineFlag); | ||
| 2267 | $button->set_alignment($alignX, $alignY); | ||
| 2268 | |||
| 2269 | } elsif (! $stock && $image) { | ||
| 2270 | |||
| 2271 | $button->set_image($image); | ||
| 2272 | } | ||
| 2273 | |||
| 2274 | if (defined $tooltips && $tooltips ne '') { | ||
| 2275 | |||
| 2276 | $button->set_tooltip_markup($tooltips); | ||
| 2277 | } | ||
| 2278 | |||
| 2279 | if (! $normalFlag) { | ||
| 2280 | |||
| 2281 | $button->set_state('insensitive'); | ||
| 2282 | } | ||
| 2283 | |||
| 2284 | # Set expansion | ||
| 2285 | $button->set_hexpand($hExpandFlag); | ||
| 2286 | $button->set_vexpand($vExpandFlag); | ||
| 2287 | |||
| 2288 | # Update IVs | ||
| 2289 | $self->ivPoke('funcRef', $funcRef); | ||
| 2290 | $self->ivPoke('funcID', $funcID); | ||
| 2291 | $self->ivPoke('packingBox', $packingBox); | ||
| 2292 | $self->ivPoke('packingBox2', $packingBox2); | ||
| 2293 | $self->ivPoke('button', $button); | ||
| 2294 | |||
| 2295 | # Set up ->signal_connects | ||
| 2296 | $self->setClickedEvent(); | ||
| 2297 | |||
| 2298 | return 1; | ||
| 2299 | } | ||
| 2300 | |||
| 2301 | # sub objDestroy { # Inherited from GA::Generic::Table | ||
| 2302 | |||
| 2303 | # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table | ||
| 2304 | |||
| 2305 | # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table | ||
| 2306 | |||
| 2307 | # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table | ||
| 2308 | |||
| 2309 | # ->signal_connects | ||
| 2310 | |||
| 2311 | sub setClickedEvent { | ||
| 2312 | |||
| 2313 | # Called by $self->objEnable | ||
| 2314 | # | ||
| 2315 | # Expected arguments | ||
| 2316 | # (none besides $self) | ||
| 2317 | # | ||
| 2318 | # Return values | ||
| 2319 | # 'undef' on improper arguments | ||
| 2320 | # 1 otherwise | ||
| 2321 | |||
| 2322 | my ($self, $check) = @_; | ||
| 2323 | |||
| 2324 | # Check for improper arguments | ||
| 2325 | if (defined $check) { | ||
| 2326 | |||
| 2327 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setClickedEvent', @_); | ||
| 2328 | } | ||
| 2329 | |||
| 2330 | $self->button->signal_connect('clicked' => sub { | ||
| 2331 | |||
| 2332 | my $currentFuncRef = $self->funcRef; | ||
| 2333 | |||
| 2334 | if ($currentFuncRef) { | ||
| 2335 | |||
| 2336 | &$currentFuncRef($self, $self->button, $self->funcID); | ||
| 2337 | } | ||
| 2338 | }); | ||
| 2339 | |||
| 2340 | return 1; | ||
| 2341 | } | ||
| 2342 | |||
| 2343 | # Other functions | ||
| 2344 | |||
| 2345 | ################## | ||
| 2346 | # Accessors - set | ||
| 2347 | |||
| 2348 | sub set_align { | ||
| 2349 | |||
| 2350 | my ($self, $alignX, $alignY, $check) = @_; | ||
| 2351 | |||
| 2352 | # Check for improper arguments | ||
| 2353 | if (defined $check) { | ||
| 2354 | |||
| 2355 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_align', @_); | ||
| 2356 | } | ||
| 2357 | |||
| 2358 | $alignX = $self->testAlign($alignX, 0); | ||
| 2359 | $alignY = $self->testAlign($alignY, 0.5); | ||
| 2360 | |||
| 2361 | $self->button->set_alignment($alignX, $alignY); | ||
| 2362 | |||
| 2363 | return 1; | ||
| 2364 | } | ||
| 2365 | |||
| 2366 | # sub set_func {} # Inherited from GA::Generic::Table | ||
| 2367 | |||
| 2368 | # sub set_id {} # Inherited from GA::Generic::Table | ||
| 2369 | |||
| 2370 | sub set_normal { | ||
| 2371 | |||
| 2372 | my ($self, $flag, $check) = @_; | ||
| 2373 | |||
| 2374 | # Check for improper arguments | ||
| 2375 | if (defined $check) { | ||
| 2376 | |||
| 2377 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_normal', @_); | ||
| 2378 | } | ||
| 2379 | |||
| 2380 | if (! $flag) { | ||
| 2381 | $self->button->set_sensitive(FALSE); | ||
| 2382 | } else { | ||
| 2383 | $self->button->set_sensitive(TRUE); | ||
| 2384 | } | ||
| 2385 | |||
| 2386 | return 1; | ||
| 2387 | } | ||
| 2388 | |||
| 2389 | sub set_text { | ||
| 2390 | |||
| 2391 | my ($self, $text, $check) = @_; | ||
| 2392 | |||
| 2393 | # Check for improper arguments | ||
| 2394 | if (defined $check) { | ||
| 2395 | |||
| 2396 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_text', @_); | ||
| 2397 | } | ||
| 2398 | |||
| 2399 | if (! defined $text) { | ||
| 2400 | |||
| 2401 | $text = ''; | ||
| 2402 | } | ||
| 2403 | |||
| 2404 | $self->button->set_label($text); | ||
| 2405 | |||
| 2406 | return 1; | ||
| 2407 | } | ||
| 2408 | |||
| 2409 | sub set_tooltips { | ||
| 2410 | |||
| 2411 | my ($self, $tooltips, $check) = @_; | ||
| 2412 | |||
| 2413 | # Check for improper arguments | ||
| 2414 | if (defined $check) { | ||
| 2415 | |||
| 2416 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_tooltips', @_); | ||
| 2417 | } | ||
| 2418 | |||
| 2419 | if (! defined $tooltips || $tooltips eq '') { | ||
| 2420 | $self->button->set_tooltip_text(undef); | ||
| 2421 | } else { | ||
| 2422 | $self->button->set_tooltip_markup($tooltips); | ||
| 2423 | } | ||
| 2424 | |||
| 2425 | return 1; | ||
| 2426 | } | ||
| 2427 | |||
| 2428 | sub set_underline { | ||
| 2429 | |||
| 2430 | my ($self, $flag, $check) = @_; | ||
| 2431 | |||
| 2432 | # Check for improper arguments | ||
| 2433 | if (defined $check) { | ||
| 2434 | |||
| 2435 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_underline', @_); | ||
| 2436 | } | ||
| 2437 | |||
| 2438 | $self->button->set_use_underline($self->testFlag($flag)); | ||
| 2439 | |||
| 2440 | return 1; | ||
| 2441 | } | ||
| 2442 | |||
| 2443 | # (Get equivalents) | ||
| 2444 | |||
| 2445 | sub get_align { | ||
| 2446 | |||
| 2447 | # Returns list in form ($alignX, $alignY); | ||
| 2448 | |||
| 2449 | my ($self, $alignX, $alignY, $check) = @_; | ||
| 2450 | |||
| 2451 | # Check for improper arguments | ||
| 2452 | if (defined $check) { | ||
| 2453 | |||
| 2454 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_align', @_); | ||
| 2455 | } | ||
| 2456 | |||
| 2457 | return $self->button->get_alignment(); | ||
| 2458 | } | ||
| 2459 | |||
| 2460 | sub get_normal { | ||
| 2461 | |||
| 2462 | # Returns TRUE for 'normal', FALSE for 'insensitive' or any other value | ||
| 2463 | |||
| 2464 | my ($self, $check) = @_; | ||
| 2465 | |||
| 2466 | # Check for improper arguments | ||
| 2467 | if (defined $check) { | ||
| 2468 | |||
| 2469 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_normal', @_); | ||
| 2470 | } | ||
| 2471 | |||
| 2472 | if ($self->button->get_sensitive()) { | ||
| 2473 | return TRUE; | ||
| 2474 | } else { | ||
| 2475 | return FALSE; | ||
| 2476 | } | ||
| 2477 | |||
| 2478 | return 1; | ||
| 2479 | } | ||
| 2480 | |||
| 2481 | sub get_text { | ||
| 2482 | |||
| 2483 | # Returns string | ||
| 2484 | my ($self, $check) = @_; | ||
| 2485 | |||
| 2486 | # Check for improper arguments | ||
| 2487 | if (defined $check) { | ||
| 2488 | |||
| 2489 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_text', @_); | ||
| 2490 | } | ||
| 2491 | |||
| 2492 | return $self->button->get_label(); | ||
| 2493 | } | ||
| 2494 | |||
| 2495 | sub get_tooltips { | ||
| 2496 | |||
| 2497 | # Returns string | ||
| 2498 | |||
| 2499 | my ($self, $check) = @_; | ||
| 2500 | |||
| 2501 | # Check for improper arguments | ||
| 2502 | if (defined $check) { | ||
| 2503 | |||
| 2504 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_tooltips', @_); | ||
| 2505 | } | ||
| 2506 | |||
| 2507 | return $self->button->get_tooltip_text(); | ||
| 2508 | } | ||
| 2509 | |||
| 2510 | sub get_underline { | ||
| 2511 | |||
| 2512 | # Returns TRUE or FALSE | ||
| 2513 | |||
| 2514 | my ($self, $check) = @_; | ||
| 2515 | |||
| 2516 | # Check for improper arguments | ||
| 2517 | if (defined $check) { | ||
| 2518 | |||
| 2519 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_underline', @_); | ||
| 2520 | } | ||
| 2521 | |||
| 2522 | if ($self->button->get_use_underline()) { | ||
| 2523 | return TRUE; | ||
| 2524 | } else { | ||
| 2525 | return FALSE; | ||
| 2526 | } | ||
| 2527 | } | ||
| 2528 | |||
| 2529 | ################## | ||
| 2530 | # Accessors - get | ||
| 2531 | |||
| 2532 | sub button | ||
| 2533 | { $_[0]->{button} } | ||
| 2534 | } | ||
| 2535 | |||
| 2536 | { package Games::Axmud::Table::CheckButton; | ||
| 2537 | |||
| 2538 | use strict; | ||
| 2539 | use warnings; | ||
| 2540 | # use diagnostics; | ||
| 2541 | |||
| 2542 | use Glib qw(TRUE FALSE); | ||
| 2543 | |||
| 2544 | our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud); | ||
| 2545 | |||
| 2546 | ################## | ||
| 2547 | # Constructors | ||
| 2548 | |||
| 2549 | sub new { | ||
| 2550 | |||
| 2551 | # Called by GA::Strip::Table->addTableObj | ||
| 2552 | # Creates the GA::Table::CheckButton, which contains a simple Gtk3::CheckButton | ||
| 2553 | # | ||
| 2554 | # Expected arguments | ||
| 2555 | # $number - The table object's number within the parent strip object (matches | ||
| 2556 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object | ||
| 2557 | # created to access its default IVs) | ||
| 2558 | # $name - A name for the table object. Can be any string or, if no name was | ||
| 2559 | # specified in the call to the calling function, $name is the same as | ||
| 2560 | # $number. (No part of the code checks that table object names are unique; | ||
| 2561 | # if two or more table objects share the same ->name, usually the one with | ||
| 2562 | # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16 | ||
| 2563 | # chars) | ||
| 2564 | # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table | ||
| 2565 | # objects | ||
| 2566 | # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the | ||
| 2567 | # parent strip object's Gtk3::Grid for use exclusively by this table | ||
| 2568 | # object. 'temp' for temporary table objects | ||
| 2569 | # | ||
| 2570 | # Optional arguments | ||
| 2571 | # %initHash - A hash containing arbitrary data to use as the table object's | ||
| 2572 | # initialisation settings. The table object should use default | ||
| 2573 | # initialisation settings unless it can succesfully interpret one or more | ||
| 2574 | # of the key-value pairs in the hash, if there are any | ||
| 2575 | # - This type of table object recognises these initialisation settings: | ||
| 2576 | # | ||
| 2577 | # 'func' - Reference to a function to call when the button is clicked. If | ||
| 2578 | # not specified or 'undef', it's up to the calling code to create its | ||
| 2579 | # own ->signal_connect. To obtain a reference to an OOP method, you | ||
| 2580 | # can use the generic object function Games::Axmud->getMethodRef() | ||
| 2581 | # 'id' - A value passed to the function which identifies the button. If | ||
| 2582 | # specified, can be any value except 'undef'. It's up to the | ||
| 2583 | # calling code to keep track of the widgets it has created and their | ||
| 2584 | # corresponding 'id' values | ||
| 2585 | # 'text' - The text to display as a label next to the button. In In Gtk, | ||
| 2586 | # 'text' is officially called a mnemonic, i.e. if any character is | ||
| 2587 | # preceded by an underline, that character is used as a keyboard | ||
| 2588 | # accelerator ('press' the button by pressing ALT + character). Must | ||
| 2589 | # be plain text, not pango markup. If not specified, 'undef' or an | ||
| 2590 | # empty string, no text is displayed | ||
| 2591 | # 'tooltips' - The text to display as tooltips for the button. Can be | ||
| 2592 | # plain text or pango markup text. If not specified, 'undef' or an | ||
| 2593 | # empty string, no tooltips are displayed | ||
| 2594 | # 'align_x', 'align_y' - The Gtk3::Button's alignment, values in the | ||
| 2595 | # range 0-1. If not specified, 'align_x' is set to 0, 'align_y' is set | ||
| 2596 | # to 0.5. Ignored if 'text' is not specified | ||
| 2597 | # 'select_flag' - If TRUE, the button is selected (checked) initially, if | ||
| 2598 | # FALSE (or not specified), it is not checked initially | ||
| 2599 | # 'normal_flag' - If TRUE (or not specified), the button's state is | ||
| 2600 | # 'normal'. If FALSE, the button's state is 'insensitive' (nothing can | ||
| 2601 | # interact with it) | ||
| 2602 | # 'expand_horizontal_flag' - If TRUE or unspecified, the table object | ||
| 2603 | # expands horizontally; if FALSE, it doesn't. Note that typically, | ||
| 2604 | # alignment does not work unless expansion is enabled | ||
| 2605 | # 'expand_vertical_flag' - If TRUE or unspecified, the table object | ||
| 2606 | # expands vertically; if FALSE, it doesn't | ||
| 2607 | # | ||
| 2608 | # Return values | ||
| 2609 | # 'undef' on improper arguments | ||
| 2610 | # Blessed reference to the newly-created object on success | ||
| 2611 | |||
| 2612 | my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_; | ||
| 2613 | |||
| 2614 | # Local variables | ||
| 2615 | my ( | ||
| 2616 | $winObj, | ||
| 2617 | %modHash, | ||
| 2618 | ); | ||
| 2619 | |||
| 2620 | # Check for improper arguments | ||
| 2621 | if ( | ||
| 2622 | ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj | ||
| 2623 | || ! defined $zoneObj | ||
| 2624 | ) { | ||
| 2625 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 2626 | } | ||
| 2627 | |||
| 2628 | # Deal with temporary table objects | ||
| 2629 | if ($stripObj eq 'temp') { | ||
| 2630 | $winObj = 'temp'; | ||
| 2631 | } else { | ||
| 2632 | $winObj = $stripObj->winObj; | ||
| 2633 | } | ||
| 2634 | |||
| 2635 | # Default initialisation settings | ||
| 2636 | %modHash = ( | ||
| 2637 | 'func' => undef, | ||
| 2638 | 'id' => '', | ||
| 2639 | 'text' => undef, | ||
| 2640 | 'tooltips' => undef, | ||
| 2641 | 'align_x' => 0, | ||
| 2642 | 'align_y' => 0.5, | ||
| 2643 | 'select_flag' => FALSE, | ||
| 2644 | 'normal_flag' => TRUE, | ||
| 2645 | 'expand_horizontal_flag' => TRUE, | ||
| 2646 | 'expand_vertical_flag' => TRUE, | ||
| 2647 | ); | ||
| 2648 | |||
| 2649 | # Interpret the initialisation settings in %initHash, if any | ||
| 2650 | foreach my $key (keys %modHash) { | ||
| 2651 | |||
| 2652 | if (exists $initHash{$key}) { | ||
| 2653 | |||
| 2654 | if ($key =~ m/flag$/) { | ||
| 2655 | |||
| 2656 | if ($initHash{$key}) { | ||
| 2657 | $modHash{$key} = TRUE; | ||
| 2658 | } else { | ||
| 2659 | $modHash{$key} = FALSE; | ||
| 2660 | } | ||
| 2661 | |||
| 2662 | } elsif ($key eq 'id' && ! defined $initHash{$key}) { | ||
| 2663 | |||
| 2664 | $modHash{$key} = ''; # 'id' value must not be 'undef' | ||
| 2665 | |||
| 2666 | } else { | ||
| 2667 | |||
| 2668 | $modHash{$key} = $initHash{$key}; | ||
| 2669 | } | ||
| 2670 | } | ||
| 2671 | } | ||
| 2672 | |||
| 2673 | # Setup | ||
| 2674 | my $self = { | ||
| 2675 | _objName => 'table_obj_' . $number, | ||
| 2676 | _objClass => $class, | ||
| 2677 | _parentFile => undef, # No parent file object | ||
| 2678 | _parentWorld => undef, # No parent file object | ||
| 2679 | _privFlag => TRUE, # All IVs are private | ||
| 2680 | |||
| 2681 | # Standard table object IVs | ||
| 2682 | # ------------------------- | ||
| 2683 | |||
| 2684 | # The table object's number within the parent strip object (matches | ||
| 2685 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to | ||
| 2686 | # access its default IVs) | ||
| 2687 | number => $number, | ||
| 2688 | # A name for the table object. Can be any string or, if no name was specified in the | ||
| 2689 | # call to the calling function, $name is the same as $number. (No part of the code | ||
| 2690 | # checks that table object names are unique; if two or more table objects share the | ||
| 2691 | # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary | ||
| 2692 | # table objects. Max 16 chars) | ||
| 2693 | name => $name, | ||
| 2694 | # The type of table object (custom table objects should use a ->type starting with | ||
| 2695 | # 'custom_' to avoid clashing with future built-in table objects) | ||
| 2696 | type => 'check_button', | ||
| 2697 | # The parent strip object (GA::Strip::Table) | ||
| 2698 | stripObj => $stripObj, | ||
| 2699 | # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for | ||
| 2700 | # temporary table objects | ||
| 2701 | winObj => $winObj, | ||
| 2702 | # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip | ||
| 2703 | # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary | ||
| 2704 | # table objects | ||
| 2705 | zoneObj => $zoneObj, | ||
| 2706 | |||
| 2707 | # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is | ||
| 2708 | # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as | ||
| 2709 | # when a connection to a world terminates) | ||
| 2710 | allowRemoveFlag => TRUE, | ||
| 2711 | # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is | ||
| 2712 | # created. Set to FALSE if it can't be resized | ||
| 2713 | allowResizeFlag => TRUE, | ||
| 2714 | # Initialisation settings stored as a hash (see the comments above) | ||
| 2715 | initHash => \%modHash, | ||
| 2716 | # Reference to a function to call when some widget is used. This IV is set only when | ||
| 2717 | # required by this type of table object. It can be set by a call to | ||
| 2718 | # $self->set_func() or by some setting in $self->initHash, which is applied in the | ||
| 2719 | # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the | ||
| 2720 | # generic object function Games::Axmud->getMethodRef() | ||
| 2721 | funcRef => undef, | ||
| 2722 | # A value passed to ->funcRef when it is called which identifies this table object and | ||
| 2723 | # its widget(s). Can be any value except 'undef'. It can be set by a call to | ||
| 2724 | # $self->set_id() or by some setting in $self->initHash, which is applied in the call | ||
| 2725 | # to $self->objEnable() | ||
| 2726 | funcID => '', | ||
| 2727 | |||
| 2728 | # The container widget(s) for this table object | ||
| 2729 | packingBox => undef, # Gtk3::Grid | ||
| 2730 | packingBox2 => undef, # Gtk3::Grid | ||
| 2731 | |||
| 2732 | |||
| 2733 | # Other IVs | ||
| 2734 | # --------- | ||
| 2735 | |||
| 2736 | # Widgets | ||
| 2737 | button => undef, # Gtk3::CheckButton | ||
| 2738 | }; | ||
| 2739 | |||
| 2740 | # Bless the object into existence | ||
| 2741 | bless $self, $class; | ||
| 2742 | |||
| 2743 | return $self; | ||
| 2744 | } | ||
| 2745 | |||
| 2746 | ################## | ||
| 2747 | # Methods | ||
| 2748 | |||
| 2749 | # Standard table object functions | ||
| 2750 | |||
| 2751 | sub objEnable { | ||
| 2752 | |||
| 2753 | # Called by GA::Strip::Table->addTableObj | ||
| 2754 | # Sets up the table object's widgets | ||
| 2755 | # | ||
| 2756 | # Expected arguments | ||
| 2757 | # (none besides $self) | ||
| 2758 | # | ||
| 2759 | # Return values | ||
| 2760 | # 'undef' on improper arguments | ||
| 2761 | # 1 on success | ||
| 2762 | |||
| 2763 | my ($self, $check) = @_; | ||
| 2764 | |||
| 2765 | # Local variables | ||
| 2766 | my ( | ||
| 2767 | $funcRef, $funcID, $text, $tooltips, $alignX, $alignY, $selectFlag, $normalFlag, | ||
| 2768 | $hExpandFlag, $vExpandFlag, | ||
| 2769 | ); | ||
| 2770 | |||
| 2771 | # Check for improper arguments | ||
| 2772 | if (defined $check) { | ||
| 2773 | |||
| 2774 | return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_); | ||
| 2775 | } | ||
| 2776 | |||
| 2777 | # Interpret $self->initHash, replacing any invalid values | ||
| 2778 | $funcRef = $self->ivShow('initHash', 'func'); | ||
| 2779 | $funcID = $self->ivShow('initHash', 'id'); | ||
| 2780 | $text = $self->ivShow('initHash', 'text'); | ||
| 2781 | $tooltips = $self->ivShow('initHash', 'tooltips'); | ||
| 2782 | $alignX = $self->testAlign($self->ivShow('initHash', 'align_x'), 0); | ||
| 2783 | $alignY = $self->testAlign($self->ivShow('initHash', 'align_y'), 0.5); | ||
| 2784 | $selectFlag = $self->testFlag($self->ivShow('initHash', 'select_flag')); | ||
| 2785 | $normalFlag = $self->testFlag($self->ivShow('initHash', 'normal_flag')); | ||
| 2786 | $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag')); | ||
| 2787 | $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag')); | ||
| 2788 | |||
| 2789 | # Create packing box(es) | ||
| 2790 | my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::Grid->new()); | ||
| 2791 | |||
| 2792 | # Create the Gtk3::CheckButton | ||
| 2793 | my $button; | ||
| 2794 | if (defined $text && $text ne '') { | ||
| 2795 | $button = Gtk3::CheckButton->new_with_mnemonic($text); | ||
| 2796 | } else { | ||
| 2797 | $button = Gtk3::CheckButton->new(); | ||
| 2798 | } | ||
| 2799 | |||
| 2800 | $packingBox2->attach($button, 0, 0, 1, 1); | ||
| 2801 | |||
| 2802 | if (defined $text && $text ne '') { | ||
| 2803 | |||
| 2804 | $button->set_alignment($alignX, $alignY); | ||
| 2805 | } | ||
| 2806 | |||
| 2807 | if (defined $tooltips && $tooltips ne '') { | ||
| 2808 | |||
| 2809 | $button->set_tooltip_markup($tooltips); | ||
| 2810 | } | ||
| 2811 | |||
| 2812 | $button->set_active($selectFlag); | ||
| 2813 | if (! $normalFlag) { | ||
| 2814 | |||
| 2815 | $button->set_state('insensitive'); | ||
| 2816 | } | ||
| 2817 | |||
| 2818 | # Set expansion | ||
| 2819 | $button->set_hexpand($hExpandFlag); | ||
| 2820 | $button->set_vexpand($vExpandFlag); | ||
| 2821 | |||
| 2822 | # Update IVs | ||
| 2823 | $self->ivPoke('funcRef', $funcRef); | ||
| 2824 | $self->ivPoke('funcID', $funcID); | ||
| 2825 | $self->ivPoke('packingBox', $packingBox); | ||
| 2826 | $self->ivPoke('packingBox2', $packingBox2); | ||
| 2827 | $self->ivPoke('button', $button); | ||
| 2828 | |||
| 2829 | # Set up ->signal_connects | ||
| 2830 | $self->setToggledEvent(); | ||
| 2831 | |||
| 2832 | return 1; | ||
| 2833 | } | ||
| 2834 | |||
| 2835 | # sub objDestroy { # Inherited from GA::Generic::Table | ||
| 2836 | |||
| 2837 | # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table | ||
| 2838 | |||
| 2839 | # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table | ||
| 2840 | |||
| 2841 | # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table | ||
| 2842 | |||
| 2843 | # ->signal_connects | ||
| 2844 | |||
| 2845 | sub setToggledEvent { | ||
| 2846 | |||
| 2847 | # Called by $self->objEnable | ||
| 2848 | # | ||
| 2849 | # Expected arguments | ||
| 2850 | # (none besides $self) | ||
| 2851 | # | ||
| 2852 | # Return values | ||
| 2853 | # 'undef' on improper arguments | ||
| 2854 | # 1 otherwise | ||
| 2855 | |||
| 2856 | my ($self, $check) = @_; | ||
| 2857 | |||
| 2858 | # Check for improper arguments | ||
| 2859 | if (defined $check) { | ||
| 2860 | |||
| 2861 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setToggledEvent', @_); | ||
| 2862 | } | ||
| 2863 | |||
| 2864 | # ->signal_connect | ||
| 2865 | $self->button->signal_connect('toggled' => sub { | ||
| 2866 | |||
| 2867 | my $currentFuncRef = $self->funcRef; | ||
| 2868 | |||
| 2869 | if ($currentFuncRef) { | ||
| 2870 | |||
| 2871 | if ($self->button->get_active()) { | ||
| 2872 | &$currentFuncRef($self, $self->button, $self->funcID, TRUE); | ||
| 2873 | } else { | ||
| 2874 | &$currentFuncRef($self, $self->button, $self->funcID, FALSE); | ||
| 2875 | } | ||
| 2876 | } | ||
| 2877 | }); | ||
| 2878 | |||
| 2879 | return 1; | ||
| 2880 | } | ||
| 2881 | |||
| 2882 | # Other functions | ||
| 2883 | |||
| 2884 | ################## | ||
| 2885 | # Accessors - set | ||
| 2886 | |||
| 2887 | sub set_align { | ||
| 2888 | |||
| 2889 | my ($self, $alignX, $alignY, $check) = @_; | ||
| 2890 | |||
| 2891 | # Check for improper arguments | ||
| 2892 | if (defined $check) { | ||
| 2893 | |||
| 2894 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_align', @_); | ||
| 2895 | } | ||
| 2896 | |||
| 2897 | $alignX = $self->testAlign($alignX, 0); | ||
| 2898 | $alignY = $self->testAlign($alignY, 0.5); | ||
| 2899 | |||
| 2900 | $self->button->set_alignment($alignX, $alignY); | ||
| 2901 | |||
| 2902 | return 1; | ||
| 2903 | } | ||
| 2904 | |||
| 2905 | # sub set_func {} # Inherited from GA::Generic::Table | ||
| 2906 | |||
| 2907 | # sub set_id {} # Inherited from GA::Generic::Table | ||
| 2908 | |||
| 2909 | sub set_select { | ||
| 2910 | |||
| 2911 | my ($self, $flag, $check) = @_; | ||
| 2912 | |||
| 2913 | # Check for improper arguments | ||
| 2914 | if (defined $check) { | ||
| 2915 | |||
| 2916 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_select', @_); | ||
| 2917 | } | ||
| 2918 | |||
| 2919 | $self->button->set_active($self->testFlag($flag)); | ||
| 2920 | |||
| 2921 | return 1; | ||
| 2922 | } | ||
| 2923 | |||
| 2924 | sub set_normal { | ||
| 2925 | |||
| 2926 | my ($self, $flag, $check) = @_; | ||
| 2927 | |||
| 2928 | # Check for improper arguments | ||
| 2929 | if (defined $check) { | ||
| 2930 | |||
| 2931 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_normal', @_); | ||
| 2932 | } | ||
| 2933 | |||
| 2934 | if (! $flag) { | ||
| 2935 | $self->button->set_state('insensitive'); | ||
| 2936 | } else { | ||
| 2937 | $self->button->set_state('normal'); | ||
| 2938 | } | ||
| 2939 | |||
| 2940 | return 1; | ||
| 2941 | } | ||
| 2942 | |||
| 2943 | sub set_text { | ||
| 2944 | |||
| 2945 | my ($self, $text, $check) = @_; | ||
| 2946 | |||
| 2947 | # Check for improper arguments | ||
| 2948 | if (defined $check) { | ||
| 2949 | |||
| 2950 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_text', @_); | ||
| 2951 | } | ||
| 2952 | |||
| 2953 | if (! defined $text) { | ||
| 2954 | |||
| 2955 | $text = ''; | ||
| 2956 | } | ||
| 2957 | |||
| 2958 | $self->button->set_label($text); | ||
| 2959 | |||
| 2960 | return 1; | ||
| 2961 | } | ||
| 2962 | |||
| 2963 | sub set_tooltips { | ||
| 2964 | |||
| 2965 | my ($self, $tooltips, $check) = @_; | ||
| 2966 | |||
| 2967 | # Check for improper arguments | ||
| 2968 | if (defined $check) { | ||
| 2969 | |||
| 2970 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_tooltips', @_); | ||
| 2971 | } | ||
| 2972 | |||
| 2973 | if (! defined $tooltips || $tooltips eq '') { | ||
| 2974 | $self->button->set_tooltip_text(undef); | ||
| 2975 | } else { | ||
| 2976 | $self->button->set_tooltip_markup($tooltips); | ||
| 2977 | } | ||
| 2978 | |||
| 2979 | return 1; | ||
| 2980 | } | ||
| 2981 | |||
| 2982 | # (Get equivalents) | ||
| 2983 | |||
| 2984 | sub get_align { | ||
| 2985 | |||
| 2986 | # Returns list in form ($alignX, $alignY); | ||
| 2987 | |||
| 2988 | my ($self, $alignX, $alignY, $check) = @_; | ||
| 2989 | |||
| 2990 | # Check for improper arguments | ||
| 2991 | if (defined $check) { | ||
| 2992 | |||
| 2993 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_align', @_); | ||
| 2994 | } | ||
| 2995 | |||
| 2996 | return $self->button->get_alignment(); | ||
| 2997 | } | ||
| 2998 | |||
| 2999 | sub get_normal { | ||
| 3000 | |||
| 3001 | # Returns TRUE for 'normal', FALSE for 'insensitive' or any other value | ||
| 3002 | |||
| 3003 | my ($self, $check) = @_; | ||
| 3004 | |||
| 3005 | # Check for improper arguments | ||
| 3006 | if (defined $check) { | ||
| 3007 | |||
| 3008 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_normal', @_); | ||
| 3009 | } | ||
| 3010 | |||
| 3011 | if ($self->button->get_state eq 'normal') { | ||
| 3012 | return TRUE; | ||
| 3013 | } else { | ||
| 3014 | return FALSE; | ||
| 3015 | } | ||
| 3016 | |||
| 3017 | return 1; | ||
| 3018 | } | ||
| 3019 | |||
| 3020 | sub get_select { | ||
| 3021 | |||
| 3022 | # Returns TRUE or FALSE | ||
| 3023 | |||
| 3024 | my ($self, $check) = @_; | ||
| 3025 | |||
| 3026 | # Check for improper arguments | ||
| 3027 | if (defined $check) { | ||
| 3028 | |||
| 3029 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_select', @_); | ||
| 3030 | } | ||
| 3031 | |||
| 3032 | if ($self->button->get_active()) { | ||
| 3033 | return TRUE; | ||
| 3034 | } else { | ||
| 3035 | return FALSE; | ||
| 3036 | } | ||
| 3037 | |||
| 3038 | return 1; | ||
| 3039 | } | ||
| 3040 | |||
| 3041 | sub get_text { | ||
| 3042 | |||
| 3043 | # Returns string | ||
| 3044 | my ($self, $check) = @_; | ||
| 3045 | |||
| 3046 | # Check for improper arguments | ||
| 3047 | if (defined $check) { | ||
| 3048 | |||
| 3049 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_text', @_); | ||
| 3050 | } | ||
| 3051 | |||
| 3052 | return $self->button->get_label(); | ||
| 3053 | } | ||
| 3054 | |||
| 3055 | sub get_tooltips { | ||
| 3056 | |||
| 3057 | # Returns string | ||
| 3058 | |||
| 3059 | my ($self, $check) = @_; | ||
| 3060 | |||
| 3061 | # Check for improper arguments | ||
| 3062 | if (defined $check) { | ||
| 3063 | |||
| 3064 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_tooltips', @_); | ||
| 3065 | } | ||
| 3066 | |||
| 3067 | return $self->button->get_tooltip_text(); | ||
| 3068 | } | ||
| 3069 | |||
| 3070 | ################## | ||
| 3071 | # Accessors - get | ||
| 3072 | |||
| 3073 | sub button | ||
| 3074 | { $_[0]->{button} } | ||
| 3075 | } | ||
| 3076 | |||
| 3077 | { package Games::Axmud::Table::RadioButton; | ||
| 3078 | |||
| 3079 | use strict; | ||
| 3080 | use warnings; | ||
| 3081 | # use diagnostics; | ||
| 3082 | |||
| 3083 | use Glib qw(TRUE FALSE); | ||
| 3084 | |||
| 3085 | our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud); | ||
| 3086 | |||
| 3087 | ################## | ||
| 3088 | # Constructors | ||
| 3089 | |||
| 3090 | sub new { | ||
| 3091 | |||
| 3092 | # Called by GA::Strip::Table->addTableObj | ||
| 3093 | # Creates the GA::Table::RadioButton, which contains a simple Gtk3::RadioButton | ||
| 3094 | # | ||
| 3095 | # Expected arguments | ||
| 3096 | # $number - The table object's number within the parent strip object (matches | ||
| 3097 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object | ||
| 3098 | # created to access its default IVs) | ||
| 3099 | # $name - A name for the table object. Can be any string or, if no name was | ||
| 3100 | # specified in the call to the calling function, $name is the same as | ||
| 3101 | # $number. (No part of the code checks that table object names are unique; | ||
| 3102 | # if two or more table objects share the same ->name, usually the one with | ||
| 3103 | # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16 | ||
| 3104 | # chars) | ||
| 3105 | # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table | ||
| 3106 | # objects | ||
| 3107 | # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the | ||
| 3108 | # parent strip object's Gtk3::Grid for use exclusively by this table | ||
| 3109 | # object. 'temp' for temporary table objects | ||
| 3110 | # | ||
| 3111 | # Optional arguments | ||
| 3112 | # %initHash - A hash containing arbitrary data to use as the table object's | ||
| 3113 | # initialisation settings. The table object should use default | ||
| 3114 | # initialisation settings unless it can succesfully interpret one or more | ||
| 3115 | # of the key-value pairs in the hash, if there are any | ||
| 3116 | # - This type of table object recognises these initialisation settings: | ||
| 3117 | # | ||
| 3118 | # 'func' - Reference to a function to call when the button is clicked. If | ||
| 3119 | # not specified or 'undef', it's up to the calling code to create its | ||
| 3120 | # own ->signal_connect. To obtain a reference to an OOP method, you | ||
| 3121 | # can use the generic object function Games::Axmud->getMethodRef() | ||
| 3122 | # 'id' - A value passed to the function which identifies the button. If | ||
| 3123 | # specified, can be any value except 'undef'. It's up to the | ||
| 3124 | # calling code to keep track of the widgets it has created and their | ||
| 3125 | # corresponding 'id' values | ||
| 3126 | # 'text' - The text to display as a label next to the button. In In Gtk, | ||
| 3127 | # 'text' is officially called a mnemonic, i.e. if any character is | ||
| 3128 | # preceded by an underline, that character is used as a keyboard | ||
| 3129 | # accelerator ('press' the button by pressing ALT + character). Must | ||
| 3130 | # be plain text, not pango markup. If not specified, 'undef' or an | ||
| 3131 | # empty string, no text is displayed | ||
| 3132 | # 'tooltips' - The text to display as tooltips for the button. Can be | ||
| 3133 | # plain text or pango markup text. If not specified, 'undef' or an | ||
| 3134 | # empty string, no tooltips are displayed | ||
| 3135 | # 'align_x', 'align_y' - The Gtk3::Button's alignment, values in the | ||
| 3136 | # range 0-1. If not specified, 'align_x' is set to 0, 'align_y' is set | ||
| 3137 | # to 0.5. Ignored if 'text' is not specified | ||
| 3138 | # 'select_flag' - If TRUE, the button is selected initially, if FALSE (or | ||
| 3139 | # not specified), it is not selected initially | ||
| 3140 | # 'normal_flag' - If TRUE (or not specified), the button's state is | ||
| 3141 | # 'normal'. If FALSE, the button's state is 'insensitive' (nothing can | ||
| 3142 | # interact with it) | ||
| 3143 | # 'group' - The radio button group from a previously-created | ||
| 3144 | # GA::Table::RadioButton object (and stored in its ->group IV). If | ||
| 3145 | # not specified or 'undef', this is the first radio button in its | ||
| 3146 | # group | ||
| 3147 | # 'expand_horizontal_flag' - If TRUE or unspecified, the table object | ||
| 3148 | # expands horizontally; if FALSE, it doesn't. Note that typically, | ||
| 3149 | # alignment does not work unless expansion is enabled | ||
| 3150 | # 'expand_vertical_flag' - If TRUE or unspecified, the table object | ||
| 3151 | # expands vertically; if FALSE, it doesn't | ||
| 3152 | # | ||
| 3153 | # Return values | ||
| 3154 | # 'undef' on improper arguments | ||
| 3155 | # Blessed reference to the newly-created object on success | ||
| 3156 | |||
| 3157 | my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_; | ||
| 3158 | |||
| 3159 | # Local variables | ||
| 3160 | my ( | ||
| 3161 | $winObj, | ||
| 3162 | %modHash, | ||
| 3163 | ); | ||
| 3164 | |||
| 3165 | # Check for improper arguments | ||
| 3166 | if ( | ||
| 3167 | ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj | ||
| 3168 | || ! defined $zoneObj | ||
| 3169 | ) { | ||
| 3170 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 3171 | } | ||
| 3172 | |||
| 3173 | # Deal with temporary table objects | ||
| 3174 | if ($stripObj eq 'temp') { | ||
| 3175 | $winObj = 'temp'; | ||
| 3176 | } else { | ||
| 3177 | $winObj = $stripObj->winObj; | ||
| 3178 | } | ||
| 3179 | |||
| 3180 | # Default initialisation settings | ||
| 3181 | %modHash = ( | ||
| 3182 | 'func' => undef, | ||
| 3183 | 'id' => '', | ||
| 3184 | 'text' => undef, | ||
| 3185 | 'tooltips' => undef, | ||
| 3186 | 'align_x' => 0, | ||
| 3187 | 'align_y' => 0.5, | ||
| 3188 | 'select_flag' => FALSE, | ||
| 3189 | 'normal_flag' => TRUE, | ||
| 3190 | 'group' => undef, | ||
| 3191 | 'expand_horizontal_flag' => TRUE, | ||
| 3192 | 'expand_vertical_flag' => TRUE, | ||
| 3193 | ); | ||
| 3194 | |||
| 3195 | # Interpret the initialisation settings in %initHash, if any | ||
| 3196 | foreach my $key (keys %modHash) { | ||
| 3197 | |||
| 3198 | if (exists $initHash{$key}) { | ||
| 3199 | |||
| 3200 | if ($key =~ m/flag$/) { | ||
| 3201 | |||
| 3202 | if ($initHash{$key}) { | ||
| 3203 | $modHash{$key} = TRUE; | ||
| 3204 | } else { | ||
| 3205 | $modHash{$key} = FALSE; | ||
| 3206 | } | ||
| 3207 | |||
| 3208 | } elsif ($key eq 'id' && ! defined $initHash{$key}) { | ||
| 3209 | |||
| 3210 | $modHash{$key} = ''; # 'id' value must not be 'undef' | ||
| 3211 | |||
| 3212 | } else { | ||
| 3213 | |||
| 3214 | $modHash{$key} = $initHash{$key}; | ||
| 3215 | } | ||
| 3216 | } | ||
| 3217 | } | ||
| 3218 | |||
| 3219 | # Setup | ||
| 3220 | my $self = { | ||
| 3221 | _objName => 'table_obj_' . $number, | ||
| 3222 | _objClass => $class, | ||
| 3223 | _parentFile => undef, # No parent file object | ||
| 3224 | _parentWorld => undef, # No parent file object | ||
| 3225 | _privFlag => TRUE, # All IVs are private | ||
| 3226 | |||
| 3227 | # Standard table object IVs | ||
| 3228 | # ------------------------- | ||
| 3229 | |||
| 3230 | # The table object's number within the parent strip object (matches | ||
| 3231 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to | ||
| 3232 | # access its default IVs) | ||
| 3233 | number => $number, | ||
| 3234 | # A name for the table object. Can be any string or, if no name was specified in the | ||
| 3235 | # call to the calling function, $name is the same as $number. (No part of the code | ||
| 3236 | # checks that table object names are unique; if two or more table objects share the | ||
| 3237 | # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary | ||
| 3238 | # table objects. Max 16 chars) | ||
| 3239 | name => $name, | ||
| 3240 | # The type of table object (custom table objects should use a ->type starting with | ||
| 3241 | # 'custom_' to avoid clashing with future built-in table objects) | ||
| 3242 | type => 'radio_button', | ||
| 3243 | # The parent strip object (GA::Strip::Table) | ||
| 3244 | stripObj => $stripObj, | ||
| 3245 | # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for | ||
| 3246 | # temporary table objects | ||
| 3247 | winObj => $winObj, | ||
| 3248 | # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip | ||
| 3249 | # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary | ||
| 3250 | # table objects | ||
| 3251 | zoneObj => $zoneObj, | ||
| 3252 | |||
| 3253 | # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is | ||
| 3254 | # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as | ||
| 3255 | # when a connection to a world terminates) | ||
| 3256 | allowRemoveFlag => TRUE, | ||
| 3257 | # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is | ||
| 3258 | # created. Set to FALSE if it can't be resized | ||
| 3259 | allowResizeFlag => TRUE, | ||
| 3260 | # Initialisation settings stored as a hash (see the comments above) | ||
| 3261 | initHash => \%modHash, | ||
| 3262 | # Reference to a function to call when some widget is used. This IV is set only when | ||
| 3263 | # required by this type of table object. It can be set by a call to | ||
| 3264 | # $self->set_func() or by some setting in $self->initHash, which is applied in the | ||
| 3265 | # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the | ||
| 3266 | # generic object function Games::Axmud->getMethodRef() | ||
| 3267 | funcRef => undef, | ||
| 3268 | # A value passed to ->funcRef when it is called which identifies this table object and | ||
| 3269 | # its widget(s). Can be any value except 'undef'. It can be set by a call to | ||
| 3270 | # $self->set_id() or by some setting in $self->initHash, which is applied in the call | ||
| 3271 | # to $self->objEnable() | ||
| 3272 | funcID => '', | ||
| 3273 | |||
| 3274 | # The container widget(s) for this table object | ||
| 3275 | packingBox => undef, # Gtk3::Grid | ||
| 3276 | packingBox2 => undef, # Gtk3::Grid | ||
| 3277 | |||
| 3278 | # Other IVs | ||
| 3279 | # --------- | ||
| 3280 | |||
| 3281 | # Widgets | ||
| 3282 | button => undef, # Gtk3::RadioButton | ||
| 3283 | group => undef, # Reference to array of widget references | ||
| 3284 | }; | ||
| 3285 | |||
| 3286 | # Bless the object into existence | ||
| 3287 | bless $self, $class; | ||
| 3288 | |||
| 3289 | return $self; | ||
| 3290 | } | ||
| 3291 | |||
| 3292 | ################## | ||
| 3293 | # Methods | ||
| 3294 | |||
| 3295 | # Standard table object functions | ||
| 3296 | |||
| 3297 | sub objEnable { | ||
| 3298 | |||
| 3299 | # Called by GA::Strip::Table->addTableObj | ||
| 3300 | # Sets up the table object's widgets | ||
| 3301 | # | ||
| 3302 | # Expected arguments | ||
| 3303 | # (none besides $self) | ||
| 3304 | # | ||
| 3305 | # Return values | ||
| 3306 | # 'undef' on improper arguments | ||
| 3307 | # 1 on success | ||
| 3308 | |||
| 3309 | my ($self, $check) = @_; | ||
| 3310 | |||
| 3311 | # Local variables | ||
| 3312 | my ( | ||
| 3313 | $funcRef, $funcID, $text, $tooltips, $alignX, $alignY, $selectFlag, $normalFlag, $group, | ||
| 3314 | $hExpandFlag, $vExpandFlag, | ||
| 3315 | ); | ||
| 3316 | |||
| 3317 | # Check for improper arguments | ||
| 3318 | if (defined $check) { | ||
| 3319 | |||
| 3320 | return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_); | ||
| 3321 | } | ||
| 3322 | |||
| 3323 | # Interpret $self->initHash, replacing any invalid values | ||
| 3324 | $funcRef = $self->ivShow('initHash', 'func'); | ||
| 3325 | $funcID = $self->ivShow('initHash', 'id'); | ||
| 3326 | $text = $self->ivShow('initHash', 'text'); | ||
| 3327 | $tooltips = $self->ivShow('initHash', 'tooltips'); | ||
| 3328 | $alignX = $self->testAlign($self->ivShow('initHash', 'align_x'), 0); | ||
| 3329 | $alignY = $self->testAlign($self->ivShow('initHash', 'align_y'), 0.5); | ||
| 3330 | $selectFlag = $self->testFlag($self->ivShow('initHash', 'select_flag')); | ||
| 3331 | $normalFlag = $self->testFlag($self->ivShow('initHash', 'normal_flag')); | ||
| 3332 | $group = $self->ivShow('initHash', 'group'); | ||
| 3333 | $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag')); | ||
| 3334 | $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag')); | ||
| 3335 | |||
| 3336 | # Create packing box(es) | ||
| 3337 | my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::Grid->new()); | ||
| 3338 | |||
| 3339 | # Create the Gtk3::RadioButton | ||
| 3340 | my $button = Gtk3::RadioButton->new(); | ||
| 3341 | $packingBox2->attach($button, 0, 0, 1, 1); | ||
| 3342 | |||
| 3343 | if (defined $text && $text ne '') { | ||
| 3344 | |||
| 3345 | $button->set_label($text); | ||
| 3346 | $button->set_alignment($alignX, $alignY); | ||
| 3347 | } | ||
| 3348 | |||
| 3349 | if (defined $tooltips && $tooltips ne '') { | ||
| 3350 | |||
| 3351 | $button->set_tooltip_markup($tooltips); | ||
| 3352 | } | ||
| 3353 | |||
| 3354 | if ($group) { | ||
| 3355 | |||
| 3356 | $button->set_group($group); | ||
| 3357 | } | ||
| 3358 | |||
| 3359 | $button->set_active($selectFlag); | ||
| 3360 | if (! $normalFlag) { | ||
| 3361 | |||
| 3362 | $button->set_state('insensitive'); | ||
| 3363 | } | ||
| 3364 | |||
| 3365 | # Set expansion | ||
| 3366 | $button->set_hexpand($hExpandFlag); | ||
| 3367 | $button->set_vexpand($vExpandFlag); | ||
| 3368 | |||
| 3369 | # Update IVs | ||
| 3370 | $self->ivPoke('funcRef', $funcRef); | ||
| 3371 | $self->ivPoke('funcID', $funcID); | ||
| 3372 | $self->ivPoke('packingBox', $packingBox); | ||
| 3373 | $self->ivPoke('packingBox2', $packingBox2); | ||
| 3374 | $self->ivPoke('button', $button); | ||
| 3375 | $self->ivPoke('group', $button->get_group()); | ||
| 3376 | |||
| 3377 | # Set up ->signal_connects | ||
| 3378 | $self->setToggledEvent(); | ||
| 3379 | |||
| 3380 | return 1; | ||
| 3381 | } | ||
| 3382 | |||
| 3383 | # sub objDestroy { # Inherited from GA::Generic::Table | ||
| 3384 | |||
| 3385 | # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table | ||
| 3386 | |||
| 3387 | # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table | ||
| 3388 | |||
| 3389 | # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table | ||
| 3390 | |||
| 3391 | # ->signal_connects | ||
| 3392 | |||
| 3393 | sub setToggledEvent { | ||
| 3394 | |||
| 3395 | # Called by $self->objEnable | ||
| 3396 | # | ||
| 3397 | # Expected arguments | ||
| 3398 | # (none besides $self) | ||
| 3399 | # | ||
| 3400 | # Return values | ||
| 3401 | # 'undef' on improper arguments | ||
| 3402 | # 1 otherwise | ||
| 3403 | |||
| 3404 | my ($self, $check) = @_; | ||
| 3405 | |||
| 3406 | # Check for improper arguments | ||
| 3407 | if (defined $check) { | ||
| 3408 | |||
| 3409 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setToggledEvent', @_); | ||
| 3410 | } | ||
| 3411 | |||
| 3412 | $self->button->signal_connect('toggled' => sub { | ||
| 3413 | |||
| 3414 | my $currentFuncRef = $self->funcRef; | ||
| 3415 | |||
| 3416 | # (Only call the function is the radio button is now active) | ||
| 3417 | if ($currentFuncRef && $self->button->get_active()) { | ||
| 3418 | |||
| 3419 | &$currentFuncRef($self, $self->button, $self->funcID); | ||
| 3420 | } | ||
| 3421 | }); | ||
| 3422 | |||
| 3423 | return 1; | ||
| 3424 | } | ||
| 3425 | |||
| 3426 | # Other functions | ||
| 3427 | |||
| 3428 | ################## | ||
| 3429 | # Accessors - set | ||
| 3430 | |||
| 3431 | sub set_align { | ||
| 3432 | |||
| 3433 | my ($self, $alignX, $alignY, $check) = @_; | ||
| 3434 | |||
| 3435 | # Check for improper arguments | ||
| 3436 | if (defined $check) { | ||
| 3437 | |||
| 3438 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_align', @_); | ||
| 3439 | } | ||
| 3440 | |||
| 3441 | $alignX = $self->testAlign($alignX, 0); | ||
| 3442 | $alignY = $self->testAlign($alignY, 0.5); | ||
| 3443 | |||
| 3444 | $self->button->set_alignment($alignX, $alignY); | ||
| 3445 | |||
| 3446 | return 1; | ||
| 3447 | } | ||
| 3448 | |||
| 3449 | # sub set_func {} # Inherited from GA::Generic::Table | ||
| 3450 | |||
| 3451 | # sub set_id {} # Inherited from GA::Generic::Table | ||
| 3452 | |||
| 3453 | sub set_normal { | ||
| 3454 | |||
| 3455 | my ($self, $flag, $check) = @_; | ||
| 3456 | |||
| 3457 | # Check for improper arguments | ||
| 3458 | if (defined $check) { | ||
| 3459 | |||
| 3460 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_normal', @_); | ||
| 3461 | } | ||
| 3462 | |||
| 3463 | if (! $flag) { | ||
| 3464 | $self->button->set_state('insensitive'); | ||
| 3465 | } else { | ||
| 3466 | $self->button->set_state('normal'); | ||
| 3467 | } | ||
| 3468 | |||
| 3469 | return 1; | ||
| 3470 | } | ||
| 3471 | |||
| 3472 | sub set_select { | ||
| 3473 | |||
| 3474 | my ($self, $flag, $check) = @_; | ||
| 3475 | |||
| 3476 | # Check for improper arguments | ||
| 3477 | if (defined $check) { | ||
| 3478 | |||
| 3479 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_select', @_); | ||
| 3480 | } | ||
| 3481 | |||
| 3482 | $self->button->set_active($self->testFlag($flag)); | ||
| 3483 | |||
| 3484 | return 1; | ||
| 3485 | } | ||
| 3486 | |||
| 3487 | sub set_text { | ||
| 3488 | |||
| 3489 | my ($self, $text, $check) = @_; | ||
| 3490 | |||
| 3491 | # Check for improper arguments | ||
| 3492 | if (defined $check) { | ||
| 3493 | |||
| 3494 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_text', @_); | ||
| 3495 | } | ||
| 3496 | |||
| 3497 | if (! defined $text) { | ||
| 3498 | |||
| 3499 | $text = ''; | ||
| 3500 | } | ||
| 3501 | |||
| 3502 | $self->button->set_label($text); | ||
| 3503 | |||
| 3504 | return 1; | ||
| 3505 | } | ||
| 3506 | |||
| 3507 | sub set_tooltips { | ||
| 3508 | |||
| 3509 | my ($self, $tooltips, $check) = @_; | ||
| 3510 | |||
| 3511 | # Check for improper arguments | ||
| 3512 | if (defined $check) { | ||
| 3513 | |||
| 3514 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_tooltips', @_); | ||
| 3515 | } | ||
| 3516 | |||
| 3517 | if (! defined $tooltips || $tooltips eq '') { | ||
| 3518 | $self->button->set_tooltip_text(undef); | ||
| 3519 | } else { | ||
| 3520 | $self->button->set_tooltip_markup($tooltips); | ||
| 3521 | } | ||
| 3522 | |||
| 3523 | return 1; | ||
| 3524 | } | ||
| 3525 | |||
| 3526 | # (Get equivalents) | ||
| 3527 | |||
| 3528 | sub get_align { | ||
| 3529 | |||
| 3530 | # Returns list in form ($alignX, $alignY); | ||
| 3531 | |||
| 3532 | my ($self, $alignX, $alignY, $check) = @_; | ||
| 3533 | |||
| 3534 | # Check for improper arguments | ||
| 3535 | if (defined $check) { | ||
| 3536 | |||
| 3537 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_align', @_); | ||
| 3538 | } | ||
| 3539 | |||
| 3540 | return $self->button->get_alignment(); | ||
| 3541 | } | ||
| 3542 | |||
| 3543 | sub get_normal { | ||
| 3544 | |||
| 3545 | # Returns TRUE for 'normal', FALSE for 'insensitive' or any other value | ||
| 3546 | |||
| 3547 | my ($self, $check) = @_; | ||
| 3548 | |||
| 3549 | # Check for improper arguments | ||
| 3550 | if (defined $check) { | ||
| 3551 | |||
| 3552 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_normal', @_); | ||
| 3553 | } | ||
| 3554 | |||
| 3555 | if ($self->button->get_state eq 'normal') { | ||
| 3556 | return TRUE; | ||
| 3557 | } else { | ||
| 3558 | return FALSE; | ||
| 3559 | } | ||
| 3560 | |||
| 3561 | return 1; | ||
| 3562 | } | ||
| 3563 | |||
| 3564 | sub get_select { | ||
| 3565 | |||
| 3566 | # Returns TRUE or FALSE | ||
| 3567 | |||
| 3568 | my ($self, $check) = @_; | ||
| 3569 | |||
| 3570 | # Check for improper arguments | ||
| 3571 | if (defined $check) { | ||
| 3572 | |||
| 3573 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_select', @_); | ||
| 3574 | } | ||
| 3575 | |||
| 3576 | if ($self->button->get_active()) { | ||
| 3577 | return TRUE; | ||
| 3578 | } else { | ||
| 3579 | return FALSE; | ||
| 3580 | } | ||
| 3581 | |||
| 3582 | return 1; | ||
| 3583 | } | ||
| 3584 | |||
| 3585 | sub get_text { | ||
| 3586 | |||
| 3587 | # Returns string | ||
| 3588 | my ($self, $check) = @_; | ||
| 3589 | |||
| 3590 | # Check for improper arguments | ||
| 3591 | if (defined $check) { | ||
| 3592 | |||
| 3593 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_text', @_); | ||
| 3594 | } | ||
| 3595 | |||
| 3596 | return $self->button->get_label(); | ||
| 3597 | } | ||
| 3598 | |||
| 3599 | sub get_tooltips { | ||
| 3600 | |||
| 3601 | # Returns string | ||
| 3602 | |||
| 3603 | my ($self, $check) = @_; | ||
| 3604 | |||
| 3605 | # Check for improper arguments | ||
| 3606 | if (defined $check) { | ||
| 3607 | |||
| 3608 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_tooltips', @_); | ||
| 3609 | } | ||
| 3610 | |||
| 3611 | return $self->button->get_tooltip_text(); | ||
| 3612 | } | ||
| 3613 | |||
| 3614 | ################## | ||
| 3615 | # Accessors - get | ||
| 3616 | |||
| 3617 | sub button | ||
| 3618 | { $_[0]->{button} } | ||
| 3619 | sub group | ||
| 3620 | { $_[0]->{group} } | ||
| 3621 | } | ||
| 3622 | |||
| 3623 | { package Games::Axmud::Table::Entry; | ||
| 3624 | |||
| 3625 | use strict; | ||
| 3626 | use warnings; | ||
| 3627 | # use diagnostics; | ||
| 3628 | |||
| 3629 | use Glib qw(TRUE FALSE); | ||
| 3630 | |||
| 3631 | our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud); | ||
| 3632 | |||
| 3633 | ################## | ||
| 3634 | # Constructors | ||
| 3635 | |||
| 3636 | sub new { | ||
| 3637 | |||
| 3638 | # Called by GA::Strip::Table->addTableObj | ||
| 3639 | # Creates the GA::Table::Entry, which contains a simple Gtk3::Entry | ||
| 3640 | # | ||
| 3641 | # Expected arguments | ||
| 3642 | # $number - The table object's number within the parent strip object (matches | ||
| 3643 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object | ||
| 3644 | # created to access its default IVs) | ||
| 3645 | # $name - A name for the table object. Can be any string or, if no name was | ||
| 3646 | # specified in the call to the calling function, $name is the same as | ||
| 3647 | # $number. (No part of the code checks that table object names are unique; | ||
| 3648 | # if two or more table objects share the same ->name, usually the one with | ||
| 3649 | # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16 | ||
| 3650 | # chars) | ||
| 3651 | # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table | ||
| 3652 | # objects | ||
| 3653 | # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the | ||
| 3654 | # parent strip object's Gtk3::Grid for use exclusively by this table | ||
| 3655 | # object. 'temp' for temporary table objects | ||
| 3656 | # | ||
| 3657 | # Optional arguments | ||
| 3658 | # %initHash - A hash containing arbitrary data to use as the table object's | ||
| 3659 | # initialisation settings. The table object should use default | ||
| 3660 | # initialisation settings unless it can succesfully interpret one or more | ||
| 3661 | # of the key-value pairs in the hash, if there are any | ||
| 3662 | # - This type of table object recognises these initialisation settings: | ||
| 3663 | # | ||
| 3664 | # 'func' - Reference to a function to call when the user types something | ||
| 3665 | # in the entry box and presses 'return'. If not specified or 'undef', | ||
| 3666 | # it's up to the calling code to create its own ->signal_connect. To | ||
| 3667 | # obtain a reference to an OOP method, you can use the generic object | ||
| 3668 | # function Games::Axmud->getMethodRef() | ||
| 3669 | # 'id' - A value passed to the function which identifies the button. If | ||
| 3670 | # specified, can be any value except 'undef'. It's up to the | ||
| 3671 | # calling code to keep track of the widgets it has created and their | ||
| 3672 | # corresponding 'id' values | ||
| 3673 | # 'text' - The initial contents of the entry. If an empty string or | ||
| 3674 | # 'undef', the entry is initially empty | ||
| 3675 | # 'clear_flag' - If TRUE (or not specified), the entry is cleared when the | ||
| 3676 | # user presses the ENTER ley | ||
| 3677 | # 'width_chars' - The width of the entry, in characters. If not | ||
| 3678 | # specified, 0 or 'undef', a width is not applied to the entry | ||
| 3679 | # 'max_chars' - The maximum number of characters the entry can contain. | ||
| 3680 | # If not specified, 0 or 'undef', no maximum is applied to the entry | ||
| 3681 | # 'tooltips' - The text to display as tooltips for the entry. Can be | ||
| 3682 | # plain text or pango markup text. If not specified, 'undef' or an | ||
| 3683 | # empty string, no tooltips are displayed | ||
| 3684 | # 'normal_flag' - If TRUE (or not specified), the entry's state is | ||
| 3685 | # 'normal'. If FALSE, the button's state is 'insensitive' (nothing can | ||
| 3686 | # interact with it) | ||
| 3687 | # 'expand_flag' - Deprecated since v1.2.170; ignored if specified | ||
| 3688 | # 'expand_horizontal_flag' - If TRUE or unspecified, the table object | ||
| 3689 | # expands horizontally; if FALSE, it doesn't | ||
| 3690 | # 'expand_vertical_flag' - If TRUE or unspecified, the table object | ||
| 3691 | # expands vertically; if FALSE, it doesn't | ||
| 3692 | # 'check_flag' - If specified, the entry contains a stock icon which | ||
| 3693 | # indicates whether the entry's text is acceptable. The function | ||
| 3694 | # specified by 'func' will then only be called when the user presses | ||
| 3695 | # 'return' AND the entry's text is acceptable | ||
| 3696 | # 'check_yes' - The stock icon to use to show the entry's text is | ||
| 3697 | # acceptable. If not specified, 'gtk-yes' is used. (Ignored when | ||
| 3698 | # 'check_flag' is not specified) | ||
| 3699 | # 'check_no' - The stock icon to use to show the entry's text is not | ||
| 3700 | # acceptable. If not specified, 'gtk-no' is used. (Ignored when | ||
| 3701 | # 'check_flag' is not specified) | ||
| 3702 | # 'check_func' - Reference to a function which receives the entry's text | ||
| 3703 | # as an argument, and returns 1 if the text is acceptable, but 'undef' | ||
| 3704 | # if it's not acceptable. If not specified, 'check_type' is used to | ||
| 3705 | # judge acceptability instead. (Ignored when 'check_flag' is not | ||
| 3706 | # specified) | ||
| 3707 | # 'check_type' - Set to 'int' (to be acceptable, the entry's text must be | ||
| 3708 | # an integer), 'odd' (the entry's text must be an odd-numbered | ||
| 3709 | # integer), 'even' (the entry's text must be an even-numbered | ||
| 3710 | # integer), 'float' (the entry's text must be an integer or floating | ||
| 3711 | # point number), 'string' (the entry's text can contain anything, even | ||
| 3712 | # an empty string). If not specified, 'string' is used as a default. | ||
| 3713 | # (Ignored when 'check_flag' is not specified or if 'check_func' is | ||
| 3714 | # specified) | ||
| 3715 | # 'check_min', 'check_max' - For 'int'/'float', the minimum/maximum | ||
| 3716 | # values that are acceptable. For 'odd'/'even', the minimum/maximum | ||
| 3717 | # values that are acceptable; if the minimum value is less than 1 or 2 | ||
| 3718 | # respectively, then 1 or 2 are used instead. For 'string', the | ||
| 3719 | # minimum/maximum length of the string. If either or both values are | ||
| 3720 | # not specified or 'undef', then no minimumx and/or maximum applies. | ||
| 3721 | # (Ignored when 'check_flag' is not specified or if 'check_func' is | ||
| 3722 | # specified) | ||
| 3723 | # | ||
| 3724 | # Return values | ||
| 3725 | # 'undef' on improper arguments | ||
| 3726 | # Blessed reference to the newly-created object on success | ||
| 3727 | |||
| 3728 | my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_; | ||
| 3729 | |||
| 3730 | # Local variables | ||
| 3731 | my ( | ||
| 3732 | $winObj, | ||
| 3733 | %modHash, | ||
| 3734 | ); | ||
| 3735 | |||
| 3736 | # Check for improper arguments | ||
| 3737 | if ( | ||
| 3738 | ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj | ||
| 3739 | || ! defined $zoneObj | ||
| 3740 | ) { | ||
| 3741 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 3742 | } | ||
| 3743 | |||
| 3744 | # Deal with temporary table objects | ||
| 3745 | if ($stripObj eq 'temp') { | ||
| 3746 | $winObj = 'temp'; | ||
| 3747 | } else { | ||
| 3748 | $winObj = $stripObj->winObj; | ||
| 3749 | } | ||
| 3750 | |||
| 3751 | # Default initialisation settings | ||
| 3752 | %modHash = ( | ||
| 3753 | 'func' => undef, | ||
| 3754 | 'id' => '', | ||
| 3755 | 'text' => undef, | ||
| 3756 | 'clear_flag' => TRUE, | ||
| 3757 | 'width_chars' => 0, | ||
| 3758 | 'max_chars' => 0, | ||
| 3759 | 'tooltips' => undef, | ||
| 3760 | 'normal_flag' => TRUE, | ||
| 3761 | 'expand_flag' => TRUE, # Deprecated since v1.2.170 | ||
| 3762 | 'expand_horizontal_flag' => TRUE, | ||
| 3763 | 'expand_vertical_flag' => TRUE, | ||
| 3764 | 'check_flag' => FALSE, | ||
| 3765 | 'check_yes' => 'gtk-yes', | ||
| 3766 | 'check_no' => 'gtk-no', | ||
| 3767 | 'check_func' => undef, | ||
| 3768 | 'check_type' => 'string', | ||
| 3769 | 'check_min' => undef, | ||
| 3770 | 'check_max' => undef, | ||
| 3771 | ); | ||
| 3772 | |||
| 3773 | # Interpret the initialisation settings in %initHash, if any | ||
| 3774 | foreach my $key (keys %modHash) { | ||
| 3775 | |||
| 3776 | if (exists $initHash{$key}) { | ||
| 3777 | |||
| 3778 | if ($key =~ m/flag$/) { | ||
| 3779 | |||
| 3780 | if ($initHash{$key}) { | ||
| 3781 | $modHash{$key} = TRUE; | ||
| 3782 | } else { | ||
| 3783 | $modHash{$key} = FALSE; | ||
| 3784 | } | ||
| 3785 | |||
| 3786 | } elsif ($key eq 'id' && ! defined $initHash{$key}) { | ||
| 3787 | |||
| 3788 | $modHash{$key} = ''; # 'id' value must not be 'undef' | ||
| 3789 | |||
| 3790 | } else { | ||
| 3791 | |||
| 3792 | $modHash{$key} = $initHash{$key}; | ||
| 3793 | } | ||
| 3794 | } | ||
| 3795 | } | ||
| 3796 | |||
| 3797 | # Setup | ||
| 3798 | my $self = { | ||
| 3799 | _objName => 'table_obj_' . $number, | ||
| 3800 | _objClass => $class, | ||
| 3801 | _parentFile => undef, # No parent file object | ||
| 3802 | _parentWorld => undef, # No parent file object | ||
| 3803 | _privFlag => TRUE, # All IVs are private | ||
| 3804 | |||
| 3805 | # Standard table object IVs | ||
| 3806 | # ------------------------- | ||
| 3807 | |||
| 3808 | # The table object's number within the parent strip object (matches | ||
| 3809 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to | ||
| 3810 | # access its default IVs) | ||
| 3811 | number => $number, | ||
| 3812 | # A name for the table object. Can be any string or, if no name was specified in the | ||
| 3813 | # call to the calling function, $name is the same as $number. (No part of the code | ||
| 3814 | # checks that table object names are unique; if two or more table objects share the | ||
| 3815 | # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary | ||
| 3816 | # table objects. Max 16 chars) | ||
| 3817 | name => $name, | ||
| 3818 | # The type of table object (custom table objects should use a ->type starting with | ||
| 3819 | # 'custom_' to avoid clashing with future built-in table objects) | ||
| 3820 | type => 'entry', | ||
| 3821 | # The parent strip object (GA::Strip::Table) | ||
| 3822 | stripObj => $stripObj, | ||
| 3823 | # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for | ||
| 3824 | # temporary table objects | ||
| 3825 | winObj => $winObj, | ||
| 3826 | # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip | ||
| 3827 | # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary | ||
| 3828 | # table objects | ||
| 3829 | zoneObj => $zoneObj, | ||
| 3830 | |||
| 3831 | # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is | ||
| 3832 | # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as | ||
| 3833 | # when a connection to a world terminates) | ||
| 3834 | allowRemoveFlag => TRUE, | ||
| 3835 | # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is | ||
| 3836 | # created. Set to FALSE if it can't be resized | ||
| 3837 | allowResizeFlag => TRUE, | ||
| 3838 | # Initialisation settings stored as a hash (see the comments above) | ||
| 3839 | initHash => \%modHash, | ||
| 3840 | # Reference to a function to call when some widget is used. This IV is set only when | ||
| 3841 | # required by this type of table object. It can be set by a call to | ||
| 3842 | # $self->set_func() or by some setting in $self->initHash, which is applied in the | ||
| 3843 | # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the | ||
| 3844 | # generic object function Games::Axmud->getMethodRef() | ||
| 3845 | funcRef => undef, | ||
| 3846 | # A value passed to ->funcRef when it is called which identifies this table object and | ||
| 3847 | # its widget(s). Can be any value except 'undef'. It can be set by a call to | ||
| 3848 | # $self->set_id() or by some setting in $self->initHash, which is applied in the call | ||
| 3849 | # to $self->objEnable() | ||
| 3850 | funcID => '', | ||
| 3851 | |||
| 3852 | # The container widget(s) for this table object | ||
| 3853 | packingBox => undef, # Gtk3::Grid | ||
| 3854 | packingBox2 => undef, # Gtk3::Grid | ||
| 3855 | |||
| 3856 | # Other IVs | ||
| 3857 | # --------- | ||
| 3858 | |||
| 3859 | # Widgets | ||
| 3860 | entry => undef, # Gtk3::Entry | ||
| 3861 | |||
| 3862 | # IVs set by $self->objEnable, using values from $self->initHash after checking they're | ||
| 3863 | # valid (and using default values, if not) | ||
| 3864 | clearFlag => undef, | ||
| 3865 | checkFlag => undef, | ||
| 3866 | checkYes => undef, | ||
| 3867 | checkNo => undef, | ||
| 3868 | checkFunc => undef, | ||
| 3869 | checkType => undef, | ||
| 3870 | checkMin => undef, | ||
| 3871 | checkMax => undef, | ||
| 3872 | }; | ||
| 3873 | |||
| 3874 | # Bless the object into existence | ||
| 3875 | bless $self, $class; | ||
| 3876 | |||
| 3877 | return $self; | ||
| 3878 | } | ||
| 3879 | |||
| 3880 | ################## | ||
| 3881 | # Methods | ||
| 3882 | |||
| 3883 | # Standard table object functions | ||
| 3884 | |||
| 3885 | sub objEnable { | ||
| 3886 | |||
| 3887 | # Called by GA::Strip::Table->addTableObj | ||
| 3888 | # Sets up the table object's widgets | ||
| 3889 | # | ||
| 3890 | # Expected arguments | ||
| 3891 | # (none besides $self) | ||
| 3892 | # | ||
| 3893 | # Return values | ||
| 3894 | # 'undef' on improper arguments | ||
| 3895 | # 1 on success | ||
| 3896 | |||
| 3897 | my ($self, $check) = @_; | ||
| 3898 | |||
| 3899 | # Local variables | ||
| 3900 | my ( | ||
| 3901 | $funcRef, $funcID, $text, $clearFlag, $widthChars, $maxChars, $tooltips, $normalFlag, | ||
| 3902 | $hExpandFlag, $vExpandFlag, $checkFlag, $checkYes, $checkNo, $checkFunc, $checkType, | ||
| 3903 | $checkMin, $checkMax, | ||
| 3904 | ); | ||
| 3905 | |||
| 3906 | # Check for improper arguments | ||
| 3907 | if (defined $check) { | ||
| 3908 | |||
| 3909 | return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_); | ||
| 3910 | } | ||
| 3911 | |||
| 3912 | # Interpret $self->initHash, replacing any invalid values | ||
| 3913 | $funcRef = $self->ivShow('initHash', 'func'); | ||
| 3914 | $funcID = $self->ivShow('initHash', 'id'); | ||
| 3915 | $text = $self->ivShow('initHash', 'text'); | ||
| 3916 | $clearFlag = $self->testFlag($self->ivShow('initHash', 'clear_flag')); | ||
| 3917 | $widthChars = $self->testInt($self->ivShow('initHash', 'width_chars'), 0, 0); | ||
| 3918 | $maxChars = $self->testInt($self->ivShow('initHash', 'max_chars'), 0, 0); | ||
| 3919 | $tooltips = $self->ivShow('initHash', 'tooltips'); | ||
| 3920 | $normalFlag = $self->testFlag($self->ivShow('initHash', 'normal_flag')); | ||
| 3921 | $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag')); | ||
| 3922 | $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag')); | ||
| 3923 | $checkFlag = $self->testFlag($self->ivShow('initHash', 'check_flag')); | ||
| 3924 | |||
| 3925 | if ($checkFlag) { | ||
| 3926 | |||
| 3927 | $checkYes = $self->testStock($self->ivShow('initHash', 'check_yes'), 'gtk-yes'); | ||
| 3928 | $checkNo = $self->testStock($self->ivShow('initHash', 'check_no'), 'gtk-no'); | ||
| 3929 | $checkFunc = $self->ivShow('initHash', 'check_func'); | ||
| 3930 | $checkType = $self->ivShow('initHash', 'check_type'); | ||
| 3931 | if ( | ||
| 3932 | ! defined $checkType | ||
| 3933 | || ( | ||
| 3934 | $checkType ne 'int' | ||
| 3935 | && $checkType ne 'even' | ||
| 3936 | && $checkType ne 'odd' | ||
| 3937 | && $checkType ne 'float' | ||
| 3938 | && $checkType ne 'string' | ||
| 3939 | ) | ||
| 3940 | ) { | ||
| 3941 | $checkType = 'string'; | ||
| 3942 | } | ||
| 3943 | |||
| 3944 | $checkMin = $self->testInt($self->ivShow('initHash', 'check_min'), undef, undef); | ||
| 3945 | $checkMax = $self->testInt($self->ivShow('initHash', 'check_max'), undef, undef); | ||
| 3946 | if (defined $checkMin && defined $checkMax && $checkMin > $checkMax) { | ||
| 3947 | |||
| 3948 | $checkMin = undef; | ||
| 3949 | $checkMax = undef; | ||
| 3950 | } | ||
| 3951 | |||
| 3952 | if (defined $checkType) { | ||
| 3953 | |||
| 3954 | if ($checkType eq 'odd' && defined $checkMin && $checkMin < 1) { | ||
| 3955 | |||
| 3956 | $checkMin = 1; | ||
| 3957 | |||
| 3958 | } elsif ($checkType eq 'even' && defined $checkMin && $checkMin < 2) { | ||
| 3959 | |||
| 3960 | $checkMin = 2; | ||
| 3961 | } | ||
| 3962 | |||
| 3963 | if ($checkType eq 'string' && defined $checkMin && $checkMin < 0) { | ||
| 3964 | |||
| 3965 | $checkMin = 0; | ||
| 3966 | } | ||
| 3967 | |||
| 3968 | if ($checkType eq 'string' && defined $checkMax && $checkMax < 0) { | ||
| 3969 | |||
| 3970 | $checkMax = 0; | ||
| 3971 | } | ||
| 3972 | } | ||
| 3973 | } | ||
| 3974 | |||
| 3975 | # Create packing box(es) | ||
| 3976 | my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::Grid->new()); | ||
| 3977 | |||
| 3978 | # Create the Gtk3::Entry | ||
| 3979 | my $entry = Gtk3::Entry->new(); | ||
| 3980 | $packingBox2->attach($entry, 0, 0, 1, 1); | ||
| 3981 | if (defined $text && $text ne '') { | ||
| 3982 | |||
| 3983 | $entry->set_text($text); | ||
| 3984 | } | ||
| 3985 | |||
| 3986 | if ($checkFlag && ! $checkFunc) { | ||
| 3987 | |||
| 3988 | if ($self->testIconValue($text, $checkType, $checkMax, $checkMin)) { | ||
| 3989 | $entry->set_icon_from_stock('secondary', $self->checkNo); | ||
| 3990 | } else { | ||
| 3991 | $entry->set_icon_from_stock('secondary', $self->checkYes); | ||
| 3992 | } | ||
| 3993 | } | ||
| 3994 | |||
| 3995 | if ($widthChars) { | ||
| 3996 | |||
| 3997 | $entry->set_width_chars($widthChars); | ||
| 3998 | } | ||
| 3999 | |||
| 4000 | if ($maxChars) { | ||
| 4001 | |||
| 4002 | $entry->set_max_length($maxChars); | ||
| 4003 | } | ||
| 4004 | |||
| 4005 | if (defined $tooltips && $tooltips ne '') { | ||
| 4006 | |||
| 4007 | $entry->set_tooltip_markup($tooltips); | ||
| 4008 | } | ||
| 4009 | |||
| 4010 | if (! $normalFlag) { | ||
| 4011 | |||
| 4012 | $entry->set_state('insensitive'); | ||
| 4013 | } | ||
| 4014 | |||
| 4015 | # Set expansion | ||
| 4016 | $entry->set_hexpand($hExpandFlag); | ||
| 4017 | $entry->set_vexpand($vExpandFlag); | ||
| 4018 | |||
| 4019 | # Update IVs | ||
| 4020 | $self->ivPoke('funcRef', $funcRef); | ||
| 4021 | $self->ivPoke('funcID', $funcID); | ||
| 4022 | $self->ivPoke('packingBox', $packingBox); | ||
| 4023 | $self->ivPoke('packingBox2', $packingBox2); | ||
| 4024 | $self->ivPoke('entry', $entry); | ||
| 4025 | $self->ivPoke('clearFlag', $clearFlag); | ||
| 4026 | $self->ivPoke('checkFlag', $checkFlag); | ||
| 4027 | $self->ivPoke('checkYes', $checkYes); | ||
| 4028 | $self->ivPoke('checkNo', $checkNo); | ||
| 4029 | $self->ivPoke('checkFunc', $checkFunc); | ||
| 4030 | $self->ivPoke('checkType', $checkType); | ||
| 4031 | $self->ivPoke('checkMin', $checkMin); | ||
| 4032 | $self->ivPoke('checkMax', $checkMax); | ||
| 4033 | |||
| 4034 | # Set up ->signal_connects | ||
| 4035 | $self->setChangedEvent(); | ||
| 4036 | $self->setActivateEvent(); | ||
| 4037 | |||
| 4038 | return 1; | ||
| 4039 | } | ||
| 4040 | |||
| 4041 | # sub objDestroy { # Inherited from GA::Generic::Table | ||
| 4042 | |||
| 4043 | # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table | ||
| 4044 | |||
| 4045 | # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table | ||
| 4046 | |||
| 4047 | # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table | ||
| 4048 | |||
| 4049 | # ->signal_connects | ||
| 4050 | |||
| 4051 | sub setChangedEvent { | ||
| 4052 | |||
| 4053 | # Called by $self->objEnable | ||
| 4054 | # | ||
| 4055 | # Expected arguments | ||
| 4056 | # (none besides $self) | ||
| 4057 | # | ||
| 4058 | # Return values | ||
| 4059 | # 'undef' on improper arguments | ||
| 4060 | # 1 otherwise | ||
| 4061 | |||
| 4062 | my ($self, $check) = @_; | ||
| 4063 | |||
| 4064 | # Check for improper arguments | ||
| 4065 | if (defined $check) { | ||
| 4066 | |||
| 4067 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setChangedEvent', @_); | ||
| 4068 | } | ||
| 4069 | |||
| 4070 | $self->entry->signal_connect('changed' => sub { | ||
| 4071 | |||
| 4072 | my ($value, $thisCheckFunc); | ||
| 4073 | |||
| 4074 | $value = $self->entry->get_text(); | ||
| 4075 | $thisCheckFunc = $self->checkFunc; | ||
| 4076 | |||
| 4077 | if ($self->checkFlag) { | ||
| 4078 | |||
| 4079 | if (! $thisCheckFunc) { | ||
| 4080 | |||
| 4081 | if ( | ||
| 4082 | ! $self->testIconValue( | ||
| 4083 | $value, | ||
| 4084 | $self->checkType, | ||
| 4085 | $self->checkMin, | ||
| 4086 | $self->checkMax, | ||
| 4087 | ) | ||
| 4088 | ) { | ||
| 4089 | $self->entry->set_icon_from_stock('secondary', $self->checkNo); | ||
| 4090 | } else { | ||
| 4091 | $self->entry->set_icon_from_stock('secondary', $self->checkYes); | ||
| 4092 | } | ||
| 4093 | |||
| 4094 | } else { | ||
| 4095 | |||
| 4096 | if (! &$thisCheckFunc($self, $self->entry, $self->funcID, $value)) { | ||
| 4097 | $self->entry->set_icon_from_stock('secondary', $self->checkNo); | ||
| 4098 | } else { | ||
| 4099 | $self->entry->set_icon_from_stock('secondary', $self->checkYes); | ||
| 4100 | } | ||
| 4101 | } | ||
| 4102 | } | ||
| 4103 | }); | ||
| 4104 | |||
| 4105 | return 1; | ||
| 4106 | } | ||
| 4107 | |||
| 4108 | sub setActivateEvent { | ||
| 4109 | |||
| 4110 | # Called by $self->objEnable | ||
| 4111 | # | ||
| 4112 | # Expected arguments | ||
| 4113 | # (none besides $self) | ||
| 4114 | # | ||
| 4115 | # Return values | ||
| 4116 | # 'undef' on improper arguments | ||
| 4117 | # 1 otherwise | ||
| 4118 | |||
| 4119 | my ($self, $check) = @_; | ||
| 4120 | |||
| 4121 | # Check for improper arguments | ||
| 4122 | if (defined $check) { | ||
| 4123 | |||
| 4124 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setActivateEvent', @_); | ||
| 4125 | } | ||
| 4126 | |||
| 4127 | $self->entry->signal_connect('activate' => sub { | ||
| 4128 | |||
| 4129 | my ($value, $thisFuncRef); | ||
| 4130 | |||
| 4131 | $value = $self->entry->get_text(); | ||
| 4132 | $thisFuncRef = $self->funcRef; | ||
| 4133 | |||
| 4134 | if ( | ||
| 4135 | $thisFuncRef | ||
| 4136 | && ( | ||
| 4137 | ! $self->checkFlag || $self->testIconValue( | ||
| 4138 | $value, | ||
| 4139 | $self->checkType, | ||
| 4140 | $self->checkMin, | ||
| 4141 | $self->checkMax, | ||
| 4142 | ) | ||
| 4143 | ) | ||
| 4144 | ) { | ||
| 4145 | &$thisFuncRef($self, $self->entry, $self->funcID, $value); | ||
| 4146 | } | ||
| 4147 | |||
| 4148 | if ($self->clearFlag) { | ||
| 4149 | |||
| 4150 | $self->entry->set_text(''); | ||
| 4151 | } | ||
| 4152 | }); | ||
| 4153 | |||
| 4154 | return 1; | ||
| 4155 | } | ||
| 4156 | |||
| 4157 | # Other functions | ||
| 4158 | |||
| 4159 | ################## | ||
| 4160 | # Accessors - set | ||
| 4161 | |||
| 4162 | sub set_check_func { | ||
| 4163 | |||
| 4164 | # If $funcRef is 'undef', $self->checkType is used to judge acceptability instead | ||
| 4165 | |||
| 4166 | my ($self, $funcRef, $check) = @_; | ||
| 4167 | |||
| 4168 | # Check for improper arguments | ||
| 4169 | if (defined $check) { | ||
| 4170 | |||
| 4171 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_check_func', @_); | ||
| 4172 | } | ||
| 4173 | |||
| 4174 | if (! $self->checkFlag) { | ||
| 4175 | |||
| 4176 | return undef; | ||
| 4177 | |||
| 4178 | } else { | ||
| 4179 | |||
| 4180 | $self->ivPoke('checkFunc', $funcRef); | ||
| 4181 | |||
| 4182 | return 1; | ||
| 4183 | } | ||
| 4184 | } | ||
| 4185 | |||
| 4186 | sub set_check_max { | ||
| 4187 | |||
| 4188 | my ($self, $num, $check) = @_; | ||
| 4189 | |||
| 4190 | # Check for improper arguments | ||
| 4191 | if (defined $check) { | ||
| 4192 | |||
| 4193 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_check_max', @_); | ||
| 4194 | } | ||
| 4195 | |||
| 4196 | if (! $self->checkFlag) { | ||
| 4197 | |||
| 4198 | return undef; | ||
| 4199 | |||
| 4200 | } else { | ||
| 4201 | |||
| 4202 | $self->ivPoke('checkMax', $self->testInt($num, undef, undef)); | ||
| 4203 | |||
| 4204 | return 1; | ||
| 4205 | } | ||
| 4206 | } | ||
| 4207 | |||
| 4208 | sub set_check_min { | ||
| 4209 | |||
| 4210 | my ($self, $num, $check) = @_; | ||
| 4211 | |||
| 4212 | # Check for improper arguments | ||
| 4213 | if (defined $check) { | ||
| 4214 | |||
| 4215 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_check_min', @_); | ||
| 4216 | } | ||
| 4217 | |||
| 4218 | if (! $self->checkFlag) { | ||
| 4219 | |||
| 4220 | return undef; | ||
| 4221 | |||
| 4222 | } else { | ||
| 4223 | |||
| 4224 | $self->ivPoke('checkMin', $self->testInt($num, undef, undef)); | ||
| 4225 | |||
| 4226 | return 1; | ||
| 4227 | } | ||
| 4228 | } | ||
| 4229 | |||
| 4230 | sub set_check_type { | ||
| 4231 | |||
| 4232 | my ($self, $type, $check) = @_; | ||
| 4233 | |||
| 4234 | # Check for improper arguments | ||
| 4235 | if (defined $check) { | ||
| 4236 | |||
| 4237 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_check_type', @_); | ||
| 4238 | } | ||
| 4239 | |||
| 4240 | if (! $self->checkFlag) { | ||
| 4241 | |||
| 4242 | return undef; | ||
| 4243 | } | ||
| 4244 | |||
| 4245 | if ( | ||
| 4246 | ! defined $type | ||
| 4247 | || ( | ||
| 4248 | $type ne 'int' | ||
| 4249 | && $type ne 'even' | ||
| 4250 | && $type ne 'odd' | ||
| 4251 | && $type ne 'float' | ||
| 4252 | && $type ne 'string' | ||
| 4253 | ) | ||
| 4254 | ) { | ||
| 4255 | $type = 'string'; | ||
| 4256 | } | ||
| 4257 | |||
| 4258 | $self->ivPoke('checkType', $type); | ||
| 4259 | |||
| 4260 | return 1; | ||
| 4261 | } | ||
| 4262 | |||
| 4263 | # sub set_func {} # Inherited from GA::Generic::Table | ||
| 4264 | |||
| 4265 | # sub set_id {} # Inherited from GA::Generic::Table | ||
| 4266 | |||
| 4267 | sub set_max_chars { | ||
| 4268 | |||
| 4269 | my ($self, $num, $check) = @_; | ||
| 4270 | |||
| 4271 | # Check for improper arguments | ||
| 4272 | if (defined $check) { | ||
| 4273 | |||
| 4274 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_max_chars', @_); | ||
| 4275 | } | ||
| 4276 | |||
| 4277 | $self->entry->set_max_length($self->testInt($num, 0, 0)); | ||
| 4278 | |||
| 4279 | return 1; | ||
| 4280 | } | ||
| 4281 | |||
| 4282 | sub set_normal { | ||
| 4283 | |||
| 4284 | my ($self, $flag, $check) = @_; | ||
| 4285 | |||
| 4286 | # Check for improper arguments | ||
| 4287 | if (defined $check) { | ||
| 4288 | |||
| 4289 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_normal', @_); | ||
| 4290 | } | ||
| 4291 | |||
| 4292 | if (! $flag) { | ||
| 4293 | $self->entry->set_state('insensitive'); | ||
| 4294 | } else { | ||
| 4295 | $self->entry->set_state('normal'); | ||
| 4296 | } | ||
| 4297 | |||
| 4298 | return 1; | ||
| 4299 | } | ||
| 4300 | |||
| 4301 | sub set_text { | ||
| 4302 | |||
| 4303 | my ($self, $text, $check) = @_; | ||
| 4304 | |||
| 4305 | # Check for improper arguments | ||
| 4306 | if (defined $check) { | ||
| 4307 | |||
| 4308 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_text', @_); | ||
| 4309 | } | ||
| 4310 | |||
| 4311 | if (! defined $text) { | ||
| 4312 | |||
| 4313 | $text = ''; | ||
| 4314 | } | ||
| 4315 | |||
| 4316 | $self->entry->set_text($text); | ||
| 4317 | |||
| 4318 | return 1; | ||
| 4319 | } | ||
| 4320 | |||
| 4321 | sub set_tooltips { | ||
| 4322 | |||
| 4323 | my ($self, $tooltips, $check) = @_; | ||
| 4324 | |||
| 4325 | # Check for improper arguments | ||
| 4326 | if (defined $check) { | ||
| 4327 | |||
| 4328 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_tooltips', @_); | ||
| 4329 | } | ||
| 4330 | |||
| 4331 | if (! defined $tooltips || $tooltips eq '') { | ||
| 4332 | $self->entry->set_tooltip_text(undef); | ||
| 4333 | } else { | ||
| 4334 | $self->entry->set_tooltip_markup($tooltips); | ||
| 4335 | } | ||
| 4336 | |||
| 4337 | return 1; | ||
| 4338 | } | ||
| 4339 | |||
| 4340 | sub set_width_chars { | ||
| 4341 | |||
| 4342 | my ($self, $num, $check) = @_; | ||
| 4343 | |||
| 4344 | # Check for improper arguments | ||
| 4345 | if (defined $check) { | ||
| 4346 | |||
| 4347 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_width_chars', @_); | ||
| 4348 | } | ||
| 4349 | |||
| 4350 | $self->entry->set_width_chars($self->testInt($num, 0, 0)); | ||
| 4351 | |||
| 4352 | return 1; | ||
| 4353 | } | ||
| 4354 | |||
| 4355 | # (Get equivalents) | ||
| 4356 | |||
| 4357 | sub get_max_chars { | ||
| 4358 | |||
| 4359 | # Returns string | ||
| 4360 | my ($self, $check) = @_; | ||
| 4361 | |||
| 4362 | # Check for improper arguments | ||
| 4363 | if (defined $check) { | ||
| 4364 | |||
| 4365 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_max_chars', @_); | ||
| 4366 | } | ||
| 4367 | |||
| 4368 | return $self->entry->get_max_length(); | ||
| 4369 | } | ||
| 4370 | |||
| 4371 | sub get_normal { | ||
| 4372 | |||
| 4373 | # Returns TRUE for 'normal', FALSE for 'insensitive' or any other value | ||
| 4374 | |||
| 4375 | my ($self, $check) = @_; | ||
| 4376 | |||
| 4377 | # Check for improper arguments | ||
| 4378 | if (defined $check) { | ||
| 4379 | |||
| 4380 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_normal', @_); | ||
| 4381 | } | ||
| 4382 | |||
| 4383 | if ($self->entry->get_state eq 'normal') { | ||
| 4384 | return TRUE; | ||
| 4385 | } else { | ||
| 4386 | return FALSE; | ||
| 4387 | } | ||
| 4388 | |||
| 4389 | return 1; | ||
| 4390 | } | ||
| 4391 | |||
| 4392 | sub get_text { | ||
| 4393 | |||
| 4394 | # Returns string | ||
| 4395 | my ($self, $check) = @_; | ||
| 4396 | |||
| 4397 | # Check for improper arguments | ||
| 4398 | if (defined $check) { | ||
| 4399 | |||
| 4400 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_text', @_); | ||
| 4401 | } | ||
| 4402 | |||
| 4403 | return $self->entry->get_text(); | ||
| 4404 | } | ||
| 4405 | |||
| 4406 | sub get_tooltips { | ||
| 4407 | |||
| 4408 | # Returns string | ||
| 4409 | |||
| 4410 | my ($self, $check) = @_; | ||
| 4411 | |||
| 4412 | # Check for improper arguments | ||
| 4413 | if (defined $check) { | ||
| 4414 | |||
| 4415 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_tooltips', @_); | ||
| 4416 | } | ||
| 4417 | |||
| 4418 | return $self->entry->get_tooltip_text(); | ||
| 4419 | } | ||
| 4420 | |||
| 4421 | sub get_width_chars { | ||
| 4422 | |||
| 4423 | # Returns string | ||
| 4424 | my ($self, $check) = @_; | ||
| 4425 | |||
| 4426 | # Check for improper arguments | ||
| 4427 | if (defined $check) { | ||
| 4428 | |||
| 4429 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_width_chars', @_); | ||
| 4430 | } | ||
| 4431 | |||
| 4432 | return $self->entry->get_width_chars(); | ||
| 4433 | } | ||
| 4434 | |||
| 4435 | ################## | ||
| 4436 | # Accessors - get | ||
| 4437 | |||
| 4438 | sub entry | ||
| 4439 | { $_[0]->{entry} } | ||
| 4440 | |||
| 4441 | sub clearFlag | ||
| 4442 | { $_[0]->{clearFlag} } | ||
| 4443 | sub checkFlag | ||
| 4444 | { $_[0]->{checkFlag} } | ||
| 4445 | sub checkYes | ||
| 4446 | { $_[0]->{checkYes} } | ||
| 4447 | sub checkNo | ||
| 4448 | { $_[0]->{checkNo} } | ||
| 4449 | sub checkFunc | ||
| 4450 | { $_[0]->{checkFunc} } | ||
| 4451 | sub checkType | ||
| 4452 | { $_[0]->{checkType} } | ||
| 4453 | sub checkMin | ||
| 4454 | { $_[0]->{checkMin} } | ||
| 4455 | sub checkMax | ||
| 4456 | { $_[0]->{checkMax} } | ||
| 4457 | } | ||
| 4458 | |||
| 4459 | { package Games::Axmud::Table::ComboBox; | ||
| 4460 | |||
| 4461 | use strict; | ||
| 4462 | use warnings; | ||
| 4463 | # use diagnostics; | ||
| 4464 | |||
| 4465 | use Glib qw(TRUE FALSE); | ||
| 4466 | |||
| 4467 | our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud); | ||
| 4468 | |||
| 4469 | ################## | ||
| 4470 | # Constructors | ||
| 4471 | |||
| 4472 | sub new { | ||
| 4473 | |||
| 4474 | # Called by GA::Strip::Table->addTableObj | ||
| 4475 | # Creates the GA::Table::ComboBox, which contains a simple Gtk3::ComboBox | ||
| 4476 | # | ||
| 4477 | # Expected arguments | ||
| 4478 | # $number - The table object's number within the parent strip object (matches | ||
| 4479 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object | ||
| 4480 | # created to access its default IVs) | ||
| 4481 | # $name - A name for the table object. Can be any string or, if no name was | ||
| 4482 | # specified in the call to the calling function, $name is the same as | ||
| 4483 | # $number. (No part of the code checks that table object names are unique; | ||
| 4484 | # if two or more table objects share the same ->name, usually the one with | ||
| 4485 | # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16 | ||
| 4486 | # chars) | ||
| 4487 | # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table | ||
| 4488 | # objects | ||
| 4489 | # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the | ||
| 4490 | # parent strip object's Gtk3::Grid for use exclusively by this table | ||
| 4491 | # object. 'temp' for temporary table objects | ||
| 4492 | # | ||
| 4493 | # Optional arguments | ||
| 4494 | # %initHash - A hash containing arbitrary data to use as the table object's | ||
| 4495 | # initialisation settings. The table object should use default | ||
| 4496 | # initialisation settings unless it can succesfully interpret one or more | ||
| 4497 | # of the key-value pairs in the hash, if there are any | ||
| 4498 | # - This type of table object recognises these initialisation settings: | ||
| 4499 | # | ||
| 4500 | # 'func' - Reference to a function to call when an item in the combobox | ||
| 4501 | # is selected. If not specified or 'undef', it's up to the calling | ||
| 4502 | # code to create its own ->signal_connect. To obtain a reference to an | ||
| 4503 | # OOP method, you can use the generic object function | ||
| 4504 | # Games::Axmud->getMethodRef() | ||
| 4505 | # 'id' - A value passed to the function which identifies the button. If | ||
| 4506 | # specified, can be any value except 'undef'. It's up to the | ||
| 4507 | # calling code to keep track of the widgets it has created and their | ||
| 4508 | # corresponding 'id' values | ||
| 4509 | # 'list_ref' - Reference to a list used to fill the combobox. If 'undef' | ||
| 4510 | # or if the referenced list is empty, the combobox is empty | ||
| 4511 | # 'title' - A string to use as the combobox's title, e.g. 'Choose your | ||
| 4512 | # favourite cat'. If 'undef', a title isn't used | ||
| 4513 | # 'tooltips' - The text to display as tooltips for the button. Can be | ||
| 4514 | # plain text or pango markup text. If not specified, 'undef' or an | ||
| 4515 | # empty string, no tooltips are displayed | ||
| 4516 | # 'normal_flag' - If TRUE (or not specified), the button's state is | ||
| 4517 | # 'normal'. If FALSE, the button's state is 'insensitive' (nothing can | ||
| 4518 | # interact with it) | ||
| 4519 | # 'expand_flag' - Deprecated since v1.2.170; ignored if specified | ||
| 4520 | # 'expand_horizontal_flag' - If TRUE or unspecified, the table object | ||
| 4521 | # expands horizontally; if FALSE, it doesn't | ||
| 4522 | # 'expand_vertical_flag' - If TRUE or unspecified, the table object | ||
| 4523 | # expands vertically; if FALSE, it doesn't | ||
| 4524 | # | ||
| 4525 | # Return values | ||
| 4526 | # 'undef' on improper arguments | ||
| 4527 | # Blessed reference to the newly-created object on success | ||
| 4528 | |||
| 4529 | my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_; | ||
| 4530 | |||
| 4531 | # Local variables | ||
| 4532 | my ( | ||
| 4533 | $winObj, | ||
| 4534 | %modHash, | ||
| 4535 | ); | ||
| 4536 | |||
| 4537 | # Check for improper arguments | ||
| 4538 | if ( | ||
| 4539 | ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj | ||
| 4540 | || ! defined $zoneObj | ||
| 4541 | ) { | ||
| 4542 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 4543 | } | ||
| 4544 | |||
| 4545 | # Deal with temporary table objects | ||
| 4546 | if ($stripObj eq 'temp') { | ||
| 4547 | $winObj = 'temp'; | ||
| 4548 | } else { | ||
| 4549 | $winObj = $stripObj->winObj; | ||
| 4550 | } | ||
| 4551 | |||
| 4552 | # Default initialisation settings | ||
| 4553 | %modHash = ( | ||
| 4554 | 'func' => undef, | ||
| 4555 | 'id' => '', | ||
| 4556 | 'list_ref' => undef, | ||
| 4557 | 'title' => undef, | ||
| 4558 | 'tooltips' => undef, | ||
| 4559 | 'normal_flag' => TRUE, | ||
| 4560 | 'expand_flag' => TRUE, # Deprecated since v1.2.170 | ||
| 4561 | 'expand_horizontal_flag' => TRUE, | ||
| 4562 | 'expand_vertical_flag' => TRUE, | ||
| 4563 | ); | ||
| 4564 | |||
| 4565 | # Interpret the initialisation settings in %initHash, if any | ||
| 4566 | foreach my $key (keys %modHash) { | ||
| 4567 | |||
| 4568 | if (exists $initHash{$key}) { | ||
| 4569 | |||
| 4570 | if ($key =~ m/flag$/) { | ||
| 4571 | |||
| 4572 | if ($initHash{$key}) { | ||
| 4573 | $modHash{$key} = TRUE; | ||
| 4574 | } else { | ||
| 4575 | $modHash{$key} = FALSE; | ||
| 4576 | } | ||
| 4577 | |||
| 4578 | } elsif ($key eq 'id' && ! defined $initHash{$key}) { | ||
| 4579 | |||
| 4580 | $modHash{$key} = ''; # 'id' value must not be 'undef' | ||
| 4581 | |||
| 4582 | } else { | ||
| 4583 | |||
| 4584 | $modHash{$key} = $initHash{$key}; | ||
| 4585 | } | ||
| 4586 | } | ||
| 4587 | } | ||
| 4588 | |||
| 4589 | # Setup | ||
| 4590 | my $self = { | ||
| 4591 | _objName => 'table_obj_' . $number, | ||
| 4592 | _objClass => $class, | ||
| 4593 | _parentFile => undef, # No parent file object | ||
| 4594 | _parentWorld => undef, # No parent file object | ||
| 4595 | _privFlag => TRUE, # All IVs are private | ||
| 4596 | |||
| 4597 | # Standard table object IVs | ||
| 4598 | # ------------------------- | ||
| 4599 | |||
| 4600 | # The table object's number within the parent strip object (matches | ||
| 4601 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to | ||
| 4602 | # access its default IVs) | ||
| 4603 | number => $number, | ||
| 4604 | # A name for the table object. Can be any string or, if no name was specified in the | ||
| 4605 | # call to the calling function, $name is the same as $number. (No part of the code | ||
| 4606 | # checks that table object names are unique; if two or more table objects share the | ||
| 4607 | # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary | ||
| 4608 | # table objects. Max 16 chars) | ||
| 4609 | name => $name, | ||
| 4610 | # The type of table object (custom table objects should use a ->type starting with | ||
| 4611 | # 'custom_' to avoid clashing with future built-in table objects) | ||
| 4612 | type => 'combo_box', | ||
| 4613 | # The parent strip object (GA::Strip::Table) | ||
| 4614 | stripObj => $stripObj, | ||
| 4615 | # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for | ||
| 4616 | # temporary table objects | ||
| 4617 | winObj => $winObj, | ||
| 4618 | # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip | ||
| 4619 | # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary | ||
| 4620 | # table objects | ||
| 4621 | zoneObj => $zoneObj, | ||
| 4622 | |||
| 4623 | # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is | ||
| 4624 | # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as | ||
| 4625 | # when a connection to a world terminates) | ||
| 4626 | allowRemoveFlag => TRUE, | ||
| 4627 | # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is | ||
| 4628 | # created. Set to FALSE if it can't be resized | ||
| 4629 | allowResizeFlag => TRUE, | ||
| 4630 | # Initialisation settings stored as a hash (see the comments above) | ||
| 4631 | initHash => \%modHash, | ||
| 4632 | # Reference to a function to call when some widget is used. This IV is set only when | ||
| 4633 | # required by this type of table object. It can be set by a call to | ||
| 4634 | # $self->set_func() or by some setting in $self->initHash, which is applied in the | ||
| 4635 | # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the | ||
| 4636 | # generic object function Games::Axmud->getMethodRef() | ||
| 4637 | funcRef => undef, | ||
| 4638 | # A value passed to ->funcRef when it is called which identifies this table object and | ||
| 4639 | # its widget(s). Can be any value except 'undef'. It can be set by a call to | ||
| 4640 | # $self->set_id() or by some setting in $self->initHash, which is applied in the call | ||
| 4641 | # to $self->objEnable() | ||
| 4642 | funcID => '', | ||
| 4643 | |||
| 4644 | # The container widget(s) for this table object | ||
| 4645 | packingBox => undef, # Gtk3::Grid | ||
| 4646 | packingBox2 => undef, # Gtk3::Grid | ||
| 4647 | |||
| 4648 | # Other IVs | ||
| 4649 | # --------- | ||
| 4650 | |||
| 4651 | # Widgets | ||
| 4652 | comboBox => undef, # Gtk3::ComboBox | ||
| 4653 | |||
| 4654 | # Item in the combobox used as a title ('undef' if no title specified). Set by | ||
| 4655 | # $self->objEnable from $self->initHash | ||
| 4656 | title => undef, | ||
| 4657 | }; | ||
| 4658 | |||
| 4659 | # Bless the object into existence | ||
| 4660 | bless $self, $class; | ||
| 4661 | |||
| 4662 | return $self; | ||
| 4663 | } | ||
| 4664 | |||
| 4665 | ################## | ||
| 4666 | # Methods | ||
| 4667 | |||
| 4668 | # Standard table object functions | ||
| 4669 | |||
| 4670 | sub objEnable { | ||
| 4671 | |||
| 4672 | # Called by GA::Strip::Table->addTableObj | ||
| 4673 | # Sets up the table object's widgets | ||
| 4674 | # | ||
| 4675 | # Expected arguments | ||
| 4676 | # (none besides $self) | ||
| 4677 | # | ||
| 4678 | # Return values | ||
| 4679 | # 'undef' on improper arguments | ||
| 4680 | # 1 on success | ||
| 4681 | |||
| 4682 | my ($self, $check) = @_; | ||
| 4683 | |||
| 4684 | # Local variables | ||
| 4685 | my ( | ||
| 4686 | $funcRef, $funcID, $listRef, $title, $tooltips, $normalFlag, $hExpandFlag, $vExpandFlag, | ||
| 4687 | ); | ||
| 4688 | |||
| 4689 | # Check for improper arguments | ||
| 4690 | if (defined $check) { | ||
| 4691 | |||
| 4692 | return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_); | ||
| 4693 | } | ||
| 4694 | |||
| 4695 | # Interpret $self->initHash, replacing any invalid values | ||
| 4696 | $funcRef = $self->ivShow('initHash', 'func'); | ||
| 4697 | $funcID = $self->ivShow('initHash', 'id'); | ||
| 4698 | $listRef = $self->ivShow('initHash', 'list_ref'); | ||
| 4699 | $title = $self->ivShow('initHash', 'title'); | ||
| 4700 | $tooltips = $self->ivShow('initHash', 'tooltips'); | ||
| 4701 | $normalFlag = $self->testFlag($self->ivShow('initHash', 'normal_flag')); | ||
| 4702 | $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag')); | ||
| 4703 | $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag')); | ||
| 4704 | |||
| 4705 | # Create packing box(es) | ||
| 4706 | my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::Grid->new()); | ||
| 4707 | |||
| 4708 | # Create the Gtk3::ComboBox | ||
| 4709 | my $comboBox = Gtk3::ComboBoxText->new(); | ||
| 4710 | $packingBox2->attach($comboBox, 0, 0, 1, 1); | ||
| 4711 | if (defined $title) { | ||
| 4712 | |||
| 4713 | $comboBox->append_text($title); | ||
| 4714 | } | ||
| 4715 | |||
| 4716 | foreach my $item (@$listRef) { | ||
| 4717 | |||
| 4718 | $comboBox->append_text($item); | ||
| 4719 | } | ||
| 4720 | |||
| 4721 | # The first item in the combobox is the first one selected | ||
| 4722 | $comboBox->set_active(0); | ||
| 4723 | |||
| 4724 | if (defined $tooltips && $tooltips ne '') { | ||
| 4725 | |||
| 4726 | $comboBox->set_tooltip_markup($tooltips); | ||
| 4727 | } | ||
| 4728 | |||
| 4729 | if (! $normalFlag) { | ||
| 4730 | |||
| 4731 | $comboBox->set_state('insensitive'); | ||
| 4732 | } | ||
| 4733 | |||
| 4734 | # Set expansion | ||
| 4735 | $comboBox->set_hexpand($hExpandFlag); | ||
| 4736 | $comboBox->set_vexpand($vExpandFlag); | ||
| 4737 | |||
| 4738 | # Update IVs | ||
| 4739 | $self->ivPoke('funcRef', $funcRef); | ||
| 4740 | $self->ivPoke('funcID', $funcID); | ||
| 4741 | $self->ivPoke('packingBox', $packingBox); | ||
| 4742 | $self->ivPoke('packingBox2', $packingBox2); | ||
| 4743 | $self->ivPoke('comboBox', $comboBox); | ||
| 4744 | $self->ivPoke('title', $title); | ||
| 4745 | |||
| 4746 | # Set up ->signal_connects | ||
| 4747 | $self->setChangedEvent(); | ||
| 4748 | |||
| 4749 | return 1; | ||
| 4750 | } | ||
| 4751 | |||
| 4752 | # sub objDestroy { # Inherited from GA::Generic::Table | ||
| 4753 | |||
| 4754 | # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table | ||
| 4755 | |||
| 4756 | # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table | ||
| 4757 | |||
| 4758 | # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table | ||
| 4759 | |||
| 4760 | # ->signal_connects | ||
| 4761 | |||
| 4762 | sub setChangedEvent { | ||
| 4763 | |||
| 4764 | # Called by $self->objEnable | ||
| 4765 | # | ||
| 4766 | # Expected arguments | ||
| 4767 | # (none besides $self) | ||
| 4768 | # | ||
| 4769 | # Return values | ||
| 4770 | # 'undef' on improper arguments | ||
| 4771 | # 1 otherwise | ||
| 4772 | |||
| 4773 | my ($self, $check) = @_; | ||
| 4774 | |||
| 4775 | # Check for improper arguments | ||
| 4776 | if (defined $check) { | ||
| 4777 | |||
| 4778 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setChangedEvent', @_); | ||
| 4779 | } | ||
| 4780 | |||
| 4781 | $self->comboBox->signal_connect('changed' => sub { | ||
| 4782 | |||
| 4783 | my ($currentFuncRef, $value); | ||
| 4784 | |||
| 4785 | $currentFuncRef = $self->funcRef; | ||
| 4786 | $value = $self->comboBox->get_active_text(); | ||
| 4787 | |||
| 4788 | # (If the user selects the title, ignore it) | ||
| 4789 | if ($currentFuncRef && (! defined $self->title || $value ne $self->title)) { | ||
| 4790 | |||
| 4791 | &$currentFuncRef($self, $self->comboBox, $self->funcID, $value); | ||
| 4792 | } | ||
| 4793 | }); | ||
| 4794 | |||
| 4795 | return 1; | ||
| 4796 | } | ||
| 4797 | |||
| 4798 | # Other functions | ||
| 4799 | |||
| 4800 | sub resetCombo { | ||
| 4801 | |||
| 4802 | # Can be called by anything | ||
| 4803 | # Resets the appearance of the combobox | ||
| 4804 | |||
| 4805 | # Expected arguments | ||
| 4806 | # (none besides $self) | ||
| 4807 | # | ||
| 4808 | # Return values | ||
| 4809 | # 'undef' on improper arguments | ||
| 4810 | # 1 otherwise | ||
| 4811 | |||
| 4812 | my ($self, $check) = @_; | ||
| 4813 | |||
| 4814 | # Check for improper arguments | ||
| 4815 | if (defined $check) { | ||
| 4816 | |||
| 4817 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetCombo', @_); | ||
| 4818 | } | ||
| 4819 | |||
| 4820 | $self->comboBox->set_active(0); | ||
| 4821 | $self->comboBox->popdown(); | ||
| 4822 | |||
| 4823 | return 1; | ||
| 4824 | } | ||
| 4825 | |||
| 4826 | ################## | ||
| 4827 | # Accessors - set | ||
| 4828 | |||
| 4829 | # sub set_func {} # Inherited from GA::Generic::Table | ||
| 4830 | |||
| 4831 | # sub set_id {} # Inherited from GA::Generic::Table | ||
| 4832 | |||
| 4833 | sub set_list { | ||
| 4834 | |||
| 4835 | my ($self, $title, @list) = @_; | ||
| 4836 | |||
| 4837 | # Local variables | ||
| 4838 | my ($funcRef, $model); | ||
| 4839 | |||
| 4840 | # (No improper arguments to check) | ||
| 4841 | |||
| 4842 | # Temporarily resetting $self->funcRef prevents the ->signal_connect from calling that | ||
| 4843 | # function while we're resetting the combobox | ||
| 4844 | $funcRef = $self->funcRef; | ||
| 4845 | $self->ivUndef('funcRef'); | ||
| 4846 | |||
| 4847 | # Empty the combobox... | ||
| 4848 | $model = $self->comboBox->get_model(); | ||
| 4849 | $model->clear(); | ||
| 4850 | |||
| 4851 | # ...and refill it (if specified) | ||
| 4852 | if (defined $title) { | ||
| 4853 | |||
| 4854 | $self->comboBox->append_text($title); | ||
| 4855 | $self->ivPoke('title', $title); | ||
| 4856 | |||
| 4857 | } else { | ||
| 4858 | |||
| 4859 | $self->ivUndef($title); | ||
| 4860 | } | ||
| 4861 | |||
| 4862 | foreach my $item (@list) { | ||
| 4863 | |||
| 4864 | $self->comboBox->append_text($item); | ||
| 4865 | } | ||
| 4866 | |||
| 4867 | # The first item in the combobox is the first one selected | ||
| 4868 | $self->comboBox->set_active(0); | ||
| 4869 | $self->comboBox->popdown(); | ||
| 4870 | |||
| 4871 | # Restore the combobox to normal operations | ||
| 4872 | $self->ivPoke('funcRef', $funcRef); | ||
| 4873 | |||
| 4874 | return 1; | ||
| 4875 | } | ||
| 4876 | |||
| 4877 | sub set_normal { | ||
| 4878 | |||
| 4879 | my ($self, $flag, $check) = @_; | ||
| 4880 | |||
| 4881 | # Check for improper arguments | ||
| 4882 | if (defined $check) { | ||
| 4883 | |||
| 4884 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_normal', @_); | ||
| 4885 | } | ||
| 4886 | |||
| 4887 | if (! $flag) { | ||
| 4888 | $self->comboBox->set_state('insensitive'); | ||
| 4889 | } else { | ||
| 4890 | $self->comboBox->set_state('normal'); | ||
| 4891 | } | ||
| 4892 | |||
| 4893 | return 1; | ||
| 4894 | } | ||
| 4895 | |||
| 4896 | sub set_tooltips { | ||
| 4897 | |||
| 4898 | my ($self, $tooltips, $check) = @_; | ||
| 4899 | |||
| 4900 | # Check for improper arguments | ||
| 4901 | if (defined $check) { | ||
| 4902 | |||
| 4903 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_tooltips', @_); | ||
| 4904 | } | ||
| 4905 | |||
| 4906 | if (! defined $tooltips || $tooltips eq '') { | ||
| 4907 | $self->comboBox->set_tooltip_text(undef); | ||
| 4908 | } else { | ||
| 4909 | $self->comboBox->set_tooltip_markup($tooltips); | ||
| 4910 | } | ||
| 4911 | |||
| 4912 | return 1; | ||
| 4913 | } | ||
| 4914 | |||
| 4915 | # (Get equivalents) | ||
| 4916 | |||
| 4917 | sub get_normal { | ||
| 4918 | |||
| 4919 | # Returns TRUE for 'normal', FALSE for 'insensitive' or any other value | ||
| 4920 | |||
| 4921 | my ($self, $check) = @_; | ||
| 4922 | |||
| 4923 | # Check for improper arguments | ||
| 4924 | if (defined $check) { | ||
| 4925 | |||
| 4926 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_normal', @_); | ||
| 4927 | } | ||
| 4928 | |||
| 4929 | if ($self->comboBox->get_state eq 'normal') { | ||
| 4930 | return TRUE; | ||
| 4931 | } else { | ||
| 4932 | return FALSE; | ||
| 4933 | } | ||
| 4934 | |||
| 4935 | return 1; | ||
| 4936 | } | ||
| 4937 | |||
| 4938 | sub get_text { | ||
| 4939 | |||
| 4940 | # Returns 'undef' if the combobox's title is selected | ||
| 4941 | |||
| 4942 | my ($self, $check) = @_; | ||
| 4943 | |||
| 4944 | # Local variables | ||
| 4945 | my $text; | ||
| 4946 | |||
| 4947 | # Check for improper arguments | ||
| 4948 | if (defined $check) { | ||
| 4949 | |||
| 4950 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_text', @_); | ||
| 4951 | } | ||
| 4952 | |||
| 4953 | $text = $self->comboBox->get_active_text(); | ||
| 4954 | |||
| 4955 | if (defined $self->title && $self->title eq $text) { | ||
| 4956 | return undef; | ||
| 4957 | } else { | ||
| 4958 | return $text; | ||
| 4959 | } | ||
| 4960 | } | ||
| 4961 | |||
| 4962 | sub get_tooltips { | ||
| 4963 | |||
| 4964 | # Returns string | ||
| 4965 | |||
| 4966 | my ($self, $check) = @_; | ||
| 4967 | |||
| 4968 | # Check for improper arguments | ||
| 4969 | if (defined $check) { | ||
| 4970 | |||
| 4971 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_tooltips', @_); | ||
| 4972 | } | ||
| 4973 | |||
| 4974 | return $self->comboBox->get_tooltip_text(); | ||
| 4975 | } | ||
| 4976 | |||
| 4977 | ################## | ||
| 4978 | # Accessors - get | ||
| 4979 | |||
| 4980 | sub comboBox | ||
| 4981 | { $_[0]->{comboBox} } | ||
| 4982 | sub title | ||
| 4983 | { $_[0]->{title} } | ||
| 4984 | } | ||
| 4985 | |||
| 4986 | { package Games::Axmud::Table::SimpleList; | ||
| 4987 | |||
| 4988 | use strict; | ||
| 4989 | use warnings; | ||
| 4990 | # use diagnostics; | ||
| 4991 | |||
| 4992 | use Glib qw(TRUE FALSE); | ||
| 4993 | |||
| 4994 | our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud); | ||
| 4995 | |||
| 4996 | ################## | ||
| 4997 | # Constructors | ||
| 4998 | |||
| 4999 | sub new { | ||
| 5000 | |||
| 5001 | # Called by GA::Strip::Table->addTableObj | ||
| 5002 | # Creates the GA::Table::SimpleList, which contains a simple GA::Obj::SimpleList | ||
| 5003 | # | ||
| 5004 | # Expected arguments | ||
| 5005 | # $number - The table object's number within the parent strip object (matches | ||
| 5006 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object | ||
| 5007 | # created to access its default IVs) | ||
| 5008 | # $name - A name for the table object. Can be any string or, if no name was | ||
| 5009 | # specified in the call to the calling function, $name is the same as | ||
| 5010 | # $number. (No part of the code checks that table object names are unique; | ||
| 5011 | # if two or more table objects share the same ->name, usually the one with | ||
| 5012 | # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16 | ||
| 5013 | # chars) | ||
| 5014 | # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table | ||
| 5015 | # objects | ||
| 5016 | # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the | ||
| 5017 | # parent strip object's Gtk3::Grid for use exclusively by this table | ||
| 5018 | # object. 'temp' for temporary table objects | ||
| 5019 | # | ||
| 5020 | # Optional arguments | ||
| 5021 | # %initHash - A hash containing arbitrary data to use as the table object's | ||
| 5022 | # initialisation settings. The table object should use default | ||
| 5023 | # initialisation settings unless it can succesfully interpret one or more | ||
| 5024 | # of the key-value pairs in the hash, if there are any | ||
| 5025 | # - This type of table object recognises these initialisation settings: | ||
| 5026 | # | ||
| 5027 | # 'frame_title' - If specified, the table object is drawn inside a frame | ||
| 5028 | # with the specified title. If 'undef', an empty string or not | ||
| 5029 | # specified, the table object does not use a frame and title | ||
| 5030 | # 'func' - Reference to a function to call when an item in the combobox | ||
| 5031 | # is selected. If not specified or 'undef', it's up to the calling | ||
| 5032 | # code to create its own ->signal_connect. To obtain a reference to an | ||
| 5033 | # OOP method, you can use the generic object function | ||
| 5034 | # Games::Axmud->getMethodRef() | ||
| 5035 | # 'id' - A value passed to the function which identifies the button. If | ||
| 5036 | # specified, can be any value except 'undef'. It's up to the | ||
| 5037 | # calling code to keep track of the widgets it has created and their | ||
| 5038 | # corresponding 'id' values | ||
| 5039 | # 'column_ref' - Reference to a list of column headings and types, in the | ||
| 5040 | # form ('heading', 'column_type', 'heading', 'column_type'...), where | ||
| 5041 | # 'column_type' is one of the column types recognised by | ||
| 5042 | # GA::Obj::SimpleList, i.e. 'text', 'markup', 'int', 'double', | ||
| 5043 | # 'bool', 'scalar' or 'pixbuf'. If 'undef' or an empty list, a single | ||
| 5044 | # column of type 'text' is created. If the list contains an odd | ||
| 5045 | # number of items, the final one is discarded | ||
| 5046 | # 'data_ref' - Reference to a list used to populate the | ||
| 5047 | # GA::Obj::SimpleList. If there are 2 columns, a list in the form | ||
| 5048 | # (a, b, a, b...) is expected. If there are 3 columns, a list in the | ||
| 5049 | # form (a, b, c, a, b, c) is expected. If 'undef' or an empty list, | ||
| 5050 | # nothing is added to the simple list | ||
| 5051 | # 'expand_horizontal_flag' - If TRUE or not specified, the table object | ||
| 5052 | # expands horizontally; if FALSE, it doesn't | ||
| 5053 | # 'expand_vertical_flag' - If TRUE or not specified, the table object | ||
| 5054 | # expands vertically; if FALSE, it doesn't | ||
| 5055 | # | ||
| 5056 | # Return values | ||
| 5057 | # 'undef' on improper arguments | ||
| 5058 | # Blessed reference to the newly-created object on success | ||
| 5059 | |||
| 5060 | my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_; | ||
| 5061 | |||
| 5062 | # Local variables | ||
| 5063 | my ( | ||
| 5064 | $winObj, | ||
| 5065 | %modHash, | ||
| 5066 | ); | ||
| 5067 | |||
| 5068 | # Check for improper arguments | ||
| 5069 | if ( | ||
| 5070 | ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj | ||
| 5071 | || ! defined $zoneObj | ||
| 5072 | ) { | ||
| 5073 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 5074 | } | ||
| 5075 | |||
| 5076 | # Deal with temporary table objects | ||
| 5077 | if ($stripObj eq 'temp') { | ||
| 5078 | $winObj = 'temp'; | ||
| 5079 | } else { | ||
| 5080 | $winObj = $stripObj->winObj; | ||
| 5081 | } | ||
| 5082 | |||
| 5083 | # Default initialisation settings | ||
| 5084 | %modHash = ( | ||
| 5085 | 'frame_title' => undef, | ||
| 5086 | 'func' => undef, | ||
| 5087 | 'id' => '', | ||
| 5088 | 'column_ref' => undef, | ||
| 5089 | 'data_ref' => undef, | ||
| 5090 | 'expand_horizontal_flag' => TRUE, | ||
| 5091 | 'expand_vertical_flag' => TRUE, | ||
| 5092 | ); | ||
| 5093 | |||
| 5094 | # Interpret the initialisation settings in %initHash, if any | ||
| 5095 | foreach my $key (keys %modHash) { | ||
| 5096 | |||
| 5097 | if (exists $initHash{$key}) { | ||
| 5098 | |||
| 5099 | if ($key =~ m/flag$/) { | ||
| 5100 | |||
| 5101 | if ($initHash{$key}) { | ||
| 5102 | $modHash{$key} = TRUE; | ||
| 5103 | } else { | ||
| 5104 | $modHash{$key} = FALSE; | ||
| 5105 | } | ||
| 5106 | |||
| 5107 | } elsif ($key eq 'id' && ! defined $initHash{$key}) { | ||
| 5108 | |||
| 5109 | $modHash{$key} = ''; # 'id' value must not be 'undef' | ||
| 5110 | |||
| 5111 | } else { | ||
| 5112 | |||
| 5113 | $modHash{$key} = $initHash{$key}; | ||
| 5114 | } | ||
| 5115 | } | ||
| 5116 | } | ||
| 5117 | |||
| 5118 | # Setup | ||
| 5119 | my $self = { | ||
| 5120 | _objName => 'table_obj_' . $number, | ||
| 5121 | _objClass => $class, | ||
| 5122 | _parentFile => undef, # No parent file object | ||
| 5123 | _parentWorld => undef, # No parent file object | ||
| 5124 | _privFlag => TRUE, # All IVs are private | ||
| 5125 | |||
| 5126 | # Standard table object IVs | ||
| 5127 | # ------------------------- | ||
| 5128 | |||
| 5129 | # The table object's number within the parent strip object (matches | ||
| 5130 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to | ||
| 5131 | # access its default IVs) | ||
| 5132 | number => $number, | ||
| 5133 | # A name for the table object. Can be any string or, if no name was specified in the | ||
| 5134 | # call to the calling function, $name is the same as $number. (No part of the code | ||
| 5135 | # checks that table object names are unique; if two or more table objects share the | ||
| 5136 | # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary | ||
| 5137 | # table objects. Max 16 chars) | ||
| 5138 | name => $name, | ||
| 5139 | # The type of table object (custom table objects should use a ->type starting with | ||
| 5140 | # 'custom_' to avoid clashing with future built-in table objects) | ||
| 5141 | type => 'simple_list', | ||
| 5142 | # The parent strip object (GA::Strip::Table) | ||
| 5143 | stripObj => $stripObj, | ||
| 5144 | # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for | ||
| 5145 | # temporary table objects | ||
| 5146 | winObj => $winObj, | ||
| 5147 | # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip | ||
| 5148 | # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary | ||
| 5149 | # table objects | ||
| 5150 | zoneObj => $zoneObj, | ||
| 5151 | |||
| 5152 | # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is | ||
| 5153 | # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as | ||
| 5154 | # when a connection to a world terminates) | ||
| 5155 | allowRemoveFlag => TRUE, | ||
| 5156 | # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is | ||
| 5157 | # created. Set to FALSE if it can't be resized | ||
| 5158 | allowResizeFlag => TRUE, | ||
| 5159 | # Initialisation settings stored as a hash (see the comments above) | ||
| 5160 | initHash => \%modHash, | ||
| 5161 | # Reference to a function to call when some widget is used. This IV is set only when | ||
| 5162 | # required by this type of table object. It can be set by a call to | ||
| 5163 | # $self->set_func() or by some setting in $self->initHash, which is applied in the | ||
| 5164 | # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the | ||
| 5165 | # generic object function Games::Axmud->getMethodRef() | ||
| 5166 | funcRef => undef, | ||
| 5167 | # A value passed to ->funcRef when it is called which identifies this table object and | ||
| 5168 | # its widget(s). Can be any value except 'undef'. It can be set by a call to | ||
| 5169 | # $self->set_id() or by some setting in $self->initHash, which is applied in the call | ||
| 5170 | # to $self->objEnable() | ||
| 5171 | funcID => '', | ||
| 5172 | |||
| 5173 | # The container widget(s) for this table object | ||
| 5174 | packingBox => undef, # Gtk3::ScrolledWindow or Gtk3::Frame | ||
| 5175 | packingBox2 => undef, # Gtk3::ScrolledWindow | ||
| 5176 | |||
| 5177 | # Other IVs | ||
| 5178 | # --------- | ||
| 5179 | |||
| 5180 | # Widgets | ||
| 5181 | slWidget => undef, # GA::Obj::SimpleList | ||
| 5182 | |||
| 5183 | # The number of columns in the simple list (minimum 1) | ||
| 5184 | numColumns => undef, | ||
| 5185 | }; | ||
| 5186 | |||
| 5187 | # Bless the object into existence | ||
| 5188 | bless $self, $class; | ||
| 5189 | |||
| 5190 | return $self; | ||
| 5191 | } | ||
| 5192 | |||
| 5193 | ################## | ||
| 5194 | # Methods | ||
| 5195 | |||
| 5196 | # Standard table object functions | ||
| 5197 | |||
| 5198 | sub objEnable { | ||
| 5199 | |||
| 5200 | # Called by GA::Strip::Table->addTableObj | ||
| 5201 | # Sets up the table object's widgets | ||
| 5202 | # | ||
| 5203 | # Expected arguments | ||
| 5204 | # (none besides $self) | ||
| 5205 | # | ||
| 5206 | # Return values | ||
| 5207 | # 'undef' on improper arguments | ||
| 5208 | # 1 on success | ||
| 5209 | |||
| 5210 | my ($self, $check) = @_; | ||
| 5211 | |||
| 5212 | # Local variables | ||
| 5213 | my ( | ||
| 5214 | $funcRef, $funcID, $columnListRef, $dataListRef, $hExpandFlag, $vExpandFlag, | ||
| 5215 | $numColumns, $count, | ||
| 5216 | @columnList, @dataList, | ||
| 5217 | ); | ||
| 5218 | |||
| 5219 | # Check for improper arguments | ||
| 5220 | if (defined $check) { | ||
| 5221 | |||
| 5222 | return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_); | ||
| 5223 | } | ||
| 5224 | |||
| 5225 | # Interpret $self->initHash, replacing any invalid values | ||
| 5226 | $funcRef = $self->ivShow('initHash', 'func'); | ||
| 5227 | $funcID = $self->ivShow('initHash', 'id'); | ||
| 5228 | $columnListRef = $self->ivShow('initHash', 'column_ref'); | ||
| 5229 | $dataListRef = $self->ivShow('initHash', 'data_ref'); | ||
| 5230 | $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag')); | ||
| 5231 | $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag')); | ||
| 5232 | |||
| 5233 | if (defined $columnListRef) { | ||
| 5234 | |||
| 5235 | @columnList = @$columnListRef; | ||
| 5236 | } | ||
| 5237 | |||
| 5238 | if (! (scalar @columnList) % 2) { | ||
| 5239 | |||
| 5240 | # List should be in the form ('heading', 'column_type', 'heading', 'column_type'...) but | ||
| 5241 | # a 'column_type' is missing; discard the unpaired 'heading' | ||
| 5242 | pop @columnList; | ||
| 5243 | } | ||
| 5244 | |||
| 5245 | if (! @columnList) { | ||
| 5246 | |||
| 5247 | # List contains no 'heading' or 'column_type', use default ones | ||
| 5248 | push (@columnList, 'Items', 'text'); | ||
| 5249 | } | ||
| 5250 | |||
| 5251 | if (defined $dataListRef) { | ||
| 5252 | |||
| 5253 | @dataList = @$dataListRef; | ||
| 5254 | } | ||
| 5255 | |||
| 5256 | # Create packing box(es) | ||
| 5257 | my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::ScrolledWindow->new()); | ||
| 5258 | $packingBox2->set_policy('automatic', 'automatic'); | ||
| 5259 | |||
| 5260 | # Create the GA::Obj::SimpleList | ||
| 5261 | my $slWidget = Games::Axmud::Obj::SimpleList->new(@columnList); | ||
| 5262 | $packingBox2->add_with_viewport($slWidget); | ||
| 5263 | |||
| 5264 | # Make all columns of type 'bool' (which are composed of checkbuttons) non-activatable, so | ||
| 5265 | # that the user can't click them on and off | ||
| 5266 | $numColumns = scalar (@columnList / 2); | ||
| 5267 | $count = -1; | ||
| 5268 | do { | ||
| 5269 | |||
| 5270 | my ($heading, $type); | ||
| 5271 | |||
| 5272 | $heading = shift @columnList; | ||
| 5273 | $type = shift @columnList; | ||
| 5274 | |||
| 5275 | $count++; | ||
| 5276 | |||
| 5277 | if ($type eq 'bool') { | ||
| 5278 | |||
| 5279 | my ($cellRenderer) = $slWidget->get_column($count)->get_cells(); | ||
| 5280 | $cellRenderer->set(activatable => FALSE); | ||
| 5281 | } | ||
| 5282 | |||
| 5283 | } until (! @columnList); | ||
| 5284 | |||
| 5285 | # Fill the simple list | ||
| 5286 | @{$slWidget->{data}} = @dataList; | ||
| 5287 | |||
| 5288 | # Set expansion | ||
| 5289 | $slWidget->set_hexpand($hExpandFlag); | ||
| 5290 | $slWidget->set_vexpand($vExpandFlag); | ||
| 5291 | |||
| 5292 | # Update IVs | ||
| 5293 | $self->ivPoke('funcRef', $funcRef); | ||
| 5294 | $self->ivPoke('funcID', $funcID); | ||
| 5295 | $self->ivPoke('packingBox', $packingBox); | ||
| 5296 | $self->ivPoke('packingBox2', $packingBox2); | ||
| 5297 | $self->ivPoke('slWidget', $slWidget); | ||
| 5298 | $self->ivPoke('numColumns', $numColumns); | ||
| 5299 | |||
| 5300 | return 1; | ||
| 5301 | } | ||
| 5302 | |||
| 5303 | # sub objDestroy { # Inherited from GA::Generic::Table | ||
| 5304 | |||
| 5305 | # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table | ||
| 5306 | |||
| 5307 | # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table | ||
| 5308 | |||
| 5309 | # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table | ||
| 5310 | |||
| 5311 | # ->signal_connects | ||
| 5312 | |||
| 5313 | # Other functions | ||
| 5314 | |||
| 5315 | ################## | ||
| 5316 | # Accessors - set | ||
| 5317 | |||
| 5318 | sub set_cell { | ||
| 5319 | |||
| 5320 | my ($self, $x, $y, $item, $check) = @_; | ||
| 5321 | |||
| 5322 | # Local variables | ||
| 5323 | my $slWidget; | ||
| 5324 | |||
| 5325 | # Check for improper arguments | ||
| 5326 | if (! defined $x || ! defined $y || defined $check) { | ||
| 5327 | |||
| 5328 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_cell', @_); | ||
| 5329 | } | ||
| 5330 | |||
| 5331 | $slWidget = $self->slWidget; | ||
| 5332 | ${$slWidget->{data}}[$x][$y] = $item; | ||
| 5333 | |||
| 5334 | return 1; | ||
| 5335 | } | ||
| 5336 | |||
| 5337 | # sub set_func {} # Inherited from GA::Generic::Table | ||
| 5338 | |||
| 5339 | # sub set_id {} # Inherited from GA::Generic::Table | ||
| 5340 | |||
| 5341 | sub set_list { | ||
| 5342 | |||
| 5343 | my ($self, @list) = @_; | ||
| 5344 | |||
| 5345 | # Local variables | ||
| 5346 | my $slWidget; | ||
| 5347 | |||
| 5348 | # (No improper arguments to check) | ||
| 5349 | |||
| 5350 | $slWidget = $self->slWidget; | ||
| 5351 | @{$slWidget->{data}} = @list; | ||
| 5352 | |||
| 5353 | return 1; | ||
| 5354 | } | ||
| 5355 | |||
| 5356 | sub set_row { | ||
| 5357 | |||
| 5358 | my ($self, $y, @list) = @_; | ||
| 5359 | |||
| 5360 | # Local variables | ||
| 5361 | my $slWidget; | ||
| 5362 | |||
| 5363 | # Check for improper arguments | ||
| 5364 | if (! defined $y) { | ||
| 5365 | |||
| 5366 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_item', @_); | ||
| 5367 | } | ||
| 5368 | |||
| 5369 | $slWidget = $self->slWidget; | ||
| 5370 | ${$slWidget->{data}}[$y] = \@list; | ||
| 5371 | |||
| 5372 | return 1; | ||
| 5373 | } | ||
| 5374 | |||
| 5375 | sub set_select { | ||
| 5376 | |||
| 5377 | my ($self, $y, $check) = @_; | ||
| 5378 | |||
| 5379 | # Check for improper arguments | ||
| 5380 | if (defined $check) { | ||
| 5381 | |||
| 5382 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_select', @_); | ||
| 5383 | } | ||
| 5384 | |||
| 5385 | if (defined $y) { | ||
| 5386 | $self->slWidget->select($y); | ||
| 5387 | } else { | ||
| 5388 | $self->slWidget->unselect_all(); | ||
| 5389 | } | ||
| 5390 | |||
| 5391 | return 1; | ||
| 5392 | } | ||
| 5393 | |||
| 5394 | # (Get equivalents) | ||
| 5395 | |||
| 5396 | sub get_cell { | ||
| 5397 | |||
| 5398 | my ($self, $x, $y, $check) = @_; | ||
| 5399 | |||
| 5400 | # Local variables | ||
| 5401 | my $slWidget; | ||
| 5402 | |||
| 5403 | # Check for improper arguments | ||
| 5404 | if (! defined $x || ! defined $y || defined $check) { | ||
| 5405 | |||
| 5406 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_cell', @_); | ||
| 5407 | } | ||
| 5408 | |||
| 5409 | $slWidget = $self->slWidget; | ||
| 5410 | return ${$slWidget->{data}}[$x][$y]; | ||
| 5411 | } | ||
| 5412 | |||
| 5413 | sub get_row { | ||
| 5414 | |||
| 5415 | my ($self, $y, $check) = @_; | ||
| 5416 | |||
| 5417 | # Local variables | ||
| 5418 | my $slWidget; | ||
| 5419 | |||
| 5420 | # Check for improper arguments | ||
| 5421 | if (! defined $y || defined $check) { | ||
| 5422 | |||
| 5423 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_item', @_); | ||
| 5424 | } | ||
| 5425 | |||
| 5426 | $slWidget = $self->slWidget; | ||
| 5427 | return ${$slWidget->{data}}[$y]; | ||
| 5428 | } | ||
| 5429 | |||
| 5430 | sub get_select { | ||
| 5431 | |||
| 5432 | my ($self, $check) = @_; | ||
| 5433 | |||
| 5434 | # Local variables | ||
| 5435 | my $rowNum; | ||
| 5436 | |||
| 5437 | # Check for improper arguments | ||
| 5438 | if (defined $check) { | ||
| 5439 | |||
| 5440 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_select', @_); | ||
| 5441 | } | ||
| 5442 | |||
| 5443 | ($rowNum) = $self->slWidget->get_selected_indices(); | ||
| 5444 | |||
| 5445 | return $rowNum; | ||
| 5446 | } | ||
| 5447 | |||
| 5448 | ################## | ||
| 5449 | # Accessors - get | ||
| 5450 | |||
| 5451 | sub slWidget | ||
| 5452 | { $_[0]->{slWidget} } | ||
| 5453 | |||
| 5454 | sub numColumns | ||
| 5455 | { $_[0]->{numColumns} } | ||
| 5456 | } | ||
| 5457 | |||
| 5458 | { package Games::Axmud::Table::TextView; | ||
| 5459 | |||
| 5460 | use strict; | ||
| 5461 | use warnings; | ||
| 5462 | # use diagnostics; | ||
| 5463 | |||
| 5464 | use Glib qw(TRUE FALSE); | ||
| 5465 | |||
| 5466 | our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud); | ||
| 5467 | |||
| 5468 | ################## | ||
| 5469 | # Constructors | ||
| 5470 | |||
| 5471 | sub new { | ||
| 5472 | |||
| 5473 | # Called by GA::Strip::Table->addTableObj | ||
| 5474 | # Creates the GA::Table::TextView, which contains a simple Gtk3::TextView | ||
| 5475 | # If all you want to do is to display some monochrome text in a scrolling textview (and | ||
| 5476 | # optionally allow the user to edit it), use this table object | ||
| 5477 | # For anything more ambitious, use a GA::Table::Pane object | ||
| 5478 | # | ||
| 5479 | # Expected arguments | ||
| 5480 | # $number - The table object's number within the parent strip object (matches | ||
| 5481 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object | ||
| 5482 | # created to access its default IVs) | ||
| 5483 | # $name - A name for the table object. Can be any string or, if no name was | ||
| 5484 | # specified in the call to the calling function, $name is the same as | ||
| 5485 | # $number. (No part of the code checks that table object names are unique; | ||
| 5486 | # if two or more table objects share the same ->name, usually the one with | ||
| 5487 | # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16 | ||
| 5488 | # chars) | ||
| 5489 | # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table | ||
| 5490 | # objects | ||
| 5491 | # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the | ||
| 5492 | # parent strip object's Gtk3::Grid for use exclusively by this table | ||
| 5493 | # object. 'temp' for temporary table objects | ||
| 5494 | # | ||
| 5495 | # Optional arguments | ||
| 5496 | # %initHash - A hash containing arbitrary data to use as the table object's | ||
| 5497 | # initialisation settings. The table object should use default | ||
| 5498 | # initialisation settings unless it can succesfully interpret one or more | ||
| 5499 | # of the key-value pairs in the hash, if there are any | ||
| 5500 | # - This type of table object recognises these initialisation settings: | ||
| 5501 | # | ||
| 5502 | # 'frame_title' - If specified, the table object is drawn inside a frame | ||
| 5503 | # with the specified title. If 'undef', an empty string or not | ||
| 5504 | # specified, the table object does not use a frame and title | ||
| 5505 | # 'func' - Reference to a function to call when an the contents of the | ||
| 5506 | # textview is edited. If not specified or 'undef', it's up to the | ||
| 5507 | # calling code to create its own ->signal_connect. To obtain a | ||
| 5508 | # reference to an OOP method, you can use the generic object function | ||
| 5509 | # Games::Axmud->getMethodRef() | ||
| 5510 | # 'id' - A value passed to the function which identifies the button. If | ||
| 5511 | # specified, can be any value except 'undef'. It's up to the | ||
| 5512 | # calling code to keep track of the widgets it has created and their | ||
| 5513 | # corresponding 'id' values | ||
| 5514 | # 'text' - String containing text and newline characters. If 'undef' or | ||
| 5515 | # not specified, the textview is initially empty | ||
| 5516 | # 'edit_flag' - If TRUE, the contents of the textview can be edited. If | ||
| 5517 | # FALSE (or not specified), the contents can't be edited | ||
| 5518 | # 'system_flag' - If TRUE, the system's preferred colours/fonts are | ||
| 5519 | # used. If FALSE (or not specified), an Axmud colour scheme is used | ||
| 5520 | # 'colour_scheme' - The name of the colour scheme to use (matches a key | ||
| 5521 | # in GA::Client->colourSchemeHash). If not specified or 'undef', the | ||
| 5522 | # parent window's colour scheme is used | ||
| 5523 | # 'spacing' - The size (in pixels) of the gap between the textview itself | ||
| 5524 | # and its containing Gtk3::Frame. A value in the range 0-100. If | ||
| 5525 | # 'undef', not specified or an invalid value, a value of 0 is used | ||
| 5526 | # 'expand_horizontal_flag' - If TRUE or not specified, the table object | ||
| 5527 | # expands horizontally; if FALSE, it doesn't | ||
| 5528 | # 'expand_vertical_flag' - If TRUE or not specified, the table object | ||
| 5529 | # expands vertically; if FALSE, it doesn't | ||
| 5530 | # | ||
| 5531 | # Return values | ||
| 5532 | # 'undef' on improper arguments | ||
| 5533 | # Blessed reference to the newly-created object on success | ||
| 5534 | |||
| 5535 | my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_; | ||
| 5536 | |||
| 5537 | # Local variables | ||
| 5538 | my ( | ||
| 5539 | $winObj, | ||
| 5540 | %modHash, | ||
| 5541 | ); | ||
| 5542 | |||
| 5543 | # Check for improper arguments | ||
| 5544 | if ( | ||
| 5545 | ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj | ||
| 5546 | || ! defined $zoneObj | ||
| 5547 | ) { | ||
| 5548 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 5549 | } | ||
| 5550 | |||
| 5551 | # Deal with temporary table objects | ||
| 5552 | if ($stripObj eq 'temp') { | ||
| 5553 | $winObj = 'temp'; | ||
| 5554 | } else { | ||
| 5555 | $winObj = $stripObj->winObj; | ||
| 5556 | } | ||
| 5557 | |||
| 5558 | # Default initialisation settings | ||
| 5559 | %modHash = ( | ||
| 5560 | 'frame_title' => undef, | ||
| 5561 | 'func' => undef, | ||
| 5562 | 'id' => '', | ||
| 5563 | 'text' => '', | ||
| 5564 | 'edit_flag' => FALSE, | ||
| 5565 | 'system_flag' => FALSE, | ||
| 5566 | 'colour_scheme' => undef, | ||
| 5567 | 'spacing' => 0, | ||
| 5568 | 'expand_horizontal_flag' => TRUE, | ||
| 5569 | 'expand_vertical_flag' => TRUE, | ||
| 5570 | ); | ||
| 5571 | |||
| 5572 | # Interpret the initialisation settings in %initHash, if any | ||
| 5573 | foreach my $key (keys %modHash) { | ||
| 5574 | |||
| 5575 | if (exists $initHash{$key}) { | ||
| 5576 | |||
| 5577 | if ($key =~ m/flag$/) { | ||
| 5578 | |||
| 5579 | if ($initHash{$key}) { | ||
| 5580 | $modHash{$key} = TRUE; | ||
| 5581 | } else { | ||
| 5582 | $modHash{$key} = FALSE; | ||
| 5583 | } | ||
| 5584 | |||
| 5585 | } elsif ($key eq 'id' && ! defined $initHash{$key}) { | ||
| 5586 | |||
| 5587 | $modHash{$key} = ''; # 'id' value must not be 'undef' | ||
| 5588 | |||
| 5589 | } else { | ||
| 5590 | |||
| 5591 | $modHash{$key} = $initHash{$key}; | ||
| 5592 | } | ||
| 5593 | } | ||
| 5594 | } | ||
| 5595 | |||
| 5596 | # Setup | ||
| 5597 | my $self = { | ||
| 5598 | _objName => 'table_obj_' . $number, | ||
| 5599 | _objClass => $class, | ||
| 5600 | _parentFile => undef, # No parent file object | ||
| 5601 | _parentWorld => undef, # No parent file object | ||
| 5602 | _privFlag => TRUE, # All IVs are private | ||
| 5603 | |||
| 5604 | # Standard table object IVs | ||
| 5605 | # ------------------------- | ||
| 5606 | |||
| 5607 | # The table object's number within the parent strip object (matches | ||
| 5608 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to | ||
| 5609 | # access its default IVs) | ||
| 5610 | number => $number, | ||
| 5611 | # A name for the table object. Can be any string or, if no name was specified in the | ||
| 5612 | # call to the calling function, $name is the same as $number. (No part of the code | ||
| 5613 | # checks that table object names are unique; if two or more table objects share the | ||
| 5614 | # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary | ||
| 5615 | # table objects. Max 16 chars) | ||
| 5616 | name => $name, | ||
| 5617 | # The type of table object (custom table objects should use a ->type starting with | ||
| 5618 | # 'custom_' to avoid clashing with future built-in table objects) | ||
| 5619 | type => 'text_view', | ||
| 5620 | # The parent strip object (GA::Strip::Table) | ||
| 5621 | stripObj => $stripObj, | ||
| 5622 | # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for | ||
| 5623 | # temporary table objects | ||
| 5624 | winObj => $winObj, | ||
| 5625 | # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip | ||
| 5626 | # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary | ||
| 5627 | # table objects | ||
| 5628 | zoneObj => $zoneObj, | ||
| 5629 | |||
| 5630 | # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is | ||
| 5631 | # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as | ||
| 5632 | # when a connection to a world terminates) | ||
| 5633 | allowRemoveFlag => TRUE, | ||
| 5634 | # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is | ||
| 5635 | # created. Set to FALSE if it can't be resized | ||
| 5636 | allowResizeFlag => TRUE, | ||
| 5637 | # Initialisation settings stored as a hash (see the comments above) | ||
| 5638 | initHash => \%modHash, | ||
| 5639 | # Reference to a function to call when some widget is used. This IV is set only when | ||
| 5640 | # required by this type of table object. It can be set by a call to | ||
| 5641 | # $self->set_func() or by some setting in $self->initHash, which is applied in the | ||
| 5642 | # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the | ||
| 5643 | # generic object function Games::Axmud->getMethodRef() | ||
| 5644 | funcRef => undef, | ||
| 5645 | # A value passed to ->funcRef when it is called which identifies this table object and | ||
| 5646 | # its widget(s). Can be any value except 'undef'. It can be set by a call to | ||
| 5647 | # $self->set_id() or by some setting in $self->initHash, which is applied in the call | ||
| 5648 | # to $self->objEnable() | ||
| 5649 | funcID => '', | ||
| 5650 | |||
| 5651 | # The container widget(s) for this table object | ||
| 5652 | packingBox => undef, # Gtk3::Grid or Gtk3::Frame | ||
| 5653 | packingBox2 => undef, # Gtk3::Grid | ||
| 5654 | |||
| 5655 | # Other IVs | ||
| 5656 | # --------- | ||
| 5657 | |||
| 5658 | # Widgets | ||
| 5659 | frame => undef, # Gtk3::Frame (may be 'undef') | ||
| 5660 | scroll => undef, # Gtk3::ScrolledWindow | ||
| 5661 | textView => undef, # Gtk3::TextView | ||
| 5662 | buffer => undef, # Gtk3::TextBuffer | ||
| 5663 | }; | ||
| 5664 | |||
| 5665 | # Bless the object into existence | ||
| 5666 | bless $self, $class; | ||
| 5667 | |||
| 5668 | return $self; | ||
| 5669 | } | ||
| 5670 | |||
| 5671 | ################## | ||
| 5672 | # Methods | ||
| 5673 | |||
| 5674 | # Standard table object functions | ||
| 5675 | |||
| 5676 | sub objEnable { | ||
| 5677 | |||
| 5678 | # Called by GA::Strip::Table->addTableObj | ||
| 5679 | # Sets up the table object's widgets | ||
| 5680 | # | ||
| 5681 | # Expected arguments | ||
| 5682 | # (none besides $self) | ||
| 5683 | # | ||
| 5684 | # Return values | ||
| 5685 | # 'undef' on improper arguments | ||
| 5686 | # 1 on success | ||
| 5687 | |||
| 5688 | my ($self, $check) = @_; | ||
| 5689 | |||
| 5690 | # Local variables | ||
| 5691 | my ( | ||
| 5692 | $funcRef, $funcID, $text, $editFlag, $systemFlag, $colourScheme, $spacing, $hExpandFlag, | ||
| 5693 | $vExpandFlag, $winType, | ||
| 5694 | ); | ||
| 5695 | |||
| 5696 | # Check for improper arguments | ||
| 5697 | if (defined $check) { | ||
| 5698 | |||
| 5699 | return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_); | ||
| 5700 | } | ||
| 5701 | |||
| 5702 | # Interpret $self->initHash, replacing any invalid values | ||
| 5703 | $funcRef = $self->ivShow('initHash', 'func'); | ||
| 5704 | $funcID = $self->ivShow('initHash', 'id'); | ||
| 5705 | $text = $self->ivShow('initHash', 'text'); | ||
| 5706 | if (! defined $text) { | ||
| 5707 | |||
| 5708 | $text = ''; | ||
| 5709 | } | ||
| 5710 | |||
| 5711 | $editFlag = $self->testFlag($self->ivShow('initHash', 'edit_flag')); | ||
| 5712 | $systemFlag = $self->testFlag($self->ivShow('initHash', 'system_flag')); | ||
| 5713 | $colourScheme = $self->ivShow('initHash', 'colour_scheme'); | ||
| 5714 | $spacing = $self->testInt($self->ivShow('initHash', 'spacing'), 0, 0); | ||
| 5715 | $hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag')); | ||
| 5716 | $vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag')); | ||
| 5717 | |||
| 5718 | # Create packing box(es) | ||
| 5719 | my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::Grid->new()); | ||
| 5720 | |||
| 5721 | # Create the Gtk3::TextView inside a Gtk3::Frame and Gtk3::ScrolledWindow. However, if | ||
| 5722 | # $packingBox is itself a Gtk3::Frame, don't create a second one | ||
| 5723 | my ($frame, $scroll); | ||
| 5724 | if (! $packingBox->isa('Gtk3::Frame')) { | ||
| 5725 | |||
| 5726 | $frame = Gtk3::Frame->new(undef); | ||
| 5727 | $packingBox2->attach($frame, 0, 0, 1, 1); | ||
| 5728 | $frame->set_border_width($spacing); | ||
| 5729 | |||
| 5730 | $scroll = Gtk3::ScrolledWindow->new(undef, undef); | ||
| 5731 | $frame->add($scroll); | ||
| 5732 | |||
| 5733 | } else { | ||
| 5734 | |||
| 5735 | $scroll = Gtk3::ScrolledWindow->new(undef, undef); | ||
| 5736 | $packingBox2->attach($scroll, 0, 0, 1, 1); | ||
| 5737 | } | ||
| 5738 | |||
| 5739 | $scroll->set_shadow_type($axmud::CLIENT->constShadowType); | ||
| 5740 | $scroll->set_policy('automatic', 'automatic'); | ||
| 5741 | $scroll->set_border_width($spacing); | ||
| 5742 | |||
| 5743 | # Create a textview | ||
| 5744 | my $textView = Gtk3::TextView->new(); | ||
| 5745 | $scroll->add($textView); | ||
| 5746 | my $buffer = Gtk3::TextBuffer->new(); | ||
| 5747 | $textView->set_buffer($buffer); | ||
| 5748 | |||
| 5749 | if (! $editFlag) { | ||
| 5750 | |||
| 5751 | $textView->set_editable(FALSE); | ||
| 5752 | $textView->set_cursor_visible(FALSE); | ||
| 5753 | $textView->set_can_focus(FALSE); | ||
| 5754 | |||
| 5755 | } else { | ||
| 5756 | |||
| 5757 | $textView->set_editable(TRUE); | ||
| 5758 | $textView->set_cursor_visible(TRUE); | ||
| 5759 | $textView->set_can_focus(TRUE); | ||
| 5760 | } | ||
| 5761 | |||
| 5762 | $textView->set_wrap_mode('word-char'); # Wrap words if possible, characters if not | ||
| 5763 | $textView->set_justification('left'); | ||
| 5764 | |||
| 5765 | if ($systemFlag && $axmud::CLIENT->ivExists('colourSchemeHash', $colourScheme)) { | ||
| 5766 | $axmud::CLIENT->desktopObj->setTextViewStyle($colourScheme, $textView); | ||
| 5767 | } else { | ||
| 5768 | $axmud::CLIENT->desktopObj->setTextViewStyle($self->winObj->winType, $textView); | ||
| 5769 | } | ||
| 5770 | |||
| 5771 | $buffer->set_text($text); | ||
| 5772 | |||
| 5773 | # Set expansion | ||
| 5774 | $textView->set_hexpand($hExpandFlag); | ||
| 5775 | $textView->set_vexpand($vExpandFlag); | ||
| 5776 | |||
| 5777 | # Update IVs | ||
| 5778 | $self->ivPoke('funcRef', $funcRef); | ||
| 5779 | $self->ivPoke('funcID', $funcID); | ||
| 5780 | $self->ivPoke('packingBox', $packingBox); | ||
| 5781 | $self->ivPoke('packingBox2', $packingBox2); | ||
| 5782 | $self->ivPoke('frame', $frame); | ||
| 5783 | $self->ivPoke('scroll', $scroll); | ||
| 5784 | $self->ivPoke('textView', $textView); | ||
| 5785 | $self->ivPoke('buffer', $buffer); | ||
| 5786 | |||
| 5787 | # Set up ->signal_connects | ||
| 5788 | $self->setChangedEvent(); | ||
| 5789 | |||
| 5790 | return 1; | ||
| 5791 | } | ||
| 5792 | |||
| 5793 | # sub objDestroy { # Inherited from GA::Generic::Table | ||
| 5794 | |||
| 5795 | # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table | ||
| 5796 | |||
| 5797 | # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table | ||
| 5798 | |||
| 5799 | # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table | ||
| 5800 | |||
| 5801 | # ->signal_connects | ||
| 5802 | |||
| 5803 | sub setChangedEvent { | ||
| 5804 | |||
| 5805 | # Called by $self->objEnable | ||
| 5806 | # | ||
| 5807 | # Expected arguments | ||
| 5808 | # (none besides $self) | ||
| 5809 | # | ||
| 5810 | # Return values | ||
| 5811 | # 'undef' on improper arguments | ||
| 5812 | # 1 otherwise | ||
| 5813 | |||
| 5814 | my ($self, $check) = @_; | ||
| 5815 | |||
| 5816 | # Check for improper arguments | ||
| 5817 | if (defined $check) { | ||
| 5818 | |||
| 5819 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setChangedEvent', @_); | ||
| 5820 | } | ||
| 5821 | |||
| 5822 | $self->buffer->signal_connect('changed' => sub { | ||
| 5823 | |||
| 5824 | my $currentFuncRef = $self->funcRef; | ||
| 5825 | |||
| 5826 | if ($currentFuncRef) { | ||
| 5827 | |||
| 5828 | &$currentFuncRef( | ||
| 5829 | $self, | ||
| 5830 | $self->textView, | ||
| 5831 | $self->buffer, | ||
| 5832 | $self->funcID, | ||
| 5833 | $axmud::CLIENT->desktopObj->bufferGetText($self->buffer), | ||
| 5834 | ); | ||
| 5835 | } | ||
| 5836 | }); | ||
| 5837 | |||
| 5838 | return 1; | ||
| 5839 | } | ||
| 5840 | |||
| 5841 | # Other functions | ||
| 5842 | |||
| 5843 | ################## | ||
| 5844 | # Accessors - set | ||
| 5845 | |||
| 5846 | sub set_editable { | ||
| 5847 | |||
| 5848 | my ($self, $flag, $check) = @_; | ||
| 5849 | |||
| 5850 | # Check for improper arguments | ||
| 5851 | if (defined $check) { | ||
| 5852 | |||
| 5853 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_editable', @_); | ||
| 5854 | } | ||
| 5855 | |||
| 5856 | if (! $flag) { | ||
| 5857 | |||
| 5858 | $self->textView->set_editable(FALSE); | ||
| 5859 | $self->textView->set_cursor_visible(FALSE); | ||
| 5860 | $self->textView->set_can_focus(FALSE); | ||
| 5861 | |||
| 5862 | } else { | ||
| 5863 | |||
| 5864 | $self->textView->set_editable(TRUE); | ||
| 5865 | $self->textView->set_cursor_visible(TRUE); | ||
| 5866 | $self->textView->set_can_focus(TRUE); | ||
| 5867 | } | ||
| 5868 | |||
| 5869 | return 1; | ||
| 5870 | } | ||
| 5871 | |||
| 5872 | # sub set_func {} # Inherited from GA::Generic::Table | ||
| 5873 | |||
| 5874 | # sub set_id {} # Inherited from GA::Generic::Table | ||
| 5875 | |||
| 5876 | sub set_text { | ||
| 5877 | |||
| 5878 | my ($self, $text, $check) = @_; | ||
| 5879 | |||
| 5880 | # Check for improper arguments | ||
| 5881 | if (defined $check) { | ||
| 5882 | |||
| 5883 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_text', @_); | ||
| 5884 | } | ||
| 5885 | |||
| 5886 | if (! defined $text) { | ||
| 5887 | |||
| 5888 | $text = ''; | ||
| 5889 | } | ||
| 5890 | |||
| 5891 | $self->buffer->set_text($text); | ||
| 5892 | |||
| 5893 | return 1; | ||
| 5894 | } | ||
| 5895 | |||
| 5896 | sub insert_text { | ||
| 5897 | |||
| 5898 | my ($self, $text, $check) = @_; | ||
| 5899 | |||
| 5900 | # Check for improper arguments | ||
| 5901 | if (defined $check) { | ||
| 5902 | |||
| 5903 | return $axmud::CLIENT->writeImproper($self->_objClass . '->insert_text_at_cursor', @_); | ||
| 5904 | } | ||
| 5905 | |||
| 5906 | if (! defined $text) { | ||
| 5907 | |||
| 5908 | $text = ''; | ||
| 5909 | } | ||
| 5910 | |||
| 5911 | $self->buffer->insert_at_cursor ($text); | ||
| 5912 | |||
| 5913 | return 1; | ||
| 5914 | } | ||
| 5915 | |||
| 5916 | # (Get equivalents) | ||
| 5917 | |||
| 5918 | sub get_editable { | ||
| 5919 | |||
| 5920 | my ($self, $check) = @_; | ||
| 5921 | |||
| 5922 | # Check for improper arguments | ||
| 5923 | if (defined $check) { | ||
| 5924 | |||
| 5925 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_editable', @_); | ||
| 5926 | } | ||
| 5927 | |||
| 5928 | if ($self->textView->get_editable()) { | ||
| 5929 | return TRUE; | ||
| 5930 | } else { | ||
| 5931 | return FALSE; | ||
| 5932 | } | ||
| 5933 | } | ||
| 5934 | |||
| 5935 | sub get_text { | ||
| 5936 | |||
| 5937 | my ($self, $check) = @_; | ||
| 5938 | |||
| 5939 | # Check for improper arguments | ||
| 5940 | if (defined $check) { | ||
| 5941 | |||
| 5942 | return $axmud::CLIENT->writeImproper($self->_objClass . '->get_text', @_); | ||
| 5943 | } | ||
| 5944 | |||
| 5945 | return $axmud::CLIENT->desktopObj->bufferGetText($self->buffer); | ||
| 5946 | } | ||
| 5947 | |||
| 5948 | ################## | ||
| 5949 | # Accessors - get | ||
| 5950 | |||
| 5951 | sub frame | ||
| 5952 | { $_[0]->{frame} } | ||
| 5953 | sub scroll | ||
| 5954 | { $_[0]->{scroll} } | ||
| 5955 | sub textView | ||
| 5956 | { $_[0]->{textView} } | ||
| 5957 | sub buffer | ||
| 5958 | { $_[0]->{buffer} } | ||
| 5959 | } | ||
| 5960 | |||
| 5961 | # Complex table objects | ||
| 5962 | |||
| 5963 | { package Games::Axmud::Table::Pane; | ||
| 5964 | |||
| 5965 | use strict; | ||
| 5966 | use warnings; | ||
| 5967 | # use diagnostics; | ||
| 5968 | |||
| 5969 | use Glib qw(TRUE FALSE); | ||
| 5970 | |||
| 5971 | our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud); | ||
| 5972 | |||
| 5973 | ################## | ||
| 5974 | # Constructors | ||
| 5975 | |||
| 5976 | sub new { | ||
| 5977 | |||
| 5978 | # Called by GA::Strip::Table->addTableObj | ||
| 5979 | # Creates the GA::Table::Pane, which contains one or more Gtk3::TextViews sharing a single | ||
| 5980 | # Gtk3::TextBuffer | ||
| 5981 | # | ||
| 5982 | # Expected arguments | ||
| 5983 | # $number - The table object's number within the parent strip object (matches | ||
| 5984 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object | ||
| 5985 | # created to access its default IVs) | ||
| 5986 | # $name - A name for the table object. Can be any string or, if no name was | ||
| 5987 | # specified in the call to the calling function, $name is the same as | ||
| 5988 | # $number. (No part of the code checks that table object names are unique; | ||
| 5989 | # if two or more table objects share the same ->name, usually the one with | ||
| 5990 | # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16 | ||
| 5991 | # chars) | ||
| 5992 | # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table | ||
| 5993 | # objects | ||
| 5994 | # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the | ||
| 5995 | # parent strip object's Gtk3::Grid for use exclusively by this table | ||
| 5996 | # object. 'temp' for temporary table objects | ||
| 5997 | # | ||
| 5998 | # Optional arguments | ||
| 5999 | # %initHash - A hash containing arbitrary data to use as the table object's | ||
| 6000 | # initialisation settings. The table object should use default | ||
| 6001 | # initialisation settings unless it can succesfully interpret one or more | ||
| 6002 | # of the key-value pairs in the hash, if there are any | ||
| 6003 | # - This type of table object recognises these initialisation settings: | ||
| 6004 | # | ||
| 6005 | # 'frame_title' - If specified, the table object is drawn inside a frame | ||
| 6006 | # with the specified title. If 'undef', an empty string or not | ||
| 6007 | # specified, the table object does not use a frame and title | ||
| 6008 | # 'entry_flag' - TRUE if a Gtk3::Entry should be drawn beneath the | ||
| 6009 | # textview(s), FALSE if not. Ignored if 'func' is not also specified | ||
| 6010 | # 'func' - Reference to a function to call when the user types something | ||
| 6011 | # in the pane's own entry box and presses 'return'. If not specified | ||
| 6012 | # or 'undef', it's up to the calling code to create its own | ||
| 6013 | # ->signal_connect. Ignored if 'entry_flag' is FALSE. To obtain a | ||
| 6014 | # reference to an OOP method, you can use the generic object function | ||
| 6015 | # Games::Axmud->getMethodRef() | ||
| 6016 | # 'id' - A value passed to the function which identifies this pane. If | ||
| 6017 | # specified, can be any value except 'undef'. It's up to the | ||
| 6018 | # calling code to keep track of the widgets it has created and their | ||
| 6019 | # corresponding 'id' values | ||
| 6020 | # 'switch_func' - Reference to a function to call when a tab becomes the | ||
| 6021 | # visible one (including when it is created). Not required for | ||
| 6022 | # sessions using this pane object for their default tabs, as the | ||
| 6023 | # code checks for that separately | ||
| 6024 | # 'switch_id' - A value passed to the function which identifies this | ||
| 6025 | # pane. If specified, can be any value except 'undef'. It's up to the | ||
| 6026 | # calling code to keep track of the widgets it has created and their | ||
| 6027 | # corresponding 'id' values | ||
| 6028 | # 'close_func' - Reference to a function to call when a tab is closed. Not | ||
| 6029 | # required for sessions using this pane object for their default tabs, | ||
| 6030 | # as the code checks for that separately | ||
| 6031 | # 'close_id' - A value passed to the function which identifies this | ||
| 6032 | # pane. If specified, can be any value except 'undef'. It's up to the | ||
| 6033 | # calling code to keep track of the widgets it has created and their | ||
| 6034 | # corresponding 'id' values | ||
| 6035 | # 'can_close_flag' - TRUE if tabs with labels also have a small button for | ||
| 6036 | # closing the tab, FALSE (or 'undef') if not. Ignored for 'simple' | ||
| 6037 | # tabs which have no label | ||
| 6038 | # 'split_mode' - 'single' if split screen mode is off, 'split' or 'hidden' | ||
| 6039 | # if split screen mode is on (for 'hidden', the divider is initially | ||
| 6040 | # positioned at the top of the screen). If not specified or an | ||
| 6041 | # unrecognised value, 'single' is used | ||
| 6042 | # 'colour_scheme' - The name of a colour scheme to use in this pane's | ||
| 6043 | # textviews (if the colour scheme is updated, so are the colours and | ||
| 6044 | # fonts used in the textviews). If not specified or if the named | ||
| 6045 | # colour scheme doesn't exist, uses the colour scheme named after the | ||
| 6046 | # window type | ||
| 6047 | # 'max_lines' - The maximum number of lines for the textview buffer. If | ||
| 6048 | # specified, must be 0 (meaning no maximum; not recommended) or a | ||
| 6049 | # positive integer between GA::Client->constMinBufferSize and | ||
| 6050 | # ->constMaxBufferSize (inclusive) | ||
| 6051 | # 'new_line' - The default behaviour when a string is inserted into the | ||
| 6052 | # tab's textview: 'before' prepends a newline character to the string, | ||
| 6053 | # 'after' prepends a newline character after the string, 'echo' does | ||
| 6054 | # not prepend/a newline character by default. If 'undef' or an | ||
| 6055 | # unrecognised value, 'after' is used | ||
| 6056 | # | ||
| 6057 | # Return values | ||
| 6058 | # 'undef' on improper arguments | ||
| 6059 | # Blessed reference to the newly-created object on success | ||
| 6060 | |||
| 6061 | my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_; | ||
| 6062 | |||
| 6063 | # Local variables | ||
| 6064 | my ( | ||
| 6065 | $winObj, $colourScheme, | ||
| 6066 | %modHash, | ||
| 6067 | ); | ||
| 6068 | |||
| 6069 | # Check for improper arguments | ||
| 6070 | if ( | ||
| 6071 | ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj | ||
| 6072 | || ! defined $zoneObj | ||
| 6073 | ) { | ||
| 6074 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 6075 | } | ||
| 6076 | |||
| 6077 | # Deal with temporary table objects | ||
| 6078 | if ($stripObj eq 'temp') { | ||
| 6079 | $winObj = 'temp'; | ||
| 6080 | } else { | ||
| 6081 | $winObj = $stripObj->winObj; | ||
| 6082 | } | ||
| 6083 | |||
| 6084 | # Default initialisation settings | ||
| 6085 | if ( | ||
| 6086 | $number != -1 | ||
| 6087 | && (! $colourScheme || ! $axmud::CLIENT->ivShow('colourSchemeHash', $colourScheme)) | ||
| 6088 | ) { | ||
| 6089 | $colourScheme = $stripObj->winObj->winType; | ||
| 6090 | } | ||
| 6091 | |||
| 6092 | %modHash = ( | ||
| 6093 | 'frame_title' => undef, | ||
| 6094 | 'entry_flag' => FALSE, | ||
| 6095 | 'func' => undef, | ||
| 6096 | 'id' => '', | ||
| 6097 | 'switch_func' => undef, | ||
| 6098 | 'switch_id' => '', | ||
| 6099 | 'close_func' => undef, | ||
| 6100 | 'close_id' => '', | ||
| 6101 | 'can_close_flag' => TRUE, | ||
| 6102 | 'split_mode' => 'single', | ||
| 6103 | 'colour_scheme' => $colourScheme, | ||
| 6104 | 'max_lines' => $axmud::CLIENT->customTextBufferSize, | ||
| 6105 | 'new_line' => 'after', | ||
| 6106 | ); | ||
| 6107 | |||
| 6108 | # Interpret the initialisation settings in %initHash, if any | ||
| 6109 | foreach my $key (keys %modHash) { | ||
| 6110 | |||
| 6111 | if (exists $initHash{$key}) { | ||
| 6112 | |||
| 6113 | if ($key =~ m/flag$/) { | ||
| 6114 | |||
| 6115 | if ($initHash{$key}) { | ||
| 6116 | $modHash{$key} = TRUE; | ||
| 6117 | } else { | ||
| 6118 | $modHash{$key} = FALSE; | ||
| 6119 | } | ||
| 6120 | |||
| 6121 | } elsif ($key eq 'max_lines') { | ||
| 6122 | |||
| 6123 | if ( | ||
| 6124 | $initHash{$key} == 0 | ||
| 6125 | || ( | ||
| 6126 | $initHash{$key} >= $axmud::CLIENT->constMinBufferSize | ||
| 6127 | && $initHash{$key} <= $axmud::CLIENT->constMaxBufferSize | ||
| 6128 | ) | ||
| 6129 | ) { | ||
| 6130 | $modHash{$key} = $initHash{$key}; | ||
| 6131 | } | ||
| 6132 | |||
| 6133 | } elsif ( | ||
| 6134 | ($key eq 'id' || $key eq 'switch_id' || $key eq 'close_id') | ||
| 6135 | && ! defined $initHash{$key} | ||
| 6136 | ) { | ||
| 6137 | $modHash{$key} = ''; # 'id' value must not be 'undef' | ||
| 6138 | |||
| 6139 | } elsif ( | ||
| 6140 | $key eq 'split_mode' | ||
| 6141 | && ( | ||
| 6142 | $initHash{$key} eq 'single' || $initHash{$key} eq 'split' | ||
| 6143 | || $initHash{$key} eq 'hidden' | ||
| 6144 | ) | ||
| 6145 | ) { | ||
| 6146 | $modHash{$key} = $initHash{$key}; | ||
| 6147 | |||
| 6148 | } elsif ( | ||
| 6149 | $key eq 'new_line' | ||
| 6150 | && defined $initHash{$key} | ||
| 6151 | && ($initHash{$key} eq 'echo' || $initHash{$key} eq 'before') | ||
| 6152 | ) { | ||
| 6153 | $modHash{$key} = $initHash{$key}; | ||
| 6154 | |||
| 6155 | } else { | ||
| 6156 | |||
| 6157 | $modHash{$key} = $initHash{$key}; | ||
| 6158 | } | ||
| 6159 | } | ||
| 6160 | } | ||
| 6161 | |||
| 6162 | # Setup | ||
| 6163 | my $self = { | ||
| 6164 | _objName => 'table_obj_' . $number, | ||
| 6165 | _objClass => $class, | ||
| 6166 | _parentFile => undef, # No parent file object | ||
| 6167 | _parentWorld => undef, # No parent file object | ||
| 6168 | _privFlag => TRUE, # All IVs are private | ||
| 6169 | |||
| 6170 | # Standard table object IVs | ||
| 6171 | # ------------------------- | ||
| 6172 | |||
| 6173 | # The table object's number within the parent strip object (matches | ||
| 6174 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to | ||
| 6175 | # access its default IVs) | ||
| 6176 | number => $number, | ||
| 6177 | # A name for the table object. Can be any string or, if no name was specified in the | ||
| 6178 | # call to the calling function, $name is the same as $number. (No part of the code | ||
| 6179 | # checks that table object names are unique; if two or more table objects share the | ||
| 6180 | # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary | ||
| 6181 | # table objects. Max 16 chars) | ||
| 6182 | name => $name, | ||
| 6183 | # The type of table object (custom table objects should use a ->type starting with | ||
| 6184 | # 'custom_' to avoid clashing with future built-in table objects) | ||
| 6185 | type => 'pane', | ||
| 6186 | # The parent strip object (GA::Strip::Table) | ||
| 6187 | stripObj => $stripObj, | ||
| 6188 | # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for | ||
| 6189 | # temporary table objects | ||
| 6190 | winObj => $winObj, | ||
| 6191 | # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip | ||
| 6192 | # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary | ||
| 6193 | # table objects | ||
| 6194 | zoneObj => $zoneObj, | ||
| 6195 | |||
| 6196 | # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is | ||
| 6197 | # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as | ||
| 6198 | # when a connection to a world terminates) | ||
| 6199 | allowRemoveFlag => TRUE, | ||
| 6200 | # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is | ||
| 6201 | # created. Set to FALSE if it can't be resized | ||
| 6202 | allowResizeFlag => TRUE, | ||
| 6203 | # Initialisation settings stored as a hash (see the comments above) | ||
| 6204 | initHash => \%modHash, | ||
| 6205 | # Reference to a function to call when some widget is used. This IV is set only when | ||
| 6206 | # required by this type of table object. It can be set by a call to | ||
| 6207 | # $self->set_func() or by some setting in $self->initHash, which is applied in the | ||
| 6208 | # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the | ||
| 6209 | # generic object function Games::Axmud->getMethodRef() | ||
| 6210 | funcRef => undef, | ||
| 6211 | # A value passed to ->funcRef when it is called which identifies this table object and | ||
| 6212 | # its widget(s). Can be any value except 'undef'. It can be set by a call to | ||
| 6213 | # $self->set_id() or by some setting in $self->initHash, which is applied in the call | ||
| 6214 | # to $self->objEnable() | ||
| 6215 | funcID => '', | ||
| 6216 | |||
| 6217 | # The container widget(s) for this table object | ||
| 6218 | packingBox => undef, # Gtk3::VBox or Gtk3::Frame | ||
| 6219 | packingBox2 => undef, # Gtk3::VBox | ||
| 6220 | |||
| 6221 | # Other IVs | ||
| 6222 | # --------- | ||
| 6223 | |||
| 6224 | # Widgets | ||
| 6225 | notebook => undef, # Gtk3::Notebook | ||
| 6226 | hBox => undef, # Gtk3::HBox | ||
| 6227 | entry => undef, # Gtk3::Entry | ||
| 6228 | |||
| 6229 | # The normal and modified border widths to apply to $self->packingBox2 when this pane is | ||
| 6230 | # selected and unselected by the switcher button in | ||
| 6231 | # GA::Strip::Entry->setSwitchSignals | ||
| 6232 | normalBorderWidth => 0, | ||
| 6233 | selectBorderWidth => 5, | ||
| 6234 | |||
| 6235 | # Hashes of tabs and their corresponding tab objects (GA::Obj::Tab), which store the | ||
| 6236 | # widgets required to create, modify or remove each tab | ||
| 6237 | # Every tab contains a single textview object (GA::Obj::TextView). A textview object | ||
| 6238 | # handles either a single Gtk3::TextView, or two Gtk3::TextViews sharing a single | ||
| 6239 | # Gtk3::TextBuffer (depending on whether split screen mode is off or on) | ||
| 6240 | # The tab object stores that textview object, the controlling session (GA::Session) | ||
| 6241 | # and details of which Gtk3 widgets to pack/unpack when the appearance of the tab is | ||
| 6242 | # modified | ||
| 6243 | # | ||
| 6244 | # When a Gtk3::Notebook is in use, the Gtk3 inheritance tree looks like this: | ||
| 6245 | # Gtk3::VBox ($self->packingBox, ->packingBox2) | ||
| 6246 | # Gtk3::Notebook | ||
| 6247 | # Gtk3::VBox ($tabObj->packableObj) | ||
| 6248 | # Gtk3::ScrolledWindow ($tabObj->packedObj) | ||
| 6249 | # Gtk3::TextView ($tabObj->textViewObj->textView) | ||
| 6250 | # ...or like this, when split screen mode is on: | ||
| 6251 | # Gtk3::VBox ($self->packingBox, ->packingBox2) | ||
| 6252 | # Gtk3::Notebook | ||
| 6253 | # Gtk3::VBox ($tabObj->packableObj) | ||
| 6254 | # Gtk3::VPaned ($tabObj->packedObj) | ||
| 6255 | # Gtk3::Scroll | ||
| 6256 | # Gtk3::TextView ($tabObj->textViewObj->textView) | ||
| 6257 | # Gtk3::Scroll | ||
| 6258 | # Gtk3::TextView ($tabObj->textViewObj->textView2) | ||
| 6259 | # ..and the hash in the form | ||
| 6260 | # $tabObjHash{unique_number} = blessed_reference_to_tab_object | ||
| 6261 | # | ||
| 6262 | # When a Gtk3::Notebook is not in use, the comments in this table object describe a | ||
| 6263 | # 'simple tab'. In actuality, the simplified inheritance tree looks like this: | ||
| 6264 | # Gtk3::VBox ($self->packingBox, ->packingBox2) | ||
| 6265 | # Gtk3::ScrolledWindow ($tabObj->packedObj) | ||
| 6266 | # Gtk3::TextView ($tabObj->textViewObj->textView) | ||
| 6267 | # ...or like this, when split screen mode is on: | ||
| 6268 | # Gtk3::VBox ($self->packingBox, ->packingBox2) | ||
| 6269 | # Gtk3::VPaned ($tabObj->packedObj) | ||
| 6270 | # Gtk3::ScrolledWindow | ||
| 6271 | # Gtk3::TextView ($tabObj->textViewObj->textView) | ||
| 6272 | # Gtk3::ScrolledWindow | ||
| 6273 | # Gtk3::TextView ($tabObj->textViewObj->textView2) | ||
| 6274 | # ...and the hash contains a single key-value pair, in the form | ||
| 6275 | # $tabObjHash{0} = blessed_reference_to_tab_object | ||
| 6276 | # | ||
| 6277 | # NB If a 'frame_title' was specified by the calling function, $self->packingBox will | ||
| 6278 | # be a Gtk3::Frame, and $self->packingBox2 will be a Gtk3::VBox. If not, both | ||
| 6279 | # $self->packingBox and ->packingBox2 will be the same Gtk3::VBox widget | ||
| 6280 | tabObjHash => {}, | ||
| 6281 | # Number of tab objects created since this pane object was created (used to give each | ||
| 6282 | # tab object a unique number). When converting from a simple tab to (normal) tabs, or | ||
| 6283 | # vice-versa, ->tabObjHash is emptied and ->tabObjCount is reset | ||
| 6284 | tabObjCount => 0, | ||
| 6285 | # The visible tab object; set by $self->respondVisibleTab when the visible tab actually | ||
| 6286 | # changes | ||
| 6287 | currentTabObj => undef, | ||
| 6288 | # When a simple tab is created, this flag is set to TRUE. If a second tab is added, the | ||
| 6289 | # existing simple tab is converted into a normal tab, and this flag is unchanged. If | ||
| 6290 | # tabs are removed and there's only one tab left, that tab is converted into a simple | ||
| 6291 | # tab if this flag is TRUE. When there are no tabs left, the flag is set back to | ||
| 6292 | # FALSE | ||
| 6293 | # In that way, whether the pane uses simple tabs or not depends entirely on the calling | ||
| 6294 | # code, which can create its first tab through a call ->addSimpleTab or ->addTab | ||
| 6295 | simpleTabFlag => FALSE, | ||
| 6296 | # Flag set to TRUE while $self->convertSimpleTab and ->convertTab are in progress, so | ||
| 6297 | # that various ->signal_connects know not to take action | ||
| 6298 | tabConvertFlag => FALSE, | ||
| 6299 | # Flag set to TRUE if tabs with labels also have a small button for closing the tab, | ||
| 6300 | # FALSE if not. Ignored for 'simple' tabs which have no label | ||
| 6301 | # If modified via a call to $self->set_canCloseFlag, the new setting will only be | ||
| 6302 | # applied to tabs opened after that | ||
| 6303 | canCloseFlag => TRUE, | ||
| 6304 | |||
| 6305 | # Reference to a function to call when a tab becomes the visible one (including when it | ||
| 6306 | # is created). Not required for sessions using this pane object for their default | ||
| 6307 | # tabs, as the code checks for that separately | ||
| 6308 | switchFuncRef => undef, | ||
| 6309 | # A value passed to the $self->switchFuncRef which identifies this pane. If specified, | ||
| 6310 | # can be any value except 'undef'. It's up to the calling code to keep track of the | ||
| 6311 | # widgets it has created and their corresponding 'id' values | ||
| 6312 | switchFuncID => '', | ||
| 6313 | # Reference to a function to call when a tab is closed. Not required for sessions using | ||
| 6314 | # this pane object for their default tabs, as the code checks for that separately | ||
| 6315 | closeFuncRef => undef, | ||
| 6316 | # A value passed to the $self->closeFuncRef which identifies this pane. If specified, | ||
| 6317 | # can be any value except 'undef'. It's up to the calling code to keep track of the | ||
| 6318 | # widgets it has created and their corresponding 'id' values | ||
| 6319 | closeFuncID => '', | ||
| 6320 | }; | ||
| 6321 | |||
| 6322 | # Bless the object into existence | ||
| 6323 | bless $self, $class; | ||
| 6324 | |||
| 6325 | return $self; | ||
| 6326 | } | ||
| 6327 | |||
| 6328 | ################## | ||
| 6329 | # Methods | ||
| 6330 | |||
| 6331 | # Standard table object functions | ||
| 6332 | |||
| 6333 | sub objEnable { | ||
| 6334 | |||
| 6335 | # Called by GA::Strip::Table->addTableObj | ||
| 6336 | # Sets up the table object's widgets | ||
| 6337 | # | ||
| 6338 | # Expected arguments | ||
| 6339 | # (none besides $self) | ||
| 6340 | # | ||
| 6341 | # Return values | ||
| 6342 | # 'undef' on improper arguments | ||
| 6343 | # 1 on success | ||
| 6344 | |||
| 6345 | my ($self, $check) = @_; | ||
| 6346 | |||
| 6347 | # Check for improper arguments | ||
| 6348 | if (defined $check) { | ||
| 6349 | |||
| 6350 | return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_); | ||
| 6351 | } | ||
| 6352 | |||
| 6353 | # Create packing box(es) | ||
| 6354 | my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::VBox->new(FALSE, 0)); | ||
| 6355 | $packingBox2->set_border_width($self->normalBorderWidth); | ||
| 6356 | |||
| 6357 | # Draw a Gtk3::Entry, if specified | ||
| 6358 | my ($hBox, $entry); | ||
| 6359 | if ( | ||
| 6360 | $self->ivShow('initHash', 'entry_flag') | ||
| 6361 | && $self->ivShow('initHash', 'func') | ||
| 6362 | ) { | ||
| 6363 | $hBox = Gtk3::HBox->new(FALSE, 0); | ||
| 6364 | $packingBox2->pack_end($hBox, FALSE, FALSE, $axmud::CLIENT->constGridSpacingPixels); | ||
| 6365 | |||
| 6366 | $entry = Gtk3::Entry->new(); | ||
| 6367 | $hBox->pack_start($entry, TRUE, TRUE, $axmud::CLIENT->constGridSpacingPixels); | ||
| 6368 | } | ||
| 6369 | |||
| 6370 | # Set expansion | ||
| 6371 | $packingBox->set_hexpand(TRUE); | ||
| 6372 | $packingBox->set_vexpand(TRUE); | ||
| 6373 | |||
| 6374 | # Update IVs | ||
| 6375 | $self->ivPoke('funcRef', $self->ivShow('initHash', 'func')); | ||
| 6376 | $self->ivPoke('funcID', $self->ivShow('initHash', 'id')); | ||
| 6377 | $self->ivPoke('packingBox', $packingBox); | ||
| 6378 | $self->ivPoke('packingBox2', $packingBox2); | ||
| 6379 | $self->ivPoke('hBox', $hBox); | ||
| 6380 | $self->ivPoke('entry', $entry); | ||
| 6381 | |||
| 6382 | if ($self->ivShow('initHash', 'can_close_flag')) { | ||
| 6383 | $self->ivPoke('canCloseFlag', TRUE); | ||
| 6384 | } else { | ||
| 6385 | $self->ivPoke('canCloseFlag', FALSE); | ||
| 6386 | } | ||
| 6387 | |||
| 6388 | $self->ivPoke('switchFuncRef', $self->ivShow('initHash', 'switch_func')); | ||
| 6389 | $self->ivPoke('switchFuncID', $self->ivShow('initHash', 'switch_id')); | ||
| 6390 | $self->ivPoke('closeFuncRef', $self->ivShow('initHash', 'close_func')); | ||
| 6391 | $self->ivPoke('closeFuncID', $self->ivShow('initHash', 'close_id')); | ||
| 6392 | |||
| 6393 | # Set up ->signal_connects | ||
| 6394 | if ($self->entry) { | ||
| 6395 | |||
| 6396 | $self->setActivateEvent(); | ||
| 6397 | } | ||
| 6398 | |||
| 6399 | return 1; | ||
| 6400 | } | ||
| 6401 | |||
| 6402 | sub objDestroy { | ||
| 6403 | |||
| 6404 | # Called by GA::Strip::Table->objDestroy, just before that strip is removed from its parent | ||
| 6405 | # window, to give this object a chance to do any necessary tidying up | ||
| 6406 | # Generic function that can be inherited by any table object that doesn't need to do any | ||
| 6407 | # tidying up | ||
| 6408 | # | ||
| 6409 | # Expected arguments | ||
| 6410 | # (none besides $self) | ||
| 6411 | # | ||
| 6412 | # Return values | ||
| 6413 | # 'undef' on improper arguments | ||
| 6414 | # 1 otherwise | ||
| 6415 | |||
| 6416 | my ($self, $check) = @_; | ||
| 6417 | |||
| 6418 | # Check for improper arguments | ||
| 6419 | if (defined $check) { | ||
| 6420 | |||
| 6421 | return $axmud::CLIENT->writeImproper($self->_objClass . '->objDestroy', @_); | ||
| 6422 | } | ||
| 6423 | |||
| 6424 | # Tidy up any textview objects | ||
| 6425 | foreach my $tabObj ($self->ivValues('tabObjHash')) { | ||
| 6426 | |||
| 6427 | $tabObj->textViewObj->objDestroy(); | ||
| 6428 | } | ||
| 6429 | |||
| 6430 | return 1; | ||
| 6431 | } | ||
| 6432 | |||
| 6433 | # sub setWidgetsIfSession {} | ||
| 6434 | |||
| 6435 | # sub setWidgetsChangeSession {} | ||
| 6436 | |||
| 6437 | sub setWidgetsOnResize { | ||
| 6438 | |||
| 6439 | # Called by GA::Strip::Table->resizeTableObj | ||
| 6440 | # Allows this table object to update its widgets whenever the table object is resized on its | ||
| 6441 | # Gtk3::Grid | ||
| 6442 | # | ||
| 6443 | # Expected arguments | ||
| 6444 | # $left, $right, $top, $bottom | ||
| 6445 | # - The coordinates of the top-left ($left, $top) and bottom-right ($right, $bottom) | ||
| 6446 | # corners of the table object on the table after the resize | ||
| 6447 | # | ||
| 6448 | # Return values | ||
| 6449 | # 'undef' on improper arguments | ||
| 6450 | # 1 otherwise | ||
| 6451 | |||
| 6452 | my ($self, $left, $right, $top, $bottom, $check) = @_; | ||
| 6453 | |||
| 6454 | # Check for improper arguments | ||
| 6455 | if ( | ||
| 6456 | ! defined $left || ! defined $right || ! defined $top || ! defined $bottom | ||
| 6457 | || defined $check | ||
| 6458 | ) { | ||
| 6459 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setWidgetsOnResize', @_); | ||
| 6460 | } | ||
| 6461 | |||
| 6462 | # For some reason, resizing the table object makes the Gtk3::TextView use the most recent | ||
| 6463 | # rc file, which messes up the colours; therefore, we have to re-apply the colour scheme | ||
| 6464 | # for each tab | ||
| 6465 | $self->updateColourScheme(); | ||
| 6466 | |||
| 6467 | return 1; | ||
| 6468 | } | ||
| 6469 | |||
| 6470 | # ->signal_connects | ||
| 6471 | |||
| 6472 | sub setSwitchPageEvent { | ||
| 6473 | |||
| 6474 | # Called by $self->drawNotebook | ||
| 6475 | # | ||
| 6476 | # Expected arguments | ||
| 6477 | # $notebook - The Gtk3::Notebook which emits the signal | ||
| 6478 | # | ||
| 6479 | # Return values | ||
| 6480 | # 'undef' on improper arguments | ||
| 6481 | # 1 otherwise | ||
| 6482 | |||
| 6483 | my ($self, $notebook, $check) = @_; | ||
| 6484 | |||
| 6485 | # Check for improper arguments | ||
| 6486 | if (! defined $notebook || defined $check) { | ||
| 6487 | |||
| 6488 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setSwitchPageEvent', @_); | ||
| 6489 | } | ||
| 6490 | |||
| 6491 | # This callback is intended to detect when the user clicks on one of the notebook's tabs, | ||
| 6492 | # making that tab visible | ||
| 6493 | $notebook->signal_connect('switch-page' => sub { | ||
| 6494 | |||
| 6495 | my ($widget, $num, $page) = @_; | ||
| 6496 | |||
| 6497 | my $tabObj = $self->findPage($page); | ||
| 6498 | if ($tabObj) { | ||
| 6499 | |||
| 6500 | $self->respondVisibleTab($tabObj); | ||
| 6501 | } | ||
| 6502 | }); | ||
| 6503 | |||
| 6504 | return 1; | ||
| 6505 | } | ||
| 6506 | |||
| 6507 | sub setButtonClicked { | ||
| 6508 | |||
| 6509 | # Called by $self->addTab | ||
| 6510 | # | ||
| 6511 | # Expected arguments | ||
| 6512 | # $button - The Gtk3::Button which emits the signal | ||
| 6513 | # $tabObj - The corresponding GA::Obj::Tab | ||
| 6514 | # | ||
| 6515 | # Optional arguments | ||
| 6516 | # $session - If the tab is a session's default tab, the GA::Session for the tab | ||
| 6517 | # | ||
| 6518 | # Return values | ||
| 6519 | # 'undef' on improper arguments | ||
| 6520 | # 1 otherwise | ||
| 6521 | |||
| 6522 | my ($self, $button, $tabObj, $session, $check) = @_; | ||
| 6523 | |||
| 6524 | # Check for improper arguments | ||
| 6525 | if (! defined $button || ! defined $tabObj || defined $check) { | ||
| 6526 | |||
| 6527 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setButtonClicked', @_); | ||
| 6528 | } | ||
| 6529 | |||
| 6530 | $button->signal_connect('clicked' => sub { | ||
| 6531 | |||
| 6532 | my $choice; | ||
| 6533 | |||
| 6534 | if ($session) { | ||
| 6535 | |||
| 6536 | if ($session->status eq 'connected' && $axmud::CLIENT->confirmCloseTabFlag) { | ||
| 6537 | |||
| 6538 | $choice = $self->winObj->showMsgDialogue( | ||
| 6539 | 'Close tab', | ||
| 6540 | 'question', | ||
| 6541 | 'This session is connected to a world. Are you sure you want to close it?', | ||
| 6542 | 'yes-no', | ||
| 6543 | ); | ||
| 6544 | |||
| 6545 | if ($choice && $choice eq 'yes') { | ||
| 6546 | |||
| 6547 | # ->stopSession calls this object's ->removeSessionTab | ||
| 6548 | $session->pseudoCmd('stopsession', $self->winObj->pseudoCmdMode); | ||
| 6549 | } | ||
| 6550 | |||
| 6551 | } else { | ||
| 6552 | |||
| 6553 | $session->pseudoCmd('stopsession', $self->winObj->pseudoCmdMode); | ||
| 6554 | } | ||
| 6555 | |||
| 6556 | } else { | ||
| 6557 | |||
| 6558 | # If this isn't a session's default tab, we can remove the tab directly | ||
| 6559 | $self->removeTab($tabObj); | ||
| 6560 | } | ||
| 6561 | }); | ||
| 6562 | |||
| 6563 | return 1; | ||
| 6564 | } | ||
| 6565 | |||
| 6566 | sub setActivateEvent { | ||
| 6567 | |||
| 6568 | # Called by $self->objEnable | ||
| 6569 | # | ||
| 6570 | # Expected arguments | ||
| 6571 | # (none besides $self) | ||
| 6572 | # | ||
| 6573 | # Return values | ||
| 6574 | # 'undef' on improper arguments | ||
| 6575 | # 1 otherwise | ||
| 6576 | |||
| 6577 | my ($self, $check) = @_; | ||
| 6578 | |||
| 6579 | # Check for improper arguments | ||
| 6580 | if (defined $check) { | ||
| 6581 | |||
| 6582 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setActivateEvent', @_); | ||
| 6583 | } | ||
| 6584 | |||
| 6585 | $self->entry->signal_connect('activate' => sub { | ||
| 6586 | |||
| 6587 | my ($value, $thisFuncRef); | ||
| 6588 | |||
| 6589 | $value = $self->entry->get_text(); | ||
| 6590 | $thisFuncRef = $self->funcRef; | ||
| 6591 | |||
| 6592 | if ($thisFuncRef) { | ||
| 6593 | |||
| 6594 | &$thisFuncRef($self, $self->entry, $self->funcID, $value); | ||
| 6595 | } | ||
| 6596 | |||
| 6597 | $self->entry->set_text(''); | ||
| 6598 | }); | ||
| 6599 | |||
| 6600 | return 1; | ||
| 6601 | } | ||
| 6602 | |||
| 6603 | # Other functions | ||
| 6604 | |||
| 6605 | sub drawNotebook { | ||
| 6606 | |||
| 6607 | # Called by $self->addTab and $self->convertSimpleTab | ||
| 6608 | # Draws a Gtk3::Notebook whose tabs can each contain a Gtk3::TextView | ||
| 6609 | # | ||
| 6610 | # Expected arguments | ||
| 6611 | # (none besides $self) | ||
| 6612 | # | ||
| 6613 | # Return values | ||
| 6614 | # 'undef' on improper arguments or if the widget can't be drawn | ||
| 6615 | # Otherwise returns the Gtk3::Notebook | ||
| 6616 | |||
| 6617 | my ($self, $check) = @_; | ||
| 6618 | |||
| 6619 | # Check for improper arguments | ||
| 6620 | if (defined $check) { | ||
| 6621 | |||
| 6622 | return $axmud::CLIENT->writeImproper($self->_objClass . '->drawNotebook', @_); | ||
| 6623 | } | ||
| 6624 | |||
| 6625 | # Create the notebook, stored in $self->notebook | ||
| 6626 | my $notebook = Gtk3::Notebook->new(); | ||
| 6627 | $notebook->set_scrollable(TRUE); | ||
| 6628 | $notebook->popup_enable(); | ||
| 6629 | $notebook->set_can_focus(FALSE); | ||
| 6630 | |||
| 6631 | # Gtk3::Notebook created | ||
| 6632 | $self->packingBox2->pack_start($notebook, TRUE, TRUE, 0); | ||
| 6633 | # Set up ->signal_connects | ||
| 6634 | $self->setSwitchPageEvent($notebook); | ||
| 6635 | |||
| 6636 | # Update IVs | ||
| 6637 | $self->ivPoke('notebook', $notebook); | ||
| 6638 | |||
| 6639 | return $notebook; | ||
| 6640 | } | ||
| 6641 | |||
| 6642 | sub addSimpleTab { | ||
| 6643 | |||
| 6644 | # Called by GA::Session->setDefaultTab, $self->convertTab or any other code | ||
| 6645 | # Adds a simple tab (containing a standalone textview object, not a page in a notebook) | ||
| 6646 | # | ||
| 6647 | # Expected arguments | ||
| 6648 | # $session - The GA::Session that will control the tab (and the textview object | ||
| 6649 | # it contains) | ||
| 6650 | # | ||
| 6651 | # Optional arguments | ||
| 6652 | # $colourScheme - If specified, the name of the colour scheme to use. If 'undef' (or if | ||
| 6653 | # the specified colour scheme doesn't exist), the colour scheme | ||
| 6654 | # specified by $self->initHash is used | ||
| 6655 | # $sessionFlag - Flag set to TRUE if this tab was called by | ||
| 6656 | # GA::Session->setDefaultTab, FALSE (or 'undef') if it was called by | ||
| 6657 | # anything else | ||
| 6658 | # $defaultFlag - Flag set to TRUE if this tab will be $session's default tab (where | ||
| 6659 | # text received from the world is usually displayed), FALSE (or | ||
| 6660 | # 'undef') otherwise (might be TRUE even if $sessionFlag is FALSE) | ||
| 6661 | # $labelText - The text to use in the tab label, ignored if specified (exists for | ||
| 6662 | # compatibility with other functions in this group) | ||
| 6663 | # $oldBuffer - If a Gtk3::Notebook with a single tab is being replaced by a | ||
| 6664 | # standalone textview object, the old textview object's | ||
| 6665 | # Gtk3::TextBuffer, which is transferred to the new textview object | ||
| 6666 | # ('undef' otherwise) | ||
| 6667 | # | ||
| 6668 | # Return values | ||
| 6669 | # 'undef' on improper arguments or if the simple tab can't be drawn | ||
| 6670 | # Otherwise returns the tab object (GA::Obj::Tab) created, which stores (among other | ||
| 6671 | # things) the textview object created | ||
| 6672 | |||
| 6673 | my ( | ||
| 6674 | $self, $session, $colourScheme, $sessionFlag, $defaultFlag, $labelText, $oldBuffer, | ||
| 6675 | $check, | ||
| 6676 | ) = @_; | ||
| 6677 | |||
| 6678 | # Local variables | ||
| 6679 | my ($textViewObj, $packedObj, $tabObj); | ||
| 6680 | |||
| 6681 | # Check for improper arguments | ||
| 6682 | if (! defined $session || defined $check) { | ||
| 6683 | |||
| 6684 | return $axmud::CLIENT->writeImproper($self->_objClass . '->addSimpleTab', @_); | ||
| 6685 | } | ||
| 6686 | |||
| 6687 | # If this pane object has drawn a notebook, not a simple container (a Gtk3::ScrolledWindow | ||
| 6688 | # or Gtk3::VPaned), $self->addTab should have been called instead. Show a warning, then | ||
| 6689 | # redirect the function call | ||
| 6690 | if ($self->notebook) { | ||
| 6691 | |||
| 6692 | $self->winObj->session->writeWarning( | ||
| 6693 | 'Tried to add a simple tab to a notebook; code should call ->addTab, not' | ||
| 6694 | . ' ->addSimpleTab', | ||
| 6695 | $self->_objClass . '->addSimpleTab', | ||
| 6696 | ); | ||
| 6697 | |||
| 6698 | return $self->addTab( | ||
| 6699 | $session, | ||
| 6700 | $colourScheme, | ||
| 6701 | $sessionFlag, | ||
| 6702 | $defaultFlag, | ||
| 6703 | $labelText, | ||
| 6704 | $oldBuffer, | ||
| 6705 | ); | ||
| 6706 | |||
| 6707 | # If there is already a simple tab, don't create another one | ||
| 6708 | } elsif ($self->tabObjHash) { | ||
| 6709 | |||
| 6710 | return $self->writeError( | ||
| 6711 | 'Tried to add a simple tab, but one or more tabs already exist', | ||
| 6712 | $self->_objClass . '->addSimpleTab', | ||
| 6713 | ); | ||
| 6714 | } | ||
| 6715 | |||
| 6716 | # Create a new GA::Obj::Textview object to handle the Gtk3::Textview(s) | ||
| 6717 | $textViewObj = $axmud::CLIENT->desktopObj->add_textView( | ||
| 6718 | $session, | ||
| 6719 | $self->winObj, | ||
| 6720 | $self, | ||
| 6721 | ); | ||
| 6722 | |||
| 6723 | if (! $textViewObj) { | ||
| 6724 | |||
| 6725 | return undef; | ||
| 6726 | } | ||
| 6727 | |||
| 6728 | # Set the colour scheme to use | ||
| 6729 | if ( | ||
| 6730 | ! defined $colourScheme | ||
| 6731 | || ! $axmud::CLIENT->ivExists('colourSchemeHash', $colourScheme) | ||
| 6732 | ) { | ||
| 6733 | $colourScheme = $self->ivShow('initHash', 'colour_scheme'); | ||
| 6734 | } | ||
| 6735 | |||
| 6736 | # Create the Gtk3::TextView(s) themselves. The function call returns a Gtk3::ScrolledWindow | ||
| 6737 | # or a Gtk3::VPaned containing the textview(s) | ||
| 6738 | $packedObj = $textViewObj->objEnable( | ||
| 6739 | $self->ivShow('initHash', 'split_mode'), | ||
| 6740 | $colourScheme, | ||
| 6741 | $self->ivShow('initHash', 'max_lines'), | ||
| 6742 | $self->ivShow('initHash', 'new_line'), | ||
| 6743 | $oldBuffer, | ||
| 6744 | ); | ||
| 6745 | |||
| 6746 | if (! $packedObj) { | ||
| 6747 | |||
| 6748 | $textViewObj->objDestroy(); | ||
| 6749 | return undef; | ||
| 6750 | } | ||
| 6751 | |||
| 6752 | # Pack the Gtk3::ScrolledWindow/Gtk3::VPaned into our main Gtk3::VBox | ||
| 6753 | $self->packingBox2->pack_start($packedObj, TRUE, TRUE, 0); | ||
| 6754 | |||
| 6755 | # Create a tab object to store details about the tab | ||
| 6756 | $tabObj = Games::Axmud::Obj::Tab->new( | ||
| 6757 | 0, # ->number | ||
| 6758 | $self, | ||
| 6759 | $session, | ||
| 6760 | $defaultFlag, | ||
| 6761 | $textViewObj, | ||
| 6762 | $self->packingBox2, # ->packableObj | ||
| 6763 | $packedObj, # ->packedObj | ||
| 6764 | ); | ||
| 6765 | |||
| 6766 | # Update IVs. The code above has already checked that $self->tabObjHash is empty | ||
| 6767 | $self->ivAdd('tabObjHash', $tabObj->number, $tabObj); | ||
| 6768 | $self->ivIncrement('tabObjCount'); | ||
| 6769 | $self->ivPoke('simpleTabFlag', TRUE); | ||
| 6770 | |||
| 6771 | # Make the changes visible | ||
| 6772 | $self->winObj->winShowAll($self->_objClass . '->addSimpleTab'); | ||
| 6773 | |||
| 6774 | # The new tab is the visible tab | ||
| 6775 | $self->respondVisibleTab($tabObj, $sessionFlag); | ||
| 6776 | |||
| 6777 | return $tabObj; | ||
| 6778 | } | ||
| 6779 | |||
| 6780 | sub addTab { | ||
| 6781 | |||
| 6782 | # Called by GA::Session->setDefaultTab, $self->convertSimpleTab or by any other code | ||
| 6783 | # Adds a (normal) tab to the Gtk3::Notebook | ||
| 6784 | # | ||
| 6785 | # Expected arguments | ||
| 6786 | # $session - The GA::Session that will control the tab (and the textview object | ||
| 6787 | # it contains) | ||
| 6788 | # | ||
| 6789 | # Optional arguments | ||
| 6790 | # $colourScheme - If specified, the name of the colour scheme to use. If 'undef' (or if | ||
| 6791 | # the specified colour scheme doesn't exist), the colour scheme | ||
| 6792 | # specified by $self->initHash is used | ||
| 6793 | # $sessionFlag - Flag set to TRUE if this tab was called by | ||
| 6794 | # GA::Session->setDefaultTab, FALSE (or 'undef') if it was called by | ||
| 6795 | # anything else | ||
| 6796 | # $defaultFlag - Flag set to TRUE if this tab will be $session's default tab (where | ||
| 6797 | # text received from the world is usually displayed), FALSE (or | ||
| 6798 | # 'undef') otherwise (might be TRUE even if $sessionFlag is FALSE) | ||
| 6799 | # $labelText - The text to use in the tab label (empty strings are acceptable). If | ||
| 6800 | # 'undef', 'Tab #' is used | ||
| 6801 | # $oldBuffer - If a standalone textview object is being replaced by a Gtk3::Notebook | ||
| 6802 | # with a single tab, the old textview object's Gtk3::TextBuffer, which | ||
| 6803 | # is transferred to the new textview object ('undef' otherwise) | ||
| 6804 | # | ||
| 6805 | # Return values | ||
| 6806 | # 'undef' on improper arguments or if the tab can't be drawn | ||
| 6807 | # Otherwise returns the tab object (GA::Obj::Tab) created, which stores (among other | ||
| 6808 | # things) the textview object created | ||
| 6809 | |||
| 6810 | my ( | ||
| 6811 | $self, $session, $colourScheme, $sessionFlag, $defaultFlag, $labelText, $oldBuffer, | ||
| 6812 | $check, | ||
| 6813 | ) = @_; | ||
| 6814 | |||
| 6815 | # Local variables | ||
| 6816 | my ($textViewObj, $packedObj, $tabObj); | ||
| 6817 | |||
| 6818 | # Check for improper arguments | ||
| 6819 | if (! defined $session || defined $check) { | ||
| 6820 | |||
| 6821 | return $axmud::CLIENT->writeImproper($self->_objClass . '->addTab', @_); | ||
| 6822 | } | ||
| 6823 | |||
| 6824 | # If this table object isn't using a notebook, but a simple container (a | ||
| 6825 | # Gtk3::ScrolledWindow or a Gtk3::VPaned), convert from the latter to the former | ||
| 6826 | if (! $self->notebook) { | ||
| 6827 | |||
| 6828 | if ($self->tabObjHash) { | ||
| 6829 | |||
| 6830 | # Convert the existing single tab to a normal tab | ||
| 6831 | if (! $self->convertSimpleTab()) { | ||
| 6832 | |||
| 6833 | # (Error message displayed by called function) | ||
| 6834 | return undef; | ||
| 6835 | } | ||
| 6836 | |||
| 6837 | } else { | ||
| 6838 | |||
| 6839 | # No tabs exist, so create the notebook, then we can continue creating the first | ||
| 6840 | # tab in it | ||
| 6841 | if (! $self->drawNotebook()) { | ||
| 6842 | |||
| 6843 | return $self->writeWarning( | ||
| 6844 | 'General error adding a tab', | ||
| 6845 | $self->_objClass . '->addTab', | ||
| 6846 | ); | ||
| 6847 | } | ||
| 6848 | } | ||
| 6849 | } | ||
| 6850 | |||
| 6851 | # Create the tab | ||
| 6852 | |||
| 6853 | # The tab contains a vertical packing box, which contains everything else | ||
| 6854 | my $vBox = Gtk3::VBox->new(FALSE, 0); | ||
| 6855 | $vBox->set_border_width(0); | ||
| 6856 | |||
| 6857 | # A horizontal packing box is used as the tab's label (in place of a Gtk3::Label) | ||
| 6858 | my $hBox = Gtk3::HBox->new(FALSE, 0); | ||
| 6859 | my $label = Gtk3::Label->new(); | ||
| 6860 | $hBox->pack_start($label, FALSE, FALSE, 0); | ||
| 6861 | $label->show(); | ||
| 6862 | |||
| 6863 | # Add an 'X' button to close the tab, if required | ||
| 6864 | my $button; | ||
| 6865 | if ($self->canCloseFlag) { | ||
| 6866 | |||
| 6867 | $button = Gtk3::Button->new(); | ||
| 6868 | $hBox->pack_start($button, FALSE, FALSE, 0); | ||
| 6869 | $button->set_image(Gtk3::Image->new_from_stock('gtk-close', 'menu')); | ||
| 6870 | $button->set_relief('none'); | ||
| 6871 | $button->show(); | ||
| 6872 | } | ||
| 6873 | |||
| 6874 | # Create a new GA::Obj::Textview object to handle the Gtk3::Textview(s) | ||
| 6875 | $textViewObj = $axmud::CLIENT->desktopObj->add_textView( | ||
| 6876 | $session, | ||
| 6877 | $self->winObj, | ||
| 6878 | $self, | ||
| 6879 | ); | ||
| 6880 | |||
| 6881 | if (! $textViewObj) { | ||
| 6882 | |||
| 6883 | return undef; | ||
| 6884 | } | ||
| 6885 | |||
| 6886 | # Set the colour scheme to use | ||
| 6887 | if ( | ||
| 6888 | ! defined $colourScheme | ||
| 6889 | || ! $axmud::CLIENT->ivExists('colourSchemeHash', $colourScheme) | ||
| 6890 | ) { | ||
| 6891 | $colourScheme = $self->ivShow('initHash', 'colour_scheme'); | ||
| 6892 | } | ||
| 6893 | |||
| 6894 | # Create the Gtk3::TextView(s) themselves. The function call returns a Gtk3::ScrolledWindow | ||
| 6895 | # or a Gtk3::VPaned containing the textview(s) | ||
| 6896 | $packedObj = $textViewObj->objEnable( | ||
| 6897 | $self->ivShow('initHash', 'split_mode'), | ||
| 6898 | $colourScheme, | ||
| 6899 | $self->ivShow('initHash', 'max_lines'), | ||
| 6900 | $self->ivShow('initHash', 'new_line'), | ||
| 6901 | $oldBuffer, | ||
| 6902 | ); | ||
| 6903 | |||
| 6904 | if (! $packedObj) { | ||
| 6905 | |||
| 6906 | $textViewObj->objDestroy(); | ||
| 6907 | return undef; | ||
| 6908 | } | ||
| 6909 | |||
| 6910 | # Pack the Gtk3::ScrolledWindow/Gtk3::VPaned into this tab's Gtk3::VBox | ||
| 6911 | $vBox->pack_start($packedObj, TRUE, TRUE, 0); | ||
| 6912 | |||
| 6913 | # From Gtk documentation: 'Note that due to historical reasons, GtkNotebook refuses to | ||
| 6914 | # switch to a page unless the child widget is visible. Therefore, it is recommended to | ||
| 6915 | # show child widgets before adding them to a notebook.' | ||
| 6916 | $vBox->show(); | ||
| 6917 | $hBox->show(); | ||
| 6918 | |||
| 6919 | # Add the tab to the notebook | ||
| 6920 | my $tabNum = $self->notebook->append_page($vBox, $hBox); | ||
| 6921 | |||
| 6922 | # Make the tab re-orderable | ||
| 6923 | my $tabWidget = $self->notebook->get_nth_page($tabNum); | ||
| 6924 | $self->notebook->set_tab_reorderable($tabWidget, TRUE); | ||
| 6925 | |||
| 6926 | # If no label text was specified, use the default text | ||
| 6927 | if (! defined $labelText) { | ||
| 6928 | |||
| 6929 | $labelText = 'Tab #' . $tabNum; | ||
| 6930 | } | ||
| 6931 | |||
| 6932 | $label->set_markup($labelText); | ||
| 6933 | |||
| 6934 | # Create a tab object to store details about the tab | ||
| 6935 | $tabObj = Games::Axmud::Obj::Tab->new( | ||
| 6936 | $self->tabObjCount, # ->number | ||
| 6937 | $self, | ||
| 6938 | $session, | ||
| 6939 | $defaultFlag, | ||
| 6940 | $textViewObj, | ||
| 6941 | $vBox, # ->packableObj | ||
| 6942 | $packedObj, # ->packedObj | ||
| 6943 | $vBox, # ->tabWidget | ||
| 6944 | $label, # ->tabLabel | ||
| 6945 | ); | ||
| 6946 | |||
| 6947 | # Update IVs | ||
| 6948 | $self->ivAdd('tabObjHash', $tabObj->number, $tabObj); | ||
| 6949 | $self->ivIncrement('tabObjCount'); | ||
| 6950 | |||
| 6951 | # The new tab should be the visible (current) one | ||
| 6952 | # NB When replacing a standalone textview object with a Gtk3::Notebook, adding the old | ||
| 6953 | # textview object's buffer to the new notebook's first tab, we don't set the first tab as | ||
| 6954 | # the current page - because the calling function wants to set the (new) second tab as the | ||
| 6955 | # current page | ||
| 6956 | if (! $oldBuffer) { | ||
| 6957 | |||
| 6958 | $self->notebook->set_current_page($tabNum); | ||
| 6959 | } | ||
| 6960 | |||
| 6961 | # After replacing a standalone textview object with a Gtk3::Notebook, the original session's | ||
| 6962 | # textview(s) don't scroll to the bottom (as it should) without this code (and placing the | ||
| 6963 | # code anywhere else doesn't work, either) | ||
| 6964 | if ($oldBuffer) { | ||
| 6965 | |||
| 6966 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->addTab'); | ||
| 6967 | } | ||
| 6968 | |||
| 6969 | # Set up ->signal_connects for the close button, if it was created | ||
| 6970 | if ($button) { | ||
| 6971 | |||
| 6972 | if (! $defaultFlag) { | ||
| 6973 | $self->setButtonClicked($button, $tabObj); | ||
| 6974 | } else { | ||
| 6975 | $self->setButtonClicked($button, $tabObj, $session); | ||
| 6976 | } | ||
| 6977 | } | ||
| 6978 | |||
| 6979 | # Make the changes visible | ||
| 6980 | $self->winObj->winShowAll($self->_objClass . '->addTab'); | ||
| 6981 | |||
| 6982 | # The new tab is the visible tab. The call above to ->set_current_page ought to have | ||
| 6983 | # caused a call to $self->respondVisibleTab, but if $sessionFlag is set, call it again, | ||
| 6984 | # forcing it to call GA::Win::Internal->setVisibleSession at least once | ||
| 6985 | if ($sessionFlag) { | ||
| 6986 | |||
| 6987 | $self->respondVisibleTab($tabObj, $sessionFlag); | ||
| 6988 | } | ||
| 6989 | |||
| 6990 | return $tabObj; | ||
| 6991 | } | ||
| 6992 | |||
| 6993 | sub removeSessionTab { | ||
| 6994 | |||
| 6995 | # Called by GA::Session->stop (only) | ||
| 6996 | # Removes the tab containing the default textview object for the calling session (if other | ||
| 6997 | # parts of the code want to remove a non-default tab, they should call | ||
| 6998 | # $self->removeTabNum) | ||
| 6999 | # After removing the tab, if there is then only a single session open, and if the | ||
| 7000 | # initialisation setting demands that we use a simple tab rather than a Gtk3::Notebook | ||
| 7001 | # tab, replace the notebook with a simple tab | ||
| 7002 | # | ||
| 7003 | # Expected arguments | ||
| 7004 | # $session - The GA::Session for the tab to be removed | ||
| 7005 | # | ||
| 7006 | # Return values | ||
| 7007 | # 'undef' on improper arguments, or if the tab widgets can't be removed or if the | ||
| 7008 | # session's default tab can't be found | ||
| 7009 | # 1 on success | ||
| 7010 | |||
| 7011 | my ($self, $session, $check) = @_; | ||
| 7012 | |||
| 7013 | # Local variables | ||
| 7014 | my ($tabObj, $count, $newTabObj); | ||
| 7015 | |||
| 7016 | # Check for improper arguments | ||
| 7017 | if (! defined $session || defined $check) { | ||
| 7018 | |||
| 7019 | return $axmud::CLIENT->writeImproper($self->_objClass . '->removeTab', @_); | ||
| 7020 | } | ||
| 7021 | |||
| 7022 | if (! $self->notebook) { | ||
| 7023 | |||
| 7024 | # A simple tab, containing a standalone textview object | ||
| 7025 | $tabObj = $self->ivShow('tabObjHash', 0); | ||
| 7026 | if (! $tabObj || ! $tabObj->defaultFlag || $tabObj->session ne $session) { | ||
| 7027 | |||
| 7028 | # (Error message displayed by calling function) | ||
| 7029 | return undef; | ||
| 7030 | } | ||
| 7031 | |||
| 7032 | # Remove the simple tab by removing everything from the main packing box | ||
| 7033 | $axmud::CLIENT->desktopObj->removeWidget($self->packingBox2, $tabObj->packedObj); | ||
| 7034 | # Inform the textview object (if any) of its demise | ||
| 7035 | if ($tabObj->textViewObj) { | ||
| 7036 | |||
| 7037 | $tabObj->textViewObj->objDestroy(); | ||
| 7038 | } | ||
| 7039 | |||
| 7040 | # Update IVs | ||
| 7041 | $self->ivEmpty('tabObjHash'); | ||
| 7042 | $self->ivPoke('tabObjCount', 0); | ||
| 7043 | |||
| 7044 | } else { | ||
| 7045 | |||
| 7046 | # A tab in a Gtk3::Notebook. Find which one corresponds to the session | ||
| 7047 | $tabObj = $self->findSession($session); | ||
| 7048 | if (! defined $tabObj) { | ||
| 7049 | |||
| 7050 | # (Error message displayed by calling function) | ||
| 7051 | return undef; | ||
| 7052 | } | ||
| 7053 | |||
| 7054 | # Remove the tab from its Gtk3::Notebook | ||
| 7055 | $self->notebook->remove_page($self->notebook->page_num($tabObj->tabWidget)); | ||
| 7056 | # Inform the textview object (if any) of its demise | ||
| 7057 | if ($tabObj->textViewObj) { | ||
| 7058 | |||
| 7059 | $tabObj->textViewObj->objDestroy(); | ||
| 7060 | } | ||
| 7061 | |||
| 7062 | # Update IVs | ||
| 7063 | $self->ivDelete('tabObjHash', $tabObj->number); | ||
| 7064 | |||
| 7065 | # If there is only one tab left, and the first tab created (since the pane was last | ||
| 7066 | # empty of tabs) was a simple tab, convert a normal tab into a simple tab | ||
| 7067 | $count = $self->ivPairs('tabObjHash'); | ||
| 7068 | if ($count == 1 && $self->simpleTabFlag) { | ||
| 7069 | |||
| 7070 | if (! $self->convertTab()) { | ||
| 7071 | |||
| 7072 | # (Error message already displayed) | ||
| 7073 | return undef; | ||
| 7074 | } | ||
| 7075 | |||
| 7076 | # If there are no tabs left, remove the notebook itself, so the next tab to be added can | ||
| 7077 | # be a simple or normal tab | ||
| 7078 | } elsif (! $count) { | ||
| 7079 | |||
| 7080 | $axmud::CLIENT->desktopObj->removeWidget($self->packingBox2, $self->notebook); | ||
| 7081 | |||
| 7082 | $self->ivUndef('notebook'); | ||
| 7083 | } | ||
| 7084 | } | ||
| 7085 | |||
| 7086 | # If there are no tabs left, the calling code can create a simple tab or a normal tab | ||
| 7087 | if (! $self->tabObjHash) { | ||
| 7088 | |||
| 7089 | $self->ivPoke('simpleTabFlag', FALSE); | ||
| 7090 | } | ||
| 7091 | |||
| 7092 | # Make the changes visible | ||
| 7093 | $self->winObj->winShowAll($self->_objClass . '->removeTab'); | ||
| 7094 | |||
| 7095 | return 1; | ||
| 7096 | } | ||
| 7097 | |||
| 7098 | sub removeTab { | ||
| 7099 | |||
| 7100 | # Called by callback in $self->setButtonClicked (only) | ||
| 7101 | # Removes the specified tab | ||
| 7102 | # | ||
| 7103 | # Expected arguments | ||
| 7104 | # $tabObj - The GA::Obj::Tab to remove | ||
| 7105 | # | ||
| 7106 | # Return values | ||
| 7107 | # 'undef' on improper arguments, or if the specified tab doesn't exist | ||
| 7108 | # 1 on success | ||
| 7109 | |||
| 7110 | my ($self, $tabObj, $check) = @_; | ||
| 7111 | |||
| 7112 | # Local variables | ||
| 7113 | my ($count, $funcRef); | ||
| 7114 | |||
| 7115 | # Check for improper arguments | ||
| 7116 | if (! defined $tabObj || defined $check) { | ||
| 7117 | |||
| 7118 | return $axmud::CLIENT->writeImproper($self->_objClass . '->removeTab', @_); | ||
| 7119 | } | ||
| 7120 | |||
| 7121 | # Check the tab exists | ||
| 7122 | if (! $self->ivExists('tabObjHash', $tabObj->number)) { | ||
| 7123 | |||
| 7124 | return undef; | ||
| 7125 | } | ||
| 7126 | |||
| 7127 | # Remove the tab | ||
| 7128 | if (! $self->notebook) { | ||
| 7129 | |||
| 7130 | # A simple tab, containing a standalone textview object | ||
| 7131 | |||
| 7132 | # Remove the simple tab by removing everything from the main packing box | ||
| 7133 | $axmud::CLIENT->desktopObj->removeWidget($self->packingBox2, $tabObj->packedObj); | ||
| 7134 | # Inform the textview object (if any) of its demise | ||
| 7135 | if ($tabObj->textViewObj) { | ||
| 7136 | |||
| 7137 | $tabObj->textViewObj->objDestroy(); | ||
| 7138 | } | ||
| 7139 | |||
| 7140 | # Update IVs | ||
| 7141 | $self->ivEmpty('tabObjHash'); | ||
| 7142 | $self->ivPoke('tabObjCount', 0); | ||
| 7143 | |||
| 7144 | } else { | ||
| 7145 | |||
| 7146 | # A tab in a Gtk3::Notebook | ||
| 7147 | |||
| 7148 | # Remove the tab from its Gtk3::Notebook | ||
| 7149 | $self->notebook->remove_page($self->notebook->page_num($tabObj->tabWidget)); | ||
| 7150 | # Inform the textview object (if any) of its demise | ||
| 7151 | if ($tabObj->textViewObj) { | ||
| 7152 | |||
| 7153 | $tabObj->textViewObj->objDestroy(); | ||
| 7154 | } | ||
| 7155 | |||
| 7156 | # Update IVs | ||
| 7157 | $self->ivDelete('tabObjHash', $tabObj->number); | ||
| 7158 | |||
| 7159 | # If there is only one tab left, and the first tab created (since the pane was last | ||
| 7160 | # empty of tabs) was a simple tab, convert a normal tab into a simple tab | ||
| 7161 | $count = $self->ivPairs('tabObjHash'); | ||
| 7162 | if ($count == 1 && $self->simpleTabFlag) { | ||
| 7163 | |||
| 7164 | if (! $self->convertTab()) { | ||
| 7165 | |||
| 7166 | # (Error message already displayed) | ||
| 7167 | return undef; | ||
| 7168 | } | ||
| 7169 | |||
| 7170 | # If there are no tabs left, remove the notebook itself, so the next tab to be added can | ||
| 7171 | # be a simple or normal tab | ||
| 7172 | } elsif (! $count) { | ||
| 7173 | |||
| 7174 | $axmud::CLIENT->desktopObj->removeWidget($self->packingBox2, $self->notebook); | ||
| 7175 | |||
| 7176 | $self->ivUndef('notebook'); | ||
| 7177 | } | ||
| 7178 | } | ||
| 7179 | |||
| 7180 | # If there are no tabs left, the calling code can create a simple tab or a normal tab | ||
| 7181 | if (! $self->tabObjHash) { | ||
| 7182 | |||
| 7183 | $self->ivPoke('simpleTabFlag', FALSE); | ||
| 7184 | } | ||
| 7185 | |||
| 7186 | # Inform any code that wants to be informed when the tab changes | ||
| 7187 | if ($self->closeFuncRef) { | ||
| 7188 | |||
| 7189 | $funcRef = $self->closeFuncRef; | ||
| 7190 | &$funcRef($self, $tabObj, $self->closeFuncID); | ||
| 7191 | } | ||
| 7192 | |||
| 7193 | # Make the changes visible | ||
| 7194 | $self->winObj->winShowAll($self->_objClass . '->removeTab'); | ||
| 7195 | |||
| 7196 | return 1; | ||
| 7197 | } | ||
| 7198 | |||
| 7199 | sub convertSimpleTab { | ||
| 7200 | |||
| 7201 | # Called by $self->addTab, when a simple tab is currently visible | ||
| 7202 | # | ||
| 7203 | # Converts the standalone textview object (a simple tab) into a new tab on a Gtk3::Notebook, | ||
| 7204 | # preserving the Gtk3::TextBuffer | ||
| 7205 | # | ||
| 7206 | # Expected arguments | ||
| 7207 | # (none besides $self) | ||
| 7208 | # | ||
| 7209 | # Return values | ||
| 7210 | # 'undef' on improper arguments or if there's an error | ||
| 7211 | # 1 on success | ||
| 7212 | |||
| 7213 | my ($self, $check) = @_; | ||
| 7214 | |||
| 7215 | # Local variables | ||
| 7216 | my ($oldTabObj, $newTabObj, $notebook, $oldLabelText); | ||
| 7217 | |||
| 7218 | # Check for improper arguments | ||
| 7219 | if (defined $check) { | ||
| 7220 | |||
| 7221 | return $axmud::CLIENT->writeImproper($self->_objClass . '->convertSimpleTab', @_); | ||
| 7222 | } | ||
| 7223 | |||
| 7224 | # Set a flag that various ->signal_connects can use to avoid responding when a tab | ||
| 7225 | # conversion operation is in progress | ||
| 7226 | $self->ivPoke('tabConvertFlag', TRUE); | ||
| 7227 | |||
| 7228 | # Get the single existing tab | ||
| 7229 | $oldTabObj = $self->ivShow('tabObjHash', 0); | ||
| 7230 | |||
| 7231 | # Remove the standalone textview object | ||
| 7232 | $axmud::CLIENT->desktopObj->removeWidget($self->packingBox2, $oldTabObj->packedObj); | ||
| 7233 | |||
| 7234 | # Add a Gtk3::Notebook in its place | ||
| 7235 | $notebook = $self->drawNotebook(); | ||
| 7236 | if (! $notebook) { | ||
| 7237 | |||
| 7238 | # Emergency fallback - put the old textview back, as if nothing had happened (but show a | ||
| 7239 | # warning) | ||
| 7240 | $self->packingBox2->pack_start($oldTabObj->packedObj, TRUE, TRUE, 0); | ||
| 7241 | |||
| 7242 | return $self->writeWarning( | ||
| 7243 | 'General error converting simple tab', | ||
| 7244 | $self->_objClass . '->convertSimpleTab', | ||
| 7245 | ); | ||
| 7246 | } | ||
| 7247 | |||
| 7248 | # Update IVs | ||
| 7249 | $self->ivEmpty('tabObjHash'); | ||
| 7250 | $self->ivPoke('tabObjCount', 0); | ||
| 7251 | |||
| 7252 | # Add a tab in its place, using the old textview object's buffer and the old session number | ||
| 7253 | if ($oldTabObj->defaultFlag) { | ||
| 7254 | |||
| 7255 | $oldLabelText = $oldTabObj->session->getTabLabelText(); | ||
| 7256 | } | ||
| 7257 | |||
| 7258 | $newTabObj = $self->addTab( | ||
| 7259 | $oldTabObj->session, | ||
| 7260 | $oldTabObj->textViewObj->colourScheme, | ||
| 7261 | undef, # Not called by GA::Session->setDefaultTab | ||
| 7262 | $oldTabObj->defaultFlag, | ||
| 7263 | $oldLabelText, | ||
| 7264 | $oldTabObj->textViewObj->buffer, | ||
| 7265 | ); | ||
| 7266 | |||
| 7267 | # Restore the scroll lock, if it was enabled in the old single textview | ||
| 7268 | if ($oldTabObj->textViewObj->scrollLockFlag) { | ||
| 7269 | |||
| 7270 | $newTabObj->textViewObj->toggleScrollLock(); | ||
| 7271 | } | ||
| 7272 | |||
| 7273 | # Restore the old single textview's split screen mode | ||
| 7274 | $newTabObj->textViewObj->setSplitScreenMode($oldTabObj->textViewObj->splitScreenMode); | ||
| 7275 | |||
| 7276 | # Update the GA::Session's tab IVs, as required | ||
| 7277 | if ( | ||
| 7278 | $oldTabObj->session->defaultTabObj | ||
| 7279 | && $oldTabObj->session->defaultTabObj eq $oldTabObj | ||
| 7280 | ) { | ||
| 7281 | $oldTabObj->session->set_defaultTabObj($newTabObj); | ||
| 7282 | } | ||
| 7283 | |||
| 7284 | if ( | ||
| 7285 | $oldTabObj->session->currentTabObj | ||
| 7286 | && $oldTabObj->session->currentTabObj eq $oldTabObj | ||
| 7287 | ) { | ||
| 7288 | $oldTabObj->session->set_currentTabObj($newTabObj); | ||
| 7289 | } | ||
| 7290 | |||
| 7291 | # Operation complete | ||
| 7292 | $self->ivPoke('tabConvertFlag', FALSE); | ||
| 7293 | |||
| 7294 | return 1; | ||
| 7295 | } | ||
| 7296 | |||
| 7297 | sub convertTab { | ||
| 7298 | |||
| 7299 | # Called by $self->removeSessionTab or ->removeTab when there's only a single Gtk3::Notebook | ||
| 7300 | # tab left, and the initialisation setting specifies that a tab label shouldn't be visible | ||
| 7301 | # Converts the Gtk3::Notebook containing a single remaining tab into a standalone textview | ||
| 7302 | # object, preserving its Gtk3::TextBuffer (a simple tab) | ||
| 7303 | # | ||
| 7304 | # Expected arguments | ||
| 7305 | # (none besides $self) | ||
| 7306 | # | ||
| 7307 | # Return values | ||
| 7308 | # 'undef' on improper arguments or if there's an error | ||
| 7309 | # 1 on success | ||
| 7310 | |||
| 7311 | my ($self, $tabObj, $check) = @_; | ||
| 7312 | |||
| 7313 | # Local variables | ||
| 7314 | my ($oldTabObj, $scroll, $newTabObj, $oldLabelText); | ||
| 7315 | |||
| 7316 | # Check for improper arguments | ||
| 7317 | if (defined $check) { | ||
| 7318 | |||
| 7319 | return $axmud::CLIENT->writeImproper($self->_objClass . '->convertTab', @_); | ||
| 7320 | } | ||
| 7321 | |||
| 7322 | # Set a flag that various ->signal_connects can use to avoid responding when a tab | ||
| 7323 | # conversion operation is in progress | ||
| 7324 | $self->ivPoke('tabConvertFlag', TRUE); | ||
| 7325 | |||
| 7326 | # Get the single remaining tab (the calling function has already checked there is only one) | ||
| 7327 | ($oldTabObj) = $self->ivValues('tabObjHash'); | ||
| 7328 | if (! $oldTabObj) { | ||
| 7329 | |||
| 7330 | return $self->writeWarning( | ||
| 7331 | 'General error converting tab', | ||
| 7332 | $self->_objClass . '->convertTab', | ||
| 7333 | ); | ||
| 7334 | } | ||
| 7335 | |||
| 7336 | # Remove the Gtk3::Notebook | ||
| 7337 | $axmud::CLIENT->desktopObj->removeWidget($self->packingBox2, $self->notebook); | ||
| 7338 | |||
| 7339 | # v1.1.128 This is not necessary, and in fact messes up everything | ||
| 7340 | # # Replace it with a standalone textview object | ||
| 7341 | # $axmud::CLIENT->desktopObj->removeWidget($oldTabObj->packableObj, $oldTabObj->packedObj); | ||
| 7342 | # $self->packingBox2->pack_start($oldTabObj->packedObj, TRUE, TRUE, 0); | ||
| 7343 | |||
| 7344 | # Update IVs | ||
| 7345 | $self->ivUndef('notebook'); | ||
| 7346 | $self->ivEmpty('tabObjHash'); | ||
| 7347 | $self->ivPoke('tabObjCount', 0); | ||
| 7348 | |||
| 7349 | # Add a simple tab, using the old tab's buffer and the old session | ||
| 7350 | if ($oldTabObj->defaultFlag) { | ||
| 7351 | |||
| 7352 | $oldLabelText = $oldTabObj->session->getTabLabelText(); | ||
| 7353 | } | ||
| 7354 | |||
| 7355 | $newTabObj = $self->addSimpleTab( | ||
| 7356 | $oldTabObj->session, | ||
| 7357 | $oldTabObj->textViewObj->colourScheme, | ||
| 7358 | undef, # Not called by GA::Session->setDefaultTab | ||
| 7359 | $oldTabObj->defaultFlag, | ||
| 7360 | $oldLabelText, | ||
| 7361 | $oldTabObj->textViewObj->buffer, | ||
| 7362 | ); | ||
| 7363 | |||
| 7364 | # Restore the scroll lock, if it was enabled in the old single textview | ||
| 7365 | if ($oldTabObj->textViewObj->scrollLockFlag) { | ||
| 7366 | |||
| 7367 | $newTabObj->textViewObj->toggleScrollLock(); | ||
| 7368 | } | ||
| 7369 | |||
| 7370 | # Restore the old single textview's split screen mode | ||
| 7371 | $newTabObj->textViewObj->setSplitScreenMode($oldTabObj->textViewObj->splitScreenMode); | ||
| 7372 | |||
| 7373 | # Update the GA::Session's tab IVs, as required | ||
| 7374 | if ( | ||
| 7375 | $oldTabObj->session->defaultTabObj | ||
| 7376 | && $oldTabObj->session->defaultTabObj eq $oldTabObj | ||
| 7377 | ) { | ||
| 7378 | $oldTabObj->session->set_defaultTabObj($newTabObj); | ||
| 7379 | } | ||
| 7380 | |||
| 7381 | if ( | ||
| 7382 | $oldTabObj->session->currentTabObj | ||
| 7383 | && $oldTabObj->session->currentTabObj eq $oldTabObj | ||
| 7384 | ) { | ||
| 7385 | $oldTabObj->session->set_currentTabObj($newTabObj); | ||
| 7386 | } | ||
| 7387 | |||
| 7388 | # Operation complete | ||
| 7389 | $self->ivPoke('tabConvertFlag', FALSE); | ||
| 7390 | |||
| 7391 | return 1; | ||
| 7392 | } | ||
| 7393 | |||
| 7394 | sub updateColourScheme { | ||
| 7395 | |||
| 7396 | # Called by GA::Win::Internal->updateColourScheme (only) | ||
| 7397 | # When a colour scheme is modified, checks all textview objects in this pane object and | ||
| 7398 | # updates any that use the modified colour scheme. Alternatively, when no colour scheme is | ||
| 7399 | # specified, updates all textview objects | ||
| 7400 | # | ||
| 7401 | # Expected arguments | ||
| 7402 | # (none besides $self) | ||
| 7403 | # | ||
| 7404 | # Optional arguments | ||
| 7405 | # $colourScheme - The name of the modified colour scheme (matches a key in | ||
| 7406 | # GA::Client->colourSchemeHash; the calling function has already | ||
| 7407 | # checked it is valid). If 'undef', all pane objects are updated | ||
| 7408 | # $noDrawFlag - TRUE when the calling function was itself called by | ||
| 7409 | # GA::Win::Internal->redrawWidgets, which doesn't want this function | ||
| 7410 | # to call GA::Win::Generic->winShowAll or | ||
| 7411 | # GA::Obj::Desktop->updateWidgets as it normally would. FALSE (or | ||
| 7412 | # 'undef') otherwise | ||
| 7413 | # | ||
| 7414 | # Return values | ||
| 7415 | # 'undef' on improper arguments | ||
| 7416 | # 1 on success | ||
| 7417 | |||
| 7418 | my ($self, $colourScheme, $noDrawFlag, $check) = @_; | ||
| 7419 | |||
| 7420 | # Check for improper arguments | ||
| 7421 | if (defined $check) { | ||
| 7422 | |||
| 7423 | return $axmud::CLIENT->writeImproper($self->_objClass . '->updateColourScheme', @_); | ||
| 7424 | } | ||
| 7425 | |||
| 7426 | # Update each tab in turn | ||
| 7427 | OUTER: foreach my $tabObj ($self->ivValues('tabObjHash')) { | ||
| 7428 | |||
| 7429 | my $packedObj; | ||
| 7430 | |||
| 7431 | if (! $colourScheme || $tabObj->textViewObj->colourScheme eq $colourScheme) { | ||
| 7432 | |||
| 7433 | $tabObj->textViewObj->objUpdate($colourScheme); | ||
| 7434 | } | ||
| 7435 | } | ||
| 7436 | |||
| 7437 | return 1; | ||
| 7438 | } | ||
| 7439 | |||
| 7440 | sub applyColourScheme { | ||
| 7441 | |||
| 7442 | # Can be called by anything to apply a new colour scheme to one or more of this pane | ||
| 7443 | # object's tabs (in contrast to $self->updateColourScheme, which is only called by | ||
| 7444 | # GA::Win::Internal->winUpdate and applies a modified colour scheme to any textview | ||
| 7445 | # object that uses it) | ||
| 7446 | # | ||
| 7447 | # Expected arguments | ||
| 7448 | # (none besides $self) | ||
| 7449 | # | ||
| 7450 | # Optional arguments | ||
| 7451 | # $tabObj - The tab object (GA::Obj::Tab) containing the textview object to which | ||
| 7452 | # the colour scheme must be applied. If 'undef', the colour scheme is | ||
| 7453 | # applied to all tabs in this pane object | ||
| 7454 | # $colourScheme - The name of the colour scheme to apply (matches a key in | ||
| 7455 | # GA::Client->colourSchemeHash). If unrecognised or 'undef', a default | ||
| 7456 | # colour scheme for the parent window is applied to the textview | ||
| 7457 | # | ||
| 7458 | # Return values | ||
| 7459 | # 'undef' on improper arguments or if there's an error | ||
| 7460 | # 1 on success | ||
| 7461 | |||
| 7462 | my ($self, $tabObj, $colourScheme, $check) = @_; | ||
| 7463 | |||
| 7464 | # Local variables | ||
| 7465 | my @tabList; | ||
| 7466 | |||
| 7467 | # Check for improper arguments | ||
| 7468 | if (defined $check) { | ||
| 7469 | |||
| 7470 | return $axmud::CLIENT->writeImproper($self->_objClass . '->applyColourScheme', @_); | ||
| 7471 | } | ||
| 7472 | |||
| 7473 | # Compile a list of tabs whose textview objects should be modified | ||
| 7474 | if ($tabObj) { | ||
| 7475 | push (@tabList, $tabObj); | ||
| 7476 | } else { | ||
| 7477 | push (@tabList, $self->ivValues('tabObjHash')); | ||
| 7478 | } | ||
| 7479 | |||
| 7480 | # Set the colour scheme to use, if a valid one wasn't specified | ||
| 7481 | if ( | ||
| 7482 | ! defined $colourScheme | ||
| 7483 | || ! $axmud::CLIENT->ivExists('colourSchemeHash', $colourScheme) | ||
| 7484 | ) { | ||
| 7485 | $colourScheme = $self->winObj->winType; | ||
| 7486 | } | ||
| 7487 | |||
| 7488 | # Apply the colour scheme | ||
| 7489 | foreach my $thisTabObj (@tabList) { | ||
| 7490 | |||
| 7491 | $thisTabObj->textViewObj->objUpdate($colourScheme); | ||
| 7492 | } | ||
| 7493 | |||
| 7494 | return 1; | ||
| 7495 | } | ||
| 7496 | |||
| 7497 | sub applyMonochrome { | ||
| 7498 | |||
| 7499 | # Can be called by anything to switch on monochrome mode for one or more of the tabs in this | ||
| 7500 | # pane object (or, for any tabs already in monochrome mode, to change the colour used) | ||
| 7501 | # | ||
| 7502 | # Expected arguments | ||
| 7503 | # (none besides $self) | ||
| 7504 | # | ||
| 7505 | # Optional arguments | ||
| 7506 | # $tabObj - The tab object (GA::Obj::Tab) containing the textview object whose monochrome | ||
| 7507 | # mode must be switched on. If 'undef', monochrome mode is switched on for | ||
| 7508 | # all tabs in this pane object | ||
| 7509 | # $backgroundColour | ||
| 7510 | # - The background colour to use (can be any Axmud colour tag, e.g 'red'). If it's | ||
| 7511 | # an underlay tag like 'ul_red', the equivalent colour tag is used instead. If | ||
| 7512 | # 'undef', the tab's current colour scheme (set by a call to | ||
| 7513 | # $self->applyColourScheme) is used to select a background colour | ||
| 7514 | # $textColour | ||
| 7515 | # - The text colour to use. Is normally 'undef', in which case this function will | ||
| 7516 | # choose a suitable text colour to match the background. Should be specified | ||
| 7517 | # if $backgroundColour is an Xterm or RGB colour tag, otherwise the text | ||
| 7518 | # colour might not suit the background colour | ||
| 7519 | # | ||
| 7520 | # Return values | ||
| 7521 | # 'undef' on improper arguments or if there's an error | ||
| 7522 | # 1 on success | ||
| 7523 | |||
| 7524 | my ($self, $tabObj, $backgroundColour, $textColour, $check) = @_; | ||
| 7525 | |||
| 7526 | # Local variables | ||
| 7527 | my ( | ||
| 7528 | $type, | ||
| 7529 | @tabList, | ||
| 7530 | ); | ||
| 7531 | |||
| 7532 | # Check for improper arguments | ||
| 7533 | if (defined $check) { | ||
| 7534 | |||
| 7535 | return $axmud::CLIENT->writeImproper($self->_objClass . '->applyMonochrome', @_); | ||
| 7536 | } | ||
| 7537 | |||
| 7538 | # Compile a list of tabs whose textview objects should be modified | ||
| 7539 | if ($tabObj) { | ||
| 7540 | push (@tabList, $tabObj); | ||
| 7541 | } else { | ||
| 7542 | push (@tabList, $self->ivValues('tabObjHash')); | ||
| 7543 | } | ||
| 7544 | |||
| 7545 | # If colours were specified, check they are valid | ||
| 7546 | if (defined $backgroundColour) { | ||
| 7547 | |||
| 7548 | ($type) = defined $axmud::CLIENT->checkColourTags($backgroundColour); | ||
| 7549 | if (! $type) { | ||
| 7550 | |||
| 7551 | return undef; | ||
| 7552 | } | ||
| 7553 | |||
| 7554 | } elsif (defined $textColour) { | ||
| 7555 | |||
| 7556 | ($type) = defined $axmud::CLIENT->checkColourTags($textColour); | ||
| 7557 | if (! $type) { | ||
| 7558 | |||
| 7559 | return undef; | ||
| 7560 | } | ||
| 7561 | } | ||
| 7562 | |||
| 7563 | # Switch on monochrome mode for the specified tab(s) | ||
| 7564 | foreach my $thisTabObj (@tabList) { | ||
| 7565 | |||
| 7566 | $thisTabObj->textViewObj->setMonochromeMode($backgroundColour, $textColour); | ||
| 7567 | } | ||
| 7568 | |||
| 7569 | return 1; | ||
| 7570 | } | ||
| 7571 | |||
| 7572 | sub removeMonochrome { | ||
| 7573 | |||
| 7574 | # Can be called by anything to switch off monochrome mode for one or more of the tabs in | ||
| 7575 | # this pane object | ||
| 7576 | # | ||
| 7577 | # Expected arguments | ||
| 7578 | # (none besides $self) | ||
| 7579 | # | ||
| 7580 | # Optional arguments | ||
| 7581 | # $tabObj - The tab object (GA::Obj::Tab) containing the textview object whose monochrome | ||
| 7582 | # mode must be switched off. If 'undef', monochrome mode is switched off for | ||
| 7583 | # all tabs in this pane object | ||
| 7584 | # | ||
| 7585 | # Return values | ||
| 7586 | # 'undef' on improper arguments or if there's an error | ||
| 7587 | # 1 on success | ||
| 7588 | |||
| 7589 | my ($self, $tabObj, $check) = @_; | ||
| 7590 | |||
| 7591 | # Local variables | ||
| 7592 | my @tabList; | ||
| 7593 | |||
| 7594 | # Check for improper arguments | ||
| 7595 | if (defined $check) { | ||
| 7596 | |||
| 7597 | return $axmud::CLIENT->writeImproper($self->_objClass . '->removeMonochrome', @_); | ||
| 7598 | } | ||
| 7599 | |||
| 7600 | # Compile a list of tabs whose textview objects should be modified | ||
| 7601 | if ($tabObj) { | ||
| 7602 | push (@tabList, $tabObj); | ||
| 7603 | } else { | ||
| 7604 | push (@tabList, $self->ivValues('tabObjHash')); | ||
| 7605 | } | ||
| 7606 | |||
| 7607 | # Switch off monochrome mode for the specified tab(s) | ||
| 7608 | foreach my $thisTabObj (@tabList) { | ||
| 7609 | |||
| 7610 | $thisTabObj->textViewObj->resetMonochromeMode(); | ||
| 7611 | } | ||
| 7612 | |||
| 7613 | return 1; | ||
| 7614 | } | ||
| 7615 | |||
| 7616 | sub toggleScrollLock { | ||
| 7617 | |||
| 7618 | # Called by GA::Cmd::ScrollLock->do or GA::Strip::Entry->setScrollSignals | ||
| 7619 | # Toggles the scroll lock in the active textview object | ||
| 7620 | # | ||
| 7621 | # Expected arguments | ||
| 7622 | # (none besides $self) | ||
| 7623 | # | ||
| 7624 | # Return values | ||
| 7625 | # 'undef' on improper arguments or if the toggle operation fails | ||
| 7626 | # 1 on success | ||
| 7627 | |||
| 7628 | my ($self, $check) = @_; | ||
| 7629 | |||
| 7630 | # Local variables | ||
| 7631 | my ($tabObj, $entryObj); | ||
| 7632 | |||
| 7633 | # Check for improper arguments | ||
| 7634 | if (defined $check) { | ||
| 7635 | |||
| 7636 | return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleScrollLock', @_); | ||
| 7637 | } | ||
| 7638 | |||
| 7639 | # Get the visible tab's tab object | ||
| 7640 | if (! $self->notebook) { | ||
| 7641 | $tabObj = $self->ivShow('tabObjHash', 0); | ||
| 7642 | } else { | ||
| 7643 | $tabObj = $self->ivShow('tabObjHash', $self->notebook->get_current_page()); | ||
| 7644 | } | ||
| 7645 | |||
| 7646 | if (! $tabObj || ! $tabObj->textViewObj) { | ||
| 7647 | |||
| 7648 | return undef; | ||
| 7649 | } | ||
| 7650 | |||
| 7651 | # Toggle scroll lock | ||
| 7652 | $tabObj->textViewObj->toggleScrollLock(); | ||
| 7653 | |||
| 7654 | # Find the entry strip object (if it exists) | ||
| 7655 | $entryObj = $self->winObj->ivShow('firstStripHash', 'Games::Axmud::Strip::Entry'); | ||
| 7656 | if ($entryObj) { | ||
| 7657 | |||
| 7658 | # Update the toolbutton icon for its scroll lock button | ||
| 7659 | $entryObj->updateScrollButton($tabObj->textViewObj->scrollLockFlag); | ||
| 7660 | } | ||
| 7661 | |||
| 7662 | $self->winObj->winShowAll($self->_objClass . '->toggleScrollLock'); | ||
| 7663 | |||
| 7664 | return 1; | ||
| 7665 | } | ||
| 7666 | |||
| 7667 | sub toggleSplitScreen { | ||
| 7668 | |||
| 7669 | # Called by GA::Cmd::SplitScreen->do or GA::Strip::Entry->setSplitSignals | ||
| 7670 | # Toggles between split screen modes in the active textview object | ||
| 7671 | # | ||
| 7672 | # Before v1.0.905, textview objects had two split screen modes, 'on' and 'off'. Since then, | ||
| 7673 | # textview objects have had three modes, but pane objects continue to distinguish only | ||
| 7674 | # between 'on' and 'off' | ||
| 7675 | # The textview object modes 'single' and 'hidden' are considered 'off', and this function | ||
| 7676 | # converts them to 'split' | ||
| 7677 | # The textview object mode 'split' is considered 'off', and this function converts it to | ||
| 7678 | # 'hidden' | ||
| 7679 | # In this way, for textview objects created by a pane object, split screen mode is only | ||
| 7680 | # 'single' when the textview object is created with that mode set. Once the mode is | ||
| 7681 | # changed (by this function), it cannot be restored to 'single' (by this function) | ||
| 7682 | # | ||
| 7683 | # This change has been made because of Gtk3 performance issues, particularly with | ||
| 7684 | # Gtk3::TextViews with large buffers. In general, any pane in which split screen mode | ||
| 7685 | # might be turned 'on' should probably create the textview object using the mode 'hidden' | ||
| 7686 | # rather than 'single' | ||
| 7687 | # | ||
| 7688 | # Expected arguments | ||
| 7689 | # (none besides $self) | ||
| 7690 | # | ||
| 7691 | # Return values | ||
| 7692 | # 'undef' on improper arguments or if the toggle operation fails | ||
| 7693 | # 1 on success | ||
| 7694 | |||
| 7695 | my ($self, $check) = @_; | ||
| 7696 | |||
| 7697 | # Local variables | ||
| 7698 | my ($tabObj, $packedObj, $viewport, $entryObj); | ||
| 7699 | |||
| 7700 | # Check for improper arguments | ||
| 7701 | if (defined $check) { | ||
| 7702 | |||
| 7703 | return $axmud::CLIENT->writeImproper($self->_objClass . '->toggleSplitScreen', @_); | ||
| 7704 | } | ||
| 7705 | |||
| 7706 | # Get the visible tab's tab object | ||
| 7707 | if (! $self->notebook) { | ||
| 7708 | $tabObj = $self->ivShow('tabObjHash', 0); | ||
| 7709 | } else { | ||
| 7710 | $tabObj = $self->ivShow('tabObjHash', $self->notebook->get_current_page()); | ||
| 7711 | } | ||
| 7712 | |||
| 7713 | if (! $tabObj || ! $tabObj->textViewObj) { | ||
| 7714 | |||
| 7715 | return undef; | ||
| 7716 | } | ||
| 7717 | |||
| 7718 | # Get a new packable widget | ||
| 7719 | if ( | ||
| 7720 | $tabObj->textViewObj->splitScreenMode eq 'single' | ||
| 7721 | || $tabObj->textViewObj->splitScreenMode eq 'hidden' | ||
| 7722 | ) { | ||
| 7723 | $packedObj = $tabObj->textViewObj->setSplitScreenMode('split'); | ||
| 7724 | } else { | ||
| 7725 | $packedObj = $tabObj->textViewObj->setSplitScreenMode('hidden'); | ||
| 7726 | } | ||
| 7727 | |||
| 7728 | # If $packedObj is defined, it must be re-packed, replacing the old packable widget | ||
| 7729 | if ($packedObj) { | ||
| 7730 | |||
| 7731 | $axmud::CLIENT->desktopObj->removeWidget($tabObj->packableObj, $tabObj->packedObj); | ||
| 7732 | $tabObj->packableObj->pack_start($packedObj, TRUE, TRUE, 0); | ||
| 7733 | $tabObj->ivPoke('packedObj', $packedObj); | ||
| 7734 | } | ||
| 7735 | |||
| 7736 | # Find the entry strip object (if it exists) | ||
| 7737 | $entryObj = $self->winObj->ivShow('firstStripHash', 'Games::Axmud::Strip::Entry'); | ||
| 7738 | if ($entryObj) { | ||
| 7739 | |||
| 7740 | # Update the toolbutton icon for its scroll lock button | ||
| 7741 | if ($tabObj->textViewObj->splitScreenMode eq 'split') { | ||
| 7742 | $entryObj->updateSplitButton(TRUE); | ||
| 7743 | } else { | ||
| 7744 | $entryObj->updateSplitButton(FALSE); | ||
| 7745 | } | ||
| 7746 | } | ||
| 7747 | |||
| 7748 | if ($packedObj) { | ||
| 7749 | |||
| 7750 | # (If we try to scroll the textviews before they've been re-packed, we get an | ||
| 7751 | # uncomfortable flash, so the scrolling function is called last) | ||
| 7752 | $self->winObj->winShowAll($self->_objClass . '->toggleSplitScreen'); | ||
| 7753 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->toggleSplitScreen'); | ||
| 7754 | $tabObj->textViewObj->scrollToLock(); | ||
| 7755 | } | ||
| 7756 | |||
| 7757 | return 1; | ||
| 7758 | } | ||
| 7759 | |||
| 7760 | sub findPage { | ||
| 7761 | |||
| 7762 | # Can be called by anything | ||
| 7763 | # Finds the tab object (GA::Obj::Tab) corresponding to a specified page in the | ||
| 7764 | # Gtk3::Notebook, when normal tabs (not simple tabs) are visible | ||
| 7765 | # If there is a simple tab visible and the specified page is 0, return it | ||
| 7766 | # | ||
| 7767 | # Expected arguments | ||
| 7768 | # $page - The tab's current page number in the notebook (0 for the first tab, 1 | ||
| 7769 | # for the second, etc) | ||
| 7770 | # | ||
| 7771 | # Return values | ||
| 7772 | # 'undef' on improper arguments or if a matching tab object doesn't exist | ||
| 7773 | # Otherwise, returns the tab object | ||
| 7774 | |||
| 7775 | my ($self, $page, $check) = @_; | ||
| 7776 | |||
| 7777 | # Check for improper arguments | ||
| 7778 | if (! defined $page || defined $check) { | ||
| 7779 | |||
| 7780 | return $axmud::CLIENT->writeImproper($self->_objClass . '->findPage', @_); | ||
| 7781 | } | ||
| 7782 | |||
| 7783 | # If there is a simple tab visible and the specified page is 0, return it | ||
| 7784 | if (! $self->notebook) { | ||
| 7785 | |||
| 7786 | if ($page == 0) { | ||
| 7787 | return $self->ivShow('tabObjHash', 0); | ||
| 7788 | } else { | ||
| 7789 | return undef; | ||
| 7790 | } | ||
| 7791 | } | ||
| 7792 | |||
| 7793 | # Otherwise, check each tab in turn until we find the right page number | ||
| 7794 | foreach my $tabObj ($self->ivValues('tabObjHash')) { | ||
| 7795 | |||
| 7796 | my $num = $self->notebook->page_num($tabObj->tabWidget); | ||
| 7797 | if ($num == $page) { | ||
| 7798 | |||
| 7799 | return $tabObj; | ||
| 7800 | } | ||
| 7801 | } | ||
| 7802 | |||
| 7803 | # Corresponding tab object not found | ||
| 7804 | return undef; | ||
| 7805 | } | ||
| 7806 | |||
| 7807 | sub findSession { | ||
| 7808 | |||
| 7809 | # Can be called by anything | ||
| 7810 | # Finds the tab object (GA::Obj::Tab) for the tab/simple tab which contains the specified | ||
| 7811 | # session's default textview object (GA::Obj::TextView) | ||
| 7812 | # | ||
| 7813 | # Expected arguments | ||
| 7814 | # $session - The GA::Session whose tab we want to find | ||
| 7815 | # | ||
| 7816 | # Return values | ||
| 7817 | # 'undef' on improper arguments or if a matching tab object doesn't exist | ||
| 7818 | # Otherwise, returns the tab object | ||
| 7819 | |||
| 7820 | my ($self, $session, $check) = @_; | ||
| 7821 | |||
| 7822 | # Check for improper arguments | ||
| 7823 | if (! defined $session || defined $check) { | ||
| 7824 | |||
| 7825 | return $axmud::CLIENT->writeImproper($self->_objClass . '->findSession', @_); | ||
| 7826 | } | ||
| 7827 | |||
| 7828 | # No session should have more than one tab. Nevertheless, search tabs in ascending order and | ||
| 7829 | # return the first one matching the specified session | ||
| 7830 | foreach my $tabObj (sort {$a->number <=> $b->number} ($self->ivValues('tabObjHash'))) { | ||
| 7831 | |||
| 7832 | if ($tabObj->defaultFlag && $tabObj->session && $tabObj->session eq $session) { | ||
| 7833 | |||
| 7834 | return $tabObj; | ||
| 7835 | } | ||
| 7836 | } | ||
| 7837 | |||
| 7838 | # No tab matching the specified session found | ||
| 7839 | return undef; | ||
| 7840 | } | ||
| 7841 | |||
| 7842 | sub findTextView { | ||
| 7843 | |||
| 7844 | # Can be called by anything | ||
| 7845 | # Finds the tab object (GA::Obj::Tab) for the tab/simple tab which uses the specified | ||
| 7846 | # textview object | ||
| 7847 | # | ||
| 7848 | # Expected arguments | ||
| 7849 | # $textViewObj - The GA::Obj::Textview whose tab we want to find | ||
| 7850 | # | ||
| 7851 | # Return values | ||
| 7852 | # 'undef' on improper arguments or if no tab uses the specified textview object | ||
| 7853 | # Otherwise, returns the tab object | ||
| 7854 | |||
| 7855 | my ($self, $textViewObj, $check) = @_; | ||
| 7856 | |||
| 7857 | # Check for improper arguments | ||
| 7858 | if (! defined $textViewObj || defined $check) { | ||
| 7859 | |||
| 7860 | return $axmud::CLIENT->writeImproper($self->_objClass . '->findTextView', @_); | ||
| 7861 | } | ||
| 7862 | |||
| 7863 | # No textview object should be used by more than one tab. Nevertheless, search tabs in | ||
| 7864 | # ascending order and return the first one matching the specified textview object | ||
| 7865 | foreach my $tabObj (sort {$a->number <=> $b->number} ($self->ivValues('tabObjHash'))) { | ||
| 7866 | |||
| 7867 | if ($tabObj->textViewObj && $tabObj->textViewObj eq $textViewObj) { | ||
| 7868 | |||
| 7869 | return $tabObj; | ||
| 7870 | } | ||
| 7871 | } | ||
| 7872 | |||
| 7873 | # No tab matching using the specified textview object found | ||
| 7874 | return undef; | ||
| 7875 | } | ||
| 7876 | |||
| 7877 | sub getVisibleTab { | ||
| 7878 | |||
| 7879 | # Can be called by anything | ||
| 7880 | # Finds the visible tab and returns its corresponding GA::Obj::Tab object | ||
| 7881 | # | ||
| 7882 | # Expected arguments | ||
| 7883 | # (none besides $self) | ||
| 7884 | # | ||
| 7885 | # Return values | ||
| 7886 | # 'undef' on improper arguments or if there is no visible tab | ||
| 7887 | # Otherwise returns the visible tab's tab object | ||
| 7888 | |||
| 7889 | my ($self, $check) = @_; | ||
| 7890 | |||
| 7891 | # Check for improper arguments | ||
| 7892 | if (defined $check) { | ||
| 7893 | |||
| 7894 | return $axmud::CLIENT->writeImproper($self->_objClass . '->getVisibleTab', @_); | ||
| 7895 | } | ||
| 7896 | |||
| 7897 | if (! $self->notebook) { | ||
| 7898 | |||
| 7899 | return $self->ivShow('tabObjHash', 0); | ||
| 7900 | |||
| 7901 | } else { | ||
| 7902 | |||
| 7903 | return $self->findPage($self->notebook->get_current_page()); | ||
| 7904 | } | ||
| 7905 | } | ||
| 7906 | |||
| 7907 | sub setVisibleTab { | ||
| 7908 | |||
| 7909 | # Can be called by anything | ||
| 7910 | # Sets the visible tab (unless the tab is already the visible one, in which case nothing | ||
| 7911 | # happens) | ||
| 7912 | # | ||
| 7913 | # Expected arguments | ||
| 7914 | # $tabObj - The new visible tab's GA::Obj::Tab | ||
| 7915 | # | ||
| 7916 | # Return values | ||
| 7917 | # 'undef' on improper arguments or if the tab object doesn't exist | ||
| 7918 | # Otherwise returns $tabObj to show the new visible tab | ||
| 7919 | |||
| 7920 | my ($self, $tabObj, $check) = @_; | ||
| 7921 | |||
| 7922 | # Check for improper arguments | ||
| 7923 | if (! defined $tabObj || defined $check) { | ||
| 7924 | |||
| 7925 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setVisibleTab', @_); | ||
| 7926 | } | ||
| 7927 | |||
| 7928 | # Check the tab still exists | ||
| 7929 | if (! $self->ivShow('tabObjHash', $tabObj->number)) { | ||
| 7930 | |||
| 7931 | return undef; | ||
| 7932 | } | ||
| 7933 | |||
| 7934 | # If a simple tab exists, it is the only tab that exists, so it's already the visible one | ||
| 7935 | if ($self->notebook) { | ||
| 7936 | |||
| 7937 | $self->notebook->set_current_page($self->notebook->page_num($tabObj->tabWidget)); | ||
| 7938 | } | ||
| 7939 | |||
| 7940 | return $tabObj; | ||
| 7941 | } | ||
| 7942 | |||
| 7943 | sub switchVisibleTab { | ||
| 7944 | |||
| 7945 | # Called by GA::Win::Internal->setKeyPressEvent when the user presses the 'tab' key | ||
| 7946 | # Switches to the next tab (moving from left to right). If we're already at the right-most | ||
| 7947 | # tab, switches to the first tab | ||
| 7948 | # | ||
| 7949 | # Expected arguments | ||
| 7950 | # (none besides $self) | ||
| 7951 | # | ||
| 7952 | # Return values | ||
| 7953 | # 'undef' on improper arguments or if there's an error | ||
| 7954 | # Otherwise, returns the tab object for the new tab | ||
| 7955 | |||
| 7956 | my ($self, $check) = @_; | ||
| 7957 | |||
| 7958 | # Local variables | ||
| 7959 | my ($currentPage, $tabCount, $nextPage); | ||
| 7960 | |||
| 7961 | # Check for improper arguments | ||
| 7962 | if (defined $check) { | ||
| 7963 | |||
| 7964 | return $axmud::CLIENT->writeImproper($self->_objClass . '->switchVisibleTab', @_); | ||
| 7965 | } | ||
| 7966 | |||
| 7967 | # Deal with simple tabs first, for which the tab can't be switched | ||
| 7968 | if (! $self->notebook) { | ||
| 7969 | |||
| 7970 | return $self->ivShow('tabObjHash', 0); | ||
| 7971 | } | ||
| 7972 | |||
| 7973 | # Get the current visible tab | ||
| 7974 | $currentPage = $self->notebook->get_current_page(); | ||
| 7975 | # Get the number of visible tabs | ||
| 7976 | $tabCount = $self->ivPairs('tabObjHash'); | ||
| 7977 | |||
| 7978 | if ($currentPage >= ($tabCount - 1)) { | ||
| 7979 | |||
| 7980 | $nextPage = 0; | ||
| 7981 | |||
| 7982 | } else { | ||
| 7983 | |||
| 7984 | $nextPage = $currentPage + 1; | ||
| 7985 | } | ||
| 7986 | |||
| 7987 | # Set the new visible tab | ||
| 7988 | $self->notebook->set_current_page($nextPage); | ||
| 7989 | |||
| 7990 | return $self->findPage($nextPage); | ||
| 7991 | } | ||
| 7992 | |||
| 7993 | sub respondVisibleTab { | ||
| 7994 | |||
| 7995 | # Called by $self->setSwitchPageEvent, ->addSimpleTab and (either directly, or via a call | ||
| 7996 | # from the ->signal_connect in $self->setSwitchPageEvent) ->addTab | ||
| 7997 | # | ||
| 7998 | # When a tab becomes the visible tab, inform any code that wants to know. A number of | ||
| 7999 | # occurences can cause the ->signal_connect in $self->setSwitchPageEvent to be | ||
| 8000 | # emitted. When called by ->setSwitchpageEvent, this function only takes action if the | ||
| 8001 | # visible tab has actually changed | ||
| 8002 | # To artificially change the visible tab, call $self->switchVisibleTab or | ||
| 8003 | # ->setVisibleTab | ||
| 8004 | # | ||
| 8005 | # Expected arguments | ||
| 8006 | # $tabObj - The new visible tab's GA::Obj::Tab | ||
| 8007 | # | ||
| 8008 | # Optional arguments | ||
| 8009 | # $sessionFlag - Set to TRUE when called by ->addSimpleTab/->addTab, which in turn | ||
| 8010 | # were called by GA::Session->setDefaultTab; FALSE (or 'undef') | ||
| 8011 | # otherwise | ||
| 8012 | # | ||
| 8013 | # Return values | ||
| 8014 | # 'undef' on improper arguments or if the tab hasn't finished setting up yet | ||
| 8015 | # 1 otherwise | ||
| 8016 | |||
| 8017 | my ($self, $tabObj, $sessionFlag, $check) = @_; | ||
| 8018 | |||
| 8019 | # Local variables | ||
| 8020 | my ($changeFlag, $winObj, $funcRef); | ||
| 8021 | |||
| 8022 | # Check for improper arguments | ||
| 8023 | if (! defined $tabObj || defined $check) { | ||
| 8024 | |||
| 8025 | return $axmud::CLIENT->writeImproper($self->_objClass . '->respondVisibleTab', @_); | ||
| 8026 | } | ||
| 8027 | |||
| 8028 | # Import the parent window (for convenience) | ||
| 8029 | $winObj = $self->winObj; | ||
| 8030 | |||
| 8031 | # Update IVs | ||
| 8032 | if (! $self->currentTabObj || $self->currentTabObj ne $tabObj) { | ||
| 8033 | |||
| 8034 | $self->ivPoke('currentTabObj', $tabObj); | ||
| 8035 | $changeFlag = TRUE; | ||
| 8036 | } | ||
| 8037 | |||
| 8038 | # If this is a session's default tab, inform the parent window so it can update its visible | ||
| 8039 | # visible session | ||
| 8040 | if ( | ||
| 8041 | $sessionFlag | ||
| 8042 | || ( | ||
| 8043 | $tabObj->session->defaultTabObj | ||
| 8044 | && $tabObj->session->defaultTabObj eq $tabObj | ||
| 8045 | && ( | ||
| 8046 | ! $winObj->visibleSession | ||
| 8047 | || $winObj->visibleSession ne $tabObj->session | ||
| 8048 | ) | ||
| 8049 | ) | ||
| 8050 | ) { | ||
| 8051 | $winObj->setVisibleSession($tabObj->session); | ||
| 8052 | } | ||
| 8053 | |||
| 8054 | # Inform any code that wants to be informed when the tab changes | ||
| 8055 | if (! $sessionFlag && $changeFlag && $self->switchFuncRef) { | ||
| 8056 | |||
| 8057 | $funcRef = $self->switchFuncRef; | ||
| 8058 | &$funcRef($self, $tabObj, $self->switchFuncID); | ||
| 8059 | } | ||
| 8060 | |||
| 8061 | return 1; | ||
| 8062 | } | ||
| 8063 | |||
| 8064 | sub setSessionTabLabel { | ||
| 8065 | |||
| 8066 | # Called by GA::Session->spinTaskLoop and ->checkTabLabels to change the label of the | ||
| 8067 | # session's default tab's to something like '*Deathmud (Gandalf)' to show that there are | ||
| 8068 | # files that need to be saved, or to something like 'Deathmud (Gandalf)', to show there | ||
| 8069 | # are no longer files that need to be saved | ||
| 8070 | # | ||
| 8071 | # Expected arguments | ||
| 8072 | # $session - The calling GA::Session which uses a default tab (or default simple tab) | ||
| 8073 | # $string - The string to use (resembles one of the strings described above). Empty | ||
| 8074 | # strings are acceptable, if some code wants to do that | ||
| 8075 | # | ||
| 8076 | # Optional arguments | ||
| 8077 | # $flag - If set to TRUE, show an asterisk. If set to FALSE (or 'undef'), don't show | ||
| 8078 | # an asterisk | ||
| 8079 | # | ||
| 8080 | # Return values | ||
| 8081 | # 'undef' on improper arguments or if the session's default tab doesn't exist | ||
| 8082 | # 1 otherwise | ||
| 8083 | |||
| 8084 | my ($self, $session, $string, $flag, $check) = @_; | ||
| 8085 | |||
| 8086 | # Local variables | ||
| 8087 | my $tabObj; | ||
| 8088 | |||
| 8089 | # Check for improper arguments | ||
| 8090 | if (! defined $session || ! defined $string || defined $check) { | ||
| 8091 | |||
| 8092 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setSessionTabLabel', @_); | ||
| 8093 | } | ||
| 8094 | |||
| 8095 | # Find the session's tab | ||
| 8096 | $tabObj = $self->findSession($session); | ||
| 8097 | if (! $tabObj) { | ||
| 8098 | |||
| 8099 | return undef; | ||
| 8100 | } | ||
| 8101 | |||
| 8102 | # Set the tab label, but don't modify a simple tab (which has no tab label) | ||
| 8103 | if ($self->notebook && $tabObj->tabLabel) { | ||
| 8104 | |||
| 8105 | if ($flag) { | ||
| 8106 | |||
| 8107 | $tabObj->tabLabel->set_markup('*' . $string); | ||
| 8108 | |||
| 8109 | } else { | ||
| 8110 | |||
| 8111 | $tabObj->tabLabel->set_markup($string); | ||
| 8112 | } | ||
| 8113 | } | ||
| 8114 | |||
| 8115 | return 1; | ||
| 8116 | } | ||
| 8117 | |||
| 8118 | sub setTabLabel { | ||
| 8119 | |||
| 8120 | # Can be called by anything | ||
| 8121 | # Changes the specified tab's label | ||
| 8122 | # | ||
| 8123 | # Expected arguments | ||
| 8124 | # $tabNum - The number of the tab object (GA::Obj::Tab) whose label should be changed | ||
| 8125 | # $string - The string to use. Empty strings are acceptable, if some code wants to do | ||
| 8126 | # that | ||
| 8127 | # | ||
| 8128 | # Return values | ||
| 8129 | # 'undef' on improper arguments or if the specified tab doesn't exist in this window | ||
| 8130 | # 1 otherwise | ||
| 8131 | |||
| 8132 | my ($self, $tabNum, $string, $check) = @_; | ||
| 8133 | |||
| 8134 | # Local variables | ||
| 8135 | my $tabObj; | ||
| 8136 | |||
| 8137 | # Check for improper arguments | ||
| 8138 | if (! defined $tabNum || ! defined $string || defined $check) { | ||
| 8139 | |||
| 8140 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setTabLabel', @_); | ||
| 8141 | } | ||
| 8142 | |||
| 8143 | # Check the tab exists in this window | ||
| 8144 | $tabObj = $self->ivShow('tabObjHash', $tabNum); | ||
| 8145 | if (! $tabObj) { | ||
| 8146 | |||
| 8147 | return undef; | ||
| 8148 | } | ||
| 8149 | |||
| 8150 | # Set the tab label, but don't modify a simple tab (which has no tab label) | ||
| 8151 | if ($self->notebook && $tabObj->tabLabel) { | ||
| 8152 | |||
| 8153 | $tabObj->tabLabel->set_markup($string); | ||
| 8154 | } | ||
| 8155 | |||
| 8156 | return 1; | ||
| 8157 | } | ||
| 8158 | |||
| 8159 | sub getTabSize { | ||
| 8160 | |||
| 8161 | # Called by GA::Obj::TextView->setupVPaned or by any other code | ||
| 8162 | # Returns the size of the area occupied by a tab in this pane object | ||
| 8163 | # If there is only a simple tab, it's the same size as the pane. If the pane object is | ||
| 8164 | # using a Gtk3::Notebook, it's the size of the notebook page | ||
| 8165 | # | ||
| 8166 | # Expected arguments | ||
| 8167 | # (none besides $self) | ||
| 8168 | # | ||
| 8169 | # Return values | ||
| 8170 | # An empty list on improper arguments or if there are no tabs open | ||
| 8171 | # Otherwise, returns a list in the form ($width, $height) | ||
| 8172 | |||
| 8173 | my ($self, $check) = @_; | ||
| 8174 | |||
| 8175 | # Local variables | ||
| 8176 | my ( | ||
| 8177 | $tabObj, $hashRef, | ||
| 8178 | @emptyList, | ||
| 8179 | ); | ||
| 8180 | |||
| 8181 | # Check for improper arguments | ||
| 8182 | if (defined $check) { | ||
| 8183 | |||
| 8184 | $axmud::CLIENT->writeImproper($self->_objClass . '->getTabSize', @_); | ||
| 8185 | return @emptyList; | ||
| 8186 | } | ||
| 8187 | |||
| 8188 | # All tabs in this pane object have the same size, so use the first one | ||
| 8189 | $tabObj = $self->ivShow('tabObjHash', 0); | ||
| 8190 | if (! $tabObj) { | ||
| 8191 | |||
| 8192 | # No tabs visible | ||
| 8193 | return @emptyList; | ||
| 8194 | |||
| 8195 | } else { | ||
| 8196 | |||
| 8197 | $hashRef = $tabObj->packableObj->get_allocation; | ||
| 8198 | return ($$hashRef{'width'}, $$hashRef{'height'}); | ||
| 8199 | } | ||
| 8200 | } | ||
| 8201 | |||
| 8202 | ################## | ||
| 8203 | # Accessors - set | ||
| 8204 | |||
| 8205 | sub set_borderWidth { | ||
| 8206 | |||
| 8207 | # Called by $axmud::CLIENT->paneModifyBorder or ->paneRestoreBorder | ||
| 8208 | |||
| 8209 | my ($self, $flag, $check) = @_; | ||
| 8210 | |||
| 8211 | if (! $flag && $self->packingBox2->get_border_width() ne $self->normalBorderWidth) { | ||
| 8212 | |||
| 8213 | # Restore border width | ||
| 8214 | $self->packingBox2->set_border_width($self->normalBorderWidth); | ||
| 8215 | |||
| 8216 | } elsif ($flag && $self->packingBox2->get_border_width() ne $self->selectBorderWidth) { | ||
| 8217 | |||
| 8218 | # Modify border width | ||
| 8219 | $self->packingBox2->set_border_width($self->selectBorderWidth); | ||
| 8220 | } | ||
| 8221 | |||
| 8222 | return 1; | ||
| 8223 | } | ||
| 8224 | |||
| 8225 | sub set_canCloseFlag { | ||
| 8226 | |||
| 8227 | my ($self, $flag, $check) = @_; | ||
| 8228 | |||
| 8229 | # Check for improper arguments | ||
| 8230 | if (! defined $flag || defined $check) { | ||
| 8231 | |||
| 8232 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_canCloseFlag', @_); | ||
| 8233 | } | ||
| 8234 | |||
| 8235 | if (! $flag) { | ||
| 8236 | $self->ivPoke('canCloseFlag', FALSE); | ||
| 8237 | } else { | ||
| 8238 | $self->ivPoke('canCloseFlag', TRUE); | ||
| 8239 | } | ||
| 8240 | |||
| 8241 | return 1; | ||
| 8242 | } | ||
| 8243 | |||
| 8244 | sub set_closeFunc { | ||
| 8245 | |||
| 8246 | # A ->set_func exists in the generic table object for setting $self->funcRef, but there's | ||
| 8247 | # no generic ->closeFuncRef and therefore no generic accessor function | ||
| 8248 | |||
| 8249 | my ($self, $funcRef, $check) = @_; | ||
| 8250 | |||
| 8251 | # Check for improper arguments | ||
| 8252 | if (defined $check) { | ||
| 8253 | |||
| 8254 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_closeFunc', @_); | ||
| 8255 | } | ||
| 8256 | |||
| 8257 | $self->ivPoke('closeFuncRef', $funcRef); | ||
| 8258 | |||
| 8259 | return 1; | ||
| 8260 | } | ||
| 8261 | |||
| 8262 | sub set_closeID { | ||
| 8263 | |||
| 8264 | my ($self, $funcID, $check) = @_; | ||
| 8265 | |||
| 8266 | # Check for improper arguments | ||
| 8267 | if (defined $check) { | ||
| 8268 | |||
| 8269 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_closeID', @_); | ||
| 8270 | } | ||
| 8271 | |||
| 8272 | $self->ivPoke('closeFuncID', $funcID); | ||
| 8273 | |||
| 8274 | return 1; | ||
| 8275 | } | ||
| 8276 | |||
| 8277 | sub set_switchFunc { | ||
| 8278 | |||
| 8279 | # A ->set_func exists in the generic table object for setting $self->funcRef, but there's | ||
| 8280 | # no generic ->switchFuncRef and therefore no generic accessor function | ||
| 8281 | |||
| 8282 | my ($self, $funcRef, $check) = @_; | ||
| 8283 | |||
| 8284 | # Check for improper arguments | ||
| 8285 | if (defined $check) { | ||
| 8286 | |||
| 8287 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_switchFunc', @_); | ||
| 8288 | } | ||
| 8289 | |||
| 8290 | $self->ivPoke('switchFuncRef', $funcRef); | ||
| 8291 | |||
| 8292 | return 1; | ||
| 8293 | } | ||
| 8294 | |||
| 8295 | sub set_switchID { | ||
| 8296 | |||
| 8297 | my ($self, $funcID, $check) = @_; | ||
| 8298 | |||
| 8299 | # Check for improper arguments | ||
| 8300 | if (defined $check) { | ||
| 8301 | |||
| 8302 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_switchID', @_); | ||
| 8303 | } | ||
| 8304 | |||
| 8305 | $self->ivPoke('switchFuncID', $funcID); | ||
| 8306 | |||
| 8307 | return 1; | ||
| 8308 | } | ||
| 8309 | |||
| 8310 | ################## | ||
| 8311 | # Accessors - get | ||
| 8312 | |||
| 8313 | sub notebook | ||
| 8314 | { $_[0]->{notebook} } | ||
| 8315 | sub entry | ||
| 8316 | { $_[0]->{entry} } | ||
| 8317 | |||
| 8318 | sub normalBorderWidth | ||
| 8319 | { $_[0]->{normalBorderWidth} } | ||
| 8320 | sub selectBorderWidth | ||
| 8321 | { $_[0]->{selectBorderWidth} } | ||
| 8322 | |||
| 8323 | sub tabObjHash | ||
| 8324 | { my $self = shift; return %{$self->{tabObjHash}}; } | ||
| 8325 | sub tabObjCount | ||
| 8326 | { $_[0]->{tabObjCount} } | ||
| 8327 | sub currentTabObj | ||
| 8328 | { $_[0]->{currentTabObj} } | ||
| 8329 | sub simpleTabFlag | ||
| 8330 | { $_[0]->{simpleTabFlag} } | ||
| 8331 | sub tabConvertFlag | ||
| 8332 | { $_[0]->{tabConvertFlag} } | ||
| 8333 | sub canCloseFlag | ||
| 8334 | { $_[0]->{canCloseFlag} } | ||
| 8335 | |||
| 8336 | sub switchFuncRef | ||
| 8337 | { $_[0]->{switchFuncRef} } | ||
| 8338 | sub switchFuncID | ||
| 8339 | { $_[0]->{switchFuncID} } | ||
| 8340 | sub closeFuncRef | ||
| 8341 | { $_[0]->{closeFuncRef} } | ||
| 8342 | sub closeFuncID | ||
| 8343 | { $_[0]->{closeFuncID} } | ||
| 8344 | } | ||
| 8345 | |||
| 8346 | # 'Grid' window substitutes | ||
| 8347 | |||
| 8348 | { package Games::Axmud::Table::PseudoWin; | ||
| 8349 | |||
| 8350 | use strict; | ||
| 8351 | use warnings; | ||
| 8352 | # use diagnostics; | ||
| 8353 | |||
| 8354 | use Glib qw(TRUE FALSE); | ||
| 8355 | |||
| 8356 | our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud); | ||
| 8357 | |||
| 8358 | ################## | ||
| 8359 | # Constructors | ||
| 8360 | |||
| 8361 | sub new { | ||
| 8362 | |||
| 8363 | # Called by GA::Strip::Table->addTableObj | ||
| 8364 | # Creates the GA::Table::PseudoWin, which creates a container widget and a pseudo-window | ||
| 8365 | # containing all the widgets normally drawn inside a separate 'grid' window object | ||
| 8366 | # NB Not all 'grid' windows can be used as a pseudo-window. 'main' and 'external' windows | ||
| 8367 | # can never be used | ||
| 8368 | # Other types of window can be used, but the code handling them might need to be modified; | ||
| 8369 | # for example, tasks tend to call functions in GA::Generic::Task rather than functions | ||
| 8370 | # inherited from GA::Generic::Win | ||
| 8371 | # In general, the main problem is using the window object's ->winWidget and ->winBox IVs. In | ||
| 8372 | # most windows, these IVs are set to the same value (the Gtk3::Window), but in | ||
| 8373 | # pseudo-windows, ->winWidget is set to the parent window's Gtk3::Window, and ->winBox is | ||
| 8374 | # set to this table object's ->packingBox, a Gtk3::VBox | ||
| 8375 | # When you wants to do something to the Gtk3::Window in its capacity as a window (such as | ||
| 8376 | # minimise it or make it active), the code should use ->winWidget. When you want to do | ||
| 8377 | # something to the Gtk3::Window in its capacity as a container (such as add or remove | ||
| 8378 | # widgets), the code should use ->winBox | ||
| 8379 | # | ||
| 8380 | # Expected arguments | ||
| 8381 | # $number - The table object's number within the parent strip object (matches | ||
| 8382 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object | ||
| 8383 | # created to access its default IVs) | ||
| 8384 | # $name - A name for the table object. Can be any string or, if no name was | ||
| 8385 | # specified in the call to the calling function, $name is the same as | ||
| 8386 | # $number. (No part of the code checks that table object names are unique; | ||
| 8387 | # if two or more table objects share the same ->name, usually the one with | ||
| 8388 | # the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16 | ||
| 8389 | # chars) | ||
| 8390 | # $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table | ||
| 8391 | # objects | ||
| 8392 | # $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the | ||
| 8393 | # parent strip object's Gtk3::Grid for use exclusively by this table | ||
| 8394 | # object. 'temp' for temporary table objects | ||
| 8395 | # | ||
| 8396 | # Optional arguments | ||
| 8397 | # %initHash - A hash containing arbitrary data to use as the table object's | ||
| 8398 | # initialisation settings. The table object should use default | ||
| 8399 | # initialisation settings unless it can succesfully interpret one or more | ||
| 8400 | # of the key-value pairs in the hash, if there are any | ||
| 8401 | # - This type of table object recognises these initialisation settings: | ||
| 8402 | # | ||
| 8403 | # 'frame_title' - If specified, the table object is drawn inside a frame | ||
| 8404 | # with the specified title. If 'undef', an empty string or not | ||
| 8405 | # specified, the table object does not use a frame and title | ||
| 8406 | # 'win_type' - The 'grid' window type, can be 'map', 'protocol', 'fixed' | ||
| 8407 | # or 'custom' (but not 'main' or 'external'). If 'undef' or not | ||
| 8408 | # specified, 'custom' is used. If an invalid value is specified, the | ||
| 8409 | # table object is not created | ||
| 8410 | # 'win_name' - The window name. For 'protocol' windows, any string chosen | ||
| 8411 | # by the protocol code. If not specified, 'undef' or an mpty string, | ||
| 8412 | # 'win_type' and 'win_name' have the same value | ||
| 8413 | # 'package' - The perl package name for the window object. Only needs to | ||
| 8414 | # be specified for 'fixed' windows (e.g. GA::FixedWin::Something); | ||
| 8415 | # however, if a package is specified for any window object type, it is | ||
| 8416 | # used ('grid' windows only). For 'fixed' windows, if 'undef' or not | ||
| 8417 | # specified, the table object is not created | ||
| 8418 | # 'owner' - The owner of the window object ('undef' or not specified if no | ||
| 8419 | # owner). Typically it's a GA::Session or a task (inheriting from | ||
| 8420 | # GA::Generic::Task); could also be GA::Client. It should not be | ||
| 8421 | # another window object (inheriting from GA::Generic::Win). The owner | ||
| 8422 | # should have its own ->del_winObj function which is called when the | ||
| 8423 | # window object's ->winDestroy is called | ||
| 8424 | # 'session' - The owner's session. If $owner is a GA::Session, that | ||
| 8425 | # session. If it's something else (like a task), the task's session. | ||
| 8426 | # If $owner is 'undef' or not specified, so is 'session' | ||
| 8427 | # 'winmap' - The name of the winmap to use in the pseudo-window. If | ||
| 8428 | # 'undef', not specified or not a recognised winmap, a default winmap | ||
| 8429 | # is used | ||
| 8430 | # | ||
| 8431 | # Return values | ||
| 8432 | # 'undef' on improper arguments | ||
| 8433 | # Blessed reference to the newly-created object on success | ||
| 8434 | |||
| 8435 | my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_; | ||
| 8436 | |||
| 8437 | # Local variables | ||
| 8438 | my ( | ||
| 8439 | $winObj, | ||
| 8440 | %modHash, | ||
| 8441 | ); | ||
| 8442 | |||
| 8443 | # Check for improper arguments | ||
| 8444 | if ( | ||
| 8445 | ! defined $class || ! defined $number || ! defined $name || ! defined $stripObj | ||
| 8446 | || ! defined $zoneObj | ||
| 8447 | ) { | ||
| 8448 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 8449 | } | ||
| 8450 | |||
| 8451 | # Deal with temporary table objects | ||
| 8452 | if ($stripObj eq 'temp') { | ||
| 8453 | $winObj = 'temp'; | ||
| 8454 | } else { | ||
| 8455 | $winObj = $stripObj->winObj; | ||
| 8456 | } | ||
| 8457 | |||
| 8458 | # Default initialisation settings | ||
| 8459 | %modHash = ( | ||
| 8460 | 'frame_title' => undef, | ||
| 8461 | 'win_type' => 'custom', | ||
| 8462 | 'win_name' => 'custom', | ||
| 8463 | 'package' => undef, | ||
| 8464 | 'owner' => undef, | ||
| 8465 | 'session' => undef, | ||
| 8466 | 'winmap' => undef, | ||
| 8467 | ); | ||
| 8468 | |||
| 8469 | # Interpret the initialisation settings in %initHash, if any | ||
| 8470 | foreach my $key (keys %modHash) { | ||
| 8471 | |||
| 8472 | if (exists $initHash{$key}) { | ||
| 8473 | |||
| 8474 | $modHash{$key} = $initHash{$key}; | ||
| 8475 | } | ||
| 8476 | } | ||
| 8477 | |||
| 8478 | # Setup | ||
| 8479 | my $self = { | ||
| 8480 | _objName => 'table_obj_' . $number, | ||
| 8481 | _objClass => $class, | ||
| 8482 | _parentFile => undef, # No parent file object | ||
| 8483 | _parentWorld => undef, # No parent file object | ||
| 8484 | _privFlag => TRUE, # All IVs are private | ||
| 8485 | |||
| 8486 | # Standard table object IVs | ||
| 8487 | # ------------------------- | ||
| 8488 | |||
| 8489 | # The table object's number within the parent strip object (matches | ||
| 8490 | # GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to | ||
| 8491 | # access its default IVs) | ||
| 8492 | number => $number, | ||
| 8493 | # A name for the table object. Can be any string or, if no name was specified in the | ||
| 8494 | # call to the calling function, $name is the same as $number. (No part of the code | ||
| 8495 | # checks that table object names are unique; if two or more table objects share the | ||
| 8496 | # same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary | ||
| 8497 | # table objects. Max 16 chars) | ||
| 8498 | name => $name, | ||
| 8499 | # The type of table object (custom table objects should use a ->type starting with | ||
| 8500 | # 'custom_' to avoid clashing with future built-in table objects) | ||
| 8501 | type => 'internal', | ||
| 8502 | # The parent strip object (GA::Strip::Table) | ||
| 8503 | stripObj => $stripObj, | ||
| 8504 | # The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for | ||
| 8505 | # temporary table objects | ||
| 8506 | winObj => $winObj, | ||
| 8507 | # The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip | ||
| 8508 | # object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary | ||
| 8509 | # table objects | ||
| 8510 | zoneObj => $zoneObj, | ||
| 8511 | |||
| 8512 | # Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is | ||
| 8513 | # created. Set to FALSE if it can't be deleted (except in a few circumstances, such as | ||
| 8514 | # when a connection to a world terminates) | ||
| 8515 | allowRemoveFlag => TRUE, | ||
| 8516 | # Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is | ||
| 8517 | # created. Set to FALSE if it can't be resized | ||
| 8518 | allowResizeFlag => TRUE, | ||
| 8519 | # Initialisation settings stored as a hash (see the comments above) | ||
| 8520 | initHash => \%modHash, | ||
| 8521 | # Reference to a function to call when some widget is used. This IV is set only when | ||
| 8522 | # required by this type of table object. It can be set by a call to | ||
| 8523 | # $self->set_func() or by some setting in $self->initHash, which is applied in the | ||
| 8524 | # call to $self->objEnable(). To obtain a reference to an OOP method, you can use the | ||
| 8525 | # generic object function Games::Axmud->getMethodRef() | ||
| 8526 | funcRef => undef, | ||
| 8527 | # A value passed to ->funcRef when it is called which identifies this table object and | ||
| 8528 | # its widget(s). Can be any value, including 'undef'. It can be set by a call to | ||
| 8529 | # $self->set_id() or by some setting in $self->initHash, which is applied in the call | ||
| 8530 | # to $self->objEnable() | ||
| 8531 | funcID => '', | ||
| 8532 | |||
| 8533 | # The container widget(s) for this table object; both IVs are always set to the same | ||
| 8534 | # widget | ||
| 8535 | packingBox => undef, # Gtk3::VBox | ||
| 8536 | packingBox2 => undef, # Gtk3::VBox | ||
| 8537 | |||
| 8538 | # Other IVs | ||
| 8539 | # --------- | ||
| 8540 | |||
| 8541 | # The pseudo-window's window object, an ordinary 'grid' window object whose ->number is | ||
| 8542 | # -1 to mark it as a pseudo-window, created via a direct call to its ->new function | ||
| 8543 | # rather than calling GA::Obj::Workspace->createGridWin as we normally would | ||
| 8544 | # Its ->winSetup and ->winEnable functions are never called; instead, the code in this | ||
| 8545 | # table object sets up the window's widgets | ||
| 8546 | pseudoWinObj => undef, | ||
| 8547 | }; | ||
| 8548 | |||
| 8549 | # Bless the object into existence | ||
| 8550 | bless $self, $class; | ||
| 8551 | |||
| 8552 | return $self; | ||
| 8553 | } | ||
| 8554 | |||
| 8555 | ################## | ||
| 8556 | # Methods | ||
| 8557 | |||
| 8558 | # Standard table object functions | ||
| 8559 | |||
| 8560 | sub objEnable { | ||
| 8561 | |||
| 8562 | # Called by GA::Strip::Table->addTableObj | ||
| 8563 | # Sets up the table object's widgets | ||
| 8564 | # | ||
| 8565 | # Expected arguments | ||
| 8566 | # (none besides $self) | ||
| 8567 | # | ||
| 8568 | # Return values | ||
| 8569 | # 'undef' on improper arguments or if the table object can't be created | ||
| 8570 | # 1 on success | ||
| 8571 | |||
| 8572 | my ($self, $check) = @_; | ||
| 8573 | |||
| 8574 | # Local variables | ||
| 8575 | my ($winType, $winName, $package, $owner, $session, $winmap); | ||
| 8576 | |||
| 8577 | # Check for improper arguments | ||
| 8578 | if (defined $check) { | ||
| 8579 | |||
| 8580 | return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_); | ||
| 8581 | } | ||
| 8582 | |||
| 8583 | # Interpret $self->initHash, replacing any invalid values | ||
| 8584 | $winType = $self->ivShow('initHash', 'win_type'); | ||
| 8585 | $winName = $self->ivShow('initHash', 'win_name'); | ||
| 8586 | $package = $self->ivShow('initHash', 'package'); | ||
| 8587 | $owner = $self->ivShow('initHash', 'owner'); | ||
| 8588 | $session = $self->ivShow('initHash', 'session'); | ||
| 8589 | $winmap = $self->ivShow('initHash', 'winmap'); | ||
| 8590 | |||
| 8591 | if ( | ||
| 8592 | ! $winType | ||
| 8593 | || ( | ||
| 8594 | $winType ne 'map' && $winType ne 'protocol' && $winType ne 'fixed' | ||
| 8595 | && $winType ne 'custom' | ||
| 8596 | ) || ($winType eq 'fixed' && ! $package) | ||
| 8597 | ) { | ||
| 8598 | return undef; | ||
| 8599 | } | ||
| 8600 | |||
| 8601 | if (! $winName) { | ||
| 8602 | |||
| 8603 | $winName = $winType; | ||
| 8604 | } | ||
| 8605 | |||
| 8606 | # Create the packing box | ||
| 8607 | my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::VBox->new(FALSE, 0)); | ||
| 8608 | |||
| 8609 | # Set the package name (for 'fixed' windows, $package is definitely set) | ||
| 8610 | if (! $package) { | ||
| 8611 | |||
| 8612 | if ($winType eq 'map') { | ||
| 8613 | $package = 'Games::Axmud::Win::Map'; | ||
| 8614 | } else { | ||
| 8615 | $package = 'Games::Axmud::Win::Internal'; | ||
| 8616 | } | ||
| 8617 | } | ||
| 8618 | |||
| 8619 | # Create a pseudo-window object | ||
| 8620 | my $winObj = $package->new( | ||
| 8621 | -1, # Pseudo-window objects have the ->number -1 | ||
| 8622 | $winType, | ||
| 8623 | $winName, | ||
| 8624 | $self->winObj->workspaceObj, | ||
| 8625 | $owner, # May be 'undef' | ||
| 8626 | $session, # May be 'undef' | ||
| 8627 | undef, # No workspace grid | ||
| 8628 | undef, # No area object | ||
| 8629 | $winmap, # May be 'undef' | ||
| 8630 | ); | ||
| 8631 | |||
| 8632 | if (! $winObj) { | ||
| 8633 | |||
| 8634 | return undef; | ||
| 8635 | } | ||
| 8636 | |||
| 8637 | # Update IVs for the window object | ||
| 8638 | $winObj->ivPoke('pseudoWinTableObj', $self); | ||
| 8639 | |||
| 8640 | if ($winType eq 'protocol' || $winType eq 'custom') { | ||
| 8641 | |||
| 8642 | # Code to replace the pseudo-window object's ->winSetup | ||
| 8643 | $winObj->set_winWidget($self->winObj->winWidget); | ||
| 8644 | $winObj->set_winBox($packingBox2); | ||
| 8645 | $winObj->setKeyPressEvent(); # 'key-press-event' | ||
| 8646 | $winObj->setKeyReleaseEvent(); # 'key-release-event' | ||
| 8647 | $winObj->drawWidgets(); | ||
| 8648 | |||
| 8649 | # Code to replace the pseudo-window object's ->winEnable | ||
| 8650 | $winObj->set_enabledFlag(TRUE); | ||
| 8651 | $winObj->setConfigureEvent(); # 'check-resize' | ||
| 8652 | $winObj->setFocusInEvent(); # 'focus-in-event' | ||
| 8653 | $winObj->setFocusOutEvent(); # 'focus-out-event' | ||
| 8654 | |||
| 8655 | } elsif ($winType eq 'map') { | ||
| 8656 | |||
| 8657 | # Code to replace the pseudo-window object's ->winSetup | ||
| 8658 | $winObj->set_winWidget($self->winObj->winWidget); | ||
| 8659 | $winObj->set_winBox($packingBox2); | ||
| 8660 | $winObj->setFocusOutEvent(); # 'focus-out-event' | ||
| 8661 | $winObj->drawWidgets(); | ||
| 8662 | |||
| 8663 | # Code to replace the pseudo-window object's ->winEnable | ||
| 8664 | $winObj->set_enabledFlag(TRUE); | ||
| 8665 | if ($session) { | ||
| 8666 | |||
| 8667 | $session->set_mapWin($winObj); | ||
| 8668 | $session->mapObj->set_trackAloneFlag(FALSE); | ||
| 8669 | } | ||
| 8670 | |||
| 8671 | } elsif ($winType eq 'fixed') { | ||
| 8672 | |||
| 8673 | # Code to replace the pseudo-window object's ->winSetup | ||
| 8674 | $winObj->set_winWidget($self->winObj->winWidget); | ||
| 8675 | $winObj->set_winBox($packingBox2); | ||
| 8676 | $winObj->drawWidgets(); | ||
| 8677 | |||
| 8678 | # Code to replace the pseudo-window object's ->winEnable | ||
| 8679 | $winObj->set_enabledFlag(TRUE); | ||
| 8680 | } | ||
| 8681 | |||
| 8682 | # Set expansion | ||
| 8683 | $packingBox->set_hexpand(TRUE); | ||
| 8684 | $packingBox->set_vexpand(TRUE); | ||
| 8685 | |||
| 8686 | # Update IVs for this table object | ||
| 8687 | $self->ivPoke('packingBox', $packingBox); | ||
| 8688 | $self->ivPoke('packingBox2', $packingBox2); | ||
| 8689 | $self->ivPoke('pseudoWinObj', $winObj); | ||
| 8690 | |||
| 8691 | return 1; | ||
| 8692 | } | ||
| 8693 | |||
| 8694 | # sub objDestroy { # Inherited from GA::Generic::Table | ||
| 8695 | |||
| 8696 | # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table | ||
| 8697 | |||
| 8698 | # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table | ||
| 8699 | |||
| 8700 | # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table | ||
| 8701 | |||
| 8702 | # ->signal_connects | ||
| 8703 | |||
| 8704 | # Other functions | ||
| 8705 | |||
| 8706 | ################## | ||
| 8707 | # Accessors - set | ||
| 8708 | |||
| 8709 | # (Get equivalents) | ||
| 8710 | |||
| 8711 | ################## | ||
| 8712 | # Accessors - get | ||
| 8713 | |||
| 8714 | sub pseudoWinObj | ||
| 8715 | { $_[0]->{pseudoWinObj} } | ||
| 8716 | } | ||
| 8717 | |||
| 8718 | # Custom table objects | ||
| 8719 | |||
| 8720 | { package Games::Axmud::Table::Custom; | ||
| 8721 | |||
| 8722 | # Any user-written table objects should inherit from this object | ||
| 8723 | |||
| 8724 | use strict; | ||
| 8725 | use warnings; | ||
| 8726 | # use diagnostics; | ||
| 8727 | |||
| 8728 | use Glib qw(TRUE FALSE); | ||
| 8729 | |||
| 8730 | our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud); | ||
| 8731 | |||
| 8732 | ################## | ||
| 8733 | # Constructors | ||
| 8734 | |||
| 8735 | # sub new {} # Inherited from GA::Generic::Table | ||
| 8736 | |||
| 8737 | ################## | ||
| 8738 | # Methods | ||
| 8739 | |||
| 8740 | # Standard table object functions | ||
| 8741 | |||
| 8742 | # sub objEnable {} # Inherited from GA::Generic::Table | ||
| 8743 | |||
| 8744 | # sub objDestroy {} # Inherited from GA::Generic::Table | ||
| 8745 | |||
| 8746 | # sub setWidgetsIfSession {} # Inherited from GA::Generic::Table | ||
| 8747 | |||
| 8748 | # sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table | ||
| 8749 | |||
| 8750 | # sub setWidgetsOnResize {} # Inherited from GA::Generic::Table | ||
| 8751 | |||
| 8752 | # ->signal_connects | ||
| 8753 | |||
| 8754 | # Other functions | ||
| 8755 | |||
| 8756 | ################## | ||
| 8757 | # Accessors - set | ||
| 8758 | |||
| 8759 | ################## | ||
| 8760 | # Accessors - get | ||
| 8761 | } | ||
| 8762 | |||
| 8763 | # Package must return a true value | ||
| 8764 | 1 |