Example #1
0
abmfP_write_init_proc_decl(
		GenCodeInfo	genCodeInfo,
		ABObj		obj
)
{
    if (obj_is_message(obj))
    {
        return abmfP_write_c_func_decl(
            genCodeInfo,
            FALSE,                              /* Is static */
            abmfP_str_int,                      /* return type */
            abmfP_get_init_proc_name(obj),      /* function name */
            "DtbMessageData",			/* Argument type */
	    abmfP_instance_ptr_var_name,	/* Argument name */
            NULL
	   );   
    }
    else if (obj_is_window(obj))
    {
	return abmfP_write_c_func_decl(
	    genCodeInfo,
	    FALSE,				   /* Is static */
	    abmfP_str_int,			   /* return type */
	    abmfP_get_init_proc_name(obj),	   /* function name */
	    abmfP_get_c_struct_ptr_type_name(obj), /* Argument type */
	    abmfP_instance_ptr_var_name,	   /* Argument name */
	    abmfP_str_widget,	"parent",	   /* Argument type */
	    NULL				   /* Argument name */
	   );
    }
}
Example #2
0
/*
 * Write main() for the given project.
 */
static int
write_main(GenCodeInfo genCodeInfo, ABObj project)
{
    int                 returnValue = 0;
    File                codeFile = genCodeInfo->code_file;
    ABObj               window = NULL;
    int                 initialized = FALSE;
    ABObj		main_window= NULL;
    AB_TRAVERSAL        trav;
    BOOL		mainWindowHasIcon = FALSE;

    abmfP_gencode_enter_func(genCodeInfo);

    main_window = abmfP_get_root_window(project);
    if (main_window != NULL)
    {
	mfobj_set_flags(main_window, CGenFlagTreatAsAppShell);
    }
    mainWindowHasIcon = 
	(   (main_window != NULL) 
	 && (   (obj_get_icon(main_window) != NULL)
	     || (obj_get_icon_mask(main_window) != NULL)) );

    abio_puts(codeFile, "\n\n");
    abio_puts(codeFile, abmfP_comment_begin);
    abio_puts(codeFile, abmfP_comment_continue);
    abio_printf(codeFile, "main for application %s\n",
		obj_get_name(project));
    abio_puts(codeFile, abmfP_comment_end);

    /*
     * Write func declaration.
     */
    abio_puts(codeFile, "int\n");
    if (genCodeInfo->prototype_funcs)
    {
	abio_puts(codeFile, "main(int argc, char **argv)\n");
    }
    else
    {
	abio_puts(codeFile, "main(argc, argv)\n");
	abio_indent(codeFile);
	abio_puts(codeFile, "int\t\targc;\n");
	abio_puts(codeFile, "char\t\t**argv;\n");
	abio_outdent(codeFile);
    }

    abio_puts(codeFile, "{\n");
    abio_set_indent(codeFile, 1);

    /*
     * Local variables
     */
    abio_puts(codeFile, "Widget\t\ttoplevel = (Widget)NULL;\n");
    abio_puts(codeFile, "Display\t\t*display = (Display*)NULL;\n");
    abio_puts(codeFile, "XtAppContext\tapp = (XtAppContext)NULL;\n");
    abio_puts(codeFile, "String\t\t*fallback_resources = (String*)NULL;\n");
    abio_puts(codeFile, "ArgList\t\tinit_args = (ArgList)NULL;\n");
    abio_puts(codeFile, "Cardinal\t\tnum_init_args = (Cardinal)0;\n");
    abio_puts(codeFile, "ArgList\t\tget_resources_args = (ArgList)NULL;\n");
    abio_puts(codeFile, "Cardinal\t\tnum_get_resources_args = (Cardinal)0;\n");
    abio_puts(codeFile, "Atom\t\tsave_yourself_atom = (Atom)NULL;\n");
    write_main_i18n_local_vars(genCodeInfo, project);
    write_main_tooltalk_local_vars(genCodeInfo, project);
    abio_puts(codeFile, nlstr);

    if (mainWindowHasIcon)
    {
	abmfP_icon_pixmap_var(genCodeInfo) = istr_const("icon_pixmap");
	abmfP_icon_mask_pixmap_var(genCodeInfo) = 
					istr_const("icon_mask_pixmap");
	abio_puts(codeFile, "Pixmap\ticon_pixmap = NULL;\n");
	abio_puts(codeFile, "Pixmap\ticon_mask_pixmap = NULL;\n");
    }

    abmfP_write_user_long_seg(genCodeInfo,
    " No initialization has been done.\n"
"     ***\n"
"     *** Add local variables and code."
    );

    if (genCodeInfo->i18n_method == ABMF_I18N_XPG4_API)
        write_main_xt_i18n(genCodeInfo, project);

    /*
     * Create a parent shell for every other shell and don't realize it. This
     * way, we can be consistent with our hierarchy.
     */
    abio_printf(codeFile,"toplevel = XtAppInitialize(&app, \"%s\",\n",
	abmfP_capitalize_first_char(obj_get_name(project)));
    abio_indent(codeFile);
    abio_puts(codeFile, "optionDescList, XtNumber(optionDescList),\n");
    abio_puts(codeFile, "&argc, argv, fallback_resources,\n");
    abio_puts(codeFile, "init_args, num_init_args);\n\n");
    abio_outdent(codeFile);

    abmfP_write_c_comment(genCodeInfo, FALSE,
	"Get display and verify initialization was successful.");
    abio_puts(codeFile, "if (toplevel != NULL)\n");
    abmfP_write_c_block_begin(genCodeInfo);
    abio_puts(codeFile, "display = XtDisplayOfObject(toplevel);\n");
    abmfP_write_c_block_end(genCodeInfo);

    if (genCodeInfo->i18n_method == ABMF_I18N_XPG4_API)
        write_main_msg_i18n(genCodeInfo, project);
    
    abio_puts(codeFile, "if (display == NULL)\n");
    abmfP_write_c_block_begin(genCodeInfo);
    abio_puts(codeFile, "fprintf(stderr, \"Could not open display.\");\n");
    abio_puts(codeFile, "exit(1);\n");
    abmfP_write_c_block_end(genCodeInfo);

    /* Save the toplevel widget so it can be fetched later as needed */
    abio_puts(codeFile,"\n");
    abmfP_write_c_comment(genCodeInfo, FALSE,
      "Save the toplevel widget so it can be fetched later as needed.");
    abio_puts(codeFile, "dtb_save_toplevel_widget(toplevel);\n");

    /* Save the command used to invoke the application */
    abio_puts(codeFile,"\n");
    abmfP_write_c_comment(genCodeInfo, FALSE,
      "Save the command used to invoke the application.");
    abio_puts(codeFile, "dtb_save_command(argv[0]);\n");

    /*
     * Get application resources
     */
    abio_puts(codeFile,"\n");
    abio_puts(codeFile, "XtGetApplicationResources(toplevel, (XtPointer)&dtb_app_resource_rec,\n");
    abio_indent(codeFile);
    abio_puts(codeFile, "resources, XtNumber(resources),\n");
    abio_puts(codeFile, "get_resources_args, num_get_resources_args);\n");
    abio_outdent(codeFile);
    abio_puts(codeFile, nlstr);

    /*
     * User segment after initialization
     */
    abmfP_write_user_long_seg(genCodeInfo,
"     A connection to the X server has been established, and all\n"
"     *** initialization has been done.\n"
"     ***\n"
"     ***  Add extra initialization code after this comment."
    );

    /*
     * Call session restore callback (if needed)
     */
    write_main_session_restore(genCodeInfo, project);

    /*
     * Initialize all global variables
     */
    abio_puts(codeFile, nlstr);
    abmfP_write_c_comment(genCodeInfo, FALSE, 
	"Initialize all global variables.");
    for (trav_open(&trav, project, AB_TRAV_SALIENT_UI);
	(window= trav_next(&trav)) != NULL; )
    {
	if (!obj_is_defined(window))
	{
	    continue;
	}

	if (obj_is_message(window))
 	{
	    abio_printf(codeFile, "%s(&%s);\n",
		abmfP_get_msg_clear_proc_name(window),
		abmfP_get_c_struct_global_name(window));
	}
	else if (obj_is_window(window))
	{
	    abio_printf(codeFile, "%s(&%s);\n",
		abmfP_get_clear_proc_name(window),
		abmfP_get_c_struct_global_name(window));
	}
    }
    trav_close(&trav);
    abio_puts(codeFile, "\n");

    if (main_window != NULL)
    {
	abmfP_write_c_comment(genCodeInfo, FALSE,
		"Set up the application's root window.");
        abio_printf(codeFile, "%s = toplevel;\n",
	    abmfP_get_c_name_global(main_window));

	if (obj_get_icon(main_window) != NULL)
	{
	    abio_printf(codeFile, "%s(%s,\n", 
		abmfP_lib_cvt_image_file_to_pixmap->name,
	        abmfP_get_c_name_global(main_window));
	    abio_indent(codeFile);
	    abio_put_string(codeFile, obj_get_icon(main_window));
	    abio_printf(codeFile, ", &%s);\n",
		istr_string(abmfP_icon_pixmap_var(genCodeInfo)));
	    abio_outdent(codeFile);
	    abmfP_icon_pixmap_var_has_value(genCodeInfo) = TRUE;
	}
	if (obj_get_icon_mask(main_window) != NULL)
	{
	    abio_printf(codeFile, "%s(%s,\n", 
		abmfP_lib_cvt_image_file_to_pixmap->name,
	        abmfP_get_c_name_global(main_window));
	    abio_indent(codeFile);
	    abio_put_string(codeFile, obj_get_icon_mask(main_window));
	    abio_printf(codeFile, ", &%s);\n",
		istr_string(abmfP_icon_mask_pixmap_var(genCodeInfo)));
	    abio_outdent(codeFile);
	    abmfP_icon_mask_pixmap_var_has_value(genCodeInfo) = TRUE;
	}

	if (abmfP_get_num_args_of_classes(main_window, ABMF_ARGCLASS_ALL) > 0)
	{
	    abmfP_xt_va_list_open_setvalues(genCodeInfo, main_window);
            abmfP_obj_spew_args(genCodeInfo, 
		main_window, ABMF_ARGCLASS_ALL, ABMF_ARGFMT_VA_LIST);
    	    if (!obj_get_resizable(main_window))
	    {
        	abio_printf(codeFile,
            	    "XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_RESIZEH,\n");
        	abio_printf(codeFile, 
            	    "XmNmwmFunctions, MWM_FUNC_ALL | MWM_FUNC_RESIZE,\n"); 
	    }
	    abmfP_xt_va_list_close(genCodeInfo);
	}
    }
    abio_puts(codeFile, nlstr);
    if ((main_window != NULL) && (obj_is_initially_visible(main_window)))
    {
	/* ApplicationShell doesn't require "show" action for mapping */
        write_map_window(genCodeInfo, main_window, False);
    }
    /*
     * Display any initially mapped windows
     */  
    abio_puts(codeFile, nlstr);
    abmfP_write_c_comment(genCodeInfo, FALSE,
        "Map any initially-visible windows");
    for (trav_open(&trav, project, AB_TRAV_WINDOWS);
	 (window = trav_next(&trav)) != NULL;)
    {
	if ( (window != main_window) && 	
	     (obj_is_initially_visible(window)) &&
	     obj_is_defined(window)
	   )
	{
	    write_map_window(genCodeInfo, window, True);
	}
    }
    trav_close(&trav);

    /*
     * Get WM_SAVE_YOURSELF atom
     */
    abio_puts(codeFile, "\n");
    abio_puts(codeFile, "save_yourself_atom = XmInternAtom(XtDisplay(toplevel),\n");
    abio_puts(codeFile, "\t\"WM_SAVE_YOURSELF\", False);\n");

    /*
     * Register callback for WM_SAVE_YOURSELF
     */
    write_main_register_save_yourself(genCodeInfo, project, "save_yourself_atom");

    /*
     * User seg before realize
     */
    abmfP_write_user_long_seg(genCodeInfo,
"     All initially-mapped widgets have been created, but not\n"
"     *** realized. Set resources on widgets, or perform other operations\n"
"     *** that must be completed before the toplevel widget is\n"
"     *** realized."
    );

    /*
     * Realize the widget hierarchy
     */
    abio_puts(codeFile, "XtRealizeWidget(toplevel);\n\n");

    /*
     * Write ToolTalk Initialization if needed
     */
    write_main_tooltalk_init(genCodeInfo, project);

    /*
     * User seg before event loop
     */
    abmfP_write_user_long_seg(genCodeInfo,
"     The initially-mapped widgets have all been realized, and\n"
"     *** the Xt main loop is about to be entered."
    );

    abio_puts(codeFile, nlstr);

    abmfP_write_c_comment(genCodeInfo, FALSE, "Enter event loop");
    abio_puts(codeFile, "XtAppMainLoop(app);\n");

    /*
     * Write func footer.
     */
    abio_printf(codeFile, "return 0;\n");
    abio_set_indent(codeFile, 0);
    abio_puts(codeFile, "}\n\n");

    abmfP_gencode_exit_func(genCodeInfo);
    return returnValue;
}
Example #3
0
File: trav.c Project: juddy/edcde
/*
 *  Check the new current object to see if it qualifies for the traversal.
 *
 *  Assumes: trav->curObj is not null
 */
