Hi,
From: Jan Füssel [mailto:[EMAIL PROTECTED] Sent: Friday, October 31, 2008 11:57 AM
To: dev@api.openoffice.org
Subject: Re: [api-dev] Using an Xframe as a parent for a Java dialog

Hi,

i've currently a solution to open a modless java-dialog, which need SWT and 
only works on a windows machine.


may be somebody has a solution for Swing and win32 too??

To get Windows Handle I used the following Basic-Code:

Dim oWindow : oWindow = ThisComponent.CurrentController.Frame.ContainerWindow
Dim HWND : HWND = oWindow.getWindowHandle(Array(),
com.sun.star.lang.SystemDependent.SYSTEM_WIN32)

With that handle I call java Java-Method which start an SWT-Dialog:

private void createDialog(int handle) {
        final MyDialog myDialog = MyDialog.create(handle, componentContext);
        myDialog.show();
}

Here a little piece of the MyDialog Class:

public class MyDialog {

    private final Shell myShell;

    private MyDialog(Shell shell) {
        myShell = shell;
        myShell.addFocusListener(new FocusAdapter() {
            public void focusLost(FocusEvent e) {
                myShell.setVisible(true);
            }
        });
    }

    public static MyDialog create(int handle, XComponentContext
componentContext) {
        final int style = SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE;
        final Display display = new Display();
        final Shell shell;
        if (handle > 0) {
            final Shell parent = Shell.win32_new(display, handle);
            shell = new Shell(parent, style);
        } else {
            shell = new Shell(style);
        }
        return new MyDialog(shell);
    }

    public void show() {
        createMyShell();
        myShell.open();
        final Composite parent = myShell.getParent();
        final Display display;
        if (parent != null) {
            display = parent.getDisplay();
        } else {
            display = Display.getDefault();
        }
        while (!myShell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }
}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to