Changeset 66 for trunk/src/plugins/org.eclipse.swt/Eclipse SWT
- Timestamp:
- Mar 13, 2008, 11:42:52 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plugins/org.eclipse.swt/Eclipse SWT/pm/org/eclipse/swt/widgets/Menu.java
r58 r66 330 330 if (id == 0) return null; 331 331 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 333 335 // info.cbSize = MENUITEMINFO.sizeof; 334 336 // info.fMask = OS.MIIM_ID; … … 380 382 * </ul> 381 383 */ 382 //public MenuItem getItem (int index) {383 //checkWidget ();384 public MenuItem getItem (int index) { 385 checkWidget (); 384 386 // MENUITEMINFO info = new MENUITEMINFO (); 385 387 // info.cbSize = MENUITEMINFO.sizeof; 386 388 // 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 } 392 397 393 398 /** … … 401 406 * </ul> 402 407 */ 403 //public int getItemCount () { 404 // checkWidget (); 405 //// return OS.GetMenuItemCount (handle); 406 // return GetMenuItemCount (handle); 407 //} 408 public int getItemCount () { 409 checkWidget (); 410 return OS.WinSendMsg (handle, OS.MM_QUERYITEMCOUNT, 0, 0); 411 } 408 412 409 413 /** … … 423 427 * </ul> 424 428 */ 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();429 public 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(); 431 435 // info.cbSize = MENUITEMINFO.sizeof; 432 436 // 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 } 446 453 447 454 int GetMenuItemCount (int handle) { … … 450 457 } 451 458 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 //}459 String 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 } 464 471 465 472 /** … … 550 557 * </ul> 551 558 */ 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 //}559 public boolean getVisible () { 560 checkWidget (); 561 if ((style & SWT.BAR) != 0) { 562 return this == parent.menuShell ().menuBar; 563 } 564 return this == getShell ().activeMenu; 565 } 559 566 560 567 /** … … 575 582 * </ul> 576 583 */ 577 //public int indexOf (MenuItem item) { 578 // checkWidget (); 579 // if (item == null) error (SWT.ERROR_NULL_ARGUMENT); 580 // int index = 0; 584 public 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; 581 590 // MENUITEMINFO info = new MENUITEMINFO (); 582 591 // info.cbSize = MENUITEMINFO.sizeof; 583 592 // 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 } 590 601 591 602 /** … … 625 636 * @see #getVisible 626 637 */ 627 //public boolean isVisible () {628 //checkWidget ();629 //return getVisible ();630 //}638 public boolean isVisible () { 639 checkWidget (); 640 return getVisible (); 641 } 631 642 632 643 //void redraw () { … … 682 693 } 683 694 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 //}695 void 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 } 695 706 696 707 /** … … 757 768 * </ul> 758 769 */ 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); 770 public 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); 768 778 // redraw (); 769 //}779 } 770 780 771 781 /**
Note:
See TracChangeset
for help on using the changeset viewer.