Subversion Repositories Kolibri OS

Rev

Rev 4060 | Rev 4477 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2013. 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.  
  14. ; in:  window ptr in ebx
  15. ; out: eax = 0 on error
  16. window_create:
  17.  
  18.         push    ebx
  19. ; allocate the window data block
  20.         mcall   68, 12, sizeof.window_data
  21.         test    eax, eax
  22.         pop     ebx
  23.         jz      .fail
  24.  
  25. ; fill it with all zeros
  26.         push    eax
  27.         mov     edi, eax
  28.         mov     ecx, (sizeof.window_data+3)/4
  29.         xor     eax, eax
  30.         rep     stosd
  31.         pop     eax
  32.  
  33.         mov     [ebx + window.data_ptr], eax
  34.         mov     [ebx + window.flags], 0
  35.  
  36.         add     eax, window_data.text+1         ; let text begin at offset 1, this way the text will be prepended with a 0
  37.         mov     [ebx + window.text_start], eax
  38.         mov     [ebx + window.text_print], eax
  39.         mov     [ebx + window.text_write], eax
  40.         mov     [ebx + window.text_scanned], eax
  41.         mov     [ebx + window.text_lines], 0
  42.         mov     [ebx + window.text_line_print], 0
  43.         add     eax, TEXT_BUFFERSIZE-1
  44.         mov     [ebx + window.text_end], eax
  45.  
  46.   .fail:
  47.         ret
  48.  
  49.  
  50. window_set_name:    ; esi = ptr to name, ebx = window ptr
  51.  
  52.         pusha
  53.  
  54. ; Skip heading spaces
  55.   .spaceloop:
  56.         cmp     byte[esi], ' '
  57.         jne     .done
  58.         inc     esi
  59.         jmp     .spaceloop
  60.   .done:
  61.  
  62. ; Now copy it
  63.         lea     edi, [ebx + window.name]
  64.         mov     ecx, MAX_WINDOWNAME_LEN
  65.   .loop:
  66.         lodsb
  67.         cmp     al, 0x21
  68.         jbe     .addzero
  69.         stosb
  70.         dec     ecx
  71.         jnz     .loop
  72.   .addzero:
  73.         xor     al, al
  74.         stosb
  75.  
  76.         call    draw_windowtabs         ; redraw it
  77.  
  78.         popa
  79.  
  80.         ret
  81.  
  82.  
  83.  
  84. window_is_updated:
  85.  
  86.         mov     edi, [window_print]
  87.         cmp     edi, [window_active]
  88.         je      .skip
  89.         test    [edi + window.flags], FLAG_UPDATED
  90.         jnz     .skip
  91.         or      [edi + window.flags], FLAG_UPDATED
  92.  
  93. ; TODO: make some noise
  94.  
  95.         call    draw_windowtabs         ; highlight updated tabs
  96.   .skip:
  97.  
  98.         ret
  99.  
  100.  
  101.  
  102. window_close:   ; closes the 'print' window
  103.  
  104. ; Remove the window (overwrite current structure with trailing ones)
  105.         mov     edi, [window_print]
  106.         push    [edi + window.data_ptr]         ; remember data ptr so we can free it later
  107.         lea     esi, [edi + sizeof.window]
  108.         mov     ecx, windows + MAX_WINDOWS*sizeof.window
  109.         sub     ecx, esi
  110.         rep     movsb
  111.  
  112. ; Completely zero the trailing window block (there will always be one!)
  113.         mov     ecx, sizeof.window
  114.         xor     al, al
  115.         rep     stosb
  116.  
  117. ; free the window data block
  118.         pop     ecx
  119.         mcall   68, 13
  120.  
  121. ; We closed this window so we need to show another
  122.         mov     edi, [window_active]
  123.         cmp     [edi + window.data_ptr], 0
  124.         jne     @f
  125.         sub     edi, sizeof.window
  126.         mov     [window_active], edi
  127.         mov     [window_print], edi  ;;;;;;;;
  128.   @@:
  129.  
  130. ; At last, redraw everything
  131.         call    draw_window
  132.  
  133.         ret
  134.  
  135.  
  136.  
  137. window_find:    ; esi = window name
  138. ; search for window in list
  139.         mov     ebx, windows
  140.         mov     [window_print], ebx     ; set first window (server window) as default output window
  141.         mov     eax, MAX_WINDOWS
  142.   .scanloop:
  143.         push    esi
  144.         cmp     [ebx + window.type], WINDOWTYPE_NONE
  145.         je      .try_next
  146.         lea     edi, [ebx + window.name]
  147.         mov     ecx, MAX_WINDOWNAME_LEN
  148.         repe    cmpsb
  149.         cmp     byte[edi-1], 0
  150.         jne     .try_next
  151.         cmp     byte[esi-1], 0
  152.         je      .got_it
  153.         cmp     byte[esi-1], 10
  154.         je      .got_it
  155.         cmp     byte[esi-1], 13
  156.         je      .got_it
  157.         cmp     byte[esi-1], ' '
  158.         je      .got_it
  159.   .try_next:
  160.         pop     esi
  161.         add     ebx, sizeof.window
  162.         dec     eax
  163.         jnz     .scanloop
  164.  
  165.         xor     ebx, ebx
  166.         ret
  167.  
  168.   .got_it:
  169.         pop     esi                 ;;; TODO: dont reset ESI  ?
  170.         mov     [window_print], ebx
  171.         ret
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178. ; open a window with a given name, if it does not exist, create it
  179. ; This procedure only affects window_print ptr, not window_active!
  180. ;
  181. ; esi = ptr to ASCIIZ windowname
  182. window_open:
  183.  
  184.         push    esi
  185.  
  186.         mov     edi, esi
  187.         call    compare_to_nick
  188.         jne     .nochat
  189.  
  190.         mov     esi, servercommand+1
  191.   .nochat:
  192.  
  193.         call    window_find
  194.         test    ebx, ebx
  195.         jne     .got_it
  196.  
  197. ; create channel window - search for empty slot
  198.   .create_it:
  199.         mov     ebx, windows
  200.         mov     ecx, MAX_WINDOWS
  201.   .scanloop2:
  202.         cmp     [ebx + window.data_ptr], 0
  203.         je      .free_found
  204.         add     ebx, sizeof.window
  205.         dec     ecx
  206.         jnz     .scanloop2
  207. ; Error: no more available windows!
  208.         jmp     .got_it ; TODO: return error
  209.  
  210.   .free_found:
  211.         call    window_create
  212.         test    eax, eax
  213.         jz      .got_it ; TODO: return error
  214.         mov     [ebx + window.type], WINDOWTYPE_CHAT    ; FIXME: let caller handle this ?
  215.  
  216.         call    window_set_name
  217.         mov     [window_print], ebx
  218.  
  219.         call    draw_windowtabs
  220.  
  221.   .got_it:
  222.         pop     esi
  223.   .skip1:
  224. ; skip text
  225.         lodsb
  226.         test    al, al
  227.         jz      .quit
  228.         cmp     al, ' '
  229.         jne     .skip1
  230.         dec     esi
  231. ; now skip trailing spaces and semicolons
  232.   .skip2:
  233.         lodsb
  234.         test    al, al
  235.         jz      .quit
  236.         cmp     al, ' '
  237.         je      .skip2
  238.         cmp     al, ':'
  239.         je      .skip2
  240.         dec     esi
  241.  
  242.   .quit:
  243.         ret