Subversion Repositories Kolibri OS

Rev

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