/* * 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); }
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); }
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); }
int abmfP_tree_set_action_names(ABObj rootObj) { int return_value = 0; AB_TRAVERSAL moduleTrav; ABObj module = NULL; if (!obj_is_project(rootObj)) { return_value = abmfP_set_action_names_for_obj(rootObj); } else { /* for efficiency, we'll only visit those modules that are * going to be written */ abmfP_set_action_names_for_obj(rootObj); /* project 1st */ for (trav_open(&moduleTrav, rootObj, AB_TRAV_MODULES); (module = trav_next(&moduleTrav)) != NULL; ) { if (obj_get_write_me(module)) { abmfP_set_action_names_for_obj(module); /* each module */ } } trav_close(&moduleTrav); } return return_value; }
/* * Object rename callback * Update project organizer when module is renamed. */ static int projP_obj_renameOCB( ObjEvAttChangeInfo info ) { ABObj obj = info->obj; char *name; /* * We only care about modules and projects here */ if (!obj || (!obj_is_module(obj) && !obj_is_project(obj))) return (0); /* * Update the module name only if the old name is not NULL. * * If the old name is NULL that means this is a new object. * and we let the update callback handle that. */ if (info->old_name != NULL) proj_update_node(obj); return (0); }
static MsgSet get_cached_msg_set( MsgFile msg_file, ABObj obj ) { static ABObj prev_obj = (ABObj)NULL; static MsgSet prev_msg_set = (MsgSet)NULL; MsgSet msg_set; if (obj == prev_obj) msg_set = prev_msg_set; else if (obj_is_project(obj)) { char *project_name = obj_get_name(obj); char proj_suffixed_name[BUFSIZ]; strcpy(proj_suffixed_name, project_name); strcat(proj_suffixed_name, "_project"); msg_set = MsgFile_sure_find_msg_set(msg_file, proj_suffixed_name); prev_msg_set = msg_set; } else { static ABObj prev_module = (ABObj)NULL; ABObj module; char *module_name; module = obj_get_module(obj); if (module == prev_module) msg_set = prev_msg_set; else { prev_module = module; module_name = obj_get_name(module); msg_set = MsgFile_sure_find_msg_set(msg_file, module_name); prev_msg_set = msg_set; } } return(msg_set); }
/* * projP_obj_updateOCB * Update project organizer when new modules are added */ static int projP_obj_updateOCB( ObjEvUpdateInfo info ) { ABObj obj = info->obj; /* * We should only care about modules and projects * here. */ if (!obj || (!obj_is_module(obj) && !obj_is_project(obj))) return (0); proj_add_objects(obj); return (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; }
/* * 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; }