#!/usr/bin/perl
# -*- perl -*-
# Generated automatically from ConfigEdit.in by configure.

# Enlightenment Configurator version 0.1
# Copyright 1998 Geoff Harrison (Mandrake)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

use Gtk;
use Gtk::Atoms;

$version = "0.1";
$enlversion = "0.14";
init Gtk;

@actions = ();

sub destroy_window {
	my($widget, $windowref, $w2) = @_;
	$$windowref = undef;
	$w2 = undef if defined $w2;
	0;
}

@actionclasstypes = ("normal","globalkeybind");
@action_types =  ("ACTION_NONE","ACTION_EXEC","ACTION_ALERT","ACTION_MOVE","ACTION_RESIZE","ACTION_RAISE","ACTION_LOWER","ACTION_EXIT","ACTION_CLEANUP","ACTION_SHOW_MENU","ACTION_HIDE_MENU","ACTION_RESIZE_H","ACTION_RESIZE_V","ACTION_KILL","ACTION_KILL_NASTY","ACTION_DESKTOP_NEXT","ACTION_DESKTOP_PREV","ACTION_DESKTOP_RAISE","ACTION_DESKTOP_LOWER","ACTION_DESKTOP_DRAG","ACTION_STICK","ACTION_DESKTOP_INPLACE","ACTION_DRAG_BUTTON","ACTION_FOCUSMODE_SET","ACTION_MOVEMODE_SET","ACTION_RESIZEMODE_SET","ACTION_SLIDEMODE_SET","ACTION_CLEANUPSILDE_SET","ACTION_MAPSLIDE_SET","ACTION_SOUND_SET","ACTION_BUTTONMOVE_RESIST_SET","ACTION_DESKTOPBG_TIMEOUT_SET","ACTION_MAPSLIDE_SPEED_SET","ACTION_CLEANUPSLIDE_SPEED_SET","ACTION_DRAGDIR_SET","ACTION_DRAGBAR_ORDER_SET","ACTION_DRAGBAR_WIDTH_SET","ACTION_DRAGBAR_LENGTH_SET","ACTION_DESKSLIDE_SET","ACTION_DESKSLIDE_SPEED_SET","ACTION_HIQUALITYBG_SET","ACTION_PLAYSOUNDCLASS","ACTION_GOTO_DESK","ACTION_DESKRAY","ACTION_AUTOSAVE_SET","ACTION_HIDESHOW_BUTTON");
@event_types = ("mousedown","mouseup","keydown","keyup","mouseover","mouseout");
@button_types = ("none","1","2","3","any");
@modifier_types = ("none","ctrl","alt","shift","ctrl+alt","ctrl+shift","alt+shift","ctrl+alt+shift","any");


@keys_available = ("BackSpace","Tab","Escape","Delete","Home","Left","Up","Right","Down","Page_Up","Page_Down","End","Insert","Equal","Decimal","F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F12","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0");

sub create_and_tie_entrybox {

	my $ref = shift;
	my $entry = new Gtk::Entry;
	$entry->set_text($$ref);
	$entry->signal_connect( "changed" => sub { $$ref = $entry->get_text; });
	$entry->show;

	return $entry;
}

sub create_and_tie_menu {

	my $menu = new Gtk::OptionMenu;
	$menu->set_menu(create_menu(@_));
	$menu->set_history($curitem);

	return $menu;

}

sub file_selection_ok {
	my($widget, $fs) = @_;
	Gtk->print( $fs->get_filename . "\n");
}

sub LoadControlSegment {
	my $currentline;
	CONTROL: while(!(($currentline = <FILE>) =~ /\}/) ) {
		$currentline =~ s/^\s+//g;
		next CONTROL if($currentline =~ /^#/);
		next CONTROL if(!$currentline);
		my @options = split(/\s+/,$currentline);
		$control{$options[0]} = $options[1];
	}
}

sub LoadActionClass {

	my $currentline;
	my %action = ();
	my $currentaction;
	my %something = ();
	my @localactions = ();
	$action{"actionset"} = \@localactions;
	$currentaction = \%something;
	$currentaction->{button} = "none";
	$currentaction->{modifier} = "none";
	{
		my @setofactions = ();
		$currentaction->{actionsubset} = \@setofactions;
	}

	ACTION:  while(!(($currentline = <FILE>) =~ /\}/) ) {
		$currentline =~ s/^\s+//g;
		next ACTION if($currentline =~ /^#/);
		next ACTION if(!$currentline);
		my @options = split(/\s+/,$currentline);
		if(uc($options[0]) eq "NEXT") {
			my %somethingorother = ();
			push @localactions, $currentaction;
			$currentaction = \%somethingorother;
			my @setofactions = ();
			$currentaction->{actionsubset} = \@setofactions;
		} else {
			if(uc($options[0]) =~ /^TYPE|CLASSNAME$/) {
				$action{$options[0]} = $options[1];
			} else {
				if(uc($options[0]) =~ /^ANYBUT|ANYMOD$/) {
					if(uc($options[0]) eq "ANYBUT") {
						$currentaction->{button} = "any";
					} else {
						$currentaction->{modifier} = "any";
					}
				} else {
					if($options[0] eq "action") {
						my %actionsubset = ();
						$actionsubset{action} = $options[1];
						$actionsubset{params} = substr($currentline,index($currentline,$options[2])) if($options[2] ne "");
						chomp $actionsubset{params} if($actionsubset{params});
						push @{$currentaction->{actionsubset}}, \%actionsubset;
					} else {
						$currentaction->{$options[0]} = $options[1];
					}
				}
			}
		}
	}
	push @localactions, $currentaction;
	push @actions,\%action;

}

sub LoadTextClass {

	my $currentline;
	my %textclass;
	TEXT:  while(!(($currentline = <FILE>) =~ /\}/) ) {
		$currentline =~ s/^\s+//g;
		next TEXT if($currentline =~ /^#/);
		next TEXT if(!$currentline);
		my @options = split(/\s+/,$currentline);
		$textclass{$options[0]} = $options[1];
	}
	push @textclasses,\%textclass;

}

sub LoadSoundClasses {

	my $currentline;
	SOUND:  while(!(($currentline = <FILE>) =~ /\}/) ) {
		$currentline =~ s/^\s+//g;
		next SOUND if($currentline =~ /^#/);
		next SOUND if(!$currentline);
		my @options = split(/\s+/,$currentline);
		$sounds{$options[0]} = $options[1];
	}

}

sub LoadButton {

	my $currentline;
	my %buttonclass;
	BUTTON:  while(!(($currentline = <FILE>) =~ /\}/) ) {
		$currentline =~ s/^\s+//g;
		next BUTTON if($currentline =~ /^#/);
		next BUTTON if(!$currentline);
		my @options = split(/\s+/,$currentline);
		$buttonclass{$options[0]} = $options[1];
	}
	push @buttons,\%buttonclass;

}

sub LoadBackground {

	my $currentline;
	my %background;
	my @bgdesk;
	$background{bgdesk} = \@bgdesk;
	BACKGROUND:  while(!(($currentline = <FILE>) =~ /\}/) ) {
		$currentline =~ s/^\s+//g;
		next BACKGROUND if($currentline =~ /^#/);
		next BACKGROUND if(!$currentline);
		my @options = split(/\s+/,$currentline);
		if(uc($options[0]) eq "BGDESK") {
			push @bgdesk, $options[1];
		} else {
			$background{$options[0]} = substr($currentline,index($currentline,$options[1]));
			chomp $background{$options[0]};
		}
	}
	push @backgrounds,\%background;

}

sub purgeconfig {

	%control = ();
	@actions = ();
	@textclasses = ();
	%sounds = ();
	@buttons = ();

}