static BOOL
travP_qualifies(ABTraversal trav)
{
    register ABObj	curObj = trav->curObj;
    register BOOL	qualifies= TRUE;

    if (obj_has_impl_flags(curObj, ObjFlagDestroyed))
    {
        qualifies= FALSE;
        goto epilogue;
    }

    switch (travP_get_qualifier(trav))
    {
    case AB_TRAV_ACTIONS:
    case AB_TRAV_ACTIONS_FOR_OBJ:
        qualifies= obj_is_action(curObj);
        break;

    case AB_TRAV_COMP_SUBOBJS:
        qualifies = (obj_get_root(curObj) == trav->rootObj);
        break;

    case AB_TRAV_FILES:
        qualifies= (curObj->type == AB_TYPE_FILE);
        break;

    case AB_TRAV_GROUPS:
        qualifies= obj_is_group(curObj);
        break;

    case AB_TRAV_ITEMS:
    case AB_TRAV_ITEMS_FOR_OBJ:
        qualifies= obj_is_item(curObj);
        break;

    case AB_TRAV_MENUS:
        qualifies= obj_is_menu(curObj);
        break;

    case AB_TRAV_MODULES:
        qualifies= obj_is_module(curObj);
        break;

    case AB_TRAV_SALIENT:
    case AB_TRAV_SALIENT_CHILDREN:
        qualifies= obj_is_salient(curObj);
        break;

    case AB_TRAV_SALIENT_UI:
    case AB_TRAV_SALIENT_UI_CHILDREN:
        qualifies= obj_is_salient_ui(curObj);
        break;

    case AB_TRAV_UI:
        qualifies= obj_is_ui(curObj);
        break;

    case AB_TRAV_WINDOWS:
        qualifies= obj_is_window(curObj);
        break;
    }

    if ((qualifies) && (trav->testFunc != NULL))
    {
        qualifies = trav->testFunc(curObj);
    }

epilogue:
    return qualifies;
} /* travP_qualifies */
Example #4
0
/*
 * Creates an ABObj that is a duplicates of the given object, but does 
 * NOT duplicate parent, siblings, children, et cetera.
 *
 * Most references to other objects or dynamic data are set to NULL.
 * ISTRINGS are duplicated
 */
