<?PHP
/*******************************************************************************
| @script_type - PHP-Script | Class to handle WinBinder-ListViews
| @scriptname - hnwb_listviews.class.php
| @version - 1.0 BETA
| -------------------------------------------------------------------------
| @author - Horst Nogajski <hide@address.com>
| @copyright - (c) 1999 - 2007
| @licence - GNU LGPL (http://opensource.org/licenses/lgpl-license.html)
| -------------------------------------------------------------------------
| $Source: /WINBINDER/hnwb_ListViewClass/hnwb_listview.class.php,v $
| $Id: hnwb_listview.class.php,v 1.5 2007/01/04 22:21:42 horst Exp $
******************************************************************************/
/*******************************************************************************
*
* Documentation is located here: http://nogajski.de/horst/php/listview/
*
* and here: http://hn273.users.phpclasses.org/browse/author/45770.html
*
* Tabsize: 4
*
******************************************************************************/
if(!class_exists('hnwb_ListView'))
{
/**
* MainClass
* @PUBLIC
**/
class hnwb_ListView
{
/**
*
***** Default-Vars, Public **********************************************/
// Color of ListView Background
var $BGColor = 16777215; // white, (BGR-Value, long)
// Color of ListView Text
var $TextColor = 0; // black, (BGR-Value, long)
/**
*
***** Private Default-Vars & Handles ************************************/
// Ctrl-Handle of ListView
var $ctrl = null;
// if the configurator is enabled or not
var $cfg = FALSE;
// Object, hn_ini_class(), is required for the configurator
var $ini = NULL;
// if the Listview should display Lines
var $Lines = TRUE;
// if the Listview should display CheckBoxes in the first Column
var $CheckBoxes = TRUE;
// can be used to store multiple settings for the same ListView in one inifile
var $IniSectionPrefix = '';
// used for ListViews without UniqueIdentifier-Fields
var $generic_uid_name = 'hnwb_LV_generic_uid';
/**
*
***** Constructor *******************************************************/
function hnwb_ListView($ini=null, $Lines=TRUE, $CheckBoxes=TRUE)
{
// global constants
if(!defined('LVM_FIRST')) define('LVM_FIRST', 4096); // &H1000
if(!defined('LVM_SETBKCOLOR')) define('LVM_SETBKCOLOR', (LVM_FIRST + 1));
if(!defined('LVM_SETTEXTCOLOR')) define('LVM_SETTEXTCOLOR', (LVM_FIRST + 36));
if(!defined('LVM_SETTEXTBKCOLOR')) define('LVM_SETTEXTBKCOLOR', (LVM_FIRST + 38));
// CONSTANTS are used with DATA_GET & DATA_DELETE
if(!defined('ID_LV_DATATYPE_SELECTED')) define('ID_LV_DATATYPE_SELECTED', 0);
if(!defined('ID_LV_DATATYPE_UNSELECTED')) define('ID_LV_DATATYPE_UNSELECTED', 1);
if(!defined('ID_LV_DATATYPE_CHECKED')) define('ID_LV_DATATYPE_CHECKED', 2);
if(!defined('ID_LV_DATATYPE_UNCHECKED')) define('ID_LV_DATATYPE_UNCHECKED', 3);
if(!defined('ID_LV_DATATYPE_ALL')) define('ID_LV_DATATYPE_ALL', 4);
$this->CheckBoxes = $CheckBoxes;
$this->Lines = $Lines;
if(is_object($ini) && get_class($ini)==='hn_ini')
{
// ini-Object isn't passed by Reference anymore
// therefor we restrict writeaccess to only one Section
$this->ini = $ini;
$this->cfg = TRUE;
return TRUE;
}
else
{
if(!class_exists('hn_ini'))
{
$this->cfg = FALSE;
return FALSE;
}
}
if(defined('APPNAME'))
{
$inifile = dirname(__FILE__) .'/'. str_replace(array(' ',':','/','\\','?','*'), array('_',''), APPNAME) . '.ini';
}
else
{
$inifile = str_replace('.php','', __FILE__).'.ini';
}
$this->ini = new hn_ini($inifile);
$this->cfg = TRUE;
return TRUE;
}
/**
*
***** ReadOnly Properties ***********************************************/
function get_ID()
{
return wb_get_id($this->ctrl);
}
function get_Parent_Ctrl()
{
return wb_get_parent($this->ctrl);
}
function get_Parent_ID()
{
return wb_get_id(wb_get_parent($this->ctrl));
}
function has_CheckBoxes()
{
return $this->CheckBoxes;
}
function has_Lines()
{
return $this->Lines;
}
function count_Records()
{
return wb_get_item_count($this->ctrl);
}
function count_Selected()
{
return count(wb_get_selected($this->ctrl));
}
function count_Checked()
{
return count(wb_get_value($this->ctrl));
}
/**
*
***** Initialization ****************************************************/
function initialize_ini($IniSectionPrefix='')
{
if(!isset($this->ini) || !is_object($this->ini) || get_class($this->ini)!='hn_ini')
{
return FALSE;
}
$this->IniSectionPrefix = (string)$IniSectionPrefix;
$this->ini->SYNCHRONIZE = TRUE;
$this->ini->PROCESS_SECTIONS = TRUE;
$this->ini->set_Writeable_SectionName($this->_ini_Section());
$this->ini->load();
$this->ini->set('COMPUTERNAME',getenv('COMPUTERNAME'),$this->_ini_Section());
return TRUE;
}
function set_ASSOC_AUTO_Column_Header($data, $unique_id=null)
{
if(count($data)<1)
{
trigger_error('NO DATAROW PASSED TO ANALYZE FOR CREATING COLUMNHEADERS!',E_USER_WARNING);
return FALSE;
}
$i = 0;
$temp = array();
$MyHeaders = array();
foreach($data as $row)
{
if(!is_array($row)) break;
$col = 0;
foreach($row as $k=>$v)
{
// from first row we get column header names
$colname = is_string($k) && strlen(trim($k))>0 ? $k : 'Col_'.(string)$col;
$MyHeaders[] = array($colname);
}
if(++$i>=1) break;
}
unset($data);
return $this->set_Column_Header($MyHeaders,$unique_id,TRUE);
}
function set_Column_Header($array_names, $unique_id_column=null, $use_assoziative_Data_Arrays=FALSE)
{
if($this->_is_initialized())
{
return;
}
if(is_string($array_names))
{
$array_names = implode(',',$array_names);
}
$this->ini->load();
$num = count($array_names);
$res = array();
$this->colids = array();
for($i=0;$i<$num;$i++)
{
$v = $array_names[$i];
if(is_string($v))
{
if(in_array(strtolower($v),$this->colids))
{
trigger_error('DUPLICATE ENTRY IN COLUMNHEADERS!',E_USER_WARNING);
return FALSE;
}
$res[] = array($v,-1,WBC_LEFT);
$this->colids[$i] = strtolower($v);
}
elseif(is_array($v))
{
// extract the name for this Column Header
$name = isset($v[0]) ? $v[0] : "Field $i";
// check against defined Names
if(in_array(strtolower($name),$this->colids))
{
trigger_error("DUPLICATE ENTRY IN COLUMN_HEADERS!\r\n\t[$name]",E_USER_WARNING);
return FALSE;
}
// register it
$this->colids[$i] = strtolower($name);
// check ini for stored width value
if(isset($this->ini) && is_object($this->ini) && $this->cfg===TRUE)
{
// set width value passed by array | stored in inifile | or default -1
$size = $this->ini->get($this->_ini_keyname($name,'width'), $this->_ini_Section());
$size = is_string($size) && $size==='' ? -1 : $size;
$width = isset($v[1]) ? (int)$v[1] : isset($size) ? $size : -1;
}
else
{
// set width value passed by array | or default -1
$width = isset($v[1]) ? (int)$v[1] : -1;
}
// check ini for stored align value
if(isset($this->ini) && is_object($this->ini) && $this->cfg===TRUE)
{
// set align value passed by array | stored in inifile | or default WBC_LEFT
$align = $this->ini->get($this->_ini_keyname($name,'align'), $this->_ini_Section());
$align = is_string($align) && $align==='' ? WBC_LEFT : $align;
$align = isset($v[2]) ? (int)$v[2] : $align;
}
else
{
$align = isset($v[2]) ? (int)$v[2] : WBC_LEFT;
}
// add this row to resulting array
$res[] = array($name, $width, $align);
}
}
// check if we have at least one column
if(count($this->colids)<1)
{
trigger_error("THERE ARE NO COLUMN_HEADER DEFINED!\r\nWe need at least 1 of them.",E_USER_WARNING);
return FALSE;
}
// check if we have to use associative arrays
$this->assoc = (bool)$use_assoziative_Data_Arrays;
// define the column with unique datarecord id
$this->unique_id_column = $unique_id_column;
if($unique_id_column!==null)
{
if($this->assoc && is_string($unique_id_column))
{
if(in_array($unique_id_column,$this->colids))
{
$temp = array_flip($this->colids);
$this->uid_name = $unique_id_column;
$this->uid = $temp[$unique_id_column];
}
else
{
trigger_error("COLUMN ID FOR UNIQUE DATA ID IS NOT AVAILABLE IN HEADERNAMES!\r\n\tUID=[$unique_id_column]",E_USER_WARNING);
return FALSE;
}
}
else
{
if(!isset($this->colids[(int)$unique_id_column]))
{
trigger_error("COLUMN ID FOR YOUR UNIQUE DATA ID IS OUT OF RANGE!\r\n\tUID=[$unique_id_column]\r\nHeaders Range=0-".(count($this->colids)-1),E_USER_WARNING);
return FALSE;
}
$this->uid = (int)$unique_id_column;
$this->uid_name = $this->colids[$this->uid];
}
}
else
{
$this->uid = count($this->colids);
$this->uid_name = $this->generic_uid_name;
$this->colids[$this->uid] = $this->uid_name;
$res[] = array($this->uid_name,0,WBC_RIGHT);
}
return wb_set_text($this->ctrl,$res);
}
function set_extended_SortList($mixed_column_name_or_id,$array_sortinglist)
{
if((is_string($mixed_column_name_or_id) && !in_array($mixed_column_name_or_id,$this->colids)) ||
(is_numeric($mixed_column_name_or_id) && !isset($this->colids[$mixed_column_name_or_id])))
{
trigger_error("COLUMN ID PASSED TO SET_ADVANCED_SORTINGLIST IS OUT OF RANGE!\r\n\tUID=[$unique_id_column]\r\nHeaders Range=0-".(count($this->colids)-1),E_USER_NOTICE);
return FALSE;
}
if(!is_string($mixed_column_name_or_id) && !is_numeric($mixed_column_name_or_id))
{
trigger_error("WRONG DATA_TYPE PASSED FOR COLUMN_ID!\r\n",E_USER_NOTICE);
return FALSE;
}
if(!is_array($array_sortinglist))
{
trigger_error("WRONG DATA_TYPE PASSED FOR SORTINGLIST!\r\n",E_USER_NOTICE);
return FALSE;
}
if(!isset($this->sortvalues))
{
$this->sortvalues = array();
}
if(count($array_sortinglist)===0 && isset($this->sortvalues[$mixed_column_name_or_id]))
{
unset($this->sortvalues[$mixed_column_name_or_id]);
return TRUE;
}
$res = array();
foreach($array_sortinglist as $v)
{
if($this->_get_colid_4_name($v)===FALSE)
{
trigger_error("COLUMN ID PASSED TO SET_ADVANCED_SORTINGLIST IS OUT OF RANGE!\r\n\tUID=[$unique_id_column]\r\nHeaders Range=0-".(count($this->colids)-1),E_USER_NOTICE);
continue;
}
else
{
$res[] = $v;
}
}
$this->sortvalues[$mixed_column_name_or_id] = $res;
return TRUE;
}
function initialize()
{
if($this->_is_initialized())
{
return FALSE;
}
$temp = wb_get_position($this->ctrl,TRUE);
$this->x = $temp[0] - 3;
$this->y = $temp[1] - 22;
$temp = wb_get_size($this->ctrl);
$this->w = $temp[0];
$this->h = $temp[1];
// create Configurator-Button
$ToolTip = "Click to open the Configurator-Dialog for this ListView.\nOptions:\n save ColumnWidth,\n define Colors,\n enable and define enhanced Sorting";
if($this->_Parent_is_Tab() && isset($this->TabPage))
{
$this->cfg_btn = wb_create_control($this->get_Parent_Ctrl(), PushButton, array(chr(0x5E), $ToolTip), $this->x, $this->y - 12, 24, 12, $this->get_ID(), 0, 0, $this->TabPage);
}
elseif($this->_Parent_is_Tab() && !isset($this->TabPage))
{
$this->cfg_btn = wb_create_control($this->get_Parent_Ctrl(), PushButton, array(chr(0x5E), $ToolTip), $this->x, $this->y - 12, 24, 12, $this->get_ID(), 1, 0, 0);
$this->enable_user_config(FALSE);
}
else
{
$this->cfg_btn = wb_create_control($this->get_Parent_Ctrl(), PushButton, array(chr(0x5E), $ToolTip), $this->x, $this->y - 12, 24, 12, $this->get_ID(), 1, 0, 0);
}
// create status_txt-Control
if(!isset($this->status_txt))
{
if($this->_Parent_is_Tab() && isset($this->TabPage))
{
wb_set_size($this->ctrl, $this->w, $this->h -15);
$this->status_txt = wb_create_control($this->get_Parent_Ctrl(), Label, '', $this->x, ($this->y + $this->h -15), $this->w, 16, $this->get_ID(), 0x00000008, 0, $this->TabPage);
}
elseif($this->_Parent_is_Tab() && !isset($this->TabPage))
{
//wb_set_size($this->ctrl, $this->w, $this->h -15);
$this->status_txt = wb_create_control($this->get_Parent_Ctrl(), Label, '', $this->x, ($this->y + $this->h -15), $this->w, 16, $this->get_ID(), 0x00000009, 0, 0);
}
else
{
wb_set_size($this->ctrl, $this->w, $this->h -15);
$this->status_txt = wb_create_control($this->get_Parent_Ctrl(), Label, '', $this->x, ($this->y + $this->h -15), $this->w, 16, $this->get_ID(), 0x00000008, 0, 0);
}
}
// SortLists
$this->cfg_update_ListView();
// Styles
$this->set_Style_Lines();
$this->set_Style_Checkboxes();
$this->set_Style_Enabled();
$this->BGColor = isset($this->ini->VARS[$this->_ini_Section()]['BGColor']) ? $this->ini->get('BGColor',$this->_ini_Section()) : $this->BGColor;
$this->TextColor = isset($this->ini->VARS[$this->_ini_Section()]['TextColor']) ? $this->ini->get('TextColor',$this->_ini_Section()) : $this->TextColor;
$this->Refresh();
// Status
$this->Status = array();
$this->provide_status();
$this->INITIALIZED = TRUE;
}
/**
*
***** Status, Refresh & CleanUp *****************************************/
function provide_status()
{
if(isset($this->NoStatus))
{
return;
}
$this->Status['1_total'] = 'Records: '.$this->Count_Records();
$this->Status['2_selected'] = 'selected: '.$this->Count_Selected();
if($this->has_CheckBoxes())
{
$this->Status['3_checked'] = 'checked: '.$this->Count_Checked();
}
else
{
if(isset($this->Status['3_checked'])) unset($this->Status['3_checked']);
}
ksort($this->Status);
$msg = ' ['.implode('] [', $this->Status).']';
wb_set_text($this->status_txt, $msg);
}
function Refresh()
{
// Set Control Backgroundcolor
wb_send_message($this->ctrl, LVM_SETBKCOLOR, 0, $this->BGColor);
// Set Rows Backgroundcolor
wb_send_message($this->ctrl, LVM_SETTEXTBKCOLOR, 0, $this->BGColor);
// Set Text Color
wb_send_message($this->ctrl, LVM_SETTEXTCOLOR, 0, $this->TextColor);
wb_refresh($this->ctrl,TRUE);
}
function Reset()
{
// clear List
if(!wb_delete_items($this->ctrl))
{
trigger_error("CANNOT DELETE RECORDS!\r\n[->RESET()]",E_USER_WARNING);
}
// clear the uids
if(isset($this->colids)) unset($this->colids);
if(isset($this->unique_id_column)) unset($this->unique_id_column);
if(isset($this->generic_uid_number)) unset($this->generic_uid_number);
if(isset($this->assoc)) unset($this->assoc);
if(isset($this->uid_name)) unset($this->uid_name);
if(isset($this->uid)) unset($this->uid);
if(isset($this->IniSectionPrefix)) unset($this->IniSectionPrefix);
if(isset($this->ColumnHeaderClick)) unset($this->ColumnHeaderClick);
if(isset($this->sortvalues)) unset($this->sortvalues);
if(isset($this->used_uids)) unset($this->used_uids);
if(isset($this->RECORDS)) unset($this->RECORDS);
if(isset($this->Status)) unset($this->Status);
if(isset($this->INITIALIZED)) unset($this->INITIALIZED);
}
function Destroy()
{
$this->Reset();
wb_destroy_control($this->cfg_btn);
wb_destroy_control($this->status_txt);
wb_destroy_control($this->ctrl);
if(isset($this->status_txt)) unset($this->status_txt);
if(isset($this->cfg_btn)) unset($this->cfg_btn);
if(isset($this->ctrl)) unset($this->ctrl);
if(isset($this->BGColor)) unset($this->BGColor);
if(isset($this->TextColor)) unset($this->TextColor);
if(isset($this->Lines)) unset($this->Lines);
if(isset($this->CheckBoxes)) unset($this->CheckBoxes);
if(isset($this->cfg)) unset($this->cfg);
if(isset($this->generic_uid_name)) unset($this->generic_uid_name);
if(isset($this->x)) unset($this->x);
if(isset($this->y)) unset($this->y);
if(isset($this->w)) unset($this->w);
if(isset($this->h)) unset($this->h);
if(isset($this->ini)) unset($this->ini);
}
/**
*
***** DataHandling ******************************************************/
function Data_PUT( $array_data, $append=TRUE )
{
if(!$this->_is_initialized())
{
return;
}
if($append!==TRUE)
{
// clear List
if(!wb_delete_items($this->ctrl))
{
trigger_error("CANNOT DELETE RECORDS!\r\n[->Data_PUT(\$array_data,\$append=FALSE)]",E_USER_WARNING);
return FALSE;
}
// clear the uids
$this->used_uids = array();
// clear the Records Array used for advanced sorting
$this->RECORDS = array();
}
if(!isset($this->used_uids))
{
$this->used_uids = array();
}
if(!isset($this->RECORDS))
{
// holds the Data as it is passed to the Method, but if isset an uid, uses it as Key
$this->RECORDS = array();
}
if(!isset($this->generic_uid_number))
{
$this->generic_uid_number = 0;
}
$this->NoStatus = TRUE;
################
// Combinations between: none | assoc | uid |
$combi = 0;
if($this->assoc) $combi += 1;
if(isset($this->uid_name)) $combi += 2;
if($this->_generic_uid()) $combi += 5;
// collector for ListviewRows
$rows = array();
foreach($array_data as $data)
{
if(is_string($data) || is_numeric($data))
{
if(count($this->colids)===1)
{
// this is the simplest way to use a Listview, but must be supported too
$rows[] = $data;
continue;
}
// throw an ERROR ??
##--ToDo---->>
}
$uid = null;
switch($combi)
{
case 2:
// we have to check unique IDs,
// no duplicate entries are allowed
$uid = $data[$this->uid];
if(in_array($uid,$this->used_uids))
{
continue;
}
$this->used_uids[] = $uid;
$row = array_values($data);
break;
case 3: // uid & assoc
// we have to take care of associative Arrays
// and also we have to check unique ID.
// So, duplicate entries are _NOT_ allowed!
$uid = $data[$this->uid_name];
if(in_array($uid,$this->used_uids))
{
continue;
}
$this->used_uids[] = $uid;
$row = array();
foreach($data as $k=>$v)
{ // switch assoc key to indexed key
$row[$this->_get_colid_4_name($k)] = $v;
}
ksort($row);
break;
case 6: // assoc
// we have to take care of associative Arrays,
// duplicate entries are allowed
$row = array();
foreach($data as $k=>$v)
{ // switch assoc key to indexed key
$row[$this->_get_colid_4_name($k)] = $v;
}
ksort($row);
// now we add a generic UID as the _LAST_ARRAY_ENTRY_ !!
$uid = $this->generic_uid_number++;
$row[$this->uid] = $uid;
break;
default: // none
$row = array_values($data);
// now we add a generic UID as the _LAST_ARRAY_ENTRY_ !!
$uid = $this->generic_uid_number++;
$row[$this->uid] = $uid;
break;
}
$rows[] = $row;
$this->RECORDS[$uid] = $this->_generic_uid() ? array_merge($data,array(($this->assoc ? $this->uid_name : $this->uid)=>$uid)) : $data;
}
$res = wb_create_items($this->ctrl, $rows);
unset($this->NoStatus);
$this->provide_status();
$this->Refresh();
return $res;
}
function Data_DELETE( $LV_DATATYPE )
{
if(!$this->_is_initialized())
{
return;
}
if(wb_get_item_count($this->ctrl)===0)
{
return TRUE;
}
$sel = null;
switch($LV_DATATYPE)
{
case ID_LV_DATATYPE_ALL:
$this->used_uids = array();
$this->RECORDS = array();
$res = wb_delete_items($this->ctrl, null);
$this->Refresh();
return $res;
break;
case ID_LV_DATATYPE_CHECKED:
$sel = wb_get_value($this->ctrl);
break;
case ID_LV_DATATYPE_SELECTED:
$sel = wb_get_selected($this->ctrl);
break;
case ID_LV_DATATYPE_UNSELECTED:
if(is_array(wb_get_selected($this->ctrl)))
{
$sel = array_diff(range(0, wb_get_item_count($this->ctrl)-1), wb_get_selected($this->ctrl));
break;
}
$sel = range(0, wb_get_item_count($this->ctrl)-1);
break;
case ID_LV_DATATYPE_UNCHECKED:
if(is_array(wb_get_value($this->ctrl)))
{
$sel = array_diff(range(0, wb_get_item_count($this->ctrl)-1), wb_get_value($this->ctrl));
break;
}
$sel = range(0, wb_get_item_count($this->ctrl)-1);
break;
}
if(!is_array($sel) || count($sel)<1)
{
return TRUE;
}
$this->NoStatus = TRUE;
foreach($sel as $i)
{
$uid = wb_get_text($this->ctrl,$i,$this->uid);
if(isset($this->RECORDS[$uid]))
{
unset($this->RECORDS[$uid]);
}
if(isset($this->used_uids[$uid]))
{
unset($this->used_uids[$uid]);
}
}
rsort($sel);
$res = wb_delete_items($this->ctrl, $sel);
unset($this->NoStatus);
$this->provide_status();
$this->Refresh();
return $res;
}
function Data_GET( $LV_DATATYPE = ID_LV_DATATYPE_SELECTED , $preserveArrayKeys=FALSE )
{
if(!$this->_is_initialized())
{
return;
}
if(wb_get_item_count($this->ctrl)===0)
{
return NULL;
}
$sel = null;
switch($LV_DATATYPE)
{
case ID_LV_DATATYPE_ALL:
$sel = range(0, wb_get_item_count($this->ctrl)-1);
break;
case ID_LV_DATATYPE_CHECKED:
$sel = wb_get_value($this->ctrl);
break;
case ID_LV_DATATYPE_SELECTED:
$sel = wb_get_selected($this->ctrl);
break;
case ID_LV_DATATYPE_UNSELECTED:
if(is_array(wb_get_selected($this->ctrl)))
{
$sel = array_diff(range(0, wb_get_item_count($this->ctrl)-1), wb_get_selected($this->ctrl));
break;
}
$sel = range(0, wb_get_item_count($this->ctrl)-1);
break;
case ID_LV_DATATYPE_UNCHECKED:
if(is_array(wb_get_value($this->ctrl)))
{
$sel = array_diff(range(0, wb_get_item_count($this->ctrl)-1), wb_get_value($this->ctrl));
break;
}
$sel = range(0, wb_get_item_count($this->ctrl)-1);
break;
}
if(!is_array($sel) || count($sel)<1)
{
return NULL;
}
$res = array();
if($this->assoc)
{
$cols = count($this->colids);
foreach($sel as $i)
{
$a = wb_get_text($this->ctrl,$i);
$key = isset($this->uid_name) ? $a[$this->uid] : $i;
$t = array();
for($l=0;$l<$cols;$l++)
{
$t[$this->_get_name_4_colid($l)] = $a[$l];
}
$res[$key] = $t;
}
}
else
{
foreach($sel as $i)
{
$a = wb_get_text($this->ctrl,$i);
$key = isset($this->uid_name) ? $a[$this->uid] : $i;
$res[$key] = $a;
}
}
return $preserveArrayKeys ? $res : array_values($res);
}
/**
*
***** The Configurator **************************************************/
function enable_user_config($on=TRUE)
{
$this->cfg = (bool)$on;
}
function cfg_update_ListView()
{
$this->ini->load();
$max = count($this->colids);
for($i=0;$i<$max;$i++)
{
// SortingLists
$cur = $this->_get_name_4_colid($i);
if($cur===$this->generic_uid_name) continue;
$array_sortinglist = $this->ini->get($this->_ini_keyname($i,'sortlist'), $this->_ini_Section());
if($array_sortinglist===null || $array_sortinglist==='')
{
if(isset($this->sortvalues[$cur]))
{
// preserve existing sorting list, if none is available from ini
continue;
}
// save empty array
$array_sortinglist = array();
}
$this->set_extended_SortList($cur, $array_sortinglist);
}
$this->provide_status();
$this->Refresh();
}
/**
*
***** Display & Styles **************************************************/
function set_Style_CheckBoxes($on=null,$save2ini=TRUE)
{
if($on===null)
{
// get Value from ini or from Default-Var
$on = (isset($this->ini->VARS[$this->_ini_Section()][$this->_ini_keyname(null,'checkboxes')]) ? $this->ini->get($this->_ini_keyname(null,'checkboxes'),$this->_ini_Section()) : $this->CheckBoxes);
}
$on = (bool)$on;
$this->CheckBoxes = $on;
if($save2ini===TRUE)
{
$this->ini->set($this->_ini_keyname(null,'checkboxes'),$on,$this->_ini_Section());
}
return wb_set_style($this->ctrl, WBC_CHECKBOXES, $this->CheckBoxes);
}
function set_Style_Lines($on=null,$save2ini=TRUE)
{
if($on===null)
{
// get Value from ini or from Default-Var
$on = (isset($this->ini->VARS[$this->_ini_Section()][$this->_ini_keyname(null,'lines')]) ? $this->ini->get($this->_ini_keyname(null,'lines'),$this->_ini_Section()) : $this->Lines);
}
$on = (bool)$on;
$this->Lines = $on;
if($save2ini===TRUE)
{
$this->ini->set($this->_ini_keyname(null,'lines'),$on,$this->_ini_Section());
}
return wb_set_style($this->ctrl, WBC_LINES, $this->Lines);
}
function set_Style_Enabled($on=null,$save2ini=TRUE)
{
if($on===null)
{
// get Value from ini or set to TRUE
$on = (isset($this->ini->VARS[$this->_ini_Section()][$this->_ini_keyname(null,'enabled')]) ? $this->ini->get($this->_ini_keyname(null,'enabled'),$this->_ini_Section()) : TRUE);
}
$on = (bool)$on;
if($save2ini===TRUE)
{
$this->ini->set($this->_ini_keyname(null,'enabled'),$on,$this->_ini_Section());
}
return wb_set_enabled($this->ctrl,$on);
}
function set_Style_Visible($on=TRUE)
{
return wb_set_visible($this->ctrl,$on);
}
/**
*
***** EventHandler, hooked into process_main ****************************/
function Event_Handler($window, $id, $ctrl, $lparam1, $lparam2, &$LV_cfg)
{
// validate the ID
if(!$id===$this->get_ID() || !$this->_is_initialized())
{
return;
}
// ColumnHeaderClick
if($lparam1===WBC_HEADERSEL)
{
// a ColumnHeader for sorting was clicked:
if(isset($this->BLOCK_SORT)) return;
$this->BLOCK_SORT = TRUE;
$sort = new LV_sort($this,$lparam2);
unset($sort);
unset($this->BLOCK_SORT);
$this->provide_status();
return;
}
if(is_long($ctrl) && wb_get_class($ctrl)===PushButton) // check for is_long($ctrl), because sometimes I have had Errors where $ctrl was an array ?? (ErrorMessage: first parameter of wb_get_class() needs to be long, but array given)
{
// PushButton for the Configurator Window was pressed, create the Window:
if(!isset($GLOBALS['winLVcfg']))
{
$LV_cfg = new LV_cfg($this);
$LV_cfg->cfg_create_window();
}
return;
}
// more events for ListView may follow here:
// ... e.g. doubleclick to edit a datarow
// ... //
// display or hide the ConfiguratorButton
$x = $lparam2 & 0xFFFF;
$y = ($lparam2 & 0xFFFF0000) >> 16;
if($this->cfg && !$this->_Parent_is_Tab())
{
if(($x > $this->x) && ($x < $this->x + $this->w))
{
// above the Listview
$on = ($y > $this->y - 12) && ($y < $this->y - 3) ? TRUE:FALSE;
wb_set_visible($this->cfg_btn,$on);
}
}
// if none of the above has matched, we renew status-message
if($lparam1!==WBC_MOUSEMOVE)
{
$this->provide_status();
}
return;
}
/**
*
***** PRIVATES **********************************************************/
function _get_colid_4_name($name)
{
if(in_array(strtolower($name),$this->colids))
{
$a = array_flip($this->colids);
return $a[$name];
}
return FALSE;
}
function _get_name_4_colid($id)
{
return isset($this->colids[$id]) ? $this->colids[$id] : FALSE;
}
function _get_rowid_4_uid($uid)
{
$max = wb_get_item_count($this->ctrl);
for($i=0;$i<$max;$i++)
{
if($uid==wb_get_text($this->ctrl,$i,$this->uid))
{
return $i;
}
}
return -1;
}
function _generic_uid()
{
return ($this->generic_uid_name === $this->uid_name);
}
function _is_initialized()
{
return isset($this->INITIALIZED) && $this->INITIALIZED;
}
function _ini_Section()
{
return 'LV_' . (string)$this->IniSectionPrefix . (string)$this->get_ID() .'_'. (string)$this->get_Parent_ID();
}
function _ini_keyname($id,$part)
{
if($id===null)
{
// Listview is meant, not a specific column
return "LV_".strtolower($part);
}
if(!is_string($id))
{
$id = $this->_get_name_4_colid($id);
}
return "col_{$id}_".strtolower($part);
}
function _Parent_is_Tab()
{
$test = wb_get_item_list($this->get_Parent_Ctrl());
if(count($test)>1)
{
foreach($test as $i)
{
if($i>0)
{
return FALSE;
}
}
return TRUE;
}
if($test[0]===0)
{
return TRUE;
}
return FALSE;
}
} // END CLASS hnwb_ListView
/**
* ClassExtension for hnwb_ListView:
* Adds Default-Buttons for Row-Deleting
* @PUBLIC
**/
class hnwb_ListView_Buttons extends hnwb_ListView
{
// Button-Text
var $LABELS = array('del selected','del unselected','del checked','del unchecked','del all');
function hnwb_ListView_Buttons($ini=null, $Lines=TRUE, $CheckBoxes=TRUE, $IniSectionPrefix='')
{
$this->hnwb_ListView($ini, $Lines, $CheckBoxes, $IniSectionPrefix);
}
function define_Start_ID($start_id)
{
$this->Button_ID_first = $start_id;
$this->Button_ID_last = $start_id + count($this->LABELS) - 1;
$this->LABEL_IDS = array();
for($i=$this->Button_ID_first;$i<=$this->Button_ID_last;$i++)
{
$this->LABEL_IDS[] = $i;
}
}
function initialize()
{
if($this->_is_initialized())
{
return FALSE;
}
$temp = wb_get_position($this->ctrl,TRUE);
$this->x = $temp[0] - 3;
$this->y = $temp[1] - 22;
$temp = wb_get_size($this->ctrl);
$this->w = $temp[0];
$this->h = $temp[1];
// create Configurator-Button
$ToolTip = "Click to open the Configurator-Dialog for this ListView.\nOptions:\n save ColumnWidth,\n define Colors,\n enable and define enhanced Sorting";
if($this->_Parent_is_Tab() && isset($this->TabPage))
{
$this->cfg_btn = wb_create_control($this->get_Parent_Ctrl(), PushButton, array(chr(0x5E), $ToolTip), $this->x, $this->y - 12, 24, 12, $this->get_ID(), 0, 0, $this->TabPage);
}
elseif($this->_Parent_is_Tab() && !isset($this->TabPage))
{
$this->cfg_btn = wb_create_control($this->get_Parent_Ctrl(), PushButton, array(chr(0x5E), $ToolTip), $this->x, $this->y - 12, 24, 12, $this->get_ID(), 1, 0, 0);
$this->enable_user_config(FALSE);
}
else
{
$this->cfg_btn = wb_create_control($this->get_Parent_Ctrl(), PushButton, array(chr(0x5E), $ToolTip), $this->x, $this->y - 12, 24, 12, $this->get_ID(), 1, 0, 0);
}
// create status_txt-Control
if(!isset($this->status_txt))
{
if($this->_Parent_is_Tab() && isset($this->TabPage))
{
wb_set_size($this->ctrl, $this->w, $this->h -15);
$this->status_txt = wb_create_control($this->get_Parent_Ctrl(), Label, '', $this->x, ($this->y + $this->h -15), $this->w, 16, $this->get_ID(), 0x00000008, 0, $this->TabPage);
}
elseif($this->_Parent_is_Tab() && !isset($this->TabPage))
{
//wb_set_size($this->ctrl, $this->w, $this->h -15);
$this->status_txt = wb_create_control($this->get_Parent_Ctrl(), Label, '', $this->x, ($this->y + $this->h -15), $this->w, 16, $this->get_ID(), 0x00000009, 0, 0);
}
else
{
wb_set_size($this->ctrl, $this->w, $this->h -15);
$this->status_txt = wb_create_control($this->get_Parent_Ctrl(), Label, '', $this->x, ($this->y + $this->h -15), $this->w, 16, $this->get_ID(), 0x00000008, 0, 0);
}
}
// SortLists
$this->cfg_update_ListView();
// Styles
$this->set_Style_Lines();
$this->set_Style_Checkboxes();
$this->set_Style_Enabled();
$this->BGColor = isset($this->ini->VARS[$this->_ini_Section()]['BGColor']) ? $this->ini->get('BGColor',$this->_ini_Section()) : $this->BGColor;
$this->TextColor = isset($this->ini->VARS[$this->_ini_Section()]['TextColor']) ? $this->ini->get('TextColor',$this->_ini_Section()) : $this->TextColor;
$this->Refresh();
// Buttons
$y = $this->y + $this->h + 1;
$x = $this->x;
$height = 20;
$width = (floor($this->w / ($this->Button_ID_last - $this->Button_ID_first + 1)) > 70) ? floor($this->w / ($this->Button_ID_last - $this->Button_ID_first + 1)) : 70;
$j = 0;
$item_id = isset($this->TabPage) ? $this->TabPage : 0;
for($i=$this->Button_ID_first;$i<=$this->Button_ID_last;$i++)
{
$this->bt_ctrl{$i} = wb_create_control($this->get_Parent_Ctrl(), PushButton, $this->LABELS[$j], $x, $y, $width, $height, $i, (isset($this->TabPage)?0:1), 0, $item_id);
$x += $width;
$j++;
}
// Status
$this->Status = array();
$this->provide_status();
$this->INITIALIZED = TRUE;
}
function Destroy()
{
$this->Reset();
wb_destroy_control($this->cfg_btn);
wb_destroy_control($this->status_txt);
for($i=$this->Button_ID_first;$i<=$this->Button_ID_last;$i++)
{
wb_destroy_control($this->bt_ctrl{$i});
}
wb_destroy_control($this->ctrl);
if(isset($this->status_txt)) unset($this->status_txt);
if(isset($this->cfg_btn)) unset($this->cfg_btn);
if(isset($this->ctrl)) unset($this->ctrl);
if(isset($this->BGColor)) unset($this->BGColor);
if(isset($this->TextColor)) unset($this->TextColor);
if(isset($this->Lines)) unset($this->Lines);
if(isset($this->CheckBoxes)) unset($this->CheckBoxes);
if(isset($this->cfg)) unset($this->cfg);
if(isset($this->generic_uid_name)) unset($this->generic_uid_name);
if(isset($this->x)) unset($this->x);
if(isset($this->y)) unset($this->y);
if(isset($this->w)) unset($this->w);
if(isset($this->h)) unset($this->h);
if(isset($this->ini)) unset($this->ini);
}
function Event_Handler($window, $id, $ctrl, $lparam1, $lparam2, &$LV_cfg)
{
// validate the ID
if(!$this->_is_initialized() || !$id===$this->get_ID())
{
return;
}
// ColumnHeaderClick
if($lparam1===WBC_HEADERSEL)
{
// a ColumnHeader for sorting was clicked:
if(isset($this->BLOCK_SORT)) return;
$this->BLOCK_SORT = TRUE;
$sort = new LV_sort($this,$lparam2);
unset($sort);
unset($this->BLOCK_SORT);
$this->provide_status();
return;
}
if(is_long($ctrl) && wb_get_class($ctrl)===PushButton) // check for is_long($ctrl), because sometimes I have had Errors where $ctrl was an array ?? (ErrorMessage: first parameter of wb_get_class() needs to be long, but array given)
{
// PushButton for the Configurator Window was pressed, create the Window:
if(!isset($GLOBALS['winLVcfg']))
{
$LV_cfg = new LV_cfg($this);
$LV_cfg->cfg_create_window();
}
return;
}
// more events for the ListView may follow here:
// ... e.g. doubleclick to edit a datarow, etc.
// ... //
// display or hide Buttons
$x = $lparam2 & 0xFFFF;
$y = ($lparam2 & 0xFFFF0000) >> 16;
if($this->cfg && !$this->_Parent_is_Tab())
{
if(($x > $this->x) && ($x < $this->x + $this->w))
{
// above the Listview
$on = ($y > $this->y - 12) && ($y < $this->y - 3) ? TRUE:FALSE;
wb_set_visible($this->cfg_btn,$on);
}
}
if(!$this->_Parent_is_Tab())
{
if(($x > $this->x) && ($x < $this->x + $this->w))
{
// beneath the Listview
$this->display_Buttons((($y > $this->y + $this->h + 4) && ($y < $this->y + $this->h + 21) ? TRUE:FALSE));
}
}
if($this->_Parent_is_Tab())
{
$this->display_Buttons(TRUE);
}
// for all other, (click, doubleclick), we renew status-message
if($lparam1!==WBC_MOUSEMOVE)
{
$this->provide_status();
}
return;
}
function Button_Event_Handler($id)
{
switch($id)
{
case $this->Button_ID_first:
$this->Data_DELETE(ID_LV_DATATYPE_SELECTED);
break;
case $this->Button_ID_first + 1:
$this->Data_DELETE(ID_LV_DATATYPE_UNSELECTED);
break;
case $this->Button_ID_first + 2:
$this->Data_DELETE(ID_LV_DATATYPE_CHECKED);
break;
case $this->Button_ID_first + 3:
$this->Data_DELETE(ID_LV_DATATYPE_UNCHECKED);
break;
case $this->Button_ID_first + 4:
$this->Data_DELETE(ID_LV_DATATYPE_ALL);
break;
}
$this->display_Buttons(FALSE);
}
function display_Buttons($on=TRUE)
{
if(!$this->_Parent_is_Tab())
{
for($i=$this->Button_ID_first;$i<=$this->Button_ID_last;$i++)
{
wb_set_visible($this->bt_ctrl{$i},$on);
}
}
// configure Buttons
if($this->Count_Selected()>0)
{
wb_set_enabled($this->bt_ctrl{$this->Button_ID_first},TRUE);
wb_set_enabled($this->bt_ctrl{($this->Button_ID_first + 1)},TRUE);
}
else
{
wb_set_enabled($this->bt_ctrl{$this->Button_ID_first},FALSE);
wb_set_enabled($this->bt_ctrl{($this->Button_ID_first + 1)},FALSE);
}
if($this->has_CheckBoxes() && $this->Count_Checked()>0)
{
wb_set_enabled($this->bt_ctrl{($this->Button_ID_first + 2)},TRUE);
wb_set_enabled($this->bt_ctrl{($this->Button_ID_first + 3)},TRUE);
}
else
{
wb_set_enabled($this->bt_ctrl{($this->Button_ID_first + 2)},FALSE);
wb_set_enabled($this->bt_ctrl{($this->Button_ID_first + 3)},FALSE);
}
if($this->count_Records()>0)
{
wb_set_enabled($this->bt_ctrl{($this->Button_ID_first + 4)},TRUE);
}
else
{
wb_set_enabled($this->bt_ctrl{($this->Button_ID_first + 4)},FALSE);
}
}
} // END Class hnwb_ListView_Buttons
/**
* HelperClass for hnwb_ListView:
* used for X-tended sort of DataRows
* @PRIVATE
**/
class LV_sort
{
var $LV = null;
function LV_sort(&$caller_class,$lparam2)
{
$this->LV =& $caller_class;
$this->_extended_sort($lparam2);
}
function _extended_sort($lparam2)
{
if(!$this->LV->_is_initialized())
{
return;
}
if(!isset($this->LV->sortvalues[$this->LV->_get_name_4_colid($lparam2)]))
{
$this->LV->ColumnHeaderClick['descending'] = FALSE;
$this->LV->ColumnHeaderClick['id'] = $lparam2;
$this->LV->Status['sort'] = 'sorted: '.$this->LV->_get_name_4_colid($lparam2).' (ASC)';
return;
}
$sortvalues = $this->LV->sortvalues[$this->LV->_get_name_4_colid($lparam2)];
if(count($sortvalues)===0)
{
$this->LV->ColumnHeaderClick['descending'] = FALSE;
$this->LV->ColumnHeaderClick['id'] = $lparam2;
$this->LV->Status['sort'] = 'sorted: '.$this->LV->_get_name_4_colid($lparam2).' (ASC)';
return;
}
$this->LV->NoStatus = TRUE;
#echo "\n".($this->LV->ColumnHeaderClick['descending'] ? 'TRUE ':'FALSE') . ' ' .$this->LV->ColumnHeaderClick['id']."\n";
// check and set current click
// if not exist, initialize memory to store clicks
if(!isset($this->LV->ColumnHeaderClick)) $this->LV->ColumnHeaderClick = array();
if(!isset($this->LV->ColumnHeaderClick['id'])) $this->LV->ColumnHeaderClick['id'] = null;
if(!isset($this->LV->ColumnHeaderClick['descending'])) $this->LV->ColumnHeaderClick['descending'] = FALSE;
$this->LV->ColumnHeaderClick['descending'] = ($this->LV->ColumnHeaderClick['id']===$lparam2) ? !$this->LV->ColumnHeaderClick['descending'] : FALSE;
$this->LV->ColumnHeaderClick['id'] = $lparam2;
#echo ($this->LV->ColumnHeaderClick['descending'] ? 'TRUE ':'FALSE') . ' ' .$this->LV->ColumnHeaderClick['id']."\n";
// get checked Records
$checked = array();
if($this->LV->has_CheckBoxes())
{
$temp = wb_get_value($this->LV->ctrl);
if(is_array($temp) && count($temp)>0)
{
foreach($temp as $sel)
{
$a = wb_get_text($this->LV->ctrl,$sel);
$checked[] = $a[$this->LV->uid];
}
}
}
// get selected Records
$selected = array();
$temp = wb_get_selected($this->LV->ctrl);
if(is_array($temp) && count($temp)>0)
{
foreach($temp as $sel)
{
$a = wb_get_text($this->LV->ctrl,$sel);
$selected[] = $a[$this->LV->uid];
}
}
// sort Records
$temp = $this->_ArraySort($this->LV->RECORDS, $sortvalues, $this->LV->ColumnHeaderClick['descending']);
$count = count($temp);
$new_selected = array();
$new_checked = array();
for($i=0;$i<$count;$i++)
{
$row = array_values($temp[$i]);
if(is_array($selected) && count($selected)>0 && in_array($row[$this->LV->uid], $selected))
{
$new_selected[] = $i;
}
if(count($checked)>0 && in_array($row[$this->LV->uid], $checked))
{
$new_checked[] = $i;
}
$temp2[] = $row;
}
$res = wb_create_items($this->LV->ctrl, $temp2, TRUE);
if(count($new_selected)>0) wb_set_selected($this->LV->ctrl, $new_selected);
if(count($new_checked)>0) wb_set_value($this->LV->ctrl, $new_checked);
unset($this->LV->NoStatus);
$this->LV->Status['sort'] = 'X-sorted: '.implode('|',$this->LV->sortvalues[$this->LV->_get_name_4_colid($lparam2)]).' (' . ($this->LV->ColumnHeaderClick['descending'] ? 'DESC':'ASC') . ')';
return;
}
function _ArraySort($a,$sl,$desc=FALSE)
{
$this->SORTVALUE_LIST = $sl;
$this->SORTDESCENDING = (bool)$desc;
usort($a, array(&$this, '_ArraySort_CallBack'));
return $a;
}
function _ArraySort_CallBack($a,$b)
{
foreach($this->SORTVALUE_LIST as $f)
{
if(is_numeric($a[$f]))
{
if($b[$f] > $a[$f])
{
$strc = -1;
}
elseif($b[$f] < $a[$f])
{
$strc = 1;
}
else
{
$strc = 0;
}
}
else
{
$strc = strcasecmp($a[$f],$b[$f]);
}
if($strc!==0)
{
return $this->SORTDESCENDING ? -1 * $strc : $strc;
}
}
#return $this->SORTDESCENDING ? -1 : 1;
return 0;
}
} // END CLASS LV_sort
/**
* HelperClass for hnwb_ListView:
* Creates and Handles the ConfiguratorWindow
* @PRIVATE
**/
class LV_cfg
{
var $LV = null;
function LV_cfg(&$caller_class)
{
$this->LV =& $caller_class;
$this->LV->ini->load();
}
function cfg_create_window()
{
if(!$this->LV->cfg)
{
return;
}
//wb_set_visible($this->LV->cfg_btn,FALSE);
wb_refresh($this->LV->get_Parent_Ctrl(),TRUE);
$p1 = wb_get_position($this->LV->get_Parent_Ctrl());
$p2 = wb_get_position($this->LV->ctrl,TRUE);
$x = $p1[0] + $p2[0] + 21;
$y = $p1[1] + $p2[1] + 74;
$w = 727;
$h = 276;
$this->ctrl = wb_create_window($this->LV->get_Parent_Ctrl(), ModalDialog, 'hnwb_ListView Class :: Configurator', $x, $y, $w, $h, WBC_NOTIFY, WBC_HEADERSEL);
wb_set_handler($this->ctrl, "process_LV_configurator");
if(!defined('IDC_PUSHBUTTON_WIDTH')) define('IDC_PUSHBUTTON_WIDTH', 711);
if(!defined('IDC_PUSHBUTTON_BGCOLOR')) define('IDC_PUSHBUTTON_BGCOLOR', 712);
if(!defined('IDC_PUSHBUTTON_FORECOLOR')) define('IDC_PUSHBUTTON_FORECOLOR', 713);
if(!defined('IDC_CHECKBOX_ENABLE')) define('IDC_CHECKBOX_ENABLE', 721);
if(!defined('IDC_CHECKBOX_CHECKBOXES')) define('IDC_CHECKBOX_CHECKBOXES', 722);
if(!defined('IDC_CHECKBOX_LINES')) define('IDC_CHECKBOX_LINES', 723);
if(!defined('IDC_TABCONTROL_CFG')) define('IDC_TABCONTROL_CFG', 11111);
wb_create_control($this->ctrl, PushButton, 'Save Column Width', 0, 0, 240, 16, IDC_PUSHBUTTON_WIDTH, 0x00000000, 0, 0);
wb_create_control($this->ctrl, PushButton, 'Select BackgroundColor', 480, 0, 240, 16, IDC_PUSHBUTTON_BGCOLOR, 0x00000000, 0, 0);
wb_create_control($this->ctrl, PushButton, 'Select ForegroundColor', 240, 0, 240, 16, IDC_PUSHBUTTON_FORECOLOR, 0x00000000, 0, 0);
wb_create_control($this->ctrl, CheckBox, 'Enable ListView', 20, 30, 165, 16, IDC_CHECKBOX_ENABLE, 0x00000003, 0, 0);
wb_create_control($this->ctrl, CheckBox, 'Display CheckBoxes', 260, 30, 180, 15, IDC_CHECKBOX_CHECKBOXES, 0x00000000, 0, 0);
wb_create_control($this->ctrl, CheckBox, 'Display Lines', 500, 30, 165, 15, IDC_CHECKBOX_LINES, 0x00000000, 0, 0);
wb_set_value(wb_get_control($this->ctrl, IDC_CHECKBOX_CHECKBOXES), $this->LV->ini->get($this->LV->_ini_keyname(null,'checkboxes'), $this->LV->_ini_Section()));
wb_set_value(wb_get_control($this->ctrl, IDC_CHECKBOX_LINES), $this->LV->ini->get($this->LV->_ini_keyname(null,'lines'), $this->LV->_ini_Section()));
//wb_set_value(wb_get_control($this->ctrl, IDC_CHECKBOX_ENABLE), $this->ini->get($this->_ini_keyname(null,'enabled'), $this->_ini_Section()));
wb_create_control($this->ctrl, Frame, 'Configure Columns (Textalign | Hirarchical Sorting)', 30, 60, 661, 160, 0, 0x00000000, 0, 0);
if($this->LV->_generic_uid())
{
$tab = array();
foreach($this->LV->colids as $col)
{
if($col===$this->LV->generic_uid_name) continue;
$tab[] = $col;
}
$TABS = implode("\r\n",$tab);
}
else
{
$TABS = implode("\r\n",$this->LV->colids);
}
wb_create_control($this->ctrl, TabControl, $TABS, 32, 85, 659, 20, IDC_TABCONTROL_CFG, 0x00000000, 0, 0);
wb_create_control($this->ctrl, RadioButton, 'Align Left', 45, 126, 95, 16, 501, 0x00000000, 1, 0);
wb_create_control($this->ctrl, RadioButton, 'Align Center', 45, 156, 95, 15, 502, 0x00000000, 0, 0);
wb_create_control($this->ctrl, RadioButton, 'Align Right', 45, 186, 95, 15, 503, 0x00000000, 0, 0);
wb_create_control($this->ctrl, CheckBox, 'enable first field', 155, 120, 150, 15, 100, 0x00000000, 0, 0);
wb_create_control($this->ctrl, CheckBox, 'enable second field', 335, 120, 150, 15, 200, 0x00000002, 0, 0);
wb_create_control($this->ctrl, CheckBox, 'enable third field', 515, 120, 150, 15, 300, 0x00000002, 0, 0);
wb_create_control($this->ctrl, ComboBox, '', 155, 140, 150, 120, 150, 0x00000042, 0, 0);
wb_create_control($this->ctrl, ComboBox, '', 335, 140, 150, 120, 250, 0x00000042, 0, 0);
wb_create_control($this->ctrl, ComboBox, '', 515, 140, 150, 120, 350, 0x00000042, 0, 0);
wb_create_control($this->ctrl, Label, 'AlignSettings take effect, only after a NewStart of the App!'."\n".'The SortSettings take effect immediately!', 155, 180, 525, 35, 0, 0x00000002, 0, 0);
wb_set_text(wb_get_control($this->ctrl, 150), implode("\n",$this->LV->colids));
wb_set_text(wb_get_control($this->ctrl, 250), implode("\n",$this->LV->colids));
wb_set_text(wb_get_control($this->ctrl, 350), implode("\n",$this->LV->colids));
wb_set_selected(wb_get_control($this->ctrl, 150), -1);
wb_set_selected(wb_get_control($this->ctrl, 250), -1);
wb_set_selected(wb_get_control($this->ctrl, 350), -1);
$this->cfg_on_TabChange(0);//process_LV_configurator($this->ctrl, IDC_TABCONTROL_CFG, wb_get_control($this->ctrl, IDC_TABCONTROL_CFG));
}
function cfg_on_TabChange($id)
{
$this->cfg_set_control_RadioButtons($id);
$this->cfg_set_controls_4_sorting($id);
}
function cfg_set_control_RadioButtons($id)
{
if($id===0)
{
wb_set_enabled(wb_get_control($this->ctrl,501), TRUE);
wb_set_enabled(wb_get_control($this->ctrl,502), FALSE);
wb_set_enabled(wb_get_control($this->ctrl,503), FALSE);
wb_set_value(wb_get_control($this->ctrl,501), TRUE);
wb_set_value(wb_get_control($this->ctrl,502), FALSE);
wb_set_value(wb_get_control($this->ctrl,503), FALSE);
return;
}
wb_set_enabled(wb_get_control($this->ctrl,501), TRUE);
wb_set_enabled(wb_get_control($this->ctrl,502), TRUE);
wb_set_enabled(wb_get_control($this->ctrl,503), TRUE);
$align = $this->LV->ini->get($this->LV->_ini_keyname($id,'align'), $this->LV->_ini_Section());
switch($align)
{
case WBC_RIGHT: // 503
wb_set_value(wb_get_control($this->ctrl,501), FALSE);
wb_set_value(wb_get_control($this->ctrl,502), FALSE);
wb_set_value(wb_get_control($this->ctrl,503), TRUE);
break;
case WBC_CENTER: // 502
wb_set_value(wb_get_control($this->ctrl,501), FALSE);
wb_set_value(wb_get_control($this->ctrl,502), TRUE);
wb_set_value(wb_get_control($this->ctrl,503), FALSE);
break;
default: // 501
wb_set_value(wb_get_control($this->ctrl,501), TRUE);
wb_set_value(wb_get_control($this->ctrl,502), FALSE);
wb_set_value(wb_get_control($this->ctrl,503), FALSE);
break;
}
}
function cfg_set_controls_4_sorting($cur)
{
// get current states from INI-Values or DefaultValues
$enabled_1 = TRUE;
$checked_1 = (isset($this->LV->ini->VARS[$this->LV->_ini_Section()][$cur.'_100']) ? (bool)$this->LV->ini->get($cur.'_100',$this->LV->_ini_Section()) : FALSE);
$listval_1 = isset($this->LV->ini->VARS[$this->LV->_ini_Section()][$cur.'_150']) ? (int)$this->LV->ini->get("{$cur}_150", $this->LV->_ini_section()) : -1;
$selected_1 = ($checked_1 && $listval_1 > -1) ? TRUE : FALSE;
$enabled_2 = $checked_1 && $selected_1 ? TRUE : FALSE;
$checked_2 = !$enabled_2 ? FALSE : ((isset($this->LV->ini->VARS[$this->LV->_ini_Section()][$cur.'_200']) ? (bool)$this->LV->ini->get($cur.'_200',$this->LV->_ini_Section()) : FALSE));
$listval_2 = isset($this->LV->ini->VARS[$this->LV->_ini_Section()][$cur.'_250']) ? (int)$this->LV->ini->get("{$cur}_250", $this->LV->_ini_section()) : -1;
$selected_2 = ($checked_2 && $listval_2 > -1) ? TRUE : FALSE;
$enabled_3 = $checked_2 && $selected_2 ? TRUE : FALSE;
$checked_3 = !$enabled_3 ? FALSE : ((isset($this->LV->ini->VARS[$this->LV->_ini_Section()][$cur.'_300']) ? (bool)$this->LV->ini->get($cur.'_300',$this->LV->_ini_Section()) : FALSE));
$listval_3 = isset($this->LV->ini->VARS[$this->LV->_ini_Section()][$cur.'_350']) ? (int)$this->LV->ini->get("{$cur}_350", $this->LV->_ini_section()) : -1;
$selected_3 = ($checked_3 && $listval_3 > -1) ? TRUE : FALSE;
// enable controls & set/correct Values
wb_set_enabled(wb_get_control($this->ctrl,100), $enabled_1);
wb_set_value(wb_get_control($this->ctrl,100), $checked_1);
wb_set_enabled(wb_get_control($this->ctrl,150), $checked_1);
wb_set_selected(wb_get_control($this->ctrl,150), $listval_1);
wb_set_enabled(wb_get_control($this->ctrl,200), $selected_1);
wb_set_value(wb_get_control($this->ctrl,200), $checked_2);
wb_set_enabled(wb_get_control($this->ctrl,250), $checked_2);
wb_set_selected(wb_get_control($this->ctrl,250), $listval_2);
wb_set_enabled(wb_get_control($this->ctrl,300), $selected_2);
wb_set_value(wb_get_control($this->ctrl,300), $checked_3);
wb_set_enabled(wb_get_control($this->ctrl,350), $checked_3);
wb_set_selected(wb_get_control($this->ctrl,350), $listval_3);
// save corrected Values to INI
$this->LV->ini->set("{$cur}_100", wb_get_value(wb_get_control($this->ctrl, 100)), $this->LV->_ini_section());
$this->LV->ini->set("{$cur}_200", wb_get_value(wb_get_control($this->ctrl, 200)), $this->LV->_ini_section());
$this->LV->ini->set("{$cur}_300", wb_get_value(wb_get_control($this->ctrl, 300)), $this->LV->_ini_section());
$this->LV->ini->set("{$cur}_150", wb_get_selected(wb_get_control($this->ctrl, 150)), $this->LV->_ini_section());
$this->LV->ini->set("{$cur}_250", wb_get_selected(wb_get_control($this->ctrl, 250)), $this->LV->_ini_section());
$this->LV->ini->set("{$cur}_350", wb_get_selected(wb_get_control($this->ctrl, 350)), $this->LV->_ini_section());
// create SortingList
$array_sortinglist = array();
if($selected_1) $array_sortinglist[] = $this->LV->colids[$listval_1];
if($selected_2 && !in_array($listval_2,$array_sortinglist)) $array_sortinglist[] = $this->LV->colids[$listval_2];
if($selected_3 && !in_array($listval_3,$array_sortinglist)) $array_sortinglist[] = $this->LV->colids[$listval_3];
$this->LV->ini->set($this->LV->_ini_keyname($cur,'sortlist'), $array_sortinglist, $this->LV->_ini_Section());
}
function cfg_close_Window()
{
$this->LV->ini->save();
$this->LV->cfg_update_ListView();
}
} // END Class LV_cfg
} // END ifClassExists
if(!function_exists('process_LV_configurator'))
{
// EventHandler for the ConfiguratorWindow
function process_LV_configurator($window, $id, $ctrl=0, $lparam1=0, $lparam2=0)
{
$LV_cfg =& $GLOBALS['LV_cfg'];
$cur = wb_get_selected(wb_get_control($LV_cfg->ctrl, IDC_TABCONTROL_CFG));
switch($id)
{
case IDCLOSE:
$LV_cfg->cfg_close_Window();
wb_destroy_window($window);
$LV_cfg = null;
return;
break;
case IDC_CHECKBOX_ENABLE:
$LV_cfg->LV->set_Style_Enabled((bool)wb_get_value($ctrl), FALSE);
$LV_cfg->LV->ini->VARS[$LV_cfg->LV->_ini_Section()][$LV_cfg->LV->_ini_keyname(null,'enabled')] = (bool)wb_get_value($ctrl);
break;
case IDC_CHECKBOX_CHECKBOXES:
$LV_cfg->LV->set_Style_CheckBoxes((bool)wb_get_value($ctrl), FALSE);
$LV_cfg->LV->ini->VARS[$LV_cfg->LV->_ini_Section()][$LV_cfg->LV->_ini_keyname(null,'checkboxes')] = (bool)wb_get_value($ctrl);
break;
case IDC_CHECKBOX_LINES:
$LV_cfg->LV->set_Style_Lines((bool)wb_get_value($ctrl), FALSE);
$LV_cfg->LV->ini->VARS[$LV_cfg->LV->_ini_Section()][$LV_cfg->LV->_ini_keyname(null,'lines')] = (bool)wb_get_value($ctrl);
break;
case IDC_PUSHBUTTON_WIDTH:
$size = wb_get_size($LV_cfg->LV->ctrl, true);
foreach($LV_cfg->LV->colids as $i)
{
$key = $LV_cfg->LV->_ini_keyname($i,'width');
$value = (int)$size[(is_string($i) ? $LV_cfg->LV->_get_colid_4_name($i) : $i)];
$LV_cfg->LV->ini->set($key,$value,$LV_cfg->LV->_ini_Section());
}
break;
case IDC_PUSHBUTTON_BGCOLOR:
$color = isset($LV_cfg->LV->ini->VARS[$LV_cfg->LV->_ini_section()]['BGColor']) ? (int)$LV_cfg->LV->ini->VARS[$LV_cfg->LV->_ini_section()]['BGColor'] : 0;
$color = wb_sys_dlg_color($window, 'choose Background Color', $color);
if($color!==NOCOLOR)
{
$LV_cfg->LV->ini->set('BGColor', $color, $LV_cfg->LV->_ini_section());
$LV_cfg->LV->BGColor = $color;
$LV_cfg->LV->Refresh();
}
break;
case IDC_PUSHBUTTON_FORECOLOR:
$color = isset($LV_cfg->LV->ini->VARS[$LV_cfg->LV->_ini_section()]['TextColor']) ? (int)$LV_cfg->LV->ini->VARS[$LV_cfg->LV->_ini_section()]['TextColor'] : 0;
$color = wb_sys_dlg_color($window, 'choose TextColor', $color);
if($color!==NOCOLOR)
{
$LV_cfg->LV->ini->set('TextColor', $color, $LV_cfg->LV->_ini_section());
$LV_cfg->LV->TextColor = $color;
$LV_cfg->LV->Refresh();
}
break;
case IDC_TABCONTROL_CFG:
$LV_cfg->cfg_on_TabChange($lparam2);
break;
}
if($ctrl===0) return;
switch(wb_get_class($ctrl))
{
// ids 100, 200, 300
case CheckBox:
$b = (bool)wb_get_value($ctrl);
$LV_cfg->LV->ini->set("{$cur}_{$id}", $b, $LV_cfg->LV->_ini_section());
$LV_cfg->cfg_set_controls_4_sorting($cur);
break;
// ids 150, 250, 350
case ComboBox:
$sel = (int)wb_get_selected($ctrl);
$LV_cfg->LV->ini->set("{$cur}_{$id}", $sel, $LV_cfg->LV->_ini_section());
$LV_cfg->cfg_set_controls_4_sorting($cur);
break;
// ids 501, 502, 503
case RadioButton:
$align = WBC_LEFT;
if($id===502) $align = WBC_CENTER;
if($id===503) $align = WBC_RIGHT;
$LV_cfg->LV->ini->set($LV_cfg->LV->_ini_keyname($cur,'align'), $align, $LV_cfg->LV->_ini_section());
break;
}
} // END function process_LV_configurator()
} // END IfFunctionExists
?>