Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / libedataserverui / e-name-selector-list.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* e-name-selector-list.c - Single-line text entry widget for EDestinations.
4  *
5  * Copyright (C) 2005 Novell, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of version 2 of the GNU General Public
9  * License as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  * Authors: Srinivasa Ragavan <sragavan@novell.com>
22  *        : Devashish Sharma  <sdevashish@novell.com>   
23  */
24
25 #include <config.h>
26 #include <string.h>
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkentry.h>
30 #include <gtk/gtkentrycompletion.h>
31 #include <gtk/gtkcelllayout.h>
32 #include <gtk/gtkcellrenderertext.h>
33 #include <gtk/gtkframe.h>
34 #include <gtk/gtkmenuitem.h>
35 #include <gtk/gtkradiomenuitem.h>
36 #include <gtk/gtkseparatormenuitem.h>
37 #include <gtk/gtkscrolledwindow.h>
38 #include <gtk/gtktreeselection.h>
39 #include <gtk/gtktreemodel.h>
40 #include <gtk/gtkvbox.h>
41 #include <glib/gi18n-lib.h>
42
43 #include <libebook/e-book.h>
44 #include <libebook/e-contact.h>
45 #include <libebook/e-destination.h>
46 #include <libedataserverui/e-book-auth-util.h>
47 #include "libedataserver/e-sexp.h"
48 #include <libedataserverui/e-data-server-ui-marshal.h>
49 #include <libedataserverui/e-name-selector-entry.h>
50 #include "e-name-selector-list.h"
51
52 #define MAX_ROW 10
53
54 G_DEFINE_TYPE (ENameSelectorList, e_name_selector_list, E_TYPE_NAME_SELECTOR_ENTRY);
55
56 static void e_name_selector_list_class_init (ENameSelectorListClass *name_selector_list_class);
57 static void e_name_selector_list_init       (ENameSelectorList *name_selector_list);
58 static void e_name_selector_list_dispose    (GObject *object);
59 static void e_name_selector_list_finalize   (GObject *object);
60
61 /* Signals */
62
63 static void
64 enl_popup_size (ENameSelectorList *list)
65 {
66         int height = 0, count;
67         GtkTreeViewColumn *column = NULL;
68
69         column = gtk_tree_view_get_column ( GTK_TREE_VIEW (list->tree_view), 0);
70         if (column)
71                 gtk_tree_view_column_cell_get_size (column, NULL, NULL, NULL, NULL, &height);
72
73         /* Show a maximum of 10 rows in the popup list view */
74         count = list->rows;
75         if (count > MAX_ROW) 
76                 count = MAX_ROW;
77         if (count <= 0)
78                 count = 1;
79
80         gtk_widget_set_size_request (list->tree_view, ((GtkWidget *)list)->allocation.width - 3 , height * count);
81 }
82
83 static void
84 enl_popup_position (ENameSelectorList *list)
85 {
86         int x,y;
87
88         enl_popup_size (list);
89         gdk_window_get_origin (((GtkWidget *)list)->window, &x, &y);
90         y = y +((GtkWidget *)list)->allocation.height;
91         
92         gtk_window_move (list->popup, x, y);
93 }
94
95 static void
96 enl_popup_grab (ENameSelectorList *list)
97 {
98         int len; 
99         
100         gtk_grab_add (GTK_WIDGET (list->popup));
101         
102         gdk_pointer_grab (((GtkWidget *)list->popup)->window, TRUE,
103                           GDK_BUTTON_PRESS_MASK |
104                           GDK_BUTTON_RELEASE_MASK |
105                           GDK_POINTER_MOTION_MASK,
106                           NULL, NULL, GDK_CURRENT_TIME);
107
108         gdk_keyboard_grab (((GtkWidget *)list->popup)->window, TRUE, GDK_CURRENT_TIME);
109         gtk_widget_grab_focus ((GtkWidget *)list);
110         
111         /* Build the listview from the model */
112         gtk_tree_view_set_model (GTK_TREE_VIEW (list->tree_view), GTK_TREE_MODEL(((ENameSelectorEntry *)list)->destination_store));
113
114         /* If any selection of text is present, unselect it */
115         len = strlen(gtk_entry_get_text(GTK_ENTRY(list)));
116         gtk_editable_select_region (GTK_EDITABLE(list), len, -1); 
117 }
118
119 static void
120 enl_popup_ungrab (ENameSelectorList *list)
121 {
122         if (!GTK_WIDGET_HAS_GRAB(list->popup))
123                 return;
124         
125         gdk_pointer_ungrab (GDK_CURRENT_TIME);  
126         gtk_grab_remove ( GTK_WIDGET (list->popup));
127         gdk_keyboard_ungrab (GDK_CURRENT_TIME);
128 }
129
130 static gboolean
131 enl_entry_focus_in (ENameSelectorList *list, GdkEventFocus *event, gpointer dummy)
132 {
133         int len;
134         
135         /* FIXME: Dont select every thing by default- Code is there but still it does */
136         len = strlen(gtk_entry_get_text(GTK_ENTRY(list)));
137         gtk_editable_select_region (GTK_EDITABLE(list), len, -1);
138         
139         return TRUE;
140 }
141
142 static gboolean
143 enl_entry_focus_out (ENameSelectorList *list, GdkEventFocus *event, gpointer dummy)
144 {
145         /* When we lose focus and popup is still present hide it. Dont do it, when we click the popup. Look for grab */
146         if (GTK_WIDGET_VISIBLE (list->popup) && !GTK_WIDGET_HAS_GRAB(list->popup)) {
147                 enl_popup_ungrab (list);
148                 gtk_widget_hide ((GtkWidget *)list->popup);
149                 
150                 return FALSE;
151         }
152
153         return FALSE;
154 }
155
156 static gboolean
157 enl_popup_button_press (GtkWidget *widget,
158                         GdkEventButton *event,
159                         ENameSelectorList *list)
160 {
161         if (!GTK_WIDGET_MAPPED (widget))
162                 return FALSE;
163         /* if we come here, it's usually time to popdown */
164         gtk_widget_hide ((GtkWidget *)list->popup);
165
166         return TRUE;
167 }
168
169 static gboolean
170 enl_popup_focus_out (GtkWidget *w,
171                      GdkEventFocus *event,
172                      ENameSelectorList *list)
173 {
174         /* Just ungrab. We lose focus on button press event */
175         enl_popup_ungrab(list);
176         return TRUE;
177 }
178
179 static gboolean
180 enl_popup_enter_notify (GtkWidget        *widget,
181                         GdkEventCrossing *event,
182                         ENameSelectorList *list)
183 {
184   if (event->type == GDK_ENTER_NOTIFY && !GTK_WIDGET_HAS_GRAB (list->popup))
185         enl_popup_grab (list);
186   
187   return TRUE;
188 }
189
190 static void
191 enl_tree_select_node (ENameSelectorList *list,
192                       int n)
193 {
194         GtkTreeSelection *selection;
195         GtkTreeIter iter;
196         GtkTreePath *path;
197         
198         selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list->tree_view));
199         iter.stamp = ((ENameSelectorEntry *) list)->destination_store->stamp;
200         iter.user_data = GINT_TO_POINTER (n-1);
201
202         gtk_tree_selection_unselect_all (selection);
203         gtk_tree_selection_select_iter (selection, &iter);
204
205         path = e_destination_store_get_path (GTK_TREE_MODEL(((ENameSelectorEntry *) list)->destination_store), &iter);
206         gtk_tree_view_scroll_to_cell ( GTK_TREE_VIEW (list->tree_view), path, gtk_tree_view_get_column( GTK_TREE_VIEW (list->tree_view), 0), FALSE, 0, 0);
207         gtk_tree_view_set_cursor ( GTK_TREE_VIEW (list->tree_view), path, gtk_tree_view_get_column( GTK_TREE_VIEW (list->tree_view), 0), FALSE);
208         gtk_widget_grab_focus (list->tree_view);
209         /*Fixme: We should grab the focus to the column. How? */
210         
211         gtk_tree_path_free (path);
212 }
213
214 static gboolean
215 enl_entry_key_press_event (ENameSelectorList *list, 
216                            GdkEventKey *event,
217                            gpointer dummy)
218 {
219         if ( (event->state & GDK_CONTROL_MASK)  && (event->keyval == GDK_Down)) {
220                 enl_popup_position (list);
221                 gtk_widget_show_all (GTK_WIDGET (list->popup));
222                 enl_popup_grab (list);
223                 list->rows = e_destination_store_get_destination_count (((ENameSelectorEntry *) list)->destination_store);
224                 enl_popup_size (list);
225                 enl_tree_select_node (list, 1);
226                 return TRUE;
227         }
228         return FALSE;
229 }
230
231 static void
232 delete_row (GtkTreePath *path, ENameSelectorList *list)
233 {
234         GtkTreeIter   iter;
235         int n, len;
236         GtkTreeSelection *selection;
237         
238         if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (E_NAME_SELECTOR_ENTRY (list)->destination_store), &iter, path))
239                 return;
240                 
241         selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (list->tree_view));
242         len = e_destination_store_get_destination_count (E_NAME_SELECTOR_ENTRY (list)->destination_store);
243         n = GPOINTER_TO_INT (iter.user_data);
244         
245         e_destination_store_remove_destination_nth (((ENameSelectorEntry *) list)->destination_store, n);
246         
247         /* If the last one is deleted select the last but one or the deleted +1 */
248         if (n == len -1)
249                 n -= 1;
250         
251         /* We deleted the last entry */
252         if (len == 1) {
253                 enl_popup_ungrab (list);
254                 if(list->menu)
255                         gtk_menu_popdown(GTK_MENU (list->menu));
256                 gtk_widget_hide ( GTK_WIDGET (list->popup));
257                 return;
258         }
259
260         iter.stamp = ((ENameSelectorEntry *) list)->destination_store->stamp;
261         iter.user_data = GINT_TO_POINTER (n);
262
263         gtk_tree_selection_unselect_all (selection);    
264         gtk_tree_selection_select_iter (selection, &iter);
265         
266         gtk_tree_path_free (path);
267
268         list->rows = e_destination_store_get_destination_count (((ENameSelectorEntry *) list)->destination_store);
269         enl_popup_size (list);
270
271         
272 }
273
274 static void
275 popup_activate_email (ENameSelectorEntry *name_selector_entry, GtkWidget *menu_item)
276 {
277         EDestination *destination;
278         EContact     *contact;
279         gint          email_num;
280
281         destination = name_selector_entry->popup_destination;
282         if (!destination)
283                 return;
284
285         contact = e_destination_get_contact (destination);
286         if (!contact)
287                 return;
288
289         email_num = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "order"));
290         e_destination_set_contact (destination, contact, email_num);
291 }
292
293 static void
294 popup_activate_list (EDestination *destination, GtkWidget *item)
295 {
296         gboolean status = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item));
297         
298         e_destination_set_ignored (destination, !status);       
299 }
300
301 static void
302 destination_set_list (GtkWidget *item, EDestination *destination)
303 {
304         EContact *contact;
305         gboolean status = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item));
306
307         contact = e_destination_get_contact (destination);
308         if (!contact)
309                 return;
310         
311         e_destination_set_ignored (destination, !status);
312 }
313
314 static void
315 destination_set_email (GtkWidget *item, EDestination *destination)
316 {
317         int email_num;
318         EContact *contact;
319
320         if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item)))
321                 return;
322         contact = e_destination_get_contact (destination);
323         if (!contact)
324                 return;
325
326         email_num = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "order"));
327         e_destination_set_contact (destination, contact, email_num);
328 }
329
330 typedef struct {
331         ENameSelectorList *list;
332         GtkTreePath *path;
333 }PopupDeleteRowInfo;
334
335 static void
336 popup_delete_row(GtkWidget *w, PopupDeleteRowInfo *row_info)
337 {
338         delete_row(row_info->path, row_info->list);
339         g_free(row_info);
340 }
341
342 static void
343 menu_deactivate (GtkMenuShell *junk, ENameSelectorList *list)
344 {
345         enl_popup_grab (list);
346 }
347
348 static gboolean
349 enl_tree_button_press_event (GtkWidget *widget,
350                        GdkEventButton *event,
351                        ENameSelectorList *list)
352 {
353         GtkWidget *menu;
354         EDestination *destination;
355         ENameSelectorEntry *name_selector_entry;
356         EContact     *contact;
357         GtkWidget    *menu_item;
358         GList        *email_list = NULL, *l;
359         gint          i;
360         int           email_num, len;
361         char         *delete_label;
362         GSList       *group = NULL;
363         gboolean      is_list;
364         gboolean      show_menu = FALSE;
365         GtkTreeSelection *selection;
366         GtkTreePath  *path;
367         PopupDeleteRowInfo *row_info;
368         GtkTreeIter   iter;
369
370         if ( !GTK_WIDGET_HAS_GRAB (list->popup))
371                 enl_popup_grab (list);
372   
373         gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW (list->tree_view), event->x, event->y, &path, NULL);
374         selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (list->tree_view));
375         if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (E_NAME_SELECTOR_ENTRY (list)->destination_store), &iter, path))
376                 return FALSE;
377                                 
378         gtk_tree_selection_unselect_all (selection);    
379         gtk_tree_selection_select_iter (selection, &iter);
380
381         if (event->button != 3) {
382                 return FALSE;
383         }
384         
385         name_selector_entry = E_NAME_SELECTOR_ENTRY (list);
386
387         destination = e_destination_store_get_destination ( ((ENameSelectorEntry *)list)->destination_store, &iter);    
388
389         if (!destination)
390                 return FALSE;
391
392         contact = e_destination_get_contact (destination);
393         if (!contact)
394                 return FALSE;
395
396         if (list->menu) {
397                 gtk_menu_popdown (GTK_MENU (list->menu));
398         }
399         menu = gtk_menu_new ();
400         g_signal_connect (menu, "deactivate", G_CALLBACK(menu_deactivate), list);
401         list->menu = menu;
402         gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, event->button, gtk_get_current_event_time());
403
404         email_num = e_destination_get_email_num (destination);
405
406         /* Addresses */
407         is_list = e_contact_get (contact, E_CONTACT_IS_LIST) ? TRUE : FALSE;
408         if (is_list) {
409                 const GList *dests = e_destination_list_get_dests (destination);
410                 GList *iters;
411                 int length = g_list_length ((GList *)dests);
412
413                 for (iters = (GList *)dests; iters; iters = iters->next) {
414                         EDestination *dest = (EDestination *) iters->data;
415                         const char *email = e_destination_get_email (dest);
416                         
417                         if (!email || *email == '\0')
418                                 continue;       
419
420                         if (length > 1) {
421                                 menu_item = gtk_check_menu_item_new_with_label (email);
422                                 g_signal_connect (menu_item, "toggled", G_CALLBACK (destination_set_list), dest);                               
423                         } else {
424                                 menu_item = gtk_menu_item_new_with_label (email);
425                         }
426                         
427                         gtk_widget_show (menu_item);
428                         gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
429                         show_menu = TRUE;
430
431                         if (length > 1) {
432                                 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), !e_destination_is_ignored(dest));
433                                 g_signal_connect_swapped (menu_item, "activate", G_CALLBACK (popup_activate_list),
434                                                           dest);        
435                         }
436                 }
437                 
438         } else {
439                 email_list = e_contact_get (contact, E_CONTACT_EMAIL);
440                 len = g_list_length (email_list);
441
442                 for (l = email_list, i = 0; l; l = g_list_next (l), i++) {
443                         gchar *email = l->data;
444
445                         if (!email || *email == '\0')
446                                 continue;
447                 
448                         if (len > 1) {
449                                 menu_item = gtk_radio_menu_item_new_with_label (group, email);
450                                 group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menu_item));
451                                 g_signal_connect (menu_item, "toggled", G_CALLBACK (destination_set_email), destination);
452                         } else {
453                                 menu_item = gtk_menu_item_new_with_label (email);                       
454                         }
455                         
456                         gtk_widget_show (menu_item);
457                         gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
458                         show_menu = TRUE;
459                         g_object_set_data (G_OBJECT (menu_item), "order", GINT_TO_POINTER (i));                 
460
461                         if ( i == email_num && len > 1 ) {
462                                 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), TRUE);
463                                 g_signal_connect_swapped (menu_item, "activate", G_CALLBACK (popup_activate_email),
464                                                           name_selector_entry);
465                         }
466                 }
467                 g_list_foreach (email_list, (GFunc) g_free, NULL);
468                 g_list_free (email_list);
469         }
470
471         /* Separator */
472
473         if (show_menu) {
474                 menu_item = gtk_separator_menu_item_new ();
475                 gtk_widget_show (menu_item);
476                 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
477         }
478
479         delete_label = g_strdup_printf(_("_Delete %s"), (char *)e_contact_get_const (contact, E_CONTACT_FILE_AS));
480         menu_item = gtk_menu_item_new_with_mnemonic (delete_label);
481         g_free (delete_label);
482         gtk_widget_show (menu_item);
483         gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
484
485         row_info = g_new (PopupDeleteRowInfo, 1);
486         row_info->list = list;
487         row_info->path = path;
488
489         g_signal_connect (menu_item, "activate", G_CALLBACK (popup_delete_row),
490                                   row_info);
491         
492         return TRUE;
493
494
495 }
496
497 static gboolean
498 enl_tree_key_press_event (GtkWidget *w,
499                            GdkEventKey *event,
500                            ENameSelectorList *list)
501 {
502         if (event->keyval == GDK_Escape) {
503                 enl_popup_ungrab (list);
504                 gtk_widget_hide ( GTK_WIDGET (list->popup));
505                 return TRUE;
506         } else if (event->keyval == GDK_Delete) {
507                 GtkTreeSelection *selection;
508                 GList *paths;
509
510                 selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (list->tree_view));
511                 paths = gtk_tree_selection_get_selected_rows (selection, (GtkTreeModel **)&(E_NAME_SELECTOR_ENTRY (list)->destination_store));
512                 paths = g_list_reverse (paths);
513                 g_list_foreach (paths, (GFunc) delete_row, list);
514                 g_list_free (paths);
515         } else if (event->keyval != GDK_Up && event->keyval != GDK_Down 
516                    && event->keyval != GDK_Shift_R && event->keyval != GDK_Shift_L
517                    && event->keyval != GDK_Control_R && event->keyval != GDK_Control_L){
518                    
519                 enl_popup_ungrab (list);
520                 gtk_widget_hide ( GTK_WIDGET (list->popup));
521                 gtk_widget_event (GTK_WIDGET (list), (GdkEvent *)event);
522                 return TRUE;
523         }
524
525         return FALSE;
526 }
527
528 void 
529 e_name_selector_list_expand_clicked(ENameSelectorList *list)
530 {
531
532         if (!GTK_WIDGET_VISIBLE (list->popup)) {
533                 enl_popup_position (list);
534                 gtk_widget_show_all (GTK_WIDGET (list->popup));
535                 enl_popup_grab (list);
536                 list->rows = e_destination_store_get_destination_count (((ENameSelectorEntry *) list)->destination_store);
537                 enl_popup_size (list);
538                 enl_tree_select_node (list, 1);
539         }
540         else {
541                 enl_popup_ungrab (list);
542                 if(list->menu)
543                         gtk_menu_popdown(GTK_MENU (list->menu));
544                 gtk_widget_hide (GTK_WIDGET (list->popup));
545         }
546 }
547 /* Object Methods */
548 static void
549 e_name_selector_list_dispose (GObject *object)
550 {
551         if (G_OBJECT_CLASS (e_name_selector_list_parent_class)->dispose)
552                 G_OBJECT_CLASS (e_name_selector_list_parent_class)->dispose (object);
553 }
554
555 static void
556 e_name_selector_list_finalize (GObject *object)
557 {
558         if (G_OBJECT_CLASS (e_name_selector_list_parent_class)->finalize)
559                 G_OBJECT_CLASS (e_name_selector_list_parent_class)->finalize (object);
560 }
561
562 static void
563 e_name_selector_list_realize (GtkWidget *widget)
564 {
565         ENameSelectorList *list = (ENameSelectorList *)widget;
566         GTK_WIDGET_CLASS (e_name_selector_list_parent_class)->realize (widget);
567         
568         gtk_tree_view_set_model ( GTK_TREE_VIEW (list->tree_view), GTK_TREE_MODEL(((ENameSelectorEntry *)list)->destination_store));
569 }
570
571 static void
572 e_name_selector_list_class_init (ENameSelectorListClass *name_selector_list_class)
573 {
574         GObjectClass   *object_class = G_OBJECT_CLASS (name_selector_list_class);
575         GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (name_selector_list_class);
576
577         object_class->dispose      = e_name_selector_list_dispose;
578         object_class->finalize     = e_name_selector_list_finalize;
579
580         widget_class->realize      = e_name_selector_list_realize;
581
582         /* Install properties */
583
584         /* Install signals */
585
586 }
587
588 static void
589 e_name_selector_list_init (ENameSelectorList *list)
590 {
591         GtkCellRenderer *renderer;
592         GtkWidget *scroll, *popup_frame, *vbox;
593         GtkTreeSelection *selection;
594         GtkTreeViewColumn *column;
595         ENameSelectorEntry *entry = E_NAME_SELECTOR_ENTRY (list);
596         GtkEntryCompletion *completion;
597
598         list->store = e_destination_store_new ();
599         list->menu = NULL;
600         
601         list->tree_view = GTK_WIDGET (gtk_tree_view_new_with_model (GTK_TREE_MODEL(entry->destination_store)));
602         gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (list->tree_view), FALSE);
603         gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (list->tree_view), FALSE);
604         
605         selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list->tree_view));
606         gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
607         gtk_tree_selection_unselect_all (selection);
608         gtk_tree_view_set_enable_search (GTK_TREE_VIEW (list->tree_view), FALSE);
609
610         completion = gtk_entry_get_completion (GTK_ENTRY(list));
611         gtk_entry_completion_set_inline_completion (completion, TRUE);
612         gtk_entry_completion_set_popup_completion (completion, TRUE);
613
614         renderer = gtk_cell_renderer_text_new ();
615         column = gtk_tree_view_column_new_with_attributes ("Name", renderer, "text", E_DESTINATION_STORE_COLUMN_ADDRESS, NULL);
616         gtk_tree_view_append_column (GTK_TREE_VIEW (list->tree_view), column);
617         gtk_tree_view_column_set_clickable (column, TRUE);
618
619         scroll = gtk_scrolled_window_new (NULL, NULL);
620         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
621                                         GTK_POLICY_NEVER,
622                                         GTK_POLICY_AUTOMATIC);
623         gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll),
624                                              GTK_SHADOW_NONE);  
625         gtk_widget_set_size_request (GTK_SCROLLED_WINDOW (scroll)->vscrollbar, -1, 0);
626
627         list->popup =  GTK_WINDOW (gtk_window_new (GTK_WINDOW_POPUP));
628         gtk_window_set_resizable (GTK_WINDOW (list->popup), FALSE);
629
630         popup_frame = gtk_frame_new (NULL);
631         gtk_frame_set_shadow_type (GTK_FRAME (popup_frame),
632                                    GTK_SHADOW_ETCHED_IN);
633         
634         gtk_container_add (GTK_CONTAINER (list->popup), popup_frame);
635   
636         vbox = gtk_vbox_new (FALSE, 0);
637         gtk_container_add (GTK_CONTAINER (popup_frame), vbox);
638
639         gtk_container_add (GTK_CONTAINER (scroll), list->tree_view);
640         gtk_box_pack_start (GTK_BOX (vbox), scroll,
641                             TRUE, TRUE, 0);
642
643         g_signal_connect_after (GTK_WIDGET (list), "focus-in-event", G_CALLBACK(enl_entry_focus_in), NULL);
644         g_signal_connect (GTK_WIDGET (list), "focus-out-event", G_CALLBACK(enl_entry_focus_out), NULL);
645         g_signal_connect (GTK_WIDGET (list), "key-press-event", G_CALLBACK(enl_entry_key_press_event), NULL);
646
647         g_signal_connect_after (list->tree_view, "key-press-event", G_CALLBACK(enl_tree_key_press_event), list);
648         g_signal_connect (list->tree_view, "button-press-event", G_CALLBACK (enl_tree_button_press_event), list);
649
650         g_signal_connect (GTK_WIDGET (list->popup), "button-press-event", G_CALLBACK(enl_popup_button_press), list);
651         g_signal_connect (GTK_WIDGET (list->popup), "focus-out-event", G_CALLBACK(enl_popup_focus_out), list);
652         g_signal_connect (GTK_WIDGET (list->popup), "enter-notify-event", G_CALLBACK (enl_popup_enter_notify), list);
653         
654 }
655
656 ENameSelectorList *
657 e_name_selector_list_new (void)
658 {
659         return g_object_new (e_name_selector_list_get_type (), NULL);
660 }