Changeset 76 for trunk/src


Ignore:
Timestamp:
May 23, 2008, 6:30:07 PM (17 years ago)
Author:
lpino
Message:
  • (Menu.java) Lots of fixes and new code
File:
1 edited

Legend:

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

    r66 r76  
    221221void createHandle () {
    222222        if ((style & SWT.BAR) != 0) {
    223             handle = OS.WinCreateWindow (OS.HWND_DESKTOP,       /* parent window */
     223            System.out.println("Menu:createHandle:  Menu Bar");
     224            handle = OS.WinCreateWindow (parent.frameHandle,    /* parent window */
    224225                                                        PSZ.getAtom (OS.WC_MENU),       /* class name */
    225                                                         new PSZ(""),    /* window text */
     226                                                        null,   /* window text */
    226227                                                        OS.MS_ACTIONBAR,        /* window style */
    227228                                                        0, 0, 0, 0, /* size and position */
    228                                                         OS.HWND_DESKTOP,        /* owner window */
     229                                                        parent.frameHandle,     /* owner window */
    229230                                                        OS.HWND_TOP, /* sibling window */
    230231                                                        OS.FID_MENU,    /* ID */
     
    232233                                                        0               /* presentation parameters */
    233234                                                        );
    234         } else {
     235//System.out.println (
     236//    "Menu.createHandle(): FID_MENU window has been created:\n" +
     237//    "    hwnd = " + Integer.toHexString (handle) + "\n" +
     238//    "    hwnd.parent = hwnd.owner = " + Integer.toHexString (handle) + "\n" +
     239//    "    class = WC_MENU\n" +
     240//    "    style = MS_ACTIONBAR"
     241//);
     242        } else  if ((style & SWT.POP_UP) != 0) {
    235243            short flOptions = OS.PU_MOUSEBUTTON1DOWN | OS.PU_KEYBOARD | OS.PU_MOUSEBUTTON1;
    236244            handle = OS.WinCreateWindow (OS.HWND_DESKTOP,       /* parent window */
    237245                                                        PSZ.getAtom (OS.WC_MENU),       /* class name */
    238                                                         new PSZ(""),    /* window text */
     246                                                        null,   /* window text */
    239247                                                        0,      /* window style */
    240248                                                        0, 0, 0, 0, /* size and position */
     
    246254                                                        );
    247255          boolean rc = OS.WinPopupMenu(OS.HWND_DESKTOP, OS.HWND_DESKTOP, handle, 0, 0, 0, flOptions);
     256System.out.println (
     257    "Menu.createHandle(): FID_MENU window has been created:\n" +
     258    "    hwnd = " + Integer.toHexString (handle) + "\n" +
     259    "    hwnd.parent = hwnd.owner = " + Integer.toHexString (handle) + "\n" +
     260    "    class = WC_MENU\n" +
     261    "    style = MS_ACTIONBAR"
     262);
    248263             
     264        } else if ((style & SWT.DROP_DOWN) != 0) {
     265            System.out.println("Menu:createHandle:  Menu DropDown");
     266            handle = OS.WinCreateWindow (OS.HWND_DESKTOP,       /* parent window */
     267                                                        PSZ.getAtom (OS.WC_MENU),       /* class name */
     268                                                        null,   /* window text */
     269                                                        0,      /* window style */
     270                                                        0, 0, 0, 0, /* size and position */
     271                                                        OS.HWND_DESKTOP,        /* owner window */
     272                                                        OS.HWND_TOP, /* sibling window */
     273                                                        OS.FID_MENU,    /* ID */
     274                                                        OS.NULLHANDLE,  /* control data */
     275                                                        0               /* presentation parameters */
     276                                                        );
     277//System.out.println (
     278//    "Menu.createHandle(): A menu has been created:\n" +
     279//    "    hwnd = " + Integer.toHexString (handle) + "\n" +
     280//    "    hwnd.parent = hwnd.owner = " + Integer.toHexString (handle) + "\n" +
     281//    "    class = WC_MENU\n" +
     282//    "    style = 0"
     283//);
    249284        }
    250285        if (handle == 0) error (SWT.ERROR_NO_HANDLES);
     
    257292        boolean success = false;
    258293
    259        
    260294        MENUITEM info = new MENUITEM();
    261295        info.iPosition = OS.MIT_END;
     
    263297        info.afAttribute = 0;
    264298        info.id = (short)item.id;
     299        System.out.println("Menu:createItem ID = " + info.id);
    265300        info.hwndSubMenu = OS.NULLHANDLE;
    266301        info.hItem = 0;
    267        
    268         int rc = OS.WinSendMsg (handle, OS.MM_INSERTITEM,  info, new PSZ(""));
     302        int rc = OS.WinSendMsg (handle, OS.MM_INSERTITEM,  info, new PSZ(" "));
    269303        if(rc != OS.MIT_MEMERROR && rc != OS.MIT_ERROR)
    270304            success = true;
     
    273307                error (SWT.ERROR_ITEM_NOT_ADDED);
    274308        }
    275 //      redraw ();
     309        redraw ();
    276310}
    277311
     
    295329}
    296330
    297 //void destroyAcceleratorTable () {
    298 //      parent.destroyAcceleratorTable ();
    299 //}
     331void destroyAcceleratorTable () {
     332        parent.destroyAcceleratorTable ();
     333}
    300334
    301335void destroyItem (MenuItem item) {
    302336    int count = GetMenuItemCount (handle);
     337    System.out.println("ITEMS antes de destroy = " + count);
    303338    int rc = OS.WinSendMsg (handle, OS.MM_DELETEITEM,  OS.MPFROM2SHORT ((short)item.id, (short)OS.TRUE), 0);
    304339                if (rc == count) {
    305340                        error (SWT.ERROR_ITEM_NOT_REMOVED);
    306341                }
    307 //      redraw ();
     342        redraw ();
    308343}
    309344
     
    333368            return parent.findMenuItem (info.id);
    334369       
    335 //      info.cbSize = MENUITEMINFO.sizeof;
    336 //      info.fMask = OS.MIIM_ID;
    337 //      if (OS.GetMenuItemInfo (handle, id, false, info)) {
    338 //              return parent.findMenuItem (info.wID);
    339 //      }
    340370        return null;
    341371}
     
    384414public MenuItem getItem (int index) {
    385415        checkWidget ();
    386 //      MENUITEMINFO info = new MENUITEMINFO ();
    387 //      info.cbSize = MENUITEMINFO.sizeof;
    388 //      info.fMask = OS.MIIM_DATA;
    389416        MENUITEM info = new MENUITEM();
    390417        int id = OS.WinSendMsg (handle, OS.MM_ITEMIDFROMPOSITION,  (short)index, 0);
     
    433460        MenuItem [] items = new MenuItem [length];
    434461        MENUITEM info = new MENUITEM();
    435 //      info.cbSize = MENUITEMINFO.sizeof;
    436 //      info.fMask = OS.MIIM_DATA;
    437462        int idItem = 0;
    438463//      Revisa si esto es redundante o  no
     
    588613        MENUITEM info = new MENUITEM();
    589614        int idItem = 0;
    590 //      MENUITEMINFO info = new MENUITEMINFO ();
    591 //      info.cbSize = MENUITEMINFO.sizeof;
    592 //      info.fMask = OS.MIIM_DATA;
    593615        while ((idItem=OS.WinSendMsg (handle, OS.MM_ITEMIDFROMPOSITION,  index, 0)) != OS.MIT_ERROR) {
    594616            //@@TODO(lpino) Check if the next call is necesary or we could use the idItem directly
     
    641663}
    642664
    643 //void redraw () {
    644 //      if (OS.IsPPC) return;
    645 //      if (OS.IsHPC) {
    646 //              /*
    647 //              * Each time a menu has been modified, we need
    648 //              * to redraw the command bar.
    649 //              */
    650 //              OS.CommandBar_DrawMenuBar (parent.hwndCB, 0);
    651 //              return;
    652 //      }
    653 //      if ((style & SWT.BAR) != 0) {
     665void redraw () {
     666        if ((style & SWT.BAR) != 0) {
     667//            OS.WinSendMsg (frameHandle, OS.WM_UPDATEFRAME, OS.FCF_MENU, 0);
    654668//              OS.DrawMenuBar (parent.handle);
    655 //              return;
    656 //      }
    657 //      if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) {
    658 //              return;
    659 //      }
    660 //      boolean hasCheck = false, hasImage = false;
     669                return;
     670        }
     671
     672//        boolean hasCheck = false, hasImage = false;
    661673//      MenuItem [] items = getItems ();
    662674//      for (int i=0; i<items.length; i++) {
     
    679691//      }
    680692//      OS.SetMenuInfo (handle, lpcmi);
    681 //}
    682 
    683 //void releaseChild () {
    684 //      super.releaseChild ();
    685 //      if (cascade != null) cascade.setMenu (null);
    686 //      if ((style & SWT.BAR) != 0 && this == parent.menuBar) {
    687 //              parent.setMenuBar (null);
    688 //      }
    689 //}
     693}
     694
     695void releaseChild () {
     696        super.releaseChild ();
     697        if (cascade != null) cascade.setMenu (null);
     698        if ((style & SWT.BAR) != 0 && this == parent.menuBar) {
     699                parent.setMenuBar (null);
     700        }
     701}
    690702
    691703void releaseHandle () {
     
    776788        }
    777789        OS.WinSendMsg (handle, OS.MM_SETDEFAULTITEMID,  command, 0);
    778 //      redraw ();
     790        redraw ();
    779791}
    780792
     
    838850 * </ul>
    839851 */
    840 //public void setVisible (boolean visible) {
    841 //      checkWidget ();
    842 //      if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
    843 //      int hwndParent = parent.handle;
     852public void setVisible (boolean visible) {
     853        checkWidget ();
     854        if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
     855        int hwndParent = parent.handle;
    844856//      if (!visible) {
    845857//              OS.SendMessage (hwndParent, OS.WM_CANCELMODE, 0, 0);
     
    853865//              nY = (short) (pos >> 16);
    854866//      }
    855 //      /*
    856 //      * Feature in Windows.  It is legal use TrackPopupMenu ()
    857 //      * to display an empty menu as long as menu items are added
    858 //      * inside of WM_INITPOPUPMENU.  If no items are added, then
    859 //      * TrackPopupMenu () fails and does not send an indication
    860 //      * that the menu has been closed.  This is not strictly a
    861 //      * bug but leads to unwanted behavior when application code
    862 //      * assumes that every WM_INITPOPUPMENU will eventually result
    863 //      * in a WM_MENUSELECT, wParam=0xFFFF0000, lParam=0 to indicate
    864 //      * that the menu has been closed.  The fix is to detect the
    865 //      * case when TrackPopupMenu fails and the number of items in
    866 //      * the menu is zero and issue a fake WM_MENUSELECT.
    867 //      */
     867        /*
     868        * Feature in Windows.  It is legal use TrackPopupMenu ()
     869        * to display an empty menu as long as menu items are added
     870        * inside of WM_INITPOPUPMENU.  If no items are added, then
     871        * TrackPopupMenu () fails and does not send an indication
     872        * that the menu has been closed.  This is not strictly a
     873        * bug but leads to unwanted behavior when application code
     874        * assumes that every WM_INITPOPUPMENU will eventually result
     875        * in a WM_MENUSELECT, wParam=0xFFFF0000, lParam=0 to indicate
     876        * that the menu has been closed.  The fix is to detect the
     877        * case when TrackPopupMenu fails and the number of items in
     878        * the menu is zero and issue a fake WM_MENUSELECT.
     879        */
    868880//      boolean success = OS.TrackPopupMenu (handle, flags, nX, nY, 0, hwndParent, null);
    869881//      if (!success && GetMenuItemCount (handle) == 0) {
    870882//              OS.SendMessage (hwndParent, OS.WM_MENUSELECT, 0xFFFF0000, 0);
    871883//      }
    872 //}
    873 
    874 }
     884}
     885
     886}
Note: See TracChangeset for help on using the changeset viewer.