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;
} 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;
}
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;
}
khm_int32 renew_cmd;
khm_int32 destroy_cmd;
khm_int32 new_cmd;
+ khm_int32 setdef_cmd;
int refreshcycle;
};
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
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;
}
}
}
return 0;
}
+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;
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;
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;
}
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,
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,
} 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);
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);
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);
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();
NULL);
return TRUE;
}
+
+ if (id_action_map[i].setdef_cmd == act_id) {
+ khm_cred_set_default_identity(id_action_map[i].identity);
+
+ return TRUE;
+ }
}
}
MENU_ACTION(KHUI_ACTION_IMPORT),
MENU_SUBMENU(KHUI_MENU_DESTROY_CRED),
MENU_SEP(),
+ MENU_SUBMENU(KHUI_MENU_SETDEF),
+ MENU_SEP(),
MENU_ACTION(KHUI_ACTION_PASSWD_ID),
MENU_SEP(),
MENU_ACTION(KHUI_ACTION_HELP_CTX),
MENU_ACTION(KHUI_ACTION_IMPORT),
MENU_SUBMENU(KHUI_MENU_DESTROY_CRED),
MENU_SEP(),
+ MENU_SUBMENU(KHUI_MENU_SETDEF),
+ MENU_SEP(),
MENU_ACTION(KHUI_ACTION_PASSWD_ID),
MENU_SEP(),
MENU_ACTION(KHUI_ACTION_HELP_CTX),
MENU_END()
};
+khui_action_ref khui_menu_setdef[] = {
+ MENU_END()
+};
+
khui_action_ref khui_pmenu_tok_sel[] = {
MENU_ACTION(KHUI_ACTION_RENEW_CRED),
MENU_ACTION(KHUI_ACTION_DESTROY_CRED),
CONSTMENU(KHUI_MENU_COLUMNS, KHUI_MENUSTATE_CONSTANT | KHUI_MENUSTATE_SYSTEM, khui_menu_columns),
CONSTMENU(KHUI_MENU_RENEW_CRED, KHUI_MENUSTATE_CONSTANT | KHUI_MENUSTATE_SYSTEM, khui_menu_renew_cred),
CONSTMENU(KHUI_MENU_DESTROY_CRED, KHUI_MENUSTATE_CONSTANT | KHUI_MENUSTATE_SYSTEM, khui_menu_destroy_cred),
+ CONSTMENU(KHUI_MENU_SETDEF, KHUI_MENUSTATE_CONSTANT | KHUI_MENUSTATE_SYSTEM, khui_menu_setdef),
/* toolbars */
CONSTMENU(KHUI_TOOLBAR_STANDARD, KHUI_MENUSTATE_CONSTANT | KHUI_MENUSTATE_SYSTEM, khui_toolbar_standard),
!caption ||
FAILED(StringCchLength(caption, KHUI_MAXCCH_SHORT_DESC, &s)) ||
(tooltip && FAILED(StringCchLength(tooltip, KHUI_MAXCCH_SHORT_DESC, &s))) ||
- (type != KHUI_ACTIONTYPE_TRIGGER && type != KHUI_ACTIONTYPE_TOGGLE)) {
+ (type != KHUI_ACTIONTYPE_TRIGGER && type != KHUI_ACTIONTYPE_TOGGLE &&
+ type != KHUI_ACTIONTYPE_IDENTITY)) {
return 0;
}
KHUI_MENU_COLUMNS,KHUI_ACTIONTYPE_TRIGGER,,0,0,0,0,0,IDS_ACTION_CHOOSE_COLS,0,IDH_ACTION_CHOOSE_COLS,0
KHUI_MENU_DESTROY_CRED,KHUI_ACTIONTYPE_TRIGGER,,0,0,0,0,0,IDS_MENU_DESTROY_CRED,0,0,0
KHUI_MENU_RENEW_CRED,KHUI_ACTIONTYPE_TRIGGER,,0,0,0,0,0,IDS_MENU_RENEW_CRED,0,0,0
+KHUI_MENU_SETDEF,KHUI_ACTIONTYPE_TRIGGER,,0,0,0,0,0,IDS_MENU_SETDEF,0,0,0
KHUI_ACTION_PROPERTIES,KHUI_ACTIONTYPE_TRIGGER,,0,0,0,0,0,IDS_ACTION_PROPERTIES,IDS_ACTIONT_PROPERTIES,IDH_ACTION_PROPERTIES,0
KHUI_ACTION_EXIT,KHUI_ACTIONTYPE_TRIGGER,,0,0,0,0,0,IDS_ACTION_EXIT,IDS_ACTIONT_EXIT,IDH_ACTION_EXIT,0
KHUI_ACTION_SET_DEF_ID,KHUI_ACTIONTYPE_TRIGGER | KHUI_ACTIONTYPE_TOGGLE,,0,0,0,0,0,IDS_ACTION_SET_DEF_ID,IDS_ACTIONT_SET_DEF_ID,IDH_ACTION_SET_DEF_ID,0