Subversion Repositories Kolibri OS

Rev

Rev 4988 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4327 yogev_ezra 1
format MS COFF
2
public EXPORTS
3
section '.flat' code readable align 16
4
 
5
include '../../../macros.inc'
6
purge mov
7
include 'strlen.inc'
8
 
9
MB_FIRST_BUT_ID equ 3 ;идентификатор 1-й кнопки на сообщении
10
MB_MAX_BUT equ 8 ;максимальное число кнопок в сообщении
11
MB_BUT_HEIGHT equ 20 ;высота кнопки на сообщении
12
CHAR_WIDTH equ 6 ;ширина 1-й буквы текста
13
MB_BUT_OTY_1 equ  5 ;выртикальный(е) отступ(ы) между: заголовком окна и текстом, текстом кнопками
14
;--- отступы на кнопках, указанные вопросами: <-?->, без учета текста ---
15
MB_BUT_OTX_1 equ  5 ;[<-?->Caption.....]
16
MB_BUT_OTX_2 equ 10 ;[<-?->Caption<-?->]
17
MB_BUT_OTX_3 equ 15 ;[<-?->Caption<-?->]<-?->
18
MB_TEXT_OFFSET equ 2 ;смещение, по которому начинаеться текст заголовка окна
19
 
20
align 4
21
start:
22
  mov eax,48
23
  mov ebx,3
24
  mov ecx,sc
25
  mov edx,sizeof.system_colors
26
  mcall
27
  mov eax,40
28
  mov ebx,0x27
29
  mcall
30
 
31
  ;-- clear id pressed button ---
32
  mov ebx,[mb_text]
33
  mov al,byte[ebx]
34
  add al,MB_FIRST_BUT_ID
35
  dec al
36
  mov byte[mb_key_foc],al
37
 
38
  push [mb_text]
39
  call MsgBoxReInit
40
 
41
align 4
42
red_win:
43
  mov eax,12
44
  mov ebx,1
45
  mcall
46
 
47
  xor eax,eax
48
  mov bx,word[mb_left]
49
  shl ebx,16
50
  mov bx,word[mb_width]
51
  mov cx,word[mb_top]
52
  shl ecx,16
53
  mov cx,word[mb_height]
54
  mov edx,[sc.work]
55
  or  edx,0x33000000
56
  mov edi,[mb_text]
57
  add edi,MB_TEXT_OFFSET ;Caption
58
  mcall
59
 
60
  mcall 9,mb_procinfo,-1
61
  mov eax,dword[mb_procinfo.client_box.width]
62
 
63
  sub eax,[but_width]
64
  shr eax,1
65
  add eax,MB_BUT_OTX_1
66
  mov [ot_left],eax
67
 
68
  mov eax,4 ;рисование текста
69
  mov bx,MB_BUT_OTX_1
70
  shl ebx,16
71
  mov bx,MB_BUT_OTY_1
72
  mov ecx,[sc.work_text]
73
  mov edx,[txtMsg]
74
 
75
  @@:
76
    mov esi,edx
77
    call strlen
78
    call linlen
79
 
80
    cmp eax,0
81
    je @f
82
 
83
    mov esi,eax
84
    push eax
85
      mov eax,4
86
      int 0x40
87
    pop eax
88
 
89
    add edx,eax
90
    cmp byte[edx],0
91
    je @f
92
    inc edx
93
 
94
    add ebx,10 ; move <--y-->
95
    jmp @b
96
  @@:
97
 
98
  call MsgBoxDrawAllBut
99
  mcall 12,2
100
 
101
align 4
102
still:
103
  mov eax,10
104
  mcall
105
 
106
  cmp al,1 ;изм. положение окна
107
  jz red_win
108
  cmp al,2
109
  jz key
110
  cmp al,3
111
  jz button
112
 
113
  jmp still
114
 
115
align 4
116
key:
117
  mcall 2
118
  cmp ah,13
119
  jne @f
120
    mov ah,[mb_key_foc]
121
    jmp close
122
  @@:
123
 
124
  cmp ah,176 ;Left
125
  jne .no_left
126
  cmp [mb_key_foc],MB_FIRST_BUT_ID
127
  jg @f
128
    mov al,[mb_key_max]
129
    add [mb_key_foc],al
130
  @@:
131
    dec [mb_key_foc]
132
    call MsgBoxDrawAllBut
133
  .no_left:
134
 
135
  cmp ah,179 ;Right
136
  jne .no_right
137
  mov al,[mb_key_max]
138
  add al,MB_FIRST_BUT_ID
