Subversion Repositories Kolibri OS

Rev

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

Rev 8457 Rev 8490
1
//===================================================//
1
//===================================================//
2
//                                                   //
2
//                                                   //
3
//                      MODULE                       //
3
//                      MODULE                       //
4
//                                                   //
4
//                                                   //
5
//===================================================//
5
//===================================================//
6
 
6
 
7
#define TABS_MAX 5
7
#define TABS_MAX 5
8
 
8
 
9
TWebBrowser data[TABS_MAX+1]=0;
9
TWebBrowser tabdata[TABS_MAX+1]=0;
10
_history tabstory[TABS_MAX+1]=0;
10
_history tabstory[TABS_MAX+1]=0;
11
 
11
 
12
struct TAB
12
struct TAB
13
{
13
{
14
	int count;
14
	int count;
15
	signed int active;
15
	signed int active;
16
	bool add();
16
	bool add();
17
	bool close();
17
	bool close();
18
	void save_state();
18
	void save_state();
19
	void restore();
19
	void restore();
20
} tab = {1,0};
20
} tab = {1,0};
21
 
21
 
22
 
22
 
23
bool TAB::add()
23
bool TAB::add()
24
{
24
{
25
	if (count==TABS_MAX) return false;
25
	if (count==TABS_MAX) return false;
26
	save_state();
26
	save_state();
27
	count++;
27
	count++;
28
	active = count-1;
28
	active = count-1;
29
	history = tabstory[active];
29
	history = tabstory[active];
30
	return true;
30
	return true;
31
}
31
}
32
 
32
 
33
bool TAB::close(int _tab_number)
33
bool TAB::close(int _tab_number)
34
{
34
{
35
	int i;
35
	int i;
36
	if (count==1) return false;
36
	if (count==1) return false;
37
	for (i=_tab_number; i
37
	for (i=_tab_number; i
38
		data[i] = data[i+1];
38
		tabdata[i] = tabdata[i+1];
39
		tabstory[i] = tabstory[i+1];
39
		tabstory[i] = tabstory[i+1];
40
	}
40
	}
41
	if (_tab_number0) active--;
41
	if (_tab_number0) active--;
42
	if (active==count-1) && (active>0) active--;
42
	if (active==count-1) && (active>0) active--;
43
	count--;
43
	count--;
44
	return true;
44
	return true;
45
}
45
}
46
 
46
 
47
void TAB::save_state()
47
void TAB::save_state()
48
{
48
{
49
	tabstory[active] = history;
49
	tabstory[active] = history;
50
	data[active] = WB1;
50
	tabdata[active] = WB1;
51
}
51
}
52
 
52
 
53
void TAB::restore(int _id)
53
void TAB::restore(int _id)
54
{
54
{
55
	tab.active = _id;
55
	tab.active = _id;
56
	WB1 = data[_id];	
56
	WB1 = tabdata[_id];	
57
	history = tabstory[_id];
57
	history = tabstory[_id];
58
}
58
}
59
 
59
 
60
//===================================================//
60
//===================================================//
61
//                                                   //
61
//                                                   //
62
//                 WebView Actions                   //
62
//                 WebView Actions                   //
63
//                                                   //
63
//                                                   //
64
//===================================================//
64
//===================================================//
65
 
65
 
66
#define DEFAULT_TABW 220
66
#define DEFAULT_TABW 220
67
int tab_w = DEFAULT_TABW;
67
int tab_w = DEFAULT_TABW;
68
 
68
 
69
int GetTabWidth()
69
int GetTabWidth()
70
{
70
{
71
	if (tab.count == TABS_MAX) return Form.cwidth / tab.count;
71
	if (tab.count == TABS_MAX) return Form.cwidth / tab.count;
72
	if (tab.count * DEFAULT_TABW + TAB_H < Form.cwidth) return DEFAULT_TABW; else 
72
	if (tab.count * DEFAULT_TABW + TAB_H < Form.cwidth) return DEFAULT_TABW; else 
73
	return Form.cwidth - TAB_H - 2 / tab.count;
73
	return Form.cwidth - TAB_H - 2 / tab.count;
74
}
74
}
75
 
75
 
