
#ifdef MACVERSION
	#include <standard.h>
#endif

#ifdef WIN95VERSION
	#include "standard.h"
#endif

#include "resources.h"
#include "lang.h"
#include "langexternal.h"
#include "tablestructure.h"
#include "cancoon.h"
#include "cancooninternal.h"
#include "kernelverbdefs.h"
#include "about.h"




#define cancoonerrorlist 268 
#define notimplementederror 3


typedef enum tycancoontoken { 
	
	showflagfunc,
	
	hideflagfunc,
	
	showpopupfunc,
	
	hidepopupfunc,
	
	showbuttonsfunc,
	
	hidebuttonsfunc,

	showserverstatsfunc,
	
	/*
	setmsgfunc,
	*/
	
	ctcancoonverbs
	} tycancoontoken;



static boolean ccshowhideverb (hdltreenode hparam1, boolean flshow, boolean flshowing, callback toggleroutine, tyvaluerecord *vreturned) {
	
	/*
	set vreturned to false if the state of the flag is not changed.  otherwise, 
	call the toggle routine and return true.
	
	1/30/92 dmb: fixed typo; when toggling, set vreturned to true, not false!
	
	5.6.97 dmb: can no longer assume that the "root" window is cancoon. globals 
	are now set in ccfunctionvalue
	*/
	
	if (!langcheckparamcount (hparam1, 0)) /*shouldn't have any parameters*/
		return (false);
	
	if (flshowing != flshow) { /*changing*/
	
	//	shellpushfrontrootglobals ();
		
		(*toggleroutine) ();
		
	//	shellpopglobals ();
		
		(*vreturned).data.flvalue = true;
		}
	
	return (true);
	} /*ccshowhideverb*/


static boolean ccshowflagverb (hdltreenode hparam1, boolean flshow, tyvaluerecord *vreturned) {
	
	/*
	set vreturned to false if the state of the flag is not changed.
	*/
	
	return (ccshowhideverb (hparam1, flshow, !(**cancoonglobals).flflagdisabled, (callback) &cctoggleflag, vreturned));
	} /*ccshowflagverb*/


static boolean ccshowpopupverb (hdltreenode hparam1, boolean flshow, tyvaluerecord *vreturned) {
	
	/*
	set vreturned to false if the state of the popup is not changed.
	*/
	
	return (ccshowhideverb (hparam1, flshow, !(**cancoonglobals).flpopupdisabled, (callback) &cctoggleagentspopup, vreturned));
	} /*ccshowpopupverb*/


static boolean ccshowbuttonsverb (hdltreenode hparam1, boolean flshow, tyvaluerecord *vreturned) {
	
	/*
	set vreturned to false if the state of the buttons is not changed.
	*/
	
	return (ccshowhideverb (hparam1, flshow, (**cancoonglobals).flbigwindow, (callback) &ccflipflag, vreturned));
	} /*ccshowbuttonsverb*/


static boolean ccmsgverb (hdltreenode hparam1, tyvaluerecord *vreturned) {
	
	bigstring bsmsg;
	
	flnextparamislast = true;
	
	if (!getstringvalue (hparam1, 1, bsmsg))
		return (false);
	
	if (shellwindow != nil)
		shellpushrootglobals (shellwindow);
	else
		shellpushfrontrootglobals ();
	
	ccmsg (bsmsg, !processisoneshot (true));
	
	shellpopglobals ();
	
	return (setbooleanvalue (true, vreturned));
	} /*ccmsgverb*/


static boolean ccfunctionvalue (short token, hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
	
	/*
	8/23/91 dmb: don't push front globals around entire switch, since that 
	would disable background processes while the parameter to "msg" is 
	evaluated.
	
	8/25/92 dmb: commented-out setmsgfunc -- redundant & undocumented
	*/
	
	register tyvaluerecord *v = vreturned;
	register boolean fl = false;
	register short errornum = 0;
	
	setbooleanvalue (false, v); /*by default, cancoon functions return false*/
	
	#ifdef version42orgreater
		// can no longer assume that the "root" window is cancoon
		if (!shellfindwindow (idcancoonconfig, &cancoonwindow, &cancoonwindowinfo, (Handle *) &cancoondata))
			return (true);
		
		shellpushglobals (cancoonwindow);
	#endif

	switch (token) {
		
		case showflagfunc:
			fl = ccshowflagverb (hparam1, true, v);
			
			break;
		
		case hideflagfunc:
			fl = ccshowflagverb (hparam1, false, v);
			
			break;
		
		case showpopupfunc:
			fl = ccshowpopupverb (hparam1, true, v);
			
			break;
		
		case hidepopupfunc:
			fl = ccshowpopupverb (hparam1, false, v);
			
			break;
		
		case showbuttonsfunc:
			fl = ccshowbuttonsverb (hparam1, true, v);
			
			break;
		
		case hidebuttonsfunc:
			fl = ccshowbuttonsverb (hparam1, false, v);
			
			break;
		
		case showserverstatsfunc: {
			boolean flset;
			
			flnextparamislast = true;

			if (!getbooleanvalue (hparam1, 1, &flset))
				break;
												
			aboutsetstatsflag (flset);
						
			fl = setbooleanvalue (true, v);
			}
			
			break;
		
		/*
		case setmsgfunc:
			fl = ccmsgverb (hparam1, v);
			
			break;
		*/
		
		default:
			fl = false;
			
			errornum = notimplementederror;
			
			break;
		} /*switch*/
	
	#ifdef version42orgreater
		shellpopglobals ();
	#endif

	if (fl)
		return (true);
	
	if (errornum != 0) /*get error string*/
		getstringlist (cancoonerrorlist, errornum, bserror);
	
	return (false);
	} /*ccfunctionvalue*/


boolean ccinitverbs (void) {
	
	langcallbacks.msgverbcallback = &ccmsgverb;
	
	return (loadfunctionprocessor (idcancoonverbs, &ccfunctionvalue));
	} /*ccinitverbs*/




