home *** CD-ROM | disk | FTP | other *** search
- *****************************************************************
- FUNCTION MEMOCTRL (mode, line, col)
- *****************************************************************
-
- * Generic control function for MEMOVIEW or MEMOEDIT
-
- * Copyright(c) 1991 - James Occhiogrosso
-
- #include "setcurs.ch"
- #include "set.ch"
- #include "inkey.ch"
- #include "dl_keys.ch"
- #define WORDWRAP 34
- #define SAVEMEMO 23
- #define ABORT 27
- #define IGNORE 32
-
-
- LOCAL ret_value, keypress, message, spacing, ;
- old_color, old_cursor, memo_scr, line_24
-
- STATIC counter := 1
-
- ret_value = 0
-
- * Initialize undefined parameters
-
- format = IF(format == NIL, .T., format)
-
- * If logic variable "altered" is pre-defined, it is set
- * when the memo is changed. Otherwise, it is used locally
-
- IF TYPE('altered') != 'L'
- PRIVATE altered
- ENDIF
- altered = .F.
-
- IF mode = 3
- * Initialize MEMOEDIT and test for a word_wrap toggle
-
- IF TYPE("word_wrap") = 'L' .AND. counter = 1
- IF .NOT. word_wrap
- * Return code to toggle word wrap off
- ret_value = WORDWRAP
- counter = 0
- ENDIF
- ENDIF
-
- ELSEIF mode = 0
-
- * Idling mode - waiting for next key press.
- IF format
- * Write current line and column information
- @ top, left + 2 SAY " Line Col "
- @ top, left + 8 SAY LTRIM(STR(line))
- @ top, left + 16 SAY LTRIM(STR(col))
- ENDIF
-
- ELSE
- * Keystroke exception. Get key value.
- keypress = LASTKEY()
-
- IF keypress = K_CTRL_W .OR. keypress = K_CTRL_ENTER
- * User pressed ctrl-enter or ctrl-W. Save and exit
- IF mode = 2
- * User made changes. Set altered variable.
- altered = .T.
- ENDIF
- ret_value = SAVEMEMO
-
- ELSEIF keypress = K_ESC
- * User pressed Esc. Check for changes
-
- IF mode = 2
- * User made changes. Confirm that abort is desired.
- message = ' Abandon Edits? (Y/N) '
-
- IF format .OR. TYPE('aed_row') = 'U'
-
- * If aed_row is not defined, operator is using
- * MEMOCTRL without AEDBAR. Place message at
- * bottom of window area.
-
- spacing = (((right - left)-2) - LEN(message))/2
- @ bottom, left + 1 SAY REPLICATE('─',spacing) +;
- message + ' ' + REPLICATE('─', spacing-2)
-
- * Reposition cursor to end of message
- @ bottom, left + spacing + LEN(message)+1 SAY ''
-
- ELSE
- AEDMSG(message)
- ENDIF
-
- * Get the operator response
- IF OPCONFIRM()
- * Abandon the edit
- ret_value = ABORT
- ELSE
- * Operator pressed Esc in error, ignore it
- altered = .T.
- ret_value = IGNORE
-
- ENDIF
- ENDIF
-
- ELSEIF keypress = K_INS
-
- * User pressed Ctrl-V or Ins key. Toggle cursor
- * size and display insert "on/off" status.
-
- CSRINSERT()
- IF format
- @ top, right-4 SAY IF(READINSERT(), "on ", "off")
- ENDIF
-
- * Tell MEMOEDIT to ignore this key
- ret_value = IGNORE
-
- ELSEIF (keypress <= -2 .OR. keypress > 256 ;
- .OR. keypress = K_F1) .AND. TYPE('fkeyset') != 'U'
-
- * Call special keys procedure if any function key or
- * alternate key combination is pressed. The variable,
- * "fkeyset" must contain the procedure name.
-
- IF .NOT. EMPTY(fkeyset)
- DO &fkeyset WITH 'MEMOCTRL', 0, READVAR(), keypress
- ENDIF
-
-
- ELSEIF keypress = K_F2
-
- * Display key definition help for the user
-
- memo_scrn = SCRNSAVE(3, 50, 20, 79)
- line_24 = SCRNSAVE(24, 0, 24, 79)
- old_color = SETCOLOR(colstd)
- CENTERON(24, hitanykey)
- SETCOLOR(colwindow)
- old_cursor = SET(_SET_CURSOR, SC_NONE)
-
- @ 3, 50 SAY '┌────────────────────────────┐'
- @ 4, 50 SAY '│ Memo Editing Keys │'
- @ 5, 50 SAY '├────────────────────────────┤'
- @ 6, 50 SAY '│Esc .............. Exit memo│'
- @ 7, 50 SAY '│Ctrl-Enter ....... Save memo│'
- @ 8, 50 SAY '│Ins........... Insert on/off│'
- @ 9, 50 SAY '│Enter(Ins on)... Insert line│'
- @ 10, 50 SAY '│Enter(Ins off).... Next line│'
- @ 11, 50 SAY '│Ctrl-B.......... Reform para│'
- @ 12, 50 SAY '│Del............. Delete char│'
- @ 13, 50 SAY '│BackSpace..... Del char left│'
- @ 14, 50 SAY '│Ctrl-T....... Del word right│'
- @ 15, 50 SAY '│Ctrl-Y.......... Delete line│'
- @ 16, 50 SAY '│Arrow keys ..... move cursor│'
- @ 17, 50 SAY '│Pgup/Pgdn ..... window up/dn│'
- @ 18, 50 SAY '│Home/End .... window top/bot│'
- @ 19, 50 SAY '│Crtl-Pgup/Pgdn..memo top/bot│'
- @ 20, 50 SAY '└────────────────────────────┘'
- INKEY(0)
- SETCOLOR(old_color)
- SCRNREST(memo_scrn)
- SCRNREST(line_24)
- SETCURSOR(old_cursor)
-
- ENDIF
- ENDIF
-
- RETURN ret_value
-
-
-