/* X-Chat
* Copyright (C) 1998 Peter Zelezny.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "fe-gtk.h"
#include <gtk/gtkeditable.h>
#include <gtk/gtkframe.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkbutton.h>
#include "../common/hexchat.h"
#include "../common/hexchatc.h"
#include "gtkutil.h"
#include "ascii.h"
#include "maingui.h"
static const unsigned char table[]=
{
/* Line 1 */ '\n',
0xc2,0xa1,0xc2,0xbf,0xc2,0xa2,0xc2,0xa3,0xe2,0x82,0xac,0xc2,0xa5,0xc2,0xa6,0xc2,
0xa7,0xc2,0xa8,0xc2,0xa9,0xc2,0xae,0xc2,0xaa,0xc2,0xab,0xc2,0xbb,0xc2,0xac,0xc2,
0xad,0xc2,0xaf,0xe2,0x99,0xaa,
/* Line 2 */ '\n',
0xc2,0xba,0xc2,0xb9,0xc2,0xb2,0xc2,0xb3,0xc2,0xb4,0xc2,0xb5,0xc3,0x9e,0xc3,0xbe,
0xc2,0xb6,0xc2,0xb7,0xc2,0xb8,0xc2,0xb0,0xc2,0xbc,0xc2,0xbd,0xc2,0xbe,0xc3,0x97,
0xc2,0xb1,0xc3,0xb7,
/* Line 3 */ '\n',
0xc3,0x80,0xc3,0x81,0xc3,0x82,0xc3,0x83,0xc3,0x84,0xc3,0x85,0xc3,0x86,0xc4,0x82,
0xc4,0x84,0x20,0xc3,0x87,0xc4,0x86,0xc4,0x8c,0xc5,0x92,0x20,0xc4/* 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
*/
/* abstract channel view: tabs or tree or anything you like */
#include <stdlib.h>
#include <string.h>
#include "../common/hexchat.h"
#include "../common/hexchatc.h"
#include "fe-gtk.h"
#include "maingui.h"
#include "gtkutil.h"
#include "chanview.h"
/* treeStore columns */
#define COL_NAME 0 /* (char *) */
#define COL_CHAN 1 /* (chan *) */
#define COL_ATTR 2 /* (PangoAttrList *) */
#define COL_PIXBUF 3 /* (GdkPixbuf *) */
struct _chanview
{
/* impl scratch area */
char implscratch[sizeof (void *) * 8];
GtkTreeStore *store;
int size; /* number of channels in view */
GtkWidget *box; /* the box we destroy when changing implementations */
GtkStyle *style; /* style used for tree */
chan *focused; /* currently focused channel */
int trunc_len;
/* callbacks */
void (*cb_focus) (chanview *, chan *, int tag, void *userdata);
void (*cb_xbutton) (chanview *, chan *, int tag, void *userdata);
gboolean (*cb_contextmenu) (chanview *, chan *, int tag, void *userdata, GdkEventButton *);
int (*cb_compare) (void *a, void *b);
/* impl */
void (*func_init) (chanview *);
void (*func_postinit) (chanview *);
void *(*func_add) (chanview *, chan *, char *, GtkTreeIter *);
void (*func_move_focus) (chanview *, gboolean, int);
void (*func_change_orientation) (chanview *);
void (*func_remove) (chan *);
void (*func_move) (chan *, int delta);
void (*func_move_family) (chan *, int delta);
void (*func_focus) (chan *);
void (*func_set_color) (chan *, PangoAttrList *);
void (*func_rename) (chan *, char *);
gboolean (*func_is_collapsed) (chan *);
chan *(*func_get_parent) (chan *);
void (*func_cleanup) (chanview *);
unsigned int sorted:1;
unsigned int vertical:1;
unsigned int use_icons:1;
};
struct _chan
{
chanview *cv; /* our owner */
GtkTreeIter iter;
void *userdata; /* session * */
void *family; /* server * or null */
void *impl; /* togglebutton or null */
GdkPixbuf *icon;
short allow_closure; /* allow it to be closed when it still has children? */
short tag;
};
static chan *cv_find_chan_by_number (chanview *cv, int num);
static int cv_find_number_of_chan (chanview *cv, chan *find_ch);
/* ======= TABS ======= */
#include "chanview-tabs.c"
/* ======= TREE ======= */
#include "chanview-tree.c"
/* ==== ABSTRACT CHANVIEW ==== */
static char *
truncate_tab_name (char *name, int max)
{
char *buf;
if (max > 2 && g_utf8_strlen (name, -1) > max)
{
/* truncate long channel names */
buf = g_malloc (strlen (name) + 4);
g_utf8_strncpy (buf, name, max);
strcat (buf, "..");
return buf;
}
return name;
}
/* iterate through a model, into 1 depth of children */
static void
model_foreach_1 (GtkTreeModel *model, void (*func)(void *, GtkTreeIter *),
void *userdata)
{
GtkTreeIter iter, inner;
if (gtk_tree_model_get_iter_first (model, &iter))
{
do
{
func (userdata, &iter);
if (gtk_tree_model_iter_children (model, &inner, &iter))
{
do
func (userdata, &inner);
while (gtk_tree_model_iter_next (model, &inner));
}
}
while (gtk_tree_model_iter_next (model, &iter));
}
}
static void
chanview_pop_cb (chanview *cv, GtkTreeIter *iter)
{
chan *ch;
char *name;
PangoAttrList *attr;
gtk_tree_model_get (GTK_TREE_MODEL (cv->store), iter,
COL_NAME, &name, COL_CHAN, &ch, COL_ATTR, &attr, -1);
ch->impl = cv->func_add (cv, ch, name, NULL);
if (attr)
{
cv->func_set_color (ch, attr);
pango_attr_list_unref (attr);
}
g_free (name);
}
static void
chanview_populate (chanview *cv)
{
model_foreach_1 (GTK_TREE_MODEL (cv->store), (void *)chanview_pop_cb, cv);
}
void
chanview_set_impl (chanview *cv, int type)
{
/* cleanup the old one */
if (cv->func_cleanup)
cv->func_cleanup (cv);
switch (type)
{
case 0:
cv->func_init = cv_tabs_init;
cv->func_postinit = cv_tabs_postinit;
cv->func_add = cv_tabs_add;
cv->func_move_focus = cv_tabs_move_focus;
cv->func_change_orientation = cv_tabs_change_orientation;
cv->func_remove = cv_tabs_remove;
cv->func_move = cv_tabs_move;
cv->func_move_family = cv_tabs_move_family;
cv->func_focus = cv_tabs_focus;
cv->func_set_color = cv_tabs_set_color;
cv