<?php
/*
GUI.php, the main window and other widgets for creating GUI's
Copyright (C) 2004 Arend van Beelen, Auton Rijnsburg
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.
This program 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 General Public License for
more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For any questions, comments or whatever, you may mail me at: hide@address.com
*/
require_once('Constants.php');
require_once('Locale.php');
require_once('Messages.php');
require_once('Output.php');
require_once('Widgets.php');
require_once('Windows.php');
/**
* @brief The main window in which you can create your GUI.
*
* Every application should have exactly one main window. This is the main
* window in which you create your interface. You can also create new windows
* using classes like Window.
*
* The main window is usually instantiated by an Aukyla Frontend.
*/
class MainWindow extends Window
{
/**
* Constructor.
*
* Creates a new main window in which you can build your user
* interface.
*
* @param title Title of the main window.
*
* @note Only one MainWindow instance can be created.
*/
public function __construct($title = '')
{
parent::__construct(null, '', $title);
$instance = self::instance();
if($instance !== null)
{
die('Only one MainWindow instance can be created.');
}
else
{
self::$instance = $this;
}
$this->windowTag = 'mainwindow';
}
/**
* Returns the global main window instance.
*
* @return Instance of the main window widget. If no main window has
* been created yet, this is @p null.
*/
public static function instance()
{
return self::$instance;
}
protected $windowTag;
private static $instance = null;
}
/**
* @brief A document section.
*/
class Section extends Container
{
/**
* Constructor.
*
* @param parent Container to add this widget to.
*/
public function __construct(Container $parent)
{
parent::__construct($parent);
}
public function show()
{
Output::write('<section'.$this->parentProperties().'>');
parent::show();
Output::write('</section>');
}
}
/**
* @brief A simple identifiable container widget.
*/
class Box extends Container
{
public function __construct(Container $parent, $id = '')
{
parent::__construct($parent, $id);
}
/**
* @deprecated
*
* @return The string 'vertical'.
*/
public function orientation()
{
return 'vertical';
}
/**
* @deprecated
*/
public function setOrientation($orientation)
{
}
public function show()
{
Output::write("<box".$this->parentProperties().'>');
parent::show();
Output::write('</box>');
}
}
/**
* @brief A header widget.
*/
class Header extends RawContainer
{
public function show()
{
Output::write('<header'.$this->parentProperties().'>');
parent::show();
Output::write('</header>');
}
}
/**
* @brief A simple paragraph widget.
*/
class Paragraph extends RawContainer
{
public function show()
{
Output::write('<paragraph'.$this->parentProperties().'>');
parent::show();
Output::write('</paragraph>');
}
}
/**
* @brief A hyper-link widget.
*/
class Link extends RawContainer
{
/**
* Constructor.
*
* @param parent Container to add this widget to.
* @param url The URL to point to.
* @param text Text shown in the link.
*/
public function __construct(Container $parent, $url, $text = '')
{
parent::__construct($parent, $text);
$this->url = $url;
}
/**
* Returns the URL to which this link points.
*
* @return The URL of this link.
*
* @sa setUrl()
*/
public function url()
{
return $this->url;
}
/**
* Sets a new URL to link to.
*
* @param url The new URL to link to.
*
* @sa url()
*/
public function setUrl($url)
{
$this->url = $url;
}
/**
* Show the link.
*/
public function show()
{
Output::write("<link href=\"{$this->url}\"".$this->parentProperties().'>');
parent::show();
Output::write('</link>');
}
private $url;
}
/**
* @brief A groupbox widget.
*
* Groupboxes are used to group other widgets together so they form a unit to
* the user.
*/
class GroupBox extends RawContainer
{
/**
* Constructor.
*
* Creates a new groupbox.
*
* @param parent Container to add this groupbox to.
* @param label The label to be shown on the groupbox.
*/
public function __construct(Container $parent, $label)
{
parent::__construct($parent);
$this->label = $label;
}
/**
* Returns the label displayed on this groupbox.
*
* @return The label of the groupbox.
*
* @sa setLabel()
*/
public function label()
{
return $this->label;
}
/**
* Sets a new label on the groupbox.
*
* @param label The new label to display on the groupbox.
*
* @sa label()
*/
public function setLabel($label)
{
$this->label = $label;
}
public function show()
{
Output::write("<groupbox label=\"{$this->label}\"".$this->parentProperties().'>');
parent::show();
Output::write('</groupbox>');
}
private $label;
}
/**
* @brief An image widget.
*
* Inserts an image using a URL as source. You can set text on this widget which
* will be used as alternative text if the URL can't be loaded.
*/
class Image extends RawWidget
{
/**
* Constructor.
*
* @param parent Container to add this image to.
* @param url The URL to the image.
*/
function __construct(Container $parent, $url)
{
parent::__construct($parent);
$this->title = '';
$this->url = $url;
}
/**
* Sets the title of the image. The title is shown when the user hovers over
* the image with the mouse.
*
* @param title The new title of the image.
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Show the link.
*/
public function show()
{
$titleProperty = ($this->title == '' ? '' : " title=\"{$this->title}\"");
Output::write("<image src=\"{$this->url}\" alt=\"{$this->text}\"$titleProperty".$this->parentProperties().' />');
}
protected $text;
private $title;
private $url;
}
/**
* @brief A single line.
*
* A single line of text which starts on a new line and ends with a newline.
*/
class Line extends RawContainer
{
/**
* Constructor.
*
* @param parent Parent widget to add this line to.
* @param text Text to show in this line.
*/
public function __construct(Container $parent, $text = '')
{
parent::__construct($parent, $text);
}
public function show()
{
Output::write('<line'.$this->parentProperties().'>');
parent::show();
Output::write('</line>');
}
}
/**
* @brief A horizontal ruler widget.
*/
class Ruler extends Widget
{
public function show()
{
Output::write('<ruler'.$this->parentProperties().' />');
}
}
/**
* @brief Shows the given icon as a page icon.
*
* This shows a simple image with a specified icon. This page icon can be used
* to give a quick graphical indication about the current page. You should only
* show one page icon per page.
*
* The image has an id which is set to "pageicon". This id can be used to
* position the icon using CSS.
*
* Page icons are only shown when Decoration::useDecorations() returns @p true.
*
* @sa Decoration
*/
class PageIcon extends Image
{
/**
* Constructor.
*
* @param parent The parent widget to add the icon to.
* @param icon Path of the icon in the resources/ directory. The path
* should not include the file extension.
*
* @sa iconExists()
*/
public function __construct(Container $parent, $icon)
{
parent::__construct($parent, "resources/$icon.png");
self::setText(i18n('Page Icon'));
self::setID('pageicon');
$this->icon = $icon;
}
/**
* Queries whether a given icon exists.
*
* @param icon Path of the icon in the resources/ directory. The path
* should not include the file extension.
*
* @return @p true if the icon exists, @p false otherwise.
*/
public static function iconExists($icon)
{
return file_exists(AUKYLA_DIR."/htdocs/resources/$icon.png");
}
public function show()
{
if(Decoration::useDecorations() == true && self::iconExists($this->icon))
{
parent::show();
}
}
private $icon;
}
/**
* @brief A tooltip showing help or an informational message.
*
* This widget provides a simple box in which a help or info message can be
* shown. The tooltip is invisible by default, but is shown when the user hovers
* over the previous item with the mouse.
*
* For example, to attach a tooltip to an image, just create the image and then
* create the tooltip under the same parent as the image.
*
* The tooltip has a CSS class called "tooltipbox" for which the look and
* behavior is defined in the default style.
*/
class Tooltip extends Box
{
/**
* Constructor.
*
* Creates a new tooltip which is attached to the previous widget (the
* previous sibling).
*
* @param parent The parent widget to add the tooltip to.
* @param text Text to add to the tooltip. A single paragraph is
* created inside the tooltip box containing this text.
* Other widgets may be added to the tooltip box as well.
*/
public function __construct(Container $parent, $text)
{
parent::__construct($parent);
self::setCssClass('tooltipbox');
new Paragraph($this, $text);
}
}
/**
* @brief Widget for showing messages reported through the Messages class.
*
* This widget shows all logged messages, both errors and confirmations. Errors
* are displayed with class="error" and confirmations are displayed with
* class="confirm".
*
* @sa Messages
*/
class MessagesWidget extends Widget
{
public function show()
{
Messages::show();
}
}
?>