- Timestamp:
- Jan 9, 2008, 2:25:30 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plugins/org.eclipse.swt/Eclipse SWT/pm/org/eclipse/swt/widgets/Menu.java
r51 r58 258 258 259 259 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; 287 271 if (!success) { 288 272 parent.remove (item); 289 273 error (SWT.ERROR_ITEM_NOT_ADDED); 290 274 } 291 redraw ();275 // redraw (); 292 276 } 293 277 … … 315 299 //} 316 300 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 // } 301 void 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 } 345 307 // redraw (); 346 //} 347 // 348 //void destroyWidget () { 349 // int hMenu = handle; 350 // releaseHandle (); 351 // if (hMenu != 0) { 352 // OS.DestroyMenu (hMenu); 353 // } 354 //} 308 } 309 310 void destroyWidget () { 311 int hMenu = handle; 312 releaseHandle (); 313 } 355 314 356 315 /** … … 366 325 * </ul> 367 326 */ 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 ();327 public 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); 374 333 // info.cbSize = MENUITEMINFO.sizeof; 375 334 // info.fMask = OS.MIIM_ID; … … 377 336 // return parent.findMenuItem (info.wID); 378 337 // } 379 //return null;380 //}338 return null; 339 } 381 340 382 341 public Display getDisplay () { … … 485 444 // return result; 486 445 //} 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 447 int GetMenuItemCount (int handle) { 448 checkWidget (); 449 return OS.WinSendMsg(handle, OS.MM_QUERYITEMCOUNT, 0, 0); 450 } 451 500 452 //String getNameText () { 501 453 // String result = "";
Note:
See TracChangeset
for help on using the changeset viewer.