diff options
author | Chris Lahey <clahey@src.gnome.org> | 2000-01-14 06:01:23 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2000-01-14 06:01:23 +0800 |
commit | f5347f59ff008ebc53f456cfcd4b8c58dead29c5 (patch) | |
tree | 1bfa9616fde11bbc40d7bf80557caf8f0429a84c | |
parent | 21c698ec023314751227247e4bef1d68a78a21ea (diff) | |
download | gsoc2013-evolution-f5347f59ff008ebc53f456cfcd4b8c58dead29c5.tar gsoc2013-evolution-f5347f59ff008ebc53f456cfcd4b8c58dead29c5.tar.gz gsoc2013-evolution-f5347f59ff008ebc53f456cfcd4b8c58dead29c5.tar.bz2 gsoc2013-evolution-f5347f59ff008ebc53f456cfcd4b8c58dead29c5.tar.lz gsoc2013-evolution-f5347f59ff008ebc53f456cfcd4b8c58dead29c5.tar.xz gsoc2013-evolution-f5347f59ff008ebc53f456cfcd4b8c58dead29c5.tar.zst gsoc2013-evolution-f5347f59ff008ebc53f456cfcd4b8c58dead29c5.zip |
e_canvas_item_move_absolute is just a helper function not supplied by the
* widgets/e-canvas-utils.c, widgets/e-canvas-utils.h:
e_canvas_item_move_absolute is just a helper function not supplied
by the gnome_canvas.[ch] I put it here so that multiple items can
use it.
* widgets/e-reflow.c, widgets/e-reflow.h: This item contains a
number of other items and places them into multiple columns. The
items contained must support a number of arguments and signals to
allow the reflow to interact with them.
* widgets/test-reflow.c: This is a test program for e-reflow.
* widgets/e-text.c, widgets/e-text.h: Added properly drawn
selected text. Added some preliminary code for X selection
handling and cut & paste.
* widgets/e-minicard.c, widgets/e-minicard.h: Added ARG_HAS_FOCUS
handling. Made label display random for more interesting tests of
multiple cards. Tweaked sizing information for better display.
* widgets/e-minicard-label.c, widgets/e-minicard-label.h: Added
ARG_HAS_FOCUS handling.
* widgets/Makefile.am: Added the reflow test and reflow files.
svn path=/trunk/; revision=1566
44 files changed, 4114 insertions, 193 deletions
@@ -1,3 +1,30 @@ +2000-01-13 Christopher James Lahey <clahey@helixcode.com> + + * widgets/e-canvas-utils.c, widgets/e-canvas-utils.h: + e_canvas_item_move_absolute is just a helper function not supplied + by the gnome_canvas.[ch] I put it here so that multiple items can + use it. + + * widgets/e-reflow.c, widgets/e-reflow.h: This item contains a + number of other items and places them into multiple columns. The + items contained must support a number of arguments and signals to + allow the reflow to interact with them. + + * widgets/test-reflow.c: This is a test program for e-reflow. + + * widgets/e-text.c, widgets/e-text.h: Added properly drawn + selected text. Added some preliminary code for X selection + handling and cut & paste. + + * widgets/e-minicard.c, widgets/e-minicard.h: Added ARG_HAS_FOCUS + handling. Made label display random for more interesting tests of + multiple cards. Tweaked sizing information for better display. + + * widgets/e-minicard-label.c, widgets/e-minicard-label.h: Added + ARG_HAS_FOCUS handling. + + * widgets/Makefile.am: Added the reflow test and reflow files. + 2000-01-12 bertrand <bertrand@helixcode.com> * camel/providers/mbox/camel-mbox-parser.h (camel_mbox_parse_file): @@ -28,8 +55,7 @@ disabled gmime-rfc2047 as it depends on libunicode and is not used for the moment. - -2000-01-12 <clahey@galapagos.helixcode.com> +2000-01-12 Christopher James Lahey <clahey@helixcode.com> * widgets/e-minicard.c, widgets/e-minicard.h: Added a resize signal for when the card changes height. Made it so that when you @@ -43,7 +69,7 @@ * widgets/Makefile.am: Removed an extraneous build target. -2000-01-11 <clahey@galapagos.helixcode.com> +2000-01-11 Christopher James Lahey <clahey@helixcode.com> * widgets/e-text-event-processor-emacs-like.c: Blocked the tab key from getting inserted into the buffer since the renderer doesn't diff --git a/addressbook/gui/minicard/e-minicard-label.c b/addressbook/gui/minicard/e-minicard-label.c index 9efdd0ba65..a550031123 100644 --- a/addressbook/gui/minicard/e-minicard-label.c +++ b/addressbook/gui/minicard/e-minicard-label.c @@ -48,6 +48,7 @@ enum { ARG_0, ARG_WIDTH, ARG_HEIGHT, + ARG_HAS_FOCUS, ARG_FIELD, ARG_FIELDNAME }; @@ -103,6 +104,8 @@ e_minicard_label_class_init (EMinicardLabelClass *klass) GTK_ARG_READWRITE, ARG_WIDTH); gtk_object_add_arg_type ("EMinicardLabel::height", GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_HEIGHT); + gtk_object_add_arg_type ("EMinicardLabel::has_focus", GTK_TYPE_BOOL, + GTK_ARG_READWRITE, ARG_HAS_FOCUS); gtk_object_add_arg_type ("EMinicardLabel::field", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_FIELD); gtk_object_add_arg_type ("EMinicardLabel::fieldname", GTK_TYPE_STRING, @@ -148,6 +151,10 @@ e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) _update_label( e_minicard_label ); gnome_canvas_item_request_update (item); break; + case ARG_HAS_FOCUS: + if (e_minicard_label->field && GTK_VALUE_BOOL(*arg)) + gnome_canvas_item_grab_focus(e_minicard_label->field); + break; case ARG_FIELD: if ( e_minicard_label->field ) gnome_canvas_item_set( e_minicard_label->field, "text", GTK_VALUE_STRING (*arg), NULL ); @@ -178,6 +185,9 @@ e_minicard_label_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) case ARG_HEIGHT: GTK_VALUE_DOUBLE (*arg) = e_minicard_label->height; break; + case ARG_HAS_FOCUS: + GTK_VALUE_BOOL (*arg) = e_minicard_label->has_focus; + break; case ARG_FIELD: if ( e_minicard_label->field ) { @@ -317,6 +327,7 @@ e_minicard_label_event (GnomeCanvasItem *item, GdkEvent *event) "outline_color", "grey50", "fill_color", "grey90", NULL ); + e_minicard_label->has_focus = TRUE; } else { @@ -324,6 +335,7 @@ e_minicard_label_event (GnomeCanvasItem *item, GdkEvent *event) "outline_color", NULL, "fill_color", NULL, NULL ); + e_minicard_label->has_focus = FALSE; } } break; diff --git a/addressbook/gui/minicard/e-minicard-label.h b/addressbook/gui/minicard/e-minicard-label.h index bbaca884ac..ddbe7ab191 100644 --- a/addressbook/gui/minicard/e-minicard-label.h +++ b/addressbook/gui/minicard/e-minicard-label.h @@ -62,6 +62,8 @@ struct _EMinicardLabel GnomeCanvasItem *rect; char *fieldname_text; char *field_text; + + gboolean has_focus; }; struct _EMinicardLabelClass diff --git a/addressbook/gui/minicard/e-minicard.c b/addressbook/gui/minicard/e-minicard.c index 01c326d568..52d241d11e 100644 --- a/addressbook/gui/minicard/e-minicard.c +++ b/addressbook/gui/minicard/e-minicard.c @@ -49,6 +49,7 @@ enum { ARG_0, ARG_WIDTH, ARG_HEIGHT, + ARG_HAS_FOCUS, ARG_CARD }; @@ -103,6 +104,8 @@ e_minicard_class_init (EMinicardClass *klass) GTK_ARG_READWRITE, ARG_WIDTH); gtk_object_add_arg_type ("EMinicard::height", GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_HEIGHT); + gtk_object_add_arg_type ("EMinicard::has_focus", GTK_TYPE_BOOL, + GTK_ARG_READWRITE, ARG_HAS_FOCUS); gtk_object_add_arg_type ("EMinicard::card", GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_CARD); @@ -124,6 +127,7 @@ e_minicard_init (EMinicard *minicard) minicard->fields = NULL; minicard->width = 10; minicard->height = 10; + minicard->has_focus = FALSE; } static void @@ -141,6 +145,14 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) _update_card(e_minicard); gnome_canvas_item_request_update (item); break; + case ARG_HAS_FOCUS: + if (e_minicard->fields) + gnome_canvas_item_set(GNOME_CANVAS_ITEM(e_minicard->fields->data), + "has_focus", GTK_VALUE_BOOL(*arg), + NULL); + else + gnome_canvas_item_grab_focus(GNOME_CANVAS_ITEM(e_minicard)); + break; case ARG_CARD: /* e_minicard->card = GTK_VALUE_POINTER (*arg); _update_card(e_minicard); @@ -163,6 +175,9 @@ e_minicard_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) case ARG_HEIGHT: GTK_VALUE_DOUBLE (*arg) = e_minicard->height; break; + case ARG_HAS_FOCUS: + GTK_VALUE_BOOL (*arg) = e_minicard->has_focus; + break; case ARG_CARD: /* GTK_VALUE_POINTER (*arg) = e_minicard->card; */ break; @@ -218,42 +233,61 @@ e_minicard_realize (GnomeCanvasItem *item) "fill_color", "black", "text", "Chris Lahey", NULL ); - - gtk_signal_connect(GTK_OBJECT(e_minicard->header_text), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_minicard); - - new_item = gnome_canvas_item_new( group, - e_minicard_label_get_type(), - "x", (double) 2, - "y", e_minicard->height, - "width", e_minicard->width - 4, - "fieldname", "Full Name:", - "field", "Christopher James Lahey", - NULL ); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); - - gtk_signal_connect(GTK_OBJECT(new_item), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_minicard); - new_item = gnome_canvas_item_new( group, - e_minicard_label_get_type(), - "x", (double) 2, - "y", e_minicard->height, - "width", e_minicard->width - 4.0, - "fieldname", "Email:", - "field", "clahey@helixcode.com", - NULL ); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); - - gtk_signal_connect(GTK_OBJECT(new_item), + gtk_signal_connect(GTK_OBJECT(e_minicard->header_text), "resize", GTK_SIGNAL_FUNC(_resize), (gpointer) e_minicard); + if ( rand() % 2 ) { + new_item = gnome_canvas_item_new( group, + e_minicard_label_get_type(), + "x", (double) 2, + "y", e_minicard->height, + "width", e_minicard->width - 4, + "fieldname", "Full Name:", + "field", "Christopher James Lahey", + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + gtk_signal_connect(GTK_OBJECT(new_item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); + } + if (rand() % 2) { + new_item = gnome_canvas_item_new( group, + e_minicard_label_get_type(), + "x", (double) 2, + "y", e_minicard->height, + "width", e_minicard->width - 4, + "fieldname", "Address:", + "field", "100 Main St\nHome town, USA", + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + gtk_signal_connect(GTK_OBJECT(new_item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); + } + + if (rand() % 2) { + new_item = gnome_canvas_item_new( group, + e_minicard_label_get_type(), + "x", (double) 2, + "y", e_minicard->height, + "width", e_minicard->width - 4.0, + "fieldname", "Email:", + "field", "clahey@helixcode.com", + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + gtk_signal_connect(GTK_OBJECT(new_item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); + } _update_card( e_minicard ); if (!item->canvas->aa) { @@ -298,6 +332,7 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) gnome_canvas_item_set( e_minicard->header_text, "fill_color", "white", NULL ); + e_minicard->has_focus = TRUE; } else { @@ -305,11 +340,12 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) "outline_color", NULL, NULL ); gnome_canvas_item_set( e_minicard->header_rect, - "fill_color", "grey50", + "fill_color", "grey70", NULL ); gnome_canvas_item_set( e_minicard->header_text, "fill_color", "black", NULL ); + e_minicard->has_focus = FALSE; } } break; @@ -317,15 +353,21 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) if (event->key.length == 1 && event->key.string[0] == '\t') { GList *list; for (list = e_minicard->fields; list; list = list->next) { - EMinicardLabel *label = E_MINICARD_LABEL (list->data); - if (label->field == label->field->canvas->focused_item) { + GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); + gboolean has_focus; + gtk_object_get(GTK_OBJECT(item), + "has_focus", &has_focus, + NULL); + if (has_focus) { if (event->key.state & GDK_SHIFT_MASK) list = list->prev; else list = list->next; if (list) { - label = E_MINICARD_LABEL (list->data); - gnome_canvas_item_grab_focus(label->field); + item = GNOME_CANVAS_ITEM (list->data); + gnome_canvas_item_set(item, + "has_focus", TRUE, + NULL); return 1; } else { return 0; @@ -357,7 +399,7 @@ _update_card( EMinicard *e_minicard ) "text_height", &text_height, NULL ); - e_minicard->height = text_height + 12.0; + e_minicard->height = text_height + 10.0; gnome_canvas_item_set( e_minicard->header_rect, "y2", text_height + 9.0, @@ -387,7 +429,7 @@ _update_card( EMinicard *e_minicard ) "y2", (double) e_minicard->height - 1.0, NULL ); gnome_canvas_item_set( e_minicard->header_rect, - "x2", (double) e_minicard->width - 4.0, + "x2", (double) e_minicard->width - 3.0, NULL ); gnome_canvas_item_set( e_minicard->header_text, "clip_width", (double) e_minicard->width - 12, diff --git a/addressbook/gui/minicard/e-minicard.h b/addressbook/gui/minicard/e-minicard.h index 43e7d8307f..98f6ea124a 100644 --- a/addressbook/gui/minicard/e-minicard.h +++ b/addressbook/gui/minicard/e-minicard.h @@ -61,6 +61,8 @@ struct _EMinicard GnomeCanvasItem *header_text; GList *fields; /* Of type GnomeCanvasItem. */ + gboolean has_focus; + double width; double height; }; @@ -69,7 +71,7 @@ struct _EMinicardClass { GnomeCanvasGroupClass parent_class; - void (* resize) (EMinicard *text); + void (* resize) (EMinicard *minicard); }; diff --git a/addressbook/gui/minicard/e-reflow.c b/addressbook/gui/minicard/e-reflow.c new file mode 100644 index 0000000000..ce2e92e530 --- /dev/null +++ b/addressbook/gui/minicard/e-reflow.c @@ -0,0 +1,438 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-reflow.c + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <gnome.h> +#include "e-reflow.h" +#include "e-canvas-utils.h" +static void e_reflow_init (EReflow *card); +static void e_reflow_class_init (EReflowClass *klass); +static void e_reflow_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); +static void e_reflow_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); +static gboolean e_reflow_event (GnomeCanvasItem *item, GdkEvent *event); +static void e_reflow_realize (GnomeCanvasItem *item); +static void e_reflow_unrealize (GnomeCanvasItem *item); +static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable, + int x, int y, int width, int height); + +static void _update_reflow ( EReflow *reflow ); +static void _resize( GtkObject *object, gpointer data ); +static void _queue_reflow(EReflow *e_reflow); + +static GnomeCanvasGroupClass *parent_class = NULL; + +enum { + E_REFLOW_RESIZE, + E_REFLOW_LAST_SIGNAL +}; + +static guint e_reflow_signals[E_REFLOW_LAST_SIGNAL] = { 0 }; + +/* The arguments we take */ +enum { + ARG_0, + ARG_WIDTH, + ARG_HEIGHT +}; + +GtkType +e_reflow_get_type (void) +{ + static GtkType reflow_type = 0; + + if (!reflow_type) + { + static const GtkTypeInfo reflow_info = + { + "EReflow", + sizeof (EReflow), + sizeof (EReflowClass), + (GtkClassInitFunc) e_reflow_class_init, + (GtkObjectInitFunc) e_reflow_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + reflow_type = gtk_type_unique (gnome_canvas_group_get_type (), &reflow_info); + } + + return reflow_type; +} + +static void +e_reflow_class_init (EReflowClass *klass) +{ + GtkObjectClass *object_class; + GnomeCanvasItemClass *item_class; + + object_class = (GtkObjectClass*) klass; + item_class = (GnomeCanvasItemClass *) klass; + + parent_class = gtk_type_class (gnome_canvas_group_get_type ()); + + e_reflow_signals[E_REFLOW_RESIZE] = + gtk_signal_new ("resize", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (EReflowClass, resize), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + gtk_object_class_add_signals (object_class, e_reflow_signals, E_REFLOW_LAST_SIGNAL); + + gtk_object_add_arg_type ("EReflow::width", GTK_TYPE_DOUBLE, + GTK_ARG_READABLE, ARG_WIDTH); + gtk_object_add_arg_type ("EReflow::height", GTK_TYPE_DOUBLE, + GTK_ARG_READWRITE, ARG_HEIGHT); + + object_class->set_arg = e_reflow_set_arg; + object_class->get_arg = e_reflow_get_arg; + /* object_class->destroy = e_reflow_destroy; */ + + /* GnomeCanvasItem method overrides */ + item_class->event = e_reflow_event; + item_class->realize = e_reflow_realize; + item_class->unrealize = e_reflow_unrealize; + /* item_class->draw = e_reflow_draw;*/ +} + +static void +e_reflow_init (EReflow *reflow) +{ + /* reflow->card = NULL;*/ + reflow->items = NULL; + reflow->columns = NULL; + reflow->column_width = 150; + + reflow->width = 10; + reflow->height = 10; + reflow->idle = 0; +} + +static void +e_reflow_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) +{ + GnomeCanvasItem *item; + EReflow *e_reflow; + + item = GNOME_CANVAS_ITEM (o); + e_reflow = E_REFLOW (o); + + switch (arg_id){ + case ARG_HEIGHT: + e_reflow->height = GTK_VALUE_DOUBLE (*arg); + _update_reflow(e_reflow); + gnome_canvas_item_request_update (item); + break; + } +} + +static void +e_reflow_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) +{ + EReflow *e_reflow; + + e_reflow = E_REFLOW (object); + + switch (arg_id) { + case ARG_WIDTH: + GTK_VALUE_DOUBLE (*arg) = e_reflow->width; + break; + case ARG_HEIGHT: + GTK_VALUE_DOUBLE (*arg) = e_reflow->height; + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} + +static void +e_reflow_realize (GnomeCanvasItem *item) +{ + EReflow *e_reflow; + GnomeCanvasGroup *group; + GList *list; + + e_reflow = E_REFLOW (item); + group = GNOME_CANVAS_GROUP( item ); + + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) + (* GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) (item); + + for(list = e_reflow->items; list; list = g_list_next(list)) { + GnomeCanvasItem *item = GNOME_CANVAS_ITEM(list->data); + gtk_signal_connect(GTK_OBJECT(item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_reflow); + gnome_canvas_item_set(item, + "width", (double) e_reflow->column_width, + NULL); + } + + _update_reflow( e_reflow ); + + if (!item->canvas->aa) { + } +} + +static void +e_reflow_unrealize (GnomeCanvasItem *item) +{ + EReflow *e_reflow; + + e_reflow = E_REFLOW (item); + + if (!item->canvas->aa) + { + } + + g_list_free (e_reflow->items); + g_list_free (e_reflow->columns); + + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) + (* GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) (item); +} + +static gboolean +e_reflow_event (GnomeCanvasItem *item, GdkEvent *event) +{ + EReflow *e_reflow; + + e_reflow = E_REFLOW (item); + + switch( event->type ) + { + case GDK_KEY_PRESS: + if (event->key.length == 1 && event->key.string[0] == '\t') { + GList *list; + for (list = e_reflow->items; list; list = list->next) { + GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); + gboolean has_focus; + gtk_object_get(GTK_OBJECT(item), + "has_focus", &has_focus, + NULL); + if (has_focus) { + if (event->key.state & GDK_SHIFT_MASK) + list = list->prev; + else + list = list->next; + if (list) { + item = GNOME_CANVAS_ITEM(list->data); + gnome_canvas_item_set(item, + "has_focus", TRUE, + NULL); + return 1; + } else { + return 0; + } + } + } + } + default: + break; + } + + if (GNOME_CANVAS_ITEM_CLASS( parent_class )->event) + return (* GNOME_CANVAS_ITEM_CLASS( parent_class )->event) (item, event); + else + return 0; +} + +void +e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item) +{ + e_reflow->items = g_list_append(e_reflow->items, item); + if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { + gtk_signal_connect(GTK_OBJECT(item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_reflow); + gnome_canvas_item_set(item, + "width", (double) e_reflow->column_width, + NULL); + _queue_reflow(e_reflow); + } + +} +#if 0 +static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable, + int x, int y, int width, int height) +{ + int x_rect, y_rect, width_rect, height_rect; + gint running_width; + EReflow *e_reflow = E_REFLOW(item); + int i; + + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->draw) + GNOME_CANVAS_ITEM_CLASS(parent_class)->draw (item, drawable, x, y, width, height); + + running_width = 7 + e_reflow->column_width + 7; + x_rect = running_width; + y_rect = 7; + width_rect = 2; + height_rect = e_reflow->height - 14; + + for (i = 0; i < e_reflow->column_count - 1; i++) { + x_rect = running_width; + gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style, + drawable, + GTK_STATE_ACTIVE, + GTK_SHADOW_NONE, + NULL, + GTK_WIDGET(item->canvas), + "reflow", + x_rect - x, + y_rect - x, + width_rect, + height_rect); + running_width += 2 + 7 + e_reflow->column_width + 7; + } +} +#endif + +static void +_reflow( EReflow *e_reflow ) +{ + int running_height; + GList *list; + double item_height; + + if (e_reflow->columns) { + g_list_free (e_reflow->columns); + e_reflow->columns = NULL; + } + + e_reflow->column_count = 0; + + if (e_reflow->items == NULL) { + e_reflow->columns = NULL; + e_reflow->column_count = 1; + return; + } + + list = e_reflow->items; + + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + running_height = 7 + item_height + 7; + e_reflow->columns = g_list_append (e_reflow->columns, list); + e_reflow->column_count = 1; + + list = g_list_next(list); + + for ( ; list; list = g_list_next(list)) { + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + if (running_height + item_height + 7 > e_reflow->height) { + running_height = 7 + item_height + 7; + e_reflow->columns = g_list_append (e_reflow->columns, list); + e_reflow->column_count ++; + } else { + running_height += item_height + 7; + } + } +} + +static void +_update_reflow( EReflow *e_reflow ) +{ + if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { + + gint old_width; + gint running_width; + + _reflow (e_reflow); + + old_width = e_reflow->width; + + running_width = 7; + + if (e_reflow->items == NULL) { + } else { + GList *list; + GList *next_column; + gdouble item_height; + gint running_height; + + running_height = 7; + + list = e_reflow->items; + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), + (double) running_width, + (double) running_height); + running_height += item_height + 7; + next_column = g_list_next(e_reflow->columns); + list = g_list_next(list); + + for( ; list; list = g_list_next(list)) { + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + + if (next_column && (next_column->data == list)) { + next_column = g_list_next (next_column); + running_height = 7; + running_width += e_reflow->column_width + 7 + 2 + 7; + } + e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), + (double) running_width, + (double) running_height); + + running_height += item_height + 7; + } + + } + e_reflow->width = running_width + e_reflow->column_width + 7; + if (old_width != e_reflow->width) + gtk_signal_emit_by_name (GTK_OBJECT (e_reflow), "resize"); + } +} + + +static gboolean +_idle_reflow(gpointer data) +{ + EReflow *e_reflow = E_REFLOW(data); + _update_reflow(e_reflow); + e_reflow->idle = 0; + return FALSE; +} + +static void +_queue_reflow(EReflow *e_reflow) +{ + if (e_reflow->idle == 0) + e_reflow->idle = g_idle_add(_idle_reflow, e_reflow); +} + +static void +_resize( GtkObject *object, gpointer data ) +{ + _queue_reflow(E_REFLOW(data)); +} diff --git a/addressbook/gui/minicard/e-reflow.h b/addressbook/gui/minicard/e-reflow.h new file mode 100644 index 0000000000..0d0ab4251a --- /dev/null +++ b/addressbook/gui/minicard/e-reflow.h @@ -0,0 +1,88 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* e-reflow.h + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef __E_REFLOW_H__ +#define __E_REFLOW_H__ + +#include <gnome.h> + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +/* EReflow - A canvas item container. + * + * The following arguments are available: + * + * name type read/write description + * -------------------------------------------------------------------------------- + * width double R width of the reflow + * height double RW height of the reflow + */ + +#define E_REFLOW_TYPE (e_reflow_get_type ()) +#define E_REFLOW(obj) (GTK_CHECK_CAST ((obj), E_REFLOW_TYPE, EReflow)) +#define E_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_REFLOW_TYPE, EReflowClass)) +#define E_IS_REFLOW(obj) (GTK_CHECK_TYPE ((obj), E_REFLOW_TYPE)) +#define E_IS_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_REFLOW_TYPE)) + + +typedef struct _EReflow EReflow; +typedef struct _EReflowClass EReflowClass; + +struct _EReflow +{ + GnomeCanvasGroup parent; + + /* item specific fields */ + /* EBook *book; */ + + GList *items; /* Of type GnomeCanvasItem */ + GList *columns; /* Of type GList pointing to type GnomeCanvasItem (points into items) */ + gint column_count; /* Number of columnns */ + + double width; + double height; + + double column_width; + + int idle; +}; + +struct _EReflowClass +{ + GnomeCanvasGroupClass parent_class; + + void (* resize) (EReflow *reflow); +}; + +/* To be added to a reflow, an item must have the arguments "x", "y", + and "width" as Read/Write arguments and "height" as a Read Only + argument. It must also have a "resize" signal. */ +void e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item); +GtkType e_reflow_get_type (void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __E_REFLOW_H__ */ diff --git a/addressbook/gui/minicard/test-reflow.c b/addressbook/gui/minicard/test-reflow.c new file mode 100644 index 0000000000..f03232c72d --- /dev/null +++ b/addressbook/gui/minicard/test-reflow.c @@ -0,0 +1,136 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* test-reflow.c + * + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + + + +#include "config.h" + +#include <gnome.h> +#include "e-reflow.h" +#include "e-minicard.h" + +/* This is a horrible thing to do, but it is just a test. */ +GnomeCanvasItem *reflow; +GnomeCanvasItem *rect; + +static void destroy_callback(GtkWidget *app, gpointer data) +{ + exit(0); +} + +static void allocate_callback(GtkWidget *canvas, GtkAllocation *allocation, gpointer data) +{ + double width; + gnome_canvas_item_set( reflow, + "height", (double) allocation->height, + NULL ); + gtk_object_get(GTK_OBJECT(reflow), + "width", &width, + NULL); + width = MAX(width, allocation->width); + gnome_canvas_set_scroll_region(GNOME_CANVAS( canvas ), 0, 0, width, allocation->height ); + gnome_canvas_item_set( rect, + "x2", (double) width, + "y2", (double) allocation->height, + NULL ); +} + +static void about_callback( GtkWidget *widget, gpointer data ) +{ + + const gchar *authors[] = + { + "Christopher James Lahey <clahey@umich.edu>", + NULL + }; + + GtkWidget *about = + gnome_about_new ( _( "Reflow Test" ), VERSION, + _( "Copyright (C) 2000, Helix Code, Inc." ), + authors, + _( "This should test the reflow canvas item" ), + NULL); + gtk_widget_show (about); +} + +int main( int argc, char *argv[] ) +{ + GtkWidget *app; + GtkWidget *canvas; + GtkWidget *vbox; + GtkWidget *scrollbar; + int i; + + /* bindtextdomain (PACKAGE, GNOMELOCALEDIR); + textdomain (PACKAGE);*/ + + gnome_init( "Reflow Test", VERSION, argc, argv); + app = gnome_app_new("Reflow Test", NULL); + + vbox = gtk_vbox_new(FALSE, 0); + + canvas = gnome_canvas_new(); + rect = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), + gnome_canvas_rect_get_type(), + "x1", (double) 0, + "y1", (double) 0, + "x2", (double) 100, + "y2", (double) 100, + "fill_color", "white", + NULL ); + reflow = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), + e_reflow_get_type(), + "x", (double) 0, + "y", (double) 0, + "height", (double) 100, + NULL ); + for ( i = 0; i < 200; i++ ) + { + GnomeCanvasItem *item; + item = gnome_canvas_item_new( GNOME_CANVAS_GROUP(reflow), + e_minicard_get_type(), + NULL); + e_reflow_add_item(E_REFLOW(reflow), item); + } + gnome_canvas_set_scroll_region ( GNOME_CANVAS( canvas ), + 0, 0, + 100, 100 ); + + gtk_box_pack_start(GTK_BOX(vbox), canvas, TRUE, TRUE, 0); + + scrollbar = gtk_hscrollbar_new(gtk_layout_get_hadjustment(GTK_LAYOUT(canvas))); + + gtk_box_pack_start(GTK_BOX(vbox), scrollbar, FALSE, FALSE, 0); + + gnome_app_set_contents( GNOME_APP( app ), vbox ); + + /* Connect the signals */ + gtk_signal_connect( GTK_OBJECT( app ), "destroy", + GTK_SIGNAL_FUNC( destroy_callback ), + ( gpointer ) app ); + + gtk_signal_connect( GTK_OBJECT( canvas ), "size_allocate", + GTK_SIGNAL_FUNC( allocate_callback ), + ( gpointer ) app ); + + gtk_widget_show_all( app ); + + gtk_main(); + + /* Not reached. */ + return 0; +} diff --git a/addressbook/gui/widgets/e-minicard-label.c b/addressbook/gui/widgets/e-minicard-label.c index 9efdd0ba65..a550031123 100644 --- a/addressbook/gui/widgets/e-minicard-label.c +++ b/addressbook/gui/widgets/e-minicard-label.c @@ -48,6 +48,7 @@ enum { ARG_0, ARG_WIDTH, ARG_HEIGHT, + ARG_HAS_FOCUS, ARG_FIELD, ARG_FIELDNAME }; @@ -103,6 +104,8 @@ e_minicard_label_class_init (EMinicardLabelClass *klass) GTK_ARG_READWRITE, ARG_WIDTH); gtk_object_add_arg_type ("EMinicardLabel::height", GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_HEIGHT); + gtk_object_add_arg_type ("EMinicardLabel::has_focus", GTK_TYPE_BOOL, + GTK_ARG_READWRITE, ARG_HAS_FOCUS); gtk_object_add_arg_type ("EMinicardLabel::field", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_FIELD); gtk_object_add_arg_type ("EMinicardLabel::fieldname", GTK_TYPE_STRING, @@ -148,6 +151,10 @@ e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) _update_label( e_minicard_label ); gnome_canvas_item_request_update (item); break; + case ARG_HAS_FOCUS: + if (e_minicard_label->field && GTK_VALUE_BOOL(*arg)) + gnome_canvas_item_grab_focus(e_minicard_label->field); + break; case ARG_FIELD: if ( e_minicard_label->field ) gnome_canvas_item_set( e_minicard_label->field, "text", GTK_VALUE_STRING (*arg), NULL ); @@ -178,6 +185,9 @@ e_minicard_label_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) case ARG_HEIGHT: GTK_VALUE_DOUBLE (*arg) = e_minicard_label->height; break; + case ARG_HAS_FOCUS: + GTK_VALUE_BOOL (*arg) = e_minicard_label->has_focus; + break; case ARG_FIELD: if ( e_minicard_label->field ) { @@ -317,6 +327,7 @@ e_minicard_label_event (GnomeCanvasItem *item, GdkEvent *event) "outline_color", "grey50", "fill_color", "grey90", NULL ); + e_minicard_label->has_focus = TRUE; } else { @@ -324,6 +335,7 @@ e_minicard_label_event (GnomeCanvasItem *item, GdkEvent *event) "outline_color", NULL, "fill_color", NULL, NULL ); + e_minicard_label->has_focus = FALSE; } } break; diff --git a/addressbook/gui/widgets/e-minicard-label.h b/addressbook/gui/widgets/e-minicard-label.h index bbaca884ac..ddbe7ab191 100644 --- a/addressbook/gui/widgets/e-minicard-label.h +++ b/addressbook/gui/widgets/e-minicard-label.h @@ -62,6 +62,8 @@ struct _EMinicardLabel GnomeCanvasItem *rect; char *fieldname_text; char *field_text; + + gboolean has_focus; }; struct _EMinicardLabelClass diff --git a/addressbook/gui/widgets/e-minicard.c b/addressbook/gui/widgets/e-minicard.c index 01c326d568..52d241d11e 100644 --- a/addressbook/gui/widgets/e-minicard.c +++ b/addressbook/gui/widgets/e-minicard.c @@ -49,6 +49,7 @@ enum { ARG_0, ARG_WIDTH, ARG_HEIGHT, + ARG_HAS_FOCUS, ARG_CARD }; @@ -103,6 +104,8 @@ e_minicard_class_init (EMinicardClass *klass) GTK_ARG_READWRITE, ARG_WIDTH); gtk_object_add_arg_type ("EMinicard::height", GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_HEIGHT); + gtk_object_add_arg_type ("EMinicard::has_focus", GTK_TYPE_BOOL, + GTK_ARG_READWRITE, ARG_HAS_FOCUS); gtk_object_add_arg_type ("EMinicard::card", GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_CARD); @@ -124,6 +127,7 @@ e_minicard_init (EMinicard *minicard) minicard->fields = NULL; minicard->width = 10; minicard->height = 10; + minicard->has_focus = FALSE; } static void @@ -141,6 +145,14 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) _update_card(e_minicard); gnome_canvas_item_request_update (item); break; + case ARG_HAS_FOCUS: + if (e_minicard->fields) + gnome_canvas_item_set(GNOME_CANVAS_ITEM(e_minicard->fields->data), + "has_focus", GTK_VALUE_BOOL(*arg), + NULL); + else + gnome_canvas_item_grab_focus(GNOME_CANVAS_ITEM(e_minicard)); + break; case ARG_CARD: /* e_minicard->card = GTK_VALUE_POINTER (*arg); _update_card(e_minicard); @@ -163,6 +175,9 @@ e_minicard_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) case ARG_HEIGHT: GTK_VALUE_DOUBLE (*arg) = e_minicard->height; break; + case ARG_HAS_FOCUS: + GTK_VALUE_BOOL (*arg) = e_minicard->has_focus; + break; case ARG_CARD: /* GTK_VALUE_POINTER (*arg) = e_minicard->card; */ break; @@ -218,42 +233,61 @@ e_minicard_realize (GnomeCanvasItem *item) "fill_color", "black", "text", "Chris Lahey", NULL ); - - gtk_signal_connect(GTK_OBJECT(e_minicard->header_text), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_minicard); - - new_item = gnome_canvas_item_new( group, - e_minicard_label_get_type(), - "x", (double) 2, - "y", e_minicard->height, - "width", e_minicard->width - 4, - "fieldname", "Full Name:", - "field", "Christopher James Lahey", - NULL ); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); - - gtk_signal_connect(GTK_OBJECT(new_item), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_minicard); - new_item = gnome_canvas_item_new( group, - e_minicard_label_get_type(), - "x", (double) 2, - "y", e_minicard->height, - "width", e_minicard->width - 4.0, - "fieldname", "Email:", - "field", "clahey@helixcode.com", - NULL ); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); - - gtk_signal_connect(GTK_OBJECT(new_item), + gtk_signal_connect(GTK_OBJECT(e_minicard->header_text), "resize", GTK_SIGNAL_FUNC(_resize), (gpointer) e_minicard); + if ( rand() % 2 ) { + new_item = gnome_canvas_item_new( group, + e_minicard_label_get_type(), + "x", (double) 2, + "y", e_minicard->height, + "width", e_minicard->width - 4, + "fieldname", "Full Name:", + "field", "Christopher James Lahey", + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + gtk_signal_connect(GTK_OBJECT(new_item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); + } + if (rand() % 2) { + new_item = gnome_canvas_item_new( group, + e_minicard_label_get_type(), + "x", (double) 2, + "y", e_minicard->height, + "width", e_minicard->width - 4, + "fieldname", "Address:", + "field", "100 Main St\nHome town, USA", + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + gtk_signal_connect(GTK_OBJECT(new_item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); + } + + if (rand() % 2) { + new_item = gnome_canvas_item_new( group, + e_minicard_label_get_type(), + "x", (double) 2, + "y", e_minicard->height, + "width", e_minicard->width - 4.0, + "fieldname", "Email:", + "field", "clahey@helixcode.com", + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + gtk_signal_connect(GTK_OBJECT(new_item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); + } _update_card( e_minicard ); if (!item->canvas->aa) { @@ -298,6 +332,7 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) gnome_canvas_item_set( e_minicard->header_text, "fill_color", "white", NULL ); + e_minicard->has_focus = TRUE; } else { @@ -305,11 +340,12 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) "outline_color", NULL, NULL ); gnome_canvas_item_set( e_minicard->header_rect, - "fill_color", "grey50", + "fill_color", "grey70", NULL ); gnome_canvas_item_set( e_minicard->header_text, "fill_color", "black", NULL ); + e_minicard->has_focus = FALSE; } } break; @@ -317,15 +353,21 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) if (event->key.length == 1 && event->key.string[0] == '\t') { GList *list; for (list = e_minicard->fields; list; list = list->next) { - EMinicardLabel *label = E_MINICARD_LABEL (list->data); - if (label->field == label->field->canvas->focused_item) { + GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); + gboolean has_focus; + gtk_object_get(GTK_OBJECT(item), + "has_focus", &has_focus, + NULL); + if (has_focus) { if (event->key.state & GDK_SHIFT_MASK) list = list->prev; else list = list->next; if (list) { - label = E_MINICARD_LABEL (list->data); - gnome_canvas_item_grab_focus(label->field); + item = GNOME_CANVAS_ITEM (list->data); + gnome_canvas_item_set(item, + "has_focus", TRUE, + NULL); return 1; } else { return 0; @@ -357,7 +399,7 @@ _update_card( EMinicard *e_minicard ) "text_height", &text_height, NULL ); - e_minicard->height = text_height + 12.0; + e_minicard->height = text_height + 10.0; gnome_canvas_item_set( e_minicard->header_rect, "y2", text_height + 9.0, @@ -387,7 +429,7 @@ _update_card( EMinicard *e_minicard ) "y2", (double) e_minicard->height - 1.0, NULL ); gnome_canvas_item_set( e_minicard->header_rect, - "x2", (double) e_minicard->width - 4.0, + "x2", (double) e_minicard->width - 3.0, NULL ); gnome_canvas_item_set( e_minicard->header_text, "clip_width", (double) e_minicard->width - 12, diff --git a/addressbook/gui/widgets/e-minicard.h b/addressbook/gui/widgets/e-minicard.h index 43e7d8307f..98f6ea124a 100644 --- a/addressbook/gui/widgets/e-minicard.h +++ b/addressbook/gui/widgets/e-minicard.h @@ -61,6 +61,8 @@ struct _EMinicard GnomeCanvasItem *header_text; GList *fields; /* Of type GnomeCanvasItem. */ + gboolean has_focus; + double width; double height; }; @@ -69,7 +71,7 @@ struct _EMinicardClass { GnomeCanvasGroupClass parent_class; - void (* resize) (EMinicard *text); + void (* resize) (EMinicard *minicard); }; diff --git a/addressbook/gui/widgets/test-reflow.c b/addressbook/gui/widgets/test-reflow.c new file mode 100644 index 0000000000..f03232c72d --- /dev/null +++ b/addressbook/gui/widgets/test-reflow.c @@ -0,0 +1,136 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* test-reflow.c + * + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + + + +#include "config.h" + +#include <gnome.h> +#include "e-reflow.h" +#include "e-minicard.h" + +/* This is a horrible thing to do, but it is just a test. */ +GnomeCanvasItem *reflow; +GnomeCanvasItem *rect; + +static void destroy_callback(GtkWidget *app, gpointer data) +{ + exit(0); +} + +static void allocate_callback(GtkWidget *canvas, GtkAllocation *allocation, gpointer data) +{ + double width; + gnome_canvas_item_set( reflow, + "height", (double) allocation->height, + NULL ); + gtk_object_get(GTK_OBJECT(reflow), + "width", &width, + NULL); + width = MAX(width, allocation->width); + gnome_canvas_set_scroll_region(GNOME_CANVAS( canvas ), 0, 0, width, allocation->height ); + gnome_canvas_item_set( rect, + "x2", (double) width, + "y2", (double) allocation->height, + NULL ); +} + +static void about_callback( GtkWidget *widget, gpointer data ) +{ + + const gchar *authors[] = + { + "Christopher James Lahey <clahey@umich.edu>", + NULL + }; + + GtkWidget *about = + gnome_about_new ( _( "Reflow Test" ), VERSION, + _( "Copyright (C) 2000, Helix Code, Inc." ), + authors, + _( "This should test the reflow canvas item" ), + NULL); + gtk_widget_show (about); +} + +int main( int argc, char *argv[] ) +{ + GtkWidget *app; + GtkWidget *canvas; + GtkWidget *vbox; + GtkWidget *scrollbar; + int i; + + /* bindtextdomain (PACKAGE, GNOMELOCALEDIR); + textdomain (PACKAGE);*/ + + gnome_init( "Reflow Test", VERSION, argc, argv); + app = gnome_app_new("Reflow Test", NULL); + + vbox = gtk_vbox_new(FALSE, 0); + + canvas = gnome_canvas_new(); + rect = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), + gnome_canvas_rect_get_type(), + "x1", (double) 0, + "y1", (double) 0, + "x2", (double) 100, + "y2", (double) 100, + "fill_color", "white", + NULL ); + reflow = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), + e_reflow_get_type(), + "x", (double) 0, + "y", (double) 0, + "height", (double) 100, + NULL ); + for ( i = 0; i < 200; i++ ) + { + GnomeCanvasItem *item; + item = gnome_canvas_item_new( GNOME_CANVAS_GROUP(reflow), + e_minicard_get_type(), + NULL); + e_reflow_add_item(E_REFLOW(reflow), item); + } + gnome_canvas_set_scroll_region ( GNOME_CANVAS( canvas ), + 0, 0, + 100, 100 ); + + gtk_box_pack_start(GTK_BOX(vbox), canvas, TRUE, TRUE, 0); + + scrollbar = gtk_hscrollbar_new(gtk_layout_get_hadjustment(GTK_LAYOUT(canvas))); + + gtk_box_pack_start(GTK_BOX(vbox), scrollbar, FALSE, FALSE, 0); + + gnome_app_set_contents( GNOME_APP( app ), vbox ); + + /* Connect the signals */ + gtk_signal_connect( GTK_OBJECT( app ), "destroy", + GTK_SIGNAL_FUNC( destroy_callback ), + ( gpointer ) app ); + + gtk_signal_connect( GTK_OBJECT( canvas ), "size_allocate", + GTK_SIGNAL_FUNC( allocate_callback ), + ( gpointer ) app ); + + gtk_widget_show_all( app ); + + gtk_main(); + + /* Not reached. */ + return 0; +} diff --git a/e-util/e-canvas-utils.c b/e-util/e-canvas-utils.c new file mode 100644 index 0000000000..2b50248124 --- /dev/null +++ b/e-util/e-canvas-utils.c @@ -0,0 +1,36 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-canvas-utils.c + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "e-canvas-utils.h" + +void +e_canvas_item_move_absolute (GnomeCanvasItem *item, double dx, double dy) +{ + double translate[6]; + + g_return_if_fail (item != NULL); + g_return_if_fail (GNOME_IS_CANVAS_ITEM (item)); + + art_affine_translate (translate, dx, dy); + + gnome_canvas_item_affine_absolute (item, translate); +} diff --git a/e-util/e-canvas-utils.h b/e-util/e-canvas-utils.h new file mode 100644 index 0000000000..13ec43117c --- /dev/null +++ b/e-util/e-canvas-utils.h @@ -0,0 +1,24 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-canvas-utils.c + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <gnome.h> +void e_canvas_item_move_absolute (GnomeCanvasItem *item, double dx, double dy); diff --git a/widgets/Makefile.am b/widgets/Makefile.am index 91e97910a7..1e2016ef3c 100644 --- a/widgets/Makefile.am +++ b/widgets/Makefile.am @@ -11,12 +11,16 @@ noinst_LIBRARIES = \ libevolutionwidgets.a libevolutionwidgets_a_SOURCES = \ + e-canvas-utils.c \ + e-canvas-utils.h \ e-cursors.c \ e-cursors.h \ e-minicard.c \ e-minicard.h \ e-minicard-label.c \ e-minicard-label.h \ + e-reflow.c \ + e-reflow.h \ e-text.c \ e-text.h \ e-text-event-processor.c \ @@ -26,7 +30,8 @@ libevolutionwidgets_a_SOURCES = \ noinst_PROGRAMS = \ minicard-label-test \ - minicard-test + minicard-test \ + reflow-test minicard_label_test_SOURCES = \ test-minicard-label.c @@ -41,3 +46,10 @@ minicard_test_SOURCES = \ minicard_test_LDADD = \ $(EXTRA_GNOME_LIBS) \ libevolutionwidgets.a + +reflow_test_SOURCES = \ + test-reflow.c + +reflow_test_LDADD = \ + $(EXTRA_GNOME_LIBS) \ + libevolutionwidgets.a diff --git a/widgets/e-canvas-utils.c b/widgets/e-canvas-utils.c new file mode 100644 index 0000000000..2b50248124 --- /dev/null +++ b/widgets/e-canvas-utils.c @@ -0,0 +1,36 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-canvas-utils.c + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "e-canvas-utils.h" + +void +e_canvas_item_move_absolute (GnomeCanvasItem *item, double dx, double dy) +{ + double translate[6]; + + g_return_if_fail (item != NULL); + g_return_if_fail (GNOME_IS_CANVAS_ITEM (item)); + + art_affine_translate (translate, dx, dy); + + gnome_canvas_item_affine_absolute (item, translate); +} diff --git a/widgets/e-canvas-utils.h b/widgets/e-canvas-utils.h new file mode 100644 index 0000000000..13ec43117c --- /dev/null +++ b/widgets/e-canvas-utils.h @@ -0,0 +1,24 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-canvas-utils.c + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <gnome.h> +void e_canvas_item_move_absolute (GnomeCanvasItem *item, double dx, double dy); diff --git a/widgets/e-minicard-label.c b/widgets/e-minicard-label.c index 9efdd0ba65..a550031123 100644 --- a/widgets/e-minicard-label.c +++ b/widgets/e-minicard-label.c @@ -48,6 +48,7 @@ enum { ARG_0, ARG_WIDTH, ARG_HEIGHT, + ARG_HAS_FOCUS, ARG_FIELD, ARG_FIELDNAME }; @@ -103,6 +104,8 @@ e_minicard_label_class_init (EMinicardLabelClass *klass) GTK_ARG_READWRITE, ARG_WIDTH); gtk_object_add_arg_type ("EMinicardLabel::height", GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_HEIGHT); + gtk_object_add_arg_type ("EMinicardLabel::has_focus", GTK_TYPE_BOOL, + GTK_ARG_READWRITE, ARG_HAS_FOCUS); gtk_object_add_arg_type ("EMinicardLabel::field", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_FIELD); gtk_object_add_arg_type ("EMinicardLabel::fieldname", GTK_TYPE_STRING, @@ -148,6 +151,10 @@ e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) _update_label( e_minicard_label ); gnome_canvas_item_request_update (item); break; + case ARG_HAS_FOCUS: + if (e_minicard_label->field && GTK_VALUE_BOOL(*arg)) + gnome_canvas_item_grab_focus(e_minicard_label->field); + break; case ARG_FIELD: if ( e_minicard_label->field ) gnome_canvas_item_set( e_minicard_label->field, "text", GTK_VALUE_STRING (*arg), NULL ); @@ -178,6 +185,9 @@ e_minicard_label_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) case ARG_HEIGHT: GTK_VALUE_DOUBLE (*arg) = e_minicard_label->height; break; + case ARG_HAS_FOCUS: + GTK_VALUE_BOOL (*arg) = e_minicard_label->has_focus; + break; case ARG_FIELD: if ( e_minicard_label->field ) { @@ -317,6 +327,7 @@ e_minicard_label_event (GnomeCanvasItem *item, GdkEvent *event) "outline_color", "grey50", "fill_color", "grey90", NULL ); + e_minicard_label->has_focus = TRUE; } else { @@ -324,6 +335,7 @@ e_minicard_label_event (GnomeCanvasItem *item, GdkEvent *event) "outline_color", NULL, "fill_color", NULL, NULL ); + e_minicard_label->has_focus = FALSE; } } break; diff --git a/widgets/e-minicard-label.h b/widgets/e-minicard-label.h index bbaca884ac..ddbe7ab191 100644 --- a/widgets/e-minicard-label.h +++ b/widgets/e-minicard-label.h @@ -62,6 +62,8 @@ struct _EMinicardLabel GnomeCanvasItem *rect; char *fieldname_text; char *field_text; + + gboolean has_focus; }; struct _EMinicardLabelClass diff --git a/widgets/e-minicard.c b/widgets/e-minicard.c index 01c326d568..52d241d11e 100644 --- a/widgets/e-minicard.c +++ b/widgets/e-minicard.c @@ -49,6 +49,7 @@ enum { ARG_0, ARG_WIDTH, ARG_HEIGHT, + ARG_HAS_FOCUS, ARG_CARD }; @@ -103,6 +104,8 @@ e_minicard_class_init (EMinicardClass *klass) GTK_ARG_READWRITE, ARG_WIDTH); gtk_object_add_arg_type ("EMinicard::height", GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_HEIGHT); + gtk_object_add_arg_type ("EMinicard::has_focus", GTK_TYPE_BOOL, + GTK_ARG_READWRITE, ARG_HAS_FOCUS); gtk_object_add_arg_type ("EMinicard::card", GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_CARD); @@ -124,6 +127,7 @@ e_minicard_init (EMinicard *minicard) minicard->fields = NULL; minicard->width = 10; minicard->height = 10; + minicard->has_focus = FALSE; } static void @@ -141,6 +145,14 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) _update_card(e_minicard); gnome_canvas_item_request_update (item); break; + case ARG_HAS_FOCUS: + if (e_minicard->fields) + gnome_canvas_item_set(GNOME_CANVAS_ITEM(e_minicard->fields->data), + "has_focus", GTK_VALUE_BOOL(*arg), + NULL); + else + gnome_canvas_item_grab_focus(GNOME_CANVAS_ITEM(e_minicard)); + break; case ARG_CARD: /* e_minicard->card = GTK_VALUE_POINTER (*arg); _update_card(e_minicard); @@ -163,6 +175,9 @@ e_minicard_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) case ARG_HEIGHT: GTK_VALUE_DOUBLE (*arg) = e_minicard->height; break; + case ARG_HAS_FOCUS: + GTK_VALUE_BOOL (*arg) = e_minicard->has_focus; + break; case ARG_CARD: /* GTK_VALUE_POINTER (*arg) = e_minicard->card; */ break; @@ -218,42 +233,61 @@ e_minicard_realize (GnomeCanvasItem *item) "fill_color", "black", "text", "Chris Lahey", NULL ); - - gtk_signal_connect(GTK_OBJECT(e_minicard->header_text), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_minicard); - - new_item = gnome_canvas_item_new( group, - e_minicard_label_get_type(), - "x", (double) 2, - "y", e_minicard->height, - "width", e_minicard->width - 4, - "fieldname", "Full Name:", - "field", "Christopher James Lahey", - NULL ); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); - - gtk_signal_connect(GTK_OBJECT(new_item), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_minicard); - new_item = gnome_canvas_item_new( group, - e_minicard_label_get_type(), - "x", (double) 2, - "y", e_minicard->height, - "width", e_minicard->width - 4.0, - "fieldname", "Email:", - "field", "clahey@helixcode.com", - NULL ); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); - - gtk_signal_connect(GTK_OBJECT(new_item), + gtk_signal_connect(GTK_OBJECT(e_minicard->header_text), "resize", GTK_SIGNAL_FUNC(_resize), (gpointer) e_minicard); + if ( rand() % 2 ) { + new_item = gnome_canvas_item_new( group, + e_minicard_label_get_type(), + "x", (double) 2, + "y", e_minicard->height, + "width", e_minicard->width - 4, + "fieldname", "Full Name:", + "field", "Christopher James Lahey", + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + gtk_signal_connect(GTK_OBJECT(new_item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); + } + if (rand() % 2) { + new_item = gnome_canvas_item_new( group, + e_minicard_label_get_type(), + "x", (double) 2, + "y", e_minicard->height, + "width", e_minicard->width - 4, + "fieldname", "Address:", + "field", "100 Main St\nHome town, USA", + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + gtk_signal_connect(GTK_OBJECT(new_item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); + } + + if (rand() % 2) { + new_item = gnome_canvas_item_new( group, + e_minicard_label_get_type(), + "x", (double) 2, + "y", e_minicard->height, + "width", e_minicard->width - 4.0, + "fieldname", "Email:", + "field", "clahey@helixcode.com", + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + gtk_signal_connect(GTK_OBJECT(new_item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); + } _update_card( e_minicard ); if (!item->canvas->aa) { @@ -298,6 +332,7 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) gnome_canvas_item_set( e_minicard->header_text, "fill_color", "white", NULL ); + e_minicard->has_focus = TRUE; } else { @@ -305,11 +340,12 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) "outline_color", NULL, NULL ); gnome_canvas_item_set( e_minicard->header_rect, - "fill_color", "grey50", + "fill_color", "grey70", NULL ); gnome_canvas_item_set( e_minicard->header_text, "fill_color", "black", NULL ); + e_minicard->has_focus = FALSE; } } break; @@ -317,15 +353,21 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) if (event->key.length == 1 && event->key.string[0] == '\t') { GList *list; for (list = e_minicard->fields; list; list = list->next) { - EMinicardLabel *label = E_MINICARD_LABEL (list->data); - if (label->field == label->field->canvas->focused_item) { + GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); + gboolean has_focus; + gtk_object_get(GTK_OBJECT(item), + "has_focus", &has_focus, + NULL); + if (has_focus) { if (event->key.state & GDK_SHIFT_MASK) list = list->prev; else list = list->next; if (list) { - label = E_MINICARD_LABEL (list->data); - gnome_canvas_item_grab_focus(label->field); + item = GNOME_CANVAS_ITEM (list->data); + gnome_canvas_item_set(item, + "has_focus", TRUE, + NULL); return 1; } else { return 0; @@ -357,7 +399,7 @@ _update_card( EMinicard *e_minicard ) "text_height", &text_height, NULL ); - e_minicard->height = text_height + 12.0; + e_minicard->height = text_height + 10.0; gnome_canvas_item_set( e_minicard->header_rect, "y2", text_height + 9.0, @@ -387,7 +429,7 @@ _update_card( EMinicard *e_minicard ) "y2", (double) e_minicard->height - 1.0, NULL ); gnome_canvas_item_set( e_minicard->header_rect, - "x2", (double) e_minicard->width - 4.0, + "x2", (double) e_minicard->width - 3.0, NULL ); gnome_canvas_item_set( e_minicard->header_text, "clip_width", (double) e_minicard->width - 12, diff --git a/widgets/e-minicard.h b/widgets/e-minicard.h index 43e7d8307f..98f6ea124a 100644 --- a/widgets/e-minicard.h +++ b/widgets/e-minicard.h @@ -61,6 +61,8 @@ struct _EMinicard GnomeCanvasItem *header_text; GList *fields; /* Of type GnomeCanvasItem. */ + gboolean has_focus; + double width; double height; }; @@ -69,7 +71,7 @@ struct _EMinicardClass { GnomeCanvasGroupClass parent_class; - void (* resize) (EMinicard *text); + void (* resize) (EMinicard *minicard); }; diff --git a/widgets/e-minicard/e-minicard-label.c b/widgets/e-minicard/e-minicard-label.c index 9efdd0ba65..a550031123 100644 --- a/widgets/e-minicard/e-minicard-label.c +++ b/widgets/e-minicard/e-minicard-label.c @@ -48,6 +48,7 @@ enum { ARG_0, ARG_WIDTH, ARG_HEIGHT, + ARG_HAS_FOCUS, ARG_FIELD, ARG_FIELDNAME }; @@ -103,6 +104,8 @@ e_minicard_label_class_init (EMinicardLabelClass *klass) GTK_ARG_READWRITE, ARG_WIDTH); gtk_object_add_arg_type ("EMinicardLabel::height", GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_HEIGHT); + gtk_object_add_arg_type ("EMinicardLabel::has_focus", GTK_TYPE_BOOL, + GTK_ARG_READWRITE, ARG_HAS_FOCUS); gtk_object_add_arg_type ("EMinicardLabel::field", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_FIELD); gtk_object_add_arg_type ("EMinicardLabel::fieldname", GTK_TYPE_STRING, @@ -148,6 +151,10 @@ e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) _update_label( e_minicard_label ); gnome_canvas_item_request_update (item); break; + case ARG_HAS_FOCUS: + if (e_minicard_label->field && GTK_VALUE_BOOL(*arg)) + gnome_canvas_item_grab_focus(e_minicard_label->field); + break; case ARG_FIELD: if ( e_minicard_label->field ) gnome_canvas_item_set( e_minicard_label->field, "text", GTK_VALUE_STRING (*arg), NULL ); @@ -178,6 +185,9 @@ e_minicard_label_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) case ARG_HEIGHT: GTK_VALUE_DOUBLE (*arg) = e_minicard_label->height; break; + case ARG_HAS_FOCUS: + GTK_VALUE_BOOL (*arg) = e_minicard_label->has_focus; + break; case ARG_FIELD: if ( e_minicard_label->field ) { @@ -317,6 +327,7 @@ e_minicard_label_event (GnomeCanvasItem *item, GdkEvent *event) "outline_color", "grey50", "fill_color", "grey90", NULL ); + e_minicard_label->has_focus = TRUE; } else { @@ -324,6 +335,7 @@ e_minicard_label_event (GnomeCanvasItem *item, GdkEvent *event) "outline_color", NULL, "fill_color", NULL, NULL ); + e_minicard_label->has_focus = FALSE; } } break; diff --git a/widgets/e-minicard/e-minicard-label.h b/widgets/e-minicard/e-minicard-label.h index bbaca884ac..ddbe7ab191 100644 --- a/widgets/e-minicard/e-minicard-label.h +++ b/widgets/e-minicard/e-minicard-label.h @@ -62,6 +62,8 @@ struct _EMinicardLabel GnomeCanvasItem *rect; char *fieldname_text; char *field_text; + + gboolean has_focus; }; struct _EMinicardLabelClass diff --git a/widgets/e-minicard/e-minicard.c b/widgets/e-minicard/e-minicard.c index 01c326d568..52d241d11e 100644 --- a/widgets/e-minicard/e-minicard.c +++ b/widgets/e-minicard/e-minicard.c @@ -49,6 +49,7 @@ enum { ARG_0, ARG_WIDTH, ARG_HEIGHT, + ARG_HAS_FOCUS, ARG_CARD }; @@ -103,6 +104,8 @@ e_minicard_class_init (EMinicardClass *klass) GTK_ARG_READWRITE, ARG_WIDTH); gtk_object_add_arg_type ("EMinicard::height", GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_HEIGHT); + gtk_object_add_arg_type ("EMinicard::has_focus", GTK_TYPE_BOOL, + GTK_ARG_READWRITE, ARG_HAS_FOCUS); gtk_object_add_arg_type ("EMinicard::card", GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_CARD); @@ -124,6 +127,7 @@ e_minicard_init (EMinicard *minicard) minicard->fields = NULL; minicard->width = 10; minicard->height = 10; + minicard->has_focus = FALSE; } static void @@ -141,6 +145,14 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) _update_card(e_minicard); gnome_canvas_item_request_update (item); break; + case ARG_HAS_FOCUS: + if (e_minicard->fields) + gnome_canvas_item_set(GNOME_CANVAS_ITEM(e_minicard->fields->data), + "has_focus", GTK_VALUE_BOOL(*arg), + NULL); + else + gnome_canvas_item_grab_focus(GNOME_CANVAS_ITEM(e_minicard)); + break; case ARG_CARD: /* e_minicard->card = GTK_VALUE_POINTER (*arg); _update_card(e_minicard); @@ -163,6 +175,9 @@ e_minicard_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) case ARG_HEIGHT: GTK_VALUE_DOUBLE (*arg) = e_minicard->height; break; + case ARG_HAS_FOCUS: + GTK_VALUE_BOOL (*arg) = e_minicard->has_focus; + break; case ARG_CARD: /* GTK_VALUE_POINTER (*arg) = e_minicard->card; */ break; @@ -218,42 +233,61 @@ e_minicard_realize (GnomeCanvasItem *item) "fill_color", "black", "text", "Chris Lahey", NULL ); - - gtk_signal_connect(GTK_OBJECT(e_minicard->header_text), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_minicard); - - new_item = gnome_canvas_item_new( group, - e_minicard_label_get_type(), - "x", (double) 2, - "y", e_minicard->height, - "width", e_minicard->width - 4, - "fieldname", "Full Name:", - "field", "Christopher James Lahey", - NULL ); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); - - gtk_signal_connect(GTK_OBJECT(new_item), - "resize", - GTK_SIGNAL_FUNC(_resize), - (gpointer) e_minicard); - new_item = gnome_canvas_item_new( group, - e_minicard_label_get_type(), - "x", (double) 2, - "y", e_minicard->height, - "width", e_minicard->width - 4.0, - "fieldname", "Email:", - "field", "clahey@helixcode.com", - NULL ); - e_minicard->fields = g_list_append( e_minicard->fields, new_item); - - gtk_signal_connect(GTK_OBJECT(new_item), + gtk_signal_connect(GTK_OBJECT(e_minicard->header_text), "resize", GTK_SIGNAL_FUNC(_resize), (gpointer) e_minicard); + if ( rand() % 2 ) { + new_item = gnome_canvas_item_new( group, + e_minicard_label_get_type(), + "x", (double) 2, + "y", e_minicard->height, + "width", e_minicard->width - 4, + "fieldname", "Full Name:", + "field", "Christopher James Lahey", + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + gtk_signal_connect(GTK_OBJECT(new_item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); + } + if (rand() % 2) { + new_item = gnome_canvas_item_new( group, + e_minicard_label_get_type(), + "x", (double) 2, + "y", e_minicard->height, + "width", e_minicard->width - 4, + "fieldname", "Address:", + "field", "100 Main St\nHome town, USA", + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + gtk_signal_connect(GTK_OBJECT(new_item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); + } + + if (rand() % 2) { + new_item = gnome_canvas_item_new( group, + e_minicard_label_get_type(), + "x", (double) 2, + "y", e_minicard->height, + "width", e_minicard->width - 4.0, + "fieldname", "Email:", + "field", "clahey@helixcode.com", + NULL ); + e_minicard->fields = g_list_append( e_minicard->fields, new_item); + + gtk_signal_connect(GTK_OBJECT(new_item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_minicard); + } _update_card( e_minicard ); if (!item->canvas->aa) { @@ -298,6 +332,7 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) gnome_canvas_item_set( e_minicard->header_text, "fill_color", "white", NULL ); + e_minicard->has_focus = TRUE; } else { @@ -305,11 +340,12 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) "outline_color", NULL, NULL ); gnome_canvas_item_set( e_minicard->header_rect, - "fill_color", "grey50", + "fill_color", "grey70", NULL ); gnome_canvas_item_set( e_minicard->header_text, "fill_color", "black", NULL ); + e_minicard->has_focus = FALSE; } } break; @@ -317,15 +353,21 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) if (event->key.length == 1 && event->key.string[0] == '\t') { GList *list; for (list = e_minicard->fields; list; list = list->next) { - EMinicardLabel *label = E_MINICARD_LABEL (list->data); - if (label->field == label->field->canvas->focused_item) { + GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); + gboolean has_focus; + gtk_object_get(GTK_OBJECT(item), + "has_focus", &has_focus, + NULL); + if (has_focus) { if (event->key.state & GDK_SHIFT_MASK) list = list->prev; else list = list->next; if (list) { - label = E_MINICARD_LABEL (list->data); - gnome_canvas_item_grab_focus(label->field); + item = GNOME_CANVAS_ITEM (list->data); + gnome_canvas_item_set(item, + "has_focus", TRUE, + NULL); return 1; } else { return 0; @@ -357,7 +399,7 @@ _update_card( EMinicard *e_minicard ) "text_height", &text_height, NULL ); - e_minicard->height = text_height + 12.0; + e_minicard->height = text_height + 10.0; gnome_canvas_item_set( e_minicard->header_rect, "y2", text_height + 9.0, @@ -387,7 +429,7 @@ _update_card( EMinicard *e_minicard ) "y2", (double) e_minicard->height - 1.0, NULL ); gnome_canvas_item_set( e_minicard->header_rect, - "x2", (double) e_minicard->width - 4.0, + "x2", (double) e_minicard->width - 3.0, NULL ); gnome_canvas_item_set( e_minicard->header_text, "clip_width", (double) e_minicard->width - 12, diff --git a/widgets/e-minicard/e-minicard.h b/widgets/e-minicard/e-minicard.h index 43e7d8307f..98f6ea124a 100644 --- a/widgets/e-minicard/e-minicard.h +++ b/widgets/e-minicard/e-minicard.h @@ -61,6 +61,8 @@ struct _EMinicard GnomeCanvasItem *header_text; GList *fields; /* Of type GnomeCanvasItem. */ + gboolean has_focus; + double width; double height; }; @@ -69,7 +71,7 @@ struct _EMinicardClass { GnomeCanvasGroupClass parent_class; - void (* resize) (EMinicard *text); + void (* resize) (EMinicard *minicard); }; diff --git a/widgets/e-minicard/e-reflow.c b/widgets/e-minicard/e-reflow.c new file mode 100644 index 0000000000..ce2e92e530 --- /dev/null +++ b/widgets/e-minicard/e-reflow.c @@ -0,0 +1,438 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-reflow.c + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <gnome.h> +#include "e-reflow.h" +#include "e-canvas-utils.h" +static void e_reflow_init (EReflow *card); +static void e_reflow_class_init (EReflowClass *klass); +static void e_reflow_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); +static void e_reflow_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); +static gboolean e_reflow_event (GnomeCanvasItem *item, GdkEvent *event); +static void e_reflow_realize (GnomeCanvasItem *item); +static void e_reflow_unrealize (GnomeCanvasItem *item); +static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable, + int x, int y, int width, int height); + +static void _update_reflow ( EReflow *reflow ); +static void _resize( GtkObject *object, gpointer data ); +static void _queue_reflow(EReflow *e_reflow); + +static GnomeCanvasGroupClass *parent_class = NULL; + +enum { + E_REFLOW_RESIZE, + E_REFLOW_LAST_SIGNAL +}; + +static guint e_reflow_signals[E_REFLOW_LAST_SIGNAL] = { 0 }; + +/* The arguments we take */ +enum { + ARG_0, + ARG_WIDTH, + ARG_HEIGHT +}; + +GtkType +e_reflow_get_type (void) +{ + static GtkType reflow_type = 0; + + if (!reflow_type) + { + static const GtkTypeInfo reflow_info = + { + "EReflow", + sizeof (EReflow), + sizeof (EReflowClass), + (GtkClassInitFunc) e_reflow_class_init, + (GtkObjectInitFunc) e_reflow_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + reflow_type = gtk_type_unique (gnome_canvas_group_get_type (), &reflow_info); + } + + return reflow_type; +} + +static void +e_reflow_class_init (EReflowClass *klass) +{ + GtkObjectClass *object_class; + GnomeCanvasItemClass *item_class; + + object_class = (GtkObjectClass*) klass; + item_class = (GnomeCanvasItemClass *) klass; + + parent_class = gtk_type_class (gnome_canvas_group_get_type ()); + + e_reflow_signals[E_REFLOW_RESIZE] = + gtk_signal_new ("resize", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (EReflowClass, resize), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + gtk_object_class_add_signals (object_class, e_reflow_signals, E_REFLOW_LAST_SIGNAL); + + gtk_object_add_arg_type ("EReflow::width", GTK_TYPE_DOUBLE, + GTK_ARG_READABLE, ARG_WIDTH); + gtk_object_add_arg_type ("EReflow::height", GTK_TYPE_DOUBLE, + GTK_ARG_READWRITE, ARG_HEIGHT); + + object_class->set_arg = e_reflow_set_arg; + object_class->get_arg = e_reflow_get_arg; + /* object_class->destroy = e_reflow_destroy; */ + + /* GnomeCanvasItem method overrides */ + item_class->event = e_reflow_event; + item_class->realize = e_reflow_realize; + item_class->unrealize = e_reflow_unrealize; + /* item_class->draw = e_reflow_draw;*/ +} + +static void +e_reflow_init (EReflow *reflow) +{ + /* reflow->card = NULL;*/ + reflow->items = NULL; + reflow->columns = NULL; + reflow->column_width = 150; + + reflow->width = 10; + reflow->height = 10; + reflow->idle = 0; +} + +static void +e_reflow_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) +{ + GnomeCanvasItem *item; + EReflow *e_reflow; + + item = GNOME_CANVAS_ITEM (o); + e_reflow = E_REFLOW (o); + + switch (arg_id){ + case ARG_HEIGHT: + e_reflow->height = GTK_VALUE_DOUBLE (*arg); + _update_reflow(e_reflow); + gnome_canvas_item_request_update (item); + break; + } +} + +static void +e_reflow_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) +{ + EReflow *e_reflow; + + e_reflow = E_REFLOW (object); + + switch (arg_id) { + case ARG_WIDTH: + GTK_VALUE_DOUBLE (*arg) = e_reflow->width; + break; + case ARG_HEIGHT: + GTK_VALUE_DOUBLE (*arg) = e_reflow->height; + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} + +static void +e_reflow_realize (GnomeCanvasItem *item) +{ + EReflow *e_reflow; + GnomeCanvasGroup *group; + GList *list; + + e_reflow = E_REFLOW (item); + group = GNOME_CANVAS_GROUP( item ); + + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) + (* GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) (item); + + for(list = e_reflow->items; list; list = g_list_next(list)) { + GnomeCanvasItem *item = GNOME_CANVAS_ITEM(list->data); + gtk_signal_connect(GTK_OBJECT(item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_reflow); + gnome_canvas_item_set(item, + "width", (double) e_reflow->column_width, + NULL); + } + + _update_reflow( e_reflow ); + + if (!item->canvas->aa) { + } +} + +static void +e_reflow_unrealize (GnomeCanvasItem *item) +{ + EReflow *e_reflow; + + e_reflow = E_REFLOW (item); + + if (!item->canvas->aa) + { + } + + g_list_free (e_reflow->items); + g_list_free (e_reflow->columns); + + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) + (* GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) (item); +} + +static gboolean +e_reflow_event (GnomeCanvasItem *item, GdkEvent *event) +{ + EReflow *e_reflow; + + e_reflow = E_REFLOW (item); + + switch( event->type ) + { + case GDK_KEY_PRESS: + if (event->key.length == 1 && event->key.string[0] == '\t') { + GList *list; + for (list = e_reflow->items; list; list = list->next) { + GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); + gboolean has_focus; + gtk_object_get(GTK_OBJECT(item), + "has_focus", &has_focus, + NULL); + if (has_focus) { + if (event->key.state & GDK_SHIFT_MASK) + list = list->prev; + else + list = list->next; + if (list) { + item = GNOME_CANVAS_ITEM(list->data); + gnome_canvas_item_set(item, + "has_focus", TRUE, + NULL); + return 1; + } else { + return 0; + } + } + } + } + default: + break; + } + + if (GNOME_CANVAS_ITEM_CLASS( parent_class )->event) + return (* GNOME_CANVAS_ITEM_CLASS( parent_class )->event) (item, event); + else + return 0; +} + +void +e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item) +{ + e_reflow->items = g_list_append(e_reflow->items, item); + if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { + gtk_signal_connect(GTK_OBJECT(item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_reflow); + gnome_canvas_item_set(item, + "width", (double) e_reflow->column_width, + NULL); + _queue_reflow(e_reflow); + } + +} +#if 0 +static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable, + int x, int y, int width, int height) +{ + int x_rect, y_rect, width_rect, height_rect; + gint running_width; + EReflow *e_reflow = E_REFLOW(item); + int i; + + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->draw) + GNOME_CANVAS_ITEM_CLASS(parent_class)->draw (item, drawable, x, y, width, height); + + running_width = 7 + e_reflow->column_width + 7; + x_rect = running_width; + y_rect = 7; + width_rect = 2; + height_rect = e_reflow->height - 14; + + for (i = 0; i < e_reflow->column_count - 1; i++) { + x_rect = running_width; + gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style, + drawable, + GTK_STATE_ACTIVE, + GTK_SHADOW_NONE, + NULL, + GTK_WIDGET(item->canvas), + "reflow", + x_rect - x, + y_rect - x, + width_rect, + height_rect); + running_width += 2 + 7 + e_reflow->column_width + 7; + } +} +#endif + +static void +_reflow( EReflow *e_reflow ) +{ + int running_height; + GList *list; + double item_height; + + if (e_reflow->columns) { + g_list_free (e_reflow->columns); + e_reflow->columns = NULL; + } + + e_reflow->column_count = 0; + + if (e_reflow->items == NULL) { + e_reflow->columns = NULL; + e_reflow->column_count = 1; + return; + } + + list = e_reflow->items; + + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + running_height = 7 + item_height + 7; + e_reflow->columns = g_list_append (e_reflow->columns, list); + e_reflow->column_count = 1; + + list = g_list_next(list); + + for ( ; list; list = g_list_next(list)) { + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + if (running_height + item_height + 7 > e_reflow->height) { + running_height = 7 + item_height + 7; + e_reflow->columns = g_list_append (e_reflow->columns, list); + e_reflow->column_count ++; + } else { + running_height += item_height + 7; + } + } +} + +static void +_update_reflow( EReflow *e_reflow ) +{ + if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { + + gint old_width; + gint running_width; + + _reflow (e_reflow); + + old_width = e_reflow->width; + + running_width = 7; + + if (e_reflow->items == NULL) { + } else { + GList *list; + GList *next_column; + gdouble item_height; + gint running_height; + + running_height = 7; + + list = e_reflow->items; + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), + (double) running_width, + (double) running_height); + running_height += item_height + 7; + next_column = g_list_next(e_reflow->columns); + list = g_list_next(list); + + for( ; list; list = g_list_next(list)) { + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + + if (next_column && (next_column->data == list)) { + next_column = g_list_next (next_column); + running_height = 7; + running_width += e_reflow->column_width + 7 + 2 + 7; + } + e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), + (double) running_width, + (double) running_height); + + running_height += item_height + 7; + } + + } + e_reflow->width = running_width + e_reflow->column_width + 7; + if (old_width != e_reflow->width) + gtk_signal_emit_by_name (GTK_OBJECT (e_reflow), "resize"); + } +} + + +static gboolean +_idle_reflow(gpointer data) +{ + EReflow *e_reflow = E_REFLOW(data); + _update_reflow(e_reflow); + e_reflow->idle = 0; + return FALSE; +} + +static void +_queue_reflow(EReflow *e_reflow) +{ + if (e_reflow->idle == 0) + e_reflow->idle = g_idle_add(_idle_reflow, e_reflow); +} + +static void +_resize( GtkObject *object, gpointer data ) +{ + _queue_reflow(E_REFLOW(data)); +} diff --git a/widgets/e-minicard/e-reflow.h b/widgets/e-minicard/e-reflow.h new file mode 100644 index 0000000000..0d0ab4251a --- /dev/null +++ b/widgets/e-minicard/e-reflow.h @@ -0,0 +1,88 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* e-reflow.h + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef __E_REFLOW_H__ +#define __E_REFLOW_H__ + +#include <gnome.h> + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +/* EReflow - A canvas item container. + * + * The following arguments are available: + * + * name type read/write description + * -------------------------------------------------------------------------------- + * width double R width of the reflow + * height double RW height of the reflow + */ + +#define E_REFLOW_TYPE (e_reflow_get_type ()) +#define E_REFLOW(obj) (GTK_CHECK_CAST ((obj), E_REFLOW_TYPE, EReflow)) +#define E_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_REFLOW_TYPE, EReflowClass)) +#define E_IS_REFLOW(obj) (GTK_CHECK_TYPE ((obj), E_REFLOW_TYPE)) +#define E_IS_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_REFLOW_TYPE)) + + +typedef struct _EReflow EReflow; +typedef struct _EReflowClass EReflowClass; + +struct _EReflow +{ + GnomeCanvasGroup parent; + + /* item specific fields */ + /* EBook *book; */ + + GList *items; /* Of type GnomeCanvasItem */ + GList *columns; /* Of type GList pointing to type GnomeCanvasItem (points into items) */ + gint column_count; /* Number of columnns */ + + double width; + double height; + + double column_width; + + int idle; +}; + +struct _EReflowClass +{ + GnomeCanvasGroupClass parent_class; + + void (* resize) (EReflow *reflow); +}; + +/* To be added to a reflow, an item must have the arguments "x", "y", + and "width" as Read/Write arguments and "height" as a Read Only + argument. It must also have a "resize" signal. */ +void e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item); +GtkType e_reflow_get_type (void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __E_REFLOW_H__ */ diff --git a/widgets/e-minicard/test-reflow.c b/widgets/e-minicard/test-reflow.c new file mode 100644 index 0000000000..f03232c72d --- /dev/null +++ b/widgets/e-minicard/test-reflow.c @@ -0,0 +1,136 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* test-reflow.c + * + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + + + +#include "config.h" + +#include <gnome.h> +#include "e-reflow.h" +#include "e-minicard.h" + +/* This is a horrible thing to do, but it is just a test. */ +GnomeCanvasItem *reflow; +GnomeCanvasItem *rect; + +static void destroy_callback(GtkWidget *app, gpointer data) +{ + exit(0); +} + +static void allocate_callback(GtkWidget *canvas, GtkAllocation *allocation, gpointer data) +{ + double width; + gnome_canvas_item_set( reflow, + "height", (double) allocation->height, + NULL ); + gtk_object_get(GTK_OBJECT(reflow), + "width", &width, + NULL); + width = MAX(width, allocation->width); + gnome_canvas_set_scroll_region(GNOME_CANVAS( canvas ), 0, 0, width, allocation->height ); + gnome_canvas_item_set( rect, + "x2", (double) width, + "y2", (double) allocation->height, + NULL ); +} + +static void about_callback( GtkWidget *widget, gpointer data ) +{ + + const gchar *authors[] = + { + "Christopher James Lahey <clahey@umich.edu>", + NULL + }; + + GtkWidget *about = + gnome_about_new ( _( "Reflow Test" ), VERSION, + _( "Copyright (C) 2000, Helix Code, Inc." ), + authors, + _( "This should test the reflow canvas item" ), + NULL); + gtk_widget_show (about); +} + +int main( int argc, char *argv[] ) +{ + GtkWidget *app; + GtkWidget *canvas; + GtkWidget *vbox; + GtkWidget *scrollbar; + int i; + + /* bindtextdomain (PACKAGE, GNOMELOCALEDIR); + textdomain (PACKAGE);*/ + + gnome_init( "Reflow Test", VERSION, argc, argv); + app = gnome_app_new("Reflow Test", NULL); + + vbox = gtk_vbox_new(FALSE, 0); + + canvas = gnome_canvas_new(); + rect = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), + gnome_canvas_rect_get_type(), + "x1", (double) 0, + "y1", (double) 0, + "x2", (double) 100, + "y2", (double) 100, + "fill_color", "white", + NULL ); + reflow = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), + e_reflow_get_type(), + "x", (double) 0, + "y", (double) 0, + "height", (double) 100, + NULL ); + for ( i = 0; i < 200; i++ ) + { + GnomeCanvasItem *item; + item = gnome_canvas_item_new( GNOME_CANVAS_GROUP(reflow), + e_minicard_get_type(), + NULL); + e_reflow_add_item(E_REFLOW(reflow), item); + } + gnome_canvas_set_scroll_region ( GNOME_CANVAS( canvas ), + 0, 0, + 100, 100 ); + + gtk_box_pack_start(GTK_BOX(vbox), canvas, TRUE, TRUE, 0); + + scrollbar = gtk_hscrollbar_new(gtk_layout_get_hadjustment(GTK_LAYOUT(canvas))); + + gtk_box_pack_start(GTK_BOX(vbox), scrollbar, FALSE, FALSE, 0); + + gnome_app_set_contents( GNOME_APP( app ), vbox ); + + /* Connect the signals */ + gtk_signal_connect( GTK_OBJECT( app ), "destroy", + GTK_SIGNAL_FUNC( destroy_callback ), + ( gpointer ) app ); + + gtk_signal_connect( GTK_OBJECT( canvas ), "size_allocate", + GTK_SIGNAL_FUNC( allocate_callback ), + ( gpointer ) app ); + + gtk_widget_show_all( app ); + + gtk_main(); + + /* Not reached. */ + return 0; +} diff --git a/widgets/e-reflow.c b/widgets/e-reflow.c new file mode 100644 index 0000000000..ce2e92e530 --- /dev/null +++ b/widgets/e-reflow.c @@ -0,0 +1,438 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-reflow.c + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <gnome.h> +#include "e-reflow.h" +#include "e-canvas-utils.h" +static void e_reflow_init (EReflow *card); +static void e_reflow_class_init (EReflowClass *klass); +static void e_reflow_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); +static void e_reflow_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); +static gboolean e_reflow_event (GnomeCanvasItem *item, GdkEvent *event); +static void e_reflow_realize (GnomeCanvasItem *item); +static void e_reflow_unrealize (GnomeCanvasItem *item); +static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable, + int x, int y, int width, int height); + +static void _update_reflow ( EReflow *reflow ); +static void _resize( GtkObject *object, gpointer data ); +static void _queue_reflow(EReflow *e_reflow); + +static GnomeCanvasGroupClass *parent_class = NULL; + +enum { + E_REFLOW_RESIZE, + E_REFLOW_LAST_SIGNAL +}; + +static guint e_reflow_signals[E_REFLOW_LAST_SIGNAL] = { 0 }; + +/* The arguments we take */ +enum { + ARG_0, + ARG_WIDTH, + ARG_HEIGHT +}; + +GtkType +e_reflow_get_type (void) +{ + static GtkType reflow_type = 0; + + if (!reflow_type) + { + static const GtkTypeInfo reflow_info = + { + "EReflow", + sizeof (EReflow), + sizeof (EReflowClass), + (GtkClassInitFunc) e_reflow_class_init, + (GtkObjectInitFunc) e_reflow_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + reflow_type = gtk_type_unique (gnome_canvas_group_get_type (), &reflow_info); + } + + return reflow_type; +} + +static void +e_reflow_class_init (EReflowClass *klass) +{ + GtkObjectClass *object_class; + GnomeCanvasItemClass *item_class; + + object_class = (GtkObjectClass*) klass; + item_class = (GnomeCanvasItemClass *) klass; + + parent_class = gtk_type_class (gnome_canvas_group_get_type ()); + + e_reflow_signals[E_REFLOW_RESIZE] = + gtk_signal_new ("resize", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (EReflowClass, resize), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + gtk_object_class_add_signals (object_class, e_reflow_signals, E_REFLOW_LAST_SIGNAL); + + gtk_object_add_arg_type ("EReflow::width", GTK_TYPE_DOUBLE, + GTK_ARG_READABLE, ARG_WIDTH); + gtk_object_add_arg_type ("EReflow::height", GTK_TYPE_DOUBLE, + GTK_ARG_READWRITE, ARG_HEIGHT); + + object_class->set_arg = e_reflow_set_arg; + object_class->get_arg = e_reflow_get_arg; + /* object_class->destroy = e_reflow_destroy; */ + + /* GnomeCanvasItem method overrides */ + item_class->event = e_reflow_event; + item_class->realize = e_reflow_realize; + item_class->unrealize = e_reflow_unrealize; + /* item_class->draw = e_reflow_draw;*/ +} + +static void +e_reflow_init (EReflow *reflow) +{ + /* reflow->card = NULL;*/ + reflow->items = NULL; + reflow->columns = NULL; + reflow->column_width = 150; + + reflow->width = 10; + reflow->height = 10; + reflow->idle = 0; +} + +static void +e_reflow_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) +{ + GnomeCanvasItem *item; + EReflow *e_reflow; + + item = GNOME_CANVAS_ITEM (o); + e_reflow = E_REFLOW (o); + + switch (arg_id){ + case ARG_HEIGHT: + e_reflow->height = GTK_VALUE_DOUBLE (*arg); + _update_reflow(e_reflow); + gnome_canvas_item_request_update (item); + break; + } +} + +static void +e_reflow_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) +{ + EReflow *e_reflow; + + e_reflow = E_REFLOW (object); + + switch (arg_id) { + case ARG_WIDTH: + GTK_VALUE_DOUBLE (*arg) = e_reflow->width; + break; + case ARG_HEIGHT: + GTK_VALUE_DOUBLE (*arg) = e_reflow->height; + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} + +static void +e_reflow_realize (GnomeCanvasItem *item) +{ + EReflow *e_reflow; + GnomeCanvasGroup *group; + GList *list; + + e_reflow = E_REFLOW (item); + group = GNOME_CANVAS_GROUP( item ); + + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) + (* GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) (item); + + for(list = e_reflow->items; list; list = g_list_next(list)) { + GnomeCanvasItem *item = GNOME_CANVAS_ITEM(list->data); + gtk_signal_connect(GTK_OBJECT(item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_reflow); + gnome_canvas_item_set(item, + "width", (double) e_reflow->column_width, + NULL); + } + + _update_reflow( e_reflow ); + + if (!item->canvas->aa) { + } +} + +static void +e_reflow_unrealize (GnomeCanvasItem *item) +{ + EReflow *e_reflow; + + e_reflow = E_REFLOW (item); + + if (!item->canvas->aa) + { + } + + g_list_free (e_reflow->items); + g_list_free (e_reflow->columns); + + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) + (* GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) (item); +} + +static gboolean +e_reflow_event (GnomeCanvasItem *item, GdkEvent *event) +{ + EReflow *e_reflow; + + e_reflow = E_REFLOW (item); + + switch( event->type ) + { + case GDK_KEY_PRESS: + if (event->key.length == 1 && event->key.string[0] == '\t') { + GList *list; + for (list = e_reflow->items; list; list = list->next) { + GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); + gboolean has_focus; + gtk_object_get(GTK_OBJECT(item), + "has_focus", &has_focus, + NULL); + if (has_focus) { + if (event->key.state & GDK_SHIFT_MASK) + list = list->prev; + else + list = list->next; + if (list) { + item = GNOME_CANVAS_ITEM(list->data); + gnome_canvas_item_set(item, + "has_focus", TRUE, + NULL); + return 1; + } else { + return 0; + } + } + } + } + default: + break; + } + + if (GNOME_CANVAS_ITEM_CLASS( parent_class )->event) + return (* GNOME_CANVAS_ITEM_CLASS( parent_class )->event) (item, event); + else + return 0; +} + +void +e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item) +{ + e_reflow->items = g_list_append(e_reflow->items, item); + if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { + gtk_signal_connect(GTK_OBJECT(item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_reflow); + gnome_canvas_item_set(item, + "width", (double) e_reflow->column_width, + NULL); + _queue_reflow(e_reflow); + } + +} +#if 0 +static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable, + int x, int y, int width, int height) +{ + int x_rect, y_rect, width_rect, height_rect; + gint running_width; + EReflow *e_reflow = E_REFLOW(item); + int i; + + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->draw) + GNOME_CANVAS_ITEM_CLASS(parent_class)->draw (item, drawable, x, y, width, height); + + running_width = 7 + e_reflow->column_width + 7; + x_rect = running_width; + y_rect = 7; + width_rect = 2; + height_rect = e_reflow->height - 14; + + for (i = 0; i < e_reflow->column_count - 1; i++) { + x_rect = running_width; + gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style, + drawable, + GTK_STATE_ACTIVE, + GTK_SHADOW_NONE, + NULL, + GTK_WIDGET(item->canvas), + "reflow", + x_rect - x, + y_rect - x, + width_rect, + height_rect); + running_width += 2 + 7 + e_reflow->column_width + 7; + } +} +#endif + +static void +_reflow( EReflow *e_reflow ) +{ + int running_height; + GList *list; + double item_height; + + if (e_reflow->columns) { + g_list_free (e_reflow->columns); + e_reflow->columns = NULL; + } + + e_reflow->column_count = 0; + + if (e_reflow->items == NULL) { + e_reflow->columns = NULL; + e_reflow->column_count = 1; + return; + } + + list = e_reflow->items; + + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + running_height = 7 + item_height + 7; + e_reflow->columns = g_list_append (e_reflow->columns, list); + e_reflow->column_count = 1; + + list = g_list_next(list); + + for ( ; list; list = g_list_next(list)) { + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + if (running_height + item_height + 7 > e_reflow->height) { + running_height = 7 + item_height + 7; + e_reflow->columns = g_list_append (e_reflow->columns, list); + e_reflow->column_count ++; + } else { + running_height += item_height + 7; + } + } +} + +static void +_update_reflow( EReflow *e_reflow ) +{ + if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { + + gint old_width; + gint running_width; + + _reflow (e_reflow); + + old_width = e_reflow->width; + + running_width = 7; + + if (e_reflow->items == NULL) { + } else { + GList *list; + GList *next_column; + gdouble item_height; + gint running_height; + + running_height = 7; + + list = e_reflow->items; + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), + (double) running_width, + (double) running_height); + running_height += item_height + 7; + next_column = g_list_next(e_reflow->columns); + list = g_list_next(list); + + for( ; list; list = g_list_next(list)) { + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + + if (next_column && (next_column->data == list)) { + next_column = g_list_next (next_column); + running_height = 7; + running_width += e_reflow->column_width + 7 + 2 + 7; + } + e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), + (double) running_width, + (double) running_height); + + running_height += item_height + 7; + } + + } + e_reflow->width = running_width + e_reflow->column_width + 7; + if (old_width != e_reflow->width) + gtk_signal_emit_by_name (GTK_OBJECT (e_reflow), "resize"); + } +} + + +static gboolean +_idle_reflow(gpointer data) +{ + EReflow *e_reflow = E_REFLOW(data); + _update_reflow(e_reflow); + e_reflow->idle = 0; + return FALSE; +} + +static void +_queue_reflow(EReflow *e_reflow) +{ + if (e_reflow->idle == 0) + e_reflow->idle = g_idle_add(_idle_reflow, e_reflow); +} + +static void +_resize( GtkObject *object, gpointer data ) +{ + _queue_reflow(E_REFLOW(data)); +} diff --git a/widgets/e-reflow.h b/widgets/e-reflow.h new file mode 100644 index 0000000000..0d0ab4251a --- /dev/null +++ b/widgets/e-reflow.h @@ -0,0 +1,88 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* e-reflow.h + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef __E_REFLOW_H__ +#define __E_REFLOW_H__ + +#include <gnome.h> + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +/* EReflow - A canvas item container. + * + * The following arguments are available: + * + * name type read/write description + * -------------------------------------------------------------------------------- + * width double R width of the reflow + * height double RW height of the reflow + */ + +#define E_REFLOW_TYPE (e_reflow_get_type ()) +#define E_REFLOW(obj) (GTK_CHECK_CAST ((obj), E_REFLOW_TYPE, EReflow)) +#define E_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_REFLOW_TYPE, EReflowClass)) +#define E_IS_REFLOW(obj) (GTK_CHECK_TYPE ((obj), E_REFLOW_TYPE)) +#define E_IS_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_REFLOW_TYPE)) + + +typedef struct _EReflow EReflow; +typedef struct _EReflowClass EReflowClass; + +struct _EReflow +{ + GnomeCanvasGroup parent; + + /* item specific fields */ + /* EBook *book; */ + + GList *items; /* Of type GnomeCanvasItem */ + GList *columns; /* Of type GList pointing to type GnomeCanvasItem (points into items) */ + gint column_count; /* Number of columnns */ + + double width; + double height; + + double column_width; + + int idle; +}; + +struct _EReflowClass +{ + GnomeCanvasGroupClass parent_class; + + void (* resize) (EReflow *reflow); +}; + +/* To be added to a reflow, an item must have the arguments "x", "y", + and "width" as Read/Write arguments and "height" as a Read Only + argument. It must also have a "resize" signal. */ +void e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item); +GtkType e_reflow_get_type (void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __E_REFLOW_H__ */ diff --git a/widgets/e-reflow/e-reflow.c b/widgets/e-reflow/e-reflow.c new file mode 100644 index 0000000000..ce2e92e530 --- /dev/null +++ b/widgets/e-reflow/e-reflow.c @@ -0,0 +1,438 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-reflow.c + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <gnome.h> +#include "e-reflow.h" +#include "e-canvas-utils.h" +static void e_reflow_init (EReflow *card); +static void e_reflow_class_init (EReflowClass *klass); +static void e_reflow_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); +static void e_reflow_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); +static gboolean e_reflow_event (GnomeCanvasItem *item, GdkEvent *event); +static void e_reflow_realize (GnomeCanvasItem *item); +static void e_reflow_unrealize (GnomeCanvasItem *item); +static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable, + int x, int y, int width, int height); + +static void _update_reflow ( EReflow *reflow ); +static void _resize( GtkObject *object, gpointer data ); +static void _queue_reflow(EReflow *e_reflow); + +static GnomeCanvasGroupClass *parent_class = NULL; + +enum { + E_REFLOW_RESIZE, + E_REFLOW_LAST_SIGNAL +}; + +static guint e_reflow_signals[E_REFLOW_LAST_SIGNAL] = { 0 }; + +/* The arguments we take */ +enum { + ARG_0, + ARG_WIDTH, + ARG_HEIGHT +}; + +GtkType +e_reflow_get_type (void) +{ + static GtkType reflow_type = 0; + + if (!reflow_type) + { + static const GtkTypeInfo reflow_info = + { + "EReflow", + sizeof (EReflow), + sizeof (EReflowClass), + (GtkClassInitFunc) e_reflow_class_init, + (GtkObjectInitFunc) e_reflow_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + reflow_type = gtk_type_unique (gnome_canvas_group_get_type (), &reflow_info); + } + + return reflow_type; +} + +static void +e_reflow_class_init (EReflowClass *klass) +{ + GtkObjectClass *object_class; + GnomeCanvasItemClass *item_class; + + object_class = (GtkObjectClass*) klass; + item_class = (GnomeCanvasItemClass *) klass; + + parent_class = gtk_type_class (gnome_canvas_group_get_type ()); + + e_reflow_signals[E_REFLOW_RESIZE] = + gtk_signal_new ("resize", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (EReflowClass, resize), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + gtk_object_class_add_signals (object_class, e_reflow_signals, E_REFLOW_LAST_SIGNAL); + + gtk_object_add_arg_type ("EReflow::width", GTK_TYPE_DOUBLE, + GTK_ARG_READABLE, ARG_WIDTH); + gtk_object_add_arg_type ("EReflow::height", GTK_TYPE_DOUBLE, + GTK_ARG_READWRITE, ARG_HEIGHT); + + object_class->set_arg = e_reflow_set_arg; + object_class->get_arg = e_reflow_get_arg; + /* object_class->destroy = e_reflow_destroy; */ + + /* GnomeCanvasItem method overrides */ + item_class->event = e_reflow_event; + item_class->realize = e_reflow_realize; + item_class->unrealize = e_reflow_unrealize; + /* item_class->draw = e_reflow_draw;*/ +} + +static void +e_reflow_init (EReflow *reflow) +{ + /* reflow->card = NULL;*/ + reflow->items = NULL; + reflow->columns = NULL; + reflow->column_width = 150; + + reflow->width = 10; + reflow->height = 10; + reflow->idle = 0; +} + +static void +e_reflow_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) +{ + GnomeCanvasItem *item; + EReflow *e_reflow; + + item = GNOME_CANVAS_ITEM (o); + e_reflow = E_REFLOW (o); + + switch (arg_id){ + case ARG_HEIGHT: + e_reflow->height = GTK_VALUE_DOUBLE (*arg); + _update_reflow(e_reflow); + gnome_canvas_item_request_update (item); + break; + } +} + +static void +e_reflow_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) +{ + EReflow *e_reflow; + + e_reflow = E_REFLOW (object); + + switch (arg_id) { + case ARG_WIDTH: + GTK_VALUE_DOUBLE (*arg) = e_reflow->width; + break; + case ARG_HEIGHT: + GTK_VALUE_DOUBLE (*arg) = e_reflow->height; + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} + +static void +e_reflow_realize (GnomeCanvasItem *item) +{ + EReflow *e_reflow; + GnomeCanvasGroup *group; + GList *list; + + e_reflow = E_REFLOW (item); + group = GNOME_CANVAS_GROUP( item ); + + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) + (* GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) (item); + + for(list = e_reflow->items; list; list = g_list_next(list)) { + GnomeCanvasItem *item = GNOME_CANVAS_ITEM(list->data); + gtk_signal_connect(GTK_OBJECT(item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_reflow); + gnome_canvas_item_set(item, + "width", (double) e_reflow->column_width, + NULL); + } + + _update_reflow( e_reflow ); + + if (!item->canvas->aa) { + } +} + +static void +e_reflow_unrealize (GnomeCanvasItem *item) +{ + EReflow *e_reflow; + + e_reflow = E_REFLOW (item); + + if (!item->canvas->aa) + { + } + + g_list_free (e_reflow->items); + g_list_free (e_reflow->columns); + + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) + (* GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) (item); +} + +static gboolean +e_reflow_event (GnomeCanvasItem *item, GdkEvent *event) +{ + EReflow *e_reflow; + + e_reflow = E_REFLOW (item); + + switch( event->type ) + { + case GDK_KEY_PRESS: + if (event->key.length == 1 && event->key.string[0] == '\t') { + GList *list; + for (list = e_reflow->items; list; list = list->next) { + GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); + gboolean has_focus; + gtk_object_get(GTK_OBJECT(item), + "has_focus", &has_focus, + NULL); + if (has_focus) { + if (event->key.state & GDK_SHIFT_MASK) + list = list->prev; + else + list = list->next; + if (list) { + item = GNOME_CANVAS_ITEM(list->data); + gnome_canvas_item_set(item, + "has_focus", TRUE, + NULL); + return 1; + } else { + return 0; + } + } + } + } + default: + break; + } + + if (GNOME_CANVAS_ITEM_CLASS( parent_class )->event) + return (* GNOME_CANVAS_ITEM_CLASS( parent_class )->event) (item, event); + else + return 0; +} + +void +e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item) +{ + e_reflow->items = g_list_append(e_reflow->items, item); + if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { + gtk_signal_connect(GTK_OBJECT(item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_reflow); + gnome_canvas_item_set(item, + "width", (double) e_reflow->column_width, + NULL); + _queue_reflow(e_reflow); + } + +} +#if 0 +static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable, + int x, int y, int width, int height) +{ + int x_rect, y_rect, width_rect, height_rect; + gint running_width; + EReflow *e_reflow = E_REFLOW(item); + int i; + + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->draw) + GNOME_CANVAS_ITEM_CLASS(parent_class)->draw (item, drawable, x, y, width, height); + + running_width = 7 + e_reflow->column_width + 7; + x_rect = running_width; + y_rect = 7; + width_rect = 2; + height_rect = e_reflow->height - 14; + + for (i = 0; i < e_reflow->column_count - 1; i++) { + x_rect = running_width; + gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style, + drawable, + GTK_STATE_ACTIVE, + GTK_SHADOW_NONE, + NULL, + GTK_WIDGET(item->canvas), + "reflow", + x_rect - x, + y_rect - x, + width_rect, + height_rect); + running_width += 2 + 7 + e_reflow->column_width + 7; + } +} +#endif + +static void +_reflow( EReflow *e_reflow ) +{ + int running_height; + GList *list; + double item_height; + + if (e_reflow->columns) { + g_list_free (e_reflow->columns); + e_reflow->columns = NULL; + } + + e_reflow->column_count = 0; + + if (e_reflow->items == NULL) { + e_reflow->columns = NULL; + e_reflow->column_count = 1; + return; + } + + list = e_reflow->items; + + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + running_height = 7 + item_height + 7; + e_reflow->columns = g_list_append (e_reflow->columns, list); + e_reflow->column_count = 1; + + list = g_list_next(list); + + for ( ; list; list = g_list_next(list)) { + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + if (running_height + item_height + 7 > e_reflow->height) { + running_height = 7 + item_height + 7; + e_reflow->columns = g_list_append (e_reflow->columns, list); + e_reflow->column_count ++; + } else { + running_height += item_height + 7; + } + } +} + +static void +_update_reflow( EReflow *e_reflow ) +{ + if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { + + gint old_width; + gint running_width; + + _reflow (e_reflow); + + old_width = e_reflow->width; + + running_width = 7; + + if (e_reflow->items == NULL) { + } else { + GList *list; + GList *next_column; + gdouble item_height; + gint running_height; + + running_height = 7; + + list = e_reflow->items; + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), + (double) running_width, + (double) running_height); + running_height += item_height + 7; + next_column = g_list_next(e_reflow->columns); + list = g_list_next(list); + + for( ; list; list = g_list_next(list)) { + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + + if (next_column && (next_column->data == list)) { + next_column = g_list_next (next_column); + running_height = 7; + running_width += e_reflow->column_width + 7 + 2 + 7; + } + e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), + (double) running_width, + (double) running_height); + + running_height += item_height + 7; + } + + } + e_reflow->width = running_width + e_reflow->column_width + 7; + if (old_width != e_reflow->width) + gtk_signal_emit_by_name (GTK_OBJECT (e_reflow), "resize"); + } +} + + +static gboolean +_idle_reflow(gpointer data) +{ + EReflow *e_reflow = E_REFLOW(data); + _update_reflow(e_reflow); + e_reflow->idle = 0; + return FALSE; +} + +static void +_queue_reflow(EReflow *e_reflow) +{ + if (e_reflow->idle == 0) + e_reflow->idle = g_idle_add(_idle_reflow, e_reflow); +} + +static void +_resize( GtkObject *object, gpointer data ) +{ + _queue_reflow(E_REFLOW(data)); +} diff --git a/widgets/e-reflow/e-reflow.h b/widgets/e-reflow/e-reflow.h new file mode 100644 index 0000000000..0d0ab4251a --- /dev/null +++ b/widgets/e-reflow/e-reflow.h @@ -0,0 +1,88 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* e-reflow.h + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef __E_REFLOW_H__ +#define __E_REFLOW_H__ + +#include <gnome.h> + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +/* EReflow - A canvas item container. + * + * The following arguments are available: + * + * name type read/write description + * -------------------------------------------------------------------------------- + * width double R width of the reflow + * height double RW height of the reflow + */ + +#define E_REFLOW_TYPE (e_reflow_get_type ()) +#define E_REFLOW(obj) (GTK_CHECK_CAST ((obj), E_REFLOW_TYPE, EReflow)) +#define E_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_REFLOW_TYPE, EReflowClass)) +#define E_IS_REFLOW(obj) (GTK_CHECK_TYPE ((obj), E_REFLOW_TYPE)) +#define E_IS_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_REFLOW_TYPE)) + + +typedef struct _EReflow EReflow; +typedef struct _EReflowClass EReflowClass; + +struct _EReflow +{ + GnomeCanvasGroup parent; + + /* item specific fields */ + /* EBook *book; */ + + GList *items; /* Of type GnomeCanvasItem */ + GList *columns; /* Of type GList pointing to type GnomeCanvasItem (points into items) */ + gint column_count; /* Number of columnns */ + + double width; + double height; + + double column_width; + + int idle; +}; + +struct _EReflowClass +{ + GnomeCanvasGroupClass parent_class; + + void (* resize) (EReflow *reflow); +}; + +/* To be added to a reflow, an item must have the arguments "x", "y", + and "width" as Read/Write arguments and "height" as a Read Only + argument. It must also have a "resize" signal. */ +void e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item); +GtkType e_reflow_get_type (void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __E_REFLOW_H__ */ diff --git a/widgets/e-text.c b/widgets/e-text.c index 023ad2428d..99e35348b9 100644 --- a/widgets/e-text.c +++ b/widgets/e-text.c @@ -75,6 +75,12 @@ enum { }; +enum { + TARGET_STRING, + TARGET_TEXT, + TARGET_COMPOUND_TEXT +}; + static void e_text_class_init (ETextClass *class); static void e_text_init (EText *text); static void e_text_destroy (GtkObject *object); @@ -96,6 +102,8 @@ static gint e_text_event (GnomeCanvasItem *item, GdkEvent *event); static void e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data); +static guint32 e_text_get_event_time (EText *text); + static ETextSuckFont *e_suck_font (GdkFont *font); static void e_suck_font_free (ETextSuckFont *suckfont); @@ -1124,7 +1132,7 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) { EText *text; - GdkRectangle rect; + GdkRectangle rect, *clip_rect; struct line *lines; int i; int xpos, ypos; @@ -1140,6 +1148,7 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, if (!text->text || !text->font) return; + clip_rect = NULL; if (text->clip) { rect.x = text->clip_cx - x; rect.y = text->clip_cy - y; @@ -1148,6 +1157,7 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, gdk_gc_set_clip_rectangle (text->gc, &rect); gdk_gc_set_clip_rectangle (GTK_WIDGET(canvas)->style->fg_gc[GTK_STATE_SELECTED], &rect); + clip_rect = ▭ } lines = text->lines; ypos = text->cy + text->font->ascent; @@ -1182,13 +1192,17 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, lines->text + sel_start - start_char, sel_end - sel_start); sel_rect.height = text->font->ascent + text->font->descent; - gdk_draw_rectangle (drawable, - text->gc, - TRUE, - sel_rect.x, - sel_rect.y, - sel_rect.width, - sel_rect.height); + gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style, + drawable, + GTK_STATE_SELECTED, + GTK_SHADOW_NONE, + clip_rect, + GTK_WIDGET(item->canvas), + "text", + sel_rect.x, + sel_rect.y, + sel_rect.width, + sel_rect.height); gdk_draw_text (drawable, text->font, text->gc, @@ -1897,6 +1911,89 @@ e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gp gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); } +#if 0 +static void +e_text_real_copy_clipboard (EText *text) +{ + guint32 time; + gint selection_start_pos; + gint selection_end_pos; + + g_return_if_fail (text != NULL); + g_return_if_fail (E_IS_TEXT (text)); + + time = gtk_text_get_event_time (text); + selection_start_pos = MIN (text->selection_start, text->selection_end); + selection_end_pos = MAX (text->selection_start, text->selection_end); + + if (selection_start_pos != selection_end_pos) + { + if (gtk_selection_owner_set (GTK_WIDGET (text->canvas), + clipboard_atom, + time)) + text->clipboard_text = ""; + } +} + +static void +e_text_real_paste_clipboard (EText *text) +{ + guint32 time; + + g_return_if_fail (text != NULL); + g_return_if_fail (E_IS_TEXT (text)); + + time = e_text_get_event_time (text); + if (text->editable) + gtk_selection_convert (GTK_WIDGET(text->widget), + clipboard_atom, + gdk_atom_intern ("COMPOUND_TEXT", FALSE), time); +} +#endif + +/* Get the timestamp of the current event. Actually, the only thing + * we really care about below is the key event + */ +static guint32 +e_text_get_event_time (EText *text) +{ + GdkEvent *event; + guint32 tm = GDK_CURRENT_TIME; + + event = gtk_get_current_event(); + + if (event) + switch (event->type) + { + case GDK_MOTION_NOTIFY: + tm = event->motion.time; break; + case GDK_BUTTON_PRESS: + case GDK_2BUTTON_PRESS: + case GDK_3BUTTON_PRESS: + case GDK_BUTTON_RELEASE: + tm = event->button.time; break; + case GDK_KEY_PRESS: + case GDK_KEY_RELEASE: + tm = event->key.time; break; + case GDK_ENTER_NOTIFY: + case GDK_LEAVE_NOTIFY: + tm = event->crossing.time; break; + case GDK_PROPERTY_NOTIFY: + tm = event->property.time; break; + case GDK_SELECTION_CLEAR: + case GDK_SELECTION_REQUEST: + case GDK_SELECTION_NOTIFY: + tm = event->selection.time; break; + case GDK_PROXIMITY_IN: + case GDK_PROXIMITY_OUT: + tm = event->proximity.time; break; + default: /* use current time */ + break; + } + gdk_event_free(event); + + return tm; +} diff --git a/widgets/e-text.h b/widgets/e-text.h index 42683a6a74..de7d28fd72 100644 --- a/widgets/e-text.h +++ b/widgets/e-text.h @@ -65,8 +65,8 @@ BEGIN_GNOME_DECLS * ellipsis string RW The characters to use as ellipsis. NULL = "...". * * These are not implemented yet: - * multi_line boolean RW Line wrap when not editing. - * multi_line_on_edit boolean RW Switch to line wrap when editing. + * line_wrap boolean RW Line wrap when not editing. + * line_wrap_on_edit boolean RW Switch to line wrap when editing. * background boolean RW Draw a background rectangle. * background_on_edit boolean RW Draw a background when editing. */ @@ -148,7 +148,7 @@ struct _EText { int selection_end; /* End of selection */ gboolean select_by_word; /* Current selection is by word */ - /* This section is for drag scrolling. */ + /* This section is for drag scrolling and blinking cursor. */ gint timeout_id; /* Current timeout id for scrolling */ GTimer *timer; /* Timer for blinking cursor and scrolling */ @@ -160,6 +160,8 @@ struct _EText { gboolean button_down; /* Is mouse button 1 down */ ETextEventProcessor *tep; /* Text Event Processor */ + + GtkWidget *invisible; /* For selection handling. */ }; struct _ETextClass { diff --git a/widgets/e-text/e-text.c b/widgets/e-text/e-text.c index 023ad2428d..99e35348b9 100644 --- a/widgets/e-text/e-text.c +++ b/widgets/e-text/e-text.c @@ -75,6 +75,12 @@ enum { }; +enum { + TARGET_STRING, + TARGET_TEXT, + TARGET_COMPOUND_TEXT +}; + static void e_text_class_init (ETextClass *class); static void e_text_init (EText *text); static void e_text_destroy (GtkObject *object); @@ -96,6 +102,8 @@ static gint e_text_event (GnomeCanvasItem *item, GdkEvent *event); static void e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data); +static guint32 e_text_get_event_time (EText *text); + static ETextSuckFont *e_suck_font (GdkFont *font); static void e_suck_font_free (ETextSuckFont *suckfont); @@ -1124,7 +1132,7 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) { EText *text; - GdkRectangle rect; + GdkRectangle rect, *clip_rect; struct line *lines; int i; int xpos, ypos; @@ -1140,6 +1148,7 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, if (!text->text || !text->font) return; + clip_rect = NULL; if (text->clip) { rect.x = text->clip_cx - x; rect.y = text->clip_cy - y; @@ -1148,6 +1157,7 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, gdk_gc_set_clip_rectangle (text->gc, &rect); gdk_gc_set_clip_rectangle (GTK_WIDGET(canvas)->style->fg_gc[GTK_STATE_SELECTED], &rect); + clip_rect = ▭ } lines = text->lines; ypos = text->cy + text->font->ascent; @@ -1182,13 +1192,17 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, lines->text + sel_start - start_char, sel_end - sel_start); sel_rect.height = text->font->ascent + text->font->descent; - gdk_draw_rectangle (drawable, - text->gc, - TRUE, - sel_rect.x, - sel_rect.y, - sel_rect.width, - sel_rect.height); + gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style, + drawable, + GTK_STATE_SELECTED, + GTK_SHADOW_NONE, + clip_rect, + GTK_WIDGET(item->canvas), + "text", + sel_rect.x, + sel_rect.y, + sel_rect.width, + sel_rect.height); gdk_draw_text (drawable, text->font, text->gc, @@ -1897,6 +1911,89 @@ e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gp gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); } +#if 0 +static void +e_text_real_copy_clipboard (EText *text) +{ + guint32 time; + gint selection_start_pos; + gint selection_end_pos; + + g_return_if_fail (text != NULL); + g_return_if_fail (E_IS_TEXT (text)); + + time = gtk_text_get_event_time (text); + selection_start_pos = MIN (text->selection_start, text->selection_end); + selection_end_pos = MAX (text->selection_start, text->selection_end); + + if (selection_start_pos != selection_end_pos) + { + if (gtk_selection_owner_set (GTK_WIDGET (text->canvas), + clipboard_atom, + time)) + text->clipboard_text = ""; + } +} + +static void +e_text_real_paste_clipboard (EText *text) +{ + guint32 time; + + g_return_if_fail (text != NULL); + g_return_if_fail (E_IS_TEXT (text)); + + time = e_text_get_event_time (text); + if (text->editable) + gtk_selection_convert (GTK_WIDGET(text->widget), + clipboard_atom, + gdk_atom_intern ("COMPOUND_TEXT", FALSE), time); +} +#endif + +/* Get the timestamp of the current event. Actually, the only thing + * we really care about below is the key event + */ +static guint32 +e_text_get_event_time (EText *text) +{ + GdkEvent *event; + guint32 tm = GDK_CURRENT_TIME; + + event = gtk_get_current_event(); + + if (event) + switch (event->type) + { + case GDK_MOTION_NOTIFY: + tm = event->motion.time; break; + case GDK_BUTTON_PRESS: + case GDK_2BUTTON_PRESS: + case GDK_3BUTTON_PRESS: + case GDK_BUTTON_RELEASE: + tm = event->button.time; break; + case GDK_KEY_PRESS: + case GDK_KEY_RELEASE: + tm = event->key.time; break; + case GDK_ENTER_NOTIFY: + case GDK_LEAVE_NOTIFY: + tm = event->crossing.time; break; + case GDK_PROPERTY_NOTIFY: + tm = event->property.time; break; + case GDK_SELECTION_CLEAR: + case GDK_SELECTION_REQUEST: + case GDK_SELECTION_NOTIFY: + tm = event->selection.time; break; + case GDK_PROXIMITY_IN: + case GDK_PROXIMITY_OUT: + tm = event->proximity.time; break; + default: /* use current time */ + break; + } + gdk_event_free(event); + + return tm; +} diff --git a/widgets/e-text/e-text.h b/widgets/e-text/e-text.h index 42683a6a74..de7d28fd72 100644 --- a/widgets/e-text/e-text.h +++ b/widgets/e-text/e-text.h @@ -65,8 +65,8 @@ BEGIN_GNOME_DECLS * ellipsis string RW The characters to use as ellipsis. NULL = "...". * * These are not implemented yet: - * multi_line boolean RW Line wrap when not editing. - * multi_line_on_edit boolean RW Switch to line wrap when editing. + * line_wrap boolean RW Line wrap when not editing. + * line_wrap_on_edit boolean RW Switch to line wrap when editing. * background boolean RW Draw a background rectangle. * background_on_edit boolean RW Draw a background when editing. */ @@ -148,7 +148,7 @@ struct _EText { int selection_end; /* End of selection */ gboolean select_by_word; /* Current selection is by word */ - /* This section is for drag scrolling. */ + /* This section is for drag scrolling and blinking cursor. */ gint timeout_id; /* Current timeout id for scrolling */ GTimer *timer; /* Timer for blinking cursor and scrolling */ @@ -160,6 +160,8 @@ struct _EText { gboolean button_down; /* Is mouse button 1 down */ ETextEventProcessor *tep; /* Text Event Processor */ + + GtkWidget *invisible; /* For selection handling. */ }; struct _ETextClass { diff --git a/widgets/misc/e-canvas-utils.c b/widgets/misc/e-canvas-utils.c new file mode 100644 index 0000000000..2b50248124 --- /dev/null +++ b/widgets/misc/e-canvas-utils.c @@ -0,0 +1,36 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-canvas-utils.c + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "e-canvas-utils.h" + +void +e_canvas_item_move_absolute (GnomeCanvasItem *item, double dx, double dy) +{ + double translate[6]; + + g_return_if_fail (item != NULL); + g_return_if_fail (GNOME_IS_CANVAS_ITEM (item)); + + art_affine_translate (translate, dx, dy); + + gnome_canvas_item_affine_absolute (item, translate); +} diff --git a/widgets/misc/e-canvas-utils.h b/widgets/misc/e-canvas-utils.h new file mode 100644 index 0000000000..13ec43117c --- /dev/null +++ b/widgets/misc/e-canvas-utils.h @@ -0,0 +1,24 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-canvas-utils.c + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <gnome.h> +void e_canvas_item_move_absolute (GnomeCanvasItem *item, double dx, double dy); diff --git a/widgets/misc/e-reflow.c b/widgets/misc/e-reflow.c new file mode 100644 index 0000000000..ce2e92e530 --- /dev/null +++ b/widgets/misc/e-reflow.c @@ -0,0 +1,438 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * e-reflow.c + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <gnome.h> +#include "e-reflow.h" +#include "e-canvas-utils.h" +static void e_reflow_init (EReflow *card); +static void e_reflow_class_init (EReflowClass *klass); +static void e_reflow_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); +static void e_reflow_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); +static gboolean e_reflow_event (GnomeCanvasItem *item, GdkEvent *event); +static void e_reflow_realize (GnomeCanvasItem *item); +static void e_reflow_unrealize (GnomeCanvasItem *item); +static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable, + int x, int y, int width, int height); + +static void _update_reflow ( EReflow *reflow ); +static void _resize( GtkObject *object, gpointer data ); +static void _queue_reflow(EReflow *e_reflow); + +static GnomeCanvasGroupClass *parent_class = NULL; + +enum { + E_REFLOW_RESIZE, + E_REFLOW_LAST_SIGNAL +}; + +static guint e_reflow_signals[E_REFLOW_LAST_SIGNAL] = { 0 }; + +/* The arguments we take */ +enum { + ARG_0, + ARG_WIDTH, + ARG_HEIGHT +}; + +GtkType +e_reflow_get_type (void) +{ + static GtkType reflow_type = 0; + + if (!reflow_type) + { + static const GtkTypeInfo reflow_info = + { + "EReflow", + sizeof (EReflow), + sizeof (EReflowClass), + (GtkClassInitFunc) e_reflow_class_init, + (GtkObjectInitFunc) e_reflow_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + reflow_type = gtk_type_unique (gnome_canvas_group_get_type (), &reflow_info); + } + + return reflow_type; +} + +static void +e_reflow_class_init (EReflowClass *klass) +{ + GtkObjectClass *object_class; + GnomeCanvasItemClass *item_class; + + object_class = (GtkObjectClass*) klass; + item_class = (GnomeCanvasItemClass *) klass; + + parent_class = gtk_type_class (gnome_canvas_group_get_type ()); + + e_reflow_signals[E_REFLOW_RESIZE] = + gtk_signal_new ("resize", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (EReflowClass, resize), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + gtk_object_class_add_signals (object_class, e_reflow_signals, E_REFLOW_LAST_SIGNAL); + + gtk_object_add_arg_type ("EReflow::width", GTK_TYPE_DOUBLE, + GTK_ARG_READABLE, ARG_WIDTH); + gtk_object_add_arg_type ("EReflow::height", GTK_TYPE_DOUBLE, + GTK_ARG_READWRITE, ARG_HEIGHT); + + object_class->set_arg = e_reflow_set_arg; + object_class->get_arg = e_reflow_get_arg; + /* object_class->destroy = e_reflow_destroy; */ + + /* GnomeCanvasItem method overrides */ + item_class->event = e_reflow_event; + item_class->realize = e_reflow_realize; + item_class->unrealize = e_reflow_unrealize; + /* item_class->draw = e_reflow_draw;*/ +} + +static void +e_reflow_init (EReflow *reflow) +{ + /* reflow->card = NULL;*/ + reflow->items = NULL; + reflow->columns = NULL; + reflow->column_width = 150; + + reflow->width = 10; + reflow->height = 10; + reflow->idle = 0; +} + +static void +e_reflow_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) +{ + GnomeCanvasItem *item; + EReflow *e_reflow; + + item = GNOME_CANVAS_ITEM (o); + e_reflow = E_REFLOW (o); + + switch (arg_id){ + case ARG_HEIGHT: + e_reflow->height = GTK_VALUE_DOUBLE (*arg); + _update_reflow(e_reflow); + gnome_canvas_item_request_update (item); + break; + } +} + +static void +e_reflow_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) +{ + EReflow *e_reflow; + + e_reflow = E_REFLOW (object); + + switch (arg_id) { + case ARG_WIDTH: + GTK_VALUE_DOUBLE (*arg) = e_reflow->width; + break; + case ARG_HEIGHT: + GTK_VALUE_DOUBLE (*arg) = e_reflow->height; + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} + +static void +e_reflow_realize (GnomeCanvasItem *item) +{ + EReflow *e_reflow; + GnomeCanvasGroup *group; + GList *list; + + e_reflow = E_REFLOW (item); + group = GNOME_CANVAS_GROUP( item ); + + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) + (* GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) (item); + + for(list = e_reflow->items; list; list = g_list_next(list)) { + GnomeCanvasItem *item = GNOME_CANVAS_ITEM(list->data); + gtk_signal_connect(GTK_OBJECT(item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_reflow); + gnome_canvas_item_set(item, + "width", (double) e_reflow->column_width, + NULL); + } + + _update_reflow( e_reflow ); + + if (!item->canvas->aa) { + } +} + +static void +e_reflow_unrealize (GnomeCanvasItem *item) +{ + EReflow *e_reflow; + + e_reflow = E_REFLOW (item); + + if (!item->canvas->aa) + { + } + + g_list_free (e_reflow->items); + g_list_free (e_reflow->columns); + + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) + (* GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) (item); +} + +static gboolean +e_reflow_event (GnomeCanvasItem *item, GdkEvent *event) +{ + EReflow *e_reflow; + + e_reflow = E_REFLOW (item); + + switch( event->type ) + { + case GDK_KEY_PRESS: + if (event->key.length == 1 && event->key.string[0] == '\t') { + GList *list; + for (list = e_reflow->items; list; list = list->next) { + GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); + gboolean has_focus; + gtk_object_get(GTK_OBJECT(item), + "has_focus", &has_focus, + NULL); + if (has_focus) { + if (event->key.state & GDK_SHIFT_MASK) + list = list->prev; + else + list = list->next; + if (list) { + item = GNOME_CANVAS_ITEM(list->data); + gnome_canvas_item_set(item, + "has_focus", TRUE, + NULL); + return 1; + } else { + return 0; + } + } + } + } + default: + break; + } + + if (GNOME_CANVAS_ITEM_CLASS( parent_class )->event) + return (* GNOME_CANVAS_ITEM_CLASS( parent_class )->event) (item, event); + else + return 0; +} + +void +e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item) +{ + e_reflow->items = g_list_append(e_reflow->items, item); + if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { + gtk_signal_connect(GTK_OBJECT(item), + "resize", + GTK_SIGNAL_FUNC(_resize), + (gpointer) e_reflow); + gnome_canvas_item_set(item, + "width", (double) e_reflow->column_width, + NULL); + _queue_reflow(e_reflow); + } + +} +#if 0 +static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable, + int x, int y, int width, int height) +{ + int x_rect, y_rect, width_rect, height_rect; + gint running_width; + EReflow *e_reflow = E_REFLOW(item); + int i; + + if (GNOME_CANVAS_ITEM_CLASS(parent_class)->draw) + GNOME_CANVAS_ITEM_CLASS(parent_class)->draw (item, drawable, x, y, width, height); + + running_width = 7 + e_reflow->column_width + 7; + x_rect = running_width; + y_rect = 7; + width_rect = 2; + height_rect = e_reflow->height - 14; + + for (i = 0; i < e_reflow->column_count - 1; i++) { + x_rect = running_width; + gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style, + drawable, + GTK_STATE_ACTIVE, + GTK_SHADOW_NONE, + NULL, + GTK_WIDGET(item->canvas), + "reflow", + x_rect - x, + y_rect - x, + width_rect, + height_rect); + running_width += 2 + 7 + e_reflow->column_width + 7; + } +} +#endif + +static void +_reflow( EReflow *e_reflow ) +{ + int running_height; + GList *list; + double item_height; + + if (e_reflow->columns) { + g_list_free (e_reflow->columns); + e_reflow->columns = NULL; + } + + e_reflow->column_count = 0; + + if (e_reflow->items == NULL) { + e_reflow->columns = NULL; + e_reflow->column_count = 1; + return; + } + + list = e_reflow->items; + + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + running_height = 7 + item_height + 7; + e_reflow->columns = g_list_append (e_reflow->columns, list); + e_reflow->column_count = 1; + + list = g_list_next(list); + + for ( ; list; list = g_list_next(list)) { + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + if (running_height + item_height + 7 > e_reflow->height) { + running_height = 7 + item_height + 7; + e_reflow->columns = g_list_append (e_reflow->columns, list); + e_reflow->column_count ++; + } else { + running_height += item_height + 7; + } + } +} + +static void +_update_reflow( EReflow *e_reflow ) +{ + if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { + + gint old_width; + gint running_width; + + _reflow (e_reflow); + + old_width = e_reflow->width; + + running_width = 7; + + if (e_reflow->items == NULL) { + } else { + GList *list; + GList *next_column; + gdouble item_height; + gint running_height; + + running_height = 7; + + list = e_reflow->items; + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), + (double) running_width, + (double) running_height); + running_height += item_height + 7; + next_column = g_list_next(e_reflow->columns); + list = g_list_next(list); + + for( ; list; list = g_list_next(list)) { + gtk_object_get (GTK_OBJECT(list->data), + "height", &item_height, + NULL); + + if (next_column && (next_column->data == list)) { + next_column = g_list_next (next_column); + running_height = 7; + running_width += e_reflow->column_width + 7 + 2 + 7; + } + e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), + (double) running_width, + (double) running_height); + + running_height += item_height + 7; + } + + } + e_reflow->width = running_width + e_reflow->column_width + 7; + if (old_width != e_reflow->width) + gtk_signal_emit_by_name (GTK_OBJECT (e_reflow), "resize"); + } +} + + +static gboolean +_idle_reflow(gpointer data) +{ + EReflow *e_reflow = E_REFLOW(data); + _update_reflow(e_reflow); + e_reflow->idle = 0; + return FALSE; +} + +static void +_queue_reflow(EReflow *e_reflow) +{ + if (e_reflow->idle == 0) + e_reflow->idle = g_idle_add(_idle_reflow, e_reflow); +} + +static void +_resize( GtkObject *object, gpointer data ) +{ + _queue_reflow(E_REFLOW(data)); +} diff --git a/widgets/misc/e-reflow.h b/widgets/misc/e-reflow.h new file mode 100644 index 0000000000..0d0ab4251a --- /dev/null +++ b/widgets/misc/e-reflow.h @@ -0,0 +1,88 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* e-reflow.h + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef __E_REFLOW_H__ +#define __E_REFLOW_H__ + +#include <gnome.h> + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +/* EReflow - A canvas item container. + * + * The following arguments are available: + * + * name type read/write description + * -------------------------------------------------------------------------------- + * width double R width of the reflow + * height double RW height of the reflow + */ + +#define E_REFLOW_TYPE (e_reflow_get_type ()) +#define E_REFLOW(obj) (GTK_CHECK_CAST ((obj), E_REFLOW_TYPE, EReflow)) +#define E_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_REFLOW_TYPE, EReflowClass)) +#define E_IS_REFLOW(obj) (GTK_CHECK_TYPE ((obj), E_REFLOW_TYPE)) +#define E_IS_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_REFLOW_TYPE)) + + +typedef struct _EReflow EReflow; +typedef struct _EReflowClass EReflowClass; + +struct _EReflow +{ + GnomeCanvasGroup parent; + + /* item specific fields */ + /* EBook *book; */ + + GList *items; /* Of type GnomeCanvasItem */ + GList *columns; /* Of type GList pointing to type GnomeCanvasItem (points into items) */ + gint column_count; /* Number of columnns */ + + double width; + double height; + + double column_width; + + int idle; +}; + +struct _EReflowClass +{ + GnomeCanvasGroupClass parent_class; + + void (* resize) (EReflow *reflow); +}; + +/* To be added to a reflow, an item must have the arguments "x", "y", + and "width" as Read/Write arguments and "height" as a Read Only + argument. It must also have a "resize" signal. */ +void e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item); +GtkType e_reflow_get_type (void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __E_REFLOW_H__ */ diff --git a/widgets/test-reflow.c b/widgets/test-reflow.c new file mode 100644 index 0000000000..f03232c72d --- /dev/null +++ b/widgets/test-reflow.c @@ -0,0 +1,136 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* test-reflow.c + * + * Copyright (C) 2000 Helix Code, Inc. + * Author: Chris Lahey <clahey@helixcode.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + + + +#include "config.h" + +#include <gnome.h> +#include "e-reflow.h" +#include "e-minicard.h" + +/* This is a horrible thing to do, but it is just a test. */ +GnomeCanvasItem *reflow; +GnomeCanvasItem *rect; + +static void destroy_callback(GtkWidget *app, gpointer data) +{ + exit(0); +} + +static void allocate_callback(GtkWidget *canvas, GtkAllocation *allocation, gpointer data) +{ + double width; + gnome_canvas_item_set( reflow, + "height", (double) allocation->height, + NULL ); + gtk_object_get(GTK_OBJECT(reflow), + "width", &width, + NULL); + width = MAX(width, allocation->width); + gnome_canvas_set_scroll_region(GNOME_CANVAS( canvas ), 0, 0, width, allocation->height ); + gnome_canvas_item_set( rect, + "x2", (double) width, + "y2", (double) allocation->height, + NULL ); +} + +static void about_callback( GtkWidget *widget, gpointer data ) +{ + + const gchar *authors[] = + { + "Christopher James Lahey <clahey@umich.edu>", + NULL + }; + + GtkWidget *about = + gnome_about_new ( _( "Reflow Test" ), VERSION, + _( "Copyright (C) 2000, Helix Code, Inc." ), + authors, + _( "This should test the reflow canvas item" ), + NULL); + gtk_widget_show (about); +} + +int main( int argc, char *argv[] ) +{ + GtkWidget *app; + GtkWidget *canvas; + GtkWidget *vbox; + GtkWidget *scrollbar; + int i; + + /* bindtextdomain (PACKAGE, GNOMELOCALEDIR); + textdomain (PACKAGE);*/ + + gnome_init( "Reflow Test", VERSION, argc, argv); + app = gnome_app_new("Reflow Test", NULL); + + vbox = gtk_vbox_new(FALSE, 0); + + canvas = gnome_canvas_new(); + rect = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), + gnome_canvas_rect_get_type(), + "x1", (double) 0, + "y1", (double) 0, + "x2", (double) 100, + "y2", (double) 100, + "fill_color", "white", + NULL ); + reflow = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), + e_reflow_get_type(), + "x", (double) 0, + "y", (double) 0, + "height", (double) 100, + NULL ); + for ( i = 0; i < 200; i++ ) + { + GnomeCanvasItem *item; + item = gnome_canvas_item_new( GNOME_CANVAS_GROUP(reflow), + e_minicard_get_type(), + NULL); + e_reflow_add_item(E_REFLOW(reflow), item); + } + gnome_canvas_set_scroll_region ( GNOME_CANVAS( canvas ), + 0, 0, + 100, 100 ); + + gtk_box_pack_start(GTK_BOX(vbox), canvas, TRUE, TRUE, 0); + + scrollbar = gtk_hscrollbar_new(gtk_layout_get_hadjustment(GTK_LAYOUT(canvas))); + + gtk_box_pack_start(GTK_BOX(vbox), scrollbar, FALSE, FALSE, 0); + + gnome_app_set_contents( GNOME_APP( app ), vbox ); + + /* Connect the signals */ + gtk_signal_connect( GTK_OBJECT( app ), "destroy", + GTK_SIGNAL_FUNC( destroy_callback ), + ( gpointer ) app ); + + gtk_signal_connect( GTK_OBJECT( canvas ), "size_allocate", + GTK_SIGNAL_FUNC( allocate_callback ), + ( gpointer ) app ); + + gtk_widget_show_all( app ); + + gtk_main(); + + /* Not reached. */ + return 0; +} diff --git a/widgets/text/e-text.c b/widgets/text/e-text.c index 023ad2428d..99e35348b9 100644 --- a/widgets/text/e-text.c +++ b/widgets/text/e-text.c @@ -75,6 +75,12 @@ enum { }; +enum { + TARGET_STRING, + TARGET_TEXT, + TARGET_COMPOUND_TEXT +}; + static void e_text_class_init (ETextClass *class); static void e_text_init (EText *text); static void e_text_destroy (GtkObject *object); @@ -96,6 +102,8 @@ static gint e_text_event (GnomeCanvasItem *item, GdkEvent *event); static void e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data); +static guint32 e_text_get_event_time (EText *text); + static ETextSuckFont *e_suck_font (GdkFont *font); static void e_suck_font_free (ETextSuckFont *suckfont); @@ -1124,7 +1132,7 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) { EText *text; - GdkRectangle rect; + GdkRectangle rect, *clip_rect; struct line *lines; int i; int xpos, ypos; @@ -1140,6 +1148,7 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, if (!text->text || !text->font) return; + clip_rect = NULL; if (text->clip) { rect.x = text->clip_cx - x; rect.y = text->clip_cy - y; @@ -1148,6 +1157,7 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, gdk_gc_set_clip_rectangle (text->gc, &rect); gdk_gc_set_clip_rectangle (GTK_WIDGET(canvas)->style->fg_gc[GTK_STATE_SELECTED], &rect); + clip_rect = ▭ } lines = text->lines; ypos = text->cy + text->font->ascent; @@ -1182,13 +1192,17 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, lines->text + sel_start - start_char, sel_end - sel_start); sel_rect.height = text->font->ascent + text->font->descent; - gdk_draw_rectangle (drawable, - text->gc, - TRUE, - sel_rect.x, - sel_rect.y, - sel_rect.width, - sel_rect.height); + gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style, + drawable, + GTK_STATE_SELECTED, + GTK_SHADOW_NONE, + clip_rect, + GTK_WIDGET(item->canvas), + "text", + sel_rect.x, + sel_rect.y, + sel_rect.width, + sel_rect.height); gdk_draw_text (drawable, text->font, text->gc, @@ -1897,6 +1911,89 @@ e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gp gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); } +#if 0 +static void +e_text_real_copy_clipboard (EText *text) +{ + guint32 time; + gint selection_start_pos; + gint selection_end_pos; + + g_return_if_fail (text != NULL); + g_return_if_fail (E_IS_TEXT (text)); + + time = gtk_text_get_event_time (text); + selection_start_pos = MIN (text->selection_start, text->selection_end); + selection_end_pos = MAX (text->selection_start, text->selection_end); + + if (selection_start_pos != selection_end_pos) + { + if (gtk_selection_owner_set (GTK_WIDGET (text->canvas), + clipboard_atom, + time)) + text->clipboard_text = ""; + } +} + +static void +e_text_real_paste_clipboard (EText *text) +{ + guint32 time; + + g_return_if_fail (text != NULL); + g_return_if_fail (E_IS_TEXT (text)); + + time = e_text_get_event_time (text); + if (text->editable) + gtk_selection_convert (GTK_WIDGET(text->widget), + clipboard_atom, + gdk_atom_intern ("COMPOUND_TEXT", FALSE), time); +} +#endif + +/* Get the timestamp of the current event. Actually, the only thing + * we really care about below is the key event + */ +static guint32 +e_text_get_event_time (EText *text) +{ + GdkEvent *event; + guint32 tm = GDK_CURRENT_TIME; + + event = gtk_get_current_event(); + + if (event) + switch (event->type) + { + case GDK_MOTION_NOTIFY: + tm = event->motion.time; break; + case GDK_BUTTON_PRESS: + case GDK_2BUTTON_PRESS: + case GDK_3BUTTON_PRESS: + case GDK_BUTTON_RELEASE: + tm = event->button.time; break; + case GDK_KEY_PRESS: + case GDK_KEY_RELEASE: + tm = event->key.time; break; + case GDK_ENTER_NOTIFY: + case GDK_LEAVE_NOTIFY: + tm = event->crossing.time; break; + case GDK_PROPERTY_NOTIFY: + tm = event->property.time; break; + case GDK_SELECTION_CLEAR: + case GDK_SELECTION_REQUEST: + case GDK_SELECTION_NOTIFY: + tm = event->selection.time; break; + case GDK_PROXIMITY_IN: + case GDK_PROXIMITY_OUT: + tm = event->proximity.time; break; + default: /* use current time */ + break; + } + gdk_event_free(event); + + return tm; +} diff --git a/widgets/text/e-text.h b/widgets/text/e-text.h index 42683a6a74..de7d28fd72 100644 --- a/widgets/text/e-text.h +++ b/widgets/text/e-text.h @@ -65,8 +65,8 @@ BEGIN_GNOME_DECLS * ellipsis string RW The characters to use as ellipsis. NULL = "...". * * These are not implemented yet: - * multi_line boolean RW Line wrap when not editing. - * multi_line_on_edit boolean RW Switch to line wrap when editing. + * line_wrap boolean RW Line wrap when not editing. + * line_wrap_on_edit boolean RW Switch to line wrap when editing. * background boolean RW Draw a background rectangle. * background_on_edit boolean RW Draw a background when editing. */ @@ -148,7 +148,7 @@ struct _EText { int selection_end; /* End of selection */ gboolean select_by_word; /* Current selection is by word */ - /* This section is for drag scrolling. */ + /* This section is for drag scrolling and blinking cursor. */ gint timeout_id; /* Current timeout id for scrolling */ GTimer *timer; /* Timer for blinking cursor and scrolling */ @@ -160,6 +160,8 @@ struct _EText { gboolean button_down; /* Is mouse button 1 down */ ETextEventProcessor *tep; /* Text Event Processor */ + + GtkWidget *invisible; /* For selection handling. */ }; struct _ETextClass { |