Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
4870 leency 1
/*
5406 leency 2
SOFTWARE CENTER v2.2
4870 leency 3
*/
4
 
5
#define MEMSIZE 0x3E80
6
#include "..\lib\kolibri.h"
7
#include "..\lib\strings.h"
8
#include "..\lib\mem.h"
9
#include "..\lib\file_system.h"
10
#include "..\lib\dll.h"
11
#include "..\lib\figures.h"
12
#include "..\lib\lib.obj\libio_lib.h"
13
#include "..\lib\lib.obj\libimg_lib.h"
5151 leency 14
#include "..\lib\lib.obj\libini.h"
4870 leency 15
 
5405 leency 16
 
4870 leency 17
system_colors sc;
18
proc_info Form;
5403 leency 19
mouse m;
4870 leency 20
 
5405 leency 21
int item_id_need_to_run=-1,
22
    current_item_id;
5403 leency 23
 
5405 leency 24
int window_width,
25
    window_height;
5403 leency 26
 
5405 leency 27
int col_max,
28
    cell_w,
29
    cell_h,
30
    list_pos,
31
    list_top,
32
    row,
33
    col,
34
    default_icon;
5403 leency 35
 
5405 leency 36
char window_title[128],
37
     settings_ini_path[256] = "/sys/settings/";
38
 
5403 leency 39
#define LIST_BACKGROUND_COLOR 0xF3F3F3
40
 
41
 
42
 
5405 leency 43
 
4870 leency 44
struct struct_skin {
45
	dword image, w, h;
5403 leency 46
	int load();
4870 leency 47
} skin;
48
 
5403 leency 49
 
50
int struct_skin::load()
4870 leency 51
{
5403 leency 52
	int i, max_i;
4870 leency 53
	dword image_data;
54
	skin.image = load_image("/sys/iconstrp.png");
55
	if (!skin.image) notify("'iconstrp.png not found' -E");
5403 leency 56
	skin.w = DSWORD[skin.image + 4];
57
	skin.h = DSWORD[skin.image + 8];
58
	image_data = DSDWORD[skin.image + 24];
4870 leency 59
	sc.get();
5403 leency 60
	max_i = w * h * 4 + image_data;
61
	for (i = image_data; i < max_i; i += 4)	if (DSDWORD[i]==0) DSDWORD[i] = LIST_BACKGROUND_COLOR;
62
}
4870 leency 63
 
5403 leency 64
void load_config()
65
{
66
	ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget");
67
	ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690);
68
	window_width = EAX;
69
	ini_get_int stdcall (#settings_ini_path, "Config", "window_height", 540);
70
	window_height = EAX;
5404 leency 71
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 66);
72
	cell_w = EAX;
73
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 64);
74
	cell_h = EAX;
5405 leency 75
	ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0);
76
	default_icon = EAX;
4870 leency 77
}
78
 
79
 
