Rev 6267 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
895 | barsuk | 1 | ; <--- description ---> |
2 | ; compiler: FASM |
||
3 | ; name: Clipboard test with GUI. |
||
4 | ; version: 0.1 |
||
5 | ; author: barsuk |
||
6 | ; comments: uses edit_box by Maxxxx32, |
||
7 | |||
8 | |||
9 | ; <--- include all MeOS stuff ---> |
||
10 | include "lang.inc" |
||
6268 | leency | 11 | include "..\..\..\..\macros.inc" |
895 | barsuk | 12 | |
13 | ; <--- start of MenuetOS application ---> |
||
14 | MEOS_APP_START |
||
15 | |||
16 | SEND_DELAY = 10 |
||
17 | RECV_DELAY = 100 |
||
18 | ATTEMPT = 5 |
||
19 | |||
20 | |||
21 | define DEBUG TRUE |
||
22 | include "bdebug.inc" |
||
23 | |||
24 | include "editbox.inc" |
||
25 | |||
26 | include "clip.inc" |
||
27 | |||
28 | use_edit_box |
||
29 | |||
30 | ; <--- start of code ---> |
||
31 | CODE |
||
32 | |||
33 | call clipboard_init |
||
34 | |||
35 | call draw_window ; at first create and draw the window |
||
36 | |||
37 | wait_event: ; main cycle |
||
38 | |||
39 | mov edi, input_box |
||
40 | call edit_box.mouse |
||
41 | |||
42 | mov eax, 10 |
||
43 | int 0x40 |
||
44 | |||
45 | cmp eax, 1 ; if event == 1 |
||
46 | je redraw ; jump to redraw handler |
||
47 | cmp eax, 2 ; else if event == 2 |
||
48 | je key ; jump to key handler |
||
49 | cmp eax, 3 ; else if event == 3 |
||
50 | je button ; jump to button handler |
||
51 | |||
52 | jmp wait_event ; else return to the start of main cycle |
||
53 | |||
54 | |||
55 | redraw: ; redraw event handler |
||
56 | call draw_window |
||
57 | jmp wait_event |
||
58 | |||
59 | |||
60 | key: ; key event handler |
||
61 | mov eax, 2 ; get key code |
||
62 | int 0x40 |
||
63 | |||
64 | cmp ah, '0' |
||
65 | jb no_digit |
||
66 | cmp ah, '9' |
||
67 | ja no_digit |
||
68 | sub ah, '0' |
||
69 | mov byte [format_id], ah |
||
70 | call draw_window |
||
71 | jmp wait_event |
||
72 | no_digit: |
||
3587 | fedesco | 73 | |
895 | barsuk | 74 | mov edi, input_box |
75 | call edit_box.key |
||
76 | |||
77 | jmp wait_event |
||
78 | |||
79 | |||
80 | button: ; button event handler |
||
81 | mov eax, 17 ; get button identifier |
||
82 | int 0x40 |
||
83 | |||
84 | cmp ah, 1 |
||
85 | jz exit |
||
86 | |||
87 | cmp ah, 5 |
||
88 | jz copy |
||
89 | cmp ah, 6 |
||
90 | jz paste |
||
91 | jmp wait_event |
||
92 | copy: |
||
93 | mov esi, input_text |
||
94 | mov edi, buffer.data |
||
95 | mov ecx, [buffer.size] |
||
96 | rep movsb ; copy text to buffer |
||
97 | |||
98 | mov edi, input_box |
||
99 | mov edx, [edi + 38] ; ed_size |
||
100 | xchg edx, [buffer.size] |
||
101 | movzx eax, byte [format_id] |
||
102 | mov esi, buffer |
||
103 | call clipboard_write |
||
104 | xchg edx, [buffer.size] |
||
105 | jmp wait_event |
||
106 | |||
107 | paste: |
||
108 | mov esi, buffer |
||
109 | movzx eax, byte [format_id] |
||
110 | mov edx, 7 |
||
111 | call clipboard_read |
||
3587 | fedesco | 112 | |
895 | barsuk | 113 | or eax, eax |
114 | jz wait_event |
||
115 | |||
116 | cmp eax, -1 |
||
117 | jz wait_event |
||
118 | |||
119 | or edx, edx |
||
120 | jz wait_event ; это все ошибки |
||
121 | |||
122 | mov eax, input_box |
||
123 | ;print "input box" |
||
124 | ;dph1 [eax] |
||
125 | ;dph1 [eax+4] |
||
126 | ;dph1 [eax+8] |
||
127 | ;dph1 [eax+12] |
||
128 | ;dph1 [eax+16] |
||
129 | ;dph1 [eax+20] |
||
130 | ;dph1 [eax+24] |
||
131 | |||
132 | ;;;;jmp wait_event |
||
133 | |||
134 | mov word [input_box + 36], ed_focus ; flags |
||
135 | |||
136 | mov ecx, [input_box + 38] ; size |
||
137 | print "paste read ecx=size" |
||
138 | jecxz .noloop |
||
139 | mov edi, input_box |
||
140 | mov ah, 8 ; backspace |
||
141 | .loop: |
||
142 | call edit_box.key |
||
143 | dec ecx |
||
144 | jnz .loop |
||
145 | .noloop: |
||
146 | mov esi, buffer.data |
||
147 | mov ecx, edx |
||
148 | pregs |
||
149 | .loop2: |
||
150 | mov ah, [esi] |
||
151 | cmp ah, 0 |
||
152 | jz .done |
||
153 | call edit_box.key ; я бы себе руки отрезал за такое |
||
154 | ; но что делать, если иначе не получается? |
||
155 | inc esi |
||
156 | dec ecx |
||
157 | jnz .loop2 |
||
158 | |||
159 | .done: |
||
160 | print "rest of data ecx" |
||
161 | pregs |
||
162 | call draw_window |
||
163 | jmp wait_event |
||
164 | |||
165 | exit: |
||
166 | or eax, -1 ; exit application |
||
167 | int 0x40 |
||
168 | |||
169 | |||
170 | draw_window: |
||
171 | mov eax, 12 ; start drawing |
||
172 | mov ebx, 1 |
||
173 | int 0x40 |
||
174 | |||
175 | mov eax, 0 ; create and draw the window |
||
176 | mov ebx, 100*65536+400 ; (window_cx)*65536+(window_sx) |
||
177 | mov ecx, 100*65536+250 ; (window_cy)*65536+(window_sy) |
||
178 | mov edx, 0x33ffffff ; work area color & window type 3 |
||
179 | mov edi, head |
||
180 | int 0x40 |
||
181 | |||
182 | mov eax, 4 |
||
183 | mov ebx, 10 shl 16 + 10 |
||
184 | mov ecx, 0x80000000 |
||
185 | mov edx, text1 |
||
186 | int 0x40 |
||
187 | mov eax, 4 |
||
188 | mov ebx, 10 shl 16 + 20 |
||
189 | mov edx, text2 |
||
190 | int 0x40 |
||
191 | mov eax, 47 |
||
192 | mov ebx, 0x00020000 |
||
193 | movzx ecx, byte [format_id] |
||
194 | mov edx, 200 shl 16 + 20 |
||
195 | mov esi, 0 |
||
196 | int 0x40 |
||
197 | |||
198 | mov eax, 8 |
||
199 | mov ebx, 10 shl 16 + 60 |
||
200 | mov ecx, 40 shl 16 + 15 |
||
201 | mov edx, 5 |
||
202 | mov esi, 0xd72189 |
||
203 | int 0x40 |
||
204 | mov eax, 4 |
||
205 | mov ebx, 12 shl 16 + 42 |
||
206 | mov ecx, 0x80000000 |
||
207 | mov edx, button1 |
||
208 | int 0x40 |
||
209 | |||
210 | mov eax, 8 |
||
211 | mov ebx, 80 shl 16 + 60 |
||
212 | mov ecx, 40 shl 16 + 15 |
||
213 | mov edx, 6 |
||
214 | mov esi, 0xd72189 |
||
215 | int 0x40 |
||
216 | mov eax, 4 |
||
217 | mov ebx, 82 shl 16 + 42 |
||
218 | mov ecx, 0x80000000 |
||
219 | mov edx, button2 |
||
220 | int 0x40 |
||
221 | |||
222 | mov edi, input_box |
||
223 | call edit_box.draw |
||
224 | |||
225 | ; mov eax, 4 |
||
226 | ; mov ebx, 10 shl 16 + 90 |
||
227 | ; mov ecx, 0 |
||
228 | ; mov edx, input_text |
||
229 | ; mov esi, [input_box + 38] |
||
230 | ; int 0x40 |
||
231 | ; mov eax, esi |
||
232 | ;print "eax = edit etxt len" |
||
233 | ;pregs |
||
234 | |||
235 | |||
236 | |||
237 | mov eax, 12 ; finish drawing |
||
238 | mov ebx, 2 |
||
3587 | fedesco | 239 | int 0x40 |
895 | barsuk | 240 | |
241 | ret |
||
242 | |||
243 | |||
244 | |||
245 | ; <--- initialised data ---> |
||
246 | DATA |
||
247 | |||
248 | format_id db 1 |
||
249 | |||
250 | ; buffer db 256 dup(0) |
||
251 | |||
252 | CLIP_BUFFER buffer, 256 |
||
253 | |||
254 | input_text db 256 dup(0) |
||
255 | input_box edit_box 100,10,70,0xffffff,0,0x00aaaaaa,0,255,input_text |
||
256 | |||
257 | ; input_box edit_box 100,10,70,0xffffff,0,0xaaaaaa,0,\ |
||
258 | ; 0xaaaaaa,0,255,input_text,ed_always_focus |
||
259 | |||
260 | head db "Пример работы с буфером обмена",0 |
||
261 | text1 db "Нажимайте цифры 0-9 для смены id формата данных",0 |
||
262 | text2 db "Сейчас выбран id формата данных: ",0 |
||
263 | |||
264 | button1 db "Копировать",0 |
||
265 | button2 db "Вставить",0 |
||
266 | |||
267 | ; <--- uninitialised data ---> |
||
268 | UDATA |
||
269 | |||
270 | |||
271 | MEOS_APP_END |
||
3587 | fedesco | 272 | ; <--- end of MenuetOS application --->--->--->--->--->--->--->---> |