<?php

class MBox extends MContainerControl
{
    public $boxTitle;
    protected $boxInner;
    protected $borderStyle;

    /**
     * Some controls, like message boxes, don't require some buttons, the parameters are used to identify wich should or not be created.
     * Even if the parameter is true, the button is only generated if the configuration in miolo.conf (or module.conf) is enabled (true)
     *
     * @param $showHelp     (boolean) true if the help button should be created
     * @param $showMinimize (boolean) true if the minimize button should be created
     * @param $showClose    (boolean) true if the help button should be created
     */

    public function __construct( $caption = NULL, $close = '', $icon = '', $help = '', $showHelp=true, $showMinimize=true, $showClose=true )
    {
        $boxId = 'box' . MControl::$_number++;
        parent::__construct($boxId);

        $this->boxTitle =  is_null( $caption ) ? NULL : new MBoxTitle( '', $caption, $close, $icon, $help, $showHelp, $showMinimize, $showClose, $boxId );
        $this->setClass('mBox');
        $this->borderStyle = '';
    }

    /**
     *
     */
    public function setClose( $close )
    {
        if ( $this->boxTitle InstanceOf MBoxTitle )
        {
            $this->boxTitle->setClose( $close );
        }
    }

    /**
     *
     */
    public function setHelp( $help )
    {
        if ( $this->boxTitle InstanceOf MBoxTitle )
        {
            $this->boxTitle->setHelp( $help );
        }
    }

    /**
     *
     */
    public function setCaption( $caption )
    {
        if ( is_null( $caption ) )
        {
            $this->boxTitle = NULL;
        }
        elseif ( $this->boxTitle InstanceOf MBoxTitle )
        {
            $this->boxTitle->setText( $caption );
        }
    }

    public function getCaption()
    {
        if ( is_null( $this->boxTitle ) )
        {
             return NULL;
        }
        else
        {
            return $this->boxTitle->text;
        }
    }
    /**
     *
     */
    public function setBorderStyle( $style )
    {
        $this->borderStyle = $style;
    }

    /**
     *
     */
    public function setText( $text )
    {
        $this->setCaption($text);
    }
    /**
     *
     */
    public function generateInner()
    {
        $this->insertControl( $this->boxTitle );
        $this->inner = new MDiv( NULL, $this->getControls(), 'mBoxInner' );
        if ($this->borderStyle != '')
        {
            $this->inner->addStyle('border', $this->borderStyle);
        }

    }
}
?>