80
void main()
81
{
82
	int id, key;
83
	mem_Init();
5403 leency 84
	if (load_dll2(libio,  #libio_init,1)!=0) notify("Error: library doesn't exists - libio");
4870 leency 85
	if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg");
5151 leency 86
	if (load_dll2(libini, #lib_init,1)!=0) notify("Error: library doesn't exists - libini");
5403 leency 87
	skin.load();
88
 
5406 leency 89
	if (#param)
90
	{
91
		strcpy(#settings_ini_path, #param);
92
	}
93
	else
94
	{
95
		strcat(#settings_ini_path, #program_path + strrchr(#program_path, '/'));
96
		strcat(#settings_ini_path, ".ini");
97
	}
5403 leency 98
	load_config();
99
 
4870 leency 100
	loop()
5403 leency 101
	{
4870 leency 102
      switch(WaitEvent())
103
      {
104
         case evButton:
105
            id=GetButtonID();
106
            if (id==1) ExitProcess();
5151 leency 107
            if (id>=100)
108
            {
5403 leency 109
            	item_id_need_to_run = id - 100;
110
            	current_item_id = 0;
111
            	ini_enum_sections stdcall (#settings_ini_path, #draw_section);
5404 leency 112
            	item_id_need_to_run = -1;
5151 leency 113
            }
4870 leency 114
			break;
5403 leency 115
 
4870 leency 116
         case evReDraw:
117
			sc.get();
5406 leency 118
			DefineAndDrawWindow(GetScreenWidth()-window_width/2,GetScreenHeight()-window_height/2,window_width,window_height,0x74,sc.work,"");
4870 leency 119
			GetProcessInfo(#Form, SelfInfo);
5406 leency 120
			if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle("");
5404 leency 121
			col_max = Form.cwidth - 10 / cell_w;
5403 leency 122
			current_item_id = 0;
123
			draw_top_bar();
124
			ini_enum_sections stdcall (#settings_ini_path, #draw_section);
5404 leency 125
			DrawBar(0, row + 1 * cell_h + list_pos, Form.cwidth, -row - 1 * cell_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR);
4870 leency 126
			break;
127
      }
5403 leency 128
	}
4870 leency 129
}
130
 
5403 leency 131
byte search_for_id_need_to_run(dword key_value, key_name, sec_name, f_name)
5151 leency 132
{
5404 leency 133
	int icon_char_pos;
5403 leency 134
	if (item_id_need_to_run == current_item_id)
5151 leency 135
	{
5404 leency 136
		icon_char_pos = strchr(key_value, ',');
137
		if (icon_char_pos) ESBYTE[key_value + icon_char_pos - 1] = 0; //delete icon from string
5403 leency 138
		RunProgram(key_value, "");
5151 leency 139
	}
5403 leency 140
	current_item_id++;
5151 leency 141
	return 1;
142
}
4870 leency 143
 
5151 leency 144
 
5403 leency 145
byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
5151 leency 146
{
5405 leency 147
	int tmp,
148
	    icon_id,
149
	    icon_char_pos;
5151 leency 150
 
151
	if (col==col_max) {
152
		row++;
153
		col=0;
154
	}
5404 leency 155
	if (col==0) DrawBar(0, row * cell_h + list_pos, Form.cwidth, cell_h, LIST_BACKGROUND_COLOR);
156
	DefineButton(col*cell_w+6,row*cell_h + list_pos,cell_w,cell_h-5,current_item_id + 100 + BT_HIDE,0);
157
	tmp = cell_w/2;
5405 leency 158
 
159
	icon_char_pos = strchr(key_value, ',');
160
	if (icon_char_pos) icon_id = atoi(key_value + icon_char_pos); else icon_id = default_icon;
5404 leency 161
	img_draw stdcall(skin.image, col*cell_w+tmp-10, row*cell_h+5 + list_pos, 32, 32, 0, icon_id*32);
5405 leency 162
	WriteTextCenter(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0xDCDCDC,key_name);
5404 leency 163
	WriteTextCenter(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0x000000,key_name);
5403 leency 164
	current_item_id++;
5151 leency 165
	col++;
166
	return 1;
167
}
168
 
5403 leency 169
 
170
byte draw_section(dword sec_name, f_name)
4870 leency 171
{
5403 leency 172
	if (strcmp(sec_name, "Config")==0) return 1;
4870 leency 173
 
5404 leency 174
	if (item_id_need_to_run!=-1)
5403 leency 175
	{
176
		ini_enum_keys stdcall (f_name, sec_name, #search_for_id_need_to_run);
177
	}
178
	else
179
	{
180
		row++;
181
		col = 0;
5404 leency 182
		DrawBar(0, row * cell_h + list_pos, Form.cwidth , 20, LIST_BACKGROUND_COLOR);
183
		WriteTextB(10, row * cell_h + 9 + list_pos, 0x90, 0x000000, sec_name);
5403 leency 184
		list_pos += 20;
185
		ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
186
	}
187
	return 1;
4870 leency 188
}
189
 
5403 leency 190
void draw_top_bar()
191
{
192
	int top_position = 25;
193
	DrawBar(0,0,Form.cwidth, top_position-1, sc.work);
194
	DrawBar(0,top_position-1, Form.cwidth, 1, sc.work_graph);
195
	WriteTextB(Form.cwidth/2-70, 9, 0x90, sc.work_text, #window_title);
196
	list_top = top_position;
197
	list_pos = list_top;
198
	row = -1;
199
}
4870 leency 200
 
201
 
5403 leency 202
 
4870 leency 203
stop: