Subversion Repositories Kolibri OS

Rev

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

Rev 7444 Rev 8954
1
#define MAX_LINE_CHARS 256
1
#define MAX_LINE_CHARS 128
2
 
2
 
3
#define CHBOX 12
3
#define CHBOX 12
4
#define CHECKBOX_ID 50
4
#define CHECKBOX_ID 50
5
unsigned char checkbox[sizeof(file "img/checkbox.raw")]= FROM "img/checkbox.raw";
5
unsigned char checkbox[sizeof(file "img/checkbox.raw")]= FROM "img/checkbox.raw";
6
 
6
 
7
#define COL_BG_ACTIVE 0xFFF0A9
7
#define COL_BG_ACTIVE 0xFFF0A9
8
#define COL_BG_INACTIVE 0xFFFFFF
8
#define COL_BG_INACTIVE 0xFFFFFF
9
 
9
 
10
//===================================================//
10
//===================================================//
11
//                                                   //
11
//                                                   //
12
//                       LINE                        //
12
//                       LINE                        //
13
//                                                   //
13
//                                                   //
14
//===================================================//
14
//===================================================//
15
 
15
 
16
struct NOTE_LINE
16
struct NOTE_LINE
17
{
17
{
18
	bool state;
18
	bool state;
19
	char data[MAX_LINE_CHARS];
19
	char data[MAX_LINE_CHARS];
20
	void Delete();
20
	void Delete();
21
};
21
};
22
 
22
 
23
void NOTE_LINE::Delete()
23
void NOTE_LINE::Delete()
24
{
24
{
25
	state=false;
25
	state=false;
26
	data[0]=' ';
26
	data[0]=' ';
27
	data[1]=NULL;
27
	data[1]=NULL;
28
}
28
}
29
 
29
 
30
//===================================================//
30
//===================================================//
31
//                                                   //
31
//                                                   //
32
//                       LIST                        //
32
//                       LIST                        //
33
//                                                   //
33
//                                                   //
34
//===================================================//
34
//===================================================//
35
 
35
 
36
struct NOTES : llist {
36
struct NOTES : llist {
37
	char txt_path[4096];
37
	char txt_path[4096];
38
	char txt_data[MAX_LINE_CHARS*LINES_COUNT];
38
	char txt_data[MAX_LINE_CHARS+4*LINES_COUNT+30];
39
	bool txt_file_exists;
39
	bool txt_file_exists;
40
 
40
 
41
	NOTE_LINE lines[LINES_COUNT]; 
41
	NOTE_LINE lines[LINES_COUNT]; 
42
 
42
 
43
	char edit_active;
43
	char edit_active;
44
	int OpenTxt();
44
	int OpenTxt();
45
	int SaveTxt();
45
	int SaveTxt();
46
	void DrawList();
46
	void DrawList();
47
	dword DrawLine(int line_n, draw_h);
47
	dword DrawLine(int line_n, draw_h);
48
} notes;
48
} notes;
49
 
49
 
50
 
50
 
