Changeset 83 for trunk/src


Ignore:
Timestamp:
May 28, 2008, 12:48:03 AM (17 years ago)
Author:
lpino
Message:

(MenuItem.java) - A lot of new code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/org.eclipse.swt/Eclipse SWT/pm/org/eclipse/swt/widgets/MenuItem.java

    r67 r83  
    212212}
    213213
    214 //void fillAccel (ACCEL accel) {
    215 //      accel.fVirt = 0;
    216 //      accel.cmd = accel.key = 0;
    217 //      if (accelerator == 0) return;
    218 //      int fVirt = OS.FVIRTKEY;
    219 //      int key = accelerator & ~(SWT.ALT | SWT.CTRL | SWT.SHIFT);
    220 //      int vKey = Display.untranslateKey (key);
    221 //      if (vKey != 0) {
    222 //              key = vKey;     
    223 //      } else {
     214void fillAccel (ACCEL accel) {
     215        accel.fs = 0;
     216        accel.cmd = accel.key = 0;
     217        if (accelerator == 0) return;
     218        int fs = OS.AF_VIRTUALKEY;
     219        int key = accelerator & ~(SWT.ALT | SWT.CTRL | SWT.SHIFT);
     220        int vKey = Display.untranslateKey (key);
     221        if (vKey != 0) {
     222                key = vKey;     
     223        } //else {
    224224//              switch (key) {
    225225//                      /*
     
    229229//                      * as a special case.
    230230//                      */
    231 //                      case 27: key = OS.VK_ESCAPE; break;
     231//                      case 27: key = OS.VK_ESC; break;
    232232//                      case 127: key = OS.VK_DELETE; break;
    233233//                      default: {
    234 //                              key = wcsToMbcs ((char) key);
     234////                            key = wcsToMbcs ((char) key);
    235235//                              if (key == 0) return;
    236 //                              if (OS.IsWinCE) {
    237 //                                      key = OS.CharUpper ((short) key);
    238 //                              } else {
     236////                            if (OS.IsWinCE) {
     237////                                    key = OS.CharUpper ((short) key);
     238////                            } else {
    239239//                                      vKey = OS.VkKeyScan ((short) key) & 0xFF;
    240240//                                      if (vKey == -1) {
    241 //                                              fVirt = 0;
     241//                                              fs = 0;
    242242//                                      } else {
    243243//                                              key = vKey;
    244244//                                      }
    245 //                              }
     245////                            }
    246246//                      }
    247247//              }
    248248//      }
    249 //      accel.key = (short) key;
    250 //      accel.cmd = (short) id;
    251 //      accel.fVirt = (byte) fVirt;
    252 //      if ((accelerator & SWT.ALT) != 0) accel.fVirt |= OS.FALT;
    253 //      if ((accelerator & SWT.CTRL) != 0) accel.fVirt |= OS.FCONTROL;
    254 //      if ((accelerator & SWT.SHIFT) != 0) accel.fVirt |= OS.FSHIFT;
    255 //}
     249        accel.key = (short) key;
     250        accel.cmd = (short) id;
     251        accel.fs = (byte) fs;
     252        if ((accelerator & SWT.ALT) != 0) accel.fs |= OS.AF_ALT;
     253        if ((accelerator & SWT.CTRL) != 0) accel.fs |= OS.AF_CONTROL;
     254        if ((accelerator & SWT.SHIFT) != 0) accel.fs |= OS.AF_SHIFT;
     255       
     256        System.out.println("MenuItem.fillAccel - KEY = " + accel.key);
     257}
    256258
    257259/**
     
    294296 * @see #isEnabled
    295297 */
    296 //public boolean getEnabled () {
    297 //      checkWidget ();
    298 //      int hMenu = parent.handle;
    299 //      MENUITEMINFO info = new MENUITEMINFO ();
    300 //      info.cbSize = MENUITEMINFO.sizeof;
    301 //      info.fMask = OS.MIIM_STATE;
    302 //      boolean success;
    303 //      if (OS.IsWinCE) {
    304 //              int index = parent.indexOf (this);
    305 //              if (index == -1) error (SWT.ERROR_CANNOT_GET_ENABLED);
    306 //              success = OS.GetMenuItemInfo (hMenu, index, true, info);
    307 //      } else {
    308 //              success = OS.GetMenuItemInfo (hMenu, id, false, info);
    309 //      }
    310 //      if (!success) error (SWT.ERROR_CANNOT_GET_ENABLED);
    311 //      return (info.fState & (OS.MFS_DISABLED | OS.MFS_GRAYED)) == 0;
    312 //}
     298public boolean getEnabled () {
     299        checkWidget ();
     300        int hMenu = parent.handle;
     301        short sState = (short) OS.WinSendMsg(hMenu, OS.MM_QUERYITEMATTR,  OS.MPFROM2SHORT((short)id, (short)OS.FALSE), OS.MIA_DISABLED);
     302        return (sState & OS.MIA_DISABLED) == 0;
     303}
    313304
    314305/**
     
    365356 * </ul>
    366357 */
    367 //public boolean getSelection () {
    368 //      checkWidget ();
    369 //      if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
    370 //      int hMenu = parent.handle;
    371 //      MENUITEMINFO info = new MENUITEMINFO ();
    372 //      info.cbSize = MENUITEMINFO.sizeof;
    373 //      info.fMask = OS.MIIM_STATE;
    374 //      boolean success = OS.GetMenuItemInfo (hMenu, id, false, info);
    375 //      if (!success) error (SWT.ERROR_CANNOT_GET_SELECTION);
    376 //      return (info.fState & OS.MFS_CHECKED) !=0;
    377 //}
     358public boolean getSelection () {
     359        checkWidget ();
     360        if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
     361        int hMenu = parent.handle;
     362        short sState = (short) OS.WinSendMsg(hMenu, OS.MM_QUERYITEMATTR,  OS.MPFROM2SHORT((short)id, (short)OS.FALSE), OS.MIA_CHECKED);
     363        return (sState & OS.MIA_CHECKED) !=0;
     364}
    378365
    379366/**
     
    392379 * @see #getEnabled
    393380 */
    394 //public boolean isEnabled () {
    395 //      return getEnabled () && parent.isEnabled ();
    396 //}
    397 //
    398 //void releaseChild () {
    399 //      super.releaseChild ();
    400 //      if (menu != null) menu.dispose ();
    401 //      menu = null;
    402 //      parent.destroyItem (this);
    403 //}
    404 
    405 //void releaseWidget () {
    406 //      if (menu != null) {
    407 //              menu.releaseWidget ();
    408 //              menu.releaseHandle ();
    409 //      }
    410 //      menu = null;
    411 //      super.releaseWidget ();
     381public boolean isEnabled () {
     382        return getEnabled () && parent.isEnabled ();
     383}
     384
     385void releaseChild () {
     386        super.releaseChild ();
     387        if (menu != null) menu.dispose ();
     388        menu = null;
     389        parent.destroyItem (this);
     390}
     391
     392void releaseWidget () {
     393        if (menu != null) {
     394                menu.releaseWidget ();
     395                menu.releaseHandle ();
     396        }
     397        menu = null;
     398        super.releaseWidget ();
    412399//      if (accelerator != 0) {
    413400//              parent.destroyAcceleratorTable ();
    414401//      }
    415 //      accelerator = 0;
    416 //      Decorations shell = parent.parent;
    417 //      shell.remove (this);
    418 //      parent = null;
    419 //}
     402        accelerator = 0;
     403        Decorations shell = parent.parent;
     404        shell.remove (this);
     405        parent = null;
     406}
    420407
    421408/**
     
    503490 * </ul>
    504491 */
    505 //public void setAccelerator (int accelerator) {
    506 //      checkWidget ();
    507 //      this.accelerator = accelerator;
    508 //      parent.destroyAcceleratorTable ();
    509 //}
     492public void setAccelerator (int accelerator) {
     493        checkWidget ();
     494        this.accelerator = accelerator;
     495        parent.destroyAcceleratorTable ();
     496}
    510497
    511498/**
     
    522509 * </ul>
    523510 */
    524 //public void setEnabled (boolean enabled) {
    525 //      checkWidget ();
    526 //      int hMenu = parent.handle;
    527 //      if (OS.IsWinCE) {
    528 //              int index = parent.indexOf (this);
    529 //              if (index == -1) return;
    530 //              int uEnable = OS.MF_BYPOSITION | (enabled ? OS.MF_ENABLED : OS.MF_GRAYED);
    531 //              OS.EnableMenuItem (hMenu, index, uEnable);
    532 //              if (OS.IsPPC) {
    533 //                      /* if it is a top level menu item, set the state in the corresponding tool item */
    534 //                      Decorations shell = parent.parent;
    535 //                      if (parent == shell.menuBar) {
    536 //                              int fsState = OS.SendMessage (shell.hwndTB, OS.TB_GETSTATE, id, 0);
    537 //                              fsState &= ~OS.TBSTATE_ENABLED;
    538 //                              if (enabled) fsState |= OS.TBSTATE_ENABLED;
    539 //                              OS.SendMessage (shell.hwndTB, OS.TB_SETSTATE, id, fsState);
    540 //                      }
    541 //              }
    542 //      } else {
     511public void setEnabled (boolean enabled) {
     512        checkWidget ();
     513        int hMenu = parent.handle;
    543514//              MENUITEMINFO info = new MENUITEMINFO ();
    544515//              info.cbSize = MENUITEMINFO.sizeof;
    545516//              info.fMask = OS.MIIM_STATE;
     517        short sState = (short) OS.WinSendMsg(hMenu, OS.MM_QUERYITEMATTR,  OS.MPFROM2SHORT((short)id, (short)OS.FALSE), OS.MIA_DISABLED);
    546518//              boolean success = OS.GetMenuItemInfo (hMenu, id, false, info);
    547519//              if (!success) error (SWT.ERROR_CANNOT_SET_ENABLED);
    548 //              info.fState &= ~(OS.MFS_DISABLED | OS.MFS_GRAYED);
    549 //              if (!enabled) info.fState |= (OS.MFS_DISABLED | OS.MFS_GRAYED);
    550 //              success = OS.SetMenuItemInfo (hMenu, id, false, info);
     520        sState &= ~(OS.MIA_DISABLED);
     521        if (!enabled) sState |= (OS.MIA_DISABLED);
     522        int success = OS.WinSendMsg(hMenu, OS.MM_SETITEMATTR,  OS.MPFROM2SHORT((short)id, (short)OS.FALSE), OS.MPFROM2SHORT((short)OS.MIA_DISABLED, sState));
     523//              boolean success = OS.SetMenuItemInfo (hMenu, id, false, info);
    551524//              if (!success) error (SWT.ERROR_CANNOT_SET_ENABLED);
    552 //      }
    553525//      parent.redraw ();
    554 //}
     526}
    555527
    556528/**
     
    609581 * </ul>
    610582 */
    611 //public void setMenu (Menu menu) {
    612 //      checkWidget ();
    613 //
    614 //      /* Check to make sure the new menu is valid */
    615 //      if ((style & SWT.CASCADE) == 0) {
    616 //              error (SWT.ERROR_MENUITEM_NOT_CASCADE);
    617 //      }
    618 //      if (menu != null) {
    619 //              if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
    620 //              if ((menu.style & SWT.DROP_DOWN) == 0) {
    621 //                      error (SWT.ERROR_MENU_NOT_DROP_DOWN);
    622 //              }
    623 //              if (menu.parent != parent.parent) {
    624 //                      error (SWT.ERROR_INVALID_PARENT);
    625 //              }
    626 //      }
    627 //
    628 //      /* Assign the new menu */
    629 //      Menu oldMenu = this.menu;
    630 //      if (oldMenu == menu) return;
    631 //      if (oldMenu != null) oldMenu.cascade = null;
    632 //      this.menu = menu;
    633 //
    634 //      /* Assign the new menu in the OS */
    635 //     
    636 //      /*
    637 //      * Feature in Windows.  When SetMenuItemInfo () is used to
    638 //      * set a submenu and the menu item already has a submenu,
    639 //      * Windows destroys the previous menu.  This is undocumented
    640 //      * and unexpected but not necessarily wrong.  The fix is to
    641 //      * remove the item with RemoveMenu () which does not destroy
    642 //      * the submenu and then insert the item with InsertMenuItem ().
    643 //      */
    644 //      int hMenu = parent.handle;
    645 //      MENUITEMINFO info = new MENUITEMINFO ();
    646 //      info.cbSize = MENUITEMINFO.sizeof;
    647 //      info.fMask = OS.MIIM_DATA;
    648 //      int index = 0;
    649 //      while (OS.GetMenuItemInfo (hMenu, index, true, info)) {
    650 //              if (info.dwItemData == id) break;
    651 //              index++;
    652 //      }
    653 //      if (info.dwItemData != id) return;
    654 //      int cch = 128;
    655 //      int hHeap = OS.GetProcessHeap ();
    656 //      int byteCount = cch * TCHAR.sizeof;
    657 //      int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
    658 //      info.fMask = OS.MIIM_STATE | OS.MIIM_ID | OS.MIIM_TYPE | OS.MIIM_DATA;
    659 //      info.dwTypeData = pszText;
    660 //      info.cch = cch;
    661 //      boolean success = OS.GetMenuItemInfo (hMenu, index, true, info);
    662 //      if (menu != null) {
    663 //              menu.cascade = this;
    664 //              info.fMask |= OS.MIIM_SUBMENU;
    665 //              info.hSubMenu = menu.handle;
    666 //      }
    667 //      OS.RemoveMenu (hMenu, index, OS.MF_BYPOSITION);
    668 //      if (OS.IsWinCE) {
    669 //              /*
    670 //              * On WinCE, InsertMenuItem is not available.  SetMenuItemInfo
    671 //              * does not set the menu item state and submenu use InsertMenu
    672 //              * to set these fields and SetMenuItemInfo to set the menu item
    673 //              * data.  NOTE: SetMenuItemInfo is also used to set the string
    674 //              * that was queried from the original menu item.
    675 //              */
    676 //              int uIDNewItem = id;
    677 //              int uFlags = OS.MF_BYPOSITION;
    678 //              if (menu != null) {
    679 //                      uFlags |= OS.MF_POPUP;
    680 //                      uIDNewItem = menu.handle;
    681 //              }
    682 //              TCHAR lpNewItem = new TCHAR (0, "", true);
    683 //              success = OS.InsertMenu (hMenu, index, uFlags, uIDNewItem, lpNewItem);
    684 //              if (success) {
    685 //                      info.fMask = OS.MIIM_DATA | OS.MIIM_TYPE;
    686 //                      success = OS.SetMenuItemInfo (hMenu, index, true, info);
    687 //                      if ((info.fState & (OS.MFS_DISABLED | OS.MFS_GRAYED)) != 0) {
    688 //                              OS.EnableMenuItem (hMenu, index, OS.MF_BYPOSITION | OS.MF_GRAYED);
    689 //                      }
    690 //                      if ((info.fState & OS.MFS_CHECKED) != 0) {
    691 //                              OS.CheckMenuItem (hMenu, index, OS.MF_BYPOSITION | OS.MF_CHECKED);
    692 //                      }
    693 //                      if (OS.IsPPC) {
    694 //                              if (success) {
    695 //                                      /* if it is a top level menu item, update the corresponding tool item */
    696 //                                      Decorations shell = parent.parent;
    697 //                                      if (parent == shell.menuBar) {
    698 //                                              OS.SendMessage (shell.hwndCB, OS.SHCMBM_SETSUBMENU, id, uIDNewItem);
    699 //                                      }
    700 //                              }
    701 //                      }
    702 //              }
    703 //             
    704 //      } else {
    705 //              success = OS.InsertMenuItem (hMenu, index, true, info);
    706 //      }
    707 //      if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
    708 //      if (!success) error (SWT.ERROR_CANNOT_SET_MENU);
     583public void setMenu (Menu menu) {
     584        checkWidget ();
     585        /* Check to make sure the new menu is valid */
     586        if ((style & SWT.CASCADE) == 0) {
     587                error (SWT.ERROR_MENUITEM_NOT_CASCADE);
     588        }
     589        if (menu != null) {
     590                if (menu.isDisposed())
     591                    error(SWT.ERROR_INVALID_ARGUMENT);
     592                if ((menu.style & SWT.DROP_DOWN) == 0) {
     593                        error (SWT.ERROR_MENU_NOT_DROP_DOWN);
     594                }
     595                if (menu.parent != parent.parent) {
     596                        error (SWT.ERROR_INVALID_PARENT);
     597                }
     598        }
     599        /* Assign the new menu */
     600        Menu oldMenu = this.menu;
     601        if (oldMenu == menu) return;
     602        if (oldMenu != null) oldMenu.cascade = null;
     603        this.menu = menu;
     604
     605        /* Assign the new menu in the OS */
     606       
     607        int hMenu = parent.handle;
     608        MENUITEM info = new MENUITEM ();
     609        int index = 0;
     610        while (index < parent.getItemCount ()) {
     611                if (OS.WinSendMsg (hMenu, OS.MM_ITEMIDFROMPOSITION,  (short)index, 0) == id)
     612                    break;
     613                index++;
     614        }
     615        int idItem = OS.WinSendMsg (hMenu, OS.MM_ITEMIDFROMPOSITION,  (short)index, 0);
     616        OS.WinSendMsg (hMenu, OS.MM_QUERYITEM,  OS.MPFROM2SHORT ((short)idItem, (short)OS.TRUE), info);
     617        int length = 128;
     618        PSZ buffer = new PSZ (length);
     619        if (menu != null) {
     620                menu.cascade = this;
     621                info.afStyle |= OS.MIS_SUBMENU;
     622                info.hwndSubMenu = menu.handle;
     623        }
     624       
     625        //Given an id of a menuitem changes it to a MIS_SUBMENU type of item
     626        //Note: You have to delete and reinsert a menu item if you want to change it from
     627       
     628        OS.WinSendMsg (hMenu, OS.MM_QUERYITEMTEXT,  OS.MPFROM2SHORT ((short)idItem, (short)length), buffer);
     629        OS.WinSendMsg (hMenu, OS.MM_DELETEITEM,  OS.MPFROM2SHORT ((short)idItem, (short)OS.FALSE), 0);
     630        int rc = OS.WinSendMsg (hMenu, OS.MM_INSERTITEM,  info, buffer);
     631//        boolean success = OS.WinSendMsg (hMenu, OS.MM_SETITEM,  OS.MPFROM2SHORT ((short)0, (short)OS.TRUE), info);
     632        System.out.println("RC = " + rc);
     633        if(rc == OS.MIT_ERROR || rc == OS.MIT_MEMERROR)
     634            error (SWT.ERROR_CANNOT_SET_MENU);
    709635//      parent.destroyAcceleratorTable ();
    710 //}
     636}
    711637
    712638/**
     
    723649 * </ul>
    724650 */
    725 //public void setSelection (boolean selected) {
    726 //      checkWidget ();
    727 //      if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
    728 //      int hMenu = parent.handle;
    729 //      if (OS.IsWinCE) {
    730 //              int index = parent.indexOf (this);
    731 //              if (index == -1) return;
    732 //              int uCheck = OS.MF_BYPOSITION | (selected ? OS.MF_CHECKED : OS.MF_UNCHECKED);
    733 //              OS.CheckMenuItem (hMenu, index, uCheck);
    734 //      } else {
    735 //              MENUITEMINFO info = new MENUITEMINFO ();
    736 //              info.cbSize = MENUITEMINFO.sizeof;
    737 //              info.fMask = OS.MIIM_STATE;
    738 //              boolean success = OS.GetMenuItemInfo (hMenu, id, false, info);
    739 //              if (!success) error (SWT.ERROR_CANNOT_SET_SELECTION);
    740 //              info.fState &= ~OS.MFS_CHECKED;
    741 //              if (selected) info.fState |= OS.MFS_CHECKED;
    742 //              success = OS.SetMenuItemInfo (hMenu, id, false, info);
    743 //              if (!success) error (SWT.ERROR_CANNOT_SET_SELECTION);
    744 //      }
    745 //      parent.redraw ();
    746 //}
    747 
    748 //public void setText (String string) {
    749 //      checkWidget ();
    750 //      if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
    751 //      if ((style & SWT.SEPARATOR) != 0) return;
    752 //      super.setText (string);
    753 //      boolean fixPPCMenuBar = false;
    754 //      if (OS.IsPPC) {
    755 //              Decorations shell = parent.parent;
    756 //              if (parent == shell.menuBar) {
    757 //                      fixPPCMenuBar = true;
    758 //                      /*
    759 //                      * Bug in WinCE PPC.  Tool items on the menubar don't resize
    760 //                      * correctly when the character '&' is used (even when it
    761 //                      * is a sequence '&&').  The fix is to remove all '&' from
    762 //                      * the string.
    763 //                      */
    764 //                      if (string.indexOf ('&') != -1) {
    765 //                              int length = string.length ();
    766 //                              char[] text = new char [length];
    767 //                              string.getChars( 0, length, text, 0);
    768 //                              int i = 0, j = 0;
    769 //                              for (i=0; i<length; i++) {
    770 //                                      if (text[i] != '&') text [j++] = text [i];
    771 //                              }
    772 //                              if (j < i) string = new String (text, 0, j);
    773 //                      }
    774 //              }
    775 //      }
    776 //      int hMenu = parent.handle;
    777 //      int hHeap = OS.GetProcessHeap ();
    778 //      /* Use the character encoding for the default locale */
    779 //      TCHAR buffer = new TCHAR (0, string, true);
    780 //      int byteCount = buffer.length () * TCHAR.sizeof;
    781 //      int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
    782 //      OS.MoveMemory (pszText, buffer, byteCount);
    783 //      MENUITEMINFO info = new MENUITEMINFO ();
    784 //      info.cbSize = MENUITEMINFO.sizeof;
    785 //      info.fMask = OS.MIIM_TYPE;
    786 //      info.fType = widgetStyle ();
    787 //      info.dwTypeData = pszText;
    788 //      boolean success = OS.SetMenuItemInfo (hMenu, id, false, info);
    789 //      /*
    790 //      * Bug in Windows 2000.  For some reason, when MIIM_TYPE is set
    791 //      * on a menu item that also has MIIM_BITMAP, the MIIM_TYPE clears
    792 //      * the MIIM_BITMAP style.  The fix is to reset both MIIM_BITMAP.
    793 //      * Note, this does not happen on Windows 98.
    794 //      */
    795 //      if (!OS.IsWinCE) {
    796 //              if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) >= (4 << 16 | 10)) {
    797 //                      if (image != null) {
    798 //                              info.fMask = OS.MIIM_BITMAP;
    799 //                              info.hbmpItem = OS.HBMMENU_CALLBACK;
    800 //                              success = OS.SetMenuItemInfo (hMenu, id, false, info);
    801 //                      }
    802 //              }
    803 //      }
    804 //      if (fixPPCMenuBar) {
    805 //              Decorations shell = parent.parent;
    806 //              TBBUTTONINFO info2 = new TBBUTTONINFO ();
    807 //              info2.cbSize = TBBUTTONINFO.sizeof;
    808 //              info2.dwMask = OS.TBIF_TEXT;
    809 //              info2.pszText = pszText;
    810 //              OS.SendMessage (shell.hwndTB, OS.TB_SETBUTTONINFO, id, info2);
    811 //      }
    812 //      if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
    813 //      if (!success) error (SWT.ERROR_CANNOT_SET_TEXT);
    814 //      parent.redraw ();
    815 //}
    816 
    817 //int widgetStyle () {
    818 //      if ((style & SWT.SEPARATOR) != 0) return OS.MFT_SEPARATOR;
     651public void setSelection (boolean selected) {
     652        checkWidget ();
     653        if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
     654        int hMenu = parent.handle;
     655       
     656        int sState = OS.WinSendMsg(hMenu, OS.MM_QUERYITEMATTR, OS.MPFROM2SHORT((short)id, (short)OS.TRUE), OS.MIA_CHECKED);
     657        sState &= ~OS.MIA_CHECKED;
     658        if (selected) sState |= OS.MIA_CHECKED;
     659        int success = OS.WinSendMsg(hMenu, OS.MM_SETITEMATTR, OS.MPFROM2SHORT((short)id, (short)OS.TRUE), OS.MPFROM2SHORT((short)OS.MIA_CHECKED, (short)sState));
     660        if (success == 0) error (SWT.ERROR_CANNOT_SET_SELECTION);
     661
     662        parent.redraw ();
     663}
     664
     665public void setText (String string) {
     666        checkWidget ();
     667        if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
     668        if ((style & SWT.SEPARATOR) != 0) return;
     669        super.setText (string);
     670        int hMenu = parent.handle;
     671        PSZ buffer = new PSZ(string);
     672        int rc = OS.WinSendMsg (hMenu, OS.MM_SETITEMTEXT,  (short)id, buffer);
     673        if (rc != 1)
     674            error (SWT.ERROR_CANNOT_SET_TEXT);
     675        parent.redraw ();
     676}
     677
     678int widgetStyle () {
     679        if ((style & SWT.SEPARATOR) != 0) return OS.MIS_SEPARATOR;
    819680//      if ((style & SWT.RADIO) != 0) return OS.MFT_RADIOCHECK;
    820 //      return OS.MFT_STRING;
    821 //}
    822 
    823 //LRESULT wmCommandChild (int wParam, int lParam) {
    824 //      if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
    825 //              setSelection (!getSelection ());
    826 //      }
    827 //      Event event = new Event ();
    828 //      if (OS.GetKeyState (OS.VK_MENU) < 0) event.stateMask |= SWT.ALT;
    829 //      if (OS.GetKeyState (OS.VK_SHIFT) < 0) event.stateMask |= SWT.SHIFT;
    830 //      if (OS.GetKeyState (OS.VK_CONTROL) < 0) event.stateMask |= SWT.CONTROL;
    831 //      if (OS.GetKeyState (OS.VK_LBUTTON) < 0) event.stateMask |= SWT.BUTTON1;
    832 //      if (OS.GetKeyState (OS.VK_MBUTTON) < 0) event.stateMask |= SWT.BUTTON2;
    833 //      if (OS.GetKeyState (OS.VK_RBUTTON) < 0) event.stateMask |= SWT.BUTTON3;
    834 //      postEvent (SWT.Selection, event);
    835 //      return null;
    836 //}
     681        return OS.MIS_TEXT;
     682}
     683
     684MRESULT wmCommandChild (int mp1, int mp2) {
     685        if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
     686                setSelection (!getSelection ());
     687        }
     688        System.out.println("MenuItem:wmCommandChild");
     689        Event event = new Event ();
     690        if ((OS.WinGetKeyState (OS.HWND_DESKTOP, OS.VK_MENU) & 0x8000) != 0) event.stateMask |= SWT.ALT;
     691        if ((OS.WinGetKeyState (OS.HWND_DESKTOP, OS.VK_SHIFT) & 0x8000) != 0) event.stateMask |= SWT.SHIFT;
     692        if ((OS.WinGetKeyState (OS.HWND_DESKTOP, OS.VK_CTRL) & 0x8000) != 0) event.stateMask |= SWT.CONTROL;
     693        if ((OS.WinGetKeyState (OS.HWND_DESKTOP, OS.VK_BUTTON1) & 0x8000) != 0) event.stateMask |= SWT.BUTTON1;
     694        if ((OS.WinGetKeyState (OS.HWND_DESKTOP, OS.VK_BUTTON2) & 0x8000) != 0) event.stateMask |= SWT.BUTTON2;
     695        if ((OS.WinGetKeyState (OS.HWND_DESKTOP, OS.VK_BUTTON3) & 0x8000) != 0) event.stateMask |= SWT.BUTTON3;
     696        postEvent (SWT.Selection, event);
     697        return null;
     698}
    837699
    838700//LRESULT wmDrawChild (int wParam, int lParam) {
Note: See TracChangeset for help on using the changeset viewer.