Ignore:
Timestamp:
Mar 13, 2008, 11:42:52 PM (17 years ago)
Author:
lpino
Message:
  • (Menu.java) Lots of new methods implemented
File:
1 edited

Legend:

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

    r58 r66  
    330330        if (id == 0) return null;
    331331        MENUITEM info = new MENUITEM();
    332         int rc = OS.WinSendMsg (handle, OS.MM_QUERYITEM,  OS.MPFROM2SHORT ((short)id, (short)OS.TRUE), info);
     332        if(OS.WinSendMsg (handle, OS.MM_QUERYITEM,  OS.MPFROM2SHORT ((short)id, (short)OS.TRUE), info))
     333            return parent.findMenuItem (info.id);
     334       
    333335//      info.cbSize = MENUITEMINFO.sizeof;
    334336//      info.fMask = OS.MIIM_ID;
     
    380382 * </ul>
    381383 */
    382 //public MenuItem getItem (int index) {
    383 //      checkWidget ();
     384public MenuItem getItem (int index) {
     385        checkWidget ();
    384386//      MENUITEMINFO info = new MENUITEMINFO ();
    385387//      info.cbSize = MENUITEMINFO.sizeof;
    386388//      info.fMask = OS.MIIM_DATA;
    387 //      if (!OS.GetMenuItemInfo (handle, index, true, info)) {
    388 //              error (SWT.ERROR_INVALID_RANGE);
    389 //      }
    390 //      return parent.findMenuItem (info.dwItemData);
    391 //}
     389        MENUITEM info = new MENUITEM();
     390        int id = OS.WinSendMsg (handle, OS.MM_ITEMIDFROMPOSITION,  (short)index, 0);
     391        if(id == OS.MIT_ERROR){
     392            error (SWT.ERROR_INVALID_RANGE);
     393        }
     394        OS.WinSendMsg (handle, OS.MM_QUERYITEM,  OS.MPFROM2SHORT ((short)id, (short)OS.TRUE), info);   
     395        return parent.findMenuItem (info.id);
     396}
    392397
    393398/**
     
    401406 * </ul>
    402407 */
    403 //public int getItemCount () {
    404 //      checkWidget ();
    405 ////    return OS.GetMenuItemCount (handle);
    406 //      return GetMenuItemCount (handle);
    407 //}
     408public int getItemCount () {
     409        checkWidget ();
     410        return OS.WinSendMsg (handle, OS.MM_QUERYITEMCOUNT,  0, 0);
     411}
    408412
    409413/**
     
    423427 * </ul>
    424428 */
    425 //public MenuItem [] getItems () {
    426 //      checkWidget ();
    427 //      int index = 0;
    428 //      int length = OS.IsWinCE ? 4 : OS.GetMenuItemCount (handle);
    429 //      MenuItem [] items = new MenuItem [length];
    430 //      MENUITEMINFO info = new MENUITEMINFO ();
     429public MenuItem [] getItems () {
     430        checkWidget ();
     431        int index = 0;
     432        int length = OS.WinSendMsg (handle, OS.MM_QUERYITEMCOUNT,  0, 0);
     433        MenuItem [] items = new MenuItem [length];
     434        MENUITEM info = new MENUITEM();
    431435//      info.cbSize = MENUITEMINFO.sizeof;
    432436//      info.fMask = OS.MIIM_DATA;
    433 //      while (OS.GetMenuItemInfo (handle, index, true, info)) {
    434 //              if (index == items.length) {
    435 //                      MenuItem [] newItems = new MenuItem [index + 4];
    436 //                      System.arraycopy (items, 0, newItems, 0, index);
    437 //                      items = newItems;
    438 //              }
    439 //              items [index++] = parent.findMenuItem (info.dwItemData);
    440 //      }
    441 //      if (index == items.length) return items;
    442 //      MenuItem [] result = new MenuItem [index];
    443 //      System.arraycopy (items, 0, result, 0, index);
    444 //      return result;
    445 //}
     437        int idItem = 0;
     438//      Revisa si esto es redundante o  no
     439        while ((idItem=OS.WinSendMsg (handle, OS.MM_ITEMIDFROMPOSITION,  index, 0)) != OS.MIT_ERROR) {
     440                if (index == items.length) {
     441                        MenuItem [] newItems = new MenuItem [index + 4];
     442                        System.arraycopy (items, 0, newItems, 0, index);
     443                        items = newItems;
     444                }
     445                OS.WinSendMsg (handle, OS.MM_QUERYITEM, OS.MPFROM2SHORT ((short)idItem, (short)OS.TRUE), info);
     446                items [index++] = parent.findMenuItem (info.id);
     447        }
     448        if (index == items.length) return items;
     449        MenuItem [] result = new MenuItem [index];
     450        System.arraycopy (items, 0, result, 0, index);
     451        return result;
     452}
    446453
    447454int GetMenuItemCount (int handle) {
     
    450457}
    451458
    452 //String getNameText () {
    453 //      String result = "";
    454 //      MenuItem [] items = getItems ();
    455 //      int length = items.length;
    456 //      if (length > 0) {
    457 //              for (int i=0; i<length-1; i++) {
    458 //                      result = result + items [i].getNameText() + ", ";
    459 //              }
    460 //              result = result + items [length-1].getNameText ();
    461 //      }
    462 //      return result;
    463 //}
     459String getNameText () {
     460        String result = "";
     461        MenuItem [] items = getItems ();
     462        int length = items.length;
     463        if (length > 0) {
     464                for (int i=0; i<length-1; i++) {
     465                        result = result + items [i].getNameText() + ", ";
     466                }
     467                result = result + items [length-1].getNameText ();
     468        }
     469        return result;
     470}
    464471
    465472/**
     
    550557 * </ul>
    551558 */
    552 //public boolean getVisible () {
    553 //      checkWidget ();
    554 //      if ((style & SWT.BAR) != 0) {
    555 //              return this == parent.menuShell ().menuBar;
    556 //      }
    557 //      return this == getShell ().activeMenu;
    558 //}
     559public boolean getVisible () {
     560        checkWidget ();
     561        if ((style & SWT.BAR) != 0) {
     562                return this == parent.menuShell ().menuBar;
     563        }
     564        return this == getShell ().activeMenu;
     565}
    559566
    560567/**
     
    575582 * </ul>
    576583 */
    577 //public int indexOf (MenuItem item) {
    578 //      checkWidget ();
    579 //      if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
    580 //      int index = 0;
     584public int indexOf (MenuItem item) {
     585        checkWidget ();
     586        if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
     587        int index = 0;
     588        MENUITEM info = new MENUITEM();
     589        int idItem = 0;
    581590//      MENUITEMINFO info = new MENUITEMINFO ();
    582591//      info.cbSize = MENUITEMINFO.sizeof;
    583592//      info.fMask = OS.MIIM_DATA;
    584 //      while (OS.GetMenuItemInfo (handle, index, true, info)) {
    585 //              if (info.dwItemData == item.id) return index;
    586 //              index++;
    587 //      }
    588 //      return -1;
    589 //}
     593        while ((idItem=OS.WinSendMsg (handle, OS.MM_ITEMIDFROMPOSITION,  index, 0)) != OS.MIT_ERROR) {
     594            //@@TODO(lpino) Check if the next call is necesary or we could use the idItem directly
     595                OS.WinSendMsg (handle, OS.MM_QUERYITEM, OS.MPFROM2SHORT ((short)idItem, (short)OS.TRUE), info);
     596                if (info.id == item.id) return index;
     597                index++;
     598        }
     599        return -1;
     600}
    590601
    591602/**
     
    625636 * @see #getVisible
    626637 */
    627 //public boolean isVisible () {
    628 //      checkWidget ();
    629 //      return getVisible ();
    630 //}
     638public boolean isVisible () {
     639        checkWidget ();
     640        return getVisible ();
     641}
    631642
    632643//void redraw () {
     
    682693}
    683694
    684 //void releaseWidget () {
    685 //      MenuItem [] items = getItems ();
    686 //      for (int i=0; i<items.length; i++) {
    687 //              MenuItem item = items [i];
    688 //              if (!item.isDisposed ()) item.releaseWidget ();
    689 //      }
    690 //      super.releaseWidget ();
    691 //      if (parent != null) parent.remove (this);
    692 //      parent = null;
    693 //      cascade = null;
    694 //}
     695void releaseWidget () {
     696        MenuItem [] items = getItems ();
     697        for (int i=0; i<items.length; i++) {
     698                MenuItem item = items [i];
     699                if (!item.isDisposed ()) item.releaseWidget ();
     700        }
     701        super.releaseWidget ();
     702        if (parent != null) parent.remove (this);
     703        parent = null;
     704        cascade = null;
     705}
    695706
    696707/**
     
    757768 * </ul>
    758769 */
    759 //public void setDefaultItem (MenuItem item) {
    760 //      checkWidget ();
    761 //      int command = -1;
    762 //      if (item != null) {
    763 //              if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
    764 //              command = item.id;
    765 //      }
    766 //      if (OS.IsWinCE) return;
    767 //      OS.SetMenuDefaultItem (handle, command, OS.MF_BYCOMMAND);
     770public void setDefaultItem (MenuItem item) {
     771        checkWidget ();
     772        int command = -1;
     773        if (item != null) {
     774                if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
     775                command = item.id;
     776        }
     777        OS.WinSendMsg (handle, OS.MM_SETDEFAULTITEMID,  command, 0);
    768778//      redraw ();
    769 //}
     779}
    770780
    771781/**
Note: See TracChangeset for help on using the changeset viewer.