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

Source for file IndexedComboBox.php

Documentation is available at IndexedComboBox.php

  1. <?php
  2. require_once 'Gtk2/IndexedComboBox/Model.php';
  3.  
  4. /**
  5. *   Indexed Gtk2 combo box similar to the HTML select box.
  6. *   Lets you not only store values as the normal GtkComboBox,
  7. *   but associated keys as well. The active key can be easily
  8. *   received with get_active_key.
  9. *
  10. *   It imitates the convenience methods of a text-based GtkComboBox
  11. *   that is constructed with GtkComboBox::new_text().
  12. *
  13. *   Both key and values can be strings or integers.
  14. *
  15. *   Method names aren't camelCase but with underscores to be close
  16. *   the naming of the original Gtk2 methods.
  17. *
  18. *   @category   Gtk2
  19. *   @package    Gtk2_IndexedComboBox
  20. *   @author     Christian Weiske <cweiske@php.net>
  21. *   @license    LGPL
  22. *   @version    CVS: $Id: IndexedComboBox.php,v 1.3 2006/04/05 07:13:27 cweiske Exp $
  23. */
  24. class Gtk2_IndexedComboBox extends GtkComboBox
  25. {
  26.     /**
  27.     *   The cell renderer for the text
  28.     *   @var GtkCellRenderer 
  29.     */
  30.     protected $renderer = null;
  31.  
  32.  
  33.  
  34.     public function __construct($arData = null)
  35.     {
  36.         parent::__construct();
  37.         $model = new Gtk2_IndexedComboBox_Model();
  38.         $this->set_model($model);
  39.  
  40.         //show the second column only
  41.         $this->renderer = new GtkCellRendererText();
  42.         $this->pack_start($this->renderer);
  43.         $this->set_attributes($this->renderer'text'1);
  44.  
  45.         if ($arData !== null{
  46.             $this->set_array($arData);
  47.         }
  48.     }//public function __construct($arData = null)
  49.  
  50.  
  51.  
  52.     /**
  53.     *   Appends a single key/value pair to the list.
  54.     *
  55.     *   @param string   $strId      The id to append
  56.     *   @param string   $strValue   The value to append
  57.     */
  58.     public function append($strId$strValue)
  59.     {
  60.         $this->get_model()->append($strId$strValue);
  61.     }//public function append_array($strId, $strValue)
  62.  
  63.  
  64.  
  65.     /**
  66.     *   Appends an array (key and value) as data to the store.
  67.     *
  68.     *   @param array    $arData     The array to append
  69.     */
  70.     public function append_array($arData)
  71.     {
  72.         $this->get_model()->append_array($arData);
  73.     }//public function append_array($arData)
  74.  
  75.  
  76.  
  77.     /**
  78.     *   Returns the id of the active entry.
  79.     *   If there is no active key, NULL will be returned.
  80.     *
  81.     *   @return string  The id/key of the selected entry
  82.     */
  83.     public function get_active_key()
  84.     {
  85.         $nActive $this->get_active();
  86.         if ($nActive === -1{
  87.             return null;
  88.         }
  89.         //workaround bug in php-gtk2: get_active_iter wants a parameter instead of giving one
  90.         return $this->get_model()->get_key($this->get_model()->get_iter($nActive));
  91.         //That's the better one (that doesn't work as of 2006-03-04)
  92.         return $this->get_model()->get_key($this->get_active_iter());
  93.     }//public function get_active_key()
  94.  
  95.  
  96.  
  97.     /**
  98.     *   Returns the string of the active entry.
  99.     *   If there is no active entry, NULL will be returned.
  100.     *
  101.     *   @return string  The string value of the selected entry
  102.     */
  103.     public function get_active_text()
  104.     {
  105.         $nActive $this->get_active();
  106.         if ($nActive === -1{
  107.             return null;
  108.         }
  109.         //workaround bug in php-gtk2: get_active_iter wants a parameter instead of giving one
  110.         return $this->get_model()->get_text($this->get_model()->get_iter($nActive));
  111.         //That's the better one (that doesn't work as of 2006-03-04)
  112.         return $this->get_model()->get_text($this->get_active_iter());
  113.     }//public function get_active_text()
  114.  
  115.  
  116.  
  117.     /**
  118.     *   Returns an array with all key/value pairs.
  119.     *
  120.     *   @return array Array with key/value pairs in the model
  121.     */
  122.     public function get_array()
  123.     {
  124.         return $this->get_model()->get_array();
  125.     }//public function get_array()
  126.  
  127.  
  128.  
  129.     /**
  130.     *   Returns the default cell renderer.
  131.     *
  132.     *   @return GtkCellRenderer The default cell renderer
  133.     */
  134.     public function get_cell_renderer()
  135.     {
  136.         return $this->renderer;
  137.     }//public function get_cell_renderer()
  138.  
  139.  
  140.  
  141.     /**
  142.     *   Inserts a single key/value pair at a certain position into the list.
  143.     *
  144.     *   @param int      $nPosition  The position to insert the values at
  145.     *   @param string   $strId      The id to append
  146.     *   @param string   $strValue   The value to append
  147.     */
  148.     public function insert($nPosition$strId$strValue)
  149.     {
  150.         $this->get_model()->insert($nPosition$strId$strValue);
  151.     }//public function insert($nPosition, $strId, $strValue)
  152.  
  153.  
  154.  
  155.     /**
  156.     *   Inserts an array (key and value) at a certain position into the list.
  157.     *
  158.     *   @param int      $nPosition  The position to insert the array at
  159.     *   @param array    $arData     The array to append
  160.     */
  161.     public function insert_array($nPosition$arData)
  162.     {
  163.         $this->get_model()->insert_array($nPosition$arData);
  164.     }//public function insert_array($nPosition, $arData)
  165.  
  166.  
  167.  
  168.     /**
  169.     *   Prepends a single key/value pair to the list.
  170.     *
  171.     *   @param string   $strId      The id to append
  172.     *   @param string   $strValue   The value to append
  173.     */
  174.     public function prepend($strId$strValue)
  175.     {
  176.         $this->get_model()->prepend($strId$strValue);
  177.     }//public function prepend($strId, $strValue)
  178.  
  179.  
  180.  
  181.     /**
  182.     *   Prepends an array (key and value) at the beginning of the store
  183.     *
  184.     *   @param array    $arData     The array to append
  185.     */
  186.     public function prepend_array($arData)
  187.     {
  188.         $this->get_model()->prepend_array($arData);
  189.     }//public function prepend_array($arData)
  190.  
  191.  
  192.  
  193.     /**
  194.     *   Removes the first entry with the given key from the list.
  195.     *
  196.     *   @param string   $strId      The key of the entry to remove
  197.     *
  198.     *   @return boolean     True if an entry has been deleted
  199.     */
  200.     public function remove_key($strId)
  201.     {
  202.         return $this->get_model()->remove_key($strId);
  203.     }//public function remove_key($strId)
  204.  
  205.  
  206.  
  207.     /**
  208.     *   Sets the model row with the given key as active.
  209.     *
  210.     *   @param string   $strId      The key of the entry to be made active
  211.     *
  212.     *   @return boolean     True if an entry has been set active
  213.     */
  214.     public function set_active_key($strId)
  215.     {
  216.         if ($strId === null{
  217.             $this->set_active(-1);
  218.             return true;
  219.         }
  220.  
  221.         $model $this->get_model();
  222.         $iter  $model->get_iter_first();
  223.         if ($iter !== null{
  224.             do {
  225.                 if ($model->get_key($iter== $strId{
  226.                     break;
  227.                 }
  228.             while (($iter $model->iter_next($iter)) !== null);
  229.  
  230.             if ($iter !== null{
  231.                 $this->set_active_iter($iter);
  232.                 return true;
  233.             }
  234.         }
  235.         return false;
  236.     }//public function set_active_key($strId)
  237.  
  238.  
  239.  
  240.     /**
  241.     *   Sets an array (key and value) as data into the store.
  242.     *   Clears any previous entries.
  243.     *
  244.     *   @param array    $arData     The array to set
  245.     */
  246.     public function set_array($arData)
  247.     {
  248.         return $this->get_model()->set_array($arData);
  249.     }//public function set_array($arData)
  250.  
  251.  
  252.  
  253.     /*
  254.     *   PEAR-style camelCaseNamed method aliases
  255.     */
  256.  
  257.  
  258.  
  259.     public function appendArray($arData{
  260.         return $this->append_array($arData);
  261.     }
  262.  
  263.  
  264.  
  265.     public function getActiveKey({
  266.         return $this->get_active_key();
  267.     }
  268.  
  269.  
  270.  
  271.     public function getActiveText({
  272.         return $this->get_active_text();
  273.     }
  274.  
  275.  
  276.  
  277.     public function getArray({
  278.         return $this->get_array();
  279.     }
  280.  
  281.  
  282.  
  283.     public function getCellRenderer({
  284.         return $this->get_cell_renderer();
  285.     }
  286.  
  287.  
  288.  
  289.     public function insertArray($nPosition$arData{
  290.         return $this->insert_array($nPosition$arData);
  291.     }
  292.  
  293.  
  294.  
  295.     public function prependArray($arData{
  296.         return $this->prepend_array($arData);
  297.     }
  298.  
  299.  
  300.  
  301.     public function removeKey($strId{
  302.         return $this->remove_key($strId);
  303.     }
  304.  
  305.  
  306.  
  307.     public function setActiveKey($strId{
  308.         return $this->set_active_key($strId);
  309.     }
  310.  
  311.  
  312.  
  313.     public function setArray($arData{
  314.         return $this->set_array($arData);
  315.     }
  316.  
  317. }//class Gtk2_IndexedComboBox extends GtkMessageDialog
  318. ?>

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