Add:gui_internal:Improved osd keyboard
[navit-package] / navit / search.c
index 7c8b7fd..d61e22d 100644 (file)
@@ -30,7 +30,7 @@
 struct search_list_level {
        struct mapset *ms;
        struct search_list_common *parent;
-       struct attr attr;
+       struct attr *attr;
        int partial;
        int selected;
        struct mapset_search *search;
@@ -51,7 +51,7 @@ static guint
 search_item_hash_hash(gconstpointer key)
 {
        const struct item *itm=key;
-       gconstpointer hashkey=(gconstpointer)(itm->id_hi^itm->id_lo);
+       gconstpointer hashkey=(gconstpointer)GINT_TO_POINTER(itm->id_hi^itm->id_lo);
        return g_direct_hash(hashkey);
 }
 
@@ -115,10 +115,8 @@ search_list_search(struct search_list *this_, struct attr *search_attr, int part
                this_->result.id=0;
                this_->level=level;
                le=&this_->levels[level];
-               le->attr=*search_attr;
-               if (search_attr->type != attr_country_id)
-                       le->attr.u.str=g_strdup(search_attr->u.str);
                search_list_search_free(this_, level);
+               le->attr=attr_dup(search_attr);
                le->partial=partial;
                if (level > 0) {
                        le=&this_->levels[level-1];
@@ -147,7 +145,8 @@ search_list_select(struct search_list *this_, enum attr_type attr_type, int id,
                        slc=curr->data;
                        slc->selected=mode;
                        if (id) {
-                               dbg(1,"found\n");
+                               le->last=curr;
+                               dbg(0,"found\n");
                                return slc;
                        }
                }
@@ -157,6 +156,37 @@ search_list_select(struct search_list *this_, enum attr_type attr_type, int id,
        return NULL;
 }
 
+static void
+search_list_common_new(struct item *item, struct search_list_common *common)
+{
+       struct attr attr;
+       if (item_attr_get(item, attr_town_name, &attr))
+               common->town_name=map_convert_string(item->map, attr.u.str);
+       else
+               common->town_name=NULL;
+       if (item_attr_get(item, attr_district_name, &attr))
+               common->district_name=map_convert_string(item->map, attr.u.str);
+       else
+               common->district_name=NULL;
+       if (item_attr_get(item, attr_postal, &attr))
+               common->postal=map_convert_string(item->map, attr.u.str);
+       else
+               common->postal=NULL;
+       if (item_attr_get(item, attr_postal_mask, &attr)) 
+               common->postal_mask=map_convert_string(item->map, attr.u.str);
+       else 
+               common->postal_mask=NULL;
+}
+
+static void
+search_list_common_destroy(struct search_list_common *common)
+{
+       map_convert_free(common->town_name);
+       map_convert_free(common->district_name);
+       map_convert_free(common->postal);
+       map_convert_free(common->postal_mask);
+}
+
 static struct search_list_country *
 search_list_country_new(struct item *item)
 {
@@ -201,18 +231,11 @@ search_list_town_new(struct item *item)
                dbg(1,"town_assoc 0x%x 0x%x\n", attr.u.item->id_hi, attr.u.item->id_lo);
                ret->common.unique=*attr.u.item;
        }
-       if (item_attr_get(item, attr_town_name, &attr))
-               ret->name=map_convert_string(item->map,attr.u.str);
-       else
-               ret->name=NULL;
-       if (item_attr_get(item, attr_town_postal, &attr))
-               ret->common.postal=map_convert_string(item->map,attr.u.str);
-       else
-               ret->common.postal=NULL;
-       if (item_attr_get(item, attr_district_name, &attr))
-               ret->district=map_convert_string(item->map,attr.u.str);
+       search_list_common_new(item, &ret->common);
+       if (item_attr_get(item, attr_county_name, &attr))
+               ret->county=map_convert_string(item->map,attr.u.str);
        else
-               ret->district=NULL;
+               ret->county=NULL;
        if (item_coord_get(item, &c, 1)) {
                ret->common.c=g_new(struct pcoord, 1);
                ret->common.c->x=c.x;
@@ -225,30 +248,13 @@ search_list_town_new(struct item *item)
 static void
 search_list_town_destroy(struct search_list_town *this_)
 {
-       map_convert_free(this_->name);
-       map_convert_free(this_->common.postal);
+       map_convert_free(this_->county);
+       search_list_common_destroy(&this_->common);
        if (this_->common.c)
                g_free(this_->common.c);
        g_free(this_);
 }
 
-static void
-search_list_common_new(struct item *item, struct search_list_common *common)
-{
-       struct attr attr;
-       if (item_attr_get(item, attr_town_name, &attr))
-               common->town_name=map_convert_string(item->map, attr.u.str);
-       else
-               common->town_name=NULL;
-       if (item_attr_get(item, attr_district_name, &attr))
-               common->district_name=map_convert_string(item->map, attr.u.str);
-       else
-               common->district_name=NULL;
-       if (item_attr_get(item, attr_postal, &attr))
-               common->postal=map_convert_string(item->map, attr.u.str);
-       else
-               common->postal=NULL;
-}
 
 static struct search_list_street *
 search_list_street_new(struct item *item)
@@ -272,13 +278,6 @@ search_list_street_new(struct item *item)
        return ret;
 }
 
-static void
-search_list_common_destroy(struct search_list_common *common)
-{
-       map_convert_free(common->town_name);
-       map_convert_free(common->district_name);
-       map_convert_free(common->postal);
-}
 
 static void
 search_list_street_destroy(struct search_list_street *this_)
@@ -360,6 +359,7 @@ search_list_search_free(struct search_list *sl, int level)
                next=g_list_next(curr);
                curr=next;
        }
+       attr_free(le->attr);
        g_list_free(le->list);
        le->list=NULL;
        le->curr=NULL;
@@ -450,8 +450,8 @@ search_list_get_result(struct search_list *this_)
                        }
                        if (le->parent)
                                dbg(1,"mapset_search_new with item(%d,%d)\n", le->parent->item.id_hi, le->parent->item.id_lo);
-                       dbg(1,"attr=%s\n", attr_to_name(le->attr.type));
-                       le->search=mapset_search_new(this_->ms, &le->parent->item, &le->attr, le->partial);
+                       dbg(1,"attr=%s\n", attr_to_name(le->attr->type));
+                       le->search=mapset_search_new(this_->ms, &le->parent->item, le->attr, le->partial);
                        le->hash=g_hash_table_new(search_item_hash_hash, search_item_hash_equal);
                }
                dbg(1,"le->search=%p\n", le->search);
