summary refs log tree commit diff stats
path: root/src/fe-gtk/chanview-tree.c
blob: 078068608467fdbf57ca6b68373741cb02256247 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/* HexChat
 * Copyright (C) 1998-2010 Peter Zelezny.
 * Copyright (C) 2009-2013 Berke Viktor.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

/* file included in chanview.c */

typedef struct
{
	GtkTreeView *tree;
	GtkWidget *scrollw;	/* scrolledWindow */
} treeview;

#include <gdk/gdk.h>

static void 	/* row-activated, when a row is double clicked */
cv_tree_activated_cb (GtkTreeView *view, GtkTreePath *path,
							 GtkTreeViewColumn *column, gpointer data)
{
	if (gtk_tree_view_row_expanded (view, path))
		gtk_tree_view_collapse_row (view, path);
	else
		gtk_tree_view_expand_row (view, path, FALSE);
}

static void		/* row selected callback */
cv_tree_sel_cb (GtkTreeSelection *sel, chanview *cv)
{
	GtkTreeModel *model;
	GtkTreeIter iter;
	chan *ch;

	if (gtk_tree_selection_get_selected (sel, &model, &iter))
	{
		gtk_tree_model_get (model, &iter, COL_CHAN, &ch, -1);

		cv->focused = ch;
		cv->cb_focus (cv, ch, ch->tag, ch->userdata);
	}
}

static gboolean
cv_tree_click_cb (GtkTreeView *tree, GdkEventButton *event, chanview *cv)
{
	chan *ch;
	GtkTreePath *path;
	GtkTreeIter iter;
	int ret = FALSE;

	if (gtk_tree_view_get_path_at_pos (tree, event->x, event->y, &path, 0, 0, 0))
	{
		if (gtk_tree_model_get_iter (GTK_TREE_MODEL (cv->store), &iter, path))
		{
			gtk_tree_model_get (GTK_TREE_MODEL (cv->store), &iter, COL_CHAN, &ch, -1);
			ret = cv->cb_contextmenu (cv, ch, ch->tag, ch->userdata, event);
		}
		gtk_tree_path_free (path);
	}
	return ret;
}

static void
cv_tree_scroll_event_cb (GtkWidget *widget, GdkEventScroll *event)
{
	if (prefs.hex_gui_tab_scrollchans)
	{
		if (event->direction == GDK_SCROLL_DOWN)
			mg_switch_page (1, 1);
		else if (event->direction == GDK_SCROLL_UP)
			mg_switch_page (1, -1);
	}
}

