package FBP::Window;

=pod

=head1 NAME

FBP::Window - Base class for all graphical wxWindow objects

=cut

use Mouse;
use Scalar::Util ();

our $VERSION = '0.18';

extends 'FBP::Object';
with    'FBP::Children';
with    'FBP::KeyEvent';
with    'FBP::MouseEvent';
with    'FBP::FocusEvent';





######################################################################
# Direct Properties

=pod

=head2 id

The C<id> method returns the numeric wxWidgets identifier for the window.

=cut

has id => (
	is  => 'ro',
	isa => 'Str',
);

=pod

=head2 name

The C<name> method returns the logical name of the object.

=cut

has name => (
	is  => 'ro',
	isa => 'Str',
);

=pod

=head2 enabled

The C<enabled> method indicates if the object is enabled or not.

=cut

has enabled => (
	is  => 'ro',
	isa => 'Bool',
);

=pod

=head2 subclass

The C<subclass> method returns the literal C-style 'subclass' property
produced by wxFormBuilder.

The format of this raw version is 'ClassName;headerfile.h'.

=cut

has subclass => (
	is       => 'ro',
	isa      => 'Str',
	required => 1,
	default  => '',
);

=pod

=head2 pos

The C<pos> method returns the position of the window.

=cut

has pos => (
	is  => 'ro',
	isa => 'Str',
);

=pod

=head2 size

The C<size> method returns the size of the window, if it has a specific
strict size.

=cut

has size => (
	is  => 'ro',
	isa => 'Str',
);

=pod

=head2 window_style

The C<window_style> method returns a set of Wx style flags that are common
to all window types.

=cut

has window_style => (
	is  => 'ro',
	isa => 'Str',
);





######################################################################
# Derived Values

=pod

=head2 styles

The C<styles> method returns the merged set of all constructor style flags
for the object.

You should generally call this method if you are writing code generators,
rather than calling C<style> or C<window_style> methods specifically.

=cut

sub styles {
	my $self   = shift;
	my @styles = grep { length $_ } (
		$self->can('style') ? $self->style : (),
		$self->window_style,
	) or return '';
	return join '|', @styles;
}

=pod

=head2 wxclass

The C<wxclass> method determines the Perl class that should be used to
instantiate this window. Most of the time this will be a standard class,
but it may be different if a custom C<subclass> property has been set.

=cut

sub wxclass {
	my $self = shift;

	# If a custom class is defined, use it literally
	my $subclass = $self->subclass;
	if ( length $subclass ) {
		my ($wxclass, $header) = split /;/, $subclass;
		if ( defined $wxclass and length $wxclass ) {
			return $wxclass;
		}
	}

	# Fall through to the default.
	# For now, derive it automatically from the FBP child object.
	my $wxclass = Scalar::Util::blessed($self);
	if ( $wxclass =~ s/^FBP::/Wx::/ ) {
		return $wxclass;
	}

	# No idea what to do at this point...
	die 'Failed to derive Wx class from FBP class';
}

1;

=pod

=head1 SUPPORT

Bugs should be reported via the CPAN bug tracker at

L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=FBP>

For other issues, or commercial enhancement or support, contact the author.

=head1 AUTHOR

Adam Kennedy E<lt>adamk@cpan.orgE<gt>

=head1 COPYRIGHT

Copyright 2009 - 2011 Adam Kennedy.

This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the
LICENSE file included with this module.

=cut
