config_dialog_generic($glade,$config_array); $conf->btn_ok->connect("pressed",array(&$this,"update_config")); to display it: $conf->prefs = $current_config_array; $conf->show(); function update_config() { $new_config_array = $conf->get_results(); $conf->hide(); } */ class config_dialog_generic extends phpide_dialog_generic { var $prefs; // where stuff is stored and retrieved from function init($conf_array) { //$this->phpide_dialog_generic($glade); $prefs = $conf_array; foreach($prefs as $k => $v) { $kname = ereg_replace("[^a-z0-9]+", "_", trim(strtolower($k))); $widget = $this->widget->get_widget($kname); if (!$widget) continue; switch (get_class($widget)) { case "GtkButton": $widget->connect_object_after('clicked', array(&$this,"select_font"), array($kname,$k)); break; case "GtkDrawingArea": $btn = $widget->parent; $btn->connect_object_after('button_press_event', array(&$this,"select_color"), $kname, $k); break; } } // actions //sub dialogs $this->dialog_font_select=$this->widget->get_widget("fontselectiondialog1"); $this->dialog_color_select=$this->widget->get_widget("colorselectiondialog1"); $this->dialog_color_select_widget=$this->dialog_color_select->colorsel; $this->btn_fontsel_ok=$this->widget->get_widget("fontsel_ok"); $this->btn_fontsel_cancel=$this->widget->get_widget("fontsel_cancel"); $this->btn_fontsel_ok->connect_object_after('clicked',array(&$this,"fontsel_ok")); $this->btn_fontsel_cancel->connect_object_after('clicked',array(&$this,"fontsel_cancel")); $this->btn_colorsel_ok=$this->widget->get_widget("colorsel_ok"); $this->btn_colorsel_cancel=$this->widget->get_widget("colorsel_cancel"); $this->btn_colorsel_ok->connect_object_after('clicked',array(&$this,"colorsel_ok")); $this->btn_colorsel_cancel->connect_object_after('clicked',array(&$this,"colorsel_cancel")); // my ok and cancel // defined in parent! //$this->btn_ok->connect_object_after('clicked',array(&$this,ok_pressed)); //echo "CONNECTING cancel"; $this->btn_cancel->connect_object_after('clicked',array(&$this,"hide")); } function show($prefs="") { if ($prefs) $this->prefs = $prefs; if (!$this->prefs) return; foreach($this->prefs as $k => $v) { $kname = ereg_replace("[^a-z0-9]+", "_", trim(strtolower($k))); $kname2 = ereg_replace("[^a-z0-9]+", "_", trim(strtolower($k." ".sprintf("%01d",$v)))); $widget = $this->widget->get_widget($kname); if (!$widget) $widget = $this->widget->get_widget($kname2); if (!$widget) { //echo "NO WIDGET FOR $k"; continue; } switch (get_class($widget)) { case "GtkCheckButton": $vv=0; if ($v) $vv = 1; $widget->set_active($vv); break; case "GtkSpinButton": $widget->set_value($v); break; case "GtkButton": $this->set_fontname( $kname,$v); break; case "GtkDrawingArea": $this->set_buttoncolor($kname,$v); break; case "GtkRadioButton": $widget->set_active(0); break; case "GtkText": //$len = $widget->get_length(); $widget->delete_text(0,-1); $t = explode(" ", $v); asort($t); $tt = implode("\n", $t); $widget->insert_text($tt,0); break; } } $this->__show(); // $this->text_entry->set_text(""); // $this->text_entry->grab_focus(); } function winFont($font) { if (substr(PHP_OS, 0, 3) == 'WIN') { return 'Arial'; } return $font; } function set_buttoncolor($widgetname, $setting) { //echo $setting; $setting = substr("000000".dechex($setting),-6); $s = substr($setting,4,2) . substr($setting,2,2) . substr($setting,0,2); $setting = "#". $s; //echo "\nSETTING COLOR? $widgetname $setting"; $w = $this->widget->get_widget($widgetname); //echo serialize($w); $p = $w->parent; $p->set_sensitive(TRUE); $current_style=$w->get_style(); $new_style = $current_style->copy(); $new_style->bg[GTK_STATE_NORMAL]=new GdkColor($setting); $new_style->bg[GTK_STATE_NORMAL]=new GdkColor($setting); $w->set_style($new_style); $w->hide(); $w->show(); } function set_fontname($widgetname,$setting) { $b = $this->widget->get_widget($widgetname); $w = $b->child; $fontar = explode("-",$setting); $size = $fontar[7]; if ($size == "*") $size = $fontar[8]/10; if (substr(PHP_OS, 0, 3) != 'WIN') { $current_style=$w->get_style(); $new_style = $current_style->copy(); $new_style->font = gdk::font_load($setting); $w->set_style($new_style); } $w->set_text("{$fontar[2]} ($size) {$fontar[3]}"); $b->set_sensitive(TRUE); } function select_font($a) { $fontar = explode("-",$this->prefs[$a[1]]); //echo serialize($fontar); if ($fontar[8] == "*") { $fontar[8] = $fontar[7]*10; $fontar[7] = "*"; } $fontname = implode("-",$fontar); //echo "SET" .$fontname; $this->dialog_font_select->set_font_name($fontname); $this->dialog_font_select->show(); $this->active_font_sel = $a[1]; $this->active_font_sel_widget = $a[0]; Gtk::grab_remove($this->window); Gtk::grab_add($this->dialog_font_select); } function fontsel_ok() { $this->prefs[$this->active_font_sel] = $this->dialog_font_select->get_font_name(); //echo "GOT " .$this->prefs[$this->active_font_sel]; $this->set_fontname($this->active_font_sel_widget,$this->prefs[$this->active_font_sel]); $this->dialog_font_select->hide(); Gtk::grab_remove($this->dialog_font_select); Gtk::grab_add($this->window); if (method_exists($this,"extend_font_change")) $this->extend_font_change($this->active_font_sel); } function fontsel_cancel() { $this->dialog_font_select->hide(); Gtk::grab_remove($this->dialog_font_select); Gtk::grab_add($this->window); } function select_color($e,$widgetname,$config_variable){ //echo "looking up prefs ". serialize($a)."\n"; $setting = substr("000000".dechex($this->prefs[$config_variable]),-6); $b = hexdec( substr($setting,0,2)) /256; $g = hexdec( substr($setting,2,2))/256; $r = hexdec( substr($setting,4,2))/256; $this->not_active_window = TRUE; $this->dialog_color_select_widget->set_color($r,$g,$b); $this->dialog_color_select->show(); $wi = $this->dialog_color_select->window; $wi->raise(); $this->active_color_sel = $config_variable; $this->active_color_sel_widget = $widgetname; Gtk::grab_remove($this->window); Gtk::grab_add($this->dialog_color_select); } function colorsel_ok() { $a = $this->dialog_color_select_widget->get_color(); echo "GOT " . serialize($a); $b = substr("00".dechex($a[2]*255),-2) . substr("00".dechex($a[1]*255),-2) . substr("00".dechex($a[0]*255),-2); //echo "XX " . $this->active_color_sel . " storing ($b) = ". hexdec($b) . "\n"; $this->prefs[$this->active_color_sel] = hexdec($b); $this->set_buttoncolor( $this->active_color_sel_widget, $this->prefs[$this->active_color_sel]); $this->dialog_color_select->hide(); Gtk::grab_remove($this->dialog_color_select); Gtk::grab_add($this->window); $this->not_active_window = FALSE; if (method_exists($this,"extend_color_change")) $this->extend_color_change($this->active_color_sel); } function colorsel_cancel() { $this->dialog_color_select->hide(); Gtk::grab_remove($this->dialog_color_select); Gtk::grab_add($this->window); $this->not_active_window = FALSE; } function get_results() { foreach($this->prefs as $k => $v) { $kname = ereg_replace("[^a-z0-9]+", "_", trim(strtolower($k))); $kname2 = ereg_replace("[^a-z0-9]+", "_", trim(strtolower($k." ".sprintf("%01d",$v)))); $widget = $this->widget->get_widget($kname); if (!$widget) $widget = $this->widget->get_widget($kname2); switch (get_class($widget)) { case "GtkCheckButton": if (!$widget) continue; $this->prefs[$k] = $widget->get_active(); break; case "GtkSpinButton": if (!$widget) continue; $this->prefs[$k] = $widget->get_value_as_int(); break; case "GtkRadioButton": // now this is a bit more complex!!! $this->prefs[$k] = 0; // default it for ($i=0;$i<9;$i++) { echo "LOOKING FOR ".$kname . "_".sprintf("%01d",$i); $w = $this->widget->get_widget($kname . "_".sprintf("%01d",$i)); if (!$w) break; if (!$w->get_active()) continue; echo "SETTING!"; $this->prefs[$k] = $i; break; } break; case "GtkText": $s = $widget->get_chars(0,-1); $st = trim(str_replace("\n", " ", $s)); $this->prefs[$k] = $st; break; } } } } ?>