summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTingPing <tingping@tingping.se>2014-02-05 18:08:40 -0500
committerTingPing <tingping@tingping.se>2014-02-06 20:17:07 -0500
commit5f7321280e2dfaa097fbd4855b547069ee96edc2 (patch)
tree8d7e919a55763f924da99a0d44ba16e3bf254f8f
parent8d77fd6a57b2cc54fbeae0a3d745cf60bfa9caec (diff)
Use a standard GtkScrolledWindow with xtext
Used in maingui, fkeys, text events, rawlog

This also implements the set_scroll_adjustments signal in xtext
-rw-r--r--src/fe-gtk/Makefile.am10
-rw-r--r--src/fe-gtk/fkeys.c22
-rw-r--r--src/fe-gtk/maingui.c22
-rw-r--r--src/fe-gtk/rawlog.c31
-rw-r--r--src/fe-gtk/textgui.c23
-rw-r--r--src/fe-gtk/xtext.c67
-rw-r--r--src/fe-gtk/xtext.h1
-rw-r--r--src/fe-gtk/xtext_marshalers.list2
8 files changed, 96 insertions, 82 deletions
diff --git a/src/fe-gtk/Makefile.am b/src/fe-gtk/Makefile.am
index 5a622fa0..07f2ffc0 100644
--- a/src/fe-gtk/Makefile.am
+++ b/src/fe-gtk/Makefile.am
@@ -14,7 +14,7 @@ EXTRA_DIST = \
 	sexy-spell-entry.h sexy-marshal.h textgui.h urlgrab.h userlistgui.h xtext.h \
 	../../data/hexchat.gresource.xml
 
-BUILT_SOURCES = resources.c
+BUILT_SOURCES = resources.c xtext_marshalers.h xtext_marshalers.c
 
 CLEANFILES = $(BUILT_SOURCES)
 
@@ -30,7 +30,13 @@ hexchat_SOURCES = ascii.c banlist.c chanlist.c chanview.c custom-list.c \
 	dccgui.c editlist.c fe-gtk.c fkeys.c gtkutil.c ignoregui.c joind.c menu.c \
 	maingui.c notifygui.c palette.c pixmaps.c plugin-tray.c $(plugingui_c) \
 	rawlog.c resources.c servlistgui.c setup.c $(iso_codes_c) sexy-marshal.c \
-	sexy-spell-entry.c textgui.c urlgrab.c userlistgui.c xtext.c
+	sexy-spell-entry.c textgui.c urlgrab.c userlistgui.c xtext.c xtext_marshalers.c
 
 resources.c: ../../data/hexchat.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=../../data --generate-dependencies ../../data/hexchat.gresource.xml)
 	$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=../../data --generate-source $<
