X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=shell%2Fev-navigation-action-widget.c;h=c3de6958845d26609c563f0a98b4f215c1629967;hb=d4139205b010ed06310d14284e63114e88ec6de2;hp=1de4cf1a060627ed954f08686221adda5957afb9;hpb=8228ff475e7dced57dbaa9550255534d0c275767;p=evince.git diff --git a/shell/ev-navigation-action-widget.c b/shell/ev-navigation-action-widget.c index 1de4cf1a..c3de6958 100644 --- a/shell/ev-navigation-action-widget.c +++ b/shell/ev-navigation-action-widget.c @@ -14,7 +14,7 @@ * * 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. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "config.h" @@ -27,7 +27,8 @@ static void ev_navigation_action_widget_init (EvNavigationActionWidget static void ev_navigation_action_widget_class_init (EvNavigationActionWidgetClass *action_widget); static void ev_navigation_action_widget_toggled (GtkToggleToolButton *toggle); static gboolean ev_navigation_action_widget_button_press_event (GtkWidget *widget, - GdkEventButton *event); + GdkEventButton *event, + gpointer data); G_DEFINE_TYPE (EvNavigationActionWidget, ev_navigation_action_widget, GTK_TYPE_TOGGLE_TOOL_BUTTON) @@ -42,19 +43,27 @@ static gint signals[LAST_SIGNAL]; static void ev_navigation_action_widget_init (EvNavigationActionWidget *action_widget) { + GtkWidget *toggle_button; + + /* It's rather dirty hack but we need a child to connect to + * button press event + */ + + toggle_button = gtk_bin_get_child (GTK_BIN (action_widget)); + + g_signal_connect (toggle_button, "button-press-event", + G_CALLBACK (ev_navigation_action_widget_button_press_event), + action_widget); return; } static void ev_navigation_action_widget_class_init (EvNavigationActionWidgetClass *klass) { - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); GtkToggleToolButtonClass *toggle_tool_button_class = GTK_TOGGLE_TOOL_BUTTON_CLASS (klass); - widget_class->button_press_event = ev_navigation_action_widget_button_press_event; toggle_tool_button_class->toggled = ev_navigation_action_widget_toggled; - signals[SHOW_MENU] = g_signal_new ("show-menu", G_OBJECT_CLASS_TYPE (klass), @@ -89,7 +98,7 @@ ev_navigation_action_widget_set_menu(EvNavigationActionWidget *button, GtkWidget if (button->menu == GTK_MENU (menu)) return; - if (button->menu && GTK_WIDGET_VISIBLE (button->menu)) + if (button->menu && gtk_widget_get_visible (GTK_WIDGET (button->menu))) gtk_menu_shell_deactivate (GTK_MENU_SHELL (button->menu)); if (button->menu) { @@ -118,35 +127,39 @@ menu_position_func (GtkMenu *menu, { GtkWidget *widget = GTK_WIDGET (button); GtkRequisition menu_req; + GtkAllocation allocation; GtkTextDirection direction; + GdkWindow *gdk_window; GdkRectangle monitor; gint monitor_num; GdkScreen *screen; - gtk_widget_size_request (GTK_WIDGET (button->menu), &menu_req); + gtk_widget_get_preferred_size (GTK_WIDGET (button->menu), &menu_req, NULL); 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); + gdk_window = gtk_widget_get_window (widget); + monitor_num = gdk_screen_get_monitor_at_window (screen, gdk_window); if (monitor_num < 0) monitor_num = 0; gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); - gdk_window_get_origin (widget->window, x, y); - *x += widget->allocation.x; - *y += widget->allocation.y; + gdk_window_get_origin (gdk_window, x, y); + gtk_widget_get_allocation (widget, &allocation); + *x += allocation.x; + *y += 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; + *x += MAX (allocation.width - menu_req.width, 0); + else if (menu_req.width > allocation.width) + *x -= menu_req.width - allocation.width; - if ((*y + widget->allocation.height + menu_req.height) <= monitor.y + monitor.height) - *y += widget->allocation.height; + if ((*y + allocation.height + menu_req.height) <= monitor.y + monitor.height) + *y += 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 if (monitor.y + monitor.height - (*y + allocation.height) > *y) + *y += allocation.height; else *y -= menu_req.height; @@ -157,11 +170,11 @@ static void popup_menu_under_arrow (EvNavigationActionWidget *button, GdkEventButton *event) { + g_signal_emit (button, signals[SHOW_MENU], 0); + if (!button->menu) return; - g_signal_emit (button, signals[SHOW_MENU], 0); - gtk_menu_popup (button->menu, NULL, NULL, (GtkMenuPositionFunc) menu_position_func, button, @@ -177,7 +190,7 @@ ev_navigation_action_widget_toggled (GtkToggleToolButton *toggle) return; if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (button)) && - !GTK_WIDGET_VISIBLE (button->menu)) { + !gtk_widget_get_visible (GTK_WIDGET (button->menu))) { /* we get here only when the menu is activated by a key * press, so that we can select the first menu item */ popup_menu_under_arrow (button, NULL); @@ -187,9 +200,11 @@ ev_navigation_action_widget_toggled (GtkToggleToolButton *toggle) static gboolean ev_navigation_action_widget_button_press_event (GtkWidget *widget, - GdkEventButton *event) + GdkEventButton *event, + gpointer data) { - EvNavigationActionWidget *button = EV_NAVIGATION_ACTION_WIDGET (widget); + EvNavigationActionWidget *button = EV_NAVIGATION_ACTION_WIDGET (data); + if (event->button == 1) { popup_menu_under_arrow (button, event); gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (button), TRUE);