Box lib tree list

来自KolibriOS wiki
跳到导航 跳到搜索

Functions

  • tl_data_init - Element constructor, must be called before using the item to allocate memory and other settings.
  • tl_data_clear - Деструктор элемента, чистит память по указателям: data_info, data_nodes, data_img и data_img_sys. Если в программе используется несколько элементов с одинаковыми иконками, то указатели data_img и data_img_sys нужно приравнять к 0 в других элементах, так что-бы при вызове деструкторов не было повторного удаления одних и тех же иконок.
  • tl_info_clear - Clearing the list of all nodes. You can not undo with tl_info_undo.
  • tl_key - Function that should be called when you press on the keyboard. Buttons that are not available if there is tl_key_no_edit style: [Enter], [Delete], [←], [→]. Always available: [↑], [↓], [Page Up], [Page Dn], [Space]. The function checks whether the scan code is enabled, and if necessary, converts the code itself.
  • tl_mouse - Function for mouse events.
  • tl_draw - draw tree list.
  • tl_info_undo - Отменяет добавление узлов. Действует только на весь узел целиком, не учитывая изменения внутри узлов. Т. е. нельзя отменить действия выполненные например функциями: tl_node_set_data, tl_node_lev_inc и им подобным.
  • tl_info_redo - Повтор отмененных действий. Обратная функция по отношению к tl_info_undo.
  • tl_node_add - Adds a node to the position indicated by the cursor. Example of adding a node:
  stdcall dword[tl_node_add], tree1, 0x10002, data_buffer

where: tree1 - tree_list structure; 0x10002 - site settings (upper bytes of 0x0001 - index icon type that is displayed next to the node; a smaller byte 0x02 - level of nesting); data_buffer - pointer to the data to add.

  • tl_node_set_data - sets the new data (user and signature) of the node under the cursor.
  • tl_node_get_data - returns a pointer to the data (user and signature) of the node under the cursor.
  • tl_node_delete - удаляет узел, но не окончательно, при необходимости узел можно вернуть функцией tl_info_undo.
  • tl_cur_beg - puts the cursor at the top of the list, if you want to rewind the scroll.
  • tl_cur_next - moves the cursor one position lower.
  • tl_cur_perv - moves the cursor one position higher.
  • tl_node_close_open - Opens or closes the parent node. If this node has no child elements, it does nothing. Automatically redraws the screen if the host state has changed.
  • tl_node_lev_inc - Increments level of nesting of the node.
  • tl_node_lev_dec - Decrements level of nesting of the node.
  • tl_node_move_up - Moves up the node under the cursor. Example:
  push dword tree1
  call dword[tl_node_move_up]

where: tree1 - tree_list structure

  • tl_node_move_down

moves down the node under the cursor. Example:

  push dword tree1
  call dword[tl_node_move_down]

where: tree1 - tree_list structure

  • tl_node_poi_get_info - Get the internal pointer to a structure describing the node. Example:
stdcall dword[tl_node_poi_get_info], tree1, 0

where: tree1 - tree_list structure; 0 - node position at which the pointer is taken; the eax - a pointer to a structure describing the node.

  • tl_node_poi_get_next_info - берет указатель на следующий элемент в цепи, без учета открытия/закрытия дочерних узлов.
  • tl_node_poi_get_data - берет указатель на данные (пользовательские и подпись) из узла указанного в указателе.

Функциями tl_node_poi_get_info, tl_node_poi_get_next_info и tl_node_poi_get_data можно считывать информацию о узлах элемента, при этом не меняя текущего положения курсора. Т. е. можно организовать доступ к данным элемента в "фоновом режиме".

  • tl_save_mem - Сохраняет информацию об узлах элемента в память. Пример использования функции:
  MEM_SIZE equ 5000
  node_data rb MEM_SIZE
.........
  stdcall dword[tl_save_mem], tree1, 0, node_data, MEM_SIZE

где: tree1 - структура tree_list; 0 - опция сохранения в начало блока памяти (если = 1, то добавляет элемент после других сохраненных ранее); node_data - указатель на блок памяти; MEM_SIZE - размер блока памяти для сохранения. В регистр eax пишется значение 0 или записываются коды ошибок сохранения.

  • tl_load_mem - Загружает информацию об узлах элемента из памяти. Пример использования функции:
  MEM_SIZE equ 5000
  node_data rb MEM_SIZE