+
+xtext_marshalers.h: xtext_marshalers.list
+	$(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix=_xtext_marshal --header $(srcdir)/xtext_marshalers.list > $@
+
+xtext_marshalers.c: xtext_marshalers.list
+	$(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix=_xtext_marshal --body $(srcdir)/xtext_marshalers.list > $@
diff --git a/src/fe-gtk/fkeys.c b/src/fe-gtk/fkeys.c
index b5172091..cdbdc0d0 100644
--- a/src/fe-gtk/fkeys.c
+++ b/src/fe-gtk/fkeys.c
@@ -661,7 +661,7 @@ key_dialog_set_data (GtkWidget * entry, int d)
 void
 key_dialog_show ()
 {
-	GtkWidget *vbox, *hbox, *list, *vbox2, *wid, *wid2, *wid3, *hbox2;
+	GtkWidget *vbox, *hbox, *list, *vbox2, *wid, *wid2, *wid3;
 	struct key_binding *kb;
 	gchar *titles[] = { NULL, NULL, NULL, "1", "2" };
 	char temp[32];
@@ -774,21 +774,13 @@ key_dialog_show ()
 															 key_dialog_set_data,
 															 (void *) 1, vbox2);
 
-	hbox2 = gtk_hbox_new (0, 2);
-	gtk_box_pack_end (GTK_BOX (vbox), hbox2, 0, 0, 1);
+	wid2 = gtk_scrolled_window_new (NULL, NULL);
+	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (wid2), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+	gtk_container_add (GTK_CONTAINER (vbox), wid2);
 
-	wid = gtk_xtext_new (colors, 0);
-	gtk_widget_set_usize (wid, 0, 75);
-	gtk_box_pack_start (GTK_BOX (hbox2), wid, 1, 1, 1);
-	gtk_xtext_set_font (GTK_XTEXT (wid), prefs.hex_text_font);
-	gtk_widget_show (wid);
-
-	wid2 = gtk_vscrollbar_new (GTK_XTEXT (wid)->adj);
-	gtk_box_pack_start (GTK_BOX (hbox2), wid2, 0, 0, 0);
-	gtk_widget_show (wid2);
-
-	gtk_widget_show (hbox2);
-	key_dialog_text = wid;
+	key_dialog_text = gtk_xtext_new (colors, 0);
+	gtk_container_add (GTK_CONTAINER (wid2), key_dialog_text);
+	gtk_xtext_set_font (GTK_XTEXT (key_dialog_text), prefs.hex_text_font);
 
 	gtk_widget_show_all (key_dialog);
 }
diff --git a/src/fe-gtk/maingui.c b/src/fe-gtk/maingui.c
index 8e6bbfe3..8ac6f437 100644
--- a/src/fe-gtk/maingui.c
+++ b/src/fe-gtk/maingui.c
@@ -54,7 +54,6 @@
 
 #define GUI_SPACING (3)
 #define GUI_BORDER (0)
-#define SCROLLBAR_SPACING (2)
 
 enum
 {
@@ -2309,7 +2308,7 @@ mg_update_xtext (GtkWidget *wid)
 static void
 mg_create_textarea (session *sess, GtkWidget *box)
 {
-	GtkWidget *inbox, *vbox, *frame;
+	GtkWidget *scrolledwindow;
 	GtkXText *xtext;
 	session_gui *gui = sess->gui;
 	static const GtkTargetEntry dnd_targets[] =
@@ -2322,15 +2321,12 @@ mg_create_textarea (session *sess, GtkWidget *box)
 		{"HEXCHAT_USERLIST", GTK_TARGET_SAME_APP, 75 }
 	};
 
-	vbox = gtk_vbox_new (FALSE, 0);
-	gtk_container_add (GTK_CONTAINER (box), vbox);
-
-	inbox = gtk_hbox_new (FALSE, SCROLLBAR_SPACING);
-	gtk_container_add (GTK_CONTAINER (vbox), inbox);
 
-	frame = gtk_frame_new (NULL);
-	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
-	gtk_container_add (GTK_CONTAINER (inbox), frame);
+	scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
+	gui->vscrollbar = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (scrolledwindow)); /* For fkeys */
+	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
+	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_SHADOW_IN);
+	gtk_container_add (GTK_CONTAINER (box), scrolledwindow);
 
 	gui->xtext = gtk_xtext_new (colors, TRUE);
 	xtext = GTK_XTEXT (gui->xtext);
@@ -2338,14 +2334,12 @@ mg_create_textarea (session *sess, GtkWidget *box)
 	gtk_xtext_set_thin_separator (xtext, prefs.hex_text_thin_sep);
 	gtk_xtext_set_urlcheck_function (xtext, mg_word_check);
 	gtk_xtext_set_max_lines (xtext, prefs.hex_text_max_lines);
-	gtk_container_add (GTK_CONTAINER (frame), GTK_WIDGET (xtext));
+	gtk_container_add (GTK_CONTAINER (scrolledwindow), GTK_WIDGET (xtext));
+
 	mg_update_xtext (GTK_WIDGET (xtext));
 
 	g_signal_connect (G_OBJECT (xtext), "word_click",
 							G_CALLBACK (mg_word_clicked), NULL);
-
-	gui->vscrollbar = gtk_vscrollbar_new (GTK_XTEXT (xtext)->adj);
-	gtk_box_pack_start (GTK_BOX (inbox), gui->vscrollbar, FALSE, TRUE, 0);
 #ifndef WIN32	/* needs more work */
 	gtk_drag_dest_set (gui->vscrollbar, 5, dnd_dest_targets, 2,
 							 GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK);
diff --git a/src/fe-gtk/rawlog.c b/src/fe-gtk/rawlog.c
index fea53e84..f2527492 100644
--- a/src/fe-gtk/rawlog.c
+++ b/src/fe-gtk/rawlog.c
@@ -100,7 +100,7 @@ rawlog_key_cb (GtkWidget * wid, GdkEventKey * key, gpointer userdata)
 void
 open_rawlog (struct server *serv)
 {
-	GtkWidget *hbox, *vscrollbar, *vbox;
+	GtkWidget *bbox, *scrolledwindow, *vbox;
 	char tbuf[256];
 
 	if (serv->gui->rawlog_window)
@@ -115,37 +115,30 @@ open_rawlog (struct server *serv)
 							 640, 320, &vbox, serv);
 	gtkutil_destroy_on_esc (serv->gui->rawlog_window);
 
