#!/bin/sh

GTKDIALOG=gtkdialog

export TMPDIR=/tmp/gtkdialog/examples/"$(basename $0)"
mkdir -p "$TMPDIR"

funcbtnType0Create() {
	echo '<button image-position="'$1'" use-stock="true" label="gtk-'$2'">
			<action>""</action>
		</button>'
}

funcbtnType1Create() {
	echo '<button image-position="'$1'">
			<label>'$1'</label>
			<input file stock="gtk-'$2'"></input>
			<action>""</action>
		</button>'
}

funcbtnType2Create() {
	echo '<button image-position="'$1'">
			<label>'$1'</label>
			<variable>btn'$2$1'</variable>
			<input file>'"$TMPDIR"'/image.svg</input>
			<action>echo Refreshing btn'$2$1'</action>
			<action>refresh:btn'$2$1'</action>
		</button>'
}

funcbtnType3Create() {
	echo '<button image-position="'$1'">
			<label>'$1'</label>
			<variable>btn'$2$1'</variable>
			<input file>'"$TMPDIR"'/image.svg</input>
			<width>64</width>
			<action>echo Refreshing btn'$2$1'</action>
			<action>refresh:btn'$2$1'</action>
		</button>'
}

funcimgCreate() {
	echo '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
			<rect x="0" y="0" height="32" width="32" fill="#000000"/>
			<rect x="2" y="2" height="28" width="28" fill="#ffffff"/>
			<rect x="16" y="16" height="12" width="12" fill="#d0d0d0"/>
			<rect x="4" y="16" height="12" width="12" fill="#a0a0a0"/>
			<rect x="4" y="4" height="12" width="12" fill="#707070"/>
			<rect x="16" y="4" height="12" width="12" fill="#404040"/>
			<rect x="18" y="18" height="4" width="4" fill="#ffffff"/>
			<rect x="22" y="18" height="4" width="4" fill="#a0a0a0"/>
			<rect x="22" y="22" height="4" width="4" fill="#707070"/>
			<rect x="18" y="22" height="4" width="4" fill="#404040"/>
		</svg>' > "$TMPDIR"/image.svg
}; export -f funcimgCreate

if [ ! -f "$TMPDIR"/image.svg ]; then funcimgCreate; fi

export MAIN_DIALOG='
<window title="Button Image Position" width-request="500" resizable="false">
	<vbox>
		<frame Stock images (and labels) using GTK properties>
			<hbox homogeneous="true">
				'"$(funcbtnType0Create 0 about)"'
				'"$(funcbtnType0Create 1 add)"'
				'"$(funcbtnType0Create 2 apply)"'
				'"$(funcbtnType0Create 3 bold)"'
			</hbox>
		</frame>
		<frame Stock images using Gtkdialog directives>
			<hbox homogeneous="true">
				'"$(funcbtnType1Create Left about)"'
				'"$(funcbtnType1Create Right add)"'
				'"$(funcbtnType1Create Top apply)"'
				'"$(funcbtnType1Create Bottom bold)"'
			</hbox>
		</frame>
		<frame Images from files using Gtkdialog directives>
			<hbox homogeneous="true">
				'"$(funcbtnType2Create Left Woden)"'
				'"$(funcbtnType2Create Right Woden)"'
				'"$(funcbtnType2Create Top Woden)"'
				'"$(funcbtnType2Create Bottom Woden)"'
			</hbox>
		</frame>
		<frame Scaled images from files using Gtkdialog directives>
			<hbox homogeneous="true">
				'"$(funcbtnType3Create Left Frige)"'
				'"$(funcbtnType3Create Right Frige)"'
				'"$(funcbtnType3Create Top Frige)"'
				'"$(funcbtnType3Create Bottom Frige)"'
			</hbox>
		</frame>
		<hbox homogeneous="true">
			<button>
				<label>Remove/Create Image</label>
				<variable>btnimgControl</variable>
				<input file>'"$TMPDIR"'/image.svg</input>
				<width>16</width>
				<action>if [ ! -f '"$TMPDIR"'/image.svg ]; then funcimgCreate; else rm '"$TMPDIR"'/image.svg; fi</action>
				<action>refresh:btnimgControl</action>
			</button>
			<button ok></button>
		</hbox>
	</vbox>
	<action signal="hide">exit:Exit</action> 
</window>
'

$GTKDIALOG --program=MAIN_DIALOG 
