|
From: <sa...@us...> - 2006-09-02 18:56:23
|
Revision: 17128
http://svn.sourceforge.net/gaim/?rev=17128&view=rev
Author: sadrul
Date: 2006-09-02 11:55:27 -0700 (Sat, 02 Sep 2006)
Log Message:
-----------
Keep things neat and clean in gnt_util_onscreen_width_to_pointer.
The only use of this function currently is to truncate a string to
make sure it fits in the drawing area, eg, the title of a window,
or in the combobox. The function is called on a newly allocated
string, which is truncated (if necessary), printed, and freed.
Modified Paths:
--------------
trunk/console/libgnt/gntbox.c
trunk/console/libgnt/gntcombobox.c
trunk/console/libgnt/gntutils.c
trunk/console/libgnt/gntutils.h
trunk/console/libgnt/test/focus.c
Modified: trunk/console/libgnt/gntbox.c
===================================================================
--- trunk/console/libgnt/gntbox.c 2006-09-02 16:55:32 UTC (rev 17127)
+++ trunk/console/libgnt/gntbox.c 2006-09-02 18:55:27 UTC (rev 17128)
@@ -30,7 +30,7 @@
{
GntWidget *widget = GNT_WIDGET(box);
int len;
- char *end = gnt_util_onscreen_width_to_pointer(title, widget->priv.width - 4, &len);
+ char *end = (char*)gnt_util_onscreen_width_to_pointer(title, widget->priv.width - 4, &len);
if (p)
*p = (widget->priv.width - len) / 2;
Modified: trunk/console/libgnt/gntcombobox.c
===================================================================
--- trunk/console/libgnt/gntcombobox.c 2006-09-02 16:55:32 UTC (rev 17127)
+++ trunk/console/libgnt/gntcombobox.c 2006-09-02 18:55:27 UTC (rev 17128)
@@ -36,7 +36,7 @@
gnt_combo_box_draw(GntWidget *widget)
{
GntComboBox *box = GNT_COMBO_BOX(widget);
- char *text = NULL;
+ char *text = NULL, *s;
GntColorType type;
int len;
@@ -53,12 +53,8 @@
wbkgdset(widget->window, '\0' | COLOR_PAIR(type));
- if ((len = g_utf8_strlen(text, -1)) > widget->priv.width - 4)
- {
- char *s = gnt_util_onscreen_width_to_pointer(text, widget->priv.width - 4, NULL);
- *s = '\0';
- len = widget->priv.width - 4;
- }
+ s = (char*)gnt_util_onscreen_width_to_pointer(text, widget->priv.width - 4, &len);
+ *s = '\0';
mvwprintw(widget->window, 1, 1, text);
whline(widget->window, ' ' | COLOR_PAIR(type), widget->priv.width - 4 - len);
Modified: trunk/console/libgnt/gntutils.c
===================================================================
--- trunk/console/libgnt/gntutils.c 2006-09-02 16:55:32 UTC (rev 17127)
+++ trunk/console/libgnt/gntutils.c 2006-09-02 18:55:27 UTC (rev 17128)
@@ -20,15 +20,15 @@
if (*s == '\n' || *s == '\r')
{
count++;
- len = g_utf8_pointer_to_offset(last, s);
+ len = gnt_util_onscreen_width(last, s);
if (max < len)
max = len;
last = s + 1;
}
- s++;
+ s = g_utf8_next_char(s);
}
- len = g_utf8_pointer_to_offset(last, s);
+ len = gnt_util_onscreen_width(last, s);
if (max < len)
max = len;
}
@@ -50,11 +50,11 @@
return width;
}
-char *gnt_util_onscreen_width_to_pointer(const char *string, int len, int *w)
+const char *gnt_util_onscreen_width_to_pointer(const char *string, int len, int *w)
{
int size;
int width = 0;
- char *str = (char*)string;
+ const char *str = string;
while (width < len && *str) {
size = g_unichar_iswide(g_utf8_get_char(str)) ? 2 : 1;
Modified: trunk/console/libgnt/gntutils.h
===================================================================
--- trunk/console/libgnt/gntutils.h 2006-09-02 16:55:32 UTC (rev 17127)
+++ trunk/console/libgnt/gntutils.h 2006-09-02 18:55:27 UTC (rev 17128)
@@ -8,4 +8,4 @@
/* excluding *end */
int gnt_util_onscreen_width(const char *start, const char *end);
-char *gnt_util_onscreen_width_to_pointer(const char *str, int len, int *w);
+const char *gnt_util_onscreen_width_to_pointer(const char *str, int len, int *w);
Modified: trunk/console/libgnt/test/focus.c
===================================================================
--- trunk/console/libgnt/test/focus.c 2006-09-02 16:55:32 UTC (rev 17127)
+++ trunk/console/libgnt/test/focus.c 2006-09-02 18:55:27 UTC (rev 17128)
@@ -25,7 +25,7 @@
gnt_init();
#endif
- GntWidget *label = gnt_label_new("So wassup dudes and dudettes!!\nSo this is, like,\nthe third line!! \\o/");
+ GntWidget *label = gnt_label_new("So wassup dudes and dudettes!!\u4e0a1\u6d772\u67003\u4f4e4\u67085\nSo this is, like,\nthe third line!! \\o/");
GntWidget *vbox, *hbox, *tree, *box, *button;
WINDOW *test;
@@ -61,7 +61,7 @@
gnt_tree_add_choice(GNT_TREE(tree), "b", gnt_tree_create_row(GNT_TREE(tree), "b"), "d", NULL);
GNT_WIDGET_UNSET_FLAGS(hbox, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW);
- gnt_box_set_title(GNT_BOX(hbox), "This is the title …");
+ gnt_box_set_title(GNT_BOX(hbox), "\u4e0a\u6d77\u6700\u4f4e\u6708\u5de5 …");
g_signal_connect(G_OBJECT(tree), "toggled", G_CALLBACK(toggled), NULL);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|