# Copyright 2002-2007 Interchange Development Group and others
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.

UserTag tabbed-display PosNumber     0
UserTag tabbed-display addAttr 
UserTag tabbed-display hasEndTag 
UserTag tabbed-display Interpolate 
UserTag tabbed-display NoReparse 
UserTag tabbed-display Version       1.6
UserTag tabbed-display Documentation <<EOD
=head1 NAME

tabbed-display

=head1 SYNOPSIS

    [tabbed-display OPTIONS]
        [tabbed-panel The title of one]
        The contents of one
        [/tabbed-panel]
        [tabbed-panel The contents of two]
        The contents of two
        [/tabbed-panel]
    [/tabbed-display]

=head1 DESCRIPTION

The [tabbed-display] ITL tag breaks text into a dynamic tabbed display.
There are many options which can change the size of the display,
colors, and styles.

NOTE: All sizes are in pixels to allow size calculation.

=head2 OPTIONS

=over 4

=item tab_bgcolor_template

Default #xxxxxx. A template where each "x" will be broken into
descending-brightness colors. The default value will cause
the selected tab to have a color of #eeeeee, the first unselected
tab will have #dddddd, the next #cccccc, etc. To create a yellow
series, use #ffffxx.

=item tab_height

Sets the height of the title tab. Default 30.

=item tab_width

Sets the width of the title tab. Default is 100.

=item panel_height

Sets the height of the panel display. Default 600.

=item panel_width

Sets the width of the panel display. Default is 800.

=item panel_id

To account for multiple tabbed displays in a page, the second
one should have a unique ID assigned to it. Default is "mvpan".

=item tab_horiz_offset

The amount that the tab will be offset from tabs in multi-row
displays to allow view of all tabs.  Default 10.

=item tab_vert_offset

The amount that the tab will be offset from tabs in multi-row
displays to allow view of all tabs.  Default 8.

=item tab_style

The style items which will be set for the title tab portion.
Default:

    text-align:center;
    font-family: sans-serif;
    line-height:150%;
    border:2px;
    border-color:#999999;
    border-style:outset;
    border-bottom-style:none;


=item panel_style

The style items which will be set for the panel portion.  Default:

    font-family: sans-serif;
    font-size: smaller;
    border: 2px;
    border-color:#999999;
    border-style:outset;

=item panel_prepend

A string which will be prepended to every panel content.
A typical value might be "<table>", which allows table rows to
be sent as content. This is the value used in Interchange's
table editor.


=item panel_append

A string which will be appended to every panel content.
A typical value might be "</table>", which allows table rows to
be sent as content. This is the value used in Interchange's
table editor.

=item contents

If you have an array set with the value of each panel's content,
you can send it as an array reference in the contents option.
This option will also accept a null-separated string as might
be found in a form input.

If there are contents in an array, the body text of the tag
is ignored.

=item titles

If you have an array set with the value of each tab's title,
you can send it as an array reference in the C<titles> option.
This option will also accept a null-separated string as might
be found in a form input.

If the title for a panel is set in the array, the title found in the
body text of the tag is ignored.

=back

=head2 Use in embedded Perl

The tabbed_display tag can be used in embedded Perl as well.

    my @titles = ( 'Title 1', 'Title 2' );
    my @contents = ( 'Content of panel 1: foo', 'Content of 2' );

    return $Tag->tabbed_display({
        titles => \@titles,
        contents => \@contents,
        panel_width => 600,
        panel_height => 400,
        tab_bgcolor_template => '#ffffxx',
    });

=cut
EOD
UserTag tabbed-display Routine       <<EOR
sub {
	my $opt = shift;
	my $body = shift;
#::logDebug("opt is $opt, body is $body");
	my $tit; my $cont;

	if($opt->{titles}) {
		if(ref($opt->{titles}) eq 'ARRAY') {
			$tit = delete $opt->{titles};
		}
		elsif($opt->{titles} =~ /\0/) {
			$tit = [ split /\0/, delete $opt->{titles} ];
		}
		elsif($opt->{titles} =~ /\n/) {
			$tit = [ split /\n/, delete $opt->{titles} ];
		}
		else {
			$tit = [ map { $::Scratch->{$_} } split /[\s,]+/, delete $opt->{titles}];
		}
	}

	if($opt->{contents}) {
		if(ref($opt->{contents}) eq 'ARRAY') {
			$cont = delete $opt->{contents};
		}
		elsif($opt->{contents} =~ /\0/) {
			$cont = [ split /\0/, delete $opt->{contents} ];
		}
	}

	$tit ||= [];
	if(! $cont) {
		$cont = [];
		while($body =~ s{
							\[tabbed[-_]panel (.*?) \]
									(.*?)
							\[/tabbed[-_]panel\]}
						{}xis
					)
		{
			push @$cont, $2;
			my $t = $1;
			if($t and $t =~ /\S/) {
				$tit->[$#$cont] ||= $t;
			}
		}
	}
	return Vend::Table::Editor::tabbed_display($tit, $cont, $opt);
}
EOR
