gtk-ui handls know buttons like the html-ui

This commit is contained in:
Ralf Becker 2002-06-02 21:10:24 +00:00
parent b4b697f0f1
commit a642084e99
3 changed files with 105 additions and 71 deletions

View File

@ -255,4 +255,54 @@
} }
return $this->extension[$name]; return $this->extension[$name];
} }
/*!
@function isset_array($idx,$arr)
@abstract checks if idx, which may contain ONE subindex is set in array
*/
function isset_array($idx,$arr)
{
if (ereg('^([^[]*)\\[(.*)\\]$',$idx,$regs))
{
return $regs[2] && isset($arr[$regs[1]][$regs[2]]);
}
return isset($arr[$idx]);
}
function set_array(&$arr,$idx,$val,$set=True)
{
if (ereg('^([^[]*)(\\[.*\\])$',$idx,$regs)) // idx contains array-index
{
$arr_idx = '['.$regs[1].']'.$regs[2];
}
else
{
$arr_idx = "[$idx]";
}
if ($set)
{
$code = '$arr'.$arr_idx.' = $val;';
}
else
{
$code = 'unset($arr'.$arr_idx.');';
}
eval($code = str_replace(']',"']",str_replace('[',"['",$code)));
//echo "set_array: $code = '$val'\n";
}
function get_array(&$arr,$idx)
{
if (ereg('^([^[]*)(\\[.*\\])$',$idx,$regs)) // idx contains array-index
{
eval($code = str_replace(']',"']",str_replace('[',"['",'$val = $arr['.$regs[1].']'.$regs[2].';')));
//echo "get_array: $code = '$val'\n";
}
else
{
$val = $arr[$idx];
}
return $val;
}
}; };

View File

