Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

446 lines
10 KiB

  1. //=============================================================================
  2. // Copyright (c) 2000 Microsoft Corporation
  3. //
  4. // controls.hpp
  5. //
  6. // User interface control classes.
  7. //
  8. // Created 02/29/2000 johnstep (John Stephens)
  9. //=============================================================================
  10. #ifndef __CONTROLS_HPP__
  11. #define __CONTROLS_HPP__
  12. //-----------------------------------------------------------------------------
  13. #include <objidl.h>
  14. #include <scuisupp.h>
  15. //-----------------------------------------------------------------------------
  16. // Global Variables
  17. //-----------------------------------------------------------------------------
  18. extern CLSID CreduiStringArrayClassId;
  19. #define CREDUI_STRING_ARRAY_CLASS_STRING\
  20. L"{82BD0E67-9FEA-4748-8672-D5EFE5B779B0}"
  21. //-----------------------------------------------------------------------------
  22. // Types
  23. //-----------------------------------------------------------------------------
  24. struct CREDUI_BALLOON_TIP_INFO
  25. {
  26. WCHAR *Title;
  27. WCHAR *Text;
  28. INT Icon;
  29. INT XPercent;
  30. INT YPercent;
  31. };
  32. //-----------------------------------------------------------------------------
  33. // CreduiBalloonTip Class
  34. //-----------------------------------------------------------------------------
  35. class CreduiBalloonTip
  36. {
  37. public:
  38. CreduiBalloonTip();
  39. ~CreduiBalloonTip();
  40. BOOL Init(HINSTANCE instance, HWND parentWindow);
  41. BOOL SetInfo(HWND controlWindow, CONST CREDUI_BALLOON_TIP_INFO *tipInfo);
  42. CREDUI_BALLOON_TIP_INFO *GetInfo() { return TipInfo; }
  43. BOOL Show();
  44. BOOL Hide();
  45. BOOL IsVisible() { return Visible; }
  46. private:
  47. HWND Window;
  48. HWND ParentWindow;
  49. HWND ControlWindow;
  50. CREDUI_BALLOON_TIP_INFO *TipInfo;
  51. BOOL Visible;
  52. };
  53. //-----------------------------------------------------------------------------
  54. // CreduiPasswordBox Class
  55. //-----------------------------------------------------------------------------
  56. class CreduiPasswordBox
  57. {
  58. public:
  59. CreduiPasswordBox();
  60. ~CreduiPasswordBox();
  61. BOOL Init(
  62. HWND window,
  63. CreduiBalloonTip *ballonTip,
  64. CONST CREDUI_BALLOON_TIP_INFO *capsLockTipInfo,
  65. HFONT passwordFont = NULL,
  66. WCHAR passwordChar = L'');
  67. private:
  68. WNDPROC OriginalMessageHandler;
  69. LRESULT
  70. MessageHandler(
  71. UINT message,
  72. WPARAM wParam,
  73. LPARAM lParam
  74. );
  75. static LRESULT CALLBACK MessageHandlerCallback(
  76. HWND passwordWindow,
  77. UINT message,
  78. WPARAM wParam,
  79. LPARAM lParam
  80. );
  81. HWND Window;
  82. HFONT PasswordFont;
  83. CreduiBalloonTip *BalloonTip;
  84. CONST CREDUI_BALLOON_TIP_INFO *CapsLockTipInfo;
  85. };
  86. //-----------------------------------------------------------------------------
  87. // CreduiStringArrayFactory Class
  88. //-----------------------------------------------------------------------------
  89. class CreduiStringArrayFactory : public IClassFactory
  90. {
  91. public:
  92. CreduiStringArrayFactory();
  93. // IUnknown
  94. HRESULT STDMETHODCALLTYPE QueryInterface(
  95. CONST IID &interfaceId,
  96. VOID **outInterface
  97. );
  98. ULONG STDMETHODCALLTYPE AddRef();
  99. ULONG STDMETHODCALLTYPE Release();
  100. // IClassFactory
  101. HRESULT STDMETHODCALLTYPE CreateInstance(
  102. IUnknown *unknownOuter,
  103. CONST IID &interfaceId,
  104. VOID **outInterface
  105. );
  106. HRESULT STDMETHODCALLTYPE LockServer(BOOL lock);
  107. private:
  108. ~CreduiStringArrayFactory(); // must use IUnknown::Release()
  109. ULONG ReferenceCount;
  110. };
  111. //-----------------------------------------------------------------------------
  112. // CreduiStringArray Class
  113. //-----------------------------------------------------------------------------
  114. class CreduiStringArray : public IEnumString
  115. {
  116. public:
  117. CreduiStringArray();
  118. BOOL Init(UINT count);
  119. BOOL Find(CONST WCHAR *string);
  120. INT Add(CONST WCHAR *string);
  121. UINT GetCount() CONST { return Count; }
  122. // IUnknown
  123. HRESULT STDMETHODCALLTYPE QueryInterface(
  124. CONST IID &interfaceId,
  125. VOID **outInterface
  126. );
  127. ULONG STDMETHODCALLTYPE AddRef();
  128. ULONG STDMETHODCALLTYPE Release();
  129. // IEnumString
  130. HRESULT STDMETHODCALLTYPE Next(
  131. ULONG count,
  132. WCHAR **array,
  133. ULONG *countFetched
  134. );
  135. HRESULT STDMETHODCALLTYPE Skip(ULONG count);
  136. HRESULT STDMETHODCALLTYPE Reset();
  137. HRESULT STDMETHODCALLTYPE Clone(IEnumString **enumInterface);
  138. private:
  139. ~CreduiStringArray(); // must use IUnknown::Release()
  140. ULONG ReferenceCount;
  141. UINT Index;
  142. UINT Count;
  143. UINT MaxCount;
  144. WCHAR **Array;
  145. };
  146. //-----------------------------------------------------------------------------
  147. // CreduiAutoCompleteComboBox Class
  148. //-----------------------------------------------------------------------------
  149. class CreduiAutoCompleteComboBox
  150. {
  151. public:
  152. CreduiAutoCompleteComboBox();
  153. ~CreduiAutoCompleteComboBox();
  154. BOOL Init(
  155. HMODULE instance,
  156. HWND comboBoxwindow,
  157. UINT stringCount,
  158. INT imageListResourceId = 0,
  159. INT initialImage = -1
  160. );
  161. INT Add(
  162. WCHAR *string,
  163. INT image = -1,
  164. BOOL autoComplete = TRUE,
  165. BOOL addUnique = TRUE,
  166. INT indexBefore = -1,
  167. INT indent = 0
  168. );
  169. BOOL Update(
  170. INT index,
  171. WCHAR *string,
  172. INT image = -1
  173. );
  174. BOOL Enable();
  175. private:
  176. HWND Window;
  177. HIMAGELIST ImageList;
  178. CreduiStringArray *StringArray;
  179. };
  180. //-----------------------------------------------------------------------------
  181. // CreduiIconParentWindow Class
  182. //-----------------------------------------------------------------------------
  183. class CreduiIconParentWindow
  184. {
  185. public:
  186. CreduiIconParentWindow();
  187. ~CreduiIconParentWindow();
  188. BOOL Init(HINSTANCE instance, UINT iconResourceId);
  189. HWND GetWindow() { return Window; }
  190. static BOOL Register(HINSTANCE instance);
  191. static BOOL Unregister();
  192. private:
  193. HWND Window;
  194. static CONST WCHAR *ClassName;
  195. static HINSTANCE Instance;
  196. static LONG Registered;
  197. };
  198. //-----------------------------------------------------------------------------
  199. // CreduiCredentialControl Class
  200. //-----------------------------------------------------------------------------
  201. class CreduiCredentialControl
  202. {
  203. public:
  204. CreduiCredentialControl();
  205. ~CreduiCredentialControl();
  206. static BOOL Register(HINSTANCE instance);
  207. static BOOL Unregister();
  208. virtual BOOL
  209. OnHelpInfo(
  210. LPARAM lp
  211. );
  212. virtual UINT
  213. MapID(UINT uid);
  214. private:
  215. static CONST WCHAR *ClassName;
  216. static HINSTANCE Instance;
  217. static LONG Registered;
  218. BOOL IsInitialized;
  219. // User interface control state flags:
  220. enum
  221. {
  222. DISABLED_CONTROL = 0x0001,
  223. DISABLED_CONTROL_PASSWORD = 0x0002,
  224. DISABLED_CONTROL_USERNAME = 0x0010,
  225. DISABLED_CONTROL_VIEW = 0x0004,
  226. DISABLED_CONTROL_SAVE = 0x0008,
  227. };
  228. BOOL DisabledControlMask;
  229. // User type image indices:
  230. enum
  231. {
  232. IMAGE_USERNAME = 0,
  233. IMAGE_CERT = 1,
  234. IMAGE_CERT_EXPIRED = 2,
  235. IMAGE_SMART_CARD = 3,
  236. IMAGE_SMART_CARD_MISSING = 4,
  237. IMAGE_SMART_CARD_EXPIRED = 5
  238. };
  239. HWND Window;
  240. LONG Style;
  241. HWND UserNameStaticWindow;
  242. HWND UserNameControlWindow;
  243. HWND ViewCertControlWindow;
  244. HWND PasswordStaticWindow;
  245. HWND PasswordControlWindow;
  246. HWND SaveControlWindow;
  247. BOOL FirstPaint;
  248. BOOL ShowBalloonTip;
  249. CreduiBalloonTip BalloonTip;
  250. BOOL IsAutoComplete;
  251. BOOL NoEditUserName;
  252. BOOL KeepUserName;
  253. BOOL IsPassport;
  254. CreduiPasswordBox PasswordBox;
  255. UCHAR (*CertHashes)[CERT_HASH_LENGTH];
  256. ULONG CertCount;
  257. INT CertBaseInComboBox;
  258. UCHAR (*UserNameCertHash)[CERT_HASH_LENGTH];
  259. INT SmartCardBaseInComboBox;
  260. UINT SmartCardReadCount;
  261. UINT IsChangingUserName;
  262. UINT IsChangingPassword;
  263. CreduiAutoCompleteComboBox UserNameComboBox;
  264. LONG UserNameSelection;
  265. HSCARDUI ScardUiHandle;
  266. // Functions:
  267. BOOL InitWindow();
  268. BOOL CreateControls();
  269. BOOL InitComboBoxUserNames();
  270. BOOL AddCertificates();
  271. BOOL ViewCertificate(INT index);
  272. BOOL HandleSmartCardMessages(UINT message, CERT_ENUM *certEnum);
  273. INT FindSmartCardInComboBox(CERT_ENUM *certEnum);
  274. VOID RemoveSmartCardFromComboBox(CERT_ENUM *certEnum, BOOL removeParent);
  275. VOID Enable(BOOL enable = TRUE);
  276. VOID OnUserNameSelectionChange();
  277. BOOL OnSetUserNameA(CHAR *userNameA);
  278. BOOL OnSetUserName(WCHAR *userName);
  279. BOOL OnGetUserNameA(CHAR *userNameA, ULONG maxChars);
  280. BOOL OnGetUserName(WCHAR *userName, ULONG maxChars);
  281. BOOL OnSetPasswordA(CHAR *passwordA);
  282. BOOL OnSetPassword(WCHAR *password);
  283. BOOL OnGetPasswordA(CHAR *passwordA, ULONG maxChars);
  284. BOOL OnGetPassword(WCHAR *password, ULONG maxChars);
  285. LONG OnGetUserNameLength();
  286. BOOL OnShowBalloonA(CREDUI_BALLOONA *balloonA);
  287. BOOL OnShowBalloon(CREDUI_BALLOON *balloon);
  288. static LRESULT CALLBACK MessageHandlerCallback(
  289. HWND window,
  290. UINT message,
  291. WPARAM wParam,
  292. LPARAM lParam
  293. );
  294. LRESULT
  295. MessageHandler(
  296. UINT message,
  297. WPARAM wParam,
  298. LPARAM lParam
  299. );
  300. //
  301. // Command line specific data
  302. //
  303. BOOL DoingCommandLine;
  304. INT Heartbeats;
  305. #define CREDUI_HEARTBEAT_TIMER 1
  306. #define CREDUI_HEARTBEAT_TIMER_VALUE 2000
  307. #define CREDUI_MAX_HEARTBEATS 15
  308. #define CREDUI_TIMEOUT_HEARTBEATS 5
  309. LPWSTR TargetName;
  310. LPWSTR InitialUserName;
  311. void CmdlineSmartCardPrompt();
  312. void CmdlineSavePrompt();
  313. BOOL GetSmartCardInfo(
  314. IN DWORD SmartCardIndex,
  315. IN DWORD BufferLength,
  316. OUT LPWSTR Buffer,
  317. OUT BOOL *IsACard,
  318. OUT BOOL *IsValid,
  319. OUT CERT_ENUM **CertEnum OPTIONAL
  320. );
  321. LPWSTR MatchSmartCard(
  322. IN DWORD SmartCardCount,
  323. IN LPWSTR UserName,
  324. OUT LPDWORD RetCertIndex,
  325. OUT CERT_ENUM **RetCertEnum
  326. );
  327. };
  328. //-----------------------------------------------------------------------------
  329. #endif // __CONTROLS_HPP__