mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-26 21:51:08 +00:00
Reimplement GtkPopover
This commit is contained in:
parent
9e6d8becbb
commit
6ab8ab87c8
@ -1332,6 +1332,27 @@ rewrite_event_for_grabs (GdkEvent *event)
|
||||
event_widget = gtk_get_event_widget (event);
|
||||
grab_widget = gtk_native_get_for_surface (grab_surface);
|
||||
|
||||
switch ((guint) event->any.type)
|
||||
{
|
||||
case GDK_BUTTON_PRESS:
|
||||
case GDK_BUTTON_RELEASE:
|
||||
case GDK_KEY_PRESS:
|
||||
case GDK_KEY_RELEASE:
|
||||
case GDK_TOUCH_BEGIN:
|
||||
case GDK_TOUCH_END:
|
||||
case GDK_TOUCH_CANCEL:
|
||||
case GDK_TOUCHPAD_SWIPE:
|
||||
case GDK_TOUCHPAD_PINCH:
|
||||
if (grab_surface != event->any.surface &&
|
||||
GTK_IS_POPOVER (grab_widget))
|
||||
{
|
||||
gtk_widget_hide (grab_widget);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
|
||||
if (grab_widget &&
|
||||
gtk_main_get_window_group (grab_widget) != gtk_main_get_window_group (event_widget))
|
||||
return rewrite_event_for_surface (event, grab_surface);
|
||||
|
2495
gtk/gtkpopover.c
2495
gtk/gtkpopover.c
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,8 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright © 2013 Carlos Garnacho <carlosg@gnome.org>
|
||||
* Copyright (C) 2019 Red Hat, Inc.
|
||||
*
|
||||
* Authors:
|
||||
* - Matthias Clasen <mclasen@redhat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@ -22,23 +25,23 @@
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include <gtk/gtkwindow.h>
|
||||
#include <gtk/gtkbin.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_POPOVER (gtk_popover_get_type ())
|
||||
#define GTK_POPOVER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_POPOVER, GtkPopover))
|
||||
#define GTK_POPOVER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), GTK_TYPE_POPOVER, GtkPopoverClass))
|
||||
#define GTK_IS_POPOVER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_POPOVER))
|
||||
#define GTK_IS_POPOVER_CLASS(o) (G_TYPE_CHECK_CLASS_TYPE ((o), GTK_TYPE_POPOVER))
|
||||
#define GTK_POPOVER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_POPOVER, GtkPopoverClass))
|
||||
#define GTK_TYPE_POPOVER (gtk_popover_get_type ())
|
||||
#define GTK_POPOVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_POPOVER, GtkPopover))
|
||||
#define GTK_POPOVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_POPOVER, GtkPopoverClass))
|
||||
#define GTK_IS_POPOVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_POPOVER))
|
||||
#define GTK_IS_POPOVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_POPOVER))
|
||||
#define GTK_POPOVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_POPOVER, GtkPopoverClass))
|
||||
|
||||
typedef struct _GtkPopover GtkPopover;
|
||||
typedef struct _GtkPopoverClass GtkPopoverClass;
|
||||
typedef struct _GtkPopover GtkPopover;
|
||||
typedef struct _GtkPopoverClass GtkPopoverClass;
|
||||
|
||||
struct _GtkPopover
|
||||
{
|
||||
GtkBin parent_instance;
|
||||
GtkBin parent;
|
||||
};
|
||||
|
||||
struct _GtkPopoverClass
|
||||
@ -53,63 +56,55 @@ struct _GtkPopoverClass
|
||||
};
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GType gtk_popover_get_type (void) G_GNUC_CONST;
|
||||
GType gtk_popover_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkWidget * gtk_popover_new (GtkWidget *relative_to);
|
||||
GtkWidget * gtk_popover_new (GtkWidget *relative_to);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkWidget * gtk_popover_new_from_model (GtkWidget *relative_to,
|
||||
GMenuModel *model);
|
||||
GtkWidget * gtk_popover_new_from_model (GtkWidget *relative_to,
|
||||
GMenuModel *model);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_popover_set_relative_to (GtkPopover *popover,
|
||||
GtkWidget *relative_to);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkWidget * gtk_popover_get_relative_to (GtkPopover *popover);
|
||||
void gtk_popover_bind_model (GtkPopover *popover,
|
||||
GMenuModel *model,
|
||||
const gchar *action_namespace);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_popover_set_pointing_to (GtkPopover *popover,
|
||||
const GdkRectangle *rect);
|
||||
void gtk_popover_set_relative_to (GtkPopover *popover,
|
||||
GtkWidget *relative_to);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_popover_get_pointing_to (GtkPopover *popover,
|
||||
GdkRectangle *rect);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_popover_set_position (GtkPopover *popover,
|
||||
GtkPositionType position);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkPositionType gtk_popover_get_position (GtkPopover *popover);
|
||||
GtkWidget * gtk_popover_get_relative_to (GtkPopover *popover);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_popover_set_modal (GtkPopover *popover,
|
||||
gboolean modal);
|
||||
void gtk_popover_set_pointing_to (GtkPopover *popover,
|
||||
const GdkRectangle *rect);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_popover_get_modal (GtkPopover *popover);
|
||||
gboolean gtk_popover_get_pointing_to (GtkPopover *popover,
|
||||
GdkRectangle *rect);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_popover_set_position (GtkPopover *popover,
|
||||
GtkPositionType position);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkPositionType gtk_popover_get_position (GtkPopover *popover);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_popover_bind_model (GtkPopover *popover,
|
||||
GMenuModel *model,
|
||||
const gchar *action_namespace);
|
||||
void gtk_popover_set_modal (GtkPopover *popover,
|
||||
gboolean modal);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_popover_get_modal (GtkPopover *popover);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_popover_set_default_widget (GtkPopover *popover,
|
||||
GtkWidget *widget);
|
||||
void gtk_popover_popup (GtkPopover *popover);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkWidget * gtk_popover_get_default_widget (GtkPopover *popover);
|
||||
void gtk_popover_popdown (GtkPopover *popover);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_popover_set_constrain_to (GtkPopover *popover,
|
||||
GtkPopoverConstraint constraint);
|
||||
void gtk_popover_set_default_widget (GtkPopover *popover,
|
||||
GtkWidget *widget);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkPopoverConstraint gtk_popover_get_constrain_to (GtkPopover *popover);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_popover_popup (GtkPopover *popover);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_popover_popdown (GtkPopover *popover);
|
||||
|
||||
GListModel * gtk_popover_get_popovers (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -22,8 +22,6 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
void gtk_popover_update_position (GtkPopover *popover);
|
||||
|
||||
GtkWidget *gtk_popover_get_contents_widget (GtkPopover *popover);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -7343,10 +7343,12 @@ gtk_widget_get_scale_factor (GtkWidget *widget)
|
||||
* just returning 1:
|
||||
*/
|
||||
display = _gtk_widget_get_display (widget);
|
||||
monitor = gdk_display_get_monitor (display, 0);
|
||||
|
||||
if (monitor)
|
||||
return gdk_monitor_get_scale_factor (monitor);
|
||||
if (display)
|
||||
{
|
||||
monitor = gdk_display_get_monitor (display, 0);
|
||||
if (monitor)
|
||||
return gdk_monitor_get_scale_factor (monitor);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -5895,8 +5895,10 @@ popover_size_allocate (GtkWindowPopover *popover,
|
||||
if (!gtk_widget_get_mapped (popover->widget))
|
||||
return;
|
||||
|
||||
#if 0
|
||||
if (GTK_IS_POPOVER (popover->widget))
|
||||
gtk_popover_update_position (GTK_POPOVER (popover->widget));
|
||||
#endif
|
||||
|
||||
popover_get_rect (popover, window, &rect);
|
||||
gtk_widget_size_allocate (popover->widget, &rect, -1);
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "gtklabel.h"
|
||||
#include "gtklistbox.h"
|
||||
#include "gtkmenuitem.h"
|
||||
#include "gtkpopover.h"
|
||||
#include "gtksettings.h"
|
||||
#include "gtksizegroup.h"
|
||||
#include "gtktextview.h"
|
||||
@ -1144,6 +1145,7 @@ create_root_model (void)
|
||||
g_object_unref);
|
||||
gtk_filter_list_model_set_model (filter, gtk_window_get_toplevels ());
|
||||
g_list_store_append (list, filter);
|
||||
g_list_store_append (list, gtk_popover_get_popovers ());
|
||||
g_object_unref (filter);
|
||||
|
||||
flatten = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (list));
|
||||
|
@ -114,7 +114,6 @@ gtk_tests = [
|
||||
['testpopover'],
|
||||
['gdkgears', ['gtkgears.c']],
|
||||
['listmodel'],
|
||||
['testpopup'],
|
||||
['testgaction'],
|
||||
['testwidgetfocus'],
|
||||
['testwidgettransforms'],
|
||||
|
@ -1,62 +0,0 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
static void
|
||||
draw_popup (GtkDrawingArea *da,
|
||||
cairo_t *cr,
|
||||
int width,
|
||||
int height,
|
||||
gpointer data)
|
||||
{
|
||||
cairo_set_source_rgb (cr, 1, 0, 0);
|
||||
cairo_paint (cr);
|
||||
}
|
||||
|
||||
static void
|
||||
place_popup (GtkEventControllerMotion *motion,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
GtkWidget *popup)
|
||||
{
|
||||
}
|
||||
|
||||
static gboolean
|
||||
on_map (GtkWidget *parent)
|
||||
{
|
||||
GtkWidget *popup, *da;
|
||||
GtkEventController *motion;
|
||||
|
||||
popup = gtk_window_new (GTK_WINDOW_POPUP);
|
||||
da = gtk_drawing_area_new ();
|
||||
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (da), draw_popup, NULL, NULL);
|
||||
gtk_container_add (GTK_CONTAINER (popup), da);
|
||||
|
||||
gtk_widget_set_size_request (GTK_WIDGET (popup), 20, 20);
|
||||
gtk_window_set_transient_for (GTK_WINDOW (popup), GTK_WINDOW (parent));
|
||||
|
||||
motion = gtk_event_controller_motion_new ();
|
||||
gtk_widget_add_controller (parent, motion);
|
||||
g_signal_connect (motion, "motion", G_CALLBACK (place_popup), popup);
|
||||
|
||||
gtk_widget_show (popup);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
GtkWidget *window;
|
||||
|
||||
gtk_init ();
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
|
||||
g_signal_connect (window, "destroy", gtk_main_quit, NULL);
|
||||
g_signal_connect (window, "map", G_CALLBACK (on_map), NULL);
|
||||
|
||||
gtk_widget_show (window);
|
||||
|
||||
gtk_main ();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user