static ABObj
objP_create_dup_or_ref(ABObj obj, BOOL createRef)
{
    ABObj	newObj= (ABObj)util_malloc(sizeof(AB_OBJ));
    if (newObj == NULL)
    {
	return NULL;
    }

    *newObj= *obj;
    newObj->parent= NULL;
    newObj->next_sibling= NULL;
    newObj->prev_sibling= NULL;
    newObj->first_child= NULL;

    newObj->name= istr_dup(obj->name);
#ifdef DEBUG
    newObj->debug_name = obj->debug_name;
#endif
    newObj->user_data= istr_dup(obj->user_data);
    newObj->bg_color= istr_dup(obj->bg_color);
    newObj->fg_color= istr_dup(obj->fg_color);
    newObj->label= istr_dup(obj->label);
    newObj->menu_name= istr_dup(obj->menu_name);
    newObj->attachments= NULL;
    newObj->part_of= NULL;
    newObj->ref_to = (createRef? obj : obj->ref_to);

    newObj->ui_handle= NULL;
    newObj->class_name= istr_dup(obj->class_name);
    newObj->ui_args= NULL;
    obj_set_is_selected(newObj, FALSE);
    newObj->browser_data= NULL;
    newObj->projwin_data= NULL;

    if (obj_is_action(newObj))
    {
	newObj->info.action.func_name_suffix= 
		istr_dup(obj->info.action.func_name_suffix);
    }
    else if (obj_is_file_chooser(newObj))
    {
	newObj->info.file_chooser.filter_pattern= 
		istr_dup(obj->info.file_chooser.filter_pattern);
	newObj->info.file_chooser.ok_label= 
		istr_dup(obj->info.file_chooser.ok_label);
	newObj->info.file_chooser.directory= 
		istr_dup(obj->info.file_chooser.directory);
     }
     else if (obj_is_menu(newObj))
     {
	newObj->info.menu.tear_off = obj->info.menu.tear_off;
     }
     else if (obj_is_message(newObj))
     {
	newObj->info.message.msg_string =
                istr_dup(obj->info.message.msg_string);
	newObj->info.message.action1_label =
                istr_dup(obj->info.message.action1_label);
	newObj->info.message.action2_label =
                istr_dup(obj->info.message.action2_label);
    }
    else if (obj_is_module(newObj))
    {
	newObj->info.module.file= istr_dup(obj->info.module.file);
	newObj->info.module.stubs_file= istr_dup(obj->info.module.stubs_file);
	newObj->info.module.ui_file= istr_dup(obj->info.module.ui_file);
    }
    else if (obj_is_item(newObj))
    {
	newObj->info.item.accelerator= istr_dup(newObj->info.item.accelerator);
	newObj->info.item.mnemonic= istr_dup(newObj->info.item.mnemonic);
    }
    else if (obj_is_project(newObj))
    {
	newObj->info.project.file= istr_dup(obj->info.project.file);
	newObj->info.project.stubs_file= istr_dup(obj->info.project.stubs_file);
	newObj->info.project.root_window= obj->info.project.root_window;
    }
    else if (obj_is_text(newObj))
    {
	newObj->info.text.initial_value_string= 
		istr_dup(obj->info.text.initial_value_string);
    }
    else if (obj_is_term_pane(newObj))
    {
	newObj->info.term.process_string= 
		istr_dup(obj->info.term.process_string);
    }
    else if (obj_is_window(newObj) && !obj_is_file_chooser(newObj))
    {
	newObj->info.window.icon= istr_dup(obj->info.window.icon);
	newObj->info.window.icon_label= istr_dup(obj->info.window.icon_label);
    }

    objP_notify_send_create(obj);
    return newObj;
}