Skip to content
Snippets Groups Projects
Commit 4f087081 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Add some more uifc functions to the uifc object.

scrn, showbuf, timedisplay, bottomline, getstrxy
parent 1c13b8af
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #1237 passed
...@@ -50,12 +50,27 @@ struct list_ctx_private { ...@@ -50,12 +50,27 @@ struct list_ctx_private {
int width; int width;
}; };
struct showbuf_ctx_private {
int cur;
int bar;
int left;
int top;
int width;
int height;
};
struct getstrxy_ctx_private {
int lastkey;
};
enum { enum {
PROP_CUR PROP_CUR
,PROP_BAR ,PROP_BAR
,PROP_LEFT ,PROP_LEFT
,PROP_TOP ,PROP_TOP
,PROP_WIDTH ,PROP_WIDTH
,PROP_HEIGHT
,PROP_LASTKEY
}; };
static JSBool js_list_ctx_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp) static JSBool js_list_ctx_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
...@@ -126,6 +141,124 @@ static JSBool js_list_ctx_set(JSContext *cx, JSObject *obj, jsid id, JSBool stri ...@@ -126,6 +141,124 @@ static JSBool js_list_ctx_set(JSContext *cx, JSObject *obj, jsid id, JSBool stri
return JS_TRUE; return JS_TRUE;
} }
static JSBool js_showbuf_ctx_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
jsval idval;
jsint tiny;
struct showbuf_ctx_private* p;
if((p=(struct showbuf_ctx_private*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
switch(tiny) {
case PROP_CUR:
*vp=INT_TO_JSVAL(p->cur);
break;
case PROP_BAR:
*vp=INT_TO_JSVAL(p->bar);
break;
case PROP_LEFT:
*vp=INT_TO_JSVAL(p->left);
break;
case PROP_TOP:
*vp=INT_TO_JSVAL(p->top);
break;
case PROP_WIDTH:
*vp=INT_TO_JSVAL(p->width);
break;
case PROP_HEIGHT:
*vp=INT_TO_JSVAL(p->height);
break;
}
return JS_TRUE;
}
static JSBool js_showbuf_ctx_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
jsval idval;
jsint tiny;
int32 i=0;
struct showbuf_ctx_private* p;
if((p=(struct showbuf_ctx_private*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
if(!JS_ValueToInt32(cx, *vp, &i))
return JS_FALSE;
switch(tiny) {
case PROP_CUR:
p->cur=i;
break;
case PROP_BAR:
p->bar=i;
break;
case PROP_LEFT:
p->left=i;
break;
case PROP_TOP:
p->top=i;
break;
case PROP_WIDTH:
p->width=i;
break;
case PROP_HEIGHT:
p->height=i;
break;
}
return JS_TRUE;
}
static JSBool js_getstrxy_ctx_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
jsval idval;
jsint tiny;
struct getstrxy_ctx_private* p;
if((p=(struct getstrxy_ctx_private*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
switch(tiny) {
case PROP_LASTKEY:
*vp=INT_TO_JSVAL(p->lastkey);
break;
}
return JS_TRUE;
}
static JSBool js_getstrxy_ctx_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
jsval idval;
jsint tiny;
int32 i=0;
struct getstrxy_ctx_private* p;
if((p=(struct getstrxy_ctx_private*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
if(!JS_ValueToInt32(cx, *vp, &i))
return JS_FALSE;
switch(tiny) {
case PROP_LASTKEY:
p->lastkey=i;
break;
}
return JS_TRUE;
}
#ifdef BUILD_JSDOCS #ifdef BUILD_JSDOCS
static char* uifc_list_ctx_prop_desc[] = { static char* uifc_list_ctx_prop_desc[] = {
"Currently selected item" "Currently selected item"
...@@ -135,6 +268,21 @@ static char* uifc_list_ctx_prop_desc[] = { ...@@ -135,6 +268,21 @@ static char* uifc_list_ctx_prop_desc[] = {
,"forced width" ,"forced width"
,NULL ,NULL
}; };
static char* uifc_showbuf_ctx_prop_desc[] = {
"Currently selected item"
,"0-based Line number in the currently displayed set that is highlighted"
,"left column"
,"top line"
,"forced width"
,"forced height"
,NULL
};
static char* uifc_gotoxy_ctx_prop_desc[] = {
"Last pressed key"
,NULL
};
#endif #endif
/* Destructor */ /* Destructor */
...@@ -151,6 +299,30 @@ js_list_ctx_finalize(JSContext *cx, JSObject *obj) ...@@ -151,6 +299,30 @@ js_list_ctx_finalize(JSContext *cx, JSObject *obj)
JS_SetPrivate(cx,obj,NULL); JS_SetPrivate(cx,obj,NULL);
} }
static void
js_showbuf_ctx_finalize(JSContext *cx, JSObject *obj)
{
struct showbuf_ctx_private* p;
if((p=(struct showbuf_ctx_private*)JS_GetPrivate(cx,obj))==NULL)
return;
free(p);
JS_SetPrivate(cx,obj,NULL);
}
static void
js_getstrxy_ctx_finalize(JSContext *cx, JSObject *obj)
{
struct getstrxy_ctx_private* p;
if((p=(struct getstrxy_ctx_private*)JS_GetPrivate(cx,obj))==NULL)
return;
free(p);
JS_SetPrivate(cx,obj,NULL);
}
static JSClass js_uifc_list_ctx_class = { static JSClass js_uifc_list_ctx_class = {
"CTX" /* name */ "CTX" /* name */
,JSCLASS_HAS_PRIVATE /* flags */ ,JSCLASS_HAS_PRIVATE /* flags */
...@@ -164,11 +336,55 @@ static JSClass js_uifc_list_ctx_class = { ...@@ -164,11 +336,55 @@ static JSClass js_uifc_list_ctx_class = {
,js_list_ctx_finalize /* finalize */ ,js_list_ctx_finalize /* finalize */
}; };
static JSClass js_uifc_showbuf_ctx_class = {
"CTX" /* name */
,JSCLASS_HAS_PRIVATE /* flags */
,JS_PropertyStub /* addProperty */
,JS_PropertyStub /* delProperty */
,js_showbuf_ctx_get /* getProperty */
,js_showbuf_ctx_set /* setProperty */
,JS_EnumerateStub /* enumerate */
,JS_ResolveStub /* resolve */
,JS_ConvertStub /* convert */
,js_showbuf_ctx_finalize /* finalize */
};
static JSClass js_uifc_getstrxy_ctx_class = {
"CTX" /* name */
,JSCLASS_HAS_PRIVATE /* flags */
,JS_PropertyStub /* addProperty */
,JS_PropertyStub /* delProperty */
,js_getstrxy_ctx_get /* getProperty */
,js_getstrxy_ctx_set /* setProperty */
,JS_EnumerateStub /* enumerate */
,JS_ResolveStub /* resolve */
,JS_ConvertStub /* convert */
,js_getstrxy_ctx_finalize /* finalize */
};
static jsSyncPropertySpec js_uifc_list_class_properties[] = { static jsSyncPropertySpec js_uifc_list_class_properties[] = {
/* name ,tinyid ,flags, ver */ /* name ,tinyid ,flags, ver */
{ "cur" ,PROP_CUR ,JSPROP_ENUMERATE, 317 }, { "cur" ,PROP_CUR ,JSPROP_ENUMERATE, 317 },
{ "bar" ,PROP_BAR ,JSPROP_ENUMERATE, 317 }, { "bar" ,PROP_BAR ,JSPROP_ENUMERATE, 317 },
{ "left" ,PROP_LEFT ,JSPROP_ENUMERATE, 31802 },
{ "top" ,PROP_TOP ,JSPROP_ENUMERATE, 31802 },
{ "width" ,PROP_WIDTH ,JSPROP_ENUMERATE, 31802 },
{0}
};
static jsSyncPropertySpec js_uifc_showbuf_class_properties[] = {
/* name ,tinyid ,flags, ver */
{ "cur" ,PROP_CUR ,JSPROP_ENUMERATE, 31802 },
{ "bar" ,PROP_BAR ,JSPROP_ENUMERATE, 31802 },
{0}
};
static jsSyncPropertySpec js_uifc_getstrxy_class_properties[] = {
/* name ,tinyid ,flags, ver */
{ "lastkey" ,PROP_LASTKEY ,JSPROP_ENUMERATE, 31802 },
{0} {0}
}; };
...@@ -200,6 +416,60 @@ static JSBool js_list_ctx_constructor(JSContext *cx, uintN argc, jsval *arglist) ...@@ -200,6 +416,60 @@ static JSBool js_list_ctx_constructor(JSContext *cx, uintN argc, jsval *arglist)
return JS_TRUE; return JS_TRUE;
} }
static JSBool js_showbuf_ctx_constructor(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj = JS_THIS_OBJECT(cx, arglist);
struct showbuf_ctx_private* p;
obj = JS_NewObject(cx, &js_uifc_showbuf_ctx_class, NULL, NULL);
JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(obj));
if ((p = (struct showbuf_ctx_private *)calloc(1, sizeof(struct showbuf_ctx_private)))==NULL) {
JS_ReportError(cx, "calloc failed");
return JS_FALSE;
}
if(!JS_SetPrivate(cx, obj, p)) {
JS_ReportError(cx, "JS_SetPrivate failed");
return JS_FALSE;
}
js_SyncResolve(cx, obj, NULL, js_uifc_showbuf_class_properties, NULL, NULL, 0);
#ifdef BUILD_JSDOCS
js_DescribeSyncObject(cx, obj, "Class used to retain UIFC showbuf context", 317);
js_DescribeSyncConstructor(cx, obj, "To create a new UIFCShowbufContext object: <tt>var ctx = new UIFCShowbufContext();</tt>");
js_CreateArrayOfStrings(cx, obj, "_property_desc_list", uifc_showbuf_ctx_prop_desc, JSPROP_READONLY);
#endif
return JS_TRUE;
}
static JSBool js_getstrxy_ctx_constructor(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj = JS_THIS_OBJECT(cx, arglist);
struct getstrxy_ctx_private* p;
obj = JS_NewObject(cx, &js_uifc_getstrxy_ctx_class, NULL, NULL);
JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(obj));
if ((p = (struct getstrxy_ctx_private *)calloc(1, sizeof(struct getstrxy_ctx_private)))==NULL) {
JS_ReportError(cx, "calloc failed");
return JS_FALSE;
}
if(!JS_SetPrivate(cx, obj, p)) {
JS_ReportError(cx, "JS_SetPrivate failed");
return JS_FALSE;
}
js_SyncResolve(cx, obj, NULL, js_uifc_getstrxy_class_properties, NULL, NULL, 0);
#ifdef BUILD_JSDOCS
js_DescribeSyncObject(cx, obj, "Class used to retain UIFC getstrxy context", 317);
js_DescribeSyncConstructor(cx, obj, "To create a new UIFCGetStrXYContext object: <tt>var ctx = new UIFCGetStrXYContext();</tt>");
js_CreateArrayOfStrings(cx, obj, "_property_desc_list", uifc_showbuf_ctx_prop_desc, JSPROP_READONLY);
#endif
return JS_TRUE;
}
/* Properties */ /* Properties */
enum { enum {
PROP_INITIALIZED /* read-only */ PROP_INITIALIZED /* read-only */
...@@ -765,6 +1035,255 @@ js_uifc_list(JSContext *cx, uintN argc, jsval *arglist) ...@@ -765,6 +1035,255 @@ js_uifc_list(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE); return(JS_TRUE);
} }
static JSBool
js_uifc_scrn(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* str = NULL;
uifcapi_t* uifc;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((uifc=get_uifc(cx,obj))==NULL)
return(JS_FALSE);
JSVALUE_TO_MSTRING(cx, argv[0], str, NULL);
HANDLE_PENDING(cx, str);
if(str==NULL)
return(JS_TRUE);
rc=JS_SUSPENDREQUEST(cx);
uifc->scrn(str);
free(str);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_uifc_timedisplay(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
JSBool force = JS_FALSE;
uifcapi_t* uifc;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((uifc=get_uifc(cx,obj))==NULL)
return(JS_FALSE);
if (argc > 0)
force = JSVAL_TO_BOOLEAN(argv[0]);
rc=JS_SUSPENDREQUEST(cx);
uifc->timedisplay(force);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_uifc_bottomline(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
int mode;
uifcapi_t* uifc;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((uifc=get_uifc(cx,obj))==NULL)
return(JS_FALSE);
if (argc == 0) {
JS_ReportError(cx, "No mode specified");
return(JS_FALSE);
}
mode = JSVAL_TO_INT(argv[0]);
rc=JS_SUSPENDREQUEST(cx);
uifc->bottomline(mode);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_uifc_getstrxy(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* str;
char* org=NULL;
int32 left=0;
int32 top=0;
int32 width=0;
int32 maxlen=0;
int32 mode=0;
uifcapi_t* uifc;
uintN argn=0;
jsrefcount rc;
JSObject* objarg;
int *lastkey = NULL;
struct getstrxy_ctx_private *p;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((uifc=get_uifc(cx,obj))==NULL)
return(JS_FALSE);
if (argc < 5) {
JS_ReportError(cx, "getstrxy requires at least five arguments");
return JS_FALSE;
}
if (!JS_ValueToInt32(cx, argv[argn++], &left))
return JS_FALSE;
if (!JS_ValueToInt32(cx, argv[argn++], &top))
return JS_FALSE;
if (!JS_ValueToInt32(cx, argv[argn++], &width))
return JS_FALSE;
if (!JS_ValueToInt32(cx, argv[argn++], &maxlen))
return JS_FALSE;
if (!JS_ValueToInt32(cx, argv[argn++], &mode))
return JS_FALSE;
if(argn<argc && JSVAL_IS_STRING(argv[argn])) {
JSVALUE_TO_MSTRING(cx, argv[argn], org, NULL);
argn++;
if(JS_IsExceptionPending(cx))
return JS_FALSE;
if(org==NULL)
return(JS_TRUE);
}
if(argn<argc && JSVAL_IS_OBJECT(argv[argn])) {
if((objarg = JSVAL_TO_OBJECT(argv[argn]))==NULL) {
free(org);
return(JS_FALSE);
}
if(JS_GetClass(cx, objarg) == &js_uifc_getstrxy_ctx_class) {
p = JS_GetPrivate(cx, objarg);
if (p != NULL) {
lastkey = &(p->lastkey);
}
}
}
if(maxlen < 1) {
JS_ReportError(cx, "max length less than one");
free(org);
return JS_FALSE;
}
if((str=(char*)malloc(maxlen+1))==NULL) {
free(org);
return(JS_FALSE);
}
memset(str,0,maxlen+1);
if(org) {
strncpy(str,org,maxlen);
free(org);
}
rc=JS_SUSPENDREQUEST(cx);
if(uifc->getstrxy(left, top, width, str, maxlen, mode, lastkey)<0) {
JS_RESUMEREQUEST(cx, rc);
free(str);
JS_SET_RVAL(cx, arglist, JSVAL_NULL);
return(JS_TRUE);
}
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(JS_NewStringCopyZ(cx,str)));
if(str)
free(str);
return(JS_TRUE);
}
static JSBool
js_uifc_showbuf(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* str;
char* title;
int32 left=0;
int32 top=0;
int32 width=0;
int32 height=0;
int32 mode=0;
int *cur = NULL;
int *bar = NULL;
uifcapi_t* uifc;
uintN argn=0;
jsrefcount rc;
JSObject* objarg;
struct showbuf_ctx_private *p;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((uifc=get_uifc(cx,obj))==NULL)
return(JS_FALSE);
if (argc < 3) {
JS_ReportError(cx, "showbuf requires at least three arguments");
return JS_FALSE;
}
if (!JS_ValueToInt32(cx, argv[argn++], &mode))
return JS_FALSE;
JSVALUE_TO_MSTRING(cx, argv[argn++], title, NULL);
if(JS_IsExceptionPending(cx))
return JS_FALSE;
if(title==NULL)
return(JS_TRUE);
JSVALUE_TO_MSTRING(cx, argv[argn++], str, NULL);
if(JS_IsExceptionPending(cx)) {
free(title);
return JS_FALSE;
}
if(str==NULL) {
free(title);
return(JS_TRUE);
}
if(argn<argc && JSVAL_IS_OBJECT(argv[argn])) {
if((objarg = JSVAL_TO_OBJECT(argv[argn]))==NULL) {
free(title);
free(str);
return(JS_FALSE);
}
if(JS_GetClass(cx, objarg) == &js_uifc_list_ctx_class) {
p = JS_GetPrivate(cx, objarg);
if (p != NULL) {
cur = &(p->cur);
bar = &(p->bar);
left = p->left;
top = p->top;
width = p->width;
height = p->height;
}
}
}
rc=JS_SUSPENDREQUEST(cx);
uifc->showbuf(mode, left, top, width, height,title, str, cur, bar);
JS_RESUMEREQUEST(cx, rc);
free(title);
free(str);
return(JS_TRUE);
}
/* Destructor */ /* Destructor */
static void static void
...@@ -797,7 +1316,7 @@ static jsSyncMethodSpec js_functions[] = { ...@@ -797,7 +1316,7 @@ static jsSyncMethodSpec js_functions[] = {
,JSDOCSTR("popup (or down) a message") ,JSDOCSTR("popup (or down) a message")
,314 ,314
}, },
{"input", js_uifc_input, 0, JSTYPE_STRING, JSDOCSTR("[number mode] [number left] [number top] [string default] [number maxlen] [number kmode]") {"input", js_uifc_input, 0, JSTYPE_STRING, JSDOCSTR("[number mode] [,number left] [,number top] [,string default] [,number maxlen] [,number kmode]")
,JSDOCSTR("prompt for a string input") ,JSDOCSTR("prompt for a string input")
,314 ,314
}, },
...@@ -808,10 +1327,34 @@ static jsSyncMethodSpec js_functions[] = { ...@@ -808,10 +1327,34 @@ static jsSyncMethodSpec js_functions[] = {
) )
,314 ,314
}, },
{"showhelp", js_uifc_showhelp, 0, JSTYPE_VOID, JSDOCSTR("") {"showhelp", js_uifc_showhelp, 0, JSTYPE_VOID, JSDOCSTR("")
,JSDOCSTR("Shows the current help text") ,JSDOCSTR("Shows the current help text")
,317 ,317
}, },
{"scrn", js_uifc_scrn, 1, JSTYPE_BOOLEAN, JSDOCSTR("string text")
,JSDOCSTR("Fill the screen with the appropriate background attribute. string is the title for the application banner.")
,31802
},
{"showbuf", js_uifc_showbuf, 7, JSTYPE_VOID, JSDOCSTR("number mode, string title, string helpbuf [,uifc.showbuf.CTX object]")
,JSDOCSTR("Shows a scrollable text buffer - optionally parsing \"help markup codes\"<br>"
"The context object can be created using new uifc.showbuf.CTX() and if the same object is passed, allows WIN_SAV to work correctly.<br>"
"The context object has the following properties: cur, bar")
,31802
},
{"timedisplay", js_uifc_timedisplay, 0, JSTYPE_VOID, JSDOCSTR("[bool force = false]")
,JSDOCSTR("Updates time in upper left corner of screen with current time in ASCII/Unix format")
,31802
},
{"bottomline", js_uifc_bottomline, 1, JSTYPE_VOID, JSDOCSTR("number mode")
,JSDOCSTR("Displays the bottom line using the WIN_* mode flags")
,31802
},
{"getstrxy", js_uifc_getstrxy, 7, JSTYPE_STRING, JSDOCSTR("number left, number top, number width, number max, number mode[, string original][, uifc.getstrxy.CTX object]")
,JSDOCSTR("String input/exit box at a specified position"
"The context object can be created using new uifc.showbuf.CTX() and if the same object is passed, allows WIN_SAV to work correctly.<br>"
"The context object has the following properties: lastkey")
,31802
},
{0} {0}
}; };
...@@ -840,6 +1383,20 @@ static JSBool js_uifc_resolve(JSContext *cx, JSObject *obj, jsid id) ...@@ -840,6 +1383,20 @@ static JSBool js_uifc_resolve(JSContext *cx, JSObject *obj, jsid id)
JS_InitClass(cx, tobj, NULL, &js_uifc_list_ctx_class, js_list_ctx_constructor, 0, NULL, NULL, NULL, NULL); JS_InitClass(cx, tobj, NULL, &js_uifc_list_ctx_class, js_list_ctx_constructor, 0, NULL, NULL, NULL, NULL);
} }
} }
if (name == NULL || strcmp(name, "showbuf") == 0) {
if(JS_GetProperty(cx, obj, "showbuf", &objval)) {
tobj = JSVAL_TO_OBJECT(objval);
if (tobj)
JS_InitClass(cx, tobj, NULL, &js_uifc_showbuf_ctx_class, js_showbuf_ctx_constructor, 0, NULL, NULL, NULL, NULL);
}
}
if (name == NULL || strcmp(name, "getstrxy") == 0) {
if(JS_GetProperty(cx, obj, "getstrxy", &objval)) {
tobj = JSVAL_TO_OBJECT(objval);
if (tobj)
JS_InitClass(cx, tobj, NULL, &js_uifc_getstrxy_ctx_class, js_getstrxy_ctx_constructor, 0, NULL, NULL, NULL, NULL);
}
}
if(name) if(name)
free(name); free(name);
return ret; return ret;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment