summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fe-gtk/xtext.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/fe-gtk/xtext.c b/src/fe-gtk/xtext.c
index fef00c51..203bcd60 100644
--- a/src/fe-gtk/xtext.c
+++ b/src/fe-gtk/xtext.c
@@ -157,7 +157,10 @@ static char * gtk_xtext_get_word (GtkXText * xtext, int x, int y, textentry ** r
 #define EMPH_BOLD 2
 #define EMPH_HIDDEN 4
 static PangoAttrList *attr_lists[4];
+#ifdef G_OS_WIN32
+/* the fontwidths variable is used on Windows only. */
 static int fontwidths[4][128];
+#endif
 
 static PangoAttribute *
 xtext_pango_attr (PangoAttribute *attr)
@@ -170,7 +173,10 @@ xtext_pango_attr (PangoAttribute *attr)
 static void
 xtext_pango_init (GtkXText *xtext)
 {
-	int i, j;
+	int i;
+#ifdef G_OS_WIN32
+	int j;
+#endif
 	char buf[2] = "\000";
 
 	if (attr_lists[0])
@@ -202,6 +208,7 @@ xtext_pango_init (GtkXText *xtext)
 			break;
 		}
 
+#ifdef G_OS_WIN32
 		/* Now initialize fontwidths[i] */
 		pango_layout_set_attributes (xtext->layout, attr_lists[i]);
 		for (j = 0; j < 128; j++)
@@ -210,8 +217,14 @@ xtext_pango_init (GtkXText *xtext)
 			pango_layout_set_text (xtext->layout, buf, 1);
 			pango_layout_get_pixel_size (xtext->layout, &fontwidths[i][j], NULL);
 		}
+#endif
 	}
-	xtext->space_width = fontwidths[0][' '];
+
+	/* re-compute space_width without using fontwidths */
+	pango_layout_set_attributes (xtext->layout, attr_lists[0]);
+	buf[0] = ' ';
+	pango_layout_set_text (xtext->layout, buf, 1);
+	pango_layout_get_pixel_size (xtext->layout, &(xtext->space_width), NULL);
 }
 
 static void
@@ -289,8 +302,10 @@ static int
 backend_get_text_width_emph (GtkXText *xtext, guchar *str, int len, int emphasis)
 {
 	int width;
+#ifdef G_OS_WIN32
 	int deltaw;
 	int mbl;
+#endif
 
 	if (*str == 0)
 		return 0;
@@ -301,6 +316,8 @@ backend_get_text_width_emph (GtkXText *xtext, guchar *str, int len, int emphasis
 
 	width = 0;
 	pango_layout_set_attributes (xtext->layout, attr_lists[emphasis]);
+
+#ifdef G_OS_WIN32
 	while (len > 0)
 	{
 		mbl = charlen(str);
@@ -315,6 +332,12 @@ backend_get_text_width_emph (GtkXText *xtext, guchar *str, int len, int emphasis
 		str += mbl;
 		len -= mbl;
 	}
+#else
+	/* This code is slow on Windows,
+	   but it will get the correct width from pango on Linux. */
+	pango_layout_set_text (xtext->layout, str, len);
+	pango_layout_get_pixel_size (xtext->layout, &width, NULL);
+#endif
 
 	return width;
 }
*/ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* 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
 */

#ifndef HEXCHAT_CUSTOM_LIST_H
#define HEXCHAT_CUSTOM_LIST_H

#include <gtk/gtk.h>

GType custom_list_get_type (void);

/* Some boilerplate GObject defines. 'klass' is used
 *   instead of 'class', because 'class' is a C++ keyword */

#define CUSTOM_TYPE_LIST            (custom_list_get_type ())
#define CUSTOM_LIST(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), CUSTOM_TYPE_LIST, CustomList))
#define CUSTOM_LIST_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  CUSTOM_TYPE_LIST, CustomListClass))
#define CUSTOM_IS_LIST(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CUSTOM_TYPE_LIST))
#define CUSTOM_IS_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  CUSTOM_TYPE_LIST))
#define CUSTOM_LIST_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  CUSTOM_TYPE_LIST, CustomListClass))

/* The data columns that we export via the tree model interface */

enum
{
	CUSTOM_LIST_COL_NAME,
	CUSTOM_LIST_COL_USERS,
	CUSTOM_LIST_COL_TOPIC,
	CUSTOM_LIST_N_COLUMNS
};

enum
{
	SORT_ID_CHANNEL,
	SORT_ID_USERS,
	SORT_ID_TOPIC
};

typedef struct
{
	char *topic;
	char *collation_key;
	guint32 pos;						  /* pos within the array */
	guint32 users;
	/* channel string lives beyond "users" */
#define GET_CHAN(row) (((char *)row)+sizeof(chanlistrow))
}
chanlistrow;

typedef struct _CustomList CustomList;
typedef struct _CustomListClass CustomListClass;



/* CustomList: this structure contains everything we need for our
 *             model implementation. You can add extra fields to
 *             this structure, e.g. hashtables to quickly lookup
 *             rows or whatever else you might need, but it is
 *             crucial that 'parent' is the first member of the
 *             structure.                                          */
struct _CustomList
{
	GObject parent;

	guint num_rows;				  /* number of rows that we have used */
	guint num_alloc;					/* number of rows allocated */
	chanlistrow **rows;			  /* a dynamically allocated array of pointers to the
										   *  CustomRecord structure for each row */

	gint n_columns;
	GType column_types[CUSTOM_LIST_N_COLUMNS];

	gint sort_id;
	GtkSortType sort_order;
};


/* CustomListClass: more boilerplate GObject stuff */

struct _CustomListClass
{
	GObjectClass parent_class;
};


CustomList *custom_list_new (void);
void custom_list_append (CustomList *, chanlistrow *);
void custom_list_resort (CustomList *);
void custom_list_clear (CustomList *);

#endif /* HEXCHAT_CUSTOM_LIST_H */