changeset 18166:afeb35205669

Reduce code duplication and keep gtk 2.0 compatibility by making pidgin_menu_position_func_helper() public and available for use by gtkimhtmltoolbar
author Stu Tomlinson <stu@nosnilmot.com>
date Sun, 17 Jun 2007 16:55:45 +0000
parents 580eeb340cf4
children b8b475f31008 09eb621782bc
files ChangeLog.API pidgin/gtkimhtmltoolbar.c pidgin/gtkutils.c pidgin/gtkutils.h
diffstat 4 files changed, 32 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Sun Jun 17 16:54:10 2007 +0000
+++ b/ChangeLog.API	Sun Jun 17 16:55:45 2007 +0000
@@ -70,6 +70,7 @@
 		  information about a user.
 		* gtk_imhtml_animation_new
 		    Can be used for inserting an animated image into an IMHTML.
+		* pidgin_menu_position_func_helper
 
 		Changed:
 		* pidgin_append_menu_action returns the menuitem added to the menu.
--- a/pidgin/gtkimhtmltoolbar.c	Sun Jun 17 16:54:10 2007 +0000
+++ b/pidgin/gtkimhtmltoolbar.c	Sun Jun 17 16:55:45 2007 +0000
@@ -865,41 +865,21 @@
                     gboolean          *push_in,
                     gpointer          data)
 {
+	GtkWidget *widget = GTK_WIDGET(data);
 	GtkRequisition menu_req;
-	GtkTextDirection direction;
-	GdkRectangle monitor;
-	gint monitor_num;
-	GdkScreen *screen;
-	GtkWidget *widget = GTK_WIDGET(data);
-
-	gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
-
-	direction = gtk_widget_get_direction (widget);
-
-	screen = gtk_widget_get_screen (GTK_WIDGET (menu));
-	monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
-	if (monitor_num < 0)
-		monitor_num = 0;
-	gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+	gint ythickness = widget->style->ythickness;
+	int savy;
 
-	gdk_window_get_origin (widget->window, x, y);
+	gtk_widget_size_request(GTK_WIDGET (menu), &menu_req);
+	gdk_window_get_origin(widget->window, x, y);
 	*x += widget->allocation.x;
-	*y += widget->allocation.y;
-
-	if (direction == GTK_TEXT_DIR_LTR)
-		*x += MAX (widget->allocation.width - menu_req.width, 0);
-	else if (menu_req.width > widget->allocation.width)
-		*x -= menu_req.width - widget->allocation.width;
+	*y += widget->allocation.y + widget->allocation.height;
+	savy = *y;
 
-	if ((*y + widget->allocation.height + menu_req.height) <= monitor.y + monitor.height)
-		*y += widget->allocation.height;
-	else if ((*y - menu_req.height) >= monitor.y)
-		*y -= menu_req.height;
-	else if (monitor.y + monitor.height - (*y + widget->allocation.height) > *y)
-		*y += widget->allocation.height;
-	else
-		*y -= menu_req.height;
-	*push_in = FALSE;
+	pidgin_menu_position_func_helper(menu, x, y, push_in, data);
+
+	if (savy > *y + ythickness + 1)
+		*y -= widget->allocation.height;
 }
 
 static void pidgin_menu_clicked(GtkWidget *button, GtkMenu *menu)
--- a/pidgin/gtkutils.c	Sun Jun 17 16:54:10 2007 +0000
+++ b/pidgin/gtkutils.c	Sun Jun 17 16:55:45 2007 +0000
@@ -1141,14 +1141,14 @@
 	g_object_unref (relation);
 }
 
-#if GTK_CHECK_VERSION(2,2,0)
-static void
-pidgin_menu_position_func(GtkMenu *menu,
+void
+pidgin_menu_position_func_helper(GtkMenu *menu,
 							gint *x,
 							gint *y,
 							gboolean *push_in,
 							gpointer data)
 {
+#if GTK_CHECK_VERSION(2,2,0)
 	GtkWidget *widget;
 	GtkRequisition requisition;
 	GdkScreen *screen;
@@ -1289,9 +1289,9 @@
 	{
 		*y = monitor.y;
 	}
+#endif
 }
 
-#endif
 
 void
 pidgin_treeview_popup_menu_position_func(GtkMenu *menu,
@@ -1313,9 +1313,7 @@
 
 	*x += rect.x+rect.width;
 	*y += rect.y+rect.height+ythickness;
-#if GTK_CHECK_VERSION(2,2,0)
-	pidgin_menu_position_func (menu, x, y, push_in, data);
-#endif
+	pidgin_menu_position_func_helper(menu, x, y, push_in, data);
 }
 
 enum {
--- a/pidgin/gtkutils.h	Sun Jun 17 16:54:10 2007 +0000
+++ b/pidgin/gtkutils.h	Sun Jun 17 16:55:45 2007 +0000
@@ -359,6 +359,21 @@
 void pidgin_set_accessible_label(GtkWidget *w, GtkWidget *l);
 
 /**
+ * A helper function for GtkMenuPositionFuncs. This ensures the menu will
+ * be kept on screen if possible.
+ *
+ * @param menu The menu we are positioning.
+ * @param x Address of the gint representing the horizontal position
+ *        where the menu shall be drawn. This is an output parameter.
+ * @param y Address of the gint representing the vertical position
+ *        where the menu shall be drawn. This is an output parameter.
+ * @param push_in This is an output parameter?
+ * @param user_data Not used by this particular position function.
+ */
+void pidgin_menu_position_func_helper(GtkMenu *menu, gint *x, gint *y,
+										gboolean *push_in, gpointer data);
+
+/**
  * A valid GtkMenuPositionFunc.  This is used to determine where 
  * to draw context menu's when the menu is activated with the 
  * keyboard (shift+F10).  If the menu is activated with the mouse,