comparison console/libgnt/gnttree.c @ 14824:6ec7e963d186

[gaim-migrate @ 17591] This fixes at least some issues with wide-characters in the tree-widget. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 27 Oct 2006 18:30:56 +0000
parents 10244943bbc9
children bfcdd361357e
comparison
equal deleted inserted replaced
14823:10244943bbc9 14824:6ec7e963d186
194 int i; 194 int i;
195 195
196 for (i = 0, iter = row->columns; i < tree->ncol && iter; i++, iter = iter->next) 196 for (i = 0, iter = row->columns; i < tree->ncol && iter; i++, iter = iter->next)
197 { 197 {
198 GntTreeCol *col = iter->data; 198 GntTreeCol *col = iter->data;
199 char *text; 199 const char *text;
200 int len = g_utf8_strlen(col->text, -1); 200 int len = gnt_util_onscreen_width(col->text, NULL);
201 int fl = 0; 201 int fl = 0;
202 202
203 if (i == 0) 203 if (i == 0)
204 { 204 {
205 if (row->choice) 205 if (row->choice)
233 if (len > tree->columns[i].width) 233 if (len > tree->columns[i].width)
234 { 234 {
235 len = tree->columns[i].width; 235 len = tree->columns[i].width;
236 } 236 }
237 237
238 text = g_utf8_offset_to_pointer(col->text, len - fl); 238 text = gnt_util_onscreen_width_to_pointer(col->text, len - fl, NULL);
239 string = g_string_append_len(string, col->text, text - col->text); 239 string = g_string_append_len(string, col->text, text - col->text);
240 if (len < tree->columns[i].width && iter->next) 240 if (len < tree->columns[i].width && iter->next)
241 g_string_append_printf(string, "%*s", tree->columns[i].width - len, ""); 241 g_string_append_printf(string, "%*s", tree->columns[i].width - len, "");
242 } 242 }
243 return g_string_free(string, FALSE); 243 return g_string_free(string, FALSE);
322 tree->top = tree->current; 322 tree->top = tree->current;
323 else if (up >= widget->priv.height - pos) 323 else if (up >= widget->priv.height - pos)
324 tree->top = get_prev_n(tree->current, rows); 324 tree->top = get_prev_n(tree->current, rows);
325 325
326 row = tree->top; 326 row = tree->top;
327 scrcol = widget->priv.width - 1 - 2 * pos; /* exclude the borders and the scrollbar */
327 for (i = start + pos; row && i < widget->priv.height - pos; 328 for (i = start + pos; row && i < widget->priv.height - pos;
328 i++, row = get_next(row)) 329 i++, row = get_next(row))
329 { 330 {
330 char *str; 331 char *str;
331 int wr; 332 int wr;
333 GntTextFormatFlags flags = row->flags; 334 GntTextFormatFlags flags = row->flags;
334 int attr = 0; 335 int attr = 0;
335 336
336 str = update_row_text(tree, row); 337 str = update_row_text(tree, row);
337 338
338 if ((wr = g_utf8_strlen(str, -1)) >= widget->priv.width - 1 - pos) 339 if ((wr = gnt_util_onscreen_width(str, NULL)) > scrcol)
339 { 340 {
340 /* XXX: ellipsize */ 341 /* XXX: ellipsize */
341 char *s = g_utf8_offset_to_pointer(str, widget->priv.width - 1 - pos); 342 char *s = (char*)gnt_util_onscreen_width_to_pointer(str, scrcol, &wr);
342 *s = '\0'; 343 *s = '\0';
343 } 344 }
344 345
345 if (flags & GNT_TEXT_FLAG_BOLD) 346 if (flags & GNT_TEXT_FLAG_BOLD)
346 attr |= A_BOLD; 347 attr |= A_BOLD;
366 attr |= COLOR_PAIR(GNT_COLOR_NORMAL); 367 attr |= COLOR_PAIR(GNT_COLOR_NORMAL);
367 } 368 }
368 369
369 wbkgdset(widget->window, '\0' | attr); 370 wbkgdset(widget->window, '\0' | attr);
370 mvwprintw(widget->window, i, pos, str); 371 mvwprintw(widget->window, i, pos, str);
371 whline(widget->window, ' ', widget->priv.width - pos * 2 - g_utf8_strlen(str, -1) - 1); 372 whline(widget->window, ' ', scrcol - wr);
372 tree->bottom = row; 373 tree->bottom = row;
373 g_free(str); 374 g_free(str);
374 tree_mark_columns(tree, pos, i, 375 tree_mark_columns(tree, pos, i,
375 (tree->show_separator ? ACS_VLINE : ' ') | attr); 376 (tree->show_separator ? ACS_VLINE : ' ') | attr);
376 } 377 }
383 tree_mark_columns(tree, pos, i, 384 tree_mark_columns(tree, pos, i,
384 (tree->show_separator ? ACS_VLINE : ' ')); 385 (tree->show_separator ? ACS_VLINE : ' '));
385 i++; 386 i++;
386 } 387 }
387 388
388 scrcol = widget->priv.width - pos - 1; 389 scrcol = widget->priv.width - pos - 1; /* position of the scrollbar */
389 rows--; 390 rows--;
390 if (rows > 0) 391 if (rows > 0)
391 { 392 {
392 int total; 393 int total;
393 int showing, position; 394 int showing, position;