Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java')
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java216
1 files changed, 149 insertions, 67 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java
index e014e1f8b0..69268fe0a7 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java
@@ -1,8 +1,8 @@
package org.eclipse.swt.widgets;
/*
- * Licensed Materials - Property of IBM,
- * (c) Copyright IBM Corp. 1998, 2001 All Rights Reserved
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
*/
import org.eclipse.swt.internal.*;
@@ -13,6 +13,8 @@ import org.eclipse.swt.events.*;
public class MenuItem extends Item {
Menu parent, menu;
+ int accelerator;
+ boolean enabled = true;
public MenuItem (Menu parent, int style) {
this (parent, style, parent.getItemCount());
@@ -58,6 +60,7 @@ static int checkStyle (int style) {
}
void createHandle (int index) {
+ state |= HANDLE;
int count = parent.getItemCount();
if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
int parentHandle = parent.handle;
@@ -65,8 +68,6 @@ void createHandle (int index) {
handle = OS.PtCreateWidget (OS.PtSeparator (), parentHandle, 0, null);
} else if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
int [] args = {
-// OS.Pt_ARG_FLAGS, OS.Pt_MENU_BUTTON | OS.Pt_SELECTABLE, OS.Pt_MENU_BUTTON | OS.Pt_SELECTABLE,
-// OS.Pt_ARG_FLAGS, OS.Pt_AUTOHIGHLIGHT, OS.Pt_AUTOHIGHLIGHT,
OS.Pt_ARG_INDICATOR_TYPE, (style & SWT.CHECK) != 0 ? OS.Pt_N_OF_MANY : OS.Pt_ONE_OF_MANY, 0
};
handle = OS.PtCreateWidget (OS.PtToggleButton (), parentHandle, args.length / 3, args);
@@ -91,18 +92,13 @@ void createHandle (int index) {
}
if (OS.PtWidgetIsRealized (parentHandle)) {
OS.PtRealizeWidget (topHandle ());
- if ((parent.style & SWT.BAR) == 0) {
- OS.PtExtentWidgetFamily (parentHandle);
- OS.PtPositionMenu (parentHandle, null);
- }
}
}
public int getAccelerator () {
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- //NOT DONE - NOT NEEDED
- return 0;
+ return accelerator;
}
public Display getDisplay () {
@@ -114,9 +110,16 @@ public Display getDisplay () {
public boolean getEnabled () {
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int [] args = {OS.Pt_ARG_FLAGS, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return (args [1] & OS.Pt_BLOCKED) == 0;
+ /*
+ * Bug in Photon. The Pt_BLOCKED flag of a menu item is cleared
+ * when its parent menu is realized. The fix is to remember
+ * the menu item state and reset it when the menu item is
+ * realized.
+ */
+// int [] args = {OS.Pt_ARG_FLAGS, 0, 0};
+// OS.PtGetResources (handle, args.length / 3, args);
+// return (args [1] & OS.Pt_BLOCKED) == 0;
+ return enabled;
}
public Menu getMenu () {
@@ -149,15 +152,22 @@ void hookEvents () {
if ((style & SWT.SEPARATOR) != 0) return;
int windowProc = getDisplay ().windowProc;
if ((style & SWT.CASCADE) != 0) {
- OS.PtAddCallback (handle, OS.Pt_CB_ARM, windowProc, SWT.Show);
+ OS.PtAddCallback (handle, OS.Pt_CB_ARM, windowProc, SWT.Arm);
}
OS.PtAddCallback (handle, OS.Pt_CB_ACTIVATE, windowProc, SWT.Selection);
+ if ((parent.style & SWT.BAR) == 0) {
+ OS.PtAddCallback (handle, OS.Pt_CB_REALIZED, windowProc, SWT.Show);
+ }
}
public boolean isEnabled () {
return getEnabled () && parent.isEnabled ();
}
+int processActivate (int info) {
+ return processArm (info);
+}
+
int processSelection (int info) {
if ((style & SWT.CASCADE) != 0) {
int [] args = {OS.Pt_ARG_BUTTON_TYPE, 0, 0};
@@ -170,38 +180,79 @@ int processSelection (int info) {
return OS.Pt_CONTINUE;
}
+int processShow (int info) {
+ /*
+ * Bug in Photon. The Pt_BLOCKED flag of a menu item is cleared
+ * when its parent menu is realized. The fix is to remember
+ * the menu item state and reset it when the menu item is
+ * realized.
+ */
+ int [] args = {
+ OS.Pt_ARG_FLAGS, enabled ? 0 : OS.Pt_BLOCKED, OS.Pt_BLOCKED,
+ OS.Pt_ARG_FLAGS, enabled ? 0 : OS.Pt_GHOST, OS.Pt_GHOST,
+ };
+ OS.PtSetResources (handle, args.length / 3, args);
+ return OS.Pt_CONTINUE;
+}
+
+int processArm(int info) {
+ if (menu != null) {
+ int menuHandle = menu.handle;
+ if (!OS.PtWidgetIsRealized (menuHandle)) {
+ if ((parent.style & SWT.BAR) == 0) {
+ int [] args = {OS.Pt_ARG_MENU_FLAGS, OS.Pt_MENU_CHILD, OS.Pt_MENU_CHILD};
+ OS.PtSetResources (menuHandle, args.length / 3, args);
+ }
+ OS.PtReParentWidget (menuHandle, handle);
+
+ /*
+ * Bug in Photon. PtPositionMenu does not position the menu
+ * properly when the menu is a direct child a menu bar item.
+ * The fix is to position the menu ourselfs.
+ */
+ if ((parent.style & SWT.BAR) != 0) {
+ PhPoint_t pt = new PhPoint_t ();
+ short [] x = new short [1], y = new short [1];
+ OS.PtGetAbsPosition (handle, x, y);
+ pt.x = x [0];
+ pt.y = y [0];
+ int [] args = {OS.Pt_ARG_HEIGHT, 0, 0};
+ OS.PtGetResources (handle, args.length / 3, args);
+ pt.y += args [1];
+ int ptr = OS.malloc (PhPoint_t.sizeof);
+ OS.memmove (ptr, pt, PhPoint_t.sizeof);
+ args = new int [] {OS.Pt_ARG_POS, ptr, 0};
+ OS.PtSetResources (menuHandle, args.length / 3, args);
+ OS.free (ptr);
+ } else {
+ OS.PtPositionMenu (menuHandle, null);
+ }
+
+ menu.sendEvent (SWT.Show);
+ OS.PtRealizeWidget (menuHandle);
+ }
+ }
+ return OS.Pt_CONTINUE;
+}
+
void releaseChild () {
super.releaseChild ();
if (menu != null) menu.dispose ();
menu = null;
-// parent.destroyItem (this);
}
void releaseWidget () {
- if (menu != null) {
+ if (menu != null && !menu.isDisposed ()) {
menu.releaseWidget ();
menu.releaseHandle ();
}
menu = null;
super.releaseWidget ();
-// if (accelerator != 0) {
-// parent.destroyAcceleratorTable ();
-// }
-// accelerator = 0;
-// Decorations shell = parent.parent;
-// shell.remove (this);
+ if (accelerator != 0) removeAccelerator ();
+ accelerator = 0;
parent = null;
}
-int processShow (int damage) {
- if (menu != null) {
- int menuHandle = menu.handle;
- OS.PtPositionMenu (menuHandle, null);
- OS.PtRealizeWidget (menuHandle);
- }
- return OS.Pt_CONTINUE;
-}
-
public void removeArmListener (ArmListener listener) {
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
@@ -218,6 +269,22 @@ public void removeHelpListener (HelpListener listener) {
eventTable.unhook (SWT.Help, listener);
}
+void removeAccelerator () {
+ if (accelerator == 0) return;
+
+ int keyMods = 0;
+ if ((accelerator & SWT.ALT) != 0) keyMods |= OS.Pk_KM_Alt;
+ if ((accelerator & SWT.SHIFT) != 0) keyMods |= OS.Pk_KM_Shift;
+ if ((accelerator & SWT.CONTROL) != 0) keyMods |= OS.Pk_KM_Ctrl;
+ int key = (accelerator & ~(SWT.ALT | SWT.SHIFT | SWT.CONTROL));
+ Display display = getDisplay ();
+ int keyCode = display.untranslateKey (key);
+ if (keyCode != 0) key = keyCode;
+ else key = Character.toLowerCase ((char)key);
+ Shell shell = parent.getShell ();
+ OS.PtRemoveHotkeyHandler(shell.shellHandle, key, keyMods, (short)0, handle, display.hotkeyProc);
+}
+
public void removeSelectionListener (SelectionListener listener) {
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
@@ -231,24 +298,28 @@ public void setAccelerator (int accelerator) {
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- //NOT DONE: remove previous - NEEDED NEEDED
-//
-// if (accelerator != 0) {
-// int keyMods = 0;
-// if ((accelerator & SWT.ALT) != 0) keyMods |= OS.Pk_KM_Alt;
-// if ((accelerator & SWT.SHIFT) != 0) keyMods |= OS.Pk_KM_Shift;
-// if ((accelerator & SWT.CONTROL) != 0) keyMods |= OS.Pk_KM_Ctrl;
-// int key = accelerator & ~(SWT.ALT | SWT.SHIFT | SWT.CONTROL);
-// //key = Display.untranslateKey(key);
-// key = 0x61;
-// System.out.println("key=" + Integer.toHexString(key));
-// OS.PtAddHotkeyHandler(handle, key, keyMods, (short)0, SWT.Selection, 0);
-// }
+ removeAccelerator ();
+
+ this.accelerator = accelerator;
+ if (accelerator == 0) return;
+
+ int keyMods = 0;
+ if ((accelerator & SWT.ALT) != 0) keyMods |= OS.Pk_KM_Alt;
+ if ((accelerator & SWT.SHIFT) != 0) keyMods |= OS.Pk_KM_Shift;
+ if ((accelerator & SWT.CONTROL) != 0) keyMods |= OS.Pk_KM_Ctrl;
+ int key = (accelerator & ~(SWT.ALT | SWT.SHIFT | SWT.CONTROL));
+ Display display = getDisplay ();
+ int keyCode = display.untranslateKey (key);
+ if (keyCode != 0) key = keyCode;
+ else key = Character.toLowerCase ((char)key);
+ Shell shell = parent.getShell ();
+ OS.PtAddHotkeyHandler(shell.shellHandle, key, keyMods, (short)0, handle, display.hotkeyProc);
}
public void setEnabled (boolean enabled) {
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ this.enabled = enabled;
int [] args = {
OS.Pt_ARG_FLAGS, enabled ? 0 : OS.Pt_BLOCKED, OS.Pt_BLOCKED,
OS.Pt_ARG_FLAGS, enabled ? 0 : OS.Pt_GHOST, OS.Pt_GHOST,
@@ -284,26 +355,17 @@ public void setMenu (Menu menu) {
this.menu = menu;
if (oldMenu != null) {
oldMenu.cascade = null;
- int menuHandle = oldMenu.handle;
- int shellHandle = oldMenu.parent.topHandle ();
if ((parent.style & SWT.BAR) == 0) {
- int [] args = {OS.Pt_ARG_BUTTON_TYPE, 0, OS.Pt_MENU_RIGHT};
+ int [] args = {OS.Pt_ARG_BUTTON_TYPE, OS.Pt_MENU_TEXT, 0};
OS.PtSetResources (handle, args.length / 3, args);
- args = new int [] {OS.Pt_ARG_MENU_FLAGS, 0, OS.Pt_MENU_CHILD};
- OS.PtSetResources (menuHandle, args.length / 3, args);
}
- OS.PtReParentWidget (menuHandle, shellHandle);
}
if (menu != null) {
menu.cascade = this;
- int menuHandle = menu.handle;
if ((parent.style & SWT.BAR) == 0) {
- int [] args = {OS.Pt_ARG_BUTTON_TYPE, OS.Pt_MENU_RIGHT, OS.Pt_MENU_RIGHT};
+ int [] args = {OS.Pt_ARG_BUTTON_TYPE, OS.Pt_MENU_RIGHT, 0};
OS.PtSetResources (handle, args.length / 3, args);
- args = new int [] {OS.Pt_ARG_MENU_FLAGS, OS.Pt_MENU_CHILD, OS.Pt_MENU_CHILD};
- OS.PtSetResources (menuHandle, args.length / 3, args);
}
- OS.PtReParentWidget (menuHandle, handle);
}
}
@@ -333,31 +395,51 @@ public void setText (String string) {
if (mnemonic == 0) mnemonic = text [i];
j--;
}
- }
- byte [] buffer2;
+ }
+ int keyMods = 0;
+ byte [] buffer2 = new byte [1];
if (accel && ++i < text.length) {
- char [] accelText = new char [text.length - i];
- System.arraycopy (text, i, accelText, 0, accelText.length);
- buffer2 = Converter.wcsToMbcs (null, accelText, true);
- } else {
- buffer2 = new byte [1];
+ int start = i;
+// while (i < text.length) {
+// if (text [i] == '+') {
+// String str = new String (text, start, i - start);
+// if (str.equals ("Ctrl")) keyMods |= OS.Pk_KM_Ctrl;
+// if (str.equals ("Shift")) keyMods |= OS.Pk_KM_Shift;
+// if (str.equals ("Alt")) keyMods |= OS.Pk_KM_Alt;
+// start = i + 1;
+// }
+// i++;
+// }
+ if (start < text.length) {
+ char [] accelText = new char [text.length - start];
+ System.arraycopy (text, start, accelText, 0, accelText.length);
+ buffer2 = Converter.wcsToMbcs (null, accelText, true);
+ }
}
while (j < text.length) text [j++] = 0;
byte [] buffer1 = Converter.wcsToMbcs (null, text, true);
- int ptr = OS.malloc (buffer1.length);
- OS.memmove (ptr, buffer1, buffer1.length);
+ int ptr1 = OS.malloc (buffer1.length);
+ OS.memmove (ptr1, buffer1, buffer1.length);
+ int ptr2 = OS.malloc (buffer2.length);
+ OS.memmove (ptr2, buffer2, buffer2.length);
int ptr3 = 0;
if (mnemonic != 0) {
byte [] buffer3 = Converter.wcsToMbcs (null, new char []{mnemonic}, true);
ptr3 = OS.malloc (buffer3.length);
OS.memmove (ptr3, buffer3, buffer3.length);
}
+ if ((parent.style & SWT.BAR) != 0) {
+ replaceMnemonic (mnemonic, OS.Pk_KM_Alt);
+ }
int [] args = {
- OS.Pt_ARG_TEXT_STRING, ptr, 0,
+ OS.Pt_ARG_TEXT_STRING, ptr1, 0,
+ OS.Pt_ARG_ACCEL_TEXT, ptr2, 0,
+ OS.Pt_ARG_MODIFIER_KEYS, keyMods, keyMods,
OS.Pt_ARG_ACCEL_KEY, ptr3, 0,
};
OS.PtSetResources (handle, args.length / 3, args);
- OS.free (ptr);
+ OS.free (ptr1);
+ OS.free (ptr2);
OS.free (ptr3);
/*
* Bug on Photon. When a the text is set on a menu
@@ -368,4 +450,4 @@ public void setText (String string) {
if (OS.PtWidgetIsRealized (handle)) OS.PtExtentWidget (handle);
}
-} \ No newline at end of file
+}

Back to the top