home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a013 / 1.ddi / SOURCE.EXE / F_MMOCTL.PRG < prev    next >
Encoding:
Text File  |  1991-01-25  |  5.1 KB  |  173 lines

  1. *****************************************************************
  2. FUNCTION MEMOCTRL (mode, line, col)
  3. *****************************************************************
  4.  
  5. * Generic control function for MEMOVIEW or MEMOEDIT
  6.  
  7. * Copyright(c) 1991 - James Occhiogrosso
  8.  
  9. #include "setcurs.ch"
  10. #include "set.ch"
  11. #include "inkey.ch"
  12. #include "dl_keys.ch"
  13. #define  WORDWRAP  34
  14. #define  SAVEMEMO  23
  15. #define  ABORT     27
  16. #define  IGNORE    32
  17.  
  18.  
  19. LOCAL ret_value, keypress, message, spacing, ;
  20.       old_color, old_cursor, memo_scr, line_24
  21.  
  22. STATIC counter := 1
  23.  
  24. ret_value = 0
  25.  
  26. * Initialize undefined parameters
  27.  
  28. format = IF(format == NIL, .T., format)
  29.  
  30. * If logic variable "altered" is pre-defined, it is set 
  31. * when the memo is changed. Otherwise, it is used locally
  32.  
  33. IF TYPE('altered') != 'L'
  34.     PRIVATE altered
  35. ENDIF
  36. altered = .F.
  37.  
  38. IF mode = 3
  39.     * Initialize MEMOEDIT and test for a word_wrap toggle
  40.  
  41.     IF TYPE("word_wrap") = 'L' .AND. counter = 1
  42.         IF .NOT. word_wrap
  43.             * Return code to toggle word wrap off
  44.             ret_value = WORDWRAP
  45.             counter = 0
  46.         ENDIF
  47.     ENDIF
  48.  
  49. ELSEIF mode = 0
  50.  
  51.     * Idling mode - waiting for next key press.
  52.     IF format
  53.         * Write current line and column information
  54.         @ top, left + 2 SAY " Line     Col    "
  55.         @ top, left + 8 SAY LTRIM(STR(line))
  56.         @ top, left + 16 SAY LTRIM(STR(col))
  57.     ENDIF
  58.  
  59. ELSE
  60.     * Keystroke exception. Get key value.
  61.     keypress = LASTKEY()
  62.  
  63.     IF keypress = K_CTRL_W .OR. keypress = K_CTRL_ENTER
  64.         * User pressed ctrl-enter or ctrl-W. Save and exit
  65.         IF mode = 2
  66.             * User made changes. Set altered variable.
  67.             altered = .T.
  68.         ENDIF
  69.         ret_value = SAVEMEMO
  70.  
  71.     ELSEIF keypress = K_ESC
  72.         * User pressed Esc. Check for changes
  73.  
  74.         IF mode = 2
  75.              * User made changes. Confirm that abort is desired.
  76.              message = ' Abandon Edits? (Y/N) '
  77.  
  78.              IF format .OR. TYPE('aed_row') = 'U'
  79.  
  80.                  * If aed_row is not defined, operator is using 
  81.                  * MEMOCTRL without AEDBAR. Place message at 
  82.                  * bottom of window area.
  83.  
  84.                  spacing = (((right - left)-2) - LEN(message))/2
  85.                  @ bottom, left + 1 SAY REPLICATE('─',spacing) +;
  86.                        message + '  ' + REPLICATE('─', spacing-2)
  87.  
  88.                  * Reposition cursor to end of message
  89.                  @ bottom, left + spacing + LEN(message)+1 SAY ''
  90.  
  91.              ELSE
  92.                  AEDMSG(message)
  93.              ENDIF
  94.  
  95.              * Get the operator response
  96.              IF OPCONFIRM()
  97.                   * Abandon the edit
  98.                   ret_value = ABORT
  99.              ELSE
  100.                   * Operator pressed Esc in error, ignore it
  101.                   altered = .T.
  102.                   ret_value = IGNORE
  103.  
  104.              ENDIF
  105.         ENDIF
  106.  
  107.     ELSEIF keypress = K_INS
  108.  
  109.         * User pressed Ctrl-V or Ins key. Toggle cursor
  110.         * size and display insert "on/off" status.
  111.  
  112.         CSRINSERT()
  113.         IF format
  114.             @ top, right-4 SAY IF(READINSERT(), "on ", "off")
  115.         ENDIF
  116.  
  117.         * Tell MEMOEDIT to ignore this key
  118.         ret_value = IGNORE
  119.  
  120.     ELSEIF (keypress <= -2 .OR. keypress > 256 ;
  121.            .OR. keypress = K_F1) .AND. TYPE('fkeyset') != 'U'
  122.  
  123.         * Call special keys procedure if any function key or
  124.         * alternate key combination is pressed. The variable,
  125.         * "fkeyset" must contain the procedure name.
  126.  
  127.         IF .NOT. EMPTY(fkeyset)
  128.             DO &fkeyset WITH 'MEMOCTRL', 0, READVAR(), keypress
  129.         ENDIF
  130.  
  131.  
  132.     ELSEIF keypress = K_F2
  133.  
  134.         * Display key definition help for the user
  135.  
  136.         memo_scrn = SCRNSAVE(3, 50, 20, 79)
  137.         line_24   = SCRNSAVE(24, 0, 24, 79)
  138.         old_color = SETCOLOR(colstd)
  139.         CENTERON(24, hitanykey)
  140.         SETCOLOR(colwindow)
  141.         old_cursor = SET(_SET_CURSOR, SC_NONE)
  142.  
  143.         @  3, 50 SAY '┌────────────────────────────┐'
  144.         @  4, 50 SAY '│      Memo Editing Keys     │'
  145.         @  5, 50 SAY '├────────────────────────────┤'
  146.         @  6, 50 SAY '│Esc .............. Exit memo│'
  147.         @  7, 50 SAY '│Ctrl-Enter ....... Save memo│'
  148.         @  8, 50 SAY '│Ins........... Insert on/off│'
  149.         @  9, 50 SAY '│Enter(Ins on)... Insert line│'
  150.         @ 10, 50 SAY '│Enter(Ins off).... Next line│'
  151.         @ 11, 50 SAY '│Ctrl-B.......... Reform para│'
  152.         @ 12, 50 SAY '│Del............. Delete char│'
  153.         @ 13, 50 SAY '│BackSpace..... Del char left│'
  154.         @ 14, 50 SAY '│Ctrl-T....... Del word right│'
  155.         @ 15, 50 SAY '│Ctrl-Y.......... Delete line│'
  156.         @ 16, 50 SAY '│Arrow keys ..... move cursor│'
  157.         @ 17, 50 SAY '│Pgup/Pgdn ..... window up/dn│'
  158.         @ 18, 50 SAY '│Home/End .... window top/bot│'
  159.         @ 19, 50 SAY '│Crtl-Pgup/Pgdn..memo top/bot│'
  160.         @ 20, 50 SAY '└────────────────────────────┘'
  161.         INKEY(0)
  162.         SETCOLOR(old_color)
  163.         SCRNREST(memo_scrn)
  164.         SCRNREST(line_24)
  165.         SETCURSOR(old_cursor)
  166.  
  167.     ENDIF
  168. ENDIF
  169.  
  170. RETURN ret_value
  171.  
  172.  
  173.