2020-05-17 23:10:07 +03:00
|
|
|
|
|
|
|
#define SEARCH_H 34
|
|
|
|
|
|
|
|
|
|
|
|
struct SEARCH
|
|
|
|
{
|
|
|
|
bool visible;
|
|
|
|
int found_count;
|
2020-05-20 22:34:09 +03:00
|
|
|
collection_int found;
|
2020-05-17 23:10:07 +03:00
|
|
|
void show();
|
|
|
|
void hide();
|
|
|
|
bool draw();
|
|
|
|
bool edit_key();
|
|
|
|
bool edit_mouse();
|
2020-05-20 22:34:09 +03:00
|
|
|
int find_all();
|
2020-05-17 23:10:07 +03:00
|
|
|
int find_next();
|
|
|
|
} search;
|
|
|
|
|
|
|
|
char found_text[64];
|
|
|
|
|
|
|
|
char search_text[64];
|
|
|
|
edit_box search_box = {250, 10, NULL, 0xffffff,
|
|
|
|
0x94AECE, 0xffffff, 0xffffff,0x10000000,sizeof(search_text)-1,#search_text};
|
|
|
|
|
|
|
|
|
|
|
|
void SEARCH::show()
|
|
|
|
{
|
|
|
|
visible = true;
|
|
|
|
search_box.flags = ed_focus;
|
|
|
|
draw_window();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SEARCH::hide()
|
|
|
|
{
|
|
|
|
visible = false;
|
|
|
|
draw_window();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SEARCH::edit_key()
|
|
|
|
{
|
|
|
|
if (visible) && (search_box.flags & ed_focus) {
|
|
|
|
EAX = key_editbox;
|
|
|
|
edit_box_key stdcall(#search_box);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SEARCH::edit_mouse()
|
|
|
|
{
|
|
|
|
if (visible) {
|
|
|
|
edit_box_mouse stdcall(#search_box);
|
|
|
|
if (search_box.flags & ed_focus) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SEARCH::draw(dword _btn_find, _btn_hide, _y)
|
|
|
|
{
|
2020-05-18 13:03:45 +03:00
|
|
|
char matches[30];
|
2020-05-17 23:10:07 +03:00
|
|
|
if (!visible) return false;
|
|
|
|
DrawBar(0, _y, Form.cwidth, 1, sc.work_graph);
|
|
|
|
DrawBar(0, _y+1, Form.cwidth, SEARCH_H-1, sc.work);
|
|
|
|
|
|
|
|
search_box.top = _y + 6;
|
2020-05-24 03:18:40 +03:00
|
|
|
search_box.width = math.min(Form.width - 200, 150);
|
2020-05-17 23:10:07 +03:00
|
|
|
|
|
|
|
DrawRectangle(search_box.left-1, search_box.top-1, search_box.width+2, 23,sc.work_graph);
|
|
|
|
|
|
|
|
edit_box_draw stdcall(#search_box);
|
|
|
|
|
2020-05-24 03:18:40 +03:00
|
|
|
DrawCaptButton(search_box.left+search_box.width+14, search_box.top-1, 100,
|
2020-05-17 23:10:07 +03:00
|
|
|
TOOLBAR_ICON_HEIGHT+1, _btn_find, sc.work_light, sc.work_text, T_FIND_NEXT);
|
|
|
|
|
2020-05-20 22:34:09 +03:00
|
|
|
sprintf(#matches, T_MATCHES, found.count);
|
2020-05-24 03:18:40 +03:00
|
|
|
WriteTextWithBg(search_box.left+search_box.width+14+115,
|
2020-05-18 13:03:45 +03:00
|
|
|
search_box.top+3, 0xD0, sc.work_text, #matches, sc.work);
|
2020-05-17 23:10:07 +03:00
|
|
|
|
|
|
|
DefineHiddenButton(Form.cwidth-26, search_box.top-1, TOOLBAR_ICON_HEIGHT+1,
|
|
|
|
TOOLBAR_ICON_HEIGHT+1, _btn_hide);
|
|
|
|
WriteText(Form.cwidth-26+7, search_box.top+2, 0x81, sc.work_graph, "x");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-20 22:34:09 +03:00
|
|
|
int SEARCH::find_all()
|
2020-05-17 23:10:07 +03:00
|
|
|
{
|
2020-05-20 22:34:09 +03:00
|
|
|
dword haystack = io.buffer_data;
|
|
|
|
int needle_len = strlen(#found_text);
|
|
|
|
found.drop();
|
|
|
|
loop() {
|
|
|
|
if (! haystack = strstri(haystack, #found_text)) break;
|
|
|
|
found.add(haystack - needle_len);
|
|
|
|
haystack += needle_len;
|
|
|
|
}
|
2020-05-17 23:10:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int SEARCH::find_next(int _cur_pos)
|
|
|
|
{
|
|
|
|
int i;
|
2020-05-24 03:18:40 +03:00
|
|
|
dword t1, t2;
|
2020-05-17 23:10:07 +03:00
|
|
|
if (!search_text[0]) return false;
|
|
|
|
|
2020-05-20 22:34:09 +03:00
|
|
|
if (!streq(#found_text, #search_text)) {
|
|
|
|
strcpy(#found_text, #search_text);
|
|
|
|
find_all();
|
2020-05-24 03:18:40 +03:00
|
|
|
draw_window();
|
2020-05-20 22:34:09 +03:00
|
|
|
}
|
2020-05-17 23:10:07 +03:00
|
|
|
|
2020-05-24 03:18:40 +03:00
|
|
|
for (i=0; i<found.count; i++) {
|
|
|
|
if (signed found.get(i) - lines.get(_cur_pos) > 0) {
|
|
|
|
t1 = found.get(i);
|
|
|
|
while(t1 > lines.get(_cur_pos)) _cur_pos++;
|
|
|
|
return _cur_pos-1;
|
|
|
|
}
|
|
|
|
}
|
2020-05-17 23:10:07 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|