Search in sources :

Example 46 with Pointer

use of com.sun.jna.Pointer in project dukescript-presenters by dukescript.

the class Cocoa method callback.

public void callback(Pointer self) throws Exception {
    if (NSApp != null) {
        process();
        return;
    }
    ObjC objC = ObjC.INSTANCE;
    long res = send(objC.objc_getClass("NSApplication"), "sharedApplication");
    if (res == 0) {
        System.err.print("Failed to initialized NSApplication...  terminating...\n");
        System.exit(1);
    }
    dispatchThread = Thread.currentThread();
    NSApp = new Pointer(res);
    send(NSApp, "setActivationPolicy:", 0);
    send(NSApp, "setDelegate:", self);
    res = send(NSApp, "run");
    System.err.println("end res: " + res);
}
Also used : Pointer(com.sun.jna.Pointer)

Example 47 with Pointer

use of com.sun.jna.Pointer in project dukescript-presenters by dukescript.

the class InvokeLater method run.

@Override
public void run() {
    final Gtk gtk = getInstance(null);
    final Pointer screen = gdk.gdk_screen_get_default();
    int primaryMonitor = gdk.gdk_screen_get_primary_monitor(screen);
    GRectangle size = new GRectangle();
    gdk.gdk_screen_get_monitor_geometry(screen, primaryMonitor, size);
    int height = (int) (size.height * 0.9);
    int width = (int) (size.width * 0.9);
    int x = (int) (size.width * 0.05) + size.x;
    int y = (int) (size.height * 0.05) + size.y;
    final Pointer window = gtk.gtk_window_new(0);
    gtk.gtk_window_set_default_size(window, width, height);
    gtk.gtk_window_set_gravity(window, 5);
    gtk.gtk_window_move(window, x, y);
    Pointer scroll = gtk.gtk_scrolled_window_new(null, null);
    gtk.gtk_container_add(window, scroll);
    final Pointer webView = webKit.webkit_web_view_new();
    gtk.gtk_container_add(scroll, webView);
    Pointer frame = webKit.webkit_web_view_get_main_frame(webView);
    Pointer ctx = webKit.webkit_web_frame_get_global_context(frame);
    this.jsContext = ctx;
    if (onContext != null) {
        onContext.run();
    }
    onLoad = new OnLoad(webView, gtk, window);
    g.g_signal_connect_data(webView, "notify::load-status", onLoad, null);
    webKit.webkit_web_view_load_uri(webView, page);
    gtk.gtk_widget_grab_focus(webView);
    onDestroy = new OnDestroy();
    g.g_signal_connect_data(window, "destroy", onDestroy, null);
    pending = new Pending();
    if (!headless) {
        gtk.gtk_widget_show_all(window);
    }
}
Also used : Pointer(com.sun.jna.Pointer)

Example 48 with Pointer

use of com.sun.jna.Pointer in project dukescript-presenters by dukescript.

the class Cocoa method show.

@Override
public void show(URI page) {
    this.page = page.toASCIIString();
    Native.loadLibrary("WebKit", WebKit.class);
    appDidStart = new AppDidStart();
    contextCreated = new ContextCreated();
    ready = new Ready();
    if (appDelPtr == null) {
        ObjC objC = ObjC.INSTANCE;
        Pointer appDelClass = objC.objc_allocateClassPair(objC.objc_getClass("NSObject"), "AppDelegate", 0);
        objC.class_addMethod(appDelClass, objC.sel_getUid("applicationDidFinishLaunching:"), appDidStart, "i@:@");
        doMainSelector = objC.sel_getUid("doMain");
        Native.setCallbackThreadInitializer(this, new CallbackThreadInitializer(false, false, "Cocoa Dispatch Thread"));
        objC.class_addMethod(appDelClass, doMainSelector, this, "i@");
        objC.class_addMethod(appDelClass, objC.sel_getUid("webView:didCreateJavaScriptContext:forFrame:"), contextCreated, "v@:@:@");
        objC.class_addMethod(appDelClass, objC.sel_getUid("webView:didFinishLoadForFrame:"), ready, "v@:@");
        objC.objc_registerClassPair(appDelClass);
        long appDelObj = send(objC.objc_getClass("AppDelegate"), "alloc");
        appDelPtr = new Pointer(appDelObj);
        send(appDelPtr, "init");
        send(appDelPtr, "performSelectorOnMainThread:withObject:waitUntilDone:", doMainSelector, null, 1);
    } else {
        execute(new Runnable() {

            @Override
            public void run() {
                appDidStart.callback(appDelPtr);
            }
        });
    }
}
Also used : CallbackThreadInitializer(com.sun.jna.CallbackThreadInitializer) Pointer(com.sun.jna.Pointer)

