Internationalize the file browser.
authorTim Mann <tim@tim-mann.org>
Fri, 10 Jun 2011 06:57:43 +0000 (23:57 -0700)
committerTim Mann <tim@tim-mann.org>
Fri, 10 Jun 2011 06:57:43 +0000 (23:57 -0700)
The file browser was missed in the previous round of
internationalization and had gotten broken by setting international =
True in its widgets.  I got nothing but segfaults trying to set
international to False in the file browser widget subtree when it was
True in the main window, so I gave up and did the
internationalization.  It turned out to be pretty easy.

As a tiny bonus fix, I removed some ../'s from includes, and you can
now configure and build xboard in a subdirectory again.  This was
useful for building both --enable-nls and --disable-nls from the same
sources to compare functionality and make sure both still work.

filebrowser/dir.c
filebrowser/draw.c
filebrowser/path.c
filebrowser/selfile.c
filebrowser/selfile.h

index 918d555..40d13fb 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <stdio.h>
 #include <stdlib.h> /* for qsort */
-#include "../config.h" /* to check for dirent.h */
+#include "config.h" /* to check for dirent.h */
 
 #ifdef SEL_FILE_IGNORE_CASE
 #include <ctype.h>
index 048fa85..4f8abaa 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include "xstat.h"
 #include "selfile.h"
+#include "config.h"
 #include <X11/StringDefs.h>
 #include <X11/Xaw/Scrollbar.h>
 #include <X11/Xaw/Cardinals.h>
@@ -53,7 +54,11 @@ static XtResource textResources[] = {
                XtOffset(textPtr, fontname), XtRString, SF_DEFAULT_FONT},
 };
 
+#if ENABLE_NLS
+extern XFontSet fontSet; //XXX should really be in a .h file
+#else
 static XFontStruct *SFfont;
+#endif
 
 static int SFcurrentListY;
 
@@ -62,6 +67,12 @@ static XtIntervalId SFscrollTimerId;
 void
 SFinitFont()
 {
+#if ENABLE_NLS
+       XFontSetExtents *fse = XExtentsOfFontSet(fontSet);
+       SFcharWidth = fse->max_logical_extent.width;
+       SFcharAscent = -fse->max_logical_extent.y;
+       SFcharHeight = fse->max_logical_extent.height;
+#else
        TextData        *data;
 
        data = XtNew(TextData);
@@ -85,6 +96,7 @@ SFinitFont()
        SFcharWidth = (SFfont->max_bounds.width + SFfont->min_bounds.width) / 2;
        SFcharAscent = SFfont->max_bounds.ascent;
        SFcharHeight = SFcharAscent + SFfont->max_bounds.descent;
+#endif
        return;
 }
 
@@ -125,7 +137,9 @@ SFcreateGC()
 
        gcValues.foreground = SFfore;
        gcValues.background = SFback;
+#if !ENABLE_NLS
        gcValues.font = SFfont->fid;
+#endif
 
        SFtextGC = XCreateGC(
                SFdisplay,
@@ -133,7 +147,9 @@ SFcreateGC()
                (unsigned long)
                        GCForeground            |
                        GCBackground            |
+#if !ENABLE_NLS
                        GCFont                  |
+#endif
                        0,
                &gcValues
        );
@@ -355,6 +371,18 @@ SFdrawStrings(w, dir, from, to)
                                continue;
                        }
                }
+#if ENABLE_NLS
+               XmbDrawImageString(
+                       SFdisplay,
+                       w,
+                       fontSet,
+                       SFtextGC,
+                       x,
+                       SFtextYoffset + i * SFentryHeight,
+                       entry->shown,
+                       strlen(entry->shown)
+               );
+#else
                XDrawImageString(
                        SFdisplay,
                        w,
@@ -364,6 +392,7 @@ SFdrawStrings(w, dir, from, to)
                        entry->shown,
                        strlen(entry->shown)
                );
