G4C

;
; QuickCode V1.11
;
; A Mathscript Icon Bar, allowing rapid access to your 10 most
; used formula elements.
;
; This is the GUI4CLI layer for QuickCode.rexx.  Make sure
; QuickCode.rexx and QC_Prefs.gc are in the Mathscript:Rexx/QC dir!
;
; Chris Coulson
;
; History:
;
; 28.12.96
; 31.12.96 - First batch of icons done
; 05.01.97 - Changed env-var format
; 08.01.97 - Prefs editor now sets icon bar
; 09.01.97 - Version 1.0
;            Changed env-var format again, it's half the size!
; 12.01.97 - Now opens on whatever pubscreen the Gui was last 
;            jumped onto.
; 13.01.97 - Version 1.1
;            Version number bumped to correspond with QuickCode.rexx
; 14.01.97 - Project...Quit now does what it says :-)
; 17.01.97 - Wierd bug reported by Simon Ihmig.  I've only managed to replicate
;            it once, and I can't figure out why it happened...  So I've added
;            what seems to be the only possible fix, given the nature of the bug.
;            Clear button now works again...
; 18.01.97 - Version 1.2
;            Added the MxN matrix
; 21.01.97 - Version 1.3
;            Added new codes from Mathscript 3.1
; 25.01.97 - Version 1.4
;            I think I've fixed the other wierd bug Simon reported...
;            Following advice from Dimitris, I've renamed most of the variables, so
;            that they're all hopefully unique to QuickCode, and I've also removed 
;            the Quit command on closing the GUI.  These changes should allow
;            Quickcode to run happily on a system that's running other Guis.
; 28.01.97 - Version 1.5
;            Now I REALLY think I've fixed that bug of Simon's...
; 09.02.97 - Version 1.6
;            Removed all the absolute file paths, allowing the QC directory to be
;            placed anywhere.
;            Will now remove Gui4CLI on exit, if the user permits it.
;            Cleared up some little bugs in the screen jumping code.
; 24.05.97 - Version 1.7
;            Clear button can now be given an "Are you SURE?" requester, or can
;            be removed completely.
; 31.05.97 - Version 1.8
;            Checks to see if there are any other Guis loaded before closing G4C.
;            Added snapshot option to save bar position, rather than have it always
;            start in the top left corner of the screen.
; 05.06.97 - Version 1.9
;            Fixed minor bug in snapshot routine - closing the prefs window used to
;            redraw the bar at the last snapshotted position, rather than whatever
;            position the bar was at when the prefs window was opened.
; 23.08.97 - Version 1.10
;            Will now always attempt to close Gui4CLI when quit.
;            Revised interface with prefs module to allow button bar to act as part of
;            the prefs interface.
; 13.10.97 - Version 1.11
;            Improved prefs interface.
; 14.12.97 - Variable passing now works with latest version of Gui4CLI.

WinBig 0 0 200 17 "QuickCode 1.11"
WinType 11010000

NoFontSense

xOnLoad
	GuiLoad :qc_prefs.gc
	GuiLoad :qc_getmxn.gc
	VarPath "qc_prefs.gc"
	
	GoSub quickcode.gc getprefs			
	Extract QuickCode.gc GuiPath qc_path
	qc_rexxprog = $qc_path
	AppVar qc_rexxprog "/QuickCode.rexx"
	GuiOpen QuickCode.gc
	
	GoSub quickcode.gc changebuttons
	Run 'rx $qc_rexxprog'
	Wait PORT quickcode 100

; Global inits for QC_Prefs
	
	qcp_Bank = 1
	qcp_Button = 1
	qcp_Cmd = "lank"
	qcp_open = 0
	
	
xOnClose
	SendRexx quickcode "EXIT"
	GoSub quickcode.gc saveprefs
	GuiQuit QuickCode.gc
	GuiQuit QC_Prefs.gc
	GuiQuit QC_GetMxN.gc
	IF $$g4c.loaded = 3
		Quit
	ENDIF


