Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scintilla control modifies line text and Lexer
#1
Hi,

The following code, I can:
1.Use the hotkey Ctrl+Q to add // to the beginning of the current line
2.Use the hotkey Alt+Q to Replace the text of the current line
But it's not perfect. It flashes during execution. Can it be executed in the background without selecting the line text?

In addition, Can i use Scintilla control built-in language Lexer(Keywords auto coloring, As shown in the picture below)? Can anyone provide an example?
[Image: 1676708532]

I want to switch different code coloring Lexer schemes by pushing buttons, As shown in the picture below​​​​​​​
[Image: 1676708486]
Thanks in advance for any advice and help
david


Macro Macro5
Code:
Copy      Help
;
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 384 240 "Dialog" "4"
;3 Scintilla 0x54000000 0x20000 8 8 368 206 ""
;4 Button 0x54032000 0x0 40 220 48 14 "C# Lexer"
;5 Button 0x54032000 0x0 104 220 48 14 "QM Lexer"
;6 Button 0x54032000 0x4 168 220 70 14 "Powershell  Lexer"
;1 Button 0x54030001 0x4 268 220 48 14 "OK"
;2 Button 0x54030000 0x4 328 220 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls="3"
str cs3
cs3=
;using System;
;namespace HelloWorld
;{
;,/// <summary>
;,/// Summary description for Class1.
;,/// </summary>
;,class HelloWorldClass
;,{
;,,static void Main(string[] args)
;,,{
;,,,Console.WriteLine("Hello World!");
;,,,Console.ReadLine();
;,,}
;,}
;}

str qm3.getmacro

str ps3=
;$Hash = @{ }
;$Hash = @{ a = 1; b = 2; c = 3 }
;$Hash.Add('d', 4)
;$Hash.ContainsKey('d')
;$Hash['d']
;$Hash.GetEnumerator() | Sort-Object Name

int sci

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,DT_SetAccelerators(hDlg "401 Cq[]402 Aq")
,sci=id(3 hDlg)
,sub.SetText cs3
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 401 ;;Ctrl+Q: add //
,sub.Sci(SCI.SCI_MOVESELECTEDLINESDOWN 0 0)
,sub.Sci(SCI.SCI_MOVESELECTEDLINESUP 0 0)
,_s.getsel
,_s-"//"
,_s.setsel
,
,case 402 ;;Alt+Q:  Modify the current line text
,sub.Sci(SCI.SCI_MOVESELECTEDLINESDOWN 0 0)
,sub.Sci(SCI.SCI_MOVESELECTEDLINESUP 0 0)
,_s.getsel
,_s=
,;hello world
,_s+"[]"
,_s.setsel
,
,case 4 ;;C# Lexer
,sub.SetText cs3
,
,case 5 ;;QM Lexer
,sub.SetText qm3
,
,case 6 ;;Powershell Lexer
,sub.SetText ps3

ret 1

#sub Sci v
function# message [param1] [param2]
ret SendMessage(sci message param1 param2)

#sub Sci2 v
function# message [param1] [$text]
ret SendMessage(sci message param1 text)

#sub GetText v
function str&text
int n=SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0)
text.fix(SendMessage(sci SCI.SCI_GETTEXT n+1 text.all(n)))

#sub SetText v
function $text
sub.Sci2(SCI.SCI_SETTEXT 0 text)
#2
The QM's qmsci.dll does not have most or all lexers. Instead use 2 dlls from Scite.

All info is in the Scintilla website.
#3
Thanks for your help
How to implement the following commands in QM?  My code doesn't work

SCI_GETLINE(line line, char *text) → position
 
Code:
Copy      Help
,act sci
,int cp=SendMessage(sci SCI.SCI_GETCURRENTPOS 0 0)
,int line=SendMessage(sci SCI.SCI_LINEFROMPOSITION cp 0)
,SendMessage(sci SCI.SCI_GETLINE line _s)
,mes _s

SCI_GETCURLINE(position length, char *text NUL-terminated) → position
 
Code:
Copy      Help
,act sci
,int cp=SendMessage(sci SCI.SCI_GETCURRENTPOS 0 0)
,int line=SendMessage(sci SCI.SCI_LINEFROMPOSITION cp 0)
,int length=SendMessage(sci SCI.SCI_LINELENGTH line 0)
,SendMessage(sci SCI.SCI_GETCURLINE length _s)
,mes _s

