Subversion Repositories Kolibri OS

Rev

Rev 1283 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1277 IgorA 1
; макрос для системной библиотеки box_lib.obj
2
; элемент TreeList для Kolibri OS
1285 IgorA 3
; файл последний раз изменялся 24.11.2009 IgorA
1277 IgorA 4
; на код применена GPL2 лицензия
5
 
6
 
7
sizeof.TreeList equ 20
1283 IgorA 8
;struct TreeList
9
;  type dw ? ;+ 0 тип элемента, или индекс иконки для узла
10
;  lev db ?  ;+ 2 уровень элемента
11
;  clo db ?  ;+ 3 флаг закрытия, или открытия (имеет смысл для родительского узла)
12
;  perv dd ? ;+ 4 индекс предыдущего элемента
13
;  next dd ? ;+ 8 индекс последующего элемента
14
;  tc dd ?   ;+12 врем. создания
15
;  td dd ?   ;+16 врем. удаления
16
;ends
1277 IgorA 17
 
1283 IgorA 18
tl_info_size  equ  word[edi +4] ;размер данных выделяемых для каждого узла (пользовательськие данные + текст для подписи)
1277 IgorA 19
tl_style      equ dword[edi+10] ;стили элемента
1283 IgorA 20
tl_data_nodes equ dword[edi+14] ;указатель на структуры узлов
1277 IgorA 21
tl_img_cx     equ  word[edi+22] ;ширина иконок
22
tl_img_cy     equ  word[edi+24] ;высота иконок
23
tl_data_img_sys equ dword[edi+26] ;указатель на системные изображения (стрелки, плюсики)
24
tl_ch_tim     equ dword[edi+30] ;количество изменений в файле
25
tl_tim_undo   equ dword[edi+38] ;количество отмененных действий
26
tl_cur_pos    equ dword[edi+42] ;позиция курсора
27
tl_col_bkg    equ dword[edi+46] ;цвет фона
28
tl_col_zag    equ dword[edi+50] ;цвет заголовка
29
tl_col_txt    equ dword[edi+54] ;цвет текста
30
tl_box_left   equ dword[edi+58]
31
tl_box_top    equ dword[edi+62]
32
tl_box_width  equ dword[edi+66]
33
tl_box_height equ dword[edi+70]
34
tl_capt_cy    equ  word[edi+74] ;высота подписи
1283 IgorA 35
tl_info_capt_offs equ dword[edi+76] ;сдвиг для начала текста (подписи узла)
1277 IgorA 36
tl_el_focus   equ dword[edi+80] ;указатель на структуру элемента в фокусе
37
tl_p_scrol    equ dword[edi+84] ;указатель на структуру скроллинга
38
tl_sb_draw    equ dword[edi+88] ;указатель на функцию перерисовывающую скроллинг
39
tl_on_press   equ dword[edi+96] ;указатель на функцию, которая вызывается при нажатии Enter
40
 
41
;константы стиля
42
tl_key_no_edit   equ   1b ;элемент нельзя редактировать на клавиатуре (изменять уровни, удалять)
43
tl_draw_par_line equ  10b ;рисовать линии к родительскому узлу
44
tl_list_box_mode equ 100b ;стиль не отображает уровни (как в ListBox все одного уровня)
45
 
1283 IgorA 46
;data_info	 dd ? ;+ 0 указатель на основные даные
47
;info_max_count dd ? ;+ 6 максимальное колличество структур
48
;data_img	 dd ? ;+18 указатель на изображения
49
;ls_tim		dd ? ;+34 время последнего сохранения
50
;on_activate dd ? ;+92 указатель на функцию при активировании узла
1277 IgorA 51
 
52
struc tree_list info_size,info_max_count,style, img_cx,img_cy,\
53
    col_bkg,col_zag,col_txt, box_l,box_t,box_w,box_h, capt_cy,info_capt_offs,\
1283 IgorA 54
    el_focus, p_scrol,p_sb_draw,on_press {
1277 IgorA 55
  .data_info	dd 0
56
  .info_size	dw info_size
57
  .info_max_count dd info_max_count
58
  .style	    dd style
59
  .data_nodes	dd 0
60
  .data_img	 dd 0
61
  .img_cx	   dw img_cx
62
  .img_cy	   dw img_cy
63
  .data_img_sys	 dd 0
64
  .ch_tim		  dd 0
65
  .ls_tim		  dd 0
66
  .tim_undo	 dd 0
67
  .cur_pos	  dd 0
68
  .col_bkg	  dd col_bkg
69
  .col_zag	  dd col_zag
70
  .col_txt	  dd col_txt
71
  .box_lert   dd box_l
72
  .box_top    dd box_t
73
  .box_width  dd box_w
74
  .box_height dd box_h
75
  .capt_cy	   dw capt_cy
76
  .info_capt_offs dd info_capt_offs
77
  .el_focus dd el_focus
78
  .p_scrol  dd p_scrol
79
  .p_sb_draw dd p_sb_draw
80
  .on_activate dd 0
1283 IgorA 81
  .on_press dd on_press
1277 IgorA 82
}
83
 
84
;-----------------------------------------------------------------------------
85
;функция для выделения памяти
86
;input:
87
; ecx = size data
88
;otput:
89
; eax = pointer to memory
90
align 4
91
mem_Alloc:
92
  push ebx
93
  mov eax,68
94
  mov ebx,12
95
  int 0x40
96
  pop ebx
97
  ret
98
;-----------------------------------------------------------------------------
99
;функция для освобождения памяти
100
;input:
101
; ecx = pointer to memory
102
align 4
103
mem_Free:
104
  push eax ebx
105
  cmp ecx,0
106
  jz @f
107
    mov eax,68
108
    mov ebx,13
109
    int 0x40
110
  @@:
111
  pop ebx eax
112
  ret
113
 