.........
  stdcall dword[tl_load_mem], tree1, 0, node_data, MEM_SIZE

где: tree1 - структура tree_list; 0 - индекс считываемого элемента; node_data - указатель на блок памяти; MEM_SIZE - размер блока памяти для сохранения. В регистр eax пишется значение 0 или записываются коды ошибок считывания.

  • tl_get_mem_size - Вычисляет размер блока памяти (в который были раньше сохранены элементы). Эту функцию можно использовать перед сохранением на диск, для получения точного размера сохраняемых данных.
  • version_tree_list - version element

tree_list structure

struc tree_list info_size,info_max_count,style, img_cx,img_cy,\
    col_bkg,col_zag,col_txt, box_l,box_t,box_w,box_h, capt_cy,info_capt_offs,\
    info_capt_len,el_focus, p_scrol,on_press {
  .box_left   dd box_l
  .box_top    dd box_t
  .box_width  dd box_w
  .box_height dd box_h
  .data_info  dd 0
  .info_size  dw info_size
  .info_max_count dd info_max_count
  .style      dd style
  .data_nodes dd 0
  .data_img   dd 0
  .img_cx     dw img_cx
  .img_cy     dw img_cy
  .data_img_sys dd 0
  .ch_tim     dd 0
  .tim_undo   dd 0
  .cur_pos    dd 0
  .col_bkg    dd col_bkg
  .col_zag    dd col_zag
  .col_txt    dd col_txt
  .capt_cy    dw capt_cy
  .info_capt_offs dw info_capt_offs
  .info_capt_len  dw info_capt_len
  .el_focus    dd el_focus
  .p_scrol     dd p_scrol
  .on_press    dd on_press
}
  • info_size - the number of bytes that will be allocated for each node. Part of this memory, the user can use for their own purposes (regulated through info_capt_offs and info_capt_len) and the rest will be used as a node signature.
  • info_max_count - the maximum number of nodes that can be added to an element.
  • style - style element.
  • data_nodes - указатель на внутренние структуры узлов (TreeList).
  • data_img - указатель на изображения с иконками узлов. Формат изображения такой же как и в сист. ф. 7: BBGGRRBBGGRR....
  • img_cx - width of a single icon.
  • img_cy - the height of a single icon.
  • data_img_sys - указатель на системные изображения (курсор, плюсики, линии, ... все кроме иконок узлов). Формат изображения такой же как и в сист. ф. 7: BBGGRRBBGGRR...
  • col_bkg - background color.
  • col_zag - the color of the title bar (if specified) and the buttons and slider to the vertical scroll bar (if any).
  • col_txt - the color of the text.
  • capt_cy - высота строки для подписи вверху элемента, если меньше 9 подпись не выводится.
  • info_capt_len - длинна текста для подписи. Если равно 0, то длинна считается так: info_size - info_capt_offs.
  • p_scrol - a pointer to the scroll structure associated with the item.
  • on_press - a pointer to a function that will be called by pressing [Enter]. If the index is equal to 0 then nothing will be called.

Example of creating a structure:

tree1 tree_list 24,500, tl_draw_par_line+tl_list_box_mode, 16,16,\
    0x8080ff,0x0000ff,0xffffff, 10,35,200-16,285, 14,4,0,\
    el_focus, wScr,fun_on_enter

Style elements

  • tl_key_no_edit

The element can not be edited on the keyboard (to change levels, delete). Put this style if you want to create an item to view the data.

  • tl_draw_par_line

Рисовать линии к родительскому узлу.

  • tl_list_box_mode

The style does not display the levels (as in the ListBox all nodes are of the same level).

Example

To compile include the full path to SVN directory. The program uses two icon files tl_sys_16.bmp and tl_nod_16.bmp from programs\develop\libraries\box_lib\trunk. The files macros.inc, proc32.inc, etc. can be found in programs directory.

use32                  ; use 32-bit command
; standard header
    db 'MENUET01'      ; signature
    dd 1               ; header version
    dd start           ; entry point
    dd i_end           ; initialized size
    dd mem             ; required memory
    dd stacktop        ; stack pointer
    dd file_name       ; parameters
    dd cur_dir_path    ; path
 
