All pastes #272113 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-12-08 19:14 UTC
rendered paste body
<?php

/**
 * CC_Window - basic window with menu, toolbar, status bar automagically created
 *
 * Streamlines creation of similiar windows and callbacks - handles automatic
 * saving and returning x and y position, as well as height and width on windows
 */
abstract class CC_Window extends GtkWindow
{

	protected $isModal = false;

	/**
	 * customize style for window
	 * @var $customize int
	 */
	public $customize = CC_Customize::ICONVIEW;

	/**
	 * windows can be minimized, maximized and fullscreened
	 * @var $minimized bool
	 */
	protected $minimized = FALSE;

	/**
	 * windows can be minimized, maximized and fullscreened
	 * @var $maximized bool
	 */
	protected $maximized = FALSE;

	/**
	 * windows can be minimized, maximized and fullscreened
	 * @var $fullscreen bool
	 */
	protected $fullscreen = FALSE;

	//----------------------------------------------------------------
	//             Setup
	//----------------------------------------------------------------

	/**
	 * public function __construct
	 *
	 * Create a new CharacterWindow instance and build internal gui items
	 *
	 * @return void
	 */
	public function __construct()
	{

		parent::__construct();

		$config = CC_Config::instance();

		if(empty($this->name))
		{
			$this->set_name(strtolower(get_class($this)));
		}

		$this->connect('window-state-event', array($this, 'windowState'));
		$this->connect_simple('delete-event', array($this, 'saveWindowState'));
		$this->restoreWindowState();
		return;
	}

	/**
	 * public function set_title
	 *
	 * overload set_title
	 *
	 * @param string $name title to set
	 * @return void
	 */
	public function set_title($title, $program = 'Callicore')
	{
		parent::set_title(CC::i18n('%s :: %s', $program, $title));
		return;
	}


	//----------------------------------------------------------------
	//             Callbacks
	//----------------------------------------------------------------

	/**
	 * public function saveWindowState
	 *
	 * saves window state
	 *
	 * @return void
	 */
	public function saveWindowState()
	{
		$name = $this->name;
		$config = CC_Config::instance();

		// unmax/min/fullscreen
		$config->{$name . '_fullscreen'} = $this->fullscreen;
		$config->{$name . '_maximized'} = $this->maximized;
		$config->{$name . '_minimized'} = $this->minimized;

		if($this->minimized)
		{
			$this->deiconify();
		}
		if($this->maximized)
		{
			$this->unmaximize();
		}
		elseif($this->fullscreen)
		{
			$this->unfullscreen();
		}

		// size
		list($height, $width) = $this->get_size();
		$config->{$name . '_height'} = $height;
		$config->{$name . '_width'} = $width;

		// position
		list($x, $y) = $this->get_position();
		$config->{$name . '_x'} = $x;
		$config->{$name . '_y'} = $y;

		$this->destroy();
		return;
	}

	/**
	 * public function restoreWindowState
	 *
	 * restores a window state
	 *
	 * @return void
	 */
	public function restoreWindowState()
	{
		$name = $this->name;
		$config = CC_Config::instance();

		// default size and location
		$width = isset($config->{$name . '_height'}) ? (int) $config->{$name . '_height'} : 800;
		$height = isset($config->{$name . '_width'}) ? (int) $config->{$name . '_width'} : 600;
		$this->set_default_size($width, $height);

		$x = isset($config->{$name . '_x'}) ? (int) $config->{$name . '_x'} : NULL;
		$y = isset($config->{$name . '_y'}) ? (int) $config->{$name . '_y'} : NULL;
		if(!is_null($x) && !is_null($y))
		{
			$this->move($x, $y);
		}

		$fullscreen = isset($config->{$name . '_fullscreen'}) ? (bool) $config->{$name . '_fullscreen'} : FALSE;
		$maximized = isset($config->{$name . '_maximized'}) ? (bool) $config->{$name . '_maximized'} : FALSE;
		$minimized = isset($config->{$name . '_minimized'}) ? (bool) $config->{$name . '_minimized'} : FALSE;

		if($fullscreen)
		{
			$this->fullscreen();
		}
		if($maximized)
		{
			$this->maximize();
		}
		if($minimized)
		{
			$this->iconify();
		}
		return;
	}

	/**
	 * public function saveWindow
	 *
	 * keeps track of minimized/maximized/fullscreen or normal windows states
	 *
	 * @return void
	 */
	public function windowState($widget, $event)
	{
		$this->minimized = ($event->new_window_state & Gdk::WINDOW_STATE_ICONIFIED) ? TRUE : FALSE;
		$this->maximized = ($event->new_window_state & Gdk::WINDOW_STATE_MAXIMIZED) ? TRUE : FALSE;
		$this->fullscreen = ($event->new_window_state & Gdk::WINDOW_STATE_FULLSCREEN) ? TRUE : FALSE;
	}
	
	public function hide_all() {
		if (class_exists('CC_WM') && CC_WM::is_window($this->get_name()) && $this->isModal) {
			parent::grab_remove();
			$return = parent::hide_all();
			$this->isModal = false;
			return $return;
		} else {
			return parent::hide_all();
		}
	}
	
	public function show_all($modal = false) {
		if (class_exists('CC_WM') && CC_WM::is_window($this->get_name())) {
			$return = parent::show_all();
			parent::grab_add();
			$this->isModal = true;
			return $return;
		} else {
			return parent::show_all();
		}
	}

}
?>