# Copyright (c) 1999-2011 bivio Software, Inc. All rights reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: Page.pm,v 2.24 2011/10/02 00:03:22 nagler Exp $ package Bivio::UI::HTML::Widget::Page; use strict; use Bivio::Base 'UI.Widget'; use Bivio::UI::ViewLanguageAUTOLOAD; # C is an HTML C tag surrounding # a widget, which is usually a # L, # but might be a # L. # The widget or its children should be a # L. # # The link, bg, and text colors are specified by the # L names: # page_bg, page_text, page_link, page_vlink, and page_alink. # page_bg must be defined, but the others may be undefined iwc # the color defaults to the browser default. # # # # background : string # # Name of the icon to use for the page background. # # body : Bivio::UI::Widget (required) # # How to render the C tag contents. Usually a # L # or # L. # # head : Bivio::UI::Widget (required) # # How to render the C tag contents. # Usually a # L. # # page_alink_color : string # # Facade color for active links. # # page_bgcolor : string # # Facade color for the page background. # # page_link_color : string # # Facade color for links. # # page_text_color : string # # Facade color for text. # # page_vlink_color : string # # Facade color for visited links. # # script : any [Script()] # # Renders script code in the header. # # style : any [Style()] # # Renders an inline style in the header. # # want_page_print : any [0] # # If true, adds onLoad=window.print() to the body tag. # # xhtml : boolean [0] # # If set, the page will be generated with the following XHTML doctype # # # # # # # html_tag_attrs : any [] # # Attributes to be applied to the html_tag used to generate the tag. Works on # and tags. # # Must have a leading space. # # # # # Bivio::UI::Color.page_link : string # # Color of links. # # INCOMPLETE our($VERSION) = sprintf('%d.%02d', q$Revision: 2.24 $ =~ /\d+/g); our($_TRACE); b_use('IO.Trace'); my($_CL) = b_use('IO.ClassLoader'); my($_HANDLERS) = b_use('Biz.Registrar')->new; sub execute { my($self, $req) = @_; # Calls L # as text/html. return $self->execute_with_content_type($req, 'text/html'); } sub initialize { my($self) = shift; $self->initialize_attr('head'); $self->initialize_attr('body'); $self->unsafe_initialize_attr('background'); $self->unsafe_initialize_attr('body_class'); $self->unsafe_initialize_attr('html_tag_attrs'); $self->internal_initialize_head_attrs(@_); return; } sub internal_initialize_head_attrs { my($self) = @_; $self->unsafe_initialize_attr('style'); $self->unsafe_initialize_attr('xhtml'); foreach my $x (qw(Style Script JavaScript)) { $self->initialize_attr(lc($x), sub {vs_call($x)}); } $self->initialize_attr( _page_print_script => $self->get('script')->new('page_print'), ) if $self->unsafe_initialize_attr('want_page_print'); return; } sub internal_new_args { my($proto, $head, $body, $attrs) = @_; # Implements positional argument parsing for L. return '"head" must be defined' unless defined($head); return '"body" must be defined' unless defined($body); return { head => $head, body => $body, ($attrs ? %$attrs : ()), }; } sub internal_render_head_attrs { my($self, $source) = @_; my($b); my($x) = ''; $self->map_invoke( unsafe_render_attr => [ map( [$_, $source, \$b], 'head', 'style', $self->unsafe_render_attr('want_page_print', $source, \$x) && $x ? '_page_print_script' : (), 'script', 'javascript', ), ], undef, [$source], ); # IE caches too much. $b .= qq{\n} .qq{\n} if $source->get_request->get('Type.UserAgent')->has_over_caching_bug; return $b; } sub render { my($self, $source, $buffer) = @_; my($req) = $source->get_request; my($xhtml) = $self->internal_setup_xhtml($req); my($body) = $self->render_attr('body', $source); $$buffer .= ($xhtml # ? '' ? '' : '') . "\nrender_simple_attr(html_tag_attrs => $source) . ">\n" . $self->internal_render_head_attrs($source) . 'format_html( $self->get_or_default('page_bgcolor', 'page_bg'), 'bgcolor', $req); foreach my $c ('text', 'link', 'alink', 'vlink') { my($n) = 'page_'.$c; $$buffer .= Bivio::UI::Color->format_html( $self->get_or_default($n.'_color', $n), $c, $req); } my($x) = ''; $$buffer .= Bivio::UI::Icon->format_html_attribute( $x, 'background', $req ) if $self->unsafe_render_attr('background', $source, \$x) && $x; $$buffer .= vs_html_attrs_render_one( $self, $source, 'body_class'); $self->get('body')->unsafe_render_attr('html_tag_attrs', $source, $buffer) if Bivio::UI::Widget->is_blessed($self->get('body')) && $self->get('body')->can('unsafe_render_attr'); $$buffer .= ">\n$$body\n\n"; $_HANDLERS->do_filo(handle_page_render_end => [$source, $buffer]); return; } sub internal_setup_xhtml { my($self, $req) = @_; $req->put(font_with_style => $req->get('Type.UserAgent')->is_css_compatible && $self->unsafe_get('style') ? 1 : 0, ); $req->put(xhtml => my $xhtml = $self->render_simple_attr('xhtml', $req)); return $xhtml; } sub register_handler { shift; $_HANDLERS->push_object(@_); return; } 1;