Example #1
0
/*
** we are on a virtual object and need to write the actual builtin action
** for each ref to it.
*/
static int
write_builtin_action_for_ref(
    GenCodeInfo	      genCodeInfo,
    ABObj 	      action,
    ABObj             toObj,
    BOOL              setUpVars,
    AB_BUILTIN_ACTION builtin_action,
    STRING            actionTKResource,		       /* in toolkit */
    STRING	      actionResource		       /* in source code */
)
{
    int                        i = 0;
    int                  numRefs = 0;
    int             return_value = 0;
    ABObj                 refObj = NULL;
    ABObjList            refList = NULL;

    if (!genCodeInfo || !action || !toObj)
        return -1;

    refList = abmfP_find_refs_to(toObj);
    numRefs = objlist_get_num_objs(refList);

    if ((refList != NULL) && (numRefs > 0))
    {
        if (setUpVars)
        {
            refObj = objlist_get_obj(refList, 0, NULL);
            set_up_user_type_variables(genCodeInfo, refObj);
        }

        /* write the builtin actions */
        for (i = 0; i < numRefs; ++i)
        {
            refObj  = objlist_get_obj(refList, i, NULL);

            if (abmfP_get_c_name(genCodeInfo, refObj) != NULL)
            {
                return_value = write_builtin_action(genCodeInfo,
                                                    action, refObj, builtin_action, actionTKResource,
                                                    actionResource);
            }
        }
    }
    else
    {
        util_dprintf(0, "ERROR: write_builtin_action_for_ref(): ");
        util_dprintf(0, "Unable to obtain references to the object.\n");
    }

epiloge:
    objlist_destroy(refList);
    return return_value;
}
Example #2
0
/*
 * Generate XtVaSetvalues calls in callbacks.
 * obj is the object that will have it's resources set.
 *
 * Resource list must be name,value pairs, NULL-terminated
 * All resource values must be of type (void *)
 */
static int
printf_setval(GenCodeInfo genCodeInfo, ABObj obj, ...)
{
    int			return_value = 0;
    File		codeFile = genCodeInfo->code_file;
#if defined(__osf__) || defined(linux) || defined(CSRG_BASED)
    /* OSF/1 define va_list in <va_list.h> as structure of char ** and int
     * Sun define va_list as void * */
    va_list             paramList = { 0, 0 };
#else
    va_list             paramList = NULL;
#endif /* __osf__ */
    STRING              resName = NULL;
    void		*resValue = NULL;
    STRING		objCName = NULL;
    ISTRING		istrValue = NULL;

    va_start(paramList, obj);

    objCName = abmfP_get_c_name(genCodeInfo, obj);
    abio_printf(codeFile, "\tXtVaSetValues(%s,", objCName);
    abio_printf(codeFile, "\n\t\t");

    while ((resName = va_arg(paramList, STRING)) != NULL)
    {
        resValue = va_arg(paramList, VoidPtr);
        switch (abmfP_get_res_type(resName, obj))
        {
        case AB_ARG_LITERAL:
        case AB_ARG_PIXEL:
        case AB_ARG_PIXMAP:
        case AB_ARG_XMSTRING:
            istrValue = istr_create((STRING)resValue);
            resValue = (VoidPtr)istrValue;
            break;

        case AB_ARG_WIDGET:
            util_dprintf(1,
                         "Ignoring unsupported connection resource type: WIDGET\n");
            break;
        }
        abmfP_write_arg_val(genCodeInfo, FALSE, resName, resValue, obj);
        abio_printf(codeFile, ",\n\t\t");

        istr_destroy(istrValue);
        resValue = NULL;
    }
    abio_printf(codeFile, "NULL);");

    va_end(paramList);
    return return_value;
}
Example #3
0
static void
set_up_user_type_variables(GenCodeInfo genCodeInfo, ABObj toObj)
{
    File                codeFile = genCodeInfo->code_file;
    ABObj               structObj = abmfP_obj_get_struct_obj(toObj);
    ABObj		winParent = NULL;
    char		winParentName[1024];
    *winParentName = 0;

    /*
     * Determine window parent of this popup
     */
    winParent = obj_get_win_parent(structObj);
    if (winParent == NULL)
    {
        sprintf(winParentName, "%s()", abmfP_lib_get_toplevel_widget->name);
    }
    else
    {
        strcpy(winParentName, abmfP_get_c_name(genCodeInfo, winParent));
    }

    /*
     * REMIND: This is obsolete and should be removed!
     */
    if (cwd_is_dtbuilder_src_dir())
    {
        write_instance_ptr_var(genCodeInfo, toObj,
                               instanceVarName, abmfP_client_data_var_name, TRUE, NULL);
        abio_puts(genCodeInfo->code_file, nlstr);
    }
    else
    {
        write_instance_ptr_var(genCodeInfo, toObj,
                               toVarName, abmfP_client_data_var_name, TRUE, NULL);
        write_instance_ptr_var(genCodeInfo, toObj,
                               instanceVarName, toVarName, FALSE, "/* obsolete */");
        abio_puts(genCodeInfo->code_file, nlstr);
    }
    abio_printf(codeFile, "if (!(%s->initialized))\n", get_to_var_name());
    abmfP_write_c_block_begin(genCodeInfo);
    abio_printf(codeFile, "%s(%s, %s);\n",
                abmfP_get_init_proc_name(structObj),
                get_to_var_name(),
                winParentName);
    abmfP_write_c_block_end(genCodeInfo);
}
Example #4
0
/*
 * printf_getval - can only get one resource.  This can be changed at a later
 * date if need be. NOTE: We need to declare local variables in one pass,
 * Then write out an XtVaGetValues on a second pass, if we ever want to get
 * more that one value back.
 */
