diff -rcN --exclude=Makefile --exclude=X11 ../xclock/Clock.c ./Clock.c *** ../xclock/Clock.c Mon Apr 18 09:23:50 1994 --- ./Clock.c Fri Jan 29 18:38:34 1999 *************** *** 118,125 **** --- 118,136 ---- offset(padding), XtRImmediate, (XtPointer) 8}, {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), offset(font), XtRString, XtDefaultFont}, + #ifdef I18N + {XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet), + offset(fs), XtRString, XtDefaultFontSet}, + {XtNfontList, XtCString, XtRString, sizeof(String), + offset(font_list), XtRImmediate, (XtPointer) NULL}, + #endif {XtNbackingStore, XtCBackingStore, XtRBackingStore, sizeof (int), offset (backing_store), XtRString, "default"}, + #ifdef NO_STRFTIME + #else + {XtNformat, XtCString, XtRString, sizeof(String), + offset(format), XtRImmediate, (XtPointer) NULL}, + #endif }; #undef offset *************** *** 211,225 **** --- 222,280 ---- (void) time(&time_value); tm = *localtime(&time_value); + #ifdef NO_STRFTIME str = asctime(&tm); + #else + { + #define format (w->clock.format?w->clock.format:"%c") + static int size = 8; + str = (char*)malloc(sizeof(char)*size); + while (strftime(str, size, format, &tm) == 0 + && strlen(format) != 0) { + size += 8; + str = (char*)realloc(str, sizeof(char)*size); + } + size = strlen(str) + 1; + } + #endif + w->clock.prev_time_string = (char*)malloc(sizeof(char)*(strlen(str)+10)); + #ifdef I18N + { + XFontSet fs; + char **miss, *def; + int n_miss; + + if (w->clock.font_list) { + fs = XCreateFontSet(XtDisplay(w), w->clock.font_list, + &miss, &n_miss, &def); + if (fs) + w->clock.fs = fs; + } + } + #else if (w->clock.font == NULL) w->clock.font = XQueryFont( XtDisplay(w), XGContextFromGC( DefaultGCOfScreen(XtScreen(w))) ); + #endif + #ifdef I18N + { + XRectangle ink, log; + + XmbTextExtents(w->clock.fs, str, strlen(str), &ink, &log); + min_width = log.width + 2 * w->clock.padding; + min_height = log.height + 2 * w->clock.padding; + } + #else min_width = XTextWidth(w->clock.font, str, strlen(str)) + 2 * w->clock.padding; min_height = w->clock.font->ascent + w->clock.font->descent + 2 * w->clock.padding; + #endif + #ifdef NO_STRFTIME + #else + free(str); + #endif } if (w->core.width == 0) w->core.width = min_width; *************** *** 362,368 **** --- 417,436 ---- int clear_from; int i, len, prev_len; + #ifdef NO_STRFTIME time_ptr = asctime(&tm); + #else + { + static int size = 8; + time_ptr = (char*)malloc(sizeof(char)*size); + while (strftime(time_ptr, size, format, &tm) == 0 + && strlen(format) != 0) { + size += 8; + time_ptr = (char*)realloc(time_ptr, sizeof(char)*size); + } + size = strlen(time_ptr) + 1; + } + #endif len = strlen (time_ptr); if (time_ptr[len - 1] == '\n') time_ptr[--len] = '\0'; prev_len = strlen (w->clock.prev_time_string); *************** *** 370,385 **** --- 438,478 ---- (w->clock.prev_time_string[i] == time_ptr[i])); i++); strcpy (w->clock.prev_time_string+i, time_ptr+i); + #ifdef I18N + { + XRectangle ink, log; + + XmbTextExtents(w->clock.fs, time_ptr, i, &ink, &log); + XmbDrawImageString(dpy, win, w->clock.fs, w->clock.myGC, + w->clock.padding + log.width, + w->core.height - w->clock.padding - 2, + time_ptr + i, len - i); + } + #else XDrawImageString (dpy, win, w->clock.myGC, (2+w->clock.padding + XTextWidth (w->clock.font, time_ptr, i)), 2+w->clock.font->ascent+w->clock.padding, time_ptr + i, len - i); + #endif /* * Clear any left over bits */ + #ifdef I18N + { + XRectangle ink, log; + + XmbTextExtents(w->clock.fs, time_ptr, len, &ink, &log); + clear_from = log.width + 2 + w->clock.padding; + } + #else clear_from = XTextWidth (w->clock.font, time_ptr, len) + 2 + w->clock.padding; + #endif + #ifdef NO_STRFTIME + #else + free(time_ptr); + #endif if (clear_from < (int)w->core.width) XFillRectangle (dpy, win, w->clock.EraseGC, clear_from, 0, w->core.width - clear_from, w->core.height); *************** *** 824,829 **** --- 917,926 ---- if (new->clock.font != current->clock.font) redisplay = TRUE; + #ifdef I18N + if (new->clock.fs != current->clock.fs) + redisplay = TRUE; + #endif if ((new->clock.fgpixel != current->clock.fgpixel) || (new->core.background_pixel != current->core.background_pixel)) { diff -rcN --exclude=Makefile --exclude=X11 ../xclock/Clock.h ./Clock.h *** ../xclock/Clock.h Mon Apr 18 09:23:51 1994 --- ./Clock.h Fri Jan 29 18:38:34 1999 *************** *** 102,107 **** --- 102,118 ---- /* Int: amount of space around outside of clock */ #define XtNpadding "padding" + #ifdef I18N + /* String: font list for font set ifdef I18N */ + #define XtNfontList "fontList" + #endif + + #ifdef NO_STRFTIME + #else + /* String: strftime format if digital */ + #define XtNformat "format" + #endif + typedef struct _ClockRec *ClockWidget; /* completely defined in ClockPrivate.h */ typedef struct _ClockClassRec *ClockWidgetClass; /* completely defined in ClockPrivate.h */ diff -rcN --exclude=Makefile --exclude=X11 ../xclock/ClockP.h ./ClockP.h *** ../xclock/ClockP.h Mon Apr 18 09:23:53 1994 --- ./ClockP.h Fri Jan 29 18:38:34 1999 *************** *** 59,65 **** #include #define SEG_BUFF_SIZE 128 - #define ASCII_TIME_BUFLEN 32 /* big enough for 26 plus slop */ /* New fields for the clock widget instance record */ typedef struct { --- 59,64 ---- *************** *** 67,72 **** --- 66,75 ---- Pixel Hipixel; /* color index for Highlighting */ Pixel Hdpixel; /* color index for hands */ XFontStruct *font; /* font for text */ + #ifdef I18N + XFontSet fs; /* font set for text */ + String font_list; /* font list for font set */ + #endif GC myGC; /* pointer to GraphicsContext */ GC EraseGC; /* eraser GC */ GC HandGC; /* Hand GC */ *************** *** 93,99 **** XPoint *hour, *sec; struct tm otm ; XtIntervalId interval_id; ! char prev_time_string[ASCII_TIME_BUFLEN]; } ClockPart; /* Full instance record declaration */ --- 96,106 ---- XPoint *hour, *sec; struct tm otm ; XtIntervalId interval_id; ! char *prev_time_string; ! #ifdef NO_STRFTIME ! #else ! String format; ! #endif } ClockPart; /* Full instance record declaration */ diff -rcN --exclude=Makefile --exclude=X11 ../xclock/Imakefile ./Imakefile *** ../xclock/Imakefile Thu Jan 20 10:23:21 1994 --- ./Imakefile Fri Jan 29 18:40:31 1999 *************** *** 4,9 **** --- 4,11 ---- SRCS = xclock.c Clock.c OBJS = xclock.o Clock.o HEADERS = ClockP.h Clock.h + # DEFINES = -DNO_STRFTIME + DEFINES = -DI18N ComplexProgramTarget(xclock) InstallAppDefaults(XClock) diff -rcN --exclude=Makefile --exclude=X11 ../xclock/xclock.c ./xclock.c *** ../xclock/xclock.c Mon Apr 18 09:23:54 1994 --- ./xclock.c Fri Jan 29 18:38:34 1999 *************** *** 44,49 **** --- 44,52 ---- pass over the remaining options after XtParseCommand is let loose. */ static XrmOptionDescRec options[] = { + #ifdef I18N + {"-fn", "*clock.fontList", XrmoptionSepArg, NULL}, + #endif {"-chime", "*clock.chime", XrmoptionNoArg, "TRUE"}, {"-hd", "*clock.hands", XrmoptionSepArg, NULL}, {"-hands", "*clock.hands", XrmoptionSepArg, NULL}, *************** *** 54,59 **** --- 57,66 ---- {"-d", "*clock.analog", XrmoptionNoArg, "FALSE"}, {"-digital", "*clock.analog", XrmoptionNoArg, "FALSE"}, {"-analog", "*clock.analog", XrmoptionNoArg, "TRUE"}, + #ifdef NO_STRFTIME + #else + {"-format", "*clock.format", XrmoptionSepArg, NULL}, + #endif }; static void quit(); *************** *** 72,79 **** --- 79,94 ---- (void) printf ("Usage: %s [-analog] [-bw ] [-digital]\n", call); (void) printf (" [-fg ] [-bg ] [-hd ]\n"); (void) printf (" [-hl ] [-bd ]\n"); + #ifdef I18N + (void) printf (" [-fn ] [-help] [-padding ]\n"); + #else (void) printf (" [-fn ] [-help] [-padding ]\n"); + #endif (void) printf (" [-rv] [-update ] [-display displayname]\n"); + #ifdef NO_STRFTIME + #else + (void) printf (" [-format ]\n"); + #endif (void) printf (" [-geometry geom]\n\n"); exit(1); } *************** *** 124,129 **** --- 139,147 ---- Pixmap icon_pixmap = None; XtAppContext app_con; + #ifdef I18N + XtSetLanguageProc(NULL, NULL, NULL); + #endif toplevel = XtOpenApplication(&app_con, "XClock", options, XtNumber(options), &argc, argv, NULL, sessionShellWidgetClass, NULL, ZERO);