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
113 lines
4.9 KiB
Java
113 lines
4.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.MouseEvent;
|
|
import com.sun.star.awt.Rectangle;
|
|
import com.sun.star.awt.XControl;
|
|
import com.sun.star.awt.XMouseListener;
|
|
import com.sun.star.awt.XWindow;
|
|
import com.sun.star.beans.XMultiPropertySet;
|
|
import com.sun.star.lang.EventObject;
|
|
import com.sun.star.lang.XMultiComponentFactory;
|
|
import com.sun.star.uno.UnoRuntime;
|
|
import com.sun.star.uno.XComponentContext;
|
|
|
|
|
|
public class UnoMenu2 extends UnoMenu implements XMouseListener{
|
|
|
|
public UnoMenu2(XComponentContext _xContext, XMultiComponentFactory _xMCF) {
|
|
super(_xContext, _xMCF);
|
|
}
|
|
|
|
public static void main(String args[]){
|
|
UnoMenu2 oUnoMenu2 = 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();
|
|
oUnoMenu2 = new UnoMenu2(xContext, xMCF);
|
|
oUnoMenu2.initialize( new String[] {"Height", "Moveable", "Name","PositionX","PositionY", "Step", "TabIndex","Title","Width"},
|
|
new Object[] { new Integer(140), Boolean.TRUE, "Dialog1", new Integer(102),new Integer(41), new Integer(1), new Short((short) 0), "Menu-Dialog", new Integer(200)});
|
|
|
|
Object oFTHeaderModel = oUnoMenu2.m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel");
|
|
XMultiPropertySet xFTHeaderModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFTHeaderModel);
|
|
xFTHeaderModelMPSet.setPropertyValues(
|
|
new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"},
|
|
new Object[] { new Integer(8), "This code-sample demonstrates the creation of a popup-menu", "HeaderLabel", new Integer(6), new Integer(6), new Integer(200)});
|
|
// add the model to the NameContainer of the dialog model
|
|
oUnoMenu2.m_xDlgModelNameContainer.insertByName("Headerlabel", oFTHeaderModel);
|
|
oUnoMenu2.addLabelForPopupMenu();
|
|
oUnoMenu2.executeDialog();
|
|
}catch( Exception ex ) {
|
|
ex.printStackTrace(System.err);
|
|
}
|
|
finally{
|
|
//make sure always to dispose the component and free the memory!
|
|
if (oUnoMenu2 != null) {
|
|
if (oUnoMenu2.m_xComponent != null){
|
|
oUnoMenu2.m_xComponent.dispose();
|
|
}
|
|
}
|
|
System.exit( 0 );
|
|
}}
|
|
|
|
|
|
public void addLabelForPopupMenu(){
|
|
try{
|
|
String sName = "lblPopup";
|
|
Object oFTModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel");
|
|
XMultiPropertySet xFTModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFTModel);
|
|
// Set the properties at the model - keep in mind to pass the property names in alphabetical order!
|
|
xFTModelMPSet.setPropertyValues(
|
|
new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"},
|
|
new Object[] { new Integer(8), "Right-click here", sName, new Integer(50), new Integer(50), new Integer(100)});
|
|
// add the model to the NameContainer of the dialog model
|
|
m_xDlgModelNameContainer.insertByName(sName, oFTModel);
|
|
XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, m_xDlgContainer.getControl(sName));
|
|
xWindow.addMouseListener(this);
|
|
}catch( Exception e ) {
|
|
System.err.println( e + e.getMessage());
|
|
e.printStackTrace();
|
|
}}
|
|
|
|
protected void closeDialog(){
|
|
xDialog.endExecute();
|
|
}
|
|
|
|
public void mouseReleased(MouseEvent mouseEvent) {
|
|
}
|
|
|
|
public void mousePressed(MouseEvent mouseEvent) {
|
|
if (mouseEvent.PopupTrigger){
|
|
Rectangle aPos = new Rectangle(mouseEvent.X, mouseEvent.Y, 0, 0);
|
|
XControl xControl = UnoRuntime.queryInterface(XControl.class, mouseEvent.Source);
|
|
getPopupMenu().execute( xControl.getPeer(), aPos, com.sun.star.awt.PopupMenuDirection.EXECUTE_DEFAULT);
|
|
}
|
|
}
|
|
|
|
public void mouseExited(MouseEvent mouseEvent) {
|
|
}
|
|
|
|
public void mouseEntered(MouseEvent mouseEvent) {
|
|
}
|
|
|
|
public void disposing(EventObject eventObject) {
|
|
}
|
|
}
|