Пример #1
0
        public XWindow createItemWindow(XWindow xWindow)
        {
            // xMSF is set by initialize(Object[])
            try
            {
                // get XWindowPeer
                XWindowPeer xWinPeer = (XWindowPeer)xWindow;
                Object      o        = _xMsf.createInstanceWithContext("com.sun.star.awt.Toolkit", OO.GetContext());
                XToolkit    xToolkit = (XToolkit)o;
                // create WindowDescriptor
                WindowDescriptor wd = new WindowDescriptor();
                wd.Type              = WindowClass.SIMPLE;
                wd.Parent            = xWinPeer;
                wd.Bounds            = new Rectangle(0, 0, 20, 23);
                wd.ParentIndex       = (short)-1;
                wd.WindowAttributes  = WindowAttribute.SHOW;
                wd.WindowServiceName = "pushbutton";
                // create Button
                XWindowPeer cBox_xWinPeer = xToolkit.createWindow(wd);// null here
                var         xButton       = (XButton)cBox_xWinPeer;
                xButton.setLabel("My Texte");
                XWindow cBox_xWindow = (XWindow)cBox_xWinPeer;
                cBox_xWindow.addKeyListener(this);

                return(cBox_xWindow);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("createItemWindow left not o.k.\n" + e);
                return(null);
            }
        }
        public static XControlContainer createDialog(XMultiComponentFactory xMultiComponentFactory, XComponentContext xContext,
                                                     int posX, int posY, int width, int height, string title
                                                     )
        {
            //dialog model
            Object oDialogModel = xMultiComponentFactory.createInstanceWithContext(
                "com.sun.star.awt.UnoControlDialogModel", xContext);


            XPropertySet xPSetDialog = (XPropertySet)oDialogModel;

            xPSetDialog.setPropertyValue("PositionX", Any.Get(posX));
            xPSetDialog.setPropertyValue("PositionY", Any.Get(posY));
            xPSetDialog.setPropertyValue("Width", Any.Get(width));
            xPSetDialog.setPropertyValue("Height", Any.Get(height));
            xPSetDialog.setPropertyValue("Title", Any.Get(title));

            // get service manager from  dialog model
            XMultiServiceFactory MXMsfDialogModel = (XMultiServiceFactory)oDialogModel;

            // dialog control model
            Object oUnoDialog = xMultiComponentFactory.createInstanceWithContext(
                "com.sun.star.awt.UnoControlDialog", xContext);


            XControl      MXDialogControl = (XControl)oUnoDialog;
            XControlModel xControlModel   = (XControlModel)oDialogModel;

            MXDialogControl.setModel(xControlModel);



            XToolkit xToolkit = (XToolkit)xMultiComponentFactory
                                .createInstanceWithContext("com.sun.star.awt.Toolkit",
                                                           xContext);

            WindowDescriptor aDescriptor = new WindowDescriptor();

            aDescriptor.Type = WindowClass.TOP;
            aDescriptor.WindowServiceName = "";
            aDescriptor.ParentIndex       = -1;
            aDescriptor.Parent            = xToolkit.getDesktopWindow();
            aDescriptor.Bounds            = new Rectangle(100, 200, 300, 400);

            aDescriptor.WindowAttributes = WindowAttribute.BORDER
                                           | WindowAttribute.MOVEABLE | WindowAttribute.SIZEABLE
                                           | WindowAttribute.CLOSEABLE;

            XWindowPeer xPeer = xToolkit.createWindow(aDescriptor);

            XWindow xWindow = (XWindow)xPeer;

            xWindow.setVisible(false);
            MXDialogControl.createPeer(xToolkit, xPeer);

            // execute the dialog
            XDialog xDialog = (XDialog)oUnoDialog;

            xDialog.execute();

            // dispose the dialog
            XComponent xComponent = (XComponent)oUnoDialog;

            xComponent.dispose();

            return(oUnoDialog as XControlContainer);
        }