static void
cv_tree_init (chanview *cv)
{
	GtkWidget *view, *win;
	GtkCellRenderer *renderer;
	GtkTreeViewColumn *col;
	int wid1, wid2;
	static const GtkTargetEntry dnd_src_target[] =
	{
		{"HEXCHAT_CHANVIEW", GTK_TARGET_SAME_APP, 75 }
	};
	static const GtkTargetEntry dnd_dest_target[] =
	{
		{"HEXCHAT_USERLIST", GTK_TARGET_SAME_APP, 75 }
	};

	win = gtk_scrolled_window_new (0, 0);
	/*gtk_container_set_border_width (GTK_CONTAINER (win), 1);*/
	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (win),
													 GTK_SHADOW_IN);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (win),
											  GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
	gtk_container_add (GTK_CONTAINER (cv->box), win);
	gtk_widget_show (win);

	view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (cv->store));
	gtk_widget_set_name (view, "hexchat-tree");
	if (cv->style)
		gtk_widget_set_style (view, cv->style);
	/*gtk_widget_modify_base (view, GTK_STATE_NORMAL, &colors[COL_BG]);*/
	gtk_widget_set_can_focus (view, FALSE);
	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);

	if (prefs.hex_gui_tab_dots)
	{
		gtk_tree_view_set_enable_tree_lines (GTK_TREE_VIEW (view), TRUE);
	}
	
	/* Indented channels with no server looks silly, but we still want expanders */
	if (!prefs.hex_gui_tab_server)
	{
		gtk_widget_style_get (view, "expander-size", &wid1, "horizontal-separator", &wid2, NULL);
		gtk_tree_view_set_level_indentation (GTK_TREE_VIEW (view), -wid1 - wid2);
	}


	gtk_container_add (GTK_CONTAINER (win), view);
	col = gtk_tree_view_column_new();

	/* icon column */
	if (cv->use_icons)
	{
		renderer = gtk_cell_renderer_pixbuf_new ();
		if (prefs.hex_gui_compact)
			g_object_set (G_OBJECT (renderer), "ypad", 0, NULL);

		gtk_tree_view_column_pack_start(col, renderer, FALSE);
		gtk_tree_view_column_set_attributes (col, renderer, "pixbuf", COL_PIXBUF, NULL);
	}

	/* main column */
	renderer = gtk_cell_renderer_text_new ();
	if (prefs.hex_gui_compact)
		g_object_set (G_OBJECT (renderer), "ypad", 0, NULL);
	gtk_cell_renderer_text_set_fixed_height_from_font (GTK_CELL_RENDERER_TEXT (renderer), 1);
	gtk_tree_view_column_pack_start(col, renderer, TRUE);
	gtk_tree_view_column_set_attributes (col, renderer, "text", COL_NAME, "attributes", COL_ATTR, NULL);
	gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);									

	g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (view))),
							"changed", G_CALLBACK (cv_tree_sel_cb), cv);
	g_signal_connect (G_OBJECT (view), "button-press-event",
							G_CALLBACK (cv_tree_click_cb), cv);
	g_signal_connect (G_OBJECT (view), "row-activated",
							G_CALLBACK (cv_tree_activated_cb), NULL);
	g_signal_connect (G_OBJECT (view), "scroll_event",
							G_CALLBACK (cv_tree_scroll_event_cb), NULL);

	gtk_drag_dest_set (view, GTK_DEST_DEFAULT_ALL, dnd_dest_target, 1,
							 GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK);
	gtk_drag_source_set (view, GDK_BUTTON1_MASK, dnd_src_target, 1, GDK_ACTION_COPY);

#ifndef WIN32
	g_signal_connect (G_OBJECT (view), "drag_begin",
							G_CALLBACK (mg_drag_begin_cb), NULL);
	g_signal_connect (G_OBJECT (view), "drag_drop",
							G_CALLBACK (mg_drag_drop_cb), NULL);
	g_signal_connect (G_OBJECT (view), "drag_motion",
							G_CALLBACK (mg_drag_motion_cb), NULL);
	g_signal_connect (G_OBJECT (view), "drag_end",
							G_CALLBACK (mg_drag_end_cb), NULL);
#endif

	((treeview *)cv)->tree = GTK_TREE_VIEW (view);
	((treeview *)cv)->scrollw = win;
	gtk_widget_show (view);
}

static void
cv_tree_postinit (chanview *cv)
{
	gtk_tree_view_expand_all (((treeview *)cv)->tree);
}

static void *
cv_tree_add (chanview *cv, chan *ch, char *name, GtkTreeIter *parent)
{
	GtkTreePath *path;

	if (parent)
	{
		/* expand the parent node */
		path = gtk_tree_model_get_path (GTK_TREE_MODEL (cv->store), parent);
		if (path)
		{
			gtk_tree_view_expand_row (((treeview *)cv)->tree, path, FALSE);
			gtk_tree_path_free (path);
		}
	}

	return NULL;
}

static void
cv_tree_change_orientation (chanview *cv)
{
}