include 'macros.inc'
include 'proc32.inc'
include 'box_lib.mac'
include 'load_lib.mac'
include 'dll.inc' ;for mem.Alloc,mem.Free,mem.ReAlloc
 
@use_library_mem mem.Alloc,mem.Free,mem.ReAlloc,0
 
struct FileInfoBlock
    Function dd ?
    Position dd ?
    Flags    dd ?
    Count    dd ?
    Buffer   dd ?
             db ?
    FileName dd ?
ends
 
fn_icon1 db 'tl_sys_16.bmp',0
fn_icon2 db 'tl_nod_16.bmp',0
bmp_icon dd 0
run_file_70 FileInfoBlock
 
align 4
start:
    ; load libraries
    stdcall dll.Load, @IMPORT_BOXLIB
    test    eax, eax
    jnz     exit
 
    mcall 48,3,sc,sizeof.system_colors
    mcall 40,0x27 ;mask anticipated events
    mcall 68,11
 
    stdcall dword[tl_data_init], tree1
 
; read * .bmp file system icons
    copy_path fn_icon1,cur_dir_path,file_name,0
 
    mov ecx,3*256*13
    stdcall mem.Alloc,ecx
    mov [bmp_icon],eax
 
    mov [run_file_70.Buffer], eax
    mov [run_file_70.Function], 0
    mov [run_file_70.Position], 54
    mov [run_file_70.Flags], 0
    mov [run_file_70.Count], ecx
    mov byte[run_file_70+20], 0
    mov [run_file_70.FileName], file_name
    mcall 70,run_file_70
    cmp ebx,0
    jl @f
        m2m dword[tree1.data_img_sys],dword[bmp_icon]
    @@:
 
; read * .bmp file with the icon of nodes
    copy_path fn_icon2,cur_dir_path,file_name,0
 
    mov ecx,3*256*13
    stdcall mem.Alloc,ecx
    mov [bmp_icon],eax
 
    mov [run_file_70.Buffer], eax
    ;mov [run_file_70.Function], 0
    ;mov [run_file_70.Position], 54
    ;mov [run_file_70.Flags], 0
    mov [run_file_70.Count], ecx
    mov byte[run_file_70+20], 0
    mov [run_file_70.FileName], file_name
    mcall 70,run_file_70
    cmp ebx,0
    jl @f
        m2m dword[tree1.data_img],dword[bmp_icon]
    @@:
 
;Redraw the window
align 4
red_win:
    mcall 12,1
 
    xor eax,eax ; draw window
    mov ebx,30*65536+320
    mov ecx,25*65536+255
    mov edx,[sc.work]
    or  edx,0x33000000
    mov edi,hed
    mcall
 
    ; buttons
    mov eax,8
    mov ebx,215*65536+85
    mov ecx,5*65536+15
    mov edx,2
    mov esi,[sc.work_button]
    int 0x40
 
    mov ebx,215*65536+60
    mov ecx,25*65536+15
    mov edx,3
;  mov esi,0xffd000
    int 0x40
 
    mov ebx,215*65536+85
    mov ecx,45*65536+15
    mov edx,4
    int 0x40
 
    mov ecx,65*65536+15
    mov edx,5
    int 0x40
 
    mov ecx,85*65536+15
    mov edx,6
    int 0x40
 
    mov ecx,105*65536+15
    mov edx,7
    int 0x40
 
    mov ecx,125*65536+15
    mov edx,8
    int 0x40
 
    mov ecx,145*65536+15
    mov edx,9
    int 0x40
 
    mov ecx,165*65536+15
    mov edx,10
    int 0x40
 
    mov ecx,185*65536+15
    mov edx,11
    int 0x40
 
    mov ecx,205*65536+15
    mov edx,12
    int 0x40
 
    mov ebx,280*65536+20
    mov ecx,25*65536+15
    mov edx,100
    mov esi,0xd0d0
    int 0x40
 
    mov eax,4 ;drawing text
    mov ebx,10*65536+25
    mov ecx,[sc.work_button_text]
    or  ecx,0x80000000
    mov edx,dword[node_data]
    int 0x40
 
    mov eax,4 ;drawing text on buttons
    mov ebx,220*65536+10
    mov edx,txt10
    int 0x40
 
    mov ebx,220*65536+30
    mov edx,txt11
    int 0x40
 
    mov ebx,220*65536+50
    mov edx,txt12
    int 0x40
 
    mov ebx,220*65536+70
    mov edx,txt13
    int 0x40
 
    mov ebx,220*65536+90
    mov edx,txt14
    int 0x40
 
    mov ebx,220*65536+110
    mov edx,txt15
    int 0x40
 
    mov ebx,220*65536+130
    mov edx,txt16
    int 0x40
 
    mov ebx,220*65536+150
    mov edx,txt17
    int 0x40
 
    mov ebx,220*65536+170
    mov edx,txt18
    int 0x40
 
    mov ebx,220*65536+190
    mov edx,txt19
    int 0x40
 
    mov ebx,220*65536+210
    mov edx,txt20
    int 0x40
 
    stdcall dword[tl_draw], tree1
    stdcall [edit_box_draw], dword edit1
 
    mov dword[wScr.all_redraw],1
    stdcall [scrollbar_ver_draw], dword wScr
 
    mcall 12,2

    jmp still

 
