menu: remove preferences and about menu 02/13302/1
authormunkyu.im <munkyu.im@samsung.com>
Tue, 3 Dec 2013 06:59:37 +0000 (15:59 +0900)
committermunkyu.im <munkyu.im@samsung.com>
Tue, 3 Dec 2013 06:59:37 +0000 (15:59 +0900)
They are default swt menu and do not have handler.
They are unnecessary. so remove them.

Change-Id: I765e8feb3c235bb898a5f48b59090995a5b8560d
Signed-off-by: munkyu.im <munkyu.im@samsung.com>
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java
tizen/src/skin/client/src/org/tizen/emulator/skin/util/CocoaUtil.java [new file with mode: 0644]

index 78d5ddcbb02ffcc104a4d191c0d2de028ab60ef6..1062e353aa4f6dd80b95fedc9c657acf2b9a1557 100644 (file)
@@ -59,6 +59,7 @@ import org.tizen.emulator.skin.image.ImageRegistry;
 import org.tizen.emulator.skin.info.SkinInformation;
 import org.tizen.emulator.skin.log.SkinLogger;
 import org.tizen.emulator.skin.log.SkinLogger.SkinLogLevel;
+import org.tizen.emulator.skin.util.CocoaUtil;
 import org.tizen.emulator.skin.util.IOUtil;
 import org.tizen.emulator.skin.util.JaxbUtil;
 import org.tizen.emulator.skin.util.SkinRotation;
@@ -84,10 +85,17 @@ public class EmulatorSkinMain {
         * @param args
         */
        public static void main(String[] args) {
+               /* make vm name and remove unused menu for macos-x */
                if (SwtUtil.isMacPlatform()) {
-                       //TODO: event handling of about dialog 
                        System.setProperty("apple.laf.useScreenMenuBar", "true");
-                       System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Emulator"); 
+                       System.setProperty("com.apple.mrj.application.apple.menu.about.name",
+                                       "Emulator");
+                       Display display = Display.getDefault();
+                       display.syncExec(new Runnable() {
+                               public void run() {
+                                       new CocoaUtil().removeTopMenuItems();
+                               }
+                       });
                }
 
                String simpleMsg = getSimpleMsg(args);
diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/util/CocoaUtil.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/util/CocoaUtil.java
new file mode 100644 (file)
index 0000000..430df17
--- /dev/null
@@ -0,0 +1,106 @@
+/**
+ *
+ *
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Munkyu Im <munkyu.im@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.skin.util;
+
+import java.lang.reflect.InvocationTargetException;
+
+public class CocoaUtil {
+
+       private static final long aboutMenuValue = 0;
+       private static final long prefMenuValue = 2;
+       public static final String NSApplication_CLASS = "org.eclipse.swt.internal.cocoa.NSApplication";
+       public static final String NSMenu_CLASS = "org.eclipse.swt.internal.cocoa.NSMenu";
+       public static final String NSMenuItem_CLASS = "org.eclipse.swt.internal.cocoa.NSMenuItem";
+
+       public static Object invokeMethod(Class<?> clazz, Object object, String method, Object[] args)
+                       throws IllegalArgumentException, IllegalAccessException, InvocationTargetException,
+                       SecurityException, NoSuchMethodException {
+               Class<?>[] signature = new Class[args.length];
+               for (int i = 0; i < args.length; i++) {
+                       Class<?> thisClass = args[i].getClass();
+                       if (thisClass == Integer.class)
+                               signature[i] = int.class;
+                       else if (thisClass == Long.class)
+                               signature[i] = long.class;
+                       else if (thisClass == Byte.class)
+                               signature[i] = byte.class;
+                       else if ( thisClass == Boolean.class )
+                signature[i] = boolean.class;
+                       else
+                               signature[i] = thisClass;
+               }
+               return clazz.getDeclaredMethod(method, signature).invoke(object, args);
+       }
+           
+       // remove about and preference menu item
+       public void removeTopMenuItems() {
+               try {
+                       Class<?> nsmenuClass = Class.forName(NSMenu_CLASS);
+                       Class<?> nsmenuitemClass = Class.forName(NSMenuItem_CLASS);
+                       Class<?> nsapplicationClass = Class.forName(NSApplication_CLASS);
+                       
+                       Object sharedApplication = nsapplicationClass.getDeclaredMethod(
+                                       "sharedApplication", (Class<?>[]) null).invoke(null,
+                                       (Object[]) null);
+                       Object mainMenu = sharedApplication.getClass()
+                                       .getDeclaredMethod("mainMenu", (Class<?>[]) null)
+                                       .invoke(sharedApplication, (Object[]) null);
+
+                       Object mainMenuItem = invokeMethod(nsmenuClass, mainMenu,
+                                       "itemAtIndex", new Object[] { new Long(0) });
+                       Object appMenu = mainMenuItem.getClass()
+                                       .getDeclaredMethod("submenu", (Class<?>[]) null)
+                                       .invoke(mainMenuItem, (Object[]) null);
+
+                       Object aboutMenuItem = invokeMethod(nsmenuClass, appMenu,
+                                       "itemAtIndex", new Object[] { new Long(aboutMenuValue) });
+                       Object prefMenuItem = invokeMethod(nsmenuClass, appMenu,
+                                       "itemAtIndex", new Object[] { new Long(prefMenuValue) });
+
+                       //set hidden
+                       invokeMethod(nsmenuitemClass, aboutMenuItem, "setHidden",
+                                       new Object[] { new Boolean(true) });
+                       invokeMethod(nsmenuitemClass, prefMenuItem, "setHidden",
+                                       new Object[] { new Boolean(true) });
+
+               } catch (ClassNotFoundException e) {
+                       e.printStackTrace();
+               } catch (IllegalArgumentException e) {
+                       e.printStackTrace();
+               } catch (SecurityException e) {
+                       e.printStackTrace();
+               } catch (IllegalAccessException e) {
+                       e.printStackTrace();
+               } catch (InvocationTargetException e) {
+                       e.printStackTrace();
+               } catch (NoSuchMethodException e) {
+                       e.printStackTrace();
+               }
+       }
+}