Exemple #1
0
static int
add_user_handler(ABObj obj, ABObj module,
                 ISTRING handler, AB_WHEN when)
{
    int                 retval = 0;
    ABObj               project = NULL;
    ABObj               action = NULL;

    if (handler == NULL)
    {
        return 0;
    }
    project = obj_get_project(module);

    /*
     * With "callbacks," the to field is irrelevant.  The target is generally
     * whatever widget calls the callback, so we set the "to" field to NULL,
     * so that this action may be used by multiple widgets.  I.e., if the
     * function type, name and to fields match, an action will be shared.
     */
    action = obj_create(AB_TYPE_ACTION, NULL);
    obj_set_func_type(action, AB_FUNC_USER_DEF);
    obj_set_func_name(action, istr_string(handler));
    obj_set_arg_type(action, AB_ARG_VOID_PTR);
    action->info.action.to = NULL;

    obj_set_from(action, obj);
    obj_set_when(action, when);

    install_action(obj, module, action);
    return 0;
}
Exemple #2
0
static int
write_main_session_restore(
    GenCodeInfo	genCodeInfo, 
    ABObj	project
)
{
    File	codeFile;

    if (!genCodeInfo || !project)
	return (0);

    codeFile = genCodeInfo->code_file;

    if (abmfP_proj_needs_session_restore(project))
    {
        AB_TRAVERSAL	trav;
	ABObj		action;
	char		*ss_restore_CB_name = NULL;

        abio_puts(codeFile,"\n");
        abio_puts(codeFile,"if (dtb_app_resource_rec.session_file)\n");
        abio_puts(codeFile,"{\n");

	if (!obj_is_project(project))
	    project = obj_get_project(project);

	/*
	 * Search for session restore callback in project
	 * action list
	 */
    	for (trav_open(&trav, project, AB_TRAV_ACTIONS);
             (action = trav_next(&trav)) != NULL;)
    	{
	    switch(obj_get_when(action))
	    {
		case AB_WHEN_SESSION_RESTORE:
		    /*
		     * Remember session restore callback if found
		     */
		    ss_restore_CB_name = obj_get_func_name(action);
		    break;
		default:
		    break;
	    }
	}
	trav_close(&trav);

	abio_printf(codeFile, 
	"    dtb_set_client_session_restoreCB((DtbClientSessionRestoreCB)%s);\n",
		ss_restore_CB_name ? ss_restore_CB_name : "NULL");

        abio_puts(codeFile,
	"    (void)dtb_session_restore(toplevel, dtb_app_resource_rec.session_file);\n");
        abio_puts(codeFile,"}\n");

        abio_puts(codeFile,"\n");
    }

    return (0);
}
Exemple #3
0
void
proj_delete_objects
(
    AB_OBJ	*obj
)
{
    AB_OBJ		*project;
    Vwr			viewer;
    ViewerMethods	*m;

    if (!Proj_viewer)
	return;

    /*
     * Get project object
     */
    project = obj_get_project(obj);

    viewer = Proj_viewer;

    m = viewer->methods;
    (*m->remove_tree)(viewer, obj);

    /*
     * Erase/redraw viewer
     */
    if (viewer->ui_handle)
    {
        erase_viewer(viewer);
        draw_viewer(viewer);
    }
}
Exemple #4
0
/*
 * Object destroy callback
 * Remove viewer nodes from project organizer when module is destroyed.
 */
