-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17790e3
commit 6b0ac0c
Showing
13 changed files
with
4,614 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/** | ||
* SciLoad uses the **LoadLibrary** function from **libloaderapi.h** | ||
* to load the Scintilla DLL library and bind a method named **`SciAdd`** | ||
* to the prototype of the global Gui class. **SciAdd** takes one | ||
* argument, the options parameter associated with **`Gui.Add`**. The | ||
* control returned from **SciAdd** owns a **`Send`** method used for | ||
* sending messages directly to the control via DLL calls, which takes | ||
* a *message*, optional *wparam*, and optional *lparam* as arguments. | ||
* | ||
* | ||
* @param {`String`} _sci_dll If left blank, "Scintilla.dll" will be searched | ||
* for in the current working directory. | ||
* @param {`String`} _lex_dll If left blank, "CustomLexer.dll" will be searched | ||
* for in the current working directory. | ||
* @return {`Object`} Pointers to the Scintilla.dll and CustomLexer.dll libraries | ||
* | ||
* ReturnObj := { | ||
* sci: 0x123456 ; scintilla.dll pointer | ||
* lex: 0x654321 ; customlexer.dll pointer | ||
* } | ||
*/ | ||
SciLoad(_sci_dll:="", _lex_dll:="") { | ||
; Load Scintilla library and obtain pointer | ||
_sci_pointer := DllCall( "LoadLibrary" ; | ||
, "Str", !!_sci_dll ? _sci_dll : "Scintilla.dll" ; | ||
, "Ptr" ) | ||
|
||
_lex_pointer := DllCall( "LoadLibrary" ; | ||
, "Str", !!_sci_dll ? _sci_dll : "CustomLexer.dll" ; | ||
, "Ptr" ) | ||
/** | ||
* Function to be attached to *`Gui.Prototype`*, allowing for a custom | ||
* Scintilla control to be added with a **`Send`** method for sending | ||
* messages to the control directly with DLL calls | ||
*/ | ||
SciAdd(_gui, _opts:="") { | ||
ctrl := _gui.Add("Custom", "ClassScintilla " _opts) | ||
ctrl.Send := SciCtrlSend | ||
ctrl.Send(0, 0, 0, ctrl.Hwnd) | ||
Return ctrl | ||
} | ||
|
||
; Set SciAdd method for global Gui class | ||
Gui.Prototype.SciAdd := SciAdd | ||
|
||
; Return pointer to Scintilla library | ||
Return { sci: _sci_pointer, lex: _lex_pointer } | ||
} | ||
|
||
/** | ||
* SciFree uses the **FreeLibrary** function from **libloaderapi.h** in System Services | ||
* @param {`Object`} _pointers Pointers to the Scintilla.dll and CustomLexer.dll libraries | ||
*/ | ||
SciFree(_pointers) { | ||
Try | ||
FileAppend("Freeing the Scintilla.dll Library...`n", "*") | ||
|
||
DllCall("FreeLibrary", "Ptr", _pointers.sci) | ||
|
||
Try | ||
FileAppend("Freeing the custom lexer dll library...`n", "*") | ||
|
||
DllCall("FreeLibrary", "Ptr", _pointers.lex) | ||
} | ||
|
||
/** | ||
* Retrieve direct references to a Scintilla function and pointer and store | ||
* them in static variables so as to avoid the overhead associated with | ||
* using SendMessage. The hwnd is stored in a static variable after first | ||
* usage (and subsequents). | ||
* @param {Int} _msg | ||
* @param {UInt} _wparam | ||
* @param {UInt} _lparam | ||
* @param {hWnd} _hwnd | ||
*/ | ||
SciSend(_msg, _wparam:=0, _lparam:=0, _hwnd:="") { | ||
static _init := False | ||
, _DirectFunction := "" | ||
, _DirectPointer := "" | ||
, _SCI_GETDIRECTFUNCTION := 2184 | ||
, _SCI_GETDIRECTPOINTER := 2185 | ||
if !_init and _hwnd { | ||
_init := True | ||
_DirectFunction := SendMessage(_SCI_GETDIRECTFUNCTION, 0, 0,, "ahk_id " _hwnd) | ||
_DirectPointer := SendMessage(_SCI_GETDIRECTPOINTER , 0, 0,, "ahk_id " _hwnd) | ||
Return | ||
} else if !_init and !_hwnd | ||
Return | ||
Return DllCall(_DirectFunction | ||
, "UInt", _DirectPointer | ||
, "Int" , _msg | ||
, "UInt", _wparam | ||
, "UInt", _lparam) | ||
} | ||
|
||
/** | ||
* If **_hwnd** is present and the *`_DirectFunction`* or *`_DirectPointer`* | ||
* property is not already set for **_ctrl**, a direct reference to a | ||
* Scintilla function and pointer are retrieved and stored as said | ||
* properties of **_ctrl**. Subsequent calls use the function and pointer | ||
* to send messages via DLL calls to the Scintilla ctrl without the | ||
* overhead associated with SendMessage. | ||
* | ||
* | ||
* This function is meant to be bound to a *`Gui.Custom`* Scintilla control, | ||
* and as such would pass a hidden **this** variable | ||
* into the first parameter (**_ctrl**), leaving only the remaining | ||
* parameters to be passed when calling. | ||
* | ||
* @param {Gui.Custom} _ctrl | ||
* @param {Any} _msg | ||
* @param {Integer} _wparam | ||
* @param {Integer} _lparam | ||
* @param {Hwnd} _hwnd | ||
*/ | ||
SciCtrlSend(_ctrl, _msg, _wparam:=0x00, _lparam:=0x00, _hwnd:=0x00) { | ||
static _SCI_GETDIRECTFUNCTION := 2184 | ||
, _SCI_GETDIRECTPOINTER := 2185 | ||
|
||
; Check for existence of function/pointer properties in _ctrl | ||
if !(_ctrl.HasOwnProp("_DirectFunction")) or !(_ctrl.HasOwnProp("_DirectPointer")) | ||
_init := false | ||
else _init := true | ||
|
||
; If properties aren't initialized, do so | ||
if (!_init and _hwnd) { | ||
_ctrl.DefineProp("_DirectFunction", { | ||
Value: SendMessage(_SCI_GETDIRECTFUNCTION, 0, 0,, "ahk_id " _hwnd) | ||
}) | ||
_ctrl.DefineProp("_DirectPointer", { | ||
Value: SendMessage(_SCI_GETDIRECTPOINTER , 0, 0,, "ahk_id " _hwnd) | ||
}) | ||
Return | ||
} else if (!_init and !_hwnd) { ; properties do not exist and cannot be set | ||
Return | ||
} | ||
|
||
; Send message to Scintilla control | ||
Return DllCall( _ctrl._DirectFunction | ||
, "UInt", _ctrl._DirectPointer | ||
, "Int", _msg | ||
, "UInt", _wparam | ||
, "UInt", _lparam ) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
|
||
Class __PC { | ||
static name := '', | ||
monitors := Map() | ||
|
||
static __New() { | ||
this.name := (A_ComputerName ~= 'DESKTOP-B2B2M4P') ? 'primary' : | ||
(A_ComputerName ~= 'DESKTOP-JJTV8BS') ? 'secondary' : | ||
(A_ComputerName ~= 'DESKTOP-HJ4S4Q2') ? 'laptop' : 'unknown' | ||
} | ||
|
||
static RefreshMonitors(_force:=False) { | ||
loop (mcnt := MonitorGetCount()) { | ||
if !!this.monitors.Has(A_Index) and !_force | ||
continue | ||
; wa := MonitorGetWorkArea(A_Index, &_l, &_t, &_r, &_b) | ||
this.monitors[A_Index] := __PC.__Monitor(A_Index) | ||
} | ||
} | ||
|
||
; static IsPointOnMonitor(_point_x, _point_y, _N) { | ||
; this.RefreshMonitors() | ||
; if !!this.monitors[_N].HasPoint[_point_x, _point_y] | ||
; return true | ||
; return false | ||
; } | ||
|
||
static MonitorWithPoint[_x,_y] { | ||
get { | ||
this.RefreshMonitors() | ||
for _N, _mon in this.monitors | ||
if !!_mon.HasPoint[_x, _y] | ||
return _N | ||
return False | ||
} | ||
} | ||
|
||
static MonitorWithMouse { | ||
get { | ||
this.RefreshMonitors() | ||
if (mcnt := MonitorGetCount()) = 1 | ||
return 1 | ||
MouseGetPos(&_x, &_y) | ||
for _N, _mon in this.monitors | ||
if !!_mon.HasPoint[_x, _y] | ||
return _N | ||
return False | ||
} | ||
} | ||
|
||
static MonitorWithFocus { | ||
get { | ||
this.RefreshMonitors() | ||
if (mcnt := MonitorGetCount()) = 1 | ||
return 1 | ||
WinGetPos(&_x, &_y, &_w, &_h, WinExist("A")) | ||
cx := _x + (_w // 2) | ||
cy := _y + (_h // 2) | ||
if !!this.monitors[1].HasFocus[true] | ||
return 1 | ||
if (this.monitors.Count > 1) and !!this.monitors[2].HasFocus[true] | ||
return 2 | ||
if (this.monitors.Count > 2) and !!this.monitors[3].HasFocus[true] | ||
return 3 | ||
if (this.monitors.Count > 3) | ||
Loop (this.monitors.Count - 3) | ||
if !!this.monitors[A_Index].HasFocus[false] | ||
return this.monitors[A_Index]._N | ||
return False | ||
} | ||
} | ||
|
||
Class __Monitor { | ||
_N := 0, | ||
l := left := 0, | ||
r := right := 0, | ||
t := top := 0, | ||
b := bottom := 0, | ||
w := width := 0, | ||
h := height := 0 | ||
|
||
|
||
__New(_N) { | ||
this.UpdateWorkingArea(_N) | ||
} | ||
|
||
/** | ||
* @prop {number} HasPoint `boolean` | ||
* @param {number} _px | ||
* @param {number} _py | ||
*/ | ||
HasPoint[_px, _py] { | ||
get { | ||
if (_px < this.l) or | ||
(_py < this.t) or | ||
(_px >= this.r) or | ||
(_py >= this.b) | ||
return false | ||
return True | ||
} | ||
} | ||
|
||
/** | ||
* @prop {number} HasMouse `boolean` | ||
*/ | ||
HasMouse { | ||
get { | ||
MouseGetPos(&_mx, &_my) | ||
if this.HasPoint(_mx, _my) | ||
return true | ||
return false | ||
} | ||
} | ||
|
||
/** | ||
* @prop {number} HasFocus `boolean` | ||
* @param {number} _force run `WinGetPos` to update window position. | ||
* otherwise it returns the last calculation made | ||
*/ | ||
HasFocus[_force:=true] { | ||
get { | ||
GetWindowPosition(_force_update) { | ||
static x := 0, y := 0, w := 0, h := 0, first_pass := true | ||
if !!_force_update or !!first_pass | ||
WinGetPos(&_wx, &_wy, &_ww, &_wh, WinExist('A')), | ||
x := _wx, y := _wy, w := _ww, h := _wh | ||
return {x: x, y: y, w: w, h: h} | ||
first_pass := false | ||
} | ||
active_win_pos := GetWindowPosition(_force) | ||
cx := active_win_pos.x + (active_win_pos.w // 2) | ||
cy := active_win_pos.y + (active_win_pos.h // 2) | ||
if !!this.HasPoint[cx, cy] | ||
return true | ||
return false | ||
} | ||
} | ||
|
||
UpdateWorkingArea(_N?) { | ||
this._N := _N ?? this._N | ||
wa := MonitorGetWorkArea(this._N, &_l, &_t, &_r, &_b) | ||
if not wa | ||
throw ValueError("Tried to create an instance of __Monitor " . | ||
"using an out-of-bounds monitor number" ) | ||
this.l := this.left := _l, | ||
this.r := this.right := _r, | ||
this.t := this.top := _t, | ||
this.b := this.bottom := _b, | ||
this.w := this.width := (_r - _l), | ||
this.h := this.height := (_b - _t) | ||
return this | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
|
||
|
||
SciLoad(_dll_path:="SciLexer.dll") { | ||
_sci_pointer := DllCall("LoadLibrary", "Str", _dll_path, "Ptr") | ||
Gui.Prototype.SciAdd := ((_gui, _opts:="")=>_SciBase(_gui, _opts)) | ||
Return _sci_pointer | ||
} | ||
|
||
SciFree(_sci_pointer) { | ||
Try | ||
FileAppend("Freeing the Scintilla.dll Library...`n", "*") | ||
|
||
DllCall("FreeLibrary", "Ptr", _sci_pointer) | ||
} | ||
|
||
Class _SciBase { | ||
Static Default := { | ||
Options: { | ||
x: 5, | ||
y: 5, | ||
w: 450, | ||
h: 250, | ||
Style: 0x40000000 | 0x00010000, ; WS_CHILD | WS_TABSTOP | ||
Visible: False, | ||
ExStyle: 0x00000200, ; WS_EX_CLIENTEDGE | ||
GuiID: 311210 | ||
} | ||
} | ||
Options := { | ||
x: 5, | ||
y: 5, | ||
w: 450, | ||
h: 250, | ||
Style: 0x40000000 | 0x00010000, ; WS_CHILD | WS_TABSTOP | ||
Visible: False, | ||
ExStyle: 0x00000200, ; WS_EX_CLIENTEDGE | ||
GuiID: 311210 | ||
} | ||
|
||
/* @prop {Gui} gui */ | ||
gui := {} | ||
__New(_gui, _opts:="") { | ||
Global sNul := "" | ||
, iNul := 0 | ||
if (IsObject(_opts)) | ||
for _prop, _def in _opts.OwnProps() | ||
if (this.Options.HasOwnProp(_prop)) | ||
this.Options.%_prop% := _def | ||
this.gui := _gui | ||
this.Init() | ||
} | ||
Init() { | ||
WStyle := ( (!!this.Options.Visible) ; | ||
? (this.Options.Style | 0x10000000) ; <Style> | WS_VISIBLE | ||
: this.Options.Style ) ; | ||
this.hwnd := DllCall("CreateWindowEx" ; ------------- | ||
,"Uint", this.Options.ExStyle ; Ex Style | ||
,"Str", "Scintilla" ; Class Name | ||
,"Str", sNul ; Window Name | ||
,"UInt", WStyle ; Window Styles | ||
,"Int", this.Options.x ; x | ||
,"Int", this.Options.y ; y | ||
,"Int", this.Options.w ; Width | ||
,"Int", this.Options.h ; Height | ||
,"UInt", this.gui.Hwnd ; Parent HWND | ||
,"UInt", this.Options.GuiID ; (HMENU)GuiID | ||
,"UInt", iNul ; hInstance | ||
,"UInt", iNul, "UInt") ; lpParam | ||
this.Send(iNul, iNul, iNul, this.hwnd) | ||
Return this.hwnd | ||
} | ||
Send(_msg, _wparam:=0x00, _lparam:=0x00, _hwnd:=0x00) { | ||
static _SCI_GETDIRECTFUNCTION := 2184, _SCI_GETDIRECTPOINTER := 2185 | ||
, _DirectFunction := 0x0, _DirectPointer := 0x0 | ||
, _init := False | ||
; If properties aren't initialized, do so | ||
if (!_init and _hwnd) { | ||
_DirectFunction := SendMessage(_SCI_GETDIRECTFUNCTION, 0, 0,, "ahk_id " _hwnd) | ||
_DirectPointer := SendMessage(_SCI_GETDIRECTPOINTER , 0, 0,, "ahk_id " _hwnd) | ||
_init := True | ||
Return | ||
} else if (!_init and !_hwnd) { ; properties do not exist and cannot be set | ||
Return | ||
} | ||
; Send message to Scintilla control | ||
Return DllCall( _DirectFunction | ||
, "UInt", _DirectPointer | ||
, "Int", _msg | ||
, "UInt", _wparam | ||
, "UInt", _lparam ) | ||
} | ||
} |
Oops, something went wrong.