If you go through the
HiEdit.inc document that is included with the
HiEdit download, you would quickly determine that there are quite a few of routines that could be added to the
HiEdit library. Unfortunately most of the "new" routines would go unused because they are not needed, there are alternative commands, etc. But and however, there are a few unused commands that have value.
Using the current library syntax (for the most part), I've written a few functions that might be useful:
Code:
;-------------------------------------------------------------------------------
; Function: HE_GetModify
;
; Gets the state of the modification flag for the HiEdit control. The
; flag indicates whether the contents of the control have been
; modified.
;
;
; Parameters:
;
; idx - Index of the file. -1 for the current file (default)
;
;
; Returns:
;
; TRUE if the content of HiEdit control has been modified, FALSE
; otherwise.
;
;
HE_GetModify(hEdit,idx=-1)
{
Static EM_GETMODIFY:=0xB8
SendMessage EM_GETMODIFY,0,idx,,ahk_id %hEdit%
Return ErrorLevel
}
;-------------------------------------------------------------------------------
; Function: HE_SetModify
;
; Sets or clears the modification flag for the current file. The
; modification flag indicates whether the text within the control has
; been modified.
;
;
; Parameters:
;
; ModifyFlag - Set to TRUE to set the modification flag. Set to FALSE
; to clear the modification flag.
;
;
; Returns:
;
; (None)
;
;
HE_SetModify(hEdit,ModifyFlag)
{
Static EM_SETMODIFY:=0xB9
SendMessage EM_SETMODIFY,ModifyFlag,0,,ahk_id %hEdit%
Return
}
;-------------------------------------------------------------------------------
; Function: HE_EmptyUndoBuffer
;
; Resets the undo flag in the HiEdit control for the current file.
;
;
; Returns:
;
; (None)
;
;
HE_EmptyUndoBuffer(hEdit)
{
Static EM_EMPTYUNDOBUFFER:=0xCD
SendMessage EM_EMPTYUNDOBUFFER,0,0,,ahk_id %hEdit%
Return
}
;-------------------------------------------------------------------------------
; Function: HE_Scroll
;
; Scrolls the text vertically in the HiEdit control for the current
; file.
;
;
; Parameters:
;
; Pages - The number of pages to scroll. Use a negative number to
; scroll up and a positive number to scroll down.
;
; Lines - The number of lines to scroll. Use a negative number to
; scroll up and a positive number to scroll down.
;
;
; Returns:
;
; {The following information extracted from HiEdit.inc}
; The number of lines that the command scrolls. The number returned
; may not be the same as the actual number of lines scrolled if the
; scrolling moves to the beginning or the end of the text.
;
;
; Remarks:
;
; This message does not move the caret.
;
;
; Programming Notes:
;
; 0x7FFFFFFF=2147483647=largest possible 32-bit signed integer value
;
;
; Observations:
;
; Despite the documentation, the return value for the message always
; reflects the request, not necessarily the actual number of lines
; that were scrolled. Example: If a request to scroll down 25 lines
; is made, 25 is returned even if the control is already scrolled down
; to the bottom of the document. [Bug?]
;
;
HE_Scroll(hEdit,Pages=0,Lines=0)
{
Static EM_SCROLL:=0xB5
,SB_LINEDOWN:=0x1 ;-- Scroll down one line
,SB_LINEUP:=0x0 ;-- Scroll up one line
,SB_PAGEDOWN:=0x3 ;-- Scroll down one page
,SB_PAGEUP:=0x2 ;-- Scroll up one page
;-- Initialize
l_ScrollLineCount:=0
;-- Pages
if Pages
{
l_nScroll:=SB_PAGEDOWN
if Pages<0
{
l_nScroll:=SB_PAGEUP
Pages:=Abs(Pages)
}
loop %Pages%
{
SendMessage EM_SCROLL,l_nScroll,0,,ahk_id %hEdit%
l_ErrorLevel:=ErrorLevel
;-- Negative number?
if l_ErrorLevel>0x7FFFFFFF
l_ErrorLevel:=-(~l_ErrorLevel)-1 ;-- Convert to signed integer
;-- Add to the total
l_ScrollLineCount:=l_ScrollLineCount+l_ErrorLevel
}
}
;-- Lines
if Lines
{
l_nScroll:=SB_LINEDOWN
if Lines<0
{
l_nScroll:=SB_LINEUP
Lines:=Abs(Lines)
}
loop %Lines%
{
SendMessage EM_SCROLL,l_nScroll,0,,ahk_id %hEdit%
l_ErrorLevel:=ErrorLevel
;-- Negative number?
if l_ErrorLevel>0x7FFFFFFF
l_ErrorLevel:=-(~l_ErrorLevel)-1 ;-- Convert to signed integer
;-- Add to the total
l_ScrollLineCount:=l_ScrollLineCount+l_ErrorLevel
}
}
;-- Return number of lines scrolled
Return l_ScrollLineCount
}
;-------------------------------------------------------------------------------
; Function: HE_LineScroll
;
; Scrolls the text in the HiEdit control for the current file.
;
;
; Parameters:
;
; xScroll - The number of characters to scroll horizontally. Use a
; negative number to scroll to the left and a positive number to
; scroll to the right.
;
; yScroll - The number of lines to scroll vertically. Use a negative
; number to scroll up and a positive number to scroll down.
;
;
; Returns:
;
; (None)
;
;
; Remarks:
;
; This message does not move the caret.
;
; {The following information extracted from HiEdit.inc}
; The HiEdit control does not scroll vertically past the last line of
; text in the control. If the current line plus the number of lines
; specified by the yScroll parameter exceeds the total number of lines
; in the HiEdit control, the value is adjusted so that the last line
; of the HiEdit control is scrolled to the top of the HiEdit control
; window.
;
; The EM_LINESCROLL message can be used to scroll horizontally past
; the last character of any line.
;
;
HE_LineScroll(hEdit,xScroll=0,yScroll=0)
{
Static EM_LINESCROLL:=0xB6
SendMessage EM_LINESCROLL,xScroll,yScroll,,ahk_id %hEdit%
Return
}
Examples of use:
Code:
;-- If modification flag set, save file
if HE_GetModify(hEdit)
HE_SaveFile(hEdit,"C:\Test.txt")
;-- Clear modification flag
HE_SetModify(hEdit,false)
;-- Populate the control then empty UnDo buffer
HE_ReplaceSel(hEdit,"Stuff that I'm adding to the control for the 1st time")
HE_EmptyUndoBuffer(hEdit)
;-- The HE_EmptyUndoBuffer can be used to keep the user from "accidentally"
; undoing a developer-initiated operation that updates the Undo buffer.
HE_Scroll(hEdit,1) ;-- Scroll down 1 page
HE_Scroll(hEdit,-2) ;-- Scroll up 2 pages
HE_Scroll(hEdit,0,5) ;-- Scroll down 5 lines
HE_Scroll(hEdit,0,-25) ;-- Scroll up 25 lines
HE_Scroll(hEdit,2,-5) ;-- Scroll down 2 pages and then up 5 lines
HE_LineScroll(hEdit,25) ;-- Scroll 25 characters to the right
HE_LineScroll(hEdit,-5) ;-- Scroll 5 characters to the left
HE_LineScroll(hEdit,0,50) ;-- Scroll down 50 lines.
HE_LineScroll(hEdit,0,-7) ;-- Scroll up 7 lines.
HE_LineScroll(hEdit,-999999,-999999)
;-- Scroll to the top/left. Similar to the Ctrl+Home hotkey.
HE_LineScroll(hEdit,-999999,999999)
;-- Scroll to the bottom/left. Similar to the Ctrl+End hotkey.
Although I've tested these functions, they haven't gone through extensive field testing. If desired, add these functions to the
HiEdit library at your discretion and with any changes you see fit.
I hope that someone finds this useful.