static int
projP_obj_destroyOCB(
    ObjEvDestroyInfo    info
)
{
    ABObj	obj = info->obj;

    if (!obj || (!obj_is_module(obj) && !obj_is_project(obj)))
	return (0);

    if (obj->projwin_data)
    {
	ABObj	proj = obj_get_project(obj);

	if (!proj)
	    return (0);

	/*
	 * If the project is being destroyed, skip if the object passed in is
	 * not the project itself. We do this so that proj_delete_objects() is
	 * not called for every module in the project. Instead, it is called
	 * just once for the project.
	 */
	if (obj_has_flag(proj, BeingDestroyedFlag) && !obj_is_project(obj))
	    return (0);

        proj_delete_objects(obj);
    }

    return (0);
}
Exemple #5
0
STRING
abmfP_get_action_name(ABObj action)
{
    static char         name[256];
    STRING		parent_name = (STRING) NULL;
    ABObj               from = NULL, parent = NULL;
    STRING		tmpName = NULL;
    *name = 0;

    from = obj_get_from(action);
    if (action->info.action.auto_named && (from != NULL))
    {
        /* If the source object is the project,
         * then this is an "Application" connection.
	 * This probably won't happen because right
	 * now "Application" connections can only be
	 * of type AB_FUNC_USER_DEF (which means auto-
	 * named is FALSE).
         */
        if (obj_is_project(from))
	{
	    parent = obj_get_project(action);
	    parent_name = (STRING) util_malloc(
				strlen(obj_get_name(parent)) 
				+ APP_PREFIX_LEN + 1);
	    strcpy(parent_name, obj_get_name(parent));
	    strcat(parent_name, APP_PREFIX);
	}
	else
	{
            parent = obj_get_module(from);
            parent_name = obj_get_name(parent);
	}

        if (!util_strempty(parent_name) &&
            !util_strempty(obj_get_name(from)))
	{
	    sprintf(name, "%s_%s%s",
		    parent_name,
		    obj_get_name(from),
		    obj_get_func_name_suffix(action));
	}

        if (obj_is_project(from))
        {
	    util_free(parent_name);
	}
    }
    else
    {
	if ((tmpName = obj_get_func_name(action)) != NULL)
	{
	    sprintf(name, "%s", tmpName);
	}
    }

    return (name[0] == 0 ? NULL : name);
}
Exemple #6
0
static int
write_map_window(
			GenCodeInfo	genCodeInfo, 
			ABObj 		window,
			BOOL		show
)
{
    File	codeFile = genCodeInfo->code_file;
    ABObj	project = obj_get_project(window);
    ABObj	proj_root_window = abmfP_get_root_window(project);
    ABObjRec	showActionRec;
    ABObj	showAction = &showActionRec;
    ABObj	winParent = NULL;
    char	winParentName[1024];
    obj_construct(showAction, AB_TYPE_ACTION, NULL);
    *winParentName = 0;

    obj_set_from(showAction, NULL);
    obj_set_to(showAction, window);
    obj_set_func_type(showAction, AB_FUNC_BUILTIN);
    obj_set_func_builtin(showAction, AB_STDACT_SHOW);

    winParent = obj_get_win_parent(window);
    if (winParent == NULL)
    {
	sprintf(winParentName, "%s()", abmfP_lib_get_toplevel_widget->name);
    }
    else
    {
        strcpy(winParentName, abmfP_get_c_name(genCodeInfo, winParent));
    }
    abio_printf(codeFile, "%s(%s, %s);\n",
	abmfP_get_init_proc_name(window),
	abmfP_get_c_struct_ptr_name(genCodeInfo, window),
	winParentName);

    if (show)
    	abmfP_write_builtin_action(genCodeInfo, showAction, FALSE);

    obj_destruct(showAction);
    return 0;
}
Exemple #7
0
void
proj_add_objects
(
    AB_OBJ	*obj
)
{
    AB_OBJ		*project;
    Vwr			viewer;
    ViewerMethods	*m;

    if (!Proj_viewer)
	return;
/*
        Proj_viewer = create_proj_struct();
*/

    /*
     * Get project object
     */
    project = obj_get_project(obj);

    viewer = Proj_viewer;

    m = viewer->methods;
    (*m->insert_tree)(viewer, obj);

    /*
     * Erase/redraw viewer
     */
    if (viewer->ui_handle)
    {
	/*
	 * Don't need to erase viewer as a new node is 
	 * added to end of the array of nodes in project window
        erase_viewer(viewer);
	 */
        draw_viewer(viewer);
    }
}
Exemple #8
0
/*
 * Write the callback proc stub file.
 */
