changeset 14371:f3137c1faebe

[gaim-migrate @ 17077] The width of the conversation windows can now be resized. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Tue, 29 Aug 2006 03:47:34 +0000
parents c2fe0f54c389
children d5c22258df09
files console/libgnt/gnttextview.c
diffstat 1 files changed, 61 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/console/libgnt/gnttextview.c	Tue Aug 29 02:22:08 2006 +0000
+++ b/console/libgnt/gnttextview.c	Tue Aug 29 03:47:34 2006 +0000
@@ -8,7 +8,8 @@
 
 typedef struct
 {
-	GntTextFormatFlags flags;
+	GntTextFormatFlags tvflag;
+	chtype flags;
 	char *text;
 } GntTextSegment;
 
@@ -16,6 +17,7 @@
 {
 	GList *segments;         /* A list of GntTextSegments */
 	int length;              /* The current length of the line so far (ie. onscreen width) */
+	gboolean soft;           /* TRUE if it's an overflow from prev. line */
 } GntTextLine;
 
 static GntWidgetClass *parent_class = NULL;
@@ -148,6 +150,59 @@
 }
 
 static void
+gnt_text_view_reflow(GntTextView *view)
+{
+	/* This is pretty ugly, and inefficient. Someone do something about it. */
+	GntTextLine *line;
+	GList *back, *iter, *list;
+	int pos = 0;
+
+	list = view->list;
+	while (list->prev) {
+		line = list->data;
+		if (!line->soft)
+			pos++;
+		list = list->prev;
+	}
+
+	back = g_list_last(view->list);
+	view->list = NULL;
+	gnt_text_view_clear(view);
+
+	for (; back; back = back->prev) {
+		line = back->data;
+
+		if (back->next && !line->soft)
+			gnt_text_view_next_line(view);
+
+		for (iter = line->segments; iter; iter = iter->next) {
+			GntTextSegment *seg = iter->data;
+			gnt_text_view_append_text_with_flags(view, seg->text, seg->tvflag);
+		}
+
+		free_text_line(line, NULL);
+	}
+	g_list_free(list);
+
+	list = view->list = g_list_first(view->list);
+	while (pos--) {
+		while (((GntTextLine*)list->data)->soft)
+			list = list->next;
+		list = list->next;
+	}
+	view->list = list;
+	gnt_widget_draw(GNT_WIDGET(view));
+}
+
+static void
+gnt_text_view_size_changed(GntWidget *widget, int w, int h)
+{
+	if (w != widget->priv.width) {
+		gnt_text_view_reflow(GNT_TEXT_VIEW(widget));
+	}
+}
+
+static void
 gnt_text_view_class_init(GntTextViewClass *klass)
 {
 	parent_class = GNT_WIDGET_CLASS(klass);
@@ -157,6 +212,7 @@
 	parent_class->size_request = gnt_text_view_size_request;
 	parent_class->key_pressed = gnt_text_view_key_pressed;
 	parent_class->clicked = gnt_text_view_clicked;
+	parent_class->size_changed = gnt_text_view_size_changed;
 
 	DEBUG;
 }
@@ -166,9 +222,7 @@
 {
 	GntWidget *widget = GNT_WIDGET(instance);
 	
-	/* XXX: For now, resizing the width is not permitted. This is because
-	 * of the way I am handling wrapped lines. */
-	GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance), GNT_WIDGET_GROW_Y);
+	GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance), GNT_WIDGET_GROW_Y | GNT_WIDGET_GROW_X);
 
 	widget->priv.minw = 5;
 	widget->priv.minh = 2;
@@ -256,6 +310,7 @@
 			if (len) {
 				GntTextSegment *seg = g_new0(GntTextSegment, 1);
 				seg->flags = fl;
+				seg->tvflag = flags;
 				seg->text = g_new0(char, len + 1);
 				g_utf8_strncpy(seg->text, iter, g_utf8_pointer_to_offset(iter, iter + len));
 				line->segments = g_list_append(line->segments, seg);
@@ -264,10 +319,12 @@
 				iter += len;
 				if (line->length >= widget->priv.width - 1 && *iter) {
 					line = g_new0(GntTextLine, 1);
+					line->soft = TRUE;
 					view->list = g_list_prepend(g_list_first(view->list), line);
 				}
 			} else {
 				line = g_new0(GntTextLine, 1);
+				line->soft = TRUE;
 				view->list = g_list_prepend(g_list_first(view->list), line);
 			}
 		}