summaryrefslogtreecommitdiff
path: root/eel
diff options
context:
space:
mode:
authorCarlos Soriano <csoriano@gnome.org>2016-08-29 18:24:05 +0200
committerCarlos Soriano <csoriano@gnome.org>2016-08-29 18:37:10 +0200
commit52d960542b4d5fdf2bd06735d0dbf7934cf2ec12 (patch)
tree5e000d5ed40b52b003c02b597e51ae0b87ff22ac /eel
parent4cafccd82859a4ee0bdfad3e31a310f2d94c0485 (diff)
downloadnautilus-52d960542b4d5fdf2bd06735d0dbf7934cf2ec12.tar.gz
general: run uncrustify
And make the style of Nautilus the same for all files. Hopefully we can fix all the style issues we can find in the next days, so expect a little of movement on this. https://bugzilla.gnome.org/show_bug.cgi?id=770564
Diffstat (limited to 'eel')
-rw-r--r--eel/check-program.c67
-rw-r--r--eel/eel-accessibility.c266
-rw-r--r--eel/eel-art-extensions.c230
-rw-r--r--eel/eel-canvas.c5116
-rw-r--r--eel/eel-debug.c104
-rw-r--r--eel/eel-gdk-extensions.c114
-rw-r--r--eel/eel-glib-extensions.c201
-rw-r--r--eel/eel-gnome-extensions.c81
-rw-r--r--eel/eel-graphic-effects.c206
-rw-r--r--eel/eel-gtk-extensions.c456
-rw-r--r--eel/eel-lib-self-check-functions.c44
-rw-r--r--eel/eel-self-checks.c237
-rw-r--r--eel/eel-stock-dialogs.c754
-rw-r--r--eel/eel-string.c1653
-rw-r--r--eel/eel-vfs-extensions.c245
15 files changed, 5324 insertions, 4450 deletions
diff --git a/eel/check-program.c b/eel/check-program.c
index ca109740f..1e0f0a382 100644
--- a/eel/check-program.c
+++ b/eel/check-program.c
@@ -1,24 +1,23 @@
-
/* check-program.c: A simple driver for eel self checks.
-
- Copyright (C) 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Ramiro Estrugo <ramiro@eazel.com>
-*/
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Ramiro Estrugo <ramiro@eazel.com>
+ */
#include <config.h>
@@ -32,27 +31,29 @@
#include <stdlib.h>
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
#if !defined (EEL_OMIT_SELF_CHECK)
- eel_make_warnings_and_criticals_stop_in_debugger ();
-
+ eel_make_warnings_and_criticals_stop_in_debugger ();
- LIBXML_TEST_VERSION
- gtk_init (&argc, &argv);
- /* Run the checks for eel twice. */
+ LIBXML_TEST_VERSION
+ gtk_init (&argc,
+ &argv);
- eel_run_lib_self_checks ();
- eel_exit_if_self_checks_failed ();
+ /* Run the checks for eel twice. */
- eel_run_lib_self_checks ();
- eel_exit_if_self_checks_failed ();
+ eel_run_lib_self_checks ();
+ eel_exit_if_self_checks_failed ();
- eel_debug_shut_down ();
+ eel_run_lib_self_checks ();
+ eel_exit_if_self_checks_failed ();
+
+ eel_debug_shut_down ();
#endif /* !EEL_OMIT_SELF_CHECK */
-
- return EXIT_SUCCESS;
+
+ return EXIT_SUCCESS;
}
diff --git a/eel/eel-accessibility.c b/eel/eel-accessibility.c
index 83b88accd..3510fc491 100644
--- a/eel/eel-accessibility.c
+++ b/eel/eel-accessibility.c
@@ -1,202 +1,212 @@
/* eel-accessibility.h - Utility functions for accessibility
-
- Copyright (C) 2002 Anders Carlsson, Sun Microsystems, Inc.
-
- The Eel Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Eel 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Eel Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors:
- Anders Carlsson <andersca@gnu.org>
- Michael Meeks <michael@ximian.com>
-*/
+ *
+ * Copyright (C) 2002 Anders Carlsson, Sun Microsystems, Inc.
+ *
+ * The Eel Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Eel 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Eel Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Anders Carlsson <andersca@gnu.org>
+ * Michael Meeks <michael@ximian.com>
+ */
#include <config.h>
#include <gtk/gtk.h>
#include <atk/atkrelationset.h>
#include <eel/eel-accessibility.h>
void
-eel_accessibility_set_up_label_widget_relation (GtkWidget *label, GtkWidget *widget)
+eel_accessibility_set_up_label_widget_relation (GtkWidget *label,
+ GtkWidget *widget)
{
- AtkObject *atk_widget, *atk_label;
+ AtkObject *atk_widget, *atk_label;
- atk_label = gtk_widget_get_accessible (label);
- atk_widget = gtk_widget_get_accessible (widget);
+ atk_label = gtk_widget_get_accessible (label);
+ atk_widget = gtk_widget_get_accessible (widget);
- /* Create the label -> widget relation */
- atk_object_add_relationship (atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
+ /* Create the label -> widget relation */
+ atk_object_add_relationship (atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
- /* Create the widget -> label relation */
- atk_object_add_relationship (atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
+ /* Create the widget -> label relation */
+ atk_object_add_relationship (atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
}
static GQuark
get_quark_gobject (void)
{
- static GQuark quark_accessible_gobject = 0;
+ static GQuark quark_accessible_gobject = 0;
- if (!quark_accessible_gobject) {
- quark_accessible_gobject = g_quark_from_static_string
- ("object-for-accessible");
- }
+ if (!quark_accessible_gobject)
+ {
+ quark_accessible_gobject = g_quark_from_static_string
+ ("object-for-accessible");
+ }
- return quark_accessible_gobject;
+ return quark_accessible_gobject;
}
/**
* eel_accessibility_get_gobject:
* @object: an AtkObject
- *
+ *
* gets the GObject associated with the AtkObject, for which
* @object provides accessibility support.
- *
+ *
* Return value: the accessible's associated GObject
**/
gpointer
eel_accessibility_get_gobject (AtkObject *object)
{
- return g_object_get_qdata (G_OBJECT (object), get_quark_gobject ());
+ return g_object_get_qdata (G_OBJECT (object), get_quark_gobject ());
}
static GailTextUtil *
get_simple_text (gpointer object)
{
- GObject *gobject;
- EelAccessibleTextIface *aif;
-
- if (GTK_IS_ACCESSIBLE (object)) {
- gobject = G_OBJECT (gtk_accessible_get_widget (GTK_ACCESSIBLE (object)));
- } else {
- gobject = eel_accessibility_get_gobject (object);
- }
-
- if (!gobject) {
- return NULL;
- }
-
- aif = EEL_ACCESSIBLE_TEXT_GET_IFACE (gobject);
- if (!aif) {
- g_warning ("No accessible text inferface on '%s'",
- g_type_name_from_instance ((gpointer) gobject));
-
- } else if (aif->get_text) {
- return aif->get_text (gobject);
- }
-
- return NULL;
+ GObject *gobject;
+ EelAccessibleTextIface *aif;
+
+ if (GTK_IS_ACCESSIBLE (object))
+ {
+ gobject = G_OBJECT (gtk_accessible_get_widget (GTK_ACCESSIBLE (object)));
+ }
+ else
+ {
+ gobject = eel_accessibility_get_gobject (object);
+ }
+
+ if (!gobject)
+ {
+ return NULL;
+ }
+
+ aif = EEL_ACCESSIBLE_TEXT_GET_IFACE (gobject);
+ if (!aif)
+ {
+ g_warning ("No accessible text inferface on '%s'",
+ g_type_name_from_instance ((gpointer) gobject));
+ }
+ else if (aif->get_text)
+ {
+ return aif->get_text (gobject);
+ }
+
+ return NULL;
}
char *
eel_accessibility_text_get_text (AtkText *text,
- gint start_pos,
- gint end_pos)
+ gint start_pos,
+ gint end_pos)
{
- GailTextUtil *util = get_simple_text (text);
- g_return_val_if_fail (util != NULL, NULL);
+ GailTextUtil *util = get_simple_text (text);
+ g_return_val_if_fail (util != NULL, NULL);
- return gail_text_util_get_substring (util, start_pos, end_pos);
+ return gail_text_util_get_substring (util, start_pos, end_pos);
}
-gunichar
+gunichar
eel_accessibility_text_get_character_at_offset (AtkText *text,
- gint offset)
+ gint offset)
{
- char *txt, *index;
- gint sucks1 = 0, sucks2 = -1;
- gunichar c;
- GailTextUtil *util = get_simple_text (text);
- g_return_val_if_fail (util != NULL, 0);
+ char *txt, *index;
+ gint sucks1 = 0, sucks2 = -1;
+ gunichar c;
+ GailTextUtil *util = get_simple_text (text);
+ g_return_val_if_fail (util != NULL, 0);
- txt = gail_text_util_get_substring (util, sucks1, sucks2);
+ txt = gail_text_util_get_substring (util, sucks1, sucks2);
- index = g_utf8_offset_to_pointer (txt, offset);
- c = g_utf8_get_char (index);
- g_free (txt);
+ index = g_utf8_offset_to_pointer (txt, offset);
+ c = g_utf8_get_char (index);
+ g_free (txt);
- return c;
+ return c;
}
char *
-eel_accessibility_text_get_text_before_offset (AtkText *text,
- gint offset,
- AtkTextBoundary boundary_type,
- gint *start_offset,
- gint *end_offset)
+eel_accessibility_text_get_text_before_offset (AtkText *text,
+ gint offset,
+ AtkTextBoundary boundary_type,
+ gint *start_offset,
+ gint *end_offset)
{
- GailTextUtil *util = get_simple_text (text);
- g_return_val_if_fail (util != NULL, NULL);
+ GailTextUtil *util = get_simple_text (text);
+ g_return_val_if_fail (util != NULL, NULL);
- return gail_text_util_get_text (
- util, NULL, GAIL_BEFORE_OFFSET,
- boundary_type, offset, start_offset, end_offset);
+ return gail_text_util_get_text (
+ util, NULL, GAIL_BEFORE_OFFSET,
+ boundary_type, offset, start_offset, end_offset);
}
char *
-eel_accessibility_text_get_text_at_offset (AtkText *text,
- gint offset,
- AtkTextBoundary boundary_type,
- gint *start_offset,
- gint *end_offset)
+eel_accessibility_text_get_text_at_offset (AtkText *text,
+ gint offset,
+ AtkTextBoundary boundary_type,
+ gint *start_offset,
+ gint *end_offset)
{
- GailTextUtil *util = get_simple_text (text);
- g_return_val_if_fail (util != NULL, NULL);
+ GailTextUtil *util = get_simple_text (text);
+ g_return_val_if_fail (util != NULL, NULL);
- return gail_text_util_get_text (
- util, NULL, GAIL_AT_OFFSET,
- boundary_type, offset, start_offset, end_offset);
+ return gail_text_util_get_text (
+ util, NULL, GAIL_AT_OFFSET,
+ boundary_type, offset, start_offset, end_offset);
}
-gchar*
-eel_accessibility_text_get_text_after_offset (AtkText *text,
- gint offset,
- AtkTextBoundary boundary_type,
- gint *start_offset,
- gint *end_offset)
+gchar *
+eel_accessibility_text_get_text_after_offset (AtkText *text,
+ gint offset,
+ AtkTextBoundary boundary_type,
+ gint *start_offset,
+ gint *end_offset)
{
- GailTextUtil *util = get_simple_text (text);
- g_return_val_if_fail (util != NULL, NULL);
+ GailTextUtil *util = get_simple_text (text);
+ g_return_val_if_fail (util != NULL, NULL);
- return gail_text_util_get_text (
- util, NULL, GAIL_AFTER_OFFSET,
- boundary_type, offset, start_offset, end_offset);
+ return gail_text_util_get_text (
+ util, NULL, GAIL_AFTER_OFFSET,
+ boundary_type, offset, start_offset, end_offset);
}
gint
eel_accessibility_text_get_character_count (AtkText *text)
{
- GailTextUtil *util = get_simple_text (text);
- g_return_val_if_fail (util != NULL, -1);
+ GailTextUtil *util = get_simple_text (text);
+ g_return_val_if_fail (util != NULL, -1);
- return gtk_text_buffer_get_char_count (util->buffer);
+ return gtk_text_buffer_get_char_count (util->buffer);
}
GType
eel_accessible_text_get_type (void)
{
- static GType type = 0;
-
- if (!type) {
- const GTypeInfo tinfo = {
- sizeof (AtkTextIface),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) NULL,
- (GClassFinalizeFunc) NULL
- };
-
- type = g_type_register_static (
- G_TYPE_INTERFACE, "EelAccessibleText", &tinfo, 0);
- }
-
- return type;
+ static GType type = 0;
+
+ if (!type)
+ {
+ const GTypeInfo tinfo =
+ {
+ sizeof (AtkTextIface),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) NULL,
+ (GClassFinalizeFunc) NULL
+ };
+
+ type = g_type_register_static (
+ G_TYPE_INTERFACE, "EelAccessibleText", &tinfo, 0);
+ }
+
+ return type;
}
diff --git a/eel/eel-art-extensions.c b/eel/eel-art-extensions.c
index 38072b562..e8ce5f957 100644
--- a/eel/eel-art-extensions.c
+++ b/eel/eel-art-extensions.c
@@ -1,25 +1,24 @@
-
/* eel-art-extensions.c - implementation of libart extension functions.
-
- Copyright (C) 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Darin Adler <darin@eazel.com>
- Ramiro Estrugo <ramiro@eazel.com>
-*/
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Darin Adler <darin@eazel.com>
+ * Ramiro Estrugo <ramiro@eazel.com>
+ */
#include <config.h>
@@ -31,170 +30,185 @@ const EelDRect eel_drect_empty = { 0.0, 0.0, 0.0, 0.0 };
const EelIRect eel_irect_empty = { 0, 0, 0, 0 };
void
-eel_irect_copy (EelIRect *dest, const EelIRect *src)
+eel_irect_copy (EelIRect *dest,
+ const EelIRect *src)
{
- dest->x0 = src->x0;
- dest->y0 = src->y0;
- dest->x1 = src->x1;
- dest->y1 = src->y1;
+ dest->x0 = src->x0;
+ dest->y0 = src->y0;
+ dest->x1 = src->x1;
+ dest->y1 = src->y1;
}
void
-eel_irect_union (EelIRect *dest,
- const EelIRect *src1,
- const EelIRect *src2) {
- if (eel_irect_is_empty (src1)) {
- eel_irect_copy (dest, src2);
- } else if (eel_irect_is_empty (src2)) {
- eel_irect_copy (dest, src1);
- } else {
- dest->x0 = MIN (src1->x0, src2->x0);
- dest->y0 = MIN (src1->y0, src2->y0);
- dest->x1 = MAX (src1->x1, src2->x1);
- dest->y1 = MAX (src1->y1, src2->y1);
- }
+eel_irect_union (EelIRect *dest,
+ const EelIRect *src1,
+ const EelIRect *src2)
+{
+ if (eel_irect_is_empty (src1))
+ {
+ eel_irect_copy (dest, src2);
+ }
+ else if (eel_irect_is_empty (src2))
+ {
+ eel_irect_copy (dest, src1);
+ }
+ else
+ {
+ dest->x0 = MIN (src1->x0, src2->x0);
+ dest->y0 = MIN (src1->y0, src2->y0);
+ dest->x1 = MAX (src1->x1, src2->x1);
+ dest->y1 = MAX (src1->y1, src2->y1);
+ }
}
void
-eel_irect_intersect (EelIRect *dest,
- const EelIRect *src1,
- const EelIRect *src2)
+eel_irect_intersect (EelIRect *dest,
+ const EelIRect *src1,
+ const EelIRect *src2)
{
- dest->x0 = MAX (src1->x0, src2->x0);
- dest->y0 = MAX (src1->y0, src2->y0);
- dest->x1 = MIN (src1->x1, src2->x1);
- dest->y1 = MIN (src1->y1, src2->y1);
+ dest->x0 = MAX (src1->x0, src2->x0);
+ dest->y0 = MAX (src1->y0, src2->y0);
+ dest->x1 = MIN (src1->x1, src2->x1);
+ dest->y1 = MIN (src1->y1, src2->y1);
}
gboolean
eel_irect_is_empty (const EelIRect *src)
{
- return (src->x1 <= src->x0 ||
- src->y1 <= src->y0);
+ return (src->x1 <= src->x0 ||
+ src->y1 <= src->y0);
}
/**
* eel_irect_get_width:
- *
+ *
* @rectangle: An EelIRect.
*
* Returns: The width of the rectangle.
- *
+ *
*/
int
eel_irect_get_width (EelIRect rectangle)
{
- return rectangle.x1 - rectangle.x0;
+ return rectangle.x1 - rectangle.x0;
}
/**
* eel_irect_get_height:
- *
+ *
* @rectangle: An EelIRect.
*
* Returns: The height of the rectangle.
- *
+ *
*/
int
eel_irect_get_height (EelIRect rectangle)
{
- return rectangle.y1 - rectangle.y0;
+ return rectangle.y1 - rectangle.y0;
}
static void
-eel_drect_copy (EelDRect *dest,
- const EelDRect *src)
+eel_drect_copy (EelDRect *dest,
+ const EelDRect *src)
{
- dest->x0 = src->x0;
- dest->y0 = src->y0;
- dest->x1 = src->x1;
- dest->y1 = src->y1;
+ dest->x0 = src->x0;
+ dest->y0 = src->y0;
+ dest->x1 = src->x1;
+ dest->y1 = src->y1;
}
static gboolean
eel_drect_is_empty (const EelDRect *src)
{
- return (src->x1 <= src->x0 || src->y1 <= src->y0);
+ return (src->x1 <= src->x0 || src->y1 <= src->y0);
}
void
-eel_drect_union (EelDRect *dest,
- const EelDRect *src1,
- const EelDRect *src2)
+eel_drect_union (EelDRect *dest,
+ const EelDRect *src1,
+ const EelDRect *src2)
{
- if (eel_drect_is_empty (src1)) {
- eel_drect_copy (dest, src2);
- } else if (eel_drect_is_empty (src2)) {
- eel_drect_copy (dest, src1);
- } else {
- dest->x0 = MIN (src1->x0, src2->x0);
- dest->y0 = MIN (src1->y0, src2->y0);
- dest->x1 = MAX (src1->x1, src2->x1);
- dest->y1 = MAX (src1->y1, src2->y1);
- }
+ if (eel_drect_is_empty (src1))
+ {
+ eel_drect_copy (dest, src2);
+ }
+ else if (eel_drect_is_empty (src2))
+ {
+ eel_drect_copy (dest, src1);
+ }
+ else
+ {
+ dest->x0 = MIN (src1->x0, src2->x0);
+ dest->y0 = MIN (src1->y0, src2->y0);
+ dest->x1 = MAX (src1->x1, src2->x1);
+ dest->y1 = MAX (src1->y1, src2->y1);
+ }
}
/**
* eel_irect_contains_point:
- *
+ *
* @rectangle: An EelIRect.
* @x: X coordinate to test.
* @y: Y coordinate to test.
*
- * Returns: A boolean value indicating whether the rectangle
+ * Returns: A boolean value indicating whether the rectangle
* contains the x,y coordinate.
- *
+ *
*/
gboolean
eel_irect_contains_point (EelIRect rectangle,
- int x,
- int y)
+ int x,
+ int y)
{
- return x >= rectangle.x0
- && x <= rectangle.x1
- && y >= rectangle.y0
- && y <= rectangle.y1;
+ return x >= rectangle.x0
+ && x <= rectangle.x1
+ && y >= rectangle.y0
+ && y <= rectangle.y1;
}
gboolean
eel_irect_hits_irect (EelIRect rectangle_a,
- EelIRect rectangle_b)
+ EelIRect rectangle_b)
{
- EelIRect intersection;
- eel_irect_intersect (&intersection, &rectangle_a, &rectangle_b);
- return !eel_irect_is_empty (&intersection);
+ EelIRect intersection;
+ eel_irect_intersect (&intersection, &rectangle_a, &rectangle_b);
+ return !eel_irect_is_empty (&intersection);
}
gboolean
eel_irect_equal (EelIRect rectangle_a,
- EelIRect rectangle_b)
+ EelIRect rectangle_b)
{
- return rectangle_a.x0 == rectangle_b.x0
- && rectangle_a.y0 == rectangle_b.y0
- && rectangle_a.x1 == rectangle_b.x1
- && rectangle_a.y1 == rectangle_b.y1;
+ return rectangle_a.x0 == rectangle_b.x0
+ && rectangle_a.y0 == rectangle_b.y0
+ && rectangle_a.x1 == rectangle_b.x1
+ && rectangle_a.y1 == rectangle_b.y1;
}
-EelIRect
-eel_irect_offset_by (EelIRect rectangle, int x, int y)
+EelIRect
+eel_irect_offset_by (EelIRect rectangle,
+ int x,
+ int y)
{
- rectangle.x0 += x;
- rectangle.x1 += x;
- rectangle.y0 += y;
- rectangle.y1 += y;
-
- return rectangle;
+ rectangle.x0 += x;
+ rectangle.x1 += x;
+ rectangle.y0 += y;
+ rectangle.y1 += y;
+
+ return rectangle;
}
-EelIRect
-eel_irect_scale_by (EelIRect rectangle, double scale)
+EelIRect
+eel_irect_scale_by (EelIRect rectangle,
+ double scale)
{
- rectangle.x0 *= scale;
- rectangle.x1 *= scale;
- rectangle.y0 *= scale;
- rectangle.y1 *= scale;
-
- return rectangle;
+ rectangle.x0 *= scale;
+ rectangle.x1 *= scale;
+ rectangle.y0 *= scale;
+ rectangle.y1 *= scale;
+
+ return rectangle;
}
diff --git a/eel/eel-canvas.c b/eel/eel-canvas.c
index a0f7bf4dc..044beeb0d 100644
--- a/eel/eel-canvas.c
+++ b/eel/eel-canvas.c
@@ -19,7 +19,7 @@
* see <http://www.gnu.org/licenses/>.
*/
/*
- @NOTATION@
+ * @NOTATION@
*/
/*
* EelCanvas widget - Tk-like canvas widget for Gnome
@@ -70,11 +70,11 @@
#include <cairo-gobject.h>
#include "eel-canvas.h"
-static void eel_canvas_request_update (EelCanvas *canvas);
-static void group_add (EelCanvasGroup *group,
- EelCanvasItem *item);
-static void group_remove (EelCanvasGroup *group,
- EelCanvasItem *item);
+static void eel_canvas_request_update (EelCanvas *canvas);
+static void group_add (EelCanvasGroup *group,
+ EelCanvasItem *item);
+static void group_remove (EelCanvasGroup *group,
+ EelCanvasItem *item);
static void redraw_and_repick_if_mapped (EelCanvasItem *item);
/*** EelCanvasItem ***/
@@ -83,21 +83,24 @@ static void redraw_and_repick_if_mapped (EelCanvasItem *item);
#define GCI_UPDATE_MASK (EEL_CANVAS_UPDATE_REQUESTED | EEL_CANVAS_UPDATE_DEEP)
#define GCI_EPSILON 1e-18
-enum {
- ITEM_PROP_0,
- ITEM_PROP_PARENT,
- ITEM_PROP_VISIBLE
+enum
+{
+ ITEM_PROP_0,
+ ITEM_PROP_PARENT,
+ ITEM_PROP_VISIBLE
};
-enum {
- ITEM_DESTROY,
- ITEM_EVENT,
- ITEM_LAST_SIGNAL
+enum
+{
+ ITEM_DESTROY,
+ ITEM_EVENT,
+ ITEM_LAST_SIGNAL
};
-static void eel_canvas_item_class_init (EelCanvasItemClass *klass);
-static void eel_canvas_item_init (EelCanvasItem *item);
-static int emit_event (EelCanvas *canvas, GdkEvent *event);
+static void eel_canvas_item_class_init (EelCanvasItemClass *klass);
+static void eel_canvas_item_init (EelCanvasItem *item);
+static int emit_event (EelCanvas *canvas,
+ GdkEvent *event);
static guint item_signals[ITEM_LAST_SIGNAL];
@@ -118,35 +121,37 @@ static gpointer accessible_parent_class;
GType
eel_canvas_item_get_type (void)
{
- static GType canvas_item_type = 0;
-
- if (!canvas_item_type) {
- static const GTypeInfo canvas_item_info = {
- sizeof (EelCanvasItemClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) eel_canvas_item_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (EelCanvasItem),
- 0, /* n_preallocs */
- (GInstanceInitFunc) eel_canvas_item_init
- };
+ static GType canvas_item_type = 0;
- canvas_item_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED,
- "EelCanvasItem",
- &canvas_item_info,
- 0);
- }
-
- return canvas_item_type;
+ if (!canvas_item_type)
+ {
+ static const GTypeInfo canvas_item_info =
+ {
+ sizeof (EelCanvasItemClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) eel_canvas_item_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (EelCanvasItem),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) eel_canvas_item_init
+ };
+
+ canvas_item_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED,
+ "EelCanvasItem",
+ &canvas_item_info,
+ 0);
+ }
+
+ return canvas_item_type;
}
/* Object initialization function for EelCanvasItem */
static void
eel_canvas_item_init (EelCanvasItem *item)
{
- item->flags |= EEL_CANVAS_ITEM_VISIBLE;
+ item->flags |= EEL_CANVAS_ITEM_VISIBLE;
}
/**
@@ -167,21 +172,24 @@ eel_canvas_item_init (EelCanvasItem *item)
* Return value: The newly-created item.
**/
EelCanvasItem *
-eel_canvas_item_new (EelCanvasGroup *parent, GType type, const gchar *first_arg_name, ...)
+eel_canvas_item_new (EelCanvasGroup *parent,
+ GType type,
+ const gchar *first_arg_name,
+ ...)
{
- EelCanvasItem *item;
- va_list args;
+ EelCanvasItem *item;
+ va_list args;
- g_return_val_if_fail (EEL_IS_CANVAS_GROUP (parent), NULL);
- g_return_val_if_fail (g_type_is_a (type, eel_canvas_item_get_type ()), NULL);
+ g_return_val_if_fail (EEL_IS_CANVAS_GROUP (parent), NULL);
+ g_return_val_if_fail (g_type_is_a (type, eel_canvas_item_get_type ()), NULL);
- item = EEL_CANVAS_ITEM (g_object_new (type, NULL));
+ item = EEL_CANVAS_ITEM (g_object_new (type, NULL));
- va_start (args, first_arg_name);
- eel_canvas_item_construct (item, parent, first_arg_name, args);
- va_end (args);
+ va_start (args, first_arg_name);
+ eel_canvas_item_construct (item, parent, first_arg_name, args);
+ va_end (args);
- return item;
+ return item;
}
@@ -191,65 +199,90 @@ eel_canvas_item_new (EelCanvasGroup *parent, GType type, const gchar *first_arg_
static void
item_post_create_setup (EelCanvasItem *item)
{
- group_add (EEL_CANVAS_GROUP (item->parent), item);
+ group_add (EEL_CANVAS_GROUP (item->parent), item);
- redraw_and_repick_if_mapped (item);
+ redraw_and_repick_if_mapped (item);
}
/* Set_property handler for canvas items */
static void
-eel_canvas_item_set_property (GObject *gobject, guint param_id,
- const GValue *value, GParamSpec *pspec)
-{
- EelCanvasItem *item;
-
- g_return_if_fail (EEL_IS_CANVAS_ITEM (gobject));
-
- item = EEL_CANVAS_ITEM (gobject);
-
- switch (param_id) {
- case ITEM_PROP_PARENT:
- if (item->parent != NULL) {
- g_warning ("Cannot set `parent' argument after item has "
- "already been constructed.");
- } else if (g_value_get_object (value)) {
- item->parent = EEL_CANVAS_ITEM (g_value_get_object (value));
- item->canvas = item->parent->canvas;
- item_post_create_setup (item);
- }
- break;
- case ITEM_PROP_VISIBLE:
- if (g_value_get_boolean (value)) {
- eel_canvas_item_show (item);
- } else {
- eel_canvas_item_hide (item);
- }
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
- break;
- }
+eel_canvas_item_set_property (GObject *gobject,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EelCanvasItem *item;
+
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (gobject));
+
+ item = EEL_CANVAS_ITEM (gobject);
+
+ switch (param_id)
+ {
+ case ITEM_PROP_PARENT:
+ {
+ if (item->parent != NULL)
+ {
+ g_warning ("Cannot set `parent' argument after item has "
+ "already been constructed.");
+ }
+ else if (g_value_get_object (value))
+ {
+ item->parent = EEL_CANVAS_ITEM (g_value_get_object (value));
+ item->canvas = item->parent->canvas;
+ item_post_create_setup (item);
+ }
+ }
+ break;
+
+ case ITEM_PROP_VISIBLE:
+ {
+ if (g_value_get_boolean (value))
+ {
+ eel_canvas_item_show (item);
+ }
+ else
+ {
+ eel_canvas_item_hide (item);
+ }
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
+ }
+ break;
+ }
}
/* Get_property handler for canvas items */
static void
-eel_canvas_item_get_property (GObject *gobject, guint param_id,
- GValue *value, GParamSpec *pspec)
+eel_canvas_item_get_property (GObject *gobject,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- EelCanvasItem *item;
+ EelCanvasItem *item;
- g_return_if_fail (EEL_IS_CANVAS_ITEM (gobject));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (gobject));
- item = EEL_CANVAS_ITEM (gobject);
+ item = EEL_CANVAS_ITEM (gobject);
- switch (param_id) {
- case ITEM_PROP_VISIBLE:
- g_value_set_boolean (value, item->flags & EEL_CANVAS_ITEM_VISIBLE);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
- break;
- }
+ switch (param_id)
+ {
+ case ITEM_PROP_VISIBLE:
+ {
+ g_value_set_boolean (value, item->flags & EEL_CANVAS_ITEM_VISIBLE);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
+ }
+ break;
+ }
}
/**
@@ -262,135 +295,159 @@ eel_canvas_item_get_property (GObject *gobject, guint param_id,
* Constructs a canvas item; meant for use only by item implementations.
**/
void
-eel_canvas_item_construct (EelCanvasItem *item, EelCanvasGroup *parent,
- const gchar *first_arg_name, va_list args)
+eel_canvas_item_construct (EelCanvasItem *item,
+ EelCanvasGroup *parent,
+ const gchar *first_arg_name,
+ va_list args)
{
- g_return_if_fail (EEL_IS_CANVAS_GROUP (parent));
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_GROUP (parent));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- item->parent = EEL_CANVAS_ITEM (parent);
- item->canvas = item->parent->canvas;
+ item->parent = EEL_CANVAS_ITEM (parent);
+ item->canvas = item->parent->canvas;
- g_object_set_valist (G_OBJECT (item), first_arg_name, args);
+ g_object_set_valist (G_OBJECT (item), first_arg_name, args);
- item_post_create_setup (item);
+ item_post_create_setup (item);
}
static void
redraw_and_repick_if_mapped (EelCanvasItem *item)
{
- if (item->flags & EEL_CANVAS_ITEM_MAPPED) {
- eel_canvas_item_request_redraw (item);
- item->canvas->need_repick = TRUE;
- }
+ if (item->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ eel_canvas_item_request_redraw (item);
+ item->canvas->need_repick = TRUE;
+ }
}
/* Dispose handler for canvas items */
static void
eel_canvas_item_dispose (GObject *object)
{
- EelCanvasItem *item;
+ EelCanvasItem *item;
- g_return_if_fail (EEL_IS_CANVAS_ITEM (object));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (object));
- item = EEL_CANVAS_ITEM (object);
+ item = EEL_CANVAS_ITEM (object);
- if (item->canvas) {
- eel_canvas_item_request_redraw (item);
+ if (item->canvas)
+ {
+ eel_canvas_item_request_redraw (item);
- /* Make the canvas forget about us */
+ /* Make the canvas forget about us */
- if (item == item->canvas->current_item) {
- item->canvas->current_item = NULL;
- item->canvas->need_repick = TRUE;
- }
+ if (item == item->canvas->current_item)
+ {
+ item->canvas->current_item = NULL;
+ item->canvas->need_repick = TRUE;
+ }
- if (item == item->canvas->new_current_item) {
- item->canvas->new_current_item = NULL;
- item->canvas->need_repick = TRUE;
- }
+ if (item == item->canvas->new_current_item)
+ {
+ item->canvas->new_current_item = NULL;
+ item->canvas->need_repick = TRUE;
+ }
- eel_canvas_item_ungrab (item);
+ eel_canvas_item_ungrab (item);
- if (item == item->canvas->focused_item)
- item->canvas->focused_item = NULL;
+ if (item == item->canvas->focused_item)
+ {
+ item->canvas->focused_item = NULL;
+ }
- /* Normal destroy stuff */
+ /* Normal destroy stuff */
- if (item->flags & EEL_CANVAS_ITEM_MAPPED)
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->unmap) (item);
+ if (item->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->unmap)(item);
+ }
- if (item->flags & EEL_CANVAS_ITEM_REALIZED)
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->unrealize) (item);
+ if (item->flags & EEL_CANVAS_ITEM_REALIZED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->unrealize)(item);
+ }
- if (item->parent)
- group_remove (EEL_CANVAS_GROUP (item->parent), item);
+ if (item->parent)
+ {
+ group_remove (EEL_CANVAS_GROUP (item->parent), item);
+ }
- item->canvas = NULL;
- }
+ item->canvas = NULL;
+ }
- g_object_set_data (object, "in-destruction", GINT_TO_POINTER (1));
- g_signal_emit (object, item_signals[ITEM_DESTROY], 0);
+ g_object_set_data (object, "in-destruction", GINT_TO_POINTER (1));
+ g_signal_emit (object, item_signals[ITEM_DESTROY], 0);
- g_object_set_data (object, "in-destruction", NULL);
+ g_object_set_data (object, "in-destruction", NULL);
- G_OBJECT_CLASS (item_parent_class)->dispose (object);
+ G_OBJECT_CLASS (item_parent_class)->dispose (object);
}
void
eel_canvas_item_destroy (EelCanvasItem *item)
{
- if (g_object_get_data (G_OBJECT (item), "in-destruction") == NULL) {
- g_object_run_dispose (G_OBJECT (item));
- }
+ if (g_object_get_data (G_OBJECT (item), "in-destruction") == NULL)
+ {
+ g_object_run_dispose (G_OBJECT (item));
+ }
}
/* Realize handler for canvas items */
static void
eel_canvas_item_realize (EelCanvasItem *item)
{
- if (item->parent && !(item->parent->flags & EEL_CANVAS_ITEM_REALIZED))
- (* EEL_CANVAS_ITEM_GET_CLASS (item->parent)->realize) (item->parent);
-
- if (item->parent == NULL && !gtk_widget_get_realized (GTK_WIDGET (item->canvas)))
- gtk_widget_realize (GTK_WIDGET (item->canvas));
+ if (item->parent && !(item->parent->flags & EEL_CANVAS_ITEM_REALIZED))
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item->parent)->realize)(item->parent);
+ }
+
+ if (item->parent == NULL && !gtk_widget_get_realized (GTK_WIDGET (item->canvas)))
+ {
+ gtk_widget_realize (GTK_WIDGET (item->canvas));
+ }
- item->flags |= EEL_CANVAS_ITEM_REALIZED;
+ item->flags |= EEL_CANVAS_ITEM_REALIZED;
- eel_canvas_item_request_update (item);
+ eel_canvas_item_request_update (item);
}
/* Unrealize handler for canvas items */
static void
eel_canvas_item_unrealize (EelCanvasItem *item)
{
- if (item->flags & EEL_CANVAS_ITEM_MAPPED)
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->unmap) (item);
+ if (item->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->unmap)(item);
+ }
- item->flags &= ~(EEL_CANVAS_ITEM_REALIZED);
+ item->flags &= ~(EEL_CANVAS_ITEM_REALIZED);
}
/* Map handler for canvas items */
static void
eel_canvas_item_map (EelCanvasItem *item)
{
- item->flags |= EEL_CANVAS_ITEM_MAPPED;
+ item->flags |= EEL_CANVAS_ITEM_MAPPED;
}
/* Unmap handler for canvas items */
static void
eel_canvas_item_unmap (EelCanvasItem *item)
{
- item->flags &= ~(EEL_CANVAS_ITEM_MAPPED);
+ item->flags &= ~(EEL_CANVAS_ITEM_MAPPED);
}
/* Update handler for canvas items */
static void
-eel_canvas_item_update (EelCanvasItem *item, double i2w_dx, double i2w_dy, int flags)
+eel_canvas_item_update (EelCanvasItem *item,
+ double i2w_dx,
+ double i2w_dy,
+ int flags)
{
- item->flags &= ~(EEL_CANVAS_ITEM_NEED_UPDATE);
- item->flags &= ~(EEL_CANVAS_ITEM_NEED_DEEP_UPDATE);
+ item->flags &= ~(EEL_CANVAS_ITEM_NEED_UPDATE);
+ item->flags &= ~(EEL_CANVAS_ITEM_NEED_DEEP_UPDATE);
}
/*
@@ -408,31 +465,38 @@ eel_canvas_item_update (EelCanvasItem *item, double i2w_dx, double i2w_dy, int f
static void
eel_canvas_item_invoke_update (EelCanvasItem *item,
- double i2w_dx,
- double i2w_dy,
- int flags)
+ double i2w_dx,
+ double i2w_dy,
+ int flags)
{
- int child_flags;
+ int child_flags;
+
+ child_flags = flags;
- child_flags = flags;
+ /* apply object flags to child flags */
+ child_flags &= ~EEL_CANVAS_UPDATE_REQUESTED;
- /* apply object flags to child flags */
- child_flags &= ~EEL_CANVAS_UPDATE_REQUESTED;
+ if (item->flags & EEL_CANVAS_ITEM_NEED_UPDATE)
+ {
+ child_flags |= EEL_CANVAS_UPDATE_REQUESTED;
+ }
- if (item->flags & EEL_CANVAS_ITEM_NEED_UPDATE)
- child_flags |= EEL_CANVAS_UPDATE_REQUESTED;
+ if (item->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE)
+ {
+ child_flags |= EEL_CANVAS_UPDATE_DEEP;
+ }
- if (item->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE)
- child_flags |= EEL_CANVAS_UPDATE_DEEP;
+ if (child_flags & GCI_UPDATE_MASK)
+ {
+ if (EEL_CANVAS_ITEM_GET_CLASS (item)->update)
+ {
+ EEL_CANVAS_ITEM_GET_CLASS (item)->update (item, i2w_dx, i2w_dy, child_flags);
+ }
+ }
- if (child_flags & GCI_UPDATE_MASK) {
- if (EEL_CANVAS_ITEM_GET_CLASS (item)->update)
- EEL_CANVAS_ITEM_GET_CLASS (item)->update (item, i2w_dx, i2w_dy, child_flags);
- }
-
- /* If this fail you probably forgot to chain up to
- * EelCanvasItem::update from a derived class */
- g_return_if_fail (!(item->flags & EEL_CANVAS_ITEM_NEED_UPDATE));
+ /* If this fail you probably forgot to chain up to
+ * EelCanvasItem::update from a derived class */
+ g_return_if_fail (!(item->flags & EEL_CANVAS_ITEM_NEED_UPDATE));
}
/*
@@ -441,14 +505,21 @@ eel_canvas_item_invoke_update (EelCanvasItem *item,
*/
static double
-eel_canvas_item_invoke_point (EelCanvasItem *item, double x, double y, int cx, int cy, EelCanvasItem **actual_item)
+eel_canvas_item_invoke_point (EelCanvasItem *item,
+ double x,
+ double y,
+ int cx,
+ int cy,
+ EelCanvasItem **actual_item)
{
- /* Calculate x & y in item local coordinates */
+ /* Calculate x & y in item local coordinates */
- if (EEL_CANVAS_ITEM_GET_CLASS (item)->point)
- return EEL_CANVAS_ITEM_GET_CLASS (item)->point (item, x, y, cx, cy, actual_item);
+ if (EEL_CANVAS_ITEM_GET_CLASS (item)->point)
+ {
+ return EEL_CANVAS_ITEM_GET_CLASS (item)->point (item, x, y, cx, cy, actual_item);
+ }
- return 1e18;
+ return 1e18;
}
/**
@@ -461,13 +532,15 @@ eel_canvas_item_invoke_point (EelCanvasItem *item, double x, double y, int cx, i
* values, and the item is repainted as appropriate.
**/
void
-eel_canvas_item_set (EelCanvasItem *item, const gchar *first_arg_name, ...)
+eel_canvas_item_set (EelCanvasItem *item,
+ const gchar *first_arg_name,
+ ...)
{
- va_list args;
+ va_list args;
- va_start (args, first_arg_name);
- eel_canvas_item_set_valist (item, first_arg_name, args);
- va_end (args);
+ va_start (args, first_arg_name);
+ eel_canvas_item_set_valist (item, first_arg_name, args);
+ va_end (args);
}
@@ -481,13 +554,15 @@ eel_canvas_item_set (EelCanvasItem *item, const gchar *first_arg_name, ...)
* values, and the item is repainted as appropriate.
**/
void
-eel_canvas_item_set_valist (EelCanvasItem *item, const gchar *first_arg_name, va_list args)
+eel_canvas_item_set_valist (EelCanvasItem *item,
+ const gchar *first_arg_name,
+ va_list args)
{
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- g_object_set_valist (G_OBJECT (item), first_arg_name, args);
+ g_object_set_valist (G_OBJECT (item), first_arg_name, args);
- item->canvas->need_repick = TRUE;
+ item->canvas->need_repick = TRUE;
}
@@ -503,92 +578,126 @@ eel_canvas_item_set_valist (EelCanvasItem *item, const gchar *first_arg_name, va
* most probably does not do, what you want.
**/
void
-eel_canvas_item_move (EelCanvasItem *item, double dx, double dy)
+eel_canvas_item_move (EelCanvasItem *item,
+ double dx,
+ double dy)
{
- g_return_if_fail (item != NULL);
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (item != NULL);
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- if (!EEL_CANVAS_ITEM_GET_CLASS (item)->translate) {
- g_warning ("Item type %s does not implement translate method.\n",
- g_type_name (G_OBJECT_TYPE (item)));
- return;
- }
-
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->translate) (item, dx, dy);
+ if (!EEL_CANVAS_ITEM_GET_CLASS (item)->translate)
+ {
+ g_warning ("Item type %s does not implement translate method.\n",
+ g_type_name (G_OBJECT_TYPE (item)));
+ return;
+ }
- if (item->flags & EEL_CANVAS_ITEM_MAPPED)
- item->canvas->need_repick = TRUE;
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->translate)(item, dx, dy);
- if (!(item->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE)) {
- item->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
- if (item->parent != NULL)
- eel_canvas_item_request_update (item->parent);
- else
- eel_canvas_request_update (item->canvas);
- }
+ if (item->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ item->canvas->need_repick = TRUE;
+ }
+ if (!(item->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE))
+ {
+ item->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
+ if (item->parent != NULL)
+ {
+ eel_canvas_item_request_update (item->parent);
+ }
+ else
+ {
+ eel_canvas_request_update (item->canvas);
+ }
+ }
}
static void
eel_canvas_queue_resize (EelCanvas *canvas)
{
- if (gtk_widget_is_drawable (GTK_WIDGET (canvas)))
- gtk_widget_queue_resize (GTK_WIDGET (canvas));
+ if (gtk_widget_is_drawable (GTK_WIDGET (canvas)))
+ {
+ gtk_widget_queue_resize (GTK_WIDGET (canvas));
+ }
}
/* Convenience function to reorder items in a group's child list. This puts the
* specified link after the "before" link. Returns TRUE if the list was changed.
*/
static gboolean
-put_item_after (GList *link, GList *before)
+put_item_after (GList *link,
+ GList *before)
{
- EelCanvasGroup *parent;
+ EelCanvasGroup *parent;
- if (link == before)
- return FALSE;
+ if (link == before)
+ {
+ return FALSE;
+ }
- parent = EEL_CANVAS_GROUP (EEL_CANVAS_ITEM (link->data)->parent);
+ parent = EEL_CANVAS_GROUP (EEL_CANVAS_ITEM (link->data)->parent);
- if (before == NULL) {
- if (link == parent->item_list)
- return FALSE;
+ if (before == NULL)
+ {
+ if (link == parent->item_list)
+ {
+ return FALSE;
+ }
- link->prev->next = link->next;
+ link->prev->next = link->next;
- if (link->next)
- link->next->prev = link->prev;
- else
- parent->item_list_end = link->prev;
+ if (link->next)
+ {
+ link->next->prev = link->prev;
+ }
+ else
+ {
+ parent->item_list_end = link->prev;
+ }
- link->prev = before;
- link->next = parent->item_list;
- link->next->prev = link;
- parent->item_list = link;
- } else {
- if ((link == parent->item_list_end) && (before == parent->item_list_end->prev))
- return FALSE;
+ link->prev = before;
+ link->next = parent->item_list;
+ link->next->prev = link;
+ parent->item_list = link;
+ }
+ else
+ {
+ if ((link == parent->item_list_end) && (before == parent->item_list_end->prev))
+ {
+ return FALSE;
+ }
- if (link->next)
- link->next->prev = link->prev;
+ if (link->next)
+ {
+ link->next->prev = link->prev;
+ }
- if (link->prev)
- link->prev->next = link->next;
- else {
- parent->item_list = link->next;
- parent->item_list->prev = NULL;
- }
+ if (link->prev)
+ {
+ link->prev->next = link->next;
+ }
+ else
+ {
+ parent->item_list = link->next;
+ parent->item_list->prev = NULL;
+ }
- link->prev = before;
- link->next = before->next;
+ link->prev = before;
+ link->next = before->next;
- link->prev->next = link;
+ link->prev->next = link;
- if (link->next)
- link->next->prev = link;
- else
- parent->item_list_end = link;
- }
- return TRUE;
+ if (link->next)
+ {
+ link->next->prev = link;
+ }
+ else
+ {
+ parent->item_list_end = link;
+ }
+ }
+ return TRUE;
}
@@ -602,30 +711,38 @@ put_item_after (GList *link, GList *before)
* stack, then the item is put at the top.
**/
void
-eel_canvas_item_raise (EelCanvasItem *item, int positions)
+eel_canvas_item_raise (EelCanvasItem *item,
+ int positions)
{
- GList *link, *before;
- EelCanvasGroup *parent;
-
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- g_return_if_fail (positions >= 0);
-
- if (!item->parent || positions == 0)
- return;
-
- parent = EEL_CANVAS_GROUP (item->parent);
- link = g_list_find (parent->item_list, item);
- g_assert (link != NULL);
+ GList *link, *before;
+ EelCanvasGroup *parent;
- for (before = link; positions && before; positions--)
- before = before->next;
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (positions >= 0);
- if (!before)
- before = parent->item_list_end;
-
- if (put_item_after (link, before)) {
- redraw_and_repick_if_mapped (item);
- }
+ if (!item->parent || positions == 0)
+ {
+ return;
+ }
+
+ parent = EEL_CANVAS_GROUP (item->parent);
+ link = g_list_find (parent->item_list, item);
+ g_assert (link != NULL);
+
+ for (before = link; positions && before; positions--)
+ {
+ before = before->next;
+ }
+
+ if (!before)
+ {
+ before = parent->item_list_end;
+ }
+
+ if (put_item_after (link, before))
+ {
+ redraw_and_repick_if_mapped (item);
+ }
}
@@ -639,30 +756,40 @@ eel_canvas_item_raise (EelCanvasItem *item, int positions)
* stack, then the item is put at the bottom.
**/
void
-eel_canvas_item_lower (EelCanvasItem *item, int positions)
+eel_canvas_item_lower (EelCanvasItem *item,
+ int positions)
{
- GList *link, *before;
- EelCanvasGroup *parent;
-
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- g_return_if_fail (positions >= 1);
+ GList *link, *before;
+ EelCanvasGroup *parent;
- if (!item->parent || positions == 0)
- return;
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (positions >= 1);
- parent = EEL_CANVAS_GROUP (item->parent);
- link = g_list_find (parent->item_list, item);
- g_assert (link != NULL);
+ if (!item->parent || positions == 0)
+ {
+ return;
+ }
- if (link->prev)
- for (before = link->prev; positions && before; positions--)
- before = before->prev;
- else
- before = NULL;
+ parent = EEL_CANVAS_GROUP (item->parent);
+ link = g_list_find (parent->item_list, item);
+ g_assert (link != NULL);
- if (put_item_after (link, before)) {
- redraw_and_repick_if_mapped (item);
- }
+ if (link->prev)
+ {
+ for (before = link->prev; positions && before; positions--)
+ {
+ before = before->prev;
+ }
+ }
+ else
+ {
+ before = NULL;
+ }
+
+ if (put_item_after (link, before))
+ {
+ redraw_and_repick_if_mapped (item);
+ }
}
@@ -675,21 +802,24 @@ eel_canvas_item_lower (EelCanvasItem *item, int positions)
void
eel_canvas_item_raise_to_top (EelCanvasItem *item)
{
- GList *link;
- EelCanvasGroup *parent;
+ GList *link;
+ EelCanvasGroup *parent;
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- if (!item->parent)
- return;
+ if (!item->parent)
+ {
+ return;
+ }
- parent = EEL_CANVAS_GROUP (item->parent);
- link = g_list_find (parent->item_list, item);
- g_assert (link != NULL);
+ parent = EEL_CANVAS_GROUP (item->parent);
+ link = g_list_find (parent->item_list, item);
+ g_assert (link != NULL);
- if (put_item_after (link, parent->item_list_end)) {
- redraw_and_repick_if_mapped (item);
- }
+ if (put_item_after (link, parent->item_list_end))
+ {
+ redraw_and_repick_if_mapped (item);
+ }
}
@@ -702,21 +832,24 @@ eel_canvas_item_raise_to_top (EelCanvasItem *item)
void
eel_canvas_item_lower_to_bottom (EelCanvasItem *item)
{
- GList *link;
- EelCanvasGroup *parent;
+ GList *link;
+ EelCanvasGroup *parent;
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- if (!item->parent)
- return;
+ if (!item->parent)
+ {
+ return;
+ }
- parent = EEL_CANVAS_GROUP (item->parent);
- link = g_list_find (parent->item_list, item);
- g_assert (link != NULL);
+ parent = EEL_CANVAS_GROUP (item->parent);
+ link = g_list_find (parent->item_list, item);
+ g_assert (link != NULL);
- if (put_item_after (link, NULL)) {
- redraw_and_repick_if_mapped (item);
- }
+ if (put_item_after (link, NULL))
+ {
+ redraw_and_repick_if_mapped (item);
+ }
}
/**
@@ -730,38 +863,43 @@ eel_canvas_item_lower_to_bottom (EelCanvasItem *item)
**/
void
eel_canvas_item_send_behind (EelCanvasItem *item,
- EelCanvasItem *behind_item)
+ EelCanvasItem *behind_item)
{
- GList *item_list;
- int item_position, behind_position;
-
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ GList *item_list;
+ int item_position, behind_position;
- if (behind_item == NULL) {
- eel_canvas_item_raise_to_top (item);
- return;
- }
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- g_return_if_fail (EEL_IS_CANVAS_ITEM (behind_item));
- g_return_if_fail (item->parent == behind_item->parent);
+ if (behind_item == NULL)
+ {
+ eel_canvas_item_raise_to_top (item);
+ return;
+ }
- item_list = EEL_CANVAS_GROUP (item->parent)->item_list;
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (behind_item));
+ g_return_if_fail (item->parent == behind_item->parent);
- item_position = g_list_index (item_list, item);
- g_assert (item_position != -1);
- behind_position = g_list_index (item_list, behind_item);
- g_assert (behind_position != -1);
- g_assert (item_position != behind_position);
+ item_list = EEL_CANVAS_GROUP (item->parent)->item_list;
- if (item_position == behind_position - 1) {
- return;
- }
+ item_position = g_list_index (item_list, item);
+ g_assert (item_position != -1);
+ behind_position = g_list_index (item_list, behind_item);
+ g_assert (behind_position != -1);
+ g_assert (item_position != behind_position);
- if (item_position < behind_position) {
- eel_canvas_item_raise (item, (behind_position - 1) - item_position);
- } else {
- eel_canvas_item_lower (item, item_position - behind_position);
- }
+ if (item_position == behind_position - 1)
+ {
+ return;
+ }
+
+ if (item_position < behind_position)
+ {
+ eel_canvas_item_raise (item, (behind_position - 1) - item_position);
+ }
+ else
+ {
+ eel_canvas_item_lower (item, item_position - behind_position);
+ }
}
/**
@@ -773,27 +911,37 @@ eel_canvas_item_send_behind (EelCanvasItem *item,
void
eel_canvas_item_show (EelCanvasItem *item)
{
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- if (!(item->flags & EEL_CANVAS_ITEM_VISIBLE)) {
- item->flags |= EEL_CANVAS_ITEM_VISIBLE;
-
- if (!(item->flags & EEL_CANVAS_ITEM_REALIZED))
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->realize) (item);
+ if (!(item->flags & EEL_CANVAS_ITEM_VISIBLE))
+ {
+ item->flags |= EEL_CANVAS_ITEM_VISIBLE;
- if (item->parent != NULL) {
- if (!(item->flags & EEL_CANVAS_ITEM_MAPPED) &&
- item->parent->flags & EEL_CANVAS_ITEM_MAPPED)
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->map) (item);
- } else {
- if (!(item->flags & EEL_CANVAS_ITEM_MAPPED) &&
- gtk_widget_get_mapped (GTK_WIDGET (item->canvas)))
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->map) (item);
- }
+ if (!(item->flags & EEL_CANVAS_ITEM_REALIZED))
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->realize)(item);
+ }
- redraw_and_repick_if_mapped (item);
- eel_canvas_queue_resize (item->canvas);
- }
+ if (item->parent != NULL)
+ {
+ if (!(item->flags & EEL_CANVAS_ITEM_MAPPED) &&
+ item->parent->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->map)(item);
+ }
+ }
+ else
+ {
+ if (!(item->flags & EEL_CANVAS_ITEM_MAPPED) &&
+ gtk_widget_get_mapped (GTK_WIDGET (item->canvas)))
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->map)(item);
+ }
+ }
+
+ redraw_and_repick_if_mapped (item);
+ eel_canvas_queue_resize (item->canvas);
+ }
}
@@ -807,20 +955,23 @@ eel_canvas_item_show (EelCanvasItem *item)
void
eel_canvas_item_hide (EelCanvasItem *item)
{
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- if (item->flags & EEL_CANVAS_ITEM_VISIBLE) {
- item->flags &= ~EEL_CANVAS_ITEM_VISIBLE;
+ if (item->flags & EEL_CANVAS_ITEM_VISIBLE)
+ {
+ item->flags &= ~EEL_CANVAS_ITEM_VISIBLE;
- redraw_and_repick_if_mapped (item);
+ redraw_and_repick_if_mapped (item);
- if (item->flags & EEL_CANVAS_ITEM_MAPPED)
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->unmap) (item);
+ if (item->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->unmap)(item);
+ }
- eel_canvas_queue_resize (item->canvas);
+ eel_canvas_queue_resize (item->canvas);
- /* No need to unrealize when we just want to hide */
- }
+ /* No need to unrealize when we just want to hide */
+ }
}
@@ -828,11 +979,11 @@ eel_canvas_item_hide (EelCanvasItem *item)
* Prepare the window for grabbing, i.e. show it.
*/
static void
-seat_grab_prepare_window (GdkSeat *seat,
- GdkWindow *window,
- gpointer user_data)
+seat_grab_prepare_window (GdkSeat *seat,
+ GdkWindow *window,
+ gpointer user_data)
{
- gdk_window_show (window);
+ gdk_window_show (window);
}
/**
@@ -852,45 +1003,51 @@ seat_grab_prepare_window (GdkSeat *seat,
* gdk_seat_grab().
**/
GdkGrabStatus
-eel_canvas_item_grab (EelCanvasItem *item,
- GdkEventMask event_mask,
- GdkCursor *cursor,
- const GdkEvent *event)
+eel_canvas_item_grab (EelCanvasItem *item,
+ GdkEventMask event_mask,
+ GdkCursor *cursor,
+ const GdkEvent *event)
{
- GdkGrabStatus retval;
- GdkDisplay *display;
- GdkSeat *seat;
-
- g_return_val_if_fail (EEL_IS_CANVAS_ITEM (item), GDK_GRAB_NOT_VIEWABLE);
- g_return_val_if_fail (gtk_widget_get_mapped (GTK_WIDGET (item->canvas)),
- GDK_GRAB_NOT_VIEWABLE);
-
- if (item->canvas->grabbed_item)
- return GDK_GRAB_ALREADY_GRABBED;
-
- if (!(item->flags & EEL_CANVAS_ITEM_MAPPED))
- return GDK_GRAB_NOT_VIEWABLE;
-
- display = gtk_widget_get_display (GTK_WIDGET (item->canvas));
- seat = gdk_display_get_default_seat (display);
-
- retval = gdk_seat_grab (seat,
- gtk_layout_get_bin_window (GTK_LAYOUT (item->canvas)),
- GDK_SEAT_CAPABILITY_ALL_POINTING,
- FALSE,
- cursor,
- event,
- seat_grab_prepare_window,
- NULL);
-
- if (retval != GDK_GRAB_SUCCESS)
- return retval;
+ GdkGrabStatus retval;
+ GdkDisplay *display;
+ GdkSeat *seat;
+
+ g_return_val_if_fail (EEL_IS_CANVAS_ITEM (item), GDK_GRAB_NOT_VIEWABLE);
+ g_return_val_if_fail (gtk_widget_get_mapped (GTK_WIDGET (item->canvas)),
+ GDK_GRAB_NOT_VIEWABLE);
+
+ if (item->canvas->grabbed_item)
+ {
+ return GDK_GRAB_ALREADY_GRABBED;
+ }
+
+ if (!(item->flags & EEL_CANVAS_ITEM_MAPPED))
+ {
+ return GDK_GRAB_NOT_VIEWABLE;
+ }
+
+ display = gtk_widget_get_display (GTK_WIDGET (item->canvas));
+ seat = gdk_display_get_default_seat (display);
+
+ retval = gdk_seat_grab (seat,
+ gtk_layout_get_bin_window (GTK_LAYOUT (item->canvas)),
+ GDK_SEAT_CAPABILITY_ALL_POINTING,
+ FALSE,
+ cursor,
+ event,
+ seat_grab_prepare_window,
+ NULL);
+
+ if (retval != GDK_GRAB_SUCCESS)
+ {
+ return retval;
+ }
- item->canvas->grabbed_item = item;
- item->canvas->grabbed_event_mask = event_mask;
- item->canvas->current_item = item; /* So that events go to the grabbed item */
+ item->canvas->grabbed_item = item;
+ item->canvas->grabbed_event_mask = event_mask;
+ item->canvas->current_item = item; /* So that events go to the grabbed item */
- return retval;
+ return retval;
}
@@ -904,19 +1061,21 @@ eel_canvas_item_grab (EelCanvasItem *item,
void
eel_canvas_item_ungrab (EelCanvasItem *item)
{
- GdkDisplay *display;
- GdkSeat *seat;
+ GdkDisplay *display;
+ GdkSeat *seat;
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- if (item->canvas->grabbed_item != item)
- return;
+ if (item->canvas->grabbed_item != item)
+ {
+ return;
+ }
- display = gtk_widget_get_display (GTK_WIDGET (item->canvas));
- seat = gdk_display_get_default_seat (display);
+ display = gtk_widget_get_display (GTK_WIDGET (item->canvas));
+ seat = gdk_display_get_default_seat (display);
- item->canvas->grabbed_item = NULL;
- gdk_seat_ungrab (seat);
+ item->canvas->grabbed_item = NULL;
+ gdk_seat_ungrab (seat);
}
/**
@@ -929,21 +1088,25 @@ eel_canvas_item_ungrab (EelCanvasItem *item)
* coordinates.
**/
void
-eel_canvas_item_w2i (EelCanvasItem *item, double *x, double *y)
+eel_canvas_item_w2i (EelCanvasItem *item,
+ double *x,
+ double *y)
{
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- g_return_if_fail (x != NULL);
- g_return_if_fail (y != NULL);
-
- item = item->parent;
- while (item) {
- if (EEL_IS_CANVAS_GROUP (item)) {
- *x -= EEL_CANVAS_GROUP (item)->xpos;
- *y -= EEL_CANVAS_GROUP (item)->ypos;
- }
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (x != NULL);
+ g_return_if_fail (y != NULL);
+
+ item = item->parent;
+ while (item)
+ {
+ if (EEL_IS_CANVAS_GROUP (item))
+ {
+ *x -= EEL_CANVAS_GROUP (item)->xpos;
+ *y -= EEL_CANVAS_GROUP (item)->ypos;
+ }
- item = item->parent;
- }
+ item = item->parent;
+ }
}
@@ -957,32 +1120,41 @@ eel_canvas_item_w2i (EelCanvasItem *item, double *x, double *y)
* coordinates.
**/
void
-eel_canvas_item_i2w (EelCanvasItem *item, double *x, double *y)
+eel_canvas_item_i2w (EelCanvasItem *item,
+ double *x,
+ double *y)
{
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- g_return_if_fail (x != NULL);
- g_return_if_fail (y != NULL);
-
- item = item->parent;
- while (item) {
- if (EEL_IS_CANVAS_GROUP (item)) {
- *x += EEL_CANVAS_GROUP (item)->xpos;
- *y += EEL_CANVAS_GROUP (item)->ypos;
- }
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (x != NULL);
+ g_return_if_fail (y != NULL);
+
+ item = item->parent;
+ while (item)
+ {
+ if (EEL_IS_CANVAS_GROUP (item))
+ {
+ *x += EEL_CANVAS_GROUP (item)->xpos;
+ *y += EEL_CANVAS_GROUP (item)->ypos;
+ }
- item = item->parent;
- }
+ item = item->parent;
+ }
}
/* Returns whether the item is an inferior of or is equal to the parent. */
static int
-is_descendant (EelCanvasItem *item, EelCanvasItem *parent)
+is_descendant (EelCanvasItem *item,
+ EelCanvasItem *parent)
{
- for (; item; item = item->parent)
- if (item == parent)
- return TRUE;
+ for (; item; item = item->parent)
+ {
+ if (item == parent)
+ {
+ return TRUE;
+ }
+ }
- return FALSE;
+ return FALSE;
}
/**
@@ -995,35 +1167,36 @@ is_descendant (EelCanvasItem *item, EelCanvasItem *parent)
* its absolute position within the canvas.
**/
void
-eel_canvas_item_reparent (EelCanvasItem *item, EelCanvasGroup *new_group)
+eel_canvas_item_reparent (EelCanvasItem *item,
+ EelCanvasGroup *new_group)
{
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- g_return_if_fail (EEL_IS_CANVAS_GROUP (new_group));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_GROUP (new_group));
- /* Both items need to be in the same canvas */
- g_return_if_fail (item->canvas == EEL_CANVAS_ITEM (new_group)->canvas);
+ /* Both items need to be in the same canvas */
+ g_return_if_fail (item->canvas == EEL_CANVAS_ITEM (new_group)->canvas);
- /* The group cannot be an inferior of the item or be the item itself --
- * this also takes care of the case where the item is the root item of
- * the canvas. */
- g_return_if_fail (!is_descendant (EEL_CANVAS_ITEM (new_group), item));
+ /* The group cannot be an inferior of the item or be the item itself --
+ * this also takes care of the case where the item is the root item of
+ * the canvas. */
+ g_return_if_fail (!is_descendant (EEL_CANVAS_ITEM (new_group), item));
- /* Everything is ok, now actually reparent the item */
+ /* Everything is ok, now actually reparent the item */
- g_object_ref (G_OBJECT (item)); /* protect it from the unref in group_remove */
+ g_object_ref (G_OBJECT (item)); /* protect it from the unref in group_remove */
- eel_canvas_item_request_redraw (item);
+ eel_canvas_item_request_redraw (item);
- group_remove (EEL_CANVAS_GROUP (item->parent), item);
- item->parent = EEL_CANVAS_ITEM (new_group);
- /* item->canvas is unchanged. */
- group_add (new_group, item);
+ group_remove (EEL_CANVAS_GROUP (item->parent), item);
+ item->parent = EEL_CANVAS_ITEM (new_group);
+ /* item->canvas is unchanged. */
+ group_add (new_group, item);
- /* Redraw and repick */
+ /* Redraw and repick */
- redraw_and_repick_if_mapped (item);
+ redraw_and_repick_if_mapped (item);
- g_object_unref (G_OBJECT (item));
+ g_object_unref (G_OBJECT (item));
}
/**
@@ -1037,34 +1210,36 @@ eel_canvas_item_reparent (EelCanvasItem *item, EelCanvasGroup *new_group)
void
eel_canvas_item_grab_focus (EelCanvasItem *item)
{
- EelCanvasItem *focused_item;
- GdkEvent ev;
+ EelCanvasItem *focused_item;
+ GdkEvent ev;
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- g_return_if_fail (gtk_widget_get_can_focus (GTK_WIDGET (item->canvas)));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (gtk_widget_get_can_focus (GTK_WIDGET (item->canvas)));
- focused_item = item->canvas->focused_item;
+ focused_item = item->canvas->focused_item;
- if (focused_item) {
- ev.focus_change.type = GDK_FOCUS_CHANGE;
- ev.focus_change.window = gtk_layout_get_bin_window (GTK_LAYOUT (item->canvas));
- ev.focus_change.send_event = FALSE;
- ev.focus_change.in = FALSE;
+ if (focused_item)
+ {
+ ev.focus_change.type = GDK_FOCUS_CHANGE;
+ ev.focus_change.window = gtk_layout_get_bin_window (GTK_LAYOUT (item->canvas));
+ ev.focus_change.send_event = FALSE;
+ ev.focus_change.in = FALSE;
- emit_event (item->canvas, &ev);
- }
+ emit_event (item->canvas, &ev);
+ }
- item->canvas->focused_item = item;
- gtk_widget_grab_focus (GTK_WIDGET (item->canvas));
+ item->canvas->focused_item = item;
+ gtk_widget_grab_focus (GTK_WIDGET (item->canvas));
- if (focused_item) {
- ev.focus_change.type = GDK_FOCUS_CHANGE;
- ev.focus_change.window = gtk_layout_get_bin_window (GTK_LAYOUT (item->canvas));
- ev.focus_change.send_event = FALSE;
- ev.focus_change.in = TRUE;
+ if (focused_item)
+ {
+ ev.focus_change.type = GDK_FOCUS_CHANGE;
+ ev.focus_change.window = gtk_layout_get_bin_window (GTK_LAYOUT (item->canvas));
+ ev.focus_change.send_event = FALSE;
+ ev.focus_change.in = TRUE;
- emit_event (item->canvas, &ev);
- }
+ emit_event (item->canvas, &ev);
+ }
}
@@ -1080,32 +1255,46 @@ eel_canvas_item_grab_focus (EelCanvasItem *item)
* coordinate system of the item's parent.
**/
void
-eel_canvas_item_get_bounds (EelCanvasItem *item, double *x1, double *y1, double *x2, double *y2)
+eel_canvas_item_get_bounds (EelCanvasItem *item,
+ double *x1,
+ double *y1,
+ double *x2,
+ double *y2)
{
- double tx1, ty1, tx2, ty2;
+ double tx1, ty1, tx2, ty2;
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- tx1 = ty1 = tx2 = ty2 = 0.0;
+ tx1 = ty1 = tx2 = ty2 = 0.0;
- /* Get the item's bounds in its coordinate system */
+ /* Get the item's bounds in its coordinate system */
- if (EEL_CANVAS_ITEM_GET_CLASS (item)->bounds)
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->bounds) (item, &tx1, &ty1, &tx2, &ty2);
+ if (EEL_CANVAS_ITEM_GET_CLASS (item)->bounds)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->bounds)(item, &tx1, &ty1, &tx2, &ty2);
+ }
- /* Return the values */
+ /* Return the values */
- if (x1)
- *x1 = tx1;
+ if (x1)
+ {
+ *x1 = tx1;
+ }
- if (y1)
- *y1 = ty1;
+ if (y1)
+ {
+ *y1 = ty1;
+ }
- if (x2)
- *x2 = tx2;
+ if (x2)
+ {
+ *x2 = tx2;
+ }
- if (y2)
- *y2 = ty2;
+ if (y2)
+ {
+ *y2 = ty2;
+ }
}
@@ -1119,23 +1308,30 @@ eel_canvas_item_get_bounds (EelCanvasItem *item, double *x1, double *y1, double
void
eel_canvas_item_request_update (EelCanvasItem *item)
{
- if (NULL == item->canvas)
- return;
-
- g_return_if_fail (!item->canvas->doing_update);
-
- if (item->flags & EEL_CANVAS_ITEM_NEED_UPDATE)
- return;
+ if (NULL == item->canvas)
+ {
+ return;
+ }
- item->flags |= EEL_CANVAS_ITEM_NEED_UPDATE;
+ g_return_if_fail (!item->canvas->doing_update);
- if (item->parent != NULL) {
- /* Recurse up the tree */
- eel_canvas_item_request_update (item->parent);
- } else {
- /* Have reached the top of the tree, make sure the update call gets scheduled. */
- eel_canvas_request_update (item->canvas);
- }
+ if (item->flags & EEL_CANVAS_ITEM_NEED_UPDATE)
+ {
+ return;
+ }
+
+ item->flags |= EEL_CANVAS_ITEM_NEED_UPDATE;
+
+ if (item->parent != NULL)
+ {
+ /* Recurse up the tree */
+ eel_canvas_item_request_update (item->parent);
+ }
+ else
+ {
+ /* Have reached the top of the tree, make sure the update call gets scheduled. */
+ eel_canvas_request_update (item->canvas);
+ }
}
/**
@@ -1148,10 +1344,12 @@ eel_canvas_item_request_update (EelCanvasItem *item)
void
eel_canvas_item_request_redraw (EelCanvasItem *item)
{
- if (item->flags & EEL_CANVAS_ITEM_MAPPED)
- eel_canvas_request_redraw (item->canvas,
- item->x1, item->y1,
- item->x2 + 1, item->y2 + 1);
+ if (item->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ eel_canvas_request_redraw (item->canvas,
+ item->x1, item->y1,
+ item->x2 + 1, item->y2 + 1);
+ }
}
@@ -1159,42 +1357,51 @@ eel_canvas_item_request_redraw (EelCanvasItem *item)
/*** EelCanvasGroup ***/
-enum {
- GROUP_PROP_0,
- GROUP_PROP_X,
- GROUP_PROP_Y
+enum
+{
+ GROUP_PROP_0,
+ GROUP_PROP_X,
+ GROUP_PROP_Y
};
-static void eel_canvas_group_class_init (EelCanvasGroupClass *klass);
-static void eel_canvas_group_init (EelCanvasGroup *group);
-static void eel_canvas_group_set_property(GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
-static void eel_canvas_group_get_property(GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-
-static void eel_canvas_group_destroy (EelCanvasItem *object);
-
-static void eel_canvas_group_update (EelCanvasItem *item,
- double i2w_dx,
- double i2w_dy,
- int flags);
-static void eel_canvas_group_unrealize (EelCanvasItem *item);
-static void eel_canvas_group_map (EelCanvasItem *item);
-static void eel_canvas_group_unmap (EelCanvasItem *item);
-static void eel_canvas_group_draw (EelCanvasItem *item,
- cairo_t *cr,
- cairo_region_t *region);
-static double eel_canvas_group_point (EelCanvasItem *item, double x, double y,
- int cx, int cy,
- EelCanvasItem **actual_item);
-static void eel_canvas_group_translate (EelCanvasItem *item, double dx, double dy);
-static void eel_canvas_group_bounds (EelCanvasItem *item, double *x1, double *y1,
- double *x2, double *y2);
+static void eel_canvas_group_class_init (EelCanvasGroupClass *klass);
+static void eel_canvas_group_init (EelCanvasGroup *group);
+static void eel_canvas_group_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void eel_canvas_group_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+static void eel_canvas_group_destroy (EelCanvasItem *object);
+
+static void eel_canvas_group_update (EelCanvasItem *item,
+ double i2w_dx,
+ double i2w_dy,
+ int flags);
+static void eel_canvas_group_unrealize (EelCanvasItem *item);
+static void eel_canvas_group_map (EelCanvasItem *item);
+static void eel_canvas_group_unmap (EelCanvasItem *item);
+static void eel_canvas_group_draw (EelCanvasItem *item,
+ cairo_t *cr,
+ cairo_region_t *region);
+static double eel_canvas_group_point (EelCanvasItem *item,
+ double x,
+ double y,
+ int cx,
+ int cy,
+ EelCanvasItem **actual_item);
+static void eel_canvas_group_translate (EelCanvasItem *item,
+ double dx,
+ double dy);
+static void eel_canvas_group_bounds (EelCanvasItem *item,
+ double *x1,
+ double *y1,
+ double *x2,
+ double *y2);
static EelCanvasItemClass *group_parent_class;
@@ -1211,286 +1418,335 @@ static EelCanvasItemClass *group_parent_class;
GType
eel_canvas_group_get_type (void)
{
- static GType group_type = 0;
-
- if (!group_type) {
- static const GTypeInfo group_info = {
- sizeof (EelCanvasGroupClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) eel_canvas_group_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (EelCanvasGroup),
- 0, /* n_preallocs */
- (GInstanceInitFunc) eel_canvas_group_init
-
-
- };
-
- group_type = g_type_register_static (eel_canvas_item_get_type (),
- "EelCanvasGroup",
- &group_info,
- 0);
- }
+ static GType group_type = 0;
- return group_type;
+ if (!group_type)
+ {
+ static const GTypeInfo group_info =
+ {
+ sizeof (EelCanvasGroupClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) eel_canvas_group_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (EelCanvasGroup),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) eel_canvas_group_init
+ };
+
+ group_type = g_type_register_static (eel_canvas_item_get_type (),
+ "EelCanvasGroup",
+ &group_info,
+ 0);
+ }
+
+ return group_type;
}
/* Class initialization function for EelCanvasGroupClass */
static void
eel_canvas_group_class_init (EelCanvasGroupClass *klass)
{
- GObjectClass *gobject_class;
- EelCanvasItemClass *item_class;
-
- gobject_class = (GObjectClass *) klass;
- item_class = (EelCanvasItemClass *) klass;
-
- group_parent_class = g_type_class_peek_parent (klass);
-
- gobject_class->set_property = eel_canvas_group_set_property;
- gobject_class->get_property = eel_canvas_group_get_property;
-
- g_object_class_install_property
- (gobject_class, GROUP_PROP_X,
- g_param_spec_double ("x",
- _("X"),
- _("X"),
- -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
- g_object_class_install_property
- (gobject_class, GROUP_PROP_Y,
- g_param_spec_double ("y",
- _("Y"),
- _("Y"),
- -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- item_class->destroy = eel_canvas_group_destroy;
- item_class->update = eel_canvas_group_update;
- item_class->unrealize = eel_canvas_group_unrealize;
- item_class->map = eel_canvas_group_map;
- item_class->unmap = eel_canvas_group_unmap;
- item_class->draw = eel_canvas_group_draw;
- item_class->point = eel_canvas_group_point;
- item_class->translate = eel_canvas_group_translate;
- item_class->bounds = eel_canvas_group_bounds;
+ GObjectClass *gobject_class;
+ EelCanvasItemClass *item_class;
+
+ gobject_class = (GObjectClass *) klass;
+ item_class = (EelCanvasItemClass *) klass;
+
+ group_parent_class = g_type_class_peek_parent (klass);
+
+ gobject_class->set_property = eel_canvas_group_set_property;
+ gobject_class->get_property = eel_canvas_group_get_property;
+
+ g_object_class_install_property
+ (gobject_class, GROUP_PROP_X,
+ g_param_spec_double ("x",
+ _("X"),
+ _("X"),
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property
+ (gobject_class, GROUP_PROP_Y,
+ g_param_spec_double ("y",
+ _("Y"),
+ _("Y"),
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
+
+ item_class->destroy = eel_canvas_group_destroy;
+ item_class->update = eel_canvas_group_update;
+ item_class->unrealize = eel_canvas_group_unrealize;
+ item_class->map = eel_canvas_group_map;
+ item_class->unmap = eel_canvas_group_unmap;
+ item_class->draw = eel_canvas_group_draw;
+ item_class->point = eel_canvas_group_point;
+ item_class->translate = eel_canvas_group_translate;
+ item_class->bounds = eel_canvas_group_bounds;
}
/* Object initialization function for EelCanvasGroup */
static void
eel_canvas_group_init (EelCanvasGroup *group)
{
- group->xpos = 0.0;
- group->ypos = 0.0;
+ group->xpos = 0.0;
+ group->ypos = 0.0;
}
/* Set_property handler for canvas groups */
static void
-eel_canvas_group_set_property (GObject *gobject, guint param_id,
- const GValue *value, GParamSpec *pspec)
-{
- EelCanvasItem *item;
- EelCanvasGroup *group;
- double old;
- gboolean moved;
-
- g_return_if_fail (EEL_IS_CANVAS_GROUP (gobject));
-
- item = EEL_CANVAS_ITEM (gobject);
- group = EEL_CANVAS_GROUP (gobject);
-
- moved = FALSE;
- switch (param_id) {
- case GROUP_PROP_X:
- old = group->xpos;
- group->xpos = g_value_get_double (value);
- if (old != group->xpos)
- moved = TRUE;
- break;
-
- case GROUP_PROP_Y:
- old = group->ypos;
- group->ypos = g_value_get_double (value);
- if (old != group->ypos)
- moved = TRUE;
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
- break;
- }
-
- if (moved) {
- item->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
- if (item->parent != NULL)
- eel_canvas_item_request_update (item->parent);
- else
- eel_canvas_request_update (item->canvas);
- }
+eel_canvas_group_set_property (GObject *gobject,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EelCanvasItem *item;
+ EelCanvasGroup *group;
+ double old;
+ gboolean moved;
+
+ g_return_if_fail (EEL_IS_CANVAS_GROUP (gobject));
+
+ item = EEL_CANVAS_ITEM (gobject);
+ group = EEL_CANVAS_GROUP (gobject);
+
+ moved = FALSE;
+ switch (param_id)
+ {
+ case GROUP_PROP_X:
+ {
+ old = group->xpos;
+ group->xpos = g_value_get_double (value);
+ if (old != group->xpos)
+ {
+ moved = TRUE;
+ }
+ }
+ break;
+
+ case GROUP_PROP_Y:
+ {
+ old = group->ypos;
+ group->ypos = g_value_get_double (value);
+ if (old != group->ypos)
+ {
+ moved = TRUE;
+ }
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
+ }
+ break;
+ }
+
+ if (moved)
+ {
+ item->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
+ if (item->parent != NULL)
+ {
+ eel_canvas_item_request_update (item->parent);
+ }
+ else
+ {
+ eel_canvas_request_update (item->canvas);
+ }
+ }
}
/* Get_property handler for canvas groups */
static void
-eel_canvas_group_get_property (GObject *gobject, guint param_id,
- GValue *value, GParamSpec *pspec)
+eel_canvas_group_get_property (GObject *gobject,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- EelCanvasGroup *group;
+ EelCanvasGroup *group;
- g_return_if_fail (EEL_IS_CANVAS_GROUP (gobject));
+ g_return_if_fail (EEL_IS_CANVAS_GROUP (gobject));
- group = EEL_CANVAS_GROUP (gobject);
+ group = EEL_CANVAS_GROUP (gobject);
- switch (param_id) {
- case GROUP_PROP_X:
- g_value_set_double (value, group->xpos);
- break;
+ switch (param_id)
+ {
+ case GROUP_PROP_X:
+ {
+ g_value_set_double (value, group->xpos);
+ }
+ break;
- case GROUP_PROP_Y:
- g_value_set_double (value, group->ypos);
- break;
+ case GROUP_PROP_Y:
+ {
+ g_value_set_double (value, group->ypos);
+ }
+ break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
- break;
- }
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
+ }
+ break;
+ }
}
/* Destroy handler for canvas groups */
static void
eel_canvas_group_destroy (EelCanvasItem *object)
{
- EelCanvasGroup *group;
- EelCanvasItem *child;
- GList *list;
+ EelCanvasGroup *group;
+ EelCanvasItem *child;
+ GList *list;
- g_return_if_fail (EEL_IS_CANVAS_GROUP (object));
+ g_return_if_fail (EEL_IS_CANVAS_GROUP (object));
- group = EEL_CANVAS_GROUP (object);
+ group = EEL_CANVAS_GROUP (object);
- list = group->item_list;
- while (list) {
- child = list->data;
- list = list->next;
+ list = group->item_list;
+ while (list)
+ {
+ child = list->data;
+ list = list->next;
- eel_canvas_item_destroy (child);
- }
+ eel_canvas_item_destroy (child);
+ }
- if (EEL_CANVAS_ITEM_CLASS (group_parent_class)->destroy)
- (* EEL_CANVAS_ITEM_CLASS (group_parent_class)->destroy) (object);
+ if (EEL_CANVAS_ITEM_CLASS (group_parent_class)->destroy)
+ {
+ (*EEL_CANVAS_ITEM_CLASS (group_parent_class)->destroy)(object);
+ }
}
/* Update handler for canvas groups */
static void
-eel_canvas_group_update (EelCanvasItem *item, double i2w_dx, double i2w_dy, int flags)
-{
- EelCanvasGroup *group;
- GList *list;
- EelCanvasItem *i;
- double bbox_x0, bbox_y0, bbox_x1, bbox_y1;
- gboolean first = TRUE;
-
- group = EEL_CANVAS_GROUP (item);
-
- (* group_parent_class->update) (item, i2w_dx, i2w_dy, flags);
-
- bbox_x0 = 0;
- bbox_y0 = 0;
- bbox_x1 = 0;
- bbox_y1 = 0;
-
- for (list = group->item_list; list; list = list->next) {
- i = list->data;
-
- eel_canvas_item_invoke_update (i, i2w_dx + group->xpos, i2w_dy + group->ypos, flags);
-
- if (first) {
- first = FALSE;
- bbox_x0 = i->x1;
- bbox_y0 = i->y1;
- bbox_x1 = i->x2;
- bbox_y1 = i->y2;
- } else {
- bbox_x0 = MIN (bbox_x0, i->x1);
- bbox_y0 = MIN (bbox_y0, i->y1);
- bbox_x1 = MAX (bbox_x1, i->x2);
- bbox_y1 = MAX (bbox_y1, i->y2);
- }
- }
- item->x1 = bbox_x0;
- item->y1 = bbox_y0;
- item->x2 = bbox_x1;
- item->y2 = bbox_y1;
+eel_canvas_group_update (EelCanvasItem *item,
+ double i2w_dx,
+ double i2w_dy,
+ int flags)
+{
+ EelCanvasGroup *group;
+ GList *list;
+ EelCanvasItem *i;
+ double bbox_x0, bbox_y0, bbox_x1, bbox_y1;
+ gboolean first = TRUE;
+
+ group = EEL_CANVAS_GROUP (item);
+
+ (*group_parent_class->update)(item, i2w_dx, i2w_dy, flags);
+
+ bbox_x0 = 0;
+ bbox_y0 = 0;
+ bbox_x1 = 0;
+ bbox_y1 = 0;
+
+ for (list = group->item_list; list; list = list->next)
+ {
+ i = list->data;
+
+ eel_canvas_item_invoke_update (i, i2w_dx + group->xpos, i2w_dy + group->ypos, flags);
+
+ if (first)
+ {
+ first = FALSE;
+ bbox_x0 = i->x1;
+ bbox_y0 = i->y1;
+ bbox_x1 = i->x2;
+ bbox_y1 = i->y2;
+ }
+ else
+ {
+ bbox_x0 = MIN (bbox_x0, i->x1);
+ bbox_y0 = MIN (bbox_y0, i->y1);
+ bbox_x1 = MAX (bbox_x1, i->x2);
+ bbox_y1 = MAX (bbox_y1, i->y2);
+ }
+ }
+ item->x1 = bbox_x0;
+ item->y1 = bbox_y0;
+ item->x2 = bbox_x1;
+ item->y2 = bbox_y1;
}
/* Unrealize handler for canvas groups */
static void
eel_canvas_group_unrealize (EelCanvasItem *item)
{
- EelCanvasGroup *group;
- GList *list;
- EelCanvasItem *i;
+ EelCanvasGroup *group;
+ GList *list;
+ EelCanvasItem *i;
- group = EEL_CANVAS_GROUP (item);
+ group = EEL_CANVAS_GROUP (item);
- /* Unmap group before children to avoid flash */
- if (item->flags & EEL_CANVAS_ITEM_MAPPED)
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->unmap) (item);
+ /* Unmap group before children to avoid flash */
+ if (item->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->unmap)(item);
+ }
- for (list = group->item_list; list; list = list->next) {
- i = list->data;
+ for (list = group->item_list; list; list = list->next)
+ {
+ i = list->data;
- if (i->flags & EEL_CANVAS_ITEM_REALIZED)
- (* EEL_CANVAS_ITEM_GET_CLASS (i)->unrealize) (i);
- }
+ if (i->flags & EEL_CANVAS_ITEM_REALIZED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (i)->unrealize)(i);
+ }
+ }
- (* group_parent_class->unrealize) (item);
+ (*group_parent_class->unrealize)(item);
}
/* Map handler for canvas groups */
static void
eel_canvas_group_map (EelCanvasItem *item)
{
- EelCanvasGroup *group;
- GList *list;
- EelCanvasItem *i;
+ EelCanvasGroup *group;
+ GList *list;
+ EelCanvasItem *i;
- group = EEL_CANVAS_GROUP (item);
+ group = EEL_CANVAS_GROUP (item);
- for (list = group->item_list; list; list = list->next) {
- i = list->data;
+ for (list = group->item_list; list; list = list->next)
+ {
+ i = list->data;
- if (i->flags & EEL_CANVAS_ITEM_VISIBLE &&
- !(i->flags & EEL_CANVAS_ITEM_MAPPED)) {
- if (!(i->flags & EEL_CANVAS_ITEM_REALIZED))
- (* EEL_CANVAS_ITEM_GET_CLASS (i)->realize) (i);
-
- (* EEL_CANVAS_ITEM_GET_CLASS (i)->map) (i);
- }
- }
+ if (i->flags & EEL_CANVAS_ITEM_VISIBLE &&
+ !(i->flags & EEL_CANVAS_ITEM_MAPPED))
+ {
+ if (!(i->flags & EEL_CANVAS_ITEM_REALIZED))
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (i)->realize)(i);
+ }
- (* group_parent_class->map) (item);
+ (*EEL_CANVAS_ITEM_GET_CLASS (i)->map)(i);
+ }
+ }
+
+ (*group_parent_class->map)(item);
}
/* Unmap handler for canvas groups */
static void
eel_canvas_group_unmap (EelCanvasItem *item)
{
- EelCanvasGroup *group;
- GList *list;
- EelCanvasItem *i;
+ EelCanvasGroup *group;
+ GList *list;
+ EelCanvasItem *i;
- group = EEL_CANVAS_GROUP (item);
+ group = EEL_CANVAS_GROUP (item);
- for (list = group->item_list; list; list = list->next) {
- i = list->data;
+ for (list = group->item_list; list; list = list->next)
+ {
+ i = list->data;
- if (i->flags & EEL_CANVAS_ITEM_MAPPED)
- (* EEL_CANVAS_ITEM_GET_CLASS (i)->unmap) (i);
- }
+ if (i->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (i)->unmap)(i);
+ }
+ }
- (* group_parent_class->unmap) (item);
+ (*group_parent_class->unmap)(item);
}
/* Draw handler for canvas groups */
@@ -1499,263 +1755,323 @@ eel_canvas_group_draw (EelCanvasItem *item,
cairo_t *cr,
cairo_region_t *region)
{
- EelCanvasGroup *group;
- GList *list;
- EelCanvasItem *child = NULL;
+ EelCanvasGroup *group;
+ GList *list;
+ EelCanvasItem *child = NULL;
- group = EEL_CANVAS_GROUP (item);
+ group = EEL_CANVAS_GROUP (item);
- for (list = group->item_list; list; list = list->next) {
- child = list->data;
+ for (list = group->item_list; list; list = list->next)
+ {
+ child = list->data;
- if ((child->flags & EEL_CANVAS_ITEM_MAPPED) &&
- (EEL_CANVAS_ITEM_GET_CLASS (child)->draw)) {
- GdkRectangle child_rect;
+ if ((child->flags & EEL_CANVAS_ITEM_MAPPED) &&
+ (EEL_CANVAS_ITEM_GET_CLASS (child)->draw))
+ {
+ GdkRectangle child_rect;
- child_rect.x = child->x1;
- child_rect.y = child->y1;
- child_rect.width = child->x2 - child->x1 + 1;
- child_rect.height = child->y2 - child->y1 + 1;
+ child_rect.x = child->x1;
+ child_rect.y = child->y1;
+ child_rect.width = child->x2 - child->x1 + 1;
+ child_rect.height = child->y2 - child->y1 + 1;
- if (cairo_region_contains_rectangle (region, &child_rect) != CAIRO_REGION_OVERLAP_OUT)
- EEL_CANVAS_ITEM_GET_CLASS (child)->draw (child, cr, region);
- }
- }
+ if (cairo_region_contains_rectangle (region, &child_rect) != CAIRO_REGION_OVERLAP_OUT)
+ {
+ EEL_CANVAS_ITEM_GET_CLASS (child)->draw (child, cr, region);
+ }
+ }
+ }
}
/* Point handler for canvas groups */
static double
-eel_canvas_group_point (EelCanvasItem *item, double x, double y, int cx, int cy,
- EelCanvasItem **actual_item)
+eel_canvas_group_point (EelCanvasItem *item,
+ double x,
+ double y,
+ int cx,
+ int cy,
+ EelCanvasItem **actual_item)
{
- EelCanvasGroup *group;
- GList *list;
- EelCanvasItem *child, *point_item;
- int x1, y1, x2, y2;
- double gx, gy;
- double dist, best;
- int has_point;
+ EelCanvasGroup *group;
+ GList *list;
+ EelCanvasItem *child, *point_item;
+ int x1, y1, x2, y2;
+ double gx, gy;
+ double dist, best;
+ int has_point;
- group = EEL_CANVAS_GROUP (item);
+ group = EEL_CANVAS_GROUP (item);
- x1 = cx - item->canvas->close_enough;
- y1 = cy - item->canvas->close_enough;
- x2 = cx + item->canvas->close_enough;
- y2 = cy + item->canvas->close_enough;
+ x1 = cx - item->canvas->close_enough;
+ y1 = cy - item->canvas->close_enough;
+ x2 = cx + item->canvas->close_enough;
+ y2 = cy + item->canvas->close_enough;
- best = 0.0;
- *actual_item = NULL;
+ best = 0.0;
+ *actual_item = NULL;
- gx = x - group->xpos;
- gy = y - group->ypos;
+ gx = x - group->xpos;
+ gy = y - group->ypos;
- dist = 0.0; /* keep gcc happy */
+ dist = 0.0; /* keep gcc happy */
- for (list = group->item_list; list; list = list->next) {
- child = list->data;
+ for (list = group->item_list; list; list = list->next)
+ {
+ child = list->data;
- if ((child->x1 > x2) || (child->y1 > y2) || (child->x2 < x1) || (child->y2 < y1))
- continue;
+ if ((child->x1 > x2) || (child->y1 > y2) || (child->x2 < x1) || (child->y2 < y1))
+ {
+ continue;
+ }
- point_item = NULL; /* cater for incomplete item implementations */
+ point_item = NULL; /* cater for incomplete item implementations */
- if ((child->flags & EEL_CANVAS_ITEM_MAPPED)
- && EEL_CANVAS_ITEM_GET_CLASS (child)->point) {
- dist = eel_canvas_item_invoke_point (child, gx, gy, cx, cy, &point_item);
- has_point = TRUE;
- } else
- has_point = FALSE;
+ if ((child->flags & EEL_CANVAS_ITEM_MAPPED)
+ && EEL_CANVAS_ITEM_GET_CLASS (child)->point)
+ {
+ dist = eel_canvas_item_invoke_point (child, gx, gy, cx, cy, &point_item);
+ has_point = TRUE;
+ }
+ else
+ {
+ has_point = FALSE;
+ }
- if (has_point
- && point_item
- && ((int) (dist * item->canvas->pixels_per_unit + 0.5)
- <= item->canvas->close_enough)) {
- best = dist;
- *actual_item = point_item;
- }
- }
+ if (has_point
+ && point_item
+ && ((int) (dist * item->canvas->pixels_per_unit + 0.5)
+ <= item->canvas->close_enough))
+ {
+ best = dist;
+ *actual_item = point_item;
+ }
+ }
- return best;
+ return best;
}
void
-eel_canvas_group_translate (EelCanvasItem *item, double dx, double dy)
+eel_canvas_group_translate (EelCanvasItem *item,
+ double dx,
+ double dy)
{
- EelCanvasGroup *group;
+ EelCanvasGroup *group;
- group = EEL_CANVAS_GROUP (item);
+ group = EEL_CANVAS_GROUP (item);
- group->xpos += dx;
- group->ypos += dy;
+ group->xpos += dx;
+ group->ypos += dy;
}
/* Bounds handler for canvas groups */
static void
-eel_canvas_group_bounds (EelCanvasItem *item, double *x1, double *y1, double *x2, double *y2)
+eel_canvas_group_bounds (EelCanvasItem *item,
+ double *x1,
+ double *y1,
+ double *x2,
+ double *y2)
{
- EelCanvasGroup *group;
- EelCanvasItem *child;
- GList *list;
- double tx1, ty1, tx2, ty2;
- double minx, miny, maxx, maxy;
- int set;
-
- group = EEL_CANVAS_GROUP (item);
+ EelCanvasGroup *group;
+ EelCanvasItem *child;
+ GList *list;
+ double tx1, ty1, tx2, ty2;
+ double minx, miny, maxx, maxy;
+ int set;
- /* Get the bounds of the first visible item */
+ group = EEL_CANVAS_GROUP (item);
- child = NULL; /* Unnecessary but eliminates a warning. */
+ /* Get the bounds of the first visible item */
- set = FALSE;
+ child = NULL; /* Unnecessary but eliminates a warning. */
- for (list = group->item_list; list; list = list->next) {
- child = list->data;
+ set = FALSE;
- if (child->flags & EEL_CANVAS_ITEM_MAPPED) {
- set = TRUE;
- eel_canvas_item_get_bounds (child, &minx, &miny, &maxx, &maxy);
- break;
- }
- }
+ for (list = group->item_list; list; list = list->next)
+ {
+ child = list->data;
- /* If there were no visible items, return an empty bounding box */
-
- if (!set) {
- *x1 = *y1 = *x2 = *y2 = 0.0;
- return;
- }
+ if (child->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ set = TRUE;
+ eel_canvas_item_get_bounds (child, &minx, &miny, &maxx, &maxy);
+ break;
+ }
+ }
- /* Now we can grow the bounds using the rest of the items */
+ /* If there were no visible items, return an empty bounding box */
- list = list->next;
+ if (!set)
+ {
+ *x1 = *y1 = *x2 = *y2 = 0.0;
+ return;
+ }
- for (; list; list = list->next) {
- child = list->data;
+ /* Now we can grow the bounds using the rest of the items */
- if (!(child->flags & EEL_CANVAS_ITEM_MAPPED))
- continue;
+ list = list->next;
- eel_canvas_item_get_bounds (child, &tx1, &ty1, &tx2, &ty2);
+ for (; list; list = list->next)
+ {
+ child = list->data;
- if (tx1 < minx)
- minx = tx1;
+ if (!(child->flags & EEL_CANVAS_ITEM_MAPPED))
+ {
+ continue;
+ }
- if (ty1 < miny)
- miny = ty1;
+ eel_canvas_item_get_bounds (child, &tx1, &ty1, &tx2, &ty2);
- if (tx2 > maxx)
- maxx = tx2;
+ if (tx1 < minx)
+ {
+ minx = tx1;
+ }
- if (ty2 > maxy)
- maxy = ty2;
- }
+ if (ty1 < miny)
+ {
+ miny = ty1;
+ }
- /* Make the bounds be relative to our parent's coordinate system */
+ if (tx2 > maxx)
+ {
+ maxx = tx2;
+ }
- if (item->parent) {
- minx += group->xpos;
- miny += group->ypos;
- maxx += group->xpos;
- maxy += group->ypos;
- }
-
- *x1 = minx;
- *y1 = miny;
- *x2 = maxx;
- *y2 = maxy;
+ if (ty2 > maxy)
+ {
+ maxy = ty2;
+ }
+ }
+
+ /* Make the bounds be relative to our parent's coordinate system */
+
+ if (item->parent)
+ {
+ minx += group->xpos;
+ miny += group->ypos;
+ maxx += group->xpos;
+ maxy += group->ypos;
+ }
+
+ *x1 = minx;
+ *y1 = miny;
+ *x2 = maxx;
+ *y2 = maxy;
}
/* Adds an item to a group */
static void
-group_add (EelCanvasGroup *group, EelCanvasItem *item)
+group_add (EelCanvasGroup *group,
+ EelCanvasItem *item)
{
- g_object_ref_sink (item);
-
- if (!group->item_list) {
- group->item_list = g_list_append (group->item_list, item);
- group->item_list_end = group->item_list;
- } else
- group->item_list_end = g_list_append (group->item_list_end, item)->next;
+ g_object_ref_sink (item);
+
+ if (!group->item_list)
+ {
+ group->item_list = g_list_append (group->item_list, item);
+ group->item_list_end = group->item_list;
+ }
+ else
+ {
+ group->item_list_end = g_list_append (group->item_list_end, item)->next;
+ }
+
+ if (item->flags & EEL_CANVAS_ITEM_VISIBLE &&
+ group->item.flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ if (!(item->flags & EEL_CANVAS_ITEM_REALIZED))
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->realize)(item);
+ }
- if (item->flags & EEL_CANVAS_ITEM_VISIBLE &&
- group->item.flags & EEL_CANVAS_ITEM_MAPPED) {
- if (!(item->flags & EEL_CANVAS_ITEM_REALIZED))
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->realize) (item);
-
- if (!(item->flags & EEL_CANVAS_ITEM_MAPPED))
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->map) (item);
- }
+ if (!(item->flags & EEL_CANVAS_ITEM_MAPPED))
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->map)(item);
+ }
+ }
- if (item->flags & EEL_CANVAS_ITEM_VISIBLE)
- eel_canvas_queue_resize (EEL_CANVAS_ITEM (group)->canvas);
+ if (item->flags & EEL_CANVAS_ITEM_VISIBLE)
+ {
+ eel_canvas_queue_resize (EEL_CANVAS_ITEM (group)->canvas);
+ }
}
/* Removes an item from a group */
static void
-group_remove (EelCanvasGroup *group, EelCanvasItem *item)
+group_remove (EelCanvasGroup *group,
+ EelCanvasItem *item)
{
- GList *children;
+ GList *children;
- g_return_if_fail (EEL_IS_CANVAS_GROUP (group));
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_GROUP (group));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- for (children = group->item_list; children; children = children->next)
- if (children->data == item) {
- if (item->flags & EEL_CANVAS_ITEM_MAPPED) {
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->unmap) (item);
- }
+ for (children = group->item_list; children; children = children->next)
+ {
+ if (children->data == item)
+ {
+ if (item->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->unmap)(item);
+ }
- if (item->flags & EEL_CANVAS_ITEM_REALIZED)
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->unrealize) (item);
+ if (item->flags & EEL_CANVAS_ITEM_REALIZED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->unrealize)(item);
+ }
- if (item->flags & EEL_CANVAS_ITEM_VISIBLE)
- eel_canvas_queue_resize (item->canvas);
+ if (item->flags & EEL_CANVAS_ITEM_VISIBLE)
+ {
+ eel_canvas_queue_resize (item->canvas);
+ }
- /* Unparent the child */
+ /* Unparent the child */
- item->parent = NULL;
- /* item->canvas = NULL; */
- g_object_unref (G_OBJECT (item));
+ item->parent = NULL;
+ /* item->canvas = NULL; */
+ g_object_unref (G_OBJECT (item));
- /* Remove it from the list */
+ /* Remove it from the list */
- if (children == group->item_list_end)
- group->item_list_end = children->prev;
+ if (children == group->item_list_end)
+ {
+ group->item_list_end = children->prev;
+ }
- group->item_list = g_list_remove_link (group->item_list, children);
- g_list_free (children);
- break;
- }
+ group->item_list = g_list_remove_link (group->item_list, children);
+ g_list_free (children);
+ break;
+ }
+ }
}
/*** EelCanvas ***/
-static void eel_canvas_class_init (EelCanvasClass *klass);
-static void eel_canvas_init (EelCanvas *canvas);
-static void eel_canvas_destroy (GtkWidget *object);
-static void eel_canvas_map (GtkWidget *widget);
-static void eel_canvas_unmap (GtkWidget *widget);
-static void eel_canvas_realize (GtkWidget *widget);
-static void eel_canvas_unrealize (GtkWidget *widget);
-static void eel_canvas_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-static gint eel_canvas_button (GtkWidget *widget,
- GdkEventButton *event);
-static gint eel_canvas_motion (GtkWidget *widget,
- GdkEventMotion *event);
-static gint eel_canvas_draw (GtkWidget *widget,
- cairo_t *cr);
-static gint eel_canvas_key (GtkWidget *widget,
- GdkEventKey *event);
-static gint eel_canvas_crossing (GtkWidget *widget,
- GdkEventCrossing *event);
-static gint eel_canvas_focus_in (GtkWidget *widget,
- GdkEventFocus *event);
-static gint eel_canvas_focus_out (GtkWidget *widget,
- GdkEventFocus *event);
-static void eel_canvas_request_update_real (EelCanvas *canvas);
+static void eel_canvas_class_init (EelCanvasClass *klass);
+static void eel_canvas_init (EelCanvas *canvas);
+static void eel_canvas_destroy (GtkWidget *object);
+static void eel_canvas_map (GtkWidget *widget);
+static void eel_canvas_unmap (GtkWidget *widget);
+static void eel_canvas_realize (GtkWidget *widget);
+static void eel_canvas_unrealize (GtkWidget *widget);
+static void eel_canvas_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+static gint eel_canvas_button (GtkWidget *widget,
+ GdkEventButton *event);
+static gint eel_canvas_motion (GtkWidget *widget,
+ GdkEventMotion *event);
+static gint eel_canvas_draw (GtkWidget *widget,
+ cairo_t *cr);
+static gint eel_canvas_key (GtkWidget *widget,
+ GdkEventKey *event);
+static gint eel_canvas_crossing (GtkWidget *widget,
+ GdkEventCrossing *event);
+static gint eel_canvas_focus_in (GtkWidget *widget,
+ GdkEventFocus *event);
+static gint eel_canvas_focus_out (GtkWidget *widget,
+ GdkEventFocus *event);
+static void eel_canvas_request_update_real (EelCanvas *canvas);
static GtkLayoutClass *canvas_parent_class;
/**
@@ -1769,162 +2085,173 @@ static GtkLayoutClass *canvas_parent_class;
GType
eel_canvas_get_type (void)
{
- static GType canvas_type = 0;
-
- if (!canvas_type) {
- static const GTypeInfo canvas_info = {
- sizeof (EelCanvasClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) eel_canvas_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (EelCanvas),
- 0, /* n_preallocs */
- (GInstanceInitFunc) eel_canvas_init
- };
-
- canvas_type = g_type_register_static (gtk_layout_get_type (),
- "EelCanvas",
- &canvas_info,
- 0);
- }
+ static GType canvas_type = 0;
- return canvas_type;
+ if (!canvas_type)
+ {
+ static const GTypeInfo canvas_info =
+ {
+ sizeof (EelCanvasClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) eel_canvas_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (EelCanvas),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) eel_canvas_init
+ };
+
+ canvas_type = g_type_register_static (gtk_layout_get_type (),
+ "EelCanvas",
+ &canvas_info,
+ 0);
+ }
+
+ return canvas_type;
}
static void
-eel_canvas_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+eel_canvas_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- switch (prop_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ switch (prop_id)
+ {
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+ break;
+ }
}
static void
-eel_canvas_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+eel_canvas_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- switch (prop_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ switch (prop_id)
+ {
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+ break;
+ }
}
static void
eel_canvas_accessible_adjustment_changed (GtkAdjustment *adjustment,
- gpointer data)
+ gpointer data)
{
- AtkObject *atk_obj;
+ AtkObject *atk_obj;
- /* The scrollbars have changed */
- atk_obj = ATK_OBJECT (data);
+ /* The scrollbars have changed */
+ atk_obj = ATK_OBJECT (data);
- g_signal_emit_by_name (atk_obj, "visible-data-changed");
+ g_signal_emit_by_name (atk_obj, "visible-data-changed");
}
static void
-eel_canvas_accessible_initialize (AtkObject *obj,
- gpointer data)
+eel_canvas_accessible_initialize (AtkObject *obj,
+ gpointer data)
{
- EelCanvas *canvas = data;
-
- if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize != NULL) {
- ATK_OBJECT_CLASS (accessible_parent_class)->initialize (obj, data);
- }
-
- gtk_accessible_set_widget (GTK_ACCESSIBLE (obj), GTK_WIDGET (data));
- g_signal_connect (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas)),
- "value-changed",
- G_CALLBACK (eel_canvas_accessible_adjustment_changed),
- obj);
- g_signal_connect (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas)),
- "value-changed",
- G_CALLBACK (eel_canvas_accessible_adjustment_changed),
- obj);
-
- obj->role = ATK_ROLE_LAYERED_PANE;
+ EelCanvas *canvas = data;
+
+ if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize != NULL)
+ {
+ ATK_OBJECT_CLASS (accessible_parent_class)->initialize (obj, data);
+ }
+
+ gtk_accessible_set_widget (GTK_ACCESSIBLE (obj), GTK_WIDGET (data));
+ g_signal_connect (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas)),
+ "value-changed",
+ G_CALLBACK (eel_canvas_accessible_adjustment_changed),
+ obj);
+ g_signal_connect (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas)),
+ "value-changed",
+ G_CALLBACK (eel_canvas_accessible_adjustment_changed),
+ obj);
+
+ obj->role = ATK_ROLE_LAYERED_PANE;
}
static gint
-eel_canvas_accessible_get_n_children (AtkObject* obj)
+eel_canvas_accessible_get_n_children (AtkObject *obj)
{
- GtkAccessible *accessible;
- GtkWidget *widget;
- EelCanvas *canvas;
- EelCanvasGroup *root_group;
+ GtkAccessible *accessible;
+ GtkWidget *widget;
+ EelCanvas *canvas;
+ EelCanvasGroup *root_group;
- accessible = GTK_ACCESSIBLE (obj);
- widget = gtk_accessible_get_widget (accessible);
+ accessible = GTK_ACCESSIBLE (obj);
+ widget = gtk_accessible_get_widget (accessible);
- if (widget == NULL) {
- return 0;
- }
+ if (widget == NULL)
+ {
+ return 0;
+ }
- g_return_val_if_fail (EEL_IS_CANVAS (widget), 0);
+ g_return_val_if_fail (EEL_IS_CANVAS (widget), 0);
- canvas = EEL_CANVAS (widget);
- root_group = eel_canvas_root (canvas);
- g_return_val_if_fail (root_group, 0);
+ canvas = EEL_CANVAS (widget);
+ root_group = eel_canvas_root (canvas);
+ g_return_val_if_fail (root_group, 0);
- return 1;
+ return 1;
}
-static AtkObject*
+static AtkObject *
eel_canvas_accessible_ref_child (AtkObject *obj,
gint i)
{
- GtkAccessible *accessible;
- GtkWidget *widget;
- EelCanvas *canvas;
- EelCanvasGroup *root_group;
- AtkObject *atk_object;
+ GtkAccessible *accessible;
+ GtkWidget *widget;
+ EelCanvas *canvas;
+ EelCanvasGroup *root_group;
+ AtkObject *atk_object;
+
+ /* Canvas only has one child, so return NULL if index is non zero */
+ if (i != 0)
+ {
+ return NULL;
+ }
- /* Canvas only has one child, so return NULL if index is non zero */
- if (i != 0) {
- return NULL;
- }
+ accessible = GTK_ACCESSIBLE (obj);
+ widget = gtk_accessible_get_widget (accessible);
- accessible = GTK_ACCESSIBLE (obj);
- widget = gtk_accessible_get_widget (accessible);
+ if (widget == NULL)
+ {
+ return NULL;
+ }
- if (widget == NULL) {
- return NULL;
- }
+ canvas = EEL_CANVAS (widget);
+ root_group = eel_canvas_root (canvas);
+ g_return_val_if_fail (root_group, NULL);
- canvas = EEL_CANVAS (widget);
- root_group = eel_canvas_root (canvas);
- g_return_val_if_fail (root_group, NULL);
+ atk_object = atk_gobject_accessible_for_object (G_OBJECT (root_group));
- atk_object = atk_gobject_accessible_for_object (G_OBJECT (root_group));
-
- return g_object_ref (atk_object);
+ return g_object_ref (atk_object);
}
static void
eel_canvas_accessible_class_init (EelCanvasAccessibleClass *klass)
{
- AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
+ AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
- accessible_parent_class = g_type_class_peek_parent (klass);
+ accessible_parent_class = g_type_class_peek_parent (klass);
- atk_class->initialize = eel_canvas_accessible_initialize;
- atk_class->get_n_children = eel_canvas_accessible_get_n_children;
- atk_class->ref_child = eel_canvas_accessible_ref_child;
+ atk_class->initialize = eel_canvas_accessible_initialize;
+ atk_class->get_n_children = eel_canvas_accessible_get_n_children;
+ atk_class->ref_child = eel_canvas_accessible_ref_child;
}
static void
eel_canvas_accessible_init (EelCanvasAccessible *accessible)
{
-
}
G_DEFINE_TYPE (EelCanvasAccessible, eel_canvas_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE)
@@ -1933,145 +2260,154 @@ G_DEFINE_TYPE (EelCanvasAccessible, eel_canvas_accessible, GTK_TYPE_CONTAINER_AC
static void
eel_canvas_class_init (EelCanvasClass *klass)
{
- GObjectClass *gobject_class;
- GtkWidgetClass *widget_class;
-
- gobject_class = (GObjectClass *)klass;
- widget_class = (GtkWidgetClass *) klass;
-
- canvas_parent_class = g_type_class_peek_parent (klass);
-
- gobject_class->set_property = eel_canvas_set_property;
- gobject_class->get_property = eel_canvas_get_property;
-
- widget_class->destroy = eel_canvas_destroy;
- widget_class->map = eel_canvas_map;
- widget_class->unmap = eel_canvas_unmap;
- widget_class->realize = eel_canvas_realize;
- widget_class->unrealize = eel_canvas_unrealize;
- widget_class->size_allocate = eel_canvas_size_allocate;
- widget_class->button_press_event = eel_canvas_button;
- widget_class->button_release_event = eel_canvas_button;
- widget_class->motion_notify_event = eel_canvas_motion;
- widget_class->draw = eel_canvas_draw;
- widget_class->key_press_event = eel_canvas_key;
- widget_class->key_release_event = eel_canvas_key;
- widget_class->enter_notify_event = eel_canvas_crossing;
- widget_class->leave_notify_event = eel_canvas_crossing;
- widget_class->focus_in_event = eel_canvas_focus_in;
- widget_class->focus_out_event = eel_canvas_focus_out;
-
- klass->request_update = eel_canvas_request_update_real;
-
- gtk_widget_class_set_accessible_type (widget_class, eel_canvas_accessible_get_type ());
+ GObjectClass *gobject_class;
+ GtkWidgetClass *widget_class;
+
+ gobject_class = (GObjectClass *) klass;
+ widget_class = (GtkWidgetClass *) klass;
+
+ canvas_parent_class = g_type_class_peek_parent (klass);
+
+ gobject_class->set_property = eel_canvas_set_property;
+ gobject_class->get_property = eel_canvas_get_property;
+
+ widget_class->destroy = eel_canvas_destroy;
+ widget_class->map = eel_canvas_map;
+ widget_class->unmap = eel_canvas_unmap;
+ widget_class->realize = eel_canvas_realize;
+ widget_class->unrealize = eel_canvas_unrealize;
+ widget_class->size_allocate = eel_canvas_size_allocate;
+ widget_class->button_press_event = eel_canvas_button;
+ widget_class->button_release_event = eel_canvas_button;
+ widget_class->motion_notify_event = eel_canvas_motion;
+ widget_class->draw = eel_canvas_draw;
+ widget_class->key_press_event = eel_canvas_key;
+ widget_class->key_release_event = eel_canvas_key;
+ widget_class->enter_notify_event = eel_canvas_crossing;
+ widget_class->leave_notify_event = eel_canvas_crossing;
+ widget_class->focus_in_event = eel_canvas_focus_in;
+ widget_class->focus_out_event = eel_canvas_focus_out;
+
+ klass->request_update = eel_canvas_request_update_real;
+
+ gtk_widget_class_set_accessible_type (widget_class, eel_canvas_accessible_get_type ());
}
/* Callback used when the root item of a canvas is destroyed. The user should
* never ever do this, so we panic if this happens.
*/
static void
-panic_root_destroyed (GtkWidget *object, gpointer data)
+panic_root_destroyed (GtkWidget *object,
+ gpointer data)
{
- g_error ("Eeeek, root item %p of canvas %p was destroyed!", object, data);
+ g_error ("Eeeek, root item %p of canvas %p was destroyed!", object, data);
}
/* Object initialization function for EelCanvas */
static void
eel_canvas_init (EelCanvas *canvas)
{
- guint width, height;
- gtk_widget_set_can_focus (GTK_WIDGET (canvas), TRUE);
+ guint width, height;
+ gtk_widget_set_can_focus (GTK_WIDGET (canvas), TRUE);
- gtk_widget_set_redraw_on_allocate (GTK_WIDGET (canvas), FALSE);
+ gtk_widget_set_redraw_on_allocate (GTK_WIDGET (canvas), FALSE);
- canvas->scroll_x1 = 0.0;
- canvas->scroll_y1 = 0.0;
- gtk_layout_get_size (GTK_LAYOUT (canvas),
- &width, &height);
- canvas->scroll_x2 = width;
- canvas->scroll_y2 = height;
+ canvas->scroll_x1 = 0.0;
+ canvas->scroll_y1 = 0.0;
+ gtk_layout_get_size (GTK_LAYOUT (canvas),
+ &width, &height);
+ canvas->scroll_x2 = width;
+ canvas->scroll_y2 = height;
- canvas->pixels_per_unit = 1.0;
+ canvas->pixels_per_unit = 1.0;
- canvas->pick_event.type = GDK_LEAVE_NOTIFY;
- canvas->pick_event.crossing.x = 0;
- canvas->pick_event.crossing.y = 0;
+ canvas->pick_event.type = GDK_LEAVE_NOTIFY;
+ canvas->pick_event.crossing.x = 0;
+ canvas->pick_event.crossing.y = 0;
- gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (canvas), NULL);
- gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (canvas), NULL);
+ gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (canvas), NULL);
+ gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (canvas), NULL);
- /* Create the root item as a special case */
+ /* Create the root item as a special case */
- canvas->root = EEL_CANVAS_ITEM (g_object_new (eel_canvas_group_get_type (), NULL));
- canvas->root->canvas = canvas;
+ canvas->root = EEL_CANVAS_ITEM (g_object_new (eel_canvas_group_get_type (), NULL));
+ canvas->root->canvas = canvas;
- g_object_ref_sink (canvas->root);
+ g_object_ref_sink (canvas->root);
- canvas->root_destroy_id = g_signal_connect (G_OBJECT (canvas->root),
- "destroy", G_CALLBACK (panic_root_destroyed), canvas);
+ canvas->root_destroy_id = g_signal_connect (G_OBJECT (canvas->root),
+ "destroy", G_CALLBACK (panic_root_destroyed), canvas);
- canvas->need_repick = TRUE;
- canvas->doing_update = FALSE;
+ canvas->need_repick = TRUE;
+ canvas->doing_update = FALSE;
}
/* Convenience function to remove the idle handler of a canvas */
static void
remove_idle (EelCanvas *canvas)
{
- if (canvas->idle_id == 0)
- return;
+ if (canvas->idle_id == 0)
+ {
+ return;
+ }
- g_source_remove (canvas->idle_id);
- canvas->idle_id = 0;
+ g_source_remove (canvas->idle_id);
+ canvas->idle_id = 0;
}
/* Removes the transient state of the canvas (idle handler, grabs). */
static void
shutdown_transients (EelCanvas *canvas)
{
- /* We turn off the need_redraw flag, since if the canvas is mapped again
- * it will request a redraw anyways. We do not turn off the need_update
- * flag, though, because updates are not queued when the canvas remaps
- * itself.
- */
- if (canvas->need_redraw) {
- canvas->need_redraw = FALSE;
- }
-
- if (canvas->grabbed_item) {
- eel_canvas_item_ungrab (canvas->grabbed_item);
- }
-
- remove_idle (canvas);
+ /* We turn off the need_redraw flag, since if the canvas is mapped again
+ * it will request a redraw anyways. We do not turn off the need_update
+ * flag, though, because updates are not queued when the canvas remaps
+ * itself.
+ */
+ if (canvas->need_redraw)
+ {
+ canvas->need_redraw = FALSE;
+ }
+
+ if (canvas->grabbed_item)
+ {
+ eel_canvas_item_ungrab (canvas->grabbed_item);
+ }
+
+ remove_idle (canvas);
}
/* Destroy handler for EelCanvas */
static void
eel_canvas_destroy (GtkWidget *object)
{
- EelCanvas *canvas;
+ EelCanvas *canvas;
- g_return_if_fail (EEL_IS_CANVAS (object));
+ g_return_if_fail (EEL_IS_CANVAS (object));
- /* remember, destroy can be run multiple times! */
+ /* remember, destroy can be run multiple times! */
- canvas = EEL_CANVAS (object);
+ canvas = EEL_CANVAS (object);
- if (canvas->root_destroy_id) {
- g_signal_handler_disconnect (G_OBJECT (canvas->root), canvas->root_destroy_id);
- canvas->root_destroy_id = 0;
- }
- if (canvas->root) {
- EelCanvasItem *root = canvas->root;
- canvas->root = NULL;
- eel_canvas_item_destroy (root);
- g_object_unref (root);
- }
+ if (canvas->root_destroy_id)
+ {
+ g_signal_handler_disconnect (G_OBJECT (canvas->root), canvas->root_destroy_id);
+ canvas->root_destroy_id = 0;
+ }
+ if (canvas->root)
+ {
+ EelCanvasItem *root = canvas->root;
+ canvas->root = NULL;
+ eel_canvas_item_destroy (root);
+ g_object_unref (root);
+ }
- shutdown_transients (canvas);
+ shutdown_transients (canvas);
- if (GTK_WIDGET_CLASS (canvas_parent_class)->destroy)
- (* GTK_WIDGET_CLASS (canvas_parent_class)->destroy) (object);
+ if (GTK_WIDGET_CLASS (canvas_parent_class)->destroy)
+ {
+ (*GTK_WIDGET_CLASS (canvas_parent_class)->destroy)(object);
+ }
}
/**
@@ -2088,237 +2424,285 @@ eel_canvas_destroy (GtkWidget *object)
GtkWidget *
eel_canvas_new (void)
{
- return GTK_WIDGET (g_object_new (eel_canvas_get_type (), NULL));
+ return GTK_WIDGET (g_object_new (eel_canvas_get_type (), NULL));
}
/* Map handler for the canvas */
static void
eel_canvas_map (GtkWidget *widget)
{
- EelCanvas *canvas;
+ EelCanvas *canvas;
- g_return_if_fail (EEL_IS_CANVAS (widget));
+ g_return_if_fail (EEL_IS_CANVAS (widget));
- /* Normal widget mapping stuff */
+ /* Normal widget mapping stuff */
- if (GTK_WIDGET_CLASS (canvas_parent_class)->map)
- (* GTK_WIDGET_CLASS (canvas_parent_class)->map) (widget);
+ if (GTK_WIDGET_CLASS (canvas_parent_class)->map)
+ {
+ (*GTK_WIDGET_CLASS (canvas_parent_class)->map)(widget);
+ }
- canvas = EEL_CANVAS (widget);
+ canvas = EEL_CANVAS (widget);
- /* Map items */
+ /* Map items */
- if (canvas->root->flags & EEL_CANVAS_ITEM_VISIBLE &&
- !(canvas->root->flags & EEL_CANVAS_ITEM_MAPPED) &&
- EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->map)
- (* EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->map) (canvas->root);
+ if (canvas->root->flags & EEL_CANVAS_ITEM_VISIBLE &&
+ !(canvas->root->flags & EEL_CANVAS_ITEM_MAPPED) &&
+ EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->map)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->map)(canvas->root);
+ }
}
/* Unmap handler for the canvas */
static void
eel_canvas_unmap (GtkWidget *widget)
{
- EelCanvas *canvas;
+ EelCanvas *canvas;
- g_return_if_fail (EEL_IS_CANVAS (widget));
+ g_return_if_fail (EEL_IS_CANVAS (widget));
- canvas = EEL_CANVAS (widget);
+ canvas = EEL_CANVAS (widget);
- shutdown_transients (canvas);
+ shutdown_transients (canvas);
- /* Unmap items */
+ /* Unmap items */
- if (EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->unmap)
- (* EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->unmap) (canvas->root);
+ if (EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->unmap)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->unmap)(canvas->root);
+ }
- /* Normal widget unmapping stuff */
+ /* Normal widget unmapping stuff */
- if (GTK_WIDGET_CLASS (canvas_parent_class)->unmap)
- (* GTK_WIDGET_CLASS (canvas_parent_class)->unmap) (widget);
+ if (GTK_WIDGET_CLASS (canvas_parent_class)->unmap)
+ {
+ (*GTK_WIDGET_CLASS (canvas_parent_class)->unmap)(widget);
+ }
}
/* Realize handler for the canvas */
static void
eel_canvas_realize (GtkWidget *widget)
{
- EelCanvas *canvas;
+ EelCanvas *canvas;
- g_return_if_fail (EEL_IS_CANVAS (widget));
+ g_return_if_fail (EEL_IS_CANVAS (widget));
- /* Normal widget realization stuff */
+ /* Normal widget realization stuff */
- if (GTK_WIDGET_CLASS (canvas_parent_class)->realize)
- (* GTK_WIDGET_CLASS (canvas_parent_class)->realize) (widget);
+ if (GTK_WIDGET_CLASS (canvas_parent_class)->realize)
+ {
+ (*GTK_WIDGET_CLASS (canvas_parent_class)->realize)(widget);
+ }
- canvas = EEL_CANVAS (widget);
+ canvas = EEL_CANVAS (widget);
- gdk_window_set_events (gtk_layout_get_bin_window (GTK_LAYOUT (canvas)),
- (gdk_window_get_events (gtk_layout_get_bin_window (GTK_LAYOUT (canvas)))
- | GDK_EXPOSURE_MASK
- | GDK_BUTTON_PRESS_MASK
- | GDK_BUTTON_RELEASE_MASK
- | GDK_POINTER_MOTION_MASK
- | GDK_KEY_PRESS_MASK
- | GDK_KEY_RELEASE_MASK
- | GDK_ENTER_NOTIFY_MASK
- | GDK_LEAVE_NOTIFY_MASK
- | GDK_FOCUS_CHANGE_MASK));
+ gdk_window_set_events (gtk_layout_get_bin_window (GTK_LAYOUT (canvas)),
+ (gdk_window_get_events (gtk_layout_get_bin_window (GTK_LAYOUT (canvas)))
+ | GDK_EXPOSURE_MASK
+ | GDK_BUTTON_PRESS_MASK
+ | GDK_BUTTON_RELEASE_MASK
+ | GDK_POINTER_MOTION_MASK
+ | GDK_KEY_PRESS_MASK
+ | GDK_KEY_RELEASE_MASK
+ | GDK_ENTER_NOTIFY_MASK
+ | GDK_LEAVE_NOTIFY_MASK
+ | GDK_FOCUS_CHANGE_MASK));
- /* Create our own temporary pixmap gc and realize all the items */
+ /* Create our own temporary pixmap gc and realize all the items */
- (* EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->realize) (canvas->root);
+ (*EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->realize)(canvas->root);
}
/* Unrealize handler for the canvas */
static void
eel_canvas_unrealize (GtkWidget *widget)
{
- EelCanvas *canvas;
+ EelCanvas *canvas;
- g_return_if_fail (EEL_IS_CANVAS (widget));
+ g_return_if_fail (EEL_IS_CANVAS (widget));
- canvas = EEL_CANVAS (widget);
+ canvas = EEL_CANVAS (widget);
- shutdown_transients (canvas);
+ shutdown_transients (canvas);
- /* Unrealize items and parent widget */
+ /* Unrealize items and parent widget */
- (* EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->unrealize) (canvas->root);
+ (*EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->unrealize)(canvas->root);
- if (GTK_WIDGET_CLASS (canvas_parent_class)->unrealize)
- (* GTK_WIDGET_CLASS (canvas_parent_class)->unrealize) (widget);
+ if (GTK_WIDGET_CLASS (canvas_parent_class)->unrealize)
+ {
+ (*GTK_WIDGET_CLASS (canvas_parent_class)->unrealize)(widget);
+ }
}
/* Handles scrolling of the canvas. Adjusts the scrolling and zooming offset to
* keep as much as possible of the canvas scrolling region in view.
*/
static void
-scroll_to (EelCanvas *canvas, int cx, int cy)
-{
- int scroll_width, scroll_height;
- int right_limit, bottom_limit;
- int old_zoom_xofs, old_zoom_yofs;
- int changed_x = FALSE, changed_y = FALSE;
- int canvas_width, canvas_height;
- GtkAllocation allocation;
- GtkAdjustment *vadjustment, *hadjustment;
- guint width, height;
-
- gtk_widget_get_allocation (GTK_WIDGET (canvas), &allocation);
- canvas_width = allocation.width;
- canvas_height = allocation.height;
-
- scroll_width = floor ((canvas->scroll_x2 - canvas->scroll_x1) * canvas->pixels_per_unit + 0.5);
- scroll_height = floor ((canvas->scroll_y2 - canvas->scroll_y1) * canvas->pixels_per_unit + 0.5);
-
- right_limit = scroll_width - canvas_width;
- bottom_limit = scroll_height - canvas_height;
-
- old_zoom_xofs = canvas->zoom_xofs;
- old_zoom_yofs = canvas->zoom_yofs;
-
- if (right_limit < 0) {
- cx = 0;
- if (canvas->center_scroll_region) {
- canvas->zoom_xofs = (canvas_width - scroll_width) / 2;
- scroll_width = canvas_width;
- } else {
- canvas->zoom_xofs = 0;
- }
- } else if (cx < 0) {
- cx = 0;
- canvas->zoom_xofs = 0;
- } else if (cx > right_limit) {
- cx = right_limit;
- canvas->zoom_xofs = 0;
- } else
- canvas->zoom_xofs = 0;
-
- if (bottom_limit < 0) {
- cy = 0;
- if (canvas->center_scroll_region) {
- canvas->zoom_yofs = (canvas_height - scroll_height) / 2;
- scroll_height = canvas_height;
- } else {
- canvas->zoom_yofs = 0;
- }
- } else if (cy < 0) {
- cy = 0;
- canvas->zoom_yofs = 0;
- } else if (cy > bottom_limit) {
- cy = bottom_limit;
- canvas->zoom_yofs = 0;
- } else
- canvas->zoom_yofs = 0;
-
- if ((canvas->zoom_xofs != old_zoom_xofs) || (canvas->zoom_yofs != old_zoom_yofs)) {
- /* This can only occur, if either canvas size or widget size changes */
- /* So I think we can request full redraw here */
- /* More stuff - we have to mark root as needing fresh affine (Lauris) */
- if (!(canvas->root->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE)) {
- canvas->root->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
- eel_canvas_request_update (canvas);
- }
- gtk_widget_queue_draw (GTK_WIDGET (canvas));
- }
-
- hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
- vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
-
- if (((int) gtk_adjustment_get_value (hadjustment)) != cx) {
- gtk_adjustment_set_value (hadjustment, cx);
- changed_x = TRUE;
- }
-
- if (((int) gtk_adjustment_get_value (vadjustment)) != cy) {
- gtk_adjustment_set_value (vadjustment, cy);
- changed_y = TRUE;
- }
-
- gtk_layout_get_size (&canvas->layout, &width, &height);
- if ((scroll_width != (int) width )|| (scroll_height != (int) height)) {
- gtk_layout_set_size (GTK_LAYOUT (canvas), scroll_width, scroll_height);
- }
-
- /* Signal GtkLayout that it should do a redraw. */
- if (changed_x)
- g_signal_emit_by_name (hadjustment, "value-changed");
- if (changed_y)
- g_signal_emit_by_name (vadjustment, "value-changed");
+scroll_to (EelCanvas *canvas,
+ int cx,
+ int cy)
+{
+ int scroll_width, scroll_height;
+ int right_limit, bottom_limit;
+ int old_zoom_xofs, old_zoom_yofs;
+ int changed_x = FALSE, changed_y = FALSE;
+ int canvas_width, canvas_height;
+ GtkAllocation allocation;
+ GtkAdjustment *vadjustment, *hadjustment;
+ guint width, height;
+
+ gtk_widget_get_allocation (GTK_WIDGET (canvas), &allocation);
+ canvas_width = allocation.width;
+ canvas_height = allocation.height;
+
+ scroll_width = floor ((canvas->scroll_x2 - canvas->scroll_x1) * canvas->pixels_per_unit + 0.5);
+ scroll_height = floor ((canvas->scroll_y2 - canvas->scroll_y1) * canvas->pixels_per_unit + 0.5);
+
+ right_limit = scroll_width - canvas_width;
+ bottom_limit = scroll_height - canvas_height;
+
+ old_zoom_xofs = canvas->zoom_xofs;
+ old_zoom_yofs = canvas->zoom_yofs;
+
+ if (right_limit < 0)
+ {
+ cx = 0;
+ if (canvas->center_scroll_region)
+ {
+ canvas->zoom_xofs = (canvas_width - scroll_width) / 2;
+ scroll_width = canvas_width;
+ }
+ else
+ {
+ canvas->zoom_xofs = 0;
+ }
+ }
+ else if (cx < 0)
+ {
+ cx = 0;
+ canvas->zoom_xofs = 0;
+ }
+ else if (cx > right_limit)
+ {
+ cx = right_limit;
+ canvas->zoom_xofs = 0;
+ }
+ else
+ {
+ canvas->zoom_xofs = 0;
+ }
+
+ if (bottom_limit < 0)
+ {
+ cy = 0;
+ if (canvas->center_scroll_region)
+ {
+ canvas->zoom_yofs = (canvas_height - scroll_height) / 2;
+ scroll_height = canvas_height;
+ }
+ else
+ {
+ canvas->zoom_yofs = 0;
+ }
+ }
+ else if (cy < 0)
+ {
+ cy = 0;
+ canvas->zoom_yofs = 0;
+ }
+ else if (cy > bottom_limit)
+ {
+ cy = bottom_limit;
+ canvas->zoom_yofs = 0;
+ }
+ else
+ {
+ canvas->zoom_yofs = 0;
+ }
+
+ if ((canvas->zoom_xofs != old_zoom_xofs) || (canvas->zoom_yofs != old_zoom_yofs))
+ {
+ /* This can only occur, if either canvas size or widget size changes */
+ /* So I think we can request full redraw here */
+ /* More stuff - we have to mark root as needing fresh affine (Lauris) */
+ if (!(canvas->root->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE))
+ {
+ canvas->root->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
+ eel_canvas_request_update (canvas);
+ }
+ gtk_widget_queue_draw (GTK_WIDGET (canvas));
+ }
+
+ hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
+ vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
+
+ if (((int) gtk_adjustment_get_value (hadjustment)) != cx)
+ {
+ gtk_adjustment_set_value (hadjustment, cx);
+ changed_x = TRUE;
+ }
+
+ if (((int) gtk_adjustment_get_value (vadjustment)) != cy)
+ {
+ gtk_adjustment_set_value (vadjustment, cy);
+ changed_y = TRUE;
+ }
+
+ gtk_layout_get_size (&canvas->layout, &width, &height);
+ if ((scroll_width != (int) width) || (scroll_height != (int) height))
+ {
+ gtk_layout_set_size (GTK_LAYOUT (canvas), scroll_width, scroll_height);
+ }
+
+ /* Signal GtkLayout that it should do a redraw. */
+ if (changed_x)
+ {
+ g_signal_emit_by_name (hadjustment, "value-changed");
+ }
+ if (changed_y)
+ {
+ g_signal_emit_by_name (vadjustment, "value-changed");
+ }
}
/* Size allocation handler for the canvas */
static void
-eel_canvas_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
+eel_canvas_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
{
- EelCanvas *canvas;
- GtkAdjustment *vadjustment, *hadjustment;
+ EelCanvas *canvas;
+ GtkAdjustment *vadjustment, *hadjustment;
- g_return_if_fail (EEL_IS_CANVAS (widget));
- g_return_if_fail (allocation != NULL);
+ g_return_if_fail (EEL_IS_CANVAS (widget));
+ g_return_if_fail (allocation != NULL);
- if (GTK_WIDGET_CLASS (canvas_parent_class)->size_allocate)
- (* GTK_WIDGET_CLASS (canvas_parent_class)->size_allocate) (widget, allocation);
+ if (GTK_WIDGET_CLASS (canvas_parent_class)->size_allocate)
+ {
+ (*GTK_WIDGET_CLASS (canvas_parent_class)->size_allocate)(widget, allocation);
+ }
- canvas = EEL_CANVAS (widget);
+ canvas = EEL_CANVAS (widget);
- /* Recenter the view, if appropriate */
+ /* Recenter the view, if appropriate */
- hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
- vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
+ hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
+ vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
- gtk_adjustment_set_page_size (hadjustment, allocation->width);
- gtk_adjustment_set_page_increment (hadjustment, allocation->width / 2);
+ gtk_adjustment_set_page_size (hadjustment, allocation->width);
+ gtk_adjustment_set_page_increment (hadjustment, allocation->width / 2);
- gtk_adjustment_set_page_size (vadjustment, allocation->height);
- gtk_adjustment_set_page_increment (vadjustment, allocation->height / 2);
+ gtk_adjustment_set_page_size (vadjustment, allocation->height);
+ gtk_adjustment_set_page_increment (vadjustment, allocation->height / 2);
- scroll_to (canvas,
- gtk_adjustment_get_value (hadjustment),
- gtk_adjustment_get_value (vadjustment));
+ scroll_to (canvas,
+ gtk_adjustment_get_value (hadjustment),
+ gtk_adjustment_get_value (vadjustment));
- g_signal_emit_by_name (hadjustment, "changed");
- g_signal_emit_by_name (vadjustment, "changed");
+ g_signal_emit_by_name (hadjustment, "changed");
+ g_signal_emit_by_name (vadjustment, "changed");
}
/* Emits an event for an item in the canvas, be it the current item, grabbed
@@ -2326,598 +2710,728 @@ eel_canvas_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
*/
static int
-emit_event (EelCanvas *canvas, GdkEvent *event)
-{
- GdkEvent ev;
- gint finished;
- EelCanvasItem *item;
- EelCanvasItem *parent;
- guint mask;
-
- /* Could be an old pick event */
- if (!gtk_widget_get_realized (GTK_WIDGET (canvas))) {
- return FALSE;
- }
-
- /* Perform checks for grabbed items */
-
- if (canvas->grabbed_item &&
- !is_descendant (canvas->current_item, canvas->grabbed_item)) {
- return FALSE;
- }
-
- if (canvas->grabbed_item) {
- switch (event->type) {
- case GDK_ENTER_NOTIFY:
- mask = GDK_ENTER_NOTIFY_MASK;
- break;
+emit_event (EelCanvas *canvas,
+ GdkEvent *event)
+{
+ GdkEvent ev;
+ gint finished;
+ EelCanvasItem *item;
+ EelCanvasItem *parent;
+ guint mask;
+
+ /* Could be an old pick event */
+ if (!gtk_widget_get_realized (GTK_WIDGET (canvas)))
+ {
+ return FALSE;
+ }
+
+ /* Perform checks for grabbed items */
+
+ if (canvas->grabbed_item &&
+ !is_descendant (canvas->current_item, canvas->grabbed_item))
+ {
+ return FALSE;
+ }
+
+ if (canvas->grabbed_item)
+ {
+ switch (event->type)
+ {
+ case GDK_ENTER_NOTIFY:
+ {
+ mask = GDK_ENTER_NOTIFY_MASK;
+ }
+ break;
+
+ case GDK_LEAVE_NOTIFY:
+ {
+ mask = GDK_LEAVE_NOTIFY_MASK;
+ }
+ break;
+
+ case GDK_MOTION_NOTIFY:
+ {
+ mask = GDK_POINTER_MOTION_MASK;
+ }
+ break;
+
+ case GDK_BUTTON_PRESS:
+ case GDK_2BUTTON_PRESS:
+ case GDK_3BUTTON_PRESS:
+ {
+ mask = GDK_BUTTON_PRESS_MASK;
+ }
+ break;
+
+ case GDK_BUTTON_RELEASE:
+ {
+ mask = GDK_BUTTON_RELEASE_MASK;
+ }
+ break;
+
+ case GDK_KEY_PRESS:
+ {
+ mask = GDK_KEY_PRESS_MASK;
+ }
+ break;
+
+ case GDK_KEY_RELEASE:
+ {
+ mask = GDK_KEY_RELEASE_MASK;
+ }
+ break;
+
+ default:
+ {
+ mask = 0;
+ }
+ break;
+ }
- case GDK_LEAVE_NOTIFY:
- mask = GDK_LEAVE_NOTIFY_MASK;
- break;
+ if (!(mask & canvas->grabbed_event_mask))
+ {
+ return FALSE;
+ }
+ }
+
+ /* Convert to world coordinates -- we have two cases because of diferent
+ * offsets of the fields in the event structures.
+ */
+
+ ev = *event;
+
+ switch (ev.type)
+ {
+ case GDK_ENTER_NOTIFY:
+ case GDK_LEAVE_NOTIFY:
+ {
+ eel_canvas_window_to_world (canvas,
+ ev.crossing.x, ev.crossing.y,
+ &ev.crossing.x, &ev.crossing.y);
+ }
+ break;
+
+ case GDK_MOTION_NOTIFY:
+ case GDK_BUTTON_PRESS:
+ case GDK_2BUTTON_PRESS:
+ case GDK_3BUTTON_PRESS:
+ case GDK_BUTTON_RELEASE:
+ {
+ eel_canvas_window_to_world (canvas,
+ ev.motion.x, ev.motion.y,
+ &ev.motion.x, &ev.motion.y);
+ }
+ break;
+
+ default:
+ {
+ }
+ break;
+ }
+
+ /* Choose where we send the event */
- case GDK_MOTION_NOTIFY:
- mask = GDK_POINTER_MOTION_MASK;
- break;
+ item = canvas->current_item;
- case GDK_BUTTON_PRESS:
- case GDK_2BUTTON_PRESS:
- case GDK_3BUTTON_PRESS:
- mask = GDK_BUTTON_PRESS_MASK;
- break;
+ if (canvas->focused_item
+ && ((event->type == GDK_KEY_PRESS) ||
+ (event->type == GDK_KEY_RELEASE) ||
+ (event->type == GDK_FOCUS_CHANGE)))
+ {
+ item = canvas->focused_item;
+ }
- case GDK_BUTTON_RELEASE:
- mask = GDK_BUTTON_RELEASE_MASK;
- break;
+ /* The event is propagated up the hierarchy (for if someone connected to
+ * a group instead of a leaf event), and emission is stopped if a
+ * handler returns TRUE, just like for GtkWidget events.
+ */
- case GDK_KEY_PRESS:
- mask = GDK_KEY_PRESS_MASK;
- break;
+ finished = FALSE;
- case GDK_KEY_RELEASE:
- mask = GDK_KEY_RELEASE_MASK;
- break;
+ while (item && !finished)
+ {
+ g_object_ref (item);
- default:
- mask = 0;
- break;
- }
+ g_signal_emit (
+ G_OBJECT (item), item_signals[ITEM_EVENT], 0,
+ &ev, &finished);
- if (!(mask & canvas->grabbed_event_mask))
- return FALSE;
- }
+ parent = item->parent;
+ g_object_unref (item);
- /* Convert to world coordinates -- we have two cases because of diferent
- * offsets of the fields in the event structures.
- */
+ item = parent;
+ }
- ev = *event;
+ return finished;
+}
- switch (ev.type)
+/* Re-picks the current item in the canvas, based on the event's coordinates.
+ * Also emits enter/leave events for items as appropriate.
+ */
+static int
+pick_current_item (EelCanvas *canvas,
+ GdkEvent *event)
+{
+ int button_down;
+ double x, y;
+ int cx, cy;
+ int retval;
+
+ retval = FALSE;
+
+ /* If a button is down, we'll perform enter and leave events on the
+ * current item, but not enter on any other item. This is more or less
+ * like X pointer grabbing for canvas items.
+ */
+ button_down = canvas->state & (GDK_BUTTON1_MASK
+ | GDK_BUTTON2_MASK
+ | GDK_BUTTON3_MASK
+ | GDK_BUTTON4_MASK
+ | GDK_BUTTON5_MASK);
+ if (!button_down)
+ {
+ canvas->left_grabbed_item = FALSE;
+ }
+
+ /* Save the event in the canvas. This is used to synthesize enter and
+ * leave events in case the current item changes. It is also used to
+ * re-pick the current item if the current one gets deleted. Also,
+ * synthesize an enter event.
+ */
+ if (event != &canvas->pick_event)
+ {
+ if ((event->type == GDK_MOTION_NOTIFY) || (event->type == GDK_BUTTON_RELEASE))
{
- case GDK_ENTER_NOTIFY:
- case GDK_LEAVE_NOTIFY:
- eel_canvas_window_to_world (canvas,
- ev.crossing.x, ev.crossing.y,
- &ev.crossing.x, &ev.crossing.y);
- break;
+ /* these fields have the same offsets in both types of events */
+
+ canvas->pick_event.crossing.type = GDK_ENTER_NOTIFY;
+ canvas->pick_event.crossing.window = event->motion.window;
+ canvas->pick_event.crossing.send_event = event->motion.send_event;
+ canvas->pick_event.crossing.subwindow = NULL;
+ canvas->pick_event.crossing.x = event->motion.x;
+ canvas->pick_event.crossing.y = event->motion.y;
+ canvas->pick_event.crossing.mode = GDK_CROSSING_NORMAL;
+ canvas->pick_event.crossing.detail = GDK_NOTIFY_NONLINEAR;
+ canvas->pick_event.crossing.focus = FALSE;
+ canvas->pick_event.crossing.state = event->motion.state;
+
+ /* these fields don't have the same offsets in both types of events */
+
+ if (event->type == GDK_MOTION_NOTIFY)
+ {
+ canvas->pick_event.crossing.x_root = event->motion.x_root;
+ canvas->pick_event.crossing.y_root = event->motion.y_root;
+ }
+ else
+ {
+ canvas->pick_event.crossing.x_root = event->button.x_root;
+ canvas->pick_event.crossing.y_root = event->button.y_root;
+ }
+ }
+ else
+ {
+ canvas->pick_event = *event;
+ }
+ }
- case GDK_MOTION_NOTIFY:
- case GDK_BUTTON_PRESS:
- case GDK_2BUTTON_PRESS:
- case GDK_3BUTTON_PRESS:
- case GDK_BUTTON_RELEASE:
- eel_canvas_window_to_world (canvas,
- ev.motion.x, ev.motion.y,
- &ev.motion.x, &ev.motion.y);
- break;
+ /* Don't do anything else if this is a recursive call */
- default:
- break;
- }
+ if (canvas->in_repick)
+ {
+ return retval;
+ }
- /* Choose where we send the event */
+ /* LeaveNotify means that there is no current item, so we don't look for one */
- item = canvas->current_item;
+ if (canvas->pick_event.type != GDK_LEAVE_NOTIFY)
+ {
+ /* these fields don't have the same offsets in both types of events */
- if (canvas->focused_item
- && ((event->type == GDK_KEY_PRESS) ||
- (event->type == GDK_KEY_RELEASE) ||
- (event->type == GDK_FOCUS_CHANGE)))
- item = canvas->focused_item;
+ if (canvas->pick_event.type == GDK_ENTER_NOTIFY)
+ {
+ x = canvas->pick_event.crossing.x;
+ y = canvas->pick_event.crossing.y;
+ }
+ else
+ {
+ x = canvas->pick_event.motion.x;
+ y = canvas->pick_event.motion.y;
+ }
- /* The event is propagated up the hierarchy (for if someone connected to
- * a group instead of a leaf event), and emission is stopped if a
- * handler returns TRUE, just like for GtkWidget events.
- */
+ /* canvas pixel coords */
- finished = FALSE;
+ cx = (int) (x + 0.5);
+ cy = (int) (y + 0.5);
- while (item && !finished) {
- g_object_ref (item);
+ /* world coords */
+ eel_canvas_c2w (canvas, cx, cy, &x, &y);
- g_signal_emit (
- G_OBJECT (item), item_signals[ITEM_EVENT], 0,
- &ev, &finished);
-
- parent = item->parent;
- g_object_unref (item);
+ /* find the closest item */
+ if (canvas->root->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ eel_canvas_item_invoke_point (canvas->root, x, y, cx, cy,
+ &canvas->new_current_item);
+ }
+ else
+ {
+ canvas->new_current_item = NULL;
+ }
+ }
+ else
+ {
+ canvas->new_current_item = NULL;
+ }
+
+ if ((canvas->new_current_item == canvas->current_item) && !canvas->left_grabbed_item)
+ {
+ return retval; /* current item did not change */
+ }
+ /* Synthesize events for old and new current items */
+
+ if ((canvas->new_current_item != canvas->current_item)
+ && (canvas->current_item != NULL)
+ && !canvas->left_grabbed_item)
+ {
+ GdkEvent new_event;
+
+ new_event = canvas->pick_event;
+ new_event.type = GDK_LEAVE_NOTIFY;
+
+ new_event.crossing.detail = GDK_NOTIFY_ANCESTOR;
+ new_event.crossing.subwindow = NULL;
+ canvas->in_repick = TRUE;
+ retval = emit_event (canvas, &new_event);
+ canvas->in_repick = FALSE;
+ }
+
+ /* new_current_item may have been set to NULL during the call to emit_event() above */
+
+ if ((canvas->new_current_item != canvas->current_item) && button_down)
+ {
+ canvas->current_item = canvas->new_current_item;
+ canvas->left_grabbed_item = TRUE;
+ return retval;
+ }
- item = parent;
- }
+ /* Handle the rest of cases */
- return finished;
-}
+ canvas->left_grabbed_item = FALSE;
+ canvas->current_item = canvas->new_current_item;
-/* Re-picks the current item in the canvas, based on the event's coordinates.
- * Also emits enter/leave events for items as appropriate.
- */
-static int
-pick_current_item (EelCanvas *canvas, GdkEvent *event)
-{
- int button_down;
- double x, y;
- int cx, cy;
- int retval;
-
- retval = FALSE;
-
- /* If a button is down, we'll perform enter and leave events on the
- * current item, but not enter on any other item. This is more or less
- * like X pointer grabbing for canvas items.
- */
- button_down = canvas->state & (GDK_BUTTON1_MASK
- | GDK_BUTTON2_MASK
- | GDK_BUTTON3_MASK
- | GDK_BUTTON4_MASK
- | GDK_BUTTON5_MASK);
- if (!button_down)
- canvas->left_grabbed_item = FALSE;
-
- /* Save the event in the canvas. This is used to synthesize enter and
- * leave events in case the current item changes. It is also used to
- * re-pick the current item if the current one gets deleted. Also,
- * synthesize an enter event.
- */
- if (event != &canvas->pick_event) {
- if ((event->type == GDK_MOTION_NOTIFY) || (event->type == GDK_BUTTON_RELEASE)) {
- /* these fields have the same offsets in both types of events */
-
- canvas->pick_event.crossing.type = GDK_ENTER_NOTIFY;
- canvas->pick_event.crossing.window = event->motion.window;
- canvas->pick_event.crossing.send_event = event->motion.send_event;
- canvas->pick_event.crossing.subwindow = NULL;
- canvas->pick_event.crossing.x = event->motion.x;
- canvas->pick_event.crossing.y = event->motion.y;
- canvas->pick_event.crossing.mode = GDK_CROSSING_NORMAL;
- canvas->pick_event.crossing.detail = GDK_NOTIFY_NONLINEAR;
- canvas->pick_event.crossing.focus = FALSE;
- canvas->pick_event.crossing.state = event->motion.state;
-
- /* these fields don't have the same offsets in both types of events */
-
- if (event->type == GDK_MOTION_NOTIFY) {
- canvas->pick_event.crossing.x_root = event->motion.x_root;
- canvas->pick_event.crossing.y_root = event->motion.y_root;
- } else {
- canvas->pick_event.crossing.x_root = event->button.x_root;
- canvas->pick_event.crossing.y_root = event->button.y_root;
- }
- } else
- canvas->pick_event = *event;
- }
-
- /* Don't do anything else if this is a recursive call */
-
- if (canvas->in_repick)
- return retval;
-
- /* LeaveNotify means that there is no current item, so we don't look for one */
-
- if (canvas->pick_event.type != GDK_LEAVE_NOTIFY) {
- /* these fields don't have the same offsets in both types of events */
-
- if (canvas->pick_event.type == GDK_ENTER_NOTIFY) {
- x = canvas->pick_event.crossing.x;
- y = canvas->pick_event.crossing.y;
- } else {
- x = canvas->pick_event.motion.x;
- y = canvas->pick_event.motion.y;
- }
-
- /* canvas pixel coords */
-
- cx = (int) (x + 0.5);
- cy = (int) (y + 0.5);
-
- /* world coords */
- eel_canvas_c2w (canvas, cx, cy, &x, &y);
-
- /* find the closest item */
- if (canvas->root->flags & EEL_CANVAS_ITEM_MAPPED)
- eel_canvas_item_invoke_point (canvas->root, x, y, cx, cy,
- &canvas->new_current_item);
- else
- canvas->new_current_item = NULL;
- } else
- canvas->new_current_item = NULL;
-
- if ((canvas->new_current_item == canvas->current_item) && !canvas->left_grabbed_item)
- return retval; /* current item did not change */
-
- /* Synthesize events for old and new current items */
-
- if ((canvas->new_current_item != canvas->current_item)
- && (canvas->current_item != NULL)
- && !canvas->left_grabbed_item) {
- GdkEvent new_event;
-
- new_event = canvas->pick_event;
- new_event.type = GDK_LEAVE_NOTIFY;
-
- new_event.crossing.detail = GDK_NOTIFY_ANCESTOR;
- new_event.crossing.subwindow = NULL;
- canvas->in_repick = TRUE;
- retval = emit_event (canvas, &new_event);
- canvas->in_repick = FALSE;
- }
-
- /* new_current_item may have been set to NULL during the call to emit_event() above */
-
- if ((canvas->new_current_item != canvas->current_item) && button_down) {
- canvas->current_item = canvas->new_current_item;
- canvas->left_grabbed_item = TRUE;
- return retval;
- }
-
- /* Handle the rest of cases */
-
- canvas->left_grabbed_item = FALSE;
- canvas->current_item = canvas->new_current_item;
-
- if (canvas->current_item != NULL) {
- GdkEvent new_event;
-
- new_event = canvas->pick_event;
- new_event.type = GDK_ENTER_NOTIFY;
- new_event.crossing.detail = GDK_NOTIFY_ANCESTOR;
- new_event.crossing.subwindow = NULL;
- retval = emit_event (canvas, &new_event);
- }
-
- return retval;
+ if (canvas->current_item != NULL)
+ {
+ GdkEvent new_event;
+
+ new_event = canvas->pick_event;
+ new_event.type = GDK_ENTER_NOTIFY;
+ new_event.crossing.detail = GDK_NOTIFY_ANCESTOR;
+ new_event.crossing.subwindow = NULL;
+ retval = emit_event (canvas, &new_event);
+ }
+
+ return retval;
}
/* Button event handler for the canvas */
static gint
-eel_canvas_button (GtkWidget *widget, GdkEventButton *event)
-{
- EelCanvas *canvas;
- int mask;
- int retval;
-
- g_return_val_if_fail (EEL_IS_CANVAS (widget), FALSE);
- g_return_val_if_fail (event != NULL, FALSE);
-
- retval = FALSE;
-
- canvas = EEL_CANVAS (widget);
-
- /* Don't handle extra mouse button events */
- if (event->button > 5)
- return FALSE;
-
- /*
- * dispatch normally regardless of the event's window if an item has
- * has a pointer grab in effect
- */
- if (!canvas->grabbed_item && event->window != gtk_layout_get_bin_window (GTK_LAYOUT (canvas)))
- return retval;
-
- switch (event->button) {
- case 1:
- mask = GDK_BUTTON1_MASK;
- break;
- case 2:
- mask = GDK_BUTTON2_MASK;
- break;
- case 3:
- mask = GDK_BUTTON3_MASK;
- break;
- case 4:
- mask = GDK_BUTTON4_MASK;
- break;
- case 5:
- mask = GDK_BUTTON5_MASK;
- break;
- default:
- mask = 0;
- }
-
- switch (event->type) {
- case GDK_BUTTON_PRESS:
- case GDK_2BUTTON_PRESS:
- case GDK_3BUTTON_PRESS:
- /* Pick the current item as if the button were not pressed, and
- * then process the event.
- */
- event->state ^= mask;
- canvas->state = event->state;
- pick_current_item (canvas, (GdkEvent *) event);
- event->state ^= mask;
- canvas->state = event->state;
- retval = emit_event (canvas, (GdkEvent *) event);
- break;
-
- case GDK_BUTTON_RELEASE:
- /* Process the event as if the button were pressed, then repick
- * after the button has been released
- */
- canvas->state = event->state;
- retval = emit_event (canvas, (GdkEvent *) event);
- event->state ^= mask;
- canvas->state = event->state;
- pick_current_item (canvas, (GdkEvent *) event);
- event->state ^= mask;
- break;
-
- default:
- g_assert_not_reached ();
- }
-
- return retval;
+eel_canvas_button (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ EelCanvas *canvas;
+ int mask;
+ int retval;
+
+ g_return_val_if_fail (EEL_IS_CANVAS (widget), FALSE);
+ g_return_val_if_fail (event != NULL, FALSE);
+
+ retval = FALSE;
+
+ canvas = EEL_CANVAS (widget);
+
+ /* Don't handle extra mouse button events */
+ if (event->button > 5)
+ {
+ return FALSE;
+ }
+
+ /*
+ * dispatch normally regardless of the event's window if an item has
+ * has a pointer grab in effect
+ */
+ if (!canvas->grabbed_item && event->window != gtk_layout_get_bin_window (GTK_LAYOUT (canvas)))
+ {
+ return retval;
+ }
+
+ switch (event->button)
+ {
+ case 1:
+ {
+ mask = GDK_BUTTON1_MASK;
+ }
+ break;
+
+ case 2:
+ {
+ mask = GDK_BUTTON2_MASK;
+ }
+ break;
+
+ case 3:
+ {
+ mask = GDK_BUTTON3_MASK;
+ }
+ break;
+
+ case 4:
+ {
+ mask = GDK_BUTTON4_MASK;
+ }
+ break;
+
+ case 5:
+ {
+ mask = GDK_BUTTON5_MASK;
+ }
+ break;
+
+ default:
+ mask = 0;
+ }
+
+ switch (event->type)
+ {
+ case GDK_BUTTON_PRESS:
+ case GDK_2BUTTON_PRESS:
+ case GDK_3BUTTON_PRESS:
+ {
+ /* Pick the current item as if the button were not pressed, and
+ * then process the event.
+ */
+ event->state ^= mask;
+ canvas->state = event->state;
+ pick_current_item (canvas, (GdkEvent *) event);
+ event->state ^= mask;
+ canvas->state = event->state;
+ retval = emit_event (canvas, (GdkEvent *) event);
+ }
+ break;
+
+ case GDK_BUTTON_RELEASE:
+ {
+ /* Process the event as if the button were pressed, then repick
+ * after the button has been released
+ */
+ canvas->state = event->state;
+ retval = emit_event (canvas, (GdkEvent *) event);
+ event->state ^= mask;
+ canvas->state = event->state;
+ pick_current_item (canvas, (GdkEvent *) event);
+ event->state ^= mask;
+ }
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ return retval;
}
/* Motion event handler for the canvas */
static gint
-eel_canvas_motion (GtkWidget *widget, GdkEventMotion *event)
+eel_canvas_motion (GtkWidget *widget,
+ GdkEventMotion *event)
{
- EelCanvas *canvas;
+ EelCanvas *canvas;
- g_return_val_if_fail (EEL_IS_CANVAS (widget), FALSE);
- g_return_val_if_fail (event != NULL, FALSE);
+ g_return_val_if_fail (EEL_IS_CANVAS (widget), FALSE);
+ g_return_val_if_fail (event != NULL, FALSE);
- canvas = EEL_CANVAS (widget);
+ canvas = EEL_CANVAS (widget);
- if (event->window != gtk_layout_get_bin_window (GTK_LAYOUT (canvas)))
- return FALSE;
+ if (event->window != gtk_layout_get_bin_window (GTK_LAYOUT (canvas)))
+ {
+ return FALSE;
+ }
- canvas->state = event->state;
- pick_current_item (canvas, (GdkEvent *) event);
- return emit_event (canvas, (GdkEvent *) event);
+ canvas->state = event->state;
+ pick_current_item (canvas, (GdkEvent *) event);
+ return emit_event (canvas, (GdkEvent *) event);
}
/* Key event handler for the canvas */
static gint
-eel_canvas_key (GtkWidget *widget, GdkEventKey *event)
+eel_canvas_key (GtkWidget *widget,
+ GdkEventKey *event)
{
- EelCanvas *canvas;
-
- g_return_val_if_fail (EEL_IS_CANVAS (widget), FALSE);
- g_return_val_if_fail (event != NULL, FALSE);
-
- canvas = EEL_CANVAS (widget);
-
- if (emit_event (canvas, (GdkEvent *) event))
- return TRUE;
- if (event->type == GDK_KEY_RELEASE)
- return GTK_WIDGET_CLASS (canvas_parent_class)->key_release_event (widget, event);
- else
- return GTK_WIDGET_CLASS (canvas_parent_class)->key_press_event (widget, event);
+ EelCanvas *canvas;
+
+ g_return_val_if_fail (EEL_IS_CANVAS (widget), FALSE);
+ g_return_val_if_fail (event != NULL, FALSE);
+
+ canvas = EEL_CANVAS (widget);
+
+ if (emit_event (canvas, (GdkEvent *) event))
+ {
+ return TRUE;
+ }
+ if (event->type == GDK_KEY_RELEASE)
+ {
+ return GTK_WIDGET_CLASS (canvas_parent_class)->key_release_event (widget, event);
+ }
+ else
+ {
+ return GTK_WIDGET_CLASS (canvas_parent_class)->key_press_event (widget, event);
+ }
}
/* Crossing event handler for the canvas */
static gint
-eel_canvas_crossing (GtkWidget *widget, GdkEventCrossing *event)
+eel_canvas_crossing (GtkWidget *widget,
+ GdkEventCrossing *event)
{
- EelCanvas *canvas;
+ EelCanvas *canvas;
- g_return_val_if_fail (EEL_IS_CANVAS (widget), FALSE);
- g_return_val_if_fail (event != NULL, FALSE);
+ g_return_val_if_fail (EEL_IS_CANVAS (widget), FALSE);
+ g_return_val_if_fail (event != NULL, FALSE);
- canvas = EEL_CANVAS (widget);
+ canvas = EEL_CANVAS (widget);
- if (event->window != gtk_layout_get_bin_window (GTK_LAYOUT (canvas)))
- return FALSE;
+ if (event->window != gtk_layout_get_bin_window (GTK_LAYOUT (canvas)))
+ {
+ return FALSE;
+ }
- canvas->state = event->state;
- return pick_current_item (canvas, (GdkEvent *) event);
+ canvas->state = event->state;
+ return pick_current_item (canvas, (GdkEvent *) event);
}
/* Focus in handler for the canvas */
static gint
-eel_canvas_focus_in (GtkWidget *widget, GdkEventFocus *event)
+eel_canvas_focus_in (GtkWidget *widget,
+ GdkEventFocus *event)
{
- EelCanvas *canvas;
-
- canvas = EEL_CANVAS (widget);
-
- if (canvas->focused_item)
- return emit_event (canvas, (GdkEvent *) event);
- else
- return FALSE;
+ EelCanvas *canvas;
+
+ canvas = EEL_CANVAS (widget);
+
+ if (canvas->focused_item)
+ {
+ return emit_event (canvas, (GdkEvent *) event);
+ }
+ else
+ {
+ return FALSE;
+ }
}
/* Focus out handler for the canvas */
static gint
-eel_canvas_focus_out (GtkWidget *widget, GdkEventFocus *event)
+eel_canvas_focus_out (GtkWidget *widget,
+ GdkEventFocus *event)
{
- EelCanvas *canvas;
-
- canvas = EEL_CANVAS (widget);
-
- if (canvas->focused_item)
- return emit_event (canvas, (GdkEvent *) event);
- else
- return FALSE;
+ EelCanvas *canvas;
+
+ canvas = EEL_CANVAS (widget);
+
+ if (canvas->focused_item)
+ {
+ return emit_event (canvas, (GdkEvent *) event);
+ }
+ else
+ {
+ return FALSE;
+ }
}
static cairo_region_t *
eel_cairo_get_clip_region (cairo_t *cr)
{
- cairo_rectangle_list_t *list;
- cairo_region_t *region;
- int i;
+ cairo_rectangle_list_t *list;
+ cairo_region_t *region;
+ int i;
- list = cairo_copy_clip_rectangle_list (cr);
- if (list->status == CAIRO_STATUS_CLIP_NOT_REPRESENTABLE) {
- cairo_rectangle_int_t clip_rect;
+ list = cairo_copy_clip_rectangle_list (cr);
+ if (list->status == CAIRO_STATUS_CLIP_NOT_REPRESENTABLE)
+ {
+ cairo_rectangle_int_t clip_rect;
- cairo_rectangle_list_destroy (list);
+ cairo_rectangle_list_destroy (list);
- if (!gdk_cairo_get_clip_rectangle (cr, &clip_rect))
- return NULL;
- return cairo_region_create_rectangle (&clip_rect);
+ if (!gdk_cairo_get_clip_rectangle (cr, &clip_rect))
+ {
+ return NULL;
}
+ return cairo_region_create_rectangle (&clip_rect);
+ }
- region = cairo_region_create ();
- for (i = list->num_rectangles - 1; i >= 0; --i) {
- cairo_rectangle_t *rect = &list->rectangles[i];
- cairo_rectangle_int_t clip_rect;
+ region = cairo_region_create ();
+ for (i = list->num_rectangles - 1; i >= 0; --i)
+ {
+ cairo_rectangle_t *rect = &list->rectangles[i];
+ cairo_rectangle_int_t clip_rect;
- clip_rect.x = floor (rect->x);
- clip_rect.y = floor (rect->y);
- clip_rect.width = ceil (rect->x + rect->width) - clip_rect.x;
- clip_rect.height = ceil (rect->y + rect->height) - clip_rect.y;
+ clip_rect.x = floor (rect->x);
+ clip_rect.y = floor (rect->y);
+ clip_rect.width = ceil (rect->x + rect->width) - clip_rect.x;
+ clip_rect.height = ceil (rect->y + rect->height) - clip_rect.y;
- if (cairo_region_union_rectangle (region, &clip_rect) != CAIRO_STATUS_SUCCESS) {
- cairo_region_destroy (region);
- region = NULL;
- break;
- }
+ if (cairo_region_union_rectangle (region, &clip_rect) != CAIRO_STATUS_SUCCESS)
+ {
+ cairo_region_destroy (region);
+ region = NULL;
+ break;
}
+ }
- cairo_rectangle_list_destroy (list);
- return region;
+ cairo_rectangle_list_destroy (list);
+ return region;
}
/* Expose handler for the canvas */
static gboolean
-eel_canvas_draw (GtkWidget *widget, cairo_t *cr)
+eel_canvas_draw (GtkWidget *widget,
+ cairo_t *cr)
{
- EelCanvas *canvas = EEL_CANVAS (widget);
- GdkWindow *bin_window;
- cairo_region_t *region;
+ EelCanvas *canvas = EEL_CANVAS (widget);
+ GdkWindow *bin_window;
+ cairo_region_t *region;
- if (!gdk_cairo_get_clip_rectangle (cr, NULL))
- return FALSE;
+ if (!gdk_cairo_get_clip_rectangle (cr, NULL))
+ {
+ return FALSE;
+ }
- bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (widget));
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (widget));
- if (!gtk_cairo_should_draw_window (cr, bin_window))
- return FALSE;
+ if (!gtk_cairo_should_draw_window (cr, bin_window))
+ {
+ return FALSE;
+ }
- cairo_save (cr);
+ cairo_save (cr);
- gtk_cairo_transform_to_window (cr, widget, bin_window);
+ gtk_cairo_transform_to_window (cr, widget, bin_window);
- region = eel_cairo_get_clip_region (cr);
- if (region == NULL) {
- cairo_restore (cr);
- return FALSE;
- }
+ region = eel_cairo_get_clip_region (cr);
+ if (region == NULL)
+ {
+ cairo_restore (cr);
+ return FALSE;
+ }
#ifdef VERBOSE
- g_print ("Draw\n");
+ g_print ("Draw\n");
#endif
- /* If there are any outstanding items that need updating, do them now */
- if (canvas->idle_id) {
- g_source_remove (canvas->idle_id);
- canvas->idle_id = 0;
- }
- if (canvas->need_update) {
- g_return_val_if_fail (!canvas->doing_update, FALSE);
+ /* If there are any outstanding items that need updating, do them now */
+ if (canvas->idle_id)
+ {
+ g_source_remove (canvas->idle_id);
+ canvas->idle_id = 0;
+ }
+ if (canvas->need_update)
+ {
+ g_return_val_if_fail (!canvas->doing_update, FALSE);
- canvas->doing_update = TRUE;
- eel_canvas_item_invoke_update (canvas->root, 0, 0, 0);
+ canvas->doing_update = TRUE;
+ eel_canvas_item_invoke_update (canvas->root, 0, 0, 0);
- g_return_val_if_fail (canvas->doing_update, FALSE);
+ g_return_val_if_fail (canvas->doing_update, FALSE);
- canvas->doing_update = FALSE;
+ canvas->doing_update = FALSE;
- canvas->need_update = FALSE;
- }
+ canvas->need_update = FALSE;
+ }
- if (canvas->root->flags & EEL_CANVAS_ITEM_MAPPED)
- EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->draw (canvas->root, cr, region);
+ if (canvas->root->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->draw (canvas->root, cr, region);
+ }
- cairo_restore (cr);
+ cairo_restore (cr);
- /* Chain up to get exposes on child widgets */
- if (GTK_WIDGET_CLASS (canvas_parent_class)->draw)
- GTK_WIDGET_CLASS (canvas_parent_class)->draw (widget, cr);
+ /* Chain up to get exposes on child widgets */
+ if (GTK_WIDGET_CLASS (canvas_parent_class)->draw)
+ {
+ GTK_WIDGET_CLASS (canvas_parent_class)->draw (widget, cr);
+ }
- cairo_region_destroy (region);
- return FALSE;
+ cairo_region_destroy (region);
+ return FALSE;
}
static void
do_update (EelCanvas *canvas)
{
- /* Cause the update if necessary */
+ /* Cause the update if necessary */
update_again:
- if (canvas->need_update) {
- g_return_if_fail (!canvas->doing_update);
+ if (canvas->need_update)
+ {
+ g_return_if_fail (!canvas->doing_update);
- canvas->doing_update = TRUE;
- eel_canvas_item_invoke_update (canvas->root, 0, 0, 0);
+ canvas->doing_update = TRUE;
+ eel_canvas_item_invoke_update (canvas->root, 0, 0, 0);
- g_return_if_fail (canvas->doing_update);
+ g_return_if_fail (canvas->doing_update);
- canvas->doing_update = FALSE;
+ canvas->doing_update = FALSE;
- canvas->need_update = FALSE;
- }
+ canvas->need_update = FALSE;
+ }
- /* Pick new current item */
+ /* Pick new current item */
- while (canvas->need_repick) {
- canvas->need_repick = FALSE;
- pick_current_item (canvas, &canvas->pick_event);
- }
+ while (canvas->need_repick)
+ {
+ canvas->need_repick = FALSE;
+ pick_current_item (canvas, &canvas->pick_event);
+ }
- /* it is possible that during picking we emitted an event in which
- the user then called some function which then requested update
- of something. Without this we'd be left in a state where
- need_update would have been left TRUE and the canvas would have
- been left unpainted. */
- if (canvas->need_update) {
- goto update_again;
- }
+ /* it is possible that during picking we emitted an event in which
+ * the user then called some function which then requested update
+ * of something. Without this we'd be left in a state where
+ * need_update would have been left TRUE and the canvas would have
+ * been left unpainted. */
+ if (canvas->need_update)
+ {
+ goto update_again;
+ }
}
/* Idle handler for the canvas. It deals with pending updates and redraws. */
static gint
idle_handler (gpointer data)
{
- EelCanvas *canvas;
+ EelCanvas *canvas;
- canvas = EEL_CANVAS (data);
- do_update (canvas);
+ canvas = EEL_CANVAS (data);
+ do_update (canvas);
- /* Reset idle id */
- canvas->idle_id = 0;
+ /* Reset idle id */
+ canvas->idle_id = 0;
- return FALSE;
+ return FALSE;
}
/* Convenience function to add an idle handler to a canvas */
static void
add_idle (EelCanvas *canvas)
{
- if (!canvas->idle_id) {
- /* We let the update idle handler have higher priority
- * than the redraw idle handler so the canvas state
- * will be updated during the expose event. canvas in
- * expose_event.
- */
- canvas->idle_id = g_idle_add_full (GDK_PRIORITY_REDRAW - 20,
- idle_handler, canvas, NULL);
- }
+ if (!canvas->idle_id)
+ {
+ /* We let the update idle handler have higher priority
+ * than the redraw idle handler so the canvas state
+ * will be updated during the expose event. canvas in
+ * expose_event.
+ */
+ canvas->idle_id = g_idle_add_full (GDK_PRIORITY_REDRAW - 20,
+ idle_handler, canvas, NULL);
+ }
}
/**
@@ -2931,9 +3445,9 @@ add_idle (EelCanvas *canvas)
EelCanvasGroup *
eel_canvas_root (EelCanvas *canvas)
{
- g_return_val_if_fail (EEL_IS_CANVAS (canvas), NULL);
+ g_return_val_if_fail (EEL_IS_CANVAS (canvas), NULL);
- return EEL_CANVAS_GROUP (canvas->root);
+ return EEL_CANVAS_GROUP (canvas->root);
}
@@ -2950,48 +3464,54 @@ eel_canvas_root (EelCanvas *canvas)
* is adjusted as appropriate to display as much of the new region as possible.
**/
void
-eel_canvas_set_scroll_region (EelCanvas *canvas, double x1, double y1, double x2, double y2)
+eel_canvas_set_scroll_region (EelCanvas *canvas,
+ double x1,
+ double y1,
+ double x2,
+ double y2)
{
- double wxofs, wyofs;
- int xofs, yofs;
- GtkAdjustment *vadjustment, *hadjustment;
-
- g_return_if_fail (EEL_IS_CANVAS (canvas));
-
- if ((canvas->scroll_x1 == x1) && (canvas->scroll_y1 == y1) &&
- (canvas->scroll_x2 == x2) && (canvas->scroll_y2 == y2)) {
- return;
- }
-
- /*
- * Set the new scrolling region. If possible, do not move the visible contents of the
- * canvas.
- */
- hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
- vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
-
- eel_canvas_c2w (canvas,
- gtk_adjustment_get_value (hadjustment) + canvas->zoom_xofs,
- gtk_adjustment_get_value (vadjustment) + canvas->zoom_yofs,
- /*canvas->zoom_xofs,
- canvas->zoom_yofs,*/
- &wxofs, &wyofs);
+ double wxofs, wyofs;
+ int xofs, yofs;
+ GtkAdjustment *vadjustment, *hadjustment;
- canvas->scroll_x1 = x1;
- canvas->scroll_y1 = y1;
- canvas->scroll_x2 = x2;
- canvas->scroll_y2 = y2;
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- eel_canvas_w2c (canvas, wxofs, wyofs, &xofs, &yofs);
-
- scroll_to (canvas, xofs, yofs);
-
- canvas->need_repick = TRUE;
-
- if (!(canvas->root->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE)) {
- canvas->root->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
- eel_canvas_request_update (canvas);
- }
+ if ((canvas->scroll_x1 == x1) && (canvas->scroll_y1 == y1) &&
+ (canvas->scroll_x2 == x2) && (canvas->scroll_y2 == y2))
+ {
+ return;
+ }
+
+ /*
+ * Set the new scrolling region. If possible, do not move the visible contents of the
+ * canvas.
+ */
+ hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
+ vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
+
+ eel_canvas_c2w (canvas,
+ gtk_adjustment_get_value (hadjustment) + canvas->zoom_xofs,
+ gtk_adjustment_get_value (vadjustment) + canvas->zoom_yofs,
+ /*canvas->zoom_xofs,
+ * canvas->zoom_yofs,*/
+ &wxofs, &wyofs);
+
+ canvas->scroll_x1 = x1;
+ canvas->scroll_y1 = y1;
+ canvas->scroll_x2 = x2;
+ canvas->scroll_y2 = y2;
+
+ eel_canvas_w2c (canvas, wxofs, wyofs, &xofs, &yofs);
+
+ scroll_to (canvas, xofs, yofs);
+
+ canvas->need_repick = TRUE;
+
+ if (!(canvas->root->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE))
+ {
+ canvas->root->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
+ eel_canvas_request_update (canvas);
+ }
}
@@ -3006,39 +3526,51 @@ eel_canvas_set_scroll_region (EelCanvas *canvas, double x1, double y1, double x2
* Queries the scrolling region of a canvas.
**/
void
-eel_canvas_get_scroll_region (EelCanvas *canvas, double *x1, double *y1, double *x2, double *y2)
+eel_canvas_get_scroll_region (EelCanvas *canvas,
+ double *x1,
+ double *y1,
+ double *x2,
+ double *y2)
{
- g_return_if_fail (EEL_IS_CANVAS (canvas));
-
- if (x1)
- *x1 = canvas->scroll_x1;
-
- if (y1)
- *y1 = canvas->scroll_y1;
-
- if (x2)
- *x2 = canvas->scroll_x2;
-
- if (y2)
- *y2 = canvas->scroll_y2;
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
+
+ if (x1)
+ {
+ *x1 = canvas->scroll_x1;
+ }
+
+ if (y1)
+ {
+ *y1 = canvas->scroll_y1;
+ }
+
+ if (x2)
+ {
+ *x2 = canvas->scroll_x2;
+ }
+
+ if (y2)
+ {
+ *y2 = canvas->scroll_y2;
+ }
}
void
eel_canvas_set_center_scroll_region (EelCanvas *canvas,
- gboolean center_scroll_region)
+ gboolean center_scroll_region)
{
- GtkAdjustment *vadjustment, *hadjustment;
+ GtkAdjustment *vadjustment, *hadjustment;
- g_return_if_fail (EEL_IS_CANVAS (canvas));
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- canvas->center_scroll_region = center_scroll_region != 0;
+ canvas->center_scroll_region = center_scroll_region != 0;
- hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (&canvas->layout));
- vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (&canvas->layout));
+ hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (&canvas->layout));
+ vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (&canvas->layout));
- scroll_to (canvas,
- gtk_adjustment_get_value (hadjustment),
- gtk_adjustment_get_value (vadjustment));
+ scroll_to (canvas,
+ gtk_adjustment_get_value (hadjustment),
+ gtk_adjustment_get_value (vadjustment));
}
@@ -3051,85 +3583,89 @@ eel_canvas_set_center_scroll_region (EelCanvas *canvas,
* correspond to one canvas unit.
**/
void
-eel_canvas_set_pixels_per_unit (EelCanvas *canvas, double n)
-{
- GtkWidget *widget;
- double cx, cy;
- int x1, y1;
- int center_x, center_y;
- GdkWindow *window;
- GdkWindowAttr attributes;
- gint attributes_mask;
- GtkAllocation allocation;
- GtkAdjustment *vadjustment, *hadjustment;
-
- g_return_if_fail (EEL_IS_CANVAS (canvas));
- g_return_if_fail (n > EEL_CANVAS_EPSILON);
-
- widget = GTK_WIDGET (canvas);
-
- gtk_widget_get_allocation (widget, &allocation);
- center_x = allocation.width / 2;
- center_y = allocation.height / 2;
-
- /* Find the coordinates of the screen center in units. */
- hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
- vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
- cx = (gtk_adjustment_get_value (hadjustment) + center_x) / canvas->pixels_per_unit + canvas->scroll_x1 + canvas->zoom_xofs;
- cy = (gtk_adjustment_get_value (vadjustment) + center_y) / canvas->pixels_per_unit + canvas->scroll_y1 + canvas->zoom_yofs;
-
- /* Now calculate the new offset of the upper left corner. (round not truncate) */
- x1 = ((cx - canvas->scroll_x1) * n) - center_x + .5;
- y1 = ((cy - canvas->scroll_y1) * n) - center_y + .5;
-
- canvas->pixels_per_unit = n;
-
- if (!(canvas->root->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE)) {
- canvas->root->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
- eel_canvas_request_update (canvas);
- }
-
- /* Map a background None window over the bin_window to avoid
- * scrolling the window scroll causing exposes.
- */
- window = NULL;
- if (gtk_widget_get_mapped (widget)) {
- GtkAllocation allocation;
- attributes.window_type = GDK_WINDOW_CHILD;
- gtk_widget_get_allocation (widget, &allocation);
- attributes.x = allocation.x;
- attributes.y = allocation.y;
- attributes.width = allocation.width;
- attributes.height = allocation.height;
- attributes.wclass = GDK_INPUT_OUTPUT;
- attributes.visual = gtk_widget_get_visual (widget);
- attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
-
- attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
-
- window = gdk_window_new (gtk_widget_get_parent_window (widget),
- &attributes, attributes_mask);
- gdk_window_set_user_data (window, widget);
-
- gdk_window_show (window);
- }
-
- scroll_to (canvas, x1, y1);
-
- /* If we created a an overlapping background None window, remove it how.
- *
- * TODO: We would like to temporarily set the bin_window background to
- * None to avoid clearing the bin_window to the background, but gdk doesn't
- * expose enought to let us do this, so we get a flash-effect here. At least
- * it looks better than scroll + expose.
- */
- if (window != NULL) {
- gdk_window_hide (window);
- gdk_window_set_user_data (window, NULL);
- gdk_window_destroy (window);
- }
-
- canvas->need_repick = TRUE;
+eel_canvas_set_pixels_per_unit (EelCanvas *canvas,
+ double n)
+{
+ GtkWidget *widget;
+ double cx, cy;
+ int x1, y1;
+ int center_x, center_y;
+ GdkWindow *window;
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+ GtkAllocation allocation;
+ GtkAdjustment *vadjustment, *hadjustment;
+
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
+ g_return_if_fail (n > EEL_CANVAS_EPSILON);
+
+ widget = GTK_WIDGET (canvas);
+
+ gtk_widget_get_allocation (widget, &allocation);
+ center_x = allocation.width / 2;
+ center_y = allocation.height / 2;
+
+ /* Find the coordinates of the screen center in units. */
+ hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
+ vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
+ cx = (gtk_adjustment_get_value (hadjustment) + center_x) / canvas->pixels_per_unit + canvas->scroll_x1 + canvas->zoom_xofs;
+ cy = (gtk_adjustment_get_value (vadjustment) + center_y) / canvas->pixels_per_unit + canvas->scroll_y1 + canvas->zoom_yofs;
+
+ /* Now calculate the new offset of the upper left corner. (round not truncate) */
+ x1 = ((cx - canvas->scroll_x1) * n) - center_x + .5;
+ y1 = ((cy - canvas->scroll_y1) * n) - center_y + .5;
+
+ canvas->pixels_per_unit = n;
+
+ if (!(canvas->root->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE))
+ {
+ canvas->root->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
+ eel_canvas_request_update (canvas);
+ }
+
+ /* Map a background None window over the bin_window to avoid
+ * scrolling the window scroll causing exposes.
+ */
+ window = NULL;
+ if (gtk_widget_get_mapped (widget))
+ {
+ GtkAllocation allocation;
+ attributes.window_type = GDK_WINDOW_CHILD;
+ gtk_widget_get_allocation (widget, &allocation);
+ attributes.x = allocation.x;
+ attributes.y = allocation.y;
+ attributes.width = allocation.width;
+ attributes.height = allocation.height;
+ attributes.wclass = GDK_INPUT_OUTPUT;
+ attributes.visual = gtk_widget_get_visual (widget);
+ attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
+
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
+
+ window = gdk_window_new (gtk_widget_get_parent_window (widget),
+ &attributes, attributes_mask);
+ gdk_window_set_user_data (window, widget);
+
+ gdk_window_show (window);
+ }
+
+ scroll_to (canvas, x1, y1);
+
+ /* If we created a an overlapping background None window, remove it how.
+ *
+ * TODO: We would like to temporarily set the bin_window background to
+ * None to avoid clearing the bin_window to the background, but gdk doesn't
+ * expose enought to let us do this, so we get a flash-effect here. At least
+ * it looks better than scroll + expose.
+ */
+ if (window != NULL)
+ {
+ gdk_window_hide (window);
+ gdk_window_set_user_data (window, NULL);
+ gdk_window_destroy (window);
+ }
+
+ canvas->need_repick = TRUE;
}
/**
@@ -3144,11 +3680,13 @@ eel_canvas_set_pixels_per_unit (EelCanvas *canvas, double n)
* scrollbars to the canvas layout's scrolling adjusments.
**/
void
-eel_canvas_scroll_to (EelCanvas *canvas, int cx, int cy)
+eel_canvas_scroll_to (EelCanvas *canvas,
+ int cx,
+ int cy)
{
- g_return_if_fail (EEL_IS_CANVAS (canvas));
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- scroll_to (canvas, cx, cy);
+ scroll_to (canvas, cx, cy);
}
/**
@@ -3161,20 +3699,26 @@ eel_canvas_scroll_to (EelCanvas *canvas, int cx, int cy)
* pixel units.
**/
void
-eel_canvas_get_scroll_offsets (EelCanvas *canvas, int *cx, int *cy)
+eel_canvas_get_scroll_offsets (EelCanvas *canvas,
+ int *cx,
+ int *cy)
{
- GtkAdjustment *vadjustment, *hadjustment;
+ GtkAdjustment *vadjustment, *hadjustment;
- g_return_if_fail (EEL_IS_CANVAS (canvas));
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
- vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
+ hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
+ vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
- if (cx)
- *cx = gtk_adjustment_get_value (hadjustment);
+ if (cx)
+ {
+ *cx = gtk_adjustment_get_value (hadjustment);
+ }
- if (cy)
- *cy = gtk_adjustment_get_value (vadjustment);
+ if (cy)
+ {
+ *cy = gtk_adjustment_get_value (vadjustment);
+ }
}
/**
@@ -3189,12 +3733,14 @@ eel_canvas_get_scroll_offsets (EelCanvas *canvas, int *cx, int *cy)
void
eel_canvas_update_now (EelCanvas *canvas)
{
- g_return_if_fail (EEL_IS_CANVAS (canvas));
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- if (!(canvas->need_update || canvas->need_redraw))
- return;
- remove_idle (canvas);
- do_update (canvas);
+ if (!(canvas->need_update || canvas->need_redraw))
+ {
+ return;
+ }
+ remove_idle (canvas);
+ do_update (canvas);
}
/**
@@ -3210,35 +3756,41 @@ eel_canvas_update_now (EelCanvas *canvas)
* coordinates.
**/
EelCanvasItem *
-eel_canvas_get_item_at (EelCanvas *canvas, double x, double y)
+eel_canvas_get_item_at (EelCanvas *canvas,
+ double x,
+ double y)
{
- EelCanvasItem *item;
- double dist;
- int cx, cy;
-
- g_return_val_if_fail (EEL_IS_CANVAS (canvas), NULL);
-
- eel_canvas_w2c (canvas, x, y, &cx, &cy);
-
- dist = eel_canvas_item_invoke_point (canvas->root, x, y, cx, cy, &item);
- if ((int) (dist * canvas->pixels_per_unit + 0.5) <= canvas->close_enough)
- return item;
- else
- return NULL;
+ EelCanvasItem *item;
+ double dist;
+ int cx, cy;
+
+ g_return_val_if_fail (EEL_IS_CANVAS (canvas), NULL);
+
+ eel_canvas_w2c (canvas, x, y, &cx, &cy);
+
+ dist = eel_canvas_item_invoke_point (canvas->root, x, y, cx, cy, &item);
+ if ((int) (dist * canvas->pixels_per_unit + 0.5) <= canvas->close_enough)
+ {
+ return item;
+ }
+ else
+ {
+ return NULL;
+ }
}
/* Queues an update of the canvas */
static void
eel_canvas_request_update (EelCanvas *canvas)
{
- EEL_CANVAS_GET_CLASS (canvas)->request_update (canvas);
+ EEL_CANVAS_GET_CLASS (canvas)->request_update (canvas);
}
static void
eel_canvas_request_update_real (EelCanvas *canvas)
{
- canvas->need_update = TRUE;
- add_idle (canvas);
+ canvas->need_update = TRUE;
+ add_idle (canvas);
}
/**
@@ -3254,22 +3806,29 @@ eel_canvas_request_update_real (EelCanvas *canvas)
* To be used only by item implementations.
**/
void
-eel_canvas_request_redraw (EelCanvas *canvas, int x1, int y1, int x2, int y2)
+eel_canvas_request_redraw (EelCanvas *canvas,
+ int x1,
+ int y1,
+ int x2,
+ int y2)
{
- GdkRectangle bbox;
+ GdkRectangle bbox;
- g_return_if_fail (EEL_IS_CANVAS (canvas));
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- if (!gtk_widget_is_drawable (GTK_WIDGET (canvas))
- || (x1 >= x2) || (y1 >= y2)) return;
+ if (!gtk_widget_is_drawable (GTK_WIDGET (canvas))
+ || (x1 >= x2) || (y1 >= y2))
+ {
+ return;
+ }
- bbox.x = x1;
- bbox.y = y1;
- bbox.width = x2 - x1;
- bbox.height = y2 - y1;
+ bbox.x = x1;
+ bbox.y = y1;
+ bbox.width = x2 - x1;
+ bbox.height = y2 - y1;
- gdk_window_invalidate_rect (gtk_layout_get_bin_window (GTK_LAYOUT (canvas)),
- &bbox, FALSE);
+ gdk_window_invalidate_rect (gtk_layout_get_bin_window (GTK_LAYOUT (canvas)),
+ &bbox, FALSE);
}
/**
@@ -3283,18 +3842,26 @@ eel_canvas_request_redraw (EelCanvas *canvas, int x1, int y1, int x2, int y2)
* Converts world coordinates into canvas pixel coordinates.
**/
void
-eel_canvas_w2c (EelCanvas *canvas, double wx, double wy, int *cx, int *cy)
+eel_canvas_w2c (EelCanvas *canvas,
+ double wx,
+ double wy,
+ int *cx,
+ int *cy)
{
- double zoom;
+ double zoom;
+
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
+
+ zoom = canvas->pixels_per_unit;
- g_return_if_fail (EEL_IS_CANVAS (canvas));
-
- zoom = canvas->pixels_per_unit;
-
- if (cx)
- *cx = floor ((wx - canvas->scroll_x1)*zoom + canvas->zoom_xofs + 0.5);
- if (cy)
- *cy = floor ((wy - canvas->scroll_y1)*zoom + canvas->zoom_yofs + 0.5);
+ if (cx)
+ {
+ *cx = floor ((wx - canvas->scroll_x1) * zoom + canvas->zoom_xofs + 0.5);
+ }
+ if (cy)
+ {
+ *cy = floor ((wy - canvas->scroll_y1) * zoom + canvas->zoom_yofs + 0.5);
+ }
}
/**
@@ -3307,15 +3874,17 @@ eel_canvas_w2c (EelCanvas *canvas, double wx, double wy, int *cx, int *cy)
**/
void
eel_canvas_w2c_rect_d (EelCanvas *canvas,
- double *x1, double *y1,
- double *x2, double *y2)
+ double *x1,
+ double *y1,
+ double *x2,
+ double *y2)
{
- eel_canvas_w2c_d (canvas,
- *x1, *y1,
- x1, y1);
- eel_canvas_w2c_d (canvas,
- *x2, *y2,
- x2, y2);
+ eel_canvas_w2c_d (canvas,
+ *x1, *y1,
+ x1, y1);
+ eel_canvas_w2c_d (canvas,
+ *x2, *y2,
+ x2, y2);
}
@@ -3332,18 +3901,26 @@ eel_canvas_w2c_rect_d (EelCanvas *canvas,
* produces coordinates in floating point coordinates, for greater precision.
**/
void
-eel_canvas_w2c_d (EelCanvas *canvas, double wx, double wy, double *cx, double *cy)
+eel_canvas_w2c_d (EelCanvas *canvas,
+ double wx,
+ double wy,
+ double *cx,
+ double *cy)
{
- double zoom;
+ double zoom;
- g_return_if_fail (EEL_IS_CANVAS (canvas));
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- zoom = canvas->pixels_per_unit;
-
- if (cx)
- *cx = (wx - canvas->scroll_x1)*zoom + canvas->zoom_xofs;
- if (cy)
- *cy = (wy - canvas->scroll_y1)*zoom + canvas->zoom_yofs;
+ zoom = canvas->pixels_per_unit;
+
+ if (cx)
+ {
+ *cx = (wx - canvas->scroll_x1) * zoom + canvas->zoom_xofs;
+ }
+ if (cy)
+ {
+ *cy = (wy - canvas->scroll_y1) * zoom + canvas->zoom_yofs;
+ }
}
@@ -3358,18 +3935,26 @@ eel_canvas_w2c_d (EelCanvas *canvas, double wx, double wy, double *cx, double *c
* Converts canvas pixel coordinates to world coordinates.
**/
void
-eel_canvas_c2w (EelCanvas *canvas, int cx, int cy, double *wx, double *wy)
+eel_canvas_c2w (EelCanvas *canvas,
+ int cx,
+ int cy,
+ double *wx,
+ double *wy)
{
- double zoom;
+ double zoom;
+
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- g_return_if_fail (EEL_IS_CANVAS (canvas));
+ zoom = canvas->pixels_per_unit;
- zoom = canvas->pixels_per_unit;
-
- if (wx)
- *wx = (cx - canvas->zoom_xofs)/zoom + canvas->scroll_x1;
- if (wy)
- *wy = (cy - canvas->zoom_yofs)/zoom + canvas->scroll_y1;
+ if (wx)
+ {
+ *wx = (cx - canvas->zoom_xofs) / zoom + canvas->scroll_x1;
+ }
+ if (wy)
+ {
+ *wy = (cy - canvas->zoom_yofs) / zoom + canvas->scroll_y1;
+ }
}
@@ -3388,18 +3973,25 @@ eel_canvas_c2w (EelCanvas *canvas, int cx, int cy, double *wx, double *wy)
* function is here for backwards compatibility reasons.
**/
void
-eel_canvas_window_to_world (EelCanvas *canvas, double winx, double winy,
- double *worldx, double *worldy)
+eel_canvas_window_to_world (EelCanvas *canvas,
+ double winx,
+ double winy,
+ double *worldx,
+ double *worldy)
{
- g_return_if_fail (EEL_IS_CANVAS (canvas));
-
- if (worldx)
- *worldx = canvas->scroll_x1 + ((winx - canvas->zoom_xofs)
- / canvas->pixels_per_unit);
-
- if (worldy)
- *worldy = canvas->scroll_y1 + ((winy - canvas->zoom_yofs)
- / canvas->pixels_per_unit);
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
+
+ if (worldx)
+ {
+ *worldx = canvas->scroll_x1 + ((winx - canvas->zoom_xofs)
+ / canvas->pixels_per_unit);
+ }
+
+ if (worldy)
+ {
+ *worldy = canvas->scroll_y1 + ((winy - canvas->zoom_yofs)
+ / canvas->pixels_per_unit);
+ }
}
@@ -3416,361 +4008,391 @@ eel_canvas_window_to_world (EelCanvas *canvas, double winx, double winy,
* function is here for backwards compatibility reasons.
**/
void
-eel_canvas_world_to_window (EelCanvas *canvas, double worldx, double worldy,
- double *winx, double *winy)
+eel_canvas_world_to_window (EelCanvas *canvas,
+ double worldx,
+ double worldy,
+ double *winx,
+ double *winy)
{
- g_return_if_fail (EEL_IS_CANVAS (canvas));
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- if (winx)
- *winx = (canvas->pixels_per_unit)*(worldx - canvas->scroll_x1) + canvas->zoom_xofs;
+ if (winx)
+ {
+ *winx = (canvas->pixels_per_unit) * (worldx - canvas->scroll_x1) + canvas->zoom_xofs;
+ }
- if (winy)
- *winy = (canvas->pixels_per_unit)*(worldy - canvas->scroll_y1) + canvas->zoom_yofs;
+ if (winy)
+ {
+ *winy = (canvas->pixels_per_unit) * (worldy - canvas->scroll_y1) + canvas->zoom_yofs;
+ }
}
static gboolean
boolean_handled_accumulator (GSignalInvocationHint *ihint,
- GValue *return_accu,
- const GValue *handler_return,
- gpointer dummy)
+ GValue *return_accu,
+ const GValue *handler_return,
+ gpointer dummy)
{
- gboolean continue_emission;
- gboolean signal_handled;
-
- signal_handled = g_value_get_boolean (handler_return);
- g_value_set_boolean (return_accu, signal_handled);
- continue_emission = !signal_handled;
-
- return continue_emission;
+ gboolean continue_emission;
+ gboolean signal_handled;
+
+ signal_handled = g_value_get_boolean (handler_return);
+ g_value_set_boolean (return_accu, signal_handled);
+ continue_emission = !signal_handled;
+
+ return continue_emission;
}
static void
eel_canvas_item_accessible_get_item_extents (EelCanvasItem *item,
GdkRectangle *rect)
{
- double bx1, bx2, by1, by2;
- gint scroll_x, scroll_y;
- gint x1, x2, y1, y2;
-
- eel_canvas_item_get_bounds (item, &bx1, &by1, &bx2, &by2);
- eel_canvas_w2c_rect_d (item->canvas, &bx1, &by1, &bx2, &by2);
- eel_canvas_get_scroll_offsets (item->canvas, &scroll_x, &scroll_y);
- x1 = floor (bx1 + .5);
- y1 = floor (by1 + .5);
- x2 = floor (bx2 + .5);
- y2 = floor (by2 + .5);
- rect->x = x1 - scroll_x;
- rect->y = y1 - scroll_y;
- rect->width = x2 - x1;
- rect->height = y2 - y1;
+ double bx1, bx2, by1, by2;
+ gint scroll_x, scroll_y;
+ gint x1, x2, y1, y2;
+
+ eel_canvas_item_get_bounds (item, &bx1, &by1, &bx2, &by2);
+ eel_canvas_w2c_rect_d (item->canvas, &bx1, &by1, &bx2, &by2);
+ eel_canvas_get_scroll_offsets (item->canvas, &scroll_x, &scroll_y);
+ x1 = floor (bx1 + .5);
+ y1 = floor (by1 + .5);
+ x2 = floor (bx2 + .5);
+ y2 = floor (by2 + .5);
+ rect->x = x1 - scroll_x;
+ rect->y = y1 - scroll_y;
+ rect->width = x2 - x1;
+ rect->height = y2 - y1;
}
static gboolean
eel_canvas_item_accessible_is_item_in_window (EelCanvasItem *item,
GdkRectangle *rect)
{
- GtkWidget *widget;
- gboolean retval;
-
- widget = GTK_WIDGET (item->canvas);
- if (gtk_widget_get_window (widget)) {
- int window_width, window_height;
-
- gdk_window_get_geometry (gtk_widget_get_window (widget), NULL, NULL,
- &window_width, &window_height);
- /*
- * Check whether rectangles intersect
- */
- if (rect->x + rect->width < 0 ||
- rect->y + rect->height < 0 ||
- rect->x > window_width ||
- rect->y > window_height) {
- retval = FALSE;
- } else {
- retval = TRUE;
- }
- } else {
- retval = FALSE;
- }
- return retval;
+ GtkWidget *widget;
+ gboolean retval;
+
+ widget = GTK_WIDGET (item->canvas);
+ if (gtk_widget_get_window (widget))
+ {
+ int window_width, window_height;
+
+ gdk_window_get_geometry (gtk_widget_get_window (widget), NULL, NULL,
+ &window_width, &window_height);
+ /*
+ * Check whether rectangles intersect
+ */
+ if (rect->x + rect->width < 0 ||
+ rect->y + rect->height < 0 ||
+ rect->x > window_width ||
+ rect->y > window_height)
+ {
+ retval = FALSE;
+ }
+ else
+ {
+ retval = TRUE;
+ }
+ }
+ else
+ {
+ retval = FALSE;
+ }
+ return retval;
}
static void
eel_canvas_item_accessible_get_extents (AtkComponent *component,
- gint *x,
- gint *y,
- gint *width,
- gint *height,
- AtkCoordType coord_type)
-{
- AtkGObjectAccessible *atk_gobj;
- GObject *obj;
- EelCanvasItem *item;
- gint window_x, window_y;
- gint toplevel_x, toplevel_y;
- GdkRectangle rect;
- GdkWindow *window;
- GtkWidget *canvas;
-
- atk_gobj = ATK_GOBJECT_ACCESSIBLE (component);
- obj = atk_gobject_accessible_get_object (atk_gobj);
-
- if (obj == NULL) {
- /* item is defunct */
- return;
- }
-
- /* Get the CanvasItem */
- item = EEL_CANVAS_ITEM (obj);
-
- /* If this item has no parent canvas, something's broken */
- g_return_if_fail (GTK_IS_WIDGET (item->canvas));
-
- eel_canvas_item_accessible_get_item_extents (item, &rect);
- *width = rect.width;
- *height = rect.height;
- if (!eel_canvas_item_accessible_is_item_in_window (item, &rect)) {
- *x = G_MININT;
- *y = G_MININT;
- return;
- }
-
- canvas = GTK_WIDGET (item->canvas);
- window = gtk_widget_get_parent_window (canvas);
- gdk_window_get_origin (window, &window_x, &window_y);
- *x = rect.x + window_x;
- *y = rect.y + window_y;
- if (coord_type == ATK_XY_WINDOW) {
- window = gdk_window_get_toplevel (gtk_widget_get_window (canvas));
- gdk_window_get_origin (window, &toplevel_x, &toplevel_y);
- *x -= toplevel_x;
- *y -= toplevel_y;
- }
+ gint *x,
+ gint *y,
+ gint *width,
+ gint *height,
+ AtkCoordType coord_type)
+{
+ AtkGObjectAccessible *atk_gobj;
+ GObject *obj;
+ EelCanvasItem *item;
+ gint window_x, window_y;
+ gint toplevel_x, toplevel_y;
+ GdkRectangle rect;
+ GdkWindow *window;
+ GtkWidget *canvas;
+
+ atk_gobj = ATK_GOBJECT_ACCESSIBLE (component);
+ obj = atk_gobject_accessible_get_object (atk_gobj);
+
+ if (obj == NULL)
+ {
+ /* item is defunct */
+ return;
+ }
+
+ /* Get the CanvasItem */
+ item = EEL_CANVAS_ITEM (obj);
+
+ /* If this item has no parent canvas, something's broken */
+ g_return_if_fail (GTK_IS_WIDGET (item->canvas));
+
+ eel_canvas_item_accessible_get_item_extents (item, &rect);
+ *width = rect.width;
+ *height = rect.height;
+ if (!eel_canvas_item_accessible_is_item_in_window (item, &rect))
+ {
+ *x = G_MININT;
+ *y = G_MININT;
return;
+ }
+
+ canvas = GTK_WIDGET (item->canvas);
+ window = gtk_widget_get_parent_window (canvas);
+ gdk_window_get_origin (window, &window_x, &window_y);
+ *x = rect.x + window_x;
+ *y = rect.y + window_y;
+ if (coord_type == ATK_XY_WINDOW)
+ {
+ window = gdk_window_get_toplevel (gtk_widget_get_window (canvas));
+ gdk_window_get_origin (window, &toplevel_x, &toplevel_y);
+ *x -= toplevel_x;
+ *y -= toplevel_y;
+ }
+ return;
}
static gint
eel_canvas_item_accessible_get_mdi_zorder (AtkComponent *component)
{
- AtkGObjectAccessible *atk_gobj;
- GObject *g_obj;
- EelCanvasItem *item;
-
- atk_gobj = ATK_GOBJECT_ACCESSIBLE (component);
- g_obj = atk_gobject_accessible_get_object (atk_gobj);
- if (g_obj == NULL) {
- /* Object is defunct */
- return -1;
- }
-
- item = EEL_CANVAS_ITEM (g_obj);
- if (item->parent) {
- return g_list_index (EEL_CANVAS_GROUP (item->parent)->item_list, item);
- } else {
- g_return_val_if_fail (item->canvas->root == item, -1);
- return 0;
- }
+ AtkGObjectAccessible *atk_gobj;
+ GObject *g_obj;
+ EelCanvasItem *item;
+
+ atk_gobj = ATK_GOBJECT_ACCESSIBLE (component);
+ g_obj = atk_gobject_accessible_get_object (atk_gobj);
+ if (g_obj == NULL)
+ {
+ /* Object is defunct */
+ return -1;
+ }
+
+ item = EEL_CANVAS_ITEM (g_obj);
+ if (item->parent)
+ {
+ return g_list_index (EEL_CANVAS_GROUP (item->parent)->item_list, item);
+ }
+ else
+ {
+ g_return_val_if_fail (item->canvas->root == item, -1);
+ return 0;
+ }
}
static gboolean
eel_canvas_item_accessible_grab_focus (AtkComponent *component)
{
- AtkGObjectAccessible *atk_gobj;
- GObject *obj;
- EelCanvasItem *item;
- GtkWidget *toplevel;
-
- atk_gobj = ATK_GOBJECT_ACCESSIBLE (component);
- obj = atk_gobject_accessible_get_object (atk_gobj);
-
- item = EEL_CANVAS_ITEM (obj);
- if (item == NULL) {
- /* item is defunct */
- return FALSE;
- }
-
- eel_canvas_item_grab_focus (item);
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->canvas));
- if (gtk_widget_is_toplevel (toplevel)) {
- gtk_window_present (GTK_WINDOW (toplevel));
- }
-
- return TRUE;
+ AtkGObjectAccessible *atk_gobj;
+ GObject *obj;
+ EelCanvasItem *item;
+ GtkWidget *toplevel;
+
+ atk_gobj = ATK_GOBJECT_ACCESSIBLE (component);
+ obj = atk_gobject_accessible_get_object (atk_gobj);
+
+ item = EEL_CANVAS_ITEM (obj);
+ if (item == NULL)
+ {
+ /* item is defunct */
+ return FALSE;
+ }
+
+ eel_canvas_item_grab_focus (item);
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->canvas));
+ if (gtk_widget_is_toplevel (toplevel))
+ {
+ gtk_window_present (GTK_WINDOW (toplevel));
+ }
+
+ return TRUE;
}
static void
eel_canvas_item_accessible_component_interface_init (AtkComponentIface *iface)
{
- g_return_if_fail (iface != NULL);
+ g_return_if_fail (iface != NULL);
- iface->get_extents = eel_canvas_item_accessible_get_extents;
- iface->get_mdi_zorder = eel_canvas_item_accessible_get_mdi_zorder;
- iface->grab_focus = eel_canvas_item_accessible_grab_focus;
+ iface->get_extents = eel_canvas_item_accessible_get_extents;
+ iface->get_mdi_zorder = eel_canvas_item_accessible_get_mdi_zorder;
+ iface->grab_focus = eel_canvas_item_accessible_grab_focus;
}
static gboolean
eel_canvas_item_accessible_is_item_on_screen (EelCanvasItem *item)
{
- GdkRectangle rect;
+ GdkRectangle rect;
- eel_canvas_item_accessible_get_item_extents (item, &rect);
- return eel_canvas_item_accessible_is_item_in_window (item, &rect);
+ eel_canvas_item_accessible_get_item_extents (item, &rect);
+ return eel_canvas_item_accessible_is_item_in_window (item, &rect);
}
static void
-eel_canvas_item_accessible_initialize (AtkObject *obj, gpointer data)
+eel_canvas_item_accessible_initialize (AtkObject *obj,
+ gpointer data)
{
- if (ATK_OBJECT_CLASS (accessible_item_parent_class)->initialize != NULL)
- ATK_OBJECT_CLASS (accessible_item_parent_class)->initialize (obj, data);
- g_object_set_data (G_OBJECT (obj), "atk-component-layer",
- GINT_TO_POINTER (ATK_LAYER_MDI));
+ if (ATK_OBJECT_CLASS (accessible_item_parent_class)->initialize != NULL)
+ {
+ ATK_OBJECT_CLASS (accessible_item_parent_class)->initialize (obj, data);
+ }
+ g_object_set_data (G_OBJECT (obj), "atk-component-layer",
+ GINT_TO_POINTER (ATK_LAYER_MDI));
}
-static AtkStateSet*
+static AtkStateSet *
eel_canvas_item_accessible_ref_state_set (AtkObject *accessible)
{
- AtkGObjectAccessible *atk_gobj;
- GObject *obj;
- EelCanvasItem *item;
- AtkStateSet *state_set;
-
- state_set = ATK_OBJECT_CLASS (accessible_item_parent_class)->ref_state_set (accessible);
- atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible);
- obj = atk_gobject_accessible_get_object (atk_gobj);
-
- item = EEL_CANVAS_ITEM (obj);
- if (item == NULL) {
- atk_state_set_add_state (state_set, ATK_STATE_DEFUNCT);
- } else {
- if (item->flags & EEL_CANVAS_ITEM_VISIBLE) {
- atk_state_set_add_state (state_set, ATK_STATE_VISIBLE);
-
- if (eel_canvas_item_accessible_is_item_on_screen (item)) {
- atk_state_set_add_state (state_set, ATK_STATE_SHOWING);
- }
- }
- if (gtk_widget_get_can_focus (GTK_WIDGET (item->canvas))) {
- atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE);
-
- if (item->canvas->focused_item == item) {
- atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
- }
- }
- }
-
- return state_set;
+ AtkGObjectAccessible *atk_gobj;
+ GObject *obj;
+ EelCanvasItem *item;
+ AtkStateSet *state_set;
+
+ state_set = ATK_OBJECT_CLASS (accessible_item_parent_class)->ref_state_set (accessible);
+ atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible);
+ obj = atk_gobject_accessible_get_object (atk_gobj);
+
+ item = EEL_CANVAS_ITEM (obj);
+ if (item == NULL)
+ {
+ atk_state_set_add_state (state_set, ATK_STATE_DEFUNCT);
+ }
+ else
+ {
+ if (item->flags & EEL_CANVAS_ITEM_VISIBLE)
+ {
+ atk_state_set_add_state (state_set, ATK_STATE_VISIBLE);
+
+ if (eel_canvas_item_accessible_is_item_on_screen (item))
+ {
+ atk_state_set_add_state (state_set, ATK_STATE_SHOWING);
+ }
+ }
+ if (gtk_widget_get_can_focus (GTK_WIDGET (item->canvas)))
+ {
+ atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE);
+
+ if (item->canvas->focused_item == item)
+ {
+ atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
+ }
+ }
+ }
+
+ return state_set;
}
static void
eel_canvas_item_accessible_class_init (EelCanvasItemAccessibleClass *klass)
{
- AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
+ AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
- accessible_item_parent_class = g_type_class_peek_parent (klass);
+ accessible_item_parent_class = g_type_class_peek_parent (klass);
- atk_class->initialize = eel_canvas_item_accessible_initialize;
- atk_class->ref_state_set = eel_canvas_item_accessible_ref_state_set;
+ atk_class->initialize = eel_canvas_item_accessible_initialize;
+ atk_class->ref_state_set = eel_canvas_item_accessible_ref_state_set;
}
static void
eel_canvas_item_accessible_init (EelCanvasItemAccessible *self)
{
-
}
G_DEFINE_TYPE_WITH_CODE (EelCanvasItemAccessible,
- eel_canvas_item_accessible,
- ATK_TYPE_GOBJECT_ACCESSIBLE,
- G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT,
- eel_canvas_item_accessible_component_interface_init));
+ eel_canvas_item_accessible,
+ ATK_TYPE_GOBJECT_ACCESSIBLE,
+ G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT,
+ eel_canvas_item_accessible_component_interface_init));
static GType eel_canvas_item_accessible_factory_get_type (void);
-typedef AtkObjectFactory EelCanvasItemAccessibleFactory;
+typedef AtkObjectFactory EelCanvasItemAccessibleFactory;
typedef AtkObjectFactoryClass EelCanvasItemAccessibleFactoryClass;
G_DEFINE_TYPE (EelCanvasItemAccessibleFactory, eel_canvas_item_accessible_factory,
- ATK_TYPE_OBJECT_FACTORY)
+ ATK_TYPE_OBJECT_FACTORY)
static GType
eel_canvas_item_accessible_factory_get_accessible_type (void)
{
- return eel_canvas_item_accessible_get_type ();
+ return eel_canvas_item_accessible_get_type ();
}
-static AtkObject*
+static AtkObject *
eel_canvas_item_accessible_factory_create_accessible (GObject *for_object)
{
- AtkObject *accessible;
+ AtkObject *accessible;
- accessible = g_object_new (eel_canvas_item_accessible_get_type (), NULL);
- atk_object_initialize (accessible, for_object);
- return accessible;
+ accessible = g_object_new (eel_canvas_item_accessible_get_type (), NULL);
+ atk_object_initialize (accessible, for_object);
+ return accessible;
}
static void
eel_canvas_item_accessible_factory_init (EelCanvasItemAccessibleFactory *self)
{
-
}
static void
eel_canvas_item_accessible_factory_class_init (AtkObjectFactoryClass *klass)
{
- klass->create_accessible = eel_canvas_item_accessible_factory_create_accessible;
- klass->get_accessible_type = eel_canvas_item_accessible_factory_get_accessible_type;
+ klass->create_accessible = eel_canvas_item_accessible_factory_create_accessible;
+ klass->get_accessible_type = eel_canvas_item_accessible_factory_get_accessible_type;
}
/* Class initialization function for EelCanvasItemClass */
static void
eel_canvas_item_class_init (EelCanvasItemClass *klass)
{
- GObjectClass *gobject_class = (GObjectClass *) klass;
-
- item_parent_class = g_type_class_peek_parent (klass);
-
- gobject_class->set_property = eel_canvas_item_set_property;
- gobject_class->get_property = eel_canvas_item_get_property;
- gobject_class->dispose = eel_canvas_item_dispose;
-
- g_object_class_install_property
- (gobject_class, ITEM_PROP_PARENT,
- g_param_spec_object ("parent", NULL, NULL,
- EEL_TYPE_CANVAS_ITEM,
- G_PARAM_READWRITE));
-
- g_object_class_install_property
- (gobject_class, ITEM_PROP_VISIBLE,
- g_param_spec_boolean ("visible", NULL, NULL,
- TRUE,
- G_PARAM_READWRITE));
-
- item_signals[ITEM_EVENT] =
- g_signal_new ("event",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (EelCanvasItemClass, event),
- boolean_handled_accumulator, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_BOOLEAN, 1,
- GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
-
- item_signals[ITEM_DESTROY] =
- g_signal_new ("destroy",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- G_STRUCT_OFFSET (EelCanvasItemClass, destroy),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- klass->realize = eel_canvas_item_realize;
- klass->unrealize = eel_canvas_item_unrealize;
- klass->map = eel_canvas_item_map;
- klass->unmap = eel_canvas_item_unmap;
- klass->update = eel_canvas_item_update;
-
- atk_registry_set_factory_type (atk_get_default_registry (),
- EEL_TYPE_CANVAS_ITEM,
- eel_canvas_item_accessible_factory_get_type ());
+ GObjectClass *gobject_class = (GObjectClass *) klass;
+
+ item_parent_class = g_type_class_peek_parent (klass);
+
+ gobject_class->set_property = eel_canvas_item_set_property;
+ gobject_class->get_property = eel_canvas_item_get_property;
+ gobject_class->dispose = eel_canvas_item_dispose;
+
+ g_object_class_install_property
+ (gobject_class, ITEM_PROP_PARENT,
+ g_param_spec_object ("parent", NULL, NULL,
+ EEL_TYPE_CANVAS_ITEM,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property
+ (gobject_class, ITEM_PROP_VISIBLE,
+ g_param_spec_boolean ("visible", NULL, NULL,
+ TRUE,
+ G_PARAM_READWRITE));
+
+ item_signals[ITEM_EVENT] =
+ g_signal_new ("event",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EelCanvasItemClass, event),
+ boolean_handled_accumulator, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_BOOLEAN, 1,
+ GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+
+ item_signals[ITEM_DESTROY] =
+ g_signal_new ("destroy",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
+ G_STRUCT_OFFSET (EelCanvasItemClass, destroy),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ klass->realize = eel_canvas_item_realize;
+ klass->unrealize = eel_canvas_item_unrealize;
+ klass->map = eel_canvas_item_map;
+ klass->unmap = eel_canvas_item_unmap;
+ klass->update = eel_canvas_item_update;
+
+ atk_registry_set_factory_type (atk_get_default_registry (),
+ EEL_TYPE_CANVAS_ITEM,
+ eel_canvas_item_accessible_factory_get_type ());
}
diff --git a/eel/eel-debug.c b/eel/eel-debug.c
index df3f51d78..f3d94ec0f 100644
--- a/eel/eel-debug.c
+++ b/eel/eel-debug.c
@@ -1,23 +1,23 @@
/*
- eel-debug.c: Eel debugging aids.
-
- Copyright (C) 2000, 2001 Eazel, Inc.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with this program; if not, see <http://www.gnu.org/licenses/>.
-
- Author: Darin Adler <darin@eazel.com>
-*/
+ * eel-debug.c: Eel debugging aids.
+ *
+ * Copyright (C) 2000, 2001 Eazel, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Darin Adler <darin@eazel.com>
+ */
#include <config.h>
#include "eel-debug.h"
@@ -26,9 +26,10 @@
#include <signal.h>
#include <stdio.h>
-typedef struct {
- gpointer data;
- GFreeFunc function;
+typedef struct
+{
+ gpointer data;
+ GFreeFunc function;
} ShutdownFunction;
static GList *shutdown_functions;
@@ -40,11 +41,11 @@ static GList *shutdown_functions;
static void
eel_stop_in_debugger (void)
{
- void (* saved_handler) (int);
+ void (*saved_handler) (int);
- saved_handler = signal (SIGINT, SIG_IGN);
- raise (SIGINT);
- signal (SIGINT, saved_handler);
+ saved_handler = signal (SIGINT, SIG_IGN);
+ raise (SIGINT);
+ signal (SIGINT, saved_handler);
}
/* Stop in the debugger after running the default log handler.
@@ -52,50 +53,53 @@ eel_stop_in_debugger (void)
* without making them fatal (you can continue).
*/
static void
-log_handler (const char *domain,
- GLogLevelFlags level,
- const char *message,
- gpointer data)
+log_handler (const char *domain,
+ GLogLevelFlags level,
+ const char *message,
+ gpointer data)
{
- g_log_default_handler (domain, level, message, data);
- if ((level & (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING)) != 0) {
- eel_stop_in_debugger ();
- }
+ g_log_default_handler (domain, level, message, data);
+ if ((level & (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING)) != 0)
+ {
+ eel_stop_in_debugger ();
+ }
}
void
eel_make_warnings_and_criticals_stop_in_debugger (void)
{
- g_log_set_default_handler (log_handler, NULL);
+ g_log_set_default_handler (log_handler, NULL);
}
void
eel_debug_shut_down (void)
{
- ShutdownFunction *f;
+ ShutdownFunction *f;
+
+ while (shutdown_functions != NULL)
+ {
+ f = shutdown_functions->data;
+ shutdown_functions = g_list_remove (shutdown_functions, f);
- while (shutdown_functions != NULL) {
- f = shutdown_functions->data;
- shutdown_functions = g_list_remove (shutdown_functions, f);
-
- f->function (f->data);
- g_free (f);
- }
+ f->function (f->data);
+ g_free (f);
+ }
}
void
eel_debug_call_at_shutdown (EelFunction function)
{
- eel_debug_call_at_shutdown_with_data ((GFreeFunc) function, NULL);
+ eel_debug_call_at_shutdown_with_data ((GFreeFunc) function, NULL);
}
void
-eel_debug_call_at_shutdown_with_data (GFreeFunc function, gpointer data)
+eel_debug_call_at_shutdown_with_data (GFreeFunc function,
+ gpointer data)
{
- ShutdownFunction *f;
+ ShutdownFunction *f;
- f = g_new (ShutdownFunction, 1);
- f->data = data;
- f->function = function;
- shutdown_functions = g_list_prepend (shutdown_functions, f);
+ f = g_new (ShutdownFunction, 1);
+ f->data = data;
+ f->function = function;
+ shutdown_functions = g_list_prepend (shutdown_functions, f);
}
diff --git a/eel/eel-gdk-extensions.c b/eel/eel-gdk-extensions.c
index dc06f9d4c..6642dda4a 100644
--- a/eel/eel-gdk-extensions.c
+++ b/eel/eel-gdk-extensions.c
@@ -1,26 +1,25 @@
-
/* eel-gdk-extensions.c: Graphics routines to augment what's in gdk.
-
- Copyright (C) 1999, 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Darin Adler <darin@eazel.com>,
- Pavel Cisler <pavel@eazel.com>,
- Ramiro Estrugo <ramiro@eazel.com>
-*/
+ *
+ * Copyright (C) 1999, 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Darin Adler <darin@eazel.com>,
+ * Pavel Cisler <pavel@eazel.com>,
+ * Ramiro Estrugo <ramiro@eazel.com>
+ */
#include <config.h>
#include "eel-gdk-extensions.h"
@@ -34,40 +33,49 @@
#include <pango/pango.h>
EelGdkGeometryFlags
-eel_gdk_parse_geometry (const char *string, int *x_return, int *y_return,
- guint *width_return, guint *height_return)
+eel_gdk_parse_geometry (const char *string,
+ int *x_return,
+ int *y_return,
+ guint *width_return,
+ guint *height_return)
{
- int x11_flags;
- EelGdkGeometryFlags gdk_flags;
+ int x11_flags;
+ EelGdkGeometryFlags gdk_flags;
- g_return_val_if_fail (string != NULL, EEL_GDK_NO_VALUE);
- g_return_val_if_fail (x_return != NULL, EEL_GDK_NO_VALUE);
- g_return_val_if_fail (y_return != NULL, EEL_GDK_NO_VALUE);
- g_return_val_if_fail (width_return != NULL, EEL_GDK_NO_VALUE);
- g_return_val_if_fail (height_return != NULL, EEL_GDK_NO_VALUE);
+ g_return_val_if_fail (string != NULL, EEL_GDK_NO_VALUE);
+ g_return_val_if_fail (x_return != NULL, EEL_GDK_NO_VALUE);
+ g_return_val_if_fail (y_return != NULL, EEL_GDK_NO_VALUE);
+ g_return_val_if_fail (width_return != NULL, EEL_GDK_NO_VALUE);
+ g_return_val_if_fail (height_return != NULL, EEL_GDK_NO_VALUE);
- x11_flags = XParseGeometry (string, x_return, y_return,
- width_return, height_return);
+ x11_flags = XParseGeometry (string, x_return, y_return,
+ width_return, height_return);
- gdk_flags = EEL_GDK_NO_VALUE;
- if (x11_flags & XValue) {
- gdk_flags |= EEL_GDK_X_VALUE;
- }
- if (x11_flags & YValue) {
- gdk_flags |= EEL_GDK_Y_VALUE;
- }
- if (x11_flags & WidthValue) {
- gdk_flags |= EEL_GDK_WIDTH_VALUE;
- }
- if (x11_flags & HeightValue) {
- gdk_flags |= EEL_GDK_HEIGHT_VALUE;
- }
- if (x11_flags & XNegative) {
- gdk_flags |= EEL_GDK_X_NEGATIVE;
- }
- if (x11_flags & YNegative) {
- gdk_flags |= EEL_GDK_Y_NEGATIVE;
- }
+ gdk_flags = EEL_GDK_NO_VALUE;
+ if (x11_flags & XValue)
+ {
+ gdk_flags |= EEL_GDK_X_VALUE;
+ }
+ if (x11_flags & YValue)
+ {
+ gdk_flags |= EEL_GDK_Y_VALUE;
+ }
+ if (x11_flags & WidthValue)
+ {
+ gdk_flags |= EEL_GDK_WIDTH_VALUE;
+ }
+ if (x11_flags & HeightValue)
+ {
+ gdk_flags |= EEL_GDK_HEIGHT_VALUE;
+ }
+ if (x11_flags & XNegative)
+ {
+ gdk_flags |= EEL_GDK_X_NEGATIVE;
+ }
+ if (x11_flags & YNegative)
+ {
+ gdk_flags |= EEL_GDK_Y_NEGATIVE;
+ }
- return gdk_flags;
+ return gdk_flags;
}
diff --git a/eel/eel-glib-extensions.c b/eel/eel-glib-extensions.c
index 5564eda08..0a1b22d75 100644
--- a/eel/eel-glib-extensions.c
+++ b/eel/eel-glib-extensions.c
@@ -1,26 +1,25 @@
-
/* eel-glib-extensions.c - implementation of new functions that conceptually
- belong in glib. Perhaps some of these will be
- actually rolled into glib someday.
-
- Copyright (C) 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: John Sullivan <sullivan@eazel.com>
-*/
+ * belong in glib. Perhaps some of these will be
+ * actually rolled into glib someday.
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: John Sullivan <sullivan@eazel.com>
+ */
#include <config.h>
#include "eel-glib-extensions.h"
@@ -33,104 +32,118 @@
#include <stdlib.h>
gboolean
-eel_g_strv_equal (char **a, char **b)
+eel_g_strv_equal (char **a,
+ char **b)
{
- int i;
-
- if (g_strv_length (a) != g_strv_length (b)) {
- return FALSE;
- }
-
- for (i = 0; a[i] != NULL; i++) {
- if (strcmp (a[i], b[i]) != 0) {
- return FALSE;
- }
- }
- return TRUE;
+ int i;
+
+ if (g_strv_length (a) != g_strv_length (b))
+ {
+ return FALSE;
+ }
+
+ for (i = 0; a[i] != NULL; i++)
+ {
+ if (strcmp (a[i], b[i]) != 0)
+ {
+ return FALSE;
+ }
+ }
+ return TRUE;
}
static int
-compare_pointers (gconstpointer pointer_1, gconstpointer pointer_2)
+compare_pointers (gconstpointer pointer_1,
+ gconstpointer pointer_2)
{
- if ((const char *) pointer_1 < (const char *) pointer_2) {
- return -1;
- }
- if ((const char *) pointer_1 > (const char *) pointer_2) {
- return +1;
- }
- return 0;
+ if ((const char *) pointer_1 < (const char *) pointer_2)
+ {
+ return -1;
+ }
+ if ((const char *) pointer_1 > (const char *) pointer_2)
+ {
+ return +1;
+ }
+ return 0;
}
gboolean
eel_g_lists_sort_and_check_for_intersection (GList **list_1,
- GList **list_2)
-
+ GList **list_2)
{
- GList *node_1, *node_2;
- int compare_result;
-
- *list_1 = g_list_sort (*list_1, compare_pointers);
- *list_2 = g_list_sort (*list_2, compare_pointers);
-
- node_1 = *list_1;
- node_2 = *list_2;
-
- while (node_1 != NULL && node_2 != NULL) {
- compare_result = compare_pointers (node_1->data, node_2->data);
- if (compare_result == 0) {
- return TRUE;
- }
- if (compare_result <= 0) {
- node_1 = node_1->next;
- }
- if (compare_result >= 0) {
- node_2 = node_2->next;
- }
- }
-
- return FALSE;
+ GList *node_1, *node_2;
+ int compare_result;
+
+ *list_1 = g_list_sort (*list_1, compare_pointers);
+ *list_2 = g_list_sort (*list_2, compare_pointers);
+
+ node_1 = *list_1;
+ node_2 = *list_2;
+
+ while (node_1 != NULL && node_2 != NULL)
+ {
+ compare_result = compare_pointers (node_1->data, node_2->data);
+ if (compare_result == 0)
+ {
+ return TRUE;
+ }
+ if (compare_result <= 0)
+ {
+ node_1 = node_1->next;
+ }
+ if (compare_result >= 0)
+ {
+ node_2 = node_2->next;
+ }
+ }
+
+ return FALSE;
}
-typedef struct {
- GList *keys;
- GList *values;
+typedef struct
+{
+ GList *keys;
+ GList *values;
} FlattenedHashTable;
static void
-flatten_hash_table_element (gpointer key, gpointer value, gpointer callback_data)
+flatten_hash_table_element (gpointer key,
+ gpointer value,
+ gpointer callback_data)
{
- FlattenedHashTable *flattened_table;
+ FlattenedHashTable *flattened_table;
- flattened_table = callback_data;
- flattened_table->keys = g_list_prepend
- (flattened_table->keys, key);
- flattened_table->values = g_list_prepend
- (flattened_table->values, value);
+ flattened_table = callback_data;
+ flattened_table->keys = g_list_prepend
+ (flattened_table->keys, key);
+ flattened_table->values = g_list_prepend
+ (flattened_table->values, value);
}
void
eel_g_hash_table_safe_for_each (GHashTable *hash_table,
- GHFunc callback,
- gpointer callback_data)
+ GHFunc callback,
+ gpointer callback_data)
{
- FlattenedHashTable flattened;
- GList *p, *q;
+ FlattenedHashTable flattened;
+ GList *p, *q;
- flattened.keys = NULL;
- flattened.values = NULL;
+ flattened.keys = NULL;
+ flattened.values = NULL;
- g_hash_table_foreach (hash_table,
- flatten_hash_table_element,
- &flattened);
+ g_hash_table_foreach (hash_table,
+ flatten_hash_table_element,
+ &flattened);
- for (p = flattened.keys, q = flattened.values;
- p != NULL;
- p = p->next, q = q->next) {
- (* callback) (p->data, q->data, callback_data);
- }
+ for (p = flattened.keys, q = flattened.values;
+ p != NULL;
+ p = p->next, q = q->next)
+ {
+ (*callback)(p->data, q->data, callback_data);
+ }
- g_list_free (flattened.keys);
- g_list_free (flattened.values);
+ g_list_free (flattened.keys);
+ g_list_free (flattened.values);
}
#if !defined (EEL_OMIT_SELF_CHECK)
diff --git a/eel/eel-gnome-extensions.c b/eel/eel-gnome-extensions.c
index fe5efef9a..65de96180 100644
--- a/eel/eel-gnome-extensions.c
+++ b/eel/eel-gnome-extensions.c
@@ -1,26 +1,25 @@
-
/* eel-gnome-extensions.c - implementation of new functions that operate on
- gnome classes. Perhaps some of these should be
- rolled into gnome someday.
-
- Copyright (C) 1999, 2000, 2001 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Darin Adler <darin@eazel.com>
-*/
+ * gnome classes. Perhaps some of these should be
+ * rolled into gnome someday.
+ *
+ * Copyright (C) 1999, 2000, 2001 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Darin Adler <darin@eazel.com>
+ */
#include <config.h>
@@ -34,29 +33,31 @@
void
eel_gnome_open_terminal_on_screen (const char *command,
- GdkScreen *screen)
+ GdkScreen *screen)
{
- GAppInfo *app;
- GdkAppLaunchContext *ctx;
- GError *error = NULL;
- GdkDisplay *display;
+ GAppInfo *app;
+ GdkAppLaunchContext *ctx;
+ GError *error = NULL;
+ GdkDisplay *display;
- app = g_app_info_create_from_commandline (command, NULL, G_APP_INFO_CREATE_NEEDS_TERMINAL, &error);
+ app = g_app_info_create_from_commandline (command, NULL, G_APP_INFO_CREATE_NEEDS_TERMINAL, &error);
- if (app != NULL && screen != NULL) {
- display = gdk_screen_get_display (screen);
- ctx = gdk_display_get_app_launch_context (display);
- gdk_app_launch_context_set_screen (ctx, screen);
+ if (app != NULL && screen != NULL)
+ {
+ display = gdk_screen_get_display (screen);
+ ctx = gdk_display_get_app_launch_context (display);
+ gdk_app_launch_context_set_screen (ctx, screen);
- g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), &error);
+ g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), &error);
- g_object_unref (app);
- g_object_unref (ctx);
- }
+ g_object_unref (app);
+ g_object_unref (ctx);
+ }
- if (error != NULL) {
- g_message ("Could not start application on terminal: %s", error->message);
+ if (error != NULL)
+ {
+ g_message ("Could not start application on terminal: %s", error->message);
- g_error_free (error);
- }
+ g_error_free (error);
+ }
}
diff --git a/eel/eel-graphic-effects.c b/eel/eel-graphic-effects.c
index 820435ab7..b3fdc5bdb 100644
--- a/eel/eel-graphic-effects.c
+++ b/eel/eel-graphic-effects.c
@@ -1,4 +1,3 @@
-
/* Eel - pixbuf manipulation routines for graphical effects.
*
* Copyright (C) 2000 Eazel, Inc
@@ -20,7 +19,7 @@
*/
/* This file contains pixbuf manipulation routines used for graphical effects like pre-lighting
- and selection hilighting */
+ * and selection hilighting */
#include <config.h>
@@ -35,17 +34,17 @@
static GdkPixbuf *
create_new_pixbuf (GdkPixbuf *src)
{
- g_assert (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB);
- g_assert ((!gdk_pixbuf_get_has_alpha (src)
- && gdk_pixbuf_get_n_channels (src) == 3)
- || (gdk_pixbuf_get_has_alpha (src)
- && gdk_pixbuf_get_n_channels (src) == 4));
-
- return gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
- gdk_pixbuf_get_has_alpha (src),
- gdk_pixbuf_get_bits_per_sample (src),
- gdk_pixbuf_get_width (src),
- gdk_pixbuf_get_height (src));
+ g_assert (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB);
+ g_assert ((!gdk_pixbuf_get_has_alpha (src)
+ && gdk_pixbuf_get_n_channels (src) == 3)
+ || (gdk_pixbuf_get_has_alpha (src)
+ && gdk_pixbuf_get_n_channels (src) == 4));
+
+ return gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
+ gdk_pixbuf_get_has_alpha (src),
+ gdk_pixbuf_get_bits_per_sample (src),
+ gdk_pixbuf_get_width (src),
+ gdk_pixbuf_get_height (src));
}
/* utility routine to bump the level of a color component with pinning */
@@ -53,102 +52,109 @@ create_new_pixbuf (GdkPixbuf *src)
static guchar
lighten_component (guchar cur_value)
{
- int new_value = cur_value;
- new_value += 24 + (new_value >> 3);
- if (new_value > 255) {
- new_value = 255;
- }
- return (guchar) new_value;
+ int new_value = cur_value;
+ new_value += 24 + (new_value >> 3);
+ if (new_value > 255)
+ {
+ new_value = 255;
+ }
+ return (guchar) new_value;
}
GdkPixbuf *
-eel_create_spotlight_pixbuf (GdkPixbuf* src)
+eel_create_spotlight_pixbuf (GdkPixbuf *src)
{
- GdkPixbuf *dest;
- int i, j;
- int width, height, has_alpha, src_row_stride, dst_row_stride;
- guchar *target_pixels, *original_pixels;
- guchar *pixsrc, *pixdest;
-
- g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL);
- g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src)
- && gdk_pixbuf_get_n_channels (src) == 3)
- || (gdk_pixbuf_get_has_alpha (src)
- && gdk_pixbuf_get_n_channels (src) == 4), NULL);
- g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL);
-
- dest = create_new_pixbuf (src);
-
- has_alpha = gdk_pixbuf_get_has_alpha (src);
- width = gdk_pixbuf_get_width (src);
- height = gdk_pixbuf_get_height (src);
- dst_row_stride = gdk_pixbuf_get_rowstride (dest);
- src_row_stride = gdk_pixbuf_get_rowstride (src);
- target_pixels = gdk_pixbuf_get_pixels (dest);
- original_pixels = gdk_pixbuf_get_pixels (src);
-
- for (i = 0; i < height; i++) {
- pixdest = target_pixels + i * dst_row_stride;
- pixsrc = original_pixels + i * src_row_stride;
- for (j = 0; j < width; j++) {
- *pixdest++ = lighten_component (*pixsrc++);
- *pixdest++ = lighten_component (*pixsrc++);
- *pixdest++ = lighten_component (*pixsrc++);
- if (has_alpha) {
- *pixdest++ = *pixsrc++;
- }
- }
- }
- return dest;
+ GdkPixbuf *dest;
+ int i, j;
+ int width, height, has_alpha, src_row_stride, dst_row_stride;
+ guchar *target_pixels, *original_pixels;
+ guchar *pixsrc, *pixdest;
+
+ g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL);
+ g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src)
+ && gdk_pixbuf_get_n_channels (src) == 3)
+ || (gdk_pixbuf_get_has_alpha (src)
+ && gdk_pixbuf_get_n_channels (src) == 4), NULL);
+ g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL);
+
+ dest = create_new_pixbuf (src);
+
+ has_alpha = gdk_pixbuf_get_has_alpha (src);
+ width = gdk_pixbuf_get_width (src);
+ height = gdk_pixbuf_get_height (src);
+ dst_row_stride = gdk_pixbuf_get_rowstride (dest);
+ src_row_stride = gdk_pixbuf_get_rowstride (src);
+ target_pixels = gdk_pixbuf_get_pixels (dest);
+ original_pixels = gdk_pixbuf_get_pixels (src);
+
+ for (i = 0; i < height; i++)
+ {
+ pixdest = target_pixels + i * dst_row_stride;
+ pixsrc = original_pixels + i * src_row_stride;
+ for (j = 0; j < width; j++)
+ {
+ *pixdest++ = lighten_component (*pixsrc++);
+ *pixdest++ = lighten_component (*pixsrc++);
+ *pixdest++ = lighten_component (*pixsrc++);
+ if (has_alpha)
+ {
+ *pixdest++ = *pixsrc++;
+ }
+ }
+ }
+ return dest;
}
/* this routine colorizes the passed-in pixbuf by multiplying each pixel with the passed in color */
GdkPixbuf *
eel_create_colorized_pixbuf (GdkPixbuf *src,
- GdkRGBA *color)
+ GdkRGBA *color)
{
- int i, j;
- int width, height, has_alpha, src_row_stride, dst_row_stride;
- guchar *target_pixels;
- guchar *original_pixels;
- guchar *pixsrc;
- guchar *pixdest;
- GdkPixbuf *dest;
- gint red_value, green_value, blue_value;
-
- g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL);
- g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src)
- && gdk_pixbuf_get_n_channels (src) == 3)
- || (gdk_pixbuf_get_has_alpha (src)
- && gdk_pixbuf_get_n_channels (src) == 4), NULL);
- g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL);
-
- red_value = (gint) floor (color->red * 255);
- green_value = (gint) floor (color->green * 255);
- blue_value = (gint) floor (color->blue * 255);
-
- dest = create_new_pixbuf (src);
-
- has_alpha = gdk_pixbuf_get_has_alpha (src);
- width = gdk_pixbuf_get_width (src);
- height = gdk_pixbuf_get_height (src);
- src_row_stride = gdk_pixbuf_get_rowstride (src);
- dst_row_stride = gdk_pixbuf_get_rowstride (dest);
- target_pixels = gdk_pixbuf_get_pixels (dest);
- original_pixels = gdk_pixbuf_get_pixels (src);
-
- for (i = 0; i < height; i++) {
- pixdest = target_pixels + i*dst_row_stride;
- pixsrc = original_pixels + i*src_row_stride;
- for (j = 0; j < width; j++) {
- *pixdest++ = (*pixsrc++ * red_value) >> 8;
- *pixdest++ = (*pixsrc++ * green_value) >> 8;
- *pixdest++ = (*pixsrc++ * blue_value) >> 8;
- if (has_alpha) {
- *pixdest++ = *pixsrc++;
- }
- }
- }
- return dest;
+ int i, j;
+ int width, height, has_alpha, src_row_stride, dst_row_stride;
+ guchar *target_pixels;
+ guchar *original_pixels;
+ guchar *pixsrc;
+ guchar *pixdest;
+ GdkPixbuf *dest;
+ gint red_value, green_value, blue_value;
+
+ g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL);
+ g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src)
+ && gdk_pixbuf_get_n_channels (src) == 3)
+ || (gdk_pixbuf_get_has_alpha (src)
+ && gdk_pixbuf_get_n_channels (src) == 4), NULL);
+ g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL);
+
+ red_value = (gint) floor (color->red * 255);
+ green_value = (gint) floor (color->green * 255);
+ blue_value = (gint) floor (color->blue * 255);
+
+ dest = create_new_pixbuf (src);
+
+ has_alpha = gdk_pixbuf_get_has_alpha (src);
+ width = gdk_pixbuf_get_width (src);
+ height = gdk_pixbuf_get_height (src);
+ src_row_stride = gdk_pixbuf_get_rowstride (src);
+ dst_row_stride = gdk_pixbuf_get_rowstride (dest);
+ target_pixels = gdk_pixbuf_get_pixels (dest);
+ original_pixels = gdk_pixbuf_get_pixels (src);
+
+ for (i = 0; i < height; i++)
+ {
+ pixdest = target_pixels + i * dst_row_stride;
+ pixsrc = original_pixels + i * src_row_stride;
+ for (j = 0; j < width; j++)
+ {
+ *pixdest++ = (*pixsrc++ *red_value) >> 8;
+ *pixdest++ = (*pixsrc++ *green_value) >> 8;
+ *pixdest++ = (*pixsrc++ *blue_value) >> 8;
+ if (has_alpha)
+ {
+ *pixdest++ = *pixsrc++;
+ }
+ }
+ }
+ return dest;
}
diff --git a/eel/eel-gtk-extensions.c b/eel/eel-gtk-extensions.c
index d694ad4f1..8b9a0d909 100644
--- a/eel/eel-gtk-extensions.c
+++ b/eel/eel-gtk-extensions.c
@@ -1,28 +1,27 @@
-
/* eel-gtk-extensions.c - implementation of new functions that operate on
- gtk classes. Perhaps some of these should be
- rolled into gtk someday.
-
- Copyright (C) 1999, 2000, 2001 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: John Sullivan <sullivan@eazel.com>
- Ramiro Estrugo <ramiro@eazel.com>
- Darin Adler <darin@eazel.com>
-*/
+ * gtk classes. Perhaps some of these should be
+ * rolled into gtk someday.
+ *
+ * Copyright (C) 1999, 2000, 2001 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: John Sullivan <sullivan@eazel.com>
+ * Ramiro Estrugo <ramiro@eazel.com>
+ * Darin Adler <darin@eazel.com>
+ */
#include <config.h>
#include "eel-gtk-extensions.h"
@@ -43,93 +42,95 @@
/* This number is fairly arbitrary. Long enough to show a pretty long
* menu title, but not so long to make a menu grotesquely wide.
*/
-#define MAXIMUM_MENU_TITLE_LENGTH 48
+#define MAXIMUM_MENU_TITLE_LENGTH 48
/* Used for window position & size sanity-checking. The sizes are big enough to prevent
- * at least normal-sized gnome panels from obscuring the window at the screen edges.
+ * at least normal-sized gnome panels from obscuring the window at the screen edges.
*/
-#define MINIMUM_ON_SCREEN_WIDTH 100
-#define MINIMUM_ON_SCREEN_HEIGHT 100
+#define MINIMUM_ON_SCREEN_WIDTH 100
+#define MINIMUM_ON_SCREEN_HEIGHT 100
/**
* eel_gtk_window_get_geometry_string:
* @window: a #GtkWindow
- *
+ *
* Obtains the geometry string for this window, suitable for
* set_geometry_string(); assumes the window has NorthWest gravity
- *
+ *
* Return value: geometry string, must be freed
**/
-char*
+char *
eel_gtk_window_get_geometry_string (GtkWindow *window)
{
- char *str;
- int w, h, x, y;
-
- g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
- g_return_val_if_fail (gtk_window_get_gravity (window) ==
- GDK_GRAVITY_NORTH_WEST, NULL);
-
- gtk_window_get_position (window, &x, &y);
- gtk_window_get_size (window, &w, &h);
-
- str = g_strdup_printf ("%dx%d+%d+%d", w, h, x, y);
-
- return str;
+ char *str;
+ int w, h, x, y;
+
+ g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
+ g_return_val_if_fail (gtk_window_get_gravity (window) ==
+ GDK_GRAVITY_NORTH_WEST, NULL);
+
+ gtk_window_get_position (window, &x, &y);
+ gtk_window_get_size (window, &w, &h);
+
+ str = g_strdup_printf ("%dx%d+%d+%d", w, h, x, y);
+
+ return str;
}
static void
-sanity_check_window_position (int *left, int *top)
+sanity_check_window_position (int *left,
+ int *top)
{
- g_assert (left != NULL);
- g_assert (top != NULL);
-
- /* Make sure the top of the window is on screen, for
- * draggability (might not be necessary with all window managers,
- * but seems reasonable anyway). Make sure the top of the window
- * isn't off the bottom of the screen, or so close to the bottom
- * that it might be obscured by the panel.
- */
- *top = CLAMP (*top, 0, gdk_screen_height() - MINIMUM_ON_SCREEN_HEIGHT);
-
- /* FIXME bugzilla.eazel.com 669:
- * If window has negative left coordinate, set_uposition sends it
- * somewhere else entirely. Not sure what level contains this bug (XWindows?).
- * Hacked around by pinning the left edge to zero, which just means you
- * can't set a window to be partly off the left of the screen using
- * this routine.
- */
- /* Make sure the left edge of the window isn't off the right edge of
- * the screen, or so close to the right edge that it might be
- * obscured by the panel.
- */
- *left = CLAMP (*left, 0, gdk_screen_width() - MINIMUM_ON_SCREEN_WIDTH);
+ g_assert (left != NULL);
+ g_assert (top != NULL);
+
+ /* Make sure the top of the window is on screen, for
+ * draggability (might not be necessary with all window managers,
+ * but seems reasonable anyway). Make sure the top of the window
+ * isn't off the bottom of the screen, or so close to the bottom
+ * that it might be obscured by the panel.
+ */
+ *top = CLAMP (*top, 0, gdk_screen_height () - MINIMUM_ON_SCREEN_HEIGHT);
+
+ /* FIXME bugzilla.eazel.com 669:
+ * If window has negative left coordinate, set_uposition sends it
+ * somewhere else entirely. Not sure what level contains this bug (XWindows?).
+ * Hacked around by pinning the left edge to zero, which just means you
+ * can't set a window to be partly off the left of the screen using
+ * this routine.
+ */
+ /* Make sure the left edge of the window isn't off the right edge of
+ * the screen, or so close to the right edge that it might be
+ * obscured by the panel.
+ */
+ *left = CLAMP (*left, 0, gdk_screen_width () - MINIMUM_ON_SCREEN_WIDTH);
}
static void
-sanity_check_window_dimensions (guint *width, guint *height)
+sanity_check_window_dimensions (guint *width,
+ guint *height)
{
- g_assert (width != NULL);
- g_assert (height != NULL);
-
- /* Pin the size of the window to the screen, so we don't end up in
- * a state where the window is so big essential parts of it can't
- * be reached (might not be necessary with all window managers,
- * but seems reasonable anyway).
- */
- *width = MIN (*width, gdk_screen_width());
- *height = MIN (*height, gdk_screen_height());
+ g_assert (width != NULL);
+ g_assert (height != NULL);
+
+ /* Pin the size of the window to the screen, so we don't end up in
+ * a state where the window is so big essential parts of it can't
+ * be reached (might not be necessary with all window managers,
+ * but seems reasonable anyway).
+ */
+ *width = MIN (*width, gdk_screen_width ());
+ *height = MIN (*height, gdk_screen_height ());
}
/**
* eel_gtk_window_set_initial_geometry:
- *
+ *
* Sets the position and size of a GtkWindow before the
* GtkWindow is shown. It is an error to call this on a window that
* is already on-screen. Takes into account screen size, and does
* some sanity-checking on the passed-in values.
- *
+ *
* @window: A non-visible GtkWindow
* @geometry_flags: A EelGdkGeometryFlags value defining which of
* the following parameters have defined values
@@ -139,65 +140,69 @@ sanity_check_window_dimensions (guint *width, guint *height)
* @height: height of window in pixels
*/
static void
-eel_gtk_window_set_initial_geometry (GtkWindow *window,
- EelGdkGeometryFlags geometry_flags,
- int left,
- int top,
- guint width,
- guint height)
+eel_gtk_window_set_initial_geometry (GtkWindow *window,
+ EelGdkGeometryFlags geometry_flags,
+ int left,
+ int top,
+ guint width,
+ guint height)
{
- GdkScreen *screen;
- int real_left, real_top;
- int screen_width, screen_height;
-
- g_return_if_fail (GTK_IS_WINDOW (window));
-
- /* Setting the default size doesn't work when the window is already showing.
- * Someday we could make this move an already-showing window, but we don't
- * need that functionality yet.
- */
- g_return_if_fail (!gtk_widget_get_visible (GTK_WIDGET (window)));
-
- if ((geometry_flags & EEL_GDK_X_VALUE) && (geometry_flags & EEL_GDK_Y_VALUE)) {
- real_left = left;
- real_top = top;
-
- screen = gtk_window_get_screen (window);
- screen_width = gdk_screen_get_width (screen);
- screen_height = gdk_screen_get_height (screen);
-
- /* This is sub-optimal. GDK doesn't allow us to set win_gravity
- * to South/East types, which should be done if using negative
- * positions (so that the right or bottom edge of the window
- * appears at the specified position, not the left or top).
- * However it does seem to be consistent with other GNOME apps.
- */
- if (geometry_flags & EEL_GDK_X_NEGATIVE) {
- real_left = screen_width - real_left;
- }
- if (geometry_flags & EEL_GDK_Y_NEGATIVE) {
- real_top = screen_height - real_top;
- }
-
- sanity_check_window_position (&real_left, &real_top);
- gtk_window_move (window, real_left, real_top);
- }
-
- if ((geometry_flags & EEL_GDK_WIDTH_VALUE) && (geometry_flags & EEL_GDK_HEIGHT_VALUE)) {
- sanity_check_window_dimensions (&width, &height);
- gtk_window_set_default_size (GTK_WINDOW (window), (int)width, (int)height);
- }
+ GdkScreen *screen;
+ int real_left, real_top;
+ int screen_width, screen_height;
+
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
+ /* Setting the default size doesn't work when the window is already showing.
+ * Someday we could make this move an already-showing window, but we don't
+ * need that functionality yet.
+ */
+ g_return_if_fail (!gtk_widget_get_visible (GTK_WIDGET (window)));
+
+ if ((geometry_flags & EEL_GDK_X_VALUE) && (geometry_flags & EEL_GDK_Y_VALUE))
+ {
+ real_left = left;
+ real_top = top;
+
+ screen = gtk_window_get_screen (window);
+ screen_width = gdk_screen_get_width (screen);
+ screen_height = gdk_screen_get_height (screen);
+
+ /* This is sub-optimal. GDK doesn't allow us to set win_gravity
+ * to South/East types, which should be done if using negative
+ * positions (so that the right or bottom edge of the window
+ * appears at the specified position, not the left or top).
+ * However it does seem to be consistent with other GNOME apps.
+ */
+ if (geometry_flags & EEL_GDK_X_NEGATIVE)
+ {
+ real_left = screen_width - real_left;
+ }
+ if (geometry_flags & EEL_GDK_Y_NEGATIVE)
+ {
+ real_top = screen_height - real_top;
+ }
+
+ sanity_check_window_position (&real_left, &real_top);
+ gtk_window_move (window, real_left, real_top);
+ }
+
+ if ((geometry_flags & EEL_GDK_WIDTH_VALUE) && (geometry_flags & EEL_GDK_HEIGHT_VALUE))
+ {
+ sanity_check_window_dimensions (&width, &height);
+ gtk_window_set_default_size (GTK_WINDOW (window), (int) width, (int) height);
+ }
}
/**
* eel_gtk_window_set_initial_geometry_from_string:
- *
+ *
* Sets the position and size of a GtkWindow before the
- * GtkWindow is shown. The geometry is passed in as a string.
+ * GtkWindow is shown. The geometry is passed in as a string.
* It is an error to call this on a window that
* is already on-screen. Takes into account screen size, and does
* some sanity-checking on the passed-in values.
- *
+ *
* @window: A non-visible GtkWindow
* @geometry_string: A string suitable for use with eel_gdk_parse_geometry
* @minimum_width: If the width from the string is smaller than this,
@@ -207,55 +212,58 @@ eel_gtk_window_set_initial_geometry (GtkWindow *window,
* @ignore_position: If true position data from string will be ignored.
*/
void
-eel_gtk_window_set_initial_geometry_from_string (GtkWindow *window,
- const char *geometry_string,
- guint minimum_width,
- guint minimum_height,
- gboolean ignore_position)
+eel_gtk_window_set_initial_geometry_from_string (GtkWindow *window,
+ const char *geometry_string,
+ guint minimum_width,
+ guint minimum_height,
+ gboolean ignore_position)
{
- int left, top;
- guint width, height;
- EelGdkGeometryFlags geometry_flags;
-
- g_return_if_fail (GTK_IS_WINDOW (window));
- g_return_if_fail (geometry_string != NULL);
-
- /* Setting the default size doesn't work when the window is already showing.
- * Someday we could make this move an already-showing window, but we don't
- * need that functionality yet.
- */
- g_return_if_fail (!gtk_widget_get_visible (GTK_WIDGET (window)));
-
- geometry_flags = eel_gdk_parse_geometry (geometry_string, &left, &top, &width, &height);
-
- /* Make sure the window isn't smaller than makes sense for this window.
- * Other sanity checks are performed in set_initial_geometry.
- */
- if (geometry_flags & EEL_GDK_WIDTH_VALUE) {
- width = MAX (width, minimum_width);
- }
- if (geometry_flags & EEL_GDK_HEIGHT_VALUE) {
- height = MAX (height, minimum_height);
- }
-
- /* Ignore saved window position if requested. */
- if (ignore_position) {
- geometry_flags &= ~(EEL_GDK_X_VALUE | EEL_GDK_Y_VALUE);
- }
-
- eel_gtk_window_set_initial_geometry (window, geometry_flags, left, top, width, height);
+ int left, top;
+ guint width, height;
+ EelGdkGeometryFlags geometry_flags;
+
+ g_return_if_fail (GTK_IS_WINDOW (window));
+ g_return_if_fail (geometry_string != NULL);
+
+ /* Setting the default size doesn't work when the window is already showing.
+ * Someday we could make this move an already-showing window, but we don't
+ * need that functionality yet.
+ */
+ g_return_if_fail (!gtk_widget_get_visible (GTK_WIDGET (window)));
+
+ geometry_flags = eel_gdk_parse_geometry (geometry_string, &left, &top, &width, &height);
+
+ /* Make sure the window isn't smaller than makes sense for this window.
+ * Other sanity checks are performed in set_initial_geometry.
+ */
+ if (geometry_flags & EEL_GDK_WIDTH_VALUE)
+ {
+ width = MAX (width, minimum_width);
+ }
+ if (geometry_flags & EEL_GDK_HEIGHT_VALUE)
+ {
+ height = MAX (height, minimum_height);
+ }
+
+ /* Ignore saved window position if requested. */
+ if (ignore_position)
+ {
+ geometry_flags &= ~(EEL_GDK_X_VALUE | EEL_GDK_Y_VALUE);
+ }
+
+ eel_gtk_window_set_initial_geometry (window, geometry_flags, left, top, width, height);
}
/**
* eel_pop_up_context_menu:
- *
+ *
* Pop up a context menu under the mouse.
- * The menu is sunk after use, so it will be destroyed unless the
+ * The menu is sunk after use, so it will be destroyed unless the
* caller first ref'ed it.
- *
+ *
* This function is more of a helper function than a gtk extension,
* so perhaps it belongs in a different file.
- *
+ *
* @menu: The menu to pop up under the mouse.
* @offset_x: Ignored.
* @offset_y: Ignored.
@@ -263,76 +271,80 @@ eel_gtk_window_set_initial_geometry_from_string (GtkWindow *window,
* is no event available. This is used to get the timestamp for the menu's popup.
* In case no event is provided, gtk_get_current_event_time() will be used automatically.
**/
-void
-eel_pop_up_context_menu (GtkMenu *menu,
- GdkEventButton *event)
+void
+eel_pop_up_context_menu (GtkMenu *menu,
+ GdkEventButton *event)
{
- int button;
-
- g_return_if_fail (GTK_IS_MENU (menu));
-
- /* The event button needs to be 0 if we're popping up this menu from
- * a button release, else a 2nd click outside the menu with any button
- * other than the one that invoked the menu will be ignored (instead
- * of dismissing the menu). This is a subtle fragility of the GTK menu code.
- */
-
- if (event) {
- button = event->type == GDK_BUTTON_RELEASE
- ? 0
- : event->button;
- } else {
- button = 0;
- }
-
- gtk_menu_popup (menu, /* menu */
- NULL, /* parent_menu_shell */
- NULL, /* parent_menu_item */
- NULL, /* popup_position_func */
- NULL, /* popup_position_data */
- button, /* button */
- event ? event->time : gtk_get_current_event_time ()); /* activate_time */
-
- g_object_ref_sink (menu);
- g_object_unref (menu);
+ int button;
+
+ g_return_if_fail (GTK_IS_MENU (menu));
+
+ /* The event button needs to be 0 if we're popping up this menu from
+ * a button release, else a 2nd click outside the menu with any button
+ * other than the one that invoked the menu will be ignored (instead
+ * of dismissing the menu). This is a subtle fragility of the GTK menu code.
+ */
+
+ if (event)
+ {
+ button = event->type == GDK_BUTTON_RELEASE
+ ? 0
+ : event->button;
+ }
+ else
+ {
+ button = 0;
+ }
+
+ gtk_menu_popup (menu, /* menu */
+ NULL, /* parent_menu_shell */
+ NULL, /* parent_menu_item */
+ NULL, /* popup_position_func */
+ NULL, /* popup_position_data */
+ button, /* button */
+ event ? event->time : gtk_get_current_event_time ()); /* activate_time */
+
+ g_object_ref_sink (menu);
+ g_object_unref (menu);
}
GtkMenuItem *
eel_gtk_menu_append_separator (GtkMenu *menu)
{
- return eel_gtk_menu_insert_separator (menu, -1);
+ return eel_gtk_menu_insert_separator (menu, -1);
}
GtkMenuItem *
-eel_gtk_menu_insert_separator (GtkMenu *menu, int index)
+eel_gtk_menu_insert_separator (GtkMenu *menu,
+ int index)
{
- GtkWidget *menu_item;
+ GtkWidget *menu_item;
- menu_item = gtk_separator_menu_item_new ();
- gtk_widget_show (menu_item);
- gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menu_item, index);
+ menu_item = gtk_separator_menu_item_new ();
+ gtk_widget_show (menu_item);
+ gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menu_item, index);
- return GTK_MENU_ITEM (menu_item);
+ return GTK_MENU_ITEM (menu_item);
}
void
eel_gtk_message_dialog_set_details_label (GtkMessageDialog *dialog,
- const gchar *details_text)
+ const gchar *details_text)
{
- GtkWidget *content_area, *expander, *label;
+ GtkWidget *content_area, *expander, *label;
- content_area = gtk_message_dialog_get_message_area (dialog);
- expander = gtk_expander_new_with_mnemonic (_("Show more _details"));
- gtk_expander_set_spacing (GTK_EXPANDER (expander), 6);
+ content_area = gtk_message_dialog_get_message_area (dialog);
+ expander = gtk_expander_new_with_mnemonic (_("Show more _details"));
+ gtk_expander_set_spacing (GTK_EXPANDER (expander), 6);
- label = gtk_label_new (details_text);
- gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
- gtk_label_set_selectable (GTK_LABEL (label), TRUE);
- gtk_label_set_xalign (GTK_LABEL (label), 0);
+ label = gtk_label_new (details_text);
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_label_set_selectable (GTK_LABEL (label), TRUE);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_container_add (GTK_CONTAINER (expander), label);
- gtk_box_pack_start (GTK_BOX (content_area), expander, FALSE, FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (expander), label);
+ gtk_box_pack_start (GTK_BOX (content_area), expander, FALSE, FALSE, 0);
- gtk_widget_show (label);
- gtk_widget_show (expander);
+ gtk_widget_show (label);
+ gtk_widget_show (expander);
}
diff --git a/eel/eel-lib-self-check-functions.c b/eel/eel-lib-self-check-functions.c
index 2c180e8ae..af1dddfa9 100644
--- a/eel/eel-lib-self-check-functions.c
+++ b/eel/eel-lib-self-check-functions.c
@@ -1,35 +1,35 @@
/*
- eel-lib-self-check-functions.c: Wrapper for all self check functions
- in Eel proper.
-
- Copyright (C) 2000 Eazel, Inc.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with this program; if not, see <http://www.gnu.org/licenses/>.
-
- Author: Darin Adler <darin@eazel.com>
-*/
+ * eel-lib-self-check-functions.c: Wrapper for all self check functions
+ * in Eel proper.
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Darin Adler <darin@eazel.com>
+ */
#include <config.h>
-#if ! defined (EEL_OMIT_SELF_CHECK)
+#if !defined (EEL_OMIT_SELF_CHECK)
#include "eel-lib-self-check-functions.h"
void
eel_run_lib_self_checks (void)
{
- EEL_LIB_FOR_EACH_SELF_CHECK_FUNCTION (EEL_CALL_SELF_CHECK_FUNCTION)
+ EEL_LIB_FOR_EACH_SELF_CHECK_FUNCTION (EEL_CALL_SELF_CHECK_FUNCTION)
}
#endif /* ! EEL_OMIT_SELF_CHECK */
diff --git a/eel/eel-self-checks.c b/eel/eel-self-checks.c
index 8de01a421..0ed94f265 100644
--- a/eel/eel-self-checks.c
+++ b/eel/eel-self-checks.c
@@ -1,27 +1,27 @@
/*
- eel-self-checks.c: The self-check framework.
-
- Copyright (C) 1999 Eazel, Inc.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with this program; if not, see <http://www.gnu.org/licenses/>.
-
- Author: Darin Adler <darin@eazel.com>
-*/
+ * eel-self-checks.c: The self-check framework.
+ *
+ * Copyright (C) 1999 Eazel, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Darin Adler <darin@eazel.com>
+ */
#include <config.h>
-#if ! defined (EEL_OMIT_SELF_CHECK)
+#if !defined (EEL_OMIT_SELF_CHECK)
#include "eel-self-checks.h"
@@ -38,142 +38,161 @@ static int current_line_number;
void
eel_exit_if_self_checks_failed (void)
{
- if (!failed) {
- return;
- }
+ if (!failed)
+ {
+ return;
+ }
- printf ("\n");
+ printf ("\n");
- exit (EXIT_FAILURE);
+ exit (EXIT_FAILURE);
}
void
-eel_report_check_failure (char *result, char *expected)
+eel_report_check_failure (char *result,
+ char *expected)
{
- if (!failed) {
- fprintf (stderr, "\n");
- }
-
- fprintf (stderr, "FAIL: check failed in %s, line %d\n", current_file_name, current_line_number);
- fprintf (stderr, " evaluated: %s\n", current_expression);
- fprintf (stderr, " expected: %s\n", expected == NULL ? "NULL" : expected);
- fprintf (stderr, " got: %s\n", result == NULL ? "NULL" : result);
-
- failed = TRUE;
-
- g_free (result);
- g_free (expected);
+ if (!failed)
+ {
+ fprintf (stderr, "\n");
+ }
+
+ fprintf (stderr, "FAIL: check failed in %s, line %d\n", current_file_name, current_line_number);
+ fprintf (stderr, " evaluated: %s\n", current_expression);
+ fprintf (stderr, " expected: %s\n", expected == NULL ? "NULL" : expected);
+ fprintf (stderr, " got: %s\n", result == NULL ? "NULL" : result);
+
+ failed = TRUE;
+
+ g_free (result);
+ g_free (expected);
}
static char *
eel_strdup_boolean (gboolean boolean)
{
- if (boolean == FALSE) {
- return g_strdup ("FALSE");
- }
- if (boolean == TRUE) {
- return g_strdup ("TRUE");
- }
- return g_strdup_printf ("gboolean(%d)", boolean);
+ if (boolean == FALSE)
+ {
+ return g_strdup ("FALSE");
+ }
+ if (boolean == TRUE)
+ {
+ return g_strdup ("TRUE");
+ }
+ return g_strdup_printf ("gboolean(%d)", boolean);
}
void
eel_before_check (const char *expression,
- const char *file_name,
- int line_number)
+ const char *file_name,
+ int line_number)
{
- current_expression = expression;
- current_file_name = file_name;
- current_line_number = line_number;
+ current_expression = expression;
+ current_file_name = file_name;
+ current_line_number = line_number;
}
void
eel_after_check (void)
{
- /* It would be good to check here if there was a memory leak. */
+ /* It would be good to check here if there was a memory leak. */
}
void
-eel_check_boolean_result (gboolean result, gboolean expected)
+eel_check_boolean_result (gboolean result,
+ gboolean expected)
{
- if (result != expected) {
- eel_report_check_failure (eel_strdup_boolean (result),
- eel_strdup_boolean (expected));
- }
- eel_after_check ();
+ if (result != expected)
+ {
+ eel_report_check_failure (eel_strdup_boolean (result),
+ eel_strdup_boolean (expected));
+ }
+ eel_after_check ();
}
void
eel_check_rectangle_result (EelIRect result,
- int expected_x0,
- int expected_y0,
- int expected_x1,
- int expected_y1)
+ int expected_x0,
+ int expected_y0,
+ int expected_x1,
+ int expected_y1)
{
- if (result.x0 != expected_x0
- || result.y0 != expected_y0
- || result.x1 != expected_x1
- || result.y1 != expected_y1) {
- eel_report_check_failure (g_strdup_printf ("x0=%d, y0=%d, x1=%d, y1=%d",
- result.x0,
- result.y0,
- result.x1,
- result.y1),
- g_strdup_printf ("x0=%d, y0=%d, x1=%d, y1=%d",
- expected_x0,
- expected_y0,
- expected_x1,
- expected_y1));
- }
- eel_after_check ();
+ if (result.x0 != expected_x0
+ || result.y0 != expected_y0
+ || result.x1 != expected_x1
+ || result.y1 != expected_y1)
+ {
+ eel_report_check_failure (g_strdup_printf ("x0=%d, y0=%d, x1=%d, y1=%d",
+ result.x0,
+ result.y0,
+ result.x1,
+ result.y1),
+ g_strdup_printf ("x0=%d, y0=%d, x1=%d, y1=%d",
+ expected_x0,
+ expected_y0,
+ expected_x1,
+ expected_y1));
+ }
+ eel_after_check ();
}
void
-eel_check_integer_result (long result, long expected)
+eel_check_integer_result (long result,
+ long expected)
{
- if (result != expected) {
- eel_report_check_failure (g_strdup_printf ("%ld", result),
- g_strdup_printf ("%ld", expected));
- }
- eel_after_check ();
+ if (result != expected)
+ {
+ eel_report_check_failure (g_strdup_printf ("%ld", result),
+ g_strdup_printf ("%ld", expected));
+ }
+ eel_after_check ();
}
void
-eel_check_double_result (double result, double expected)
+eel_check_double_result (double result,
+ double expected)
{
- if (result != expected) {
- eel_report_check_failure (g_strdup_printf ("%f", result),
- g_strdup_printf ("%f", expected));
- }
- eel_after_check ();
+ if (result != expected)
+ {
+ eel_report_check_failure (g_strdup_printf ("%f", result),
+ g_strdup_printf ("%f", expected));
+ }
+ eel_after_check ();
}
void
-eel_check_string_result (char *result, const char *expected)
+eel_check_string_result (char *result,
+ const char *expected)
{
- gboolean match;
-
- /* Stricter than eel_strcmp.
- * NULL does not match "" in this test.
- */
- if (expected == NULL) {
- match = result == NULL;
- } else {
- match = result != NULL && strcmp (result, expected) == 0;
- }
-
- if (!match) {
- eel_report_check_failure (result, g_strdup (expected));
- } else {
- g_free (result);
- }
- eel_after_check ();
+ gboolean match;
+
+ /* Stricter than eel_strcmp.
+ * NULL does not match "" in this test.
+ */
+ if (expected == NULL)
+ {
+ match = result == NULL;
+ }
+ else
+ {
+ match = result != NULL && strcmp (result, expected) == 0;
+ }
+
+ if (!match)
+ {
+ eel_report_check_failure (result, g_strdup (expected));
+ }
+ else
+ {
+ g_free (result);
+ }
+ eel_after_check ();
}
void
eel_before_check_function (const char *name)
{
- fprintf (stderr, "running %s\n", name);
+ fprintf (stderr, "running %s\n", name);
}
void
diff --git a/eel/eel-stock-dialogs.c b/eel/eel-stock-dialogs.c
index 2de57672b..499af99d5 100644
--- a/eel/eel-stock-dialogs.c
+++ b/eel/eel-stock-dialogs.c
@@ -1,24 +1,23 @@
-
/* eel-stock-dialogs.c: Various standard dialogs for Eel.
-
- Copyright (C) 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Darin Adler <darin@eazel.com>
-*/
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Darin Adler <darin@eazel.com>
+ */
#include <config.h>
#include "eel-stock-dialogs.h"
@@ -36,429 +35,452 @@
#define RESPONSE_DETAILS 1000
-typedef struct {
- EelCancelCallback cancel_callback;
- gpointer callback_data;
+typedef struct
+{
+ EelCancelCallback cancel_callback;
+ gpointer callback_data;
- /* Parameters for creation of the window. */
- char *wait_message;
- GtkWindow *parent_window;
+ /* Parameters for creation of the window. */
+ char *wait_message;
+ GtkWindow *parent_window;
- /* Timer to determine when we need to create the window. */
- guint timeout_handler_id;
-
- /* Window, once it's created. */
- GtkDialog *dialog;
-
- /* system time (microseconds) when dialog was created */
- gint64 dialog_creation_time;
+ /* Timer to determine when we need to create the window. */
+ guint timeout_handler_id;
+ /* Window, once it's created. */
+ GtkDialog *dialog;
+
+ /* system time (microseconds) when dialog was created */
+ gint64 dialog_creation_time;
} TimedWait;
static GHashTable *timed_wait_hash_table;
-static void timed_wait_dialog_destroy_callback (GtkWidget *object, gpointer callback_data);
+static void timed_wait_dialog_destroy_callback (GtkWidget *object,
+ gpointer callback_data);
static guint
timed_wait_hash (gconstpointer value)
{
- const TimedWait *wait;
+ const TimedWait *wait;
- wait = value;
+ wait = value;
- return GPOINTER_TO_UINT (wait->cancel_callback)
- ^ GPOINTER_TO_UINT (wait->callback_data);
+ return GPOINTER_TO_UINT (wait->cancel_callback)
+ ^ GPOINTER_TO_UINT (wait->callback_data);
}
static gboolean
-timed_wait_hash_equal (gconstpointer value1, gconstpointer value2)
+timed_wait_hash_equal (gconstpointer value1,
+ gconstpointer value2)
{
- const TimedWait *wait1, *wait2;
+ const TimedWait *wait1, *wait2;
- wait1 = value1;
- wait2 = value2;
+ wait1 = value1;
+ wait2 = value2;
- return wait1->cancel_callback == wait2->cancel_callback
- && wait1->callback_data == wait2->callback_data;
+ return wait1->cancel_callback == wait2->cancel_callback
+ && wait1->callback_data == wait2->callback_data;
}
static void
-timed_wait_delayed_close_destroy_dialog_callback (GtkWidget *object, gpointer callback_data)
+timed_wait_delayed_close_destroy_dialog_callback (GtkWidget *object,
+ gpointer callback_data)
{
- g_source_remove (GPOINTER_TO_UINT (callback_data));
+ g_source_remove (GPOINTER_TO_UINT (callback_data));
}
static gboolean
timed_wait_delayed_close_timeout_callback (gpointer callback_data)
{
- guint handler_id;
-
- handler_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (callback_data),
- "eel-stock-dialogs/delayed_close_handler_timeout_id"));
-
- g_signal_handlers_disconnect_by_func (G_OBJECT (callback_data),
- G_CALLBACK (timed_wait_delayed_close_destroy_dialog_callback),
- GUINT_TO_POINTER (handler_id));
-
- gtk_widget_destroy (GTK_WIDGET (callback_data));
-
- return FALSE;
+ guint handler_id;
+
+ handler_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (callback_data),
+ "eel-stock-dialogs/delayed_close_handler_timeout_id"));
+
+ g_signal_handlers_disconnect_by_func (G_OBJECT (callback_data),
+ G_CALLBACK (timed_wait_delayed_close_destroy_dialog_callback),
+ GUINT_TO_POINTER (handler_id));
+
+ gtk_widget_destroy (GTK_WIDGET (callback_data));
+
+ return FALSE;
}
static void
timed_wait_free (TimedWait *wait)
{
- guint delayed_close_handler_id;
- guint64 time_up;
-
- g_assert (g_hash_table_lookup (timed_wait_hash_table, wait) != NULL);
-
- g_hash_table_remove (timed_wait_hash_table, wait);
-
- g_free (wait->wait_message);
- if (wait->parent_window != NULL) {
- g_object_unref (wait->parent_window);
- }
- if (wait->timeout_handler_id != 0) {
- g_source_remove (wait->timeout_handler_id);
- }
- if (wait->dialog != NULL) {
- /* Make sure to detach from the "destroy" signal, or we'll
- * double-free.
- */
- g_signal_handlers_disconnect_by_func (G_OBJECT (wait->dialog),
- G_CALLBACK (timed_wait_dialog_destroy_callback),
- wait);
-
- /* compute time up in milliseconds */
- time_up = (g_get_monotonic_time () - wait->dialog_creation_time) / 1000;
-
- if (time_up < TIMED_WAIT_MIN_TIME_UP) {
- delayed_close_handler_id = g_timeout_add (TIMED_WAIT_MIN_TIME_UP - time_up,
- timed_wait_delayed_close_timeout_callback,
- wait->dialog);
- g_object_set_data (G_OBJECT (wait->dialog),
- "eel-stock-dialogs/delayed_close_handler_timeout_id",
- GUINT_TO_POINTER (delayed_close_handler_id));
- g_signal_connect (wait->dialog, "destroy",
- G_CALLBACK (timed_wait_delayed_close_destroy_dialog_callback),
- GUINT_TO_POINTER (delayed_close_handler_id));
- } else {
- gtk_widget_destroy (GTK_WIDGET (wait->dialog));
- }
- }
-
- /* And the wait object itself. */
- g_free (wait);
+ guint delayed_close_handler_id;
+ guint64 time_up;
+
+ g_assert (g_hash_table_lookup (timed_wait_hash_table, wait) != NULL);
+
+ g_hash_table_remove (timed_wait_hash_table, wait);
+
+ g_free (wait->wait_message);
+ if (wait->parent_window != NULL)
+ {
+ g_object_unref (wait->parent_window);
+ }
+ if (wait->timeout_handler_id != 0)
+ {
+ g_source_remove (wait->timeout_handler_id);
+ }
+ if (wait->dialog != NULL)
+ {
+ /* Make sure to detach from the "destroy" signal, or we'll
+ * double-free.
+ */
+ g_signal_handlers_disconnect_by_func (G_OBJECT (wait->dialog),
+ G_CALLBACK (timed_wait_dialog_destroy_callback),
+ wait);
+
+ /* compute time up in milliseconds */
+ time_up = (g_get_monotonic_time () - wait->dialog_creation_time) / 1000;
+
+ if (time_up < TIMED_WAIT_MIN_TIME_UP)
+ {
+ delayed_close_handler_id = g_timeout_add (TIMED_WAIT_MIN_TIME_UP - time_up,
+ timed_wait_delayed_close_timeout_callback,
+ wait->dialog);
+ g_object_set_data (G_OBJECT (wait->dialog),
+ "eel-stock-dialogs/delayed_close_handler_timeout_id",
+ GUINT_TO_POINTER (delayed_close_handler_id));
+ g_signal_connect (wait->dialog, "destroy",
+ G_CALLBACK (timed_wait_delayed_close_destroy_dialog_callback),
+ GUINT_TO_POINTER (delayed_close_handler_id));
+ }
+ else
+ {
+ gtk_widget_destroy (GTK_WIDGET (wait->dialog));
+ }
+ }
+
+ /* And the wait object itself. */
+ g_free (wait);
}
static void
-timed_wait_dialog_destroy_callback (GtkWidget *object, gpointer callback_data)
+timed_wait_dialog_destroy_callback (GtkWidget *object,
+ gpointer callback_data)
{
- TimedWait *wait;
+ TimedWait *wait;
- wait = callback_data;
+ wait = callback_data;
- g_assert (GTK_DIALOG (object) == wait->dialog);
+ g_assert (GTK_DIALOG (object) == wait->dialog);
- wait->dialog = NULL;
-
- /* When there's no cancel_callback, the originator will/must
- * call eel_timed_wait_stop which will call timed_wait_free.
- */
+ wait->dialog = NULL;
- if (wait->cancel_callback != NULL) {
- (* wait->cancel_callback) (wait->callback_data);
- timed_wait_free (wait);
- }
+ /* When there's no cancel_callback, the originator will/must
+ * call eel_timed_wait_stop which will call timed_wait_free.
+ */
+
+ if (wait->cancel_callback != NULL)
+ {
+ (*wait->cancel_callback)(wait->callback_data);
+ timed_wait_free (wait);
+ }
}
static void
trash_dialog_response_callback (GtkDialog *dialog,
- int response_id,
- TimedWait *wait)
+ int response_id,
+ TimedWait *wait)
{
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
static gboolean
timed_wait_callback (gpointer callback_data)
{
- TimedWait *wait;
- GtkDialog *dialog;
- const char *button;
-
- wait = callback_data;
-
- /* Put up the timed wait window. */
- button = wait->cancel_callback != NULL ? _("_Cancel") : ("_OK");
- dialog = GTK_DIALOG (gtk_message_dialog_new (wait->parent_window,
- 0,
- GTK_MESSAGE_INFO,
- GTK_BUTTONS_NONE,
- NULL));
-
- g_object_set (dialog,
- "text", wait->wait_message,
- "secondary-text", _("You can stop this operation by clicking cancel."),
- NULL);
-
- gtk_dialog_add_button (GTK_DIALOG (dialog), button, GTK_RESPONSE_OK);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
-
- /* The contents are often very small, causing tiny little
- * dialogs with their titles clipped if you just let gtk
- * sizing do its thing. This enforces a minimum width to
- * make it more likely that the title won't be clipped.
- */
- gtk_window_set_default_size (GTK_WINDOW (dialog),
- TIMED_WAIT_MINIMUM_DIALOG_WIDTH,
- -1);
- wait->dialog_creation_time = g_get_monotonic_time ();
- gtk_widget_show (GTK_WIDGET (dialog));
-
- /* FIXME bugzilla.eazel.com 2441:
- * Could parent here, but it's complicated because we
- * don't want this window to go away just because the parent
- * would go away first.
- */
-
- /* Make the dialog cancel the timed wait when it goes away.
- * Connect to "destroy" instead of "response" since we want
- * to be called no matter how the dialog goes away.
- */
- g_signal_connect (dialog, "destroy",
- G_CALLBACK (timed_wait_dialog_destroy_callback),
- wait);
- g_signal_connect (dialog, "response",
- G_CALLBACK (trash_dialog_response_callback),
- wait);
-
- wait->timeout_handler_id = 0;
- wait->dialog = dialog;
-
- return FALSE;
+ TimedWait *wait;
+ GtkDialog *dialog;
+ const char *button;
+
+ wait = callback_data;
+
+ /* Put up the timed wait window. */
+ button = wait->cancel_callback != NULL ? _("_Cancel") : ("_OK");
+ dialog = GTK_DIALOG (gtk_message_dialog_new (wait->parent_window,
+ 0,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_NONE,
+ NULL));
+
+ g_object_set (dialog,
+ "text", wait->wait_message,
+ "secondary-text", _("You can stop this operation by clicking cancel."),
+ NULL);
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog), button, GTK_RESPONSE_OK);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+ /* The contents are often very small, causing tiny little
+ * dialogs with their titles clipped if you just let gtk
+ * sizing do its thing. This enforces a minimum width to
+ * make it more likely that the title won't be clipped.
+ */
+ gtk_window_set_default_size (GTK_WINDOW (dialog),
+ TIMED_WAIT_MINIMUM_DIALOG_WIDTH,
+ -1);
+ wait->dialog_creation_time = g_get_monotonic_time ();
+ gtk_widget_show (GTK_WIDGET (dialog));
+
+ /* FIXME bugzilla.eazel.com 2441:
+ * Could parent here, but it's complicated because we
+ * don't want this window to go away just because the parent
+ * would go away first.
+ */
+
+ /* Make the dialog cancel the timed wait when it goes away.
+ * Connect to "destroy" instead of "response" since we want
+ * to be called no matter how the dialog goes away.
+ */
+ g_signal_connect (dialog, "destroy",
+ G_CALLBACK (timed_wait_dialog_destroy_callback),
+ wait);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (trash_dialog_response_callback),
+ wait);
+
+ wait->timeout_handler_id = 0;
+ wait->dialog = dialog;
+
+ return FALSE;
}
void
-eel_timed_wait_start_with_duration (int duration,
- EelCancelCallback cancel_callback,
- gpointer callback_data,
- const char *wait_message,
- GtkWindow *parent_window)
+eel_timed_wait_start_with_duration (int duration,
+ EelCancelCallback cancel_callback,
+ gpointer callback_data,
+ const char *wait_message,
+ GtkWindow *parent_window)
{
- TimedWait *wait;
-
- g_return_if_fail (callback_data != NULL);
- g_return_if_fail (wait_message != NULL);
- g_return_if_fail (parent_window == NULL || GTK_IS_WINDOW (parent_window));
-
- /* Create the timed wait record. */
- wait = g_new0 (TimedWait, 1);
- wait->wait_message = g_strdup (wait_message);
- wait->cancel_callback = cancel_callback;
- wait->callback_data = callback_data;
- wait->parent_window = parent_window;
-
- if (parent_window != NULL) {
- g_object_ref (parent_window);
- }
-
- /* Start the timer. */
- wait->timeout_handler_id = g_timeout_add (duration, timed_wait_callback, wait);
-
- /* Put in the hash table so we can find it later. */
- if (timed_wait_hash_table == NULL) {
- timed_wait_hash_table = g_hash_table_new (timed_wait_hash, timed_wait_hash_equal);
- }
- g_assert (g_hash_table_lookup (timed_wait_hash_table, wait) == NULL);
- g_hash_table_insert (timed_wait_hash_table, wait, wait);
- g_assert (g_hash_table_lookup (timed_wait_hash_table, wait) == wait);
+ TimedWait *wait;
+
+ g_return_if_fail (callback_data != NULL);
+ g_return_if_fail (wait_message != NULL);
+ g_return_if_fail (parent_window == NULL || GTK_IS_WINDOW (parent_window));
+
+ /* Create the timed wait record. */
+ wait = g_new0 (TimedWait, 1);
+ wait->wait_message = g_strdup (wait_message);
+ wait->cancel_callback = cancel_callback;
+ wait->callback_data = callback_data;
+ wait->parent_window = parent_window;
+
+ if (parent_window != NULL)
+ {
+ g_object_ref (parent_window);
+ }
+
+ /* Start the timer. */
+ wait->timeout_handler_id = g_timeout_add (duration, timed_wait_callback, wait);
+
+ /* Put in the hash table so we can find it later. */
+ if (timed_wait_hash_table == NULL)
+ {
+ timed_wait_hash_table = g_hash_table_new (timed_wait_hash, timed_wait_hash_equal);
+ }
+ g_assert (g_hash_table_lookup (timed_wait_hash_table, wait) == NULL);
+ g_hash_table_insert (timed_wait_hash_table, wait, wait);
+ g_assert (g_hash_table_lookup (timed_wait_hash_table, wait) == wait);
}
void
-eel_timed_wait_start (EelCancelCallback cancel_callback,
- gpointer callback_data,
- const char *wait_message,
- GtkWindow *parent_window)
+eel_timed_wait_start (EelCancelCallback cancel_callback,
+ gpointer callback_data,
+ const char *wait_message,
+ GtkWindow *parent_window)
{
- eel_timed_wait_start_with_duration
- (TIMED_WAIT_STANDARD_DURATION,
- cancel_callback, callback_data,
- wait_message, parent_window);
+ eel_timed_wait_start_with_duration
+ (TIMED_WAIT_STANDARD_DURATION,
+ cancel_callback, callback_data,
+ wait_message, parent_window);
}
void
eel_timed_wait_stop (EelCancelCallback cancel_callback,
- gpointer callback_data)
+ gpointer callback_data)
{
- TimedWait key;
- TimedWait *wait;
+ TimedWait key;
+ TimedWait *wait;
+
+ g_return_if_fail (callback_data != NULL);
- g_return_if_fail (callback_data != NULL);
-
- key.cancel_callback = cancel_callback;
- key.callback_data = callback_data;
- wait = g_hash_table_lookup (timed_wait_hash_table, &key);
+ key.cancel_callback = cancel_callback;
+ key.callback_data = callback_data;
+ wait = g_hash_table_lookup (timed_wait_hash_table, &key);
- g_return_if_fail (wait != NULL);
+ g_return_if_fail (wait != NULL);
- timed_wait_free (wait);
+ timed_wait_free (wait);
}
int
-eel_run_simple_dialog (GtkWidget *parent, gboolean ignore_close_box,
- GtkMessageType message_type, const char *primary_text,
- const char *secondary_text, ...)
+eel_run_simple_dialog (GtkWidget *parent,
+ gboolean ignore_close_box,
+ GtkMessageType message_type,
+ const char *primary_text,
+ const char *secondary_text,
+ ...)
{
- va_list button_title_args;
- const char *button_title;
- GtkWidget *dialog;
- GtkWidget *top_widget, *chosen_parent;
- int result;
- int response_id;
-
- /* Parent it if asked to. */
- chosen_parent = NULL;
- if (parent != NULL) {
- top_widget = gtk_widget_get_toplevel (parent);
- if (GTK_IS_WINDOW (top_widget)) {
- chosen_parent = top_widget;
- }
- }
-
- /* Create the dialog. */
- dialog = gtk_message_dialog_new (GTK_WINDOW (chosen_parent),
- 0,
- message_type,
- GTK_BUTTONS_NONE,
- NULL);
-
- g_object_set (dialog,
- "text", primary_text,
- "secondary-text", secondary_text,
- NULL);
-
- va_start (button_title_args, secondary_text);
- response_id = 0;
- while (1) {
- button_title = va_arg (button_title_args, const char *);
- if (button_title == NULL) {
- break;
- }
- gtk_dialog_add_button (GTK_DIALOG (dialog), button_title, response_id);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), response_id);
- response_id++;
- }
- va_end (button_title_args);
-
- /* Run it. */
- gtk_widget_show (dialog);
+ va_list button_title_args;
+ const char *button_title;
+ GtkWidget *dialog;
+ GtkWidget *top_widget, *chosen_parent;
+ int result;
+ int response_id;
+
+ /* Parent it if asked to. */
+ chosen_parent = NULL;
+ if (parent != NULL)
+ {
+ top_widget = gtk_widget_get_toplevel (parent);
+ if (GTK_IS_WINDOW (top_widget))
+ {
+ chosen_parent = top_widget;
+ }
+ }
+
+ /* Create the dialog. */
+ dialog = gtk_message_dialog_new (GTK_WINDOW (chosen_parent),
+ 0,
+ message_type,
+ GTK_BUTTONS_NONE,
+ NULL);
+
+ g_object_set (dialog,
+ "text", primary_text,
+ "secondary-text", secondary_text,
+ NULL);
+
+ va_start (button_title_args, secondary_text);
+ response_id = 0;
+ while (1)
+ {
+ button_title = va_arg (button_title_args, const char *);
+ if (button_title == NULL)
+ {
+ break;
+ }
+ gtk_dialog_add_button (GTK_DIALOG (dialog), button_title, response_id);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), response_id);
+ response_id++;
+ }
+ va_end (button_title_args);
+
+ /* Run it. */
+ gtk_widget_show (dialog);
+ result = gtk_dialog_run (GTK_DIALOG (dialog));
+ while ((result == GTK_RESPONSE_NONE || result == GTK_RESPONSE_DELETE_EVENT) && ignore_close_box)
+ {
+ gtk_widget_show (GTK_WIDGET (dialog));
result = gtk_dialog_run (GTK_DIALOG (dialog));
- while ((result == GTK_RESPONSE_NONE || result == GTK_RESPONSE_DELETE_EVENT) && ignore_close_box) {
- gtk_widget_show (GTK_WIDGET (dialog));
- result = gtk_dialog_run (GTK_DIALOG (dialog));
- }
- gtk_widget_destroy (dialog);
+ }
+ gtk_widget_destroy (dialog);
- return result;
+ return result;
}
static GtkDialog *
-create_message_dialog (const char *primary_text,
- const char *secondary_text,
- GtkMessageType type,
- GtkButtonsType buttons_type,
- GtkWindow *parent)
-{
- GtkWidget *dialog;
-
- dialog = gtk_message_dialog_new (parent,
- 0,
- type,
- buttons_type,
- NULL);
- if (parent)
- gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
-
- g_object_set (dialog,
- "text", primary_text,
- "secondary-text", secondary_text,
- NULL);
-
- return GTK_DIALOG (dialog);
+create_message_dialog (const char *primary_text,
+ const char *secondary_text,
+ GtkMessageType type,
+ GtkButtonsType buttons_type,
+ GtkWindow *parent)
+{
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (parent,
+ 0,
+ type,
+ buttons_type,
+ NULL);
+ if (parent)
+ {
+ gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+ }
+
+ g_object_set (dialog,
+ "text", primary_text,
+ "secondary-text", secondary_text,
+ NULL);
+
+ return GTK_DIALOG (dialog);
}
static GtkDialog *
-show_message_dialog (const char *primary_text,
- const char *secondary_text,
- GtkMessageType type,
- GtkButtonsType buttons_type,
- GtkWindow *parent)
+show_message_dialog (const char *primary_text,
+ const char *secondary_text,
+ GtkMessageType type,
+ GtkButtonsType buttons_type,
+ GtkWindow *parent)
{
- GtkDialog *dialog;
+ GtkDialog *dialog;
- dialog = create_message_dialog (primary_text, secondary_text, type,
- buttons_type, parent);
- gtk_widget_show (GTK_WIDGET (dialog));
+ dialog = create_message_dialog (primary_text, secondary_text, type,
+ buttons_type, parent);
+ gtk_widget_show (GTK_WIDGET (dialog));
- g_signal_connect (dialog, "response",
- G_CALLBACK (gtk_widget_destroy), NULL);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), NULL);
- return dialog;
+ return dialog;
}
static GtkDialog *
-show_ok_dialog (const char *primary_text,
- const char *secondary_text,
- GtkMessageType type,
- GtkWindow *parent)
-{
- GtkDialog *dialog;
-
- dialog = show_message_dialog (primary_text, secondary_text, type,
- GTK_BUTTONS_OK, parent);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
-
- return dialog;
+show_ok_dialog (const char *primary_text,
+ const char *secondary_text,
+ GtkMessageType type,
+ GtkWindow *parent)
+{
+ GtkDialog *dialog;
+
+ dialog = show_message_dialog (primary_text, secondary_text, type,
+ GTK_BUTTONS_OK, parent);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+ return dialog;
}
GtkDialog *
eel_show_info_dialog (const char *primary_text,
- const char *secondary_text,
- GtkWindow *parent)
+ const char *secondary_text,
+ GtkWindow *parent)
{
- return show_ok_dialog (primary_text,
- secondary_text,
- GTK_MESSAGE_INFO, parent);
+ return show_ok_dialog (primary_text,
+ secondary_text,
+ GTK_MESSAGE_INFO, parent);
}
GtkDialog *
eel_show_warning_dialog (const char *primary_text,
- const char *secondary_text,
- GtkWindow *parent)
+ const char *secondary_text,
+ GtkWindow *parent)
{
- return show_ok_dialog (primary_text,
- secondary_text,
- GTK_MESSAGE_WARNING, parent);
+ return show_ok_dialog (primary_text,
+ secondary_text,
+ GTK_MESSAGE_WARNING, parent);
}
GtkDialog *
eel_show_error_dialog (const char *primary_text,
- const char *secondary_text,
- GtkWindow *parent)
+ const char *secondary_text,
+ GtkWindow *parent)
{
- return show_ok_dialog (primary_text,
- secondary_text,
- GTK_MESSAGE_ERROR, parent);
+ return show_ok_dialog (primary_text,
+ secondary_text,
+ GTK_MESSAGE_ERROR, parent);
}
/**
* eel_show_yes_no_dialog:
- *
+ *
* Create and show a dialog asking a question with two choices.
- * The caller needs to set up any necessary callbacks
+ * The caller needs to set up any necessary callbacks
* for the buttons. Use eel_create_question_dialog instead
* if any visual changes need to be made, to avoid flashiness.
* @question: The text of the question.
@@ -467,27 +489,27 @@ eel_show_error_dialog (const char *primary_text,
* @parent: The parent window for this dialog.
*/
GtkDialog *
-eel_show_yes_no_dialog (const char *primary_text,
- const char *secondary_text,
- const char *yes_label,
- const char *no_label,
- GtkWindow *parent)
+eel_show_yes_no_dialog (const char *primary_text,
+ const char *secondary_text,
+ const char *yes_label,
+ const char *no_label,
+ GtkWindow *parent)
{
- GtkDialog *dialog = NULL;
- dialog = eel_create_question_dialog (primary_text,
- secondary_text,
- no_label, GTK_RESPONSE_CANCEL,
- yes_label, GTK_RESPONSE_YES,
- GTK_WINDOW (parent));
- gtk_widget_show (GTK_WIDGET (dialog));
- return dialog;
+ GtkDialog *dialog = NULL;
+ dialog = eel_create_question_dialog (primary_text,
+ secondary_text,
+ no_label, GTK_RESPONSE_CANCEL,
+ yes_label, GTK_RESPONSE_YES,
+ GTK_WINDOW (parent));
+ gtk_widget_show (GTK_WIDGET (dialog));
+ return dialog;
}
/**
* eel_create_question_dialog:
- *
+ *
* Create a dialog asking a question with at least two choices.
- * The caller needs to set up any necessary callbacks
+ * The caller needs to set up any necessary callbacks
* for the buttons. The dialog is not yet shown, so that the
* caller can add additional buttons or make other visual changes
* without causing flashiness.
@@ -498,20 +520,20 @@ eel_show_yes_no_dialog (const char *primary_text,
*/
GtkDialog *
eel_create_question_dialog (const char *primary_text,
- const char *secondary_text,
- const char *answer_1,
- int response_1,
- const char *answer_2,
- int response_2,
- GtkWindow *parent)
+ const char *secondary_text,
+ const char *answer_1,
+ int response_1,
+ const char *answer_2,
+ int response_2,
+ GtkWindow *parent)
{
- GtkDialog *dialog;
-
- dialog = create_message_dialog (primary_text,
- secondary_text,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_NONE,
- parent);
- gtk_dialog_add_buttons (dialog, answer_1, response_1, answer_2, response_2, NULL);
- return dialog;
+ GtkDialog *dialog;
+
+ dialog = create_message_dialog (primary_text,
+ secondary_text,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE,
+ parent);
+ gtk_dialog_add_buttons (dialog, answer_1, response_1, answer_2, response_2, NULL);
+ return dialog;
}
diff --git a/eel/eel-string.c b/eel/eel-string.c
index e0f849c7f..9fe79ab98 100644
--- a/eel/eel-string.c
+++ b/eel/eel-string.c
@@ -1,24 +1,24 @@
/*
- eel-string.c: String routines to augment <string.h>.
-
- Copyright (C) 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Darin Adler <darin@eazel.com>
-*/
+ * eel-string.c: String routines to augment <string.h>.
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Darin Adler <darin@eazel.com>
+ */
#include <config.h>
#include "eel-string.h"
@@ -36,207 +36,228 @@
char *
eel_str_double_underscores (const char *string)
{
- int underscores;
- const char *p;
- char *q;
- char *escaped;
-
- if (string == NULL) {
- return NULL;
- }
-
- underscores = 0;
- for (p = string; *p != '\0'; p++) {
- underscores += (*p == '_');
- }
-
- if (underscores == 0) {
- return g_strdup (string);
- }
-
- escaped = g_new (char, strlen (string) + underscores + 1);
- for (p = string, q = escaped; *p != '\0'; p++, q++) {
- /* Add an extra underscore. */
- if (*p == '_') {
- *q++ = '_';
- }
- *q = *p;
- }
- *q = '\0';
-
- return escaped;
+ int underscores;
+ const char *p;
+ char *q;
+ char *escaped;
+
+ if (string == NULL)
+ {
+ return NULL;
+ }
+
+ underscores = 0;
+ for (p = string; *p != '\0'; p++)
+ {
+ underscores += (*p == '_');
+ }
+
+ if (underscores == 0)
+ {
+ return g_strdup (string);
+ }
+
+ escaped = g_new (char, strlen (string) + underscores + 1);
+ for (p = string, q = escaped; *p != '\0'; p++, q++)
+ {
+ /* Add an extra underscore. */
+ if (*p == '_')
+ {
+ *q++ = '_';
+ }
+ *q = *p;
+ }
+ *q = '\0';
+
+ return escaped;
}
char *
eel_str_capitalize (const char *string)
{
- char *capitalized;
+ char *capitalized;
- if (string == NULL) {
- return NULL;
- }
+ if (string == NULL)
+ {
+ return NULL;
+ }
- capitalized = g_strdup (string);
+ capitalized = g_strdup (string);
- capitalized[0] = g_ascii_toupper (capitalized[0]);
+ capitalized[0] = g_ascii_toupper (capitalized[0]);
- return capitalized;
+ return capitalized;
}
/* Note: eel_string_ellipsize_* that use a length in pixels
* rather than characters can be found in eel_gdk_extensions.h
- *
- * FIXME bugzilla.eazel.com 5089:
+ *
+ * FIXME bugzilla.eazel.com 5089:
* we should coordinate the names of eel_string_ellipsize_*
* and eel_str_*_truncate so that they match better and reflect
* their different behavior.
*/
char *
eel_str_middle_truncate (const char *string,
- guint truncate_length)
+ guint truncate_length)
{
- char *truncated;
- guint length;
- guint num_left_chars;
- guint num_right_chars;
-
- const char delimter[] = "...";
- const guint delimter_length = strlen (delimter);
- const guint min_truncate_length = delimter_length + 2;
-
- if (string == NULL) {
- return NULL;
- }
-
- /* It doesnt make sense to truncate strings to less than
- * the size of the delimiter plus 2 characters (one on each
- * side)
- */
- if (truncate_length < min_truncate_length) {
- return g_strdup (string);
- }
-
- length = g_utf8_strlen (string, -1);
-
- /* Make sure the string is not already small enough. */
- if (length <= truncate_length) {
- return g_strdup (string);
- }
-
- /* Find the 'middle' where the truncation will occur. */
- num_left_chars = (truncate_length - delimter_length) / 2;
- num_right_chars = truncate_length - num_left_chars - delimter_length;
-
- truncated = g_new (char, strlen (string) + 1);
-
- g_utf8_strncpy (truncated, string, num_left_chars);
- strcat (truncated, delimter);
- strcat (truncated, g_utf8_offset_to_pointer (string, length - num_right_chars));
-
- return truncated;
+ char *truncated;
+ guint length;
+ guint num_left_chars;
+ guint num_right_chars;
+
+ const char delimter[] = "...";
+ const guint delimter_length = strlen (delimter);
+ const guint min_truncate_length = delimter_length + 2;
+
+ if (string == NULL)
+ {
+ return NULL;
+ }
+
+ /* It doesnt make sense to truncate strings to less than
+ * the size of the delimiter plus 2 characters (one on each
+ * side)
+ */
+ if (truncate_length < min_truncate_length)
+ {
+ return g_strdup (string);
+ }
+
+ length = g_utf8_strlen (string, -1);
+
+ /* Make sure the string is not already small enough. */
+ if (length <= truncate_length)
+ {
+ return g_strdup (string);
+ }
+
+ /* Find the 'middle' where the truncation will occur. */
+ num_left_chars = (truncate_length - delimter_length) / 2;
+ num_right_chars = truncate_length - num_left_chars - delimter_length;
+
+ truncated = g_new (char, strlen (string) + 1);
+
+ g_utf8_strncpy (truncated, string, num_left_chars);
+ strcat (truncated, delimter);
+ strcat (truncated, g_utf8_offset_to_pointer (string, length - num_right_chars));
+
+ return truncated;
}
char *
eel_str_strip_substring_and_after (const char *string,
- const char *substring)
+ const char *substring)
{
- const char *substring_position;
+ const char *substring_position;
- g_return_val_if_fail (substring != NULL, g_strdup (string));
- g_return_val_if_fail (substring[0] != '\0', g_strdup (string));
+ g_return_val_if_fail (substring != NULL, g_strdup (string));
+ g_return_val_if_fail (substring[0] != '\0', g_strdup (string));
- if (string == NULL) {
- return NULL;
- }
+ if (string == NULL)
+ {
+ return NULL;
+ }
- substring_position = strstr (string, substring);
- if (substring_position == NULL) {
- return g_strdup (string);
- }
+ substring_position = strstr (string, substring);
+ if (substring_position == NULL)
+ {
+ return g_strdup (string);
+ }
- return g_strndup (string,
- substring_position - string);
+ return g_strndup (string,
+ substring_position - string);
}
char *
eel_str_replace_substring (const char *string,
- const char *substring,
- const char *replacement)
+ const char *substring,
+ const char *replacement)
{
- int substring_length, replacement_length, result_length, remaining_length;
- const char *p, *substring_position;
- char *result, *result_position;
-
- g_return_val_if_fail (substring != NULL, g_strdup (string));
- g_return_val_if_fail (substring[0] != '\0', g_strdup (string));
-
- if (string == NULL) {
- return NULL;
- }
-
- substring_length = substring ? strlen (substring) : 0;
- replacement_length = replacement ? strlen (replacement) : 0;
-
- result_length = strlen (string);
- for (p = string; ; p = substring_position + substring_length) {
- substring_position = strstr (p, substring);
- if (substring_position == NULL) {
- break;
- }
- result_length += replacement_length - substring_length;
- }
-
- result = g_malloc (result_length + 1);
-
- result_position = result;
- for (p = string; ; p = substring_position + substring_length) {
- substring_position = strstr (p, substring);
- if (substring_position == NULL) {
- remaining_length = strlen (p);
- memcpy (result_position, p, remaining_length);
- result_position += remaining_length;
- break;
- }
- memcpy (result_position, p, substring_position - p);
- result_position += substring_position - p;
- memcpy (result_position, replacement, replacement_length);
- result_position += replacement_length;
- }
- g_assert (result_position - result == result_length);
- result_position[0] = '\0';
-
- return result;
+ int substring_length, replacement_length, result_length, remaining_length;
+ const char *p, *substring_position;
+ char *result, *result_position;
+
+ g_return_val_if_fail (substring != NULL, g_strdup (string));
+ g_return_val_if_fail (substring[0] != '\0', g_strdup (string));
+
+ if (string == NULL)
+ {
+ return NULL;
+ }
+
+ substring_length = substring ? strlen (substring) : 0;
+ replacement_length = replacement ? strlen (replacement) : 0;
+
+ result_length = strlen (string);
+ for (p = string;; p = substring_position + substring_length)
+ {
+ substring_position = strstr (p, substring);
+ if (substring_position == NULL)
+ {
+ break;
+ }
+ result_length += replacement_length - substring_length;
+ }
+
+ result = g_malloc (result_length + 1);
+
+ result_position = result;
+ for (p = string;; p = substring_position + substring_length)
+ {
+ substring_position = strstr (p, substring);
+ if (substring_position == NULL)
+ {
+ remaining_length = strlen (p);
+ memcpy (result_position, p, remaining_length);
+ result_position += remaining_length;
+ break;
+ }
+ memcpy (result_position, p, substring_position - p);
+ result_position += substring_position - p;
+ memcpy (result_position, replacement, replacement_length);
+ result_position += replacement_length;
+ }
+ g_assert (result_position - result == result_length);
+ result_position[0] = '\0';
+
+ return result;
}
char *
eel_str_rtrim_punctuation (char *str)
{
- int num_punctuation_chars;
- int str_len;
- int num_chars_left;
- char *current_char_pos;
- gunichar current_char;
+ int num_punctuation_chars;
+ int str_len;
+ int num_chars_left;
+ char *current_char_pos;
+ gunichar current_char;
- num_punctuation_chars = 0;
- str_len = g_utf8_strlen (str, -1);
- current_char_pos = g_utf8_offset_to_pointer (str, str_len);
+ num_punctuation_chars = 0;
+ str_len = g_utf8_strlen (str, -1);
+ current_char_pos = g_utf8_offset_to_pointer (str, str_len);
- while (num_punctuation_chars <= str_len) {
- current_char_pos = g_utf8_prev_char (current_char_pos);
- current_char = g_utf8_get_char (current_char_pos);
+ while (num_punctuation_chars <= str_len)
+ {
+ current_char_pos = g_utf8_prev_char (current_char_pos);
+ current_char = g_utf8_get_char (current_char_pos);
- if (!g_unichar_ispunct (current_char) && !g_unichar_isspace (current_char))
- break;
+ if (!g_unichar_ispunct (current_char) && !g_unichar_isspace (current_char))
+ {
+ break;
+ }
- ++num_punctuation_chars;
- }
+ ++num_punctuation_chars;
+ }
- if (num_punctuation_chars == 0)
- return g_strdup (str);
+ if (num_punctuation_chars == 0)
+ {
+ return g_strdup (str);
+ }
- num_chars_left = str_len - num_punctuation_chars;
+ num_chars_left = str_len - num_punctuation_chars;
- return g_utf8_substring (str, 0, num_chars_left);
+ return g_utf8_substring (str, 0, num_chars_left);
}
/**
@@ -251,460 +272,550 @@ eel_str_rtrim_punctuation (char *str)
*/
static int
get_common_prefix_length (char *str_a,
- char *str_b,
- int min_required_len)
+ char *str_b,
+ int min_required_len)
{
- int a_len;
- int b_len;
- int intersection_len;
- int matching_chars;
- char *a;
- char *b;
-
- a_len = g_utf8_strlen (str_a, -1);
- b_len = g_utf8_strlen (str_b, -1);
-
- intersection_len = MIN (a_len, b_len);
- if (intersection_len < min_required_len)
- return -1;
-
- matching_chars = 0;
- a = str_a;
- b = str_b;
- while (matching_chars < intersection_len) {
- if (g_utf8_get_char (a) != g_utf8_get_char (b))
- break;
-
- ++matching_chars;
-
- a = g_utf8_next_char (a);
- b = g_utf8_next_char (b);
- }
-
- if (matching_chars < min_required_len)
- return -1;
-
- return matching_chars;
+ int a_len;
+ int b_len;
+ int intersection_len;
+ int matching_chars;
+ char *a;
+ char *b;
+
+ a_len = g_utf8_strlen (str_a, -1);
+ b_len = g_utf8_strlen (str_b, -1);
+
+ intersection_len = MIN (a_len, b_len);
+ if (intersection_len < min_required_len)
+ {
+ return -1;
+ }
+
+ matching_chars = 0;
+ a = str_a;
+ b = str_b;
+ while (matching_chars < intersection_len)
+ {
+ if (g_utf8_get_char (a) != g_utf8_get_char (b))
+ {
+ break;
+ }
+
+ ++matching_chars;
+
+ a = g_utf8_next_char (a);
+ b = g_utf8_next_char (b);
+ }
+
+ if (matching_chars < min_required_len)
+ {
+ return -1;
+ }
+
+ return matching_chars;
}
char *
-eel_str_get_common_prefix (GList *strs, int min_required_len)
+eel_str_get_common_prefix (GList *strs,
+ int min_required_len)
{
- GList *l;
- char *common_part;
- char *name;
- char *truncated;
- int matching_chars;
-
- if (strs == NULL)
- return NULL;
-
- common_part = NULL;
- for (l = strs; l != NULL; l = l->next) {
-
- name = l->data;
- if (name == NULL) {
- g_free (common_part);
- return NULL;
- }
-
- if (l->prev == NULL) {
- common_part = g_strdup (name);
- continue;
- }
-
- matching_chars = get_common_prefix_length (common_part, name, min_required_len);
-
- if (matching_chars == -1) {
- g_free (common_part);
- return NULL;
- }
-
- truncated = g_utf8_substring (common_part, 0, matching_chars);
- g_free (common_part);
- common_part = truncated;
- }
-
- matching_chars = g_utf8_strlen (common_part, -1);
- if (matching_chars < min_required_len) {
- g_free (common_part);
- return NULL;
- }
-
- return common_part;
+ GList *l;
+ char *common_part;
+ char *name;
+ char *truncated;
+ int matching_chars;
+
+ if (strs == NULL)
+ {
+ return NULL;
+ }
+
+ common_part = NULL;
+ for (l = strs; l != NULL; l = l->next)
+ {
+ name = l->data;
+ if (name == NULL)
+ {
+ g_free (common_part);
+ return NULL;
+ }
+
+ if (l->prev == NULL)
+ {
+ common_part = g_strdup (name);
+ continue;
+ }
+
+ matching_chars = get_common_prefix_length (common_part, name, min_required_len);
+
+ if (matching_chars == -1)
+ {
+ g_free (common_part);
+ return NULL;
+ }
+
+ truncated = g_utf8_substring (common_part, 0, matching_chars);
+ g_free (common_part);
+ common_part = truncated;
+ }
+
+ matching_chars = g_utf8_strlen (common_part, -1);
+ if (matching_chars < min_required_len)
+ {
+ g_free (common_part);
+ return NULL;
+ }
+
+ return common_part;
}
/**************** Custom printf ***********/
-typedef struct {
- const char *start;
- const char *end;
- GString *format;
- int arg_pos;
- int width_pos;
- int width_format_index;
- int precision_pos;
- int precision_format_index;
+typedef struct
+{
+ const char *start;
+ const char *end;
+ GString *format;
+ int arg_pos;
+ int width_pos;
+ int width_format_index;
+ int precision_pos;
+ int precision_format_index;
} ConversionInfo;
-enum {
- ARG_TYPE_INVALID,
- ARG_TYPE_INT,
- ARG_TYPE_LONG,
- ARG_TYPE_LONG_LONG,
- ARG_TYPE_SIZE,
- ARG_TYPE_LONG_DOUBLE,
- ARG_TYPE_DOUBLE,
- ARG_TYPE_POINTER
+enum
+{
+ ARG_TYPE_INVALID,
+ ARG_TYPE_INT,
+ ARG_TYPE_LONG,
+ ARG_TYPE_LONG_LONG,
+ ARG_TYPE_SIZE,
+ ARG_TYPE_LONG_DOUBLE,
+ ARG_TYPE_DOUBLE,
+ ARG_TYPE_POINTER
};
typedef int ArgType; /* An int, because custom are < 0 */
static const char *
-get_position (const char *format, int *i)
+get_position (const char *format,
+ int *i)
{
- const char *p;
-
- p = format;
-
- if (g_ascii_isdigit (*p)) {
- p++;
-
- while (g_ascii_isdigit (*p)) {
- p++;
- }
-
- if (*p == '$') {
- if (i != NULL) {
- *i = atoi (format) - 1;
- }
- return p + 1;
- }
- }
-
- return format;
+ const char *p;
+
+ p = format;
+
+ if (g_ascii_isdigit (*p))
+ {
+ p++;
+
+ while (g_ascii_isdigit (*p))
+ {
+ p++;
+ }
+
+ if (*p == '$')
+ {
+ if (i != NULL)
+ {
+ *i = atoi (format) - 1;
+ }
+ return p + 1;
+ }
+ }
+
+ return format;
}
static gboolean
is_flag (char c)
{
- return strchr ("#0- +'I", c) != NULL;
+ return strchr ("#0- +'I", c) != NULL;
}
static gboolean
is_length_modifier (char c)
{
- return strchr ("hlLjzt", c) != NULL;
+ return strchr ("hlLjzt", c) != NULL;
}
static ArgType
get_arg_type_from_format (EelPrintfHandler *custom_handlers,
- const char *format,
- int len)
+ const char *format,
+ int len)
{
- int i;
- char c;
-
- c = format[len-1];
-
- if (custom_handlers != NULL) {
- for (i = 0; custom_handlers[i].character != 0; i++) {
- if (custom_handlers[i].character == c) {
- return -(i + 1);
- }
- }
- }
-
- switch (c) {
- case 'd':
- case 'i':
- case 'o':
- case 'u':
- case 'x':
- case 'X':
- if (g_str_has_prefix (format, "ll")) {
- return ARG_TYPE_LONG_LONG;
- }
- if (g_str_has_prefix (format, "l")) {
- return ARG_TYPE_LONG;
- }
- if (g_str_has_prefix (format, "l")) {
- return ARG_TYPE_LONG;
- }
- if (g_str_has_prefix (format, "z")) {
- return ARG_TYPE_SIZE;
- }
- return ARG_TYPE_INT;
- case 'e':
- case 'E':
- case 'f':
- case 'F':
- case 'g':
- case 'G':
- case 'a':
- case 'A':
- if (g_str_has_prefix (format, "L")) {
- return ARG_TYPE_LONG_DOUBLE;
- }
- return ARG_TYPE_DOUBLE;
- case 'c':
- return ARG_TYPE_INT;
- case 's':
- case 'p':
- case 'n':
- return ARG_TYPE_POINTER;
- }
- return ARG_TYPE_INVALID;
+ int i;
+ char c;
+
+ c = format[len - 1];
+
+ if (custom_handlers != NULL)
+ {
+ for (i = 0; custom_handlers[i].character != 0; i++)
+ {
+ if (custom_handlers[i].character == c)
+ {
+ return -(i + 1);
+ }
+ }
+ }
+
+ switch (c)
+ {
+ case 'd':
+ case 'i':
+ case 'o':
+ case 'u':
+ case 'x':
+ case 'X':
+ {
+ if (g_str_has_prefix (format, "ll"))
+ {
+ return ARG_TYPE_LONG_LONG;
+ }
+ if (g_str_has_prefix (format, "l"))
+ {
+ return ARG_TYPE_LONG;
+ }
+ if (g_str_has_prefix (format, "l"))
+ {
+ return ARG_TYPE_LONG;
+ }
+ if (g_str_has_prefix (format, "z"))
+ {
+ return ARG_TYPE_SIZE;
+ }
+ return ARG_TYPE_INT;
+ }
+
+ case 'e':
+ case 'E':
+ case 'f':
+ case 'F':
+ case 'g':
+ case 'G':
+ case 'a':
+ case 'A':
+ {
+ if (g_str_has_prefix (format, "L"))
+ {
+ return ARG_TYPE_LONG_DOUBLE;
+ }
+ return ARG_TYPE_DOUBLE;
+ }
+
+ case 'c':
+ {
+ return ARG_TYPE_INT;
+ }
+
+ case 's':
+ case 'p':
+ case 'n':
+ return ARG_TYPE_POINTER;
+ }
+ return ARG_TYPE_INVALID;
}
static void
-skip_argv (va_list *va,
- ArgType type,
- EelPrintfHandler *custom_handlers)
+skip_argv (va_list *va,
+ ArgType type,
+ EelPrintfHandler *custom_handlers)
{
- if (type < 0) {
- custom_handlers[-type - 1].skip (va);
- return;
- }
-
- switch (type) {
- default:
- case ARG_TYPE_INVALID:
- return;
-
- case ARG_TYPE_INT:
- (void) va_arg (*va, int);
- break;
- case ARG_TYPE_LONG:
- (void) va_arg (*va, long int);
- break;
- case ARG_TYPE_LONG_LONG:
- (void) va_arg (*va, long long int);
- break;
- case ARG_TYPE_SIZE:
- (void) va_arg (*va, gsize);
- break;
- case ARG_TYPE_LONG_DOUBLE:
- (void) va_arg (*va, long double);
- break;
- case ARG_TYPE_DOUBLE:
- (void) va_arg (*va, double);
- break;
- case ARG_TYPE_POINTER:
- (void) va_arg (*va, void *);
- break;
- }
+ if (type < 0)
+ {
+ custom_handlers[-type - 1].skip (va);
+ return;
+ }
+
+ switch (type)
+ {
+ default:
+ case ARG_TYPE_INVALID:
+ {
+ return;
+ }
+
+ case ARG_TYPE_INT:
+ {
+ (void) va_arg (*va, int);
+ }
+ break;
+
+ case ARG_TYPE_LONG:
+ {
+ (void) va_arg (*va, long int);
+ }
+ break;
+
+ case ARG_TYPE_LONG_LONG:
+ {
+ (void) va_arg (*va, long long int);
+ }
+ break;
+
+ case ARG_TYPE_SIZE:
+ {
+ (void) va_arg (*va, gsize);
+ }
+ break;
+
+ case ARG_TYPE_LONG_DOUBLE:
+ {
+ (void) va_arg (*va, long double);
+ }
+ break;
+
+ case ARG_TYPE_DOUBLE:
+ {
+ (void) va_arg (*va, double);
+ }
+ break;
+
+ case ARG_TYPE_POINTER:
+ {
+ (void) va_arg (*va, void *);
+ }
+ break;
+ }
}
static void
-skip_to_arg (va_list *va,
- ArgType *types,
- EelPrintfHandler *custom_handlers,
- int n)
+skip_to_arg (va_list *va,
+ ArgType *types,
+ EelPrintfHandler *custom_handlers,
+ int n)
{
- int i;
- for (i = 0; i < n; i++) {
- skip_argv (va, types[i], custom_handlers);
- }
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ skip_argv (va, types[i], custom_handlers);
+ }
}
char *
eel_strdup_vprintf_with_custom (EelPrintfHandler *custom,
- const char *format,
- va_list va_orig)
+ const char *format,
+ va_list va_orig)
{
- va_list va;
- const char *p;
- int num_args, i, j;
- ArgType *args;
- ArgType type;
- ConversionInfo *conversions;
- GString *f, *str;
- const char *flags, *width, *prec, *mod, *pos;
- char *s;
-
- num_args = 0;
- for (p = format; *p != 0; p++) {
- if (*p == '%') {
- p++;
- if (*p != '%') {
- num_args++;
- }
- }
- }
-
- args = g_new0 (ArgType, num_args * 3 + 1);
- conversions = g_new0 (ConversionInfo, num_args);
-
- /* i indexes conversions, j indexes args */
- i = 0; j = 0;
- p = format;
- while (*p != 0) {
- if (*p != '%') {
- p++;
- continue;
- }
- p++;
- if (*p == '%') {
- p++;
- continue;
- }
-
- /* We got a real conversion: */
- f = g_string_new ("%");
- conversions[i].start = p - 1;
-
- /* First comes the positional arg */
-
- pos = p;
- p = get_position (p, NULL);
-
- /* Then flags */
- flags = p;
- while (is_flag (*p)) {
- p++;
- }
- g_string_append_len (f, flags, p - flags);
-
- /* Field width */
-
- if (*p == '*') {
- p++;
- p = get_position (p, &j);
- args[j] = ARG_TYPE_INT;
- conversions[i].width_pos = j++;
- conversions[i].width_format_index = f->len;
- } else {
- conversions[i].width_pos = -1;
- conversions[i].width_format_index = -1;
- width = p;
- while (g_ascii_isdigit (*p)) {
- p++;
- }
- g_string_append_len (f, width, p - width);
- }
-
- /* Precision */
- conversions[i].precision_pos = -1;
- conversions[i].precision_format_index = -1;
- if (*p == '.') {
- g_string_append_c (f, '.');
- p++;
-
- if (*p == '*') {
- p++;
- p = get_position (p, &j);
- args[j] = ARG_TYPE_INT;
- conversions[i].precision_pos = j++;
- conversions[i].precision_format_index = f->len;
- } else {
- prec = p;
- while (g_ascii_isdigit (*p) || *p == '-') {
- p++;
- }
- g_string_append_len (f, prec, p - prec);
- }
- }
-
- /* length modifier */
-
- mod = p;
-
- while (is_length_modifier (*p)) {
- p++;
- }
-
- /* conversion specifier */
- if (*p != 0)
- p++;
-
- g_string_append_len (f, mod, p - mod);
-
- get_position (pos, &j);
- args[j] = get_arg_type_from_format (custom, mod, p - mod);
- conversions[i].arg_pos = j++;
- conversions[i].format = f;
- conversions[i].end = p;
-
- i++;
- }
-
- g_assert (i == num_args);
-
- str = g_string_new ("");
-
- p = format;
- for (i = 0; i < num_args; i++) {
- g_string_append_len (str, p, conversions[i].start - p);
- p = conversions[i].end;
-
- if (conversions[i].precision_pos != -1) {
- char *val;
-
- G_VA_COPY(va, va_orig);
- skip_to_arg (&va, args, custom, conversions[i].precision_pos);
- val = g_strdup_vprintf ("%d", va);
- va_end (va);
-
- g_string_insert (conversions[i].format,
- conversions[i].precision_format_index,
- val);
-
- g_free (val);
- }
-
- if (conversions[i].width_pos != -1) {
- char *val;
-
- G_VA_COPY(va, va_orig);
- skip_to_arg (&va, args, custom, conversions[i].width_pos);
- val = g_strdup_vprintf ("%d", va);
- va_end (va);
-
- g_string_insert (conversions[i].format,
- conversions[i].width_format_index,
- val);
-
- g_free (val);
- }
-
- G_VA_COPY(va, va_orig);
- skip_to_arg (&va, args, custom, conversions[i].arg_pos);
- type = args[conversions[i].arg_pos];
- if (type < 0) {
- s = custom[-type - 1].to_string (conversions[i].format->str, va);
- g_string_append (str, s);
- g_free (s);
- } else{
- g_string_append_vprintf (str, conversions[i].format->str, va);
- }
- va_end (va);
-
- g_string_free (conversions[i].format, TRUE);
- }
- g_string_append (str, p);
-
- g_free (args);
- g_free (conversions);
-
- return g_string_free (str, FALSE);
+ va_list va;
+ const char *p;
+ int num_args, i, j;
+ ArgType *args;
+ ArgType type;
+ ConversionInfo *conversions;
+ GString *f, *str;
+ const char *flags, *width, *prec, *mod, *pos;
+ char *s;
+
+ num_args = 0;
+ for (p = format; *p != 0; p++)
+ {
+ if (*p == '%')
+ {
+ p++;
+ if (*p != '%')
+ {
+ num_args++;
+ }
+ }
+ }
+
+ args = g_new0 (ArgType, num_args * 3 + 1);
+ conversions = g_new0 (ConversionInfo, num_args);
+
+ /* i indexes conversions, j indexes args */
+ i = 0;
+ j = 0;
+ p = format;
+ while (*p != 0)
+ {
+ if (*p != '%')
+ {
+ p++;
+ continue;
+ }
+ p++;
+ if (*p == '%')
+ {
+ p++;
+ continue;
+ }
+
+ /* We got a real conversion: */
+ f = g_string_new ("%");
+ conversions[i].start = p - 1;
+
+ /* First comes the positional arg */
+
+ pos = p;
+ p = get_position (p, NULL);
+
+ /* Then flags */
+ flags = p;
+ while (is_flag (*p))
+ {
+ p++;
+ }
+ g_string_append_len (f, flags, p - flags);
+
+ /* Field width */
+
+ if (*p == '*')
+ {
+ p++;
+ p = get_position (p, &j);
+ args[j] = ARG_TYPE_INT;
+ conversions[i].width_pos = j++;
+ conversions[i].width_format_index = f->len;
+ }
+ else
+ {
+ conversions[i].width_pos = -1;
+ conversions[i].width_format_index = -1;
+ width = p;
+ while (g_ascii_isdigit (*p))
+ {
+ p++;
+ }
+ g_string_append_len (f, width, p - width);
+ }
+
+ /* Precision */
+ conversions[i].precision_pos = -1;
+ conversions[i].precision_format_index = -1;
+ if (*p == '.')
+ {
+ g_string_append_c (f, '.');
+ p++;
+
+ if (*p == '*')
+ {
+ p++;
+ p = get_position (p, &j);
+ args[j] = ARG_TYPE_INT;
+ conversions[i].precision_pos = j++;
+ conversions[i].precision_format_index = f->len;
+ }
+ else
+ {
+ prec = p;
+ while (g_ascii_isdigit (*p) || *p == '-')
+ {
+ p++;
+ }
+ g_string_append_len (f, prec, p - prec);
+ }
+ }
+
+ /* length modifier */
+
+ mod = p;
+
+ while (is_length_modifier (*p))
+ {
+ p++;
+ }
+
+ /* conversion specifier */
+ if (*p != 0)
+ {
+ p++;
+ }
+
+ g_string_append_len (f, mod, p - mod);
+
+ get_position (pos, &j);
+ args[j] = get_arg_type_from_format (custom, mod, p - mod);
+ conversions[i].arg_pos = j++;
+ conversions[i].format = f;
+ conversions[i].end = p;
+
+ i++;
+ }
+
+ g_assert (i == num_args);
+
+ str = g_string_new ("");
+
+ p = format;
+ for (i = 0; i < num_args; i++)
+ {
+ g_string_append_len (str, p, conversions[i].start - p);
+ p = conversions[i].end;
+
+ if (conversions[i].precision_pos != -1)
+ {
+ char *val;
+
+ G_VA_COPY (va, va_orig);
+ skip_to_arg (&va, args, custom, conversions[i].precision_pos);
+ val = g_strdup_vprintf ("%d", va);
+ va_end (va);
+
+ g_string_insert (conversions[i].format,
+ conversions[i].precision_format_index,
+ val);
+
+ g_free (val);
+ }
+
+ if (conversions[i].width_pos != -1)
+ {
+ char *val;
+
+ G_VA_COPY (va, va_orig);
+ skip_to_arg (&va, args, custom, conversions[i].width_pos);
+ val = g_strdup_vprintf ("%d", va);
+ va_end (va);
+
+ g_string_insert (conversions[i].format,
+ conversions[i].width_format_index,
+ val);
+
+ g_free (val);
+ }
+
+ G_VA_COPY (va, va_orig);
+ skip_to_arg (&va, args, custom, conversions[i].arg_pos);
+ type = args[conversions[i].arg_pos];
+ if (type < 0)
+ {
+ s = custom[-type - 1].to_string (conversions[i].format->str, va);
+ g_string_append (str, s);
+ g_free (s);
+ }
+ else
+ {
+ g_string_append_vprintf (str, conversions[i].format->str, va);
+ }
+ va_end (va);
+
+ g_string_free (conversions[i].format, TRUE);
+ }
+ g_string_append (str, p);
+
+ g_free (args);
+ g_free (conversions);
+
+ return g_string_free (str, FALSE);
}
char *
eel_strdup_printf_with_custom (EelPrintfHandler *handlers,
- const char *format,
- ...)
+ const char *format,
+ ...)
{
- va_list va;
- char *res;
-
- va_start (va, format);
- res = eel_strdup_vprintf_with_custom (handlers, format, va);
- va_end (va);
-
- return res;
+ va_list va;
+ char *res;
+
+ va_start (va, format);
+ res = eel_strdup_vprintf_with_custom (handlers, format, va);
+ va_end (va);
+
+ return res;
}
/*********** refcounted strings ****************/
@@ -713,249 +824,269 @@ G_LOCK_DEFINE_STATIC (unique_ref_strs);
static GHashTable *unique_ref_strs = NULL;
static eel_ref_str
-eel_ref_str_new_internal (const char *string, int start_count)
+eel_ref_str_new_internal (const char *string,
+ int start_count)
{
- char *res;
- volatile gint *count;
- gsize len;
-
- len = strlen (string);
- res = g_malloc (sizeof (gint) + len + 1);
- count = (volatile gint *)res;
- *count = start_count;
- res += sizeof(gint);
- memcpy (res, string, len + 1);
- return res;
+ char *res;
+ volatile gint *count;
+ gsize len;
+
+ len = strlen (string);
+ res = g_malloc (sizeof (gint) + len + 1);
+ count = (volatile gint *) res;
+ *count = start_count;
+ res += sizeof (gint);
+ memcpy (res, string, len + 1);
+ return res;
}
eel_ref_str
eel_ref_str_new (const char *string)
{
- if (string == NULL) {
- return NULL;
- }
-
- return eel_ref_str_new_internal (string, 1);
+ if (string == NULL)
+ {
+ return NULL;
+ }
+
+ return eel_ref_str_new_internal (string, 1);
}
eel_ref_str
eel_ref_str_get_unique (const char *string)
{
- eel_ref_str res;
-
- if (string == NULL) {
- return NULL;
- }
-
- G_LOCK (unique_ref_strs);
- if (unique_ref_strs == NULL) {
- unique_ref_strs =
- g_hash_table_new (g_str_hash, g_str_equal);
- }
-
- res = g_hash_table_lookup (unique_ref_strs, string);
- if (res != NULL) {
- eel_ref_str_ref (res);
- } else {
- res = eel_ref_str_new_internal (string, 0x80000001);
- g_hash_table_insert (unique_ref_strs, res, res);
- }
-
- G_UNLOCK (unique_ref_strs);
-
- return res;
+ eel_ref_str res;
+
+ if (string == NULL)
+ {
+ return NULL;
+ }
+
+ G_LOCK (unique_ref_strs);
+ if (unique_ref_strs == NULL)
+ {
+ unique_ref_strs =
+ g_hash_table_new (g_str_hash, g_str_equal);
+ }
+
+ res = g_hash_table_lookup (unique_ref_strs, string);
+ if (res != NULL)
+ {
+ eel_ref_str_ref (res);
+ }
+ else
+ {
+ res = eel_ref_str_new_internal (string, 0x80000001);
+ g_hash_table_insert (unique_ref_strs, res, res);
+ }
+
+ G_UNLOCK (unique_ref_strs);
+
+ return res;
}
eel_ref_str
eel_ref_str_ref (eel_ref_str str)
{
- volatile gint *count;
+ volatile gint *count;
- count = (volatile gint *)((char *)str - sizeof (gint));
- g_atomic_int_add (count, 1);
+ count = (volatile gint *) ((char *) str - sizeof (gint));
+ g_atomic_int_add (count, 1);
- return str;
+ return str;
}
void
eel_ref_str_unref (eel_ref_str str)
{
- volatile gint *count;
- gint old_ref;
-
- if (str == NULL)
- return;
-
- count = (volatile gint *)((char *)str - sizeof (gint));
-
- retry_atomic_decrement:
- old_ref = g_atomic_int_get (count);
- if (old_ref == 1) {
- g_free ((char *)count);
- } else if (old_ref == 0x80000001) {
- G_LOCK (unique_ref_strs);
- /* Need to recheck after taking lock to avoid races with _get_unique() */
- if (g_atomic_int_add (count, -1) == 0x80000001) {
- g_hash_table_remove (unique_ref_strs, (char *)str);
- g_free ((char *)count);
- }
- G_UNLOCK (unique_ref_strs);
- } else if (!g_atomic_int_compare_and_exchange (count,
- old_ref, old_ref - 1)) {
- goto retry_atomic_decrement;
- }
+ volatile gint *count;
+ gint old_ref;
+
+ if (str == NULL)
+ {
+ return;
+ }
+
+ count = (volatile gint *) ((char *) str - sizeof (gint));
+
+retry_atomic_decrement:
+ old_ref = g_atomic_int_get (count);
+ if (old_ref == 1)
+ {
+ g_free ((char *) count);
+ }
+ else if (old_ref == 0x80000001)
+ {
+ G_LOCK (unique_ref_strs);
+ /* Need to recheck after taking lock to avoid races with _get_unique() */
+ if (g_atomic_int_add (count, -1) == 0x80000001)
+ {
+ g_hash_table_remove (unique_ref_strs, (char *) str);
+ g_free ((char *) count);
+ }
+ G_UNLOCK (unique_ref_strs);
+ }
+ else if (!g_atomic_int_compare_and_exchange (count,
+ old_ref, old_ref - 1))
+ {
+ goto retry_atomic_decrement;
+ }
}
#if !defined (EEL_OMIT_SELF_CHECK)
static void
-verify_printf (const char *format, ...)
+verify_printf (const char *format,
+ ...)
{
- va_list va;
- char *orig, *new;
-
- va_start (va, format);
- orig = g_strdup_vprintf (format, va);
- va_end (va);
-
- va_start (va, format);
- new = eel_strdup_vprintf_with_custom (NULL, format, va);
- va_end (va);
-
- EEL_CHECK_STRING_RESULT (new, orig);
-
- g_free (orig);
+ va_list va;
+ char *orig, *new;
+
+ va_start (va, format);
+ orig = g_strdup_vprintf (format, va);
+ va_end (va);
+
+ va_start (va, format);
+ new = eel_strdup_vprintf_with_custom (NULL, format, va);
+ va_end (va);
+
+ EEL_CHECK_STRING_RESULT (new, orig);
+
+ g_free (orig);
}
static char *
-custom1_to_string (char *format, va_list va)
+custom1_to_string (char *format,
+ va_list va)
{
- int i;
-
- i = va_arg (va, int);
-
- return g_strdup_printf ("c1-%d-", i);
+ int i;
+
+ i = va_arg (va, int);
+
+ return g_strdup_printf ("c1-%d-", i);
}
static void
custom1_skip (va_list *va)
{
- (void) va_arg (*va, int);
+ (void) va_arg (*va, int);
}
static char *
-custom2_to_string (char *format, va_list va)
+custom2_to_string (char *format,
+ va_list va)
{
- char *s;
-
- s = va_arg (va, char *);
-
- return g_strdup_printf ("c2-%s-", s);
+ char *s;
+
+ s = va_arg (va, char *);
+
+ return g_strdup_printf ("c2-%s-", s);
}
static void
custom2_skip (va_list *va)
{
- (void) va_arg (*va, char *);
+ (void) va_arg (*va, char *);
}
-static EelPrintfHandler handlers[] = {
- { 'N', custom1_to_string, custom1_skip },
- { 'Y', custom2_to_string, custom2_skip },
- { 0 }
+static EelPrintfHandler handlers[] =
+{
+ { 'N', custom1_to_string, custom1_skip },
+ { 'Y', custom2_to_string, custom2_skip },
+ { 0 }
};
static void
-verify_custom (const char *orig, const char *format, ...)
+verify_custom (const char *orig,
+ const char *format,
+ ...)
{
- char *new;
- va_list va;
-
- va_start (va, format);
- new = eel_strdup_vprintf_with_custom (handlers, format, va);
- va_end (va);
-
- EEL_CHECK_STRING_RESULT (new, orig);
+ char *new;
+ va_list va;
+
+ va_start (va, format);
+ new = eel_strdup_vprintf_with_custom (handlers, format, va);
+ va_end (va);
+
+ EEL_CHECK_STRING_RESULT (new, orig);
}
void
eel_self_check_string (void)
{
- EEL_CHECK_STRING_RESULT (eel_str_double_underscores (NULL), NULL);
- EEL_CHECK_STRING_RESULT (eel_str_double_underscores (""), "");
- EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("_"), "__");
- EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("foo"), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("foo_bar"), "foo__bar");
- EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("foo_bar_2"), "foo__bar__2");
- EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("_foo"), "__foo");
- EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("foo_"), "foo__");
-
- EEL_CHECK_STRING_RESULT (eel_str_capitalize (NULL), NULL);
- EEL_CHECK_STRING_RESULT (eel_str_capitalize (""), "");
- EEL_CHECK_STRING_RESULT (eel_str_capitalize ("foo"), "Foo");
- EEL_CHECK_STRING_RESULT (eel_str_capitalize ("Foo"), "Foo");
-
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 0), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 1), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 3), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 4), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 5), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 6), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 7), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 0), "a_much_longer_foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 1), "a_much_longer_foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 2), "a_much_longer_foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 3), "a_much_longer_foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 4), "a_much_longer_foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 5), "a...o");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 6), "a...oo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 7), "a_...oo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 8), "a_...foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 9), "a_m...foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 8), "so...ven");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 8), "so...odd");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 9), "som...ven");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 9), "som...odd");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 10), "som...even");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 10), "som..._odd");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 11), "some...even");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 11), "some..._odd");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 12), "some..._even");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 12), "some...g_odd");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 13), "somet..._even");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 13), "something_odd");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 14), "something_even");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 13), "something_odd");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("ääääääääää", 5), "ä...ä");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("あぃいぅうぇえぉ", 7), "あぃ...えぉ");
-
- EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after (NULL, "bar"), NULL);
- EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("", "bar"), "");
- EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("foo", "bar"), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("foo bar", "bar"), "foo ");
- EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("foo bar xxx", "bar"), "foo ");
- EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("bar", "bar"), "");
-
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring (NULL, "foo", NULL), NULL);
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring (NULL, "foo", "bar"), NULL);
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("bar", "foo", NULL), "bar");
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("", "foo", ""), "");
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("", "foo", "bar"), "");
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("bar", "foo", ""), "bar");
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("xxx", "x", "foo"), "foofoofoo");
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("fff", "f", "foo"), "foofoofoo");
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("foofoofoo", "foo", "f"), "fff");
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("foofoofoo", "f", ""), "oooooo");
-
- verify_printf ("%.*s", 2, "foo");
- verify_printf ("%*.*s", 2, 4, "foo");
- verify_printf ("before %5$*1$.*2$s between %6$*3$.*4$d after",
- 4, 5, 6, 7, "foo", G_PI);
- verify_custom ("c1-42- c2-foo-","%N %Y", 42 ,"foo");
- verify_custom ("c1-42- bar c2-foo-","%N %s %Y", 42, "bar" ,"foo");
- verify_custom ("c1-42- bar c2-foo-","%3$N %2$s %1$Y","foo", "bar", 42);
-
+ EEL_CHECK_STRING_RESULT (eel_str_double_underscores (NULL), NULL);
+ EEL_CHECK_STRING_RESULT (eel_str_double_underscores (""), "");
+ EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("_"), "__");
+ EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("foo"), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("foo_bar"), "foo__bar");
+ EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("foo_bar_2"), "foo__bar__2");
+ EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("_foo"), "__foo");
+ EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("foo_"), "foo__");
+
+ EEL_CHECK_STRING_RESULT (eel_str_capitalize (NULL), NULL);
+ EEL_CHECK_STRING_RESULT (eel_str_capitalize (""), "");
+ EEL_CHECK_STRING_RESULT (eel_str_capitalize ("foo"), "Foo");
+ EEL_CHECK_STRING_RESULT (eel_str_capitalize ("Foo"), "Foo");
+
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 0), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 1), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 3), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 4), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 5), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 6), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 7), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 0), "a_much_longer_foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 1), "a_much_longer_foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 2), "a_much_longer_foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 3), "a_much_longer_foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 4), "a_much_longer_foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 5), "a...o");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 6), "a...oo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 7), "a_...oo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 8), "a_...foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 9), "a_m...foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 8), "so...ven");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 8), "so...odd");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 9), "som...ven");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 9), "som...odd");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 10), "som...even");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 10), "som..._odd");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 11), "some...even");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 11), "some..._odd");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 12), "some..._even");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 12), "some...g_odd");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 13), "somet..._even");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 13), "something_odd");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 14), "something_even");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 13), "something_odd");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("ääääääääää", 5), "ä...ä");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("あぃいぅうぇえぉ", 7), "あぃ...えぉ");
+
+ EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after (NULL, "bar"), NULL);
+ EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("", "bar"), "");
+ EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("foo", "bar"), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("foo bar", "bar"), "foo ");
+ EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("foo bar xxx", "bar"), "foo ");
+ EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("bar", "bar"), "");
+
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring (NULL, "foo", NULL), NULL);
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring (NULL, "foo", "bar"), NULL);
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("bar", "foo", NULL), "bar");
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("", "foo", ""), "");
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("", "foo", "bar"), "");
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("bar", "foo", ""), "bar");
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("xxx", "x", "foo"), "foofoofoo");
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("fff", "f", "foo"), "foofoofoo");
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("foofoofoo", "foo", "f"), "fff");
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("foofoofoo", "f", ""), "oooooo");
+
+ verify_printf ("%.*s", 2, "foo");
+ verify_printf ("%*.*s", 2, 4, "foo");
+ verify_printf ("before %5$*1$.*2$s between %6$*3$.*4$d after",
+ 4, 5, 6, 7, "foo", G_PI);
+ verify_custom ("c1-42- c2-foo-", "%N %Y", 42, "foo");
+ verify_custom ("c1-42- bar c2-foo-", "%N %s %Y", 42, "bar", "foo");
+ verify_custom ("c1-42- bar c2-foo-", "%3$N %2$s %1$Y", "foo", "bar", 42);
}
#endif /* !EEL_OMIT_SELF_CHECK */
diff --git a/eel/eel-vfs-extensions.c b/eel/eel-vfs-extensions.c
index 5dd6225c4..9b5b24aa4 100644
--- a/eel/eel-vfs-extensions.c
+++ b/eel/eel-vfs-extensions.c
@@ -1,28 +1,27 @@
-
-/* eel-vfs-extensions.c - gnome-vfs extensions. Its likely some of these will
- be part of gnome-vfs in the future.
-
- Copyright (C) 1999, 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Darin Adler <darin@eazel.com>
- Pavel Cisler <pavel@eazel.com>
- Mike Fleming <mfleming@eazel.com>
- John Sullivan <sullivan@eazel.com>
-*/
+/* eel-vfs-extensions.c - gnome-vfs extensions. Its likely some of these will
+ * be part of gnome-vfs in the future.
+ *
+ * Copyright (C) 1999, 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Darin Adler <darin@eazel.com>
+ * Pavel Cisler <pavel@eazel.com>
+ * Mike Fleming <mfleming@eazel.com>
+ * John Sullivan <sullivan@eazel.com>
+ */
#include <config.h>
#include "eel-vfs-extensions.h"
@@ -41,138 +40,150 @@
gboolean
eel_uri_is_trash (const char *uri)
{
- return g_str_has_prefix (uri, "trash:");
+ return g_str_has_prefix (uri, "trash:");
}
gboolean
eel_uri_is_recent (const char *uri)
{
- return g_str_has_prefix (uri, "recent:");
+ return g_str_has_prefix (uri, "recent:");
}
gboolean
eel_uri_is_search (const char *uri)
{
- return g_str_has_prefix (uri, EEL_SEARCH_URI);
+ return g_str_has_prefix (uri, EEL_SEARCH_URI);
}
gboolean
eel_uri_is_desktop (const char *uri)
{
- return g_str_has_prefix (uri, EEL_DESKTOP_URI);
+ return g_str_has_prefix (uri, EEL_DESKTOP_URI);
}
char *
eel_make_valid_utf8 (const char *name)
{
- GString *string;
- const char *remainder, *invalid;
- int remaining_bytes, valid_bytes;
-
- string = NULL;
- remainder = name;
- remaining_bytes = strlen (name);
-
- while (remaining_bytes != 0) {
- if (g_utf8_validate (remainder, remaining_bytes, &invalid)) {
- break;
- }
- valid_bytes = invalid - remainder;
-
- if (string == NULL) {
- string = g_string_sized_new (remaining_bytes);
- }
- g_string_append_len (string, remainder, valid_bytes);
- g_string_append_c (string, '?');
-
- remaining_bytes -= valid_bytes + 1;
- remainder = invalid + 1;
- }
-
- if (string == NULL) {
- return g_strdup (name);
- }
-
- g_string_append (string, remainder);
- g_string_append (string, _(" (invalid Unicode)"));
- g_assert (g_utf8_validate (string->str, -1, NULL));
-
- return g_string_free (string, FALSE);
+ GString *string;
+ const char *remainder, *invalid;
+ int remaining_bytes, valid_bytes;
+
+ string = NULL;
+ remainder = name;
+ remaining_bytes = strlen (name);
+
+ while (remaining_bytes != 0)
+ {
+ if (g_utf8_validate (remainder, remaining_bytes, &invalid))
+ {
+ break;
+ }
+ valid_bytes = invalid - remainder;
+
+ if (string == NULL)
+ {
+ string = g_string_sized_new (remaining_bytes);
+ }
+ g_string_append_len (string, remainder, valid_bytes);
+ g_string_append_c (string, '?');
+
+ remaining_bytes -= valid_bytes + 1;
+ remainder = invalid + 1;
+ }
+
+ if (string == NULL)
+ {
+ return g_strdup (name);
+ }
+
+ g_string_append (string, remainder);
+ g_string_append (string, _(" (invalid Unicode)"));
+ g_assert (g_utf8_validate (string->str, -1, NULL));
+
+ return g_string_free (string, FALSE);
}
char *
eel_filename_get_extension_offset (const char *filename)
{
- char *end, *end2;
- const char *start;
-
- if (filename == NULL || filename[0] == '\0') {
- return NULL;
- }
-
- /* basename must have at least one char */
- start = filename + 1;
-
- end = strrchr (start, '.');
- if (end == NULL || end[1] == '\0') {
- return NULL;
- }
-
- if (end != start) {
- if (strcmp (end, ".gz") == 0 ||
- strcmp (end, ".bz2") == 0 ||
- strcmp (end, ".sit") == 0 ||
- strcmp (end, ".Z") == 0) {
- end2 = end - 1;
- while (end2 > start &&
- *end2 != '.') {
- end2--;
- }
- if (end2 != start) {
- end = end2;
- }
- }
- }
-
- return end;
+ char *end, *end2;
+ const char *start;
+
+ if (filename == NULL || filename[0] == '\0')
+ {
+ return NULL;
+ }
+
+ /* basename must have at least one char */
+ start = filename + 1;
+
+ end = strrchr (start, '.');
+ if (end == NULL || end[1] == '\0')
+ {
+ return NULL;
+ }
+
+ if (end != start)
+ {
+ if (strcmp (end, ".gz") == 0 ||
+ strcmp (end, ".bz2") == 0 ||
+ strcmp (end, ".sit") == 0 ||
+ strcmp (end, ".Z") == 0)
+ {
+ end2 = end - 1;
+ while (end2 > start &&
+ *end2 != '.')
+ {
+ end2--;
+ }
+ if (end2 != start)
+ {
+ end = end2;
+ }
+ }
+ }
+
+ return end;
}
char *
-eel_filename_strip_extension (const char * filename_with_extension)
+eel_filename_strip_extension (const char *filename_with_extension)
{
- char *filename, *end;
+ char *filename, *end;
- if (filename_with_extension == NULL) {
- return NULL;
- }
+ if (filename_with_extension == NULL)
+ {
+ return NULL;
+ }
- filename = g_strdup (filename_with_extension);
- end = eel_filename_get_extension_offset (filename);
+ filename = g_strdup (filename_with_extension);
+ end = eel_filename_get_extension_offset (filename);
- if (end && end != filename) {
- *end = '\0';
- }
+ if (end && end != filename)
+ {
+ *end = '\0';
+ }
- return filename;
+ return filename;
}
void
-eel_filename_get_rename_region (const char *filename,
- int *start_offset,
- int *end_offset)
+eel_filename_get_rename_region (const char *filename,
+ int *start_offset,
+ int *end_offset)
{
- char *filename_without_extension;
+ char *filename_without_extension;
- g_return_if_fail (start_offset != NULL);
- g_return_if_fail (end_offset != NULL);
+ g_return_if_fail (start_offset != NULL);
+ g_return_if_fail (end_offset != NULL);
- *start_offset = 0;
- *end_offset = 0;
+ *start_offset = 0;
+ *end_offset = 0;
- g_return_if_fail (filename != NULL);
+ g_return_if_fail (filename != NULL);
- filename_without_extension = eel_filename_strip_extension (filename);
- *end_offset = g_utf8_strlen (filename_without_extension, -1);
+ filename_without_extension = eel_filename_strip_extension (filename);
+ *end_offset = g_utf8_strlen (filename_without_extension, -1);
- g_free (filename_without_extension);
+ g_free (filename_without_extension);
}