align 4
still:
    mcall 10
 
    cmp al, 1 ;change in window position
    jz  red_win
    cmp al, 2
    jz  key
    cmp al, 3
    jz  button
    cmp al, 6
    jz  mouse
    jmp still
 
align 4
key:
    mcall 2
    stdcall [tl_key], tree1
    stdcall [edit_box_key], dword edit1
    jmp still
 
align 4
button:
    mcall 17 ;get the code of the pressed button
    cmp ah,2
    jz  but_clear
    cmp ah,3
    jz  but_add_node
    cmp ah,4
    jz  but_undo
    cmp ah,5
    jz  but_redo
    cmp ah,6
    jz  but_lev_add
    cmp ah,7
    jz  but_lev_dec
    cmp ah,8
    jz  but_node_set_data
    cmp ah,9
    jz  but_node_get_data
    cmp ah,10
    jz  but_node_delete
    cmp ah,11
    jz  but_node_move_up
    cmp ah,12
    jz  but_node_move_down
    cmp ah,100
    jz  but_add_node_2
 
    cmp ah,1
    jne still

exit:
;  stdcall mem.Free,[bmp_icon]
    stdcall dword[tl_data_clear], tree1
    mcall -1 ;выход из программы
 
 
align 4
mouse:
    stdcall [tl_mouse], tree1
    stdcall [edit_box_mouse], dword edit1
    jmp still
 
but_clear:
    stdcall dword[tl_info_clear], tree1
    stdcall dword[tl_draw], tree1
    jmp still
 
; Add a node (the icon which is at index 0)
but_add_node:
    stdcall dword[tl_node_add], tree1, 0, ed_buffer
    stdcall dword[tl_draw], tree1
    jmp still
 
; Add a node (the icon which is at index 1)
but_add_node_2:
    stdcall dword[tl_node_add], tree1, 0x10000, ed_buffer
    stdcall dword[tl_draw], tree1
    jmp still
 
but_undo:
  stdcall dword[tl_info_undo], tree1
  stdcall dword[tl_draw], tree1
  jmp still
 
but_redo:
  stdcall dword[tl_info_redo], tree1
  stdcall dword[tl_draw], tree1
  jmp still
 
but_lev_add:
  stdcall dword[tl_node_lev_inc], tree1
  stdcall dword[tl_draw], tree1
  jmp still
 
but_lev_dec:
  stdcall dword[tl_node_lev_dec], tree1
  stdcall dword[tl_draw], tree1
  jmp still
 
; We set the (new) unit data
but_node_set_data:
    stdcall dword[tl_node_set_data], tree1, ed_buffer
    stdcall dword[tl_draw], tree1
    jmp still

; Take a pointer to the node data
but_node_get_data:
push eax
    stdcall dword[tl_node_get_data], tree1
    mov dword[node_data], eax
pop eax
    jmp red_win ;still
 
; Remove the node
but_node_delete:
  stdcall dword[tl_node_delete], tree1
  stdcall dword[tl_draw], tree1
  jmp still
 
; Function to call when you press [Enter]
align 4
fun_on_enter:
    stdcall dword[tl_node_set_data], tree1, txt_on_enter
    stdcall dword[tl_draw], tree1
    ret
 
but_node_move_up:
  stdcall dword[tl_node_move_up], tree1
  jmp still
 
but_node_move_down:
  stdcall dword[tl_node_move_down], tree1
  jmp still
 
