<?PHP
/*****************************************************************************
| @script_type - PHP-WinBinder
| @scriptname - hnwb_ListView.example.phpw
| @version - 1.0
| -------------------------------------------------------------------------
| @author - Horst Nogajski <coding@nogajski.de>
| @copyright - (c) 1999 - 2007
| @licence - LGPL
| -------------------------------------------------------------------------
| $Source: /WINBINDER/hnwb_ListViewClass/hnwb_ListView.example_3.phpw,v $
| $Id: hnwb_ListView.example_3.phpw,v 1.3 2007/01/04 22:21:42 horst Exp $
****************************************************************************/
include('config.php');
define('APPNAME', basename( __FILE__ ));
//------------------------------------------------------------------------------
#--> STEP 1:
// define ID-Constants for your ListViews
if(!defined('IDC_LISTVIEW_1')) define('IDC_LISTVIEW_1', 1001);
if(!defined('IDC_LISTVIEW_2')) define('IDC_LISTVIEW_2', 1002);
#--> STEP 2:
// Create window with: WBC_NOTIFY, WBC_MOUSEMOVE | WBC_HEADERSEL !!!
$winmain = wb_create_window(null, AppWindow, APPNAME, WBC_CENTER, WBC_CENTER,
540, 449, WBC_NOTIFY, WBC_MOUSEMOVE | WBC_HEADERSEL );
#--> STEP 3:
// create a global INI-Object
$inifile = str_replace('.phpw','', __FILE__).'.ini';
$ini = new hn_ini($inifile,TRUE,TRUE);
#--> STEP 4:
//
// define a customized Button-CLassExtension for the first ListView:
// 1):
// define the ButtonLabels in Array $LABELS
// 2):
// define the Actions for the Buttons in Method Button_Event_Handler()
// 3):
// define enabled/disabled states in Method display_Buttons()
//
class My_ListView_with_Buttons extends hnwb_ListView_Buttons
{
// Button-Texts
var $LABELS = array('copy selected','move selected','copy checked','move checked');
// we create this as a Reference-Handle to the TargetListView, because we
// want copy DataRows from the first to the second ListView
var $lv2 = null;
function My_ListView_with_Buttons($ini=null, $Lines=TRUE, $CheckBoxes=TRUE, $IniSectionPrefix='')
{
// CALL THE PARENT CONSTRUCTOR
$this->hnwb_ListView_Buttons($ini, $Lines, $CheckBoxes, $IniSectionPrefix);
}
function Button_Event_Handler($id)
{
switch($id)
{
case $this->Button_ID_first:
$data = $this->Data_GET(ID_LV_DATATYPE_SELECTED, FALSE);
$this->lv2->Data_PUT($data, TRUE);
unset($data);
break;
case $this->Button_ID_first + 1:
$data = $this->Data_GET(ID_LV_DATATYPE_SELECTED, FALSE);
$this->Data_DELETE(ID_LV_DATATYPE_SELECTED);
$this->lv2->Data_PUT($data, TRUE);
unset($data);
break;
case $this->Button_ID_first + 2:
$data = $this->Data_GET(ID_LV_DATATYPE_CHECKED, FALSE);
$this->lv2->Data_PUT($data, TRUE);
unset($data);
break;
case $this->Button_ID_first + 3:
$data = $this->Data_GET(ID_LV_DATATYPE_CHECKED, FALSE);
$this->Data_DELETE(ID_LV_DATATYPE_CHECKED);
$this->lv2->Data_PUT($data, TRUE);
unset($data);
break;
}
$this->display_Buttons(FALSE);
}
function display_Buttons($on=TRUE)
{
// THIS PART IS REQUIRED:
for($i=$this->Button_ID_first;$i<=$this->Button_ID_last;$i++)
{
wb_set_visible($this->bt_ctrl{$i},$on);
}
// END REQUIRED PART
// THE FOLLOWING PARTS CAN BE DEFINED TO SUITE YOUR NEEDS:
// Buttons should only enabled if there Actions make sence depending
// to the current ListViewState
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);
}
}
} // END class My_ListView_with_Buttons
#--> STEP 5
// get Data for the Listview (e.g. from MySQL-Query)
$data = example_data();
#--> STEP 6, CREATE THE SECOND LISTVIEW FIRST - (use the standard Buttons)
$lv2 = new hnwb_ListView_Buttons($ini,TRUE,TRUE);
// define first ID for the Buttons
$lv2->define_Start_ID(9000);
// create the Control
$lv2->ctrl = wb_create_control($winmain, ListView, '', 10, 250, 511, 145, IDC_LISTVIEW_2, WBC_VISIBLE | WBC_ENABLED | WBC_SORT | WBC_LINES | WBC_CHECKBOXES, 0, 0);
// setup the ini-object, (ATTENTION: THIS MUST BE CALLED DIRECTLY AFTER THE CONTROL IS CREATED)
$lv2->initialize_ini();
// use AutoConfigure for the Headernames without Uniqe-IDs
$lv2->set_ASSOC_AUTO_Column_Header($data);
// finally setup the enhanced Control, (ATTENTION: THIS MUST BE CALLED AFTER THE ColumnHeader ARE CREATED)
$lv2->initialize();
#--> STEP 7:
// create a _CUSTOMIZED_ Object for the FIRST LISTVIEW:
$lv1 = new My_ListView_with_Buttons($ini,TRUE,TRUE);
// define first ID for the Buttons
$lv1->define_Start_ID(9010);
// create the Control
$lv1->ctrl = wb_create_control($winmain, ListView, '', 10, 15, 511, 195, IDC_LISTVIEW_1, WBC_VISIBLE | WBC_ENABLED | WBC_SORT | WBC_LINES | WBC_CHECKBOXES, 0, 0);
// setup the ini-object, (ATTENTION: THIS MUST BE CALLED AFTER THE CONTROL IS CREATED)
$lv1->initialize_ini();
// put Reference to the Second ListView
$lv1->lv2 =& $lv2;
// use AutoConfigure for the Headernames and setup the listview to handle
// data with Unique-ID's (uid-field = id)
$lv1->set_ASSOC_AUTO_Column_Header($data, 'id');
// finally setup the enhanced Control, (ATTENTION: THIS MUST BE CALLED AFTER THE ColumnHeader ARE CREATED)
$lv1->initialize();
$lv1->Data_PUT($data);
wb_set_handler($winmain, "process_main");
wb_main_loop();
//-------------------------------------------------------------------- FUNCTIONS
function process_main($window, $id, $ctrl=0, $lparam1=0, $lparam2=0)
{
#--> STEP 8:
// make the $LV_cfg and the ListView-ObjectHandlers global!
if(!isset($GLOBALS['LV_cfg'])) $GLOBALS['LV_cfg'] = null;
global $lv1, $lv2;
switch($id)
{
#--> STEP 9:
// First Hook into the MainProcess-EventHandler,
// with fallthrough ! (without break-command)
case IDDEFAULT:
$lv1->Event_Handler($window, $id, $ctrl, $lparam1, $lparam2, $GLOBALS['LV_cfg']);
$lv2->Event_Handler($window, $id, $ctrl, $lparam1, $lparam2, $GLOBALS['LV_cfg']);
#--> STEP 10:
// For each ListView-ObjectHandler:
// set a second Hook into the MainProcess-EventHandler,
case $lv1->get_ID():
$lv1->Event_Handler($window, $id, $ctrl, $lparam1, $lparam2, $GLOBALS['LV_cfg']);
break;
case $lv2->get_ID():
$lv2->Event_Handler($window, $id, $ctrl, $lparam1, $lparam2, $GLOBALS['LV_cfg']);
break;
#--> STEP 11:
// For each Button-Extended-ListView-ObjectHandler:
// catch and proceed Button-Events
case $id >= $lv1->Button_ID_first && $id <= $lv1->Button_ID_last:
$lv1->Button_Event_Handler($id);
break;
case $id >= $lv2->Button_ID_first && $id <= $lv2->Button_ID_last:
$lv2->Button_Event_Handler($id);
break;
#--> STEP 12:
// For each ListView-ObjectHandler:
// CleanUp at ProcessTermination
case IDCLOSE:
$GLOBALS['LV_cfg'] = null;
unset($GLOBALS['LV_cfg']);
// CleanUp the SECOND LISTVIEW FIRST !!
$lv2->Destroy();
$lv2=null;
unset($lv2);
$lv1->Destroy();
$lv1=null;
unset($lv1);
wb_destroy_window($window);
break;
}
}
function example_data()
{
$data_src = array(
array('company'=>'company', 'name'=>'doe', 'firstname'=>'john'),
array('company'=>'', 'name'=>'doe', 'firstname'=>'john'),
array('company'=>'ab ltd.', 'name'=>'doe', 'firstname'=>'john'),
array('company'=>'de ltd.', 'name'=>'doe', 'firstname'=>'john'),
array('company'=>'fg ltd.', 'name'=>'doe', 'firstname'=>'john'),
array('company'=>'xy ltd.', 'name'=>'doe', 'firstname'=>'john'),
array('company'=>'company', 'name'=>'wesson', 'firstname'=>'al'),
array('company'=>'company', 'name'=>'baker', 'firstname'=>'barry'),
array('company'=>'company', 'name'=>'butcher', 'firstname'=>'barry'),
array('company'=>'company', 'name'=>'baker', 'firstname'=>'terry'),
array('company'=>'xy ltd.', 'name'=>'patterson','firstname'=>'aldus'),
array('company'=>'trade united', 'name'=>'hugley', 'firstname'=>'jenny')
);
$data = array();
$uid = 0;
for($i=0;$i<3;$i++)
{
foreach($data_src as $d)
{
$data[] = array_merge($d,array('id'=>$uid));
$uid++;
}
}
return $data;
}
?>
|