+#endif
                if (dir->vOrigin + i == dir->beginSelection) {
                        XDrawLine(
                                SFdisplay,
@@ -419,6 +448,18 @@ SFdrawList(n, doScroll)
        if (SFdirPtr + (3-NR) + n < SFdirEnd) {
                dir = &(SFdirs[SFdirPtr + n + (3-NR)]);
                w = XtWindow(selFileLists[n]);
+#if ENABLE_NLS
+               XmbDrawImageString(
+                       SFdisplay,
+                       w,
+                       fontSet,
+                       SFtextGC,
+                       SFtextX - dir->hOrigin * SFcharWidth,
+                       SFlineToTextV + SFaboveAndBelowText + SFcharAscent,
+                       dir->dir,
+                       strlen(dir->dir)
+               );
+#else
                XDrawImageString(
                        SFdisplay,
                        w,
@@ -428,6 +469,7 @@ SFdrawList(n, doScroll)
                        dir->dir,
                        strlen(dir->dir)
                );
+#endif
                SFdrawStrings(w, dir, 0, SFlistSize - 1);
        }
        return;
index a68b7c1..66c9ab5 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <stdio.h>
 #include <stdlib.h> /* for qsort */
-#include "../config.h"
+#include "config.h"
 
 #ifdef SEL_FILE_IGNORE_CASE
 #include <ctype.h>
@@ -182,23 +182,6 @@ SFstrncmp(p, q, n)
 }
 #endif /* def SEL_FILE_IGNORE_CASE */
 
-void
-SFsetText(path)
-       char    *path;
-{
-       XawTextBlock    text;
-
-       text.firstPos = 0;
-       text.length = strlen(path);
-       text.ptr = path;
-       text.format = FMT8BIT;
-
-       XawTextReplace(selFileField, 0, strlen(SFtextBuffer), &text);
-       XawTextSetInsertionPoint(selFileField, strlen(SFtextBuffer));
-
-       return;
-}
-
 static void
 SFreplaceText(dir, str)
        SFDir   *dir;
index 3a597b0..71dcd8c 100644 (file)
@@ -74,10 +74,10 @@ extern char *getwd();
 int SFstatus = SEL_FILE_NULL;
 
 char
-       SFstartDir[MAXPATHLEN],
-       SFcurrentPath[MAXPATHLEN],
-       SFlastPath[MAXPATHLEN],
-       SFcurrentDir[MAXPATHLEN];
+       SFstartDir[MAXPATHLEN+1],
+       SFcurrentPath[MAXPATHLEN+1],
+       SFlastPath[MAXPATHLEN+1],
+       SFcurrentDir[MAXPATHLEN+1];
 
 Widget
        selFile,
@@ -127,9 +127,9 @@ XtAppContext SFapp;
 
 int SFpathScrollWidth, SFvScrollHeight, SFhScrollWidth;
 
-char SFtextBuffer[MAXPATHLEN];
+char SFtextBuffer[MAXPATHLEN+1];
 
-char SFfilterBuffer[MAXPATHLEN];
+char SFfilterBuffer[MAXPATHLEN+1];
 
 XtIntervalId SFdirModTimerId;
 
@@ -383,7 +383,6 @@ SFcreateWidgets(toplevel, prompt, ok, cancel)
        XtSetArg(arglist[i], XtNeditType, XawtextEdit);                 i++;
        XtSetArg(arglist[i], XtNwrap, XawtextWrapWord);                 i++;
        XtSetArg(arglist[i], XtNresize, XawtextResizeHeight);           i++;
-       XtSetArg(arglist[i], XtNuseStringInPlace, True);                i++;
        selFileField = XtCreateManagedWidget("selFileField",
                asciiTextWidgetClass, selFileForm, arglist, i);
 
@@ -678,9 +677,36 @@ SFopenFile(name, mode, prompt, failed)
     return fp;
 }
 
+void
+SFupdateTextBuffer()
+{
+       Arg arglist[2];
+       int i;
+       char *v;
+
+       i = 0;
+       XtSetArg(arglist[i], XtNstring, &v);  i++;
+       XtGetValues(selFileField, arglist, i);
+       strncpy(SFtextBuffer, v, MAXPATHLEN);
+}
+
+void
+SFsetText(path)
+       char    *path;
+{
+       Arg arglist[2];
+       int i;
+
+       i = 0;
+       XtSetArg(arglist[i], XtNstring, path);  i++;
+       XtSetValues(selFileField, arglist, i);
+       XawTextSetInsertionPoint(selFileField, strlen(path));
+}
+
 void
 SFtextChanged()
 {
+       SFupdateTextBuffer();
 
        if ((SFtextBuffer[0] == '/') || (SFtextBuffer[0] == '~')) {
          (void) strncpy(SFcurrentPath, SFtextBuffer, MAXPATHLEN);
@@ -786,6 +812,7 @@ XsraSelFile(toplevel, prompt, ok, cancel, failed,
        XtSetValues(filterField, arglist, i);
 
        strncpy(SFfilterBuffer, filter, MAXPATHLEN-1);
+       SFupdateTextBuffer();
        strncpy(SFlastPath, SFtextBuffer, MAXPATHLEN-1); // remember for cancel
 
        SFpositionWidget(selFile);
@@ -861,4 +888,5 @@ XsraSelFile(toplevel, prompt, ok, cancel, failed,
                        break;
                }
        }
+
 }
index 525b1c2..19036bf 100644 (file)
@@ -135,8 +135,6 @@ extern XtAppContext SFapp;
 
 extern int SFpathScrollWidth, SFvScrollHeight, SFhScrollWidth;
 
-extern char SFtextBuffer[];
-
 extern char SFfilterBuffer[];
 
 extern int SFbuttonPressed;