;подписи на кнопки
txt10 db 'List Clear',0
txt11 db 'Node add',0
txt12 db 'List Undo',0
txt13 db 'List Redo',0
txt14 db 'Node lev >>',0
txt15 db 'Node lev <<',0
txt16 db 'Node set data',0
txt17 db 'Node get data',0
txt18 db 'Node delete',0
txt19 db 'Node move ',24,0 ;24 up
txt20 db 'Node move ',25,0 ;25 down
 
; A table of imported functions
align 4
@IMPORT_BOXLIB:

library box_lib, 'box_lib.obj'

import  box_lib, \
        edit_box_draw,      'edit_box', \
        edit_box_key,       'edit_box_key', \
        edit_box_mouse,     'edit_box_mouse', \
        version_ed,         'version_ed', \
        scrollbar_ver_draw ,'scrollbar_v_draw', \
        scrollbar_ver_mouse,'scrollbar_v_mouse', \
        scrollbar_hor_draw, 'scrollbar_h_draw', \
        scrollbar_hor_mouse,'scrollbar_h_mouse', \
        version_scrollbar,  'version_scrollbar', \
        tl_info_undo,       'tl_info_undo', \
        tl_info_redo,       'tl_info_redo', \
        tl_node_lev_inc,    'tl_node_lev_inc', \
        tl_node_lev_dec,    'tl_node_lev_dec', \
        tl_node_move_up,    'tl_node_move_up', \
        tl_node_move_down,  'tl_node_move_down', \
        tl_data_init,       'tl_data_init', \
        tl_data_clear,      'tl_data_clear', \
        tl_info_clear,      'tl_info_clear', \
        tl_key,             'tl_key', \
        tl_mouse,           'tl_mouse', \
        tl_draw,            'tl_draw', \
        tl_node_add,        'tl_node_add', \
        tl_node_set_data,   'tl_node_set_data', \
        tl_node_get_data,   'tl_node_get_data', \
        tl_node_delete,     'tl_node_delete', \
        tl_cur_beg,         'tl_cur_beg', \
        tl_cur_next,        'tl_cur_next', \
        tl_cur_perv,        'tl_cur_perv', \
        tl_node_close_open, 'tl_node_close_open' 
 
; Element structure tree_list
tree1 tree_list 24,500, tl_draw_par_line, 16,16, 0x8080ff,0x0000ff,0xffffff,\
    10,35,200-16,185, 14,4,0, el_focus, wScr,fun_on_enter
 
; A subsidiary structure for scrolling
align 4
wScr:
.x:
.size_x     dw 16 ;+0
.start_x    dw 210-16 ;+2
.y:
.size_y     dw 185 ;+4
.start_y    dw 35 ;+6
.btn_high   dd 15 ;+8
.type       dd 1  ;+12
.max_area   dd 100  ;+16
.cur_area   dd 30  ;+20
.position   dd 0  ;+24
.bckg_col   dd 0xeeeeee ;+28
.frnt_col   dd 0xbbddff ;+32
.line_col   dd 0  ;+36
.redraw     dd 0  ;+40
.delta      dw 0  ;+44
.delta2     dw 0  ;+46
.run_x:
.r_size_x   dw 0  ;+48
.r_start_x  dw 0  ;+50
.run_y:
.r_size_y   dw 0 ;+52
.r_start_y  dw 0 ;+54
.m_pos      dd 0 ;+56
.m_pos_2    dd 0 ;+60
.m_keys     dd 0 ;+64
.run_size   dd 0 ;+68
.position2  dd 0 ;+72
.work_size  dd 0 ;+76
.all_redraw dd 0 ;+80
.ar_offset  dd 1 ;+84
 
; Element structure editbox
edit1 edit_box 200, 10, 5, 0xffffff, 0x80ff, 0xff0080, 0, 0xff, 80, ed_buffer, mouse_dd, ed_focus, 13, 13
ed_buffer: db 'dataNode Text',0
    rb 69
 
txt_on_enter db '1111Enter',0
hed db 'tree_list example',0
 
;-------------------------------------------------------------------------------
node_data dd 0
el_focus dd tree1
mouse_dd dd ?   
 
i_end: ;the end of the executable file
    sc system_colors
    rb 2048
stacktop:
    cur_dir_path rb 4096
    library_path rb 4096
    file_name rb 4096
mem: