loginbox.cpp 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804
  1. #include "./common.h"
  2. #include "./loginBox.h"
  3. #include "./loginProvider.h"
  4. #include "./providerLoader.h"
  5. #include "./providerEnumerator.h"
  6. #include "./loginTemplate.h"
  7. #include "./loginCommand.h"
  8. #include "./loginPage.h"
  9. #include "./loginData.h"
  10. #include "./loginCredentials.h"
  11. #include "./loginCurtain.h"
  12. #include "./loginNotifier.h"
  13. #include "./loginPopup.h"
  14. #include "./popupAgreement.h"
  15. #include "./popupPasscode.h"
  16. #include "./popupMessage.h"
  17. #include "./pageEmpty.h"
  18. #include "./pageError.h"
  19. #include "./animation.h"
  20. #include "./loginStatus.h"
  21. #include "./providerOperation.h"
  22. #include "./loginConfig.h"
  23. #include "./loginTab.h"
  24. #include "./loginGui.h"
  25. #include "./download.h"
  26. #include "./downloadResult.h"
  27. #include "./imageCache.h"
  28. #include "../resource.h"
  29. #include "../api.h"
  30. #include "../api_auth.h"
  31. #include "../../nu/windowsTheme.h"
  32. #include "../../winamp/commandLink.h"
  33. #include "../../ombrowser/ifc_omcacherecord.h"
  34. #include <windows.h>
  35. #include <commctrl.h>
  36. #include <vssym32.h>
  37. #include <shlwapi.h>
  38. #include <strsafe.h>
  39. #define PROVIDERLIST_URL L"http://client.winamp.com/data/loginproviders"
  40. //#define PROVIDERLIST_URL L"http://dl.getdropbox.com/u/1994752/loginProviders.xml"
  41. // max mini in dpi
  42. #define LOGINBOX_MINWIDTH 153
  43. #define LOGINBOX_MINHEIGHT 140
  44. #define LOGINBOX_MAXWIDTH 800
  45. #define LOGINBOX_MAXHEIGHT 420
  46. #define NLBS_MODAL 0x00010000
  47. typedef struct __LOGINBOXCREATEPARAM
  48. {
  49. HWND hOwner;
  50. api_auth *auth;
  51. UINT style;
  52. const GUID *pRealm;
  53. } LOGINBOXCREATEPARAM;
  54. #define PROVIDEROP_UPDATE 0
  55. #define PROVIDEROP_REMOVE 1
  56. typedef struct __LOGINBOX
  57. {
  58. api_auth *auth;
  59. UINT style;
  60. GUID realm;
  61. RECT gripRect;
  62. LoginDownloadResult *providerUpdate;
  63. LoginResult *loginResult;
  64. LoginStatus *loginStatus;
  65. LoginProviderOperation *providerOp;
  66. BOOL agreementOk;
  67. RECT buttonMargins;
  68. LONG buttonHeight;
  69. LONG buttonSpace;
  70. LONG buttonTop;
  71. RECT minmaxInfo;
  72. LoginImageCache *imageCache;
  73. } LOGINBOX;
  74. #define TIMER_ID_CHECKIMAGES 20
  75. #define TIMER_DELAY_CHECKIMAGES 25
  76. typedef struct __LOGINBOXFIND
  77. {
  78. HWND hwnd;
  79. WCHAR buffer[32];
  80. GUID realm;
  81. } LOGINBOXFIND;
  82. #define LOGINBOX_PROP L"NullsoftAuthLoginBoxProp"
  83. #define GetLoginBox(__hwnd) ((LOGINBOX*)GetProp(__hwnd, LOGINBOX_PROP))
  84. #define IDC_TABFRAME 10000
  85. #define IDC_ACTIVEPAGE 10001
  86. #define IDC_NOTIFIER 10002
  87. #define IDC_CURTAIN 10003
  88. #define IDC_POPUPAGREEMENT 10004
  89. #define IDC_POPUPPASSCODE 10005
  90. #define IDC_POPUPPROVIDEROP 10006
  91. static INT_PTR CALLBACK LoginBox_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  92. static BOOL LoginBox_InitCreateParam(LOGINBOXCREATEPARAM *param, api_auth *auth, const GUID *pRealm, HWND hOwner, UINT style)
  93. {
  94. if (NULL == param)
  95. return FALSE;
  96. ZeroMemory(param, sizeof(LOGINBOXCREATEPARAM));
  97. param->style = style;
  98. param->hOwner = hOwner;
  99. param->pRealm = pRealm;
  100. param->auth = auth;
  101. if (NULL == auth)
  102. return FALSE;
  103. return TRUE;
  104. }
  105. HWND LoginBox_CreateWindow(api_auth *auth, const GUID *pRealm, HWND hOwner, UINT fStyle)
  106. {
  107. LOGINBOXCREATEPARAM param;
  108. if (FALSE == LoginBox_InitCreateParam(&param, auth, pRealm, hOwner, (0x0000FFFF & fStyle)))
  109. return NULL;
  110. return WASABI_API_CREATEDIALOGPARAMW(IDD_LOGINBOX, hOwner, LoginBox_DialogProc, (LPARAM)&param);
  111. }
  112. INT_PTR LoginBox_Show(api_auth *auth, const GUID *pRealm, HWND hOwner, UINT fStyle)
  113. {
  114. LOGINBOXCREATEPARAM param;
  115. if (FALSE == LoginBox_InitCreateParam(&param, auth, pRealm, hOwner, (0x0000FFFF & fStyle) | NLBS_MODAL))
  116. return -1;
  117. INT_PTR result = WASABI_API_DIALOGBOXPARAMW(IDD_LOGINBOX, hOwner, LoginBox_DialogProc, (LPARAM)&param);
  118. return result;
  119. }
  120. static BOOL CALLBACK LoginBox_WindowEnumerator(HWND hwnd, LPARAM lParam)
  121. {
  122. LOGINBOXFIND *find = (LOGINBOXFIND*)lParam;
  123. if (0 != GetClassName(hwnd, find->buffer, ARRAYSIZE(find->buffer)) &&
  124. CSTR_EQUAL == CompareString(CSTR_INVARIANT, 0, L"#32770", -1, find->buffer, -1))
  125. {
  126. LOGINBOX *login = GetLoginBox(hwnd);
  127. if (NULL != login && IsEqualGUID(find->realm, login->realm))
  128. {
  129. find->hwnd = hwnd;
  130. return FALSE;
  131. }
  132. }
  133. return TRUE;
  134. }
  135. HWND LoginBox_FindActive(const GUID *pRealm)
  136. {
  137. LOGINBOXFIND find;
  138. ZeroMemory(&find, sizeof(find));
  139. find.realm = (NULL == pRealm) ? GUID_NULL : *pRealm;
  140. EnumWindows(LoginBox_WindowEnumerator, (LPARAM)&find);
  141. return find.hwnd;
  142. }
  143. static void LoginBox_ShowNotifier(HWND hwnd, INT durationMs)
  144. {
  145. if (NULL == hwnd) return;
  146. HWND hNotifier = GetDlgItem(hwnd, IDC_NOTIFIER);
  147. if (NULL == hNotifier) return;
  148. LONG targetHeight = (LONG)LoginNotifier_GetIdealHeight(hNotifier);
  149. RECT notifierRect;
  150. GetWindowRect(hNotifier, &notifierRect);
  151. LONG currentHeight = notifierRect.bottom - notifierRect.top;
  152. LONG notifierWidth = notifierRect.right - notifierRect.left;
  153. if (currentHeight < targetHeight)
  154. {
  155. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&notifierRect, 2);
  156. HWND hPage = GetDlgItem(hwnd, IDC_ACTIVEPAGE);
  157. RECT pageRect;
  158. if (NULL != hPage)
  159. {
  160. GetWindowRect(hPage, &pageRect);
  161. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&pageRect, 2);
  162. }
  163. LONG pageWidth = pageRect.right - pageRect.left;
  164. LONG pageHeight = pageRect.bottom - pageRect.top;
  165. UINT pageStyle = (NULL != hPage) ? GetWindowStyle(hPage) : 0;
  166. if (0 != (WS_VISIBLE & pageStyle))
  167. SetWindowLongPtr(hPage, GWL_STYLE, pageStyle & ~WS_VISIBLE);
  168. UINT notifierStyle = GetWindowStyle(hNotifier);
  169. if (0 != (WS_VISIBLE & notifierStyle))
  170. SetWindowLongPtr(hNotifier, GWL_STYLE, notifierStyle & ~WS_VISIBLE);
  171. SetWindowPos(hNotifier, NULL, 0, 0, notifierWidth, targetHeight,
  172. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOREDRAW | SWP_NOCOPYBITS);
  173. if (durationMs > 0)
  174. {
  175. HDC targetDc = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_NORESETATTRS);
  176. if (NULL != targetDc)
  177. {
  178. HDC composeDc = CreateCompatibleDC(targetDc);
  179. if (NULL != composeDc)
  180. {
  181. HBITMAP composeBmp = CreateCompatibleBitmap(targetDc,
  182. (notifierWidth > pageWidth) ? notifierWidth : pageWidth,
  183. targetHeight + pageHeight);
  184. if (NULL != composeBmp)
  185. {
  186. HBITMAP composeBmpOrig = (HBITMAP)SelectObject(composeDc, composeBmp);
  187. SendMessage(hNotifier, WM_PRINTCLIENT, (WPARAM)composeDc, (LPARAM)(PRF_CLIENT | PRF_ERASEBKGND));
  188. ANIMATIONDATA animation;
  189. if (FALSE != Animation_Initialize(&animation, durationMs))
  190. {
  191. while(currentHeight++ < targetHeight)
  192. {
  193. Animation_BeginStep(&animation);
  194. Animation_SetWindowPos(hPage, pageRect.left, ++pageRect.top, pageWidth, --pageHeight,
  195. 0, composeDc, 0, targetHeight);
  196. BitBlt(targetDc, notifierRect.left, notifierRect.top, notifierWidth, currentHeight, composeDc, 0, targetHeight - currentHeight, SRCCOPY);
  197. if (NULL != hPage)
  198. BitBlt(targetDc, pageRect.left, pageRect.top, pageWidth, pageHeight, composeDc, 0, targetHeight, SRCCOPY);
  199. Animation_EndStep(&animation, targetHeight - currentHeight);
  200. }
  201. }
  202. SelectObject(composeDc, composeBmpOrig);
  203. DeleteObject(composeBmp);
  204. }
  205. DeleteDC(composeDc);
  206. }
  207. ReleaseDC(hwnd, targetDc);
  208. }
  209. }
  210. if (0 != (WS_VISIBLE & pageStyle))
  211. {
  212. SetWindowLongPtr(hPage, GWL_STYLE, pageStyle);
  213. INT delta = (targetHeight - currentHeight);
  214. if (delta > 0)
  215. {
  216. SetWindowPos(hPage, NULL, pageRect.left, pageRect.top + delta, pageWidth, pageHeight - delta,
  217. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOCOPYBITS);
  218. }
  219. RedrawWindow(hPage, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN | RDW_ERASENOW | RDW_ERASE);
  220. }
  221. LoginNotifier_PlayBeep(hNotifier);
  222. ShowWindow(hNotifier, SW_SHOWNA);
  223. UpdateWindow(hNotifier);
  224. }
  225. }
  226. static void LoginBox_HideNotifier(HWND hwnd, INT durationMs)
  227. {
  228. if (NULL == hwnd) return;
  229. HWND hNotifier = GetDlgItem(hwnd, IDC_NOTIFIER);
  230. if (NULL == hNotifier) return;
  231. UINT notifierStyle = GetWindowStyle(hNotifier);
  232. if (0 == (WS_VISIBLE & notifierStyle)) return;
  233. SetWindowLongPtr(hNotifier, GWL_STYLE, notifierStyle & ~WS_VISIBLE);
  234. RECT notifierRect;
  235. GetWindowRect(hNotifier, &notifierRect);
  236. LONG currentHeight = notifierRect.bottom - notifierRect.top;
  237. LONG startHeight = currentHeight;
  238. LONG notifierWidth = notifierRect.right - notifierRect.left;
  239. if (currentHeight > 0)
  240. {
  241. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&notifierRect, 2);
  242. HWND hPage = GetDlgItem(hwnd, IDC_ACTIVEPAGE);
  243. RECT pageRect;
  244. if (NULL != hPage)
  245. {
  246. GetWindowRect(hPage, &pageRect);
  247. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&pageRect, 2);
  248. }
  249. LONG pageWidth = pageRect.right - pageRect.left;
  250. LONG pageHeight = pageRect.bottom - pageRect.top;
  251. UINT pageStyle = (NULL != hPage) ? GetWindowStyle(hPage) : 0;
  252. if (0 != (WS_VISIBLE & pageStyle))
  253. SetWindowLongPtr(hPage, GWL_STYLE, pageStyle & ~WS_VISIBLE);
  254. if (durationMs > 0)
  255. {
  256. HDC targetDc = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_NORESETATTRS);
  257. if (NULL != targetDc)
  258. {
  259. HDC composeDc = CreateCompatibleDC(targetDc);
  260. if (NULL != composeDc)
  261. {
  262. HBITMAP composeBmp = CreateCompatibleBitmap(targetDc,
  263. (notifierWidth > pageWidth) ? notifierWidth : pageWidth,
  264. 2*startHeight + pageHeight);
  265. if (NULL != composeBmp)
  266. {
  267. HBITMAP composeBmpOrig = (HBITMAP)SelectObject(composeDc, composeBmp);
  268. SendMessage(hNotifier, WM_PRINTCLIENT, (WPARAM)composeDc, (LPARAM)(PRF_CLIENT | PRF_ERASEBKGND));
  269. ANIMATIONDATA animation;
  270. if (FALSE != Animation_Initialize(&animation, durationMs))
  271. {
  272. while(currentHeight-- > 0)
  273. {
  274. Animation_BeginStep(&animation);
  275. if (FALSE != Animation_SetWindowPos(hPage, pageRect.left, --pageRect.top, pageWidth, ++pageHeight,
  276. 0, composeDc, 0, startHeight))
  277. {
  278. BitBlt(targetDc, pageRect.left, pageRect.top, pageWidth, pageHeight, composeDc, 0, startHeight, SRCCOPY);
  279. }
  280. BitBlt(targetDc, notifierRect.left, notifierRect.top, notifierWidth, currentHeight, composeDc, 0, startHeight - currentHeight, SRCCOPY);
  281. Animation_EndStep(&animation, currentHeight);
  282. }
  283. }
  284. SelectObject(composeDc, composeBmpOrig);
  285. DeleteObject(composeBmp);
  286. }
  287. DeleteDC(composeDc);
  288. }
  289. ReleaseDC(hwnd, targetDc);
  290. }
  291. }
  292. if (0 != (WS_VISIBLE & pageStyle))
  293. {
  294. SetWindowLongPtr(hPage, GWL_STYLE, pageStyle);
  295. INT delta = currentHeight;
  296. if (delta > 0)
  297. {
  298. SetWindowPos(hPage, NULL, pageRect.left, pageRect.top - delta, pageWidth, pageHeight + delta,
  299. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOCOPYBITS);
  300. }
  301. RedrawWindow(hPage, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN | RDW_ERASENOW | RDW_ERASE);
  302. }
  303. SetWindowPos(hNotifier, NULL, 0, 0, notifierWidth, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOREDRAW | SWP_NOCOPYBITS);
  304. }
  305. }
  306. static HRESULT LoginBox_SaveUsername(const GUID *realm, LoginProvider *provider, LoginCredentials *credentials)
  307. {
  308. if (NULL == realm || NULL == provider || NULL == credentials)
  309. return E_INVALIDARG;
  310. HRESULT hr;
  311. LoginConfig *config;
  312. hr = LoginConfig::CreateInstance(&config);
  313. if (FAILED(hr)) return hr;
  314. RPC_CSTR pszRealm;
  315. if (RPC_S_OK == UuidToStringA(realm, &pszRealm))
  316. {
  317. GUID providerId;
  318. RPC_CSTR pszProvider;
  319. if (SUCCEEDED(provider->GetId(&providerId)) &&
  320. RPC_S_OK == UuidToStringA(&providerId, &pszProvider))
  321. {
  322. LPCWSTR pszUser = credentials->GetUsername();
  323. LPSTR pszUserAnsi;
  324. if (NULL != pszUser && L'\0' != *pszUser)
  325. hr = LoginBox_WideCharToMultiByte(CP_UTF8, 0, pszUser, -1, NULL, NULL, &pszUserAnsi);
  326. else
  327. pszUserAnsi = NULL;
  328. if (SUCCEEDED(hr))
  329. {
  330. hr = config->WriteAnsiStr((LPCSTR)pszRealm, (LPCSTR)pszProvider, pszUserAnsi);
  331. LoginBox_FreeAnsiString(pszUserAnsi);
  332. }
  333. RpcStringFreeA(&pszProvider);
  334. }
  335. else
  336. hr = E_FAIL;
  337. RpcStringFreeA(&pszRealm);
  338. }
  339. else
  340. hr = E_FAIL;
  341. config->Release();
  342. return hr;
  343. }
  344. static HRESULT LoginBox_LoadUsername(const GUID *realm, LoginProvider *provider, LPWSTR pszBuffer, UINT cchBufferMax)
  345. {
  346. if (NULL == pszBuffer)
  347. return E_POINTER;
  348. if (NULL == realm || NULL == provider)
  349. return E_INVALIDARG;
  350. HRESULT hr;
  351. LoginConfig *config;
  352. hr = LoginConfig::CreateInstance(&config);
  353. if (FAILED(hr)) return hr;
  354. RPC_CSTR pszRealm;
  355. if (RPC_S_OK == UuidToStringA(realm, &pszRealm))
  356. {
  357. GUID providerId;
  358. RPC_CSTR pszProvider;
  359. if (SUCCEEDED(provider->GetId(&providerId)) &&
  360. RPC_S_OK == UuidToStringA(&providerId, &pszProvider))
  361. {
  362. CHAR szUserAnsi[1024] = {0};
  363. INT cchUser = config->ReadAnsiStr((LPCSTR)pszRealm, (LPCSTR)pszProvider, NULL, szUserAnsi, ARRAYSIZE(szUserAnsi));
  364. if (0 == cchUser)
  365. pszBuffer[0] = L'\0';
  366. else
  367. {
  368. cchUser = MultiByteToWideChar(CP_UTF8, 0, szUserAnsi, cchUser, pszBuffer, cchBufferMax);
  369. if (0 == cchUser)
  370. hr = HRESULT_FROM_WIN32(GetLastError());
  371. else
  372. pszBuffer[cchUser] = L'\0';
  373. }
  374. RpcStringFreeA(&pszProvider);
  375. }
  376. else
  377. hr = E_FAIL;
  378. RpcStringFreeA(&pszRealm);
  379. }
  380. else
  381. hr = E_FAIL;
  382. config->Release();
  383. return hr;
  384. }
  385. static BOOL LoginBox_SelectActivePage(HWND hwnd)
  386. {
  387. LOGINBOX *loginbox = GetLoginBox(hwnd);
  388. if (NULL == loginbox) return FALSE;
  389. loginbox->agreementOk = FALSE;
  390. LoginBox_HideNotifier(hwnd, 0);
  391. HWND hFrame = GetDlgItem(hwnd, IDC_TABFRAME);
  392. if (NULL == hFrame) return FALSE;
  393. HWND hPageOld = GetDlgItem(hwnd, IDC_ACTIVEPAGE);
  394. if (NULL != hPageOld)
  395. SetWindowLongPtr(hPageOld, GWLP_ID, 0);
  396. BOOL enableLogin = FALSE;
  397. HWND hPage = NULL;
  398. LoginProvider *provider = NULL;
  399. INT iIndex = LoginTab_GetCurSel(hFrame);
  400. if (-1 != iIndex)
  401. {
  402. NLTITEM tabItem;
  403. tabItem.mask = NLTIF_PARAM;
  404. provider = (TRUE == LoginTab_GetItem(hFrame, iIndex, &tabItem)) ?
  405. (LoginProvider*)tabItem.param : NULL;
  406. if (NULL != provider)
  407. {
  408. LoginTemplate *pageTemplate;
  409. if (SUCCEEDED(provider->GetTemplate(&pageTemplate)) && NULL != pageTemplate)
  410. {
  411. hPage = pageTemplate->CreatePage(hwnd, hwnd);
  412. pageTemplate->Release();
  413. }
  414. LoginCommand *command;
  415. if (SUCCEEDED(provider->GetCommand(&command)) && NULL != command)
  416. {
  417. enableLogin = (S_OK == command->IsValid());
  418. command->Release();
  419. }
  420. }
  421. }
  422. if (NULL == hPage)
  423. {
  424. hPage = (-1 == iIndex) ?
  425. LoginPageEmpty::CreatePage(hwnd, hwnd) :
  426. LoginPageError::CreatePage(hwnd, hwnd);
  427. }
  428. if (NULL != hPage)
  429. {
  430. //if (S_OK == UxTheme_IsThemeActive())
  431. // UxEnableThemeDialogTexture(hPage, ETDT_ENABLETAB);
  432. SetWindowLongPtr(hPage, GWLP_ID, IDC_ACTIVEPAGE);
  433. RECT rect;
  434. if (NULL != hPageOld && FALSE != GetWindowRect(hPageOld, &rect))
  435. {
  436. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&rect, 2);
  437. SetWindowPos(hPage, HWND_TOP, rect.left, rect.top,
  438. rect.right - rect.left, rect.bottom - rect.top,
  439. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOREDRAW);
  440. }
  441. else
  442. {
  443. SetWindowPos(hPage, HWND_TOP, 0, 0, 0, 0,
  444. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOSIZE | SWP_NOMOVE);
  445. SetWindowPos(hwnd, NULL, 0, 0, 0, 0,
  446. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_FRAMECHANGED | SWP_NOZORDER);
  447. }
  448. WCHAR szUsername[512] = {0};
  449. if(SUCCEEDED(LoginBox_LoadUsername(&loginbox->realm, provider, szUsername, ARRAYSIZE(szUsername))) &&
  450. L'\0' != szUsername[0])
  451. {
  452. LoginPage_SetUsername(hPage, szUsername);
  453. }
  454. ShowWindow(hPage, SW_SHOWNORMAL);
  455. if (WS_VISIBLE == ((WS_VISIBLE | WS_DISABLED) & GetWindowStyle(hPage)))
  456. {
  457. HWND hFocus = GetFocus();
  458. if (hFrame != hFocus)
  459. {
  460. HWND hTarget = LoginPage_GetFirstItem(hPage);
  461. if (NULL == hTarget ||
  462. ((WS_VISIBLE | WS_TABSTOP) != ((WS_VISIBLE | WS_TABSTOP | WS_DISABLED) & GetWindowStyle(hTarget))))
  463. {
  464. hTarget = GetNextDlgTabItem(hwnd, hFrame, FALSE);
  465. }
  466. if (NULL != hTarget && hTarget != hFocus)
  467. PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)hTarget, TRUE);
  468. }
  469. }
  470. }
  471. else
  472. {
  473. enableLogin = FALSE;
  474. }
  475. HWND hButton = GetDlgItem(hwnd, IDOK);
  476. if (NULL != hButton)
  477. EnableWindow(hButton, enableLogin);
  478. if (NULL != hPageOld)
  479. {
  480. DestroyWindow(hPageOld);
  481. }
  482. return TRUE;
  483. }
  484. static BOOL LoginBox_RemoveImageHelper(HWND hFrame, HIMAGELIST imageList, UINT imageIndex)
  485. {
  486. if (NLTM_IMAGE_NONE == imageIndex || NLTM_IMAGE_CALLBACK == imageIndex)
  487. return FALSE;
  488. UINT imageListCount = ImageList_GetImageCount(imageList);
  489. if (imageIndex > imageListCount)
  490. return FALSE;
  491. INT iItem = LoginTab_GetItemCount(hFrame);
  492. NLTITEM tab;
  493. while(iItem--)
  494. {
  495. tab.mask = NLTIF_IMAGE_MASK;
  496. if (FALSE != LoginTab_GetItem(hFrame, iItem, &tab))
  497. {
  498. tab.mask = 0;
  499. if (tab.iImage >= imageIndex && tab.iImage < imageListCount)
  500. {
  501. tab.iImage = (tab.iImage != imageIndex) ? --tab.iImage : NLTM_IMAGE_NONE;
  502. tab.mask |= NLTIF_IMAGE;
  503. }
  504. if (tab.iImageActive >= imageIndex && tab.iImageActive < imageListCount)
  505. {
  506. tab.iImageActive = (tab.iImageActive != imageIndex) ? --tab.iImageActive : NLTM_IMAGE_NONE;
  507. tab.mask |= NLTIF_IMAGE_ACTIVE;
  508. }
  509. if (tab.iImageDisabled >= imageIndex && tab.iImageDisabled < imageListCount)
  510. {
  511. tab.iImageDisabled = (tab.iImageDisabled != imageIndex) ? --tab.iImageDisabled : NLTM_IMAGE_NONE;
  512. tab.mask |= NLTIF_IMAGE_DISABLED;
  513. }
  514. if (0 != tab.mask)
  515. LoginTab_SetItem(hFrame, iItem, &tab);
  516. }
  517. }
  518. return ImageList_Remove(imageList, imageIndex);
  519. }
  520. #define IS_IMAGEINDEX_VALID(__imageIndex) (((INT)(__imageIndex)) >= 0)
  521. static BOOL LoginBox_RemoveImageHelper2(HWND hFrame, NLTITEM *tab)
  522. {
  523. if (NULL == tab) return FALSE;
  524. HIMAGELIST imageList = LoginTab_GetImageList(hFrame);
  525. if (NULL == imageList) return FALSE;
  526. if (IS_IMAGEINDEX_VALID(tab->iImageActive) &&
  527. FALSE != LoginBox_RemoveImageHelper(hFrame, imageList, tab->iImageActive))
  528. {
  529. if (IS_IMAGEINDEX_VALID(tab->iImage))
  530. {
  531. if (tab->iImage > tab->iImageActive) tab->iImage--;
  532. else if (tab->iImage == tab->iImageActive) tab->iImage = NLTM_IMAGE_CALLBACK;
  533. }
  534. if (IS_IMAGEINDEX_VALID(tab->iImageDisabled))
  535. {
  536. if (tab->iImageDisabled > tab->iImageActive) tab->iImageDisabled--;
  537. else if (tab->iImageDisabled == tab->iImageActive) tab->iImageDisabled = NLTM_IMAGE_CALLBACK;
  538. }
  539. }
  540. if (IS_IMAGEINDEX_VALID(tab->iImage) &&
  541. FALSE != LoginBox_RemoveImageHelper(hFrame, imageList, tab->iImageActive))
  542. {
  543. if (IS_IMAGEINDEX_VALID(tab->iImageActive))
  544. {
  545. if (tab->iImageActive > tab->iImage) tab->iImageActive--;
  546. else if (tab->iImageActive == tab->iImage) tab->iImageActive = NLTM_IMAGE_CALLBACK;
  547. }
  548. if (IS_IMAGEINDEX_VALID(tab->iImageDisabled))
  549. {
  550. if (tab->iImageDisabled > tab->iImage) tab->iImageDisabled--;
  551. else if (tab->iImageDisabled == tab->iImage) tab->iImageDisabled = NLTM_IMAGE_CALLBACK;
  552. }
  553. }
  554. if (IS_IMAGEINDEX_VALID(tab->iImageDisabled) &&
  555. FALSE != LoginBox_RemoveImageHelper(hFrame, imageList, tab->iImageDisabled))
  556. {
  557. if (IS_IMAGEINDEX_VALID(tab->iImageActive))
  558. {
  559. if (tab->iImageActive > tab->iImageDisabled) tab->iImageActive--;
  560. else if (tab->iImageActive == tab->iImageDisabled) tab->iImageActive = NLTM_IMAGE_CALLBACK;
  561. }
  562. if (IS_IMAGEINDEX_VALID(tab->iImage))
  563. {
  564. if (tab->iImage > tab->iImageDisabled) tab->iImage--;
  565. else if (tab->iImage == tab->iImageDisabled) tab->iImage = NLTM_IMAGE_CALLBACK;
  566. }
  567. }
  568. return TRUE;
  569. }
  570. static INT LoginBox_AppendMultipleTabs(HWND hwnd, LoginProviderEnumerator *enumerator, const GUID *filterOut, INT *filteredIndex)
  571. {
  572. LOGINBOX *loginbox = GetLoginBox(hwnd);
  573. if (NULL == loginbox) return -1;
  574. HWND hFrame = GetDlgItem(hwnd, IDC_TABFRAME);
  575. if (NULL == hFrame) return -1;
  576. if (NULL == enumerator)
  577. return 0;
  578. GUID testId;
  579. INT baseIndex = LoginTab_GetItemCount(hwnd);
  580. INT count = 0;
  581. NLTITEM tab;
  582. WCHAR szTitle[256] = {0};
  583. tab.mask = NLTIF_TEXT | NLTIF_PARAM | NLTIF_IMAGE_MASK;
  584. LoginProvider *provider;
  585. while(S_OK == enumerator->Next(1, &provider, NULL))
  586. {
  587. if (NULL != filterOut && SUCCEEDED(provider->GetId(&testId)) && FALSE != IsEqualGUID(testId, *filterOut))
  588. {
  589. if (NULL != filteredIndex)
  590. *filteredIndex = baseIndex + count;
  591. }
  592. else
  593. {
  594. if (FAILED(provider->GetName(szTitle, ARRAYSIZE(szTitle))))
  595. szTitle[0] = L'\0';
  596. tab.param = (LPARAM)provider;
  597. tab.pszText = (LPWSTR)szTitle;
  598. tab.iImage = NLTM_IMAGE_CALLBACK;
  599. tab.iImageActive = NLTM_IMAGE_CALLBACK;
  600. tab.iImageDisabled = NLTM_IMAGE_CALLBACK;
  601. if (-1 != LoginTab_InsertItem(hFrame, baseIndex + count, &tab))
  602. {
  603. provider->AddRef();
  604. count++;
  605. }
  606. }
  607. provider->Release();
  608. }
  609. return count;
  610. }
  611. static INT LoginBox_InsertTab(HWND hwnd, INT index, LoginProvider *provider)
  612. {
  613. LOGINBOX *loginbox = GetLoginBox(hwnd);
  614. if (NULL == loginbox) return -1;
  615. HWND hFrame = GetDlgItem(hwnd, IDC_TABFRAME);
  616. if (NULL == hFrame) return -1;
  617. if (NULL == provider)
  618. return -1;
  619. INT count = LoginTab_GetItemCount(hFrame);
  620. if (index > count) index = count;
  621. NLTITEM tab;
  622. WCHAR szTitle[256] = {0};
  623. if (FAILED(provider->GetName(szTitle, ARRAYSIZE(szTitle))))
  624. szTitle[0] = L'\0';
  625. tab.mask = NLTIF_TEXT | NLTIF_PARAM | NLTIF_IMAGE_MASK;
  626. tab.param = (LPARAM)provider;
  627. tab.pszText = (LPWSTR)szTitle;
  628. tab.iImage = NLTM_IMAGE_CALLBACK;
  629. tab.iImageActive = NLTM_IMAGE_CALLBACK;
  630. tab.iImageDisabled = NLTM_IMAGE_CALLBACK;
  631. index = LoginTab_InsertItem(hFrame, index, &tab);
  632. if (-1 != index)
  633. provider->AddRef();
  634. return index;
  635. }
  636. static INT LoginBox_FindTabByProviderId(HWND hwnd, const GUID *providerId)
  637. {
  638. if (NULL == providerId)
  639. return -1;
  640. HWND hFrame = GetDlgItem(hwnd, IDC_TABFRAME);
  641. if (NULL == hFrame) return -1;
  642. NLTITEM tab;
  643. tab.mask = NLTIF_PARAM;
  644. INT count = LoginTab_GetItemCount(hFrame);
  645. GUID testId;
  646. for (INT i =0; i < count; i++)
  647. {
  648. if (FALSE != LoginTab_GetItem(hFrame, i, &tab))
  649. {
  650. if (NULL != tab.param)
  651. {
  652. LoginProvider *provider = (LoginProvider*)tab.param;
  653. if (SUCCEEDED(provider->GetId(&testId)) && FALSE != IsEqualGUID(testId, *providerId))
  654. return i;
  655. }
  656. }
  657. }
  658. return -1;
  659. }
  660. static void LoginBox_DeleteAllTabs(HWND hwnd)
  661. {
  662. HWND hFrame = GetDlgItem(hwnd, IDC_TABFRAME);
  663. if (NULL == hFrame) return;
  664. LoginTab_DeleteAllItems(hFrame);
  665. }
  666. static BOOL LoginBox_ReplaceProvider(HWND hwnd, const GUID *sourceId, LoginProvider *target)
  667. {
  668. if (NULL == sourceId || NULL == target)
  669. return FALSE;
  670. LOGINBOX *loginbox = GetLoginBox(hwnd);
  671. if (NULL == loginbox) return FALSE;
  672. HWND hFrame = GetDlgItem(hwnd, IDC_TABFRAME);
  673. if (NULL == hFrame) return FALSE;
  674. GUID testId;
  675. BOOL resultOk = FALSE;
  676. NLTITEM tab;
  677. tab.mask = NLTIF_PARAM | NLTIF_IMAGE_MASK;
  678. INT count = LoginTab_GetItemCount(hFrame);
  679. for (INT i =0; i < count; i++)
  680. {
  681. if (FALSE != LoginTab_GetItem(hFrame, i, &tab))
  682. {
  683. LoginProvider *provider = (LoginProvider*)tab.param;
  684. if (NULL != provider && SUCCEEDED(provider->GetId(&testId)) && IsEqualGUID(*sourceId, testId))
  685. {
  686. tab.mask = NLTIF_TEXT | NLTIF_PARAM | NLTIF_IMAGE_MASK;
  687. tab.param = (LPARAM)target;
  688. WCHAR szTitle[256] = {0};
  689. if (FAILED(target->GetName(szTitle, ARRAYSIZE(szTitle))))
  690. szTitle[0] = L'\0';
  691. tab.pszText = szTitle;
  692. LoginBox_RemoveImageHelper2(hFrame, &tab);
  693. tab.iImage = NLTM_IMAGE_CALLBACK;
  694. tab.iImageActive = NLTM_IMAGE_CALLBACK;
  695. tab.iImageDisabled = NLTM_IMAGE_CALLBACK;
  696. if (TRUE == LoginTab_SetItem(hFrame,i, &tab))
  697. {
  698. target->AddRef();
  699. resultOk = TRUE;
  700. if (i == LoginTab_GetCurSel(hFrame))
  701. LoginBox_SelectActivePage(hwnd);
  702. provider->Release();
  703. }
  704. break;
  705. }
  706. }
  707. }
  708. return resultOk;
  709. }
  710. static BOOL LoginBox_DeleteProvider(HWND hwnd, const GUID *providerId)
  711. {
  712. if (NULL == providerId)
  713. return FALSE;
  714. HWND hFrame = GetDlgItem(hwnd, IDC_TABFRAME);
  715. if (NULL == hFrame) return FALSE;
  716. GUID testId;
  717. BOOL resultOk = FALSE;
  718. NLTITEM tab;
  719. tab.mask = NLTIF_PARAM;
  720. INT count = LoginTab_GetItemCount(hFrame);
  721. for (INT i =0; i < count; i++)
  722. {
  723. if (FALSE != LoginTab_GetItem(hFrame, i, &tab))
  724. {
  725. LoginProvider *provider = (LoginProvider*)tab.param;
  726. if (NULL != provider && SUCCEEDED(provider->GetId(&testId)) && IsEqualGUID(*providerId, testId))
  727. {
  728. BOOL updateSelection = (i == LoginTab_GetCurSel(hFrame));
  729. if (TRUE == LoginTab_DeleteItem(hFrame, i))
  730. {
  731. resultOk = TRUE;
  732. if (FALSE != updateSelection)
  733. {
  734. LoginTab_SetCurSel(hFrame, 0);
  735. LoginBox_SelectActivePage(hwnd);
  736. }
  737. }
  738. break;
  739. }
  740. }
  741. }
  742. return resultOk;
  743. }
  744. static BOOL LoginBox_CenterOver(HWND hwnd, HWND hOwner)
  745. {
  746. RECT rect, rectOwner;
  747. if (NULL == hwnd || FALSE == GetWindowRect(hwnd, &rect))
  748. return FALSE;
  749. if(NULL == hOwner || FALSE == GetWindowRect(hOwner, &rectOwner))
  750. {
  751. HMONITOR hMonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY);
  752. if (NULL == hMonitor) return FALSE;
  753. MONITORINFO mi;
  754. mi.cbSize = sizeof(mi);
  755. if (FALSE == GetMonitorInfo(hMonitor, &mi)) return FALSE;
  756. CopyRect(&rectOwner, &mi.rcWork);
  757. }
  758. LONG x = rectOwner.left + ((rectOwner.right - rectOwner.left) - (rect.right - rect.left))/2;
  759. LONG y = rectOwner.top + ((rectOwner.bottom - rectOwner.top) - (rect.bottom - rect.top))/2;
  760. return SetWindowPos(hwnd, NULL, x, y, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
  761. }
  762. static void LoginBox_UpdateMargins(HWND hwnd)
  763. {
  764. LOGINBOX *loginbox = GetLoginBox(hwnd);
  765. if (NULL == loginbox) return;
  766. RECT rect;
  767. SetRect(&rect, 4, 14, 0, 0);
  768. MapDialogRect(hwnd, &rect);
  769. loginbox->buttonHeight = rect.top;
  770. loginbox->buttonSpace = rect.left;
  771. HWND hControl = GetDlgItem(hwnd, IDOK);
  772. if (NULL != hControl)
  773. {
  774. loginbox->buttonHeight = LoginBox_GetWindowTextHeight(hControl, 3);
  775. }
  776. if (loginbox->buttonHeight < 23)
  777. loginbox->buttonHeight = 23;
  778. SetRect(&rect, 2, 8, 8, 6);
  779. MapDialogRect(hwnd, &rect);
  780. CopyRect(&loginbox->buttonMargins, &rect);
  781. SetRect(&loginbox->minmaxInfo, LOGINBOX_MINWIDTH, LOGINBOX_MINHEIGHT, LOGINBOX_MAXWIDTH, LOGINBOX_MAXHEIGHT);
  782. MapDialogRect(hwnd, &loginbox->minmaxInfo);
  783. }
  784. static BOOL LoginBox_GetGripSize(HWND hwnd, HDC hdc, SIZE *gripSize)
  785. {
  786. BOOL gripSizeOk = FALSE;
  787. if (SUCCEEDED(UxTheme_LoadLibrary()) && FALSE != UxIsAppThemed())
  788. {
  789. UXTHEME hTheme = UxOpenThemeData(hwnd, L"Scrollbar");
  790. if (NULL != hTheme)
  791. {
  792. if (SUCCEEDED(UxGetThemePartSize(hTheme, hdc, SBP_SIZEBOX, SZB_RIGHTALIGN, NULL, TS_TRUE, gripSize)))
  793. gripSizeOk = TRUE;
  794. UxCloseThemeData(hTheme);
  795. }
  796. }
  797. if (FALSE == gripSizeOk)
  798. {
  799. gripSize->cx = GetSystemMetrics(SM_CXVSCROLL);
  800. gripSize->cy = GetSystemMetrics(SM_CYHSCROLL);
  801. }
  802. return TRUE;
  803. }
  804. static void LoginBox_LayoutGrip(HWND hwnd)
  805. {
  806. LOGINBOX *loginbox = GetLoginBox(hwnd);
  807. if (NULL == loginbox) return;
  808. HDC hdc = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_NORESETATTRS);
  809. if (NULL != hdc)
  810. {
  811. SIZE gripSize;
  812. if (FALSE != LoginBox_GetGripSize(hwnd, hdc, &gripSize))
  813. {
  814. GetClientRect(hwnd, &loginbox->gripRect);
  815. loginbox->gripRect.left = loginbox->gripRect.right - gripSize.cx;
  816. loginbox->gripRect.top = loginbox->gripRect.bottom - gripSize.cy;
  817. LONG test;
  818. test = gripSize.cx - MulDiv(gripSize.cx, 2, 3);
  819. if (loginbox->buttonMargins.right < test)
  820. loginbox->buttonMargins.right = test;
  821. test = gripSize.cy - MulDiv(gripSize.cy, 2, 3);
  822. if (loginbox->buttonMargins.bottom < test)
  823. loginbox->buttonMargins.bottom = test;
  824. }
  825. ReleaseDC(hwnd, hdc);
  826. }
  827. }
  828. static void LoginBox_UpdateLayout(HWND hwnd, BOOL fRedraw)
  829. {
  830. LOGINBOX *loginbox = GetLoginBox(hwnd);
  831. if (NULL == loginbox) return;
  832. RECT clientRect;
  833. if (NULL == hwnd || FALSE == GetClientRect(hwnd, &clientRect))
  834. return;
  835. UINT swpFlags = SWP_NOACTIVATE | SWP_NOZORDER;
  836. if (FALSE == fRedraw) swpFlags |= SWP_NOREDRAW;
  837. const INT szButtons[] = { IDOK, IDCANCEL, };
  838. const INT szControls[] = { IDC_STATUS, IDC_TABFRAME, IDC_NOTIFIER, IDC_ACTIVEPAGE, IDC_CURTAIN, };
  839. HDWP hdwp = BeginDeferWindowPos(ARRAYSIZE(szButtons) + ARRAYSIZE(szControls));
  840. if (NULL == hdwp) return;
  841. RECT rect;
  842. HRGN rgnUpdate(NULL), rgn(NULL);
  843. if (FALSE != fRedraw)
  844. {
  845. rgnUpdate = CreateRectRgn(0, 0, 0, 0);
  846. rgn = CreateRectRgn(0,0,0,0);
  847. if (FALSE == IsRectEmpty(&loginbox->gripRect))
  848. {
  849. SetRectRgn(rgn, loginbox->gripRect.left, loginbox->gripRect.top,
  850. loginbox->gripRect.right, loginbox->gripRect.bottom);
  851. CombineRgn(rgnUpdate, rgnUpdate, rgn, RGN_OR);
  852. }
  853. if (loginbox->buttonTop > clientRect.top)
  854. {
  855. SetRectRgn(rgn, clientRect.left, loginbox->buttonTop, clientRect.right, loginbox->buttonTop + 1);
  856. CombineRgn(rgnUpdate, rgnUpdate, rgn, RGN_OR);
  857. }
  858. }
  859. LoginBox_LayoutGrip(hwnd);
  860. CopyRect(&rect, &clientRect);
  861. rect.left += loginbox->buttonMargins.left;
  862. rect.top += loginbox->buttonMargins.top;
  863. rect.right -= loginbox->buttonMargins.right;
  864. rect.bottom -= loginbox->buttonMargins.bottom;
  865. hdwp = LoginBox_LayoutButtonBar(hdwp, hwnd, szButtons, ARRAYSIZE(szButtons), &rect,
  866. loginbox->buttonHeight, loginbox->buttonSpace, fRedraw, &rect);
  867. loginbox->buttonTop = rect.top - loginbox->buttonMargins.top;
  868. if (NULL != rgn && loginbox->buttonTop > clientRect.top)
  869. {
  870. SetRectRgn(rgn, clientRect.left, loginbox->buttonTop, clientRect.right, loginbox->buttonTop + 1);
  871. CombineRgn(rgnUpdate, rgnUpdate, rgn, RGN_OR);
  872. }
  873. LONG statusRight = rect.left - loginbox->buttonSpace;
  874. LONG pageTop = clientRect.top;
  875. LONG pageBottom = loginbox->buttonTop;
  876. UINT flags;
  877. if (NULL != rgn)
  878. {
  879. SetRectRgn(rgn, loginbox->gripRect.left, loginbox->gripRect.top,
  880. loginbox->gripRect.right, loginbox->gripRect.bottom);
  881. CombineRgn(rgnUpdate, rgnUpdate, rgn, RGN_OR);
  882. }
  883. for (INT i = 0; i < ARRAYSIZE(szControls); i++)
  884. {
  885. HWND hControl = GetDlgItem(hwnd, szControls[i]);
  886. if (NULL == hControl || FALSE == GetWindowRect(hControl, &rect)) continue;
  887. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&rect, 2);
  888. flags = swpFlags;
  889. switch(szControls[i])
  890. {
  891. case IDC_STATUS:
  892. if (NULL != rgn && 0 != (WS_VISIBLE & GetWindowStyle(hControl)))
  893. {
  894. SetRectRgn(rgn, rect.left, rect.top, rect.right, rect.bottom);
  895. CombineRgn(rgnUpdate, rgnUpdate, rgn, RGN_OR);
  896. }
  897. rect.top = rect.bottom - rect.top;
  898. rect.bottom = clientRect.bottom - loginbox->buttonMargins.bottom;
  899. rect.top = rect.bottom - rect.top;
  900. rect.left = clientRect.left + loginbox->buttonMargins.left;
  901. rect.right = statusRight;
  902. flags |= SWP_NOREDRAW | SWP_NOCOPYBITS;
  903. if (NULL != rgn && 0 != (WS_VISIBLE & GetWindowStyle(hControl)))
  904. {
  905. SetRectRgn(rgn, rect.left, rect.top, rect.right, rect.bottom);
  906. CombineRgn(rgnUpdate, rgnUpdate, rgn, RGN_OR);
  907. }
  908. break;
  909. case IDC_TABFRAME:
  910. rect.left = clientRect.left;
  911. rect.top = clientRect.top;
  912. rect.right = clientRect.right;
  913. rect.bottom = rect.top + LoginTab_GetIdealHeight(hControl);
  914. pageTop = rect.bottom;
  915. break;
  916. case IDC_NOTIFIER:
  917. rect.bottom = pageTop + (rect.bottom - rect.top);
  918. rect.top = pageTop;
  919. rect.left = clientRect.left;
  920. rect.right = clientRect.right;
  921. if (0 != (WS_VISIBLE & GetWindowStyle(hControl)))
  922. pageTop = rect.bottom;
  923. break;
  924. case IDC_ACTIVEPAGE:
  925. case IDC_CURTAIN:
  926. rect.left = clientRect.left;
  927. rect.top = pageTop;
  928. rect.right = clientRect.right;
  929. rect.bottom = (pageBottom > pageTop) ? pageBottom : pageTop;
  930. break;
  931. }
  932. hdwp = DeferWindowPos(hdwp, hControl, NULL, rect.left, rect.top,
  933. rect.right - rect.left, rect.bottom - rect.top, flags);
  934. if (NULL == hdwp) break;
  935. }
  936. if (NULL != hdwp)
  937. {
  938. EndDeferWindowPos(hdwp);
  939. }
  940. if (NULL != rgnUpdate)
  941. {
  942. RedrawWindow(hwnd, NULL, rgnUpdate, RDW_INVALIDATE | RDW_ALLCHILDREN);
  943. DeleteObject(rgnUpdate);
  944. }
  945. if (NULL != rgn)
  946. DeleteObject(rgn);
  947. }
  948. static BOOL LoginBox_DrawResizeGrip(HWND hwnd, HDC hdc, const RECT *gripRect, HBRUSH brushBk)
  949. {
  950. BOOL gripDrawOk = FALSE;
  951. if (SUCCEEDED(UxTheme_LoadLibrary()) && FALSE != UxIsAppThemed())
  952. {
  953. UXTHEME hTheme = UxOpenThemeData(hwnd, L"Scrollbar");
  954. if (NULL != hTheme)
  955. {
  956. if (UxIsThemeBackgroundPartiallyTransparent(hTheme, SBP_SIZEBOX, SZB_RIGHTALIGN))
  957. {
  958. UXTHEME windowTheme = UxOpenThemeData(hwnd, L"Window");
  959. if (NULL != windowTheme)
  960. {
  961. if (UxIsThemeBackgroundPartiallyTransparent(windowTheme, WP_DIALOG, 0))
  962. UxDrawThemeParentBackground(hwnd, hdc, gripRect);
  963. //UxDrawThemeBackground(windowTheme, hdc, WP_DIALOG, 0, &gripRect, &gripRect);
  964. FillRect(hdc, gripRect, brushBk);
  965. UxCloseThemeData(windowTheme);
  966. }
  967. }
  968. if (SUCCEEDED(UxDrawThemeBackground(hTheme, hdc, SBP_SIZEBOX, SZB_RIGHTALIGN, gripRect, gripRect)))
  969. gripDrawOk = TRUE;
  970. UxCloseThemeData(hTheme);
  971. }
  972. }
  973. if (FALSE == gripDrawOk)
  974. gripDrawOk = DrawFrameControl(hdc, (RECT*)gripRect, DFC_SCROLL, DFCS_SCROLLSIZEGRIP);
  975. return gripDrawOk;
  976. }
  977. static void LoginBox_Paint(HWND hwnd, HDC hdc, const RECT *prcPaint, BOOL fErase)
  978. {
  979. LOGINBOX *loginbox = GetLoginBox(hwnd);
  980. if (NULL == loginbox) return;
  981. if (FALSE != fErase)
  982. {
  983. HBRUSH brushBk = (HBRUSH)SendMessage(hwnd, WM_CTLCOLORDLG, (WPARAM)hdc, (LPARAM)hwnd);
  984. if (NULL == brushBk)
  985. {
  986. brushBk = GetSysColorBrush(COLOR_3DFACE);
  987. }
  988. HRGN regionFill = CreateRectRgnIndirect(prcPaint);
  989. HRGN regionClip = NULL;
  990. if (RectInRegion(regionFill, &loginbox->gripRect) &&
  991. FALSE != LoginBox_DrawResizeGrip(hwnd, hdc, &loginbox->gripRect, brushBk))
  992. {
  993. regionClip = CreateRectRgnIndirect(&loginbox->gripRect);
  994. if (NULL != regionClip)
  995. CombineRgn(regionFill, regionFill, regionClip, RGN_DIFF);
  996. }
  997. if (loginbox->buttonTop > 0)
  998. {
  999. RECT lineRect;
  1000. GetClientRect(hwnd, &lineRect);
  1001. lineRect.top = loginbox->buttonTop;
  1002. lineRect.bottom = loginbox->buttonTop + 1;
  1003. if (RectInRegion(regionFill, &lineRect))
  1004. {
  1005. COLORREF rgbLine = GetSysColor(COLOR_3DLIGHT);
  1006. if (rgbLine == GetSysColor(COLOR_3DFACE))
  1007. rgbLine = ColorAdjustLuma(rgbLine, -50, TRUE);
  1008. COLORREF rgbOrig = SetBkColor(hdc, rgbLine);
  1009. if (0 != ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &lineRect, NULL, 0, NULL))
  1010. {
  1011. if (NULL == regionClip) regionClip = CreateRectRgnIndirect(&lineRect);
  1012. else SetRectRgn(regionClip, lineRect.left, lineRect.top, lineRect.right, lineRect.bottom);
  1013. if (NULL != regionClip)
  1014. CombineRgn(regionFill, regionFill, regionClip, RGN_DIFF);
  1015. }
  1016. if (rgbOrig != rgbLine) SetBkColor(hdc, rgbOrig);
  1017. }
  1018. }
  1019. if (NULL != regionFill)
  1020. {
  1021. FillRgn(hdc, regionFill, brushBk);
  1022. DeleteObject(regionFill);
  1023. }
  1024. if (NULL != regionClip)
  1025. DeleteObject(regionClip);
  1026. }
  1027. }
  1028. static LoginProvider *LoginBox_GetActiveProviderInternal(HWND hwnd)
  1029. {
  1030. HWND hFrame = GetDlgItem(hwnd, IDC_TABFRAME);
  1031. if (NULL == hFrame) return NULL;
  1032. INT iSelected = LoginTab_GetCurSel(hFrame);
  1033. if (-1 == iSelected) return NULL;
  1034. NLTITEM tab;
  1035. tab.mask = NLTIF_PARAM;
  1036. return (TRUE == LoginTab_GetItem(hFrame, iSelected, &tab)) ?
  1037. (LoginProvider*)tab.param : NULL;
  1038. }
  1039. static void CALLBACK LoginBox_LoginCompletedEvent(LoginResult *result)
  1040. {
  1041. HWND hLoginbox;
  1042. if (SUCCEEDED(result->GetUser((void**)&hLoginbox)) && NULL != hLoginbox)
  1043. PostMessage(hLoginbox, NLBM_LOGINCOMPLETED, 0, (LPARAM)result);
  1044. }
  1045. static void Loginbox_LockTabFrame(HWND hwnd, BOOL fLock)
  1046. {
  1047. HWND hFrame = GetDlgItem(hwnd, IDC_TABFRAME);
  1048. if (NULL == hFrame) return;
  1049. UINT frameStyle = GetWindowStyle(hFrame);
  1050. if (FALSE != fLock)
  1051. frameStyle &= ~WS_TABSTOP;
  1052. else
  1053. frameStyle |= WS_TABSTOP;
  1054. SetWindowLongPtr(hFrame, GWL_STYLE, frameStyle);
  1055. LoginTab_LockSelection(hFrame, fLock);
  1056. }
  1057. static BOOL LoginBox_EnableLoginMode(HWND hwnd, BOOL fEnable, BOOL fValidateTos)
  1058. {
  1059. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1060. if (NULL == loginbox) return FALSE;
  1061. const static INT szControls[] = { IDC_ACTIVEPAGE, IDOK, };
  1062. BOOL resultCode = TRUE;
  1063. HWND hPage = GetDlgItem(hwnd, IDC_ACTIVEPAGE);
  1064. HWND hCurtain = GetDlgItem(hwnd, IDC_CURTAIN);
  1065. if (FALSE != LoginPopup::AnyPopup(hwnd))
  1066. return FALSE;
  1067. if (FALSE != fEnable)
  1068. {
  1069. HWND hPopup = NULL;
  1070. if (NULL == hCurtain)
  1071. {
  1072. hCurtain = LoginCurtain_CreateWindow(hwnd, (NULL != hPage) ? hPage : hwnd);
  1073. if (NULL != hCurtain)
  1074. SetWindowLongPtr(hCurtain, GWLP_ID, IDC_CURTAIN);
  1075. }
  1076. if (FALSE != fValidateTos && TRUE != loginbox->agreementOk)
  1077. {
  1078. LoginProvider *provider = LoginBox_GetActiveProviderInternal(hwnd);
  1079. hPopup = LoginPopupAgreement::CreatePopup((NULL != hCurtain) ? hCurtain : hwnd, provider);
  1080. if (NULL != hPopup)
  1081. {
  1082. SetWindowLongPtr(hPopup, GWLP_ID, IDC_POPUPAGREEMENT);
  1083. if (NULL != loginbox->loginStatus)
  1084. {
  1085. WCHAR szBuffer[128] = {0};
  1086. WASABI_API_LNGSTRINGW_BUF(IDS_STATUS_AGREEMENT_REQUIRED, szBuffer, ARRAYSIZE(szBuffer));
  1087. if (L'\0' != szBuffer[0])
  1088. {
  1089. UINT statusCookie = loginbox->loginStatus->Add(SysAllocString(szBuffer));
  1090. if (-1 != statusCookie && FALSE == SetProp(hPopup, L"StatusCookie", (HANDLE)(UINT_PTR)(statusCookie + 1)))
  1091. loginbox->loginStatus->Remove(statusCookie);
  1092. }
  1093. }
  1094. SetWindowPos(hPopup, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
  1095. ShowWindow(hPopup, SW_SHOW);
  1096. if (NULL != hCurtain)
  1097. SetWindowPos(hCurtain, NULL, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_FRAMECHANGED );
  1098. resultCode = FALSE;
  1099. }
  1100. else
  1101. {
  1102. LoginBox_EnableLoginMode(hwnd, FALSE, FALSE);
  1103. return FALSE;
  1104. }
  1105. }
  1106. if (NULL != hCurtain)
  1107. {
  1108. ShowWindow(hCurtain, SW_SHOW);
  1109. UpdateWindow(hCurtain);
  1110. }
  1111. if (NULL != hPopup && IsWindowVisible(hPopup) && IsWindowEnabled(hPopup))
  1112. {
  1113. HWND hRoot = GetAncestor(hPopup, GA_ROOT);
  1114. if (NULL != hRoot)
  1115. SendMessage(hRoot, WM_NEXTDLGCTL, (WPARAM)hPopup, TRUE);
  1116. LoginPopup_PlayBeep(hPopup);
  1117. }
  1118. Loginbox_LockTabFrame(hwnd, TRUE);
  1119. for (INT i = 0; i < ARRAYSIZE(szControls); i++)
  1120. {
  1121. HWND hControl = GetDlgItem(hwnd, szControls[i]);
  1122. if (NULL != hControl)
  1123. {
  1124. EnableWindow(hControl, FALSE);
  1125. }
  1126. }
  1127. }
  1128. else
  1129. {
  1130. Loginbox_LockTabFrame(hwnd, FALSE);
  1131. for (INT i = 0; i < ARRAYSIZE(szControls); i++)
  1132. {
  1133. HWND hControl = GetDlgItem(hwnd, szControls[i]);
  1134. if (NULL != hControl) EnableWindow(hControl, TRUE);
  1135. }
  1136. if (NULL != hPage && IsWindowVisible(hPage) && IsWindowEnabled(hPage))
  1137. {
  1138. HWND hRoot = GetAncestor(hPage, GA_ROOT);
  1139. if (NULL != hRoot)
  1140. SendMessage(hRoot, WM_NEXTDLGCTL, (WPARAM)hPage, TRUE);
  1141. }
  1142. if (NULL != hCurtain)
  1143. {
  1144. DestroyWindow(hCurtain);
  1145. }
  1146. }
  1147. return resultCode;
  1148. }
  1149. static void LoginBox_PerformLogin(HWND hwnd, LoginData *loginData)
  1150. {
  1151. LoginBox_HideNotifier(hwnd, 150);
  1152. if (FALSE == LoginBox_EnableLoginMode(hwnd, TRUE, TRUE))
  1153. return;
  1154. INT authError;
  1155. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1156. if (NULL == loginbox) authError = AUTH_UNEXPECTED;
  1157. else
  1158. {
  1159. HWND hPage = GetDlgItem(hwnd, IDC_ACTIVEPAGE);
  1160. if (NULL == hPage) authError = AUTH_UNEXPECTED;
  1161. else
  1162. {
  1163. LoginProvider *provider = LoginBox_GetActiveProviderInternal(hwnd);
  1164. if (NULL == provider) authError = AUTH_UNEXPECTED;
  1165. else
  1166. {
  1167. LoginCommand *command;
  1168. if (FAILED(provider->GetCommand(&command))) authError = AUTH_UNEXPECTED;
  1169. else
  1170. {
  1171. if (NULL == loginData)
  1172. {
  1173. if (FALSE == LoginPage_GetData(hPage, &loginData))
  1174. loginData = NULL;
  1175. }
  1176. else
  1177. loginData->AddRef();
  1178. HRESULT hr = command->BeginLogin(loginData, LoginBox_LoginCompletedEvent, hwnd, &loginbox->loginResult);
  1179. authError = (SUCCEEDED(hr)) ? AUTH_SUCCESS : AUTH_UNEXPECTED;
  1180. command->Release();
  1181. if (NULL != loginData)
  1182. loginData->Release();
  1183. }
  1184. }
  1185. }
  1186. }
  1187. if (AUTH_SUCCESS != authError)
  1188. {
  1189. LoginBox_EnableLoginMode(hwnd, FALSE, FALSE);
  1190. if (AUTH_ABORT != authError)
  1191. {
  1192. HWND hNotifier = GetDlgItem(hwnd, IDC_NOTIFIER);
  1193. if (NULL != hNotifier)
  1194. {
  1195. LoginNotifier_Notify(hNotifier, NLNTYPE_ERROR, MAKEINTRESOURCE(authError));
  1196. LoginBox_ShowNotifier(hwnd, 200);
  1197. }
  1198. }
  1199. }
  1200. }
  1201. static INT LoginBox_SetCredentials(HWND hwnd, LoginCredentials *credentials)
  1202. {
  1203. if (NULL == credentials)
  1204. return AUTH_UNEXPECTED;
  1205. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1206. if (NULL == loginbox || NULL == loginbox->auth)
  1207. return AUTH_UNEXPECTED;
  1208. INT result = loginbox->auth->SetCredentials(credentials->GetRealm(), credentials->GetSessionKey(),
  1209. credentials->GetToken(), credentials->GetUsername(), credentials->GetExpiration());
  1210. return result;
  1211. }
  1212. static INT LoginBox_RequestPasscode(HWND hwnd, LoginResult *loginResult)
  1213. {
  1214. LoginData *loginData;
  1215. if (NULL == loginResult || FAILED(loginResult->GetLoginData(&loginData)) || NULL == loginData)
  1216. return AUTH_UNEXPECTED;
  1217. HWND hCurtain = GetDlgItem(hwnd, IDC_CURTAIN);
  1218. HWND hPopup = LoginPopupPasscode::CreatePopup((NULL != hCurtain) ? hCurtain : hwnd, loginData);
  1219. if (NULL != hPopup)
  1220. {
  1221. SetWindowLongPtr(hPopup, GWLP_ID, IDC_POPUPPASSCODE);
  1222. SetWindowPos(hPopup, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
  1223. ShowWindow(hPopup, SW_SHOW);
  1224. if (NULL != hCurtain)
  1225. SetWindowPos(hCurtain, NULL, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_FRAMECHANGED );
  1226. if (IsWindowVisible(hPopup) && IsWindowEnabled(hPopup))
  1227. {
  1228. HWND hRoot = GetAncestor(hPopup, GA_ROOT);
  1229. if (NULL != hRoot)
  1230. SendMessage(hRoot, WM_NEXTDLGCTL, (WPARAM)hPopup, TRUE);
  1231. LoginPopup_PlayBeep(hPopup);
  1232. }
  1233. }
  1234. loginData->Release();
  1235. return (NULL != hPopup) ? AUTH_SUCCESS : AUTH_UNEXPECTED;
  1236. }
  1237. static BOOL LoginBox_EndDialog(HWND hwnd, INT authResult)
  1238. {
  1239. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1240. if (0 != (NLBS_MODAL & loginbox->style))
  1241. {
  1242. EndDialog(hwnd, authResult);
  1243. }
  1244. else
  1245. {
  1246. DestroyWindow(hwnd);
  1247. }
  1248. return TRUE;
  1249. }
  1250. static BOOL LoginBox_ReloadProviders(HWND hwnd, INT *loaded, INT *prefVisible)
  1251. {
  1252. if (NULL != loaded)
  1253. *loaded = NULL;
  1254. WCHAR szPath[MAX_PATH] = {0};
  1255. if (FAILED(LoginBox_GetConfigPath(szPath, FALSE)))
  1256. return FALSE;
  1257. if (FALSE == PathAppend(szPath, L"loginProviders.xml"))
  1258. return FALSE;
  1259. LoginProviderEnumerator *enumerator;
  1260. LoginProviderLoader loader;
  1261. if (FAILED(loader.ReadXml(szPath,&enumerator, prefVisible)))
  1262. return FALSE;
  1263. HWND hFrame = GetDlgItem(hwnd, IDC_TABFRAME);
  1264. if (NULL != hFrame)
  1265. {
  1266. UINT frameStyle = GetWindowStyle(hFrame);
  1267. if (0 != (WS_VISIBLE & frameStyle))
  1268. SetWindowLongPtr(hFrame, GWL_STYLE, frameStyle & ~WS_VISIBLE);
  1269. LoginBox_DeleteAllTabs(hwnd);
  1270. INT r = LoginBox_AppendMultipleTabs(hwnd, enumerator, NULL, NULL);
  1271. if (NULL != loaded)
  1272. *loaded = r;
  1273. if (0 != (WS_VISIBLE & frameStyle))
  1274. {
  1275. frameStyle = GetWindowStyle(hFrame);
  1276. if (0 == (WS_VISIBLE & frameStyle))
  1277. SetWindowLongPtr(hFrame, GWL_STYLE, frameStyle | WS_VISIBLE);
  1278. }
  1279. }
  1280. enumerator->Release();
  1281. return TRUE;
  1282. }
  1283. static void LoginBox_PerformProviderOp(HWND hwnd)
  1284. {
  1285. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1286. if (NULL == loginbox || NULL == loginbox->providerOp)
  1287. return;
  1288. if (FALSE == LoginBox_EnableLoginMode(hwnd, TRUE, FALSE))
  1289. return;
  1290. HWND hCurtain = GetDlgItem(hwnd, IDC_CURTAIN);
  1291. LPCWSTR pszMessage;
  1292. switch(loginbox->providerOp->GetCode())
  1293. {
  1294. case LoginProviderOperation::operationReplace:
  1295. pszMessage = MAKEINTRESOURCE(IDS_PROVIDER_CHANGED); break;
  1296. case LoginProviderOperation::operationDelete:
  1297. pszMessage = MAKEINTRESOURCE(IDS_PROVIDER_REMOVED); break;
  1298. default:
  1299. pszMessage = NULL;
  1300. break;
  1301. }
  1302. HWND hPopup = LoginPopupMessage::CreatePopup((NULL != hCurtain) ? hCurtain : hwnd,
  1303. MAKEINTRESOURCE(IDS_PROVIDERUPDATE_TITLE), pszMessage,
  1304. LoginPopupMessage::typeContinue | LoginPopupMessage::iconWarning, NULL, NULL);
  1305. if (NULL != hPopup)
  1306. {
  1307. SetWindowLongPtr(hPopup, GWLP_ID, IDC_POPUPPROVIDEROP);
  1308. SetWindowPos(hPopup, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
  1309. ShowWindow(hPopup, SW_SHOW);
  1310. if (NULL != hCurtain)
  1311. SetWindowPos(hCurtain, NULL, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_FRAMECHANGED );
  1312. if (IsWindowVisible(hPopup) && IsWindowEnabled(hPopup))
  1313. {
  1314. HWND hRoot = GetAncestor(hPopup, GA_ROOT);
  1315. if (NULL != hRoot)
  1316. SendMessage(hRoot, WM_NEXTDLGCTL, (WPARAM)hPopup, TRUE);
  1317. LoginPopup_PlayBeep(hPopup);
  1318. }
  1319. }
  1320. else
  1321. {
  1322. LoginBox_EnableLoginMode(hwnd, FALSE, FALSE);
  1323. }
  1324. }
  1325. static INT_PTR LoginBox_OnInitDialog(HWND hwnd, HWND hFocus, LPARAM param)
  1326. {
  1327. LOGINBOXCREATEPARAM *createParam = (LOGINBOXCREATEPARAM*)param;
  1328. LOGINBOX *login = (LOGINBOX*)calloc(1, sizeof(LOGINBOX));
  1329. if (NULL == login)
  1330. {
  1331. return 0;
  1332. }
  1333. SetProp(hwnd, LOGINBOX_PROP, login);
  1334. if (NULL != createParam)
  1335. {
  1336. login->style = createParam->style;
  1337. login->realm = (NULL == createParam->pRealm) ? GUID_NULL : *createParam->pRealm;
  1338. login->auth = createParam->auth;
  1339. }
  1340. if (NULL != login->auth)
  1341. login->auth->AddRef();
  1342. LoginGuiObject::InitializeThread();
  1343. HFONT hFont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0L);
  1344. HWND hFrame = LoginTab_CreateWindow(0, L"Select provider:",
  1345. WS_CHILD | WS_CLIPSIBLINGS | WS_TABSTOP | WS_VISIBLE, 0, 0, 0, 0, hwnd, IDC_TABFRAME);
  1346. if (NULL != hFrame)
  1347. {
  1348. HIMAGELIST imageList = ImageList_Create(40, 40, ILC_COLOR32, 7*3, 3*3);
  1349. if (NULL != imageList)
  1350. LoginTab_SetImageList(hFrame, imageList);
  1351. }
  1352. HWND hNotifier = LoginNotifier_CreateWindow(0, WS_CHILD | WS_CLIPSIBLINGS, 0, 0, 0, 0, hwnd, IDC_NOTIFIER);
  1353. if (NULL != hNotifier)
  1354. {
  1355. if (NULL != hFont)
  1356. SendMessage(hNotifier, WM_SETFONT, (WPARAM)hFont, 0L);
  1357. SetWindowPos(hNotifier, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
  1358. }
  1359. HWND hStatus = GetDlgItem(hwnd, IDC_STATUS);
  1360. if (NULL != hStatus)
  1361. {
  1362. LoginStatus::CreateInstance(hStatus, &login->loginStatus);
  1363. }
  1364. LoginGuiObject *loginGui;
  1365. if (SUCCEEDED(LoginGuiObject::QueryInstance(&loginGui)))
  1366. {
  1367. HFONT fontButton = loginGui->GetTextFont();
  1368. if (NULL != fontButton)
  1369. {
  1370. INT szButtons[] = {IDOK, IDCANCEL, };
  1371. for (INT i = 0; i < ARRAYSIZE(szButtons); i++)
  1372. {
  1373. HWND hButton = GetDlgItem(hwnd, szButtons[i]);
  1374. if(NULL != hButton)
  1375. SNDMSG(hButton, WM_SETFONT, (WPARAM)fontButton, 0L);
  1376. }
  1377. }
  1378. loginGui->Release();
  1379. }
  1380. INT loaded, prefVisible, prefWidth;
  1381. prefWidth = 0;
  1382. if (FALSE == LoginBox_ReloadProviders(hwnd, &loaded, &prefVisible))
  1383. {
  1384. loaded = 0;
  1385. prefVisible = 0;
  1386. }
  1387. if (NULL != hFrame && prefVisible > 0)
  1388. prefWidth = LoginTab_GetIdealWidth(hFrame, prefVisible);
  1389. if (NULL != hFrame)
  1390. {
  1391. INT activeId = -1;
  1392. LoginConfig *config;
  1393. if (SUCCEEDED(LoginConfig::CreateInstance(&config)))
  1394. {
  1395. RPC_CSTR pszRealm;
  1396. if (RPC_S_OK == UuidToStringA(&login->realm, &pszRealm))
  1397. {
  1398. CHAR szProvider[128] = {0};
  1399. config->ReadAnsiStr((LPCSTR)pszRealm, "lastProvider", NULL, szProvider, ARRAYSIZE(szProvider));
  1400. if (NULL != szProvider && L'\0' != *szProvider)
  1401. {
  1402. GUID providerId;
  1403. if (RPC_S_OK == UuidFromStringA((RPC_CSTR)szProvider, &providerId))
  1404. activeId = LoginBox_FindTabByProviderId(hwnd, &providerId);
  1405. }
  1406. RpcStringFreeA(&pszRealm);
  1407. }
  1408. config->Release();
  1409. }
  1410. if (-1 == activeId)
  1411. activeId = 0;
  1412. LoginTab_SetCurSel(hFrame, activeId);
  1413. LoginBox_SelectActivePage(hwnd);
  1414. }
  1415. LoginBox_UpdateMargins(hwnd);
  1416. if (0 != prefWidth)
  1417. {
  1418. RECT rect;
  1419. GetClientRect(hwnd, &rect);
  1420. prefWidth -= rect.right - rect.left;
  1421. GetWindowRect(hwnd, &rect);
  1422. prefWidth += rect.right - rect.left;
  1423. if (prefWidth < login->minmaxInfo.left) prefWidth = login->minmaxInfo.left;
  1424. else if (prefWidth > login->minmaxInfo.right) prefWidth = login->minmaxInfo.right;
  1425. SetWindowPos(hwnd, NULL, 0, 0, prefWidth, rect.bottom - rect.top, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOREDRAW);
  1426. }
  1427. LoginBox_UpdateLayout(hwnd, FALSE);
  1428. if (NULL != createParam && 0 == (LBS_NOCENTEROWNER & createParam->style))
  1429. LoginBox_CenterOver(hwnd, createParam->hOwner);
  1430. SendMessage(hwnd, DM_REPOSITION, 0, 0L);
  1431. PostMessage(hwnd, WM_CHANGEUISTATE, MAKEWPARAM(UIS_INITIALIZE, UISF_HIDEACCEL | UISF_HIDEFOCUS), 0L);
  1432. PostMessage(hwnd, NLBM_UPDATEPROVIDERS, (0 == loaded), 0L);
  1433. return 0;
  1434. }
  1435. static void LoginBox_OnDestroy(HWND hwnd)
  1436. {
  1437. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1438. RemoveProp(hwnd, LOGINBOX_PROP);
  1439. if (NULL == loginbox)
  1440. return;
  1441. LoginConfig *config;
  1442. if (SUCCEEDED(LoginConfig::CreateInstance(&config)))
  1443. {
  1444. RPC_CSTR pszRealm, pszProvider;
  1445. if (RPC_S_OK == UuidToStringA(&loginbox->realm, &pszRealm))
  1446. {
  1447. GUID providerId;
  1448. LoginProvider *activeProvider = LoginBox_GetActiveProviderInternal(hwnd);
  1449. if (NULL == activeProvider || FAILED(activeProvider->GetId(&providerId)) ||
  1450. RPC_S_OK != UuidToStringA(&providerId, &pszProvider))
  1451. {
  1452. pszProvider = NULL;
  1453. }
  1454. config->WriteAnsiStr((LPCSTR)pszRealm, "lastProvider", (LPCSTR)pszProvider);
  1455. if (NULL != pszProvider)
  1456. RpcStringFreeA(&pszProvider);
  1457. RpcStringFreeA(&pszRealm);
  1458. }
  1459. config->Release();
  1460. }
  1461. if (NULL != loginbox->imageCache)
  1462. {
  1463. loginbox->imageCache->Finish();
  1464. loginbox->imageCache->Release();
  1465. loginbox->imageCache = NULL;
  1466. }
  1467. LoginBox_DeleteAllTabs(hwnd);
  1468. HWND hFrame = GetDlgItem(hwnd, IDC_TABFRAME);
  1469. if (NULL != hFrame)
  1470. {
  1471. HIMAGELIST imageList = LoginTab_SetImageList(hFrame, NULL);
  1472. if (NULL != imageList)
  1473. {
  1474. ImageList_Destroy(imageList);
  1475. }
  1476. }
  1477. if (NULL != loginbox->loginResult)
  1478. {
  1479. LoginResult *result = loginbox->loginResult;
  1480. result->RequestAbort(TRUE);
  1481. HANDLE resultAborted;
  1482. if (SUCCEEDED(result->GetWaitHandle(&resultAborted)))
  1483. {
  1484. WaitForSingleObjectEx(resultAborted, INFINITE, TRUE);
  1485. CloseHandle(resultAborted);
  1486. }
  1487. loginbox->loginResult = NULL;
  1488. result->Release();
  1489. }
  1490. if (NULL != loginbox->auth)
  1491. loginbox->auth->Release();
  1492. if (NULL != loginbox->providerUpdate)
  1493. {
  1494. UINT state;
  1495. if (FAILED(loginbox->providerUpdate->GetState(&state)) ||
  1496. LoginDownloadResult::stateCompleted != state)
  1497. {
  1498. loginbox->providerUpdate->RequestAbort(TRUE);
  1499. HANDLE completed;
  1500. if (SUCCEEDED(loginbox->providerUpdate->GetWaitHandle(&completed)) && NULL != completed)
  1501. {
  1502. WaitForSingleObject(completed, INFINITE);
  1503. CloseHandle(completed);
  1504. }
  1505. }
  1506. loginbox->providerUpdate->Release();
  1507. }
  1508. if (NULL != loginbox->providerOp)
  1509. loginbox->providerOp->Release();
  1510. if (NULL != loginbox->loginStatus)
  1511. {
  1512. loginbox->loginStatus->DetachWindow();
  1513. loginbox->loginStatus->Release();
  1514. }
  1515. LoginGuiObject::UninitializeThread();
  1516. free(loginbox);
  1517. }
  1518. static void LoginBox_OnGetMinMaxInfo(HWND hwnd, MINMAXINFO *mmi)
  1519. {
  1520. if (NULL == mmi) return;
  1521. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1522. if (NULL != loginbox)
  1523. {
  1524. mmi->ptMinTrackSize.x = loginbox->minmaxInfo.left;
  1525. mmi->ptMinTrackSize.y = loginbox->minmaxInfo.top;
  1526. mmi->ptMaxTrackSize.x = loginbox->minmaxInfo.right;
  1527. mmi->ptMaxTrackSize.y = loginbox->minmaxInfo.bottom;
  1528. }
  1529. }
  1530. static void LoginBox_OnWindowPosChanged(HWND hwnd, WINDOWPOS *pwp)
  1531. {
  1532. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1533. if (NULL == loginbox) return;
  1534. if (SWP_NOSIZE != ((SWP_NOSIZE | SWP_FRAMECHANGED) & pwp->flags))
  1535. {
  1536. LoginBox_UpdateLayout(hwnd, 0 == (SWP_NOREDRAW & pwp->flags));
  1537. }
  1538. }
  1539. static void LoginBox_OnCommand(HWND hwnd, INT commandId, INT eventId, HWND hControl)
  1540. {
  1541. switch(commandId)
  1542. {
  1543. case IDOK:
  1544. LoginBox_PerformLogin(hwnd, NULL);
  1545. break;
  1546. case IDCANCEL:
  1547. LoginBox_EndDialog(hwnd, AUTH_ABORT);
  1548. break;
  1549. case ID_LOGINBOX_UPDATEPROVIDERS:
  1550. LoginBox_UpdateProviders(hwnd, TRUE);
  1551. break;
  1552. case ID_LOGINTAB_RESETORDER:
  1553. LoginTab_ResetOrder(GetDlgItem(hwnd, IDC_TABFRAME));
  1554. break;
  1555. }
  1556. }
  1557. static void LoginBox_OnTabSelected(HWND hwnd, HWND hFrame)
  1558. {
  1559. LoginBox_SelectActivePage(hwnd);
  1560. }
  1561. static void LoginBox_OnTabDeleted(HWND hwnd, HWND hFrame, INT iItem)
  1562. {
  1563. if (NULL == hFrame || iItem < 0) return;
  1564. NLTITEM tab;
  1565. tab.mask = NLTIF_PARAM | NLTIF_IMAGE_MASK;
  1566. if (FALSE != LoginTab_GetItem(hFrame, iItem, &tab))
  1567. {
  1568. LoginBox_RemoveImageHelper2(hFrame, &tab);
  1569. LoginProvider *provider = (LoginProvider*)tab.param;
  1570. if (NULL != provider)
  1571. provider->Release();
  1572. }
  1573. }
  1574. static BOOL LoginBox_OnTabDeleteAll(HWND hwnd, HWND hFrame)
  1575. {
  1576. if (NULL == hFrame) return FALSE;
  1577. HIMAGELIST imageList = LoginTab_GetImageList(hFrame);
  1578. if (NULL != imageList)
  1579. ImageList_RemoveAll(imageList);
  1580. NLTITEM tab;
  1581. tab.mask = NLTIF_PARAM;
  1582. INT iItem = LoginTab_GetItemCount(hFrame);
  1583. while (iItem--)
  1584. {
  1585. if (FALSE != LoginTab_GetItem(hFrame, iItem, &tab))
  1586. {
  1587. LoginProvider *provider = (LoginProvider*)tab.param;
  1588. if (NULL != provider)
  1589. provider->Release();
  1590. }
  1591. }
  1592. return TRUE;
  1593. }
  1594. static void LoginBox_OnTabRClick(HWND hwnd, HWND hFrame, POINT pt)
  1595. {
  1596. HMENU hMenu = WASABI_API_LOADMENUW(IDR_MENU_TABCONTEXT);
  1597. HMENU hContext = (NULL != hMenu) ? GetSubMenu(hMenu, 0) : NULL;
  1598. if (NULL == hContext) return;
  1599. MapWindowPoints(hFrame, HWND_DESKTOP, &pt, 1);
  1600. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1601. UINT fEnable = (NULL != loginbox && NULL == loginbox->providerUpdate) ? MF_ENABLED : MF_DISABLED;
  1602. EnableMenuItem(hContext, ID_LOGINBOX_UPDATEPROVIDERS, fEnable | MF_BYCOMMAND);
  1603. TrackPopupMenuEx(hContext, TPM_TOPALIGN | TPM_LEFTALIGN | TPM_VERPOSANIMATION, pt.x, pt.y, hwnd, NULL);
  1604. }
  1605. static void LoginBox_OnTabHelp(HWND hwnd, HWND hFrame, NMLOGINTABHELP *plth)
  1606. {
  1607. if (NULL == plth || NULL == plth->param)
  1608. return;
  1609. LoginProvider *provider = (LoginProvider*)plth->param;
  1610. WCHAR szBuffer[2048] = {0};
  1611. if (SUCCEEDED(provider->GetDescription(szBuffer, ARRAYSIZE(szBuffer))))
  1612. plth->bstrHelp = SysAllocString(szBuffer);
  1613. }
  1614. static void LoginBox_OnTabImage(HWND hwnd, HWND hFrame, NMLOGINTABIMAGE *plti)
  1615. {
  1616. if (NULL == plti || NULL == plti->imageList)
  1617. return;
  1618. if (NLTM_IMAGE_CALLBACK == plti->iImage)
  1619. {
  1620. plti->maskUpdate = NLTIF_IMAGE_MASK;
  1621. plti->iImage = NLTM_IMAGE_NONE;
  1622. plti->iImageActive = NLTM_IMAGE_NONE;
  1623. plti->iImageDisabled = NLTM_IMAGE_NONE;
  1624. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1625. if (NULL != loginbox)
  1626. {
  1627. if (NULL == loginbox->imageCache)
  1628. LoginImageCache::CreateInstance(hwnd, &loginbox->imageCache);
  1629. LoginProvider *provider = (LoginProvider*)plti->param;
  1630. if (NULL != provider && NULL != loginbox->imageCache)
  1631. {
  1632. WCHAR szImage[4096] = {0};
  1633. if (SUCCEEDED(provider->GetImagePath(szImage, ARRAYSIZE(szImage))))
  1634. {
  1635. loginbox->imageCache->GetImageListIndex(szImage, plti->imageList,
  1636. &plti->iImage, &plti->iImageActive, &plti->iImageDisabled);
  1637. }
  1638. }
  1639. }
  1640. return;
  1641. }
  1642. if (0 != (NLTIF_IMAGE_ACTIVE & plti->maskRequest))
  1643. {
  1644. plti->iImageActive = plti->iImage;
  1645. plti->maskUpdate |= NLTIF_IMAGE_ACTIVE;
  1646. }
  1647. if (0 != (NLTIF_IMAGE_DISABLED & plti->maskRequest))
  1648. {
  1649. plti->iImageDisabled = plti->iImage;
  1650. plti->maskUpdate |= NLTIF_IMAGE_DISABLED;
  1651. }
  1652. }
  1653. static void LoginBox_OnPopupAgreementResult(HWND hwnd, NLPNRESULT *pnr)
  1654. {
  1655. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1656. if (NULL == loginbox) return;
  1657. HWND hCurtain = GetDlgItem(hwnd, IDC_CURTAIN);
  1658. UINT curtainStyle = (NULL != hCurtain) ? GetWindowStyle(hCurtain) : 0;
  1659. if (0 != (WS_VISIBLE & curtainStyle))
  1660. SetWindowLongPtr(hCurtain, GWL_STYLE, curtainStyle & ~WS_VISIBLE);
  1661. UINT statusCookie = (UINT)(UINT_PTR)GetProp(pnr->hdr.hwndFrom, L"StatusCookie");
  1662. RemoveProp(pnr->hdr.hwndFrom, L"StatusCookie");
  1663. if (0 != statusCookie)
  1664. loginbox->loginStatus->Remove(statusCookie - 1);
  1665. DestroyWindow(pnr->hdr.hwndFrom);
  1666. if (IDOK == pnr->exitCode)
  1667. {
  1668. loginbox->agreementOk = TRUE;
  1669. LoginBox_PerformLogin(hwnd, NULL); // this will restore curtain visibility
  1670. }
  1671. else
  1672. {
  1673. loginbox->agreementOk = FALSE;
  1674. RECT invalidRect;
  1675. if (NULL != hCurtain)
  1676. {
  1677. GetWindowRect(hCurtain, &invalidRect);
  1678. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&invalidRect, 2);
  1679. }
  1680. else
  1681. SetRectEmpty(&invalidRect);
  1682. LoginBox_EnableLoginMode(hwnd, FALSE, FALSE);
  1683. if (FALSE == IsRectEmpty(&invalidRect))
  1684. RedrawWindow(hwnd, &invalidRect, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_UPDATENOW | RDW_ERASENOW);
  1685. LoginBox_PerformProviderOp(hwnd);
  1686. }
  1687. }
  1688. static void LoginBox_OnPopupPasscodeResult(HWND hwnd, NPPNRESULT *pnr)
  1689. {
  1690. HWND hCurtain = GetDlgItem(hwnd, IDC_CURTAIN);
  1691. UINT curtainStyle = (NULL != hCurtain) ? GetWindowStyle(hCurtain) : 0;
  1692. if (0 != (WS_VISIBLE & curtainStyle))
  1693. SetWindowLongPtr(hCurtain, GWL_STYLE, curtainStyle & ~WS_VISIBLE);
  1694. DestroyWindow(pnr->hdr.hwndFrom);
  1695. if (IDOK == pnr->exitCode)
  1696. {
  1697. LoginBox_PerformLogin(hwnd, pnr->loginData); // this will restore curtain visibility
  1698. }
  1699. else
  1700. {
  1701. RECT invalidRect;
  1702. if (NULL != hCurtain)
  1703. {
  1704. GetWindowRect(hCurtain, &invalidRect);
  1705. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&invalidRect, 2);
  1706. }
  1707. else
  1708. SetRectEmpty(&invalidRect);
  1709. LoginBox_EnableLoginMode(hwnd, FALSE, FALSE);
  1710. if (FALSE == IsRectEmpty(&invalidRect))
  1711. RedrawWindow(hwnd, &invalidRect, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_UPDATENOW | RDW_ERASENOW);
  1712. LoginBox_PerformProviderOp(hwnd);
  1713. }
  1714. }
  1715. static void LoginBox_OnPopupProviderOpResult(HWND hwnd, NLPNRESULT *pnr)
  1716. {
  1717. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1718. if (NULL == loginbox) return;
  1719. HWND hCurtain = GetDlgItem(hwnd, IDC_CURTAIN);
  1720. UINT curtainStyle = (NULL != hCurtain) ? GetWindowStyle(hCurtain) : 0;
  1721. if (0 != (WS_VISIBLE & curtainStyle))
  1722. SetWindowLongPtr(hCurtain, GWL_STYLE, curtainStyle & ~WS_VISIBLE);
  1723. DestroyWindow(pnr->hdr.hwndFrom);
  1724. RECT invalidRect;
  1725. if (NULL != hCurtain)
  1726. {
  1727. GetWindowRect(hCurtain, &invalidRect);
  1728. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&invalidRect, 2);
  1729. }
  1730. else
  1731. SetRectEmpty(&invalidRect);
  1732. LoginBox_EnableLoginMode(hwnd, FALSE, FALSE);
  1733. if (FALSE == IsRectEmpty(&invalidRect))
  1734. RedrawWindow(hwnd, &invalidRect, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_UPDATENOW | RDW_ERASENOW);
  1735. if (NULL != loginbox->providerOp)
  1736. {
  1737. LoginProvider *source, *target;
  1738. GUID sourceId;
  1739. if(SUCCEEDED(loginbox->providerOp->GetSource(&source)) && NULL != source)
  1740. {
  1741. if (FAILED(source->GetId(&sourceId)))
  1742. sourceId = GUID_NULL;
  1743. source->Release();
  1744. switch(loginbox->providerOp->GetCode())
  1745. {
  1746. case LoginProviderOperation::operationReplace:
  1747. if(SUCCEEDED(loginbox->providerOp->GetTarget(&target)))
  1748. {
  1749. LoginBox_ReplaceProvider(hwnd, &sourceId, target);
  1750. target->Release();
  1751. }
  1752. break;
  1753. case LoginProviderOperation::operationDelete:
  1754. LoginBox_DeleteProvider(hwnd, &sourceId);
  1755. break;
  1756. }
  1757. }
  1758. loginbox->providerOp->Release();
  1759. loginbox->providerOp = NULL;
  1760. }
  1761. }
  1762. static LRESULT LoginBox_OnNotify(HWND hwnd, INT controlId, NMHDR *pnmh)
  1763. {
  1764. switch(controlId)
  1765. {
  1766. case IDC_TABFRAME:
  1767. switch(pnmh->code)
  1768. {
  1769. case NLTN_SELCHANGE:
  1770. LoginBox_OnTabSelected(hwnd, pnmh->hwndFrom);
  1771. break;
  1772. case NLTN_DELETEITEM:
  1773. LoginBox_OnTabDeleted(hwnd, pnmh->hwndFrom, ((NMLOGINTAB*)pnmh)->iItem);
  1774. break;
  1775. case NLTN_DELETEALLITEMS:
  1776. return LoginBox_OnTabDeleteAll(hwnd, pnmh->hwndFrom);
  1777. case NM_RCLICK:
  1778. LoginBox_OnTabRClick(hwnd, pnmh->hwndFrom, ((NMLOGINTABCLICK*)pnmh)->pt);
  1779. break;
  1780. case NLTN_GETITEMHELP:
  1781. LoginBox_OnTabHelp(hwnd, pnmh->hwndFrom, (NMLOGINTABHELP*)pnmh);
  1782. break;
  1783. case NLTN_GETITEMIMAGE:
  1784. LoginBox_OnTabImage(hwnd, pnmh->hwndFrom, (NMLOGINTABIMAGE*)pnmh);
  1785. break;
  1786. }
  1787. break;
  1788. case IDC_POPUPAGREEMENT:
  1789. switch(pnmh->code)
  1790. {
  1791. case NLPN_RESULT:
  1792. LoginBox_OnPopupAgreementResult(hwnd, (NLPNRESULT*)pnmh);
  1793. break;
  1794. }
  1795. break;
  1796. case IDC_POPUPPASSCODE:
  1797. switch(pnmh->code)
  1798. {
  1799. case NPPN_RESULT:
  1800. LoginBox_OnPopupPasscodeResult(hwnd, (NPPNRESULT*)pnmh);
  1801. break;
  1802. }
  1803. break;
  1804. case IDC_POPUPPROVIDEROP:
  1805. switch(pnmh->code)
  1806. {
  1807. case NLPN_RESULT:
  1808. LoginBox_OnPopupProviderOpResult(hwnd, (NLPNRESULT*)pnmh);
  1809. break;
  1810. }
  1811. break;
  1812. }
  1813. return 0;
  1814. }
  1815. static INT_PTR LoginBox_OnNcHitTest(HWND hwnd, POINTS pts)
  1816. {
  1817. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1818. if (NULL != loginbox)
  1819. {
  1820. POINT pt;
  1821. POINTSTOPOINT(pt, pts);
  1822. MapWindowPoints(HWND_DESKTOP, hwnd, &pt, 1);
  1823. LONG offsetX = (loginbox->gripRect.right - loginbox->gripRect.left)/3;
  1824. LONG offsetY = (loginbox->gripRect.bottom - loginbox->gripRect.top)/3;
  1825. if (pt.x < loginbox->gripRect.right && pt.y < loginbox->gripRect.bottom &&
  1826. pt.x > (loginbox->gripRect.left + offsetX) && pt.y > (loginbox->gripRect.top + offsetY))
  1827. {
  1828. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, HTBOTTOMRIGHT);
  1829. return TRUE;
  1830. }
  1831. }
  1832. return FALSE;
  1833. }
  1834. static void LoginBox_OnSetFont(HWND hwnd, HFONT hFont, BOOL fRedraw)
  1835. {
  1836. DefWindowProc(hwnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(fRedraw, 0));
  1837. LoginBox_UpdateMargins(hwnd);
  1838. }
  1839. static void LoginBox_OnPaint(HWND hwnd)
  1840. {
  1841. PAINTSTRUCT ps;
  1842. if (BeginPaint(hwnd, &ps))
  1843. {
  1844. if (ps.rcPaint.left != ps.rcPaint.right)
  1845. LoginBox_Paint(hwnd, ps.hdc, &ps.rcPaint, ps.fErase);
  1846. EndPaint(hwnd, &ps);
  1847. }
  1848. }
  1849. static void LoginBox_OnPrintClient(HWND hwnd, HDC hdc, UINT options)
  1850. {
  1851. if (0 != (PRF_CLIENT & options))
  1852. {
  1853. RECT clientRect;
  1854. if (GetClientRect(hwnd, &clientRect))
  1855. LoginBox_Paint(hwnd, hdc, &clientRect, TRUE);
  1856. }
  1857. }
  1858. static HBRUSH LoginBox_OnGetStaticColor(HWND hwnd, HDC hdc, HWND hControl)
  1859. {
  1860. HBRUSH hb;
  1861. INT_PTR controlId = (INT_PTR)GetWindowLongPtr(hControl, GWLP_ID);
  1862. switch(controlId)
  1863. {
  1864. case IDC_STATUS:
  1865. hb = (HBRUSH)SendMessage(hwnd, WM_CTLCOLORDLG, (WPARAM)hdc, (LPARAM)hwnd);
  1866. SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
  1867. return hb;
  1868. }
  1869. return 0;
  1870. }
  1871. static BOOL LoginBox_OnGetAuthApi(HWND hwnd, api_auth **authApi)
  1872. {
  1873. if (NULL == authApi) return FALSE;
  1874. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1875. if (NULL == loginbox || NULL == loginbox->auth)
  1876. {
  1877. *authApi = NULL;
  1878. return FALSE;
  1879. }
  1880. *authApi = loginbox->auth;
  1881. loginbox->auth->AddRef();
  1882. return TRUE;
  1883. }
  1884. static BOOL LoginBox_OnGetRealm(HWND hwnd, GUID *realm)
  1885. {
  1886. if (NULL == realm) return FALSE;
  1887. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1888. if (NULL == loginbox)
  1889. {
  1890. *realm = GUID_NULL;
  1891. return FALSE;
  1892. }
  1893. *realm = loginbox->realm;
  1894. return TRUE;
  1895. }
  1896. static BOOL LoginBox_OnGetActiveProvider(HWND hwnd, LoginProvider **provider)
  1897. {
  1898. if (NULL == provider)
  1899. return FALSE;
  1900. *provider = LoginBox_GetActiveProviderInternal(hwnd);
  1901. if (NULL == (*provider))
  1902. return FALSE;
  1903. (*provider)->AddRef();
  1904. return TRUE;
  1905. }
  1906. static void LoginBox_OnLoginCompleted(HWND hwnd, LoginResult *result)
  1907. {
  1908. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1909. if (NULL == loginbox || NULL == result || loginbox->loginResult != result)
  1910. return;
  1911. INT authError = AUTH_ABORT;
  1912. LoginProvider *provider = LoginBox_GetActiveProviderInternal(hwnd);
  1913. if (NULL != provider)
  1914. {
  1915. LoginCommand *command;
  1916. if (SUCCEEDED(provider->GetCommand(&command)))
  1917. {
  1918. LoginCredentials *credentials;
  1919. if (SUCCEEDED(command->EndLogin(result, &authError, &credentials)))
  1920. {
  1921. switch(authError)
  1922. {
  1923. case AUTH_SUCCESS:
  1924. authError = LoginBox_SetCredentials(hwnd, credentials);
  1925. LoginBox_SaveUsername(&loginbox->realm, provider, credentials);
  1926. break;
  1927. case AUTH_SECURID:
  1928. authError = LoginBox_RequestPasscode(hwnd, result);
  1929. if (AUTH_SUCCESS == authError)
  1930. authError = AUTH_SECURID;
  1931. break;
  1932. }
  1933. if (NULL != credentials)
  1934. credentials->Release();
  1935. }
  1936. command->Release();
  1937. }
  1938. }
  1939. loginbox->loginResult = NULL;
  1940. result->Release();
  1941. switch(authError)
  1942. {
  1943. case AUTH_SUCCESS:
  1944. LoginBox_EndDialog(hwnd, AUTH_SUCCESS);
  1945. break;
  1946. case AUTH_SECURID:
  1947. break;
  1948. default:
  1949. LoginBox_EnableLoginMode(hwnd, FALSE, FALSE);
  1950. if (AUTH_ABORT != authError)
  1951. {
  1952. HWND hNotifier = GetDlgItem(hwnd, IDC_NOTIFIER);
  1953. if (NULL != hNotifier)
  1954. {
  1955. LoginNotifier_Notify(hNotifier, NLNTYPE_ERROR, MAKEINTRESOURCE(authError));
  1956. LoginBox_ShowNotifier(hwnd, 200);
  1957. }
  1958. }
  1959. LoginBox_PerformProviderOp(hwnd);
  1960. break;
  1961. }
  1962. }
  1963. static BOOL LoginBox_OnGetStatus(HWND hwnd, LoginStatus **loginStatus)
  1964. {
  1965. if (NULL == loginStatus)
  1966. return FALSE;
  1967. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1968. if (NULL != loginbox && NULL !=loginbox->loginStatus)
  1969. {
  1970. *loginStatus = loginbox->loginStatus;
  1971. (*loginStatus)->AddRef();
  1972. return TRUE;
  1973. }
  1974. return FALSE;
  1975. }
  1976. static UINT LoginBox_OnAddStatus(HWND hwnd, BSTR pszStatus)
  1977. {
  1978. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1979. if (NULL != loginbox && NULL !=loginbox->loginStatus)
  1980. return loginbox->loginStatus->Add(pszStatus);
  1981. return 0;
  1982. }
  1983. static BOOL LoginBox_OnSetStatus(HWND hwnd, UINT cookie, BSTR pszStatus)
  1984. {
  1985. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1986. if (NULL != loginbox && NULL !=loginbox->loginStatus)
  1987. return loginbox->loginStatus->Set(cookie, pszStatus);
  1988. return TRUE;
  1989. }
  1990. static void LoginBox_OnRemoveStatus(HWND hwnd, UINT cookie)
  1991. {
  1992. LOGINBOX *loginbox = GetLoginBox(hwnd);
  1993. if (NULL != loginbox && NULL !=loginbox->loginStatus)
  1994. loginbox->loginStatus->Remove(cookie);
  1995. }
  1996. static BOOL LoginBox_ApplyProvidersUpdate(HWND hwnd, LoginProviderEnumerator *providerEnum)
  1997. {
  1998. if (NULL == providerEnum)
  1999. return FALSE;
  2000. GUID activeId(GUID_NULL);
  2001. INT activeIndex(-1);
  2002. LoginProviderOperation *providerOp(NULL);
  2003. LoginProvider *providerActive = LoginBox_GetActiveProviderInternal(hwnd);
  2004. if (NULL != providerActive)
  2005. {
  2006. providerActive->GetId(&activeId);
  2007. if (S_OK != LoginProviderOperation::CreateFromUpdate(providerActive, providerEnum, &providerOp))
  2008. providerOp = NULL;
  2009. }
  2010. HWND hFrame = GetDlgItem(hwnd, IDC_TABFRAME);
  2011. if (NULL != hFrame)
  2012. {
  2013. UINT frameStyle = GetWindowStyle(hFrame);
  2014. if (0 != (WS_VISIBLE & frameStyle))
  2015. SetWindowLongPtr(hFrame, GWL_STYLE, frameStyle & ~WS_VISIBLE);
  2016. LoginBox_DeleteAllTabs(hwnd);
  2017. providerEnum->Reset();
  2018. if(NULL != providerOp)
  2019. LoginBox_AppendMultipleTabs(hwnd, providerEnum, &activeId, &activeIndex);
  2020. else
  2021. LoginBox_AppendMultipleTabs(hwnd, providerEnum, NULL, NULL);
  2022. LoginProvider *provider;
  2023. if (NULL != providerOp && SUCCEEDED(providerOp->GetSource(&provider)))
  2024. {
  2025. LoginBox_InsertTab(hwnd, activeIndex, provider);
  2026. provider->Release();
  2027. }
  2028. activeIndex = (FALSE == IsEqualGUID(activeId, GUID_NULL)) ?
  2029. LoginBox_FindTabByProviderId(hwnd, &activeId) : -1;
  2030. if (-1 != activeIndex)
  2031. {
  2032. LoginTab_SetCurSel(hFrame, activeIndex);
  2033. }
  2034. else
  2035. {
  2036. LoginTab_SetCurSel(hFrame, 0);
  2037. LoginBox_SelectActivePage(hwnd);
  2038. }
  2039. if (0 != (WS_VISIBLE & frameStyle))
  2040. {
  2041. frameStyle = GetWindowStyle(hFrame);
  2042. if (0 == (WS_VISIBLE & frameStyle))
  2043. SetWindowLongPtr(hFrame, GWL_STYLE, frameStyle | WS_VISIBLE);
  2044. RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASENOW | RDW_ALLCHILDREN);
  2045. UpdateWindow(hFrame);
  2046. }
  2047. }
  2048. if (NULL != providerOp)
  2049. {
  2050. LOGINBOX *loginbox = GetLoginBox(hwnd);
  2051. if (NULL != loginbox)
  2052. {
  2053. if (NULL != loginbox->providerOp)
  2054. loginbox->providerOp->Release();
  2055. loginbox->providerOp = providerOp;
  2056. providerOp->AddRef();
  2057. }
  2058. providerOp->Release();
  2059. }
  2060. LoginBox_PerformProviderOp(hwnd);
  2061. return TRUE;
  2062. }
  2063. static void LoginBox_OnProvidersUpdated(HWND hwnd, PROVIDERUPDATERESULT *result)
  2064. {
  2065. if (NULL == result)
  2066. return;
  2067. LOGINBOX *loginbox = GetLoginBox(hwnd);
  2068. if (NULL == loginbox) return;
  2069. BOOL dataIdentical;
  2070. LoginProviderEnumerator *providerEnum;
  2071. HRESULT resultCode = result->errorCode;
  2072. if (SUCCEEDED(resultCode))
  2073. {
  2074. providerEnum = result->enumerator;
  2075. if(NULL != providerEnum) providerEnum->AddRef();
  2076. dataIdentical = result->dataIdentical;
  2077. }
  2078. else
  2079. {
  2080. providerEnum = NULL;
  2081. dataIdentical = FALSE;
  2082. }
  2083. BOOL storedUpdate = (NULL != loginbox->providerUpdate &&
  2084. loginbox->providerUpdate == result->downloader);
  2085. ReplyMessage(0);
  2086. if (SUCCEEDED(resultCode))
  2087. {
  2088. BOOL updateOk;
  2089. if(FALSE == dataIdentical)
  2090. updateOk = LoginBox_ApplyProvidersUpdate(hwnd, providerEnum);
  2091. else
  2092. updateOk = TRUE;
  2093. if(FALSE != updateOk)
  2094. {
  2095. LoginConfig *config;
  2096. if (SUCCEEDED(LoginConfig::CreateInstance(&config)))
  2097. {
  2098. UINT ts = LoginBox_GetCurrentTime();
  2099. config->WriteInt("LoginBox", "lastCheck", ts);
  2100. LPSTR lang;
  2101. if (FAILED(LoginBox_GetCurrentLang(&lang)))
  2102. lang = NULL;
  2103. config->WriteAnsiStr("LoginBox", "lastLang", lang);
  2104. LoginBox_FreeAnsiString(lang);
  2105. config->Release();
  2106. }
  2107. }
  2108. }
  2109. if (NULL != providerEnum)
  2110. providerEnum->Release();
  2111. if (FALSE != storedUpdate)
  2112. {
  2113. loginbox->providerUpdate->Release();
  2114. loginbox->providerUpdate = NULL;
  2115. HWND hPage = GetDlgItem(hwnd, IDC_ACTIVEPAGE);
  2116. if (NULL != hPage)
  2117. LoginPage_UpdateStateChange(hPage, FALSE);
  2118. }
  2119. }
  2120. static void CALLBACK LoginBox_DownloadCompleted(LoginDownloadResult *result, void *data)
  2121. {
  2122. HWND hLoginbox = (HWND)data;
  2123. if(NULL == result || FALSE == IsWindow(hLoginbox)) return;
  2124. UINT type;
  2125. if (FAILED(result->GetType(&type)) || LoginDownloadResult::typeProviderList != type)
  2126. return;
  2127. BSTR fileName = NULL;
  2128. LoginDownload download;
  2129. HRESULT hr = download.End(result, &fileName);
  2130. LoginProviderEnumerator *enumerator = NULL;
  2131. if (SUCCEEDED(hr))
  2132. {
  2133. if (S_FALSE != hr)
  2134. {
  2135. LoginProviderLoader loader;
  2136. hr = loader.ReadXml(fileName, &enumerator, NULL);
  2137. if (FAILED(hr))
  2138. enumerator = NULL;
  2139. }
  2140. }
  2141. LoginBox_ProvidersUpdated(hLoginbox, result, hr, (S_FALSE == hr), enumerator);
  2142. if (NULL != enumerator)
  2143. enumerator->Release();
  2144. SysFreeString(fileName);
  2145. }
  2146. static BOOL LoginBox_OnUpdateProviders(HWND hwnd, BOOL forceUpdate)
  2147. {
  2148. LOGINBOX *loginbox = GetLoginBox(hwnd);
  2149. if (NULL == loginbox || NULL != loginbox->providerUpdate)
  2150. return FALSE;
  2151. if (FALSE == forceUpdate)
  2152. {
  2153. LoginConfig *config;
  2154. if (SUCCEEDED(LoginConfig::CreateInstance(&config)))
  2155. {
  2156. BOOL checkRequired = TRUE;
  2157. UINT ts = LoginBox_GetCurrentTime();
  2158. UINT lastCheck = config->ReadInt("LoginBox", "lastCheck", 0);
  2159. if ((ts - lastCheck) < (60*60*24)) // check once 24 hours
  2160. {
  2161. checkRequired = FALSE;
  2162. LPSTR lang;
  2163. if (SUCCEEDED(LoginBox_GetCurrentLang(&lang)))
  2164. {
  2165. CHAR lastLang[32] = {0};
  2166. config->ReadAnsiStr("LoginBox", "lastLang", NULL, lastLang, ARRAYSIZE(lastLang));
  2167. checkRequired = (NULL == lang || NULL == lastLang) ?
  2168. ((NULL == lang) != (NULL == lastLang)) :
  2169. (CSTR_EQUAL != CompareStringA(CSTR_INVARIANT, NORM_IGNORECASE, lang, -1, lastLang, -1));
  2170. LoginBox_FreeAnsiString(lang);
  2171. }
  2172. }
  2173. config->Release();
  2174. if (FALSE == checkRequired)
  2175. return FALSE;
  2176. }
  2177. }
  2178. WCHAR szUrl[4096] = {0};
  2179. LPWSTR cursor = szUrl;
  2180. size_t remaining = ARRAYSIZE(szUrl);
  2181. HRESULT hr;
  2182. hr = StringCchCopyEx(cursor, remaining, PROVIDERLIST_URL, &cursor, &remaining, 0);
  2183. if (SUCCEEDED(hr))
  2184. {
  2185. if (NULL != WASABI_API_LNG)
  2186. {
  2187. LPCWSTR lang = WASABI_API_LNG->GetLanguageIdentifier(LANG_LANG_CODE);
  2188. if (NULL != lang && L'\0' != *lang)
  2189. {
  2190. hr = StringCchPrintfEx(cursor, remaining, &cursor, &remaining, 0, L"?lang=%s", lang);
  2191. }
  2192. }
  2193. }
  2194. if (SUCCEEDED(hr))
  2195. {
  2196. HWND hPage = GetDlgItem(hwnd, IDC_ACTIVEPAGE);
  2197. if (NULL != hPage)
  2198. LoginPage_UpdateStateChange(hPage, TRUE);
  2199. LoginDownload download;
  2200. hr = download.Begin(szUrl, LoginDownloadResult::typeProviderList, LoginBox_DownloadCompleted,
  2201. hwnd, loginbox->loginStatus, &loginbox->providerUpdate);
  2202. if (FAILED(hr))
  2203. {
  2204. loginbox->providerUpdate = NULL;
  2205. if (NULL != hPage)
  2206. LoginPage_UpdateStateChange(hPage, FALSE);
  2207. }
  2208. }
  2209. return SUCCEEDED(hr);
  2210. }
  2211. static BOOL LoginBox_OnGetUpdateState(HWND hwnd)
  2212. {
  2213. LOGINBOX *loginbox = GetLoginBox(hwnd);
  2214. return (NULL != loginbox && NULL != loginbox->providerUpdate);
  2215. }
  2216. static void LoginBox_OnImageCached(HWND hwnd, IMAGECACHERESULT *result)
  2217. {
  2218. LoginImageCache *cache = NULL;
  2219. ifc_omcacherecord *record = NULL;
  2220. if (NULL != result)
  2221. {
  2222. cache = result->imageCache;
  2223. record = result->cacheRecord;
  2224. }
  2225. if (NULL != cache) cache->AddRef();
  2226. if (NULL != record) record->AddRef();
  2227. ReplyMessage(0);
  2228. if (NULL != cache && NULL != record)
  2229. {
  2230. WCHAR szName[4096] = {0};
  2231. if (SUCCEEDED(record->GetName(szName, ARRAYSIZE(szName))))
  2232. {
  2233. HWND hFrame = GetDlgItem(hwnd, IDC_TABFRAME);
  2234. if (NULL != hFrame)
  2235. {
  2236. NLTITEM tab;
  2237. tab.mask = NLTIF_PARAM;
  2238. INT count = LoginTab_GetItemCount(hFrame);
  2239. for (INT i = 0; i < count; i++)
  2240. {
  2241. if (FALSE != LoginTab_GetItem(hFrame, i, &tab))
  2242. {
  2243. WCHAR szImage[4096] = {0};
  2244. LoginProvider *provider = (LoginProvider*)tab.param;
  2245. if (NULL != provider &&
  2246. SUCCEEDED(provider->GetImagePath(szImage, ARRAYSIZE(szImage))) &&
  2247. S_OK == LoginBox_IsStrEqInvI(szImage, szName))
  2248. {
  2249. LoginBox_RemoveImageHelper2(hFrame, &tab);
  2250. tab.mask = NLTIF_IMAGE_MASK;
  2251. tab.iImage = NLTM_IMAGE_CALLBACK;
  2252. tab.iImageActive = NLTM_IMAGE_CALLBACK;
  2253. tab.iImageDisabled = NLTM_IMAGE_CALLBACK;
  2254. LoginTab_SetItem(hFrame, i, &tab);
  2255. tab.mask = NLTIF_PARAM;
  2256. }
  2257. }
  2258. }
  2259. }
  2260. }
  2261. }
  2262. if (NULL != cache) cache->Release();
  2263. if (NULL != record) record->Release();
  2264. }
  2265. static INT_PTR CALLBACK LoginBox_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2266. {
  2267. switch(uMsg)
  2268. {
  2269. case WM_INITDIALOG: return LoginBox_OnInitDialog(hwnd, (HWND)wParam, lParam);
  2270. case WM_DESTROY: LoginBox_OnDestroy(hwnd); return 0;
  2271. case WM_WINDOWPOSCHANGED: LoginBox_OnWindowPosChanged(hwnd, (WINDOWPOS*)lParam); return TRUE;
  2272. case WM_COMMAND: LoginBox_OnCommand(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); return TRUE;
  2273. case WM_NOTIFY: MSGRESULT(hwnd, LoginBox_OnNotify(hwnd, (INT)wParam, (NMHDR*)lParam));
  2274. case WM_GETMINMAXINFO: LoginBox_OnGetMinMaxInfo(hwnd, (MINMAXINFO*)lParam); return TRUE;
  2275. case WM_ERASEBKGND: MSGRESULT(hwnd, 0);
  2276. case WM_PAINT: LoginBox_OnPaint(hwnd); return TRUE;
  2277. case WM_PRINTCLIENT: LoginBox_OnPrintClient(hwnd, (HDC)wParam, (UINT)lParam); return TRUE;
  2278. case WM_CTLCOLORSTATIC: return (INT_PTR)LoginBox_OnGetStaticColor(hwnd, (HDC)wParam, (HWND)lParam);
  2279. case WM_NCHITTEST: return LoginBox_OnNcHitTest(hwnd, MAKEPOINTS(lParam));
  2280. case WM_SETFONT: LoginBox_OnSetFont(hwnd, (HFONT)wParam, LOWORD(lParam)); return TRUE;
  2281. case WM_SIZE: MSGRESULT(hwnd, 0);
  2282. case NLBM_GETAUTHAPI: MSGRESULT(hwnd, LoginBox_OnGetAuthApi(hwnd, (api_auth**)lParam));
  2283. case NLBM_GETREALM: MSGRESULT(hwnd, LoginBox_OnGetRealm(hwnd, (GUID*)lParam));
  2284. case NLBM_GETACTIVEPROVIDER:MSGRESULT(hwnd, LoginBox_OnGetActiveProvider(hwnd, (LoginProvider**)lParam));
  2285. case NLBM_GETSTATUS: MSGRESULT(hwnd, LoginBox_OnGetStatus(hwnd, (LoginStatus**)lParam));
  2286. case NLBM_ADDSTATUS: MSGRESULT(hwnd, LoginBox_OnAddStatus(hwnd, (BSTR)lParam));
  2287. case NLBM_SETSTATUS: MSGRESULT(hwnd, LoginBox_OnSetStatus(hwnd, (UINT)wParam, (BSTR)lParam));
  2288. case NLBM_REMOVESTATUS: LoginBox_OnRemoveStatus(hwnd, (UINT)wParam);
  2289. case NLBM_UPDATEPROVIDERS: MSGRESULT(hwnd, LoginBox_OnUpdateProviders(hwnd, (BOOL)wParam));
  2290. case NLBM_GETUPDATESTATE: MSGRESULT(hwnd, LoginBox_OnGetUpdateState(hwnd));
  2291. case NLBM_LOGINCOMPLETED: LoginBox_OnLoginCompleted(hwnd, (LoginResult*)lParam); return TRUE;
  2292. case NLBM_PROVIDERSUPDATED: LoginBox_OnProvidersUpdated(hwnd, (PROVIDERUPDATERESULT*)lParam); return TRUE;
  2293. case NLBM_IMAGECACHED: LoginBox_OnImageCached(hwnd, (IMAGECACHERESULT*)lParam); return TRUE;
  2294. }
  2295. return FALSE;
  2296. }