/lib/sci.ahk
http://github.com/Skiouros/Macro · AutoHotKey · 2820 lines · 490 code · 191 blank · 2139 comment · 21 complexity · 2728862b27df57b342fabef7e1f2edee MD5 · raw file
Large files are truncated click here to view the full file
- ; Title: Scintilla Wrapper for AHK
-
- ; Group: Helper Functions
-
- /*
- Function: Add
- Creates a Scintilla component and adds it to the Parent GUI.
-
- This function initializes the Scintilla Component.
- See <http://www.scintilla.org/Steps.html> for more information on how to add the component to a GUI/Control.
-
- Parameters:
- SCI_Add(hParent, [x, y, w, h, Styles, MsgHandler, DllPath])
-
- hParent - Hwnd of the parent control who will host the Scintilla Component
- x - x position for the control (default 5)
- y - y position for the control (default 15)
- w - Width of the control (default 390)
- h - Height of the control (default 270)
- Styles - List of window style variable names separated by spaces.
- The WS_ prefix for the variables is optional.
- Full list of Style names can be found at
- <http://msdn.microsoft.com/en-us/library/ms632600%28v=vs.85%29.aspx>.
-
- MsgHandler - Name of the function that will handle the window messages sent by the control.
- This is very useful for when creating personalized lexing or folding for your control.
- DllPath - Path to the SciLexer.dll file, if omitted the function looks for it in *a_scriptdir*.
-
- Returns:
- HWND - Component handle.
-
- Examples:
- (start code)
- ; Add a component with default values.
- ; It expects scilexer.dll to be on the script's location.
- ; The default values are calculated to fit optimally on a 400x300 GUI/Control
-
- Gui +LastFound
- hwnd:=WinExist()
- hSci:=SCI_Add(hwnd)
- Gui, show, w400 h300
- return
-
- ;---------------------
- ; Add a component with default values.
- ; It expects scilexer.dll to be on the script's location.
- ; This script also adds some styles.
- ; If variables "x,y,w,h" are empty the default values are used.
-
- Gui +LastFound
- hwnd:=WinExist()
- hSci:=SCI_Add(hwnd, x, y, w, h, "WS_CHILD WS_BORDER WS_VISIBLE")
- Gui, show, w400 h300
- return
-
- ;---------------------
- ; Add a component embedded in a tab with additional code for
- ; hiding/showing the component depending on which tab is open.
- ; If variables "x,w,h" are empty the default values are used.
-
- Gui, add, Tab2, HWNDhwndtab x0 y0 w400 h300 gtabHandler vtabLast,one|two
- hSci:=SCI_Add(hwndtab,x,25,w,h,"Child Border Visible","",a_desktop "\scilexer.dll")
- Gui, show, w400 h300
- return
-
- tabHandler: ; Tab Handler for the Scintilla Control
- Gui, submit, Nohide
- action := tabLast = "one" ? "Show" : "Hide" ; decide which action to take
- Control,%action%,,,ahk_id %hSci%
- return
- (end)
- */
- SCI_Add(hParent, x=5, y=15, w=390, h=270, Styles="", MsgHandler="", DllPath=""){
- static WS_OVERLAPPED:=0x00000000,WS_POPUP:=0x80000000,WS_CHILD:=0x40000000,WS_MINIMIZE:=0x20000000
- ,WS_VISIBLE:=0x10000000,WS_DISABLED:=0x08000000,WS_CLIPSIBLINGS:=0x04000000,WS_CLIPCHILDREN:=0x02000000
- ,WS_MAXIMIZE:=0x01000000,WS_CAPTION:=0x00C00000,WS_BORDER:=0x00800000,WS_DLGFRAME:=0x00400000
- ,WS_VSCROLL:=0x00200000,WS_HSCROLL:=0x00100000,WS_SYSMENU:=0x00080000,WS_THICKFRAME:=0x00040000
- ,WS_GROUP:=0x00020000,WS_TABSTOP:=0x00010000,WS_MINIMIZEBOX:=0x00020000,WS_MAXIMIZEBOX:=0x00010000
- ,WS_TILED:=0x00000000,WS_ICONIC:=0x20000000,WS_SIZEBOX:=0x00040000,WS_EX_CLIENTEDGE:=0x00000200
- ,GuiID:=311210,init:=False, NULL:=0
-
- if !init ; WM_NOTIFY = 0x4E
- old:=OnMessage(0x4E,"SCI_onNotify"),init:=True,old!="SCI_onNotify" ? SCI("oldNotify", RegisterCallback(old))
-
- if !SCIModule:=DllCall("LoadLibrary", "Str", DllPath ? DllPath : "SciLexer.dll")
- return debug ? A_ThisFunc "> Could not load library: " DllPath : -1
-
- hStyle := WS_CHILD | (VISIBILITY := InStr(Styles, "Hidden") ? 0 : WS_VISIBLE) | WS_TABSTOP
-
- if Styles
- Loop, Parse, Styles, %a_tab%%a_space%, %a_tab%%a_space%
- hStyle |= %a_loopfield%+0 ? %a_loopfield% : WS_%a_loopfield% ? WS_%a_loopfield% : 0
-
- hSci:=DllCall("CreateWindowEx"
- ,Uint ,WS_EX_CLIENTEDGE ; Ex Style
- ,Str ,"Scintilla" ; Class Name
- ,Str ,"" ; Window Name
- ,UInt ,hStyle ; Window Styles
- ,Int ,x ? x : 5 ; x
- ,Int ,y ? y : 15 ; y
- ,Int ,w ? w : 390 ; Width
- ,Int ,h ? h : 270 ; Height
- ,UInt ,hParent ; Parent HWND
- ,UInt ,GuiID ; (HMENU)GuiID
- ,UInt ,NULL ; hInstance
- ,UInt ,NULL, "UInt") ; lpParam
-
- ,SCI(hSci, True) ; used to check if that handle exist.
- ,SCI_sendEditor(hSci) ; initialize SCI_sendEditor function
- ,IsFunc(MsgHandler) ? SCI(hSci "MsgHandler", MsgHandler)
-
- return hSci
- }
-
- /* Group: Text
- Group of funtions that handle the text in the scintilla component.
-
- <http://www.scintilla.org/ScintillaDoc.html#TextRetrievalAndModification>
-
- Each byte in a Scintilla document is followed by an associated byte of styling information. The combination of
- a character byte and a style byte is called a cell. Style bytes are interpreted an index into an array of
- styles.
-
- Style bytes may be split into an index and a set of indicator bits but this use is discouraged and indicators
- should now use *SCI_INDICATORFILLRANGE* and related calls. The default split is with the index in the low 5
- bits and 3 high bits as indicators. This allows 32 fundamental styles, which is enough for most languages, and
- three independent indicators so that, for example, syntax errors, deprecated names and bad indentation could
- all be displayed at once. The number of bits used for styles can be altered with *SCI_SETSTYLEBITS* up to a
- maximum of 8 bits. The remaining bits can be used for indicators.
-
- In this document, 'character' normally refers to a byte even when multi-byte characters are used. Lengths
- measure the numbers of bytes, not the amount of characters in those bytes.
-
- Positions within the Scintilla document refer to a character or the gap before that character. The first
- character in a document is 0, the second 1 and so on. If a document contains nLen characters, the last
- character is numbered nLen-1. The caret exists between character positions and can be located from before the
- first character (0) to after the last character (nLen).
-
- There are places where the caret can not go where two character bytes make up one character. This occurs when a
- DBCS character from a language like Japanese is included in the document or when line ends are marked with the
- CP/M standard of a carriage return followed by a line feed. The *INVALID_POSITION* constant (-1) represents an
- invalid position within the document.
-
- All lines of text in Scintilla are the same height, and this height is calculated from the largest font in any
- current style. This restriction is for performance; if lines differed in height then calculations involving
- positioning of text would require the text to be styled first.
- */
-
- ; Group: General Text Functions
-
- /*
- Function: ReplaceSel
- <http://www.scintilla.org/ScintillaDoc.html#SCI_REPLACESEL>
-
- The currently selected text between the anchor and the current position is replaced by the 0 terminated text
- string. If the anchor and current position are the same, the text is inserted at the caret position. The caret
- is positioned after the inserted text and the caret is scrolled into view.
-
- Parameters:
- SCI_ReplaceSel(rStr[, hwnd])
-
- rStr - String of text to use for replacing the current selection.
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- >SCI_ReplaceSel("replace currently selected text with this", hSci)
- */
- SCI_ReplaceSel(rStr, hwnd=0){
-
- a_isunicode ? (VarSetCapacity(rStrA, StrPut(rStr, "CP0")), StrPut(rStr, &rStrA, "CP0"))
- return SCI_sendEditor(hwnd, "SCI_REPLACESEL", 0, a_isunicode ? &rStrA : &rStr)
- }
-
- /*
- Function: Allocate
- <http://www.scintilla.org/ScintillaDoc.html#SCI_ALLOCATE>
-
- Allocate a document buffer large enough to store a given number of bytes. The document will not be made
- smaller than its current contents.
-
- Parameters:
- SCI_Allocate(nBytes[, hwnd])
-
- nBytes - Number of bytes to allocate for the document buffer.
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- >SCI_Allocate(1024, hSci)
- */
- SCI_Allocate(nBytes, hwnd=0){
-
- return SCI_sendEditor(hwnd, "SCI_ALLOCATE", nBytes)
- }
-
- /*
- Function: AddText
- <http://www.scintilla.org/ScintillaDoc.html#SCI_ADDTEXT>
-
- This inserts the first *len* characters from the string *aStr* at the current position.
- The current position is set at the end of the inserted text, but it is *not* scrolled into view.
-
- Parameters:
- SCI_AddText(aStr[, len, hwnd])
-
- aStr - The string to be added to the component at current caret position.
- len - Lenght of the string that will be added to the component. If 0 or blank it will be calculated
- automatically using StrLen()
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- (start code)
- #include ../SCI.ahk
-
- Gui +LastFound
- hwnd:=WinExist()
- hSci1:=SCI_Add(hwnd, x, y, w, h)
- Gui, show, w400 h300
- SCI_SetWrapMode(True, hSci1)
- SCI_AddText(x:="my text",StrLen(x), hSci)
- return
- ;---------------------
-
- #include ../SCI.ahk
-
- Gui +LastFound
- hwnd:=WinExist()
- hSci1:=SCI_Add(hwnd, x, y, w, h)
- Gui, show, w400 h300
- SCI_SetWrapMode(True, hSci1)
-
- ; stores "This is my truncated text".
- SCI_AddText("This is my truncated text, this is not added!",25)
- return
- ;---------------------
-
- #include ../SCI.ahk
-
- Gui +LastFound
- hwnd:=WinExist()
- hSci1:=SCI_Add(hwnd, x, y, w, h)
- Gui, show, w400 h300
- SCI_SetWrapMode(True, hSci1)
-
- ; In this example the whole text is stored because the length is calculated internally.
- SCI_AddText("This is my truncated text, this is added!")
- return
- (end)
- */
- SCI_AddText(aStr, len=0, hwnd=0){
-
- a_isunicode ? (VarSetCapacity(aStrA, StrPut(aStr, "CP0")), StrPut(aStr, &aStrA, "CP0"))
- return SCI_sendEditor(hwnd, "SCI_ADDTEXT", len ? len : strLen(aStr), a_isunicode ? &aStrA : &aStr)
- }
-
- ; /* needs work
- ; Function: AddStyledText
- ; <http://www.scintilla.org/ScintillaDoc.html#SCI_ADDSTYLEDTEXT>
-
- ; This behaves just like <AddText()>, but inserts styled text.
-
- ; Parameters:
- ; SCI_AddText(cell[, len, hwnd])
-
- ; cell - The styled string cell to be added to the component at current caret position.
- ; len - lenght of the string that will be added to the component. If 0 or blank it will be calculated
- ; automatically using StrLen()
- ; hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- ; Scintilla components in the same script. The wrapper will remember the last used hwnd,
- ; so you can specify it once and only specify it again when you want to operate on a different
- ; component.
-
- ; Returns:
- ; Zero - Nothing is returned by this function.
-
- ; Examples:
- ; */
- ; SCI_AddStyledText(cell, len=0, hwnd=0){
-
- ; a_isunicode ? (VarSetCapacity(cellA, StrPut(cell, "CP0")), StrPut(cell, &cellA, "CP0"))
- ; return SCI_sendEditor(hwnd, "SCI_ADDSTYLEDTEXT", len ? len : strLen(cell), a_isunicode ? &cellA : &cell)
- ; }
-
- /*
- Function: AppendText
- <http://www.scintilla.org/ScintillaDoc.html#SCI_APPENDTEXT>
-
- This adds the first *len* characters from the string *aStr* to the end of the document.
- The current selection is not changed and the new text is *not* scrolled into view.
-
- Parameters:
- SCI_AppendText(aStr[, len, hwnd])
-
- aStr - The string to be appended to the end of the current document on the selected component.
- len - Lenght of the string that will be added to the component. If 0 or blank it will be calculated
- automatically using StrLen()
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- (start code)
- #include ../SCI.ahk
-
- Gui +LastFound
- hwnd:=WinExist()
- hSci1:=SCI_Add(hwnd, x, y, w, h)
- Gui, show, w400 h300
- SCI_SetWrapMode(True, hSci1)
- SCI_AppendText(x:="my text",StrLen(x), hSci)
- return
- ;---------------------
-
- #include ../SCI.ahk
-
- Gui +LastFound
- hwnd:=WinExist()
- hSci1:=SCI_Add(hwnd, x, y, w, h)
- Gui, show, w400 h300
- SCI_SetWrapMode(True, hSci1)
-
- ; stores "This is my truncated text".
- SCI_AppendText("This is my truncated text, this is not added!",25)
- return
- ;---------------------
-
- #include ../SCI.ahk
-
- Gui +LastFound
- hwnd:=WinExist()
- hSci1:=SCI_Add(hwnd, x, y, w, h)
- Gui, show, w400 h300
- SCI_SetWrapMode(True, hSci1)
-
- ; In this example the whole text is stored because the length is calculated internally.
- SCI_AppendText("This is my truncated text, this is added!")
- return
- (end)
- */
- SCI_AppendText(aStr, len=0, hwnd=0){
-
- a_isunicode ? (VarSetCapacity(aStrA, StrPut(aStr, "CP0")), StrPut(aStr, &aStrA, "CP0"))
- return SCI_sendEditor(hwnd, "SCI_APPENDTEXT", len ? len : strLen(aStr), a_isunicode ? &aStrA : &aStr)
- }
-
- /*
- Function: InsertText
- <http://www.scintilla.org/ScintillaDoc.html#SCI_INSERTTEXT>
-
- This inserts the text string at position *pos* or at the current position if pos is not specified.
- If the current position is after the insertion point then it is moved along with its surrounding text
- but no scrolling is performed.
-
- Parameters:
- SCI_InsertText(iStr[, pos,hwnd])
-
- iStr - String of text to be inserted.
- pos - Position where the text is to be inserted. If not specified it defaults to current caret position.
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- */
- SCI_InsertText(iStr, pos=-1,hwnd=0){
-
- a_isunicode ? (VarSetCapacity(iStrA, StrPut(iStr, "CP0")), StrPut(iStr, &iStrA, "CP0"))
- return SCI_sendEditor(hwnd, "SCI_INSERTTEXT", pos, a_isunicode ? &iStrA : &iStr)
- }
-
- /*
- Function: ClearAll
- <http://www.scintilla.org/ScintillaDoc.html#SCI_CLEARALL>
-
- Unless the document is read-only, this deletes all the text.
-
- Parameters:
- SCI_ClearAll([hwnd])
-
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- >SCI_ClearAll(hSci)
- */
- SCI_ClearAll(hwnd=0){
-
- return SCI_sendEditor(hwnd, "SCI_CLEARALL")
- }
-
- /*
- Function: ClearDocumentStyle
- <http://www.scintilla.org/ScintillaDoc.html#SCI_CLEARDOCUMENTSTYLE>
-
- When wanting to completely restyle the document, for example after choosing a lexer, the
- *ClearDocumentStyle()* can be used to clear all styling information and reset the folding state.
-
- Parameters:
- SCI_ClearDocumentStyle([hwnd])
-
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- >SCI_ClearDocumentStyle(hSci)
- */
- SCI_ClearDocumentStyle(hwnd=0){
-
- return SCI_sendEditor(hwnd, "SCI_CLEARDOCUMENTSTYLE")
- }
-
- ; /* needs work
- ; Function: TargetAsUTF8
- ; <http://www.scintilla.org/ScintillaDoc.html#SCI_TARGETASUTF8>
-
- ; This function retrieves the value of the target encoded as UTF-8, so is useful for retrieving text for use in
- ; other parts of the user interface, such as find and replace dialogs. The length of the encoded text in bytes
- ; is returned.
-
- ; Parameters:
- ; SCI_TargetAsUTF8(tStr[, hwnd])
-
- ; tStr - Target string that will be converted to UTF-8 encoding.
- ; hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- ; Scintilla components in the same script. The wrapper will remember the last used hwnd,
- ; so you can specify it once and only specify it again when you want to operate on a different
- ; component.
-
- ; Returns:
- ; utfLen - Length of the encoded text in bytes.
-
- ; Example:
- ; */
- ; SCI_TargetAsUTF8(tStr, hwnd=0){
-
- ; a_isunicode ? (VarSetCapacity(tStrA, StrPut(tStr, "CP0")), StrPut(tStr, &tStrA, "CP0"))
- ; return SCI_sendEditor(hwnd, "SCI_TARGETASUTF8", 0, a_isunicode ? &tStrA : &tStr)
- ; }
-
- ; /* needs work
- ; Function: EncodedFromUTF8
- ; <http://www.scintilla.org/ScintillaDoc.html#SCI_ENCODEDFROMUTF8>
-
- ; *EncodedFromUTF8()* converts a UTF-8 string into the document's encoding which is useful for taking the
- ; results of a find dialog, for example, and receiving a string of bytes that can be searched for in the
- ; document. Since the text can contain nul bytes, the <SetLengthForEncode()> function can be used to set the
- ; length that will be converted. If set to -1, the length is determined by finding a nul byte. The length of the
- ; converted string is returned.
-
- ; Parameters:
- ; SCI_EncodedFromUTF8(utf8Str, encStr[, hwnd])
-
- ; utf8Str -
- ; encStr -
- ; hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- ; Scintilla components in the same script. The wrapper will remember the last used hwnd,
- ; so you can specify it once and only specify it again when you want to operate on a different
- ; component.
-
- ; Examples:
- ; */
- ; SCI_EncodedFromUTF8(utf8Str, encStr, hwnd=0){
- ; return
- ; }
-
- ; Group: Text Set Functions
-
- /*
- Function: SetText
- <http://www.scintilla.org/ScintillaDoc.html#SCI_SETTEXT>
-
- Replaces all the text in the document with the zero terminated text string you pass in.
-
- Parameters:
- SCI_SetText(sStr[, hwnd])
-
- sStr - String of text to be set on the Scintilla component.
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- */
- SCI_SetText(sStr, hwnd=0){
-
- a_isunicode ? (VarSetCapacity(sStrA, StrPut(sStr, "CP0")), StrPut(sStr, &sStrA, "CP0"))
- return SCI_sendEditor(hwnd, "SCI_SETTEXT", 0, a_isunicode ? &sStrA : &sStr)
- }
-
- /*
- Function: SetSavePoint
- <http://www.scintilla.org/ScintillaDoc.html#SCI_SETSAVEPOINT>
-
- This message tells Scintilla that the current state of the document is unmodified. This is usually done when
- the file is saved or loaded, hence the name "save point". As Scintilla performs undo and redo operations, it
- notifies the container that it has entered or left the save point with *SCN_SAVEPOINTREACHED* and
- *SCN_SAVEPOINTLEFT* notification messages, allowing the container to know if the file should be considered
- dirty or not.
-
- Parameters:
- SCI_SetSavePoint([hwnd])
-
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- */
- SCI_SetSavePoint(hwnd=0){
-
- return SCI_sendEditor(hwnd, "SCI_SETSAVEPOINT")
- }
-
- /*
- Function: SetReadOnly
- <http://www.scintilla.org/ScintillaDoc.html#SCI_SETREADONLY>
-
- These messages set and get the read-only flag for the document. If you mark a document as read only, attempts to modify the text cause the *SCN_MODIFYATTEMPTRO* notification.
-
- Parameters:
- SCI_SetReadOnly(roMode[, hwnd])
-
- roMode - True (1) or False (0).
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- */
- SCI_SetReadOnly(roMode, hwnd=0){
-
- return SCI_sendEditor(hwnd, "SCI_SETREADONLY", roMode)
- }
-
- /*
- Function: SetStyleBits
- <http://www.scintilla.org/ScintillaDoc.html#SCI_SETSTYLEBITS>
-
- This Routine sets the number of bits in each cell to use for styling, to a maximum of 8 style bits. The remaining bits can be used as indicators. The standard setting is *SCI_SETSTYLEBITS(5)*. The number of styling bits needed by the current lexer can be found with <GetStyleBitsNeeded>.
-
- Parameters:
- SCI_SetStyleBits(bits[, hwnd])
-
- bits -
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- */
- SCI_SetStyleBits(bits, hwnd=0){
-
- return SCI_sendEditor(hwnd, "SCI_SETSTYLEBITS", bits)
- }
-
- /*
- Function: SetLengthForEncode
- http://www.scintilla.org/ScintillaDoc.html#SCI_SETLENGTHFORENCODE
-
- <EncodedFromUTF8()> converts a UTF-8 string into the document's encoding which is useful for taking the
- results of a find dialog, for example, and receiving a string of bytes that can be searched for in the
- document. Since the text can contain nul bytes, the *SetLengthForEncode()* method can be used to set the
- length that will be converted. If set to -1, the length is determined by finding a nul byte. The length of the
- converted string is returned.
-
- Parameters:
- SCI_SetLengthForEncode(bytes[, hwnd])
-
- bytes - Length of the string that will be converted with <EncodedFromUTF8()>
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- */
- SCI_SetLengthForEncode(bytes, hwnd=0){
-
- return SCI_sendEditor(hwnd, "SCI_SETLENGTHFORENCODE", bytes)
- }
-
- ; Group: Text Get Functions
-
- /*
- Function: GetText
- <http://www.scintilla.org/ScintillaDoc.html#SCI_GETTEXT>
-
- This returns len-1 characters of text from the start of the document plus one terminating 0 character.
- To collect all the text in a document, use <GetLength()> to get the number of characters in the document
- (nLen), allocate a character buffer of length nLen+1 bytes, then call *GetText*(nLen+1, vText).
- If the vText argument is 0 then the length that should be allocated to store the entire document is returned.
- If you then save the text, you should use <SetSavePoint()> to mark the text as unmodified.
-
- See also: <GetSelText()>, <GetCurLine()>, <GetLine()>, <GetStyledText()>, <GetTextRange()>
-
- Parameters:
- len -
- vText -
-
- Returns:
-
- Examples:
- */
- SCI_GetText(len=0, Byref vText=0, hwnd=0){
-
- VarSetCapacity(str, len * (a_isunicode ? 2 : 1)), cLen := SCI_sendEditor(hwnd, "SCI_GETTEXT", len, &str)
- vText := StrGet(&str, "CP0")
- return cLen
- }
-
- ; /* needs work (LineLenght() from selection and information)
- ; Function: GetLine
- ; <http://www.scintilla.org/ScintillaDoc.html#SCI_GETLINE>
-
- ; This fills the buffer defined by text with the contents of the nominated line (lines start at 0). The buffer
- ; is not terminated by a 0 character. It is up to you to make sure that the buffer is long enough for the text,
- ; use <LineLength()> for that. The returned value is the number of characters copied to the buffer.
- ; The returned text includes any end of line characters. If you ask for a line number outside the range of lines
- ; in the document, 0 characters are copied. If the text argument is 0 then the length that should be allocated
- ; to store the entire line is returned.
-
- ; See also: <GetCurLine()>, <GetSelText()>, <GetTextRange()>, <GetStyledText()>, <GetText()>
-
- ; */
- ; SCI_GetLine(line, vText, hwnd=0){
-
- ; VarSetCapacity(str, SCI_LineLength(hwnd) * (a_isunicode ? 2 : 1))
- ; cLen := SCI_sendEditor(hwnd, "SCI_GETLINE", len, &str)
- ; vText := StrGet(&str, "CP0")
- ; return cLen
- ; }
-
- /*
- Function: GetReadonly
- <http://www.scintilla.org/ScintillaDoc.html#SCI_GETREADONLY>
-
- This function gets the read-only flag for the document. If you mark a document as read only, attempts to
- modify the text cause the *SCN_MODIFYATTEMPTRO* notification.
-
- Parameters:
-
- */
- SCI_GetReadonly(){
-
- return
- }
-
- /*
- Function: GetTextRange
- <http://www.scintilla.org/ScintillaDoc.html#SCI_GETTEXTRANGE>
-
- This collects the text between the positions cpMin and cpMax and copies it to lpstrText (see struct
- <SCI_TextRange>). If cpMax is -1, text is returned to the end of the document. The text is 0 terminated, so
- you must supply a buffer that is at least 1 character longer than the number of characters you wish to read.
- The return value is the length of the returned text not including the terminating 0.
-
- See also: <SCI_GetSelText()>, <SCI_GetLine()>, <SCI_GetCurLine()>, <SCI_GetStyledText()>, <SCI_GetText()>
- */
- SCI_GetTextRange(){
- }
-
- /*
- Function: GetCharAt
- <http://www.scintilla.org/ScintillaDoc.html#SCI_GETCHARAT>
-
- This returns the character at pos in the document or 0 if pos is negative or past the end of the document.
- */
- SCI_GetCharAt(){
-
- return
- }
-
- /*
- Function: GetStyleAt
- <http://www.scintilla.org/ScintillaDoc.html#SCI_GETSTYLEAT>
-
- This returns the style at pos in the document, or 0 if pos is negative or past the end of the document.
- */
- SCI_GetStyleAt(){
-
- return
- }
-
- /*
- Function: GetStyledText
- <http://www.scintilla.org/ScintillaDoc.html#SCI_GETSTYLEDTEXT>
-
- This collects styled text into a buffer using two bytes for each cell, with the character at the lower address
- of each pair and the style byte at the upper address. Characters between the positions cpMin and cpMax are
- copied to lpstrText (see struct <SCI_TextRange>). Two 0 bytes are added to the end of the text, so the buffer
- that lpstrText points at must be at least 2*(cpMax-cpMin)+2 bytes long. No check is made for sensible values
- of cpMin or cpMax. Positions outside the document return character codes and style bytes of 0.
-
- See also: <GetSelText()>, <GetLine()>, <GetCurLine()>, <GetTextRange()>, <GetText()>
- */
- SCI_GetStyledText(){
-
- return
- }
-
- /*
- Function: GetStyleBits
- <http://www.scintilla.org/ScintillaDoc.html#SCI_GETSTYLEBITS>
-
- This routine reads back the number of bits in each cell to use for styling, to a maximum of 8 style bits. The
- remaining bits can be used as indicators. The standard setting is *SetStyleBits(5)*. The number of styling
- bits needed by the current lexer can be found with <GetStyleBitsNeeded()>.
- */
- SCI_GetStyleBits(){
-
- return
- }
-
- /* Group: Selection and information
- */
-
- /*
- Function: GetTextLength
- <http://www.scintilla.org/ScintillaDoc.html#SCI_GETTEXTLENGTH>
-
- Returns the length of the document in bytes.
-
- Parameters:
- SCI_GetTextLength([hwnd])
-
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns
- nLen - Length of the document in bytes.
-
- Examples
- */
- SCI_GetTextLength(hwnd=0){
-
- return SCI_sendEditor(hwnd, "SCI_GETTEXTLENGTH")
- }
-
- /*
- Function: GetLength
- <http://www.scintilla.org/ScintillaDoc.html#SCI_GETLENGTH>
-
- Returns the length of the document in bytes.
-
- Parameters:
- SCI_GetLength([hwnd])
-
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns
- nLen - Length of the document in bytes.
-
- Examples
- */
- SCI_GetLength(hwnd=0){
-
- return SCI_sendEditor(hwnd, "SCI_GETLENGTH")
- }
-
- /* Group: Style Definition
- <http://www.scintilla.org/ScintillaDoc.html#StyleDefinition>
-
- While the style setting messages mentioned above change the style numbers associated with text, these messages
- define how those style numbers are interpreted visually. There are 256 lexer styles that can be set, numbered 0
- to *STYLE_MAX* (255). Unless you use *SCI_SETSTYLEBITS* to change the number of style bits,
- styles 0 to 31 are used to set the text attributes. There are also some predefined numbered styles starting at
- 32, The following *STYLE_** constants are defined:
-
- - *STYLE_DEFAULT* (32) This style defines the attributes that all styles receive when the
- *SCI_STYLECLEARALL* message is used.
-
- - *STYLE_LINENUMBER* (33) This style sets the attributes of the text used to display line numbers in a line
- number margin. The background colour set for this style also sets the background colour for all margins that do
- not have any folding mask bits set. That is, any margin for which mask & *SC_MASK_FOLDERS* is 0. See
- *SCI_SETMARGINMASKN* for more about masks.
-
- - *STYLE_BRACELIGHT* (34) This style sets the attributes used when highlighting braces with the
- *SCI_BRACEHIGHLIGHT* message and when highlighting the corresponding indentation with *SCI_SETHIGHLIGHTGUIDE*.
-
- - *STYLE_BRACEBAD* (35) This style sets the display attributes used when marking an unmatched brace with the
- *SCI_BRACEBADLIGHT* message.
-
- - *STYLE_CONTROLCHAR* (36) This style sets the font used when drawing control characters. Only the font, size,
- bold, italics, and character set attributes are used and not the colour attributes. See also:
- *SCI_SETCONTROLCHARSYMBOL*.
-
- - *STYLE_INDENTGUIDE* (37) This style sets the foreground and background colours used when drawing the
- indentation guides.
-
- - *STYLE_CALLTIP* (38) Call tips normally use the font attributes defined by *STYLE_DEFAULT*. Use of
- *SCI_CALLTIPUSESTYLE* causes call tips to use this style instead. Only the font face name, font size, foreground
- and background colours and character set attributes are used.
-
- - *STYLE_LASTPREDEFINED* (39) To make it easier for client code to discover the range of styles that are
- predefined, this is set to the style number of the last predefined style. This is currently set to 39 and the
- last style with an identifier is 38, which reserves space for one future predefined style.
-
- - *STYLE_MAX* (255) This is not a style but is the number of the maximum style that can be set. Styles
- between *STYLE_LASTPREDEFINED* and *STYLE_MAX* would be appropriate if you used *SCI_SETSTYLEBITS* to set more
- than 5 style bits.
-
- For each style you can set the font name, size and use of bold, italic and underline, foreground and background colour and the character set. You can also choose to hide text with a given style, display all characters as upper or lower case and fill from the last character on a line to the end of the line (for embedded languages). There is also an experimental attribute to make text read-only.
-
- It is entirely up to you how you use styles. If you want to use syntax colouring you might use style 0 for white space, style 1 for numbers, style 2 for keywords, style 3 for strings, style 4 for preprocessor, style 5 for operators, and so on.
- */
-
- ; Group: General Style Functions
-
- /*
- Function: StyleResetDefault
- <http://www.scintilla.org/ScintillaDoc.html#SCI_STYLERESETDEFAULT>
-
- This message resets STYLE_DEFAULT to its state when Scintilla was initialised.
-
- Parameters:
- SCI_StyleResetDefault([hwnd])
-
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- >SCI_StyleResetDefault(hSci)
- */
- SCI_StyleResetDefault(hwnd=0){
-
- return SCI_sendEditor(hwnd, "SCI_STYLERESETDEFAULT")
- }
-
- /*
- Function: StyleClearAll
- <http://www.scintilla.org/ScintillaDoc.html#SCI_STYLECLEARALL>
-
- This message sets all styles to have the same attributes as STYLE_DEFAULT.
- If you are setting up Scintilla for syntax coloring, it is likely that the lexical styles you set
- will be very similar. One way to set the styles is to:
-
- - Set STYLE_DEFAULT to the common features of all styles.
- - Use SCI_STYLECLEARALL to copy this to all styles.
- - Set the style attributes that make your lexical styles different.
-
- Parameters:
- SCI_StyleClearAll([hwnd])
-
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- >SCI_StyleClearAll(hSci)
- */
- SCI_StyleClearAll(hwnd=0){
-
- return SCI_sendEditor(hwnd, "SCI_STYLECLEARALL")
- }
-
- ; Group: Set Style Functions
-
- /*
- Function: StyleSetFont
- <http://www.scintilla.org/ScintillaDoc.html#SCI_STYLESETFONT>
-
- These functions (plus SCI_StyleSetCharacterset) set the font attributes that are used to match
- the fonts you request to those available. The fName parameter is a zero terminated string holding
- the name of a font. Under Windows, only the first 32 characters of the name are used and
- the name is not case sensitive. For internal caching, Scintilla tracks fonts by name
- and does care about the casing of font names, so please be consistent.
-
- Parameters:
- SCI_StyleSetFont(stNumber, fName[, hwnd])
-
- stNumber - Style Number on which to operate.
- There are 256 lexer styles that can be set, numbered 0 to *STYLE_MAX* (255)
- See: <http://www.scintilla.org/ScintillaDoc.html#StyleDefinition>.
- fName - Name of the font to apply.
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- (Start Code)
- #include ../SCI.ahk
-
- Gui +LastFound
- hwnd:=WinExist()
- hSci1:=SCI_Add(hwnd, x, y, w, h, "WS_CHILD WS_VISIBLE")
- hSci2:=SCI_Add(hwnd, x, 290, w, h, "WS_CHILD WS_VISIBLE")
- Gui, show, w400 h570
-
- ; Each component will have its own font
- SCI_StyleSetFont("STYLE_DEFAULT", "Courier New", hSci1)
- SCI_StyleSetFont("STYLE_DEFAULT", "Arial Black", hSci2)
- return
- (End)
- */
- SCI_StyleSetFont(stNumber, fName, hwnd=0){
-
- a_isunicode ? (VarSetCapacity(fNameA, StrPut(fName, "CP0")), StrPut(fName, &fNameA, "CP0"))
- return SCI_sendEditor(hwnd, "SCI_STYLESETFONT", stNumber, a_isunicode ? &fNameA : &fName)
- }
-
- /*
- Function: StyleSetSize
- <http://www.scintilla.org/ScintillaDoc.html#SCI_STYLESETSIZE>
-
- Parameters:
- SCI_StyleSetSize(stNumber, fSize[, hwnd])
-
- stNumber - Style Number on which to operate.
- There are 256 lexer styles that can be set, numbered 0 to *STYLE_MAX* (255)
- See: <http://www.scintilla.org/ScintillaDoc.html#StyleDefinition>.
- fSize - Size in points of the font to apply.
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- (Start Code)
- #include ../SCI.ahk
-
- Gui +LastFound
- hwnd:=WinExist()
- hSci1:=SCI_Add(hwnd, x, y, w, h, "WS_CHILD WS_VISIBLE")
- hSci2:=SCI_Add(hwnd, x, 290, w, h, "WS_CHILD WS_VISIBLE")
- Gui, show, w400 h570
-
- ; Each component will have its own font size
- SCI_StyleSetSize("STYLE_DEFAULT", 12, hSci1)
- SCI_StyleSetSize("STYLE_DEFAULT", 32, hSci2)
- return
- (End)
- */
- SCI_StyleSetSize(stNumber, fSize, hwnd=0){
-
- return SCI_sendEditor(hwnd, "SCI_STYLESETSIZE", stNumber, fSize)
- }
-
- /*
- Function: StyleSetBold
- <http://www.scintilla.org/ScintillaDoc.html#SCI_STYLESETBOLD>
-
- Parameters:
- SCI_StyleSetBold(stNumber, bMode[, hwnd])
-
- stNumber - Style Number on which to operate.
- There are 256 lexer styles that can be set, numbered 0 to *STYLE_MAX* (255)
- See: <http://www.scintilla.org/ScintillaDoc.html#StyleDefinition>.
- bMode - True (1) or False (0).
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- (Start Code)
- #include ../SCI.ahk
-
- Gui +LastFound
- hwnd:=WinExist()
- hSci1:=SCI_Add(hwnd, x, y, w, h, "WS_CHILD WS_VISIBLE")
- hSci2:=SCI_Add(hwnd, x, 290, w, h, "WS_CHILD WS_VISIBLE")
- Gui, show, w400 h570
-
- ; Each component will have its own bold status
- SCI_StyleSetBold("STYLE_DEFAULT", True, hSci1)
- SCI_StyleSetBold("STYLE_DEFAULT", False, hSci2)
- return
- (End)
- */
- SCI_StyleSetBold(stNumber, bMode, hwnd=0){
-
- return SCI_sendEditor(hwnd, "SCI_STYLESETBOLD", stNumber, bMode)
- }
-
- /*
- Function: StyleSetItalic
- <http://www.scintilla.org/ScintillaDoc.html#SCI_STYLESETITALIC>
-
- Parameters:
- SCI_StyleSetItalic(stNumber, iMode[, hwnd])
-
- stNumber - Style Number on which to operate.
- There are 256 lexer styles that can be set, numbered 0 to *STYLE_MAX* (255)
- See: <http://www.scintilla.org/ScintillaDoc.html#StyleDefinition>.
- iMode - True (1) or False (0).
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- (Start Code)
- #include ../SCI.ahk
-
- Gui +LastFound
- hwnd:=WinExist()
- hSci1:=SCI_Add(hwnd, x, y, w, h, "WS_CHILD WS_VISIBLE")
- hSci2:=SCI_Add(hwnd, x, 290, w, h, "WS_CHILD WS_VISIBLE")
- Gui, show, w400 h570
-
- ; Each component will have its own bold status
- SCI_StyleSetItalic("STYLE_DEFAULT", True, hSci1)
- SCI_StyleSetItalic("STYLE_DEFAULT", False, hSci2)
- return
- (End)
- */
- SCI_StyleSetItalic(stNumber, iMode, hwnd=0){
-
- return SCI_sendEditor(hwnd, "SCI_STYLESETITALIC", stNumber, iMode)
- }
-
- /*
- Function: StyleSetUnderline
- <http://www.scintilla.org/ScintillaDoc.html#SCI_STYLESETUNDERLINE>
-
- Parameters:
- SCI_StyleSetUnderline(stNumber, uMode[, hwnd])
-
- stNumber - Style Number on which to operate.
- There are 256 lexer styles that can be set, numbered 0 to *STYLE_MAX* (255)
- See: <http://www.scintilla.org/ScintillaDoc.html#StyleDefinition>.
- uMode - True (1) or False (0).
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Note:
- - If you set the underline option for the *STYLE_DEFAULT* style
- you *have* to call <StyleClearAll()> for the changes to take effect.
-
- Examples:
- (Start Code)
- #include ../SCI.ahk
-
- Gui +LastFound
- hwnd:=WinExist()
- hSci1:=SCI_Add(hwnd, x, y, w, h, "WS_CHILD WS_VISIBLE")
- hSci2:=SCI_Add(hwnd, x, 290, w, h, "WS_CHILD WS_VISIBLE")
- Gui, show, w400 h570
-
- ; Each component will have its own underline status
- SCI_StyleSetUnderline("STYLE_DEFAULT", True, hSci1)
- SCI_StyleClearAll() ; the last hwnd is remembered by the wrapper, so no need to put it here.
- SCI_StyleSetUnderline("STYLE_DEFAULT", False, hSci2)
- SCI_StyleClearAll() ; the last hwnd is remembered by the wrapper, so no need to put it here.
- return
- (End)
- */
- SCI_StyleSetUnderline(stNumber, uMode, hwnd=0){
-
- return SCI_sendEditor(hwnd, "SCI_STYLESETUNDERLINE", stNumber, uMode)
- }
-
- /*
- Function: StyleSetFore
- <http://www.scintilla.org/ScintillaDoc.html#SCI_STYLESETFORE>
-
- Sets the foreground color of the specified style number.
-
- Parameters:
- SCI_StyleSetFore(stNumber, r, [g, b, hwnd])
-
- stNumber - Style Number on which to operate.
- There are 256 lexer styles that can be set, numbered 0 to *STYLE_MAX* (255)
- See: <http://www.scintilla.org/ScintillaDoc.html#StyleDefinition>.
- r,g,b - Colors are set using the RGB format (Red, Green, Blue). The intensity of each color
- is set in the range 0 to 255.
-
- - *Note 1:* If you set all intensities to 255, the color is white.
- If you set all intensities to 0, the color is black.
- When you set a color, you are making a request.
- What you will get depends on the capabilities of the system and the current screen mode.
-
- - *Note 2:* If you omit *g* and *b* you can specify the hex value of the color as
- well as one of the many predefined names available.
- You can take a look at the available color names with their hex values here:
- <http://www.w3schools.com/html/html_colornames.asp>.
-
- - *Note 3:* the parameter *g* can be used to specify the hwnd of the component you want
- to control, only if you are using *r* to specify a hex value or a color name.
- See the examples below for more information.
-
- hwnd - The hwnd of the control that you want to operate on. Useful for when you have more than 1
- Scintilla components in the same script. The wrapper will remember the last used hwnd,
- so you can specify it once and only specify it again when you want to operate on a different
- component.
-
- Note:
- - If you change the color of the *STYLE_DEFAULT* style
- you *have* to call <StyleClearAll()> for the changes to take effect.
- This is not true for setting the background color though.
-
-
- Returns:
- Zero - Nothing is returned by this function.
-
- Examples:
- (Start Code)
- ; This all mean the same
- SCI_StyleSetFore("STYLE_DEFAULT", 0xFF0000, hSci) ; using the parameter g to specify the hwnd.
- SCI_StyleSetFore("STYLE_DEFAULT", "red", hSci)
- SCI_StyleSetFore("STYLE_DEFAULT", 255,0,0, hSci) ; using the last parameter to specify the hwnd.
-
- ; Remember to always call SCI_StyleClearAll()
- ; if you are setting the foreground color of the STYLE_DEFAULT style
- SCI_StyleClearAll()
-
- ;---------------------
- #include ../SCI.ahk
-
- Gui +LastFound
- hwnd:=WinExist()
- hSci1:=SCI_Add(hwnd, x, y, w, h, "WS_CHILD WS_VISIBLE")
- hSci2:=SCI_Add(hwnd, x, 290, w, h, "WS_CHILD WS_VISIBLE")
- Gui, show, w400 h570
-
- SCI_StyleSetFore("STYLE_DEFAULT", 0xFF0000, hSci1)
- SCI_StyleClearAll() ; the last hwnd is remembered by the wrapper, so no need to put it here.
- SCI_StyleSetFore("STYLE_DEFAULT", "blue", hSci2)
- SCI_StyleClearAll() ; the last hwnd is remembered by the wrapper, so no need to put it here.
- return
- (End)
- */
- SCI_StyleSetFore(stNumber, r, g=0, b=0, hwnd=0){…