rendered paste body<?php/* Handle text/treeview, columnstores, etc. */class columns { public function new_from_xml($obj, $filename) { $filename_with_path = $GLOBALS['baseDir'] . '/lib/ui/xml/'. $filename; if(!file_exists($filename_with_path)) { echo "Could not find " . $filename_with_path . "\n"; } $xml_in = simplexml_load_file($filename_with_path); (array) $columns = array(); $columnCount = 0; foreach($xml_in->columns->name as $key => $value) { $i+ $columnType = (string) $value->attributes()->columnType; array_push($columns, array('columnName'=> (string) $value, 'columnType' => (strlen($columnType) == 0 && $columnCount == 0) ? (string) $xml_in->fct : $columnType, 'specialHandler' => (string) $value->attributes()->specialHandler, 'icon' => (string) $value->attributes()->icon, 'e_closed' => (string) $value->attributes()->ExpanderClosed, 'e_open' => (string) $value->attributes()->ExpanderOpen) ); $columnCount++; } // if(!isset($xml_in->colors)) { // $xml_in->colors = '#FFFFFF,#CCFF99'; // } // echo "Building " . (string) $xml_in->widget_name ."\n"; return($this->buildColumns($obj, array( 'widget_name' => (string) $xml_in->widget_name, 'glade_name' => (string) $xml_in->glade_name, 'type' => (string) $xml_in->type, 'columns' => $columns, 'color' => (strtolower((string) $xml_in->color) == 'y')?true:false, 'colors' => (strlen((string) $xml_in->colors)>1?$xml_in->colors:'#FFFFFF,#CCFF99'), 'size' => ((int) $xml_in->text_size > 1?(int) $xml_in->text_size:'8'), 'scrolled' => (string) $xml_in->scrolled, 'scrolled_method' => (string) $xml_in->scrolled_method, 'fct' => (string) $xml_in->fct, 'editable' => (string) $xml_in->editable, 'editable_method' => (string) $xml_in->editable_method, 'hiddencells' => (string) $xml_in->hiddencells, 'html' => (strtolower((string)$xml_in->html) == 'y')?true:false, 'combo' => (string) $xml_in->combo, 'tree_lines' => (string) $xml_in->tree_lines, 'set_model' => (strtolower((string)$xml_in->set_model) == 'n')?false:true ))); } public function buildColumns($obj, $options, $oobj=null) { if(strlen($options['glade_name']) == 0) { $TreeView = $obj->get_widget($options['widget_name']); } else { $TreeView = $obj->{$options['glade_name']}->get_widget($options['widget_name']); } $ColCnt = array(); $ColNum = 0; // Create Model. switch(strtolower($options['type'])) { case 'liststore': $Model = new GtkListStore(); break; case 'treestore'; $Model = new GtkTreeStore(); break; } // Create actual columns and place in array to be pushed into model. foreach ($options['columns'] as $key => $Col) { switch($Col['columnType']) { case 'checkbox': $ColCnt[] = gObject::TYPE_BOOLEAN; $cell_renderer = new GtkCellRendererToggle(); $TreeViewColumn = new GtkTreeViewColumn($Col['columnName'], $cell_renderer, 'active', $ColNum); $TreeViewColumn->set_cell_data_func($cell_renderer, array($this, 'format_columns'), $ColNum, FALSE, $options['color'], $options['colors'], $options['size']); break; case 'pixbuf': $ColCnt[] = gObject::TYPE_STRING; $cell_renderer = new GtkCellRendererPixbuf(); $TreeViewColumn = new GtkTreeViewColumn(); $TreeViewColumn->set_attributes($cell_renderer, 'text', 0); $TreeViewColumn->pack_start($cell_renderer, true); $TreeViewColumn->set_title($Col['columnName']); if(strlen($Col['icon']) > 0) { $cell_renderer->set_property('pixbuf', GdkPixbuf::new_from_file($GLOBALS['baseDir'] .'/lib/ui/'. $Col['icon'])); } $TreeViewColumn->set_cell_data_func($cell_renderer, array($this, (strlen($Col['specialHandler']) > 0? $Col['specialHandler']:'format_columns')), $ColNum,false, $options['color'], $options['colors'], $options['size']); break; case 'pixbuf_expandable': $ColCnt[] = gObject::TYPE_STRING; $cell_renderer = new GtkCellRendererPixbuf(); $TreeViewColumn = new GtkTreeViewColumn(); $TreeViewColumn->set_attributes($cell_renderer, 'text', 0); $TreeViewColumn->pack_start($cell_renderer, true); $TreeViewColumn->set_title($Col['columnName']); $cell_renderer->set_property('pixbuf-expander-open', GdkPixbuf::new_from_file($GLOBALS['baseDir'] . '/lib/ui/'.$Col['e_open'])); $cell_renderer->set_property('pixbuf-expander-closed', GdkPixbuf::new_from_file($GLOBALS['baseDir'] . '/lib/ui/'.$Col['e_closed'])); if(strlen($Col['specialHandler'])>0) { $TreeViewColumn->set_cell_data_func($cell_renderer, array($this, $Col['specialHandler']), $ColNum, $options['html'], $options['color'], $options['colors'],$options['size']); } break; case 'qty': $ColCnt[] = gObject::TYPE_LONG; $cell_renderer = new GtkCellRendererText(); $TreeViewColumn = new GtkTreeViewColumn($Col['columnName'], $cell_renderer, 'text', $ColNum); $TreeViewColumn->set_cell_data_func($cell_renderer, array($this, 'format_columns'), $ColNum, $options['html'], $options['color'], $options['colors'], $options['size']); break; case 'hidden': echo "hidden"; $ColCnt[] = gObject::TYPE_STRING;// $TreeViewColumn = new GtkTreeViewColumn(); break; default: $ColCnt[] = gObject::TYPE_STRING; $cell_renderer = new GtkCellRendererText(); $TreeViewColumn = new GtkTreeViewColumn($Col['columnName'], $cell_renderer, 'text', $ColNum); $TreeViewColumn->set_cell_data_func($cell_renderer, array($this, 'format_columns'), $ColNum, $options['html'], $options['color'], $options['colors'], $options['size']); if(isset($options['editable']) && strtolower($options['editable']) == 'y') { $cell_renderer->set_property('editable', true); $cell_renderer->connect("edited", array((isset($oobj)) ?$oobj:$obj, $options['editable_method']), $TreeView, $ColNum); } break; } if(strtolower($options['scrolled']) == 'y') { $TreeViewColumn->set_sort_column_id($ColNum); } if(isset($options['combo'])) { if(strtolower($options['combo']) != 'y') { if($Col['columnType'] != 'columnName') { $TreeView->append_column($TreeViewColumn); } } } $ColNum++; } $hColCnt = $this->hidden_cells($options['hiddencells'], $ColCnt); if(sizeof($hColCnt) > 0) { array_merge($ColCnt, $hColCnt); } $Model->set_column_types($ColCnt); if(strtolower($options['scrolled']) == 'y') { $ModelSort = new GtkTreeModelSort($Model); $ModelSort->set_sort_column_id(0, Gtk::SORT_ASCENDING); if(strlen($options['glade_name']) == 0) { $obj->get_widget($options['scrolled_method'])->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); } else { $obj->$options['glade_name']->get_widget($options['scrolled_method'])->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); }// if($options['set_model'] == true) { $TreeView->set_model($ModelSort);// } return($Model); } else {// if($options['set_model'] == true) { $TreeView->set_model($Model);// } return $Model; } } private function hidden_cells($Count) { if($Count > 0) { for($i=0;$i<$Count;$i++) { $myColCnt[] = gObject::TYPE_STRING; } return $myColCnt; } } public function format_columns($column, $cell, $model, $iter, $col_num, $html, $color, $colors, $size) { $path = $model->get_path($iter); $row_number = $path[0]; $val = $model->get_value($iter, $col_num); if($html == true) { $cell->set_property('markup', "<span font_desc='Verdana $size'>".$val."</span>"); // note 3 } else { $cell->set_property('markup', "<span font_desc='Verdana $size'>".htmlspecialchars($val)."</span>"); // note 3 } if($color) { $htmlColors = split(",", $colors); $row_color = ($row_number%2==1) ? $htmlColors[0] : $htmlColors[1]; $cell->set_property('cell-background', $row_color); } }