2014-02-21 22:24:53 -08:00
|
|
|
#include <Elementary.h>
|
|
|
|
#include "common.h"
|
|
|
|
|
2014-02-27 09:45:49 -08:00
|
|
|
typedef struct search_s
|
2014-02-25 17:36:53 -08:00
|
|
|
{
|
2014-02-27 09:45:49 -08:00
|
|
|
Evas_Object *win;
|
2014-02-25 17:36:53 -08:00
|
|
|
int order;
|
2014-02-27 09:45:49 -08:00
|
|
|
} search_data;
|
2014-02-25 17:36:53 -08:00
|
|
|
|
2014-02-27 09:45:49 -08:00
|
|
|
static search_data *g_sd = NULL;
|
|
|
|
static Evas_Coord win_x = -1;
|
|
|
|
static Evas_Coord win_y = -1;
|
|
|
|
static Evas_Coord win_w = 300;
|
|
|
|
static Evas_Coord win_h = 100;
|
|
|
|
|
|
|
|
static void
|
|
|
|
win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
|
2014-02-25 17:36:53 -08:00
|
|
|
{
|
2014-02-27 09:45:49 -08:00
|
|
|
search_data *sd = data;
|
|
|
|
search_close();
|
|
|
|
}
|
|
|
|
|
2014-02-28 06:41:16 -08:00
|
|
|
static void
|
|
|
|
win_moved_cb(void *data, Evas_Object *obj, void *event_info)
|
|
|
|
{
|
|
|
|
/* Move the window with the previous remembered position when the window is
|
|
|
|
moved by window manager first time. */
|
|
|
|
if ((win_x != -1) || (win_y != -1)) evas_object_move(obj, win_x, win_y);
|
|
|
|
evas_object_smart_callback_del(obj, "moved", win_moved_cb);
|
|
|
|
}
|
|
|
|
|
2014-02-27 09:45:49 -08:00
|
|
|
void
|
|
|
|
search_open()
|
|
|
|
{
|
2014-02-28 06:41:16 -08:00
|
|
|
if (g_sd) return;
|
|
|
|
|
2014-02-27 09:45:49 -08:00
|
|
|
search_data *sd = calloc(1, sizeof(search_data));
|
|
|
|
g_sd = sd;
|
|
|
|
|
|
|
|
//Win
|
|
|
|
Evas_Object *win = elm_win_add(base_win_get(), "Enventor Search",
|
2014-02-28 06:41:16 -08:00
|
|
|
ELM_WIN_UTILITY);
|
2014-02-27 09:45:49 -08:00
|
|
|
elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
|
|
|
|
elm_win_title_set(win, "Find/Replace");
|
2014-02-28 06:41:16 -08:00
|
|
|
|
2014-02-27 09:45:49 -08:00
|
|
|
evas_object_resize(win, win_w, win_h);
|
|
|
|
evas_object_smart_callback_add(win, "delete,request", win_delete_request_cb,
|
|
|
|
sd);
|
2014-02-28 06:41:16 -08:00
|
|
|
evas_object_smart_callback_add(win, "moved", win_moved_cb, sd);
|
2014-02-27 09:45:49 -08:00
|
|
|
evas_object_show(win);
|
|
|
|
|
2014-02-28 06:41:16 -08:00
|
|
|
//Bg
|
2014-02-27 09:45:49 -08:00
|
|
|
Evas_Object *bg = elm_bg_add(win);
|
|
|
|
evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_show(bg);
|
|
|
|
elm_win_resize_object_add(win, bg);
|
|
|
|
|
2014-02-28 06:41:16 -08:00
|
|
|
//Layout
|
|
|
|
Evas_Object *layout = elm_layout_add(win);
|
|
|
|
elm_layout_file_set(layout, EDJE_PATH, "search");
|
|
|
|
evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_show(layout);
|
|
|
|
elm_win_resize_object_add(win, layout);
|
|
|
|
|
|
|
|
//Entry (find)
|
|
|
|
Evas_Object *entry_find = elm_entry_add(layout);
|
|
|
|
elm_object_style_set(entry_find, elm_app_name_get());
|
|
|
|
elm_entry_single_line_set(entry_find, EINA_TRUE);
|
|
|
|
elm_entry_scrollable_set(entry_find, EINA_TRUE);
|
|
|
|
evas_object_size_hint_weight_set(entry_find, EVAS_HINT_EXPAND, 0);
|
|
|
|
evas_object_size_hint_align_set(entry_find, EVAS_HINT_FILL, 0);
|
|
|
|
evas_object_show(entry_find);
|
|
|
|
elm_object_part_content_set(layout, "elm.swallow.find_entry", entry_find);
|
|
|
|
|
|
|
|
//Entry (replace)
|
|
|
|
Evas_Object *entry_replace = elm_entry_add(layout);
|
|
|
|
elm_object_style_set(entry_replace, elm_app_name_get());
|
|
|
|
elm_entry_single_line_set(entry_replace, EINA_TRUE);
|
|
|
|
elm_entry_scrollable_set(entry_replace, EINA_TRUE);
|
|
|
|
evas_object_size_hint_weight_set(entry_replace, EVAS_HINT_EXPAND,0);
|
|
|
|
evas_object_size_hint_align_set(entry_replace, EVAS_HINT_FILL, 0);
|
|
|
|
evas_object_show(entry_replace);
|
|
|
|
elm_object_part_content_set(layout, "elm.swallow.replace_entry",
|
|
|
|
entry_replace);
|
2014-02-27 09:45:49 -08:00
|
|
|
sd->win = win;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
search_close()
|
|
|
|
{
|
|
|
|
search_data *sd = g_sd;
|
|
|
|
if (!sd) return;
|
|
|
|
//Save last state
|
|
|
|
evas_object_geometry_get(sd->win, NULL, NULL, &win_w, &win_h);
|
|
|
|
elm_win_screen_position_get(sd->win, &win_x, &win_y);
|
|
|
|
evas_object_del(sd->win);
|
|
|
|
free(sd);
|
|
|
|
g_sd = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
search_word(Evas_Object *entry, const char *word, Eina_Bool *found)
|
|
|
|
{
|
|
|
|
search_data *sd = g_sd;
|
|
|
|
|
2014-02-25 17:36:53 -08:00
|
|
|
*found = EINA_FALSE;
|
|
|
|
|
2014-02-27 09:45:49 -08:00
|
|
|
if (!word) return;
|
2014-02-25 17:36:53 -08:00
|
|
|
|
|
|
|
const char *text = elm_entry_entry_get(entry);
|
|
|
|
const char *utf8 = elm_entry_markup_to_utf8(text);
|
|
|
|
|
|
|
|
//There is no word in the text
|
|
|
|
char *s = strstr(utf8, word);
|
|
|
|
if (!s)
|
|
|
|
{
|
|
|
|
free(sd);
|
2014-02-27 09:45:49 -08:00
|
|
|
return;
|
2014-02-25 17:36:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int order = sd->order;
|
|
|
|
|
|
|
|
//No more next word found
|
2014-02-27 09:45:49 -08:00
|
|
|
if ((order > 0) && (strlen(s) <= 1)) return;
|
2014-02-25 17:36:53 -08:00
|
|
|
|
|
|
|
while (order > 0)
|
|
|
|
{
|
|
|
|
s++;
|
|
|
|
s = strstr(s, word);
|
2014-02-27 09:45:49 -08:00
|
|
|
if (!s) return;
|
2014-02-25 17:36:53 -08:00
|
|
|
order--;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Got you!
|
|
|
|
int len = strlen(word);
|
|
|
|
elm_entry_select_region_set(entry, (s - utf8), (s - utf8) + len);
|
|
|
|
sd->order++;
|
|
|
|
*found = EINA_TRUE;
|
|
|
|
|
2014-02-27 09:45:49 -08:00
|
|
|
return;
|
2014-02-21 22:24:53 -08:00
|
|
|
}
|