#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "xaw.h"
//*** Strong suggetion for mac users to overwrite Intrinsic.h ***
void functionLoader_Gui(JSGlobalContextRef ctx, JSObjectRef jobjGlobal);
XtAppContext app_con;
-XtOrientation xawOrientationDirection[]={XtorientHorizontal, XtorientVertical};
-
-
-volatile Widget *myWidgets;
-volatile xawWidet *myCtrls;
+JSContextRef jsGlobalCtx;
+JSObjectRef tmp;
+const XtOrientation xawOrientationDirection[]={XtorientHorizontal, XtorientVertical};
+Widget *myWidgets;
int objIDc = 0;
volatile jsCallbackInfo *myCallBacks;
#pragma GCC optimization_level 0
void xawJsCallbackFunction( Widget w, XtPointer client, XtPointer called )
{
- JSObjectCallAsFunction((*(jsCallbackInfo*)client).Context, (*(jsCallbackInfo*)client).Function, NULL, 0,resources,NULL);
+ //JSObjectCallAsFunction((*(jsCallbackInfo*)client).Context, (*(jsCallbackInfo*)client).Function, NULL, 0,resources,NULL);
}
#pragma GCC optimization_level reset
-Widget createForm(Widget* form, xawWindow window)
+static JSValueRef jsXawWindowGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+ JSValueRef result = NULL;
+ //printf("Get:");
+ size_t len = JSStringGetMaximumUTF8CStringSize(propertyName);
+ char* pname = (char*)malloc(len);
+
+ JSStringGetUTF8CString(propertyName, pname, len);
+ //printf("%s\n",pname);
+
+ if (!strcmp(pname, "test")) {
+ result = JSValueMakeNumber(ctx, 1.23);
+ }
+
+ free(pname);
+ return result;
+}
+static bool jsXawWindowSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef jsPropertyName, JSValueRef value, JSValueRef* exception)
{
- Widget top;
+ printf("Set\n");
+ bool setSuccess = FALSE;
+ size_t len = JSStringGetMaximumUTF8CStringSize(jsPropertyName);
+ char* propertyName = (char*)malloc(len);
+ JSStringGetUTF8CString(jsPropertyName, propertyName, len);
+
+
+ if(!strcmp( propertyName, "direction" ))
+ {
+ setSuccess = TRUE;
+ }
+
+
+
+ free(propertyName);
+ return setSuccess;
+}
- /* ツールキットの初期化 */
- top = XtVaAppInitialize( window.Context, window.Name, NULL, 0, &(window.argc), window.argv, NULL, NULL );
- /* クラス名 引数のリソース指定を解釈*/
- /* 台紙ウィジットの作成 */ /* ウィジットクラス */
- *form = XtVaCreateManagedWidget( "form", formWidgetClass, top,
- /* ウィジット名 */ /* 親ウィンドウ */
- /* リソースの指定 */ XtNorientation, window.Direction,
- /* いくつでもOKなので最後はNULL */ NULL );
- return top;
+static JSValueRef jsXawWindowShow(
+ JSContextRef ctx,
+ JSObjectRef jobj,
+ JSObjectRef jobjThis,
+ size_t argLen,
+ const JSObjectRef args[],
+ JSValueRef* jobjExp)
+{
+ jsGlobalCtx = ctx;
+
+ const int parentObjectID = (int)JSObjectGetPrivate(jobjThis);
+
+ XtRealizeWidget( myWidgets[parentObjectID] );
+ XtAppMainLoop( app_con );
+
+ // undefined を作って返す
+ return JSValueMakeUndefined(ctx);
}
-#pragma GCC optimization_level 0
-Widget createControl(xawWidet widget, jsCallbackInfo* callinfo)
+
+static JSObjectRef jsXawWindowConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
- myWidgets = (Widget *)realloc( (void*)myWidgets, sizeof(Widget)*(objIDc+2) );
+ myWidgets = (Widget *)realloc( (void*)myWidgets, sizeof(Widget)*(objIDc+1) );
if( myWidgets == NULL )//ポインタが空っぽだったら実行停止。
{
- printf( "Memory re-allocation failed!\n" );
+ printf( "Memory alloc failed!\n" );
exit( 1 );
}
- myWidgets[objIDc+2] =0;
- myWidgets[objIDc+2] = XtVaCreateManagedWidget( widget.Name, widget.Type, widget.Parent,
- XtNlabel, widget.Text,
- XtNwidth, widget.Width, XtNheight, widget.Height,
- /* 縁取り */ XtNborderWidth, widget.Border,
- /* 配置方法 */ XtNfromHoriz, NULL,
- /* ウィンドウの左端から */ XtNhorizDistance, widget.Left,
- /* ウィンドウの上端から */ XtNfromVert, NULL,
- XtNvertDistance, widget.Top,
- NULL );
- Colormap cmap;
- XColor c0,c1;
- cmap = DefaultColormap(XtDisplay(myWidgets[objIDc+2]),0);
- XAllocNamedColor(XtDisplay(myWidgets[objIDc+2]),cmap,"rgb:d4/d4/d4",&c1,&c0);
- XtVaSetValues(myWidgets[objIDc+2], XtNbackground,c1.pixel, NULL );
+ /********************************************************************************\
+ Create a whole new class definition for to create new window object with get-set.
+ \********************************************************************************/
+
+ JSClassDefinition classDefinition = kJSClassDefinitionEmpty;
+ classDefinition.className = "Window";
+ classDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
+ classDefinition.getProperty = (JSObjectGetPropertyCallback)jsXawWindowGetProperty;
+ classDefinition.setProperty = (JSObjectSetPropertyCallback)jsXawWindowSetProperty;
+
+ /********************************************************************************\
+ Call XAW to put xwindow instance up.
+ var mywindow = new xawWindow("form", 0);
+ \********************************************************************************/
+
+ char* windowName = "Untitled Window";
+ double windowDirection = 0;
+
+ if (argumentCount) {
+ JSStringRef jstrArg = JSValueToStringCopy(ctx, arguments[0], exception);
+ size_t len = JSStringGetMaximumUTF8CStringSize(jstrArg);
+ windowName = (char*)malloc(len);
+
+ JSStringGetUTF8CString(jstrArg, windowName, len);
+ JSStringRelease(jstrArg);
+ }
+
+ myWidgets[objIDc] = XtVaAppInitialize( &app_con, windowName, NULL, 0, &g_argc, g_argv, NULL, NULL);
+
+ //Construct a class and create object out of it
+ JSObjectRef windowObj = JSObjectMake(ctx, JSClassCreate(&classDefinition), NULL);
+ functionWrapper(ctx, constructor, "Show", (JSObjectCallAsFunctionCallback)jsXawWindowShow);
+ JSObjectSetPrivate(windowObj, (void*)objIDc);
+
- XtAddCallback( myWidgets[objIDc+2], XtNcallback, xawJsCallbackFunction, callinfo );
objIDc++;
- return myWidgets[objIDc+2];
+ return windowObj;
+
}
-
-static JSValueRef jsControlCreate(
- JSContextRef ctx,
- JSObjectRef jobj,
- JSObjectRef jobjThis,
- size_t argLen,
- const JSObjectRef args[],
- JSValueRef* jobjExp)
+static JSValueRef jsXawFormGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
- JSValueRef r = JSValueMakeNumber(ctx, -1);
-
- //type
- int typenum = (int)JSValueToNumber(ctx, JSObjectGetProperty(ctx, jobjThis, JSStringCreateWithUTF8CString("Type"), jobjExp),NULL);
- WidgetClass type;
- switch(typenum)
+ printf("Get:");
+ size_t len = JSStringGetMaximumUTF8CStringSize(propertyName);
+ char* pname = (char*)malloc(len);
+
+ JSStringGetUTF8CString(propertyName, pname, len);
+ printf("%s\n",pname);
+ free(pname);
+ return JSValueMakeNumber(ctx, 1.23);
+}
+static bool jsXawFormSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef jsPropertyName, JSValueRef value, JSValueRef* exception)
+{
+ printf("Set\n");
+ bool setSuccess = FALSE;
+ size_t len = JSStringGetMaximumUTF8CStringSize(jsPropertyName);
+ char* propertyName = (char*)malloc(len);
+ JSStringGetUTF8CString(jsPropertyName, propertyName, len);
+
+
+ if(!strcmp( propertyName, "direction" ))
{
- case 0:
- type = labelWidgetClass;
- break;
- case 1:
- type = commandWidgetClass;
- break;
- case 2:
- type = asciiTextWidgetClass;
- break;
+ setSuccess = TRUE;
}
- //*********
-
- //parent ///???
- int parentID = (int)JSValueToNumber(ctx,
- JSObjectGetProperty(ctx,
- (JSObjectRef)JSObjectGetProperty(ctx, jobjThis, JSStringCreateWithUTF8CString("Parent"), jobjExp),
- JSStringCreateWithUTF8CString("ID"),
- jobjExp),NULL);
- //-------
- parentID++;
-
- //text
- JSStringRef jstrText = JSValueToStringCopy(ctx, JSObjectGetProperty(ctx, jobjThis, JSStringCreateWithUTF8CString("Text"), jobjExp), jobjExp);
- size_t len = JSStringGetMaximumUTF8CStringSize(jstrText);
- char* text = (char*)malloc(len);
- JSStringGetUTF8CString(jstrText, text, len);
- //**********
-
- int W = (int)JSValueToNumber(ctx, JSObjectGetProperty(ctx, jobjThis, JSStringCreateWithUTF8CString("Width"), jobjExp),NULL);
- int H = (int)JSValueToNumber(ctx, JSObjectGetProperty(ctx, jobjThis, JSStringCreateWithUTF8CString("Height"), jobjExp),NULL);
- int L = (int)JSValueToNumber(ctx, JSObjectGetProperty(ctx, jobjThis, JSStringCreateWithUTF8CString("Left"), jobjExp),NULL);
- int T = (int)JSValueToNumber(ctx, JSObjectGetProperty(ctx, jobjThis, JSStringCreateWithUTF8CString("Top"), jobjExp),NULL);
- int B = (int)JSValueToNumber(ctx, JSObjectGetProperty(ctx, jobjThis, JSStringCreateWithUTF8CString("Border"), jobjExp),NULL);
-
- JSStringRef jstrCallback = JSValueToStringCopy(ctx, JSObjectGetProperty(ctx, jobjThis, JSStringCreateWithUTF8CString("Callback"), jobjExp), jobjExp);
- len = JSStringGetMaximumUTF8CStringSize(jstrCallback);
- char* func = (char*)malloc(len);
- JSStringGetUTF8CString(jstrCallback, func, len);
-
- myCtrls = (xawWidet *)realloc( (void*)myCtrls, sizeof(xawWidet)*(objIDc+2) );
- if( myCtrls == NULL )//ポインタが空っぽだったら実行停止。
+
+ free(propertyName);
+ return setSuccess;
+}
+static JSObjectRef jsXawFormConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ const int parentObjectID = (int)JSObjectGetPrivate(JSValueToObject(ctx,arguments[0],exception));
+ //myWidgets[parentObjectID] is the way of access of parental Widget of the Widget this function is about to create
+ //printf("recieved:%d\n", parentObjectID);
+ //printf("FormConstructor: arg count = %d\n", argumentCount);
+
+ //Add heap area to accomodate a new Widget
+ myWidgets = (Widget *)realloc( (void*)myWidgets, sizeof(Widget)*(objIDc+1) );
+ if( myWidgets == NULL )//stop if empty pointer for some reason
{
- printf( "Memory re-allocation failed!\n" );
- exit( 1 );
+ printf( "Memory alloc failed!\n" );
+ return JSValueToObject(ctx, JSValueMakeNull(ctx), exception);
}
- myCallBacks = (jsCallbackInfo *)realloc( (void*)myCallBacks, sizeof(xawWidet)*(objIDc+2) );
- if( myCallBacks == NULL )//ポインタが空っぽだったら実行停止。
- {
- printf( "Memory re-allocation failed!\n" );
- exit( 1 );
+
+ /********************************************************************************\
+ Create a whole new class definition for to create new window object with get-set.
+ \********************************************************************************/
+
+ JSClassDefinition classDefinition = kJSClassDefinitionEmpty;
+ classDefinition.className = "Form";
+ classDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
+ classDefinition.getProperty = (JSObjectGetPropertyCallback)jsXawFormGetProperty;
+ classDefinition.setProperty = (JSObjectSetPropertyCallback)jsXawFormSetProperty;
+
+
+ /********************************************************************************\
+ Call XAW to put xwindow instance up.
+ var form = new xawForm(mywindow, "form", 0);
+ \********************************************************************************/
+
+
+ char* formName = "Untitled form";
+ double formDirection = 0;
+
+
+ if (argumentCount >= 2) {
+ JSStringRef jstrArg = JSValueToStringCopy(ctx, arguments[1], exception);
+ size_t len = JSStringGetMaximumUTF8CStringSize(jstrArg);
+ formName = (char*)malloc(len);
+
+ JSStringGetUTF8CString(jstrArg, formName, len);
+ JSStringRelease(jstrArg);
+ }
+
+ XtOrientation o = XtorientVertical;
+ if (argumentCount == 3) {
+ formDirection = JSValueToNumber(ctx, arguments[2], exception);
+ o = (formDirection==0)?XtorientVertical:XtorientHorizontal;
}
- char* name = (char*)malloc(sizeof(char)*16);
- sprintf(name, "%d", objIDc+2);
- myCtrls[objIDc+2].Name = name;
- //myCtrl.Name = name;
- myCtrls[objIDc+2].Type = type;
- myCtrls[objIDc+2].Parent = myWidgets[parentID];
- myCtrls[objIDc+2].Text = text;
- myCtrls[objIDc+2].Width = W;//x
- myCtrls[objIDc+2].Height = H;//y
- myCtrls[objIDc+2].Left = L;//x
- myCtrls[objIDc+2].Top = T;//y
- myCtrls[objIDc+2].Border = B;
+ myWidgets[objIDc] = XtVaCreateManagedWidget(formName, formWidgetClass, myWidgets[parentObjectID], XtNorientation, o, NULL);
- //jsCallbackInfo mycallback;
- myCallBacks[objIDc+2].Context = ctx;
+ //Construct a class and create object out of it, send it back to JavaScript.
+ JSObjectRef formObj = JSObjectMake(ctx, JSClassCreate(&classDefinition), NULL);
+ JSObjectSetPrivate(formObj, (void*)objIDc);
- if(!JSValueIsUndefined(ctx, JSObjectGetProperty(ctx, jobjThis, JSStringCreateWithUTF8CString("Callback"), NULL)))
+ objIDc++;
+ return formObj;
+}
+
+static JSValueRef jsXawLabelGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+ printf("Get:");
+ size_t len = JSStringGetMaximumUTF8CStringSize(propertyName);
+ char* pname = (char*)malloc(len);
+
+ JSStringGetUTF8CString(propertyName, pname, len);
+ printf("%s\n",pname);
+ free(pname);
+ return JSValueMakeNumber(ctx, 1.23);
+}
+static bool jsXawLabelSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef jsPropertyName, JSValueRef value, JSValueRef* exception)
+{
+ int objectID = (int)JSObjectGetPrivate(object);
+ //printf("jsXawWidget[%d].Set.", objectID );
+ bool setSuccess = FALSE;
+ size_t len = JSStringGetMaximumUTF8CStringSize(jsPropertyName);
+ char* propertyName = (char*)malloc(len);
+ JSStringGetUTF8CString(jsPropertyName, propertyName, len);
+
+ JSStringRef strOfSetValueTo = JSValueToStringCopy(ctx, value, *exception);
+ len = JSStringGetMaximumUTF8CStringSize(strOfSetValueTo);
+ char* strOfSetTo = (char*)malloc(len);
+ JSStringGetUTF8CString(strOfSetValueTo, strOfSetTo, len);
+ //printf("%s = %s\n",propertyName,strOfSetTo);
+
+ if(!strcmp( propertyName, "direction" ))
{
- myCallBacks[objIDc+2].Function = JSObjectGetProperty(ctx, jobjThis, JSStringCreateWithUTF8CString("Callback"), NULL);
- }else {
- myCallBacks[objIDc+2].Function = NULL;
+ setSuccess = TRUE;
+ }else if(!strcmp( propertyName, "Text" ))
+ {
+ Arg args[1];
+ XtSetArg(args[0],XtNlabel,(XtArgVal)strOfSetTo);
+ XtSetValues(myWidgets[objectID],args,1);
+ //XClearArea(XtDisplay(myWidgets[objectID]), XtWindow(myWidgets[objectID]), 0, 0, 0, 0, True);//NG. BadWindow
+ setSuccess = TRUE;
}
-
-
- Widget w = createControl(myCtrls[objIDc+2], &(myCallBacks[objIDc+2]));
- r = JSValueMakeNumber(ctx, objIDc);
- JSObjectSetProperty(ctx, jobjThis, JSStringCreateWithUTF8CString("ID"), r, kJSPropertyAttributeNone, NULL);
- return r;
+
+ free(propertyName);
+ return setSuccess;
}
-#pragma GCC optimization_level reset
-
-static JSValueRef jsWindowCreate(
- JSContextRef ctx,
- JSObjectRef jobj,
- JSObjectRef jobjThis,
- size_t argLen,
- const JSObjectRef args[],
- JSValueRef* jobjExp)
+static JSObjectRef jsXawWidgetConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
+ const int parentObjectID = (int)JSObjectGetPrivate(JSValueToObject(ctx,arguments[0],exception));
+ //myWidgets[parentObjectID] is the way of access of parental Widget of the Widget this function is about to create
+ //printf("recieved:%d\n", parentObjectID);
+ //printf("WidgetConstructor: arg count = %d\n", argumentCount);
- //XtSetLanguageProc (app_con, NULL, NULL);
-
- myWidgets = (Widget *)malloc( sizeof(Widget)*2 );
- if( myWidgets == NULL )//ポインタが空っぽだったら実行停止。
+ //Add heap area to accomodate a new Widget
+ myWidgets = (Widget *)realloc( (void*)myWidgets, sizeof(Widget)*(objIDc+1) );
+ if( myWidgets == NULL )//stop if empty pointer for some reason
{
printf( "Memory alloc failed!\n" );
- exit( 1 );
+ return JSValueToObject(ctx, JSValueMakeNull(ctx), exception);
}
- xawWindow myWindow;
- JSValueRef r = JSValueMakeNumber(ctx, -1);
- //if(JSObjectIsConstructor(ctx, jobj))
-
- JSStringRef jstrName = JSValueToStringCopy(ctx, JSObjectGetProperty(ctx, jobjThis, JSStringCreateWithUTF8CString("Name"), jobjExp), jobjExp);
- size_t len = JSStringGetMaximumUTF8CStringSize(jstrName);
- char* name = (char*)malloc(len);
- JSStringGetUTF8CString(jstrName, name, len);
+ if (argumentCount >= 2)
+ {
+ char widgetName[8]={'W','i','d','g','e','t','_',(char)objIDc+48};
+ printf("Untitled Widget%d on %d", objIDc, parentObjectID);
+ double widgetDirection = 0;
- myWindow.Context = &app_con;
- myWindow.argc = g_argc;
- myWindow.argv = g_argv;
- myWindow.Name = name;
- myWindow.Direction = (JSValueToBoolean(ctx, JSObjectGetProperty(ctx, jobjThis, JSStringCreateWithUTF8CString("Name"), jobjExp)))?XtorientVertical:XtorientHorizontal;
+ /********************************************************************************\
+ Create a whole new class definition for to create new window object with get-set.
+ \********************************************************************************/
+
+ JSClassDefinition classDefinition = kJSClassDefinitionEmpty;
+ classDefinition.className = "Widget";
+ classDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
+ JSObjectRef widgetObj = NULL;
+
+ /********************************************************************************\
+ Determine what kind of widget is required to be made
+ \********************************************************************************/
+
+ if((argumentCount == 2) && JSValueIsString(ctx, arguments[1]))
+ {//Label
+ printf("Label selected for widget %d on %d.\n", objIDc,parentObjectID);
+
+
+ classDefinition.getProperty = (JSObjectGetPropertyCallback)jsXawLabelGetProperty;
+ classDefinition.setProperty = (JSObjectSetPropertyCallback)jsXawLabelSetProperty;
+
+ /********************************************************************************\
+ Call XAW to put xwindow instance up.
+ var Widget = new xawWidget(mywindow, "Widget", 0);
+ \********************************************************************************/
+
+
+ JSStringRef jstrArg = JSValueToStringCopy(ctx, arguments[1], exception);
+ size_t len = JSStringGetMaximumUTF8CStringSize(jstrArg);
+ char* text = (char*)malloc(len);
+
+ JSStringGetUTF8CString(jstrArg, text, len);
+ JSStringRelease(jstrArg);
+
+
+ myWidgets[objIDc] = XtVaCreateManagedWidget(widgetName, labelWidgetClass, myWidgets[parentObjectID], XtNlabel, text, NULL);
+
+ //Construct a class and create object out of it, send it back to JavaScript.
+ widgetObj = JSObjectMake(ctx, JSClassCreate(&classDefinition), NULL);
+ JSObjectSetPrivate(widgetObj, (void*)objIDc);
+
+ }else {
+ printf("Nothing selected for widget %d on %d.\n", objIDc,parentObjectID);
+ }
- myWidgets[objIDc] = createForm(&myWidgets[objIDc + 1], myWindow);
-
-
- r = JSValueMakeNumber(ctx, objIDc);
- JSObjectSetProperty(ctx, jobjThis, JSStringCreateWithUTF8CString("ID"), r, kJSPropertyAttributeNone, NULL);
+
+ //XtAddCallback( myWidgets[objIDc], XtNcallback, xawJsCallbackFunction, callinfo );
+
+ objIDc++;
+ return widgetObj;
+ }
+ return NULL;
+}
+#pragma GCC optimization_level 0
+void jsXawAppAddTimeOutCallback(XtPointer client)
+{
+ jsCallbackInfo* timeOutCallback = (jsCallbackInfo*)client;
+ assert(((*timeOutCallback).Context != NULL) && ((*timeOutCallback).Function != NULL) );
+ //printf("timeout.\n");
+ JSContextRef ctx = jsGlobalCtx;//timeOutCallback->Context does not work.
+ const JSObjectRef f = timeOutCallback->Function;
- objIDc ++;
+ if (JSValueIsString(ctx, f)) {
+ JSStringRef jstrSource = JSValueToStringCopy(ctx, f, NULL);
+ JSEvaluateScript(ctx, jstrSource, NULL, NULL, 1, NULL);
+ JSStringRelease(jstrSource);
+ }else {
+ JSObjectCallAsFunction(jsGlobalCtx, timeOutCallback->Function , NULL, 0,NULL,NULL);
+ }
+
+ free(timeOutCallback);
+ timeOutCallback = NULL;
- return r;
}
+#pragma GCC optimization_level reset
-static JSValueRef jsWindowShow(
- JSContextRef ctx,
- JSObjectRef jobj,
- JSObjectRef jobjThis,
- size_t argLen,
- const JSObjectRef args[],
- JSValueRef* jobjExp)
+static JSValueRef jsXawAppAddTimeOut(
+ JSContextRef ctx,
+ JSObjectRef jobj,
+ JSObjectRef jobjThis,
+ size_t argLen,
+ const JSObjectRef args[],
+ JSValueRef* jobjExp)
{
- //jobjThis.ID
- JSValueRef objID = JSObjectGetProperty(ctx, jobjThis, JSStringCreateWithUTF8CString("ID"), jobjExp);
- int windowID = (int)JSValueToNumber(ctx,objID,jobjExp);
- XtRealizeWidget( myWidgets[windowID] );
- XtAppMainLoop( app_con );
+ //Add heap area to accomodate a new Widget
+ jsCallbackInfo* timeOutCallback = (jsCallbackInfo *)malloc( sizeof(jsCallbackInfo));
+ if( myWidgets == NULL )//stop if empty pointer for some reason
+ {
+ printf( "Memory alloc failed!\n" );
+ return JSValueToObject(ctx, JSValueMakeNull(ctx), jobjExp);
+ }
+
+
+ if ( argLen == 2 && JSValueIsNumber(ctx,args[1]) ) {
+ memmove(timeOutCallback, &((jsCallbackInfo){ctx, args[0]}), sizeof(jsCallbackInfo));
+
+ JSObjectCallAsFunction(ctx, args[0], NULL, 0,NULL,NULL);
+ tmp = args[0];
+ XtAppAddTimeOut(app_con, (unsigned long)JSValueToNumber( ctx, args[1], jobjExp), (XtTimerCallbackProc)jsXawAppAddTimeOutCallback,(XtPointer)timeOutCallback);
+ }
+
+ return JSValueMakeUndefined(ctx);
}
void functionLoader_Gui(JSGlobalContextRef ctx, JSObjectRef jobjGlobal)
{
- JSObjectRef Window, Widget;
- printf("GUI has been enabled with this version.\nEnjoy!\n");
- classWrapper(ctx, jobjGlobal, "xawWindow", &Window);
-
- JSObjectRef Window_Name, Window_Direction;
- Window_Name = JSValueMakeString(ctx, JSStringCreateWithUTF8CString("undefined"));
- JSObjectSetProperty(ctx, Window, JSStringCreateWithUTF8CString("Name"), Window_Name, kJSPropertyAttributeNone, NULL);
- JSObjectSetProperty(ctx, Window, JSStringCreateWithUTF8CString("Direction"), Window_Direction, kJSPropertyAttributeNone, NULL);
-
- functionWrapper(ctx, Window, "SetProperty", (JSObjectCallAsFunctionCallback)jsWindowCreate);
- functionWrapper(ctx, Window, "Show", (JSObjectCallAsFunctionCallback)jsWindowShow);
-
- classWrapper(ctx, jobjGlobal, "xawControl", &Widget);
- functionWrapper(ctx, Widget, "Create", (JSObjectCallAsFunctionCallback)jsControlCreate);
- JSObjectRef Control_Name, Control_Type, Control_Parent, Control_Text, Control_Width, Control_Height, Control_Left, Control_Top, Control_Border, Control_Callback;
- Control_Name = JSValueMakeString(ctx, JSStringCreateWithUTF8CString("undefined"));
- JSObjectSetProperty(ctx, Widget, JSStringCreateWithUTF8CString("Name"), Control_Name, kJSPropertyAttributeNone, NULL);
- JSObjectSetProperty(ctx, Widget, JSStringCreateWithUTF8CString("Type"), Control_Type, kJSPropertyAttributeNone, NULL);
- JSObjectSetProperty(ctx, Widget, JSStringCreateWithUTF8CString("Parent"), Control_Parent, kJSPropertyAttributeNone, NULL);
- JSObjectSetProperty(ctx, Widget, JSStringCreateWithUTF8CString("Text"), Control_Text, kJSPropertyAttributeNone, NULL);
- JSObjectSetProperty(ctx, Widget, JSStringCreateWithUTF8CString("Width"), Control_Width, kJSPropertyAttributeNone, NULL);
- JSObjectSetProperty(ctx, Widget, JSStringCreateWithUTF8CString("Height"), Control_Height, kJSPropertyAttributeNone, NULL);
- JSObjectSetProperty(ctx, Widget, JSStringCreateWithUTF8CString("Left"), Control_Left, kJSPropertyAttributeNone, NULL);
- JSObjectSetProperty(ctx, Widget, JSStringCreateWithUTF8CString("Top"), Control_Top, kJSPropertyAttributeNone, NULL);
- JSObjectSetProperty(ctx, Widget, JSStringCreateWithUTF8CString("Border"), Control_Border, kJSPropertyAttributeNone, NULL);
- JSObjectSetProperty(ctx, Widget, JSStringCreateWithUTF8CString("Callback"), Control_Callback, kJSPropertyAttributeNone, NULL);
+ assert(sizeof( ( (void*)1 ) ) >= sizeof( (int)1 ) );
+ JSObjectRef Window, Form;
+ classWrapper(ctx, jobjGlobal, "xawWindow", &Window, jsXawWindowConstructor);\
+ classWrapper(ctx, jobjGlobal, "xawForm", &Form, jsXawFormConstructor);
+ classWrapper(ctx, jobjGlobal, "xawWidget", &Form, jsXawWidgetConstructor);
+
+ functionWrapper(ctx, jobjGlobal, "setTimeout", (JSObjectCallAsFunctionCallback)jsXawAppAddTimeOut);
+
}