forked from AuroraMiddleware/gtk
paned: Add a paned handle class
Instead of bending GtkGizmo to the breaking point, split off a GtkPanedHandle class that just does what is needed here. Its simpler, and lets us keep GtkGizmo simpler too. Everybody wins.
This commit is contained in:
parent
af1981eda2
commit
35488959b4
@ -30,16 +30,13 @@
|
||||
#include "gtkeventcontrollermotion.h"
|
||||
#include "gtkgesturepan.h"
|
||||
#include "gtkgesturesingle.h"
|
||||
#include "gtkgizmoprivate.h"
|
||||
#include "gtkpanedhandleprivate.h"
|
||||
#include "gtkintl.h"
|
||||
#include "gtkmarshalers.h"
|
||||
#include "gtkorientable.h"
|
||||
#include "gtkprivate.h"
|
||||
#include "gtkrendericonprivate.h"
|
||||
#include "gtkcssnodeprivate.h"
|
||||
#include "gtktypebuiltins.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gtkcssboxesprivate.h"
|
||||
#include "gtkbuildable.h"
|
||||
|
||||
#include <math.h>
|
||||
@ -300,26 +297,6 @@ get_handle_area (GtkPaned *paned,
|
||||
graphene_rect_inset (area, - extra, - extra);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_paned_handle_contains (GtkGizmo *handle,
|
||||
double x,
|
||||
double y)
|
||||
{
|
||||
GtkWidget *paned;
|
||||
GtkCssBoxes boxes;
|
||||
graphene_rect_t area;
|
||||
|
||||
gtk_css_boxes_init (&boxes, GTK_WIDGET (handle));
|
||||
|
||||
graphene_rect_init_from_rect (&area, gtk_css_boxes_get_border_rect (&boxes));
|
||||
|
||||
paned = gtk_widget_get_parent (GTK_WIDGET (handle));
|
||||
if (!gtk_paned_get_wide_handle (GTK_PANED (paned)))
|
||||
graphene_rect_inset (&area, - HANDLE_EXTRA_SIZE, - HANDLE_EXTRA_SIZE);
|
||||
|
||||
return graphene_rect_contains_point (&area, &GRAPHENE_POINT_INIT (x, y));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_paned_compute_expand (GtkWidget *widget,
|
||||
gboolean *hexpand,
|
||||
@ -1407,21 +1384,6 @@ gtk_paned_unrealize (GtkWidget *widget)
|
||||
GTK_WIDGET_CLASS (gtk_paned_parent_class)->unrealize (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_paned_render_handle (GtkGizmo *gizmo,
|
||||
GtkSnapshot *snapshot)
|
||||
{
|
||||
GtkWidget *widget = GTK_WIDGET (gizmo);
|
||||
GtkCssStyle *style = gtk_css_node_get_style (gtk_widget_get_css_node (widget));
|
||||
int width, height;
|
||||
|
||||
width = gtk_widget_get_width (widget);
|
||||
height = gtk_widget_get_height (widget);
|
||||
|
||||
if (width > 0 && height > 0)
|
||||
gtk_css_style_snapshot_icon (style, snapshot, width, height);
|
||||
}
|
||||
|
||||
static void
|
||||
connect_drag_gesture_signals (GtkPaned *paned,
|
||||
GtkGesture *gesture)
|
||||
@ -1479,7 +1441,7 @@ gtk_paned_init (GtkPaned *paned)
|
||||
gtk_widget_add_controller (GTK_WIDGET (paned), GTK_EVENT_CONTROLLER (gesture));
|
||||
paned->drag_gesture = gesture;
|
||||
|
||||
paned->handle_widget = gtk_gizmo_new ("separator", NULL, NULL, gtk_paned_render_handle, gtk_paned_handle_contains, NULL, NULL);
|
||||
paned->handle_widget = gtk_paned_handle_new ();
|
||||
gtk_widget_set_parent (paned->handle_widget, GTK_WIDGET (paned));
|
||||
gtk_widget_set_cursor_from_name (paned->handle_widget, "col-resize");
|
||||
}
|
||||
|
114
gtk/gtkpanedhandle.c
Normal file
114
gtk/gtkpanedhandle.c
Normal file
@ -0,0 +1,114 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2021 Red Hat, Inc.
|
||||
*
|
||||
* Authors:
|
||||
* - Matthias Clasen <mclasen@redhat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkpanedhandleprivate.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gtkcssnodeprivate.h"
|
||||
#include "gtkcssstyleprivate.h"
|
||||
#include "gtkrendericonprivate.h"
|
||||
#include "gtkcssboxesprivate.h"
|
||||
#include "gtkintl.h"
|
||||
|
||||
#include "gtkpaned.h"
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GtkPanedHandle, gtk_paned_handle, GTK_TYPE_WIDGET);
|
||||
|
||||
static void
|
||||
gtk_paned_handle_snapshot (GtkWidget *widget,
|
||||
GtkSnapshot *snapshot)
|
||||
{
|
||||
GtkCssStyle *style = gtk_css_node_get_style (gtk_widget_get_css_node (widget));
|
||||
int width, height;
|
||||
|
||||
width = gtk_widget_get_width (widget);
|
||||
height = gtk_widget_get_height (widget);
|
||||
|
||||
if (width > 0 && height > 0)
|
||||
gtk_css_style_snapshot_icon (style, snapshot, width, height);
|
||||
}
|
||||
|
||||
#define HANDLE_EXTRA_SIZE 6
|
||||
|
||||
static gboolean
|
||||
gtk_paned_handle_contains (GtkWidget *widget,
|
||||
double x,
|
||||
double y)
|
||||
{
|
||||
GtkWidget *paned;
|
||||
GtkCssBoxes boxes;
|
||||
graphene_rect_t area;
|
||||
|
||||
gtk_css_boxes_init (&boxes, widget);
|
||||
|
||||
graphene_rect_init_from_rect (&area, gtk_css_boxes_get_border_rect (&boxes));
|
||||
|
||||
paned = gtk_widget_get_parent (widget);
|
||||
if (!gtk_paned_get_wide_handle (GTK_PANED (paned)))
|
||||
graphene_rect_inset (&area, - HANDLE_EXTRA_SIZE, - HANDLE_EXTRA_SIZE);
|
||||
|
||||
return graphene_rect_contains_point (&area, &GRAPHENE_POINT_INIT (x, y));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_paned_handle_finalize (GObject *object)
|
||||
{
|
||||
GtkPanedHandle *self = GTK_PANED_HANDLE (object);
|
||||
GtkWidget *widget;
|
||||
|
||||
widget = _gtk_widget_get_first_child (GTK_WIDGET (self));
|
||||
while (widget != NULL)
|
||||
{
|
||||
GtkWidget *next = _gtk_widget_get_next_sibling (widget);
|
||||
|
||||
gtk_widget_unparent (widget);
|
||||
|
||||
widget = next;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (gtk_paned_handle_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_paned_handle_class_init (GtkPanedHandleClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
object_class->finalize = gtk_paned_handle_finalize;
|
||||
|
||||
widget_class->snapshot = gtk_paned_handle_snapshot;
|
||||
widget_class->contains = gtk_paned_handle_contains;
|
||||
|
||||
gtk_widget_class_set_css_name (widget_class, I_("separator"));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_paned_handle_init (GtkPanedHandle *self)
|
||||
{
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
gtk_paned_handle_new (void)
|
||||
{
|
||||
return g_object_new (GTK_TYPE_PANED_HANDLE, NULL);
|
||||
}
|
32
gtk/gtkpanedhandleprivate.h
Normal file
32
gtk/gtkpanedhandleprivate.h
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
#ifndef __GTK_PANED_HANDLE_H__
|
||||
#define __GTK_PANED_HANDLE_H__
|
||||
|
||||
#include "gtkwidget.h"
|
||||
#include "gtkenums.h"
|
||||
|
||||
#define GTK_TYPE_PANED_HANDLE (gtk_paned_handle_get_type ())
|
||||
#define GTK_PANED_HANDLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PANED_HANDLE, GtkPanedHandle))
|
||||
#define GTK_PANED_HANDLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_PANED_HANDLE, GtkPanedHandleClass))
|
||||
#define GTK_IS_PANED_HANDLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_PANED_HANDLE))
|
||||
#define GTK_IS_PANED_HANDLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PANED_HANDLE))
|
||||
#define GTK_PANED_HANDLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PANED_HANDLE, GtkPanedHandleClass))
|
||||
|
||||
typedef struct _GtkPanedHandle GtkPanedHandle;
|
||||
typedef struct _GtkPanedHandleClass GtkPanedHandleClass;
|
||||
|
||||
struct _GtkPanedHandle
|
||||
{
|
||||
GtkWidget parent_instance;
|
||||
};
|
||||
|
||||
struct _GtkPanedHandleClass
|
||||
{
|
||||
GtkWidgetClass parent_class;
|
||||
};
|
||||
|
||||
GType gtk_paned_handle_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkWidget *gtk_paned_handle_new (void);
|
||||
|
||||
#endif
|
@ -119,6 +119,7 @@ gtk_private_sources = files([
|
||||
'gtkmenusectionbox.c',
|
||||
'gtkmenutracker.c',
|
||||
'gtkmenutrackeritem.c',
|
||||
'gtkpanedhandle.c',
|
||||
'gtkpango.c',
|
||||
'gskpango.c',
|
||||
'gtkpasswordentrybuffer.c',
|
||||
|
Loading…
Reference in New Issue
Block a user