@@ -468,27 +468,31 @@ search_list_get_result(struct search_list *this_)
                        case 0:
                                p=search_list_country_new(item);
                                this_->result.country=p;
+                               this_->result.country->common.parent=NULL;
                                break;
                        case 1:
                                p=search_list_town_new(item);
-                               this_->result.country=this_->levels[0].last->data;
                                this_->result.town=p;
+                               this_->result.town->common.parent=this_->levels[0].last->data;
+                               this_->result.country=this_->result.town->common.parent;
                                this_->result.c=this_->result.town->common.c;
                                break;
                        case 2:
                                p=search_list_street_new(item);
-                               this_->result.country=this_->levels[0].last->data;
-                               this_->result.town=this_->levels[1].last->data;
                                this_->result.street=p;
+                               this_->result.street->common.parent=this_->levels[1].last->data;
+                               this_->result.town=this_->result.street->common.parent;
+                               this_->result.country=this_->result.town->common.parent;
                                this_->result.c=this_->result.street->common.c;
                                break;
                        case 3:
                                p=search_list_house_number_new(item);
-                               this_->result.country=this_->levels[0].last->data;
-                               this_->result.town=this_->levels[1].last->data;
-                               this_->result.street=this_->levels[2].last->data;
                                this_->result.house_number=p;
-                               this_->result.c=this_->result.street->common.c;
+                               this_->result.house_number->common.parent=this_->levels[2].last->data;
+                               this_->result.street=this_->result.house_number->common.parent;
+                               this_->result.town=this_->result.street->common.parent;
+                               this_->result.country=this_->result.town->common.parent;
+                               this_->result.c=this_->result.house_number->common.c;
                                
                        }
                        if (p) {