aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui/widgets
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@ximian.com>2001-03-01 16:43:28 +0800
committerChris Lahey <clahey@src.gnome.org>2001-03-01 16:43:28 +0800
commit92d19d2d4f989a021a6587755689b7439c7fb064 (patch)
tree1b1de8956425713bb497983620ffb3011964b086 /addressbook/gui/widgets
parenta4fe250a03ac4b9571dd4da9e9d83e941046775b (diff)
downloadgsoc2013-evolution-92d19d2d4f989a021a6587755689b7439c7fb064.tar
gsoc2013-evolution-92d19d2d4f989a021a6587755689b7439c7fb064.tar.gz
gsoc2013-evolution-92d19d2d4f989a021a6587755689b7439c7fb064.tar.bz2
gsoc2013-evolution-92d19d2d4f989a021a6587755689b7439c7fb064.tar.lz
gsoc2013-evolution-92d19d2d4f989a021a6587755689b7439c7fb064.tar.xz
gsoc2013-evolution-92d19d2d4f989a021a6587755689b7439c7fb064.tar.zst
gsoc2013-evolution-92d19d2d4f989a021a6587755689b7439c7fb064.zip
Used ESelectionModelSimple and the changes to EReflow and EReflowSorted to
2001-03-01 Christopher James Lahey <clahey@ximian.com> * gui/widgets/e-minicard-view.c, gui/widgets/e-minicard-view.h, gui/widgets/e-minicard.c, gui/widgets/e-minicard.h: Used ESelectionModelSimple and the changes to EReflow and EReflowSorted to get multiple selection in the minicard view. * gui/widgets/test-reflow.c: Changed this to get it to compile with the changes to EReflow. svn path=/trunk/; revision=8444
Diffstat (limited to 'addressbook/gui/widgets')
-rw-r--r--addressbook/gui/widgets/e-minicard-view.c103
-rw-r--r--addressbook/gui/widgets/e-minicard-view.h3
-rw-r--r--addressbook/gui/widgets/e-minicard.c140
-rw-r--r--addressbook/gui/widgets/e-minicard.h8
-rw-r--r--addressbook/gui/widgets/test-reflow.c2
5 files changed, 189 insertions, 67 deletions
diff --git a/addressbook/gui/widgets/e-minicard-view.c b/addressbook/gui/widgets/e-minicard-view.c
index d3f08b71ab..3e3b1ceaf0 100644
--- a/addressbook/gui/widgets/e-minicard-view.c
+++ b/addressbook/gui/widgets/e-minicard-view.c
@@ -34,6 +34,7 @@ static void e_minicard_view_destroy (GtkObject *object);
static gboolean e_minicard_view_event (GnomeCanvasItem *item, GdkEvent *event);
static void canvas_destroy (GtkObject *object, EMinicardView *view);
static void disconnect_signals (EMinicardView *view);
+static void e_minicard_view_update_selection (EMinicardView *view);
static EReflowSortedClass *parent_class = NULL;
@@ -112,6 +113,12 @@ e_minicard_view_class_init (EMinicardViewClass *klass)
}
static void
+selection_changed (ESelectionModel *selection, EMinicardView *view)
+{
+ e_minicard_view_update_selection (view);
+}
+
+static void
e_minicard_view_init (EMinicardView *view)
{
view->book = NULL;
@@ -124,6 +131,11 @@ e_minicard_view_init (EMinicardView *view)
view->status_message_id = 0;
view->canvas_destroy_id = 0;
view->first_get_view = TRUE;
+
+ view->selection = e_selection_model_simple_new();
+
+ gtk_signal_connect(GTK_OBJECT(view->selection), "selection_changed",
+ GTK_SIGNAL_FUNC(selection_changed), view);
gtk_object_set(GTK_OBJECT(view),
"empty_message", _("\n\nThere are no items to show in this view\n\n"
@@ -134,15 +146,40 @@ e_minicard_view_init (EMinicardView *view)
E_REFLOW_SORTED(view)->string_func = (EReflowStringFunc) e_minicard_get_card_id;
}
+static gint
+card_selected (EMinicard *card, GdkEvent *event, EMinicardView *view)
+{
+ int i = 0;
+ GList *item;
+ for (item = E_REFLOW(view)->items; item->data != card; item = item->next, i++)
+ /* Empty for loop */;
+ switch(event->type) {
+ case GDK_BUTTON_PRESS:
+ e_selection_model_do_something(E_SELECTION_MODEL(view->selection), i, 0, event->button.state);
+ return TRUE;
+ break;
+ default:
+ e_selection_model_do_something(E_SELECTION_MODEL(view->selection), i, 0, 0);
+ return FALSE;
+ break;
+ }
+}
+
static void
create_card(EBookView *book_view, const GList *cards, EMinicardView *view)
{
for (; cards; cards = g_list_next(cards)) {
+ int position;
GnomeCanvasItem *item = gnome_canvas_item_new(GNOME_CANVAS_GROUP(view),
e_minicard_get_type(),
"card", cards->data,
NULL);
- e_reflow_add_item(E_REFLOW(view), item);
+ gtk_signal_connect(GTK_OBJECT(item), "selected",
+ GTK_SIGNAL_FUNC(card_selected), view);
+
+ e_reflow_add_item(E_REFLOW(view), item, &position);
+
+ e_selection_model_simple_insert_row(view->selection, position);
}
}
@@ -152,12 +189,18 @@ modify_card(EBookView *book_view, const GList *cards, EMinicardView *view)
for (; cards; cards = g_list_next(cards)) {
ECard *card = cards->data;
gchar *id = e_card_get_id(card);
- GnomeCanvasItem *item = e_reflow_sorted_get_item(E_REFLOW_SORTED(view), id);
+ GnomeCanvasItem *item = e_reflow_sorted_get_item(E_REFLOW_SORTED(view), id, NULL);
if (item && !GTK_OBJECT_DESTROYED(item)) {
+ int old_pos;
+ int new_pos;
+
gnome_canvas_item_set(item,
"card", card,
NULL);
- e_reflow_sorted_reorder_item(E_REFLOW_SORTED(view), id);
+
+ e_reflow_sorted_reorder_item(E_REFLOW_SORTED(view), id, &old_pos, &new_pos);
+
+ e_selection_model_simple_move_row(view->selection, old_pos, new_pos);
}
}
}
@@ -175,7 +218,9 @@ status_message (EBookView *book_view,
static void
remove_card(EBookView *book_view, const char *id, EMinicardView *view)
{
- e_reflow_sorted_remove_item(E_REFLOW_SORTED(view), id);
+ int position;
+ e_reflow_sorted_remove_item(E_REFLOW_SORTED(view), id, &position);
+ e_selection_model_simple_delete_row(view->selection, position);
}
static void
@@ -197,22 +242,26 @@ book_view_loaded (EBook *book, EBookStatus status, EBookView *book_view, gpointe
gtk_object_ref(GTK_OBJECT(view->book_view));
- view->create_card_id = gtk_signal_connect(GTK_OBJECT(view->book_view),
- "card_added",
- GTK_SIGNAL_FUNC(create_card),
- view);
- view->remove_card_id = gtk_signal_connect(GTK_OBJECT(view->book_view),
- "card_removed",
- GTK_SIGNAL_FUNC(remove_card),
- view);
- view->modify_card_id = gtk_signal_connect(GTK_OBJECT(view->book_view),
- "card_changed",
- GTK_SIGNAL_FUNC(modify_card),
- view);
- view->status_message_id = gtk_signal_connect(GTK_OBJECT(view->book_view),
- "status_message",
- GTK_SIGNAL_FUNC(status_message),
- view);
+ view->create_card_id =
+ gtk_signal_connect(GTK_OBJECT(view->book_view),
+ "card_added",
+ GTK_SIGNAL_FUNC(create_card),
+ view);
+ view->remove_card_id =
+ gtk_signal_connect(GTK_OBJECT(view->book_view),
+ "card_removed",
+ GTK_SIGNAL_FUNC(remove_card),
+ view);
+ view->modify_card_id =
+ gtk_signal_connect(GTK_OBJECT(view->book_view),
+ "card_changed",
+ GTK_SIGNAL_FUNC(modify_card),
+ view);
+ view->status_message_id =
+ gtk_signal_connect(GTK_OBJECT(view->book_view),
+ "status_message",
+ GTK_SIGNAL_FUNC(status_message),
+ view);
g_list_foreach(E_REFLOW(view)->items, (GFunc) gtk_object_unref, NULL);
g_list_foreach(E_REFLOW(view)->items, (GFunc) gtk_object_destroy, NULL);
@@ -487,3 +536,17 @@ e_minicard_view_stop (EMinicardView *view)
gtk_object_unref(GTK_OBJECT(view->book_view));
view->book_view = NULL;
}
+
+static void
+e_minicard_view_update_selection (EMinicardView *view)
+{
+ int i;
+ GList *item;
+
+ for (i = 0, item = E_REFLOW(view)->items; item; item = item->next, i++) {
+ if (E_IS_MINICARD(item->data))
+ gtk_object_set(GTK_OBJECT(item->data),
+ "selected", e_selection_model_is_row_selected(E_SELECTION_MODEL(view->selection), i),
+ NULL);
+ }
+}
diff --git a/addressbook/gui/widgets/e-minicard-view.h b/addressbook/gui/widgets/e-minicard-view.h
index 804290d427..2cfe74e993 100644
--- a/addressbook/gui/widgets/e-minicard-view.h
+++ b/addressbook/gui/widgets/e-minicard-view.h
@@ -23,6 +23,7 @@
#include <gnome.h>
#include <gal/widgets/e-reflow-sorted.h>
+#include <gal/widgets/e-selection-model-simple.h>
#include "addressbook/backend/ebook/e-book.h"
#ifdef __cplusplus
@@ -68,6 +69,8 @@ struct _EMinicardView
char *query;
EBookView *book_view;
+ ESelectionModelSimple *selection;
+
int get_view_idle;
int canvas_destroy_id;
diff --git a/addressbook/gui/widgets/e-minicard.c b/addressbook/gui/widgets/e-minicard.c
index be0fe6eba8..6208f1f23f 100644
--- a/addressbook/gui/widgets/e-minicard.c
+++ b/addressbook/gui/widgets/e-minicard.c
@@ -74,9 +74,17 @@ enum {
ARG_WIDTH,
ARG_HEIGHT,
ARG_HAS_FOCUS,
+ ARG_SELECTED,
ARG_CARD
};
+enum {
+ SELECTED,
+ LAST_SIGNAL
+};
+
+static guint e_minicard_signals [LAST_SIGNAL] = {0, };
+
GtkType
e_minicard_get_type (void)
{
@@ -105,32 +113,46 @@ e_minicard_get_type (void)
static void
e_minicard_class_init (EMinicardClass *klass)
{
- GtkObjectClass *object_class;
- GnomeCanvasItemClass *item_class;
+ GtkObjectClass *object_class;
+ GnomeCanvasItemClass *item_class;
- object_class = (GtkObjectClass*) klass;
- item_class = (GnomeCanvasItemClass *) klass;
+ object_class = (GtkObjectClass*) klass;
+ item_class = (GnomeCanvasItemClass *) klass;
- parent_class = gtk_type_class (gnome_canvas_group_get_type ());
+ parent_class = gtk_type_class (gnome_canvas_group_get_type ());
- gtk_object_add_arg_type ("EMinicard::width", GTK_TYPE_DOUBLE,
- 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_ENUM,
- GTK_ARG_READWRITE, ARG_HAS_FOCUS);
- gtk_object_add_arg_type ("EMinicard::card", GTK_TYPE_OBJECT,
- GTK_ARG_READWRITE, ARG_CARD);
+ gtk_object_add_arg_type ("EMinicard::width", GTK_TYPE_DOUBLE,
+ 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_ENUM,
+ GTK_ARG_READWRITE, ARG_HAS_FOCUS);
+ gtk_object_add_arg_type ("EMinicard::selected", GTK_TYPE_BOOL,
+ GTK_ARG_READWRITE, ARG_SELECTED);
+ gtk_object_add_arg_type ("EMinicard::card", GTK_TYPE_OBJECT,
+ GTK_ARG_READWRITE, ARG_CARD);
+
+ e_minicard_signals [SELECTED] =
+ gtk_signal_new ("selected",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (EMinicardClass, selected),
+ gtk_marshal_INT__POINTER,
+ GTK_TYPE_INT, 1, GTK_TYPE_POINTER);
+
+ gtk_object_class_add_signals (object_class, e_minicard_signals, LAST_SIGNAL);
- object_class->set_arg = e_minicard_set_arg;
- object_class->get_arg = e_minicard_get_arg;
- object_class->destroy = e_minicard_destroy;
- object_class->finalize = e_minicard_finalize;
+ object_class->set_arg = e_minicard_set_arg;
+ object_class->get_arg = e_minicard_get_arg;
+ object_class->destroy = e_minicard_destroy;
+ object_class->finalize = e_minicard_finalize;
- /* GnomeCanvasItem method overrides */
- item_class->realize = e_minicard_realize;
- item_class->unrealize = e_minicard_unrealize;
- item_class->event = e_minicard_event;
+ /* GnomeCanvasItem method overrides */
+ item_class->realize = e_minicard_realize;
+ item_class->unrealize = e_minicard_unrealize;
+ item_class->event = e_minicard_event;
+
+ klass->selected = NULL;
}
static void
@@ -142,6 +164,7 @@ e_minicard_init (EMinicard *minicard)
minicard->width = 10;
minicard->height = 10;
minicard->has_focus = FALSE;
+ minicard->selected = FALSE;
minicard->card = NULL;
minicard->simple = e_card_simple_new(NULL);
@@ -154,6 +177,35 @@ e_minicard_init (EMinicard *minicard)
}
static void
+set_selected (EMinicard *minicard, gboolean selected)
+{
+ GtkWidget *canvas = GTK_WIDGET(GNOME_CANVAS_ITEM(minicard)->canvas);
+ if (selected) {
+ gnome_canvas_item_set (minicard->rect,
+ "outline_color_gdk", &canvas->style->bg[GTK_STATE_NORMAL],
+ NULL);
+ gnome_canvas_item_set (minicard->header_rect,
+ "fill_color_gdk", &canvas->style->bg[GTK_STATE_SELECTED],
+ NULL);
+ gnome_canvas_item_set (minicard->header_text,
+ "fill_color_gdk", &canvas->style->text[GTK_STATE_SELECTED],
+ NULL);
+ } else {
+ gnome_canvas_item_set (minicard->rect,
+ "outline_color", NULL,
+ NULL);
+ gnome_canvas_item_set (minicard->header_rect,
+ "fill_color_gdk", &canvas->style->bg[GTK_STATE_NORMAL],
+ NULL);
+ gnome_canvas_item_set (minicard->header_text,
+ "fill_color_gdk", &canvas->style->fg[GTK_STATE_NORMAL],
+ NULL);
+ }
+ minicard->selected = selected;
+}
+
+
+static void
e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
{
GnomeCanvasItem *item;
@@ -187,6 +239,10 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
else
e_canvas_item_grab_focus(item);
break;
+ case ARG_SELECTED:
+ if (e_minicard->selected != GTK_VALUE_BOOL(*arg))
+ set_selected (e_minicard, GTK_VALUE_BOOL(*arg));
+ break;
case ARG_CARD:
if (e_minicard->card)
gtk_object_unref (GTK_OBJECT(e_minicard->card));
@@ -220,6 +276,9 @@ e_minicard_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
case ARG_HAS_FOCUS:
GTK_VALUE_ENUM (*arg) = e_minicard->has_focus ? E_FOCUS_CURRENT : E_FOCUS_NONE;
break;
+ case ARG_SELECTED:
+ GTK_VALUE_BOOL (*arg) = e_minicard->selected;
+ break;
case ARG_CARD:
e_card_simple_sync_card(e_minicard->simple);
GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(e_minicard->card);
@@ -511,17 +570,10 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event)
case GDK_FOCUS_CHANGE:
{
GdkEventFocus *focus_event = (GdkEventFocus *) event;
- if ( focus_event->in ) {
- gnome_canvas_item_set( e_minicard->rect,
- "outline_color_gdk", &canvas->style->bg[GTK_STATE_NORMAL],
- NULL );
- gnome_canvas_item_set( e_minicard->header_rect,
- "fill_color_gdk", &canvas->style->bg[GTK_STATE_SELECTED],
- NULL );
- gnome_canvas_item_set( e_minicard->header_text,
- "fill_color_gdk", &canvas->style->text[GTK_STATE_SELECTED],
- NULL );
- e_minicard->has_focus = TRUE;
+ if (focus_event->in) {
+ if (!e_minicard->selected) {
+ e_minicard_selected(e_minicard, event);
+ }
} else {
EBook *book = NULL;
@@ -550,25 +602,15 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event)
}
e_minicard->changed = FALSE;
}
-
- gnome_canvas_item_set( e_minicard->rect,
- "outline_color", NULL,
- NULL );
- gnome_canvas_item_set( e_minicard->header_rect,
- "fill_color_gdk",
- &canvas->style->bg[GTK_STATE_NORMAL],
- NULL );
- gnome_canvas_item_set( e_minicard->header_text,
- "fill_color_gdk",
- &canvas->style->fg[GTK_STATE_NORMAL],
- NULL );
e_minicard->has_focus = FALSE;
}
}
break;
case GDK_BUTTON_PRESS:
if (event->button.button == 1) {
+ int ret_val = e_minicard_selected(e_minicard, event);
e_canvas_item_grab_focus(item);
+ return ret_val;
} else if (event->button.button == 3) {
MinicardAndParent *mnp = g_new(MinicardAndParent, 1);
EPopupMenu menu[] = { {"Save as VCard", NULL, GTK_SIGNAL_FUNC(save_as), NULL, 0},
@@ -904,3 +946,13 @@ e_minicard_compare (EMinicard *minicard1, EMinicard *minicard2)
return 0;
}
}
+
+int
+e_minicard_selected (EMinicard *minicard, GdkEvent *event)
+{
+ gint ret_val = 0;
+ gtk_signal_emit(GTK_OBJECT(minicard),
+ e_minicard_signals[SELECTED],
+ event, &ret_val);
+ return ret_val;
+}
diff --git a/addressbook/gui/widgets/e-minicard.h b/addressbook/gui/widgets/e-minicard.h
index 54c5806a28..dbc914502c 100644
--- a/addressbook/gui/widgets/e-minicard.h
+++ b/addressbook/gui/widgets/e-minicard.h
@@ -76,8 +76,10 @@ struct _EMinicard
guint needs_remodeling : 1;
guint changed : 1;
+
+ guint selected : 1;
- gboolean has_focus;
+ guint has_focus : 1;
double width;
double height;
@@ -87,7 +89,7 @@ struct _EMinicardClass
{
GnomeCanvasGroupClass parent_class;
- void (* resize) (EMinicard *minicard);
+ gint (* selected) (EMinicard *minicard, GdkEvent *event);
};
@@ -95,6 +97,8 @@ GtkType e_minicard_get_type (void);
char *e_minicard_get_card_id (EMinicard *minicard);
int e_minicard_compare (EMinicard *minicard1, EMinicard *minicard2);
+int e_minicard_selected (EMinicard *minicard, GdkEvent *event);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/addressbook/gui/widgets/test-reflow.c b/addressbook/gui/widgets/test-reflow.c
index 2a8e7093fe..1a2cc9f017 100644
--- a/addressbook/gui/widgets/test-reflow.c
+++ b/addressbook/gui/widgets/test-reflow.c
@@ -159,7 +159,7 @@ int main( int argc, char *argv[] )
e_minicard_get_type(),
"card", card,
NULL);
- e_reflow_add_item(E_REFLOW(reflow), item);
+ e_reflow_add_item(E_REFLOW(reflow), item, NULL);
}
gnome_canvas_set_scroll_region ( GNOME_CANVAS( canvas ),
0, 0,