static int
printf_getval(GenCodeInfo genCodeInfo, ABObj obj, int nres,...)
{
    int			return_value = 0;
    File		codeFile = genCodeInfo->code_file;
    va_list             ap;
    STRING              resource;
    ARG_TYPES           type;
    STRING		objCName = NULL;
    nres = nres;		/* avoid warning */

    va_start(ap, nres);

    objCName = abmfP_get_c_name(genCodeInfo, obj);
    resource = va_arg(ap, STRING);
    type = va_arg(ap, ARG_TYPES);

    /* Print the declaration */
    switch (type)
    {
    case IMMED_TYPE:
    case INT_TYPE:
        abio_printf(codeFile, "\tint i;\n\n");
        break;
    case STRING_TYPE:
        abio_printf(codeFile, "\tchar *str;\n\n");
        break;
    }

    abio_printf(codeFile, "\tXtVaGetValues(%s,\n\t\t%s, ", objCName, resource);

    /* Print the local variable reference */
    switch (type)
    {
    case IMMED_TYPE:
    case INT_TYPE:
        abio_printf(codeFile, "&i");
        break;
    case STRING_TYPE:
        abio_printf(codeFile, "&str");
        break;
    }
    abio_printf(codeFile, ",\n\t\tNULL);\n");

    va_end(ap);
    return return_value;
}
Example #5
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;
}
Example #6
0
/*
** determine which builtin action and write the appropriate code.
*/
static int
write_builtin_action(
    GenCodeInfo	      genCodeInfo,
    ABObj 	      action,
    ABObj             toObj,
    AB_BUILTIN_ACTION builtin_action,
    STRING            actionTKResource,		       /* in toolkit */
    STRING	      actionResource		       /* in source code */
)
{
#define	 IS(type)	(obj_get_func_type(action) ==(type))
#define	 SVAL(action)	((STRING)obj_get_arg_string(action))
#define	 IVAL(action)	((int)obj_get_arg_int(action))

    File                codeFile     = genCodeInfo->code_file;
    int			return_value = 0;

    if (!codeFile || !action || !toObj || !builtin_action)
        return return_value;

    switch (builtin_action)
    {
    case AB_STDACT_ENABLE:
        abio_print_line(codeFile, NULL);
        abio_print_line(codeFile, "XtSetSensitive(%s, True);",
                        abmfP_get_c_name(genCodeInfo, toObj));
        break;

    case AB_STDACT_DISABLE:
        abio_print_line(codeFile, NULL);
        abio_print_line(codeFile, "XtSetSensitive(%s, False);",
                        abmfP_get_c_name(genCodeInfo, toObj));
        break;

    case AB_STDACT_SHOW:
        switch((obj_get_root(toObj))->type)
        {
        case AB_TYPE_BASE_WINDOW:
            abio_print_line(codeFile, "XtPopup(%s, XtGrabNone);",
                            abmfP_get_c_name(genCodeInfo, toObj));
            break;

        case AB_TYPE_DIALOG:
        case AB_TYPE_FILE_CHOOSER:
        default:
            abio_print_line(codeFile, "XtManageChild(%s);",
                            abmfP_get_c_name(genCodeInfo, toObj));
            break;
        }
        break;

    case AB_STDACT_HIDE:
        switch((obj_get_root(toObj))->type)
        {
        case AB_TYPE_BASE_WINDOW:
            abio_print_line(codeFile, "XtPopdown(%s);",
                            abmfP_get_c_name(genCodeInfo, toObj));
            break;

        case AB_TYPE_DIALOG:
        case AB_TYPE_FILE_CHOOSER:
        default:
            abio_print_line(codeFile, "XtUnmanageChild(%s);",
                            abmfP_get_c_name(genCodeInfo, toObj));
            break;
        }
        break;

    case AB_STDACT_SET_LABEL:
        /* check toObj for root */
        if ( obj_get_label_type(obj_get_root(toObj)) == AB_LABEL_GLYPH)
        {
            abio_printf(codeFile, "%s(%s, ",
                        abmfP_lib_set_label_from_image_file->name,
                        abmfP_get_c_name(genCodeInfo, toObj));
            abio_put_string(codeFile, SVAL(action));
            abio_puts(codeFile, ");\n");
        }
        else
        {
            assert(actionTKResource != NULL);
            printf_setval(genCodeInfo, toObj,
                          actionTKResource, SVAL(action),
                          NULL);
        }
        break;

    case AB_STDACT_SET_VALUE:
        printf_setval(genCodeInfo, toObj,
                      actionTKResource, IVAL(action), NULL);
        break;

    case AB_STDACT_SET_TEXT:
        printf_setval(genCodeInfo, toObj,
                      actionTKResource, SVAL(action),
                      NULL);
        break;

    /* 	case AB_STDACT_SHOW_HELP: */
    /* 	    abio_print_line(codeFile, NULL); */
    /* 	    abio_print_line(codeFile,  */
    /* 		"XtCallCallbacks(%s,XmNhelpCallback,(XtPointer)NULL);", */
    /* 		abmfP_get_c_name(genCodeInfo, toObj)); */
    /* 	    break; */

    default:
    {
        static char         msg[255];

        if (obj_get_name(action) != NULL)
        {
            char *action_name = obj_get_name(action);
            sprintf(msg, catgets(Dtb_project_catd, 1, 76,
                                 "Unknown action name, %s"), action_name);
        }
        else
        {
            int action_type = obj_get_func_builtin(action);
            sprintf(msg, catgets(Dtb_project_catd, 1, 77,
                                 "Unknown action type, %d"), action_type);
        }
        util_error(msg);
        return_value = ERR_INTERNAL;

        /*
         * return msg; Just print message and go on - JT
         */
    }
    break;
    }			/* switch func.value.builtin */

    return return_value;
#undef IS
#undef SVAL
#undef IVAL
}
Example #7
0
int
abmfP_write_builtin_action(
    GenCodeInfo	genCodeInfo,
    ABObj 		action,
    BOOL		setUpVars
)
{
    int			return_value     = 0;
    File                codeFile         = genCodeInfo->code_file;
    ABObj               toObj            = NULL;
    STRING		actionTKResource = NULL;	/* in toolkit */
    STRING		actionResource   = NULL;	/* in source code */
    ISTRING		istr_resource    = NULL;
    AB_BUILTIN_ACTION	builtin_action   = AB_STDACT_UNDEF;

    toObj          = obj_get_to(action);
    builtin_action = obj_get_func_builtin(action);
    if (toObj != NULL)
    {
        toObj = objxm_comp_get_target_for_builtin_action(toObj, builtin_action);
    }
    if (toObj == NULL)
    {
        abmfP_write_c_comment(genCodeInfo, FALSE, "Invalid action ignored.");
        abio_puts(codeFile, nlstr);
        return 0;
    }

    /*
     * We need to convert the resource into a string that can be put
     * in the .c file.
     */
    actionTKResource = objxm_get_resource_for_builtin_action(
                           toObj, builtin_action);
    istr_resource    = objxm_get_res_strname(actionTKResource);
    actionResource   = istr_string(istr_resource);

    if (abmfP_get_c_name(genCodeInfo, toObj) == NULL)
    {
        return_value = write_builtin_action_for_ref(genCodeInfo,
                       action, toObj, setUpVars, builtin_action, actionTKResource,
                       actionResource);
    }
    else
    {
        if (setUpVars)
        {
            set_up_user_type_variables(genCodeInfo, toObj);
        }

        return_value = write_builtin_action(genCodeInfo, action, toObj,
                                            builtin_action, actionTKResource, actionResource);
    }

    if (return_value == 0)
        abio_printf(codeFile, nlstr);

epiloge:
    abio_printf(codeFile, nlstr);
    return return_value;
}