2020-02-29 14:17:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2020 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* 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.1 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/>.
|
|
|
|
*
|
|
|
|
* Authors: Matthias Clasen <mclasen@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2022-09-24 03:23:27 +00:00
|
|
|
#include "gdkprivate.h"
|
2022-09-24 03:33:42 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2020-02-29 14:17:02 +00:00
|
|
|
#include "gdkpopupprivate.h"
|
|
|
|
|
|
|
|
/**
|
2021-02-21 05:13:57 +00:00
|
|
|
* GdkPopup:
|
2020-02-29 14:17:02 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* A `GdkPopup` is a surface that is attached to another surface.
|
2020-10-29 18:00:13 +00:00
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* The `GdkPopup` is positioned relative to its parent surface.
|
|
|
|
*
|
|
|
|
* `GdkPopup`s are typically used to implement menus and similar popups.
|
|
|
|
* They can be modal, which is indicated by the [property@GdkPopup:autohide]
|
|
|
|
* property.
|
2020-02-29 14:17:02 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-10 11:23:49 +00:00
|
|
|
G_DEFINE_INTERFACE (GdkPopup, gdk_popup, GDK_TYPE_SURFACE)
|
2020-02-29 14:17:02 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gdk_popup_default_present (GdkPopup *popup,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
GdkPopupLayout *layout)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkGravity
|
|
|
|
gdk_popup_default_get_surface_anchor (GdkPopup *popup)
|
|
|
|
{
|
|
|
|
return GDK_GRAVITY_STATIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkGravity
|
|
|
|
gdk_popup_default_get_rect_anchor (GdkPopup *popup)
|
|
|
|
{
|
|
|
|
return GDK_GRAVITY_STATIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gdk_popup_default_get_position_x (GdkPopup *popup)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gdk_popup_default_get_position_y (GdkPopup *popup)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_popup_default_init (GdkPopupInterface *iface)
|
|
|
|
{
|
|
|
|
iface->present = gdk_popup_default_present;
|
|
|
|
iface->get_surface_anchor = gdk_popup_default_get_surface_anchor;
|
|
|
|
iface->get_rect_anchor = gdk_popup_default_get_rect_anchor;
|
|
|
|
iface->get_position_x = gdk_popup_default_get_position_x;
|
|
|
|
iface->get_position_y = gdk_popup_default_get_position_y;
|
|
|
|
|
2021-02-25 01:05:43 +00:00
|
|
|
/**
|
|
|
|
* GdkPopup:parent: (attributes org.gtk.Property.get=gdk_popup_get_parent)
|
|
|
|
*
|
|
|
|
* The parent surface.
|
|
|
|
*/
|
2020-02-29 14:17:02 +00:00
|
|
|
g_object_interface_install_property (iface,
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("parent", NULL, NULL,
|
2020-02-29 14:17:02 +00:00
|
|
|
GDK_TYPE_SURFACE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
2021-02-25 01:05:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GdkPopup:autohide: (attributes org.gtk.Property.get=gdk_popup_get_autohide)
|
|
|
|
*
|
|
|
|
* Whether to hide on outside clicks.
|
|
|
|
*/
|
2020-02-29 14:17:02 +00:00
|
|
|
g_object_interface_install_property (iface,
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_boolean ("autohide", NULL, NULL,
|
2020-02-29 14:17:02 +00:00
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_popup_present:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @popup: the `GdkPopup` to show
|
2020-02-29 14:17:02 +00:00
|
|
|
* @width: the unconstrained popup width to layout
|
|
|
|
* @height: the unconstrained popup height to layout
|
2021-02-21 05:13:57 +00:00
|
|
|
* @layout: the `GdkPopupLayout` object used to layout
|
2020-02-29 14:17:02 +00:00
|
|
|
*
|
2021-05-20 03:39:18 +00:00
|
|
|
* Present @popup after having processed the `GdkPopupLayout` rules.
|
2021-02-21 05:13:57 +00:00
|
|
|
*
|
2020-02-29 14:17:02 +00:00
|
|
|
* If the popup was previously now showing, it will be showed,
|
|
|
|
* otherwise it will change position according to @layout.
|
|
|
|
*
|
2020-11-25 10:48:08 +00:00
|
|
|
* After calling this function, the result should be handled in response
|
2021-02-21 05:13:57 +00:00
|
|
|
* to the [signal@GdkSurface::layout] signal being emitted. The resulting
|
|
|
|
* popup position can be queried using [method@Gdk.Popup.get_position_x],
|
|
|
|
* [method@Gdk.Popup.get_position_y], and the resulting size will be sent as
|
|
|
|
* parameters in the layout signal. Use [method@Gdk.Popup.get_rect_anchor]
|
|
|
|
* and [method@Gdk.Popup.get_surface_anchor] to get the resulting anchors.
|
2020-02-29 14:17:02 +00:00
|
|
|
*
|
2020-12-05 17:28:50 +00:00
|
|
|
* Presenting may fail, for example if the @popup is set to autohide
|
|
|
|
* and is immediately hidden upon being presented. If presenting failed,
|
2021-02-21 05:13:57 +00:00
|
|
|
* the [signal@Gdk.Surface::layout] signal will not me emitted.
|
2020-02-29 14:17:02 +00:00
|
|
|
*
|
|
|
|
* Returns: %FALSE if it failed to be presented, otherwise %TRUE.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gdk_popup_present (GdkPopup *popup,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
GdkPopupLayout *layout)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GDK_IS_POPUP (popup), FALSE);
|
|
|
|
g_return_val_if_fail (width > 0, FALSE);
|
|
|
|
g_return_val_if_fail (height > 0, FALSE);
|
|
|
|
g_return_val_if_fail (layout != NULL, FALSE);
|
|
|
|
|
|
|
|
return GDK_POPUP_GET_IFACE (popup)->present (popup, width, height, layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_popup_get_surface_anchor:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @popup: a `GdkPopup`
|
2020-02-29 14:17:02 +00:00
|
|
|
*
|
|
|
|
* Gets the current popup surface anchor.
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* The value returned may change after calling [method@Gdk.Popup.present],
|
|
|
|
* or after the [signal@Gdk.Surface::layout] signal is emitted.
|
2020-02-29 14:17:02 +00:00
|
|
|
*
|
|
|
|
* Returns: the current surface anchor value of @popup
|
|
|
|
*/
|
|
|
|
GdkGravity
|
|
|
|
gdk_popup_get_surface_anchor (GdkPopup *popup)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GDK_IS_POPUP (popup), GDK_GRAVITY_STATIC);
|
|
|
|
|
|
|
|
return GDK_POPUP_GET_IFACE (popup)->get_surface_anchor (popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_popup_get_rect_anchor:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @popup: a `GdkPopup`
|
2020-02-29 14:17:02 +00:00
|
|
|
*
|
|
|
|
* Gets the current popup rectangle anchor.
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
* The value returned may change after calling [method@Gdk.Popup.present],
|
|
|
|
* or after the [signal@Gdk.Surface::layout] signal is emitted.
|
2020-02-29 14:17:02 +00:00
|
|
|
*
|
|
|
|
* Returns: the current rectangle anchor value of @popup
|
|
|
|
*/
|
|
|
|
GdkGravity
|
|
|
|
gdk_popup_get_rect_anchor (GdkPopup *popup)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GDK_IS_POPUP (popup), GDK_GRAVITY_STATIC);
|
|
|
|
|
|
|
|
return GDK_POPUP_GET_IFACE (popup)->get_rect_anchor (popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 01:05:43 +00:00
|
|
|
* gdk_popup_get_parent: (attributes org.gtk.Method.get_property=parent)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @popup: a `GdkPopup`
|
2020-02-29 14:17:02 +00:00
|
|
|
*
|
|
|
|
* Returns the parent surface of a popup.
|
|
|
|
*
|
2022-01-01 16:03:10 +00:00
|
|
|
* Returns: (transfer none) (nullable): the parent surface
|
2020-02-29 14:17:02 +00:00
|
|
|
*/
|
|
|
|
GdkSurface *
|
|
|
|
gdk_popup_get_parent (GdkPopup *popup)
|
|
|
|
{
|
|
|
|
GdkSurface *surface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_POPUP (popup), NULL);
|
|
|
|
|
|
|
|
g_object_get (popup, "parent", &surface, NULL);
|
|
|
|
|
|
|
|
if (surface)
|
|
|
|
g_object_unref (surface);
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_popup_get_position_x:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @popup: a `GdkPopup`
|
2020-02-29 14:17:02 +00:00
|
|
|
*
|
|
|
|
* Obtains the position of the popup relative to its parent.
|
|
|
|
*
|
|
|
|
* Returns: the X coordinate of @popup position
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
gdk_popup_get_position_x (GdkPopup *popup)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GDK_IS_POPUP (popup), 0);
|
|
|
|
|
|
|
|
return GDK_POPUP_GET_IFACE (popup)->get_position_x (popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_popup_get_position_y:
|
2021-02-21 05:13:57 +00:00
|
|
|
* @popup: a `GdkPopup`
|
2020-02-29 14:17:02 +00:00
|
|
|
*
|
|
|
|
* Obtains the position of the popup relative to its parent.
|
|
|
|
*
|
|
|
|
* Returns: the Y coordinate of @popup position
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
gdk_popup_get_position_y (GdkPopup *popup)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GDK_IS_POPUP (popup), 0);
|
|
|
|
|
|
|
|
return GDK_POPUP_GET_IFACE (popup)->get_position_y (popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 01:05:43 +00:00
|
|
|
* gdk_popup_get_autohide: (attributes org.gtk.Method.get_property=autohide)
|
2021-02-21 05:13:57 +00:00
|
|
|
* @popup: a `GdkPopup`
|
2020-02-29 14:17:02 +00:00
|
|
|
*
|
|
|
|
* Returns whether this popup is set to hide on outside clicks.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @popup will autohide
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gdk_popup_get_autohide (GdkPopup *popup)
|
|
|
|
{
|
|
|
|
gboolean autohide;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_POPUP (popup), FALSE);
|
|
|
|
|
|
|
|
g_object_get (popup, "autohide", &autohide, NULL);
|
|
|
|
|
|
|
|
return autohide;
|
|
|
|
}
|
|
|
|
|
|
|
|
guint
|
|
|
|
gdk_popup_install_properties (GObjectClass *object_class,
|
|
|
|
guint first_prop)
|
|
|
|
{
|
2021-02-21 05:13:57 +00:00
|
|
|
/**
|
|
|
|
* GdkToplevel:parent:
|
|
|
|
*
|
|
|
|
* The parent surface of the toplevel.
|
|
|
|
*/
|
2020-02-29 14:17:02 +00:00
|
|
|
g_object_class_override_property (object_class, first_prop + GDK_POPUP_PROP_PARENT, "parent");
|
2021-02-21 05:13:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GdkToplevel:autohide:
|
|
|
|
*
|
|
|
|
* Whether the toplevel should be modal with respect to its parent.
|
|
|
|
*/
|
2020-02-29 14:17:02 +00:00
|
|
|
g_object_class_override_property (object_class, first_prop + GDK_POPUP_PROP_AUTOHIDE, "autohide");
|
|
|
|
|
|
|
|
return GDK_POPUP_NUM_PROPERTIES;
|
|
|
|
}
|