Subversion Repositories Kolibri OS

Rev

Rev 7611 | Rev 7613 | 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!
7594 leency 2
//ver 2.3
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"
5499 leency 13
#include "..\lib\gui.h"
7353 leency 14
 
5499 leency 15
#include "..\lib\obj\box_lib.h"
7353 leency 16
#include "..\lib\obj\proc_lib.h"
7594 leency 17
#include "..\lib\obj\libini.h"
7353 leency 18
 
6651 leency 19
#include "..\lib\patterns\select_list.h"
7353 leency 20
#include "..\lib\patterns\simple_open_dialog.h"
4078 leency 21
 
6212 leency 22
//===================================================//
23
//                                                   //
24
//                       DATA                        //
25
//                                                   //
26
//===================================================//
27
 
4085 leency 28
#ifdef LANG_RUS
6212 leency 29
	?define WINDOW_HEADER "Настройки оформления"
6264 leency 30
	?define T_SKINS       "Стиль окон"
31
	?define T_WALLPAPERS  "Обои"
7353 leency 32
	?define T_SELECT_FOLDER "Выбрать папку"
7447 leency 33
	?define MENU_LIST "Открыть файл   Enter\nУдалить файл     Del"
7611 leency 34
	?define T_PICTURE_MODE " Положение картинки "
35
	?define T_CHECKBOX_STRETCH "Растянуть"
36
	?define T_CHECKBOX_TILED "Замостить"
7612 leency 37
	?define T_UPDATE_DOCK "Обновлять Dock-панель"
4085 leency 38
#else
39
	?define WINDOW_HEADER "Appearance"
6264 leency 40
	?define T_SKINS       "Skins"
7353 leency 41
	?define T_WALLPAPERS  "Wallpapers"
7611 leency 42
	?define T_SELECT_FOLDER "Select folder"
7447 leency 43
	?define MENU_LIST "Open file      Enter\nDelete file      Del"
7611 leency 44
	?define T_PICTURE_MODE " Picture Mode "
45
	?define T_CHECKBOX_STRETCH "Stretch"
46
	?define T_CHECKBOX_TILED "Tiled"
7612 leency 47
	?define T_UPDATE_DOCK "Update Dock"
4085 leency 48
#endif
4078 leency 49
 
6212 leency 50
#define PANEL_H 40
7225 leency 51
#define LP 10 //LIST_PADDING
7594 leency 52
char skins_folder_path[4096];
53
char wallp_folder_path[4096];
4078 leency 54
 
6264 leency 55
signed int active_skin=-1, active_wallpaper=-1;
7353 leency 56
enum {
57
	SKINS=2,
58
	WALLPAPERS,
59
	BTN_SELECT_WALLP_FOLDER };
4078 leency 60
 
61
char folder_path[4096];
62
char cur_file_path[4096];
7551 leency 63
char cur_skin_path[4096];
4078 leency 64
char temp_filename[4096];
6096 leency 65
int files_mas[400];
4078 leency 66
 
67
int cur;
68
 
69
proc_info Form;
7244 leency 70
block skp;
4078 leency 71
 
7225 leency 72
_tabs tabs = { LP, LP, NULL, NULL, SKINS };
73
 
