All pastes #272061 Raw Edit

Untitled

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

/**
 * Class for handling multipul GtkWindow objects
 * @author Leon Pegg <leon.pegg@gmail.com>
 */
class CC_WM {

	/**
	 * GtkWindow object array
     *   Structure:
     *      [string GtkWindow_Name]
     *          array(
     *            GtkWindow - Store GtkWindow object
     *          )
	 *
	 * @var array GtkWindow
	 */
	protected static $GtkWindows = array();
	protected static $GtkWindowGroup;

	private function __construct() {

	}

	/**
	 * Adds a GtkWindow object to Application::$GtkWindows
	 *
	 * @param GtkWindow $GtkWindow
	 * @return bool
	 */
	public static function add_window(GtkWindow $GtkWindow) {
		$GtkWindow_Name = $GtkWindow->get_name();
		if ($GtkWindow_Name !== '' && !array_key_exists($GtkWindow_Name, self::$GtkWindows)) {
			if (!is_object(self::$GtkWindowGroup)) {
				self::$GtkWindowGroup = new GtkWindowGroup();
			}
			self::$GtkWindowGroup->add_window($GtkWindow);
			self::$GtkWindows[$GtkWindow_Name] = $GtkWindow;
			return true;
		}
		return false;
	}
	
	/**
	 * Removes a GtkWindow object from Application::$GtkWindows
	 *
	 * @param string $GtkWindow_Name
	 * @return GtkWindow
	 */
	public static function remove_window($GtkWindow_Name) {
		if ($GtkWindow_Name !== '' && array_key_exists($GtkWindow_Name, self::$GtkWindows)) {
			$GtkWindow = self::$GtkWindows[$GtkWindow_Name];
			unset(self::$GtkWindows[$GtkWindow_Name]);
			self::$GtkWindowGroup->remove_window($GtkWindow);
			return $GtkWindow;
		}
		return false;
	}

	/**
	 * Retrives GtkWindow object from Application::$GtkWindows
	 *
	 * @param string $GtkWindow_Name
	 * @return GtkWindow
	 */
	public static function window($GtkWindow_Name) {
		if ($GtkWindow_Name !== '' && array_key_exists($GtkWindow_Name, self::$GtkWindows)) {
			return self::$GtkWindows[$GtkWindow_Name];
		}
		return false;
	}

	/**
	 * Retrives Application::$GtkWindows infomation array
     *   Structure:
     *      [int window_id]
     *          array(
     *            name   - Name of GtkWindow
     *            class  - Name of GtkWindow class
     *          )
	 *
	 * @return array
	 */
	public static function list_windows() {
		$Window_List = array();
		foreach (self::$GtkWindows as $GtkWindow_Name => $Class) {
			$Class_Name = get_class($Class);
			$Window_List[] = array('name' => $GtkWindow_Name, 'class' => $Class_Name);
		}
		return $Window_List;
	}

	/**
	 * Shows all windows managed by Application
	 *
	 */
	public static function show_all_windows() {
		foreach (self::$GtkWindows as $GtkWindow) {
			$GtkWindow->show_all();
		}
	}

	/**
	 * Hides all windows managed by Application
	 *
	 */
	public static function hide_all_windows() {
		foreach (self::$GtkWindows as $GtkWindow) {
			$GtkWindow->hide_all();
		}
	}

	public static function is_window($GtkWindow_Name) {
		return array_key_exists($GtkWindow_Name, self::$GtkWindows);
	}
	
}

?>