[gnome-panel] add GpHandle widget
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel] add GpHandle widget
- Date: Sun, 25 Apr 2021 12:00:16 +0000 (UTC)
commit 81614e99c5bfaeaf3e9fd3aca5d615d80a3132a5
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Sun Apr 25 14:04:38 2021 +0300
add GpHandle widget
Will be used to replace custom drawing and size allocation in
PanelToplevel.
gnome-panel/Makefile.am | 2 +
gnome-panel/gp-handle.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++++
gnome-panel/gp-handle.h | 32 +++++++++
3 files changed, 220 insertions(+)
---
diff --git a/gnome-panel/Makefile.am b/gnome-panel/Makefile.am
index bd88ef07c..bd3f88c1e 100644
--- a/gnome-panel/Makefile.am
+++ b/gnome-panel/Makefile.am
@@ -19,6 +19,8 @@ panel_sources = \
gp-application.h \
gp-arrow-button.c \
gp-arrow-button.h \
+ gp-handle.c \
+ gp-handle.h \
gp-main.c \
gp-module-manager.c \
gp-module-manager.h \
diff --git a/gnome-panel/gp-handle.c b/gnome-panel/gp-handle.c
new file mode 100644
index 000000000..dcc532b70
--- /dev/null
+++ b/gnome-panel/gp-handle.c
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2021 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "gp-handle.h"
+
+#include "panel-enums-gsettings.h"
+#include "panel-typebuiltins.h"
+
+#define HANDLE_SIZE 10
+
+struct _GpHandle
+{
+ GtkWidget parent;
+
+ PanelOrientation orientation;
+};
+
+enum
+{
+ PROP_0,
+
+ PROP_ORIENTATION,
+
+ LAST_PROP
+};
+
+static GParamSpec *handle_properties[LAST_PROP] = { NULL };
+
+G_DEFINE_TYPE (GpHandle, gp_handle, GTK_TYPE_WIDGET)
+
+static void
+gp_handle_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GpHandle *self;
+
+ self = GP_HANDLE (object);
+
+ switch (property_id)
+ {
+ case PROP_ORIENTATION:
+ g_value_set_enum (value, self->orientation);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gp_handle_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GpHandle *self;
+
+ self = GP_HANDLE (object);
+
+ switch (property_id)
+ {
+ case PROP_ORIENTATION:
+ self->orientation = g_value_get_enum (value);
+ gtk_widget_queue_resize (GTK_WIDGET (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static gboolean
+gp_handle_draw (GtkWidget *widget,
+ cairo_t *cr)
+{
+ GtkStyleContext *context;
+
+ context = gtk_widget_get_style_context (gtk_widget_get_toplevel (widget));
+
+ gtk_render_handle (context,
+ cr,
+ 0,
+ 0,
+ gtk_widget_get_allocated_width (widget),
+ gtk_widget_get_allocated_height (widget));
+
+ return FALSE;
+}
+
+static void
+gp_handle_get_preferred_height (GtkWidget *widget,
+ gint *minimum_height,
+ gint *natural_height)
+{
+ GpHandle *self;
+
+ self = GP_HANDLE (widget);
+
+ if (self->orientation & PANEL_VERTICAL_MASK)
+ *minimum_height = *natural_height = HANDLE_SIZE;
+ else
+ *minimum_height = *natural_height = 0;
+}
+
+static void
+gp_handle_get_preferred_width (GtkWidget *widget,
+ gint *minimum_width,
+ gint *natural_width)
+{
+ GpHandle *self;
+
+ self = GP_HANDLE (widget);
+
+ if (self->orientation & PANEL_HORIZONTAL_MASK)
+ *minimum_width = *natural_width = HANDLE_SIZE;
+ else
+ *minimum_width = *natural_width = 0;
+}
+
+static void
+install_properties (GObjectClass *object_class)
+{
+ handle_properties[PROP_ORIENTATION] =
+ g_param_spec_enum ("orientation",
+ "orientation",
+ "orientation",
+ PANEL_TYPE_ORIENTATION,
+ PANEL_ORIENTATION_TOP,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class,
+ LAST_PROP,
+ handle_properties);
+}
+
+static void
+gp_handle_class_init (GpHandleClass *self_class)
+{
+ GObjectClass *object_class;
+ GtkWidgetClass *widget_class;
+
+ object_class = G_OBJECT_CLASS (self_class);
+ widget_class = GTK_WIDGET_CLASS (self_class);
+
+ object_class->get_property = gp_handle_get_property;
+ object_class->set_property = gp_handle_set_property;
+
+ widget_class->draw = gp_handle_draw;
+ widget_class->get_preferred_height = gp_handle_get_preferred_height;
+ widget_class->get_preferred_width = gp_handle_get_preferred_width;
+
+ install_properties (object_class);
+}
+
+static void
+gp_handle_init (GpHandle *self)
+{
+ gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
+}
+
+GtkWidget *
+gp_handle_new (void)
+{
+ return g_object_new (GP_TYPE_HANDLE, NULL);
+}
diff --git a/gnome-panel/gp-handle.h b/gnome-panel/gp-handle.h
new file mode 100644
index 000000000..391cbc02c
--- /dev/null
+++ b/gnome-panel/gp-handle.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2021 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GP_HANDLE_H
+#define GP_HANDLE_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GP_TYPE_HANDLE (gp_handle_get_type ())
+G_DECLARE_FINAL_TYPE (GpHandle, gp_handle, GP, HANDLE, GtkWidget)
+
+GtkWidget *gp_handle_new (void);
+
+G_END_DECLS
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]