Games-Axmud
view release on metacpan or search on metacpan
lib/Games/Axmud/Table.pm view on Meta::CPAN
sub clearFlag
{ $_[0]->{clearFlag} }
sub checkFlag
{ $_[0]->{checkFlag} }
sub checkYes
{ $_[0]->{checkYes} }
sub checkNo
{ $_[0]->{checkNo} }
sub checkFunc
{ $_[0]->{checkFunc} }
sub checkType
{ $_[0]->{checkType} }
sub checkMin
{ $_[0]->{checkMin} }
sub checkMax
{ $_[0]->{checkMax} }
}
{ package Games::Axmud::Table::ComboBox;
use strict;
use warnings;
# use diagnostics;
use Glib qw(TRUE FALSE);
our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud);
##################
# Constructors
sub new {
# Called by GA::Strip::Table->addTableObj
# Creates the GA::Table::ComboBox, which contains a simple Gtk3::ComboBox
#
# Expected arguments
# $number - The table object's number within the parent strip object (matches
# GA::Strip::Table->tableObjCount, or -1 for a temporary table object
# created to access its default IVs)
# $name - A name for the table object. Can be any string or, if no name was
# specified in the call to the calling function, $name is the same as
# $number. (No part of the code checks that table object names are unique;
# if two or more table objects share the same ->name, usually the one with
# the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
# chars)
# $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table
# objects
# $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
# parent strip object's Gtk3::Grid for use exclusively by this table
# object. 'temp' for temporary table objects
#
# Optional arguments
# %initHash - A hash containing arbitrary data to use as the table object's
# initialisation settings. The table object should use default
# initialisation settings unless it can succesfully interpret one or more
# of the key-value pairs in the hash, if there are any
# - This type of table object recognises these initialisation settings:
#
# 'func' - Reference to a function to call when an item in the combobox
# is selected. If not specified or 'undef', it's up to the calling
# code to create its own ->signal_connect. To obtain a reference to an
# OOP method, you can use the generic object function
# Games::Axmud->getMethodRef()
# 'id' - A value passed to the function which identifies the button. If
# specified, can be any value except 'undef'. It's up to the
# calling code to keep track of the widgets it has created and their
# corresponding 'id' values
# 'list_ref' - Reference to a list used to fill the combobox. If 'undef'
# or if the referenced list is empty, the combobox is empty
# 'title' - A string to use as the combobox's title, e.g. 'Choose your
# favourite cat'. If 'undef', a title isn't used
# 'tooltips' - The text to display as tooltips for the button. Can be
# plain text or pango markup text. If not specified, 'undef' or an
# empty string, no tooltips are displayed
# 'normal_flag' - If TRUE (or not specified), the button's state is
# 'normal'. If FALSE, the button's state is 'insensitive' (nothing can
# interact with it)
# 'expand_flag' - Deprecated since v1.2.170; ignored if specified
# 'expand_horizontal_flag' - If TRUE or unspecified, the table object
# expands horizontally; if FALSE, it doesn't
# 'expand_vertical_flag' - If TRUE or unspecified, the table object
# expands vertically; if FALSE, it doesn't
#
# Return values
# 'undef' on improper arguments
# Blessed reference to the newly-created object on success
my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
# Local variables
my (
$winObj,
%modHash,
);
# Check for improper arguments
if (
! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
|| ! defined $zoneObj
) {
return $axmud::CLIENT->writeImproper($class . '->new', @_);
}
# Deal with temporary table objects
if ($stripObj eq 'temp') {
$winObj = 'temp';
} else {
$winObj = $stripObj->winObj;
}
# Default initialisation settings
%modHash = (
'func' => undef,
'id' => '',
'list_ref' => undef,
'title' => undef,
'tooltips' => undef,
'normal_flag' => TRUE,
'expand_flag' => TRUE, # Deprecated since v1.2.170
'expand_horizontal_flag' => TRUE,
'expand_vertical_flag' => TRUE,
);
# Interpret the initialisation settings in %initHash, if any
foreach my $key (keys %modHash) {
if (exists $initHash{$key}) {
if ($key =~ m/flag$/) {
lib/Games/Axmud/Table.pm view on Meta::CPAN
_parentWorld => undef, # No parent file object
_privFlag => TRUE, # All IVs are private
# Standard table object IVs
# -------------------------
# The table object's number within the parent strip object (matches
# GA::Strip::Table->tableObjCount, or -1 for a temporary table object created to
# access its default IVs)
number => $number,
# A name for the table object. Can be any string or, if no name was specified in the
# call to the calling function, $name is the same as $number. (No part of the code
# checks that table object names are unique; if two or more table objects share the
# same ->name, usually the one with the lowest ->number 'wins'. 'temp' for temporary
# table objects. Max 16 chars)
name => $name,
# The type of table object (custom table objects should use a ->type starting with
# 'custom_' to avoid clashing with future built-in table objects)
type => 'combo_box',
# The parent strip object (GA::Strip::Table)
stripObj => $stripObj,
# The parent strip object's window object (inheriting from GA::Generic::Win). 'temp' for
# temporary table objects
winObj => $winObj,
# The tablezone object (GA::Obj::Tablezone) which marks out an area of the parent strip
# object's Gtk3::Grid for use exclusively by this table object. 'temp' for temporary
# table objects
zoneObj => $zoneObj,
# Flag set to TRUE if this table object can be removed from the Gtk3::Grid, once it is
# created. Set to FALSE if it can't be deleted (except in a few circumstances, such as
# when a connection to a world terminates)
allowRemoveFlag => TRUE,
# Flag set to TRUE if this table object can be resized on the Gtk3::Grid, once it is
# created. Set to FALSE if it can't be resized
allowResizeFlag => TRUE,
# Initialisation settings stored as a hash (see the comments above)
initHash => \%modHash,
# Reference to a function to call when some widget is used. This IV is set only when
# required by this type of table object. It can be set by a call to
# $self->set_func() or by some setting in $self->initHash, which is applied in the
# call to $self->objEnable(). To obtain a reference to an OOP method, you can use the
# generic object function Games::Axmud->getMethodRef()
funcRef => undef,
# A value passed to ->funcRef when it is called which identifies this table object and
# its widget(s). Can be any value except 'undef'. It can be set by a call to
# $self->set_id() or by some setting in $self->initHash, which is applied in the call
# to $self->objEnable()
funcID => '',
# The container widget(s) for this table object
packingBox => undef, # Gtk3::Grid
packingBox2 => undef, # Gtk3::Grid
# Other IVs
# ---------
# Widgets
comboBox => undef, # Gtk3::ComboBox
# Item in the combobox used as a title ('undef' if no title specified). Set by
# $self->objEnable from $self->initHash
title => undef,
};
# Bless the object into existence
bless $self, $class;
return $self;
}
##################
# Methods
# Standard table object functions
sub objEnable {
# Called by GA::Strip::Table->addTableObj
# Sets up the table object's widgets
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments
# 1 on success
my ($self, $check) = @_;
# Local variables
my (
$funcRef, $funcID, $listRef, $title, $tooltips, $normalFlag, $hExpandFlag, $vExpandFlag,
);
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->objEnable', @_);
}
# Interpret $self->initHash, replacing any invalid values
$funcRef = $self->ivShow('initHash', 'func');
$funcID = $self->ivShow('initHash', 'id');
$listRef = $self->ivShow('initHash', 'list_ref');
$title = $self->ivShow('initHash', 'title');
$tooltips = $self->ivShow('initHash', 'tooltips');
$normalFlag = $self->testFlag($self->ivShow('initHash', 'normal_flag'));
$hExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_horizontal_flag'));
$vExpandFlag = $self->testFlag($self->ivShow('initHash', 'expand_vertical_flag'));
# Create packing box(es)
my ($packingBox, $packingBox2) = $self->setupPackingBoxes(Gtk3::Grid->new());
# Create the Gtk3::ComboBox
my $comboBox = Gtk3::ComboBoxText->new();
$packingBox2->attach($comboBox, 0, 0, 1, 1);
if (defined $title) {
$comboBox->append_text($title);
}
foreach my $item (@$listRef) {
$comboBox->append_text($item);
}
# The first item in the combobox is the first one selected
$comboBox->set_active(0);
if (defined $tooltips && $tooltips ne '') {
$comboBox->set_tooltip_markup($tooltips);
}
if (! $normalFlag) {
$comboBox->set_state('insensitive');
}
# Set expansion
$comboBox->set_hexpand($hExpandFlag);
$comboBox->set_vexpand($vExpandFlag);
# Update IVs
$self->ivPoke('funcRef', $funcRef);
$self->ivPoke('funcID', $funcID);
$self->ivPoke('packingBox', $packingBox);
$self->ivPoke('packingBox2', $packingBox2);
$self->ivPoke('comboBox', $comboBox);
$self->ivPoke('title', $title);
# Set up ->signal_connects
$self->setChangedEvent();
return 1;
}
# sub objDestroy { # Inherited from GA::Generic::Table
# sub setWidgetsIfSession {} # Inherited from GA::Generic::Table
# sub setWidgetsChangeSession {} # Inherited from GA::Generic::Table
# sub setWidgetsOnResize {} # Inherited from GA::Generic::Table
# ->signal_connects
sub setChangedEvent {
# Called by $self->objEnable
#
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $check) = @_;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->setChangedEvent', @_);
}
$self->comboBox->signal_connect('changed' => sub {
my ($currentFuncRef, $value);
$currentFuncRef = $self->funcRef;
$value = $self->comboBox->get_active_text();
# (If the user selects the title, ignore it)
if ($currentFuncRef && (! defined $self->title || $value ne $self->title)) {
&$currentFuncRef($self, $self->comboBox, $self->funcID, $value);
}
});
return 1;
}
# Other functions
sub resetCombo {
# Can be called by anything
# Resets the appearance of the combobox
# Expected arguments
# (none besides $self)
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $check) = @_;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->resetCombo', @_);
}
$self->comboBox->set_active(0);
$self->comboBox->popdown();
return 1;
}
##################
# Accessors - set
# sub set_func {} # Inherited from GA::Generic::Table
# sub set_id {} # Inherited from GA::Generic::Table
sub set_list {
my ($self, $title, @list) = @_;
# Local variables
my ($funcRef, $model);
# (No improper arguments to check)
# Temporarily resetting $self->funcRef prevents the ->signal_connect from calling that
# function while we're resetting the combobox
$funcRef = $self->funcRef;
$self->ivUndef('funcRef');
# Empty the combobox...
$model = $self->comboBox->get_model();
$model->clear();
# ...and refill it (if specified)
if (defined $title) {
$self->comboBox->append_text($title);
$self->ivPoke('title', $title);
} else {
$self->ivUndef($title);
}
foreach my $item (@list) {
$self->comboBox->append_text($item);
}
# The first item in the combobox is the first one selected
$self->comboBox->set_active(0);
$self->comboBox->popdown();
# Restore the combobox to normal operations
$self->ivPoke('funcRef', $funcRef);
return 1;
}
sub set_normal {
my ($self, $flag, $check) = @_;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->set_normal', @_);
}
if (! $flag) {
$self->comboBox->set_state('insensitive');
} else {
$self->comboBox->set_state('normal');
}
return 1;
}
sub set_tooltips {
my ($self, $tooltips, $check) = @_;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->set_tooltips', @_);
}
if (! defined $tooltips || $tooltips eq '') {
$self->comboBox->set_tooltip_text(undef);
} else {
$self->comboBox->set_tooltip_markup($tooltips);
}
return 1;
}
# (Get equivalents)
sub get_normal {
# Returns TRUE for 'normal', FALSE for 'insensitive' or any other value
my ($self, $check) = @_;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->get_normal', @_);
}
if ($self->comboBox->get_state eq 'normal') {
return TRUE;
} else {
return FALSE;
}
return 1;
}
sub get_text {
# Returns 'undef' if the combobox's title is selected
my ($self, $check) = @_;
# Local variables
my $text;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->get_text', @_);
}
$text = $self->comboBox->get_active_text();
if (defined $self->title && $self->title eq $text) {
return undef;
} else {
return $text;
}
}
sub get_tooltips {
# Returns string
my ($self, $check) = @_;
# Check for improper arguments
if (defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->get_tooltips', @_);
}
return $self->comboBox->get_tooltip_text();
}
##################
# Accessors - get
sub comboBox
{ $_[0]->{comboBox} }
sub title
{ $_[0]->{title} }
}
{ package Games::Axmud::Table::SimpleList;
use strict;
use warnings;
# use diagnostics;
use Glib qw(TRUE FALSE);
our @ISA = qw(Games::Axmud::Generic::Table Games::Axmud);
##################
# Constructors
sub new {
# Called by GA::Strip::Table->addTableObj
# Creates the GA::Table::SimpleList, which contains a simple GA::Obj::SimpleList
#
# Expected arguments
# $number - The table object's number within the parent strip object (matches
# GA::Strip::Table->tableObjCount, or -1 for a temporary table object
# created to access its default IVs)
# $name - A name for the table object. Can be any string or, if no name was
# specified in the call to the calling function, $name is the same as
# $number. (No part of the code checks that table object names are unique;
# if two or more table objects share the same ->name, usually the one with
# the lowest ->number 'wins'. 'temp' for temporary table objects. Max 16
# chars)
# $stripObj - The parent strip object (GA::Strip::Table). 'temp' for temporary table
# objects
# $zoneObj - The tablezone object (GA::Obj::Tablezone) which marks out an area of the
# parent strip object's Gtk3::Grid for use exclusively by this table
# object. 'temp' for temporary table objects
#
# Optional arguments
# %initHash - A hash containing arbitrary data to use as the table object's
# initialisation settings. The table object should use default
# initialisation settings unless it can succesfully interpret one or more
# of the key-value pairs in the hash, if there are any
# - This type of table object recognises these initialisation settings:
#
# 'frame_title' - If specified, the table object is drawn inside a frame
# with the specified title. If 'undef', an empty string or not
# specified, the table object does not use a frame and title
# 'func' - Reference to a function to call when an item in the combobox
# is selected. If not specified or 'undef', it's up to the calling
# code to create its own ->signal_connect. To obtain a reference to an
# OOP method, you can use the generic object function
# Games::Axmud->getMethodRef()
# 'id' - A value passed to the function which identifies the button. If
# specified, can be any value except 'undef'. It's up to the
# calling code to keep track of the widgets it has created and their
# corresponding 'id' values
# 'column_ref' - Reference to a list of column headings and types, in the
# form ('heading', 'column_type', 'heading', 'column_type'...), where
# 'column_type' is one of the column types recognised by
# GA::Obj::SimpleList, i.e. 'text', 'markup', 'int', 'double',
# 'bool', 'scalar' or 'pixbuf'. If 'undef' or an empty list, a single
# column of type 'text' is created. If the list contains an odd
# number of items, the final one is discarded
# 'data_ref' - Reference to a list used to populate the
# GA::Obj::SimpleList. If there are 2 columns, a list in the form
# (a, b, a, b...) is expected. If there are 3 columns, a list in the
# form (a, b, c, a, b, c) is expected. If 'undef' or an empty list,
# nothing is added to the simple list
# 'expand_horizontal_flag' - If TRUE or not specified, the table object
# expands horizontally; if FALSE, it doesn't
# 'expand_vertical_flag' - If TRUE or not specified, the table object
# expands vertically; if FALSE, it doesn't
#
# Return values
# 'undef' on improper arguments
# Blessed reference to the newly-created object on success
my ($class, $number, $name, $stripObj, $zoneObj, %initHash) = @_;
# Local variables
my (
$winObj,
%modHash,
);
# Check for improper arguments
if (
! defined $class || ! defined $number || ! defined $name || ! defined $stripObj
|| ! defined $zoneObj
) {
return $axmud::CLIENT->writeImproper($class . '->new', @_);
}
# Deal with temporary table objects
if ($stripObj eq 'temp') {
$winObj = 'temp';
} else {
$winObj = $stripObj->winObj;
}
# Default initialisation settings
%modHash = (
'frame_title' => undef,
'func' => undef,
'id' => '',
'column_ref' => undef,
'data_ref' => undef,
'expand_horizontal_flag' => TRUE,
( run in 1.168 second using v1.01-cache-2.11-cpan-8dfa8b56332 )