sub loadconfigfile {

	if(-e $_[0]) {
		open FILE, $_[0];
		CONFIGSET: while(<FILE>) {
			s/^\s+//g;
			next CONFIGSET if(/^#/);
			next CONFIGSET if(!$_);
			@currentline = split(/\s+/);
			if($currentline[1] eq "{") {
				if(uc($currentline[0]) eq "CONTROL") {
					LoadControlSegment;
				} elsif(uc($currentline[0]) eq "ACTIONCLASS") {
					LoadActionClass;
				} elsif(uc($currentline[0]) eq "TEXTCLASS") {
					LoadTextClass;
				} elsif(uc($currentline[0]) eq "SOUND") {
					LoadSoundClasses;
				} elsif(uc($currentline[0]) eq "BUTTON") {
					LoadButton;
				} elsif(uc($currentline[0]) eq "DESKTOP") {
					LoadBackground;
				} else {
					# Currently unsupported segment?
				}
			}

		}
		close FILE;

	} else {
		print "That file doesn't exist.  bummer\n";
	}

}

sub saveconfigfile {

	my $filename = shift;
	my $segemnt;

	open FILE, ">$filename";
	print FILE "# This configuration file was automatically generated by the\n";
	print FILE "# Enlightenment Configurator version $version\n";
	print FILE "# Copyright 1998 Geoff Harrison (mandrake\@mandrake.net)\n";
	print FILE "# In theory, this configuration should be compatible with enlightenment\n";
	print FILE "# version $enlversion.  For information on enlightenment or the\n";
	print FILE "# enlightenment configurator, see http://www.enlightenment.org.\n";
	print FILE "# Edit at your own risk.\n\n";

# Dump control segment.
	print FILE "control {\n\n";
	foreach(keys(%control)) {
		print FILE "  $_ $control{$_}\n";
	}
	print FILE "\n}\n";

# Dump Text Classes
	foreach $segment (@textclasses) {
		print FILE "\n\ntextclass {\n\n  classname $segment->{classname}\n";
		foreach(keys(%$segment)) {
			print FILE "  $_ $segment->{$_}\n" if(!(/classname/));
		}
		print FILE "\n}\n";
	}

# Dump Action Classes

	foreach $action (@actions) {
		print FILE "\n\nactionclass {\n\n  classname $action->{classname}\n";
		$firstone = 1;
		foreach $set (keys(%$action)) {
			if($set =~ /actionset/) {
				my $list = $action->{"actionset"};
				my $firstone=1;
				foreach $item (@$list) {
					if($firstone) {
						$firstone=0;
					} else {
						print FILE "\n  next\n";
					}
					foreach(keys(%$item)) { 
						if(!(/action/ || /key/)) {
							if(/button|modifier/) {
								if($item->{$_} =~ /^any$/) {
									print FILE "  any" . substr($_,0,3) . " yes\n";
								} elsif($item->{$_} =~ /^none$/) {
								} else {
									print FILE "  $_ $item->{$_}\n";
								}
							} else {
								print FILE "  $_ $item->{$_}\n" if(!(/params/));
							}
						}
					}
					print FILE "  key $item->{key}\n" if $item->{key};
					foreach $setkey (@{$item->{actionsubset}}) {
						print FILE "  action $setkey->{action}";
						print FILE " $setkey->{params}" if $setkey->{params};
						print FILE " $setkey->{params}" if($setkey->{params} eq "0");
						print FILE "\n";
					}
				}
			} else {
				print FILE "  $set $action->{$set}\n" if(!($set =~ /classname/));
			}
		}
		print FILE "\n}\n";
	}

# Dump Sound Classes
	print FILE "\n\nsound {\n\n";
	foreach (keys(%sounds)) {
		print FILE "  $_ $sounds{$_}\n";

	}
	print FILE "}\n";

# Dump Buttons
	foreach $segment (@buttons) {
		print FILE "\n\nbutton {\n\n  name $segment->{name}\n";
		foreach(keys(%$segment)) {
			print FILE "  $_ $segment->{$_}\n" if(!(/name/));
		}
		print FILE "\n}\n";
	}

# Dump Desktop Settings...

	foreach $segment (@backgrounds) {
		print FILE "\n\ndesktop {\n\n";
		print FILE "  bgname $segment->{bgname}\n";
		print FILE "  rgb $segment->{rgb}\n" if $segment->{rgb};
		print FILE "  bg1 $segment->{bg1}\n";
		print FILE "  bg2 $segment->{bg2}\n" if $segment->{bg2};
		foreach(@{$segment->{bgdesk}}) {
			print FILE "  bgdesk $_\n";
		}
		print FILE "\n}\n";
	}

# Done
	close FILE;
}


sub create_save_file_selection {
	if (not defined $fs_window) {
		$fs_window = new Gtk::FileSelection "Save Config File";
		$fs_window->position(-mouse);
		$fs_window->signal_connect("destroy", \&destroy_window, \$fs_window);
		$fs_window->signal_connect("delete_event", \&destroy_window, \$fs_window);
		$fs_window->ok_button->signal_connect("clicked", sub { &saveconfigfile($_[1]->get_filename); destroy $fs_window; } , $fs_window);
		$fs_window->cancel_button->signal_connect("clicked", sub { destroy $fs_window });
		
	}
	if (!visible $fs_window) {
		show $fs_window;
	} else {
		destroy $fs_window;
	}
}

sub create_load_file_selection {
	if (not defined $fs_window) {
		$fs_window = new Gtk::FileSelection "Load Config File";
		$fs_window->position(-mouse);
		$fs_window->signal_connect("destroy", \&destroy_window, \$fs_window);
		$fs_window->signal_connect("delete_event", \&destroy_window, \$fs_window);
		$fs_window->ok_button->signal_connect("clicked", sub { &loadconfigfile($_[1]->get_filename); destroy $fs_window; } , $fs_window);
		$fs_window->cancel_button->signal_connect("clicked", sub { destroy $fs_window });
		
	}
	if (!visible $fs_window) {
		show $fs_window;
	} else {
		destroy $fs_window;
	}
}

sub create_grab_file_selection {
	if (not defined $fs_window) {
		$fs_window = new Gtk::FileSelection "Load Config File";
		$fs_window->position(-mouse);
		$fs_window->signal_connect("destroy", \&destroy_window, \$fs_window);
		$fs_window->signal_connect("delete_event", \&destroy_window, \$fs_window);
		$fs_window->ok_button->signal_connect("clicked", sub { $$entryref->set_text($_[1]->get_filename); destroy $fs_window; }, $fs_window);
		$fs_window->cancel_button->signal_connect("clicked", sub { destroy $fs_window });
		
	}
	if (!visible $fs_window) {
		show $fs_window;
	} else {
		destroy $fs_window;
	}
}


sub create_preferences_box {

	my($box1,$box2,$box3,$entry,$entry2,$entry3,$button,$button2,$label);
	if(not defined $prefs_box) {
		$prefs_box = new Gtk::Window "toplevel";
		$prefs_box->set_name("pref window");
		$prefs_box->signal_connect("destroy", \&destroy_window, \$prefs_box);
		$prefs_box->signal_connect("delete_event", \&destroy_window, \$prefs_box);
		$prefs_box->set_title("Configurator Preferences");
		$prefs_box->border_width(0);

		$box1 = new Gtk::VBox(0,0);
		$prefs_box->add($box1);
		$box1->show;

		$label = new Gtk::Label "Configurator Preferences";
		$box1->pack_start($label,1,1,0);
		show $label;

		$box2 = new Gtk::HBox(0,0);
		$box2->border_width(5);
		$box1->pack_start($box2,1,1,0);
		$box2->show;

		$box3 = new Gtk::VBox(0,0);
		$box3->border_width(5);
		$box2->pack_start($box3,1,1,0);
		$box3->show;

		$label = new Gtk::Label "Default Config: ";
		$label->set_alignment(1.0,0.5);
		$box3->pack_start($label,1,1,0);
		show $label;

		$label = new Gtk::Label "Components Dir: ";
		$label->set_alignment(1.0,0.5);
		$box3->pack_start($label,1,1,0);
		show $label;

		$label = new Gtk::Label "Gtkrc file to load: ";
		$label->set_alignment(1.0,0.5);
		$box3->pack_start($label,1,1,0);
		show $label;

		$box3 = new Gtk::VBox(0,0);
		$box3->border_width(5);
		$box2->pack_start($box3,1,1,0);
		$box3->show;

		$entry2 = new Gtk::Entry;
		if($prefs{cfgtoload}) {
			$entry2->set_text($prefs{cfgtoload});
		}
		$box3->pack_start($entry2,1,1,0);
		$entry2->show;

		$entry = new Gtk::Entry;
		if($prefs{enlroot}) {
			$entry->set_text($prefs{enlroot});
		}
		$box3->pack_start($entry,1,1,0);
		$entry->show;

		$entry3 = new Gtk::Entry;
		if($prefs{gtkrc}) {
			$entry3->set_text($prefs{gtkrc});
		}
		$box3->pack_start($entry3,1,1,0);
		$entry3->show;

		$box3 = new Gtk::VBox(0,0);
		$box3->border_width(5);
		$box2->pack_start($box3,1,1,0);
		$box3->show;

		$button2 = new Gtk::Button "Browse";
		$box3->pack_start($button2,1,1,0);
		$button2->signal_connect("clicked", sub { $entryref = \$entry2; &create_grab_file_selection; });
		$button2->show;

		$button2 = new Gtk::Button "Browse";
		$box3->pack_start($button2,1,1,0);
		$button2->signal_connect("clicked", sub { $entryref = \$entry; &create_grab_file_selection; });
		$button2->show;

		$button2 = new Gtk::Button "Browse";
		$box3->pack_start($button2,1,1,0);
		$button2->signal_connect("clicked", sub { $entryref = \$entry3; &create_grab_file_selection; });
		$button2->show;

		$box2 = new Gtk::HBox(0,0);
		$box2->border_width(5);
		$box1->pack_start($box2,1,1,0);
		$box2->show;

		my $aboutboxstate;
		$button = new Gtk::CheckButton "Disable About Box On Startup";
		$button->set_state(1) if($prefs{no_about_box});
		$aboutboxstate=1 if($prefs{no_about_box});
		$button->signal_connect("clicked", sub { if($aboutboxstate) { $aboutboxstate=0;} else { $aboutboxstate=1;}});
		$box2->pack_start($button,1,1,0);
		$button->show;

		$button2 = new Gtk::Button "Save Preferences";
		$button2->signal_connect("clicked", 
				sub {  
					if($aboutboxstate > 0) {
						$prefs{no_about_box} = yes
					} else {
						delete $prefs{no_about_box};
					}
					$prefs{enlroot} = $entry->get_text;
					$prefs{cfgtoload} = $entry2->get_text;
					$prefs{gtkrc} = $entry3->get_text;
					open PREFFILE, ">" . $ENV{HOME} . "/.enlightenment/configedit.rc";
					if(PREFFILE) {
						foreach(keys(%prefs)) {
							print PREFFILE "$_ $prefs{$_}\n";
						}
						close PREFFILE;
					} else {
						print "Couldn't open preferences file for saving.  sorry!\n";
					}
					destroy $prefs_box;


				});
		$box2->pack_start($button2,1,1,0);
		$button2->show;

	}
	if (!visible $prefs_box) {
		show $prefs_box;
	} else {
		destroy $prefs_box;
	}

}

sub page_switch {
	my($widget, $page, $page_num) = @_;
	my($oldpage, $pixwid);

	$oldpage = $widget->cur_page;


	return if ($page == $oldpage);

	$p1 = $page->tab_label;
	@c = $p1->children;
	$p2 = $c[0];

	if ($oldpage) {
	}

}

sub create_menu {
	my($selected,@menuitems) = @_;
	my($menu,$menuitem,$thisitem);
	
	$menu = new Gtk::Menu;
	$menuitem = undef;
	
	my $i=0;
	foreach $thisitem (@menuitems) {
		$menuitem = new Gtk::RadioMenuItem($thisitem,$menuitem);
		$menu->append($menuitem);
		if($thisitem eq $$selected) {
			$menuitem->set_show_toggle(1);
			$curitem = $i;
		} else {
			$menuitem->set_show_toggle(0);
		}
		$menuitem->signal_connect( "activate" => sub { $$selected = $thisitem; });
		$menuitem->show;
		$i++;
	}
	return $menu;
}

sub create_text_tabs {
	my($notebook, $start, $end) = @_;
	
	my($child, $label, $box, $hbox, $label_box, $menu_box, $button, $pixwid);
	my ($vbox);
	my $localmenu;
	my($i, $buffer);

	for ($i=$start; $i <= $end; $i++) {
		$buffer = "Page $i";
		
		$child = new Gtk::Frame $textclasses[$i-1]->{classname};
		$child->border_width(10);

		$vbox = new Gtk::HBox(0,0);
		$child->add($vbox);
		$vbox->border_width(0);
		$vbox->show;

		$hbox = new Gtk::VBox(0,0);
		$vbox->pack_start($hbox,1,1,0);
		$hbox->border_width(2);
		$hbox->show;

		$label = new Gtk::Label "Classname: ";
		$label->set_alignment(1.0,0.5);
		$hbox->pack_start($label,1,1,0);

		$label = new Gtk::Label "font name: ";
		$label->set_alignment(1.0,0.5);
		$hbox->pack_start($label,1,1,0);

		$hbox = new Gtk::VBox(0,0);
		$vbox->pack_start($hbox,1,1,0);
		$hbox->border_width(2);
		$hbox->show;

		$hbox->pack_start(create_and_tie_entrybox(\$textclasses[$i-1]->{classname}),1,1,0);

		$hbox->pack_start(create_and_tie_entrybox(\$textclasses[$i-1]->{fontname}),1,1,0);

		show_all $child;
		
		$label_box = new Gtk::HBox 0, 0;
		$label = new Gtk::Label $textclasses[$i-1]->{classname};
		$label_box->pack_start($label, 0, 1, 0);
		show_all $label_box;
		
		$menu_box = new Gtk::HBox 0, 0;
		$label = new Gtk::Label "where? $buffer";
		$menu_box->pack_start($label, 0, 1, 0);
		show_all $menu_box;
		
		$notebook->append_page_menu($child, $label_box, $menu_box);
	}
}

sub create_action_tab {
	my($notebook, $actionclass,$member) = @_;
	
	my($child, $label, $box, $hbox, $label_box, $menu_box, $button, $pixwid);
	my ($container,$bigbox);
	my $localmenu;
	my($i, $buffer);
	
	$bigbox = new Gtk::VBox(0,0);
	$bigbox->border_width(0);
	$bigbox->show;


	$container = new Gtk::HBox(0,0);
	$container->border_width(0);
	$bigbox->pack_start($container,1,1,0);
	$container->show;

	$hbox = new Gtk::VBox(0,0);
	$container->pack_start($hbox,1,1,0);
	$hbox->border_width(2);
	$hbox->show;

	$label = new Gtk::Label "Key to Use: ";
	$label->set_alignment(1.0,0.5);
	$hbox->pack_start($label,1,1,0);

	$label = new Gtk::Label "Button: ";
	$label->set_alignment(1.0,0.5);
	$hbox->pack_start($label,1,1,0);

	$label = new Gtk::Label "Modifier: ";
	$label->set_alignment(1.0,0.5);
	$hbox->pack_start($label,1,1,0);

	$label = new Gtk::Label "event to trigger: ";
	$label->set_alignment(1.0,0.5);
	$hbox->pack_start($label,1,1,0);

	$hbox = new Gtk::VBox(0,0);
	$container->pack_start($hbox,1,1,0);
	$hbox->border_width(2);
	$hbox->show;

	$hbox->pack_start(create_and_tie_entrybox(\$actionclass->{actionset}[$member]{key}),1,1,0);
# $hbox->pack_start(create_and_tie_menu(\$actionclass->{actionset}[$member]{key},@keys_available),1,1,0);
	$hbox->pack_start(create_and_tie_menu(\$actionclass->{actionset}[$member]{button},@button_types),1,1,0);
	$hbox->pack_start(create_and_tie_menu(\$actionclass->{actionset}[$member]{modifier},@modifier_types),1,1,0);
	$hbox->pack_start(create_and_tie_menu(\$actionclass->{actionset}[$member]{event},@event_types),1,1,0);

	{
		my $scw = new Gtk::ScrolledWindow(undef,undef);
		$scw->set_policy('automatic','automatic');
		$scw->show;
		$scw->border_width(2);
		$bigbox->pack_start($scw,1,1,0);
		
		my $vertbox = new Gtk::VBox(0,0);
		$vertbox->border_width(0);
		$vertbox->show;
		$scw->add($vertbox);
		my $i=0;
		foreach(@{$actionclass->{actionset}[$member]{actionsubset}}) {
			my $horizbox = new Gtk::HBox(0,0);
			$horizbox->border_width(2);
			$horizbox->show;
			$vertbox->pack_start($horizbox,1,1,0);
			$horizbox->pack_start(create_and_tie_menu(\$actionclass->{actionset}[$member]{actionsubset}[$i]{action},@action_types),1,1,0);
			$horizbox->pack_start(create_and_tie_entrybox(\$actionclass->{actionset}[$member]{actionsubset}[$i++]{params}),1,1,0);
		}
	}

	show_all $container;
	
	$label_box = new Gtk::HBox 0, 0;
	$label = new Gtk::Label "Segment $member";
	$label_box->pack_start($label, 0, 1, 0);
	show_all $label_box;
	
	$menu_box = new Gtk::HBox 0, 0;
	$label = new Gtk::Label "where is this?";
	$menu_box->pack_start($label, 0, 1, 0);
	show_all $menu_box;
	
	$notebook->append_page_menu($bigbox, $label_box, $menu_box);

}

sub spawn_button_edit_window {
	my $buttonobject = shift;
	my ($box1,$box2,$box3,$label);

	if(not defined $windows{$buttonobject->{name}}) {
		$windows{$buttonobject->{name}} = new Gtk::Window "toplevel";
# $windows{$buttonobject->{name}}->set_usize(550, 330);
		$windows{$buttonobject->{name}}->set_name("pref window");
		$windows{$buttonobject->{name}}->signal_connect("destroy", \&destroy_window, \$windows{$buttonobject->{name}});
		$windows{$buttonobject->{name}}->signal_connect("delete_event", \&destroy_window, \$windows{$actionclas->{name}});
		$windows{$buttonobject->{name}}->set_title("$buttonobject->{name}");
		$windows{$buttonobject->{name}}->border_width(0);
	}
	if (!$windows{$buttonobject->{name}}->visible) {
		$windows{$buttonobject->{name}}->show_all;
	} else {
		$windows{$buttonobject->{name}}->destroy;
	}

}

sub spawn_edit_window {

	my $actionclass = shift;
	my ($box1,$box2,$box3,$label);

	if(not defined $windows{$actionclass->{classname}}) {
		$windows{$actionclass->{classname}} = new Gtk::Window "toplevel";
# $windows{$actionclass->{classname}}->set_usize(550, 330);
		$windows{$actionclass->{classname}}->set_name("pref window");
		$windows{$actionclass->{classname}}->signal_connect("destroy", \&destroy_window, \$windows{$actionclass->{classname}});
		$windows{$actionclass->{classname}}->signal_connect("delete_event", \&destroy_window, \$windows{$actionclas->{classname}});
		$windows{$actionclass->{classname}}->set_title("$actionclass->{classname}");
		$windows{$actionclass->{classname}}->border_width(0);

		$box1 = new Gtk::VBox(0, 0);
		$windows{$actionclass->{classname}}->add($box1);

		$box2 = new Gtk::HBox(0,0);
		$box1->pack_start($box2,1,1,0);
		$box2->show;

		$box3 = new Gtk::VBox(0,0);
		$box2->pack_start($box3,1,1,0);
		$box3->show;

		$label = new Gtk::Label "Classname: ";
		$label->set_alignment(1.0,0.5);
		$box3->pack_start($label,1,1,0);

		$label = new Gtk::Label "Type of Action Class: ";
		$label->set_alignment(1.0,0.5);
		$box3->pack_start($label,1,1,0);

		$box3 = new Gtk::VBox(0,0);
		$box2->pack_start($box3,1,1,0);
		$box3->show;

		$box3->pack_start(create_and_tie_entrybox(\$actionclass->{classname}),1,1,0);
		$box3->pack_start(create_and_tie_menu(\$actionclass->{type},@actionclasstypes),1,1,0);

		my $notebook;
		$notebook = new Gtk::Notebook;
		$notebook->signal_connect("switch_page",\&page_switch);
		$notebook->set_tab_pos(-top);
		$box1->pack_start($notebook,1,1,0);
		$notebook->border_width(5);
		$notebook->set_scrollable(1);
# $notebook->set_usize(300,250);
		$notebook->realize;

		my $i=0;
		foreach(@{$actionclass->{actionset}}) {
			create_action_tab($notebook,$actionclass, $i++);
		}
		
		$separator = new Gtk::HSeparator;
		$box1->pack_start($separator,1,1,0);
		show $separator;

		$box2 = new Gtk::HBox(0,0);
		$box1->pack_start($box2,1,1,0);
		$box2->border_width(2);
		$box2->show;

		{
			my $button;
			$button = new Gtk::Button "Add New Action";
			$button->signal_connect( clicked => sub { $windows{$actionclass->{classname}}->destroy;} );

			$box2->pack_start($button,1,1,0);
			$button->show;
		}
		
		{
			my $button;
			$button = new Gtk::Button "Remove";
			$button->signal_connect( clicked => sub { $windows{$actionclass->{classname}}->destroy;} );

			$box2->pack_start($button,1,1,0);
			$button->show;
		}
		
		{
			my $button;
			$button = new Gtk::Button "close";
			$button->signal_connect( clicked => sub { $windows{$actionclass->{classname}}->destroy; } );

			$box2->pack_start($button,1,1,0);
			$button->can_default(1);
			$button->grab_default;
			$button->show;
		}
		
	}
	if (!$windows{$actionclass->{classname}}->visible) {
		$windows{$actionclass->{classname}}->show_all;
	} else {
		$windows{$actionclass->{classname}}->destroy;
	}

}

sub create_actionclass_control {

	my($actionclass,$scw,$box1,$box2,$separator);

	if(not defined $actionclass_control) {
		$actionclass_control = new Gtk::Window "toplevel";
		$actionclass_control->set_usize(270, 400);
		$actionclass_control->set_name("pref window");
		$actionclass_control->signal_connect("destroy", \&destroy_window, \$actionclass_control);
		$actionclass_control->signal_connect("delete_event", \&destroy_window, \$actionclass_control);
		$actionclass_control->set_title("Action Classes");
		$actionclass_control->border_width(0);

		$box1 = new Gtk::VBox(0, 0);
		$actionclass_control->add($box1);
		$box1->show;

		$scw = new Gtk::ScrolledWindow(undef, undef);
		$scw->set_policy('automatic', 'automatic');
		$scw->show;
		$scw->border_width(5);

		$box2 = new Gtk::VBox(undef, undef);
		$box1->pack_start($scw, 1, 1, 0);
		$box2->show;
		$box2->border_width(10);
		$scw->add($box2);

		foreach $actionclass (@actions) {
			my $button = new Gtk::Button $actionclass->{classname};
			$button->signal_connect("clicked" => sub { spawn_edit_window($actionclass);});
			$box2->pack_start($button,1,1,0);
			$button->show;
		}

		$separator = new Gtk::HSeparator;
		$box1->pack_start($separator,0,1,0);
		show $separator;

		$box2 = new Gtk::HBox(0,0);
		$box1->pack_start($box2,0,1,0);
		$box2->border_width(5);
		$box2->show;
		{
			my $button;
			$button = new Gtk::Button "Create New Action Class";
			$button->signal_connect( clicked => sub { print "No, I refuse to make a new action class\n";} );

			$box2->pack_start($button,1,1,0);
			$button->show;
		}
		
		{
			my $button;
			$button = new Gtk::Button "close";
			$button->signal_connect( clicked => sub { $actionclass_control->destroy; } );

			$box2->pack_start($button,1,1,0);
			$button->can_default(1);
			$button->grab_default;
			$button->show;
		}
		
	}
	if (!visible $actionclass_control) {
		$actionclass_control->show_all;
	} else {
		destroy $actionclass_control;
	}

}

sub create_desktop_control {

	my($desktop,$separator,$scw,$box1,$box2);

	if(not defined $desktop_control) {
		$desktop_control = new Gtk::Window "toplevel";
		$desktop_control->set_usize(300,250);
		$desktop_control->set_name("pref window");
		$desktop_control->signal_connect("destroy", \&destroy_window, \$desktop_control);
		$desktop_control->signal_connect("delete_event", \&destroy_window, \$desktop_control);
		$desktop_control->set_title("Desktops");
		$desktop_control->border_width(3);

		$box1 = new Gtk::VBox(0, 0);
		$desktop_control->add($box1);
		$box1->show;

		$scw = new Gtk::ScrolledWindow(undef, undef);
		$scw->set_policy('automatic', 'automatic');
		$scw->show;
		$scw->border_width(5);

		$box2 = new Gtk::VBox(undef, undef);
		$box1->pack_start($scw, 1, 1, 0);
		$box2->show;
		$box2->border_width(10);
		$scw->add($box2);

		foreach $desktop (@backgrounds) {
			my $button = new Gtk::Button $desktop->{bgname};
			$button->signal_connect("clicked" => sub { spawn_edit_window($buttonobject);});
			$box2->pack_start($button,1,1,0);
			$button->show;
		}

		$separator = new Gtk::HSeparator;
		$box1->pack_start($separator,0,1,0);

		$box2 = new Gtk::HBox(0,0);
		$box1->pack_start($box2,0,1,0);
		$box2->border_width(5);
		$box2->show;
		{
			my $button;
			$button = new Gtk::Button "Create New Action Class";
			$button->signal_connect( clicked => sub { print "No, I refuse to make a new desktop policy\n";} );

			$box2->pack_start($button,1,1,0);
			$button->show;
		}
		
		{
			my $button;
			$button = new Gtk::Button "close";
			$button->signal_connect( clicked => sub { $desktop_control->destroy; } );

			$box2->pack_start($button,1,1,0);
			$button->can_default(1);
			$button->grab_default;
			$button->show;
		}
	}
	if (!visible $desktop_control) {
		show $desktop_control;
	} else {
		destroy $desktop_control;
	}

}

sub create_buttons_control {
	my $buttonobject;
	my($desktop,$separator,$scw,$box1,$box2);
	if(not defined $buttons_control) {
		$buttons_control = new Gtk::Window "toplevel";
		$buttons_control->set_usize(300,250);
		$buttons_control->set_name("pref window");
		$buttons_control->signal_connect("destroy", \&destroy_window, \$buttons_control);
		$buttons_control->signal_connect("delete_event", \&destroy_window, \$buttons_control);
		$buttons_control->set_title("Buttons");
		$buttons_control->border_width(3);

		$box1 = new Gtk::VBox(0, 0);
		$buttons_control->add($box1);
		$box1->show;

		$scw = new Gtk::ScrolledWindow(undef, undef);
		$scw->set_policy('automatic', 'automatic');
		$scw->show;
		$scw->border_width(5);

		$box2 = new Gtk::VBox(undef, undef);
		$box1->pack_start($scw, 1, 1, 0);
		$box2->show;
		$box2->border_width(10);
		$scw->add($box2);

		foreach $buttonobject (@buttons) {
			my $button = new Gtk::Button $buttonobject->{name};
			$button->signal_connect("clicked" => sub { spawn_button_edit_window($buttonobject);});
			$box2->pack_start($button,1,1,0);
			$button->show;
		}

		$separator = new Gtk::HSeparator;
		$box1->pack_start($separator,0,1,0);

		$box2 = new Gtk::HBox(0,0);
		$box1->pack_start($box2,0,1,0);
		$box2->border_width(5);
		$box2->show;
		{
			my $button;
			$button = new Gtk::Button "Create New Button";
			$button->signal_connect( clicked => sub { print "No, I refuse to make a new button\n";} );

			$box2->pack_start($button,1,1,0);
			$button->show;
		}
		
		{
			my $button;
			$button = new Gtk::Button "close";
			$button->signal_connect( clicked => sub { $buttons_control->destroy; } );

			$box2->pack_start($button,1,1,0);
			$button->can_default(1);
			$button->grab_default;
			$button->show;
		}
	}
	if (!visible $buttons_control) {
		show $buttons_control;
	} else {
		destroy $buttons_control;
	}
}

sub create_textclass_box {

	my($box1,$box2,$frame,$button,$notebook,$entry,$label,$separator);

	if(not defined $textclass_box) {
		$textclass_box = new Gtk::Window "toplevel";
		$textclass_box->set_usize(300,250);
		$textclass_box->set_name("pref window");
		$textclass_box->signal_connect("destroy", \&destroy_window, \$textclass_box);
		$textclass_box->signal_connect("delete_event", \&destroy_window, \$textclass_box);
		$textclass_box->set_title("Text Classes");
		$textclass_box->border_width(3);

		$box1 = new Gtk::VBox(0,0);
		$textclass_box->add($box1);
		$box1->border_width(5);
		$box1->show;

		$label = new Gtk::Label "Text Classes";
		$box1->pack_start($label,1,1,0);
		show $label;

		$notebook = new Gtk::Notebook;
		$notebook->signal_connect("switch_page",\&page_switch);
		$notebook->set_tab_pos(-top);
		$box1->pack_start($notebook,1,1,0);
		$notebook->border_width(5);
		$notebook->set_scrollable(1);
		$notebook->set_usize(200,130);
		
		$notebook->realize;
		show $notebook;

		create_text_tabs($notebook,1,$#textclasses+1);

		$separator = new Gtk::HSeparator;
		$box1->pack_start($separator, 0,1,0);
		show $separator;

		$box2 = new Gtk::HBox(0,0);
		$box1->pack_start($box2,0,1,0);
		$box2->show;

		$button = new Gtk::Button "Create New TextClass";
		$button->signal_connect( clicked => sub { print "No I refuse to make a new TextClass\n";} );

		$box2->pack_start($button,1,1,0);
		$button->show;

		$button = new Gtk::Button "close";
		$button->signal_connect( clicked => sub { destroy $textclass_box} );

		$box2->pack_start($button,1,1,0);
		$button->can_default(1);
		$button->grab_default;
		$button->show;

	}
	if (!visible $textclass_box) {
		show $textclass_box;
	} else {
		destroy $textclass_box;
	}

}

sub create_dragbar_box {

	my($box1,$box2,$box3,$box4,$frame,$button,$entry,$label,$separator);

	if(not defined $dragbar_box) {
		$control{dragdir} = "top" if(!$control{dragdir});
		$control{dragbarwidth} = "16" if(!$control{dragbarwidth});
		$control{dragbarlength} = "0" if(!$control{dragbarlength});
		$control{dragbarordering} = "left->left" if(!$control{dragbarordering});
		$dragbar_box = new Gtk::Window "toplevel";
		$dragbar_box->set_name("pref window");
		$dragbar_box->signal_connect("destroy", \&destroy_window, \$dragbar_box);
		$dragbar_box->signal_connect("delete_event", \&destroy_window, \$dragbar_box);
		$dragbar_box->set_title("Desktop Dragbar");
		$dragbar_box->border_width(0);

		$box1 = new Gtk::VBox(0,0);
		$dragbar_box->add($box1);
		$box1->border_width(5);
		$box1->show;

		$label = new Gtk::Label "Desktop Dragbar";
		$box1->pack_start($label,1,1,0);
		show $label;

		$box2 = new Gtk::HBox(0,0);
		$box2->border_width(2);
		$box1->pack_start($box2,1,1,0);
		$box2->show;

		$frame = new Gtk::Frame "Orientation";
		$frame->border_width(2);
		$box2->pack_start($frame,1,1,0);
		show $frame;

		$box3 = new Gtk::VBox(0,0);
		$box3->border_width(0);
		$frame->add($box3);
		$box3->show;

		my $init=1;
		$first=1;
		for $pointertype ("left","right","top","bottom") {
			if($first) {
				$button = new Gtk::RadioButton $pointertype;
				$first=0;
			} else {
				$button = new Gtk::RadioButton $pointertype,$button;
			}
			my $scope = $pointertype;
			$button->signal_connect('clicked', sub { if(!$init) { $control{dragdir} = $scope; } });
			$button->set_state(1) if($control{dragdir} eq $pointertype);
			$box3->pack_start($button,1,1,0);
			$button->show;
		}

		$frame = new Gtk::Frame "Dimensions";
		$frame->border_width(2);
		$box2->pack_start($frame,1,1,0);
		show $frame;

		$box3 = new Gtk::VBox(0,0);
		$box3->border_width(0);
		$frame->add($box3);
		$box3->show;

		$box4 = new Gtk::HBox(0,0);
		$box4->border_width(2);
		$box3->pack_start($box4,1,1,0);
		$box4->show;

		$label = new Gtk::Label "width";
		$box4->pack_start($label,1,1,0);
		show $label;

		$entry = create_and_tie_entrybox(\$control{dragbarwidth});
		$entry->set_usize(30,0);
		$box4->pack_start($entry,1,1,0);

		$box4 = new Gtk::HBox(0,0);
		$box4->border_width(2);
		$box3->pack_start($box4,1,1,0);
		$box4->show;

		$label = new Gtk::Label "length";
		$box4->pack_start($label,1,1,0);
		show $label;

		$entry = create_and_tie_entrybox(\$control{dragbarlength});
		$entry->set_usize(30,0);
		$box4->pack_start($entry,1,1,0);

		$frame = new Gtk::Frame "Drag Ordering";
		$frame->border_width(2);
		$box2->pack_start($frame,1,1,0);
		show $frame;

		$box3 = new Gtk::VBox(0,0);
		$box3->border_width(0);
		$frame->add($box3);
		$box3->show;

		$label = new Gtk::Label "(if oriented left)";
		$box3->pack_start($label,1,1,0);
		show $label;


		$first=1;
		for $pointertype ("left->left","left->right","right->right") {
			if($first) {
				$button = new Gtk::RadioButton $pointertype;
				$first=0;
			} else {
				$button = new Gtk::RadioButton $pointertype,$button;
			}
			my $scope = $pointertype;
			$button->signal_connect('clicked', sub { if(!$init) { $control{dragbarordering} = $scope; } });
			$button->set_state(1) if($control{dragbarordering} eq $pointertype);
			$box3->pack_start($button,1,1,0);
			$button->show;
		}

		$separator = new Gtk::HSeparator;
		$box1->pack_start($separator,1,1,0);
		show $separator;

		$button = new Gtk::Button "close";
		$button->signal_connect( clicked => sub { destroy $dragbar_box} );

		$box1->pack_start($button,1,1,0);
		$button->can_default(1);
		$button->grab_default;
		$button->show;
		
		$init=0;

	}
	if (!visible $dragbar_box) {
		show $dragbar_box;
	} else {
		destroy $dragbar_box;
	}

}

sub create_general_controls_box {

	my($box1,$box2,$box3,$button,$separator,$label,$frame);

	if(not defined $controls_box) {
		$control{focus} = "pointer" if(!$control{focus});
		$control{move} = "box" if(!$control{move});
		$control{resize} = "box" if(!$control{resize});
		$control{slidemode} = "opaque" if(!$control{slidemode});
		$controls_box = new Gtk::Window "toplevel";
		$controls_box->set_name("control window");
		$controls_box->signal_connect("destroy", \&destroy_window, \$controls_box);
		$controls_box->signal_connect("delete_event", \&destroy_window, \$controls_box);
		$controls_box->set_title("General Controls");
		$controls_box->border_width(3);

		$box1 = new Gtk::VBox(0,0);
		$controls_box->add($box1);
		$box1->show;

		$label = new Gtk::Label "General Controls";
		$box1->pack_start($label,1,1,0);
		show $label;

		$box2 = new Gtk::HBox(0,0);
		$box2->border_width(2);
		$box1->pack_start($box2,1,1,0);
		$box2->show;

		$frame = new Gtk::Frame "Focus Types";
		$frame->border_width(2);
		$box2->pack_start($frame,1,1,0);
		show $frame;

		$box3 = new Gtk::VBox(0,0);
		$box3->border_width(0);
		$frame->add($box3);
		$box3->show;


		$init=1;
		$first=1;
		for $pointertype ("pointer","sloppy","click") {
			if($first) {
				$button = new Gtk::RadioButton $pointertype;
				$first=0;
			} else {
				$button = new Gtk::RadioButton $pointertype,$button;
			}
			my $scope = $pointertype;
			$button->signal_connect('clicked', sub { if(!$init) { $control{focus} = $scope; } });
			$button->set_state(1) if($control{focus} eq $pointertype);
			$box3->pack_start($button,1,1,0);
			$button->show;
		}

		$frame = new Gtk::Frame "Toggles";
		$frame->border_width(2);
		$box2->pack_start($frame,1,1,0);
		show $frame;

		$box3 = new Gtk::VBox(0,0);
		$box3->border_width(0);
		$frame->add($box3);
		$box3->show;



		$button = new Gtk::CheckButton "sound";
		$button->set_state(1) if($control{sound} eq "on");
		$button->signal_connect('clicked', 
				sub { 
					if(!$init) { 
						if($control{sound} eq "on") {
							$control{sound} = "off"; 
						} else {
							$control{sound} = "on";
						}
					} 
				});
		$box3->pack_start($button,1,1,0);
		$button->show;

		$button = new Gtk::CheckButton "Desktop Slides";
		$button->set_state(1) if($control{slidein} eq "on");
		$button->signal_connect('clicked', 
				sub { 
					if(!$init) { 
						if($control{slidein} eq "on") {
							$control{slidein} = "off"; 
						} else {
							$control{slidein} = "on";
						}
					} 
				});
		$box3->pack_start($button,1,1,0);
		$button->show;

		$button = new Gtk::CheckButton "New Window Slides";
		$button->set_state(1) if($control{mapslide} eq "on");
		$button->signal_connect('clicked', 
				sub { 
					if(!$init) { 
						if($control{mapslide} eq "on") {
							$control{mapslide} = "off"; 
						} else {
							$control{mapslide} = "on";
						}
					} 
				});
		$box3->pack_start($button,1,1,0);
		$button->show;

		$button = new Gtk::CheckButton "Slide on Cleanup";
		$button->set_state(1) if($control{slidecleanup} eq "on");
		$button->signal_connect('clicked', 
				sub { 
					if(!$init) { 
						if($control{slidecleanup} eq "on") {
							$control{slidecleanup} = "off"; 
						} else {
							$control{slidecleanup} = "on";
						}
					} 
				});
		$box3->pack_start($button,1,1,0);
		$button->show;

		$button = new Gtk::CheckButton "High Quality Backgrounds";
		$button->set_state(1) if($control{hiqualbg} eq "on");
		$button->signal_connect('clicked', 
				sub { 
					if(!$init) { 
						if($control{hiqualbg} eq "on") {
							$control{hiqualbg} = "off"; 
						} else {
							$control{hiqualbg} = "on";
						}
					} 
				});
		$box3->pack_start($button,1,1,0);
		$button->show;

		$button = new Gtk::CheckButton "Auto Save Runtime Settings";
		$button->set_state(1) if($control{autosave} eq "on");
		$button->signal_connect('clicked', 
				sub { 
					if(!$init) { 
						if($control{autosave} eq "on") {
							$control{autosave} = "off"; 
						} else {
							$control{autosave} = "on";
						}
					} 
				});
		$box3->pack_start($button,1,1,0);
		$button->show;

		$box2 = new Gtk::HBox(0,0);
		$box2->border_width(0);
		$box1->pack_start($box2,1,1,0);
		$box2->show;

		$frame = new Gtk::Frame "Move";
		$frame->border_width(2);
		$box2->pack_start($frame,1,1,0);
		show $frame;

		$box3 = new Gtk::VBox(0,0);
		$box3->border_width(0);
		$frame->add($box3);
		$box3->show;

		$first=1;
		for $pointertype ("box","opaque") {
			if($first) {
				$button = new Gtk::RadioButton $pointertype;
				$first=0;
			} else {
				$button = new Gtk::RadioButton $pointertype,$button;
			}
			my $scope = $pointertype;
			$button->signal_connect('clicked', sub { if(!$init) { $control{move} = $scope; } });
			$button->set_state(1) if($control{move} eq $pointertype);
			$box3->pack_start($button,1,1,0);
			$button->show;
		}

		$frame = new Gtk::Frame "Resize";
		$frame->border_width(2);
		$box2->pack_start($frame,1,1,0);
		show $frame;

		$box3 = new Gtk::VBox(0,0);
		$box3->border_width(0);
		$frame->add($box3);
		$box3->show;

		$first=1;
		for $pointertype ("box","opaque") {
			if($first) {
				$button = new Gtk::RadioButton $pointertype;
				$first=0;
			} else {
				$button = new Gtk::RadioButton $pointertype,$button;
			}
			my $scope = $pointertype;
			$button->signal_connect('clicked', sub { if(!$init) { $control{resize} = $scope; } });
			$button->set_state(1) if($control{resize} eq $pointertype);
			$box3->pack_start($button,1,1,0);
			$button->show;
		}

		$frame = new Gtk::Frame "Slidemode";
		$frame->border_width(2);
		$box2->pack_start($frame,1,1,0);
		show $frame;

		$box3 = new Gtk::VBox(0,0);
		$box3->border_width(0);
		$frame->add($box3);
		$box3->show;

		$first=1;
		for $pointertype ("box","opaque") {
			if($first) {
				$button = new Gtk::RadioButton $pointertype;
				$first=0;
			} else {
				$button = new Gtk::RadioButton $pointertype,$button;
			}
			my $scope = $pointertype;
			$button->signal_connect('clicked', sub { if(!$init) { $control{slidemode} = $scope; } });
			$button->set_state(1) if($control{slidemode} eq $pointertype);
			$box3->pack_start($button,1,1,0);
			$button->show;
		}

		$seperator = new Gtk::HSeparator;
		$box1->pack_start($seperator,0,1,0);
		$seperator->show;

		$box2 = new Gtk::VBox(0,10);
		$box2->border_width(5);
		$box1->pack_start($box2,0,1,0);
		$box2->show;


		$button = new Gtk::Button "close";
		$button->signal_connect( clicked => sub { destroy $controls_box} );
		$box2->pack_start($button, 1, 1, 0);
		$button->can_default(1);
		$button->grab_default;
		$button->show;
		$init=0;


	}
	if (!visible $controls_box) {
		show $controls_box;
	} else {
		destroy $controls_box;
	}


}

sub create_help_box {
	my($box1,$box2,$button,$separator,$table,$hscrollbar,$vscrollbar,$text);
	
	if (not defined $help_window) {
		$help_window = new Gtk::Window "toplevel";
		$help_window->set_name("text window");
		$help_window->signal_connect("destroy", \&destroy_window, \$help_window);
		$help_window->signal_connect("delete_event", \&destroy_window, \$help_window);
		$help_window->set_title("Help!");
		$help_window->border_width(0);
		
		$box1 = new Gtk::VBox(0,0);
		$help_window->add($box1);
		$box1->show;
		
		$box2 = new Gtk::VBox(0,0);
		$box2->border_width(10);
		$box1->pack_start($box2,1,1,0);
		$box2->show;
		
		$table = new Gtk::Table(2,2,0);
		$table->set_row_spacing(0,2);
		$table->set_col_spacing(0,2);
		$box2->pack_start($table,1,1,0);
		$table->show;
		
		$text = new Gtk::Text(undef,undef);
		$table->attach_defaults($text, 0,1,0,1);
		show $text;
		
		$text->freeze;
		$text->realize;
		
		$text->insert(undef,$text->style->black,undef, "This is supposed to launch dox\n");
		
		$text->thaw;

		$separator = new Gtk::HSeparator();
		$box1->pack_start($separator,0,1,0);
		$separator->show;
		
		$box2 = new Gtk::VBox(0,10);
		$box2->border_width(10);
		$box1->pack_start($box2, 0, 1, 0);
		$box2->show;
		
		$button = new Gtk::Button "close";
		$button->signal_connect("clicked", sub {destroy $help_window});
		$box2->pack_start($button, 1, 1, 0);
		$button->can_default(1);
		$button->grab_default;
		$button->show;
		
	}
	if (!visible $help_window) {
		show $help_window;
	} else {
		destroy $help_window;
	}
}

sub create_sound_window {
	my ($box1,$box2,$box3,$button,$separator,$label,$scw);
	if(not defined $sound_window) {
		$sound_window = new Gtk::Window "toplevel";
		$sound_window->set_usize(570, 260);
		$sound_window->set_name("sound window");
		$sound_window->signal_connect("destroy", \&destroy_window, \$sound_window);
		$sound_window->signal_connect("delete_event", \&destroy_window, \$sound_window);
		$sound_window->set_title("Sound Classes");
		$sound_window->border_width(0);

		$box1 = new Gtk::VBox(0, 0);
		$sound_window->add($box1);
		$box1->show;

		$label = new Gtk::Label "Sound Classes";
		$box1->pack_start($label,0,0,0);
		$label->show;

		$scw = new Gtk::ScrolledWindow(undef, undef);
		$scw->set_policy('automatic', 'automatic');
		$scw->show;
		$scw->border_width(10);
		$box1->pack_start($scw, 1, 1, 0);
		
		$box2 = new Gtk::HBox(undef, undef);
		$box2->show;
		$box2->border_width(5);
		$scw->add($box2);
		
		$box3 = new Gtk::VBox(undef, undef);
		$box3->show;
		$box3->border_width(5);
		$box2->pack_start($box3,1,1,0);
		
		$label = new Gtk::Label "SoundClass";
		$box3->pack_start($label,1,1,0);
		$label->show;

		foreach(keys(%sounds)) {
			$label = new Gtk::Label "$_";
			$box3->pack_start($label,1,1,0);
			# $label->set_alignment(1.0,0.5);
			$label->show;
		}

		$box3 = new Gtk::VBox(undef, undef);
		$box3->show;
		$box3->border_width(5);
		$box2->pack_start($box3,1,1,0);
		
		$label = new Gtk::Label "File To Play";
		$box3->pack_start($label,1,1,0);
		$label->show;

		foreach(keys(%sounds)) {
			$box3->pack_start(create_and_tie_entrybox(\$sounds{$_}),1,1,0);
		}

		$box3 = new Gtk::VBox(undef, undef);
		$box3->show;
		$box3->border_width(5);
		$box2->pack_start($box3,1,1,0);
		
		$label = new Gtk::Label "Browse";
		$box3->pack_start($label,1,1,0);
		$label->show;
		
		foreach(keys(%sounds)) {
			$button = new Gtk::Button "Browse";
			$button->signal_connect( "clicked" => sub { $entryref = \$sounds{$_}; &create_grab_file_selection; });
			$box3->pack_start($button,1,1,0);
			$button->show;
		}

		$box3 = new Gtk::VBox(undef, undef);
		$box3->show;
		$box3->border_width(5);
		$box2->pack_start($box3,1,1,0);
		
		$label = new Gtk::Label "Sample";
		$box3->pack_start($label,1,1,0);
		$label->show;

		foreach(keys(%sounds)) {
			$button = new Gtk::Button "Sample";
			$box3->pack_start($button,1,1,0);
			$button->show;
		}

		$box3 = new Gtk::VBox(undef, undef);
		$box3->show;
		$box3->border_width(5);
		$box2->pack_start($box3,1,1,0);
		
		$label = new Gtk::Label "Remove";
		$box3->pack_start($label,1,1,0);
		$label->show;

		foreach(keys(%sounds)) {
			$button = new Gtk::Button "Remove";
			$box3->pack_start($button,1,1,0);
			$button->show;
		}

		$separator = new Gtk::HSeparator();
		$box1->pack_start($separator,0,1,0);
		$separator->show;
		
		$box2 = new Gtk::HBox(0,10);
		$box2->border_width(10);
		$box1->pack_start($box2, 0, 1, 0);
		$box2->show;
		
		$button = new Gtk::Button "Add a New Sound Class";
		$button->signal_connect("clicked", sub {print "No, I refuse to make a new Sound Class\n"});
		$box2->pack_start($button, 1, 1, 0);
		$button->show;

		$button = new Gtk::Button "close";
		$button->signal_connect("clicked", sub {destroy $sound_window});
		$box2->pack_start($button, 1, 1, 0);
		$button->can_default(1);
		$button->grab_default;
		$button->show;

	}
	if (!visible $sound_window) {
		show $sound_window;
	} else {
		destroy $sound_window;
	}
}

sub create_about_box {
	my($box1,$box2,$button,$separator,$text);
	
	if (not defined $text_window) {
		$text_window = new Gtk::Window "toplevel";
		$text_window->set_name("text window");
		$text_window->signal_connect("destroy", \&destroy_window, \$text_window);
		$text_window->signal_connect("delete_event", \&destroy_window, \$text_window);
		$text_window->set_title("About The Configurator...");
		$text_window->border_width(0);
		
		$box1 = new Gtk::VBox(0,0);
		$text_window->add($box1);
		$box1->show;
		
		$box2 = new Gtk::VBox(0,0);
		$box2->border_width(5);
		$box1->pack_start($box2,1,1,0);
		$box2->show;
		
		$text = new Gtk::Label  "Enlightenment Configurator Version $version\n\tCopyright 1998 Geoff Harrison\n(Mandrake - http://mandrake.net)\n\nThis app is a little something I had been\nplanning on brewing up for a while now.\nI have been playing around with GTK\nunder perl and decided to do something\nuseful with it.  Requires Gtk-0.2.2 of\nGtk-perl or higher to use.  Enjoy!\n\nSpecial Thanks to:\nBass & Co's Pale Ale (imported by Guinness)\nhttp://www.bassale.com";
		$box2->pack_start($text,1,1,0);
		$text->show;
		
		$separator = new Gtk::HSeparator();
		$box1->pack_start($separator,0,1,0);
		$separator->show;
		
		$box2 = new Gtk::VBox(0,10);
		$box2->border_width(10);
		$box1->pack_start($box2, 0, 1, 0);
		$box2->show;
		
		$button = new Gtk::Button "close";
		$button->signal_connect("clicked", sub {destroy $text_window});
		$box2->pack_start($button, 1, 1, 0);
		$button->can_default(1);
		$button->grab_default;
		$button->show;
		
	}
	if (!visible $text_window) {
		show $text_window;
	} else {
		destroy $text_window;
	}
}

my($color_idle)=0;
my($color_count)=1;

sub color_idle_func {
	my($preview) = @_;
	my($i,$j,$k,$buf);
	for($i=0;$i<32;$i++) {
		for($j=0,$k=0;$j<32;$j++) {
			vec($buf, $k+0, 8) = $i+$color_count;
			vec($buf, $k+1, 8) = 0;
			vec($buf, $k+2, 8) = $j+$color_count;
			$k += 3;
		}
		$preview->draw_row($buf,0,$i,32);
	}
	
	$color_count +=1;
	
	$preview->draw(undef);
	
	return 1;
}

sub color_preview_destroy {
	my($widget,$windowref) = @_;
	if ($color_idle) {
		Gtk->idle_remove($color_idle);
	}
	$color_idle=0;
	
	destroy_window($window, $windowref);
}

sub create_color_preview {
	my($preview,$buf,$i,$j,$k);
	
	if (not defined $cp_window) {
		Gtk::Widget->push_visual(Gtk::Preview->get_visual);
		Gtk::Widget->push_colormap(Gtk::Preview->get_cmap);
		
		$cp_window = new Gtk::Window "toplevel";
		$cp_window->signal_connect("destroy", \&color_preview_destroy, \$cp_window);
		$cp_window->signal_connect("delete_event", \&color_preview_destroy, \$cp_window);
		$cp_window->set_title("test");
		$cp_window->border_width(10);
		
		$preview = new Gtk::Preview("color");
		$preview->size(32,32);
		$cp_window->add($preview);
		$preview->show;
		
		for($i=0;$i<32;$i++)
		{
			for($j=0,$k=0;$j<32;$j++)
			{
				vec($buf,$k+0,8) = $i;
				vec($buf,$k+1,8) = 0;
				vec($buf,$k+2,8) = $j;
				$k+=3;
			}
			$preview->draw_row($buf, 0, $i, 32);
		}
		
		$color_idle = Gtk->idle_add(\&color_idle_func, $preview);
		
		Gtk::Widget->pop_colormap;
		Gtk::Widget->pop_visual;
		
	}
	if (!visible $cp_window) {
		show $cp_window;
	} else {
		destroy $cp_window;
	}
}

my($curve_count)=0;

sub create_gamma_curve {
	my($curve,@vec,$i,$max);

	if (not defined $curve_window) {
		$curve_window = new Gtk::Window "toplevel";
		$curve_window->set_title("test");
		$curve_window->border_width(10);
		
		$gamma_curve = new Gtk::GammaCurve;
		$curve_window->add($gamma_curve);
		$gamma_curve->show;
	}

	$max = 127 + ($curve_count % 2) * 128;
	$gamma_curve->curve->set_range(0, $max, 0, $max);
	
	for($i=0;$i<$max;$i++) {
		$vec[$i] = (127 / sqrt($max))*sqrt($i);
	}
	$gamma_curve->curve->set_vector(@vec);
	
	if (!visible $curve_window) {
		show $curve_window;
	} elsif ($curve_count % 4 == 3) {
		destroy $curve_window;
		$curve_window = undef;
	}
	
	$curve_count++;
}

sub do_exit {
	Gtk->exit(0);
}

sub create_main_window {
	my(@buttons,$window,$box1,$scw, $box2,$button,$separator);

	@buttons = (
			"General Controls",\&create_general_controls_box,
			"Action Classes",\&create_actionclass_control,
			"Text Classes",\&create_textclass_box,
			"Buttons",\&create_buttons_control,
			"Sounds",\&create_sound_window,
			"Desktops",\&create_desktop_control,
			"Desktop Dragbar",\&create_dragbar_box,
# "Image Classes",undef,
# "Color Modifiers",undef,
# "Border Declarations",undef,
# "Border Matches",undef,
			"Configurator Preferences", \&create_preferences_box,
			"Help",\&create_help_box,
			"About The Configurator", \&create_about_box,
	);

	$window = new Gtk::Window('toplevel');
	$window->set_name("Enlightenment $enlversion Configurator");
	$window->set_title("Enlightenment $enlversion Configurator");
	$window->set_uposition(20, 20);
	$window->set_usize(170, 360);
	
	$window->signal_connect("destroy" => \&do_exit, \$window);
	$window->signal_connect("delete_event" => \&do_exit, \$window);

	$box1 = new Gtk::VBox(0, 0);
	$window->add($box1);
	$box1->show;

	$scw = new Gtk::ScrolledWindow(undef, undef);
	$scw->set_policy('automatic', 'automatic');
	$scw->show;
	$scw->border_width(5);
	
	$box2 = new Gtk::VBox(undef, undef);
	$box1->pack_start($scw, 1, 1, 0);
	$box2->show;
	$box2->border_width(5);
	$scw->add($box2);
	
	for($i=0;$i<@buttons;$i+=2) {
		$button = new Gtk::Button($buttons[$i]);
		if (defined $buttons[$i+1]) {
			$button->signal_connect(clicked => $buttons[$i+1]);
		} else {
			$button->set_sensitive(0);
		}
		$box2->pack_start($button, 1, 1, 0);
		show $button;
	}


	$separator = new Gtk::HSeparator;
	$box1->pack_start($separator, 0, 1, 0);
	$separator->show;
	
	$box2 = new Gtk::VBox(0, 0);
	$box2->border_width(0);
	$box1->pack_start($box2, 0, 1, 0);
	$box2->show();

	$button2 = new Gtk::Button "Purge Configs From Memory";
	signal_connect $button2 "clicked", \&purgeconfig;
	$box2->pack_start($button2, 1, 1, 0);
	$button2->can_default(1);
	$button2->grab_default();
	$button2->show;
	
	$button2 = new Gtk::Button "Load Config File";
	signal_connect $button2 "clicked", \&create_load_file_selection;
	$box2->pack_start($button2, 1, 1, 0);
	$button2->can_default(1);
	$button2->grab_default();
	$button2->show;
	
	$button3 = new Gtk::Button "Save Config File";
	signal_connect $button3 "clicked", \&create_save_file_selection;
	$box2->pack_start($button3, 1, 1, 0);
	$button3->can_default(1);
	$button3->grab_default();
	$button3->show;
	
	$button = new Gtk::Button "Quit the Configurator";
	signal_connect $button "clicked", \&do_exit;
	$box2->pack_start($button, 1, 1, 0);
	$button->can_default(1);
	$button->grab_default();
	$button->show;
	
	$window->show;
	
}

sub load_rc_file {

	$prefs{gtkrc} = "/usr/share/enlightenment/config/configedit.gtkrc";
	if(-e $ENV{HOME} . "/.enlightenment/configedit.rc") {
		open FILE, $ENV{HOME} . "/.enlightenment/configedit.rc";
	} else {
		open FILE, "/usr/share/enlightenment/config/configedit.rc";
	}
	while(<FILE>) {
		@currentline = split(/\s+/);
		$prefs{$currentline[0]} = $currentline[1];
	}
	close FILE;


}


load_rc_file;

if(-e $prefs{gtkrc}) {
	parse Gtk::Rc $prefs{gtkrc};
}
if($prefs{cfgtoload}) {
	loadconfigfile($prefs{cfgtoload});
}

create_main_window;
if(!$prefs{no_about_box}) {
	create_about_box;
}

main Gtk;