autoit related code:
Code:
Copy      Help
Local $ret, $iPos = SendMessage($Sci, $SCI_GETCURRENTPOS, 0, 0)

$iLen = SendMessage($Sci, $SCI_GETCURLINE, 0, 0)

$sBuf = DllStructCreate("byte[" & $iLen & "]")

$ret = DllCall($user32, "long", "SendMessageA", "long", $Sci, "int", $SCI_GETCURLINE, "int", $iLen, "ptr", DllStructGetPtr($sBuf))

$current = $ret[0]

$startword = $current
#4
you need to allocate the string buffer

SCI_GETCURLINE
Code:
Copy      Help
int length=SendMessage(sci SCI.SCI_GETCURLINE 0 0)
str text.all(length 2)
SendMessage(sci SCI.SCI_GETCURLINE length text)
mes text

SCI_GETLINE
Code:
Copy      Help
int cp=SendMessage(sci SCI.SCI_GETCURRENTPOS 0 0)
int line=SendMessage(sci SCI.SCI_LINEFROMPOSITION cp 0)
int length2=SendMessage(sci SCI.SCI_LINELENGTH line 0)
str text.all(length2 2)
SendMessage(sci SCI.SCI_GETLINE line text)
mes text
#5
kevin, thanks for your help!

The code changes as follows, No flicker, But the code is a little long, and there might be an easier way

about Ctrl+Q:
 
Code:
Copy      Help
,int cp=SendMessage(sci SCI.SCI_GETCURRENTPOS 0 0)
,int line=SendMessage(sci SCI.SCI_LINEFROMPOSITION cp 0)
,
,int Start=SendMessage(sci SCI.SCI_POSITIONFROMLINE line 0)
,SendMessage(sci SCI.SCI_SETTARGETSTART Start 0)
,
,int End=SendMessage(sci SCI.SCI_GETLINEENDPOSITION line 0)
,SendMessage(sci SCI.SCI_SETTARGETEND End 0)
,
,int length=End-Start
,SendMessage(sci SCI.SCI_GETCURLINE length+1 _s.all(length 2))
,
,SendMessage sci SCI.SCI_REPLACETARGET 0 0
,
,_s-"//"
,SendMessage(sci SCI.SCI_INSERTTEXT Start _s)
,SendMessage(sci SCI.SCI_LINEEND 0 0)

about Alt+Q:
 
Code:
Copy      Help
,cp=SendMessage(sci SCI.SCI_GETCURRENTPOS 0 0)
,line=SendMessage(sci SCI.SCI_LINEFROMPOSITION cp 0)
,
,lineStart=SendMessage(sci SCI.SCI_POSITIONFROMLINE line 0)
,SendMessage(sci SCI.SCI_SETTARGETSTART lineStart 0)
,
,lineEnd=SendMessage(sci SCI.SCI_GETLINEENDPOSITION line 0)
,SendMessage(sci SCI.SCI_SETTARGETEND lineEnd 0)
,
,SendMessage sci SCI.SCI_REPLACETARGET 0 0
,
,_s="hello world"
,SendMessage(sci SCI.SCI_INSERTTEXT lineStart _s)
,SendMessage(sci SCI.SCI_LINEEND 0 0)
#6
Use the code above:
There is a small problem, ctrl+Z does not restore directly, need to press ctrl+Z twice
#7
I found two 32-bit dll files ver5.3.3 :  Lexilla.dll and Scintilla.dll (in the attachment below)

The following two commands cannot be executed with the following code
 
Code:
Copy      Help
SendMessage(sci SCI.SETLEXER SCLEX_CPP 0)
 
Code:
Copy      Help
,SendMessage(sci SCI.SETLEXER SCLEX_POWERSHELL 0)


Macro Macro5
 
