Changeset 75 for trunk/src


Ignore:
Timestamp:
May 23, 2008, 6:27:46 PM (17 years ago)
Author:
lpino
Message:
  • (Decorations.java) Added getMenuBar, setMenuBar methods and broken implementations of createAcceleratorTable and destroyAcceleratorTable
File:
1 edited

Legend:

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

    r65 r75  
    101101        Button defaultButton, saveDefault;
    102102//@@TODO (dmik): later   
    103 //      int swFlags, hAccel, nAccel;
     103        int swFlags, hAccel, nAccel;
    104104//      int hwndCB, hwndTB, hIcon;
    105105//     
     
    294294}
    295295
    296 //@@TODO(dmik)
    297 //void createAcceleratorTable () {
    298 //      hAccel = nAccel = 0;
    299 //      int maxAccel = 0;
    300 //      if (menuBar == null || items == null) {
    301 //              if (!OS.IsPPC) return;
    302 //              maxAccel = 1;
    303 //      } else {
    304 //              maxAccel = OS.IsPPC ? items.length + 1 : items.length;
    305 //      }
    306 //      int size = ACCEL.sizeof;
    307 //      ACCEL accel = new ACCEL ();
    308 //      byte [] buffer1 = new byte [size];     
    309 //      byte [] buffer2 = new byte [maxAccel * size];
    310 //      if (menuBar != null && items != null) {
    311 //              for (int i=0; i<items.length; i++) {
    312 //                      MenuItem item = items [i];
    313 //                      if (item != null && item.accelerator != 0) {
    314 //                              Menu parent = item.parent;
    315 //                              while (parent != null && parent != menuBar) {
    316 //                                      parent = parent.getParentMenu ();
    317 //                              }
    318 //                              if (parent == menuBar) {
    319 //                                      item.fillAccel (accel);
    320 //                                      OS.MoveMemory (buffer1, accel, size);
    321 //                                      System.arraycopy (buffer1, 0, buffer2, nAccel * size, size);
    322 //                                      nAccel++;
    323 //                              }
    324 //                      }
    325 //              }
    326 //      }
    327 //      if (nAccel != 0) hAccel = OS.CreateAcceleratorTable (buffer2, nAccel);
    328 //}
     296void createAcceleratorTable () {
     297        hAccel = nAccel = 0;
     298        int maxAccel = 0;
     299        if (menuBar == null || items == null) {
     300             return;
     301        } else {
     302                maxAccel = items.length;
     303        }
     304        int size = ACCEL.sizeof;
     305        ACCEL accel = new ACCEL ();
     306        byte [] buffer1 = new byte [size];     
     307        byte [] buffer2 = new byte [maxAccel * size];
     308        if (menuBar != null && items != null) {
     309                for (int i=0; i<items.length; i++) {
     310                        MenuItem item = items [i];
     311                        if (item != null && item.accelerator != 0) {
     312                                Menu parent = item.parent;
     313                                while (parent != null && parent != menuBar) {
     314                                        parent = parent.getParentMenu ();
     315                                }
     316                                if (parent == menuBar) {
     317                                        item.fillAccel (accel);
     318                                        OS.MoveMemory (buffer1, accel, size);
     319                                        System.arraycopy (buffer1, 0, buffer2, nAccel * size, size);
     320                                        nAccel++;
     321                                }
     322                        }
     323                }
     324        }
     325//        hAccel = OS.WinCreateAccelTable(hab, pacctAccelTable);
     326        if (nAccel != 0) hAccel = OS.CreateAcceleratorTable (buffer2, nAccel);
     327}
    329328
    330329void createHandle () {
     
    429428//}
    430429
    431 //@@TODO (dmik): later
    432 //void destroyAcceleratorTable () {
    433 //      if (hAccel != 0 && hAccel != -1) OS.DestroyAcceleratorTable (hAccel);
    434 //      hAccel = -1;
    435 //}
     430void destroyAcceleratorTable () {
     431        if (hAccel != 0 && hAccel != -1) OS.DestroyAcceleratorTable (hAccel);
     432        hAccel = -1;
     433}
    436434
    437435void destroyWidget () {
     
    585583// * </ul>
    586584// */
    587 //public Menu getMenuBar () {
    588 //      checkWidget ();
    589 //      return menuBar;
    590 //}
     585public Menu getMenuBar () {
     586        checkWidget ();
     587        return menuBar;
     588}
    591589
    592590/**
     
    10441042// * </ul>
    10451043// */
    1046 //public void setMenuBar (Menu menu) {
    1047 //      checkWidget ();
    1048 //      if (menuBar == menu) return;
    1049 //      if (menu != null) {
    1050 //              if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
    1051 //              if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR);
    1052 //              if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT);
    1053 //      }       
    1054 //      if (OS.IsPPC) {
    1055 //              /*
    1056 //              * Note in WinCE PPC.  MenuBar is a separate popup window. If
    1057 //              * the Shell is full screen, resize its window to leave
    1058 //              * space for the MenuBar.
    1059 //              */
    1060 //              boolean resize = (getMaximized() && menuBar != menu);
    1061 //              if (menuBar != null) {
    1062 //                      OS.CommandBar_Destroy (hwndCB);
    1063 //                      hwndCB = 0;
    1064 //                      hwndTB = 0;
    1065 //              }
    1066 //              menuBar = menu;
    1067 //              if (menuBar != null) {         
    1068 //                      SHMENUBARINFO mbi = new SHMENUBARINFO ();
    1069 //                      mbi.cbSize = mbi.sizeof;
    1070 //                      mbi.hwndParent = handle;
    1071 //                      mbi.dwFlags = 0;
    1072 //                      mbi.nToolBarId = 100; /* as defined in .rc file */
    1073 //                      mbi.hInstRes = OS.GetLibraryHandle ();
    1074 //                      boolean success = OS.SHCreateMenuBar (mbi);
    1075 //                      hwndCB = mbi.hwndMB;
    1076 //
    1077 //                      /* get toolbar */
    1078 //                      if (success && hwndCB != 0) hwndTB = OS.GetWindow (hwndCB, OS.GW_CHILD);
    1079 //                                             
    1080 //                      if (hwndTB == 0) {
    1081 //                              /* we can't use the menubar */
    1082 //                              if (hwndCB != 0) OS.CommandBar_Destroy (hwndCB);
    1083 //                              return;
    1084 //                      }
    1085 //                      /* remove the menu item coming from the resource file */
    1086 //                      OS.SendMessage (hwndTB, OS.TB_DELETEBUTTON, 0, 0);
    1087 //                     
    1088 //                      /* populate tool bar mapping menu items to tool items */
    1089 //                      if (menuBar.getItemCount () > 0) {
    1090 //                              MenuItem[] items = menuBar.getItems ();
    1091 //                              TBBUTTON lpButton = new TBBUTTON ();
    1092 //                              TBBUTTONINFO info = new TBBUTTONINFO ();
    1093 //                              info.cbSize = TBBUTTONINFO.sizeof;
    1094 //                              info.dwMask = OS.TBIF_TEXT;
    1095 //                             
    1096 //                              int cch = 128;
    1097 //                              int hHeap = OS.GetProcessHeap ();
    1098 //                              int byteCount = cch * TCHAR.sizeof;
    1099 //                              int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
    1100 //                              MENUITEMINFO mii = new MENUITEMINFO ();
    1101 //                              mii.cbSize = MENUITEMINFO.sizeof;
    1102 //                              mii.fMask = OS.MIIM_STATE | OS.MIIM_TYPE;
    1103 //                              mii.dwTypeData = pszText;
    1104 //
    1105 //                              for (int i = 0; i < items.length; i++) {
    1106 //                                      MenuItem item = items[i];
    1107 //                                      /* insert item */
    1108 //                                      lpButton.idCommand = item.id;
    1109 //                                      lpButton.fsStyle = (byte) (OS.TBSTYLE_DROPDOWN | OS.TBSTYLE_AUTOSIZE | 0x80);
    1110 //                                      lpButton.fsState = (byte) OS.TBSTATE_ENABLED;
    1111 //                                      lpButton.iBitmap = OS.I_IMAGENONE;
    1112 //                                      if ((item.style & SWT.SEPARATOR) != 0) {
    1113 //                                              lpButton.fsStyle = (byte) OS.BTNS_SEP;
    1114 //                                      }
    1115 //                                      OS.SendMessage (hwndTB, OS.TB_INSERTBUTTON, i, lpButton);
    1116 //
    1117 //                                      if ((item.style & SWT.SEPARATOR) == 0) {
    1118 //                                              /* set text and state info */
    1119 //                                              Menu parent = item.parent;
    1120 //                                              int id = item.id;
    1121 //                                              int hMenu = parent.handle;
    1122 //                                                                                             
    1123 //                                              mii.cch = cch;
    1124 //                                              success = OS.GetMenuItemInfo (hMenu, i, true, mii);
    1125 //                                              if (!success) error (SWT.ERROR_INVALID_ARGUMENT);
    1126 //                                              boolean enabled = (mii.fState & (OS.MFS_DISABLED | OS.MFS_GRAYED)) == 0;
    1127 //                                              if (!enabled) {
    1128 //                                                      info.dwMask |= OS.TBIF_STATE;
    1129 //                                                      info.fsStyle = 0;
    1130 //                                              }                                               
    1131 //                                              info.pszText = pszText;
    1132 //                                              OS.SendMessage (hwndTB, OS.TB_SETBUTTONINFO, item.id, info);
    1133 //
    1134 //                                              /* set menu */
    1135 //                                              Menu menu2 = item.menu;
    1136 //                                              if (menu2 != null) {
    1137 //                                                      OS.SendMessage (hwndCB, OS.SHCMBM_SETSUBMENU, item.id, menu2.handle);
    1138 //                                              }
    1139 //                                      }
    1140 //                              }
    1141 //                              if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
    1142 //                      }
    1143 //              }
    1144 //              if (resize) setMaximized (true);
    1145 //      } else if (OS.IsHPC) {
    1146 //              boolean resize = menuBar != menu;
    1147 //              if (menuBar != null) {
    1148 //                      /*
    1149 //                      * Because CommandBar_Destroy destroys the menu bar, it
    1150 //                      * is necessary to move the current items into a new menu
    1151 //                      * before it is called.
    1152 //                      */
    1153 //                      int hMenu = OS.CreateMenu ();
    1154 //                      if (!moveMenu (menuBar.handle, hMenu)) {
    1155 //                              error (SWT.ERROR_CANNOT_SET_MENU);
    1156 //                      }
    1157 //                      menuBar.handle = hMenu;
    1158 //                      if (hwndCB != 0) OS.CommandBar_Destroy (hwndCB);
    1159 //                      hwndCB = 0;
    1160 //              }
    1161 //              menuBar = menu;
    1162 //              if (menuBar != null) {         
    1163 //                      hwndCB = OS.CommandBar_Create (OS.GetModuleHandle (null), handle, 1);
    1164 //                      OS.CommandBar_InsertMenubarEx (hwndCB, 0, menuBar.handle, 0);
    1165 //                      /*
    1166 //                      * The command bar hosts the 'close' button when the window does not
    1167 //                      * have a caption.
    1168 //                      */
    1169 //                      if ((style & SWT.CLOSE) != 0 && (style & SWT.TITLE) == 0) {
    1170 //                              OS.CommandBar_AddAdornments(hwndCB, 0, 0);
    1171 //                      }
    1172 //              }
    1173 //              if (resize) {
    1174 //                      sendEvent (SWT.Resize);
    1175 //                      layout (false);
    1176 //              }
    1177 //      } else {
    1178 //              menuBar = menu;
    1179 //              int hMenu = 0;
    1180 //              if (menuBar != null) hMenu = menuBar.handle;
    1181 //              OS.SetMenu (handle, hMenu);
    1182 //      }
     1044public void setMenuBar (Menu menu) {
     1045        checkWidget ();
     1046        if (menuBar == menu) return;
     1047        if (menu != null) {
     1048                if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
     1049                if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR);
     1050                if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT);
     1051        }       
     1052        menuBar = menu;
     1053        int hMenu = 0;
     1054        if (menuBar != null)
     1055            hMenu = menuBar.handle;
     1056//        OS.SetMenu (handle, hMenu);
     1057        OS.WinSendMsg (frameHandle, OS.WM_UPDATEFRAME, OS.FCF_MENU, 0);
     1058        System.out.println("Decorations:setMenuBar");
    11831059//      destroyAcceleratorTable ();
    1184 //}
     1060}
    11851061
    11861062/**
Note: See TracChangeset for help on using the changeset viewer.