-	hbox = gtk_hbox_new (FALSE, 2);
-	gtk_container_add (GTK_CONTAINER (vbox), hbox);
-	gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
-	gtk_widget_show (hbox);
+	scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
+	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
+	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_SHADOW_IN);
+	gtk_container_add (GTK_CONTAINER (vbox), scrolledwindow);
 
 	serv->gui->rawlog_textlist = gtk_xtext_new (colors, 0);
-
-	gtk_container_add (GTK_CONTAINER (hbox), serv->gui->rawlog_textlist);
+	gtk_container_add (GTK_CONTAINER (scrolledwindow), serv->gui->rawlog_textlist);
 	gtk_xtext_set_font (GTK_XTEXT (serv->gui->rawlog_textlist), prefs.hex_text_font);
 	GTK_XTEXT (serv->gui->rawlog_textlist)->ignore_hidden = 1;
-	gtk_widget_show (serv->gui->rawlog_textlist);
-
-	vscrollbar = gtk_vscrollbar_new (GTK_XTEXT (serv->gui->rawlog_textlist)->adj);
-	gtk_box_pack_start (GTK_BOX (hbox), vscrollbar, FALSE, FALSE, 0);
-	show_and_unfocus (vscrollbar);
 
-	hbox = gtk_hbutton_box_new ();
-	gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_SPREAD);
-	gtk_box_pack_end (GTK_BOX (vbox), hbox, 0, 0, 0);
-	gtk_widget_show (hbox);
+	bbox = gtk_hbutton_box_new ();
+	gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_SPREAD);
+	gtk_box_pack_end (GTK_BOX (vbox), bbox, 0, 0, 4);
 
-	gtkutil_button (hbox, GTK_STOCK_CLEAR, NULL, rawlog_clearbutton,
+	gtkutil_button (bbox, GTK_STOCK_CLEAR, NULL, rawlog_clearbutton,
 						 serv, _("Clear Raw Log"));
 
-	gtkutil_button (hbox, GTK_STOCK_SAVE_AS, NULL, rawlog_savebutton,
+	gtkutil_button (bbox, GTK_STOCK_SAVE_AS, NULL, rawlog_savebutton,
 						 serv, _("Save As..."));
 
 	/* Copy selection to clipboard when Ctrl+Shift+C is pressed AND text auto-copy is disabled */
 	g_signal_connect (G_OBJECT (serv->gui->rawlog_window), "key_press_event", G_CALLBACK (rawlog_key_cb), serv->gui->rawlog_textlist);
 
-	gtk_widget_show (serv->gui->rawlog_window);
+	gtk_widget_show_all (serv->gui->rawlog_window);
 }
 
 void
diff --git a/src/fe-gtk/textgui.c b/src/fe-gtk/textgui.c
index 74972fe0..11dc236c 100644
--- a/src/fe-gtk/textgui.c
+++ b/src/fe-gtk/textgui.c
@@ -371,7 +371,6 @@ pevent_dialog_show ()
 	gtk_paned_pack1 (GTK_PANED (wid), th, 1, 1);
 	gtk_paned_pack2 (GTK_PANED (wid), bh, 0, 1);
 	gtk_box_pack_start (GTK_BOX (vbox), wid, 1, 1, 0);
-	gtk_widget_show (wid);
 
 	store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING,
 	                            G_TYPE_STRING, G_TYPE_INT);
@@ -389,30 +388,24 @@ pevent_dialog_show ()
 	g_signal_connect (G_OBJECT (pevent_dialog_entry), "activate",
 							G_CALLBACK (pevent_dialog_update), pevent_dialog_twid);
 	gtk_box_pack_start (GTK_BOX (bh), pevent_dialog_entry, 0, 0, 0);
-	gtk_widget_show (pevent_dialog_entry);
 
 	tbox = gtk_hbox_new (0, 0);
 	gtk_container_add (GTK_CONTAINER (bh), tbox);
-	gtk_widget_show (tbox);
 
-	gtk_container_add (GTK_CONTAINER (tbox), pevent_dialog_twid);
-	gtk_xtext_set_font (GTK_XTEXT (pevent_dialog_twid), prefs.hex_text_font);
-
-	wid = gtk_vscrollbar_new (GTK_XTEXT (pevent_dialog_twid)->adj);
-	gtk_box_pack_start (GTK_BOX (tbox), wid, FALSE, FALSE, 0);
-	show_and_unfocus (wid);
+	wid = gtk_scrolled_window_new (NULL, NULL);
+	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (wid), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
+	gtk_container_add (GTK_CONTAINER (tbox), wid);
 