Example 49 with Pointer

use of com.sun.jna.Pointer in project dukescript-presenters by dukescript.

the class WebKitPresenter method defineFn.

@Override
public Fn defineFn(String code, String[] names, boolean[] keepAlive) {
    JSC jsc = shell.jsc();
    Pointer[] jsNames = new Pointer[names.length];
    for (int i = 0; i < jsNames.length; i++) {
        jsNames[i] = jsc.JSStringCreateWithUTF8CString(names[i]);
    }
    Pointer jsCode = jsc.JSStringCreateWithUTF8CString(code);
    PointerByReference exc = new PointerByReference();
    Pointer fn = jsc.JSObjectMakeFunction(ctx, null, names.length, jsNames, jsCode, null, 1, exc);
    if (fn == null) {
        throw new IllegalStateException("Cannot initialize function: " + exc.getValue());
    }
    jsc.JSStringRelease(jsCode);
    for (Pointer jsName : jsNames) {
        jsc.JSStringRelease(jsName);
    }
    return new JSCFn(fn, keepAlive);
}
Also used : PointerByReference(com.sun.jna.ptr.PointerByReference) Pointer(com.sun.jna.Pointer) JSC(com.dukescript.presenters.renderer.JSC)

Example 50 with Pointer

use of com.sun.jna.Pointer in project dukescript-presenters by dukescript.

the class WebKitPresenter method loadScript.

@Override
public void loadScript(Reader code) throws Exception {
    StringBuilder sb = new StringBuilder();
    for (; ; ) {
        int ch = code.read();
        if (ch == -1) {
            break;
        }
        sb.append((char) ch);
    }
    Pointer script = shell.jsc().JSStringCreateWithUTF8CString(sb.toString());
    PointerByReference ex = new PointerByReference();
    shell.jsc().JSEvaluateScript(ctx, script, null, null, 1, ex);
    shell.jsc().JSStringRelease(script);
    if (ex.getValue() != null) {
        throw new Exception(convertToString(shell.jsc(), ex.getValue()));
    }
}
Also used : PointerByReference(com.sun.jna.ptr.PointerByReference) Pointer(com.sun.jna.Pointer)

Aggregations

Pointer (com.sun.jna.Pointer)93 PointerByReference (com.sun.jna.ptr.PointerByReference)20 Memory (com.sun.jna.Memory)15 IntByReference (com.sun.jna.ptr.IntByReference)15 Test (org.junit.Test)12 HDDEDATA (com.sun.jna.platform.win32.Ddeml.HDDEDATA)8 HSZ (com.sun.jna.platform.win32.Ddeml.HSZ)8 HCONV (com.sun.jna.platform.win32.Ddeml.HCONV)7 ConnectHandler (com.sun.jna.platform.win32.DdemlUtil.ConnectHandler)7 IDdeConnection (com.sun.jna.platform.win32.DdemlUtil.IDdeConnection)7 StandaloneDdeClient (com.sun.jna.platform.win32.DdemlUtil.StandaloneDdeClient)7 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)7 File (java.io.File)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 HWND (com.sun.jna.platform.win32.WinDef.HWND)6 ULONG (com.sun.jna.platform.win32.WinDef.ULONG)6 IOException (java.io.IOException)6 BufferedImage (java.awt.image.BufferedImage)5 Function (com.sun.jna.Function)4 ULONG_PTR (com.sun.jna.platform.win32.BaseTSD.ULONG_PTR)4