@ -138,19 +138,6 @@
ExecMethod($session_data['method'],array_merge($content,$session_data['preserv'])); ExecMethod($session_data['method'],array_merge($content,$session_data['preserv']));
} }
/*!
@function isset_array($idx,$arr)
@abstract checks if idx, which may contain ONE subindex is set in array
*/
function isset_array($idx,$arr)
{
if (ereg('^([^[]*)\\[(.*)\\]$',$idx,$regs))
{
return $regs[2] && isset($arr[$regs[1]][$regs[2]]);
}
return isset($arr[$idx]);
}
/*! /*!
@function show @function show
@abstract creates HTML from an eTemplate @abstract creates HTML from an eTemplate
@ -298,20 +285,17 @@
$name = $this->expand_name($cell['name'],$show_c,$show_row,$content['.c'],$content['.row'],$content); $name = $this->expand_name($cell['name'],$show_c,$show_row,$content['.c'],$content['.row'],$content);
$value = $content[$name]; $value = $content[$name];
$org_name = $name; if (ereg('^([^[]*)(\\[.*\\])$',$name,$regs)) // name contains array-index
if ($cname == '') // building the form-field-name depending on prefix $cname and possibl. Array-subscript in name
{ {
$form_name = $name; $form_name = $cname == '' ? $name : $cname.'['.$regs[1].']'.$regs[2];
} eval(str_replace(']',"']",str_replace('[',"['",'$value = $content['.$regs[1].']'.$regs[2].';')));
elseif (ereg('^([^[]*)\\[(.*)\\]$',$name,$regs)) // name contains array-index $org_name = substr($regs[2],1,-1);
{
$form_name = $cname.'['.$regs[1].']['.$regs[2].']';
$value = $content[$regs[1]][$regs[2]];
$org_name = $regs[2];
} }
else else
{ {
$form_name = $cname.'['.$name.']'; $form_name = $cname == '' ? $name : $cname.'['.$name.']';
$value = $content[$name];
$org_name = $name;
} }
if ($readonly = $cell['readonly'] || $readonlys[$name] || $readonlys['__ALL__']) if ($readonly = $cell['readonly'] || $readonlys[$name] || $readonlys['__ALL__'])
{ {

View File

@ -113,8 +113,8 @@
$window = &new GtkWindow(); $window = &new GtkWindow();
$window->connect('destroy',array('etemplate','destroy')); $window->connect('destroy',array('etemplate','destroy'));
$window->connect('delete-event',array('etemplate','delete_event')); $window->connect('delete-event',array('etemplate','delete_event'));
$window->set_title('phpGroupwareGTK'); $window->set_title('phpGroupWareGTK: '.$GLOBALS['phpgw_info']['server']['site_title']);
$window->set_default_size(800,600); $window->set_default_size(1024,600);
$GLOBALS['phpgw_info']['etemplate']['window'] = &$window; $GLOBALS['phpgw_info']['etemplate']['window'] = &$window;
} }
@ -122,8 +122,8 @@
{ {
$window = &$GLOBALS['phpgw_info']['etemplate']['window']; $window = &$GLOBALS['phpgw_info']['etemplate']['window'];
} }
$result = array(); $this->result = array('test' => 'test');
$table = &$this->show($result,$content,$sel_options,$readonlys); $table = &$this->show($this->result,$content,$sel_options,$readonlys);
$table->set_border_width(10); $table->set_border_width(10);
$table->show(); $table->show();
@ -148,8 +148,7 @@
// set application name so that lang, etc. works // set application name so that lang, etc. works
list($GLOBALS['phpgw_info']['flags']['currentapp']) = explode('.',$method); list($GLOBALS['phpgw_info']['flags']['currentapp']) = explode('.',$method);
//echo "<p>uietemplate.process_exec: ExecMethod('${exec['method']}')</p>\n"; ExecMethod($method,array_merge($this->result,$preserv));
ExecMethod($method,array_merge($result,$preserv));
} }
/* /*
@ -170,10 +169,16 @@
exit(); exit();
} }
function button_clicked(&$data) function button_clicked(&$var,$form_name)
{ {
$data = 'pressed'; echo "button '$form_name' pressed\n";
echo "button pressed\n"; $var = 'pressed';
Gtk::main_quit();
}
function submit()
{
echo "OnChange --> submit\n";
Gtk::main_quit(); Gtk::main_quit();
} }
@ -184,24 +189,29 @@
$set = &$this->widgets[$i]; $set = &$this->widgets[$i];
$widget = &$set['widget']; $widget = &$set['widget'];
$val_is_set = False;
echo "$i: $set[name]/$set[type]/".Gtk::type_name($widget->get_type()); echo "$i: $set[name]/$set[type]/".Gtk::type_name($widget->get_type());
switch ($set['type']) switch ($set['type'])
{ {
case 'button': // is already done in the signal-handler case 'button': // is set to 'pressed' or is '' (not unset !!!)
$val_is_set = ($val = $this->get_array($this->result,$set['name']));
break; break;
case 'int': case 'int':
case 'float': case 'float':
case 'text': case 'text':
case 'textarea': case 'textarea':
$set['var'] = $widget->get_chars(0,-1); $val = $widget->get_chars(0,-1);
$val_is_set = True;
break; break;
case 'checkbox': case 'checkbox':
$set['var'] = $widget->get_active(); $val = $widget->get_active();
$val_is_set = True;
break; break;
case 'radio': case 'radio':
if ($widget->get_active()) if ($widget->get_active())
{ {
$set['var'] = $set['set_val']; $val = $set['set_val'];
$val_is_set = True;
} }
break; break;
case 'select': case 'select':
@ -213,28 +223,18 @@
{ {
if ($val == $selected) if ($val == $selected)
{ {
$set['var'] = $key; $val = $key;
$val_is_set = True;
break; break;
} }
} }
break; break;
case 'date': case 'date':
} }
echo " = '$set[var]'\n"; echo $val_is_set && !$set['readonly'] ? " = '$val'\n" : " NOT SET\n";
}
}
/*! $this->set_array($this->result,$set['name'],$val,$val_is_set && !$set['readonly']);
@function isset_array($idx,$arr)
@abstract checks if idx, which may contain ONE subindex is set in array
*/
function isset_array($idx,$arr)
{
if (ereg('^([^[]*)\\[(.*)\\]$',$idx,$regs))
{
return $regs[2] && isset($arr[$regs[1]][$regs[2]]);
} }
return isset($arr[$idx]);
} }
/*! /*!
@ -254,7 +254,7 @@
@param $show_xxx row,col name/index for name expansion @param $show_xxx row,col name/index for name expansion
@returns the generated HTML @returns the generated HTML
*/ */
function show(&$result,$content,$sel_options='',$readonlys='',$show_c=0,$show_row=0) function show(&$result,$content,$sel_options='',$readonlys='',$cname='',$show_c=0,$show_row=0)
{ {
if (!$sel_options) if (!$sel_options)
{ {
@ -422,29 +422,24 @@
list($span) = explode(',',$cell['span']); // evtl. overriten later for type template list($span) = explode(',',$cell['span']); // evtl. overriten later for type template
$name = $this->expand_name($cell['name'],$show_c,$show_row,$content['.c'],$content['.row'],$content); $name = $this->expand_name($cell['name'],$show_c,$show_row,$content['.c'],$content['.row'],$content);
$value = $content[$name];
$var = &$result[$name];
$org_name = $name; // building the form-field-name depending on prefix $cname and possibl. Array-subscript in name
if ($cname == '') // building the form-field-name depending on prefix $cname and possibl. Array-subscript in name if (ereg('^([^[]*)(\\[.*\\])$',$name,$regs)) // name contains array-index
{ {
$form_name = $name; $form_name = $cname == '' ? $name : $cname.'['.$regs[1].']'.$regs[2];
} eval(str_replace(']',"']",str_replace('[',"['",'$value = $content['.$regs[1].']'.$regs[2].';')));
elseif (ereg('^([^[]*)\\[(.*)\\]$',$name,$regs)) // name contains array-index $org_name = substr($regs[2],1,-1);
{ eval(str_replace(']',"']",str_replace('[',"['",'$var = &$result['.$regs[1].']'.$regs[2].';')));
$form_name = $cname.'['.$regs[1].']['.$regs[2].']';
$value = $content[$regs[1]][$regs[2]];
$var = &$result[$regs[1]][$regs[2]];
$org_name = $regs[2];
} }
else else
{ {
$form_name = $cname.'['.$name.']'; $form_name = $cname == '' ? $name : $cname.'['.$name.']';
} $value = $content[$name];
if ($readonly = $cell['readonly'] || $readonlys[$name] || $readonlys['__ALL__']) $org_name = $name;
{ $var = &$result[$name];
$options .= ' READONLY';
} }
$readonly = $cell['readonly'] || $readonlys[$name] || $readonlys['__ALL__'];
if ($cell['disabled'] || $cell['type'] == 'button' && $readonly) if ($cell['disabled'] || $cell['type'] == 'button' && $readonly)
{ {
if ($this->rows == 1) { if ($this->rows == 1) {
@ -464,6 +459,7 @@
} }
list($left_label,$right_label) = explode('%s',$label); list($left_label,$right_label) = explode('%s',$label);
//echo "show_cell: type='$cell[type]', name='$cell[name]'-->'$name', value='$value'\n";
$widget = False; $widget = False;
switch ($cell['type']) switch ($cell['type'])
{ {
@ -580,7 +576,7 @@
case 'button': case 'button':
//$html .= $this->html->submit_button($form_name,$cell['label'],'',strlen($cell['label']) <= 1 || $cell['no_lang'],$options); //$html .= $this->html->submit_button($form_name,$cell['label'],'',strlen($cell['label']) <= 1 || $cell['no_lang'],$options);
$widget = &new GtkButton(strlen($cell['label']) > 1 ? lang($cell['label']) : $cell['label']); $widget = &new GtkButton(strlen($cell['label']) > 1 ? lang($cell['label']) : $cell['label']);
$widget->connect_object('clicked', array('etemplate', 'button_clicked'),&$var); $widget->connect_object('clicked', array('etemplate', 'button_clicked'),&$var,$form_name);
break; break;
case 'hrule': case 'hrule':
//$html .= $this->html->hr($cell['size']); //$html .= $this->html->hr($cell['size']);
@ -651,6 +647,10 @@
$entry->set_text($sel_options[$value]); $entry->set_text($sel_options[$value]);
$entry->set_editable(False); $entry->set_editable(False);
$entry->set_usize($maxlen*$this->font_width,0); $entry->set_usize($maxlen*$this->font_width,0);
if ($cell['onchange'] == '1')
{
$entry->connect('changed',array('etemplate', 'submit'));
}
break; break;
/* case 'select-percent': /* case 'select-percent':
$html .= $this->sbox->getPercentage($form_name,$value,$options); $html .= $this->sbox->getPercentage($form_name,$value,$options);
@ -695,9 +695,9 @@
$this->widgets[] = array( $this->widgets[] = array(
'widget' => &$widget, 'widget' => &$widget,
'type' => $cell['type'], 'type' => $cell['type'],
'var' => &$var,
'set_val' => $cell['type'] == 'radio' ? $cell['size'] : $sel_options, 'set_val' => $cell['type'] == 'radio' ? $cell['size'] : $sel_options,
'name' => $form_name 'name' => $form_name,
'readonly' => $readonly
); );
} }
if ($cell['type'] != 'button' && $cell['type'] != 'image' && ($left_label || $right_label)) if ($cell['type'] != 'button' && $cell['type'] != 'image' && ($left_label || $right_label))