Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2014. 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], 0
  39.         or      [ebx + window.flags], FLAG_SCROLL_LOW
  40.  
  41.         add     eax, window_data.text+2         ; let text begin at offset 2, this way the text will be prepended with two null bytes
  42.         mov     [ebx + window.text_start], eax
  43.         mov     [ebx + window.text_print], eax
  44.         mov     [ebx + window.text_write], eax
  45.         mov     [ebx + window.text_scanned], eax
  46.         mov     [ebx + window.text_lines], 0
  47.         mov     [ebx + window.text_line_print], 0
  48.         add     eax, TEXT_BUFFERSIZE-1
  49.         mov     [ebx + window.text_end], eax
  50.  
  51.   .fail:
  52.         ret
  53.  
  54.  
  55. ; window_set_name
  56. ; Fills in the window name in window structure
  57. ;
  58. ; IN:   esi = ptr to name
  59. ;       ebx = window ptr
  60. ; OUT:  esi = ptr to next parameter
  61. ;       ebx = window ptr
  62. ;       eax, ecx, edx, edi = destroyed
  63.  
  64. window_set_name:
  65.  
  66.         lea     edi, [ebx + window.name]
  67.         mov     ecx, MAX_WINDOWNAME_LEN
  68.   .loop:
  69.         lodsb
  70.         cmp     al, 0x21        ; name ends with 0, space or !
  71.         jbe     .addzero
  72.         stosb
  73.         dec     ecx
  74.         jnz     .loop
  75.   .addzero:
  76.         xor     al, al
  77.         stosb
  78.  
  79.         push    esi ebx
  80.         call    draw_windowtabs
  81.         pop     ebx esi
  82.  
  83.         ret
  84.  
  85.  
  86. window_close:   ; closes the 'print' window
  87.  
  88. ; Remove the window (overwrite current structure with trailing ones)
  89.         mov     edi, [window_print]
  90.         push    [edi + window.data_ptr]         ; remember data ptr so we can free it later
  91.         lea     esi, [edi + sizeof.window]
  92.         mov     ecx, windows + MAX_WINDOWS*sizeof.window
  93.         sub     ecx, esi
  94.         rep     movsb
  95.  
  96. ; Completely zero the trailing window block (there will always be one!)
  97.         mov     ecx, sizeof.window
  98.         xor     al, al
  99.         rep     stosb
  100.  
  101. ; free the window data block
  102.         pop     ecx
  103.         mcall   68, 13
  104.  
  105. ; We closed this window so we need to show another
  106.         mov     edi, [window_active]
  107.         cmp     [edi + window.data_ptr], 0
  108.         jne     @f
  109.         sub     edi, sizeof.window
  110.         mov     [window_active], edi
  111.         mov     [window_print], edi  ;;;;;;;;
  112.   @@:
  113.  
  114. ; At last, redraw everything
  115.         call    draw_window
  116.  
  117.         ret
  118.  
  119.  
  120. ; window_find:
  121. ; search for a window with given name in the window list
  122. ;
  123. ; IN:   esi = ptr to start of window name
  124. ; OUT:  ebx = window ptr, or 0 if none found
  125. ;       esi = ptr to end of window name, if window was found
  126.  
  127. window_find:
  128.  
  129.         mov     ebx, windows
  130.         mov     eax, MAX_WINDOWS
  131.   .scanloop:
  132.         push    esi
  133.         cmp     [ebx + window.type], WINDOWTYPE_NONE
  134.         je      .try_next
  135.         lea     edi, [ebx + window.name]
  136.         mov     ecx, MAX_WINDOWNAME_LEN
  137.         repe    cmpsb
  138.         cmp     byte[edi-1], 0          ; last equall character was null? yes, the strings match!
  139.         je      .got_it
  140.         cmp     byte[edi], 0            ; we're at the end of string1.. ?
  141.         jne     .try_next
  142.         cmp     byte[esi], 0x21         ; and the end of string2? yes!
  143.         jbe     .got_it
  144.   .try_next:
  145.         pop     esi
  146.         add     ebx, sizeof.window
  147.         dec     eax
  148.         jnz     .scanloop
  149.  
  150.         xor     ebx, ebx
  151.         ret
  152.  
  153.   .got_it:
  154.         add     esp, 4
  155.         ret
  156.  
  157.  
  158.  
  159. ; window_open:
  160. ; open a window with a given name, if it does not exist, create it
  161. ; This procedure only affects window_print ptr, not window_active!
  162. ;
  163. ; IN:   esi = ptr to ASCIIZ windowname
  164. ; OUT:  esi = ptr to next parameter
  165. ;       ebx = window ptr/0 on error
  166.  
  167. window_open:
  168.  
  169. ; Skip heading spaces
  170.         lodsb
  171.         cmp     al, ' '
  172.         je      window_open
  173.         cmp     al, ':'
  174.         je      window_open
  175.         dec     esi
  176.  
  177.         call    window_find
  178.         test    ebx, ebx
  179.         jnz     .got_it
  180.  
  181. ; create channel window - search for empty slot
  182.   .create_it:
  183.         mov     ebx, windows
  184.         mov     ecx, MAX_WINDOWS
  185.   .scanloop2:
  186.         cmp     [ebx + window.type], WINDOWTYPE_NONE
  187.         je      .free_found
  188.         add     ebx, sizeof.window
  189.         dec     ecx
  190.         jnz     .scanloop2
  191.         jmp     .error
  192.  
  193.   .free_found:
  194.         call    window_create_textbox
  195.         test    eax, eax
  196.         jz      .error
  197.         mov     [ebx + window.type], WINDOWTYPE_CHAT    ; FIXME: let caller handle this ?
  198.  
  199.         call    window_set_name
  200.  
  201.   .got_it:
  202.         lodsb
  203.         cmp     al, ' '
  204.         je      .got_it
  205.         cmp     al, ':'
  206.         je      .got_it
  207.         dec     esi
  208.  
  209.         mov     [window_print], ebx
  210.         ret
  211.  
  212.   .error:
  213.         xor     ebx, ebx
  214.         ret