Subversion Repositories Kolibri OS

Rev

Rev 6026 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2018. All rights reserved.    ;;
  4. ;; Distributed under terms of the GNU General Public License       ;;
  5. ;;                                                                 ;;
  6. ;;   Written by hidnplayr@kolibrios.org                            ;;
  7. ;;                                                                 ;;
  8. ;;         GNU GENERAL PUBLIC LICENSE                              ;;
  9. ;;          Version 2, June 1991                                   ;;
  10. ;;                                                                 ;;
  11. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12.  
  13. ; window_create_textbox
  14. ; Initialises the data structure for our multiline textbox
  15. ;
  16. ; in:   window ptr in ebx
  17. ; out:  eax = 0 on error
  18. ;       ecx, edi = destroyed
  19.  
  20. window_create_textbox:
  21.  
  22.         push    ebx
  23. ; allocate the window data block
  24.         mcall   68, 12, sizeof.window_data
  25.         test    eax, eax
  26.         pop     ebx
  27.         jz      .fail
  28.  
  29. ; fill it with all zeros
  30.         push    eax
  31.         mov     edi, eax
  32.         mov     ecx, (sizeof.window_data+3)/4
  33.         xor     eax, eax
  34.         rep stosd
  35.         pop     eax
  36.  
  37.         mov     [ebx + window.data_ptr], eax
  38.         mov     [ebx + window.flags], FLAG_SCROLL_LOW
  39.  
  40.         add     eax, window_data.text+2         ; let text begin at offset 2, this way the text will be prepended with two null bytes
  41.         mov     [ebx + window.text_start], eax
  42.         mov     [ebx + window.text_print], eax
  43.         mov     [ebx + window.text_write], eax
  44.         mov     [ebx + window.text_scanned], eax
  45.         mov     [ebx + window.text_lines], 0
  46.         mov     [ebx + window.text_line_print], 0
  47.         add     eax, TEXT_BUFFERSIZE-1
  48.         mov     [ebx + window.text_end], eax
  49.  
  50.   .fail:
  51.         ret
  52.  
  53.  
  54. ; window_set_name
  55. ; Fills in the window name in window structure
  56. ;
  57. ; IN:   esi = ptr to name
  58. ;       ebx = window ptr
  59. ; OUT:  esi = ptr to next parameter
  60. ;       ebx = window ptr
  61. ;       eax, ecx, edx, edi = destroyed
  62.  
  63. window_set_name:
  64.  
  65.         lea     edi, [ebx + window.name]
  66.         mov     ecx, MAX_WINDOWNAME_LEN
  67.   .loop:
  68.         lodsb
  69.         cmp     al, 0x21        ; name ends with 0, space or !
  70.         jbe     .addzero
  71.         stosb
  72.         dec     ecx
  73.         jnz     .loop
  74.   .addzero:
  75.         xor     al, al
  76.         stosb
  77.  
  78.         push    esi ebx
  79.         call    draw_window_tabs
  80.         pop     ebx esi
  81.  
  82.         ret
  83.  
  84. window_close_all:
  85.  
  86.   .loop:
  87.         call    window_close
  88.  
  89.         cmp     [window_print], 0
  90.         jne     .loop
  91.  
  92.         ret
  93.  
  94.  
  95. window_close:   ; closes the 'print' window
  96.  
  97. ; Remove the window (overwrite current structure with trailing ones)
  98.         mov     edi, [window_print]
  99.         push    [edi + window.data_ptr]         ; remember data ptr so we can free it later
  100.         lea     esi, [edi + sizeof.window]
  101.         mov     ecx, windows + MAX_WINDOWS*sizeof.window
  102.         sub     ecx, esi
  103.         rep movsb
  104.  
  105. ; Completely zero the trailing window block (there will always be one!)
  106.         mov     ecx, sizeof.window
  107.         xor     al, al
  108.         rep stosb
  109.  
  110. ; Clear the window data block to erase the chat history and nicknames
  111.         mov     edi, [esp]
  112.         mov     ecx, sizeof.window_data         ; TEXT_BUFFERSIZE + MAX_NICK_LEN * MAX_USERS
  113.         rep stosb
  114.  
  115. ; And now free the window data block
  116.         pop     ecx
  117.         mcall   68, 13
  118.  
  119. ; We closed this window so we need to show another
  120.         ; Is there still a window in the active position?
  121.         mov     edi, [window_active]
  122.         cmp     [edi + window.data_ptr], 0
  123.         jne     .redraw
  124.         ; Did we just close the last window?
  125.         cmp     edi, windows
  126.         je      .closed_last
  127.         ; Nope, move one window to the left
  128.         sub     edi, sizeof.window
  129.         mov     [window_active], edi
  130.         mov     [window_print], edi
  131.         jmp     .redraw
  132.  
  133.   .closed_last:
  134.         xor     edi, edi
  135.         mov     [window_active], edi
  136.         mov     [window_print], edi
  137.  
  138. ; At last, redraw everything
  139.   .redraw:
  140.         call    draw_window
  141.  
  142.         ret
  143.  
  144.  
  145. ; window_find:
  146. ; search for a window with given name in the window list
  147. ;
  148. ; IN:   esi = ptr to start of window name
  149. ; OUT:  ebx = window ptr, or 0 if none found
  150. ;       esi = ptr to end of window name, if window was found
  151.  
  152. window_find:
  153.  
  154.         mov     ebx, windows
  155.         mov     eax, MAX_WINDOWS
  156.   .scanloop:
  157.         push    esi
  158.         cmp     [ebx + window.type], WINDOWTYPE_NONE
  159.         je      .try_next
  160.         lea     edi, [ebx + window.name]
  161.         mov     ecx, MAX_WINDOWNAME_LEN
  162.         repe    cmpsb
  163.         cmp     byte[edi-1], 0          ; last equall character was null? yes, the strings match!
  164.         je      .got_it
  165.         cmp     byte[edi], 0            ; we're at the end of string1.. ?
  166.         jne     .try_next
  167.         cmp     byte[esi], 0x21         ; and the end of string2? yes!
  168.         jbe     .got_it
  169.   .try_next:
  170.         pop     esi
  171.         add     ebx, sizeof.window
  172.         dec     eax
  173.         jnz     .scanloop
  174.  
  175.         xor     ebx, ebx
  176.         ret
  177.  
  178.   .got_it:
  179.         add     esp, 4
  180.         ret
  181.  
  182.  
  183.  
  184. ; window_open:
  185. ; open a window with a given name, if it does not exist, create it
  186. ; This procedure only affects window_print ptr, not window_active!
  187. ;
  188. ; IN:   esi = ptr to ASCIIZ windowname
  189. ; OUT:  esi = ptr to next parameter
  190. ;       ebx = window ptr/0 on error
  191.  
  192. window_open:
  193.  
  194. ; Skip heading spaces
  195.         lodsb
  196.         cmp     al, ' '
  197.         je      window_open
  198.         cmp     al, ':'
  199.         je      window_open
  200.         dec     esi
  201.  
  202.         call    window_find
  203.         test    ebx, ebx
  204.         jnz     .got_it
  205.  
  206. ; create channel window - search for empty slot
  207.   .create_it:
  208.         mov     ebx, windows
  209.         mov     ecx, MAX_WINDOWS
  210.   .scanloop2:
  211.         cmp     [ebx + window.type], WINDOWTYPE_NONE
  212.         je      .free_found
  213.         add     ebx, sizeof.window
  214.         dec     ecx
  215.         jnz     .scanloop2
  216.         jmp     .error
  217.  
  218.   .free_found:
  219.         call    window_create_textbox
  220.         test    eax, eax
  221.         jz      .error
  222.         mov     [ebx + window.type], WINDOWTYPE_CHAT    ; FIXME: let caller handle this ?
  223.  
  224.         call    window_set_name
  225.  
  226.   .got_it:
  227.         lodsb
  228.         cmp     al, ' '
  229.         je      .got_it
  230.         cmp     al, ':'
  231.         je      .got_it
  232.         dec     esi
  233.  
  234.         mov     [window_print], ebx
  235.         ret
  236.  
  237.   .error:
  238.         xor     ebx, ebx
  239.         ret