Gtk2_IndexedComboBox
[ class tree: Gtk2_IndexedComboBox ] [ index: Gtk2_IndexedComboBox ] [ all elements ]

Source for file Model.php

Documentation is available at Model.php

  1. <?php
  2. /**
  3. *   Indexed Gtk2 combo box model. Can be used stand-alone
  4. *   e.g. as model for a GtkComboBox from a glade file.
  5. *
  6. *   Both key and values can be strings or integers.
  7. *
  8. *   @category   Gtk2
  9. *   @package    Gtk2_IndexedComboBox
  10. *   @author     Christian Weiske <cweiske@php.net>
  11. *   @license    LGPL
  12. *   @version    CVS: $Id: Model.php,v 1.1 2006/05/12 22:43:26 cweiske Exp $
  13. */
  14. class Gtk2_IndexedComboBox_Model extends GtkListStore
  15. {
  16.     /**
  17.     *   Constructor.
  18.     *
  19.     *   @param array    $arData     If wished, you can set the initial data here.
  20.     */
  21.     public function __construct($arData = null)
  22.     {
  23.         parent::__construct(Gtk::TYPE_STRINGGtk::TYPE_STRING);
  24.         if ($arData !== null{
  25.             $this->set_array($arData);
  26.         }
  27.     }//public function __construct($arData = null)
  28.  
  29.  
  30.  
  31.     /**
  32.     *   Appends a single key/value pair to the list.
  33.     *
  34.     *   @param mixed    $strId      (string) id to append, or an array to append
  35.     *   @param string   $strValue   The value to append
  36.     */
  37.     public function append($strId$strValue = null)
  38.     {
  39.         if (is_array($strId)) {
  40.             parent::append($strId);
  41.         else {
  42.             parent::append(array($strId$strValue));
  43.         }
  44.     }//public function append_array($strId, $strValue = null)
  45.  
  46.  
  47.  
  48.     /**
  49.     *   Appends an array (key and value) as data to the store.
  50.     *
  51.     *   @param array    $arData     The array to append
  52.     */
  53.     public function append_array($arData)
  54.     {
  55.         foreach ($arData as $strId => &$strValue{
  56.             parent::append(array($strId$strValue));
  57.         }
  58.     }//public function append_array($arData)
  59.  
  60.  
  61.  
  62.     /**
  63.     *   Returns the key/id of the given iter.
  64.     *   If $iter is NULL, this method returns NULL.
  65.     *
  66.     *   @param GtkTreeIter  $iter   Iterator whose key shall be gotten.
  67.     *   @return string  The id/key of the selected entry
  68.     */
  69.     public function get_key($iter)
  70.     {
  71.         if ($iter === null{
  72.             return null;
  73.         }
  74.         return $this->get_value($iter0);
  75.     }//public function get_key($iter)
  76.  
  77.  
  78.  
  79.     /**
  80.     *   Returns the string of the given iter.
  81.     *   If $iter is NULL, this method returns NULL.
  82.     *
  83.     *   @param GtkTreeIter  $iter   Iterator whose string shall be gotten.
  84.     *   @return string  The string value of the selected entry
  85.     */
  86.     public function get_text($iter)
  87.     {
  88.         if ($iter === null{
  89.             return null;
  90.         }
  91.         return $this->get_value($iter1);
  92.     }//public function get_key($iter)
  93.  
  94.  
  95.  
  96.     /**
  97.     *   Returns an array with all key/value pairs.
  98.     *
  99.     *   @return array Array with key/value pairs in the model
  100.     */
  101.     public function get_array()
  102.     {
  103.         $ar = array();
  104.  
  105.         $iter $this->get_iter_first();
  106.         if ($iter !== null{
  107.             do {
  108.                 $ar[$this->get_value($iter0)$this->get_value($iter1);
  109.             while (($iter $this->iter_next($iter)) !== null);
  110.         }
  111.  
  112.         return $ar;
  113.     }//public function get_array()
  114.  
  115.  
  116.  
  117.     /**
  118.     *   Inserts a single key/value pair (or an array) at
  119.     *   a certain position into the list.
  120.     *
  121.     *   @param int      $nPosition  The position to insert the values at
  122.     *   @param mixed    $strId      (string) id to append, or array to append
  123.     *   @param string   $strValue   The value to append
  124.     */
  125.     public function insert($nPosition$strId$strValue = null)
  126.     {
  127.         if (is_array($strId)) {
  128.             parent::insert($nPosition$strId);
  129.         else {
  130.             parent::insert($nPositionarray($strId$strValue));
  131.         }
  132.     }//public function insert($nPosition, $strId, $strValue = null)
  133.  
  134.  
  135.  
  136.     /**
  137.     *   Inserts an array (key and value) at a certain position into the list.
  138.     *
  139.     *   @param int      $nPosition  The position to insert the array at
  140.     *   @param array    $arData     The array to append
  141.     */
  142.     public function insert_array($nPosition$arData)
  143.     {
  144.         foreach ($arData as $strId => &$strValue{
  145.             parent::insert($nPosition++array($strId$strValue));
  146.         }
  147.     }//public function insert_array($nPosition, $arData)
  148.  
  149.  
  150.  
  151.     /**
  152.     *   Prepends a single key/value pair to the list.
  153.     *
  154.     *   @param mixed    $strId      (string) id to prepend, or array to prepend
  155.     *   @param string   $strValue   The value to append
  156.     */
  157.     public function prepend($strId$strValue = null)
  158.     {
  159.         if (is_array($strId)) {
  160.             parent::prepend($strId);
  161.         else {
  162.             parent::prepend(array($strId$strValue));
  163.         }
  164.     }//public function prepend($strId, $strValue = null)
  165.  
  166.  
  167.  
  168.     /**
  169.     *   Prepends an array (key and value) at the beginning of the store
  170.     *
  171.     *   @param array    $arData     The array to append
  172.     */
  173.     public function prepend_array($arData)
  174.     {
  175.         $nPosition = 0;
  176.         foreach ($arData as $strId => &$strValue{
  177.             parent::insert($nPosition++array($strId$strValue));
  178.         }
  179.     }//public function prepend_array($arData)
  180.  
  181.  
  182.  
  183.     /**
  184.     *   Removes the first entry with the given key from the list.
  185.     *
  186.     *   @param string   $strId      The key of the entry to remove
  187.     *
  188.     *   @return boolean     True if an entry has been deleted
  189.     */
  190.     public function remove_key($strId)
  191.     {
  192.         $iter $this->get_iter_first();
  193.         if ($iter !== null{
  194.             do {
  195.                 if ($this->get_value($iter0== $strId{
  196.                     break;
  197.                 }
  198.             while (($iter $this->iter_next($iter)) !== null);
  199.  
  200.             if ($iter !== null{
  201.                 $this->remove($iter);
  202.                 return true;
  203.             }
  204.         }
  205.         return false;
  206.     }//public function remove_key($strId)
  207.  
  208.  
  209.  
  210.     /**
  211.     *   Sets an array (key and value) as data into the store.
  212.     *   Clears any previous entries.
  213.     *
  214.     *   @param array    $arData     The array to set
  215.     */
  216.     public function set_array($arData)
  217.     {
  218.         $this->clear();
  219.         return $this->append_array($arData);
  220.     }//public function set_array($arData)
  221.  
  222.  
  223.  
  224.     /*
  225.     *   PEAR-style camelCaseNamed method aliases
  226.     */
  227.  
  228.  
  229.  
  230.     public function appendArray($arData{
  231.         return $this->append_array($arData);
  232.     }
  233.  
  234.  
  235.  
  236.     public function getArray({
  237.         return $this->get_array();
  238.     }
  239.  
  240.  
  241.  
  242.     public function insertArray($nPosition$arData{
  243.         return $this->insert_array($nPosition$arData);
  244.     }
  245.  
  246.  
  247.  
  248.     public function prependArray($arData{
  249.         return $this->prepend_array($arData);
  250.     }
  251.  
  252.  
  253.  
  254.     public function removeKey($strId{
  255.         return $this->remove_key($strId);
  256.     }
  257.  
  258.  
  259.  
  260.     public function setArray($arData{
  261.         return $this->set_array($arData);
  262.     }
  263.  
  264. }//class Gtk2_IndexedComboBox_Model extends GtkListStore
  265. ?>

Documentation generated on Mon, 11 Mar 2019 14:48:47 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.