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

725 lines
18 KiB

  1. //<SCRIPT language=javascript>
  2. // The line above and the </SCRIPT> at the botttom of the file are so the
  3. // localization tools work properly for this file.
  4. // NOTE: because comments are taken out by the preprocessor,
  5. // it's really included by findinc.sed
  6. #include "dialogs.dh"
  7. //+--------------------------------------------------
  8. //
  9. // Find dialog header file. This file contains functions
  10. // common to the find.dlg and bidifind.dlg.
  11. //
  12. //---------------------------------------------------
  13. //Find Text dialog box
  14. #define IDH_FIND_WHOLE 50022 // was 0x3063
  15. #define IDH_FIND_CASE 50023 // was 0x3064
  16. #define IDH_FIND_UP 50025 // was 0x3065
  17. #define IDH_FIND_DOWN 50024 // was 0x3066
  18. #define IDH_FIND_NEXT 50026 // was 0x3067
  19. #define IDH_FIND_WHAT 50027 // was 0x3068
  20. #define IDH_FIND_DIACRITIC 50401
  21. #define IDH_FIND_KASHIDA 50402
  22. #define IDH_FIND_ALEF_HAMZA 50403
  23. setState(Find, btnFind, txtFindText)
  24. //
  25. // global variables
  26. //
  27. var g_docLastFound; // the document we last searched through
  28. var g_fFrameset = false; // Are we in a frameset?
  29. var g_arrFrames = new Array(); // Array of path through framesets
  30. var g_fSearchTopFrame = false; // Should we search the doc of
  31. // the top frame?
  32. var g_fFollowIframes = true; // Should we walk down iframes?
  33. var g_fError = false; // Has a handled error occured?
  34. var g_docSearch ;
  35. var g_rngWorking; // The range we're going to search
  36. var g_rngFoundText; // The found text
  37. var g_fFoundText = false; // If the text has already been found
  38. var g_intDirection; // What direction to search
  39. //+-------------------------------------------------------------------
  40. //
  41. // Synopsis: Turns off error messages in dialogs
  42. //
  43. // Arguments: none
  44. //
  45. // returns: true (tells browser not to handle message)
  46. //
  47. //--------------------------------------------------------------------
  48. function FindHandleError(message, url, line)
  49. {
  50. // NOTE TO LOCALIZERS! (krisma) The next two strings must exactly match
  51. // the error text that appears if you comment out the
  52. // "window.onerror = FindHandleError;" line in loadBdy() and
  53. // launch the find dialog.
  54. var L_Find_DIALOG_NoAction_ErrorMessage = "Object doesn't support this action";
  55. var L_Find_DIALOG_NoProperty_ErrorMessage = "Object doesn't support this property or method";
  56. if (message != L_Find_DIALOG_NoProperty_ErrorMessage)
  57. {
  58. if (message != L_Find_DIALOG_NoAction_ErrorMessage)
  59. {
  60. var str = L_Dialog_ErrorMessage + "\n\n"
  61. + L_ErrorNumber_Text + line + "\n"
  62. + message;
  63. alert (str);
  64. window.close();
  65. }
  66. else // We've got an iframe without trident.
  67. {
  68. g_fError = true;
  69. g_fFrameset = false;
  70. }
  71. }
  72. return true;
  73. }
  74. //
  75. // Frameset navigation functions
  76. //
  77. //+---------------------------------------------------------------------
  78. //
  79. // Synopsis: Follows the path in g_arrFrames
  80. //
  81. // Arguments: none
  82. //
  83. // Returns: window object at end of frameset path
  84. //
  85. //----------------------------------------------------------------------
  86. function CrawlPath()
  87. {
  88. var win = window.dialogArguments.unsecuredWindowOfDocument;
  89. var i = 0;
  90. //
  91. // Special case if top doc has iframe
  92. //
  93. if (g_fSearchTopFrame)
  94. {
  95. return win;
  96. }
  97. while (g_arrFrames[i] >= 0)
  98. {
  99. win = win.frames[g_arrFrames[i]];
  100. i++;
  101. }
  102. return win;
  103. } // CrawlPath
  104. //+---------------------------------------------------------------------
  105. //
  106. // Synopsis: Whether or not the end of the current path is
  107. // at another frameset
  108. //
  109. // Arguments: none
  110. //
  111. // Returns: 0 if false, non-zero if true
  112. //
  113. //----------------------------------------------------------------------
  114. function AtFrameset()
  115. {
  116. var win = CrawlPath();
  117. return win.frames.length;
  118. } // AtFrameset
  119. //+---------------------------------------------------------------------
  120. //
  121. // Synopsis: Whether or not the end of the current path is
  122. // at a document with iframes
  123. //
  124. // Arguments: none
  125. //
  126. // Returns: 0 if false, non-zero if true
  127. //
  128. //----------------------------------------------------------------------
  129. function AtIframe()
  130. {
  131. var win = CrawlPath();
  132. return win.document.all.tags("IFRAME").length;
  133. } // AtIFrame
  134. //+---------------------------------------------------------------------
  135. //
  136. // Synopsis: checks the extension of the current file against
  137. // a list of file types we should search into
  138. //
  139. // Arguments: the window that contains the file we're checkin
  140. //
  141. // Returns: true if we can search it, false if we can't.
  142. //
  143. //----------------------------------------------------------------------
  144. function IsLegalPage(win)
  145. {
  146. var arrBadFileTypes = new Array(".doc", ".xls", ".pdf");
  147. var strHref = win.location.href;
  148. for (i=0; i < arrBadFileTypes.length; i++)
  149. {
  150. if (strHref.lastIndexOf(arrBadFileTypes[i]) == (strHref.length - 4))
  151. {
  152. return false;
  153. }
  154. }
  155. return true;
  156. }
  157. //+---------------------------------------------------------------------
  158. //
  159. // Synopsis: gets the position in the current frameset
  160. //
  161. // Arguments: none
  162. //
  163. // Returns: 0-based integer representing position
  164. //
  165. //----------------------------------------------------------------------
  166. function GetCurrentPos()
  167. {
  168. var i = GetCurrentDepth();
  169. return g_arrFrames[i];
  170. } // GetCurrentPos
  171. //+---------------------------------------------------------------------
  172. //
  173. // Synopsis: Tells how many frames deep we're currently at
  174. //
  175. // Arguments: none
  176. //
  177. // Returns: 0-based integer representing depth
  178. //
  179. //----------------------------------------------------------------------
  180. function GetCurrentDepth()
  181. {
  182. var i = 0;
  183. while (g_arrFrames[i] >= 0)
  184. {
  185. i++;
  186. }
  187. return i-1;
  188. } // GetCurrentDepth
  189. //+---------------------------------------------------------------------
  190. //
  191. // Synopsis: Can we move forward in the current frameset?
  192. //
  193. // Arguments: fForward Whether we're trying to move forwards or
  194. // backwards
  195. //
  196. // Returns: 0 if false, non-zero if true
  197. //
  198. //----------------------------------------------------------------------
  199. function MovePossible(fForward)
  200. {
  201. var intCurPos = GetCurrentPos();
  202. var win = CrawlPath();
  203. var winParent = win.parent;
  204. if (fForward)
  205. {
  206. if ((winParent.frames.length - intCurPos - 1)
  207. && (IsLegalPage(winParent.frames[intCurPos + 1])))
  208. {
  209. return true;
  210. }
  211. else
  212. {
  213. return false;
  214. }
  215. }
  216. else
  217. {
  218. return (intCurPos != 0);
  219. }
  220. } // MovePossible
  221. //+---------------------------------------------------------------------
  222. //
  223. // Synopsis: Moves up in the frameset
  224. //
  225. // Arguments: none
  226. //
  227. // Returns: nothing
  228. //
  229. //----------------------------------------------------------------------
  230. function MoveUpFrameset()
  231. {
  232. var i = GetCurrentDepth();
  233. g_arrFrames[i] = -1;
  234. } // MoveUpFrameset
  235. //+---------------------------------------------------------------------
  236. //
  237. // Synopsis: Moves down in the frameset
  238. //
  239. // Arguments: fForward Whether we're trying to move forwards or
  240. // backwards
  241. //
  242. // Returns: nothing
  243. //
  244. //----------------------------------------------------------------------
  245. function MoveDownFrameset(fForward)
  246. {
  247. var i = GetCurrentDepth();
  248. var win = CrawlPath();
  249. g_arrFrames[i+1] = fForward ? 0 : win.frames.length - 1;
  250. g_arrFrames[i+2] = -1;
  251. } // MoveDownFrameset
  252. //+---------------------------------------------------------------------
  253. //
  254. // Synopsis: moves one window in the current frameset
  255. //
  256. // Arguments: fForward Whether we're trying to move forwards or
  257. // backwards
  258. //
  259. // Returns: nothing
  260. //
  261. //----------------------------------------------------------------------
  262. function MoveWin(fForward)
  263. {
  264. var intDepth = GetCurrentDepth();
  265. var intPos = GetCurrentPos();
  266. g_arrFrames[intDepth] = fForward ? ++intPos : --intPos;
  267. } // MoveWin
  268. //+---------------------------------------------------------------------
  269. //
  270. // Synopsis: Moves to the next document
  271. //
  272. // Arguments: fForward Whether we're trying to move forwards or
  273. // backwards
  274. //
  275. // Returns: true if sucessful or false if fails
  276. //
  277. //----------------------------------------------------------------------
  278. function MoveDoc(fForward)
  279. {
  280. //
  281. // Special case of top document contains an iframe.
  282. //
  283. if (g_fSearchTopFrame) // special case forward
  284. {
  285. if (fForward)
  286. {
  287. g_fSearchTopFrame = false;
  288. return true;
  289. }
  290. else
  291. {
  292. return false;
  293. }
  294. }
  295. // special case backwards
  296. if (!fForward && (g_arrFrames[0] == 0) && (g_arrFrames[1] < 0)
  297. && window.dialogArguments.document.all.tags("IFRAME").length)
  298. {
  299. g_fSearchTopFrame = true;
  300. return true;
  301. }
  302. if (g_fFollowIframes && AtIframe())
  303. {
  304. MoveDownFrameset(fForward);
  305. while (!AtIframe() && AtFrameset())
  306. {
  307. MoveDownFrameset(fForward);
  308. return true;
  309. }
  310. return false;
  311. }
  312. if (MovePossible(fForward))
  313. {
  314. MoveWin(fForward);
  315. g_fFollowIframes = true;
  316. while (!AtIframe() && AtFrameset())
  317. {
  318. MoveDownFrameset(fForward);
  319. }
  320. return true;
  321. }
  322. else
  323. {
  324. if (GetCurrentDepth() > 0)
  325. {
  326. MoveUpFrameset();
  327. while (AtIframe() && !MovePossible(fForward)
  328. && (GetCurrentDepth() >= 0))
  329. {
  330. MoveUpFrameset();
  331. }
  332. if (AtIframe() && MovePossible(fForward))
  333. {
  334. g_fFollowIframes = false;
  335. }
  336. return MoveDoc(fForward);
  337. }
  338. }
  339. return false;
  340. } // MoveDoc
  341. //+---------------------------------------------------------------------
  342. //
  343. // Synopsis: walks to first document
  344. //
  345. // Arguments: none
  346. //
  347. // Returns: document object
  348. //
  349. //----------------------------------------------------------------------
  350. function GetFirstDoc()
  351. {
  352. var win;
  353. var doc = window.dialogArguments.document;
  354. //
  355. // If the main document conttains an iframe, we need to special
  356. // case it.
  357. //
  358. if (doc.all.tags("IFRAME").length)
  359. {
  360. g_fSearchTopFrame = true;
  361. return doc;
  362. }
  363. while (!AtIframe() && AtFrameset())
  364. {
  365. MoveDownFrameset(true);
  366. }
  367. win = CrawlPath();
  368. return win.document;
  369. } // GetFirstDoc
  370. //+---------------------------------------------------------------------
  371. //
  372. // Set the initial range to the enitire document or the selection
  373. //
  374. // Arguments: none
  375. //
  376. // Returns: nothing
  377. //
  378. //-----------------------------------------------------------------------
  379. function setInitSearchRng()
  380. {
  381. //
  382. // Determine starting location
  383. //
  384. findStartPoint();
  385. //
  386. // Are we in a frameset?
  387. //
  388. if (g_fFrameset)
  389. {
  390. var win;
  391. //
  392. // Check to see if we're still in a frameset.
  393. // (This could happen if there's a frameset in an
  394. // inline frame.)
  395. //
  396. if (!AtIframe() && AtFrameset())
  397. {
  398. MoveDownFrameset(!radDirection[0].checked);
  399. while (!AtIframe() && AtFrameset())
  400. {
  401. MoveDownFrameset(!radDirection[0].checked);
  402. }
  403. }
  404. win = CrawlPath();
  405. g_docSearch = win.document;
  406. }
  407. else
  408. {
  409. g_docSearch = window.dialogArguments.document;
  410. }
  411. //
  412. // If we're in browse mode and nothing is selected,
  413. // set the range to the entire body.
  414. //
  415. if (g_docSearch .queryCommandState("BrowseMode")
  416. && g_docSearch .selection.type != "Text")
  417. {
  418. if (g_docSearch .body == null)
  419. return;
  420. g_rngWorking = g_docSearch .body.createTextRange();
  421. }
  422. else
  423. {
  424. g_rngWorking = g_docSearch .selection.createRange();
  425. }
  426. } // setInitSearchRng
  427. //+---------------------------------------------------------------------
  428. //
  429. // Set direction and adjust range
  430. //
  431. // Arguments: none
  432. //
  433. // Returns: nothing
  434. //
  435. //-----------------------------------------------------------------------
  436. function directionAdjust()
  437. {
  438. //
  439. // If there's a current selection, we'll start from the
  440. // selection
  441. //
  442. g_fFoundText = (g_docSearch .selection.type == "Text");
  443. //
  444. // rngWorking starts as the entire body, and is then narrowed
  445. // down by the 'set direction' code.
  446. //
  447. //
  448. // Set direction
  449. //
  450. if (radDirection[0].checked) // Search backwards
  451. {
  452. //
  453. // set range to search
  454. //
  455. if (g_fFoundText)
  456. {
  457. //
  458. // Search from the end of the current selection
  459. // minus 1 so we don't find the text we just found
  460. //
  461. g_rngWorking.moveEnd("character" , -1);
  462. }
  463. //
  464. // Move the beginning of the range to the beginning
  465. // of the document
  466. //
  467. // This use to move one character at a time, but since it
  468. // will move as many characters as possible, it is more
  469. // efficient to move in big jumps.
  470. //
  471. while (0 != g_rngWorking.moveStart("textedit", -10000))
  472. {
  473. }
  474. g_intDirection = -1000000000;
  475. }
  476. else // Search forwards
  477. {
  478. //
  479. // set range to search
  480. //
  481. if (g_fFoundText)
  482. {
  483. //
  484. // Search from the start of the current selection plus
  485. // one so we don't find the text we just found
  486. //
  487. g_rngWorking.moveStart("character", 1);
  488. }
  489. //
  490. // Move the end of the range to the end
  491. // of the document
  492. //
  493. //
  494. // This use to move one character at a time, but since it
  495. // will move as many characters as possible, it is more
  496. // efficient to move in big jumps.
  497. //
  498. while (0 != g_rngWorking.moveEnd("textedit", 10000))
  499. {
  500. }
  501. g_intDirection = 1000000000;
  502. }
  503. }
  504. //+---------------------------------------------------------------------
  505. //
  506. // Synopsis: Three steps:
  507. // 1. Make sure there's something to find.
  508. // 2. Determine the direction and how far to search.
  509. // 3. Find and select the text.
  510. //
  511. // Arguments: none
  512. //
  513. // Returns: nothing
  514. //
  515. //-----------------------------------------------------------------------
  516. function btnFindClick()
  517. {
  518. var fDone = false;
  519. var L_FinishedDocument_Text = "Finished searching the document.";
  520. var index;
  521. //
  522. // Initial range is the entire document or the selection
  523. //
  524. setInitSearchRng();
  525. //
  526. // Set direction and adjust range based on direction
  527. //
  528. directionAdjust();
  529. //
  530. // We have to loop, because findText includes text that may be hidden.
  531. //
  532. g_rngFoundText = g_rngWorking.duplicate();
  533. success = g_rngFoundText.findText(txtFindText.value,
  534. g_intDirection,
  535. findFlags());
  536. while ((!fDone) && success)
  537. {
  538. fDone = true;
  539. //
  540. // Using try catch on select, because selecting invisible text
  541. // results in an exception.
  542. //
  543. try
  544. {
  545. g_rngFoundText.select();
  546. }
  547. catch (exception)
  548. {
  549. if (g_intDirection == 1000000000) // forward
  550. {
  551. g_rngFoundText.moveStart("character" , 1);
  552. while (0 != g_rngFoundText.moveEnd("textedit", 10000))
  553. {
  554. }
  555. }
  556. else
  557. {
  558. g_rngFoundText.moveEnd("character" , -1);
  559. while (0 != g_rngFoundText.moveStart("textedit", -10000))
  560. {
  561. }
  562. }
  563. fDone = false;
  564. success = g_rngFoundText.findText(txtFindText.value,
  565. g_intDirection,
  566. findFlags());
  567. }
  568. }
  569. if (!success) // Text was not found
  570. {
  571. if (g_fFrameset)
  572. {
  573. if (MoveDoc(!radDirection[0].checked))
  574. {
  575. btnFindClick();
  576. return;
  577. }
  578. }
  579. alert(L_FinishedDocument_Text);
  580. txtFindText.focus();
  581. }
  582. else // Text was found
  583. {
  584. //
  585. // If we're in a frameset, we have to unselect
  586. // the previously searched document
  587. //
  588. if (g_fFrameset)
  589. {
  590. g_docLastFound.execCommand("Unselect", false);
  591. g_docLastFound = g_docSearch ;
  592. }
  593. g_rngFoundText.select();
  594. g_rngFoundText.scrollIntoView(true);
  595. }
  596. } // btnFindClick
  597. //----------------------------------------------------------------------
  598. //
  599. // Synopsis: Save the last search, then discard the user's
  600. // changes and dismiss the dialog.
  601. //
  602. // Arguments: none
  603. //
  604. // Returns: nothing
  605. //
  606. //----------------------------------------------------------------------
  607. function btnCancelClick2()
  608. {
  609. window.dialogArguments.findText = txtFindText.value;
  610. window.close();
  611. } // btnCancelClick2
  612. //</SCRIPT>