UnoMenu.java (ae15d43a) UnoMenu.java (d026be40)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 11 unchanged lines hidden (view full) ---

20 *************************************************************/
21
22import com.sun.star.awt.MenuEvent;
23import com.sun.star.awt.MenuItemStyle;
24import com.sun.star.awt.Rectangle;
25import com.sun.star.awt.WindowAttribute;
26import com.sun.star.awt.WindowClass;
27import com.sun.star.awt.XMenuBar;
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 11 unchanged lines hidden (view full) ---

20 *************************************************************/
21
22import com.sun.star.awt.MenuEvent;
23import com.sun.star.awt.MenuItemStyle;
24import com.sun.star.awt.Rectangle;
25import com.sun.star.awt.WindowAttribute;
26import com.sun.star.awt.WindowClass;
27import com.sun.star.awt.XMenuBar;
28import com.sun.star.awt.XMenuExtended;
29import com.sun.star.awt.XMenuListener;
30import com.sun.star.awt.XPopupMenu;
31import com.sun.star.awt.XToolkit;
32import com.sun.star.awt.XTopWindow;
33import com.sun.star.awt.XWindow;
34import com.sun.star.awt.XWindowPeer;
35import com.sun.star.frame.XFrame;
36import com.sun.star.frame.XFramesSupplier;

--- 25 unchanged lines hidden (view full) ---

62 }
63 }
64
65
66 public XPopupMenu getPopupMenu(){
67 XPopupMenu xPopupMenu = null;
68 try{
69 // create a popup menu
28import com.sun.star.awt.XMenuListener;
29import com.sun.star.awt.XPopupMenu;
30import com.sun.star.awt.XToolkit;
31import com.sun.star.awt.XTopWindow;
32import com.sun.star.awt.XWindow;
33import com.sun.star.awt.XWindowPeer;
34import com.sun.star.frame.XFrame;
35import com.sun.star.frame.XFramesSupplier;

--- 25 unchanged lines hidden (view full) ---

61 }
62 }
63
64
65 public XPopupMenu getPopupMenu(){
66 XPopupMenu xPopupMenu = null;
67 try{
68 // create a popup menu
70 Object oPopupMenu = m_xMCF.createInstanceWithContext("stardiv.Toolkit.VCLXPopupMenu", m_xContext);
69 Object oPopupMenu = m_xMCF.createInstanceWithContext("com.sun.star.awt.PopupMenu", m_xContext);
71 xPopupMenu = (XPopupMenu) UnoRuntime.queryInterface(XPopupMenu.class, oPopupMenu);
70 xPopupMenu = (XPopupMenu) UnoRuntime.queryInterface(XPopupMenu.class, oPopupMenu);
72 XMenuExtended xMenuExtended = (XMenuExtended) UnoRuntime.queryInterface(XMenuExtended.class, xPopupMenu);
73
71
74 xPopupMenu.insertItem((short) 0, "~First Entry", MenuItemStyle.AUTOCHECK, (short) 0);
75 xPopupMenu.insertItem((short) 1, "First ~Radio Entry", (short) (MenuItemStyle.RADIOCHECK + MenuItemStyle.AUTOCHECK), (short) 1);
76 xPopupMenu.insertItem((short) 2, "~Second Radio Entry", (short) (MenuItemStyle.RADIOCHECK + MenuItemStyle.AUTOCHECK), (short) 2);
77 xPopupMenu.insertItem((short) 3, "~Third RadioEntry",(short) (MenuItemStyle.RADIOCHECK + MenuItemStyle.AUTOCHECK), (short) 3);
78 xPopupMenu.insertSeparator((short)4);
79 xPopupMenu.insertItem((short) 4, "F~ifth Entry", (short) (MenuItemStyle.CHECKABLE + MenuItemStyle.AUTOCHECK), (short) 5);
80 xPopupMenu.insertItem((short) 5, "~Fourth Entry", (short) (MenuItemStyle.CHECKABLE + MenuItemStyle.AUTOCHECK), (short) 6);
81 xPopupMenu.enableItem((short) 1, false);
82 xPopupMenu.insertItem((short) 6, "~Sixth Entry", (short) 0, (short) 7);
83 xPopupMenu.insertItem((short) 7, "~Close Dialog", (short) 0, (short) 8);
84 xPopupMenu.checkItem((short) 2, true);
72 // ID must start be > 0
73 short nId = 1;
74 short nPos = 0;
75
76 xPopupMenu.insertItem(nId++, "First Entry", MenuItemStyle.AUTOCHECK, nPos++);
77 xPopupMenu.insertItem(nId++, "First Radio Entry", (short) (MenuItemStyle.RADIOCHECK + MenuItemStyle.AUTOCHECK), nPos++);
78 xPopupMenu.insertItem(nId++, "Second Radio Entry", (short) (MenuItemStyle.RADIOCHECK + MenuItemStyle.AUTOCHECK), nPos++);
79 xPopupMenu.insertItem(nId++, "Third RadioEntry",(short) (MenuItemStyle.RADIOCHECK + MenuItemStyle.AUTOCHECK), nPos++);
80 xPopupMenu.insertSeparator(nPos++);
81 xPopupMenu.insertItem(nId++, "Fifth Entry", (short) (MenuItemStyle.CHECKABLE + MenuItemStyle.AUTOCHECK), nPos++);
82 xPopupMenu.insertItem(nId++, "Fourth Entry", (short) (MenuItemStyle.CHECKABLE + MenuItemStyle.AUTOCHECK), nPos++);
83 xPopupMenu.insertItem(nId++, "Sixth Entry", (short) 0, nPos++);
84 xPopupMenu.insertItem(nId++, "Close Dialog", (short) 0, nPos++);
85
86 xPopupMenu.enableItem((short) 2, false);
87 xPopupMenu.checkItem((short) 3, true);
88
85 xPopupMenu.addMenuListener(this);
86 }catch( Exception e ) {
87 throw new java.lang.RuntimeException("cannot happen...");
88 }
89 return xPopupMenu;
90 }
91
92
93 public void addMenuBar(XTopWindow _xTopWindow, XMenuListener _xMenuListener){
94 try{
95 // create a menubar at the global MultiComponentFactory...
89 xPopupMenu.addMenuListener(this);
90 }catch( Exception e ) {
91 throw new java.lang.RuntimeException("cannot happen...");
92 }
93 return xPopupMenu;
94 }
95
96
97 public void addMenuBar(XTopWindow _xTopWindow, XMenuListener _xMenuListener){
98 try{
99 // create a menubar at the global MultiComponentFactory...
96 Object oMenuBar = m_xMCF.createInstanceWithContext("stardiv.Toolkit.VCLXMenuBar", m_xContext);
100 Object oMenuBar = m_xMCF.createInstanceWithContext("com.sun.star.awt.MenuBar", m_xContext);
97 // add the menu items...
98 XMenuBar xMenuBar = (XMenuBar) UnoRuntime.queryInterface(XMenuBar.class, oMenuBar);
101 // add the menu items...
102 XMenuBar xMenuBar = (XMenuBar) UnoRuntime.queryInterface(XMenuBar.class, oMenuBar);
99 xMenuBar.insertItem((short) 0, "~First MenuBar Item", com.sun.star.awt.MenuItemStyle.AUTOCHECK, (short) 0);
100 xMenuBar.insertItem((short) 1, "~Second MenuBar Item", com.sun.star.awt.MenuItemStyle.AUTOCHECK, (short) 1);
101 xMenuBar.setPopupMenu((short) 0, getPopupMenu());
103 xMenuBar.insertItem((short) 1, "~First MenuBar Item", com.sun.star.awt.MenuItemStyle.AUTOCHECK, (short) 0);
104 xMenuBar.insertItem((short) 2, "~Second MenuBar Item", com.sun.star.awt.MenuItemStyle.AUTOCHECK, (short) 1);
105 xMenuBar.setPopupMenu((short) 1, getPopupMenu());
102 xMenuBar.addMenuListener(_xMenuListener);
103 _xTopWindow.setMenuBar(xMenuBar);
104 }catch( Exception e ) {
105 throw new java.lang.RuntimeException("cannot happen...");
106 }}
107
108 protected void closeDialog(){
109 XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, mxTopWindow);