int
abmfP_write_stubs_c_file(
    GenCodeInfo genCodeInfo,
    STRING codeFileName,
    ABObj module
)
{
    File                codeFile = genCodeInfo->code_file;
    STRING              errmsg = NULL;
    ABObj               win_obj = NULL;
    ABObj               project = obj_get_project(module);
    char		moduleHeaderFileName[MAX_PATH_SIZE];
    char		moduleName[MAX_PATH_SIZE];

    /*
     * Write file header.
     */

    abmfP_write_user_header_seg(genCodeInfo);
    abio_puts(codeFile, nlstr);

    sprintf(moduleName, "module %s", obj_get_name(module));
    abmfP_write_file_header(
        genCodeInfo,
        codeFileName,
        FALSE,
        moduleName,
        util_get_program_name(),
        ABMF_MODIFY_USER_SEGS,
        " * Contains: Module callbacks and connection functions"
    );


    /*
     * Write includes.
     */
    strcpy(moduleHeaderFileName, abmfP_get_ui_header_file_name(module));
    abmfP_write_c_system_include(genCodeInfo, "stdio.h");
    abmfP_write_c_system_include(genCodeInfo, "Xm/Xm.h");
    abmfP_write_c_local_include(genCodeInfo,
                                abmfP_get_utils_header_file_name(module));

    /*
     * Include project file if i18n is enabled. This file
     * is needed for the message catalog stuff
     */
    if (genCodeInfo->i18n_method == ABMF_I18N_XPG4_API)
        abmfP_write_c_local_include(genCodeInfo,
                                    abmfP_get_project_header_file_name(project));
    abmfP_write_c_local_include(genCodeInfo, moduleHeaderFileName);


    /*
     * Write out includes for modules with connection targets
     */
    {
        StringListRec       connIncludes;
        int                 i = 0;
        int                 num_strings = 0;
        strlist_construct(&connIncludes);

        strlist_add_str(&connIncludes, moduleHeaderFileName, NULL);
        abmfP_get_connect_includes(&connIncludes, module);
        num_strings = strlist_get_num_strs(&connIncludes);
        if (num_strings > 1)		/* start at 1 - skip this_ui.h */
        {
            abio_puts(codeFile, nlstr);
            abmfP_write_c_comment(genCodeInfo, FALSE,
                                  "Header files for cross-module connections");
        }
        for (i = 1; i < num_strings; ++i)
        {
            abio_printf(codeFile, "#include %s\n",
                        strlist_get_str(&connIncludes, i, NULL));
        }

        strlist_destruct(&connIncludes);
    }
    abio_puts(codeFile, nlstr);

    abmfP_write_user_file_top_seg(genCodeInfo);
    abio_puts(codeFile, nlstr);

    if (write_action_functions(genCodeInfo, module) != OK)
        return ERROR;

    abmfP_write_user_file_bottom_seg(genCodeInfo);
    return OK;
}
Exemple #9
0
/*
 * The objName parameter can be a simple name, or can be of the form
 * module.name or module::name.  The separator can have an arbitrary
 * amount of white space on either side of it.  For example, these are
 * all legal names:
 *
 *	"my_object"
 *	"my_module::your_object"
 *	"your_module.your_object
 *	"your_module .  her_object"
 *	"his_module   ::   that_object"
 *
 * If the object name is simple (without "." or "::"), searchFirstObj
 * is searched, and then the module is searched for an object with the
 * given name.
 *
 * If the name is complex, the module and object name
 * are found, relative to the project.
 */
