G4C

;
; QuickCode V1.8
;
; 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.

WinBig 0 0 200 17 "QuickCode 1.8"
WinType 11010000

NoFontSense

xOnLoad
	GuiLoad :qc_prefs.gc
	GuiLoad :qc_getmxn.gc
	
	GoSub quickcode.gc getprefs			
	Extract QuickCode.gc GuiPath qc_path
	SetVar 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
	
	SetVar qcp_Bank 1
	SetVar qcp_Button 1
	SetVar qcp_Cmd "lank"
	
	
xOnClose
	SendRexx quickcode "EXIT"
	GoSub quickcode.gc saveprefs
	GuiQuit QuickCode.gc
	GuiQuit QC_Prefs.gc
	GuiQuit QC_GetMxN.gc
	IF $qc_guiquit = 1
		IF $$g4c.loaded = 3
			Quit
		ELSE
			EzReq "Cannot unload G4C, sorry" "OK" dummy
		ENDIF
	ENDIF

	
xOnJump qc_screen
	SetScreen qc_prefs.gc $qc_screen
	SetScreen qc_getmxn.gc $qc_screen
	SetVar .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_guiquit "
	AppVar .qcprefs "$qc_clrbutt "
	AppVar .qcprefs "$qc_clrquery "
	AppVar .qcprefs "$qc_winx "
	AppVar .qcprefs "$qc_winy "
	
	Copy "env:.qcprefs" "envarc:"


; Menu definitions

xMenu Project About "" ""
	EzReq "QuickCode 1.8 (31st May 1997)\n\nby Chris Coulson\n(c.j.coulson@ncl.ac.uk)\n\nUsing Gui4CLI v3.0" "OK" Dummy
xMenu Project Barlabel "" ""
xMenu Project Quit "" "Q"
	GuiClose quickcode.gc

xMenu Settings Change "" "C"
	GuiOpen qc_prefs.gc
xMenu Settings Snapshot "" "S"
	qc_winx = $$win.l
	qc_winy = $$win.t

	
	
; 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 "$qcicon0" = "14/13"
		GuiOpen qc_getmxn.gc
	ELSE
		SendRexx quickcode "B0"
	ENDIF
xIcon 16 0 ":icons/blank"
	GadID 2
	IF "$qcicon1" = "14/13"
		GuiOpen qc_getmxn.gc
	ELSE
		SendRexx quickcode "B1"
	ENDIF
xIcon 32 0 ":icons/blank"
	GadID 3
	IF "$qcicon2" = "14/13"
		GuiOpen qc_getmxn.gc
	ELSE
		SendRexx quickcode "B2"
	ENDIF
xIcon 48 0 ":icons/blank"
	GadID 4
	IF "$qcicon3" = "14/13"
		GuiOpen qc_getmxn.gc
	ELSE
		SendRexx quickcode "B3"
	ENDIF
xIcon 64 0 ":icons/blank"
	GadID 5
	IF "$qcicon4" = "14/13"
		GuiOpen qc_getmxn.gc
	ELSE
		SendRexx quickcode "B4"
	ENDIF
xIcon 80 0 ":icons/blank"
	GadID 6
	IF "$qcicon5" = "14/13"
		GuiOpen qc_getmxn.gc
	ELSE
		SendRexx quickcode "B5"
	ENDIF
xIcon 96 0 ":icons/blank"
	GadID 7
	IF "$qcicon6" = "14/13"
		GuiOpen qc_getmxn.gc
	ELSE
		SendRexx quickcode "B6"
	ENDIF
xIcon 112 0 ":icons/blank"
	GadID 8
	IF "$qcicon7" = "14/13"
		GuiOpen qc_getmxn.gc
	ELSE
		SendRexx quickcode "B7"
	ENDIF
xIcon 128 0 ":icons/blank"
	GadID 9
	IF "$qcicon8" = "14/13"
		GuiOpen qc_getmxn.gc
	ELSE
		SendRexx quickcode "B8"
	ENDIF
xIcon 144 0 ":icons/blank"
	GadID 10
	IF "$qcicon9" = "14/13"
		GuiOpen qc_getmxn.gc
	ELSE
		SendRexx quickcode "B9"
	ENDIF
 	
xButton 161 0 40 17 "CLR"
	GadID 20
	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
	
	
; 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"
	
	IF $qc_winx = ""
		qc_winx = 0
	ENDIF
	IF $qc_winy = ""
		qc_winy = 0
	ENDIF
	
	IF $qc_clrbutt = 0
		SetGad quickcode.gc 20 HIDE
		ChangeGad quickcode.gc 0 $qc_winx $qc_winy 160 17 ""
	ELSE
		SetGad quickcode.gc 20 SHOW
		ChangeGad quickcode.gc 0 $qc_winx $qc_winy 200 17 ""
	ENDIF
	Redraw quickcode.gc


xRoutine SavePrefs
	DelVar .qcprefs
	SetVar .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_guiquit "
	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
		SetVar .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 "					; Quit G4C on close
		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
	SetVar 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_guiquit
	CutVar qc_guiquit Cut Char 1 qc_dummy
	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

	