51
int NOTES::OpenTxt(dword file_path)
51
int NOTES::OpenTxt(dword file_path)
52
{
52
{
53
	int i=0, linepos=0;
53
	int i=0, linepos=0;
54
	int item_n=-1;
54
	int item_n=-1;
55
 
55
 
56
	count = LINES_COUNT;
56
	count = LINES_COUNT;
57
 
57
 
58
	strcpy(#txt_path, file_path);
58
	strcpy(#txt_path, file_path);
59
	ReadFile(0, 4096, #txt_data, #txt_path);
59
	ReadFile(0, 4096, #txt_data, #txt_path);
60
	if (!txt_data) || (strncmp(#txt_data, "notes", 5)!=0)
60
	if (!txt_data) || (strncmp(#txt_data, "notes", 5)!=0)
61
	{
61
	{
62
		txt_file_exists = false;
62
		txt_file_exists = false;
63
		return 0;
63
		return 0;
64
	}
64
	}
65
	else
65
	else
66
	{
66
	{
67
		txt_file_exists = true;
67
		txt_file_exists = true;
68
		i+=5; //skip "notes" indefinier
68
		i+=5; //skip "notes" indefinier
69
		while (txt_data[i]) 
69
		while (txt_data[i]) 
70
		{
70
		{
71
			if (txt_data[i]=='\n') {
71
			if (txt_data[i]=='\n') {
72
				item_n++;
72
				item_n++;
73
				i+=2;
73
				i+=2;
74
				if (txt_data[i]=='-') lines[item_n].state=false; else lines[item_n].state=true;
74
				if (txt_data[i]=='-') lines[item_n].state=false; else lines[item_n].state=true;
75
				i+=2;
75
				i+=2;
76
				linepos = 0;
76
				linepos = 0;
77
				continue;
77
				continue;
78
			}
78
			}
79
			if (linepos
79
			if (linepos
80
			linepos++;				
80
			linepos++;				
81
			i++;
81
			i++;
82
		}
82
		}
83
		while (item_n < LINES_COUNT)
83
		while (item_n < LINES_COUNT)
84
		{
84
		{
85
			//lines[item_n].Delete();
85
			//lines[item_n].Delete();
86
			item_n++;
86
			item_n++;
87
		}
87
		}
88
		return 1;
88
		return 1;
89
	}
89
	}
90
}
90
}
91
 
91
 
92
int NOTES::SaveTxt()
92
int NOTES::SaveTxt()
93
{
93
{
94
	int i;
94
	int i;
95
	dword tm;
95
	dword tm;
96
	strcpy(#txt_data, "notes");
96
	strcpy(#txt_data, "notes");
97
	for (i=0; i<=count; i++)
97
	for (i=0; i<=count; i++)
98
	{
98
	{
99
		if (lines[i].state==false) strcat(#txt_data, "\n- "); else strcat(#txt_data, "\n+ ");
99
		if (lines[i].state==false) strcat(#txt_data, "\n- "); else strcat(#txt_data, "\n+ ");
100
		tm = #lines[i].data;
100
		tm = #lines[i].data;
101
		strcat(#txt_data, #lines[i].data);
101
		strcat(#txt_data, #lines[i].data);
102
	}
102
	}
103
	if (!txt_file_exists) CreateFile(0, 0, #txt_path);
103
	if (!txt_file_exists) CreateFile(0, 0, #txt_path);
104
	WriteFile(0, strlen(#txt_data), #txt_data, #txt_path);
104
	WriteFile(0, strlen(#txt_data), #txt_data, #txt_path);
105
}
105
}
106
 
106
 
107
void NOTES::DrawList()
107
void NOTES::DrawList()
108
{
108
{
109
	int i;
109
	int i;
110
	for (i=0; i
110
	for (i=0; i
111
}
111
}
112
 
112
 
113
 
113
 
114
dword NOTES::DrawLine(int line_n, draw_h) {
114
dword NOTES::DrawLine(int line_n, draw_h) {
115
	dword 
115
	dword 
116
		COL_BOTTOM_LINE=0xE8EFF4,
116
		COL_BOTTOM_LINE=0xE8EFF4,
117
		COL_BG,
117
		COL_BG,
118
		cur_text;
118
		cur_text;
119
	int drawy;
119
	int drawy;
120
	char line_text[4096];
120
	char line_text[4096];
121
	if (line_n<0) return;
121
	if (line_n<0) return;
122
	x = 1;
122
	x = 1;
123
	if (line_n==cur_y) COL_BG = COL_BG_ACTIVE; else COL_BG = COL_BG_INACTIVE;
123
	if (line_n==cur_y) COL_BG = COL_BG_ACTIVE; else COL_BG = COL_BG_INACTIVE;
124
	DrawBar(x, line_n*item_h+y, RED_LINE_X, draw_h-1, COL_BG_INACTIVE);
124
	DrawBar(x, line_n*item_h+y, RED_LINE_X, draw_h-1, COL_BG_INACTIVE);
125
	DrawBar(x+RED_LINE_X+1, line_n*item_h+y, w-RED_LINE_X-1, draw_h-1, COL_BG);
125
	DrawBar(x+RED_LINE_X+1, line_n*item_h+y, w-RED_LINE_X-1, draw_h-1, COL_BG);
126
 
126
 
127
	cur_text = #lines[line_n].data;
127
	cur_text = #lines[line_n].data;
128
 
128
 
129
	if (draw_h!=item_h) 
129
	if (draw_h!=item_h) 
130
	{
130
	{
131
		COL_BOTTOM_LINE=COL_BG;
131
		COL_BOTTOM_LINE=COL_BG;
132
	}
132
	}
133
	else
133
	else
134
	{
134
	{
135
		drawy = item_h*line_n+5+y;
135
		drawy = item_h*line_n+5+y;
136
		DefineButton(RED_LINE_X-CHBOX/2+x, drawy, CHBOX-1,CHBOX-1, CHECKBOX_ID+line_n+BT_HIDE, 0); //checkbox
136
		DefineButton(RED_LINE_X-CHBOX/2+x, drawy, CHBOX-1,CHBOX-1, CHECKBOX_ID+line_n+BT_HIDE, 0); //checkbox
137
		_PutImage(RED_LINE_X-CHBOX/2+x,drawy, CHBOX,CHBOX, lines[line_n].state*CHBOX*CHBOX*3+#checkbox);
137
		_PutImage(RED_LINE_X-CHBOX/2+x,drawy, CHBOX,CHBOX, lines[line_n].state*CHBOX*CHBOX*3+#checkbox);
138
		if (cur_text) WriteText(x+RED_LINE_X+6, drawy+2, 0x80, lines[line_n].state*0x777777, cur_text);
138
		if (cur_text) WriteText(x+RED_LINE_X+6, drawy+2, 0x80, lines[line_n].state*0x777777, cur_text);
139
		if (lines[line_n].state == true) DrawBar(x+RED_LINE_X+6, drawy+6, strlen(cur_text)*6, 1, 0x444444); //strike
139
		if (lines[line_n].state == true) DrawBar(x+RED_LINE_X+6, drawy+6, strlen(cur_text)*6, 1, 0x444444); //strike
140
		DrawBar(WIN_W,drawy,1,item_h,0xBBBBBB); //fast fix; proper fix is to restrict WriteText() char length
140
		DrawBar(WIN_W,drawy,1,item_h,0xBBBBBB); //fast fix; proper fix is to restrict WriteText() char length
141
	}
141
	}
142
	DrawBar(x, line_n*item_h+draw_h-1+y, w, 1, COL_BOTTOM_LINE);
142
	DrawBar(x, line_n*item_h+draw_h-1+y, w, 1, COL_BOTTOM_LINE);
143
	DrawBar(x+RED_LINE_X, line_n*item_h+y, 1, draw_h, COL_RED_LINE);
143
	DrawBar(x+RED_LINE_X, line_n*item_h+y, 1, draw_h, COL_RED_LINE);
144
	x = RED_LINE_X;
144
	x = RED_LINE_X;
145
	return cur_text;
145
	return cur_text;
146
}
146
}