[Xfce4-commits] [apps/xfdashboard] 02/03: Implement a box layout manager XfdashboardBoxLayout derived from ClutterBoxLayout which uses all functions of derived class but disregards text direction settings. It forces always left-to-right text direction when layouting children horizontal.

noreply at xfce.org noreply at xfce.org
Fri Mar 27 12:14:06 CET 2015


This is an automated email from the git hooks/post-receive script.

nomad pushed a commit to branch master
in repository apps/xfdashboard.

commit acad499c17ad3d1baf3b987ef37e5dbb67344ffa
Author: Stephan Haller <nomad at froevel.de>
Date:   Fri Mar 27 12:02:01 2015 +0100

    Implement a box layout manager XfdashboardBoxLayout derived from ClutterBoxLayout which uses all functions of derived class but disregards text direction settings. It forces always left-to-right text direction when layouting children horizontal.
    
    This fixes issue #66 at GitHub.
---
 xfdashboard/Makefile.am  |    2 +
 xfdashboard/box-layout.c |  133 ++++++++++++++++++++++++++++++++++++++++++++++
 xfdashboard/box-layout.h |   63 ++++++++++++++++++++++
 3 files changed, 198 insertions(+)

diff --git a/xfdashboard/Makefile.am b/xfdashboard/Makefile.am
index 55b2251..4662fbf 100644
--- a/xfdashboard/Makefile.am
+++ b/xfdashboard/Makefile.am
@@ -27,6 +27,7 @@ xfdashboard_headers = \
 	background.h \
 	binding.h \
 	bindings-pool.h \
+	box-layout.h \
 	button.h \
 	click-action.h \
 	collapse-box.h \
@@ -87,6 +88,7 @@ xfdashboard_SOURCES = \
 	background.c \
 	binding.c \
 	bindings-pool.c \
+	box-layout.c \
 	button.c \
 	click-action.c \
 	collapse-box.c \
