home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v17n03 / oopasm.exe / EDITWIN.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-07-11  |  8.1 KB  |  328 lines

  1.     .MODEL    SMALL
  2.  
  3.     INCLUDE    equates.inc
  4.     INCLUDE    instance.inc
  5.     INCLUDE    messages.inc
  6.     INCLUDE    objects.inc
  7.  
  8.     MaxSize        EQU    BufSize-10    ;Maximum number of characters
  9.     WindowWidth    EQU    29        ;Column width of edit window
  10.     ScrollCols    EQU    WindowWidth-4    ;Number of columns to scroll
  11.  
  12. IF1
  13.     INCLUDE    macros.mac
  14.     INCLUDE    objects.mac
  15. ENDIF
  16.  
  17.     EXTRN    disCharacter:NEAR
  18.     EXTRN    makeActive:NEAR
  19.     EXTRN    sendMsg:NEAR
  20.  
  21.     EXTRN    Buffer:WORD
  22.     EXTRN    Cursor:WORD
  23.     EXTRN    Dispatch:WORD
  24.     EXTRN    Keyboard:WORD
  25.     EXTRN    Self:WORD
  26.     EXTRN    SBorder:WORD
  27.     EXTRN    Window:WORD
  28.  
  29.     .CODE
  30.  
  31. IF Dbug
  32.     PUBLIC    initEditWinVars
  33. ENDIF
  34. COMMENT    %
  35. ==============================================================================
  36. Sets EditWin's instance variables with values handed down from the master.
  37.  
  38. =============================================================================%
  39. initEditWinVars    PROC    NEAR
  40.     push        Self
  41.     getInst$    ch,Row1,MasterObj    ;Get upper row from master
  42.     getInst        cl,Col1            ;Get left column
  43.     getInst        dh,Row2            ;Get lower row
  44.     getInst        dl,Col2            ;Get right column
  45.  
  46.     add        ch,RowOffset        ;Add in row offset
  47.     add        ch,RowOffset        ;Add in row offset
  48.     mov        dh,ch
  49.     add        dh,2
  50.     add        cl,ColOffset        ;Add in column offset
  51.     add        cl,ColOffset        ;Add in column offset
  52.     mov        dl,cl
  53.     add        dl,WindowWidth+4
  54.  
  55.     setInst        Row1,ch,EditWin        ;Set upper row
  56.     setInst        Col1,cl            ;Set left column
  57.     setInst        Row2,dh            ;Set lower row
  58.     setInst        Col2,dl            ;Set right column
  59.     setInst        InxPtr,0,,2        ;Clear char count
  60.  
  61.     inc        ch
  62.     setInst        Row1,ch,Cursor        ;Set cursor row
  63.     add        cl,ColOffset        ;Add in column offset
  64.     setInst        Col1,cl            ;Set cursor column
  65.     pop        Self
  66.     ret
  67. initEditWinVars    ENDP
  68.  
  69.  
  70.  
  71. COMMENT    %
  72. ==============================================================================
  73. Displays an ASCII character, or performs a function based on the last key
  74. event.
  75.  
  76. =============================================================================%
  77. handleEvent    PROC    NEAR
  78.     getInst        ah,ScanCode,Keyboard    ;Get scan code
  79.     null        ah,hdl1            ;Invalid key - Exit
  80.  
  81.     getInst        al,AsciiCode        ;Get char code
  82.     moreThan    al,126,hdl1        ;> 126? - Exit
  83.     lessThan    al,32,hdl2        ;< 32? - Check if command
  84.     call        disChar            ;Display if char
  85.     jmp        hdl1
  86.  
  87. hdl2:    call        processCmd        ;Process if command
  88. hdl1:    ret
  89. handleEvent    ENDP
  90.  
  91.  
  92.  
  93. COMMENT    %
  94. ==============================================================================
  95. Processes keyboard commands based on ASCII and scan codes for EditWin.
  96.  
  97. Passed:    al - Character code
  98.  
  99. =============================================================================%
  100. processCmd    PROC    NEAR
  101.     lea        si,EditWinDispTbl    ;Get addr of dispatch tbl
  102. pcmd1:    eq        al,Bptr[si],pcmd2    ;Match ASCII code? - Exit loop
  103.     add        si,3            ;Else - Point to next entry
  104.     identity    Bptr[si],pcmd1        ;More? - Keep looking
  105. pcmd2:    call        Wptr[si+1]        ;Call procedure
  106.     ret
  107. processCmd    ENDP
  108.  
  109.  
  110.  
  111. COMMENT    %
  112. ==============================================================================
  113. Displays an ASCII character in the EditWindow.
  114.  
  115. Passed:    al - Character code
  116.  
  117. =============================================================================%
  118. disChar    PROC    NEAR
  119.     call        getInstVars        ;Get instance variables
  120.     neq        cx,MaxSize,dchr1    ;Room in buffer? - Skip
  121.     call        invalidKey        ;Else - Alert user
  122.     jmp        dchr3            ;Exit
  123.  
  124. dchr1:    add        di,cx            ;Point to end of buffer
  125.     mov        Bptr[di],bh        ;Save new char there
  126.     mov        Bptr[di+1],0        ;Save zero in next position
  127.     inc        cx            ;Increment char count
  128.     setInst        InxPtr,cx        ;Save new count
  129.  
  130.     getInst        dl,Col1,Cursor        ;Get cursor column
  131.     neq        dl,al,dchr2        ;Not at edge? - Skip
  132.     push        si            ;Else - Save obj ptr
  133.     send        Self,ScrollLeft,ScrollCols
  134.     pop        si            ;Restore obj ptr
  135.  
  136. dchr2:    call        disCharacter        ;Display character
  137.     inc        dl            ;Increment column
  138.     setInst        Col1,dl            ;Update cursor column
  139. dchr3:    ret
  140. disChar    ENDP
  141.  
  142.  
  143.  
  144. COMMENT    %
  145. ==============================================================================
  146. Returns important EditWindow instance variables.
  147.  
  148. Passed:    al - Character code
  149.  
  150. Passes:    ax - Lower/Right row/column
  151.     bh - Character code
  152.     bl - Color
  153.     cx - Character count
  154.     di - Text input buffer pointer
  155.     dx - Upper/Left row/column
  156.  
  157. =============================================================================%
  158. getInstVars    PROC    NEAR
  159.     getInst        dh,Row1,Self        ;Get upper row
  160.     inc        dh            ;Increment row
  161.     getInst        dl,Col1            ;Get left column
  162.     add        dl,ColOffset        ;Add in column offset
  163.  
  164.     getInst        bl,Color        ;Get color
  165.     mov        bh,al            ;Pass char code in bh
  166.  
  167.     getInst        ah,Row2            ;Get lower row
  168.     dec        ah
  169.     getInst        al,Col2            ;Get right column
  170.     sub        al,ColOffset        ;Subtract column offset
  171.  
  172.     getInst        cx,InxPtr        ;Get character count
  173.     getInst        di,TxtPtr        ;Get text input buffer addr
  174.     ret
  175. getInstVars    ENDP
  176.  
  177.  
  178.  
  179. IF Dbug
  180.     PUBLIC    backSpace
  181. ENDIF
  182. COMMENT    %
  183. ==============================================================================
  184. Deletes the character to left of cursor scring if necessary.
  185.  
  186. =============================================================================%
  187. backSpace    PROC    NEAR
  188.     call        getInstVars        ;Get instance variables
  189.     notZero        cx,bksp1        ;Chars in buffer? - Skip
  190.     call        invalidKey        ;Else - Alert user
  191.     jmp        bksp3            ;Exit
  192.  
  193. bksp1:    dec        cx            ;Decrement char count
  194.     setInst        InxPtr,cx        ;Save new count
  195.     add        di,cx            ;Point to last char in buffer
  196.     mov        Bptr[di],0        ;Replace with a zero
  197.  
  198.     mov        al,dl            ;Get left column
  199.     getInst        dl,Col1,Cursor        ;Get cursor column
  200.     dec        dl            ;Decrement column
  201.     setInst        Col1,dl            ;Update cursor column
  202.     neq        dl,al,bksp2        ;Not at edge? - Skip
  203.     send        Self,ScrollRight,ScrollCols
  204.  
  205. bksp2:    mov        bh,Space        ;Pass blank character
  206.     call        disCharacter        ;Display character
  207. bksp3:    ret
  208. backSpace    ENDP
  209.  
  210.  
  211.  
  212. COMMENT    %
  213. ==============================================================================
  214. Scrolls a line of text to the left.
  215.  
  216. Passed:    StackTop - Number of columns to scroll
  217.  
  218. =============================================================================%
  219. scrLeft    PROC    NEAR
  220.     call        getInstVars        ;Get instance variables
  221.     add        di,cx            ;Point to end of text
  222.     sub        di,WindowWidth        ;Point to 1st char in window
  223.     getStackArgs    cx            ;Get #columns to scroll
  224.     add        di,cx            ;Point to new 1st char
  225.     mov        ax,WindowWidth        ;Calculate loop count
  226.     sub        ax,cx
  227.     mov        cx,ax
  228.  
  229. scrl1:    mov        bh,Bptr[di]        ;Get character
  230.     call        disCharacter        ;Display it
  231.     inc        dl            ;Next column
  232.     inc        di            ;Next character
  233.     loop        scrl1
  234.  
  235.     dec        dl
  236.     setInst        Col1,dl,Cursor        ;Update cursor position
  237.     ret
  238. scrLeft    ENDP
  239.  
  240.  
  241.  
  242. IF Dbug
  243.     PUBLIC    scrRight
  244. ENDIF
  245. COMMENT    %
  246. ==============================================================================
  247. Scrolls a line of text to the right.
  248.  
  249. Passed:    StackTop - Number of columns to scroll
  250.  
  251. =============================================================================%
  252. scrRight    PROC    NEAR
  253.     call        getInstVars        ;Get instance variables
  254.     zero        cx,scrr2        ;No chars in buffer? - Exit
  255.  
  256.     add        di,cx            ;Point to end of text
  257.     getStackArgs    ax            ;Get #columns to scroll
  258.     lessThan    cx,ax,scrr3        ;Not enough chars? - Skip
  259.     mov        cx,ax            ;Set up loop counter
  260. scrr3:    sub        di,cx            ;Point to 1st char in window
  261.  
  262. scrr1:    mov        bh,Bptr[di]        ;Get character
  263.     call        disCharacter        ;Display it
  264.     inc        dl            ;Next column
  265.     inc        di            ;Next character
  266.     loop        scrr1
  267.  
  268.     setInst        Col1,dl,Cursor        ;Update cursor position
  269. scrr2:    ret
  270. scrRight    ENDP
  271.  
  272.  
  273.  
  274. COMMENT    %
  275. ==============================================================================
  276. Alerts user as to invalid input.
  277.  
  278. =============================================================================%
  279. invalidKey    PROC    NEAR
  280.     push        Self
  281.     send        Dispatch,Update        ;Alert user
  282.     pop        Self
  283.     ret
  284. invalidKey    ENDP
  285.  
  286.  
  287.  
  288.     .DATA
  289.  
  290. EditWinDispTbl    LABEL    WORD
  291.     DB    008
  292.     DW    OFFSET backSpace
  293.     DB    Nil
  294.     DW    OFFSET invalidKey
  295.  
  296. defMsg    EditWin,\
  297.     Refresh,\
  298.     <initEditWinVars,,>
  299.  
  300. defMsg    EditWin,\
  301.     Read,\
  302.     <handleEvent,,makeActive>
  303.  
  304. defMsg    EditWin,\
  305.     ScrollLeft,\
  306.     <,,scrLeft>
  307.  
  308. defMsg    EditWin,\
  309.     ScrollRight,\
  310.     <,,scrRight>
  311.  
  312. defObj    EditWin,\
  313.     <Window,SBorder>,\
  314.     <Row1,1,11,\
  315.     Col1,1,17,\
  316.     Row2,1,13,\
  317.     Col2,1,36,\
  318.     Color,1,34h,\
  319.     Unused,1,Nil,\
  320.     TxtPtr,2,Buffer,\
  321.     InxPtr,2,0,\
  322.     MasterObj,2,Nil>,\
  323.     <Refresh,Read,ScrollLeft,ScrollRight>
  324.  
  325.  
  326.  
  327.     END
  328.