static void
cv_tree_focus (chan *ch)
{
	GtkTreeView *tree = ((treeview *)ch->cv)->tree;
	GtkTreeModel *model = gtk_tree_view_get_model (tree);
	GtkTreePath *path;
	GtkTreeIter parent;
	GdkRectangle cell_rect;
	GdkRectangle vis_rect;
	gint dest_y;

	/* expand the parent node */
	if (gtk_tree_model_iter_parent (model, &parent, &ch->iter))
	{
		path = gtk_tree_model_get_path (model, &parent);
		if (path)
		{
			/*if (!gtk_tree_view_row_expanded (tree, path))
			{
				gtk_tree_path_free (path);
				return;
			}*/
			gtk_tree_view_expand_row (tree, path, FALSE);
			gtk_tree_path_free (path);
		}
	}

	path = gtk_tree_model_get_path (model, &ch->iter);
	if (path)
	{
		/* This full section does what
		 * gtk_tree_view_scroll_to_cell (tree, path, NULL, TRUE, 0.5, 0.5);
		 * does, except it only scrolls the window if the provided cell is
		 * not visible. Basic algorithm taken from gtktreeview.c */

		/* obtain information to see if the cell is visible */
		gtk_tree_view_get_background_area (tree, path, NULL, &cell_rect);
		gtk_tree_view_get_visible_rect (tree, &vis_rect);

		/* The cordinates aren't offset correctly */
		gtk_tree_view_convert_widget_to_bin_window_coords ( tree, cell_rect.x, cell_rect.y, NULL, &cell_rect.y );

		/* only need to scroll if out of bounds */
		if (cell_rect.y < vis_rect.y ||
				cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
		{
			dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * 0.5);
			if (dest_y < 0)
				dest_y = 0;
			gtk_tree_view_scroll_to_point (tree, -1, dest_y);
		}
		/* theft done, now make it focused like */
		gtk_tree_view_set_cursor (tree, path, NULL, FALSE);
		gtk_tree_path_free (path);
	}
}

static void
cv_tree_move_focus (chanview *cv, gboolean relative, int num)
{
	chan *ch;

	if (relative)
	{
		num += cv_find_number_of_chan (cv, cv->focused);
		num %= cv->size;
		/* make it wrap around at both ends */
		if (num < 0)
			num = cv->size - 1;
	}

	ch = cv_find_chan_by_number (cv, num);
	if (ch)
		cv_tree_focus (ch);
}

static void
cv_tree_remove (chan *ch)
{
}

static void
move_row (chan *ch, int delta, GtkTreeIter *parent)
{
	GtkTreeStore *store = ch->cv->store;
	GtkTreeIter *src = &ch->iter;
	GtkTreeIter dest = ch->iter;
	GtkTreePath *dest_path;

	if (delta < 0) /* down */
	{
		if (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &dest))
			gtk_tree_store_swap (store, src, &dest);
		else	/* move to top */
			gtk_tree_store_move_after (store, src, NULL);

	} else
	{
		dest_path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &dest);
		if (gtk_tree_path_prev (dest_path))
		{
			gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &dest, dest_path);
			gtk_tree_store_swap (store, src, &dest);
		} else
		{	/* move to bottom */
			gtk_tree_store_move_before (store, src, NULL);
		}

		gtk_tree_path_free (dest_path);
	}
}

static void
cv_tree_move (chan *ch, int delta)
{
	GtkTreeIter parent;

	/* do nothing if this is a server row */
	if (gtk_tree_model_iter_parent (GTK_TREE_MODEL (ch->cv->store), &parent, &ch->iter))
		move_row (ch, delta, &parent);
}

static void
cv_tree_move_family (chan *ch, int delta)
{
	move_row (ch, delta, NULL);
}

static void
cv_tree_cleanup (chanview *cv)
{
	if (cv->box)
		/* kill the scrolled window */
		gtk_widget_destroy (((treeview *)cv)->scrollw);
}

static void
cv_tree_set_color (chan *ch, PangoAttrList *list)
{
	/* nothing to do, it's already set in the store */
}

static void
cv_tree_rename (chan *ch, char *name)
{
	/* nothing to do, it's already renamed in the store */
}

static chan *
cv_tree_get_parent (chan *ch)
{
	chan *parent_ch = NULL;
	GtkTreeIter parent;

	if (gtk_tree_model_iter_parent (GTK_TREE_MODEL (ch->cv->store), &parent, &ch->iter))
	{
		gtk_tree_model_get (GTK_TREE_MODEL (ch->cv->store), &parent, COL_CHAN, &parent_ch, -1);
	}

	return parent_ch;
}

