comparison finch/libgnt/gntws.c @ 17699:97802d3f3f1f

Forgot these...
author Richard Nelson <wabz@pidgin.im>
date Fri, 27 Apr 2007 12:56:59 +0000
parents
children 596c970076df
comparison
equal deleted inserted replaced
17698:56d2ae9cbb5c 17699:97802d3f3f1f
1 #include <gmodule.h>
2
3 #include "gntbox.h"
4 #include "gntws.h"
5 #include "gntwm.h"
6 #include "gntwidget.h"
7
8 static void
9 widget_hide(gpointer data, gpointer nodes)
10 {
11 GntWidget *widget = GNT_WIDGET(data);
12 GntNode *node = g_hash_table_lookup(nodes, widget);
13 hide_panel(node->panel);
14 }
15
16 static void
17 widget_show(gpointer data, gpointer nodes)
18 {
19 GntNode *node = g_hash_table_lookup(nodes, data);
20 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(data), GNT_WIDGET_INVISIBLE);
21 if (node) {
22 show_panel(node->panel);
23 gnt_wm_copy_win(GNT_WIDGET(data), node);
24 }
25 }
26
27 void
28 gnt_ws_draw_taskbar(GntWS *ws, gboolean reposition)
29 {
30 static WINDOW *taskbar = NULL;
31 GList *iter;
32 int n, width = 0;
33 int i;
34
35 if (taskbar == NULL) {
36 taskbar = newwin(1, getmaxx(stdscr), getmaxy(stdscr) - 1, 0);
37 } else if (reposition) {
38 int Y_MAX = getmaxy(stdscr) - 1;
39 mvwin(taskbar, Y_MAX, 0);
40 }
41
42 wbkgdset(taskbar, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL));
43 werase(taskbar);
44
45 n = g_list_length(ws->list);
46 if (n)
47 width = getmaxx(stdscr) / n;
48
49 for (i = 0, iter = ws->list; iter; iter = iter->next, i++) {
50 GntWidget *w = iter->data;
51 int color;
52 const char *title;
53
54 if (w == ws->ordered->data) {
55 /* This is the current window in focus */
56 color = GNT_COLOR_TITLE;
57 } else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_URGENT)) {
58 /* This is a window with the URGENT hint set */
59 color = GNT_COLOR_URGENT;
60 } else {
61 color = GNT_COLOR_NORMAL;
62 }
63 wbkgdset(taskbar, '\0' | COLOR_PAIR(color));
64 if (iter->next)
65 mvwhline(taskbar, 0, width * i, ' ' | COLOR_PAIR(color), width);
66 else
67 mvwhline(taskbar, 0, width * i, ' ' | COLOR_PAIR(color), getmaxx(stdscr) - width * i);
68 title = GNT_BOX(w)->title;
69 mvwprintw(taskbar, 0, width * i, "%s", title ? title : "<gnt>");
70 if (i)
71 mvwaddch(taskbar, 0, width *i - 1, ACS_VLINE | A_STANDOUT | COLOR_PAIR(GNT_COLOR_NORMAL));
72 }
73 wrefresh(taskbar);
74 }
75
76 static void
77 gnt_ws_init(GTypeInstance *instance, gpointer class)
78 {
79 GntWS *ws = GNT_WS(instance);
80 ws->list = NULL;
81 ws->ordered = NULL;
82 ws->name = NULL;
83 }
84
85 void gnt_ws_add_widget(GntWS *ws, GntWidget* wid)
86 {
87 ws->list = g_list_append(ws->list, wid);
88 ws->ordered = g_list_prepend(ws->ordered, wid);
89 }
90
91 void gnt_ws_remove_widget(GntWS *ws, GntWidget* wid)
92 {
93 ws->list = g_list_remove(ws->list, wid);
94 ws->ordered = g_list_remove(ws->ordered, wid);
95 }
96
97 void
98 gnt_ws_set_name(GntWS *ws, const gchar *name)
99 {
100 g_free(ws->name);
101 ws->name = g_strdup(name);
102 }
103
104 void
105 gnt_ws_hide(GntWS *ws, GHashTable *nodes)
106 {
107 g_list_foreach(ws->ordered, widget_hide, nodes);
108 }
109
110 void gnt_ws_widget_hide(GntWidget *widget, GHashTable *nodes) {
111 widget_hide(widget, nodes);
112 }
113
114 void gnt_ws_widget_show(GntWidget *widget, GHashTable *nodes) {
115 widget_show(widget, nodes);
116 }
117
118 void
119 gnt_ws_show(GntWS *ws, GHashTable *nodes)
120 {
121 GList *l;
122 for (l = g_list_last(ws->ordered); l; l = g_list_previous(l))
123 widget_show(l->data, nodes);
124 }
125
126 GType
127 gnt_ws_get_gtype(void)
128 {
129 static GType type = 0;
130
131 if(type == 0) {
132 static const GTypeInfo info = {
133 sizeof(GntWSClass),
134 NULL, /* base_init */
135 NULL, /* base_finalize */
136 NULL,
137 /*(GClassInitFunc)gnt_ws_class_init,*/
138 NULL,
139 NULL, /* class_data */
140 sizeof(GntWS),
141 0, /* n_preallocs */
142 gnt_ws_init, /* instance_init */
143 NULL /* value_table */
144 };
145
146 type = g_type_register_static(GNT_TYPE_BINDABLE,
147 "GntWS",
148 &info, 0);
149 }
150
151 return type;
152 }
153