76
void DrawTab(int _id)
76
void DrawTab(int _id)
77
{
77
{
78
	#define CLOSE_S 13
78
	#define CLOSE_S 13
79
	dword bgcol, border_bottom_color;
79
	dword bgcol, border_bottom_color;
80
	char header_no_version[sizeof(TWebBrowser.header)];
80
	char header_no_version[sizeof(TWebBrowser.header)];
81
	char name[DEFAULT_TABW/6];
81
	char name[DEFAULT_TABW/6];
82
	int xxx = _id * tab_w;
82
	int xxx = _id * tab_w;
83
 
83
 
84
	if (_id==tab.active) {
84
	if (_id==tab.active) {
85
		tab.save_state();
85
		tab.save_state();
86
		bgcol = sc.work_light; 
86
		bgcol = sc.work_light; 
87
		border_bottom_color = sc.work_light;
87
		border_bottom_color = sc.work_light;
88
	} else {
88
	} else {
89
		bgcol=sc.work;
89
		bgcol=sc.work;
90
		border_bottom_color = sc.work_graph;
90
		border_bottom_color = sc.work_graph;
91
	}
91
	}
92
	if (data[_id].header) {
92
	if (tabdata[_id].header) {
93
		strncpy(#header_no_version, #data[_id].header, strlen(#data[_id].header)-sizeof(version)-2);
93
		strncpy(#header_no_version, #tabdata[_id].header, strlen(#tabdata[_id].header)-sizeof(version)-2);
94
		strncpy(#name, #header_no_version, tab_w-CLOSE_S/6-2);
94
		strncpy(#name, #header_no_version, tab_w-CLOSE_S/6-2);
95
	}
95
	}
96
	DrawBar(xxx, TOOLBAR_H, 1, TAB_H, sc.work_dark);
96
	DrawBar(xxx, TOOLBAR_H, 1, TAB_H, sc.work_dark);
97
	DrawBar(xxx+1, TOOLBAR_H, tab_w-1, TAB_H-1, bgcol);
97
	DrawBar(xxx+1, TOOLBAR_H, tab_w-1, TAB_H-1, bgcol);
98
	DrawBar(xxx+1, TOOLBAR_H+TAB_H-1, tab_w-1, 1, border_bottom_color);
98
	DrawBar(xxx+1, TOOLBAR_H+TAB_H-1, tab_w-1, 1, border_bottom_color);
99
	DefineHiddenButton(xxx, TOOLBAR_H-1, tab_w, TAB_H, TAB_ID+_id);
99
	DefineHiddenButton(xxx, TOOLBAR_H-1, tab_w, TAB_H, TAB_ID+_id);
100
	WriteTextCenter(xxx, TOOLBAR_H+6, tab_w-CLOSE_S, sc.work_text, #name);
100
	WriteTextCenter(xxx, TOOLBAR_H+6, tab_w-CLOSE_S, sc.work_text, #name);
101
 
101
 
102
	DefineHiddenButton(xxx+tab_w-CLOSE_S-3, TOOLBAR_H+3, CLOSE_S-1, CLOSE_S-1, TAB_CLOSE_ID+_id);
102
	DefineHiddenButton(xxx+tab_w-CLOSE_S-3, TOOLBAR_H+3, CLOSE_S-1, CLOSE_S-1, TAB_CLOSE_ID+_id);
103
	DrawBar(xxx+tab_w-CLOSE_S-3, TOOLBAR_H+3, CLOSE_S, CLOSE_S, sc.work_dark);
103
	DrawBar(xxx+tab_w-CLOSE_S-3, TOOLBAR_H+3, CLOSE_S, CLOSE_S, sc.work_dark);
104
	WriteText(xxx+tab_w-CLOSE_S+1, TOOLBAR_H+5, 0x80, sc.work_light, "x");
104
	WriteText(xxx+tab_w-CLOSE_S+1, TOOLBAR_H+5, 0x80, sc.work_light, "x");
105
}
105
}
106
 
106
 
107
void DrawActiveTab()
107
void DrawActiveTab()
108
{
108
{
109
	if (tab_w == GetTabWidth())	DrawTab(tab.active);
109
	if (tab_w == GetTabWidth())	DrawTab(tab.active);
110
	else DrawTabsBar();
110
	else DrawTabsBar();
111
}
111
}
112
 
112
 
113
int DrawNewTabButton()
113
int DrawNewTabButton()
114
{
114
{
115
	dword btn_light = MixColors(sc.button, 0xFFFfff, 220);
115
	dword btn_light = MixColors(sc.button, 0xFFFfff, 220);
116
	dword btn_dark = MixColors(sc.button, 0, 180);
116
	dword btn_dark = MixColors(sc.button, 0, 180);
117
	int xxx = tab.count * tab_w;
117
	int xxx = tab.count * tab_w;
118
 
118
 
119
	if (tab.count < TABS_MAX) {
119
	if (tab.count < TABS_MAX) {
120
		DrawBar(xxx, TOOLBAR_H, 1, TAB_H, sc.work_graph);
120
		DrawBar(xxx, TOOLBAR_H, 1, TAB_H, sc.work_graph);
121
		DrawBar(xxx+1, TOOLBAR_H, TAB_H, TAB_H-1, sc.button);
121
		DrawBar(xxx+1, TOOLBAR_H, TAB_H, TAB_H-1, sc.button);
122
		DrawRectangle3D(xxx+1, TOOLBAR_H, TAB_H, TAB_H-1, btn_light, btn_dark);
122
		DrawRectangle3D(xxx+1, TOOLBAR_H, TAB_H, TAB_H-1, btn_light, btn_dark);
123
		PutPixel(xxx+1+TAB_H, TOOLBAR_H, btn_dark);
123
		PutPixel(xxx+1+TAB_H, TOOLBAR_H, btn_dark);
124
		DefineHiddenButton(xxx+1, TOOLBAR_H, TAB_H-1, TAB_H-1, NEW_TAB);
124
		DefineHiddenButton(xxx+1, TOOLBAR_H, TAB_H-1, TAB_H-1, NEW_TAB);
125
		WriteText(xxx+7, TOOLBAR_H+2, 0x90, sc.button_text, "+");
125
		WriteText(xxx+7, TOOLBAR_H+2, 0x90, sc.button_text, "+");
126
		return xxx + TAB_H + 2;
126
		return xxx + TAB_H + 2;
127
	} else {
127
	} else {
128
		return xxx;
128
		return xxx;
129
	}
129
	}
130
}
130
}
131
 
131
 
132
void DrawTabsBar()
132
void DrawTabsBar()
133
{
133
{
134
	dword i;
134
	dword i;
135
	tab_w = GetTabWidth();
135
	tab_w = GetTabWidth();
136
	for (i=0; i
136
	for (i=0; i
137
	i = DrawNewTabButton();
137
	i = DrawNewTabButton();
138
	DrawBar(i, TOOLBAR_H, Form.cwidth-i, TAB_H-1, MixColors(sc.work_dark, sc.work, 128));
138
	DrawBar(i, TOOLBAR_H, Form.cwidth-i, TAB_H-1, MixColors(sc.work_dark, sc.work, 128));
139
	DrawBar(i, TOOLBAR_H+TAB_H-1, Form.cwidth-i, 1, sc.work_graph);
139
	DrawBar(i, TOOLBAR_H+TAB_H-1, Form.cwidth-i, 1, sc.work_graph);
140
}
140
}
141
 
141
 
142
void EventTabClose(int _id)
142
void EventTabClose(int _id)
143
{
143
{
144
	DeleteButton(TAB_ID + tab.count-1);
144
	DeleteButton(TAB_ID + tab.count-1);
145
	if (_id == tab.active) {
145
	if (_id == tab.active) {
146
		tab.close(_id);
146
		tab.close(_id);
147
		tab.restore(tab.active);
147
		tab.restore(tab.active);
148
		SetElementSizes();
148
		SetElementSizes();
149
		WB1.ParseHtml(WB1.bufpointer, WB1.bufsize);
149
		WB1.ParseHtml(WB1.bufpointer, WB1.bufsize);
150
		WB1.DrawPage();
150
		WB1.DrawPage();
151
		SetOmniboxText(history.current());
151
		SetOmniboxText(history.current());
152
	} else {
152
	} else {
153
		tab.close(_id);
153
		tab.close(_id);
154
	}
154
	}
155
	DrawTabsBar();
155
	DrawTabsBar();
156
}
156
}
157
 
157
 
158
void EventCloseActiveTab()
158
void EventCloseActiveTab()
159
{
159
{
160
	EventTabClose(tab.active);
160
	EventTabClose(tab.active);
161
}
161
}
162
 
162
 
163
void EventTabClick(int _id)
163
void EventTabClick(int _id)
164
{
164
{
165
	if (_id>=tab.count) _id = 0;
165
	if (_id>=tab.count) _id = 0;
166
	if (_id==-1) _id = tab.count-1;
166
	if (_id==-1) _id = tab.count-1;
167
	tab.save_state();
167
	tab.save_state();
168
	tab.restore(_id);
168
	tab.restore(_id);
169
	DrawTabsBar();
169
	DrawTabsBar();
170
	SetElementSizes();
170
	SetElementSizes();
171
	WB1.ParseHtml(WB1.bufpointer, WB1.bufsize);
171
	WB1.ParseHtml(WB1.bufpointer, WB1.bufsize);
172
	WB1.DrawPage();		
172
	WB1.DrawPage();		
173
	SetOmniboxText(history.current());
173
	SetOmniboxText(history.current());
174
}
174
}
175
 
175
 
176
void EventOpenNewTab(dword _url)
176
void EventOpenNewTab(dword _url)
177
{
177
{
178
	tab.add();
178
	tab.add();
179
	OpenPage(_url);
179
	OpenPage(_url);
180
	DrawTabsBar();
180
	DrawTabsBar();
181
}
181
}
182
 
182
 
183
void EventActivateNextTab()
183
void EventActivateNextTab()
184
{
184
{
185
	EventTabClick(tab.active+1);
185
	EventTabClick(tab.active+1);
186
}
186
}
187
 
187
 
188
void EventActivatePreviousTab()
188
void EventActivatePreviousTab()
189
{
189
{
190
	EventTabClick(tab.active-1);
190
	EventTabClick(tab.active-1);
191
}
191
}