mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-25 05:01:09 +00:00
Add some more tests for menu placement.
2005-08-15 Matthias Clasen <mclasen@redhat.com> * tests/testtoolbar.c: Add some more tests for menu placement. * gtk/gtkmenutoolbutton.c (menu_position_func): * gtk/gtktoolbar.c (menu_position_func): Improve positioning of toolbutton menus and of the overflow menu. (#312937, #153870, Christian Persch, Paolo Borelli)
This commit is contained in:
parent
c92959a448
commit
24a55633ce
@ -1,3 +1,12 @@
|
|||||||
|
2005-08-15 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* tests/testtoolbar.c: Add some more tests for menu placement.
|
||||||
|
|
||||||
|
* gtk/gtkmenutoolbutton.c (menu_position_func):
|
||||||
|
* gtk/gtktoolbar.c (menu_position_func): Improve positioning
|
||||||
|
of toolbutton menus and of the overflow menu. (#312937,
|
||||||
|
#153870, Christian Persch, Paolo Borelli)
|
||||||
|
|
||||||
2005-08-15 Tor Lillqvist <tml@novell.com>
|
2005-08-15 Tor Lillqvist <tml@novell.com>
|
||||||
|
|
||||||
* gtk/updateiconcache.c: Use g_path_get_dirname() instead of
|
* gtk/updateiconcache.c: Use g_path_get_dirname() instead of
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
2005-08-15 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* tests/testtoolbar.c: Add some more tests for menu placement.
|
||||||
|
|
||||||
|
* gtk/gtkmenutoolbutton.c (menu_position_func):
|
||||||
|
* gtk/gtktoolbar.c (menu_position_func): Improve positioning
|
||||||
|
of toolbutton menus and of the overflow menu. (#312937,
|
||||||
|
#153870, Christian Persch, Paolo Borelli)
|
||||||
|
|
||||||
2005-08-15 Tor Lillqvist <tml@novell.com>
|
2005-08-15 Tor Lillqvist <tml@novell.com>
|
||||||
|
|
||||||
* gtk/updateiconcache.c: Use g_path_get_dirname() instead of
|
* gtk/updateiconcache.c: Use g_path_get_dirname() instead of
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
2005-08-15 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* tests/testtoolbar.c: Add some more tests for menu placement.
|
||||||
|
|
||||||
|
* gtk/gtkmenutoolbutton.c (menu_position_func):
|
||||||
|
* gtk/gtktoolbar.c (menu_position_func): Improve positioning
|
||||||
|
of toolbutton menus and of the overflow menu. (#312937,
|
||||||
|
#153870, Christian Persch, Paolo Borelli)
|
||||||
|
|
||||||
2005-08-15 Tor Lillqvist <tml@novell.com>
|
2005-08-15 Tor Lillqvist <tml@novell.com>
|
||||||
|
|
||||||
* gtk/updateiconcache.c: Use g_path_get_dirname() instead of
|
* gtk/updateiconcache.c: Use g_path_get_dirname() instead of
|
||||||
|
@ -278,36 +278,61 @@ menu_position_func (GtkMenu *menu,
|
|||||||
GtkMenuToolButton *button)
|
GtkMenuToolButton *button)
|
||||||
{
|
{
|
||||||
GtkMenuToolButtonPrivate *priv = button->priv;
|
GtkMenuToolButtonPrivate *priv = button->priv;
|
||||||
|
GtkWidget *widget = GTK_WIDGET (button);
|
||||||
GtkRequisition req;
|
GtkRequisition req;
|
||||||
GtkRequisition menu_req;
|
GtkRequisition menu_req;
|
||||||
GtkOrientation orientation;
|
GtkOrientation orientation;
|
||||||
GtkTextDirection direction;
|
GtkTextDirection direction;
|
||||||
|
GdkRectangle monitor;
|
||||||
|
gint monitor_num;
|
||||||
|
GdkScreen *screen;
|
||||||
|
|
||||||
gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
|
|
||||||
gtk_widget_size_request (priv->arrow_button, &req);
|
|
||||||
gtk_widget_size_request (GTK_WIDGET (priv->menu), &menu_req);
|
gtk_widget_size_request (GTK_WIDGET (priv->menu), &menu_req);
|
||||||
|
|
||||||
orientation = gtk_tool_item_get_orientation (GTK_TOOL_ITEM (button));
|
orientation = gtk_tool_item_get_orientation (GTK_TOOL_ITEM (button));
|
||||||
direction = gtk_widget_get_direction (GTK_WIDGET (priv->arrow_button));
|
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);
|
||||||
|
|
||||||
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
{
|
{
|
||||||
|
gdk_window_get_origin (widget->window, x, y);
|
||||||
|
*x += widget->allocation.x;
|
||||||
|
|
||||||
if (direction == GTK_TEXT_DIR_LTR)
|
if (direction == GTK_TEXT_DIR_LTR)
|
||||||
*x += priv->arrow_button->allocation.width - req.width;
|
*x += MAX (widget->allocation.width - menu_req.width, 0);
|
||||||
|
else if (menu_req.width > widget->allocation.width)
|
||||||
|
*x -= menu_req.width - widget->allocation.width;
|
||||||
|
|
||||||
|
if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
|
||||||
|
*y += priv->arrow_button->allocation.height;
|
||||||
|
else if ((*y - menu_req.height) >= monitor.y)
|
||||||
|
*y -= menu_req.height;
|
||||||
|
else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
|
||||||
|
*y += priv->arrow_button->allocation.height;
|
||||||
else
|
else
|
||||||
*x += req.width - menu_req.width;
|
*y -= menu_req.height;
|
||||||
*y += priv->arrow_button->allocation.height;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
|
||||||
|
gtk_widget_size_request (priv->arrow_button, &req);
|
||||||
|
|
||||||
if (direction == GTK_TEXT_DIR_LTR)
|
if (direction == GTK_TEXT_DIR_LTR)
|
||||||
*x += priv->arrow_button->allocation.width;
|
*x += priv->arrow_button->allocation.width;
|
||||||
else
|
else
|
||||||
*x -= menu_req.width;
|
*x -= menu_req.width;
|
||||||
*y += priv->arrow_button->allocation.height - req.height;
|
|
||||||
|
if (*y + menu_req.height > monitor.y + monitor.height &&
|
||||||
|
*y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
|
||||||
|
*y += priv->arrow_button->allocation.height - menu_req.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
*push_in = TRUE;
|
*push_in = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -2538,18 +2538,35 @@ menu_position_func (GtkMenu *menu,
|
|||||||
GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
|
GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
|
||||||
GtkRequisition req;
|
GtkRequisition req;
|
||||||
GtkRequisition menu_req;
|
GtkRequisition menu_req;
|
||||||
|
GdkRectangle monitor;
|
||||||
|
gint monitor_num;
|
||||||
|
GdkScreen *screen;
|
||||||
|
|
||||||
gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
|
|
||||||
gtk_widget_size_request (priv->arrow_button, &req);
|
gtk_widget_size_request (priv->arrow_button, &req);
|
||||||
gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
|
gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
|
||||||
|
|
||||||
|
screen = gtk_widget_get_screen (GTK_WIDGET (menu));
|
||||||
|
monitor_num = gdk_screen_get_monitor_at_window (screen, priv->arrow_button->window);
|
||||||
|
if (monitor_num < 0)
|
||||||
|
monitor_num = 0;
|
||||||
|
gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
|
||||||
|
|
||||||
|
gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
|
||||||
if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
|
if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
{
|
{
|
||||||
*y += priv->arrow_button->allocation.height;
|
|
||||||
if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
|
if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
|
||||||
*x += priv->arrow_button->allocation.width - req.width;
|
*x += priv->arrow_button->allocation.width - req.width;
|
||||||
else
|
else
|
||||||
*x += req.width - menu_req.width;
|
*x += req.width - menu_req.width;
|
||||||
|
|
||||||
|
if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
|
||||||
|
*y += priv->arrow_button->allocation.height;
|
||||||
|
else if ((*y - menu_req.height) >= monitor.y)
|
||||||
|
*y -= menu_req.height;
|
||||||
|
else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
|
||||||
|
*y += priv->arrow_button->allocation.height;
|
||||||
|
else
|
||||||
|
*y -= menu_req.height;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2557,10 +2574,13 @@ menu_position_func (GtkMenu *menu,
|
|||||||
*x += priv->arrow_button->allocation.width;
|
*x += priv->arrow_button->allocation.width;
|
||||||
else
|
else
|
||||||
*x -= menu_req.width;
|
*x -= menu_req.width;
|
||||||
*y += priv->arrow_button->allocation.height - req.height;
|
|
||||||
|
if (*y + menu_req.height > monitor.y + monitor.height &&
|
||||||
|
*y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
|
||||||
|
*y += priv->arrow_button->allocation.height - menu_req.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
*push_in = TRUE;
|
*push_in = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -488,6 +488,15 @@ timeout_cb (GtkWidget *widget)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
timeout_cb1 (GtkWidget *widget)
|
||||||
|
{
|
||||||
|
static gboolean sensitive = TRUE;
|
||||||
|
sensitive = !sensitive;
|
||||||
|
gtk_widget_set_sensitive (widget, sensitive);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
gint
|
gint
|
||||||
main (gint argc, gchar **argv)
|
main (gint argc, gchar **argv)
|
||||||
{
|
{
|
||||||
@ -603,17 +612,37 @@ main (gint argc, gchar **argv)
|
|||||||
gtk_tool_item_set_expand (item, TRUE);
|
gtk_tool_item_set_expand (item, TRUE);
|
||||||
|
|
||||||
menu = gtk_menu_new ();
|
menu = gtk_menu_new ();
|
||||||
menuitem = gtk_menu_item_new_with_label ("foo.txt");
|
for (i = 0; i < 20; i++)
|
||||||
gtk_widget_show (menuitem);
|
{
|
||||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
char *text;
|
||||||
menuitem = gtk_menu_item_new_with_label ("bar.txt");
|
text = g_strdup_printf ("Menuitem %d", i);
|
||||||
gtk_widget_show (menuitem);
|
menuitem = gtk_menu_item_new_with_label (text);
|
||||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
g_free (text);
|
||||||
|
gtk_widget_show (menuitem);
|
||||||
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
||||||
|
}
|
||||||
|
|
||||||
item = gtk_menu_tool_button_new_from_stock (GTK_STOCK_OPEN);
|
item = gtk_menu_tool_button_new_from_stock (GTK_STOCK_OPEN);
|
||||||
gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (item), menu);
|
gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (item), menu);
|
||||||
add_item_to_list (store, item, "Open");
|
add_item_to_list (store, item, "Open");
|
||||||
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
|
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
|
||||||
|
g_timeout_add (3000, (GSourceFunc) timeout_cb1, item);
|
||||||
|
|
||||||
|
menu = gtk_menu_new ();
|
||||||
|
for (i = 0; i < 20; i++)
|
||||||
|
{
|
||||||
|
char *text;
|
||||||
|
text = g_strdup_printf ("A%d", i);
|
||||||
|
menuitem = gtk_menu_item_new_with_label (text);
|
||||||
|
g_free (text);
|
||||||
|
gtk_widget_show (menuitem);
|
||||||
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
||||||
|
}
|
||||||
|
|
||||||
|
item = gtk_menu_tool_button_new_from_stock (GTK_STOCK_GO_BACK);
|
||||||
|
gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (item), menu);
|
||||||
|
add_item_to_list (store, item, "BackWithHistory");
|
||||||
|
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
|
||||||
|
|
||||||
item = gtk_separator_tool_item_new ();
|
item = gtk_separator_tool_item_new ();
|
||||||
add_item_to_list (store, item, "-----");
|
add_item_to_list (store, item, "-----");
|
||||||
|
Loading…
Reference in New Issue
Block a user