xOnJump qc_screen
	SetScreen qc_prefs.gc $qc_screen
	SetScreen qc_getmxn.gc $qc_screen
	GoSub quickcode.gc saveprefs
	

; Menu definitions

xMenu Project About "" ""
	GoSub quickcode.gc About
xMenu Project Barlabel "" ""
xMenu Project Quit "" "Q"
	GuiClose quickcode.gc

xMenu Settings "Open/Close Prefs" "" "C"
	GoSub quickcode.gc OpenClosePrefs
xMenu Settings Snapshot "" "S"
	GoSub quickcode.gc SnapShot
	

xRoutine About
	EzReq "QuickCode 1.11 (14th December 1997)\n\nby Chris Coulson\n(chris@tornado.pair.com)\n\nUsing Gui4CLI v3.2" "OK" Dummy

xRoutine OpenClosePrefs
; Alter the temporary bar location variables to reflect the current position, so that when
; returning from the prefs window, the bar is redrawn at the same location it's in
; right now.  But since we're only altering the temp vars, this position won't necessarily
; be the same as the one saved in the env: file.

	IF $qcp_open = 0
		qc_tempwinx = $$win.l
		qc_tempwiny = $$win.t
		qcp_open = 1
		GuiOpen qc_prefs.gc
	ELSE
		qcp_open = 0
		GuiClose qc_prefs.gc
		GoSub quickcode.gc SavePrefs
		SendRexx quickcode "PREFS"
		GoSub quickcode.gc RetFromPrefs
	ENDIF

xRoutine SnapShot

; Store the current bar location, and make copies to be used when returning from
; the prefs window.

	qc_winx = $$win.l
	qc_winy = $$win.t
	qc_tempwinx = $qc_winx
	qc_tempwiny = $qc_winy
	
	
; QuickCode buttons
;
; Note: xIcons MUST be first setup with an actual filename rather than a variable
; containing the filename - I suspect Gui4CLI tries to setup the icons before it
; sets up the variables.  If the xIcon gadget is not initialised correctly, any
; attempt to ChangeIcon it at a later stage will fail.
	 
xIcon 0 0 ":icons/blank"
	GadID 1
	IF $qcp_open = 1
		qcp_NewButt = 1
		GoSub qc_prefs.gc ChangeLight
	ELSE
		IF "$qcicon0" = "14/13"
			GuiOpen qc_getmxn.gc
		ELSE
			SendRexx quickcode "B0"
		ENDIF
	ENDIF
xIcon 16 0 ":icons/blank"
	GadID 2
	IF $qcp_open = 1
		qcp_NewButt = 2
		GoSub qc_prefs.gc ChangeLight
	ELSE
		IF "$qcicon1" = "14/13"
			GuiOpen qc_getmxn.gc
		ELSE
			SendRexx quickcode "B1"
		ENDIF
	ENDIF
xIcon 32 0 ":icons/blank"
	GadID 3
	IF $qcp_open = 1
		qcp_NewButt = 3
		GoSub qc_prefs.gc ChangeLight
	ELSE
		IF "$qcicon2" = "14/13"
			GuiOpen qc_getmxn.gc
		ELSE
			SendRexx quickcode "B2"
		ENDIF
	ENDIF
xIcon 48 0 ":icons/blank"
	GadID 4
	IF $qcp_open = 1
		qcp_NewButt = 4
		GoSub qc_prefs.gc ChangeLight
	ELSE
		IF "$qcicon3" = "14/13"
			GuiOpen qc_getmxn.gc
		ELSE
			SendRexx quickcode "B3"
		ENDIF
	ENDIF
xIcon 64 0 ":icons/blank"
	GadID 5
	IF $qcp_open = 1
		qcp_NewButt = 5
		GoSub qc_prefs.gc ChangeLight
	ELSE
		IF "$qcicon4" = "14/13"
			GuiOpen qc_getmxn.gc
		ELSE
			SendRexx quickcode "B4"
		ENDIF
	ENDIF