-	gtk_widget_show (pevent_dialog_twid);
+	gtk_container_add (GTK_CONTAINER (wid), pevent_dialog_twid);
+	gtk_xtext_set_font (GTK_XTEXT (pevent_dialog_twid), prefs.hex_text_font);
 
 	hstore = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING);
 	pevent_dialog_hlist = gtkutil_treeview_new (bh, GTK_TREE_MODEL (hstore),
 															  NULL,
 															  0, _("$ Number"),
 															  1, _("Description"), -1);
-	gtk_widget_show (pevent_dialog_hlist);
 
 	pevent_dialog_fill (pevent_dialog_list);
-	gtk_widget_show (pevent_dialog_list);
 
 	hbox = gtk_hbutton_box_new ();
 	gtk_box_pack_end (GTK_BOX (vbox), hbox, 0, 0, 2);
@@ -429,15 +422,11 @@ pevent_dialog_show ()
 	gtk_box_pack_end (GTK_BOX (hbox), wid, 0, 0, 0);
 	g_signal_connect (G_OBJECT (wid), "clicked",
 							G_CALLBACK (pevent_test_cb), pevent_dialog_twid);
-	gtk_widget_show (wid);
 
 	wid = gtk_button_new_from_stock (GTK_STOCK_OK);
 	gtk_box_pack_start (GTK_BOX (hbox), wid, 0, 0, 0);
 	g_signal_connect (G_OBJECT (wid), "clicked",
 							G_CALLBACK (pevent_ok_cb), NULL);
-	gtk_widget_show (wid);
-
-	gtk_widget_show (hbox);
 
-	gtk_widget_show (pevent_dialog);
+	gtk_widget_show_all (pevent_dialog);
 }
diff --git a/src/fe-gtk/xtext.c b/src/fe-gtk/xtext.c
index aa2dc11b..53658b09 100644
--- a/src/fe-gtk/xtext.c
+++ b/src/fe-gtk/xtext.c
@@ -45,6 +45,7 @@
 #include "fe-gtk.h"
 #include "xtext.h"
 #include "fkeys.h"
+#include "xtext_marshalers.h"
 
 #define charlen(str) g_utf8_skip[*(guchar *)(str)]
 
@@ -67,13 +68,6 @@
 /* force scrolling off */
 #define dontscroll(buf) (buf)->last_pixel_pos = 0x7fffffff
 
-extern void gtk_marshal_VOID__POINTER_POINTER (GClosure     *closure,
-                                               GValue       *return_value,
-                                               guint         n_param_values,
-                                               const GValue *param_values,
-                                               gpointer      invocation_hint,
-                                               gpointer      marshal_data);
-
 static GtkWidgetClass *parent_class = NULL;
 
 struct textentry
@@ -99,6 +93,7 @@ struct textentry
 enum
 {
 	WORD_CLICK,
+	SET_SCROLL_ADJUSTMENTS,
 	LAST_SIGNAL
 };
 
@@ -121,6 +116,8 @@ static char *gtk_xtext_selection_get_text (GtkXText *xtext, int *len_ret);
 static textentry *gtk_xtext_nth (GtkXText *xtext, int line, int *subline);
 static void gtk_xtext_adjustment_changed (GtkAdjustment * adj,
 														GtkXText * xtext);
+static void gtk_xtext_scroll_adjustments (GtkXText *xtext, GtkAdjustment *hadj,
+										GtkAdjustment *vadj);
 static int gtk_xtext_render_ents (GtkXText * xtext, textentry *, textentry *);
 static void gtk_xtext_recalc_widths (xtext_buffer *buf, int);
 static void gtk_xtext_fix_indent (xtext_buffer *buf);
@@ -452,14 +449,8 @@ gtk_xtext_init (GtkXText * xtext)
 	xtext->recycle = FALSE;
 	xtext->dont_render = FALSE;
 	xtext->dont_render2 = FALSE;
+	gtk_xtext_scroll_adjustments (xtext, NULL, NULL);
 
