#!/usr/local/bin/moat

###################################################################
#
# display a set of buttons, one for each font
# When a button is selected, a message is shown
# in that font.
# Based on Motif programmer's Guide example
#
###################################################################


##################################################################
#
# put up a dialog showing the font
#
proc showFont font {
    xmMessageDialog .msg managed \
	-labelFontList $font \
	-messageString "This is font $font.\n\
The quick brown fox jumps over the lazy dog" \
	-messageAlignment alignment_center
    .msg okCallback {.msg destroyWidget}
    #.msg.Cancel unmanageChild
    #.msg.Help unmanageChild
}


###################################################################
#
# X world starts here
#
xtAppInitialize \
	-fallbackResources {
		{*allowShellResize: true}
		{*XmMainWindow.height: 300}
		{*XmMainWindow.width:  400}
	} \
	-options { {-fontPath fontPath sepArg} }

. getAppResources  { {fontPath FontPath "/usr/lib/X11/fonts/misc" fontDir} }

xmMainWindow .main managed

#########################################################
#
# menu system along top
#

# menu bar
xmMenuBar .main.menuBar managed

# file pulldown
xmPulldownMenu .main.filePane
xmCascadeButton .main.menuBar.file managed \
        -labelString File \
        -subMenuId .main.filePane

xmPushButton .main.filePane.exit managed \
        -labelString Exit
.main.filePane.exit activateCallback {exit 0}

########################################################
#
# geometry inside main window
#
xmFrame .main.frame managed \
	-marginWidth 2 \
	-marginHeight 2 \
	-shadowThickness 1 \
	-shadowType shadow_out

xmScrolledWindow .main.frame.sw managed \
	-scrollBarDisplayPolicy as_needed \
	-scrollingPolicy automatic

xmRowColumn .main.frame.sw.rowcol managed \
	-packing pack_column \
	-numColumns 5

.main setValues -menuBar .main.menuBar \
                -workWindow .main.frame parent

#######################################################
#
# create a push button for each font
#

#set fontDir "/usr/lib/X11/fonts/misc"
set fonts [eval " exec ls $fontDir"]
foreach file $fonts {
    # lose from "." onwards
    regsub {\..*} $file "" fileStem
    xmPushButton .main.frame.sw.rowcol.$fileStem managed
    .main.frame.sw.rowcol.$fileStem activateCallback "showFont $fileStem"
}

. realizeWidget

. mainLoop