xIcon 80 0 ":icons/blank"
	GadID 6
	IF $qcp_open = 1
		qcp_NewButt = 6
		GoSub qc_prefs.gc ChangeLight
	ELSE
		IF "$qcicon5" = "14/13"
			GuiOpen qc_getmxn.gc
		ELSE
			SendRexx quickcode "B5"
		ENDIF
	ENDIF
xIcon 96 0 ":icons/blank"
	GadID 7
	IF $qcp_open = 1
		qcp_NewButt = 7
		GoSub qc_prefs.gc ChangeLight
	ELSE
		IF "$qcicon6" = "14/13"
			GuiOpen qc_getmxn.gc
		ELSE
			SendRexx quickcode "B6"
		ENDIF
	ENDIF
xIcon 112 0 ":icons/blank"
	GadID 8
	IF $qcp_open = 1
		qcp_NewButt = 8
		GoSub qc_prefs.gc ChangeLight
	ELSE
		IF "$qcicon7" = "14/13"
			GuiOpen qc_getmxn.gc
		ELSE
			SendRexx quickcode "B7"
		ENDIF
	ENDIF
xIcon 128 0 ":icons/blank"
	GadID 9
	IF $qcp_open = 1
		qcp_NewButt = 9
		GoSub qc_prefs.gc ChangeLight
	ELSE
		IF "$qcicon8" = "14/13"
			GuiOpen qc_getmxn.gc
		ELSE
			SendRexx quickcode "B8"
		ENDIF
	ENDIF
xIcon 144 0 ":icons/blank"
	GadID 10
	IF $qcp_open = 1
		qcp_NewButt = 10
		GoSub qc_prefs.gc ChangeLight
	ELSE
		IF "$qcicon9" = "14/13"
			GuiOpen qc_getmxn.gc
		ELSE
			SendRexx quickcode "B9"
		ENDIF
	ENDIF
 	
xButton 161 0 40 17 "CLR"
	GadID 20
	IF $qcp_open = 0
		IF $qc_clrquery = 1
			EzReq "Clear equation\n\nARE YOU SURE???" "Yes|NO" qc_goahead
			IF $qc_goahead = 1 
				SendRexx quickcode "BCLR"
			ENDIF
		ELSE
			SendRexx quickcode "BCLR"
		ENDIF
	ENDIF
	
	
; Subroutines

xRoutine ChangeButtons

	ChangeIcon QuickCode.gc 1 -1 -1 ":icons/b$qcicon0"
	ChangeIcon QuickCode.gc 2 -1 -1 ":icons/b$qcicon1"
	ChangeIcon QuickCode.gc 3 -1 -1 ":icons/b$qcicon2"
	ChangeIcon QuickCode.gc 4 -1 -1 ":icons/b$qcicon3"
	ChangeIcon QuickCode.gc 5 -1 -1 ":icons/b$qcicon4"
	ChangeIcon QuickCode.gc 6 -1 -1 ":icons/b$qcicon5"
	ChangeIcon QuickCode.gc 7 -1 -1 ":icons/b$qcicon6"
	ChangeIcon QuickCode.gc 8 -1 -1 ":icons/b$qcicon7"
	ChangeIcon QuickCode.gc 9 -1 -1 ":icons/b$qcicon8"
	ChangeIcon QuickCode.gc 10 -1 -1 ":icons/b$qcicon9"
	GoSub quickcode.gc RetFromPrefs

xRoutine RetFromPrefs

; If the user is upgrading from QuickCode 1.7 or earlier, they won't have the
; winx or winy parameters in their env file, so we provide default settings
; for now.

	IF $qc_tempwinx = ""
		qc_tempwinx = 0
	ENDIF
	IF $qc_tempwiny = ""
		qc_tempwiny = 0
	ENDIF
	
	IF $qc_clrbutt = 0
		SetGad quickcode.gc 20 HIDE
		ChangeGad quickcode.gc 0 $qc_tempwinx $qc_tempwiny 160 17 ""
	ELSE
		SetGad quickcode.gc 20 SHOW
		ChangeGad quickcode.gc 0 $qc_tempwinx $qc_tempwiny 200 17 ""
	ENDIF
	Redraw quickcode.gc