-	xtext->adj = (GtkAdjustment *) gtk_adjustment_new (0, 0, 1, 1, 1, 1);
-	g_object_ref (G_OBJECT (xtext->adj));
-	g_object_ref_sink (G_OBJECT (xtext->adj));
-	g_object_unref (G_OBJECT (xtext->adj));
-
-	xtext->vc_signal_tag = g_signal_connect (G_OBJECT (xtext->adj),
-				"value_changed", G_CALLBACK (gtk_xtext_adjustment_changed), xtext);
 	{
 		static const GtkTargetEntry targets[] = {
 			{ "UTF8_STRING", 0, TARGET_UTF8_STRING },
@@ -513,6 +504,9 @@ gtk_xtext_adjustment_timeout (GtkXText * xtext)
 static void
 gtk_xtext_adjustment_changed (GtkAdjustment * adj, GtkXText * xtext)
 {
+	if (!gtk_widget_get_realized (GTK_WIDGET (xtext)))
+		return;
+
 	if (xtext->buffer->old_value != xtext->adj->value)
 	{
 		if (xtext->adj->value >= xtext->adj->upper - xtext->adj->page_size)
@@ -2217,6 +2211,37 @@ gtk_xtext_scroll (GtkWidget *widget, GdkEventScroll *event)
 }
 
 static void
+gtk_xtext_scroll_adjustments (GtkXText *xtext, GtkAdjustment *hadj, GtkAdjustment *vadj)
+{
+	/* hadj is ignored entirely */
+
+	if (vadj)
+		g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
+	else
+		vadj = GTK_ADJUSTMENT(gtk_adjustment_new (0, 0, 1, 1, 1, 1));
+
+	if (xtext->adj && (xtext->adj != vadj))
+	{
+		g_signal_handlers_disconnect_by_func (xtext->adj,
+								gtk_xtext_adjustment_changed,
+								xtext);
+		g_object_unref (xtext->adj);
+	}
+
+	if (xtext->adj != vadj)
+	{
+		xtext->adj = vadj;
+		g_object_ref_sink (xtext->adj);
+
+		xtext->vc_signal_tag = g_signal_connect (xtext->adj, "value-changed",
+							G_CALLBACK (gtk_xtext_adjustment_changed),
+							xtext);
+
+		gtk_xtext_adjustment_changed (xtext->adj, xtext);
+	}
+}
+
+static void
 gtk_xtext_class_init (GtkXTextClass * class)
 {
 	GtkObjectClass *object_class;
@@ -2235,9 +2260,19 @@ gtk_xtext_class_init (GtkXTextClass * class)
 							G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
 							G_STRUCT_OFFSET (GtkXTextClass, word_click),
 							NULL, NULL,
-							gtk_marshal_VOID__POINTER_POINTER,
+							_xtext_marshal_VOID__POINTER_POINTER,
 							G_TYPE_NONE,
 							2, G_TYPE_POINTER, G_TYPE_POINTER);
+	xtext_signals[SET_SCROLL_ADJUSTMENTS] =
+		g_signal_new ("set_scroll_adjustments",
+							G_OBJECT_CLASS_TYPE (object_class),
+							G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+							G_STRUCT_OFFSET (GtkXTextClass, set_scroll_adjustments),
+							NULL, NULL,
+							_xtext_marshal_VOID__OBJECT_OBJECT,
+							G_TYPE_NONE,
+							2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
+
 	object_class->destroy = gtk_xtext_destroy;
 
 	widget_class->realize = gtk_xtext_realize;
@@ -2252,8 +2287,10 @@ gtk_xtext_class_init (GtkXTextClass * class)
 	widget_class->expose_event = gtk_xtext_expose;
 	widget_class->scroll_event = gtk_xtext_scroll;
 	widget_class->leave_notify_event = gtk_xtext_leave_notify;
+	widget_class->set_scroll_adjustments_signal = xtext_signals[SET_SCROLL_ADJUSTMENTS];
 
 	xtext_class->word_click = NULL;
+	xtext_class->set_scroll_adjustments = gtk_xtext_scroll_adjustments;
 }
 
 GType
diff --git a/src/fe-gtk/xtext.h b/src/fe-gtk/xtext.h
index 136121f4..2476e15c 100644
--- a/src/fe-gtk/xtext.h
+++ b/src/fe-gtk/xtext.h
@@ -239,6 +239,7 @@ struct _GtkXTextClass
 {
 	GtkWidgetClass parent_class;
 	void (*word_click) (GtkXText * xtext, char *word, GdkEventButton * event);
+	void (*set_scroll_adjustments) (GtkXText *xtext, GtkAdjustment *hadj, GtkAdjustment *vadj);
 };
 
 GtkWidget *gtk_xtext_new (GdkColor palette[], int separator);
diff --git a/src/fe-gtk/xtext_marshalers.list b/src/fe-gtk/xtext_marshalers.list
new file mode 100644
index 00000000..2f708bb3
--- /dev/null
+++ b/src/fe-gtk/xtext_marshalers.list
@@ -0,0 +1,2 @@
+VOID:OBJECT,OBJECT
+VOID:POINTER,POINTER