Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

392 lines
11 KiB

  1. var _oSelectedItem = null;
  2. var _szTempFile = null;
  3. var _bHaveTemp = false;
  4. var _szPictureSource = null;
  5. var _oWIA = null;
  6. function PageInit()
  7. {
  8. var oUser = top.window.g_oSelectedUser;
  9. var bSelf = top.window.IsSelf();
  10. top.window.PopulateLeftPane(bSelf ? idRelatedTaskContent.innerHTML : null, idLearnAboutContent.innerHTML, idPreview.innerHTML);
  11. top.window.idPicture.src = oUser.setting("Picture");
  12. _szPictureSource = oUser.setting("PictureSource");
  13. if (_szPictureSource)
  14. {
  15. if (0 == _szPictureSource.length)
  16. _szPictureSource = null;
  17. else
  18. _szPictureSource = _szPictureSource.toLowerCase();
  19. }
  20. var szTitle = bSelf ? idPageTitle.innerHTML : idAltPageTitle.innerHTML;
  21. idPageTitle.innerHTML = szTitle.replace(/%1/g, top.window.GetUserDisplayName(oUser));
  22. idWelcome.ttText = top.window.L_Welcome_ToolTip;
  23. // CSIDL_COMMON_APPDATA = 0x0023 = 35
  24. EnumPics(top.window.GetShell().NameSpace(35).Self.Path + "\\Microsoft\\User Account Pictures\\Default Pictures");
  25. window.setTimeout("InitCameraLink();", 0);
  26. idPictures.focus();
  27. }
  28. function ApplyPictureChange2(szPicture)
  29. {
  30. var oUser = top.window.g_oSelectedUser;
  31. if (unescape(szPicture) != oUser.setting("Picture"))
  32. {
  33. try
  34. {
  35. oUser.setting("Picture") = szPicture;
  36. top.window.g_Navigator.navigate("mainpage.htm", true);
  37. }
  38. catch (error)
  39. {
  40. var nErr = (error.number & 0x7fffffff);
  41. // Any of these mean "invalid parameter". Somewhere in
  42. // mshtml or oleaut32, E_INVALIDARG is being tranlated to
  43. // CTL_E_ILLEGALFUNCTIONCALL.
  44. //
  45. // ERROR_INVALID_PARAMETER = 87
  46. // E_INVALIDARG = 0x80070057
  47. // CTL_E_ILLEGALFUNCTIONCALL = 0x800A0005
  48. // E_FAIL = 0x80004005
  49. if (nErr == 87 || nErr == 0x70057 || nErr == 0xA0005 || nErr == 0x4005)
  50. {
  51. alert(top.window.L_UnknownImageType_ErrorMessage);
  52. return false;
  53. }
  54. else
  55. throw error;
  56. }
  57. }
  58. return true;
  59. }
  60. function ApplyPictureChange()
  61. {
  62. if (_oSelectedItem)
  63. ApplyPictureChange2(_oSelectedItem.firstChild.src);
  64. }
  65. function SelectItem(oItem)
  66. {
  67. if (_oSelectedItem)
  68. {
  69. _oSelectedItem.selected = false;
  70. _oSelectedItem.tabIndex = -1;
  71. }
  72. oItem.selected = true;
  73. oItem.tabIndex = 0;
  74. _oSelectedItem = oItem;
  75. }
  76. function OnClickPicture()
  77. {
  78. SelectItem(this);
  79. idOK.disabled = false;
  80. event.cancelBubble = true;
  81. }
  82. function DeselectItem()
  83. {
  84. if (_oSelectedItem)
  85. {
  86. _oSelectedItem.selected = false;
  87. _oSelectedItem = null;
  88. }
  89. idOK.disabled = true;
  90. }
  91. function OnLoadError(img)
  92. {
  93. // mshtml blows chunks if we try to remove the parent node here,
  94. // so just hide it.
  95. img.parentElement.style.display = 'none';
  96. }
  97. function OnKeyDown()
  98. {
  99. // Handle arrow key navigation
  100. if (event.keyCode >= 37 && event.keyCode <= 40)
  101. {
  102. // Find the middle of the picture with focus
  103. var cx = this.offsetWidth;
  104. var cy = this.offsetHeight;
  105. var x = this.offsetLeft + (cx/2);
  106. var y = this.offsetTop + (cy/2);
  107. // Offset to the middle of the neighboring picture,
  108. // scrolling that direction if necessary
  109. switch (event.keyCode)
  110. {
  111. case 37: // VK_LEFT
  112. x -= cx;
  113. if (x < idPictures.scrollLeft)
  114. idPictures.scrollLeft -= cx;
  115. break;
  116. case 38: // VK_UP
  117. y -= cy;
  118. if (y < idPictures.scrollTop)
  119. idPictures.scrollTop -= cy;
  120. break;
  121. case 39: // VK_RIGHT
  122. x += cx;
  123. if (x - idPictures.scrollLeft > idPictures.offsetWidth)
  124. idPictures.scrollLeft += cx;
  125. break;
  126. case 40: // VK_DOWN
  127. y += cy;
  128. if (y - idPictures.scrollTop > idPictures.offsetHeight)
  129. idPictures.scrollTop += cy;
  130. break;
  131. }
  132. // Convert to document coords and find the neighboring picture
  133. var oTarget = document.elementFromPoint(idPictures.offsetLeft - idPictures.scrollLeft + x, idPictures.offsetTop - idPictures.scrollTop + y);
  134. if (oTarget != null && idPictures.contains(oTarget) && idPictures != oTarget)
  135. {
  136. // We usually find the IMG tag, but we want the SPAN that contains it.
  137. if (oTarget.tagName == "IMG")
  138. oTarget = oTarget.parentElement;
  139. if (oTarget != this)
  140. {
  141. this.tabIndex = -1;
  142. oTarget.tabIndex = 0;
  143. oTarget.focus();
  144. event.returnValue = false;
  145. }
  146. }
  147. }
  148. else if (event.keyCode == 27) // VK_ESCAPE
  149. {
  150. // For some reason, this is necessary to keep us from going
  151. // all the way back to the first page.
  152. event.returnValue = false;
  153. }
  154. }
  155. function AddPictureToList(oItem, szID, bNoDimensions)
  156. {
  157. if (!oItem)
  158. return;
  159. //alert(oItem.path); // for debugging only
  160. var span = document.createElement('<SPAN tabindex=-1 class="Selectable" paddingWidth=3 borderWidth=3></SPAN>');
  161. if (span)
  162. {
  163. span.onclick = OnClickPicture;
  164. span.ondblclick = ApplyPictureChange;
  165. span.onkeydown=OnKeyDown;
  166. span.title = oItem.name;
  167. if (szID)
  168. span.id = szID;
  169. span.innerHTML = '<IMG onerror="OnLoadError(this);"/>';
  170. if (true != bNoDimensions)
  171. span.firstChild.className = "PictureSize";
  172. idPictures.appendChild(span);
  173. //
  174. // NTRAID#NTBUG9-199491-2000/11/29-jeffreys
  175. //
  176. // The "file:///" part (with 3 slashes) turns off URL escaping so the
  177. // file path remains intact.
  178. //
  179. // Without this, chars between 0x80 and 0xff are "escaped" and later
  180. // unescaped (via SHPathCreateFromUrl, SHUrlUnescapeW, MultiByteToWideChar)
  181. // which may convert them to other chars depending on the current code page.
  182. // If the path is mangled, mshtml/urlmon fail to load the file.
  183. //
  184. var szPath = oItem.path;
  185. span.firstChild.src = "file:///" + szPath;
  186. span.firstChild.alt = oItem.name;
  187. if (_szPictureSource && _szPictureSource == szPath.toLowerCase() && span.style.display != 'none')
  188. SelectItem(span);
  189. }
  190. }
  191. function EnumPics(szFolder)
  192. {
  193. var oShell = top.window.GetShell();
  194. if (oShell)
  195. {
  196. var oFolder = oShell.Namespace(szFolder);
  197. if (oFolder)
  198. {
  199. var oFolderItems = oFolder.Items();
  200. if (oFolderItems)
  201. {
  202. var cItems = oFolderItems.count;
  203. for (var i = 0; i < cItems; i++)
  204. AddPictureToList(oFolderItems.Item(i));
  205. }
  206. }
  207. if (_szPictureSource && !_oSelectedItem)
  208. {
  209. AddPictureToList(oShell.Namespace(0).ParseName(top.window.idPicture.src), null, true);
  210. SelectItem(idPictures.lastChild);
  211. }
  212. if (!_oSelectedItem && idPictures.firstChild)
  213. idPictures.firstChild.tabIndex = 0;
  214. }
  215. }
  216. function SetTempPicture(szPath)
  217. {
  218. var szPrevious = null;
  219. if (!_bHaveTemp)
  220. {
  221. AddPictureToList(top.window.GetShell().Namespace(0).ParseName(szPath), "idTempPicture");
  222. _bHaveTemp = true;
  223. }
  224. else
  225. {
  226. idTempPicture.style.display = 'block';
  227. var img = idTempPicture.firstChild;
  228. szPrevious = img.src;
  229. //
  230. // NTRAID#NTBUG9-199491-2000/11/29-jeffreys
  231. //
  232. img.src = "file:///" + szPath;
  233. }
  234. // If the file is invalid, OnLoadError hides idTempPicture
  235. if (idTempPicture.style.display == 'none')
  236. {
  237. if (szPrevious)
  238. {
  239. idTempPicture.style.display = 'block';
  240. idTempPicture.firstChild.src = szPrevious;
  241. }
  242. alert(top.window.L_UnknownImageType_ErrorMessage);
  243. }
  244. else
  245. idTempPicture.click();
  246. }
  247. function FindOtherPictures()
  248. {
  249. try
  250. {
  251. var commDialog = new ActiveXObject("UserAccounts.CommonDialog");
  252. // OFN_HIDEREADONLY = 0x00000004
  253. // OFN_PATHMUSTEXIST = 0x00000800
  254. // OFN_FILEMUSTEXIST = 0x00001000
  255. // OFN_DONTADDTORECENT = 0x02000000
  256. commDialog.Flags = 0x02001804;
  257. commDialog.Filter = L_OpenFilesFilter_Text;
  258. commDialog.FilterIndex = 1;
  259. commDialog.Owner = top.window.document.title;
  260. var szPath = top.window.g_szCustomPicturePath;
  261. if (szPath)
  262. commDialog.FileName = szPath;
  263. try
  264. {
  265. // CSIDL_MYPICTURES = 0x0027 = 39
  266. commDialog.InitialDir = top.window.GetShell().NameSpace(39).Self.Path;
  267. }
  268. catch (e)
  269. {
  270. commDialog.InitialDir = "";
  271. }
  272. if (commDialog.ShowOpen())
  273. {
  274. szPath = commDialog.FileName;
  275. //SetTempPicture(szPath);
  276. if (ApplyPictureChange2(szPath))
  277. top.window.g_szCustomPicturePath = szPath;
  278. }
  279. }
  280. catch (error)
  281. {
  282. //EnumPics(39);
  283. idBrowse.disabled = 'true';
  284. }
  285. }
  286. function InitCameraLink()
  287. {
  288. var bCamera = false;
  289. try
  290. {
  291. _oWIA = new ActiveXObject("Wia.Script");
  292. bCamera = (_oWIA.Devices.length > 0);
  293. }
  294. catch (e)
  295. {
  296. }
  297. if (bCamera)
  298. {
  299. _szTempFile = top.window.GetWShell().ExpandEnvironmentStrings("%TEMP%\\") + top.window.GetUserDisplayName(top.window.g_oSelectedUser) + ".bmp";
  300. idTakeAPicture.style.display = 'block';
  301. }
  302. else
  303. idTakeAPicture.removeNode(true);
  304. }
  305. // constants passed to GetItemsFromUI (from public\sdk\inc\wiadef.h)
  306. // #define WIA_DEVICE_DIALOG_SINGLE_IMAGE 0x00000002
  307. // #define WIA_INTENT_IMAGE_TYPE_COLOR 0x00000001
  308. function TakeAPicture()
  309. {
  310. try
  311. {
  312. var oItem = _oWIA.Create(null);
  313. if (oItem)
  314. {
  315. var oNewPictures = oItem.GetItemsFromUI(2,1);
  316. if (oNewPictures && oNewPictures.length > 0)
  317. {
  318. oNewPictures.Item(0).Transfer(_szTempFile, false);
  319. SetTempPicture(_szTempFile);
  320. }
  321. }
  322. }
  323. catch (error)
  324. {
  325. var nErr = (error.number & 0xffffff);
  326. if (nErr == 0x210015 || nErr == 0x210005) // WIA_S_NO_DEVICE_AVAILABLE or WIA_ERROR_OFFLINE
  327. alert(top.window.L_NoCamera_ErrorMessage);
  328. else
  329. throw error;
  330. }
  331. }
  332. function onUnLoad()
  333. {
  334. if (_szTempFile)
  335. {
  336. // Try to delete the temp file, which may or may not exist
  337. // TODO: figure out a way to do this from script (it's currently abandoned)
  338. }
  339. }