Subversion Repositories Kolibri OS

Rev

Rev 6251 | Rev 6264 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4078 leency 1
//11.03.12 - start!
6212 leency 2
//ver 2.0
4078 leency 3
 
4085 leency 4
#ifndef AUTOBUILD
5
	?include "lang.h--"
6
#endif
7
 
4078 leency 8
#define MEMSIZE 0xFE800
9
#include "..\lib\mem.h"
4085 leency 10
#include "..\lib\strings.h"
5654 leency 11
#include "..\lib\io.h"
4078 leency 12
#include "..\lib\list_box.h"
6212 leency 13
#include "..\lib\menu.h"
5499 leency 14
#include "..\lib\gui.h"
15
#include "..\lib\obj\box_lib.h"
4078 leency 16
 
6212 leency 17
 
18
//===================================================//
19
//                                                   //
20
//                       DATA                        //
21
//                                                   //
22
//===================================================//
23
 
4085 leency 24
#ifdef LANG_RUS
6212 leency 25
	?define WINDOW_HEADER "Настройки оформления"
26
	?define T_SKINS       "   Стиль окон"
27
	?define T_WALLPAPERS  "   Обои"
4085 leency 28
#else
29
	?define WINDOW_HEADER "Appearance"
4411 leency 30
	?define T_SKINS       "   Skins"
31
	?define T_WALLPAPERS  "   Wallpappers"
4085 leency 32
#endif
4078 leency 33
 
4544 leency 34
unsigned char icons[]= FROM "icons.raw";
4085 leency 35
 
6212 leency 36
#define PANEL_H 40
37
#define LIST_PADDING 20
38
#define TAB_PADDING 16
39
#define TAB_HEIGHT 25
5765 leency 40
#define SKINS_STANDART_PATH "/kolibrios/res/skins"
4885 leency 41
#define WALP_STANDART_PATH "/kolibrios/res/wallpapers"
4078 leency 42
 
6212 leency 43
llist list;
44
signed int active_tab, active_skin=-1, active_wallpaper=-1;
45
enum { SKINS=2, WALLPAPERS };
4078 leency 46
 
47
char folder_path[4096];
48
char cur_file_path[4096];
49
char temp_filename[4096];
6096 leency 50
int files_mas[400];
4078 leency 51
 
52
int cur;
53
 
54
proc_info Form;
55
 
4085 leency 56
scroll_bar scroll1 = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
57
 
4078 leency 58
 
6212 leency 59
//===================================================//
60
//                                                   //
61
//                       CODE                        //
62
//                                                   //
63
//===================================================//
5548 leency 64
 
