Skip to content

Commit 3410805

Browse files
committed
+ Added SciterAPIHost.GetWindowFocus
1 parent b0fd6cb commit 3410805

3 files changed

Lines changed: 13 additions & 81 deletions

File tree

src/EmptyFlow.SciterAPI/Client/HostWindowsAPI.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,17 @@ public bool SetWindowAspectRatio ( nint window, double value ) {
329329
return false;
330330
}
331331

332+
public nint GetWindowFocus ( nint window ) {
333+
var script = $"Window.this.focus";
334+
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {
335+
if ( result.IsNull ) return nint.Zero;
336+
337+
return ElementFromValue ( result );
338+
}
339+
340+
return nint.Zero;
341+
}
342+
332343
public string GetWindowCaption ( nint window ) {
333344
var script = $"Window.this.caption";
334345
if ( m_basicApi.SciterEval ( window, script, (uint) script.Length, out var result ) ) {

src/EmptyFlow.SciterAPI/Client/SciterEventHandler.cs

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -47,72 +47,6 @@ public void SetActiveBehaviourGroups ( IEnumerable<EventBehaviourGroups> groups
4747
m_includedEvents.AddRange ( groups );
4848
}
4949

50-
private static int m_referenceCounter = 0;
51-
52-
[UnmanagedCallersOnly ( CallConvs = new[] { typeof ( CallConvCdecl ) } )]
53-
public static int AssetAddRef ( nint thing ) {
54-
m_referenceCounter++;
55-
return m_referenceCounter;
56-
}
57-
58-
[UnmanagedCallersOnly ( CallConvs = new[] { typeof ( CallConvCdecl ) } )]
59-
public static int AssetRelease ( nint thing ) {
60-
m_referenceCounter--;
61-
return m_referenceCounter;
62-
}
63-
64-
[UnmanagedCallersOnly ( CallConvs = new[] { typeof ( CallConvCdecl ) } )]
65-
public static int AssetGetInterface ( nint thing, nint name, nint @out ) {
66-
//if ( name != "asset.sciter.com" ) return 0;
67-
//if ( 0 != strcmp ( name, interface_name () ) ) return false;
68-
//if (out) { this->asset_add_ref (); *out = this; }
69-
return 1;
70-
}
71-
72-
[UnmanagedCallersOnly ( CallConvs = new[] { typeof ( CallConvCdecl ) } )]
73-
public static nint AssetGetPassport ( nint thing ) => IntPtr.Zero;//m_relatedPassport;
74-
75-
private nint GetAsset () {
76-
if ( m_relatedAsset != nint.Zero ) return m_relatedAsset;
77-
78-
nint assetAddRefPointer = nint.Zero;
79-
nint assetReleasePointer = nint.Zero;
80-
nint getInterfacePointer = nint.Zero;
81-
nint getPassportPointer = nint.Zero;
82-
unsafe {
83-
delegate* unmanaged[Cdecl]< nint, int > AssetAddRefPointer = &AssetAddRef;
84-
assetAddRefPointer = (nint) AssetAddRefPointer;
85-
86-
delegate* unmanaged[Cdecl]< nint, int > AssetReleasePointer = &AssetRelease;
87-
assetReleasePointer = (nint) AssetReleasePointer;
88-
89-
delegate* unmanaged[Cdecl]< nint, nint, nint, int > GetInterfacePointer = &AssetGetInterface;
90-
getInterfacePointer = (nint) GetInterfacePointer;
91-
92-
delegate* unmanaged[Cdecl]< nint, nint > GetPassportPointer = &AssetGetPassport;
93-
getPassportPointer = (nint) GetPassportPointer;
94-
95-
var assetClass = new SomAssetClass {
96-
AssetAddRef = assetAddRefPointer,
97-
AssetRelease = assetReleasePointer,
98-
AssetGetInterface = getInterfacePointer,
99-
AssetGetPassport = getPassportPointer
100-
};
101-
102-
var classPointer = NativeMemory.Alloc ( (nuint) Marshal.SizeOf<SomAssetClass> () );
103-
104-
var asset = new SomAsset {
105-
isa = (nint) classPointer
106-
};
107-
108-
m_relatedAsset = (nint) NativeMemory.Alloc ( (nuint) Marshal.SizeOf<SomAsset> () ); // Marshal.AllocHGlobal ( Marshal.SizeOf<SomAsset> () );
109-
110-
Marshal.StructureToPtr ( asset, m_relatedAsset, true );
111-
}
112-
113-
return m_relatedAsset;
114-
}
115-
11650
public override bool EventHandler ( nint processedElement, EventBehaviourGroups eventBehaviourGroup, nint parameters ) {
11751
if ( m_includedEvents.Any () && !m_includedEvents.Contains ( eventBehaviourGroup ) ) return false;
11852

@@ -214,21 +148,7 @@ public override bool EventHandler ( nint processedElement, EventBehaviourGroups
214148
return handled;
215149
case EventBehaviourGroups.HANDLE_SOM:
216150
var somCommand = Marshal.PtrToStructure<SOMParameters> ( parameters );
217-
if ( somCommand.Command is not SOMEvents.SOM_GET_PASSPORT and not SOMEvents.SOM_GET_ASSET ) return false;
218-
219-
if ( somCommand.Command == SOMEvents.SOM_GET_PASSPORT ) {
220-
var passport = m_relatedPassport != nint.Zero ? m_relatedPassport : SOMEventPassport ();
221-
if ( passport != nint.Zero ) {
222-
m_relatedPassport = passport;
223-
somCommand.Data = passport;
224-
Marshal.StructureToPtr ( somCommand, parameters, true );
225-
}
226-
}
227-
if ( somCommand.Command == SOMEvents.SOM_GET_ASSET ) {
228-
somCommand.Data = GetAsset ();
229-
Marshal.StructureToPtr ( somCommand, parameters, true );
230-
}
231-
return true;
151+
return false;
232152
case EventBehaviourGroups.HANDLE_INITIALIZATION:
233153
var initializationArguments = Marshal.PtrToStructure<InitializationParameters> ( parameters );
234154
HandleInitializationEvent ( initializationArguments.cmd );

src/EmptyFlow.SciterAPI/EmptyFlow.SciterAPI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<PackageReleaseNotes>
2424
Added enum SciterKeyCode contains all supported key codes
2525
SciterAPIHost.ShowWindowSelectFolderDialog for show select folder dialog
26+
SciterAPIHost.GetWindowFocus get focus element in window
2627
</PackageReleaseNotes>
2728
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2829
</PropertyGroup>

0 commit comments

Comments
 (0)