From c9790e09a38c188367ba5745c9c2b6e4e656431e Mon Sep 17 00:00:00 2001 From: Maurilio Longo Date: Mon, 23 Oct 2000 16:18:42 +0000 Subject: [PATCH] 2000-10-23 18:15 GMT+2 Maurilio Longo --- harbour/ChangeLog | 6 ++ harbour/contrib/mysql/tsqlbrw.prg | 152 ++++++++++++++++++------------ harbour/source/rtl/teditor.prg | 27 +++++- 3 files changed, 120 insertions(+), 65 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 23e4306be3..49e25412fc 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,9 @@ +2000-10-23 18:15 GMT+2 Maurilio Longo + * source/rtl/teditor.prg + + added KeyboardHook() and IdleHook() methods. + * contrib/mysql/tsqlbrw.prg + + little changes. + 2000-10-22 09:05 UTC+0800 Ron Pinkas * source/compiler/simplex.c ! Corrrected bug reported by Luiz regarding menuto.prg diff --git a/harbour/contrib/mysql/tsqlbrw.prg b/harbour/contrib/mysql/tsqlbrw.prg index 5da1201f26..f6ed537b58 100644 --- a/harbour/contrib/mysql/tsqlbrw.prg +++ b/harbour/contrib/mysql/tsqlbrw.prg @@ -121,11 +121,17 @@ CLASS TBrowseSQL from TBrowse DATA oQuery // Query / table object which we are browsing METHOD New(nTop, nLeft, nBottom, nRight, oServer, oQuery, cTable) + METHOD EditField() // Editing of hilighted field, after editing does an update of // corresponding row inside table - METHOD BrowseTable(nKey, lCanEdit) // Handles standard moving inside table and if lCanEdit == .T. - // allows editing of field. It is the stock ApplyKey() moved inside a table - // if lCanEdit K_DEL deletes current row + + METHOD BrowseTable(lCanEdit, aExitKeys) // Handles standard moving inside table and if lCanEdit == .T. + // allows editing of field. It is the stock ApplyKey() moved inside a table + // if lCanEdit K_DEL deletes current row + // When a key is pressed which is present inside aExitKeys it leaves editing loop + + METHOD KeyboardHook(nKey) // Where do all unknown keys go? + ENDCLASS @@ -314,75 +320,97 @@ METHOD EditField() CLASS TBrowseSQL RETURN Self -METHOD BrowseTable(nKey, lCanEdit) CLASS TBrowseSQL +METHOD BrowseTable(lCanEdit, aExitKeys) CLASS TBrowseSQL + + local nKey + local lKeepGoing := .T. default nKey to nil default lCanEdit to .F. + default aExitKeys to {K_ESC} - do case - case nKey == K_DOWN - ::down() + while lKeepGoing - case nKey == K_PGDN - ::pageDown() - - case nKey == K_CTRL_PGDN - ::goBottom() - - case nKey == K_UP - ::up() - - case nKey == K_PGUP - ::pageUp() - - case nKey == K_CTRL_PGUP - ::goTop() - - case nKey == K_RIGHT - ::right() - - case nKey == K_LEFT - ::left() - - case nKey == K_HOME - ::home() - - case nKey == K_END - ::end() - - case nKey == K_CTRL_LEFT - ::panLeft() - - case nKey == K_CTRL_RIGHT - ::panRight() - - case nKey == K_CTRL_HOME - ::panHome() - - case nKey == K_CTRL_END - ::panEnd() - - case nKey == K_RETURN - if lCanEdit - ::EditField() + if !::Stable + ::ForceStable() endif - /*case nKey == K_DEL - if lCanEdit - if ! ::oQuery:Delete(::oCurRow) - Alert("not deleted " + ::oQuery:Error()) - endif - if !::oQuery:Refresh() - Alert(::oQuery:Error()) - endif + nKey := Inkey(0) - ::inValidate() - ::refreshAll():forceStable() - endif*/ + if AScan(aExitKeys, nKey) > 0 + lKeepGoing := .F. + LOOP + endif - otherwise - endcase + do case + case nKey == K_DOWN + ::down() + + case nKey == K_PGDN + ::pageDown() + + case nKey == K_CTRL_PGDN + ::goBottom() + + case nKey == K_UP + ::up() + + case nKey == K_PGUP + ::pageUp() + + case nKey == K_CTRL_PGUP + ::goTop() + + case nKey == K_RIGHT + ::right() + + case nKey == K_LEFT + ::left() + + case nKey == K_HOME + ::home() + + case nKey == K_END + ::end() + + case nKey == K_CTRL_LEFT + ::panLeft() + + case nKey == K_CTRL_RIGHT + ::panRight() + + case nKey == K_CTRL_HOME + ::panHome() + + case nKey == K_CTRL_END + ::panEnd() + + case nKey == K_RETURN .AND. lCanEdit + ::EditField() + + /*case nKey == K_DEL + if lCanEdit + if ! ::oQuery:Delete(::oCurRow) + Alert("not deleted " + ::oQuery:Error()) + endif + if !::oQuery:Refresh() + Alert(::oQuery:Error()) + endif + + ::inValidate() + ::refreshAll():forceStable() + endif*/ + + otherwise + ::KeyboardHook(nKey) + endcase + enddo return Self + +// Empty method to be subclassed +METHOD KeyboardHook(nKey) CLASS TBrowseSQL + +return Self diff --git a/harbour/source/rtl/teditor.prg b/harbour/source/rtl/teditor.prg index a9c3895302..b7206f795d 100644 --- a/harbour/source/rtl/teditor.prg +++ b/harbour/source/rtl/teditor.prg @@ -103,6 +103,9 @@ CLASS TEditor METHOD InsertState(lInsState) // Changes lInsert value and insertion / overstrike mode of editor METHOD Edit(nPassedKey) // Handles input (can receive a key in which case handles only this key and then exits) + 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 Resize(nTop, nLeft, nBottom, nRight) // Redefines editor window size and refreshes it METHOD SetColor(cColorString) // Sets/retrieves color used for screen writes METHOD Hilite() // Start Hilighting swapping first two color definitions inside cColorSpec @@ -784,8 +787,11 @@ METHOD Edit(nPassedKey) CLASS TEditor while lKeepGoing - // If I've been called with a key already preset, evaluate this key and then exit + // If I haven't been called with a key already preset, evaluate this key and then exit if nPassedKey == NIL + if NextKey() == 0 + ::IdleHook() + endif nKey := InKey(0) else lKeepGoing := .F. @@ -793,7 +799,7 @@ METHOD Edit(nPassedKey) CLASS TEditor endif do case - case nKey >= 32 .AND. nKey <= 255 + case nKey >= K_SPACE .AND. nKey < 256 // If I'm past EOL I need to add as much spaces as I need to reach ::nCol if ::nCol > ::LineLen(::nRow) ::aText[::nRow]:cText += Space(::nCol - ::LineLen(::nRow)) @@ -885,7 +891,9 @@ METHOD Edit(nPassedKey) CLASS TEditor lKeepGoing := .F. otherwise - /* TODO: Here we should call an user defined function (to match memoedit() behaviour) */ + /* NOTE: if you call ::Edit() with a key that is passed to ::KeyboardHook() and then + ::KeyboardHook() calls ::Edit() with the same key you end up with an endless loop */ + ::KeyboardHook(nKey) endcase enddo endif @@ -893,6 +901,19 @@ METHOD Edit(nPassedKey) CLASS TEditor return Self +// This in an empty method which can be used by classes subclassing TEditor to be able +// to handle particular keys. +METHOD KeyboardHook(nKey) CLASS TEditor + +return Self + + +// There are no more keys to handle. Can I do something for you? +METHOD IdleHook() CLASS TEditor + +return Self + + METHOD SetColor(cColorString) CLASS TEditor local cOldColor := ::cColorSpec