xRoutine SavePrefs
	DelVar .qcprefs
	.qcprefs = "$qcicon0 "
	AppVar .qcprefs "$qcicon1 "
	AppVar .qcprefs "$qcicon2 "
	AppVar .qcprefs "$qcicon3 "
	AppVar .qcprefs "$qcicon4 "
	AppVar .qcprefs "$qcicon5 "
	AppVar .qcprefs "$qcicon6 "
	AppVar .qcprefs "$qcicon7 "
	AppVar .qcprefs "$qcicon8 "
	AppVar .qcprefs "$qcicon9 "
	AppVar .qcprefs "$qc_screen "
	AppVar .qcprefs "$qc_clrbutt "
	AppVar .qcprefs "$qc_clrquery "
	AppVar .qcprefs "$qc_winx "
	AppVar .qcprefs "$qc_winy "
	Copy "env:.qcprefs" "envarc:"
	
	
xRoutine GetPrefs
	IfExists FILE "env:.qcprefs"
	Else
		DelVar .qcprefs
		.qcprefs = "lank "					; Buttons 1-10
		AppVar .qcprefs "lank "
		AppVar .qcprefs "lank "
		AppVar .qcprefs "lank "
		AppVar .qcprefs "lank "
		AppVar .qcprefs "lank "
		AppVar .qcprefs "lank "
		AppVar .qcprefs "lank "
		AppVar .qcprefs "lank "
		AppVar .qcprefs "lank "
		AppVar .qcprefs "Workbench "		; Public screen
		AppVar .qcprefs "0 "					; Show CLEAR button
		AppVar .qcprefs "0 "					; Query CLEAR operation
		AppVar .qcprefs "0 "					; Window x-pos
		AppVar .qcprefs "0 "					; Window y-pos
		Copy "env:.qcprefs" "envarc:"
	EndIf
	qc_rawprefs =  $.qcprefs
	CutVar qc_rawprefs Cut Word 1 qcicon0
	CutVar qc_rawprefs Cut Word 1 qcicon1
	CutVar qcicon1 Cut Char 1 qc_dummy
	CutVar qc_rawprefs Cut Word 1 qcicon2
	CutVar qcicon2 Cut Char 1 qc_dummy
	CutVar qc_rawprefs Cut Word 1 qcicon3
	CutVar qcicon3 Cut Char 1 qc_dummy
	CutVar qc_rawprefs Cut Word 1 qcicon4
	CutVar qcicon4 Cut Char 1 qc_dummy
	CutVar qc_rawprefs Cut Word 1 qcicon5
	CutVar qcicon5 Cut Char 1 qc_dummy
	CutVar qc_rawprefs Cut Word 1 qcicon6
	CutVar qcicon6 Cut Char 1 qc_dummy
	CutVar qc_rawprefs Cut Word 1 qcicon7
	CutVar qcicon7 Cut Char 1 qc_dummy
	CutVar qc_rawprefs Cut Word 1 qcicon8
	CutVar qcicon8 Cut Char 1 qc_dummy
	CutVar qc_rawprefs Cut Word 1 qcicon9
	CutVar qcicon9 Cut Char 1 qc_dummy
	CutVar qc_rawprefs Cut Word 1 qc_screen
	CutVar qc_screen Cut Char 1 qc_dummy
	
	SetScreen quickcode.gc $qc_screen
	SetScreen qc_prefs.gc $qc_screen
	SetScreen qc_getmxn.qc $qc_screen

	CutVar qc_rawprefs Cut Word 1 qc_clrbutt
	CutVar qc_clrbutt Cut Char 1 qc_dummy
	CutVar qc_rawprefs Cut Word 1 qc_clrquery
	CutVar qc_clrquery Cut Char 1 qc_dummy
	
	CutVar qc_rawprefs Cut Word 1 qc_winx
	CutVar qc_winx Cut Char 1 qc_dummy
	CutVar qc_rawprefs Cut Word 1 qc_winy
	CutVar qc_winy Cut Char 1 qc_dummy
	
	qc_tempwinx = $qc_winx
	qc_tempwiny = $qc_winy
	
	