Skip to content

Commit d1b99ae

Browse files
author
HackMemory
committed
upd
1 parent 03d2036 commit d1b99ae

File tree

5 files changed

+82
-6
lines changed

5 files changed

+82
-6
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ package.hub.yml
88

99
vendor/
1010

11+
bundle/
1112
build/
1213
out/
1314

15+
.idea/
1416
gradle/
15-
.gradle/
17+
.gradle/
18+
19+
*.iml

api-docs/classes/system/DFFI.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Class DFFI
1313

1414
- `->`[`__construct()`](#method-__construct) - _DFFI constructor._
1515
- `->`[`bind()`](#method-bind) - _Bind function_
16+
- `->`[`addSearchPath()`](#method-addsearchpath) - _Add library to search path_
17+
- `->`[`getJFXHandle()`](#method-getjfxhandle) - _Get JavaFX window handle_
1618

1719
---
1820
# Methods
@@ -33,4 +35,24 @@ DFFI constructor.
3335
```php
3436
bind(string $functionName, string $returnType, array $types): void
3537
```
36-
Bind function
38+
Bind function
39+
40+
---
41+
42+
<a name="method-addsearchpath"></a>
43+
44+
### addSearchPath()
45+
```php
46+
addSearchPath(string $lib, string $path): void
47+
```
48+
Add library to search path
49+
50+
---
51+
52+
<a name="method-getjfxhandle"></a>
53+
54+
### getJFXHandle()
55+
```php
56+
getJFXHandle(UXForm $form): void
57+
```
58+
Get JavaFX window handle

package.php.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: jphp-dffi-ext
2-
version: 1.0.0
2+
version: 1.0.1
33
description: DevelNext Foreign Function Interface
44

55
plugins:
@@ -11,6 +11,18 @@ deps:
1111
jphp-runtime: '*'
1212
jphp-zend-ext: '*'
1313

14+
devDeps:
15+
dn-bundle-plugin: '*'
16+
17+
develnext-bundle:
18+
version: 1.0.1
19+
name: DFFI
20+
author: HackMemory
21+
icon: "develnext/bundle/dffi/icon32.png"
22+
description: "DevelNext Foreign Function Interface"
23+
group: "system"
24+
class: "develnext\\bundle\\dffi\\DFFIBundle"
25+
1426
sources:
1527
- src
1628

@@ -25,4 +37,7 @@ gradle:
2537
config:
2638
ignore:
2739
- /.git/**
40+
- /.idea/**
41+
- /*.iml
42+
- /bundle/**
2843
- /package.hub.yml

sdk/system/DFFI.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,19 @@ public function __construct($lib){ }
2222
* @param array $types
2323
*/
2424
public function bind($functionName, $returnType, $types) {}
25+
26+
/**
27+
* Add library to search path
28+
*
29+
* @param string $lib
30+
* @param string $path
31+
*/
32+
public function addSearchPath($lib, $path) {}
33+
34+
/**
35+
* Get JavaFX window handle
36+
*
37+
* @param UXForm $form
38+
*/
39+
public function getJFXHandle($form) {}
2540
}

src-jvm/main/java/org/develnext/jphp/ext/system/classes/DFFI.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
import php.runtime.Memory;
55
import php.runtime.annotation.Reflection;
66
import php.runtime.memory.*;
7-
import php.runtime.memory.helper.*;
87
import php.runtime.env.Environment;
98
import php.runtime.env.TraceInfo;
109
import php.runtime.lang.BaseObject;
11-
import php.runtime.lang.BaseWrapper;
1210
import php.runtime.reflection.ClassEntity;
1311

12+
import javafx.stage.Stage;
13+
import com.sun.javafx.tk.TKStage;
14+
import java.lang.reflect.Method;
15+
1416
import java.awt.*;
15-
import java.util.*;
1617
import com.sun.jna.*;
1718

1819
@Reflection.Name("DFFI")
@@ -89,5 +90,24 @@ public static void addSearchPath(String lib, String path) throws AWTException
8990
{
9091
NativeLibrary.addSearchPath(lib, path);
9192
}
93+
94+
@Reflection.Signature
95+
public static Long getJFXHandle(Object window)
96+
{
97+
try {
98+
Stage stage = (Stage) window;
99+
100+
TKStage tkStage = stage.impl_getPeer();
101+
Method getPlatformWindow = tkStage.getClass().getDeclaredMethod("getPlatformWindow" );
102+
getPlatformWindow.setAccessible(true);
103+
Object platformWindow = getPlatformWindow.invoke(tkStage);
104+
Method getNativeHandle = platformWindow.getClass().getMethod( "getNativeHandle" );
105+
getNativeHandle.setAccessible(true);
106+
Object nativeHandle = getNativeHandle.invoke(platformWindow);
107+
return (Long) nativeHandle;
108+
} catch (Throwable e) {
109+
return null;
110+
}
111+
}
92112

93113
}

0 commit comments

Comments
 (0)