diff options
author | Jeffrey Altman <jaltman@secure-endpoints.com> | 2007-09-27 03:42:20 +0000 |
---|---|---|
committer | Jeffrey Altman <jaltman@secure-endpoints.com> | 2007-09-27 03:42:20 +0000 |
commit | b3e642e821a09e9cea46c604d0b5450ffbafcfbf (patch) | |
tree | 79aac69fe51675687d74364f500054df0b814a0a /src/windows/identity/ui | |
parent | 973497ea9a2f1b19520bc326bf2b36114426511f (diff) | |
download | krb5-b3e642e821a09e9cea46c604d0b5450ffbafcfbf.tar.gz krb5-b3e642e821a09e9cea46c604d0b5450ffbafcfbf.tar.xz krb5-b3e642e821a09e9cea46c604d0b5450ffbafcfbf.zip |
Add a "Set default" sub menu to the Network Identity Manager
notification icon context menu. The submenu will display a list of
identities that the user can select as the default identity.
Each identity that is displayed in the sub menu will be colored the
same way it is colored in the basic view to provide a hint as to the
state of the credentials belonging to the identity.
ticket: 5724
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@19983 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/windows/identity/ui')
-rw-r--r-- | src/windows/identity/ui/credfuncs.c | 5 | ||||
-rw-r--r-- | src/windows/identity/ui/credfuncs.h | 2 | ||||
-rw-r--r-- | src/windows/identity/ui/credwnd.c | 130 | ||||
-rw-r--r-- | src/windows/identity/ui/credwnd.h | 4 | ||||
-rw-r--r-- | src/windows/identity/ui/images/enabled.ico | bin | 2166 -> 2166 bytes | |||
-rw-r--r-- | src/windows/identity/ui/lang/en_us/khapp.rc | 4 | ||||
-rw-r--r-- | src/windows/identity/ui/mainmenu.c | 210 | ||||
-rw-r--r-- | src/windows/identity/ui/resource.h | 3 |
8 files changed, 300 insertions, 58 deletions
diff --git a/src/windows/identity/ui/credfuncs.c b/src/windows/identity/ui/credfuncs.c index b90d9a60d9..c8b6727b8a 100644 --- a/src/windows/identity/ui/credfuncs.c +++ b/src/windows/identity/ui/credfuncs.c @@ -555,6 +555,11 @@ void khm_cred_set_default(void) khui_context_release(&ctx); } +void khm_cred_set_default_identity(khm_handle identity) +{ + kcdb_identity_set_default(identity); +} + void khm_cred_destroy_creds(khm_boolean sync, khm_boolean quiet) { khui_action_context * pctx; diff --git a/src/windows/identity/ui/credfuncs.h b/src/windows/identity/ui/credfuncs.h index 0a4e2531a6..9bc2890896 100644 --- a/src/windows/identity/ui/credfuncs.h +++ b/src/windows/identity/ui/credfuncs.h @@ -59,6 +59,8 @@ khm_cred_obtain_new_creds_for_ident(khm_handle ident, wchar_t * title); void khm_cred_set_default(void); +void khm_cred_set_default_identity(khm_handle identity); + void khm_cred_change_password(wchar_t * window_title); diff --git a/src/windows/identity/ui/credwnd.c b/src/windows/identity/ui/credwnd.c index 2f36f330e0..1148a9b779 100644 --- a/src/windows/identity/ui/credwnd.c +++ b/src/windows/identity/ui/credwnd.c @@ -5714,6 +5714,136 @@ khm_credwnd_proc(HWND hwnd, return DefWindowProc(hwnd,uMsg,wParam,lParam); } +void +khm_measure_identity_menu_item(HWND hwnd, LPMEASUREITEMSTRUCT lpm, khui_action * act) +{ + wchar_t * cap; + HDC hdc; + SIZE sz; + size_t len; + HFONT hf_old; + + sz.cx = MENU_SIZE_ICON_X; + sz.cy = MENU_SIZE_ICON_Y; + + cap = act->caption; +#ifdef DEBUG + assert(cap); +#endif + hdc = GetDC(khm_hwnd_main); +#ifdef DEBUG + assert(hdc); +#endif + + StringCchLength(cap, KHUI_MAXCCH_NAME, &len); + + hf_old = SelectFont(hdc, (HFONT) GetStockObject(DEFAULT_GUI_FONT)); + + GetTextExtentPoint32(hdc, cap, (int) len, &sz); + + SelectFont(hdc, hf_old); + + ReleaseDC(khm_hwnd_main, hdc); + + lpm->itemWidth = sz.cx + sz.cy * 3 / 2 + GetSystemMetrics(SM_CXSMICON); + lpm->itemHeight = sz.cy * 3 / 2; +} + +void +khm_draw_identity_menu_item(HWND hwnd, LPDRAWITEMSTRUCT lpd, khui_action * act) +{ + khui_credwnd_tbl * tbl; + khm_handle ident; + khm_size i; + size_t count = 0; + COLORREF old_clr; + wchar_t * cap; + size_t len; + int margin; + SIZE sz; + HBRUSH hbr; + COLORREF text_clr; + khm_int32 idflags; + khm_int32 expflags; + + tbl = (khui_credwnd_tbl *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (tbl == NULL) + return; + + ident = act->data; + cap = act->caption; +#ifdef DEBUG + assert(ident != NULL); + assert(cap != NULL); +#endif + + for (i=0; i < tbl->n_idents; i++) { + if (kcdb_identity_is_equal(tbl->idents[i].ident, ident)) { + count = tbl->idents[i].credcount; + break; + } + } + + expflags = cw_get_buf_exp_flags(tbl, ident); + + text_clr = tbl->cr_hdr_normal; + + if (lpd->itemState & (ODS_HOTLIGHT | ODS_SELECTED)) { + hbr = GetSysColorBrush(COLOR_HIGHLIGHT); + text_clr = GetSysColor(COLOR_HIGHLIGHTTEXT); + } else if (count == 0) { + hbr = tbl->hb_hdr_bg; + } else if (expflags == CW_EXPSTATE_EXPIRED) { + hbr = tbl->hb_hdr_bg_exp; + } else if (expflags == CW_EXPSTATE_WARN) { + hbr = tbl->hb_hdr_bg_warn; + } else if (expflags == CW_EXPSTATE_CRITICAL) { + hbr = tbl->hb_hdr_bg_crit; + } else { + hbr = tbl->hb_hdr_bg_cred; + } + + FillRect(lpd->hDC, &lpd->rcItem, hbr); + + SetBkMode(lpd->hDC, TRANSPARENT); + + old_clr = SetTextColor(lpd->hDC, text_clr); + + StringCchLength(cap, KHUI_MAXCCH_NAME, &len); + + GetTextExtentPoint32(lpd->hDC, cap, (int) len, &sz); + margin = sz.cy / 4; + + TextOut(lpd->hDC, lpd->rcItem.left + margin * 2 + GetSystemMetrics(SM_CXSMICON), + lpd->rcItem.top + margin, cap, (int) len); + + SetTextColor(lpd->hDC, old_clr); + + kcdb_identity_get_flags(ident, &idflags); + + if (idflags & KCDB_IDENT_FLAG_DEFAULT) { + HICON hic; + + hic = (HICON) LoadImage(khm_hInstance, MAKEINTRESOURCE(IDI_ENABLED), + IMAGE_ICON, + GetSystemMetrics(SM_CXSMICON), + GetSystemMetrics(SM_CYSMICON), + LR_DEFAULTCOLOR); + if (hic) { + DrawIconEx(lpd->hDC, + lpd->rcItem.left + margin, + lpd->rcItem.top + margin, + hic, + GetSystemMetrics(SM_CXSMICON), + GetSystemMetrics(SM_CYSMICON), + 0, + hbr, + DI_NORMAL); + DestroyIcon(hic); + } + } +} + void khm_register_credwnd_class(void) { WNDCLASSEX wcx; diff --git a/src/windows/identity/ui/credwnd.h b/src/windows/identity/ui/credwnd.h index 6849f9f025..7f90710144 100644 --- a/src/windows/identity/ui/credwnd.h +++ b/src/windows/identity/ui/credwnd.h @@ -299,4 +299,8 @@ void khm_get_cw_element_font(HDC hdc, wchar_t * name, BOOL use_default, void khm_set_cw_element_font(wchar_t * name, LOGFONT * pfont); +void khm_draw_identity_menu_item(HWND hwnd, LPDRAWITEMSTRUCT lpd, khui_action * act); + +void khm_measure_identity_menu_item(HWND hwnd, LPMEASUREITEMSTRUCT lpm, khui_action * act); + #endif diff --git a/src/windows/identity/ui/images/enabled.ico b/src/windows/identity/ui/images/enabled.ico Binary files differindex 22821a8b78..fc83ad8584 100644 --- a/src/windows/identity/ui/images/enabled.ico +++ b/src/windows/identity/ui/images/enabled.ico diff --git a/src/windows/identity/ui/lang/en_us/khapp.rc b/src/windows/identity/ui/lang/en_us/khapp.rc index 02fa984c34..4dc9f733b0 100644 --- a/src/windows/identity/ui/lang/en_us/khapp.rc +++ b/src/windows/identity/ui/lang/en_us/khapp.rc @@ -714,6 +714,7 @@ BEGIN IDS_WTPOST_PASSWORD " - Changing password" IDS_CTX_PROC_PASSWORD "Changing password for %1!s!" IDS_NC_PWD_FAILED_TITLE "Failed to change password" + IDS_MENU_SETDEF "Set default" IDS_PACTION_NEXT "Next alert" IDS_ERR_TITLE_NO_IDENTPRO "Cannot proceed without identity provider" END @@ -837,10 +838,12 @@ BEGIN IDS_CW_TYPEF "(%s)" IDS_CW_EXPIREF "Expires in %s" IDS_CW_EXPIRED "(Expired)" + IDS_IDACTIONT_SETDEF "Set %s as default identity" END STRINGTABLE BEGIN + IDS_IDACTION_SETDEF "%s" IDS_ACTION_VIEW_ALL_IDS "All identities" END @@ -862,3 +865,4 @@ END + diff --git a/src/windows/identity/ui/mainmenu.c b/src/windows/identity/ui/mainmenu.c index 7ae6e33f1a..8645dc7bc6 100644 --- a/src/windows/identity/ui/mainmenu.c +++ b/src/windows/identity/ui/mainmenu.c @@ -139,19 +139,27 @@ void add_action_to_menu(HMENU hm, khui_action * act, } else { khui_menu_def * def; - khm_get_action_caption(act->cmd, buf, sizeof(buf)); + if (act->type == KHUI_ACTIONTYPE_IDENTITY) { + mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_DATA; + mii.fType = MFT_OWNERDRAW; - if(khui_get_cmd_accel_string(act->cmd, accel, - ARRAYLENGTH(accel))) { - StringCbCat(buf, sizeof(buf), L"\t"); - StringCbCat(buf, sizeof(buf), accel); - } + mii.dwTypeData = 0; + mii.dwItemData = 0; + } else { + khm_get_action_caption(act->cmd, buf, sizeof(buf)); - mii.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID; - mii.fType = MFT_STRING; + if(khui_get_cmd_accel_string(act->cmd, accel, + ARRAYLENGTH(accel))) { + StringCbCat(buf, sizeof(buf), L"\t"); + StringCbCat(buf, sizeof(buf), accel); + } - mii.dwTypeData = buf; - mii.cch = (int) wcslen(buf); + mii.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID; + mii.fType = MFT_STRING; + + mii.dwTypeData = buf; + mii.cch = (int) wcslen(buf); + } mii.wID = act->cmd; @@ -391,48 +399,61 @@ LRESULT khm_menu_activate(int menu_id) { } LRESULT khm_menu_measure_item(WPARAM wParam, LPARAM lParam) { - /* all menu icons have a fixed size */ LPMEASUREITEMSTRUCT lpm = (LPMEASUREITEMSTRUCT) lParam; - lpm->itemWidth = MENU_SIZE_ICON_X; - lpm->itemHeight = MENU_SIZE_ICON_Y; + khui_action * act; + + act = khui_find_action(lpm->itemID); + if (act && act->type == KHUI_ACTIONTYPE_IDENTITY) { + khm_measure_identity_menu_item(khm_hwnd_main_cred, lpm, act); + } else { + lpm->itemWidth = MENU_SIZE_ICON_X; + lpm->itemHeight = MENU_SIZE_ICON_Y; + } return TRUE; } LRESULT khm_menu_draw_item(WPARAM wParam, LPARAM lParam) { LPDRAWITEMSTRUCT lpd; khui_action * act; - int resid; - int iidx; - UINT style; lpd = (LPDRAWITEMSTRUCT) lParam; act = khui_find_action(lpd->itemID); - resid = 0; - if((lpd->itemState & ODS_DISABLED) || (lpd->itemState & ODS_GRAYED)) { - resid = act->ib_icon_dis; - } - if(!resid) - resid = act->ib_icon; + if (act && act->type == KHUI_ACTIONTYPE_IDENTITY) { - if(!resid) /* nothing to draw */ - return TRUE; + khm_draw_identity_menu_item(khm_hwnd_main_cred, lpd, act); + + } else { + int resid; + int iidx; + UINT style; + + resid = 0; + if((lpd->itemState & ODS_DISABLED) || (lpd->itemState & ODS_GRAYED)) { + resid = act->ib_icon_dis; + } + if(!resid) + resid = act->ib_icon; + + if(!resid) /* nothing to draw */ + return TRUE; - iidx = khui_get_icon_index(resid); - if(iidx == -1) - return TRUE; + iidx = khui_get_icon_index(resid); + if(iidx == -1) + return TRUE; - style = ILD_TRANSPARENT; - if(lpd->itemState & ODS_HOTLIGHT || lpd->itemState & ODS_SELECTED) { - style |= ILD_SELECTED; - } + style = ILD_TRANSPARENT; + if(lpd->itemState & ODS_HOTLIGHT || lpd->itemState & ODS_SELECTED) { + style |= ILD_SELECTED; + } - khui_ilist_draw(il_icon, - iidx, - lpd->hDC, - lpd->rcItem.left, lpd->rcItem.top, style); + khui_ilist_draw(il_icon, + iidx, + lpd->hDC, + lpd->rcItem.left, lpd->rcItem.top, style); + } return TRUE; } @@ -636,6 +657,7 @@ struct identity_action_map { khm_int32 renew_cmd; khm_int32 destroy_cmd; khm_int32 new_cmd; + khm_int32 setdef_cmd; int refreshcycle; }; @@ -727,6 +749,19 @@ create_identity_cmd_map(khm_handle ident) { khui_action_create(actionname, caption, tooltip, NULL, KHUI_ACTIONTYPE_TRIGGER, NULL); + /* set default */ + GETFORMAT(IDS_IDACTIONT_SETDEF); + EXPFORMAT(tooltip, idname); + + GETFORMAT(IDS_IDACTION_SETDEF); + EXPFORMAT(caption, idname); + + StringCbPrintf(actionname, sizeof(actionname), L"E:%s", idname); + + actmap->setdef_cmd = + khui_action_create(actionname, caption, tooltip, ident, + KHUI_ACTIONTYPE_IDENTITY, NULL); + actmap->refreshcycle = idcmd_refreshcycle; #undef GETFORMAT @@ -749,9 +784,13 @@ purge_identity_cmd_map(void) { khui_action_delete(id_action_map[i].renew_cmd); khui_action_delete(id_action_map[i].destroy_cmd); + khui_action_delete(id_action_map[i].new_cmd); + khui_action_delete(id_action_map[i].setdef_cmd); id_action_map[i].renew_cmd = 0; id_action_map[i].destroy_cmd = 0; + id_action_map[i].new_cmd = 0; + id_action_map[i].setdef_cmd = 0; } } } @@ -799,6 +838,18 @@ khm_get_identity_destroy_action(khm_handle ident) { } khm_int32 +khm_get_identity_setdef_action(khm_handle ident) { + struct identity_action_map * map; + + map = get_identity_cmd_map(ident); + + if (map) + return map->setdef_cmd; + else + return 0; +} + +khm_int32 khm_get_identity_new_creds_action(khm_handle ident) { struct identity_action_map * map; @@ -814,6 +865,7 @@ void khm_refresh_identity_menus(void) { khui_menu_def * renew_def = NULL; khui_menu_def * dest_def = NULL; + khui_menu_def * setdef_def = NULL; wchar_t * idlist = NULL; wchar_t * idname = NULL; khm_size cb = 0; @@ -823,10 +875,14 @@ khm_refresh_identity_menus(void) { khm_handle csp_cw = NULL; khm_int32 idflags; khm_int32 def_sticky = 0; + khm_int32 all_identities = 0; khm_boolean sticky_done = FALSE; + khm_boolean added_dest = FALSE; + khm_boolean added_setdef = FALSE; if (KHM_SUCCEEDED(khc_open_space(NULL, L"CredWindow", 0, &csp_cw))) { khc_read_int32(csp_cw, L"DefaultSticky", &def_sticky); + khc_read_int32(csp_cw, L"ViewAllIdents", &all_identities); khc_close_space(csp_cw); csp_cw = NULL; } @@ -843,7 +899,7 @@ khm_refresh_identity_menus(void) { idlist = NULL; cb = 0; - rv = kcdb_identity_enum(KCDB_IDENT_FLAG_ACTIVE | KCDB_IDENT_FLAG_EMPTY, + rv = kcdb_identity_enum(KCDB_IDENT_FLAG_ACTIVE, KCDB_IDENT_FLAG_ACTIVE, NULL, &cb, @@ -856,7 +912,7 @@ khm_refresh_identity_menus(void) { assert(idlist); #endif - rv = kcdb_identity_enum(KCDB_IDENT_FLAG_ACTIVE | KCDB_IDENT_FLAG_EMPTY, + rv = kcdb_identity_enum(KCDB_IDENT_FLAG_ACTIVE, KCDB_IDENT_FLAG_ACTIVE, idlist, &cb, @@ -874,23 +930,13 @@ khm_refresh_identity_menus(void) { } while(TRUE); - if (idlist != NULL && n_idents > 0) { - khui_enable_action(KHUI_MENU_RENEW_CRED, TRUE); - khui_enable_action(KHUI_MENU_DESTROY_CRED, TRUE); - khui_enable_action(KHUI_ACTION_RENEW_CRED, TRUE); - khui_enable_action(KHUI_ACTION_DESTROY_CRED, TRUE); - } else { - khui_enable_action(KHUI_MENU_RENEW_CRED, FALSE); - khui_enable_action(KHUI_MENU_DESTROY_CRED, FALSE); - khui_enable_action(KHUI_ACTION_RENEW_CRED, FALSE); - khui_enable_action(KHUI_ACTION_DESTROY_CRED, FALSE); - } - renew_def = khui_find_menu(KHUI_MENU_RENEW_CRED); dest_def = khui_find_menu(KHUI_MENU_DESTROY_CRED); + setdef_def = khui_find_menu(KHUI_MENU_SETDEF); #ifdef DEBUG assert(renew_def); assert(dest_def); + assert(setdef_def); #endif t = khui_menu_get_size(renew_def); @@ -905,6 +951,12 @@ khm_refresh_identity_menus(void) { t--; } + t = khui_menu_get_size(setdef_def); + while(t) { + khui_menu_remove_action(setdef_def, 0); + t--; + } + if (idlist != NULL && n_idents > 1) { khui_menu_insert_action(renew_def, 0, KHUI_ACTION_RENEW_ALL, 0); khui_menu_insert_action(renew_def, 1, KHUI_MENU_SEP, 0); @@ -924,14 +976,6 @@ khm_refresh_identity_menus(void) { continue; } - khui_menu_insert_action(renew_def, 1000, - khm_get_identity_renew_action(identity), - 0); - - khui_menu_insert_action(dest_def, 1000, - khm_get_identity_destroy_action(identity), - 0); - idflags = 0; kcdb_identity_get_flags(identity, &idflags); @@ -939,12 +983,56 @@ khm_refresh_identity_menus(void) { kcdb_identity_set_flags(identity, KCDB_IDENT_FLAG_STICKY, KCDB_IDENT_FLAG_STICKY); + idflags |= KCDB_IDENT_FLAG_STICKY; sticky_done = TRUE; } + + if (!(idflags & KCDB_IDENT_FLAG_EMPTY)) { + khui_menu_insert_action(renew_def, 1000, + khm_get_identity_renew_action(identity), + 0); + + khui_menu_insert_action(dest_def, 1000, + khm_get_identity_destroy_action(identity), + 0); + added_dest = TRUE; + } + + if (all_identities || + !(idflags & KCDB_IDENT_FLAG_EMPTY) || + (idflags & KCDB_IDENT_FLAG_STICKY)) { + + khui_menu_insert_action(setdef_def, 1000, + khm_get_identity_setdef_action(identity), + 0); + added_setdef = TRUE; + } + + kcdb_identity_release(identity); } - if (idlist) + if (idlist) { PFREE(idlist); + idlist = NULL; + } + + if (added_dest) { + khui_enable_action(KHUI_MENU_RENEW_CRED, TRUE); + khui_enable_action(KHUI_MENU_DESTROY_CRED, TRUE); + khui_enable_action(KHUI_ACTION_RENEW_CRED, TRUE); + khui_enable_action(KHUI_ACTION_DESTROY_CRED, TRUE); + } else { + khui_enable_action(KHUI_MENU_RENEW_CRED, FALSE); + khui_enable_action(KHUI_MENU_DESTROY_CRED, FALSE); + khui_enable_action(KHUI_ACTION_RENEW_CRED, FALSE); + khui_enable_action(KHUI_ACTION_DESTROY_CRED, FALSE); + } + + if (added_setdef) { + khui_enable_action(KHUI_MENU_SETDEF, TRUE); + } else { + khui_enable_action(KHUI_MENU_SETDEF, FALSE); + } purge_identity_cmd_map(); @@ -1002,6 +1090,12 @@ khm_check_identity_menu_action(khm_int32 act_id) { NULL); return TRUE; } + + if (id_action_map[i].setdef_cmd == act_id) { + khm_cred_set_default_identity(id_action_map[i].identity); + + return TRUE; + } } } diff --git a/src/windows/identity/ui/resource.h b/src/windows/identity/ui/resource.h index 1a75a3cb5c..19cd49de6e 100644 --- a/src/windows/identity/ui/resource.h +++ b/src/windows/identity/ui/resource.h @@ -214,6 +214,7 @@ #define IDS_WTPOST_PASSWORD 218 #define IDS_CTX_PROC_PASSWORD 219 #define IDS_NC_PWD_FAILED_TITLE 220 +#define IDS_MENU_SETDEF 221 #define IDS_PACTION_NEXT 222 #define IDS_ERR_TITLE_NO_IDENTPRO 223 #define IDS_ERR_MSG_NO_IDENTPRO 224 @@ -311,6 +312,8 @@ #define IDS_CW_TYPEF 316 #define IDS_CW_EXPIREF 317 #define IDS_CW_EXPIRED 318 +#define IDS_IDACTIONT_SETDEF 319 +#define IDS_IDACTION_SETDEF 320 #define IDS_ACTION_VIEW_ALL_IDS 321 #define IDC_NC_CREDTEXT_LABEL 1009 #define IDC_NC_CREDTEXT 1012 |