forked from AuroraMiddleware/gtk
combobox: Remove dead code & unneeded type checks
Commit fdc0c6426b
removed the appears-as-
list style property, & hence the ability to put the ComboBox into list
mode – but it left behind a pile of hijinks that were only used in said
mode & so were now doing absolutely nothing. This commit deletes those.
While doing that, I got carried away…so this also stops pointlessly type
checking popup_widget, as that can never be anything but a GtkTreeMenu.
It still checks for NULL everywhere, which shouldn’t be needed, but (A)
this commit is already too big, & (B) simply removing such checks where
they _seem_ unnecessary causes bad times. I’ll puzzle through that later
This commit is contained in:
parent
d7c3d86f02
commit
68824e80fd
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include "gtkcombobox.h"
|
#include "gtkcombobox.h"
|
||||||
|
|
||||||
#include "gtkadjustment.h"
|
|
||||||
#include "gtkcellareabox.h"
|
#include "gtkcellareabox.h"
|
||||||
#include "gtktreemenu.h"
|
#include "gtktreemenu.h"
|
||||||
#include "gtkbindings.h"
|
#include "gtkbindings.h"
|
||||||
@ -36,12 +35,9 @@
|
|||||||
#include "gtkmain.h"
|
#include "gtkmain.h"
|
||||||
#include "gtkmenuprivate.h"
|
#include "gtkmenuprivate.h"
|
||||||
#include "gtkmenushellprivate.h"
|
#include "gtkmenushellprivate.h"
|
||||||
#include "gtkscrolledwindow.h"
|
|
||||||
#include "gtktogglebutton.h"
|
#include "gtktogglebutton.h"
|
||||||
#include "gtktreeselection.h"
|
|
||||||
#include "gtkwidgetpath.h"
|
#include "gtkwidgetpath.h"
|
||||||
#include "gtkwidgetprivate.h"
|
#include "gtkwidgetprivate.h"
|
||||||
#include "gtkwindow.h"
|
|
||||||
#include "gtktypebuiltins.h"
|
#include "gtktypebuiltins.h"
|
||||||
#include "gtkprivate.h"
|
#include "gtkprivate.h"
|
||||||
#include "gtkcomboboxprivate.h"
|
#include "gtkcomboboxprivate.h"
|
||||||
@ -55,7 +51,6 @@
|
|||||||
#include "gtkintl.h"
|
#include "gtkintl.h"
|
||||||
|
|
||||||
#include "gtkentryprivate.h"
|
#include "gtkentryprivate.h"
|
||||||
#include "gtktreeprivate.h"
|
|
||||||
#include "a11y/gtkcomboboxaccessible.h"
|
#include "a11y/gtkcomboboxaccessible.h"
|
||||||
|
|
||||||
|
|
||||||
@ -144,8 +139,6 @@ struct _GtkComboBoxPrivate
|
|||||||
GtkWidget *arrow;
|
GtkWidget *arrow;
|
||||||
|
|
||||||
GtkWidget *popup_widget;
|
GtkWidget *popup_widget;
|
||||||
GtkWidget *popup_window;
|
|
||||||
GtkWidget *scrolled_window;
|
|
||||||
|
|
||||||
GtkCssGadget *gadget;
|
GtkCssGadget *gadget;
|
||||||
|
|
||||||
@ -179,54 +172,23 @@ struct _GtkComboBoxPrivate
|
|||||||
GtkTreeViewRowSeparatorFunc row_separator_func;
|
GtkTreeViewRowSeparatorFunc row_separator_func;
|
||||||
gpointer row_separator_data;
|
gpointer row_separator_data;
|
||||||
GDestroyNotify row_separator_destroy;
|
GDestroyNotify row_separator_destroy;
|
||||||
|
|
||||||
GdkDevice *grab_pointer;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* While debugging this evil code, I have learned that
|
/* There are 2 modes to this widget, which can be characterized as follows:
|
||||||
* there are actually 4 modes to this widget, which can
|
|
||||||
* be characterized as follows
|
|
||||||
*
|
*
|
||||||
* 1) menu mode, no child added
|
* 1) no child added:
|
||||||
*
|
*
|
||||||
* tree_view -> NULL
|
|
||||||
* cell_view -> GtkCellView, regular child
|
* cell_view -> GtkCellView, regular child
|
||||||
* button -> GtkToggleButton set_parent to combo
|
* button -> GtkToggleButton set_parent to combo
|
||||||
* arrow -> GtkArrow set_parent to button
|
* arrow -> GtkArrow set_parent to button
|
||||||
* popup_widget -> GtkMenu
|
* popup_widget -> GtkMenu
|
||||||
* popup_window -> NULL
|
|
||||||
* scrolled_window -> NULL
|
|
||||||
*
|
*
|
||||||
* 2) menu mode, child added
|
* 2) child added:
|
||||||
*
|
*
|
||||||
* tree_view -> NULL
|
|
||||||
* cell_view -> NULL
|
* cell_view -> NULL
|
||||||
* button -> GtkToggleButton set_parent to combo
|
* button -> GtkToggleButton set_parent to combo
|
||||||
* arrow -> GtkArrow, child of button
|
* arrow -> GtkArrow, child of button
|
||||||
* popup_widget -> GtkMenu
|
* popup_widget -> GtkMenu
|
||||||
* popup_window -> NULL
|
|
||||||
* scrolled_window -> NULL
|
|
||||||
*
|
|
||||||
* 3) list mode, no child added
|
|
||||||
*
|
|
||||||
* tree_view -> GtkTreeView, child of scrolled_window
|
|
||||||
* cell_view -> GtkCellView, regular child
|
|
||||||
* button -> GtkToggleButton, set_parent to combo
|
|
||||||
* arrow -> GtkArrow, child of button
|
|
||||||
* popup_widget -> tree_view
|
|
||||||
* popup_window -> GtkWindow
|
|
||||||
* scrolled_window -> GtkScrolledWindow, child of popup_window
|
|
||||||
*
|
|
||||||
* 4) list mode, child added
|
|
||||||
*
|
|
||||||
* tree_view -> GtkTreeView, child of scrolled_window
|
|
||||||
* cell_view -> NULL
|
|
||||||
* button -> GtkToggleButton, set_parent to combo
|
|
||||||
* arrow -> GtkArrow, child of button
|
|
||||||
* popup_widget -> tree_view
|
|
||||||
* popup_window -> GtkWindow
|
|
||||||
* scrolled_window -> GtkScrolledWindow, child of popup_window
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -290,9 +252,6 @@ static void gtk_combo_box_menu_show (GtkWidget *menu,
|
|||||||
static void gtk_combo_box_menu_hide (GtkWidget *menu,
|
static void gtk_combo_box_menu_hide (GtkWidget *menu,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
static void gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
|
|
||||||
GtkWidget *popup);
|
|
||||||
|
|
||||||
static void gtk_combo_box_unset_model (GtkComboBox *combo_box);
|
static void gtk_combo_box_unset_model (GtkComboBox *combo_box);
|
||||||
|
|
||||||
static void gtk_combo_box_forall (GtkContainer *container,
|
static void gtk_combo_box_forall (GtkContainer *container,
|
||||||
@ -304,7 +263,6 @@ static gboolean gtk_combo_box_scroll_event (GtkWidget *widget,
|
|||||||
static void gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
|
static void gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
|
||||||
GtkTreePath *path);
|
GtkTreePath *path);
|
||||||
|
|
||||||
static void gtk_combo_box_check_appearance (GtkComboBox *combo_box);
|
|
||||||
static void gtk_combo_box_real_move_active (GtkComboBox *combo_box,
|
static void gtk_combo_box_real_move_active (GtkComboBox *combo_box,
|
||||||
GtkScrollType scroll);
|
GtkScrollType scroll);
|
||||||
static void gtk_combo_box_real_popup (GtkComboBox *combo_box);
|
static void gtk_combo_box_real_popup (GtkComboBox *combo_box);
|
||||||
@ -1070,6 +1028,7 @@ gtk_combo_box_init (GtkComboBox *combo_box)
|
|||||||
combo_box->priv = gtk_combo_box_get_instance_private (combo_box);
|
combo_box->priv = gtk_combo_box_get_instance_private (combo_box);
|
||||||
priv = combo_box->priv;
|
priv = combo_box->priv;
|
||||||
|
|
||||||
|
priv->popup_widget = NULL;
|
||||||
priv->wrap_width = 0;
|
priv->wrap_width = 0;
|
||||||
|
|
||||||
priv->active = -1;
|
priv->active = -1;
|
||||||
@ -1291,15 +1250,6 @@ gtk_combo_box_get_property (GObject *object,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
gtk_combo_box_check_appearance (GtkComboBox *combo_box)
|
|
||||||
{
|
|
||||||
GtkComboBoxPrivate *priv = combo_box->priv;
|
|
||||||
/* Create the menu mode widgets, if they don't already exist. */
|
|
||||||
if (!GTK_IS_MENU (priv->popup_widget))
|
|
||||||
gtk_combo_box_menu_setup (combo_box);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_combo_box_button_toggled (GtkWidget *widget,
|
gtk_combo_box_button_toggled (GtkWidget *widget,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
@ -1312,7 +1262,9 @@ gtk_combo_box_button_toggled (GtkWidget *widget,
|
|||||||
gtk_combo_box_popup (combo_box);
|
gtk_combo_box_popup (combo_box);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
gtk_combo_box_popdown (combo_box);
|
gtk_combo_box_popdown (combo_box);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1421,7 +1373,7 @@ gtk_combo_box_remove (GtkContainer *container,
|
|||||||
|
|
||||||
gtk_widget_queue_resize (GTK_WIDGET (container));
|
gtk_widget_queue_resize (GTK_WIDGET (container));
|
||||||
|
|
||||||
if (GTK_IS_MENU (priv->popup_widget))
|
if (priv->popup_widget)
|
||||||
{
|
{
|
||||||
gtk_combo_box_menu_destroy (combo_box);
|
gtk_combo_box_menu_destroy (combo_box);
|
||||||
gtk_menu_detach (GTK_MENU (priv->popup_widget));
|
gtk_menu_detach (GTK_MENU (priv->popup_widget));
|
||||||
@ -1439,7 +1391,9 @@ gtk_combo_box_remove (GtkContainer *container,
|
|||||||
gtk_tree_path_free (path);
|
gtk_tree_path_free (path);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
gtk_combo_box_set_active_internal (combo_box, NULL);
|
gtk_combo_box_set_active_internal (combo_box, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1488,104 +1442,6 @@ gtk_combo_box_detacher (GtkWidget *widget,
|
|||||||
priv->popup_widget = NULL;
|
priv->popup_widget = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
|
|
||||||
GtkWidget *popup)
|
|
||||||
{
|
|
||||||
GtkComboBoxPrivate *priv = combo_box->priv;
|
|
||||||
|
|
||||||
if (GTK_IS_MENU (priv->popup_widget))
|
|
||||||
{
|
|
||||||
gtk_menu_detach (GTK_MENU (priv->popup_widget));
|
|
||||||
priv->popup_widget = NULL;
|
|
||||||
}
|
|
||||||
else if (priv->popup_widget)
|
|
||||||
{
|
|
||||||
gtk_container_remove (GTK_CONTAINER (priv->scrolled_window),
|
|
||||||
priv->popup_widget);
|
|
||||||
g_object_unref (priv->popup_widget);
|
|
||||||
priv->popup_widget = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GTK_IS_MENU (popup))
|
|
||||||
{
|
|
||||||
if (priv->popup_window)
|
|
||||||
{
|
|
||||||
gtk_widget_destroy (priv->popup_window);
|
|
||||||
priv->popup_window = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
priv->popup_widget = popup;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Note that we connect to show/hide on the toplevel, not the
|
|
||||||
* menu itself, since the menu is not shown/hidden when it is
|
|
||||||
* popped up while torn-off.
|
|
||||||
*/
|
|
||||||
g_signal_connect (GTK_MENU (popup)->priv->toplevel, "show",
|
|
||||||
G_CALLBACK (gtk_combo_box_menu_show), combo_box);
|
|
||||||
g_signal_connect (GTK_MENU (popup)->priv->toplevel, "hide",
|
|
||||||
G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
|
|
||||||
|
|
||||||
gtk_menu_attach_to_widget (GTK_MENU (popup),
|
|
||||||
GTK_WIDGET (combo_box),
|
|
||||||
gtk_combo_box_detacher);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!priv->popup_window)
|
|
||||||
{
|
|
||||||
GtkWidget *toplevel;
|
|
||||||
|
|
||||||
priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
|
|
||||||
gtk_widget_set_name (priv->popup_window, "gtk-combobox-popup-window");
|
|
||||||
|
|
||||||
gtk_window_set_type_hint (GTK_WINDOW (priv->popup_window),
|
|
||||||
GDK_WINDOW_TYPE_HINT_COMBO);
|
|
||||||
|
|
||||||
g_signal_connect (GTK_WINDOW (priv->popup_window),"show",
|
|
||||||
G_CALLBACK (gtk_combo_box_child_show),
|
|
||||||
combo_box);
|
|
||||||
g_signal_connect (GTK_WINDOW (priv->popup_window),"hide",
|
|
||||||
G_CALLBACK (gtk_combo_box_child_hide),
|
|
||||||
combo_box);
|
|
||||||
|
|
||||||
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
|
|
||||||
if (GTK_IS_WINDOW (toplevel))
|
|
||||||
{
|
|
||||||
gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
|
|
||||||
GTK_WINDOW (priv->popup_window));
|
|
||||||
gtk_window_set_transient_for (GTK_WINDOW (priv->popup_window),
|
|
||||||
GTK_WINDOW (toplevel));
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_window_set_resizable (GTK_WINDOW (priv->popup_window), FALSE);
|
|
||||||
gtk_window_set_screen (GTK_WINDOW (priv->popup_window),
|
|
||||||
gtk_widget_get_screen (GTK_WIDGET (combo_box)));
|
|
||||||
|
|
||||||
priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
|
||||||
|
|
||||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
|
|
||||||
GTK_POLICY_NEVER,
|
|
||||||
GTK_POLICY_NEVER);
|
|
||||||
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window),
|
|
||||||
GTK_SHADOW_IN);
|
|
||||||
|
|
||||||
gtk_widget_show (priv->scrolled_window);
|
|
||||||
|
|
||||||
gtk_container_add (GTK_CONTAINER (priv->popup_window),
|
|
||||||
priv->scrolled_window);
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_container_add (GTK_CONTAINER (priv->scrolled_window),
|
|
||||||
popup);
|
|
||||||
|
|
||||||
gtk_widget_show (popup);
|
|
||||||
g_object_ref (popup);
|
|
||||||
priv->popup_widget = popup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
cell_layout_is_sensitive (GtkCellLayout *layout)
|
cell_layout_is_sensitive (GtkCellLayout *layout)
|
||||||
{
|
{
|
||||||
@ -1754,11 +1610,11 @@ gtk_combo_box_menu_popup (GtkComboBox *combo_box,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* FIXME handle nested menus better */
|
|
||||||
gint rect_anchor_dy = -2;
|
gint rect_anchor_dy = -2;
|
||||||
GList *i;
|
GList *i;
|
||||||
GtkWidget *child;
|
GtkWidget *child;
|
||||||
|
|
||||||
|
/* FIXME handle nested menus better */
|
||||||
active = gtk_menu_get_active (GTK_MENU (priv->popup_widget));
|
active = gtk_menu_get_active (GTK_MENU (priv->popup_widget));
|
||||||
|
|
||||||
if (!(active && gtk_widget_get_visible (active)))
|
if (!(active && gtk_widget_get_visible (active)))
|
||||||
@ -1818,135 +1674,6 @@ gtk_combo_box_menu_popup (GtkComboBox *combo_box,
|
|||||||
gtk_menu_shell_select_item (GTK_MENU_SHELL (priv->popup_widget), active);
|
gtk_menu_shell_select_item (GTK_MENU_SHELL (priv->popup_widget), active);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
popup_grab_on_window (GdkWindow *window,
|
|
||||||
GdkDevice *pointer)
|
|
||||||
{
|
|
||||||
GdkGrabStatus status;
|
|
||||||
GdkSeat *seat;
|
|
||||||
|
|
||||||
seat = gdk_device_get_seat (pointer);
|
|
||||||
status = gdk_seat_grab (seat, window,
|
|
||||||
GDK_SEAT_CAPABILITY_ALL, TRUE,
|
|
||||||
NULL, NULL, NULL, NULL);
|
|
||||||
|
|
||||||
return status == GDK_GRAB_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gtk_combo_box_grab_broken_event (GtkWidget *widget,
|
|
||||||
GdkEventGrabBroken *event,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
|
||||||
|
|
||||||
if (event->grab_window == NULL)
|
|
||||||
gtk_combo_box_popdown (combo_box);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
gtk_combo_box_list_position (GtkComboBox *combo_box,
|
|
||||||
gint *x,
|
|
||||||
gint *y,
|
|
||||||
gint *width,
|
|
||||||
gint *height)
|
|
||||||
{
|
|
||||||
GtkComboBoxPrivate *priv = combo_box->priv;
|
|
||||||
GtkAllocation content_allocation;
|
|
||||||
GdkDisplay *display;
|
|
||||||
GdkMonitor *monitor;
|
|
||||||
GdkRectangle area;
|
|
||||||
GtkRequisition popup_req;
|
|
||||||
GtkPolicyType hpolicy, vpolicy;
|
|
||||||
GdkWindow *window;
|
|
||||||
|
|
||||||
/* under windows, the drop down list is as wide as the combo box itself.
|
|
||||||
see bug #340204 */
|
|
||||||
GtkWidget *widget = GTK_WIDGET (combo_box);
|
|
||||||
|
|
||||||
gtk_css_gadget_get_content_allocation (priv->gadget, &content_allocation, NULL);
|
|
||||||
|
|
||||||
*x = content_allocation.x;
|
|
||||||
*y = content_allocation.y;
|
|
||||||
*width = content_allocation.width;
|
|
||||||
|
|
||||||
window = gtk_widget_get_window (GTK_WIDGET (combo_box));
|
|
||||||
gdk_window_get_root_coords (window, *x, *y, x, y);
|
|
||||||
|
|
||||||
hpolicy = vpolicy = GTK_POLICY_NEVER;
|
|
||||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
|
|
||||||
hpolicy, vpolicy);
|
|
||||||
|
|
||||||
if (priv->popup_fixed_width)
|
|
||||||
{
|
|
||||||
gtk_widget_get_preferred_size (priv->scrolled_window, &popup_req, NULL);
|
|
||||||
|
|
||||||
if (popup_req.width > *width)
|
|
||||||
{
|
|
||||||
hpolicy = GTK_POLICY_ALWAYS;
|
|
||||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
|
|
||||||
hpolicy, vpolicy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* XXX This code depends on treeviews properly reporting their natural width
|
|
||||||
* list-mode menus won't fill up to their natural width until then */
|
|
||||||
gtk_widget_get_preferred_size (priv->scrolled_window, NULL, &popup_req);
|
|
||||||
|
|
||||||
if (popup_req.width > *width)
|
|
||||||
{
|
|
||||||
hpolicy = GTK_POLICY_NEVER;
|
|
||||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
|
|
||||||
hpolicy, vpolicy);
|
|
||||||
|
|
||||||
*width = popup_req.width;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*height = popup_req.height;
|
|
||||||
|
|
||||||
display = gtk_widget_get_display (widget);
|
|
||||||
monitor = gdk_display_get_monitor_at_window (display, window);
|
|
||||||
gdk_monitor_get_workarea (monitor, &area);
|
|
||||||
|
|
||||||
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
|
||||||
*x = *x + content_allocation.width - *width;
|
|
||||||
|
|
||||||
if (*x < area.x)
|
|
||||||
*x = area.x;
|
|
||||||
else if (*x + *width > area.x + area.width)
|
|
||||||
*x = area.x + area.width - *width;
|
|
||||||
|
|
||||||
if (*y + content_allocation.height + *height <= area.y + area.height)
|
|
||||||
*y += content_allocation.height;
|
|
||||||
else if (*y - *height >= area.y)
|
|
||||||
*y -= *height;
|
|
||||||
else if (area.y + area.height - (*y + content_allocation.height) > *y - area.y)
|
|
||||||
{
|
|
||||||
*y += content_allocation.height;
|
|
||||||
*height = area.y + area.height - *y;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*height = *y - area.y;
|
|
||||||
*y = area.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (popup_req.height > *height)
|
|
||||||
{
|
|
||||||
vpolicy = GTK_POLICY_ALWAYS;
|
|
||||||
|
|
||||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
|
|
||||||
hpolicy, vpolicy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gtk_combo_box_popup:
|
* gtk_combo_box_popup:
|
||||||
* @combo_box: a #GtkComboBox
|
* @combo_box: a #GtkComboBox
|
||||||
@ -1971,9 +1698,10 @@ gtk_combo_box_popup (GtkComboBox *combo_box)
|
|||||||
* @combo_box: a #GtkComboBox
|
* @combo_box: a #GtkComboBox
|
||||||
* @device: a #GdkDevice
|
* @device: a #GdkDevice
|
||||||
*
|
*
|
||||||
* Pops up the menu or dropdown list of @combo_box, the popup window
|
* Pops up the menu of @combo_box. Note that currently this does not do anything
|
||||||
* will be grabbed so only @device and its associated pointer/keyboard
|
* with the device, as it was previously only used for list-mode ComboBoxes,
|
||||||
* are the only #GdkDevices able to send events to it.
|
* and those were removed in GTK+ 4. However, it is retained in case similar
|
||||||
|
* functionality is added back later.
|
||||||
*
|
*
|
||||||
* Since: 3.0
|
* Since: 3.0
|
||||||
**/
|
**/
|
||||||
@ -1981,10 +1709,10 @@ void
|
|||||||
gtk_combo_box_popup_for_device (GtkComboBox *combo_box,
|
gtk_combo_box_popup_for_device (GtkComboBox *combo_box,
|
||||||
GdkDevice *device)
|
GdkDevice *device)
|
||||||
{
|
{
|
||||||
|
/* As above, this currently does not do anything useful, and nothing with the
|
||||||
|
* passed-in device. But the bits that are not blatantly obsolete are kept. */
|
||||||
|
|
||||||
GtkComboBoxPrivate *priv = combo_box->priv;
|
GtkComboBoxPrivate *priv = combo_box->priv;
|
||||||
gint x, y, width, height;
|
|
||||||
GtkWidget *toplevel;
|
|
||||||
GdkDevice *pointer;
|
|
||||||
|
|
||||||
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
||||||
g_return_if_fail (GDK_IS_DEVICE (device));
|
g_return_if_fail (GDK_IS_DEVICE (device));
|
||||||
@ -1995,69 +1723,17 @@ gtk_combo_box_popup_for_device (GtkComboBox *combo_box,
|
|||||||
if (gtk_widget_get_mapped (priv->popup_widget))
|
if (gtk_widget_get_mapped (priv->popup_widget))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (priv->grab_pointer)
|
if (priv->popup_widget)
|
||||||
return;
|
|
||||||
|
|
||||||
if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
|
|
||||||
pointer = gdk_device_get_associated_device (device);
|
|
||||||
else
|
|
||||||
pointer = device;
|
|
||||||
|
|
||||||
if (GTK_IS_MENU (priv->popup_widget))
|
|
||||||
{
|
|
||||||
gtk_combo_box_menu_popup (combo_box, priv->trigger_event);
|
gtk_combo_box_menu_popup (combo_box, priv->trigger_event);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
|
|
||||||
if (GTK_IS_WINDOW (toplevel))
|
|
||||||
gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
|
|
||||||
GTK_WINDOW (priv->popup_window));
|
|
||||||
|
|
||||||
gtk_widget_show_all (priv->scrolled_window);
|
|
||||||
gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);
|
|
||||||
|
|
||||||
gtk_widget_set_size_request (priv->popup_window, width, height);
|
|
||||||
gtk_window_move (GTK_WINDOW (priv->popup_window), x, y);
|
|
||||||
|
|
||||||
/* popup */
|
|
||||||
gtk_widget_show (priv->popup_window);
|
|
||||||
|
|
||||||
gtk_widget_grab_focus (priv->popup_window);
|
|
||||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
|
|
||||||
TRUE);
|
|
||||||
|
|
||||||
if (!popup_grab_on_window (gtk_widget_get_window (priv->popup_window), pointer))
|
|
||||||
{
|
|
||||||
gtk_widget_hide (priv->popup_window);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
priv->grab_pointer = pointer;
|
|
||||||
|
|
||||||
g_signal_connect (priv->popup_window,
|
|
||||||
"grab-broken-event",
|
|
||||||
G_CALLBACK (gtk_combo_box_grab_broken_event),
|
|
||||||
combo_box);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_combo_box_real_popup (GtkComboBox *combo_box)
|
gtk_combo_box_real_popup (GtkComboBox *combo_box)
|
||||||
{
|
{
|
||||||
GdkDevice *device;
|
GtkComboBoxPrivate *priv = combo_box->priv;
|
||||||
|
|
||||||
device = gtk_get_current_event_device ();
|
if (priv->popup_widget)
|
||||||
|
gtk_combo_box_menu_popup (combo_box, priv->trigger_event);
|
||||||
if (!device)
|
|
||||||
{
|
|
||||||
GdkDisplay *display;
|
|
||||||
|
|
||||||
/* No device was set, pick the first master device */
|
|
||||||
display = gtk_widget_get_display (GTK_WIDGET (combo_box));
|
|
||||||
device = gdk_seat_get_pointer (gdk_display_get_default_seat (display));
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_combo_box_popup_for_device (combo_box, device);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -2090,32 +1766,8 @@ gtk_combo_box_popdown (GtkComboBox *combo_box)
|
|||||||
|
|
||||||
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
|
||||||
|
|
||||||
if (GTK_IS_MENU (priv->popup_widget))
|
if (priv->popup_widget)
|
||||||
{
|
|
||||||
gtk_menu_popdown (GTK_MENU (priv->popup_widget));
|
gtk_menu_popdown (GTK_MENU (priv->popup_widget));
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!gtk_widget_get_realized (GTK_WIDGET (combo_box)))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!gtk_widget_is_drawable (priv->popup_window))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (priv->grab_pointer)
|
|
||||||
gdk_seat_ungrab (gdk_device_get_seat (priv->grab_pointer));
|
|
||||||
|
|
||||||
gtk_widget_hide (priv->popup_window);
|
|
||||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button),
|
|
||||||
FALSE);
|
|
||||||
|
|
||||||
if (priv->scroll_timer)
|
|
||||||
{
|
|
||||||
g_source_remove (priv->scroll_timer);
|
|
||||||
priv->scroll_timer = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
priv->grab_pointer = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -2433,7 +2085,26 @@ gtk_combo_box_menu_setup (GtkComboBox *combo_box)
|
|||||||
|
|
||||||
g_signal_connect (menu, "key-press-event",
|
g_signal_connect (menu, "key-press-event",
|
||||||
G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
|
G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
|
||||||
gtk_combo_box_set_popup_widget (combo_box, menu);
|
|
||||||
|
/* Set up the popup menu */
|
||||||
|
if (priv->popup_widget)
|
||||||
|
gtk_menu_detach (GTK_MENU (priv->popup_widget));
|
||||||
|
|
||||||
|
priv->popup_widget = menu;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note that we connect to show/hide on the toplevel, not the
|
||||||
|
* menu itself, since the menu is not shown/hidden when it is
|
||||||
|
* popped up while torn-off.
|
||||||
|
*/
|
||||||
|
g_signal_connect (GTK_MENU (menu)->priv->toplevel, "show",
|
||||||
|
G_CALLBACK (gtk_combo_box_menu_show), combo_box);
|
||||||
|
g_signal_connect (GTK_MENU (menu)->priv->toplevel, "hide",
|
||||||
|
G_CALLBACK (gtk_combo_box_menu_hide), combo_box);
|
||||||
|
|
||||||
|
gtk_menu_attach_to_widget (GTK_MENU (menu),
|
||||||
|
GTK_WIDGET (combo_box),
|
||||||
|
gtk_combo_box_detacher);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -2462,7 +2133,7 @@ gtk_combo_box_menu_button_press (GtkWidget *widget,
|
|||||||
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
|
||||||
GtkComboBoxPrivate *priv = combo_box->priv;
|
GtkComboBoxPrivate *priv = combo_box->priv;
|
||||||
|
|
||||||
if (GTK_IS_MENU (priv->popup_widget) &&
|
if (priv->popup_widget &&
|
||||||
event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY)
|
event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY)
|
||||||
{
|
{
|
||||||
if (gtk_widget_get_focus_on_click (GTK_WIDGET (combo_box)) &&
|
if (gtk_widget_get_focus_on_click (GTK_WIDGET (combo_box)) &&
|
||||||
@ -2775,7 +2446,7 @@ gtk_combo_box_set_wrap_width (GtkComboBox *combo_box,
|
|||||||
{
|
{
|
||||||
priv->wrap_width = width;
|
priv->wrap_width = width;
|
||||||
|
|
||||||
if (GTK_IS_TREE_MENU (priv->popup_widget))
|
if (priv->popup_widget)
|
||||||
_gtk_tree_menu_set_wrap_width (GTK_TREE_MENU (priv->popup_widget), priv->wrap_width);
|
_gtk_tree_menu_set_wrap_width (GTK_TREE_MENU (priv->popup_widget), priv->wrap_width);
|
||||||
|
|
||||||
g_object_notify (G_OBJECT (combo_box), "wrap-width");
|
g_object_notify (G_OBJECT (combo_box), "wrap-width");
|
||||||
@ -2829,7 +2500,7 @@ gtk_combo_box_set_row_span_column (GtkComboBox *combo_box,
|
|||||||
{
|
{
|
||||||
priv->row_column = row_span;
|
priv->row_column = row_span;
|
||||||
|
|
||||||
if (GTK_IS_TREE_MENU (priv->popup_widget))
|
if (priv->popup_widget)
|
||||||
_gtk_tree_menu_set_row_span_column (GTK_TREE_MENU (priv->popup_widget), priv->row_column);
|
_gtk_tree_menu_set_row_span_column (GTK_TREE_MENU (priv->popup_widget), priv->row_column);
|
||||||
|
|
||||||
g_object_notify (G_OBJECT (combo_box), "row-span-column");
|
g_object_notify (G_OBJECT (combo_box), "row-span-column");
|
||||||
@ -2883,7 +2554,7 @@ gtk_combo_box_set_column_span_column (GtkComboBox *combo_box,
|
|||||||
{
|
{
|
||||||
priv->col_column = column_span;
|
priv->col_column = column_span;
|
||||||
|
|
||||||
if (GTK_IS_TREE_MENU (priv->popup_widget))
|
if (priv->popup_widget)
|
||||||
_gtk_tree_menu_set_column_span_column (GTK_TREE_MENU (priv->popup_widget), priv->col_column);
|
_gtk_tree_menu_set_column_span_column (GTK_TREE_MENU (priv->popup_widget), priv->col_column);
|
||||||
|
|
||||||
g_object_notify (G_OBJECT (combo_box), "column-span-column");
|
g_object_notify (G_OBJECT (combo_box), "column-span-column");
|
||||||
@ -2996,10 +2667,8 @@ gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
|
|||||||
|
|
||||||
if (!path)
|
if (!path)
|
||||||
{
|
{
|
||||||
GtkMenu *menu = GTK_MENU (priv->popup_widget);
|
if (priv->popup_widget)
|
||||||
|
gtk_menu_set_active (GTK_MENU (priv->popup_widget), -1);
|
||||||
if (GTK_IS_MENU (menu))
|
|
||||||
gtk_menu_set_active (menu, -1);
|
|
||||||
|
|
||||||
if (priv->cell_view)
|
if (priv->cell_view)
|
||||||
gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), NULL);
|
gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view), NULL);
|
||||||
@ -3016,12 +2685,10 @@ gtk_combo_box_set_active_internal (GtkComboBox *combo_box,
|
|||||||
priv->active_row =
|
priv->active_row =
|
||||||
gtk_tree_row_reference_new (priv->model, path);
|
gtk_tree_row_reference_new (priv->model, path);
|
||||||
|
|
||||||
if (GTK_IS_MENU (priv->popup_widget))
|
|
||||||
{
|
|
||||||
/* FIXME handle nested menus better */
|
/* FIXME handle nested menus better */
|
||||||
|
if (priv->popup_widget)
|
||||||
gtk_menu_set_active (GTK_MENU (priv->popup_widget),
|
gtk_menu_set_active (GTK_MENU (priv->popup_widget),
|
||||||
gtk_tree_path_get_indices (path)[0]);
|
gtk_tree_path_get_indices (path)[0]);
|
||||||
}
|
|
||||||
|
|
||||||
if (priv->cell_view)
|
if (priv->cell_view)
|
||||||
gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view),
|
gtk_cell_view_set_displayed_row (GTK_CELL_VIEW (priv->cell_view),
|
||||||
@ -3146,12 +2813,9 @@ gtk_combo_box_set_model (GtkComboBox *combo_box,
|
|||||||
G_CALLBACK (gtk_combo_box_model_row_changed),
|
G_CALLBACK (gtk_combo_box_model_row_changed),
|
||||||
combo_box);
|
combo_box);
|
||||||
|
|
||||||
if (GTK_IS_TREE_MENU (priv->popup_widget))
|
if (priv->popup_widget)
|
||||||
{
|
|
||||||
/* menu mode */
|
|
||||||
_gtk_tree_menu_set_model (GTK_TREE_MENU (priv->popup_widget),
|
_gtk_tree_menu_set_model (GTK_TREE_MENU (priv->popup_widget),
|
||||||
priv->model);
|
priv->model);
|
||||||
}
|
|
||||||
|
|
||||||
if (priv->cell_view)
|
if (priv->cell_view)
|
||||||
gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view),
|
gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view),
|
||||||
@ -3448,7 +3112,9 @@ gtk_combo_box_constructed (GObject *object)
|
|||||||
|
|
||||||
gtk_combo_box_create_child (combo_box);
|
gtk_combo_box_create_child (combo_box);
|
||||||
|
|
||||||
gtk_combo_box_check_appearance (combo_box);
|
/* Create the popup menu, if it doesn’t already exist. */
|
||||||
|
if (!priv->popup_widget)
|
||||||
|
gtk_combo_box_menu_setup (combo_box);
|
||||||
|
|
||||||
if (priv->has_entry)
|
if (priv->has_entry)
|
||||||
{
|
{
|
||||||
@ -3467,7 +3133,7 @@ gtk_combo_box_dispose(GObject* object)
|
|||||||
GtkComboBox *combo_box = GTK_COMBO_BOX (object);
|
GtkComboBox *combo_box = GTK_COMBO_BOX (object);
|
||||||
GtkComboBoxPrivate *priv = combo_box->priv;
|
GtkComboBoxPrivate *priv = combo_box->priv;
|
||||||
|
|
||||||
if (GTK_IS_MENU (priv->popup_widget))
|
if (priv->popup_widget)
|
||||||
{
|
{
|
||||||
gtk_combo_box_menu_destroy (combo_box);
|
gtk_combo_box_menu_destroy (combo_box);
|
||||||
gtk_menu_detach (GTK_MENU (priv->popup_widget));
|
gtk_menu_detach (GTK_MENU (priv->popup_widget));
|
||||||
@ -3480,12 +3146,6 @@ gtk_combo_box_dispose(GObject* object)
|
|||||||
priv->area = NULL;
|
priv->area = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priv->popup_window)
|
|
||||||
{
|
|
||||||
gtk_widget_destroy (priv->popup_window);
|
|
||||||
priv->popup_window = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_combo_box_unset_model (combo_box);
|
gtk_combo_box_unset_model (combo_box);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gtk_combo_box_parent_class)->dispose (object);
|
G_OBJECT_CLASS (gtk_combo_box_parent_class)->dispose (object);
|
||||||
@ -3694,7 +3354,7 @@ gtk_combo_box_set_row_separator_func (GtkComboBox *combo_box,
|
|||||||
priv->row_separator_destroy = destroy;
|
priv->row_separator_destroy = destroy;
|
||||||
|
|
||||||
/* Provoke the underlying menu to rebuild themselves with the new separator func */
|
/* Provoke the underlying menu to rebuild themselves with the new separator func */
|
||||||
if (GTK_IS_TREE_MENU (priv->popup_widget))
|
if (priv->popup_widget)
|
||||||
{
|
{
|
||||||
_gtk_tree_menu_set_model (GTK_TREE_MENU (priv->popup_widget), NULL);
|
_gtk_tree_menu_set_model (GTK_TREE_MENU (priv->popup_widget), NULL);
|
||||||
_gtk_tree_menu_set_model (GTK_TREE_MENU (priv->popup_widget), priv->model);
|
_gtk_tree_menu_set_model (GTK_TREE_MENU (priv->popup_widget), priv->model);
|
||||||
@ -4069,8 +3729,5 @@ gtk_combo_box_set_active_id (GtkComboBox *combo_box,
|
|||||||
GtkWidget *
|
GtkWidget *
|
||||||
gtk_combo_box_get_popup (GtkComboBox *combo)
|
gtk_combo_box_get_popup (GtkComboBox *combo)
|
||||||
{
|
{
|
||||||
if (combo->priv->popup_window)
|
|
||||||
return combo->priv->popup_window;
|
|
||||||
else
|
|
||||||
return combo->priv->popup_widget;
|
return combo->priv->popup_widget;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user