forked from AuroraMiddleware/gtk
menu: Don't set widget->window
Instead, create an input window for the menubar and omit the window for the menu itself.
This commit is contained in:
parent
633a93f418
commit
bb8b24da47
@ -2598,37 +2598,24 @@ gtk_menu_realize (GtkWidget *widget)
|
||||
GtkMenu *menu = GTK_MENU (widget);
|
||||
GtkMenuPrivate *priv = menu->priv;
|
||||
GtkAllocation allocation;
|
||||
GdkWindow *window;
|
||||
GtkWidget *child;
|
||||
GList *children;
|
||||
GtkBorder arrow_border, padding;
|
||||
|
||||
g_return_if_fail (GTK_IS_MENU (widget));
|
||||
|
||||
gtk_widget_set_realized (widget, TRUE);
|
||||
GTK_WIDGET_CLASS (gtk_menu_parent_class)->realize (widget);
|
||||
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
|
||||
window = gdk_window_new_child (gtk_widget_get_parent_window (widget),
|
||||
gtk_widget_get_events (widget)
|
||||
| GDK_KEY_PRESS_MASK
|
||||
| GDK_ENTER_NOTIFY_MASK
|
||||
| GDK_LEAVE_NOTIFY_MASK,
|
||||
&allocation);
|
||||
gtk_widget_set_window (widget, window);
|
||||
gtk_widget_register_window (widget, window);
|
||||
|
||||
get_menu_padding (widget, &padding);
|
||||
get_arrows_border (menu, &arrow_border);
|
||||
|
||||
priv->view_window = gdk_window_new_child (window,
|
||||
priv->view_window = gdk_window_new_child (gtk_widget_get_window (widget),
|
||||
gtk_widget_get_events (widget)
|
||||
| GDK_KEY_PRESS_MASK
|
||||
| GDK_ENTER_NOTIFY_MASK
|
||||
| GDK_LEAVE_NOTIFY_MASK,
|
||||
&(GdkRectangle) {
|
||||
padding.left,
|
||||
padding.top + arrow_border.top,
|
||||
allocation.x + padding.left,
|
||||
allocation.y + padding.top + arrow_border.top,
|
||||
MAX (1, allocation.width - padding.left - padding.right),
|
||||
MAX (1, allocation.height - padding.top - padding.bottom
|
||||
- arrow_border.top - arrow_border.bottom)});
|
||||
@ -2853,8 +2840,8 @@ gtk_menu_size_allocate (GtkWidget *widget,
|
||||
for (i = 0; i < priv->heights_length; i++)
|
||||
priv->requested_height += priv->heights[i];
|
||||
|
||||
x = padding.left;
|
||||
y = padding.top;
|
||||
x = allocation->x + padding.left;
|
||||
y = allocation->y + padding.top;
|
||||
width = allocation->width - padding.left - padding.right;
|
||||
height = allocation->height - padding.top - padding.bottom;
|
||||
|
||||
@ -2886,10 +2873,6 @@ gtk_menu_size_allocate (GtkWidget *widget,
|
||||
|
||||
if (gtk_widget_get_realized (widget))
|
||||
{
|
||||
gdk_window_move_resize (gtk_widget_get_window (widget),
|
||||
allocation->x, allocation->y,
|
||||
allocation->width, allocation->height);
|
||||
|
||||
gdk_window_move_resize (priv->view_window, x, y, width, height);
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,7 @@ struct _GtkMenuBarPrivate
|
||||
GtkPackDirection pack_direction;
|
||||
GtkPackDirection child_pack_direction;
|
||||
|
||||
GdkWindow *input_window;
|
||||
GtkCssGadget *gadget;
|
||||
};
|
||||
|
||||
@ -96,6 +97,8 @@ static void gtk_menu_bar_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation);
|
||||
static gint gtk_menu_bar_draw (GtkWidget *widget,
|
||||
cairo_t *cr);
|
||||
static void gtk_menu_bar_realize (GtkWidget *widget);
|
||||
static void gtk_menu_bar_unrealize (GtkWidget *widget);
|
||||
static void gtk_menu_bar_hierarchy_changed (GtkWidget *widget,
|
||||
GtkWidget *old_toplevel);
|
||||
static gint gtk_menu_bar_get_popup_delay (GtkMenuShell *menu_shell);
|
||||
@ -144,7 +147,11 @@ gtk_menu_bar_class_init (GtkMenuBarClass *class)
|
||||
|
||||
widget_class->measure = gtk_menu_bar_measure_;
|
||||
widget_class->size_allocate = gtk_menu_bar_size_allocate;
|
||||
widget_class->size_allocate = gtk_menu_bar_size_allocate;
|
||||
widget_class->size_allocate = gtk_menu_bar_size_allocate;
|
||||
widget_class->draw = gtk_menu_bar_draw;
|
||||
widget_class->realize = gtk_menu_bar_realize;
|
||||
widget_class->unrealize = gtk_menu_bar_unrealize;
|
||||
widget_class->hierarchy_changed = gtk_menu_bar_hierarchy_changed;
|
||||
|
||||
menu_shell_class->submenu_placement = GTK_TOP_BOTTOM;
|
||||
@ -317,6 +324,42 @@ gtk_menu_bar_get_property (GObject *object,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_menu_bar_realize (GtkWidget *widget)
|
||||
{
|
||||
GtkMenuBar *menubar = GTK_MENU_BAR (widget);
|
||||
GtkMenuBarPrivate *priv = menubar->priv;
|
||||
GtkAllocation allocation;
|
||||
|
||||
GTK_WIDGET_CLASS (gtk_menu_bar_parent_class)->realize (widget);
|
||||
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
|
||||
priv->input_window = gdk_window_new_input (gtk_widget_get_window (widget),
|
||||
gtk_widget_get_events (widget)
|
||||
| GDK_BUTTON_PRESS_MASK
|
||||
| GDK_BUTTON_RELEASE_MASK
|
||||
| GDK_POINTER_MOTION_MASK
|
||||
| GDK_KEY_PRESS_MASK
|
||||
| GDK_ENTER_NOTIFY_MASK
|
||||
| GDK_LEAVE_NOTIFY_MASK,
|
||||
&allocation);
|
||||
gtk_widget_register_window (widget, priv->input_window);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_menu_bar_unrealize (GtkWidget *widget)
|
||||
{
|
||||
GtkMenuBar *menubar = GTK_MENU_BAR (widget);
|
||||
GtkMenuBarPrivate *priv = menubar->priv;
|
||||
|
||||
gtk_widget_unregister_window (widget, priv->input_window);
|
||||
gdk_window_destroy (priv->input_window);
|
||||
priv->input_window = NULL;
|
||||
|
||||
GTK_WIDGET_CLASS (gtk_menu_bar_parent_class)->unrealize (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_menu_bar_measure (GtkCssGadget *gadget,
|
||||
GtkOrientation orientation,
|
||||
@ -556,20 +599,18 @@ static void
|
||||
gtk_menu_bar_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation)
|
||||
{
|
||||
GtkMenuBar *menu_bar;
|
||||
GtkMenuBar *menu_bar = GTK_MENU_BAR (widget);
|
||||
GtkMenuBarPrivate *priv = menu_bar->priv;
|
||||
GtkAllocation clip, content_allocation;
|
||||
|
||||
menu_bar = GTK_MENU_BAR (widget);
|
||||
gtk_widget_set_allocation (widget, allocation);
|
||||
|
||||
if (gtk_widget_get_realized (widget))
|
||||
gdk_window_move_resize (gtk_widget_get_window (widget),
|
||||
gdk_window_move_resize (priv->input_window,
|
||||
allocation->x, allocation->y,
|
||||
allocation->width, allocation->height);
|
||||
|
||||
content_allocation = *allocation;
|
||||
content_allocation.x = content_allocation.y = 0;
|
||||
gtk_css_gadget_allocate (menu_bar->priv->gadget,
|
||||
gtk_css_gadget_allocate (priv->gadget,
|
||||
&content_allocation,
|
||||
gtk_widget_get_allocated_baseline (widget),
|
||||
&clip);
|
||||
|
@ -115,7 +115,6 @@ static void gtk_menu_shell_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void gtk_menu_shell_realize (GtkWidget *widget);
|
||||
static void gtk_menu_shell_finalize (GObject *object);
|
||||
static void gtk_menu_shell_dispose (GObject *object);
|
||||
static gint gtk_menu_shell_button_press (GtkWidget *widget,
|
||||
@ -189,7 +188,6 @@ gtk_menu_shell_class_init (GtkMenuShellClass *klass)
|
||||
object_class->finalize = gtk_menu_shell_finalize;
|
||||
object_class->dispose = gtk_menu_shell_dispose;
|
||||
|
||||
widget_class->realize = gtk_menu_shell_realize;
|
||||
widget_class->button_press_event = gtk_menu_shell_button_press;
|
||||
widget_class->button_release_event = gtk_menu_shell_button_release;
|
||||
widget_class->grab_broken_event = gtk_menu_shell_grab_broken;
|
||||
@ -434,7 +432,7 @@ gtk_menu_shell_init (GtkMenuShell *menu_shell)
|
||||
menu_shell->priv = gtk_menu_shell_get_instance_private (menu_shell);
|
||||
menu_shell->priv->take_focus = TRUE;
|
||||
|
||||
gtk_widget_set_has_window (GTK_WIDGET (menu_shell), TRUE);
|
||||
gtk_widget_set_has_window (GTK_WIDGET (menu_shell), FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -582,29 +580,6 @@ gtk_menu_shell_deactivate (GtkMenuShell *menu_shell)
|
||||
g_signal_emit (menu_shell, menu_shell_signals[DEACTIVATE], 0);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_menu_shell_realize (GtkWidget *widget)
|
||||
{
|
||||
GtkAllocation allocation;
|
||||
GdkWindow *window;
|
||||
|
||||
gtk_widget_set_realized (widget, TRUE);
|
||||
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
|
||||
window = gdk_window_new_child (gtk_widget_get_parent_window (widget),
|
||||
gtk_widget_get_events (widget)
|
||||
| GDK_BUTTON_PRESS_MASK
|
||||
| GDK_BUTTON_RELEASE_MASK
|
||||
| GDK_POINTER_MOTION_MASK
|
||||
| GDK_KEY_PRESS_MASK
|
||||
| GDK_ENTER_NOTIFY_MASK
|
||||
| GDK_LEAVE_NOTIFY_MASK,
|
||||
&allocation);
|
||||
gtk_widget_set_window (widget, window);
|
||||
gtk_widget_register_window (widget, window);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_menu_shell_activate (GtkMenuShell *menu_shell)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user