static gboolean
cv_tree_is_collapsed (chan *ch)
{
	chan *parent = cv_tree_get_parent (ch);
	GtkTreePath *path = NULL;
	gboolean ret;

	if (parent == NULL)
		return FALSE;

	path = gtk_tree_model_get_path (GTK_TREE_MODEL (parent->cv->store),
											  &parent->iter);
	ret = !gtk_tree_view_row_expanded (((treeview *)parent->cv)->tree, path);
	gtk_tree_path_free (path);
	
	return ret;
}
class="p">), viewport, 1, 1, 0); gtk_widget_show (viewport); if (cv->vertical) box = gtk_vbox_new (FALSE, 0); else box = gtk_hbox_new (FALSE, 0); ((tabview *)cv)->inner = box; gtk_container_add (GTK_CONTAINER (viewport), box); gtk_widget_show (box); /* if vertical, the buttons can be side by side */ if (cv->vertical) { hbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (outer), hbox, 0, 0, 0); gtk_widget_show (hbox); } /* make the Scroll buttons */ ((tabview *)cv)->b2 = make_sbutton (cv->vertical ? GTK_ARROW_UP : GTK_ARROW_LEFT, tab_scroll_left_up_clicked, cv); ((tabview *)cv)->b1 = make_sbutton (cv->vertical ? GTK_ARROW_DOWN : GTK_ARROW_RIGHT, tab_scroll_right_down_clicked, cv); if (hbox) { gtk_container_add (GTK_CONTAINER (hbox), ((tabview *)cv)->b2); gtk_container_add (GTK_CONTAINER (hbox), ((tabview *)cv)->b1); } else { gtk_box_pack_start (GTK_BOX (outer), ((tabview *)cv)->b2, 0, 0, 0); gtk_box_pack_start (GTK_BOX (outer), ((tabview *)cv)->b1, 0, 0, 0); } button = gtkutil_button (outer, GTK_STOCK_CLOSE, NULL, cv_tabs_xclick_cb, cv, 0); gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); gtk_widget_set_can_focus (button, FALSE); gtk_container_add (GTK_CONTAINER (cv->box), outer); } static void cv_tabs_postinit (chanview *cv) { } static void tab_add_sorted (chanview *cv, GtkWidget *box, GtkWidget *tab, chan *ch) { GList *list; GtkWidget *child; int i = 0; void *b; if (!cv->sorted) { gtk_box_pack_start (GTK_BOX (box), tab, 0, 0, 0); gtk_widget_show (tab); return; } /* sorting TODO: * - move tab if renamed (dialogs) */ /* userdata, passed to mg_tabs_compare() */ b = ch->userdata; list = gtk_container_get_children (GTK_CONTAINER (box)); while (list) { child = list->data; if (!GTK_IS_SEPARATOR (child)) { void *a = g_object_get_data (G_OBJECT (child), "u"); if (ch->tag == 0 && cv->cb_compare (a, b) > 0) { gtk_box_pack_start (GTK_BOX (box), tab, 0, 0, 0); gtk_box_reorder_child (GTK_BOX (box), tab, i); gtk_widget_show (tab); return; } } i++; list = list->next; } /* append */ gtk_box_pack_start (GTK_BOX (box), tab, 0, 0, 0); gtk_box_reorder_child (GTK_BOX (box), tab, i); gtk_widget_show (tab); } /* remove empty boxes and separators */ static void cv_tabs_prune (chanview *cv) { GList *boxes, *children; GtkWidget *box, *inner; GtkWidget *child; int empty; inner = ((tabview *)cv)->inner; boxes = gtk_container_get_children (GTK_CONTAINER (inner)); while (boxes) { child = boxes->data; box = child; boxes = boxes->next; /* check if the box is empty (except a vseperator) */ empty = TRUE; children = gtk_container_get_children (GTK_CONTAINER (box)); while (children) { if (!GTK_IS_SEPARATOR ((GtkWidget *)children->data)) { empty = FALSE; break; } children = children->next; } if (empty) gtk_widget_destroy (box); } } static void tab_add_real (chanview *cv, GtkWidget *tab, chan *ch) { GList *boxes, *children; GtkWidget *sep, *box, *inner; GtkWidget *child; int empty; inner = ((tabview *)cv)->inner; /* see if a family for this tab already exists */ boxes = gtk_container_get_children (GTK_CONTAINER (inner)); while (boxes) { child = boxes->data; box = child; if (g_object_get_data (G_OBJECT (box), "f") == ch->family) { tab_add_sorted (cv, box, tab, ch); gtk_widget_queue_resize (gtk_widget_get_parent(inner)); return; } boxes = boxes->next; /* check if the box is empty (except a vseperator) */ empty = TRUE; children = gtk_container_get_children (GTK_CONTAINER (box)); while (children) { if (!GTK_IS_SEPARATOR ((GtkWidget *)children->data)) { empty = FALSE; break; } children = children->next; } if (empty) gtk_widget_destroy (box); } /* create a new family box */ if (cv->vertical) { /* vertical */ box = gtk_vbox_new (FALSE, 0); sep = gtk_hseparator_new (); } else { /* horiz */ box = gtk_hbox_new (FALSE, 0); sep = gtk_vseparator_new (); } gtk_box_pack_end (GTK_BOX (box), sep, 0, 0, 4); gtk_widget_show (sep); gtk_box_pack_start (GTK_BOX (inner), box, 0, 0, 0); g_object_set_data (G_OBJECT (box), "f", ch->family); gtk_box_pack_start (GTK_BOX (box), tab, 0, 0, 0); gtk_widget_show (tab); gtk_widget_show (box); gtk_widget_queue_resize (gtk_widget_get_parent(inner)); } static gboolean tab_ignore_cb (GtkWidget *widget, GdkEventCrossing *event, gpointer user_data) { return TRUE; } /* called when a tab is clicked (button down) */ static void tab_pressed_cb (GtkToggleButton *tab, chan *ch) { chan *old_tab; int is_switching = TRUE; chanview *cv = ch->cv; ignore_toggle = TRUE; /* de-activate the old tab */ old_tab = cv->focused; if (old_tab && old_tab->impl) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (old_tab->impl), FALSE); if (old_tab == ch) is_switching = FALSE; } gtk_toggle_button_set_active (tab, TRUE); ignore_toggle = FALSE; cv->focused = ch; if (/*tab->active*/is_switching) /* call the focus callback */ cv->cb_focus (cv, ch, ch->tag, ch->userdata); } /* called for keyboard tab toggles only */ static void tab_toggled_cb (GtkToggleButton *tab, chan *ch) { if (ignore_toggle) return; /* activated a tab via keyboard */ tab_pressed_cb (tab, ch); } static gboolean tab_click_cb (GtkWidget *wid, GdkEventButton *event, chan *ch) { return ch->cv->cb_contextmenu (ch->cv, ch, ch->tag, ch->userdata, event); } static void * cv_tabs_add (chanview *cv, chan *ch, char *name, GtkTreeIter *parent) { GtkWidget *but; but = gtk_toggle_button_new_with_label (name); gtk_widget_set_name (but, "hexchat-tab"); g_object_set_data (G_OBJECT (but), "c", ch); /* used to trap right-clicks */ g_signal_connect (G_OBJECT (but), "button_press_event", G_CALLBACK (tab_click_cb), ch); /* avoid prelights */ g_signal_connect (G_OBJECT (but), "enter_notify_event", G_CALLBACK (tab_ignore_cb), NULL); g_signal_connect (G_OBJECT (but), "leave_notify_event", G_CALLBACK (tab_ignore_cb), NULL); g_signal_connect (G_OBJECT (but), "pressed", G_CALLBACK (tab_pressed_cb), ch); /* for keyboard */ g_signal_connect (G_OBJECT (but), "toggled", G_CALLBACK (tab_toggled_cb), ch); g_object_set_data (G_OBJECT (but), "u", ch->userdata); tab_add_real (cv, but, ch); return but; } /* traverse all the family boxes of tabs * * A "group" is basically: * GtkV/HBox * `-GtkViewPort * `-GtkV/HBox (inner box) * `- GtkBox (family box) * `- GtkToggleButton * `- GtkToggleButton * `- ... * `- GtkBox * `- GtkToggleButton * `- GtkToggleButton * `- ... * `- ... * * */ static int tab_group_for_each_tab (chanview *cv, int (*callback) (GtkWidget *tab, int num, int usernum), int usernum) { GList *tabs; GList *boxes; GtkWidget *child; GtkBox *innerbox; int i; innerbox = (GtkBox *) ((tabview *)cv)->inner; boxes = gtk_container_get_children (GTK_CONTAINER (innerbox)); i = 0; while (boxes) { child = boxes->data; tabs = gtk_container_get_children (GTK_CONTAINER (child)); while (tabs) { child = tabs->data; if (!GTK_IS_SEPARATOR (child)) { if (callback (child, i, usernum) != -1) return i; i++; } tabs = tabs->next; } boxes = boxes->next; } return i; } static int tab_check_focus_cb (GtkWidget *tab, int num, int unused) { if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tab))) return num; return -1; } /* returns the currently focused tab number */ static int tab_group_get_cur_page (chanview *cv) { return tab_group_for_each_tab (cv, tab_check_focus_cb, 0); } static void cv_tabs_focus (chan *ch) { if (ch->impl) /* focus the new one (tab_pressed_cb defocuses the old one) */ tab_pressed_cb (GTK_TOGGLE_BUTTON (ch->impl), ch); } static int tab_focus_num_cb (GtkWidget *tab, int num, int want) { if (num == want) { cv_tabs_focus (g_object_get_data (G_OBJECT (tab), "c")); return 1; } return -1; } static void cv_tabs_change_orientation (chanview *cv) { /* cleanup the old one */ if (cv->func_cleanup) cv->func_cleanup (cv); /* now rebuild a new tabbar or tree */ cv->func_init (cv); chanview_populate (cv); } /* switch to the tab number specified */ static void cv_tabs_move_focus (chanview *cv, gboolean relative, int num) { int i, max; if (relative) { max = cv->size; i = tab_group_get_cur_page (cv) + num; /* make it wrap around at both ends */ if (i < 0) i = max - 1; if (i >= max) i = 0; tab_group_for_each_tab (cv, tab_focus_num_cb, i); return; } tab_group_for_each_tab (cv, tab_focus_num_cb, num); } static void cv_tabs_remove (chan *ch) { gtk_widget_destroy (ch->impl); ch->impl = NULL; cv_tabs_prune (ch->cv); } static void cv_tabs_move (chan *ch, int delta) { int i = 0; int pos = 0; GList *list; GtkWidget *parent = gtk_widget_get_parent(GTK_WIDGET (ch->impl)); for (list = gtk_container_get_children (GTK_CONTAINER (parent)); list; list = list->next) { GtkWidget *child_entry; child_entry = list->data; if (child_entry == ch->impl) pos = i; /* keep separator at end to not throw off our count */ if (GTK_IS_SEPARATOR (child_entry)) gtk_box_reorder_child (GTK_BOX (parent), child_entry, -1); else i++; } pos = (pos - delta) % i; gtk_box_reorder_child (GTK_BOX (parent), ch->impl, pos); } static void cv_tabs_move_family (chan *ch, int delta) { int i, pos = 0; GList *list; GtkWidget *box = NULL; /* find position of tab's family */ i = 0; for (list = gtk_container_get_children (GTK_CONTAINER (((tabview *)ch->cv)->inner)); list; list = list->next) { GtkWidget *child_entry; void *fam; child_entry = list->data; fam = g_object_get_data (G_OBJECT (child_entry), "f"); if (fam == ch->family) { box = child_entry; pos = i; } i++; } pos = (pos - delta) % i; gtk_box_reorder_child (GTK_BOX (gtk_widget_get_parent(box)), box, pos); } static void cv_tabs_cleanup (chanview *cv) { if (cv->box) gtk_widget_destroy (((tabview *)cv)->outer); } static void cv_tabs_set_color (chan *ch, PangoAttrList *list) { gtk_label_set_attributes (GTK_LABEL (gtk_bin_get_child (GTK_BIN (ch->impl))), list); } static void cv_tabs_rename (chan *ch, char *name) { PangoAttrList *attr; GtkWidget *tab = ch->impl; attr = gtk_label_get_attributes (GTK_LABEL (gtk_bin_get_child (GTK_BIN (tab)))); if (attr) pango_attr_list_ref (attr); gtk_button_set_label (GTK_BUTTON (tab), name); gtk_widget_queue_resize (gtk_widget_get_parent(gtk_widget_get_parent(gtk_widget_get_parent(tab)))); if (attr) { gtk_label_set_attributes (GTK_LABEL (gtk_bin_get_child (GTK_BIN (tab))), attr); pango_attr_list_unref (attr); } } static gboolean cv_tabs_is_collapsed (chan *ch) { return FALSE; } static chan * cv_tabs_get_parent (chan *ch) { return NULL; }