Code:
Copy      Help
LoadLibraryW(@_s.expandpath("$desktop$\sci\Lexilla.dll"))
LoadLibraryW(@_s.expandpath("$desktop$\sci\Scintilla.dll"))

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 384 240 "Dialog" "4"
;3 Scintilla 0x54000000 0x20000 8 8 368 206 ""
;4 Button 0x54032000 0x0 40 220 48 14 "C# Lexer"
;5 Button 0x54032000 0x0 104 220 48 14 "QM Lexer"
;6 Button 0x54032000 0x4 168 220 70 14 "Powershell  Lexer"
;1 Button 0x54030001 0x4 268 220 48 14 "OK"
;2 Button 0x54030000 0x4 328 220 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls="3"
str cs3
cs3=
;using System;
;namespace HelloWorld
;{
;,/// <summary>
;,/// Summary description for Class1.
;,/// </summary>
;,class HelloWorldClass
;,{
;,,static void Main(string[] args)
;,,{
;,,,Console.WriteLine("Hello World!");
;,,,Console.ReadLine();
;,,}
;,}
;}

str qm3.getmacro

str ps3=
;$Hash = @{ }
;$Hash = @{ a = 1; b = 2; c = 3 }
;$Hash.Add('d', 4)
;$Hash.ContainsKey('d')
;$Hash['d']
;$Hash.GetEnumerator() | Sort-Object Name

int sci

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,sci=id(3 hDlg)
,sub.SetText cs3
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 4 ;;C# Lexer
,sub.SetText cs3
,;SendMessage(sci SCI.SETLEXER SCLEX_CPP 0)
,
,case 5 ;;QM Lexer
,sub.SetText qm3
,
,case 6 ;;Powershell Lexer
,sub.SetText ps3
,;SendMessage(sci SCI.SETLEXER SCLEX_POWERSHELL 0)

ret 1

#sub Sci v
function# message [param1] [param2]
ret SendMessage(sci message param1 param2)

#sub Sci2 v
function# message [param1] [$text]
ret SendMessage(sci message param1 text)

#sub GetText v
function str&text
int n=SendMessage(sci SCI.SCI_GETTEXTLENGTH 0 0)
text.fix(SendMessage(sci SCI.SCI_GETTEXT n+1 text.all(n)))

#sub SetText v
function $text
sub.Sci2(SCI.SCI_SETTEXT 0 text)

I found the code for ScintillaNET. It's not very long
 
C# code:

