From 912816177b589b0f6133ac5731b16a48463447b2 Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Fri, 28 Sep 2007 23:36:57 +0000 Subject: [PATCH] pull up r19856 from trunk r19856@cathode-dark-space: jaltman | 2007-08-24 10:29:37 -0400 ticket: new subject: NIM: Context menu selection issues component: windows The handler for WM_CONTEXTMENU in the credentials view of Network Identity Manager assumed that the context menu was invoked using the mouse. If it was, then the message parameters would specify the x and y co-ordinates of the mouse. The context menu can also be invoked via the keyboard, in which case the x- and y- coordinates are set to (-1,-1). An additional problem with the code is that it was not selecting the row that was right-clicked on if it was not already selected. This results in the some of the commands on the context menu targetting credentials that the user didn't intend to target. This patch adds support for handling the context menu when it is invoked via the keyboard and also sets the selection to the row that was right-clicked if the user invokes the context menu using the mouse. ticket: 5677 version_fixed: 1.6.3 git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-6@19991 dc483132-0cff-0310-8789-dd5450dbe970 --- src/windows/identity/ui/credwnd.c | 55 ++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/src/windows/identity/ui/credwnd.c b/src/windows/identity/ui/credwnd.c index b8d159ac4..62c69668c 100644 --- a/src/windows/identity/ui/credwnd.c +++ b/src/windows/identity/ui/credwnd.c @@ -5406,6 +5406,33 @@ cw_wm_contextmenu(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) x = GET_X_LPARAM(lParam); y = GET_Y_LPARAM(lParam); + /* if the user invokes the context menu using the keyboard, we get + x=-1 and y=-1. In this case, we use the cursor_row as the + target row. */ + if (x == -1 && y == -1) { + + row = tbl->cursor_row; + + if (tbl->flags & KHUI_CW_TBL_EXPIDENT) { + int i; + + y = 0; + for (i=0; i < tbl->n_rows && i < row; i++) { + if (tbl->rows[i].flags & KHUI_CW_ROW_EXPVIEW) + y += tbl->cell_height * CW_EXP_ROW_MULT; + else + y += tbl->cell_height; + } + } else { + y = row * tbl->cell_height; + } + + x = r.left; + y = y + r.top + tbl->header_height - tbl->scr_top; + + goto have_row; + } + x += tbl->scr_left - r.left; y += tbl->scr_top - tbl->header_height - r.top; @@ -5440,23 +5467,21 @@ cw_wm_contextmenu(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if(row < 0 || row >= (int) tbl->n_rows) return FALSE; - cw_set_row_context(tbl, row); + /* now, if the user has right clicked outside the selection, we + treat the right-click as a regular click before showing the + context menu. */ + if (!(tbl->rows[row].flags & KHUI_CW_ROW_SELECTED)) { + cw_select_row(tbl, row, 0); + } - khm_menu_show_panel(KHUI_MENU_IDENT_CTX, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + x = GET_X_LPARAM(lParam); + y = GET_Y_LPARAM(lParam); -#if 0 - /* calling cw_set_row_context() should take care of enabling or - disabling actions as appropriate. We don't need to - differentiate between IDENT_CTX and TOK_CTX here. */ - if((tbl->rows[row].flags & KHUI_CW_ROW_HEADER) && - (tbl->cols[tbl->rows[row].col].attr_id == KCDB_ATTR_ID_NAME)) { - khm_menu_show_panel(KHUI_MENU_IDENT_CTX, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); - //khui_context_reset(); - } else { - khm_menu_show_panel(KHUI_MENU_TOK_CTX, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); - //khui_context_reset(); - } -#endif + have_row: + + cw_set_row_context(tbl, row); + + khm_menu_show_panel(KHUI_MENU_IDENT_CTX, x, y); return DefWindowProc(hwnd, uMsg, wParam, lParam); } -- 2.26.2