forked from amazingfate/loongoffice
(cherry picked from commit 399946b82f5efec19cd82d1c320d5aa9295d235d) Conflicts: chart2/source/controller/main/ChartController_Window.cxx framework/source/uielement/langselectionmenucontroller.cxx framework/source/uielement/popupmenucontroller.cxx framework/source/uielement/recentfilesmenucontroller.cxx framework/source/uielement/toolbarsmenucontroller.cxx odk/examples/DevelopersGuide/GUI/UnoMenu.java odk/examples/DevelopersGuide/GUI/UnoMenu2.java odk/examples/cpp/StatusbarController/SelectionModeStatusbarController/SelectionModeStatusbarController.cxx offapi/com/sun/star/awt/MenuBar.idl offapi/com/sun/star/awt/MenuEvent.idl offapi/com/sun/star/awt/MenuItemStyle.idl offapi/com/sun/star/awt/MenuItemType.idl offapi/com/sun/star/awt/MenuLogo.idl offapi/com/sun/star/awt/PopupMenu.idl offapi/com/sun/star/awt/PopupMenuDirection.idl offapi/com/sun/star/awt/XMenu.idl offapi/com/sun/star/awt/XMenuBar.idl offapi/com/sun/star/awt/XMenuBarExtended.idl offapi/com/sun/star/awt/XMenuExtended.idl offapi/com/sun/star/awt/XMenuExtended2.idl offapi/com/sun/star/awt/XMenuListener.idl offapi/com/sun/star/awt/XPopupMenu.idl offapi/com/sun/star/awt/XPopupMenuExtended.idl offapi/com/sun/star/awt/makefile.mk offapi/type_reference/types.rdb svtools/inc/svtools/popupmenucontrollerbase.hxx svtools/source/uno/popupmenucontrollerbase.cxx svx/source/tbxctrls/extrusioncontrols.cxx toolkit/inc/pch/precompiled_toolkit.hxx toolkit/inc/toolkit/awt/vclxmenu.hxx toolkit/inc/toolkit/helper/listenermultiplexer.hxx toolkit/source/awt/vclxmenu.cxx Change-Id: I3d9a1e109b9ff35901a3075b44a4c27e7c12b5c7 Related: #i121542# css::awt::XPopupMenu::execute() needs a Rectangle (cherry picked from commit c01a6f4f370b72f0751cf4f5c11310682e2b3248) Conflicts: odk/examples/DevelopersGuide/GUI/UnoMenu2.java offapi/type_reference/types.rdb toolkit/inc/toolkit/awt/vclxmenu.hxx Change-Id: I2cccc95086fe3d1522d03346e3c577fb2f21f621
190 lines
7.9 KiB
Java
190 lines
7.9 KiB
Java
/*
|
|
* This file is part of the LibreOffice project.
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*
|
|
* This file incorporates work covered by the following license notice:
|
|
*
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
* with this work for additional information regarding copyright
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
* except in compliance with the License. You may obtain a copy of
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
*/
|
|
|
|
import com.sun.star.awt.MenuEvent;
|
|
import com.sun.star.awt.MenuItemStyle;
|
|
import com.sun.star.awt.Rectangle;
|
|
import com.sun.star.awt.WindowAttribute;
|
|
import com.sun.star.awt.WindowClass;
|
|
import com.sun.star.awt.XMenuBar;
|
|
import com.sun.star.awt.XMenuListener;
|
|
import com.sun.star.awt.XPopupMenu;
|
|
import com.sun.star.awt.XToolkit;
|
|
import com.sun.star.awt.XTopWindow;
|
|
import com.sun.star.awt.XWindow;
|
|
import com.sun.star.awt.XWindowPeer;
|
|
import com.sun.star.frame.XFrame;
|
|
import com.sun.star.frame.XFramesSupplier;
|
|
import com.sun.star.lang.XComponent;
|
|
import com.sun.star.lang.XMultiComponentFactory;
|
|
import com.sun.star.uno.UnoRuntime;
|
|
import com.sun.star.uno.XComponentContext;
|
|
|
|
public class UnoMenu extends UnoDialogSample implements XMenuListener {
|
|
private XTopWindow mxTopWindow = null;
|
|
|
|
public UnoMenu(XComponentContext _xContext, XMultiComponentFactory _xMCF) {
|
|
super(_xContext, _xMCF);
|
|
}
|
|
|
|
public static void main(String args[]){
|
|
UnoMenu oUnoMenu = null;
|
|
XComponent xComponent = null;
|
|
try {
|
|
XComponentContext xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
|
|
if(xContext != null )
|
|
System.out.println("Connected to a running office ...");
|
|
XMultiComponentFactory xMCF = xContext.getServiceManager();
|
|
oUnoMenu = new UnoMenu(xContext, xMCF);
|
|
oUnoMenu.mxTopWindow = oUnoMenu.showTopWindow( new Rectangle(100, 100, 500, 500)); //oUnoDialogSample.m_xWindowPeer,
|
|
oUnoMenu.addMenuBar(oUnoMenu.mxTopWindow, oUnoMenu);
|
|
}catch( Exception ex ) {
|
|
ex.printStackTrace(System.err);
|
|
}
|
|
}
|
|
|
|
|
|
public XPopupMenu getPopupMenu(){
|
|
XPopupMenu xPopupMenu = null;
|
|
try{
|
|
// create a popup menu
|
|
Object oPopupMenu = m_xMCF.createInstanceWithContext("com.sun.star.awt.PopupMenu", m_xContext);
|
|
xPopupMenu = UnoRuntime.queryInterface(XPopupMenu.class, oPopupMenu);
|
|
|
|
// ID must start be > 0
|
|
short nId = 1;
|
|
short nPos = 0;
|
|
|
|
xPopupMenu.insertItem(nId++, "First Entry", MenuItemStyle.AUTOCHECK, nPos++);
|
|
xPopupMenu.insertItem(nId++, "First Radio Entry", (short) (MenuItemStyle.RADIOCHECK + MenuItemStyle.AUTOCHECK), nPos++);
|
|
xPopupMenu.insertItem(nId++, "Second Radio Entry", (short) (MenuItemStyle.RADIOCHECK + MenuItemStyle.AUTOCHECK), nPos++);
|
|
xPopupMenu.insertItem(nId++, "Third RadioEntry",(short) (MenuItemStyle.RADIOCHECK + MenuItemStyle.AUTOCHECK), nPos++);
|
|
xPopupMenu.insertSeparator(nPos++);
|
|
xPopupMenu.insertItem(nId++, "Fifth Entry", (short) (MenuItemStyle.CHECKABLE + MenuItemStyle.AUTOCHECK), nPos++);
|
|
xPopupMenu.insertItem(nId++, "Fourth Entry", (short) (MenuItemStyle.CHECKABLE + MenuItemStyle.AUTOCHECK), nPos++);
|
|
xPopupMenu.insertItem(nId++, "Sixth Entry", (short) 0, nPos++);
|
|
xPopupMenu.insertItem(nId++, "Close Dialog", (short) 0, nPos++);
|
|
|
|
xPopupMenu.enableItem((short) 2, false);
|
|
xPopupMenu.checkItem((short) 3, true);
|
|
|
|
xPopupMenu.addMenuListener(this);
|
|
}catch( Exception e ) {
|
|
throw new java.lang.RuntimeException("cannot happen...");
|
|
}
|
|
return xPopupMenu;
|
|
}
|
|
|
|
|
|
public void addMenuBar(XTopWindow _xTopWindow, XMenuListener _xMenuListener){
|
|
try{
|
|
// create a menubar at the global MultiComponentFactory...
|
|
Object oMenuBar = m_xMCF.createInstanceWithContext("com.sun.star.awt.MenuBar", m_xContext);
|
|
// add the menu items...
|
|
XMenuBar xMenuBar = UnoRuntime.queryInterface(XMenuBar.class, oMenuBar);
|
|
xMenuBar.insertItem((short) 1, "~First MenuBar Item", com.sun.star.awt.MenuItemStyle.AUTOCHECK, (short) 0);
|
|
xMenuBar.insertItem((short) 2, "~Second MenuBar Item", com.sun.star.awt.MenuItemStyle.AUTOCHECK, (short) 1);
|
|
xMenuBar.setPopupMenu((short) 1, getPopupMenu());
|
|
xMenuBar.addMenuListener(_xMenuListener);
|
|
_xTopWindow.setMenuBar(xMenuBar);
|
|
}catch( Exception e ) {
|
|
throw new java.lang.RuntimeException("cannot happen...");
|
|
}}
|
|
|
|
protected void closeDialog(){
|
|
XComponent xComponent = UnoRuntime.queryInterface(XComponent.class, mxTopWindow);
|
|
if (xComponent != null){
|
|
xComponent.dispose();
|
|
}
|
|
|
|
// to ensure that the Java application terminates
|
|
System.exit( 0 );
|
|
}
|
|
|
|
public XTopWindow showTopWindow( Rectangle _aRectangle){
|
|
XTopWindow xTopWindow = null;
|
|
try {
|
|
// The Toolkit is the creator of all windows...
|
|
Object oToolkit = m_xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", m_xContext);
|
|
XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, oToolkit);
|
|
|
|
// set up a window description and create the window. A parent window is always necessary for this...
|
|
com.sun.star.awt.WindowDescriptor aWindowDescriptor = new com.sun.star.awt.WindowDescriptor();
|
|
// a TopWindow is contains a title bar and is able to inlude menus...
|
|
aWindowDescriptor.Type = WindowClass.TOP;
|
|
// specify the position and height of the window on the parent window
|
|
aWindowDescriptor.Bounds = _aRectangle;
|
|
// set the window attributes...
|
|
aWindowDescriptor.WindowAttributes = WindowAttribute.SHOW + WindowAttribute.MOVEABLE + WindowAttribute.SIZEABLE + WindowAttribute.CLOSEABLE;
|
|
|
|
// create the window...
|
|
XWindowPeer xWindowPeer = xToolkit.createWindow(aWindowDescriptor);
|
|
XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, xWindowPeer);
|
|
|
|
// create a frame and initialize it with the created window...
|
|
Object oFrame = m_xMCF.createInstanceWithContext("com.sun.star.frame.Frame", m_xContext);
|
|
m_xFrame = UnoRuntime.queryInterface(XFrame.class, oFrame);
|
|
|
|
Object oDesktop = m_xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", m_xContext);
|
|
XFramesSupplier xFramesSupplier = UnoRuntime.queryInterface(XFramesSupplier.class, oDesktop);
|
|
m_xFrame.setCreator(xFramesSupplier);
|
|
// get the XTopWindow interface..
|
|
xTopWindow = UnoRuntime.queryInterface(XTopWindow.class, xWindow);
|
|
} catch (com.sun.star.lang.IllegalArgumentException ex) {
|
|
ex.printStackTrace();
|
|
} catch (com.sun.star.uno.Exception ex) {
|
|
ex.printStackTrace();
|
|
}
|
|
return xTopWindow;
|
|
}
|
|
|
|
public void addMenuBar(XWindow _xWindow){
|
|
XTopWindow xTopWindow = UnoRuntime.queryInterface(XTopWindow.class, _xWindow);
|
|
addMenuBar(xTopWindow, this);
|
|
}
|
|
|
|
public void itemSelected(MenuEvent menuEvent){
|
|
// find out which menu item has been triggered,
|
|
// by getting the menu-id...
|
|
switch (menuEvent.MenuId){
|
|
case 1:
|
|
// add your menu-item-specific code here:
|
|
break;
|
|
case 2:
|
|
// add your menu-item-specific code here:
|
|
break;
|
|
case 8:
|
|
closeDialog();
|
|
default:
|
|
//..
|
|
}
|
|
}
|
|
|
|
public void itemHighlighted(MenuEvent menuEvent) {
|
|
int i = 0;
|
|
}
|
|
|
|
public void itemDeactivated(MenuEvent menuEvent) {
|
|
int i = 0; }
|
|
|
|
public void itemActivated(MenuEvent menuEvent) {
|
|
int i = 0;
|
|
}
|
|
|
|
}
|