namespace ScintillaNET.Demo {
public partial class MainForm : Form {
public MainForm() {
InitializeComponent();
}

ScintillaNET.Scintilla TextArea;

private void MainForm_Load(object sender, EventArgs e) {

// CREATE CONTROL
TextArea = new ScintillaNET.Scintilla();
TextPanel.Controls.Add(TextArea);

// BASIC CONFIG
TextArea.Dock = System.Windows.Forms.DockStyle.Fill;
TextArea.TextChanged += (this.OnTextChanged);

// INITIAL VIEW CONFIG
TextArea.WrapMode = WrapMode.None;
TextArea.IndentationGuides = IndentView.LookBoth;

// STYLING
InitColors();
InitSyntaxColoring();
}

private void InitColors() {

TextArea.SetSelectionBackColor(true, IntToColor(0x114D9C));

}

private void InitSyntaxColoring() {

// Configure the default style
TextArea.StyleResetDefault();
TextArea.Styles[Style.Default].Font = "Consolas";
TextArea.Styles[Style.Default].Size = 10;
TextArea.Styles[Style.Default].BackColor = IntToColor(0x212121);
TextArea.Styles[Style.Default].ForeColor = IntToColor(0xFFFFFF);
TextArea.StyleClearAll();

// Configure the CPP (C#) lexer styles
TextArea.Styles[Style.Cpp.Identifier].ForeColor = IntToColor(0xD0DAE2);
TextArea.Styles[Style.Cpp.Comment].ForeColor = IntToColor(0xBD758B);
TextArea.Styles[Style.Cpp.CommentLine].ForeColor = IntToColor(0x40BF57);
TextArea.Styles[Style.Cpp.CommentDoc].ForeColor = IntToColor(0x2FAE35);
TextArea.Styles[Style.Cpp.Number].ForeColor = IntToColor(0xFFFF00);
TextArea.Styles[Style.Cpp.String].ForeColor = IntToColor(0xFFFF00);
TextArea.Styles[Style.Cpp.Character].ForeColor = IntToColor(0xE95454);
TextArea.Styles[Style.Cpp.Preprocessor].ForeColor = IntToColor(0x8AAFEE);
TextArea.Styles[Style.Cpp.Operator].ForeColor = IntToColor(0xE0E0E0);
TextArea.Styles[Style.Cpp.Regex].ForeColor = IntToColor(0xff00ff);
TextArea.Styles[Style.Cpp.CommentLineDoc].ForeColor = IntToColor(0x77A7DB);
TextArea.Styles[Style.Cpp.Word].ForeColor = IntToColor(0x48A8EE);
TextArea.Styles[Style.Cpp.Word2].ForeColor = IntToColor(0xF98906);
TextArea.Styles[Style.Cpp.CommentDocKeyword].ForeColor = IntToColor(0xB3D991);
TextArea.Styles[Style.Cpp.CommentDocKeywordError].ForeColor = IntToColor(0xFF0000);
TextArea.Styles[Style.Cpp.GlobalClass].ForeColor = IntToColor(0x48A8EE);

TextArea.Lexer = Lexer.Cpp;

TextArea.SetKeywords(0, "class extends implements import interface new case do while else if for in switch throw get set function var try catch finally while with default break continue delete return each const namespace package include use is as instanceof typeof author copy default deprecated eventType example exampleText exception haxe inheritDoc internal link mtasc mxmlc param private return see serial serialData serialField since throws usage version langversion playerversion productversion dynamic private public partial static intrinsic internal native override protected AS3 final super this arguments null Infinity NaN undefined true false abstract as base bool break by byte case catch char checked class const continue decimal default delegate do double descending explicit event extern else enum false finally fixed float for foreach from goto group if implicit in int interface internal into is lock long new null namespace object operator out override orderby params private protected public readonly ref return switch struct sbyte sealed short sizeof stackalloc static string select this throw true try typeof uint ulong unchecked unsafe ushort using var virtual volatile void while where yield");
TextArea.SetKeywords(1, "void Null ArgumentError arguments Array Boolean Class Date DefinitionError Error EvalError Function int Math Namespace Number Object RangeError ReferenceError RegExp SecurityError String SyntaxError TypeError uint XML XMLList Boolean Byte Char DateTime Decimal Double Int16 Int32 Int64 IntPtr SByte Single UInt16 UInt32 UInt64 UIntPtr Void Path File System Windows Forms ScintillaNET");

}

private void OnTextChanged(object sender, EventArgs e) {

}

#region Numbers, Bookmarks, Code Folding

/// <summary>
/// the background color of the text area
/// </summary>
private const int BACK_COLOR = 0x2A211C;

/// <summary>
/// default text color of the text area
/// </summary>
private const int FORE_COLOR = 0xB7B7B7;

/// <summary>
/// change this to whatever margin you want the line numbers to show in
/// </summary>
private const int NUMBER_MARGIN = 1;

/// <summary>
/// change this to whatever margin you want the bookmarks/breakpoints to show in
/// </summary>
private const int BOOKMARK_MARGIN = 2;
private const int BOOKMARK_MARKER = 2;

/// <summary>
/// change this to whatever margin you want the code folding tree (+/-) to show in
/// </summary>
private const int FOLDING_MARGIN = 3;

/// <summary>
/// set this true to show circular buttons for code folding (the [+] and [-] buttons on the margin)
/// </summary>
private const bool CODEFOLDING_CIRCULAR = true;

private void TextArea_MarginClick(object sender, MarginClickEventArgs e) {
if (e.Margin == BOOKMARK_MARGIN) {
// Do we have a marker for this line?
const uint mask = (1 << BOOKMARK_MARKER);
var line = TextArea.Lines[TextArea.LineFromPosition(e.Position)];
if ((line.MarkerGet() & mask) > 0) {
// Remove existing bookmark
line.MarkerDelete(BOOKMARK_MARKER);
} else {
// Add bookmark
line.MarkerAdd(BOOKMARK_MARKER);
}
}
}
#endregion
}
}



Attached Files
.zip   Scintilla_Lexilla.zip (Size: 903.95 KB / Downloads: 76)


Forum Jump:


Users browsing this thread: 1 Guest(s)