mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-25 16:19:00 +01:00
Got a nice persistent main-window with automatic scrollbars now.
Deleted a lot of stuff not needed for GTK.
This commit is contained in:
parent
8b54414c64
commit
8344eff5fa
@ -25,13 +25,20 @@
|
||||
@example if the user submitts the form. Vor the complete param's see the description of exec.
|
||||
@param $debug enables debug messages: 0=no, 1=calls to show and process_show, 2=content of process_show
|
||||
@param 3=calls to show_cell OR template- or cell-type name
|
||||
@param $html,$sbox instances of html and sbox2 class used to generate the html
|
||||
*/
|
||||
class etemplate extends boetemplate
|
||||
{
|
||||
var $debug;//='etemplate.editor.edit'; // 1=calls to show and process_show, 2=content after process_show,
|
||||
// 3=calls to show_cell and process_show_cell, or template-name or cell-type
|
||||
|
||||
var $no_result = array( // field-types which generate no direct result
|
||||
'label' => True,
|
||||
'hrule' => True,
|
||||
'image' => True,
|
||||
'raw' => True,
|
||||
'template' => True
|
||||
);
|
||||
|
||||
/*!
|
||||
@function etemplate
|
||||
@abstract constructor of etemplate class, reads an eTemplate if $name is given
|
||||
@ -41,9 +48,6 @@
|
||||
{
|
||||
$this->public_functions += array(
|
||||
'exec' => True,
|
||||
'process_exec' => True,
|
||||
'show' => True,
|
||||
'process_show' => True,
|
||||
);
|
||||
$this->boetemplate();
|
||||
|
||||
@ -101,28 +105,43 @@
|
||||
}
|
||||
/*
|
||||
* Create a new top-level window and connect the signals to the appropriate
|
||||
* functions. Note that all constructors must be assigned by reference.
|
||||
* functions if the window not already exists.
|
||||
*/
|
||||
$this->window = &new GtkWindow();
|
||||
$this->window->connect('destroy',array('etemplate','destroy'));
|
||||
$this->window->connect('delete-event',array('etemplate','delete_event'));
|
||||
$this->window->set_title('phpGroupware & GTK');
|
||||
$this->window->set_border_width(10);
|
||||
if (!$GLOBALS['phpgw_info']['etemplate']['window'])
|
||||
{
|
||||
$window = &new GtkWindow();
|
||||
$window->connect('destroy',array('etemplate','destroy'));
|
||||
$window->connect('delete-event',array('etemplate','delete_event'));
|
||||
$window->set_title('phpGroupwareGTK');
|
||||
$window->set_default_size(800,600);
|
||||
|
||||
$GLOBALS['phpgw_info']['etemplate']['window'] = &$window;
|
||||
}
|
||||
else
|
||||
{
|
||||
$window = &$GLOBALS['phpgw_info']['etemplate']['window'];
|
||||
}
|
||||
$result = array();
|
||||
$this->window->add($this->show($result,$content,$sel_options,$readonlys));
|
||||
/*
|
||||
* Show the window and all its child widgets.
|
||||
*/
|
||||
$this->window->show_all();
|
||||
$table = &$this->show($result,$content,$sel_options,$readonlys);
|
||||
$table->set_border_width(10);
|
||||
$table->show();
|
||||
|
||||
$swindow = &new GtkScrolledWindow(null,null);
|
||||
$swindow->set_policy(GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
|
||||
$swindow->add_with_viewport($table);
|
||||
$swindow->show();
|
||||
|
||||
$window->add($swindow);
|
||||
$window->show_all();
|
||||
|
||||
/* Run the main loop. */
|
||||
Gtk::main();
|
||||
|
||||
$this->collect_results();
|
||||
|
||||
$this->window->hide();
|
||||
unset($this->window);
|
||||
$swindow->hide();
|
||||
$window->remove($swindow);
|
||||
unset($swindow);
|
||||
unset($this->widgets);
|
||||
|
||||
// set application name so that lang, etc. works
|
||||
@ -167,6 +186,8 @@
|
||||
echo "$i: $set[name]/$set[type]/".Gtk::type_name($widget->get_type());
|
||||
switch ($set['type'])
|
||||
{
|
||||
case 'button': // is already done in the signal-handler
|
||||
break;
|
||||
case 'int':
|
||||
case 'float':
|
||||
case 'text':
|
||||
@ -197,7 +218,6 @@
|
||||
break;
|
||||
case 'textarea':
|
||||
case 'date':
|
||||
case 'button':
|
||||
}
|
||||
echo " = '$set[var]'\n";
|
||||
}
|
||||
@ -622,12 +642,11 @@
|
||||
$html .= $name == '' ? $image : $this->html->a_href($image,$name);
|
||||
break;
|
||||
*/ default:
|
||||
$html .= '<i>unknown type</i>';
|
||||
//$html .= '<i>unknown type</i>';
|
||||
$widget = &new GtkLabel('unknown type: '.$cell['type']);
|
||||
break;
|
||||
}
|
||||
$no_result = array('label' => True,'hrule' => True,'image' => True,'raw' => True,'template' => True);
|
||||
if ($widget && !$readonly && !$no_result[$cell['type']])
|
||||
if ($widget && !$readonly && !$this->no_result[$cell['type']])
|
||||
{
|
||||
$this->widgets[] = array(
|
||||
'widget' => &$widget,
|
||||
@ -675,244 +694,4 @@
|
||||
}
|
||||
return $hbox ? $hbox : $widget;
|
||||
}
|
||||
|
||||
/*!
|
||||
@function process_show
|
||||
@abstract makes necessary adjustments on HTTP_POST_VARS after a eTemplate / form gots submitted
|
||||
@discussion This is only an internal function, dont call it direct use only exec
|
||||
@discussion process_show recursivly calls itself for the included eTemplates.
|
||||
@param $vars HTTP_POST_VARS on first call, later (deeper recursions) subscripts of it
|
||||
@param $readonly array with cell- / var-names which should NOT return content (this is to workaround browsers who not understand READONLY correct)
|
||||
@param $cname basename of our returnt content (same as in call to show)
|
||||
@returns the adjusted content (in the simplest case that would be $vars[$cname])
|
||||
*/
|
||||
function process_show(&$content,$readonlys='')
|
||||
{
|
||||
if (!$readonlys)
|
||||
{
|
||||
$readonlys = array();
|
||||
}
|
||||
if (!isset($content) || !is_array($content))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ($this->debug >= 1 || $this->debug == $this->name && $this->name)
|
||||
{
|
||||
echo "<p>process_show($this->name) start: content ="; _debug_array($content);
|
||||
}
|
||||
reset($this->data);
|
||||
if (isset($this->data[0]))
|
||||
{
|
||||
each($this->data); // skip width
|
||||
}
|
||||
for ($r = 0; True /*list($row,$cols) = each($this->data)*/; ++$r)
|
||||
{
|
||||
$old_cols = $cols;
|
||||
if (!(list($nul,$cols) = each($this->data))) // no further row
|
||||
{
|
||||
$cols = $old_cols;
|
||||
list($nul,$cell) = each($cols); reset($cols);
|
||||
if ((!$this->autorepeat_idx($cols['A'],0,$r,$idx,$idx_cname) ||
|
||||
$idx_cname == '' || !$this->isset_array($idx,$content)) &&
|
||||
(!$this->autorepeat_idx($cols['B'],1,$r,$idx,$idx_cname) ||
|
||||
$idx_cname == '' || !$this->isset_array($idx,$content)))
|
||||
{
|
||||
break; // no auto-row-repeat
|
||||
}
|
||||
}
|
||||
$row = 1+$r;
|
||||
for ($c = 0; True /*list($col,$cell) = each($cols)*/; ++$c)
|
||||
{
|
||||
$old_cell = $cell;
|
||||
if (!(list($nul,$cell) = each($cols))) // no further cols
|
||||
{
|
||||
$cell = $old_cell;
|
||||
if (!$this->autorepeat_idx($cell,$c,$r,$idx,$idx_cname,True) ||
|
||||
$idx_cname == '' || !$this->isset_array($idx,$content))
|
||||
{
|
||||
break; // no auto-col-repeat
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->autorepeat_idx($cell,$c,$r,$idx,$idx_cname,True); // get idx_cname
|
||||
}
|
||||
$col = $this->num2chrs($c);
|
||||
|
||||
$name = $this->expand_name($cell['name'],$c,$r);
|
||||
$readonly = $cell['readonly'] || $readonlys[$name] || $readonlys['__ALL__'] ||
|
||||
$cell['type'] == 'label' || $cell['type'] == 'image' || $cell['type'] == 'raw' ||
|
||||
$cell['type'] == 'hrule';
|
||||
|
||||
if ($idx_cname == '' && $cell['type'] == 'template') // only templates
|
||||
{
|
||||
if ($readonly && !isset($readonlys['__ALL__'])) // can't unset whole content!!!
|
||||
{
|
||||
$readonlys['__ALL__'] = True;
|
||||
$this->process_show_cell($cell,$name,$c,$r,$readonlys,$content);
|
||||
unset($readonlys['__ALL__']); // unset it after or everything gets set readonly
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->process_show_cell($cell,$name,$c,$r,$readonlys,$content);
|
||||
}
|
||||
}
|
||||
elseif (ereg('^([^[]*)\\[(.*)\\]$',$idx_cname,$regs)) // name contains array-index
|
||||
{
|
||||
/* Attention: the unsets here and in the next else are vor two reasons:
|
||||
* 1) some browsers does NOT understand the READONLY-tag and sent content back
|
||||
* this has to be unset, as we only report no-readonly fields
|
||||
* 2) php has a fault / feature :-) that it set unset array-elements passed as
|
||||
* variable / changeable (&$var) to a function, this messes up a lot, as we
|
||||
* depend on the fact variables are set or not for the autorepeat. To work
|
||||
* around that, process_show_cell reports back if a variable is set or not
|
||||
* via the returnvalue and we unset it or even the parent if is was not set.
|
||||
*/
|
||||
$parent_isset = isset($content[$regs[1]]);
|
||||
|
||||
if ($readonly || !$this->process_show_cell($cell,$name,$c,$r,
|
||||
$readonlys[$regs[1]][$regs[2]],$content[$regs[1]][$regs[2]]))
|
||||
{
|
||||
if (!$parent_isset)
|
||||
{
|
||||
unset($content[$regs[1]]);
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($content[$regs[1]][$regs[2]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($readonly || !$this->process_show_cell($cell,$name,$c,$r,
|
||||
$readonlys[$idx_cname],$content[$idx_cname]))
|
||||
{
|
||||
unset($content[$idx_cname]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($this->debug >= 2 || $this->debug == $this->name && $this->name)
|
||||
{
|
||||
echo "<p>process_show($this->name) end: content ="; _debug_array($content);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
@function process_show_cell($cell,$name,$c,$r,$readonlys,&$value)
|
||||
@abstract makes necessary adjustments on $value eTemplate / form gots submitted
|
||||
@discussion This is only an internal function, dont call it direct use only exec
|
||||
@discussion process_show recursivly calls itself for the included eTemplates.
|
||||
@param $cell processed cell
|
||||
@param $name expanded name of cell
|
||||
@param $c,$r col,row index
|
||||
@param $readonlys readonlys-array to pass on for templates
|
||||
@param &$value value to change
|
||||
@returns if $value is set
|
||||
*/
|
||||
function process_show_cell($cell,$name,$c,$r,$readonlys,&$value)
|
||||
{
|
||||
if (is_array($cell['type']))
|
||||
{
|
||||
$cell['type'] = $cell['type'][0];
|
||||
}
|
||||
if ($this->debug >= 3 || $this->debug == $this->name || $this->debug == $cell['type'])
|
||||
{
|
||||
echo "<p>process_show_cell(c=$c, r=$r, name='$name',type='${cell['type']}) start: isset(value)=".(0+isset($value)).", value=";
|
||||
if (is_array($value))
|
||||
{
|
||||
_debug_array($value);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "'$value'</p>\n";
|
||||
}
|
||||
}
|
||||
switch ($cell['type'])
|
||||
{
|
||||
case 'int':
|
||||
case 'float':
|
||||
list($min,$max) = explode(',',$cell['size']);
|
||||
/*
|
||||
* TO DO: number- and range-check, if not enshured by java-script
|
||||
*/
|
||||
break;
|
||||
case 'text':
|
||||
case 'textarea':
|
||||
if (isset($value))
|
||||
{
|
||||
$value = stripslashes($value);
|
||||
}
|
||||
break;
|
||||
case 'date':
|
||||
if ($value['d'])
|
||||
{
|
||||
if (!$value['m'])
|
||||
{
|
||||
$value['m'] = date('m');
|
||||
}
|
||||
if (!$value['Y'])
|
||||
{
|
||||
$value['Y'] = date('Y');
|
||||
}
|
||||
if ($cell['size'] == '')
|
||||
{
|
||||
$value = mktime(0,0,0,$value['m'],$value['d'],$value['Y']);
|
||||
}
|
||||
else
|
||||
{
|
||||
for ($n = 0,$str = ''; $n < strlen($cell['size']); ++$n)
|
||||
{
|
||||
if (strstr('Ymd',$c = $cell['size'][$n]))
|
||||
{
|
||||
$str .= sprintf($c=='Y'?'%04d':'%02d',$value[$c]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$str .= $c;
|
||||
}
|
||||
}
|
||||
$value = $str;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = '';
|
||||
}
|
||||
break;
|
||||
case 'checkbox':
|
||||
if (!isset($value)) // checkbox was not checked
|
||||
{
|
||||
$value = 0; // need to be reported too
|
||||
}
|
||||
break;
|
||||
case 'template':
|
||||
$templ = new etemplate($name);
|
||||
$templ->process_show($value,$readonlys);
|
||||
break;
|
||||
case 'select':
|
||||
case 'select-cat':
|
||||
case 'select-account':
|
||||
if (is_array($value))
|
||||
{
|
||||
$value = count($value) <= 1 ? $value[0] : implode(',',$value);
|
||||
}
|
||||
break;
|
||||
default: // do nothing, $value is correct as is
|
||||
}
|
||||
if ($this->debug >= 3 || $this->debug == $this->name || $this->debug == $cell['type'])
|
||||
{
|
||||
echo "<p>process_show_cell(name='$name',type='${cell['type']}) end: isset(value)=".(0+isset($value)).", value=";
|
||||
if (is_array($value))
|
||||
{
|
||||
_debug_array($value);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "'$value'</p>\n";
|
||||
}
|
||||
}
|
||||
return isset($value);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user