Changeset 51 for trunk/src


Ignore:
Timestamp:
Dec 26, 2007, 4:51:23 PM (18 years ago)
Author:
lpino
Message:

(Menu.java) - Inital implementation of createHandle, createWidget, createItem, defaultBackground and defaultForeground

File:
1 edited

Legend:

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

    r42 r51  
    22/*
    33 * OS/2 version.
    4  * Copyright (c) 2002, 2004 EclipseOS2 Team.
     4 * Copyright (c) 2002, 2007 EclipseOS2 Team.
    55 */
    66
     
    9696        super (parent, checkStyle (style));
    9797        this.parent = parent;
    98 //      createWidget ();
     98        createWidget ();
    9999}
    100100
     
    219219}
    220220
    221 //void createHandle () {
    222 //      if ((style & SWT.BAR) != 0) {
    223 //              /*
    224 //              * Note in WinCE PPC.  CreateMenu cannot insert items of type
    225 //              * separator.  The workaround is to always use CreatePopupMenu.
    226 //              */
    227 //              handle = OS.IsPPC ? OS.CreatePopupMenu () : OS.CreateMenu();
    228 //      } else {
    229 //              handle = OS.CreatePopupMenu ();
    230 //      }
    231 //      if (handle == 0) error (SWT.ERROR_NO_HANDLES);
    232 //}
    233 //
    234 //void createItem (MenuItem item, int index) {
    235 //      int count = GetMenuItemCount (handle);
    236 //      if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
    237 //      parent.add (item);
    238 //      boolean success = false;
    239 //      if (OS.IsWinCE) {
    240 //              int uFlags = OS.MF_BYPOSITION;
    241 //              TCHAR lpNewItem = null;
    242 //              if ((item.style & SWT.SEPARATOR) != 0) {
    243 //                      uFlags |= OS.MF_SEPARATOR;
    244 //              } else {
    245 //                      lpNewItem = new TCHAR (0, "", true);
    246 //              }
    247 //              success = OS.InsertMenu (handle, index, uFlags, item.id, lpNewItem);
    248 //              if (success) {
    249 //                      MENUITEMINFO info = new MENUITEMINFO ();
    250 //                      info.cbSize = MENUITEMINFO.sizeof;
    251 //                      info.fMask = OS.MIIM_DATA;
    252 //                      info.dwItemData = item.id;
    253 //                      success = OS.SetMenuItemInfo (handle, index, true, info);
    254 //                     
    255 //                      if (OS.IsPPC) {
    256 //                              /* if it is a top level menu item, display it on the toolbar */
    257 //                              if (item.parent == parent.menuBar) {
    258 //                                      TBBUTTON lpButton = new TBBUTTON ();
    259 //                                      lpButton.idCommand = item.id;
    260 //                                      lpButton.fsStyle = (byte) (OS.TBSTYLE_DROPDOWN | OS.TBSTYLE_AUTOSIZE | 0x80);
    261 //                                      lpButton.fsState = (byte) OS.TBSTATE_ENABLED;
    262 //                                      lpButton.iBitmap = OS.I_IMAGENONE;
    263 //                                      if ((item.style & SWT.SEPARATOR) != 0) {
    264 //                                              lpButton.fsStyle = (byte) OS.BTNS_SEP;
    265 //                                      }
    266 //                                      success = OS.SendMessage (parent.hwndTB, OS.TB_INSERTBUTTON, index, lpButton) != 0;
    267 //                              }
    268 //                      }
    269 //              }
    270 //      } else {
    271 //              /*
    272 //              * Bug in Windows.  For some reason, when InsertMenuItem ()
    273 //              * is used to insert an item without text, it is not possible
    274 //              * to use SetMenuItemInfo () to set the text at a later time.
    275 //              * The fix is to insert the item with an empty string.
    276 //              */
    277 //              int hHeap = OS.GetProcessHeap ();
    278 //              int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof);
    279 //              MENUITEMINFO info = new MENUITEMINFO ();
    280 //              info.cbSize = MENUITEMINFO.sizeof;
    281 //              info.fMask = OS.MIIM_ID | OS.MIIM_TYPE | OS.MIIM_DATA;
    282 //              info.wID = info.dwItemData = item.id;
    283 //              info.fType = item.widgetStyle ();
    284 //              info.dwTypeData = pszText;
    285 //              success = OS.InsertMenuItem (handle, index, true, info);
    286 //              if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
    287 //      }
    288 //      if (!success) {
    289 //              parent.remove (item);
    290 //              error (SWT.ERROR_ITEM_NOT_ADDED);
    291 //      }
    292 //      redraw ();
    293 //}
    294 
    295 //void createWidget () {
    296 //      createHandle ();
    297 //      parent.add (this);
    298 //}
     221void createHandle () {
     222        if ((style & SWT.BAR) != 0) {
     223            handle = OS.WinCreateWindow (OS.HWND_DESKTOP,       /* parent window */
     224                                                        PSZ.getAtom (OS.WC_MENU),       /* class name */
     225                                                        new PSZ(""),    /* window text */
     226                                                        OS.MS_ACTIONBAR,        /* window style */
     227                                                        0, 0, 0, 0, /* size and position */
     228                                                        OS.HWND_DESKTOP,        /* owner window */
     229                                                        OS.HWND_TOP, /* sibling window */
     230                                                        OS.FID_MENU,    /* ID */
     231                                                        OS.NULLHANDLE,  /* control data */
     232                                                        0               /* presentation parameters */
     233                                                        );
     234        } else {
     235            short flOptions = OS.PU_MOUSEBUTTON1DOWN | OS.PU_KEYBOARD | OS.PU_MOUSEBUTTON1;
     236            handle = OS.WinCreateWindow (OS.HWND_DESKTOP,       /* parent window */
     237                                                        PSZ.getAtom (OS.WC_MENU),       /* class name */
     238                                                        new PSZ(""),    /* window text */
     239                                                        0,      /* window style */
     240                                                        0, 0, 0, 0, /* size and position */
     241                                                        OS.HWND_DESKTOP,        /* owner window */
     242                                                        OS.HWND_TOP, /* sibling window */
     243                                                        OS.FID_MENU,    /* ID */
     244                                                        OS.NULLHANDLE,  /* control data */
     245                                                        0               /* presentation parameters */
     246                                                        );
     247          boolean rc = OS.WinPopupMenu(OS.HWND_DESKTOP, OS.HWND_DESKTOP, handle, 0, 0, 0, flOptions);
     248             
     249        }
     250        if (handle == 0) error (SWT.ERROR_NO_HANDLES);
     251}
     252
     253void createItem (MenuItem item, int index) {
     254        int count = GetMenuItemCount (handle);
     255        if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
     256        parent.add (item);
     257        boolean success = false;
     258
     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
     287        if (!success) {
     288                parent.remove (item);
     289                error (SWT.ERROR_ITEM_NOT_ADDED);
     290        }
     291        redraw ();
     292}
     293
     294void createWidget () {
     295        createHandle ();
     296        parent.add (this);
     297}
    299298
    300299/*
    301300* Currently not used.
    302301*/
    303 //int defaultBackground () {
    304 //      return OS.GetSysColor (OS.COLOR_MENU);
    305 //}
     302int defaultBackground () {
     303        return OS.WinQuerySysColor(handle, OS.SYSCLR_MENU, 0);
     304}
    306305
    307306/*
    308307* Currently not used.
    309308*/
    310 //int defaultForeground () {
    311 //      return OS.GetSysColor (OS.COLOR_MENUTEXT);
    312 //}
     309int defaultForeground () {
     310        return OS.WinQuerySysColor(handle, OS.SYSCLR_MENUTEXT, 0);
     311}
    313312
    314313//void destroyAcceleratorTable () {
Note: See TracChangeset for help on using the changeset viewer.