ABObj
obj_scoped_find_by_name(ABObj searchFirstObj, STRING objName)
{
    ABObj	obj= NULL;
    char	*dotPtr= NULL;
    char	*moduleNamePtr= NULL;
    char	*objNamePtr= objName;
    char	*moduleNameEndPtr = NULL;
    int		moduleNameEndChar = -1;
    char	nameBuf[1024];
    /* printf("obj_scoped_find_by_name(%s[%s])\n",
    obj_get_safe_name(searchFirstObj, nameBuf, 1024),
    util_strsafe(objName)); */

    if ((dotPtr= strchr(objName, '.')) != NULL)
    {
        moduleNamePtr= objName;
        objNamePtr= dotPtr+1;
    }
    else if ((dotPtr= strstr(objName, "::")) != NULL)
    {
        moduleNamePtr= objName;
        objNamePtr= dotPtr+2;
    }

    /*
     *  Remove white space on either side of the separator
     */
    if (dotPtr != NULL)
    {
        /* put a 0 at the end of the module name */
        for (moduleNameEndPtr = dotPtr-1;
                ((moduleNameEndPtr > objName) && isspace(*moduleNameEndPtr)); )
        {
            --moduleNameEndPtr;
        }
        if (moduleNameEndPtr < dotPtr)
        {
            ++moduleNameEndPtr; /* point one *after* last char in name */
        }
        moduleNameEndChar = *moduleNameEndPtr;
        *moduleNameEndPtr = 0;
    }
    while (((*objNamePtr) != 0) && (isspace(*objNamePtr)))
    {
        ++objNamePtr;
    }

    /*
     * We now have the module and object name, so find the object.
     */
    if (moduleNamePtr == NULL)
    {
        /*
         * This is a simple name
         */
        obj= obj_find_by_name(searchFirstObj, objNamePtr);

        /*
         * It doesn't exist in the scoping object, so look at the module
         */
        if ((obj == NULL) && (!obj_is_module(searchFirstObj)))
        {
            ABObj module = obj_get_module(searchFirstObj);
            if (module != NULL)
            {
                obj = obj_find_by_name(module, objNamePtr);
            }
        }
    }
    else
    {
        /*
         * Module name has been specified
         */
        ABObj	objProject= obj_get_project(searchFirstObj);
        ABObj	objModule= NULL;

        if (objProject != NULL)
        {
            objModule = obj_find_module_by_name(objProject, moduleNamePtr);
        }
        if (objModule != NULL)
        {
            obj= obj_find_by_name(objModule, objNamePtr);
        }
    }

epilogue:
    /* replace the 0 we inserted with the char that was there */
    if (moduleNameEndPtr != NULL)
    {
        *moduleNameEndPtr= moduleNameEndChar;
    }
    return obj;
}
Exemple #10
0
/*
 * Finds the target matching the given description, creating it if necessary.
 * 
 * Assumes: strings are pointers to allocated space. Sets strings to NULL, if
 * the values are used.
 * 
 * Assumes that obj may not be in the object tree yet, and may return it as the
 * target.
 */
