From: <kr_...@us...> - 2003-08-15 21:25:22
|
Update of /cvsroot/htoolkit/port/src/cbits/Win32 In directory sc8-pr-cvs1:/tmp/cvs-serv11074/port/src/cbits/Win32 Modified Files: Frame.c Menu.c MenuHandlesMap.c MenuHandlesMap.h Window.c Log Message: Simplified API for MenuRadioItems Index: Frame.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Frame.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Frame.c 15 Aug 2003 16:40:01 -0000 1.13 --- Frame.c 15 Aug 2003 21:24:54 -0000 1.14 *************** *** 1,4 **** --- 1,6 ---- #include "Types.h" #include "Window.h" + #include "Menu.h" + #include "DockBar.h" #include "MenuHandlesMap.h" #include "Canvas.h" *************** *** 21,25 **** LRESULT CALLBACK HFrameSharedFunction(int DocumentInterface, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { ! int pos, ppos; HMENU hParent; MENUITEMINFO mii; --- 23,27 ---- LRESULT CALLBACK HFrameSharedFunction(int DocumentInterface, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { ! int pos; HMENU hParent; MENUITEMINFO mii; *************** *** 140,163 **** if (handle) { ! hParent = getParentHMENU(handle); ! pos = getMenuPos(pData->pMenuHandlesMap, handle); ! ! mii.cbSize = sizeof(mii); ! mii.fMask = MIIM_STATE; ! GetMenuItemInfo(hParent, pos, TRUE, &mii); ! ! switch (handle->type) ! { ! case MENU_RADIO_ITEM: ! ppos = getMenuPos(pData->pMenuHandlesMap, handle->parent); ! CheckMenuRadioItem(hParent, ppos, ppos+getChildrenCount(pData->pMenuHandlesMap, handle->parent)-1, pos, MF_BYPOSITION); ! break; ! case MENU_CHECK_ITEM: ! CheckMenuItem(hParent, pos, ((mii.fState & MFS_CHECKED) ? MF_UNCHECKED : MF_CHECKED) | MF_BYPOSITION); ! break; ! default: ! } ! ! handleMenuCommand(handle); } } --- 142,148 ---- if (handle) { ! if (handle->type & (MENU_RADIO_ITEM | MENU_CHECK_ITEM)) ! osSetMenuItemChecked(handle, TRUE); ! handleMenuCommand(handle); } } Index: Menu.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Menu.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Menu.c 23 Jul 2003 16:25:21 -0000 1.11 --- Menu.c 15 Aug 2003 21:24:54 -0000 1.12 *************** *** 182,202 **** } - MenuHandle osInsertMenuRadioGroup(MenuHandle parent, int pos) - { - FrameData *pFrameData; - - CHECK_MENU_TYPE(parent, MENU_POPUP, NULL); - - pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); - - return newMenuHandle(pFrameData->pMenuHandlesMap, parent, MENU_RADIO_GROUP, pos); - }; - MenuHandle osInsertMenuRadioItem(MenuHandle parent, int pos) { MenuHandle handle; FrameData *pFrameData; ! CHECK_MENU_TYPE(parent, MENU_RADIO_GROUP, NULL); pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); --- 182,192 ---- } MenuHandle osInsertMenuRadioItem(MenuHandle parent, int pos) { MenuHandle handle; FrameData *pFrameData; + MENUITEMINFO mii; ! CHECK_MENU_TYPE(parent, MENU_POPUP, NULL); pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); *************** *** 205,209 **** if (handle) { ! InsertMenu(getParentHMENU(handle),getMenuPos(pFrameData->pMenuHandlesMap, handle),MF_BYPOSITION | MF_STRING,handle->id,""); updateMenuBar(parent); } --- 195,204 ---- if (handle) { ! mii.cbSize = sizeof(mii); ! mii.fMask = MIIM_ID | MIIM_STATE | MIIM_TYPE; ! mii.wID = handle->id; ! mii.fState = MFS_ENABLED; ! mii.fType = MFT_RADIOCHECK; ! InsertMenuItem(getParentHMENU(handle),getMenuPos(pFrameData->pMenuHandlesMap, handle),TRUE,&mii); updateMenuBar(parent); } *************** *** 212,236 **** }; void osDestroyMenu(MenuHandle handle) { - int pos, count; - HMENU hParent; FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); notifyHandleForDestroy(handle); ! ! hParent = getParentHMENU(handle); ! pos = getMenuPos(pFrameData->pMenuHandlesMap, handle); ! ! if (handle->type != MENU_RADIO_GROUP) ! DeleteMenu(hParent, pos, MF_BYPOSITION); ! else ! { ! count = getChildrenCount(pFrameData->pMenuHandlesMap, handle); ! while (count--) ! DeleteMenu(hParent, pos, MF_BYPOSITION); ! } ! deleteMenuHandle(pFrameData->pMenuHandlesMap, handle); updateMenuBar(handle->parent); } --- 207,244 ---- }; + void osSetMenuRadioGroup(MenuHandle *handles) + { + MenuHandle child, handle, *phandle; + + phandle=handles; + for (;;) + { + handle = *phandle; + + child = handle->nextInGroup; + while (child->nextInGroup != handle) + child = child->nextInGroup; + child->nextInGroup = handle->nextInGroup; + + phandle++; + if (*phandle) + handle->nextInGroup = *phandle; + else + { + handle->nextInGroup = *handles; + break; + } + } + } + void osDestroyMenu(MenuHandle handle) { FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); notifyHandleForDestroy(handle); ! ! DeleteMenu(getParentHMENU(handle), getMenuPos(pFrameData->pMenuHandlesMap, handle), MF_BYPOSITION); deleteMenuHandle(pFrameData->pMenuHandlesMap, handle); + updateMenuBar(handle->parent); } *************** *** 240,244 **** FrameData *pFrameData; ! CHECK_MENU_TYPE(handle, MENU_RADIO_GROUP | MENU_POPUP, 0); pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); --- 248,252 ---- FrameData *pFrameData; ! CHECK_MENU_TYPE(handle, MENU_POPUP, 0); pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); *************** *** 277,286 **** { FrameData *pFrameData; ! CHECK_MENU_TYPE_V(handle, MENU_CHECK_ITEM); pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! CheckMenuItem(getParentHMENU(handle), getMenuPos(pFrameData->pMenuHandlesMap, handle), (bState ? MF_CHECKED : MF_UNCHECKED) | MF_BYPOSITION); updateMenuBar(handle->parent); --- 285,308 ---- { FrameData *pFrameData; + MenuHandle child; ! CHECK_MENU_TYPE_V(handle, MENU_CHECK_ITEM | MENU_RADIO_ITEM); pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! if (bState) ! { ! child = handle->nextInGroup; ! while (child != handle) ! { ! CheckMenuItem(getParentHMENU(child), getMenuPos(pFrameData->pMenuHandlesMap, child), MF_UNCHECKED | MF_BYPOSITION); ! child = child->nextInGroup; ! } ! ! CheckMenuItem(getParentHMENU(handle), getMenuPos(pFrameData->pMenuHandlesMap, handle), MF_CHECKED | MF_BYPOSITION); ! } ! else ! CheckMenuItem(getParentHMENU(handle), getMenuPos(pFrameData->pMenuHandlesMap, handle), MF_UNCHECKED | MF_BYPOSITION); ! updateMenuBar(handle->parent); *************** *** 293,297 **** FrameData *pFrameData; ! CHECK_MENU_TYPE(handle, MENU_CHECK_ITEM, FALSE); pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); --- 315,319 ---- FrameData *pFrameData; ! CHECK_MENU_TYPE(handle, MENU_CHECK_ITEM | MENU_RADIO_ITEM, FALSE); pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); *************** *** 303,359 **** } - void osSetMenuRadioGroupSelection(MenuHandle handle, int index) - { - int pos; - HMENU hParent; - FrameData *pFrameData; - MenuHandle child; - - CHECK_MENU_TYPE_V(handle, MENU_RADIO_GROUP); - - pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); - hParent = getParentHMENU(handle); - pos = getMenuPos(pFrameData->pMenuHandlesMap, handle); - child = getNthChild(pFrameData->pMenuHandlesMap, handle, index); - - if (!child) return; - - CheckMenuRadioItem(hParent, pos, pos+getChildrenCount(pFrameData->pMenuHandlesMap, handle)-1, pos+index, MF_BYPOSITION); - updateMenuBar(handle->parent); - - handleMenuCommand(child); - } - - int osGetMenuRadioGroupSelection(MenuHandle handle) - { - HMENU hParent; - int pos, index; - MenuHandle child; - FrameData *pFrameData; - - CHECK_MENU_TYPE(handle, MENU_RADIO_GROUP, -1); - - pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); - hParent = getParentHMENU(handle); - pos = getMenuPos(pFrameData->pMenuHandlesMap, handle); - - index = 0; - child = handle->children; - while (child) - { - MENUITEMINFO mii; - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_STATE; - GetMenuItemInfo(hParent, pos+index, TRUE, &mii); - if (mii.fState & MFT_RADIOCHECK) - return index; - - index++; - child = child->sibling; - } - - return index; - } - char *osGetMenuLabel(MenuHandle handle) { --- 325,328 ---- *************** *** 513,516 **** { FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! return getMenuIndex(pFrameData->pMenuHandlesMap, handle); } --- 482,485 ---- { FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! return getMenuPos(pFrameData->pMenuHandlesMap, handle); } Index: MenuHandlesMap.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/MenuHandlesMap.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MenuHandlesMap.c 23 Apr 2003 21:48:53 -0000 1.1 --- MenuHandlesMap.c 15 Aug 2003 21:24:54 -0000 1.2 *************** *** 83,86 **** --- 83,87 ---- handle->type = type; handle->hMenu = NULL; + handle->nextInGroup = handle; if (parent) *************** *** 167,170 **** --- 168,176 ---- } + child = handle->nextInGroup; + while (child->nextInGroup != handle) + child = child->nextInGroup; + child->nextInGroup = handle->nextInGroup; + handle->next = pMap->pFreeList; pMap->pFreeList = handle; *************** *** 287,361 **** }; ! static BOOL getMenuPosEx(MenuHandle firstSibling, MenuHandle handle, int *pos) { MenuHandle h; ! h = firstSibling; ! while (h) { ! if (h == handle) ! return TRUE; ! ! if (h->type != MENU_RADIO_GROUP) ! *pos += 1; ! else ! { ! if (getMenuPosEx(h->children, handle, pos)) ! return TRUE; ! } ! h = h->sibling; } - - return FALSE; - }; - - int getMenuPos(MenuHandlesMap *pMap, MenuHandle handle) - { - int pos; - MenuHandle parent; - - parent = handle->parent; - while (parent && parent->hMenu == NULL) - parent = parent->parent; - - pos = 0; - if (!getMenuPosEx(parent ? parent->children : pMap->children, handle, &pos)) - return -1; return pos; }; - int getMenuIndex(MenuHandlesMap *pMap, MenuHandle handle) - { - int index; - MenuHandle child; - - index = 0; - child = handle->parent ? handle->parent->children : pMap->children; - while (child) - { - if (child == handle) - break; - - index += 1; - child = child->sibling; - } - - return index; - }; - HMENU getParentHMENU(MenuHandle handle) { ! MenuHandle parent; ! ! parent = handle->parent; ! while (parent && parent->hMenu == NULL) ! parent = parent->parent; ! ! if (parent == NULL) return GetMenu(ghWndFrame); else ! return parent->hMenu; } --- 293,318 ---- }; ! int getMenuPos(MenuHandlesMap *pMap, MenuHandle handle) { + int pos; MenuHandle h; ! pos = 0; ! h = handle->parent ? handle->parent->children : pMap->children; ! while (h && h != handle) { ! pos++; h = h->sibling; } return pos; }; HMENU getParentHMENU(MenuHandle handle) { ! if (handle->parent == NULL) return GetMenu(ghWndFrame); else ! return handle->parent->hMenu; } Index: MenuHandlesMap.h =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/MenuHandlesMap.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MenuHandlesMap.h 23 Jul 2003 16:25:21 -0000 1.2 --- MenuHandlesMap.h 15 Aug 2003 21:24:54 -0000 1.3 *************** *** 12,17 **** , MENU_POPUP = 4 , MENU_CHECK_ITEM = 8 ! , MENU_RADIO_GROUP = 16 ! , MENU_RADIO_ITEM = 32 }; --- 12,16 ---- , MENU_POPUP = 4 , MENU_CHECK_ITEM = 8 ! , MENU_RADIO_ITEM = 16 }; *************** *** 24,27 **** --- 23,27 ---- struct MenuHandle *children; struct MenuHandle *sibling; + struct MenuHandle *nextInGroup; UINT id; *************** *** 55,59 **** MenuHandle getMenuHandle(MenuHandlesMap *pMap, UINT id); int getMenuPos(MenuHandlesMap *pMap, MenuHandle handle); - int getMenuIndex(MenuHandlesMap *pMap, MenuHandle handle); void updateAccelTable(MenuHandlesMap *pMap, MenuHandle item, int key, unsigned int mods); HACCEL getAccelTableFromMap(MenuHandlesMap *pMap); --- 55,58 ---- Index: Window.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Window.c,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** Window.c 15 Jul 2003 19:00:30 -0000 1.36 --- Window.c 15 Aug 2003 21:24:54 -0000 1.37 *************** *** 1,3 **** --- 1,4 ---- #include "Window.h" + #include "Menu.h" #include "Internals.h" #include "Handlers_stub.h" *************** *** 186,192 **** else { - int pos, ppos; - HMENU hParent; - MENUITEMINFO mii; FrameData *pData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); MenuHandle handle = getMenuHandle(pData->pMenuHandlesMap, (UINT) LOWORD(wParam)); --- 187,190 ---- *************** *** 194,220 **** if (handle) { ! hParent = getParentHMENU(handle); ! pos = getMenuPos(pData->pMenuHandlesMap, handle); ! ! mii.cbSize = sizeof(mii); ! mii.fMask = MIIM_STATE; ! GetMenuItemInfo(hParent, pos, TRUE, &mii); ! ! if ((mii.fState & MFS_DISABLED) == 0) ! { ! switch (handle->type) ! { ! case MENU_RADIO_ITEM: ! ppos = getMenuPos(pData->pMenuHandlesMap, handle->parent); ! CheckMenuRadioItem(hParent, ppos, ppos+getChildrenCount(pData->pMenuHandlesMap, handle->parent)-1, pos, MF_BYPOSITION); ! break; ! case MENU_CHECK_ITEM: ! CheckMenuItem(hParent, pos, ((mii.fState & MFS_CHECKED) ? MF_UNCHECKED : MF_CHECKED) | MF_BYPOSITION); ! break; ! default: ! } ! ! handleMenuCommand(handle); ! } } } --- 192,198 ---- if (handle) { ! if (handle->type & (MENU_RADIO_ITEM | MENU_CHECK_ITEM)) ! osSetMenuItemChecked(handle, TRUE); ! handleMenuCommand(handle); } } |