<?php
/**
 * 
 */

/**
 * Auto-loading Glade window
 */
class Glade_Window
  {
  /**
   * The top widget. It does not have to be
   * a top-level object if this is loaded
   * within another UI
   *
   * @var GtkWidget
   */
  public $top; 
  
  /**
   * @var GladeXML
   */
  protected $glade;
  
  /**
   * Load the fixed structure for the actual class invoking the constructor
   * 
   * @param void
   * @return void
   */
  public function __construct($topName = 'top')
    {
    $uiDescriptionFileName = get_class($this) . '.glade';
    try
      {
      $this->glade = new GladeXML($uiDescriptionFileName);
      $this->glade->signal_autoconnect_instance($this);
      $this->top = $this->glade->get_widget($topName);
      }
    catch (Exception $e)
      {
      echo "Glade_Windows/__construct(): " . $e->getMessage();
      die();
      }
    }
    
  /**
   * callback wrapper around Gtk::main_quit() for Glade
   */
  public function quit()
    {
    Gtk::main_quit();
    }
   
  /**
   * A utility callback for views inherited from this class: it
   * enables automatic alternate row colors
   *
   * @param GtkCellLayout $cell_layout
   * @param GtkCellRenderer $cell
   * @param GtkTreeModel $tree_model
   * @param GtkTreeIter $iter
   * @return void
   */
  static public function zebraTreeViewCallback(GtkCellLayout $cell_layout, GtkCellRenderer $cell, GtkTreeModel $tree_model, GtkTreeIter $iter /* [, user_data] */)
    {
    $path = $tree_model->get_path($iter);
    $cell->set_property('cell-background', ($path[0] % 2) ?'#d0d0d0' : '#ffffff');
    }
  }