--- 42 unchanged lines hidden (view full) ---

152 return xTopWindow;
153 }
154
155 public void addMenuBar(XWindow _xWindow){
156 XTopWindow xTopWindow = (XTopWindow) UnoRuntime.queryInterface(XTopWindow.class, _xWindow);
157 addMenuBar(xTopWindow, this);
158 }
159
106 xMenuBar.addMenuListener(_xMenuListener);
107 _xTopWindow.setMenuBar(xMenuBar);
108 }catch( Exception e ) {
109 throw new java.lang.RuntimeException("cannot happen...");
110 }}
111
112 protected void closeDialog(){
113 XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, mxTopWindow);

--- 42 unchanged lines hidden (view full) ---

156 return xTopWindow;
157 }
158
159 public void addMenuBar(XWindow _xWindow){
160 XTopWindow xTopWindow = (XTopWindow) UnoRuntime.queryInterface(XTopWindow.class, _xWindow);
161 addMenuBar(xTopWindow, this);
162 }
163
160 public void select(MenuEvent menuEvent){
164 public void itemSelected(MenuEvent menuEvent){
161 // find out which menu item has been triggered,
162 // by getting the menu-id...
163 switch (menuEvent.MenuId){
165 // find out which menu item has been triggered,
166 // by getting the menu-id...
167 switch (menuEvent.MenuId){
164 case 0:
168 case 1:
165 // add your menu-item-specific code here:
166 break;
169 // add your menu-item-specific code here:
170 break;
167 case 1:
171 case 2:
168 // add your menu-item-specific code here:
169 break;
172 // add your menu-item-specific code here:
173 break;
170 case 7:
174 case 8:
171 closeDialog();
172 default:
173 //..
174 }
175 }
176
175 closeDialog();
176 default:
177 //..
178 }
179 }
180
177 public void highlight(MenuEvent menuEvent) {
181 public void itemHighlighted(MenuEvent menuEvent) {
178 int i = 0;
179 }
180
182 int i = 0;
183 }
184
181 public void deactivate(MenuEvent menuEvent) {
185 public void itemDeactivated(MenuEvent menuEvent) {
182 int i = 0; }
183
186 int i = 0; }
187
184 public void activate(MenuEvent menuEvent) {
188 public void itemActivated(MenuEvent menuEvent) {
185 int i = 0;
186 }
187
188}
189 int i = 0;
190 }
191
192}