Changeset 58 for trunk/src


Ignore:
Timestamp:
Jan 9, 2008, 2:25:30 PM (18 years ago)
Author:
lpino
Message:
  • (Menu.java) Added destroyItem, destroyWidget, getDefaultItem and GetMenuItemCount methods. Also modified createItem and getDisplay methods
File:
1 edited

Legend:

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

    r51 r58  
    258258
    259259       
    260         MENUITEM item = new MENUITEM();;
    261         item .iPosition = position;
    262         item . afStyle = style;
    263         item . afAttribute = attributes;
    264         item . id = id;
    265         item . hwndSubMenu = submenu;
    266         item . hItem = 0;
    267 
    268         return (SHORT1FROMMR (WinSendMsg (menu, MM_INSERTITEM,  (MPFROMP (&item)), (MPFROMP (text)))));
    269 
    270                 /*
    271                 * Bug in Windows.  For some reason, when InsertMenuItem ()
    272                 * is used to insert an item without text, it is not possible
    273                 * to use SetMenuItemInfo () to set the text at a later time.
    274                 * The fix is to insert the item with an empty string.
    275                 */
    276                 int hHeap = OS.GetProcessHeap ();
    277                 int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof);
    278                 MENUITEMINFO info = new MENUITEMINFO ();
    279                 info.cbSize = MENUITEMINFO.sizeof;
    280                 info.fMask = OS.MIIM_ID | OS.MIIM_TYPE | OS.MIIM_DATA;
    281                 info.wID = info.dwItemData = item.id;
    282                 info.fType = item.widgetStyle ();
    283                 info.dwTypeData = pszText;
    284                 success = OS.InsertMenuItem (handle, index, true, info);
    285                 if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
    286 
     260        MENUITEM info = new MENUITEM();
     261        info.iPosition = OS.MIT_END;
     262        info.afStyle = OS.MIS_TEXT;
     263        info.afAttribute = 0;
     264        info.id = (short)item.id;
     265        info.hwndSubMenu = OS.NULLHANDLE;
     266        info.hItem = 0;
     267       
     268        int rc = OS.WinSendMsg (handle, OS.MM_INSERTITEM,  info, new PSZ(""));
     269        if(rc != OS.MIT_MEMERROR && rc != OS.MIT_ERROR)
     270            success = true;
    287271        if (!success) {
    288272                parent.remove (item);
    289273                error (SWT.ERROR_ITEM_NOT_ADDED);
    290274        }
    291         redraw ();
     275//      redraw ();
    292276}
    293277
     
    315299//}
    316300
    317 //void destroyItem (MenuItem item) {
    318 //      if (OS.IsWinCE) {
    319 //              int index = 0;
    320 //              MENUITEMINFO info = new MENUITEMINFO ();
    321 //              info.cbSize = MENUITEMINFO.sizeof;
    322 //              info.fMask = OS.MIIM_DATA;
    323 //              while (OS.GetMenuItemInfo (handle, index, true, info)) {
    324 //                      if (info.dwItemData == item.id) break;
    325 //                      index++;
    326 //              }
    327 //              if (info.dwItemData != item.id) {
    328 //                      error (SWT.ERROR_ITEM_NOT_REMOVED);
    329 //              }       
    330 //              if (!OS.RemoveMenu (handle, index, OS.MF_BYPOSITION)) {
    331 //                      error (SWT.ERROR_ITEM_NOT_REMOVED);
    332 //              }
    333 //              /*
    334 //              * if it is a top level menu item, remove the corresponding
    335 //              * tool item.
    336 //              */
    337 //              if (parent.menuBar == this) {
    338 //                      OS.SendMessage (parent.hwndTB, OS.TB_DELETEBUTTON, index, 0);
    339 //              }
    340 //      } else {
    341 //              if (!OS.RemoveMenu (handle, item.id, OS.MF_BYCOMMAND)) {
    342 //                      error (SWT.ERROR_ITEM_NOT_REMOVED);
    343 //              }
    344 //      }
     301void destroyItem (MenuItem item) {
     302    int count = GetMenuItemCount (handle);
     303    int rc = OS.WinSendMsg (handle, OS.MM_DELETEITEM,  OS.MPFROM2SHORT ((short)item.id, (short)OS.TRUE), 0);
     304                if (rc == count) {
     305                        error (SWT.ERROR_ITEM_NOT_REMOVED);
     306                }
    345307//      redraw ();
    346 //}
    347 //
    348 //void destroyWidget () {
    349 //      int hMenu = handle;
    350 //      releaseHandle ();
    351 //      if (hMenu != 0) {
    352 //              OS.DestroyMenu (hMenu);
    353 //      }
    354 //}
     308}
     309
     310void destroyWidget () {
     311        int hMenu = handle;
     312        releaseHandle ();
     313}
    355314
    356315/**
     
    366325 * </ul>
    367326 */
    368 //public MenuItem getDefaultItem () {
    369 //      checkWidget ();
    370 //      if (OS.IsWinCE) return null;
    371 //      int id = OS.GetMenuDefaultItem (handle, OS.MF_BYCOMMAND, OS.GMDI_USEDISABLED);
    372 //      if (id == -1) return null;
    373 //      MENUITEMINFO info = new MENUITEMINFO ();
     327public MenuItem getDefaultItem () {
     328        checkWidget ();
     329        int id = OS.WinSendMsg (handle, OS.MM_QUERYDEFAULTITEMID,  0, 0);
     330        if (id == 0) return null;
     331        MENUITEM info = new MENUITEM();
     332        int rc = OS.WinSendMsg (handle, OS.MM_QUERYITEM,  OS.MPFROM2SHORT ((short)id, (short)OS.TRUE), info);
    374333//      info.cbSize = MENUITEMINFO.sizeof;
    375334//      info.fMask = OS.MIIM_ID;
     
    377336//              return parent.findMenuItem (info.wID);
    378337//      }
    379 //      return null;
    380 //}
     338        return null;
     339}
    381340
    382341public Display getDisplay () {
     
    485444//      return result;
    486445//}
    487 //
    488 //int GetMenuItemCount (int handle) {
    489 //      checkWidget ();
    490 //      if (OS.IsWinCE) {
    491 //              int count = 0;
    492 //              MENUITEMINFO info = new MENUITEMINFO ();
    493 //              info.cbSize = MENUITEMINFO.sizeof;
    494 //              while (OS.GetMenuItemInfo (handle, count, true, info)) count++;
    495 //              return count;
    496 //      }
    497 //      return OS.GetMenuItemCount (handle);
    498 //}
    499 //
     446
     447int GetMenuItemCount (int handle) {
     448        checkWidget ();
     449        return OS.WinSendMsg(handle, OS.MM_QUERYITEMCOUNT, 0, 0);
     450}
     451
    500452//String getNameText () {
    501453//      String result = "";
Note: See TracChangeset for help on using the changeset viewer.