Mercurial > pidgin.yaz
comparison console/libgnt/gnttextview.c @ 14826:955798236bf4
[gaim-migrate @ 17593]
I have learnt two things today: (1) no one resizes the conversation windows (2) no one uses the lastlog plugin ... let's
fix them anyway.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 28 Oct 2006 04:55:07 +0000 |
parents | b7e145ea9076 |
children | 5228f8cf2a6a |
comparison
equal
deleted
inserted
replaced
14825:a02c29df922f | 14826:955798236bf4 |
---|---|
160 { | 160 { |
161 /* This is pretty ugly, and inefficient. Someone do something about it. */ | 161 /* This is pretty ugly, and inefficient. Someone do something about it. */ |
162 GntTextLine *line; | 162 GntTextLine *line; |
163 GList *back, *iter, *list; | 163 GList *back, *iter, *list; |
164 GString *string; | 164 GString *string; |
165 int pos = 0; | 165 int pos = 0; /* no. of 'real' lines */ |
166 | 166 |
167 list = view->list; | 167 list = view->list; |
168 while (list->prev) { | 168 while (list->prev) { |
169 line = list->data; | 169 line = list->data; |
170 if (!line->soft) | 170 if (!line->soft) |
178 string = view->string; | 178 string = view->string; |
179 view->string = NULL; | 179 view->string = NULL; |
180 gnt_text_view_clear(view); | 180 gnt_text_view_clear(view); |
181 | 181 |
182 view->string = g_string_set_size(view->string, string->len); | 182 view->string = g_string_set_size(view->string, string->len); |
183 view->string->len = 0; | |
183 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING); | 184 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING); |
184 | 185 |
185 for (; back; back = back->prev) { | 186 for (; back; back = back->prev) { |
186 line = back->data; | 187 line = back->data; |
187 if (back->next && !line->soft) { | 188 if (back->next && !line->soft) { |
188 GList *llist = g_list_first(view->list); | 189 gnt_text_view_append_text_with_flags(view, "\n", GNT_TEXT_FLAG_NORMAL); |
189 llist = g_list_prepend(llist, g_new0(GntTextLine, 1)); | 190 } |
190 } | 191 |
191 | |
192 for (iter = line->segments; iter; iter = iter->next) { | 192 for (iter = line->segments; iter; iter = iter->next) { |
193 GntTextSegment *seg = iter->data; | 193 GntTextSegment *seg = iter->data; |
194 char *start = string->str + seg->start; | 194 char *start = string->str + seg->start; |
195 char *end = string->str + seg->end; | 195 char *end = string->str + seg->end; |
196 char back = *end; | 196 char back = *end; |
201 free_text_line(line, NULL); | 201 free_text_line(line, NULL); |
202 } | 202 } |
203 g_list_free(list); | 203 g_list_free(list); |
204 | 204 |
205 list = view->list = g_list_first(view->list); | 205 list = view->list = g_list_first(view->list); |
206 /* Go back to the line that was in view before resizing started */ | |
206 while (pos--) { | 207 while (pos--) { |
207 while (((GntTextLine*)list->data)->soft) | 208 while (((GntTextLine*)list->data)->soft) |
208 list = list->next; | 209 list = list->next; |
209 list = list->next; | 210 list = list->next; |
210 } | 211 } |
306 return; | 307 return; |
307 | 308 |
308 fl = gnt_text_format_flag_to_chtype(flags); | 309 fl = gnt_text_format_flag_to_chtype(flags); |
309 | 310 |
310 len = view->string->len; | 311 len = view->string->len; |
311 g_string_append(view->string, text); | 312 view->string = g_string_append(view->string, text); |
312 | 313 |
313 view->list = g_list_first(view->list); | 314 view->list = g_list_first(view->list); |
314 | 315 |
315 start = end = view->string->str + len; | 316 start = end = view->string->str + len; |
316 | 317 |
317 while (*start) { | 318 while (*start) { |
318 GntTextSegment *seg; | 319 GntTextSegment *seg = NULL; |
319 | 320 |
320 if (*end == '\n' || *end == '\r') { | 321 if (*end == '\n' || *end == '\r') { |
321 end++; | 322 end++; |
322 start = end; | 323 start = end; |
323 gnt_text_view_next_line(view); | 324 gnt_text_view_next_line(view); |
324 view->list = g_list_first(view->list); | 325 view->list = g_list_first(view->list); |
325 continue; | 326 continue; |
326 } | 327 } |
327 | 328 |
328 line = view->list->data; | 329 line = view->list->data; |
330 if (line->length == widget->priv.width - 1) { | |
331 /* The last added line was exactly the same width as the widget */ | |
332 line = g_new0(GntTextLine, 1); | |
333 line->soft = TRUE; | |
334 view->list = g_list_prepend(view->list, line); | |
335 } | |
336 | |
329 if ((end = strchr(start, '\n')) != NULL || | 337 if ((end = strchr(start, '\n')) != NULL || |
330 (end = strchr(start, '\r')) != NULL) { | 338 (end = strchr(start, '\r')) != NULL) { |
331 len = gnt_util_onscreen_width(start, end - 1); | 339 len = gnt_util_onscreen_width(start, end - 1); |
332 if (len >= widget->priv.width - line->length - 1) { | 340 if (len >= widget->priv.width - line->length - 1) { |
333 end = NULL; | 341 end = NULL; |
336 | 344 |
337 if (end == NULL) | 345 if (end == NULL) |
338 end = gnt_util_onscreen_width_to_pointer(start, | 346 end = gnt_util_onscreen_width_to_pointer(start, |
339 widget->priv.width - line->length - 1, &len); | 347 widget->priv.width - line->length - 1, &len); |
340 | 348 |
341 seg = g_new0(GntTextSegment, 1); | 349 /* Try to append to the previous segment if possible */ |
342 seg->start = start - view->string->str; | 350 if (line->segments) { |
351 seg = g_list_last(line->segments)->data; | |
352 if (seg->flags != fl) | |
353 seg = NULL; | |
354 } | |
355 | |
356 if (seg == NULL) { | |
357 seg = g_new0(GntTextSegment, 1); | |
358 seg->start = start - view->string->str; | |
359 seg->tvflag = flags; | |
360 seg->flags = fl; | |
361 line->segments = g_list_append(line->segments, seg); | |
362 } | |
343 seg->end = end - view->string->str; | 363 seg->end = end - view->string->str; |
344 seg->tvflag = flags; | |
345 seg->flags = fl; | |
346 line->segments = g_list_append(line->segments, seg); | |
347 line->length += len; | 364 line->length += len; |
348 | 365 |
349 start = end; | 366 start = end; |
350 if (*end && *end != '\n' && *end != '\r') { | 367 if (*end && *end != '\n' && *end != '\r') { |
351 line = g_new0(GntTextLine, 1); | 368 line = g_new0(GntTextLine, 1); |