139
  cmp [mb_key_foc],al
140
  je .no_right
141
    inc [mb_key_foc]
142
    cmp [mb_key_foc],al
143
    jl @f
144
      mov [mb_key_foc],MB_FIRST_BUT_ID
145
    @@:
146
    call MsgBoxDrawAllBut
147
  .no_right:
148
 
149
  jmp still
150
 
151
align 4
152
button:
153
  mcall 17 ;получить код нажатой кнопки
154
  cmp ah,MB_FIRST_BUT_ID
155
  jge close
156
  cmp ah,1
157
  jne still
158
 
159
;.exit:
160
  mov ah,MB_FIRST_BUT_ID
161
  dec ah
162
close:
163
  sub ah,MB_FIRST_BUT_ID
164
  inc ah
165
  mov ebx,[mb_text]
166
  mov byte[ebx],ah
167
 
168
  ;*** call msgbox functions ***
169
  cmp ah,0
170
  je @f
171
  cmp dword[mb_funct],0
172
  je @f
173
    xor ebx,ebx
174
    mov bl,ah
175
    dec bl
176
    shl bx,2 ;bx=bx*4
177
    add ebx,dword[mb_funct]
178
    cmp dword[ebx],0
179
    je @f
180
      call dword[ebx]
181
  @@:
182
  mcall -1 ;выход из программы
183
 
184
align 4
185
MsgBoxDrawAllBut:
186
  mov ebx,[ot_left]
187
  shl ebx,16
188
  mov bx,word[ot_top]
189
  add bx,MB_BUT_OTY_1
190
 
191
  ; Buttons ...
192
  push edi
193
  mov edi,txtBut
194
  mov edx,[edi]
195
 
196
  mov ecx,MB_FIRST_BUT_ID
197
  @@:
198
    ;eax = len button caption text
199
    mov esi,edx
200
    call strlen
201
 
202
    cmp eax,0
203
    je @f
204
 
205
    call MsgBoxDrawButton
206
    inc ecx
207
 
208
    add edi,4
209
    cmp edi,endBut
210
    jge @f
211
    mov edx,[edi]
212
 
213
    push bx
214
    ror ebx,16
215
      imul esi,CHAR_WIDTH
216
      add esi,MB_BUT_OTX_3
217
      add ebx,esi ; ...
218
    ror ebx,16
219
    pop bx
220
 
221
    jmp @b
222
  @@:
223
  pop edi
224
  ret
225
 
226
;input:
227
; ecx = button id
228
align 4
229
MsgBoxDrawButton:
230
  push ecx
231
 
232
  ;button
233
  push eax ebx edx
234
    mov edx,ecx
235
    imul eax,CHAR_WIDTH
236
    add eax,MB_BUT_OTX_2
237
 
238
    mov esi,[sc.work_button]
239
    cmp cl,[mb_key_foc]
240
    jne @f
241
      mov esi,[sc.work_button_text]
242
    @@:
243
 
244
    mov cx,bx
245
    sub cx,MB_BUT_OTY_1
246
    shl ecx,16
247
    mov cx,MB_BUT_HEIGHT
248
    ror ebx,16
249
    sub bx,MB_BUT_OTX_1
250
    ror ebx,16
251
    mov bx,ax
252
 
253
    mov eax,8
254
    int 0x40
255
  pop edx ebx eax
256
 
257
  ;caption
258
  mov ecx,[sc.work_button_text]
259
  cmp esi,ecx
260
  jne @f
261
    mov ecx,[sc.work_button]
262
  @@:
263
  mov esi,eax
264
  mov eax,4
265
  int 0x40
266
 
267
  pop ecx
268
  ret
269
 
270
align 4
271
MsgBoxReInit:
272
  push ebp
273
  mov ebp,esp
274
    m2m dword[mb_text],dword[ebp+8]
275
  push eax ebx ecx edi esi
276
 
277
  mov esi,[mb_text]
278
  add esi,MB_TEXT_OFFSET
279
  call strlen
280
  inc esi ;add terminated zero
281
  add esi,eax ;add len of caption
282
  mov [txtMsg],esi
283
 
284
  ;--- go to first button text --- buttons 1...MB_MAX_BUT
285
  mov ebx,txtBut
286
  mov cx,MB_MAX_BUT
287
  @@:
288
    call strlen
289
    add esi,eax ;add len of caption
290
    inc esi ;add terminated zero
291
 
292
    mov dword[ebx],esi
293
    cmp byte[esi],0
294
    je @f
295
    add ebx,4