114
macro use_tree_list
115
{
116
align 4
117
tl_data_init: ;выделние памяти для структур списка и основной информации (конструктор)
118
  push ebp
119
  mov ebp,esp
120
  push eax ecx edi
121
    mov edi,dword[ebp+8]
122
 
123
    xor ecx,ecx
1283 IgorA 124
    mov cx,tl_info_size
1277 IgorA 125
    imul ecx,dword[edi+6]
126
    call mem_Alloc
127
    mov dword[edi],eax ;копируем указатель на полученую память в структуру
128
    mov dword[edi+18],0 ;обнуляем указатель 'data_img'
129
    mov tl_data_img_sys,0 ;обнуляем указатель 'data_img_sys'
130
 
131
    mov ecx,sizeof.TreeList
132
    imul ecx,dword[edi+6]
133
    call mem_Alloc
1283 IgorA 134
    mov tl_data_nodes,eax ;копируем указатель на полученую память в структуру
1277 IgorA 135
 
136
    push dword edi
137
    call tl_info_clear
138
 
139
    ;настройки дочернего скроллинга
140
    cmp tl_p_scrol,0
141
    je @f
142
      mov eax,tl_p_scrol
143
      ;*** цветовые настройки ***
144
      mov ecx,tl_col_bkg
145
      mov dword[eax+28],ecx ;+28 .bckg_col
146
      mov ecx,tl_col_zag
147
      mov dword[eax+32],ecx ;+32 .frnt_col
148
      mov ecx,tl_col_txt
149
      mov dword[eax+36],ecx ;+32 .line_col
150
      ;*** настройки размеров ***
151
      mov ecx,tl_box_left
152
      add ecx,tl_box_width
153
      mov word[eax+2],cx
154
      mov ecx,tl_box_height
155
      mov word[eax+4],cx
156
      mov ecx,tl_box_top
157
      mov word[eax+6],cx
158
    @@:
159
  pop edi ecx eax
160
  pop ebp
161
  ret 4
162
 
163
align 4
164
tl_data_clear: ;очистка памяти элемента (деструктор)
165
  push ebp
166
  mov ebp,esp
167
    push ecx edi
168
    mov edi,dword[ebp+8]
169
    cmp dword[edi+18],0 ;data_img
170
    je @f
171
      mov ecx,dword[edi+18]
172
      call mem_Free ;чистка системных иконок
173
    @@:
174
    cmp tl_data_img_sys,0
175
    je @f
176
      mov ecx,tl_data_img_sys
177
      call mem_Free ;чистка системных иконок
178
    @@:
179
    mov ecx,dword[edi]
180
    call mem_Free
181
 
1283 IgorA 182
    mov ecx,tl_data_nodes
1277 IgorA 183
    call mem_Free
184
    pop edi ecx
185
  pop ebp
186
  ret 4
187
 
188
align 4
189
tl_info_clear: ;очистка списка (информации)
190
  push ebp
191
  mov ebp,esp
192
    push eax ecx edi
193
    mov edi,dword[ebp+8]
194
    mov tl_ch_tim,0
195
    mov dword[edi+34],0 ;ls_tim
196
    mov tl_tim_undo,0
197
    mov tl_cur_pos,0
198
    ;xor ecx,ecx
199
    mov ecx,sizeof.TreeList
200
    imul ecx,dword[edi+6]
1283 IgorA 201
    mov eax,tl_data_nodes
1277 IgorA 202
    @@:
203
      mov byte[eax],0 ;чистим узлы 0-ми
204
      inc eax
205
      loop @b
1283 IgorA 206
    mov eax,tl_data_nodes ;указатель на 0-й узел
207
    mov dword[eax+8],1 ;указатель next в 0-м узле приравниваем к 1
1277 IgorA 208
    call tb_scrol_resize ;обработка скроллинга
209
    pop edi ecx eax
210
  pop ebp
211
  ret 4
212
 
213
 
214
align 4
215
tl_key: ;реакция на клавиатуру
216
  push ebp
217
  mov ebp,esp
218
    push ebx edi
219
    mov edi,dword[ebp+8]
220
 
221
    mov ebx,tl_el_focus
222
    cmp dword[ebx],edi
223
    jne .no_focus ;элемент не в фокусе
224
 
225
    xor bx,bx
226
    cmp ah,13 ;Enter
227
    jne @f
228
      cmp tl_on_press,0
229
      je @f
230
        call tl_on_press
231
    @@:
232
    cmp ah,32 ;Space
233
    jne @f
234
      push dword edi
235
      call tl_node_close_open
236
    @@:
237
    cmp ah,178 ;Up
238
    jne @f
239
      push dword edi
240
      call tl_cur_perv
241
    @@:
242
    cmp ah,177 ;Down
243
    jne @f
244
      push dword edi
245
      call tl_cur_next
246
    @@:
247
 
248
    bt tl_style,0 ;tl_key_no_edit
249
    jc .no_edit
250
      cmp ah,176 ;Left
251
      jne @f
252
	push dword edi
253
	call tl_node_lev_dec
254
	mov bx,1
255
      @@:
256
      cmp ah,179 ;Right
257
      jne @f
258
	push dword edi
259
	call tl_node_lev_inc
260
	mov bx,1
261
      @@:
262
      cmp ah,182 ;Delete
263
      jne @f
264
	push dword edi
265
	call tl_node_delete
266
	mov bx,1
267
      @@:
268
    .no_edit:
269
 
270
    cmp bx,1
271
    jne .no_focus
272
      push dword edi
273
      call tl_draw
274
    .no_focus:
275
 
276
    pop edi ebx
277
  pop ebp
278
  ret 4
279
 
280
align 4
281
tl_mouse: ;реакция на мышь
282
  push ebp
283
  mov ebp,esp
284
    push eax ebx ecx edx edi esi
285
    mov edi,dword[ebp+8]
286
 
287
    mov eax,37
288
    mov ebx,2
289
    int 0x40
290
 
291
    bt eax,0 ;left mouse button press
292
    jae .no_draw
293
 
294
    mov eax,37
295
    mov ebx,1
296
    int 0x40
297
 
298
    mov ebx,tl_box_left
299
    shl ebx,16
300
    cmp eax,ebx ;левая граница окна
301
    jl .no_in_wnd
302
 
303
    mov ebx,tl_box_left
304
    add ebx,tl_box_width
305
    shl ebx,16
306
    cmp eax,ebx ;правая граница окна
307
    jg .no_in_wnd
308
 
309
    mov ebx,tl_box_top
310
    add ebx,tl_box_height
311
    cmp ax,bx ;нижняя граница окна
312
    jg .no_in_wnd
313
 
314
    sub ebx,tl_box_height
315
    add bx,tl_capt_cy
316
    cmp ax,bx ;верхняя граница окна + высота подписи
317
    jl .no_in_wnd
318
 
1283 IgorA 319
    mov esi,tl_el_focus
320
    mov dword[esi],edi ;set focus
321
 
1277 IgorA 322
    ; if '+' or '-' press
323
    mov esi,eax
324
    shr esi,16
325
    sub esi,tl_box_left ;esi = mouse x coord in element window
326
 
327
    and eax,0xffff
328
    sub ax,bx
329
    xor edx,edx
330
    xor ecx,ecx
331
    mov cx,tl_img_cy
332
    div ecx
333
    cmp tl_p_scrol,0 ;учитываем скроллинг
334
    je @f
335
      mov edx,tl_p_scrol
336
      add eax,dword[edx+24] ;добавляем скроллинг на верху
337
    @@:
338
 
339
    mov ecx,eax
340
    call tl_get_node_count ;eax = node count
341
    cmp eax,ecx
342
    jl @f
343
      mov eax,ecx ;если курсор не вышел за пределы узлов, восстанавливаем старое значение eax
344
    @@:
345
 
346
    cmp eax,tl_cur_pos ;если новое значение курсора совпало с предыдущим
1283 IgorA 347
    je @f ;то не стираем курсор
348
    push esi
349
      mov esi,tl_box_top
350
      add esi,tl_box_height ;esi = coord bottom border
351
      call tl_draw_null_cursor ;стираем курсор
352
    pop esi
1277 IgorA 353
    @@:
354
 
355
    mov tl_cur_pos,eax
356
 
357
    ; if '+' or '-' press
358
    call tl_get_cur_node_index ;eax = node index
359
    cmp eax,2
360
    jl .no_open_close ;курсор стоит на пустом месте, без узлов
361
    imul eax,sizeof.TreeList
1283 IgorA 362
    add eax,tl_data_nodes
1277 IgorA 363
    xor bx,bx
364
    mov bl,byte[eax+2] ;+2 lev сохраняем уровень текущего узла
365
    inc bx ;+ поле для курсора
366
 
367
    cmp si,tl_img_cx
368
    jl .no_open_close ;мышей попали на левое поле для курсора, где точно нет '+' и '-'
369
      mov eax,esi
370
      xor edx,edx
371
      xor ecx,ecx
372
      mov cx,tl_img_cx
373
      div ecx
374
 
375
      cmp ax,bx
376
      jne .no_open_close
377
 
378
      push dword edi
379
      call tl_node_close_open
380
    .no_open_close:
381
 
1283 IgorA 382
      mov esi,tl_box_top
383
      add esi,tl_box_height ;esi = coord bottom border
384
      call tl_draw_cursor ;перерисовка курсора
1285 IgorA 385
      call tl_draw_caption_cur_pos
1277 IgorA 386
      jmp .no_draw
1283 IgorA 387
    .no_in_wnd: ;не попали в окно - потеря фокуса (при условии что фокус был на данном эелементе)
1277 IgorA 388
      mov ebx,tl_el_focus
1283 IgorA 389
      cmp dword[ebx],edi
390
      jne .no_draw ;элемент не в фокусе
391
        mov dword[ebx],0 ;reset focus
1277 IgorA 392
    .no_draw:
393
 
394
    pop esi edi edx ecx ebx eax
395
  pop ebp
396
  ret 4
397
 
398
align 4
399
tl_info_undo: ;отмена действия
400
  push ebp
401
  mov ebp,esp
402
  push eax edi
403
    mov edi,dword[ebp+8]
404
    mov eax,tl_tim_undo
405
    cmp tl_ch_tim,eax
406
    jbe @f
407
      inc tl_tim_undo
408
      call tb_scrol_resize ;обработка скроллинга
409
    @@:
410
  pop edi eax
411
  pop ebp
412
  ret 4
413
 
414
align 4
415
tl_info_redo: ;повтор действия
416
  push ebp
417
  mov ebp,esp
418
  push edi
419
    mov edi,dword[ebp+8]
420
    cmp tl_tim_undo,1
421
    jl @f
422
      dec tl_tim_undo
423
      call tb_scrol_resize ;обработка скроллинга
424
    @@:
425
  pop edi
426
  pop ebp
427
  ret 4
428
 
429
align 4
430
tl_info_set_undo: ;удаление отмененных действий
431
;  push ebp
432
;  mov ebp,esp
433
;  push edi
434
;    mov edi,dword[ebp+8]
435
 
436
;  mov [dragk],0 ;заканчиваем выделение от клавиатуры
437
  cmp tl_tim_undo,1
438
  jl .no_work
439
 
440
  push eax ebx ecx edx
1283 IgorA 441
  mov edx,tl_data_nodes
1277 IgorA 442
  mov ecx,edx
443
  add ecx,sizeof.TreeList
1283 IgorA 444
  call tl_move_next ;long i=node[0].next;
1277 IgorA 445
  mov eax,tl_tim_undo
446
  sub tl_ch_tim,eax ;ch_tim-=tim_undo;
447
  mov eax,tl_ch_tim
448
  cmp [edi+34],eax ;if(ls_tim>ch_tim)
449
  jle @f
450
    mov dword[edi+34],0 ;ls_tim=0
451
  @@:
452
    cmp edx,ecx
453
    jle @f
454
 
1283 IgorA 455
    ;if(node[i].tc>ch_tim){ // если создание символа было отменено
1277 IgorA 456
    cmp dword[edx+12],eax
457
    jle .no_u1
458
      mov dword[edx+12],0
459
      mov dword[edx+16],0
460
 
461
      mov ebx, dword[edx+4]
462
      imul ebx,sizeof.TreeList
1283 IgorA 463
      add ebx, tl_data_nodes ;.next
464
      push dword[edx+8] ;node[node[i].perv].next=node[i].next;
1277 IgorA 465
      pop dword[ebx+8]
466
 
467
      mov ebx, dword[edx+8]
468
      imul ebx,sizeof.TreeList
1283 IgorA 469
      add ebx, tl_data_nodes ;.perv
470
      push dword[edx+4] ;node[node[i].next].perv=node[i].perv;
1277 IgorA 471
      pop dword[ebx+4]
472
 
473
    .no_u1:
474
 
1283 IgorA 475
    ;else if(node[i].td>ch_tim) node[i].td=0; // если удаление символа было отменено
1277 IgorA 476
    cmp dword[edx+16],eax
477
    jle .no_u2
478
      mov dword[edx+16],0
479
    .no_u2:
480
 
481
    call tl_move_next
482
    jmp @b
483
  @@:
484
  mov tl_tim_undo,0
485
;  mov eax,[edi+?] ;co_tim
486
;  cmp tl_ch_tim,eax ;ch_tim
487
;  jge @f
488
;    mov [edi+?],0 ;co_tim
489
;  @@:
490
  pop edx ecx ebx eax
491
  .no_work:
492
 
493
;  pop edi
494
;  pop ebp
495
;  ret 4
496
  ret
497
 
498
align 4
499
tl_draw: ;вывод списка на экран
500
  push ebp
501
  mov ebp,esp
502
    push eax ebx ecx edx edi esi
503
    ;draw dir_list main rect
504
    mov edi,dword[ebp+8]
505
    mov ebx,tl_box_left
506
    shl ebx,16
507
    add ebx,tl_box_width
508
    mov ecx,tl_box_top
509
    shl ecx,16
510
    mov cx,tl_capt_cy
511
    mov edx,tl_col_zag
512
    mov eax,13
513
    int 0x40 ;draw window caption
514
 
515
    add ecx,tl_box_top
516
    shl ecx,16
517
    add ecx,tl_box_height
518
    sub cx,tl_capt_cy
519
    mov edx,tl_col_bkg
520
    int 0x40 ;draw window client rect
521
 
522
    cmp tl_capt_cy,9 ;9 - minimum caption height
523
    jl @f
524
    mov eax,4 ;draw text captions
525
    mov ebx,tl_box_left
526
    shl ebx,16
527
    add ebx,5*65536+3
528
    add ebx,tl_box_top
529
    mov ecx,tl_col_txt
530
    or	ecx,0x80000000
531
    lea edx,[txt_capt_cur]
532
    int 0x40
533
 
534
    mov ebx,tl_box_left
535
    shl ebx,16
536
    add ebx,100*65536+3
537
    add ebx,tl_box_top
538
    lea edx,[txt_capt_otm]
539
    int 0x40
540
 
541
    mov eax,47 ;draw
542
    mov ebx,0x40000
543
    mov ecx,tl_cur_pos
544
  inc ecx
545
    mov edx,tl_box_left
546
    shl edx,16
547
    add edx,50*65536+3
548
    add edx,tl_box_top
549
    mov esi,tl_col_txt
550
    int 0x40
551
    mov ecx,tl_tim_undo
552
    mov edx,tl_box_left
553
    shl edx,16
554
    add edx,140*65536+3
555
    add edx,tl_box_top
556
    mov esi,tl_col_txt
557
    int 0x40
558
    @@:
559
 
560
;---debug---
561
;mov ecx,0
562
;@@:
563
;call DebugSymb
564
;inc ecx
565
;cmp ecx,10
566
;jge @f
567
;jmp @b
568
;@@:
569
;---debug---
570
 
571
    ;cycle to nodes
572
    xor eax,eax
1283 IgorA 573
    mov edx,tl_data_nodes
1277 IgorA 574
    mov ecx,edx
575
    add ecx,sizeof.TreeList
576
 
577
    ;*** пропуск узлов, которые промотаны скроллингом ***
578
    cmp tl_p_scrol,0 ;если есть указатель на скроллинг
579
    je .end_c1
580
    mov esi,tl_p_scrol
581
    cmp dword[esi+24],0 ;если скроллинг на верху, выходим
582
    je .end_c1
583
      @@:
584
	call tl_iterat_next
585
	cmp edx,ecx
586
	jle .end_draw
587
	inc eax
588
	cmp eax,dword[esi+24]
589
	jge .end_c1
590
	jmp @b
591
    .end_c1:
592
 
593
    xor eax,eax
594
    mov esi,tl_box_top
595
    add esi,tl_box_height ;esi = coord bottom border
596
    @@:
597
      call tl_iterat_next
598
      cmp edx,ecx
599
      jle @f
600
      call tl_draw_node
601
      inc eax
602
      jmp @b
603
    @@:
604
 
605
    call tl_draw_cursor
606
    .end_draw:
607
    pop esi edi edx ecx ebx eax
608
  pop ebp
609
  ret 4
610
 
611
;input:
612
; ecx = pointer to 1 node struct
613
; edx = pointer to some node struct
614
; edi = pointer to 'TreeList' struct
1285 IgorA 615
;output:
616
; edx = pointer to next node struct
1277 IgorA 617
align 4
618
tl_iterat_next:
619
  push bx
620
  mov bl,0x7f
621
  cmp byte[edx+3],1
622
  jne @f
623
    mov bl,byte[edx+2]
624
  @@:
625
 
626
  cmp tl_tim_undo,0
627
  je .else
628
 
629
  push eax
630
  .beg0:
631
    call tl_move_next
632
    cmp edx,ecx
633
    jle @f
634
    call tl_node_not_vis ;пропуск удаленных и отмененных
635
    cmp al,1
636
    je .beg0
637
    cmp bl,byte[edx+2] ;пропуск закрытых
638
    jl .beg0
639
  @@:
640
  pop eax
641
  pop bx
642
  ret
643
 
644
  .else:
645
    call tl_move_next
646
    cmp edx,ecx
647
    jle .endif
648
    cmp dword[edx+16],0 ;td = 'time delete' -> пропуск удаленных
649
    jne .else
650
    cmp bl,byte[edx+2] ;пропуск закрытых
651
    jl .else
652
  .endif:
653
  pop bx
654
  ret
655
 
656
;input:
657
; ecx = pointer to 1 node struct
658
; edx = pointer to some node struct
659
; edi = pointer to 'TreeList' struct
660
align 4
661
tl_iterat_next_all:
662
  cmp tl_tim_undo,0
663
  je .else
664
 
665
  push eax
666
  @@:
667
    call tl_move_next
668
    cmp edx,ecx
669
    jle @f
670
    call tl_node_not_vis
671
    cmp al,1
672
    je @b
673
  @@:
674
  pop eax
675
  ret
676
  .else:
677
    call tl_move_next
678
    cmp edx,ecx
679
    jle .endif
680
    cmp dword[edx+16],0 ;td -> time delete
681
    jne .else
682
  .endif:
683
  ret
684
 
685
;input:
686
; ecx = pointer to 1 node struct
687
; edx = pointer to some node struct
688
; edi = pointer to 'TreeList' struct
689
align 4
690
tl_iterat_perv:
691
  push bx
692
  mov bl,0x7f
693
  cmp byte[edx+3],1
694
  jne @f
695
    mov bl,byte[edx+2]
696
  @@:
697
 
698
  cmp tl_tim_undo,0
699
  je .else
700
 
701
  push eax
702
  .beg0:
703
    call tl_move_perv
704
    cmp edx,ecx
705
    jle @f
706
    call tl_node_not_vis ;пропуск удаленных и отмененных
707
    cmp al,1
708
    je .beg0
709
    cmp bl,byte[edx+2] ;пропуск закрытых
710
    jl .beg0
711
  @@:
712
  pop eax
713
  pop bx
714
  ret
715
 
716
  .else:
717
    call tl_move_perv
718
    cmp edx,ecx
719
    jle .endif
720
    cmp dword[edx+16],0 ;td = 'time delete' -> пропуск удаленных
721
    jne .else
722
    cmp bl,byte[edx+2] ;пропуск закрытых
723
    jl .else
724
  .endif:
725
  pop bx
726
  ret
727
 
728
;input:
729
; edx = pointer to some node struct
730
; edi = pointer to 'TreeList' struct
731
;output:
732
; edx = pointer to next node struct
733
align 4
734
tl_move_next:
735
  mov edx,dword[edx+8]
736
  imul edx,sizeof.TreeList
1283 IgorA 737
  add edx,tl_data_nodes
1277 IgorA 738
  ret
739
 
740
;input:
741
; edx = pointer to some node struct
742
; edi = pointer to 'TreeList' struct
743
;output:
744
; edx = pointer to perv node struct
745
align 4
746
tl_move_perv:
747
  mov edx,dword[edx+4]
748
  imul edx,sizeof.TreeList
1283 IgorA 749
  add edx,tl_data_nodes
1277 IgorA 750
  ret
751
 
752
;input:
753
; edx = pointer to symbol struct
754
; edi = pointer to 'TreeList' struct
755
;output:
756
; al = 1 if sumbol not visible
1283 IgorA 757
; (node[i].td+tim_Undo<=ch_tim && node[i].td) || (node[i].tc>ch_tim-tim_Undo)
1277 IgorA 758
align 4
759
tl_node_not_vis:
760
  cmp dword[edx+16],0
761
  je @f
1283 IgorA 762
  mov eax,dword[edx+16] ;eax=node[i].td
1277 IgorA 763
  add eax,tl_tim_undo
764
  cmp eax,tl_ch_tim
765
  jg @f
766
    mov al,1
767
    ret
768
  @@:
769
 
770
  mov eax,tl_ch_tim
771
  sub eax,tl_tim_undo
772
  cmp dword[edx+12],eax ;tc -> time create
773
  jle @f
774
    mov al,1
775
    ret
776
  @@:
777
  xor al,al
778
  ret
779
 
780
 
781
;input:
782
; edi = pointer to TreeInfo struct
783
; esi = coord bottom border
784
align 4
785
tl_draw_cursor: ;рисуем курсор на экране
786
  push eax ebx ecx edx esi
787
    call tl_get_display_cur_pos ;eax = cursor pos in screen
788
    cmp eax,0
789
    jl .end_f ;курсор находится выше окна, в области прокрученной скроллингом
790
 
791
    cmp tl_data_img_sys,0 ;смотрим есть ли указатель на картинку системных иконок
792
    jne @f
793
      mov ebx,tl_box_left
794
      shl ebx,16
795
      mov bx,tl_img_cx
796
      xor ecx,ecx
797
      mov cx,tl_img_cy
798
      imul ecx,eax
799
      add ecx,tl_box_top
800
      add cx,tl_capt_cy
801
 
802
      ;crop image if on the border
803
      cmp esi,ecx ;если курсор внизу и его вообще не видно
804
      jl .end_f
805
 
806
      sub esi,ecx
807
      shl ecx,16
808
      mov cx,tl_img_cy
809
      cmp si,tl_img_cy
810
      jge .crop0
811
        mov cx,si ;если курсор виден частично (попал на нижнюю границу)
812
      .crop0:
813
 
814
      mov edx,tl_col_txt
815
      mov eax,13
816
      int 0x40 ;рисуем простой прямоугольник, т.к. нет системных иконок
817
      jmp .end_f
818
    @@:
819
      mov ebx,tl_data_img_sys
820
      imul ax,tl_img_cy
821
      mov cx,tl_img_cx
822
      shl ecx,16
823
      mov cx,tl_img_cy
824
      mov edx,tl_box_left
825
      shl edx,16
826
      mov dx,ax
827
      add edx,tl_box_top
828
      add dx,tl_capt_cy
829
 
830
      ;crop image if on the border
831
      cmp si,dx ;если курсор внизу и его вообще не видно
832
      jl .end_f
833
 
834
      sub si,dx
835
      cmp si,tl_img_cy
836
      jge .crop1
837
	mov cx,si ;если курсор виден частично (попал на нижнюю границу)
838
      .crop1:
839
 
840
      mov eax,7
841
      int 0x40 ;рисуем иконку курсора
842
    .end_f:
843
  pop esi edx ecx ebx eax
844
  ret
845
 
846
;input:
847
; edi = pointer to TreeInfo struct
848
; esi = coord bottom border
849
align 4
850
tl_draw_null_cursor: ;стираем курсор на экране
851
  push eax ebx ecx edx esi
852
    call tl_get_display_cur_pos ;eax = cursor pos in screen
853
    cmp eax,0
854
    jl .end_f ;курсор находится выше окна, в области прокрученной скроллингом
855
 
856
    mov ebx,tl_box_left
857
    shl ebx,16
858
    mov bx,tl_img_cx
859
    xor ecx,ecx
860
    mov cx,tl_img_cy
861
    imul ecx,eax
862
    add ecx,tl_box_top
863
    add cx,tl_capt_cy
864
 
865
    ;crop image if on the border
866
    cmp esi,ecx ;если курсор внизу и его вообще не видно
867
    jl .end_f
868
 
869
    sub esi,ecx
870
    shl ecx,16
871
    mov cx,tl_img_cy
872
    cmp si,tl_img_cy
873
    jge @f
874
      mov cx,si ;если курсор виден частично (попал на нижнюю границу)
875
    @@:
876
 
877
    mov edx,tl_col_bkg
878
    mov eax,13
879
    int 0x40 ;рисуем простой прямоугольник с фоновым цветом
880
 
881
    .end_f:
882
  pop esi edx ecx ebx eax
883
  ret
884
 
885
;input:
886
; edi = pointer to TreeInfo struct
887
;output:
888
; eax = index
889
align 4
890
tl_get_display_cur_pos: ;берет позицию курсора, относительно экрана
891
   mov eax,tl_cur_pos
892
   cmp tl_p_scrol,0
893
   je @f
894
     push ebx
895
       mov ebx,tl_p_scrol
896
       mov ebx,dword[ebx+24]
897
       sub eax,ebx ;отнимаем позицию скроллинга
898
     pop ebx
899
  @@:
900
  ret
901
 
902
;input:
903
; eax = node position
904
; edx = pointer to some node struct
905
; edi = pointer to TreeInfo struct
906
; esi = coord of bottom border
907
align 4
908
tl_draw_node:
909
  push eax ebx ecx edx esi
910
 
911
    mov ebx,1 ;1 - место под курсор и под знак +,-
912
    bt tl_style,2 ;tl_list_box_mode
913
    jc @f
914
      inc ebx ;+1 - место под знак +,-
915
    @@:
916
    add bl,byte[edx+2];get level
917
    imul bx,tl_img_cx
918
    add ebx,tl_box_left
919
 
920
    shl ebx,16
921
    mov bx,tl_img_cx
922
    xor ecx,ecx
923
    mov cx,tl_img_cy
924
    imul ecx,eax
925
    add ecx,tl_box_top
926
    add cx,tl_capt_cy
927
 
928
    ;crop image if on the border
929
    cmp esi,ecx ;если узел внизу и его вообще не видно
930
    jl .end_draw
931
 
932
    sub esi,ecx
933
    shl ecx,16
934
    mov cx,tl_img_cy
935
    cmp si,tl_img_cy
936
    jge @f
937
      mov cx,si ;если узел виден частично (попал на нижнюю границу)
938
      jmp .crop ;пропускаем рисование надписи, которая скорее всего тоже вылезет за нижнюю границу
939
    @@:
940
      call tl_draw_node_caption
941
    .crop:
942
    mov esi,ecx ;save ecx
943
 
944
    cmp dword[edi+18],0 ;data_img
945
    jne .draw_img_n
946
    push edx
947
      mov edx,tl_col_txt
948
      mov eax,13
949
      int 0x40 ;draw node rect
950
    pop edx
951
    jmp @f
952
    .draw_img_n:
953
    push ebx edx esi
954
      xor esi,esi
955
      mov si,word[edx] ;get icon type
956
      mov edx,ebx
957
      ror ecx,16
958
      mov dx,cx
959
      mov cx,bx
960
      ror ecx,16
961
      mov ebx,3 ;rgb = 3 bytes
962
      imul bx,tl_img_cx
963
      imul bx,tl_img_cy
964
      imul ebx,esi ;esi = icon index
965
      add ebx,dword[edi+18] ;data_img
966
 
967
      mov eax,7
968
      int 0x40 ;draw node icon '-'
969
    pop esi edx ebx
970
    @@:
971
 
972
    mov al,byte[edx+2] ;draw minus '-'
1283 IgorA 973
    mov ecx,tl_data_nodes
1277 IgorA 974
    add ecx,sizeof.TreeList
975
 
976
    mov ah,10 ;get icon index '+' or '-' ?
977
    cmp byte[edx+3],1
978
    jne .close
979
      dec ah
980
    .close:
981
 
982
    call tl_draw_node_icon_opn_clo
983
    bt tl_style,1
984
    jae .end_draw
985
      call tl_draw_node_icon_par_lin
986
 
987
    .end_draw:
988
  pop esi edx ecx ebx eax
989
  ret
990
 
991
;input:
992
; ecx = pointer to 1 node struct
993
;...
994
align 4
1285 IgorA 995
tl_draw_node_icon_opn_clo: ;рисует иконки открытого или закрытого узла (обычно + или -)
1277 IgorA 996
  push eax ebx ecx edx esi
997
    inc al
998
    call tl_iterat_next_all ;get next visible item
999
    cmp edx,ecx
1000
    jle @f
1001
      mov ecx,esi ;load ecx
1002
      cmp al,byte[edx+2]
1003
      jne @f
1004
      ror ebx,16
1005
      sub bx,tl_img_cx
1006
      ror ebx,16
1007
      cmp tl_data_img_sys,0
1008
      jne .draw_img_s
1009
	mov edx,tl_col_txt
1010
	mov eax,13
1011
	int 0x40 ;draw minus rect, if not system icons
1012
	jmp @f
1013
      .draw_img_s:
1014
      mov ecx,esi ;load ecx
1015
      mov edx,ebx
1016
      ror ecx,16
1017
      mov dx,cx
1018
      mov cx,bx
1019
      ror ecx,16
1020
      mov ebx,3 ;rgb = 3 bytes
1021
      imul bx,tl_img_cx
1022
      imul bx,tl_img_cy
1023
      shr eax,8
1024
      and eax,0xff
1025
      imul ebx,eax ;eax = icon index
1026
      add ebx,tl_data_img_sys
1027
      mov eax,7
1028
      int 0x40 ;draw minus icon '-'
1029
    @@:
1030
  pop esi edx ecx ebx eax
1031
  ret
1032
 
1033
;input:
1034
;...
1035
align 4
1036
tl_draw_node_icon_par_lin:
1037
  cmp byte[edx+3],1
1038
  je .close
1039
  push eax ebx ecx edx esi
1040
    cmp al,0
1041
    je @f
1042
;    dec al
1043
;    call tl_iterat_perv ;get perv visible item
1044
 
1045
    call tl_iterat_next_all ;get next visible item
1046
    cmp edx,ecx
1047
    jle .line3 ;if end of list
1048
      cmp al,byte[edx+2]
1049
      jne .line3 ;jg ???
1050
      mov eax,3 ;line in middle element
1051
      jmp .line2
1052
    .line3:
1053
      mov eax,6 ;line in end element
1054
    .line2:
1055
 
1056
      mov ecx,esi ;load ecx
1057
      ror ebx,16
1058
      sub bx,tl_img_cx
1059
      ror ebx,16
1060
      cmp tl_data_img_sys,0
1061
      jne .draw_img_s
1062
	mov edx,tl_col_txt
1063
	mov eax,13
1064
	int 0x40 ;draw minus rect, if not system icons
1065
	jmp @f
1066
      .draw_img_s:
1067
      mov ecx,esi ;load ecx
1068
      mov edx,ebx
1069
      ror ecx,16
1070
      mov dx,cx
1071
      mov cx,bx
1072
      ror ecx,16
1073
      mov ebx,3 ;rgb = 3 bytes
1074
      imul bx,tl_img_cx
1075
      imul bx,tl_img_cy
1076
 
1077
;      shr eax,8
1078
;      and eax,0xff
1079
      imul ebx,eax ;eax = icon index
1080
      add ebx,tl_data_img_sys
1081
      mov eax,7
1082
      int 0x40 ;draw line icon
1083
    @@:
1084
  pop esi edx ecx ebx eax
1085
  .close:
1086
  ret
1087
 
1088
;input:
1089
; edi = pointer to TreeInfo struct
1090
;output:
1091
; eax = rows
1092
align 4
1093
tl_get_rows_count:
1094
  push ecx edx
1095
    mov eax,tl_box_height
1096
    sub ax,tl_capt_cy
1097
    xor ecx,ecx
1098
    mov cx,tl_img_cy
1099
    xor edx,edx
1100
    div ecx
1101
  pop edx ecx
1102
  ret
1103
 
1104
;input:
1105
; eax = node position
1106
; ebx = [координата по оси x]*65536 + [img_cx]
1107
; ecx = [координата по оси y]*65536 + [img_cy]
1108
; edx = pointer to some node struct
1109
; edi = pointer to TreeInfo struct
1110
align 4
1111
tl_draw_node_caption:
1112
    push ebx ecx edx esi
1113
 
1114
    xor esi,esi
1283 IgorA 1115
    mov si,tl_info_size
1277 IgorA 1116
    cmp esi,tl_info_capt_offs
1117
    jle @f ;if caption size <= 0
1118
 
1119
    push eax
1120
      call tl_get_node_index ;eax = node index
1121
      imul esi,eax
1122
    pop eax
1123
      add esi,dword[edi]
1124
      add esi,tl_info_capt_offs
1125
      mov edx,esi
1126
 
1127
      shr ebx,16
1128
      add bx,tl_img_cx ;сдвигаем надпись по горизонтали --->
1129
      add bx,3 ;отступ
1130
      ;bx = coord. x
1131
      call tl_strlen ;eax = strlen
1132
      call tl_get_draw_text_len
1133
      mov cx,bx
1134
      ror ecx,16
1135
      mov ebx,ecx
1136
      add bx,tl_img_cy ;выравнивиние по нижней границе иконки
1137
      sub bx,9 ;отнимаем высоту текста
1138
      mov ecx,tl_col_txt
1139
      and ecx,0xffffff
1140
;      or ecx,0x80000000 ;text is ASCIIZ
1141
      mov eax,4
1142
      int 0x40
1143
    @@:
1144
    pop esi edx ecx ebx
1145
  ret
1146
 
1147
;input:
1148
; eax = strlen
1149
; ebx = text coord x
1150
;output:
1151
; esi = text len
1152
align 4
1153
tl_get_draw_text_len:
1154
  push eax ecx edx
1155
    mov esi,eax ;берем длинну строки
1156
 
1157
    mov eax,tl_box_left
1158
    add eax,tl_box_width
1159
    cmp eax,ebx
1160
    jle .text_null ;если подпись полностью вся за экраном
1161
    sub eax,ebx
1162
    xor edx,edx
1163
    mov ecx,6 ;ширина системного шрифта
1164
    div ecx ;смотрим сколько символов может поместиться на экране
1165
 
1166
    cmp esi,eax
1167
    jl @f
1168
      mov esi,eax ;если длинна текста меньше, чем все место под строку
1169
    jmp @f
1170
    .text_null:
1171
      xor esi,esi
1172
    @@:
1173
  pop edx ecx eax
1174
  ret
1175
 
1176
;input:
1177
; esi = pointer to string
1178
;output:
1179
; eax = strlen
1180
align 4
1181
tl_strlen:
1182
  mov eax,esi
1183
  @@:
1184
    cmp byte[eax],0
1185
    je @f
1186
    inc eax
1187
    loop @b
1188
  @@:
1189
  sub eax,esi
1190
  ret
1191
 
1192
;input:
1193
;dword[ebp+ 8] - pointer to node info
1194
;dword[ebp+12] - options
1195
;dword[ebp+16] - pointer to 'TreeList' struct
1196
align 4
1197
tl_node_add: ;добавить узел
1198
  push ebp
1199
  mov ebp,esp
1200
  push eax ebx ecx edx edi
1201
    mov edi,dword[ebp+16]
1202
 
1203
    call tl_info_set_undo
1204
 
1205
    mov ebx,sizeof.TreeList
1206
    imul ebx,dword[edi+6] ;+6 макс. количество узлов
1283 IgorA 1207
    add ebx,tl_data_nodes
1277 IgorA 1208
;--
1209
    call tl_get_cur_node_index ;eax=po_t
1210
    imul eax,sizeof.TreeList
1283 IgorA 1211
    add eax,tl_data_nodes
1277 IgorA 1212
    mov edx,eax
1213
    call tl_move_perv
1214
    call tl_get_node_index ;eax = index of pointer [edx]
1215
;--
1216
    mov edx,sizeof.TreeList
1217
    shl edx,1
1283 IgorA 1218
    add edx,tl_data_nodes
1219
    @@: ;for(i=2;i
1277 IgorA 1220
      cmp dword [edx+12],0
1221
      jne .u0
1222
      cmp dword [edx+16],0
1223
      jne .u0
1224
 
1225
	inc  tl_ch_tim
1226
	push  word[ebp+14] ;get type
1227
	pop   word[edx]
1228
	mov   byte[edx+2], 0 ;node[i].lev=0
1283 IgorA 1229
  bt tl_style,2 ;tl_list_box_mode
1230
  jc .l_box_m
1231
    mov cl,byte[ebp+12]
1232
    mov byte[edx+2],cl  ;node[i].lev
1233
  .l_box_m:
1277 IgorA 1234
	push tl_ch_tim       ;node[i].tc=ch_tim;
1235
	pop  dword[edx+12]
1236
	mov  dword[edx+4], eax ;node[i].perv=po_t;
1237
	;*** copy node data ***
1238
	push esi
1239
	xor ecx,ecx
1283 IgorA 1240
	mov cx,tl_info_size
1277 IgorA 1241
	mov esi,ecx
1242
 
1243
	push eax
1244
	  call tl_get_node_index ;eax = node index
1245
	  imul esi,eax
1246
	pop eax
1247
	add esi,dword[edi]
1248
	mov edi,dword[ebp+8] ;pointer to node data
1249
	xchg edi,esi
1250
	rep movsb
1251
 
1252
	mov esi,edi
1253
	mov edi,dword[ebp+16] ;restore edi
1254
	mov ecx,tl_info_capt_offs
1283 IgorA 1255
	cmp cx,tl_info_size
1277 IgorA 1256
	jge .no_text_data
1257
	  dec esi
1258
	  mov byte[esi],0
1259
	.no_text_data:
1260
	pop esi ;restore esi
1261
 
1262
	mov ecx,eax
1263
	imul ecx,sizeof.TreeList
1283 IgorA 1264
	add ecx,tl_data_nodes ; *** ecx = node[po_t] ***
1265
	add ecx,8   ; *** ecx = node[po_t].next ***
1266
	push dword [ecx] ;node[i].next=node[po_t].next;
1277 IgorA 1267
	pop dword [edx+8]
1268
 
1269
	call tl_get_node_index ;*** eax = i ***
1270
	cmp eax,dword[edi+6] ;info_max_count
1271
	jge .u0
1272
 
1283 IgorA 1273
	mov [ecx],eax ;node[po_t].next=i; // ссылки перенаправляем
1274
	mov ecx,[edx+8] ; *** ecx = node[i].next ***
1277 IgorA 1275
	imul ecx,sizeof.TreeList
1283 IgorA 1276
	add ecx,tl_data_nodes ; *** ecx = node[node[i].next] ***
1277
	mov [ecx+4],eax ;node[node[i].next].perv=i;
1277 IgorA 1278
 
1279
	call tb_scrol_resize ;обработка скроллинга
1280
    jmp @f
1281
      .u0:
1282
      add edx,sizeof.TreeList
1283
      cmp edx,ebx ;enf of node memory ?
1284
      jle @b
1285
    @@:
1286
  pop edi edx ecx ebx eax
1287
  pop ebp
1288
  ret 12
1289
 
1290
;input:
1291
; edi = pointer to TreeInfo struct
1292
align 4
1293
tb_scrol_resize:
1294
  push eax ecx edx
1295
  cmp tl_p_scrol,0 ;обработка скроллинга
1296
  je @f
1297
    call tl_get_node_count ;eax = node count
1298
    mov ecx,eax
1299
    call tl_get_rows_count
1300
    cmp ecx,eax
1301
    jg .ye_sb
1302
      xor ecx,ecx
1303
    .ye_sb:
1304
 
1305
    mov edx,tl_p_scrol
1306
    mov dword[edx+20],eax ;+20 .cur_area
1307
    mov dword[edx+16],ecx ;+16 .max_area
1308
    push dword edx ;pointer to scroll struct
1309
    mov edx,tl_sb_draw ;pointer to scroll draw function
1310
    call dword[edx]
1311
  @@:
1312
  pop edx ecx eax
1313
ret
1314
 
1315
;input:
1316
;dword[ebp+ 8] - pointer to node info
1317
;dword[ebp+12] - pointer to 'TreeList' struct
1318
align 4
1319
tl_node_set_data:
1320
  push ebp
1321
  mov ebp,esp
1322
  push eax ecx edx edi esi
1323
    mov edi,dword[ebp+12]
1324
    call tl_get_cur_node_index ;eax=po_t
1325
    cmp eax,2
1326
    jl @f
1327
      xor ecx,ecx
1283 IgorA 1328
      mov cx,tl_info_size
1277 IgorA 1329
      imul eax,ecx
1330
      add eax,dword[edi]
1331
      mov edi,eax
1332
      mov esi,dword[ebp+8] ;pointer to node data
1333
      rep movsb
1334
 
1335
      mov esi,edi
1336
      mov edi,dword[ebp+12] ;restore edi
1337
      mov ecx,tl_info_capt_offs
1283 IgorA 1338
      cmp cx,tl_info_size
1277 IgorA 1339
      jge .no_text_data
1340
	dec esi
1341
	mov byte[esi],0
1342
      .no_text_data:
1343
 
1344
    @@:
1345
  pop esi edi edx ecx eax
1346
  pop ebp
1347
  ret 8
1348
 
1349
;input:
1350
;dword[ebp+ 8] - pointer to 'TreeList' struct
1351
align 4
1352
tl_node_get_data: ;взять указатель на данные узла под курсором
1353
  push ebp
1354
  mov ebp,esp
1355
  push eax ecx edi
1356
    mov edi,dword[ebp+8]
1357
    call tl_get_cur_node_index ;eax=po_t
1358
    mov dword[ebp+8],0 ;if return 0 pointer
1359
    cmp eax,2
1360
    jl @f
1361
      xor ecx,ecx
1283 IgorA 1362
      mov cx,tl_info_size
1277 IgorA 1363
      imul eax,ecx
1364
      add eax,dword[edi]
1365
      mov dword[ebp+8],eax ;return node data pointer
1366
    @@:
1367
  pop edi ecx eax
1368
  pop ebp
1369
  ret
1370
 
1371
;input:
1372
;dword[ebp+ 8] - node index
1373
;dword[ebp+12] - pointer to 'TreeList' struct
1374
align 4
1375
tl_node_poi_get_info: ;взять указатель на структуру узла в указанной позиции
1376
  push ebp
1377
  mov ebp,esp
1378
  push eax ecx edx edi
1379
    mov edi,dword[ebp+12]
1380
    mov eax,dword[ebp+8]
1381
 
1382
    ;cycle to nodes
1283 IgorA 1383
    mov edx,tl_data_nodes
1277 IgorA 1384
    mov ecx,edx
1385
    add ecx,sizeof.TreeList
1386
    @@:
1387
      call tl_iterat_next_all
1388
      cmp edx,ecx
1389
      jle @f
1390
      dec eax
1391
      cmp eax,0
1392
      jg @b
1393
      jmp .find
1394
    @@:
1395
      xor edx,edx
1396
    .find:
1397
    mov dword[ebp+12],edx
1398
  pop edi edx ecx eax
1399
  pop ebp
1400
  ret 4
1401
 
1402
;input:
1403
;dword[ebp+ 8] - node param struct
1404
;dword[ebp+12] - pointer to 'TreeList' struct
1405
align 4
1406
tl_node_poi_get_next_info: ;взять указатель на следущую структуру узла
1407
  push ebp
1408
  mov ebp,esp
1409
  push ecx edx edi
1410
    mov edi,dword[ebp+12]
1411
    mov edx,dword[ebp+8]
1412
 
1283 IgorA 1413
    mov ecx,tl_data_nodes
1277 IgorA 1414
    add ecx,sizeof.TreeList
1415
 
1416
    call tl_iterat_next_all
1417
    cmp edx,ecx
1418
    jg @f
1419
      xor edx,edx
1420
    @@:
1421
 
1422
    mov dword[ebp+12],edx
1423
  pop edi edx ecx
1424
  pop ebp
1425
  ret 4
1426
 
1427
;input:
1428
;dword[ebp+ 8] - node param struct
1429
;dword[ebp+12] - pointer to 'TreeList' struct
1430
align 4
1431
tl_node_poi_get_data: ;взять указатель на данные узла
1432
  push ebp
1433
  mov ebp,esp
1434
  push eax ecx edi
1435
    mov edi,dword[ebp+12]
1436
    mov edx,dword[ebp+8]
1437
 
1438
    mov dword[ebp+12],0
1439
    call tl_get_node_index ;eax = node index
1440
    cmp eax,2
1441
    jl @f
1442
      xor ecx,ecx
1283 IgorA 1443
      mov cx,tl_info_size
1277 IgorA 1444
      imul eax,ecx
1445
      add eax,dword[edi]
1446
      mov dword[ebp+12],eax ;return node data pointer
1447
    @@:
1448
  pop edi ecx eax
1449
  pop ebp
1450
  ret 4
1451
 
1452
;input:
1453
; edi = pointer 'tl' struct
1454
;output:
1455
; eax = index of current node
1456
align 4
1457
tl_get_cur_node_index: ;берет позицию под курсором
1458
  push ecx edx
1459
    ;cycle to nodes
1460
    xor eax,eax
1283 IgorA 1461
    mov edx,tl_data_nodes
1277 IgorA 1462
    mov ecx,edx
1463
    add ecx,sizeof.TreeList
1464
    @@:
1465
      call tl_iterat_next
1466
      cmp edx,ecx
1467
      jle @f
1468
      cmp eax,tl_cur_pos
1469
      je @f
1470
      inc eax
1471
      jmp @b
1472
    @@:
1473
  mov eax,edx
1283 IgorA 1474
  sub eax,tl_data_nodes
1277 IgorA 1475
  xor edx,edx
1476
  mov ecx,sizeof.TreeList
1477
  div ecx
1478
  pop edx ecx
1479
  ret
1480
 
1481
;input:
1482
; edx = pointer node memory
1483
; edi = pointer 'tl' struct
1484
;output:
1485
; eax = struct index of current node
1486
align 4
1487
tl_get_node_index: ;берет позицию указанного символа
1488
  push ecx edx
1489
  mov eax,edx
1283 IgorA 1490
  sub eax,tl_data_nodes
1277 IgorA 1491
  xor edx,edx
1492
  mov ecx,sizeof.TreeList
1493
  div ecx
1494
  pop edx ecx
1495
  ret
1496
 
1497
align 4
1498
tl_node_delete: ;удалить узел
1499
  push ebp
1500
  mov ebp,esp
1501
  push eax edx edi
1502
    mov edi,dword[ebp+8]
1503
    call tl_get_cur_node_index ;eax=po_t
1504
    cmp eax,2
1505
    jl @f
1506
      imul eax,sizeof.TreeList
1283 IgorA 1507
      add eax,tl_data_nodes
1277 IgorA 1508
      mov edx,eax
1509
      inc tl_ch_tim
1510
      mov eax,tl_ch_tim
1511
      mov dword[edx+16],eax
1512
      call tb_scrol_resize ;обработка скроллинга
1513
    @@:
1514
  pop edi edx eax
1515
  pop ebp
1516
  ret 4
1517
 
1518
align 4
1519
tl_cur_beg: ;поставить курсор на первый узел
1520
  push ebp
1521
  mov ebp,esp
1522
  push edi
1523
    mov edi,dword[ebp+8]
1524
    mov tl_cur_pos,0
1525
    cmp tl_p_scrol,0
1526
    je @f
1527
      mov edi,tl_p_scrol
1528
      mov dword[edi+24],0
1529
      push dword edi
1530
      mov edi,dword[ebp+8]
1531
      mov edi,tl_sb_draw
1532
      call dword[edi]
1533
    @@:
1534
  pop edi
1535
 
1536
  pop ebp
1537
  ret 4
1538
 
1539
align 4
1540
tl_cur_next: ;перенести курсор на 1 позицию ниже
1541
  push ebp
1542
  mov ebp,esp
1543
  push eax ebx edi esi
1544
    mov edi,dword[ebp+8]
1545
    call tl_get_node_count ;eax = node count
1546
    ;inc eax
1547
    cmp tl_cur_pos,eax
1548
    jge .no_redraw
1549
      mov esi,tl_box_top
1550
      add esi,tl_box_height ;esi = coord bottom border
1551
      call tl_draw_null_cursor ;стираем курсор
1552
      inc tl_cur_pos
1553
 
1554
    cmp tl_p_scrol,0 ;if not scrol struct
1555
    je @f
1556
    call tl_get_rows_count ;eax = rows count
1557
    mov ebx,tl_p_scrol
1558
    add eax,dword[ebx+24] ;.position +24
1559
    cmp tl_cur_pos,eax
1560
    jl @f
1561
      inc dword[ebx+24] ;.position +24
1562
      push dword ebx
1563
      mov edi,tl_sb_draw ;перерисовка скроллинга
1564
      call dword[edi]
1565
 
1566
      mov edi,dword[ebp+8] ;restore edi
1567
      push dword edi
1568
      call tl_draw ;полная перерисовка окна
1569
      jmp .no_redraw
1570
    @@:
1571
      mov edi,dword[ebp+8] ;restore edi
1572
      call tl_draw_cursor ;перерисовка курсора
1285 IgorA 1573
      call tl_draw_caption_cur_pos
1277 IgorA 1574
    .no_redraw:
1575
  pop esi edi ebx eax
1576
  pop ebp
1577
  ret 4
1578
 
1579
 
1580
;input:
1581
; edi = pointer 'tl' struct
1582
;output:
1583
; eax = struct index of current node
1584
align 4
1585
tl_get_node_count: ;берет число всех видимых узлов (не считая закрытых дочерних)
1586
  push ecx edx
1587
    ;cycle to nodes
1588
    xor eax,eax
1283 IgorA 1589
    mov edx,tl_data_nodes
1277 IgorA 1590
    mov ecx,edx
1591
    add ecx,sizeof.TreeList
1592
    @@:
1593
      call tl_iterat_next
1594
      cmp edx,ecx
1595
      jle @f
1596
      inc eax
1597
      jmp @b
1598
    @@:
1599
  pop edx ecx
1600
  ret
1601
 
1602
align 4
1603
tl_cur_perv: ;перенести курсор на 1 позицию выше
1604
  push ebp
1605
  mov ebp,esp
1606
  push eax edi esi
1607
    mov edi,dword[ebp+8]
1608
    cmp tl_cur_pos,0
1609
    je .no_redraw
1610
      mov esi,tl_box_top
1611
      add esi,tl_box_height ;esi = coord bottom border
1612
      call tl_draw_null_cursor ;стираем курсор
1613
      dec tl_cur_pos ;двигаем курсор вверх
1614
 
1615
    cmp tl_p_scrol,0 ;если есть указатель на скроллинг
1616
    je @f
1617
    mov eax,tl_p_scrol
1618
    cmp dword[eax+24],0 ;если скроллинг на верху, выходим
1619
    je @f
1620
    mov edi,tl_cur_pos
1621
    cmp edi,dword[eax+24] ;если курсор ушел выше скроллинга, тогда опускаем скроллинг
1622
    jge @f
1623
      dec dword[eax+24]
1624
      push dword eax
1625
      mov edi,dword[ebp+8]
1626
      mov edi,tl_sb_draw ;.redraw
1627
      call dword[edi]
1628
      mov edi,dword[ebp+8] ;restore edi
1629
      push dword edi
1630
      call tl_draw ;полная перерисовка окна
1631
      jmp .no_redraw
1632
    @@:
1633
      mov edi,dword[ebp+8] ;restore edi
1634
      ;mov esi,tl_box_top
1635
      ;add esi,tl_box_height ;esi = coord bottom border
1636
      call tl_draw_cursor ;перерисовка курсора
1285 IgorA 1637
      call tl_draw_caption_cur_pos
1277 IgorA 1638
    .no_redraw:
1639
  pop esi edi eax
1640
  pop ebp
1641
  ret 4
1642
 
1643
align 4
1644
tl_node_close_open: ;открыть/закрыть узел (работает с узлами которые имеют дочерние узлы)
1645
  push ebp
1646
  mov ebp,esp
1647
  push eax edx edi
1648
    mov edi,dword[ebp+8]
1649
    call tl_get_cur_node_index ;eax = позиция узла на котором стоит курсор
1650
    cmp eax,2 ;курсор стоит на узле ?
1651
    jl @f
1652
      imul eax,sizeof.TreeList
1283 IgorA 1653
      add eax,tl_data_nodes
1277 IgorA 1654
      ;eax = указатель на структуру узла выбранного курсором
1655
      push dword edi
1656
      push dword eax
1657
      call tl_node_poi_get_next_info
1658
      pop dword edx ;edx = указатель на структуру узла который идет после узла eax
1659
      cmp edx,0 ;есть ли узлы ниже выбранного нами ?
1660
      je @f
1661
	mov dl,byte[edx+2] ;берем уровень нижнего узла
1662
	cmp byte[eax+2],dl ;+2 = .lev
1663
	jge @f ;если нижние узлы меньшего уровня, значит они не дочерние, конец функции
1664
	  xor byte[eax+3],1 ;+3 = .clo *** открытие/закрытие узла ***
1665
	  call tb_scrol_resize ;обработка скроллинга
1666
 
1667
	  push dword edi
1668
	  call tl_draw ;обновление окна
1669
    @@:
1670
  pop edi edx eax
1671
  pop ebp
1672
  ret 4
1673
 
1674
align 4
1675
tl_node_lev_inc: ;увеличить уровень
1676
  push ebp
1677
  mov ebp,esp
1678
  push eax edx edi
1679
    mov edi,dword[ebp+8]
1680
    bt tl_style,2 ;tl_list_box_mode
1681
    jc @f
1682
    call tl_get_cur_node_index ;eax=po_t
1683
    cmp eax,2
1684
    jl @f
1685
      imul eax,sizeof.TreeList
1283 IgorA 1686
      add eax,tl_data_nodes
1277 IgorA 1687
      mov edx,eax
1688
      inc word[edx+2]
1689
    @@:
1690
  pop edi edx eax
1691
  pop ebp
1692
  ret 4
1693
 
1694
align 4
1695
tl_node_lev_dec: ;уменьшить уровень
1696
  push ebp
1697
  mov ebp,esp
1698
  push eax edx edi
1699
    mov edi,dword[ebp+8]
1700
    call tl_get_cur_node_index ;eax=po_t
1701
    cmp eax,2
1702
    jl @f
1703
      imul eax,sizeof.TreeList
1283 IgorA 1704
      add eax,tl_data_nodes
1277 IgorA 1705
      mov edx,eax
1706
      cmp word[edx+2],0
1707
      je @f
1708
      dec word[edx+2]
1709
    @@:
1710
  pop edi edx eax
1711
  pop ebp
1712
  ret 4
1713
 
1285 IgorA 1714
align 4
1715
tl_node_move_up: ;перемещаем узел вверх
1716
  push ebp
1717
  mov ebp,esp
1718
  push eax ebx ecx edx edi esi
1719
    mov edi,dword[ebp+8]
1720
    call tl_get_cur_node_index ;eax=po_t
1721
    cmp eax,2
1722
    jl @f
1723
      mov ebx,eax ;copy index of node struct
1724
      mov edx,tl_data_nodes
1725
      mov ecx,edx
1726
      add ecx,sizeof.TreeList
1727
      imul eax,sizeof.TreeList
1728
      add eax,edx ;eax = pointer to 2 node struct
1729
      mov edx,eax ;edx = pointer to 2 node struct
1730
      mov esi,eax ;esi = pointer to 2 node struct
1731
      call tl_iterat_perv ;edx = pointer to 1 node struct
1732
      call tl_get_node_index ;eax = index of 1 node struct
1733
      cmp edx,ecx
1734
      jle @f
1735
        cmp dword[edx+8],ebx ;+8 next
1736
        jne .po8
1737
          call tl_node_move_po6 ;узлы идут подряд меняем 6 ссылок
1738
          jmp .cur_mov
1739
        .po8:
1740
          call tl_node_move_po8 ;узлы идут не подряд меняем 8 ссылок
1741
        .cur_mov:
1742
          push dword edi
1743
          call tl_cur_perv
1744
          push dword edi
1745
          call tl_draw
1746
    @@:
1747
  pop esi edi edx ecx ebx eax
1748
  pop ebp
1749
  ret 4
1750
 
1751
align 4
1752
tl_node_move_down: ;перемещаем узел вниз
1753
  push ebp
1754
  mov ebp,esp
1755
  push eax ebx ecx edx edi esi
1756
    mov edi,dword[ebp+8]
1757
    call tl_get_cur_node_index ;eax=po_t
1758
    cmp eax,2
1759
    jl @f
1760
      mov ebx,eax ;copy index of node struct
1761
      mov edx,tl_data_nodes
1762
      mov ecx,edx
1763
      add ecx,sizeof.TreeList
1764
      imul eax,sizeof.TreeList
1765
      add eax,edx ;eax = pointer to 1 node struct
1766
      mov edx,eax ;edx = pointer to 1 node struct
1767
      mov esi,eax ;esi = pointer to 1 node struct
1768
      call tl_iterat_next ;edx = pointer to 2 node struct
1769
      call tl_get_node_index ;eax = index of 2 node struct
1770
      cmp edx,ecx
1771
      jle @f
1772
        cmp dword[esi+8],eax ;+8 next
1773
        jne .po8
1774
          xchg eax,ebx ;меняе порядок следования заменяемых узлов
1775
          xchg edx,esi
1776
          call tl_node_move_po6 ;узлы идут подряд меняем 6 ссылок
1777
          jmp .cur_mov
1778
        .po8: ;а тут порядок следования узлов не меняем
1779
          call tl_node_move_po8 ;узлы идут не подряд меняем 8 ссылок
1780
        .cur_mov:
1781
          push dword edi
1782
          call tl_cur_next
1783
          push dword edi
1784
          call tl_draw
1785
    @@:
1786
  pop esi edi edx ecx ebx eax
1787
  pop ebp
1788
  ret 4
1789
 
1790
align 4
1791
tl_node_move_po6:
1792
  mov ecx,edx ;save node pointer
1793
  call tl_move_perv
1794
  mov dword[edx+8],ebx
1795
 
1796
  mov edx,esi
1797
  call tl_move_next
1798
  mov dword[edx+4],eax
1799
  mov edx,ecx ;restore node pointer
1800
 
1801
  ;+4 perv
1802
  mov ecx,dword[edx+4]
1803
  mov dword[esi+4],ecx
1804
  ;+8 next
1805
  mov ecx,dword[esi+8]
1806
  mov dword[edx+8],ecx
1807
 
1808
  mov dword[edx+4],ebx
1809
  mov dword[esi+8],eax
1810
  ret
1811
 
1812
;input
1813
;eax = index 1 node struct
1814
;ebx = index 2 node struct
1815
;edx = pointer 1 node struct
1816
;esi = pointer 2 node struct
1817
;edi = pointer to 'TreeList' struct
1818
;output:
1819
;eax = ?
1820
;ebx = ?
1821
;ecx = ?
1822
align 4
1823
tl_node_move_po8:
1824
;  push ecx
1825
  mov ecx,edx ;save node pointer
1826
  call tl_move_perv
1827
  mov dword[edx+8],ebx
1828
  mov edx,ecx
1829
  call tl_move_next
1830
  mov dword[edx+4],ebx
1831
  mov edx,esi
1832
  call tl_move_perv
1833
  mov dword[edx+8],eax
1834
  mov edx,esi
1835
  call tl_move_next
1836
  mov dword[edx+4],eax
1837
  mov edx,ecx ;restore node pointer
1838
;  pop ecx
1839
 
1840
  ;+4 perv
1841
  mov eax,dword[edx+4]
1842
  mov ebx,dword[esi+4]
1843
  xchg eax,ebx
1844
  mov dword[edx+4],eax
1845
  mov dword[esi+4],ebx
1846
  ;+8 next
1847
  mov eax,dword[edx+8]
1848
  mov ebx,dword[esi+8]
1849
  xchg eax,ebx
1850
  mov dword[edx+8],eax
1851
  mov dword[esi+8],ebx
1852
  ret
1853
 
1854
;input:
1855
; edi = pointer to 'TreeList' struct
1856
align 4
1857
tl_draw_caption_cur_pos:
1858
  cmp tl_capt_cy,9 ;9 - minimum caption height
1859
  jl @f
1860
  push eax ebx ecx edx edi esi
1861
    mov eax,47 ;draw
1862
    mov ebx,0x40000
1863
    mov ecx,tl_cur_pos
1864
    inc ecx
1865
    mov edx,tl_box_left
1866
    shl edx,16
1867
    add edx,50*65536+3
1868
    add edx,tl_box_top
1869
    mov esi,tl_col_txt
1870
    or  esi,0x40000000 ;закрашивать фон цветом edi
1871
    mov edi,tl_col_zag
1872
    int 0x40
1873
  pop esi edi edx ecx ebx eax
1874
  @@:
1875
  ret
1876
 
1277 IgorA 1877
txt_capt_cur db '‘ва®Є ',0
1878
txt_capt_otm db 'Ћв¬Ґ­л',0
1879
}