comparison console/libgnt/gnttree.c @ 14123:f8ab496671fa

[gaim-migrate @ 16761] Show scrollbars in trees and textviews. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Tue, 15 Aug 2006 02:45:52 +0000
parents c0ee28af3ca2
children b71bfeaaed58
comparison
equal deleted inserted replaced
14122:dabbcb9b013d 14123:f8ab496671fa
244 } 244 }
245 245
246 static void 246 static void
247 redraw_tree(GntTree *tree) 247 redraw_tree(GntTree *tree)
248 { 248 {
249 int start; 249 int start, i;
250 GntWidget *widget = GNT_WIDGET(tree); 250 GntWidget *widget = GNT_WIDGET(tree);
251 GntTreeRow *row; 251 GntTreeRow *row;
252 int pos, up, down, nr; 252 int pos, up, down;
253 int showing, position, rows, scrcol;
253 254
254 if (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED)) 255 if (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED))
255 return; 256 return;
256 257
257 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) 258 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER))
271 { 272 {
272 int i; 273 int i;
273 int x = pos; 274 int x = pos;
274 275
275 mvwhline(widget->window, pos + 1, pos, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL), 276 mvwhline(widget->window, pos + 1, pos, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL),
276 widget->priv.width - pos - 1); 277 widget->priv.width - pos);
277 278
278 for (i = 0; i < tree->ncol; i++) 279 for (i = 0; i < tree->ncol; i++)
279 { 280 {
280 mvwprintw(widget->window, pos, x + i, tree->columns[i].title); 281 mvwprintw(widget->window, pos, x + i, tree->columns[i].title);
281 x += tree->columns[i].width; 282 x += tree->columns[i].width;
289 tree_mark_columns(tree, pos, pos + 1, ACS_PLUS | COLOR_PAIR(GNT_COLOR_NORMAL)); 290 tree_mark_columns(tree, pos, pos + 1, ACS_PLUS | COLOR_PAIR(GNT_COLOR_NORMAL));
290 tree_mark_columns(tree, pos, pos, ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL)); 291 tree_mark_columns(tree, pos, pos, ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL));
291 start = 2; 292 start = 2;
292 } 293 }
293 294
294 nr = widget->priv.height - pos * 2 - start - 1; 295 rows = widget->priv.height - pos * 2 - start - 1;
295 tree->bottom = get_next_n_opt(tree->top, nr, &down); 296 tree->bottom = get_next_n_opt(tree->top, rows, &down);
296 if (down < nr) 297 if (down < rows)
297 { 298 {
298 tree->top = get_prev_n(tree->bottom, nr); 299 tree->top = get_prev_n(tree->bottom, rows);
299 if (tree->top == NULL) 300 if (tree->top == NULL)
300 tree->top = tree->root; 301 tree->top = tree->root;
301 } 302 }
302 303
303 up = get_distance(tree->top, tree->current); 304 up = get_distance(tree->top, tree->current);
304 if (up < 0) 305 if (up < 0)
305 tree->top = tree->current; 306 tree->top = tree->current;
306 else if (up >= widget->priv.height - pos) 307 else if (up >= widget->priv.height - pos)
307 tree->top = get_prev_n(tree->current, nr); 308 tree->top = get_prev_n(tree->current, rows);
308
309 mvwaddch(widget->window, start + pos,
310 widget->priv.width - pos - 1,
311 (tree->top != tree->root) ?
312 ACS_UARROW | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D) :
313 ' '| COLOR_PAIR(GNT_COLOR_NORMAL));
314 309
315 row = tree->top; 310 row = tree->top;
316 for (start = start + pos; row && start < widget->priv.height - pos; 311 for (i = start + pos; row && i < widget->priv.height - pos;
317 start++, row = get_next(row)) 312 i++, row = get_next(row))
318 { 313 {
319 char *str; 314 char *str;
320 int wr; 315 int wr;
321 316
322 GntTextFormatFlags flags = row->flags; 317 GntTextFormatFlags flags = row->flags;
354 else 349 else
355 attr |= COLOR_PAIR(GNT_COLOR_NORMAL); 350 attr |= COLOR_PAIR(GNT_COLOR_NORMAL);
356 } 351 }
357 352
358 wbkgdset(widget->window, '\0' | attr); 353 wbkgdset(widget->window, '\0' | attr);
359 mvwprintw(widget->window, start, pos, str); 354 mvwprintw(widget->window, i, pos, str);
360 whline(widget->window, ' ', widget->priv.width - pos * 2 - g_utf8_strlen(str, -1) - 1); 355 whline(widget->window, ' ', widget->priv.width - pos * 2 - g_utf8_strlen(str, -1) - 1);
361 tree->bottom = row; 356 tree->bottom = row;
362 g_free(str); 357 g_free(str);
363 tree_mark_columns(tree, pos, start, ACS_VLINE | attr); 358 tree_mark_columns(tree, pos, i, ACS_VLINE | attr);
364 } 359 }
365
366 mvwaddch(widget->window, widget->priv.height - pos - 1,
367 widget->priv.width - pos - 1,
368 get_next(tree->bottom) ?
369 ACS_DARROW | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D) :
370 ' '| COLOR_PAIR(GNT_COLOR_NORMAL));
371 360
372 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); 361 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL));
373 while (start < widget->priv.height - pos) 362 while (i < widget->priv.height - pos)
374 { 363 {
375 mvwhline(widget->window, start, pos, ' ', 364 mvwhline(widget->window, i, pos, ' ',
376 widget->priv.width - pos * 2 - 1); 365 widget->priv.width - pos * 2 - 1);
377 tree_mark_columns(tree, pos, start, ACS_VLINE); 366 tree_mark_columns(tree, pos, i, ACS_VLINE);
378 start++; 367 i++;
379 } 368 }
369
370 scrcol = widget->priv.width - pos - 1;
371 rows--;
372 if (rows > 0)
373 {
374 get_next_n_opt(tree->root, g_list_length(tree->list), &i);
375 showing = rows * rows / MAX(i, 1) + 1;
376 showing = MIN(rows, showing);
377
378 position = showing * get_distance(tree->root, tree->top) / rows;
379 position = MAX((tree->top != tree->root), position);
380
381 if (showing + position > rows)
382 position = rows - showing;
383
384 if (showing + position == rows && row)
385 position = MAX(0, rows - 1 - showing);
386 else if (showing + position < rows && !row)
387 position = rows - showing;
388
389 position += pos + start + 1;
390
391 mvwvline(widget->window, pos + start + 1, scrcol,
392 ' ' | COLOR_PAIR(GNT_COLOR_NORMAL), rows);
393 mvwvline(widget->window, position, scrcol,
394 ACS_CKBOARD | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D), showing);
395 }
396
397 mvwaddch(widget->window, start + pos, scrcol,
398 ((tree->top != tree->root) ? ACS_UARROW : ' ') |
399 COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D));
400
401 mvwaddch(widget->window, widget->priv.height - pos - 1, scrcol,
402 (row ? ACS_DARROW : ' ') | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D));
380 403
381 gnt_widget_queue_update(widget); 404 gnt_widget_queue_update(widget);
382 } 405 }
383 406
384 static void 407 static void
548 gnt_tree_init(GTypeInstance *instance, gpointer class) 571 gnt_tree_init(GTypeInstance *instance, gpointer class)
549 { 572 {
550 GntWidget *widget = GNT_WIDGET(instance); 573 GntWidget *widget = GNT_WIDGET(instance);
551 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y); 574 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y);
552 widget->priv.minw = 4; 575 widget->priv.minw = 4;
553 widget->priv.minh = 3; 576 widget->priv.minh = 4;
554 DEBUG; 577 DEBUG;
555 } 578 }
556 579
557 /****************************************************************************** 580 /******************************************************************************
558 * GntTree API 581 * GntTree API
1005 GntTreeRow *row; 1028 GntTreeRow *row;
1006 1029
1007 va_start(args, tree); 1030 va_start(args, tree);
1008 for (i = 0; i < tree->ncol; i++) 1031 for (i = 0; i < tree->ncol; i++)
1009 { 1032 {
1010 list = g_list_append(list, va_arg(args, const char *)); 1033 list = g_list_append(list, va_arg(args, char *));
1011 } 1034 }
1012 va_end(args); 1035 va_end(args);
1013 1036
1014 row = gnt_tree_create_row_from_list(tree, list); 1037 row = gnt_tree_create_row_from_list(tree, list);
1015 g_list_free(list); 1038 g_list_free(list);
1039 } 1062 }
1040 1063
1041 void gnt_tree_set_show_title(GntTree *tree, gboolean set) 1064 void gnt_tree_set_show_title(GntTree *tree, gboolean set)
1042 { 1065 {
1043 tree->show_title = set; 1066 tree->show_title = set;
1067 GNT_WIDGET(tree)->priv.minh = (set ? 6 : 4);
1044 } 1068 }
1045 1069
1046 void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func) 1070 void gnt_tree_set_compare_func(GntTree *tree, GCompareFunc func)
1047 { 1071 {
1048 tree->compare = func; 1072 tree->compare = func;