-- Copyright 1993-1998, by the Cecil Project -- Department of Computer Science and Engineering, University of Washington -- See the LICENSE file for license information. (-- N O T E: 1) In this file, some codes were written in Xlib, Xt, and Xm. Regarding Xm ( or Motif ), I didn't use those special functions of motif-1.2.2 that are replacing older motif functions because it is easier to wrap around older motif libraries functions. 2) The string defines of most widget's properties are defined in the include/Xm/XmStrDefs.h file. The real string should be passed to XtSetArg and the string will be converted to C string and in X11/StringDefs.h 3) Most values used in XtSetArg are defines which can be found in Xm.h I will need to somehow represent them in cecil. --) (-- I N C L U D E S --) (** include_dir("${X_INCLUDE_DIRS}") **) (** lib_dir("${X_LIB_DIRS}") **) (** lib("-lXm") **) (** lib("-lXt") **) (** lib("-lX11") **) prim c_++: " #include #include #include #include #include #include // widgets include files #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef DEBUG_SUPPORT // the Cecil environment when entering an X primitive static EnvOOP last_currentEnv = GLOBAL_ENV; #ifdef ACCURATE_GC_LIB RegisteredGlobalOOP last_currentEnv_(last_currentEnv); #endif #else static EnvOOP last_currentEnv = NULL; #endif // cecil's X call back interface template typedef struct CallBackRecordStruct* CallBackRecordPtr; /* link all the call backs to a global variable, so that GC won't lose them */ CallBackRecordPtr call_backs = NULL; struct CallBackRecordStruct { OOP CallBack; OOP client_data; // the callback function should convert it // to appropriate type CallBackRecordPtr next; // keep all live call backs on a big linked list CallBackRecordStruct(OOP c, OOP cd) { CallBack = c; client_data = cd; /* prepend this new call back onto a big list */ next = call_backs; call_backs = this; #ifdef ACCURATE_GC_LIB register_global_oop(CallBack); register_global_oop(client_data); #endif } ~CallBackRecordStruct() { #ifdef ACCURATE_GC_LIB unregister_global_oop(CallBack); unregister_global_oop(client_data); #endif /* splice out this record from the list */ for (CallBackRecordPtr l = call_backs, p = NULL; l; p = l, l = l->next) { if (l == this) { if (p == NULL) { call_backs = next; } else { p->next = next; } return; } } fatalEnv(last_currentEnv, \"didn't find call back to free\"); } }; struct GenericCecilCallBackStruct { Widget widget; XtPointer client_data; XtPointer call_data; }; void GenericCallBackFunc( Widget widget, XtPointer client_data, XtPointer call_data); "; (-- S T A R T U P --) (-- M A I N W I N D O W S & S H E L L --) (---------------------------------------------------------------------------- create_main_wind Create the main application window using - parent widget - window name - width - height nb: shall I pass in arg and dislay/not option? -----------------------------------------------------------------------------) method create_main_wind(parentWidget:int, name:string, width:int, height:int):int (** return_type(int) **) { prim c_++: " Widget parent = (Widget)(parentWidget->asInt()); char* widgetName = AS_C_STRING(name); Widget mainWind; Arg args[10]; int n = 0; XtSetArg( args[n], XmNwidth, width->asInt()); n++; XtSetArg( args[n], XmNheight, height->asInt()); n++; XtSetArg( args[n], XmNshadowThickness, 4); n++; XtSetArg( args[n], XmNshowSeparator, True); n++; mainWind = XmCreateMainWindow( parent, widgetName, args, n); XtManageChild( mainWind); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt)mainWind)); #else BP( asTaggedInt( (wInt)mainWind)); #endif " } (-------------------------------------------------------------------------- create_new_shell Creates a new application shell w/ - window name --------------------------------------------------------------------------) method create_new_shell(name:string):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Widget newShell; Arg args[10]; int n = 0; XtSetArg(args[n],XmNtitle, AS_C_STRING(name) ); n++; newShell = XtCreateApplicationShell( AS_C_STRING(name), topLevelShellWidgetClass, args,n); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt)newShell)); #else BP( asTaggedInt( (wInt)newShell)); #endif " } (-- W I D G E T P R O P E R T I E S --) (---------------------------------------------------------------------------- make_x_arg Create an array of X arguments so that one can use to manipulate the widget's properties NB: need to be free after usage ----------------------------------------------------------------------------) method make_x_arg(maxArg:int):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Arg *arg = (Arg*)(GC_malloc(sizeof(Arg) * maxArg->asInt())); #ifdef DISPATCHERS RETURN(asTaggedInt((wInt)arg)); #else BP(asTaggedInt((wInt)arg)); #endif " } (---------------------------------------------------------------------------- add_x_arg Adds in the properties of the widget - it is just the wrapping function of motif's XtSetArg ----------------------------------------------------------------------------) method add_x_arg(args:int, pos:int, property:string, value:int):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Arg* arrayPtr = (Arg*)(args->asInt()); XtSetArg( arrayPtr[pos->asInt()], AS_C_STRING(property), value->asInt()); " } (---------------------------------------------------------------------------- set_x_value Set the widget's properties as defined in the args -----------------------------------------------------------------------------) method set_x_value( widget:int, args:int, n:int):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Widget whichWidget = (Widget)(widget->asInt()); Arg * argArray = (Arg*)(args->asInt()); XtSetValues(whichWidget, argArray, n->asInt()); " } (---------------------------------------------------------------------------- free_x_arg Free the memory which was allocated by MakeXArg ----------------------------------------------------------------------------) method free_x_arg(args:int):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif GC_free( (Arg*)(args->asInt()) ); " } (---------------------------------------------------------------------------- add_xm_string It is a fast way of setting the widget's "labelString" property. Returns a pointer to a string so that the caller can free up the string after the widget whose property is being set has been managed. NB: need to be freed after usage ----------------------------------------------------------------------------) method add_xm_string(args:int, pos:int, label:string):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Arg* arrayPtr = (Arg*)(args->asInt()); char * cString = AS_C_STRING(label); XmString motifString; motifString = XmStringCreateLtoR(cString, XmSTRING_DEFAULT_CHARSET); XtSetArg( arrayPtr[pos->asInt()], XmNlabelString, motifString); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt)motifString)); #else BP( asTaggedInt( (wInt)motifString)); #endif " } (-------------------------------------------------------------------------- free_xm_string Free up the memory occupied by a motif string that is no longer needed --------------------------------------------------------------------------) method free_xm_string(xmstring:int):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif XmStringFree( (XmString)xmstring->asInt()); " } (-------------------------------------------------------------------------- add_xm_string_arg A convenient function for setting up any widget's properties that require a motif string NB: Need to be free after usage --------------------------------------------------------------------------) method add_xm_string_arg(args:int, pos:int, property:string, cecil_string:string):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Arg* arrayPtr = (Arg*)(args->asInt()); char *c_string = AS_C_STRING(cecil_string); XmString motifString; motifString = XmStringCreateLtoR(c_string, XmSTRING_DEFAULT_CHARSET); XtSetArg(arrayPtr[pos->asInt()], AS_C_STRING(property), motifString); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt)motifString)); #else BP( asTaggedInt( (wInt)motifString)); #endif " } (-------------------------------------------------------------------------- text_set_string A cecil wrapping function for the motif's XmTextSetString fuction - which is used to change the content of a text widget --------------------------------------------------------------------------) method text_set_string( widgetID:int, buffer:string):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif XmTextSetString( (Widget)widgetID->asInt(), AS_C_STRING(buffer)); " } (---------------------------------------------------------------------------- change_label Change the text string of a label widget ----------------------------------------------------------------------------) method change_label(labelWidget:int, message:string):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Widget widget = (Widget)(labelWidget->asInt()); char *labelString = AS_C_STRING(message); XmString labelText; Arg args[10]; int n; n = 0; labelText = XmStringCreateLtoR( labelString, XmSTRING_DEFAULT_CHARSET); XtSetArg( args[n], XmNlabelString, labelText); n++; XtSetValues(widget, args, n); XmStringFree( labelText); " } (-- C A L L B A C K S --) (-------------------------------------------------------------------------- make_call_back Creates a C structure for the method's call back to be passed to the X server ------------------------------------------------------------------------) method make_call_back(call_back_func:&(any,any,any):any, call_back_arg:any):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif CallBackRecordPtr funcArg = new CallBackRecordStruct(call_back_func, call_back_arg); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt)funcArg)); #else BP( asTaggedInt( (wInt)funcArg)); #endif " } (---------------------------------------------------------------------------- free_call_back Frees the memory occupied by the call_back created using make_call_back ---------------------------------------------------------------------------) method free_call_back(call_back:int):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif CallBackRecordPtr cb = (CallBackRecordPtr)(call_back->asInt()); delete cb; " } (-------------------------------------------------------------------------- reall_quit Close the x session and frees all X's memory ---------------------------------------------------------------------------) method really_quit(widgetID:int, client_data:int, call_data:int):void { close_x_session(widgetID); } (--------------------------------------------------------------------------- confirm_quit Pops up a dialog box confirming the user's desiring to quit the application ----------------------------------------------------------------------------) method confirm_quit(widgetID:int, client_data:int, call_data:int):void { let var widget:int := 0; let display:int := 1; -- true widget = make_warning_dialog( client_data,"confirm_message", "Are you Sure?", make_call_back(&(widget:int, client_data:int, call_data:int){ really_quit(widget,client_data,call_data)},0), display); } (------------------------------------------------------------------------ print_choice This is for debugging purposes only. This is used as a callback for List widgets to determine what option is selected ------------------------------------------------------------------------) method print_choice(widgetID:int, client_data:int, call_data:int):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif char * printString; XmFileSelectionBoxCallbackStruct *fileStruct; fileStruct = (XmFileSelectionBoxCallbackStruct*)(call_data->asInt()); printf(\"inside princhoice\\n\"); XmStringGetLtoR( fileStruct->value, XmSTRING_DEFAULT_CHARSET, &printString); printf(\" you selected %s \\n\",printString); " } (-- M A N A G E R W I D G E T S --) (-------------------------------------------------------------------------- create_form Make a form widget using - parent - class name - X args - display/not -----------------------------------------------------------------------) method create_form( parentWidget:int, name:string, setArg:int, argN:int, display:int):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Widget formWidget; Arg *args = (Arg*)(setArg->asInt()); int n = argN->asInt(); formWidget = XtCreateManagedWidget( \"form\", xmFormWidgetClass, (Widget)(parentWidget->asInt()), args,n); if(display->asInt()) XtManageChild( formWidget); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt)formWidget)); #else BP( asTaggedInt( (wInt)formWidget)); #endif " } (----------------------------------------------------------------------------- make_row_column Create a row column widget with - parent widget id - class name, - X args - display/not -----------------------------------------------------------------------------) method make_row_column(parentWidget:int, name:string, setArg:int, argN:int, display:int):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Widget rowColumn; Arg *args = (Arg*)setArg->asInt(); int n = argN->asInt(); rowColumn = XmCreateRowColumn((Widget)parentWidget->asInt(), AS_C_STRING(name), args,n); if( display->asInt()) XtManageChild(rowColumn); #ifdef DISPATCHERS RETURN( asTaggedInt((wInt)rowColumn)); #else BP( asTaggedInt((wInt)rowColumn)); #endif " } (----------------------------------------------------------------------------- make_frame Make a frame widget ( it simply a wrapping motif function ) w/ - parent widget id - class name - X args - display/not -----------------------------------------------------------------------------) method make_frame(parentWidget:int, name:string, setArg:int, argN:int, display:int):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Widget frame; Arg *args = (Arg*)setArg->asInt(); int n = argN->asInt(); frame = XmCreateFrame((Widget)parentWidget->asInt(), AS_C_STRING(name), args,n); if( display->asInt()) XtManageChild(frame); #ifdef DISPATCHERS RETURN( asTaggedInt((wInt)frame)); #else BP( asTaggedInt((wInt)frame)); #endif " } (---------------------------------------------------------------------- make_dialog_form Creates a dialog form with - parent widget ID - class name - X properties argument - display/not widget flag ---------------------------------------------------------------------) method make_dialog_form( parentWidget:int, name:string, setArg:int, argN:int, display:int):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Widget formWidget; Arg *args = (Arg*)(setArg->asInt()); int n = argN->asInt(); formWidget = XmCreateFormDialog( (Widget)parentWidget->asInt(), AS_C_STRING(name), args,n); if( display->asInt()) XtManageChild(formWidget); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt)formWidget)); #else BP( asTaggedInt( (wInt)formWidget)); #endif " } (--------------------------------------------------------------------------- make_dialog_bulletin_board Creates a type of dialog window that allows other widgets to attach to it. Uses - parent widget id - class name - X properties argument - display/do not widget flag ---------------------------------------------------------------------------) method make_dialog_bulletin_board( parentWidget:int, name:string, setArg:int, argN:int, display:int):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Widget bBoardWidget; Arg *args = (Arg*)(setArg->asInt()); int n = argN->asInt(); bBoardWidget = XmCreateBulletinBoardDialog( (Widget)parentWidget->asInt(), AS_C_STRING(name), args,n); if( display->asInt()) XtManageChild(bBoardWidget); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt)bBoardWidget)); #else BP( asTaggedInt( (wInt)bBoardWidget)); #endif " } (-- H I G H L E V E L W I D G E T S --) (---------------------------------------------------------------------------- make_label Creates a label widget given - parent widget - class name - text string ( what should the label be ) - X args - boolean of whether it should be display ( manage ) or not -----------------------------------------------------------------------------) method make_label(parentWidget:int, name:string, message:string, setArg:int, argN:int, display:int):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif // conversion Widget parent = (Widget)(parentWidget->asInt()); char* widgetName = AS_C_STRING(name); char* labelString = AS_C_STRING(message); Arg* argList = (Arg*)( setArg->asInt()); int argListN = argN->asInt(); Widget labelWidget; XmString labelText; labelText = XmStringCreateLtoR( labelString, XmSTRING_DEFAULT_CHARSET); XtSetArg( argList[argListN], XmNlabelString, labelText); argListN++; labelWidget = XtCreateManagedWidget( widgetName, xmLabelWidgetClass, parent, argList, argListN); XmStringFree( labelText); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt)labelWidget)); #else BP( asTaggedInt( (wInt)labelWidget)); #endif if( !(display->asInt()) ) XtUnmanageChild( labelWidget ); " } (---------------------------------------------------------------------------- make_file_selection Create a file selection widget from the following information - parent widget - class name - X args - call back functions for file selection - display or not display the widget -----------------------------------------------------------------------------) method make_file_selection(parentWidget:int, name:string, setArg:int, argN:int, call_back:int,display:int):int (** return_type(int) **) { prim c_++:" #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif // conversion Widget parent = (Widget)(parentWidget->asInt()); char* widgetName = AS_C_STRING(name); Arg* argList = (Arg*)( setArg->asInt()); CallBackRecordPtr funcArg = (CallBackRecordPtr)( call_back->asInt()); Widget fileSelectWidget; // the resulting widget fileSelectWidget = XmCreateFileSelectionDialog( parent,widgetName,0,0); XtAddCallback(fileSelectWidget, XmNokCallback, GenericCallBackFunc, (XtPointer)funcArg); if( display->asInt() ) XtManageChild( fileSelectWidget); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt) fileSelectWidget)); #else BP( asTaggedInt( (wInt) fileSelectWidget)); #endif " } (---------------------------------------------------------------------------- make_prompt_dialog Create a prompt dialog with - parent widget - class name - prompt message - call back functions - display widget / not note: i may need to pass in args -----------------------------------------------------------------------------) method make_prompt_dialog(parentWidget:int, name:string, message:string, call_back:int, display:int):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Arg args[10]; int n; Widget promptWidget, okWidget; XmString motifString; CallBackRecordPtr funcArg = (CallBackRecordPtr)( call_back->asInt()); motifString = XmStringCreateLtoR( AS_C_STRING(message), XmSTRING_DEFAULT_CHARSET); n = 0; XtSetArg( args[n], XmNselectionLabelString, motifString); n++; promptWidget = XmCreatePromptDialog( (Widget)parentWidget->asInt(), AS_C_STRING(name), args,n); XtAddCallback( promptWidget, XmNokCallback, GenericCallBackFunc, (XtPointer)funcArg); if( display->asInt()) XtManageChild( promptWidget); XmStringFree( motifString); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt)promptWidget)); #else BP( asTaggedInt( (wInt)promptWidget)); #endif " } (---------------------------------------------------------------------------- make_warning_dialog Create a popup warning message box using - parent widget - class name - warning message - okay class back routine - display/not nb: should i put in args too? -----------------------------------------------------------------------------) method make_warning_dialog(parentWidget:int, name:string, message:string, call_back:int, display:int):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Widget parent = (Widget)(parentWidget->asInt()); char* widgetName = AS_C_STRING(name); char* warnMessage = AS_C_STRING(message); XmString messageStr; Arg args[10]; int n = 0; messageStr = XmStringCreateLtoR( warnMessage, XmSTRING_DEFAULT_CHARSET); CallBackRecordPtr funcArg = (CallBackRecordPtr)( call_back->asInt()); // need to check if malloc was successful Widget warningWidget; // the resulting widget Widget deadWidget; XtSetArg(args[n], XmNmessageString, messageStr);n++; warningWidget = XmCreateWarningDialog( parent, widgetName, args, n); // need to write fucntion to remove widget deadWidget = XmMessageBoxGetChild( warningWidget, XmDIALOG_HELP_BUTTON); XtUnmanageChild( deadWidget); XtAddCallback( warningWidget, XmNokCallback, GenericCallBackFunc, (XtPointer)funcArg); if( display->asInt()) XtManageChild( warningWidget); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt)warningWidget)); #else BP( asTaggedInt( (wInt)warningWidget)); #endif " } (-------------------------------------------------------------------------- make_toggle_button Creates a toggle button using - parent widget - class name - X args - call back for toggle button clicked - display/not -------------------------------------------------------------------------) method make_toggle_button(parentWidget:int, name:string, setArg:int, argN:int, call_back:int, display:int):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Widget toggle; Arg *args = (Arg*)setArg->asInt(); int n = argN->asInt(); CallBackRecordPtr funcArg = (CallBackRecordPtr)( call_back->asInt()); toggle = XmCreateToggleButton( (Widget)parentWidget->asInt(), \"Toggle\", args,n); if( display->asInt()) XtManageChild(toggle); XtAddCallback(toggle, XmNvalueChangedCallback, GenericCallBackFunc, (XtPointer)funcArg); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt)toggle)); #else BP( asTaggedInt( (wInt)toggle)); #endif " } (---------------------------------------------------------------------------- make_scrolled_list Create a sroll list widget with - parent widget ID - class name - scroll selection call back routine - display/not display scroll list -----------------------------------------------------------------------------) method make_scrolled_list(parentWidget:int, name:int, setArg:int, argN:int, call_back:int,display:int):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Widget listWidget; Arg *args = (Arg*)(setArg->asInt()); int n = argN->asInt(); CallBackRecordPtr funcArg; funcArg = (CallBackRecordPtr)( call_back->asInt()); XtSetArg( args[n], XmNitemCount, 0); n++; XtSetArg( args[n], XmNselectionPolicy, XmSINGLE_SELECT);n++; listWidget = XmCreateScrolledList((Widget)parentWidget->asInt(), AS_C_STRING(name), args,n); if( display->asInt() ) XtManageChild( listWidget); XtAddCallback( listWidget, XmNsingleSelectionCallback, GenericCallBackFunc, (XtPointer)funcArg); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt) listWidget)); #else BP( asTaggedInt( (wInt) listWidget)); #endif " } (---------------------------------------------------------------------------- add_to_scrolled_list Add itmes to the scroll list -----------------------------------------------------------------------------) method add_to_scrolled_list( listWidget:int, message:string, position:int):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif XmString motifString; motifString = XmStringCreateLtoR( AS_C_STRING(message), XmSTRING_DEFAULT_CHARSET); XmListAddItemUnselected( (Widget)listWidget->asInt(), motifString, position->asInt()); XmStringFree( motifString); " } (----------------------------------------------------------------------- make_scrolled_text Create a text window with scrolling using - parent widget id - class name - X properties argument - selection call back routine - display/not display widget ----------------------------------------------------------------------) method make_scrolled_text(parentWidget:int, name:int, setArg:int, argN:int, call_back:int, display:int):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Widget ScrollText; Arg *args = (Arg*)(setArg->asInt()); int n = argN->asInt(); CallBackRecordPtr funcArg; funcArg = (CallBackRecordPtr)( call_back->asInt()); ScrollText = XmCreateScrolledText( (Widget)parentWidget->asInt(), AS_C_STRING(name),args,n); if( display->asInt()) XtManageChild(ScrollText); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt) ScrollText)); #else BP( asTaggedInt( (wInt) ScrollText)); #endif " } (---------------------------------------------------------------------------- make_button Creates a button that - parentWidget as parent - name as class name - calls call_back when it is pushed - option to display/not -----------------------------------------------------------------------------) method make_button(parentWidget:int, name:string, setArg:int, argN:int, call_back:int,display:int):int (** return_type(int) **) { prim c_++:" #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif // conversion Widget parent = (Widget)(parentWidget->asInt()); char* widgetName = AS_C_STRING(name); Arg *args = (Arg*)(setArg->asInt()); int n = argN->asInt(); CallBackRecordPtr funcArg = (CallBackRecordPtr)(call_back->asInt()); // need to check if malloc was successful Widget pushWidget; // the resulting widget pushWidget = XtCreateManagedWidget( widgetName, xmPushButtonWidgetClass, parent, args,n); XtAddCallback( pushWidget, XmNactivateCallback, GenericCallBackFunc, (XtPointer)funcArg); if( ! (display->asInt())) XtUnmanageChild(pushWidget); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt)pushWidget)); #else BP( asTaggedInt( (wInt)pushWidget)); #endif " } (-- C A L L B A C K S --) (---------------------------------------------------------------------------- GenericCallBackFunc This is a generic function for most callbacks. What this does is act as a C call back function which wil then call the real Cecil wrapped call back function. ----------------------------------------------------------------------------) prim c_++: " void GenericCallBackFunc( Widget widget, XtPointer client_data, XtPointer call_data) { CallBackRecordPtr cecilCallBackRec = (CallBackRecordPtr)client_data; // OOP widgetID = asTaggedInt( (wInt)widget); // OOP callData = asTaggedInt( (wInt)client_data); #ifdef DEBUG_SUPPORT EnvOOP currentEnv = last_currentEnv; #else EnvOOP currentEnv = GLOBAL_ENV; #endif OOP evalResult; ReturnCode returnCode; #ifdef DISPATCHERS OOP returnArg; SEND_NO_PROP(evalResult, returnCode, returnArg, eval,0,4, (cecilCallBackRec->CallBack, asTaggedInt((wInt)widget), cecilCallBackRec->client_data, asTaggedInt((wInt)call_data)), \"1#GenericCallBackFunc(a,b,c)\"); #else SEND_NO_PROP(evalResult, returnCode, eval,0,4, (cecilCallBackRec->CallBack, asTaggedInt((wInt)widget), cecilCallBackRec->client_data, asTaggedInt((wInt)call_data)), \"1#GenericCallBackFunc(a,b,c)\"); #endif if (returnCode != NRM_RET) { fatalEnv(currentEnv, \"cannot handle non-local return from X call-back function\"); } } "; (-- X S E S S I O N --) (---------------------------------------------------------------------------- init_x_session Before we can use any X functions, an X session must be initialized - sessionName: the name of this session - appName: name of this application ----------------------------------------------------------------------------) method init_x_session(sessionName:string, appName:string):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Widget parent; char *argv[1]; int n =1; argv[0] = AS_C_STRING(appName); parent = XtInitialize( argv[0], // (char*)(sessionName->asInt()), AS_C_STRING(sessionName), NULL, 0, &n, argv); #ifdef DISPATCHERS RETURN(asTaggedInt((wInt)parent)); #else BP(asTaggedInt((wInt)parent)); #endif " } (------------------------------------------------------------------------------ close_x_session Close the X application's session. This will in turn free some ( but not user's allocated memory ) to the system. -------------------------------------------------------------------------------) method close_x_session(widgetId:int):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif XtCloseDisplay( XtDisplay( (Widget)widgetId->asInt())); " } (------------------------------------------------------------------------------ destroy_widget Kill a widget and frees the memory used by the widget ------------------------------------------------------------------------------) method destroy_widget(widgetId:int):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif XtDestroyWidget((Widget)widgetId->asInt()); " } (------------------------------------------------------------------------------ start_application This function simply starts the event loop. NOTE: Shouldn't use this in cecil. If you do once you close the X session, there is no way getting back to the Cecil prompt. Use manual_event_dispatch instead -------------------------------------------------------------------------------) method start_application(parentWidget:int):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif XtMainLoop(); " } (----------------------------------------------------------------------------- manual_event_dispatch This functions starts the X events query and dispatch it. -----------------------------------------------------------------------------) method manual_event_dispatch():void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif XEvent event; XtNextEvent(&event); XtDispatchEvent(&event); " } (------------------------------------------------------------------------------ realize_widget Simply Cecil's wrap for XtRealizeWidget -----------------------------------------------------------------------------) method realize_widget( shellWidget:int):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif XtRealizeWidget( (Widget)shellWidget->asInt()); " } (----------------------------------------------------------------------------- un_realize_widget Simply the Cecil's wrap for XtUnrealizeWidget -----------------------------------------------------------------------------) method un_realize_widget(shellWidget:int):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif XtUnrealizeWidget( (Widget)shellWidget->asInt()); " } (------------------------------------------------------------------------------ manage_widget Cecil's wrap for XtManageChild ------------------------------------------------------------------------------) method manage_widget( widget:int):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif XtManageChild( (Widget)widget->asInt()); " } (------------------------------------------------------------------------------- un_manage_widget Cecil's wrap for XtUnmanageChild ------------------------------------------------------------------------------) method un_manage_widget( widget:int):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif XtUnmanageChild( (Widget)widget->asInt()); " } (------------------------------------------------------------------------------- get_parent Returns the parent of the current widget -------------------------------------------------------------------------------) method get_parent(widget:int):int (** return_type(int) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif Widget parentWidget = XtParent((Widget)widget->asInt()); #ifdef DISPATCHERS RETURN( asTaggedInt( (wInt)parentWidget)); #else BP( asTaggedInt( (wInt)parentWidget)); #endif " } -- raise the object's window above other windows method raise_window(widget:int):void (** return_type(void) **) { prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif XRaiseWindow(XtDisplay((Widget)widget->asInt()), XtWindow((Widget)widget->asInt())); " } method retrieve_object_index(call_data:int):string(** return_type(i_vstring) **){ prim c_++: " #ifdef DEBUG_SUPPORT last_currentEnv = currentEnv; // for debugging purposes #endif char * listString; XmFileSelectionBoxCallbackStruct *fileStruct; OOP cecilString; fileStruct = (XmFileSelectionBoxCallbackStruct*)(call_data->asInt()); XmStringGetLtoR( fileStruct->value, XmSTRING_DEFAULT_CHARSET, &listString); cecilString = NEW_STRING(listString); #ifdef DISPATCHERS RETURN(cecilString); #else BP(cecilString); #endif " }