Daichi Kawahata wrote:
> I'm afraid but in GTK2, same thing happens against the config_gnet and
> config_gui files while tooltips are new-lined correctly.

Well, the text itself (usually) doesn't contain any newline characters,
so the line breaks in tooltips are added by GTK+ itself. The comments in
configuration files are forced to about 72 characters at maximum per line.
However, if the text doesn't contain ASCII spaces or the text between
those is longer, the text won't be broken down.
If you can insert newlines after any character in Japanese, a hard limit
could be enforced. In most other languages this limit wouldn't be reached
because words are comparatively short.
 
> > Sounds OK to me; lines shouldn't be longer than about 60-70 characters.
> > However, it might be better to add line breaks automagically when assigning
> > the tooltips.
 
> OK, I'm pending this case.

I've tried to enforce linebreaks after a maximum amount of characters for
tooltips. This works for GTK+ 2.x but GTK+ 2.x doesn't have a problem with
this anyway. When using GTK+ 1.2, this causes empty lines after each
line break because GTK+ 1.2 seems to add an additional line break. It also
actually uses strlen() to determine the line length. So it's no wonder
that the tooltips have irregular line breaks. Again, line breaks will only
be inserted at ASCII spaces. If the tooltip text doesn't contain any, you
will simply get a very wide tooltip.

Therefore, I think it's best if the text that causes ugly (large) tooltips
is modified, so that at least line breaks can be inserted. The irregular
line breaks cannot really be prevented.

Try the attached patch to see how it looks if line breaks are automagically
added.

-- 
Christian
Index: ./ui/gtk/settings.c
===================================================================
RCS file: /cvsroot/gtk-gnutella/gtk-gnutella-current/src/ui/gtk/settings.c,v
retrieving revision 1.29
diff -u -r1.29 settings.c
--- src/ui/gtk/settings.c       21 Nov 2004 21:12:42 -0000      1.29
+++ src/ui/gtk/settings.c       8 Dec 2004 23:09:23 -0000
@@ -47,6 +47,7 @@
 
 #include "lib/prop.h"
 #include "lib/glib-missing.h"
+#include "lib/utf8.h"
 #include "lib/override.h"              /* Must be the last header included */
 
 /* Uncomment to override debug level for this file. */
@@ -2523,7 +2524,42 @@
                        if (!GTK_IS_TREE_VIEW(w))
 #endif
                        {
-               gtk_tooltips_set_tip(tooltips, w, def->desc, "");
+                               GString *gs = g_string_new("");
+                               const gchar *s;
+                               gint len = 0; /* Length of the current row in 
characters */
+                               gint c, clen;
+
+                               /* Force a line break after about 40 characters 
to prevent
+                                * very wide tooltips and irregular line break. 
*/
+                               
+                               for (s = def->desc; (c = *s) != '\0'; s += 
clen) {
+                                       gchar utf8_char[7];
+                                       
+                                       clen = utf8_is_valid_char(s);
+                                       /* If the charset isn't UTF-8 (often 
the case with
+                                        * GTK+ 1.2), just copy a single byte */
+                                       clen = MAX(1, clen);
+                                       g_assert(clen > 0 && clen < 7);
+
+                                       /* Add a line break at the softlimit */
+                                       if (c == ' ' && len > 40) {
+                                               gs = g_string_append_c(gs, 
'\n');
+                                               len = 0;
+                                       } else {
+                                               /* Append a single (UTF-8) 
character */
+                                               g_strlcpy(utf8_char, s, clen + 
1);
+                                               gs = g_string_append(gs, 
utf8_char);
+                                               len++;
+
+                                               if (c == '\n') {
+                                                       len = 0;
+                                               }
+                                       }
+                               }
+                               
+               gtk_tooltips_set_tip(tooltips, w, gs->str, "");
+                               g_string_free(gs, TRUE);
+                               
                                if (gui_debug >= 9)
                                        printf("\t...added tooltip\n");
                        }

Attachment: pgpIpfRK8t8WE.pgp
Description: PGP signature

Reply via email to