2013-01-11 16:32:08 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright © 2013 Carlos Garnacho <carlosg@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-11-13 14:11:21 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtkpopover
|
|
|
|
* @Short_description: Context dependent bubbles
|
|
|
|
* @Title: GtkPopover
|
2013-01-11 16:32:08 +00:00
|
|
|
*
|
2013-11-13 14:11:21 +00:00
|
|
|
* GtkPopover is a bubble-like context window, primarily meant to
|
|
|
|
* provide context-dependent information or options. Popovers are
|
|
|
|
* attached to a widget, passed at construction time on gtk_popover_new(),
|
|
|
|
* or updated afterwards through gtk_popover_set_relative_to(), by
|
|
|
|
* default they will point to the whole widget area, although this
|
|
|
|
* behavior can be changed through gtk_popover_set_pointing_to().
|
2013-01-11 16:32:08 +00:00
|
|
|
*
|
2013-11-13 14:11:21 +00:00
|
|
|
* The position of a popover relative to the widget it is attached to
|
|
|
|
* can also be changed through gtk_popover_set_position().
|
|
|
|
*
|
2014-01-22 15:26:13 +00:00
|
|
|
* By default, #GtkPopover performs a GTK+ grab, in order to ensure
|
|
|
|
* input events get redirected to it while it is shown, and also so
|
2014-01-23 22:41:37 +00:00
|
|
|
* the popover is dismissed in the expected situations (clicks outside
|
2014-01-22 15:26:13 +00:00
|
|
|
* the popover, or the Esc key being pressed). If no such modal behavior
|
|
|
|
* is desired on a popover, gtk_popover_set_modal() may be called on it
|
|
|
|
* to tweak its behavior.
|
|
|
|
*
|
2014-04-26 18:38:07 +00:00
|
|
|
* ## GtkPopover as menu replacement
|
|
|
|
*
|
|
|
|
* GtkPopover is often used to replace menus. To facilitate this, it
|
|
|
|
* supports being populated from a #GMenuModel, using
|
|
|
|
* gtk_popover_new_from_model(). In addition to all the regular menu
|
|
|
|
* model features, this function supports rendering sections in the
|
|
|
|
* model in a more compact form, as a row of icon buttons instead of
|
|
|
|
* menu items.
|
|
|
|
*
|
|
|
|
* To use this rendering, set the ”display-hint” attribute of the
|
|
|
|
* section to ”horizontal-buttons” and set the icons of your items
|
|
|
|
* with the ”verb-icon” attribute.
|
|
|
|
*
|
|
|
|
* |[
|
|
|
|
* <section>
|
|
|
|
* <attribute name="display-hint">horizontal-buttons</attribute>
|
|
|
|
* <item>
|
|
|
|
* <attribute name="label">Cut</attribute>
|
|
|
|
* <attribute name="action">app.cut</attribute>
|
|
|
|
* <attribute name="verb-icon">edit-cut-symbolic</attribute>
|
|
|
|
* </item>
|
|
|
|
* <item>
|
|
|
|
* <attribute name="label">Copy</attribute>
|
|
|
|
* <attribute name="action">app.copy</attribute>
|
|
|
|
* <attribute name="verb-icon">edit-copy-symbolic</attribute>
|
|
|
|
* </item>
|
|
|
|
* <item>
|
|
|
|
* <attribute name="label">Paste</attribute>
|
|
|
|
* <attribute name="action">app.paste</attribute>
|
|
|
|
* <attribute name="verb-icon">edit-paste-symbolic</attribute>
|
|
|
|
* </item>
|
|
|
|
* </section>
|
|
|
|
* ]|
|
|
|
|
*
|
2015-11-02 17:53:57 +00:00
|
|
|
* # CSS nodes
|
|
|
|
*
|
2017-07-08 10:04:44 +00:00
|
|
|
* |[<!-- language="plain" -->
|
|
|
|
* popover
|
|
|
|
* ├── arrow
|
|
|
|
* ╰── contents.background[.menu]
|
|
|
|
* ╰── <child>
|
|
|
|
* ]|
|
|
|
|
*
|
|
|
|
* The contents child node always gets the .background style class and it
|
|
|
|
* gets the .menu style class if the popover is menu-like (e.g. #GtkPopoverMenu
|
|
|
|
* or created using gtk_popover_new_from_model().
|
2015-11-02 17:53:57 +00:00
|
|
|
*
|
|
|
|
* Particular uses of GtkPopover, such as touch selection popups
|
|
|
|
* or magnifiers in #GtkEntry or #GtkTextView get style classes
|
|
|
|
* like .touch-selection or .magnifier to differentiate from
|
|
|
|
* plain popovers.
|
2015-10-30 14:08:18 +00:00
|
|
|
*
|
2017-07-08 10:04:44 +00:00
|
|
|
* When styling a popover directly, the popover node should usually not have any
|
|
|
|
* background.
|
|
|
|
*
|
|
|
|
* Note that, in order to accomplish appropriate arrow visuals, #GtkPopover uses
|
|
|
|
* custom drawing for the arrow node. This makes it possible for the arrow to change
|
|
|
|
* its shape dynamically, but it also limits the possibilities of styling it using CSS.
|
|
|
|
* In particular, the arrow gets drawn over the content node's border so they look
|
|
|
|
* like one shape, which means that the border-width of the content node and the arrow
|
|
|
|
* node should be the same. The arrow also does not support any border shape other than
|
|
|
|
* solid, no border-radius, only one border width (border-bottom-width is used) and no box-shadow.
|
2013-01-11 16:32:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <gdk/gdk.h>
|
2013-11-12 15:55:23 +00:00
|
|
|
#include "gtkpopover.h"
|
2014-08-01 15:38:42 +00:00
|
|
|
#include "gtkpopoverprivate.h"
|
2013-01-18 02:49:24 +00:00
|
|
|
#include "gtktypebuiltins.h"
|
|
|
|
#include "gtkmain.h"
|
2014-01-17 17:12:31 +00:00
|
|
|
#include "gtkwindowprivate.h"
|
2014-01-22 15:43:37 +00:00
|
|
|
#include "gtkscrollable.h"
|
|
|
|
#include "gtkadjustment.h"
|
2013-01-11 16:32:08 +00:00
|
|
|
#include "gtkprivate.h"
|
|
|
|
#include "gtkintl.h"
|
2014-02-07 19:51:49 +00:00
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkbox.h"
|
|
|
|
#include "gtkbutton.h"
|
2016-11-15 16:28:34 +00:00
|
|
|
#include "gtkcontainerprivate.h"
|
2014-02-07 19:51:49 +00:00
|
|
|
#include "gtkseparator.h"
|
|
|
|
#include "gtkmodelbutton.h"
|
|
|
|
#include "gtkwidgetprivate.h"
|
2018-02-02 09:13:10 +00:00
|
|
|
#include "gtkactionmuxerprivate.h"
|
2014-02-07 19:51:49 +00:00
|
|
|
#include "gtkmenutracker.h"
|
|
|
|
#include "gtkstack.h"
|
|
|
|
#include "gtksizegroup.h"
|
2014-03-06 23:07:54 +00:00
|
|
|
#include "a11y/gtkpopoveraccessible.h"
|
2014-04-28 15:55:52 +00:00
|
|
|
#include "gtkmenusectionbox.h"
|
2016-01-05 18:05:43 +00:00
|
|
|
#include "gtkroundedboxprivate.h"
|
|
|
|
#include "gtkstylecontextprivate.h"
|
2016-03-28 21:45:21 +00:00
|
|
|
#include "gtkprogresstrackerprivate.h"
|
2016-05-01 04:39:03 +00:00
|
|
|
#include "gtksettingsprivate.h"
|
2017-07-08 10:04:44 +00:00
|
|
|
#include "gtkgizmoprivate.h"
|
|
|
|
#include "gtkcssnodeprivate.h"
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2016-12-13 20:00:28 +00:00
|
|
|
#include "gsk/gskroundedrectprivate.h"
|
|
|
|
|
2014-10-20 17:10:52 +00:00
|
|
|
#ifdef GDK_WINDOWING_WAYLAND
|
|
|
|
#include "wayland/gdkwayland.h"
|
|
|
|
#endif
|
|
|
|
|
2015-01-09 15:10:29 +00:00
|
|
|
#define TAIL_GAP_WIDTH 24
|
|
|
|
#define TAIL_HEIGHT 12
|
|
|
|
#define TRANSITION_DIFF 20
|
2015-09-23 15:36:39 +00:00
|
|
|
#define TRANSITION_DURATION 150 * 1000
|
2013-01-11 16:32:08 +00:00
|
|
|
|
|
|
|
#define POS_IS_VERTICAL(p) ((p) == GTK_POS_TOP || (p) == GTK_POS_BOTTOM)
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_RELATIVE_TO = 1,
|
|
|
|
PROP_POINTING_TO,
|
2014-01-10 11:04:17 +00:00
|
|
|
PROP_POSITION,
|
2015-01-09 15:10:29 +00:00
|
|
|
PROP_MODAL,
|
2015-12-02 06:03:35 +00:00
|
|
|
PROP_CONSTRAIN_TO,
|
|
|
|
NUM_PROPERTIES
|
2013-01-11 16:32:08 +00:00
|
|
|
};
|
|
|
|
|
2014-02-06 14:30:55 +00:00
|
|
|
enum {
|
|
|
|
CLOSED,
|
|
|
|
N_SIGNALS
|
|
|
|
};
|
|
|
|
|
2015-01-09 15:10:29 +00:00
|
|
|
enum {
|
|
|
|
STATE_SHOWING,
|
|
|
|
STATE_SHOWN,
|
|
|
|
STATE_HIDING,
|
|
|
|
STATE_HIDDEN
|
|
|
|
};
|
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
struct _GtkPopoverPrivate
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2013-11-11 09:36:51 +00:00
|
|
|
GtkWidget *widget;
|
2017-07-08 10:04:44 +00:00
|
|
|
GtkWidget *contents_widget;
|
|
|
|
GtkCssNode *arrow_node;
|
2013-11-11 09:36:51 +00:00
|
|
|
GtkWindow *window;
|
2014-01-10 14:23:12 +00:00
|
|
|
GtkWidget *prev_focus_widget;
|
2015-04-17 04:10:06 +00:00
|
|
|
GtkWidget *default_widget;
|
|
|
|
GtkWidget *prev_default;
|
2014-01-22 15:43:37 +00:00
|
|
|
GtkScrollable *parent_scrollable;
|
|
|
|
GtkAdjustment *vadj;
|
|
|
|
GtkAdjustment *hadj;
|
2014-02-04 21:33:25 +00:00
|
|
|
GdkRectangle pointing_to;
|
2015-12-01 19:56:56 +00:00
|
|
|
GtkPopoverConstraint constraint;
|
2016-03-28 21:45:21 +00:00
|
|
|
GtkProgressTracker tracker;
|
2014-12-02 14:44:04 +00:00
|
|
|
guint prev_focus_unmap_id;
|
2013-11-13 09:47:13 +00:00
|
|
|
guint hierarchy_changed_id;
|
|
|
|
guint size_allocate_id;
|
|
|
|
guint unmap_id;
|
2014-01-22 15:43:37 +00:00
|
|
|
guint scrollable_notify_id;
|
2014-02-07 15:14:23 +00:00
|
|
|
guint grab_notify_id;
|
2014-02-07 15:18:48 +00:00
|
|
|
guint state_changed_id;
|
2013-01-11 16:32:08 +00:00
|
|
|
guint has_pointing_to : 1;
|
|
|
|
guint preferred_position : 2;
|
|
|
|
guint final_position : 2;
|
2013-11-12 15:55:23 +00:00
|
|
|
guint current_position : 2;
|
2014-01-10 11:04:17 +00:00
|
|
|
guint modal : 1;
|
2014-01-28 13:05:08 +00:00
|
|
|
guint button_pressed : 1;
|
2014-03-06 13:50:35 +00:00
|
|
|
guint grab_notify_blocked : 1;
|
2015-01-09 15:10:29 +00:00
|
|
|
guint state : 2;
|
|
|
|
guint visible : 1;
|
2016-09-03 07:58:27 +00:00
|
|
|
guint first_frame_skipped : 1;
|
2015-01-09 15:10:29 +00:00
|
|
|
gint transition_diff;
|
|
|
|
guint tick_id;
|
2015-10-12 22:21:43 +00:00
|
|
|
|
|
|
|
gint tip_x;
|
|
|
|
gint tip_y;
|
2013-01-11 16:32:08 +00:00
|
|
|
};
|
|
|
|
|
2015-12-02 06:03:35 +00:00
|
|
|
static GParamSpec *properties[NUM_PROPERTIES];
|
popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.
The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.
This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
2014-01-09 16:21:43 +00:00
|
|
|
static GQuark quark_widget_popovers = 0;
|
2014-02-06 14:30:55 +00:00
|
|
|
static guint signals[N_SIGNALS] = { 0 };
|
popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.
The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.
This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
2014-01-09 16:21:43 +00:00
|
|
|
|
2013-11-13 09:47:13 +00:00
|
|
|
static void gtk_popover_update_relative_to (GtkPopover *popover,
|
|
|
|
GtkWidget *relative_to);
|
2015-01-09 15:10:29 +00:00
|
|
|
static void gtk_popover_set_state (GtkPopover *popover,
|
|
|
|
guint state);
|
2015-12-16 19:25:54 +00:00
|
|
|
static void gtk_popover_apply_modality (GtkPopover *popover,
|
|
|
|
gboolean modal);
|
2013-11-12 15:55:23 +00:00
|
|
|
|
2016-09-28 17:53:10 +00:00
|
|
|
static void gtk_popover_set_scrollable_full (GtkPopover *popover,
|
|
|
|
GtkScrollable *scrollable);
|
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkPopover, gtk_popover, GTK_TYPE_BIN)
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2017-07-08 10:04:44 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
measure_contents (GtkGizmo *gizmo,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
int for_size,
|
|
|
|
int *minimum,
|
|
|
|
int *natural,
|
|
|
|
int *minimum_baseline,
|
|
|
|
int *natural_baseline)
|
|
|
|
{
|
|
|
|
GtkPopover *popover = GTK_POPOVER (gtk_widget_get_parent (GTK_WIDGET (gizmo)));
|
|
|
|
GtkWidget *child = gtk_bin_get_child (GTK_BIN (popover));
|
|
|
|
|
|
|
|
if (child)
|
|
|
|
gtk_widget_measure (child, orientation, for_size,
|
|
|
|
minimum, natural,
|
|
|
|
minimum_baseline, natural_baseline);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
allocate_contents (GtkGizmo *gizmo,
|
|
|
|
const GtkAllocation *allocation,
|
|
|
|
int baseline,
|
|
|
|
GtkAllocation *out_clip)
|
|
|
|
{
|
|
|
|
GtkPopover *popover = GTK_POPOVER (gtk_widget_get_parent (GTK_WIDGET (gizmo)));
|
|
|
|
GtkWidget *child = gtk_bin_get_child (GTK_BIN (popover));
|
|
|
|
|
|
|
|
if (child)
|
2017-07-11 07:58:21 +00:00
|
|
|
gtk_widget_size_allocate (child, allocation, -1, out_clip);
|
2017-07-08 10:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
node_style_changed_cb (GtkCssNode *node,
|
|
|
|
GtkCssStyleChange *change,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
if (gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_SIZE | GTK_CSS_AFFECTS_CLIP))
|
|
|
|
gtk_widget_queue_resize (widget);
|
|
|
|
else
|
|
|
|
gtk_widget_queue_draw (widget);
|
|
|
|
}
|
|
|
|
|
2013-01-11 16:32:08 +00:00
|
|
|
static void
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_init (GtkPopover *popover)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2015-11-04 17:01:26 +00:00
|
|
|
GtkStyleContext *context;
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
widget = GTK_WIDGET (popover);
|
2013-11-11 09:36:51 +00:00
|
|
|
gtk_widget_set_has_window (widget, TRUE);
|
2014-02-09 06:22:07 +00:00
|
|
|
popover->priv = gtk_popover_get_instance_private (popover);
|
|
|
|
popover->priv->modal = TRUE;
|
2015-01-09 15:10:29 +00:00
|
|
|
popover->priv->tick_id = 0;
|
2016-08-10 16:28:14 +00:00
|
|
|
popover->priv->state = STATE_HIDDEN;
|
|
|
|
popover->priv->visible = FALSE;
|
2015-12-02 06:07:02 +00:00
|
|
|
popover->priv->preferred_position = GTK_POS_TOP;
|
2015-12-01 19:56:56 +00:00
|
|
|
popover->priv->constraint = GTK_POPOVER_CONSTRAINT_WINDOW;
|
2015-11-04 17:01:26 +00:00
|
|
|
|
2017-07-08 10:04:44 +00:00
|
|
|
popover->priv->arrow_node = gtk_css_node_new ();
|
|
|
|
gtk_css_node_set_name (popover->priv->arrow_node, I_("arrow"));
|
|
|
|
gtk_css_node_set_parent (popover->priv->arrow_node, gtk_widget_get_css_node (widget));
|
|
|
|
gtk_css_node_set_state (popover->priv->arrow_node,
|
|
|
|
gtk_css_node_get_state (gtk_widget_get_css_node (widget)));
|
|
|
|
g_signal_connect_object (popover->priv->arrow_node, "style-changed",
|
|
|
|
G_CALLBACK (node_style_changed_cb), popover, 0);
|
|
|
|
g_object_unref (popover->priv->arrow_node);
|
|
|
|
|
|
|
|
popover->priv->contents_widget = gtk_gizmo_new ("contents",
|
|
|
|
measure_contents,
|
|
|
|
allocate_contents,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_widget_set_parent (popover->priv->contents_widget, widget);
|
|
|
|
|
|
|
|
context = gtk_widget_get_style_context (popover->priv->contents_widget);
|
2015-11-04 17:01:26 +00:00
|
|
|
gtk_style_context_add_class (context, GTK_STYLE_CLASS_BACKGROUND);
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_RELATIVE_TO:
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_set_relative_to (GTK_POPOVER (object),
|
|
|
|
g_value_get_object (value));
|
2013-01-11 16:32:08 +00:00
|
|
|
break;
|
|
|
|
case PROP_POINTING_TO:
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_set_pointing_to (GTK_POPOVER (object),
|
|
|
|
g_value_get_boxed (value));
|
2013-01-11 16:32:08 +00:00
|
|
|
break;
|
|
|
|
case PROP_POSITION:
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_set_position (GTK_POPOVER (object),
|
|
|
|
g_value_get_enum (value));
|
2013-01-11 16:32:08 +00:00
|
|
|
break;
|
2014-01-10 11:04:17 +00:00
|
|
|
case PROP_MODAL:
|
|
|
|
gtk_popover_set_modal (GTK_POPOVER (object),
|
|
|
|
g_value_get_boolean (value));
|
|
|
|
break;
|
2015-12-01 19:56:56 +00:00
|
|
|
case PROP_CONSTRAIN_TO:
|
|
|
|
gtk_popover_set_constrain_to (GTK_POPOVER (object),
|
|
|
|
g_value_get_enum (value));
|
|
|
|
break;
|
2013-01-11 16:32:08 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2013-11-12 15:55:23 +00:00
|
|
|
GtkPopoverPrivate *priv = GTK_POPOVER (object)->priv;
|
2013-01-11 16:32:08 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_RELATIVE_TO:
|
2013-11-11 13:27:19 +00:00
|
|
|
g_value_set_object (value, priv->widget);
|
2013-01-11 16:32:08 +00:00
|
|
|
break;
|
|
|
|
case PROP_POINTING_TO:
|
|
|
|
g_value_set_boxed (value, &priv->pointing_to);
|
|
|
|
break;
|
|
|
|
case PROP_POSITION:
|
|
|
|
g_value_set_enum (value, priv->preferred_position);
|
|
|
|
break;
|
2014-01-10 11:04:17 +00:00
|
|
|
case PROP_MODAL:
|
|
|
|
g_value_set_boolean (value, priv->modal);
|
|
|
|
break;
|
2015-12-01 19:56:56 +00:00
|
|
|
case PROP_CONSTRAIN_TO:
|
|
|
|
g_value_set_enum (value, priv->constraint);
|
|
|
|
break;
|
2013-01-11 16:32:08 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-09 15:10:29 +00:00
|
|
|
static gboolean
|
|
|
|
transitions_enabled (GtkPopover *popover)
|
|
|
|
{
|
2016-10-14 19:35:35 +00:00
|
|
|
return gtk_settings_get_enable_animations (gtk_widget_get_settings (GTK_WIDGET (popover)));
|
2015-01-09 15:10:29 +00:00
|
|
|
}
|
|
|
|
|
2016-08-10 16:28:14 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_hide_internal (GtkPopover *popover)
|
|
|
|
{
|
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
|
|
|
GtkWidget *widget = GTK_WIDGET (popover);
|
|
|
|
|
|
|
|
if (!priv->visible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->visible = FALSE;
|
|
|
|
g_signal_emit (widget, signals[CLOSED], 0);
|
|
|
|
|
|
|
|
if (priv->modal)
|
|
|
|
gtk_popover_apply_modality (popover, FALSE);
|
|
|
|
|
|
|
|
if (gtk_widget_get_realized (widget))
|
|
|
|
{
|
|
|
|
cairo_region_t *region = cairo_region_create ();
|
2017-07-08 10:04:44 +00:00
|
|
|
gdk_window_input_shape_combine_region (gtk_widget_get_window (widget),
|
2016-08-10 16:28:14 +00:00
|
|
|
region, 0, 0);
|
|
|
|
cairo_region_destroy (region);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-11 16:32:08 +00:00
|
|
|
static void
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_finalize (GObject *object)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2013-11-12 15:55:23 +00:00
|
|
|
GtkPopover *popover = GTK_POPOVER (object);
|
2013-11-13 09:47:13 +00:00
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
|
|
|
|
|
|
|
if (priv->widget)
|
|
|
|
gtk_popover_update_relative_to (popover, NULL);
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
G_OBJECT_CLASS (gtk_popover_parent_class)->finalize (object);
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 14:44:04 +00:00
|
|
|
static void
|
|
|
|
popover_unset_prev_focus (GtkPopover *popover)
|
|
|
|
{
|
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
|
|
|
|
|
|
|
if (!priv->prev_focus_widget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (priv->prev_focus_unmap_id)
|
|
|
|
{
|
|
|
|
g_signal_handler_disconnect (priv->prev_focus_widget,
|
|
|
|
priv->prev_focus_unmap_id);
|
|
|
|
priv->prev_focus_unmap_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_clear_object (&priv->prev_focus_widget);
|
|
|
|
}
|
|
|
|
|
2013-11-11 09:36:51 +00:00
|
|
|
static void
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_dispose (GObject *object)
|
2013-11-11 09:36:51 +00:00
|
|
|
{
|
2013-11-12 15:55:23 +00:00
|
|
|
GtkPopover *popover = GTK_POPOVER (object);
|
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
2013-11-11 09:36:51 +00:00
|
|
|
|
2015-12-16 19:25:54 +00:00
|
|
|
if (priv->modal)
|
|
|
|
gtk_popover_apply_modality (popover, FALSE);
|
|
|
|
|
2013-11-11 09:36:51 +00:00
|
|
|
if (priv->window)
|
2015-04-09 00:20:38 +00:00
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_data (priv->window, popover);
|
|
|
|
_gtk_window_remove_popover (priv->window, GTK_WIDGET (object));
|
|
|
|
}
|
2013-11-11 09:36:51 +00:00
|
|
|
|
|
|
|
priv->window = NULL;
|
2013-11-13 09:47:13 +00:00
|
|
|
|
|
|
|
if (priv->widget)
|
|
|
|
gtk_popover_update_relative_to (popover, NULL);
|
2013-11-11 09:36:51 +00:00
|
|
|
|
2014-12-02 14:44:04 +00:00
|
|
|
popover_unset_prev_focus (popover);
|
2014-01-10 14:23:12 +00:00
|
|
|
|
2015-05-12 11:57:04 +00:00
|
|
|
g_clear_object (&priv->default_widget);
|
|
|
|
|
2017-07-08 10:04:44 +00:00
|
|
|
if (priv->contents_widget)
|
|
|
|
{
|
|
|
|
GtkWidget *child = gtk_bin_get_child (GTK_BIN (popover));
|
|
|
|
|
|
|
|
if (child)
|
|
|
|
{
|
|
|
|
/* Parent is content_widget! */
|
|
|
|
gtk_widget_unparent (child);
|
|
|
|
_gtk_bin_set_child (GTK_BIN (popover), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_unparent (priv->contents_widget);
|
|
|
|
priv->contents_widget = NULL;
|
|
|
|
}
|
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
G_OBJECT_CLASS (gtk_popover_parent_class)->dispose (object);
|
2013-11-11 09:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_realize (GtkWidget *widget)
|
2013-11-11 09:36:51 +00:00
|
|
|
{
|
|
|
|
GtkAllocation allocation;
|
|
|
|
GdkWindow *window;
|
|
|
|
|
2017-06-21 11:25:41 +00:00
|
|
|
gtk_widget_get_window_allocation (widget, &allocation);
|
|
|
|
|
2017-08-26 19:34:46 +00:00
|
|
|
/* We want to use subsurfaces for popovers, so they can extend outside
|
|
|
|
* the main window, but for that, we first need to have clean subsurface
|
|
|
|
* support that works with GSK.
|
|
|
|
*/
|
|
|
|
#if 0
|
2017-06-21 11:25:41 +00:00
|
|
|
if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (widget)))
|
|
|
|
{
|
|
|
|
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
|
|
|
|
|
|
|
|
g_assert (GTK_IS_WINDOW (toplevel));
|
|
|
|
|
|
|
|
window = gdk_wayland_window_new_subsurface (gtk_widget_get_display (toplevel),
|
|
|
|
&allocation);
|
|
|
|
|
|
|
|
gdk_window_set_transient_for (window,
|
|
|
|
gtk_widget_get_window (toplevel));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
window = gdk_window_new_child (gtk_widget_get_parent_window (widget),
|
|
|
|
&allocation);
|
|
|
|
}
|
2013-11-11 09:36:51 +00:00
|
|
|
|
|
|
|
gtk_widget_set_window (widget, window);
|
|
|
|
gtk_widget_register_window (widget, window);
|
|
|
|
gtk_widget_set_realized (widget, TRUE);
|
|
|
|
}
|
|
|
|
|
2018-01-06 17:21:31 +00:00
|
|
|
static void
|
|
|
|
window_active_changed (GtkWindow *window,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkPopover *popover)
|
2014-03-06 13:50:35 +00:00
|
|
|
{
|
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
|
|
|
|
2018-01-06 17:21:31 +00:00
|
|
|
if (!priv->modal ||
|
|
|
|
!gtk_widget_is_drawable (GTK_WIDGET (popover)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (gtk_window_is_active (window))
|
2014-03-06 13:50:35 +00:00
|
|
|
{
|
2018-01-06 17:21:31 +00:00
|
|
|
/* Regain the grab when the window is focused */
|
2014-03-06 13:50:35 +00:00
|
|
|
GtkWidget *focus;
|
|
|
|
|
|
|
|
gtk_grab_add (GTK_WIDGET (popover));
|
|
|
|
|
2018-01-06 17:21:31 +00:00
|
|
|
focus = gtk_window_get_focus (window);
|
2014-03-06 13:50:35 +00:00
|
|
|
|
2014-11-27 23:22:52 +00:00
|
|
|
if (focus == NULL || !gtk_widget_is_ancestor (focus, GTK_WIDGET (popover)))
|
2014-03-06 13:50:35 +00:00
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (popover));
|
|
|
|
|
|
|
|
if (priv->grab_notify_blocked)
|
|
|
|
g_signal_handler_unblock (priv->widget, priv->grab_notify_id);
|
|
|
|
|
|
|
|
priv->grab_notify_blocked = FALSE;
|
|
|
|
}
|
2018-01-06 17:21:31 +00:00
|
|
|
else
|
2014-03-06 13:50:35 +00:00
|
|
|
{
|
2018-01-06 17:21:31 +00:00
|
|
|
/* Temporarily remove the grab when unfocused */
|
2014-03-06 13:50:35 +00:00
|
|
|
g_signal_handler_block (priv->widget, priv->grab_notify_id);
|
|
|
|
gtk_grab_remove (GTK_WIDGET (popover));
|
2018-01-06 17:21:31 +00:00
|
|
|
|
2014-03-06 13:50:35 +00:00
|
|
|
priv->grab_notify_blocked = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-06 15:58:06 +00:00
|
|
|
static void
|
|
|
|
window_set_focus (GtkWindow *window,
|
|
|
|
GtkWidget *widget,
|
|
|
|
GtkPopover *popover)
|
|
|
|
{
|
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
|
|
|
|
2016-04-25 12:16:21 +00:00
|
|
|
if (!priv->modal || !widget || !gtk_widget_is_drawable (GTK_WIDGET (popover)))
|
|
|
|
return;
|
2015-06-12 13:05:33 +00:00
|
|
|
|
2016-04-25 12:16:21 +00:00
|
|
|
widget = gtk_widget_get_ancestor (widget, GTK_TYPE_POPOVER);
|
|
|
|
while (widget != NULL)
|
|
|
|
{
|
|
|
|
if (widget == GTK_WIDGET (popover))
|
|
|
|
return;
|
2015-06-12 13:05:33 +00:00
|
|
|
|
2016-04-25 12:16:21 +00:00
|
|
|
widget = gtk_popover_get_relative_to (GTK_POPOVER (widget));
|
|
|
|
if (widget == NULL)
|
|
|
|
break;
|
|
|
|
widget = gtk_widget_get_ancestor (widget, GTK_TYPE_POPOVER);
|
2015-06-12 13:05:33 +00:00
|
|
|
}
|
2016-04-25 12:16:21 +00:00
|
|
|
|
|
|
|
popover_unset_prev_focus (popover);
|
|
|
|
gtk_widget_hide (GTK_WIDGET (popover));
|
2014-03-06 15:58:06 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 14:44:04 +00:00
|
|
|
static void
|
|
|
|
prev_focus_unmap_cb (GtkWidget *widget,
|
|
|
|
GtkPopover *popover)
|
|
|
|
{
|
|
|
|
popover_unset_prev_focus (popover);
|
|
|
|
}
|
|
|
|
|
2014-01-10 14:23:12 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_apply_modality (GtkPopover *popover,
|
|
|
|
gboolean modal)
|
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
2014-01-10 14:23:12 +00:00
|
|
|
|
2014-06-09 13:17:43 +00:00
|
|
|
if (!priv->window)
|
|
|
|
return;
|
|
|
|
|
2014-01-10 14:23:12 +00:00
|
|
|
if (modal)
|
|
|
|
{
|
|
|
|
GtkWidget *prev_focus;
|
|
|
|
|
|
|
|
prev_focus = gtk_window_get_focus (priv->window);
|
2014-01-30 13:11:41 +00:00
|
|
|
priv->prev_focus_widget = prev_focus;
|
|
|
|
if (priv->prev_focus_widget)
|
2014-12-02 14:44:04 +00:00
|
|
|
{
|
|
|
|
priv->prev_focus_unmap_id =
|
|
|
|
g_signal_connect (prev_focus, "unmap",
|
|
|
|
G_CALLBACK (prev_focus_unmap_cb), popover);
|
|
|
|
g_object_ref (prev_focus);
|
|
|
|
}
|
2014-01-10 14:23:12 +00:00
|
|
|
gtk_grab_add (GTK_WIDGET (popover));
|
2014-12-02 14:44:04 +00:00
|
|
|
gtk_window_set_focus (priv->window, NULL);
|
2014-01-10 14:23:12 +00:00
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (popover));
|
2014-03-06 13:50:35 +00:00
|
|
|
|
2018-01-06 17:21:31 +00:00
|
|
|
g_signal_connect (priv->window, "notify::is-active",
|
|
|
|
G_CALLBACK (window_active_changed), popover);
|
2014-03-06 15:58:06 +00:00
|
|
|
g_signal_connect (priv->window, "set-focus",
|
|
|
|
G_CALLBACK (window_set_focus), popover);
|
2014-01-10 14:23:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-06 13:50:35 +00:00
|
|
|
g_signal_handlers_disconnect_by_data (priv->window, popover);
|
2017-09-06 12:04:33 +00:00
|
|
|
if (priv->prev_focus_widget == GTK_WIDGET (priv->window))
|
|
|
|
priv->prev_focus_unmap_id = 0;
|
2014-01-10 14:23:12 +00:00
|
|
|
gtk_grab_remove (GTK_WIDGET (popover));
|
|
|
|
|
2014-12-02 14:44:04 +00:00
|
|
|
/* Let prev_focus_widget regain focus */
|
|
|
|
if (priv->prev_focus_widget &&
|
|
|
|
gtk_widget_is_drawable (priv->prev_focus_widget))
|
2017-08-11 16:03:54 +00:00
|
|
|
{
|
|
|
|
if (GTK_IS_ENTRY (priv->prev_focus_widget))
|
|
|
|
gtk_entry_grab_focus_without_selecting (GTK_ENTRY (priv->prev_focus_widget));
|
|
|
|
else
|
|
|
|
gtk_widget_grab_focus (priv->prev_focus_widget);
|
|
|
|
}
|
2015-01-09 15:10:29 +00:00
|
|
|
else if (priv->window)
|
2014-12-02 14:44:04 +00:00
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (priv->window));
|
2014-03-06 19:38:11 +00:00
|
|
|
|
2014-12-02 14:44:04 +00:00
|
|
|
popover_unset_prev_focus (popover);
|
2014-01-10 14:23:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-09 15:10:29 +00:00
|
|
|
static gboolean
|
|
|
|
show_animate_cb (GtkWidget *widget,
|
|
|
|
GdkFrameClock *frame_clock,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkPopover *popover = GTK_POPOVER (widget);
|
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
|
|
|
gdouble t;
|
|
|
|
|
2016-09-03 07:58:27 +00:00
|
|
|
if (priv->first_frame_skipped)
|
|
|
|
gtk_progress_tracker_advance_frame (&priv->tracker,
|
|
|
|
gdk_frame_clock_get_frame_time (frame_clock));
|
|
|
|
else
|
|
|
|
priv->first_frame_skipped = TRUE;
|
|
|
|
|
2016-03-28 21:45:21 +00:00
|
|
|
t = gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE);
|
2015-01-09 15:10:29 +00:00
|
|
|
|
|
|
|
if (priv->state == STATE_SHOWING)
|
|
|
|
{
|
|
|
|
priv->transition_diff = TRANSITION_DIFF - (TRANSITION_DIFF * t);
|
|
|
|
gtk_widget_set_opacity (widget, t);
|
|
|
|
}
|
|
|
|
else if (priv->state == STATE_HIDING)
|
|
|
|
{
|
|
|
|
priv->transition_diff = -TRANSITION_DIFF * t;
|
|
|
|
gtk_widget_set_opacity (widget, 1.0 - t);
|
|
|
|
}
|
|
|
|
|
2015-09-22 18:27:51 +00:00
|
|
|
gtk_popover_update_position (popover);
|
2017-10-14 10:45:17 +00:00
|
|
|
gtk_widget_queue_allocate (GTK_WIDGET (priv->window));
|
2015-08-21 22:08:30 +00:00
|
|
|
|
2016-03-28 21:45:21 +00:00
|
|
|
if (gtk_progress_tracker_get_state (&priv->tracker) == GTK_PROGRESS_STATE_AFTER)
|
2015-01-09 15:10:29 +00:00
|
|
|
{
|
|
|
|
if (priv->state == STATE_SHOWING)
|
|
|
|
{
|
|
|
|
gtk_popover_set_state (popover, STATE_SHOWN);
|
|
|
|
|
|
|
|
if (!priv->visible)
|
|
|
|
gtk_popover_set_state (popover, STATE_HIDING);
|
|
|
|
}
|
|
|
|
else
|
2016-08-10 16:28:14 +00:00
|
|
|
{
|
|
|
|
gtk_widget_hide (widget);
|
|
|
|
}
|
2015-01-09 15:10:29 +00:00
|
|
|
|
2016-08-10 16:28:14 +00:00
|
|
|
priv->tick_id = 0;
|
|
|
|
return G_SOURCE_REMOVE;
|
2015-01-09 15:10:29 +00:00
|
|
|
}
|
|
|
|
else
|
2016-08-10 16:28:14 +00:00
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_popover_stop_transition (GtkPopover *popover)
|
|
|
|
{
|
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
|
|
|
|
|
|
|
if (priv->tick_id != 0)
|
|
|
|
{
|
|
|
|
gtk_widget_remove_tick_callback (GTK_WIDGET (popover), priv->tick_id);
|
|
|
|
priv->tick_id = 0;
|
|
|
|
}
|
2015-01-09 15:10:29 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 09:36:51 +00:00
|
|
|
static void
|
2015-01-09 15:10:29 +00:00
|
|
|
gtk_popover_start_transition (GtkPopover *popover)
|
2013-11-11 09:36:51 +00:00
|
|
|
{
|
2015-01-09 15:10:29 +00:00
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
|
|
|
|
|
|
|
if (priv->tick_id != 0)
|
|
|
|
return;
|
|
|
|
|
2016-09-03 07:58:27 +00:00
|
|
|
priv->first_frame_skipped = FALSE;
|
2016-03-28 21:45:21 +00:00
|
|
|
gtk_progress_tracker_start (&priv->tracker, TRANSITION_DURATION, 0, 1.0);
|
2015-01-09 15:10:29 +00:00
|
|
|
priv->tick_id = gtk_widget_add_tick_callback (GTK_WIDGET (popover),
|
|
|
|
show_animate_cb,
|
|
|
|
popover, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_popover_set_state (GtkPopover *popover,
|
|
|
|
guint state)
|
|
|
|
{
|
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
|
|
|
|
|
|
|
if (!transitions_enabled (popover) ||
|
|
|
|
!gtk_widget_get_realized (GTK_WIDGET (popover)))
|
|
|
|
{
|
|
|
|
if (state == STATE_SHOWING)
|
|
|
|
state = STATE_SHOWN;
|
|
|
|
else if (state == STATE_HIDING)
|
|
|
|
state = STATE_HIDDEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->state = state;
|
2014-01-10 11:04:17 +00:00
|
|
|
|
2015-01-09 15:10:29 +00:00
|
|
|
if (state == STATE_SHOWING || state == STATE_HIDING)
|
|
|
|
gtk_popover_start_transition (popover);
|
|
|
|
else
|
|
|
|
{
|
2016-08-10 16:28:14 +00:00
|
|
|
gtk_popover_stop_transition (popover);
|
2015-01-09 15:10:29 +00:00
|
|
|
|
|
|
|
gtk_widget_set_visible (GTK_WIDGET (popover), state == STATE_SHOWN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_popover_map (GtkWidget *widget)
|
|
|
|
{
|
2015-04-17 04:10:06 +00:00
|
|
|
GtkPopoverPrivate *priv = GTK_POPOVER (widget)->priv;
|
|
|
|
|
|
|
|
priv->prev_default = gtk_window_get_default_widget (priv->window);
|
2015-05-03 10:19:18 +00:00
|
|
|
if (priv->prev_default)
|
|
|
|
g_object_ref (priv->prev_default);
|
2015-04-17 04:10:06 +00:00
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_popover_parent_class)->map (widget);
|
2014-02-09 06:22:07 +00:00
|
|
|
|
2013-11-11 09:36:51 +00:00
|
|
|
gdk_window_show (gtk_widget_get_window (widget));
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_update_position (GTK_POPOVER (widget));
|
2015-04-17 04:10:06 +00:00
|
|
|
|
|
|
|
gtk_window_set_default (priv->window, priv->default_widget);
|
2013-11-11 09:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_unmap (GtkWidget *widget)
|
2013-11-11 09:36:51 +00:00
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkPopoverPrivate *priv = GTK_POPOVER (widget)->priv;
|
2014-01-10 14:23:12 +00:00
|
|
|
|
2014-01-28 13:05:08 +00:00
|
|
|
priv->button_pressed = FALSE;
|
2014-01-10 14:23:12 +00:00
|
|
|
|
2013-11-11 09:36:51 +00:00
|
|
|
gdk_window_hide (gtk_widget_get_window (widget));
|
2013-11-12 15:55:23 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_popover_parent_class)->unmap (widget);
|
2015-04-17 04:10:06 +00:00
|
|
|
|
2015-08-16 03:38:20 +00:00
|
|
|
if (gtk_window_get_default_widget (priv->window) == priv->default_widget)
|
|
|
|
gtk_window_set_default (priv->window, priv->prev_default);
|
2015-04-17 04:10:06 +00:00
|
|
|
g_clear_object (&priv->prev_default);
|
2013-11-11 09:36:51 +00:00
|
|
|
}
|
|
|
|
|
2014-01-14 11:31:25 +00:00
|
|
|
static GtkPositionType
|
|
|
|
get_effective_position (GtkPopover *popover,
|
|
|
|
GtkPositionType pos)
|
|
|
|
{
|
2017-01-11 14:27:51 +00:00
|
|
|
if (_gtk_widget_get_direction (GTK_WIDGET (popover)) == GTK_TEXT_DIR_RTL)
|
2014-01-14 11:31:25 +00:00
|
|
|
{
|
|
|
|
if (pos == GTK_POS_LEFT)
|
|
|
|
pos = GTK_POS_RIGHT;
|
|
|
|
else if (pos == GTK_POS_RIGHT)
|
|
|
|
pos = GTK_POS_LEFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2014-01-14 17:02:38 +00:00
|
|
|
static void
|
|
|
|
get_margin (GtkWidget *widget,
|
|
|
|
GtkBorder *border)
|
|
|
|
{
|
|
|
|
GtkStyleContext *context;
|
|
|
|
|
|
|
|
context = gtk_widget_get_style_context (widget);
|
2015-11-22 10:43:39 +00:00
|
|
|
gtk_style_context_get_margin (context,
|
|
|
|
border);
|
2014-01-14 17:02:38 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 16:32:08 +00:00
|
|
|
static void
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_get_gap_coords (GtkPopover *popover,
|
|
|
|
gint *initial_x_out,
|
|
|
|
gint *initial_y_out,
|
|
|
|
gint *tip_x_out,
|
|
|
|
gint *tip_y_out,
|
|
|
|
gint *final_x_out,
|
2017-08-03 09:03:39 +00:00
|
|
|
gint *final_y_out)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2013-11-12 15:55:23 +00:00
|
|
|
GtkWidget *widget = GTK_WIDGET (popover);
|
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
2017-08-28 09:15:58 +00:00
|
|
|
GdkRectangle rect = { 0 };
|
2013-11-12 15:55:23 +00:00
|
|
|
gint base, tip, tip_pos;
|
2013-03-05 16:13:54 +00:00
|
|
|
gint initial_x, initial_y;
|
|
|
|
gint tip_x, tip_y;
|
|
|
|
gint final_x, final_y;
|
2017-08-03 09:03:39 +00:00
|
|
|
GtkPositionType pos;
|
2013-11-12 11:41:24 +00:00
|
|
|
gint border_radius;
|
2014-01-22 17:32:16 +00:00
|
|
|
GtkStyleContext *context;
|
2017-08-03 09:03:39 +00:00
|
|
|
GtkBorder border;
|
|
|
|
int popover_width, popover_height;
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_get_pointing_to (popover, &rect);
|
2017-12-04 11:42:52 +00:00
|
|
|
popover_width = gtk_widget_get_width (widget);
|
|
|
|
popover_height = gtk_widget_get_height (widget);
|
2014-10-20 17:10:52 +00:00
|
|
|
|
|
|
|
#ifdef GDK_WINDOWING_WAYLAND
|
|
|
|
if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (widget)))
|
|
|
|
{
|
|
|
|
gint win_x, win_y;
|
|
|
|
|
|
|
|
gtk_widget_translate_coordinates (priv->widget, GTK_WIDGET (priv->window),
|
|
|
|
rect.x, rect.y, &rect.x, &rect.y);
|
|
|
|
gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (popover)),
|
|
|
|
&win_x, &win_y);
|
|
|
|
rect.x -= win_x;
|
|
|
|
rect.y -= win_y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
gtk_widget_translate_coordinates (priv->widget, widget,
|
|
|
|
rect.x, rect.y, &rect.x, &rect.y);
|
|
|
|
|
2017-08-03 09:03:39 +00:00
|
|
|
context = gtk_widget_get_style_context (priv->contents_widget);
|
|
|
|
gtk_style_context_get_border (context, &border);
|
2013-11-12 15:55:23 +00:00
|
|
|
|
2017-08-03 09:03:39 +00:00
|
|
|
pos = get_effective_position (popover, priv->final_position);
|
2014-01-22 17:32:16 +00:00
|
|
|
|
2016-10-08 03:07:23 +00:00
|
|
|
gtk_style_context_get_border (context, &border);
|
2015-11-22 10:43:39 +00:00
|
|
|
gtk_style_context_get (context,
|
2013-11-12 11:41:24 +00:00
|
|
|
GTK_STYLE_PROPERTY_BORDER_RADIUS, &border_radius,
|
|
|
|
NULL);
|
|
|
|
|
2014-01-14 11:31:25 +00:00
|
|
|
if (pos == GTK_POS_BOTTOM || pos == GTK_POS_RIGHT)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2017-08-03 09:03:39 +00:00
|
|
|
tip = 0;
|
|
|
|
base = tip + TAIL_HEIGHT + border.top;
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
2014-01-14 11:31:25 +00:00
|
|
|
else if (pos == GTK_POS_TOP)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2017-08-03 09:03:39 +00:00
|
|
|
base = popover_height - border.bottom - TAIL_HEIGHT;
|
|
|
|
tip = base + TAIL_HEIGHT;
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
2014-01-14 11:31:25 +00:00
|
|
|
else if (pos == GTK_POS_LEFT)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2017-08-03 09:03:39 +00:00
|
|
|
base = popover_width - border.right - TAIL_HEIGHT;
|
|
|
|
tip = base + TAIL_HEIGHT;
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
2013-11-12 15:55:23 +00:00
|
|
|
else
|
|
|
|
g_assert_not_reached ();
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2014-01-14 11:31:25 +00:00
|
|
|
if (POS_IS_VERTICAL (pos))
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2017-08-03 09:03:39 +00:00
|
|
|
tip_pos = rect.x + (rect.width / 2);
|
2013-11-12 15:55:23 +00:00
|
|
|
initial_x = CLAMP (tip_pos - TAIL_GAP_WIDTH / 2,
|
2017-08-03 09:03:39 +00:00
|
|
|
border_radius,
|
|
|
|
popover_width - TAIL_GAP_WIDTH - border_radius);
|
2013-03-05 16:13:54 +00:00
|
|
|
initial_y = base;
|
|
|
|
|
2017-08-03 09:03:39 +00:00
|
|
|
tip_x = CLAMP (tip_pos, 0, popover_width);
|
2013-03-05 16:13:54 +00:00
|
|
|
tip_y = tip;
|
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
final_x = CLAMP (tip_pos + TAIL_GAP_WIDTH / 2,
|
2017-08-03 09:03:39 +00:00
|
|
|
border_radius + TAIL_GAP_WIDTH,
|
|
|
|
popover_width - border_radius);
|
2013-03-05 16:13:54 +00:00
|
|
|
final_y = base;
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-03 09:03:39 +00:00
|
|
|
tip_pos = rect.y + (rect.height / 2);
|
2013-11-12 15:55:23 +00:00
|
|
|
|
2013-03-05 16:13:54 +00:00
|
|
|
initial_x = base;
|
2013-11-12 15:55:23 +00:00
|
|
|
initial_y = CLAMP (tip_pos - TAIL_GAP_WIDTH / 2,
|
2017-08-03 09:03:39 +00:00
|
|
|
border_radius,
|
|
|
|
popover_height - TAIL_GAP_WIDTH - border_radius);
|
2013-03-05 16:13:54 +00:00
|
|
|
|
|
|
|
tip_x = tip;
|
2017-08-03 09:03:39 +00:00
|
|
|
tip_y = CLAMP (tip_pos, 0, popover_height);
|
2013-03-05 16:13:54 +00:00
|
|
|
|
|
|
|
final_x = base;
|
2013-11-12 15:55:23 +00:00
|
|
|
final_y = CLAMP (tip_pos + TAIL_GAP_WIDTH / 2,
|
2017-08-03 09:03:39 +00:00
|
|
|
border_radius + TAIL_GAP_WIDTH,
|
|
|
|
popover_height - border_radius);
|
2013-03-05 16:13:54 +00:00
|
|
|
}
|
|
|
|
|
2017-08-03 09:03:39 +00:00
|
|
|
*initial_x_out = initial_x;
|
|
|
|
*initial_y_out = initial_y;
|
2013-03-05 16:13:54 +00:00
|
|
|
|
2017-08-03 09:03:39 +00:00
|
|
|
*tip_x_out = tip_x;
|
|
|
|
*tip_y_out = tip_y;
|
2013-03-05 16:13:54 +00:00
|
|
|
|
2017-08-03 09:03:39 +00:00
|
|
|
*final_x_out = final_x;
|
|
|
|
*final_y_out = final_y;
|
2013-03-05 16:13:54 +00:00
|
|
|
}
|
|
|
|
|
2016-09-01 13:15:18 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_get_rect_for_size (GtkPopover *popover,
|
|
|
|
int popover_width,
|
|
|
|
int popover_height,
|
|
|
|
GdkRectangle *rect)
|
|
|
|
{
|
|
|
|
GtkWidget *widget = GTK_WIDGET (popover);
|
|
|
|
int x, y, w, h;
|
|
|
|
GtkBorder margin;
|
|
|
|
|
|
|
|
get_margin (widget, &margin);
|
|
|
|
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
w = popover_width;
|
|
|
|
h = popover_height;
|
|
|
|
|
|
|
|
x += MAX (TAIL_HEIGHT, margin.left);
|
|
|
|
y += MAX (TAIL_HEIGHT, margin.top);
|
|
|
|
w -= x + MAX (TAIL_HEIGHT, margin.right);
|
|
|
|
h -= y + MAX (TAIL_HEIGHT, margin.bottom);
|
|
|
|
|
|
|
|
rect->x = x;
|
|
|
|
rect->y = y;
|
|
|
|
rect->width = w;
|
|
|
|
rect->height = h;
|
|
|
|
}
|
|
|
|
|
2013-03-05 16:13:54 +00:00
|
|
|
static void
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_get_rect_coords (GtkPopover *popover,
|
2016-09-01 13:15:18 +00:00
|
|
|
int *x_out,
|
|
|
|
int *y_out,
|
|
|
|
int *w_out,
|
|
|
|
int *h_out)
|
2013-03-05 16:13:54 +00:00
|
|
|
{
|
2013-11-12 15:55:23 +00:00
|
|
|
GtkWidget *widget = GTK_WIDGET (popover);
|
2016-09-01 13:15:18 +00:00
|
|
|
GdkRectangle rect;
|
2013-03-05 16:13:54 +00:00
|
|
|
GtkAllocation allocation;
|
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
2016-09-01 13:15:18 +00:00
|
|
|
gtk_popover_get_rect_for_size (popover, allocation.width, allocation.height, &rect);
|
2013-11-12 15:55:23 +00:00
|
|
|
|
2016-09-01 13:15:18 +00:00
|
|
|
*x_out = rect.x;
|
|
|
|
*y_out = rect.y;
|
|
|
|
*w_out = rect.width;
|
|
|
|
*h_out = rect.height;
|
2013-03-05 16:13:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_apply_tail_path (GtkPopover *popover,
|
|
|
|
cairo_t *cr)
|
2013-03-05 16:13:54 +00:00
|
|
|
{
|
|
|
|
gint initial_x, initial_y;
|
|
|
|
gint tip_x, tip_y;
|
|
|
|
gint final_x, final_y;
|
2017-07-08 10:04:44 +00:00
|
|
|
GtkStyleContext *context;
|
|
|
|
GtkBorder border;
|
2013-03-05 16:13:54 +00:00
|
|
|
|
2014-11-14 04:09:21 +00:00
|
|
|
if (!popover->priv->widget)
|
|
|
|
return;
|
|
|
|
|
2017-07-08 10:04:44 +00:00
|
|
|
context = gtk_widget_get_style_context (popover->priv->contents_widget);
|
|
|
|
gtk_style_context_get_border (context, &border);
|
|
|
|
|
2014-02-04 19:45:53 +00:00
|
|
|
cairo_set_line_width (cr, 1);
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_get_gap_coords (popover,
|
|
|
|
&initial_x, &initial_y,
|
|
|
|
&tip_x, &tip_y,
|
2017-08-03 09:03:39 +00:00
|
|
|
&final_x, &final_y);
|
2017-07-08 10:04:44 +00:00
|
|
|
|
|
|
|
cairo_move_to (cr, initial_x, initial_y);
|
|
|
|
cairo_line_to (cr, tip_x, tip_y);
|
|
|
|
cairo_line_to (cr, final_x, final_y);
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-02-04 19:45:53 +00:00
|
|
|
gtk_popover_fill_border_path (GtkPopover *popover,
|
|
|
|
cairo_t *cr)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkWidget *widget = GTK_WIDGET (popover);
|
2013-01-11 16:32:08 +00:00
|
|
|
GtkAllocation allocation;
|
2014-02-04 19:45:53 +00:00
|
|
|
GtkStyleContext *context;
|
2016-09-01 13:15:18 +00:00
|
|
|
int x, y, w, h;
|
2016-12-13 19:48:58 +00:00
|
|
|
GskRoundedRect box;
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2014-02-09 06:22:07 +00:00
|
|
|
context = gtk_widget_get_style_context (widget);
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2016-01-05 18:05:43 +00:00
|
|
|
cairo_set_source_rgba (cr, 0, 0, 0, 1);
|
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_apply_tail_path (popover, cr);
|
2013-01-15 16:32:42 +00:00
|
|
|
cairo_close_path (cr);
|
2014-02-04 19:45:53 +00:00
|
|
|
cairo_fill (cr);
|
|
|
|
|
2016-09-01 13:15:18 +00:00
|
|
|
gtk_popover_get_rect_coords (popover, &x, &y, &w, &h);
|
2016-01-05 18:05:43 +00:00
|
|
|
|
2016-12-19 18:19:15 +00:00
|
|
|
gtk_rounded_boxes_init_for_style (&box,
|
|
|
|
NULL, NULL,
|
|
|
|
gtk_style_context_lookup_style (context),
|
|
|
|
x, y, w, h);
|
2016-12-13 20:00:28 +00:00
|
|
|
gsk_rounded_rect_path (&box, cr);
|
2016-01-05 18:05:43 +00:00
|
|
|
cairo_fill (cr);
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_update_shape (GtkPopover *popover)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkWidget *widget = GTK_WIDGET (popover);
|
2013-01-11 16:32:08 +00:00
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_region_t *region;
|
|
|
|
GdkWindow *win;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
2015-10-01 11:08:37 +00:00
|
|
|
#ifdef GDK_WINDOWING_WAYLAND
|
|
|
|
if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (widget)))
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2014-02-09 06:22:07 +00:00
|
|
|
win = gtk_widget_get_window (widget);
|
2013-01-11 16:32:08 +00:00
|
|
|
surface =
|
|
|
|
gdk_window_create_similar_surface (win,
|
|
|
|
CAIRO_CONTENT_COLOR_ALPHA,
|
|
|
|
gdk_window_get_width (win),
|
|
|
|
gdk_window_get_height (win));
|
|
|
|
|
|
|
|
cr = cairo_create (surface);
|
2014-02-04 19:45:53 +00:00
|
|
|
gtk_popover_fill_border_path (popover, cr);
|
2013-01-11 16:32:08 +00:00
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
region = gdk_cairo_region_create_from_surface (surface);
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
2014-02-09 06:22:07 +00:00
|
|
|
gtk_widget_shape_combine_region (widget, region);
|
2013-01-11 16:32:08 +00:00
|
|
|
cairo_region_destroy (region);
|
2014-02-04 11:07:42 +00:00
|
|
|
|
2017-06-28 14:19:22 +00:00
|
|
|
gdk_window_set_child_shapes (gtk_widget_get_window (widget));
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
2014-01-22 15:45:01 +00:00
|
|
|
static void
|
|
|
|
_gtk_popover_update_child_visible (GtkPopover *popover)
|
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
|
|
|
GtkWidget *widget = GTK_WIDGET (popover);
|
2014-02-04 21:33:25 +00:00
|
|
|
GdkRectangle rect;
|
2014-01-22 15:45:01 +00:00
|
|
|
GtkAllocation allocation;
|
|
|
|
GtkWidget *parent;
|
|
|
|
|
|
|
|
if (!priv->parent_scrollable)
|
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
gtk_widget_set_child_visible (widget, TRUE);
|
2014-01-22 15:45:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent = gtk_widget_get_parent (GTK_WIDGET (priv->parent_scrollable));
|
|
|
|
rect = priv->pointing_to;
|
|
|
|
|
|
|
|
gtk_widget_translate_coordinates (priv->widget, parent,
|
|
|
|
rect.x, rect.y, &rect.x, &rect.y);
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (GTK_WIDGET (parent), &allocation);
|
|
|
|
|
2015-06-12 09:59:47 +00:00
|
|
|
if (rect.x + rect.width < 0 || rect.x > allocation.width ||
|
|
|
|
rect.y + rect.height < 0 || rect.y > allocation.height)
|
2014-02-09 06:22:07 +00:00
|
|
|
gtk_widget_set_child_visible (widget, FALSE);
|
2014-01-22 15:45:01 +00:00
|
|
|
else
|
2014-02-09 06:22:07 +00:00
|
|
|
gtk_widget_set_child_visible (widget, TRUE);
|
2014-01-22 15:45:01 +00:00
|
|
|
}
|
|
|
|
|
2014-02-09 03:14:51 +00:00
|
|
|
static GtkPositionType
|
|
|
|
opposite_position (GtkPositionType pos)
|
|
|
|
{
|
|
|
|
switch (pos)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case GTK_POS_LEFT: return GTK_POS_RIGHT;
|
|
|
|
case GTK_POS_RIGHT: return GTK_POS_LEFT;
|
|
|
|
case GTK_POS_TOP: return GTK_POS_BOTTOM;
|
|
|
|
case GTK_POS_BOTTOM: return GTK_POS_TOP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-01 15:38:42 +00:00
|
|
|
void
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_update_position (GtkPopover *popover)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
|
|
|
GtkWidget *widget = GTK_WIDGET (popover);
|
2013-11-12 15:55:23 +00:00
|
|
|
GtkAllocation window_alloc;
|
2017-08-23 20:44:10 +00:00
|
|
|
GtkBorder window_shadow;
|
2017-08-28 09:15:58 +00:00
|
|
|
GdkRectangle rect = { 0 };
|
2013-11-12 15:55:23 +00:00
|
|
|
GtkRequisition req;
|
2014-02-09 03:14:51 +00:00
|
|
|
GtkPositionType pos;
|
|
|
|
gint overshoot[4];
|
2014-08-21 15:57:19 +00:00
|
|
|
gint i, j;
|
2014-02-09 03:14:51 +00:00
|
|
|
gint best;
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
if (!priv->window)
|
|
|
|
return;
|
|
|
|
|
2014-02-09 06:22:07 +00:00
|
|
|
gtk_widget_get_preferred_size (widget, NULL, &req);
|
2013-11-12 11:15:53 +00:00
|
|
|
gtk_widget_get_allocation (GTK_WIDGET (priv->window), &window_alloc);
|
2017-08-23 20:44:10 +00:00
|
|
|
_gtk_window_get_shadow_width (priv->window, &window_shadow);
|
2013-01-11 16:32:08 +00:00
|
|
|
priv->final_position = priv->preferred_position;
|
|
|
|
|
2015-09-22 16:25:26 +00:00
|
|
|
gtk_popover_get_pointing_to (popover, &rect);
|
|
|
|
gtk_widget_translate_coordinates (priv->widget, GTK_WIDGET (priv->window),
|
|
|
|
rect.x, rect.y, &rect.x, &rect.y);
|
|
|
|
|
2014-01-14 11:31:25 +00:00
|
|
|
pos = get_effective_position (popover, priv->preferred_position);
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2017-08-23 20:44:10 +00:00
|
|
|
overshoot[GTK_POS_TOP] = req.height - rect.y + window_shadow.top;
|
|
|
|
overshoot[GTK_POS_BOTTOM] = rect.y + rect.height + req.height - window_alloc.height
|
|
|
|
+ window_shadow.bottom;
|
|
|
|
overshoot[GTK_POS_LEFT] = req.width - rect.x + window_shadow.left;
|
|
|
|
overshoot[GTK_POS_RIGHT] = rect.x + rect.width + req.width - window_alloc.width
|
|
|
|
+ window_shadow.right;
|
2014-02-09 03:14:51 +00:00
|
|
|
|
2014-12-24 13:59:49 +00:00
|
|
|
#ifdef GDK_WINDOWING_WAYLAND
|
2015-12-01 19:56:56 +00:00
|
|
|
if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (widget)) &&
|
|
|
|
priv->constraint == GTK_POPOVER_CONSTRAINT_NONE)
|
2014-10-20 17:10:52 +00:00
|
|
|
{
|
|
|
|
priv->final_position = priv->preferred_position;
|
|
|
|
}
|
2014-12-24 13:59:49 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (overshoot[pos] <= 0)
|
2014-02-09 03:14:51 +00:00
|
|
|
{
|
2014-08-21 15:57:19 +00:00
|
|
|
priv->final_position = priv->preferred_position;
|
2014-02-09 03:14:51 +00:00
|
|
|
}
|
|
|
|
else if (overshoot[opposite_position (pos)] <= 0)
|
|
|
|
{
|
2014-08-21 15:57:19 +00:00
|
|
|
priv->final_position = opposite_position (priv->preferred_position);
|
2014-02-09 03:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
best = G_MAXINT;
|
|
|
|
pos = 0;
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
2014-08-21 15:57:19 +00:00
|
|
|
j = get_effective_position (popover, i);
|
|
|
|
if (overshoot[j] < best)
|
2014-02-09 03:14:51 +00:00
|
|
|
{
|
|
|
|
pos = i;
|
2014-08-21 15:57:19 +00:00
|
|
|
best = overshoot[j];
|
2014-02-09 03:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
priv->final_position = pos;
|
|
|
|
}
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2015-01-09 15:10:29 +00:00
|
|
|
switch (priv->final_position)
|
|
|
|
{
|
|
|
|
case GTK_POS_TOP:
|
|
|
|
rect.y += priv->transition_diff;
|
|
|
|
break;
|
|
|
|
case GTK_POS_BOTTOM:
|
|
|
|
rect.y -= priv->transition_diff;
|
|
|
|
break;
|
|
|
|
case GTK_POS_LEFT:
|
|
|
|
rect.x += priv->transition_diff;
|
|
|
|
break;
|
|
|
|
case GTK_POS_RIGHT:
|
|
|
|
rect.x -= priv->transition_diff;
|
|
|
|
break;
|
2017-10-06 19:19:42 +00:00
|
|
|
default:
|
|
|
|
break;
|
2015-01-09 15:10:29 +00:00
|
|
|
}
|
|
|
|
|
2014-02-09 06:22:07 +00:00
|
|
|
_gtk_window_set_popover_position (priv->window, widget,
|
2014-01-17 17:12:31 +00:00
|
|
|
priv->final_position, &rect);
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
if (priv->final_position != priv->current_position)
|
|
|
|
{
|
2015-09-23 09:30:52 +00:00
|
|
|
if (gtk_widget_is_drawable (widget))
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_update_shape (popover);
|
2013-11-11 09:36:51 +00:00
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
priv->current_position = priv->final_position;
|
|
|
|
}
|
2014-01-22 15:45:01 +00:00
|
|
|
|
|
|
|
_gtk_popover_update_child_visible (popover);
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
2017-07-08 10:04:44 +00:00
|
|
|
GtkWidget *
|
|
|
|
gtk_popover_get_contents_widget (GtkPopover *popover)
|
|
|
|
{
|
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
|
|
|
|
|
|
|
return priv->contents_widget;
|
|
|
|
}
|
|
|
|
|
2016-11-15 16:28:34 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_snapshot (GtkWidget *widget,
|
|
|
|
GtkSnapshot *snapshot)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkPopover *popover = GTK_POPOVER (widget);
|
2017-07-08 10:04:44 +00:00
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
2013-01-11 16:32:08 +00:00
|
|
|
GtkStyleContext *context;
|
2013-03-05 16:13:54 +00:00
|
|
|
GtkBorder border;
|
2016-11-15 16:28:34 +00:00
|
|
|
graphene_rect_t bounds;
|
|
|
|
cairo_t *cr;
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2017-07-08 10:04:44 +00:00
|
|
|
/* Draw the child first so we can draw the arrow (partially) over it */
|
|
|
|
gtk_widget_snapshot_child (widget, priv->contents_widget, snapshot);
|
2013-03-05 16:13:54 +00:00
|
|
|
|
2016-11-15 16:28:34 +00:00
|
|
|
graphene_rect_init (&bounds,
|
2017-07-08 10:04:44 +00:00
|
|
|
0, 0,
|
2017-11-23 10:29:47 +00:00
|
|
|
gtk_widget_get_width (widget),
|
|
|
|
gtk_widget_get_height (widget));
|
2017-01-13 03:46:09 +00:00
|
|
|
cr = gtk_snapshot_append_cairo (snapshot,
|
|
|
|
&bounds,
|
|
|
|
"Popover");
|
2013-03-05 16:13:54 +00:00
|
|
|
|
|
|
|
/* Clip to the arrow shape */
|
|
|
|
cairo_save (cr);
|
|
|
|
|
2014-02-09 06:22:07 +00:00
|
|
|
gtk_popover_apply_tail_path (popover, cr);
|
2017-07-08 10:04:44 +00:00
|
|
|
|
2013-03-05 16:13:54 +00:00
|
|
|
cairo_clip (cr);
|
|
|
|
|
2017-07-08 10:04:44 +00:00
|
|
|
context = gtk_widget_get_style_context (widget);
|
|
|
|
gtk_style_context_save_to_node (context, priv->arrow_node);
|
|
|
|
gtk_style_context_get_border (context, &border);
|
|
|
|
|
2013-03-05 16:13:54 +00:00
|
|
|
/* Render the arrow background */
|
|
|
|
gtk_render_background (context, cr,
|
2017-07-08 10:04:44 +00:00
|
|
|
0, 0,
|
2017-11-23 10:29:47 +00:00
|
|
|
gtk_widget_get_width (widget),
|
|
|
|
gtk_widget_get_height (widget));
|
2013-01-15 16:32:42 +00:00
|
|
|
|
2013-03-05 16:13:54 +00:00
|
|
|
/* Render the border of the arrow tip */
|
|
|
|
if (border.bottom > 0)
|
|
|
|
{
|
2017-08-03 09:03:39 +00:00
|
|
|
GdkRGBA border_color;
|
2014-10-03 03:52:49 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
2016-10-08 03:07:23 +00:00
|
|
|
gtk_style_context_get_border_color (context, &border_color);
|
2014-10-03 03:52:49 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
2015-10-12 22:21:43 +00:00
|
|
|
|
2014-02-09 06:22:07 +00:00
|
|
|
gtk_popover_apply_tail_path (popover, cr);
|
2013-03-05 16:13:54 +00:00
|
|
|
gdk_cairo_set_source_rgba (cr, &border_color);
|
|
|
|
|
2014-01-14 17:02:38 +00:00
|
|
|
cairo_set_line_width (cr, border.bottom + 1);
|
2013-03-05 16:13:54 +00:00
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
|
2017-07-08 10:04:44 +00:00
|
|
|
cairo_restore (cr);
|
2013-03-05 16:13:54 +00:00
|
|
|
/* We're done */
|
2016-11-15 16:28:34 +00:00
|
|
|
cairo_destroy (cr);
|
2013-01-15 16:32:42 +00:00
|
|
|
|
2017-07-08 10:04:44 +00:00
|
|
|
gtk_style_context_restore (context);
|
2013-03-05 15:55:41 +00:00
|
|
|
}
|
|
|
|
|
2014-01-28 15:02:47 +00:00
|
|
|
static gint
|
|
|
|
get_border_radius (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkStyleContext *context;
|
|
|
|
gint border_radius;
|
|
|
|
|
|
|
|
context = gtk_widget_get_style_context (widget);
|
2016-10-08 03:07:23 +00:00
|
|
|
gtk_style_context_get (context,
|
2014-01-28 15:02:47 +00:00
|
|
|
GTK_STYLE_PROPERTY_BORDER_RADIUS, &border_radius,
|
|
|
|
NULL);
|
|
|
|
return border_radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
get_minimal_size (GtkPopover *popover,
|
|
|
|
GtkOrientation orientation)
|
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
2014-01-28 15:02:47 +00:00
|
|
|
GtkPositionType pos;
|
|
|
|
gint minimal_size;
|
|
|
|
|
|
|
|
minimal_size = 2 * get_border_radius (GTK_WIDGET (popover));
|
|
|
|
pos = get_effective_position (popover, priv->preferred_position);
|
|
|
|
|
|
|
|
if ((orientation == GTK_ORIENTATION_HORIZONTAL && POS_IS_VERTICAL (pos)) ||
|
|
|
|
(orientation == GTK_ORIENTATION_VERTICAL && !POS_IS_VERTICAL (pos)))
|
|
|
|
minimal_size += TAIL_GAP_WIDTH;
|
|
|
|
|
|
|
|
return minimal_size;
|
|
|
|
}
|
|
|
|
|
2013-01-11 16:32:08 +00:00
|
|
|
static void
|
2016-10-22 14:06:14 +00:00
|
|
|
gtk_popover_measure (GtkWidget *widget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
int for_size,
|
|
|
|
int *minimum,
|
|
|
|
int *natural,
|
|
|
|
int *minimum_baseline,
|
|
|
|
int *natural_baseline)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkPopover *popover = GTK_POPOVER (widget);
|
2017-07-08 10:04:44 +00:00
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
2016-10-22 14:06:14 +00:00
|
|
|
GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
|
2017-06-21 10:14:00 +00:00
|
|
|
int minimal_size;
|
2014-01-10 22:43:42 +00:00
|
|
|
|
2016-10-22 14:06:14 +00:00
|
|
|
*minimum = 0;
|
|
|
|
*natural = 0;
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2016-10-22 14:06:14 +00:00
|
|
|
if (child != NULL)
|
|
|
|
{
|
|
|
|
if (for_size >= 0)
|
2017-06-21 10:14:00 +00:00
|
|
|
for_size -= TAIL_HEIGHT;
|
2016-09-01 13:16:58 +00:00
|
|
|
|
2017-07-08 10:04:44 +00:00
|
|
|
gtk_widget_measure (priv->contents_widget, orientation, for_size, minimum, natural, NULL, NULL);
|
2016-10-22 14:06:14 +00:00
|
|
|
}
|
2014-01-14 17:02:38 +00:00
|
|
|
|
2016-10-22 14:06:14 +00:00
|
|
|
minimal_size = get_minimal_size (popover, orientation);
|
2017-06-21 10:14:00 +00:00
|
|
|
*minimum = MAX (*minimum, minimal_size);
|
|
|
|
*natural = MAX (*natural, minimal_size);
|
2014-01-10 22:43:42 +00:00
|
|
|
|
2017-07-08 10:04:44 +00:00
|
|
|
*minimum += TAIL_HEIGHT;
|
|
|
|
*natural += TAIL_HEIGHT;
|
2015-10-12 22:21:43 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 16:32:08 +00:00
|
|
|
static void
|
2017-07-11 07:58:21 +00:00
|
|
|
gtk_popover_size_allocate (GtkWidget *widget,
|
|
|
|
const GtkAllocation *allocation,
|
|
|
|
int baseline,
|
|
|
|
GtkAllocation *out_clip)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkPopover *popover = GTK_POPOVER (widget);
|
2017-07-08 10:04:44 +00:00
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
|
|
|
GtkAllocation child_alloc = *allocation;
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2017-07-08 10:04:44 +00:00
|
|
|
/* Note that we in measure() we add TAIL_HEIGHT in both directions, regardless
|
|
|
|
* of the popovers position. This is to ensure that we get enough space
|
|
|
|
* even priv->current_position changes between measure and size-allocate.
|
|
|
|
*/
|
2017-08-03 09:03:39 +00:00
|
|
|
child_alloc.height -= TAIL_HEIGHT;
|
|
|
|
child_alloc.width -= TAIL_HEIGHT;
|
|
|
|
|
2017-07-08 10:04:44 +00:00
|
|
|
switch (priv->current_position)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2017-07-08 10:04:44 +00:00
|
|
|
case GTK_POS_TOP:
|
|
|
|
child_alloc.x += TAIL_HEIGHT / 2;
|
|
|
|
break;
|
|
|
|
case GTK_POS_BOTTOM:
|
|
|
|
child_alloc.x += TAIL_HEIGHT / 2;
|
2017-08-03 09:03:39 +00:00
|
|
|
child_alloc.y += TAIL_HEIGHT;
|
|
|
|
break;
|
|
|
|
case GTK_POS_LEFT:
|
|
|
|
child_alloc.y += TAIL_HEIGHT / 2;
|
2017-07-08 10:04:44 +00:00
|
|
|
break;
|
|
|
|
case GTK_POS_RIGHT:
|
|
|
|
child_alloc.x += TAIL_HEIGHT;
|
|
|
|
child_alloc.y += TAIL_HEIGHT / 2;
|
|
|
|
break;
|
2017-10-06 19:19:42 +00:00
|
|
|
default:
|
|
|
|
break;
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
2017-07-11 07:58:21 +00:00
|
|
|
gtk_widget_size_allocate (priv->contents_widget, &child_alloc, -1, out_clip);
|
2017-07-08 10:04:44 +00:00
|
|
|
|
2013-01-11 16:32:08 +00:00
|
|
|
if (gtk_widget_get_realized (widget))
|
2013-11-11 09:36:51 +00:00
|
|
|
{
|
2017-06-21 10:14:00 +00:00
|
|
|
GtkAllocation a;
|
|
|
|
gtk_widget_get_window_allocation (widget, &a);
|
2013-11-11 09:36:51 +00:00
|
|
|
gdk_window_move_resize (gtk_widget_get_window (widget),
|
2017-06-21 10:14:00 +00:00
|
|
|
a.x, a.y, a.width, a.height);
|
2015-09-23 09:30:52 +00:00
|
|
|
gtk_popover_update_shape (popover);
|
2013-11-11 09:36:51 +00:00
|
|
|
}
|
2016-10-29 17:43:49 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 16:32:08 +00:00
|
|
|
static gboolean
|
2018-01-16 18:57:50 +00:00
|
|
|
gtk_popover_event (GtkWidget *widget,
|
|
|
|
GdkEvent *event)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkPopover *popover = GTK_POPOVER (widget);
|
2014-01-28 13:05:08 +00:00
|
|
|
|
2018-01-16 18:57:50 +00:00
|
|
|
if (gdk_event_get_event_type (event) == GDK_BUTTON_PRESS)
|
|
|
|
popover->priv->button_pressed = TRUE;
|
|
|
|
else if (gdk_event_get_event_type (event) == GDK_BUTTON_RELEASE)
|
|
|
|
{
|
|
|
|
GtkAllocation child_alloc;
|
|
|
|
GtkWidget *child;
|
|
|
|
gdouble x, y;
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2018-01-16 18:57:50 +00:00
|
|
|
child = gtk_bin_get_child (GTK_BIN (widget));
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2018-01-16 18:57:50 +00:00
|
|
|
if (!popover->priv->button_pressed ||
|
|
|
|
!gdk_event_get_coords (event, &x, &y))
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
2014-01-28 13:05:08 +00:00
|
|
|
|
2018-01-16 18:57:50 +00:00
|
|
|
gtk_widget_get_allocation (child, &child_alloc);
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2018-01-16 18:57:50 +00:00
|
|
|
if (x < child_alloc.x ||
|
|
|
|
x > child_alloc.x + child_alloc.width ||
|
|
|
|
y < child_alloc.y ||
|
|
|
|
y > child_alloc.y + child_alloc.height)
|
|
|
|
gtk_popover_popdown (popover);
|
|
|
|
}
|
2013-01-11 16:32:08 +00:00
|
|
|
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *event)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2014-11-25 12:54:25 +00:00
|
|
|
GtkWidget *toplevel, *focus;
|
2017-08-25 14:52:16 +00:00
|
|
|
guint keyval;
|
2014-11-25 12:54:25 +00:00
|
|
|
|
2017-08-25 14:52:16 +00:00
|
|
|
if (!gdk_event_get_keyval ((GdkEvent *) event, &keyval))
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
if (keyval == GDK_KEY_Escape)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2016-11-03 10:58:41 +00:00
|
|
|
gtk_popover_popdown (GTK_POPOVER (widget));
|
2013-01-11 16:32:08 +00:00
|
|
|
return GDK_EVENT_STOP;
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:54:25 +00:00
|
|
|
if (!GTK_POPOVER (widget)->priv->modal)
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
toplevel = gtk_widget_get_toplevel (widget);
|
|
|
|
|
|
|
|
if (GTK_IS_WINDOW (toplevel))
|
|
|
|
{
|
|
|
|
focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
|
|
|
|
|
|
|
|
if (focus && gtk_widget_is_ancestor (focus, widget))
|
2014-11-26 14:30:52 +00:00
|
|
|
return gtk_widget_event (focus, (GdkEvent*) event);
|
2014-11-25 12:54:25 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 16:32:08 +00:00
|
|
|
return GDK_EVENT_PROPAGATE;
|
|
|
|
}
|
|
|
|
|
2014-01-09 11:53:29 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_grab_focus (GtkWidget *widget)
|
|
|
|
{
|
2015-01-09 15:10:29 +00:00
|
|
|
GtkPopoverPrivate *priv = GTK_POPOVER (widget)->priv;
|
2014-12-13 16:05:56 +00:00
|
|
|
GtkWidget *child;
|
|
|
|
|
2015-01-09 15:10:29 +00:00
|
|
|
if (!priv->visible)
|
|
|
|
return;
|
|
|
|
|
2014-01-09 11:53:29 +00:00
|
|
|
/* Focus the first natural child */
|
2014-12-13 16:05:56 +00:00
|
|
|
child = gtk_bin_get_child (GTK_BIN (widget));
|
|
|
|
|
|
|
|
if (child)
|
|
|
|
gtk_widget_child_focus (child, GTK_DIR_TAB_FORWARD);
|
2014-01-09 11:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_popover_focus (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction)
|
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkPopover *popover = GTK_POPOVER (widget);
|
2015-01-09 15:10:29 +00:00
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
|
|
|
|
|
|
|
if (!priv->visible)
|
|
|
|
return FALSE;
|
2014-01-09 11:53:29 +00:00
|
|
|
|
|
|
|
if (!GTK_WIDGET_CLASS (gtk_popover_parent_class)->focus (widget, direction))
|
|
|
|
{
|
|
|
|
GtkWidget *focus;
|
|
|
|
|
2014-02-09 06:22:07 +00:00
|
|
|
focus = gtk_window_get_focus (popover->priv->window);
|
2014-01-09 11:53:29 +00:00
|
|
|
focus = gtk_widget_get_parent (focus);
|
|
|
|
|
|
|
|
/* Unset focus child through children, so it is next stepped from
|
|
|
|
* scratch.
|
|
|
|
*/
|
|
|
|
while (focus && focus != widget)
|
|
|
|
{
|
2017-02-08 08:00:29 +00:00
|
|
|
gtk_widget_set_focus_child (focus, NULL);
|
2014-01-09 11:53:29 +00:00
|
|
|
focus = gtk_widget_get_parent (focus);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gtk_widget_child_focus (gtk_bin_get_child (GTK_BIN (widget)),
|
|
|
|
direction);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-01-09 15:10:29 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_show (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkPopoverPrivate *priv = GTK_POPOVER (widget)->priv;
|
|
|
|
|
2015-10-22 16:13:19 +00:00
|
|
|
if (priv->window)
|
|
|
|
_gtk_window_raise_popover (priv->window, widget);
|
|
|
|
|
2015-01-09 15:10:29 +00:00
|
|
|
priv->visible = TRUE;
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_popover_parent_class)->show (widget);
|
|
|
|
|
|
|
|
if (priv->modal)
|
|
|
|
gtk_popover_apply_modality (GTK_POPOVER (widget), TRUE);
|
|
|
|
|
2016-08-10 16:28:14 +00:00
|
|
|
priv->state = STATE_SHOWN;
|
2015-01-09 15:10:29 +00:00
|
|
|
|
|
|
|
if (gtk_widget_get_realized (widget))
|
2017-07-08 10:04:44 +00:00
|
|
|
gdk_window_input_shape_combine_region (gtk_widget_get_window (widget),
|
2015-01-09 15:10:29 +00:00
|
|
|
NULL, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_popover_hide (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkPopoverPrivate *priv = GTK_POPOVER (widget)->priv;
|
|
|
|
|
2016-08-10 16:28:14 +00:00
|
|
|
gtk_popover_hide_internal (GTK_POPOVER (widget));
|
2015-01-09 15:10:29 +00:00
|
|
|
|
2016-08-10 16:28:14 +00:00
|
|
|
gtk_popover_stop_transition (GTK_POPOVER (widget));
|
|
|
|
priv->state = STATE_HIDDEN;
|
|
|
|
priv->transition_diff = 0;
|
|
|
|
gtk_progress_tracker_finish (&priv->tracker);
|
|
|
|
gtk_widget_set_opacity (widget, 1.0);
|
2015-01-09 15:10:29 +00:00
|
|
|
|
|
|
|
|
2016-08-10 16:28:14 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_popover_parent_class)->hide (widget);
|
2015-01-09 15:10:29 +00:00
|
|
|
}
|
2014-01-09 11:53:29 +00:00
|
|
|
|
2017-07-08 10:04:44 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_add (GtkContainer *container,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
|
|
|
GtkPopover *popover = GTK_POPOVER (container);
|
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
|
|
|
|
|
|
|
_gtk_bin_set_child (GTK_BIN (popover), child);
|
|
|
|
|
|
|
|
gtk_widget_set_parent (child, priv->contents_widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_popover_remove (GtkContainer *container,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
|
|
|
GtkPopover *popover = GTK_POPOVER (container);
|
|
|
|
|
|
|
|
_gtk_bin_set_child (GTK_BIN (popover), NULL);
|
|
|
|
gtk_widget_unparent (child);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_popover_state_flags_changed (GtkWidget *widget,
|
|
|
|
GtkStateFlags previous_state)
|
|
|
|
{
|
|
|
|
GtkPopover *popover = GTK_POPOVER (widget);
|
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
|
|
|
GtkStateFlags state;
|
|
|
|
|
|
|
|
state = gtk_widget_get_state_flags (widget);
|
|
|
|
gtk_css_node_set_state (priv->arrow_node, state);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_popover_parent_class)->state_flags_changed (widget, previous_state);
|
|
|
|
}
|
|
|
|
|
2013-01-11 16:32:08 +00:00
|
|
|
static void
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_class_init (GtkPopoverClass *klass)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2017-07-08 10:04:44 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
object_class->set_property = gtk_popover_set_property;
|
|
|
|
object_class->get_property = gtk_popover_get_property;
|
|
|
|
object_class->finalize = gtk_popover_finalize;
|
|
|
|
object_class->dispose = gtk_popover_dispose;
|
|
|
|
|
|
|
|
widget_class->realize = gtk_popover_realize;
|
|
|
|
widget_class->map = gtk_popover_map;
|
|
|
|
widget_class->unmap = gtk_popover_unmap;
|
2016-10-22 14:06:14 +00:00
|
|
|
widget_class->measure = gtk_popover_measure;
|
2013-11-12 15:55:23 +00:00
|
|
|
widget_class->size_allocate = gtk_popover_size_allocate;
|
2016-11-15 16:28:34 +00:00
|
|
|
widget_class->snapshot = gtk_popover_snapshot;
|
2018-01-16 18:57:50 +00:00
|
|
|
widget_class->event = gtk_popover_event;
|
2013-11-12 15:55:23 +00:00
|
|
|
widget_class->key_press_event = gtk_popover_key_press;
|
2014-01-09 11:53:29 +00:00
|
|
|
widget_class->grab_focus = gtk_popover_grab_focus;
|
|
|
|
widget_class->focus = gtk_popover_focus;
|
2015-01-09 15:10:29 +00:00
|
|
|
widget_class->show = gtk_popover_show;
|
|
|
|
widget_class->hide = gtk_popover_hide;
|
2017-07-08 10:04:44 +00:00
|
|
|
widget_class->state_flags_changed = gtk_popover_state_flags_changed;
|
|
|
|
|
|
|
|
container_class->add = gtk_popover_add;
|
|
|
|
container_class->remove = gtk_popover_remove;
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2013-11-13 14:11:21 +00:00
|
|
|
/**
|
|
|
|
* GtkPopover:relative-to:
|
|
|
|
*
|
|
|
|
* Sets the attached widget.
|
|
|
|
*/
|
2015-12-02 06:03:35 +00:00
|
|
|
properties[PROP_RELATIVE_TO] =
|
|
|
|
g_param_spec_object ("relative-to",
|
|
|
|
P_("Relative to"),
|
|
|
|
P_("Widget the bubble window points to"),
|
|
|
|
GTK_TYPE_WIDGET,
|
|
|
|
GTK_PARAM_READWRITE);
|
|
|
|
|
2013-11-13 14:11:21 +00:00
|
|
|
/**
|
|
|
|
* GtkPopover:pointing-to:
|
|
|
|
*
|
|
|
|
* Marks a specific rectangle to be pointed.
|
|
|
|
*/
|
2015-12-02 06:03:35 +00:00
|
|
|
properties[PROP_POINTING_TO] =
|
|
|
|
g_param_spec_boxed ("pointing-to",
|
|
|
|
P_("Pointing to"),
|
|
|
|
P_("Rectangle the bubble window points to"),
|
|
|
|
GDK_TYPE_RECTANGLE,
|
|
|
|
GTK_PARAM_READWRITE);
|
|
|
|
|
2013-11-13 14:11:21 +00:00
|
|
|
/**
|
|
|
|
* GtkPopover:position
|
|
|
|
*
|
|
|
|
* Sets the preferred position of the popover.
|
|
|
|
*/
|
2015-12-02 06:03:35 +00:00
|
|
|
properties[PROP_POSITION] =
|
|
|
|
g_param_spec_enum ("position",
|
|
|
|
P_("Position"),
|
|
|
|
P_("Position to place the bubble window"),
|
|
|
|
GTK_TYPE_POSITION_TYPE, GTK_POS_TOP,
|
2015-12-02 06:07:02 +00:00
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.
The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.
This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
2014-01-09 16:21:43 +00:00
|
|
|
|
2014-01-10 11:04:17 +00:00
|
|
|
/**
|
|
|
|
* GtkPopover:modal
|
|
|
|
*
|
2014-01-23 22:41:37 +00:00
|
|
|
* Sets whether the popover is modal (so other elements in the window do not
|
|
|
|
* receive input while the popover is visible).
|
2014-01-10 11:04:17 +00:00
|
|
|
*/
|
2015-12-02 06:03:35 +00:00
|
|
|
properties[PROP_MODAL] =
|
|
|
|
g_param_spec_boolean ("modal",
|
|
|
|
P_("Modal"),
|
|
|
|
P_("Whether the popover is modal"),
|
|
|
|
TRUE,
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
2014-01-10 11:04:17 +00:00
|
|
|
|
2015-12-01 19:56:56 +00:00
|
|
|
/**
|
|
|
|
* GtkPopover:constrain-to:
|
|
|
|
*
|
|
|
|
* Sets a constraint for the popover position.
|
|
|
|
*/
|
2015-12-02 06:03:35 +00:00
|
|
|
properties[PROP_CONSTRAIN_TO] =
|
|
|
|
g_param_spec_enum ("constrain-to",
|
|
|
|
P_("Constraint"),
|
|
|
|
P_("Constraint for the popover position"),
|
|
|
|
GTK_TYPE_POPOVER_CONSTRAINT, GTK_POPOVER_CONSTRAINT_WINDOW,
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
|
|
|
|
|
2014-02-06 14:30:55 +00:00
|
|
|
signals[CLOSED] =
|
|
|
|
g_signal_new (I_("closed"),
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkPopoverClass, closed),
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.
The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.
This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
2014-01-09 16:21:43 +00:00
|
|
|
quark_widget_popovers = g_quark_from_static_string ("gtk-quark-widget-popovers");
|
2014-03-06 23:07:54 +00:00
|
|
|
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_POPOVER_ACCESSIBLE);
|
2017-11-18 03:49:57 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("popover"));
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
2016-09-28 17:53:10 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_update_scrollable (GtkPopover *popover)
|
|
|
|
{
|
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
|
|
|
GtkScrollable *scrollable;
|
|
|
|
|
|
|
|
scrollable = GTK_SCROLLABLE (gtk_widget_get_ancestor (priv->widget,
|
|
|
|
GTK_TYPE_SCROLLABLE));
|
|
|
|
gtk_popover_set_scrollable_full (popover, scrollable);
|
|
|
|
}
|
|
|
|
|
2013-11-13 09:47:13 +00:00
|
|
|
static void
|
|
|
|
_gtk_popover_parent_hierarchy_changed (GtkWidget *widget,
|
|
|
|
GtkWidget *previous_toplevel,
|
|
|
|
GtkPopover *popover)
|
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
2013-11-13 09:47:13 +00:00
|
|
|
GtkWindow *new_window;
|
|
|
|
|
|
|
|
new_window = GTK_WINDOW (gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW));
|
|
|
|
|
|
|
|
if (priv->window == new_window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_object_ref (popover);
|
|
|
|
|
2015-02-03 11:03:22 +00:00
|
|
|
if (gtk_widget_has_grab (GTK_WIDGET (popover)))
|
|
|
|
gtk_popover_apply_modality (popover, FALSE);
|
|
|
|
|
2013-11-13 09:47:13 +00:00
|
|
|
if (priv->window)
|
2014-01-17 17:12:31 +00:00
|
|
|
_gtk_window_remove_popover (priv->window, GTK_WIDGET (popover));
|
2013-11-13 09:47:13 +00:00
|
|
|
|
2016-09-28 17:56:49 +00:00
|
|
|
if (priv->parent_scrollable)
|
|
|
|
gtk_popover_set_scrollable_full (popover, NULL);
|
|
|
|
|
2013-11-13 09:47:13 +00:00
|
|
|
priv->window = new_window;
|
|
|
|
|
|
|
|
if (new_window)
|
2016-05-21 17:43:15 +00:00
|
|
|
{
|
|
|
|
_gtk_window_add_popover (new_window, GTK_WIDGET (popover), priv->widget, TRUE);
|
2016-09-28 17:56:49 +00:00
|
|
|
gtk_popover_update_scrollable (popover);
|
2016-05-21 17:43:15 +00:00
|
|
|
gtk_popover_update_position (popover);
|
|
|
|
}
|
2013-11-13 09:47:13 +00:00
|
|
|
|
|
|
|
if (gtk_widget_is_visible (GTK_WIDGET (popover)))
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (popover));
|
popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.
The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.
This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
2014-01-09 16:21:43 +00:00
|
|
|
|
|
|
|
g_object_unref (popover);
|
2013-11-13 09:47:13 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 15:18:48 +00:00
|
|
|
static void
|
|
|
|
_popover_propagate_state (GtkPopover *popover,
|
|
|
|
GtkStateFlags state,
|
|
|
|
GtkStateFlags old_state,
|
|
|
|
GtkStateFlags flag)
|
|
|
|
{
|
|
|
|
if ((state & flag) != (old_state & flag))
|
|
|
|
{
|
|
|
|
if ((state & flag) == flag)
|
|
|
|
gtk_widget_set_state_flags (GTK_WIDGET (popover), flag, FALSE);
|
|
|
|
else
|
|
|
|
gtk_widget_unset_state_flags (GTK_WIDGET (popover), flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_popover_parent_state_changed (GtkWidget *widget,
|
|
|
|
GtkStateFlags old_state,
|
|
|
|
GtkPopover *popover)
|
|
|
|
{
|
|
|
|
guint state;
|
|
|
|
|
|
|
|
state = gtk_widget_get_state_flags (widget);
|
|
|
|
_popover_propagate_state (popover, state, old_state,
|
|
|
|
GTK_STATE_FLAG_INSENSITIVE);
|
|
|
|
_popover_propagate_state (popover, state, old_state,
|
|
|
|
GTK_STATE_FLAG_BACKDROP);
|
|
|
|
}
|
|
|
|
|
2014-02-07 15:14:23 +00:00
|
|
|
static void
|
|
|
|
_gtk_popover_parent_grab_notify (GtkWidget *widget,
|
|
|
|
gboolean was_shadowed,
|
|
|
|
GtkPopover *popover)
|
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
2014-02-07 15:14:23 +00:00
|
|
|
|
|
|
|
if (priv->modal &&
|
|
|
|
gtk_widget_is_visible (GTK_WIDGET (popover)) &&
|
|
|
|
!gtk_widget_has_grab (GTK_WIDGET (popover)))
|
2015-06-12 13:05:33 +00:00
|
|
|
{
|
|
|
|
GtkWidget *grab_widget;
|
|
|
|
|
|
|
|
grab_widget = gtk_grab_get_current ();
|
|
|
|
|
|
|
|
if (!grab_widget || !GTK_IS_POPOVER (grab_widget))
|
2016-08-10 16:28:14 +00:00
|
|
|
gtk_popover_popdown (popover);
|
2015-06-12 13:05:33 +00:00
|
|
|
}
|
2014-02-07 15:14:23 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 09:47:13 +00:00
|
|
|
static void
|
|
|
|
_gtk_popover_parent_unmap (GtkWidget *widget,
|
|
|
|
GtkPopover *popover)
|
|
|
|
{
|
2015-01-09 15:10:29 +00:00
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
|
|
|
|
|
|
|
if (priv->state == STATE_SHOWING)
|
|
|
|
priv->visible = FALSE;
|
|
|
|
else if (priv->state == STATE_SHOWN)
|
|
|
|
gtk_popover_set_state (popover, STATE_HIDING);
|
2013-11-13 09:47:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-11 07:58:21 +00:00
|
|
|
_gtk_popover_parent_size_allocate (GtkWidget *widget,
|
|
|
|
const GtkAllocation *allocation,
|
|
|
|
int baseline,
|
|
|
|
GtkAllocation *out_clip,
|
|
|
|
GtkPopover *popover)
|
2013-11-13 09:47:13 +00:00
|
|
|
{
|
|
|
|
gtk_popover_update_position (popover);
|
|
|
|
}
|
|
|
|
|
2014-03-06 17:59:40 +00:00
|
|
|
static void
|
|
|
|
_unmanage_popover (GObject *object)
|
|
|
|
{
|
2014-09-15 12:05:43 +00:00
|
|
|
gtk_popover_update_relative_to (GTK_POPOVER (object), NULL);
|
2014-03-06 17:59:40 +00:00
|
|
|
g_object_unref (object);
|
|
|
|
}
|
|
|
|
|
popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.
The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.
This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
2014-01-09 16:21:43 +00:00
|
|
|
static void
|
|
|
|
widget_manage_popover (GtkWidget *widget,
|
|
|
|
GtkPopover *popover)
|
|
|
|
{
|
|
|
|
GHashTable *popovers;
|
|
|
|
|
|
|
|
popovers = g_object_get_qdata (G_OBJECT (widget), quark_widget_popovers);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!popovers))
|
|
|
|
{
|
|
|
|
popovers = g_hash_table_new_full (NULL, NULL,
|
2014-03-06 17:59:40 +00:00
|
|
|
(GDestroyNotify) _unmanage_popover, NULL);
|
popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.
The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.
This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
2014-01-09 16:21:43 +00:00
|
|
|
g_object_set_qdata_full (G_OBJECT (widget),
|
|
|
|
quark_widget_popovers, popovers,
|
|
|
|
(GDestroyNotify) g_hash_table_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_add (popovers, g_object_ref_sink (popover));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
widget_unmanage_popover (GtkWidget *widget,
|
|
|
|
GtkPopover *popover)
|
|
|
|
{
|
|
|
|
GHashTable *popovers;
|
|
|
|
|
|
|
|
popovers = g_object_get_qdata (G_OBJECT (widget), quark_widget_popovers);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!popovers))
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_hash_table_remove (popovers, popover);
|
|
|
|
}
|
|
|
|
|
2014-01-22 15:43:37 +00:00
|
|
|
static void
|
|
|
|
adjustment_changed_cb (GtkAdjustment *adjustment,
|
|
|
|
GtkPopover *popover)
|
|
|
|
{
|
|
|
|
gtk_popover_update_position (popover);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_popover_set_scrollable (GtkPopover *popover,
|
|
|
|
GtkScrollable *scrollable)
|
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
2014-01-22 15:43:37 +00:00
|
|
|
|
|
|
|
if (priv->parent_scrollable)
|
|
|
|
{
|
|
|
|
if (priv->vadj)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_data (priv->vadj, popover);
|
|
|
|
g_object_unref (priv->vadj);
|
|
|
|
priv->vadj = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->hadj)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_data (priv->hadj, popover);
|
|
|
|
g_object_unref (priv->hadj);
|
|
|
|
priv->hadj = NULL;
|
|
|
|
}
|
2015-02-05 13:17:51 +00:00
|
|
|
|
|
|
|
g_object_unref (priv->parent_scrollable);
|
2014-01-22 15:43:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
priv->parent_scrollable = scrollable;
|
|
|
|
|
|
|
|
if (scrollable)
|
|
|
|
{
|
2015-02-05 13:17:51 +00:00
|
|
|
g_object_ref (scrollable);
|
2014-01-22 15:43:37 +00:00
|
|
|
priv->vadj = gtk_scrollable_get_vadjustment (scrollable);
|
|
|
|
priv->hadj = gtk_scrollable_get_hadjustment (scrollable);
|
|
|
|
|
|
|
|
if (priv->vadj)
|
|
|
|
{
|
|
|
|
g_object_ref (priv->vadj);
|
|
|
|
g_signal_connect (priv->vadj, "changed",
|
|
|
|
G_CALLBACK (adjustment_changed_cb), popover);
|
|
|
|
g_signal_connect (priv->vadj, "value-changed",
|
|
|
|
G_CALLBACK (adjustment_changed_cb), popover);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->hadj)
|
|
|
|
{
|
|
|
|
g_object_ref (priv->hadj);
|
|
|
|
g_signal_connect (priv->hadj, "changed",
|
|
|
|
G_CALLBACK (adjustment_changed_cb), popover);
|
|
|
|
g_signal_connect (priv->hadj, "value-changed",
|
|
|
|
G_CALLBACK (adjustment_changed_cb), popover);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
scrollable_notify_cb (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkPopover *popover)
|
|
|
|
{
|
|
|
|
if (pspec->value_type == GTK_TYPE_ADJUSTMENT)
|
|
|
|
_gtk_popover_set_scrollable (popover, GTK_SCROLLABLE (object));
|
|
|
|
}
|
|
|
|
|
2016-09-28 17:53:10 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_set_scrollable_full (GtkPopover *popover,
|
|
|
|
GtkScrollable *scrollable)
|
|
|
|
{
|
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
|
|
|
|
|
|
|
if (priv->scrollable_notify_id != 0 &&
|
|
|
|
g_signal_handler_is_connected (priv->parent_scrollable, priv->scrollable_notify_id))
|
|
|
|
{
|
|
|
|
g_signal_handler_disconnect (priv->parent_scrollable, priv->scrollable_notify_id);
|
|
|
|
priv->scrollable_notify_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_gtk_popover_set_scrollable (popover, scrollable);
|
|
|
|
|
|
|
|
if (scrollable)
|
|
|
|
{
|
|
|
|
priv->scrollable_notify_id =
|
|
|
|
g_signal_connect (priv->parent_scrollable, "notify",
|
|
|
|
G_CALLBACK (scrollable_notify_cb), popover);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_update_relative_to (GtkPopover *popover,
|
|
|
|
GtkWidget *relative_to)
|
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2013-11-11 13:27:19 +00:00
|
|
|
if (priv->widget == relative_to)
|
2013-01-11 16:32:08 +00:00
|
|
|
return;
|
|
|
|
|
popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.
The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.
This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
2014-01-09 16:21:43 +00:00
|
|
|
g_object_ref (popover);
|
|
|
|
|
2013-11-11 09:36:51 +00:00
|
|
|
if (priv->window)
|
|
|
|
{
|
2014-01-17 17:12:31 +00:00
|
|
|
_gtk_window_remove_popover (priv->window, GTK_WIDGET (popover));
|
2013-11-11 09:36:51 +00:00
|
|
|
priv->window = NULL;
|
|
|
|
}
|
|
|
|
|
2014-12-02 14:44:04 +00:00
|
|
|
popover_unset_prev_focus (popover);
|
2014-09-15 12:05:43 +00:00
|
|
|
|
2013-11-13 09:47:13 +00:00
|
|
|
if (priv->widget)
|
|
|
|
{
|
|
|
|
if (g_signal_handler_is_connected (priv->widget, priv->hierarchy_changed_id))
|
|
|
|
g_signal_handler_disconnect (priv->widget, priv->hierarchy_changed_id);
|
|
|
|
if (g_signal_handler_is_connected (priv->widget, priv->size_allocate_id))
|
|
|
|
g_signal_handler_disconnect (priv->widget, priv->size_allocate_id);
|
|
|
|
if (g_signal_handler_is_connected (priv->widget, priv->unmap_id))
|
|
|
|
g_signal_handler_disconnect (priv->widget, priv->unmap_id);
|
2014-02-07 15:18:48 +00:00
|
|
|
if (g_signal_handler_is_connected (priv->widget, priv->state_changed_id))
|
|
|
|
g_signal_handler_disconnect (priv->widget, priv->state_changed_id);
|
2014-02-07 15:14:23 +00:00
|
|
|
if (g_signal_handler_is_connected (priv->widget, priv->grab_notify_id))
|
|
|
|
g_signal_handler_disconnect (priv->widget, priv->grab_notify_id);
|
popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.
The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.
This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
2014-01-09 16:21:43 +00:00
|
|
|
|
|
|
|
widget_unmanage_popover (priv->widget, popover);
|
2013-11-13 09:47:13 +00:00
|
|
|
}
|
|
|
|
|
2014-01-22 15:43:37 +00:00
|
|
|
if (priv->parent_scrollable)
|
2016-09-28 17:53:10 +00:00
|
|
|
gtk_popover_set_scrollable_full (popover, NULL);
|
2014-01-22 15:43:37 +00:00
|
|
|
|
2013-11-11 13:27:19 +00:00
|
|
|
priv->widget = relative_to;
|
2015-12-02 06:03:35 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (popover), properties[PROP_RELATIVE_TO]);
|
2013-11-11 09:36:51 +00:00
|
|
|
|
2013-11-11 13:27:19 +00:00
|
|
|
if (priv->widget)
|
2013-11-13 09:47:13 +00:00
|
|
|
{
|
|
|
|
priv->window =
|
|
|
|
GTK_WINDOW (gtk_widget_get_ancestor (priv->widget, GTK_TYPE_WINDOW));
|
|
|
|
|
|
|
|
priv->hierarchy_changed_id =
|
|
|
|
g_signal_connect (priv->widget, "hierarchy-changed",
|
|
|
|
G_CALLBACK (_gtk_popover_parent_hierarchy_changed),
|
|
|
|
popover);
|
|
|
|
priv->size_allocate_id =
|
|
|
|
g_signal_connect (priv->widget, "size-allocate",
|
|
|
|
G_CALLBACK (_gtk_popover_parent_size_allocate),
|
|
|
|
popover);
|
|
|
|
priv->unmap_id =
|
|
|
|
g_signal_connect (priv->widget, "unmap",
|
|
|
|
G_CALLBACK (_gtk_popover_parent_unmap),
|
|
|
|
popover);
|
2014-02-07 15:18:48 +00:00
|
|
|
priv->state_changed_id =
|
|
|
|
g_signal_connect (priv->widget, "state-flags-changed",
|
|
|
|
G_CALLBACK (_gtk_popover_parent_state_changed),
|
|
|
|
popover);
|
2014-02-07 15:14:23 +00:00
|
|
|
priv->grab_notify_id =
|
|
|
|
g_signal_connect (priv->widget, "grab-notify",
|
|
|
|
G_CALLBACK (_gtk_popover_parent_grab_notify),
|
|
|
|
popover);
|
popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.
The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.
This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
2014-01-09 16:21:43 +00:00
|
|
|
|
|
|
|
/* Give ownership of the popover to widget */
|
|
|
|
widget_manage_popover (priv->widget, popover);
|
2013-11-13 09:47:13 +00:00
|
|
|
}
|
2013-11-11 09:36:51 +00:00
|
|
|
|
|
|
|
if (priv->window)
|
2015-07-06 14:39:06 +00:00
|
|
|
_gtk_window_add_popover (priv->window, GTK_WIDGET (popover), priv->widget, TRUE);
|
2013-11-12 15:55:23 +00:00
|
|
|
|
2016-09-28 17:53:10 +00:00
|
|
|
if (priv->widget)
|
|
|
|
gtk_popover_update_scrollable (popover);
|
2014-01-22 15:43:37 +00:00
|
|
|
|
2014-05-12 20:25:25 +00:00
|
|
|
_gtk_widget_update_parent_muxer (GTK_WIDGET (popover));
|
popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.
The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.
This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
2014-01-09 16:21:43 +00:00
|
|
|
g_object_unref (popover);
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-02-04 21:33:25 +00:00
|
|
|
gtk_popover_update_pointing_to (GtkPopover *popover,
|
|
|
|
const GdkRectangle *pointing_to)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2014-02-09 06:22:07 +00:00
|
|
|
GtkPopoverPrivate *priv = popover->priv;
|
2013-11-12 11:56:40 +00:00
|
|
|
|
|
|
|
if (pointing_to)
|
|
|
|
{
|
|
|
|
priv->pointing_to = *pointing_to;
|
|
|
|
priv->has_pointing_to = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
priv->has_pointing_to = FALSE;
|
|
|
|
|
2015-12-02 06:03:35 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (popover), properties[PROP_POINTING_TO]);
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_update_preferred_position (GtkPopover *popover,
|
|
|
|
GtkPositionType position)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2015-12-02 06:03:35 +00:00
|
|
|
if (popover->priv->preferred_position == position)
|
|
|
|
return;
|
|
|
|
|
|
|
|
popover->priv->preferred_position = position;
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (popover), properties[PROP_POSITION]);
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 14:11:21 +00:00
|
|
|
/**
|
2013-11-12 15:55:23 +00:00
|
|
|
* gtk_popover_new:
|
2014-03-17 23:13:53 +00:00
|
|
|
* @relative_to: (allow-none): #GtkWidget the popover is related to
|
2013-01-11 16:32:08 +00:00
|
|
|
*
|
2013-11-13 14:11:21 +00:00
|
|
|
* Creates a new popover to point to @relative_to
|
2013-01-11 16:32:08 +00:00
|
|
|
*
|
2013-11-12 15:55:23 +00:00
|
|
|
* Returns: a new #GtkPopover
|
2013-11-13 14:11:21 +00:00
|
|
|
**/
|
2013-01-11 16:32:08 +00:00
|
|
|
GtkWidget *
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_new (GtkWidget *relative_to)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2014-02-18 13:38:30 +00:00
|
|
|
g_return_val_if_fail (relative_to == NULL || GTK_IS_WIDGET (relative_to), NULL);
|
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
return g_object_new (GTK_TYPE_POPOVER,
|
2013-11-11 13:27:19 +00:00
|
|
|
"relative-to", relative_to,
|
|
|
|
NULL);
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 14:11:21 +00:00
|
|
|
/**
|
2013-11-12 15:55:23 +00:00
|
|
|
* gtk_popover_set_relative_to:
|
2013-11-13 14:11:21 +00:00
|
|
|
* @popover: a #GtkPopover
|
2014-03-17 23:13:53 +00:00
|
|
|
* @relative_to: (allow-none): a #GtkWidget
|
2013-01-11 16:32:08 +00:00
|
|
|
*
|
2013-11-13 14:11:21 +00:00
|
|
|
* Sets a new widget to be attached to @popover. If @popover is
|
|
|
|
* visible, the position will be updated.
|
2013-01-11 16:32:08 +00:00
|
|
|
*
|
2014-02-18 13:38:30 +00:00
|
|
|
* Note: the ownership of popovers is always given to their @relative_to
|
|
|
|
* widget, so if @relative_to is set to %NULL on an attached @popover, it
|
|
|
|
* will be detached from its previous widget, and consequently destroyed
|
|
|
|
* unless extra references are kept.
|
2013-11-13 14:11:21 +00:00
|
|
|
**/
|
2013-01-11 16:32:08 +00:00
|
|
|
void
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_set_relative_to (GtkPopover *popover,
|
|
|
|
GtkWidget *relative_to)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2013-11-12 15:55:23 +00:00
|
|
|
g_return_if_fail (GTK_IS_POPOVER (popover));
|
2014-02-18 13:38:30 +00:00
|
|
|
g_return_if_fail (relative_to == NULL || GTK_IS_WIDGET (relative_to));
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_update_relative_to (popover, relative_to);
|
2014-02-18 13:38:30 +00:00
|
|
|
|
|
|
|
if (relative_to)
|
|
|
|
gtk_popover_update_position (popover);
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 14:11:21 +00:00
|
|
|
/**
|
2013-11-12 15:55:23 +00:00
|
|
|
* gtk_popover_get_relative_to:
|
2013-11-13 14:11:21 +00:00
|
|
|
* @popover: a #GtkPopover
|
2013-01-11 16:32:08 +00:00
|
|
|
*
|
2014-02-18 03:30:58 +00:00
|
|
|
* Returns the widget @popover is currently attached to
|
2013-01-11 16:32:08 +00:00
|
|
|
*
|
2014-01-22 15:27:44 +00:00
|
|
|
* Returns: (transfer none): a #GtkWidget
|
2013-11-13 14:11:21 +00:00
|
|
|
**/
|
2013-11-11 13:27:19 +00:00
|
|
|
GtkWidget *
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_get_relative_to (GtkPopover *popover)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2013-11-12 15:55:23 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_POPOVER (popover), NULL);
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2014-02-09 06:22:07 +00:00
|
|
|
return popover->priv->widget;
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 14:11:21 +00:00
|
|
|
/**
|
2013-11-12 15:55:23 +00:00
|
|
|
* gtk_popover_set_pointing_to:
|
2013-11-13 14:11:21 +00:00
|
|
|
* @popover: a #GtkPopover
|
2013-01-11 16:32:08 +00:00
|
|
|
* @rect: rectangle to point to
|
|
|
|
*
|
2014-02-18 03:37:55 +00:00
|
|
|
* Sets the rectangle that @popover will point to, in the
|
|
|
|
* coordinate space of the widget @popover is attached to,
|
|
|
|
* see gtk_popover_set_relative_to().
|
2013-11-13 14:11:21 +00:00
|
|
|
**/
|
2013-01-11 16:32:08 +00:00
|
|
|
void
|
2014-02-09 03:18:15 +00:00
|
|
|
gtk_popover_set_pointing_to (GtkPopover *popover,
|
2014-02-04 21:33:25 +00:00
|
|
|
const GdkRectangle *rect)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2013-11-12 15:55:23 +00:00
|
|
|
g_return_if_fail (GTK_IS_POPOVER (popover));
|
2013-01-11 16:32:08 +00:00
|
|
|
g_return_if_fail (rect != NULL);
|
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_update_pointing_to (popover, rect);
|
|
|
|
gtk_popover_update_position (popover);
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 14:11:21 +00:00
|
|
|
/**
|
2013-11-12 15:55:23 +00:00
|
|
|
* gtk_popover_get_pointing_to:
|
2013-11-13 14:11:21 +00:00
|
|
|
* @popover: a #GtkPopover
|
2013-01-11 16:32:08 +00:00
|
|
|
* @rect: (out): location to store the rectangle
|
|
|
|
*
|
2013-11-13 14:11:21 +00:00
|
|
|
* If a rectangle to point to has been set, this function will
|
|
|
|
* return %TRUE and fill in @rect with such rectangle, otherwise
|
|
|
|
* it will return %FALSE and fill in @rect with the attached
|
|
|
|
* widget coordinates.
|
2013-01-11 16:32:08 +00:00
|
|
|
*
|
2013-11-13 14:11:21 +00:00
|
|
|
* Returns: %TRUE if a rectangle to point to was set.
|
|
|
|
**/
|
2013-01-11 16:32:08 +00:00
|
|
|
gboolean
|
2014-02-04 21:33:25 +00:00
|
|
|
gtk_popover_get_pointing_to (GtkPopover *popover,
|
|
|
|
GdkRectangle *rect)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2016-08-09 17:29:41 +00:00
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_POPOVER (popover), FALSE);
|
2017-06-03 12:38:56 +00:00
|
|
|
g_return_val_if_fail (rect != NULL, FALSE);
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2017-06-03 12:38:56 +00:00
|
|
|
if (priv->has_pointing_to)
|
|
|
|
*rect = priv->pointing_to;
|
2017-08-03 09:03:39 +00:00
|
|
|
else if (priv->widget)
|
|
|
|
gtk_widget_get_own_allocation (priv->widget, rect);
|
2013-01-11 16:32:08 +00:00
|
|
|
|
|
|
|
return priv->has_pointing_to;
|
|
|
|
}
|
|
|
|
|
2013-11-13 14:11:21 +00:00
|
|
|
/**
|
2013-11-12 15:55:23 +00:00
|
|
|
* gtk_popover_set_position:
|
2013-11-13 14:11:21 +00:00
|
|
|
* @popover: a #GtkPopover
|
|
|
|
* @position: preferred popover position
|
2013-01-11 16:32:08 +00:00
|
|
|
*
|
2013-11-13 14:11:21 +00:00
|
|
|
* Sets the preferred position for @popover to appear. If the @popover
|
|
|
|
* is currently visible, it will be immediately updated.
|
2013-01-11 16:32:08 +00:00
|
|
|
*
|
2014-02-02 06:22:14 +00:00
|
|
|
* This preference will be respected where possible, although
|
|
|
|
* on lack of space (eg. if close to the window edges), the
|
|
|
|
* #GtkPopover may choose to appear on the opposite side
|
2013-11-13 14:11:21 +00:00
|
|
|
**/
|
2013-01-11 16:32:08 +00:00
|
|
|
void
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_set_position (GtkPopover *popover,
|
|
|
|
GtkPositionType position)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2013-11-12 15:55:23 +00:00
|
|
|
g_return_if_fail (GTK_IS_POPOVER (popover));
|
2013-01-11 16:32:08 +00:00
|
|
|
g_return_if_fail (position >= GTK_POS_LEFT && position <= GTK_POS_BOTTOM);
|
|
|
|
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_update_preferred_position (popover, position);
|
|
|
|
gtk_popover_update_position (popover);
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 14:11:21 +00:00
|
|
|
/**
|
2013-11-12 15:55:23 +00:00
|
|
|
* gtk_popover_get_position:
|
2013-11-13 14:11:21 +00:00
|
|
|
* @popover: a #GtkPopover
|
2013-01-11 16:32:08 +00:00
|
|
|
*
|
2013-11-13 14:11:21 +00:00
|
|
|
* Returns the preferred position of @popover.
|
2013-01-11 16:32:08 +00:00
|
|
|
*
|
2013-11-13 14:11:21 +00:00
|
|
|
* Returns: The preferred position.
|
|
|
|
**/
|
2013-01-11 16:32:08 +00:00
|
|
|
GtkPositionType
|
2013-11-12 15:55:23 +00:00
|
|
|
gtk_popover_get_position (GtkPopover *popover)
|
2013-01-11 16:32:08 +00:00
|
|
|
{
|
2013-11-12 15:55:23 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_POPOVER (popover), GTK_POS_TOP);
|
2013-01-11 16:32:08 +00:00
|
|
|
|
2014-02-09 05:48:38 +00:00
|
|
|
return popover->priv->preferred_position;
|
2013-01-11 16:32:08 +00:00
|
|
|
}
|
2014-01-10 11:04:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_popover_set_modal:
|
|
|
|
* @popover: a #GtkPopover
|
|
|
|
* @modal: #TRUE to make popover claim all input within the toplevel
|
|
|
|
*
|
|
|
|
* Sets whether @popover is modal, a modal popover will grab all input
|
|
|
|
* within the toplevel and grab the keyboard focus on it when being
|
|
|
|
* displayed. Clicking outside the popover area or pressing Esc will
|
|
|
|
* dismiss the popover and ungrab input.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_popover_set_modal (GtkPopover *popover,
|
|
|
|
gboolean modal)
|
|
|
|
{
|
2016-08-09 17:29:41 +00:00
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
2014-01-10 11:04:17 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_POPOVER (popover));
|
|
|
|
|
2014-02-09 06:22:07 +00:00
|
|
|
modal = modal != FALSE;
|
2014-02-09 05:48:38 +00:00
|
|
|
|
|
|
|
if (priv->modal == modal)
|
2014-01-10 11:04:17 +00:00
|
|
|
return;
|
|
|
|
|
2014-02-09 05:48:38 +00:00
|
|
|
priv->modal = modal;
|
2014-01-10 11:04:17 +00:00
|
|
|
|
|
|
|
if (gtk_widget_is_visible (GTK_WIDGET (popover)))
|
2014-01-10 14:23:12 +00:00
|
|
|
gtk_popover_apply_modality (popover, priv->modal);
|
2014-01-10 11:04:17 +00:00
|
|
|
|
2015-12-02 06:03:35 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (popover), properties[PROP_MODAL]);
|
2014-01-10 11:04:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_popover_get_modal:
|
|
|
|
* @popover: a #GtkPopover
|
|
|
|
*
|
|
|
|
* Returns whether the popover is modal, see gtk_popover_set_modal to
|
|
|
|
* see the implications of this.
|
|
|
|
*
|
|
|
|
* Returns: #TRUE if @popover is modal
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_popover_get_modal (GtkPopover *popover)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_POPOVER (popover), FALSE);
|
|
|
|
|
2014-02-09 05:48:38 +00:00
|
|
|
return popover->priv->modal;
|
2014-01-10 11:04:17 +00:00
|
|
|
}
|
2014-02-04 19:45:53 +00:00
|
|
|
|
2014-02-07 19:51:49 +00:00
|
|
|
static void
|
|
|
|
back_to_main (GtkWidget *popover)
|
|
|
|
{
|
|
|
|
GtkWidget *stack;
|
|
|
|
|
|
|
|
stack = gtk_bin_get_child (GTK_BIN (popover));
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (stack), "main");
|
|
|
|
}
|
|
|
|
|
2014-02-16 21:10:55 +00:00
|
|
|
/**
|
|
|
|
* gtk_popover_bind_model:
|
|
|
|
* @popover: a #GtkPopover
|
|
|
|
* @model: (allow-none): the #GMenuModel to bind to or %NULL to remove
|
|
|
|
* binding
|
|
|
|
* @action_namespace: (allow-none): the namespace for actions in @model
|
|
|
|
*
|
|
|
|
* Establishes a binding between a #GtkPopover and a #GMenuModel.
|
|
|
|
*
|
|
|
|
* The contents of @popover are removed and then refilled with menu items
|
|
|
|
* according to @model. When @model changes, @popover is updated.
|
|
|
|
* Calling this function twice on @popover with different @model will
|
|
|
|
* cause the first binding to be replaced with a binding to the new
|
|
|
|
* model. If @model is %NULL then any previous binding is undone and
|
|
|
|
* all children are removed.
|
|
|
|
*
|
|
|
|
* If @action_namespace is non-%NULL then the effect is as if all
|
|
|
|
* actions mentioned in the @model have their names prefixed with the
|
|
|
|
* namespace, plus a dot. For example, if the action “quit” is
|
|
|
|
* mentioned and @action_namespace is “app” then the effective action
|
|
|
|
* name is “app.quit”.
|
|
|
|
*
|
|
|
|
* This function uses #GtkActionable to define the action name and
|
|
|
|
* target values on the created menu items. If you want to use an
|
|
|
|
* action group other than “app” and “win”, or if you want to use a
|
|
|
|
* #GtkMenuShell outside of a #GtkApplicationWindow, then you will need
|
|
|
|
* to attach your own action group to the widget hierarchy using
|
|
|
|
* gtk_widget_insert_action_group(). As an example, if you created a
|
|
|
|
* group with a “quit” action and inserted it with the name “mygroup”
|
|
|
|
* then you would use the action name “mygroup.quit” in your
|
|
|
|
* #GMenuModel.
|
|
|
|
*/
|
|
|
|
void
|
2014-02-07 19:51:49 +00:00
|
|
|
gtk_popover_bind_model (GtkPopover *popover,
|
|
|
|
GMenuModel *model,
|
2014-02-17 11:50:25 +00:00
|
|
|
const gchar *action_namespace)
|
2014-02-07 19:51:49 +00:00
|
|
|
{
|
|
|
|
GtkWidget *child;
|
|
|
|
GtkWidget *stack;
|
2017-02-26 15:02:49 +00:00
|
|
|
GtkStyleContext *style_context;
|
2014-02-07 19:51:49 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_POPOVER (popover));
|
|
|
|
g_return_if_fail (model == NULL || G_IS_MENU_MODEL (model));
|
|
|
|
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (popover));
|
|
|
|
if (child)
|
2014-04-28 15:55:52 +00:00
|
|
|
gtk_widget_destroy (child);
|
|
|
|
|
2017-07-08 10:04:44 +00:00
|
|
|
style_context = gtk_widget_get_style_context (popover->priv->contents_widget);
|
2017-02-26 15:02:49 +00:00
|
|
|
|
2014-02-07 19:51:49 +00:00
|
|
|
if (model)
|
|
|
|
{
|
|
|
|
stack = gtk_stack_new ();
|
2014-10-26 19:03:58 +00:00
|
|
|
gtk_stack_set_vhomogeneous (GTK_STACK (stack), FALSE);
|
2014-02-07 19:51:49 +00:00
|
|
|
gtk_stack_set_transition_type (GTK_STACK (stack), GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT);
|
2015-07-19 15:40:28 +00:00
|
|
|
gtk_stack_set_interpolate_size (GTK_STACK (stack), TRUE);
|
2014-02-07 19:51:49 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (popover), stack);
|
|
|
|
|
2015-03-17 18:34:43 +00:00
|
|
|
gtk_menu_section_box_new_toplevel (GTK_STACK (stack),
|
|
|
|
model,
|
|
|
|
action_namespace,
|
|
|
|
popover);
|
2014-04-28 15:55:52 +00:00
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (stack), "main");
|
2014-02-07 19:51:49 +00:00
|
|
|
|
|
|
|
g_signal_connect (popover, "unmap", G_CALLBACK (back_to_main), NULL);
|
|
|
|
g_signal_connect (popover, "map", G_CALLBACK (back_to_main), NULL);
|
2017-02-26 15:02:49 +00:00
|
|
|
|
|
|
|
gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENU);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_style_context_remove_class (style_context, GTK_STYLE_CLASS_MENU);
|
2014-02-07 19:51:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_popover_new_from_model:
|
2014-02-20 15:10:34 +00:00
|
|
|
* @relative_to: (allow-none): #GtkWidget the popover is related to
|
2014-02-07 19:51:49 +00:00
|
|
|
* @model: a #GMenuModel
|
|
|
|
*
|
|
|
|
* Creates a #GtkPopover and populates it according to
|
2014-02-17 11:50:25 +00:00
|
|
|
* @model. The popover is pointed to the @relative_to widget.
|
2014-02-07 19:51:49 +00:00
|
|
|
*
|
|
|
|
* The created buttons are connected to actions found in the
|
|
|
|
* #GtkApplicationWindow to which the popover belongs - typically
|
|
|
|
* by means of being attached to a widget that is contained within
|
|
|
|
* the #GtkApplicationWindows widget hierarchy.
|
|
|
|
*
|
|
|
|
* Actions can also be added using gtk_widget_insert_action_group()
|
|
|
|
* on the menus attach widget or on any of its parent widgets.
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: the new #GtkPopover
|
2014-02-07 19:51:49 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_popover_new_from_model (GtkWidget *relative_to,
|
|
|
|
GMenuModel *model)
|
|
|
|
{
|
|
|
|
GtkWidget *popover;
|
|
|
|
|
2014-02-18 13:38:30 +00:00
|
|
|
g_return_val_if_fail (relative_to == NULL || GTK_IS_WIDGET (relative_to), NULL);
|
2014-02-07 19:51:49 +00:00
|
|
|
g_return_val_if_fail (G_IS_MENU_MODEL (model), NULL);
|
|
|
|
|
|
|
|
popover = gtk_popover_new (relative_to);
|
2014-02-17 11:50:25 +00:00
|
|
|
gtk_popover_bind_model (GTK_POPOVER (popover), model, NULL);
|
2014-02-07 19:51:49 +00:00
|
|
|
|
|
|
|
return popover;
|
|
|
|
}
|
2015-04-17 04:10:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_popover_set_default_widget:
|
|
|
|
* @popover: a #GtkPopover
|
|
|
|
* @widget: (allow-none): the new default widget, or %NULL
|
|
|
|
*
|
|
|
|
* Sets the widget that should be set as default widget while
|
|
|
|
* the popover is shown (see gtk_window_set_default()). #GtkPopover
|
|
|
|
* remembers the previous default widget and reestablishes it
|
|
|
|
* when the popover is dismissed.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_popover_set_default_widget (GtkPopover *popover,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
2016-08-09 17:29:41 +00:00
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
2015-04-17 04:10:06 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_POPOVER (popover));
|
|
|
|
g_return_if_fail (widget == NULL || gtk_widget_get_can_default (widget));
|
|
|
|
|
|
|
|
if (priv->default_widget == widget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (priv->default_widget)
|
|
|
|
g_object_unref (priv->default_widget);
|
|
|
|
|
|
|
|
priv->default_widget = widget;
|
|
|
|
|
|
|
|
if (priv->default_widget)
|
|
|
|
g_object_ref (priv->default_widget);
|
|
|
|
|
|
|
|
if (gtk_widget_get_mapped (GTK_WIDGET (popover)))
|
|
|
|
gtk_window_set_default (priv->window, priv->default_widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_popover_get_default_widget:
|
|
|
|
* @popover: a #GtkPopover
|
|
|
|
*
|
|
|
|
* Gets the widget that should be set as the default while
|
|
|
|
* the popover is shown.
|
|
|
|
*
|
2015-12-28 20:14:08 +00:00
|
|
|
* Returns: (nullable) (transfer none): the default widget,
|
|
|
|
* or %NULL if there is none
|
2015-04-17 04:10:06 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_popover_get_default_widget (GtkPopover *popover)
|
|
|
|
{
|
2016-08-09 17:29:41 +00:00
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
2015-04-17 04:10:06 +00:00
|
|
|
|
2015-05-04 13:27:02 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_POPOVER (popover), NULL);
|
2015-04-17 04:10:06 +00:00
|
|
|
|
|
|
|
return priv->default_widget;
|
|
|
|
}
|
2015-12-01 19:56:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_popover_set_constrain_to:
|
|
|
|
* @popover: a #GtkPopover
|
|
|
|
* @constraint: the new constraint
|
|
|
|
*
|
|
|
|
* Sets a constraint for positioning this popover.
|
|
|
|
*
|
|
|
|
* Note that not all platforms support placing popovers freely,
|
|
|
|
* and may already impose constraints.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_popover_set_constrain_to (GtkPopover *popover,
|
|
|
|
GtkPopoverConstraint constraint)
|
|
|
|
{
|
2016-08-09 17:29:41 +00:00
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
2015-12-01 19:56:56 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_POPOVER (popover));
|
|
|
|
|
|
|
|
if (priv->constraint == constraint)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->constraint = constraint;
|
|
|
|
gtk_popover_update_position (popover);
|
|
|
|
|
2015-12-02 06:03:35 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (popover), properties[PROP_CONSTRAIN_TO]);
|
2015-12-01 19:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_popover_get_constrain_to:
|
|
|
|
* @popover: a #GtkPopover
|
|
|
|
*
|
|
|
|
* Returns the constraint for placing this popover.
|
|
|
|
* See gtk_popover_set_constrain_to().
|
|
|
|
*
|
|
|
|
* Returns: the constraint for placing this popover.
|
|
|
|
*/
|
|
|
|
GtkPopoverConstraint
|
|
|
|
gtk_popover_get_constrain_to (GtkPopover *popover)
|
|
|
|
{
|
2016-08-09 17:29:41 +00:00
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
2015-12-01 19:56:56 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_POPOVER (popover), GTK_POPOVER_CONSTRAINT_WINDOW);
|
|
|
|
|
|
|
|
return priv->constraint;
|
|
|
|
}
|
2016-08-10 16:28:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_popover_popup:
|
|
|
|
* @popover: a #GtkPopover
|
|
|
|
*
|
|
|
|
* Pops @popover up. This is different than a gtk_widget_show() call
|
|
|
|
* in that it shows the popover with a transition. If you want to show
|
|
|
|
* the popover without a transition, use gtk_widget_show().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_popover_popup (GtkPopover *popover)
|
|
|
|
{
|
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_POPOVER (popover));
|
|
|
|
|
|
|
|
if (priv->state == STATE_SHOWING ||
|
|
|
|
priv->state == STATE_SHOWN)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_widget_show (GTK_WIDGET (popover));
|
|
|
|
|
|
|
|
if (transitions_enabled (popover))
|
|
|
|
gtk_popover_set_state (popover, STATE_SHOWING);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_popover_popdown:
|
|
|
|
* @popover: a #GtkPopover
|
|
|
|
*
|
|
|
|
* Pops @popover down.This is different than a gtk_widget_hide() call
|
|
|
|
* in that it shows the popover with a transition. If you want to hide
|
|
|
|
* the popover without a transition, use gtk_widget_hide().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_popover_popdown (GtkPopover *popover)
|
|
|
|
{
|
|
|
|
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_POPOVER (popover));
|
|
|
|
|
|
|
|
if (priv->state == STATE_HIDING ||
|
|
|
|
priv->state == STATE_HIDDEN)
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (!transitions_enabled (popover))
|
|
|
|
gtk_widget_hide (GTK_WIDGET (popover));
|
|
|
|
else
|
|
|
|
gtk_popover_set_state (popover, STATE_HIDING);
|
|
|
|
|
|
|
|
gtk_popover_hide_internal (popover);
|
|
|
|
}
|