Rev 3058 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3058 | Rev 3059 | ||
---|---|---|---|
1 | //HTML Viewer in C-- |
1 | //HTML Viewer in C-- |
2 | //Copyright 2007-2012 by Veliant & Leency |
2 | //Copyright 2007-2012 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 | #include "..\lib\kolibri.h" |
6 | #include "..\lib\kolibri.h" |
7 | #include "..\lib\strings.h" |
7 | #include "..\lib\strings.h" |
8 | #include "..\lib\figures.h" |
8 | #include "..\lib\figures.h" |
9 | #include "..\lib\encoding.h" |
9 | #include "..\lib\encoding.h" |
10 | #include "..\lib\file_system.h" |
10 | #include "..\lib\file_system.h" |
11 | #include "..\lib\mem.h" |
11 | #include "..\lib\mem.h" |
12 | #include "..\lib\dll.h" |
12 | #include "..\lib\dll.h" |
13 | //áèáëèîòåêè .obj |
13 | //áèáëèîòåêè .obj |
14 | #include "..\lib\libio_lib.h" |
14 | #include "..\lib\libio_lib.h" |
15 | #include "..\lib\libimg_lib.h" |
15 | #include "..\lib\libimg_lib.h" |
16 | #include "..\lib\edit_box_lib.h" |
16 | #include "..\lib\edit_box_lib.h" |
17 | #include "..\lib\scroll_lib.h" |
17 | #include "..\lib\scroll_lib.h" |
18 | #include "..\lib\truetype.h" |
18 | #include "..\lib\truetype.h" |
19 | //êàðòèíêè |
19 | //êàðòèíêè |
20 | #include "img\toolbar_icons.c" |
20 | #include "img\toolbar_icons.c" |
21 | #include "img\URLgoto.txt"; |
21 | #include "img\URLgoto.txt"; |
22 | 22 | ||
23 | 23 | ||
24 | #define URL param |
24 | #define URL param |
25 | int use_truetype = 0; |
25 | int use_truetype = 0; |
26 | 26 | ||
27 | char editURL[sizeof(URL)], |
27 | char editURL[sizeof(URL)], |
28 | page_links[12000], |
28 | page_links[12000], |
29 | header[300]; |
29 | header[300]; |
30 | 30 | ||
31 | struct lines{ |
31 | struct lines{ |
32 | int visible, all, first, column_max; |
32 | int visible, all, first, column_max; |
33 | }; |
33 | }; |
34 | 34 | ||
35 | int mouse_dd; |
35 | int mouse_dd; |
36 | edit_box edit1= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(editURL),#editURL,#mouse_dd,2,19,19}; |
36 | edit_box edit1= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(editURL),#editURL,#mouse_dd,2,19,19}; |
37 | scroll_bar scroll1 = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; //details in scroll_lib.h-- |
37 | scroll_bar scroll1 = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; //details in scroll_lib.h-- |
38 | 38 | ||
39 | 39 | ||
40 | proc_info Form; |
40 | proc_info Form; |
41 | #define WIN_W 640 |
41 | #define WIN_W 640 |
42 | #define WIN_H 480 |
42 | #define WIN_H 480 |
43 | 43 | ||
44 | 44 | ||
45 | dword stak[100]; //ìåíþ ÏÊÌ |
45 | dword stak[100]; //ìåíþ ÏÊÌ |
46 | mouse m; |
46 | mouse m; |
47 | 47 | ||
48 | #include "TWB.h" |
48 | #include "TWB.h" |
49 | #include "include\menu_rmb.h" |
49 | #include "include\menu_rmb.h" |
50 | 50 | ||
51 | 51 | ||
52 | void tre() |
52 | void tre() |
53 | { |
53 | { |
54 | char *font_picture; |
54 | char *font_picture; |
55 | char text[20]; |
55 | char text[20]; |
56 | int width=600; |
56 | int width=600; |
57 | int height=20; |
57 | int height=20; |
58 | // char palette[256*4]; |
58 | // char palette[256*4]; |
59 | int x; |
59 | int x; |
60 | 60 | ||
61 | text_out stdcall ("hello world\0",#fontlol, 17, 0x0, 10, 10); |
61 | text_out stdcall ("hello world\0",#fontlol, 17, 0x0, 10, 10); |
62 | text_out stdcall ("heyeyey!\0",#fontlol, 27, 0x0, 10, 30); |
62 | text_out stdcall ("heyeyey!\0",#fontlol, 27, 0x0, 10, 30); |
63 | text_out stdcall ("alarm!\0", #fontlol, 47, 0x00FF0000, 10, 70); |
63 | text_out stdcall ("alarm!\0", #fontlol, 47, 0x00FF0000, 10, 70); |
64 | /* |
64 | /* |
65 | strcpy(#text, "hello world\0"); |
65 | strcpy(#text, "hello world\0"); |
66 | 66 | ||
67 | debug("get width\n"); |
67 | debug("get width\n"); |
68 | get_width stdcall (#text, #fontinfo, height); |
68 | get_width stdcall (#text, #fontinfo, height); |
69 | width=EAX; |
69 | width=EAX; |
70 | for (x=0;x<20;x++) { |
70 | for (x=0;x<20;x++) { |
71 | init_font(#fontinfo); |
71 | init_font(#fontinfo); |
72 | debug("yaya\n"); |
72 | debug("yaya\n"); |
73 | font_picture=mem_Alloc(width*height); |
73 | font_picture=mem_Alloc(width*height); |
74 | text[1]=30+x; |
74 | text[1]=30+x; |
75 | truetype stdcall (#text, #fontinfo, font_picture, width, height); |
75 | truetype stdcall (#text, #fontinfo, font_picture, width, height); |
76 | 76 | ||
77 | debug("blyad'!\n"); |
77 | debug("blyad'!\n"); |
78 | 78 | ||
79 | 79 | ||
80 | 80 | ||
81 | PutPaletteImage(font_picture,width,height,0,20*x,8,#palette); |
81 | PutPaletteImage(font_picture,width,height,0,20*x,8,#palette); |
82 | mem_Free(font_picture); }*/ |
82 | mem_Free(font_picture); }*/ |
83 | } |
83 | } |
84 | 84 | ||
85 | char fontlol[64]; |
85 | char fontlol[64]; |
86 | 86 | ||
87 | void main() |
87 | void main() |
88 | { |
88 | { |
89 | int btn; |
89 | int btn; |
90 | byte key; |
90 | byte key; |
91 | int half_scroll_size; |
91 | int half_scroll_size; |
92 | int scroll_used=0; |
92 | int scroll_used=0; |
93 | 93 | ||
94 | mem_Init(); |
94 | mem_Init(); |
95 | if (load_dll2(libio, #libio_init,1)!=0) debug("Íå óäàëîñü ïîäêëþ÷èòü áèáëèîòåêó libio"w); |
95 | if (load_dll2(libio, #libio_init,1)!=0) debug("Íå óäàëîñü ïîäêëþ÷èòü áèáëèîòåêó libio"w); |
96 | if (load_dll2(libimg, #libimg_init,1)!=0) debug("Íå óäàëîñü ïîäêëþ÷èòü áèáëèîòåêó libimg"w); |
96 | if (load_dll2(libimg, #libimg_init,1)!=0) debug("Íå óäàëîñü ïîäêëþ÷èòü áèáëèîòåêó libimg"w); |
97 | if (load_dll2(boxlib, #edit_box_draw,0)!=0) {RunProgram("@notify", "System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();} |
97 | if (load_dll2(boxlib, #edit_box_draw,0)!=0) {RunProgram("@notify", "System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();} |
98 | load_dll2(#abox_lib, #boxlib_init,0); |
98 | load_dll2(#abox_lib, #boxlib_init,0); |
99 | if (load_dll2(libtruetype, #truetype,0)!=0) {debug("Íå óäàëîñü ïîäêëþ÷èòü áèáëèîòåêó TrueType"w); use_truetype = 2; } |
99 | if (load_dll2(libtruetype, #truetype,0)!=0) {debug("Íå óäàëîñü ïîäêëþ÷èòü áèáëèîòåêó TrueType"w); use_truetype = 2; } |
100 | else init_font(#fontlol); |
100 | else init_font(#fontlol); |
101 | 101 | ||
- | 102 | // if (!URL) strcpy(#URL, "/sys/home.htm"); |
|
102 | if (!URL) strcpy(#URL, "/sys/home.htm"); |
103 | if (!URL) strcpy(#URL, "/sys/ololo.txt"); |
103 | strcpy(#editURL, #URL); |
104 | strcpy(#editURL, #URL); |
104 | 105 | ||
105 | Form.width=WIN_W; |
106 | Form.width=WIN_W; |
106 | Form.height=WIN_H; |
107 | Form.height=WIN_H; |
107 | 108 | ||
108 | SetElementSizes(); |
109 | SetElementSizes(); |
109 | 110 | ||
110 | WB1.OpenPage(); |
111 | WB1.OpenPage(); |
111 | 112 | ||
112 | SetEventMask(0x27); |
113 | SetEventMask(0x27); |
113 | loop() |
114 | loop() |
114 | { |
115 | { |
115 | WaitEventTimeout(2); |
116 | WaitEventTimeout(2); |
116 | switch(EAX & 0xFF) |
117 | switch(EAX & 0xFF) |
117 | { |
118 | { |
118 | CASE evMouse: |
119 | CASE evMouse: |
119 | /*scrollbar_v_mouse (#scroll1); //êîí÷åíûé ñêðîëë ïðèòîðìàæèìàåò, èä¸ì "ñâîèì ïóò¸ì" |
120 | /*scrollbar_v_mouse (#scroll1); //êîí÷åíûé ñêðîëë ïðèòîðìàæèìàåò, èä¸ì "ñâîèì ïóò¸ì" |
120 | if (lines.first <> scroll1.position) |
121 | if (lines.first <> scroll1.position) |
121 | { |
122 | { |
122 | lines.first = scroll1.position; |
123 | lines.first = scroll1.position; |
123 | WB1.ParseHTML(buf, filesize); |
124 | WB1.ParseHTML(buf, filesize); |
124 | //break; |
125 | //break; |
125 | };*/ |
126 | };*/ |
126 | 127 | ||
127 | btn=GetProcessSlot(Form.ID); |
128 | btn=GetProcessSlot(Form.ID); |
128 | IF (btn<>GetActiveProcess()) break; //åñëè îêíî íå àêòèâíî íà ñîáûòèÿ ìûøè íå ðåàãèðóåì |
129 | IF (btn<>GetActiveProcess()) break; //åñëè îêíî íå àêòèâíî íà ñîáûòèÿ ìûøè íå ðåàãèðóåì |
129 | 130 | ||
130 | edit_box_mouse stdcall (#edit1); |
131 | edit_box_mouse stdcall (#edit1); |
131 | 132 | ||
132 | m.get(); |
133 | m.get(); |
133 | 134 | ||
134 | if (m.pkm) && (m.y>WB1.top) && (m.y |
135 | if (m.pkm) && (m.y>WB1.top) && (m.y |
135 | { |
136 | { |
136 | SwitchToAnotherThread(); |
137 | SwitchToAnotherThread(); |
137 | CreateThread(#menu_rmb,#stak); |
138 | CreateThread(#menu_rmb,#stak); |
138 | } |
139 | } |
139 | 140 | ||
140 | IF (m.vert==65535) //ïðîêðóòêà êîë¸ñèêîì |
141 | IF (m.vert==65535) //ïðîêðóòêà êîë¸ñèêîì |
141 | { |
142 | { |
142 | IF (lines.first==0) break; |
143 | IF (lines.first==0) break; |
143 | IF (lines.first>3) lines.first-=2; ELSE lines.first=1; |
144 | IF (lines.first>3) lines.first-=2; ELSE lines.first=1; |
144 | WB1.Scan(ID1); |
145 | WB1.Scan(ID1); |
145 | break; |
146 | break; |
146 | } |
147 | } |
147 | IF (m.vert==1) |
148 | IF (m.vert==1) |
148 | { |
149 | { |
149 | IF(lines.visible+lines.first+3>=lines.all) WB1.Scan(181); |
150 | IF(lines.visible+lines.first+3>=lines.all) WB1.Scan(181); |
150 | ELSE { |
151 | ELSE { |
151 | lines.first+=2; |
152 | lines.first+=2; |
152 | WB1.Scan(ID2); |
153 | WB1.Scan(ID2); |
153 | } |
154 | } |
154 | break; |
155 | break; |
155 | } |
156 | } |
156 | 157 | ||
157 | if (!m.lkm) scroll_used=0; |
158 | if (!m.lkm) scroll_used=0; |
158 | if (m.x>=WB1.width-14) && (m.x<=WB1.width+6) && (m.y>WB1.top+16) |
159 | if (m.x>=WB1.width-14) && (m.x<=WB1.width+6) && (m.y>WB1.top+16) |
159 | && (m.y |
160 | && (m.y |
160 | scroll_used=1; |
161 | scroll_used=1; |
161 | 162 | ||
162 | if (scroll_used) |
163 | if (scroll_used) |
163 | { |
164 | { |
164 | half_scroll_size = WB1.height - 16 * lines.visible / lines.all - 3 /2; |
165 | half_scroll_size = WB1.height - 16 * lines.visible / lines.all - 3 /2; |
165 | IF (half_scroll_size+WB1.top>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.top; //åñëè êóðñîð íàä îêíîì |
166 | IF (half_scroll_size+WB1.top>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.top; //åñëè êóðñîð íàä îêíîì |
166 | btn=lines.first; //ñîõðàíÿåì ñòàðîå êîëè÷åñòâî |
167 | btn=lines.first; //ñîõðàíÿåì ñòàðîå êîëè÷åñòâî |
167 | lines.first = m.y -half_scroll_size -WB1.top * lines.all / WB1.height; |
168 | lines.first = m.y -half_scroll_size -WB1.top * lines.all / WB1.height; |
168 | if (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible; |
169 | if (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible; |
169 | if (btn<>lines.first) WB1.ParseHTML(buf); //÷òîá ëèøíèé ðàç íå ïåðåðèñîâûâàòü |
170 | if (btn<>lines.first) WB1.ParseHTML(buf); //÷òîá ëèøíèé ðàç íå ïåðåðèñîâûâàòü |
170 | } |
171 | } |
171 | 172 | ||
172 | break; |
173 | break; |
173 | case evButton: |
174 | case evButton: |
174 | btn=GetButtonID(); |
175 | btn=GetButtonID(); |
175 | IF (btn==1) |
176 | IF (btn==1) |
176 | { |
177 | { |
177 | KillProcess(downloader_id); |
178 | KillProcess(downloader_id); |
178 | ExitProcess(); |
179 | ExitProcess(); |
179 | } |
180 | } |
180 | ELSE |
181 | ELSE |
181 | { |
182 | { |
182 | WB1.Scan(btn); |
183 | WB1.Scan(btn); |
183 | } |
184 | } |
184 | break; |
185 | break; |
185 | case evKey: |
186 | case evKey: |
186 | key = GetKey(); |
187 | key = GetKey(); |
187 | 188 | ||
188 | if (edit1.flags == 66) || (edit1.flags == 98) SWITCH(key) //åñëè àêòèâíà ñòðîêà àäðåñà èãíîðèðóåì íåêîòîðûå êíîïêè |
189 | if (edit1.flags == 66) || (edit1.flags == 98) SWITCH(key) //åñëè àêòèâíà ñòðîêà àäðåñà èãíîðèðóåì íåêîòîðûå êíîïêè |
189 | { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } |
190 | { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } |
190 | 191 | ||
191 | WB1.Scan(key); |
192 | WB1.Scan(key); |
192 | 193 | ||
193 | _EDIT_MARK: |
194 | _EDIT_MARK: |
194 | IF (key<>0x0d) && (key<>183) && (key<>184) && (key<>173) {EAX=key<<8; edit_box_key stdcall(#edit1);} //àäðåñíàÿ ñòðîêà |
195 | IF (key<>0x0d) && (key<>183) && (key<>184) && (key<>173) {EAX=key<<8; edit_box_key stdcall(#edit1);} //àäðåñíàÿ ñòðîêà |
195 | break; |
196 | break; |
196 | case evReDraw: |
197 | case evReDraw: |
197 | Draw_Window(); |
198 | Draw_Window(); |
198 | break; |
199 | break; |
199 | default: |
200 | default: |
200 | if (downloader_id<>0) |
201 | if (downloader_id<>0) |
201 | { |
202 | { |
202 | if (GetProcessSlot(downloader_id)<>0) break; |
203 | if (GetProcessSlot(downloader_id)<>0) break; |
203 | downloader_id=0; |
204 | downloader_id=0; |
204 | lines.first = lines.all = 0; |
205 | lines.first = lines.all = 0; |
205 | WB1.ReadHtml(_WIN); |
206 | WB1.ReadHtml(_WIN); |
206 | Draw_Window(); |
207 | Draw_Window(); |
207 | } |
208 | } |
208 | } |
209 | } |
209 | } |
210 | } |
210 | } |
211 | } |
211 | 212 | ||
212 | void SetElementSizes() |
213 | void SetElementSizes() |
213 | { |
214 | { |
214 | edit1.width=Form.width-266; |
215 | edit1.width=Form.width-266; |
215 | WB1.top=44; |
216 | WB1.top=44; |
216 | WB1.width=Form.width-13; |
217 | WB1.width=Form.width-13; |
217 | WB1.height=onTop(43,5); |
218 | WB1.height=onTop(43,5); |
218 | lines.column_max = WB1.width - 30 / 6; |
219 | lines.column_max = WB1.width - 30 / 6; |
219 | lines.visible = WB1.height - 3 / 10 - 2; |
220 | lines.visible = WB1.height - 3 / 10 - 2; |
220 | } |
221 | } |
221 | 222 | ||
222 | 223 | ||
223 | void Draw_Window() |
224 | void Draw_Window() |
224 | { |
225 | { |
225 | int j; |
226 | int j; |
226 | DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0x00E4DFE1,0,0); |
227 | DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0x00E4DFE1,0,0); |
227 | 228 | ||
228 | GetProcessInfo(#Form, SelfInfo); |
229 | GetProcessInfo(#Form, SelfInfo); |
229 | if (Form.status_window>2) //åñëè ñâåðíóòî â çàãîëîâîê, íè÷åãî íå ðèñóåì |
230 | if (Form.status_window>2) //åñëè ñâåðíóòî â çàãîëîâîê, íè÷åãî íå ðèñóåì |
230 | { |
231 | { |
231 | DrawTitle(#header); |
232 | DrawTitle(#header); |
232 | return; |
233 | return; |
233 | } |
234 | } |
234 | if (Form.height<120) MoveSize(OLD,OLD,OLD,120); |
235 | if (Form.height<120) MoveSize(OLD,OLD,OLD,120); |
235 | if (Form.width<280) MoveSize(OLD,OLD,280,OLD); |
236 | if (Form.width<280) MoveSize(OLD,OLD,280,OLD); |
236 | 237 | ||
237 | PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
238 | PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
238 | if (GetProcessSlot(downloader_id)<>0) PutImage(#stop_btn,24,24,88,10); |
239 | if (GetProcessSlot(downloader_id)<>0) PutImage(#stop_btn,24,24,88,10); |
239 | 240 | ||
240 | DrawBar(200,0,onLeft(200,9),43,0xE4DFE1); //çàêðàøèâàåì ôîí ïîä òóëáàðîì |
241 | DrawBar(200,0,onLeft(200,9),43,0xE4DFE1); //çàêðàøèâàåì ôîí ïîä òóëáàðîì |
241 | DrawBar(0,42,onLeft(5,4),1,0xE2DBDC); //âûïóêëîñòü |
242 | DrawBar(0,42,onLeft(5,4),1,0xE2DBDC); //âûïóêëîñòü |
242 | DrawBar(0,43,onLeft(5,4),1,0xD2CED0); //âûïóêëîñòü |
243 | DrawBar(0,43,onLeft(5,4),1,0xD2CED0); //âûïóêëîñòü |
243 | for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1); |
244 | for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1); |
244 | PutImage(#URLgoto,40,19,onLeft(57,0),14); |
245 | PutImage(#URLgoto,40,19,onLeft(57,0),14); |
245 | DefineButton(onLeft(37,0),15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1); |
246 | DefineButton(onLeft(37,0),15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1); |
246 | DefineButton(onLeft(56,0),15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1); |
247 | DefineButton(onLeft(56,0),15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1); |
247 | DrawRectangle(205,14,onLeft(58,205),18,0x94AECE); //îáîäîê ïîëîñû àäðåñà |
248 | DrawRectangle(205,14,onLeft(58,205),18,0x94AECE); //îáîäîê ïîëîñû àäðåñà |
248 | DrawRectangle(206,15,onLeft(59,205),16,0xE4ECF3); |
249 | DrawRectangle(206,15,onLeft(59,205),16,0xE4ECF3); |
249 | 250 | ||
250 | SetElementSizes(); |
251 | SetElementSizes(); |
251 | WB1.ShowPage(); |
252 | WB1.ShowPage(); |
252 | //tre(); |
253 | //tre(); |
253 | DefineButton(scroll1.start_x+1, scroll1.start_y+1, 16, 16, ID1+BT_HIDE, 0xE4DFE1); |
254 | DefineButton(scroll1.start_x+1, scroll1.start_y+1, 16, 16, ID1+BT_HIDE, 0xE4DFE1); |
254 | DefineButton(scroll1.start_x+1, scroll1.start_y+scroll1.size_y-18, 16, 16, ID2+BT_HIDE, 0xE4DFE1); |
255 | DefineButton(scroll1.start_x+1, scroll1.start_y+scroll1.size_y-18, 16, 16, ID2+BT_HIDE, 0xE4DFE1); |
255 | } |
256 | } |
256 | 257 | ||
257 | int onLeft(dword right,left) {return Form.width-right-left;} |
258 | int onLeft(dword right,left) {return Form.width-right-left;} |
258 | int onTop(dword down,up) {return Form.height-GetSkinHeight()-down-up;} |
259 | int onTop(dword down,up) {return Form.height-GetSkinHeight()-down-up;} |
259 | 260 | ||
260 | 261 | ||
261 | stop:5;>>280)>120)>>>8;><8;>>>>>>0)>=WB1.width+6)>>>20;x++)> |
262 | stop:5;>>280)>120)>>>8;><8;>>>>>>0)>=WB1.width+6)>>>20;x++)> |