replace LOG_MESSAGE with debug_print
[claws.git] / src / menu.c
index 54330e1065d340f75b88caa3ab7786b27081bd61..ef45d85552fa3f3471639754b18bbe2abc3aa1d7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999,2000 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2001 Hiroyuki Yamamoto
  *
  * 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
 #include <gtk/gtkmenubar.h>
 #include <gtk/gtkitemfactory.h>
 #include <gtk/gtkcheckmenuitem.h>
+#include <gtk/gtkbutton.h>
 
 #include "intl.h"
 #include "menu.h"
+#include "utils.h"
 
 static gchar *menu_translate(const gchar *path, gpointer data);
 
@@ -78,6 +80,10 @@ void menu_set_sensitive(GtkItemFactory *ifactory, const gchar *path,
        g_return_if_fail(ifactory != NULL);
 
        widget = gtk_item_factory_get_item(ifactory, path);
+       if(widget == NULL) {
+               debug_print(_("unknown menu entry %s\n"), path);
+               return;
+       }
        gtk_widget_set_sensitive(widget, sensitive);
 }
 
@@ -98,4 +104,42 @@ void menu_set_toggle(GtkItemFactory *ifactory, const gchar *path,
 
        widget = gtk_item_factory_get_item(ifactory, path);
        gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(widget), active);
-}
\ No newline at end of file
+}
+
+void menu_button_position(GtkMenu *menu, gint *x, gint *y, gpointer user_data)
+{
+       GtkWidget *button;
+       GtkRequisition requisition;
+       gint button_xpos, button_ypos;
+       gint xpos, ypos;
+       gint width, height;
+       gint scr_width, scr_height;
+
+       g_return_if_fail(user_data != NULL);
+       g_return_if_fail(GTK_IS_BUTTON(user_data));
+
+       button = GTK_WIDGET(user_data);
+
+       gtk_widget_get_child_requisition(GTK_WIDGET(menu), &requisition);
+       width = requisition.width;
+       height = requisition.height;
+       gdk_window_get_origin(button->window, &button_xpos, &button_ypos);
+
+       xpos = button_xpos;
+       ypos = button_ypos + button->allocation.height;
+
+       scr_width = gdk_screen_width();
+       scr_height = gdk_screen_height();
+
+       if (xpos + width > scr_width)
+               xpos -= (xpos + width) - scr_width;
+       if (ypos + height > scr_height)
+               ypos = button_ypos - height;
+       if (xpos < 0)
+               xpos = 0;
+       if (ypos < 0)
+               ypos = 0;
+
+       *x = xpos;
+       *y = ypos;
+}