changeset 14417:64e28f46c695

[gaim-migrate @ 17125] This should fix the problem where multi-column characters would screw up a window-title. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 02 Sep 2006 06:24:50 +0000
parents eeca8be382a5
children 010d8433db81
files configure.ac console/libgnt/configure.ac console/libgnt/gntbox.c console/libgnt/gntutils.c
diffstat 4 files changed, 12 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Sat Sep 02 05:31:10 2006 +0000
+++ b/configure.ac	Sat Sep 02 06:24:50 2006 +0000
@@ -820,6 +820,7 @@
 fi
 AC_SUBST(GNT_LIBS)
 AM_CONDITIONAL(ENABLE_GNT, test "x$enable_gnt" = "xyes")
+AC_CHECK_FUNC(wcwidth, [AC_DEFINE([HAVE_WCWIDTH], [1], [Define to 1 if you have wcwidth function.])])
 
 dnl #######################################################################
 dnl # Look for startup-notification, evolution integration, X-libraries,
--- a/console/libgnt/configure.ac	Sat Sep 02 05:31:10 2006 +0000
+++ b/console/libgnt/configure.ac	Sat Sep 02 06:24:50 2006 +0000
@@ -198,6 +198,7 @@
 AC_CHECK_HEADERS(sys/file.h sys/filio.h sys/ioctl.h sys/msgbuf.h)
 AC_CHECK_HEADERS(sys/select.h sys/uio.h sys/utsname.h sys/wait.h)
 AC_CHECK_HEADERS(termios.h)
+AC_CHECK_FUNC(wcwidth, [AC_DEFINE([HAVE_WCWIDTH], [1], [Define to 1 if you have wcwidth function.])])
 #AC_VAR_TIMEZONE_EXTERNALS
 
 AC_CHECK_LIB(ncursesw, initscr, , [AC_MSG_ERROR([
--- a/console/libgnt/gntbox.c	Sat Sep 02 05:31:10 2006 +0000
+++ b/console/libgnt/gntbox.c	Sat Sep 02 06:24:50 2006 +0000
@@ -1,4 +1,5 @@
 #include "gntbox.h"
+#include "gntutils.h"
 
 #include <string.h>
 
@@ -28,26 +29,14 @@
 get_title_thingies(GntBox *box, char *title, int *p, int *r)
 {
 	GntWidget *widget = GNT_WIDGET(box);
-	int pos = g_utf8_strlen(title, -1), right;
-
-	if (pos >= widget->priv.width - 4)
-	{
-		g_utf8_strncpy(title, title, widget->priv.width - 4);
-		pos = 2;
-		right = pos + g_utf8_strlen(title, -1);
-	}
-	else
-	{
-		/* XXX: Position of the title might be configurable */
-		right = pos;
-		pos = (widget->priv.width - pos) / 2;
-		right += pos;
-	}
-
+	int len;
+	char *end = gnt_util_onscreen_width_to_pointer(title, widget->priv.width - 4, &len);
+	
 	if (p)
-		*p = pos;
+		*p = (widget->priv.width - len) / 2;
 	if (r)
-		*r = right;
+		*r = (widget->priv.width + len) / 2;
+	*end = '\0';
 }
 
 static void
--- a/console/libgnt/gntutils.c	Sat Sep 02 05:31:10 2006 +0000
+++ b/console/libgnt/gntutils.c	Sat Sep 02 06:24:50 2006 +0000
@@ -4,7 +4,9 @@
 #include <string.h>
 #include <wchar.h>
 
-#ifndef __USE_XOPEN
+#include "config.h"
+
+#ifndef HAVE_WCWIDTH
 #define wcwidth(X) 1
 #endif