4078 leency 65
void main()
66
{
5705 punk_joker 67
	int id, mouse_clicked;
4078 leency 68
 
4410 leency 69
	SetEventMask(0x27);
5626 leency 70
	load_dll(boxlib, #box_lib_init,0);
6212 leency 71
	EventTabClick(SKINS);
6096 leency 72
	loop() switch(WaitEvent())
4078 leency 73
	{
74
	  	case evMouse:
4085 leency 75
			if (!CheckActiveProcess(Form.ID)) break;
5656 pavelyakov 76
			mouse.get();
4085 leency 77
			scrollbar_v_mouse (#scroll1);
6212 leency 78
			if (list.first != scroll1.position)
4085 leency 79
			{
6212 leency 80
				list.first = scroll1.position;
4085 leency 81
				Draw_List();
82
				break;
83
			}
4410 leency 84
 
6212 leency 85
	  		if (mouse.vert) && (list.MouseScroll(mouse.vert)) Draw_List();
4410 leency 86
 
5656 pavelyakov 87
	  		if (mouse.up)&&(mouse_clicked)
4078 leency 88
	  		{
6212 leency 89
	  			if (mouse.lkm) && (list.ProcessMouse(mouse.x, mouse.y)) EventApply();
5656 pavelyakov 90
	  			mouse_clicked=false;
4078 leency 91
	  		}
6212 leency 92
	  		else if (mouse.down)&&(mouse.lkm) && (list.MouseOver(mouse.x, mouse.y)) mouse_clicked=true;
93
 
94
	  		if (mouse.down)&&(mouse.pkm) {
95
	  			list.ProcessMouse(mouse.x, mouse.y);
96
				Draw_List();
97
	  			menu.show(Form.left+mouse.x, Form.top+mouse.y+skin_height, 136, "Open file     Enter\nDelete          Del", 10);
98
	  		}
99
 
4078 leency 100
	  		break;
101
 
4410 leency 102
 
4078 leency 103
		case evButton:
104
			id=GetButtonID();
105
			if (id==1) ExitProcess();
6212 leency 106
			if (id==SKINS) EventTabClick(SKINS);
107
			if (id==WALLPAPERS) EventTabClick(WALLPAPERS);
4078 leency 108
			break;
109
 
110
		case evKey:
5706 leency 111
			GetKeys();
6212 leency 112
			if (list.ProcessKey(key_scancode)) EventApply();
113
			if (key_scancode==SCAN_CODE_ENTER) EventOpenFile();
114
			if (key_scancode==SCAN_CODE_TAB) if (active_tab==SKINS) EventTabClick(WALLPAPERS); else EventTabClick(SKINS);
115
			if (key_scancode==SCAN_CODE_DEL) EventDeleteFile();
116
			for (id=list.cur_y+1; id
4078 leency 117
			{
6212 leency 118
				strcpy(#temp_filename, io.dir.position(files_mas[id]));
119
				if (temp_filename[0]==key_ascii) || (temp_filename[0]==key_ascii-32)
120
				{
121
					list.cur_y = id - 1;
122
					list.KeyDown();
123
					EventApply();
124
					break;
125
				}
4078 leency 126
			}
127
			break;
128
 
129
		 case evReDraw:
5674 pavelyakov 130
			system.color.get();
6212 leency 131
			DefineAndDrawWindow(screen.width-400/2,80,400,404+skin_height,0x73,0xE4DFE1,WINDOW_HEADER,0);
4078 leency 132
			GetProcessInfo(#Form, SelfInfo);
133
			IF (Form.status_window>=2) break;
6212 leency 134
		 	DrawWindowContent();
135
		 	debugi(menu.list.cur_y);
136
	 		if (menu.list.cur_y) {
137
				if (menu.list.cur_y == 10) EventOpenFile();
138
				if (menu.list.cur_y == 11) EventDeleteFile();
139
				menu.list.cur_y = 0;
140
			};
4078 leency 141
   }
142
}
143
 
6212 leency 144
void DrawWindowContent()
145
{
146
	int id;
147
	list.SetFont(8, 14, 0x90);
148
	id = list.cur_y;
149
	list.SetSizes(LIST_PADDING, PANEL_H, Form.cwidth-scroll1.size_x-LIST_PADDING-LIST_PADDING, Form.cheight-PANEL_H-LIST_PADDING, 20);
150
	list.cur_y = id;
4078 leency 151
 
6212 leency 152
	DrawBar(0,0, Form.cwidth, PANEL_H-LIST_PADDING, system.color.work);
153
	DrawRectangle3D(list.x-2, list.y-2, list.w+3+scroll1.size_x, list.h+3, system.color.work_dark, system.color.work_light);
154
	DrawWideRectangle(list.x-LIST_PADDING, list.y-LIST_PADDING, LIST_PADDING*2+list.w+scroll1.size_x, LIST_PADDING*2+list.h, LIST_PADDING-2, system.color.work);
155
	DrawTab(list.x+10, list.y, SKINS, T_SKINS);
6251 leency 156
	if (dir_exists(WALP_STANDART_PATH)) DrawTab(strlen(T_SKINS)*8+TAB_PADDING+list.x+21, list.y, WALLPAPERS, T_WALLPAPERS);
6212 leency 157
	DrawRectangle(list.x-1, list.y-1, list.w+1+scroll1.size_x, list.h+1, system.color.work_graph);
158
 
159
	Draw_List();
160
}
161
 
162
void DrawTab(dword x,y, but_id, text)
4410 leency 163
{
164
	dword col_bg, col_text;
6212 leency 165
	dword w=strlen(text)*8+TAB_PADDING, h=TAB_HEIGHT;
166
	y -= h;
4410 leency 167
 
6212 leency 168
	if (but_id==active_tab)
4410 leency 169
	{
5674 pavelyakov 170
		col_bg=system.color.work_button;
171
		col_text=system.color.work_button_text;
4410 leency 172
	}
173
	else
174
	{
5674 pavelyakov 175
		col_bg=system.color.work;
176
		col_text=system.color.work_text;
4410 leency 177
	}
6048 leency 178
	DrawCaptButton(x,y, w-1,h+1, but_id, col_bg, col_text, text);
6212 leency 179
	_PutImage(x+10,h-16/2+y+1,  16,15,   but_id-2*16*15*3+#icons);
4410 leency 180
}
181
 
6212 leency 182
void DrawScroller()
183
{
6253 leency 184
	scroll1.bckg_col = MixColors(system.color.work, 0xBBBbbb, 80);
185
	scroll1.frnt_col = MixColors(system.color.work,0xFFFfff,120);
6212 leency 186
	scroll1.line_col = system.color.work_graph;
4410 leency 187
 
6212 leency 188
	scroll1.max_area = list.count;
189
	scroll1.cur_area = list.visible;
190
	scroll1.position = list.first;
191
 
192
	scroll1.all_redraw=1;
193
	scroll1.start_x = list.x + list.w;
194
	scroll1.start_y = list.y-1;
195
	scroll1.size_y = list.h+2;
196
 
197
	scrollbar_v_draw(#scroll1);
4078 leency 198
}
199
 
6212 leency 200
void Open_Dir()
4078 leency 201
{
6212 leency 202
	int j;
203
	list.count = 0;
204
	if(io.dir.buffer)free(io.dir.buffer);
205
	io.dir.load(#folder_path,DIR_ONLYREAL);
206
	for (j=0; j
4410 leency 207
	{
6212 leency 208
		strcpy(#temp_filename, io.dir.position(j));
209
		strlwr(#temp_filename);
210
		if (active_tab==SKINS) if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".skn")!=0) continue;
211
		if (active_tab==WALLPAPERS) if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".txt")==0) continue;
212
		cur = list.count;
213
		files_mas[cur]=j;
214
		if (!strcmpi("default.skn",#temp_filename)) files_mas[0]>
215
		list.count++;
4410 leency 216
	}
6212 leency 217
}
218
 
219
void Draw_List()
220
{
221
	int i, yyy, list_last;
222
 
223
	if (list.count > list.visible) list_last = list.visible; else list_last = list.count;
224
 
225
	for (i=0; (i
4410 leency 226
	{
6212 leency 227
		cur = list.first + i;
228
		strcpy(#temp_filename, io.dir.position(files_mas[cur]));
229
		temp_filename[strlen(#temp_filename)-4] = 0;
230
		yyy = i*list.item_h+list.y;
231
 
232
		if (list.cur_y-list.first==i)
233
		{
234
			DrawBar(list.x, yyy, list.w, list.item_h, system.color.work_button);
235
			WriteText(list.x+12,yyy+list.text_y,list.font_type,system.color.work_button_text, #temp_filename);
236
		}
237
		else
238
		{
239
			DrawBar(list.x,yyy,list.w, list.item_h, 0xFFFfff);
240
			WriteText(list.x+12,yyy+list.text_y,list.font_type,0, #temp_filename);
241
		}
4410 leency 242
	}
6212 leency 243
	DrawBar(list.x,i*list.item_h+list.y, list.w, -i*list.item_h+ list.h, 0xFFFfff);
244
	DrawScroller();
4078 leency 245
}
246
 
6212 leency 247
//===================================================//
248
//                                                   //
249
//                     EVENTS                        //
250
//                                                   //
251
//===================================================//
4078 leency 252
 
6212 leency 253
void EventTabClick(int N)
4085 leency 254
{
6212 leency 255
	active_tab = N;
256
	if (active_tab == SKINS)
257
	{
258
		active_wallpaper = list.cur_y;
259
		strcpy(#folder_path, SKINS_STANDART_PATH);
260
		list.ClearList();
261
		Open_Dir();
262
		if (!list.count) notify("'No skins were found' -E");
263
		list.cur_y = active_skin;
264
	}
265
	if (active_tab == WALLPAPERS)
266
	{
267
		active_skin = list.cur_y;
268
		strcpy(#folder_path, WALP_STANDART_PATH);
269
		list.ClearList();
270
		Open_Dir();
271
		if (!list.count) notify("'No wallpapers were found' -E");
272
		list.cur_y = active_wallpaper;
273
	}
274
	if (list.w) DrawWindowContent();
275
}
4078 leency 276
 
6212 leency 277
void EventDeleteFile()
278
{
279
	io.del(#cur_file_path);
280
	Open_Dir();
281
	EventApply();
282
}
4078 leency 283
 
6212 leency 284
void EventApply()
285
{
286
	if (active_tab==SKINS)
287
	{
288
		cur = list.cur_y;
289
		sprintf(#cur_file_path,"%s/%s",#folder_path,io.dir.position(files_mas[cur]));
290
		SetSystemSkin(#cur_file_path);
291
	}
292
	if (active_tab==WALLPAPERS)
293
	{
294
		cur = list.cur_y;
295
		sprintf(#cur_file_path,"\\S__%s/%s",#folder_path,io.dir.position(files_mas[cur]));
296
		RunProgram("/sys/media/kiv", #cur_file_path);
297
		Draw_List();
298
	}
299
}
4085 leency 300
 
6212 leency 301
void EventOpenFile()
302
{
303
	if (active_tab==SKINS) RunProgram("/sys/skincfg", #cur_file_path);
304
	if (active_tab==WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
4085 leency 305
}
306
 
4078 leency 307
stop: