X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=lwlib%2Flwlib.c;h=f9c90f519c6d693bb5d02a0420d2ba02c43b3836;hb=de1ec4b272dfa3f9ef2c9ae28a9ba67170d24da5;hp=35be751595fa373d1ec549d5698e1c3d20f63447;hpb=3e447015251ce6dcde843cbed10d9033d5538622;p=chise%2Fxemacs-chise.git.1 diff --git a/lwlib/lwlib.c b/lwlib/lwlib.c index 35be751..f9c90f5 100644 --- a/lwlib/lwlib.c +++ b/lwlib/lwlib.c @@ -257,14 +257,17 @@ merge_widget_value_args (widget_value *old, widget_value *new) lw_copy_widget_value_args (old, new); changed = True; } - else if (new->args && old->args) + else if (new->args && old->args && new->args != old->args) { /* #### Do something more sensible here than just copying the new values (like actually merging the values). */ - free_widget_value_args (old); lw_copy_widget_value_args (new, old); changed = True; } + else if (new->args && new->args == old->args && new->args->args_changed == True) + { + changed = True; + } return changed; } @@ -273,7 +276,7 @@ merge_widget_value_args (widget_value *old, widget_value *new) /* Make a complete copy of a widget_value tree. Store CHANGE into the widget_value tree's `change' field. */ -static widget_value * +widget_value * copy_widget_value_tree (widget_value *val, change_type change) { widget_value *copy; @@ -509,7 +512,7 @@ safe_strcmp (const char *s1, const char *s2) return (s1 && s2) ? strcmp (s1, s2) : s1 ? False : !!s2; } -#ifndef WINDOWSNT +#ifndef WIN32_NATIVE static change_type max (change_type i1, change_type i2) { @@ -757,7 +760,11 @@ update_all_widget_values (widget_info *info, Boolean deep_p) update_one_widget_instance (instance, deep_p); for (val = info->val; val; val = val->next) - val->change = NO_CHANGE; + { + val->change = NO_CHANGE; + if (val->args) + val->args->args_changed = False; + } } void @@ -822,16 +829,35 @@ initialize_widget_instance (widget_instance *instance) update_one_widget_instance (instance, True); for (val = instance->info->val; val; val = val->next) - val->change = NO_CHANGE; + { + val->change = NO_CHANGE; + if (val->args) + val->args->args_changed = False; + } } +/* strcasecmp() is not sufficiently portable or standard, + and it's easier just to write our own. */ +static int +ascii_strcasecmp (const char *s1, const char *s2) +{ + while (1) + { + char c1 = *s1++; + char c2 = *s2++; + if (c1 >= 'A' && c1 <= 'Z') c1 += 'a' - 'A'; + if (c2 >= 'A' && c2 <= 'Z') c2 += 'a' - 'A'; + if (c1 != c2) return c1 - c2; + if (c1 == '\0') return 0; + } +} static widget_creation_function -find_in_table (const char *type, widget_creation_entry *table) +find_in_table (const char *type, const widget_creation_entry table[]) { - widget_creation_entry *cur; + const widget_creation_entry *cur; for (cur = table; cur->type; cur++) - if (!strcasecmp (type, cur->type)) + if (!ascii_strcasecmp (type, cur->type)) return cur->function; return NULL; } @@ -1049,14 +1075,14 @@ lw_destroy_all_widgets (LWLIB_ID id) } void -lw_destroy_everything () +lw_destroy_everything (void) { while (all_widget_info) lw_destroy_all_widgets (all_widget_info->id); } void -lw_destroy_all_pop_ups () +lw_destroy_all_pop_ups (void) { widget_info *info; widget_info *next; @@ -1363,8 +1389,25 @@ void lw_add_value_args_to_args (widget_value* wv, ArgList addto, int* offset) } } +XtArgVal lw_get_value_arg (widget_value* wv, String name) +{ + int i; + if (wv->args) + { + for (i = 0; i < wv->args->nargs; i++) + { + if (!strcmp (wv->args->args[i].name, name)) + { + return wv->args->args[i].value; + } + } + } + return (XtArgVal)0; +} + void lw_add_widget_value_arg (widget_value* wv, String name, XtArgVal value) { + int i = 0; if (!wv->args) { wv->args = (widget_args *) malloc (sizeof (widget_args)); @@ -1378,7 +1421,21 @@ void lw_add_widget_value_arg (widget_value* wv, String name, XtArgVal value) if (wv->args->nargs > 10) return; - XtSetArg (wv->args->args [wv->args->nargs], name, value); wv->args->nargs++; + /* Register the change. */ + wv->args->args_changed = True; + /* If the arg is already there then we must replace it. */ + for (i = 0; i < wv->args->nargs; i++) + { + if (!strcmp (wv->args->args[i].name, name)) + { + XtSetArg (wv->args->args [i], name, value); + break; + } + } + if (i >= wv->args->nargs) + { + XtSetArg (wv->args->args [wv->args->nargs], name, value); wv->args->nargs++; + } } static void free_widget_value_args (widget_value* wv) @@ -1397,23 +1454,46 @@ static void free_widget_value_args (widget_value* wv) #endif free (wv->args->args); free (wv->args); - wv->args = (widget_args*)0xDEADBEEF; + wv->args = 0; } } } void lw_copy_widget_value_args (widget_value* val, widget_value* copy) { - if (!val->args) + if (val == copy || val->args == copy->args) + return; + + if (copy->args) { - if (copy->args) - free_widget_value_args (copy); - copy->args = 0; + free_widget_value_args (copy); } - else + + if (val->args) { copy->args = val->args; copy->args->ref_count++; } } +/* Remove %_ and convert %% to %. We can do this in-place because we + are always shortening, never lengthening, the string. */ +void +lw_remove_accelerator_spec (char *val) +{ + char *foo = val, *bar = val; + + while (*bar) + { + if (*bar == '%' && *(bar+1) == '_') + bar += 2; + else if (*bar == '%' && *(bar+1) == '%') + { + *foo++ = *bar++; + bar++; + } + else + *foo++ = *bar++; + } + *foo = '\0'; +}