DEFINE CLASS wwhtmleditbox AS editbox
OLEDropMode = 1
FontName = "Tahoma"
FontSize = 8
Alignment = 0
AllowTabs = .T.
Height = 188
ScrollBars = 2
Width = 443
oundobuffer = .NULL.
*-- Last time the UndoBuffer was updated in seconds. Internally used value that keeps every character from getting added to the undo buffer._
nlastundoupdate = 0
*-- Flag used to disable Programmatic changes to the Undo buffer.
lundonoprogrammaticchange = .F.
lundotracking = .F.
oredobuffer = .NULL.
Name = "wwhtmleditbox"
PROCEDURE Init
this.oUndoBuffer = CREATEOBJECT("wwNameValueCollection")
this.oRedoBuffer = CREATEOBJECT("wwNameValueCollection")
ENDPROC
PROCEDURE undo
IF THIS.lundotracking AND THIS.oUndoBuffer.Count > 0
THIS.lUndoNoProgrammaticChange = .T.
this.oRedoBuffer.FastAdd(TRANSFORM(this.SelStart),this.Value)
lcValue = this.oUndoBuffer.aItems[this.oUndoBuffer.Count,2]
IF lcValue = this.Value AND this.oUndoBuffer.Count > 1
THIS.Value = this.oUndoBuffer.aItems[this.oUndoBuffer.Count-1,2]
this.oUndoBuffer.Remove(this.oUndoBuffer.Count)
ELSE
this.Value = lcValue
ENDIF
this.SelStart = VAL(this.oUndoBuffer.aItems[this.oUndoBuffer.Count,1])
THIS.lUndoNoProgrammaticChange = .F.
this.oUndoBuffer.Remove(this.oUndoBuffer.Count)
ENDIF
ENDPROC
PROCEDURE redo
IF THIS.lundotracking AND THIS.oRedoBuffer.Count > 0
THIS.lUndoNoProgrammaticChange = .T.
this.Value = this.oRedoBuffer.aItems[this.oReDoBuffer.Count,2]
this.SelStart = VAL(this.oRedoBuffer.aItems[this.oRedoBuffer.Count,1])
THIS.lUndoNoProgrammaticChange = .F.
this.oRedoBuffer.Remove(this.oRedoBuffer.Count)
ENDIF
ENDPROC
PROCEDURE KeyPress
LPARAMETERS nKeyCode, nShiftAltCtrl
*** Don't want ESC to wipe out content of field.
IF nKeyCode = 27
*** Eat the key
NODEFAULT
ENDIF
*** Ctrl-Z
IF THIS.lUndoTracking
IF nKeyCode = 26
*** Must check for Ctrl-<- which is also 26
DECLARE INTEGER GetKeyState IN WIN32API INTEGER
IF GetKeyState(0x25) > -1
THIS.Undo()
NODEFAULT
ENDIF
ENDIF
*** Redo Ctrl-R
IF nKeyCode = 18
THIS.Redo()
NODEFAULT
ENDIF
ENDIF
ENDPROC
PROCEDURE ProgrammaticChange
IF THIS.lUndoTracking AND !THIS.lUndoNoProgrammaticChange
this.oUndoBuffer.FastAdd(TRANSFORM(this.SelStart),this.Value)
this.oRedoBuffer.Clear()
ENDIF
ENDPROC
PROCEDURE InteractiveChange
IF THIS.lUndoTracking
*** Update only in half second intervals,
*** so if you type a bunch of words it goes in batch
IF SECONDS() - THIS.nLastUndoUpdate < 1
this.nLastUndoUpdate = SECONDS()
RETURN
ENDIF
*** Only write undo on last word boundary
IF LASTKEY() = 32 OR LASTKEY() = 13 OR LASTKEY() = 44 OR ;
LASTKEY() = 46 OR LASTKEY() = 9
this.oUndoBuffer.FastAdd(TRANSFORM(this.SelStart),this.Value)
this.oRedoBuffer.Clear()
this.nLastUndoUpdate = SECONDS()
ENDIF
ENDIF
ENDPROC
PROCEDURE Refresh
IF THIS.lUndoTracking
THIS.oUndobuffer.Clear()
ENDIF
ENDPROC
ENDDEFINE