diff --git a/xfdashboard/box-layout.c b/xfdashboard/box-layout.c
new file mode 100644
index 0000000..ff6abf2
--- /dev/null
+++ b/xfdashboard/box-layout.c
@@ -0,0 +1,133 @@
+/*
+ * box-layout: A ClutterBoxLayout derived layout manager disregarding
+ *             text direction and enforcing left-to-right layout in
+ *             horizontal orientation
+ * 
+ * Copyright 2012-2015 Stephan Haller <nomad at froevel.de>
+ * 
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ * 
+ * 
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "box-layout.h"
+
+#include <glib/gi18n-lib.h>
+#include <clutter/clutter.h>
+#include <math.h>
+
+/* Define this class in GObject system */
+G_DEFINE_TYPE(XfdashboardBoxLayout,
+				xfdashboard_box_layout,
+				CLUTTER_TYPE_BOX_LAYOUT)
+
+
+/* IMPLEMENTATION: ClutterLayoutManager */
+
+/* Re-layout and allocate children of container we manage */
+static void _xfdashboard_box_layout_allocate(ClutterLayoutManager *inLayoutManager,
+													ClutterContainer *inContainer,
+													const ClutterActorBox *inAllocation,
+													ClutterAllocationFlags inFlags)
+{
+	ClutterTextDirection				textDirection;
+	ClutterActor						*child;
+	ClutterActorIter					iter;
+	ClutterActorBox						childBox;
+	gfloat								containerWidth;
+
+	g_return_if_fail(XFDASHBOARD_IS_BOX_LAYOUT(inLayoutManager));
+	g_return_if_fail(CLUTTER_IS_CONTAINER(inContainer));
+
+
+	/* Chain up to calculate and store the allocation of children */
+	CLUTTER_LAYOUT_MANAGER_CLASS(xfdashboard_box_layout_parent_class)->allocate(inLayoutManager,
+																				inContainer,
+																				inAllocation,
+																				inFlags);
+
+	/* Right-to-left text direction only affects horizontal orientation.
+	 * If orientation is not horizontal or text direction is not right-to-left
+	 * then there is nothing to do.
+	 */
+	if(clutter_box_layout_get_orientation(CLUTTER_BOX_LAYOUT(inLayoutManager))!=CLUTTER_ORIENTATION_HORIZONTAL)
+	{
+		return;
+	}
+
+	textDirection=clutter_actor_get_text_direction(CLUTTER_ACTOR(inContainer));
+	if(textDirection==CLUTTER_TEXT_DIRECTION_DEFAULT) textDirection=clutter_get_default_text_direction();
+	if(textDirection!=CLUTTER_TEXT_DIRECTION_RTL)
+	{
+		return;
+	}
+
+	/* Iterate through children and recalculate x-coordination of each
+	 * children allocation by "mirroring" x-coordinate.
+	 */
+	containerWidth=clutter_actor_box_get_width(inAllocation);
+
+	clutter_actor_iter_init(&iter, CLUTTER_ACTOR(inContainer));
+	while(clutter_actor_iter_next(&iter, &child))
+	{
+		gfloat							x1, x2;
+
+		/* Get position and size of child */
+		clutter_actor_get_allocation_box(child, &childBox);
+
+		/* Set new allocation of child */
+		x1=containerWidth-childBox.x2;
+		x2=containerWidth-childBox.x1;
+
+		childBox.x1=x1;
+		childBox.x2=x2;
+
+		clutter_actor_allocate(child, &childBox, inFlags);
+	}
+}
+
+/* IMPLEMENTATION: GObject */
+
+/* Class initialization
+ * Override functions in parent classes and define properties
+ * and signals
+ */
+static void xfdashboard_box_layout_class_init(XfdashboardBoxLayoutClass *klass)
+{
+	ClutterLayoutManagerClass	*layoutClass=CLUTTER_LAYOUT_MANAGER_CLASS(klass);
+
+	/* Override functions */
+	layoutClass->allocate=_xfdashboard_box_layout_allocate;
+}
+
+/* Object initialization
+ * Create private structure and set up default values
+ */
+static void xfdashboard_box_layout_init(XfdashboardBoxLayout *self)
+{
+}
+
+/* IMPLEMENTATION: Public API */
+
+/* Create new instance */
+ClutterLayoutManager* xfdashboard_box_layout_new(void)
+{
+	return(CLUTTER_LAYOUT_MANAGER(g_object_new(XFDASHBOARD_TYPE_BOX_LAYOUT, NULL)));
+}
diff --git a/xfdashboard/box-layout.h b/xfdashboard/box-layout.h
new file mode 100644
index 0000000..7f1f2d8
--- /dev/null
+++ b/xfdashboard/box-layout.h
@@ -0,0 +1,63 @@
+/*
+ * box-layout: A ClutterBoxLayout derived layout manager disregarding
+ *             text direction and enforcing left-to-right layout in
+ *             horizontal orientation
+ * 
+ * Copyright 2012-2015 Stephan Haller <nomad at froevel.de>
+ * 
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ * 
+ * 
+ */
+
+#ifndef __XFDASHBOARD_BOX_LAYOUT__
+#define __XFDASHBOARD_BOX_LAYOUT__
+
+#include <clutter/clutter.h>
+
+G_BEGIN_DECLS
+
+#define XFDASHBOARD_TYPE_BOX_LAYOUT				(xfdashboard_box_layout_get_type())
+#define XFDASHBOARD_BOX_LAYOUT(obj)				(G_TYPE_CHECK_INSTANCE_CAST((obj), XFDASHBOARD_TYPE_BOX_LAYOUT, XfdashboardBoxLayout))
+#define XFDASHBOARD_IS_BOX_LAYOUT(obj)			(G_TYPE_CHECK_INSTANCE_TYPE((obj), XFDASHBOARD_TYPE_BOX_LAYOUT))
+#define XFDASHBOARD_BOX_LAYOUT_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST((klass), XFDASHBOARD_TYPE_BOX_LAYOUT, XfdashboardBoxLayoutClass))
+#define XFDASHBOARD_IS_BOX_LAYOUT_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE((klass), XFDASHBOARD_TYPE_BOX_LAYOUT))
+#define XFDASHBOARD_BOX_LAYOUT_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS((obj), XFDASHBOARD_TYPE_BOX_LAYOUT, XfdashboardBoxLayoutClass))
+
+typedef struct _XfdashboardBoxLayout			XfdashboardBoxLayout;
+typedef struct _XfdashboardBoxLayoutClass		XfdashboardBoxLayoutClass;
+
+struct _XfdashboardBoxLayout
+{
+	/* Parent instance */
+	ClutterBoxLayout 				parent_instance;
+};
+
+struct _XfdashboardBoxLayoutClass
+{
+	/*< private >*/
+	/* Parent class */
+	ClutterBoxLayoutClass			parent_class;
+};
+
+/* Public API */
+GType xfdashboard_box_layout_get_type(void) G_GNUC_CONST;
+
+ClutterLayoutManager* xfdashboard_box_layout_new(void);
+
+G_END_DECLS
+
+#endif	/* __XFDASHBOARD_BOX_LAYOUT__ */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list