Mercurial > dwindows
changeset 72:ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 15 Feb 2002 09:30:50 +0000 |
parents | 291c30a92b9b |
children | 2f339dd13496 |
files | compat.c compat.h dwcompat.def dwcompatw.def gtk/dw.c os2/dw.c win/dw.c |
diffstat | 7 files changed, 149 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/compat.c Sun Feb 10 18:22:25 2002 +0000 +++ b/compat.c Fri Feb 15 09:30:50 2002 +0000 @@ -730,3 +730,103 @@ { return fseek(stream, offset, whence); } + +static int locale_number = -1, locale_count = 0; +static char **locale_text = NULL; + +void _free_locale(void) +{ + if(locale_text) + { + int z; + + for(z=0;z<locale_count;z++) + { + if(locale_text[z]) + free(locale_text[z]); + } + free(locale_text); + locale_text = NULL; + } +} + +void _stripcrlf(char *buf) +{ + int z, len = strlen(buf); + + for(z=0;z<len;z++) + { + if(buf[z] == '\r' || buf[z] == '\n') + { + buf[z] = 0; + return; + } + } +} + +/* Initialize the locale engine + * Returns: TRUE on success, FALSE on failure. + */ +int locale_init(char *filename, int my_locale) +{ + FILE *fp = fopen(filename, FOPEN_READ_TEXT); + static char text[1025]; + int count = 0; + + _free_locale(); + + if(fp) + { + + fgets(text, 1024, fp); + if(strncasecmp(text, "MESSAGES=", 9) == 0 && (count = atoi(&text[9])) > 0) + { + int current = -1; + + locale_text = calloc(count, sizeof(char *)); + + while(!feof(fp)) + { + fgets(text, 1024, fp); + _stripcrlf(text); + + if(strncasecmp(text, "LOCALE=", 7) == 0) + { + if(current > -1) + { + fclose(fp); + locale_count = count; + locale_number = my_locale; + return 1; + } + if(atoi(&text[7]) == my_locale) + current = 0; + } + else if(current > -1 && current < count) + { + /* Use defaults on blank lines */ + if(text[0]) + locale_text[current] = strdup(text); + current++; + } + } + } + fclose(fp); + } + if(locale_text && count) + { + locale_count = count; + locale_number = my_locale; + return 1; + } + return 0; +} + +/* Retrieve a localized string if available */ +char *locale_string(char *default_text, int message) +{ + if(locale_number > -1 && message < locale_count && message > -1 && locale_text[message]) + return locale_text[message]; + return default_text; +} +
--- a/compat.h Sun Feb 10 18:22:25 2002 +0000 +++ b/compat.h Fri Feb 15 09:30:50 2002 +0000 @@ -209,4 +209,6 @@ int fsclose(FILE *fp); char *fsgets(char *str, int size, FILE *stream); int fsseek(FILE *stream, long offset, int whence); +int locale_init(char *filename, int my_locale); +char *locale_string(char *default_text, int message);
--- a/dwcompat.def Sun Feb 10 18:22:25 2002 +0000 +++ b/dwcompat.def Fri Feb 15 09:30:50 2002 +0000 @@ -36,3 +36,6 @@ fsclose @41 fsgets @42 fsseek @43 + + locale_init @50 + locale_string @51
--- a/dwcompatw.def Sun Feb 10 18:22:25 2002 +0000 +++ b/dwcompatw.def Fri Feb 15 09:30:50 2002 +0000 @@ -32,3 +32,6 @@ fsgets @42 fsseek @43 + locale_init @50 + locale_string @51 +
--- a/gtk/dw.c Sun Feb 10 18:22:25 2002 +0000 +++ b/gtk/dw.c Fri Feb 15 09:30:50 2002 +0000 @@ -3263,6 +3263,7 @@ gtk_clist_set_column_auto_resize(GTK_CLIST(clist), 0, TRUE); gtk_clist_set_selection_mode(GTK_CLIST(clist), GTK_SELECTION_SINGLE); gtk_container_add(GTK_CONTAINER(handle), clist); + gtk_object_set_data(GTK_OBJECT(clist), "multi", (gpointer)0); gtk_object_set_user_data(GTK_OBJECT(handle), (gpointer)clist); gtk_widget_show(clist); gtk_object_set_data(GTK_OBJECT(clist), "colcount", (gpointer)count); @@ -3348,6 +3349,18 @@ { } +/* Clears a CList selection and associated selection list */ +void _dw_unselect(GtkWidget *clist) +{ + GList *list = (GList *)gtk_object_get_data(GTK_OBJECT(clist), "selectlist"); + + if(list) + g_list_free(list); + + gtk_object_set_data(GTK_OBJECT(clist), "selectlist", NULL); + gtk_clist_unselect_all(GTK_CLIST(clist)); +} + /* * Allocates memory used to populate a container. * Parameters: @@ -3569,7 +3582,6 @@ void dw_container_delete(HWND handle, int rowcount) { GtkWidget *clist; - GList *list; int _locked_by_me = FALSE; DW_MUTEX_LOCK; @@ -3578,9 +3590,9 @@ { int rows, z; - list = (GList *)gtk_object_get_data(GTK_OBJECT(clist), "selectlist"); rows = (int)gtk_object_get_data(GTK_OBJECT(clist), "rowcount"); - g_list_free(list); + + _dw_unselect(clist); for(z=0;z<rowcount;z++) gtk_clist_remove(GTK_CLIST(clist), 0); @@ -3590,7 +3602,6 @@ else rows -= rowcount; - gtk_object_set_data(GTK_OBJECT(clist), "selectlist", NULL); gtk_object_set_data(GTK_OBJECT(clist), "rowcount", (gpointer)rows); } DW_MUTEX_UNLOCK; @@ -3605,16 +3616,13 @@ void dw_container_clear(HWND handle, int redraw) { GtkWidget *clist; - GList *list; int _locked_by_me = FALSE; DW_MUTEX_LOCK; clist = (GtkWidget*)gtk_object_get_user_data(GTK_OBJECT(handle)); if(clist && GTK_IS_CLIST(clist)) { - list = (GList *)gtk_object_get_data(GTK_OBJECT(clist), "selectlist"); - g_list_free(list); - gtk_object_set_data(GTK_OBJECT(clist), "selectlist", NULL); + _dw_unselect(clist); gtk_clist_clear(GTK_CLIST(clist)); gtk_object_set_data(GTK_OBJECT(clist), "rowcount", (gpointer)0); } @@ -3811,6 +3819,9 @@ { gfloat pos; GtkAdjustment *adj = gtk_clist_get_vadjustment(GTK_CLIST(clist)); + + _dw_unselect(clist); + gtk_clist_select_row(GTK_CLIST(clist), z, 0); pos = ((adj->upper - adj->lower) * ((gfloat)z/(gfloat)rowcount)) + adj->lower;
--- a/os2/dw.c Sun Feb 10 18:22:25 2002 +0000 +++ b/os2/dw.c Fri Feb 15 09:30:50 2002 +0000 @@ -5424,7 +5424,7 @@ z++; if(z > 5000000) break; - DosSleep(1); + dw_main_sleep(1); } if(!blah) @@ -5474,9 +5474,15 @@ temp = (PRECORDCORE)ci->data; - if(!WinSendMsg(handle, CM_QUERYCNRINFO, (MPARAM)&cnr, MPFROMSHORT(sizeof(CNRINFO)))) - return; - + z = 0; + + while(WinSendMsg(handle, CM_QUERYCNRINFO, (MPARAM)&cnr, MPFROMSHORT(sizeof(CNRINFO))) == 0) + { + z++; + if(z > 5000000) + return; + dw_main_sleep(1); + } currentcount = cnr.cRecords; /* Figure out the offsets to the items in the struct */ @@ -5572,7 +5578,15 @@ temp = (PRECORDCORE)ci->data; - WinSendMsg(ci->handle, CM_QUERYCNRINFO, (MPARAM)&cnr, MPFROMSHORT(sizeof(CNRINFO))); + z = 0; + + while(WinSendMsg(ci->handle, CM_QUERYCNRINFO, (MPARAM)&cnr, MPFROMSHORT(sizeof(CNRINFO))) == 0) + { + z++; + if(z > 5000000) + return; + dw_main_sleep(1); + } currentcount = cnr.cRecords; for(z=0;z<(row-currentcount);z++) @@ -5613,7 +5627,7 @@ z++; if(z > 5000000) break; - DosSleep(1); + dw_main_sleep(1); } free(ci); @@ -5634,7 +5648,7 @@ z++; if(z > 5000000) break; - DosSleep(1); + dw_main_sleep(1); } } @@ -5664,7 +5678,7 @@ z++; if(z > 5000000) break; - DosSleep(1); + dw_main_sleep(1); } free(prc);