From: <kr_...@us...> - 2004-05-14 23:01:58
|
Update of /cvsroot/htoolkit/port/src/cbits/Win32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27239/src/cbits/Win32 Modified Files: DockBar.c Frame.c Internals.h Menu.c ToolBar.c Util.c Window.c Added Files: Action.c ActionsMap.c ActionsMap.h Removed Files: MenuHandlesMap.c MenuHandlesMap.h Log Message: Still incomplete support for actions under Windows --- NEW FILE: Action.c --- #include "Action.h" #include "Window.h" #include "DockBar.h" #include "Internals.h" #include "Handlers_stub.h" ActionHandle osCreateAction() { FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); return newActionHandle(pFrameData->pActionsMap, ACTION_NORMAL); } ActionHandle osCreateCheckAction() { FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); return newActionHandle(pFrameData->pActionsMap, ACTION_CHECK); } ActionHandle osCreateRadioAction() { FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); return newActionHandle(pFrameData->pActionsMap, ACTION_RADIO); } ActionHandle osCreateDropDownAction(MenuHandle menu) { ActionHandle action; FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); action = newActionHandle(pFrameData->pActionsMap, ACTION_DROPDOWN); action->menu = menu; return action; } void osSetActionRadioGroup(ActionHandle *handles) { ActionHandle *phandle, handle, child; if (!handles || *handles == NULL) return; 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 osSetActionBitmap(ActionHandle action, BitmapHandle bitmap) { ToolHandle tool; FrameData *pFrameData; pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); action->bitmap = bitmap; tool = action->toolProxies; while (tool) { TBADDBITMAP tbab; TBBUTTONINFO tbbi; if (bitmap) { tbab.hInst = NULL; tbab.nID = (UINT) bitmap->hBitmap; tbbi.iImage = SendMessage(tool->hToolBar, TB_ADDBITMAP, 1, (LPARAM) &tbab); } else tbbi.iImage = I_IMAGENONE; tbbi.cbSize = sizeof(tbbi); tbbi.dwMask = TBIF_IMAGE; SendMessage(tool->hToolBar, TB_SETBUTTONINFO, action->id, (LPARAM) &tbbi); tool = tool->nextInAction; } RelayoutFrameBars(); } void osSetActionEnabled(ActionHandle action, BOOL enabled) { ToolHandle tool; action->enabled = enabled; tool = action->toolProxies; while (tool) { SendMessage(tool->hToolBar, TB_ENABLEBUTTON, action->id, (LPARAM) enabled); tool = tool->nextInAction; } } BOOL osGetActionEnabled(ActionHandle action) { return action->enabled; } void osSetActionTip(ActionHandle action, char *text) { action->tooltip = strdup(text); } char *osGetActionTip(ActionHandle action) { return strdup(action->tooltip); } void osSetActionText(ActionHandle action, char *text) { ToolHandle tool; action->title = strdup(text); tool = action->toolProxies; while (tool) { TBBUTTONINFO tbbi; tbbi.cbSize = sizeof(tbbi); tbbi.dwMask = TBIF_STYLE; tbbi.fsStyle = TBSTYLE_BUTTON; SendMessage(tool->hToolBar, TB_GETBUTTONINFO, action->id, (LPARAM) &tbbi); tbbi.dwMask = TBIF_TEXT | TBIF_STYLE; tbbi.fsStyle = (text && *text) ? (tbbi.fsStyle | BTNS_SHOWTEXT) : (tbbi.fsStyle & ~BTNS_SHOWTEXT); tbbi.pszText = text; tbbi.cchText = strlen(text); SendMessage(tool->hToolBar, TB_SETBUTTONINFO, action->id, (LPARAM) &tbbi); tool = tool->nextInAction; } RelayoutFrameBars(); } char *osGetActionText(ActionHandle action) { return strdup(action->title); } void osSetActionShortText(ActionHandle action, char *text) { action->short_title = (text && *text) ? strdup(text) : NULL; } char *osGetActionShortText(ActionHandle action) { return strdup(action->short_title); } void osSetActionChecked(ActionHandle action, BOOL checked) { ToolHandle tool; ActionHandle actionInGroup; actionInGroup = action; do { actionInGroup->checked = checked; tool = actionInGroup->toolProxies; while (tool) { int nState = SendMessage(tool->hToolBar, TB_GETSTATE, actionInGroup->id, 0); if (checked) nState = nState | TBSTATE_CHECKED; else nState = nState & ~TBSTATE_CHECKED; SendMessage(tool->hToolBar,TB_SETSTATE,actionInGroup->id,MAKELONG(nState, 0)); tool = tool->nextInAction; } actionInGroup = actionInGroup->nextInGroup; checked = FALSE; } while (actionInGroup != action); handleActionCommand(action); }; BOOL osGetActionChecked(ActionHandle action) { return action->checked; }; void osSetActionAccel(ActionHandle action, int key, unsigned int mods) { FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); updateAccelTable(pFrameData->pActionsMap, action, key, mods); }; void osGetActionAccel(ActionHandle action, int *key, unsigned int *mods) { *key = action->key; *mods = action->keyMods; }; void osActivateAction(int id) { FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ActionHandle action = getActionHandle(pFrameData->pActionsMap, id); if (action) { switch (action->type) { case ACTION_NORMAL: handleActionCommand(action); break; case ACTION_CHECK: osSetActionChecked(action, !action->checked); break; case ACTION_RADIO: osSetActionChecked(action, TRUE); break; case ACTION_DROPDOWN: break; } } } void osDestroyAction(ActionHandle action) { FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); deleteActionHandle(pFrameData->pActionsMap, action); } --- NEW FILE: ActionsMap.c --- #include "ActionsMap.h" #include "Window.h" #include "Internals.h" #include "Handlers_stub.h" ActionsMap *newActionsMap() { ActionsMap *pMap; pMap = (ActionsMap *) malloc(sizeof(ActionsMap)); if (!pMap) return NULL; pMap->nNextActionID=0; pMap->menus = NULL; pMap->popupMenus = NULL; pMap->pFreeList = NULL; pMap->pBlocks = NULL; pMap->nAccelCount = 0; pMap->hAccelTable = NULL; memset(pMap->HashTable, 0, sizeof(ActionHandle)*HASH_TABLE_SIZE); return pMap; } void deleteActionsMap(ActionsMap *pMap) { Block *p, *pNext; pMap->pFreeList = NULL; p = pMap->pBlocks; while (p != NULL) { pNext = p->pNext; free(p); p = pNext; } if (pMap->hAccelTable) DestroyAcceleratorTable(pMap->hAccelTable); free(pMap); } ActionHandle newActionHandle(ActionsMap *pMap, enum ACTION_TYPE type) { int i, nHash; ActionHandle action; // it doesn't exist, add a new Association if (pMap->pFreeList == NULL) { // add another block Block *p = (Block *) malloc(sizeof(Block) + HASH_BLOCK_SIZE * sizeof(struct ActionHandle)); if (!p) return NULL; p->pNext = pMap->pBlocks; pMap->pBlocks = p; // change head (adds in reverse order for simplicity) // chain them into free list action = (ActionHandle) (p+1); // free in reverse order to make it easier to debug action += HASH_BLOCK_SIZE - 1; for (i = HASH_BLOCK_SIZE-1; i >= 0; i--, action--) { action->next = pMap->pFreeList; pMap->pFreeList = action; } } action = pMap->pFreeList; pMap->pFreeList = action->next; action->id = ++pMap->nNextActionID; action->type = type; action->title = NULL; action->short_title = NULL; action->tooltip = NULL; action->bitmap = NULL; action->enabled = TRUE; action->checked = FALSE; action->key = 0; action->keyMods = 0; action->menu = NULL; action->menuProxies = NULL; action->toolProxies = NULL; // by default the action is in its own group action->nextInGroup = action; // put into hash table nHash = (action->id >> 4) % HASH_TABLE_SIZE; action->next = pMap->HashTable[nHash]; pMap->HashTable[nHash] = action; return action; } void deleteActionHandle(ActionsMap *pMap, ActionHandle action) { int nHash; ActionHandle child, *prev; handleActionDestroy(action); nHash = (action->id >> 4) % HASH_TABLE_SIZE; prev = &(pMap->HashTable[nHash]); child = pMap->HashTable[nHash]; while (child) { if (child == action) { *prev = action->next; break; } prev = &child->next; child = child->next; } action->next = pMap->pFreeList; pMap->pFreeList = action; free(action->title); free(action->short_title); free(action->tooltip); } MenuHandle newMenuHandle(ActionsMap *pMap, MenuHandle parent, int pos, MENU_TYPE type, ActionHandle action) { MenuHandle handle, child, *prev; handle = malloc(sizeof(struct MenuHandle)); handle->parent = parent; handle->children = NULL; handle->sibling = NULL; handle->type = type; handle->hMenu = NULL; handle->action = action; if (action) { // link the button to the chain handle->nextInAction = action->menuProxies; action->menuProxies = handle; } if (type != MENU_POPUP) { if (parent) { child = parent->children; prev = &parent->children; } else { child = pMap->menus; prev = &pMap->menus; } } else { child = pMap->popupMenus; prev = &pMap->popupMenus; } if (pos < 0) while (child) { prev = &child->sibling; child = child->sibling; } else while (child && pos > 0) { prev = &child->sibling; child = child->sibling; pos--; } handle->sibling = child; *prev = handle; return handle; } void deleteMenuHandle(ActionsMap *pMap, MenuHandle handle) { MenuHandle child, *prev; while (handle->children) deleteMenuHandle(pMap, handle->children); if (handle->type != MENU_POPUP) { if (handle->parent) { prev = &handle->parent->children; child = handle->parent->children; } else { prev = &pMap->menus; child = pMap->menus; } } else { prev = &pMap->popupMenus; child = pMap->popupMenus; } while (child != handle) { prev = &child->sibling; child = child->sibling; } *prev = handle->sibling; if (handle->action) { prev = &handle->action->menuProxies; child = handle->action->menuProxies; while (child != handle) { prev = &child->nextInAction; child = child->nextInAction; } *prev = handle->nextInAction; } } ActionHandle getActionHandle(ActionsMap *pMap, UINT id) { ActionHandle action; unsigned int nHash; nHash = (id >> 4) % HASH_TABLE_SIZE; for (action = pMap->HashTable[nHash]; action != NULL; action = action->next) { if (action->id == id) return action; } return NULL; } void updateAccelTable(ActionsMap *pMap, ActionHandle action, int key, int mods) { if ( action->key && !key) pMap->nAccelCount--; if (!action->key && key) pMap->nAccelCount++; action->key = key; action->keyMods = mods; if (pMap->hAccelTable) { DestroyAcceleratorTable(pMap->hAccelTable); pMap->hAccelTable = NULL; } }; HACCEL getAccelTableFromMap(ActionsMap *pMap) { int i,k; ActionHandle action; ACCEL *pAccel; if (pMap->hAccelTable) return pMap->hAccelTable; if (pMap->nAccelCount == 0) return NULL; pAccel = malloc(sizeof(ACCEL)*pMap->nAccelCount); if (!pAccel) return NULL; for (k = 0, i = 0; k < pMap->nAccelCount; i++) { action = pMap->HashTable[i]; while (action) { pAccel[k].cmd = action->id; if (action->key > 0 && action->key < 256) { pAccel[k].key = action->key; pAccel[k].fVirt = 0; k++; } else if (action->key > 256 && action->key < 512) { pAccel[k].key = action->key-256; pAccel[k].fVirt = FALT; k++; } else { pAccel[k].fVirt = (((action->keyMods & shiftBIT) ? FSHIFT : 0) | ((action->keyMods & ctrlBIT ) ? FCONTROL : 0) | ((action->keyMods & altBIT ) ? FALT : 0) | FVIRTKEY); switch (action->key) { case kbUp: pAccel[k++].key = VK_UP; break; case kbDown: pAccel[k++].key = VK_DOWN; break; case kbLeft: pAccel[k++].key = VK_LEFT; break; case kbRight: pAccel[k++].key = VK_RIGHT; break; case kbPgUp: pAccel[k++].key = VK_PRIOR; break; case kbPgDown: pAccel[k++].key = VK_NEXT; break; case kbEnd: pAccel[k++].key = VK_END; break; case kbBegin: pAccel[k++].key = VK_HOME; break; case kbBackSpace:pAccel[k++].key = VK_BACK; break; case kbDelete: pAccel[k++].key = VK_DELETE; break; case kbEnter: pAccel[k++].key = VK_RETURN; break; case kbEscape: pAccel[k++].key = VK_ESCAPE; break; case kbTab: pAccel[k++].key = VK_TAB; break; case kbHelp: pAccel[k++].key = VK_HELP; break; case kbF1: pAccel[k++].key = VK_F1; break; case kbF2: pAccel[k++].key = VK_F2; break; case kbF3: pAccel[k++].key = VK_F3; break; case kbF4: pAccel[k++].key = VK_F4; break; case kbF5: pAccel[k++].key = VK_F5; break; case kbF6: pAccel[k++].key = VK_F6; break; case kbF7: pAccel[k++].key = VK_F7; break; case kbF8: pAccel[k++].key = VK_F8; break; case kbF9: pAccel[k++].key = VK_F9; break; case kbF10: pAccel[k++].key = VK_F10; break; case kbF11: pAccel[k++].key = VK_F11; break; case kbF12: pAccel[k++].key = VK_F12; break; case kbClear: pAccel[k++].key = VK_CLEAR; break; } } action = action->next; } } pMap->hAccelTable = CreateAcceleratorTable(pAccel, pMap->nAccelCount); free(pAccel); return pMap->hAccelTable; }; int getMenuPos(ActionsMap *pMap, MenuHandle handle) { int pos; MenuHandle h; if (handle->type != MENU_POPUP) h = handle->parent ? handle->parent->children : pMap->menus; else h = pMap->popupMenus; pos = 0; while (h && h != handle) { pos++; h = h->sibling; } return pos; }; HMENU getParentHMENU(MenuHandle handle) { if (handle->type != MENU_POPUP) if (handle->parent == NULL) return GetMenu(ghWndFrame); else return handle->parent->hMenu; else return NULL; } int getChildrenCount(ActionsMap *pMap, MenuHandle handle) { int count; MenuHandle child; count = 0; child = handle ? handle->children : pMap->menus; while (child != NULL) { count++; child = child->sibling; } return count; } MenuHandle getNthChild(ActionsMap *pMap, MenuHandle handle, int index) { MenuHandle child; child = handle ? handle->children : pMap->menus; while (child != NULL && index > 0) { index--; child = child->sibling; } return child; } --- NEW FILE: ActionsMap.h --- #ifndef MENU_ITEMS_MAP_H #define MENU_ITEMS_MAP_H #include "Types.h" #define HASH_BLOCK_SIZE 10 #define HASH_TABLE_SIZE 17 enum MENU_TYPE { MENU_POPUP = 1 , MENU_SUBMENU = 2 , MENU_SEPARATOR = 4 , MENU_ITEM = 8 , MENU_CHECK_ITEM = 16 , MENU_RADIO_ITEM = 32 }; typedef enum MENU_TYPE MENU_TYPE; enum ACTION_TYPE { ACTION_NORMAL, ACTION_CHECK, ACTION_RADIO, ACTION_DROPDOWN }; struct ActionHandle { // Unique identity UINT id; // chain; ActionHandle next; // next action in the hash table ActionHandle nextInGroup; // next action in the radio group // Attributes enum ACTION_TYPE type; // the action type char *title; char *short_title; char *tooltip; BitmapHandle bitmap; BOOL enabled : 1; // TRUE if the action is enabled BOOL checked : 1; // TRUE if the action is checked MenuHandle menu; // Accelerator int key, keyMods; // the collection of all proxies (menu items or toolbar buttons) associated to this action MenuHandle menuProxies; ToolHandle toolProxies; }; struct ToolHandle { HWND hToolBar; // toolbar handle ToolHandle nextInAction; // the link to the next tool with the same action ActionHandle action; // the associated action }; struct MenuHandle { struct MenuHandle *parent; struct MenuHandle *children; struct MenuHandle *sibling; HMENU hMenu; MENU_TYPE type; MenuHandle nextInAction; // the link to the next menu item with the same action ActionHandle action; // the associated action }; typedef struct Block_tag { struct Block_tag *pNext; } Block; typedef struct { int nNextActionID; struct MenuHandle *menus; struct MenuHandle *popupMenus; Block* pBlocks; ActionHandle pFreeList; ActionHandle HashTable[HASH_TABLE_SIZE]; HACCEL hAccelTable; int nAccelCount; } ActionsMap; ActionsMap *newActionsMap(); void deleteActionsMap(ActionsMap *pMap); ActionHandle newActionHandle(ActionsMap *pMap, enum ACTION_TYPE type); void deleteActionHandle(ActionsMap *pMap, ActionHandle handle); ActionHandle getActionHandle(ActionsMap *pMap, UINT id); void updateAccelTable(ActionsMap *pMap, ActionHandle item, int key, int mods); HACCEL getAccelTableFromMap(ActionsMap *pMap); MenuHandle newMenuHandle(ActionsMap *pMap, MenuHandle parent, int pos, MENU_TYPE type, ActionHandle action); void deleteMenuHandle(ActionsMap *pMap, MenuHandle handle); int getMenuPos(ActionsMap *pMap, MenuHandle handle); HMENU getParentHMENU(MenuHandle handle); int getChildrenCount(ActionsMap *pMap, MenuHandle handle); MenuHandle getNthChild(ActionsMap *pMap, MenuHandle handle, int index); #endif Index: DockBar.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/DockBar.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** DockBar.c 7 May 2004 14:44:50 -0000 1.10 --- DockBar.c 14 May 2004 23:01:39 -0000 1.11 *************** *** 1,5 **** #include "Types.h" - #include "Internals.h" #include "DockBar.h" #include "Handlers_stub.h" --- 1,6 ---- #include "Types.h" #include "DockBar.h" + #include "Action.h" + #include "Internals.h" #include "Handlers_stub.h" *************** *** 124,132 **** } - extern void osActivateToolItem(ToolHandle toolButton); - LRESULT CALLBACK HDockBarFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { DockBarData *pData = (DockBarData *) GetWindowLong(hWnd, GWL_USERDATA); switch (uMsg) --- 125,132 ---- } LRESULT CALLBACK HDockBarFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { DockBarData *pData = (DockBarData *) GetWindowLong(hWnd, GWL_USERDATA); + FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); switch (uMsg) *************** *** 174,208 **** return 0; case WM_COMMAND: ! { ! ToolHandle handle; ! TBBUTTONINFO tbbi; ! HWND hToolBar = (HWND) lParam; ! ! tbbi.cbSize = sizeof(tbbi); ! tbbi.dwMask = TBIF_LPARAM; ! tbbi.lParam = 0; ! SendMessage(hToolBar, TB_GETBUTTONINFO, LOWORD(wParam), (LPARAM) &tbbi); ! ! handle = (ToolHandle) tbbi.lParam; ! if (handle) osActivateToolItem(handle); ! } break; case WM_NOTIFY: { ! ToolHandle handle; ! TBBUTTONINFO tbbi; ! LPNMTOOLBAR lpNMToolBar = (LPNMTOOLBAR) lParam; ! if (lpNMToolBar->hdr.code == TBN_DROPDOWN) { ! tbbi.cbSize = sizeof(tbbi); ! tbbi.dwMask = TBIF_LPARAM; ! tbbi.lParam = 0; ! SendMessage(lpNMToolBar->hdr.hwndFrom, TB_GETBUTTONINFO, lpNMToolBar->iItem, (LPARAM) &tbbi); ! handle = (ToolHandle) tbbi.lParam; ! if (handle) ! osActivateToolItem(handle); } } break; --- 174,210 ---- return 0; case WM_COMMAND: ! osActivateAction(LOWORD(wParam)); break; case WM_NOTIFY: { ! LPNMHDR lpNMHdr = (LPNMHDR) lParam; ! if (lpNMHdr->code == TBN_DROPDOWN) { ! LPNMTOOLBAR lpNMToolBar = (LPNMTOOLBAR) lpNMHdr; ! ActionHandle action = getActionHandle(pFrameData->pActionsMap, lpNMToolBar->iItem); ! if (action && action->menu) ! { ! RECT rect; ! int nIndex; ! ! memset(&rect, 0, sizeof(rect)); ! nIndex = SendMessage(lpNMHdr->hwndFrom, TB_COMMANDTOINDEX, action->id, 0); ! SendMessage(lpNMHdr->hwndFrom, TB_GETITEMRECT, nIndex, (LPARAM)&rect); ! MapWindowPoints(lpNMHdr->hwndFrom, NULL, (LPPOINT) &rect, 2); ! ! TrackPopupMenu(action->menu->hMenu, TPM_LEFTALIGN | TPM_TOPALIGN, rect.left, rect.bottom, 0, ghWndFrame, NULL); ! } } + else + if (lpNMHdr->code == TTN_NEEDTEXT) + { + LPNMTTDISPINFO lpNMTTDispInfo = (LPNMTTDISPINFO) lpNMHdr; + + ActionHandle action = getActionHandle(pFrameData->pActionsMap, lpNMHdr->idFrom); + if (action) + lpNMTTDispInfo->lpszText = action->tooltip; + } } break; Index: Frame.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Frame.c,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** Frame.c 8 May 2004 09:46:00 -0000 1.26 --- Frame.c 14 May 2004 23:01:39 -0000 1.27 *************** *** 1,8 **** #include "Types.h" #include "Window.h" - #include "Menu.h" #include "DockBar.h" #include "StatusBar.h" ! #include "MenuHandlesMap.h" #include "Canvas.h" #include "ConfigKey.h" --- 1,8 ---- #include "Types.h" #include "Window.h" #include "DockBar.h" #include "StatusBar.h" ! #include "Action.h" ! #include "ActionsMap.h" #include "Canvas.h" #include "ConfigKey.h" *************** *** 14,24 **** #define Spacing 1 ! void DrawMenuText(HDC hdc, LPTSTR lpchText, LPRECT lpRect) { ! int n = 0; ! while (lpchText[n] && lpchText[n] != '\t') n++; ! DrawText(hdc, lpchText, n, lpRect, DT_SINGLELINE|DT_VCENTER|DT_LEFT); ! DrawText(hdc, lpchText+n+1, -1, lpRect, DT_SINGLELINE|DT_VCENTER|DT_RIGHT); } --- 14,94 ---- #define Spacing 1 ! static void BuildAccelString(ActionHandle action, char *text) { ! *text = 0; ! if (!action || !action->key) ! return; ! ! if (action->keyMods & altBIT ) strcat(text, "Alt+"); ! if (action->keyMods & ctrlBIT ) strcat(text, "Ctrl+"); ! if (action->keyMods & shiftBIT) strcat(text, "Shift+"); ! ! switch (action->key) ! { ! case kbBackSpace: strcat(text, "BackSpace"); break; ! case kbTab: strcat(text, "Tab"); break; ! case kbEnter: strcat(text, "Enter"); break; ! case kbEscape: strcat(text, "Esc"); break; ! case kbBegin: strcat(text, "Home"); break; ! case kbClear: strcat(text, "Clear"); break; ! case kbDelete: strcat(text, "Del"); break; ! case kbDown: strcat(text, "Down"); break; ! case kbEnd: strcat(text, "End"); break; ! case kbF1: strcat(text, "F1"); break; ! case kbF2: strcat(text, "F2"); break; ! case kbF3: strcat(text, "F3"); break; ! case kbF4: strcat(text, "F4"); break; ! case kbF5: strcat(text, "F5"); break; ! case kbF6: strcat(text, "F6"); break; ! case kbF7: strcat(text, "F7"); break; ! case kbF8: strcat(text, "F8"); break; ! case kbF9: strcat(text, "F9"); break; ! case kbF10: strcat(text, "F10"); break; ! case kbF11: strcat(text, "F11"); break; ! case kbF12: strcat(text, "F12"); break; ! case kbF13: strcat(text, "F13"); break; ! case kbF14: strcat(text, "F14"); break; ! case kbF15: strcat(text, "F15"); break; ! case kbHelp: strcat(text, "Help"); break; ! case kbLeft: strcat(text, "Left"); break; ! case kbPgDown: strcat(text, "PgDown"); break; ! case kbPgUp: strcat(text, "PgUp"); break; ! case kbRight: strcat(text, "Right"); break; ! case kbUp: strcat(text, "Up"); break; ! case ' ': strcat(text, "Space"); break; ! default: ! { ! char s[2]; ! ! if (action->key >= 256) ! { ! strcat(text,"Alt+"); ! s[0] = action->key-256; ! } ! ! if (iscntrl(action->key)) ! { ! s[0] = '@'+action->key; ! strcat(text,"Ctrl+"); ! } ! else ! if (isupper(action->key)) strcat(text,"Shift+"); ! else s[0] = toupper(action->key); ! ! s[1] = 0; ! strcat(text, s); ! } ! break; ! } ! } ! ! static void DrawMenuText(HDC hdc, ActionHandle action, LPRECT lpRect) ! { ! char szAccText[32]; ! BuildAccelString(action, szAccText); ! ! DrawText(hdc, action->title, -1, lpRect, DT_SINGLELINE|DT_VCENTER|DT_LEFT); ! DrawText(hdc, szAccText, -1, lpRect, DT_SINGLELINE|DT_VCENTER|DT_RIGHT); } *************** *** 59,66 **** LRESULT CALLBACK HFrameSharedFunction(int DocumentInterface, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { ! int pos; ! HMENU hParent; ! MENUITEMINFO mii; ! MenuHandle handle; FrameData *pData = (FrameData *) GetWindowLong(hWnd,GWL_USERDATA); --- 129,133 ---- LRESULT CALLBACK HFrameSharedFunction(int DocumentInterface, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { ! ActionHandle action; FrameData *pData = (FrameData *) GetWindowLong(hWnd,GWL_USERDATA); *************** *** 72,80 **** return 0; case WM_DESTROY: - notifyAllHandlesForDestroy(pData->pMenuHandlesMap); handleProcessDestroy(); free(pData->lpszAppName); free(pData->lpszAppVersion); ! deleteMenuHandlesMap(pData->pMenuHandlesMap); // clear StatusBar context stack --- 139,146 ---- return 0; case WM_DESTROY: handleProcessDestroy(); free(pData->lpszAppName); free(pData->lpszAppVersion); ! deleteActionsMap(pData->pActionsMap); // clear StatusBar context stack *************** *** 115,119 **** pData->lpszAppName = NULL; pData->lpszAppVersion = NULL; ! pData->pMenuHandlesMap = newMenuHandlesMap(); pData->hLeftBar = CreateWindow("HDOCKBAR", --- 181,185 ---- pData->lpszAppName = NULL; pData->lpszAppVersion = NULL; ! pData->pActionsMap = newActionsMap(); pData->hLeftBar = CreateWindow("HDOCKBAR", *************** *** 171,184 **** case WM_COMMAND: if (lParam == 0) ! { ! handle = getMenuHandle(pData->pMenuHandlesMap, (UINT) LOWORD(wParam)); ! if (handle) ! { ! if (handle->type & (MENU_RADIO_ITEM | MENU_CHECK_ITEM)) ! osSetMenuItemChecked(handle, !osGetMenuItemChecked(handle)); ! else ! handleMenuCommand(handle); ! } ! } break; case WM_MEASUREITEM: --- 237,241 ---- case WM_COMMAND: if (lParam == 0) ! osActivateAction(LOWORD(wParam)); break; case WM_MEASUREITEM: *************** *** 188,201 **** if (lpMIS->CtlType == ODT_MENU) { ! handle = getMenuHandle(pData->pMenuHandlesMap, lpMIS->itemID); ! if (handle && handle->bitmap) { NONCLIENTMETRICS ncm; HFONT hFont, hOldFont; ! RECT rc; HDC hDC; long lDims; WORD wCheckWidth, wCheckHeight; hDC = GetDC(hWnd); --- 245,261 ---- if (lpMIS->CtlType == ODT_MENU) { ! action = getActionHandle(pData->pActionsMap, lpMIS->itemID); ! if (action) { NONCLIENTMETRICS ncm; HFONT hFont, hOldFont; ! RECT rc[2]; HDC hDC; long lDims; WORD wCheckWidth, wCheckHeight; + char szAccText[32]; + + BuildAccelString(action, szAccText); hDC = GetDC(hWnd); *************** *** 213,248 **** // Draw out menu item caption - text. ! pos = getMenuPos(pData->pMenuHandlesMap, handle); ! hParent = getParentHMENU(handle); ! ! ZeroMemory(&mii,sizeof(mii)); ! mii.cbSize = sizeof(mii); ! mii.fMask = MIIM_STRING; ! mii.fType = MFT_STRING; ! mii.dwTypeData = NULL; ! mii.cch = 0; ! GetMenuItemInfo(hParent, pos, TRUE, &mii); ! mii.cch++; ! mii.dwTypeData = malloc(mii.cch); ! ! if (mii.dwTypeData) ! { ! GetMenuItemInfo(hParent, pos, TRUE, &mii); ! ! ZeroMemory(&rc,sizeof(rc)); ! DrawText(hDC,mii.dwTypeData,mii.cch,&rc,DT_SINGLELINE|DT_VCENTER|DT_LEFT|DT_CALCRECT); ! lDims = GetMenuCheckMarkDimensions(); ! wCheckWidth = (WORD)(LOWORD(lDims)+Spacing); ! wCheckHeight = (WORD)(HIWORD(lDims)+Spacing); ! wCheckWidth = (WORD)max(handle->bitmap->destsize.cx, wCheckWidth); ! wCheckHeight = (WORD)max(handle->bitmap->destsize.cy, wCheckHeight); ! lpMIS->itemWidth = (rc.right-rc.left) + wCheckWidth + (Spacing*3); // Text width ! lpMIS->itemHeight = max((rc.bottom-rc.top),wCheckHeight) + (Spacing*2); // Text Height } ! free(mii.dwTypeData); // Clean up resources --- 273,296 ---- // Draw out menu item caption - text. ! ZeroMemory(&rc,sizeof(rc)); ! DrawText(hDC,action->title,-1,&rc[0],DT_SINGLELINE|DT_VCENTER|DT_LEFT|DT_CALCRECT); ! DrawText(hDC,szAccText, -1,&rc[1],DT_SINGLELINE|DT_VCENTER|DT_LEFT|DT_CALCRECT); ! rc[0].right += rc[1].right-rc[1].left; ! rc[0].bottom = max(rc[0].bottom, rc[1].bottom); ! lDims = GetMenuCheckMarkDimensions(); ! wCheckWidth = (WORD)(LOWORD(lDims)+Spacing); ! wCheckHeight = (WORD)(HIWORD(lDims)+Spacing); ! if (action->bitmap) ! { ! wCheckWidth = (WORD)max(action->bitmap->destsize.cx, wCheckWidth); ! wCheckHeight = (WORD)max(action->bitmap->destsize.cy, wCheckHeight); } ! lpMIS->itemWidth = (rc[0].right-rc[0].left) + wCheckWidth + (Spacing*3); // Text width ! lpMIS->itemHeight = max((rc[0].bottom-rc[0].top),wCheckHeight) + (Spacing*2); // Text Height ! // Clean up resources *************** *** 260,266 **** if (lpDIS->CtlType == ODT_MENU) { ! handle = getMenuHandle(pData->pMenuHandlesMap, lpDIS->itemID); ! if (handle && handle->bitmap) { long lDims; --- 308,314 ---- if (lpDIS->CtlType == ODT_MENU) { ! action = getActionHandle(pData->pActionsMap, lpDIS->itemID); ! if (action) { long lDims; *************** *** 280,285 **** wCheckHeight = HIWORD(lDims); ! wWidth = max(handle->bitmap->destsize.cx, wCheckWidth) + (Spacing*2); ! wHeight = max(handle->bitmap->destsize.cy, wCheckHeight) + (Spacing*2); rcFrame.left = lpDIS->rcItem.left; --- 328,336 ---- wCheckHeight = HIWORD(lDims); ! wWidth = (action->bitmap) ? action->bitmap->destsize.cx : 0; ! wHeight = (action->bitmap) ? action->bitmap->destsize.cy : 0; ! ! wWidth = max(wWidth, wCheckWidth) + (Spacing*2); ! wHeight = max(wHeight, wCheckHeight) + (Spacing*2); rcFrame.left = lpDIS->rcItem.left; *************** *** 323,380 **** // Draw out the bitmap associated with the menu item. ! pt.x = rcFrame.left+(((rcFrame.right-rcFrame.left) - handle->bitmap->destsize.cx)/2); ! pt.y = rcFrame.top +(((rcFrame.bottom-rcFrame.top) - handle->bitmap->destsize.cy)/2); ! osDrawBitmap(pt.x, pt.y, handle->bitmap, &canvas); ! // Draw bounding frame ! if (lpDIS->itemState & ODS_SELECTED) DrawEdge(lpDIS->hDC,&rcFrame,BDR_RAISEDINNER,BF_RECT); rc.left+=Spacing; ! // Draw out menu item caption - text. ! pos = getMenuPos(pData->pMenuHandlesMap, handle); ! hParent = getParentHMENU(handle); ! ! ZeroMemory(&mii,sizeof(mii)); ! mii.cbSize = sizeof(mii); ! mii.fMask = MIIM_STRING; ! mii.fType = MFT_STRING; ! mii.dwTypeData = NULL; ! mii.cch = 0; ! GetMenuItemInfo(hParent, pos, TRUE, &mii); ! mii.cch++; ! mii.dwTypeData = malloc(mii.cch); ! ! if (mii.dwTypeData) { ! GetMenuItemInfo(hParent, pos, TRUE, &mii); ! ! if (lpDIS->itemState & ODS_GRAYED) { ! // This will give it a disable text look ! if (!(lpDIS->itemState & ODS_SELECTED)) ! { ! SetTextColor(lpDIS->hDC, GetSysColor(COLOR_3DHILIGHT)); ! OffsetRect(&rc,1,1); ! DrawMenuText(lpDIS->hDC,mii.dwTypeData,&rc); ! OffsetRect(&rc,-1,-1); ! ! SetTextColor(lpDIS->hDC,GetSysColor(COLOR_GRAYTEXT)); ! DrawMenuText(lpDIS->hDC,mii.dwTypeData,&rc); ! } ! else ! { ! COLORREF crGray = (GetSysColor(COLOR_GRAYTEXT) + RGB(64,64,64)); ! SetTextColor(lpDIS->hDC,crGray); ! DrawMenuText(lpDIS->hDC,mii.dwTypeData,&rc); ! } } else ! DrawMenuText(lpDIS->hDC,mii.dwTypeData,&rc); } - free(mii.dwTypeData); RestoreDC(lpDIS->hDC,nIndexDC); --- 374,411 ---- // Draw out the bitmap associated with the menu item. ! if (action->bitmap) ! { ! pt.x = rcFrame.left+(((rcFrame.right-rcFrame.left) - action->bitmap->destsize.cx)/2); ! pt.y = rcFrame.top +(((rcFrame.bottom-rcFrame.top) - action->bitmap->destsize.cy)/2); ! osDrawBitmap(pt.x, pt.y, action->bitmap, &canvas); ! ! // Draw bounding frame ! if (lpDIS->itemState & ODS_SELECTED) DrawEdge(lpDIS->hDC,&rcFrame,BDR_RAISEDINNER,BF_RECT); + } rc.left+=Spacing; ! if (lpDIS->itemState & ODS_GRAYED) { ! // This will give it a disable text look ! if (!(lpDIS->itemState & ODS_SELECTED)) { ! SetTextColor(lpDIS->hDC, GetSysColor(COLOR_3DHILIGHT)); ! OffsetRect(&rc,1,1); ! DrawMenuText(lpDIS->hDC,action,&rc); ! OffsetRect(&rc,-1,-1); ! SetTextColor(lpDIS->hDC,GetSysColor(COLOR_GRAYTEXT)); } else ! { ! COLORREF crGray = (GetSysColor(COLOR_GRAYTEXT) + RGB(64,64,64)); ! SetTextColor(lpDIS->hDC,crGray); ! } } + DrawMenuText(lpDIS->hDC,action,&rc); RestoreDC(lpDIS->hDC,nIndexDC); *************** *** 383,411 **** } return TRUE; - case WM_INITMENUPOPUP: - { - HMENU hMenu; - int i, nCount; - - hMenu = (HMENU) wParam; - nCount = GetMenuItemCount((HMENU) wParam); - for (i = 0; i < nCount; i++) - { - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_ID; - GetMenuItemInfo(hMenu, i, TRUE, &mii); - - handle = getMenuHandle(pData->pMenuHandlesMap, (UINT) mii.wID); - if (handle) handleMenuUpdate(handle); - } - } - break; case WM_MENUSELECT: if ((HIWORD(wParam) & MF_POPUP) == 0) { ! handle = getMenuHandle(pData->pMenuHandlesMap, (UINT) LOWORD(wParam)); ! if (handle) { ! SetWindowText(pData->hStatusBar, handle->tip ? handle->tip : ""); } } --- 414,424 ---- } return TRUE; case WM_MENUSELECT: if ((HIWORD(wParam) & MF_POPUP) == 0) { ! action = getActionHandle(pData->pActionsMap, (UINT) LOWORD(wParam)); ! if (action) { ! SetWindowText(pData->hStatusBar, action->tooltip ? action->tooltip : ""); } } Index: Internals.h =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Internals.h,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Internals.h 7 May 2004 14:23:48 -0000 1.21 --- Internals.h 14 May 2004 23:01:39 -0000 1.22 *************** *** 4,8 **** #include <config.h> ! #include "MenuHandlesMap.h" extern BOOL gInKey; --- 4,8 ---- #include <config.h> ! #include "ActionsMap.h" extern BOOL gInKey; *************** *** 29,33 **** LPSTR lpszAppName; LPSTR lpszAppVersion; ! MenuHandlesMap *pMenuHandlesMap; HWND hLeftBar, hTopBar, hRightBar, hBottomBar; --- 29,33 ---- LPSTR lpszAppName; LPSTR lpszAppVersion; ! ActionsMap *pActionsMap; HWND hLeftBar, hTopBar, hRightBar, hBottomBar; *************** *** 62,66 **** } WindowData; - extern void rfree(void *ptr); extern void *rmalloc(unsigned long bytes); --- 62,65 ---- *************** *** 75,77 **** --- 74,78 ---- void RestoreWindowState(HWND hWnd, int nShow); + void osActivateAction(int id); + #endif Index: Menu.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Menu.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Menu.c 15 Nov 2003 10:31:49 -0000 1.19 --- Menu.c 14 May 2004 23:01:39 -0000 1.20 *************** *** 12,16 **** return ret; \ } ! #define CHECK_MENU_TYPE_V(handle,mask) \ if (((handle ? handle->type : MENU_SUBMENU) & (mask)) == 0) \ --- 12,16 ---- return ret; \ } ! #define CHECK_MENU_TYPE_V(handle,mask) \ if (((handle ? handle->type : MENU_SUBMENU) & (mask)) == 0) \ *************** *** 20,94 **** } - static void AddAccelString(int nKeyCode, int mods, char *text) - { - if (!nKeyCode) - return; - - strcat(text, "\t"); - - if (mods & altBIT ) strcat(text, "Alt+"); - if (mods & ctrlBIT ) strcat(text, "Ctrl+"); - if (mods & shiftBIT) strcat(text, "Shift+"); - - switch (nKeyCode) - { - case kbBackSpace: strcat(text, "BackSpace"); break; - case kbTab: strcat(text, "Tab"); break; - case kbEnter: strcat(text, "Enter"); break; - case kbEscape: strcat(text, "Esc"); break; - case kbBegin: strcat(text, "Home"); break; - case kbClear: strcat(text, "Clear"); break; - case kbDelete: strcat(text, "Del"); break; - case kbDown: strcat(text, "Down"); break; - case kbEnd: strcat(text, "End"); break; - case kbF1: strcat(text, "F1"); break; - case kbF2: strcat(text, "F2"); break; - case kbF3: strcat(text, "F3"); break; - case kbF4: strcat(text, "F4"); break; - case kbF5: strcat(text, "F5"); break; - case kbF6: strcat(text, "F6"); break; - case kbF7: strcat(text, "F7"); break; - case kbF8: strcat(text, "F8"); break; - case kbF9: strcat(text, "F9"); break; - case kbF10: strcat(text, "F10"); break; - case kbF11: strcat(text, "F11"); break; - case kbF12: strcat(text, "F12"); break; - case kbF13: strcat(text, "F13"); break; - case kbF14: strcat(text, "F14"); break; - case kbF15: strcat(text, "F15"); break; - case kbHelp: strcat(text, "Help"); break; - case kbLeft: strcat(text, "Left"); break; - case kbPgDown: strcat(text, "PgDown"); break; - case kbPgUp: strcat(text, "PgUp"); break; - case kbRight: strcat(text, "Right"); break; - case kbUp: strcat(text, "Up"); break; - case ' ': strcat(text, "Space"); break; - default: - { - char s[2]; - - if (nKeyCode >= 256) - { - strcat(text,"Alt+"); - nKeyCode -= 256; - } - - if (iscntrl(nKeyCode)) - { - nKeyCode += '@'; - strcat(text,"Ctrl+"); - } - else - if (isupper(nKeyCode)) strcat(text,"Shift+"); - else nKeyCode = toupper(nKeyCode); - - s[0] = (char) nKeyCode; - s[1] = 0; - strcat(text, s); - } - break; - } - } - static void updateMenuBar(MenuHandle parent) { --- 20,23 ---- *************** *** 101,110 **** MenuHandle osCreatePopupMenu() ! { MenuHandle handle; FrameData *pFrameData; ! pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! handle = newMenuHandle(pFrameData->pMenuHandlesMap, NULL, MENU_POPUP, -1); if (handle) --- 30,39 ---- MenuHandle osCreatePopupMenu() ! { MenuHandle handle; FrameData *pFrameData; ! pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! handle = newMenuHandle(pFrameData->pActionsMap, NULL, -1, MENU_POPUP, NULL); if (handle) *************** *** 117,124 **** { POINT pos; - int i, nCount; - MenuHandle handle; - MENUITEMINFO mii; - FrameData *pData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); pos.x = x; --- 46,49 ---- *************** *** 126,158 **** ClientToScreen(hWnd, &pos); - nCount = GetMenuItemCount(menu->hMenu); - for (i = 0; i < nCount; i++) - { - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_ID; - GetMenuItemInfo(menu->hMenu, i, TRUE, &mii); - - handle = getMenuHandle(pData->pMenuHandlesMap, (UINT) mii.wID); - if (handle) handleMenuUpdate(handle); - } - TrackPopupMenu(menu->hMenu, TPM_LEFTALIGN | TPM_TOPALIGN, pos.x, pos.y, 0, ghWndFrame, NULL); } MenuHandle osInsertMenu(MenuHandle parent, int pos) ! { MenuHandle handle; FrameData *pFrameData; ! CHECK_MENU_TYPE(parent, MENU_SUBMENU | MENU_POPUP, NULL); ! pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! handle = newMenuHandle(pFrameData->pMenuHandlesMap, parent, MENU_SUBMENU, pos); ! if (handle) { handle->hMenu = CreateMenu(); ! InsertMenu(getParentHMENU(handle),getMenuPos(pFrameData->pMenuHandlesMap, handle),MF_BYPOSITION | MF_POPUP,(UINT)handle->hMenu,""); updateMenuBar(parent); --- 51,72 ---- ClientToScreen(hWnd, &pos); TrackPopupMenu(menu->hMenu, TPM_LEFTALIGN | TPM_TOPALIGN, pos.x, pos.y, 0, ghWndFrame, NULL); } MenuHandle osInsertMenu(MenuHandle parent, int pos) ! { MenuHandle handle; FrameData *pFrameData; ! CHECK_MENU_TYPE(parent, MENU_SUBMENU | MENU_POPUP, NULL); ! pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! handle = newMenuHandle(pFrameData->pActionsMap, parent, pos, MENU_SUBMENU, NULL); ! if (handle) { handle->hMenu = CreateMenu(); ! InsertMenu(getParentHMENU(handle),getMenuPos(pFrameData->pActionsMap, handle),MF_BYPOSITION | MF_POPUP,(UINT)handle->hMenu,""); updateMenuBar(parent); *************** *** 162,272 **** }; ! MenuHandle osInsertMenuItem(MenuHandle parent, int pos) { MenuHandle handle; FrameData *pFrameData; - - CHECK_MENU_TYPE(parent, MENU_SUBMENU | MENU_POPUP, NULL); - - pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); - handle = newMenuHandle(pFrameData->pMenuHandlesMap, parent, MENU_ITEM, pos); - - if (handle) - { - InsertMenu(getParentHMENU(handle),getMenuPos(pFrameData->pMenuHandlesMap, handle),MF_BYPOSITION | MF_STRING,handle->id,""); - updateMenuBar(parent); - } - - return handle; - }; - MenuHandle osInsertMenuCheckItem(MenuHandle parent, int pos) - { - MenuHandle handle; - FrameData *pFrameData; - CHECK_MENU_TYPE(parent, MENU_SUBMENU | MENU_POPUP, NULL); ! pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! handle = newMenuHandle(pFrameData->pMenuHandlesMap, parent, MENU_CHECK_ITEM, pos); ! ! if (handle) { ! InsertMenu(getParentHMENU(handle),getMenuPos(pFrameData->pMenuHandlesMap, handle),MF_BYPOSITION | MF_STRING,handle->id,""); ! updateMenuBar(parent); } ! return handle; }; MenuHandle osInsertMenuSeparatorItem(MenuHandle parent, int pos) { MenuHandle handle; FrameData *pFrameData; - - CHECK_MENU_TYPE(parent, MENU_SUBMENU | MENU_POPUP, NULL); - - pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); - handle = newMenuHandle(pFrameData->pMenuHandlesMap, parent, MENU_SEPARATOR, pos); - - if (handle) - { - InsertMenu(getParentHMENU(handle),getMenuPos(pFrameData->pMenuHandlesMap, handle),MF_BYPOSITION | MF_SEPARATOR,0,NULL); - updateMenuBar(parent); - } - - return handle; - } - MenuHandle osInsertMenuRadioItem(MenuHandle parent, int pos) - { - MenuHandle handle; - FrameData *pFrameData; - MENUITEMINFO mii; - CHECK_MENU_TYPE(parent, MENU_SUBMENU | MENU_POPUP, NULL); pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! handle = newMenuHandle(pFrameData->pMenuHandlesMap, parent, MENU_RADIO_ITEM, pos); 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 | MFT_STRING; ! mii.dwTypeData = ""; ! mii.cch = 0; ! InsertMenuItem(getParentHMENU(handle),getMenuPos(pFrameData->pMenuHandlesMap, handle),TRUE,&mii); updateMenuBar(parent); } - return handle; - }; - - void osSetMenuRadioGroup(MenuHandle *handles) - { - MenuHandle child, handle, *phandle; - - if (!(handles && *handles)) - return; ! 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; ! } ! } } --- 76,139 ---- }; ! MenuHandle osInsertMenuItem(ActionHandle action, MenuHandle parent, int pos) { + MENUITEMINFO mii; MenuHandle handle; FrameData *pFrameData; CHECK_MENU_TYPE(parent, MENU_SUBMENU | MENU_POPUP, NULL); ! pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! ! mii.cbSize = sizeof(mii); ! mii.fMask = MIIM_ID | MIIM_STATE | MIIM_TYPE; ! mii.wID = action->id; ! mii.fState = action->enabled ? MFS_ENABLED : MFS_DISABLED; ! mii.fType = MFT_OWNERDRAW; ! ! handle = NULL; ! switch (action->type) { ! case ACTION_NORMAL: ! handle = newMenuHandle(pFrameData->pActionsMap, parent, pos, MENU_ITEM, action); ! break; ! case ACTION_CHECK: ! handle = newMenuHandle(pFrameData->pActionsMap, parent, pos, MENU_CHECK_ITEM, action); ! break; ! case ACTION_RADIO: ! handle = newMenuHandle(pFrameData->pActionsMap, parent, pos, MENU_RADIO_ITEM, action); ! mii.fType |= MFT_RADIOCHECK; ! break; ! case ACTION_DROPDOWN: ! handle = newMenuHandle(pFrameData->pActionsMap, parent, pos, MENU_SUBMENU, action); ! mii.fMask |= MIIM_SUBMENU; ! mii.hSubMenu = action->menu->hMenu; ! break; } ! ! InsertMenuItem(getParentHMENU(handle),getMenuPos(pFrameData->pActionsMap, handle),TRUE,&mii); ! ! updateMenuBar(parent); return handle; }; + MenuHandle osInsertMenuSeparatorItem(MenuHandle parent, int pos) { MenuHandle handle; FrameData *pFrameData; CHECK_MENU_TYPE(parent, MENU_SUBMENU | MENU_POPUP, NULL); + pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! handle = newMenuHandle(pFrameData->pActionsMap, parent, pos, MENU_SEPARATOR, NULL); ! if (handle) { ! InsertMenu(getParentHMENU(handle),getMenuPos(pFrameData->pActionsMap, handle),MF_BYPOSITION | MF_SEPARATOR,0,NULL); updateMenuBar(parent); } ! return handle; } *************** *** 275,287 **** FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); - notifyHandleForDestroy(handle); - if (handle->type != MENU_POPUP) { ! DeleteMenu(getParentHMENU(handle), getMenuPos(pFrameData->pMenuHandlesMap, handle), MF_BYPOSITION); updateMenuBar(handle->parent); } ! deleteMenuHandle(pFrameData->pMenuHandlesMap, handle); } --- 142,152 ---- FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); if (handle->type != MENU_POPUP) { ! DeleteMenu(getParentHMENU(handle), getMenuPos(pFrameData->pActionsMap, handle), MF_BYPOSITION); updateMenuBar(handle->parent); } ! deleteMenuHandle(pFrameData->pActionsMap, handle); } *************** *** 289,298 **** { FrameData *pFrameData; ! CHECK_MENU_TYPE(handle, MENU_SUBMENU | MENU_POPUP, 0); ! pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! ! return getChildrenCount(pFrameData->pMenuHandlesMap, handle); } --- 154,163 ---- { FrameData *pFrameData; ! CHECK_MENU_TYPE(handle, MENU_SUBMENU | MENU_POPUP, 0); ! pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! ! return getChildrenCount(pFrameData->pActionsMap, handle); } *************** *** 307,311 **** pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! EnableMenuItem(getParentHMENU(handle), getMenuPos(pFrameData->pMenuHandlesMap, handle), (bState ? MF_ENABLED : MF_GRAYED) | MF_BYPOSITION); updateMenuBar(handle->parent); } --- 172,176 ---- pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! EnableMenuItem(getParentHMENU(handle), getMenuPos(pFrameData->pActionsMap, handle), (bState ? MF_ENABLED : MF_GRAYED) | MF_BYPOSITION); updateMenuBar(handle->parent); } *************** *** 321,329 **** CHECK_MENU_TYPE(handle, MENU_RADIO_ITEM | MENU_CHECK_ITEM | MENU_ITEM | MENU_SUBMENU, FALSE); ! pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); mii.cbSize = sizeof(mii); mii.fMask = MIIM_STATE; ! GetMenuItemInfo(getParentHMENU(handle), getMenuPos(pFrameData->pMenuHandlesMap, handle), TRUE, &mii); return (mii.fState & MFS_DISABLED) == 0; } --- 186,194 ---- CHECK_MENU_TYPE(handle, MENU_RADIO_ITEM | MENU_CHECK_ITEM | MENU_ITEM | MENU_SUBMENU, FALSE); ! pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); mii.cbSize = sizeof(mii); mii.fMask = MIIM_STATE; ! GetMenuItemInfo(getParentHMENU(handle), getMenuPos(pFrameData->pActionsMap, handle), TRUE, &mii); return (mii.fState & MFS_DISABLED) == 0; } *************** *** 332,378 **** }; - void osSetMenuItemChecked(MenuHandle handle, BOOL bState) - { - 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); - - handleMenuCommand(handle); - }; - - BOOL osGetMenuItemChecked(MenuHandle handle) - { - MENUITEMINFO mii; - FrameData *pFrameData; - - CHECK_MENU_TYPE(handle, MENU_CHECK_ITEM | MENU_RADIO_ITEM, FALSE); - - pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); - - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_STATE; - GetMenuItemInfo(getParentHMENU(handle), getMenuPos(pFrameData->pMenuHandlesMap, handle), TRUE, &mii); - return (mii.fState & MFS_CHECKED) != 0; - } - char *osGetMenuLabel(MenuHandle handle) { --- 197,200 ---- *************** *** 388,392 **** pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! pos = getMenuPos(pFrameData->pMenuHandlesMap, handle); hParent = getParentHMENU(handle); --- 210,214 ---- pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! pos = getMenuPos(pFrameData->pActionsMap, handle); hParent = getParentHMENU(handle); *************** *** 420,424 **** if (handle->type != MENU_POPUP) { - char *s, *temp; MENUITEMINFO mii; FrameData *pFrameData; --- 242,245 ---- *************** *** 428,559 **** pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); - if (handle->parent == NULL) - temp = title; - else - { - temp = malloc(strlen(title)+32); - if (!temp) - temp = title; - else - { - s = temp; - while (*title) - { - if (*title != '\t') *s++ = *title; - title++; - } - *s = 0; - AddAccelString(handle->key, handle->mods, temp); - } - } - - memset(&mii,0,sizeof(mii)); - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_STRING; - mii.fType = MFT_STRING; - mii.dwTypeData = temp; - mii.cch = strlen(temp); - SetMenuItemInfo(getParentHMENU(handle), getMenuPos(pFrameData->pMenuHandlesMap, handle), TRUE, &mii); - - updateMenuBar(handle->parent); - - if (temp != title) free(temp); - } - } - - char *osGetMenuTip(MenuHandle handle) - { - CHECK_MENU_TYPE(handle, MENU_RADIO_ITEM | MENU_CHECK_ITEM | MENU_ITEM, NULL); - return handle->tip; - } - - void osSetMenuTip(MenuHandle handle, char *tip) - { - CHECK_MENU_TYPE_V(handle, MENU_RADIO_ITEM | MENU_CHECK_ITEM | MENU_ITEM); - - if (handle->tip) - free(handle->tip); - - handle->tip = strdup(tip); - } - - void osSetMenuItemAccel(MenuHandle handle, int key, unsigned int mods) - { - int pos; - HMENU hParent; - char *s; - MENUITEMINFO mii; - FrameData *pFrameData; - - CHECK_MENU_TYPE_V(handle, MENU_RADIO_ITEM | MENU_CHECK_ITEM | MENU_ITEM); - - pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); - pos = getMenuPos(pFrameData->pMenuHandlesMap, handle); - hParent = getParentHMENU(handle); - - updateAccelTable(pFrameData->pMenuHandlesMap, handle, key, mods); - - if (handle->parent != NULL) - { memset(&mii,0,sizeof(mii)); mii.cbSize = sizeof(mii); mii.fMask = MIIM_STRING; mii.fType = MFT_STRING; ! mii.dwTypeData = NULL; ! mii.cch = 0; ! GetMenuItemInfo(hParent, pos, TRUE, &mii); ! mii.dwTypeData = malloc(mii.cch+32); ! ! if (!mii.dwTypeData) ! return; ! ! mii.cch++; ! GetMenuItemInfo(hParent, pos, TRUE, &mii); ! ! s = mii.dwTypeData; ! while (*s && *s != '\t') s++; ! *s = 0; ! ! AddAccelString(key, mods, s); ! ! mii.cch = strlen(mii.dwTypeData); ! SetMenuItemInfo(hParent, pos, TRUE, &mii); updateMenuBar(handle->parent); - - free(mii.dwTypeData); } } - void osGetMenuItemAccel(MenuHandle handle, int *key, unsigned int *mods) - { - CHECK_MENU_TYPE_V(handle, MENU_RADIO_ITEM | MENU_CHECK_ITEM | MENU_ITEM); - - *key = handle->key; - *mods = handle->mods; - } - - void osSetMenuItemBitmap(MenuHandle handle, BitmapHandle bitmap) - { - MENUITEMINFO mii; - FrameData *pFrameData; - - CHECK_MENU_TYPE_V(handle, MENU_ITEM); - - pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); - handle->bitmap = bitmap; - - memset(&mii,0,sizeof(mii)); - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_FTYPE; - mii.fType = bitmap ? MFT_OWNERDRAW : MFT_STRING; - SetMenuItemInfo(getParentHMENU(handle), getMenuPos(pFrameData->pMenuHandlesMap, handle), TRUE, &mii); - - updateMenuBar(handle->parent); - } - int osGetMenuItemPos(MenuHandle handle) { FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! return getMenuPos(pFrameData->pMenuHandlesMap, handle); } --- 249,267 ---- pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); memset(&mii,0,sizeof(mii)); mii.cbSize = sizeof(mii); mii.fMask = MIIM_STRING; mii.fType = MFT_STRING; ! mii.dwTypeData = title; ! mii.cch = strlen(title); ! SetMenuItemInfo(getParentHMENU(handle), getMenuPos(pFrameData->pActionsMap, handle), TRUE, &mii); updateMenuBar(handle->parent); } } int osGetMenuItemPos(MenuHandle handle) { FrameData *pFrameData = (FrameData *) GetWindowLong(ghWndFrame,GWL_USERDATA); ! return getMenuPos(pFrameData->pActionsMap, handle); } Index: ToolBar.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/ToolBar.c,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** ToolBar.c 7 May 2004 14:44:50 -0000 1.20 --- ToolBar.c 14 May 2004 23:01:41 -0000 1.21 *************** *** 18,41 **** WNDPROC DefToolBarProc = NULL; - static int nNextToolButtonID = 0; - - enum TOOL_TYPE - { TOOL_SUBMENU = 1 - , TOOL_SEPARATOR = 2 - , TOOL_ITEM = 4 - , TOOL_CHECK_ITEM = 8 - , TOOL_RADIO_ITEM = 16 - }; - - struct ToolHandle - { - int nCommand; - HWND hToolBar; - BitmapHandle bitmap; - enum TOOL_TYPE type; - ToolHandle nextInGroup; - MenuHandle menu; - }; - //////////////////////////////////////////// // Drawing & GDI utilities --- 18,21 ---- *************** *** 817,821 **** } ! ToolHandle osInsertToolButton(WindowHandle toolBar, int pos) { TBBUTTON tbb; --- 797,801 ---- } ! ToolHandle osInsertToolButton(ActionHandle action, WindowHandle toolBar, int pos) { TBBUTTON tbb; *************** *** 825,962 **** if (!btn) return NULL; - btn->nCommand = ++nNextToolButtonID; btn->hToolBar = toolBar; ! btn->menu = NULL; ! btn->bitmap = NULL; ! btn->type = TOOL_ITEM; ! btn->nextInGroup = btn; ! ! tbb.iBitmap = I_IMAGENONE; ! tbb.idCommand = btn->nCommand; ! tbb.fsState = TBSTATE_ENABLED; ! tbb.fsStyle = TBSTYLE_BUTTON; ! tbb.dwData = (DWORD)btn; ! tbb.iString = 0; ! ! if (pos > 0) ! SendMessage(toolBar,TB_INSERTBUTTON,pos,(LPARAM)&tbb); ! else ! SendMessage(toolBar,TB_ADDBUTTONS, 1, (LPARAM)&tbb); ! ! RelayoutFrameBars(); ! return btn; ! } ! ! ToolHandle osInsertToolCheckButton(WindowHandle toolBar, int pos) ! { ! TBBUTTON tbb; ! ToolHandle btn; ! ! btn = malloc(sizeof(struct ToolHandle)); ! if (!btn) return NULL; ! btn->nCommand = ++nNextToolButtonID; ! btn->hToolBar = toolBar; ! btn->menu = NULL; ! btn->bitmap = NULL; ! btn->type = TOOL_CHECK_ITEM; ! btn->nextInGroup = btn; ! tbb.iBitmap = I_IMAGENONE; ! tbb.idCommand = btn->nCommand; ! tbb.fsState = TBSTATE_ENABLED; ! tbb.fsStyle = TBSTYLE_BUTTON | TBSTYLE_CHECK; ! tbb.dwData = (DWORD)btn; ! tbb.iString = 0; ! if (pos > 0) ! SendMessage(toolBar,TB_INSERTBUTTON,pos,(LPARAM)&tbb); else ! SendMessage(toolBar,TB_ADDBUTTONS, 1, (LPARAM)&tbb); ! ! RelayoutFrameBars(); ! return btn; ! } ! ! ToolHandle osInsertToolRadioButton(WindowHandle toolBar, int pos) ! { ! TBBUTTON tbb; ! ToolHandle btn; ! ! btn = malloc(sizeof(struct ToolHandle)); ! if (!btn) return NULL; ! ! btn->nCommand = ++nNextToolButtonID; ! btn->hToolBar = toolBar; ! btn->menu = NULL; ! btn->bitmap = NULL; ! btn->type = TOOL_RADIO_ITEM; ! btn->nextInGroup = btn; ! tbb.iBitmap = I_IMAGENONE; ! tbb.idCommand = btn->nCommand; ! tbb.fsState = TBSTATE_ENABLED; ! tbb.fsStyle = TBSTYLE_BUTTON; tbb.dwData = (DWORD)btn; tbb.iString = 0; ! if (pos > 0) ! SendMessage(toolBar,TB_INSERTBUTTON,pos,(LPARAM)&tbb); ! else ! SendMessage(toolBar,TB_ADDBUTTONS, 1, (LPARAM)&tbb); ! ! RelayoutFrameBars(); ! return btn; ! } ! ! void osSetToolRadioGroup(ToolHandle *handles) ! { ! ToolHandle next, handle, *phandle; ! ! if (!(handles && *handles)) ! return; ! ! phandle=handles; ! for (;;) { ! handle = *phandle; ! ! next = handle->nextInGroup; ! while (next->nextInGroup != handle) ! next = next->nextInGroup; ! next->nextInGroup = handle->nextInGroup; ! ! phandle++; ! if (*phandle) ! handle->nextInGroup = *phandle; ! else ! { ! handle->nextInGroup = *handles; break; - } } - } - - ToolHandle osInsertToolDropDownButton(WindowHandle toolBar, MenuHandle hmenu, int pos) - { - TBBUTTON tbb; - ToolHandle btn; - - btn = malloc(sizeof(struct ToolHandle)); - if (!btn) return NULL; - - btn->nCommand = ++nNextToolButtonID; - btn->hToolBar = toolBar; - btn->menu = hmenu; - btn->bitmap = NULL; - btn->type = TOOL_SUBMENU; - btn->nextInGroup = btn; - - tbb.iBitmap = I_IMAGENONE; - tbb.idCommand = btn->nCommand; - tbb.fsState = TBSTATE_ENABLED; - tbb.fsStyle = TBSTYLE_BUTTON | BTNS_WHOLEDROPDOWN; - tbb.dwData = (DWORD)btn; - tbb.iString = 0; if (pos > 0) --- 805,848 ---- if (!btn) return NULL; btn->hToolBar = toolBar; ! btn->action = action; ! // link the button to the chain ! btn->nextInAction = action->toolProxies; ! action->toolProxies = btn; ! TBADDBITMAP tbab; ! if (action->bitmap) ! { ! tbab.hInst = NULL; ! tbab.nID = (UINT) action->bitmap->hBitmap; ! tbb.iBitmap = SendMessage(toolBar, TB_ADDBITMAP, 1, (LPARAM) &tbab); ! } else ! { ! tbb.iBitmap = I_IMAGENONE; ! } ! tbb.idCommand = action->id; ! tbb.fsState = action->enabled ? TBSTATE_ENABLED : 0; tbb.dwData = (DWORD)btn; tbb.iString = 0; ! switch (btn->action->type) { ! case ACTION_NORMAL: ! tbb.fsStyle = TBSTYLE_BUTTON; ! break; ! case ACTION_CHECK: ! tbb.fsStyle = TBSTYLE_BUTTON | TBSTYLE_CHECK; ! break; ! case ACTION_RADIO: ! tbb.fsStyle = TBSTYLE_BUTTON; ! break; ! case ACTION_DROPDOWN: ! tbb.fsStyle = TBSTYLE_BUTTON | BTNS_WHOLEDROPDOWN; break; } if (pos > 0) *************** *** 969,1000 **** } - void osActivateToolItem(ToolHandle toolButton) - { - switch (toolButton->type) - { - case TOOL_RADIO_ITEM: - osSetToolButtonChecked(toolButton, TRUE); - break; - case TOOL_SUBMENU: - { - RECT rect; - int nBtnPos; - - memset(&rect, 0, sizeof(rect)); - nBtnPos = SendMessage(toolButton->hToolBar, TB_COMMANDTOINDEX, toolButton->nCommand, 0); - SendMessage(toolButton->hToolBar, TB_GETITEMRECT, nBtnPos, (LPARAM)&rect); - - ClientToScreen(toolButton->hToolBar, ((POINT *) &rect)); - ClientToScreen(toolButton->hToolBar, ((POINT *) &rect)+1); - - TrackPopupMenu(toolButton->menu->hMenu, TPM_LEFTALIGN | TPM_TOPALIGN, rect.left, rect.bottom, 0, ghWndFrame, NULL); - } - break; - default: - handleToolCommand(toolButton)... [truncated message content] |