Rev 4646 | Rev 4648 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4646 | Rev 4647 | ||
---|---|---|---|
1 | //HTML Viewer in C-- |
1 | //HTML Viewer in C-- |
2 | //Copyright 2007-2013 by Veliant & Leency |
2 | //Copyright 2007-2013 by Veliant & Leency |
3 | //Asper, lev, Lrz, Barsuk, Nable... |
3 | //Asper, lev, Lrz, Barsuk, Nable... |
4 | //home icon - rachel fu, GPL licence |
4 | //home icon - rachel fu, GPL licence |
5 | 5 | ||
6 | #ifndef AUTOBUILD |
6 | #ifndef AUTOBUILD |
7 | #include "lang.h--" |
7 | #include "lang.h--" |
8 | #endif |
8 | #endif |
9 | 9 | ||
10 | //libraries |
10 | //libraries |
11 | #define MEMSIZE 0x100000 |
11 | #define MEMSIZE 0x100000 |
12 | #include "..\lib\kolibri.h" |
12 | #include "..\lib\kolibri.h" |
13 | #include "..\lib\strings.h" |
13 | #include "..\lib\strings.h" |
14 | #include "..\lib\figures.h" |
14 | #include "..\lib\figures.h" |
15 | #include "..\lib\encoding.h" |
15 | #include "..\lib\encoding.h" |
16 | #include "..\lib\file_system.h" |
16 | #include "..\lib\file_system.h" |
17 | #include "..\lib\mem.h" |
17 | #include "..\lib\mem.h" |
18 | #include "..\lib\dll.h" |
18 | #include "..\lib\dll.h" |
19 | #include "..\lib\draw_buf.h" |
19 | #include "..\lib\draw_buf.h" |
20 | #include "..\lib\list_box.h" |
20 | #include "..\lib\list_box.h" |
21 | #include "..\lib\cursor.h" |
21 | #include "..\lib\cursor.h" |
22 | 22 | ||
23 | //*.obj libraries |
23 | //*.obj libraries |
24 | #include "..\lib\lib.obj\box_lib.h" |
24 | #include "..\lib\lib.obj\box_lib.h" |
25 | #include "..\lib\lib.obj\libio_lib.h" |
25 | #include "..\lib\lib.obj\libio_lib.h" |
26 | #include "..\lib\lib.obj\libimg_lib.h" |
26 | #include "..\lib\lib.obj\libimg_lib.h" |
27 | #include "..\lib\lib.obj\http.h" |
27 | #include "..\lib\lib.obj\http.h" |
28 | //images |
28 | //images |
29 | #include "img\toolbar_icons.c" |
29 | #include "img\toolbar_icons.c" |
30 | #include "img\URLgoto.txt"; |
30 | #include "img\URLgoto.txt"; |
31 | 31 | ||
32 | #ifdef LANG_RUS |
32 | #ifdef LANG_RUS |
33 | char version[]=" ¥ªáâ®¢ë© ¡à 㧥à 0.99.72"; |
33 | char version[]=" ¥ªáâ®¢ë© ¡à 㧥à 0.99.72"; |
34 | ?define IMAGES_CACHE_CLEARED "íè ª à⨮ª ®ç¨é¥" |
34 | ?define IMAGES_CACHE_CLEARED "íè ª à⨮ª ®ç¨é¥" |
35 | ?define T_LAST_SLIDE "â® ¯®á«¥¤¨© á« ©¤" |
35 | ?define T_LAST_SLIDE "â® ¯®á«¥¤¨© á« ©¤" |
36 | char loading[] = " £à㧪 áâà ¨æë... |
36 | char loading[] = " £à㧪 áâà ¨æë... |
37 | unsigned char page_not_found[] = FROM "html\page_not_found_ru.htm"; |
37 | unsigned char page_not_found[] = FROM "html\page_not_found_ru.htm"; |
38 | char accept_language[]= "Accept-Language: ru\n\0"; |
38 | char accept_language[]= "Accept-Language: ru\n\0"; |
39 | #else |
39 | #else |
40 | char version[]=" Text-based Browser 0.99.72"; |
40 | char version[]=" Text-based Browser 0.99.72"; |
41 | ?define IMAGES_CACHE_CLEARED "Images cache cleared" |
41 | ?define IMAGES_CACHE_CLEARED "Images cache cleared" |
42 | ?define T_LAST_SLIDE "This slide is the last" |
42 | ?define T_LAST_SLIDE "This slide is the last" |
43 | char loading[] = "Loading... |
43 | char loading[] = "Loading... |
44 | unsigned char page_not_found[] = FROM "html\page_not_found_en.htm"; |
44 | unsigned char page_not_found[] = FROM "html\page_not_found_en.htm"; |
45 | char accept_language[]= "Accept-Language: en\n\0"; |
45 | char accept_language[]= "Accept-Language: en\n\0"; |
46 | #endif |
46 | #endif |
47 | 47 | ||
48 | proc_info Form; |
48 | proc_info Form; |
49 | #define WIN_W 640 |
49 | #define WIN_W 640 |
50 | #define WIN_H 480 |
50 | #define WIN_H 480 |
51 | 51 | ||
52 | char search_path[]="http://nigma.ru/index.php?s="; |
52 | char search_path[]="http://nigma.ru/index.php?s="; |
53 | char str_location[]="location\0"; |
53 | char str_location[]="location\0"; |
54 | int redirected = 0; |
54 | int redirected = 0; |
55 | 55 | ||
56 | char stak[4096]; |
56 | char stak[4096]; |
57 | mouse m; |
57 | mouse m; |
58 | int action_buf; |
58 | int action_buf; |
59 | 59 | ||
60 | dword http_transfer = 0; |
60 | dword http_transfer = 0; |
61 | dword http_buffer; |
61 | dword http_buffer; |
62 | 62 | ||
63 | #include "..\TWB\TWB.c" |
63 | #include "..\TWB\TWB.c" |
64 | #include "menu_rmb.h" |
64 | #include "menu_rmb.h" |
65 | #include "history.h" |
65 | #include "history.h" |
66 | 66 | ||
67 | char editURL[sizeof(URL)]; |
67 | char editURL[sizeof(URL)]; |
68 | int mouse_twb; |
68 | int mouse_twb; |
69 | edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19}; |
69 | edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19}; |
70 | 70 | ||
71 | #define URL_HISTORY "WebView://history" |
71 | #define URL_HISTORY "WebView://history" |
72 | 72 | ||
73 | enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN }; |
73 | enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN }; |
74 | 74 | ||
75 | 75 | ||
76 | void main() |
76 | void main() |
77 | { |
77 | { |
78 | int key, btn; |
78 | int key, btn; |
79 | int half_scroll_size; |
79 | int half_scroll_size; |
80 | int scroll_used=0, show_menu; |
80 | int scroll_used=0, show_menu; |
81 | 81 | ||
82 | mem_Init(); |
82 | mem_Init(); |
83 | CursorPointer.Load(#CursorFile); |
83 | CursorPointer.Load(#CursorFile); |
84 | if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();} |
84 | if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();} |
85 | if (load_dll2(libio, #libio_init,1)!=0) notify("Error: library doesn't exists - libio"); |
85 | if (load_dll2(libio, #libio_init,1)!=0) notify("Error: library doesn't exists - libio"); |
86 | if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg"); |
86 | if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg"); |
87 | if (load_dll2(libHTTP, #http_lib_init,1)!=0) notify("Error: library doesn't exists - http"); |
87 | if (load_dll2(libHTTP, #http_lib_init,1)!=0) notify("Error: library doesn't exists - http"); |
88 | 88 | ||
89 | if (!URL) strcpy(#URL, "/sys/index.htm"); |
89 | if (!URL) strcpy(#URL, "/sys/index.htm"); |
90 | Form.width=WIN_W; |
90 | Form.width=WIN_W; |
91 | Form.height=WIN_H; |
91 | Form.height=WIN_H; |
92 | SetElementSizes(); |
92 | SetElementSizes(); |
93 | OpenPage(); |
93 | OpenPage(); |
94 | 94 | ||
95 | SetEventMask(0xa7); |
95 | SetEventMask(0xa7); |
96 | loop() |
96 | loop() |
97 | { |
97 | { |
98 | WaitEventTimeout(2); |
98 | WaitEventTimeout(2); |
99 | switch(EAX & 0xFF) |
99 | switch(EAX & 0xFF) |
100 | { |
100 | { |
101 | CASE evMouse: |
101 | CASE evMouse: |
102 | if (!CheckActiveProcess(Form.ID)) break; |
102 | if (!CheckActiveProcess(Form.ID)) break; |
103 | //Edit URL |
103 | //Edit URL |
104 | edit_box_mouse stdcall (#address_box); |
104 | edit_box_mouse stdcall (#address_box); |
105 | m.get(); |
105 | m.get(); |
106 | //Links hover |
106 | //Links hover |
107 | if (m.y>WB1.list.y) PageLinks.Hover(m.x, m.y, link_color_inactive, link_color_active, bg_color); |
107 | if (m.y>WB1.list.y) PageLinks.Hover(m.x, m.y, link_color_inactive, link_color_active, bg_color); |
108 | //Menu |
108 | //Menu |
109 | if (m.y>WB1.list.y) && (m.y |
109 | if (m.y>WB1.list.y) && (m.y |
110 | { |
110 | { |
111 | if (m.pkm) |
111 | if (m.pkm) |
112 | { |
112 | { |
113 | show_menu = 1; |
113 | show_menu = 1; |
114 | } |
114 | } |
115 | if (!m.pkm) && (show_menu) |
115 | if (!m.pkm) && (show_menu) |
116 | { |
116 | { |
117 | show_menu = 0; |
117 | show_menu = 0; |
118 | SwitchToAnotherThread(); |
118 | SwitchToAnotherThread(); |
119 | CreateThread(#menu_rmb,#stak+4092); |
119 | CreateThread(#menu_rmb,#stak+4092); |
120 | break; |
120 | break; |
121 | } |
121 | } |
122 | } |
122 | } |
123 | //Mouse scroll |
123 | //Mouse scroll |
124 | if (m.vert) |
124 | if (m.vert) |
125 | { |
125 | { |
126 | if (WB1.list.MouseScroll(m.vert)) WB1.Parse(); |
126 | if (WB1.list.MouseScroll(m.vert)) WB1.Parse(); |
127 | } |
127 | } |
128 | //Drag scroller |
128 | //Drag scroller |
129 | if (!m.lkm) scroll_used=0; |
129 | if (!m.lkm) scroll_used=0; |
130 | if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x) |
130 | if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x) |
131 | && (m.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>m.y) |
131 | && (m.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>m.y) |
132 | && (WB1.list.count>WB1.list.visible) && (m.lkm) |
132 | && (WB1.list.count>WB1.list.visible) && (m.lkm) |
133 | { |
133 | { |
134 | scroll_used=1; |
134 | scroll_used=1; |
135 | } |
135 | } |
136 | if (scroll_used) |
136 | if (scroll_used) |
137 | { |
137 | { |
138 | half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2; |
138 | half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2; |
139 | if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y; |
139 | if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y; |
140 | btn=WB1.list.first; |
140 | btn=WB1.list.first; |
141 | WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h; |
141 | WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h; |
142 | if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible; |
142 | if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible; |
143 | if (btn<>WB1.list.first) WB1.Parse(); |
143 | if (btn<>WB1.list.first) WB1.Parse(); |
144 | } |
144 | } |
145 | break; |
145 | break; |
146 | case evButton: |
146 | case evButton: |
147 | btn=GetButtonID(); |
147 | btn=GetButtonID(); |
148 | if (btn==1) ExitProcess(); |
148 | if (btn==1) ExitProcess(); |
149 | Scan(btn); |
149 | Scan(btn); |
150 | break; |
150 | break; |
151 | case evKey: |
151 | case evKey: |
152 | key = GetKey(); |
152 | key = GetKey(); |
153 | 153 | ||
154 | if (address_box.flags & 0b10) SWITCH(key) |
154 | if (address_box.flags & 0b10) SWITCH(key) |
155 | { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } |
155 | { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } |
156 | 156 | ||
157 | Scan(key); |
157 | Scan(key); |
158 | 158 | ||
159 | _EDIT_MARK: |
159 | _EDIT_MARK: |
160 | if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);} |
160 | if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);} |
161 | break; |
161 | break; |
162 | case evReDraw: |
162 | case evReDraw: |
163 | if (action_buf) Scan(action_buf); |
163 | if (action_buf) Scan(action_buf); |
164 | Draw_Window(); |
164 | Draw_Window(); |
165 | break; |
165 | break; |
166 | 166 | ||
167 | case evNetwork: |
167 | case evNetwork: |
168 | if (http_transfer > 0) { |
168 | if (http_transfer > 0) { |
169 | http_process stdcall (http_transfer); |
169 | http_process stdcall (http_transfer); |
170 | if (EAX == 0) { |
170 | if (EAX == 0) { |
171 | ESI = http_transfer; |
171 | ESI = http_transfer; |
172 | // Handle redirects |
172 | // Handle redirects |
173 | if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400) |
173 | if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400) |
174 | { |
174 | { |
175 | redirected++; |
175 | redirected++; |
176 | if (redirected<=5) |
176 | if (redirected<=5) |
177 | { |
177 | { |
178 | http_find_header_field stdcall (http_transfer, #str_location); |
178 | http_find_header_field stdcall (http_transfer, #str_location); |
179 | if (EAX!=0) { |
179 | if (EAX!=0) { |
180 | ESI = EAX; |
180 | ESI = EAX; |
181 | EDI = #URL; |
181 | EDI = #URL; |
182 | do { |
182 | do { |
183 | $lodsb; |
183 | $lodsb; |
184 | $stosb; |
184 | $stosb; |
185 | } while (AL != 0) && (AL != 13) && (AL != 10)); |
185 | } while (AL != 0) && (AL != 13) && (AL != 10)); |
186 | DSBYTE[EDI-1]='\0'; |
186 | DSBYTE[EDI-1]='\0'; |
187 | } |
187 | } |
188 | } |
188 | } |
189 | else |
189 | else |
190 | { |
190 | { |
191 | //TODO: display error (too many redirects) |
191 | //TODO: display error (too many redirects) |
192 | } |
192 | } |
193 | } |
193 | } |
194 | else |
194 | else |
195 | { |
195 | { |
196 | redirected = 0; |
196 | redirected = 0; |
197 | } |
197 | } |
198 | // Loading the page is complete, free resources |
198 | // Loading the page is complete, free resources |
199 | if (redirected>0) |
199 | if (redirected>0) |
200 | { |
200 | { |
201 | http_free stdcall (http_transfer); |
201 | http_free stdcall (http_transfer); |
202 | http_transfer=0; |
202 | http_transfer=0; |
203 | WB1.GetNewUrl(); |
203 | WB1.GetNewUrl(); |
204 | strcpy(#editURL, #URL); |
204 | strcpy(#editURL, #URL); |
205 | BrowserHistory.current--; |
205 | BrowserHistory.current--; |
206 | OpenPage(); |
206 | OpenPage(); |
207 | } |
207 | } |
208 | else |
208 | else |
209 | { |
209 | { |
210 | ESI = http_transfer; |
210 | ESI = http_transfer; |
211 | bufpointer = ESI.http_msg.content_ptr; |
211 | bufpointer = ESI.http_msg.content_ptr; |
212 | bufsize = ESI.http_msg.content_received; |
212 | bufsize = ESI.http_msg.content_received; |
213 | http_free stdcall (http_transfer); |
213 | http_free stdcall (http_transfer); |
214 | http_transfer=0; |
214 | http_transfer=0; |
215 | SetPageDefaults(); |
215 | SetPageDefaults(); |
216 | Draw_Window(); // stop button => refresh button |
216 | Draw_Window(); // stop button => refresh button |
217 | } |
217 | } |
218 | } |
218 | } |
219 | } |
219 | } |
220 | } |
220 | } |
221 | } |
221 | } |
222 | } |
222 | } |
223 | 223 | ||
224 | void SetElementSizes() |
224 | void SetElementSizes() |
225 | { |
225 | { |
226 | address_box.width = Form.width - 266; |
226 | address_box.width = Form.width - 266; |
227 | WB1.list.SetSizes(0, 44, Form.width - 10 - scroll_wv.size_x, Form.cheight - 44, 0, 10); |
227 | WB1.list.SetSizes(0, 44, Form.width - 10 - scroll_wv.size_x, Form.cheight - 44, 0, 10); |
228 | WB1.list.column_max = WB1.list.w - 30 / 6; |
228 | WB1.list.column_max = WB1.list.w - 30 / 6; |
229 | WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2; |
229 | WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2; |
230 | WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h, WB1.list.line_h); |
230 | WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h, WB1.list.line_h); |
231 | } |
231 | } |
232 | 232 | ||
233 | 233 | ||
234 | void Draw_Window() |
234 | void Draw_Window() |
235 | { |
235 | { |
236 | int j; |
236 | int j; |
237 | DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0); |
237 | DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0); |
238 | 238 | ||
239 | GetProcessInfo(#Form, SelfInfo); |
239 | GetProcessInfo(#Form, SelfInfo); |
240 | if (Form.status_window>2) |
240 | if (Form.status_window>2) |
241 | { |
241 | { |
242 | DrawTitle(#header); |
242 | DrawTitle(#header); |
243 | return; |
243 | return; |
244 | } |
244 | } |
245 | if (Form.height<120) MoveSize(OLD,OLD,OLD,120); |
245 | if (Form.height<120) MoveSize(OLD,OLD,OLD,120); |
246 | if (Form.width<280) MoveSize(OLD,OLD,280,OLD); |
246 | if (Form.width<280) MoveSize(OLD,OLD,280,OLD); |
247 | 247 | ||
248 | PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
248 | PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
249 | if (http_transfer > 0) _PutImage(88,10, 24,24, #stop_btn); |
249 | if (http_transfer > 0) _PutImage(88,10, 24,24, #stop_btn); |
250 | 250 | ||
251 | DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1); |
251 | DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1); |
252 | DrawBar(0,42,Form.cwidth,1,0xE2DBDC); |
252 | DrawBar(0,42,Form.cwidth,1,0xE2DBDC); |
253 | DrawBar(0,43,Form.cwidth,1,0xD2CED0); |
253 | DrawBar(0,43,Form.cwidth,1,0xD2CED0); |
254 | for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1); |
254 | for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1); |
255 | _PutImage(Form.cwidth-48,14, 40,19, #URLgoto); |
255 | _PutImage(Form.cwidth-48,14, 40,19, #URLgoto); |
256 | DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1); |
256 | DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1); |
257 | DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1); |
257 | DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1); |
258 | DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar |
258 | DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar |
259 | DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3); |
259 | DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3); |
260 | 260 | ||
261 | SetElementSizes(); |
261 | SetElementSizes(); |
262 | ShowPage(); |
262 | ShowPage(); |
263 | 263 | ||
264 | DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+1, 16, 16, BTN_UP+BT_HIDE, 0xE4DFE1); |
264 | DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+1, 16, 16, BTN_UP+BT_HIDE, 0xE4DFE1); |
265 | DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+scroll_wv.size_y-18, 16, 16, BTN_DOWN+BT_HIDE, 0xE4DFE1); |
265 | DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+scroll_wv.size_y-18, 16, 16, BTN_DOWN+BT_HIDE, 0xE4DFE1); |
266 | } |
266 | } |
267 | 267 | ||
268 | 268 | ||
269 | void ChangeCharset(byte new_charset) |
269 | void ChangeCharset(byte new_charset) |
270 | { |
270 | { |
271 | BufEncode(new_charset); |
271 | BufEncode(new_charset); |
272 | WB1.Parse(); |
272 | WB1.Parse(); |
273 | } |
273 | } |
274 | 274 | ||
275 | void Scan(int id) |
275 | void Scan(int id) |
276 | { |
276 | { |
277 | action_buf=0; |
277 | action_buf=0; |
278 | if (id >= 400) |
278 | if (id >= 400) |
279 | { |
279 | { |
280 | ProcessLinks(id); |
280 | ProcessLinks(id); |
281 | return; |
281 | return; |
282 | } |
282 | } |
283 | switch (id) |
283 | switch (id) |
284 | { |
284 | { |
285 | case 011: //Ctrk+K |
285 | case 011: //Ctrk+K |
286 | ChangeCharset(_KOI); |
286 | ChangeCharset(_KOI); |
287 | return; |
287 | return; |
288 | 288 | ||
289 | case 021: //Ctrl+U |
289 | case 021: //Ctrl+U |
290 | ChangeCharset(_UTF); |
290 | ChangeCharset(_UTF); |
291 | return; |
291 | return; |
292 | 292 | ||
293 | case 004: //Ctrl+D |
293 | case 004: //Ctrl+D |
294 | ChangeCharset(_DOS); |
294 | ChangeCharset(_DOS); |
295 | return; |
295 | return; |
296 | 296 | ||
297 | case 005: //Win encoding |
297 | case 005: //Win encoding |
298 | ChangeCharset(_WIN); |
298 | ChangeCharset(_WIN); |
299 | return; |
299 | return; |
300 | 300 | ||
301 | case 009: //free img cache |
301 | case 009: //free img cache |
302 | ImgCache.Free(); |
302 | ImgCache.Free(); |
303 | notify(IMAGES_CACHE_CLEARED); |
303 | notify(IMAGES_CACHE_CLEARED); |
304 | WB1.Parse(); |
304 | WB1.Parse(); |
305 | return; |
305 | return; |
306 | 306 | ||
307 | case 003: //history |
307 | case 003: //history |
308 | strcpy(#URL, URL_HISTORY); |
308 | strcpy(#URL, URL_HISTORY); |
309 | OpenPage(); |
309 | OpenPage(); |
310 | return; |
310 | return; |
311 | 311 | ||
312 | case BACK: |
312 | case BACK: |
313 | if (!BrowserHistory.GoBack()) return; |
313 | if (!BrowserHistory.GoBack()) return; |
314 | OpenPage(); |
314 | OpenPage(); |
315 | return; |
315 | return; |
316 | case FORWARD: |
316 | case FORWARD: |
317 | if (!BrowserHistory.GoForward()) return; |
317 | if (!BrowserHistory.GoForward()) return; |
318 | OpenPage(); |
318 | OpenPage(); |
319 | return; |
319 | return; |
320 | case 052: //F3 |
320 | case 052: //F3 |
321 | if (strncmp(#URL,"http:",5)==0) |
321 | if (strncmp(#URL,"http:",5)==0) |
322 | { |
322 | { |
323 | WriteFile(bufsize, bufpointer, "/tmp0/1/webview.tmp"); |
323 | WriteFile(bufsize, bufpointer, "/tmp0/1/webview.tmp"); |
324 | if (EAX==0) RunProgram("/rd/1/tinypad", "/tmp0/1/webview.tmp"); |
324 | if (EAX==0) RunProgram("/rd/1/tinypad", "/tmp0/1/webview.tmp"); |
325 | } |
325 | } |
326 | else |
326 | else |
327 | { |
327 | { |
328 | RunProgram("/rd/1/tinypad", #URL); |
328 | RunProgram("/rd/1/tinypad", #URL); |
329 | } |
329 | } |
330 | return; |
330 | return; |
331 | case 054: //F5 |
331 | case 054: //F5 |
332 | IF(address_box.flags & 0b10) WB1.Parse(); |
332 | IF(address_box.flags & 0b10) WB1.Parse(); |
333 | return; |
333 | return; |
334 | 334 | ||
335 | case REFRESH: |
335 | case REFRESH: |
336 | if (http_transfer > 0) |
336 | if (http_transfer > 0) |
337 | { |
337 | { |
338 | StopLoading(); |
338 | StopLoading(); |
339 | Draw_Window(); |
339 | Draw_Window(); |
340 | } |
340 | } |
341 | else OpenPage(); |
341 | else OpenPage(); |
342 | return; |
342 | return; |
343 | case 014: |
343 | case 014: |
344 | case 020: |
344 | case 020: |
345 | case NEWTAB: |
345 | case NEWTAB: |
346 | MoveSize(190,80,OLD,OLD); |
346 | MoveSize(190,80,OLD,OLD); |
347 | RunProgram(#program_path, #URL); |
347 | RunProgram(#program_path, #URL); |
348 | return; |
348 | return; |
349 | 349 | ||
350 | case HOME: |
350 | case HOME: |
351 | strcpy(#editURL, "http://kolibrios.org/"); |
351 | strcpy(#editURL, "http://kolibrios.org/"); |
352 | case GOTOURL: |
352 | case GOTOURL: |
353 | case 0x0D: //enter |
353 | case 0x0D: //enter |
354 | if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0; |
354 | if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0; |
355 | strcat(#URL, #editURL); |
355 | strcat(#URL, #editURL); |
356 | OpenPage(); |
356 | OpenPage(); |
357 | return; |
357 | return; |
358 | case SEARCHWEB: |
358 | case SEARCHWEB: |
359 | strcpy(#URL, #search_path); |
359 | strcpy(#URL, #search_path); |
360 | strcat(#URL, #editURL); |
360 | strcat(#URL, #editURL); |
361 | OpenPage(); |
361 | OpenPage(); |
362 | return; |
362 | return; |
363 | 363 | ||
364 | case 183: //PgDown |
364 | case 183: //PgDown |
365 | if (WB1.list.count < WB1.list.visible) return; |
365 | if (WB1.list.count < WB1.list.visible) return; |
366 | IF(WB1.list.first == WB1.list.count - WB1.list.visible) return; |
366 | IF(WB1.list.first == WB1.list.count - WB1.list.visible) return; |
367 | WB1.list.first += WB1.list.visible + 2; |
367 | WB1.list.first += WB1.list.visible + 2; |
368 | IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible; |
368 | IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible; |
369 | WB1.Parse(); |
369 | WB1.Parse(); |
370 | return; |
370 | return; |
371 | 371 | ||
372 | case 184: //PgUp |
372 | case 184: //PgUp |
373 | if (WB1.list.count < WB1.list.visible) return; |
373 | if (WB1.list.count < WB1.list.visible) return; |
374 | IF(WB1.list.first == 0) return; |
374 | IF(WB1.list.first == 0) return; |
375 | WB1.list.first -= WB1.list.visible - 2; |
375 | WB1.list.first -= WB1.list.visible - 2; |
376 | IF(WB1.list.first < 0) WB1.list.first = 0; |
376 | IF(WB1.list.first < 0) WB1.list.first = 0; |
377 | WB1.Parse(); |
377 | WB1.Parse(); |
378 | return; |
378 | return; |
379 | 379 | ||
380 | case 178: |
380 | case 178: |
381 | case BTN_UP: |
381 | case BTN_UP: |
382 | if (WB1.list.first <= 0) return; |
382 | if (WB1.list.first <= 0) return; |
383 | WB1.list.first--; |
383 | WB1.list.first--; |
384 | WB1.Parse(); |
384 | WB1.Parse(); |
385 | return; |
385 | return; |
386 | 386 | ||
387 | case 177: |
387 | case 177: |
388 | case BTN_DOWN: |
388 | case BTN_DOWN: |
389 | if (WB1.list.visible + WB1.list.first >= WB1.list.count) return; |
389 | if (WB1.list.visible + WB1.list.first >= WB1.list.count) return; |
390 | WB1.list.first++; |
390 | WB1.list.first++; |
391 | WB1.Parse(); |
391 | WB1.Parse(); |
392 | return; |
392 | return; |
393 | 393 | ||
394 | case 180: //home |
394 | case 180: //home |
395 | if (WB1.list.KeyHome()) WB1.Parse(); |
395 | if (WB1.list.KeyHome()) WB1.Parse(); |
396 | return; |
396 | return; |
397 | 397 | ||
398 | case 181: //end |
398 | case 181: //end |
399 | if (WB1.list.count < WB1.list.visible) return; |
399 | if (WB1.list.count < WB1.list.visible) return; |
400 | if (WB1.list.KeyEnd()) WB1.Parse(); |
400 | if (WB1.list.KeyEnd()) WB1.Parse(); |
401 | return; |
401 | return; |
402 | } |
402 | } |
403 | } |
403 | } |
404 | 404 | ||
405 | 405 | ||
406 | 406 | ||
407 | void ProcessLinks(int id) |
407 | void ProcessLinks(int id) |
408 | { |
408 | { |
409 | strcpy(#URL, PageLinks.GetURL(id-401)); |
409 | strcpy(#URL, PageLinks.GetURL(id-401)); |
410 | //$1 - Condition Script |
410 | //$1 - Condition Script |
411 | if (URL[0] == '$') |
411 | if (URL[0] == '$') |
412 | { |
412 | { |
413 | if (URL[1]=='-') && (condition_href) condition_href--; |
413 | if (URL[1]=='-') && (condition_href) condition_href--; |
414 | if (URL[1]=='+') |
414 | if (URL[1]=='+') |
415 | { |
415 | { |
416 | if (condition_href |
416 | if (condition_href |
417 | } |
417 | } |
418 | if (URL[1]!='-') && (URL[1]!='+') condition_href = atoi(#URL+1); |
418 | if (URL[1]!='-') && (URL[1]!='+') condition_href = atoi(#URL+1); |
419 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
419 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
420 | ShowPage(); |
420 | ShowPage(); |
421 | return; |
421 | return; |
422 | } |
422 | } |
423 | //#1 |
423 | //#1 |
424 | if (URL[0] == '#') |
424 | if (URL[0] == '#') |
425 | { |
425 | { |
426 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
426 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
427 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
427 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
428 | WB1.list.first=WB1.list.count-WB1.list.visible; |
428 | WB1.list.first=WB1.list.count-WB1.list.visible; |
429 | ShowPage(); |
429 | ShowPage(); |
430 | return; |
430 | return; |
431 | } |
431 | } |
432 | //liner.ru#1 |
432 | //liner.ru#1 |
433 | if (strrchr(#URL, '#')!=-1) |
433 | if (strrchr(#URL, '#')!=-1) |
434 | { |
434 | { |
435 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
435 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
436 | URL[strrchr(#URL, '#')-1] = 0x00; |
436 | URL[strrchr(#URL, '#')-1] = 0x00; |
437 | } |
437 | } |
438 | 438 | ||
439 | WB1.GetNewUrl(); |
439 | WB1.GetNewUrl(); |
440 | 440 | ||
441 | if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg")) |
441 | if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg")) |
442 | { |
442 | { |
443 | //if (strstr(#URL,"http:")) |
443 | //if (strstr(#URL,"http:")) |
444 | RunProgram("/sys/media/kiv", #URL); |
444 | RunProgram("/sys/media/kiv", #URL); |
445 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
445 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
446 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
446 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
447 | return; |
447 | return; |
448 | } |
448 | } |
449 | if (!strcmpn(#URL,"mailto:", 7)) |
449 | if (!strcmpn(#URL,"mailto:", 7)) |
450 | { |
450 | { |
451 | notify(#URL); |
451 | notify(#URL); |
452 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
452 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
453 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
453 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
454 | return; |
454 | return; |
455 | } |
455 | } |
456 | OpenPage(); |
456 | OpenPage(); |
457 | return; |
457 | return; |
458 | } |
458 | } |
459 | 459 | ||
460 | void StopLoading() |
460 | void StopLoading() |
461 | { |
461 | { |
- | 462 | if (http_transfer<>0) |
|
- | 463 | { |
|
462 | EAX = http_transfer; |
464 | EAX = http_transfer; |
463 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
465 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
464 | $push EAX // save it on the stack |
466 | $push EAX // save it on the stack |
465 | http_free stdcall (http_transfer); // abort connection |
467 | http_free stdcall (http_transfer); // abort connection |
466 | $pop EAX |
468 | $pop EAX |
467 | mem_Free(EAX); // free data |
469 | mem_Free(EAX); // free data |
468 | http_transfer=0; |
470 | http_transfer=0; |
469 | bufsize = 0; |
471 | bufsize = 0; |
- | 472 | } |
|
470 | PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
473 | PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
471 | } |
474 | } |
472 | 475 | ||
473 | void SetPageDefaults() |
476 | void SetPageDefaults() |
474 | { |
477 | { |
475 | strcpy(#header, #version); |
478 | strcpy(#header, #version); |
476 | pre_text = 0; |
479 | pre_text = 0; |
477 | WB1.list.count = WB1.list.first = 0; |
480 | WB1.list.count = WB1.list.first = 0; |
478 | stroka = 0; |
481 | stroka = 0; |
479 | cur_encoding = _DEFAULT; |
482 | cur_encoding = _DEFAULT; |
480 | if (o_bufpointer) o_bufpointer = free(o_bufpointer); |
483 | if (o_bufpointer) o_bufpointer = free(o_bufpointer); |
481 | anchor_line_num=WB1.list.first; |
484 | anchor_line_num=WB1.list.first; |
482 | anchor[0]='|'; |
485 | anchor[0]='|'; |
483 | } |
486 | } |
484 | 487 | ||
485 | void OpenPage() |
488 | void OpenPage() |
486 | { |
489 | { |
487 | StopLoading(); |
490 | StopLoading(); |
488 | strcpy(#editURL, #URL); |
491 | strcpy(#editURL, #URL); |
489 | BrowserHistory.AddUrl(); |
492 | BrowserHistory.AddUrl(); |
490 | if (strncmp(#URL,"http:",5)==0) |
493 | if (strncmp(#URL,"http:",5)==0) |
491 | { |
494 | { |
492 | _PutImage(88,10, 24,24, #stop_btn); |
495 | _PutImage(88,10, 24,24, #stop_btn); |
493 | http_get stdcall (#URL, #accept_language); |
496 | http_get stdcall (#URL, #accept_language); |
494 | http_transfer = EAX; |
497 | http_transfer = EAX; |
495 | if (http_transfer == 0) |
498 | if (http_transfer == 0) |
496 | { |
499 | { |
497 | StopLoading(); |
500 | StopLoading(); |
498 | bufsize = 0; |
501 | bufsize = 0; |
499 | ShowPage(); |
502 | ShowPage(); |
500 | return; |
503 | return; |
501 | } |
504 | } |
502 | IF (http_transfer < 0) notify("Error from HTTP lib"); |
- | |
503 | } |
505 | } |
504 | else |
506 | else |
505 | { |
507 | { |
506 | file_size stdcall (#URL); |
508 | file_size stdcall (#URL); |
507 | bufsize = EBX; |
509 | bufsize = EBX; |
508 | if (!bufsize) return; |
510 | if (!bufsize) return; |
509 | mem_Free(bufpointer); |
511 | mem_Free(bufpointer); |
510 | bufpointer = mem_Alloc(bufsize); |
512 | bufpointer = mem_Alloc(bufsize); |
511 | SetPageDefaults(); |
513 | SetPageDefaults(); |
512 | ReadFile(0, bufsize, bufpointer, #URL); |
514 | ReadFile(0, bufsize, bufpointer, #URL); |
513 | ShowPage(); |
515 | ShowPage(); |
514 | } |
516 | } |
515 | } |
517 | } |
516 | 518 | ||
517 | void ShowPage() |
519 | void ShowPage() |
518 | { |
520 | { |
519 | address_box.size = address_box.pos = strlen(#editURL); |
521 | address_box.size = address_box.pos = strlen(#editURL); |
520 | address_box.offset=0; |
522 | address_box.offset=0; |
521 | edit_box_draw stdcall(#address_box); |
523 | edit_box_draw stdcall(#address_box); |
522 | 524 | ||
523 | if (strcmp(#URL, URL_HISTORY)==0) ShowHistory(); else |
525 | if (strcmp(#URL, URL_HISTORY)==0) ShowHistory(); else |
524 | if (!bufsize) |
526 | if (!bufsize) |
525 | { |
527 | { |
526 | PageLinks.Clear(); |
528 | PageLinks.Clear(); |
527 | if (http_transfer<>0) |
529 | if (http_transfer<>0) |
528 | { |
530 | { |
529 | WB1.Prepare(#loading, sizeof(loading)); |
531 | WB1.Prepare(#loading, sizeof(loading)); |
530 | } |
532 | } |
531 | else |
533 | else |
532 | WB1.Prepare(#page_not_found, sizeof(page_not_found)); |
534 | WB1.Prepare(#page_not_found, sizeof(page_not_found)); |
533 | } |
535 | } |
534 | else |
536 | else |
535 | WB1.Parse(); |
537 | WB1.Parse(); |
536 | 538 | ||
537 | if (!header) strcpy(#header, #version); |
539 | if (!header) strcpy(#header, #version); |
538 | if (!strcmp(#version, #header)) DrawTitle(#header); |
540 | if (!strcmp(#version, #header)) DrawTitle(#header); |
539 | } |
541 | } |
540 | 542 | ||
541 | 543 | ||
542 | 544 | ||
543 | 545 | ||
544 | stop:>>>=>>>>5;>280)>120)>=5) |
546 | stop:>>>=>>>>5;>280)>120)>=5) |
545 | >>8;><8;>>>>>0)>=scroll_wv.start_x+scroll_wv.size_x)> |
547 | >>8;><8;>>>>>0)>=scroll_wv.start_x+scroll_wv.size_x)> |