static ABObj
find_or_create_target(
			ABObj	obj, 
			ABObj	module,
		      	ISTRING	interface_name,
                      	ISTRING	parent_name,
                      	ISTRING	obj_name,
                      	ISTRING	item_label
)
{
    ABObj               target = NULL;	/* the real thing, baby! */
    ABObj		target_project = NULL;
    char		target_interface_file[MAXPATHLEN+1];
    char		target_interface_name[GIL_MAX_NAME_SIZE];
    ABObj		target_module = NULL;
    char		target_parent_name[GIL_MAX_NAME_SIZE];
    ABObj		target_parent = NULL;
    char		target_obj_name[GIL_MAX_NAME_SIZE];
    ABObj		target_obj = NULL;
    char		target_item_label[GIL_MAX_NAME_SIZE];
    ABObj		target_item = NULL;
    AB_TRAVERSAL	trav;
    *target_interface_file = 0;
    *target_interface_name = 0;
    *target_parent_name = 0;
    *target_obj_name = 0;
    *target_item_label = 0;
   
    /* must have object name */
    if (debugging()) 
    {
	assert(   (obj_name != NULL)
	       && (obj_is_project(module) || obj_is_module(module)));
    }

    if (obj_is_project(module))
    {
	/* The first string must be an interface file name */
	if (interface_name != NULL)
	{
	    util_strncpy(target_interface_file, istr_string(interface_name),
			GIL_MAX_NAME_SIZE);
	    if (parent_name != NULL)
	    {
		util_strncpy(target_parent_name, istr_string(parent_name),
			GIL_MAX_NAME_SIZE);
	    }
	}
	else if (parent_name != NULL)
	{
	    util_strncpy(target_interface_file, istr_string(parent_name),
			GIL_MAX_NAME_SIZE);
	}
	else
	{
	    abil_print_load_err(ERR_WANT_FULL_NAME);
	    goto epilogue;
	}

	/* derive the name from the file name */
	strcpy(target_interface_name, target_interface_file);
	{
	    int		len = strlen(target_interface_name);
	    if (    (len >= 2) 
		&& (   util_streq(&(target_interface_name[len-2]), ".G")
		    || util_streq(&(target_interface_name[len-2]), ".P")))
	    {
		target_interface_name[len-2] = 0;
	    }
	}

	util_strncpy(target_obj_name, istr_string(obj_name), 
			GIL_MAX_NAME_SIZE);
	if (item_label != NULL)
	{
	    util_strncpy(target_item_label, istr_string(item_label), 
			GIL_MAX_NAME_SIZE);
	}
    }
    else 	/* ! obj_is_project() */
    {
        if (parent_name != NULL)
        {
            /* we have parent name and object name */
            util_strncpy(target_parent_name, istr_string(parent_name), 
			GIL_MAX_NAME_SIZE);
        }

	util_strncpy(target_obj_name, istr_string(obj_name), 
			GIL_MAX_NAME_SIZE);
        if (item_label != NULL)
        {
            /* we have object name and item_label */
            util_strncpy(target_item_label, istr_string(item_label),
		GIL_MAX_NAME_SIZE);
        }
     }

     /*
      * We've got the name broken down into the appropriate pieces.
      * Now find the actual target.
      */
    /*util_dprintf(3, "finding: module:'%s' parent:'%s' obj:'%s' item:'%s'\n",
	target_interface_name, target_parent_name, 
	target_obj_name, target_item_label);*/
    

    /*
     * Find target project
     */
    target_project = obj_get_project(module);

    /*
     * Find target module
     */
    if (util_strempty(target_interface_name))
    {
	target_module = module;
    }
    else
    {
	/* find specified intefarce (module) */
	for (trav_open(&trav, target_project, AB_TRAV_MODULES);
		(target_module = trav_next(&trav)) != NULL; )
	{
	    if (   (target_module != target_project)
		&& (util_streq(
			obj_get_file(target_module), target_interface_file)))
	    {
		break;
	    }
	}
	trav_close(&trav);
	if (target_module == NULL)
	{
	    target_module = obj_create(AB_TYPE_MODULE, target_project);
	    obj_set_is_defined(target_module, FALSE);
	    obj_set_file(target_module, target_interface_file);
	    obj_set_name(target_module, target_interface_name);
	}
    }

    /*
     * Find target parent
     */
    if (util_strempty(target_parent_name))
    {
	target_parent = target_module;
    }
    else
    {
	for (trav_open(&trav, target_module, 
			AB_TRAV_ALL | AB_TRAV_MOD_PARENTS_FIRST);
	    	(target_parent = trav_next(&trav)) != NULL; )
	{
	    if (   (target_parent != target_module)
		&& (util_streq(
			obj_get_name(target_parent), target_parent_name)))
	    {
		break;
	    }
	}
	trav_close(&trav);
	if (target_parent == NULL)
	{
	    target_parent = obj_create(AB_TYPE_UNDEF, target_module);
	    obj_set_is_defined(target_parent, FALSE);
	    obj_set_file(target_parent, target_interface_file);
	    obj_set_name(target_parent, target_parent_name);
	}
    }

    /*
     * Find target obj
     */
    for (trav_open(&trav, target_parent,
			AB_TRAV_ALL | AB_TRAV_MOD_PARENTS_FIRST);
		(target_obj = trav_next(&trav)) != NULL; )
    {
	if (   (target_obj != target_parent)
	   && util_streq(target_obj_name, obj_get_name(target_obj)))
	{
	    break;
	}
    }
    trav_close(&trav);
    if (target_obj == NULL)
    {
        target_obj = obj_create(AB_TYPE_UNDEF, target_parent);
        obj_set_is_defined(target_obj, FALSE);
        obj_set_file(target_obj, target_interface_file);
        obj_set_name(target_obj, target_obj_name);
    }

    /*
     * Find item
     */
    if (util_strempty(target_item_label))
    {
	target_item = NULL;
    }
    else
    {
	for (trav_open(&trav, target_obj, AB_TRAV_ITEMS);
		(target_item = trav_next(&trav)) != NULL; )
	{
	    if (   (target_item != target_obj)
		&& util_streq(obj_get_label(target_item), target_item_label))
	    {
		break;
	    }
	}
	trav_close(&trav);
	if (target_item == NULL)
	{
	    target_item = obj_create(AB_TYPE_ITEM, target_obj);
	    obj_set_is_defined(target_item, FALSE);
	    obj_set_file(target_item, target_interface_file);
	    obj_set_label(target_item, target_item_label);
	    obj_set_name_from_label(target_item, 
				obj_get_name(obj_get_parent(target_item)));
	}
    }

    if (target_item != NULL)
    {
	target = target_item;
    }
    else
    {
	target = target_obj;
    }

epilogue:
    return target;
}
Exemple #11
0
int
abmfP_get_connect_includes(StringList includeFiles, ABObj projOrModule)
{
    AB_TRAVERSAL	trav;
    BOOL		actionIsCrossModule = FALSE;
    ABObj		project = obj_get_project(projOrModule);
    ABObj		action = NULL;
    ABObj		toObj = NULL;
    ABObj		compRoot = NULL;
    ABObj		toModule = NULL;
    ABObj		win_parent = NULL;
    ABObj		popup_win = NULL;
    char		headerFilename[MAXPATHLEN+1];
    *headerFilename = 0;

    strlist_set_is_unique(includeFiles, TRUE);
    assert(project != NULL);
    if (project == NULL)
    {
	return 0;
    }

    for (trav_open(&trav, projOrModule, AB_TRAV_ACTIONS_FOR_OBJ);
	(action = trav_next(&trav)) != NULL; )
    {
	actionIsCrossModule = obj_is_cross_module(action);
	toObj = obj_get_to(action);
	if (toObj == NULL)
	{
	    continue;
	}

	toModule = obj_get_module(toObj);

	if (actionIsCrossModule)
	{
	    sprintf(headerFilename, "\"%s\"", 
	        abmfP_get_ui_header_file_name(toModule));
            strlist_add_str(includeFiles,  headerFilename, NULL);
  	}

	/*
	 * Check to see if the popup's window parent is in another module
	 */
	compRoot = obj_get_root(toObj);
	popup_win = NULL;
	if (obj_is_popup_win(compRoot))
	{
	    popup_win = compRoot;
	}
	if (popup_win == NULL) 
	{
	    popup_win = obj_get_parent_of_type(compRoot, AB_TYPE_DIALOG);
	}
	if (popup_win == NULL)
	{
	    popup_win = obj_get_parent_of_type(compRoot, AB_TYPE_BASE_WINDOW);
	}

	if (popup_win != NULL)
	{
	    win_parent= obj_get_win_parent(popup_win);
	    if (win_parent != NULL)
	    {
	       toModule = obj_get_module(win_parent);
	       if (toModule != NULL)
	       {
		   sprintf(headerFilename, "\"%s\"", 
			abmfP_get_ui_header_file_name(toModule));
	           strlist_add_str(includeFiles, headerFilename, NULL);
	       }
 	    }
        }

	/*
	 * For some actions, we need widget-specific convenience
	 * functions and resource strings that exist in the header files.
	 */
	if (obj_get_func_type(action) == AB_FUNC_BUILTIN)
	{
	    switch (obj_get_func_builtin(action))
	    {
		case AB_STDACT_SET_LABEL:
		case AB_STDACT_SET_TEXT:
		case AB_STDACT_SET_VALUE:
	            abmfP_comp_get_widget_specific_includes(
			includeFiles, obj_get_root(toObj));
		break;
	    }
	}
    }
    trav_close(&trav);

    return 0;
}