/*************************************************************************** * gui_search.c * * 2011-03-10 * Copyright (C) 2011 Steffen Pohle * steffen@gulpe.de ****************************************************************************/ /* * 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 3 of the License, or * (at your option) any later version. * * main.c 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 program. If not, see . */ #include "osmroute.h" #include "draw.h" #include "gui.h" #include "system.h" enum { SEARCHWIN_UNDEF = 0, SEARCHWIN_SEARCH, SEARCHWIN_NEXT, SEARCHWIN_PREV, SEARCHWIN_CLOSE, SEARCHWIN_LABEL, SEARCHWIN_REFRESH, SEARCHWIN_TEXT }; #define SEARCH_MAXRESULT 32 void gui_search_close (); void gui_search_refresh (); void gui_search_next (); void gui_search_prev (); void gui_search_search (); void gui_search_switch (int pos); struct map_search_data search_data[SEARCH_MAXRESULT]; int search_data_cnt = 0; int search_data_cur = -1; static GUIWindow wsearch = {0}; void gui_search_show () { int btn = 0; if (wsearch.screen == NULL) guiwindow_new (&wsearch, 220, 60); wsearch.screen_changed = 1; // wmmenu.callback_close = (void*)gui_mainmenu_closecallback; wsearch.screen_changed = 1; wsearch.style = WGUI_S_VCENTER | WGUI_S_HTOP; wsearch.title[0] = 0; /* search buttons */ strncpy (wsearch.buttons[btn].caption, _("<"), GUI_TEXTLEN); wsearch.buttons[btn].callback_clicked = (void*)gui_search_prev; wsearch.buttons[btn].id = SEARCHWIN_PREV; wsearch.buttons[btn].w = 20; wsearch.buttons[btn].h = 20; wsearch.buttons[btn].x = 5; wsearch.buttons[btn].y = 35; strncpy (wsearch.buttons[++btn].caption, _(">"), GUI_TEXTLEN); wsearch.buttons[btn].callback_clicked = (void*)gui_search_next; wsearch.buttons[btn].id = SEARCHWIN_NEXT; wsearch.buttons[btn].w = 20; wsearch.buttons[btn].h = 20; wsearch.buttons[btn].x = 85; wsearch.buttons[btn].y = 35; strncpy (wsearch.buttons[++btn].caption, _("Search"), GUI_TEXTLEN); wsearch.buttons[btn].callback_clicked = (void*)gui_search_search; wsearch.buttons[btn].id = SEARCHWIN_SEARCH; wsearch.buttons[btn].w = 50; wsearch.buttons[btn].h = 20; wsearch.buttons[btn].x = 110; wsearch.buttons[btn].y = 35; strncpy (wsearch.buttons[++btn].caption, _("Ref"), GUI_TEXTLEN); wsearch.buttons[btn].callback_clicked = (void*)gui_search_refresh; wsearch.buttons[btn].id = SEARCHWIN_REFRESH; wsearch.buttons[btn].w = 30; wsearch.buttons[btn].h = 20; wsearch.buttons[btn].x = 165; wsearch.buttons[btn].y = 35; strncpy (wsearch.buttons[++btn].caption, _("X"), GUI_TEXTLEN); wsearch.buttons[btn].callback_clicked = (void*)gui_search_close; wsearch.buttons[btn].id = SEARCHWIN_CLOSE; wsearch.buttons[btn].w = 15; wsearch.buttons[btn].h = 20; wsearch.buttons[btn].x = 200; wsearch.buttons[btn].y = 35; /* add label */ btn = 0; strncpy (wsearch.labels[btn].text, "0/0", GUI_TEXTLEN); wsearch.labels[btn].x = 35; wsearch.labels[btn].y = 37; wsearch.labels[btn].id = SEARCHWIN_LABEL; wsearch.labels[btn].textcol = &color[COLOR_white][3]; /* add entry box */ btn = 0; strncpy (wsearch.entrys[btn].text, "", GUI_TEXTLEN); wsearch.entrys[btn].id = SEARCHWIN_TEXT; wsearch.entrys[btn].x = 5; wsearch.entrys[btn].y = 5; wsearch.entrys[btn].w = 210; wsearch.entrys[btn].h = 20; wsearch.entrys[btn].curpos = 4; wsearch.entrys[btn].overwrite = 0; wsearch.entrys[btn].callback_enter = (void*)gui_search_search; gui_show (&wsearch); }; void gui_search_close () { gui_close (); }; void gui_search_refresh () { map_refresh (view_lon, view_lat); draw_redrawmap (); draw (); }; void gui_search_prev () { d_printf ("search_data_cur:%d", search_data_cur); gui_search_switch (search_data_cur-1); d_printf ("search_data_cur:%d", search_data_cur); }; void gui_search_next () { d_printf ("search_data_cur:%d", search_data_cur); gui_search_switch (search_data_cur+1); d_printf ("search_data_cur:%d", search_data_cur); }; void gui_search_search () { d_printf ("search for %s", wsearch.entrys[0].text); search_data_cnt = map_search (wsearch.entrys[0].text, search_data, SEARCH_MAXRESULT); gui_search_switch (0); }; void gui_search_switch (int pos) { d_printf ("gui_search_switch %d to %d", search_data_cur, pos); search_data_cur = pos; if (search_data_cnt <= 0) search_data_cur = -1; else if (search_data_cur >= search_data_cnt) search_data_cur = 0; else if (search_data_cur < 0) search_data_cur = search_data_cnt - 1; if (search_data_cur == -1) strncpy (wsearch.labels[0].text, _("0"), GUI_TEXTLEN); else { snprintf (wsearch.labels[0].text, GUI_TEXTLEN, _("%d of %d"), search_data_cur+1, search_data_cnt); strncpy (wsearch.entrys[0].text, search_data[search_data_cur].name, GUI_TEXTLEN); view_lon = search_data[search_data_cur].lon; view_lat = search_data[search_data_cur].lat; wsearch.screen_changed = 1; wsearch.entrys[0].curpos = strlen (wsearch.entrys[0].text); draw (); } };