7612 leency 74
checkbox update_docky = { T_UPDATE_DOCK, false };
7244 leency 75
checkbox checkbox1 = { "Checkbox", true };
7252 leency 76
more_less_box spinbox1 = { 23, 0, 999, "SpinBox" };
7254 leency 77
edit_box edit_cmm = {180,NULL,NULL,0xffffff,0x94AECE,0xFFFfff,0xffffff,
7506 leency 78
	0x10000000,sizeof(param)-2,#param,0, 0b};
7244 leency 79
 
7254 leency 80
char st_str[16];
81
edit_box edit_st = {180,NULL,NULL,0xffffff,0x94AECE,0xFFFfff,0xffffff,
7506 leency 82
	0x10000000,sizeof(st_str)-2,#st_str,0, 0b};
7254 leency 83
 
7353 leency 84
char default_dir[] = "/rd/1";
85
od_filter filter2 = { 8, "TXT\0\0" };
86
 
7611 leency 87
checkbox optionbox_stretch = { T_CHECKBOX_STRETCH, true };
88
checkbox optionbox_tiled = { T_CHECKBOX_TILED, false };
89
 
6212 leency 90
//===================================================//
91
//                                                   //
92
//                       CODE                        //
93
//                                                   //
94
//===================================================//
5548 leency 95
 
7594 leency 96
void GetRealFolderPathes()
97
{
98
	char real_skin_path[4096];
99
	SetCurDir("/kolibrios");
100
	GetCurDir(#real_skin_path, sizeof(real_skin_path));
101
	sprintf(#skins_folder_path, "%s/res/skins", #real_skin_path);
102
	sprintf(#wallp_folder_path, "%s/res/wallpapers", #real_skin_path);
103
}
104
 
4078 leency 105
void main()
106
{
5705 punk_joker 107
	int id, mouse_clicked;
4078 leency 108
 
7594 leency 109
	GetRealFolderPathes();
110
 
5626 leency 111
	load_dll(boxlib, #box_lib_init,0);
7533 leency 112
	load_dll(libini, #lib_init,1);
7353 leency 113
	load_dll(Proc_lib, #OpenDialog_init,0);
114
	o_dialog.type = 2; //select folder
115
	OpenDialog_init stdcall (#o_dialog);
116
 
6212 leency 117
	EventTabClick(SKINS);
7353 leency 118
 
7551 leency 119
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
6096 leency 120
	loop() switch(WaitEvent())
4078 leency 121
	{
122
	  	case evMouse:
4085 leency 123
			if (!CheckActiveProcess(Form.ID)) break;
6653 leency 124
			SelectList_ProcessMouse();
4410 leency 125
 
7353 leency 126
			if (tabs.active_tab == SKINS) {
127
				edit_box_mouse stdcall (#edit_cmm);
128
				edit_box_mouse stdcall (#edit_st);
129
			}
130
 
7244 leency 131
	  		if (mouse.pkm)&&(select_list.MouseOver(mouse.x, mouse.y)) {
6651 leency 132
	  			select_list.ProcessMouse(mouse.x, mouse.y);
6653 leency 133
				SelectList_Draw();
7353 leency 134
				EventSetNewCurrent();
7447 leency 135
	  			menu.show(Form.left+mouse.x, Form.top+mouse.y+skin_height, 146, MENU_LIST, 10);
6212 leency 136
	  		}
4078 leency 137
	  		break;
138
 
139
		case evButton:
140
			id=GetButtonID();
7551 leency 141
			if (id==1) EventExit();
6212 leency 142
			if (id==SKINS) EventTabClick(SKINS);
143
			if (id==WALLPAPERS) EventTabClick(WALLPAPERS);
7353 leency 144
			if (id==BTN_SELECT_WALLP_FOLDER) EventSelectWallpFolder();
7244 leency 145
			checkbox1.click(id);
7252 leency 146
			spinbox1.click(id);
7612 leency 147
			if (update_docky.click(id)) EventUpdateDocky();
7611 leency 148
			if (!optionbox_stretch.checked) && (optionbox_stretch.click(id)) EventSetWallpMode_Stretch();
149
			if (!optionbox_tiled.checked) && (optionbox_tiled.click(id)) EventSetWallpMode_Tiled();
4078 leency 150
			break;
151
 
152
		case evKey:
5706 leency 153
			GetKeys();
6651 leency 154
			if (select_list.ProcessKey(key_scancode)) EventApply();
6212 leency 155
			if (key_scancode==SCAN_CODE_ENTER) EventOpenFile();
7353 leency 156
			if (key_scancode==SCAN_CODE_TAB) {
7225 leency 157
				if (tabs.active_tab==SKINS) EventTabClick(WALLPAPERS);
7353 leency 158
				else EventTabClick(SKINS);
159
			}
6212 leency 160
			if (key_scancode==SCAN_CODE_DEL) EventDeleteFile();
7349 leency 161
 
7506 leency 162
			if (! edit_cmm.flags & ed_focus) && (! edit_st.flags & ed_focus)
6651 leency 163
			for (id=select_list.cur_y+1; id
4078 leency 164
			{
6212 leency 165
				strcpy(#temp_filename, io.dir.position(files_mas[id]));
166
				if (temp_filename[0]==key_ascii) || (temp_filename[0]==key_ascii-32)
167
				{
6651 leency 168
					select_list.cur_y = id - 1;
169
					select_list.KeyDown();
6212 leency 170
					EventApply();
171
					break;
172
				}
4078 leency 173
			}
7349 leency 174
 
7353 leency 175
			if (tabs.active_tab == SKINS) {
176
				EAX = key_ascii << 8;
177
				edit_box_key stdcall (#edit_cmm);
178
				edit_box_key stdcall (#edit_st);
179
			}
4078 leency 180
			break;
181
 
7353 leency 182
		 case evReDraw:
183
			draw_window();
7450 leency 184
	 		if (menu.cur_y) {
185
				if (menu.cur_y == 10) EventOpenFile();
186
				if (menu.cur_y == 11) EventDeleteFile();
187
				menu.cur_y = 0;
6212 leency 188
			};
4078 leency 189
   }
190
}
191
 
7353 leency 192
void draw_window()
193
{
7612 leency 194
	DefineAndDrawWindow(screen.width-600/2,80,630,504+skin_height,0x74,NULL,WINDOW_HEADER,0);
7353 leency 195
	GetProcessInfo(#Form, SelfInfo);
196
	IF (Form.status_window>=2) return;
197
	DrawWindowContent();
198
}
7244 leency 199
 
6212 leency 200
void DrawWindowContent()
201
{
202
	int id;
7252 leency 203
	incn y;
7353 leency 204
	int list_w;
7225 leency 205
 
7612 leency 206
	system.color.get();
207
 
7611 leency 208
	if (tabs.active_tab == SKINS) list_w=250; else list_w=350;
7353 leency 209
 
7225 leency 210
	DrawWideRectangle(0, 0, Form.cwidth, Form.cheight, LP, system.color.work);
211
 
212
	tabs.w = Form.cwidth-LP-LP;
213
	tabs.h = Form.cheight-LP-LP;
214
	tabs.draw_wrapper();
215
 
7226 leency 216
	tabs.draw_button(tabs.x+TAB_PADDING, SKINS, T_SKINS);
217
	tabs.draw_button(strlen(T_SKINS)*8+tabs.x+TAB_PADDING+TAB_PADDING, WALLPAPERS, T_WALLPAPERS);
7225 leency 218
 
6651 leency 219
	id = select_list.cur_y;
6653 leency 220
	SelectList_Init(
7225 leency 221
		tabs.x+TAB_PADDING,
222
		tabs.y+TAB_HEIGHT+TAB_PADDING,
7353 leency 223
		list_w,
7225 leency 224
		tabs.h - TAB_PADDING - TAB_PADDING - TAB_HEIGHT,
6653 leency 225
		false
226
		);
6651 leency 227
	select_list.cur_y = id;
7244 leency 228
 
229
	skp.set_size(
7252 leency 230
		select_list.x + select_list.w + TAB_PADDING + scroll1.size_x + 20,
7612 leency 231
		select_list.y + 30 + 50,
7353 leency 232
		list_w,
7612 leency 233
		230 //select_list.h - 50 - 50
7244 leency 234
	);
235
 
6653 leency 236
	SelectList_Draw();
6662 leency 237
	SelectList_DrawBorder();
7244 leency 238
 
239
	if (tabs.active_tab == SKINS)
240
	{
7252 leency 241
		DrawBar(skp.x-20, select_list.y, skp.w+40, select_list.h, system.color.work);
242
		DrawRectangle(skp.x-20, select_list.y, skp.w+40, select_list.h, system.color.work_graph);
7612 leency 243
		update_docky.draw(skp.x, select_list.y+15);
7252 leency 244
		y.n = skp.y;
7244 leency 245
		DrawFrame(skp.x, skp.y, skp.w, skp.h, " Components Preview ");
7252 leency 246
		spinbox1.draw(skp.x+20, y.inc(30));
7254 leency 247
		WriteText(skp.x+20, y.inc(30), 0x90, system.color.work_text, "C-- Edit");
248
		DrawEditBoxPos(skp.x+20, y.inc(20), #edit_cmm);
249
		WriteText(skp.x+20, y.inc(35), 0x90, system.color.work_text, "Strandard Edit");
250
		DrawStEditBoxPos(skp.x+20, y.inc(20), #edit_st);
7252 leency 251
		DrawStandartCaptButton(skp.x+20, skp.y+skp.h-40, GetFreeButtonId(), "Button1");
252
		DrawStandartCaptButton(skp.x+120, skp.y+skp.h-40, GetFreeButtonId(), "Button2");
7244 leency 253
	}
7353 leency 254
	if (tabs.active_tab == WALLPAPERS)
255
	{
7611 leency 256
		skp.x -= TAB_PADDING + 3;
257
		DrawStandartCaptButton(skp.x, select_list.y, BTN_SELECT_WALLP_FOLDER, T_SELECT_FOLDER);
258
		DrawBar(skp.x, select_list.y+50, 180, 80, system.color.work);
259
		DrawFrame(skp.x, select_list.y+50, 180, 80, T_PICTURE_MODE);
260
		optionbox_stretch.draw(skp.x+14, select_list.y+70);
261
		optionbox_tiled.draw(skp.x+14, select_list.y+97);
7353 leency 262
	}
6212 leency 263
}
264
 
7254 leency 265
:void DrawStEditBoxPos(dword x,y, edit_box_pointer)
266
{
267
	dword c_inactive = MixColors(system.color.work_graph, system.color.work, 128);
268
	dword c_active = MixColors(system.color.work_graph, 0, 128);
269
	ESI = edit_box_pointer;
270
	ESI.edit_box.left = x;
271
	ESI.edit_box.top = y;
272
	ESI.edit_box.blur_border_color = c_inactive;
273
	ESI.edit_box.focus_border_color = c_active;
274
	edit_box_draw  stdcall (edit_box_pointer);
275
}
4410 leency 276
 
6212 leency 277
 
7254 leency 278
 
6212 leency 279
void Open_Dir()
4078 leency 280
{
6212 leency 281
	int j;
6651 leency 282
	select_list.count = 0;
6212 leency 283
	if(io.dir.buffer)free(io.dir.buffer);
284
	io.dir.load(#folder_path,DIR_ONLYREAL);
285
	for (j=0; j
4410 leency 286
	{
6212 leency 287
		strcpy(#temp_filename, io.dir.position(j));
288
		strlwr(#temp_filename);
7353 leency 289
		if (tabs.active_tab==SKINS) {
290
			if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".skn")!=0) continue;
291
		}
292
		if (tabs.active_tab==WALLPAPERS) {
293
			if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".png")!=0)
294
			&& (strcmpi(#temp_filename+strlen(#temp_filename)-4,".jpg")!=0)
295
			&& (strcmpi(#temp_filename+strlen(#temp_filename)-5,".jpeg")!=0)
296
			&& (strcmpi(#temp_filename+strlen(#temp_filename)-4,".gif")!=0) continue;
297
		}
6651 leency 298
		cur = select_list.count;
6212 leency 299
		files_mas[cur]=j;
6651 leency 300
		if (!strcmpi("default.skn",#temp_filename)) files_mas[0]>
301
		select_list.count++;
4410 leency 302
	}
6212 leency 303
}
304
 
6653 leency 305
void SelectList_DrawLine(dword i)
6212 leency 306
{
6651 leency 307
	int yyy, list_last;
6212 leency 308
 
6651 leency 309
	cur = select_list.first + i;
310
	strcpy(#temp_filename, io.dir.position(files_mas[cur]));
311
	temp_filename[strlen(#temp_filename)-4] = 0;
312
	yyy = i*select_list.item_h+select_list.y;
313
 
314
	if (select_list.cur_y-select_list.first==i)
4410 leency 315
	{
6651 leency 316
		DrawBar(select_list.x, yyy, select_list.w, select_list.item_h, system.color.work_button);
317
		WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,system.color.work_button_text, #temp_filename);
4410 leency 318
	}
6651 leency 319
	else
320
	{
321
		DrawBar(select_list.x,yyy,select_list.w, select_list.item_h, 0xFFFfff);
322
		WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,0, #temp_filename);
323
	}
4078 leency 324
}
325
 
6653 leency 326
void SelectList_LineChanged()
327
{
328
	EventApply();
329
}
330
 
6212 leency 331
//===================================================//
332
//                                                   //
333
//                     EVENTS                        //
334
//                                                   //
335
//===================================================//
4078 leency 336
 
6212 leency 337
void EventTabClick(int N)
4085 leency 338
{
6264 leency 339
	tabs.click(N);
340
	if (tabs.active_tab == SKINS)
6212 leency 341
	{
6651 leency 342
		active_wallpaper = select_list.cur_y;
7353 leency 343
		strcpy(#folder_path, #skins_folder_path);
6651 leency 344
		select_list.ClearList();
6212 leency 345
		Open_Dir();
6651 leency 346
		if (!select_list.count) notify("'No skins were found' -E");
347
		select_list.cur_y = active_skin;
6212 leency 348
	}
6264 leency 349
	if (tabs.active_tab == WALLPAPERS)
6212 leency 350
	{
6651 leency 351
		active_skin = select_list.cur_y;
7353 leency 352
		strcpy(#folder_path, #wallp_folder_path);
6651 leency 353
		select_list.ClearList();
6212 leency 354
		Open_Dir();
6651 leency 355
		if (!select_list.count) notify("'No wallpapers were found' -E");
356
		select_list.cur_y = active_wallpaper;
6212 leency 357
	}
6651 leency 358
	if (select_list.cur_y>select_list.visible) select_list.first=select_list.cur_y; select_list.CheckDoesValuesOkey();
359
	if (select_list.w) DrawWindowContent();
6212 leency 360
}
4078 leency 361
 
6212 leency 362
void EventDeleteFile()
363
{
364
	io.del(#cur_file_path);
365
	Open_Dir();
366
	EventApply();
367
}
4078 leency 368
 
7353 leency 369
void EventSetNewCurrent()
370
{
371
	cur = select_list.cur_y;
372
	sprintf(#cur_file_path,"%s/%s",#folder_path,io.dir.position(files_mas[cur]));
373
}
374
 
375
void EventSelectWallpFolder()
376
{
377
	OpenDialog_start stdcall (#o_dialog);
378
	if (o_dialog.status) {
379
		strcpy(#wallp_folder_path, #opendir_path);
380
		EventTabClick(WALLPAPERS);
381
	}
382
}
383
 
7611 leency 384
void EventSetWallpMode_Stretch()
385
{
386
	optionbox_tiled.checked = false;
387
	optionbox_tiled.redraw();
388
	EventApply();
389
}
390
 
391
void EventSetWallpMode_Tiled()
392
{
393
	optionbox_stretch.checked = false;
394
	optionbox_stretch.redraw();
395
	EventApply();
396
}
397
 
7612 leency 398
#include "..\lib\patterns\restart_process.h"
6212 leency 399
void EventApply()
400
{
7353 leency 401
	char kivpath[4096+10];
402
	EventSetNewCurrent();
6264 leency 403
	if (tabs.active_tab==SKINS)
6212 leency 404
	{
6651 leency 405
		cur = select_list.cur_y;
6212 leency 406
		SetSystemSkin(#cur_file_path);
7612 leency 407
		SelectList_Draw();
7551 leency 408
		strcpy(#cur_skin_path, #cur_file_path);
7612 leency 409
		EventUpdateDocky();
6212 leency 410
	}
6264 leency 411
	if (tabs.active_tab==WALLPAPERS)
6212 leency 412
	{
7551 leency 413
		SelectList_Draw();
7611 leency 414
		if (optionbox_stretch.checked) strcpy(#kivpath, "\\S__");
415
		if (optionbox_tiled.checked) strcpy(#kivpath, "\\T__");
7353 leency 416
		strcat(#kivpath, #cur_file_path);
417
		RunProgram("/sys/media/kiv", #kivpath);
6212 leency 418
	}
419
}
4085 leency 420
 
7612 leency 421
void EventUpdateDocky()
422
{
423
	if (!update_docky.checked) return;
424
	KillProcessByName("@docky", MULTIPLE);
425
	RunProgram("/sys/@docky",NULL);
426
	pause(50);
427
	ActivateWindow(GetProcessSlot(Form.ID));
428
}
429
 
6212 leency 430
void EventOpenFile()
431
{
6264 leency 432
	if (tabs.active_tab==SKINS) RunProgram("/sys/skincfg", #cur_file_path);
433
	if (tabs.active_tab==WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
4085 leency 434
}
435
 
7594 leency 436
_ini ini = { "/sys/settings/eskin.ini", "main" };
7551 leency 437
void EventExit()
438
{
7594 leency 439
	ini.SetString("skin", #cur_skin_path, strlen(#cur_skin_path));
7551 leency 440
	ExitProcess();
441
}
442
 
4078 leency 443
stop: