From 7a09f03e8775c3d9b4cf7e31631a265e8699558c Mon Sep 17 00:00:00 2001 From: Maurilio Longo Date: Fri, 20 Apr 2001 13:08:43 +0000 Subject: [PATCH] 2001-04-20 15:04 GMT+2 Maurilio Longo * source/rtl/memoedit.prg * simplified handling of keys and prevented infinite recursion when a key not handled by TEditor was pressed inside a MemoEdit() window. * ME_TOGGLESCROLL is not handled since TEditor cannot handle such a kind of "movement" * K_CTRL_T (delete word right) is not handled since TEditor is not able to do it --- harbour/ChangeLog | 7 ++ harbour/source/rtl/memoedit.prg | 130 ++++++++++++++------------------ 2 files changed, 63 insertions(+), 74 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index e8e9f594c4..71be0a9f3c 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,10 @@ +2001-04-20 15:04 GMT+2 Maurilio Longo + * source/rtl/memoedit.prg + * simplified handling of keys and prevented infinite recursion when a key not + handled by TEditor was pressed inside a MemoEdit() window. + * ME_TOGGLESCROLL is not handled since TEditor cannot handle such a kind of "movement" + * K_CTRL_T (delete word right) is not handled since TEditor is not able to do it + 2001-04-20 11:09 GMT+2 Maurilio Longo * source/rtl/memoedit.prg ! fixed handling of K_ALT_W diff --git a/harbour/source/rtl/memoedit.prg b/harbour/source/rtl/memoedit.prg index f2f30e6226..9fdd39cb46 100644 --- a/harbour/source/rtl/memoedit.prg +++ b/harbour/source/rtl/memoedit.prg @@ -65,7 +65,9 @@ CLASS TMemoEditor FROM TEditor METHOD MemoInit(cUserFunction) // This method is called after ::New() returns to perform ME_INIT actions METHOD Edit() // Calls super:Edit(nKey) but is needed to handle configurable keys METHOD KeyboardHook(nKey) // Gets called every time there is a key not handled directly by TEditor - METHOD IdleHook() // Gets called every time there are no more keys to hanlde just before TEditor blocks itself waiting for a char + METHOD IdleHook() // Gets called every time there are no more keys to hanlde + + METHOD HandleUserKey(nKey, nUserKey) // Handles keys returned to MemoEdit() by user function ENDCLASS @@ -83,28 +85,10 @@ METHOD MemoInit(cUserFunction) CLASS TMemoEditor // Keep calling user function until it returns 0 while (nKey := Do(::xUserFunction, ME_INIT, ::nRow, ::nCol - 1)) <> ME_DEFAULT - do case - case nKey >= 1 .AND. nKey <= 31 - super:Edit(nKey) - - case nKey == ME_DATA - super:Edit(nKey) - - case nKey == ME_TOGGLEWRAP - ::lWordWrap := !::lWordWrap - - case nKey == ME_TOGGLESCROLL - // Don't know what to do ;-) - - case nKey == ME_WORDRIGHT - ::MoveCursor(K_CTRL_RIGHT) - - case nKey == ME_BOTTOMRIGHT - ::MoveCursor(K_CTRL_END) - - otherwise - - endcase + // At this time there is no input from user of MemoEdit() only handling + // of values returned by ::xUserFunction, so I pass these value on both + // parameters of ::HandleUserKey() + ::HandleUserKey(nKey, nKey) enddo @@ -132,38 +116,13 @@ METHOD Edit() CLASS TMemoEditor if NextKey() == 0 ::IdleHook() endif + nKey := Inkey(0) // Is it a configurable key ? if AScan(aConfigurableKeys, nKey) > 0 nUserKey := Do(::xUserFunction, iif(::lDirty, ME_UNKEYX, ME_UNKEY), ::nRow, ::nCol - 1) - - do case - case nUserKey == ME_DEFAULT - super:Edit(nKey) - - // TOFIX: Not clipper compatible, see teditor.prg - case (nUserKey >= 1 .AND. nUserKey <= 31) .OR. nUserKey == K_ALT_W - super:Edit(nUserKey) - - case nUserKey == ME_DATA - super:Edit(nKey) - - case nUserKey == ME_TOGGLEWRAP - ::lWordWrap := !::lWordWrap - - case nUserKey == ME_TOGGLESCROLL - // Don't know what to do ;-) - - case nUserKey == ME_WORDRIGHT - ::MoveCursor(K_CTRL_RIGHT) - - case nUserKey == ME_BOTTOMRIGHT - ::MoveCursor(K_CTRL_END) - - otherwise - - endcase + ::HandleUserKey(nKey, nUserKey) else super:Edit(nKey) @@ -189,31 +148,9 @@ METHOD KeyboardHook(nKey) CLASS TMemoEditor local nUserKey if ::xUserFunction <> nil + nUserKey := Do(::xUserFunction, iif(::lDirty, ME_UNKEYX, ME_UNKEY), ::nRow, ::nCol - 1) - - do case - // TOFIX: Not clipper compatible, see teditor.prg - case (nUserKey >= 1 .AND. nUserKey <= 31) .OR. nUserKey == K_ALT_W - super:Edit(nUserKey) - - case nUserKey == ME_DATA - //super:Edit(nKey) - - case nUserKey == ME_TOGGLEWRAP - ::lWordWrap := !::lWordWrap - - case nUserKey == ME_TOGGLESCROLL - // Don't know what to do ;-) - - case nUserKey == ME_WORDRIGHT - ::MoveCursor(K_CTRL_RIGHT) - - case nUserKey == ME_BOTTOMRIGHT - ::MoveCursor(K_CTRL_END) - - otherwise - - endcase + ::HandleUserKey(nKey, nUserKey) endif @@ -230,6 +167,51 @@ METHOD IdleHook() CLASS TMemoEditor return Self +METHOD HandleUserKey(nKey, nUserKey) CLASS TMemoEditor + + // TEditor does not handle these keys and would call ::KeyboardHook() causing infinite loop + local aUnHandledKeys := {K_CTRL_J, K_CTRL_K, K_CTRL_L, K_CTRL_N, K_CTRL_O, K_CTRL_P, K_CTRL_Q, K_CTRL_T,; + K_CTRL_U, K_F1 } + + do case + // I won't reach this point during ME_INIT since ME_DEFAULT ends initialization phase of MemoEdit() + case nUserKey == ME_DEFAULT + // TEditor is not able to handle keys with a value higher than 256 + if nKey <= 256 .AND. AScan(aUnHandledKeys, nKey) == 0 + super:Edit(nKey) + endif + + // TOFIX: Not clipper compatible, see teditor.prg + case (nUserKey >= 1 .AND. nUserKey <= 31) .OR. nUserKey == K_ALT_W + if AScan(aUnHandledKeys, nUserKey) == 0 + super:Edit(nUserKey) + endif + + case nUserKey == ME_DATA + if nKey <= 256 .AND. AScan(aUnHandledKeys, nKey) == 0 + super:Edit(nKey) + endif + + case nUserKey == ME_TOGGLEWRAP + ::lWordWrap := !::lWordWrap + + case nUserKey == ME_TOGGLESCROLL + // TODO: TEditor does not support vertical scrolling of text inside window without moving cursor position + + case nUserKey == ME_WORDRIGHT + ::MoveCursor(K_CTRL_RIGHT) + + case nUserKey == ME_BOTTOMRIGHT + ::MoveCursor(K_CTRL_END) + + otherwise + // Do nothing + + endcase + +return Self + + /*----------------------------------------------------------------------------------------*/