Add:Core:Made selection more flexible
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 8 Dec 2009 20:26:37 +0000 (20:26 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 8 Dec 2009 20:26:37 +0000 (20:26 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@2859 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/graphics.c
navit/graphics.h
navit/gui/internal/gui_internal.c

index f78e220..044415e 100644 (file)
@@ -2151,23 +2151,15 @@ int graphics_displayitem_within_dist(struct displaylist *displaylist, struct dis
 }
 
 
-static enum item_type
-graphics_selection_type(enum item_type type)
-{
-       if (type < type_line) 
-               return type_selected_point;
-       if (type < type_area) 
-               return type_selected_line;
-       return type_selected_area;
-       
-}
-
-
 static void
 graphics_process_selection_item(struct displaylist *dl, struct item *item)
 {
        struct displayitem di,*di_res;
        GHashTable *h;
+       int count,max=dl->dc.maxlen;
+       struct coord ca[max];
+       struct attr attr;
+       struct map_rect *mr;
 
        di.item=*item;
        di.label=NULL;
@@ -2177,24 +2169,38 @@ graphics_process_selection_item(struct displaylist *dl, struct item *item)
        if (h) {
                di_res=g_hash_table_lookup(h, &di);
                if (di_res) {
-                       di.item.type=graphics_selection_type(di.item.type);
+                       di.item.type=(enum item_type)item->priv_data;
                        display_add(dl, &di.item, di_res->count, di_res->c, NULL);
+                       return;
                }
        }
+       mr=map_rect_new(item->map, NULL);
+       item=map_rect_get_item_byid(item->map, item->id_lo, item->id_hi);
+       count=item_coord_get(item, ca, item->type < type_line ? 1: max);
+       if (!item_attr_get(item, attr_label, &attr))
+               attr.u.str=NULL;
+       if (dl->conv && attr.u.str && attr.u.str[0]) {
+               char *str=map_convert_string(item->map, attr.u.str);
+               display_add(dl, item, count, ca, str);
+               map_convert_free(str);
+       } else
+               display_add(dl, item, count, ca, attr.u.str);
+       map_rect_destroy(mr);
 }
 
 void
-graphics_add_selection(struct graphics *gra, struct item *item, struct displaylist *dl)
+graphics_add_selection(struct graphics *gra, struct item *item, enum item_type type, struct displaylist *dl)
 {
        struct item *item_dup=g_new(struct item, 1);
        *item_dup=*item;
+       item_dup->priv_data=(void *)type;
        gra->selection=g_list_append(gra->selection, item_dup);
        if (dl)
                graphics_process_selection_item(dl, item_dup);
 }
 
 void
-graphics_remove_selection(struct graphics *gra, struct item *item, struct displaylist *dl)
+graphics_remove_selection(struct graphics *gra, struct item *item, enum item_type type, struct displaylist *dl)
 {
        GList *curr;
        int found;
@@ -2212,7 +2218,7 @@ graphics_remove_selection(struct graphics *gra, struct item *item, struct displa
                                        di.label=NULL;
                                        di.displayed=0;
                                        di.count=0;
-                                       di.item.type=graphics_selection_type(di.item.type);
+                                       di.item.type=type;
                                        h=g_hash_table_lookup(dl->dl, GINT_TO_POINTER(di.item.type));
                                        if (h)
                                                g_hash_table_remove(h, &di);
@@ -2231,8 +2237,10 @@ graphics_remove_selection(struct graphics *gra, struct item *item, struct displa
 void
 graphics_clear_selection(struct graphics *gra, struct displaylist *dl)
 {
-       while (gra->selection) 
-               graphics_remove_selection(gra, (struct item *)gra->selection->data, dl);
+       while (gra->selection) {
+               struct item *item=(struct item *)gra->selection->data;
+               graphics_remove_selection(gra, item, (enum item_type)item->priv_data,dl);
+       }
 }
 
 static void
index a0ef3a0..b9603b9 100644 (file)
@@ -114,6 +114,7 @@ struct graphics_data_image {
 
 /* prototypes */
 enum attr_type;
+enum item_type;
 enum draw_mode_num;
 struct attr;
 struct attr_iter;
@@ -181,8 +182,8 @@ struct item *graphics_displayitem_get_item(struct displayitem *di);
 char *graphics_displayitem_get_label(struct displayitem *di);
 int graphics_displayitem_get_displayed(struct displayitem *di);
 int graphics_displayitem_within_dist(struct displaylist *displaylist, struct displayitem *di, struct point *p, int dist);
-void graphics_add_selection(struct graphics *gra, struct item *item, struct displaylist *dl);
-void graphics_remove_selection(struct graphics *gra, struct item *item, struct displaylist *dl);
+void graphics_add_selection(struct graphics *gra, struct item *item, enum item_type type, struct displaylist *dl);
+void graphics_remove_selection(struct graphics *gra, struct item *item, enum item_type type, struct displaylist *dl);
 void graphics_clear_selection(struct graphics *gra, struct displaylist *dl);
 /* end of prototypes */
 #ifdef __cplusplus
index 3b60486..19052eb 100644 (file)
@@ -2119,10 +2119,17 @@ static void
 gui_internal_cmd_view_on_map(struct gui_priv *this, struct widget *wm, void *data)
 {
        struct widget *w=wm->data;
-       int highlight=(w->data == (void *)2 || w->data == (void *)3 || w->data == (void *)4);
+       int highlight=(w->data == (void *)2 || w->data == (void *)3 || w->data == (void *)5);
        if (highlight) {
+               enum item_type type;
+               if (w->item.type < type_line)
+                       type=type_selected_point;
+               else if (w->item.type < type_area)
+                       type=type_selected_point;
+               else
+                       type=type_selected_area;
                graphics_clear_selection(this->gra, NULL);
-               graphics_add_selection(this->gra, &w->item, NULL);
+               graphics_add_selection(this->gra, &w->item, type, NULL);
        }
        navit_set_center(this->nav, &w->c, 1);
        gui_internal_prune_menu(this, NULL);