#!/bin/sh
#
# Demonstration on how to use the GTK-server with PDKSH by STDIN.
# Tested with the AT&T KSH (1993-12-28) on Slackware Linux 9.0.
#
# September 27, 2003 by Peter van Eerten.
# Revised for GTK-server 1.2 October 7, 2004
# Revised for GTK-server 1.3 December 4, 2004
#------------------------------------------------
#
# Communication function; $1 contains the string to be send
function gtk
{
print $1
read -p RESULT
}

# Setup environment
export LC_ALL=nl_NL
export LD_LIBRARY_PATH=/usr/X11R6/lib

# Start GTK-server in STDIN mode
gtk-server stdin

# Define GUI
gtk "gtk_init NULL NULL"
gtk "gtk_window_new 0"
WINDOW=$RESULT
gtk "gtk_window_set_title $WINDOW \"This is a title\""
GTK "gtk_window_set_default_size " WINDOW " 100 100"
gtk "gtk_window_set_position $WINDOW 1"
TABLE=gtk "gtk_table_new 30 30 1"
gtk "gtk_container_add $WINDOW $TABLE"
BUTTON1=gtk "gtk_button_new_with_label \"Click here!\""
gtk "gtk_table_attach_defaults $TABLE $BUTTON1 17 28 20 25"
BUTTON2=gtk"gtk_button_new_with_label \"Print text\""
gtk "gtk_table_attach_defaults $TABLE $BUTTON2 2 13 20 25"
ENTRY=gtk "gtk_entry_new"
gtk "gtk_table_attach_defaults $TABLE $ENTRY 1 6 3 4"
gtk "gtk_widget_show_all $WINDOW"

# Initialize variables
EVENT=0

# Mainloop
while [[ $EVENT != $BUTTON ]]
do
	gtk "gtk_server_callback WAIT"
	EVENT=$RESULT

	if [[ $EVENT = $ENTRY ]]
	then
		gtk "gtk_entry_get_text $ENTRY"
		print $RESULT
	fi
done

# Exit GTK
gtk "gtk_exit 0"
