Subversion Repositories Kolibri OS

Rev

Rev 7872 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7872 Rev 7895
1
#include "../lib/collection.h"
1
#include "../lib/collection.h"
2
 
2
 
3
#define SEARCH_H 34
3
#define SEARCH_H 34
4
 
4
 
5
 
5
 
6
struct SEARCH
6
struct SEARCH
7
{
7
{
8
	bool visible;
8
	bool visible;
9
	int found_count;
9
	int found_count;
10
	collection lines;
10
	collection lines;
11
	collection pos;
11
	collection pos;
12
	void show();
12
	void show();
13
	void hide();
13
	void hide();
14
	bool draw();
14
	bool draw();
15
	void draw_found();
15
	void draw_found();
16
	int height();
16
	int height();
17
	bool edit_key();
17
	bool edit_key();
18
	bool edit_mouse();
18
	bool edit_mouse();
19
	void add();
19
	void add();
20
	void clear();
20
	void clear();
21
	int find_next();
21
	int find_next();
22
	int highlight();
22
	int highlight();
23
} search;
23
} search;
24
 
24
 
25
char search_text[64];
25
char search_text[64];
26
char found_text[64];
26
char found_text[64];
27
edit_box search_box = {250, 10, NULL, 0xffffff,
27
edit_box search_box = {250, 10, NULL, 0xffffff,
28
0x94AECE, 0xffffff, 0xffffff,0x10000000,sizeof(search_text)-1,#search_text};
28
0x94AECE, 0xffffff, 0xffffff,0x10000000,sizeof(search_text)-1,#search_text};
29
 
29
 
30
 
30
 
31
void SEARCH::show()
31
void SEARCH::show()
32
{
32
{
33
	visible = true;
33
	visible = true;
34
	search_box.flags = ed_focus;
34
	search_box.flags = ed_focus;
35
	draw_window();
35
	draw_window();
36
}
36
}
37
 
37
 
38
void SEARCH::hide()
38
void SEARCH::hide()
39
{
39
{
40
	visible = false;
40
	visible = false;
41
	draw_window();
41
	draw_window();
42
}
42
}
43
 
43
 
44
int SEARCH::height()
44
int SEARCH::height()
45
{
45
{
46
	return visible * SEARCH_H;
46
	return visible * SEARCH_H;
47
}
47
}
48
 
48
 
49
bool SEARCH::edit_key()
49
bool SEARCH::edit_key()
50
{
50
{
51
	if (visible) && (search_box.flags & ed_focus) {
51
	if (visible) && (search_box.flags & ed_focus) {
52
		EAX = key_editbox; 
52
		EAX = key_editbox; 
53
		edit_box_key stdcall(#search_box);
53
		edit_box_key stdcall(#search_box);
54
		return true;
54
		return true;
55
	}
55
	}
56
	return false;
56
	return false;
57
}
57
}
58
 
58
 
59
bool SEARCH::edit_mouse()
59
bool SEARCH::edit_mouse()
60
{
60
{
61
	if (visible) {
61
	if (visible) {
62
		edit_box_mouse stdcall(#search_box);
62
		edit_box_mouse stdcall(#search_box);
63
		if (search_box.flags & ed_focus) return true;
63
		if (search_box.flags & ed_focus) return true;
64
	}
64
	}
65
	return false;
65
	return false;
66
}
66
}
67
 
67
 
68
void SEARCH::draw_found()
68
void SEARCH::draw_found()
69
{
69
{
70
	char matches[30];
70
	char matches[30];
71
	strcpy(#matches, "Matches: ");
71
	strcpy(#matches, "Matches: ");
72
	strcat(#matches, itoa(found_count));
72
	strcat(#matches, itoa(found_count));
73
	strcat(#matches, "   ");	
73
	strcat(#matches, "   ");	
74
	WriteTextWithBg(search_box.left+search_box.width+14+110, search_box.top+3, 0xD0, sc.work_text, #matches, sc.work);
74
	WriteTextWithBg(search_box.left+search_box.width+14+110, search_box.top+3, 0xD0, sc.work_text, #matches, sc.work);
75
}
75
}
76
 
76
 
77
bool SEARCH::draw(dword _btn_find, _btn_hide, _y)
77
bool SEARCH::draw(dword _btn_find, _btn_hide, _y)
78
{
78
{
79
	if (!visible) return false;
79
	if (!visible) return false;
80
	DrawBar(0, _y, Form.cwidth, 1, sc.work_graph);
80
	DrawBar(0, _y, Form.cwidth, 1, sc.work_graph);
81
	DrawBar(0, _y+1, Form.cwidth, SEARCH_H-1, sc.work);
81
	DrawBar(0, _y+1, Form.cwidth, SEARCH_H-1, sc.work);
82
 
82
 
83
	search_box.top = _y + 6;
83
	search_box.top = _y + 6;
84
	search_box.width = math.min(Form.width - 200, 250);
84
	search_box.width = math.min(Form.width - 200, 250);
85
 
85
 
86
	DrawRectangle(search_box.left-1, search_box.top-1, search_box.width+2, 23,sc.work_graph);
86
	DrawRectangle(search_box.left-1, search_box.top-1, search_box.width+2, 23,sc.work_graph);
87
 
87
 
88
	edit_box_draw stdcall(#search_box);
88
	edit_box_draw stdcall(#search_box);
89
 
89
 
90
	DrawCaptButton(search_box.left+search_box.width+14, search_box.top-1, 90, 
90
	DrawCaptButton(search_box.left+search_box.width+14, search_box.top-1, 90, 
91
		TOOLBAR_ICON_HEIGHT+1, _btn_find, sc.work_light, sc.work_text, "Find next");
91
		TOOLBAR_ICON_HEIGHT+1, _btn_find, sc.work_light, sc.work_text, "Find next");
92
 
92
 
93
	draw_found();
93
	draw_found();
94
 
94
 
95
	DefineHiddenButton(Form.cwidth-26, search_box.top-1, TOOLBAR_ICON_HEIGHT+1, 
95
	DefineHiddenButton(Form.cwidth-26, search_box.top-1, TOOLBAR_ICON_HEIGHT+1, 
96
		TOOLBAR_ICON_HEIGHT+1, _btn_hide);
96
		TOOLBAR_ICON_HEIGHT+1, _btn_hide);
97
	WriteText(Form.cwidth-26+7, search_box.top+2, 0x81, sc.work_graph, "x");
97
	WriteText(Form.cwidth-26+7, search_box.top+2, 0x81, sc.work_graph, "x");
98
	return true;
98
	return true;
99
}
99
}
100
 
100
 
101
void SEARCH::clear()
101
void SEARCH::clear()
102
{
102
{
103
	pos.drop();
103
	pos.drop();
104
	lines.drop();
104
	lines.drop();
105
	visible = false;
105
	visible = false;
106
	found_text[0] = '\0';
106
	found_text[0] = '\0';
107
	found_count = 0;
107
	found_count = 0;
108
}
108
}
109
 
109
 
110
void SEARCH::add(dword _pos, _line)
110
void SEARCH::add(dword _pos, _line)
111
{
111
{
112
	pos.add(itoa(_pos));
112
	pos.add(itoa(_pos));
113
	lines.add(_line);
113
	lines.add(_line);
114
}
114
}
115
 
115
 
116
int SEARCH::find_next(int _cur_pos, _bg_color)
116
int SEARCH::find_next(int _cur_pos, _bg_color)
117
{
117
{
118
	int i;
118
	int i;
119
	if (!search_text[0]) return false;
119
	if (!search_text[0]) return false;
120
 
120
 
121
		strcpy(#found_text, #search_text);
121
		strcpy(#found_text, #search_text);
122
		highlight(0xFF0000, _bg_color);
122
		highlight(0xFF0000, _bg_color);
123
		draw_found();
123
		draw_found();
124
 
124
 
125
	for (i=_cur_pos+1; i
125
	for (i=_cur_pos+1; i
126
		if (strstri(lines.get(i),#search_text)!=-1) return atoi(pos.get(i));
126
		if (strstri(lines.get(i),#search_text)!=-1) return atoi(pos.get(i));
127
	}
127
	}
128
	return false;
128
	return false;
129
}
129
}
130
 
130
 
131
int SEARCH::highlight(dword _color, _bg_color)
131
int SEARCH::highlight(dword _color, _bg_color)
132
{
132
{
133
	int i;
133
	int i;
134
	dword col;
134
	dword col;
135
	found_count = 0;
135
	found_count = 0;
136
	for (i=0; i
136
	for (i=0; i
137
		if (strstri(lines.get(i),#search_text)==-1) {
137
		if (strstri(lines.get(i),#search_text)==-1) {
138
			col=_bg_color;
138
			col=_bg_color;
139
		} else {
139
		} else {
140
			col=_color;
140
			col=_color;
141
			found_count++;	
141
			found_count++;	
142
		} 
142
		} 
143
		draw_bar(0, atoi(pos.get(i)), 3, list.item_h, col);
143
		//draw_bar(0, atoi(pos.get(i)), 3, list.item_h, col);
144
	}
144
	}
145
}
145
}
146
 
146
 
147
:void draw_bar(dword _x, _y, _w, _h, _color)
147
:void draw_bar(dword _x, _y, _w, _h, _color)
148
{
148
{
149
	int i;
149
	int i;
150
	for (i = _y*list.w+_x*4+kfont.raw ; i<_y*list.w+_x+_w*4+kfont.raw ; i+=4) 
150
	for (i = _y*list.w+_x*4+kfont.raw ; i<_y*list.w+_x+_w*4+kfont.raw ; i+=4) 
151
	{
151
	{
152
		ESDWORD[i] = _color;
152
		ESDWORD[i] = _color;
153
	}
153
	}
154
	if (_h>0) draw_bar(dword _x, _y+1, _w, _h-1, _color);
154
	if (_h>0) draw_bar(dword _x, _y+1, _w, _h-1, _color);
155
}
155
}