296
  loop @b
297
  @@:
298
 
299
  ;--- calc button top ---
300
  mov eax,1
301
  mov ebx,[txtMsg]
302
  @@:
303
    inc ebx
304
    cmp byte[ebx],0
305
    je @f
306
    cmp byte[ebx],13
307
    jne @b
308
    inc eax
309
    jmp @b
310
  @@:
311
  imul eax,10
312
  add eax,2*MB_BUT_OTY_1
313
  mov [ot_top],eax
314
 
315
  ;--- calc window height ---
316
  add eax,MB_BUT_OTY_1
317
  add eax,MB_BUT_HEIGHT
318
  add ax,5 ;height of border
319
  mov [mb_height],ax
320
  mcall 48,4 ;skin height
321
  add [mb_height],ax
322
 
323
  ;--- calc window top ---
324
  mov eax,14
325
  int 0x40
326
  mov word[mb_top],ax
327
  mov ax,word[mb_height]
328
  sub word[mb_top],ax
329
  shr word[mb_top],1
330
  ;---
331
  shr eax,16
332
  mov word[mb_left],ax
333
  mov ax,word[mb_width]
334
  sub word[mb_left],ax
335
  shr word[mb_left],1
336
 
337
  ;--- calc button width ---
338
  xor ebx,ebx
339
  xor ecx,ecx
340
  mov esi,[txtBut]
341
  mov byte[mb_key_max],0
342
  @@:
343
    cmp byte[esi],0
344
    je @f
345
    inc ecx
346
    call strlen
347
    add esi,eax
348
    inc esi
349
    inc byte[mb_key_max]
350
    add ebx,eax
351
    jmp @b
352
  @@:
353
 
354
  imul ebx,CHAR_WIDTH
355
  imul ecx,MB_BUT_OTX_3
356
  add ebx,ecx
357
  add ebx,MB_BUT_OTX_2
358
  sub ebx,MB_BUT_OTX_3
359
  mov [but_width],ebx
360
 
361
  pop esi edi ecx ebx eax
362
  pop ebp
363
  ret 4
364
 
365
;input:
366
; [esp+8] = pointer to msgbox text
367
align 4
368
MsgBoxCreate:
369
  push ebp
370
  mov ebp,esp
371
    m2m dword[mb_text],dword[ebp+8]
372
    push eax ebx ecx edx
373
 
374
    mov eax,51
375
    mov ebx,1
376
    mov ecx,start
377
    mov edx,dword[ebp+12];thread
378
    int 0x40
379
 
380
    mov dword[mb_funct],0
381
    pop edx ecx ebx eax
382
  pop ebp
383
  ret 8
384
 
385
;input:
386
; [esp+8] = pointer to msgbox functions pointers
387
align 4
388
MsgBoxSetFunctions:
389
  push ebp
390
  mov ebp,esp
391
    m2m dword[mb_funct],dword[ebp+8]
392
  pop ebp
393
  ret 4
394
 
395
;--- data ---
396
  txtMsg dd 0 ;указатель на начало текста сообщения
397
  txtBut rd MB_MAX_BUT ;указатель на начало текста подписей кнопок
398
  endBut:
399
  ot_left dd 0 ;отступ слева (для рисования кнопок)
400
  ot_top dd 0 ;отступ сверху (для рисования кнопок)
401
  but_width dd 0 ;ширина всех кнопок + зазоры между ними
402
  ;--- размеры на экране окна сообщения ---
403
  mb_left dw 0
404
  mb_width dw 300
405
  mb_top dw 0
406
  mb_height dw 50
407
  mb_key_foc db MB_FIRST_BUT_ID ;кнопка в фокусе (с учетом MB_FIRST_BUT_ID)
408
  mb_key_max db 1 ;число всех кнопок сообщения
409
;--------------------------------------------------
410
  sc system_colors
411
  mb_procinfo process_information ;указатель на структуру process_information родительского окна
412
  mb_text dd 0 ;msgbox_1 ;указатель данные для сообщения (которы передаються окну)
413
  mb_funct dd 0 ;pointer to functions
414
;--------------------------------------------------
415
align 16
416
EXPORTS:
417
  dd sz_mb_create, MsgBoxCreate
418
  dd sz_mb_reinit, MsgBoxReInit
419
  dd sz_mb_setfunctions, MsgBoxSetFunctions
420
  dd 0,0
421
  sz_mb_create db 'mb_create',0
422
  sz_mb_reinit db 'mb_reinit',0
423
  sz_mb_setfunctions db 'mb_setfunctions',0